blob: c4ce707d210b8c46d826494867fbfc08602b9bc6 [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, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530122 "1 is RFC0544 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
Vipul Pandya325abea2013-01-07 13:11:53 +0000153static void deref_qp(struct c4iw_ep *ep)
154{
155 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
156 clear_bit(QP_REFERENCED, &ep->com.flags);
157}
158
159static void ref_qp(struct c4iw_ep *ep)
160{
161 set_bit(QP_REFERENCED, &ep->com.flags);
162 c4iw_qp_add_ref(&ep->com.qp->ibqp);
163}
164
Steve Wisecfdda9d2010-04-21 15:30:06 -0700165static void start_ep_timer(struct c4iw_ep *ep)
166{
167 PDBG("%s ep %p\n", __func__, ep);
168 if (timer_pending(&ep->timer)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000169 pr_err("%s timer already started! ep %p\n",
170 __func__, ep);
171 return;
172 }
173 clear_bit(TIMEOUT, &ep->com.flags);
174 c4iw_get_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700175 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
176 ep->timer.data = (unsigned long)ep;
177 ep->timer.function = ep_timeout;
178 add_timer(&ep->timer);
179}
180
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500181static int stop_ep_timer(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700182{
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000183 PDBG("%s ep %p stopping\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700184 del_timer_sync(&ep->timer);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500185 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000186 c4iw_put_ep(&ep->com);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500187 return 0;
188 }
189 return 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700190}
191
192static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
193 struct l2t_entry *l2e)
194{
195 int error = 0;
196
197 if (c4iw_fatal_error(rdev)) {
198 kfree_skb(skb);
199 PDBG("%s - device in error state - dropping\n", __func__);
200 return -EIO;
201 }
202 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
203 if (error < 0)
204 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500205 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700206}
207
208int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
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_ofld_send(rdev->lldi.ports[0], skb);
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
223static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
224{
225 struct cpl_tid_release *req;
226
227 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
228 if (!skb)
229 return;
230 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
231 INIT_TP_WR(req, hwtid);
232 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
233 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
234 c4iw_ofld_send(rdev, skb);
235 return;
236}
237
238static void set_emss(struct c4iw_ep *ep, u16 opt)
239{
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800240 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
Hariprasad S04524a42014-09-24 03:53:41 +0530241 ((AF_INET == ep->com.remote_addr.ss_family) ?
242 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
243 sizeof(struct tcphdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700244 ep->mss = ep->emss;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800245 if (TCPOPT_TSTAMP_G(opt))
Hariprasad S04524a42014-09-24 03:53:41 +0530246 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700247 if (ep->emss < 128)
248 ep->emss = 128;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530249 if (ep->emss & 7)
250 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800251 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
252 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt),
Steve Wisecfdda9d2010-04-21 15:30:06 -0700253 ep->mss, ep->emss);
254}
255
256static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
257{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700258 enum c4iw_ep_state state;
259
Steve Wise2f5b48c2010-09-10 11:15:36 -0500260 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700261 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500262 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700263 return state;
264}
265
266static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
267{
268 epc->state = new;
269}
270
271static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
272{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500273 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700274 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
275 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500276 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700277 return;
278}
279
280static void *alloc_ep(int size, gfp_t gfp)
281{
282 struct c4iw_ep_common *epc;
283
284 epc = kzalloc(size, gfp);
285 if (epc) {
286 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500287 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500288 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700289 }
290 PDBG("%s alloc ep %p\n", __func__, epc);
291 return epc;
292}
293
294void _c4iw_free_ep(struct kref *kref)
295{
296 struct c4iw_ep *ep;
297
298 ep = container_of(kref, struct c4iw_ep, com.kref);
Hariprasad S9dec9002016-05-05 01:27:29 +0530299 PDBG("%s ep %p state %s\n", __func__, ep, states[ep->com.state]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000300 if (test_bit(QP_REFERENCED, &ep->com.flags))
301 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700302 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530303 if (ep->com.remote_addr.ss_family == AF_INET6) {
304 struct sockaddr_in6 *sin6 =
305 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600306 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530307
308 cxgb4_clip_release(
309 ep->com.dev->rdev.lldi.ports[0],
310 (const u32 *)&sin6->sin6_addr.s6_addr,
311 1);
312 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000313 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700314 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
315 dst_release(ep->dst);
316 cxgb4_l2t_release(ep->l2t);
317 }
318 kfree(ep);
319}
320
321static void release_ep_resources(struct c4iw_ep *ep)
322{
323 set_bit(RELEASE_RESOURCES, &ep->com.flags);
324 c4iw_put_ep(&ep->com);
325}
326
Steve Wisecfdda9d2010-04-21 15:30:06 -0700327static int status2errno(int status)
328{
329 switch (status) {
330 case CPL_ERR_NONE:
331 return 0;
332 case CPL_ERR_CONN_RESET:
333 return -ECONNRESET;
334 case CPL_ERR_ARP_MISS:
335 return -EHOSTUNREACH;
336 case CPL_ERR_CONN_TIMEDOUT:
337 return -ETIMEDOUT;
338 case CPL_ERR_TCAM_FULL:
339 return -ENOMEM;
340 case CPL_ERR_CONN_EXIST:
341 return -EADDRINUSE;
342 default:
343 return -EIO;
344 }
345}
346
347/*
348 * Try and reuse skbs already allocated...
349 */
350static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
351{
352 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
353 skb_trim(skb, 0);
354 skb_get(skb);
355 skb_reset_transport_header(skb);
356 } else {
357 skb = alloc_skb(len, gfp);
358 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530359 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700360 return skb;
361}
362
Vipul Pandya830662f2013-07-04 16:10:47 +0530363static struct net_device *get_real_dev(struct net_device *egress_dev)
364{
Steve Wise11b8e222014-05-16 12:42:46 -0500365 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530366}
367
368static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
369{
370 int i;
371
372 egress_dev = get_real_dev(egress_dev);
373 for (i = 0; i < dev->rdev.lldi.nports; i++)
374 if (dev->rdev.lldi.ports[i] == egress_dev)
375 return 1;
376 return 0;
377}
378
379static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
380 __u8 *peer_ip, __be16 local_port,
381 __be16 peer_port, u8 tos,
382 __u32 sin6_scope_id)
383{
384 struct dst_entry *dst = NULL;
385
386 if (IS_ENABLED(CONFIG_IPV6)) {
387 struct flowi6 fl6;
388
389 memset(&fl6, 0, sizeof(fl6));
390 memcpy(&fl6.daddr, peer_ip, 16);
391 memcpy(&fl6.saddr, local_ip, 16);
392 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
393 fl6.flowi6_oif = sin6_scope_id;
394 dst = ip6_route_output(&init_net, NULL, &fl6);
395 if (!dst)
396 goto out;
397 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
398 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
399 dst_release(dst);
400 dst = NULL;
401 }
402 }
403
404out:
405 return dst;
406}
407
408static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700409 __be32 peer_ip, __be16 local_port,
410 __be16 peer_port, u8 tos)
411{
412 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700413 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530414 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700415
David S. Miller31e4543d2011-05-03 20:25:42 -0700416 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500417 peer_port, local_port, IPPROTO_TCP,
418 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800419 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700420 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530421 n = dst_neigh_lookup(&rt->dst, &peer_ip);
422 if (!n)
423 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530424 if (!our_interface(dev, n->dev) &&
425 !(n->dev->flags & IFF_LOOPBACK)) {
Hariprasad Sd4802012014-09-24 03:53:42 +0530426 neigh_release(n);
Vipul Pandya830662f2013-07-04 16:10:47 +0530427 dst_release(&rt->dst);
428 return NULL;
429 }
430 neigh_release(n);
431 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700432}
433
434static void arp_failure_discard(void *handle, struct sk_buff *skb)
435{
Hariprasad S9dec9002016-05-05 01:27:29 +0530436 pr_err(MOD "ARP failure\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700437 kfree_skb(skb);
438}
439
Hariprasad S9dec9002016-05-05 01:27:29 +0530440enum {
441 NUM_FAKE_CPLS = 1,
442 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
443};
444
445static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
446{
447 struct c4iw_ep *ep;
448
449 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
450 release_ep_resources(ep);
451 return 0;
452}
453
454/*
455 * Fake up a special CPL opcode and call sched() so process_work() will call
456 * _put_ep_safe() in a safe context to free the ep resources. This is needed
457 * because ARP error handlers are called in an ATOMIC context, and
458 * _c4iw_free_ep() needs to block.
459 */
460static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb)
461{
462 struct cpl_act_establish *rpl = cplhdr(skb);
463
464 /* Set our special ARP_FAILURE opcode */
465 rpl->ot.opcode = FAKE_CPL_PUT_EP_SAFE;
466
467 /*
468 * Save ep in the skb->cb area, after where sched() will save the dev
469 * ptr.
470 */
471 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
472 sched(ep->com.dev, skb);
473}
474
475/* Handle an ARP failure for an accept */
476static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
477{
478 struct c4iw_ep *ep = handle;
479
480 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
481 ep->hwtid);
482
483 __state_set(&ep->com, DEAD);
484 queue_arp_failure_cpl(ep, skb);
485}
486
Steve Wisecfdda9d2010-04-21 15:30:06 -0700487/*
488 * Handle an ARP failure for an active open.
489 */
490static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
491{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530492 struct c4iw_ep *ep = handle;
493
Masanari Iidae3d132d2015-10-16 21:14:29 +0900494 printk(KERN_ERR MOD "ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530495 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530496 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530497 if (ep->com.remote_addr.ss_family == AF_INET6) {
498 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600499 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530500 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
501 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
502 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530503 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
504 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S9dec9002016-05-05 01:27:29 +0530505 queue_arp_failure_cpl(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700506}
507
508/*
509 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
510 * and send it along.
511 */
512static void abort_arp_failure(void *handle, struct sk_buff *skb)
513{
514 struct c4iw_rdev *rdev = handle;
515 struct cpl_abort_req *req = cplhdr(skb);
516
517 PDBG("%s rdev %p\n", __func__, rdev);
518 req->cmd = CPL_ABORT_NO_RST;
519 c4iw_ofld_send(rdev, skb);
520}
521
522static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
523{
524 unsigned int flowclen = 80;
525 struct fw_flowc_wr *flowc;
526 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530527 u16 vlan = ep->l2t->vlan;
528 int nparams;
529
530 if (vlan == CPL_L2T_VLAN_NONE)
531 nparams = 8;
532 else
533 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700534
535 skb = get_skb(skb, flowclen, GFP_KERNEL);
536 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
537
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530538 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530539 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530540 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(flowclen,
541 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700542
543 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530544 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530545 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700546 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
547 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
548 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
549 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
550 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
551 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
552 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
553 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
554 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
555 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
556 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530557 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700558 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
559 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530560 if (nparams == 9) {
561 u16 pri;
562
563 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
564 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
565 flowc->mnemval[8].val = cpu_to_be32(pri);
566 } else {
567 /* Pad WR to 16 byte boundary */
568 flowc->mnemval[8].mnemonic = 0;
569 flowc->mnemval[8].val = 0;
570 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700571 for (i = 0; i < 9; i++) {
572 flowc->mnemval[i].r4[0] = 0;
573 flowc->mnemval[i].r4[1] = 0;
574 flowc->mnemval[i].r4[2] = 0;
575 }
576
577 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
578 c4iw_ofld_send(&ep->com.dev->rdev, skb);
579}
580
581static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
582{
583 struct cpl_close_con_req *req;
584 struct sk_buff *skb;
585 int wrlen = roundup(sizeof *req, 16);
586
587 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
588 skb = get_skb(NULL, wrlen, gfp);
589 if (!skb) {
590 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
591 return -ENOMEM;
592 }
593 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
594 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
595 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
596 memset(req, 0, wrlen);
597 INIT_TP_WR(req, ep->hwtid);
598 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
599 ep->hwtid));
600 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
601}
602
603static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
604{
605 struct cpl_abort_req *req;
606 int wrlen = roundup(sizeof *req, 16);
607
608 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
609 skb = get_skb(skb, wrlen, gfp);
610 if (!skb) {
611 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
612 __func__);
613 return -ENOMEM;
614 }
615 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
616 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
617 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
618 memset(req, 0, wrlen);
619 INIT_TP_WR(req, ep->hwtid);
620 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
621 req->cmd = CPL_ABORT_SEND_RST;
622 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
623}
624
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530625static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530626 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530627{
Hariprasad S04524a42014-09-24 03:53:41 +0530628 unsigned short hdr_size = (ipv6 ?
629 sizeof(struct ipv6hdr) :
630 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530631 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530632 (use_ts ?
633 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530634 unsigned short data_size = mtu - hdr_size;
635
636 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
637}
638
Steve Wisecfdda9d2010-04-21 15:30:06 -0700639static int send_connect(struct c4iw_ep *ep)
640{
Hariprasad S963cab52015-09-23 17:19:27 +0530641 struct cpl_act_open_req *req = NULL;
642 struct cpl_t5_act_open_req *t5req = NULL;
643 struct cpl_t6_act_open_req *t6req = NULL;
644 struct cpl_act_open_req6 *req6 = NULL;
645 struct cpl_t5_act_open_req6 *t5req6 = NULL;
646 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700647 struct sk_buff *skb;
648 u64 opt0;
649 u32 opt2;
650 unsigned int mtu_idx;
651 int wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530652 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500653 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600654 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500655 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600656 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500657 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600658 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500659 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600660 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530661 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530662 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
663 u32 isn = (prandom_u32() & ~7UL) - 1;
664
665 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
666 case CHELSIO_T4:
667 sizev4 = sizeof(struct cpl_act_open_req);
668 sizev6 = sizeof(struct cpl_act_open_req6);
669 break;
670 case CHELSIO_T5:
671 sizev4 = sizeof(struct cpl_t5_act_open_req);
672 sizev6 = sizeof(struct cpl_t5_act_open_req6);
673 break;
674 case CHELSIO_T6:
675 sizev4 = sizeof(struct cpl_t6_act_open_req);
676 sizev6 = sizeof(struct cpl_t6_act_open_req6);
677 break;
678 default:
679 pr_err("T%d Chip is not supported\n",
680 CHELSIO_CHIP_VERSION(adapter_type));
681 return -EINVAL;
682 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530683
684 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
685 roundup(sizev4, 16) :
686 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700687
688 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
689
690 skb = get_skb(NULL, wrlen, GFP_KERNEL);
691 if (!skb) {
692 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
693 __func__);
694 return -ENOMEM;
695 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000696 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700697
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530698 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530699 enable_tcp_timestamps,
700 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700701 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530702
703 /*
704 * Specify the largest window that will fit in opt0. The
705 * remainder will be specified in the rx_data_ack.
706 */
707 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800708 if (win > RCV_BUFSIZ_M)
709 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530710
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800711 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800712 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800713 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800714 WND_SCALE_V(wscale) |
715 MSS_IDX_V(mtu_idx) |
716 L2T_IDX_V(ep->l2t->idx) |
717 TX_CHAN_V(ep->tx_chan) |
718 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530719 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800720 ULP_MODE_V(ULP_MODE_TCPDDP) |
721 RCV_BUFSIZ_V(win);
722 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800723 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800724 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700725 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800726 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700727 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800728 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700729 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800730 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530731 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
732 if (peer2peer)
733 isn += 4;
734
Anish Bhattd7990b02014-11-12 17:15:57 -0800735 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530736 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530737 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500738 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530739
740 if (ep->com.remote_addr.ss_family == AF_INET6)
741 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
742 (const u32 *)&la6->sin6_addr.s6_addr, 1);
743
Hariprasad S5dab6d32014-06-23 19:12:36 +0530744 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700745
Hariprasad S963cab52015-09-23 17:19:27 +0530746 if (ep->com.remote_addr.ss_family == AF_INET) {
747 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
748 case CHELSIO_T4:
749 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530750 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530751 break;
752 case CHELSIO_T5:
753 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
754 wrlen);
755 INIT_TP_WR(t5req, 0);
756 req = (struct cpl_act_open_req *)t5req;
757 break;
758 case CHELSIO_T6:
759 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
760 wrlen);
761 INIT_TP_WR(t6req, 0);
762 req = (struct cpl_act_open_req *)t6req;
763 t5req = (struct cpl_t5_act_open_req *)t6req;
764 break;
765 default:
766 pr_err("T%d Chip is not supported\n",
767 CHELSIO_CHIP_VERSION(adapter_type));
768 ret = -EINVAL;
769 goto clip_release;
770 }
771
772 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
773 ((ep->rss_qid<<14) | ep->atid)));
774 req->local_port = la->sin_port;
775 req->peer_port = ra->sin_port;
776 req->local_ip = la->sin_addr.s_addr;
777 req->peer_ip = ra->sin_addr.s_addr;
778 req->opt0 = cpu_to_be64(opt0);
779
780 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530781 req->params = cpu_to_be32(cxgb4_select_ntuple(
782 ep->com.dev->rdev.lldi.ports[0],
783 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530784 req->opt2 = cpu_to_be32(opt2);
785 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530786 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
787 cxgb4_select_ntuple(
788 ep->com.dev->rdev.lldi.ports[0],
789 ep->l2t)));
790 t5req->rsvd = cpu_to_be32(isn);
791 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
792 t5req->opt2 = cpu_to_be32(opt2);
793 }
794 } else {
795 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
796 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530797 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530798 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530799 break;
800 case CHELSIO_T5:
801 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
802 wrlen);
803 INIT_TP_WR(t5req6, 0);
804 req6 = (struct cpl_act_open_req6 *)t5req6;
805 break;
806 case CHELSIO_T6:
807 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
808 wrlen);
809 INIT_TP_WR(t6req6, 0);
810 req6 = (struct cpl_act_open_req6 *)t6req6;
811 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
812 break;
813 default:
814 pr_err("T%d Chip is not supported\n",
815 CHELSIO_CHIP_VERSION(adapter_type));
816 ret = -EINVAL;
817 goto clip_release;
818 }
819
820 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
821 ((ep->rss_qid<<14)|ep->atid)));
822 req6->local_port = la6->sin6_port;
823 req6->peer_port = ra6->sin6_port;
824 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
825 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
826 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
827 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
828 req6->opt0 = cpu_to_be64(opt0);
829
830 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530831 req6->params = cpu_to_be32(cxgb4_select_ntuple(
832 ep->com.dev->rdev.lldi.ports[0],
833 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530834 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530835 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530836 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
837 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530838 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530839 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530840 t5req6->rsvd = cpu_to_be32(isn);
841 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
842 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530843 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000844 }
845
Vipul Pandya793dad92012-12-10 09:30:56 +0000846 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530847 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530848clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530849 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
850 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
851 (const u32 *)&la6->sin6_addr.s6_addr, 1);
852 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700853}
854
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530855static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
856 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700857{
858 int mpalen, wrlen;
859 struct fw_ofld_tx_data_wr *req;
860 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530861 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700862
863 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
864
865 BUG_ON(skb_cloned(skb));
866
867 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530868 if (mpa_rev_to_use == 2)
869 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700870 wrlen = roundup(mpalen + sizeof *req, 16);
871 skb = get_skb(skb, wrlen, GFP_KERNEL);
872 if (!skb) {
873 connect_reply_upcall(ep, -ENOMEM);
874 return;
875 }
876 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
877
878 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
879 memset(req, 0, wrlen);
880 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530881 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
882 FW_WR_COMPL_F |
883 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700884 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530885 FW_WR_FLOWID_V(ep->hwtid) |
886 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700887 req->plen = cpu_to_be32(mpalen);
888 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530889 FW_OFLD_TX_DATA_WR_FLUSH_F |
890 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700891
892 mpa = (struct mpa_message *)(req + 1);
893 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
894 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530895 (markers_enabled ? MPA_MARKERS : 0) |
896 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700897 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530898 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530899 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530900 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530901 ep->retry_with_mpa_v1 = 0;
902 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700903
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530904 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700905 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
906 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530907 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
908 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530909 mpa_v2_params.ird = htons((u16)ep->ird);
910 mpa_v2_params.ord = htons((u16)ep->ord);
911
912 if (peer2peer) {
913 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
914 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
915 mpa_v2_params.ord |=
916 htons(MPA_V2_RDMA_WRITE_RTR);
917 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
918 mpa_v2_params.ord |=
919 htons(MPA_V2_RDMA_READ_RTR);
920 }
921 memcpy(mpa->private_data, &mpa_v2_params,
922 sizeof(struct mpa_v2_conn_params));
923
924 if (ep->plen)
925 memcpy(mpa->private_data +
926 sizeof(struct mpa_v2_conn_params),
927 ep->mpa_pkt + sizeof(*mpa), ep->plen);
928 } else
929 if (ep->plen)
930 memcpy(mpa->private_data,
931 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700932
933 /*
934 * Reference the mpa skb. This ensures the data area
935 * will remain in memory until the hw acks the tx.
936 * Function fw4_ack() will deref it.
937 */
938 skb_get(skb);
939 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
940 BUG_ON(ep->mpa_skb);
941 ep->mpa_skb = skb;
942 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
943 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530944 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700945 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530946 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700947 return;
948}
949
950static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
951{
952 int mpalen, wrlen;
953 struct fw_ofld_tx_data_wr *req;
954 struct mpa_message *mpa;
955 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530956 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700957
958 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
959
960 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530961 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
962 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700963 wrlen = roundup(mpalen + sizeof *req, 16);
964
965 skb = get_skb(NULL, wrlen, GFP_KERNEL);
966 if (!skb) {
967 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
968 return -ENOMEM;
969 }
970 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
971
972 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
973 memset(req, 0, wrlen);
974 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530975 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
976 FW_WR_COMPL_F |
977 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700978 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530979 FW_WR_FLOWID_V(ep->hwtid) |
980 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700981 req->plen = cpu_to_be32(mpalen);
982 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530983 FW_OFLD_TX_DATA_WR_FLUSH_F |
984 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700985
986 mpa = (struct mpa_message *)(req + 1);
987 memset(mpa, 0, sizeof(*mpa));
988 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
989 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000990 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700991 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530992
993 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
994 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700995 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
996 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530997 mpa_v2_params.ird = htons(((u16)ep->ird) |
998 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
999 0));
1000 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1001 (p2p_type ==
1002 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1003 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1004 FW_RI_INIT_P2PTYPE_READ_REQ ?
1005 MPA_V2_RDMA_READ_RTR : 0) : 0));
1006 memcpy(mpa->private_data, &mpa_v2_params,
1007 sizeof(struct mpa_v2_conn_params));
1008
1009 if (ep->plen)
1010 memcpy(mpa->private_data +
1011 sizeof(struct mpa_v2_conn_params), pdata, plen);
1012 } else
1013 if (plen)
1014 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001015
1016 /*
1017 * Reference the mpa skb again. This ensures the data area
1018 * will remain in memory until the hw acks the tx.
1019 * Function fw4_ack() will deref it.
1020 */
1021 skb_get(skb);
1022 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1023 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1024 BUG_ON(ep->mpa_skb);
1025 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301026 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001027 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1028}
1029
1030static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1031{
1032 int mpalen, wrlen;
1033 struct fw_ofld_tx_data_wr *req;
1034 struct mpa_message *mpa;
1035 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301036 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001037
1038 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1039
1040 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301041 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1042 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001043 wrlen = roundup(mpalen + sizeof *req, 16);
1044
1045 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1046 if (!skb) {
1047 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1048 return -ENOMEM;
1049 }
1050 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1051
1052 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1053 memset(req, 0, wrlen);
1054 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301055 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1056 FW_WR_COMPL_F |
1057 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001058 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301059 FW_WR_FLOWID_V(ep->hwtid) |
1060 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001061 req->plen = cpu_to_be32(mpalen);
1062 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301063 FW_OFLD_TX_DATA_WR_FLUSH_F |
1064 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001065
1066 mpa = (struct mpa_message *)(req + 1);
1067 memset(mpa, 0, sizeof(*mpa));
1068 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1069 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
1070 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301071 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001072 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301073
1074 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1075 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001076 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1077 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301078 mpa_v2_params.ird = htons((u16)ep->ird);
1079 mpa_v2_params.ord = htons((u16)ep->ord);
1080 if (peer2peer && (ep->mpa_attr.p2p_type !=
1081 FW_RI_INIT_P2PTYPE_DISABLED)) {
1082 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1083
1084 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1085 mpa_v2_params.ord |=
1086 htons(MPA_V2_RDMA_WRITE_RTR);
1087 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1088 mpa_v2_params.ord |=
1089 htons(MPA_V2_RDMA_READ_RTR);
1090 }
1091
1092 memcpy(mpa->private_data, &mpa_v2_params,
1093 sizeof(struct mpa_v2_conn_params));
1094
1095 if (ep->plen)
1096 memcpy(mpa->private_data +
1097 sizeof(struct mpa_v2_conn_params), pdata, plen);
1098 } else
1099 if (plen)
1100 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001101
1102 /*
1103 * Reference the mpa skb. This ensures the data area
1104 * will remain in memory until the hw acks the tx.
1105 * Function fw4_ack() will deref it.
1106 */
1107 skb_get(skb);
1108 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1109 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301110 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301111 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001112 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1113}
1114
1115static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1116{
1117 struct c4iw_ep *ep;
1118 struct cpl_act_establish *req = cplhdr(skb);
1119 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001120 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001121 struct tid_info *t = dev->rdev.lldi.tids;
1122
1123 ep = lookup_atid(t, atid);
1124
1125 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1126 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1127
Steve Wisea7db89e2014-03-21 20:40:35 +05301128 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001129 dst_confirm(ep->dst);
1130
1131 /* setup the hwtid for this connection */
1132 ep->hwtid = tid;
1133 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001134 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001135
1136 ep->snd_seq = be32_to_cpu(req->snd_isn);
1137 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1138
1139 set_emss(ep, ntohs(req->tcp_opt));
1140
1141 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001142 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001143 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001144 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001145
1146 /* start MPA negotiation */
1147 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301148 if (ep->retry_with_mpa_v1)
1149 send_mpa_req(ep, skb, 1);
1150 else
1151 send_mpa_req(ep, skb, mpa_rev);
Steve Wisea7db89e2014-03-21 20:40:35 +05301152 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001153 return 0;
1154}
1155
Steve Wisebe13b2d2014-03-21 20:40:33 +05301156static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001157{
1158 struct iw_cm_event event;
1159
1160 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1161 memset(&event, 0, sizeof(event));
1162 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301163 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001164 if (ep->com.cm_id) {
1165 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1166 ep, ep->com.cm_id, ep->hwtid);
1167 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1168 ep->com.cm_id->rem_ref(ep->com.cm_id);
1169 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001170 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001171 }
1172}
1173
1174static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
1175{
1176 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecc18b932014-04-24 14:31:53 -05001177 __state_set(&ep->com, ABORTING);
Vipul Pandya793dad92012-12-10 09:30:56 +00001178 set_bit(ABORT_CONN, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001179 return send_abort(ep, skb, gfp);
1180}
1181
1182static void peer_close_upcall(struct c4iw_ep *ep)
1183{
1184 struct iw_cm_event event;
1185
1186 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1187 memset(&event, 0, sizeof(event));
1188 event.event = IW_CM_EVENT_DISCONNECT;
1189 if (ep->com.cm_id) {
1190 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1191 ep, ep->com.cm_id, ep->hwtid);
1192 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001193 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001194 }
1195}
1196
1197static void peer_abort_upcall(struct c4iw_ep *ep)
1198{
1199 struct iw_cm_event event;
1200
1201 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1202 memset(&event, 0, sizeof(event));
1203 event.event = IW_CM_EVENT_CLOSE;
1204 event.status = -ECONNRESET;
1205 if (ep->com.cm_id) {
1206 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1207 ep->com.cm_id, ep->hwtid);
1208 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1209 ep->com.cm_id->rem_ref(ep->com.cm_id);
1210 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001211 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001212 }
1213}
1214
1215static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1216{
1217 struct iw_cm_event event;
1218
1219 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1220 memset(&event, 0, sizeof(event));
1221 event.event = IW_CM_EVENT_CONNECT_REPLY;
1222 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301223 memcpy(&event.local_addr, &ep->com.local_addr,
1224 sizeof(ep->com.local_addr));
1225 memcpy(&event.remote_addr, &ep->com.remote_addr,
1226 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001227
1228 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301229 if (!ep->tried_with_mpa_v1) {
1230 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301231 event.ord = ep->ird;
1232 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301233 event.private_data_len = ep->plen -
1234 sizeof(struct mpa_v2_conn_params);
1235 event.private_data = ep->mpa_pkt +
1236 sizeof(struct mpa_message) +
1237 sizeof(struct mpa_v2_conn_params);
1238 } else {
1239 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301240 event.ord = cur_max_read_depth(ep->com.dev);
1241 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301242 event.private_data_len = ep->plen;
1243 event.private_data = ep->mpa_pkt +
1244 sizeof(struct mpa_message);
1245 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001246 }
Roland Dreier85963e42010-07-19 13:13:09 -07001247
1248 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1249 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001250 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001251 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1252
Steve Wisecfdda9d2010-04-21 15:30:06 -07001253 if (status < 0) {
1254 ep->com.cm_id->rem_ref(ep->com.cm_id);
1255 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001256 }
1257}
1258
Steve Wisebe13b2d2014-03-21 20:40:33 +05301259static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001260{
1261 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301262 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001263
1264 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1265 memset(&event, 0, sizeof(event));
1266 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301267 memcpy(&event.local_addr, &ep->com.local_addr,
1268 sizeof(ep->com.local_addr));
1269 memcpy(&event.remote_addr, &ep->com.remote_addr,
1270 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001271 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301272 if (!ep->tried_with_mpa_v1) {
1273 /* this means MPA_v2 is used */
1274 event.ord = ep->ord;
1275 event.ird = ep->ird;
1276 event.private_data_len = ep->plen -
1277 sizeof(struct mpa_v2_conn_params);
1278 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1279 sizeof(struct mpa_v2_conn_params);
1280 } else {
1281 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301282 event.ord = cur_max_read_depth(ep->com.dev);
1283 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301284 event.private_data_len = ep->plen;
1285 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1286 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301287 c4iw_get_ep(&ep->com);
1288 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1289 &event);
1290 if (ret)
1291 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001292 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001293 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301294 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001295}
1296
1297static void established_upcall(struct c4iw_ep *ep)
1298{
1299 struct iw_cm_event event;
1300
1301 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1302 memset(&event, 0, sizeof(event));
1303 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301304 event.ird = ep->ord;
1305 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001306 if (ep->com.cm_id) {
1307 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1308 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001309 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001310 }
1311}
1312
1313static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1314{
1315 struct cpl_rx_data_ack *req;
1316 struct sk_buff *skb;
1317 int wrlen = roundup(sizeof *req, 16);
1318
1319 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1320 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1321 if (!skb) {
1322 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1323 return 0;
1324 }
1325
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301326 /*
1327 * If we couldn't specify the entire rcv window at connection setup
1328 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1329 * then add the overage in to the credits returned.
1330 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001331 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1332 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301333
Steve Wisecfdda9d2010-04-21 15:30:06 -07001334 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1335 memset(req, 0, wrlen);
1336 INIT_TP_WR(req, ep->hwtid);
1337 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1338 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001339 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301340 RX_DACK_CHANGE_F |
1341 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001342 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001343 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1344 return credits;
1345}
1346
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301347#define RELAXED_IRD_NEGOTIATION 1
1348
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301349/*
1350 * process_mpa_reply - process streaming mode MPA reply
1351 *
1352 * Returns:
1353 *
1354 * 0 upon success indicating a connect request was delivered to the ULP
1355 * or the mpa request is incomplete but valid so far.
1356 *
1357 * 1 if a failure requires the caller to close the connection.
1358 *
1359 * 2 if a failure requires the caller to abort the connection.
1360 */
Steve Wisecc18b932014-04-24 14:31:53 -05001361static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001362{
1363 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301364 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001365 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301366 u16 resp_ird, resp_ord;
1367 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001368 struct c4iw_qp_attributes attrs;
1369 enum c4iw_qp_attr_mask mask;
1370 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001371 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001372
1373 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1374
1375 /*
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001376 * Stop mpa timer. If it expired, then
1377 * we ignore the MPA reply. process_timeout()
1378 * will abort the connection.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001379 */
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001380 if (stop_ep_timer(ep))
Steve Wisecc18b932014-04-24 14:31:53 -05001381 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001382
1383 /*
1384 * If we get more than the supported amount of private data
1385 * then we must fail this connection.
1386 */
1387 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1388 err = -EINVAL;
1389 goto err;
1390 }
1391
1392 /*
1393 * copy the new data into our accumulation buffer.
1394 */
1395 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1396 skb->len);
1397 ep->mpa_pkt_len += skb->len;
1398
1399 /*
1400 * if we don't even have the mpa message, then bail.
1401 */
1402 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001403 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001404 mpa = (struct mpa_message *) ep->mpa_pkt;
1405
1406 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301407 if (mpa->revision > mpa_rev) {
1408 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1409 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001410 err = -EPROTO;
1411 goto err;
1412 }
1413 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1414 err = -EPROTO;
1415 goto err;
1416 }
1417
1418 plen = ntohs(mpa->private_data_size);
1419
1420 /*
1421 * Fail if there's too much private data.
1422 */
1423 if (plen > MPA_MAX_PRIVATE_DATA) {
1424 err = -EPROTO;
1425 goto err;
1426 }
1427
1428 /*
1429 * If plen does not account for pkt size
1430 */
1431 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1432 err = -EPROTO;
1433 goto err;
1434 }
1435
1436 ep->plen = (u8) plen;
1437
1438 /*
1439 * If we don't have all the pdata yet, then bail.
1440 * We'll continue process when more data arrives.
1441 */
1442 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001443 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001444
1445 if (mpa->flags & MPA_REJECT) {
1446 err = -ECONNREFUSED;
1447 goto err;
1448 }
1449
1450 /*
1451 * If we get here we have accumulated the entire mpa
1452 * start reply message including private data. And
1453 * the MPA header is valid.
1454 */
Steve Wisec529fb52014-03-21 20:40:37 +05301455 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001456 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1457 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1458 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301459 ep->mpa_attr.version = mpa->revision;
1460 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1461
1462 if (mpa->revision == 2) {
1463 ep->mpa_attr.enhanced_rdma_conn =
1464 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1465 if (ep->mpa_attr.enhanced_rdma_conn) {
1466 mpa_v2_params = (struct mpa_v2_conn_params *)
1467 (ep->mpa_pkt + sizeof(*mpa));
1468 resp_ird = ntohs(mpa_v2_params->ird) &
1469 MPA_V2_IRD_ORD_MASK;
1470 resp_ord = ntohs(mpa_v2_params->ord) &
1471 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301472 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1473 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301474
1475 /*
1476 * This is a double-check. Ideally, below checks are
1477 * not required since ird/ord stuff has been taken
1478 * care of in c4iw_accept_cr
1479 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301480 if (ep->ird < resp_ord) {
1481 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1482 ep->com.dev->rdev.lldi.max_ordird_qp)
1483 ep->ird = resp_ord;
1484 else
1485 insuff_ird = 1;
1486 } else if (ep->ird > resp_ord) {
1487 ep->ird = resp_ord;
1488 }
1489 if (ep->ord > resp_ird) {
1490 if (RELAXED_IRD_NEGOTIATION)
1491 ep->ord = resp_ird;
1492 else
1493 insuff_ird = 1;
1494 }
1495 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301496 err = -ENOMEM;
1497 ep->ird = resp_ord;
1498 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301499 }
1500
1501 if (ntohs(mpa_v2_params->ird) &
1502 MPA_V2_PEER2PEER_MODEL) {
1503 if (ntohs(mpa_v2_params->ord) &
1504 MPA_V2_RDMA_WRITE_RTR)
1505 ep->mpa_attr.p2p_type =
1506 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1507 else if (ntohs(mpa_v2_params->ord) &
1508 MPA_V2_RDMA_READ_RTR)
1509 ep->mpa_attr.p2p_type =
1510 FW_RI_INIT_P2PTYPE_READ_REQ;
1511 }
1512 }
1513 } else if (mpa->revision == 1)
1514 if (peer2peer)
1515 ep->mpa_attr.p2p_type = p2p_type;
1516
Steve Wisecfdda9d2010-04-21 15:30:06 -07001517 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301518 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1519 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1520 ep->mpa_attr.recv_marker_enabled,
1521 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1522 ep->mpa_attr.p2p_type, p2p_type);
1523
1524 /*
1525 * If responder's RTR does not match with that of initiator, assign
1526 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1527 * generated when moving QP to RTS state.
1528 * A TERM message will be sent after QP has moved to RTS state
1529 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001530 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301531 (ep->mpa_attr.p2p_type != p2p_type)) {
1532 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1533 rtr_mismatch = 1;
1534 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001535
1536 attrs.mpa_attr = ep->mpa_attr;
1537 attrs.max_ird = ep->ird;
1538 attrs.max_ord = ep->ord;
1539 attrs.llp_stream_handle = ep;
1540 attrs.next_state = C4IW_QP_STATE_RTS;
1541
1542 mask = C4IW_QP_ATTR_NEXT_STATE |
1543 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1544 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1545
1546 /* bind QP and TID with INIT_WR */
1547 err = c4iw_modify_qp(ep->com.qp->rhp,
1548 ep->com.qp, mask, &attrs, 1);
1549 if (err)
1550 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301551
1552 /*
1553 * If responder's RTR requirement did not match with what initiator
1554 * supports, generate TERM message
1555 */
1556 if (rtr_mismatch) {
1557 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1558 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1559 attrs.ecode = MPA_NOMATCH_RTR;
1560 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001561 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301562 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001563 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301564 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001565 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301566 goto out;
1567 }
1568
1569 /*
1570 * Generate TERM if initiator IRD is not sufficient for responder
1571 * provided ORD. Currently, we do the same behaviour even when
1572 * responder provided IRD is also not sufficient as regards to
1573 * initiator ORD.
1574 */
1575 if (insuff_ird) {
1576 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1577 __func__);
1578 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1579 attrs.ecode = MPA_INSUFF_IRD;
1580 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001581 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301582 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001583 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301584 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001585 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301586 goto out;
1587 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001588 goto out;
1589err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301590 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001591out:
1592 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001593 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001594}
1595
1596static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1597{
1598 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301599 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001600 u16 plen;
1601
1602 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1603
Steve Wisecfdda9d2010-04-21 15:30:06 -07001604 /*
1605 * If we get more than the supported amount of private data
1606 * then we must fail this connection.
1607 */
1608 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001609 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001610 abort_connection(ep, skb, GFP_KERNEL);
1611 return;
1612 }
1613
1614 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1615
1616 /*
1617 * Copy the new data into our accumulation buffer.
1618 */
1619 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1620 skb->len);
1621 ep->mpa_pkt_len += skb->len;
1622
1623 /*
1624 * If we don't even have the mpa message, then bail.
1625 * We'll continue process when more data arrives.
1626 */
1627 if (ep->mpa_pkt_len < sizeof(*mpa))
1628 return;
1629
1630 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001631 mpa = (struct mpa_message *) ep->mpa_pkt;
1632
1633 /*
1634 * Validate MPA Header.
1635 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301636 if (mpa->revision > mpa_rev) {
1637 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1638 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001639 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001640 abort_connection(ep, skb, GFP_KERNEL);
1641 return;
1642 }
1643
1644 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001645 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001646 abort_connection(ep, skb, GFP_KERNEL);
1647 return;
1648 }
1649
1650 plen = ntohs(mpa->private_data_size);
1651
1652 /*
1653 * Fail if there's too much private data.
1654 */
1655 if (plen > MPA_MAX_PRIVATE_DATA) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001656 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001657 abort_connection(ep, skb, GFP_KERNEL);
1658 return;
1659 }
1660
1661 /*
1662 * If plen does not account for pkt size
1663 */
1664 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001665 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001666 abort_connection(ep, skb, GFP_KERNEL);
1667 return;
1668 }
1669 ep->plen = (u8) plen;
1670
1671 /*
1672 * If we don't have all the pdata yet, then bail.
1673 */
1674 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1675 return;
1676
1677 /*
1678 * If we get here we have accumulated the entire mpa
1679 * start reply message including private data.
1680 */
1681 ep->mpa_attr.initiator = 0;
1682 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1683 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1684 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301685 ep->mpa_attr.version = mpa->revision;
1686 if (mpa->revision == 1)
1687 ep->tried_with_mpa_v1 = 1;
1688 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1689
1690 if (mpa->revision == 2) {
1691 ep->mpa_attr.enhanced_rdma_conn =
1692 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1693 if (ep->mpa_attr.enhanced_rdma_conn) {
1694 mpa_v2_params = (struct mpa_v2_conn_params *)
1695 (ep->mpa_pkt + sizeof(*mpa));
1696 ep->ird = ntohs(mpa_v2_params->ird) &
1697 MPA_V2_IRD_ORD_MASK;
1698 ep->ord = ntohs(mpa_v2_params->ord) &
1699 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301700 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1701 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301702 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1703 if (peer2peer) {
1704 if (ntohs(mpa_v2_params->ord) &
1705 MPA_V2_RDMA_WRITE_RTR)
1706 ep->mpa_attr.p2p_type =
1707 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1708 else if (ntohs(mpa_v2_params->ord) &
1709 MPA_V2_RDMA_READ_RTR)
1710 ep->mpa_attr.p2p_type =
1711 FW_RI_INIT_P2PTYPE_READ_REQ;
1712 }
1713 }
1714 } else if (mpa->revision == 1)
1715 if (peer2peer)
1716 ep->mpa_attr.p2p_type = p2p_type;
1717
Steve Wisecfdda9d2010-04-21 15:30:06 -07001718 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1719 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1720 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1721 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1722 ep->mpa_attr.p2p_type);
1723
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001724 /*
1725 * If the endpoint timer already expired, then we ignore
1726 * the start request. process_timeout() will abort
1727 * the connection.
1728 */
1729 if (!stop_ep_timer(ep)) {
1730 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001731
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001732 /* drive upcall */
Hariprasad Shenai10be6b42014-11-21 09:36:35 -06001733 mutex_lock_nested(&ep->parent_ep->com.mutex,
1734 SINGLE_DEPTH_NESTING);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001735 if (ep->parent_ep->com.state != DEAD) {
1736 if (connect_request_upcall(ep))
1737 abort_connection(ep, skb, GFP_KERNEL);
1738 } else {
Steve Wisebe13b2d2014-03-21 20:40:33 +05301739 abort_connection(ep, skb, GFP_KERNEL);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001740 }
1741 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301742 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001743 return;
1744}
1745
1746static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1747{
1748 struct c4iw_ep *ep;
1749 struct cpl_rx_data *hdr = cplhdr(skb);
1750 unsigned int dlen = ntohs(hdr->len);
1751 unsigned int tid = GET_TID(hdr);
1752 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001753 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001754 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001755
1756 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301757 if (!ep)
1758 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001759 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1760 skb_pull(skb, sizeof(*hdr));
1761 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301762 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001763
Steve Wisecfdda9d2010-04-21 15:30:06 -07001764 /* update RX credits */
1765 update_rx_credits(ep, dlen);
1766
Steve Wisec529fb52014-03-21 20:40:37 +05301767 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001768 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001769 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001770 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001771 break;
1772 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001773 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001774 process_mpa_request(ep, skb);
1775 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001776 case FPDU_MODE: {
1777 struct c4iw_qp_attributes attrs;
1778 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001779 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001780 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001781 " qpid %u ep %p state %d tid %u status %d\n",
1782 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301783 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301784 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001785 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001786 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1787 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001788 break;
1789 }
Vipul Pandya15579672013-01-07 13:11:52 +00001790 default:
1791 break;
1792 }
Steve Wisec529fb52014-03-21 20:40:37 +05301793 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001794 if (disconnect)
1795 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001796 return 0;
1797}
1798
1799static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1800{
1801 struct c4iw_ep *ep;
1802 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001803 int release = 0;
1804 unsigned int tid = GET_TID(rpl);
1805 struct tid_info *t = dev->rdev.lldi.tids;
1806
1807 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301808 if (!ep) {
1809 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1810 return 0;
1811 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001812 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001813 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001814 switch (ep->com.state) {
1815 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001816 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001817 __state_set(&ep->com, DEAD);
1818 release = 1;
1819 break;
1820 default:
1821 printk(KERN_ERR "%s ep %p state %d\n",
1822 __func__, ep, ep->com.state);
1823 break;
1824 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001825 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001826
1827 if (release)
1828 release_ep_resources(ep);
1829 return 0;
1830}
1831
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001832static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1833{
1834 struct sk_buff *skb;
1835 struct fw_ofld_connection_wr *req;
1836 unsigned int mtu_idx;
1837 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301838 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301839 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001840
1841 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1842 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1843 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001844 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301845 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301846 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1847 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001848 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001849 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301850 req->le.lport = sin->sin_port;
1851 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001852 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301853 req->le.pport = sin->sin_port;
1854 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001855 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301856 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1857 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001858 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301859 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001860 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001861 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301862 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301863 enable_tcp_timestamps,
1864 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001865 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301866
1867 /*
1868 * Specify the largest window that will fit in opt0. The
1869 * remainder will be specified in the rx_data_ack.
1870 */
1871 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001872 if (win > RCV_BUFSIZ_M)
1873 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301874
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001875 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1876 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001877 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001878 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001879 WND_SCALE_V(wscale) |
1880 MSS_IDX_V(mtu_idx) |
1881 L2T_IDX_V(ep->l2t->idx) |
1882 TX_CHAN_V(ep->tx_chan) |
1883 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301884 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001885 ULP_MODE_V(ULP_MODE_TCPDDP) |
1886 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001887 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1888 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001889 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001890 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001891 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001892 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001893 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001894 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001895 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001896 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001897 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1898 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1899 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001900 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1901 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001902 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1903}
1904
Steve Wisecfdda9d2010-04-21 15:30:06 -07001905/*
1906 * Return whether a failed active open has allocated a TID
1907 */
1908static inline int act_open_has_tid(int status)
1909{
1910 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1911 status != CPL_ERR_ARP_MISS;
1912}
1913
Steve Wise7a2cea22014-03-14 21:52:07 +05301914/* Returns whether a CPL status conveys negative advice.
1915 */
1916static int is_neg_adv(unsigned int status)
1917{
1918 return status == CPL_ERR_RTX_NEG_ADVICE ||
1919 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1920 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1921}
1922
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301923static char *neg_adv_str(unsigned int status)
1924{
1925 switch (status) {
1926 case CPL_ERR_RTX_NEG_ADVICE:
1927 return "Retransmit timeout";
1928 case CPL_ERR_PERSIST_NEG_ADVICE:
1929 return "Persist timeout";
1930 case CPL_ERR_KEEPALV_NEG_ADVICE:
1931 return "Keepalive timeout";
1932 default:
1933 return "Unknown";
1934 }
1935}
1936
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301937static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1938{
1939 ep->snd_win = snd_win;
1940 ep->rcv_win = rcv_win;
1941 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1942}
1943
Vipul Pandya793dad92012-12-10 09:30:56 +00001944#define ACT_OPEN_RETRY_COUNT 2
1945
Vipul Pandya830662f2013-07-04 16:10:47 +05301946static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1947 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301948 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05301949{
1950 struct neighbour *n;
1951 int err, step;
1952 struct net_device *pdev;
1953
1954 n = dst_neigh_lookup(dst, peer_ip);
1955 if (!n)
1956 return -ENODEV;
1957
1958 rcu_read_lock();
1959 err = -ENOMEM;
1960 if (n->dev->flags & IFF_LOOPBACK) {
1961 if (iptype == 4)
1962 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1963 else if (IS_ENABLED(CONFIG_IPV6))
1964 for_each_netdev(&init_net, pdev) {
1965 if (ipv6_chk_addr(&init_net,
1966 (struct in6_addr *)peer_ip,
1967 pdev, 1))
1968 break;
1969 }
1970 else
1971 pdev = NULL;
1972
1973 if (!pdev) {
1974 err = -ENODEV;
1975 goto out;
1976 }
1977 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301978 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05301979 if (!ep->l2t)
1980 goto out;
1981 ep->mtu = pdev->mtu;
1982 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05301983 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
1984 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301985 step = cdev->rdev.lldi.ntxq /
1986 cdev->rdev.lldi.nchan;
1987 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1988 step = cdev->rdev.lldi.nrxq /
1989 cdev->rdev.lldi.nchan;
1990 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1991 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1992 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301993 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301994 dev_put(pdev);
1995 } else {
1996 pdev = get_real_dev(n->dev);
1997 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1998 n, pdev, 0);
1999 if (!ep->l2t)
2000 goto out;
2001 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002002 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302003 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2004 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302005 step = cdev->rdev.lldi.ntxq /
2006 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002007 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2008 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302009 step = cdev->rdev.lldi.nrxq /
2010 cdev->rdev.lldi.nchan;
2011 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002012 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302013 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302014
2015 if (clear_mpa_v1) {
2016 ep->retry_with_mpa_v1 = 0;
2017 ep->tried_with_mpa_v1 = 0;
2018 }
2019 }
2020 err = 0;
2021out:
2022 rcu_read_unlock();
2023
2024 neigh_release(n);
2025
2026 return err;
2027}
2028
Vipul Pandya793dad92012-12-10 09:30:56 +00002029static int c4iw_reconnect(struct c4iw_ep *ep)
2030{
2031 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302032 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002033 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302034 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002035 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302036 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002037 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302038 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002039 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302040 int iptype;
2041 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002042
2043 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2044 init_timer(&ep->timer);
2045
2046 /*
2047 * Allocate an active TID to initiate a TCP connection.
2048 */
2049 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2050 if (ep->atid == -1) {
2051 pr_err("%s - cannot alloc atid.\n", __func__);
2052 err = -ENOMEM;
2053 goto fail2;
2054 }
2055 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2056
2057 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002058 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302059 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2060 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302061 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302062 iptype = 4;
2063 ra = (__u8 *)&raddr->sin_addr;
2064 } else {
2065 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2066 raddr6->sin6_addr.s6_addr,
2067 laddr6->sin6_port, raddr6->sin6_port, 0,
2068 raddr6->sin6_scope_id);
2069 iptype = 6;
2070 ra = (__u8 *)&raddr6->sin6_addr;
2071 }
2072 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002073 pr_err("%s - cannot find route.\n", __func__);
2074 err = -EHOSTUNREACH;
2075 goto fail3;
2076 }
Hariprasad S963cab52015-09-23 17:19:27 +05302077 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302078 ep->com.dev->rdev.lldi.adapter_type,
2079 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302080 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002081 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002082 goto fail4;
2083 }
2084
2085 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2086 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2087 ep->l2t->idx);
2088
2089 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302090 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002091
2092 /* send connect request to rnic */
2093 err = send_connect(ep);
2094 if (!err)
2095 goto out;
2096
2097 cxgb4_l2t_release(ep->l2t);
2098fail4:
2099 dst_release(ep->dst);
2100fail3:
2101 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2102 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2103fail2:
2104 /*
2105 * remember to send notification to upper layer.
2106 * We are in here so the upper layer is not aware that this is
2107 * re-connect attempt and so, upper layer is still waiting for
2108 * response of 1st connect request.
2109 */
2110 connect_reply_upcall(ep, -ECONNRESET);
2111 c4iw_put_ep(&ep->com);
2112out:
2113 return err;
2114}
2115
Steve Wisecfdda9d2010-04-21 15:30:06 -07002116static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2117{
2118 struct c4iw_ep *ep;
2119 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002120 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2121 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002122 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002123 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302124 struct sockaddr_in *la;
2125 struct sockaddr_in *ra;
2126 struct sockaddr_in6 *la6;
2127 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002128
2129 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002130 la = (struct sockaddr_in *)&ep->com.local_addr;
2131 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2132 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2133 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002134
2135 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2136 status, status2errno(status));
2137
Steve Wise7a2cea22014-03-14 21:52:07 +05302138 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302139 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2140 __func__, atid, status, neg_adv_str(status));
2141 ep->stats.connect_neg_adv++;
2142 mutex_lock(&dev->rdev.stats.lock);
2143 dev->rdev.stats.neg_adv++;
2144 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002145 return 0;
2146 }
2147
Vipul Pandya793dad92012-12-10 09:30:56 +00002148 set_bit(ACT_OPEN_RPL, &ep->com.history);
2149
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302150 /*
2151 * Log interesting failures.
2152 */
2153 switch (status) {
2154 case CPL_ERR_CONN_RESET:
2155 case CPL_ERR_CONN_TIMEDOUT:
2156 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002157 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302158 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002159 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302160 mutex_unlock(&dev->rdev.stats.lock);
2161 if (ep->com.local_addr.ss_family == AF_INET &&
2162 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002163 send_fw_act_open_req(ep,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002164 TID_TID_G(AOPEN_ATID_G(
Vipul Pandya793dad92012-12-10 09:30:56 +00002165 ntohl(rpl->atid_status))));
2166 return 0;
2167 }
2168 break;
2169 case CPL_ERR_CONN_EXIST:
2170 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2171 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302172 if (ep->com.remote_addr.ss_family == AF_INET6) {
2173 struct sockaddr_in6 *sin6 =
2174 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002175 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302176 cxgb4_clip_release(
2177 ep->com.dev->rdev.lldi.ports[0],
2178 (const u32 *)
2179 &sin6->sin6_addr.s6_addr, 1);
2180 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002181 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2182 atid);
2183 cxgb4_free_atid(t, atid);
2184 dst_release(ep->dst);
2185 cxgb4_l2t_release(ep->l2t);
2186 c4iw_reconnect(ep);
2187 return 0;
2188 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002189 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302190 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302191 if (ep->com.local_addr.ss_family == AF_INET) {
2192 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2193 atid, status, status2errno(status),
2194 &la->sin_addr.s_addr, ntohs(la->sin_port),
2195 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2196 } else {
2197 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2198 atid, status, status2errno(status),
2199 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2200 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2201 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302202 break;
2203 }
2204
Steve Wisecfdda9d2010-04-21 15:30:06 -07002205 connect_reply_upcall(ep, status2errno(status));
2206 state_set(&ep->com, DEAD);
2207
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302208 if (ep->com.remote_addr.ss_family == AF_INET6) {
2209 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002210 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302211 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2212 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2213 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002214 if (status && act_open_has_tid(status))
2215 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2216
Vipul Pandya793dad92012-12-10 09:30:56 +00002217 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002218 cxgb4_free_atid(t, atid);
2219 dst_release(ep->dst);
2220 cxgb4_l2t_release(ep->l2t);
2221 c4iw_put_ep(&ep->com);
2222
2223 return 0;
2224}
2225
2226static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2227{
2228 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2229 struct tid_info *t = dev->rdev.lldi.tids;
2230 unsigned int stid = GET_TID(rpl);
2231 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2232
2233 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002234 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2235 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002236 }
2237 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2238 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002239 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002240
Vipul Pandya1cab7752012-12-10 09:30:55 +00002241out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002242 return 0;
2243}
2244
Steve Wisecfdda9d2010-04-21 15:30:06 -07002245static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2246{
2247 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2248 struct tid_info *t = dev->rdev.lldi.tids;
2249 unsigned int stid = GET_TID(rpl);
2250 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2251
2252 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002253 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002254 return 0;
2255}
2256
Hariprasad S9dec9002016-05-05 01:27:29 +05302257static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2258 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002259{
2260 struct cpl_pass_accept_rpl *rpl;
2261 unsigned int mtu_idx;
2262 u64 opt0;
2263 u32 opt2;
2264 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302265 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302266 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302267 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002268
2269 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2270 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302271
Steve Wisecfdda9d2010-04-21 15:30:06 -07002272 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302273 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302274 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302275 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2276 rpl5 = (void *)rpl;
2277 INIT_TP_WR(rpl5, ep->hwtid);
2278 } else {
2279 skb_trim(skb, sizeof(*rpl));
2280 INIT_TP_WR(rpl, ep->hwtid);
2281 }
2282 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2283 ep->hwtid));
2284
2285 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302286 enable_tcp_timestamps && req->tcpopt.tstamp,
2287 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002288 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302289
2290 /*
2291 * Specify the largest window that will fit in opt0. The
2292 * remainder will be specified in the rx_data_ack.
2293 */
2294 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002295 if (win > RCV_BUFSIZ_M)
2296 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002297 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002298 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002299 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002300 WND_SCALE_V(wscale) |
2301 MSS_IDX_V(mtu_idx) |
2302 L2T_IDX_V(ep->l2t->idx) |
2303 TX_CHAN_V(ep->tx_chan) |
2304 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002305 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002306 ULP_MODE_V(ULP_MODE_TCPDDP) |
2307 RCV_BUFSIZ_V(win);
2308 opt2 = RX_CHANNEL_V(0) |
2309 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002310
2311 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002312 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002313 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002314 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002315 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002316 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002317 if (enable_ecn) {
2318 const struct tcphdr *tcph;
2319 u32 hlen = ntohl(req->hdr_len);
2320
Hariprasad S963cab52015-09-23 17:19:27 +05302321 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2322 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2323 IP_HDR_LEN_G(hlen);
2324 else
2325 tcph = (const void *)(req + 1) +
2326 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002327 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002328 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002329 }
Hariprasad S963cab52015-09-23 17:19:27 +05302330 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302331 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002332 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302333 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302334 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302335 rpl5 = (void *)rpl;
2336 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2337 if (peer2peer)
2338 isn += 4;
2339 rpl5->iss = cpu_to_be32(isn);
2340 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002341 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002342
Steve Wisecfdda9d2010-04-21 15:30:06 -07002343 rpl->opt0 = cpu_to_be64(opt0);
2344 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002345 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302346 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002347
Hariprasad S9dec9002016-05-05 01:27:29 +05302348 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002349}
2350
Vipul Pandya830662f2013-07-04 16:10:47 +05302351static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002352{
Vipul Pandya830662f2013-07-04 16:10:47 +05302353 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002354 BUG_ON(skb_cloned(skb));
2355 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002356 release_tid(&dev->rdev, hwtid, skb);
2357 return;
2358}
2359
Hariprasad S963cab52015-09-23 17:19:27 +05302360static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2361 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002362 __be16 *local_port, __be16 *peer_port)
2363{
Hariprasad S963cab52015-09-23 17:19:27 +05302364 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2365 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2366 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2367 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2368 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2369 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002370 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302371 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002372 struct tcphdr *tcp = (struct tcphdr *)
2373 ((u8 *)(req + 1) + eth_len + ip_len);
2374
Vipul Pandya830662f2013-07-04 16:10:47 +05302375 if (ip->version == 4) {
2376 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2377 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2378 ntohs(tcp->dest));
2379 *iptype = 4;
2380 memcpy(peer_ip, &ip->saddr, 4);
2381 memcpy(local_ip, &ip->daddr, 4);
2382 } else {
2383 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2384 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2385 ntohs(tcp->dest));
2386 *iptype = 6;
2387 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2388 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2389 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002390 *peer_port = tcp->source;
2391 *local_port = tcp->dest;
2392
2393 return;
2394}
2395
2396static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2397{
Vipul Pandya793dad92012-12-10 09:30:56 +00002398 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002399 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002400 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002401 struct tid_info *t = dev->rdev.lldi.tids;
2402 unsigned int hwtid = GET_TID(req);
2403 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302404 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002405 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302406 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002407 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002408 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302409 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302410 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302411 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002412
2413 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002414 if (!parent_ep) {
2415 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2416 goto reject;
2417 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002418
Steve Wisecfdda9d2010-04-21 15:30:06 -07002419 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302420 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002421 goto reject;
2422 }
2423
Hariprasad S963cab52015-09-23 17:19:27 +05302424 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2425 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302426
Steve Wisecfdda9d2010-04-21 15:30:06 -07002427 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302428 if (iptype == 4) {
2429 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2430 , __func__, parent_ep, hwtid,
2431 local_ip, peer_ip, ntohs(local_port),
2432 ntohs(peer_port), peer_mss);
2433 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2434 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302435 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302436 } else {
2437 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2438 , __func__, parent_ep, hwtid,
2439 local_ip, peer_ip, ntohs(local_port),
2440 ntohs(peer_port), peer_mss);
2441 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002442 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302443 ((struct sockaddr_in6 *)
2444 &parent_ep->com.local_addr)->sin6_scope_id);
2445 }
2446 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002447 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2448 __func__);
2449 goto reject;
2450 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002451
2452 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2453 if (!child_ep) {
2454 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2455 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002456 dst_release(dst);
2457 goto reject;
2458 }
David Miller3786cf12011-12-02 16:52:31 +00002459
Hariprasad S963cab52015-09-23 17:19:27 +05302460 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302461 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002462 if (err) {
2463 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2464 __func__);
2465 dst_release(dst);
2466 kfree(child_ep);
2467 goto reject;
2468 }
2469
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302470 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2471 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2472 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2473 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002474
Steve Wisecfdda9d2010-04-21 15:30:06 -07002475 state_set(&child_ep->com, CONNECTING);
2476 child_ep->com.dev = dev;
2477 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002478
Vipul Pandya830662f2013-07-04 16:10:47 +05302479 if (iptype == 4) {
2480 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002481 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002482
Vipul Pandya830662f2013-07-04 16:10:47 +05302483 sin->sin_family = PF_INET;
2484 sin->sin_port = local_port;
2485 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002486
2487 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2488 sin->sin_family = PF_INET;
2489 sin->sin_port = ((struct sockaddr_in *)
2490 &parent_ep->com.local_addr)->sin_port;
2491 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2492
Steve Wise170003c2016-02-26 09:18:03 -06002493 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302494 sin->sin_family = PF_INET;
2495 sin->sin_port = peer_port;
2496 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2497 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002498 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302499 sin6->sin6_family = PF_INET6;
2500 sin6->sin6_port = local_port;
2501 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002502
2503 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2504 sin6->sin6_family = PF_INET6;
2505 sin6->sin6_port = ((struct sockaddr_in6 *)
2506 &parent_ep->com.local_addr)->sin6_port;
2507 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2508
Steve Wise170003c2016-02-26 09:18:03 -06002509 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302510 sin6->sin6_family = PF_INET6;
2511 sin6->sin6_port = peer_port;
2512 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2513 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002514
Steve Wisecfdda9d2010-04-21 15:30:06 -07002515 c4iw_get_ep(&parent_ep->com);
2516 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302517 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002518 child_ep->dst = dst;
2519 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002520
2521 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002522 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002523
2524 init_timer(&child_ep->timer);
2525 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002526 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Hariprasad S9dec9002016-05-05 01:27:29 +05302527 if (accept_cr(child_ep, skb, req)) {
2528 c4iw_put_ep(&parent_ep->com);
2529 release_ep_resources(child_ep);
2530 } else {
2531 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2532 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302533 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002534 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302535 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2536 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2537 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002538 goto out;
2539reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302540 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002541out:
2542 return 0;
2543}
2544
2545static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2546{
2547 struct c4iw_ep *ep;
2548 struct cpl_pass_establish *req = cplhdr(skb);
2549 struct tid_info *t = dev->rdev.lldi.tids;
2550 unsigned int tid = GET_TID(req);
2551
2552 ep = lookup_tid(t, tid);
2553 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2554 ep->snd_seq = be32_to_cpu(req->snd_isn);
2555 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2556
Vipul Pandya1cab7752012-12-10 09:30:55 +00002557 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2558 ntohs(req->tcp_opt));
2559
Steve Wisecfdda9d2010-04-21 15:30:06 -07002560 set_emss(ep, ntohs(req->tcp_opt));
2561
2562 dst_confirm(ep->dst);
2563 state_set(&ep->com, MPA_REQ_WAIT);
2564 start_ep_timer(ep);
2565 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002566 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002567
2568 return 0;
2569}
2570
2571static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2572{
2573 struct cpl_peer_close *hdr = cplhdr(skb);
2574 struct c4iw_ep *ep;
2575 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002576 int disconnect = 1;
2577 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002578 struct tid_info *t = dev->rdev.lldi.tids;
2579 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002580 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002581
2582 ep = lookup_tid(t, tid);
2583 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2584 dst_confirm(ep->dst);
2585
Vipul Pandya793dad92012-12-10 09:30:56 +00002586 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002587 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002588 switch (ep->com.state) {
2589 case MPA_REQ_WAIT:
2590 __state_set(&ep->com, CLOSING);
2591 break;
2592 case MPA_REQ_SENT:
2593 __state_set(&ep->com, CLOSING);
2594 connect_reply_upcall(ep, -ECONNRESET);
2595 break;
2596 case MPA_REQ_RCVD:
2597
2598 /*
2599 * We're gonna mark this puppy DEAD, but keep
2600 * the reference on it until the ULP accepts or
2601 * rejects the CR. Also wake up anyone waiting
2602 * in rdma connection migration (see c4iw_accept_cr()).
2603 */
2604 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002605 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002606 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002607 break;
2608 case MPA_REP_SENT:
2609 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002610 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002611 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002612 break;
2613 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002614 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002615 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002616 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002617 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002618 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002619 if (ret != -ECONNRESET) {
2620 peer_close_upcall(ep);
2621 disconnect = 1;
2622 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002623 break;
2624 case ABORTING:
2625 disconnect = 0;
2626 break;
2627 case CLOSING:
2628 __state_set(&ep->com, MORIBUND);
2629 disconnect = 0;
2630 break;
2631 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002632 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002633 if (ep->com.cm_id && ep->com.qp) {
2634 attrs.next_state = C4IW_QP_STATE_IDLE;
2635 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2636 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2637 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302638 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002639 __state_set(&ep->com, DEAD);
2640 release = 1;
2641 disconnect = 0;
2642 break;
2643 case DEAD:
2644 disconnect = 0;
2645 break;
2646 default:
2647 BUG_ON(1);
2648 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002649 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002650 if (disconnect)
2651 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2652 if (release)
2653 release_ep_resources(ep);
2654 return 0;
2655}
2656
Steve Wisecfdda9d2010-04-21 15:30:06 -07002657static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2658{
2659 struct cpl_abort_req_rss *req = cplhdr(skb);
2660 struct c4iw_ep *ep;
2661 struct cpl_abort_rpl *rpl;
2662 struct sk_buff *rpl_skb;
2663 struct c4iw_qp_attributes attrs;
2664 int ret;
2665 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002666 struct tid_info *t = dev->rdev.lldi.tids;
2667 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002668
2669 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302670 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302671 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2672 __func__, ep->hwtid, req->status,
2673 neg_adv_str(req->status));
2674 ep->stats.abort_neg_adv++;
2675 mutex_lock(&dev->rdev.stats.lock);
2676 dev->rdev.stats.neg_adv++;
2677 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002678 return 0;
2679 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002680 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2681 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002682 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002683
2684 /*
2685 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302686 * However, this is not needed if com state is just
2687 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002688 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302689 if (ep->com.state != MPA_REQ_SENT)
2690 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002691
2692 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002693 switch (ep->com.state) {
2694 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302695 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002696 break;
2697 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002698 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002699 break;
2700 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002701 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002702 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302703 connect_reply_upcall(ep, -ECONNRESET);
2704 else {
2705 /*
2706 * we just don't send notification upwards because we
2707 * want to retry with mpa_v1 without upper layers even
2708 * knowing it.
2709 *
2710 * do some housekeeping so as to re-initiate the
2711 * connection
2712 */
2713 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2714 mpa_rev);
2715 ep->retry_with_mpa_v1 = 1;
2716 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002717 break;
2718 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002719 break;
2720 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002721 break;
2722 case MORIBUND:
2723 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002724 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002725 /*FALLTHROUGH*/
2726 case FPDU_MODE:
2727 if (ep->com.cm_id && ep->com.qp) {
2728 attrs.next_state = C4IW_QP_STATE_ERROR;
2729 ret = c4iw_modify_qp(ep->com.qp->rhp,
2730 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2731 &attrs, 1);
2732 if (ret)
2733 printk(KERN_ERR MOD
2734 "%s - qp <- error failed!\n",
2735 __func__);
2736 }
2737 peer_abort_upcall(ep);
2738 break;
2739 case ABORTING:
2740 break;
2741 case DEAD:
2742 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002743 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002744 return 0;
2745 default:
2746 BUG_ON(1);
2747 break;
2748 }
2749 dst_confirm(ep->dst);
2750 if (ep->com.state != ABORTING) {
2751 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302752 /* we don't release if we want to retry with mpa_v1 */
2753 if (!ep->retry_with_mpa_v1)
2754 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002755 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002756 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002757
2758 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2759 if (!rpl_skb) {
2760 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2761 __func__);
2762 release = 1;
2763 goto out;
2764 }
2765 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2766 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2767 INIT_TP_WR(rpl, ep->hwtid);
2768 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2769 rpl->cmd = CPL_ABORT_NO_RST;
2770 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2771out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002772 if (release)
2773 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002774 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302775 if (ep->com.remote_addr.ss_family == AF_INET6) {
2776 struct sockaddr_in6 *sin6 =
2777 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002778 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302779 cxgb4_clip_release(
2780 ep->com.dev->rdev.lldi.ports[0],
2781 (const u32 *)&sin6->sin6_addr.s6_addr,
2782 1);
2783 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002784 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302785 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2786 dst_release(ep->dst);
2787 cxgb4_l2t_release(ep->l2t);
2788 c4iw_reconnect(ep);
2789 }
2790
Steve Wisecfdda9d2010-04-21 15:30:06 -07002791 return 0;
2792}
2793
2794static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2795{
2796 struct c4iw_ep *ep;
2797 struct c4iw_qp_attributes attrs;
2798 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002799 int release = 0;
2800 struct tid_info *t = dev->rdev.lldi.tids;
2801 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002802
2803 ep = lookup_tid(t, tid);
2804
2805 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2806 BUG_ON(!ep);
2807
2808 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002809 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002810 switch (ep->com.state) {
2811 case CLOSING:
2812 __state_set(&ep->com, MORIBUND);
2813 break;
2814 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002815 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002816 if ((ep->com.cm_id) && (ep->com.qp)) {
2817 attrs.next_state = C4IW_QP_STATE_IDLE;
2818 c4iw_modify_qp(ep->com.qp->rhp,
2819 ep->com.qp,
2820 C4IW_QP_ATTR_NEXT_STATE,
2821 &attrs, 1);
2822 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302823 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002824 __state_set(&ep->com, DEAD);
2825 release = 1;
2826 break;
2827 case ABORTING:
2828 case DEAD:
2829 break;
2830 default:
2831 BUG_ON(1);
2832 break;
2833 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002834 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002835 if (release)
2836 release_ep_resources(ep);
2837 return 0;
2838}
2839
2840static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2841{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002842 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002843 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002844 unsigned int tid = GET_TID(rpl);
2845 struct c4iw_ep *ep;
2846 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002847
2848 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002849 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002850
Steve Wise30c95c22011-05-09 22:06:22 -07002851 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002852 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2853 ep->com.qp->wq.sq.qid);
2854 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2855 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2856 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2857 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002858 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002859
Steve Wisecfdda9d2010-04-21 15:30:06 -07002860 return 0;
2861}
2862
2863/*
2864 * Upcall from the adapter indicating data has been transmitted.
2865 * For us its just the single MPA request or reply. We can now free
2866 * the skb holding the mpa message.
2867 */
2868static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2869{
2870 struct c4iw_ep *ep;
2871 struct cpl_fw4_ack *hdr = cplhdr(skb);
2872 u8 credits = hdr->credits;
2873 unsigned int tid = GET_TID(hdr);
2874 struct tid_info *t = dev->rdev.lldi.tids;
2875
2876
2877 ep = lookup_tid(t, tid);
2878 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2879 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002880 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2881 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002882 return 0;
2883 }
2884
2885 dst_confirm(ep->dst);
2886 if (ep->mpa_skb) {
2887 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2888 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2889 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2890 kfree_skb(ep->mpa_skb);
2891 ep->mpa_skb = NULL;
2892 }
2893 return 0;
2894}
2895
Steve Wisecfdda9d2010-04-21 15:30:06 -07002896int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2897{
Steve Wisea7db89e2014-03-21 20:40:35 +05302898 int err = 0;
2899 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002900 struct c4iw_ep *ep = to_ep(cm_id);
2901 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2902
Steve Wisea7db89e2014-03-21 20:40:35 +05302903 mutex_lock(&ep->com.mutex);
2904 if (ep->com.state == DEAD) {
2905 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002906 c4iw_put_ep(&ep->com);
2907 return -ECONNRESET;
2908 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002909 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302910 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002911 if (mpa_rev == 0)
2912 abort_connection(ep, NULL, GFP_KERNEL);
2913 else {
2914 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302915 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002916 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302917 mutex_unlock(&ep->com.mutex);
2918 if (disconnect)
2919 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002920 c4iw_put_ep(&ep->com);
2921 return 0;
2922}
2923
2924int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2925{
2926 int err;
2927 struct c4iw_qp_attributes attrs;
2928 enum c4iw_qp_attr_mask mask;
2929 struct c4iw_ep *ep = to_ep(cm_id);
2930 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2931 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2932
2933 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302934
2935 mutex_lock(&ep->com.mutex);
2936 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002937 err = -ECONNRESET;
2938 goto err;
2939 }
2940
Steve Wisea7db89e2014-03-21 20:40:35 +05302941 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002942 BUG_ON(!qp);
2943
Vipul Pandya793dad92012-12-10 09:30:56 +00002944 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302945 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2946 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002947 abort_connection(ep, NULL, GFP_KERNEL);
2948 err = -EINVAL;
2949 goto err;
2950 }
2951
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302952 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2953 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302954 if (RELAXED_IRD_NEGOTIATION) {
2955 ep->ord = ep->ird;
2956 } else {
2957 ep->ird = conn_param->ird;
2958 ep->ord = conn_param->ord;
2959 send_mpa_reject(ep, conn_param->private_data,
2960 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302961 abort_connection(ep, NULL, GFP_KERNEL);
2962 err = -ENOMEM;
2963 goto err;
2964 }
2965 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302966 if (conn_param->ird < ep->ord) {
2967 if (RELAXED_IRD_NEGOTIATION &&
2968 ep->ord <= h->rdev.lldi.max_ordird_qp) {
2969 conn_param->ird = ep->ord;
2970 } else {
2971 abort_connection(ep, NULL, GFP_KERNEL);
2972 err = -ENOMEM;
2973 goto err;
2974 }
2975 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302976 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002977 ep->ird = conn_param->ird;
2978 ep->ord = conn_param->ord;
2979
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302980 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302981 if (peer2peer && ep->ird == 0)
2982 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302983 } else {
2984 if (peer2peer &&
2985 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05302986 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302987 ep->ird = 1;
2988 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002989
2990 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2991
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302992 cm_id->add_ref(cm_id);
2993 ep->com.cm_id = cm_id;
2994 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00002995 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302996
Steve Wisecfdda9d2010-04-21 15:30:06 -07002997 /* bind QP to EP and move to RTS */
2998 attrs.mpa_attr = ep->mpa_attr;
2999 attrs.max_ird = ep->ird;
3000 attrs.max_ord = ep->ord;
3001 attrs.llp_stream_handle = ep;
3002 attrs.next_state = C4IW_QP_STATE_RTS;
3003
3004 /* bind QP and TID with INIT_WR */
3005 mask = C4IW_QP_ATTR_NEXT_STATE |
3006 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3007 C4IW_QP_ATTR_MPA_ATTR |
3008 C4IW_QP_ATTR_MAX_IRD |
3009 C4IW_QP_ATTR_MAX_ORD;
3010
3011 err = c4iw_modify_qp(ep->com.qp->rhp,
3012 ep->com.qp, mask, &attrs, 1);
3013 if (err)
3014 goto err1;
3015 err = send_mpa_reply(ep, conn_param->private_data,
3016 conn_param->private_data_len);
3017 if (err)
3018 goto err1;
3019
Steve Wisea7db89e2014-03-21 20:40:35 +05303020 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003021 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303022 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003023 c4iw_put_ep(&ep->com);
3024 return 0;
3025err1:
3026 ep->com.cm_id = NULL;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303027 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003028 cm_id->rem_ref(cm_id);
3029err:
Steve Wisea7db89e2014-03-21 20:40:35 +05303030 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003031 c4iw_put_ep(&ep->com);
3032 return err;
3033}
3034
Vipul Pandya830662f2013-07-04 16:10:47 +05303035static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3036{
3037 struct in_device *ind;
3038 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003039 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3040 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303041
3042 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3043 if (!ind)
3044 return -EADDRNOTAVAIL;
3045 for_primary_ifa(ind) {
3046 laddr->sin_addr.s_addr = ifa->ifa_address;
3047 raddr->sin_addr.s_addr = ifa->ifa_address;
3048 found = 1;
3049 break;
3050 }
3051 endfor_ifa(ind);
3052 in_dev_put(ind);
3053 return found ? 0 : -EADDRNOTAVAIL;
3054}
3055
3056static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3057 unsigned char banned_flags)
3058{
3059 struct inet6_dev *idev;
3060 int err = -EADDRNOTAVAIL;
3061
3062 rcu_read_lock();
3063 idev = __in6_dev_get(dev);
3064 if (idev != NULL) {
3065 struct inet6_ifaddr *ifp;
3066
3067 read_lock_bh(&idev->lock);
3068 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3069 if (ifp->scope == IFA_LINK &&
3070 !(ifp->flags & banned_flags)) {
3071 memcpy(addr, &ifp->addr, 16);
3072 err = 0;
3073 break;
3074 }
3075 }
3076 read_unlock_bh(&idev->lock);
3077 }
3078 rcu_read_unlock();
3079 return err;
3080}
3081
3082static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3083{
3084 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003085 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3086 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303087
Nicholas Krause54b9a962015-08-26 23:00:59 -04003088 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303089 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3090 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3091 return 0;
3092 }
3093 return -EADDRNOTAVAIL;
3094}
3095
Steve Wisecfdda9d2010-04-21 15:30:06 -07003096int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3097{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003098 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3099 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003100 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003101 struct sockaddr_in *laddr;
3102 struct sockaddr_in *raddr;
3103 struct sockaddr_in6 *laddr6;
3104 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303105 __u8 *ra;
3106 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003107
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303108 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3109 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003110 err = -EINVAL;
3111 goto out;
3112 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003113 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3114 if (!ep) {
3115 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3116 err = -ENOMEM;
3117 goto out;
3118 }
3119 init_timer(&ep->timer);
3120 ep->plen = conn_param->private_data_len;
3121 if (ep->plen)
3122 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3123 conn_param->private_data, ep->plen);
3124 ep->ird = conn_param->ird;
3125 ep->ord = conn_param->ord;
3126
3127 if (peer2peer && ep->ord == 0)
3128 ep->ord = 1;
3129
3130 cm_id->add_ref(cm_id);
3131 ep->com.dev = dev;
3132 ep->com.cm_id = cm_id;
3133 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303134 if (!ep->com.qp) {
3135 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3136 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003137 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303138 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003139 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003140 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3141 ep->com.qp, cm_id);
3142
3143 /*
3144 * Allocate an active TID to initiate a TCP connection.
3145 */
3146 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3147 if (ep->atid == -1) {
3148 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3149 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003150 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003151 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003152 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003153
Steve Wise170003c2016-02-26 09:18:03 -06003154 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003155 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003156 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003157 sizeof(ep->com.remote_addr));
3158
Steve Wise170003c2016-02-26 09:18:03 -06003159 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3160 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3161 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3162 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003163
Steve Wise170003c2016-02-26 09:18:03 -06003164 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303165 iptype = 4;
3166 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003167
Vipul Pandya830662f2013-07-04 16:10:47 +05303168 /*
3169 * Handle loopback requests to INADDR_ANY.
3170 */
3171 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3172 err = pick_local_ipaddrs(dev, cm_id);
3173 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003174 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303175 }
3176
3177 /* find a route */
3178 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3179 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3180 ra, ntohs(raddr->sin_port));
3181 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3182 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303183 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303184 } else {
3185 iptype = 6;
3186 ra = (__u8 *)&raddr6->sin6_addr;
3187
3188 /*
3189 * Handle loopback requests to INADDR_ANY.
3190 */
3191 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3192 err = pick_local_ip6addrs(dev, cm_id);
3193 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003194 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303195 }
3196
3197 /* find a route */
3198 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3199 __func__, laddr6->sin6_addr.s6_addr,
3200 ntohs(laddr6->sin6_port),
3201 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3202 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3203 raddr6->sin6_addr.s6_addr,
3204 laddr6->sin6_port, raddr6->sin6_port, 0,
3205 raddr6->sin6_scope_id);
3206 }
3207 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003208 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3209 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003210 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003211 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003212
Hariprasad S963cab52015-09-23 17:19:27 +05303213 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303214 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003215 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003216 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003217 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003218 }
3219
3220 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3221 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3222 ep->l2t->idx);
3223
3224 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303225 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003226
3227 /* send connect request to rnic */
3228 err = send_connect(ep);
3229 if (!err)
3230 goto out;
3231
3232 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003233fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003234 dst_release(ep->dst);
3235fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003236 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003237 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003238fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003239 cm_id->rem_ref(cm_id);
3240 c4iw_put_ep(&ep->com);
3241out:
3242 return err;
3243}
3244
Vipul Pandya830662f2013-07-04 16:10:47 +05303245static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3246{
3247 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003248 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003249 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303250
Hariprasad S28de1f72016-01-13 10:03:14 +05303251 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3252 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3253 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3254 if (err)
3255 return err;
3256 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303257 c4iw_init_wr_wait(&ep->com.wr_wait);
3258 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3259 ep->stid, &sin6->sin6_addr,
3260 sin6->sin6_port,
3261 ep->com.dev->rdev.lldi.rxq_ids[0]);
3262 if (!err)
3263 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3264 &ep->com.wr_wait,
3265 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303266 else if (err > 0)
3267 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303268 if (err) {
3269 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3270 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303271 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3272 err, ep->stid,
3273 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303274 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303275 return err;
3276}
3277
3278static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3279{
3280 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003281 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003282 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303283
3284 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3285 do {
3286 err = cxgb4_create_server_filter(
3287 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3288 sin->sin_addr.s_addr, sin->sin_port, 0,
3289 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3290 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303291 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3292 err = -EIO;
3293 break;
3294 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303295 set_current_state(TASK_UNINTERRUPTIBLE);
3296 schedule_timeout(usecs_to_jiffies(100));
3297 }
3298 } while (err == -EBUSY);
3299 } else {
3300 c4iw_init_wr_wait(&ep->com.wr_wait);
3301 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3302 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3303 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3304 if (!err)
3305 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3306 &ep->com.wr_wait,
3307 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303308 else if (err > 0)
3309 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303310 }
3311 if (err)
3312 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3313 , err, ep->stid,
3314 &sin->sin_addr, ntohs(sin->sin_port));
3315 return err;
3316}
3317
Steve Wisecfdda9d2010-04-21 15:30:06 -07003318int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3319{
3320 int err = 0;
3321 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3322 struct c4iw_listen_ep *ep;
3323
Steve Wisecfdda9d2010-04-21 15:30:06 -07003324 might_sleep();
3325
3326 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3327 if (!ep) {
3328 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3329 err = -ENOMEM;
3330 goto fail1;
3331 }
3332 PDBG("%s ep %p\n", __func__, ep);
3333 cm_id->add_ref(cm_id);
3334 ep->com.cm_id = cm_id;
3335 ep->com.dev = dev;
3336 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003337 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303338 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003339
3340 /*
3341 * Allocate a server TID.
3342 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303343 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3344 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303345 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003346 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003347 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303348 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003349 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003350
Steve Wisecfdda9d2010-04-21 15:30:06 -07003351 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003352 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003353 err = -ENOMEM;
3354 goto fail2;
3355 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003356 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003357
Steve Wise170003c2016-02-26 09:18:03 -06003358 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3359 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003360
Steve Wisecfdda9d2010-04-21 15:30:06 -07003361 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303362 if (ep->com.local_addr.ss_family == AF_INET)
3363 err = create_server4(dev, ep);
3364 else
3365 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003366 if (!err) {
3367 cm_id->provider_data = ep;
3368 goto out;
3369 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003370
Vipul Pandya830662f2013-07-04 16:10:47 +05303371 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3372 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003373fail2:
3374 cm_id->rem_ref(cm_id);
3375 c4iw_put_ep(&ep->com);
3376fail1:
3377out:
3378 return err;
3379}
3380
3381int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3382{
3383 int err;
3384 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3385
3386 PDBG("%s ep %p\n", __func__, ep);
3387
3388 might_sleep();
3389 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303390 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3391 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003392 err = cxgb4_remove_server_filter(
3393 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3394 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3395 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303396 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003397 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303398 err = cxgb4_remove_server(
3399 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3400 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003401 if (err)
3402 goto done;
3403 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3404 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003405 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303406 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3407 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003408 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003409 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303410 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3411 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003412done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003413 cm_id->rem_ref(cm_id);
3414 c4iw_put_ep(&ep->com);
3415 return err;
3416}
3417
3418int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3419{
3420 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003421 int close = 0;
3422 int fatal = 0;
3423 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003424
Steve Wise2f5b48c2010-09-10 11:15:36 -05003425 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003426
3427 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3428 states[ep->com.state], abrupt);
3429
Hariprasad S6e410d82016-05-05 01:27:31 +05303430 /*
3431 * Ref the ep here in case we have fatal errors causing the
3432 * ep to be released and freed.
3433 */
3434 c4iw_get_ep(&ep->com);
3435
Steve Wisecfdda9d2010-04-21 15:30:06 -07003436 rdev = &ep->com.dev->rdev;
3437 if (c4iw_fatal_error(rdev)) {
3438 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303439 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003440 ep->com.state = DEAD;
3441 }
3442 switch (ep->com.state) {
3443 case MPA_REQ_WAIT:
3444 case MPA_REQ_SENT:
3445 case MPA_REQ_RCVD:
3446 case MPA_REP_SENT:
3447 case FPDU_MODE:
3448 close = 1;
3449 if (abrupt)
3450 ep->com.state = ABORTING;
3451 else {
3452 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003453 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003454 }
3455 set_bit(CLOSE_SENT, &ep->com.flags);
3456 break;
3457 case CLOSING:
3458 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3459 close = 1;
3460 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003461 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003462 ep->com.state = ABORTING;
3463 } else
3464 ep->com.state = MORIBUND;
3465 }
3466 break;
3467 case MORIBUND:
3468 case ABORTING:
3469 case DEAD:
3470 PDBG("%s ignoring disconnect ep %p state %u\n",
3471 __func__, ep, ep->com.state);
3472 break;
3473 default:
3474 BUG();
3475 break;
3476 }
3477
Steve Wisecfdda9d2010-04-21 15:30:06 -07003478 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003479 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003480 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303481 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003482 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003483 } else {
3484 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003485 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003486 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303487 if (ret) {
3488 if (!abrupt) {
3489 stop_ep_timer(ep);
3490 close_complete_upcall(ep, -EIO);
3491 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003492 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303493 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003494 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003495 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303496 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003497 if (fatal)
3498 release_ep_resources(ep);
3499 return ret;
3500}
3501
Vipul Pandya1cab7752012-12-10 09:30:55 +00003502static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3503 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3504{
3505 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003506 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003507
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003508 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3509 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003510 if (!ep)
3511 return;
3512
3513 switch (req->retval) {
3514 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003515 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3516 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3517 send_fw_act_open_req(ep, atid);
3518 return;
3519 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003520 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003521 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3522 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3523 send_fw_act_open_req(ep, atid);
3524 return;
3525 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003526 break;
3527 default:
3528 pr_info("%s unexpected ofld conn wr retval %d\n",
3529 __func__, req->retval);
3530 break;
3531 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003532 pr_err("active ofld_connect_wr failure %d atid %d\n",
3533 req->retval, atid);
3534 mutex_lock(&dev->rdev.stats.lock);
3535 dev->rdev.stats.act_ofld_conn_fails++;
3536 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003537 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003538 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303539 if (ep->com.remote_addr.ss_family == AF_INET6) {
3540 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003541 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303542 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3543 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3544 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003545 remove_handle(dev, &dev->atid_idr, atid);
3546 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3547 dst_release(ep->dst);
3548 cxgb4_l2t_release(ep->l2t);
3549 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003550}
3551
3552static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3553 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3554{
3555 struct sk_buff *rpl_skb;
3556 struct cpl_pass_accept_req *cpl;
3557 int ret;
3558
Paul Bolle710a3112013-02-05 20:51:30 +00003559 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003560 BUG_ON(!rpl_skb);
3561 if (req->retval) {
3562 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003563 mutex_lock(&dev->rdev.stats.lock);
3564 dev->rdev.stats.pas_ofld_conn_fails++;
3565 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003566 kfree_skb(rpl_skb);
3567 } else {
3568 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3569 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003570 (__force u32) htonl(
3571 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003572 ret = pass_accept_req(dev, rpl_skb);
3573 if (!ret)
3574 kfree_skb(rpl_skb);
3575 }
3576 return;
3577}
3578
3579static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003580{
3581 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003582 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3583
3584 switch (rpl->type) {
3585 case FW6_TYPE_CQE:
3586 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3587 break;
3588 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3589 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3590 switch (req->t_state) {
3591 case TCP_SYN_SENT:
3592 active_ofld_conn_reply(dev, skb, req);
3593 break;
3594 case TCP_SYN_RECV:
3595 passive_ofld_conn_reply(dev, skb, req);
3596 break;
3597 default:
3598 pr_err("%s unexpected ofld conn wr state %d\n",
3599 __func__, req->t_state);
3600 break;
3601 }
3602 break;
3603 }
3604 return 0;
3605}
3606
3607static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3608{
Hariprasad S963cab52015-09-23 17:19:27 +05303609 __be32 l2info;
3610 __be16 hdr_len, vlantag, len;
3611 u16 eth_hdr_len;
3612 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003613 u8 intf;
3614 struct cpl_rx_pkt *cpl = cplhdr(skb);
3615 struct cpl_pass_accept_req *req;
3616 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003617 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303618 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003619
Vipul Pandyaf079af72013-03-14 05:08:58 +00003620 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003621 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303622 vlantag = cpl->vlan;
3623 len = cpl->len;
3624 l2info = cpl->l2info;
3625 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003626 intf = cpl->iff;
3627
3628 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3629
3630 /*
3631 * We need to parse the TCP options from SYN packet.
3632 * to generate cpl_pass_accept_req.
3633 */
3634 memset(&tmp_opt, 0, sizeof(tmp_opt));
3635 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003636 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003637
3638 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3639 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303640 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3641 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303642 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303643 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303644 type = dev->rdev.lldi.adapter_type;
3645 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3646 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3647 req->hdr_len =
3648 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3649 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3650 eth_hdr_len = is_t4(type) ?
3651 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3652 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3653 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3654 IP_HDR_LEN_V(ip_hdr_len) |
3655 ETH_HDR_LEN_V(eth_hdr_len));
3656 } else { /* T6 and later */
3657 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3658 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3659 T6_IP_HDR_LEN_V(ip_hdr_len) |
3660 T6_ETH_HDR_LEN_V(eth_hdr_len));
3661 }
3662 req->vlan = vlantag;
3663 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003664 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3665 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003666 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3667 if (tmp_opt.wscale_ok)
3668 req->tcpopt.wsf = tmp_opt.snd_wscale;
3669 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3670 if (tmp_opt.sack_ok)
3671 req->tcpopt.sack = 1;
3672 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3673 return;
3674}
3675
3676static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3677 __be32 laddr, __be16 lport,
3678 __be32 raddr, __be16 rport,
3679 u32 rcv_isn, u32 filter, u16 window,
3680 u32 rss_qid, u8 port_id)
3681{
3682 struct sk_buff *req_skb;
3683 struct fw_ofld_connection_wr *req;
3684 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303685 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003686
3687 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3688 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3689 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003690 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303691 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303692 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003693 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003694 req->le.lport = lport;
3695 req->le.pport = rport;
3696 req->le.u.ipv4.lip = laddr;
3697 req->le.u.ipv4.pip = raddr;
3698 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3699 req->tcb.rcv_adv = htons(window);
3700 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303701 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3702 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3703 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003704 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003705
3706 /*
3707 * We store the qid in opt2 which will be used by the firmware
3708 * to send us the wr response.
3709 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003710 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003711
3712 /*
3713 * We initialize the MSS index in TCB to 0xF.
3714 * So that when driver sends cpl_pass_accept_rpl
3715 * TCB picks up the correct value. If this was 0
3716 * TP will ignore any value > 0 for MSS index.
3717 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003718 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303719 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003720
3721 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303722 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3723 if (ret < 0) {
3724 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3725 ret);
3726 kfree_skb(skb);
3727 kfree_skb(req_skb);
3728 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003729}
3730
3731/*
3732 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3733 * messages when a filter is being used instead of server to
3734 * redirect a syn packet. When packets hit filter they are redirected
3735 * to the offload queue and driver tries to establish the connection
3736 * using firmware work request.
3737 */
3738static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3739{
3740 int stid;
3741 unsigned int filter;
3742 struct ethhdr *eh = NULL;
3743 struct vlan_ethhdr *vlan_eh = NULL;
3744 struct iphdr *iph;
3745 struct tcphdr *tcph;
3746 struct rss_header *rss = (void *)skb->data;
3747 struct cpl_rx_pkt *cpl = (void *)skb->data;
3748 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3749 struct l2t_entry *e;
3750 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003751 struct c4iw_ep *lep;
3752 u16 window;
3753 struct port_info *pi;
3754 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003755 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003756 int step;
3757 u32 tx_chan;
3758 struct neighbour *neigh;
3759
3760 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003761 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003762 goto reject;
3763
3764 /*
3765 * Drop all packets which did not hit the filter.
3766 * Unlikely to happen.
3767 */
3768 if (!(rss->filter_hit && rss->filter_tid))
3769 goto reject;
3770
3771 /*
3772 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3773 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303774 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003775
3776 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3777 if (!lep) {
3778 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3779 goto reject;
3780 }
3781
Hariprasad S963cab52015-09-23 17:19:27 +05303782 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3783 case CHELSIO_T4:
3784 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3785 break;
3786 case CHELSIO_T5:
3787 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3788 break;
3789 case CHELSIO_T6:
3790 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3791 break;
3792 default:
3793 pr_err("T%d Chip is not supported\n",
3794 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3795 goto reject;
3796 }
3797
Vipul Pandyaf079af72013-03-14 05:08:58 +00003798 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003799 eh = (struct ethhdr *)(req + 1);
3800 iph = (struct iphdr *)(eh + 1);
3801 } else {
3802 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3803 iph = (struct iphdr *)(vlan_eh + 1);
3804 skb->vlan_tci = ntohs(cpl->vlan);
3805 }
3806
3807 if (iph->version != 0x4)
3808 goto reject;
3809
3810 tcph = (struct tcphdr *)(iph + 1);
3811 skb_set_network_header(skb, (void *)iph - (void *)rss);
3812 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3813 skb_get(skb);
3814
3815 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3816 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3817 ntohs(tcph->source), iph->tos);
3818
Vipul Pandya830662f2013-07-04 16:10:47 +05303819 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3820 iph->tos);
3821 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003822 pr_err("%s - failed to find dst entry!\n",
3823 __func__);
3824 goto reject;
3825 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003826 neigh = dst_neigh_lookup_skb(dst, skb);
3827
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003828 if (!neigh) {
3829 pr_err("%s - failed to allocate neigh!\n",
3830 __func__);
3831 goto free_dst;
3832 }
3833
Vipul Pandya1cab7752012-12-10 09:30:55 +00003834 if (neigh->dev->flags & IFF_LOOPBACK) {
3835 pdev = ip_dev_find(&init_net, iph->daddr);
3836 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3837 pdev, 0);
3838 pi = (struct port_info *)netdev_priv(pdev);
3839 tx_chan = cxgb4_port_chan(pdev);
3840 dev_put(pdev);
3841 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303842 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003843 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303844 pdev, 0);
3845 pi = (struct port_info *)netdev_priv(pdev);
3846 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003847 }
Steve Wiseebf00062014-03-19 17:44:40 +05303848 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003849 if (!e) {
3850 pr_err("%s - failed to allocate l2t entry!\n",
3851 __func__);
3852 goto free_dst;
3853 }
3854
3855 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3856 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003857 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003858
3859 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303860 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3861 dev->rdev.lldi.ports[0],
3862 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003863
3864 /*
3865 * Synthesize the cpl_pass_accept_req. We have everything except the
3866 * TID. Once firmware sends a reply with TID we update the TID field
3867 * in cpl and pass it through the regular cpl_pass_accept_req path.
3868 */
3869 build_cpl_pass_accept_req(skb, stid, iph->tos);
3870 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3871 tcph->source, ntohl(tcph->seq), filter, window,
3872 rss_qid, pi->port_id);
3873 cxgb4_l2t_release(e);
3874free_dst:
3875 dst_release(dst);
3876reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003877 return 0;
3878}
3879
Steve Wisecfdda9d2010-04-21 15:30:06 -07003880/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003881 * These are the real handlers that are called from a
3882 * work queue.
3883 */
Hariprasad S9dec9002016-05-05 01:27:29 +05303884static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003885 [CPL_ACT_ESTABLISH] = act_establish,
3886 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3887 [CPL_RX_DATA] = rx_data,
3888 [CPL_ABORT_RPL_RSS] = abort_rpl,
3889 [CPL_ABORT_RPL] = abort_rpl,
3890 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3891 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3892 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3893 [CPL_PASS_ESTABLISH] = pass_establish,
3894 [CPL_PEER_CLOSE] = peer_close,
3895 [CPL_ABORT_REQ_RSS] = peer_abort,
3896 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3897 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003898 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003899 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05303900 [CPL_RX_PKT] = rx_pkt,
3901 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003902};
3903
3904static void process_timeout(struct c4iw_ep *ep)
3905{
3906 struct c4iw_qp_attributes attrs;
3907 int abort = 1;
3908
Steve Wise2f5b48c2010-09-10 11:15:36 -05003909 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003910 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3911 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003912 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003913 switch (ep->com.state) {
3914 case MPA_REQ_SENT:
3915 __state_set(&ep->com, ABORTING);
3916 connect_reply_upcall(ep, -ETIMEDOUT);
3917 break;
3918 case MPA_REQ_WAIT:
3919 __state_set(&ep->com, ABORTING);
3920 break;
3921 case CLOSING:
3922 case MORIBUND:
3923 if (ep->com.cm_id && ep->com.qp) {
3924 attrs.next_state = C4IW_QP_STATE_ERROR;
3925 c4iw_modify_qp(ep->com.qp->rhp,
3926 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3927 &attrs, 1);
3928 }
3929 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303930 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003931 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003932 case ABORTING:
3933 case DEAD:
3934
3935 /*
3936 * These states are expected if the ep timed out at the same
3937 * time as another thread was calling stop_ep_timer().
3938 * So we silently do nothing for these states.
3939 */
3940 abort = 0;
3941 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003942 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003943 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003944 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003945 abort = 0;
3946 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003947 if (abort)
3948 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecc18b932014-04-24 14:31:53 -05003949 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003950 c4iw_put_ep(&ep->com);
3951}
3952
3953static void process_timedout_eps(void)
3954{
3955 struct c4iw_ep *ep;
3956
3957 spin_lock_irq(&timeout_lock);
3958 while (!list_empty(&timeout_list)) {
3959 struct list_head *tmp;
3960
3961 tmp = timeout_list.next;
3962 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003963 tmp->next = NULL;
3964 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003965 spin_unlock_irq(&timeout_lock);
3966 ep = list_entry(tmp, struct c4iw_ep, entry);
3967 process_timeout(ep);
3968 spin_lock_irq(&timeout_lock);
3969 }
3970 spin_unlock_irq(&timeout_lock);
3971}
3972
3973static void process_work(struct work_struct *work)
3974{
3975 struct sk_buff *skb = NULL;
3976 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003977 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003978 unsigned int opcode;
3979 int ret;
3980
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003981 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003982 while ((skb = skb_dequeue(&rxq))) {
3983 rpl = cplhdr(skb);
3984 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3985 opcode = rpl->ot.opcode;
3986
3987 BUG_ON(!work_handlers[opcode]);
3988 ret = work_handlers[opcode](dev, skb);
3989 if (!ret)
3990 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003991 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003992 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003993}
3994
3995static DECLARE_WORK(skb_work, process_work);
3996
3997static void ep_timeout(unsigned long arg)
3998{
3999 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004000 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004001
4002 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004003 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004004 /*
4005 * Only insert if it is not already on the list.
4006 */
4007 if (!ep->entry.next) {
4008 list_add_tail(&ep->entry, &timeout_list);
4009 kickit = 1;
4010 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004011 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004012 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004013 if (kickit)
4014 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004015}
4016
4017/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004018 * All the CM events are handled on a work queue to have a safe context.
4019 */
4020static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4021{
4022
4023 /*
4024 * Save dev in the skb->cb area.
4025 */
4026 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4027
4028 /*
4029 * Queue the skb and schedule the worker thread.
4030 */
4031 skb_queue_tail(&rxq, skb);
4032 queue_work(workq, &skb_work);
4033 return 0;
4034}
4035
4036static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4037{
4038 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4039
4040 if (rpl->status != CPL_ERR_NONE) {
4041 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4042 "for tid %u\n", rpl->status, GET_TID(rpl));
4043 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004044 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004045 return 0;
4046}
4047
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004048static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4049{
4050 struct cpl_fw6_msg *rpl = cplhdr(skb);
4051 struct c4iw_wr_wait *wr_waitp;
4052 int ret;
4053
4054 PDBG("%s type %u\n", __func__, rpl->type);
4055
4056 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004057 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004058 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004059 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004060 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004061 if (wr_waitp)
4062 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004063 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004064 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004065 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004066 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004067 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004068 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004069 default:
4070 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4071 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004072 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004073 break;
4074 }
4075 return 0;
4076}
4077
Steve Wise8da7e7a2011-06-14 20:59:27 +00004078static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4079{
4080 struct cpl_abort_req_rss *req = cplhdr(skb);
4081 struct c4iw_ep *ep;
4082 struct tid_info *t = dev->rdev.lldi.tids;
4083 unsigned int tid = GET_TID(req);
4084
4085 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05004086 if (!ep) {
4087 printk(KERN_WARNING MOD
4088 "Abort on non-existent endpoint, tid %d\n", tid);
4089 kfree_skb(skb);
4090 return 0;
4091 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304092 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304093 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4094 __func__, ep->hwtid, req->status,
4095 neg_adv_str(req->status));
4096 ep->stats.abort_neg_adv++;
4097 dev->rdev.stats.neg_adv++;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004098 kfree_skb(skb);
4099 return 0;
4100 }
4101 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4102 ep->com.state);
4103
4104 /*
4105 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004106 * However, if we are on MPAv2 and want to retry with MPAv1
4107 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004108 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004109 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4110 if (ep->com.state != MPA_REQ_SENT)
4111 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4112 } else
4113 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00004114 sched(dev, skb);
4115 return 0;
4116}
4117
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004118/*
4119 * Most upcalls from the T4 Core go to sched() to
4120 * schedule the processing on a work queue.
4121 */
4122c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4123 [CPL_ACT_ESTABLISH] = sched,
4124 [CPL_ACT_OPEN_RPL] = sched,
4125 [CPL_RX_DATA] = sched,
4126 [CPL_ABORT_RPL_RSS] = sched,
4127 [CPL_ABORT_RPL] = sched,
4128 [CPL_PASS_OPEN_RPL] = sched,
4129 [CPL_CLOSE_LISTSRV_RPL] = sched,
4130 [CPL_PASS_ACCEPT_REQ] = sched,
4131 [CPL_PASS_ESTABLISH] = sched,
4132 [CPL_PEER_CLOSE] = sched,
4133 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004134 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004135 [CPL_RDMA_TERMINATE] = sched,
4136 [CPL_FW4_ACK] = sched,
4137 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004138 [CPL_FW6_MSG] = fw6_msg,
4139 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004140};
4141
Steve Wisecfdda9d2010-04-21 15:30:06 -07004142int __init c4iw_cm_init(void)
4143{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004144 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004145 skb_queue_head_init(&rxq);
4146
4147 workq = create_singlethread_workqueue("iw_cxgb4");
4148 if (!workq)
4149 return -ENOMEM;
4150
Steve Wisecfdda9d2010-04-21 15:30:06 -07004151 return 0;
4152}
4153
Steve Wise46c13762014-06-20 14:26:25 -05004154void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004155{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004156 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004157 flush_workqueue(workq);
4158 destroy_workqueue(workq);
4159}