blob: c7b3d5751963978705cd8f33e927c64b8e456eea [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 Wisecfdda9d2010-04-21 15:30:06 -07001399 * If we get more than the supported amount of private data
1400 * then we must fail this connection.
1401 */
1402 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1403 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301404 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001405 }
1406
1407 /*
1408 * copy the new data into our accumulation buffer.
1409 */
1410 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1411 skb->len);
1412 ep->mpa_pkt_len += skb->len;
1413
1414 /*
1415 * if we don't even have the mpa message, then bail.
1416 */
1417 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001418 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001419 mpa = (struct mpa_message *) ep->mpa_pkt;
1420
1421 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301422 if (mpa->revision > mpa_rev) {
1423 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1424 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001425 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301426 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001427 }
1428 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1429 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301430 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001431 }
1432
1433 plen = ntohs(mpa->private_data_size);
1434
1435 /*
1436 * Fail if there's too much private data.
1437 */
1438 if (plen > MPA_MAX_PRIVATE_DATA) {
1439 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301440 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001441 }
1442
1443 /*
1444 * If plen does not account for pkt size
1445 */
1446 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1447 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301448 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001449 }
1450
1451 ep->plen = (u8) plen;
1452
1453 /*
1454 * If we don't have all the pdata yet, then bail.
1455 * We'll continue process when more data arrives.
1456 */
1457 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001458 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001459
1460 if (mpa->flags & MPA_REJECT) {
1461 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301462 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001463 }
1464
1465 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301466 * Stop mpa timer. If it expired, then
1467 * we ignore the MPA reply. process_timeout()
1468 * will abort the connection.
1469 */
1470 if (stop_ep_timer(ep))
1471 return 0;
1472
1473 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001474 * 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;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301612err_stop_timer:
1613 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001614err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301615 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001616out:
1617 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001618 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001619}
1620
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301621/*
1622 * process_mpa_request - process streaming mode MPA request
1623 *
1624 * Returns:
1625 *
1626 * 0 upon success indicating a connect request was delivered to the ULP
1627 * or the mpa request is incomplete but valid so far.
1628 *
1629 * 1 if a failure requires the caller to close the connection.
1630 *
1631 * 2 if a failure requires the caller to abort the connection.
1632 */
1633static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001634{
1635 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301636 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001637 u16 plen;
1638
1639 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1640
Steve Wisecfdda9d2010-04-21 15:30:06 -07001641 /*
1642 * If we get more than the supported amount of private data
1643 * then we must fail this connection.
1644 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301645 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1646 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001647
1648 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1649
1650 /*
1651 * Copy the new data into our accumulation buffer.
1652 */
1653 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1654 skb->len);
1655 ep->mpa_pkt_len += skb->len;
1656
1657 /*
1658 * If we don't even have the mpa message, then bail.
1659 * We'll continue process when more data arrives.
1660 */
1661 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301662 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001663
1664 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001665 mpa = (struct mpa_message *) ep->mpa_pkt;
1666
1667 /*
1668 * Validate MPA Header.
1669 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301670 if (mpa->revision > mpa_rev) {
1671 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1672 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301673 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001674 }
1675
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301676 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1677 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001678
1679 plen = ntohs(mpa->private_data_size);
1680
1681 /*
1682 * Fail if there's too much private data.
1683 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301684 if (plen > MPA_MAX_PRIVATE_DATA)
1685 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001686
1687 /*
1688 * If plen does not account for pkt size
1689 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301690 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1691 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001692 ep->plen = (u8) plen;
1693
1694 /*
1695 * If we don't have all the pdata yet, then bail.
1696 */
1697 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301698 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001699
1700 /*
1701 * If we get here we have accumulated the entire mpa
1702 * start reply message including private data.
1703 */
1704 ep->mpa_attr.initiator = 0;
1705 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1706 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1707 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301708 ep->mpa_attr.version = mpa->revision;
1709 if (mpa->revision == 1)
1710 ep->tried_with_mpa_v1 = 1;
1711 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1712
1713 if (mpa->revision == 2) {
1714 ep->mpa_attr.enhanced_rdma_conn =
1715 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1716 if (ep->mpa_attr.enhanced_rdma_conn) {
1717 mpa_v2_params = (struct mpa_v2_conn_params *)
1718 (ep->mpa_pkt + sizeof(*mpa));
1719 ep->ird = ntohs(mpa_v2_params->ird) &
1720 MPA_V2_IRD_ORD_MASK;
1721 ep->ord = ntohs(mpa_v2_params->ord) &
1722 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301723 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1724 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301725 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1726 if (peer2peer) {
1727 if (ntohs(mpa_v2_params->ord) &
1728 MPA_V2_RDMA_WRITE_RTR)
1729 ep->mpa_attr.p2p_type =
1730 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1731 else if (ntohs(mpa_v2_params->ord) &
1732 MPA_V2_RDMA_READ_RTR)
1733 ep->mpa_attr.p2p_type =
1734 FW_RI_INIT_P2PTYPE_READ_REQ;
1735 }
1736 }
1737 } else if (mpa->revision == 1)
1738 if (peer2peer)
1739 ep->mpa_attr.p2p_type = p2p_type;
1740
Steve Wisecfdda9d2010-04-21 15:30:06 -07001741 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1742 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1743 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1744 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1745 ep->mpa_attr.p2p_type);
1746
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001747 /*
1748 * If the endpoint timer already expired, then we ignore
1749 * the start request. process_timeout() will abort
1750 * the connection.
1751 */
1752 if (!stop_ep_timer(ep)) {
1753 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001754
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001755 /* drive upcall */
Hariprasad Shenai10be6b42014-11-21 09:36:35 -06001756 mutex_lock_nested(&ep->parent_ep->com.mutex,
1757 SINGLE_DEPTH_NESTING);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001758 if (ep->parent_ep->com.state != DEAD) {
1759 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301760 goto err_unlock_parent;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001761 } else {
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301762 goto err_unlock_parent;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001763 }
1764 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301765 }
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301766 return 0;
1767
1768err_unlock_parent:
1769 mutex_unlock(&ep->parent_ep->com.mutex);
1770 goto err_out;
1771err_stop_timer:
1772 (void)stop_ep_timer(ep);
1773err_out:
1774 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001775}
1776
1777static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1778{
1779 struct c4iw_ep *ep;
1780 struct cpl_rx_data *hdr = cplhdr(skb);
1781 unsigned int dlen = ntohs(hdr->len);
1782 unsigned int tid = GET_TID(hdr);
1783 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001784 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001785 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001786
1787 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301788 if (!ep)
1789 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001790 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1791 skb_pull(skb, sizeof(*hdr));
1792 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301793 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001794
Steve Wisecfdda9d2010-04-21 15:30:06 -07001795 /* update RX credits */
1796 update_rx_credits(ep, dlen);
1797
Steve Wisec529fb52014-03-21 20:40:37 +05301798 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001799 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001800 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001801 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001802 break;
1803 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001804 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001805 process_mpa_request(ep, skb);
1806 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001807 case FPDU_MODE: {
1808 struct c4iw_qp_attributes attrs;
1809 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001810 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001811 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001812 " qpid %u ep %p state %d tid %u status %d\n",
1813 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301814 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301815 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001816 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001817 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1818 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001819 break;
1820 }
Vipul Pandya15579672013-01-07 13:11:52 +00001821 default:
1822 break;
1823 }
Steve Wisec529fb52014-03-21 20:40:37 +05301824 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001825 if (disconnect)
1826 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001827 return 0;
1828}
1829
1830static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1831{
1832 struct c4iw_ep *ep;
1833 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001834 int release = 0;
1835 unsigned int tid = GET_TID(rpl);
1836 struct tid_info *t = dev->rdev.lldi.tids;
1837
1838 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301839 if (!ep) {
1840 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1841 return 0;
1842 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001843 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001844 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001845 switch (ep->com.state) {
1846 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001847 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001848 __state_set(&ep->com, DEAD);
1849 release = 1;
1850 break;
1851 default:
1852 printk(KERN_ERR "%s ep %p state %d\n",
1853 __func__, ep, ep->com.state);
1854 break;
1855 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001856 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001857
1858 if (release)
1859 release_ep_resources(ep);
1860 return 0;
1861}
1862
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001863static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1864{
1865 struct sk_buff *skb;
1866 struct fw_ofld_connection_wr *req;
1867 unsigned int mtu_idx;
1868 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301869 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301870 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001871
1872 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1873 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1874 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001875 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301876 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301877 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1878 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001879 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001880 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301881 req->le.lport = sin->sin_port;
1882 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001883 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301884 req->le.pport = sin->sin_port;
1885 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001886 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301887 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1888 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001889 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301890 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001891 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001892 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301893 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301894 enable_tcp_timestamps,
1895 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001896 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301897
1898 /*
1899 * Specify the largest window that will fit in opt0. The
1900 * remainder will be specified in the rx_data_ack.
1901 */
1902 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001903 if (win > RCV_BUFSIZ_M)
1904 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301905
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001906 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1907 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001908 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001909 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001910 WND_SCALE_V(wscale) |
1911 MSS_IDX_V(mtu_idx) |
1912 L2T_IDX_V(ep->l2t->idx) |
1913 TX_CHAN_V(ep->tx_chan) |
1914 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301915 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001916 ULP_MODE_V(ULP_MODE_TCPDDP) |
1917 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001918 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1919 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001920 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001921 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001922 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001923 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001924 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001925 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001926 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001927 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001928 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1929 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1930 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001931 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1932 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001933 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1934}
1935
Steve Wisecfdda9d2010-04-21 15:30:06 -07001936/*
1937 * Return whether a failed active open has allocated a TID
1938 */
1939static inline int act_open_has_tid(int status)
1940{
1941 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1942 status != CPL_ERR_ARP_MISS;
1943}
1944
Steve Wise7a2cea22014-03-14 21:52:07 +05301945/* Returns whether a CPL status conveys negative advice.
1946 */
1947static int is_neg_adv(unsigned int status)
1948{
1949 return status == CPL_ERR_RTX_NEG_ADVICE ||
1950 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1951 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1952}
1953
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301954static char *neg_adv_str(unsigned int status)
1955{
1956 switch (status) {
1957 case CPL_ERR_RTX_NEG_ADVICE:
1958 return "Retransmit timeout";
1959 case CPL_ERR_PERSIST_NEG_ADVICE:
1960 return "Persist timeout";
1961 case CPL_ERR_KEEPALV_NEG_ADVICE:
1962 return "Keepalive timeout";
1963 default:
1964 return "Unknown";
1965 }
1966}
1967
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301968static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1969{
1970 ep->snd_win = snd_win;
1971 ep->rcv_win = rcv_win;
1972 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1973}
1974
Vipul Pandya793dad92012-12-10 09:30:56 +00001975#define ACT_OPEN_RETRY_COUNT 2
1976
Vipul Pandya830662f2013-07-04 16:10:47 +05301977static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1978 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301979 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05301980{
1981 struct neighbour *n;
1982 int err, step;
1983 struct net_device *pdev;
1984
1985 n = dst_neigh_lookup(dst, peer_ip);
1986 if (!n)
1987 return -ENODEV;
1988
1989 rcu_read_lock();
1990 err = -ENOMEM;
1991 if (n->dev->flags & IFF_LOOPBACK) {
1992 if (iptype == 4)
1993 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1994 else if (IS_ENABLED(CONFIG_IPV6))
1995 for_each_netdev(&init_net, pdev) {
1996 if (ipv6_chk_addr(&init_net,
1997 (struct in6_addr *)peer_ip,
1998 pdev, 1))
1999 break;
2000 }
2001 else
2002 pdev = NULL;
2003
2004 if (!pdev) {
2005 err = -ENODEV;
2006 goto out;
2007 }
2008 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302009 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05302010 if (!ep->l2t)
2011 goto out;
2012 ep->mtu = pdev->mtu;
2013 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302014 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2015 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302016 step = cdev->rdev.lldi.ntxq /
2017 cdev->rdev.lldi.nchan;
2018 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2019 step = cdev->rdev.lldi.nrxq /
2020 cdev->rdev.lldi.nchan;
2021 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2022 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2023 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302024 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302025 dev_put(pdev);
2026 } else {
2027 pdev = get_real_dev(n->dev);
2028 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2029 n, pdev, 0);
2030 if (!ep->l2t)
2031 goto out;
2032 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002033 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302034 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2035 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302036 step = cdev->rdev.lldi.ntxq /
2037 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002038 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2039 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302040 step = cdev->rdev.lldi.nrxq /
2041 cdev->rdev.lldi.nchan;
2042 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002043 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302044 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302045
2046 if (clear_mpa_v1) {
2047 ep->retry_with_mpa_v1 = 0;
2048 ep->tried_with_mpa_v1 = 0;
2049 }
2050 }
2051 err = 0;
2052out:
2053 rcu_read_unlock();
2054
2055 neigh_release(n);
2056
2057 return err;
2058}
2059
Vipul Pandya793dad92012-12-10 09:30:56 +00002060static int c4iw_reconnect(struct c4iw_ep *ep)
2061{
2062 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302063 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002064 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302065 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002066 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302067 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002068 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302069 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002070 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302071 int iptype;
2072 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002073
2074 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2075 init_timer(&ep->timer);
2076
2077 /*
2078 * Allocate an active TID to initiate a TCP connection.
2079 */
2080 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2081 if (ep->atid == -1) {
2082 pr_err("%s - cannot alloc atid.\n", __func__);
2083 err = -ENOMEM;
2084 goto fail2;
2085 }
2086 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2087
2088 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002089 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302090 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2091 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302092 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302093 iptype = 4;
2094 ra = (__u8 *)&raddr->sin_addr;
2095 } else {
2096 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2097 raddr6->sin6_addr.s6_addr,
2098 laddr6->sin6_port, raddr6->sin6_port, 0,
2099 raddr6->sin6_scope_id);
2100 iptype = 6;
2101 ra = (__u8 *)&raddr6->sin6_addr;
2102 }
2103 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002104 pr_err("%s - cannot find route.\n", __func__);
2105 err = -EHOSTUNREACH;
2106 goto fail3;
2107 }
Hariprasad S963cab52015-09-23 17:19:27 +05302108 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302109 ep->com.dev->rdev.lldi.adapter_type,
2110 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302111 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002112 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002113 goto fail4;
2114 }
2115
2116 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2117 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2118 ep->l2t->idx);
2119
2120 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302121 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002122
2123 /* send connect request to rnic */
2124 err = send_connect(ep);
2125 if (!err)
2126 goto out;
2127
2128 cxgb4_l2t_release(ep->l2t);
2129fail4:
2130 dst_release(ep->dst);
2131fail3:
2132 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2133 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2134fail2:
2135 /*
2136 * remember to send notification to upper layer.
2137 * We are in here so the upper layer is not aware that this is
2138 * re-connect attempt and so, upper layer is still waiting for
2139 * response of 1st connect request.
2140 */
2141 connect_reply_upcall(ep, -ECONNRESET);
2142 c4iw_put_ep(&ep->com);
2143out:
2144 return err;
2145}
2146
Steve Wisecfdda9d2010-04-21 15:30:06 -07002147static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2148{
2149 struct c4iw_ep *ep;
2150 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002151 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2152 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002153 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002154 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302155 struct sockaddr_in *la;
2156 struct sockaddr_in *ra;
2157 struct sockaddr_in6 *la6;
2158 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002159
2160 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002161 la = (struct sockaddr_in *)&ep->com.local_addr;
2162 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2163 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2164 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002165
2166 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2167 status, status2errno(status));
2168
Steve Wise7a2cea22014-03-14 21:52:07 +05302169 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302170 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2171 __func__, atid, status, neg_adv_str(status));
2172 ep->stats.connect_neg_adv++;
2173 mutex_lock(&dev->rdev.stats.lock);
2174 dev->rdev.stats.neg_adv++;
2175 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002176 return 0;
2177 }
2178
Vipul Pandya793dad92012-12-10 09:30:56 +00002179 set_bit(ACT_OPEN_RPL, &ep->com.history);
2180
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302181 /*
2182 * Log interesting failures.
2183 */
2184 switch (status) {
2185 case CPL_ERR_CONN_RESET:
2186 case CPL_ERR_CONN_TIMEDOUT:
2187 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002188 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302189 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002190 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302191 mutex_unlock(&dev->rdev.stats.lock);
2192 if (ep->com.local_addr.ss_family == AF_INET &&
2193 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002194 send_fw_act_open_req(ep,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002195 TID_TID_G(AOPEN_ATID_G(
Vipul Pandya793dad92012-12-10 09:30:56 +00002196 ntohl(rpl->atid_status))));
2197 return 0;
2198 }
2199 break;
2200 case CPL_ERR_CONN_EXIST:
2201 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2202 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302203 if (ep->com.remote_addr.ss_family == AF_INET6) {
2204 struct sockaddr_in6 *sin6 =
2205 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002206 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302207 cxgb4_clip_release(
2208 ep->com.dev->rdev.lldi.ports[0],
2209 (const u32 *)
2210 &sin6->sin6_addr.s6_addr, 1);
2211 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002212 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2213 atid);
2214 cxgb4_free_atid(t, atid);
2215 dst_release(ep->dst);
2216 cxgb4_l2t_release(ep->l2t);
2217 c4iw_reconnect(ep);
2218 return 0;
2219 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002220 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302221 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302222 if (ep->com.local_addr.ss_family == AF_INET) {
2223 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2224 atid, status, status2errno(status),
2225 &la->sin_addr.s_addr, ntohs(la->sin_port),
2226 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2227 } else {
2228 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2229 atid, status, status2errno(status),
2230 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2231 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2232 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302233 break;
2234 }
2235
Steve Wisecfdda9d2010-04-21 15:30:06 -07002236 connect_reply_upcall(ep, status2errno(status));
2237 state_set(&ep->com, DEAD);
2238
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302239 if (ep->com.remote_addr.ss_family == AF_INET6) {
2240 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002241 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302242 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2243 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2244 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002245 if (status && act_open_has_tid(status))
2246 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2247
Vipul Pandya793dad92012-12-10 09:30:56 +00002248 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002249 cxgb4_free_atid(t, atid);
2250 dst_release(ep->dst);
2251 cxgb4_l2t_release(ep->l2t);
2252 c4iw_put_ep(&ep->com);
2253
2254 return 0;
2255}
2256
2257static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2258{
2259 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2260 struct tid_info *t = dev->rdev.lldi.tids;
2261 unsigned int stid = GET_TID(rpl);
2262 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2263
2264 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002265 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2266 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002267 }
2268 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2269 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002270 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002271
Vipul Pandya1cab7752012-12-10 09:30:55 +00002272out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002273 return 0;
2274}
2275
Steve Wisecfdda9d2010-04-21 15:30:06 -07002276static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2277{
2278 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2279 struct tid_info *t = dev->rdev.lldi.tids;
2280 unsigned int stid = GET_TID(rpl);
2281 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2282
2283 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002284 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002285 return 0;
2286}
2287
Hariprasad S9dec9002016-05-05 01:27:29 +05302288static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2289 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002290{
2291 struct cpl_pass_accept_rpl *rpl;
2292 unsigned int mtu_idx;
2293 u64 opt0;
2294 u32 opt2;
2295 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302296 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302297 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302298 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002299
2300 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2301 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302302
Steve Wisecfdda9d2010-04-21 15:30:06 -07002303 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302304 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302305 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302306 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2307 rpl5 = (void *)rpl;
2308 INIT_TP_WR(rpl5, ep->hwtid);
2309 } else {
2310 skb_trim(skb, sizeof(*rpl));
2311 INIT_TP_WR(rpl, ep->hwtid);
2312 }
2313 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2314 ep->hwtid));
2315
2316 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302317 enable_tcp_timestamps && req->tcpopt.tstamp,
2318 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002319 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302320
2321 /*
2322 * Specify the largest window that will fit in opt0. The
2323 * remainder will be specified in the rx_data_ack.
2324 */
2325 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002326 if (win > RCV_BUFSIZ_M)
2327 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002328 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002329 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002330 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002331 WND_SCALE_V(wscale) |
2332 MSS_IDX_V(mtu_idx) |
2333 L2T_IDX_V(ep->l2t->idx) |
2334 TX_CHAN_V(ep->tx_chan) |
2335 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002336 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002337 ULP_MODE_V(ULP_MODE_TCPDDP) |
2338 RCV_BUFSIZ_V(win);
2339 opt2 = RX_CHANNEL_V(0) |
2340 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002341
2342 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002343 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002344 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002345 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002346 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002347 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002348 if (enable_ecn) {
2349 const struct tcphdr *tcph;
2350 u32 hlen = ntohl(req->hdr_len);
2351
Hariprasad S963cab52015-09-23 17:19:27 +05302352 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2353 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2354 IP_HDR_LEN_G(hlen);
2355 else
2356 tcph = (const void *)(req + 1) +
2357 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002358 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002359 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002360 }
Hariprasad S963cab52015-09-23 17:19:27 +05302361 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302362 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002363 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302364 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302365 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302366 rpl5 = (void *)rpl;
2367 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2368 if (peer2peer)
2369 isn += 4;
2370 rpl5->iss = cpu_to_be32(isn);
2371 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002372 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002373
Steve Wisecfdda9d2010-04-21 15:30:06 -07002374 rpl->opt0 = cpu_to_be64(opt0);
2375 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002376 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302377 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002378
Hariprasad S9dec9002016-05-05 01:27:29 +05302379 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002380}
2381
Vipul Pandya830662f2013-07-04 16:10:47 +05302382static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002383{
Vipul Pandya830662f2013-07-04 16:10:47 +05302384 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002385 BUG_ON(skb_cloned(skb));
2386 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002387 release_tid(&dev->rdev, hwtid, skb);
2388 return;
2389}
2390
Hariprasad S963cab52015-09-23 17:19:27 +05302391static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2392 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002393 __be16 *local_port, __be16 *peer_port)
2394{
Hariprasad S963cab52015-09-23 17:19:27 +05302395 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2396 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2397 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2398 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2399 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2400 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002401 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302402 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002403 struct tcphdr *tcp = (struct tcphdr *)
2404 ((u8 *)(req + 1) + eth_len + ip_len);
2405
Vipul Pandya830662f2013-07-04 16:10:47 +05302406 if (ip->version == 4) {
2407 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2408 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2409 ntohs(tcp->dest));
2410 *iptype = 4;
2411 memcpy(peer_ip, &ip->saddr, 4);
2412 memcpy(local_ip, &ip->daddr, 4);
2413 } else {
2414 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2415 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2416 ntohs(tcp->dest));
2417 *iptype = 6;
2418 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2419 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2420 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002421 *peer_port = tcp->source;
2422 *local_port = tcp->dest;
2423
2424 return;
2425}
2426
2427static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2428{
Vipul Pandya793dad92012-12-10 09:30:56 +00002429 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002430 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002431 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002432 struct tid_info *t = dev->rdev.lldi.tids;
2433 unsigned int hwtid = GET_TID(req);
2434 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302435 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002436 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302437 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002438 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002439 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302440 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302441 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302442 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002443
2444 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002445 if (!parent_ep) {
2446 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2447 goto reject;
2448 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002449
Steve Wisecfdda9d2010-04-21 15:30:06 -07002450 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302451 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002452 goto reject;
2453 }
2454
Hariprasad S963cab52015-09-23 17:19:27 +05302455 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2456 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302457
Steve Wisecfdda9d2010-04-21 15:30:06 -07002458 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302459 if (iptype == 4) {
2460 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2461 , __func__, parent_ep, hwtid,
2462 local_ip, peer_ip, ntohs(local_port),
2463 ntohs(peer_port), peer_mss);
2464 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2465 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302466 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302467 } else {
2468 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2469 , __func__, parent_ep, hwtid,
2470 local_ip, peer_ip, ntohs(local_port),
2471 ntohs(peer_port), peer_mss);
2472 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002473 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302474 ((struct sockaddr_in6 *)
2475 &parent_ep->com.local_addr)->sin6_scope_id);
2476 }
2477 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002478 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2479 __func__);
2480 goto reject;
2481 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002482
2483 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2484 if (!child_ep) {
2485 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2486 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002487 dst_release(dst);
2488 goto reject;
2489 }
David Miller3786cf12011-12-02 16:52:31 +00002490
Hariprasad S963cab52015-09-23 17:19:27 +05302491 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302492 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002493 if (err) {
2494 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2495 __func__);
2496 dst_release(dst);
2497 kfree(child_ep);
2498 goto reject;
2499 }
2500
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302501 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2502 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2503 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2504 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002505
Steve Wisecfdda9d2010-04-21 15:30:06 -07002506 state_set(&child_ep->com, CONNECTING);
2507 child_ep->com.dev = dev;
2508 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002509
Vipul Pandya830662f2013-07-04 16:10:47 +05302510 if (iptype == 4) {
2511 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002512 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002513
Vipul Pandya830662f2013-07-04 16:10:47 +05302514 sin->sin_family = PF_INET;
2515 sin->sin_port = local_port;
2516 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002517
2518 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2519 sin->sin_family = PF_INET;
2520 sin->sin_port = ((struct sockaddr_in *)
2521 &parent_ep->com.local_addr)->sin_port;
2522 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2523
Steve Wise170003c2016-02-26 09:18:03 -06002524 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302525 sin->sin_family = PF_INET;
2526 sin->sin_port = peer_port;
2527 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2528 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002529 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302530 sin6->sin6_family = PF_INET6;
2531 sin6->sin6_port = local_port;
2532 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002533
2534 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2535 sin6->sin6_family = PF_INET6;
2536 sin6->sin6_port = ((struct sockaddr_in6 *)
2537 &parent_ep->com.local_addr)->sin6_port;
2538 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2539
Steve Wise170003c2016-02-26 09:18:03 -06002540 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302541 sin6->sin6_family = PF_INET6;
2542 sin6->sin6_port = peer_port;
2543 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2544 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002545
Steve Wisecfdda9d2010-04-21 15:30:06 -07002546 c4iw_get_ep(&parent_ep->com);
2547 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302548 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002549 child_ep->dst = dst;
2550 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002551
2552 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002553 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002554
2555 init_timer(&child_ep->timer);
2556 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002557 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Hariprasad S9dec9002016-05-05 01:27:29 +05302558 if (accept_cr(child_ep, skb, req)) {
2559 c4iw_put_ep(&parent_ep->com);
2560 release_ep_resources(child_ep);
2561 } else {
2562 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2563 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302564 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002565 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302566 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2567 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2568 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002569 goto out;
2570reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302571 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002572out:
2573 return 0;
2574}
2575
2576static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2577{
2578 struct c4iw_ep *ep;
2579 struct cpl_pass_establish *req = cplhdr(skb);
2580 struct tid_info *t = dev->rdev.lldi.tids;
2581 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302582 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002583
2584 ep = lookup_tid(t, tid);
2585 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2586 ep->snd_seq = be32_to_cpu(req->snd_isn);
2587 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2588
Vipul Pandya1cab7752012-12-10 09:30:55 +00002589 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2590 ntohs(req->tcp_opt));
2591
Steve Wisecfdda9d2010-04-21 15:30:06 -07002592 set_emss(ep, ntohs(req->tcp_opt));
2593
2594 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302595 mutex_lock(&ep->com.mutex);
2596 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002597 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002598 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad Sfef44222016-05-05 01:27:33 +05302599 ret = send_flowc(ep, skb);
2600 mutex_unlock(&ep->com.mutex);
2601 if (ret)
2602 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002603
2604 return 0;
2605}
2606
2607static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2608{
2609 struct cpl_peer_close *hdr = cplhdr(skb);
2610 struct c4iw_ep *ep;
2611 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002612 int disconnect = 1;
2613 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002614 struct tid_info *t = dev->rdev.lldi.tids;
2615 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002616 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002617
2618 ep = lookup_tid(t, tid);
2619 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2620 dst_confirm(ep->dst);
2621
Vipul Pandya793dad92012-12-10 09:30:56 +00002622 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002623 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002624 switch (ep->com.state) {
2625 case MPA_REQ_WAIT:
2626 __state_set(&ep->com, CLOSING);
2627 break;
2628 case MPA_REQ_SENT:
2629 __state_set(&ep->com, CLOSING);
2630 connect_reply_upcall(ep, -ECONNRESET);
2631 break;
2632 case MPA_REQ_RCVD:
2633
2634 /*
2635 * We're gonna mark this puppy DEAD, but keep
2636 * the reference on it until the ULP accepts or
2637 * rejects the CR. Also wake up anyone waiting
2638 * in rdma connection migration (see c4iw_accept_cr()).
2639 */
2640 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002641 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002642 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002643 break;
2644 case MPA_REP_SENT:
2645 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002646 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002647 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002648 break;
2649 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002650 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002651 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002652 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002653 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002654 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002655 if (ret != -ECONNRESET) {
2656 peer_close_upcall(ep);
2657 disconnect = 1;
2658 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002659 break;
2660 case ABORTING:
2661 disconnect = 0;
2662 break;
2663 case CLOSING:
2664 __state_set(&ep->com, MORIBUND);
2665 disconnect = 0;
2666 break;
2667 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002668 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002669 if (ep->com.cm_id && ep->com.qp) {
2670 attrs.next_state = C4IW_QP_STATE_IDLE;
2671 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2672 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2673 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302674 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002675 __state_set(&ep->com, DEAD);
2676 release = 1;
2677 disconnect = 0;
2678 break;
2679 case DEAD:
2680 disconnect = 0;
2681 break;
2682 default:
2683 BUG_ON(1);
2684 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002685 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002686 if (disconnect)
2687 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2688 if (release)
2689 release_ep_resources(ep);
2690 return 0;
2691}
2692
Steve Wisecfdda9d2010-04-21 15:30:06 -07002693static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2694{
2695 struct cpl_abort_req_rss *req = cplhdr(skb);
2696 struct c4iw_ep *ep;
2697 struct cpl_abort_rpl *rpl;
2698 struct sk_buff *rpl_skb;
2699 struct c4iw_qp_attributes attrs;
2700 int ret;
2701 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002702 struct tid_info *t = dev->rdev.lldi.tids;
2703 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002704
2705 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302706 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302707 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2708 __func__, ep->hwtid, req->status,
2709 neg_adv_str(req->status));
2710 ep->stats.abort_neg_adv++;
2711 mutex_lock(&dev->rdev.stats.lock);
2712 dev->rdev.stats.neg_adv++;
2713 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002714 return 0;
2715 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002716 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2717 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002718 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002719
2720 /*
2721 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302722 * However, this is not needed if com state is just
2723 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002724 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302725 if (ep->com.state != MPA_REQ_SENT)
2726 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002727
2728 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002729 switch (ep->com.state) {
2730 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302731 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002732 break;
2733 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002734 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002735 break;
2736 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002737 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002738 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302739 connect_reply_upcall(ep, -ECONNRESET);
2740 else {
2741 /*
2742 * we just don't send notification upwards because we
2743 * want to retry with mpa_v1 without upper layers even
2744 * knowing it.
2745 *
2746 * do some housekeeping so as to re-initiate the
2747 * connection
2748 */
2749 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2750 mpa_rev);
2751 ep->retry_with_mpa_v1 = 1;
2752 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002753 break;
2754 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002755 break;
2756 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002757 break;
2758 case MORIBUND:
2759 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002760 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002761 /*FALLTHROUGH*/
2762 case FPDU_MODE:
2763 if (ep->com.cm_id && ep->com.qp) {
2764 attrs.next_state = C4IW_QP_STATE_ERROR;
2765 ret = c4iw_modify_qp(ep->com.qp->rhp,
2766 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2767 &attrs, 1);
2768 if (ret)
2769 printk(KERN_ERR MOD
2770 "%s - qp <- error failed!\n",
2771 __func__);
2772 }
2773 peer_abort_upcall(ep);
2774 break;
2775 case ABORTING:
2776 break;
2777 case DEAD:
2778 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002779 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002780 return 0;
2781 default:
2782 BUG_ON(1);
2783 break;
2784 }
2785 dst_confirm(ep->dst);
2786 if (ep->com.state != ABORTING) {
2787 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302788 /* we don't release if we want to retry with mpa_v1 */
2789 if (!ep->retry_with_mpa_v1)
2790 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002791 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002792 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002793
2794 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2795 if (!rpl_skb) {
2796 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2797 __func__);
2798 release = 1;
2799 goto out;
2800 }
2801 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2802 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2803 INIT_TP_WR(rpl, ep->hwtid);
2804 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2805 rpl->cmd = CPL_ABORT_NO_RST;
2806 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2807out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002808 if (release)
2809 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002810 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302811 if (ep->com.remote_addr.ss_family == AF_INET6) {
2812 struct sockaddr_in6 *sin6 =
2813 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002814 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302815 cxgb4_clip_release(
2816 ep->com.dev->rdev.lldi.ports[0],
2817 (const u32 *)&sin6->sin6_addr.s6_addr,
2818 1);
2819 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002820 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302821 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2822 dst_release(ep->dst);
2823 cxgb4_l2t_release(ep->l2t);
2824 c4iw_reconnect(ep);
2825 }
2826
Steve Wisecfdda9d2010-04-21 15:30:06 -07002827 return 0;
2828}
2829
2830static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2831{
2832 struct c4iw_ep *ep;
2833 struct c4iw_qp_attributes attrs;
2834 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002835 int release = 0;
2836 struct tid_info *t = dev->rdev.lldi.tids;
2837 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002838
2839 ep = lookup_tid(t, tid);
2840
2841 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2842 BUG_ON(!ep);
2843
2844 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002845 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302846 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002847 switch (ep->com.state) {
2848 case CLOSING:
2849 __state_set(&ep->com, MORIBUND);
2850 break;
2851 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002852 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002853 if ((ep->com.cm_id) && (ep->com.qp)) {
2854 attrs.next_state = C4IW_QP_STATE_IDLE;
2855 c4iw_modify_qp(ep->com.qp->rhp,
2856 ep->com.qp,
2857 C4IW_QP_ATTR_NEXT_STATE,
2858 &attrs, 1);
2859 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302860 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002861 __state_set(&ep->com, DEAD);
2862 release = 1;
2863 break;
2864 case ABORTING:
2865 case DEAD:
2866 break;
2867 default:
2868 BUG_ON(1);
2869 break;
2870 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002871 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002872 if (release)
2873 release_ep_resources(ep);
2874 return 0;
2875}
2876
2877static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2878{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002879 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002880 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002881 unsigned int tid = GET_TID(rpl);
2882 struct c4iw_ep *ep;
2883 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002884
2885 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002886 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002887
Steve Wise30c95c22011-05-09 22:06:22 -07002888 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002889 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2890 ep->com.qp->wq.sq.qid);
2891 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2892 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2893 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2894 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002895 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002896
Steve Wisecfdda9d2010-04-21 15:30:06 -07002897 return 0;
2898}
2899
2900/*
2901 * Upcall from the adapter indicating data has been transmitted.
2902 * For us its just the single MPA request or reply. We can now free
2903 * the skb holding the mpa message.
2904 */
2905static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2906{
2907 struct c4iw_ep *ep;
2908 struct cpl_fw4_ack *hdr = cplhdr(skb);
2909 u8 credits = hdr->credits;
2910 unsigned int tid = GET_TID(hdr);
2911 struct tid_info *t = dev->rdev.lldi.tids;
2912
2913
2914 ep = lookup_tid(t, tid);
2915 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2916 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002917 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2918 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002919 return 0;
2920 }
2921
2922 dst_confirm(ep->dst);
2923 if (ep->mpa_skb) {
2924 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2925 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2926 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2927 kfree_skb(ep->mpa_skb);
2928 ep->mpa_skb = NULL;
2929 }
2930 return 0;
2931}
2932
Steve Wisecfdda9d2010-04-21 15:30:06 -07002933int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2934{
Steve Wisea7db89e2014-03-21 20:40:35 +05302935 int err = 0;
2936 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002937 struct c4iw_ep *ep = to_ep(cm_id);
2938 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2939
Steve Wisea7db89e2014-03-21 20:40:35 +05302940 mutex_lock(&ep->com.mutex);
2941 if (ep->com.state == DEAD) {
2942 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002943 c4iw_put_ep(&ep->com);
2944 return -ECONNRESET;
2945 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002946 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302947 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002948 if (mpa_rev == 0)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302949 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002950 else {
2951 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302952 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002953 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302954 mutex_unlock(&ep->com.mutex);
2955 if (disconnect)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302956 err = c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002957 c4iw_put_ep(&ep->com);
2958 return 0;
2959}
2960
2961int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2962{
2963 int err;
2964 struct c4iw_qp_attributes attrs;
2965 enum c4iw_qp_attr_mask mask;
2966 struct c4iw_ep *ep = to_ep(cm_id);
2967 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2968 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302969 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002970
2971 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302972
2973 mutex_lock(&ep->com.mutex);
2974 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002975 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302976 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002977 }
2978
Steve Wisea7db89e2014-03-21 20:40:35 +05302979 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002980 BUG_ON(!qp);
2981
Vipul Pandya793dad92012-12-10 09:30:56 +00002982 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302983 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2984 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002985 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302986 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002987 }
2988
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302989 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2990 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302991 if (RELAXED_IRD_NEGOTIATION) {
2992 ep->ord = ep->ird;
2993 } else {
2994 ep->ird = conn_param->ird;
2995 ep->ord = conn_param->ord;
2996 send_mpa_reject(ep, conn_param->private_data,
2997 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302998 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302999 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303000 }
3001 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303002 if (conn_param->ird < ep->ord) {
3003 if (RELAXED_IRD_NEGOTIATION &&
3004 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3005 conn_param->ird = ep->ord;
3006 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303007 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303008 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303009 }
3010 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303011 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003012 ep->ird = conn_param->ird;
3013 ep->ord = conn_param->ord;
3014
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303015 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303016 if (peer2peer && ep->ird == 0)
3017 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303018 } else {
3019 if (peer2peer &&
3020 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303021 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303022 ep->ird = 1;
3023 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003024
3025 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3026
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303027 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303028 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303029 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003030 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303031
Steve Wisecfdda9d2010-04-21 15:30:06 -07003032 /* bind QP to EP and move to RTS */
3033 attrs.mpa_attr = ep->mpa_attr;
3034 attrs.max_ird = ep->ird;
3035 attrs.max_ord = ep->ord;
3036 attrs.llp_stream_handle = ep;
3037 attrs.next_state = C4IW_QP_STATE_RTS;
3038
3039 /* bind QP and TID with INIT_WR */
3040 mask = C4IW_QP_ATTR_NEXT_STATE |
3041 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3042 C4IW_QP_ATTR_MPA_ATTR |
3043 C4IW_QP_ATTR_MAX_IRD |
3044 C4IW_QP_ATTR_MAX_ORD;
3045
3046 err = c4iw_modify_qp(ep->com.qp->rhp,
3047 ep->com.qp, mask, &attrs, 1);
3048 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303049 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003050 err = send_mpa_reply(ep, conn_param->private_data,
3051 conn_param->private_data_len);
3052 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303053 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003054
Steve Wisea7db89e2014-03-21 20:40:35 +05303055 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003056 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303057 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003058 c4iw_put_ep(&ep->com);
3059 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303060err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303061 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303062err_abort:
3063 abort = 1;
3064err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303065 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303066 if (abort)
3067 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003068 c4iw_put_ep(&ep->com);
3069 return err;
3070}
3071
Vipul Pandya830662f2013-07-04 16:10:47 +05303072static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3073{
3074 struct in_device *ind;
3075 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003076 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3077 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303078
3079 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3080 if (!ind)
3081 return -EADDRNOTAVAIL;
3082 for_primary_ifa(ind) {
3083 laddr->sin_addr.s_addr = ifa->ifa_address;
3084 raddr->sin_addr.s_addr = ifa->ifa_address;
3085 found = 1;
3086 break;
3087 }
3088 endfor_ifa(ind);
3089 in_dev_put(ind);
3090 return found ? 0 : -EADDRNOTAVAIL;
3091}
3092
3093static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3094 unsigned char banned_flags)
3095{
3096 struct inet6_dev *idev;
3097 int err = -EADDRNOTAVAIL;
3098
3099 rcu_read_lock();
3100 idev = __in6_dev_get(dev);
3101 if (idev != NULL) {
3102 struct inet6_ifaddr *ifp;
3103
3104 read_lock_bh(&idev->lock);
3105 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3106 if (ifp->scope == IFA_LINK &&
3107 !(ifp->flags & banned_flags)) {
3108 memcpy(addr, &ifp->addr, 16);
3109 err = 0;
3110 break;
3111 }
3112 }
3113 read_unlock_bh(&idev->lock);
3114 }
3115 rcu_read_unlock();
3116 return err;
3117}
3118
3119static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3120{
3121 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003122 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3123 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303124
Nicholas Krause54b9a962015-08-26 23:00:59 -04003125 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303126 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3127 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3128 return 0;
3129 }
3130 return -EADDRNOTAVAIL;
3131}
3132
Steve Wisecfdda9d2010-04-21 15:30:06 -07003133int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3134{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003135 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3136 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003137 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003138 struct sockaddr_in *laddr;
3139 struct sockaddr_in *raddr;
3140 struct sockaddr_in6 *laddr6;
3141 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303142 __u8 *ra;
3143 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003144
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303145 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3146 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003147 err = -EINVAL;
3148 goto out;
3149 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003150 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3151 if (!ep) {
3152 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3153 err = -ENOMEM;
3154 goto out;
3155 }
3156 init_timer(&ep->timer);
3157 ep->plen = conn_param->private_data_len;
3158 if (ep->plen)
3159 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3160 conn_param->private_data, ep->plen);
3161 ep->ird = conn_param->ird;
3162 ep->ord = conn_param->ord;
3163
3164 if (peer2peer && ep->ord == 0)
3165 ep->ord = 1;
3166
Steve Wisecfdda9d2010-04-21 15:30:06 -07003167 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303168 ref_cm_id(&ep->com);
3169 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003170 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303171 if (!ep->com.qp) {
3172 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3173 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003174 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303175 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003176 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003177 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3178 ep->com.qp, cm_id);
3179
3180 /*
3181 * Allocate an active TID to initiate a TCP connection.
3182 */
3183 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3184 if (ep->atid == -1) {
3185 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3186 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003187 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003188 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003189 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003190
Steve Wise170003c2016-02-26 09:18:03 -06003191 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003192 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003193 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003194 sizeof(ep->com.remote_addr));
3195
Steve Wise170003c2016-02-26 09:18:03 -06003196 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3197 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3198 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3199 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003200
Steve Wise170003c2016-02-26 09:18:03 -06003201 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303202 iptype = 4;
3203 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003204
Vipul Pandya830662f2013-07-04 16:10:47 +05303205 /*
3206 * Handle loopback requests to INADDR_ANY.
3207 */
3208 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3209 err = pick_local_ipaddrs(dev, cm_id);
3210 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003211 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303212 }
3213
3214 /* find a route */
3215 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3216 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3217 ra, ntohs(raddr->sin_port));
3218 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3219 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303220 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303221 } else {
3222 iptype = 6;
3223 ra = (__u8 *)&raddr6->sin6_addr;
3224
3225 /*
3226 * Handle loopback requests to INADDR_ANY.
3227 */
3228 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3229 err = pick_local_ip6addrs(dev, cm_id);
3230 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003231 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303232 }
3233
3234 /* find a route */
3235 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3236 __func__, laddr6->sin6_addr.s6_addr,
3237 ntohs(laddr6->sin6_port),
3238 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3239 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3240 raddr6->sin6_addr.s6_addr,
3241 laddr6->sin6_port, raddr6->sin6_port, 0,
3242 raddr6->sin6_scope_id);
3243 }
3244 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003245 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3246 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003247 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003248 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003249
Hariprasad S963cab52015-09-23 17:19:27 +05303250 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303251 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003252 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003253 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003254 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003255 }
3256
3257 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3258 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3259 ep->l2t->idx);
3260
3261 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303262 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003263
3264 /* send connect request to rnic */
3265 err = send_connect(ep);
3266 if (!err)
3267 goto out;
3268
3269 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003270fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003271 dst_release(ep->dst);
3272fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003273 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003274 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003275fail1:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303276 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003277 c4iw_put_ep(&ep->com);
3278out:
3279 return err;
3280}
3281
Vipul Pandya830662f2013-07-04 16:10:47 +05303282static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3283{
3284 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003285 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003286 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303287
Hariprasad S28de1f72016-01-13 10:03:14 +05303288 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3289 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3290 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3291 if (err)
3292 return err;
3293 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303294 c4iw_init_wr_wait(&ep->com.wr_wait);
3295 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3296 ep->stid, &sin6->sin6_addr,
3297 sin6->sin6_port,
3298 ep->com.dev->rdev.lldi.rxq_ids[0]);
3299 if (!err)
3300 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3301 &ep->com.wr_wait,
3302 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303303 else if (err > 0)
3304 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303305 if (err) {
3306 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3307 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303308 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3309 err, ep->stid,
3310 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303311 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303312 return err;
3313}
3314
3315static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3316{
3317 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003318 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003319 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303320
3321 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3322 do {
3323 err = cxgb4_create_server_filter(
3324 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3325 sin->sin_addr.s_addr, sin->sin_port, 0,
3326 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3327 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303328 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3329 err = -EIO;
3330 break;
3331 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303332 set_current_state(TASK_UNINTERRUPTIBLE);
3333 schedule_timeout(usecs_to_jiffies(100));
3334 }
3335 } while (err == -EBUSY);
3336 } else {
3337 c4iw_init_wr_wait(&ep->com.wr_wait);
3338 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3339 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3340 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3341 if (!err)
3342 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3343 &ep->com.wr_wait,
3344 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303345 else if (err > 0)
3346 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303347 }
3348 if (err)
3349 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3350 , err, ep->stid,
3351 &sin->sin_addr, ntohs(sin->sin_port));
3352 return err;
3353}
3354
Steve Wisecfdda9d2010-04-21 15:30:06 -07003355int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3356{
3357 int err = 0;
3358 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3359 struct c4iw_listen_ep *ep;
3360
Steve Wisecfdda9d2010-04-21 15:30:06 -07003361 might_sleep();
3362
3363 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3364 if (!ep) {
3365 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3366 err = -ENOMEM;
3367 goto fail1;
3368 }
3369 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003370 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303371 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003372 ep->com.dev = dev;
3373 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003374 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303375 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003376
3377 /*
3378 * Allocate a server TID.
3379 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303380 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3381 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303382 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003383 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003384 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303385 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003386 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003387
Steve Wisecfdda9d2010-04-21 15:30:06 -07003388 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003389 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003390 err = -ENOMEM;
3391 goto fail2;
3392 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003393 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003394
Steve Wise170003c2016-02-26 09:18:03 -06003395 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3396 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003397
Steve Wisecfdda9d2010-04-21 15:30:06 -07003398 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303399 if (ep->com.local_addr.ss_family == AF_INET)
3400 err = create_server4(dev, ep);
3401 else
3402 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003403 if (!err) {
3404 cm_id->provider_data = ep;
3405 goto out;
3406 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003407
Vipul Pandya830662f2013-07-04 16:10:47 +05303408 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3409 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003410fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303411 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003412 c4iw_put_ep(&ep->com);
3413fail1:
3414out:
3415 return err;
3416}
3417
3418int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3419{
3420 int err;
3421 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3422
3423 PDBG("%s ep %p\n", __func__, ep);
3424
3425 might_sleep();
3426 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303427 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3428 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003429 err = cxgb4_remove_server_filter(
3430 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3431 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3432 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303433 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003434 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303435 err = cxgb4_remove_server(
3436 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3437 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003438 if (err)
3439 goto done;
3440 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3441 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003442 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303443 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3444 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003445 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003446 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303447 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3448 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003449done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303450 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003451 c4iw_put_ep(&ep->com);
3452 return err;
3453}
3454
3455int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3456{
3457 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003458 int close = 0;
3459 int fatal = 0;
3460 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003461
Steve Wise2f5b48c2010-09-10 11:15:36 -05003462 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003463
3464 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3465 states[ep->com.state], abrupt);
3466
Hariprasad S6e410d82016-05-05 01:27:31 +05303467 /*
3468 * Ref the ep here in case we have fatal errors causing the
3469 * ep to be released and freed.
3470 */
3471 c4iw_get_ep(&ep->com);
3472
Steve Wisecfdda9d2010-04-21 15:30:06 -07003473 rdev = &ep->com.dev->rdev;
3474 if (c4iw_fatal_error(rdev)) {
3475 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303476 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003477 ep->com.state = DEAD;
3478 }
3479 switch (ep->com.state) {
3480 case MPA_REQ_WAIT:
3481 case MPA_REQ_SENT:
3482 case MPA_REQ_RCVD:
3483 case MPA_REP_SENT:
3484 case FPDU_MODE:
3485 close = 1;
3486 if (abrupt)
3487 ep->com.state = ABORTING;
3488 else {
3489 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003490 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003491 }
3492 set_bit(CLOSE_SENT, &ep->com.flags);
3493 break;
3494 case CLOSING:
3495 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3496 close = 1;
3497 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003498 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003499 ep->com.state = ABORTING;
3500 } else
3501 ep->com.state = MORIBUND;
3502 }
3503 break;
3504 case MORIBUND:
3505 case ABORTING:
3506 case DEAD:
3507 PDBG("%s ignoring disconnect ep %p state %u\n",
3508 __func__, ep, ep->com.state);
3509 break;
3510 default:
3511 BUG();
3512 break;
3513 }
3514
Steve Wisecfdda9d2010-04-21 15:30:06 -07003515 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003516 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003517 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303518 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003519 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003520 } else {
3521 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003522 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003523 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303524 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303525 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303526 if (!abrupt) {
3527 stop_ep_timer(ep);
3528 close_complete_upcall(ep, -EIO);
3529 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303530 if (ep->com.qp) {
3531 struct c4iw_qp_attributes attrs;
3532
3533 attrs.next_state = C4IW_QP_STATE_ERROR;
3534 ret = c4iw_modify_qp(ep->com.qp->rhp,
3535 ep->com.qp,
3536 C4IW_QP_ATTR_NEXT_STATE,
3537 &attrs, 1);
3538 if (ret)
3539 pr_err(MOD
3540 "%s - qp <- error failed!\n",
3541 __func__);
3542 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003543 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303544 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003545 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003546 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303547 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003548 if (fatal)
3549 release_ep_resources(ep);
3550 return ret;
3551}
3552
Vipul Pandya1cab7752012-12-10 09:30:55 +00003553static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3554 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3555{
3556 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003557 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003558
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003559 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3560 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003561 if (!ep)
3562 return;
3563
3564 switch (req->retval) {
3565 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003566 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3567 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3568 send_fw_act_open_req(ep, atid);
3569 return;
3570 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003571 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003572 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3573 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3574 send_fw_act_open_req(ep, atid);
3575 return;
3576 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003577 break;
3578 default:
3579 pr_info("%s unexpected ofld conn wr retval %d\n",
3580 __func__, req->retval);
3581 break;
3582 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003583 pr_err("active ofld_connect_wr failure %d atid %d\n",
3584 req->retval, atid);
3585 mutex_lock(&dev->rdev.stats.lock);
3586 dev->rdev.stats.act_ofld_conn_fails++;
3587 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003588 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003589 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303590 if (ep->com.remote_addr.ss_family == AF_INET6) {
3591 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003592 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303593 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3594 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3595 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003596 remove_handle(dev, &dev->atid_idr, atid);
3597 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3598 dst_release(ep->dst);
3599 cxgb4_l2t_release(ep->l2t);
3600 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003601}
3602
3603static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3604 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3605{
3606 struct sk_buff *rpl_skb;
3607 struct cpl_pass_accept_req *cpl;
3608 int ret;
3609
Paul Bolle710a3112013-02-05 20:51:30 +00003610 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003611 BUG_ON(!rpl_skb);
3612 if (req->retval) {
3613 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003614 mutex_lock(&dev->rdev.stats.lock);
3615 dev->rdev.stats.pas_ofld_conn_fails++;
3616 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003617 kfree_skb(rpl_skb);
3618 } else {
3619 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3620 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003621 (__force u32) htonl(
3622 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003623 ret = pass_accept_req(dev, rpl_skb);
3624 if (!ret)
3625 kfree_skb(rpl_skb);
3626 }
3627 return;
3628}
3629
3630static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003631{
3632 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003633 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3634
3635 switch (rpl->type) {
3636 case FW6_TYPE_CQE:
3637 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3638 break;
3639 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3640 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3641 switch (req->t_state) {
3642 case TCP_SYN_SENT:
3643 active_ofld_conn_reply(dev, skb, req);
3644 break;
3645 case TCP_SYN_RECV:
3646 passive_ofld_conn_reply(dev, skb, req);
3647 break;
3648 default:
3649 pr_err("%s unexpected ofld conn wr state %d\n",
3650 __func__, req->t_state);
3651 break;
3652 }
3653 break;
3654 }
3655 return 0;
3656}
3657
3658static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3659{
Hariprasad S963cab52015-09-23 17:19:27 +05303660 __be32 l2info;
3661 __be16 hdr_len, vlantag, len;
3662 u16 eth_hdr_len;
3663 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003664 u8 intf;
3665 struct cpl_rx_pkt *cpl = cplhdr(skb);
3666 struct cpl_pass_accept_req *req;
3667 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003668 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303669 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003670
Vipul Pandyaf079af72013-03-14 05:08:58 +00003671 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003672 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303673 vlantag = cpl->vlan;
3674 len = cpl->len;
3675 l2info = cpl->l2info;
3676 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003677 intf = cpl->iff;
3678
3679 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3680
3681 /*
3682 * We need to parse the TCP options from SYN packet.
3683 * to generate cpl_pass_accept_req.
3684 */
3685 memset(&tmp_opt, 0, sizeof(tmp_opt));
3686 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003687 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003688
3689 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3690 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303691 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3692 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303693 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303694 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303695 type = dev->rdev.lldi.adapter_type;
3696 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3697 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3698 req->hdr_len =
3699 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3700 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3701 eth_hdr_len = is_t4(type) ?
3702 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3703 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3704 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3705 IP_HDR_LEN_V(ip_hdr_len) |
3706 ETH_HDR_LEN_V(eth_hdr_len));
3707 } else { /* T6 and later */
3708 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3709 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3710 T6_IP_HDR_LEN_V(ip_hdr_len) |
3711 T6_ETH_HDR_LEN_V(eth_hdr_len));
3712 }
3713 req->vlan = vlantag;
3714 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003715 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3716 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003717 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3718 if (tmp_opt.wscale_ok)
3719 req->tcpopt.wsf = tmp_opt.snd_wscale;
3720 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3721 if (tmp_opt.sack_ok)
3722 req->tcpopt.sack = 1;
3723 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3724 return;
3725}
3726
3727static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3728 __be32 laddr, __be16 lport,
3729 __be32 raddr, __be16 rport,
3730 u32 rcv_isn, u32 filter, u16 window,
3731 u32 rss_qid, u8 port_id)
3732{
3733 struct sk_buff *req_skb;
3734 struct fw_ofld_connection_wr *req;
3735 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303736 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003737
3738 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3739 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3740 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003741 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303742 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303743 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003744 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003745 req->le.lport = lport;
3746 req->le.pport = rport;
3747 req->le.u.ipv4.lip = laddr;
3748 req->le.u.ipv4.pip = raddr;
3749 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3750 req->tcb.rcv_adv = htons(window);
3751 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303752 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3753 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3754 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003755 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003756
3757 /*
3758 * We store the qid in opt2 which will be used by the firmware
3759 * to send us the wr response.
3760 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003761 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003762
3763 /*
3764 * We initialize the MSS index in TCB to 0xF.
3765 * So that when driver sends cpl_pass_accept_rpl
3766 * TCB picks up the correct value. If this was 0
3767 * TP will ignore any value > 0 for MSS index.
3768 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003769 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303770 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003771
3772 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303773 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3774 if (ret < 0) {
3775 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3776 ret);
3777 kfree_skb(skb);
3778 kfree_skb(req_skb);
3779 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003780}
3781
3782/*
3783 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3784 * messages when a filter is being used instead of server to
3785 * redirect a syn packet. When packets hit filter they are redirected
3786 * to the offload queue and driver tries to establish the connection
3787 * using firmware work request.
3788 */
3789static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3790{
3791 int stid;
3792 unsigned int filter;
3793 struct ethhdr *eh = NULL;
3794 struct vlan_ethhdr *vlan_eh = NULL;
3795 struct iphdr *iph;
3796 struct tcphdr *tcph;
3797 struct rss_header *rss = (void *)skb->data;
3798 struct cpl_rx_pkt *cpl = (void *)skb->data;
3799 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3800 struct l2t_entry *e;
3801 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003802 struct c4iw_ep *lep;
3803 u16 window;
3804 struct port_info *pi;
3805 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003806 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003807 int step;
3808 u32 tx_chan;
3809 struct neighbour *neigh;
3810
3811 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003812 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003813 goto reject;
3814
3815 /*
3816 * Drop all packets which did not hit the filter.
3817 * Unlikely to happen.
3818 */
3819 if (!(rss->filter_hit && rss->filter_tid))
3820 goto reject;
3821
3822 /*
3823 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3824 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303825 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003826
3827 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3828 if (!lep) {
3829 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3830 goto reject;
3831 }
3832
Hariprasad S963cab52015-09-23 17:19:27 +05303833 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3834 case CHELSIO_T4:
3835 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3836 break;
3837 case CHELSIO_T5:
3838 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3839 break;
3840 case CHELSIO_T6:
3841 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3842 break;
3843 default:
3844 pr_err("T%d Chip is not supported\n",
3845 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3846 goto reject;
3847 }
3848
Vipul Pandyaf079af72013-03-14 05:08:58 +00003849 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003850 eh = (struct ethhdr *)(req + 1);
3851 iph = (struct iphdr *)(eh + 1);
3852 } else {
3853 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3854 iph = (struct iphdr *)(vlan_eh + 1);
3855 skb->vlan_tci = ntohs(cpl->vlan);
3856 }
3857
3858 if (iph->version != 0x4)
3859 goto reject;
3860
3861 tcph = (struct tcphdr *)(iph + 1);
3862 skb_set_network_header(skb, (void *)iph - (void *)rss);
3863 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3864 skb_get(skb);
3865
3866 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3867 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3868 ntohs(tcph->source), iph->tos);
3869
Vipul Pandya830662f2013-07-04 16:10:47 +05303870 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3871 iph->tos);
3872 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003873 pr_err("%s - failed to find dst entry!\n",
3874 __func__);
3875 goto reject;
3876 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003877 neigh = dst_neigh_lookup_skb(dst, skb);
3878
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003879 if (!neigh) {
3880 pr_err("%s - failed to allocate neigh!\n",
3881 __func__);
3882 goto free_dst;
3883 }
3884
Vipul Pandya1cab7752012-12-10 09:30:55 +00003885 if (neigh->dev->flags & IFF_LOOPBACK) {
3886 pdev = ip_dev_find(&init_net, iph->daddr);
3887 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3888 pdev, 0);
3889 pi = (struct port_info *)netdev_priv(pdev);
3890 tx_chan = cxgb4_port_chan(pdev);
3891 dev_put(pdev);
3892 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303893 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003894 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303895 pdev, 0);
3896 pi = (struct port_info *)netdev_priv(pdev);
3897 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003898 }
Steve Wiseebf00062014-03-19 17:44:40 +05303899 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003900 if (!e) {
3901 pr_err("%s - failed to allocate l2t entry!\n",
3902 __func__);
3903 goto free_dst;
3904 }
3905
3906 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3907 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003908 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003909
3910 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303911 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3912 dev->rdev.lldi.ports[0],
3913 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003914
3915 /*
3916 * Synthesize the cpl_pass_accept_req. We have everything except the
3917 * TID. Once firmware sends a reply with TID we update the TID field
3918 * in cpl and pass it through the regular cpl_pass_accept_req path.
3919 */
3920 build_cpl_pass_accept_req(skb, stid, iph->tos);
3921 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3922 tcph->source, ntohl(tcph->seq), filter, window,
3923 rss_qid, pi->port_id);
3924 cxgb4_l2t_release(e);
3925free_dst:
3926 dst_release(dst);
3927reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003928 return 0;
3929}
3930
Steve Wisecfdda9d2010-04-21 15:30:06 -07003931/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003932 * These are the real handlers that are called from a
3933 * work queue.
3934 */
Hariprasad S9dec9002016-05-05 01:27:29 +05303935static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003936 [CPL_ACT_ESTABLISH] = act_establish,
3937 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3938 [CPL_RX_DATA] = rx_data,
3939 [CPL_ABORT_RPL_RSS] = abort_rpl,
3940 [CPL_ABORT_RPL] = abort_rpl,
3941 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3942 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3943 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3944 [CPL_PASS_ESTABLISH] = pass_establish,
3945 [CPL_PEER_CLOSE] = peer_close,
3946 [CPL_ABORT_REQ_RSS] = peer_abort,
3947 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3948 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003949 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003950 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05303951 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05303952 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
3953 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003954};
3955
3956static void process_timeout(struct c4iw_ep *ep)
3957{
3958 struct c4iw_qp_attributes attrs;
3959 int abort = 1;
3960
Steve Wise2f5b48c2010-09-10 11:15:36 -05003961 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003962 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3963 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003964 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003965 switch (ep->com.state) {
3966 case MPA_REQ_SENT:
3967 __state_set(&ep->com, ABORTING);
3968 connect_reply_upcall(ep, -ETIMEDOUT);
3969 break;
3970 case MPA_REQ_WAIT:
3971 __state_set(&ep->com, ABORTING);
3972 break;
3973 case CLOSING:
3974 case MORIBUND:
3975 if (ep->com.cm_id && ep->com.qp) {
3976 attrs.next_state = C4IW_QP_STATE_ERROR;
3977 c4iw_modify_qp(ep->com.qp->rhp,
3978 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3979 &attrs, 1);
3980 }
3981 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303982 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003983 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003984 case ABORTING:
3985 case DEAD:
3986
3987 /*
3988 * These states are expected if the ep timed out at the same
3989 * time as another thread was calling stop_ep_timer().
3990 * So we silently do nothing for these states.
3991 */
3992 abort = 0;
3993 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003994 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003995 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003996 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003997 abort = 0;
3998 }
Steve Wisecc18b932014-04-24 14:31:53 -05003999 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304000 if (abort)
4001 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004002 c4iw_put_ep(&ep->com);
4003}
4004
4005static void process_timedout_eps(void)
4006{
4007 struct c4iw_ep *ep;
4008
4009 spin_lock_irq(&timeout_lock);
4010 while (!list_empty(&timeout_list)) {
4011 struct list_head *tmp;
4012
4013 tmp = timeout_list.next;
4014 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004015 tmp->next = NULL;
4016 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004017 spin_unlock_irq(&timeout_lock);
4018 ep = list_entry(tmp, struct c4iw_ep, entry);
4019 process_timeout(ep);
4020 spin_lock_irq(&timeout_lock);
4021 }
4022 spin_unlock_irq(&timeout_lock);
4023}
4024
4025static void process_work(struct work_struct *work)
4026{
4027 struct sk_buff *skb = NULL;
4028 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004029 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004030 unsigned int opcode;
4031 int ret;
4032
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004033 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004034 while ((skb = skb_dequeue(&rxq))) {
4035 rpl = cplhdr(skb);
4036 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4037 opcode = rpl->ot.opcode;
4038
4039 BUG_ON(!work_handlers[opcode]);
4040 ret = work_handlers[opcode](dev, skb);
4041 if (!ret)
4042 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004043 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004044 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004045}
4046
4047static DECLARE_WORK(skb_work, process_work);
4048
4049static void ep_timeout(unsigned long arg)
4050{
4051 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004052 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004053
4054 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004055 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004056 /*
4057 * Only insert if it is not already on the list.
4058 */
4059 if (!ep->entry.next) {
4060 list_add_tail(&ep->entry, &timeout_list);
4061 kickit = 1;
4062 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004063 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004064 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004065 if (kickit)
4066 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004067}
4068
4069/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004070 * All the CM events are handled on a work queue to have a safe context.
4071 */
4072static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4073{
4074
4075 /*
4076 * Save dev in the skb->cb area.
4077 */
4078 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4079
4080 /*
4081 * Queue the skb and schedule the worker thread.
4082 */
4083 skb_queue_tail(&rxq, skb);
4084 queue_work(workq, &skb_work);
4085 return 0;
4086}
4087
4088static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4089{
4090 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4091
4092 if (rpl->status != CPL_ERR_NONE) {
4093 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4094 "for tid %u\n", rpl->status, GET_TID(rpl));
4095 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004096 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004097 return 0;
4098}
4099
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004100static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4101{
4102 struct cpl_fw6_msg *rpl = cplhdr(skb);
4103 struct c4iw_wr_wait *wr_waitp;
4104 int ret;
4105
4106 PDBG("%s type %u\n", __func__, rpl->type);
4107
4108 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004109 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004110 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004111 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004112 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004113 if (wr_waitp)
4114 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004115 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004116 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004117 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004118 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004119 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004120 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004121 default:
4122 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4123 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004124 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004125 break;
4126 }
4127 return 0;
4128}
4129
Steve Wise8da7e7a2011-06-14 20:59:27 +00004130static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4131{
4132 struct cpl_abort_req_rss *req = cplhdr(skb);
4133 struct c4iw_ep *ep;
4134 struct tid_info *t = dev->rdev.lldi.tids;
4135 unsigned int tid = GET_TID(req);
4136
4137 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05004138 if (!ep) {
4139 printk(KERN_WARNING MOD
4140 "Abort on non-existent endpoint, tid %d\n", tid);
4141 kfree_skb(skb);
4142 return 0;
4143 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304144 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304145 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4146 __func__, ep->hwtid, req->status,
4147 neg_adv_str(req->status));
4148 ep->stats.abort_neg_adv++;
4149 dev->rdev.stats.neg_adv++;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004150 kfree_skb(skb);
4151 return 0;
4152 }
4153 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4154 ep->com.state);
4155
4156 /*
4157 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004158 * However, if we are on MPAv2 and want to retry with MPAv1
4159 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004160 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004161 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4162 if (ep->com.state != MPA_REQ_SENT)
4163 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4164 } else
4165 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00004166 sched(dev, skb);
4167 return 0;
4168}
4169
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004170/*
4171 * Most upcalls from the T4 Core go to sched() to
4172 * schedule the processing on a work queue.
4173 */
4174c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4175 [CPL_ACT_ESTABLISH] = sched,
4176 [CPL_ACT_OPEN_RPL] = sched,
4177 [CPL_RX_DATA] = sched,
4178 [CPL_ABORT_RPL_RSS] = sched,
4179 [CPL_ABORT_RPL] = sched,
4180 [CPL_PASS_OPEN_RPL] = sched,
4181 [CPL_CLOSE_LISTSRV_RPL] = sched,
4182 [CPL_PASS_ACCEPT_REQ] = sched,
4183 [CPL_PASS_ESTABLISH] = sched,
4184 [CPL_PEER_CLOSE] = sched,
4185 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004186 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004187 [CPL_RDMA_TERMINATE] = sched,
4188 [CPL_FW4_ACK] = sched,
4189 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004190 [CPL_FW6_MSG] = fw6_msg,
4191 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004192};
4193
Steve Wisecfdda9d2010-04-21 15:30:06 -07004194int __init c4iw_cm_init(void)
4195{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004196 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004197 skb_queue_head_init(&rxq);
4198
4199 workq = create_singlethread_workqueue("iw_cxgb4");
4200 if (!workq)
4201 return -ENOMEM;
4202
Steve Wisecfdda9d2010-04-21 15:30:06 -07004203 return 0;
4204}
4205
Steve Wise46c13762014-06-20 14:26:25 -05004206void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004207{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004208 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004209 flush_workqueue(workq);
4210 destroy_workqueue(workq);
4211}