blob: e953f8fd36a0da8f2fed65e5d65cdc4662475975 [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);
Steve Wise74594862010-09-10 11:14:58 -0500220 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700221}
222
223int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
224{
225 int error = 0;
226
227 if (c4iw_fatal_error(rdev)) {
228 kfree_skb(skb);
229 PDBG("%s - device in error state - dropping\n", __func__);
230 return -EIO;
231 }
232 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
233 if (error < 0)
234 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500235 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700236}
237
238static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
239{
240 struct cpl_tid_release *req;
241
242 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
243 if (!skb)
244 return;
245 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
246 INIT_TP_WR(req, hwtid);
247 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
248 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
249 c4iw_ofld_send(rdev, skb);
250 return;
251}
252
253static void set_emss(struct c4iw_ep *ep, u16 opt)
254{
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800255 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
Hariprasad S04524a42014-09-24 03:53:41 +0530256 ((AF_INET == ep->com.remote_addr.ss_family) ?
257 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
258 sizeof(struct tcphdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700259 ep->mss = ep->emss;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800260 if (TCPOPT_TSTAMP_G(opt))
Hariprasad S04524a42014-09-24 03:53:41 +0530261 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700262 if (ep->emss < 128)
263 ep->emss = 128;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530264 if (ep->emss & 7)
265 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800266 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
267 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt),
Steve Wisecfdda9d2010-04-21 15:30:06 -0700268 ep->mss, ep->emss);
269}
270
271static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
272{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700273 enum c4iw_ep_state state;
274
Steve Wise2f5b48c2010-09-10 11:15:36 -0500275 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700276 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500277 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700278 return state;
279}
280
281static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
282{
283 epc->state = new;
284}
285
286static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
287{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500288 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700289 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
290 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500291 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700292 return;
293}
294
295static void *alloc_ep(int size, gfp_t gfp)
296{
297 struct c4iw_ep_common *epc;
298
299 epc = kzalloc(size, gfp);
300 if (epc) {
301 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500302 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500303 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700304 }
305 PDBG("%s alloc ep %p\n", __func__, epc);
306 return epc;
307}
308
309void _c4iw_free_ep(struct kref *kref)
310{
311 struct c4iw_ep *ep;
312
313 ep = container_of(kref, struct c4iw_ep, com.kref);
Hariprasad S9dec9002016-05-05 01:27:29 +0530314 PDBG("%s ep %p state %s\n", __func__, ep, states[ep->com.state]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000315 if (test_bit(QP_REFERENCED, &ep->com.flags))
316 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700317 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530318 if (ep->com.remote_addr.ss_family == AF_INET6) {
319 struct sockaddr_in6 *sin6 =
320 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600321 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530322
323 cxgb4_clip_release(
324 ep->com.dev->rdev.lldi.ports[0],
325 (const u32 *)&sin6->sin6_addr.s6_addr,
326 1);
327 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000328 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700329 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
330 dst_release(ep->dst);
331 cxgb4_l2t_release(ep->l2t);
332 }
333 kfree(ep);
334}
335
336static void release_ep_resources(struct c4iw_ep *ep)
337{
338 set_bit(RELEASE_RESOURCES, &ep->com.flags);
339 c4iw_put_ep(&ep->com);
340}
341
Steve Wisecfdda9d2010-04-21 15:30:06 -0700342static int status2errno(int status)
343{
344 switch (status) {
345 case CPL_ERR_NONE:
346 return 0;
347 case CPL_ERR_CONN_RESET:
348 return -ECONNRESET;
349 case CPL_ERR_ARP_MISS:
350 return -EHOSTUNREACH;
351 case CPL_ERR_CONN_TIMEDOUT:
352 return -ETIMEDOUT;
353 case CPL_ERR_TCAM_FULL:
354 return -ENOMEM;
355 case CPL_ERR_CONN_EXIST:
356 return -EADDRINUSE;
357 default:
358 return -EIO;
359 }
360}
361
362/*
363 * Try and reuse skbs already allocated...
364 */
365static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
366{
367 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
368 skb_trim(skb, 0);
369 skb_get(skb);
370 skb_reset_transport_header(skb);
371 } else {
372 skb = alloc_skb(len, gfp);
373 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530374 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700375 return skb;
376}
377
Vipul Pandya830662f2013-07-04 16:10:47 +0530378static struct net_device *get_real_dev(struct net_device *egress_dev)
379{
Steve Wise11b8e222014-05-16 12:42:46 -0500380 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530381}
382
383static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
384{
385 int i;
386
387 egress_dev = get_real_dev(egress_dev);
388 for (i = 0; i < dev->rdev.lldi.nports; i++)
389 if (dev->rdev.lldi.ports[i] == egress_dev)
390 return 1;
391 return 0;
392}
393
394static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
395 __u8 *peer_ip, __be16 local_port,
396 __be16 peer_port, u8 tos,
397 __u32 sin6_scope_id)
398{
399 struct dst_entry *dst = NULL;
400
401 if (IS_ENABLED(CONFIG_IPV6)) {
402 struct flowi6 fl6;
403
404 memset(&fl6, 0, sizeof(fl6));
405 memcpy(&fl6.daddr, peer_ip, 16);
406 memcpy(&fl6.saddr, local_ip, 16);
407 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
408 fl6.flowi6_oif = sin6_scope_id;
409 dst = ip6_route_output(&init_net, NULL, &fl6);
410 if (!dst)
411 goto out;
412 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
413 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
414 dst_release(dst);
415 dst = NULL;
416 }
417 }
418
419out:
420 return dst;
421}
422
423static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700424 __be32 peer_ip, __be16 local_port,
425 __be16 peer_port, u8 tos)
426{
427 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700428 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530429 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700430
David S. Miller31e4543d2011-05-03 20:25:42 -0700431 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500432 peer_port, local_port, IPPROTO_TCP,
433 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800434 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700435 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530436 n = dst_neigh_lookup(&rt->dst, &peer_ip);
437 if (!n)
438 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530439 if (!our_interface(dev, n->dev) &&
440 !(n->dev->flags & IFF_LOOPBACK)) {
Hariprasad Sd4802012014-09-24 03:53:42 +0530441 neigh_release(n);
Vipul Pandya830662f2013-07-04 16:10:47 +0530442 dst_release(&rt->dst);
443 return NULL;
444 }
445 neigh_release(n);
446 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700447}
448
449static void arp_failure_discard(void *handle, struct sk_buff *skb)
450{
Hariprasad S9dec9002016-05-05 01:27:29 +0530451 pr_err(MOD "ARP failure\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700452 kfree_skb(skb);
453}
454
Hariprasad S9dec9002016-05-05 01:27:29 +0530455enum {
456 NUM_FAKE_CPLS = 1,
457 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
458};
459
460static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
461{
462 struct c4iw_ep *ep;
463
464 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
465 release_ep_resources(ep);
466 return 0;
467}
468
469/*
470 * Fake up a special CPL opcode and call sched() so process_work() will call
471 * _put_ep_safe() in a safe context to free the ep resources. This is needed
472 * because ARP error handlers are called in an ATOMIC context, and
473 * _c4iw_free_ep() needs to block.
474 */
475static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb)
476{
477 struct cpl_act_establish *rpl = cplhdr(skb);
478
479 /* Set our special ARP_FAILURE opcode */
480 rpl->ot.opcode = FAKE_CPL_PUT_EP_SAFE;
481
482 /*
483 * Save ep in the skb->cb area, after where sched() will save the dev
484 * ptr.
485 */
486 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
487 sched(ep->com.dev, skb);
488}
489
490/* Handle an ARP failure for an accept */
491static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
492{
493 struct c4iw_ep *ep = handle;
494
495 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
496 ep->hwtid);
497
498 __state_set(&ep->com, DEAD);
499 queue_arp_failure_cpl(ep, skb);
500}
501
Steve Wisecfdda9d2010-04-21 15:30:06 -0700502/*
503 * Handle an ARP failure for an active open.
504 */
505static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
506{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530507 struct c4iw_ep *ep = handle;
508
Masanari Iidae3d132d2015-10-16 21:14:29 +0900509 printk(KERN_ERR MOD "ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530510 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530511 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530512 if (ep->com.remote_addr.ss_family == AF_INET6) {
513 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600514 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530515 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
516 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
517 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530518 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
519 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S9dec9002016-05-05 01:27:29 +0530520 queue_arp_failure_cpl(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700521}
522
523/*
524 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
525 * and send it along.
526 */
527static void abort_arp_failure(void *handle, struct sk_buff *skb)
528{
529 struct c4iw_rdev *rdev = handle;
530 struct cpl_abort_req *req = cplhdr(skb);
531
532 PDBG("%s rdev %p\n", __func__, rdev);
533 req->cmd = CPL_ABORT_NO_RST;
534 c4iw_ofld_send(rdev, skb);
535}
536
Hariprasad Sfef44222016-05-05 01:27:33 +0530537static int send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700538{
539 unsigned int flowclen = 80;
540 struct fw_flowc_wr *flowc;
541 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530542 u16 vlan = ep->l2t->vlan;
543 int nparams;
544
545 if (vlan == CPL_L2T_VLAN_NONE)
546 nparams = 8;
547 else
548 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700549
550 skb = get_skb(skb, flowclen, GFP_KERNEL);
551 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
552
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530553 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530554 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530555 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(flowclen,
556 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700557
558 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530559 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530560 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700561 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
562 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
563 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
564 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
565 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
566 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
567 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
568 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
569 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
570 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
571 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530572 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700573 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
574 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530575 if (nparams == 9) {
576 u16 pri;
577
578 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
579 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
580 flowc->mnemval[8].val = cpu_to_be32(pri);
581 } else {
582 /* Pad WR to 16 byte boundary */
583 flowc->mnemval[8].mnemonic = 0;
584 flowc->mnemval[8].val = 0;
585 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700586 for (i = 0; i < 9; i++) {
587 flowc->mnemval[i].r4[0] = 0;
588 flowc->mnemval[i].r4[1] = 0;
589 flowc->mnemval[i].r4[2] = 0;
590 }
591
592 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530593 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700594}
595
596static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
597{
598 struct cpl_close_con_req *req;
599 struct sk_buff *skb;
600 int wrlen = roundup(sizeof *req, 16);
601
602 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
603 skb = get_skb(NULL, wrlen, gfp);
604 if (!skb) {
605 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
606 return -ENOMEM;
607 }
608 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
609 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
610 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
611 memset(req, 0, wrlen);
612 INIT_TP_WR(req, ep->hwtid);
613 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
614 ep->hwtid));
615 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
616}
617
618static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
619{
620 struct cpl_abort_req *req;
621 int wrlen = roundup(sizeof *req, 16);
622
623 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
624 skb = get_skb(skb, wrlen, gfp);
625 if (!skb) {
626 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
627 __func__);
628 return -ENOMEM;
629 }
630 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
631 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
632 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
633 memset(req, 0, wrlen);
634 INIT_TP_WR(req, ep->hwtid);
635 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
636 req->cmd = CPL_ABORT_SEND_RST;
637 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
638}
639
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530640static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530641 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530642{
Hariprasad S04524a42014-09-24 03:53:41 +0530643 unsigned short hdr_size = (ipv6 ?
644 sizeof(struct ipv6hdr) :
645 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530646 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530647 (use_ts ?
648 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530649 unsigned short data_size = mtu - hdr_size;
650
651 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
652}
653
Steve Wisecfdda9d2010-04-21 15:30:06 -0700654static int send_connect(struct c4iw_ep *ep)
655{
Hariprasad S963cab52015-09-23 17:19:27 +0530656 struct cpl_act_open_req *req = NULL;
657 struct cpl_t5_act_open_req *t5req = NULL;
658 struct cpl_t6_act_open_req *t6req = NULL;
659 struct cpl_act_open_req6 *req6 = NULL;
660 struct cpl_t5_act_open_req6 *t5req6 = NULL;
661 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700662 struct sk_buff *skb;
663 u64 opt0;
664 u32 opt2;
665 unsigned int mtu_idx;
666 int wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530667 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500668 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600669 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500670 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600671 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500672 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600673 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500674 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600675 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530676 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530677 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
678 u32 isn = (prandom_u32() & ~7UL) - 1;
679
680 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
681 case CHELSIO_T4:
682 sizev4 = sizeof(struct cpl_act_open_req);
683 sizev6 = sizeof(struct cpl_act_open_req6);
684 break;
685 case CHELSIO_T5:
686 sizev4 = sizeof(struct cpl_t5_act_open_req);
687 sizev6 = sizeof(struct cpl_t5_act_open_req6);
688 break;
689 case CHELSIO_T6:
690 sizev4 = sizeof(struct cpl_t6_act_open_req);
691 sizev6 = sizeof(struct cpl_t6_act_open_req6);
692 break;
693 default:
694 pr_err("T%d Chip is not supported\n",
695 CHELSIO_CHIP_VERSION(adapter_type));
696 return -EINVAL;
697 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530698
699 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
700 roundup(sizev4, 16) :
701 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700702
703 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
704
705 skb = get_skb(NULL, wrlen, GFP_KERNEL);
706 if (!skb) {
707 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
708 __func__);
709 return -ENOMEM;
710 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000711 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700712
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530713 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530714 enable_tcp_timestamps,
715 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700716 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530717
718 /*
719 * Specify the largest window that will fit in opt0. The
720 * remainder will be specified in the rx_data_ack.
721 */
722 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800723 if (win > RCV_BUFSIZ_M)
724 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530725
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800726 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800727 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800728 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800729 WND_SCALE_V(wscale) |
730 MSS_IDX_V(mtu_idx) |
731 L2T_IDX_V(ep->l2t->idx) |
732 TX_CHAN_V(ep->tx_chan) |
733 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530734 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800735 ULP_MODE_V(ULP_MODE_TCPDDP) |
736 RCV_BUFSIZ_V(win);
737 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800738 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800739 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700740 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800741 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700742 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800743 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700744 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800745 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530746 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
747 if (peer2peer)
748 isn += 4;
749
Anish Bhattd7990b02014-11-12 17:15:57 -0800750 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530751 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530752 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500753 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530754
755 if (ep->com.remote_addr.ss_family == AF_INET6)
756 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
757 (const u32 *)&la6->sin6_addr.s6_addr, 1);
758
Hariprasad S5dab6d32014-06-23 19:12:36 +0530759 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700760
Hariprasad S963cab52015-09-23 17:19:27 +0530761 if (ep->com.remote_addr.ss_family == AF_INET) {
762 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
763 case CHELSIO_T4:
764 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530765 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530766 break;
767 case CHELSIO_T5:
768 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
769 wrlen);
770 INIT_TP_WR(t5req, 0);
771 req = (struct cpl_act_open_req *)t5req;
772 break;
773 case CHELSIO_T6:
774 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
775 wrlen);
776 INIT_TP_WR(t6req, 0);
777 req = (struct cpl_act_open_req *)t6req;
778 t5req = (struct cpl_t5_act_open_req *)t6req;
779 break;
780 default:
781 pr_err("T%d Chip is not supported\n",
782 CHELSIO_CHIP_VERSION(adapter_type));
783 ret = -EINVAL;
784 goto clip_release;
785 }
786
787 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
788 ((ep->rss_qid<<14) | ep->atid)));
789 req->local_port = la->sin_port;
790 req->peer_port = ra->sin_port;
791 req->local_ip = la->sin_addr.s_addr;
792 req->peer_ip = ra->sin_addr.s_addr;
793 req->opt0 = cpu_to_be64(opt0);
794
795 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530796 req->params = cpu_to_be32(cxgb4_select_ntuple(
797 ep->com.dev->rdev.lldi.ports[0],
798 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530799 req->opt2 = cpu_to_be32(opt2);
800 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530801 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
802 cxgb4_select_ntuple(
803 ep->com.dev->rdev.lldi.ports[0],
804 ep->l2t)));
805 t5req->rsvd = cpu_to_be32(isn);
806 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
807 t5req->opt2 = cpu_to_be32(opt2);
808 }
809 } else {
810 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
811 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530812 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530813 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530814 break;
815 case CHELSIO_T5:
816 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
817 wrlen);
818 INIT_TP_WR(t5req6, 0);
819 req6 = (struct cpl_act_open_req6 *)t5req6;
820 break;
821 case CHELSIO_T6:
822 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
823 wrlen);
824 INIT_TP_WR(t6req6, 0);
825 req6 = (struct cpl_act_open_req6 *)t6req6;
826 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
827 break;
828 default:
829 pr_err("T%d Chip is not supported\n",
830 CHELSIO_CHIP_VERSION(adapter_type));
831 ret = -EINVAL;
832 goto clip_release;
833 }
834
835 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
836 ((ep->rss_qid<<14)|ep->atid)));
837 req6->local_port = la6->sin6_port;
838 req6->peer_port = ra6->sin6_port;
839 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
840 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
841 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
842 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
843 req6->opt0 = cpu_to_be64(opt0);
844
845 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530846 req6->params = cpu_to_be32(cxgb4_select_ntuple(
847 ep->com.dev->rdev.lldi.ports[0],
848 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530849 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530850 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530851 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
852 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530853 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530854 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530855 t5req6->rsvd = cpu_to_be32(isn);
856 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
857 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530858 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000859 }
860
Vipul Pandya793dad92012-12-10 09:30:56 +0000861 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530862 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530863clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530864 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
865 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
866 (const u32 *)&la6->sin6_addr.s6_addr, 1);
867 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700868}
869
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530870static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
871 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700872{
873 int mpalen, wrlen;
874 struct fw_ofld_tx_data_wr *req;
875 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530876 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700877
878 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
879
880 BUG_ON(skb_cloned(skb));
881
882 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530883 if (mpa_rev_to_use == 2)
884 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700885 wrlen = roundup(mpalen + sizeof *req, 16);
886 skb = get_skb(skb, wrlen, GFP_KERNEL);
887 if (!skb) {
888 connect_reply_upcall(ep, -ENOMEM);
889 return;
890 }
891 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
892
893 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
894 memset(req, 0, wrlen);
895 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530896 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
897 FW_WR_COMPL_F |
898 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700899 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530900 FW_WR_FLOWID_V(ep->hwtid) |
901 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700902 req->plen = cpu_to_be32(mpalen);
903 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530904 FW_OFLD_TX_DATA_WR_FLUSH_F |
905 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700906
907 mpa = (struct mpa_message *)(req + 1);
908 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
909 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530910 (markers_enabled ? MPA_MARKERS : 0) |
911 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700912 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530913 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530914 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530915 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530916 ep->retry_with_mpa_v1 = 0;
917 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700918
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530919 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700920 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
921 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530922 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
923 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530924 mpa_v2_params.ird = htons((u16)ep->ird);
925 mpa_v2_params.ord = htons((u16)ep->ord);
926
927 if (peer2peer) {
928 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
929 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
930 mpa_v2_params.ord |=
931 htons(MPA_V2_RDMA_WRITE_RTR);
932 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
933 mpa_v2_params.ord |=
934 htons(MPA_V2_RDMA_READ_RTR);
935 }
936 memcpy(mpa->private_data, &mpa_v2_params,
937 sizeof(struct mpa_v2_conn_params));
938
939 if (ep->plen)
940 memcpy(mpa->private_data +
941 sizeof(struct mpa_v2_conn_params),
942 ep->mpa_pkt + sizeof(*mpa), ep->plen);
943 } else
944 if (ep->plen)
945 memcpy(mpa->private_data,
946 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700947
948 /*
949 * Reference the mpa skb. This ensures the data area
950 * will remain in memory until the hw acks the tx.
951 * Function fw4_ack() will deref it.
952 */
953 skb_get(skb);
954 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
955 BUG_ON(ep->mpa_skb);
956 ep->mpa_skb = skb;
957 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
958 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530959 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700960 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530961 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700962 return;
963}
964
965static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
966{
967 int mpalen, wrlen;
968 struct fw_ofld_tx_data_wr *req;
969 struct mpa_message *mpa;
970 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530971 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700972
973 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
974
975 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530976 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
977 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700978 wrlen = roundup(mpalen + sizeof *req, 16);
979
980 skb = get_skb(NULL, wrlen, GFP_KERNEL);
981 if (!skb) {
982 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
983 return -ENOMEM;
984 }
985 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
986
987 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
988 memset(req, 0, wrlen);
989 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530990 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
991 FW_WR_COMPL_F |
992 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700993 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530994 FW_WR_FLOWID_V(ep->hwtid) |
995 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700996 req->plen = cpu_to_be32(mpalen);
997 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530998 FW_OFLD_TX_DATA_WR_FLUSH_F |
999 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001000
1001 mpa = (struct mpa_message *)(req + 1);
1002 memset(mpa, 0, sizeof(*mpa));
1003 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1004 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001005 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001006 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301007
1008 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1009 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001010 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1011 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301012 mpa_v2_params.ird = htons(((u16)ep->ird) |
1013 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1014 0));
1015 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1016 (p2p_type ==
1017 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1018 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1019 FW_RI_INIT_P2PTYPE_READ_REQ ?
1020 MPA_V2_RDMA_READ_RTR : 0) : 0));
1021 memcpy(mpa->private_data, &mpa_v2_params,
1022 sizeof(struct mpa_v2_conn_params));
1023
1024 if (ep->plen)
1025 memcpy(mpa->private_data +
1026 sizeof(struct mpa_v2_conn_params), pdata, plen);
1027 } else
1028 if (plen)
1029 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001030
1031 /*
1032 * Reference the mpa skb again. This ensures the data area
1033 * will remain in memory until the hw acks the tx.
1034 * Function fw4_ack() will deref it.
1035 */
1036 skb_get(skb);
1037 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1038 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1039 BUG_ON(ep->mpa_skb);
1040 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301041 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001042 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1043}
1044
1045static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1046{
1047 int mpalen, wrlen;
1048 struct fw_ofld_tx_data_wr *req;
1049 struct mpa_message *mpa;
1050 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301051 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001052
1053 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1054
1055 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301056 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1057 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001058 wrlen = roundup(mpalen + sizeof *req, 16);
1059
1060 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1061 if (!skb) {
1062 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1063 return -ENOMEM;
1064 }
1065 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1066
1067 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1068 memset(req, 0, wrlen);
1069 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301070 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1071 FW_WR_COMPL_F |
1072 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001073 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301074 FW_WR_FLOWID_V(ep->hwtid) |
1075 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001076 req->plen = cpu_to_be32(mpalen);
1077 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301078 FW_OFLD_TX_DATA_WR_FLUSH_F |
1079 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001080
1081 mpa = (struct mpa_message *)(req + 1);
1082 memset(mpa, 0, sizeof(*mpa));
1083 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1084 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
1085 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301086 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001087 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301088
1089 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1090 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001091 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1092 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301093 mpa_v2_params.ird = htons((u16)ep->ird);
1094 mpa_v2_params.ord = htons((u16)ep->ord);
1095 if (peer2peer && (ep->mpa_attr.p2p_type !=
1096 FW_RI_INIT_P2PTYPE_DISABLED)) {
1097 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1098
1099 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1100 mpa_v2_params.ord |=
1101 htons(MPA_V2_RDMA_WRITE_RTR);
1102 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1103 mpa_v2_params.ord |=
1104 htons(MPA_V2_RDMA_READ_RTR);
1105 }
1106
1107 memcpy(mpa->private_data, &mpa_v2_params,
1108 sizeof(struct mpa_v2_conn_params));
1109
1110 if (ep->plen)
1111 memcpy(mpa->private_data +
1112 sizeof(struct mpa_v2_conn_params), pdata, plen);
1113 } else
1114 if (plen)
1115 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001116
1117 /*
1118 * Reference the mpa skb. This ensures the data area
1119 * will remain in memory until the hw acks the tx.
1120 * Function fw4_ack() will deref it.
1121 */
1122 skb_get(skb);
1123 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1124 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301125 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301126 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001127 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1128}
1129
1130static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1131{
1132 struct c4iw_ep *ep;
1133 struct cpl_act_establish *req = cplhdr(skb);
1134 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001135 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001136 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301137 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001138
1139 ep = lookup_atid(t, atid);
1140
1141 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1142 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1143
Steve Wisea7db89e2014-03-21 20:40:35 +05301144 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001145 dst_confirm(ep->dst);
1146
1147 /* setup the hwtid for this connection */
1148 ep->hwtid = tid;
1149 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001150 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001151
1152 ep->snd_seq = be32_to_cpu(req->snd_isn);
1153 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1154
1155 set_emss(ep, ntohs(req->tcp_opt));
1156
1157 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001158 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001159 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001160 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001161
1162 /* start MPA negotiation */
Hariprasad Sfef44222016-05-05 01:27:33 +05301163 ret = send_flowc(ep, NULL);
1164 if (ret)
1165 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301166 if (ep->retry_with_mpa_v1)
1167 send_mpa_req(ep, skb, 1);
1168 else
1169 send_mpa_req(ep, skb, mpa_rev);
Steve Wisea7db89e2014-03-21 20:40:35 +05301170 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001171 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301172err:
1173 mutex_unlock(&ep->com.mutex);
1174 connect_reply_upcall(ep, -ENOMEM);
1175 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1176 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001177}
1178
Steve Wisebe13b2d2014-03-21 20:40:33 +05301179static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001180{
1181 struct iw_cm_event event;
1182
1183 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1184 memset(&event, 0, sizeof(event));
1185 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301186 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001187 if (ep->com.cm_id) {
1188 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1189 ep, ep->com.cm_id, ep->hwtid);
1190 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301191 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001192 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001193 }
1194}
1195
Steve Wisecfdda9d2010-04-21 15:30:06 -07001196static void peer_close_upcall(struct c4iw_ep *ep)
1197{
1198 struct iw_cm_event event;
1199
1200 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1201 memset(&event, 0, sizeof(event));
1202 event.event = IW_CM_EVENT_DISCONNECT;
1203 if (ep->com.cm_id) {
1204 PDBG("peer close 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);
Vipul Pandya793dad92012-12-10 09:30:56 +00001207 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001208 }
1209}
1210
1211static void peer_abort_upcall(struct c4iw_ep *ep)
1212{
1213 struct iw_cm_event event;
1214
1215 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1216 memset(&event, 0, sizeof(event));
1217 event.event = IW_CM_EVENT_CLOSE;
1218 event.status = -ECONNRESET;
1219 if (ep->com.cm_id) {
1220 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1221 ep->com.cm_id, ep->hwtid);
1222 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301223 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001224 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001225 }
1226}
1227
1228static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1229{
1230 struct iw_cm_event event;
1231
1232 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1233 memset(&event, 0, sizeof(event));
1234 event.event = IW_CM_EVENT_CONNECT_REPLY;
1235 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301236 memcpy(&event.local_addr, &ep->com.local_addr,
1237 sizeof(ep->com.local_addr));
1238 memcpy(&event.remote_addr, &ep->com.remote_addr,
1239 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001240
1241 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301242 if (!ep->tried_with_mpa_v1) {
1243 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301244 event.ord = ep->ird;
1245 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301246 event.private_data_len = ep->plen -
1247 sizeof(struct mpa_v2_conn_params);
1248 event.private_data = ep->mpa_pkt +
1249 sizeof(struct mpa_message) +
1250 sizeof(struct mpa_v2_conn_params);
1251 } else {
1252 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301253 event.ord = cur_max_read_depth(ep->com.dev);
1254 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301255 event.private_data_len = ep->plen;
1256 event.private_data = ep->mpa_pkt +
1257 sizeof(struct mpa_message);
1258 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001259 }
Roland Dreier85963e42010-07-19 13:13:09 -07001260
1261 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1262 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001263 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001264 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1265
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301266 if (status < 0)
1267 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001268}
1269
Steve Wisebe13b2d2014-03-21 20:40:33 +05301270static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001271{
1272 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301273 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001274
1275 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1276 memset(&event, 0, sizeof(event));
1277 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301278 memcpy(&event.local_addr, &ep->com.local_addr,
1279 sizeof(ep->com.local_addr));
1280 memcpy(&event.remote_addr, &ep->com.remote_addr,
1281 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001282 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301283 if (!ep->tried_with_mpa_v1) {
1284 /* this means MPA_v2 is used */
1285 event.ord = ep->ord;
1286 event.ird = ep->ird;
1287 event.private_data_len = ep->plen -
1288 sizeof(struct mpa_v2_conn_params);
1289 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1290 sizeof(struct mpa_v2_conn_params);
1291 } else {
1292 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301293 event.ord = cur_max_read_depth(ep->com.dev);
1294 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301295 event.private_data_len = ep->plen;
1296 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1297 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301298 c4iw_get_ep(&ep->com);
1299 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1300 &event);
1301 if (ret)
1302 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001303 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001304 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301305 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001306}
1307
1308static void established_upcall(struct c4iw_ep *ep)
1309{
1310 struct iw_cm_event event;
1311
1312 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1313 memset(&event, 0, sizeof(event));
1314 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301315 event.ird = ep->ord;
1316 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001317 if (ep->com.cm_id) {
1318 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1319 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001320 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001321 }
1322}
1323
1324static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1325{
1326 struct cpl_rx_data_ack *req;
1327 struct sk_buff *skb;
1328 int wrlen = roundup(sizeof *req, 16);
1329
1330 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1331 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1332 if (!skb) {
1333 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1334 return 0;
1335 }
1336
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301337 /*
1338 * If we couldn't specify the entire rcv window at connection setup
1339 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1340 * then add the overage in to the credits returned.
1341 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001342 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1343 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301344
Steve Wisecfdda9d2010-04-21 15:30:06 -07001345 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1346 memset(req, 0, wrlen);
1347 INIT_TP_WR(req, ep->hwtid);
1348 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1349 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001350 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301351 RX_DACK_CHANGE_F |
1352 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001353 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001354 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1355 return credits;
1356}
1357
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301358#define RELAXED_IRD_NEGOTIATION 1
1359
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301360/*
1361 * process_mpa_reply - process streaming mode MPA reply
1362 *
1363 * Returns:
1364 *
1365 * 0 upon success indicating a connect request was delivered to the ULP
1366 * or the mpa request is incomplete but valid so far.
1367 *
1368 * 1 if a failure requires the caller to close the connection.
1369 *
1370 * 2 if a failure requires the caller to abort the connection.
1371 */
Steve Wisecc18b932014-04-24 14:31:53 -05001372static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001373{
1374 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301375 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001376 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301377 u16 resp_ird, resp_ord;
1378 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001379 struct c4iw_qp_attributes attrs;
1380 enum c4iw_qp_attr_mask mask;
1381 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001382 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001383
1384 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1385
1386 /*
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001387 * Stop mpa timer. If it expired, then
1388 * we ignore the MPA reply. process_timeout()
1389 * will abort the connection.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001390 */
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001391 if (stop_ep_timer(ep))
Steve Wisecc18b932014-04-24 14:31:53 -05001392 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001393
1394 /*
1395 * If we get more than the supported amount of private data
1396 * then we must fail this connection.
1397 */
1398 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1399 err = -EINVAL;
1400 goto err;
1401 }
1402
1403 /*
1404 * copy the new data into our accumulation buffer.
1405 */
1406 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1407 skb->len);
1408 ep->mpa_pkt_len += skb->len;
1409
1410 /*
1411 * if we don't even have the mpa message, then bail.
1412 */
1413 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001414 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001415 mpa = (struct mpa_message *) ep->mpa_pkt;
1416
1417 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301418 if (mpa->revision > mpa_rev) {
1419 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1420 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001421 err = -EPROTO;
1422 goto err;
1423 }
1424 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1425 err = -EPROTO;
1426 goto err;
1427 }
1428
1429 plen = ntohs(mpa->private_data_size);
1430
1431 /*
1432 * Fail if there's too much private data.
1433 */
1434 if (plen > MPA_MAX_PRIVATE_DATA) {
1435 err = -EPROTO;
1436 goto err;
1437 }
1438
1439 /*
1440 * If plen does not account for pkt size
1441 */
1442 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1443 err = -EPROTO;
1444 goto err;
1445 }
1446
1447 ep->plen = (u8) plen;
1448
1449 /*
1450 * If we don't have all the pdata yet, then bail.
1451 * We'll continue process when more data arrives.
1452 */
1453 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001454 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001455
1456 if (mpa->flags & MPA_REJECT) {
1457 err = -ECONNREFUSED;
1458 goto err;
1459 }
1460
1461 /*
1462 * If we get here we have accumulated the entire mpa
1463 * start reply message including private data. And
1464 * the MPA header is valid.
1465 */
Steve Wisec529fb52014-03-21 20:40:37 +05301466 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001467 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1468 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1469 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301470 ep->mpa_attr.version = mpa->revision;
1471 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1472
1473 if (mpa->revision == 2) {
1474 ep->mpa_attr.enhanced_rdma_conn =
1475 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1476 if (ep->mpa_attr.enhanced_rdma_conn) {
1477 mpa_v2_params = (struct mpa_v2_conn_params *)
1478 (ep->mpa_pkt + sizeof(*mpa));
1479 resp_ird = ntohs(mpa_v2_params->ird) &
1480 MPA_V2_IRD_ORD_MASK;
1481 resp_ord = ntohs(mpa_v2_params->ord) &
1482 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301483 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1484 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301485
1486 /*
1487 * This is a double-check. Ideally, below checks are
1488 * not required since ird/ord stuff has been taken
1489 * care of in c4iw_accept_cr
1490 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301491 if (ep->ird < resp_ord) {
1492 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1493 ep->com.dev->rdev.lldi.max_ordird_qp)
1494 ep->ird = resp_ord;
1495 else
1496 insuff_ird = 1;
1497 } else if (ep->ird > resp_ord) {
1498 ep->ird = resp_ord;
1499 }
1500 if (ep->ord > resp_ird) {
1501 if (RELAXED_IRD_NEGOTIATION)
1502 ep->ord = resp_ird;
1503 else
1504 insuff_ird = 1;
1505 }
1506 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301507 err = -ENOMEM;
1508 ep->ird = resp_ord;
1509 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301510 }
1511
1512 if (ntohs(mpa_v2_params->ird) &
1513 MPA_V2_PEER2PEER_MODEL) {
1514 if (ntohs(mpa_v2_params->ord) &
1515 MPA_V2_RDMA_WRITE_RTR)
1516 ep->mpa_attr.p2p_type =
1517 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1518 else if (ntohs(mpa_v2_params->ord) &
1519 MPA_V2_RDMA_READ_RTR)
1520 ep->mpa_attr.p2p_type =
1521 FW_RI_INIT_P2PTYPE_READ_REQ;
1522 }
1523 }
1524 } else if (mpa->revision == 1)
1525 if (peer2peer)
1526 ep->mpa_attr.p2p_type = p2p_type;
1527
Steve Wisecfdda9d2010-04-21 15:30:06 -07001528 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301529 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1530 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1531 ep->mpa_attr.recv_marker_enabled,
1532 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1533 ep->mpa_attr.p2p_type, p2p_type);
1534
1535 /*
1536 * If responder's RTR does not match with that of initiator, assign
1537 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1538 * generated when moving QP to RTS state.
1539 * A TERM message will be sent after QP has moved to RTS state
1540 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001541 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301542 (ep->mpa_attr.p2p_type != p2p_type)) {
1543 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1544 rtr_mismatch = 1;
1545 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001546
1547 attrs.mpa_attr = ep->mpa_attr;
1548 attrs.max_ird = ep->ird;
1549 attrs.max_ord = ep->ord;
1550 attrs.llp_stream_handle = ep;
1551 attrs.next_state = C4IW_QP_STATE_RTS;
1552
1553 mask = C4IW_QP_ATTR_NEXT_STATE |
1554 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1555 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1556
1557 /* bind QP and TID with INIT_WR */
1558 err = c4iw_modify_qp(ep->com.qp->rhp,
1559 ep->com.qp, mask, &attrs, 1);
1560 if (err)
1561 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301562
1563 /*
1564 * If responder's RTR requirement did not match with what initiator
1565 * supports, generate TERM message
1566 */
1567 if (rtr_mismatch) {
1568 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1569 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1570 attrs.ecode = MPA_NOMATCH_RTR;
1571 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001572 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301573 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001574 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301575 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001576 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301577 goto out;
1578 }
1579
1580 /*
1581 * Generate TERM if initiator IRD is not sufficient for responder
1582 * provided ORD. Currently, we do the same behaviour even when
1583 * responder provided IRD is also not sufficient as regards to
1584 * initiator ORD.
1585 */
1586 if (insuff_ird) {
1587 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1588 __func__);
1589 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1590 attrs.ecode = MPA_INSUFF_IRD;
1591 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001592 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301593 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001594 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301595 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001596 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301597 goto out;
1598 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001599 goto out;
1600err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301601 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001602out:
1603 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001604 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001605}
1606
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301607/*
1608 * process_mpa_request - process streaming mode MPA request
1609 *
1610 * Returns:
1611 *
1612 * 0 upon success indicating a connect request was delivered to the ULP
1613 * or the mpa request is incomplete but valid so far.
1614 *
1615 * 1 if a failure requires the caller to close the connection.
1616 *
1617 * 2 if a failure requires the caller to abort the connection.
1618 */
1619static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001620{
1621 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301622 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001623 u16 plen;
1624
1625 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1626
Steve Wisecfdda9d2010-04-21 15:30:06 -07001627 /*
1628 * If we get more than the supported amount of private data
1629 * then we must fail this connection.
1630 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301631 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1632 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001633
1634 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1635
1636 /*
1637 * Copy the new data into our accumulation buffer.
1638 */
1639 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1640 skb->len);
1641 ep->mpa_pkt_len += skb->len;
1642
1643 /*
1644 * If we don't even have the mpa message, then bail.
1645 * We'll continue process when more data arrives.
1646 */
1647 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301648 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001649
1650 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001651 mpa = (struct mpa_message *) ep->mpa_pkt;
1652
1653 /*
1654 * Validate MPA Header.
1655 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301656 if (mpa->revision > mpa_rev) {
1657 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1658 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301659 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001660 }
1661
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301662 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1663 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001664
1665 plen = ntohs(mpa->private_data_size);
1666
1667 /*
1668 * Fail if there's too much private data.
1669 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301670 if (plen > MPA_MAX_PRIVATE_DATA)
1671 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001672
1673 /*
1674 * If plen does not account for pkt size
1675 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301676 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1677 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001678 ep->plen = (u8) plen;
1679
1680 /*
1681 * If we don't have all the pdata yet, then bail.
1682 */
1683 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301684 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001685
1686 /*
1687 * If we get here we have accumulated the entire mpa
1688 * start reply message including private data.
1689 */
1690 ep->mpa_attr.initiator = 0;
1691 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1692 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1693 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301694 ep->mpa_attr.version = mpa->revision;
1695 if (mpa->revision == 1)
1696 ep->tried_with_mpa_v1 = 1;
1697 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1698
1699 if (mpa->revision == 2) {
1700 ep->mpa_attr.enhanced_rdma_conn =
1701 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1702 if (ep->mpa_attr.enhanced_rdma_conn) {
1703 mpa_v2_params = (struct mpa_v2_conn_params *)
1704 (ep->mpa_pkt + sizeof(*mpa));
1705 ep->ird = ntohs(mpa_v2_params->ird) &
1706 MPA_V2_IRD_ORD_MASK;
1707 ep->ord = ntohs(mpa_v2_params->ord) &
1708 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301709 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1710 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301711 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1712 if (peer2peer) {
1713 if (ntohs(mpa_v2_params->ord) &
1714 MPA_V2_RDMA_WRITE_RTR)
1715 ep->mpa_attr.p2p_type =
1716 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1717 else if (ntohs(mpa_v2_params->ord) &
1718 MPA_V2_RDMA_READ_RTR)
1719 ep->mpa_attr.p2p_type =
1720 FW_RI_INIT_P2PTYPE_READ_REQ;
1721 }
1722 }
1723 } else if (mpa->revision == 1)
1724 if (peer2peer)
1725 ep->mpa_attr.p2p_type = p2p_type;
1726
Steve Wisecfdda9d2010-04-21 15:30:06 -07001727 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1728 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1729 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1730 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1731 ep->mpa_attr.p2p_type);
1732
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001733 /*
1734 * If the endpoint timer already expired, then we ignore
1735 * the start request. process_timeout() will abort
1736 * the connection.
1737 */
1738 if (!stop_ep_timer(ep)) {
1739 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001740
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001741 /* drive upcall */
Hariprasad Shenai10be6b42014-11-21 09:36:35 -06001742 mutex_lock_nested(&ep->parent_ep->com.mutex,
1743 SINGLE_DEPTH_NESTING);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001744 if (ep->parent_ep->com.state != DEAD) {
1745 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301746 goto err_unlock_parent;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001747 } else {
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301748 goto err_unlock_parent;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001749 }
1750 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301751 }
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301752 return 0;
1753
1754err_unlock_parent:
1755 mutex_unlock(&ep->parent_ep->com.mutex);
1756 goto err_out;
1757err_stop_timer:
1758 (void)stop_ep_timer(ep);
1759err_out:
1760 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001761}
1762
1763static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1764{
1765 struct c4iw_ep *ep;
1766 struct cpl_rx_data *hdr = cplhdr(skb);
1767 unsigned int dlen = ntohs(hdr->len);
1768 unsigned int tid = GET_TID(hdr);
1769 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001770 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001771 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001772
1773 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301774 if (!ep)
1775 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001776 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1777 skb_pull(skb, sizeof(*hdr));
1778 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301779 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001780
Steve Wisecfdda9d2010-04-21 15:30:06 -07001781 /* update RX credits */
1782 update_rx_credits(ep, dlen);
1783
Steve Wisec529fb52014-03-21 20:40:37 +05301784 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001785 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001786 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001787 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001788 break;
1789 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001790 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001791 process_mpa_request(ep, skb);
1792 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001793 case FPDU_MODE: {
1794 struct c4iw_qp_attributes attrs;
1795 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001796 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001797 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001798 " qpid %u ep %p state %d tid %u status %d\n",
1799 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301800 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301801 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001802 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001803 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1804 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001805 break;
1806 }
Vipul Pandya15579672013-01-07 13:11:52 +00001807 default:
1808 break;
1809 }
Steve Wisec529fb52014-03-21 20:40:37 +05301810 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001811 if (disconnect)
1812 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001813 return 0;
1814}
1815
1816static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1817{
1818 struct c4iw_ep *ep;
1819 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001820 int release = 0;
1821 unsigned int tid = GET_TID(rpl);
1822 struct tid_info *t = dev->rdev.lldi.tids;
1823
1824 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301825 if (!ep) {
1826 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1827 return 0;
1828 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001829 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001830 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001831 switch (ep->com.state) {
1832 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001833 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001834 __state_set(&ep->com, DEAD);
1835 release = 1;
1836 break;
1837 default:
1838 printk(KERN_ERR "%s ep %p state %d\n",
1839 __func__, ep, ep->com.state);
1840 break;
1841 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001842 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001843
1844 if (release)
1845 release_ep_resources(ep);
1846 return 0;
1847}
1848
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001849static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1850{
1851 struct sk_buff *skb;
1852 struct fw_ofld_connection_wr *req;
1853 unsigned int mtu_idx;
1854 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301855 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301856 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001857
1858 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1859 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1860 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001861 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301862 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301863 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1864 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001865 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001866 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301867 req->le.lport = sin->sin_port;
1868 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001869 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301870 req->le.pport = sin->sin_port;
1871 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001872 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301873 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1874 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001875 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301876 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001877 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001878 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301879 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301880 enable_tcp_timestamps,
1881 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001882 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301883
1884 /*
1885 * Specify the largest window that will fit in opt0. The
1886 * remainder will be specified in the rx_data_ack.
1887 */
1888 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001889 if (win > RCV_BUFSIZ_M)
1890 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301891
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001892 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1893 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001894 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001895 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001896 WND_SCALE_V(wscale) |
1897 MSS_IDX_V(mtu_idx) |
1898 L2T_IDX_V(ep->l2t->idx) |
1899 TX_CHAN_V(ep->tx_chan) |
1900 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301901 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001902 ULP_MODE_V(ULP_MODE_TCPDDP) |
1903 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001904 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1905 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001906 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001907 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001908 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001909 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001910 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001911 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001912 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001913 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001914 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1915 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1916 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001917 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1918 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001919 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1920}
1921
Steve Wisecfdda9d2010-04-21 15:30:06 -07001922/*
1923 * Return whether a failed active open has allocated a TID
1924 */
1925static inline int act_open_has_tid(int status)
1926{
1927 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1928 status != CPL_ERR_ARP_MISS;
1929}
1930
Steve Wise7a2cea22014-03-14 21:52:07 +05301931/* Returns whether a CPL status conveys negative advice.
1932 */
1933static int is_neg_adv(unsigned int status)
1934{
1935 return status == CPL_ERR_RTX_NEG_ADVICE ||
1936 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1937 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1938}
1939
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301940static char *neg_adv_str(unsigned int status)
1941{
1942 switch (status) {
1943 case CPL_ERR_RTX_NEG_ADVICE:
1944 return "Retransmit timeout";
1945 case CPL_ERR_PERSIST_NEG_ADVICE:
1946 return "Persist timeout";
1947 case CPL_ERR_KEEPALV_NEG_ADVICE:
1948 return "Keepalive timeout";
1949 default:
1950 return "Unknown";
1951 }
1952}
1953
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301954static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1955{
1956 ep->snd_win = snd_win;
1957 ep->rcv_win = rcv_win;
1958 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1959}
1960
Vipul Pandya793dad92012-12-10 09:30:56 +00001961#define ACT_OPEN_RETRY_COUNT 2
1962
Vipul Pandya830662f2013-07-04 16:10:47 +05301963static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1964 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301965 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05301966{
1967 struct neighbour *n;
1968 int err, step;
1969 struct net_device *pdev;
1970
1971 n = dst_neigh_lookup(dst, peer_ip);
1972 if (!n)
1973 return -ENODEV;
1974
1975 rcu_read_lock();
1976 err = -ENOMEM;
1977 if (n->dev->flags & IFF_LOOPBACK) {
1978 if (iptype == 4)
1979 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1980 else if (IS_ENABLED(CONFIG_IPV6))
1981 for_each_netdev(&init_net, pdev) {
1982 if (ipv6_chk_addr(&init_net,
1983 (struct in6_addr *)peer_ip,
1984 pdev, 1))
1985 break;
1986 }
1987 else
1988 pdev = NULL;
1989
1990 if (!pdev) {
1991 err = -ENODEV;
1992 goto out;
1993 }
1994 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301995 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05301996 if (!ep->l2t)
1997 goto out;
1998 ep->mtu = pdev->mtu;
1999 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302000 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2001 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302002 step = cdev->rdev.lldi.ntxq /
2003 cdev->rdev.lldi.nchan;
2004 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2005 step = cdev->rdev.lldi.nrxq /
2006 cdev->rdev.lldi.nchan;
2007 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2008 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2009 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302010 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302011 dev_put(pdev);
2012 } else {
2013 pdev = get_real_dev(n->dev);
2014 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2015 n, pdev, 0);
2016 if (!ep->l2t)
2017 goto out;
2018 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002019 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302020 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2021 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302022 step = cdev->rdev.lldi.ntxq /
2023 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002024 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2025 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302026 step = cdev->rdev.lldi.nrxq /
2027 cdev->rdev.lldi.nchan;
2028 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002029 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302030 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302031
2032 if (clear_mpa_v1) {
2033 ep->retry_with_mpa_v1 = 0;
2034 ep->tried_with_mpa_v1 = 0;
2035 }
2036 }
2037 err = 0;
2038out:
2039 rcu_read_unlock();
2040
2041 neigh_release(n);
2042
2043 return err;
2044}
2045
Vipul Pandya793dad92012-12-10 09:30:56 +00002046static int c4iw_reconnect(struct c4iw_ep *ep)
2047{
2048 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302049 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002050 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302051 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002052 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302053 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002054 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302055 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002056 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302057 int iptype;
2058 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002059
2060 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2061 init_timer(&ep->timer);
2062
2063 /*
2064 * Allocate an active TID to initiate a TCP connection.
2065 */
2066 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2067 if (ep->atid == -1) {
2068 pr_err("%s - cannot alloc atid.\n", __func__);
2069 err = -ENOMEM;
2070 goto fail2;
2071 }
2072 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2073
2074 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002075 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302076 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2077 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302078 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302079 iptype = 4;
2080 ra = (__u8 *)&raddr->sin_addr;
2081 } else {
2082 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2083 raddr6->sin6_addr.s6_addr,
2084 laddr6->sin6_port, raddr6->sin6_port, 0,
2085 raddr6->sin6_scope_id);
2086 iptype = 6;
2087 ra = (__u8 *)&raddr6->sin6_addr;
2088 }
2089 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002090 pr_err("%s - cannot find route.\n", __func__);
2091 err = -EHOSTUNREACH;
2092 goto fail3;
2093 }
Hariprasad S963cab52015-09-23 17:19:27 +05302094 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302095 ep->com.dev->rdev.lldi.adapter_type,
2096 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302097 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002098 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002099 goto fail4;
2100 }
2101
2102 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2103 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2104 ep->l2t->idx);
2105
2106 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302107 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002108
2109 /* send connect request to rnic */
2110 err = send_connect(ep);
2111 if (!err)
2112 goto out;
2113
2114 cxgb4_l2t_release(ep->l2t);
2115fail4:
2116 dst_release(ep->dst);
2117fail3:
2118 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2119 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2120fail2:
2121 /*
2122 * remember to send notification to upper layer.
2123 * We are in here so the upper layer is not aware that this is
2124 * re-connect attempt and so, upper layer is still waiting for
2125 * response of 1st connect request.
2126 */
2127 connect_reply_upcall(ep, -ECONNRESET);
2128 c4iw_put_ep(&ep->com);
2129out:
2130 return err;
2131}
2132
Steve Wisecfdda9d2010-04-21 15:30:06 -07002133static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2134{
2135 struct c4iw_ep *ep;
2136 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002137 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2138 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002139 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002140 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302141 struct sockaddr_in *la;
2142 struct sockaddr_in *ra;
2143 struct sockaddr_in6 *la6;
2144 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002145
2146 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002147 la = (struct sockaddr_in *)&ep->com.local_addr;
2148 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2149 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2150 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002151
2152 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2153 status, status2errno(status));
2154
Steve Wise7a2cea22014-03-14 21:52:07 +05302155 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302156 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2157 __func__, atid, status, neg_adv_str(status));
2158 ep->stats.connect_neg_adv++;
2159 mutex_lock(&dev->rdev.stats.lock);
2160 dev->rdev.stats.neg_adv++;
2161 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002162 return 0;
2163 }
2164
Vipul Pandya793dad92012-12-10 09:30:56 +00002165 set_bit(ACT_OPEN_RPL, &ep->com.history);
2166
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302167 /*
2168 * Log interesting failures.
2169 */
2170 switch (status) {
2171 case CPL_ERR_CONN_RESET:
2172 case CPL_ERR_CONN_TIMEDOUT:
2173 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002174 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302175 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002176 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302177 mutex_unlock(&dev->rdev.stats.lock);
2178 if (ep->com.local_addr.ss_family == AF_INET &&
2179 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002180 send_fw_act_open_req(ep,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002181 TID_TID_G(AOPEN_ATID_G(
Vipul Pandya793dad92012-12-10 09:30:56 +00002182 ntohl(rpl->atid_status))));
2183 return 0;
2184 }
2185 break;
2186 case CPL_ERR_CONN_EXIST:
2187 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2188 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302189 if (ep->com.remote_addr.ss_family == AF_INET6) {
2190 struct sockaddr_in6 *sin6 =
2191 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002192 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302193 cxgb4_clip_release(
2194 ep->com.dev->rdev.lldi.ports[0],
2195 (const u32 *)
2196 &sin6->sin6_addr.s6_addr, 1);
2197 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002198 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2199 atid);
2200 cxgb4_free_atid(t, atid);
2201 dst_release(ep->dst);
2202 cxgb4_l2t_release(ep->l2t);
2203 c4iw_reconnect(ep);
2204 return 0;
2205 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002206 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302207 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302208 if (ep->com.local_addr.ss_family == AF_INET) {
2209 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2210 atid, status, status2errno(status),
2211 &la->sin_addr.s_addr, ntohs(la->sin_port),
2212 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2213 } else {
2214 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2215 atid, status, status2errno(status),
2216 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2217 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2218 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302219 break;
2220 }
2221
Steve Wisecfdda9d2010-04-21 15:30:06 -07002222 connect_reply_upcall(ep, status2errno(status));
2223 state_set(&ep->com, DEAD);
2224
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302225 if (ep->com.remote_addr.ss_family == AF_INET6) {
2226 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002227 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302228 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2229 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2230 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002231 if (status && act_open_has_tid(status))
2232 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2233
Vipul Pandya793dad92012-12-10 09:30:56 +00002234 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002235 cxgb4_free_atid(t, atid);
2236 dst_release(ep->dst);
2237 cxgb4_l2t_release(ep->l2t);
2238 c4iw_put_ep(&ep->com);
2239
2240 return 0;
2241}
2242
2243static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2244{
2245 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2246 struct tid_info *t = dev->rdev.lldi.tids;
2247 unsigned int stid = GET_TID(rpl);
2248 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2249
2250 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002251 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2252 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002253 }
2254 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2255 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002256 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002257
Vipul Pandya1cab7752012-12-10 09:30:55 +00002258out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002259 return 0;
2260}
2261
Steve Wisecfdda9d2010-04-21 15:30:06 -07002262static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2263{
2264 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2265 struct tid_info *t = dev->rdev.lldi.tids;
2266 unsigned int stid = GET_TID(rpl);
2267 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2268
2269 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002270 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002271 return 0;
2272}
2273
Hariprasad S9dec9002016-05-05 01:27:29 +05302274static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2275 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002276{
2277 struct cpl_pass_accept_rpl *rpl;
2278 unsigned int mtu_idx;
2279 u64 opt0;
2280 u32 opt2;
2281 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302282 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302283 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302284 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002285
2286 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2287 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302288
Steve Wisecfdda9d2010-04-21 15:30:06 -07002289 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302290 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302291 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302292 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2293 rpl5 = (void *)rpl;
2294 INIT_TP_WR(rpl5, ep->hwtid);
2295 } else {
2296 skb_trim(skb, sizeof(*rpl));
2297 INIT_TP_WR(rpl, ep->hwtid);
2298 }
2299 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2300 ep->hwtid));
2301
2302 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302303 enable_tcp_timestamps && req->tcpopt.tstamp,
2304 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002305 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302306
2307 /*
2308 * Specify the largest window that will fit in opt0. The
2309 * remainder will be specified in the rx_data_ack.
2310 */
2311 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002312 if (win > RCV_BUFSIZ_M)
2313 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002314 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002315 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002316 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002317 WND_SCALE_V(wscale) |
2318 MSS_IDX_V(mtu_idx) |
2319 L2T_IDX_V(ep->l2t->idx) |
2320 TX_CHAN_V(ep->tx_chan) |
2321 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002322 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002323 ULP_MODE_V(ULP_MODE_TCPDDP) |
2324 RCV_BUFSIZ_V(win);
2325 opt2 = RX_CHANNEL_V(0) |
2326 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002327
2328 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002329 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002330 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002331 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002332 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002333 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002334 if (enable_ecn) {
2335 const struct tcphdr *tcph;
2336 u32 hlen = ntohl(req->hdr_len);
2337
Hariprasad S963cab52015-09-23 17:19:27 +05302338 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2339 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2340 IP_HDR_LEN_G(hlen);
2341 else
2342 tcph = (const void *)(req + 1) +
2343 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002344 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002345 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002346 }
Hariprasad S963cab52015-09-23 17:19:27 +05302347 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302348 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002349 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302350 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302351 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302352 rpl5 = (void *)rpl;
2353 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2354 if (peer2peer)
2355 isn += 4;
2356 rpl5->iss = cpu_to_be32(isn);
2357 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002358 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002359
Steve Wisecfdda9d2010-04-21 15:30:06 -07002360 rpl->opt0 = cpu_to_be64(opt0);
2361 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002362 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302363 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002364
Hariprasad S9dec9002016-05-05 01:27:29 +05302365 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002366}
2367
Vipul Pandya830662f2013-07-04 16:10:47 +05302368static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002369{
Vipul Pandya830662f2013-07-04 16:10:47 +05302370 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002371 BUG_ON(skb_cloned(skb));
2372 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002373 release_tid(&dev->rdev, hwtid, skb);
2374 return;
2375}
2376
Hariprasad S963cab52015-09-23 17:19:27 +05302377static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2378 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002379 __be16 *local_port, __be16 *peer_port)
2380{
Hariprasad S963cab52015-09-23 17:19:27 +05302381 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2382 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2383 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2384 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2385 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2386 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002387 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302388 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002389 struct tcphdr *tcp = (struct tcphdr *)
2390 ((u8 *)(req + 1) + eth_len + ip_len);
2391
Vipul Pandya830662f2013-07-04 16:10:47 +05302392 if (ip->version == 4) {
2393 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2394 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2395 ntohs(tcp->dest));
2396 *iptype = 4;
2397 memcpy(peer_ip, &ip->saddr, 4);
2398 memcpy(local_ip, &ip->daddr, 4);
2399 } else {
2400 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2401 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2402 ntohs(tcp->dest));
2403 *iptype = 6;
2404 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2405 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2406 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002407 *peer_port = tcp->source;
2408 *local_port = tcp->dest;
2409
2410 return;
2411}
2412
2413static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2414{
Vipul Pandya793dad92012-12-10 09:30:56 +00002415 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002416 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002417 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002418 struct tid_info *t = dev->rdev.lldi.tids;
2419 unsigned int hwtid = GET_TID(req);
2420 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302421 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002422 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302423 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002424 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002425 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302426 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302427 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302428 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002429
2430 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002431 if (!parent_ep) {
2432 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2433 goto reject;
2434 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002435
Steve Wisecfdda9d2010-04-21 15:30:06 -07002436 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302437 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002438 goto reject;
2439 }
2440
Hariprasad S963cab52015-09-23 17:19:27 +05302441 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2442 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302443
Steve Wisecfdda9d2010-04-21 15:30:06 -07002444 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302445 if (iptype == 4) {
2446 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2447 , __func__, parent_ep, hwtid,
2448 local_ip, peer_ip, ntohs(local_port),
2449 ntohs(peer_port), peer_mss);
2450 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2451 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302452 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302453 } else {
2454 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2455 , __func__, parent_ep, hwtid,
2456 local_ip, peer_ip, ntohs(local_port),
2457 ntohs(peer_port), peer_mss);
2458 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002459 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302460 ((struct sockaddr_in6 *)
2461 &parent_ep->com.local_addr)->sin6_scope_id);
2462 }
2463 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002464 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2465 __func__);
2466 goto reject;
2467 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002468
2469 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2470 if (!child_ep) {
2471 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2472 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002473 dst_release(dst);
2474 goto reject;
2475 }
David Miller3786cf12011-12-02 16:52:31 +00002476
Hariprasad S963cab52015-09-23 17:19:27 +05302477 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302478 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002479 if (err) {
2480 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2481 __func__);
2482 dst_release(dst);
2483 kfree(child_ep);
2484 goto reject;
2485 }
2486
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302487 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2488 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2489 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2490 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002491
Steve Wisecfdda9d2010-04-21 15:30:06 -07002492 state_set(&child_ep->com, CONNECTING);
2493 child_ep->com.dev = dev;
2494 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002495
Vipul Pandya830662f2013-07-04 16:10:47 +05302496 if (iptype == 4) {
2497 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002498 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002499
Vipul Pandya830662f2013-07-04 16:10:47 +05302500 sin->sin_family = PF_INET;
2501 sin->sin_port = local_port;
2502 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002503
2504 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2505 sin->sin_family = PF_INET;
2506 sin->sin_port = ((struct sockaddr_in *)
2507 &parent_ep->com.local_addr)->sin_port;
2508 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2509
Steve Wise170003c2016-02-26 09:18:03 -06002510 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302511 sin->sin_family = PF_INET;
2512 sin->sin_port = peer_port;
2513 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2514 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002515 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302516 sin6->sin6_family = PF_INET6;
2517 sin6->sin6_port = local_port;
2518 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002519
2520 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2521 sin6->sin6_family = PF_INET6;
2522 sin6->sin6_port = ((struct sockaddr_in6 *)
2523 &parent_ep->com.local_addr)->sin6_port;
2524 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2525
Steve Wise170003c2016-02-26 09:18:03 -06002526 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302527 sin6->sin6_family = PF_INET6;
2528 sin6->sin6_port = peer_port;
2529 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2530 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002531
Steve Wisecfdda9d2010-04-21 15:30:06 -07002532 c4iw_get_ep(&parent_ep->com);
2533 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302534 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002535 child_ep->dst = dst;
2536 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002537
2538 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002539 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002540
2541 init_timer(&child_ep->timer);
2542 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002543 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Hariprasad S9dec9002016-05-05 01:27:29 +05302544 if (accept_cr(child_ep, skb, req)) {
2545 c4iw_put_ep(&parent_ep->com);
2546 release_ep_resources(child_ep);
2547 } else {
2548 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2549 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302550 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002551 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302552 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2553 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2554 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002555 goto out;
2556reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302557 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002558out:
2559 return 0;
2560}
2561
2562static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2563{
2564 struct c4iw_ep *ep;
2565 struct cpl_pass_establish *req = cplhdr(skb);
2566 struct tid_info *t = dev->rdev.lldi.tids;
2567 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302568 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002569
2570 ep = lookup_tid(t, tid);
2571 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2572 ep->snd_seq = be32_to_cpu(req->snd_isn);
2573 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2574
Vipul Pandya1cab7752012-12-10 09:30:55 +00002575 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2576 ntohs(req->tcp_opt));
2577
Steve Wisecfdda9d2010-04-21 15:30:06 -07002578 set_emss(ep, ntohs(req->tcp_opt));
2579
2580 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302581 mutex_lock(&ep->com.mutex);
2582 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002583 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002584 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad Sfef44222016-05-05 01:27:33 +05302585 ret = send_flowc(ep, skb);
2586 mutex_unlock(&ep->com.mutex);
2587 if (ret)
2588 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002589
2590 return 0;
2591}
2592
2593static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2594{
2595 struct cpl_peer_close *hdr = cplhdr(skb);
2596 struct c4iw_ep *ep;
2597 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002598 int disconnect = 1;
2599 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002600 struct tid_info *t = dev->rdev.lldi.tids;
2601 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002602 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002603
2604 ep = lookup_tid(t, tid);
2605 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2606 dst_confirm(ep->dst);
2607
Vipul Pandya793dad92012-12-10 09:30:56 +00002608 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002609 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002610 switch (ep->com.state) {
2611 case MPA_REQ_WAIT:
2612 __state_set(&ep->com, CLOSING);
2613 break;
2614 case MPA_REQ_SENT:
2615 __state_set(&ep->com, CLOSING);
2616 connect_reply_upcall(ep, -ECONNRESET);
2617 break;
2618 case MPA_REQ_RCVD:
2619
2620 /*
2621 * We're gonna mark this puppy DEAD, but keep
2622 * the reference on it until the ULP accepts or
2623 * rejects the CR. Also wake up anyone waiting
2624 * in rdma connection migration (see c4iw_accept_cr()).
2625 */
2626 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002627 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002628 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002629 break;
2630 case MPA_REP_SENT:
2631 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002632 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002633 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002634 break;
2635 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002636 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002637 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002638 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002639 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002640 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002641 if (ret != -ECONNRESET) {
2642 peer_close_upcall(ep);
2643 disconnect = 1;
2644 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002645 break;
2646 case ABORTING:
2647 disconnect = 0;
2648 break;
2649 case CLOSING:
2650 __state_set(&ep->com, MORIBUND);
2651 disconnect = 0;
2652 break;
2653 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002654 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002655 if (ep->com.cm_id && ep->com.qp) {
2656 attrs.next_state = C4IW_QP_STATE_IDLE;
2657 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2658 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2659 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302660 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002661 __state_set(&ep->com, DEAD);
2662 release = 1;
2663 disconnect = 0;
2664 break;
2665 case DEAD:
2666 disconnect = 0;
2667 break;
2668 default:
2669 BUG_ON(1);
2670 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002671 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002672 if (disconnect)
2673 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2674 if (release)
2675 release_ep_resources(ep);
2676 return 0;
2677}
2678
Steve Wisecfdda9d2010-04-21 15:30:06 -07002679static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2680{
2681 struct cpl_abort_req_rss *req = cplhdr(skb);
2682 struct c4iw_ep *ep;
2683 struct cpl_abort_rpl *rpl;
2684 struct sk_buff *rpl_skb;
2685 struct c4iw_qp_attributes attrs;
2686 int ret;
2687 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002688 struct tid_info *t = dev->rdev.lldi.tids;
2689 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002690
2691 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302692 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302693 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2694 __func__, ep->hwtid, req->status,
2695 neg_adv_str(req->status));
2696 ep->stats.abort_neg_adv++;
2697 mutex_lock(&dev->rdev.stats.lock);
2698 dev->rdev.stats.neg_adv++;
2699 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002700 return 0;
2701 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002702 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2703 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002704 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002705
2706 /*
2707 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302708 * However, this is not needed if com state is just
2709 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002710 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302711 if (ep->com.state != MPA_REQ_SENT)
2712 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002713
2714 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002715 switch (ep->com.state) {
2716 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302717 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002718 break;
2719 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002720 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002721 break;
2722 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002723 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002724 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302725 connect_reply_upcall(ep, -ECONNRESET);
2726 else {
2727 /*
2728 * we just don't send notification upwards because we
2729 * want to retry with mpa_v1 without upper layers even
2730 * knowing it.
2731 *
2732 * do some housekeeping so as to re-initiate the
2733 * connection
2734 */
2735 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2736 mpa_rev);
2737 ep->retry_with_mpa_v1 = 1;
2738 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002739 break;
2740 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002741 break;
2742 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002743 break;
2744 case MORIBUND:
2745 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002746 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002747 /*FALLTHROUGH*/
2748 case FPDU_MODE:
2749 if (ep->com.cm_id && ep->com.qp) {
2750 attrs.next_state = C4IW_QP_STATE_ERROR;
2751 ret = c4iw_modify_qp(ep->com.qp->rhp,
2752 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2753 &attrs, 1);
2754 if (ret)
2755 printk(KERN_ERR MOD
2756 "%s - qp <- error failed!\n",
2757 __func__);
2758 }
2759 peer_abort_upcall(ep);
2760 break;
2761 case ABORTING:
2762 break;
2763 case DEAD:
2764 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002765 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002766 return 0;
2767 default:
2768 BUG_ON(1);
2769 break;
2770 }
2771 dst_confirm(ep->dst);
2772 if (ep->com.state != ABORTING) {
2773 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302774 /* we don't release if we want to retry with mpa_v1 */
2775 if (!ep->retry_with_mpa_v1)
2776 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002777 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002778 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002779
2780 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2781 if (!rpl_skb) {
2782 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2783 __func__);
2784 release = 1;
2785 goto out;
2786 }
2787 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2788 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2789 INIT_TP_WR(rpl, ep->hwtid);
2790 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2791 rpl->cmd = CPL_ABORT_NO_RST;
2792 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2793out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002794 if (release)
2795 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002796 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302797 if (ep->com.remote_addr.ss_family == AF_INET6) {
2798 struct sockaddr_in6 *sin6 =
2799 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002800 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302801 cxgb4_clip_release(
2802 ep->com.dev->rdev.lldi.ports[0],
2803 (const u32 *)&sin6->sin6_addr.s6_addr,
2804 1);
2805 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002806 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302807 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2808 dst_release(ep->dst);
2809 cxgb4_l2t_release(ep->l2t);
2810 c4iw_reconnect(ep);
2811 }
2812
Steve Wisecfdda9d2010-04-21 15:30:06 -07002813 return 0;
2814}
2815
2816static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2817{
2818 struct c4iw_ep *ep;
2819 struct c4iw_qp_attributes attrs;
2820 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002821 int release = 0;
2822 struct tid_info *t = dev->rdev.lldi.tids;
2823 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002824
2825 ep = lookup_tid(t, tid);
2826
2827 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2828 BUG_ON(!ep);
2829
2830 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002831 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302832 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002833 switch (ep->com.state) {
2834 case CLOSING:
2835 __state_set(&ep->com, MORIBUND);
2836 break;
2837 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002838 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002839 if ((ep->com.cm_id) && (ep->com.qp)) {
2840 attrs.next_state = C4IW_QP_STATE_IDLE;
2841 c4iw_modify_qp(ep->com.qp->rhp,
2842 ep->com.qp,
2843 C4IW_QP_ATTR_NEXT_STATE,
2844 &attrs, 1);
2845 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302846 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002847 __state_set(&ep->com, DEAD);
2848 release = 1;
2849 break;
2850 case ABORTING:
2851 case DEAD:
2852 break;
2853 default:
2854 BUG_ON(1);
2855 break;
2856 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002857 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002858 if (release)
2859 release_ep_resources(ep);
2860 return 0;
2861}
2862
2863static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2864{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002865 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002866 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002867 unsigned int tid = GET_TID(rpl);
2868 struct c4iw_ep *ep;
2869 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002870
2871 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002872 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002873
Steve Wise30c95c22011-05-09 22:06:22 -07002874 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002875 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2876 ep->com.qp->wq.sq.qid);
2877 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2878 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2879 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2880 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002881 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002882
Steve Wisecfdda9d2010-04-21 15:30:06 -07002883 return 0;
2884}
2885
2886/*
2887 * Upcall from the adapter indicating data has been transmitted.
2888 * For us its just the single MPA request or reply. We can now free
2889 * the skb holding the mpa message.
2890 */
2891static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2892{
2893 struct c4iw_ep *ep;
2894 struct cpl_fw4_ack *hdr = cplhdr(skb);
2895 u8 credits = hdr->credits;
2896 unsigned int tid = GET_TID(hdr);
2897 struct tid_info *t = dev->rdev.lldi.tids;
2898
2899
2900 ep = lookup_tid(t, tid);
2901 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2902 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002903 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2904 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002905 return 0;
2906 }
2907
2908 dst_confirm(ep->dst);
2909 if (ep->mpa_skb) {
2910 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2911 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2912 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2913 kfree_skb(ep->mpa_skb);
2914 ep->mpa_skb = NULL;
2915 }
2916 return 0;
2917}
2918
Steve Wisecfdda9d2010-04-21 15:30:06 -07002919int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2920{
Steve Wisea7db89e2014-03-21 20:40:35 +05302921 int err = 0;
2922 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002923 struct c4iw_ep *ep = to_ep(cm_id);
2924 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2925
Steve Wisea7db89e2014-03-21 20:40:35 +05302926 mutex_lock(&ep->com.mutex);
2927 if (ep->com.state == DEAD) {
2928 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002929 c4iw_put_ep(&ep->com);
2930 return -ECONNRESET;
2931 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002932 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302933 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002934 if (mpa_rev == 0)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302935 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002936 else {
2937 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302938 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002939 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302940 mutex_unlock(&ep->com.mutex);
2941 if (disconnect)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302942 err = c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002943 c4iw_put_ep(&ep->com);
2944 return 0;
2945}
2946
2947int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2948{
2949 int err;
2950 struct c4iw_qp_attributes attrs;
2951 enum c4iw_qp_attr_mask mask;
2952 struct c4iw_ep *ep = to_ep(cm_id);
2953 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2954 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302955 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002956
2957 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302958
2959 mutex_lock(&ep->com.mutex);
2960 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002961 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302962 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002963 }
2964
Steve Wisea7db89e2014-03-21 20:40:35 +05302965 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002966 BUG_ON(!qp);
2967
Vipul Pandya793dad92012-12-10 09:30:56 +00002968 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302969 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2970 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002971 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302972 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002973 }
2974
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302975 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2976 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302977 if (RELAXED_IRD_NEGOTIATION) {
2978 ep->ord = ep->ird;
2979 } else {
2980 ep->ird = conn_param->ird;
2981 ep->ord = conn_param->ord;
2982 send_mpa_reject(ep, conn_param->private_data,
2983 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302984 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302985 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302986 }
2987 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302988 if (conn_param->ird < ep->ord) {
2989 if (RELAXED_IRD_NEGOTIATION &&
2990 ep->ord <= h->rdev.lldi.max_ordird_qp) {
2991 conn_param->ird = ep->ord;
2992 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302993 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302994 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302995 }
2996 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302997 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002998 ep->ird = conn_param->ird;
2999 ep->ord = conn_param->ord;
3000
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303001 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303002 if (peer2peer && ep->ird == 0)
3003 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303004 } else {
3005 if (peer2peer &&
3006 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303007 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303008 ep->ird = 1;
3009 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003010
3011 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3012
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303013 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303014 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303015 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003016 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303017
Steve Wisecfdda9d2010-04-21 15:30:06 -07003018 /* bind QP to EP and move to RTS */
3019 attrs.mpa_attr = ep->mpa_attr;
3020 attrs.max_ird = ep->ird;
3021 attrs.max_ord = ep->ord;
3022 attrs.llp_stream_handle = ep;
3023 attrs.next_state = C4IW_QP_STATE_RTS;
3024
3025 /* bind QP and TID with INIT_WR */
3026 mask = C4IW_QP_ATTR_NEXT_STATE |
3027 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3028 C4IW_QP_ATTR_MPA_ATTR |
3029 C4IW_QP_ATTR_MAX_IRD |
3030 C4IW_QP_ATTR_MAX_ORD;
3031
3032 err = c4iw_modify_qp(ep->com.qp->rhp,
3033 ep->com.qp, mask, &attrs, 1);
3034 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303035 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003036 err = send_mpa_reply(ep, conn_param->private_data,
3037 conn_param->private_data_len);
3038 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303039 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003040
Steve Wisea7db89e2014-03-21 20:40:35 +05303041 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003042 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303043 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003044 c4iw_put_ep(&ep->com);
3045 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303046err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303047 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303048err_abort:
3049 abort = 1;
3050err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303051 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303052 if (abort)
3053 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003054 c4iw_put_ep(&ep->com);
3055 return err;
3056}
3057
Vipul Pandya830662f2013-07-04 16:10:47 +05303058static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3059{
3060 struct in_device *ind;
3061 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003062 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3063 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303064
3065 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3066 if (!ind)
3067 return -EADDRNOTAVAIL;
3068 for_primary_ifa(ind) {
3069 laddr->sin_addr.s_addr = ifa->ifa_address;
3070 raddr->sin_addr.s_addr = ifa->ifa_address;
3071 found = 1;
3072 break;
3073 }
3074 endfor_ifa(ind);
3075 in_dev_put(ind);
3076 return found ? 0 : -EADDRNOTAVAIL;
3077}
3078
3079static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3080 unsigned char banned_flags)
3081{
3082 struct inet6_dev *idev;
3083 int err = -EADDRNOTAVAIL;
3084
3085 rcu_read_lock();
3086 idev = __in6_dev_get(dev);
3087 if (idev != NULL) {
3088 struct inet6_ifaddr *ifp;
3089
3090 read_lock_bh(&idev->lock);
3091 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3092 if (ifp->scope == IFA_LINK &&
3093 !(ifp->flags & banned_flags)) {
3094 memcpy(addr, &ifp->addr, 16);
3095 err = 0;
3096 break;
3097 }
3098 }
3099 read_unlock_bh(&idev->lock);
3100 }
3101 rcu_read_unlock();
3102 return err;
3103}
3104
3105static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3106{
3107 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003108 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3109 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303110
Nicholas Krause54b9a962015-08-26 23:00:59 -04003111 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303112 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3113 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3114 return 0;
3115 }
3116 return -EADDRNOTAVAIL;
3117}
3118
Steve Wisecfdda9d2010-04-21 15:30:06 -07003119int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3120{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003121 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3122 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003123 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003124 struct sockaddr_in *laddr;
3125 struct sockaddr_in *raddr;
3126 struct sockaddr_in6 *laddr6;
3127 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303128 __u8 *ra;
3129 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003130
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303131 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3132 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003133 err = -EINVAL;
3134 goto out;
3135 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003136 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3137 if (!ep) {
3138 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3139 err = -ENOMEM;
3140 goto out;
3141 }
3142 init_timer(&ep->timer);
3143 ep->plen = conn_param->private_data_len;
3144 if (ep->plen)
3145 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3146 conn_param->private_data, ep->plen);
3147 ep->ird = conn_param->ird;
3148 ep->ord = conn_param->ord;
3149
3150 if (peer2peer && ep->ord == 0)
3151 ep->ord = 1;
3152
Steve Wisecfdda9d2010-04-21 15:30:06 -07003153 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303154 ref_cm_id(&ep->com);
3155 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003156 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303157 if (!ep->com.qp) {
3158 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3159 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003160 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303161 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003162 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003163 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3164 ep->com.qp, cm_id);
3165
3166 /*
3167 * Allocate an active TID to initiate a TCP connection.
3168 */
3169 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3170 if (ep->atid == -1) {
3171 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3172 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003173 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003174 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003175 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003176
Steve Wise170003c2016-02-26 09:18:03 -06003177 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003178 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003179 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003180 sizeof(ep->com.remote_addr));
3181
Steve Wise170003c2016-02-26 09:18:03 -06003182 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3183 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3184 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3185 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003186
Steve Wise170003c2016-02-26 09:18:03 -06003187 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303188 iptype = 4;
3189 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003190
Vipul Pandya830662f2013-07-04 16:10:47 +05303191 /*
3192 * Handle loopback requests to INADDR_ANY.
3193 */
3194 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3195 err = pick_local_ipaddrs(dev, cm_id);
3196 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003197 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303198 }
3199
3200 /* find a route */
3201 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3202 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3203 ra, ntohs(raddr->sin_port));
3204 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3205 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303206 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303207 } else {
3208 iptype = 6;
3209 ra = (__u8 *)&raddr6->sin6_addr;
3210
3211 /*
3212 * Handle loopback requests to INADDR_ANY.
3213 */
3214 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3215 err = pick_local_ip6addrs(dev, cm_id);
3216 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003217 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303218 }
3219
3220 /* find a route */
3221 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3222 __func__, laddr6->sin6_addr.s6_addr,
3223 ntohs(laddr6->sin6_port),
3224 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3225 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3226 raddr6->sin6_addr.s6_addr,
3227 laddr6->sin6_port, raddr6->sin6_port, 0,
3228 raddr6->sin6_scope_id);
3229 }
3230 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003231 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3232 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003233 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003234 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003235
Hariprasad S963cab52015-09-23 17:19:27 +05303236 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303237 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003238 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003239 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003240 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003241 }
3242
3243 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3244 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3245 ep->l2t->idx);
3246
3247 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303248 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003249
3250 /* send connect request to rnic */
3251 err = send_connect(ep);
3252 if (!err)
3253 goto out;
3254
3255 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003256fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003257 dst_release(ep->dst);
3258fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003259 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003260 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003261fail1:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303262 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003263 c4iw_put_ep(&ep->com);
3264out:
3265 return err;
3266}
3267
Vipul Pandya830662f2013-07-04 16:10:47 +05303268static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3269{
3270 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003271 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003272 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303273
Hariprasad S28de1f72016-01-13 10:03:14 +05303274 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3275 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3276 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3277 if (err)
3278 return err;
3279 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303280 c4iw_init_wr_wait(&ep->com.wr_wait);
3281 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3282 ep->stid, &sin6->sin6_addr,
3283 sin6->sin6_port,
3284 ep->com.dev->rdev.lldi.rxq_ids[0]);
3285 if (!err)
3286 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3287 &ep->com.wr_wait,
3288 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303289 else if (err > 0)
3290 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303291 if (err) {
3292 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3293 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303294 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3295 err, ep->stid,
3296 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303297 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303298 return err;
3299}
3300
3301static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3302{
3303 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003304 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003305 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303306
3307 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3308 do {
3309 err = cxgb4_create_server_filter(
3310 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3311 sin->sin_addr.s_addr, sin->sin_port, 0,
3312 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3313 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303314 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3315 err = -EIO;
3316 break;
3317 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303318 set_current_state(TASK_UNINTERRUPTIBLE);
3319 schedule_timeout(usecs_to_jiffies(100));
3320 }
3321 } while (err == -EBUSY);
3322 } else {
3323 c4iw_init_wr_wait(&ep->com.wr_wait);
3324 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3325 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3326 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3327 if (!err)
3328 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3329 &ep->com.wr_wait,
3330 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303331 else if (err > 0)
3332 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303333 }
3334 if (err)
3335 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3336 , err, ep->stid,
3337 &sin->sin_addr, ntohs(sin->sin_port));
3338 return err;
3339}
3340
Steve Wisecfdda9d2010-04-21 15:30:06 -07003341int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3342{
3343 int err = 0;
3344 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3345 struct c4iw_listen_ep *ep;
3346
Steve Wisecfdda9d2010-04-21 15:30:06 -07003347 might_sleep();
3348
3349 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3350 if (!ep) {
3351 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3352 err = -ENOMEM;
3353 goto fail1;
3354 }
3355 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003356 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303357 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003358 ep->com.dev = dev;
3359 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003360 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303361 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003362
3363 /*
3364 * Allocate a server TID.
3365 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303366 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3367 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303368 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003369 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003370 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303371 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003372 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003373
Steve Wisecfdda9d2010-04-21 15:30:06 -07003374 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003375 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003376 err = -ENOMEM;
3377 goto fail2;
3378 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003379 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003380
Steve Wise170003c2016-02-26 09:18:03 -06003381 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3382 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003383
Steve Wisecfdda9d2010-04-21 15:30:06 -07003384 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303385 if (ep->com.local_addr.ss_family == AF_INET)
3386 err = create_server4(dev, ep);
3387 else
3388 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003389 if (!err) {
3390 cm_id->provider_data = ep;
3391 goto out;
3392 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003393
Vipul Pandya830662f2013-07-04 16:10:47 +05303394 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3395 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003396fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303397 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003398 c4iw_put_ep(&ep->com);
3399fail1:
3400out:
3401 return err;
3402}
3403
3404int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3405{
3406 int err;
3407 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3408
3409 PDBG("%s ep %p\n", __func__, ep);
3410
3411 might_sleep();
3412 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303413 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3414 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003415 err = cxgb4_remove_server_filter(
3416 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3417 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3418 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303419 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003420 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303421 err = cxgb4_remove_server(
3422 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3423 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003424 if (err)
3425 goto done;
3426 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3427 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003428 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303429 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3430 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003431 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003432 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303433 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3434 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003435done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303436 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003437 c4iw_put_ep(&ep->com);
3438 return err;
3439}
3440
3441int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3442{
3443 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003444 int close = 0;
3445 int fatal = 0;
3446 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003447
Steve Wise2f5b48c2010-09-10 11:15:36 -05003448 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003449
3450 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3451 states[ep->com.state], abrupt);
3452
Hariprasad S6e410d82016-05-05 01:27:31 +05303453 /*
3454 * Ref the ep here in case we have fatal errors causing the
3455 * ep to be released and freed.
3456 */
3457 c4iw_get_ep(&ep->com);
3458
Steve Wisecfdda9d2010-04-21 15:30:06 -07003459 rdev = &ep->com.dev->rdev;
3460 if (c4iw_fatal_error(rdev)) {
3461 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303462 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003463 ep->com.state = DEAD;
3464 }
3465 switch (ep->com.state) {
3466 case MPA_REQ_WAIT:
3467 case MPA_REQ_SENT:
3468 case MPA_REQ_RCVD:
3469 case MPA_REP_SENT:
3470 case FPDU_MODE:
3471 close = 1;
3472 if (abrupt)
3473 ep->com.state = ABORTING;
3474 else {
3475 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003476 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003477 }
3478 set_bit(CLOSE_SENT, &ep->com.flags);
3479 break;
3480 case CLOSING:
3481 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3482 close = 1;
3483 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003484 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003485 ep->com.state = ABORTING;
3486 } else
3487 ep->com.state = MORIBUND;
3488 }
3489 break;
3490 case MORIBUND:
3491 case ABORTING:
3492 case DEAD:
3493 PDBG("%s ignoring disconnect ep %p state %u\n",
3494 __func__, ep, ep->com.state);
3495 break;
3496 default:
3497 BUG();
3498 break;
3499 }
3500
Steve Wisecfdda9d2010-04-21 15:30:06 -07003501 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003502 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003503 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303504 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003505 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003506 } else {
3507 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003508 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003509 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303510 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303511 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303512 if (!abrupt) {
3513 stop_ep_timer(ep);
3514 close_complete_upcall(ep, -EIO);
3515 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303516 if (ep->com.qp) {
3517 struct c4iw_qp_attributes attrs;
3518
3519 attrs.next_state = C4IW_QP_STATE_ERROR;
3520 ret = c4iw_modify_qp(ep->com.qp->rhp,
3521 ep->com.qp,
3522 C4IW_QP_ATTR_NEXT_STATE,
3523 &attrs, 1);
3524 if (ret)
3525 pr_err(MOD
3526 "%s - qp <- error failed!\n",
3527 __func__);
3528 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003529 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303530 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003531 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003532 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303533 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003534 if (fatal)
3535 release_ep_resources(ep);
3536 return ret;
3537}
3538
Vipul Pandya1cab7752012-12-10 09:30:55 +00003539static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3540 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3541{
3542 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003543 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003544
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003545 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3546 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003547 if (!ep)
3548 return;
3549
3550 switch (req->retval) {
3551 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003552 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3553 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3554 send_fw_act_open_req(ep, atid);
3555 return;
3556 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003557 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003558 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3559 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3560 send_fw_act_open_req(ep, atid);
3561 return;
3562 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003563 break;
3564 default:
3565 pr_info("%s unexpected ofld conn wr retval %d\n",
3566 __func__, req->retval);
3567 break;
3568 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003569 pr_err("active ofld_connect_wr failure %d atid %d\n",
3570 req->retval, atid);
3571 mutex_lock(&dev->rdev.stats.lock);
3572 dev->rdev.stats.act_ofld_conn_fails++;
3573 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003574 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003575 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303576 if (ep->com.remote_addr.ss_family == AF_INET6) {
3577 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003578 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303579 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3580 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3581 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003582 remove_handle(dev, &dev->atid_idr, atid);
3583 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3584 dst_release(ep->dst);
3585 cxgb4_l2t_release(ep->l2t);
3586 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003587}
3588
3589static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3590 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3591{
3592 struct sk_buff *rpl_skb;
3593 struct cpl_pass_accept_req *cpl;
3594 int ret;
3595
Paul Bolle710a3112013-02-05 20:51:30 +00003596 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003597 BUG_ON(!rpl_skb);
3598 if (req->retval) {
3599 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003600 mutex_lock(&dev->rdev.stats.lock);
3601 dev->rdev.stats.pas_ofld_conn_fails++;
3602 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003603 kfree_skb(rpl_skb);
3604 } else {
3605 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3606 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003607 (__force u32) htonl(
3608 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003609 ret = pass_accept_req(dev, rpl_skb);
3610 if (!ret)
3611 kfree_skb(rpl_skb);
3612 }
3613 return;
3614}
3615
3616static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003617{
3618 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003619 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3620
3621 switch (rpl->type) {
3622 case FW6_TYPE_CQE:
3623 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3624 break;
3625 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3626 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3627 switch (req->t_state) {
3628 case TCP_SYN_SENT:
3629 active_ofld_conn_reply(dev, skb, req);
3630 break;
3631 case TCP_SYN_RECV:
3632 passive_ofld_conn_reply(dev, skb, req);
3633 break;
3634 default:
3635 pr_err("%s unexpected ofld conn wr state %d\n",
3636 __func__, req->t_state);
3637 break;
3638 }
3639 break;
3640 }
3641 return 0;
3642}
3643
3644static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3645{
Hariprasad S963cab52015-09-23 17:19:27 +05303646 __be32 l2info;
3647 __be16 hdr_len, vlantag, len;
3648 u16 eth_hdr_len;
3649 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003650 u8 intf;
3651 struct cpl_rx_pkt *cpl = cplhdr(skb);
3652 struct cpl_pass_accept_req *req;
3653 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003654 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303655 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003656
Vipul Pandyaf079af72013-03-14 05:08:58 +00003657 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003658 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303659 vlantag = cpl->vlan;
3660 len = cpl->len;
3661 l2info = cpl->l2info;
3662 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003663 intf = cpl->iff;
3664
3665 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3666
3667 /*
3668 * We need to parse the TCP options from SYN packet.
3669 * to generate cpl_pass_accept_req.
3670 */
3671 memset(&tmp_opt, 0, sizeof(tmp_opt));
3672 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003673 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003674
3675 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3676 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303677 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3678 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303679 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303680 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303681 type = dev->rdev.lldi.adapter_type;
3682 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3683 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3684 req->hdr_len =
3685 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3686 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3687 eth_hdr_len = is_t4(type) ?
3688 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3689 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3690 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3691 IP_HDR_LEN_V(ip_hdr_len) |
3692 ETH_HDR_LEN_V(eth_hdr_len));
3693 } else { /* T6 and later */
3694 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3695 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3696 T6_IP_HDR_LEN_V(ip_hdr_len) |
3697 T6_ETH_HDR_LEN_V(eth_hdr_len));
3698 }
3699 req->vlan = vlantag;
3700 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003701 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3702 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003703 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3704 if (tmp_opt.wscale_ok)
3705 req->tcpopt.wsf = tmp_opt.snd_wscale;
3706 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3707 if (tmp_opt.sack_ok)
3708 req->tcpopt.sack = 1;
3709 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3710 return;
3711}
3712
3713static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3714 __be32 laddr, __be16 lport,
3715 __be32 raddr, __be16 rport,
3716 u32 rcv_isn, u32 filter, u16 window,
3717 u32 rss_qid, u8 port_id)
3718{
3719 struct sk_buff *req_skb;
3720 struct fw_ofld_connection_wr *req;
3721 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303722 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003723
3724 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3725 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3726 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003727 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303728 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303729 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003730 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003731 req->le.lport = lport;
3732 req->le.pport = rport;
3733 req->le.u.ipv4.lip = laddr;
3734 req->le.u.ipv4.pip = raddr;
3735 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3736 req->tcb.rcv_adv = htons(window);
3737 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303738 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3739 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3740 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003741 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003742
3743 /*
3744 * We store the qid in opt2 which will be used by the firmware
3745 * to send us the wr response.
3746 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003747 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003748
3749 /*
3750 * We initialize the MSS index in TCB to 0xF.
3751 * So that when driver sends cpl_pass_accept_rpl
3752 * TCB picks up the correct value. If this was 0
3753 * TP will ignore any value > 0 for MSS index.
3754 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003755 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303756 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003757
3758 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303759 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3760 if (ret < 0) {
3761 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3762 ret);
3763 kfree_skb(skb);
3764 kfree_skb(req_skb);
3765 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003766}
3767
3768/*
3769 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3770 * messages when a filter is being used instead of server to
3771 * redirect a syn packet. When packets hit filter they are redirected
3772 * to the offload queue and driver tries to establish the connection
3773 * using firmware work request.
3774 */
3775static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3776{
3777 int stid;
3778 unsigned int filter;
3779 struct ethhdr *eh = NULL;
3780 struct vlan_ethhdr *vlan_eh = NULL;
3781 struct iphdr *iph;
3782 struct tcphdr *tcph;
3783 struct rss_header *rss = (void *)skb->data;
3784 struct cpl_rx_pkt *cpl = (void *)skb->data;
3785 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3786 struct l2t_entry *e;
3787 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003788 struct c4iw_ep *lep;
3789 u16 window;
3790 struct port_info *pi;
3791 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003792 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003793 int step;
3794 u32 tx_chan;
3795 struct neighbour *neigh;
3796
3797 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003798 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003799 goto reject;
3800
3801 /*
3802 * Drop all packets which did not hit the filter.
3803 * Unlikely to happen.
3804 */
3805 if (!(rss->filter_hit && rss->filter_tid))
3806 goto reject;
3807
3808 /*
3809 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3810 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303811 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003812
3813 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3814 if (!lep) {
3815 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3816 goto reject;
3817 }
3818
Hariprasad S963cab52015-09-23 17:19:27 +05303819 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3820 case CHELSIO_T4:
3821 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3822 break;
3823 case CHELSIO_T5:
3824 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3825 break;
3826 case CHELSIO_T6:
3827 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3828 break;
3829 default:
3830 pr_err("T%d Chip is not supported\n",
3831 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3832 goto reject;
3833 }
3834
Vipul Pandyaf079af72013-03-14 05:08:58 +00003835 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003836 eh = (struct ethhdr *)(req + 1);
3837 iph = (struct iphdr *)(eh + 1);
3838 } else {
3839 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3840 iph = (struct iphdr *)(vlan_eh + 1);
3841 skb->vlan_tci = ntohs(cpl->vlan);
3842 }
3843
3844 if (iph->version != 0x4)
3845 goto reject;
3846
3847 tcph = (struct tcphdr *)(iph + 1);
3848 skb_set_network_header(skb, (void *)iph - (void *)rss);
3849 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3850 skb_get(skb);
3851
3852 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3853 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3854 ntohs(tcph->source), iph->tos);
3855
Vipul Pandya830662f2013-07-04 16:10:47 +05303856 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3857 iph->tos);
3858 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003859 pr_err("%s - failed to find dst entry!\n",
3860 __func__);
3861 goto reject;
3862 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003863 neigh = dst_neigh_lookup_skb(dst, skb);
3864
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003865 if (!neigh) {
3866 pr_err("%s - failed to allocate neigh!\n",
3867 __func__);
3868 goto free_dst;
3869 }
3870
Vipul Pandya1cab7752012-12-10 09:30:55 +00003871 if (neigh->dev->flags & IFF_LOOPBACK) {
3872 pdev = ip_dev_find(&init_net, iph->daddr);
3873 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3874 pdev, 0);
3875 pi = (struct port_info *)netdev_priv(pdev);
3876 tx_chan = cxgb4_port_chan(pdev);
3877 dev_put(pdev);
3878 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303879 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003880 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303881 pdev, 0);
3882 pi = (struct port_info *)netdev_priv(pdev);
3883 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003884 }
Steve Wiseebf00062014-03-19 17:44:40 +05303885 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003886 if (!e) {
3887 pr_err("%s - failed to allocate l2t entry!\n",
3888 __func__);
3889 goto free_dst;
3890 }
3891
3892 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3893 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003894 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003895
3896 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303897 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3898 dev->rdev.lldi.ports[0],
3899 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003900
3901 /*
3902 * Synthesize the cpl_pass_accept_req. We have everything except the
3903 * TID. Once firmware sends a reply with TID we update the TID field
3904 * in cpl and pass it through the regular cpl_pass_accept_req path.
3905 */
3906 build_cpl_pass_accept_req(skb, stid, iph->tos);
3907 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3908 tcph->source, ntohl(tcph->seq), filter, window,
3909 rss_qid, pi->port_id);
3910 cxgb4_l2t_release(e);
3911free_dst:
3912 dst_release(dst);
3913reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003914 return 0;
3915}
3916
Steve Wisecfdda9d2010-04-21 15:30:06 -07003917/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003918 * These are the real handlers that are called from a
3919 * work queue.
3920 */
Hariprasad S9dec9002016-05-05 01:27:29 +05303921static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003922 [CPL_ACT_ESTABLISH] = act_establish,
3923 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3924 [CPL_RX_DATA] = rx_data,
3925 [CPL_ABORT_RPL_RSS] = abort_rpl,
3926 [CPL_ABORT_RPL] = abort_rpl,
3927 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3928 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3929 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3930 [CPL_PASS_ESTABLISH] = pass_establish,
3931 [CPL_PEER_CLOSE] = peer_close,
3932 [CPL_ABORT_REQ_RSS] = peer_abort,
3933 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3934 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003935 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003936 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05303937 [CPL_RX_PKT] = rx_pkt,
3938 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003939};
3940
3941static void process_timeout(struct c4iw_ep *ep)
3942{
3943 struct c4iw_qp_attributes attrs;
3944 int abort = 1;
3945
Steve Wise2f5b48c2010-09-10 11:15:36 -05003946 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003947 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3948 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003949 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003950 switch (ep->com.state) {
3951 case MPA_REQ_SENT:
3952 __state_set(&ep->com, ABORTING);
3953 connect_reply_upcall(ep, -ETIMEDOUT);
3954 break;
3955 case MPA_REQ_WAIT:
3956 __state_set(&ep->com, ABORTING);
3957 break;
3958 case CLOSING:
3959 case MORIBUND:
3960 if (ep->com.cm_id && ep->com.qp) {
3961 attrs.next_state = C4IW_QP_STATE_ERROR;
3962 c4iw_modify_qp(ep->com.qp->rhp,
3963 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3964 &attrs, 1);
3965 }
3966 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303967 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003968 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003969 case ABORTING:
3970 case DEAD:
3971
3972 /*
3973 * These states are expected if the ep timed out at the same
3974 * time as another thread was calling stop_ep_timer().
3975 * So we silently do nothing for these states.
3976 */
3977 abort = 0;
3978 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003979 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003980 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003981 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003982 abort = 0;
3983 }
Steve Wisecc18b932014-04-24 14:31:53 -05003984 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05303985 if (abort)
3986 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003987 c4iw_put_ep(&ep->com);
3988}
3989
3990static void process_timedout_eps(void)
3991{
3992 struct c4iw_ep *ep;
3993
3994 spin_lock_irq(&timeout_lock);
3995 while (!list_empty(&timeout_list)) {
3996 struct list_head *tmp;
3997
3998 tmp = timeout_list.next;
3999 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004000 tmp->next = NULL;
4001 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004002 spin_unlock_irq(&timeout_lock);
4003 ep = list_entry(tmp, struct c4iw_ep, entry);
4004 process_timeout(ep);
4005 spin_lock_irq(&timeout_lock);
4006 }
4007 spin_unlock_irq(&timeout_lock);
4008}
4009
4010static void process_work(struct work_struct *work)
4011{
4012 struct sk_buff *skb = NULL;
4013 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004014 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004015 unsigned int opcode;
4016 int ret;
4017
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004018 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004019 while ((skb = skb_dequeue(&rxq))) {
4020 rpl = cplhdr(skb);
4021 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4022 opcode = rpl->ot.opcode;
4023
4024 BUG_ON(!work_handlers[opcode]);
4025 ret = work_handlers[opcode](dev, skb);
4026 if (!ret)
4027 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004028 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004029 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004030}
4031
4032static DECLARE_WORK(skb_work, process_work);
4033
4034static void ep_timeout(unsigned long arg)
4035{
4036 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004037 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004038
4039 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004040 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004041 /*
4042 * Only insert if it is not already on the list.
4043 */
4044 if (!ep->entry.next) {
4045 list_add_tail(&ep->entry, &timeout_list);
4046 kickit = 1;
4047 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004048 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004049 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004050 if (kickit)
4051 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004052}
4053
4054/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004055 * All the CM events are handled on a work queue to have a safe context.
4056 */
4057static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4058{
4059
4060 /*
4061 * Save dev in the skb->cb area.
4062 */
4063 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4064
4065 /*
4066 * Queue the skb and schedule the worker thread.
4067 */
4068 skb_queue_tail(&rxq, skb);
4069 queue_work(workq, &skb_work);
4070 return 0;
4071}
4072
4073static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4074{
4075 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4076
4077 if (rpl->status != CPL_ERR_NONE) {
4078 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4079 "for tid %u\n", rpl->status, GET_TID(rpl));
4080 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004081 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004082 return 0;
4083}
4084
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004085static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4086{
4087 struct cpl_fw6_msg *rpl = cplhdr(skb);
4088 struct c4iw_wr_wait *wr_waitp;
4089 int ret;
4090
4091 PDBG("%s type %u\n", __func__, rpl->type);
4092
4093 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004094 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004095 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004096 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004097 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004098 if (wr_waitp)
4099 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004100 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004101 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004102 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004103 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004104 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004105 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004106 default:
4107 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4108 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004109 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004110 break;
4111 }
4112 return 0;
4113}
4114
Steve Wise8da7e7a2011-06-14 20:59:27 +00004115static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4116{
4117 struct cpl_abort_req_rss *req = cplhdr(skb);
4118 struct c4iw_ep *ep;
4119 struct tid_info *t = dev->rdev.lldi.tids;
4120 unsigned int tid = GET_TID(req);
4121
4122 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05004123 if (!ep) {
4124 printk(KERN_WARNING MOD
4125 "Abort on non-existent endpoint, tid %d\n", tid);
4126 kfree_skb(skb);
4127 return 0;
4128 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304129 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304130 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4131 __func__, ep->hwtid, req->status,
4132 neg_adv_str(req->status));
4133 ep->stats.abort_neg_adv++;
4134 dev->rdev.stats.neg_adv++;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004135 kfree_skb(skb);
4136 return 0;
4137 }
4138 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4139 ep->com.state);
4140
4141 /*
4142 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004143 * However, if we are on MPAv2 and want to retry with MPAv1
4144 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004145 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004146 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4147 if (ep->com.state != MPA_REQ_SENT)
4148 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4149 } else
4150 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00004151 sched(dev, skb);
4152 return 0;
4153}
4154
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004155/*
4156 * Most upcalls from the T4 Core go to sched() to
4157 * schedule the processing on a work queue.
4158 */
4159c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4160 [CPL_ACT_ESTABLISH] = sched,
4161 [CPL_ACT_OPEN_RPL] = sched,
4162 [CPL_RX_DATA] = sched,
4163 [CPL_ABORT_RPL_RSS] = sched,
4164 [CPL_ABORT_RPL] = sched,
4165 [CPL_PASS_OPEN_RPL] = sched,
4166 [CPL_CLOSE_LISTSRV_RPL] = sched,
4167 [CPL_PASS_ACCEPT_REQ] = sched,
4168 [CPL_PASS_ESTABLISH] = sched,
4169 [CPL_PEER_CLOSE] = sched,
4170 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004171 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004172 [CPL_RDMA_TERMINATE] = sched,
4173 [CPL_FW4_ACK] = sched,
4174 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004175 [CPL_FW6_MSG] = fw6_msg,
4176 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004177};
4178
Steve Wisecfdda9d2010-04-21 15:30:06 -07004179int __init c4iw_cm_init(void)
4180{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004181 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004182 skb_queue_head_init(&rxq);
4183
4184 workq = create_singlethread_workqueue("iw_cxgb4");
4185 if (!workq)
4186 return -ENOMEM;
4187
Steve Wisecfdda9d2010-04-21 15:30:06 -07004188 return 0;
4189}
4190
Steve Wise46c13762014-06-20 14:26:25 -05004191void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004192{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004193 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004194 flush_workqueue(workq);
4195 destroy_workqueue(workq);
4196}