blob: d7f7ab34eeba1800a28d4eef8e7199bfbb3b885e [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
Hariprasad Sfef44222016-05-05 01:27:33 +0530522static int send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700523{
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);
Hariprasad Sfef44222016-05-05 01:27:33 +0530578 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700579}
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;
Hariprasad Sfef44222016-05-05 01:27:33 +05301122 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001123
1124 ep = lookup_atid(t, atid);
1125
1126 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1127 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1128
Steve Wisea7db89e2014-03-21 20:40:35 +05301129 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001130 dst_confirm(ep->dst);
1131
1132 /* setup the hwtid for this connection */
1133 ep->hwtid = tid;
1134 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001135 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001136
1137 ep->snd_seq = be32_to_cpu(req->snd_isn);
1138 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1139
1140 set_emss(ep, ntohs(req->tcp_opt));
1141
1142 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001143 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001144 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001145 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001146
1147 /* start MPA negotiation */
Hariprasad Sfef44222016-05-05 01:27:33 +05301148 ret = send_flowc(ep, NULL);
1149 if (ret)
1150 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301151 if (ep->retry_with_mpa_v1)
1152 send_mpa_req(ep, skb, 1);
1153 else
1154 send_mpa_req(ep, skb, mpa_rev);
Steve Wisea7db89e2014-03-21 20:40:35 +05301155 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001156 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301157err:
1158 mutex_unlock(&ep->com.mutex);
1159 connect_reply_upcall(ep, -ENOMEM);
1160 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1161 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001162}
1163
Steve Wisebe13b2d2014-03-21 20:40:33 +05301164static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001165{
1166 struct iw_cm_event event;
1167
1168 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1169 memset(&event, 0, sizeof(event));
1170 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301171 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001172 if (ep->com.cm_id) {
1173 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1174 ep, ep->com.cm_id, ep->hwtid);
1175 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1176 ep->com.cm_id->rem_ref(ep->com.cm_id);
1177 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001178 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001179 }
1180}
1181
Steve Wisecfdda9d2010-04-21 15:30:06 -07001182static void peer_close_upcall(struct c4iw_ep *ep)
1183{
1184 struct iw_cm_event event;
1185
1186 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1187 memset(&event, 0, sizeof(event));
1188 event.event = IW_CM_EVENT_DISCONNECT;
1189 if (ep->com.cm_id) {
1190 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1191 ep, ep->com.cm_id, ep->hwtid);
1192 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001193 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001194 }
1195}
1196
1197static void peer_abort_upcall(struct c4iw_ep *ep)
1198{
1199 struct iw_cm_event event;
1200
1201 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1202 memset(&event, 0, sizeof(event));
1203 event.event = IW_CM_EVENT_CLOSE;
1204 event.status = -ECONNRESET;
1205 if (ep->com.cm_id) {
1206 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1207 ep->com.cm_id, ep->hwtid);
1208 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1209 ep->com.cm_id->rem_ref(ep->com.cm_id);
1210 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001211 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001212 }
1213}
1214
1215static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1216{
1217 struct iw_cm_event event;
1218
1219 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1220 memset(&event, 0, sizeof(event));
1221 event.event = IW_CM_EVENT_CONNECT_REPLY;
1222 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301223 memcpy(&event.local_addr, &ep->com.local_addr,
1224 sizeof(ep->com.local_addr));
1225 memcpy(&event.remote_addr, &ep->com.remote_addr,
1226 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001227
1228 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301229 if (!ep->tried_with_mpa_v1) {
1230 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301231 event.ord = ep->ird;
1232 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301233 event.private_data_len = ep->plen -
1234 sizeof(struct mpa_v2_conn_params);
1235 event.private_data = ep->mpa_pkt +
1236 sizeof(struct mpa_message) +
1237 sizeof(struct mpa_v2_conn_params);
1238 } else {
1239 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301240 event.ord = cur_max_read_depth(ep->com.dev);
1241 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301242 event.private_data_len = ep->plen;
1243 event.private_data = ep->mpa_pkt +
1244 sizeof(struct mpa_message);
1245 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001246 }
Roland Dreier85963e42010-07-19 13:13:09 -07001247
1248 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1249 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001250 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001251 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1252
Steve Wisecfdda9d2010-04-21 15:30:06 -07001253 if (status < 0) {
1254 ep->com.cm_id->rem_ref(ep->com.cm_id);
1255 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001256 }
1257}
1258
Steve Wisebe13b2d2014-03-21 20:40:33 +05301259static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001260{
1261 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301262 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001263
1264 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1265 memset(&event, 0, sizeof(event));
1266 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301267 memcpy(&event.local_addr, &ep->com.local_addr,
1268 sizeof(ep->com.local_addr));
1269 memcpy(&event.remote_addr, &ep->com.remote_addr,
1270 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001271 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301272 if (!ep->tried_with_mpa_v1) {
1273 /* this means MPA_v2 is used */
1274 event.ord = ep->ord;
1275 event.ird = ep->ird;
1276 event.private_data_len = ep->plen -
1277 sizeof(struct mpa_v2_conn_params);
1278 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1279 sizeof(struct mpa_v2_conn_params);
1280 } else {
1281 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301282 event.ord = cur_max_read_depth(ep->com.dev);
1283 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301284 event.private_data_len = ep->plen;
1285 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1286 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301287 c4iw_get_ep(&ep->com);
1288 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1289 &event);
1290 if (ret)
1291 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001292 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001293 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301294 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001295}
1296
1297static void established_upcall(struct c4iw_ep *ep)
1298{
1299 struct iw_cm_event event;
1300
1301 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1302 memset(&event, 0, sizeof(event));
1303 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301304 event.ird = ep->ord;
1305 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001306 if (ep->com.cm_id) {
1307 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1308 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001309 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001310 }
1311}
1312
1313static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1314{
1315 struct cpl_rx_data_ack *req;
1316 struct sk_buff *skb;
1317 int wrlen = roundup(sizeof *req, 16);
1318
1319 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1320 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1321 if (!skb) {
1322 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1323 return 0;
1324 }
1325
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301326 /*
1327 * If we couldn't specify the entire rcv window at connection setup
1328 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1329 * then add the overage in to the credits returned.
1330 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001331 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1332 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301333
Steve Wisecfdda9d2010-04-21 15:30:06 -07001334 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1335 memset(req, 0, wrlen);
1336 INIT_TP_WR(req, ep->hwtid);
1337 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1338 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001339 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301340 RX_DACK_CHANGE_F |
1341 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001342 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001343 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1344 return credits;
1345}
1346
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301347#define RELAXED_IRD_NEGOTIATION 1
1348
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301349/*
1350 * process_mpa_reply - process streaming mode MPA reply
1351 *
1352 * Returns:
1353 *
1354 * 0 upon success indicating a connect request was delivered to the ULP
1355 * or the mpa request is incomplete but valid so far.
1356 *
1357 * 1 if a failure requires the caller to close the connection.
1358 *
1359 * 2 if a failure requires the caller to abort the connection.
1360 */
Steve Wisecc18b932014-04-24 14:31:53 -05001361static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001362{
1363 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301364 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001365 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301366 u16 resp_ird, resp_ord;
1367 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001368 struct c4iw_qp_attributes attrs;
1369 enum c4iw_qp_attr_mask mask;
1370 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001371 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001372
1373 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1374
1375 /*
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001376 * Stop mpa timer. If it expired, then
1377 * we ignore the MPA reply. process_timeout()
1378 * will abort the connection.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001379 */
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001380 if (stop_ep_timer(ep))
Steve Wisecc18b932014-04-24 14:31:53 -05001381 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001382
1383 /*
1384 * If we get more than the supported amount of private data
1385 * then we must fail this connection.
1386 */
1387 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1388 err = -EINVAL;
1389 goto err;
1390 }
1391
1392 /*
1393 * copy the new data into our accumulation buffer.
1394 */
1395 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1396 skb->len);
1397 ep->mpa_pkt_len += skb->len;
1398
1399 /*
1400 * if we don't even have the mpa message, then bail.
1401 */
1402 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001403 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001404 mpa = (struct mpa_message *) ep->mpa_pkt;
1405
1406 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301407 if (mpa->revision > mpa_rev) {
1408 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1409 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001410 err = -EPROTO;
1411 goto err;
1412 }
1413 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1414 err = -EPROTO;
1415 goto err;
1416 }
1417
1418 plen = ntohs(mpa->private_data_size);
1419
1420 /*
1421 * Fail if there's too much private data.
1422 */
1423 if (plen > MPA_MAX_PRIVATE_DATA) {
1424 err = -EPROTO;
1425 goto err;
1426 }
1427
1428 /*
1429 * If plen does not account for pkt size
1430 */
1431 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1432 err = -EPROTO;
1433 goto err;
1434 }
1435
1436 ep->plen = (u8) plen;
1437
1438 /*
1439 * If we don't have all the pdata yet, then bail.
1440 * We'll continue process when more data arrives.
1441 */
1442 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001443 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001444
1445 if (mpa->flags & MPA_REJECT) {
1446 err = -ECONNREFUSED;
1447 goto err;
1448 }
1449
1450 /*
1451 * If we get here we have accumulated the entire mpa
1452 * start reply message including private data. And
1453 * the MPA header is valid.
1454 */
Steve Wisec529fb52014-03-21 20:40:37 +05301455 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001456 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1457 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1458 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301459 ep->mpa_attr.version = mpa->revision;
1460 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1461
1462 if (mpa->revision == 2) {
1463 ep->mpa_attr.enhanced_rdma_conn =
1464 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1465 if (ep->mpa_attr.enhanced_rdma_conn) {
1466 mpa_v2_params = (struct mpa_v2_conn_params *)
1467 (ep->mpa_pkt + sizeof(*mpa));
1468 resp_ird = ntohs(mpa_v2_params->ird) &
1469 MPA_V2_IRD_ORD_MASK;
1470 resp_ord = ntohs(mpa_v2_params->ord) &
1471 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301472 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1473 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301474
1475 /*
1476 * This is a double-check. Ideally, below checks are
1477 * not required since ird/ord stuff has been taken
1478 * care of in c4iw_accept_cr
1479 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301480 if (ep->ird < resp_ord) {
1481 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1482 ep->com.dev->rdev.lldi.max_ordird_qp)
1483 ep->ird = resp_ord;
1484 else
1485 insuff_ird = 1;
1486 } else if (ep->ird > resp_ord) {
1487 ep->ird = resp_ord;
1488 }
1489 if (ep->ord > resp_ird) {
1490 if (RELAXED_IRD_NEGOTIATION)
1491 ep->ord = resp_ird;
1492 else
1493 insuff_ird = 1;
1494 }
1495 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301496 err = -ENOMEM;
1497 ep->ird = resp_ord;
1498 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301499 }
1500
1501 if (ntohs(mpa_v2_params->ird) &
1502 MPA_V2_PEER2PEER_MODEL) {
1503 if (ntohs(mpa_v2_params->ord) &
1504 MPA_V2_RDMA_WRITE_RTR)
1505 ep->mpa_attr.p2p_type =
1506 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1507 else if (ntohs(mpa_v2_params->ord) &
1508 MPA_V2_RDMA_READ_RTR)
1509 ep->mpa_attr.p2p_type =
1510 FW_RI_INIT_P2PTYPE_READ_REQ;
1511 }
1512 }
1513 } else if (mpa->revision == 1)
1514 if (peer2peer)
1515 ep->mpa_attr.p2p_type = p2p_type;
1516
Steve Wisecfdda9d2010-04-21 15:30:06 -07001517 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301518 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1519 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1520 ep->mpa_attr.recv_marker_enabled,
1521 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1522 ep->mpa_attr.p2p_type, p2p_type);
1523
1524 /*
1525 * If responder's RTR does not match with that of initiator, assign
1526 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1527 * generated when moving QP to RTS state.
1528 * A TERM message will be sent after QP has moved to RTS state
1529 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001530 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301531 (ep->mpa_attr.p2p_type != p2p_type)) {
1532 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1533 rtr_mismatch = 1;
1534 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001535
1536 attrs.mpa_attr = ep->mpa_attr;
1537 attrs.max_ird = ep->ird;
1538 attrs.max_ord = ep->ord;
1539 attrs.llp_stream_handle = ep;
1540 attrs.next_state = C4IW_QP_STATE_RTS;
1541
1542 mask = C4IW_QP_ATTR_NEXT_STATE |
1543 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1544 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1545
1546 /* bind QP and TID with INIT_WR */
1547 err = c4iw_modify_qp(ep->com.qp->rhp,
1548 ep->com.qp, mask, &attrs, 1);
1549 if (err)
1550 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301551
1552 /*
1553 * If responder's RTR requirement did not match with what initiator
1554 * supports, generate TERM message
1555 */
1556 if (rtr_mismatch) {
1557 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1558 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1559 attrs.ecode = MPA_NOMATCH_RTR;
1560 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001561 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301562 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001563 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301564 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001565 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301566 goto out;
1567 }
1568
1569 /*
1570 * Generate TERM if initiator IRD is not sufficient for responder
1571 * provided ORD. Currently, we do the same behaviour even when
1572 * responder provided IRD is also not sufficient as regards to
1573 * initiator ORD.
1574 */
1575 if (insuff_ird) {
1576 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1577 __func__);
1578 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1579 attrs.ecode = MPA_INSUFF_IRD;
1580 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001581 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301582 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001583 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301584 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001585 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301586 goto out;
1587 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001588 goto out;
1589err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301590 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001591out:
1592 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001593 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001594}
1595
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301596/*
1597 * process_mpa_request - process streaming mode MPA request
1598 *
1599 * Returns:
1600 *
1601 * 0 upon success indicating a connect request was delivered to the ULP
1602 * or the mpa request is incomplete but valid so far.
1603 *
1604 * 1 if a failure requires the caller to close the connection.
1605 *
1606 * 2 if a failure requires the caller to abort the connection.
1607 */
1608static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001609{
1610 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301611 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001612 u16 plen;
1613
1614 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1615
Steve Wisecfdda9d2010-04-21 15:30:06 -07001616 /*
1617 * If we get more than the supported amount of private data
1618 * then we must fail this connection.
1619 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301620 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1621 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001622
1623 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1624
1625 /*
1626 * Copy the new data into our accumulation buffer.
1627 */
1628 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1629 skb->len);
1630 ep->mpa_pkt_len += skb->len;
1631
1632 /*
1633 * If we don't even have the mpa message, then bail.
1634 * We'll continue process when more data arrives.
1635 */
1636 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301637 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001638
1639 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001640 mpa = (struct mpa_message *) ep->mpa_pkt;
1641
1642 /*
1643 * Validate MPA Header.
1644 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301645 if (mpa->revision > mpa_rev) {
1646 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1647 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301648 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001649 }
1650
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301651 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1652 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001653
1654 plen = ntohs(mpa->private_data_size);
1655
1656 /*
1657 * Fail if there's too much private data.
1658 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301659 if (plen > MPA_MAX_PRIVATE_DATA)
1660 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001661
1662 /*
1663 * If plen does not account for pkt size
1664 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301665 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1666 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001667 ep->plen = (u8) plen;
1668
1669 /*
1670 * If we don't have all the pdata yet, then bail.
1671 */
1672 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301673 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001674
1675 /*
1676 * If we get here we have accumulated the entire mpa
1677 * start reply message including private data.
1678 */
1679 ep->mpa_attr.initiator = 0;
1680 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1681 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1682 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301683 ep->mpa_attr.version = mpa->revision;
1684 if (mpa->revision == 1)
1685 ep->tried_with_mpa_v1 = 1;
1686 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1687
1688 if (mpa->revision == 2) {
1689 ep->mpa_attr.enhanced_rdma_conn =
1690 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1691 if (ep->mpa_attr.enhanced_rdma_conn) {
1692 mpa_v2_params = (struct mpa_v2_conn_params *)
1693 (ep->mpa_pkt + sizeof(*mpa));
1694 ep->ird = ntohs(mpa_v2_params->ird) &
1695 MPA_V2_IRD_ORD_MASK;
1696 ep->ord = ntohs(mpa_v2_params->ord) &
1697 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301698 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1699 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301700 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1701 if (peer2peer) {
1702 if (ntohs(mpa_v2_params->ord) &
1703 MPA_V2_RDMA_WRITE_RTR)
1704 ep->mpa_attr.p2p_type =
1705 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1706 else if (ntohs(mpa_v2_params->ord) &
1707 MPA_V2_RDMA_READ_RTR)
1708 ep->mpa_attr.p2p_type =
1709 FW_RI_INIT_P2PTYPE_READ_REQ;
1710 }
1711 }
1712 } else if (mpa->revision == 1)
1713 if (peer2peer)
1714 ep->mpa_attr.p2p_type = p2p_type;
1715
Steve Wisecfdda9d2010-04-21 15:30:06 -07001716 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1717 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1718 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1719 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1720 ep->mpa_attr.p2p_type);
1721
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001722 /*
1723 * If the endpoint timer already expired, then we ignore
1724 * the start request. process_timeout() will abort
1725 * the connection.
1726 */
1727 if (!stop_ep_timer(ep)) {
1728 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001729
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001730 /* drive upcall */
Hariprasad Shenai10be6b42014-11-21 09:36:35 -06001731 mutex_lock_nested(&ep->parent_ep->com.mutex,
1732 SINGLE_DEPTH_NESTING);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001733 if (ep->parent_ep->com.state != DEAD) {
1734 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301735 goto err_unlock_parent;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001736 } else {
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301737 goto err_unlock_parent;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001738 }
1739 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301740 }
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301741 return 0;
1742
1743err_unlock_parent:
1744 mutex_unlock(&ep->parent_ep->com.mutex);
1745 goto err_out;
1746err_stop_timer:
1747 (void)stop_ep_timer(ep);
1748err_out:
1749 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001750}
1751
1752static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1753{
1754 struct c4iw_ep *ep;
1755 struct cpl_rx_data *hdr = cplhdr(skb);
1756 unsigned int dlen = ntohs(hdr->len);
1757 unsigned int tid = GET_TID(hdr);
1758 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001759 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001760 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001761
1762 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301763 if (!ep)
1764 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001765 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1766 skb_pull(skb, sizeof(*hdr));
1767 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301768 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001769
Steve Wisecfdda9d2010-04-21 15:30:06 -07001770 /* update RX credits */
1771 update_rx_credits(ep, dlen);
1772
Steve Wisec529fb52014-03-21 20:40:37 +05301773 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001774 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001775 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001776 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001777 break;
1778 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001779 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001780 process_mpa_request(ep, skb);
1781 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001782 case FPDU_MODE: {
1783 struct c4iw_qp_attributes attrs;
1784 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001785 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001786 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001787 " qpid %u ep %p state %d tid %u status %d\n",
1788 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301789 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301790 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001791 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001792 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1793 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001794 break;
1795 }
Vipul Pandya15579672013-01-07 13:11:52 +00001796 default:
1797 break;
1798 }
Steve Wisec529fb52014-03-21 20:40:37 +05301799 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001800 if (disconnect)
1801 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001802 return 0;
1803}
1804
1805static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1806{
1807 struct c4iw_ep *ep;
1808 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001809 int release = 0;
1810 unsigned int tid = GET_TID(rpl);
1811 struct tid_info *t = dev->rdev.lldi.tids;
1812
1813 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301814 if (!ep) {
1815 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1816 return 0;
1817 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001818 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001819 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001820 switch (ep->com.state) {
1821 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001822 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001823 __state_set(&ep->com, DEAD);
1824 release = 1;
1825 break;
1826 default:
1827 printk(KERN_ERR "%s ep %p state %d\n",
1828 __func__, ep, ep->com.state);
1829 break;
1830 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001831 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001832
1833 if (release)
1834 release_ep_resources(ep);
1835 return 0;
1836}
1837
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001838static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1839{
1840 struct sk_buff *skb;
1841 struct fw_ofld_connection_wr *req;
1842 unsigned int mtu_idx;
1843 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301844 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301845 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001846
1847 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1848 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1849 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001850 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301851 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301852 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1853 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001854 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001855 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301856 req->le.lport = sin->sin_port;
1857 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001858 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301859 req->le.pport = sin->sin_port;
1860 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001861 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301862 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1863 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001864 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301865 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001866 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001867 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301868 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301869 enable_tcp_timestamps,
1870 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001871 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301872
1873 /*
1874 * Specify the largest window that will fit in opt0. The
1875 * remainder will be specified in the rx_data_ack.
1876 */
1877 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001878 if (win > RCV_BUFSIZ_M)
1879 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301880
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001881 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1882 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001883 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001884 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001885 WND_SCALE_V(wscale) |
1886 MSS_IDX_V(mtu_idx) |
1887 L2T_IDX_V(ep->l2t->idx) |
1888 TX_CHAN_V(ep->tx_chan) |
1889 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301890 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001891 ULP_MODE_V(ULP_MODE_TCPDDP) |
1892 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001893 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1894 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001895 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001896 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001897 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001898 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001899 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001900 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001901 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001902 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001903 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1904 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1905 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001906 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1907 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001908 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1909}
1910
Steve Wisecfdda9d2010-04-21 15:30:06 -07001911/*
1912 * Return whether a failed active open has allocated a TID
1913 */
1914static inline int act_open_has_tid(int status)
1915{
1916 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1917 status != CPL_ERR_ARP_MISS;
1918}
1919
Steve Wise7a2cea22014-03-14 21:52:07 +05301920/* Returns whether a CPL status conveys negative advice.
1921 */
1922static int is_neg_adv(unsigned int status)
1923{
1924 return status == CPL_ERR_RTX_NEG_ADVICE ||
1925 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1926 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1927}
1928
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301929static char *neg_adv_str(unsigned int status)
1930{
1931 switch (status) {
1932 case CPL_ERR_RTX_NEG_ADVICE:
1933 return "Retransmit timeout";
1934 case CPL_ERR_PERSIST_NEG_ADVICE:
1935 return "Persist timeout";
1936 case CPL_ERR_KEEPALV_NEG_ADVICE:
1937 return "Keepalive timeout";
1938 default:
1939 return "Unknown";
1940 }
1941}
1942
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301943static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1944{
1945 ep->snd_win = snd_win;
1946 ep->rcv_win = rcv_win;
1947 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1948}
1949
Vipul Pandya793dad92012-12-10 09:30:56 +00001950#define ACT_OPEN_RETRY_COUNT 2
1951
Vipul Pandya830662f2013-07-04 16:10:47 +05301952static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1953 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301954 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05301955{
1956 struct neighbour *n;
1957 int err, step;
1958 struct net_device *pdev;
1959
1960 n = dst_neigh_lookup(dst, peer_ip);
1961 if (!n)
1962 return -ENODEV;
1963
1964 rcu_read_lock();
1965 err = -ENOMEM;
1966 if (n->dev->flags & IFF_LOOPBACK) {
1967 if (iptype == 4)
1968 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1969 else if (IS_ENABLED(CONFIG_IPV6))
1970 for_each_netdev(&init_net, pdev) {
1971 if (ipv6_chk_addr(&init_net,
1972 (struct in6_addr *)peer_ip,
1973 pdev, 1))
1974 break;
1975 }
1976 else
1977 pdev = NULL;
1978
1979 if (!pdev) {
1980 err = -ENODEV;
1981 goto out;
1982 }
1983 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301984 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05301985 if (!ep->l2t)
1986 goto out;
1987 ep->mtu = pdev->mtu;
1988 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05301989 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
1990 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301991 step = cdev->rdev.lldi.ntxq /
1992 cdev->rdev.lldi.nchan;
1993 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1994 step = cdev->rdev.lldi.nrxq /
1995 cdev->rdev.lldi.nchan;
1996 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1997 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1998 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301999 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302000 dev_put(pdev);
2001 } else {
2002 pdev = get_real_dev(n->dev);
2003 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2004 n, pdev, 0);
2005 if (!ep->l2t)
2006 goto out;
2007 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002008 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302009 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2010 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302011 step = cdev->rdev.lldi.ntxq /
2012 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002013 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2014 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302015 step = cdev->rdev.lldi.nrxq /
2016 cdev->rdev.lldi.nchan;
2017 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002018 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302019 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302020
2021 if (clear_mpa_v1) {
2022 ep->retry_with_mpa_v1 = 0;
2023 ep->tried_with_mpa_v1 = 0;
2024 }
2025 }
2026 err = 0;
2027out:
2028 rcu_read_unlock();
2029
2030 neigh_release(n);
2031
2032 return err;
2033}
2034
Vipul Pandya793dad92012-12-10 09:30:56 +00002035static int c4iw_reconnect(struct c4iw_ep *ep)
2036{
2037 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302038 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002039 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302040 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002041 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302042 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002043 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302044 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002045 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302046 int iptype;
2047 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002048
2049 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2050 init_timer(&ep->timer);
2051
2052 /*
2053 * Allocate an active TID to initiate a TCP connection.
2054 */
2055 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2056 if (ep->atid == -1) {
2057 pr_err("%s - cannot alloc atid.\n", __func__);
2058 err = -ENOMEM;
2059 goto fail2;
2060 }
2061 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2062
2063 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002064 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302065 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2066 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302067 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302068 iptype = 4;
2069 ra = (__u8 *)&raddr->sin_addr;
2070 } else {
2071 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2072 raddr6->sin6_addr.s6_addr,
2073 laddr6->sin6_port, raddr6->sin6_port, 0,
2074 raddr6->sin6_scope_id);
2075 iptype = 6;
2076 ra = (__u8 *)&raddr6->sin6_addr;
2077 }
2078 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002079 pr_err("%s - cannot find route.\n", __func__);
2080 err = -EHOSTUNREACH;
2081 goto fail3;
2082 }
Hariprasad S963cab52015-09-23 17:19:27 +05302083 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302084 ep->com.dev->rdev.lldi.adapter_type,
2085 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302086 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002087 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002088 goto fail4;
2089 }
2090
2091 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2092 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2093 ep->l2t->idx);
2094
2095 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302096 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002097
2098 /* send connect request to rnic */
2099 err = send_connect(ep);
2100 if (!err)
2101 goto out;
2102
2103 cxgb4_l2t_release(ep->l2t);
2104fail4:
2105 dst_release(ep->dst);
2106fail3:
2107 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2108 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2109fail2:
2110 /*
2111 * remember to send notification to upper layer.
2112 * We are in here so the upper layer is not aware that this is
2113 * re-connect attempt and so, upper layer is still waiting for
2114 * response of 1st connect request.
2115 */
2116 connect_reply_upcall(ep, -ECONNRESET);
2117 c4iw_put_ep(&ep->com);
2118out:
2119 return err;
2120}
2121
Steve Wisecfdda9d2010-04-21 15:30:06 -07002122static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2123{
2124 struct c4iw_ep *ep;
2125 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002126 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2127 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002128 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002129 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302130 struct sockaddr_in *la;
2131 struct sockaddr_in *ra;
2132 struct sockaddr_in6 *la6;
2133 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002134
2135 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002136 la = (struct sockaddr_in *)&ep->com.local_addr;
2137 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2138 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2139 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002140
2141 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2142 status, status2errno(status));
2143
Steve Wise7a2cea22014-03-14 21:52:07 +05302144 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302145 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2146 __func__, atid, status, neg_adv_str(status));
2147 ep->stats.connect_neg_adv++;
2148 mutex_lock(&dev->rdev.stats.lock);
2149 dev->rdev.stats.neg_adv++;
2150 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002151 return 0;
2152 }
2153
Vipul Pandya793dad92012-12-10 09:30:56 +00002154 set_bit(ACT_OPEN_RPL, &ep->com.history);
2155
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302156 /*
2157 * Log interesting failures.
2158 */
2159 switch (status) {
2160 case CPL_ERR_CONN_RESET:
2161 case CPL_ERR_CONN_TIMEDOUT:
2162 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002163 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302164 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002165 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302166 mutex_unlock(&dev->rdev.stats.lock);
2167 if (ep->com.local_addr.ss_family == AF_INET &&
2168 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002169 send_fw_act_open_req(ep,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002170 TID_TID_G(AOPEN_ATID_G(
Vipul Pandya793dad92012-12-10 09:30:56 +00002171 ntohl(rpl->atid_status))));
2172 return 0;
2173 }
2174 break;
2175 case CPL_ERR_CONN_EXIST:
2176 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2177 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302178 if (ep->com.remote_addr.ss_family == AF_INET6) {
2179 struct sockaddr_in6 *sin6 =
2180 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002181 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302182 cxgb4_clip_release(
2183 ep->com.dev->rdev.lldi.ports[0],
2184 (const u32 *)
2185 &sin6->sin6_addr.s6_addr, 1);
2186 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002187 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2188 atid);
2189 cxgb4_free_atid(t, atid);
2190 dst_release(ep->dst);
2191 cxgb4_l2t_release(ep->l2t);
2192 c4iw_reconnect(ep);
2193 return 0;
2194 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002195 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302196 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302197 if (ep->com.local_addr.ss_family == AF_INET) {
2198 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2199 atid, status, status2errno(status),
2200 &la->sin_addr.s_addr, ntohs(la->sin_port),
2201 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2202 } else {
2203 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2204 atid, status, status2errno(status),
2205 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2206 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2207 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302208 break;
2209 }
2210
Steve Wisecfdda9d2010-04-21 15:30:06 -07002211 connect_reply_upcall(ep, status2errno(status));
2212 state_set(&ep->com, DEAD);
2213
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302214 if (ep->com.remote_addr.ss_family == AF_INET6) {
2215 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002216 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302217 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2218 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2219 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002220 if (status && act_open_has_tid(status))
2221 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2222
Vipul Pandya793dad92012-12-10 09:30:56 +00002223 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002224 cxgb4_free_atid(t, atid);
2225 dst_release(ep->dst);
2226 cxgb4_l2t_release(ep->l2t);
2227 c4iw_put_ep(&ep->com);
2228
2229 return 0;
2230}
2231
2232static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2233{
2234 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2235 struct tid_info *t = dev->rdev.lldi.tids;
2236 unsigned int stid = GET_TID(rpl);
2237 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2238
2239 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002240 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2241 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002242 }
2243 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2244 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002245 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002246
Vipul Pandya1cab7752012-12-10 09:30:55 +00002247out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002248 return 0;
2249}
2250
Steve Wisecfdda9d2010-04-21 15:30:06 -07002251static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2252{
2253 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2254 struct tid_info *t = dev->rdev.lldi.tids;
2255 unsigned int stid = GET_TID(rpl);
2256 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2257
2258 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002259 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002260 return 0;
2261}
2262
Hariprasad S9dec9002016-05-05 01:27:29 +05302263static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2264 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002265{
2266 struct cpl_pass_accept_rpl *rpl;
2267 unsigned int mtu_idx;
2268 u64 opt0;
2269 u32 opt2;
2270 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302271 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302272 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302273 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002274
2275 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2276 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302277
Steve Wisecfdda9d2010-04-21 15:30:06 -07002278 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302279 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302280 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302281 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2282 rpl5 = (void *)rpl;
2283 INIT_TP_WR(rpl5, ep->hwtid);
2284 } else {
2285 skb_trim(skb, sizeof(*rpl));
2286 INIT_TP_WR(rpl, ep->hwtid);
2287 }
2288 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2289 ep->hwtid));
2290
2291 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302292 enable_tcp_timestamps && req->tcpopt.tstamp,
2293 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002294 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302295
2296 /*
2297 * Specify the largest window that will fit in opt0. The
2298 * remainder will be specified in the rx_data_ack.
2299 */
2300 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002301 if (win > RCV_BUFSIZ_M)
2302 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002303 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002304 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002305 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002306 WND_SCALE_V(wscale) |
2307 MSS_IDX_V(mtu_idx) |
2308 L2T_IDX_V(ep->l2t->idx) |
2309 TX_CHAN_V(ep->tx_chan) |
2310 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002311 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002312 ULP_MODE_V(ULP_MODE_TCPDDP) |
2313 RCV_BUFSIZ_V(win);
2314 opt2 = RX_CHANNEL_V(0) |
2315 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002316
2317 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002318 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002319 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002320 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002321 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002322 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002323 if (enable_ecn) {
2324 const struct tcphdr *tcph;
2325 u32 hlen = ntohl(req->hdr_len);
2326
Hariprasad S963cab52015-09-23 17:19:27 +05302327 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2328 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2329 IP_HDR_LEN_G(hlen);
2330 else
2331 tcph = (const void *)(req + 1) +
2332 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002333 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002334 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002335 }
Hariprasad S963cab52015-09-23 17:19:27 +05302336 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302337 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002338 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302339 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302340 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302341 rpl5 = (void *)rpl;
2342 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2343 if (peer2peer)
2344 isn += 4;
2345 rpl5->iss = cpu_to_be32(isn);
2346 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002347 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002348
Steve Wisecfdda9d2010-04-21 15:30:06 -07002349 rpl->opt0 = cpu_to_be64(opt0);
2350 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002351 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302352 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002353
Hariprasad S9dec9002016-05-05 01:27:29 +05302354 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002355}
2356
Vipul Pandya830662f2013-07-04 16:10:47 +05302357static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002358{
Vipul Pandya830662f2013-07-04 16:10:47 +05302359 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002360 BUG_ON(skb_cloned(skb));
2361 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002362 release_tid(&dev->rdev, hwtid, skb);
2363 return;
2364}
2365
Hariprasad S963cab52015-09-23 17:19:27 +05302366static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2367 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002368 __be16 *local_port, __be16 *peer_port)
2369{
Hariprasad S963cab52015-09-23 17:19:27 +05302370 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2371 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2372 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2373 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2374 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2375 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002376 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302377 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002378 struct tcphdr *tcp = (struct tcphdr *)
2379 ((u8 *)(req + 1) + eth_len + ip_len);
2380
Vipul Pandya830662f2013-07-04 16:10:47 +05302381 if (ip->version == 4) {
2382 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2383 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2384 ntohs(tcp->dest));
2385 *iptype = 4;
2386 memcpy(peer_ip, &ip->saddr, 4);
2387 memcpy(local_ip, &ip->daddr, 4);
2388 } else {
2389 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2390 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2391 ntohs(tcp->dest));
2392 *iptype = 6;
2393 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2394 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2395 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002396 *peer_port = tcp->source;
2397 *local_port = tcp->dest;
2398
2399 return;
2400}
2401
2402static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2403{
Vipul Pandya793dad92012-12-10 09:30:56 +00002404 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002405 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002406 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002407 struct tid_info *t = dev->rdev.lldi.tids;
2408 unsigned int hwtid = GET_TID(req);
2409 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302410 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002411 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302412 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002413 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002414 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302415 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302416 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302417 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002418
2419 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002420 if (!parent_ep) {
2421 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2422 goto reject;
2423 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002424
Steve Wisecfdda9d2010-04-21 15:30:06 -07002425 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302426 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002427 goto reject;
2428 }
2429
Hariprasad S963cab52015-09-23 17:19:27 +05302430 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2431 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302432
Steve Wisecfdda9d2010-04-21 15:30:06 -07002433 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302434 if (iptype == 4) {
2435 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2436 , __func__, parent_ep, hwtid,
2437 local_ip, peer_ip, ntohs(local_port),
2438 ntohs(peer_port), peer_mss);
2439 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2440 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302441 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302442 } else {
2443 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2444 , __func__, parent_ep, hwtid,
2445 local_ip, peer_ip, ntohs(local_port),
2446 ntohs(peer_port), peer_mss);
2447 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002448 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302449 ((struct sockaddr_in6 *)
2450 &parent_ep->com.local_addr)->sin6_scope_id);
2451 }
2452 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002453 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2454 __func__);
2455 goto reject;
2456 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002457
2458 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2459 if (!child_ep) {
2460 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2461 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002462 dst_release(dst);
2463 goto reject;
2464 }
David Miller3786cf12011-12-02 16:52:31 +00002465
Hariprasad S963cab52015-09-23 17:19:27 +05302466 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302467 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002468 if (err) {
2469 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2470 __func__);
2471 dst_release(dst);
2472 kfree(child_ep);
2473 goto reject;
2474 }
2475
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302476 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2477 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2478 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2479 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002480
Steve Wisecfdda9d2010-04-21 15:30:06 -07002481 state_set(&child_ep->com, CONNECTING);
2482 child_ep->com.dev = dev;
2483 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002484
Vipul Pandya830662f2013-07-04 16:10:47 +05302485 if (iptype == 4) {
2486 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002487 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002488
Vipul Pandya830662f2013-07-04 16:10:47 +05302489 sin->sin_family = PF_INET;
2490 sin->sin_port = local_port;
2491 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002492
2493 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2494 sin->sin_family = PF_INET;
2495 sin->sin_port = ((struct sockaddr_in *)
2496 &parent_ep->com.local_addr)->sin_port;
2497 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2498
Steve Wise170003c2016-02-26 09:18:03 -06002499 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302500 sin->sin_family = PF_INET;
2501 sin->sin_port = peer_port;
2502 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2503 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002504 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302505 sin6->sin6_family = PF_INET6;
2506 sin6->sin6_port = local_port;
2507 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002508
2509 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2510 sin6->sin6_family = PF_INET6;
2511 sin6->sin6_port = ((struct sockaddr_in6 *)
2512 &parent_ep->com.local_addr)->sin6_port;
2513 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2514
Steve Wise170003c2016-02-26 09:18:03 -06002515 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302516 sin6->sin6_family = PF_INET6;
2517 sin6->sin6_port = peer_port;
2518 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2519 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002520
Steve Wisecfdda9d2010-04-21 15:30:06 -07002521 c4iw_get_ep(&parent_ep->com);
2522 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302523 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002524 child_ep->dst = dst;
2525 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002526
2527 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002528 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002529
2530 init_timer(&child_ep->timer);
2531 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002532 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Hariprasad S9dec9002016-05-05 01:27:29 +05302533 if (accept_cr(child_ep, skb, req)) {
2534 c4iw_put_ep(&parent_ep->com);
2535 release_ep_resources(child_ep);
2536 } else {
2537 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2538 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302539 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002540 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302541 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2542 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2543 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002544 goto out;
2545reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302546 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002547out:
2548 return 0;
2549}
2550
2551static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2552{
2553 struct c4iw_ep *ep;
2554 struct cpl_pass_establish *req = cplhdr(skb);
2555 struct tid_info *t = dev->rdev.lldi.tids;
2556 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302557 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002558
2559 ep = lookup_tid(t, tid);
2560 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2561 ep->snd_seq = be32_to_cpu(req->snd_isn);
2562 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2563
Vipul Pandya1cab7752012-12-10 09:30:55 +00002564 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2565 ntohs(req->tcp_opt));
2566
Steve Wisecfdda9d2010-04-21 15:30:06 -07002567 set_emss(ep, ntohs(req->tcp_opt));
2568
2569 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302570 mutex_lock(&ep->com.mutex);
2571 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002572 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002573 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad Sfef44222016-05-05 01:27:33 +05302574 ret = send_flowc(ep, skb);
2575 mutex_unlock(&ep->com.mutex);
2576 if (ret)
2577 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002578
2579 return 0;
2580}
2581
2582static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2583{
2584 struct cpl_peer_close *hdr = cplhdr(skb);
2585 struct c4iw_ep *ep;
2586 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002587 int disconnect = 1;
2588 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002589 struct tid_info *t = dev->rdev.lldi.tids;
2590 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002591 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002592
2593 ep = lookup_tid(t, tid);
2594 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2595 dst_confirm(ep->dst);
2596
Vipul Pandya793dad92012-12-10 09:30:56 +00002597 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002598 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002599 switch (ep->com.state) {
2600 case MPA_REQ_WAIT:
2601 __state_set(&ep->com, CLOSING);
2602 break;
2603 case MPA_REQ_SENT:
2604 __state_set(&ep->com, CLOSING);
2605 connect_reply_upcall(ep, -ECONNRESET);
2606 break;
2607 case MPA_REQ_RCVD:
2608
2609 /*
2610 * We're gonna mark this puppy DEAD, but keep
2611 * the reference on it until the ULP accepts or
2612 * rejects the CR. Also wake up anyone waiting
2613 * in rdma connection migration (see c4iw_accept_cr()).
2614 */
2615 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002616 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002617 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002618 break;
2619 case MPA_REP_SENT:
2620 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002621 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002622 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002623 break;
2624 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002625 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002626 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002627 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002628 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002629 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002630 if (ret != -ECONNRESET) {
2631 peer_close_upcall(ep);
2632 disconnect = 1;
2633 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002634 break;
2635 case ABORTING:
2636 disconnect = 0;
2637 break;
2638 case CLOSING:
2639 __state_set(&ep->com, MORIBUND);
2640 disconnect = 0;
2641 break;
2642 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002643 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002644 if (ep->com.cm_id && ep->com.qp) {
2645 attrs.next_state = C4IW_QP_STATE_IDLE;
2646 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2647 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2648 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302649 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002650 __state_set(&ep->com, DEAD);
2651 release = 1;
2652 disconnect = 0;
2653 break;
2654 case DEAD:
2655 disconnect = 0;
2656 break;
2657 default:
2658 BUG_ON(1);
2659 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002660 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002661 if (disconnect)
2662 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2663 if (release)
2664 release_ep_resources(ep);
2665 return 0;
2666}
2667
Steve Wisecfdda9d2010-04-21 15:30:06 -07002668static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2669{
2670 struct cpl_abort_req_rss *req = cplhdr(skb);
2671 struct c4iw_ep *ep;
2672 struct cpl_abort_rpl *rpl;
2673 struct sk_buff *rpl_skb;
2674 struct c4iw_qp_attributes attrs;
2675 int ret;
2676 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002677 struct tid_info *t = dev->rdev.lldi.tids;
2678 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002679
2680 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302681 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302682 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2683 __func__, ep->hwtid, req->status,
2684 neg_adv_str(req->status));
2685 ep->stats.abort_neg_adv++;
2686 mutex_lock(&dev->rdev.stats.lock);
2687 dev->rdev.stats.neg_adv++;
2688 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002689 return 0;
2690 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002691 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2692 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002693 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002694
2695 /*
2696 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302697 * However, this is not needed if com state is just
2698 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002699 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302700 if (ep->com.state != MPA_REQ_SENT)
2701 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002702
2703 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002704 switch (ep->com.state) {
2705 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302706 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002707 break;
2708 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002709 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002710 break;
2711 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002712 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002713 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302714 connect_reply_upcall(ep, -ECONNRESET);
2715 else {
2716 /*
2717 * we just don't send notification upwards because we
2718 * want to retry with mpa_v1 without upper layers even
2719 * knowing it.
2720 *
2721 * do some housekeeping so as to re-initiate the
2722 * connection
2723 */
2724 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2725 mpa_rev);
2726 ep->retry_with_mpa_v1 = 1;
2727 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002728 break;
2729 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002730 break;
2731 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002732 break;
2733 case MORIBUND:
2734 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002735 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002736 /*FALLTHROUGH*/
2737 case FPDU_MODE:
2738 if (ep->com.cm_id && ep->com.qp) {
2739 attrs.next_state = C4IW_QP_STATE_ERROR;
2740 ret = c4iw_modify_qp(ep->com.qp->rhp,
2741 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2742 &attrs, 1);
2743 if (ret)
2744 printk(KERN_ERR MOD
2745 "%s - qp <- error failed!\n",
2746 __func__);
2747 }
2748 peer_abort_upcall(ep);
2749 break;
2750 case ABORTING:
2751 break;
2752 case DEAD:
2753 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002754 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002755 return 0;
2756 default:
2757 BUG_ON(1);
2758 break;
2759 }
2760 dst_confirm(ep->dst);
2761 if (ep->com.state != ABORTING) {
2762 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302763 /* we don't release if we want to retry with mpa_v1 */
2764 if (!ep->retry_with_mpa_v1)
2765 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002766 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002767 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002768
2769 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2770 if (!rpl_skb) {
2771 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2772 __func__);
2773 release = 1;
2774 goto out;
2775 }
2776 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2777 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2778 INIT_TP_WR(rpl, ep->hwtid);
2779 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2780 rpl->cmd = CPL_ABORT_NO_RST;
2781 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2782out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002783 if (release)
2784 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002785 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302786 if (ep->com.remote_addr.ss_family == AF_INET6) {
2787 struct sockaddr_in6 *sin6 =
2788 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002789 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302790 cxgb4_clip_release(
2791 ep->com.dev->rdev.lldi.ports[0],
2792 (const u32 *)&sin6->sin6_addr.s6_addr,
2793 1);
2794 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002795 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302796 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2797 dst_release(ep->dst);
2798 cxgb4_l2t_release(ep->l2t);
2799 c4iw_reconnect(ep);
2800 }
2801
Steve Wisecfdda9d2010-04-21 15:30:06 -07002802 return 0;
2803}
2804
2805static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2806{
2807 struct c4iw_ep *ep;
2808 struct c4iw_qp_attributes attrs;
2809 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002810 int release = 0;
2811 struct tid_info *t = dev->rdev.lldi.tids;
2812 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002813
2814 ep = lookup_tid(t, tid);
2815
2816 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2817 BUG_ON(!ep);
2818
2819 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002820 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002821 switch (ep->com.state) {
2822 case CLOSING:
2823 __state_set(&ep->com, MORIBUND);
2824 break;
2825 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002826 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002827 if ((ep->com.cm_id) && (ep->com.qp)) {
2828 attrs.next_state = C4IW_QP_STATE_IDLE;
2829 c4iw_modify_qp(ep->com.qp->rhp,
2830 ep->com.qp,
2831 C4IW_QP_ATTR_NEXT_STATE,
2832 &attrs, 1);
2833 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302834 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002835 __state_set(&ep->com, DEAD);
2836 release = 1;
2837 break;
2838 case ABORTING:
2839 case DEAD:
2840 break;
2841 default:
2842 BUG_ON(1);
2843 break;
2844 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002845 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002846 if (release)
2847 release_ep_resources(ep);
2848 return 0;
2849}
2850
2851static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2852{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002853 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002854 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002855 unsigned int tid = GET_TID(rpl);
2856 struct c4iw_ep *ep;
2857 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002858
2859 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002860 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002861
Steve Wise30c95c22011-05-09 22:06:22 -07002862 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002863 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2864 ep->com.qp->wq.sq.qid);
2865 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2866 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2867 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2868 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002869 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002870
Steve Wisecfdda9d2010-04-21 15:30:06 -07002871 return 0;
2872}
2873
2874/*
2875 * Upcall from the adapter indicating data has been transmitted.
2876 * For us its just the single MPA request or reply. We can now free
2877 * the skb holding the mpa message.
2878 */
2879static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2880{
2881 struct c4iw_ep *ep;
2882 struct cpl_fw4_ack *hdr = cplhdr(skb);
2883 u8 credits = hdr->credits;
2884 unsigned int tid = GET_TID(hdr);
2885 struct tid_info *t = dev->rdev.lldi.tids;
2886
2887
2888 ep = lookup_tid(t, tid);
2889 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2890 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002891 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2892 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002893 return 0;
2894 }
2895
2896 dst_confirm(ep->dst);
2897 if (ep->mpa_skb) {
2898 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2899 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2900 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2901 kfree_skb(ep->mpa_skb);
2902 ep->mpa_skb = NULL;
2903 }
2904 return 0;
2905}
2906
Steve Wisecfdda9d2010-04-21 15:30:06 -07002907int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2908{
Steve Wisea7db89e2014-03-21 20:40:35 +05302909 int err = 0;
2910 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002911 struct c4iw_ep *ep = to_ep(cm_id);
2912 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2913
Steve Wisea7db89e2014-03-21 20:40:35 +05302914 mutex_lock(&ep->com.mutex);
2915 if (ep->com.state == DEAD) {
2916 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002917 c4iw_put_ep(&ep->com);
2918 return -ECONNRESET;
2919 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002920 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302921 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002922 if (mpa_rev == 0)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302923 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002924 else {
2925 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302926 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002927 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302928 mutex_unlock(&ep->com.mutex);
2929 if (disconnect)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302930 err = c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002931 c4iw_put_ep(&ep->com);
2932 return 0;
2933}
2934
2935int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2936{
2937 int err;
2938 struct c4iw_qp_attributes attrs;
2939 enum c4iw_qp_attr_mask mask;
2940 struct c4iw_ep *ep = to_ep(cm_id);
2941 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2942 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302943 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002944
2945 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302946
2947 mutex_lock(&ep->com.mutex);
2948 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002949 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302950 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002951 }
2952
Steve Wisea7db89e2014-03-21 20:40:35 +05302953 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002954 BUG_ON(!qp);
2955
Vipul Pandya793dad92012-12-10 09:30:56 +00002956 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302957 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2958 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002959 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302960 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002961 }
2962
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302963 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2964 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302965 if (RELAXED_IRD_NEGOTIATION) {
2966 ep->ord = ep->ird;
2967 } else {
2968 ep->ird = conn_param->ird;
2969 ep->ord = conn_param->ord;
2970 send_mpa_reject(ep, conn_param->private_data,
2971 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302972 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302973 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302974 }
2975 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302976 if (conn_param->ird < ep->ord) {
2977 if (RELAXED_IRD_NEGOTIATION &&
2978 ep->ord <= h->rdev.lldi.max_ordird_qp) {
2979 conn_param->ird = ep->ord;
2980 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302981 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302982 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302983 }
2984 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302985 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002986 ep->ird = conn_param->ird;
2987 ep->ord = conn_param->ord;
2988
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302989 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302990 if (peer2peer && ep->ird == 0)
2991 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302992 } else {
2993 if (peer2peer &&
2994 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05302995 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302996 ep->ird = 1;
2997 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002998
2999 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3000
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303001 cm_id->add_ref(cm_id);
3002 ep->com.cm_id = cm_id;
3003 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003004 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303005
Steve Wisecfdda9d2010-04-21 15:30:06 -07003006 /* bind QP to EP and move to RTS */
3007 attrs.mpa_attr = ep->mpa_attr;
3008 attrs.max_ird = ep->ird;
3009 attrs.max_ord = ep->ord;
3010 attrs.llp_stream_handle = ep;
3011 attrs.next_state = C4IW_QP_STATE_RTS;
3012
3013 /* bind QP and TID with INIT_WR */
3014 mask = C4IW_QP_ATTR_NEXT_STATE |
3015 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3016 C4IW_QP_ATTR_MPA_ATTR |
3017 C4IW_QP_ATTR_MAX_IRD |
3018 C4IW_QP_ATTR_MAX_ORD;
3019
3020 err = c4iw_modify_qp(ep->com.qp->rhp,
3021 ep->com.qp, mask, &attrs, 1);
3022 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303023 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003024 err = send_mpa_reply(ep, conn_param->private_data,
3025 conn_param->private_data_len);
3026 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303027 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003028
Steve Wisea7db89e2014-03-21 20:40:35 +05303029 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003030 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303031 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003032 c4iw_put_ep(&ep->com);
3033 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303034err_deref_cm_id:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003035 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003036 cm_id->rem_ref(cm_id);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303037err_abort:
3038 abort = 1;
3039err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303040 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303041 if (abort)
3042 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003043 c4iw_put_ep(&ep->com);
3044 return err;
3045}
3046
Vipul Pandya830662f2013-07-04 16:10:47 +05303047static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3048{
3049 struct in_device *ind;
3050 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003051 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3052 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303053
3054 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3055 if (!ind)
3056 return -EADDRNOTAVAIL;
3057 for_primary_ifa(ind) {
3058 laddr->sin_addr.s_addr = ifa->ifa_address;
3059 raddr->sin_addr.s_addr = ifa->ifa_address;
3060 found = 1;
3061 break;
3062 }
3063 endfor_ifa(ind);
3064 in_dev_put(ind);
3065 return found ? 0 : -EADDRNOTAVAIL;
3066}
3067
3068static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3069 unsigned char banned_flags)
3070{
3071 struct inet6_dev *idev;
3072 int err = -EADDRNOTAVAIL;
3073
3074 rcu_read_lock();
3075 idev = __in6_dev_get(dev);
3076 if (idev != NULL) {
3077 struct inet6_ifaddr *ifp;
3078
3079 read_lock_bh(&idev->lock);
3080 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3081 if (ifp->scope == IFA_LINK &&
3082 !(ifp->flags & banned_flags)) {
3083 memcpy(addr, &ifp->addr, 16);
3084 err = 0;
3085 break;
3086 }
3087 }
3088 read_unlock_bh(&idev->lock);
3089 }
3090 rcu_read_unlock();
3091 return err;
3092}
3093
3094static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3095{
3096 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003097 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3098 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303099
Nicholas Krause54b9a962015-08-26 23:00:59 -04003100 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303101 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3102 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3103 return 0;
3104 }
3105 return -EADDRNOTAVAIL;
3106}
3107
Steve Wisecfdda9d2010-04-21 15:30:06 -07003108int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3109{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003110 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3111 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003112 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003113 struct sockaddr_in *laddr;
3114 struct sockaddr_in *raddr;
3115 struct sockaddr_in6 *laddr6;
3116 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303117 __u8 *ra;
3118 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003119
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303120 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3121 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003122 err = -EINVAL;
3123 goto out;
3124 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003125 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3126 if (!ep) {
3127 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3128 err = -ENOMEM;
3129 goto out;
3130 }
3131 init_timer(&ep->timer);
3132 ep->plen = conn_param->private_data_len;
3133 if (ep->plen)
3134 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3135 conn_param->private_data, ep->plen);
3136 ep->ird = conn_param->ird;
3137 ep->ord = conn_param->ord;
3138
3139 if (peer2peer && ep->ord == 0)
3140 ep->ord = 1;
3141
3142 cm_id->add_ref(cm_id);
3143 ep->com.dev = dev;
3144 ep->com.cm_id = cm_id;
3145 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303146 if (!ep->com.qp) {
3147 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3148 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003149 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303150 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003151 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003152 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3153 ep->com.qp, cm_id);
3154
3155 /*
3156 * Allocate an active TID to initiate a TCP connection.
3157 */
3158 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3159 if (ep->atid == -1) {
3160 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3161 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003162 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003163 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003164 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003165
Steve Wise170003c2016-02-26 09:18:03 -06003166 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003167 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003168 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003169 sizeof(ep->com.remote_addr));
3170
Steve Wise170003c2016-02-26 09:18:03 -06003171 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3172 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3173 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3174 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003175
Steve Wise170003c2016-02-26 09:18:03 -06003176 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303177 iptype = 4;
3178 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003179
Vipul Pandya830662f2013-07-04 16:10:47 +05303180 /*
3181 * Handle loopback requests to INADDR_ANY.
3182 */
3183 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3184 err = pick_local_ipaddrs(dev, cm_id);
3185 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003186 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303187 }
3188
3189 /* find a route */
3190 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3191 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3192 ra, ntohs(raddr->sin_port));
3193 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3194 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303195 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303196 } else {
3197 iptype = 6;
3198 ra = (__u8 *)&raddr6->sin6_addr;
3199
3200 /*
3201 * Handle loopback requests to INADDR_ANY.
3202 */
3203 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3204 err = pick_local_ip6addrs(dev, cm_id);
3205 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003206 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303207 }
3208
3209 /* find a route */
3210 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3211 __func__, laddr6->sin6_addr.s6_addr,
3212 ntohs(laddr6->sin6_port),
3213 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3214 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3215 raddr6->sin6_addr.s6_addr,
3216 laddr6->sin6_port, raddr6->sin6_port, 0,
3217 raddr6->sin6_scope_id);
3218 }
3219 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003220 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3221 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003222 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003223 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003224
Hariprasad S963cab52015-09-23 17:19:27 +05303225 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303226 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003227 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003228 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003229 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003230 }
3231
3232 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3233 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3234 ep->l2t->idx);
3235
3236 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303237 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003238
3239 /* send connect request to rnic */
3240 err = send_connect(ep);
3241 if (!err)
3242 goto out;
3243
3244 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003245fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003246 dst_release(ep->dst);
3247fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003248 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003249 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003250fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003251 cm_id->rem_ref(cm_id);
3252 c4iw_put_ep(&ep->com);
3253out:
3254 return err;
3255}
3256
Vipul Pandya830662f2013-07-04 16:10:47 +05303257static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3258{
3259 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003260 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003261 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303262
Hariprasad S28de1f72016-01-13 10:03:14 +05303263 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3264 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3265 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3266 if (err)
3267 return err;
3268 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303269 c4iw_init_wr_wait(&ep->com.wr_wait);
3270 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3271 ep->stid, &sin6->sin6_addr,
3272 sin6->sin6_port,
3273 ep->com.dev->rdev.lldi.rxq_ids[0]);
3274 if (!err)
3275 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3276 &ep->com.wr_wait,
3277 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303278 else if (err > 0)
3279 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303280 if (err) {
3281 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3282 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303283 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3284 err, ep->stid,
3285 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303286 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303287 return err;
3288}
3289
3290static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3291{
3292 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003293 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003294 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303295
3296 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3297 do {
3298 err = cxgb4_create_server_filter(
3299 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3300 sin->sin_addr.s_addr, sin->sin_port, 0,
3301 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3302 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303303 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3304 err = -EIO;
3305 break;
3306 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303307 set_current_state(TASK_UNINTERRUPTIBLE);
3308 schedule_timeout(usecs_to_jiffies(100));
3309 }
3310 } while (err == -EBUSY);
3311 } else {
3312 c4iw_init_wr_wait(&ep->com.wr_wait);
3313 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3314 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3315 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3316 if (!err)
3317 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3318 &ep->com.wr_wait,
3319 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303320 else if (err > 0)
3321 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303322 }
3323 if (err)
3324 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3325 , err, ep->stid,
3326 &sin->sin_addr, ntohs(sin->sin_port));
3327 return err;
3328}
3329
Steve Wisecfdda9d2010-04-21 15:30:06 -07003330int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3331{
3332 int err = 0;
3333 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3334 struct c4iw_listen_ep *ep;
3335
Steve Wisecfdda9d2010-04-21 15:30:06 -07003336 might_sleep();
3337
3338 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3339 if (!ep) {
3340 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3341 err = -ENOMEM;
3342 goto fail1;
3343 }
3344 PDBG("%s ep %p\n", __func__, ep);
3345 cm_id->add_ref(cm_id);
3346 ep->com.cm_id = cm_id;
3347 ep->com.dev = dev;
3348 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003349 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303350 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003351
3352 /*
3353 * Allocate a server TID.
3354 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303355 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3356 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303357 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003358 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003359 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303360 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003361 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003362
Steve Wisecfdda9d2010-04-21 15:30:06 -07003363 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003364 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003365 err = -ENOMEM;
3366 goto fail2;
3367 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003368 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003369
Steve Wise170003c2016-02-26 09:18:03 -06003370 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3371 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003372
Steve Wisecfdda9d2010-04-21 15:30:06 -07003373 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303374 if (ep->com.local_addr.ss_family == AF_INET)
3375 err = create_server4(dev, ep);
3376 else
3377 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003378 if (!err) {
3379 cm_id->provider_data = ep;
3380 goto out;
3381 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003382
Vipul Pandya830662f2013-07-04 16:10:47 +05303383 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3384 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003385fail2:
3386 cm_id->rem_ref(cm_id);
3387 c4iw_put_ep(&ep->com);
3388fail1:
3389out:
3390 return err;
3391}
3392
3393int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3394{
3395 int err;
3396 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3397
3398 PDBG("%s ep %p\n", __func__, ep);
3399
3400 might_sleep();
3401 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303402 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3403 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003404 err = cxgb4_remove_server_filter(
3405 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3406 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3407 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303408 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003409 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303410 err = cxgb4_remove_server(
3411 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3412 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003413 if (err)
3414 goto done;
3415 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3416 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003417 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303418 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3419 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003420 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003421 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303422 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3423 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003424done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003425 cm_id->rem_ref(cm_id);
3426 c4iw_put_ep(&ep->com);
3427 return err;
3428}
3429
3430int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3431{
3432 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003433 int close = 0;
3434 int fatal = 0;
3435 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003436
Steve Wise2f5b48c2010-09-10 11:15:36 -05003437 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003438
3439 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3440 states[ep->com.state], abrupt);
3441
Hariprasad S6e410d82016-05-05 01:27:31 +05303442 /*
3443 * Ref the ep here in case we have fatal errors causing the
3444 * ep to be released and freed.
3445 */
3446 c4iw_get_ep(&ep->com);
3447
Steve Wisecfdda9d2010-04-21 15:30:06 -07003448 rdev = &ep->com.dev->rdev;
3449 if (c4iw_fatal_error(rdev)) {
3450 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303451 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003452 ep->com.state = DEAD;
3453 }
3454 switch (ep->com.state) {
3455 case MPA_REQ_WAIT:
3456 case MPA_REQ_SENT:
3457 case MPA_REQ_RCVD:
3458 case MPA_REP_SENT:
3459 case FPDU_MODE:
3460 close = 1;
3461 if (abrupt)
3462 ep->com.state = ABORTING;
3463 else {
3464 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003465 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003466 }
3467 set_bit(CLOSE_SENT, &ep->com.flags);
3468 break;
3469 case CLOSING:
3470 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3471 close = 1;
3472 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003473 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003474 ep->com.state = ABORTING;
3475 } else
3476 ep->com.state = MORIBUND;
3477 }
3478 break;
3479 case MORIBUND:
3480 case ABORTING:
3481 case DEAD:
3482 PDBG("%s ignoring disconnect ep %p state %u\n",
3483 __func__, ep, ep->com.state);
3484 break;
3485 default:
3486 BUG();
3487 break;
3488 }
3489
Steve Wisecfdda9d2010-04-21 15:30:06 -07003490 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003491 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003492 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303493 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003494 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003495 } else {
3496 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003497 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003498 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303499 if (ret) {
3500 if (!abrupt) {
3501 stop_ep_timer(ep);
3502 close_complete_upcall(ep, -EIO);
3503 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303504 if (ep->com.qp) {
3505 struct c4iw_qp_attributes attrs;
3506
3507 attrs.next_state = C4IW_QP_STATE_ERROR;
3508 ret = c4iw_modify_qp(ep->com.qp->rhp,
3509 ep->com.qp,
3510 C4IW_QP_ATTR_NEXT_STATE,
3511 &attrs, 1);
3512 if (ret)
3513 pr_err(MOD
3514 "%s - qp <- error failed!\n",
3515 __func__);
3516 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003517 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303518 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003519 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003520 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303521 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003522 if (fatal)
3523 release_ep_resources(ep);
3524 return ret;
3525}
3526
Vipul Pandya1cab7752012-12-10 09:30:55 +00003527static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3528 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3529{
3530 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003531 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003532
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003533 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3534 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003535 if (!ep)
3536 return;
3537
3538 switch (req->retval) {
3539 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003540 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3541 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3542 send_fw_act_open_req(ep, atid);
3543 return;
3544 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003545 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003546 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3547 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3548 send_fw_act_open_req(ep, atid);
3549 return;
3550 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003551 break;
3552 default:
3553 pr_info("%s unexpected ofld conn wr retval %d\n",
3554 __func__, req->retval);
3555 break;
3556 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003557 pr_err("active ofld_connect_wr failure %d atid %d\n",
3558 req->retval, atid);
3559 mutex_lock(&dev->rdev.stats.lock);
3560 dev->rdev.stats.act_ofld_conn_fails++;
3561 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003562 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003563 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303564 if (ep->com.remote_addr.ss_family == AF_INET6) {
3565 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003566 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303567 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3568 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3569 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003570 remove_handle(dev, &dev->atid_idr, atid);
3571 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3572 dst_release(ep->dst);
3573 cxgb4_l2t_release(ep->l2t);
3574 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003575}
3576
3577static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3578 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3579{
3580 struct sk_buff *rpl_skb;
3581 struct cpl_pass_accept_req *cpl;
3582 int ret;
3583
Paul Bolle710a3112013-02-05 20:51:30 +00003584 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003585 BUG_ON(!rpl_skb);
3586 if (req->retval) {
3587 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003588 mutex_lock(&dev->rdev.stats.lock);
3589 dev->rdev.stats.pas_ofld_conn_fails++;
3590 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003591 kfree_skb(rpl_skb);
3592 } else {
3593 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3594 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003595 (__force u32) htonl(
3596 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003597 ret = pass_accept_req(dev, rpl_skb);
3598 if (!ret)
3599 kfree_skb(rpl_skb);
3600 }
3601 return;
3602}
3603
3604static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003605{
3606 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003607 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3608
3609 switch (rpl->type) {
3610 case FW6_TYPE_CQE:
3611 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3612 break;
3613 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3614 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3615 switch (req->t_state) {
3616 case TCP_SYN_SENT:
3617 active_ofld_conn_reply(dev, skb, req);
3618 break;
3619 case TCP_SYN_RECV:
3620 passive_ofld_conn_reply(dev, skb, req);
3621 break;
3622 default:
3623 pr_err("%s unexpected ofld conn wr state %d\n",
3624 __func__, req->t_state);
3625 break;
3626 }
3627 break;
3628 }
3629 return 0;
3630}
3631
3632static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3633{
Hariprasad S963cab52015-09-23 17:19:27 +05303634 __be32 l2info;
3635 __be16 hdr_len, vlantag, len;
3636 u16 eth_hdr_len;
3637 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003638 u8 intf;
3639 struct cpl_rx_pkt *cpl = cplhdr(skb);
3640 struct cpl_pass_accept_req *req;
3641 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003642 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303643 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003644
Vipul Pandyaf079af72013-03-14 05:08:58 +00003645 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003646 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303647 vlantag = cpl->vlan;
3648 len = cpl->len;
3649 l2info = cpl->l2info;
3650 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003651 intf = cpl->iff;
3652
3653 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3654
3655 /*
3656 * We need to parse the TCP options from SYN packet.
3657 * to generate cpl_pass_accept_req.
3658 */
3659 memset(&tmp_opt, 0, sizeof(tmp_opt));
3660 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003661 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003662
3663 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3664 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303665 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3666 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303667 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303668 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303669 type = dev->rdev.lldi.adapter_type;
3670 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3671 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3672 req->hdr_len =
3673 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3674 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3675 eth_hdr_len = is_t4(type) ?
3676 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3677 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3678 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3679 IP_HDR_LEN_V(ip_hdr_len) |
3680 ETH_HDR_LEN_V(eth_hdr_len));
3681 } else { /* T6 and later */
3682 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3683 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3684 T6_IP_HDR_LEN_V(ip_hdr_len) |
3685 T6_ETH_HDR_LEN_V(eth_hdr_len));
3686 }
3687 req->vlan = vlantag;
3688 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003689 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3690 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003691 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3692 if (tmp_opt.wscale_ok)
3693 req->tcpopt.wsf = tmp_opt.snd_wscale;
3694 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3695 if (tmp_opt.sack_ok)
3696 req->tcpopt.sack = 1;
3697 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3698 return;
3699}
3700
3701static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3702 __be32 laddr, __be16 lport,
3703 __be32 raddr, __be16 rport,
3704 u32 rcv_isn, u32 filter, u16 window,
3705 u32 rss_qid, u8 port_id)
3706{
3707 struct sk_buff *req_skb;
3708 struct fw_ofld_connection_wr *req;
3709 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303710 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003711
3712 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3713 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3714 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003715 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303716 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303717 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003718 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003719 req->le.lport = lport;
3720 req->le.pport = rport;
3721 req->le.u.ipv4.lip = laddr;
3722 req->le.u.ipv4.pip = raddr;
3723 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3724 req->tcb.rcv_adv = htons(window);
3725 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303726 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3727 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3728 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003729 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003730
3731 /*
3732 * We store the qid in opt2 which will be used by the firmware
3733 * to send us the wr response.
3734 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003735 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003736
3737 /*
3738 * We initialize the MSS index in TCB to 0xF.
3739 * So that when driver sends cpl_pass_accept_rpl
3740 * TCB picks up the correct value. If this was 0
3741 * TP will ignore any value > 0 for MSS index.
3742 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003743 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303744 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003745
3746 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303747 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3748 if (ret < 0) {
3749 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3750 ret);
3751 kfree_skb(skb);
3752 kfree_skb(req_skb);
3753 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003754}
3755
3756/*
3757 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3758 * messages when a filter is being used instead of server to
3759 * redirect a syn packet. When packets hit filter they are redirected
3760 * to the offload queue and driver tries to establish the connection
3761 * using firmware work request.
3762 */
3763static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3764{
3765 int stid;
3766 unsigned int filter;
3767 struct ethhdr *eh = NULL;
3768 struct vlan_ethhdr *vlan_eh = NULL;
3769 struct iphdr *iph;
3770 struct tcphdr *tcph;
3771 struct rss_header *rss = (void *)skb->data;
3772 struct cpl_rx_pkt *cpl = (void *)skb->data;
3773 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3774 struct l2t_entry *e;
3775 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003776 struct c4iw_ep *lep;
3777 u16 window;
3778 struct port_info *pi;
3779 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003780 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003781 int step;
3782 u32 tx_chan;
3783 struct neighbour *neigh;
3784
3785 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003786 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003787 goto reject;
3788
3789 /*
3790 * Drop all packets which did not hit the filter.
3791 * Unlikely to happen.
3792 */
3793 if (!(rss->filter_hit && rss->filter_tid))
3794 goto reject;
3795
3796 /*
3797 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3798 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303799 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003800
3801 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3802 if (!lep) {
3803 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3804 goto reject;
3805 }
3806
Hariprasad S963cab52015-09-23 17:19:27 +05303807 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3808 case CHELSIO_T4:
3809 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3810 break;
3811 case CHELSIO_T5:
3812 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3813 break;
3814 case CHELSIO_T6:
3815 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3816 break;
3817 default:
3818 pr_err("T%d Chip is not supported\n",
3819 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3820 goto reject;
3821 }
3822
Vipul Pandyaf079af72013-03-14 05:08:58 +00003823 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003824 eh = (struct ethhdr *)(req + 1);
3825 iph = (struct iphdr *)(eh + 1);
3826 } else {
3827 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3828 iph = (struct iphdr *)(vlan_eh + 1);
3829 skb->vlan_tci = ntohs(cpl->vlan);
3830 }
3831
3832 if (iph->version != 0x4)
3833 goto reject;
3834
3835 tcph = (struct tcphdr *)(iph + 1);
3836 skb_set_network_header(skb, (void *)iph - (void *)rss);
3837 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3838 skb_get(skb);
3839
3840 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3841 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3842 ntohs(tcph->source), iph->tos);
3843
Vipul Pandya830662f2013-07-04 16:10:47 +05303844 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3845 iph->tos);
3846 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003847 pr_err("%s - failed to find dst entry!\n",
3848 __func__);
3849 goto reject;
3850 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003851 neigh = dst_neigh_lookup_skb(dst, skb);
3852
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003853 if (!neigh) {
3854 pr_err("%s - failed to allocate neigh!\n",
3855 __func__);
3856 goto free_dst;
3857 }
3858
Vipul Pandya1cab7752012-12-10 09:30:55 +00003859 if (neigh->dev->flags & IFF_LOOPBACK) {
3860 pdev = ip_dev_find(&init_net, iph->daddr);
3861 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3862 pdev, 0);
3863 pi = (struct port_info *)netdev_priv(pdev);
3864 tx_chan = cxgb4_port_chan(pdev);
3865 dev_put(pdev);
3866 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303867 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003868 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303869 pdev, 0);
3870 pi = (struct port_info *)netdev_priv(pdev);
3871 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003872 }
Steve Wiseebf00062014-03-19 17:44:40 +05303873 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003874 if (!e) {
3875 pr_err("%s - failed to allocate l2t entry!\n",
3876 __func__);
3877 goto free_dst;
3878 }
3879
3880 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3881 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003882 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003883
3884 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303885 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3886 dev->rdev.lldi.ports[0],
3887 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003888
3889 /*
3890 * Synthesize the cpl_pass_accept_req. We have everything except the
3891 * TID. Once firmware sends a reply with TID we update the TID field
3892 * in cpl and pass it through the regular cpl_pass_accept_req path.
3893 */
3894 build_cpl_pass_accept_req(skb, stid, iph->tos);
3895 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3896 tcph->source, ntohl(tcph->seq), filter, window,
3897 rss_qid, pi->port_id);
3898 cxgb4_l2t_release(e);
3899free_dst:
3900 dst_release(dst);
3901reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003902 return 0;
3903}
3904
Steve Wisecfdda9d2010-04-21 15:30:06 -07003905/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003906 * These are the real handlers that are called from a
3907 * work queue.
3908 */
Hariprasad S9dec9002016-05-05 01:27:29 +05303909static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003910 [CPL_ACT_ESTABLISH] = act_establish,
3911 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3912 [CPL_RX_DATA] = rx_data,
3913 [CPL_ABORT_RPL_RSS] = abort_rpl,
3914 [CPL_ABORT_RPL] = abort_rpl,
3915 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3916 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3917 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3918 [CPL_PASS_ESTABLISH] = pass_establish,
3919 [CPL_PEER_CLOSE] = peer_close,
3920 [CPL_ABORT_REQ_RSS] = peer_abort,
3921 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3922 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003923 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003924 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05303925 [CPL_RX_PKT] = rx_pkt,
3926 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003927};
3928
3929static void process_timeout(struct c4iw_ep *ep)
3930{
3931 struct c4iw_qp_attributes attrs;
3932 int abort = 1;
3933
Steve Wise2f5b48c2010-09-10 11:15:36 -05003934 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003935 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3936 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003937 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003938 switch (ep->com.state) {
3939 case MPA_REQ_SENT:
3940 __state_set(&ep->com, ABORTING);
3941 connect_reply_upcall(ep, -ETIMEDOUT);
3942 break;
3943 case MPA_REQ_WAIT:
3944 __state_set(&ep->com, ABORTING);
3945 break;
3946 case CLOSING:
3947 case MORIBUND:
3948 if (ep->com.cm_id && ep->com.qp) {
3949 attrs.next_state = C4IW_QP_STATE_ERROR;
3950 c4iw_modify_qp(ep->com.qp->rhp,
3951 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3952 &attrs, 1);
3953 }
3954 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303955 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003956 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003957 case ABORTING:
3958 case DEAD:
3959
3960 /*
3961 * These states are expected if the ep timed out at the same
3962 * time as another thread was calling stop_ep_timer().
3963 * So we silently do nothing for these states.
3964 */
3965 abort = 0;
3966 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003967 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003968 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003969 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003970 abort = 0;
3971 }
Steve Wisecc18b932014-04-24 14:31:53 -05003972 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05303973 if (abort)
3974 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003975 c4iw_put_ep(&ep->com);
3976}
3977
3978static void process_timedout_eps(void)
3979{
3980 struct c4iw_ep *ep;
3981
3982 spin_lock_irq(&timeout_lock);
3983 while (!list_empty(&timeout_list)) {
3984 struct list_head *tmp;
3985
3986 tmp = timeout_list.next;
3987 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003988 tmp->next = NULL;
3989 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003990 spin_unlock_irq(&timeout_lock);
3991 ep = list_entry(tmp, struct c4iw_ep, entry);
3992 process_timeout(ep);
3993 spin_lock_irq(&timeout_lock);
3994 }
3995 spin_unlock_irq(&timeout_lock);
3996}
3997
3998static void process_work(struct work_struct *work)
3999{
4000 struct sk_buff *skb = NULL;
4001 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004002 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004003 unsigned int opcode;
4004 int ret;
4005
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004006 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004007 while ((skb = skb_dequeue(&rxq))) {
4008 rpl = cplhdr(skb);
4009 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4010 opcode = rpl->ot.opcode;
4011
4012 BUG_ON(!work_handlers[opcode]);
4013 ret = work_handlers[opcode](dev, skb);
4014 if (!ret)
4015 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004016 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004017 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004018}
4019
4020static DECLARE_WORK(skb_work, process_work);
4021
4022static void ep_timeout(unsigned long arg)
4023{
4024 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004025 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004026
4027 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004028 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004029 /*
4030 * Only insert if it is not already on the list.
4031 */
4032 if (!ep->entry.next) {
4033 list_add_tail(&ep->entry, &timeout_list);
4034 kickit = 1;
4035 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004036 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004037 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004038 if (kickit)
4039 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004040}
4041
4042/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004043 * All the CM events are handled on a work queue to have a safe context.
4044 */
4045static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4046{
4047
4048 /*
4049 * Save dev in the skb->cb area.
4050 */
4051 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4052
4053 /*
4054 * Queue the skb and schedule the worker thread.
4055 */
4056 skb_queue_tail(&rxq, skb);
4057 queue_work(workq, &skb_work);
4058 return 0;
4059}
4060
4061static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4062{
4063 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4064
4065 if (rpl->status != CPL_ERR_NONE) {
4066 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4067 "for tid %u\n", rpl->status, GET_TID(rpl));
4068 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004069 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004070 return 0;
4071}
4072
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004073static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4074{
4075 struct cpl_fw6_msg *rpl = cplhdr(skb);
4076 struct c4iw_wr_wait *wr_waitp;
4077 int ret;
4078
4079 PDBG("%s type %u\n", __func__, rpl->type);
4080
4081 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004082 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004083 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004084 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004085 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004086 if (wr_waitp)
4087 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004088 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004089 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004090 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004091 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004092 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004093 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004094 default:
4095 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4096 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004097 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004098 break;
4099 }
4100 return 0;
4101}
4102
Steve Wise8da7e7a2011-06-14 20:59:27 +00004103static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4104{
4105 struct cpl_abort_req_rss *req = cplhdr(skb);
4106 struct c4iw_ep *ep;
4107 struct tid_info *t = dev->rdev.lldi.tids;
4108 unsigned int tid = GET_TID(req);
4109
4110 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05004111 if (!ep) {
4112 printk(KERN_WARNING MOD
4113 "Abort on non-existent endpoint, tid %d\n", tid);
4114 kfree_skb(skb);
4115 return 0;
4116 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304117 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304118 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4119 __func__, ep->hwtid, req->status,
4120 neg_adv_str(req->status));
4121 ep->stats.abort_neg_adv++;
4122 dev->rdev.stats.neg_adv++;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004123 kfree_skb(skb);
4124 return 0;
4125 }
4126 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4127 ep->com.state);
4128
4129 /*
4130 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004131 * However, if we are on MPAv2 and want to retry with MPAv1
4132 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004133 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004134 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4135 if (ep->com.state != MPA_REQ_SENT)
4136 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4137 } else
4138 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00004139 sched(dev, skb);
4140 return 0;
4141}
4142
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004143/*
4144 * Most upcalls from the T4 Core go to sched() to
4145 * schedule the processing on a work queue.
4146 */
4147c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4148 [CPL_ACT_ESTABLISH] = sched,
4149 [CPL_ACT_OPEN_RPL] = sched,
4150 [CPL_RX_DATA] = sched,
4151 [CPL_ABORT_RPL_RSS] = sched,
4152 [CPL_ABORT_RPL] = sched,
4153 [CPL_PASS_OPEN_RPL] = sched,
4154 [CPL_CLOSE_LISTSRV_RPL] = sched,
4155 [CPL_PASS_ACCEPT_REQ] = sched,
4156 [CPL_PASS_ESTABLISH] = sched,
4157 [CPL_PEER_CLOSE] = sched,
4158 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004159 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004160 [CPL_RDMA_TERMINATE] = sched,
4161 [CPL_FW4_ACK] = sched,
4162 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004163 [CPL_FW6_MSG] = fw6_msg,
4164 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004165};
4166
Steve Wisecfdda9d2010-04-21 15:30:06 -07004167int __init c4iw_cm_init(void)
4168{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004169 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004170 skb_queue_head_init(&rxq);
4171
4172 workq = create_singlethread_workqueue("iw_cxgb4");
4173 if (!workq)
4174 return -ENOMEM;
4175
Steve Wisecfdda9d2010-04-21 15:30:06 -07004176 return 0;
4177}
4178
Steve Wise46c13762014-06-20 14:26:25 -05004179void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004180{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004181 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004182 flush_workqueue(workq);
4183 destroy_workqueue(workq);
4184}