blob: cc9836e468005809f2992b4558e20b309d8ff657 [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
Steve Wisecc18b932014-04-24 14:31:53 -05001349static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001350{
1351 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301352 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001353 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301354 u16 resp_ird, resp_ord;
1355 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001356 struct c4iw_qp_attributes attrs;
1357 enum c4iw_qp_attr_mask mask;
1358 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001359 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001360
1361 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1362
1363 /*
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001364 * Stop mpa timer. If it expired, then
1365 * we ignore the MPA reply. process_timeout()
1366 * will abort the connection.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001367 */
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001368 if (stop_ep_timer(ep))
Steve Wisecc18b932014-04-24 14:31:53 -05001369 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001370
1371 /*
1372 * If we get more than the supported amount of private data
1373 * then we must fail this connection.
1374 */
1375 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1376 err = -EINVAL;
1377 goto err;
1378 }
1379
1380 /*
1381 * copy the new data into our accumulation buffer.
1382 */
1383 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1384 skb->len);
1385 ep->mpa_pkt_len += skb->len;
1386
1387 /*
1388 * if we don't even have the mpa message, then bail.
1389 */
1390 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001391 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001392 mpa = (struct mpa_message *) ep->mpa_pkt;
1393
1394 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301395 if (mpa->revision > mpa_rev) {
1396 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1397 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001398 err = -EPROTO;
1399 goto err;
1400 }
1401 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1402 err = -EPROTO;
1403 goto err;
1404 }
1405
1406 plen = ntohs(mpa->private_data_size);
1407
1408 /*
1409 * Fail if there's too much private data.
1410 */
1411 if (plen > MPA_MAX_PRIVATE_DATA) {
1412 err = -EPROTO;
1413 goto err;
1414 }
1415
1416 /*
1417 * If plen does not account for pkt size
1418 */
1419 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1420 err = -EPROTO;
1421 goto err;
1422 }
1423
1424 ep->plen = (u8) plen;
1425
1426 /*
1427 * If we don't have all the pdata yet, then bail.
1428 * We'll continue process when more data arrives.
1429 */
1430 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001431 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001432
1433 if (mpa->flags & MPA_REJECT) {
1434 err = -ECONNREFUSED;
1435 goto err;
1436 }
1437
1438 /*
1439 * If we get here we have accumulated the entire mpa
1440 * start reply message including private data. And
1441 * the MPA header is valid.
1442 */
Steve Wisec529fb52014-03-21 20:40:37 +05301443 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001444 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1445 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1446 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301447 ep->mpa_attr.version = mpa->revision;
1448 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1449
1450 if (mpa->revision == 2) {
1451 ep->mpa_attr.enhanced_rdma_conn =
1452 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1453 if (ep->mpa_attr.enhanced_rdma_conn) {
1454 mpa_v2_params = (struct mpa_v2_conn_params *)
1455 (ep->mpa_pkt + sizeof(*mpa));
1456 resp_ird = ntohs(mpa_v2_params->ird) &
1457 MPA_V2_IRD_ORD_MASK;
1458 resp_ord = ntohs(mpa_v2_params->ord) &
1459 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301460 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1461 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301462
1463 /*
1464 * This is a double-check. Ideally, below checks are
1465 * not required since ird/ord stuff has been taken
1466 * care of in c4iw_accept_cr
1467 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301468 if (ep->ird < resp_ord) {
1469 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1470 ep->com.dev->rdev.lldi.max_ordird_qp)
1471 ep->ird = resp_ord;
1472 else
1473 insuff_ird = 1;
1474 } else if (ep->ird > resp_ord) {
1475 ep->ird = resp_ord;
1476 }
1477 if (ep->ord > resp_ird) {
1478 if (RELAXED_IRD_NEGOTIATION)
1479 ep->ord = resp_ird;
1480 else
1481 insuff_ird = 1;
1482 }
1483 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301484 err = -ENOMEM;
1485 ep->ird = resp_ord;
1486 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301487 }
1488
1489 if (ntohs(mpa_v2_params->ird) &
1490 MPA_V2_PEER2PEER_MODEL) {
1491 if (ntohs(mpa_v2_params->ord) &
1492 MPA_V2_RDMA_WRITE_RTR)
1493 ep->mpa_attr.p2p_type =
1494 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1495 else if (ntohs(mpa_v2_params->ord) &
1496 MPA_V2_RDMA_READ_RTR)
1497 ep->mpa_attr.p2p_type =
1498 FW_RI_INIT_P2PTYPE_READ_REQ;
1499 }
1500 }
1501 } else if (mpa->revision == 1)
1502 if (peer2peer)
1503 ep->mpa_attr.p2p_type = p2p_type;
1504
Steve Wisecfdda9d2010-04-21 15:30:06 -07001505 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301506 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1507 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1508 ep->mpa_attr.recv_marker_enabled,
1509 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1510 ep->mpa_attr.p2p_type, p2p_type);
1511
1512 /*
1513 * If responder's RTR does not match with that of initiator, assign
1514 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1515 * generated when moving QP to RTS state.
1516 * A TERM message will be sent after QP has moved to RTS state
1517 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001518 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301519 (ep->mpa_attr.p2p_type != p2p_type)) {
1520 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1521 rtr_mismatch = 1;
1522 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001523
1524 attrs.mpa_attr = ep->mpa_attr;
1525 attrs.max_ird = ep->ird;
1526 attrs.max_ord = ep->ord;
1527 attrs.llp_stream_handle = ep;
1528 attrs.next_state = C4IW_QP_STATE_RTS;
1529
1530 mask = C4IW_QP_ATTR_NEXT_STATE |
1531 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1532 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1533
1534 /* bind QP and TID with INIT_WR */
1535 err = c4iw_modify_qp(ep->com.qp->rhp,
1536 ep->com.qp, mask, &attrs, 1);
1537 if (err)
1538 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301539
1540 /*
1541 * If responder's RTR requirement did not match with what initiator
1542 * supports, generate TERM message
1543 */
1544 if (rtr_mismatch) {
1545 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1546 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1547 attrs.ecode = MPA_NOMATCH_RTR;
1548 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001549 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301550 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001551 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301552 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001553 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301554 goto out;
1555 }
1556
1557 /*
1558 * Generate TERM if initiator IRD is not sufficient for responder
1559 * provided ORD. Currently, we do the same behaviour even when
1560 * responder provided IRD is also not sufficient as regards to
1561 * initiator ORD.
1562 */
1563 if (insuff_ird) {
1564 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1565 __func__);
1566 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1567 attrs.ecode = MPA_INSUFF_IRD;
1568 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001569 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301570 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001571 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301572 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001573 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301574 goto out;
1575 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001576 goto out;
1577err:
Steve Wisec529fb52014-03-21 20:40:37 +05301578 __state_set(&ep->com, ABORTING);
Steve Wiseb21ef162010-06-10 19:02:55 +00001579 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001580out:
1581 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001582 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001583}
1584
1585static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1586{
1587 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301588 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001589 u16 plen;
1590
1591 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1592
Steve Wisecfdda9d2010-04-21 15:30:06 -07001593 /*
1594 * If we get more than the supported amount of private data
1595 * then we must fail this connection.
1596 */
1597 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001598 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001599 abort_connection(ep, skb, GFP_KERNEL);
1600 return;
1601 }
1602
1603 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1604
1605 /*
1606 * Copy the new data into our accumulation buffer.
1607 */
1608 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1609 skb->len);
1610 ep->mpa_pkt_len += skb->len;
1611
1612 /*
1613 * If we don't even have the mpa message, then bail.
1614 * We'll continue process when more data arrives.
1615 */
1616 if (ep->mpa_pkt_len < sizeof(*mpa))
1617 return;
1618
1619 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001620 mpa = (struct mpa_message *) ep->mpa_pkt;
1621
1622 /*
1623 * Validate MPA Header.
1624 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301625 if (mpa->revision > mpa_rev) {
1626 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1627 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001628 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001629 abort_connection(ep, skb, GFP_KERNEL);
1630 return;
1631 }
1632
1633 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001634 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001635 abort_connection(ep, skb, GFP_KERNEL);
1636 return;
1637 }
1638
1639 plen = ntohs(mpa->private_data_size);
1640
1641 /*
1642 * Fail if there's too much private data.
1643 */
1644 if (plen > MPA_MAX_PRIVATE_DATA) {
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 /*
1651 * If plen does not account for pkt size
1652 */
1653 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001654 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001655 abort_connection(ep, skb, GFP_KERNEL);
1656 return;
1657 }
1658 ep->plen = (u8) plen;
1659
1660 /*
1661 * If we don't have all the pdata yet, then bail.
1662 */
1663 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1664 return;
1665
1666 /*
1667 * If we get here we have accumulated the entire mpa
1668 * start reply message including private data.
1669 */
1670 ep->mpa_attr.initiator = 0;
1671 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1672 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1673 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301674 ep->mpa_attr.version = mpa->revision;
1675 if (mpa->revision == 1)
1676 ep->tried_with_mpa_v1 = 1;
1677 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1678
1679 if (mpa->revision == 2) {
1680 ep->mpa_attr.enhanced_rdma_conn =
1681 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1682 if (ep->mpa_attr.enhanced_rdma_conn) {
1683 mpa_v2_params = (struct mpa_v2_conn_params *)
1684 (ep->mpa_pkt + sizeof(*mpa));
1685 ep->ird = ntohs(mpa_v2_params->ird) &
1686 MPA_V2_IRD_ORD_MASK;
1687 ep->ord = ntohs(mpa_v2_params->ord) &
1688 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301689 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1690 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301691 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1692 if (peer2peer) {
1693 if (ntohs(mpa_v2_params->ord) &
1694 MPA_V2_RDMA_WRITE_RTR)
1695 ep->mpa_attr.p2p_type =
1696 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1697 else if (ntohs(mpa_v2_params->ord) &
1698 MPA_V2_RDMA_READ_RTR)
1699 ep->mpa_attr.p2p_type =
1700 FW_RI_INIT_P2PTYPE_READ_REQ;
1701 }
1702 }
1703 } else if (mpa->revision == 1)
1704 if (peer2peer)
1705 ep->mpa_attr.p2p_type = p2p_type;
1706
Steve Wisecfdda9d2010-04-21 15:30:06 -07001707 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1708 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1709 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1710 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1711 ep->mpa_attr.p2p_type);
1712
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001713 /*
1714 * If the endpoint timer already expired, then we ignore
1715 * the start request. process_timeout() will abort
1716 * the connection.
1717 */
1718 if (!stop_ep_timer(ep)) {
1719 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001720
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001721 /* drive upcall */
Hariprasad Shenai10be6b42014-11-21 09:36:35 -06001722 mutex_lock_nested(&ep->parent_ep->com.mutex,
1723 SINGLE_DEPTH_NESTING);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001724 if (ep->parent_ep->com.state != DEAD) {
1725 if (connect_request_upcall(ep))
1726 abort_connection(ep, skb, GFP_KERNEL);
1727 } else {
Steve Wisebe13b2d2014-03-21 20:40:33 +05301728 abort_connection(ep, skb, GFP_KERNEL);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001729 }
1730 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301731 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001732 return;
1733}
1734
1735static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1736{
1737 struct c4iw_ep *ep;
1738 struct cpl_rx_data *hdr = cplhdr(skb);
1739 unsigned int dlen = ntohs(hdr->len);
1740 unsigned int tid = GET_TID(hdr);
1741 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001742 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001743 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001744
1745 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301746 if (!ep)
1747 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001748 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1749 skb_pull(skb, sizeof(*hdr));
1750 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301751 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001752
Steve Wisecfdda9d2010-04-21 15:30:06 -07001753 /* update RX credits */
1754 update_rx_credits(ep, dlen);
1755
Steve Wisec529fb52014-03-21 20:40:37 +05301756 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001757 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001758 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001759 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001760 break;
1761 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001762 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001763 process_mpa_request(ep, skb);
1764 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001765 case FPDU_MODE: {
1766 struct c4iw_qp_attributes attrs;
1767 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001768 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001769 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001770 " qpid %u ep %p state %d tid %u status %d\n",
1771 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301772 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301773 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001774 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001775 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1776 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001777 break;
1778 }
Vipul Pandya15579672013-01-07 13:11:52 +00001779 default:
1780 break;
1781 }
Steve Wisec529fb52014-03-21 20:40:37 +05301782 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001783 if (disconnect)
1784 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001785 return 0;
1786}
1787
1788static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1789{
1790 struct c4iw_ep *ep;
1791 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001792 int release = 0;
1793 unsigned int tid = GET_TID(rpl);
1794 struct tid_info *t = dev->rdev.lldi.tids;
1795
1796 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301797 if (!ep) {
1798 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1799 return 0;
1800 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001801 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001802 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001803 switch (ep->com.state) {
1804 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001805 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001806 __state_set(&ep->com, DEAD);
1807 release = 1;
1808 break;
1809 default:
1810 printk(KERN_ERR "%s ep %p state %d\n",
1811 __func__, ep, ep->com.state);
1812 break;
1813 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001814 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001815
1816 if (release)
1817 release_ep_resources(ep);
1818 return 0;
1819}
1820
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001821static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1822{
1823 struct sk_buff *skb;
1824 struct fw_ofld_connection_wr *req;
1825 unsigned int mtu_idx;
1826 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301827 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301828 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001829
1830 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1831 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1832 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001833 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301834 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301835 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1836 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001837 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001838 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301839 req->le.lport = sin->sin_port;
1840 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001841 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301842 req->le.pport = sin->sin_port;
1843 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001844 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301845 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1846 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001847 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301848 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001849 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001850 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301851 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301852 enable_tcp_timestamps,
1853 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001854 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301855
1856 /*
1857 * Specify the largest window that will fit in opt0. The
1858 * remainder will be specified in the rx_data_ack.
1859 */
1860 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001861 if (win > RCV_BUFSIZ_M)
1862 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301863
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001864 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1865 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001866 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001867 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001868 WND_SCALE_V(wscale) |
1869 MSS_IDX_V(mtu_idx) |
1870 L2T_IDX_V(ep->l2t->idx) |
1871 TX_CHAN_V(ep->tx_chan) |
1872 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301873 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001874 ULP_MODE_V(ULP_MODE_TCPDDP) |
1875 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001876 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1877 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001878 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001879 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001880 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001881 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001882 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001883 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001884 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001885 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001886 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1887 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1888 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001889 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1890 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001891 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1892}
1893
Steve Wisecfdda9d2010-04-21 15:30:06 -07001894/*
1895 * Return whether a failed active open has allocated a TID
1896 */
1897static inline int act_open_has_tid(int status)
1898{
1899 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1900 status != CPL_ERR_ARP_MISS;
1901}
1902
Steve Wise7a2cea22014-03-14 21:52:07 +05301903/* Returns whether a CPL status conveys negative advice.
1904 */
1905static int is_neg_adv(unsigned int status)
1906{
1907 return status == CPL_ERR_RTX_NEG_ADVICE ||
1908 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1909 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1910}
1911
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301912static char *neg_adv_str(unsigned int status)
1913{
1914 switch (status) {
1915 case CPL_ERR_RTX_NEG_ADVICE:
1916 return "Retransmit timeout";
1917 case CPL_ERR_PERSIST_NEG_ADVICE:
1918 return "Persist timeout";
1919 case CPL_ERR_KEEPALV_NEG_ADVICE:
1920 return "Keepalive timeout";
1921 default:
1922 return "Unknown";
1923 }
1924}
1925
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301926static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1927{
1928 ep->snd_win = snd_win;
1929 ep->rcv_win = rcv_win;
1930 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1931}
1932
Vipul Pandya793dad92012-12-10 09:30:56 +00001933#define ACT_OPEN_RETRY_COUNT 2
1934
Vipul Pandya830662f2013-07-04 16:10:47 +05301935static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1936 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301937 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05301938{
1939 struct neighbour *n;
1940 int err, step;
1941 struct net_device *pdev;
1942
1943 n = dst_neigh_lookup(dst, peer_ip);
1944 if (!n)
1945 return -ENODEV;
1946
1947 rcu_read_lock();
1948 err = -ENOMEM;
1949 if (n->dev->flags & IFF_LOOPBACK) {
1950 if (iptype == 4)
1951 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1952 else if (IS_ENABLED(CONFIG_IPV6))
1953 for_each_netdev(&init_net, pdev) {
1954 if (ipv6_chk_addr(&init_net,
1955 (struct in6_addr *)peer_ip,
1956 pdev, 1))
1957 break;
1958 }
1959 else
1960 pdev = NULL;
1961
1962 if (!pdev) {
1963 err = -ENODEV;
1964 goto out;
1965 }
1966 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301967 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05301968 if (!ep->l2t)
1969 goto out;
1970 ep->mtu = pdev->mtu;
1971 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05301972 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
1973 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301974 step = cdev->rdev.lldi.ntxq /
1975 cdev->rdev.lldi.nchan;
1976 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1977 step = cdev->rdev.lldi.nrxq /
1978 cdev->rdev.lldi.nchan;
1979 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1980 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1981 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301982 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301983 dev_put(pdev);
1984 } else {
1985 pdev = get_real_dev(n->dev);
1986 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1987 n, pdev, 0);
1988 if (!ep->l2t)
1989 goto out;
1990 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05001991 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05301992 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
1993 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301994 step = cdev->rdev.lldi.ntxq /
1995 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05001996 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1997 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05301998 step = cdev->rdev.lldi.nrxq /
1999 cdev->rdev.lldi.nchan;
2000 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002001 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302002 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302003
2004 if (clear_mpa_v1) {
2005 ep->retry_with_mpa_v1 = 0;
2006 ep->tried_with_mpa_v1 = 0;
2007 }
2008 }
2009 err = 0;
2010out:
2011 rcu_read_unlock();
2012
2013 neigh_release(n);
2014
2015 return err;
2016}
2017
Vipul Pandya793dad92012-12-10 09:30:56 +00002018static int c4iw_reconnect(struct c4iw_ep *ep)
2019{
2020 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302021 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002022 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302023 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002024 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302025 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002026 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302027 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002028 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302029 int iptype;
2030 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002031
2032 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2033 init_timer(&ep->timer);
2034
2035 /*
2036 * Allocate an active TID to initiate a TCP connection.
2037 */
2038 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2039 if (ep->atid == -1) {
2040 pr_err("%s - cannot alloc atid.\n", __func__);
2041 err = -ENOMEM;
2042 goto fail2;
2043 }
2044 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2045
2046 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002047 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302048 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2049 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302050 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302051 iptype = 4;
2052 ra = (__u8 *)&raddr->sin_addr;
2053 } else {
2054 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2055 raddr6->sin6_addr.s6_addr,
2056 laddr6->sin6_port, raddr6->sin6_port, 0,
2057 raddr6->sin6_scope_id);
2058 iptype = 6;
2059 ra = (__u8 *)&raddr6->sin6_addr;
2060 }
2061 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002062 pr_err("%s - cannot find route.\n", __func__);
2063 err = -EHOSTUNREACH;
2064 goto fail3;
2065 }
Hariprasad S963cab52015-09-23 17:19:27 +05302066 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302067 ep->com.dev->rdev.lldi.adapter_type,
2068 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302069 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002070 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002071 goto fail4;
2072 }
2073
2074 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2075 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2076 ep->l2t->idx);
2077
2078 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302079 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002080
2081 /* send connect request to rnic */
2082 err = send_connect(ep);
2083 if (!err)
2084 goto out;
2085
2086 cxgb4_l2t_release(ep->l2t);
2087fail4:
2088 dst_release(ep->dst);
2089fail3:
2090 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2091 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2092fail2:
2093 /*
2094 * remember to send notification to upper layer.
2095 * We are in here so the upper layer is not aware that this is
2096 * re-connect attempt and so, upper layer is still waiting for
2097 * response of 1st connect request.
2098 */
2099 connect_reply_upcall(ep, -ECONNRESET);
2100 c4iw_put_ep(&ep->com);
2101out:
2102 return err;
2103}
2104
Steve Wisecfdda9d2010-04-21 15:30:06 -07002105static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2106{
2107 struct c4iw_ep *ep;
2108 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002109 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2110 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002111 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002112 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302113 struct sockaddr_in *la;
2114 struct sockaddr_in *ra;
2115 struct sockaddr_in6 *la6;
2116 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002117
2118 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002119 la = (struct sockaddr_in *)&ep->com.local_addr;
2120 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2121 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2122 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002123
2124 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2125 status, status2errno(status));
2126
Steve Wise7a2cea22014-03-14 21:52:07 +05302127 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302128 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2129 __func__, atid, status, neg_adv_str(status));
2130 ep->stats.connect_neg_adv++;
2131 mutex_lock(&dev->rdev.stats.lock);
2132 dev->rdev.stats.neg_adv++;
2133 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002134 return 0;
2135 }
2136
Vipul Pandya793dad92012-12-10 09:30:56 +00002137 set_bit(ACT_OPEN_RPL, &ep->com.history);
2138
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302139 /*
2140 * Log interesting failures.
2141 */
2142 switch (status) {
2143 case CPL_ERR_CONN_RESET:
2144 case CPL_ERR_CONN_TIMEDOUT:
2145 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002146 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302147 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002148 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302149 mutex_unlock(&dev->rdev.stats.lock);
2150 if (ep->com.local_addr.ss_family == AF_INET &&
2151 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002152 send_fw_act_open_req(ep,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002153 TID_TID_G(AOPEN_ATID_G(
Vipul Pandya793dad92012-12-10 09:30:56 +00002154 ntohl(rpl->atid_status))));
2155 return 0;
2156 }
2157 break;
2158 case CPL_ERR_CONN_EXIST:
2159 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2160 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302161 if (ep->com.remote_addr.ss_family == AF_INET6) {
2162 struct sockaddr_in6 *sin6 =
2163 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002164 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302165 cxgb4_clip_release(
2166 ep->com.dev->rdev.lldi.ports[0],
2167 (const u32 *)
2168 &sin6->sin6_addr.s6_addr, 1);
2169 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002170 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2171 atid);
2172 cxgb4_free_atid(t, atid);
2173 dst_release(ep->dst);
2174 cxgb4_l2t_release(ep->l2t);
2175 c4iw_reconnect(ep);
2176 return 0;
2177 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002178 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302179 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302180 if (ep->com.local_addr.ss_family == AF_INET) {
2181 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2182 atid, status, status2errno(status),
2183 &la->sin_addr.s_addr, ntohs(la->sin_port),
2184 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2185 } else {
2186 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2187 atid, status, status2errno(status),
2188 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2189 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2190 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302191 break;
2192 }
2193
Steve Wisecfdda9d2010-04-21 15:30:06 -07002194 connect_reply_upcall(ep, status2errno(status));
2195 state_set(&ep->com, DEAD);
2196
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302197 if (ep->com.remote_addr.ss_family == AF_INET6) {
2198 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002199 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302200 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2201 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2202 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002203 if (status && act_open_has_tid(status))
2204 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2205
Vipul Pandya793dad92012-12-10 09:30:56 +00002206 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002207 cxgb4_free_atid(t, atid);
2208 dst_release(ep->dst);
2209 cxgb4_l2t_release(ep->l2t);
2210 c4iw_put_ep(&ep->com);
2211
2212 return 0;
2213}
2214
2215static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2216{
2217 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2218 struct tid_info *t = dev->rdev.lldi.tids;
2219 unsigned int stid = GET_TID(rpl);
2220 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2221
2222 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002223 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2224 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002225 }
2226 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2227 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002228 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002229
Vipul Pandya1cab7752012-12-10 09:30:55 +00002230out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002231 return 0;
2232}
2233
Steve Wisecfdda9d2010-04-21 15:30:06 -07002234static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2235{
2236 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2237 struct tid_info *t = dev->rdev.lldi.tids;
2238 unsigned int stid = GET_TID(rpl);
2239 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2240
2241 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002242 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002243 return 0;
2244}
2245
Hariprasad S9dec9002016-05-05 01:27:29 +05302246static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2247 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002248{
2249 struct cpl_pass_accept_rpl *rpl;
2250 unsigned int mtu_idx;
2251 u64 opt0;
2252 u32 opt2;
2253 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302254 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302255 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302256 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002257
2258 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2259 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302260
Steve Wisecfdda9d2010-04-21 15:30:06 -07002261 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302262 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302263 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302264 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2265 rpl5 = (void *)rpl;
2266 INIT_TP_WR(rpl5, ep->hwtid);
2267 } else {
2268 skb_trim(skb, sizeof(*rpl));
2269 INIT_TP_WR(rpl, ep->hwtid);
2270 }
2271 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2272 ep->hwtid));
2273
2274 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302275 enable_tcp_timestamps && req->tcpopt.tstamp,
2276 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002277 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302278
2279 /*
2280 * Specify the largest window that will fit in opt0. The
2281 * remainder will be specified in the rx_data_ack.
2282 */
2283 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002284 if (win > RCV_BUFSIZ_M)
2285 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002286 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002287 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002288 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002289 WND_SCALE_V(wscale) |
2290 MSS_IDX_V(mtu_idx) |
2291 L2T_IDX_V(ep->l2t->idx) |
2292 TX_CHAN_V(ep->tx_chan) |
2293 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002294 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002295 ULP_MODE_V(ULP_MODE_TCPDDP) |
2296 RCV_BUFSIZ_V(win);
2297 opt2 = RX_CHANNEL_V(0) |
2298 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002299
2300 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002301 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002302 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002303 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002304 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002305 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002306 if (enable_ecn) {
2307 const struct tcphdr *tcph;
2308 u32 hlen = ntohl(req->hdr_len);
2309
Hariprasad S963cab52015-09-23 17:19:27 +05302310 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2311 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2312 IP_HDR_LEN_G(hlen);
2313 else
2314 tcph = (const void *)(req + 1) +
2315 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002316 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002317 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002318 }
Hariprasad S963cab52015-09-23 17:19:27 +05302319 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302320 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002321 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302322 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302323 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302324 rpl5 = (void *)rpl;
2325 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2326 if (peer2peer)
2327 isn += 4;
2328 rpl5->iss = cpu_to_be32(isn);
2329 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002330 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002331
Steve Wisecfdda9d2010-04-21 15:30:06 -07002332 rpl->opt0 = cpu_to_be64(opt0);
2333 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002334 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302335 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002336
Hariprasad S9dec9002016-05-05 01:27:29 +05302337 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002338}
2339
Vipul Pandya830662f2013-07-04 16:10:47 +05302340static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002341{
Vipul Pandya830662f2013-07-04 16:10:47 +05302342 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002343 BUG_ON(skb_cloned(skb));
2344 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002345 release_tid(&dev->rdev, hwtid, skb);
2346 return;
2347}
2348
Hariprasad S963cab52015-09-23 17:19:27 +05302349static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2350 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002351 __be16 *local_port, __be16 *peer_port)
2352{
Hariprasad S963cab52015-09-23 17:19:27 +05302353 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2354 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2355 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2356 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2357 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2358 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002359 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302360 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002361 struct tcphdr *tcp = (struct tcphdr *)
2362 ((u8 *)(req + 1) + eth_len + ip_len);
2363
Vipul Pandya830662f2013-07-04 16:10:47 +05302364 if (ip->version == 4) {
2365 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2366 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2367 ntohs(tcp->dest));
2368 *iptype = 4;
2369 memcpy(peer_ip, &ip->saddr, 4);
2370 memcpy(local_ip, &ip->daddr, 4);
2371 } else {
2372 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2373 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2374 ntohs(tcp->dest));
2375 *iptype = 6;
2376 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2377 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2378 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002379 *peer_port = tcp->source;
2380 *local_port = tcp->dest;
2381
2382 return;
2383}
2384
2385static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2386{
Vipul Pandya793dad92012-12-10 09:30:56 +00002387 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002388 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002389 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002390 struct tid_info *t = dev->rdev.lldi.tids;
2391 unsigned int hwtid = GET_TID(req);
2392 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302393 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002394 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302395 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002396 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002397 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302398 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302399 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302400 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002401
2402 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002403 if (!parent_ep) {
2404 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2405 goto reject;
2406 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002407
Steve Wisecfdda9d2010-04-21 15:30:06 -07002408 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302409 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002410 goto reject;
2411 }
2412
Hariprasad S963cab52015-09-23 17:19:27 +05302413 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2414 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302415
Steve Wisecfdda9d2010-04-21 15:30:06 -07002416 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302417 if (iptype == 4) {
2418 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2419 , __func__, parent_ep, hwtid,
2420 local_ip, peer_ip, ntohs(local_port),
2421 ntohs(peer_port), peer_mss);
2422 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2423 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302424 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302425 } else {
2426 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2427 , __func__, parent_ep, hwtid,
2428 local_ip, peer_ip, ntohs(local_port),
2429 ntohs(peer_port), peer_mss);
2430 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002431 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302432 ((struct sockaddr_in6 *)
2433 &parent_ep->com.local_addr)->sin6_scope_id);
2434 }
2435 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002436 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2437 __func__);
2438 goto reject;
2439 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002440
2441 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2442 if (!child_ep) {
2443 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2444 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002445 dst_release(dst);
2446 goto reject;
2447 }
David Miller3786cf12011-12-02 16:52:31 +00002448
Hariprasad S963cab52015-09-23 17:19:27 +05302449 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302450 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002451 if (err) {
2452 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2453 __func__);
2454 dst_release(dst);
2455 kfree(child_ep);
2456 goto reject;
2457 }
2458
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302459 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2460 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2461 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2462 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002463
Steve Wisecfdda9d2010-04-21 15:30:06 -07002464 state_set(&child_ep->com, CONNECTING);
2465 child_ep->com.dev = dev;
2466 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002467
Vipul Pandya830662f2013-07-04 16:10:47 +05302468 if (iptype == 4) {
2469 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002470 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002471
Vipul Pandya830662f2013-07-04 16:10:47 +05302472 sin->sin_family = PF_INET;
2473 sin->sin_port = local_port;
2474 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002475
2476 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2477 sin->sin_family = PF_INET;
2478 sin->sin_port = ((struct sockaddr_in *)
2479 &parent_ep->com.local_addr)->sin_port;
2480 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2481
Steve Wise170003c2016-02-26 09:18:03 -06002482 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302483 sin->sin_family = PF_INET;
2484 sin->sin_port = peer_port;
2485 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2486 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002487 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302488 sin6->sin6_family = PF_INET6;
2489 sin6->sin6_port = local_port;
2490 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002491
2492 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2493 sin6->sin6_family = PF_INET6;
2494 sin6->sin6_port = ((struct sockaddr_in6 *)
2495 &parent_ep->com.local_addr)->sin6_port;
2496 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2497
Steve Wise170003c2016-02-26 09:18:03 -06002498 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302499 sin6->sin6_family = PF_INET6;
2500 sin6->sin6_port = peer_port;
2501 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2502 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002503
Steve Wisecfdda9d2010-04-21 15:30:06 -07002504 c4iw_get_ep(&parent_ep->com);
2505 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302506 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002507 child_ep->dst = dst;
2508 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002509
2510 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002511 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002512
2513 init_timer(&child_ep->timer);
2514 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002515 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Hariprasad S9dec9002016-05-05 01:27:29 +05302516 if (accept_cr(child_ep, skb, req)) {
2517 c4iw_put_ep(&parent_ep->com);
2518 release_ep_resources(child_ep);
2519 } else {
2520 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2521 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302522 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002523 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302524 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2525 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2526 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002527 goto out;
2528reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302529 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002530out:
2531 return 0;
2532}
2533
2534static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2535{
2536 struct c4iw_ep *ep;
2537 struct cpl_pass_establish *req = cplhdr(skb);
2538 struct tid_info *t = dev->rdev.lldi.tids;
2539 unsigned int tid = GET_TID(req);
2540
2541 ep = lookup_tid(t, tid);
2542 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2543 ep->snd_seq = be32_to_cpu(req->snd_isn);
2544 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2545
Vipul Pandya1cab7752012-12-10 09:30:55 +00002546 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2547 ntohs(req->tcp_opt));
2548
Steve Wisecfdda9d2010-04-21 15:30:06 -07002549 set_emss(ep, ntohs(req->tcp_opt));
2550
2551 dst_confirm(ep->dst);
2552 state_set(&ep->com, MPA_REQ_WAIT);
2553 start_ep_timer(ep);
2554 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002555 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002556
2557 return 0;
2558}
2559
2560static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2561{
2562 struct cpl_peer_close *hdr = cplhdr(skb);
2563 struct c4iw_ep *ep;
2564 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002565 int disconnect = 1;
2566 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002567 struct tid_info *t = dev->rdev.lldi.tids;
2568 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002569 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002570
2571 ep = lookup_tid(t, tid);
2572 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2573 dst_confirm(ep->dst);
2574
Vipul Pandya793dad92012-12-10 09:30:56 +00002575 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002576 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002577 switch (ep->com.state) {
2578 case MPA_REQ_WAIT:
2579 __state_set(&ep->com, CLOSING);
2580 break;
2581 case MPA_REQ_SENT:
2582 __state_set(&ep->com, CLOSING);
2583 connect_reply_upcall(ep, -ECONNRESET);
2584 break;
2585 case MPA_REQ_RCVD:
2586
2587 /*
2588 * We're gonna mark this puppy DEAD, but keep
2589 * the reference on it until the ULP accepts or
2590 * rejects the CR. Also wake up anyone waiting
2591 * in rdma connection migration (see c4iw_accept_cr()).
2592 */
2593 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002594 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002595 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002596 break;
2597 case MPA_REP_SENT:
2598 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002599 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002600 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002601 break;
2602 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002603 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002604 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002605 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002606 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002607 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002608 if (ret != -ECONNRESET) {
2609 peer_close_upcall(ep);
2610 disconnect = 1;
2611 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002612 break;
2613 case ABORTING:
2614 disconnect = 0;
2615 break;
2616 case CLOSING:
2617 __state_set(&ep->com, MORIBUND);
2618 disconnect = 0;
2619 break;
2620 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002621 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002622 if (ep->com.cm_id && ep->com.qp) {
2623 attrs.next_state = C4IW_QP_STATE_IDLE;
2624 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2625 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2626 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302627 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002628 __state_set(&ep->com, DEAD);
2629 release = 1;
2630 disconnect = 0;
2631 break;
2632 case DEAD:
2633 disconnect = 0;
2634 break;
2635 default:
2636 BUG_ON(1);
2637 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002638 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002639 if (disconnect)
2640 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2641 if (release)
2642 release_ep_resources(ep);
2643 return 0;
2644}
2645
Steve Wisecfdda9d2010-04-21 15:30:06 -07002646static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2647{
2648 struct cpl_abort_req_rss *req = cplhdr(skb);
2649 struct c4iw_ep *ep;
2650 struct cpl_abort_rpl *rpl;
2651 struct sk_buff *rpl_skb;
2652 struct c4iw_qp_attributes attrs;
2653 int ret;
2654 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002655 struct tid_info *t = dev->rdev.lldi.tids;
2656 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002657
2658 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302659 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302660 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2661 __func__, ep->hwtid, req->status,
2662 neg_adv_str(req->status));
2663 ep->stats.abort_neg_adv++;
2664 mutex_lock(&dev->rdev.stats.lock);
2665 dev->rdev.stats.neg_adv++;
2666 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002667 return 0;
2668 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002669 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2670 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002671 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002672
2673 /*
2674 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302675 * However, this is not needed if com state is just
2676 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002677 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302678 if (ep->com.state != MPA_REQ_SENT)
2679 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002680
2681 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002682 switch (ep->com.state) {
2683 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302684 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002685 break;
2686 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002687 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002688 break;
2689 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002690 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002691 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302692 connect_reply_upcall(ep, -ECONNRESET);
2693 else {
2694 /*
2695 * we just don't send notification upwards because we
2696 * want to retry with mpa_v1 without upper layers even
2697 * knowing it.
2698 *
2699 * do some housekeeping so as to re-initiate the
2700 * connection
2701 */
2702 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2703 mpa_rev);
2704 ep->retry_with_mpa_v1 = 1;
2705 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002706 break;
2707 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002708 break;
2709 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002710 break;
2711 case MORIBUND:
2712 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002713 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002714 /*FALLTHROUGH*/
2715 case FPDU_MODE:
2716 if (ep->com.cm_id && ep->com.qp) {
2717 attrs.next_state = C4IW_QP_STATE_ERROR;
2718 ret = c4iw_modify_qp(ep->com.qp->rhp,
2719 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2720 &attrs, 1);
2721 if (ret)
2722 printk(KERN_ERR MOD
2723 "%s - qp <- error failed!\n",
2724 __func__);
2725 }
2726 peer_abort_upcall(ep);
2727 break;
2728 case ABORTING:
2729 break;
2730 case DEAD:
2731 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002732 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002733 return 0;
2734 default:
2735 BUG_ON(1);
2736 break;
2737 }
2738 dst_confirm(ep->dst);
2739 if (ep->com.state != ABORTING) {
2740 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302741 /* we don't release if we want to retry with mpa_v1 */
2742 if (!ep->retry_with_mpa_v1)
2743 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002744 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002745 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002746
2747 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2748 if (!rpl_skb) {
2749 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2750 __func__);
2751 release = 1;
2752 goto out;
2753 }
2754 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2755 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2756 INIT_TP_WR(rpl, ep->hwtid);
2757 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2758 rpl->cmd = CPL_ABORT_NO_RST;
2759 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2760out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002761 if (release)
2762 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002763 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302764 if (ep->com.remote_addr.ss_family == AF_INET6) {
2765 struct sockaddr_in6 *sin6 =
2766 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002767 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302768 cxgb4_clip_release(
2769 ep->com.dev->rdev.lldi.ports[0],
2770 (const u32 *)&sin6->sin6_addr.s6_addr,
2771 1);
2772 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002773 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302774 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2775 dst_release(ep->dst);
2776 cxgb4_l2t_release(ep->l2t);
2777 c4iw_reconnect(ep);
2778 }
2779
Steve Wisecfdda9d2010-04-21 15:30:06 -07002780 return 0;
2781}
2782
2783static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2784{
2785 struct c4iw_ep *ep;
2786 struct c4iw_qp_attributes attrs;
2787 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002788 int release = 0;
2789 struct tid_info *t = dev->rdev.lldi.tids;
2790 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002791
2792 ep = lookup_tid(t, tid);
2793
2794 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2795 BUG_ON(!ep);
2796
2797 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002798 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002799 switch (ep->com.state) {
2800 case CLOSING:
2801 __state_set(&ep->com, MORIBUND);
2802 break;
2803 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002804 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002805 if ((ep->com.cm_id) && (ep->com.qp)) {
2806 attrs.next_state = C4IW_QP_STATE_IDLE;
2807 c4iw_modify_qp(ep->com.qp->rhp,
2808 ep->com.qp,
2809 C4IW_QP_ATTR_NEXT_STATE,
2810 &attrs, 1);
2811 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302812 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002813 __state_set(&ep->com, DEAD);
2814 release = 1;
2815 break;
2816 case ABORTING:
2817 case DEAD:
2818 break;
2819 default:
2820 BUG_ON(1);
2821 break;
2822 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002823 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002824 if (release)
2825 release_ep_resources(ep);
2826 return 0;
2827}
2828
2829static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2830{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002831 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002832 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002833 unsigned int tid = GET_TID(rpl);
2834 struct c4iw_ep *ep;
2835 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002836
2837 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002838 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002839
Steve Wise30c95c22011-05-09 22:06:22 -07002840 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002841 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2842 ep->com.qp->wq.sq.qid);
2843 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2844 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2845 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2846 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002847 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002848
Steve Wisecfdda9d2010-04-21 15:30:06 -07002849 return 0;
2850}
2851
2852/*
2853 * Upcall from the adapter indicating data has been transmitted.
2854 * For us its just the single MPA request or reply. We can now free
2855 * the skb holding the mpa message.
2856 */
2857static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2858{
2859 struct c4iw_ep *ep;
2860 struct cpl_fw4_ack *hdr = cplhdr(skb);
2861 u8 credits = hdr->credits;
2862 unsigned int tid = GET_TID(hdr);
2863 struct tid_info *t = dev->rdev.lldi.tids;
2864
2865
2866 ep = lookup_tid(t, tid);
2867 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2868 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002869 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2870 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002871 return 0;
2872 }
2873
2874 dst_confirm(ep->dst);
2875 if (ep->mpa_skb) {
2876 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2877 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2878 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2879 kfree_skb(ep->mpa_skb);
2880 ep->mpa_skb = NULL;
2881 }
2882 return 0;
2883}
2884
Steve Wisecfdda9d2010-04-21 15:30:06 -07002885int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2886{
Steve Wisea7db89e2014-03-21 20:40:35 +05302887 int err = 0;
2888 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002889 struct c4iw_ep *ep = to_ep(cm_id);
2890 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2891
Steve Wisea7db89e2014-03-21 20:40:35 +05302892 mutex_lock(&ep->com.mutex);
2893 if (ep->com.state == DEAD) {
2894 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002895 c4iw_put_ep(&ep->com);
2896 return -ECONNRESET;
2897 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002898 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302899 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002900 if (mpa_rev == 0)
2901 abort_connection(ep, NULL, GFP_KERNEL);
2902 else {
2903 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302904 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002905 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302906 mutex_unlock(&ep->com.mutex);
2907 if (disconnect)
2908 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002909 c4iw_put_ep(&ep->com);
2910 return 0;
2911}
2912
2913int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2914{
2915 int err;
2916 struct c4iw_qp_attributes attrs;
2917 enum c4iw_qp_attr_mask mask;
2918 struct c4iw_ep *ep = to_ep(cm_id);
2919 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2920 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2921
2922 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302923
2924 mutex_lock(&ep->com.mutex);
2925 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002926 err = -ECONNRESET;
2927 goto err;
2928 }
2929
Steve Wisea7db89e2014-03-21 20:40:35 +05302930 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002931 BUG_ON(!qp);
2932
Vipul Pandya793dad92012-12-10 09:30:56 +00002933 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302934 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2935 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002936 abort_connection(ep, NULL, GFP_KERNEL);
2937 err = -EINVAL;
2938 goto err;
2939 }
2940
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302941 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2942 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302943 if (RELAXED_IRD_NEGOTIATION) {
2944 ep->ord = ep->ird;
2945 } else {
2946 ep->ird = conn_param->ird;
2947 ep->ord = conn_param->ord;
2948 send_mpa_reject(ep, conn_param->private_data,
2949 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302950 abort_connection(ep, NULL, GFP_KERNEL);
2951 err = -ENOMEM;
2952 goto err;
2953 }
2954 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302955 if (conn_param->ird < ep->ord) {
2956 if (RELAXED_IRD_NEGOTIATION &&
2957 ep->ord <= h->rdev.lldi.max_ordird_qp) {
2958 conn_param->ird = ep->ord;
2959 } else {
2960 abort_connection(ep, NULL, GFP_KERNEL);
2961 err = -ENOMEM;
2962 goto err;
2963 }
2964 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302965 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002966 ep->ird = conn_param->ird;
2967 ep->ord = conn_param->ord;
2968
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302969 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302970 if (peer2peer && ep->ird == 0)
2971 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302972 } else {
2973 if (peer2peer &&
2974 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05302975 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302976 ep->ird = 1;
2977 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002978
2979 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2980
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302981 cm_id->add_ref(cm_id);
2982 ep->com.cm_id = cm_id;
2983 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00002984 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302985
Steve Wisecfdda9d2010-04-21 15:30:06 -07002986 /* bind QP to EP and move to RTS */
2987 attrs.mpa_attr = ep->mpa_attr;
2988 attrs.max_ird = ep->ird;
2989 attrs.max_ord = ep->ord;
2990 attrs.llp_stream_handle = ep;
2991 attrs.next_state = C4IW_QP_STATE_RTS;
2992
2993 /* bind QP and TID with INIT_WR */
2994 mask = C4IW_QP_ATTR_NEXT_STATE |
2995 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2996 C4IW_QP_ATTR_MPA_ATTR |
2997 C4IW_QP_ATTR_MAX_IRD |
2998 C4IW_QP_ATTR_MAX_ORD;
2999
3000 err = c4iw_modify_qp(ep->com.qp->rhp,
3001 ep->com.qp, mask, &attrs, 1);
3002 if (err)
3003 goto err1;
3004 err = send_mpa_reply(ep, conn_param->private_data,
3005 conn_param->private_data_len);
3006 if (err)
3007 goto err1;
3008
Steve Wisea7db89e2014-03-21 20:40:35 +05303009 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003010 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303011 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003012 c4iw_put_ep(&ep->com);
3013 return 0;
3014err1:
3015 ep->com.cm_id = NULL;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303016 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003017 cm_id->rem_ref(cm_id);
3018err:
Steve Wisea7db89e2014-03-21 20:40:35 +05303019 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003020 c4iw_put_ep(&ep->com);
3021 return err;
3022}
3023
Vipul Pandya830662f2013-07-04 16:10:47 +05303024static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3025{
3026 struct in_device *ind;
3027 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003028 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3029 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303030
3031 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3032 if (!ind)
3033 return -EADDRNOTAVAIL;
3034 for_primary_ifa(ind) {
3035 laddr->sin_addr.s_addr = ifa->ifa_address;
3036 raddr->sin_addr.s_addr = ifa->ifa_address;
3037 found = 1;
3038 break;
3039 }
3040 endfor_ifa(ind);
3041 in_dev_put(ind);
3042 return found ? 0 : -EADDRNOTAVAIL;
3043}
3044
3045static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3046 unsigned char banned_flags)
3047{
3048 struct inet6_dev *idev;
3049 int err = -EADDRNOTAVAIL;
3050
3051 rcu_read_lock();
3052 idev = __in6_dev_get(dev);
3053 if (idev != NULL) {
3054 struct inet6_ifaddr *ifp;
3055
3056 read_lock_bh(&idev->lock);
3057 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3058 if (ifp->scope == IFA_LINK &&
3059 !(ifp->flags & banned_flags)) {
3060 memcpy(addr, &ifp->addr, 16);
3061 err = 0;
3062 break;
3063 }
3064 }
3065 read_unlock_bh(&idev->lock);
3066 }
3067 rcu_read_unlock();
3068 return err;
3069}
3070
3071static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3072{
3073 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003074 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3075 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303076
Nicholas Krause54b9a962015-08-26 23:00:59 -04003077 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303078 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3079 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3080 return 0;
3081 }
3082 return -EADDRNOTAVAIL;
3083}
3084
Steve Wisecfdda9d2010-04-21 15:30:06 -07003085int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3086{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003087 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3088 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003089 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003090 struct sockaddr_in *laddr;
3091 struct sockaddr_in *raddr;
3092 struct sockaddr_in6 *laddr6;
3093 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303094 __u8 *ra;
3095 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003096
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303097 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3098 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003099 err = -EINVAL;
3100 goto out;
3101 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003102 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3103 if (!ep) {
3104 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3105 err = -ENOMEM;
3106 goto out;
3107 }
3108 init_timer(&ep->timer);
3109 ep->plen = conn_param->private_data_len;
3110 if (ep->plen)
3111 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3112 conn_param->private_data, ep->plen);
3113 ep->ird = conn_param->ird;
3114 ep->ord = conn_param->ord;
3115
3116 if (peer2peer && ep->ord == 0)
3117 ep->ord = 1;
3118
3119 cm_id->add_ref(cm_id);
3120 ep->com.dev = dev;
3121 ep->com.cm_id = cm_id;
3122 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303123 if (!ep->com.qp) {
3124 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3125 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003126 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303127 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003128 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003129 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3130 ep->com.qp, cm_id);
3131
3132 /*
3133 * Allocate an active TID to initiate a TCP connection.
3134 */
3135 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3136 if (ep->atid == -1) {
3137 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3138 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003139 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003140 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003141 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003142
Steve Wise170003c2016-02-26 09:18:03 -06003143 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003144 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003145 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003146 sizeof(ep->com.remote_addr));
3147
Steve Wise170003c2016-02-26 09:18:03 -06003148 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3149 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3150 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3151 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003152
Steve Wise170003c2016-02-26 09:18:03 -06003153 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303154 iptype = 4;
3155 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003156
Vipul Pandya830662f2013-07-04 16:10:47 +05303157 /*
3158 * Handle loopback requests to INADDR_ANY.
3159 */
3160 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3161 err = pick_local_ipaddrs(dev, cm_id);
3162 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003163 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303164 }
3165
3166 /* find a route */
3167 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3168 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3169 ra, ntohs(raddr->sin_port));
3170 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3171 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303172 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303173 } else {
3174 iptype = 6;
3175 ra = (__u8 *)&raddr6->sin6_addr;
3176
3177 /*
3178 * Handle loopback requests to INADDR_ANY.
3179 */
3180 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3181 err = pick_local_ip6addrs(dev, cm_id);
3182 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003183 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303184 }
3185
3186 /* find a route */
3187 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3188 __func__, laddr6->sin6_addr.s6_addr,
3189 ntohs(laddr6->sin6_port),
3190 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3191 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3192 raddr6->sin6_addr.s6_addr,
3193 laddr6->sin6_port, raddr6->sin6_port, 0,
3194 raddr6->sin6_scope_id);
3195 }
3196 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003197 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3198 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003199 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003200 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003201
Hariprasad S963cab52015-09-23 17:19:27 +05303202 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303203 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003204 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003205 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003206 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003207 }
3208
3209 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3210 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3211 ep->l2t->idx);
3212
3213 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303214 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003215
3216 /* send connect request to rnic */
3217 err = send_connect(ep);
3218 if (!err)
3219 goto out;
3220
3221 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003222fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003223 dst_release(ep->dst);
3224fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003225 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003226 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003227fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003228 cm_id->rem_ref(cm_id);
3229 c4iw_put_ep(&ep->com);
3230out:
3231 return err;
3232}
3233
Vipul Pandya830662f2013-07-04 16:10:47 +05303234static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3235{
3236 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003237 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003238 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303239
Hariprasad S28de1f72016-01-13 10:03:14 +05303240 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3241 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3242 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3243 if (err)
3244 return err;
3245 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303246 c4iw_init_wr_wait(&ep->com.wr_wait);
3247 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3248 ep->stid, &sin6->sin6_addr,
3249 sin6->sin6_port,
3250 ep->com.dev->rdev.lldi.rxq_ids[0]);
3251 if (!err)
3252 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3253 &ep->com.wr_wait,
3254 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303255 else if (err > 0)
3256 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303257 if (err) {
3258 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3259 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303260 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3261 err, ep->stid,
3262 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303263 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303264 return err;
3265}
3266
3267static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3268{
3269 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003270 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003271 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303272
3273 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3274 do {
3275 err = cxgb4_create_server_filter(
3276 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3277 sin->sin_addr.s_addr, sin->sin_port, 0,
3278 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3279 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303280 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3281 err = -EIO;
3282 break;
3283 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303284 set_current_state(TASK_UNINTERRUPTIBLE);
3285 schedule_timeout(usecs_to_jiffies(100));
3286 }
3287 } while (err == -EBUSY);
3288 } else {
3289 c4iw_init_wr_wait(&ep->com.wr_wait);
3290 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3291 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3292 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3293 if (!err)
3294 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3295 &ep->com.wr_wait,
3296 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303297 else if (err > 0)
3298 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303299 }
3300 if (err)
3301 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3302 , err, ep->stid,
3303 &sin->sin_addr, ntohs(sin->sin_port));
3304 return err;
3305}
3306
Steve Wisecfdda9d2010-04-21 15:30:06 -07003307int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3308{
3309 int err = 0;
3310 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3311 struct c4iw_listen_ep *ep;
3312
Steve Wisecfdda9d2010-04-21 15:30:06 -07003313 might_sleep();
3314
3315 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3316 if (!ep) {
3317 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3318 err = -ENOMEM;
3319 goto fail1;
3320 }
3321 PDBG("%s ep %p\n", __func__, ep);
3322 cm_id->add_ref(cm_id);
3323 ep->com.cm_id = cm_id;
3324 ep->com.dev = dev;
3325 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003326 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303327 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003328
3329 /*
3330 * Allocate a server TID.
3331 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303332 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3333 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303334 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003335 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003336 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303337 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003338 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003339
Steve Wisecfdda9d2010-04-21 15:30:06 -07003340 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003341 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003342 err = -ENOMEM;
3343 goto fail2;
3344 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003345 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003346
Steve Wise170003c2016-02-26 09:18:03 -06003347 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3348 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003349
Steve Wisecfdda9d2010-04-21 15:30:06 -07003350 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303351 if (ep->com.local_addr.ss_family == AF_INET)
3352 err = create_server4(dev, ep);
3353 else
3354 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003355 if (!err) {
3356 cm_id->provider_data = ep;
3357 goto out;
3358 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003359
Vipul Pandya830662f2013-07-04 16:10:47 +05303360 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3361 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003362fail2:
3363 cm_id->rem_ref(cm_id);
3364 c4iw_put_ep(&ep->com);
3365fail1:
3366out:
3367 return err;
3368}
3369
3370int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3371{
3372 int err;
3373 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3374
3375 PDBG("%s ep %p\n", __func__, ep);
3376
3377 might_sleep();
3378 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303379 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3380 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003381 err = cxgb4_remove_server_filter(
3382 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3383 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3384 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303385 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003386 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303387 err = cxgb4_remove_server(
3388 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3389 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003390 if (err)
3391 goto done;
3392 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3393 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003394 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303395 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3396 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003397 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003398 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303399 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3400 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003401done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003402 cm_id->rem_ref(cm_id);
3403 c4iw_put_ep(&ep->com);
3404 return err;
3405}
3406
3407int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3408{
3409 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003410 int close = 0;
3411 int fatal = 0;
3412 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003413
Steve Wise2f5b48c2010-09-10 11:15:36 -05003414 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003415
3416 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3417 states[ep->com.state], abrupt);
3418
3419 rdev = &ep->com.dev->rdev;
3420 if (c4iw_fatal_error(rdev)) {
3421 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303422 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003423 ep->com.state = DEAD;
3424 }
3425 switch (ep->com.state) {
3426 case MPA_REQ_WAIT:
3427 case MPA_REQ_SENT:
3428 case MPA_REQ_RCVD:
3429 case MPA_REP_SENT:
3430 case FPDU_MODE:
3431 close = 1;
3432 if (abrupt)
3433 ep->com.state = ABORTING;
3434 else {
3435 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003436 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003437 }
3438 set_bit(CLOSE_SENT, &ep->com.flags);
3439 break;
3440 case CLOSING:
3441 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3442 close = 1;
3443 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003444 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003445 ep->com.state = ABORTING;
3446 } else
3447 ep->com.state = MORIBUND;
3448 }
3449 break;
3450 case MORIBUND:
3451 case ABORTING:
3452 case DEAD:
3453 PDBG("%s ignoring disconnect ep %p state %u\n",
3454 __func__, ep, ep->com.state);
3455 break;
3456 default:
3457 BUG();
3458 break;
3459 }
3460
Steve Wisecfdda9d2010-04-21 15:30:06 -07003461 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003462 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003463 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303464 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003465 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003466 } else {
3467 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003468 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003469 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303470 if (ret) {
3471 if (!abrupt) {
3472 stop_ep_timer(ep);
3473 close_complete_upcall(ep, -EIO);
3474 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003475 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303476 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003477 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003478 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003479 if (fatal)
3480 release_ep_resources(ep);
3481 return ret;
3482}
3483
Vipul Pandya1cab7752012-12-10 09:30:55 +00003484static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3485 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3486{
3487 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003488 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003489
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003490 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3491 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003492 if (!ep)
3493 return;
3494
3495 switch (req->retval) {
3496 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003497 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3498 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3499 send_fw_act_open_req(ep, atid);
3500 return;
3501 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003502 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003503 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3504 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3505 send_fw_act_open_req(ep, atid);
3506 return;
3507 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003508 break;
3509 default:
3510 pr_info("%s unexpected ofld conn wr retval %d\n",
3511 __func__, req->retval);
3512 break;
3513 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003514 pr_err("active ofld_connect_wr failure %d atid %d\n",
3515 req->retval, atid);
3516 mutex_lock(&dev->rdev.stats.lock);
3517 dev->rdev.stats.act_ofld_conn_fails++;
3518 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003519 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003520 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303521 if (ep->com.remote_addr.ss_family == AF_INET6) {
3522 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003523 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303524 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3525 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3526 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003527 remove_handle(dev, &dev->atid_idr, atid);
3528 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3529 dst_release(ep->dst);
3530 cxgb4_l2t_release(ep->l2t);
3531 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003532}
3533
3534static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3535 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3536{
3537 struct sk_buff *rpl_skb;
3538 struct cpl_pass_accept_req *cpl;
3539 int ret;
3540
Paul Bolle710a3112013-02-05 20:51:30 +00003541 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003542 BUG_ON(!rpl_skb);
3543 if (req->retval) {
3544 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003545 mutex_lock(&dev->rdev.stats.lock);
3546 dev->rdev.stats.pas_ofld_conn_fails++;
3547 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003548 kfree_skb(rpl_skb);
3549 } else {
3550 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3551 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003552 (__force u32) htonl(
3553 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003554 ret = pass_accept_req(dev, rpl_skb);
3555 if (!ret)
3556 kfree_skb(rpl_skb);
3557 }
3558 return;
3559}
3560
3561static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003562{
3563 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003564 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3565
3566 switch (rpl->type) {
3567 case FW6_TYPE_CQE:
3568 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3569 break;
3570 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3571 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3572 switch (req->t_state) {
3573 case TCP_SYN_SENT:
3574 active_ofld_conn_reply(dev, skb, req);
3575 break;
3576 case TCP_SYN_RECV:
3577 passive_ofld_conn_reply(dev, skb, req);
3578 break;
3579 default:
3580 pr_err("%s unexpected ofld conn wr state %d\n",
3581 __func__, req->t_state);
3582 break;
3583 }
3584 break;
3585 }
3586 return 0;
3587}
3588
3589static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3590{
Hariprasad S963cab52015-09-23 17:19:27 +05303591 __be32 l2info;
3592 __be16 hdr_len, vlantag, len;
3593 u16 eth_hdr_len;
3594 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003595 u8 intf;
3596 struct cpl_rx_pkt *cpl = cplhdr(skb);
3597 struct cpl_pass_accept_req *req;
3598 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003599 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303600 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003601
Vipul Pandyaf079af72013-03-14 05:08:58 +00003602 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003603 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303604 vlantag = cpl->vlan;
3605 len = cpl->len;
3606 l2info = cpl->l2info;
3607 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003608 intf = cpl->iff;
3609
3610 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3611
3612 /*
3613 * We need to parse the TCP options from SYN packet.
3614 * to generate cpl_pass_accept_req.
3615 */
3616 memset(&tmp_opt, 0, sizeof(tmp_opt));
3617 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003618 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003619
3620 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3621 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303622 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3623 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303624 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303625 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303626 type = dev->rdev.lldi.adapter_type;
3627 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3628 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3629 req->hdr_len =
3630 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3631 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3632 eth_hdr_len = is_t4(type) ?
3633 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3634 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3635 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3636 IP_HDR_LEN_V(ip_hdr_len) |
3637 ETH_HDR_LEN_V(eth_hdr_len));
3638 } else { /* T6 and later */
3639 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3640 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3641 T6_IP_HDR_LEN_V(ip_hdr_len) |
3642 T6_ETH_HDR_LEN_V(eth_hdr_len));
3643 }
3644 req->vlan = vlantag;
3645 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003646 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3647 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003648 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3649 if (tmp_opt.wscale_ok)
3650 req->tcpopt.wsf = tmp_opt.snd_wscale;
3651 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3652 if (tmp_opt.sack_ok)
3653 req->tcpopt.sack = 1;
3654 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3655 return;
3656}
3657
3658static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3659 __be32 laddr, __be16 lport,
3660 __be32 raddr, __be16 rport,
3661 u32 rcv_isn, u32 filter, u16 window,
3662 u32 rss_qid, u8 port_id)
3663{
3664 struct sk_buff *req_skb;
3665 struct fw_ofld_connection_wr *req;
3666 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303667 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003668
3669 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3670 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3671 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003672 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303673 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303674 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003675 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003676 req->le.lport = lport;
3677 req->le.pport = rport;
3678 req->le.u.ipv4.lip = laddr;
3679 req->le.u.ipv4.pip = raddr;
3680 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3681 req->tcb.rcv_adv = htons(window);
3682 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303683 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3684 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3685 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003686 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003687
3688 /*
3689 * We store the qid in opt2 which will be used by the firmware
3690 * to send us the wr response.
3691 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003692 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003693
3694 /*
3695 * We initialize the MSS index in TCB to 0xF.
3696 * So that when driver sends cpl_pass_accept_rpl
3697 * TCB picks up the correct value. If this was 0
3698 * TP will ignore any value > 0 for MSS index.
3699 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003700 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303701 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003702
3703 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303704 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3705 if (ret < 0) {
3706 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3707 ret);
3708 kfree_skb(skb);
3709 kfree_skb(req_skb);
3710 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003711}
3712
3713/*
3714 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3715 * messages when a filter is being used instead of server to
3716 * redirect a syn packet. When packets hit filter they are redirected
3717 * to the offload queue and driver tries to establish the connection
3718 * using firmware work request.
3719 */
3720static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3721{
3722 int stid;
3723 unsigned int filter;
3724 struct ethhdr *eh = NULL;
3725 struct vlan_ethhdr *vlan_eh = NULL;
3726 struct iphdr *iph;
3727 struct tcphdr *tcph;
3728 struct rss_header *rss = (void *)skb->data;
3729 struct cpl_rx_pkt *cpl = (void *)skb->data;
3730 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3731 struct l2t_entry *e;
3732 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003733 struct c4iw_ep *lep;
3734 u16 window;
3735 struct port_info *pi;
3736 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003737 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003738 int step;
3739 u32 tx_chan;
3740 struct neighbour *neigh;
3741
3742 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003743 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003744 goto reject;
3745
3746 /*
3747 * Drop all packets which did not hit the filter.
3748 * Unlikely to happen.
3749 */
3750 if (!(rss->filter_hit && rss->filter_tid))
3751 goto reject;
3752
3753 /*
3754 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3755 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303756 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003757
3758 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3759 if (!lep) {
3760 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3761 goto reject;
3762 }
3763
Hariprasad S963cab52015-09-23 17:19:27 +05303764 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3765 case CHELSIO_T4:
3766 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3767 break;
3768 case CHELSIO_T5:
3769 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3770 break;
3771 case CHELSIO_T6:
3772 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3773 break;
3774 default:
3775 pr_err("T%d Chip is not supported\n",
3776 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3777 goto reject;
3778 }
3779
Vipul Pandyaf079af72013-03-14 05:08:58 +00003780 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003781 eh = (struct ethhdr *)(req + 1);
3782 iph = (struct iphdr *)(eh + 1);
3783 } else {
3784 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3785 iph = (struct iphdr *)(vlan_eh + 1);
3786 skb->vlan_tci = ntohs(cpl->vlan);
3787 }
3788
3789 if (iph->version != 0x4)
3790 goto reject;
3791
3792 tcph = (struct tcphdr *)(iph + 1);
3793 skb_set_network_header(skb, (void *)iph - (void *)rss);
3794 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3795 skb_get(skb);
3796
3797 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3798 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3799 ntohs(tcph->source), iph->tos);
3800
Vipul Pandya830662f2013-07-04 16:10:47 +05303801 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3802 iph->tos);
3803 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003804 pr_err("%s - failed to find dst entry!\n",
3805 __func__);
3806 goto reject;
3807 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003808 neigh = dst_neigh_lookup_skb(dst, skb);
3809
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003810 if (!neigh) {
3811 pr_err("%s - failed to allocate neigh!\n",
3812 __func__);
3813 goto free_dst;
3814 }
3815
Vipul Pandya1cab7752012-12-10 09:30:55 +00003816 if (neigh->dev->flags & IFF_LOOPBACK) {
3817 pdev = ip_dev_find(&init_net, iph->daddr);
3818 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3819 pdev, 0);
3820 pi = (struct port_info *)netdev_priv(pdev);
3821 tx_chan = cxgb4_port_chan(pdev);
3822 dev_put(pdev);
3823 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303824 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003825 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303826 pdev, 0);
3827 pi = (struct port_info *)netdev_priv(pdev);
3828 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003829 }
Steve Wiseebf00062014-03-19 17:44:40 +05303830 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003831 if (!e) {
3832 pr_err("%s - failed to allocate l2t entry!\n",
3833 __func__);
3834 goto free_dst;
3835 }
3836
3837 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3838 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003839 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003840
3841 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303842 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3843 dev->rdev.lldi.ports[0],
3844 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003845
3846 /*
3847 * Synthesize the cpl_pass_accept_req. We have everything except the
3848 * TID. Once firmware sends a reply with TID we update the TID field
3849 * in cpl and pass it through the regular cpl_pass_accept_req path.
3850 */
3851 build_cpl_pass_accept_req(skb, stid, iph->tos);
3852 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3853 tcph->source, ntohl(tcph->seq), filter, window,
3854 rss_qid, pi->port_id);
3855 cxgb4_l2t_release(e);
3856free_dst:
3857 dst_release(dst);
3858reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003859 return 0;
3860}
3861
Steve Wisecfdda9d2010-04-21 15:30:06 -07003862/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003863 * These are the real handlers that are called from a
3864 * work queue.
3865 */
Hariprasad S9dec9002016-05-05 01:27:29 +05303866static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003867 [CPL_ACT_ESTABLISH] = act_establish,
3868 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3869 [CPL_RX_DATA] = rx_data,
3870 [CPL_ABORT_RPL_RSS] = abort_rpl,
3871 [CPL_ABORT_RPL] = abort_rpl,
3872 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3873 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3874 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3875 [CPL_PASS_ESTABLISH] = pass_establish,
3876 [CPL_PEER_CLOSE] = peer_close,
3877 [CPL_ABORT_REQ_RSS] = peer_abort,
3878 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3879 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003880 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003881 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05303882 [CPL_RX_PKT] = rx_pkt,
3883 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003884};
3885
3886static void process_timeout(struct c4iw_ep *ep)
3887{
3888 struct c4iw_qp_attributes attrs;
3889 int abort = 1;
3890
Steve Wise2f5b48c2010-09-10 11:15:36 -05003891 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003892 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3893 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003894 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003895 switch (ep->com.state) {
3896 case MPA_REQ_SENT:
3897 __state_set(&ep->com, ABORTING);
3898 connect_reply_upcall(ep, -ETIMEDOUT);
3899 break;
3900 case MPA_REQ_WAIT:
3901 __state_set(&ep->com, ABORTING);
3902 break;
3903 case CLOSING:
3904 case MORIBUND:
3905 if (ep->com.cm_id && ep->com.qp) {
3906 attrs.next_state = C4IW_QP_STATE_ERROR;
3907 c4iw_modify_qp(ep->com.qp->rhp,
3908 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3909 &attrs, 1);
3910 }
3911 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303912 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003913 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003914 case ABORTING:
3915 case DEAD:
3916
3917 /*
3918 * These states are expected if the ep timed out at the same
3919 * time as another thread was calling stop_ep_timer().
3920 * So we silently do nothing for these states.
3921 */
3922 abort = 0;
3923 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003924 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003925 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003926 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003927 abort = 0;
3928 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003929 if (abort)
3930 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecc18b932014-04-24 14:31:53 -05003931 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003932 c4iw_put_ep(&ep->com);
3933}
3934
3935static void process_timedout_eps(void)
3936{
3937 struct c4iw_ep *ep;
3938
3939 spin_lock_irq(&timeout_lock);
3940 while (!list_empty(&timeout_list)) {
3941 struct list_head *tmp;
3942
3943 tmp = timeout_list.next;
3944 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003945 tmp->next = NULL;
3946 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003947 spin_unlock_irq(&timeout_lock);
3948 ep = list_entry(tmp, struct c4iw_ep, entry);
3949 process_timeout(ep);
3950 spin_lock_irq(&timeout_lock);
3951 }
3952 spin_unlock_irq(&timeout_lock);
3953}
3954
3955static void process_work(struct work_struct *work)
3956{
3957 struct sk_buff *skb = NULL;
3958 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003959 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003960 unsigned int opcode;
3961 int ret;
3962
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003963 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003964 while ((skb = skb_dequeue(&rxq))) {
3965 rpl = cplhdr(skb);
3966 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3967 opcode = rpl->ot.opcode;
3968
3969 BUG_ON(!work_handlers[opcode]);
3970 ret = work_handlers[opcode](dev, skb);
3971 if (!ret)
3972 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003973 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003974 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003975}
3976
3977static DECLARE_WORK(skb_work, process_work);
3978
3979static void ep_timeout(unsigned long arg)
3980{
3981 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003982 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003983
3984 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003985 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003986 /*
3987 * Only insert if it is not already on the list.
3988 */
3989 if (!ep->entry.next) {
3990 list_add_tail(&ep->entry, &timeout_list);
3991 kickit = 1;
3992 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003993 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003994 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003995 if (kickit)
3996 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003997}
3998
3999/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004000 * All the CM events are handled on a work queue to have a safe context.
4001 */
4002static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4003{
4004
4005 /*
4006 * Save dev in the skb->cb area.
4007 */
4008 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4009
4010 /*
4011 * Queue the skb and schedule the worker thread.
4012 */
4013 skb_queue_tail(&rxq, skb);
4014 queue_work(workq, &skb_work);
4015 return 0;
4016}
4017
4018static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4019{
4020 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4021
4022 if (rpl->status != CPL_ERR_NONE) {
4023 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4024 "for tid %u\n", rpl->status, GET_TID(rpl));
4025 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004026 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004027 return 0;
4028}
4029
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004030static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4031{
4032 struct cpl_fw6_msg *rpl = cplhdr(skb);
4033 struct c4iw_wr_wait *wr_waitp;
4034 int ret;
4035
4036 PDBG("%s type %u\n", __func__, rpl->type);
4037
4038 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004039 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004040 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004041 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004042 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004043 if (wr_waitp)
4044 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004045 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004046 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004047 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004048 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004049 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004050 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004051 default:
4052 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4053 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004054 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004055 break;
4056 }
4057 return 0;
4058}
4059
Steve Wise8da7e7a2011-06-14 20:59:27 +00004060static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4061{
4062 struct cpl_abort_req_rss *req = cplhdr(skb);
4063 struct c4iw_ep *ep;
4064 struct tid_info *t = dev->rdev.lldi.tids;
4065 unsigned int tid = GET_TID(req);
4066
4067 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05004068 if (!ep) {
4069 printk(KERN_WARNING MOD
4070 "Abort on non-existent endpoint, tid %d\n", tid);
4071 kfree_skb(skb);
4072 return 0;
4073 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304074 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304075 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4076 __func__, ep->hwtid, req->status,
4077 neg_adv_str(req->status));
4078 ep->stats.abort_neg_adv++;
4079 dev->rdev.stats.neg_adv++;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004080 kfree_skb(skb);
4081 return 0;
4082 }
4083 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4084 ep->com.state);
4085
4086 /*
4087 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004088 * However, if we are on MPAv2 and want to retry with MPAv1
4089 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004090 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004091 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4092 if (ep->com.state != MPA_REQ_SENT)
4093 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4094 } else
4095 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00004096 sched(dev, skb);
4097 return 0;
4098}
4099
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004100/*
4101 * Most upcalls from the T4 Core go to sched() to
4102 * schedule the processing on a work queue.
4103 */
4104c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4105 [CPL_ACT_ESTABLISH] = sched,
4106 [CPL_ACT_OPEN_RPL] = sched,
4107 [CPL_RX_DATA] = sched,
4108 [CPL_ABORT_RPL_RSS] = sched,
4109 [CPL_ABORT_RPL] = sched,
4110 [CPL_PASS_OPEN_RPL] = sched,
4111 [CPL_CLOSE_LISTSRV_RPL] = sched,
4112 [CPL_PASS_ACCEPT_REQ] = sched,
4113 [CPL_PASS_ESTABLISH] = sched,
4114 [CPL_PEER_CLOSE] = sched,
4115 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004116 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004117 [CPL_RDMA_TERMINATE] = sched,
4118 [CPL_FW4_ACK] = sched,
4119 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004120 [CPL_FW6_MSG] = fw6_msg,
4121 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004122};
4123
Steve Wisecfdda9d2010-04-21 15:30:06 -07004124int __init c4iw_cm_init(void)
4125{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004126 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004127 skb_queue_head_init(&rxq);
4128
4129 workq = create_singlethread_workqueue("iw_cxgb4");
4130 if (!workq)
4131 return -ENOMEM;
4132
Steve Wisecfdda9d2010-04-21 15:30:06 -07004133 return 0;
4134}
4135
Steve Wise46c13762014-06-20 14:26:25 -05004136void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004137{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004138 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004139 flush_workqueue(workq);
4140 destroy_workqueue(workq);
4141}