blob: cae1794cef83cb784f200b597bf78dce9ad10c61 [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);
1050 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1051 BUG_ON(ep->mpa_skb);
1052 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301053 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001054 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1055}
1056
1057static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1058{
1059 int mpalen, wrlen;
1060 struct fw_ofld_tx_data_wr *req;
1061 struct mpa_message *mpa;
1062 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301063 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001064
1065 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1066
1067 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301068 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1069 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001070 wrlen = roundup(mpalen + sizeof *req, 16);
1071
1072 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1073 if (!skb) {
1074 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1075 return -ENOMEM;
1076 }
1077 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1078
1079 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1080 memset(req, 0, wrlen);
1081 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301082 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1083 FW_WR_COMPL_F |
1084 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001085 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301086 FW_WR_FLOWID_V(ep->hwtid) |
1087 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001088 req->plen = cpu_to_be32(mpalen);
1089 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301090 FW_OFLD_TX_DATA_WR_FLUSH_F |
1091 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001092
1093 mpa = (struct mpa_message *)(req + 1);
1094 memset(mpa, 0, sizeof(*mpa));
1095 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1096 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
1097 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301098 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001099 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301100
1101 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1102 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001103 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1104 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301105 mpa_v2_params.ird = htons((u16)ep->ird);
1106 mpa_v2_params.ord = htons((u16)ep->ord);
1107 if (peer2peer && (ep->mpa_attr.p2p_type !=
1108 FW_RI_INIT_P2PTYPE_DISABLED)) {
1109 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1110
1111 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1112 mpa_v2_params.ord |=
1113 htons(MPA_V2_RDMA_WRITE_RTR);
1114 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1115 mpa_v2_params.ord |=
1116 htons(MPA_V2_RDMA_READ_RTR);
1117 }
1118
1119 memcpy(mpa->private_data, &mpa_v2_params,
1120 sizeof(struct mpa_v2_conn_params));
1121
1122 if (ep->plen)
1123 memcpy(mpa->private_data +
1124 sizeof(struct mpa_v2_conn_params), pdata, plen);
1125 } else
1126 if (plen)
1127 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001128
1129 /*
1130 * Reference the mpa skb. This ensures the data area
1131 * will remain in memory until the hw acks the tx.
1132 * Function fw4_ack() will deref it.
1133 */
1134 skb_get(skb);
1135 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1136 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301137 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301138 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001139 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1140}
1141
1142static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1143{
1144 struct c4iw_ep *ep;
1145 struct cpl_act_establish *req = cplhdr(skb);
1146 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001147 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001148 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301149 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001150
1151 ep = lookup_atid(t, atid);
1152
1153 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1154 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1155
Steve Wisea7db89e2014-03-21 20:40:35 +05301156 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001157 dst_confirm(ep->dst);
1158
1159 /* setup the hwtid for this connection */
1160 ep->hwtid = tid;
1161 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001162 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001163
1164 ep->snd_seq = be32_to_cpu(req->snd_isn);
1165 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1166
1167 set_emss(ep, ntohs(req->tcp_opt));
1168
1169 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001170 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001171 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001172 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001173
1174 /* start MPA negotiation */
Hariprasad Sfef44222016-05-05 01:27:33 +05301175 ret = send_flowc(ep, NULL);
1176 if (ret)
1177 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301178 if (ep->retry_with_mpa_v1)
1179 send_mpa_req(ep, skb, 1);
1180 else
1181 send_mpa_req(ep, skb, mpa_rev);
Steve Wisea7db89e2014-03-21 20:40:35 +05301182 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001183 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301184err:
1185 mutex_unlock(&ep->com.mutex);
1186 connect_reply_upcall(ep, -ENOMEM);
1187 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1188 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001189}
1190
Steve Wisebe13b2d2014-03-21 20:40:33 +05301191static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001192{
1193 struct iw_cm_event event;
1194
1195 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1196 memset(&event, 0, sizeof(event));
1197 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301198 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001199 if (ep->com.cm_id) {
1200 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1201 ep, ep->com.cm_id, ep->hwtid);
1202 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301203 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001204 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001205 }
1206}
1207
Steve Wisecfdda9d2010-04-21 15:30:06 -07001208static void peer_close_upcall(struct c4iw_ep *ep)
1209{
1210 struct iw_cm_event event;
1211
1212 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1213 memset(&event, 0, sizeof(event));
1214 event.event = IW_CM_EVENT_DISCONNECT;
1215 if (ep->com.cm_id) {
1216 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1217 ep, ep->com.cm_id, ep->hwtid);
1218 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001219 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001220 }
1221}
1222
1223static void peer_abort_upcall(struct c4iw_ep *ep)
1224{
1225 struct iw_cm_event event;
1226
1227 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1228 memset(&event, 0, sizeof(event));
1229 event.event = IW_CM_EVENT_CLOSE;
1230 event.status = -ECONNRESET;
1231 if (ep->com.cm_id) {
1232 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1233 ep->com.cm_id, ep->hwtid);
1234 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301235 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001236 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001237 }
1238}
1239
1240static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1241{
1242 struct iw_cm_event event;
1243
1244 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1245 memset(&event, 0, sizeof(event));
1246 event.event = IW_CM_EVENT_CONNECT_REPLY;
1247 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301248 memcpy(&event.local_addr, &ep->com.local_addr,
1249 sizeof(ep->com.local_addr));
1250 memcpy(&event.remote_addr, &ep->com.remote_addr,
1251 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001252
1253 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301254 if (!ep->tried_with_mpa_v1) {
1255 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301256 event.ord = ep->ird;
1257 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301258 event.private_data_len = ep->plen -
1259 sizeof(struct mpa_v2_conn_params);
1260 event.private_data = ep->mpa_pkt +
1261 sizeof(struct mpa_message) +
1262 sizeof(struct mpa_v2_conn_params);
1263 } else {
1264 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301265 event.ord = cur_max_read_depth(ep->com.dev);
1266 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301267 event.private_data_len = ep->plen;
1268 event.private_data = ep->mpa_pkt +
1269 sizeof(struct mpa_message);
1270 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001271 }
Roland Dreier85963e42010-07-19 13:13:09 -07001272
1273 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1274 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001275 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001276 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1277
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301278 if (status < 0)
1279 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001280}
1281
Steve Wisebe13b2d2014-03-21 20:40:33 +05301282static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001283{
1284 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301285 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001286
1287 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1288 memset(&event, 0, sizeof(event));
1289 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301290 memcpy(&event.local_addr, &ep->com.local_addr,
1291 sizeof(ep->com.local_addr));
1292 memcpy(&event.remote_addr, &ep->com.remote_addr,
1293 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001294 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301295 if (!ep->tried_with_mpa_v1) {
1296 /* this means MPA_v2 is used */
1297 event.ord = ep->ord;
1298 event.ird = ep->ird;
1299 event.private_data_len = ep->plen -
1300 sizeof(struct mpa_v2_conn_params);
1301 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1302 sizeof(struct mpa_v2_conn_params);
1303 } else {
1304 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301305 event.ord = cur_max_read_depth(ep->com.dev);
1306 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301307 event.private_data_len = ep->plen;
1308 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1309 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301310 c4iw_get_ep(&ep->com);
1311 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1312 &event);
1313 if (ret)
1314 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001315 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001316 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301317 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001318}
1319
1320static void established_upcall(struct c4iw_ep *ep)
1321{
1322 struct iw_cm_event event;
1323
1324 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1325 memset(&event, 0, sizeof(event));
1326 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301327 event.ird = ep->ord;
1328 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001329 if (ep->com.cm_id) {
1330 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1331 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001332 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001333 }
1334}
1335
1336static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1337{
1338 struct cpl_rx_data_ack *req;
1339 struct sk_buff *skb;
1340 int wrlen = roundup(sizeof *req, 16);
1341
1342 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1343 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1344 if (!skb) {
1345 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1346 return 0;
1347 }
1348
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301349 /*
1350 * If we couldn't specify the entire rcv window at connection setup
1351 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1352 * then add the overage in to the credits returned.
1353 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001354 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1355 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301356
Steve Wisecfdda9d2010-04-21 15:30:06 -07001357 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1358 memset(req, 0, wrlen);
1359 INIT_TP_WR(req, ep->hwtid);
1360 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1361 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001362 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301363 RX_DACK_CHANGE_F |
1364 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001365 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001366 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1367 return credits;
1368}
1369
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301370#define RELAXED_IRD_NEGOTIATION 1
1371
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301372/*
1373 * process_mpa_reply - process streaming mode MPA reply
1374 *
1375 * Returns:
1376 *
1377 * 0 upon success indicating a connect request was delivered to the ULP
1378 * or the mpa request is incomplete but valid so far.
1379 *
1380 * 1 if a failure requires the caller to close the connection.
1381 *
1382 * 2 if a failure requires the caller to abort the connection.
1383 */
Steve Wisecc18b932014-04-24 14:31:53 -05001384static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001385{
1386 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301387 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001388 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301389 u16 resp_ird, resp_ord;
1390 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001391 struct c4iw_qp_attributes attrs;
1392 enum c4iw_qp_attr_mask mask;
1393 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001394 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001395
1396 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1397
1398 /*
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001399 * Stop mpa timer. If it expired, then
1400 * we ignore the MPA reply. process_timeout()
1401 * will abort the connection.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001402 */
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001403 if (stop_ep_timer(ep))
Steve Wisecc18b932014-04-24 14:31:53 -05001404 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001405
1406 /*
1407 * If we get more than the supported amount of private data
1408 * then we must fail this connection.
1409 */
1410 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1411 err = -EINVAL;
1412 goto err;
1413 }
1414
1415 /*
1416 * copy the new data into our accumulation buffer.
1417 */
1418 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1419 skb->len);
1420 ep->mpa_pkt_len += skb->len;
1421
1422 /*
1423 * if we don't even have the mpa message, then bail.
1424 */
1425 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001426 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001427 mpa = (struct mpa_message *) ep->mpa_pkt;
1428
1429 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301430 if (mpa->revision > mpa_rev) {
1431 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1432 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001433 err = -EPROTO;
1434 goto err;
1435 }
1436 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1437 err = -EPROTO;
1438 goto err;
1439 }
1440
1441 plen = ntohs(mpa->private_data_size);
1442
1443 /*
1444 * Fail if there's too much private data.
1445 */
1446 if (plen > MPA_MAX_PRIVATE_DATA) {
1447 err = -EPROTO;
1448 goto err;
1449 }
1450
1451 /*
1452 * If plen does not account for pkt size
1453 */
1454 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1455 err = -EPROTO;
1456 goto err;
1457 }
1458
1459 ep->plen = (u8) plen;
1460
1461 /*
1462 * If we don't have all the pdata yet, then bail.
1463 * We'll continue process when more data arrives.
1464 */
1465 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001466 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001467
1468 if (mpa->flags & MPA_REJECT) {
1469 err = -ECONNREFUSED;
1470 goto err;
1471 }
1472
1473 /*
1474 * If we get here we have accumulated the entire mpa
1475 * start reply message including private data. And
1476 * the MPA header is valid.
1477 */
Steve Wisec529fb52014-03-21 20:40:37 +05301478 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001479 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1480 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1481 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301482 ep->mpa_attr.version = mpa->revision;
1483 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1484
1485 if (mpa->revision == 2) {
1486 ep->mpa_attr.enhanced_rdma_conn =
1487 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1488 if (ep->mpa_attr.enhanced_rdma_conn) {
1489 mpa_v2_params = (struct mpa_v2_conn_params *)
1490 (ep->mpa_pkt + sizeof(*mpa));
1491 resp_ird = ntohs(mpa_v2_params->ird) &
1492 MPA_V2_IRD_ORD_MASK;
1493 resp_ord = ntohs(mpa_v2_params->ord) &
1494 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301495 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1496 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301497
1498 /*
1499 * This is a double-check. Ideally, below checks are
1500 * not required since ird/ord stuff has been taken
1501 * care of in c4iw_accept_cr
1502 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301503 if (ep->ird < resp_ord) {
1504 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1505 ep->com.dev->rdev.lldi.max_ordird_qp)
1506 ep->ird = resp_ord;
1507 else
1508 insuff_ird = 1;
1509 } else if (ep->ird > resp_ord) {
1510 ep->ird = resp_ord;
1511 }
1512 if (ep->ord > resp_ird) {
1513 if (RELAXED_IRD_NEGOTIATION)
1514 ep->ord = resp_ird;
1515 else
1516 insuff_ird = 1;
1517 }
1518 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301519 err = -ENOMEM;
1520 ep->ird = resp_ord;
1521 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301522 }
1523
1524 if (ntohs(mpa_v2_params->ird) &
1525 MPA_V2_PEER2PEER_MODEL) {
1526 if (ntohs(mpa_v2_params->ord) &
1527 MPA_V2_RDMA_WRITE_RTR)
1528 ep->mpa_attr.p2p_type =
1529 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1530 else if (ntohs(mpa_v2_params->ord) &
1531 MPA_V2_RDMA_READ_RTR)
1532 ep->mpa_attr.p2p_type =
1533 FW_RI_INIT_P2PTYPE_READ_REQ;
1534 }
1535 }
1536 } else if (mpa->revision == 1)
1537 if (peer2peer)
1538 ep->mpa_attr.p2p_type = p2p_type;
1539
Steve Wisecfdda9d2010-04-21 15:30:06 -07001540 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301541 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1542 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1543 ep->mpa_attr.recv_marker_enabled,
1544 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1545 ep->mpa_attr.p2p_type, p2p_type);
1546
1547 /*
1548 * If responder's RTR does not match with that of initiator, assign
1549 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1550 * generated when moving QP to RTS state.
1551 * A TERM message will be sent after QP has moved to RTS state
1552 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001553 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301554 (ep->mpa_attr.p2p_type != p2p_type)) {
1555 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1556 rtr_mismatch = 1;
1557 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001558
1559 attrs.mpa_attr = ep->mpa_attr;
1560 attrs.max_ird = ep->ird;
1561 attrs.max_ord = ep->ord;
1562 attrs.llp_stream_handle = ep;
1563 attrs.next_state = C4IW_QP_STATE_RTS;
1564
1565 mask = C4IW_QP_ATTR_NEXT_STATE |
1566 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1567 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1568
1569 /* bind QP and TID with INIT_WR */
1570 err = c4iw_modify_qp(ep->com.qp->rhp,
1571 ep->com.qp, mask, &attrs, 1);
1572 if (err)
1573 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301574
1575 /*
1576 * If responder's RTR requirement did not match with what initiator
1577 * supports, generate TERM message
1578 */
1579 if (rtr_mismatch) {
1580 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1581 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1582 attrs.ecode = MPA_NOMATCH_RTR;
1583 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001584 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301585 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001586 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301587 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001588 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301589 goto out;
1590 }
1591
1592 /*
1593 * Generate TERM if initiator IRD is not sufficient for responder
1594 * provided ORD. Currently, we do the same behaviour even when
1595 * responder provided IRD is also not sufficient as regards to
1596 * initiator ORD.
1597 */
1598 if (insuff_ird) {
1599 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1600 __func__);
1601 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1602 attrs.ecode = MPA_INSUFF_IRD;
1603 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001604 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301605 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001606 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301607 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001608 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301609 goto out;
1610 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001611 goto out;
1612err:
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
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001745 /*
1746 * If the endpoint timer already expired, then we ignore
1747 * the start request. process_timeout() will abort
1748 * the connection.
1749 */
1750 if (!stop_ep_timer(ep)) {
1751 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001752
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001753 /* drive upcall */
Hariprasad Shenai10be6b42014-11-21 09:36:35 -06001754 mutex_lock_nested(&ep->parent_ep->com.mutex,
1755 SINGLE_DEPTH_NESTING);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001756 if (ep->parent_ep->com.state != DEAD) {
1757 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301758 goto err_unlock_parent;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001759 } else {
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301760 goto err_unlock_parent;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001761 }
1762 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301763 }
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301764 return 0;
1765
1766err_unlock_parent:
1767 mutex_unlock(&ep->parent_ep->com.mutex);
1768 goto err_out;
1769err_stop_timer:
1770 (void)stop_ep_timer(ep);
1771err_out:
1772 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001773}
1774
1775static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1776{
1777 struct c4iw_ep *ep;
1778 struct cpl_rx_data *hdr = cplhdr(skb);
1779 unsigned int dlen = ntohs(hdr->len);
1780 unsigned int tid = GET_TID(hdr);
1781 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001782 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001783 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001784
1785 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301786 if (!ep)
1787 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001788 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1789 skb_pull(skb, sizeof(*hdr));
1790 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301791 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001792
Steve Wisecfdda9d2010-04-21 15:30:06 -07001793 /* update RX credits */
1794 update_rx_credits(ep, dlen);
1795
Steve Wisec529fb52014-03-21 20:40:37 +05301796 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001797 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001798 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001799 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001800 break;
1801 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001802 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001803 process_mpa_request(ep, skb);
1804 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001805 case FPDU_MODE: {
1806 struct c4iw_qp_attributes attrs;
1807 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001808 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001809 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001810 " qpid %u ep %p state %d tid %u status %d\n",
1811 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301812 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301813 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001814 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001815 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1816 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001817 break;
1818 }
Vipul Pandya15579672013-01-07 13:11:52 +00001819 default:
1820 break;
1821 }
Steve Wisec529fb52014-03-21 20:40:37 +05301822 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001823 if (disconnect)
1824 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001825 return 0;
1826}
1827
1828static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1829{
1830 struct c4iw_ep *ep;
1831 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001832 int release = 0;
1833 unsigned int tid = GET_TID(rpl);
1834 struct tid_info *t = dev->rdev.lldi.tids;
1835
1836 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301837 if (!ep) {
1838 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1839 return 0;
1840 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001841 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001842 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001843 switch (ep->com.state) {
1844 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001845 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001846 __state_set(&ep->com, DEAD);
1847 release = 1;
1848 break;
1849 default:
1850 printk(KERN_ERR "%s ep %p state %d\n",
1851 __func__, ep, ep->com.state);
1852 break;
1853 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001854 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001855
1856 if (release)
1857 release_ep_resources(ep);
1858 return 0;
1859}
1860
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001861static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1862{
1863 struct sk_buff *skb;
1864 struct fw_ofld_connection_wr *req;
1865 unsigned int mtu_idx;
1866 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301867 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301868 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001869
1870 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1871 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1872 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001873 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301874 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301875 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1876 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001877 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001878 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301879 req->le.lport = sin->sin_port;
1880 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001881 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301882 req->le.pport = sin->sin_port;
1883 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001884 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301885 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1886 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001887 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301888 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001889 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001890 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301891 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301892 enable_tcp_timestamps,
1893 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001894 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301895
1896 /*
1897 * Specify the largest window that will fit in opt0. The
1898 * remainder will be specified in the rx_data_ack.
1899 */
1900 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001901 if (win > RCV_BUFSIZ_M)
1902 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301903
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001904 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1905 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001906 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001907 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001908 WND_SCALE_V(wscale) |
1909 MSS_IDX_V(mtu_idx) |
1910 L2T_IDX_V(ep->l2t->idx) |
1911 TX_CHAN_V(ep->tx_chan) |
1912 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301913 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001914 ULP_MODE_V(ULP_MODE_TCPDDP) |
1915 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001916 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1917 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001918 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001919 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001920 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001921 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001922 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001923 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001924 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001925 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001926 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1927 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1928 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001929 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1930 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001931 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1932}
1933
Steve Wisecfdda9d2010-04-21 15:30:06 -07001934/*
1935 * Return whether a failed active open has allocated a TID
1936 */
1937static inline int act_open_has_tid(int status)
1938{
1939 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1940 status != CPL_ERR_ARP_MISS;
1941}
1942
Steve Wise7a2cea22014-03-14 21:52:07 +05301943/* Returns whether a CPL status conveys negative advice.
1944 */
1945static int is_neg_adv(unsigned int status)
1946{
1947 return status == CPL_ERR_RTX_NEG_ADVICE ||
1948 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1949 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1950}
1951
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301952static char *neg_adv_str(unsigned int status)
1953{
1954 switch (status) {
1955 case CPL_ERR_RTX_NEG_ADVICE:
1956 return "Retransmit timeout";
1957 case CPL_ERR_PERSIST_NEG_ADVICE:
1958 return "Persist timeout";
1959 case CPL_ERR_KEEPALV_NEG_ADVICE:
1960 return "Keepalive timeout";
1961 default:
1962 return "Unknown";
1963 }
1964}
1965
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301966static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1967{
1968 ep->snd_win = snd_win;
1969 ep->rcv_win = rcv_win;
1970 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1971}
1972
Vipul Pandya793dad92012-12-10 09:30:56 +00001973#define ACT_OPEN_RETRY_COUNT 2
1974
Vipul Pandya830662f2013-07-04 16:10:47 +05301975static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1976 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301977 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05301978{
1979 struct neighbour *n;
1980 int err, step;
1981 struct net_device *pdev;
1982
1983 n = dst_neigh_lookup(dst, peer_ip);
1984 if (!n)
1985 return -ENODEV;
1986
1987 rcu_read_lock();
1988 err = -ENOMEM;
1989 if (n->dev->flags & IFF_LOOPBACK) {
1990 if (iptype == 4)
1991 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1992 else if (IS_ENABLED(CONFIG_IPV6))
1993 for_each_netdev(&init_net, pdev) {
1994 if (ipv6_chk_addr(&init_net,
1995 (struct in6_addr *)peer_ip,
1996 pdev, 1))
1997 break;
1998 }
1999 else
2000 pdev = NULL;
2001
2002 if (!pdev) {
2003 err = -ENODEV;
2004 goto out;
2005 }
2006 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302007 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05302008 if (!ep->l2t)
2009 goto out;
2010 ep->mtu = pdev->mtu;
2011 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302012 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2013 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302014 step = cdev->rdev.lldi.ntxq /
2015 cdev->rdev.lldi.nchan;
2016 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2017 step = cdev->rdev.lldi.nrxq /
2018 cdev->rdev.lldi.nchan;
2019 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2020 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2021 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302022 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302023 dev_put(pdev);
2024 } else {
2025 pdev = get_real_dev(n->dev);
2026 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2027 n, pdev, 0);
2028 if (!ep->l2t)
2029 goto out;
2030 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002031 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302032 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2033 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302034 step = cdev->rdev.lldi.ntxq /
2035 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002036 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2037 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302038 step = cdev->rdev.lldi.nrxq /
2039 cdev->rdev.lldi.nchan;
2040 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002041 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302042 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302043
2044 if (clear_mpa_v1) {
2045 ep->retry_with_mpa_v1 = 0;
2046 ep->tried_with_mpa_v1 = 0;
2047 }
2048 }
2049 err = 0;
2050out:
2051 rcu_read_unlock();
2052
2053 neigh_release(n);
2054
2055 return err;
2056}
2057
Vipul Pandya793dad92012-12-10 09:30:56 +00002058static int c4iw_reconnect(struct c4iw_ep *ep)
2059{
2060 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302061 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002062 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302063 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002064 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302065 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002066 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302067 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002068 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302069 int iptype;
2070 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002071
2072 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2073 init_timer(&ep->timer);
2074
2075 /*
2076 * Allocate an active TID to initiate a TCP connection.
2077 */
2078 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2079 if (ep->atid == -1) {
2080 pr_err("%s - cannot alloc atid.\n", __func__);
2081 err = -ENOMEM;
2082 goto fail2;
2083 }
2084 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2085
2086 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002087 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302088 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2089 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302090 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302091 iptype = 4;
2092 ra = (__u8 *)&raddr->sin_addr;
2093 } else {
2094 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2095 raddr6->sin6_addr.s6_addr,
2096 laddr6->sin6_port, raddr6->sin6_port, 0,
2097 raddr6->sin6_scope_id);
2098 iptype = 6;
2099 ra = (__u8 *)&raddr6->sin6_addr;
2100 }
2101 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002102 pr_err("%s - cannot find route.\n", __func__);
2103 err = -EHOSTUNREACH;
2104 goto fail3;
2105 }
Hariprasad S963cab52015-09-23 17:19:27 +05302106 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302107 ep->com.dev->rdev.lldi.adapter_type,
2108 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302109 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002110 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002111 goto fail4;
2112 }
2113
2114 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2115 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2116 ep->l2t->idx);
2117
2118 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302119 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002120
2121 /* send connect request to rnic */
2122 err = send_connect(ep);
2123 if (!err)
2124 goto out;
2125
2126 cxgb4_l2t_release(ep->l2t);
2127fail4:
2128 dst_release(ep->dst);
2129fail3:
2130 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2131 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2132fail2:
2133 /*
2134 * remember to send notification to upper layer.
2135 * We are in here so the upper layer is not aware that this is
2136 * re-connect attempt and so, upper layer is still waiting for
2137 * response of 1st connect request.
2138 */
2139 connect_reply_upcall(ep, -ECONNRESET);
2140 c4iw_put_ep(&ep->com);
2141out:
2142 return err;
2143}
2144
Steve Wisecfdda9d2010-04-21 15:30:06 -07002145static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2146{
2147 struct c4iw_ep *ep;
2148 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002149 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2150 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002151 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002152 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302153 struct sockaddr_in *la;
2154 struct sockaddr_in *ra;
2155 struct sockaddr_in6 *la6;
2156 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002157
2158 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002159 la = (struct sockaddr_in *)&ep->com.local_addr;
2160 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2161 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2162 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002163
2164 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2165 status, status2errno(status));
2166
Steve Wise7a2cea22014-03-14 21:52:07 +05302167 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302168 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2169 __func__, atid, status, neg_adv_str(status));
2170 ep->stats.connect_neg_adv++;
2171 mutex_lock(&dev->rdev.stats.lock);
2172 dev->rdev.stats.neg_adv++;
2173 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002174 return 0;
2175 }
2176
Vipul Pandya793dad92012-12-10 09:30:56 +00002177 set_bit(ACT_OPEN_RPL, &ep->com.history);
2178
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302179 /*
2180 * Log interesting failures.
2181 */
2182 switch (status) {
2183 case CPL_ERR_CONN_RESET:
2184 case CPL_ERR_CONN_TIMEDOUT:
2185 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002186 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302187 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002188 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302189 mutex_unlock(&dev->rdev.stats.lock);
2190 if (ep->com.local_addr.ss_family == AF_INET &&
2191 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002192 send_fw_act_open_req(ep,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002193 TID_TID_G(AOPEN_ATID_G(
Vipul Pandya793dad92012-12-10 09:30:56 +00002194 ntohl(rpl->atid_status))));
2195 return 0;
2196 }
2197 break;
2198 case CPL_ERR_CONN_EXIST:
2199 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2200 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302201 if (ep->com.remote_addr.ss_family == AF_INET6) {
2202 struct sockaddr_in6 *sin6 =
2203 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002204 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302205 cxgb4_clip_release(
2206 ep->com.dev->rdev.lldi.ports[0],
2207 (const u32 *)
2208 &sin6->sin6_addr.s6_addr, 1);
2209 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002210 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2211 atid);
2212 cxgb4_free_atid(t, atid);
2213 dst_release(ep->dst);
2214 cxgb4_l2t_release(ep->l2t);
2215 c4iw_reconnect(ep);
2216 return 0;
2217 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002218 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302219 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302220 if (ep->com.local_addr.ss_family == AF_INET) {
2221 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2222 atid, status, status2errno(status),
2223 &la->sin_addr.s_addr, ntohs(la->sin_port),
2224 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2225 } else {
2226 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2227 atid, status, status2errno(status),
2228 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2229 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2230 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302231 break;
2232 }
2233
Steve Wisecfdda9d2010-04-21 15:30:06 -07002234 connect_reply_upcall(ep, status2errno(status));
2235 state_set(&ep->com, DEAD);
2236
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302237 if (ep->com.remote_addr.ss_family == AF_INET6) {
2238 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002239 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302240 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2241 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2242 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002243 if (status && act_open_has_tid(status))
2244 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2245
Vipul Pandya793dad92012-12-10 09:30:56 +00002246 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002247 cxgb4_free_atid(t, atid);
2248 dst_release(ep->dst);
2249 cxgb4_l2t_release(ep->l2t);
2250 c4iw_put_ep(&ep->com);
2251
2252 return 0;
2253}
2254
2255static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2256{
2257 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2258 struct tid_info *t = dev->rdev.lldi.tids;
2259 unsigned int stid = GET_TID(rpl);
2260 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2261
2262 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002263 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2264 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002265 }
2266 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2267 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002268 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002269
Vipul Pandya1cab7752012-12-10 09:30:55 +00002270out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002271 return 0;
2272}
2273
Steve Wisecfdda9d2010-04-21 15:30:06 -07002274static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2275{
2276 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2277 struct tid_info *t = dev->rdev.lldi.tids;
2278 unsigned int stid = GET_TID(rpl);
2279 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2280
2281 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002282 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002283 return 0;
2284}
2285
Hariprasad S9dec9002016-05-05 01:27:29 +05302286static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2287 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002288{
2289 struct cpl_pass_accept_rpl *rpl;
2290 unsigned int mtu_idx;
2291 u64 opt0;
2292 u32 opt2;
2293 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302294 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302295 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302296 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002297
2298 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2299 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302300
Steve Wisecfdda9d2010-04-21 15:30:06 -07002301 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302302 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302303 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302304 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2305 rpl5 = (void *)rpl;
2306 INIT_TP_WR(rpl5, ep->hwtid);
2307 } else {
2308 skb_trim(skb, sizeof(*rpl));
2309 INIT_TP_WR(rpl, ep->hwtid);
2310 }
2311 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2312 ep->hwtid));
2313
2314 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302315 enable_tcp_timestamps && req->tcpopt.tstamp,
2316 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002317 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302318
2319 /*
2320 * Specify the largest window that will fit in opt0. The
2321 * remainder will be specified in the rx_data_ack.
2322 */
2323 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002324 if (win > RCV_BUFSIZ_M)
2325 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002326 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002327 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002328 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002329 WND_SCALE_V(wscale) |
2330 MSS_IDX_V(mtu_idx) |
2331 L2T_IDX_V(ep->l2t->idx) |
2332 TX_CHAN_V(ep->tx_chan) |
2333 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002334 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002335 ULP_MODE_V(ULP_MODE_TCPDDP) |
2336 RCV_BUFSIZ_V(win);
2337 opt2 = RX_CHANNEL_V(0) |
2338 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002339
2340 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002341 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002342 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002343 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002344 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002345 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002346 if (enable_ecn) {
2347 const struct tcphdr *tcph;
2348 u32 hlen = ntohl(req->hdr_len);
2349
Hariprasad S963cab52015-09-23 17:19:27 +05302350 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2351 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2352 IP_HDR_LEN_G(hlen);
2353 else
2354 tcph = (const void *)(req + 1) +
2355 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002356 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002357 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002358 }
Hariprasad S963cab52015-09-23 17:19:27 +05302359 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302360 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002361 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302362 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302363 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302364 rpl5 = (void *)rpl;
2365 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2366 if (peer2peer)
2367 isn += 4;
2368 rpl5->iss = cpu_to_be32(isn);
2369 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002370 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002371
Steve Wisecfdda9d2010-04-21 15:30:06 -07002372 rpl->opt0 = cpu_to_be64(opt0);
2373 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002374 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302375 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002376
Hariprasad S9dec9002016-05-05 01:27:29 +05302377 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002378}
2379
Vipul Pandya830662f2013-07-04 16:10:47 +05302380static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002381{
Vipul Pandya830662f2013-07-04 16:10:47 +05302382 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002383 BUG_ON(skb_cloned(skb));
2384 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002385 release_tid(&dev->rdev, hwtid, skb);
2386 return;
2387}
2388
Hariprasad S963cab52015-09-23 17:19:27 +05302389static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2390 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002391 __be16 *local_port, __be16 *peer_port)
2392{
Hariprasad S963cab52015-09-23 17:19:27 +05302393 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2394 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2395 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2396 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2397 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2398 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002399 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302400 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002401 struct tcphdr *tcp = (struct tcphdr *)
2402 ((u8 *)(req + 1) + eth_len + ip_len);
2403
Vipul Pandya830662f2013-07-04 16:10:47 +05302404 if (ip->version == 4) {
2405 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2406 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2407 ntohs(tcp->dest));
2408 *iptype = 4;
2409 memcpy(peer_ip, &ip->saddr, 4);
2410 memcpy(local_ip, &ip->daddr, 4);
2411 } else {
2412 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2413 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2414 ntohs(tcp->dest));
2415 *iptype = 6;
2416 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2417 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2418 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002419 *peer_port = tcp->source;
2420 *local_port = tcp->dest;
2421
2422 return;
2423}
2424
2425static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2426{
Vipul Pandya793dad92012-12-10 09:30:56 +00002427 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002428 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002429 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002430 struct tid_info *t = dev->rdev.lldi.tids;
2431 unsigned int hwtid = GET_TID(req);
2432 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302433 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002434 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302435 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002436 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002437 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302438 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302439 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302440 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002441
2442 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002443 if (!parent_ep) {
2444 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2445 goto reject;
2446 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002447
Steve Wisecfdda9d2010-04-21 15:30:06 -07002448 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302449 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002450 goto reject;
2451 }
2452
Hariprasad S963cab52015-09-23 17:19:27 +05302453 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2454 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302455
Steve Wisecfdda9d2010-04-21 15:30:06 -07002456 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302457 if (iptype == 4) {
2458 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 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_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2463 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302464 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302465 } else {
2466 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2467 , __func__, parent_ep, hwtid,
2468 local_ip, peer_ip, ntohs(local_port),
2469 ntohs(peer_port), peer_mss);
2470 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002471 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302472 ((struct sockaddr_in6 *)
2473 &parent_ep->com.local_addr)->sin6_scope_id);
2474 }
2475 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002476 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2477 __func__);
2478 goto reject;
2479 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002480
2481 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2482 if (!child_ep) {
2483 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2484 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002485 dst_release(dst);
2486 goto reject;
2487 }
David Miller3786cf12011-12-02 16:52:31 +00002488
Hariprasad S963cab52015-09-23 17:19:27 +05302489 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302490 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002491 if (err) {
2492 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2493 __func__);
2494 dst_release(dst);
2495 kfree(child_ep);
2496 goto reject;
2497 }
2498
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302499 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2500 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2501 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2502 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002503
Steve Wisecfdda9d2010-04-21 15:30:06 -07002504 state_set(&child_ep->com, CONNECTING);
2505 child_ep->com.dev = dev;
2506 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002507
Vipul Pandya830662f2013-07-04 16:10:47 +05302508 if (iptype == 4) {
2509 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002510 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002511
Vipul Pandya830662f2013-07-04 16:10:47 +05302512 sin->sin_family = PF_INET;
2513 sin->sin_port = local_port;
2514 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002515
2516 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2517 sin->sin_family = PF_INET;
2518 sin->sin_port = ((struct sockaddr_in *)
2519 &parent_ep->com.local_addr)->sin_port;
2520 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2521
Steve Wise170003c2016-02-26 09:18:03 -06002522 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302523 sin->sin_family = PF_INET;
2524 sin->sin_port = peer_port;
2525 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2526 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002527 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302528 sin6->sin6_family = PF_INET6;
2529 sin6->sin6_port = local_port;
2530 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002531
2532 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2533 sin6->sin6_family = PF_INET6;
2534 sin6->sin6_port = ((struct sockaddr_in6 *)
2535 &parent_ep->com.local_addr)->sin6_port;
2536 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2537
Steve Wise170003c2016-02-26 09:18:03 -06002538 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302539 sin6->sin6_family = PF_INET6;
2540 sin6->sin6_port = peer_port;
2541 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2542 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002543
Steve Wisecfdda9d2010-04-21 15:30:06 -07002544 c4iw_get_ep(&parent_ep->com);
2545 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302546 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002547 child_ep->dst = dst;
2548 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002549
2550 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002551 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002552
2553 init_timer(&child_ep->timer);
2554 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002555 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Hariprasad S9dec9002016-05-05 01:27:29 +05302556 if (accept_cr(child_ep, skb, req)) {
2557 c4iw_put_ep(&parent_ep->com);
2558 release_ep_resources(child_ep);
2559 } else {
2560 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2561 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302562 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002563 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302564 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2565 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2566 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002567 goto out;
2568reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302569 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002570out:
2571 return 0;
2572}
2573
2574static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2575{
2576 struct c4iw_ep *ep;
2577 struct cpl_pass_establish *req = cplhdr(skb);
2578 struct tid_info *t = dev->rdev.lldi.tids;
2579 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302580 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002581
2582 ep = lookup_tid(t, tid);
2583 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2584 ep->snd_seq = be32_to_cpu(req->snd_isn);
2585 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2586
Vipul Pandya1cab7752012-12-10 09:30:55 +00002587 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2588 ntohs(req->tcp_opt));
2589
Steve Wisecfdda9d2010-04-21 15:30:06 -07002590 set_emss(ep, ntohs(req->tcp_opt));
2591
2592 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302593 mutex_lock(&ep->com.mutex);
2594 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002595 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002596 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad Sfef44222016-05-05 01:27:33 +05302597 ret = send_flowc(ep, skb);
2598 mutex_unlock(&ep->com.mutex);
2599 if (ret)
2600 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002601
2602 return 0;
2603}
2604
2605static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2606{
2607 struct cpl_peer_close *hdr = cplhdr(skb);
2608 struct c4iw_ep *ep;
2609 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002610 int disconnect = 1;
2611 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002612 struct tid_info *t = dev->rdev.lldi.tids;
2613 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002614 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002615
2616 ep = lookup_tid(t, tid);
2617 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2618 dst_confirm(ep->dst);
2619
Vipul Pandya793dad92012-12-10 09:30:56 +00002620 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002621 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002622 switch (ep->com.state) {
2623 case MPA_REQ_WAIT:
2624 __state_set(&ep->com, CLOSING);
2625 break;
2626 case MPA_REQ_SENT:
2627 __state_set(&ep->com, CLOSING);
2628 connect_reply_upcall(ep, -ECONNRESET);
2629 break;
2630 case MPA_REQ_RCVD:
2631
2632 /*
2633 * We're gonna mark this puppy DEAD, but keep
2634 * the reference on it until the ULP accepts or
2635 * rejects the CR. Also wake up anyone waiting
2636 * in rdma connection migration (see c4iw_accept_cr()).
2637 */
2638 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002639 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002640 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002641 break;
2642 case MPA_REP_SENT:
2643 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002644 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002645 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002646 break;
2647 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002648 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002649 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002650 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002651 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002652 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002653 if (ret != -ECONNRESET) {
2654 peer_close_upcall(ep);
2655 disconnect = 1;
2656 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002657 break;
2658 case ABORTING:
2659 disconnect = 0;
2660 break;
2661 case CLOSING:
2662 __state_set(&ep->com, MORIBUND);
2663 disconnect = 0;
2664 break;
2665 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002666 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002667 if (ep->com.cm_id && ep->com.qp) {
2668 attrs.next_state = C4IW_QP_STATE_IDLE;
2669 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2670 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2671 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302672 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002673 __state_set(&ep->com, DEAD);
2674 release = 1;
2675 disconnect = 0;
2676 break;
2677 case DEAD:
2678 disconnect = 0;
2679 break;
2680 default:
2681 BUG_ON(1);
2682 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002683 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002684 if (disconnect)
2685 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2686 if (release)
2687 release_ep_resources(ep);
2688 return 0;
2689}
2690
Steve Wisecfdda9d2010-04-21 15:30:06 -07002691static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2692{
2693 struct cpl_abort_req_rss *req = cplhdr(skb);
2694 struct c4iw_ep *ep;
2695 struct cpl_abort_rpl *rpl;
2696 struct sk_buff *rpl_skb;
2697 struct c4iw_qp_attributes attrs;
2698 int ret;
2699 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002700 struct tid_info *t = dev->rdev.lldi.tids;
2701 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002702
2703 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302704 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302705 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2706 __func__, ep->hwtid, req->status,
2707 neg_adv_str(req->status));
2708 ep->stats.abort_neg_adv++;
2709 mutex_lock(&dev->rdev.stats.lock);
2710 dev->rdev.stats.neg_adv++;
2711 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002712 return 0;
2713 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002714 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2715 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002716 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002717
2718 /*
2719 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302720 * However, this is not needed if com state is just
2721 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002722 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302723 if (ep->com.state != MPA_REQ_SENT)
2724 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002725
2726 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002727 switch (ep->com.state) {
2728 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302729 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002730 break;
2731 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002732 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002733 break;
2734 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002735 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002736 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302737 connect_reply_upcall(ep, -ECONNRESET);
2738 else {
2739 /*
2740 * we just don't send notification upwards because we
2741 * want to retry with mpa_v1 without upper layers even
2742 * knowing it.
2743 *
2744 * do some housekeeping so as to re-initiate the
2745 * connection
2746 */
2747 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2748 mpa_rev);
2749 ep->retry_with_mpa_v1 = 1;
2750 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002751 break;
2752 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002753 break;
2754 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002755 break;
2756 case MORIBUND:
2757 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002758 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002759 /*FALLTHROUGH*/
2760 case FPDU_MODE:
2761 if (ep->com.cm_id && ep->com.qp) {
2762 attrs.next_state = C4IW_QP_STATE_ERROR;
2763 ret = c4iw_modify_qp(ep->com.qp->rhp,
2764 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2765 &attrs, 1);
2766 if (ret)
2767 printk(KERN_ERR MOD
2768 "%s - qp <- error failed!\n",
2769 __func__);
2770 }
2771 peer_abort_upcall(ep);
2772 break;
2773 case ABORTING:
2774 break;
2775 case DEAD:
2776 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002777 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002778 return 0;
2779 default:
2780 BUG_ON(1);
2781 break;
2782 }
2783 dst_confirm(ep->dst);
2784 if (ep->com.state != ABORTING) {
2785 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302786 /* we don't release if we want to retry with mpa_v1 */
2787 if (!ep->retry_with_mpa_v1)
2788 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002789 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002790 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002791
2792 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2793 if (!rpl_skb) {
2794 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2795 __func__);
2796 release = 1;
2797 goto out;
2798 }
2799 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2800 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2801 INIT_TP_WR(rpl, ep->hwtid);
2802 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2803 rpl->cmd = CPL_ABORT_NO_RST;
2804 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2805out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002806 if (release)
2807 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002808 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302809 if (ep->com.remote_addr.ss_family == AF_INET6) {
2810 struct sockaddr_in6 *sin6 =
2811 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002812 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302813 cxgb4_clip_release(
2814 ep->com.dev->rdev.lldi.ports[0],
2815 (const u32 *)&sin6->sin6_addr.s6_addr,
2816 1);
2817 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002818 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302819 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2820 dst_release(ep->dst);
2821 cxgb4_l2t_release(ep->l2t);
2822 c4iw_reconnect(ep);
2823 }
2824
Steve Wisecfdda9d2010-04-21 15:30:06 -07002825 return 0;
2826}
2827
2828static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2829{
2830 struct c4iw_ep *ep;
2831 struct c4iw_qp_attributes attrs;
2832 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002833 int release = 0;
2834 struct tid_info *t = dev->rdev.lldi.tids;
2835 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002836
2837 ep = lookup_tid(t, tid);
2838
2839 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2840 BUG_ON(!ep);
2841
2842 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002843 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302844 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002845 switch (ep->com.state) {
2846 case CLOSING:
2847 __state_set(&ep->com, MORIBUND);
2848 break;
2849 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002850 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002851 if ((ep->com.cm_id) && (ep->com.qp)) {
2852 attrs.next_state = C4IW_QP_STATE_IDLE;
2853 c4iw_modify_qp(ep->com.qp->rhp,
2854 ep->com.qp,
2855 C4IW_QP_ATTR_NEXT_STATE,
2856 &attrs, 1);
2857 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302858 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002859 __state_set(&ep->com, DEAD);
2860 release = 1;
2861 break;
2862 case ABORTING:
2863 case DEAD:
2864 break;
2865 default:
2866 BUG_ON(1);
2867 break;
2868 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002869 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002870 if (release)
2871 release_ep_resources(ep);
2872 return 0;
2873}
2874
2875static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2876{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002877 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002878 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002879 unsigned int tid = GET_TID(rpl);
2880 struct c4iw_ep *ep;
2881 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002882
2883 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002884 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002885
Steve Wise30c95c22011-05-09 22:06:22 -07002886 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002887 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2888 ep->com.qp->wq.sq.qid);
2889 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2890 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2891 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2892 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002893 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002894
Steve Wisecfdda9d2010-04-21 15:30:06 -07002895 return 0;
2896}
2897
2898/*
2899 * Upcall from the adapter indicating data has been transmitted.
2900 * For us its just the single MPA request or reply. We can now free
2901 * the skb holding the mpa message.
2902 */
2903static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2904{
2905 struct c4iw_ep *ep;
2906 struct cpl_fw4_ack *hdr = cplhdr(skb);
2907 u8 credits = hdr->credits;
2908 unsigned int tid = GET_TID(hdr);
2909 struct tid_info *t = dev->rdev.lldi.tids;
2910
2911
2912 ep = lookup_tid(t, tid);
2913 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2914 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002915 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2916 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002917 return 0;
2918 }
2919
2920 dst_confirm(ep->dst);
2921 if (ep->mpa_skb) {
2922 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2923 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2924 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2925 kfree_skb(ep->mpa_skb);
2926 ep->mpa_skb = NULL;
2927 }
2928 return 0;
2929}
2930
Steve Wisecfdda9d2010-04-21 15:30:06 -07002931int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2932{
Steve Wisea7db89e2014-03-21 20:40:35 +05302933 int err = 0;
2934 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002935 struct c4iw_ep *ep = to_ep(cm_id);
2936 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2937
Steve Wisea7db89e2014-03-21 20:40:35 +05302938 mutex_lock(&ep->com.mutex);
2939 if (ep->com.state == DEAD) {
2940 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002941 c4iw_put_ep(&ep->com);
2942 return -ECONNRESET;
2943 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002944 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302945 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002946 if (mpa_rev == 0)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302947 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002948 else {
2949 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302950 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002951 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302952 mutex_unlock(&ep->com.mutex);
2953 if (disconnect)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302954 err = c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002955 c4iw_put_ep(&ep->com);
2956 return 0;
2957}
2958
2959int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2960{
2961 int err;
2962 struct c4iw_qp_attributes attrs;
2963 enum c4iw_qp_attr_mask mask;
2964 struct c4iw_ep *ep = to_ep(cm_id);
2965 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2966 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302967 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002968
2969 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302970
2971 mutex_lock(&ep->com.mutex);
2972 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002973 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302974 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002975 }
2976
Steve Wisea7db89e2014-03-21 20:40:35 +05302977 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002978 BUG_ON(!qp);
2979
Vipul Pandya793dad92012-12-10 09:30:56 +00002980 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302981 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2982 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002983 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302984 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002985 }
2986
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302987 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2988 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302989 if (RELAXED_IRD_NEGOTIATION) {
2990 ep->ord = ep->ird;
2991 } else {
2992 ep->ird = conn_param->ird;
2993 ep->ord = conn_param->ord;
2994 send_mpa_reject(ep, conn_param->private_data,
2995 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302996 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302997 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302998 }
2999 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303000 if (conn_param->ird < ep->ord) {
3001 if (RELAXED_IRD_NEGOTIATION &&
3002 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3003 conn_param->ird = ep->ord;
3004 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303005 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303006 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303007 }
3008 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303009 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003010 ep->ird = conn_param->ird;
3011 ep->ord = conn_param->ord;
3012
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303013 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303014 if (peer2peer && ep->ird == 0)
3015 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303016 } else {
3017 if (peer2peer &&
3018 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303019 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303020 ep->ird = 1;
3021 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003022
3023 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3024
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303025 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303026 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303027 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003028 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303029
Steve Wisecfdda9d2010-04-21 15:30:06 -07003030 /* bind QP to EP and move to RTS */
3031 attrs.mpa_attr = ep->mpa_attr;
3032 attrs.max_ird = ep->ird;
3033 attrs.max_ord = ep->ord;
3034 attrs.llp_stream_handle = ep;
3035 attrs.next_state = C4IW_QP_STATE_RTS;
3036
3037 /* bind QP and TID with INIT_WR */
3038 mask = C4IW_QP_ATTR_NEXT_STATE |
3039 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3040 C4IW_QP_ATTR_MPA_ATTR |
3041 C4IW_QP_ATTR_MAX_IRD |
3042 C4IW_QP_ATTR_MAX_ORD;
3043
3044 err = c4iw_modify_qp(ep->com.qp->rhp,
3045 ep->com.qp, mask, &attrs, 1);
3046 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303047 goto err_deref_cm_id;
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:
3969 __state_set(&ep->com, ABORTING);
3970 break;
3971 case CLOSING:
3972 case MORIBUND:
3973 if (ep->com.cm_id && ep->com.qp) {
3974 attrs.next_state = C4IW_QP_STATE_ERROR;
3975 c4iw_modify_qp(ep->com.qp->rhp,
3976 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3977 &attrs, 1);
3978 }
3979 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303980 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003981 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003982 case ABORTING:
3983 case DEAD:
3984
3985 /*
3986 * These states are expected if the ep timed out at the same
3987 * time as another thread was calling stop_ep_timer().
3988 * So we silently do nothing for these states.
3989 */
3990 abort = 0;
3991 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003992 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003993 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003994 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003995 abort = 0;
3996 }
Steve Wisecc18b932014-04-24 14:31:53 -05003997 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05303998 if (abort)
3999 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004000 c4iw_put_ep(&ep->com);
4001}
4002
4003static void process_timedout_eps(void)
4004{
4005 struct c4iw_ep *ep;
4006
4007 spin_lock_irq(&timeout_lock);
4008 while (!list_empty(&timeout_list)) {
4009 struct list_head *tmp;
4010
4011 tmp = timeout_list.next;
4012 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004013 tmp->next = NULL;
4014 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004015 spin_unlock_irq(&timeout_lock);
4016 ep = list_entry(tmp, struct c4iw_ep, entry);
4017 process_timeout(ep);
4018 spin_lock_irq(&timeout_lock);
4019 }
4020 spin_unlock_irq(&timeout_lock);
4021}
4022
4023static void process_work(struct work_struct *work)
4024{
4025 struct sk_buff *skb = NULL;
4026 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004027 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004028 unsigned int opcode;
4029 int ret;
4030
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004031 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004032 while ((skb = skb_dequeue(&rxq))) {
4033 rpl = cplhdr(skb);
4034 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4035 opcode = rpl->ot.opcode;
4036
4037 BUG_ON(!work_handlers[opcode]);
4038 ret = work_handlers[opcode](dev, skb);
4039 if (!ret)
4040 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004041 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004042 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004043}
4044
4045static DECLARE_WORK(skb_work, process_work);
4046
4047static void ep_timeout(unsigned long arg)
4048{
4049 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004050 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004051
4052 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004053 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004054 /*
4055 * Only insert if it is not already on the list.
4056 */
4057 if (!ep->entry.next) {
4058 list_add_tail(&ep->entry, &timeout_list);
4059 kickit = 1;
4060 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004061 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004062 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004063 if (kickit)
4064 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004065}
4066
4067/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004068 * All the CM events are handled on a work queue to have a safe context.
4069 */
4070static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4071{
4072
4073 /*
4074 * Save dev in the skb->cb area.
4075 */
4076 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4077
4078 /*
4079 * Queue the skb and schedule the worker thread.
4080 */
4081 skb_queue_tail(&rxq, skb);
4082 queue_work(workq, &skb_work);
4083 return 0;
4084}
4085
4086static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4087{
4088 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4089
4090 if (rpl->status != CPL_ERR_NONE) {
4091 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4092 "for tid %u\n", rpl->status, GET_TID(rpl));
4093 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004094 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004095 return 0;
4096}
4097
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004098static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4099{
4100 struct cpl_fw6_msg *rpl = cplhdr(skb);
4101 struct c4iw_wr_wait *wr_waitp;
4102 int ret;
4103
4104 PDBG("%s type %u\n", __func__, rpl->type);
4105
4106 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004107 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004108 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004109 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004110 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004111 if (wr_waitp)
4112 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004113 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004114 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004115 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004116 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004117 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004118 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004119 default:
4120 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4121 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004122 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004123 break;
4124 }
4125 return 0;
4126}
4127
Steve Wise8da7e7a2011-06-14 20:59:27 +00004128static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4129{
4130 struct cpl_abort_req_rss *req = cplhdr(skb);
4131 struct c4iw_ep *ep;
4132 struct tid_info *t = dev->rdev.lldi.tids;
4133 unsigned int tid = GET_TID(req);
4134
4135 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05004136 if (!ep) {
4137 printk(KERN_WARNING MOD
4138 "Abort on non-existent endpoint, tid %d\n", tid);
4139 kfree_skb(skb);
4140 return 0;
4141 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304142 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304143 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4144 __func__, ep->hwtid, req->status,
4145 neg_adv_str(req->status));
4146 ep->stats.abort_neg_adv++;
4147 dev->rdev.stats.neg_adv++;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004148 kfree_skb(skb);
4149 return 0;
4150 }
4151 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4152 ep->com.state);
4153
4154 /*
4155 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004156 * However, if we are on MPAv2 and want to retry with MPAv1
4157 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004158 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004159 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4160 if (ep->com.state != MPA_REQ_SENT)
4161 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4162 } else
4163 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00004164 sched(dev, skb);
4165 return 0;
4166}
4167
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004168/*
4169 * Most upcalls from the T4 Core go to sched() to
4170 * schedule the processing on a work queue.
4171 */
4172c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4173 [CPL_ACT_ESTABLISH] = sched,
4174 [CPL_ACT_OPEN_RPL] = sched,
4175 [CPL_RX_DATA] = sched,
4176 [CPL_ABORT_RPL_RSS] = sched,
4177 [CPL_ABORT_RPL] = sched,
4178 [CPL_PASS_OPEN_RPL] = sched,
4179 [CPL_CLOSE_LISTSRV_RPL] = sched,
4180 [CPL_PASS_ACCEPT_REQ] = sched,
4181 [CPL_PASS_ESTABLISH] = sched,
4182 [CPL_PEER_CLOSE] = sched,
4183 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004184 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004185 [CPL_RDMA_TERMINATE] = sched,
4186 [CPL_FW4_ACK] = sched,
4187 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004188 [CPL_FW6_MSG] = fw6_msg,
4189 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004190};
4191
Steve Wisecfdda9d2010-04-21 15:30:06 -07004192int __init c4iw_cm_init(void)
4193{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004194 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004195 skb_queue_head_init(&rxq);
4196
4197 workq = create_singlethread_workqueue("iw_cxgb4");
4198 if (!workq)
4199 return -ENOMEM;
4200
Steve Wisecfdda9d2010-04-21 15:30:06 -07004201 return 0;
4202}
4203
Steve Wise46c13762014-06-20 14:26:25 -05004204void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004205{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004206 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004207 flush_workqueue(workq);
4208 destroy_workqueue(workq);
4209}