blob: aea69ca495f38d5ad809a3dcb61533135e7e3cf1 [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
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301604/*
1605 * process_mpa_request - process streaming mode MPA request
1606 *
1607 * Returns:
1608 *
1609 * 0 upon success indicating a connect request was delivered to the ULP
1610 * or the mpa request is incomplete but valid so far.
1611 *
1612 * 1 if a failure requires the caller to close the connection.
1613 *
1614 * 2 if a failure requires the caller to abort the connection.
1615 */
1616static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001617{
1618 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301619 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001620 u16 plen;
1621
1622 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1623
Steve Wisecfdda9d2010-04-21 15:30:06 -07001624 /*
1625 * If we get more than the supported amount of private data
1626 * then we must fail this connection.
1627 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301628 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1629 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001630
1631 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1632
1633 /*
1634 * Copy the new data into our accumulation buffer.
1635 */
1636 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1637 skb->len);
1638 ep->mpa_pkt_len += skb->len;
1639
1640 /*
1641 * If we don't even have the mpa message, then bail.
1642 * We'll continue process when more data arrives.
1643 */
1644 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301645 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001646
1647 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001648 mpa = (struct mpa_message *) ep->mpa_pkt;
1649
1650 /*
1651 * Validate MPA Header.
1652 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301653 if (mpa->revision > mpa_rev) {
1654 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1655 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301656 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001657 }
1658
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301659 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1660 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001661
1662 plen = ntohs(mpa->private_data_size);
1663
1664 /*
1665 * Fail if there's too much private data.
1666 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301667 if (plen > MPA_MAX_PRIVATE_DATA)
1668 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001669
1670 /*
1671 * If plen does not account for pkt size
1672 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301673 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1674 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001675 ep->plen = (u8) plen;
1676
1677 /*
1678 * If we don't have all the pdata yet, then bail.
1679 */
1680 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301681 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001682
1683 /*
1684 * If we get here we have accumulated the entire mpa
1685 * start reply message including private data.
1686 */
1687 ep->mpa_attr.initiator = 0;
1688 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1689 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1690 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301691 ep->mpa_attr.version = mpa->revision;
1692 if (mpa->revision == 1)
1693 ep->tried_with_mpa_v1 = 1;
1694 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1695
1696 if (mpa->revision == 2) {
1697 ep->mpa_attr.enhanced_rdma_conn =
1698 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1699 if (ep->mpa_attr.enhanced_rdma_conn) {
1700 mpa_v2_params = (struct mpa_v2_conn_params *)
1701 (ep->mpa_pkt + sizeof(*mpa));
1702 ep->ird = ntohs(mpa_v2_params->ird) &
1703 MPA_V2_IRD_ORD_MASK;
1704 ep->ord = ntohs(mpa_v2_params->ord) &
1705 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301706 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1707 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301708 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1709 if (peer2peer) {
1710 if (ntohs(mpa_v2_params->ord) &
1711 MPA_V2_RDMA_WRITE_RTR)
1712 ep->mpa_attr.p2p_type =
1713 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1714 else if (ntohs(mpa_v2_params->ord) &
1715 MPA_V2_RDMA_READ_RTR)
1716 ep->mpa_attr.p2p_type =
1717 FW_RI_INIT_P2PTYPE_READ_REQ;
1718 }
1719 }
1720 } else if (mpa->revision == 1)
1721 if (peer2peer)
1722 ep->mpa_attr.p2p_type = p2p_type;
1723
Steve Wisecfdda9d2010-04-21 15:30:06 -07001724 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1725 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1726 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1727 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1728 ep->mpa_attr.p2p_type);
1729
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001730 /*
1731 * If the endpoint timer already expired, then we ignore
1732 * the start request. process_timeout() will abort
1733 * the connection.
1734 */
1735 if (!stop_ep_timer(ep)) {
1736 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001737
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001738 /* drive upcall */
Hariprasad Shenai10be6b42014-11-21 09:36:35 -06001739 mutex_lock_nested(&ep->parent_ep->com.mutex,
1740 SINGLE_DEPTH_NESTING);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001741 if (ep->parent_ep->com.state != DEAD) {
1742 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301743 goto err_unlock_parent;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001744 } else {
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301745 goto err_unlock_parent;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001746 }
1747 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301748 }
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301749 return 0;
1750
1751err_unlock_parent:
1752 mutex_unlock(&ep->parent_ep->com.mutex);
1753 goto err_out;
1754err_stop_timer:
1755 (void)stop_ep_timer(ep);
1756err_out:
1757 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001758}
1759
1760static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1761{
1762 struct c4iw_ep *ep;
1763 struct cpl_rx_data *hdr = cplhdr(skb);
1764 unsigned int dlen = ntohs(hdr->len);
1765 unsigned int tid = GET_TID(hdr);
1766 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001767 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001768 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001769
1770 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301771 if (!ep)
1772 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001773 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1774 skb_pull(skb, sizeof(*hdr));
1775 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301776 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001777
Steve Wisecfdda9d2010-04-21 15:30:06 -07001778 /* update RX credits */
1779 update_rx_credits(ep, dlen);
1780
Steve Wisec529fb52014-03-21 20:40:37 +05301781 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001782 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001783 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001784 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001785 break;
1786 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001787 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001788 process_mpa_request(ep, skb);
1789 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001790 case FPDU_MODE: {
1791 struct c4iw_qp_attributes attrs;
1792 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001793 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001794 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001795 " qpid %u ep %p state %d tid %u status %d\n",
1796 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301797 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301798 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001799 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001800 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1801 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001802 break;
1803 }
Vipul Pandya15579672013-01-07 13:11:52 +00001804 default:
1805 break;
1806 }
Steve Wisec529fb52014-03-21 20:40:37 +05301807 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001808 if (disconnect)
1809 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001810 return 0;
1811}
1812
1813static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1814{
1815 struct c4iw_ep *ep;
1816 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001817 int release = 0;
1818 unsigned int tid = GET_TID(rpl);
1819 struct tid_info *t = dev->rdev.lldi.tids;
1820
1821 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301822 if (!ep) {
1823 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1824 return 0;
1825 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001826 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001827 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001828 switch (ep->com.state) {
1829 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001830 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001831 __state_set(&ep->com, DEAD);
1832 release = 1;
1833 break;
1834 default:
1835 printk(KERN_ERR "%s ep %p state %d\n",
1836 __func__, ep, ep->com.state);
1837 break;
1838 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001839 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001840
1841 if (release)
1842 release_ep_resources(ep);
1843 return 0;
1844}
1845
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001846static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1847{
1848 struct sk_buff *skb;
1849 struct fw_ofld_connection_wr *req;
1850 unsigned int mtu_idx;
1851 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301852 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301853 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001854
1855 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1856 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1857 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001858 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301859 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301860 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1861 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001862 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001863 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301864 req->le.lport = sin->sin_port;
1865 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001866 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301867 req->le.pport = sin->sin_port;
1868 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001869 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301870 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1871 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001872 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301873 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001874 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001875 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301876 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301877 enable_tcp_timestamps,
1878 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001879 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301880
1881 /*
1882 * Specify the largest window that will fit in opt0. The
1883 * remainder will be specified in the rx_data_ack.
1884 */
1885 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001886 if (win > RCV_BUFSIZ_M)
1887 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301888
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001889 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1890 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001891 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001892 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001893 WND_SCALE_V(wscale) |
1894 MSS_IDX_V(mtu_idx) |
1895 L2T_IDX_V(ep->l2t->idx) |
1896 TX_CHAN_V(ep->tx_chan) |
1897 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301898 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001899 ULP_MODE_V(ULP_MODE_TCPDDP) |
1900 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001901 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1902 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001903 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001904 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001905 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001906 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001907 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001908 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001909 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001910 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001911 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1912 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1913 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001914 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1915 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001916 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1917}
1918
Steve Wisecfdda9d2010-04-21 15:30:06 -07001919/*
1920 * Return whether a failed active open has allocated a TID
1921 */
1922static inline int act_open_has_tid(int status)
1923{
1924 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1925 status != CPL_ERR_ARP_MISS;
1926}
1927
Steve Wise7a2cea22014-03-14 21:52:07 +05301928/* Returns whether a CPL status conveys negative advice.
1929 */
1930static int is_neg_adv(unsigned int status)
1931{
1932 return status == CPL_ERR_RTX_NEG_ADVICE ||
1933 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1934 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1935}
1936
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301937static char *neg_adv_str(unsigned int status)
1938{
1939 switch (status) {
1940 case CPL_ERR_RTX_NEG_ADVICE:
1941 return "Retransmit timeout";
1942 case CPL_ERR_PERSIST_NEG_ADVICE:
1943 return "Persist timeout";
1944 case CPL_ERR_KEEPALV_NEG_ADVICE:
1945 return "Keepalive timeout";
1946 default:
1947 return "Unknown";
1948 }
1949}
1950
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301951static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1952{
1953 ep->snd_win = snd_win;
1954 ep->rcv_win = rcv_win;
1955 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1956}
1957
Vipul Pandya793dad92012-12-10 09:30:56 +00001958#define ACT_OPEN_RETRY_COUNT 2
1959
Vipul Pandya830662f2013-07-04 16:10:47 +05301960static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1961 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301962 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05301963{
1964 struct neighbour *n;
1965 int err, step;
1966 struct net_device *pdev;
1967
1968 n = dst_neigh_lookup(dst, peer_ip);
1969 if (!n)
1970 return -ENODEV;
1971
1972 rcu_read_lock();
1973 err = -ENOMEM;
1974 if (n->dev->flags & IFF_LOOPBACK) {
1975 if (iptype == 4)
1976 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1977 else if (IS_ENABLED(CONFIG_IPV6))
1978 for_each_netdev(&init_net, pdev) {
1979 if (ipv6_chk_addr(&init_net,
1980 (struct in6_addr *)peer_ip,
1981 pdev, 1))
1982 break;
1983 }
1984 else
1985 pdev = NULL;
1986
1987 if (!pdev) {
1988 err = -ENODEV;
1989 goto out;
1990 }
1991 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301992 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05301993 if (!ep->l2t)
1994 goto out;
1995 ep->mtu = pdev->mtu;
1996 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05301997 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
1998 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301999 step = cdev->rdev.lldi.ntxq /
2000 cdev->rdev.lldi.nchan;
2001 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2002 step = cdev->rdev.lldi.nrxq /
2003 cdev->rdev.lldi.nchan;
2004 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2005 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2006 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302007 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302008 dev_put(pdev);
2009 } else {
2010 pdev = get_real_dev(n->dev);
2011 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2012 n, pdev, 0);
2013 if (!ep->l2t)
2014 goto out;
2015 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002016 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302017 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2018 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302019 step = cdev->rdev.lldi.ntxq /
2020 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002021 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2022 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302023 step = cdev->rdev.lldi.nrxq /
2024 cdev->rdev.lldi.nchan;
2025 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002026 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302027 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302028
2029 if (clear_mpa_v1) {
2030 ep->retry_with_mpa_v1 = 0;
2031 ep->tried_with_mpa_v1 = 0;
2032 }
2033 }
2034 err = 0;
2035out:
2036 rcu_read_unlock();
2037
2038 neigh_release(n);
2039
2040 return err;
2041}
2042
Vipul Pandya793dad92012-12-10 09:30:56 +00002043static int c4iw_reconnect(struct c4iw_ep *ep)
2044{
2045 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302046 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002047 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302048 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002049 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302050 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002051 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302052 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002053 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302054 int iptype;
2055 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002056
2057 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2058 init_timer(&ep->timer);
2059
2060 /*
2061 * Allocate an active TID to initiate a TCP connection.
2062 */
2063 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2064 if (ep->atid == -1) {
2065 pr_err("%s - cannot alloc atid.\n", __func__);
2066 err = -ENOMEM;
2067 goto fail2;
2068 }
2069 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2070
2071 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002072 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302073 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2074 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302075 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302076 iptype = 4;
2077 ra = (__u8 *)&raddr->sin_addr;
2078 } else {
2079 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2080 raddr6->sin6_addr.s6_addr,
2081 laddr6->sin6_port, raddr6->sin6_port, 0,
2082 raddr6->sin6_scope_id);
2083 iptype = 6;
2084 ra = (__u8 *)&raddr6->sin6_addr;
2085 }
2086 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002087 pr_err("%s - cannot find route.\n", __func__);
2088 err = -EHOSTUNREACH;
2089 goto fail3;
2090 }
Hariprasad S963cab52015-09-23 17:19:27 +05302091 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302092 ep->com.dev->rdev.lldi.adapter_type,
2093 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302094 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002095 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002096 goto fail4;
2097 }
2098
2099 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2100 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2101 ep->l2t->idx);
2102
2103 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302104 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002105
2106 /* send connect request to rnic */
2107 err = send_connect(ep);
2108 if (!err)
2109 goto out;
2110
2111 cxgb4_l2t_release(ep->l2t);
2112fail4:
2113 dst_release(ep->dst);
2114fail3:
2115 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2116 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2117fail2:
2118 /*
2119 * remember to send notification to upper layer.
2120 * We are in here so the upper layer is not aware that this is
2121 * re-connect attempt and so, upper layer is still waiting for
2122 * response of 1st connect request.
2123 */
2124 connect_reply_upcall(ep, -ECONNRESET);
2125 c4iw_put_ep(&ep->com);
2126out:
2127 return err;
2128}
2129
Steve Wisecfdda9d2010-04-21 15:30:06 -07002130static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2131{
2132 struct c4iw_ep *ep;
2133 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002134 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2135 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002136 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002137 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302138 struct sockaddr_in *la;
2139 struct sockaddr_in *ra;
2140 struct sockaddr_in6 *la6;
2141 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002142
2143 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002144 la = (struct sockaddr_in *)&ep->com.local_addr;
2145 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2146 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2147 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002148
2149 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2150 status, status2errno(status));
2151
Steve Wise7a2cea22014-03-14 21:52:07 +05302152 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302153 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2154 __func__, atid, status, neg_adv_str(status));
2155 ep->stats.connect_neg_adv++;
2156 mutex_lock(&dev->rdev.stats.lock);
2157 dev->rdev.stats.neg_adv++;
2158 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002159 return 0;
2160 }
2161
Vipul Pandya793dad92012-12-10 09:30:56 +00002162 set_bit(ACT_OPEN_RPL, &ep->com.history);
2163
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302164 /*
2165 * Log interesting failures.
2166 */
2167 switch (status) {
2168 case CPL_ERR_CONN_RESET:
2169 case CPL_ERR_CONN_TIMEDOUT:
2170 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002171 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302172 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002173 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302174 mutex_unlock(&dev->rdev.stats.lock);
2175 if (ep->com.local_addr.ss_family == AF_INET &&
2176 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002177 send_fw_act_open_req(ep,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002178 TID_TID_G(AOPEN_ATID_G(
Vipul Pandya793dad92012-12-10 09:30:56 +00002179 ntohl(rpl->atid_status))));
2180 return 0;
2181 }
2182 break;
2183 case CPL_ERR_CONN_EXIST:
2184 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2185 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302186 if (ep->com.remote_addr.ss_family == AF_INET6) {
2187 struct sockaddr_in6 *sin6 =
2188 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002189 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302190 cxgb4_clip_release(
2191 ep->com.dev->rdev.lldi.ports[0],
2192 (const u32 *)
2193 &sin6->sin6_addr.s6_addr, 1);
2194 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002195 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2196 atid);
2197 cxgb4_free_atid(t, atid);
2198 dst_release(ep->dst);
2199 cxgb4_l2t_release(ep->l2t);
2200 c4iw_reconnect(ep);
2201 return 0;
2202 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002203 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302204 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302205 if (ep->com.local_addr.ss_family == AF_INET) {
2206 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2207 atid, status, status2errno(status),
2208 &la->sin_addr.s_addr, ntohs(la->sin_port),
2209 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2210 } else {
2211 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2212 atid, status, status2errno(status),
2213 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2214 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2215 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302216 break;
2217 }
2218
Steve Wisecfdda9d2010-04-21 15:30:06 -07002219 connect_reply_upcall(ep, status2errno(status));
2220 state_set(&ep->com, DEAD);
2221
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302222 if (ep->com.remote_addr.ss_family == AF_INET6) {
2223 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002224 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302225 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2226 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2227 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002228 if (status && act_open_has_tid(status))
2229 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2230
Vipul Pandya793dad92012-12-10 09:30:56 +00002231 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002232 cxgb4_free_atid(t, atid);
2233 dst_release(ep->dst);
2234 cxgb4_l2t_release(ep->l2t);
2235 c4iw_put_ep(&ep->com);
2236
2237 return 0;
2238}
2239
2240static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2241{
2242 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2243 struct tid_info *t = dev->rdev.lldi.tids;
2244 unsigned int stid = GET_TID(rpl);
2245 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2246
2247 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002248 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2249 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002250 }
2251 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2252 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002253 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002254
Vipul Pandya1cab7752012-12-10 09:30:55 +00002255out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002256 return 0;
2257}
2258
Steve Wisecfdda9d2010-04-21 15:30:06 -07002259static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2260{
2261 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2262 struct tid_info *t = dev->rdev.lldi.tids;
2263 unsigned int stid = GET_TID(rpl);
2264 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2265
2266 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002267 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002268 return 0;
2269}
2270
Hariprasad S9dec9002016-05-05 01:27:29 +05302271static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2272 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002273{
2274 struct cpl_pass_accept_rpl *rpl;
2275 unsigned int mtu_idx;
2276 u64 opt0;
2277 u32 opt2;
2278 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302279 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302280 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302281 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002282
2283 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2284 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302285
Steve Wisecfdda9d2010-04-21 15:30:06 -07002286 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302287 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302288 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302289 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2290 rpl5 = (void *)rpl;
2291 INIT_TP_WR(rpl5, ep->hwtid);
2292 } else {
2293 skb_trim(skb, sizeof(*rpl));
2294 INIT_TP_WR(rpl, ep->hwtid);
2295 }
2296 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2297 ep->hwtid));
2298
2299 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302300 enable_tcp_timestamps && req->tcpopt.tstamp,
2301 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002302 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302303
2304 /*
2305 * Specify the largest window that will fit in opt0. The
2306 * remainder will be specified in the rx_data_ack.
2307 */
2308 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002309 if (win > RCV_BUFSIZ_M)
2310 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002311 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002312 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002313 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002314 WND_SCALE_V(wscale) |
2315 MSS_IDX_V(mtu_idx) |
2316 L2T_IDX_V(ep->l2t->idx) |
2317 TX_CHAN_V(ep->tx_chan) |
2318 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002319 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002320 ULP_MODE_V(ULP_MODE_TCPDDP) |
2321 RCV_BUFSIZ_V(win);
2322 opt2 = RX_CHANNEL_V(0) |
2323 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002324
2325 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002326 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002327 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002328 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002329 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002330 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002331 if (enable_ecn) {
2332 const struct tcphdr *tcph;
2333 u32 hlen = ntohl(req->hdr_len);
2334
Hariprasad S963cab52015-09-23 17:19:27 +05302335 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2336 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2337 IP_HDR_LEN_G(hlen);
2338 else
2339 tcph = (const void *)(req + 1) +
2340 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002341 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002342 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002343 }
Hariprasad S963cab52015-09-23 17:19:27 +05302344 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302345 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002346 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302347 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302348 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302349 rpl5 = (void *)rpl;
2350 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2351 if (peer2peer)
2352 isn += 4;
2353 rpl5->iss = cpu_to_be32(isn);
2354 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002355 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002356
Steve Wisecfdda9d2010-04-21 15:30:06 -07002357 rpl->opt0 = cpu_to_be64(opt0);
2358 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002359 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302360 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002361
Hariprasad S9dec9002016-05-05 01:27:29 +05302362 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002363}
2364
Vipul Pandya830662f2013-07-04 16:10:47 +05302365static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002366{
Vipul Pandya830662f2013-07-04 16:10:47 +05302367 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002368 BUG_ON(skb_cloned(skb));
2369 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002370 release_tid(&dev->rdev, hwtid, skb);
2371 return;
2372}
2373
Hariprasad S963cab52015-09-23 17:19:27 +05302374static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2375 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002376 __be16 *local_port, __be16 *peer_port)
2377{
Hariprasad S963cab52015-09-23 17:19:27 +05302378 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2379 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2380 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2381 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2382 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2383 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002384 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302385 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002386 struct tcphdr *tcp = (struct tcphdr *)
2387 ((u8 *)(req + 1) + eth_len + ip_len);
2388
Vipul Pandya830662f2013-07-04 16:10:47 +05302389 if (ip->version == 4) {
2390 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2391 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2392 ntohs(tcp->dest));
2393 *iptype = 4;
2394 memcpy(peer_ip, &ip->saddr, 4);
2395 memcpy(local_ip, &ip->daddr, 4);
2396 } else {
2397 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2398 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2399 ntohs(tcp->dest));
2400 *iptype = 6;
2401 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2402 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2403 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002404 *peer_port = tcp->source;
2405 *local_port = tcp->dest;
2406
2407 return;
2408}
2409
2410static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2411{
Vipul Pandya793dad92012-12-10 09:30:56 +00002412 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002413 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002414 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002415 struct tid_info *t = dev->rdev.lldi.tids;
2416 unsigned int hwtid = GET_TID(req);
2417 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302418 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002419 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302420 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002421 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002422 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302423 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302424 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302425 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002426
2427 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002428 if (!parent_ep) {
2429 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2430 goto reject;
2431 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002432
Steve Wisecfdda9d2010-04-21 15:30:06 -07002433 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302434 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002435 goto reject;
2436 }
2437
Hariprasad S963cab52015-09-23 17:19:27 +05302438 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2439 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302440
Steve Wisecfdda9d2010-04-21 15:30:06 -07002441 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302442 if (iptype == 4) {
2443 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2444 , __func__, parent_ep, hwtid,
2445 local_ip, peer_ip, ntohs(local_port),
2446 ntohs(peer_port), peer_mss);
2447 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2448 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302449 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302450 } else {
2451 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2452 , __func__, parent_ep, hwtid,
2453 local_ip, peer_ip, ntohs(local_port),
2454 ntohs(peer_port), peer_mss);
2455 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002456 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302457 ((struct sockaddr_in6 *)
2458 &parent_ep->com.local_addr)->sin6_scope_id);
2459 }
2460 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002461 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2462 __func__);
2463 goto reject;
2464 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002465
2466 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2467 if (!child_ep) {
2468 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2469 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002470 dst_release(dst);
2471 goto reject;
2472 }
David Miller3786cf12011-12-02 16:52:31 +00002473
Hariprasad S963cab52015-09-23 17:19:27 +05302474 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302475 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002476 if (err) {
2477 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2478 __func__);
2479 dst_release(dst);
2480 kfree(child_ep);
2481 goto reject;
2482 }
2483
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302484 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2485 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2486 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2487 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002488
Steve Wisecfdda9d2010-04-21 15:30:06 -07002489 state_set(&child_ep->com, CONNECTING);
2490 child_ep->com.dev = dev;
2491 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002492
Vipul Pandya830662f2013-07-04 16:10:47 +05302493 if (iptype == 4) {
2494 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002495 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002496
Vipul Pandya830662f2013-07-04 16:10:47 +05302497 sin->sin_family = PF_INET;
2498 sin->sin_port = local_port;
2499 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002500
2501 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2502 sin->sin_family = PF_INET;
2503 sin->sin_port = ((struct sockaddr_in *)
2504 &parent_ep->com.local_addr)->sin_port;
2505 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2506
Steve Wise170003c2016-02-26 09:18:03 -06002507 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302508 sin->sin_family = PF_INET;
2509 sin->sin_port = peer_port;
2510 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2511 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002512 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302513 sin6->sin6_family = PF_INET6;
2514 sin6->sin6_port = local_port;
2515 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002516
2517 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2518 sin6->sin6_family = PF_INET6;
2519 sin6->sin6_port = ((struct sockaddr_in6 *)
2520 &parent_ep->com.local_addr)->sin6_port;
2521 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2522
Steve Wise170003c2016-02-26 09:18:03 -06002523 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302524 sin6->sin6_family = PF_INET6;
2525 sin6->sin6_port = peer_port;
2526 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2527 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002528
Steve Wisecfdda9d2010-04-21 15:30:06 -07002529 c4iw_get_ep(&parent_ep->com);
2530 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302531 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002532 child_ep->dst = dst;
2533 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002534
2535 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002536 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002537
2538 init_timer(&child_ep->timer);
2539 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002540 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Hariprasad S9dec9002016-05-05 01:27:29 +05302541 if (accept_cr(child_ep, skb, req)) {
2542 c4iw_put_ep(&parent_ep->com);
2543 release_ep_resources(child_ep);
2544 } else {
2545 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2546 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302547 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002548 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302549 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2550 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2551 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002552 goto out;
2553reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302554 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002555out:
2556 return 0;
2557}
2558
2559static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2560{
2561 struct c4iw_ep *ep;
2562 struct cpl_pass_establish *req = cplhdr(skb);
2563 struct tid_info *t = dev->rdev.lldi.tids;
2564 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302565 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002566
2567 ep = lookup_tid(t, tid);
2568 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2569 ep->snd_seq = be32_to_cpu(req->snd_isn);
2570 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2571
Vipul Pandya1cab7752012-12-10 09:30:55 +00002572 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2573 ntohs(req->tcp_opt));
2574
Steve Wisecfdda9d2010-04-21 15:30:06 -07002575 set_emss(ep, ntohs(req->tcp_opt));
2576
2577 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302578 mutex_lock(&ep->com.mutex);
2579 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002580 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002581 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad Sfef44222016-05-05 01:27:33 +05302582 ret = send_flowc(ep, skb);
2583 mutex_unlock(&ep->com.mutex);
2584 if (ret)
2585 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002586
2587 return 0;
2588}
2589
2590static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2591{
2592 struct cpl_peer_close *hdr = cplhdr(skb);
2593 struct c4iw_ep *ep;
2594 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002595 int disconnect = 1;
2596 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002597 struct tid_info *t = dev->rdev.lldi.tids;
2598 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002599 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002600
2601 ep = lookup_tid(t, tid);
2602 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2603 dst_confirm(ep->dst);
2604
Vipul Pandya793dad92012-12-10 09:30:56 +00002605 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002606 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002607 switch (ep->com.state) {
2608 case MPA_REQ_WAIT:
2609 __state_set(&ep->com, CLOSING);
2610 break;
2611 case MPA_REQ_SENT:
2612 __state_set(&ep->com, CLOSING);
2613 connect_reply_upcall(ep, -ECONNRESET);
2614 break;
2615 case MPA_REQ_RCVD:
2616
2617 /*
2618 * We're gonna mark this puppy DEAD, but keep
2619 * the reference on it until the ULP accepts or
2620 * rejects the CR. Also wake up anyone waiting
2621 * in rdma connection migration (see c4iw_accept_cr()).
2622 */
2623 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002624 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002625 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002626 break;
2627 case MPA_REP_SENT:
2628 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002629 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002630 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002631 break;
2632 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002633 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002634 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002635 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002636 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002637 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002638 if (ret != -ECONNRESET) {
2639 peer_close_upcall(ep);
2640 disconnect = 1;
2641 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002642 break;
2643 case ABORTING:
2644 disconnect = 0;
2645 break;
2646 case CLOSING:
2647 __state_set(&ep->com, MORIBUND);
2648 disconnect = 0;
2649 break;
2650 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002651 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002652 if (ep->com.cm_id && ep->com.qp) {
2653 attrs.next_state = C4IW_QP_STATE_IDLE;
2654 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2655 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2656 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302657 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002658 __state_set(&ep->com, DEAD);
2659 release = 1;
2660 disconnect = 0;
2661 break;
2662 case DEAD:
2663 disconnect = 0;
2664 break;
2665 default:
2666 BUG_ON(1);
2667 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002668 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002669 if (disconnect)
2670 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2671 if (release)
2672 release_ep_resources(ep);
2673 return 0;
2674}
2675
Steve Wisecfdda9d2010-04-21 15:30:06 -07002676static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2677{
2678 struct cpl_abort_req_rss *req = cplhdr(skb);
2679 struct c4iw_ep *ep;
2680 struct cpl_abort_rpl *rpl;
2681 struct sk_buff *rpl_skb;
2682 struct c4iw_qp_attributes attrs;
2683 int ret;
2684 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002685 struct tid_info *t = dev->rdev.lldi.tids;
2686 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002687
2688 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302689 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302690 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2691 __func__, ep->hwtid, req->status,
2692 neg_adv_str(req->status));
2693 ep->stats.abort_neg_adv++;
2694 mutex_lock(&dev->rdev.stats.lock);
2695 dev->rdev.stats.neg_adv++;
2696 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002697 return 0;
2698 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002699 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2700 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002701 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002702
2703 /*
2704 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302705 * However, this is not needed if com state is just
2706 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002707 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302708 if (ep->com.state != MPA_REQ_SENT)
2709 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002710
2711 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002712 switch (ep->com.state) {
2713 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302714 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002715 break;
2716 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002717 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002718 break;
2719 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002720 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002721 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302722 connect_reply_upcall(ep, -ECONNRESET);
2723 else {
2724 /*
2725 * we just don't send notification upwards because we
2726 * want to retry with mpa_v1 without upper layers even
2727 * knowing it.
2728 *
2729 * do some housekeeping so as to re-initiate the
2730 * connection
2731 */
2732 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2733 mpa_rev);
2734 ep->retry_with_mpa_v1 = 1;
2735 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002736 break;
2737 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002738 break;
2739 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002740 break;
2741 case MORIBUND:
2742 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002743 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002744 /*FALLTHROUGH*/
2745 case FPDU_MODE:
2746 if (ep->com.cm_id && ep->com.qp) {
2747 attrs.next_state = C4IW_QP_STATE_ERROR;
2748 ret = c4iw_modify_qp(ep->com.qp->rhp,
2749 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2750 &attrs, 1);
2751 if (ret)
2752 printk(KERN_ERR MOD
2753 "%s - qp <- error failed!\n",
2754 __func__);
2755 }
2756 peer_abort_upcall(ep);
2757 break;
2758 case ABORTING:
2759 break;
2760 case DEAD:
2761 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002762 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002763 return 0;
2764 default:
2765 BUG_ON(1);
2766 break;
2767 }
2768 dst_confirm(ep->dst);
2769 if (ep->com.state != ABORTING) {
2770 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302771 /* we don't release if we want to retry with mpa_v1 */
2772 if (!ep->retry_with_mpa_v1)
2773 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002774 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002775 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002776
2777 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2778 if (!rpl_skb) {
2779 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2780 __func__);
2781 release = 1;
2782 goto out;
2783 }
2784 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2785 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2786 INIT_TP_WR(rpl, ep->hwtid);
2787 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2788 rpl->cmd = CPL_ABORT_NO_RST;
2789 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2790out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002791 if (release)
2792 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002793 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302794 if (ep->com.remote_addr.ss_family == AF_INET6) {
2795 struct sockaddr_in6 *sin6 =
2796 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002797 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302798 cxgb4_clip_release(
2799 ep->com.dev->rdev.lldi.ports[0],
2800 (const u32 *)&sin6->sin6_addr.s6_addr,
2801 1);
2802 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002803 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302804 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2805 dst_release(ep->dst);
2806 cxgb4_l2t_release(ep->l2t);
2807 c4iw_reconnect(ep);
2808 }
2809
Steve Wisecfdda9d2010-04-21 15:30:06 -07002810 return 0;
2811}
2812
2813static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2814{
2815 struct c4iw_ep *ep;
2816 struct c4iw_qp_attributes attrs;
2817 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002818 int release = 0;
2819 struct tid_info *t = dev->rdev.lldi.tids;
2820 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002821
2822 ep = lookup_tid(t, tid);
2823
2824 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2825 BUG_ON(!ep);
2826
2827 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002828 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002829 switch (ep->com.state) {
2830 case CLOSING:
2831 __state_set(&ep->com, MORIBUND);
2832 break;
2833 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002834 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002835 if ((ep->com.cm_id) && (ep->com.qp)) {
2836 attrs.next_state = C4IW_QP_STATE_IDLE;
2837 c4iw_modify_qp(ep->com.qp->rhp,
2838 ep->com.qp,
2839 C4IW_QP_ATTR_NEXT_STATE,
2840 &attrs, 1);
2841 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302842 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002843 __state_set(&ep->com, DEAD);
2844 release = 1;
2845 break;
2846 case ABORTING:
2847 case DEAD:
2848 break;
2849 default:
2850 BUG_ON(1);
2851 break;
2852 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002853 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002854 if (release)
2855 release_ep_resources(ep);
2856 return 0;
2857}
2858
2859static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2860{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002861 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002862 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002863 unsigned int tid = GET_TID(rpl);
2864 struct c4iw_ep *ep;
2865 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002866
2867 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002868 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002869
Steve Wise30c95c22011-05-09 22:06:22 -07002870 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002871 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2872 ep->com.qp->wq.sq.qid);
2873 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2874 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2875 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2876 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002877 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002878
Steve Wisecfdda9d2010-04-21 15:30:06 -07002879 return 0;
2880}
2881
2882/*
2883 * Upcall from the adapter indicating data has been transmitted.
2884 * For us its just the single MPA request or reply. We can now free
2885 * the skb holding the mpa message.
2886 */
2887static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2888{
2889 struct c4iw_ep *ep;
2890 struct cpl_fw4_ack *hdr = cplhdr(skb);
2891 u8 credits = hdr->credits;
2892 unsigned int tid = GET_TID(hdr);
2893 struct tid_info *t = dev->rdev.lldi.tids;
2894
2895
2896 ep = lookup_tid(t, tid);
2897 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2898 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002899 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2900 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002901 return 0;
2902 }
2903
2904 dst_confirm(ep->dst);
2905 if (ep->mpa_skb) {
2906 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2907 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2908 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2909 kfree_skb(ep->mpa_skb);
2910 ep->mpa_skb = NULL;
2911 }
2912 return 0;
2913}
2914
Steve Wisecfdda9d2010-04-21 15:30:06 -07002915int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2916{
Steve Wisea7db89e2014-03-21 20:40:35 +05302917 int err = 0;
2918 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002919 struct c4iw_ep *ep = to_ep(cm_id);
2920 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2921
Steve Wisea7db89e2014-03-21 20:40:35 +05302922 mutex_lock(&ep->com.mutex);
2923 if (ep->com.state == DEAD) {
2924 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002925 c4iw_put_ep(&ep->com);
2926 return -ECONNRESET;
2927 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002928 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302929 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002930 if (mpa_rev == 0)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302931 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002932 else {
2933 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302934 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002935 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302936 mutex_unlock(&ep->com.mutex);
2937 if (disconnect)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302938 err = c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002939 c4iw_put_ep(&ep->com);
2940 return 0;
2941}
2942
2943int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2944{
2945 int err;
2946 struct c4iw_qp_attributes attrs;
2947 enum c4iw_qp_attr_mask mask;
2948 struct c4iw_ep *ep = to_ep(cm_id);
2949 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2950 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302951 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002952
2953 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302954
2955 mutex_lock(&ep->com.mutex);
2956 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002957 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302958 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002959 }
2960
Steve Wisea7db89e2014-03-21 20:40:35 +05302961 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002962 BUG_ON(!qp);
2963
Vipul Pandya793dad92012-12-10 09:30:56 +00002964 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302965 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2966 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002967 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302968 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002969 }
2970
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302971 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2972 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302973 if (RELAXED_IRD_NEGOTIATION) {
2974 ep->ord = ep->ird;
2975 } else {
2976 ep->ird = conn_param->ird;
2977 ep->ord = conn_param->ord;
2978 send_mpa_reject(ep, conn_param->private_data,
2979 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302980 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302981 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302982 }
2983 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302984 if (conn_param->ird < ep->ord) {
2985 if (RELAXED_IRD_NEGOTIATION &&
2986 ep->ord <= h->rdev.lldi.max_ordird_qp) {
2987 conn_param->ird = ep->ord;
2988 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302989 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302990 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302991 }
2992 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302993 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002994 ep->ird = conn_param->ird;
2995 ep->ord = conn_param->ord;
2996
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302997 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302998 if (peer2peer && ep->ird == 0)
2999 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303000 } else {
3001 if (peer2peer &&
3002 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303003 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303004 ep->ird = 1;
3005 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003006
3007 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3008
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303009 cm_id->add_ref(cm_id);
3010 ep->com.cm_id = cm_id;
3011 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003012 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303013
Steve Wisecfdda9d2010-04-21 15:30:06 -07003014 /* bind QP to EP and move to RTS */
3015 attrs.mpa_attr = ep->mpa_attr;
3016 attrs.max_ird = ep->ird;
3017 attrs.max_ord = ep->ord;
3018 attrs.llp_stream_handle = ep;
3019 attrs.next_state = C4IW_QP_STATE_RTS;
3020
3021 /* bind QP and TID with INIT_WR */
3022 mask = C4IW_QP_ATTR_NEXT_STATE |
3023 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3024 C4IW_QP_ATTR_MPA_ATTR |
3025 C4IW_QP_ATTR_MAX_IRD |
3026 C4IW_QP_ATTR_MAX_ORD;
3027
3028 err = c4iw_modify_qp(ep->com.qp->rhp,
3029 ep->com.qp, mask, &attrs, 1);
3030 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303031 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003032 err = send_mpa_reply(ep, conn_param->private_data,
3033 conn_param->private_data_len);
3034 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303035 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003036
Steve Wisea7db89e2014-03-21 20:40:35 +05303037 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003038 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303039 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003040 c4iw_put_ep(&ep->com);
3041 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303042err_deref_cm_id:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003043 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003044 cm_id->rem_ref(cm_id);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303045err_abort:
3046 abort = 1;
3047err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303048 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303049 if (abort)
3050 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003051 c4iw_put_ep(&ep->com);
3052 return err;
3053}
3054
Vipul Pandya830662f2013-07-04 16:10:47 +05303055static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3056{
3057 struct in_device *ind;
3058 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003059 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3060 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303061
3062 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3063 if (!ind)
3064 return -EADDRNOTAVAIL;
3065 for_primary_ifa(ind) {
3066 laddr->sin_addr.s_addr = ifa->ifa_address;
3067 raddr->sin_addr.s_addr = ifa->ifa_address;
3068 found = 1;
3069 break;
3070 }
3071 endfor_ifa(ind);
3072 in_dev_put(ind);
3073 return found ? 0 : -EADDRNOTAVAIL;
3074}
3075
3076static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3077 unsigned char banned_flags)
3078{
3079 struct inet6_dev *idev;
3080 int err = -EADDRNOTAVAIL;
3081
3082 rcu_read_lock();
3083 idev = __in6_dev_get(dev);
3084 if (idev != NULL) {
3085 struct inet6_ifaddr *ifp;
3086
3087 read_lock_bh(&idev->lock);
3088 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3089 if (ifp->scope == IFA_LINK &&
3090 !(ifp->flags & banned_flags)) {
3091 memcpy(addr, &ifp->addr, 16);
3092 err = 0;
3093 break;
3094 }
3095 }
3096 read_unlock_bh(&idev->lock);
3097 }
3098 rcu_read_unlock();
3099 return err;
3100}
3101
3102static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3103{
3104 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003105 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3106 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303107
Nicholas Krause54b9a962015-08-26 23:00:59 -04003108 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303109 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3110 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3111 return 0;
3112 }
3113 return -EADDRNOTAVAIL;
3114}
3115
Steve Wisecfdda9d2010-04-21 15:30:06 -07003116int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3117{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003118 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3119 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003120 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003121 struct sockaddr_in *laddr;
3122 struct sockaddr_in *raddr;
3123 struct sockaddr_in6 *laddr6;
3124 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303125 __u8 *ra;
3126 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003127
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303128 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3129 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003130 err = -EINVAL;
3131 goto out;
3132 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003133 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3134 if (!ep) {
3135 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3136 err = -ENOMEM;
3137 goto out;
3138 }
3139 init_timer(&ep->timer);
3140 ep->plen = conn_param->private_data_len;
3141 if (ep->plen)
3142 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3143 conn_param->private_data, ep->plen);
3144 ep->ird = conn_param->ird;
3145 ep->ord = conn_param->ord;
3146
3147 if (peer2peer && ep->ord == 0)
3148 ep->ord = 1;
3149
3150 cm_id->add_ref(cm_id);
3151 ep->com.dev = dev;
3152 ep->com.cm_id = cm_id;
3153 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303154 if (!ep->com.qp) {
3155 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3156 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003157 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303158 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003159 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003160 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3161 ep->com.qp, cm_id);
3162
3163 /*
3164 * Allocate an active TID to initiate a TCP connection.
3165 */
3166 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3167 if (ep->atid == -1) {
3168 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3169 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003170 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003171 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003172 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003173
Steve Wise170003c2016-02-26 09:18:03 -06003174 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003175 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003176 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003177 sizeof(ep->com.remote_addr));
3178
Steve Wise170003c2016-02-26 09:18:03 -06003179 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3180 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3181 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3182 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003183
Steve Wise170003c2016-02-26 09:18:03 -06003184 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303185 iptype = 4;
3186 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003187
Vipul Pandya830662f2013-07-04 16:10:47 +05303188 /*
3189 * Handle loopback requests to INADDR_ANY.
3190 */
3191 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3192 err = pick_local_ipaddrs(dev, cm_id);
3193 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003194 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303195 }
3196
3197 /* find a route */
3198 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3199 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3200 ra, ntohs(raddr->sin_port));
3201 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3202 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303203 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303204 } else {
3205 iptype = 6;
3206 ra = (__u8 *)&raddr6->sin6_addr;
3207
3208 /*
3209 * Handle loopback requests to INADDR_ANY.
3210 */
3211 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3212 err = pick_local_ip6addrs(dev, cm_id);
3213 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003214 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303215 }
3216
3217 /* find a route */
3218 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3219 __func__, laddr6->sin6_addr.s6_addr,
3220 ntohs(laddr6->sin6_port),
3221 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3222 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3223 raddr6->sin6_addr.s6_addr,
3224 laddr6->sin6_port, raddr6->sin6_port, 0,
3225 raddr6->sin6_scope_id);
3226 }
3227 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003228 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3229 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003230 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003231 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003232
Hariprasad S963cab52015-09-23 17:19:27 +05303233 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303234 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003235 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003236 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003237 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003238 }
3239
3240 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3241 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3242 ep->l2t->idx);
3243
3244 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303245 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003246
3247 /* send connect request to rnic */
3248 err = send_connect(ep);
3249 if (!err)
3250 goto out;
3251
3252 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003253fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003254 dst_release(ep->dst);
3255fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003256 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003257 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003258fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003259 cm_id->rem_ref(cm_id);
3260 c4iw_put_ep(&ep->com);
3261out:
3262 return err;
3263}
3264
Vipul Pandya830662f2013-07-04 16:10:47 +05303265static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3266{
3267 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003268 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003269 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303270
Hariprasad S28de1f72016-01-13 10:03:14 +05303271 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3272 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3273 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3274 if (err)
3275 return err;
3276 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303277 c4iw_init_wr_wait(&ep->com.wr_wait);
3278 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3279 ep->stid, &sin6->sin6_addr,
3280 sin6->sin6_port,
3281 ep->com.dev->rdev.lldi.rxq_ids[0]);
3282 if (!err)
3283 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3284 &ep->com.wr_wait,
3285 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303286 else if (err > 0)
3287 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303288 if (err) {
3289 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3290 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303291 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3292 err, ep->stid,
3293 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303294 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303295 return err;
3296}
3297
3298static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3299{
3300 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003301 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003302 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303303
3304 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3305 do {
3306 err = cxgb4_create_server_filter(
3307 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3308 sin->sin_addr.s_addr, sin->sin_port, 0,
3309 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3310 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303311 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3312 err = -EIO;
3313 break;
3314 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303315 set_current_state(TASK_UNINTERRUPTIBLE);
3316 schedule_timeout(usecs_to_jiffies(100));
3317 }
3318 } while (err == -EBUSY);
3319 } else {
3320 c4iw_init_wr_wait(&ep->com.wr_wait);
3321 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3322 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3323 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3324 if (!err)
3325 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3326 &ep->com.wr_wait,
3327 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303328 else if (err > 0)
3329 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303330 }
3331 if (err)
3332 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3333 , err, ep->stid,
3334 &sin->sin_addr, ntohs(sin->sin_port));
3335 return err;
3336}
3337
Steve Wisecfdda9d2010-04-21 15:30:06 -07003338int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3339{
3340 int err = 0;
3341 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3342 struct c4iw_listen_ep *ep;
3343
Steve Wisecfdda9d2010-04-21 15:30:06 -07003344 might_sleep();
3345
3346 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3347 if (!ep) {
3348 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3349 err = -ENOMEM;
3350 goto fail1;
3351 }
3352 PDBG("%s ep %p\n", __func__, ep);
3353 cm_id->add_ref(cm_id);
3354 ep->com.cm_id = cm_id;
3355 ep->com.dev = dev;
3356 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003357 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303358 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003359
3360 /*
3361 * Allocate a server TID.
3362 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303363 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3364 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303365 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003366 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003367 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303368 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003369 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003370
Steve Wisecfdda9d2010-04-21 15:30:06 -07003371 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003372 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003373 err = -ENOMEM;
3374 goto fail2;
3375 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003376 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003377
Steve Wise170003c2016-02-26 09:18:03 -06003378 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3379 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003380
Steve Wisecfdda9d2010-04-21 15:30:06 -07003381 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303382 if (ep->com.local_addr.ss_family == AF_INET)
3383 err = create_server4(dev, ep);
3384 else
3385 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003386 if (!err) {
3387 cm_id->provider_data = ep;
3388 goto out;
3389 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003390
Vipul Pandya830662f2013-07-04 16:10:47 +05303391 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3392 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003393fail2:
3394 cm_id->rem_ref(cm_id);
3395 c4iw_put_ep(&ep->com);
3396fail1:
3397out:
3398 return err;
3399}
3400
3401int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3402{
3403 int err;
3404 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3405
3406 PDBG("%s ep %p\n", __func__, ep);
3407
3408 might_sleep();
3409 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303410 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3411 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003412 err = cxgb4_remove_server_filter(
3413 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3414 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3415 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303416 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003417 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303418 err = cxgb4_remove_server(
3419 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3420 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003421 if (err)
3422 goto done;
3423 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3424 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003425 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303426 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3427 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003428 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003429 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303430 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3431 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003432done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003433 cm_id->rem_ref(cm_id);
3434 c4iw_put_ep(&ep->com);
3435 return err;
3436}
3437
3438int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3439{
3440 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003441 int close = 0;
3442 int fatal = 0;
3443 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003444
Steve Wise2f5b48c2010-09-10 11:15:36 -05003445 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003446
3447 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3448 states[ep->com.state], abrupt);
3449
Hariprasad S6e410d82016-05-05 01:27:31 +05303450 /*
3451 * Ref the ep here in case we have fatal errors causing the
3452 * ep to be released and freed.
3453 */
3454 c4iw_get_ep(&ep->com);
3455
Steve Wisecfdda9d2010-04-21 15:30:06 -07003456 rdev = &ep->com.dev->rdev;
3457 if (c4iw_fatal_error(rdev)) {
3458 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303459 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003460 ep->com.state = DEAD;
3461 }
3462 switch (ep->com.state) {
3463 case MPA_REQ_WAIT:
3464 case MPA_REQ_SENT:
3465 case MPA_REQ_RCVD:
3466 case MPA_REP_SENT:
3467 case FPDU_MODE:
3468 close = 1;
3469 if (abrupt)
3470 ep->com.state = ABORTING;
3471 else {
3472 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003473 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003474 }
3475 set_bit(CLOSE_SENT, &ep->com.flags);
3476 break;
3477 case CLOSING:
3478 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3479 close = 1;
3480 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003481 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003482 ep->com.state = ABORTING;
3483 } else
3484 ep->com.state = MORIBUND;
3485 }
3486 break;
3487 case MORIBUND:
3488 case ABORTING:
3489 case DEAD:
3490 PDBG("%s ignoring disconnect ep %p state %u\n",
3491 __func__, ep, ep->com.state);
3492 break;
3493 default:
3494 BUG();
3495 break;
3496 }
3497
Steve Wisecfdda9d2010-04-21 15:30:06 -07003498 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003499 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003500 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303501 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003502 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003503 } else {
3504 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003505 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003506 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303507 if (ret) {
3508 if (!abrupt) {
3509 stop_ep_timer(ep);
3510 close_complete_upcall(ep, -EIO);
3511 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303512 if (ep->com.qp) {
3513 struct c4iw_qp_attributes attrs;
3514
3515 attrs.next_state = C4IW_QP_STATE_ERROR;
3516 ret = c4iw_modify_qp(ep->com.qp->rhp,
3517 ep->com.qp,
3518 C4IW_QP_ATTR_NEXT_STATE,
3519 &attrs, 1);
3520 if (ret)
3521 pr_err(MOD
3522 "%s - qp <- error failed!\n",
3523 __func__);
3524 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003525 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303526 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003527 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003528 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303529 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003530 if (fatal)
3531 release_ep_resources(ep);
3532 return ret;
3533}
3534
Vipul Pandya1cab7752012-12-10 09:30:55 +00003535static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3536 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3537{
3538 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003539 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003540
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003541 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3542 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003543 if (!ep)
3544 return;
3545
3546 switch (req->retval) {
3547 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003548 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3549 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3550 send_fw_act_open_req(ep, atid);
3551 return;
3552 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003553 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003554 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3555 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3556 send_fw_act_open_req(ep, atid);
3557 return;
3558 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003559 break;
3560 default:
3561 pr_info("%s unexpected ofld conn wr retval %d\n",
3562 __func__, req->retval);
3563 break;
3564 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003565 pr_err("active ofld_connect_wr failure %d atid %d\n",
3566 req->retval, atid);
3567 mutex_lock(&dev->rdev.stats.lock);
3568 dev->rdev.stats.act_ofld_conn_fails++;
3569 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003570 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003571 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303572 if (ep->com.remote_addr.ss_family == AF_INET6) {
3573 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003574 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303575 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3576 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3577 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003578 remove_handle(dev, &dev->atid_idr, atid);
3579 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3580 dst_release(ep->dst);
3581 cxgb4_l2t_release(ep->l2t);
3582 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003583}
3584
3585static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3586 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3587{
3588 struct sk_buff *rpl_skb;
3589 struct cpl_pass_accept_req *cpl;
3590 int ret;
3591
Paul Bolle710a3112013-02-05 20:51:30 +00003592 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003593 BUG_ON(!rpl_skb);
3594 if (req->retval) {
3595 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003596 mutex_lock(&dev->rdev.stats.lock);
3597 dev->rdev.stats.pas_ofld_conn_fails++;
3598 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003599 kfree_skb(rpl_skb);
3600 } else {
3601 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3602 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003603 (__force u32) htonl(
3604 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003605 ret = pass_accept_req(dev, rpl_skb);
3606 if (!ret)
3607 kfree_skb(rpl_skb);
3608 }
3609 return;
3610}
3611
3612static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003613{
3614 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003615 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3616
3617 switch (rpl->type) {
3618 case FW6_TYPE_CQE:
3619 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3620 break;
3621 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3622 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3623 switch (req->t_state) {
3624 case TCP_SYN_SENT:
3625 active_ofld_conn_reply(dev, skb, req);
3626 break;
3627 case TCP_SYN_RECV:
3628 passive_ofld_conn_reply(dev, skb, req);
3629 break;
3630 default:
3631 pr_err("%s unexpected ofld conn wr state %d\n",
3632 __func__, req->t_state);
3633 break;
3634 }
3635 break;
3636 }
3637 return 0;
3638}
3639
3640static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3641{
Hariprasad S963cab52015-09-23 17:19:27 +05303642 __be32 l2info;
3643 __be16 hdr_len, vlantag, len;
3644 u16 eth_hdr_len;
3645 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003646 u8 intf;
3647 struct cpl_rx_pkt *cpl = cplhdr(skb);
3648 struct cpl_pass_accept_req *req;
3649 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003650 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303651 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003652
Vipul Pandyaf079af72013-03-14 05:08:58 +00003653 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003654 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303655 vlantag = cpl->vlan;
3656 len = cpl->len;
3657 l2info = cpl->l2info;
3658 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003659 intf = cpl->iff;
3660
3661 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3662
3663 /*
3664 * We need to parse the TCP options from SYN packet.
3665 * to generate cpl_pass_accept_req.
3666 */
3667 memset(&tmp_opt, 0, sizeof(tmp_opt));
3668 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003669 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003670
3671 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3672 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303673 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3674 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303675 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303676 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303677 type = dev->rdev.lldi.adapter_type;
3678 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3679 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3680 req->hdr_len =
3681 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3682 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3683 eth_hdr_len = is_t4(type) ?
3684 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3685 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3686 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3687 IP_HDR_LEN_V(ip_hdr_len) |
3688 ETH_HDR_LEN_V(eth_hdr_len));
3689 } else { /* T6 and later */
3690 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3691 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3692 T6_IP_HDR_LEN_V(ip_hdr_len) |
3693 T6_ETH_HDR_LEN_V(eth_hdr_len));
3694 }
3695 req->vlan = vlantag;
3696 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003697 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3698 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003699 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3700 if (tmp_opt.wscale_ok)
3701 req->tcpopt.wsf = tmp_opt.snd_wscale;
3702 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3703 if (tmp_opt.sack_ok)
3704 req->tcpopt.sack = 1;
3705 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3706 return;
3707}
3708
3709static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3710 __be32 laddr, __be16 lport,
3711 __be32 raddr, __be16 rport,
3712 u32 rcv_isn, u32 filter, u16 window,
3713 u32 rss_qid, u8 port_id)
3714{
3715 struct sk_buff *req_skb;
3716 struct fw_ofld_connection_wr *req;
3717 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303718 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003719
3720 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3721 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3722 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003723 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303724 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303725 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003726 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003727 req->le.lport = lport;
3728 req->le.pport = rport;
3729 req->le.u.ipv4.lip = laddr;
3730 req->le.u.ipv4.pip = raddr;
3731 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3732 req->tcb.rcv_adv = htons(window);
3733 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303734 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3735 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3736 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003737 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003738
3739 /*
3740 * We store the qid in opt2 which will be used by the firmware
3741 * to send us the wr response.
3742 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003743 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003744
3745 /*
3746 * We initialize the MSS index in TCB to 0xF.
3747 * So that when driver sends cpl_pass_accept_rpl
3748 * TCB picks up the correct value. If this was 0
3749 * TP will ignore any value > 0 for MSS index.
3750 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003751 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303752 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003753
3754 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303755 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3756 if (ret < 0) {
3757 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3758 ret);
3759 kfree_skb(skb);
3760 kfree_skb(req_skb);
3761 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003762}
3763
3764/*
3765 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3766 * messages when a filter is being used instead of server to
3767 * redirect a syn packet. When packets hit filter they are redirected
3768 * to the offload queue and driver tries to establish the connection
3769 * using firmware work request.
3770 */
3771static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3772{
3773 int stid;
3774 unsigned int filter;
3775 struct ethhdr *eh = NULL;
3776 struct vlan_ethhdr *vlan_eh = NULL;
3777 struct iphdr *iph;
3778 struct tcphdr *tcph;
3779 struct rss_header *rss = (void *)skb->data;
3780 struct cpl_rx_pkt *cpl = (void *)skb->data;
3781 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3782 struct l2t_entry *e;
3783 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003784 struct c4iw_ep *lep;
3785 u16 window;
3786 struct port_info *pi;
3787 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003788 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003789 int step;
3790 u32 tx_chan;
3791 struct neighbour *neigh;
3792
3793 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003794 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003795 goto reject;
3796
3797 /*
3798 * Drop all packets which did not hit the filter.
3799 * Unlikely to happen.
3800 */
3801 if (!(rss->filter_hit && rss->filter_tid))
3802 goto reject;
3803
3804 /*
3805 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3806 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303807 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003808
3809 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3810 if (!lep) {
3811 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3812 goto reject;
3813 }
3814
Hariprasad S963cab52015-09-23 17:19:27 +05303815 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3816 case CHELSIO_T4:
3817 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3818 break;
3819 case CHELSIO_T5:
3820 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3821 break;
3822 case CHELSIO_T6:
3823 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3824 break;
3825 default:
3826 pr_err("T%d Chip is not supported\n",
3827 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3828 goto reject;
3829 }
3830
Vipul Pandyaf079af72013-03-14 05:08:58 +00003831 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003832 eh = (struct ethhdr *)(req + 1);
3833 iph = (struct iphdr *)(eh + 1);
3834 } else {
3835 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3836 iph = (struct iphdr *)(vlan_eh + 1);
3837 skb->vlan_tci = ntohs(cpl->vlan);
3838 }
3839
3840 if (iph->version != 0x4)
3841 goto reject;
3842
3843 tcph = (struct tcphdr *)(iph + 1);
3844 skb_set_network_header(skb, (void *)iph - (void *)rss);
3845 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3846 skb_get(skb);
3847
3848 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3849 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3850 ntohs(tcph->source), iph->tos);
3851
Vipul Pandya830662f2013-07-04 16:10:47 +05303852 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3853 iph->tos);
3854 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003855 pr_err("%s - failed to find dst entry!\n",
3856 __func__);
3857 goto reject;
3858 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003859 neigh = dst_neigh_lookup_skb(dst, skb);
3860
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003861 if (!neigh) {
3862 pr_err("%s - failed to allocate neigh!\n",
3863 __func__);
3864 goto free_dst;
3865 }
3866
Vipul Pandya1cab7752012-12-10 09:30:55 +00003867 if (neigh->dev->flags & IFF_LOOPBACK) {
3868 pdev = ip_dev_find(&init_net, iph->daddr);
3869 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3870 pdev, 0);
3871 pi = (struct port_info *)netdev_priv(pdev);
3872 tx_chan = cxgb4_port_chan(pdev);
3873 dev_put(pdev);
3874 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303875 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003876 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303877 pdev, 0);
3878 pi = (struct port_info *)netdev_priv(pdev);
3879 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003880 }
Steve Wiseebf00062014-03-19 17:44:40 +05303881 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003882 if (!e) {
3883 pr_err("%s - failed to allocate l2t entry!\n",
3884 __func__);
3885 goto free_dst;
3886 }
3887
3888 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3889 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003890 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003891
3892 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303893 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3894 dev->rdev.lldi.ports[0],
3895 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003896
3897 /*
3898 * Synthesize the cpl_pass_accept_req. We have everything except the
3899 * TID. Once firmware sends a reply with TID we update the TID field
3900 * in cpl and pass it through the regular cpl_pass_accept_req path.
3901 */
3902 build_cpl_pass_accept_req(skb, stid, iph->tos);
3903 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3904 tcph->source, ntohl(tcph->seq), filter, window,
3905 rss_qid, pi->port_id);
3906 cxgb4_l2t_release(e);
3907free_dst:
3908 dst_release(dst);
3909reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003910 return 0;
3911}
3912
Steve Wisecfdda9d2010-04-21 15:30:06 -07003913/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003914 * These are the real handlers that are called from a
3915 * work queue.
3916 */
Hariprasad S9dec9002016-05-05 01:27:29 +05303917static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003918 [CPL_ACT_ESTABLISH] = act_establish,
3919 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3920 [CPL_RX_DATA] = rx_data,
3921 [CPL_ABORT_RPL_RSS] = abort_rpl,
3922 [CPL_ABORT_RPL] = abort_rpl,
3923 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3924 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3925 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3926 [CPL_PASS_ESTABLISH] = pass_establish,
3927 [CPL_PEER_CLOSE] = peer_close,
3928 [CPL_ABORT_REQ_RSS] = peer_abort,
3929 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3930 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003931 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003932 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05303933 [CPL_RX_PKT] = rx_pkt,
3934 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003935};
3936
3937static void process_timeout(struct c4iw_ep *ep)
3938{
3939 struct c4iw_qp_attributes attrs;
3940 int abort = 1;
3941
Steve Wise2f5b48c2010-09-10 11:15:36 -05003942 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003943 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3944 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003945 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003946 switch (ep->com.state) {
3947 case MPA_REQ_SENT:
3948 __state_set(&ep->com, ABORTING);
3949 connect_reply_upcall(ep, -ETIMEDOUT);
3950 break;
3951 case MPA_REQ_WAIT:
3952 __state_set(&ep->com, ABORTING);
3953 break;
3954 case CLOSING:
3955 case MORIBUND:
3956 if (ep->com.cm_id && ep->com.qp) {
3957 attrs.next_state = C4IW_QP_STATE_ERROR;
3958 c4iw_modify_qp(ep->com.qp->rhp,
3959 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3960 &attrs, 1);
3961 }
3962 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303963 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003964 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003965 case ABORTING:
3966 case DEAD:
3967
3968 /*
3969 * These states are expected if the ep timed out at the same
3970 * time as another thread was calling stop_ep_timer().
3971 * So we silently do nothing for these states.
3972 */
3973 abort = 0;
3974 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003975 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003976 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003977 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003978 abort = 0;
3979 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003980 if (abort)
3981 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecc18b932014-04-24 14:31:53 -05003982 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003983 c4iw_put_ep(&ep->com);
3984}
3985
3986static void process_timedout_eps(void)
3987{
3988 struct c4iw_ep *ep;
3989
3990 spin_lock_irq(&timeout_lock);
3991 while (!list_empty(&timeout_list)) {
3992 struct list_head *tmp;
3993
3994 tmp = timeout_list.next;
3995 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003996 tmp->next = NULL;
3997 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003998 spin_unlock_irq(&timeout_lock);
3999 ep = list_entry(tmp, struct c4iw_ep, entry);
4000 process_timeout(ep);
4001 spin_lock_irq(&timeout_lock);
4002 }
4003 spin_unlock_irq(&timeout_lock);
4004}
4005
4006static void process_work(struct work_struct *work)
4007{
4008 struct sk_buff *skb = NULL;
4009 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004010 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004011 unsigned int opcode;
4012 int ret;
4013
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004014 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004015 while ((skb = skb_dequeue(&rxq))) {
4016 rpl = cplhdr(skb);
4017 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4018 opcode = rpl->ot.opcode;
4019
4020 BUG_ON(!work_handlers[opcode]);
4021 ret = work_handlers[opcode](dev, skb);
4022 if (!ret)
4023 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004024 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004025 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004026}
4027
4028static DECLARE_WORK(skb_work, process_work);
4029
4030static void ep_timeout(unsigned long arg)
4031{
4032 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004033 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004034
4035 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004036 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004037 /*
4038 * Only insert if it is not already on the list.
4039 */
4040 if (!ep->entry.next) {
4041 list_add_tail(&ep->entry, &timeout_list);
4042 kickit = 1;
4043 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004044 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004045 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004046 if (kickit)
4047 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004048}
4049
4050/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004051 * All the CM events are handled on a work queue to have a safe context.
4052 */
4053static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4054{
4055
4056 /*
4057 * Save dev in the skb->cb area.
4058 */
4059 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4060
4061 /*
4062 * Queue the skb and schedule the worker thread.
4063 */
4064 skb_queue_tail(&rxq, skb);
4065 queue_work(workq, &skb_work);
4066 return 0;
4067}
4068
4069static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4070{
4071 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4072
4073 if (rpl->status != CPL_ERR_NONE) {
4074 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4075 "for tid %u\n", rpl->status, GET_TID(rpl));
4076 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004077 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004078 return 0;
4079}
4080
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004081static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4082{
4083 struct cpl_fw6_msg *rpl = cplhdr(skb);
4084 struct c4iw_wr_wait *wr_waitp;
4085 int ret;
4086
4087 PDBG("%s type %u\n", __func__, rpl->type);
4088
4089 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004090 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004091 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004092 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004093 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004094 if (wr_waitp)
4095 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004096 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004097 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004098 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004099 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004100 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004101 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004102 default:
4103 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4104 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004105 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004106 break;
4107 }
4108 return 0;
4109}
4110
Steve Wise8da7e7a2011-06-14 20:59:27 +00004111static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4112{
4113 struct cpl_abort_req_rss *req = cplhdr(skb);
4114 struct c4iw_ep *ep;
4115 struct tid_info *t = dev->rdev.lldi.tids;
4116 unsigned int tid = GET_TID(req);
4117
4118 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05004119 if (!ep) {
4120 printk(KERN_WARNING MOD
4121 "Abort on non-existent endpoint, tid %d\n", tid);
4122 kfree_skb(skb);
4123 return 0;
4124 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304125 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304126 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4127 __func__, ep->hwtid, req->status,
4128 neg_adv_str(req->status));
4129 ep->stats.abort_neg_adv++;
4130 dev->rdev.stats.neg_adv++;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004131 kfree_skb(skb);
4132 return 0;
4133 }
4134 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4135 ep->com.state);
4136
4137 /*
4138 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004139 * However, if we are on MPAv2 and want to retry with MPAv1
4140 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004141 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004142 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4143 if (ep->com.state != MPA_REQ_SENT)
4144 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4145 } else
4146 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00004147 sched(dev, skb);
4148 return 0;
4149}
4150
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004151/*
4152 * Most upcalls from the T4 Core go to sched() to
4153 * schedule the processing on a work queue.
4154 */
4155c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4156 [CPL_ACT_ESTABLISH] = sched,
4157 [CPL_ACT_OPEN_RPL] = sched,
4158 [CPL_RX_DATA] = sched,
4159 [CPL_ABORT_RPL_RSS] = sched,
4160 [CPL_ABORT_RPL] = sched,
4161 [CPL_PASS_OPEN_RPL] = sched,
4162 [CPL_CLOSE_LISTSRV_RPL] = sched,
4163 [CPL_PASS_ACCEPT_REQ] = sched,
4164 [CPL_PASS_ESTABLISH] = sched,
4165 [CPL_PEER_CLOSE] = sched,
4166 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004167 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004168 [CPL_RDMA_TERMINATE] = sched,
4169 [CPL_FW4_ACK] = sched,
4170 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004171 [CPL_FW6_MSG] = fw6_msg,
4172 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004173};
4174
Steve Wisecfdda9d2010-04-21 15:30:06 -07004175int __init c4iw_cm_init(void)
4176{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004177 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004178 skb_queue_head_init(&rxq);
4179
4180 workq = create_singlethread_workqueue("iw_cxgb4");
4181 if (!workq)
4182 return -ENOMEM;
4183
Steve Wisecfdda9d2010-04-21 15:30:06 -07004184 return 0;
4185}
4186
Steve Wise46c13762014-06-20 14:26:25 -05004187void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004188{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004189 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004190 flush_workqueue(workq);
4191 destroy_workqueue(workq);
4192}