blob: 864da9dec9f6349cb4e9686eaf21cc5df566eea9 [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
1182static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
1183{
1184 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecc18b932014-04-24 14:31:53 -05001185 __state_set(&ep->com, ABORTING);
Vipul Pandya793dad92012-12-10 09:30:56 +00001186 set_bit(ABORT_CONN, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001187 return send_abort(ep, skb, gfp);
1188}
1189
1190static void peer_close_upcall(struct c4iw_ep *ep)
1191{
1192 struct iw_cm_event event;
1193
1194 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1195 memset(&event, 0, sizeof(event));
1196 event.event = IW_CM_EVENT_DISCONNECT;
1197 if (ep->com.cm_id) {
1198 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1199 ep, ep->com.cm_id, ep->hwtid);
1200 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001201 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001202 }
1203}
1204
1205static void peer_abort_upcall(struct c4iw_ep *ep)
1206{
1207 struct iw_cm_event event;
1208
1209 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1210 memset(&event, 0, sizeof(event));
1211 event.event = IW_CM_EVENT_CLOSE;
1212 event.status = -ECONNRESET;
1213 if (ep->com.cm_id) {
1214 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1215 ep->com.cm_id, ep->hwtid);
1216 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1217 ep->com.cm_id->rem_ref(ep->com.cm_id);
1218 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001219 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001220 }
1221}
1222
1223static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1224{
1225 struct iw_cm_event event;
1226
1227 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1228 memset(&event, 0, sizeof(event));
1229 event.event = IW_CM_EVENT_CONNECT_REPLY;
1230 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301231 memcpy(&event.local_addr, &ep->com.local_addr,
1232 sizeof(ep->com.local_addr));
1233 memcpy(&event.remote_addr, &ep->com.remote_addr,
1234 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001235
1236 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301237 if (!ep->tried_with_mpa_v1) {
1238 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301239 event.ord = ep->ird;
1240 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301241 event.private_data_len = ep->plen -
1242 sizeof(struct mpa_v2_conn_params);
1243 event.private_data = ep->mpa_pkt +
1244 sizeof(struct mpa_message) +
1245 sizeof(struct mpa_v2_conn_params);
1246 } else {
1247 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301248 event.ord = cur_max_read_depth(ep->com.dev);
1249 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301250 event.private_data_len = ep->plen;
1251 event.private_data = ep->mpa_pkt +
1252 sizeof(struct mpa_message);
1253 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001254 }
Roland Dreier85963e42010-07-19 13:13:09 -07001255
1256 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1257 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001258 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001259 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1260
Steve Wisecfdda9d2010-04-21 15:30:06 -07001261 if (status < 0) {
1262 ep->com.cm_id->rem_ref(ep->com.cm_id);
1263 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001264 }
1265}
1266
Steve Wisebe13b2d2014-03-21 20:40:33 +05301267static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001268{
1269 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301270 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001271
1272 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1273 memset(&event, 0, sizeof(event));
1274 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301275 memcpy(&event.local_addr, &ep->com.local_addr,
1276 sizeof(ep->com.local_addr));
1277 memcpy(&event.remote_addr, &ep->com.remote_addr,
1278 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001279 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301280 if (!ep->tried_with_mpa_v1) {
1281 /* this means MPA_v2 is used */
1282 event.ord = ep->ord;
1283 event.ird = ep->ird;
1284 event.private_data_len = ep->plen -
1285 sizeof(struct mpa_v2_conn_params);
1286 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1287 sizeof(struct mpa_v2_conn_params);
1288 } else {
1289 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301290 event.ord = cur_max_read_depth(ep->com.dev);
1291 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301292 event.private_data_len = ep->plen;
1293 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1294 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301295 c4iw_get_ep(&ep->com);
1296 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1297 &event);
1298 if (ret)
1299 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001300 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001301 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301302 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001303}
1304
1305static void established_upcall(struct c4iw_ep *ep)
1306{
1307 struct iw_cm_event event;
1308
1309 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1310 memset(&event, 0, sizeof(event));
1311 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301312 event.ird = ep->ord;
1313 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001314 if (ep->com.cm_id) {
1315 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1316 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001317 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001318 }
1319}
1320
1321static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1322{
1323 struct cpl_rx_data_ack *req;
1324 struct sk_buff *skb;
1325 int wrlen = roundup(sizeof *req, 16);
1326
1327 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1328 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1329 if (!skb) {
1330 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1331 return 0;
1332 }
1333
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301334 /*
1335 * If we couldn't specify the entire rcv window at connection setup
1336 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1337 * then add the overage in to the credits returned.
1338 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001339 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1340 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301341
Steve Wisecfdda9d2010-04-21 15:30:06 -07001342 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1343 memset(req, 0, wrlen);
1344 INIT_TP_WR(req, ep->hwtid);
1345 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1346 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001347 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301348 RX_DACK_CHANGE_F |
1349 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001350 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001351 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1352 return credits;
1353}
1354
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301355#define RELAXED_IRD_NEGOTIATION 1
1356
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301357/*
1358 * process_mpa_reply - process streaming mode MPA reply
1359 *
1360 * Returns:
1361 *
1362 * 0 upon success indicating a connect request was delivered to the ULP
1363 * or the mpa request is incomplete but valid so far.
1364 *
1365 * 1 if a failure requires the caller to close the connection.
1366 *
1367 * 2 if a failure requires the caller to abort the connection.
1368 */
Steve Wisecc18b932014-04-24 14:31:53 -05001369static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001370{
1371 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301372 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001373 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301374 u16 resp_ird, resp_ord;
1375 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001376 struct c4iw_qp_attributes attrs;
1377 enum c4iw_qp_attr_mask mask;
1378 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001379 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001380
1381 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1382
1383 /*
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001384 * Stop mpa timer. If it expired, then
1385 * we ignore the MPA reply. process_timeout()
1386 * will abort the connection.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001387 */
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001388 if (stop_ep_timer(ep))
Steve Wisecc18b932014-04-24 14:31:53 -05001389 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001390
1391 /*
1392 * If we get more than the supported amount of private data
1393 * then we must fail this connection.
1394 */
1395 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1396 err = -EINVAL;
1397 goto err;
1398 }
1399
1400 /*
1401 * copy the new data into our accumulation buffer.
1402 */
1403 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1404 skb->len);
1405 ep->mpa_pkt_len += skb->len;
1406
1407 /*
1408 * if we don't even have the mpa message, then bail.
1409 */
1410 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001411 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001412 mpa = (struct mpa_message *) ep->mpa_pkt;
1413
1414 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301415 if (mpa->revision > mpa_rev) {
1416 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1417 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001418 err = -EPROTO;
1419 goto err;
1420 }
1421 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1422 err = -EPROTO;
1423 goto err;
1424 }
1425
1426 plen = ntohs(mpa->private_data_size);
1427
1428 /*
1429 * Fail if there's too much private data.
1430 */
1431 if (plen > MPA_MAX_PRIVATE_DATA) {
1432 err = -EPROTO;
1433 goto err;
1434 }
1435
1436 /*
1437 * If plen does not account for pkt size
1438 */
1439 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1440 err = -EPROTO;
1441 goto err;
1442 }
1443
1444 ep->plen = (u8) plen;
1445
1446 /*
1447 * If we don't have all the pdata yet, then bail.
1448 * We'll continue process when more data arrives.
1449 */
1450 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001451 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001452
1453 if (mpa->flags & MPA_REJECT) {
1454 err = -ECONNREFUSED;
1455 goto err;
1456 }
1457
1458 /*
1459 * If we get here we have accumulated the entire mpa
1460 * start reply message including private data. And
1461 * the MPA header is valid.
1462 */
Steve Wisec529fb52014-03-21 20:40:37 +05301463 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001464 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1465 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1466 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301467 ep->mpa_attr.version = mpa->revision;
1468 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1469
1470 if (mpa->revision == 2) {
1471 ep->mpa_attr.enhanced_rdma_conn =
1472 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1473 if (ep->mpa_attr.enhanced_rdma_conn) {
1474 mpa_v2_params = (struct mpa_v2_conn_params *)
1475 (ep->mpa_pkt + sizeof(*mpa));
1476 resp_ird = ntohs(mpa_v2_params->ird) &
1477 MPA_V2_IRD_ORD_MASK;
1478 resp_ord = ntohs(mpa_v2_params->ord) &
1479 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301480 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1481 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301482
1483 /*
1484 * This is a double-check. Ideally, below checks are
1485 * not required since ird/ord stuff has been taken
1486 * care of in c4iw_accept_cr
1487 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301488 if (ep->ird < resp_ord) {
1489 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1490 ep->com.dev->rdev.lldi.max_ordird_qp)
1491 ep->ird = resp_ord;
1492 else
1493 insuff_ird = 1;
1494 } else if (ep->ird > resp_ord) {
1495 ep->ird = resp_ord;
1496 }
1497 if (ep->ord > resp_ird) {
1498 if (RELAXED_IRD_NEGOTIATION)
1499 ep->ord = resp_ird;
1500 else
1501 insuff_ird = 1;
1502 }
1503 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301504 err = -ENOMEM;
1505 ep->ird = resp_ord;
1506 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301507 }
1508
1509 if (ntohs(mpa_v2_params->ird) &
1510 MPA_V2_PEER2PEER_MODEL) {
1511 if (ntohs(mpa_v2_params->ord) &
1512 MPA_V2_RDMA_WRITE_RTR)
1513 ep->mpa_attr.p2p_type =
1514 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1515 else if (ntohs(mpa_v2_params->ord) &
1516 MPA_V2_RDMA_READ_RTR)
1517 ep->mpa_attr.p2p_type =
1518 FW_RI_INIT_P2PTYPE_READ_REQ;
1519 }
1520 }
1521 } else if (mpa->revision == 1)
1522 if (peer2peer)
1523 ep->mpa_attr.p2p_type = p2p_type;
1524
Steve Wisecfdda9d2010-04-21 15:30:06 -07001525 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301526 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1527 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1528 ep->mpa_attr.recv_marker_enabled,
1529 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1530 ep->mpa_attr.p2p_type, p2p_type);
1531
1532 /*
1533 * If responder's RTR does not match with that of initiator, assign
1534 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1535 * generated when moving QP to RTS state.
1536 * A TERM message will be sent after QP has moved to RTS state
1537 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001538 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301539 (ep->mpa_attr.p2p_type != p2p_type)) {
1540 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1541 rtr_mismatch = 1;
1542 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001543
1544 attrs.mpa_attr = ep->mpa_attr;
1545 attrs.max_ird = ep->ird;
1546 attrs.max_ord = ep->ord;
1547 attrs.llp_stream_handle = ep;
1548 attrs.next_state = C4IW_QP_STATE_RTS;
1549
1550 mask = C4IW_QP_ATTR_NEXT_STATE |
1551 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1552 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1553
1554 /* bind QP and TID with INIT_WR */
1555 err = c4iw_modify_qp(ep->com.qp->rhp,
1556 ep->com.qp, mask, &attrs, 1);
1557 if (err)
1558 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301559
1560 /*
1561 * If responder's RTR requirement did not match with what initiator
1562 * supports, generate TERM message
1563 */
1564 if (rtr_mismatch) {
1565 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1566 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1567 attrs.ecode = MPA_NOMATCH_RTR;
1568 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001569 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301570 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001571 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301572 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001573 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301574 goto out;
1575 }
1576
1577 /*
1578 * Generate TERM if initiator IRD is not sufficient for responder
1579 * provided ORD. Currently, we do the same behaviour even when
1580 * responder provided IRD is also not sufficient as regards to
1581 * initiator ORD.
1582 */
1583 if (insuff_ird) {
1584 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1585 __func__);
1586 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1587 attrs.ecode = MPA_INSUFF_IRD;
1588 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001589 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301590 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001591 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301592 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001593 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301594 goto out;
1595 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001596 goto out;
1597err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301598 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001599out:
1600 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001601 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001602}
1603
1604static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1605{
1606 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301607 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001608 u16 plen;
1609
1610 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1611
Steve Wisecfdda9d2010-04-21 15:30:06 -07001612 /*
1613 * If we get more than the supported amount of private data
1614 * then we must fail this connection.
1615 */
1616 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001617 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001618 abort_connection(ep, skb, GFP_KERNEL);
1619 return;
1620 }
1621
1622 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1623
1624 /*
1625 * Copy the new data into our accumulation buffer.
1626 */
1627 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1628 skb->len);
1629 ep->mpa_pkt_len += skb->len;
1630
1631 /*
1632 * If we don't even have the mpa message, then bail.
1633 * We'll continue process when more data arrives.
1634 */
1635 if (ep->mpa_pkt_len < sizeof(*mpa))
1636 return;
1637
1638 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001639 mpa = (struct mpa_message *) ep->mpa_pkt;
1640
1641 /*
1642 * Validate MPA Header.
1643 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301644 if (mpa->revision > mpa_rev) {
1645 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1646 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001647 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001648 abort_connection(ep, skb, GFP_KERNEL);
1649 return;
1650 }
1651
1652 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001653 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001654 abort_connection(ep, skb, GFP_KERNEL);
1655 return;
1656 }
1657
1658 plen = ntohs(mpa->private_data_size);
1659
1660 /*
1661 * Fail if there's too much private data.
1662 */
1663 if (plen > MPA_MAX_PRIVATE_DATA) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001664 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001665 abort_connection(ep, skb, GFP_KERNEL);
1666 return;
1667 }
1668
1669 /*
1670 * If plen does not account for pkt size
1671 */
1672 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001673 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001674 abort_connection(ep, skb, GFP_KERNEL);
1675 return;
1676 }
1677 ep->plen = (u8) plen;
1678
1679 /*
1680 * If we don't have all the pdata yet, then bail.
1681 */
1682 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1683 return;
1684
1685 /*
1686 * If we get here we have accumulated the entire mpa
1687 * start reply message including private data.
1688 */
1689 ep->mpa_attr.initiator = 0;
1690 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1691 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1692 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301693 ep->mpa_attr.version = mpa->revision;
1694 if (mpa->revision == 1)
1695 ep->tried_with_mpa_v1 = 1;
1696 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1697
1698 if (mpa->revision == 2) {
1699 ep->mpa_attr.enhanced_rdma_conn =
1700 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1701 if (ep->mpa_attr.enhanced_rdma_conn) {
1702 mpa_v2_params = (struct mpa_v2_conn_params *)
1703 (ep->mpa_pkt + sizeof(*mpa));
1704 ep->ird = ntohs(mpa_v2_params->ird) &
1705 MPA_V2_IRD_ORD_MASK;
1706 ep->ord = ntohs(mpa_v2_params->ord) &
1707 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301708 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1709 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301710 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1711 if (peer2peer) {
1712 if (ntohs(mpa_v2_params->ord) &
1713 MPA_V2_RDMA_WRITE_RTR)
1714 ep->mpa_attr.p2p_type =
1715 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1716 else if (ntohs(mpa_v2_params->ord) &
1717 MPA_V2_RDMA_READ_RTR)
1718 ep->mpa_attr.p2p_type =
1719 FW_RI_INIT_P2PTYPE_READ_REQ;
1720 }
1721 }
1722 } else if (mpa->revision == 1)
1723 if (peer2peer)
1724 ep->mpa_attr.p2p_type = p2p_type;
1725
Steve Wisecfdda9d2010-04-21 15:30:06 -07001726 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1727 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1728 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1729 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1730 ep->mpa_attr.p2p_type);
1731
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001732 /*
1733 * If the endpoint timer already expired, then we ignore
1734 * the start request. process_timeout() will abort
1735 * the connection.
1736 */
1737 if (!stop_ep_timer(ep)) {
1738 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001739
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001740 /* drive upcall */
Hariprasad Shenai10be6b42014-11-21 09:36:35 -06001741 mutex_lock_nested(&ep->parent_ep->com.mutex,
1742 SINGLE_DEPTH_NESTING);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001743 if (ep->parent_ep->com.state != DEAD) {
1744 if (connect_request_upcall(ep))
1745 abort_connection(ep, skb, GFP_KERNEL);
1746 } else {
Steve Wisebe13b2d2014-03-21 20:40:33 +05301747 abort_connection(ep, skb, GFP_KERNEL);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001748 }
1749 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301750 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001751 return;
1752}
1753
1754static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1755{
1756 struct c4iw_ep *ep;
1757 struct cpl_rx_data *hdr = cplhdr(skb);
1758 unsigned int dlen = ntohs(hdr->len);
1759 unsigned int tid = GET_TID(hdr);
1760 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001761 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001762 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001763
1764 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301765 if (!ep)
1766 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001767 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1768 skb_pull(skb, sizeof(*hdr));
1769 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301770 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001771
Steve Wisecfdda9d2010-04-21 15:30:06 -07001772 /* update RX credits */
1773 update_rx_credits(ep, dlen);
1774
Steve Wisec529fb52014-03-21 20:40:37 +05301775 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001776 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001777 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001778 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001779 break;
1780 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001781 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001782 process_mpa_request(ep, skb);
1783 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001784 case FPDU_MODE: {
1785 struct c4iw_qp_attributes attrs;
1786 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001787 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001788 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001789 " qpid %u ep %p state %d tid %u status %d\n",
1790 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301791 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301792 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001793 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001794 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1795 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001796 break;
1797 }
Vipul Pandya15579672013-01-07 13:11:52 +00001798 default:
1799 break;
1800 }
Steve Wisec529fb52014-03-21 20:40:37 +05301801 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001802 if (disconnect)
1803 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001804 return 0;
1805}
1806
1807static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1808{
1809 struct c4iw_ep *ep;
1810 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001811 int release = 0;
1812 unsigned int tid = GET_TID(rpl);
1813 struct tid_info *t = dev->rdev.lldi.tids;
1814
1815 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301816 if (!ep) {
1817 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1818 return 0;
1819 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001820 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001821 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001822 switch (ep->com.state) {
1823 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001824 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001825 __state_set(&ep->com, DEAD);
1826 release = 1;
1827 break;
1828 default:
1829 printk(KERN_ERR "%s ep %p state %d\n",
1830 __func__, ep, ep->com.state);
1831 break;
1832 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001833 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001834
1835 if (release)
1836 release_ep_resources(ep);
1837 return 0;
1838}
1839
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001840static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1841{
1842 struct sk_buff *skb;
1843 struct fw_ofld_connection_wr *req;
1844 unsigned int mtu_idx;
1845 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301846 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301847 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001848
1849 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1850 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1851 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001852 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301853 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301854 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1855 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001856 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001857 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301858 req->le.lport = sin->sin_port;
1859 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001860 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301861 req->le.pport = sin->sin_port;
1862 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001863 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301864 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1865 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001866 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301867 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001868 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001869 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301870 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301871 enable_tcp_timestamps,
1872 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001873 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301874
1875 /*
1876 * Specify the largest window that will fit in opt0. The
1877 * remainder will be specified in the rx_data_ack.
1878 */
1879 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001880 if (win > RCV_BUFSIZ_M)
1881 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301882
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001883 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1884 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001885 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001886 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001887 WND_SCALE_V(wscale) |
1888 MSS_IDX_V(mtu_idx) |
1889 L2T_IDX_V(ep->l2t->idx) |
1890 TX_CHAN_V(ep->tx_chan) |
1891 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301892 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001893 ULP_MODE_V(ULP_MODE_TCPDDP) |
1894 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001895 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1896 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001897 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001898 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001899 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001900 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001901 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001902 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001903 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001904 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001905 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1906 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1907 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001908 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1909 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001910 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1911}
1912
Steve Wisecfdda9d2010-04-21 15:30:06 -07001913/*
1914 * Return whether a failed active open has allocated a TID
1915 */
1916static inline int act_open_has_tid(int status)
1917{
1918 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1919 status != CPL_ERR_ARP_MISS;
1920}
1921
Steve Wise7a2cea22014-03-14 21:52:07 +05301922/* Returns whether a CPL status conveys negative advice.
1923 */
1924static int is_neg_adv(unsigned int status)
1925{
1926 return status == CPL_ERR_RTX_NEG_ADVICE ||
1927 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1928 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1929}
1930
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301931static char *neg_adv_str(unsigned int status)
1932{
1933 switch (status) {
1934 case CPL_ERR_RTX_NEG_ADVICE:
1935 return "Retransmit timeout";
1936 case CPL_ERR_PERSIST_NEG_ADVICE:
1937 return "Persist timeout";
1938 case CPL_ERR_KEEPALV_NEG_ADVICE:
1939 return "Keepalive timeout";
1940 default:
1941 return "Unknown";
1942 }
1943}
1944
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301945static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1946{
1947 ep->snd_win = snd_win;
1948 ep->rcv_win = rcv_win;
1949 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1950}
1951
Vipul Pandya793dad92012-12-10 09:30:56 +00001952#define ACT_OPEN_RETRY_COUNT 2
1953
Vipul Pandya830662f2013-07-04 16:10:47 +05301954static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1955 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301956 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05301957{
1958 struct neighbour *n;
1959 int err, step;
1960 struct net_device *pdev;
1961
1962 n = dst_neigh_lookup(dst, peer_ip);
1963 if (!n)
1964 return -ENODEV;
1965
1966 rcu_read_lock();
1967 err = -ENOMEM;
1968 if (n->dev->flags & IFF_LOOPBACK) {
1969 if (iptype == 4)
1970 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1971 else if (IS_ENABLED(CONFIG_IPV6))
1972 for_each_netdev(&init_net, pdev) {
1973 if (ipv6_chk_addr(&init_net,
1974 (struct in6_addr *)peer_ip,
1975 pdev, 1))
1976 break;
1977 }
1978 else
1979 pdev = NULL;
1980
1981 if (!pdev) {
1982 err = -ENODEV;
1983 goto out;
1984 }
1985 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301986 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05301987 if (!ep->l2t)
1988 goto out;
1989 ep->mtu = pdev->mtu;
1990 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05301991 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
1992 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301993 step = cdev->rdev.lldi.ntxq /
1994 cdev->rdev.lldi.nchan;
1995 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1996 step = cdev->rdev.lldi.nrxq /
1997 cdev->rdev.lldi.nchan;
1998 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1999 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2000 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302001 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302002 dev_put(pdev);
2003 } else {
2004 pdev = get_real_dev(n->dev);
2005 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2006 n, pdev, 0);
2007 if (!ep->l2t)
2008 goto out;
2009 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002010 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302011 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2012 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302013 step = cdev->rdev.lldi.ntxq /
2014 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002015 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2016 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302017 step = cdev->rdev.lldi.nrxq /
2018 cdev->rdev.lldi.nchan;
2019 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002020 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302021 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302022
2023 if (clear_mpa_v1) {
2024 ep->retry_with_mpa_v1 = 0;
2025 ep->tried_with_mpa_v1 = 0;
2026 }
2027 }
2028 err = 0;
2029out:
2030 rcu_read_unlock();
2031
2032 neigh_release(n);
2033
2034 return err;
2035}
2036
Vipul Pandya793dad92012-12-10 09:30:56 +00002037static int c4iw_reconnect(struct c4iw_ep *ep)
2038{
2039 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302040 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002041 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302042 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002043 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302044 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002045 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302046 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002047 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302048 int iptype;
2049 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002050
2051 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2052 init_timer(&ep->timer);
2053
2054 /*
2055 * Allocate an active TID to initiate a TCP connection.
2056 */
2057 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2058 if (ep->atid == -1) {
2059 pr_err("%s - cannot alloc atid.\n", __func__);
2060 err = -ENOMEM;
2061 goto fail2;
2062 }
2063 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2064
2065 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002066 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302067 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2068 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302069 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302070 iptype = 4;
2071 ra = (__u8 *)&raddr->sin_addr;
2072 } else {
2073 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2074 raddr6->sin6_addr.s6_addr,
2075 laddr6->sin6_port, raddr6->sin6_port, 0,
2076 raddr6->sin6_scope_id);
2077 iptype = 6;
2078 ra = (__u8 *)&raddr6->sin6_addr;
2079 }
2080 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002081 pr_err("%s - cannot find route.\n", __func__);
2082 err = -EHOSTUNREACH;
2083 goto fail3;
2084 }
Hariprasad S963cab52015-09-23 17:19:27 +05302085 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302086 ep->com.dev->rdev.lldi.adapter_type,
2087 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302088 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002089 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002090 goto fail4;
2091 }
2092
2093 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2094 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2095 ep->l2t->idx);
2096
2097 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302098 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002099
2100 /* send connect request to rnic */
2101 err = send_connect(ep);
2102 if (!err)
2103 goto out;
2104
2105 cxgb4_l2t_release(ep->l2t);
2106fail4:
2107 dst_release(ep->dst);
2108fail3:
2109 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2110 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2111fail2:
2112 /*
2113 * remember to send notification to upper layer.
2114 * We are in here so the upper layer is not aware that this is
2115 * re-connect attempt and so, upper layer is still waiting for
2116 * response of 1st connect request.
2117 */
2118 connect_reply_upcall(ep, -ECONNRESET);
2119 c4iw_put_ep(&ep->com);
2120out:
2121 return err;
2122}
2123
Steve Wisecfdda9d2010-04-21 15:30:06 -07002124static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2125{
2126 struct c4iw_ep *ep;
2127 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002128 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2129 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002130 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002131 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302132 struct sockaddr_in *la;
2133 struct sockaddr_in *ra;
2134 struct sockaddr_in6 *la6;
2135 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002136
2137 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002138 la = (struct sockaddr_in *)&ep->com.local_addr;
2139 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2140 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2141 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002142
2143 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2144 status, status2errno(status));
2145
Steve Wise7a2cea22014-03-14 21:52:07 +05302146 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302147 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2148 __func__, atid, status, neg_adv_str(status));
2149 ep->stats.connect_neg_adv++;
2150 mutex_lock(&dev->rdev.stats.lock);
2151 dev->rdev.stats.neg_adv++;
2152 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002153 return 0;
2154 }
2155
Vipul Pandya793dad92012-12-10 09:30:56 +00002156 set_bit(ACT_OPEN_RPL, &ep->com.history);
2157
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302158 /*
2159 * Log interesting failures.
2160 */
2161 switch (status) {
2162 case CPL_ERR_CONN_RESET:
2163 case CPL_ERR_CONN_TIMEDOUT:
2164 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002165 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302166 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002167 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302168 mutex_unlock(&dev->rdev.stats.lock);
2169 if (ep->com.local_addr.ss_family == AF_INET &&
2170 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002171 send_fw_act_open_req(ep,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002172 TID_TID_G(AOPEN_ATID_G(
Vipul Pandya793dad92012-12-10 09:30:56 +00002173 ntohl(rpl->atid_status))));
2174 return 0;
2175 }
2176 break;
2177 case CPL_ERR_CONN_EXIST:
2178 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2179 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302180 if (ep->com.remote_addr.ss_family == AF_INET6) {
2181 struct sockaddr_in6 *sin6 =
2182 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002183 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302184 cxgb4_clip_release(
2185 ep->com.dev->rdev.lldi.ports[0],
2186 (const u32 *)
2187 &sin6->sin6_addr.s6_addr, 1);
2188 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002189 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2190 atid);
2191 cxgb4_free_atid(t, atid);
2192 dst_release(ep->dst);
2193 cxgb4_l2t_release(ep->l2t);
2194 c4iw_reconnect(ep);
2195 return 0;
2196 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002197 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302198 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302199 if (ep->com.local_addr.ss_family == AF_INET) {
2200 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2201 atid, status, status2errno(status),
2202 &la->sin_addr.s_addr, ntohs(la->sin_port),
2203 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2204 } else {
2205 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2206 atid, status, status2errno(status),
2207 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2208 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2209 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302210 break;
2211 }
2212
Steve Wisecfdda9d2010-04-21 15:30:06 -07002213 connect_reply_upcall(ep, status2errno(status));
2214 state_set(&ep->com, DEAD);
2215
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302216 if (ep->com.remote_addr.ss_family == AF_INET6) {
2217 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002218 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302219 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2220 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2221 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002222 if (status && act_open_has_tid(status))
2223 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2224
Vipul Pandya793dad92012-12-10 09:30:56 +00002225 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002226 cxgb4_free_atid(t, atid);
2227 dst_release(ep->dst);
2228 cxgb4_l2t_release(ep->l2t);
2229 c4iw_put_ep(&ep->com);
2230
2231 return 0;
2232}
2233
2234static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2235{
2236 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2237 struct tid_info *t = dev->rdev.lldi.tids;
2238 unsigned int stid = GET_TID(rpl);
2239 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2240
2241 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002242 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2243 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002244 }
2245 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2246 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002247 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002248
Vipul Pandya1cab7752012-12-10 09:30:55 +00002249out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002250 return 0;
2251}
2252
Steve Wisecfdda9d2010-04-21 15:30:06 -07002253static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2254{
2255 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2256 struct tid_info *t = dev->rdev.lldi.tids;
2257 unsigned int stid = GET_TID(rpl);
2258 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2259
2260 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002261 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002262 return 0;
2263}
2264
Hariprasad S9dec9002016-05-05 01:27:29 +05302265static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2266 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002267{
2268 struct cpl_pass_accept_rpl *rpl;
2269 unsigned int mtu_idx;
2270 u64 opt0;
2271 u32 opt2;
2272 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302273 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302274 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302275 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002276
2277 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2278 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302279
Steve Wisecfdda9d2010-04-21 15:30:06 -07002280 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302281 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302282 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302283 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2284 rpl5 = (void *)rpl;
2285 INIT_TP_WR(rpl5, ep->hwtid);
2286 } else {
2287 skb_trim(skb, sizeof(*rpl));
2288 INIT_TP_WR(rpl, ep->hwtid);
2289 }
2290 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2291 ep->hwtid));
2292
2293 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302294 enable_tcp_timestamps && req->tcpopt.tstamp,
2295 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002296 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302297
2298 /*
2299 * Specify the largest window that will fit in opt0. The
2300 * remainder will be specified in the rx_data_ack.
2301 */
2302 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002303 if (win > RCV_BUFSIZ_M)
2304 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002305 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002306 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002307 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002308 WND_SCALE_V(wscale) |
2309 MSS_IDX_V(mtu_idx) |
2310 L2T_IDX_V(ep->l2t->idx) |
2311 TX_CHAN_V(ep->tx_chan) |
2312 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002313 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002314 ULP_MODE_V(ULP_MODE_TCPDDP) |
2315 RCV_BUFSIZ_V(win);
2316 opt2 = RX_CHANNEL_V(0) |
2317 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002318
2319 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002320 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002321 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002322 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002323 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002324 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002325 if (enable_ecn) {
2326 const struct tcphdr *tcph;
2327 u32 hlen = ntohl(req->hdr_len);
2328
Hariprasad S963cab52015-09-23 17:19:27 +05302329 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2330 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2331 IP_HDR_LEN_G(hlen);
2332 else
2333 tcph = (const void *)(req + 1) +
2334 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002335 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002336 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002337 }
Hariprasad S963cab52015-09-23 17:19:27 +05302338 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302339 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002340 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302341 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302342 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302343 rpl5 = (void *)rpl;
2344 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2345 if (peer2peer)
2346 isn += 4;
2347 rpl5->iss = cpu_to_be32(isn);
2348 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002349 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002350
Steve Wisecfdda9d2010-04-21 15:30:06 -07002351 rpl->opt0 = cpu_to_be64(opt0);
2352 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002353 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302354 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002355
Hariprasad S9dec9002016-05-05 01:27:29 +05302356 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002357}
2358
Vipul Pandya830662f2013-07-04 16:10:47 +05302359static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002360{
Vipul Pandya830662f2013-07-04 16:10:47 +05302361 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002362 BUG_ON(skb_cloned(skb));
2363 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002364 release_tid(&dev->rdev, hwtid, skb);
2365 return;
2366}
2367
Hariprasad S963cab52015-09-23 17:19:27 +05302368static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2369 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002370 __be16 *local_port, __be16 *peer_port)
2371{
Hariprasad S963cab52015-09-23 17:19:27 +05302372 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2373 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2374 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2375 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2376 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2377 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002378 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302379 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002380 struct tcphdr *tcp = (struct tcphdr *)
2381 ((u8 *)(req + 1) + eth_len + ip_len);
2382
Vipul Pandya830662f2013-07-04 16:10:47 +05302383 if (ip->version == 4) {
2384 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2385 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2386 ntohs(tcp->dest));
2387 *iptype = 4;
2388 memcpy(peer_ip, &ip->saddr, 4);
2389 memcpy(local_ip, &ip->daddr, 4);
2390 } else {
2391 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2392 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2393 ntohs(tcp->dest));
2394 *iptype = 6;
2395 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2396 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2397 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002398 *peer_port = tcp->source;
2399 *local_port = tcp->dest;
2400
2401 return;
2402}
2403
2404static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2405{
Vipul Pandya793dad92012-12-10 09:30:56 +00002406 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002407 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002408 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002409 struct tid_info *t = dev->rdev.lldi.tids;
2410 unsigned int hwtid = GET_TID(req);
2411 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302412 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002413 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302414 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002415 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002416 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302417 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302418 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302419 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002420
2421 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002422 if (!parent_ep) {
2423 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2424 goto reject;
2425 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002426
Steve Wisecfdda9d2010-04-21 15:30:06 -07002427 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302428 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002429 goto reject;
2430 }
2431
Hariprasad S963cab52015-09-23 17:19:27 +05302432 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2433 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302434
Steve Wisecfdda9d2010-04-21 15:30:06 -07002435 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302436 if (iptype == 4) {
2437 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2438 , __func__, parent_ep, hwtid,
2439 local_ip, peer_ip, ntohs(local_port),
2440 ntohs(peer_port), peer_mss);
2441 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2442 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302443 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302444 } else {
2445 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2446 , __func__, parent_ep, hwtid,
2447 local_ip, peer_ip, ntohs(local_port),
2448 ntohs(peer_port), peer_mss);
2449 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002450 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302451 ((struct sockaddr_in6 *)
2452 &parent_ep->com.local_addr)->sin6_scope_id);
2453 }
2454 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002455 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2456 __func__);
2457 goto reject;
2458 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002459
2460 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2461 if (!child_ep) {
2462 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2463 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002464 dst_release(dst);
2465 goto reject;
2466 }
David Miller3786cf12011-12-02 16:52:31 +00002467
Hariprasad S963cab52015-09-23 17:19:27 +05302468 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302469 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002470 if (err) {
2471 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2472 __func__);
2473 dst_release(dst);
2474 kfree(child_ep);
2475 goto reject;
2476 }
2477
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302478 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2479 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2480 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2481 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002482
Steve Wisecfdda9d2010-04-21 15:30:06 -07002483 state_set(&child_ep->com, CONNECTING);
2484 child_ep->com.dev = dev;
2485 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002486
Vipul Pandya830662f2013-07-04 16:10:47 +05302487 if (iptype == 4) {
2488 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002489 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002490
Vipul Pandya830662f2013-07-04 16:10:47 +05302491 sin->sin_family = PF_INET;
2492 sin->sin_port = local_port;
2493 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002494
2495 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2496 sin->sin_family = PF_INET;
2497 sin->sin_port = ((struct sockaddr_in *)
2498 &parent_ep->com.local_addr)->sin_port;
2499 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2500
Steve Wise170003c2016-02-26 09:18:03 -06002501 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302502 sin->sin_family = PF_INET;
2503 sin->sin_port = peer_port;
2504 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2505 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002506 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302507 sin6->sin6_family = PF_INET6;
2508 sin6->sin6_port = local_port;
2509 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002510
2511 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2512 sin6->sin6_family = PF_INET6;
2513 sin6->sin6_port = ((struct sockaddr_in6 *)
2514 &parent_ep->com.local_addr)->sin6_port;
2515 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2516
Steve Wise170003c2016-02-26 09:18:03 -06002517 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302518 sin6->sin6_family = PF_INET6;
2519 sin6->sin6_port = peer_port;
2520 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2521 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002522
Steve Wisecfdda9d2010-04-21 15:30:06 -07002523 c4iw_get_ep(&parent_ep->com);
2524 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302525 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002526 child_ep->dst = dst;
2527 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002528
2529 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002530 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002531
2532 init_timer(&child_ep->timer);
2533 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002534 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Hariprasad S9dec9002016-05-05 01:27:29 +05302535 if (accept_cr(child_ep, skb, req)) {
2536 c4iw_put_ep(&parent_ep->com);
2537 release_ep_resources(child_ep);
2538 } else {
2539 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2540 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302541 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002542 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302543 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2544 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2545 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002546 goto out;
2547reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302548 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002549out:
2550 return 0;
2551}
2552
2553static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2554{
2555 struct c4iw_ep *ep;
2556 struct cpl_pass_establish *req = cplhdr(skb);
2557 struct tid_info *t = dev->rdev.lldi.tids;
2558 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302559 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002560
2561 ep = lookup_tid(t, tid);
2562 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2563 ep->snd_seq = be32_to_cpu(req->snd_isn);
2564 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2565
Vipul Pandya1cab7752012-12-10 09:30:55 +00002566 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2567 ntohs(req->tcp_opt));
2568
Steve Wisecfdda9d2010-04-21 15:30:06 -07002569 set_emss(ep, ntohs(req->tcp_opt));
2570
2571 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302572 mutex_lock(&ep->com.mutex);
2573 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002574 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002575 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad Sfef44222016-05-05 01:27:33 +05302576 ret = send_flowc(ep, skb);
2577 mutex_unlock(&ep->com.mutex);
2578 if (ret)
2579 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002580
2581 return 0;
2582}
2583
2584static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2585{
2586 struct cpl_peer_close *hdr = cplhdr(skb);
2587 struct c4iw_ep *ep;
2588 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002589 int disconnect = 1;
2590 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002591 struct tid_info *t = dev->rdev.lldi.tids;
2592 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002593 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002594
2595 ep = lookup_tid(t, tid);
2596 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2597 dst_confirm(ep->dst);
2598
Vipul Pandya793dad92012-12-10 09:30:56 +00002599 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002600 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002601 switch (ep->com.state) {
2602 case MPA_REQ_WAIT:
2603 __state_set(&ep->com, CLOSING);
2604 break;
2605 case MPA_REQ_SENT:
2606 __state_set(&ep->com, CLOSING);
2607 connect_reply_upcall(ep, -ECONNRESET);
2608 break;
2609 case MPA_REQ_RCVD:
2610
2611 /*
2612 * We're gonna mark this puppy DEAD, but keep
2613 * the reference on it until the ULP accepts or
2614 * rejects the CR. Also wake up anyone waiting
2615 * in rdma connection migration (see c4iw_accept_cr()).
2616 */
2617 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002618 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002619 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002620 break;
2621 case MPA_REP_SENT:
2622 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002623 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002624 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002625 break;
2626 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002627 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002628 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002629 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002630 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002631 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002632 if (ret != -ECONNRESET) {
2633 peer_close_upcall(ep);
2634 disconnect = 1;
2635 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002636 break;
2637 case ABORTING:
2638 disconnect = 0;
2639 break;
2640 case CLOSING:
2641 __state_set(&ep->com, MORIBUND);
2642 disconnect = 0;
2643 break;
2644 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002645 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002646 if (ep->com.cm_id && ep->com.qp) {
2647 attrs.next_state = C4IW_QP_STATE_IDLE;
2648 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2649 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2650 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302651 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002652 __state_set(&ep->com, DEAD);
2653 release = 1;
2654 disconnect = 0;
2655 break;
2656 case DEAD:
2657 disconnect = 0;
2658 break;
2659 default:
2660 BUG_ON(1);
2661 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002662 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002663 if (disconnect)
2664 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2665 if (release)
2666 release_ep_resources(ep);
2667 return 0;
2668}
2669
Steve Wisecfdda9d2010-04-21 15:30:06 -07002670static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2671{
2672 struct cpl_abort_req_rss *req = cplhdr(skb);
2673 struct c4iw_ep *ep;
2674 struct cpl_abort_rpl *rpl;
2675 struct sk_buff *rpl_skb;
2676 struct c4iw_qp_attributes attrs;
2677 int ret;
2678 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002679 struct tid_info *t = dev->rdev.lldi.tids;
2680 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002681
2682 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302683 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302684 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2685 __func__, ep->hwtid, req->status,
2686 neg_adv_str(req->status));
2687 ep->stats.abort_neg_adv++;
2688 mutex_lock(&dev->rdev.stats.lock);
2689 dev->rdev.stats.neg_adv++;
2690 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002691 return 0;
2692 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002693 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2694 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002695 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002696
2697 /*
2698 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302699 * However, this is not needed if com state is just
2700 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002701 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302702 if (ep->com.state != MPA_REQ_SENT)
2703 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002704
2705 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002706 switch (ep->com.state) {
2707 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302708 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002709 break;
2710 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002711 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002712 break;
2713 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002714 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002715 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302716 connect_reply_upcall(ep, -ECONNRESET);
2717 else {
2718 /*
2719 * we just don't send notification upwards because we
2720 * want to retry with mpa_v1 without upper layers even
2721 * knowing it.
2722 *
2723 * do some housekeeping so as to re-initiate the
2724 * connection
2725 */
2726 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2727 mpa_rev);
2728 ep->retry_with_mpa_v1 = 1;
2729 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002730 break;
2731 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002732 break;
2733 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002734 break;
2735 case MORIBUND:
2736 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002737 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002738 /*FALLTHROUGH*/
2739 case FPDU_MODE:
2740 if (ep->com.cm_id && ep->com.qp) {
2741 attrs.next_state = C4IW_QP_STATE_ERROR;
2742 ret = c4iw_modify_qp(ep->com.qp->rhp,
2743 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2744 &attrs, 1);
2745 if (ret)
2746 printk(KERN_ERR MOD
2747 "%s - qp <- error failed!\n",
2748 __func__);
2749 }
2750 peer_abort_upcall(ep);
2751 break;
2752 case ABORTING:
2753 break;
2754 case DEAD:
2755 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002756 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002757 return 0;
2758 default:
2759 BUG_ON(1);
2760 break;
2761 }
2762 dst_confirm(ep->dst);
2763 if (ep->com.state != ABORTING) {
2764 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302765 /* we don't release if we want to retry with mpa_v1 */
2766 if (!ep->retry_with_mpa_v1)
2767 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002768 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002769 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002770
2771 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2772 if (!rpl_skb) {
2773 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2774 __func__);
2775 release = 1;
2776 goto out;
2777 }
2778 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2779 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2780 INIT_TP_WR(rpl, ep->hwtid);
2781 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2782 rpl->cmd = CPL_ABORT_NO_RST;
2783 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2784out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002785 if (release)
2786 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002787 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302788 if (ep->com.remote_addr.ss_family == AF_INET6) {
2789 struct sockaddr_in6 *sin6 =
2790 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002791 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302792 cxgb4_clip_release(
2793 ep->com.dev->rdev.lldi.ports[0],
2794 (const u32 *)&sin6->sin6_addr.s6_addr,
2795 1);
2796 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002797 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302798 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2799 dst_release(ep->dst);
2800 cxgb4_l2t_release(ep->l2t);
2801 c4iw_reconnect(ep);
2802 }
2803
Steve Wisecfdda9d2010-04-21 15:30:06 -07002804 return 0;
2805}
2806
2807static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2808{
2809 struct c4iw_ep *ep;
2810 struct c4iw_qp_attributes attrs;
2811 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002812 int release = 0;
2813 struct tid_info *t = dev->rdev.lldi.tids;
2814 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002815
2816 ep = lookup_tid(t, tid);
2817
2818 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2819 BUG_ON(!ep);
2820
2821 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002822 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002823 switch (ep->com.state) {
2824 case CLOSING:
2825 __state_set(&ep->com, MORIBUND);
2826 break;
2827 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002828 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002829 if ((ep->com.cm_id) && (ep->com.qp)) {
2830 attrs.next_state = C4IW_QP_STATE_IDLE;
2831 c4iw_modify_qp(ep->com.qp->rhp,
2832 ep->com.qp,
2833 C4IW_QP_ATTR_NEXT_STATE,
2834 &attrs, 1);
2835 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302836 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002837 __state_set(&ep->com, DEAD);
2838 release = 1;
2839 break;
2840 case ABORTING:
2841 case DEAD:
2842 break;
2843 default:
2844 BUG_ON(1);
2845 break;
2846 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002847 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002848 if (release)
2849 release_ep_resources(ep);
2850 return 0;
2851}
2852
2853static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2854{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002855 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002856 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002857 unsigned int tid = GET_TID(rpl);
2858 struct c4iw_ep *ep;
2859 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002860
2861 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002862 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002863
Steve Wise30c95c22011-05-09 22:06:22 -07002864 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002865 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2866 ep->com.qp->wq.sq.qid);
2867 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2868 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2869 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2870 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002871 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002872
Steve Wisecfdda9d2010-04-21 15:30:06 -07002873 return 0;
2874}
2875
2876/*
2877 * Upcall from the adapter indicating data has been transmitted.
2878 * For us its just the single MPA request or reply. We can now free
2879 * the skb holding the mpa message.
2880 */
2881static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2882{
2883 struct c4iw_ep *ep;
2884 struct cpl_fw4_ack *hdr = cplhdr(skb);
2885 u8 credits = hdr->credits;
2886 unsigned int tid = GET_TID(hdr);
2887 struct tid_info *t = dev->rdev.lldi.tids;
2888
2889
2890 ep = lookup_tid(t, tid);
2891 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2892 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002893 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2894 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002895 return 0;
2896 }
2897
2898 dst_confirm(ep->dst);
2899 if (ep->mpa_skb) {
2900 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2901 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2902 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2903 kfree_skb(ep->mpa_skb);
2904 ep->mpa_skb = NULL;
2905 }
2906 return 0;
2907}
2908
Steve Wisecfdda9d2010-04-21 15:30:06 -07002909int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2910{
Steve Wisea7db89e2014-03-21 20:40:35 +05302911 int err = 0;
2912 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002913 struct c4iw_ep *ep = to_ep(cm_id);
2914 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2915
Steve Wisea7db89e2014-03-21 20:40:35 +05302916 mutex_lock(&ep->com.mutex);
2917 if (ep->com.state == DEAD) {
2918 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002919 c4iw_put_ep(&ep->com);
2920 return -ECONNRESET;
2921 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002922 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302923 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002924 if (mpa_rev == 0)
2925 abort_connection(ep, NULL, GFP_KERNEL);
2926 else {
2927 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302928 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002929 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302930 mutex_unlock(&ep->com.mutex);
2931 if (disconnect)
2932 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002933 c4iw_put_ep(&ep->com);
2934 return 0;
2935}
2936
2937int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2938{
2939 int err;
2940 struct c4iw_qp_attributes attrs;
2941 enum c4iw_qp_attr_mask mask;
2942 struct c4iw_ep *ep = to_ep(cm_id);
2943 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2944 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2945
2946 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302947
2948 mutex_lock(&ep->com.mutex);
2949 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002950 err = -ECONNRESET;
2951 goto err;
2952 }
2953
Steve Wisea7db89e2014-03-21 20:40:35 +05302954 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002955 BUG_ON(!qp);
2956
Vipul Pandya793dad92012-12-10 09:30:56 +00002957 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302958 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2959 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002960 abort_connection(ep, NULL, GFP_KERNEL);
2961 err = -EINVAL;
2962 goto err;
2963 }
2964
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302965 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2966 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302967 if (RELAXED_IRD_NEGOTIATION) {
2968 ep->ord = ep->ird;
2969 } else {
2970 ep->ird = conn_param->ird;
2971 ep->ord = conn_param->ord;
2972 send_mpa_reject(ep, conn_param->private_data,
2973 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302974 abort_connection(ep, NULL, GFP_KERNEL);
2975 err = -ENOMEM;
2976 goto err;
2977 }
2978 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302979 if (conn_param->ird < ep->ord) {
2980 if (RELAXED_IRD_NEGOTIATION &&
2981 ep->ord <= h->rdev.lldi.max_ordird_qp) {
2982 conn_param->ird = ep->ord;
2983 } else {
2984 abort_connection(ep, NULL, GFP_KERNEL);
2985 err = -ENOMEM;
2986 goto err;
2987 }
2988 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302989 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002990 ep->ird = conn_param->ird;
2991 ep->ord = conn_param->ord;
2992
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302993 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302994 if (peer2peer && ep->ird == 0)
2995 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302996 } else {
2997 if (peer2peer &&
2998 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05302999 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303000 ep->ird = 1;
3001 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003002
3003 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3004
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303005 cm_id->add_ref(cm_id);
3006 ep->com.cm_id = cm_id;
3007 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003008 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303009
Steve Wisecfdda9d2010-04-21 15:30:06 -07003010 /* bind QP to EP and move to RTS */
3011 attrs.mpa_attr = ep->mpa_attr;
3012 attrs.max_ird = ep->ird;
3013 attrs.max_ord = ep->ord;
3014 attrs.llp_stream_handle = ep;
3015 attrs.next_state = C4IW_QP_STATE_RTS;
3016
3017 /* bind QP and TID with INIT_WR */
3018 mask = C4IW_QP_ATTR_NEXT_STATE |
3019 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3020 C4IW_QP_ATTR_MPA_ATTR |
3021 C4IW_QP_ATTR_MAX_IRD |
3022 C4IW_QP_ATTR_MAX_ORD;
3023
3024 err = c4iw_modify_qp(ep->com.qp->rhp,
3025 ep->com.qp, mask, &attrs, 1);
3026 if (err)
3027 goto err1;
3028 err = send_mpa_reply(ep, conn_param->private_data,
3029 conn_param->private_data_len);
3030 if (err)
3031 goto err1;
3032
Steve Wisea7db89e2014-03-21 20:40:35 +05303033 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003034 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303035 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003036 c4iw_put_ep(&ep->com);
3037 return 0;
3038err1:
3039 ep->com.cm_id = NULL;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303040 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003041 cm_id->rem_ref(cm_id);
3042err:
Steve Wisea7db89e2014-03-21 20:40:35 +05303043 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003044 c4iw_put_ep(&ep->com);
3045 return err;
3046}
3047
Vipul Pandya830662f2013-07-04 16:10:47 +05303048static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3049{
3050 struct in_device *ind;
3051 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003052 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3053 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303054
3055 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3056 if (!ind)
3057 return -EADDRNOTAVAIL;
3058 for_primary_ifa(ind) {
3059 laddr->sin_addr.s_addr = ifa->ifa_address;
3060 raddr->sin_addr.s_addr = ifa->ifa_address;
3061 found = 1;
3062 break;
3063 }
3064 endfor_ifa(ind);
3065 in_dev_put(ind);
3066 return found ? 0 : -EADDRNOTAVAIL;
3067}
3068
3069static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3070 unsigned char banned_flags)
3071{
3072 struct inet6_dev *idev;
3073 int err = -EADDRNOTAVAIL;
3074
3075 rcu_read_lock();
3076 idev = __in6_dev_get(dev);
3077 if (idev != NULL) {
3078 struct inet6_ifaddr *ifp;
3079
3080 read_lock_bh(&idev->lock);
3081 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3082 if (ifp->scope == IFA_LINK &&
3083 !(ifp->flags & banned_flags)) {
3084 memcpy(addr, &ifp->addr, 16);
3085 err = 0;
3086 break;
3087 }
3088 }
3089 read_unlock_bh(&idev->lock);
3090 }
3091 rcu_read_unlock();
3092 return err;
3093}
3094
3095static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3096{
3097 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003098 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3099 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303100
Nicholas Krause54b9a962015-08-26 23:00:59 -04003101 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303102 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3103 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3104 return 0;
3105 }
3106 return -EADDRNOTAVAIL;
3107}
3108
Steve Wisecfdda9d2010-04-21 15:30:06 -07003109int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3110{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003111 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3112 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003113 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003114 struct sockaddr_in *laddr;
3115 struct sockaddr_in *raddr;
3116 struct sockaddr_in6 *laddr6;
3117 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303118 __u8 *ra;
3119 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003120
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303121 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3122 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003123 err = -EINVAL;
3124 goto out;
3125 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003126 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3127 if (!ep) {
3128 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3129 err = -ENOMEM;
3130 goto out;
3131 }
3132 init_timer(&ep->timer);
3133 ep->plen = conn_param->private_data_len;
3134 if (ep->plen)
3135 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3136 conn_param->private_data, ep->plen);
3137 ep->ird = conn_param->ird;
3138 ep->ord = conn_param->ord;
3139
3140 if (peer2peer && ep->ord == 0)
3141 ep->ord = 1;
3142
3143 cm_id->add_ref(cm_id);
3144 ep->com.dev = dev;
3145 ep->com.cm_id = cm_id;
3146 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303147 if (!ep->com.qp) {
3148 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3149 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003150 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303151 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003152 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003153 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3154 ep->com.qp, cm_id);
3155
3156 /*
3157 * Allocate an active TID to initiate a TCP connection.
3158 */
3159 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3160 if (ep->atid == -1) {
3161 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3162 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003163 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003164 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003165 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003166
Steve Wise170003c2016-02-26 09:18:03 -06003167 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003168 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003169 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003170 sizeof(ep->com.remote_addr));
3171
Steve Wise170003c2016-02-26 09:18:03 -06003172 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3173 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3174 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3175 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003176
Steve Wise170003c2016-02-26 09:18:03 -06003177 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303178 iptype = 4;
3179 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003180
Vipul Pandya830662f2013-07-04 16:10:47 +05303181 /*
3182 * Handle loopback requests to INADDR_ANY.
3183 */
3184 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3185 err = pick_local_ipaddrs(dev, cm_id);
3186 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003187 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303188 }
3189
3190 /* find a route */
3191 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3192 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3193 ra, ntohs(raddr->sin_port));
3194 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3195 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303196 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303197 } else {
3198 iptype = 6;
3199 ra = (__u8 *)&raddr6->sin6_addr;
3200
3201 /*
3202 * Handle loopback requests to INADDR_ANY.
3203 */
3204 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3205 err = pick_local_ip6addrs(dev, cm_id);
3206 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003207 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303208 }
3209
3210 /* find a route */
3211 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3212 __func__, laddr6->sin6_addr.s6_addr,
3213 ntohs(laddr6->sin6_port),
3214 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3215 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3216 raddr6->sin6_addr.s6_addr,
3217 laddr6->sin6_port, raddr6->sin6_port, 0,
3218 raddr6->sin6_scope_id);
3219 }
3220 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003221 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3222 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003223 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003224 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003225
Hariprasad S963cab52015-09-23 17:19:27 +05303226 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303227 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003228 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003229 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003230 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003231 }
3232
3233 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3234 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3235 ep->l2t->idx);
3236
3237 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303238 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003239
3240 /* send connect request to rnic */
3241 err = send_connect(ep);
3242 if (!err)
3243 goto out;
3244
3245 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003246fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003247 dst_release(ep->dst);
3248fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003249 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003250 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003251fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003252 cm_id->rem_ref(cm_id);
3253 c4iw_put_ep(&ep->com);
3254out:
3255 return err;
3256}
3257
Vipul Pandya830662f2013-07-04 16:10:47 +05303258static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3259{
3260 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003261 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003262 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303263
Hariprasad S28de1f72016-01-13 10:03:14 +05303264 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3265 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3266 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3267 if (err)
3268 return err;
3269 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303270 c4iw_init_wr_wait(&ep->com.wr_wait);
3271 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3272 ep->stid, &sin6->sin6_addr,
3273 sin6->sin6_port,
3274 ep->com.dev->rdev.lldi.rxq_ids[0]);
3275 if (!err)
3276 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3277 &ep->com.wr_wait,
3278 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303279 else if (err > 0)
3280 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303281 if (err) {
3282 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3283 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303284 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3285 err, ep->stid,
3286 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303287 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303288 return err;
3289}
3290
3291static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3292{
3293 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003294 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003295 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303296
3297 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3298 do {
3299 err = cxgb4_create_server_filter(
3300 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3301 sin->sin_addr.s_addr, sin->sin_port, 0,
3302 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3303 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303304 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3305 err = -EIO;
3306 break;
3307 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303308 set_current_state(TASK_UNINTERRUPTIBLE);
3309 schedule_timeout(usecs_to_jiffies(100));
3310 }
3311 } while (err == -EBUSY);
3312 } else {
3313 c4iw_init_wr_wait(&ep->com.wr_wait);
3314 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3315 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3316 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3317 if (!err)
3318 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3319 &ep->com.wr_wait,
3320 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303321 else if (err > 0)
3322 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303323 }
3324 if (err)
3325 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3326 , err, ep->stid,
3327 &sin->sin_addr, ntohs(sin->sin_port));
3328 return err;
3329}
3330
Steve Wisecfdda9d2010-04-21 15:30:06 -07003331int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3332{
3333 int err = 0;
3334 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3335 struct c4iw_listen_ep *ep;
3336
Steve Wisecfdda9d2010-04-21 15:30:06 -07003337 might_sleep();
3338
3339 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3340 if (!ep) {
3341 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3342 err = -ENOMEM;
3343 goto fail1;
3344 }
3345 PDBG("%s ep %p\n", __func__, ep);
3346 cm_id->add_ref(cm_id);
3347 ep->com.cm_id = cm_id;
3348 ep->com.dev = dev;
3349 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003350 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303351 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003352
3353 /*
3354 * Allocate a server TID.
3355 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303356 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3357 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303358 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003359 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003360 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303361 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003362 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003363
Steve Wisecfdda9d2010-04-21 15:30:06 -07003364 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003365 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003366 err = -ENOMEM;
3367 goto fail2;
3368 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003369 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003370
Steve Wise170003c2016-02-26 09:18:03 -06003371 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3372 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003373
Steve Wisecfdda9d2010-04-21 15:30:06 -07003374 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303375 if (ep->com.local_addr.ss_family == AF_INET)
3376 err = create_server4(dev, ep);
3377 else
3378 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003379 if (!err) {
3380 cm_id->provider_data = ep;
3381 goto out;
3382 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003383
Vipul Pandya830662f2013-07-04 16:10:47 +05303384 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3385 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003386fail2:
3387 cm_id->rem_ref(cm_id);
3388 c4iw_put_ep(&ep->com);
3389fail1:
3390out:
3391 return err;
3392}
3393
3394int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3395{
3396 int err;
3397 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3398
3399 PDBG("%s ep %p\n", __func__, ep);
3400
3401 might_sleep();
3402 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303403 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3404 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003405 err = cxgb4_remove_server_filter(
3406 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3407 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3408 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303409 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003410 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303411 err = cxgb4_remove_server(
3412 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3413 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003414 if (err)
3415 goto done;
3416 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3417 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003418 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303419 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3420 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003421 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003422 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303423 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3424 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003425done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003426 cm_id->rem_ref(cm_id);
3427 c4iw_put_ep(&ep->com);
3428 return err;
3429}
3430
3431int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3432{
3433 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003434 int close = 0;
3435 int fatal = 0;
3436 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003437
Steve Wise2f5b48c2010-09-10 11:15:36 -05003438 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003439
3440 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3441 states[ep->com.state], abrupt);
3442
Hariprasad S6e410d82016-05-05 01:27:31 +05303443 /*
3444 * Ref the ep here in case we have fatal errors causing the
3445 * ep to be released and freed.
3446 */
3447 c4iw_get_ep(&ep->com);
3448
Steve Wisecfdda9d2010-04-21 15:30:06 -07003449 rdev = &ep->com.dev->rdev;
3450 if (c4iw_fatal_error(rdev)) {
3451 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303452 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003453 ep->com.state = DEAD;
3454 }
3455 switch (ep->com.state) {
3456 case MPA_REQ_WAIT:
3457 case MPA_REQ_SENT:
3458 case MPA_REQ_RCVD:
3459 case MPA_REP_SENT:
3460 case FPDU_MODE:
3461 close = 1;
3462 if (abrupt)
3463 ep->com.state = ABORTING;
3464 else {
3465 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003466 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003467 }
3468 set_bit(CLOSE_SENT, &ep->com.flags);
3469 break;
3470 case CLOSING:
3471 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3472 close = 1;
3473 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003474 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003475 ep->com.state = ABORTING;
3476 } else
3477 ep->com.state = MORIBUND;
3478 }
3479 break;
3480 case MORIBUND:
3481 case ABORTING:
3482 case DEAD:
3483 PDBG("%s ignoring disconnect ep %p state %u\n",
3484 __func__, ep, ep->com.state);
3485 break;
3486 default:
3487 BUG();
3488 break;
3489 }
3490
Steve Wisecfdda9d2010-04-21 15:30:06 -07003491 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003492 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003493 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303494 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003495 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003496 } else {
3497 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003498 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003499 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303500 if (ret) {
3501 if (!abrupt) {
3502 stop_ep_timer(ep);
3503 close_complete_upcall(ep, -EIO);
3504 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003505 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303506 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003507 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003508 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303509 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003510 if (fatal)
3511 release_ep_resources(ep);
3512 return ret;
3513}
3514
Vipul Pandya1cab7752012-12-10 09:30:55 +00003515static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3516 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3517{
3518 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003519 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003520
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003521 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3522 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003523 if (!ep)
3524 return;
3525
3526 switch (req->retval) {
3527 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003528 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3529 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3530 send_fw_act_open_req(ep, atid);
3531 return;
3532 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003533 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003534 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3535 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3536 send_fw_act_open_req(ep, atid);
3537 return;
3538 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003539 break;
3540 default:
3541 pr_info("%s unexpected ofld conn wr retval %d\n",
3542 __func__, req->retval);
3543 break;
3544 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003545 pr_err("active ofld_connect_wr failure %d atid %d\n",
3546 req->retval, atid);
3547 mutex_lock(&dev->rdev.stats.lock);
3548 dev->rdev.stats.act_ofld_conn_fails++;
3549 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003550 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003551 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303552 if (ep->com.remote_addr.ss_family == AF_INET6) {
3553 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003554 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303555 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3556 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3557 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003558 remove_handle(dev, &dev->atid_idr, atid);
3559 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3560 dst_release(ep->dst);
3561 cxgb4_l2t_release(ep->l2t);
3562 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003563}
3564
3565static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3566 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3567{
3568 struct sk_buff *rpl_skb;
3569 struct cpl_pass_accept_req *cpl;
3570 int ret;
3571
Paul Bolle710a3112013-02-05 20:51:30 +00003572 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003573 BUG_ON(!rpl_skb);
3574 if (req->retval) {
3575 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003576 mutex_lock(&dev->rdev.stats.lock);
3577 dev->rdev.stats.pas_ofld_conn_fails++;
3578 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003579 kfree_skb(rpl_skb);
3580 } else {
3581 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3582 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003583 (__force u32) htonl(
3584 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003585 ret = pass_accept_req(dev, rpl_skb);
3586 if (!ret)
3587 kfree_skb(rpl_skb);
3588 }
3589 return;
3590}
3591
3592static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003593{
3594 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003595 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3596
3597 switch (rpl->type) {
3598 case FW6_TYPE_CQE:
3599 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3600 break;
3601 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3602 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3603 switch (req->t_state) {
3604 case TCP_SYN_SENT:
3605 active_ofld_conn_reply(dev, skb, req);
3606 break;
3607 case TCP_SYN_RECV:
3608 passive_ofld_conn_reply(dev, skb, req);
3609 break;
3610 default:
3611 pr_err("%s unexpected ofld conn wr state %d\n",
3612 __func__, req->t_state);
3613 break;
3614 }
3615 break;
3616 }
3617 return 0;
3618}
3619
3620static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3621{
Hariprasad S963cab52015-09-23 17:19:27 +05303622 __be32 l2info;
3623 __be16 hdr_len, vlantag, len;
3624 u16 eth_hdr_len;
3625 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003626 u8 intf;
3627 struct cpl_rx_pkt *cpl = cplhdr(skb);
3628 struct cpl_pass_accept_req *req;
3629 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003630 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303631 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003632
Vipul Pandyaf079af72013-03-14 05:08:58 +00003633 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003634 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303635 vlantag = cpl->vlan;
3636 len = cpl->len;
3637 l2info = cpl->l2info;
3638 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003639 intf = cpl->iff;
3640
3641 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3642
3643 /*
3644 * We need to parse the TCP options from SYN packet.
3645 * to generate cpl_pass_accept_req.
3646 */
3647 memset(&tmp_opt, 0, sizeof(tmp_opt));
3648 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003649 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003650
3651 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3652 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303653 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3654 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303655 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303656 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303657 type = dev->rdev.lldi.adapter_type;
3658 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3659 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3660 req->hdr_len =
3661 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3662 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3663 eth_hdr_len = is_t4(type) ?
3664 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3665 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3666 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3667 IP_HDR_LEN_V(ip_hdr_len) |
3668 ETH_HDR_LEN_V(eth_hdr_len));
3669 } else { /* T6 and later */
3670 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3671 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3672 T6_IP_HDR_LEN_V(ip_hdr_len) |
3673 T6_ETH_HDR_LEN_V(eth_hdr_len));
3674 }
3675 req->vlan = vlantag;
3676 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003677 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3678 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003679 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3680 if (tmp_opt.wscale_ok)
3681 req->tcpopt.wsf = tmp_opt.snd_wscale;
3682 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3683 if (tmp_opt.sack_ok)
3684 req->tcpopt.sack = 1;
3685 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3686 return;
3687}
3688
3689static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3690 __be32 laddr, __be16 lport,
3691 __be32 raddr, __be16 rport,
3692 u32 rcv_isn, u32 filter, u16 window,
3693 u32 rss_qid, u8 port_id)
3694{
3695 struct sk_buff *req_skb;
3696 struct fw_ofld_connection_wr *req;
3697 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303698 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003699
3700 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3701 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3702 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003703 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303704 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303705 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003706 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003707 req->le.lport = lport;
3708 req->le.pport = rport;
3709 req->le.u.ipv4.lip = laddr;
3710 req->le.u.ipv4.pip = raddr;
3711 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3712 req->tcb.rcv_adv = htons(window);
3713 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303714 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3715 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3716 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003717 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003718
3719 /*
3720 * We store the qid in opt2 which will be used by the firmware
3721 * to send us the wr response.
3722 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003723 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003724
3725 /*
3726 * We initialize the MSS index in TCB to 0xF.
3727 * So that when driver sends cpl_pass_accept_rpl
3728 * TCB picks up the correct value. If this was 0
3729 * TP will ignore any value > 0 for MSS index.
3730 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003731 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303732 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003733
3734 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303735 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3736 if (ret < 0) {
3737 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3738 ret);
3739 kfree_skb(skb);
3740 kfree_skb(req_skb);
3741 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003742}
3743
3744/*
3745 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3746 * messages when a filter is being used instead of server to
3747 * redirect a syn packet. When packets hit filter they are redirected
3748 * to the offload queue and driver tries to establish the connection
3749 * using firmware work request.
3750 */
3751static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3752{
3753 int stid;
3754 unsigned int filter;
3755 struct ethhdr *eh = NULL;
3756 struct vlan_ethhdr *vlan_eh = NULL;
3757 struct iphdr *iph;
3758 struct tcphdr *tcph;
3759 struct rss_header *rss = (void *)skb->data;
3760 struct cpl_rx_pkt *cpl = (void *)skb->data;
3761 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3762 struct l2t_entry *e;
3763 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003764 struct c4iw_ep *lep;
3765 u16 window;
3766 struct port_info *pi;
3767 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003768 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003769 int step;
3770 u32 tx_chan;
3771 struct neighbour *neigh;
3772
3773 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003774 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003775 goto reject;
3776
3777 /*
3778 * Drop all packets which did not hit the filter.
3779 * Unlikely to happen.
3780 */
3781 if (!(rss->filter_hit && rss->filter_tid))
3782 goto reject;
3783
3784 /*
3785 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3786 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303787 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003788
3789 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3790 if (!lep) {
3791 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3792 goto reject;
3793 }
3794
Hariprasad S963cab52015-09-23 17:19:27 +05303795 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3796 case CHELSIO_T4:
3797 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3798 break;
3799 case CHELSIO_T5:
3800 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3801 break;
3802 case CHELSIO_T6:
3803 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3804 break;
3805 default:
3806 pr_err("T%d Chip is not supported\n",
3807 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3808 goto reject;
3809 }
3810
Vipul Pandyaf079af72013-03-14 05:08:58 +00003811 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003812 eh = (struct ethhdr *)(req + 1);
3813 iph = (struct iphdr *)(eh + 1);
3814 } else {
3815 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3816 iph = (struct iphdr *)(vlan_eh + 1);
3817 skb->vlan_tci = ntohs(cpl->vlan);
3818 }
3819
3820 if (iph->version != 0x4)
3821 goto reject;
3822
3823 tcph = (struct tcphdr *)(iph + 1);
3824 skb_set_network_header(skb, (void *)iph - (void *)rss);
3825 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3826 skb_get(skb);
3827
3828 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3829 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3830 ntohs(tcph->source), iph->tos);
3831
Vipul Pandya830662f2013-07-04 16:10:47 +05303832 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3833 iph->tos);
3834 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003835 pr_err("%s - failed to find dst entry!\n",
3836 __func__);
3837 goto reject;
3838 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003839 neigh = dst_neigh_lookup_skb(dst, skb);
3840
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003841 if (!neigh) {
3842 pr_err("%s - failed to allocate neigh!\n",
3843 __func__);
3844 goto free_dst;
3845 }
3846
Vipul Pandya1cab7752012-12-10 09:30:55 +00003847 if (neigh->dev->flags & IFF_LOOPBACK) {
3848 pdev = ip_dev_find(&init_net, iph->daddr);
3849 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3850 pdev, 0);
3851 pi = (struct port_info *)netdev_priv(pdev);
3852 tx_chan = cxgb4_port_chan(pdev);
3853 dev_put(pdev);
3854 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303855 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003856 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303857 pdev, 0);
3858 pi = (struct port_info *)netdev_priv(pdev);
3859 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003860 }
Steve Wiseebf00062014-03-19 17:44:40 +05303861 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003862 if (!e) {
3863 pr_err("%s - failed to allocate l2t entry!\n",
3864 __func__);
3865 goto free_dst;
3866 }
3867
3868 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3869 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003870 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003871
3872 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303873 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3874 dev->rdev.lldi.ports[0],
3875 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003876
3877 /*
3878 * Synthesize the cpl_pass_accept_req. We have everything except the
3879 * TID. Once firmware sends a reply with TID we update the TID field
3880 * in cpl and pass it through the regular cpl_pass_accept_req path.
3881 */
3882 build_cpl_pass_accept_req(skb, stid, iph->tos);
3883 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3884 tcph->source, ntohl(tcph->seq), filter, window,
3885 rss_qid, pi->port_id);
3886 cxgb4_l2t_release(e);
3887free_dst:
3888 dst_release(dst);
3889reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003890 return 0;
3891}
3892
Steve Wisecfdda9d2010-04-21 15:30:06 -07003893/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003894 * These are the real handlers that are called from a
3895 * work queue.
3896 */
Hariprasad S9dec9002016-05-05 01:27:29 +05303897static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003898 [CPL_ACT_ESTABLISH] = act_establish,
3899 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3900 [CPL_RX_DATA] = rx_data,
3901 [CPL_ABORT_RPL_RSS] = abort_rpl,
3902 [CPL_ABORT_RPL] = abort_rpl,
3903 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3904 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3905 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3906 [CPL_PASS_ESTABLISH] = pass_establish,
3907 [CPL_PEER_CLOSE] = peer_close,
3908 [CPL_ABORT_REQ_RSS] = peer_abort,
3909 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3910 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003911 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003912 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05303913 [CPL_RX_PKT] = rx_pkt,
3914 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003915};
3916
3917static void process_timeout(struct c4iw_ep *ep)
3918{
3919 struct c4iw_qp_attributes attrs;
3920 int abort = 1;
3921
Steve Wise2f5b48c2010-09-10 11:15:36 -05003922 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003923 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3924 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003925 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003926 switch (ep->com.state) {
3927 case MPA_REQ_SENT:
3928 __state_set(&ep->com, ABORTING);
3929 connect_reply_upcall(ep, -ETIMEDOUT);
3930 break;
3931 case MPA_REQ_WAIT:
3932 __state_set(&ep->com, ABORTING);
3933 break;
3934 case CLOSING:
3935 case MORIBUND:
3936 if (ep->com.cm_id && ep->com.qp) {
3937 attrs.next_state = C4IW_QP_STATE_ERROR;
3938 c4iw_modify_qp(ep->com.qp->rhp,
3939 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3940 &attrs, 1);
3941 }
3942 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303943 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003944 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003945 case ABORTING:
3946 case DEAD:
3947
3948 /*
3949 * These states are expected if the ep timed out at the same
3950 * time as another thread was calling stop_ep_timer().
3951 * So we silently do nothing for these states.
3952 */
3953 abort = 0;
3954 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003955 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003956 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003957 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003958 abort = 0;
3959 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003960 if (abort)
3961 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecc18b932014-04-24 14:31:53 -05003962 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003963 c4iw_put_ep(&ep->com);
3964}
3965
3966static void process_timedout_eps(void)
3967{
3968 struct c4iw_ep *ep;
3969
3970 spin_lock_irq(&timeout_lock);
3971 while (!list_empty(&timeout_list)) {
3972 struct list_head *tmp;
3973
3974 tmp = timeout_list.next;
3975 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003976 tmp->next = NULL;
3977 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003978 spin_unlock_irq(&timeout_lock);
3979 ep = list_entry(tmp, struct c4iw_ep, entry);
3980 process_timeout(ep);
3981 spin_lock_irq(&timeout_lock);
3982 }
3983 spin_unlock_irq(&timeout_lock);
3984}
3985
3986static void process_work(struct work_struct *work)
3987{
3988 struct sk_buff *skb = NULL;
3989 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003990 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003991 unsigned int opcode;
3992 int ret;
3993
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003994 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003995 while ((skb = skb_dequeue(&rxq))) {
3996 rpl = cplhdr(skb);
3997 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3998 opcode = rpl->ot.opcode;
3999
4000 BUG_ON(!work_handlers[opcode]);
4001 ret = work_handlers[opcode](dev, skb);
4002 if (!ret)
4003 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004004 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004005 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004006}
4007
4008static DECLARE_WORK(skb_work, process_work);
4009
4010static void ep_timeout(unsigned long arg)
4011{
4012 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004013 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004014
4015 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004016 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004017 /*
4018 * Only insert if it is not already on the list.
4019 */
4020 if (!ep->entry.next) {
4021 list_add_tail(&ep->entry, &timeout_list);
4022 kickit = 1;
4023 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004024 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004025 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004026 if (kickit)
4027 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004028}
4029
4030/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004031 * All the CM events are handled on a work queue to have a safe context.
4032 */
4033static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4034{
4035
4036 /*
4037 * Save dev in the skb->cb area.
4038 */
4039 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4040
4041 /*
4042 * Queue the skb and schedule the worker thread.
4043 */
4044 skb_queue_tail(&rxq, skb);
4045 queue_work(workq, &skb_work);
4046 return 0;
4047}
4048
4049static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4050{
4051 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4052
4053 if (rpl->status != CPL_ERR_NONE) {
4054 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4055 "for tid %u\n", rpl->status, GET_TID(rpl));
4056 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004057 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004058 return 0;
4059}
4060
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004061static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4062{
4063 struct cpl_fw6_msg *rpl = cplhdr(skb);
4064 struct c4iw_wr_wait *wr_waitp;
4065 int ret;
4066
4067 PDBG("%s type %u\n", __func__, rpl->type);
4068
4069 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004070 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004071 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004072 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004073 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004074 if (wr_waitp)
4075 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004076 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004077 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004078 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004079 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004080 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004081 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004082 default:
4083 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4084 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004085 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004086 break;
4087 }
4088 return 0;
4089}
4090
Steve Wise8da7e7a2011-06-14 20:59:27 +00004091static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4092{
4093 struct cpl_abort_req_rss *req = cplhdr(skb);
4094 struct c4iw_ep *ep;
4095 struct tid_info *t = dev->rdev.lldi.tids;
4096 unsigned int tid = GET_TID(req);
4097
4098 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05004099 if (!ep) {
4100 printk(KERN_WARNING MOD
4101 "Abort on non-existent endpoint, tid %d\n", tid);
4102 kfree_skb(skb);
4103 return 0;
4104 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304105 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304106 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4107 __func__, ep->hwtid, req->status,
4108 neg_adv_str(req->status));
4109 ep->stats.abort_neg_adv++;
4110 dev->rdev.stats.neg_adv++;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004111 kfree_skb(skb);
4112 return 0;
4113 }
4114 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4115 ep->com.state);
4116
4117 /*
4118 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004119 * However, if we are on MPAv2 and want to retry with MPAv1
4120 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004121 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004122 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4123 if (ep->com.state != MPA_REQ_SENT)
4124 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4125 } else
4126 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00004127 sched(dev, skb);
4128 return 0;
4129}
4130
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004131/*
4132 * Most upcalls from the T4 Core go to sched() to
4133 * schedule the processing on a work queue.
4134 */
4135c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4136 [CPL_ACT_ESTABLISH] = sched,
4137 [CPL_ACT_OPEN_RPL] = sched,
4138 [CPL_RX_DATA] = sched,
4139 [CPL_ABORT_RPL_RSS] = sched,
4140 [CPL_ABORT_RPL] = sched,
4141 [CPL_PASS_OPEN_RPL] = sched,
4142 [CPL_CLOSE_LISTSRV_RPL] = sched,
4143 [CPL_PASS_ACCEPT_REQ] = sched,
4144 [CPL_PASS_ESTABLISH] = sched,
4145 [CPL_PEER_CLOSE] = sched,
4146 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004147 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004148 [CPL_RDMA_TERMINATE] = sched,
4149 [CPL_FW4_ACK] = sched,
4150 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004151 [CPL_FW6_MSG] = fw6_msg,
4152 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004153};
4154
Steve Wisecfdda9d2010-04-21 15:30:06 -07004155int __init c4iw_cm_init(void)
4156{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004157 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004158 skb_queue_head_init(&rxq);
4159
4160 workq = create_singlethread_workqueue("iw_cxgb4");
4161 if (!workq)
4162 return -ENOMEM;
4163
Steve Wisecfdda9d2010-04-21 15:30:06 -07004164 return 0;
4165}
4166
Steve Wise46c13762014-06-20 14:26:25 -05004167void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004168{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004169 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004170 flush_workqueue(workq);
4171 destroy_workqueue(workq);
4172}