blob: 8cd7b5e4b03dcfec55fb975bca1abda60b14e6a0 [file] [log] [blame]
Steve Wisecfdda9d2010-04-21 15:30:06 -07001/*
Steve Wise9eccfe12014-03-26 17:08:09 -05002 * Copyright (c) 2009-2014 Chelsio, Inc. All rights reserved.
Steve Wisecfdda9d2010-04-21 15:30:06 -07003 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32#include <linux/module.h>
33#include <linux/list.h>
34#include <linux/workqueue.h>
35#include <linux/skbuff.h>
36#include <linux/timer.h>
37#include <linux/notifier.h>
38#include <linux/inetdevice.h>
39#include <linux/ip.h>
40#include <linux/tcp.h>
Vipul Pandya1cab7752012-12-10 09:30:55 +000041#include <linux/if_vlan.h>
Steve Wisecfdda9d2010-04-21 15:30:06 -070042
43#include <net/neighbour.h>
44#include <net/netevent.h>
45#include <net/route.h>
Vipul Pandya1cab7752012-12-10 09:30:55 +000046#include <net/tcp.h>
Vipul Pandya830662f2013-07-04 16:10:47 +053047#include <net/ip6_route.h>
48#include <net/addrconf.h>
Steve Wisecfdda9d2010-04-21 15:30:06 -070049
Steve Wise11b8e222014-05-16 12:42:46 -050050#include <rdma/ib_addr.h>
51
Steve Wisecfdda9d2010-04-21 15:30:06 -070052#include "iw_cxgb4.h"
Hariprasad S84cc6ac62015-08-25 14:08:23 +053053#include "clip_tbl.h"
Steve Wisecfdda9d2010-04-21 15:30:06 -070054
55static char *states[] = {
56 "idle",
57 "listen",
58 "connecting",
59 "mpa_wait_req",
60 "mpa_req_sent",
61 "mpa_req_rcvd",
62 "mpa_rep_sent",
63 "fpdu_mode",
64 "aborting",
65 "closing",
66 "moribund",
67 "dead",
68 NULL,
69};
70
Vipul Pandya5be78ee2012-12-10 09:30:54 +000071static int nocong;
72module_param(nocong, int, 0644);
73MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
74
75static int enable_ecn;
76module_param(enable_ecn, int, 0644);
77MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
78
Steve Wiseb52fe092011-03-11 22:30:01 +000079static int dack_mode = 1;
Steve Wiseba6d3922010-06-23 15:46:49 +000080module_param(dack_mode, int, 0644);
Steve Wiseb52fe092011-03-11 22:30:01 +000081MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
Steve Wiseba6d3922010-06-23 15:46:49 +000082
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053083uint c4iw_max_read_depth = 32;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070084module_param(c4iw_max_read_depth, int, 0644);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053085MODULE_PARM_DESC(c4iw_max_read_depth,
86 "Per-connection max ORD/IRD (default=32)");
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070087
Steve Wisecfdda9d2010-04-21 15:30:06 -070088static int enable_tcp_timestamps;
89module_param(enable_tcp_timestamps, int, 0644);
90MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
91
92static int enable_tcp_sack;
93module_param(enable_tcp_sack, int, 0644);
94MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
95
96static int enable_tcp_window_scaling = 1;
97module_param(enable_tcp_window_scaling, int, 0644);
98MODULE_PARM_DESC(enable_tcp_window_scaling,
99 "Enable tcp window scaling (default=1)");
100
101int c4iw_debug;
102module_param(c4iw_debug, int, 0644);
103MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
104
Steve Wisedf2d5132014-03-19 17:44:44 +0530105static int peer2peer = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700106module_param(peer2peer, int, 0644);
Steve Wisedf2d5132014-03-19 17:44:44 +0530107MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700108
109static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
110module_param(p2p_type, int, 0644);
111MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
112 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
113
114static int ep_timeout_secs = 60;
115module_param(ep_timeout_secs, int, 0644);
116MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
117 "in seconds (default=60)");
118
Hariprasad Sb8ac3112015-07-27 14:08:52 +0530119static int mpa_rev = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700120module_param(mpa_rev, int, 0644);
121MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530122 "1 is RFC0544 spec compliant, 2 is IETF MPA Peer Connect Draft"
Hariprasad Sb8ac3112015-07-27 14:08:52 +0530123 " compliant (default=2)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700124
125static int markers_enabled;
126module_param(markers_enabled, int, 0644);
127MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
128
129static int crc_enabled = 1;
130module_param(crc_enabled, int, 0644);
131MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
132
133static int rcv_win = 256 * 1024;
134module_param(rcv_win, int, 0644);
135MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
136
Steve Wise98ae68b2010-09-10 11:15:41 -0500137static int snd_win = 128 * 1024;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700138module_param(snd_win, int, 0644);
Steve Wise98ae68b2010-09-10 11:15:41 -0500139MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700140
Steve Wisecfdda9d2010-04-21 15:30:06 -0700141static struct workqueue_struct *workq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700142
143static struct sk_buff_head rxq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700144
145static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
146static void ep_timeout(unsigned long arg);
147static void connect_reply_upcall(struct c4iw_ep *ep, int status);
148
Roland Dreierbe4c9ba2010-05-05 14:45:40 -0700149static LIST_HEAD(timeout_list);
150static spinlock_t timeout_lock;
151
Vipul Pandya325abea2013-01-07 13:11:53 +0000152static void deref_qp(struct c4iw_ep *ep)
153{
154 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
155 clear_bit(QP_REFERENCED, &ep->com.flags);
156}
157
158static void ref_qp(struct c4iw_ep *ep)
159{
160 set_bit(QP_REFERENCED, &ep->com.flags);
161 c4iw_qp_add_ref(&ep->com.qp->ibqp);
162}
163
Steve Wisecfdda9d2010-04-21 15:30:06 -0700164static void start_ep_timer(struct c4iw_ep *ep)
165{
166 PDBG("%s ep %p\n", __func__, ep);
167 if (timer_pending(&ep->timer)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000168 pr_err("%s timer already started! ep %p\n",
169 __func__, ep);
170 return;
171 }
172 clear_bit(TIMEOUT, &ep->com.flags);
173 c4iw_get_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700174 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
175 ep->timer.data = (unsigned long)ep;
176 ep->timer.function = ep_timeout;
177 add_timer(&ep->timer);
178}
179
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500180static int stop_ep_timer(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700181{
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000182 PDBG("%s ep %p stopping\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700183 del_timer_sync(&ep->timer);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500184 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000185 c4iw_put_ep(&ep->com);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500186 return 0;
187 }
188 return 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700189}
190
191static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
192 struct l2t_entry *l2e)
193{
194 int error = 0;
195
196 if (c4iw_fatal_error(rdev)) {
197 kfree_skb(skb);
198 PDBG("%s - device in error state - dropping\n", __func__);
199 return -EIO;
200 }
201 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
202 if (error < 0)
203 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500204 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700205}
206
207int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
208{
209 int error = 0;
210
211 if (c4iw_fatal_error(rdev)) {
212 kfree_skb(skb);
213 PDBG("%s - device in error state - dropping\n", __func__);
214 return -EIO;
215 }
216 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
217 if (error < 0)
218 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500219 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700220}
221
222static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
223{
224 struct cpl_tid_release *req;
225
226 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
227 if (!skb)
228 return;
229 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
230 INIT_TP_WR(req, hwtid);
231 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
232 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
233 c4iw_ofld_send(rdev, skb);
234 return;
235}
236
237static void set_emss(struct c4iw_ep *ep, u16 opt)
238{
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800239 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
Hariprasad S04524a42014-09-24 03:53:41 +0530240 ((AF_INET == ep->com.remote_addr.ss_family) ?
241 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
242 sizeof(struct tcphdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700243 ep->mss = ep->emss;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800244 if (TCPOPT_TSTAMP_G(opt))
Hariprasad S04524a42014-09-24 03:53:41 +0530245 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700246 if (ep->emss < 128)
247 ep->emss = 128;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530248 if (ep->emss & 7)
249 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800250 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
251 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt),
Steve Wisecfdda9d2010-04-21 15:30:06 -0700252 ep->mss, ep->emss);
253}
254
255static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
256{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700257 enum c4iw_ep_state state;
258
Steve Wise2f5b48c2010-09-10 11:15:36 -0500259 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700260 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500261 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700262 return state;
263}
264
265static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
266{
267 epc->state = new;
268}
269
270static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
271{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500272 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700273 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
274 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500275 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700276 return;
277}
278
279static void *alloc_ep(int size, gfp_t gfp)
280{
281 struct c4iw_ep_common *epc;
282
283 epc = kzalloc(size, gfp);
284 if (epc) {
285 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500286 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500287 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700288 }
289 PDBG("%s alloc ep %p\n", __func__, epc);
290 return epc;
291}
292
293void _c4iw_free_ep(struct kref *kref)
294{
295 struct c4iw_ep *ep;
296
297 ep = container_of(kref, struct c4iw_ep, com.kref);
298 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000299 if (test_bit(QP_REFERENCED, &ep->com.flags))
300 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700301 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530302 if (ep->com.remote_addr.ss_family == AF_INET6) {
303 struct sockaddr_in6 *sin6 =
304 (struct sockaddr_in6 *)
305 &ep->com.mapped_local_addr;
306
307 cxgb4_clip_release(
308 ep->com.dev->rdev.lldi.ports[0],
309 (const u32 *)&sin6->sin6_addr.s6_addr,
310 1);
311 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000312 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700313 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
314 dst_release(ep->dst);
315 cxgb4_l2t_release(ep->l2t);
316 }
Steve Wise9eccfe12014-03-26 17:08:09 -0500317 if (test_bit(RELEASE_MAPINFO, &ep->com.flags)) {
318 print_addr(&ep->com, __func__, "remove_mapinfo/mapping");
319 iwpm_remove_mapinfo(&ep->com.local_addr,
320 &ep->com.mapped_local_addr);
321 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
322 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700323 kfree(ep);
324}
325
326static void release_ep_resources(struct c4iw_ep *ep)
327{
328 set_bit(RELEASE_RESOURCES, &ep->com.flags);
329 c4iw_put_ep(&ep->com);
330}
331
Steve Wisecfdda9d2010-04-21 15:30:06 -0700332static int status2errno(int status)
333{
334 switch (status) {
335 case CPL_ERR_NONE:
336 return 0;
337 case CPL_ERR_CONN_RESET:
338 return -ECONNRESET;
339 case CPL_ERR_ARP_MISS:
340 return -EHOSTUNREACH;
341 case CPL_ERR_CONN_TIMEDOUT:
342 return -ETIMEDOUT;
343 case CPL_ERR_TCAM_FULL:
344 return -ENOMEM;
345 case CPL_ERR_CONN_EXIST:
346 return -EADDRINUSE;
347 default:
348 return -EIO;
349 }
350}
351
352/*
353 * Try and reuse skbs already allocated...
354 */
355static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
356{
357 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
358 skb_trim(skb, 0);
359 skb_get(skb);
360 skb_reset_transport_header(skb);
361 } else {
362 skb = alloc_skb(len, gfp);
363 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530364 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700365 return skb;
366}
367
Vipul Pandya830662f2013-07-04 16:10:47 +0530368static struct net_device *get_real_dev(struct net_device *egress_dev)
369{
Steve Wise11b8e222014-05-16 12:42:46 -0500370 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530371}
372
373static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
374{
375 int i;
376
377 egress_dev = get_real_dev(egress_dev);
378 for (i = 0; i < dev->rdev.lldi.nports; i++)
379 if (dev->rdev.lldi.ports[i] == egress_dev)
380 return 1;
381 return 0;
382}
383
384static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
385 __u8 *peer_ip, __be16 local_port,
386 __be16 peer_port, u8 tos,
387 __u32 sin6_scope_id)
388{
389 struct dst_entry *dst = NULL;
390
391 if (IS_ENABLED(CONFIG_IPV6)) {
392 struct flowi6 fl6;
393
394 memset(&fl6, 0, sizeof(fl6));
395 memcpy(&fl6.daddr, peer_ip, 16);
396 memcpy(&fl6.saddr, local_ip, 16);
397 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
398 fl6.flowi6_oif = sin6_scope_id;
399 dst = ip6_route_output(&init_net, NULL, &fl6);
400 if (!dst)
401 goto out;
402 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
403 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
404 dst_release(dst);
405 dst = NULL;
406 }
407 }
408
409out:
410 return dst;
411}
412
413static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700414 __be32 peer_ip, __be16 local_port,
415 __be16 peer_port, u8 tos)
416{
417 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700418 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530419 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700420
David S. Miller31e4543d2011-05-03 20:25:42 -0700421 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500422 peer_port, local_port, IPPROTO_TCP,
423 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800424 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700425 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530426 n = dst_neigh_lookup(&rt->dst, &peer_ip);
427 if (!n)
428 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530429 if (!our_interface(dev, n->dev) &&
430 !(n->dev->flags & IFF_LOOPBACK)) {
Hariprasad Sd4802012014-09-24 03:53:42 +0530431 neigh_release(n);
Vipul Pandya830662f2013-07-04 16:10:47 +0530432 dst_release(&rt->dst);
433 return NULL;
434 }
435 neigh_release(n);
436 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700437}
438
439static void arp_failure_discard(void *handle, struct sk_buff *skb)
440{
441 PDBG("%s c4iw_dev %p\n", __func__, handle);
442 kfree_skb(skb);
443}
444
445/*
446 * Handle an ARP failure for an active open.
447 */
448static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
449{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530450 struct c4iw_ep *ep = handle;
451
Masanari Iidae3d132d2015-10-16 21:14:29 +0900452 printk(KERN_ERR MOD "ARP failure during connect\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700453 kfree_skb(skb);
Hariprasad S5dab6d32014-06-23 19:12:36 +0530454 connect_reply_upcall(ep, -EHOSTUNREACH);
455 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530456 if (ep->com.remote_addr.ss_family == AF_INET6) {
457 struct sockaddr_in6 *sin6 =
458 (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
459 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
460 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
461 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530462 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
463 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
464 dst_release(ep->dst);
465 cxgb4_l2t_release(ep->l2t);
466 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700467}
468
469/*
470 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
471 * and send it along.
472 */
473static void abort_arp_failure(void *handle, struct sk_buff *skb)
474{
475 struct c4iw_rdev *rdev = handle;
476 struct cpl_abort_req *req = cplhdr(skb);
477
478 PDBG("%s rdev %p\n", __func__, rdev);
479 req->cmd = CPL_ABORT_NO_RST;
480 c4iw_ofld_send(rdev, skb);
481}
482
483static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
484{
485 unsigned int flowclen = 80;
486 struct fw_flowc_wr *flowc;
487 int i;
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +0530488 u16 vlan = ep->l2t->vlan;
489 int nparams;
490
491 if (vlan == CPL_L2T_VLAN_NONE)
492 nparams = 8;
493 else
494 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700495
496 skb = get_skb(skb, flowclen, GFP_KERNEL);
497 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
498
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530499 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +0530500 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530501 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(flowclen,
502 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700503
504 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530505 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530506 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700507 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
508 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
509 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
510 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
511 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
512 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
513 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
514 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
515 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
516 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
517 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530518 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700519 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
520 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +0530521 if (nparams == 9) {
522 u16 pri;
523
524 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
525 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
526 flowc->mnemval[8].val = cpu_to_be32(pri);
527 } else {
528 /* Pad WR to 16 byte boundary */
529 flowc->mnemval[8].mnemonic = 0;
530 flowc->mnemval[8].val = 0;
531 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700532 for (i = 0; i < 9; i++) {
533 flowc->mnemval[i].r4[0] = 0;
534 flowc->mnemval[i].r4[1] = 0;
535 flowc->mnemval[i].r4[2] = 0;
536 }
537
538 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
539 c4iw_ofld_send(&ep->com.dev->rdev, skb);
540}
541
542static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
543{
544 struct cpl_close_con_req *req;
545 struct sk_buff *skb;
546 int wrlen = roundup(sizeof *req, 16);
547
548 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
549 skb = get_skb(NULL, wrlen, gfp);
550 if (!skb) {
551 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
552 return -ENOMEM;
553 }
554 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
555 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
556 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
557 memset(req, 0, wrlen);
558 INIT_TP_WR(req, ep->hwtid);
559 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
560 ep->hwtid));
561 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
562}
563
564static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
565{
566 struct cpl_abort_req *req;
567 int wrlen = roundup(sizeof *req, 16);
568
569 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
570 skb = get_skb(skb, wrlen, gfp);
571 if (!skb) {
572 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
573 __func__);
574 return -ENOMEM;
575 }
576 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
577 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
578 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
579 memset(req, 0, wrlen);
580 INIT_TP_WR(req, ep->hwtid);
581 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
582 req->cmd = CPL_ABORT_SEND_RST;
583 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
584}
585
Steve Wise9eccfe12014-03-26 17:08:09 -0500586/*
587 * c4iw_form_pm_msg - Form a port mapper message with mapping info
588 */
589static void c4iw_form_pm_msg(struct c4iw_ep *ep,
590 struct iwpm_sa_data *pm_msg)
591{
592 memcpy(&pm_msg->loc_addr, &ep->com.local_addr,
593 sizeof(ep->com.local_addr));
594 memcpy(&pm_msg->rem_addr, &ep->com.remote_addr,
595 sizeof(ep->com.remote_addr));
596}
597
598/*
599 * c4iw_form_reg_msg - Form a port mapper message with dev info
600 */
601static void c4iw_form_reg_msg(struct c4iw_dev *dev,
602 struct iwpm_dev_data *pm_msg)
603{
604 memcpy(pm_msg->dev_name, dev->ibdev.name, IWPM_DEVNAME_SIZE);
605 memcpy(pm_msg->if_name, dev->rdev.lldi.ports[0]->name,
606 IWPM_IFNAME_SIZE);
607}
608
609static void c4iw_record_pm_msg(struct c4iw_ep *ep,
610 struct iwpm_sa_data *pm_msg)
611{
612 memcpy(&ep->com.mapped_local_addr, &pm_msg->mapped_loc_addr,
613 sizeof(ep->com.mapped_local_addr));
614 memcpy(&ep->com.mapped_remote_addr, &pm_msg->mapped_rem_addr,
615 sizeof(ep->com.mapped_remote_addr));
616}
617
Steve Wise940fd302015-05-07 16:34:23 -0500618static int get_remote_addr(struct c4iw_ep *parent_ep, struct c4iw_ep *child_ep)
Steve Wise5b6b8fe2015-04-21 16:28:41 -0400619{
620 int ret;
621
Steve Wise940fd302015-05-07 16:34:23 -0500622 print_addr(&parent_ep->com, __func__, "get_remote_addr parent_ep ");
623 print_addr(&child_ep->com, __func__, "get_remote_addr child_ep ");
Steve Wise5b6b8fe2015-04-21 16:28:41 -0400624
Steve Wise940fd302015-05-07 16:34:23 -0500625 ret = iwpm_get_remote_info(&parent_ep->com.mapped_local_addr,
626 &child_ep->com.mapped_remote_addr,
627 &child_ep->com.remote_addr, RDMA_NL_C4IW);
Steve Wise5b6b8fe2015-04-21 16:28:41 -0400628 if (ret)
Steve Wise940fd302015-05-07 16:34:23 -0500629 PDBG("Unable to find remote peer addr info - err %d\n", ret);
Steve Wise5b6b8fe2015-04-21 16:28:41 -0400630
631 return ret;
632}
633
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530634static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530635 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530636{
Hariprasad S04524a42014-09-24 03:53:41 +0530637 unsigned short hdr_size = (ipv6 ?
638 sizeof(struct ipv6hdr) :
639 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530640 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530641 (use_ts ?
642 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530643 unsigned short data_size = mtu - hdr_size;
644
645 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
646}
647
Steve Wisecfdda9d2010-04-21 15:30:06 -0700648static int send_connect(struct c4iw_ep *ep)
649{
Hariprasad S963cab52015-09-23 17:19:27 +0530650 struct cpl_act_open_req *req = NULL;
651 struct cpl_t5_act_open_req *t5req = NULL;
652 struct cpl_t6_act_open_req *t6req = NULL;
653 struct cpl_act_open_req6 *req6 = NULL;
654 struct cpl_t5_act_open_req6 *t5req6 = NULL;
655 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700656 struct sk_buff *skb;
657 u64 opt0;
658 u32 opt2;
659 unsigned int mtu_idx;
660 int wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530661 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500662 struct sockaddr_in *la = (struct sockaddr_in *)
663 &ep->com.mapped_local_addr;
664 struct sockaddr_in *ra = (struct sockaddr_in *)
665 &ep->com.mapped_remote_addr;
666 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
667 &ep->com.mapped_local_addr;
668 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
669 &ep->com.mapped_remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530670 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530671 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
672 u32 isn = (prandom_u32() & ~7UL) - 1;
673
674 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
675 case CHELSIO_T4:
676 sizev4 = sizeof(struct cpl_act_open_req);
677 sizev6 = sizeof(struct cpl_act_open_req6);
678 break;
679 case CHELSIO_T5:
680 sizev4 = sizeof(struct cpl_t5_act_open_req);
681 sizev6 = sizeof(struct cpl_t5_act_open_req6);
682 break;
683 case CHELSIO_T6:
684 sizev4 = sizeof(struct cpl_t6_act_open_req);
685 sizev6 = sizeof(struct cpl_t6_act_open_req6);
686 break;
687 default:
688 pr_err("T%d Chip is not supported\n",
689 CHELSIO_CHIP_VERSION(adapter_type));
690 return -EINVAL;
691 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530692
693 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
694 roundup(sizev4, 16) :
695 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700696
697 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
698
699 skb = get_skb(NULL, wrlen, GFP_KERNEL);
700 if (!skb) {
701 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
702 __func__);
703 return -ENOMEM;
704 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000705 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700706
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530707 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530708 enable_tcp_timestamps,
709 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700710 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530711
712 /*
713 * Specify the largest window that will fit in opt0. The
714 * remainder will be specified in the rx_data_ack.
715 */
716 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800717 if (win > RCV_BUFSIZ_M)
718 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530719
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800720 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800721 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800722 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800723 WND_SCALE_V(wscale) |
724 MSS_IDX_V(mtu_idx) |
725 L2T_IDX_V(ep->l2t->idx) |
726 TX_CHAN_V(ep->tx_chan) |
727 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +0530728 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800729 ULP_MODE_V(ULP_MODE_TCPDDP) |
730 RCV_BUFSIZ_V(win);
731 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800732 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800733 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700734 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800735 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700736 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800737 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700738 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800739 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530740 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
741 if (peer2peer)
742 isn += 4;
743
Anish Bhattd7990b02014-11-12 17:15:57 -0800744 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530745 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530746 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500747 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530748
749 if (ep->com.remote_addr.ss_family == AF_INET6)
750 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
751 (const u32 *)&la6->sin6_addr.s6_addr, 1);
752
Hariprasad S5dab6d32014-06-23 19:12:36 +0530753 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700754
Hariprasad S963cab52015-09-23 17:19:27 +0530755 if (ep->com.remote_addr.ss_family == AF_INET) {
756 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
757 case CHELSIO_T4:
758 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530759 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530760 break;
761 case CHELSIO_T5:
762 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
763 wrlen);
764 INIT_TP_WR(t5req, 0);
765 req = (struct cpl_act_open_req *)t5req;
766 break;
767 case CHELSIO_T6:
768 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
769 wrlen);
770 INIT_TP_WR(t6req, 0);
771 req = (struct cpl_act_open_req *)t6req;
772 t5req = (struct cpl_t5_act_open_req *)t6req;
773 break;
774 default:
775 pr_err("T%d Chip is not supported\n",
776 CHELSIO_CHIP_VERSION(adapter_type));
777 ret = -EINVAL;
778 goto clip_release;
779 }
780
781 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
782 ((ep->rss_qid<<14) | ep->atid)));
783 req->local_port = la->sin_port;
784 req->peer_port = ra->sin_port;
785 req->local_ip = la->sin_addr.s_addr;
786 req->peer_ip = ra->sin_addr.s_addr;
787 req->opt0 = cpu_to_be64(opt0);
788
789 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530790 req->params = cpu_to_be32(cxgb4_select_ntuple(
791 ep->com.dev->rdev.lldi.ports[0],
792 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530793 req->opt2 = cpu_to_be32(opt2);
794 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530795 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
796 cxgb4_select_ntuple(
797 ep->com.dev->rdev.lldi.ports[0],
798 ep->l2t)));
799 t5req->rsvd = cpu_to_be32(isn);
800 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
801 t5req->opt2 = cpu_to_be32(opt2);
802 }
803 } else {
804 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
805 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530806 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530807 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530808 break;
809 case CHELSIO_T5:
810 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
811 wrlen);
812 INIT_TP_WR(t5req6, 0);
813 req6 = (struct cpl_act_open_req6 *)t5req6;
814 break;
815 case CHELSIO_T6:
816 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
817 wrlen);
818 INIT_TP_WR(t6req6, 0);
819 req6 = (struct cpl_act_open_req6 *)t6req6;
820 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
821 break;
822 default:
823 pr_err("T%d Chip is not supported\n",
824 CHELSIO_CHIP_VERSION(adapter_type));
825 ret = -EINVAL;
826 goto clip_release;
827 }
828
829 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
830 ((ep->rss_qid<<14)|ep->atid)));
831 req6->local_port = la6->sin6_port;
832 req6->peer_port = ra6->sin6_port;
833 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
834 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
835 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
836 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
837 req6->opt0 = cpu_to_be64(opt0);
838
839 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530840 req6->params = cpu_to_be32(cxgb4_select_ntuple(
841 ep->com.dev->rdev.lldi.ports[0],
842 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530843 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530844 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530845 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
846 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530847 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530848 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530849 t5req6->rsvd = cpu_to_be32(isn);
850 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
851 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530852 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000853 }
854
Vipul Pandya793dad92012-12-10 09:30:56 +0000855 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530856 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530857clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530858 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
859 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
860 (const u32 *)&la6->sin6_addr.s6_addr, 1);
861 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700862}
863
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530864static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
865 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700866{
867 int mpalen, wrlen;
868 struct fw_ofld_tx_data_wr *req;
869 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530870 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700871
872 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
873
874 BUG_ON(skb_cloned(skb));
875
876 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530877 if (mpa_rev_to_use == 2)
878 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700879 wrlen = roundup(mpalen + sizeof *req, 16);
880 skb = get_skb(skb, wrlen, GFP_KERNEL);
881 if (!skb) {
882 connect_reply_upcall(ep, -ENOMEM);
883 return;
884 }
885 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
886
887 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
888 memset(req, 0, wrlen);
889 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530890 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
891 FW_WR_COMPL_F |
892 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700893 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530894 FW_WR_FLOWID_V(ep->hwtid) |
895 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700896 req->plen = cpu_to_be32(mpalen);
897 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530898 FW_OFLD_TX_DATA_WR_FLUSH_F |
899 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700900
901 mpa = (struct mpa_message *)(req + 1);
902 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
903 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530904 (markers_enabled ? MPA_MARKERS : 0) |
905 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700906 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530907 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530908 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530909 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530910 ep->retry_with_mpa_v1 = 0;
911 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700912
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530913 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700914 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
915 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530916 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
917 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530918 mpa_v2_params.ird = htons((u16)ep->ird);
919 mpa_v2_params.ord = htons((u16)ep->ord);
920
921 if (peer2peer) {
922 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
923 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
924 mpa_v2_params.ord |=
925 htons(MPA_V2_RDMA_WRITE_RTR);
926 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
927 mpa_v2_params.ord |=
928 htons(MPA_V2_RDMA_READ_RTR);
929 }
930 memcpy(mpa->private_data, &mpa_v2_params,
931 sizeof(struct mpa_v2_conn_params));
932
933 if (ep->plen)
934 memcpy(mpa->private_data +
935 sizeof(struct mpa_v2_conn_params),
936 ep->mpa_pkt + sizeof(*mpa), ep->plen);
937 } else
938 if (ep->plen)
939 memcpy(mpa->private_data,
940 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700941
942 /*
943 * Reference the mpa skb. This ensures the data area
944 * will remain in memory until the hw acks the tx.
945 * Function fw4_ack() will deref it.
946 */
947 skb_get(skb);
948 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
949 BUG_ON(ep->mpa_skb);
950 ep->mpa_skb = skb;
951 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
952 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530953 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700954 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530955 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700956 return;
957}
958
959static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
960{
961 int mpalen, wrlen;
962 struct fw_ofld_tx_data_wr *req;
963 struct mpa_message *mpa;
964 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530965 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700966
967 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
968
969 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530970 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
971 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700972 wrlen = roundup(mpalen + sizeof *req, 16);
973
974 skb = get_skb(NULL, wrlen, GFP_KERNEL);
975 if (!skb) {
976 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
977 return -ENOMEM;
978 }
979 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
980
981 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
982 memset(req, 0, wrlen);
983 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530984 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
985 FW_WR_COMPL_F |
986 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700987 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530988 FW_WR_FLOWID_V(ep->hwtid) |
989 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700990 req->plen = cpu_to_be32(mpalen);
991 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530992 FW_OFLD_TX_DATA_WR_FLUSH_F |
993 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700994
995 mpa = (struct mpa_message *)(req + 1);
996 memset(mpa, 0, sizeof(*mpa));
997 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
998 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000999 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001000 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301001
1002 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1003 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001004 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1005 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301006 mpa_v2_params.ird = htons(((u16)ep->ird) |
1007 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1008 0));
1009 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1010 (p2p_type ==
1011 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1012 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1013 FW_RI_INIT_P2PTYPE_READ_REQ ?
1014 MPA_V2_RDMA_READ_RTR : 0) : 0));
1015 memcpy(mpa->private_data, &mpa_v2_params,
1016 sizeof(struct mpa_v2_conn_params));
1017
1018 if (ep->plen)
1019 memcpy(mpa->private_data +
1020 sizeof(struct mpa_v2_conn_params), pdata, plen);
1021 } else
1022 if (plen)
1023 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001024
1025 /*
1026 * Reference the mpa skb again. This ensures the data area
1027 * will remain in memory until the hw acks the tx.
1028 * Function fw4_ack() will deref it.
1029 */
1030 skb_get(skb);
1031 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1032 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1033 BUG_ON(ep->mpa_skb);
1034 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301035 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001036 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1037}
1038
1039static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1040{
1041 int mpalen, wrlen;
1042 struct fw_ofld_tx_data_wr *req;
1043 struct mpa_message *mpa;
1044 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301045 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001046
1047 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1048
1049 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301050 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1051 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001052 wrlen = roundup(mpalen + sizeof *req, 16);
1053
1054 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1055 if (!skb) {
1056 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1057 return -ENOMEM;
1058 }
1059 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1060
1061 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1062 memset(req, 0, wrlen);
1063 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301064 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1065 FW_WR_COMPL_F |
1066 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001067 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301068 FW_WR_FLOWID_V(ep->hwtid) |
1069 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001070 req->plen = cpu_to_be32(mpalen);
1071 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301072 FW_OFLD_TX_DATA_WR_FLUSH_F |
1073 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001074
1075 mpa = (struct mpa_message *)(req + 1);
1076 memset(mpa, 0, sizeof(*mpa));
1077 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1078 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
1079 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301080 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001081 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301082
1083 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1084 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001085 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1086 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301087 mpa_v2_params.ird = htons((u16)ep->ird);
1088 mpa_v2_params.ord = htons((u16)ep->ord);
1089 if (peer2peer && (ep->mpa_attr.p2p_type !=
1090 FW_RI_INIT_P2PTYPE_DISABLED)) {
1091 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1092
1093 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1094 mpa_v2_params.ord |=
1095 htons(MPA_V2_RDMA_WRITE_RTR);
1096 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1097 mpa_v2_params.ord |=
1098 htons(MPA_V2_RDMA_READ_RTR);
1099 }
1100
1101 memcpy(mpa->private_data, &mpa_v2_params,
1102 sizeof(struct mpa_v2_conn_params));
1103
1104 if (ep->plen)
1105 memcpy(mpa->private_data +
1106 sizeof(struct mpa_v2_conn_params), pdata, plen);
1107 } else
1108 if (plen)
1109 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001110
1111 /*
1112 * Reference the mpa skb. This ensures the data area
1113 * will remain in memory until the hw acks the tx.
1114 * Function fw4_ack() will deref it.
1115 */
1116 skb_get(skb);
1117 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1118 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301119 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301120 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001121 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1122}
1123
1124static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1125{
1126 struct c4iw_ep *ep;
1127 struct cpl_act_establish *req = cplhdr(skb);
1128 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001129 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001130 struct tid_info *t = dev->rdev.lldi.tids;
1131
1132 ep = lookup_atid(t, atid);
1133
1134 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1135 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1136
Steve Wisea7db89e2014-03-21 20:40:35 +05301137 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001138 dst_confirm(ep->dst);
1139
1140 /* setup the hwtid for this connection */
1141 ep->hwtid = tid;
1142 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001143 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001144
1145 ep->snd_seq = be32_to_cpu(req->snd_isn);
1146 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1147
1148 set_emss(ep, ntohs(req->tcp_opt));
1149
1150 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001151 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001152 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001153 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001154
1155 /* start MPA negotiation */
1156 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301157 if (ep->retry_with_mpa_v1)
1158 send_mpa_req(ep, skb, 1);
1159 else
1160 send_mpa_req(ep, skb, mpa_rev);
Steve Wisea7db89e2014-03-21 20:40:35 +05301161 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001162 return 0;
1163}
1164
Steve Wisebe13b2d2014-03-21 20:40:33 +05301165static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001166{
1167 struct iw_cm_event event;
1168
1169 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1170 memset(&event, 0, sizeof(event));
1171 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301172 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001173 if (ep->com.cm_id) {
1174 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1175 ep, ep->com.cm_id, ep->hwtid);
1176 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1177 ep->com.cm_id->rem_ref(ep->com.cm_id);
1178 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001179 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001180 }
1181}
1182
1183static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
1184{
1185 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecc18b932014-04-24 14:31:53 -05001186 __state_set(&ep->com, ABORTING);
Vipul Pandya793dad92012-12-10 09:30:56 +00001187 set_bit(ABORT_CONN, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001188 return send_abort(ep, skb, gfp);
1189}
1190
1191static void peer_close_upcall(struct c4iw_ep *ep)
1192{
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_DISCONNECT;
1198 if (ep->com.cm_id) {
1199 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1200 ep, ep->com.cm_id, ep->hwtid);
1201 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001202 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001203 }
1204}
1205
1206static void peer_abort_upcall(struct c4iw_ep *ep)
1207{
1208 struct iw_cm_event event;
1209
1210 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1211 memset(&event, 0, sizeof(event));
1212 event.event = IW_CM_EVENT_CLOSE;
1213 event.status = -ECONNRESET;
1214 if (ep->com.cm_id) {
1215 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1216 ep->com.cm_id, ep->hwtid);
1217 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1218 ep->com.cm_id->rem_ref(ep->com.cm_id);
1219 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001220 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001221 }
1222}
1223
1224static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1225{
1226 struct iw_cm_event event;
1227
1228 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1229 memset(&event, 0, sizeof(event));
1230 event.event = IW_CM_EVENT_CONNECT_REPLY;
1231 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301232 memcpy(&event.local_addr, &ep->com.local_addr,
1233 sizeof(ep->com.local_addr));
1234 memcpy(&event.remote_addr, &ep->com.remote_addr,
1235 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001236
1237 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301238 if (!ep->tried_with_mpa_v1) {
1239 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301240 event.ord = ep->ird;
1241 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301242 event.private_data_len = ep->plen -
1243 sizeof(struct mpa_v2_conn_params);
1244 event.private_data = ep->mpa_pkt +
1245 sizeof(struct mpa_message) +
1246 sizeof(struct mpa_v2_conn_params);
1247 } else {
1248 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301249 event.ord = cur_max_read_depth(ep->com.dev);
1250 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301251 event.private_data_len = ep->plen;
1252 event.private_data = ep->mpa_pkt +
1253 sizeof(struct mpa_message);
1254 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001255 }
Roland Dreier85963e42010-07-19 13:13:09 -07001256
1257 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1258 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001259 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001260 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1261
Steve Wisecfdda9d2010-04-21 15:30:06 -07001262 if (status < 0) {
1263 ep->com.cm_id->rem_ref(ep->com.cm_id);
1264 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001265 }
1266}
1267
Steve Wisebe13b2d2014-03-21 20:40:33 +05301268static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001269{
1270 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301271 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001272
1273 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1274 memset(&event, 0, sizeof(event));
1275 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301276 memcpy(&event.local_addr, &ep->com.local_addr,
1277 sizeof(ep->com.local_addr));
1278 memcpy(&event.remote_addr, &ep->com.remote_addr,
1279 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001280 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301281 if (!ep->tried_with_mpa_v1) {
1282 /* this means MPA_v2 is used */
1283 event.ord = ep->ord;
1284 event.ird = ep->ird;
1285 event.private_data_len = ep->plen -
1286 sizeof(struct mpa_v2_conn_params);
1287 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1288 sizeof(struct mpa_v2_conn_params);
1289 } else {
1290 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301291 event.ord = cur_max_read_depth(ep->com.dev);
1292 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301293 event.private_data_len = ep->plen;
1294 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1295 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301296 c4iw_get_ep(&ep->com);
1297 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1298 &event);
1299 if (ret)
1300 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001301 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001302 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301303 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001304}
1305
1306static void established_upcall(struct c4iw_ep *ep)
1307{
1308 struct iw_cm_event event;
1309
1310 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1311 memset(&event, 0, sizeof(event));
1312 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301313 event.ird = ep->ord;
1314 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001315 if (ep->com.cm_id) {
1316 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1317 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001318 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001319 }
1320}
1321
1322static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1323{
1324 struct cpl_rx_data_ack *req;
1325 struct sk_buff *skb;
1326 int wrlen = roundup(sizeof *req, 16);
1327
1328 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1329 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1330 if (!skb) {
1331 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1332 return 0;
1333 }
1334
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301335 /*
1336 * If we couldn't specify the entire rcv window at connection setup
1337 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1338 * then add the overage in to the credits returned.
1339 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001340 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1341 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301342
Steve Wisecfdda9d2010-04-21 15:30:06 -07001343 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1344 memset(req, 0, wrlen);
1345 INIT_TP_WR(req, ep->hwtid);
1346 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1347 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001348 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301349 RX_DACK_CHANGE_F |
1350 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001351 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001352 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1353 return credits;
1354}
1355
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301356#define RELAXED_IRD_NEGOTIATION 1
1357
Steve Wisecc18b932014-04-24 14:31:53 -05001358static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001359{
1360 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301361 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001362 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301363 u16 resp_ird, resp_ord;
1364 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001365 struct c4iw_qp_attributes attrs;
1366 enum c4iw_qp_attr_mask mask;
1367 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001368 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001369
1370 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1371
1372 /*
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001373 * Stop mpa timer. If it expired, then
1374 * we ignore the MPA reply. process_timeout()
1375 * will abort the connection.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001376 */
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001377 if (stop_ep_timer(ep))
Steve Wisecc18b932014-04-24 14:31:53 -05001378 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001379
1380 /*
1381 * If we get more than the supported amount of private data
1382 * then we must fail this connection.
1383 */
1384 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1385 err = -EINVAL;
1386 goto err;
1387 }
1388
1389 /*
1390 * copy the new data into our accumulation buffer.
1391 */
1392 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1393 skb->len);
1394 ep->mpa_pkt_len += skb->len;
1395
1396 /*
1397 * if we don't even have the mpa message, then bail.
1398 */
1399 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001400 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001401 mpa = (struct mpa_message *) ep->mpa_pkt;
1402
1403 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301404 if (mpa->revision > mpa_rev) {
1405 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1406 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001407 err = -EPROTO;
1408 goto err;
1409 }
1410 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1411 err = -EPROTO;
1412 goto err;
1413 }
1414
1415 plen = ntohs(mpa->private_data_size);
1416
1417 /*
1418 * Fail if there's too much private data.
1419 */
1420 if (plen > MPA_MAX_PRIVATE_DATA) {
1421 err = -EPROTO;
1422 goto err;
1423 }
1424
1425 /*
1426 * If plen does not account for pkt size
1427 */
1428 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1429 err = -EPROTO;
1430 goto err;
1431 }
1432
1433 ep->plen = (u8) plen;
1434
1435 /*
1436 * If we don't have all the pdata yet, then bail.
1437 * We'll continue process when more data arrives.
1438 */
1439 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001440 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001441
1442 if (mpa->flags & MPA_REJECT) {
1443 err = -ECONNREFUSED;
1444 goto err;
1445 }
1446
1447 /*
1448 * If we get here we have accumulated the entire mpa
1449 * start reply message including private data. And
1450 * the MPA header is valid.
1451 */
Steve Wisec529fb52014-03-21 20:40:37 +05301452 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001453 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1454 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1455 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301456 ep->mpa_attr.version = mpa->revision;
1457 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1458
1459 if (mpa->revision == 2) {
1460 ep->mpa_attr.enhanced_rdma_conn =
1461 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1462 if (ep->mpa_attr.enhanced_rdma_conn) {
1463 mpa_v2_params = (struct mpa_v2_conn_params *)
1464 (ep->mpa_pkt + sizeof(*mpa));
1465 resp_ird = ntohs(mpa_v2_params->ird) &
1466 MPA_V2_IRD_ORD_MASK;
1467 resp_ord = ntohs(mpa_v2_params->ord) &
1468 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301469 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1470 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301471
1472 /*
1473 * This is a double-check. Ideally, below checks are
1474 * not required since ird/ord stuff has been taken
1475 * care of in c4iw_accept_cr
1476 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301477 if (ep->ird < resp_ord) {
1478 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1479 ep->com.dev->rdev.lldi.max_ordird_qp)
1480 ep->ird = resp_ord;
1481 else
1482 insuff_ird = 1;
1483 } else if (ep->ird > resp_ord) {
1484 ep->ird = resp_ord;
1485 }
1486 if (ep->ord > resp_ird) {
1487 if (RELAXED_IRD_NEGOTIATION)
1488 ep->ord = resp_ird;
1489 else
1490 insuff_ird = 1;
1491 }
1492 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301493 err = -ENOMEM;
1494 ep->ird = resp_ord;
1495 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301496 }
1497
1498 if (ntohs(mpa_v2_params->ird) &
1499 MPA_V2_PEER2PEER_MODEL) {
1500 if (ntohs(mpa_v2_params->ord) &
1501 MPA_V2_RDMA_WRITE_RTR)
1502 ep->mpa_attr.p2p_type =
1503 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1504 else if (ntohs(mpa_v2_params->ord) &
1505 MPA_V2_RDMA_READ_RTR)
1506 ep->mpa_attr.p2p_type =
1507 FW_RI_INIT_P2PTYPE_READ_REQ;
1508 }
1509 }
1510 } else if (mpa->revision == 1)
1511 if (peer2peer)
1512 ep->mpa_attr.p2p_type = p2p_type;
1513
Steve Wisecfdda9d2010-04-21 15:30:06 -07001514 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301515 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1516 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1517 ep->mpa_attr.recv_marker_enabled,
1518 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1519 ep->mpa_attr.p2p_type, p2p_type);
1520
1521 /*
1522 * If responder's RTR does not match with that of initiator, assign
1523 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1524 * generated when moving QP to RTS state.
1525 * A TERM message will be sent after QP has moved to RTS state
1526 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001527 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301528 (ep->mpa_attr.p2p_type != p2p_type)) {
1529 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1530 rtr_mismatch = 1;
1531 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001532
1533 attrs.mpa_attr = ep->mpa_attr;
1534 attrs.max_ird = ep->ird;
1535 attrs.max_ord = ep->ord;
1536 attrs.llp_stream_handle = ep;
1537 attrs.next_state = C4IW_QP_STATE_RTS;
1538
1539 mask = C4IW_QP_ATTR_NEXT_STATE |
1540 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1541 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1542
1543 /* bind QP and TID with INIT_WR */
1544 err = c4iw_modify_qp(ep->com.qp->rhp,
1545 ep->com.qp, mask, &attrs, 1);
1546 if (err)
1547 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301548
1549 /*
1550 * If responder's RTR requirement did not match with what initiator
1551 * supports, generate TERM message
1552 */
1553 if (rtr_mismatch) {
1554 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1555 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1556 attrs.ecode = MPA_NOMATCH_RTR;
1557 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001558 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301559 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001560 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301561 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001562 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301563 goto out;
1564 }
1565
1566 /*
1567 * Generate TERM if initiator IRD is not sufficient for responder
1568 * provided ORD. Currently, we do the same behaviour even when
1569 * responder provided IRD is also not sufficient as regards to
1570 * initiator ORD.
1571 */
1572 if (insuff_ird) {
1573 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1574 __func__);
1575 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1576 attrs.ecode = MPA_INSUFF_IRD;
1577 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001578 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301579 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001580 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301581 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001582 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301583 goto out;
1584 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001585 goto out;
1586err:
Steve Wisec529fb52014-03-21 20:40:37 +05301587 __state_set(&ep->com, ABORTING);
Steve Wiseb21ef162010-06-10 19:02:55 +00001588 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001589out:
1590 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001591 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001592}
1593
1594static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1595{
1596 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301597 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001598 u16 plen;
1599
1600 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1601
Steve Wisecfdda9d2010-04-21 15:30:06 -07001602 /*
1603 * If we get more than the supported amount of private data
1604 * then we must fail this connection.
1605 */
1606 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001607 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001608 abort_connection(ep, skb, GFP_KERNEL);
1609 return;
1610 }
1611
1612 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1613
1614 /*
1615 * Copy the new data into our accumulation buffer.
1616 */
1617 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1618 skb->len);
1619 ep->mpa_pkt_len += skb->len;
1620
1621 /*
1622 * If we don't even have the mpa message, then bail.
1623 * We'll continue process when more data arrives.
1624 */
1625 if (ep->mpa_pkt_len < sizeof(*mpa))
1626 return;
1627
1628 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001629 mpa = (struct mpa_message *) ep->mpa_pkt;
1630
1631 /*
1632 * Validate MPA Header.
1633 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301634 if (mpa->revision > mpa_rev) {
1635 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1636 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001637 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001638 abort_connection(ep, skb, GFP_KERNEL);
1639 return;
1640 }
1641
1642 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001643 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001644 abort_connection(ep, skb, GFP_KERNEL);
1645 return;
1646 }
1647
1648 plen = ntohs(mpa->private_data_size);
1649
1650 /*
1651 * Fail if there's too much private data.
1652 */
1653 if (plen > MPA_MAX_PRIVATE_DATA) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001654 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001655 abort_connection(ep, skb, GFP_KERNEL);
1656 return;
1657 }
1658
1659 /*
1660 * If plen does not account for pkt size
1661 */
1662 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001663 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001664 abort_connection(ep, skb, GFP_KERNEL);
1665 return;
1666 }
1667 ep->plen = (u8) plen;
1668
1669 /*
1670 * If we don't have all the pdata yet, then bail.
1671 */
1672 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1673 return;
1674
1675 /*
1676 * If we get here we have accumulated the entire mpa
1677 * start reply message including private data.
1678 */
1679 ep->mpa_attr.initiator = 0;
1680 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1681 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1682 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301683 ep->mpa_attr.version = mpa->revision;
1684 if (mpa->revision == 1)
1685 ep->tried_with_mpa_v1 = 1;
1686 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1687
1688 if (mpa->revision == 2) {
1689 ep->mpa_attr.enhanced_rdma_conn =
1690 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1691 if (ep->mpa_attr.enhanced_rdma_conn) {
1692 mpa_v2_params = (struct mpa_v2_conn_params *)
1693 (ep->mpa_pkt + sizeof(*mpa));
1694 ep->ird = ntohs(mpa_v2_params->ird) &
1695 MPA_V2_IRD_ORD_MASK;
1696 ep->ord = ntohs(mpa_v2_params->ord) &
1697 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301698 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1699 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301700 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1701 if (peer2peer) {
1702 if (ntohs(mpa_v2_params->ord) &
1703 MPA_V2_RDMA_WRITE_RTR)
1704 ep->mpa_attr.p2p_type =
1705 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1706 else if (ntohs(mpa_v2_params->ord) &
1707 MPA_V2_RDMA_READ_RTR)
1708 ep->mpa_attr.p2p_type =
1709 FW_RI_INIT_P2PTYPE_READ_REQ;
1710 }
1711 }
1712 } else if (mpa->revision == 1)
1713 if (peer2peer)
1714 ep->mpa_attr.p2p_type = p2p_type;
1715
Steve Wisecfdda9d2010-04-21 15:30:06 -07001716 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1717 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1718 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1719 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1720 ep->mpa_attr.p2p_type);
1721
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001722 /*
1723 * If the endpoint timer already expired, then we ignore
1724 * the start request. process_timeout() will abort
1725 * the connection.
1726 */
1727 if (!stop_ep_timer(ep)) {
1728 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001729
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001730 /* drive upcall */
Hariprasad Shenai10be6b42014-11-21 09:36:35 -06001731 mutex_lock_nested(&ep->parent_ep->com.mutex,
1732 SINGLE_DEPTH_NESTING);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001733 if (ep->parent_ep->com.state != DEAD) {
1734 if (connect_request_upcall(ep))
1735 abort_connection(ep, skb, GFP_KERNEL);
1736 } else {
Steve Wisebe13b2d2014-03-21 20:40:33 +05301737 abort_connection(ep, skb, GFP_KERNEL);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001738 }
1739 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301740 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001741 return;
1742}
1743
1744static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1745{
1746 struct c4iw_ep *ep;
1747 struct cpl_rx_data *hdr = cplhdr(skb);
1748 unsigned int dlen = ntohs(hdr->len);
1749 unsigned int tid = GET_TID(hdr);
1750 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001751 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001752 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001753
1754 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301755 if (!ep)
1756 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001757 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1758 skb_pull(skb, sizeof(*hdr));
1759 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301760 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001761
Steve Wisecfdda9d2010-04-21 15:30:06 -07001762 /* update RX credits */
1763 update_rx_credits(ep, dlen);
1764
Steve Wisec529fb52014-03-21 20:40:37 +05301765 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001766 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001767 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001768 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001769 break;
1770 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001771 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001772 process_mpa_request(ep, skb);
1773 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001774 case FPDU_MODE: {
1775 struct c4iw_qp_attributes attrs;
1776 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001777 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001778 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001779 " qpid %u ep %p state %d tid %u status %d\n",
1780 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301781 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301782 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001783 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001784 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1785 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001786 break;
1787 }
Vipul Pandya15579672013-01-07 13:11:52 +00001788 default:
1789 break;
1790 }
Steve Wisec529fb52014-03-21 20:40:37 +05301791 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001792 if (disconnect)
1793 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001794 return 0;
1795}
1796
1797static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1798{
1799 struct c4iw_ep *ep;
1800 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001801 int release = 0;
1802 unsigned int tid = GET_TID(rpl);
1803 struct tid_info *t = dev->rdev.lldi.tids;
1804
1805 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301806 if (!ep) {
1807 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1808 return 0;
1809 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001810 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001811 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001812 switch (ep->com.state) {
1813 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001814 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001815 __state_set(&ep->com, DEAD);
1816 release = 1;
1817 break;
1818 default:
1819 printk(KERN_ERR "%s ep %p state %d\n",
1820 __func__, ep, ep->com.state);
1821 break;
1822 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001823 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001824
1825 if (release)
1826 release_ep_resources(ep);
1827 return 0;
1828}
1829
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001830static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1831{
1832 struct sk_buff *skb;
1833 struct fw_ofld_connection_wr *req;
1834 unsigned int mtu_idx;
1835 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301836 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301837 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001838
1839 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1840 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1841 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001842 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301843 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301844 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1845 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001846 ep->l2t));
Steve Wise9eccfe12014-03-26 17:08:09 -05001847 sin = (struct sockaddr_in *)&ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301848 req->le.lport = sin->sin_port;
1849 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05001850 sin = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301851 req->le.pport = sin->sin_port;
1852 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001853 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301854 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1855 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001856 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301857 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001858 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001859 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301860 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301861 enable_tcp_timestamps,
1862 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001863 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301864
1865 /*
1866 * Specify the largest window that will fit in opt0. The
1867 * remainder will be specified in the rx_data_ack.
1868 */
1869 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001870 if (win > RCV_BUFSIZ_M)
1871 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301872
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001873 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1874 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001875 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001876 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001877 WND_SCALE_V(wscale) |
1878 MSS_IDX_V(mtu_idx) |
1879 L2T_IDX_V(ep->l2t->idx) |
1880 TX_CHAN_V(ep->tx_chan) |
1881 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +05301882 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001883 ULP_MODE_V(ULP_MODE_TCPDDP) |
1884 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001885 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1886 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001887 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001888 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001889 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001890 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001891 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001892 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001893 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001894 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001895 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1896 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1897 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001898 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1899 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001900 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1901}
1902
Steve Wisecfdda9d2010-04-21 15:30:06 -07001903/*
1904 * Return whether a failed active open has allocated a TID
1905 */
1906static inline int act_open_has_tid(int status)
1907{
1908 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1909 status != CPL_ERR_ARP_MISS;
1910}
1911
Steve Wise7a2cea22014-03-14 21:52:07 +05301912/* Returns whether a CPL status conveys negative advice.
1913 */
1914static int is_neg_adv(unsigned int status)
1915{
1916 return status == CPL_ERR_RTX_NEG_ADVICE ||
1917 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1918 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1919}
1920
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301921static char *neg_adv_str(unsigned int status)
1922{
1923 switch (status) {
1924 case CPL_ERR_RTX_NEG_ADVICE:
1925 return "Retransmit timeout";
1926 case CPL_ERR_PERSIST_NEG_ADVICE:
1927 return "Persist timeout";
1928 case CPL_ERR_KEEPALV_NEG_ADVICE:
1929 return "Keepalive timeout";
1930 default:
1931 return "Unknown";
1932 }
1933}
1934
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301935static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1936{
1937 ep->snd_win = snd_win;
1938 ep->rcv_win = rcv_win;
1939 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1940}
1941
Vipul Pandya793dad92012-12-10 09:30:56 +00001942#define ACT_OPEN_RETRY_COUNT 2
1943
Vipul Pandya830662f2013-07-04 16:10:47 +05301944static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1945 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +05301946 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05301947{
1948 struct neighbour *n;
1949 int err, step;
1950 struct net_device *pdev;
1951
1952 n = dst_neigh_lookup(dst, peer_ip);
1953 if (!n)
1954 return -ENODEV;
1955
1956 rcu_read_lock();
1957 err = -ENOMEM;
1958 if (n->dev->flags & IFF_LOOPBACK) {
1959 if (iptype == 4)
1960 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1961 else if (IS_ENABLED(CONFIG_IPV6))
1962 for_each_netdev(&init_net, pdev) {
1963 if (ipv6_chk_addr(&init_net,
1964 (struct in6_addr *)peer_ip,
1965 pdev, 1))
1966 break;
1967 }
1968 else
1969 pdev = NULL;
1970
1971 if (!pdev) {
1972 err = -ENODEV;
1973 goto out;
1974 }
1975 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +05301976 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05301977 if (!ep->l2t)
1978 goto out;
1979 ep->mtu = pdev->mtu;
1980 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05301981 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
1982 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301983 step = cdev->rdev.lldi.ntxq /
1984 cdev->rdev.lldi.nchan;
1985 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1986 step = cdev->rdev.lldi.nrxq /
1987 cdev->rdev.lldi.nchan;
1988 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1989 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1990 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301991 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301992 dev_put(pdev);
1993 } else {
1994 pdev = get_real_dev(n->dev);
1995 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1996 n, pdev, 0);
1997 if (!ep->l2t)
1998 goto out;
1999 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002000 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302001 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2002 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302003 step = cdev->rdev.lldi.ntxq /
2004 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002005 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2006 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302007 step = cdev->rdev.lldi.nrxq /
2008 cdev->rdev.lldi.nchan;
2009 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002010 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302011 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302012
2013 if (clear_mpa_v1) {
2014 ep->retry_with_mpa_v1 = 0;
2015 ep->tried_with_mpa_v1 = 0;
2016 }
2017 }
2018 err = 0;
2019out:
2020 rcu_read_unlock();
2021
2022 neigh_release(n);
2023
2024 return err;
2025}
2026
Vipul Pandya793dad92012-12-10 09:30:56 +00002027static int c4iw_reconnect(struct c4iw_ep *ep)
2028{
2029 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302030 struct sockaddr_in *laddr = (struct sockaddr_in *)
2031 &ep->com.cm_id->local_addr;
2032 struct sockaddr_in *raddr = (struct sockaddr_in *)
2033 &ep->com.cm_id->remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302034 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
2035 &ep->com.cm_id->local_addr;
2036 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
2037 &ep->com.cm_id->remote_addr;
2038 int iptype;
2039 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002040
2041 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2042 init_timer(&ep->timer);
2043
2044 /*
2045 * Allocate an active TID to initiate a TCP connection.
2046 */
2047 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2048 if (ep->atid == -1) {
2049 pr_err("%s - cannot alloc atid.\n", __func__);
2050 err = -ENOMEM;
2051 goto fail2;
2052 }
2053 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2054
2055 /* find a route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302056 if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
2057 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2058 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +05302059 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302060 iptype = 4;
2061 ra = (__u8 *)&raddr->sin_addr;
2062 } else {
2063 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2064 raddr6->sin6_addr.s6_addr,
2065 laddr6->sin6_port, raddr6->sin6_port, 0,
2066 raddr6->sin6_scope_id);
2067 iptype = 6;
2068 ra = (__u8 *)&raddr6->sin6_addr;
2069 }
2070 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002071 pr_err("%s - cannot find route.\n", __func__);
2072 err = -EHOSTUNREACH;
2073 goto fail3;
2074 }
Hariprasad S963cab52015-09-23 17:19:27 +05302075 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +05302076 ep->com.dev->rdev.lldi.adapter_type,
2077 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302078 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002079 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002080 goto fail4;
2081 }
2082
2083 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2084 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2085 ep->l2t->idx);
2086
2087 state_set(&ep->com, CONNECTING);
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +05302088 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002089
2090 /* send connect request to rnic */
2091 err = send_connect(ep);
2092 if (!err)
2093 goto out;
2094
2095 cxgb4_l2t_release(ep->l2t);
2096fail4:
2097 dst_release(ep->dst);
2098fail3:
2099 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2100 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2101fail2:
2102 /*
2103 * remember to send notification to upper layer.
2104 * We are in here so the upper layer is not aware that this is
2105 * re-connect attempt and so, upper layer is still waiting for
2106 * response of 1st connect request.
2107 */
2108 connect_reply_upcall(ep, -ECONNRESET);
2109 c4iw_put_ep(&ep->com);
2110out:
2111 return err;
2112}
2113
Steve Wisecfdda9d2010-04-21 15:30:06 -07002114static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2115{
2116 struct c4iw_ep *ep;
2117 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002118 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2119 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002120 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002121 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302122 struct sockaddr_in *la;
2123 struct sockaddr_in *ra;
2124 struct sockaddr_in6 *la6;
2125 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002126
2127 ep = lookup_atid(t, atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05002128 la = (struct sockaddr_in *)&ep->com.mapped_local_addr;
2129 ra = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
2130 la6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
2131 ra6 = (struct sockaddr_in6 *)&ep->com.mapped_remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002132
2133 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2134 status, status2errno(status));
2135
Steve Wise7a2cea22014-03-14 21:52:07 +05302136 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302137 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2138 __func__, atid, status, neg_adv_str(status));
2139 ep->stats.connect_neg_adv++;
2140 mutex_lock(&dev->rdev.stats.lock);
2141 dev->rdev.stats.neg_adv++;
2142 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002143 return 0;
2144 }
2145
Vipul Pandya793dad92012-12-10 09:30:56 +00002146 set_bit(ACT_OPEN_RPL, &ep->com.history);
2147
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302148 /*
2149 * Log interesting failures.
2150 */
2151 switch (status) {
2152 case CPL_ERR_CONN_RESET:
2153 case CPL_ERR_CONN_TIMEDOUT:
2154 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002155 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302156 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002157 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302158 mutex_unlock(&dev->rdev.stats.lock);
2159 if (ep->com.local_addr.ss_family == AF_INET &&
2160 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002161 send_fw_act_open_req(ep,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002162 TID_TID_G(AOPEN_ATID_G(
Vipul Pandya793dad92012-12-10 09:30:56 +00002163 ntohl(rpl->atid_status))));
2164 return 0;
2165 }
2166 break;
2167 case CPL_ERR_CONN_EXIST:
2168 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2169 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302170 if (ep->com.remote_addr.ss_family == AF_INET6) {
2171 struct sockaddr_in6 *sin6 =
2172 (struct sockaddr_in6 *)
2173 &ep->com.mapped_local_addr;
2174 cxgb4_clip_release(
2175 ep->com.dev->rdev.lldi.ports[0],
2176 (const u32 *)
2177 &sin6->sin6_addr.s6_addr, 1);
2178 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002179 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2180 atid);
2181 cxgb4_free_atid(t, atid);
2182 dst_release(ep->dst);
2183 cxgb4_l2t_release(ep->l2t);
2184 c4iw_reconnect(ep);
2185 return 0;
2186 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002187 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302188 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302189 if (ep->com.local_addr.ss_family == AF_INET) {
2190 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2191 atid, status, status2errno(status),
2192 &la->sin_addr.s_addr, ntohs(la->sin_port),
2193 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2194 } else {
2195 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2196 atid, status, status2errno(status),
2197 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2198 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2199 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302200 break;
2201 }
2202
Steve Wisecfdda9d2010-04-21 15:30:06 -07002203 connect_reply_upcall(ep, status2errno(status));
2204 state_set(&ep->com, DEAD);
2205
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302206 if (ep->com.remote_addr.ss_family == AF_INET6) {
2207 struct sockaddr_in6 *sin6 =
2208 (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
2209 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2210 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2211 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002212 if (status && act_open_has_tid(status))
2213 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2214
Vipul Pandya793dad92012-12-10 09:30:56 +00002215 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002216 cxgb4_free_atid(t, atid);
2217 dst_release(ep->dst);
2218 cxgb4_l2t_release(ep->l2t);
2219 c4iw_put_ep(&ep->com);
2220
2221 return 0;
2222}
2223
2224static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2225{
2226 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2227 struct tid_info *t = dev->rdev.lldi.tids;
2228 unsigned int stid = GET_TID(rpl);
2229 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2230
2231 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002232 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2233 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002234 }
2235 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2236 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002237 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002238
Vipul Pandya1cab7752012-12-10 09:30:55 +00002239out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002240 return 0;
2241}
2242
Steve Wisecfdda9d2010-04-21 15:30:06 -07002243static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2244{
2245 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2246 struct tid_info *t = dev->rdev.lldi.tids;
2247 unsigned int stid = GET_TID(rpl);
2248 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2249
2250 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002251 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002252 return 0;
2253}
2254
Vipul Pandya830662f2013-07-04 16:10:47 +05302255static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002256 struct cpl_pass_accept_req *req)
2257{
2258 struct cpl_pass_accept_rpl *rpl;
2259 unsigned int mtu_idx;
2260 u64 opt0;
2261 u32 opt2;
2262 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302263 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302264 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302265 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002266
2267 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2268 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302269
Steve Wisecfdda9d2010-04-21 15:30:06 -07002270 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302271 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302272 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302273 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2274 rpl5 = (void *)rpl;
2275 INIT_TP_WR(rpl5, ep->hwtid);
2276 } else {
2277 skb_trim(skb, sizeof(*rpl));
2278 INIT_TP_WR(rpl, ep->hwtid);
2279 }
2280 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2281 ep->hwtid));
2282
2283 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302284 enable_tcp_timestamps && req->tcpopt.tstamp,
2285 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002286 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302287
2288 /*
2289 * Specify the largest window that will fit in opt0. The
2290 * remainder will be specified in the rx_data_ack.
2291 */
2292 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002293 if (win > RCV_BUFSIZ_M)
2294 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002295 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002296 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002297 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002298 WND_SCALE_V(wscale) |
2299 MSS_IDX_V(mtu_idx) |
2300 L2T_IDX_V(ep->l2t->idx) |
2301 TX_CHAN_V(ep->tx_chan) |
2302 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002303 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002304 ULP_MODE_V(ULP_MODE_TCPDDP) |
2305 RCV_BUFSIZ_V(win);
2306 opt2 = RX_CHANNEL_V(0) |
2307 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002308
2309 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002310 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002311 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002312 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002313 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002314 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002315 if (enable_ecn) {
2316 const struct tcphdr *tcph;
2317 u32 hlen = ntohl(req->hdr_len);
2318
Hariprasad S963cab52015-09-23 17:19:27 +05302319 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2320 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2321 IP_HDR_LEN_G(hlen);
2322 else
2323 tcph = (const void *)(req + 1) +
2324 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002325 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002326 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002327 }
Hariprasad S963cab52015-09-23 17:19:27 +05302328 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302329 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002330 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302331 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302332 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302333 rpl5 = (void *)rpl;
2334 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2335 if (peer2peer)
2336 isn += 4;
2337 rpl5->iss = cpu_to_be32(isn);
2338 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002339 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002340
Steve Wisecfdda9d2010-04-21 15:30:06 -07002341 rpl->opt0 = cpu_to_be64(opt0);
2342 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002343 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wiseb38a0ad2013-08-06 21:04:37 +05302344 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002345 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2346
2347 return;
2348}
2349
Vipul Pandya830662f2013-07-04 16:10:47 +05302350static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002351{
Vipul Pandya830662f2013-07-04 16:10:47 +05302352 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002353 BUG_ON(skb_cloned(skb));
2354 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002355 release_tid(&dev->rdev, hwtid, skb);
2356 return;
2357}
2358
Hariprasad S963cab52015-09-23 17:19:27 +05302359static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2360 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002361 __be16 *local_port, __be16 *peer_port)
2362{
Hariprasad S963cab52015-09-23 17:19:27 +05302363 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2364 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2365 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2366 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2367 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2368 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002369 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302370 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002371 struct tcphdr *tcp = (struct tcphdr *)
2372 ((u8 *)(req + 1) + eth_len + ip_len);
2373
Vipul Pandya830662f2013-07-04 16:10:47 +05302374 if (ip->version == 4) {
2375 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2376 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2377 ntohs(tcp->dest));
2378 *iptype = 4;
2379 memcpy(peer_ip, &ip->saddr, 4);
2380 memcpy(local_ip, &ip->daddr, 4);
2381 } else {
2382 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2383 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2384 ntohs(tcp->dest));
2385 *iptype = 6;
2386 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2387 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2388 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002389 *peer_port = tcp->source;
2390 *local_port = tcp->dest;
2391
2392 return;
2393}
2394
2395static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2396{
Vipul Pandya793dad92012-12-10 09:30:56 +00002397 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002398 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002399 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002400 struct tid_info *t = dev->rdev.lldi.tids;
2401 unsigned int hwtid = GET_TID(req);
2402 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302403 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002404 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302405 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002406 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002407 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302408 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302409 unsigned short hdrs;
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +05302410 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002411
2412 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002413 if (!parent_ep) {
2414 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2415 goto reject;
2416 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002417
Steve Wisecfdda9d2010-04-21 15:30:06 -07002418 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad Shenai6102c662016-02-05 11:43:29 +05302419 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002420 goto reject;
2421 }
2422
Hariprasad S963cab52015-09-23 17:19:27 +05302423 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2424 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302425
Steve Wisecfdda9d2010-04-21 15:30:06 -07002426 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302427 if (iptype == 4) {
2428 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2429 , __func__, parent_ep, hwtid,
2430 local_ip, peer_ip, ntohs(local_port),
2431 ntohs(peer_port), peer_mss);
2432 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2433 local_port, peer_port,
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +05302434 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302435 } else {
2436 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2437 , __func__, parent_ep, hwtid,
2438 local_ip, peer_ip, ntohs(local_port),
2439 ntohs(peer_port), peer_mss);
2440 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002441 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302442 ((struct sockaddr_in6 *)
2443 &parent_ep->com.local_addr)->sin6_scope_id);
2444 }
2445 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002446 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2447 __func__);
2448 goto reject;
2449 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002450
2451 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2452 if (!child_ep) {
2453 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2454 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002455 dst_release(dst);
2456 goto reject;
2457 }
David Miller3786cf12011-12-02 16:52:31 +00002458
Hariprasad S963cab52015-09-23 17:19:27 +05302459 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +05302460 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002461 if (err) {
2462 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2463 __func__);
2464 dst_release(dst);
2465 kfree(child_ep);
2466 goto reject;
2467 }
2468
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302469 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2470 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2471 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2472 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002473
Steve Wisecfdda9d2010-04-21 15:30:06 -07002474 state_set(&child_ep->com, CONNECTING);
2475 child_ep->com.dev = dev;
2476 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002477
2478 /*
2479 * The mapped_local and mapped_remote addresses get setup with
2480 * the actual 4-tuple. The local address will be based on the
2481 * actual local address of the connection, but on the port number
2482 * of the parent listening endpoint. The remote address is
2483 * setup based on a query to the IWPM since we don't know what it
2484 * originally was before mapping. If no mapping was done, then
2485 * mapped_remote == remote, and mapped_local == local.
2486 */
Vipul Pandya830662f2013-07-04 16:10:47 +05302487 if (iptype == 4) {
2488 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002489 &child_ep->com.mapped_local_addr;
2490
Vipul Pandya830662f2013-07-04 16:10:47 +05302491 sin->sin_family = PF_INET;
2492 sin->sin_port = local_port;
2493 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002494
2495 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2496 sin->sin_family = PF_INET;
2497 sin->sin_port = ((struct sockaddr_in *)
2498 &parent_ep->com.local_addr)->sin_port;
2499 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2500
2501 sin = (struct sockaddr_in *)&child_ep->com.mapped_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302502 sin->sin_family = PF_INET;
2503 sin->sin_port = peer_port;
2504 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2505 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302506 sin6 = (struct sockaddr_in6 *)&child_ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302507 sin6->sin6_family = PF_INET6;
2508 sin6->sin6_port = local_port;
2509 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002510
2511 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2512 sin6->sin6_family = PF_INET6;
2513 sin6->sin6_port = ((struct sockaddr_in6 *)
2514 &parent_ep->com.local_addr)->sin6_port;
2515 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2516
2517 sin6 = (struct sockaddr_in6 *)&child_ep->com.mapped_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302518 sin6->sin6_family = PF_INET6;
2519 sin6->sin6_port = peer_port;
2520 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2521 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002522 memcpy(&child_ep->com.remote_addr, &child_ep->com.mapped_remote_addr,
2523 sizeof(child_ep->com.remote_addr));
Steve Wise940fd302015-05-07 16:34:23 -05002524 get_remote_addr(parent_ep, child_ep);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002525
Steve Wisecfdda9d2010-04-21 15:30:06 -07002526 c4iw_get_ep(&parent_ep->com);
2527 child_ep->parent_ep = parent_ep;
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +05302528 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002529 child_ep->dst = dst;
2530 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002531
2532 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002533 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002534
2535 init_timer(&child_ep->timer);
2536 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002537 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Vipul Pandya830662f2013-07-04 16:10:47 +05302538 accept_cr(child_ep, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00002539 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302540 if (iptype == 6) {
2541 sin6 = (struct sockaddr_in6 *)&child_ep->com.mapped_local_addr;
2542 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2543 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2544 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002545 goto out;
2546reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302547 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002548out:
2549 return 0;
2550}
2551
2552static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2553{
2554 struct c4iw_ep *ep;
2555 struct cpl_pass_establish *req = cplhdr(skb);
2556 struct tid_info *t = dev->rdev.lldi.tids;
2557 unsigned int tid = GET_TID(req);
2558
2559 ep = lookup_tid(t, tid);
2560 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2561 ep->snd_seq = be32_to_cpu(req->snd_isn);
2562 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2563
Vipul Pandya1cab7752012-12-10 09:30:55 +00002564 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2565 ntohs(req->tcp_opt));
2566
Steve Wisecfdda9d2010-04-21 15:30:06 -07002567 set_emss(ep, ntohs(req->tcp_opt));
2568
2569 dst_confirm(ep->dst);
2570 state_set(&ep->com, MPA_REQ_WAIT);
2571 start_ep_timer(ep);
2572 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002573 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002574
2575 return 0;
2576}
2577
2578static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2579{
2580 struct cpl_peer_close *hdr = cplhdr(skb);
2581 struct c4iw_ep *ep;
2582 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002583 int disconnect = 1;
2584 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002585 struct tid_info *t = dev->rdev.lldi.tids;
2586 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002587 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002588
2589 ep = lookup_tid(t, tid);
2590 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2591 dst_confirm(ep->dst);
2592
Vipul Pandya793dad92012-12-10 09:30:56 +00002593 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002594 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002595 switch (ep->com.state) {
2596 case MPA_REQ_WAIT:
2597 __state_set(&ep->com, CLOSING);
2598 break;
2599 case MPA_REQ_SENT:
2600 __state_set(&ep->com, CLOSING);
2601 connect_reply_upcall(ep, -ECONNRESET);
2602 break;
2603 case MPA_REQ_RCVD:
2604
2605 /*
2606 * We're gonna mark this puppy DEAD, but keep
2607 * the reference on it until the ULP accepts or
2608 * rejects the CR. Also wake up anyone waiting
2609 * in rdma connection migration (see c4iw_accept_cr()).
2610 */
2611 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002612 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002613 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002614 break;
2615 case MPA_REP_SENT:
2616 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002617 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002618 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002619 break;
2620 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002621 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002622 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002623 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002624 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002625 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002626 if (ret != -ECONNRESET) {
2627 peer_close_upcall(ep);
2628 disconnect = 1;
2629 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002630 break;
2631 case ABORTING:
2632 disconnect = 0;
2633 break;
2634 case CLOSING:
2635 __state_set(&ep->com, MORIBUND);
2636 disconnect = 0;
2637 break;
2638 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002639 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002640 if (ep->com.cm_id && ep->com.qp) {
2641 attrs.next_state = C4IW_QP_STATE_IDLE;
2642 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2643 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2644 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302645 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002646 __state_set(&ep->com, DEAD);
2647 release = 1;
2648 disconnect = 0;
2649 break;
2650 case DEAD:
2651 disconnect = 0;
2652 break;
2653 default:
2654 BUG_ON(1);
2655 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002656 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002657 if (disconnect)
2658 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2659 if (release)
2660 release_ep_resources(ep);
2661 return 0;
2662}
2663
Steve Wisecfdda9d2010-04-21 15:30:06 -07002664static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2665{
2666 struct cpl_abort_req_rss *req = cplhdr(skb);
2667 struct c4iw_ep *ep;
2668 struct cpl_abort_rpl *rpl;
2669 struct sk_buff *rpl_skb;
2670 struct c4iw_qp_attributes attrs;
2671 int ret;
2672 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002673 struct tid_info *t = dev->rdev.lldi.tids;
2674 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002675
2676 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302677 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302678 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2679 __func__, ep->hwtid, req->status,
2680 neg_adv_str(req->status));
2681 ep->stats.abort_neg_adv++;
2682 mutex_lock(&dev->rdev.stats.lock);
2683 dev->rdev.stats.neg_adv++;
2684 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002685 return 0;
2686 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002687 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2688 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002689 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002690
2691 /*
2692 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302693 * However, this is not needed if com state is just
2694 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002695 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302696 if (ep->com.state != MPA_REQ_SENT)
2697 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002698
2699 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002700 switch (ep->com.state) {
2701 case CONNECTING:
2702 break;
2703 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002704 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002705 break;
2706 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002707 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002708 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302709 connect_reply_upcall(ep, -ECONNRESET);
2710 else {
2711 /*
2712 * we just don't send notification upwards because we
2713 * want to retry with mpa_v1 without upper layers even
2714 * knowing it.
2715 *
2716 * do some housekeeping so as to re-initiate the
2717 * connection
2718 */
2719 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2720 mpa_rev);
2721 ep->retry_with_mpa_v1 = 1;
2722 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002723 break;
2724 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002725 break;
2726 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002727 break;
2728 case MORIBUND:
2729 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002730 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002731 /*FALLTHROUGH*/
2732 case FPDU_MODE:
2733 if (ep->com.cm_id && ep->com.qp) {
2734 attrs.next_state = C4IW_QP_STATE_ERROR;
2735 ret = c4iw_modify_qp(ep->com.qp->rhp,
2736 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2737 &attrs, 1);
2738 if (ret)
2739 printk(KERN_ERR MOD
2740 "%s - qp <- error failed!\n",
2741 __func__);
2742 }
2743 peer_abort_upcall(ep);
2744 break;
2745 case ABORTING:
2746 break;
2747 case DEAD:
2748 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002749 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002750 return 0;
2751 default:
2752 BUG_ON(1);
2753 break;
2754 }
2755 dst_confirm(ep->dst);
2756 if (ep->com.state != ABORTING) {
2757 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302758 /* we don't release if we want to retry with mpa_v1 */
2759 if (!ep->retry_with_mpa_v1)
2760 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002761 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002762 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002763
2764 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2765 if (!rpl_skb) {
2766 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2767 __func__);
2768 release = 1;
2769 goto out;
2770 }
2771 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2772 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2773 INIT_TP_WR(rpl, ep->hwtid);
2774 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2775 rpl->cmd = CPL_ABORT_NO_RST;
2776 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2777out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002778 if (release)
2779 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002780 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302781 if (ep->com.remote_addr.ss_family == AF_INET6) {
2782 struct sockaddr_in6 *sin6 =
2783 (struct sockaddr_in6 *)
2784 &ep->com.mapped_local_addr;
2785 cxgb4_clip_release(
2786 ep->com.dev->rdev.lldi.ports[0],
2787 (const u32 *)&sin6->sin6_addr.s6_addr,
2788 1);
2789 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002790 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302791 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2792 dst_release(ep->dst);
2793 cxgb4_l2t_release(ep->l2t);
2794 c4iw_reconnect(ep);
2795 }
2796
Steve Wisecfdda9d2010-04-21 15:30:06 -07002797 return 0;
2798}
2799
2800static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2801{
2802 struct c4iw_ep *ep;
2803 struct c4iw_qp_attributes attrs;
2804 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002805 int release = 0;
2806 struct tid_info *t = dev->rdev.lldi.tids;
2807 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002808
2809 ep = lookup_tid(t, tid);
2810
2811 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2812 BUG_ON(!ep);
2813
2814 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002815 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002816 switch (ep->com.state) {
2817 case CLOSING:
2818 __state_set(&ep->com, MORIBUND);
2819 break;
2820 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002821 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002822 if ((ep->com.cm_id) && (ep->com.qp)) {
2823 attrs.next_state = C4IW_QP_STATE_IDLE;
2824 c4iw_modify_qp(ep->com.qp->rhp,
2825 ep->com.qp,
2826 C4IW_QP_ATTR_NEXT_STATE,
2827 &attrs, 1);
2828 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302829 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002830 __state_set(&ep->com, DEAD);
2831 release = 1;
2832 break;
2833 case ABORTING:
2834 case DEAD:
2835 break;
2836 default:
2837 BUG_ON(1);
2838 break;
2839 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002840 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002841 if (release)
2842 release_ep_resources(ep);
2843 return 0;
2844}
2845
2846static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2847{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002848 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002849 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002850 unsigned int tid = GET_TID(rpl);
2851 struct c4iw_ep *ep;
2852 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002853
2854 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002855 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002856
Steve Wise30c95c22011-05-09 22:06:22 -07002857 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002858 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2859 ep->com.qp->wq.sq.qid);
2860 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2861 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2862 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2863 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002864 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002865
Steve Wisecfdda9d2010-04-21 15:30:06 -07002866 return 0;
2867}
2868
2869/*
2870 * Upcall from the adapter indicating data has been transmitted.
2871 * For us its just the single MPA request or reply. We can now free
2872 * the skb holding the mpa message.
2873 */
2874static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2875{
2876 struct c4iw_ep *ep;
2877 struct cpl_fw4_ack *hdr = cplhdr(skb);
2878 u8 credits = hdr->credits;
2879 unsigned int tid = GET_TID(hdr);
2880 struct tid_info *t = dev->rdev.lldi.tids;
2881
2882
2883 ep = lookup_tid(t, tid);
2884 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2885 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002886 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2887 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002888 return 0;
2889 }
2890
2891 dst_confirm(ep->dst);
2892 if (ep->mpa_skb) {
2893 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2894 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2895 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2896 kfree_skb(ep->mpa_skb);
2897 ep->mpa_skb = NULL;
2898 }
2899 return 0;
2900}
2901
Steve Wisecfdda9d2010-04-21 15:30:06 -07002902int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2903{
Steve Wisea7db89e2014-03-21 20:40:35 +05302904 int err = 0;
2905 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002906 struct c4iw_ep *ep = to_ep(cm_id);
2907 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2908
Steve Wisea7db89e2014-03-21 20:40:35 +05302909 mutex_lock(&ep->com.mutex);
2910 if (ep->com.state == DEAD) {
2911 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002912 c4iw_put_ep(&ep->com);
2913 return -ECONNRESET;
2914 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002915 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302916 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002917 if (mpa_rev == 0)
2918 abort_connection(ep, NULL, GFP_KERNEL);
2919 else {
2920 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302921 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002922 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302923 mutex_unlock(&ep->com.mutex);
2924 if (disconnect)
2925 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002926 c4iw_put_ep(&ep->com);
2927 return 0;
2928}
2929
2930int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2931{
2932 int err;
2933 struct c4iw_qp_attributes attrs;
2934 enum c4iw_qp_attr_mask mask;
2935 struct c4iw_ep *ep = to_ep(cm_id);
2936 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2937 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2938
2939 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302940
2941 mutex_lock(&ep->com.mutex);
2942 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002943 err = -ECONNRESET;
2944 goto err;
2945 }
2946
Steve Wisea7db89e2014-03-21 20:40:35 +05302947 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002948 BUG_ON(!qp);
2949
Vipul Pandya793dad92012-12-10 09:30:56 +00002950 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302951 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2952 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002953 abort_connection(ep, NULL, GFP_KERNEL);
2954 err = -EINVAL;
2955 goto err;
2956 }
2957
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302958 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2959 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302960 if (RELAXED_IRD_NEGOTIATION) {
2961 ep->ord = ep->ird;
2962 } else {
2963 ep->ird = conn_param->ird;
2964 ep->ord = conn_param->ord;
2965 send_mpa_reject(ep, conn_param->private_data,
2966 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302967 abort_connection(ep, NULL, GFP_KERNEL);
2968 err = -ENOMEM;
2969 goto err;
2970 }
2971 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302972 if (conn_param->ird < ep->ord) {
2973 if (RELAXED_IRD_NEGOTIATION &&
2974 ep->ord <= h->rdev.lldi.max_ordird_qp) {
2975 conn_param->ird = ep->ord;
2976 } else {
2977 abort_connection(ep, NULL, GFP_KERNEL);
2978 err = -ENOMEM;
2979 goto err;
2980 }
2981 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302982 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002983 ep->ird = conn_param->ird;
2984 ep->ord = conn_param->ord;
2985
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302986 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302987 if (peer2peer && ep->ird == 0)
2988 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302989 } else {
2990 if (peer2peer &&
2991 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05302992 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302993 ep->ird = 1;
2994 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002995
2996 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2997
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302998 cm_id->add_ref(cm_id);
2999 ep->com.cm_id = cm_id;
3000 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003001 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303002
Steve Wisecfdda9d2010-04-21 15:30:06 -07003003 /* bind QP to EP and move to RTS */
3004 attrs.mpa_attr = ep->mpa_attr;
3005 attrs.max_ird = ep->ird;
3006 attrs.max_ord = ep->ord;
3007 attrs.llp_stream_handle = ep;
3008 attrs.next_state = C4IW_QP_STATE_RTS;
3009
3010 /* bind QP and TID with INIT_WR */
3011 mask = C4IW_QP_ATTR_NEXT_STATE |
3012 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3013 C4IW_QP_ATTR_MPA_ATTR |
3014 C4IW_QP_ATTR_MAX_IRD |
3015 C4IW_QP_ATTR_MAX_ORD;
3016
3017 err = c4iw_modify_qp(ep->com.qp->rhp,
3018 ep->com.qp, mask, &attrs, 1);
3019 if (err)
3020 goto err1;
3021 err = send_mpa_reply(ep, conn_param->private_data,
3022 conn_param->private_data_len);
3023 if (err)
3024 goto err1;
3025
Steve Wisea7db89e2014-03-21 20:40:35 +05303026 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003027 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303028 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003029 c4iw_put_ep(&ep->com);
3030 return 0;
3031err1:
3032 ep->com.cm_id = NULL;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303033 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003034 cm_id->rem_ref(cm_id);
3035err:
Steve Wisea7db89e2014-03-21 20:40:35 +05303036 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003037 c4iw_put_ep(&ep->com);
3038 return err;
3039}
3040
Vipul Pandya830662f2013-07-04 16:10:47 +05303041static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3042{
3043 struct in_device *ind;
3044 int found = 0;
3045 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
3046 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
3047
3048 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3049 if (!ind)
3050 return -EADDRNOTAVAIL;
3051 for_primary_ifa(ind) {
3052 laddr->sin_addr.s_addr = ifa->ifa_address;
3053 raddr->sin_addr.s_addr = ifa->ifa_address;
3054 found = 1;
3055 break;
3056 }
3057 endfor_ifa(ind);
3058 in_dev_put(ind);
3059 return found ? 0 : -EADDRNOTAVAIL;
3060}
3061
3062static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3063 unsigned char banned_flags)
3064{
3065 struct inet6_dev *idev;
3066 int err = -EADDRNOTAVAIL;
3067
3068 rcu_read_lock();
3069 idev = __in6_dev_get(dev);
3070 if (idev != NULL) {
3071 struct inet6_ifaddr *ifp;
3072
3073 read_lock_bh(&idev->lock);
3074 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3075 if (ifp->scope == IFA_LINK &&
3076 !(ifp->flags & banned_flags)) {
3077 memcpy(addr, &ifp->addr, 16);
3078 err = 0;
3079 break;
3080 }
3081 }
3082 read_unlock_bh(&idev->lock);
3083 }
3084 rcu_read_unlock();
3085 return err;
3086}
3087
3088static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3089{
3090 struct in6_addr uninitialized_var(addr);
3091 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
3092 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
3093
Nicholas Krause54b9a962015-08-26 23:00:59 -04003094 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303095 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3096 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3097 return 0;
3098 }
3099 return -EADDRNOTAVAIL;
3100}
3101
Steve Wisecfdda9d2010-04-21 15:30:06 -07003102int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3103{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003104 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3105 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003106 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003107 struct sockaddr_in *laddr;
3108 struct sockaddr_in *raddr;
3109 struct sockaddr_in6 *laddr6;
3110 struct sockaddr_in6 *raddr6;
3111 struct iwpm_dev_data pm_reg_msg;
3112 struct iwpm_sa_data pm_msg;
Vipul Pandya830662f2013-07-04 16:10:47 +05303113 __u8 *ra;
3114 int iptype;
Steve Wise9eccfe12014-03-26 17:08:09 -05003115 int iwpm_err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003116
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303117 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3118 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003119 err = -EINVAL;
3120 goto out;
3121 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003122 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3123 if (!ep) {
3124 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3125 err = -ENOMEM;
3126 goto out;
3127 }
3128 init_timer(&ep->timer);
3129 ep->plen = conn_param->private_data_len;
3130 if (ep->plen)
3131 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3132 conn_param->private_data, ep->plen);
3133 ep->ird = conn_param->ird;
3134 ep->ord = conn_param->ord;
3135
3136 if (peer2peer && ep->ord == 0)
3137 ep->ord = 1;
3138
3139 cm_id->add_ref(cm_id);
3140 ep->com.dev = dev;
3141 ep->com.cm_id = cm_id;
3142 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303143 if (!ep->com.qp) {
3144 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3145 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003146 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303147 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003148 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003149 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3150 ep->com.qp, cm_id);
3151
3152 /*
3153 * Allocate an active TID to initiate a TCP connection.
3154 */
3155 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3156 if (ep->atid == -1) {
3157 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3158 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003159 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003160 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003161 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003162
Steve Wise9eccfe12014-03-26 17:08:09 -05003163 memcpy(&ep->com.local_addr, &cm_id->local_addr,
3164 sizeof(ep->com.local_addr));
3165 memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
3166 sizeof(ep->com.remote_addr));
3167
3168 /* No port mapper available, go with the specified peer information */
3169 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3170 sizeof(ep->com.mapped_local_addr));
3171 memcpy(&ep->com.mapped_remote_addr, &cm_id->remote_addr,
3172 sizeof(ep->com.mapped_remote_addr));
3173
3174 c4iw_form_reg_msg(dev, &pm_reg_msg);
3175 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3176 if (iwpm_err) {
3177 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3178 __func__, iwpm_err);
3179 }
3180 if (iwpm_valid_pid() && !iwpm_err) {
3181 c4iw_form_pm_msg(ep, &pm_msg);
3182 iwpm_err = iwpm_add_and_query_mapping(&pm_msg, RDMA_NL_C4IW);
3183 if (iwpm_err)
3184 PDBG("%s: Port Mapper query fail (err = %d).\n",
3185 __func__, iwpm_err);
3186 else
3187 c4iw_record_pm_msg(ep, &pm_msg);
3188 }
3189 if (iwpm_create_mapinfo(&ep->com.local_addr,
3190 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3191 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
3192 err = -ENOMEM;
3193 goto fail1;
3194 }
3195 print_addr(&ep->com, __func__, "add_query/create_mapinfo");
3196 set_bit(RELEASE_MAPINFO, &ep->com.flags);
3197
3198 laddr = (struct sockaddr_in *)&ep->com.mapped_local_addr;
3199 raddr = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
3200 laddr6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
3201 raddr6 = (struct sockaddr_in6 *) &ep->com.mapped_remote_addr;
3202
Vipul Pandya830662f2013-07-04 16:10:47 +05303203 if (cm_id->remote_addr.ss_family == AF_INET) {
3204 iptype = 4;
3205 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003206
Vipul Pandya830662f2013-07-04 16:10:47 +05303207 /*
3208 * Handle loopback requests to INADDR_ANY.
3209 */
3210 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3211 err = pick_local_ipaddrs(dev, cm_id);
3212 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003213 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303214 }
3215
3216 /* find a route */
3217 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3218 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3219 ra, ntohs(raddr->sin_port));
3220 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3221 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +05303222 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303223 } else {
3224 iptype = 6;
3225 ra = (__u8 *)&raddr6->sin6_addr;
3226
3227 /*
3228 * Handle loopback requests to INADDR_ANY.
3229 */
3230 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3231 err = pick_local_ip6addrs(dev, cm_id);
3232 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003233 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303234 }
3235
3236 /* find a route */
3237 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3238 __func__, laddr6->sin6_addr.s6_addr,
3239 ntohs(laddr6->sin6_port),
3240 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3241 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3242 raddr6->sin6_addr.s6_addr,
3243 laddr6->sin6_port, raddr6->sin6_port, 0,
3244 raddr6->sin6_scope_id);
3245 }
3246 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003247 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3248 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003249 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003250 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003251
Hariprasad S963cab52015-09-23 17:19:27 +05303252 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +05303253 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003254 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003255 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003256 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003257 }
3258
3259 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3260 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3261 ep->l2t->idx);
3262
3263 state_set(&ep->com, CONNECTING);
Hariprasad Shenaiba9cee62016-02-05 11:43:30 +05303264 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003265
3266 /* send connect request to rnic */
3267 err = send_connect(ep);
3268 if (!err)
3269 goto out;
3270
3271 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003272fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003273 dst_release(ep->dst);
3274fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003275 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003276 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003277fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003278 cm_id->rem_ref(cm_id);
3279 c4iw_put_ep(&ep->com);
3280out:
3281 return err;
3282}
3283
Vipul Pandya830662f2013-07-04 16:10:47 +05303284static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3285{
3286 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003287 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
3288 &ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303289
Hariprasad S28de1f72016-01-13 10:03:14 +05303290 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3291 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3292 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3293 if (err)
3294 return err;
3295 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303296 c4iw_init_wr_wait(&ep->com.wr_wait);
3297 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3298 ep->stid, &sin6->sin6_addr,
3299 sin6->sin6_port,
3300 ep->com.dev->rdev.lldi.rxq_ids[0]);
3301 if (!err)
3302 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3303 &ep->com.wr_wait,
3304 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303305 else if (err > 0)
3306 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303307 if (err) {
3308 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3309 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303310 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3311 err, ep->stid,
3312 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303313 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303314 return err;
3315}
3316
3317static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3318{
3319 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003320 struct sockaddr_in *sin = (struct sockaddr_in *)
3321 &ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303322
3323 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3324 do {
3325 err = cxgb4_create_server_filter(
3326 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3327 sin->sin_addr.s_addr, sin->sin_port, 0,
3328 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3329 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303330 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3331 err = -EIO;
3332 break;
3333 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303334 set_current_state(TASK_UNINTERRUPTIBLE);
3335 schedule_timeout(usecs_to_jiffies(100));
3336 }
3337 } while (err == -EBUSY);
3338 } else {
3339 c4iw_init_wr_wait(&ep->com.wr_wait);
3340 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3341 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3342 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3343 if (!err)
3344 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3345 &ep->com.wr_wait,
3346 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303347 else if (err > 0)
3348 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303349 }
3350 if (err)
3351 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3352 , err, ep->stid,
3353 &sin->sin_addr, ntohs(sin->sin_port));
3354 return err;
3355}
3356
Steve Wisecfdda9d2010-04-21 15:30:06 -07003357int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3358{
3359 int err = 0;
3360 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3361 struct c4iw_listen_ep *ep;
Steve Wise9eccfe12014-03-26 17:08:09 -05003362 struct iwpm_dev_data pm_reg_msg;
3363 struct iwpm_sa_data pm_msg;
3364 int iwpm_err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003365
Steve Wisecfdda9d2010-04-21 15:30:06 -07003366 might_sleep();
3367
3368 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3369 if (!ep) {
3370 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3371 err = -ENOMEM;
3372 goto fail1;
3373 }
3374 PDBG("%s ep %p\n", __func__, ep);
3375 cm_id->add_ref(cm_id);
3376 ep->com.cm_id = cm_id;
3377 ep->com.dev = dev;
3378 ep->backlog = backlog;
Steve Wise24d44a32013-07-04 16:10:44 +05303379 memcpy(&ep->com.local_addr, &cm_id->local_addr,
3380 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003381
3382 /*
3383 * Allocate a server TID.
3384 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303385 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3386 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303387 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
3388 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003389 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303390 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
3391 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003392
Steve Wisecfdda9d2010-04-21 15:30:06 -07003393 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003394 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003395 err = -ENOMEM;
3396 goto fail2;
3397 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003398 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003399
3400 /* No port mapper available, go with the specified info */
3401 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3402 sizeof(ep->com.mapped_local_addr));
3403
3404 c4iw_form_reg_msg(dev, &pm_reg_msg);
3405 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3406 if (iwpm_err) {
3407 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3408 __func__, iwpm_err);
3409 }
3410 if (iwpm_valid_pid() && !iwpm_err) {
3411 memcpy(&pm_msg.loc_addr, &ep->com.local_addr,
3412 sizeof(ep->com.local_addr));
3413 iwpm_err = iwpm_add_mapping(&pm_msg, RDMA_NL_C4IW);
3414 if (iwpm_err)
3415 PDBG("%s: Port Mapper query fail (err = %d).\n",
3416 __func__, iwpm_err);
3417 else
3418 memcpy(&ep->com.mapped_local_addr,
3419 &pm_msg.mapped_loc_addr,
3420 sizeof(ep->com.mapped_local_addr));
3421 }
3422 if (iwpm_create_mapinfo(&ep->com.local_addr,
3423 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3424 err = -ENOMEM;
3425 goto fail3;
3426 }
3427 print_addr(&ep->com, __func__, "add_mapping/create_mapinfo");
3428
3429 set_bit(RELEASE_MAPINFO, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003430 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303431 if (ep->com.local_addr.ss_family == AF_INET)
3432 err = create_server4(dev, ep);
3433 else
3434 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003435 if (!err) {
3436 cm_id->provider_data = ep;
3437 goto out;
3438 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003439
3440fail3:
Vipul Pandya830662f2013-07-04 16:10:47 +05303441 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3442 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003443fail2:
3444 cm_id->rem_ref(cm_id);
3445 c4iw_put_ep(&ep->com);
3446fail1:
3447out:
3448 return err;
3449}
3450
3451int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3452{
3453 int err;
3454 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3455
3456 PDBG("%s ep %p\n", __func__, ep);
3457
3458 might_sleep();
3459 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303460 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3461 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003462 err = cxgb4_remove_server_filter(
3463 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3464 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3465 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303466 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003467 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303468 err = cxgb4_remove_server(
3469 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3470 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003471 if (err)
3472 goto done;
3473 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3474 0, 0, __func__);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303475 sin6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
3476 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3477 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003478 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003479 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303480 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3481 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003482done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003483 cm_id->rem_ref(cm_id);
3484 c4iw_put_ep(&ep->com);
3485 return err;
3486}
3487
3488int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3489{
3490 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003491 int close = 0;
3492 int fatal = 0;
3493 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003494
Steve Wise2f5b48c2010-09-10 11:15:36 -05003495 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003496
3497 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3498 states[ep->com.state], abrupt);
3499
3500 rdev = &ep->com.dev->rdev;
3501 if (c4iw_fatal_error(rdev)) {
3502 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303503 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003504 ep->com.state = DEAD;
3505 }
3506 switch (ep->com.state) {
3507 case MPA_REQ_WAIT:
3508 case MPA_REQ_SENT:
3509 case MPA_REQ_RCVD:
3510 case MPA_REP_SENT:
3511 case FPDU_MODE:
3512 close = 1;
3513 if (abrupt)
3514 ep->com.state = ABORTING;
3515 else {
3516 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003517 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003518 }
3519 set_bit(CLOSE_SENT, &ep->com.flags);
3520 break;
3521 case CLOSING:
3522 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3523 close = 1;
3524 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003525 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003526 ep->com.state = ABORTING;
3527 } else
3528 ep->com.state = MORIBUND;
3529 }
3530 break;
3531 case MORIBUND:
3532 case ABORTING:
3533 case DEAD:
3534 PDBG("%s ignoring disconnect ep %p state %u\n",
3535 __func__, ep, ep->com.state);
3536 break;
3537 default:
3538 BUG();
3539 break;
3540 }
3541
Steve Wisecfdda9d2010-04-21 15:30:06 -07003542 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003543 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003544 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303545 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003546 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003547 } else {
3548 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003549 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003550 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003551 if (ret)
3552 fatal = 1;
3553 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003554 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003555 if (fatal)
3556 release_ep_resources(ep);
3557 return ret;
3558}
3559
Vipul Pandya1cab7752012-12-10 09:30:55 +00003560static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3561 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3562{
3563 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003564 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003565
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003566 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3567 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003568 if (!ep)
3569 return;
3570
3571 switch (req->retval) {
3572 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003573 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3574 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3575 send_fw_act_open_req(ep, atid);
3576 return;
3577 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003578 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003579 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3580 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3581 send_fw_act_open_req(ep, atid);
3582 return;
3583 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003584 break;
3585 default:
3586 pr_info("%s unexpected ofld conn wr retval %d\n",
3587 __func__, req->retval);
3588 break;
3589 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003590 pr_err("active ofld_connect_wr failure %d atid %d\n",
3591 req->retval, atid);
3592 mutex_lock(&dev->rdev.stats.lock);
3593 dev->rdev.stats.act_ofld_conn_fails++;
3594 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003595 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003596 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303597 if (ep->com.remote_addr.ss_family == AF_INET6) {
3598 struct sockaddr_in6 *sin6 =
3599 (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
3600 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3601 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3602 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003603 remove_handle(dev, &dev->atid_idr, atid);
3604 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3605 dst_release(ep->dst);
3606 cxgb4_l2t_release(ep->l2t);
3607 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003608}
3609
3610static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3611 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3612{
3613 struct sk_buff *rpl_skb;
3614 struct cpl_pass_accept_req *cpl;
3615 int ret;
3616
Paul Bolle710a3112013-02-05 20:51:30 +00003617 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003618 BUG_ON(!rpl_skb);
3619 if (req->retval) {
3620 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003621 mutex_lock(&dev->rdev.stats.lock);
3622 dev->rdev.stats.pas_ofld_conn_fails++;
3623 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003624 kfree_skb(rpl_skb);
3625 } else {
3626 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3627 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003628 (__force u32) htonl(
3629 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003630 ret = pass_accept_req(dev, rpl_skb);
3631 if (!ret)
3632 kfree_skb(rpl_skb);
3633 }
3634 return;
3635}
3636
3637static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003638{
3639 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003640 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3641
3642 switch (rpl->type) {
3643 case FW6_TYPE_CQE:
3644 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3645 break;
3646 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3647 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3648 switch (req->t_state) {
3649 case TCP_SYN_SENT:
3650 active_ofld_conn_reply(dev, skb, req);
3651 break;
3652 case TCP_SYN_RECV:
3653 passive_ofld_conn_reply(dev, skb, req);
3654 break;
3655 default:
3656 pr_err("%s unexpected ofld conn wr state %d\n",
3657 __func__, req->t_state);
3658 break;
3659 }
3660 break;
3661 }
3662 return 0;
3663}
3664
3665static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3666{
Hariprasad S963cab52015-09-23 17:19:27 +05303667 __be32 l2info;
3668 __be16 hdr_len, vlantag, len;
3669 u16 eth_hdr_len;
3670 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003671 u8 intf;
3672 struct cpl_rx_pkt *cpl = cplhdr(skb);
3673 struct cpl_pass_accept_req *req;
3674 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003675 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303676 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003677
Vipul Pandyaf079af72013-03-14 05:08:58 +00003678 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003679 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303680 vlantag = cpl->vlan;
3681 len = cpl->len;
3682 l2info = cpl->l2info;
3683 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003684 intf = cpl->iff;
3685
3686 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3687
3688 /*
3689 * We need to parse the TCP options from SYN packet.
3690 * to generate cpl_pass_accept_req.
3691 */
3692 memset(&tmp_opt, 0, sizeof(tmp_opt));
3693 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003694 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003695
3696 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3697 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303698 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3699 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303700 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303701 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303702 type = dev->rdev.lldi.adapter_type;
3703 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3704 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3705 req->hdr_len =
3706 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3707 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3708 eth_hdr_len = is_t4(type) ?
3709 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3710 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3711 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3712 IP_HDR_LEN_V(ip_hdr_len) |
3713 ETH_HDR_LEN_V(eth_hdr_len));
3714 } else { /* T6 and later */
3715 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3716 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3717 T6_IP_HDR_LEN_V(ip_hdr_len) |
3718 T6_ETH_HDR_LEN_V(eth_hdr_len));
3719 }
3720 req->vlan = vlantag;
3721 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003722 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3723 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003724 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3725 if (tmp_opt.wscale_ok)
3726 req->tcpopt.wsf = tmp_opt.snd_wscale;
3727 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3728 if (tmp_opt.sack_ok)
3729 req->tcpopt.sack = 1;
3730 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3731 return;
3732}
3733
3734static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3735 __be32 laddr, __be16 lport,
3736 __be32 raddr, __be16 rport,
3737 u32 rcv_isn, u32 filter, u16 window,
3738 u32 rss_qid, u8 port_id)
3739{
3740 struct sk_buff *req_skb;
3741 struct fw_ofld_connection_wr *req;
3742 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303743 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003744
3745 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3746 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3747 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003748 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303749 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303750 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003751 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003752 req->le.lport = lport;
3753 req->le.pport = rport;
3754 req->le.u.ipv4.lip = laddr;
3755 req->le.u.ipv4.pip = raddr;
3756 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3757 req->tcb.rcv_adv = htons(window);
3758 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303759 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3760 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3761 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003762 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003763
3764 /*
3765 * We store the qid in opt2 which will be used by the firmware
3766 * to send us the wr response.
3767 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003768 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003769
3770 /*
3771 * We initialize the MSS index in TCB to 0xF.
3772 * So that when driver sends cpl_pass_accept_rpl
3773 * TCB picks up the correct value. If this was 0
3774 * TP will ignore any value > 0 for MSS index.
3775 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003776 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303777 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003778
3779 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303780 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3781 if (ret < 0) {
3782 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3783 ret);
3784 kfree_skb(skb);
3785 kfree_skb(req_skb);
3786 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003787}
3788
3789/*
3790 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3791 * messages when a filter is being used instead of server to
3792 * redirect a syn packet. When packets hit filter they are redirected
3793 * to the offload queue and driver tries to establish the connection
3794 * using firmware work request.
3795 */
3796static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3797{
3798 int stid;
3799 unsigned int filter;
3800 struct ethhdr *eh = NULL;
3801 struct vlan_ethhdr *vlan_eh = NULL;
3802 struct iphdr *iph;
3803 struct tcphdr *tcph;
3804 struct rss_header *rss = (void *)skb->data;
3805 struct cpl_rx_pkt *cpl = (void *)skb->data;
3806 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3807 struct l2t_entry *e;
3808 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003809 struct c4iw_ep *lep;
3810 u16 window;
3811 struct port_info *pi;
3812 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003813 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003814 int step;
3815 u32 tx_chan;
3816 struct neighbour *neigh;
3817
3818 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003819 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003820 goto reject;
3821
3822 /*
3823 * Drop all packets which did not hit the filter.
3824 * Unlikely to happen.
3825 */
3826 if (!(rss->filter_hit && rss->filter_tid))
3827 goto reject;
3828
3829 /*
3830 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3831 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303832 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003833
3834 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3835 if (!lep) {
3836 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3837 goto reject;
3838 }
3839
Hariprasad S963cab52015-09-23 17:19:27 +05303840 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3841 case CHELSIO_T4:
3842 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3843 break;
3844 case CHELSIO_T5:
3845 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3846 break;
3847 case CHELSIO_T6:
3848 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3849 break;
3850 default:
3851 pr_err("T%d Chip is not supported\n",
3852 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3853 goto reject;
3854 }
3855
Vipul Pandyaf079af72013-03-14 05:08:58 +00003856 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003857 eh = (struct ethhdr *)(req + 1);
3858 iph = (struct iphdr *)(eh + 1);
3859 } else {
3860 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3861 iph = (struct iphdr *)(vlan_eh + 1);
3862 skb->vlan_tci = ntohs(cpl->vlan);
3863 }
3864
3865 if (iph->version != 0x4)
3866 goto reject;
3867
3868 tcph = (struct tcphdr *)(iph + 1);
3869 skb_set_network_header(skb, (void *)iph - (void *)rss);
3870 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3871 skb_get(skb);
3872
3873 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3874 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3875 ntohs(tcph->source), iph->tos);
3876
Vipul Pandya830662f2013-07-04 16:10:47 +05303877 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3878 iph->tos);
3879 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003880 pr_err("%s - failed to find dst entry!\n",
3881 __func__);
3882 goto reject;
3883 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003884 neigh = dst_neigh_lookup_skb(dst, skb);
3885
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003886 if (!neigh) {
3887 pr_err("%s - failed to allocate neigh!\n",
3888 __func__);
3889 goto free_dst;
3890 }
3891
Vipul Pandya1cab7752012-12-10 09:30:55 +00003892 if (neigh->dev->flags & IFF_LOOPBACK) {
3893 pdev = ip_dev_find(&init_net, iph->daddr);
3894 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3895 pdev, 0);
3896 pi = (struct port_info *)netdev_priv(pdev);
3897 tx_chan = cxgb4_port_chan(pdev);
3898 dev_put(pdev);
3899 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303900 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003901 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303902 pdev, 0);
3903 pi = (struct port_info *)netdev_priv(pdev);
3904 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003905 }
Steve Wiseebf00062014-03-19 17:44:40 +05303906 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003907 if (!e) {
3908 pr_err("%s - failed to allocate l2t entry!\n",
3909 __func__);
3910 goto free_dst;
3911 }
3912
3913 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3914 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003915 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003916
3917 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303918 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3919 dev->rdev.lldi.ports[0],
3920 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003921
3922 /*
3923 * Synthesize the cpl_pass_accept_req. We have everything except the
3924 * TID. Once firmware sends a reply with TID we update the TID field
3925 * in cpl and pass it through the regular cpl_pass_accept_req path.
3926 */
3927 build_cpl_pass_accept_req(skb, stid, iph->tos);
3928 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3929 tcph->source, ntohl(tcph->seq), filter, window,
3930 rss_qid, pi->port_id);
3931 cxgb4_l2t_release(e);
3932free_dst:
3933 dst_release(dst);
3934reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003935 return 0;
3936}
3937
Steve Wisecfdda9d2010-04-21 15:30:06 -07003938/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003939 * These are the real handlers that are called from a
3940 * work queue.
3941 */
3942static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3943 [CPL_ACT_ESTABLISH] = act_establish,
3944 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3945 [CPL_RX_DATA] = rx_data,
3946 [CPL_ABORT_RPL_RSS] = abort_rpl,
3947 [CPL_ABORT_RPL] = abort_rpl,
3948 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3949 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3950 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3951 [CPL_PASS_ESTABLISH] = pass_establish,
3952 [CPL_PEER_CLOSE] = peer_close,
3953 [CPL_ABORT_REQ_RSS] = peer_abort,
3954 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3955 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003956 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003957 [CPL_FW6_MSG] = deferred_fw6_msg,
3958 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003959};
3960
3961static void process_timeout(struct c4iw_ep *ep)
3962{
3963 struct c4iw_qp_attributes attrs;
3964 int abort = 1;
3965
Steve Wise2f5b48c2010-09-10 11:15:36 -05003966 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003967 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3968 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003969 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003970 switch (ep->com.state) {
3971 case MPA_REQ_SENT:
3972 __state_set(&ep->com, ABORTING);
3973 connect_reply_upcall(ep, -ETIMEDOUT);
3974 break;
3975 case MPA_REQ_WAIT:
3976 __state_set(&ep->com, ABORTING);
3977 break;
3978 case CLOSING:
3979 case MORIBUND:
3980 if (ep->com.cm_id && ep->com.qp) {
3981 attrs.next_state = C4IW_QP_STATE_ERROR;
3982 c4iw_modify_qp(ep->com.qp->rhp,
3983 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3984 &attrs, 1);
3985 }
3986 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303987 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003988 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003989 case ABORTING:
3990 case DEAD:
3991
3992 /*
3993 * These states are expected if the ep timed out at the same
3994 * time as another thread was calling stop_ep_timer().
3995 * So we silently do nothing for these states.
3996 */
3997 abort = 0;
3998 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003999 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004000 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004001 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004002 abort = 0;
4003 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004004 if (abort)
4005 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecc18b932014-04-24 14:31:53 -05004006 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004007 c4iw_put_ep(&ep->com);
4008}
4009
4010static void process_timedout_eps(void)
4011{
4012 struct c4iw_ep *ep;
4013
4014 spin_lock_irq(&timeout_lock);
4015 while (!list_empty(&timeout_list)) {
4016 struct list_head *tmp;
4017
4018 tmp = timeout_list.next;
4019 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004020 tmp->next = NULL;
4021 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004022 spin_unlock_irq(&timeout_lock);
4023 ep = list_entry(tmp, struct c4iw_ep, entry);
4024 process_timeout(ep);
4025 spin_lock_irq(&timeout_lock);
4026 }
4027 spin_unlock_irq(&timeout_lock);
4028}
4029
4030static void process_work(struct work_struct *work)
4031{
4032 struct sk_buff *skb = NULL;
4033 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004034 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004035 unsigned int opcode;
4036 int ret;
4037
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004038 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004039 while ((skb = skb_dequeue(&rxq))) {
4040 rpl = cplhdr(skb);
4041 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4042 opcode = rpl->ot.opcode;
4043
4044 BUG_ON(!work_handlers[opcode]);
4045 ret = work_handlers[opcode](dev, skb);
4046 if (!ret)
4047 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004048 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004049 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004050}
4051
4052static DECLARE_WORK(skb_work, process_work);
4053
4054static void ep_timeout(unsigned long arg)
4055{
4056 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004057 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004058
4059 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004060 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004061 /*
4062 * Only insert if it is not already on the list.
4063 */
4064 if (!ep->entry.next) {
4065 list_add_tail(&ep->entry, &timeout_list);
4066 kickit = 1;
4067 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004068 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004069 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004070 if (kickit)
4071 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004072}
4073
4074/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004075 * All the CM events are handled on a work queue to have a safe context.
4076 */
4077static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4078{
4079
4080 /*
4081 * Save dev in the skb->cb area.
4082 */
4083 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4084
4085 /*
4086 * Queue the skb and schedule the worker thread.
4087 */
4088 skb_queue_tail(&rxq, skb);
4089 queue_work(workq, &skb_work);
4090 return 0;
4091}
4092
4093static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4094{
4095 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4096
4097 if (rpl->status != CPL_ERR_NONE) {
4098 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4099 "for tid %u\n", rpl->status, GET_TID(rpl));
4100 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004101 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004102 return 0;
4103}
4104
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004105static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4106{
4107 struct cpl_fw6_msg *rpl = cplhdr(skb);
4108 struct c4iw_wr_wait *wr_waitp;
4109 int ret;
4110
4111 PDBG("%s type %u\n", __func__, rpl->type);
4112
4113 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004114 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004115 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004116 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004117 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004118 if (wr_waitp)
4119 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004120 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004121 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004122 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004123 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004124 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004125 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004126 default:
4127 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4128 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004129 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004130 break;
4131 }
4132 return 0;
4133}
4134
Steve Wise8da7e7a2011-06-14 20:59:27 +00004135static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4136{
4137 struct cpl_abort_req_rss *req = cplhdr(skb);
4138 struct c4iw_ep *ep;
4139 struct tid_info *t = dev->rdev.lldi.tids;
4140 unsigned int tid = GET_TID(req);
4141
4142 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05004143 if (!ep) {
4144 printk(KERN_WARNING MOD
4145 "Abort on non-existent endpoint, tid %d\n", tid);
4146 kfree_skb(skb);
4147 return 0;
4148 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304149 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304150 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4151 __func__, ep->hwtid, req->status,
4152 neg_adv_str(req->status));
4153 ep->stats.abort_neg_adv++;
4154 dev->rdev.stats.neg_adv++;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004155 kfree_skb(skb);
4156 return 0;
4157 }
4158 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4159 ep->com.state);
4160
4161 /*
4162 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004163 * However, if we are on MPAv2 and want to retry with MPAv1
4164 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004165 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004166 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4167 if (ep->com.state != MPA_REQ_SENT)
4168 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4169 } else
4170 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00004171 sched(dev, skb);
4172 return 0;
4173}
4174
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004175/*
4176 * Most upcalls from the T4 Core go to sched() to
4177 * schedule the processing on a work queue.
4178 */
4179c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4180 [CPL_ACT_ESTABLISH] = sched,
4181 [CPL_ACT_OPEN_RPL] = sched,
4182 [CPL_RX_DATA] = sched,
4183 [CPL_ABORT_RPL_RSS] = sched,
4184 [CPL_ABORT_RPL] = sched,
4185 [CPL_PASS_OPEN_RPL] = sched,
4186 [CPL_CLOSE_LISTSRV_RPL] = sched,
4187 [CPL_PASS_ACCEPT_REQ] = sched,
4188 [CPL_PASS_ESTABLISH] = sched,
4189 [CPL_PEER_CLOSE] = sched,
4190 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004191 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004192 [CPL_RDMA_TERMINATE] = sched,
4193 [CPL_FW4_ACK] = sched,
4194 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004195 [CPL_FW6_MSG] = fw6_msg,
4196 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004197};
4198
Steve Wisecfdda9d2010-04-21 15:30:06 -07004199int __init c4iw_cm_init(void)
4200{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004201 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004202 skb_queue_head_init(&rxq);
4203
4204 workq = create_singlethread_workqueue("iw_cxgb4");
4205 if (!workq)
4206 return -ENOMEM;
4207
Steve Wisecfdda9d2010-04-21 15:30:06 -07004208 return 0;
4209}
4210
Steve Wise46c13762014-06-20 14:26:25 -05004211void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004212{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004213 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004214 flush_workqueue(workq);
4215 destroy_workqueue(workq);
4216}