blob: 6fb31bacd5b4fbfe2d34146e789c06209104c129 [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"
53
54static char *states[] = {
55 "idle",
56 "listen",
57 "connecting",
58 "mpa_wait_req",
59 "mpa_req_sent",
60 "mpa_req_rcvd",
61 "mpa_rep_sent",
62 "fpdu_mode",
63 "aborting",
64 "closing",
65 "moribund",
66 "dead",
67 NULL,
68};
69
Vipul Pandya5be78ee2012-12-10 09:30:54 +000070static int nocong;
71module_param(nocong, int, 0644);
72MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
73
74static int enable_ecn;
75module_param(enable_ecn, int, 0644);
76MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
77
Steve Wiseb52fe092011-03-11 22:30:01 +000078static int dack_mode = 1;
Steve Wiseba6d3922010-06-23 15:46:49 +000079module_param(dack_mode, int, 0644);
Steve Wiseb52fe092011-03-11 22:30:01 +000080MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
Steve Wiseba6d3922010-06-23 15:46:49 +000081
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053082uint c4iw_max_read_depth = 32;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070083module_param(c4iw_max_read_depth, int, 0644);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053084MODULE_PARM_DESC(c4iw_max_read_depth,
85 "Per-connection max ORD/IRD (default=32)");
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070086
Steve Wisecfdda9d2010-04-21 15:30:06 -070087static int enable_tcp_timestamps;
88module_param(enable_tcp_timestamps, int, 0644);
89MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
90
91static int enable_tcp_sack;
92module_param(enable_tcp_sack, int, 0644);
93MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
94
95static int enable_tcp_window_scaling = 1;
96module_param(enable_tcp_window_scaling, int, 0644);
97MODULE_PARM_DESC(enable_tcp_window_scaling,
98 "Enable tcp window scaling (default=1)");
99
100int c4iw_debug;
101module_param(c4iw_debug, int, 0644);
102MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
103
Steve Wisedf2d5132014-03-19 17:44:44 +0530104static int peer2peer = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700105module_param(peer2peer, int, 0644);
Steve Wisedf2d5132014-03-19 17:44:44 +0530106MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700107
108static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
109module_param(p2p_type, int, 0644);
110MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
111 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
112
113static int ep_timeout_secs = 60;
114module_param(ep_timeout_secs, int, 0644);
115MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
116 "in seconds (default=60)");
117
118static int mpa_rev = 1;
119module_param(mpa_rev, int, 0644);
120MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530121 "1 is RFC0544 spec compliant, 2 is IETF MPA Peer Connect Draft"
122 " compliant (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700123
124static int markers_enabled;
125module_param(markers_enabled, int, 0644);
126MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
127
128static int crc_enabled = 1;
129module_param(crc_enabled, int, 0644);
130MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
131
132static int rcv_win = 256 * 1024;
133module_param(rcv_win, int, 0644);
134MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
135
Steve Wise98ae68b2010-09-10 11:15:41 -0500136static int snd_win = 128 * 1024;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700137module_param(snd_win, int, 0644);
Steve Wise98ae68b2010-09-10 11:15:41 -0500138MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700139
Steve Wisecfdda9d2010-04-21 15:30:06 -0700140static struct workqueue_struct *workq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700141
142static struct sk_buff_head rxq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700143
144static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
145static void ep_timeout(unsigned long arg);
146static void connect_reply_upcall(struct c4iw_ep *ep, int status);
147
Roland Dreierbe4c9ba2010-05-05 14:45:40 -0700148static LIST_HEAD(timeout_list);
149static spinlock_t timeout_lock;
150
Vipul Pandya325abea2013-01-07 13:11:53 +0000151static void deref_qp(struct c4iw_ep *ep)
152{
153 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
154 clear_bit(QP_REFERENCED, &ep->com.flags);
155}
156
157static void ref_qp(struct c4iw_ep *ep)
158{
159 set_bit(QP_REFERENCED, &ep->com.flags);
160 c4iw_qp_add_ref(&ep->com.qp->ibqp);
161}
162
Steve Wisecfdda9d2010-04-21 15:30:06 -0700163static void start_ep_timer(struct c4iw_ep *ep)
164{
165 PDBG("%s ep %p\n", __func__, ep);
166 if (timer_pending(&ep->timer)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000167 pr_err("%s timer already started! ep %p\n",
168 __func__, ep);
169 return;
170 }
171 clear_bit(TIMEOUT, &ep->com.flags);
172 c4iw_get_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700173 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
174 ep->timer.data = (unsigned long)ep;
175 ep->timer.function = ep_timeout;
176 add_timer(&ep->timer);
177}
178
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500179static int stop_ep_timer(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700180{
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000181 PDBG("%s ep %p stopping\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700182 del_timer_sync(&ep->timer);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500183 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000184 c4iw_put_ep(&ep->com);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500185 return 0;
186 }
187 return 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700188}
189
190static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
191 struct l2t_entry *l2e)
192{
193 int error = 0;
194
195 if (c4iw_fatal_error(rdev)) {
196 kfree_skb(skb);
197 PDBG("%s - device in error state - dropping\n", __func__);
198 return -EIO;
199 }
200 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
201 if (error < 0)
202 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500203 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700204}
205
206int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
207{
208 int error = 0;
209
210 if (c4iw_fatal_error(rdev)) {
211 kfree_skb(skb);
212 PDBG("%s - device in error state - dropping\n", __func__);
213 return -EIO;
214 }
215 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
216 if (error < 0)
217 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500218 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700219}
220
221static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
222{
223 struct cpl_tid_release *req;
224
225 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
226 if (!skb)
227 return;
228 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
229 INIT_TP_WR(req, hwtid);
230 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
231 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
232 c4iw_ofld_send(rdev, skb);
233 return;
234}
235
236static void set_emss(struct c4iw_ep *ep, u16 opt)
237{
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800238 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
Hariprasad S04524a42014-09-24 03:53:41 +0530239 ((AF_INET == ep->com.remote_addr.ss_family) ?
240 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
241 sizeof(struct tcphdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700242 ep->mss = ep->emss;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800243 if (TCPOPT_TSTAMP_G(opt))
Hariprasad S04524a42014-09-24 03:53:41 +0530244 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700245 if (ep->emss < 128)
246 ep->emss = 128;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530247 if (ep->emss & 7)
248 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800249 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
250 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt),
Steve Wisecfdda9d2010-04-21 15:30:06 -0700251 ep->mss, ep->emss);
252}
253
254static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
255{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700256 enum c4iw_ep_state state;
257
Steve Wise2f5b48c2010-09-10 11:15:36 -0500258 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700259 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500260 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700261 return state;
262}
263
264static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
265{
266 epc->state = new;
267}
268
269static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
270{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500271 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700272 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
273 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500274 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700275 return;
276}
277
278static void *alloc_ep(int size, gfp_t gfp)
279{
280 struct c4iw_ep_common *epc;
281
282 epc = kzalloc(size, gfp);
283 if (epc) {
284 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500285 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500286 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700287 }
288 PDBG("%s alloc ep %p\n", __func__, epc);
289 return epc;
290}
291
292void _c4iw_free_ep(struct kref *kref)
293{
294 struct c4iw_ep *ep;
295
296 ep = container_of(kref, struct c4iw_ep, com.kref);
297 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000298 if (test_bit(QP_REFERENCED, &ep->com.flags))
299 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700300 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000301 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700302 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
303 dst_release(ep->dst);
304 cxgb4_l2t_release(ep->l2t);
305 }
Steve Wise9eccfe12014-03-26 17:08:09 -0500306 if (test_bit(RELEASE_MAPINFO, &ep->com.flags)) {
307 print_addr(&ep->com, __func__, "remove_mapinfo/mapping");
308 iwpm_remove_mapinfo(&ep->com.local_addr,
309 &ep->com.mapped_local_addr);
310 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
311 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700312 kfree(ep);
313}
314
315static void release_ep_resources(struct c4iw_ep *ep)
316{
317 set_bit(RELEASE_RESOURCES, &ep->com.flags);
318 c4iw_put_ep(&ep->com);
319}
320
Steve Wisecfdda9d2010-04-21 15:30:06 -0700321static int status2errno(int status)
322{
323 switch (status) {
324 case CPL_ERR_NONE:
325 return 0;
326 case CPL_ERR_CONN_RESET:
327 return -ECONNRESET;
328 case CPL_ERR_ARP_MISS:
329 return -EHOSTUNREACH;
330 case CPL_ERR_CONN_TIMEDOUT:
331 return -ETIMEDOUT;
332 case CPL_ERR_TCAM_FULL:
333 return -ENOMEM;
334 case CPL_ERR_CONN_EXIST:
335 return -EADDRINUSE;
336 default:
337 return -EIO;
338 }
339}
340
341/*
342 * Try and reuse skbs already allocated...
343 */
344static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
345{
346 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
347 skb_trim(skb, 0);
348 skb_get(skb);
349 skb_reset_transport_header(skb);
350 } else {
351 skb = alloc_skb(len, gfp);
352 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530353 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700354 return skb;
355}
356
Vipul Pandya830662f2013-07-04 16:10:47 +0530357static struct net_device *get_real_dev(struct net_device *egress_dev)
358{
Steve Wise11b8e222014-05-16 12:42:46 -0500359 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530360}
361
362static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
363{
364 int i;
365
366 egress_dev = get_real_dev(egress_dev);
367 for (i = 0; i < dev->rdev.lldi.nports; i++)
368 if (dev->rdev.lldi.ports[i] == egress_dev)
369 return 1;
370 return 0;
371}
372
373static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
374 __u8 *peer_ip, __be16 local_port,
375 __be16 peer_port, u8 tos,
376 __u32 sin6_scope_id)
377{
378 struct dst_entry *dst = NULL;
379
380 if (IS_ENABLED(CONFIG_IPV6)) {
381 struct flowi6 fl6;
382
383 memset(&fl6, 0, sizeof(fl6));
384 memcpy(&fl6.daddr, peer_ip, 16);
385 memcpy(&fl6.saddr, local_ip, 16);
386 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
387 fl6.flowi6_oif = sin6_scope_id;
388 dst = ip6_route_output(&init_net, NULL, &fl6);
389 if (!dst)
390 goto out;
391 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
392 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
393 dst_release(dst);
394 dst = NULL;
395 }
396 }
397
398out:
399 return dst;
400}
401
402static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700403 __be32 peer_ip, __be16 local_port,
404 __be16 peer_port, u8 tos)
405{
406 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700407 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530408 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700409
David S. Miller31e4543d2011-05-03 20:25:42 -0700410 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500411 peer_port, local_port, IPPROTO_TCP,
412 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800413 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700414 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530415 n = dst_neigh_lookup(&rt->dst, &peer_ip);
416 if (!n)
417 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530418 if (!our_interface(dev, n->dev) &&
419 !(n->dev->flags & IFF_LOOPBACK)) {
Hariprasad Sd4802012014-09-24 03:53:42 +0530420 neigh_release(n);
Vipul Pandya830662f2013-07-04 16:10:47 +0530421 dst_release(&rt->dst);
422 return NULL;
423 }
424 neigh_release(n);
425 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700426}
427
428static void arp_failure_discard(void *handle, struct sk_buff *skb)
429{
430 PDBG("%s c4iw_dev %p\n", __func__, handle);
431 kfree_skb(skb);
432}
433
434/*
435 * Handle an ARP failure for an active open.
436 */
437static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
438{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530439 struct c4iw_ep *ep = handle;
440
Steve Wisecfdda9d2010-04-21 15:30:06 -0700441 printk(KERN_ERR MOD "ARP failure duing connect\n");
442 kfree_skb(skb);
Hariprasad S5dab6d32014-06-23 19:12:36 +0530443 connect_reply_upcall(ep, -EHOSTUNREACH);
444 state_set(&ep->com, DEAD);
445 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
446 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
447 dst_release(ep->dst);
448 cxgb4_l2t_release(ep->l2t);
449 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700450}
451
452/*
453 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
454 * and send it along.
455 */
456static void abort_arp_failure(void *handle, struct sk_buff *skb)
457{
458 struct c4iw_rdev *rdev = handle;
459 struct cpl_abort_req *req = cplhdr(skb);
460
461 PDBG("%s rdev %p\n", __func__, rdev);
462 req->cmd = CPL_ABORT_NO_RST;
463 c4iw_ofld_send(rdev, skb);
464}
465
466static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
467{
468 unsigned int flowclen = 80;
469 struct fw_flowc_wr *flowc;
470 int i;
471
472 skb = get_skb(skb, flowclen, GFP_KERNEL);
473 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
474
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530475 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
476 FW_FLOWC_WR_NPARAMS_V(8));
477 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(flowclen,
478 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700479
480 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530481 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530482 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700483 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
484 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
485 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
486 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
487 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
488 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
489 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
490 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
491 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
492 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
493 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530494 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700495 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
496 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
497 /* Pad WR to 16 byte boundary */
498 flowc->mnemval[8].mnemonic = 0;
499 flowc->mnemval[8].val = 0;
500 for (i = 0; i < 9; i++) {
501 flowc->mnemval[i].r4[0] = 0;
502 flowc->mnemval[i].r4[1] = 0;
503 flowc->mnemval[i].r4[2] = 0;
504 }
505
506 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
507 c4iw_ofld_send(&ep->com.dev->rdev, skb);
508}
509
510static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
511{
512 struct cpl_close_con_req *req;
513 struct sk_buff *skb;
514 int wrlen = roundup(sizeof *req, 16);
515
516 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
517 skb = get_skb(NULL, wrlen, gfp);
518 if (!skb) {
519 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
520 return -ENOMEM;
521 }
522 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
523 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
524 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
525 memset(req, 0, wrlen);
526 INIT_TP_WR(req, ep->hwtid);
527 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
528 ep->hwtid));
529 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
530}
531
532static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
533{
534 struct cpl_abort_req *req;
535 int wrlen = roundup(sizeof *req, 16);
536
537 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
538 skb = get_skb(skb, wrlen, gfp);
539 if (!skb) {
540 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
541 __func__);
542 return -ENOMEM;
543 }
544 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
545 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
546 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
547 memset(req, 0, wrlen);
548 INIT_TP_WR(req, ep->hwtid);
549 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
550 req->cmd = CPL_ABORT_SEND_RST;
551 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
552}
553
Steve Wise9eccfe12014-03-26 17:08:09 -0500554/*
555 * c4iw_form_pm_msg - Form a port mapper message with mapping info
556 */
557static void c4iw_form_pm_msg(struct c4iw_ep *ep,
558 struct iwpm_sa_data *pm_msg)
559{
560 memcpy(&pm_msg->loc_addr, &ep->com.local_addr,
561 sizeof(ep->com.local_addr));
562 memcpy(&pm_msg->rem_addr, &ep->com.remote_addr,
563 sizeof(ep->com.remote_addr));
564}
565
566/*
567 * c4iw_form_reg_msg - Form a port mapper message with dev info
568 */
569static void c4iw_form_reg_msg(struct c4iw_dev *dev,
570 struct iwpm_dev_data *pm_msg)
571{
572 memcpy(pm_msg->dev_name, dev->ibdev.name, IWPM_DEVNAME_SIZE);
573 memcpy(pm_msg->if_name, dev->rdev.lldi.ports[0]->name,
574 IWPM_IFNAME_SIZE);
575}
576
577static void c4iw_record_pm_msg(struct c4iw_ep *ep,
578 struct iwpm_sa_data *pm_msg)
579{
580 memcpy(&ep->com.mapped_local_addr, &pm_msg->mapped_loc_addr,
581 sizeof(ep->com.mapped_local_addr));
582 memcpy(&ep->com.mapped_remote_addr, &pm_msg->mapped_rem_addr,
583 sizeof(ep->com.mapped_remote_addr));
584}
585
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530586static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530587 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530588{
Hariprasad S04524a42014-09-24 03:53:41 +0530589 unsigned short hdr_size = (ipv6 ?
590 sizeof(struct ipv6hdr) :
591 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530592 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530593 (use_ts ?
594 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530595 unsigned short data_size = mtu - hdr_size;
596
597 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
598}
599
Steve Wisecfdda9d2010-04-21 15:30:06 -0700600static int send_connect(struct c4iw_ep *ep)
601{
602 struct cpl_act_open_req *req;
Vipul Pandyaf079af72013-03-14 05:08:58 +0000603 struct cpl_t5_act_open_req *t5_req;
Vipul Pandya830662f2013-07-04 16:10:47 +0530604 struct cpl_act_open_req6 *req6;
605 struct cpl_t5_act_open_req6 *t5_req6;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700606 struct sk_buff *skb;
607 u64 opt0;
608 u32 opt2;
609 unsigned int mtu_idx;
610 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +0530611 int wrlen;
612 int sizev4 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
613 sizeof(struct cpl_act_open_req) :
614 sizeof(struct cpl_t5_act_open_req);
615 int sizev6 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
616 sizeof(struct cpl_act_open_req6) :
617 sizeof(struct cpl_t5_act_open_req6);
Steve Wise9eccfe12014-03-26 17:08:09 -0500618 struct sockaddr_in *la = (struct sockaddr_in *)
619 &ep->com.mapped_local_addr;
620 struct sockaddr_in *ra = (struct sockaddr_in *)
621 &ep->com.mapped_remote_addr;
622 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
623 &ep->com.mapped_local_addr;
624 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
625 &ep->com.mapped_remote_addr;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530626 int win;
Vipul Pandya830662f2013-07-04 16:10:47 +0530627
628 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
629 roundup(sizev4, 16) :
630 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700631
632 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
633
634 skb = get_skb(NULL, wrlen, GFP_KERNEL);
635 if (!skb) {
636 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
637 __func__);
638 return -ENOMEM;
639 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000640 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700641
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530642 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530643 enable_tcp_timestamps,
644 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700645 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530646
647 /*
648 * Specify the largest window that will fit in opt0. The
649 * remainder will be specified in the rx_data_ack.
650 */
651 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800652 if (win > RCV_BUFSIZ_M)
653 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530654
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800655 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800656 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800657 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800658 WND_SCALE_V(wscale) |
659 MSS_IDX_V(mtu_idx) |
660 L2T_IDX_V(ep->l2t->idx) |
661 TX_CHAN_V(ep->tx_chan) |
662 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800663 DSCP_V(ep->tos) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800664 ULP_MODE_V(ULP_MODE_TCPDDP) |
665 RCV_BUFSIZ_V(win);
666 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800667 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800668 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700669 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800670 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700671 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800672 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700673 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800674 opt2 |= WND_SCALE_EN_F;
Steve Wise92e50112014-04-24 14:31:59 -0500675 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
Anish Bhattd7990b02014-11-12 17:15:57 -0800676 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530677 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530678 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500679 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530680 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700681
Vipul Pandyaf079af72013-03-14 05:08:58 +0000682 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Vipul Pandya830662f2013-07-04 16:10:47 +0530683 if (ep->com.remote_addr.ss_family == AF_INET) {
684 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
685 INIT_TP_WR(req, 0);
686 OPCODE_TID(req) = cpu_to_be32(
Vipul Pandyaf079af72013-03-14 05:08:58 +0000687 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
688 ((ep->rss_qid << 14) | ep->atid)));
Vipul Pandya830662f2013-07-04 16:10:47 +0530689 req->local_port = la->sin_port;
690 req->peer_port = ra->sin_port;
691 req->local_ip = la->sin_addr.s_addr;
692 req->peer_ip = ra->sin_addr.s_addr;
693 req->opt0 = cpu_to_be64(opt0);
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530694 req->params = cpu_to_be32(cxgb4_select_ntuple(
695 ep->com.dev->rdev.lldi.ports[0],
696 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530697 req->opt2 = cpu_to_be32(opt2);
698 } else {
699 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
700
701 INIT_TP_WR(req6, 0);
702 OPCODE_TID(req6) = cpu_to_be32(
703 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
704 ((ep->rss_qid<<14)|ep->atid)));
705 req6->local_port = la6->sin6_port;
706 req6->peer_port = ra6->sin6_port;
707 req6->local_ip_hi = *((__be64 *)
708 (la6->sin6_addr.s6_addr));
709 req6->local_ip_lo = *((__be64 *)
710 (la6->sin6_addr.s6_addr + 8));
711 req6->peer_ip_hi = *((__be64 *)
712 (ra6->sin6_addr.s6_addr));
713 req6->peer_ip_lo = *((__be64 *)
714 (ra6->sin6_addr.s6_addr + 8));
715 req6->opt0 = cpu_to_be64(opt0);
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530716 req6->params = cpu_to_be32(cxgb4_select_ntuple(
717 ep->com.dev->rdev.lldi.ports[0],
718 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530719 req6->opt2 = cpu_to_be32(opt2);
720 }
721 } else {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530722 u32 isn = (prandom_u32() & ~7UL) - 1;
723
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530724 if (peer2peer)
725 isn += 4;
726
Vipul Pandya830662f2013-07-04 16:10:47 +0530727 if (ep->com.remote_addr.ss_family == AF_INET) {
728 t5_req = (struct cpl_t5_act_open_req *)
729 skb_put(skb, wrlen);
730 INIT_TP_WR(t5_req, 0);
731 OPCODE_TID(t5_req) = cpu_to_be32(
732 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
733 ((ep->rss_qid << 14) | ep->atid)));
734 t5_req->local_port = la->sin_port;
735 t5_req->peer_port = ra->sin_port;
736 t5_req->local_ip = la->sin_addr.s_addr;
737 t5_req->peer_ip = ra->sin_addr.s_addr;
738 t5_req->opt0 = cpu_to_be64(opt0);
Anish Bhattd7990b02014-11-12 17:15:57 -0800739 t5_req->params = cpu_to_be64(FILTER_TUPLE_V(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530740 cxgb4_select_ntuple(
741 ep->com.dev->rdev.lldi.ports[0],
742 ep->l2t)));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530743 t5_req->rsvd = cpu_to_be32(isn);
744 PDBG("%s snd_isn %u\n", __func__,
745 be32_to_cpu(t5_req->rsvd));
Vipul Pandya830662f2013-07-04 16:10:47 +0530746 t5_req->opt2 = cpu_to_be32(opt2);
747 } else {
748 t5_req6 = (struct cpl_t5_act_open_req6 *)
749 skb_put(skb, wrlen);
750 INIT_TP_WR(t5_req6, 0);
751 OPCODE_TID(t5_req6) = cpu_to_be32(
752 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
753 ((ep->rss_qid<<14)|ep->atid)));
754 t5_req6->local_port = la6->sin6_port;
755 t5_req6->peer_port = ra6->sin6_port;
756 t5_req6->local_ip_hi = *((__be64 *)
757 (la6->sin6_addr.s6_addr));
758 t5_req6->local_ip_lo = *((__be64 *)
759 (la6->sin6_addr.s6_addr + 8));
760 t5_req6->peer_ip_hi = *((__be64 *)
761 (ra6->sin6_addr.s6_addr));
762 t5_req6->peer_ip_lo = *((__be64 *)
763 (ra6->sin6_addr.s6_addr + 8));
764 t5_req6->opt0 = cpu_to_be64(opt0);
Anish Bhattd7990b02014-11-12 17:15:57 -0800765 t5_req6->params = cpu_to_be64(FILTER_TUPLE_V(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530766 cxgb4_select_ntuple(
767 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530768 ep->l2t)));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530769 t5_req6->rsvd = cpu_to_be32(isn);
770 PDBG("%s snd_isn %u\n", __func__,
771 be32_to_cpu(t5_req6->rsvd));
Vipul Pandya830662f2013-07-04 16:10:47 +0530772 t5_req6->opt2 = cpu_to_be32(opt2);
773 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000774 }
775
Vipul Pandya793dad92012-12-10 09:30:56 +0000776 set_bit(ACT_OPEN_REQ, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700777 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
778}
779
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530780static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
781 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700782{
783 int mpalen, wrlen;
784 struct fw_ofld_tx_data_wr *req;
785 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530786 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700787
788 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
789
790 BUG_ON(skb_cloned(skb));
791
792 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530793 if (mpa_rev_to_use == 2)
794 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700795 wrlen = roundup(mpalen + sizeof *req, 16);
796 skb = get_skb(skb, wrlen, GFP_KERNEL);
797 if (!skb) {
798 connect_reply_upcall(ep, -ENOMEM);
799 return;
800 }
801 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
802
803 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
804 memset(req, 0, wrlen);
805 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530806 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
807 FW_WR_COMPL_F |
808 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700809 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530810 FW_WR_FLOWID_V(ep->hwtid) |
811 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700812 req->plen = cpu_to_be32(mpalen);
813 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530814 FW_OFLD_TX_DATA_WR_FLUSH_F |
815 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700816
817 mpa = (struct mpa_message *)(req + 1);
818 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
819 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530820 (markers_enabled ? MPA_MARKERS : 0) |
821 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700822 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530823 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530824 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530825 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530826 ep->retry_with_mpa_v1 = 0;
827 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700828
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530829 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700830 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
831 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530832 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
833 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530834 mpa_v2_params.ird = htons((u16)ep->ird);
835 mpa_v2_params.ord = htons((u16)ep->ord);
836
837 if (peer2peer) {
838 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
839 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
840 mpa_v2_params.ord |=
841 htons(MPA_V2_RDMA_WRITE_RTR);
842 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
843 mpa_v2_params.ord |=
844 htons(MPA_V2_RDMA_READ_RTR);
845 }
846 memcpy(mpa->private_data, &mpa_v2_params,
847 sizeof(struct mpa_v2_conn_params));
848
849 if (ep->plen)
850 memcpy(mpa->private_data +
851 sizeof(struct mpa_v2_conn_params),
852 ep->mpa_pkt + sizeof(*mpa), ep->plen);
853 } else
854 if (ep->plen)
855 memcpy(mpa->private_data,
856 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700857
858 /*
859 * Reference the mpa skb. This ensures the data area
860 * will remain in memory until the hw acks the tx.
861 * Function fw4_ack() will deref it.
862 */
863 skb_get(skb);
864 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
865 BUG_ON(ep->mpa_skb);
866 ep->mpa_skb = skb;
867 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
868 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530869 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700870 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530871 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700872 return;
873}
874
875static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
876{
877 int mpalen, wrlen;
878 struct fw_ofld_tx_data_wr *req;
879 struct mpa_message *mpa;
880 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530881 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700882
883 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
884
885 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530886 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
887 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700888 wrlen = roundup(mpalen + sizeof *req, 16);
889
890 skb = get_skb(NULL, wrlen, GFP_KERNEL);
891 if (!skb) {
892 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
893 return -ENOMEM;
894 }
895 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
896
897 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
898 memset(req, 0, wrlen);
899 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530900 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
901 FW_WR_COMPL_F |
902 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700903 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530904 FW_WR_FLOWID_V(ep->hwtid) |
905 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700906 req->plen = cpu_to_be32(mpalen);
907 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530908 FW_OFLD_TX_DATA_WR_FLUSH_F |
909 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700910
911 mpa = (struct mpa_message *)(req + 1);
912 memset(mpa, 0, sizeof(*mpa));
913 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
914 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000915 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700916 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530917
918 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
919 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700920 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
921 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530922 mpa_v2_params.ird = htons(((u16)ep->ird) |
923 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
924 0));
925 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
926 (p2p_type ==
927 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
928 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
929 FW_RI_INIT_P2PTYPE_READ_REQ ?
930 MPA_V2_RDMA_READ_RTR : 0) : 0));
931 memcpy(mpa->private_data, &mpa_v2_params,
932 sizeof(struct mpa_v2_conn_params));
933
934 if (ep->plen)
935 memcpy(mpa->private_data +
936 sizeof(struct mpa_v2_conn_params), pdata, plen);
937 } else
938 if (plen)
939 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700940
941 /*
942 * Reference the mpa skb again. This ensures the data area
943 * will remain in memory until the hw acks the tx.
944 * Function fw4_ack() will deref it.
945 */
946 skb_get(skb);
947 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
948 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
949 BUG_ON(ep->mpa_skb);
950 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +0530951 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700952 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
953}
954
955static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
956{
957 int mpalen, wrlen;
958 struct fw_ofld_tx_data_wr *req;
959 struct mpa_message *mpa;
960 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530961 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700962
963 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
964
965 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530966 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
967 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700968 wrlen = roundup(mpalen + sizeof *req, 16);
969
970 skb = get_skb(NULL, wrlen, GFP_KERNEL);
971 if (!skb) {
972 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
973 return -ENOMEM;
974 }
975 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
976
977 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
978 memset(req, 0, wrlen);
979 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530980 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
981 FW_WR_COMPL_F |
982 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700983 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530984 FW_WR_FLOWID_V(ep->hwtid) |
985 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700986 req->plen = cpu_to_be32(mpalen);
987 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530988 FW_OFLD_TX_DATA_WR_FLUSH_F |
989 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700990
991 mpa = (struct mpa_message *)(req + 1);
992 memset(mpa, 0, sizeof(*mpa));
993 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
994 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
995 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530996 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700997 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530998
999 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1000 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001001 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1002 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301003 mpa_v2_params.ird = htons((u16)ep->ird);
1004 mpa_v2_params.ord = htons((u16)ep->ord);
1005 if (peer2peer && (ep->mpa_attr.p2p_type !=
1006 FW_RI_INIT_P2PTYPE_DISABLED)) {
1007 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1008
1009 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1010 mpa_v2_params.ord |=
1011 htons(MPA_V2_RDMA_WRITE_RTR);
1012 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1013 mpa_v2_params.ord |=
1014 htons(MPA_V2_RDMA_READ_RTR);
1015 }
1016
1017 memcpy(mpa->private_data, &mpa_v2_params,
1018 sizeof(struct mpa_v2_conn_params));
1019
1020 if (ep->plen)
1021 memcpy(mpa->private_data +
1022 sizeof(struct mpa_v2_conn_params), pdata, plen);
1023 } else
1024 if (plen)
1025 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001026
1027 /*
1028 * Reference the mpa skb. This ensures the data area
1029 * will remain in memory until the hw acks the tx.
1030 * Function fw4_ack() will deref it.
1031 */
1032 skb_get(skb);
1033 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1034 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301035 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301036 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001037 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1038}
1039
1040static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1041{
1042 struct c4iw_ep *ep;
1043 struct cpl_act_establish *req = cplhdr(skb);
1044 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001045 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001046 struct tid_info *t = dev->rdev.lldi.tids;
1047
1048 ep = lookup_atid(t, atid);
1049
1050 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1051 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1052
Steve Wisea7db89e2014-03-21 20:40:35 +05301053 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001054 dst_confirm(ep->dst);
1055
1056 /* setup the hwtid for this connection */
1057 ep->hwtid = tid;
1058 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001059 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001060
1061 ep->snd_seq = be32_to_cpu(req->snd_isn);
1062 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1063
1064 set_emss(ep, ntohs(req->tcp_opt));
1065
1066 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001067 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001068 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001069 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001070
1071 /* start MPA negotiation */
1072 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301073 if (ep->retry_with_mpa_v1)
1074 send_mpa_req(ep, skb, 1);
1075 else
1076 send_mpa_req(ep, skb, mpa_rev);
Steve Wisea7db89e2014-03-21 20:40:35 +05301077 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001078 return 0;
1079}
1080
Steve Wisebe13b2d2014-03-21 20:40:33 +05301081static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001082{
1083 struct iw_cm_event event;
1084
1085 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1086 memset(&event, 0, sizeof(event));
1087 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301088 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001089 if (ep->com.cm_id) {
1090 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1091 ep, ep->com.cm_id, ep->hwtid);
1092 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1093 ep->com.cm_id->rem_ref(ep->com.cm_id);
1094 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001095 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001096 }
1097}
1098
1099static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
1100{
1101 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecc18b932014-04-24 14:31:53 -05001102 __state_set(&ep->com, ABORTING);
Vipul Pandya793dad92012-12-10 09:30:56 +00001103 set_bit(ABORT_CONN, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001104 return send_abort(ep, skb, gfp);
1105}
1106
1107static void peer_close_upcall(struct c4iw_ep *ep)
1108{
1109 struct iw_cm_event event;
1110
1111 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1112 memset(&event, 0, sizeof(event));
1113 event.event = IW_CM_EVENT_DISCONNECT;
1114 if (ep->com.cm_id) {
1115 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1116 ep, ep->com.cm_id, ep->hwtid);
1117 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001118 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001119 }
1120}
1121
1122static void peer_abort_upcall(struct c4iw_ep *ep)
1123{
1124 struct iw_cm_event event;
1125
1126 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1127 memset(&event, 0, sizeof(event));
1128 event.event = IW_CM_EVENT_CLOSE;
1129 event.status = -ECONNRESET;
1130 if (ep->com.cm_id) {
1131 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1132 ep->com.cm_id, ep->hwtid);
1133 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1134 ep->com.cm_id->rem_ref(ep->com.cm_id);
1135 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001136 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001137 }
1138}
1139
1140static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1141{
1142 struct iw_cm_event event;
1143
1144 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1145 memset(&event, 0, sizeof(event));
1146 event.event = IW_CM_EVENT_CONNECT_REPLY;
1147 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301148 memcpy(&event.local_addr, &ep->com.local_addr,
1149 sizeof(ep->com.local_addr));
1150 memcpy(&event.remote_addr, &ep->com.remote_addr,
1151 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001152
1153 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301154 if (!ep->tried_with_mpa_v1) {
1155 /* this means MPA_v2 is used */
1156 event.private_data_len = ep->plen -
1157 sizeof(struct mpa_v2_conn_params);
1158 event.private_data = ep->mpa_pkt +
1159 sizeof(struct mpa_message) +
1160 sizeof(struct mpa_v2_conn_params);
1161 } else {
1162 /* this means MPA_v1 is used */
1163 event.private_data_len = ep->plen;
1164 event.private_data = ep->mpa_pkt +
1165 sizeof(struct mpa_message);
1166 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001167 }
Roland Dreier85963e42010-07-19 13:13:09 -07001168
1169 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1170 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001171 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001172 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1173
Steve Wisecfdda9d2010-04-21 15:30:06 -07001174 if (status < 0) {
1175 ep->com.cm_id->rem_ref(ep->com.cm_id);
1176 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001177 }
1178}
1179
Steve Wisebe13b2d2014-03-21 20:40:33 +05301180static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001181{
1182 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301183 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001184
1185 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1186 memset(&event, 0, sizeof(event));
1187 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301188 memcpy(&event.local_addr, &ep->com.local_addr,
1189 sizeof(ep->com.local_addr));
1190 memcpy(&event.remote_addr, &ep->com.remote_addr,
1191 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001192 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301193 if (!ep->tried_with_mpa_v1) {
1194 /* this means MPA_v2 is used */
1195 event.ord = ep->ord;
1196 event.ird = ep->ird;
1197 event.private_data_len = ep->plen -
1198 sizeof(struct mpa_v2_conn_params);
1199 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1200 sizeof(struct mpa_v2_conn_params);
1201 } else {
1202 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301203 event.ord = cur_max_read_depth(ep->com.dev);
1204 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301205 event.private_data_len = ep->plen;
1206 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1207 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301208 c4iw_get_ep(&ep->com);
1209 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1210 &event);
1211 if (ret)
1212 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001213 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001214 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301215 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001216}
1217
1218static void established_upcall(struct c4iw_ep *ep)
1219{
1220 struct iw_cm_event event;
1221
1222 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1223 memset(&event, 0, sizeof(event));
1224 event.event = IW_CM_EVENT_ESTABLISHED;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301225 event.ird = ep->ird;
1226 event.ord = ep->ord;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001227 if (ep->com.cm_id) {
1228 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1229 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001230 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001231 }
1232}
1233
1234static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1235{
1236 struct cpl_rx_data_ack *req;
1237 struct sk_buff *skb;
1238 int wrlen = roundup(sizeof *req, 16);
1239
1240 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1241 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1242 if (!skb) {
1243 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1244 return 0;
1245 }
1246
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301247 /*
1248 * If we couldn't specify the entire rcv window at connection setup
1249 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1250 * then add the overage in to the credits returned.
1251 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001252 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1253 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301254
Steve Wisecfdda9d2010-04-21 15:30:06 -07001255 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1256 memset(req, 0, wrlen);
1257 INIT_TP_WR(req, ep->hwtid);
1258 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1259 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001260 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301261 RX_DACK_CHANGE_F |
1262 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001263 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001264 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1265 return credits;
1266}
1267
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301268#define RELAXED_IRD_NEGOTIATION 1
1269
Steve Wisecc18b932014-04-24 14:31:53 -05001270static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001271{
1272 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301273 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001274 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301275 u16 resp_ird, resp_ord;
1276 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001277 struct c4iw_qp_attributes attrs;
1278 enum c4iw_qp_attr_mask mask;
1279 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001280 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001281
1282 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1283
1284 /*
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001285 * Stop mpa timer. If it expired, then
1286 * we ignore the MPA reply. process_timeout()
1287 * will abort the connection.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001288 */
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001289 if (stop_ep_timer(ep))
Steve Wisecc18b932014-04-24 14:31:53 -05001290 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001291
1292 /*
1293 * If we get more than the supported amount of private data
1294 * then we must fail this connection.
1295 */
1296 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1297 err = -EINVAL;
1298 goto err;
1299 }
1300
1301 /*
1302 * copy the new data into our accumulation buffer.
1303 */
1304 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1305 skb->len);
1306 ep->mpa_pkt_len += skb->len;
1307
1308 /*
1309 * if we don't even have the mpa message, then bail.
1310 */
1311 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001312 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001313 mpa = (struct mpa_message *) ep->mpa_pkt;
1314
1315 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301316 if (mpa->revision > mpa_rev) {
1317 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1318 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001319 err = -EPROTO;
1320 goto err;
1321 }
1322 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1323 err = -EPROTO;
1324 goto err;
1325 }
1326
1327 plen = ntohs(mpa->private_data_size);
1328
1329 /*
1330 * Fail if there's too much private data.
1331 */
1332 if (plen > MPA_MAX_PRIVATE_DATA) {
1333 err = -EPROTO;
1334 goto err;
1335 }
1336
1337 /*
1338 * If plen does not account for pkt size
1339 */
1340 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1341 err = -EPROTO;
1342 goto err;
1343 }
1344
1345 ep->plen = (u8) plen;
1346
1347 /*
1348 * If we don't have all the pdata yet, then bail.
1349 * We'll continue process when more data arrives.
1350 */
1351 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001352 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001353
1354 if (mpa->flags & MPA_REJECT) {
1355 err = -ECONNREFUSED;
1356 goto err;
1357 }
1358
1359 /*
1360 * If we get here we have accumulated the entire mpa
1361 * start reply message including private data. And
1362 * the MPA header is valid.
1363 */
Steve Wisec529fb52014-03-21 20:40:37 +05301364 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001365 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1366 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1367 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301368 ep->mpa_attr.version = mpa->revision;
1369 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1370
1371 if (mpa->revision == 2) {
1372 ep->mpa_attr.enhanced_rdma_conn =
1373 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1374 if (ep->mpa_attr.enhanced_rdma_conn) {
1375 mpa_v2_params = (struct mpa_v2_conn_params *)
1376 (ep->mpa_pkt + sizeof(*mpa));
1377 resp_ird = ntohs(mpa_v2_params->ird) &
1378 MPA_V2_IRD_ORD_MASK;
1379 resp_ord = ntohs(mpa_v2_params->ord) &
1380 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301381 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1382 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301383
1384 /*
1385 * This is a double-check. Ideally, below checks are
1386 * not required since ird/ord stuff has been taken
1387 * care of in c4iw_accept_cr
1388 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301389 if (ep->ird < resp_ord) {
1390 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1391 ep->com.dev->rdev.lldi.max_ordird_qp)
1392 ep->ird = resp_ord;
1393 else
1394 insuff_ird = 1;
1395 } else if (ep->ird > resp_ord) {
1396 ep->ird = resp_ord;
1397 }
1398 if (ep->ord > resp_ird) {
1399 if (RELAXED_IRD_NEGOTIATION)
1400 ep->ord = resp_ird;
1401 else
1402 insuff_ird = 1;
1403 }
1404 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301405 err = -ENOMEM;
1406 ep->ird = resp_ord;
1407 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301408 }
1409
1410 if (ntohs(mpa_v2_params->ird) &
1411 MPA_V2_PEER2PEER_MODEL) {
1412 if (ntohs(mpa_v2_params->ord) &
1413 MPA_V2_RDMA_WRITE_RTR)
1414 ep->mpa_attr.p2p_type =
1415 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1416 else if (ntohs(mpa_v2_params->ord) &
1417 MPA_V2_RDMA_READ_RTR)
1418 ep->mpa_attr.p2p_type =
1419 FW_RI_INIT_P2PTYPE_READ_REQ;
1420 }
1421 }
1422 } else if (mpa->revision == 1)
1423 if (peer2peer)
1424 ep->mpa_attr.p2p_type = p2p_type;
1425
Steve Wisecfdda9d2010-04-21 15:30:06 -07001426 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301427 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1428 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1429 ep->mpa_attr.recv_marker_enabled,
1430 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1431 ep->mpa_attr.p2p_type, p2p_type);
1432
1433 /*
1434 * If responder's RTR does not match with that of initiator, assign
1435 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1436 * generated when moving QP to RTS state.
1437 * A TERM message will be sent after QP has moved to RTS state
1438 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001439 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301440 (ep->mpa_attr.p2p_type != p2p_type)) {
1441 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1442 rtr_mismatch = 1;
1443 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001444
1445 attrs.mpa_attr = ep->mpa_attr;
1446 attrs.max_ird = ep->ird;
1447 attrs.max_ord = ep->ord;
1448 attrs.llp_stream_handle = ep;
1449 attrs.next_state = C4IW_QP_STATE_RTS;
1450
1451 mask = C4IW_QP_ATTR_NEXT_STATE |
1452 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1453 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1454
1455 /* bind QP and TID with INIT_WR */
1456 err = c4iw_modify_qp(ep->com.qp->rhp,
1457 ep->com.qp, mask, &attrs, 1);
1458 if (err)
1459 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301460
1461 /*
1462 * If responder's RTR requirement did not match with what initiator
1463 * supports, generate TERM message
1464 */
1465 if (rtr_mismatch) {
1466 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1467 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1468 attrs.ecode = MPA_NOMATCH_RTR;
1469 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001470 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301471 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001472 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301473 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001474 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301475 goto out;
1476 }
1477
1478 /*
1479 * Generate TERM if initiator IRD is not sufficient for responder
1480 * provided ORD. Currently, we do the same behaviour even when
1481 * responder provided IRD is also not sufficient as regards to
1482 * initiator ORD.
1483 */
1484 if (insuff_ird) {
1485 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1486 __func__);
1487 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1488 attrs.ecode = MPA_INSUFF_IRD;
1489 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001490 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301491 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001492 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301493 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001494 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301495 goto out;
1496 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001497 goto out;
1498err:
Steve Wisec529fb52014-03-21 20:40:37 +05301499 __state_set(&ep->com, ABORTING);
Steve Wiseb21ef162010-06-10 19:02:55 +00001500 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001501out:
1502 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001503 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001504}
1505
1506static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1507{
1508 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301509 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001510 u16 plen;
1511
1512 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1513
Steve Wisecfdda9d2010-04-21 15:30:06 -07001514 /*
1515 * If we get more than the supported amount of private data
1516 * then we must fail this connection.
1517 */
1518 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001519 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001520 abort_connection(ep, skb, GFP_KERNEL);
1521 return;
1522 }
1523
1524 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1525
1526 /*
1527 * Copy the new data into our accumulation buffer.
1528 */
1529 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1530 skb->len);
1531 ep->mpa_pkt_len += skb->len;
1532
1533 /*
1534 * If we don't even have the mpa message, then bail.
1535 * We'll continue process when more data arrives.
1536 */
1537 if (ep->mpa_pkt_len < sizeof(*mpa))
1538 return;
1539
1540 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001541 mpa = (struct mpa_message *) ep->mpa_pkt;
1542
1543 /*
1544 * Validate MPA Header.
1545 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301546 if (mpa->revision > mpa_rev) {
1547 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1548 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001549 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001550 abort_connection(ep, skb, GFP_KERNEL);
1551 return;
1552 }
1553
1554 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001555 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001556 abort_connection(ep, skb, GFP_KERNEL);
1557 return;
1558 }
1559
1560 plen = ntohs(mpa->private_data_size);
1561
1562 /*
1563 * Fail if there's too much private data.
1564 */
1565 if (plen > MPA_MAX_PRIVATE_DATA) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001566 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001567 abort_connection(ep, skb, GFP_KERNEL);
1568 return;
1569 }
1570
1571 /*
1572 * If plen does not account for pkt size
1573 */
1574 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001575 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001576 abort_connection(ep, skb, GFP_KERNEL);
1577 return;
1578 }
1579 ep->plen = (u8) plen;
1580
1581 /*
1582 * If we don't have all the pdata yet, then bail.
1583 */
1584 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1585 return;
1586
1587 /*
1588 * If we get here we have accumulated the entire mpa
1589 * start reply message including private data.
1590 */
1591 ep->mpa_attr.initiator = 0;
1592 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1593 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1594 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301595 ep->mpa_attr.version = mpa->revision;
1596 if (mpa->revision == 1)
1597 ep->tried_with_mpa_v1 = 1;
1598 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1599
1600 if (mpa->revision == 2) {
1601 ep->mpa_attr.enhanced_rdma_conn =
1602 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1603 if (ep->mpa_attr.enhanced_rdma_conn) {
1604 mpa_v2_params = (struct mpa_v2_conn_params *)
1605 (ep->mpa_pkt + sizeof(*mpa));
1606 ep->ird = ntohs(mpa_v2_params->ird) &
1607 MPA_V2_IRD_ORD_MASK;
1608 ep->ord = ntohs(mpa_v2_params->ord) &
1609 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301610 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1611 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301612 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1613 if (peer2peer) {
1614 if (ntohs(mpa_v2_params->ord) &
1615 MPA_V2_RDMA_WRITE_RTR)
1616 ep->mpa_attr.p2p_type =
1617 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1618 else if (ntohs(mpa_v2_params->ord) &
1619 MPA_V2_RDMA_READ_RTR)
1620 ep->mpa_attr.p2p_type =
1621 FW_RI_INIT_P2PTYPE_READ_REQ;
1622 }
1623 }
1624 } else if (mpa->revision == 1)
1625 if (peer2peer)
1626 ep->mpa_attr.p2p_type = p2p_type;
1627
Steve Wisecfdda9d2010-04-21 15:30:06 -07001628 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1629 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1630 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1631 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1632 ep->mpa_attr.p2p_type);
1633
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001634 /*
1635 * If the endpoint timer already expired, then we ignore
1636 * the start request. process_timeout() will abort
1637 * the connection.
1638 */
1639 if (!stop_ep_timer(ep)) {
1640 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001641
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001642 /* drive upcall */
Hariprasad Shenai10be6b42014-11-21 09:36:35 -06001643 mutex_lock_nested(&ep->parent_ep->com.mutex,
1644 SINGLE_DEPTH_NESTING);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001645 if (ep->parent_ep->com.state != DEAD) {
1646 if (connect_request_upcall(ep))
1647 abort_connection(ep, skb, GFP_KERNEL);
1648 } else {
Steve Wisebe13b2d2014-03-21 20:40:33 +05301649 abort_connection(ep, skb, GFP_KERNEL);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001650 }
1651 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301652 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001653 return;
1654}
1655
1656static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1657{
1658 struct c4iw_ep *ep;
1659 struct cpl_rx_data *hdr = cplhdr(skb);
1660 unsigned int dlen = ntohs(hdr->len);
1661 unsigned int tid = GET_TID(hdr);
1662 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001663 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001664 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001665
1666 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301667 if (!ep)
1668 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001669 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1670 skb_pull(skb, sizeof(*hdr));
1671 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301672 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001673
Steve Wisecfdda9d2010-04-21 15:30:06 -07001674 /* update RX credits */
1675 update_rx_credits(ep, dlen);
1676
Steve Wisec529fb52014-03-21 20:40:37 +05301677 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001678 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001679 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001680 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001681 break;
1682 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001683 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001684 process_mpa_request(ep, skb);
1685 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001686 case FPDU_MODE: {
1687 struct c4iw_qp_attributes attrs;
1688 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001689 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001690 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001691 " qpid %u ep %p state %d tid %u status %d\n",
1692 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301693 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301694 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001695 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001696 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1697 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001698 break;
1699 }
Vipul Pandya15579672013-01-07 13:11:52 +00001700 default:
1701 break;
1702 }
Steve Wisec529fb52014-03-21 20:40:37 +05301703 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001704 if (disconnect)
1705 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001706 return 0;
1707}
1708
1709static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1710{
1711 struct c4iw_ep *ep;
1712 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001713 int release = 0;
1714 unsigned int tid = GET_TID(rpl);
1715 struct tid_info *t = dev->rdev.lldi.tids;
1716
1717 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301718 if (!ep) {
1719 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1720 return 0;
1721 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001722 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001723 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001724 switch (ep->com.state) {
1725 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001726 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001727 __state_set(&ep->com, DEAD);
1728 release = 1;
1729 break;
1730 default:
1731 printk(KERN_ERR "%s ep %p state %d\n",
1732 __func__, ep, ep->com.state);
1733 break;
1734 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001735 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001736
1737 if (release)
1738 release_ep_resources(ep);
1739 return 0;
1740}
1741
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001742static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1743{
1744 struct sk_buff *skb;
1745 struct fw_ofld_connection_wr *req;
1746 unsigned int mtu_idx;
1747 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301748 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301749 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001750
1751 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1752 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1753 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001754 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301755 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301756 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1757 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001758 ep->l2t));
Steve Wise9eccfe12014-03-26 17:08:09 -05001759 sin = (struct sockaddr_in *)&ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301760 req->le.lport = sin->sin_port;
1761 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05001762 sin = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301763 req->le.pport = sin->sin_port;
1764 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001765 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301766 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1767 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001768 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301769 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001770 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001771 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301772 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301773 enable_tcp_timestamps,
1774 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001775 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301776
1777 /*
1778 * Specify the largest window that will fit in opt0. The
1779 * remainder will be specified in the rx_data_ack.
1780 */
1781 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001782 if (win > RCV_BUFSIZ_M)
1783 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301784
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001785 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1786 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001787 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001788 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001789 WND_SCALE_V(wscale) |
1790 MSS_IDX_V(mtu_idx) |
1791 L2T_IDX_V(ep->l2t->idx) |
1792 TX_CHAN_V(ep->tx_chan) |
1793 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001794 DSCP_V(ep->tos) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001795 ULP_MODE_V(ULP_MODE_TCPDDP) |
1796 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001797 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1798 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001799 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001800 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001801 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001802 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001803 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001804 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001805 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001806 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001807 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1808 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1809 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001810 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1811 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001812 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1813}
1814
Steve Wisecfdda9d2010-04-21 15:30:06 -07001815/*
1816 * Return whether a failed active open has allocated a TID
1817 */
1818static inline int act_open_has_tid(int status)
1819{
1820 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1821 status != CPL_ERR_ARP_MISS;
1822}
1823
Steve Wise7a2cea22014-03-14 21:52:07 +05301824/* Returns whether a CPL status conveys negative advice.
1825 */
1826static int is_neg_adv(unsigned int status)
1827{
1828 return status == CPL_ERR_RTX_NEG_ADVICE ||
1829 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1830 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1831}
1832
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301833static char *neg_adv_str(unsigned int status)
1834{
1835 switch (status) {
1836 case CPL_ERR_RTX_NEG_ADVICE:
1837 return "Retransmit timeout";
1838 case CPL_ERR_PERSIST_NEG_ADVICE:
1839 return "Persist timeout";
1840 case CPL_ERR_KEEPALV_NEG_ADVICE:
1841 return "Keepalive timeout";
1842 default:
1843 return "Unknown";
1844 }
1845}
1846
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301847static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1848{
1849 ep->snd_win = snd_win;
1850 ep->rcv_win = rcv_win;
1851 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1852}
1853
Vipul Pandya793dad92012-12-10 09:30:56 +00001854#define ACT_OPEN_RETRY_COUNT 2
1855
Vipul Pandya830662f2013-07-04 16:10:47 +05301856static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1857 struct dst_entry *dst, struct c4iw_dev *cdev,
1858 bool clear_mpa_v1)
1859{
1860 struct neighbour *n;
1861 int err, step;
1862 struct net_device *pdev;
1863
1864 n = dst_neigh_lookup(dst, peer_ip);
1865 if (!n)
1866 return -ENODEV;
1867
1868 rcu_read_lock();
1869 err = -ENOMEM;
1870 if (n->dev->flags & IFF_LOOPBACK) {
1871 if (iptype == 4)
1872 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1873 else if (IS_ENABLED(CONFIG_IPV6))
1874 for_each_netdev(&init_net, pdev) {
1875 if (ipv6_chk_addr(&init_net,
1876 (struct in6_addr *)peer_ip,
1877 pdev, 1))
1878 break;
1879 }
1880 else
1881 pdev = NULL;
1882
1883 if (!pdev) {
1884 err = -ENODEV;
1885 goto out;
1886 }
1887 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1888 n, pdev, 0);
1889 if (!ep->l2t)
1890 goto out;
1891 ep->mtu = pdev->mtu;
1892 ep->tx_chan = cxgb4_port_chan(pdev);
1893 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1894 step = cdev->rdev.lldi.ntxq /
1895 cdev->rdev.lldi.nchan;
1896 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1897 step = cdev->rdev.lldi.nrxq /
1898 cdev->rdev.lldi.nchan;
1899 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1900 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1901 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301902 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301903 dev_put(pdev);
1904 } else {
1905 pdev = get_real_dev(n->dev);
1906 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1907 n, pdev, 0);
1908 if (!ep->l2t)
1909 goto out;
1910 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05001911 ep->tx_chan = cxgb4_port_chan(pdev);
1912 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
Vipul Pandya830662f2013-07-04 16:10:47 +05301913 step = cdev->rdev.lldi.ntxq /
1914 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05001915 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1916 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05301917 step = cdev->rdev.lldi.nrxq /
1918 cdev->rdev.lldi.nchan;
1919 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05001920 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301921 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301922
1923 if (clear_mpa_v1) {
1924 ep->retry_with_mpa_v1 = 0;
1925 ep->tried_with_mpa_v1 = 0;
1926 }
1927 }
1928 err = 0;
1929out:
1930 rcu_read_unlock();
1931
1932 neigh_release(n);
1933
1934 return err;
1935}
1936
Vipul Pandya793dad92012-12-10 09:30:56 +00001937static int c4iw_reconnect(struct c4iw_ep *ep)
1938{
1939 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05301940 struct sockaddr_in *laddr = (struct sockaddr_in *)
1941 &ep->com.cm_id->local_addr;
1942 struct sockaddr_in *raddr = (struct sockaddr_in *)
1943 &ep->com.cm_id->remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301944 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
1945 &ep->com.cm_id->local_addr;
1946 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
1947 &ep->com.cm_id->remote_addr;
1948 int iptype;
1949 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00001950
1951 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1952 init_timer(&ep->timer);
1953
1954 /*
1955 * Allocate an active TID to initiate a TCP connection.
1956 */
1957 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1958 if (ep->atid == -1) {
1959 pr_err("%s - cannot alloc atid.\n", __func__);
1960 err = -ENOMEM;
1961 goto fail2;
1962 }
1963 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1964
1965 /* find a route */
Vipul Pandya830662f2013-07-04 16:10:47 +05301966 if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
1967 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
1968 raddr->sin_addr.s_addr, laddr->sin_port,
1969 raddr->sin_port, 0);
1970 iptype = 4;
1971 ra = (__u8 *)&raddr->sin_addr;
1972 } else {
1973 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
1974 raddr6->sin6_addr.s6_addr,
1975 laddr6->sin6_port, raddr6->sin6_port, 0,
1976 raddr6->sin6_scope_id);
1977 iptype = 6;
1978 ra = (__u8 *)&raddr6->sin6_addr;
1979 }
1980 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001981 pr_err("%s - cannot find route.\n", __func__);
1982 err = -EHOSTUNREACH;
1983 goto fail3;
1984 }
Vipul Pandya830662f2013-07-04 16:10:47 +05301985 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false);
1986 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001987 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00001988 goto fail4;
1989 }
1990
1991 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1992 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1993 ep->l2t->idx);
1994
1995 state_set(&ep->com, CONNECTING);
1996 ep->tos = 0;
1997
1998 /* send connect request to rnic */
1999 err = send_connect(ep);
2000 if (!err)
2001 goto out;
2002
2003 cxgb4_l2t_release(ep->l2t);
2004fail4:
2005 dst_release(ep->dst);
2006fail3:
2007 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2008 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2009fail2:
2010 /*
2011 * remember to send notification to upper layer.
2012 * We are in here so the upper layer is not aware that this is
2013 * re-connect attempt and so, upper layer is still waiting for
2014 * response of 1st connect request.
2015 */
2016 connect_reply_upcall(ep, -ECONNRESET);
2017 c4iw_put_ep(&ep->com);
2018out:
2019 return err;
2020}
2021
Steve Wisecfdda9d2010-04-21 15:30:06 -07002022static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2023{
2024 struct c4iw_ep *ep;
2025 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002026 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2027 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002028 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002029 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302030 struct sockaddr_in *la;
2031 struct sockaddr_in *ra;
2032 struct sockaddr_in6 *la6;
2033 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002034
2035 ep = lookup_atid(t, atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05002036 la = (struct sockaddr_in *)&ep->com.mapped_local_addr;
2037 ra = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
2038 la6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
2039 ra6 = (struct sockaddr_in6 *)&ep->com.mapped_remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002040
2041 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2042 status, status2errno(status));
2043
Steve Wise7a2cea22014-03-14 21:52:07 +05302044 if (is_neg_adv(status)) {
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05302045 dev_warn(&dev->rdev.lldi.pdev->dev,
2046 "Connection problems for atid %u status %u (%s)\n",
2047 atid, status, neg_adv_str(status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002048 return 0;
2049 }
2050
Vipul Pandya793dad92012-12-10 09:30:56 +00002051 set_bit(ACT_OPEN_RPL, &ep->com.history);
2052
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302053 /*
2054 * Log interesting failures.
2055 */
2056 switch (status) {
2057 case CPL_ERR_CONN_RESET:
2058 case CPL_ERR_CONN_TIMEDOUT:
2059 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002060 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302061 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002062 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302063 mutex_unlock(&dev->rdev.stats.lock);
2064 if (ep->com.local_addr.ss_family == AF_INET &&
2065 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002066 send_fw_act_open_req(ep,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002067 TID_TID_G(AOPEN_ATID_G(
Vipul Pandya793dad92012-12-10 09:30:56 +00002068 ntohl(rpl->atid_status))));
2069 return 0;
2070 }
2071 break;
2072 case CPL_ERR_CONN_EXIST:
2073 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2074 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2075 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2076 atid);
2077 cxgb4_free_atid(t, atid);
2078 dst_release(ep->dst);
2079 cxgb4_l2t_release(ep->l2t);
2080 c4iw_reconnect(ep);
2081 return 0;
2082 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002083 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302084 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302085 if (ep->com.local_addr.ss_family == AF_INET) {
2086 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2087 atid, status, status2errno(status),
2088 &la->sin_addr.s_addr, ntohs(la->sin_port),
2089 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2090 } else {
2091 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2092 atid, status, status2errno(status),
2093 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2094 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2095 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302096 break;
2097 }
2098
Steve Wisecfdda9d2010-04-21 15:30:06 -07002099 connect_reply_upcall(ep, status2errno(status));
2100 state_set(&ep->com, DEAD);
2101
2102 if (status && act_open_has_tid(status))
2103 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2104
Vipul Pandya793dad92012-12-10 09:30:56 +00002105 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002106 cxgb4_free_atid(t, atid);
2107 dst_release(ep->dst);
2108 cxgb4_l2t_release(ep->l2t);
2109 c4iw_put_ep(&ep->com);
2110
2111 return 0;
2112}
2113
2114static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2115{
2116 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2117 struct tid_info *t = dev->rdev.lldi.tids;
2118 unsigned int stid = GET_TID(rpl);
2119 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2120
2121 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002122 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2123 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002124 }
2125 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2126 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002127 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002128
Vipul Pandya1cab7752012-12-10 09:30:55 +00002129out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002130 return 0;
2131}
2132
Steve Wisecfdda9d2010-04-21 15:30:06 -07002133static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2134{
2135 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2136 struct tid_info *t = dev->rdev.lldi.tids;
2137 unsigned int stid = GET_TID(rpl);
2138 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2139
2140 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002141 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002142 return 0;
2143}
2144
Vipul Pandya830662f2013-07-04 16:10:47 +05302145static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002146 struct cpl_pass_accept_req *req)
2147{
2148 struct cpl_pass_accept_rpl *rpl;
2149 unsigned int mtu_idx;
2150 u64 opt0;
2151 u32 opt2;
2152 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302153 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302154 int win;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002155
2156 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2157 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302158
Steve Wisecfdda9d2010-04-21 15:30:06 -07002159 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302160 rpl = cplhdr(skb);
2161 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
2162 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2163 rpl5 = (void *)rpl;
2164 INIT_TP_WR(rpl5, ep->hwtid);
2165 } else {
2166 skb_trim(skb, sizeof(*rpl));
2167 INIT_TP_WR(rpl, ep->hwtid);
2168 }
2169 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2170 ep->hwtid));
2171
2172 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302173 enable_tcp_timestamps && req->tcpopt.tstamp,
2174 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002175 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302176
2177 /*
2178 * Specify the largest window that will fit in opt0. The
2179 * remainder will be specified in the rx_data_ack.
2180 */
2181 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002182 if (win > RCV_BUFSIZ_M)
2183 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002184 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002185 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002186 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002187 WND_SCALE_V(wscale) |
2188 MSS_IDX_V(mtu_idx) |
2189 L2T_IDX_V(ep->l2t->idx) |
2190 TX_CHAN_V(ep->tx_chan) |
2191 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002192 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002193 ULP_MODE_V(ULP_MODE_TCPDDP) |
2194 RCV_BUFSIZ_V(win);
2195 opt2 = RX_CHANNEL_V(0) |
2196 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002197
2198 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002199 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002200 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002201 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002202 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002203 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002204 if (enable_ecn) {
2205 const struct tcphdr *tcph;
2206 u32 hlen = ntohl(req->hdr_len);
2207
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302208 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2209 IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002210 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002211 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002212 }
Steve Wise92e50112014-04-24 14:31:59 -05002213 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302214 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002215 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302216 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302217 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302218 rpl5 = (void *)rpl;
2219 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2220 if (peer2peer)
2221 isn += 4;
2222 rpl5->iss = cpu_to_be32(isn);
2223 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002224 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002225
Steve Wisecfdda9d2010-04-21 15:30:06 -07002226 rpl->opt0 = cpu_to_be64(opt0);
2227 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002228 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wiseb38a0ad2013-08-06 21:04:37 +05302229 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002230 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2231
2232 return;
2233}
2234
Vipul Pandya830662f2013-07-04 16:10:47 +05302235static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002236{
Vipul Pandya830662f2013-07-04 16:10:47 +05302237 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002238 BUG_ON(skb_cloned(skb));
2239 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002240 release_tid(&dev->rdev, hwtid, skb);
2241 return;
2242}
2243
Vipul Pandya830662f2013-07-04 16:10:47 +05302244static void get_4tuple(struct cpl_pass_accept_req *req, int *iptype,
2245 __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002246 __be16 *local_port, __be16 *peer_port)
2247{
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302248 int eth_len = ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2249 int ip_len = IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002250 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302251 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002252 struct tcphdr *tcp = (struct tcphdr *)
2253 ((u8 *)(req + 1) + eth_len + ip_len);
2254
Vipul Pandya830662f2013-07-04 16:10:47 +05302255 if (ip->version == 4) {
2256 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2257 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2258 ntohs(tcp->dest));
2259 *iptype = 4;
2260 memcpy(peer_ip, &ip->saddr, 4);
2261 memcpy(local_ip, &ip->daddr, 4);
2262 } else {
2263 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2264 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2265 ntohs(tcp->dest));
2266 *iptype = 6;
2267 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2268 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2269 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002270 *peer_port = tcp->source;
2271 *local_port = tcp->dest;
2272
2273 return;
2274}
2275
2276static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2277{
Vipul Pandya793dad92012-12-10 09:30:56 +00002278 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002279 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002280 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002281 struct tid_info *t = dev->rdev.lldi.tids;
2282 unsigned int hwtid = GET_TID(req);
2283 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302284 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002285 __be16 local_port, peer_port;
David Miller3786cf12011-12-02 16:52:31 +00002286 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002287 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302288 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302289 unsigned short hdrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002290
2291 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002292 if (!parent_ep) {
2293 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2294 goto reject;
2295 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002296
Steve Wisecfdda9d2010-04-21 15:30:06 -07002297 if (state_read(&parent_ep->com) != LISTEN) {
2298 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
2299 __func__);
2300 goto reject;
2301 }
2302
Vipul Pandya830662f2013-07-04 16:10:47 +05302303 get_4tuple(req, &iptype, local_ip, peer_ip, &local_port, &peer_port);
2304
Steve Wisecfdda9d2010-04-21 15:30:06 -07002305 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302306 if (iptype == 4) {
2307 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2308 , __func__, parent_ep, hwtid,
2309 local_ip, peer_ip, ntohs(local_port),
2310 ntohs(peer_port), peer_mss);
2311 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2312 local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002313 PASS_OPEN_TOS_G(ntohl(req->tos_stid)));
Vipul Pandya830662f2013-07-04 16:10:47 +05302314 } else {
2315 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2316 , __func__, parent_ep, hwtid,
2317 local_ip, peer_ip, ntohs(local_port),
2318 ntohs(peer_port), peer_mss);
2319 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002320 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302321 ((struct sockaddr_in6 *)
2322 &parent_ep->com.local_addr)->sin6_scope_id);
2323 }
2324 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002325 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2326 __func__);
2327 goto reject;
2328 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002329
2330 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2331 if (!child_ep) {
2332 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2333 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002334 dst_release(dst);
2335 goto reject;
2336 }
David Miller3786cf12011-12-02 16:52:31 +00002337
Vipul Pandya830662f2013-07-04 16:10:47 +05302338 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false);
David Miller3786cf12011-12-02 16:52:31 +00002339 if (err) {
2340 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2341 __func__);
2342 dst_release(dst);
2343 kfree(child_ep);
2344 goto reject;
2345 }
2346
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302347 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2348 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2349 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2350 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002351
Steve Wisecfdda9d2010-04-21 15:30:06 -07002352 state_set(&child_ep->com, CONNECTING);
2353 child_ep->com.dev = dev;
2354 child_ep->com.cm_id = NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +05302355 if (iptype == 4) {
2356 struct sockaddr_in *sin = (struct sockaddr_in *)
2357 &child_ep->com.local_addr;
2358 sin->sin_family = PF_INET;
2359 sin->sin_port = local_port;
2360 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2361 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
2362 sin->sin_family = PF_INET;
2363 sin->sin_port = peer_port;
2364 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2365 } else {
2366 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
2367 &child_ep->com.local_addr;
2368 sin6->sin6_family = PF_INET6;
2369 sin6->sin6_port = local_port;
2370 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2371 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
2372 sin6->sin6_family = PF_INET6;
2373 sin6->sin6_port = peer_port;
2374 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2375 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002376 c4iw_get_ep(&parent_ep->com);
2377 child_ep->parent_ep = parent_ep;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002378 child_ep->tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002379 child_ep->dst = dst;
2380 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002381
2382 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002383 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002384
2385 init_timer(&child_ep->timer);
2386 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002387 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Vipul Pandya830662f2013-07-04 16:10:47 +05302388 accept_cr(child_ep, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00002389 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002390 goto out;
2391reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302392 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002393out:
2394 return 0;
2395}
2396
2397static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2398{
2399 struct c4iw_ep *ep;
2400 struct cpl_pass_establish *req = cplhdr(skb);
2401 struct tid_info *t = dev->rdev.lldi.tids;
2402 unsigned int tid = GET_TID(req);
2403
2404 ep = lookup_tid(t, tid);
2405 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2406 ep->snd_seq = be32_to_cpu(req->snd_isn);
2407 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2408
Vipul Pandya1cab7752012-12-10 09:30:55 +00002409 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2410 ntohs(req->tcp_opt));
2411
Steve Wisecfdda9d2010-04-21 15:30:06 -07002412 set_emss(ep, ntohs(req->tcp_opt));
2413
2414 dst_confirm(ep->dst);
2415 state_set(&ep->com, MPA_REQ_WAIT);
2416 start_ep_timer(ep);
2417 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002418 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002419
2420 return 0;
2421}
2422
2423static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2424{
2425 struct cpl_peer_close *hdr = cplhdr(skb);
2426 struct c4iw_ep *ep;
2427 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002428 int disconnect = 1;
2429 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002430 struct tid_info *t = dev->rdev.lldi.tids;
2431 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002432 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002433
2434 ep = lookup_tid(t, tid);
2435 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2436 dst_confirm(ep->dst);
2437
Vipul Pandya793dad92012-12-10 09:30:56 +00002438 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002439 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002440 switch (ep->com.state) {
2441 case MPA_REQ_WAIT:
2442 __state_set(&ep->com, CLOSING);
2443 break;
2444 case MPA_REQ_SENT:
2445 __state_set(&ep->com, CLOSING);
2446 connect_reply_upcall(ep, -ECONNRESET);
2447 break;
2448 case MPA_REQ_RCVD:
2449
2450 /*
2451 * We're gonna mark this puppy DEAD, but keep
2452 * the reference on it until the ULP accepts or
2453 * rejects the CR. Also wake up anyone waiting
2454 * in rdma connection migration (see c4iw_accept_cr()).
2455 */
2456 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002457 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002458 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002459 break;
2460 case MPA_REP_SENT:
2461 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002462 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002463 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002464 break;
2465 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002466 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002467 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002468 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002469 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002470 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002471 if (ret != -ECONNRESET) {
2472 peer_close_upcall(ep);
2473 disconnect = 1;
2474 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002475 break;
2476 case ABORTING:
2477 disconnect = 0;
2478 break;
2479 case CLOSING:
2480 __state_set(&ep->com, MORIBUND);
2481 disconnect = 0;
2482 break;
2483 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002484 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002485 if (ep->com.cm_id && ep->com.qp) {
2486 attrs.next_state = C4IW_QP_STATE_IDLE;
2487 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2488 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2489 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302490 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002491 __state_set(&ep->com, DEAD);
2492 release = 1;
2493 disconnect = 0;
2494 break;
2495 case DEAD:
2496 disconnect = 0;
2497 break;
2498 default:
2499 BUG_ON(1);
2500 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002501 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002502 if (disconnect)
2503 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2504 if (release)
2505 release_ep_resources(ep);
2506 return 0;
2507}
2508
Steve Wisecfdda9d2010-04-21 15:30:06 -07002509static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2510{
2511 struct cpl_abort_req_rss *req = cplhdr(skb);
2512 struct c4iw_ep *ep;
2513 struct cpl_abort_rpl *rpl;
2514 struct sk_buff *rpl_skb;
2515 struct c4iw_qp_attributes attrs;
2516 int ret;
2517 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002518 struct tid_info *t = dev->rdev.lldi.tids;
2519 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002520
2521 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302522 if (is_neg_adv(req->status)) {
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05302523 dev_warn(&dev->rdev.lldi.pdev->dev,
2524 "Negative advice on abort - tid %u status %d (%s)\n",
2525 ep->hwtid, req->status, neg_adv_str(req->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002526 return 0;
2527 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002528 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2529 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002530 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002531
2532 /*
2533 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302534 * However, this is not needed if com state is just
2535 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002536 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302537 if (ep->com.state != MPA_REQ_SENT)
2538 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002539
2540 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002541 switch (ep->com.state) {
2542 case CONNECTING:
2543 break;
2544 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002545 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002546 break;
2547 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002548 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002549 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302550 connect_reply_upcall(ep, -ECONNRESET);
2551 else {
2552 /*
2553 * we just don't send notification upwards because we
2554 * want to retry with mpa_v1 without upper layers even
2555 * knowing it.
2556 *
2557 * do some housekeeping so as to re-initiate the
2558 * connection
2559 */
2560 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2561 mpa_rev);
2562 ep->retry_with_mpa_v1 = 1;
2563 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002564 break;
2565 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002566 break;
2567 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002568 break;
2569 case MORIBUND:
2570 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002571 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002572 /*FALLTHROUGH*/
2573 case FPDU_MODE:
2574 if (ep->com.cm_id && ep->com.qp) {
2575 attrs.next_state = C4IW_QP_STATE_ERROR;
2576 ret = c4iw_modify_qp(ep->com.qp->rhp,
2577 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2578 &attrs, 1);
2579 if (ret)
2580 printk(KERN_ERR MOD
2581 "%s - qp <- error failed!\n",
2582 __func__);
2583 }
2584 peer_abort_upcall(ep);
2585 break;
2586 case ABORTING:
2587 break;
2588 case DEAD:
2589 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002590 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002591 return 0;
2592 default:
2593 BUG_ON(1);
2594 break;
2595 }
2596 dst_confirm(ep->dst);
2597 if (ep->com.state != ABORTING) {
2598 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302599 /* we don't release if we want to retry with mpa_v1 */
2600 if (!ep->retry_with_mpa_v1)
2601 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002602 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002603 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002604
2605 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2606 if (!rpl_skb) {
2607 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2608 __func__);
2609 release = 1;
2610 goto out;
2611 }
2612 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2613 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2614 INIT_TP_WR(rpl, ep->hwtid);
2615 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2616 rpl->cmd = CPL_ABORT_NO_RST;
2617 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2618out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002619 if (release)
2620 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002621 else if (ep->retry_with_mpa_v1) {
2622 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302623 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2624 dst_release(ep->dst);
2625 cxgb4_l2t_release(ep->l2t);
2626 c4iw_reconnect(ep);
2627 }
2628
Steve Wisecfdda9d2010-04-21 15:30:06 -07002629 return 0;
2630}
2631
2632static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2633{
2634 struct c4iw_ep *ep;
2635 struct c4iw_qp_attributes attrs;
2636 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002637 int release = 0;
2638 struct tid_info *t = dev->rdev.lldi.tids;
2639 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002640
2641 ep = lookup_tid(t, tid);
2642
2643 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2644 BUG_ON(!ep);
2645
2646 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002647 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002648 switch (ep->com.state) {
2649 case CLOSING:
2650 __state_set(&ep->com, MORIBUND);
2651 break;
2652 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002653 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002654 if ((ep->com.cm_id) && (ep->com.qp)) {
2655 attrs.next_state = C4IW_QP_STATE_IDLE;
2656 c4iw_modify_qp(ep->com.qp->rhp,
2657 ep->com.qp,
2658 C4IW_QP_ATTR_NEXT_STATE,
2659 &attrs, 1);
2660 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302661 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002662 __state_set(&ep->com, DEAD);
2663 release = 1;
2664 break;
2665 case ABORTING:
2666 case DEAD:
2667 break;
2668 default:
2669 BUG_ON(1);
2670 break;
2671 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002672 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002673 if (release)
2674 release_ep_resources(ep);
2675 return 0;
2676}
2677
2678static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2679{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002680 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002681 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002682 unsigned int tid = GET_TID(rpl);
2683 struct c4iw_ep *ep;
2684 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002685
2686 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002687 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002688
Steve Wise30c95c22011-05-09 22:06:22 -07002689 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002690 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2691 ep->com.qp->wq.sq.qid);
2692 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2693 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2694 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2695 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002696 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002697
Steve Wisecfdda9d2010-04-21 15:30:06 -07002698 return 0;
2699}
2700
2701/*
2702 * Upcall from the adapter indicating data has been transmitted.
2703 * For us its just the single MPA request or reply. We can now free
2704 * the skb holding the mpa message.
2705 */
2706static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2707{
2708 struct c4iw_ep *ep;
2709 struct cpl_fw4_ack *hdr = cplhdr(skb);
2710 u8 credits = hdr->credits;
2711 unsigned int tid = GET_TID(hdr);
2712 struct tid_info *t = dev->rdev.lldi.tids;
2713
2714
2715 ep = lookup_tid(t, tid);
2716 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2717 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002718 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2719 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002720 return 0;
2721 }
2722
2723 dst_confirm(ep->dst);
2724 if (ep->mpa_skb) {
2725 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2726 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2727 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2728 kfree_skb(ep->mpa_skb);
2729 ep->mpa_skb = NULL;
2730 }
2731 return 0;
2732}
2733
Steve Wisecfdda9d2010-04-21 15:30:06 -07002734int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2735{
Steve Wisea7db89e2014-03-21 20:40:35 +05302736 int err = 0;
2737 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002738 struct c4iw_ep *ep = to_ep(cm_id);
2739 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2740
Steve Wisea7db89e2014-03-21 20:40:35 +05302741 mutex_lock(&ep->com.mutex);
2742 if (ep->com.state == DEAD) {
2743 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002744 c4iw_put_ep(&ep->com);
2745 return -ECONNRESET;
2746 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002747 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302748 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002749 if (mpa_rev == 0)
2750 abort_connection(ep, NULL, GFP_KERNEL);
2751 else {
2752 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302753 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002754 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302755 mutex_unlock(&ep->com.mutex);
2756 if (disconnect)
2757 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002758 c4iw_put_ep(&ep->com);
2759 return 0;
2760}
2761
2762int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2763{
2764 int err;
2765 struct c4iw_qp_attributes attrs;
2766 enum c4iw_qp_attr_mask mask;
2767 struct c4iw_ep *ep = to_ep(cm_id);
2768 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2769 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2770
2771 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302772
2773 mutex_lock(&ep->com.mutex);
2774 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002775 err = -ECONNRESET;
2776 goto err;
2777 }
2778
Steve Wisea7db89e2014-03-21 20:40:35 +05302779 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002780 BUG_ON(!qp);
2781
Vipul Pandya793dad92012-12-10 09:30:56 +00002782 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302783 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2784 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002785 abort_connection(ep, NULL, GFP_KERNEL);
2786 err = -EINVAL;
2787 goto err;
2788 }
2789
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302790 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2791 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302792 if (RELAXED_IRD_NEGOTIATION) {
2793 ep->ord = ep->ird;
2794 } else {
2795 ep->ird = conn_param->ird;
2796 ep->ord = conn_param->ord;
2797 send_mpa_reject(ep, conn_param->private_data,
2798 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302799 abort_connection(ep, NULL, GFP_KERNEL);
2800 err = -ENOMEM;
2801 goto err;
2802 }
2803 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302804 if (conn_param->ird < ep->ord) {
2805 if (RELAXED_IRD_NEGOTIATION &&
2806 ep->ord <= h->rdev.lldi.max_ordird_qp) {
2807 conn_param->ird = ep->ord;
2808 } else {
2809 abort_connection(ep, NULL, GFP_KERNEL);
2810 err = -ENOMEM;
2811 goto err;
2812 }
2813 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302814 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002815 ep->ird = conn_param->ird;
2816 ep->ord = conn_param->ord;
2817
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302818 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302819 if (peer2peer && ep->ird == 0)
2820 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302821 } else {
2822 if (peer2peer &&
2823 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
2824 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ord == 0)
2825 ep->ird = 1;
2826 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002827
2828 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2829
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302830 cm_id->add_ref(cm_id);
2831 ep->com.cm_id = cm_id;
2832 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00002833 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302834
Steve Wisecfdda9d2010-04-21 15:30:06 -07002835 /* bind QP to EP and move to RTS */
2836 attrs.mpa_attr = ep->mpa_attr;
2837 attrs.max_ird = ep->ird;
2838 attrs.max_ord = ep->ord;
2839 attrs.llp_stream_handle = ep;
2840 attrs.next_state = C4IW_QP_STATE_RTS;
2841
2842 /* bind QP and TID with INIT_WR */
2843 mask = C4IW_QP_ATTR_NEXT_STATE |
2844 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2845 C4IW_QP_ATTR_MPA_ATTR |
2846 C4IW_QP_ATTR_MAX_IRD |
2847 C4IW_QP_ATTR_MAX_ORD;
2848
2849 err = c4iw_modify_qp(ep->com.qp->rhp,
2850 ep->com.qp, mask, &attrs, 1);
2851 if (err)
2852 goto err1;
2853 err = send_mpa_reply(ep, conn_param->private_data,
2854 conn_param->private_data_len);
2855 if (err)
2856 goto err1;
2857
Steve Wisea7db89e2014-03-21 20:40:35 +05302858 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002859 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05302860 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002861 c4iw_put_ep(&ep->com);
2862 return 0;
2863err1:
2864 ep->com.cm_id = NULL;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302865 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002866 cm_id->rem_ref(cm_id);
2867err:
Steve Wisea7db89e2014-03-21 20:40:35 +05302868 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002869 c4iw_put_ep(&ep->com);
2870 return err;
2871}
2872
Vipul Pandya830662f2013-07-04 16:10:47 +05302873static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2874{
2875 struct in_device *ind;
2876 int found = 0;
2877 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2878 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
2879
2880 ind = in_dev_get(dev->rdev.lldi.ports[0]);
2881 if (!ind)
2882 return -EADDRNOTAVAIL;
2883 for_primary_ifa(ind) {
2884 laddr->sin_addr.s_addr = ifa->ifa_address;
2885 raddr->sin_addr.s_addr = ifa->ifa_address;
2886 found = 1;
2887 break;
2888 }
2889 endfor_ifa(ind);
2890 in_dev_put(ind);
2891 return found ? 0 : -EADDRNOTAVAIL;
2892}
2893
2894static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
2895 unsigned char banned_flags)
2896{
2897 struct inet6_dev *idev;
2898 int err = -EADDRNOTAVAIL;
2899
2900 rcu_read_lock();
2901 idev = __in6_dev_get(dev);
2902 if (idev != NULL) {
2903 struct inet6_ifaddr *ifp;
2904
2905 read_lock_bh(&idev->lock);
2906 list_for_each_entry(ifp, &idev->addr_list, if_list) {
2907 if (ifp->scope == IFA_LINK &&
2908 !(ifp->flags & banned_flags)) {
2909 memcpy(addr, &ifp->addr, 16);
2910 err = 0;
2911 break;
2912 }
2913 }
2914 read_unlock_bh(&idev->lock);
2915 }
2916 rcu_read_unlock();
2917 return err;
2918}
2919
2920static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2921{
2922 struct in6_addr uninitialized_var(addr);
2923 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2924 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
2925
2926 if (get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
2927 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
2928 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
2929 return 0;
2930 }
2931 return -EADDRNOTAVAIL;
2932}
2933
Steve Wisecfdda9d2010-04-21 15:30:06 -07002934int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2935{
Steve Wisecfdda9d2010-04-21 15:30:06 -07002936 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2937 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00002938 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05002939 struct sockaddr_in *laddr;
2940 struct sockaddr_in *raddr;
2941 struct sockaddr_in6 *laddr6;
2942 struct sockaddr_in6 *raddr6;
2943 struct iwpm_dev_data pm_reg_msg;
2944 struct iwpm_sa_data pm_msg;
Vipul Pandya830662f2013-07-04 16:10:47 +05302945 __u8 *ra;
2946 int iptype;
Steve Wise9eccfe12014-03-26 17:08:09 -05002947 int iwpm_err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002948
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302949 if ((conn_param->ord > cur_max_read_depth(dev)) ||
2950 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002951 err = -EINVAL;
2952 goto out;
2953 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002954 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2955 if (!ep) {
2956 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2957 err = -ENOMEM;
2958 goto out;
2959 }
2960 init_timer(&ep->timer);
2961 ep->plen = conn_param->private_data_len;
2962 if (ep->plen)
2963 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2964 conn_param->private_data, ep->plen);
2965 ep->ird = conn_param->ird;
2966 ep->ord = conn_param->ord;
2967
2968 if (peer2peer && ep->ord == 0)
2969 ep->ord = 1;
2970
2971 cm_id->add_ref(cm_id);
2972 ep->com.dev = dev;
2973 ep->com.cm_id = cm_id;
2974 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05302975 if (!ep->com.qp) {
2976 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
2977 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05002978 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05302979 }
Vipul Pandya325abea2013-01-07 13:11:53 +00002980 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002981 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2982 ep->com.qp, cm_id);
2983
2984 /*
2985 * Allocate an active TID to initiate a TCP connection.
2986 */
2987 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2988 if (ep->atid == -1) {
2989 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2990 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05002991 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002992 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002993 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002994
Steve Wise9eccfe12014-03-26 17:08:09 -05002995 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2996 sizeof(ep->com.local_addr));
2997 memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
2998 sizeof(ep->com.remote_addr));
2999
3000 /* No port mapper available, go with the specified peer information */
3001 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3002 sizeof(ep->com.mapped_local_addr));
3003 memcpy(&ep->com.mapped_remote_addr, &cm_id->remote_addr,
3004 sizeof(ep->com.mapped_remote_addr));
3005
3006 c4iw_form_reg_msg(dev, &pm_reg_msg);
3007 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3008 if (iwpm_err) {
3009 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3010 __func__, iwpm_err);
3011 }
3012 if (iwpm_valid_pid() && !iwpm_err) {
3013 c4iw_form_pm_msg(ep, &pm_msg);
3014 iwpm_err = iwpm_add_and_query_mapping(&pm_msg, RDMA_NL_C4IW);
3015 if (iwpm_err)
3016 PDBG("%s: Port Mapper query fail (err = %d).\n",
3017 __func__, iwpm_err);
3018 else
3019 c4iw_record_pm_msg(ep, &pm_msg);
3020 }
3021 if (iwpm_create_mapinfo(&ep->com.local_addr,
3022 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3023 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
3024 err = -ENOMEM;
3025 goto fail1;
3026 }
3027 print_addr(&ep->com, __func__, "add_query/create_mapinfo");
3028 set_bit(RELEASE_MAPINFO, &ep->com.flags);
3029
3030 laddr = (struct sockaddr_in *)&ep->com.mapped_local_addr;
3031 raddr = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
3032 laddr6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
3033 raddr6 = (struct sockaddr_in6 *) &ep->com.mapped_remote_addr;
3034
Vipul Pandya830662f2013-07-04 16:10:47 +05303035 if (cm_id->remote_addr.ss_family == AF_INET) {
3036 iptype = 4;
3037 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003038
Vipul Pandya830662f2013-07-04 16:10:47 +05303039 /*
3040 * Handle loopback requests to INADDR_ANY.
3041 */
3042 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3043 err = pick_local_ipaddrs(dev, cm_id);
3044 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003045 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303046 }
3047
3048 /* find a route */
3049 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3050 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3051 ra, ntohs(raddr->sin_port));
3052 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3053 raddr->sin_addr.s_addr, laddr->sin_port,
3054 raddr->sin_port, 0);
3055 } else {
3056 iptype = 6;
3057 ra = (__u8 *)&raddr6->sin6_addr;
3058
3059 /*
3060 * Handle loopback requests to INADDR_ANY.
3061 */
3062 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3063 err = pick_local_ip6addrs(dev, cm_id);
3064 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003065 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303066 }
3067
3068 /* find a route */
3069 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3070 __func__, laddr6->sin6_addr.s6_addr,
3071 ntohs(laddr6->sin6_port),
3072 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3073 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3074 raddr6->sin6_addr.s6_addr,
3075 laddr6->sin6_port, raddr6->sin6_port, 0,
3076 raddr6->sin6_scope_id);
3077 }
3078 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003079 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3080 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003081 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003082 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003083
Vipul Pandya830662f2013-07-04 16:10:47 +05303084 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true);
David Miller3786cf12011-12-02 16:52:31 +00003085 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003086 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003087 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003088 }
3089
3090 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3091 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3092 ep->l2t->idx);
3093
3094 state_set(&ep->com, CONNECTING);
3095 ep->tos = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003096
3097 /* send connect request to rnic */
3098 err = send_connect(ep);
3099 if (!err)
3100 goto out;
3101
3102 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003103fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003104 dst_release(ep->dst);
3105fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003106 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003107 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003108fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003109 cm_id->rem_ref(cm_id);
3110 c4iw_put_ep(&ep->com);
3111out:
3112 return err;
3113}
3114
Vipul Pandya830662f2013-07-04 16:10:47 +05303115static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3116{
3117 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003118 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
3119 &ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303120
3121 c4iw_init_wr_wait(&ep->com.wr_wait);
3122 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3123 ep->stid, &sin6->sin6_addr,
3124 sin6->sin6_port,
3125 ep->com.dev->rdev.lldi.rxq_ids[0]);
3126 if (!err)
3127 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3128 &ep->com.wr_wait,
3129 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303130 else if (err > 0)
3131 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303132 if (err)
3133 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3134 err, ep->stid,
3135 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
3136 return err;
3137}
3138
3139static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3140{
3141 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003142 struct sockaddr_in *sin = (struct sockaddr_in *)
3143 &ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303144
3145 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3146 do {
3147 err = cxgb4_create_server_filter(
3148 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3149 sin->sin_addr.s_addr, sin->sin_port, 0,
3150 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3151 if (err == -EBUSY) {
3152 set_current_state(TASK_UNINTERRUPTIBLE);
3153 schedule_timeout(usecs_to_jiffies(100));
3154 }
3155 } while (err == -EBUSY);
3156 } else {
3157 c4iw_init_wr_wait(&ep->com.wr_wait);
3158 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3159 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3160 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3161 if (!err)
3162 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3163 &ep->com.wr_wait,
3164 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303165 else if (err > 0)
3166 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303167 }
3168 if (err)
3169 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3170 , err, ep->stid,
3171 &sin->sin_addr, ntohs(sin->sin_port));
3172 return err;
3173}
3174
Steve Wisecfdda9d2010-04-21 15:30:06 -07003175int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3176{
3177 int err = 0;
3178 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3179 struct c4iw_listen_ep *ep;
Steve Wise9eccfe12014-03-26 17:08:09 -05003180 struct iwpm_dev_data pm_reg_msg;
3181 struct iwpm_sa_data pm_msg;
3182 int iwpm_err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003183
Steve Wisecfdda9d2010-04-21 15:30:06 -07003184 might_sleep();
3185
3186 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3187 if (!ep) {
3188 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3189 err = -ENOMEM;
3190 goto fail1;
3191 }
3192 PDBG("%s ep %p\n", __func__, ep);
3193 cm_id->add_ref(cm_id);
3194 ep->com.cm_id = cm_id;
3195 ep->com.dev = dev;
3196 ep->backlog = backlog;
Steve Wise24d44a32013-07-04 16:10:44 +05303197 memcpy(&ep->com.local_addr, &cm_id->local_addr,
3198 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003199
3200 /*
3201 * Allocate a server TID.
3202 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303203 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3204 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303205 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
3206 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003207 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303208 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
3209 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003210
Steve Wisecfdda9d2010-04-21 15:30:06 -07003211 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003212 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003213 err = -ENOMEM;
3214 goto fail2;
3215 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003216 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003217
3218 /* No port mapper available, go with the specified info */
3219 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3220 sizeof(ep->com.mapped_local_addr));
3221
3222 c4iw_form_reg_msg(dev, &pm_reg_msg);
3223 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3224 if (iwpm_err) {
3225 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3226 __func__, iwpm_err);
3227 }
3228 if (iwpm_valid_pid() && !iwpm_err) {
3229 memcpy(&pm_msg.loc_addr, &ep->com.local_addr,
3230 sizeof(ep->com.local_addr));
3231 iwpm_err = iwpm_add_mapping(&pm_msg, RDMA_NL_C4IW);
3232 if (iwpm_err)
3233 PDBG("%s: Port Mapper query fail (err = %d).\n",
3234 __func__, iwpm_err);
3235 else
3236 memcpy(&ep->com.mapped_local_addr,
3237 &pm_msg.mapped_loc_addr,
3238 sizeof(ep->com.mapped_local_addr));
3239 }
3240 if (iwpm_create_mapinfo(&ep->com.local_addr,
3241 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3242 err = -ENOMEM;
3243 goto fail3;
3244 }
3245 print_addr(&ep->com, __func__, "add_mapping/create_mapinfo");
3246
3247 set_bit(RELEASE_MAPINFO, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003248 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303249 if (ep->com.local_addr.ss_family == AF_INET)
3250 err = create_server4(dev, ep);
3251 else
3252 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003253 if (!err) {
3254 cm_id->provider_data = ep;
3255 goto out;
3256 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003257
3258fail3:
Vipul Pandya830662f2013-07-04 16:10:47 +05303259 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3260 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003261fail2:
3262 cm_id->rem_ref(cm_id);
3263 c4iw_put_ep(&ep->com);
3264fail1:
3265out:
3266 return err;
3267}
3268
3269int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3270{
3271 int err;
3272 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3273
3274 PDBG("%s ep %p\n", __func__, ep);
3275
3276 might_sleep();
3277 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303278 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3279 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003280 err = cxgb4_remove_server_filter(
3281 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3282 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3283 } else {
3284 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303285 err = cxgb4_remove_server(
3286 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3287 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003288 if (err)
3289 goto done;
3290 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3291 0, 0, __func__);
3292 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003293 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303294 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3295 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003296done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003297 cm_id->rem_ref(cm_id);
3298 c4iw_put_ep(&ep->com);
3299 return err;
3300}
3301
3302int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3303{
3304 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003305 int close = 0;
3306 int fatal = 0;
3307 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003308
Steve Wise2f5b48c2010-09-10 11:15:36 -05003309 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003310
3311 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3312 states[ep->com.state], abrupt);
3313
3314 rdev = &ep->com.dev->rdev;
3315 if (c4iw_fatal_error(rdev)) {
3316 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303317 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003318 ep->com.state = DEAD;
3319 }
3320 switch (ep->com.state) {
3321 case MPA_REQ_WAIT:
3322 case MPA_REQ_SENT:
3323 case MPA_REQ_RCVD:
3324 case MPA_REP_SENT:
3325 case FPDU_MODE:
3326 close = 1;
3327 if (abrupt)
3328 ep->com.state = ABORTING;
3329 else {
3330 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003331 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003332 }
3333 set_bit(CLOSE_SENT, &ep->com.flags);
3334 break;
3335 case CLOSING:
3336 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3337 close = 1;
3338 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003339 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003340 ep->com.state = ABORTING;
3341 } else
3342 ep->com.state = MORIBUND;
3343 }
3344 break;
3345 case MORIBUND:
3346 case ABORTING:
3347 case DEAD:
3348 PDBG("%s ignoring disconnect ep %p state %u\n",
3349 __func__, ep, ep->com.state);
3350 break;
3351 default:
3352 BUG();
3353 break;
3354 }
3355
Steve Wisecfdda9d2010-04-21 15:30:06 -07003356 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003357 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003358 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303359 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003360 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003361 } else {
3362 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003363 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003364 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003365 if (ret)
3366 fatal = 1;
3367 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003368 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003369 if (fatal)
3370 release_ep_resources(ep);
3371 return ret;
3372}
3373
Vipul Pandya1cab7752012-12-10 09:30:55 +00003374static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3375 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3376{
3377 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003378 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003379
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003380 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3381 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003382 if (!ep)
3383 return;
3384
3385 switch (req->retval) {
3386 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003387 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3388 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3389 send_fw_act_open_req(ep, atid);
3390 return;
3391 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003392 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003393 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3394 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3395 send_fw_act_open_req(ep, atid);
3396 return;
3397 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003398 break;
3399 default:
3400 pr_info("%s unexpected ofld conn wr retval %d\n",
3401 __func__, req->retval);
3402 break;
3403 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003404 pr_err("active ofld_connect_wr failure %d atid %d\n",
3405 req->retval, atid);
3406 mutex_lock(&dev->rdev.stats.lock);
3407 dev->rdev.stats.act_ofld_conn_fails++;
3408 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003409 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003410 state_set(&ep->com, DEAD);
3411 remove_handle(dev, &dev->atid_idr, atid);
3412 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3413 dst_release(ep->dst);
3414 cxgb4_l2t_release(ep->l2t);
3415 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003416}
3417
3418static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3419 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3420{
3421 struct sk_buff *rpl_skb;
3422 struct cpl_pass_accept_req *cpl;
3423 int ret;
3424
Paul Bolle710a3112013-02-05 20:51:30 +00003425 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003426 BUG_ON(!rpl_skb);
3427 if (req->retval) {
3428 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003429 mutex_lock(&dev->rdev.stats.lock);
3430 dev->rdev.stats.pas_ofld_conn_fails++;
3431 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003432 kfree_skb(rpl_skb);
3433 } else {
3434 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3435 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003436 (__force u32) htonl(
3437 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003438 ret = pass_accept_req(dev, rpl_skb);
3439 if (!ret)
3440 kfree_skb(rpl_skb);
3441 }
3442 return;
3443}
3444
3445static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003446{
3447 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003448 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3449
3450 switch (rpl->type) {
3451 case FW6_TYPE_CQE:
3452 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3453 break;
3454 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3455 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3456 switch (req->t_state) {
3457 case TCP_SYN_SENT:
3458 active_ofld_conn_reply(dev, skb, req);
3459 break;
3460 case TCP_SYN_RECV:
3461 passive_ofld_conn_reply(dev, skb, req);
3462 break;
3463 default:
3464 pr_err("%s unexpected ofld conn wr state %d\n",
3465 __func__, req->t_state);
3466 break;
3467 }
3468 break;
3469 }
3470 return 0;
3471}
3472
3473static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3474{
3475 u32 l2info;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003476 u16 vlantag, len, hdr_len, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003477 u8 intf;
3478 struct cpl_rx_pkt *cpl = cplhdr(skb);
3479 struct cpl_pass_accept_req *req;
3480 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003481 struct c4iw_dev *dev;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003482
Vipul Pandyaf079af72013-03-14 05:08:58 +00003483 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003484 /* Store values from cpl_rx_pkt in temporary location. */
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003485 vlantag = (__force u16) cpl->vlan;
3486 len = (__force u16) cpl->len;
3487 l2info = (__force u32) cpl->l2info;
3488 hdr_len = (__force u16) cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003489 intf = cpl->iff;
3490
3491 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3492
3493 /*
3494 * We need to parse the TCP options from SYN packet.
3495 * to generate cpl_pass_accept_req.
3496 */
3497 memset(&tmp_opt, 0, sizeof(tmp_opt));
3498 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003499 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003500
3501 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3502 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303503 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3504 SYN_MAC_IDX_V(RX_MACIDX_G(
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003505 (__force int) htonl(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303506 SYN_XACT_MATCH_F);
Vipul Pandyaf079af72013-03-14 05:08:58 +00003507 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003508 RX_ETHHDR_LEN_G((__force int)htonl(l2info)) :
3509 RX_T5_ETHHDR_LEN_G((__force int)htonl(l2info));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303510 req->hdr_len = cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003511 (__force int) htonl(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303512 TCP_HDR_LEN_V(RX_TCPHDR_LEN_G(
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003513 (__force int) htons(hdr_len))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303514 IP_HDR_LEN_V(RX_IPHDR_LEN_G(
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003515 (__force int) htons(hdr_len))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303516 ETH_HDR_LEN_V(RX_ETHHDR_LEN_G(eth_hdr_len)));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003517 req->vlan = (__force __be16) vlantag;
3518 req->len = (__force __be16) len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003519 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3520 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003521 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3522 if (tmp_opt.wscale_ok)
3523 req->tcpopt.wsf = tmp_opt.snd_wscale;
3524 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3525 if (tmp_opt.sack_ok)
3526 req->tcpopt.sack = 1;
3527 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3528 return;
3529}
3530
3531static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3532 __be32 laddr, __be16 lport,
3533 __be32 raddr, __be16 rport,
3534 u32 rcv_isn, u32 filter, u16 window,
3535 u32 rss_qid, u8 port_id)
3536{
3537 struct sk_buff *req_skb;
3538 struct fw_ofld_connection_wr *req;
3539 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303540 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003541
3542 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3543 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3544 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003545 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303546 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303547 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003548 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003549 req->le.lport = lport;
3550 req->le.pport = rport;
3551 req->le.u.ipv4.lip = laddr;
3552 req->le.u.ipv4.pip = raddr;
3553 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3554 req->tcb.rcv_adv = htons(window);
3555 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303556 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3557 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3558 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003559 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003560
3561 /*
3562 * We store the qid in opt2 which will be used by the firmware
3563 * to send us the wr response.
3564 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003565 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003566
3567 /*
3568 * We initialize the MSS index in TCB to 0xF.
3569 * So that when driver sends cpl_pass_accept_rpl
3570 * TCB picks up the correct value. If this was 0
3571 * TP will ignore any value > 0 for MSS index.
3572 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003573 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303574 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003575
3576 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303577 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3578 if (ret < 0) {
3579 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3580 ret);
3581 kfree_skb(skb);
3582 kfree_skb(req_skb);
3583 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003584}
3585
3586/*
3587 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3588 * messages when a filter is being used instead of server to
3589 * redirect a syn packet. When packets hit filter they are redirected
3590 * to the offload queue and driver tries to establish the connection
3591 * using firmware work request.
3592 */
3593static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3594{
3595 int stid;
3596 unsigned int filter;
3597 struct ethhdr *eh = NULL;
3598 struct vlan_ethhdr *vlan_eh = NULL;
3599 struct iphdr *iph;
3600 struct tcphdr *tcph;
3601 struct rss_header *rss = (void *)skb->data;
3602 struct cpl_rx_pkt *cpl = (void *)skb->data;
3603 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3604 struct l2t_entry *e;
3605 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003606 struct c4iw_ep *lep;
3607 u16 window;
3608 struct port_info *pi;
3609 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003610 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003611 int step;
3612 u32 tx_chan;
3613 struct neighbour *neigh;
3614
3615 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003616 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003617 goto reject;
3618
3619 /*
3620 * Drop all packets which did not hit the filter.
3621 * Unlikely to happen.
3622 */
3623 if (!(rss->filter_hit && rss->filter_tid))
3624 goto reject;
3625
3626 /*
3627 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3628 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303629 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003630
3631 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3632 if (!lep) {
3633 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3634 goto reject;
3635 }
3636
Vipul Pandyaf079af72013-03-14 05:08:58 +00003637 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003638 RX_ETHHDR_LEN_G(htonl(cpl->l2info)) :
3639 RX_T5_ETHHDR_LEN_G(htonl(cpl->l2info));
Vipul Pandyaf079af72013-03-14 05:08:58 +00003640 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003641 eh = (struct ethhdr *)(req + 1);
3642 iph = (struct iphdr *)(eh + 1);
3643 } else {
3644 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3645 iph = (struct iphdr *)(vlan_eh + 1);
3646 skb->vlan_tci = ntohs(cpl->vlan);
3647 }
3648
3649 if (iph->version != 0x4)
3650 goto reject;
3651
3652 tcph = (struct tcphdr *)(iph + 1);
3653 skb_set_network_header(skb, (void *)iph - (void *)rss);
3654 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3655 skb_get(skb);
3656
3657 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3658 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3659 ntohs(tcph->source), iph->tos);
3660
Vipul Pandya830662f2013-07-04 16:10:47 +05303661 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3662 iph->tos);
3663 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003664 pr_err("%s - failed to find dst entry!\n",
3665 __func__);
3666 goto reject;
3667 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003668 neigh = dst_neigh_lookup_skb(dst, skb);
3669
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003670 if (!neigh) {
3671 pr_err("%s - failed to allocate neigh!\n",
3672 __func__);
3673 goto free_dst;
3674 }
3675
Vipul Pandya1cab7752012-12-10 09:30:55 +00003676 if (neigh->dev->flags & IFF_LOOPBACK) {
3677 pdev = ip_dev_find(&init_net, iph->daddr);
3678 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3679 pdev, 0);
3680 pi = (struct port_info *)netdev_priv(pdev);
3681 tx_chan = cxgb4_port_chan(pdev);
3682 dev_put(pdev);
3683 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303684 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003685 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303686 pdev, 0);
3687 pi = (struct port_info *)netdev_priv(pdev);
3688 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003689 }
Steve Wiseebf00062014-03-19 17:44:40 +05303690 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003691 if (!e) {
3692 pr_err("%s - failed to allocate l2t entry!\n",
3693 __func__);
3694 goto free_dst;
3695 }
3696
3697 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3698 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003699 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003700
3701 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303702 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3703 dev->rdev.lldi.ports[0],
3704 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003705
3706 /*
3707 * Synthesize the cpl_pass_accept_req. We have everything except the
3708 * TID. Once firmware sends a reply with TID we update the TID field
3709 * in cpl and pass it through the regular cpl_pass_accept_req path.
3710 */
3711 build_cpl_pass_accept_req(skb, stid, iph->tos);
3712 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3713 tcph->source, ntohl(tcph->seq), filter, window,
3714 rss_qid, pi->port_id);
3715 cxgb4_l2t_release(e);
3716free_dst:
3717 dst_release(dst);
3718reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003719 return 0;
3720}
3721
Steve Wisecfdda9d2010-04-21 15:30:06 -07003722/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003723 * These are the real handlers that are called from a
3724 * work queue.
3725 */
3726static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3727 [CPL_ACT_ESTABLISH] = act_establish,
3728 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3729 [CPL_RX_DATA] = rx_data,
3730 [CPL_ABORT_RPL_RSS] = abort_rpl,
3731 [CPL_ABORT_RPL] = abort_rpl,
3732 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3733 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3734 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3735 [CPL_PASS_ESTABLISH] = pass_establish,
3736 [CPL_PEER_CLOSE] = peer_close,
3737 [CPL_ABORT_REQ_RSS] = peer_abort,
3738 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3739 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003740 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003741 [CPL_FW6_MSG] = deferred_fw6_msg,
3742 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003743};
3744
3745static void process_timeout(struct c4iw_ep *ep)
3746{
3747 struct c4iw_qp_attributes attrs;
3748 int abort = 1;
3749
Steve Wise2f5b48c2010-09-10 11:15:36 -05003750 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003751 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3752 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003753 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003754 switch (ep->com.state) {
3755 case MPA_REQ_SENT:
3756 __state_set(&ep->com, ABORTING);
3757 connect_reply_upcall(ep, -ETIMEDOUT);
3758 break;
3759 case MPA_REQ_WAIT:
3760 __state_set(&ep->com, ABORTING);
3761 break;
3762 case CLOSING:
3763 case MORIBUND:
3764 if (ep->com.cm_id && ep->com.qp) {
3765 attrs.next_state = C4IW_QP_STATE_ERROR;
3766 c4iw_modify_qp(ep->com.qp->rhp,
3767 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3768 &attrs, 1);
3769 }
3770 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303771 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003772 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003773 case ABORTING:
3774 case DEAD:
3775
3776 /*
3777 * These states are expected if the ep timed out at the same
3778 * time as another thread was calling stop_ep_timer().
3779 * So we silently do nothing for these states.
3780 */
3781 abort = 0;
3782 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003783 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003784 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003785 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003786 abort = 0;
3787 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003788 if (abort)
3789 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecc18b932014-04-24 14:31:53 -05003790 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003791 c4iw_put_ep(&ep->com);
3792}
3793
3794static void process_timedout_eps(void)
3795{
3796 struct c4iw_ep *ep;
3797
3798 spin_lock_irq(&timeout_lock);
3799 while (!list_empty(&timeout_list)) {
3800 struct list_head *tmp;
3801
3802 tmp = timeout_list.next;
3803 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003804 tmp->next = NULL;
3805 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003806 spin_unlock_irq(&timeout_lock);
3807 ep = list_entry(tmp, struct c4iw_ep, entry);
3808 process_timeout(ep);
3809 spin_lock_irq(&timeout_lock);
3810 }
3811 spin_unlock_irq(&timeout_lock);
3812}
3813
3814static void process_work(struct work_struct *work)
3815{
3816 struct sk_buff *skb = NULL;
3817 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003818 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003819 unsigned int opcode;
3820 int ret;
3821
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003822 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003823 while ((skb = skb_dequeue(&rxq))) {
3824 rpl = cplhdr(skb);
3825 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3826 opcode = rpl->ot.opcode;
3827
3828 BUG_ON(!work_handlers[opcode]);
3829 ret = work_handlers[opcode](dev, skb);
3830 if (!ret)
3831 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003832 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003833 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003834}
3835
3836static DECLARE_WORK(skb_work, process_work);
3837
3838static void ep_timeout(unsigned long arg)
3839{
3840 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003841 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003842
3843 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003844 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003845 /*
3846 * Only insert if it is not already on the list.
3847 */
3848 if (!ep->entry.next) {
3849 list_add_tail(&ep->entry, &timeout_list);
3850 kickit = 1;
3851 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003852 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003853 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003854 if (kickit)
3855 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003856}
3857
3858/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07003859 * All the CM events are handled on a work queue to have a safe context.
3860 */
3861static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3862{
3863
3864 /*
3865 * Save dev in the skb->cb area.
3866 */
3867 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3868
3869 /*
3870 * Queue the skb and schedule the worker thread.
3871 */
3872 skb_queue_tail(&rxq, skb);
3873 queue_work(workq, &skb_work);
3874 return 0;
3875}
3876
3877static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3878{
3879 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3880
3881 if (rpl->status != CPL_ERR_NONE) {
3882 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3883 "for tid %u\n", rpl->status, GET_TID(rpl));
3884 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003885 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003886 return 0;
3887}
3888
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003889static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3890{
3891 struct cpl_fw6_msg *rpl = cplhdr(skb);
3892 struct c4iw_wr_wait *wr_waitp;
3893 int ret;
3894
3895 PDBG("%s type %u\n", __func__, rpl->type);
3896
3897 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003898 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003899 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07003900 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003901 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07003902 if (wr_waitp)
3903 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003904 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003905 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003906 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003907 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00003908 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003909 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003910 default:
3911 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3912 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003913 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003914 break;
3915 }
3916 return 0;
3917}
3918
Steve Wise8da7e7a2011-06-14 20:59:27 +00003919static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3920{
3921 struct cpl_abort_req_rss *req = cplhdr(skb);
3922 struct c4iw_ep *ep;
3923 struct tid_info *t = dev->rdev.lldi.tids;
3924 unsigned int tid = GET_TID(req);
3925
3926 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05003927 if (!ep) {
3928 printk(KERN_WARNING MOD
3929 "Abort on non-existent endpoint, tid %d\n", tid);
3930 kfree_skb(skb);
3931 return 0;
3932 }
Steve Wise7a2cea22014-03-14 21:52:07 +05303933 if (is_neg_adv(req->status)) {
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05303934 dev_warn(&dev->rdev.lldi.pdev->dev,
3935 "Negative advice on abort - tid %u status %d (%s)\n",
3936 ep->hwtid, req->status, neg_adv_str(req->status));
Steve Wise8da7e7a2011-06-14 20:59:27 +00003937 kfree_skb(skb);
3938 return 0;
3939 }
3940 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3941 ep->com.state);
3942
3943 /*
3944 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003945 * However, if we are on MPAv2 and want to retry with MPAv1
3946 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00003947 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003948 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
3949 if (ep->com.state != MPA_REQ_SENT)
3950 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3951 } else
3952 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003953 sched(dev, skb);
3954 return 0;
3955}
3956
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003957/*
3958 * Most upcalls from the T4 Core go to sched() to
3959 * schedule the processing on a work queue.
3960 */
3961c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3962 [CPL_ACT_ESTABLISH] = sched,
3963 [CPL_ACT_OPEN_RPL] = sched,
3964 [CPL_RX_DATA] = sched,
3965 [CPL_ABORT_RPL_RSS] = sched,
3966 [CPL_ABORT_RPL] = sched,
3967 [CPL_PASS_OPEN_RPL] = sched,
3968 [CPL_CLOSE_LISTSRV_RPL] = sched,
3969 [CPL_PASS_ACCEPT_REQ] = sched,
3970 [CPL_PASS_ESTABLISH] = sched,
3971 [CPL_PEER_CLOSE] = sched,
3972 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00003973 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003974 [CPL_RDMA_TERMINATE] = sched,
3975 [CPL_FW4_ACK] = sched,
3976 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003977 [CPL_FW6_MSG] = fw6_msg,
3978 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003979};
3980
Steve Wisecfdda9d2010-04-21 15:30:06 -07003981int __init c4iw_cm_init(void)
3982{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003983 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003984 skb_queue_head_init(&rxq);
3985
3986 workq = create_singlethread_workqueue("iw_cxgb4");
3987 if (!workq)
3988 return -ENOMEM;
3989
Steve Wisecfdda9d2010-04-21 15:30:06 -07003990 return 0;
3991}
3992
Steve Wise46c13762014-06-20 14:26:25 -05003993void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07003994{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003995 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003996 flush_workqueue(workq);
3997 destroy_workqueue(workq);
3998}