blob: 410154c86061d734be5de8fb53cebe089fc18d68 [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, "
Hariprasad Sccd2c302016-05-06 22:17:55 +0530122 "1 is RFC5044 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
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530153static void deref_cm_id(struct c4iw_ep_common *epc)
154{
155 epc->cm_id->rem_ref(epc->cm_id);
156 epc->cm_id = NULL;
157 set_bit(CM_ID_DEREFED, &epc->history);
158}
159
160static void ref_cm_id(struct c4iw_ep_common *epc)
161{
162 set_bit(CM_ID_REFED, &epc->history);
163 epc->cm_id->add_ref(epc->cm_id);
164}
165
Vipul Pandya325abea2013-01-07 13:11:53 +0000166static void deref_qp(struct c4iw_ep *ep)
167{
168 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
169 clear_bit(QP_REFERENCED, &ep->com.flags);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530170 set_bit(QP_DEREFED, &ep->com.history);
Vipul Pandya325abea2013-01-07 13:11:53 +0000171}
172
173static void ref_qp(struct c4iw_ep *ep)
174{
175 set_bit(QP_REFERENCED, &ep->com.flags);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530176 set_bit(QP_REFED, &ep->com.history);
Vipul Pandya325abea2013-01-07 13:11:53 +0000177 c4iw_qp_add_ref(&ep->com.qp->ibqp);
178}
179
Steve Wisecfdda9d2010-04-21 15:30:06 -0700180static void start_ep_timer(struct c4iw_ep *ep)
181{
182 PDBG("%s ep %p\n", __func__, ep);
183 if (timer_pending(&ep->timer)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000184 pr_err("%s timer already started! ep %p\n",
185 __func__, ep);
186 return;
187 }
188 clear_bit(TIMEOUT, &ep->com.flags);
189 c4iw_get_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700190 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
191 ep->timer.data = (unsigned long)ep;
192 ep->timer.function = ep_timeout;
193 add_timer(&ep->timer);
194}
195
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500196static int stop_ep_timer(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700197{
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000198 PDBG("%s ep %p stopping\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700199 del_timer_sync(&ep->timer);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500200 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000201 c4iw_put_ep(&ep->com);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500202 return 0;
203 }
204 return 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700205}
206
207static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
208 struct l2t_entry *l2e)
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_l2t_send(rdev->lldi.ports[0], skb, l2e);
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
223int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
224{
225 int error = 0;
226
227 if (c4iw_fatal_error(rdev)) {
228 kfree_skb(skb);
229 PDBG("%s - device in error state - dropping\n", __func__);
230 return -EIO;
231 }
232 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
233 if (error < 0)
234 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500235 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700236}
237
238static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
239{
240 struct cpl_tid_release *req;
241
242 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
243 if (!skb)
244 return;
245 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
246 INIT_TP_WR(req, hwtid);
247 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
248 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
249 c4iw_ofld_send(rdev, skb);
250 return;
251}
252
253static void set_emss(struct c4iw_ep *ep, u16 opt)
254{
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800255 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
Hariprasad S04524a42014-09-24 03:53:41 +0530256 ((AF_INET == ep->com.remote_addr.ss_family) ?
257 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
258 sizeof(struct tcphdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700259 ep->mss = ep->emss;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800260 if (TCPOPT_TSTAMP_G(opt))
Hariprasad S04524a42014-09-24 03:53:41 +0530261 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700262 if (ep->emss < 128)
263 ep->emss = 128;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530264 if (ep->emss & 7)
265 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800266 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
267 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt),
Steve Wisecfdda9d2010-04-21 15:30:06 -0700268 ep->mss, ep->emss);
269}
270
271static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
272{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700273 enum c4iw_ep_state state;
274
Steve Wise2f5b48c2010-09-10 11:15:36 -0500275 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700276 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500277 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700278 return state;
279}
280
281static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
282{
283 epc->state = new;
284}
285
286static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
287{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500288 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700289 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
290 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500291 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700292 return;
293}
294
295static void *alloc_ep(int size, gfp_t gfp)
296{
297 struct c4iw_ep_common *epc;
298
299 epc = kzalloc(size, gfp);
300 if (epc) {
301 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500302 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500303 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700304 }
305 PDBG("%s alloc ep %p\n", __func__, epc);
306 return epc;
307}
308
309void _c4iw_free_ep(struct kref *kref)
310{
311 struct c4iw_ep *ep;
312
313 ep = container_of(kref, struct c4iw_ep, com.kref);
Hariprasad S9dec9002016-05-05 01:27:29 +0530314 PDBG("%s ep %p state %s\n", __func__, ep, states[ep->com.state]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000315 if (test_bit(QP_REFERENCED, &ep->com.flags))
316 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700317 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530318 if (ep->com.remote_addr.ss_family == AF_INET6) {
319 struct sockaddr_in6 *sin6 =
320 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600321 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530322
323 cxgb4_clip_release(
324 ep->com.dev->rdev.lldi.ports[0],
325 (const u32 *)&sin6->sin6_addr.s6_addr,
326 1);
327 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000328 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700329 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
330 dst_release(ep->dst);
331 cxgb4_l2t_release(ep->l2t);
332 }
333 kfree(ep);
334}
335
336static void release_ep_resources(struct c4iw_ep *ep)
337{
338 set_bit(RELEASE_RESOURCES, &ep->com.flags);
339 c4iw_put_ep(&ep->com);
340}
341
Steve Wisecfdda9d2010-04-21 15:30:06 -0700342static int status2errno(int status)
343{
344 switch (status) {
345 case CPL_ERR_NONE:
346 return 0;
347 case CPL_ERR_CONN_RESET:
348 return -ECONNRESET;
349 case CPL_ERR_ARP_MISS:
350 return -EHOSTUNREACH;
351 case CPL_ERR_CONN_TIMEDOUT:
352 return -ETIMEDOUT;
353 case CPL_ERR_TCAM_FULL:
354 return -ENOMEM;
355 case CPL_ERR_CONN_EXIST:
356 return -EADDRINUSE;
357 default:
358 return -EIO;
359 }
360}
361
362/*
363 * Try and reuse skbs already allocated...
364 */
365static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
366{
367 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
368 skb_trim(skb, 0);
369 skb_get(skb);
370 skb_reset_transport_header(skb);
371 } else {
372 skb = alloc_skb(len, gfp);
373 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530374 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700375 return skb;
376}
377
Vipul Pandya830662f2013-07-04 16:10:47 +0530378static struct net_device *get_real_dev(struct net_device *egress_dev)
379{
Steve Wise11b8e222014-05-16 12:42:46 -0500380 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530381}
382
383static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
384{
385 int i;
386
387 egress_dev = get_real_dev(egress_dev);
388 for (i = 0; i < dev->rdev.lldi.nports; i++)
389 if (dev->rdev.lldi.ports[i] == egress_dev)
390 return 1;
391 return 0;
392}
393
394static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
395 __u8 *peer_ip, __be16 local_port,
396 __be16 peer_port, u8 tos,
397 __u32 sin6_scope_id)
398{
399 struct dst_entry *dst = NULL;
400
401 if (IS_ENABLED(CONFIG_IPV6)) {
402 struct flowi6 fl6;
403
404 memset(&fl6, 0, sizeof(fl6));
405 memcpy(&fl6.daddr, peer_ip, 16);
406 memcpy(&fl6.saddr, local_ip, 16);
407 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
408 fl6.flowi6_oif = sin6_scope_id;
409 dst = ip6_route_output(&init_net, NULL, &fl6);
410 if (!dst)
411 goto out;
412 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
413 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
414 dst_release(dst);
415 dst = NULL;
416 }
417 }
418
419out:
420 return dst;
421}
422
423static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700424 __be32 peer_ip, __be16 local_port,
425 __be16 peer_port, u8 tos)
426{
427 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700428 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530429 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700430
David S. Miller31e4543d2011-05-03 20:25:42 -0700431 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500432 peer_port, local_port, IPPROTO_TCP,
433 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800434 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700435 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530436 n = dst_neigh_lookup(&rt->dst, &peer_ip);
437 if (!n)
438 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530439 if (!our_interface(dev, n->dev) &&
440 !(n->dev->flags & IFF_LOOPBACK)) {
Hariprasad Sd4802012014-09-24 03:53:42 +0530441 neigh_release(n);
Vipul Pandya830662f2013-07-04 16:10:47 +0530442 dst_release(&rt->dst);
443 return NULL;
444 }
445 neigh_release(n);
446 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700447}
448
449static void arp_failure_discard(void *handle, struct sk_buff *skb)
450{
Hariprasad S9dec9002016-05-05 01:27:29 +0530451 pr_err(MOD "ARP failure\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700452 kfree_skb(skb);
453}
454
Hariprasad S9dec9002016-05-05 01:27:29 +0530455enum {
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530456 NUM_FAKE_CPLS = 2,
Hariprasad S9dec9002016-05-05 01:27:29 +0530457 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530458 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
Hariprasad S9dec9002016-05-05 01:27:29 +0530459};
460
461static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
462{
463 struct c4iw_ep *ep;
464
465 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
466 release_ep_resources(ep);
467 return 0;
468}
469
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530470static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
471{
472 struct c4iw_ep *ep;
473
474 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
475 c4iw_put_ep(&ep->parent_ep->com);
476 release_ep_resources(ep);
477 return 0;
478}
479
Hariprasad S9dec9002016-05-05 01:27:29 +0530480/*
481 * Fake up a special CPL opcode and call sched() so process_work() will call
482 * _put_ep_safe() in a safe context to free the ep resources. This is needed
483 * because ARP error handlers are called in an ATOMIC context, and
484 * _c4iw_free_ep() needs to block.
485 */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530486static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
487 int cpl)
Hariprasad S9dec9002016-05-05 01:27:29 +0530488{
489 struct cpl_act_establish *rpl = cplhdr(skb);
490
491 /* Set our special ARP_FAILURE opcode */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530492 rpl->ot.opcode = cpl;
Hariprasad S9dec9002016-05-05 01:27:29 +0530493
494 /*
495 * Save ep in the skb->cb area, after where sched() will save the dev
496 * ptr.
497 */
498 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
499 sched(ep->com.dev, skb);
500}
501
502/* Handle an ARP failure for an accept */
503static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
504{
505 struct c4iw_ep *ep = handle;
506
507 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
508 ep->hwtid);
509
510 __state_set(&ep->com, DEAD);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530511 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
Hariprasad S9dec9002016-05-05 01:27:29 +0530512}
513
Steve Wisecfdda9d2010-04-21 15:30:06 -0700514/*
515 * Handle an ARP failure for an active open.
516 */
517static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
518{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530519 struct c4iw_ep *ep = handle;
520
Masanari Iidae3d132d2015-10-16 21:14:29 +0900521 printk(KERN_ERR MOD "ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530522 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530523 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530524 if (ep->com.remote_addr.ss_family == AF_INET6) {
525 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600526 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530527 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
528 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
529 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530530 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
531 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530532 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700533}
534
535/*
536 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
537 * and send it along.
538 */
539static void abort_arp_failure(void *handle, struct sk_buff *skb)
540{
541 struct c4iw_rdev *rdev = handle;
542 struct cpl_abort_req *req = cplhdr(skb);
543
544 PDBG("%s rdev %p\n", __func__, rdev);
545 req->cmd = CPL_ABORT_NO_RST;
546 c4iw_ofld_send(rdev, skb);
547}
548
Hariprasad Sfef44222016-05-05 01:27:33 +0530549static int send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700550{
551 unsigned int flowclen = 80;
552 struct fw_flowc_wr *flowc;
553 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530554 u16 vlan = ep->l2t->vlan;
555 int nparams;
556
557 if (vlan == CPL_L2T_VLAN_NONE)
558 nparams = 8;
559 else
560 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700561
562 skb = get_skb(skb, flowclen, GFP_KERNEL);
563 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
564
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530565 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530566 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530567 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(flowclen,
568 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700569
570 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530571 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530572 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700573 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
574 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
575 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
576 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
577 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
578 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
579 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
580 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
581 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
582 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
583 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530584 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700585 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
586 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530587 if (nparams == 9) {
588 u16 pri;
589
590 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
591 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
592 flowc->mnemval[8].val = cpu_to_be32(pri);
593 } else {
594 /* Pad WR to 16 byte boundary */
595 flowc->mnemval[8].mnemonic = 0;
596 flowc->mnemval[8].val = 0;
597 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700598 for (i = 0; i < 9; i++) {
599 flowc->mnemval[i].r4[0] = 0;
600 flowc->mnemval[i].r4[1] = 0;
601 flowc->mnemval[i].r4[2] = 0;
602 }
603
604 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530605 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700606}
607
608static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
609{
610 struct cpl_close_con_req *req;
611 struct sk_buff *skb;
612 int wrlen = roundup(sizeof *req, 16);
613
614 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
615 skb = get_skb(NULL, wrlen, gfp);
616 if (!skb) {
617 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
618 return -ENOMEM;
619 }
620 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
621 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
622 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
623 memset(req, 0, wrlen);
624 INIT_TP_WR(req, ep->hwtid);
625 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
626 ep->hwtid));
627 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
628}
629
630static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
631{
632 struct cpl_abort_req *req;
633 int wrlen = roundup(sizeof *req, 16);
634
635 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
636 skb = get_skb(skb, wrlen, gfp);
637 if (!skb) {
638 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
639 __func__);
640 return -ENOMEM;
641 }
642 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
643 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
644 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
645 memset(req, 0, wrlen);
646 INIT_TP_WR(req, ep->hwtid);
647 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
648 req->cmd = CPL_ABORT_SEND_RST;
649 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
650}
651
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530652static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530653 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530654{
Hariprasad S04524a42014-09-24 03:53:41 +0530655 unsigned short hdr_size = (ipv6 ?
656 sizeof(struct ipv6hdr) :
657 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530658 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530659 (use_ts ?
660 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530661 unsigned short data_size = mtu - hdr_size;
662
663 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
664}
665
Steve Wisecfdda9d2010-04-21 15:30:06 -0700666static int send_connect(struct c4iw_ep *ep)
667{
Hariprasad S963cab52015-09-23 17:19:27 +0530668 struct cpl_act_open_req *req = NULL;
669 struct cpl_t5_act_open_req *t5req = NULL;
670 struct cpl_t6_act_open_req *t6req = NULL;
671 struct cpl_act_open_req6 *req6 = NULL;
672 struct cpl_t5_act_open_req6 *t5req6 = NULL;
673 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700674 struct sk_buff *skb;
675 u64 opt0;
676 u32 opt2;
677 unsigned int mtu_idx;
678 int wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530679 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500680 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600681 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500682 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600683 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500684 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600685 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500686 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600687 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530688 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530689 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
690 u32 isn = (prandom_u32() & ~7UL) - 1;
691
692 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
693 case CHELSIO_T4:
694 sizev4 = sizeof(struct cpl_act_open_req);
695 sizev6 = sizeof(struct cpl_act_open_req6);
696 break;
697 case CHELSIO_T5:
698 sizev4 = sizeof(struct cpl_t5_act_open_req);
699 sizev6 = sizeof(struct cpl_t5_act_open_req6);
700 break;
701 case CHELSIO_T6:
702 sizev4 = sizeof(struct cpl_t6_act_open_req);
703 sizev6 = sizeof(struct cpl_t6_act_open_req6);
704 break;
705 default:
706 pr_err("T%d Chip is not supported\n",
707 CHELSIO_CHIP_VERSION(adapter_type));
708 return -EINVAL;
709 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530710
711 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
712 roundup(sizev4, 16) :
713 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700714
715 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
716
717 skb = get_skb(NULL, wrlen, GFP_KERNEL);
718 if (!skb) {
719 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
720 __func__);
721 return -ENOMEM;
722 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000723 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700724
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530725 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530726 enable_tcp_timestamps,
727 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700728 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530729
730 /*
731 * Specify the largest window that will fit in opt0. The
732 * remainder will be specified in the rx_data_ack.
733 */
734 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800735 if (win > RCV_BUFSIZ_M)
736 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530737
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800738 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800739 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800740 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800741 WND_SCALE_V(wscale) |
742 MSS_IDX_V(mtu_idx) |
743 L2T_IDX_V(ep->l2t->idx) |
744 TX_CHAN_V(ep->tx_chan) |
745 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530746 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800747 ULP_MODE_V(ULP_MODE_TCPDDP) |
748 RCV_BUFSIZ_V(win);
749 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800750 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800751 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700752 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800753 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700754 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800755 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700756 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800757 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530758 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
759 if (peer2peer)
760 isn += 4;
761
Anish Bhattd7990b02014-11-12 17:15:57 -0800762 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530763 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530764 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500765 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530766
767 if (ep->com.remote_addr.ss_family == AF_INET6)
768 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
769 (const u32 *)&la6->sin6_addr.s6_addr, 1);
770
Hariprasad S5dab6d32014-06-23 19:12:36 +0530771 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700772
Hariprasad S963cab52015-09-23 17:19:27 +0530773 if (ep->com.remote_addr.ss_family == AF_INET) {
774 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
775 case CHELSIO_T4:
776 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530777 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530778 break;
779 case CHELSIO_T5:
780 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
781 wrlen);
782 INIT_TP_WR(t5req, 0);
783 req = (struct cpl_act_open_req *)t5req;
784 break;
785 case CHELSIO_T6:
786 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
787 wrlen);
788 INIT_TP_WR(t6req, 0);
789 req = (struct cpl_act_open_req *)t6req;
790 t5req = (struct cpl_t5_act_open_req *)t6req;
791 break;
792 default:
793 pr_err("T%d Chip is not supported\n",
794 CHELSIO_CHIP_VERSION(adapter_type));
795 ret = -EINVAL;
796 goto clip_release;
797 }
798
799 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
800 ((ep->rss_qid<<14) | ep->atid)));
801 req->local_port = la->sin_port;
802 req->peer_port = ra->sin_port;
803 req->local_ip = la->sin_addr.s_addr;
804 req->peer_ip = ra->sin_addr.s_addr;
805 req->opt0 = cpu_to_be64(opt0);
806
807 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530808 req->params = cpu_to_be32(cxgb4_select_ntuple(
809 ep->com.dev->rdev.lldi.ports[0],
810 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530811 req->opt2 = cpu_to_be32(opt2);
812 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530813 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
814 cxgb4_select_ntuple(
815 ep->com.dev->rdev.lldi.ports[0],
816 ep->l2t)));
817 t5req->rsvd = cpu_to_be32(isn);
818 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
819 t5req->opt2 = cpu_to_be32(opt2);
820 }
821 } else {
822 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
823 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530824 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530825 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530826 break;
827 case CHELSIO_T5:
828 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
829 wrlen);
830 INIT_TP_WR(t5req6, 0);
831 req6 = (struct cpl_act_open_req6 *)t5req6;
832 break;
833 case CHELSIO_T6:
834 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
835 wrlen);
836 INIT_TP_WR(t6req6, 0);
837 req6 = (struct cpl_act_open_req6 *)t6req6;
838 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
839 break;
840 default:
841 pr_err("T%d Chip is not supported\n",
842 CHELSIO_CHIP_VERSION(adapter_type));
843 ret = -EINVAL;
844 goto clip_release;
845 }
846
847 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
848 ((ep->rss_qid<<14)|ep->atid)));
849 req6->local_port = la6->sin6_port;
850 req6->peer_port = ra6->sin6_port;
851 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
852 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
853 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
854 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
855 req6->opt0 = cpu_to_be64(opt0);
856
857 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530858 req6->params = cpu_to_be32(cxgb4_select_ntuple(
859 ep->com.dev->rdev.lldi.ports[0],
860 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530861 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530862 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530863 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
864 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530865 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530866 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530867 t5req6->rsvd = cpu_to_be32(isn);
868 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
869 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530870 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000871 }
872
Vipul Pandya793dad92012-12-10 09:30:56 +0000873 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530874 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530875clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530876 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
877 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
878 (const u32 *)&la6->sin6_addr.s6_addr, 1);
879 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700880}
881
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530882static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
883 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700884{
885 int mpalen, wrlen;
886 struct fw_ofld_tx_data_wr *req;
887 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530888 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700889
890 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
891
892 BUG_ON(skb_cloned(skb));
893
894 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530895 if (mpa_rev_to_use == 2)
896 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700897 wrlen = roundup(mpalen + sizeof *req, 16);
898 skb = get_skb(skb, wrlen, GFP_KERNEL);
899 if (!skb) {
900 connect_reply_upcall(ep, -ENOMEM);
901 return;
902 }
903 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
904
905 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
906 memset(req, 0, wrlen);
907 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530908 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
909 FW_WR_COMPL_F |
910 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700911 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530912 FW_WR_FLOWID_V(ep->hwtid) |
913 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700914 req->plen = cpu_to_be32(mpalen);
915 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530916 FW_OFLD_TX_DATA_WR_FLUSH_F |
917 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700918
919 mpa = (struct mpa_message *)(req + 1);
920 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
921 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530922 (markers_enabled ? MPA_MARKERS : 0) |
923 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700924 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530925 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530926 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530927 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530928 ep->retry_with_mpa_v1 = 0;
929 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700930
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530931 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700932 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
933 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530934 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
935 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530936 mpa_v2_params.ird = htons((u16)ep->ird);
937 mpa_v2_params.ord = htons((u16)ep->ord);
938
939 if (peer2peer) {
940 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
941 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
942 mpa_v2_params.ord |=
943 htons(MPA_V2_RDMA_WRITE_RTR);
944 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
945 mpa_v2_params.ord |=
946 htons(MPA_V2_RDMA_READ_RTR);
947 }
948 memcpy(mpa->private_data, &mpa_v2_params,
949 sizeof(struct mpa_v2_conn_params));
950
951 if (ep->plen)
952 memcpy(mpa->private_data +
953 sizeof(struct mpa_v2_conn_params),
954 ep->mpa_pkt + sizeof(*mpa), ep->plen);
955 } else
956 if (ep->plen)
957 memcpy(mpa->private_data,
958 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700959
960 /*
961 * Reference the mpa skb. This ensures the data area
962 * will remain in memory until the hw acks the tx.
963 * Function fw4_ack() will deref it.
964 */
965 skb_get(skb);
966 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
967 BUG_ON(ep->mpa_skb);
968 ep->mpa_skb = skb;
969 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
970 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530971 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700972 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530973 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700974 return;
975}
976
977static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
978{
979 int mpalen, wrlen;
980 struct fw_ofld_tx_data_wr *req;
981 struct mpa_message *mpa;
982 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530983 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700984
985 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
986
987 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530988 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
989 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700990 wrlen = roundup(mpalen + sizeof *req, 16);
991
992 skb = get_skb(NULL, wrlen, GFP_KERNEL);
993 if (!skb) {
994 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
995 return -ENOMEM;
996 }
997 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
998
999 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1000 memset(req, 0, wrlen);
1001 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301002 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1003 FW_WR_COMPL_F |
1004 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001005 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301006 FW_WR_FLOWID_V(ep->hwtid) |
1007 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001008 req->plen = cpu_to_be32(mpalen);
1009 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301010 FW_OFLD_TX_DATA_WR_FLUSH_F |
1011 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001012
1013 mpa = (struct mpa_message *)(req + 1);
1014 memset(mpa, 0, sizeof(*mpa));
1015 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1016 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001017 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001018 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301019
1020 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1021 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001022 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1023 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301024 mpa_v2_params.ird = htons(((u16)ep->ird) |
1025 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1026 0));
1027 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1028 (p2p_type ==
1029 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1030 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1031 FW_RI_INIT_P2PTYPE_READ_REQ ?
1032 MPA_V2_RDMA_READ_RTR : 0) : 0));
1033 memcpy(mpa->private_data, &mpa_v2_params,
1034 sizeof(struct mpa_v2_conn_params));
1035
1036 if (ep->plen)
1037 memcpy(mpa->private_data +
1038 sizeof(struct mpa_v2_conn_params), pdata, plen);
1039 } else
1040 if (plen)
1041 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001042
1043 /*
1044 * Reference the mpa skb again. This ensures the data area
1045 * will remain in memory until the hw acks the tx.
1046 * Function fw4_ack() will deref it.
1047 */
1048 skb_get(skb);
1049 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001050 BUG_ON(ep->mpa_skb);
1051 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301052 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001053 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1054}
1055
1056static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1057{
1058 int mpalen, wrlen;
1059 struct fw_ofld_tx_data_wr *req;
1060 struct mpa_message *mpa;
1061 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301062 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001063
1064 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1065
1066 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301067 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1068 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001069 wrlen = roundup(mpalen + sizeof *req, 16);
1070
1071 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1072 if (!skb) {
1073 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1074 return -ENOMEM;
1075 }
1076 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1077
1078 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1079 memset(req, 0, wrlen);
1080 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301081 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1082 FW_WR_COMPL_F |
1083 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001084 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301085 FW_WR_FLOWID_V(ep->hwtid) |
1086 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001087 req->plen = cpu_to_be32(mpalen);
1088 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301089 FW_OFLD_TX_DATA_WR_FLUSH_F |
1090 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001091
1092 mpa = (struct mpa_message *)(req + 1);
1093 memset(mpa, 0, sizeof(*mpa));
1094 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1095 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
1096 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301097 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001098 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301099
1100 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1101 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001102 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1103 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301104 mpa_v2_params.ird = htons((u16)ep->ird);
1105 mpa_v2_params.ord = htons((u16)ep->ord);
1106 if (peer2peer && (ep->mpa_attr.p2p_type !=
1107 FW_RI_INIT_P2PTYPE_DISABLED)) {
1108 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1109
1110 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1111 mpa_v2_params.ord |=
1112 htons(MPA_V2_RDMA_WRITE_RTR);
1113 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1114 mpa_v2_params.ord |=
1115 htons(MPA_V2_RDMA_READ_RTR);
1116 }
1117
1118 memcpy(mpa->private_data, &mpa_v2_params,
1119 sizeof(struct mpa_v2_conn_params));
1120
1121 if (ep->plen)
1122 memcpy(mpa->private_data +
1123 sizeof(struct mpa_v2_conn_params), pdata, plen);
1124 } else
1125 if (plen)
1126 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001127
1128 /*
1129 * Reference the mpa skb. This ensures the data area
1130 * will remain in memory until the hw acks the tx.
1131 * Function fw4_ack() will deref it.
1132 */
1133 skb_get(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001134 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301135 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301136 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001137 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1138}
1139
1140static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1141{
1142 struct c4iw_ep *ep;
1143 struct cpl_act_establish *req = cplhdr(skb);
1144 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001145 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001146 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301147 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001148
1149 ep = lookup_atid(t, atid);
1150
1151 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1152 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1153
Steve Wisea7db89e2014-03-21 20:40:35 +05301154 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001155 dst_confirm(ep->dst);
1156
1157 /* setup the hwtid for this connection */
1158 ep->hwtid = tid;
1159 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001160 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001161
1162 ep->snd_seq = be32_to_cpu(req->snd_isn);
1163 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1164
1165 set_emss(ep, ntohs(req->tcp_opt));
1166
1167 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001168 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001169 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001170 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001171
1172 /* start MPA negotiation */
Hariprasad Sfef44222016-05-05 01:27:33 +05301173 ret = send_flowc(ep, NULL);
1174 if (ret)
1175 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301176 if (ep->retry_with_mpa_v1)
1177 send_mpa_req(ep, skb, 1);
1178 else
1179 send_mpa_req(ep, skb, mpa_rev);
Steve Wisea7db89e2014-03-21 20:40:35 +05301180 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001181 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301182err:
1183 mutex_unlock(&ep->com.mutex);
1184 connect_reply_upcall(ep, -ENOMEM);
1185 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1186 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001187}
1188
Steve Wisebe13b2d2014-03-21 20:40:33 +05301189static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001190{
1191 struct iw_cm_event event;
1192
1193 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1194 memset(&event, 0, sizeof(event));
1195 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301196 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001197 if (ep->com.cm_id) {
1198 PDBG("close complete 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);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301201 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001202 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001203 }
1204}
1205
Steve Wisecfdda9d2010-04-21 15:30:06 -07001206static void peer_close_upcall(struct c4iw_ep *ep)
1207{
1208 struct iw_cm_event event;
1209
1210 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1211 memset(&event, 0, sizeof(event));
1212 event.event = IW_CM_EVENT_DISCONNECT;
1213 if (ep->com.cm_id) {
1214 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1215 ep, ep->com.cm_id, ep->hwtid);
1216 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001217 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001218 }
1219}
1220
1221static void peer_abort_upcall(struct c4iw_ep *ep)
1222{
1223 struct iw_cm_event event;
1224
1225 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1226 memset(&event, 0, sizeof(event));
1227 event.event = IW_CM_EVENT_CLOSE;
1228 event.status = -ECONNRESET;
1229 if (ep->com.cm_id) {
1230 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1231 ep->com.cm_id, ep->hwtid);
1232 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301233 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001234 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001235 }
1236}
1237
1238static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1239{
1240 struct iw_cm_event event;
1241
1242 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1243 memset(&event, 0, sizeof(event));
1244 event.event = IW_CM_EVENT_CONNECT_REPLY;
1245 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301246 memcpy(&event.local_addr, &ep->com.local_addr,
1247 sizeof(ep->com.local_addr));
1248 memcpy(&event.remote_addr, &ep->com.remote_addr,
1249 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001250
1251 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301252 if (!ep->tried_with_mpa_v1) {
1253 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301254 event.ord = ep->ird;
1255 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301256 event.private_data_len = ep->plen -
1257 sizeof(struct mpa_v2_conn_params);
1258 event.private_data = ep->mpa_pkt +
1259 sizeof(struct mpa_message) +
1260 sizeof(struct mpa_v2_conn_params);
1261 } else {
1262 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301263 event.ord = cur_max_read_depth(ep->com.dev);
1264 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301265 event.private_data_len = ep->plen;
1266 event.private_data = ep->mpa_pkt +
1267 sizeof(struct mpa_message);
1268 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001269 }
Roland Dreier85963e42010-07-19 13:13:09 -07001270
1271 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1272 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001273 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001274 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1275
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301276 if (status < 0)
1277 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001278}
1279
Steve Wisebe13b2d2014-03-21 20:40:33 +05301280static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001281{
1282 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301283 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001284
1285 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1286 memset(&event, 0, sizeof(event));
1287 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301288 memcpy(&event.local_addr, &ep->com.local_addr,
1289 sizeof(ep->com.local_addr));
1290 memcpy(&event.remote_addr, &ep->com.remote_addr,
1291 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001292 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301293 if (!ep->tried_with_mpa_v1) {
1294 /* this means MPA_v2 is used */
1295 event.ord = ep->ord;
1296 event.ird = ep->ird;
1297 event.private_data_len = ep->plen -
1298 sizeof(struct mpa_v2_conn_params);
1299 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1300 sizeof(struct mpa_v2_conn_params);
1301 } else {
1302 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301303 event.ord = cur_max_read_depth(ep->com.dev);
1304 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301305 event.private_data_len = ep->plen;
1306 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1307 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301308 c4iw_get_ep(&ep->com);
1309 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1310 &event);
1311 if (ret)
1312 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001313 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001314 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301315 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001316}
1317
1318static void established_upcall(struct c4iw_ep *ep)
1319{
1320 struct iw_cm_event event;
1321
1322 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1323 memset(&event, 0, sizeof(event));
1324 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301325 event.ird = ep->ord;
1326 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001327 if (ep->com.cm_id) {
1328 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1329 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001330 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001331 }
1332}
1333
1334static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1335{
1336 struct cpl_rx_data_ack *req;
1337 struct sk_buff *skb;
1338 int wrlen = roundup(sizeof *req, 16);
1339
1340 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1341 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1342 if (!skb) {
1343 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1344 return 0;
1345 }
1346
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301347 /*
1348 * If we couldn't specify the entire rcv window at connection setup
1349 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1350 * then add the overage in to the credits returned.
1351 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001352 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1353 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301354
Steve Wisecfdda9d2010-04-21 15:30:06 -07001355 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1356 memset(req, 0, wrlen);
1357 INIT_TP_WR(req, ep->hwtid);
1358 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1359 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001360 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301361 RX_DACK_CHANGE_F |
1362 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001363 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001364 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1365 return credits;
1366}
1367
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301368#define RELAXED_IRD_NEGOTIATION 1
1369
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301370/*
1371 * process_mpa_reply - process streaming mode MPA reply
1372 *
1373 * Returns:
1374 *
1375 * 0 upon success indicating a connect request was delivered to the ULP
1376 * or the mpa request is incomplete but valid so far.
1377 *
1378 * 1 if a failure requires the caller to close the connection.
1379 *
1380 * 2 if a failure requires the caller to abort the connection.
1381 */
Steve Wisecc18b932014-04-24 14:31:53 -05001382static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001383{
1384 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301385 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001386 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301387 u16 resp_ird, resp_ord;
1388 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001389 struct c4iw_qp_attributes attrs;
1390 enum c4iw_qp_attr_mask mask;
1391 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001392 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001393
1394 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1395
1396 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001397 * If we get more than the supported amount of private data
1398 * then we must fail this connection.
1399 */
1400 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1401 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301402 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001403 }
1404
1405 /*
1406 * copy the new data into our accumulation buffer.
1407 */
1408 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1409 skb->len);
1410 ep->mpa_pkt_len += skb->len;
1411
1412 /*
1413 * if we don't even have the mpa message, then bail.
1414 */
1415 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001416 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001417 mpa = (struct mpa_message *) ep->mpa_pkt;
1418
1419 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301420 if (mpa->revision > mpa_rev) {
1421 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1422 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001423 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301424 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001425 }
1426 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1427 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301428 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001429 }
1430
1431 plen = ntohs(mpa->private_data_size);
1432
1433 /*
1434 * Fail if there's too much private data.
1435 */
1436 if (plen > MPA_MAX_PRIVATE_DATA) {
1437 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301438 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001439 }
1440
1441 /*
1442 * If plen does not account for pkt size
1443 */
1444 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1445 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301446 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001447 }
1448
1449 ep->plen = (u8) plen;
1450
1451 /*
1452 * If we don't have all the pdata yet, then bail.
1453 * We'll continue process when more data arrives.
1454 */
1455 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001456 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001457
1458 if (mpa->flags & MPA_REJECT) {
1459 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301460 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001461 }
1462
1463 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301464 * Stop mpa timer. If it expired, then
1465 * we ignore the MPA reply. process_timeout()
1466 * will abort the connection.
1467 */
1468 if (stop_ep_timer(ep))
1469 return 0;
1470
1471 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001472 * If we get here we have accumulated the entire mpa
1473 * start reply message including private data. And
1474 * the MPA header is valid.
1475 */
Steve Wisec529fb52014-03-21 20:40:37 +05301476 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001477 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1478 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1479 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301480 ep->mpa_attr.version = mpa->revision;
1481 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1482
1483 if (mpa->revision == 2) {
1484 ep->mpa_attr.enhanced_rdma_conn =
1485 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1486 if (ep->mpa_attr.enhanced_rdma_conn) {
1487 mpa_v2_params = (struct mpa_v2_conn_params *)
1488 (ep->mpa_pkt + sizeof(*mpa));
1489 resp_ird = ntohs(mpa_v2_params->ird) &
1490 MPA_V2_IRD_ORD_MASK;
1491 resp_ord = ntohs(mpa_v2_params->ord) &
1492 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301493 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1494 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301495
1496 /*
1497 * This is a double-check. Ideally, below checks are
1498 * not required since ird/ord stuff has been taken
1499 * care of in c4iw_accept_cr
1500 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301501 if (ep->ird < resp_ord) {
1502 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1503 ep->com.dev->rdev.lldi.max_ordird_qp)
1504 ep->ird = resp_ord;
1505 else
1506 insuff_ird = 1;
1507 } else if (ep->ird > resp_ord) {
1508 ep->ird = resp_ord;
1509 }
1510 if (ep->ord > resp_ird) {
1511 if (RELAXED_IRD_NEGOTIATION)
1512 ep->ord = resp_ird;
1513 else
1514 insuff_ird = 1;
1515 }
1516 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301517 err = -ENOMEM;
1518 ep->ird = resp_ord;
1519 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301520 }
1521
1522 if (ntohs(mpa_v2_params->ird) &
1523 MPA_V2_PEER2PEER_MODEL) {
1524 if (ntohs(mpa_v2_params->ord) &
1525 MPA_V2_RDMA_WRITE_RTR)
1526 ep->mpa_attr.p2p_type =
1527 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1528 else if (ntohs(mpa_v2_params->ord) &
1529 MPA_V2_RDMA_READ_RTR)
1530 ep->mpa_attr.p2p_type =
1531 FW_RI_INIT_P2PTYPE_READ_REQ;
1532 }
1533 }
1534 } else if (mpa->revision == 1)
1535 if (peer2peer)
1536 ep->mpa_attr.p2p_type = p2p_type;
1537
Steve Wisecfdda9d2010-04-21 15:30:06 -07001538 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301539 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1540 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1541 ep->mpa_attr.recv_marker_enabled,
1542 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1543 ep->mpa_attr.p2p_type, p2p_type);
1544
1545 /*
1546 * If responder's RTR does not match with that of initiator, assign
1547 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1548 * generated when moving QP to RTS state.
1549 * A TERM message will be sent after QP has moved to RTS state
1550 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001551 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301552 (ep->mpa_attr.p2p_type != p2p_type)) {
1553 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1554 rtr_mismatch = 1;
1555 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001556
1557 attrs.mpa_attr = ep->mpa_attr;
1558 attrs.max_ird = ep->ird;
1559 attrs.max_ord = ep->ord;
1560 attrs.llp_stream_handle = ep;
1561 attrs.next_state = C4IW_QP_STATE_RTS;
1562
1563 mask = C4IW_QP_ATTR_NEXT_STATE |
1564 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1565 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1566
1567 /* bind QP and TID with INIT_WR */
1568 err = c4iw_modify_qp(ep->com.qp->rhp,
1569 ep->com.qp, mask, &attrs, 1);
1570 if (err)
1571 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301572
1573 /*
1574 * If responder's RTR requirement did not match with what initiator
1575 * supports, generate TERM message
1576 */
1577 if (rtr_mismatch) {
1578 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1579 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1580 attrs.ecode = MPA_NOMATCH_RTR;
1581 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001582 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301583 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001584 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301585 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001586 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301587 goto out;
1588 }
1589
1590 /*
1591 * Generate TERM if initiator IRD is not sufficient for responder
1592 * provided ORD. Currently, we do the same behaviour even when
1593 * responder provided IRD is also not sufficient as regards to
1594 * initiator ORD.
1595 */
1596 if (insuff_ird) {
1597 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1598 __func__);
1599 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1600 attrs.ecode = MPA_INSUFF_IRD;
1601 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001602 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301603 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001604 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301605 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001606 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301607 goto out;
1608 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001609 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301610err_stop_timer:
1611 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001612err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301613 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001614out:
1615 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001616 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001617}
1618
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301619/*
1620 * process_mpa_request - process streaming mode MPA request
1621 *
1622 * Returns:
1623 *
1624 * 0 upon success indicating a connect request was delivered to the ULP
1625 * or the mpa request is incomplete but valid so far.
1626 *
1627 * 1 if a failure requires the caller to close the connection.
1628 *
1629 * 2 if a failure requires the caller to abort the connection.
1630 */
1631static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001632{
1633 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301634 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001635 u16 plen;
1636
1637 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1638
Steve Wisecfdda9d2010-04-21 15:30:06 -07001639 /*
1640 * If we get more than the supported amount of private data
1641 * then we must fail this connection.
1642 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301643 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1644 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001645
1646 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1647
1648 /*
1649 * Copy the new data into our accumulation buffer.
1650 */
1651 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1652 skb->len);
1653 ep->mpa_pkt_len += skb->len;
1654
1655 /*
1656 * If we don't even have the mpa message, then bail.
1657 * We'll continue process when more data arrives.
1658 */
1659 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301660 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001661
1662 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001663 mpa = (struct mpa_message *) ep->mpa_pkt;
1664
1665 /*
1666 * Validate MPA Header.
1667 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301668 if (mpa->revision > mpa_rev) {
1669 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1670 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301671 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001672 }
1673
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301674 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1675 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001676
1677 plen = ntohs(mpa->private_data_size);
1678
1679 /*
1680 * Fail if there's too much private data.
1681 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301682 if (plen > MPA_MAX_PRIVATE_DATA)
1683 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001684
1685 /*
1686 * If plen does not account for pkt size
1687 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301688 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1689 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001690 ep->plen = (u8) plen;
1691
1692 /*
1693 * If we don't have all the pdata yet, then bail.
1694 */
1695 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301696 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001697
1698 /*
1699 * If we get here we have accumulated the entire mpa
1700 * start reply message including private data.
1701 */
1702 ep->mpa_attr.initiator = 0;
1703 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1704 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1705 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301706 ep->mpa_attr.version = mpa->revision;
1707 if (mpa->revision == 1)
1708 ep->tried_with_mpa_v1 = 1;
1709 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1710
1711 if (mpa->revision == 2) {
1712 ep->mpa_attr.enhanced_rdma_conn =
1713 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1714 if (ep->mpa_attr.enhanced_rdma_conn) {
1715 mpa_v2_params = (struct mpa_v2_conn_params *)
1716 (ep->mpa_pkt + sizeof(*mpa));
1717 ep->ird = ntohs(mpa_v2_params->ird) &
1718 MPA_V2_IRD_ORD_MASK;
1719 ep->ord = ntohs(mpa_v2_params->ord) &
1720 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301721 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1722 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301723 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1724 if (peer2peer) {
1725 if (ntohs(mpa_v2_params->ord) &
1726 MPA_V2_RDMA_WRITE_RTR)
1727 ep->mpa_attr.p2p_type =
1728 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1729 else if (ntohs(mpa_v2_params->ord) &
1730 MPA_V2_RDMA_READ_RTR)
1731 ep->mpa_attr.p2p_type =
1732 FW_RI_INIT_P2PTYPE_READ_REQ;
1733 }
1734 }
1735 } else if (mpa->revision == 1)
1736 if (peer2peer)
1737 ep->mpa_attr.p2p_type = p2p_type;
1738
Steve Wisecfdda9d2010-04-21 15:30:06 -07001739 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1740 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1741 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1742 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1743 ep->mpa_attr.p2p_type);
1744
Hariprasad Se4b76a22016-05-06 22:17:59 +05301745 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001746
Hariprasad Se4b76a22016-05-06 22:17:59 +05301747 /* drive upcall */
1748 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1749 if (ep->parent_ep->com.state != DEAD) {
1750 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301751 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301752 } else {
1753 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301754 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301755 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301756 return 0;
1757
1758err_unlock_parent:
1759 mutex_unlock(&ep->parent_ep->com.mutex);
1760 goto err_out;
1761err_stop_timer:
1762 (void)stop_ep_timer(ep);
1763err_out:
1764 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001765}
1766
1767static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1768{
1769 struct c4iw_ep *ep;
1770 struct cpl_rx_data *hdr = cplhdr(skb);
1771 unsigned int dlen = ntohs(hdr->len);
1772 unsigned int tid = GET_TID(hdr);
1773 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001774 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001775 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001776
1777 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301778 if (!ep)
1779 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001780 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1781 skb_pull(skb, sizeof(*hdr));
1782 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301783 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001784
Steve Wisecfdda9d2010-04-21 15:30:06 -07001785 /* update RX credits */
1786 update_rx_credits(ep, dlen);
1787
Steve Wisec529fb52014-03-21 20:40:37 +05301788 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001789 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001790 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001791 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001792 break;
1793 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001794 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001795 process_mpa_request(ep, skb);
1796 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001797 case FPDU_MODE: {
1798 struct c4iw_qp_attributes attrs;
1799 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001800 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001801 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001802 " qpid %u ep %p state %d tid %u status %d\n",
1803 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301804 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301805 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001806 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001807 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1808 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001809 break;
1810 }
Vipul Pandya15579672013-01-07 13:11:52 +00001811 default:
1812 break;
1813 }
Steve Wisec529fb52014-03-21 20:40:37 +05301814 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001815 if (disconnect)
1816 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001817 return 0;
1818}
1819
1820static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1821{
1822 struct c4iw_ep *ep;
1823 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001824 int release = 0;
1825 unsigned int tid = GET_TID(rpl);
1826 struct tid_info *t = dev->rdev.lldi.tids;
1827
1828 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301829 if (!ep) {
1830 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1831 return 0;
1832 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001833 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001834 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001835 switch (ep->com.state) {
1836 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001837 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001838 __state_set(&ep->com, DEAD);
1839 release = 1;
1840 break;
1841 default:
1842 printk(KERN_ERR "%s ep %p state %d\n",
1843 __func__, ep, ep->com.state);
1844 break;
1845 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001846 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001847
1848 if (release)
1849 release_ep_resources(ep);
1850 return 0;
1851}
1852
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001853static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1854{
1855 struct sk_buff *skb;
1856 struct fw_ofld_connection_wr *req;
1857 unsigned int mtu_idx;
1858 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301859 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301860 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001861
1862 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1863 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1864 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001865 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301866 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301867 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1868 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001869 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001870 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301871 req->le.lport = sin->sin_port;
1872 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001873 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301874 req->le.pport = sin->sin_port;
1875 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001876 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301877 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1878 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001879 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301880 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001881 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001882 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301883 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301884 enable_tcp_timestamps,
1885 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001886 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301887
1888 /*
1889 * Specify the largest window that will fit in opt0. The
1890 * remainder will be specified in the rx_data_ack.
1891 */
1892 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001893 if (win > RCV_BUFSIZ_M)
1894 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301895
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001896 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1897 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001898 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001899 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001900 WND_SCALE_V(wscale) |
1901 MSS_IDX_V(mtu_idx) |
1902 L2T_IDX_V(ep->l2t->idx) |
1903 TX_CHAN_V(ep->tx_chan) |
1904 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301905 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001906 ULP_MODE_V(ULP_MODE_TCPDDP) |
1907 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001908 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1909 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001910 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001911 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001912 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001913 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001914 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001915 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001916 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001917 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001918 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1919 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1920 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001921 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1922 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001923 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1924}
1925
Steve Wisecfdda9d2010-04-21 15:30:06 -07001926/*
1927 * Return whether a failed active open has allocated a TID
1928 */
1929static inline int act_open_has_tid(int status)
1930{
1931 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1932 status != CPL_ERR_ARP_MISS;
1933}
1934
Steve Wise7a2cea22014-03-14 21:52:07 +05301935/* Returns whether a CPL status conveys negative advice.
1936 */
1937static int is_neg_adv(unsigned int status)
1938{
1939 return status == CPL_ERR_RTX_NEG_ADVICE ||
1940 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1941 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1942}
1943
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301944static char *neg_adv_str(unsigned int status)
1945{
1946 switch (status) {
1947 case CPL_ERR_RTX_NEG_ADVICE:
1948 return "Retransmit timeout";
1949 case CPL_ERR_PERSIST_NEG_ADVICE:
1950 return "Persist timeout";
1951 case CPL_ERR_KEEPALV_NEG_ADVICE:
1952 return "Keepalive timeout";
1953 default:
1954 return "Unknown";
1955 }
1956}
1957
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301958static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1959{
1960 ep->snd_win = snd_win;
1961 ep->rcv_win = rcv_win;
1962 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1963}
1964
Vipul Pandya793dad92012-12-10 09:30:56 +00001965#define ACT_OPEN_RETRY_COUNT 2
1966
Vipul Pandya830662f2013-07-04 16:10:47 +05301967static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1968 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301969 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05301970{
1971 struct neighbour *n;
1972 int err, step;
1973 struct net_device *pdev;
1974
1975 n = dst_neigh_lookup(dst, peer_ip);
1976 if (!n)
1977 return -ENODEV;
1978
1979 rcu_read_lock();
1980 err = -ENOMEM;
1981 if (n->dev->flags & IFF_LOOPBACK) {
1982 if (iptype == 4)
1983 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1984 else if (IS_ENABLED(CONFIG_IPV6))
1985 for_each_netdev(&init_net, pdev) {
1986 if (ipv6_chk_addr(&init_net,
1987 (struct in6_addr *)peer_ip,
1988 pdev, 1))
1989 break;
1990 }
1991 else
1992 pdev = NULL;
1993
1994 if (!pdev) {
1995 err = -ENODEV;
1996 goto out;
1997 }
1998 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301999 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05302000 if (!ep->l2t)
2001 goto out;
2002 ep->mtu = pdev->mtu;
2003 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302004 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2005 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302006 step = cdev->rdev.lldi.ntxq /
2007 cdev->rdev.lldi.nchan;
2008 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2009 step = cdev->rdev.lldi.nrxq /
2010 cdev->rdev.lldi.nchan;
2011 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2012 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2013 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302014 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302015 dev_put(pdev);
2016 } else {
2017 pdev = get_real_dev(n->dev);
2018 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2019 n, pdev, 0);
2020 if (!ep->l2t)
2021 goto out;
2022 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002023 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302024 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2025 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302026 step = cdev->rdev.lldi.ntxq /
2027 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002028 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2029 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302030 step = cdev->rdev.lldi.nrxq /
2031 cdev->rdev.lldi.nchan;
2032 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002033 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302034 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302035
2036 if (clear_mpa_v1) {
2037 ep->retry_with_mpa_v1 = 0;
2038 ep->tried_with_mpa_v1 = 0;
2039 }
2040 }
2041 err = 0;
2042out:
2043 rcu_read_unlock();
2044
2045 neigh_release(n);
2046
2047 return err;
2048}
2049
Vipul Pandya793dad92012-12-10 09:30:56 +00002050static int c4iw_reconnect(struct c4iw_ep *ep)
2051{
2052 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302053 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002054 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302055 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002056 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302057 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002058 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302059 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002060 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302061 int iptype;
2062 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002063
2064 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2065 init_timer(&ep->timer);
2066
2067 /*
2068 * Allocate an active TID to initiate a TCP connection.
2069 */
2070 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2071 if (ep->atid == -1) {
2072 pr_err("%s - cannot alloc atid.\n", __func__);
2073 err = -ENOMEM;
2074 goto fail2;
2075 }
2076 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2077
2078 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002079 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302080 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2081 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302082 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302083 iptype = 4;
2084 ra = (__u8 *)&raddr->sin_addr;
2085 } else {
2086 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2087 raddr6->sin6_addr.s6_addr,
2088 laddr6->sin6_port, raddr6->sin6_port, 0,
2089 raddr6->sin6_scope_id);
2090 iptype = 6;
2091 ra = (__u8 *)&raddr6->sin6_addr;
2092 }
2093 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002094 pr_err("%s - cannot find route.\n", __func__);
2095 err = -EHOSTUNREACH;
2096 goto fail3;
2097 }
Hariprasad S963cab52015-09-23 17:19:27 +05302098 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302099 ep->com.dev->rdev.lldi.adapter_type,
2100 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302101 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002102 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002103 goto fail4;
2104 }
2105
2106 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2107 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2108 ep->l2t->idx);
2109
2110 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302111 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002112
2113 /* send connect request to rnic */
2114 err = send_connect(ep);
2115 if (!err)
2116 goto out;
2117
2118 cxgb4_l2t_release(ep->l2t);
2119fail4:
2120 dst_release(ep->dst);
2121fail3:
2122 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2123 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2124fail2:
2125 /*
2126 * remember to send notification to upper layer.
2127 * We are in here so the upper layer is not aware that this is
2128 * re-connect attempt and so, upper layer is still waiting for
2129 * response of 1st connect request.
2130 */
2131 connect_reply_upcall(ep, -ECONNRESET);
2132 c4iw_put_ep(&ep->com);
2133out:
2134 return err;
2135}
2136
Steve Wisecfdda9d2010-04-21 15:30:06 -07002137static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2138{
2139 struct c4iw_ep *ep;
2140 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002141 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2142 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002143 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002144 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302145 struct sockaddr_in *la;
2146 struct sockaddr_in *ra;
2147 struct sockaddr_in6 *la6;
2148 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002149
2150 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002151 la = (struct sockaddr_in *)&ep->com.local_addr;
2152 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2153 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2154 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002155
2156 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2157 status, status2errno(status));
2158
Steve Wise7a2cea22014-03-14 21:52:07 +05302159 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302160 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2161 __func__, atid, status, neg_adv_str(status));
2162 ep->stats.connect_neg_adv++;
2163 mutex_lock(&dev->rdev.stats.lock);
2164 dev->rdev.stats.neg_adv++;
2165 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002166 return 0;
2167 }
2168
Vipul Pandya793dad92012-12-10 09:30:56 +00002169 set_bit(ACT_OPEN_RPL, &ep->com.history);
2170
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302171 /*
2172 * Log interesting failures.
2173 */
2174 switch (status) {
2175 case CPL_ERR_CONN_RESET:
2176 case CPL_ERR_CONN_TIMEDOUT:
2177 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002178 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302179 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002180 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302181 mutex_unlock(&dev->rdev.stats.lock);
2182 if (ep->com.local_addr.ss_family == AF_INET &&
2183 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002184 send_fw_act_open_req(ep,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002185 TID_TID_G(AOPEN_ATID_G(
Vipul Pandya793dad92012-12-10 09:30:56 +00002186 ntohl(rpl->atid_status))));
2187 return 0;
2188 }
2189 break;
2190 case CPL_ERR_CONN_EXIST:
2191 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2192 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302193 if (ep->com.remote_addr.ss_family == AF_INET6) {
2194 struct sockaddr_in6 *sin6 =
2195 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002196 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302197 cxgb4_clip_release(
2198 ep->com.dev->rdev.lldi.ports[0],
2199 (const u32 *)
2200 &sin6->sin6_addr.s6_addr, 1);
2201 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002202 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2203 atid);
2204 cxgb4_free_atid(t, atid);
2205 dst_release(ep->dst);
2206 cxgb4_l2t_release(ep->l2t);
2207 c4iw_reconnect(ep);
2208 return 0;
2209 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002210 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302211 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302212 if (ep->com.local_addr.ss_family == AF_INET) {
2213 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2214 atid, status, status2errno(status),
2215 &la->sin_addr.s_addr, ntohs(la->sin_port),
2216 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2217 } else {
2218 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2219 atid, status, status2errno(status),
2220 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2221 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2222 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302223 break;
2224 }
2225
Steve Wisecfdda9d2010-04-21 15:30:06 -07002226 connect_reply_upcall(ep, status2errno(status));
2227 state_set(&ep->com, DEAD);
2228
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302229 if (ep->com.remote_addr.ss_family == AF_INET6) {
2230 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002231 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302232 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2233 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2234 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002235 if (status && act_open_has_tid(status))
2236 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2237
Vipul Pandya793dad92012-12-10 09:30:56 +00002238 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002239 cxgb4_free_atid(t, atid);
2240 dst_release(ep->dst);
2241 cxgb4_l2t_release(ep->l2t);
2242 c4iw_put_ep(&ep->com);
2243
2244 return 0;
2245}
2246
2247static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2248{
2249 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2250 struct tid_info *t = dev->rdev.lldi.tids;
2251 unsigned int stid = GET_TID(rpl);
2252 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2253
2254 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002255 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2256 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002257 }
2258 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2259 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002260 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002261
Vipul Pandya1cab7752012-12-10 09:30:55 +00002262out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002263 return 0;
2264}
2265
Steve Wisecfdda9d2010-04-21 15:30:06 -07002266static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2267{
2268 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2269 struct tid_info *t = dev->rdev.lldi.tids;
2270 unsigned int stid = GET_TID(rpl);
2271 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2272
2273 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002274 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002275 return 0;
2276}
2277
Hariprasad S9dec9002016-05-05 01:27:29 +05302278static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2279 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002280{
2281 struct cpl_pass_accept_rpl *rpl;
2282 unsigned int mtu_idx;
2283 u64 opt0;
2284 u32 opt2;
2285 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302286 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302287 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302288 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002289
2290 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2291 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302292
Steve Wisecfdda9d2010-04-21 15:30:06 -07002293 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302294 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302295 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302296 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2297 rpl5 = (void *)rpl;
2298 INIT_TP_WR(rpl5, ep->hwtid);
2299 } else {
2300 skb_trim(skb, sizeof(*rpl));
2301 INIT_TP_WR(rpl, ep->hwtid);
2302 }
2303 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2304 ep->hwtid));
2305
2306 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302307 enable_tcp_timestamps && req->tcpopt.tstamp,
2308 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002309 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302310
2311 /*
2312 * Specify the largest window that will fit in opt0. The
2313 * remainder will be specified in the rx_data_ack.
2314 */
2315 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002316 if (win > RCV_BUFSIZ_M)
2317 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002318 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002319 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002320 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002321 WND_SCALE_V(wscale) |
2322 MSS_IDX_V(mtu_idx) |
2323 L2T_IDX_V(ep->l2t->idx) |
2324 TX_CHAN_V(ep->tx_chan) |
2325 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002326 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002327 ULP_MODE_V(ULP_MODE_TCPDDP) |
2328 RCV_BUFSIZ_V(win);
2329 opt2 = RX_CHANNEL_V(0) |
2330 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002331
2332 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002333 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002334 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002335 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002336 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002337 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002338 if (enable_ecn) {
2339 const struct tcphdr *tcph;
2340 u32 hlen = ntohl(req->hdr_len);
2341
Hariprasad S963cab52015-09-23 17:19:27 +05302342 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2343 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2344 IP_HDR_LEN_G(hlen);
2345 else
2346 tcph = (const void *)(req + 1) +
2347 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002348 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002349 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002350 }
Hariprasad S963cab52015-09-23 17:19:27 +05302351 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302352 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002353 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302354 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302355 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302356 rpl5 = (void *)rpl;
2357 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2358 if (peer2peer)
2359 isn += 4;
2360 rpl5->iss = cpu_to_be32(isn);
2361 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002362 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002363
Steve Wisecfdda9d2010-04-21 15:30:06 -07002364 rpl->opt0 = cpu_to_be64(opt0);
2365 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002366 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302367 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002368
Hariprasad S9dec9002016-05-05 01:27:29 +05302369 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002370}
2371
Vipul Pandya830662f2013-07-04 16:10:47 +05302372static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002373{
Vipul Pandya830662f2013-07-04 16:10:47 +05302374 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002375 BUG_ON(skb_cloned(skb));
2376 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002377 release_tid(&dev->rdev, hwtid, skb);
2378 return;
2379}
2380
Hariprasad S963cab52015-09-23 17:19:27 +05302381static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2382 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002383 __be16 *local_port, __be16 *peer_port)
2384{
Hariprasad S963cab52015-09-23 17:19:27 +05302385 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2386 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2387 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2388 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2389 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2390 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002391 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302392 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002393 struct tcphdr *tcp = (struct tcphdr *)
2394 ((u8 *)(req + 1) + eth_len + ip_len);
2395
Vipul Pandya830662f2013-07-04 16:10:47 +05302396 if (ip->version == 4) {
2397 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2398 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2399 ntohs(tcp->dest));
2400 *iptype = 4;
2401 memcpy(peer_ip, &ip->saddr, 4);
2402 memcpy(local_ip, &ip->daddr, 4);
2403 } else {
2404 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2405 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2406 ntohs(tcp->dest));
2407 *iptype = 6;
2408 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2409 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2410 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002411 *peer_port = tcp->source;
2412 *local_port = tcp->dest;
2413
2414 return;
2415}
2416
2417static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2418{
Vipul Pandya793dad92012-12-10 09:30:56 +00002419 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002420 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002421 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002422 struct tid_info *t = dev->rdev.lldi.tids;
2423 unsigned int hwtid = GET_TID(req);
2424 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302425 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002426 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302427 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002428 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002429 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302430 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302431 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302432 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002433
2434 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002435 if (!parent_ep) {
2436 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2437 goto reject;
2438 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002439
Steve Wisecfdda9d2010-04-21 15:30:06 -07002440 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302441 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002442 goto reject;
2443 }
2444
Hariprasad S963cab52015-09-23 17:19:27 +05302445 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2446 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302447
Steve Wisecfdda9d2010-04-21 15:30:06 -07002448 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302449 if (iptype == 4) {
2450 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2451 , __func__, parent_ep, hwtid,
2452 local_ip, peer_ip, ntohs(local_port),
2453 ntohs(peer_port), peer_mss);
2454 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2455 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302456 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302457 } else {
2458 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2459 , __func__, parent_ep, hwtid,
2460 local_ip, peer_ip, ntohs(local_port),
2461 ntohs(peer_port), peer_mss);
2462 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002463 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302464 ((struct sockaddr_in6 *)
2465 &parent_ep->com.local_addr)->sin6_scope_id);
2466 }
2467 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002468 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2469 __func__);
2470 goto reject;
2471 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002472
2473 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2474 if (!child_ep) {
2475 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2476 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002477 dst_release(dst);
2478 goto reject;
2479 }
David Miller3786cf12011-12-02 16:52:31 +00002480
Hariprasad S963cab52015-09-23 17:19:27 +05302481 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302482 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002483 if (err) {
2484 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2485 __func__);
2486 dst_release(dst);
2487 kfree(child_ep);
2488 goto reject;
2489 }
2490
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302491 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2492 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2493 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2494 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002495
Steve Wisecfdda9d2010-04-21 15:30:06 -07002496 state_set(&child_ep->com, CONNECTING);
2497 child_ep->com.dev = dev;
2498 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002499
Vipul Pandya830662f2013-07-04 16:10:47 +05302500 if (iptype == 4) {
2501 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002502 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002503
Vipul Pandya830662f2013-07-04 16:10:47 +05302504 sin->sin_family = PF_INET;
2505 sin->sin_port = local_port;
2506 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002507
2508 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2509 sin->sin_family = PF_INET;
2510 sin->sin_port = ((struct sockaddr_in *)
2511 &parent_ep->com.local_addr)->sin_port;
2512 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2513
Steve Wise170003c2016-02-26 09:18:03 -06002514 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302515 sin->sin_family = PF_INET;
2516 sin->sin_port = peer_port;
2517 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2518 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002519 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302520 sin6->sin6_family = PF_INET6;
2521 sin6->sin6_port = local_port;
2522 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002523
2524 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2525 sin6->sin6_family = PF_INET6;
2526 sin6->sin6_port = ((struct sockaddr_in6 *)
2527 &parent_ep->com.local_addr)->sin6_port;
2528 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2529
Steve Wise170003c2016-02-26 09:18:03 -06002530 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302531 sin6->sin6_family = PF_INET6;
2532 sin6->sin6_port = peer_port;
2533 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2534 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002535
Steve Wisecfdda9d2010-04-21 15:30:06 -07002536 c4iw_get_ep(&parent_ep->com);
2537 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302538 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002539 child_ep->dst = dst;
2540 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002541
2542 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002543 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002544
2545 init_timer(&child_ep->timer);
2546 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002547 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Hariprasad S9dec9002016-05-05 01:27:29 +05302548 if (accept_cr(child_ep, skb, req)) {
2549 c4iw_put_ep(&parent_ep->com);
2550 release_ep_resources(child_ep);
2551 } else {
2552 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2553 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302554 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002555 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302556 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2557 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2558 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002559 goto out;
2560reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302561 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002562out:
2563 return 0;
2564}
2565
2566static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2567{
2568 struct c4iw_ep *ep;
2569 struct cpl_pass_establish *req = cplhdr(skb);
2570 struct tid_info *t = dev->rdev.lldi.tids;
2571 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302572 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002573
2574 ep = lookup_tid(t, tid);
2575 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2576 ep->snd_seq = be32_to_cpu(req->snd_isn);
2577 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2578
Vipul Pandya1cab7752012-12-10 09:30:55 +00002579 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2580 ntohs(req->tcp_opt));
2581
Steve Wisecfdda9d2010-04-21 15:30:06 -07002582 set_emss(ep, ntohs(req->tcp_opt));
2583
2584 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302585 mutex_lock(&ep->com.mutex);
2586 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002587 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002588 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad Sfef44222016-05-05 01:27:33 +05302589 ret = send_flowc(ep, skb);
2590 mutex_unlock(&ep->com.mutex);
2591 if (ret)
2592 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002593
2594 return 0;
2595}
2596
2597static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2598{
2599 struct cpl_peer_close *hdr = cplhdr(skb);
2600 struct c4iw_ep *ep;
2601 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002602 int disconnect = 1;
2603 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002604 struct tid_info *t = dev->rdev.lldi.tids;
2605 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002606 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002607
2608 ep = lookup_tid(t, tid);
2609 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2610 dst_confirm(ep->dst);
2611
Vipul Pandya793dad92012-12-10 09:30:56 +00002612 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002613 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002614 switch (ep->com.state) {
2615 case MPA_REQ_WAIT:
2616 __state_set(&ep->com, CLOSING);
2617 break;
2618 case MPA_REQ_SENT:
2619 __state_set(&ep->com, CLOSING);
2620 connect_reply_upcall(ep, -ECONNRESET);
2621 break;
2622 case MPA_REQ_RCVD:
2623
2624 /*
2625 * We're gonna mark this puppy DEAD, but keep
2626 * the reference on it until the ULP accepts or
2627 * rejects the CR. Also wake up anyone waiting
2628 * in rdma connection migration (see c4iw_accept_cr()).
2629 */
2630 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002631 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002632 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002633 break;
2634 case MPA_REP_SENT:
2635 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002636 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002637 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002638 break;
2639 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002640 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002641 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002642 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002643 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002644 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002645 if (ret != -ECONNRESET) {
2646 peer_close_upcall(ep);
2647 disconnect = 1;
2648 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002649 break;
2650 case ABORTING:
2651 disconnect = 0;
2652 break;
2653 case CLOSING:
2654 __state_set(&ep->com, MORIBUND);
2655 disconnect = 0;
2656 break;
2657 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002658 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002659 if (ep->com.cm_id && ep->com.qp) {
2660 attrs.next_state = C4IW_QP_STATE_IDLE;
2661 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2662 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2663 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302664 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002665 __state_set(&ep->com, DEAD);
2666 release = 1;
2667 disconnect = 0;
2668 break;
2669 case DEAD:
2670 disconnect = 0;
2671 break;
2672 default:
2673 BUG_ON(1);
2674 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002675 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002676 if (disconnect)
2677 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2678 if (release)
2679 release_ep_resources(ep);
2680 return 0;
2681}
2682
Steve Wisecfdda9d2010-04-21 15:30:06 -07002683static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2684{
2685 struct cpl_abort_req_rss *req = cplhdr(skb);
2686 struct c4iw_ep *ep;
2687 struct cpl_abort_rpl *rpl;
2688 struct sk_buff *rpl_skb;
2689 struct c4iw_qp_attributes attrs;
2690 int ret;
2691 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002692 struct tid_info *t = dev->rdev.lldi.tids;
2693 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002694
2695 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302696 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302697 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2698 __func__, ep->hwtid, req->status,
2699 neg_adv_str(req->status));
2700 ep->stats.abort_neg_adv++;
2701 mutex_lock(&dev->rdev.stats.lock);
2702 dev->rdev.stats.neg_adv++;
2703 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002704 return 0;
2705 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002706 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2707 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002708 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002709
2710 /*
2711 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302712 * However, this is not needed if com state is just
2713 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002714 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302715 if (ep->com.state != MPA_REQ_SENT)
2716 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002717
2718 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002719 switch (ep->com.state) {
2720 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302721 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002722 break;
2723 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002724 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002725 break;
2726 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002727 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002728 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302729 connect_reply_upcall(ep, -ECONNRESET);
2730 else {
2731 /*
2732 * we just don't send notification upwards because we
2733 * want to retry with mpa_v1 without upper layers even
2734 * knowing it.
2735 *
2736 * do some housekeeping so as to re-initiate the
2737 * connection
2738 */
2739 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2740 mpa_rev);
2741 ep->retry_with_mpa_v1 = 1;
2742 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002743 break;
2744 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002745 break;
2746 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002747 break;
2748 case MORIBUND:
2749 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002750 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002751 /*FALLTHROUGH*/
2752 case FPDU_MODE:
2753 if (ep->com.cm_id && ep->com.qp) {
2754 attrs.next_state = C4IW_QP_STATE_ERROR;
2755 ret = c4iw_modify_qp(ep->com.qp->rhp,
2756 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2757 &attrs, 1);
2758 if (ret)
2759 printk(KERN_ERR MOD
2760 "%s - qp <- error failed!\n",
2761 __func__);
2762 }
2763 peer_abort_upcall(ep);
2764 break;
2765 case ABORTING:
2766 break;
2767 case DEAD:
2768 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002769 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002770 return 0;
2771 default:
2772 BUG_ON(1);
2773 break;
2774 }
2775 dst_confirm(ep->dst);
2776 if (ep->com.state != ABORTING) {
2777 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302778 /* we don't release if we want to retry with mpa_v1 */
2779 if (!ep->retry_with_mpa_v1)
2780 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002781 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002782 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002783
2784 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2785 if (!rpl_skb) {
2786 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2787 __func__);
2788 release = 1;
2789 goto out;
2790 }
2791 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2792 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2793 INIT_TP_WR(rpl, ep->hwtid);
2794 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2795 rpl->cmd = CPL_ABORT_NO_RST;
2796 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2797out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002798 if (release)
2799 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002800 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302801 if (ep->com.remote_addr.ss_family == AF_INET6) {
2802 struct sockaddr_in6 *sin6 =
2803 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002804 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302805 cxgb4_clip_release(
2806 ep->com.dev->rdev.lldi.ports[0],
2807 (const u32 *)&sin6->sin6_addr.s6_addr,
2808 1);
2809 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002810 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302811 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2812 dst_release(ep->dst);
2813 cxgb4_l2t_release(ep->l2t);
2814 c4iw_reconnect(ep);
2815 }
2816
Steve Wisecfdda9d2010-04-21 15:30:06 -07002817 return 0;
2818}
2819
2820static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2821{
2822 struct c4iw_ep *ep;
2823 struct c4iw_qp_attributes attrs;
2824 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002825 int release = 0;
2826 struct tid_info *t = dev->rdev.lldi.tids;
2827 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002828
2829 ep = lookup_tid(t, tid);
2830
2831 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2832 BUG_ON(!ep);
2833
2834 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002835 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302836 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002837 switch (ep->com.state) {
2838 case CLOSING:
2839 __state_set(&ep->com, MORIBUND);
2840 break;
2841 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002842 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002843 if ((ep->com.cm_id) && (ep->com.qp)) {
2844 attrs.next_state = C4IW_QP_STATE_IDLE;
2845 c4iw_modify_qp(ep->com.qp->rhp,
2846 ep->com.qp,
2847 C4IW_QP_ATTR_NEXT_STATE,
2848 &attrs, 1);
2849 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302850 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002851 __state_set(&ep->com, DEAD);
2852 release = 1;
2853 break;
2854 case ABORTING:
2855 case DEAD:
2856 break;
2857 default:
2858 BUG_ON(1);
2859 break;
2860 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002861 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002862 if (release)
2863 release_ep_resources(ep);
2864 return 0;
2865}
2866
2867static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2868{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002869 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002870 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002871 unsigned int tid = GET_TID(rpl);
2872 struct c4iw_ep *ep;
2873 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002874
2875 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002876 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002877
Steve Wise30c95c22011-05-09 22:06:22 -07002878 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002879 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2880 ep->com.qp->wq.sq.qid);
2881 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2882 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2883 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2884 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002885 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002886
Steve Wisecfdda9d2010-04-21 15:30:06 -07002887 return 0;
2888}
2889
2890/*
2891 * Upcall from the adapter indicating data has been transmitted.
2892 * For us its just the single MPA request or reply. We can now free
2893 * the skb holding the mpa message.
2894 */
2895static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2896{
2897 struct c4iw_ep *ep;
2898 struct cpl_fw4_ack *hdr = cplhdr(skb);
2899 u8 credits = hdr->credits;
2900 unsigned int tid = GET_TID(hdr);
2901 struct tid_info *t = dev->rdev.lldi.tids;
2902
2903
2904 ep = lookup_tid(t, tid);
2905 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2906 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002907 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2908 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002909 return 0;
2910 }
2911
2912 dst_confirm(ep->dst);
2913 if (ep->mpa_skb) {
2914 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2915 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2916 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2917 kfree_skb(ep->mpa_skb);
2918 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05302919 mutex_lock(&ep->com.mutex);
2920 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
2921 stop_ep_timer(ep);
2922 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002923 }
2924 return 0;
2925}
2926
Steve Wisecfdda9d2010-04-21 15:30:06 -07002927int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2928{
Steve Wisea7db89e2014-03-21 20:40:35 +05302929 int err = 0;
2930 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002931 struct c4iw_ep *ep = to_ep(cm_id);
2932 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2933
Steve Wisea7db89e2014-03-21 20:40:35 +05302934 mutex_lock(&ep->com.mutex);
2935 if (ep->com.state == DEAD) {
2936 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002937 c4iw_put_ep(&ep->com);
2938 return -ECONNRESET;
2939 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002940 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302941 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002942 if (mpa_rev == 0)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302943 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002944 else {
2945 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302946 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002947 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302948 mutex_unlock(&ep->com.mutex);
Hariprasad Se4b76a22016-05-06 22:17:59 +05302949 if (disconnect) {
2950 stop_ep_timer(ep);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302951 err = c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad Se4b76a22016-05-06 22:17:59 +05302952 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002953 c4iw_put_ep(&ep->com);
2954 return 0;
2955}
2956
2957int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2958{
2959 int err;
2960 struct c4iw_qp_attributes attrs;
2961 enum c4iw_qp_attr_mask mask;
2962 struct c4iw_ep *ep = to_ep(cm_id);
2963 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2964 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302965 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002966
2967 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302968
2969 mutex_lock(&ep->com.mutex);
2970 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002971 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302972 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002973 }
2974
Steve Wisea7db89e2014-03-21 20:40:35 +05302975 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002976 BUG_ON(!qp);
2977
Vipul Pandya793dad92012-12-10 09:30:56 +00002978 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302979 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2980 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002981 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302982 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002983 }
2984
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302985 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2986 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302987 if (RELAXED_IRD_NEGOTIATION) {
2988 ep->ord = ep->ird;
2989 } else {
2990 ep->ird = conn_param->ird;
2991 ep->ord = conn_param->ord;
2992 send_mpa_reject(ep, conn_param->private_data,
2993 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302994 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302995 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302996 }
2997 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302998 if (conn_param->ird < ep->ord) {
2999 if (RELAXED_IRD_NEGOTIATION &&
3000 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3001 conn_param->ird = ep->ord;
3002 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303003 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303004 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303005 }
3006 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303007 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003008 ep->ird = conn_param->ird;
3009 ep->ord = conn_param->ord;
3010
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303011 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303012 if (peer2peer && ep->ird == 0)
3013 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303014 } else {
3015 if (peer2peer &&
3016 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303017 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303018 ep->ird = 1;
3019 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003020
3021 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3022
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303023 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303024 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303025 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003026 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303027
Steve Wisecfdda9d2010-04-21 15:30:06 -07003028 /* bind QP to EP and move to RTS */
3029 attrs.mpa_attr = ep->mpa_attr;
3030 attrs.max_ird = ep->ird;
3031 attrs.max_ord = ep->ord;
3032 attrs.llp_stream_handle = ep;
3033 attrs.next_state = C4IW_QP_STATE_RTS;
3034
3035 /* bind QP and TID with INIT_WR */
3036 mask = C4IW_QP_ATTR_NEXT_STATE |
3037 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3038 C4IW_QP_ATTR_MPA_ATTR |
3039 C4IW_QP_ATTR_MAX_IRD |
3040 C4IW_QP_ATTR_MAX_ORD;
3041
3042 err = c4iw_modify_qp(ep->com.qp->rhp,
3043 ep->com.qp, mask, &attrs, 1);
3044 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303045 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303046
3047 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003048 err = send_mpa_reply(ep, conn_param->private_data,
3049 conn_param->private_data_len);
3050 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303051 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003052
Steve Wisea7db89e2014-03-21 20:40:35 +05303053 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003054 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303055 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003056 c4iw_put_ep(&ep->com);
3057 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303058err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303059 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303060err_abort:
3061 abort = 1;
3062err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303063 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303064 if (abort)
3065 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003066 c4iw_put_ep(&ep->com);
3067 return err;
3068}
3069
Vipul Pandya830662f2013-07-04 16:10:47 +05303070static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3071{
3072 struct in_device *ind;
3073 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003074 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3075 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303076
3077 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3078 if (!ind)
3079 return -EADDRNOTAVAIL;
3080 for_primary_ifa(ind) {
3081 laddr->sin_addr.s_addr = ifa->ifa_address;
3082 raddr->sin_addr.s_addr = ifa->ifa_address;
3083 found = 1;
3084 break;
3085 }
3086 endfor_ifa(ind);
3087 in_dev_put(ind);
3088 return found ? 0 : -EADDRNOTAVAIL;
3089}
3090
3091static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3092 unsigned char banned_flags)
3093{
3094 struct inet6_dev *idev;
3095 int err = -EADDRNOTAVAIL;
3096
3097 rcu_read_lock();
3098 idev = __in6_dev_get(dev);
3099 if (idev != NULL) {
3100 struct inet6_ifaddr *ifp;
3101
3102 read_lock_bh(&idev->lock);
3103 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3104 if (ifp->scope == IFA_LINK &&
3105 !(ifp->flags & banned_flags)) {
3106 memcpy(addr, &ifp->addr, 16);
3107 err = 0;
3108 break;
3109 }
3110 }
3111 read_unlock_bh(&idev->lock);
3112 }
3113 rcu_read_unlock();
3114 return err;
3115}
3116
3117static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3118{
3119 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003120 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3121 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303122
Nicholas Krause54b9a962015-08-26 23:00:59 -04003123 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303124 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3125 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3126 return 0;
3127 }
3128 return -EADDRNOTAVAIL;
3129}
3130
Steve Wisecfdda9d2010-04-21 15:30:06 -07003131int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3132{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003133 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3134 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003135 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003136 struct sockaddr_in *laddr;
3137 struct sockaddr_in *raddr;
3138 struct sockaddr_in6 *laddr6;
3139 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303140 __u8 *ra;
3141 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003142
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303143 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3144 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003145 err = -EINVAL;
3146 goto out;
3147 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003148 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3149 if (!ep) {
3150 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3151 err = -ENOMEM;
3152 goto out;
3153 }
3154 init_timer(&ep->timer);
3155 ep->plen = conn_param->private_data_len;
3156 if (ep->plen)
3157 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3158 conn_param->private_data, ep->plen);
3159 ep->ird = conn_param->ird;
3160 ep->ord = conn_param->ord;
3161
3162 if (peer2peer && ep->ord == 0)
3163 ep->ord = 1;
3164
Steve Wisecfdda9d2010-04-21 15:30:06 -07003165 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303166 ref_cm_id(&ep->com);
3167 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003168 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303169 if (!ep->com.qp) {
3170 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3171 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003172 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303173 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003174 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003175 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3176 ep->com.qp, cm_id);
3177
3178 /*
3179 * Allocate an active TID to initiate a TCP connection.
3180 */
3181 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3182 if (ep->atid == -1) {
3183 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3184 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003185 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003186 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003187 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003188
Steve Wise170003c2016-02-26 09:18:03 -06003189 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003190 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003191 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003192 sizeof(ep->com.remote_addr));
3193
Steve Wise170003c2016-02-26 09:18:03 -06003194 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3195 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3196 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3197 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003198
Steve Wise170003c2016-02-26 09:18:03 -06003199 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303200 iptype = 4;
3201 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003202
Vipul Pandya830662f2013-07-04 16:10:47 +05303203 /*
3204 * Handle loopback requests to INADDR_ANY.
3205 */
3206 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3207 err = pick_local_ipaddrs(dev, cm_id);
3208 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003209 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303210 }
3211
3212 /* find a route */
3213 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3214 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3215 ra, ntohs(raddr->sin_port));
3216 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3217 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303218 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303219 } else {
3220 iptype = 6;
3221 ra = (__u8 *)&raddr6->sin6_addr;
3222
3223 /*
3224 * Handle loopback requests to INADDR_ANY.
3225 */
3226 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3227 err = pick_local_ip6addrs(dev, cm_id);
3228 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003229 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303230 }
3231
3232 /* find a route */
3233 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3234 __func__, laddr6->sin6_addr.s6_addr,
3235 ntohs(laddr6->sin6_port),
3236 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3237 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3238 raddr6->sin6_addr.s6_addr,
3239 laddr6->sin6_port, raddr6->sin6_port, 0,
3240 raddr6->sin6_scope_id);
3241 }
3242 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003243 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3244 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003245 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003246 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003247
Hariprasad S963cab52015-09-23 17:19:27 +05303248 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303249 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003250 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003251 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003252 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003253 }
3254
3255 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3256 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3257 ep->l2t->idx);
3258
3259 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303260 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003261
3262 /* send connect request to rnic */
3263 err = send_connect(ep);
3264 if (!err)
3265 goto out;
3266
3267 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003268fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003269 dst_release(ep->dst);
3270fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003271 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003272 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003273fail1:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303274 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003275 c4iw_put_ep(&ep->com);
3276out:
3277 return err;
3278}
3279
Vipul Pandya830662f2013-07-04 16:10:47 +05303280static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3281{
3282 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003283 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003284 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303285
Hariprasad S28de1f72016-01-13 10:03:14 +05303286 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3287 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3288 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3289 if (err)
3290 return err;
3291 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303292 c4iw_init_wr_wait(&ep->com.wr_wait);
3293 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3294 ep->stid, &sin6->sin6_addr,
3295 sin6->sin6_port,
3296 ep->com.dev->rdev.lldi.rxq_ids[0]);
3297 if (!err)
3298 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3299 &ep->com.wr_wait,
3300 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303301 else if (err > 0)
3302 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303303 if (err) {
3304 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3305 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303306 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3307 err, ep->stid,
3308 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303309 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303310 return err;
3311}
3312
3313static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3314{
3315 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003316 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003317 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303318
3319 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3320 do {
3321 err = cxgb4_create_server_filter(
3322 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3323 sin->sin_addr.s_addr, sin->sin_port, 0,
3324 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3325 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303326 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3327 err = -EIO;
3328 break;
3329 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303330 set_current_state(TASK_UNINTERRUPTIBLE);
3331 schedule_timeout(usecs_to_jiffies(100));
3332 }
3333 } while (err == -EBUSY);
3334 } else {
3335 c4iw_init_wr_wait(&ep->com.wr_wait);
3336 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3337 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3338 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3339 if (!err)
3340 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3341 &ep->com.wr_wait,
3342 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303343 else if (err > 0)
3344 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303345 }
3346 if (err)
3347 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3348 , err, ep->stid,
3349 &sin->sin_addr, ntohs(sin->sin_port));
3350 return err;
3351}
3352
Steve Wisecfdda9d2010-04-21 15:30:06 -07003353int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3354{
3355 int err = 0;
3356 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3357 struct c4iw_listen_ep *ep;
3358
Steve Wisecfdda9d2010-04-21 15:30:06 -07003359 might_sleep();
3360
3361 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3362 if (!ep) {
3363 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3364 err = -ENOMEM;
3365 goto fail1;
3366 }
3367 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003368 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303369 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003370 ep->com.dev = dev;
3371 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003372 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303373 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003374
3375 /*
3376 * Allocate a server TID.
3377 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303378 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3379 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303380 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003381 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003382 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303383 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003384 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003385
Steve Wisecfdda9d2010-04-21 15:30:06 -07003386 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003387 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003388 err = -ENOMEM;
3389 goto fail2;
3390 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003391 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003392
Steve Wise170003c2016-02-26 09:18:03 -06003393 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3394 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003395
Steve Wisecfdda9d2010-04-21 15:30:06 -07003396 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303397 if (ep->com.local_addr.ss_family == AF_INET)
3398 err = create_server4(dev, ep);
3399 else
3400 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003401 if (!err) {
3402 cm_id->provider_data = ep;
3403 goto out;
3404 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003405
Vipul Pandya830662f2013-07-04 16:10:47 +05303406 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3407 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003408fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303409 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003410 c4iw_put_ep(&ep->com);
3411fail1:
3412out:
3413 return err;
3414}
3415
3416int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3417{
3418 int err;
3419 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3420
3421 PDBG("%s ep %p\n", __func__, ep);
3422
3423 might_sleep();
3424 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303425 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3426 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003427 err = cxgb4_remove_server_filter(
3428 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3429 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3430 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303431 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003432 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303433 err = cxgb4_remove_server(
3434 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3435 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003436 if (err)
3437 goto done;
3438 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3439 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003440 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303441 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3442 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003443 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003444 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303445 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3446 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003447done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303448 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003449 c4iw_put_ep(&ep->com);
3450 return err;
3451}
3452
3453int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3454{
3455 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003456 int close = 0;
3457 int fatal = 0;
3458 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003459
Steve Wise2f5b48c2010-09-10 11:15:36 -05003460 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003461
3462 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3463 states[ep->com.state], abrupt);
3464
Hariprasad S6e410d82016-05-05 01:27:31 +05303465 /*
3466 * Ref the ep here in case we have fatal errors causing the
3467 * ep to be released and freed.
3468 */
3469 c4iw_get_ep(&ep->com);
3470
Steve Wisecfdda9d2010-04-21 15:30:06 -07003471 rdev = &ep->com.dev->rdev;
3472 if (c4iw_fatal_error(rdev)) {
3473 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303474 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003475 ep->com.state = DEAD;
3476 }
3477 switch (ep->com.state) {
3478 case MPA_REQ_WAIT:
3479 case MPA_REQ_SENT:
3480 case MPA_REQ_RCVD:
3481 case MPA_REP_SENT:
3482 case FPDU_MODE:
3483 close = 1;
3484 if (abrupt)
3485 ep->com.state = ABORTING;
3486 else {
3487 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003488 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003489 }
3490 set_bit(CLOSE_SENT, &ep->com.flags);
3491 break;
3492 case CLOSING:
3493 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3494 close = 1;
3495 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003496 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003497 ep->com.state = ABORTING;
3498 } else
3499 ep->com.state = MORIBUND;
3500 }
3501 break;
3502 case MORIBUND:
3503 case ABORTING:
3504 case DEAD:
3505 PDBG("%s ignoring disconnect ep %p state %u\n",
3506 __func__, ep, ep->com.state);
3507 break;
3508 default:
3509 BUG();
3510 break;
3511 }
3512
Steve Wisecfdda9d2010-04-21 15:30:06 -07003513 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003514 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003515 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303516 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003517 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003518 } else {
3519 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003520 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003521 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303522 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303523 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303524 if (!abrupt) {
3525 stop_ep_timer(ep);
3526 close_complete_upcall(ep, -EIO);
3527 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303528 if (ep->com.qp) {
3529 struct c4iw_qp_attributes attrs;
3530
3531 attrs.next_state = C4IW_QP_STATE_ERROR;
3532 ret = c4iw_modify_qp(ep->com.qp->rhp,
3533 ep->com.qp,
3534 C4IW_QP_ATTR_NEXT_STATE,
3535 &attrs, 1);
3536 if (ret)
3537 pr_err(MOD
3538 "%s - qp <- error failed!\n",
3539 __func__);
3540 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003541 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303542 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003543 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003544 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303545 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003546 if (fatal)
3547 release_ep_resources(ep);
3548 return ret;
3549}
3550
Vipul Pandya1cab7752012-12-10 09:30:55 +00003551static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3552 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3553{
3554 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003555 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003556
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003557 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3558 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003559 if (!ep)
3560 return;
3561
3562 switch (req->retval) {
3563 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003564 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3565 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3566 send_fw_act_open_req(ep, atid);
3567 return;
3568 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003569 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003570 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3571 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3572 send_fw_act_open_req(ep, atid);
3573 return;
3574 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003575 break;
3576 default:
3577 pr_info("%s unexpected ofld conn wr retval %d\n",
3578 __func__, req->retval);
3579 break;
3580 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003581 pr_err("active ofld_connect_wr failure %d atid %d\n",
3582 req->retval, atid);
3583 mutex_lock(&dev->rdev.stats.lock);
3584 dev->rdev.stats.act_ofld_conn_fails++;
3585 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003586 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003587 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303588 if (ep->com.remote_addr.ss_family == AF_INET6) {
3589 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003590 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303591 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3592 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3593 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003594 remove_handle(dev, &dev->atid_idr, atid);
3595 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3596 dst_release(ep->dst);
3597 cxgb4_l2t_release(ep->l2t);
3598 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003599}
3600
3601static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3602 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3603{
3604 struct sk_buff *rpl_skb;
3605 struct cpl_pass_accept_req *cpl;
3606 int ret;
3607
Paul Bolle710a3112013-02-05 20:51:30 +00003608 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003609 BUG_ON(!rpl_skb);
3610 if (req->retval) {
3611 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003612 mutex_lock(&dev->rdev.stats.lock);
3613 dev->rdev.stats.pas_ofld_conn_fails++;
3614 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003615 kfree_skb(rpl_skb);
3616 } else {
3617 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3618 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003619 (__force u32) htonl(
3620 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003621 ret = pass_accept_req(dev, rpl_skb);
3622 if (!ret)
3623 kfree_skb(rpl_skb);
3624 }
3625 return;
3626}
3627
3628static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003629{
3630 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003631 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3632
3633 switch (rpl->type) {
3634 case FW6_TYPE_CQE:
3635 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3636 break;
3637 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3638 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3639 switch (req->t_state) {
3640 case TCP_SYN_SENT:
3641 active_ofld_conn_reply(dev, skb, req);
3642 break;
3643 case TCP_SYN_RECV:
3644 passive_ofld_conn_reply(dev, skb, req);
3645 break;
3646 default:
3647 pr_err("%s unexpected ofld conn wr state %d\n",
3648 __func__, req->t_state);
3649 break;
3650 }
3651 break;
3652 }
3653 return 0;
3654}
3655
3656static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3657{
Hariprasad S963cab52015-09-23 17:19:27 +05303658 __be32 l2info;
3659 __be16 hdr_len, vlantag, len;
3660 u16 eth_hdr_len;
3661 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003662 u8 intf;
3663 struct cpl_rx_pkt *cpl = cplhdr(skb);
3664 struct cpl_pass_accept_req *req;
3665 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003666 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303667 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003668
Vipul Pandyaf079af72013-03-14 05:08:58 +00003669 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003670 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303671 vlantag = cpl->vlan;
3672 len = cpl->len;
3673 l2info = cpl->l2info;
3674 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003675 intf = cpl->iff;
3676
3677 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3678
3679 /*
3680 * We need to parse the TCP options from SYN packet.
3681 * to generate cpl_pass_accept_req.
3682 */
3683 memset(&tmp_opt, 0, sizeof(tmp_opt));
3684 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003685 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003686
3687 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3688 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303689 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3690 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303691 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303692 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303693 type = dev->rdev.lldi.adapter_type;
3694 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3695 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3696 req->hdr_len =
3697 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3698 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3699 eth_hdr_len = is_t4(type) ?
3700 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3701 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3702 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3703 IP_HDR_LEN_V(ip_hdr_len) |
3704 ETH_HDR_LEN_V(eth_hdr_len));
3705 } else { /* T6 and later */
3706 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3707 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3708 T6_IP_HDR_LEN_V(ip_hdr_len) |
3709 T6_ETH_HDR_LEN_V(eth_hdr_len));
3710 }
3711 req->vlan = vlantag;
3712 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003713 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3714 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003715 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3716 if (tmp_opt.wscale_ok)
3717 req->tcpopt.wsf = tmp_opt.snd_wscale;
3718 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3719 if (tmp_opt.sack_ok)
3720 req->tcpopt.sack = 1;
3721 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3722 return;
3723}
3724
3725static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3726 __be32 laddr, __be16 lport,
3727 __be32 raddr, __be16 rport,
3728 u32 rcv_isn, u32 filter, u16 window,
3729 u32 rss_qid, u8 port_id)
3730{
3731 struct sk_buff *req_skb;
3732 struct fw_ofld_connection_wr *req;
3733 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303734 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003735
3736 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3737 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3738 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003739 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303740 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303741 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003742 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003743 req->le.lport = lport;
3744 req->le.pport = rport;
3745 req->le.u.ipv4.lip = laddr;
3746 req->le.u.ipv4.pip = raddr;
3747 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3748 req->tcb.rcv_adv = htons(window);
3749 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303750 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3751 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3752 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003753 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003754
3755 /*
3756 * We store the qid in opt2 which will be used by the firmware
3757 * to send us the wr response.
3758 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003759 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003760
3761 /*
3762 * We initialize the MSS index in TCB to 0xF.
3763 * So that when driver sends cpl_pass_accept_rpl
3764 * TCB picks up the correct value. If this was 0
3765 * TP will ignore any value > 0 for MSS index.
3766 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003767 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303768 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003769
3770 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303771 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3772 if (ret < 0) {
3773 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3774 ret);
3775 kfree_skb(skb);
3776 kfree_skb(req_skb);
3777 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003778}
3779
3780/*
3781 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3782 * messages when a filter is being used instead of server to
3783 * redirect a syn packet. When packets hit filter they are redirected
3784 * to the offload queue and driver tries to establish the connection
3785 * using firmware work request.
3786 */
3787static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3788{
3789 int stid;
3790 unsigned int filter;
3791 struct ethhdr *eh = NULL;
3792 struct vlan_ethhdr *vlan_eh = NULL;
3793 struct iphdr *iph;
3794 struct tcphdr *tcph;
3795 struct rss_header *rss = (void *)skb->data;
3796 struct cpl_rx_pkt *cpl = (void *)skb->data;
3797 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3798 struct l2t_entry *e;
3799 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003800 struct c4iw_ep *lep;
3801 u16 window;
3802 struct port_info *pi;
3803 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003804 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003805 int step;
3806 u32 tx_chan;
3807 struct neighbour *neigh;
3808
3809 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003810 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003811 goto reject;
3812
3813 /*
3814 * Drop all packets which did not hit the filter.
3815 * Unlikely to happen.
3816 */
3817 if (!(rss->filter_hit && rss->filter_tid))
3818 goto reject;
3819
3820 /*
3821 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3822 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303823 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003824
3825 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3826 if (!lep) {
3827 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3828 goto reject;
3829 }
3830
Hariprasad S963cab52015-09-23 17:19:27 +05303831 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3832 case CHELSIO_T4:
3833 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3834 break;
3835 case CHELSIO_T5:
3836 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3837 break;
3838 case CHELSIO_T6:
3839 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3840 break;
3841 default:
3842 pr_err("T%d Chip is not supported\n",
3843 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3844 goto reject;
3845 }
3846
Vipul Pandyaf079af72013-03-14 05:08:58 +00003847 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003848 eh = (struct ethhdr *)(req + 1);
3849 iph = (struct iphdr *)(eh + 1);
3850 } else {
3851 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3852 iph = (struct iphdr *)(vlan_eh + 1);
3853 skb->vlan_tci = ntohs(cpl->vlan);
3854 }
3855
3856 if (iph->version != 0x4)
3857 goto reject;
3858
3859 tcph = (struct tcphdr *)(iph + 1);
3860 skb_set_network_header(skb, (void *)iph - (void *)rss);
3861 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3862 skb_get(skb);
3863
3864 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3865 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3866 ntohs(tcph->source), iph->tos);
3867
Vipul Pandya830662f2013-07-04 16:10:47 +05303868 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3869 iph->tos);
3870 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003871 pr_err("%s - failed to find dst entry!\n",
3872 __func__);
3873 goto reject;
3874 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003875 neigh = dst_neigh_lookup_skb(dst, skb);
3876
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003877 if (!neigh) {
3878 pr_err("%s - failed to allocate neigh!\n",
3879 __func__);
3880 goto free_dst;
3881 }
3882
Vipul Pandya1cab7752012-12-10 09:30:55 +00003883 if (neigh->dev->flags & IFF_LOOPBACK) {
3884 pdev = ip_dev_find(&init_net, iph->daddr);
3885 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3886 pdev, 0);
3887 pi = (struct port_info *)netdev_priv(pdev);
3888 tx_chan = cxgb4_port_chan(pdev);
3889 dev_put(pdev);
3890 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303891 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003892 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303893 pdev, 0);
3894 pi = (struct port_info *)netdev_priv(pdev);
3895 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003896 }
Steve Wiseebf00062014-03-19 17:44:40 +05303897 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003898 if (!e) {
3899 pr_err("%s - failed to allocate l2t entry!\n",
3900 __func__);
3901 goto free_dst;
3902 }
3903
3904 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3905 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003906 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003907
3908 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303909 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3910 dev->rdev.lldi.ports[0],
3911 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003912
3913 /*
3914 * Synthesize the cpl_pass_accept_req. We have everything except the
3915 * TID. Once firmware sends a reply with TID we update the TID field
3916 * in cpl and pass it through the regular cpl_pass_accept_req path.
3917 */
3918 build_cpl_pass_accept_req(skb, stid, iph->tos);
3919 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3920 tcph->source, ntohl(tcph->seq), filter, window,
3921 rss_qid, pi->port_id);
3922 cxgb4_l2t_release(e);
3923free_dst:
3924 dst_release(dst);
3925reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003926 return 0;
3927}
3928
Steve Wisecfdda9d2010-04-21 15:30:06 -07003929/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003930 * These are the real handlers that are called from a
3931 * work queue.
3932 */
Hariprasad S9dec9002016-05-05 01:27:29 +05303933static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003934 [CPL_ACT_ESTABLISH] = act_establish,
3935 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3936 [CPL_RX_DATA] = rx_data,
3937 [CPL_ABORT_RPL_RSS] = abort_rpl,
3938 [CPL_ABORT_RPL] = abort_rpl,
3939 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3940 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3941 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3942 [CPL_PASS_ESTABLISH] = pass_establish,
3943 [CPL_PEER_CLOSE] = peer_close,
3944 [CPL_ABORT_REQ_RSS] = peer_abort,
3945 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3946 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003947 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003948 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05303949 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05303950 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
3951 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003952};
3953
3954static void process_timeout(struct c4iw_ep *ep)
3955{
3956 struct c4iw_qp_attributes attrs;
3957 int abort = 1;
3958
Steve Wise2f5b48c2010-09-10 11:15:36 -05003959 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003960 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3961 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003962 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003963 switch (ep->com.state) {
3964 case MPA_REQ_SENT:
3965 __state_set(&ep->com, ABORTING);
3966 connect_reply_upcall(ep, -ETIMEDOUT);
3967 break;
3968 case MPA_REQ_WAIT:
Hariprasad Se4b76a22016-05-06 22:17:59 +05303969 case MPA_REP_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003970 __state_set(&ep->com, ABORTING);
3971 break;
3972 case CLOSING:
3973 case MORIBUND:
3974 if (ep->com.cm_id && ep->com.qp) {
3975 attrs.next_state = C4IW_QP_STATE_ERROR;
3976 c4iw_modify_qp(ep->com.qp->rhp,
3977 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3978 &attrs, 1);
3979 }
3980 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303981 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003982 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003983 case ABORTING:
3984 case DEAD:
3985
3986 /*
3987 * These states are expected if the ep timed out at the same
3988 * time as another thread was calling stop_ep_timer().
3989 * So we silently do nothing for these states.
3990 */
3991 abort = 0;
3992 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003993 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003994 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003995 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003996 abort = 0;
3997 }
Steve Wisecc18b932014-04-24 14:31:53 -05003998 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05303999 if (abort)
4000 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004001 c4iw_put_ep(&ep->com);
4002}
4003
4004static void process_timedout_eps(void)
4005{
4006 struct c4iw_ep *ep;
4007
4008 spin_lock_irq(&timeout_lock);
4009 while (!list_empty(&timeout_list)) {
4010 struct list_head *tmp;
4011
4012 tmp = timeout_list.next;
4013 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004014 tmp->next = NULL;
4015 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004016 spin_unlock_irq(&timeout_lock);
4017 ep = list_entry(tmp, struct c4iw_ep, entry);
4018 process_timeout(ep);
4019 spin_lock_irq(&timeout_lock);
4020 }
4021 spin_unlock_irq(&timeout_lock);
4022}
4023
4024static void process_work(struct work_struct *work)
4025{
4026 struct sk_buff *skb = NULL;
4027 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004028 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004029 unsigned int opcode;
4030 int ret;
4031
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004032 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004033 while ((skb = skb_dequeue(&rxq))) {
4034 rpl = cplhdr(skb);
4035 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4036 opcode = rpl->ot.opcode;
4037
4038 BUG_ON(!work_handlers[opcode]);
4039 ret = work_handlers[opcode](dev, skb);
4040 if (!ret)
4041 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004042 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004043 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004044}
4045
4046static DECLARE_WORK(skb_work, process_work);
4047
4048static void ep_timeout(unsigned long arg)
4049{
4050 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004051 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004052
4053 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004054 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004055 /*
4056 * Only insert if it is not already on the list.
4057 */
4058 if (!ep->entry.next) {
4059 list_add_tail(&ep->entry, &timeout_list);
4060 kickit = 1;
4061 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004062 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004063 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004064 if (kickit)
4065 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004066}
4067
4068/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004069 * All the CM events are handled on a work queue to have a safe context.
4070 */
4071static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4072{
4073
4074 /*
4075 * Save dev in the skb->cb area.
4076 */
4077 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4078
4079 /*
4080 * Queue the skb and schedule the worker thread.
4081 */
4082 skb_queue_tail(&rxq, skb);
4083 queue_work(workq, &skb_work);
4084 return 0;
4085}
4086
4087static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4088{
4089 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4090
4091 if (rpl->status != CPL_ERR_NONE) {
4092 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4093 "for tid %u\n", rpl->status, GET_TID(rpl));
4094 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004095 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004096 return 0;
4097}
4098
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004099static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4100{
4101 struct cpl_fw6_msg *rpl = cplhdr(skb);
4102 struct c4iw_wr_wait *wr_waitp;
4103 int ret;
4104
4105 PDBG("%s type %u\n", __func__, rpl->type);
4106
4107 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004108 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004109 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004110 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004111 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004112 if (wr_waitp)
4113 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004114 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004115 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004116 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004117 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004118 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004119 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004120 default:
4121 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4122 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004123 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004124 break;
4125 }
4126 return 0;
4127}
4128
Steve Wise8da7e7a2011-06-14 20:59:27 +00004129static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4130{
4131 struct cpl_abort_req_rss *req = cplhdr(skb);
4132 struct c4iw_ep *ep;
4133 struct tid_info *t = dev->rdev.lldi.tids;
4134 unsigned int tid = GET_TID(req);
4135
4136 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05004137 if (!ep) {
4138 printk(KERN_WARNING MOD
4139 "Abort on non-existent endpoint, tid %d\n", tid);
4140 kfree_skb(skb);
4141 return 0;
4142 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304143 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304144 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4145 __func__, ep->hwtid, req->status,
4146 neg_adv_str(req->status));
4147 ep->stats.abort_neg_adv++;
4148 dev->rdev.stats.neg_adv++;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004149 kfree_skb(skb);
4150 return 0;
4151 }
4152 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4153 ep->com.state);
4154
4155 /*
4156 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004157 * However, if we are on MPAv2 and want to retry with MPAv1
4158 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004159 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004160 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4161 if (ep->com.state != MPA_REQ_SENT)
4162 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4163 } else
4164 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00004165 sched(dev, skb);
4166 return 0;
4167}
4168
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004169/*
4170 * Most upcalls from the T4 Core go to sched() to
4171 * schedule the processing on a work queue.
4172 */
4173c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4174 [CPL_ACT_ESTABLISH] = sched,
4175 [CPL_ACT_OPEN_RPL] = sched,
4176 [CPL_RX_DATA] = sched,
4177 [CPL_ABORT_RPL_RSS] = sched,
4178 [CPL_ABORT_RPL] = sched,
4179 [CPL_PASS_OPEN_RPL] = sched,
4180 [CPL_CLOSE_LISTSRV_RPL] = sched,
4181 [CPL_PASS_ACCEPT_REQ] = sched,
4182 [CPL_PASS_ESTABLISH] = sched,
4183 [CPL_PEER_CLOSE] = sched,
4184 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004185 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004186 [CPL_RDMA_TERMINATE] = sched,
4187 [CPL_FW4_ACK] = sched,
4188 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004189 [CPL_FW6_MSG] = fw6_msg,
4190 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004191};
4192
Steve Wisecfdda9d2010-04-21 15:30:06 -07004193int __init c4iw_cm_init(void)
4194{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004195 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004196 skb_queue_head_init(&rxq);
4197
4198 workq = create_singlethread_workqueue("iw_cxgb4");
4199 if (!workq)
4200 return -ENOMEM;
4201
Steve Wisecfdda9d2010-04-21 15:30:06 -07004202 return 0;
4203}
4204
Steve Wise46c13762014-06-20 14:26:25 -05004205void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004206{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004207 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004208 flush_workqueue(workq);
4209 destroy_workqueue(workq);
4210}