blob: fb61f6685809e21f853d849d056a9111e2c3b6d0 [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 Shenai92e7ae72014-06-06 21:40:43 +0530238 ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(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;
243 if (GET_TCPOPT_TSTAMP(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",
249 GET_TCPOPT_MSS(opt), ep->mss, ep->emss);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700250 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
251 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
475 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
476 FW_FLOWC_WR_NPARAMS(8));
477 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
478 16)) | FW_WR_FLOWID(ep->hwtid));
479
480 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530481 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN
482 (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;
652 if (win > RCV_BUFSIZ_MASK)
653 win = RCV_BUFSIZ_MASK;
654
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000655 opt0 = (nocong ? NO_CONG(1) : 0) |
656 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +0000657 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700658 WND_SCALE(wscale) |
659 MSS_IDX(mtu_idx) |
660 L2T_IDX(ep->l2t->idx) |
661 TX_CHAN(ep->tx_chan) |
662 SMAC_SEL(ep->smac_idx) |
663 DSCP(ep->tos) |
Steve Wiseb48f3b92011-03-11 22:30:21 +0000664 ULP_MODE(ULP_MODE_TCPDDP) |
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530665 RCV_BUFSIZ(win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700666 opt2 = RX_CHANNEL(0) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000667 CCTRL_ECN(enable_ecn) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700668 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
669 if (enable_tcp_timestamps)
670 opt2 |= TSTAMPS_EN(1);
671 if (enable_tcp_sack)
672 opt2 |= SACK_EN(1);
673 if (wscale && enable_tcp_window_scaling)
674 opt2 |= WND_SCALE_EN(1);
Steve Wise92e50112014-04-24 14:31:59 -0500675 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
676 opt2 |= T5_OPT_2_VALID;
677 opt2 |= V_CONG_CNTRL(CONG_ALG_TAHOE);
Hariprasad Sda22b8962014-09-24 03:53:43 +0530678 opt2 |= CONG_CNTRL_VALID; /* OPT_2_ISS for T5 */
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);
739 t5_req->params = cpu_to_be64(V_FILTER_TUPLE(
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);
Hariprasad Sda22b8962014-09-24 03:53:43 +0530765 t5_req6->params = cpu_to_be64(V_FILTER_TUPLE(
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(
806 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
807 FW_WR_COMPL(1) |
808 FW_WR_IMMDLEN(mpalen));
809 req->flowid_len16 = cpu_to_be32(
810 FW_WR_FLOWID(ep->hwtid) |
811 FW_WR_LEN16(wrlen >> 4));
812 req->plen = cpu_to_be32(mpalen);
813 req->tunnel_to_proxy = cpu_to_be32(
814 FW_OFLD_TX_DATA_WR_FLUSH(1) |
815 FW_OFLD_TX_DATA_WR_SHOVE(1));
816
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(
900 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
901 FW_WR_COMPL(1) |
902 FW_WR_IMMDLEN(mpalen));
903 req->flowid_len16 = cpu_to_be32(
904 FW_WR_FLOWID(ep->hwtid) |
905 FW_WR_LEN16(wrlen >> 4));
906 req->plen = cpu_to_be32(mpalen);
907 req->tunnel_to_proxy = cpu_to_be32(
908 FW_OFLD_TX_DATA_WR_FLUSH(1) |
909 FW_OFLD_TX_DATA_WR_SHOVE(1));
910
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(
980 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
981 FW_WR_COMPL(1) |
982 FW_WR_IMMDLEN(mpalen));
983 req->flowid_len16 = cpu_to_be32(
984 FW_WR_FLOWID(ep->hwtid) |
985 FW_WR_LEN16(wrlen >> 4));
986 req->plen = cpu_to_be32(mpalen);
987 req->tunnel_to_proxy = cpu_to_be32(
988 FW_OFLD_TX_DATA_WR_FLUSH(1) |
989 FW_OFLD_TX_DATA_WR_SHOVE(1));
990
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);
1045 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
1046 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 */
1252 if (ep->rcv_win > RCV_BUFSIZ_MASK * 1024)
1253 credits += ep->rcv_win - RCV_BUFSIZ_MASK * 1024;
1254
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));
Steve Wiseba6d3922010-06-23 15:46:49 +00001260 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1261 F_RX_DACK_CHANGE |
1262 V_RX_DACK_MODE(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 */
1643 mutex_lock(&ep->parent_ep->com.mutex);
1644 if (ep->parent_ep->com.state != DEAD) {
1645 if (connect_request_upcall(ep))
1646 abort_connection(ep, skb, GFP_KERNEL);
1647 } else {
Steve Wisebe13b2d2014-03-21 20:40:33 +05301648 abort_connection(ep, skb, GFP_KERNEL);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001649 }
1650 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301651 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001652 return;
1653}
1654
1655static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1656{
1657 struct c4iw_ep *ep;
1658 struct cpl_rx_data *hdr = cplhdr(skb);
1659 unsigned int dlen = ntohs(hdr->len);
1660 unsigned int tid = GET_TID(hdr);
1661 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001662 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001663 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001664
1665 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301666 if (!ep)
1667 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001668 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1669 skb_pull(skb, sizeof(*hdr));
1670 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301671 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001672
Steve Wisecfdda9d2010-04-21 15:30:06 -07001673 /* update RX credits */
1674 update_rx_credits(ep, dlen);
1675
Steve Wisec529fb52014-03-21 20:40:37 +05301676 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001677 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001678 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001679 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001680 break;
1681 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001682 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001683 process_mpa_request(ep, skb);
1684 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001685 case FPDU_MODE: {
1686 struct c4iw_qp_attributes attrs;
1687 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001688 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001689 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001690 " qpid %u ep %p state %d tid %u status %d\n",
1691 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301692 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301693 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001694 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001695 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1696 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001697 break;
1698 }
Vipul Pandya15579672013-01-07 13:11:52 +00001699 default:
1700 break;
1701 }
Steve Wisec529fb52014-03-21 20:40:37 +05301702 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001703 if (disconnect)
1704 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001705 return 0;
1706}
1707
1708static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1709{
1710 struct c4iw_ep *ep;
1711 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001712 int release = 0;
1713 unsigned int tid = GET_TID(rpl);
1714 struct tid_info *t = dev->rdev.lldi.tids;
1715
1716 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301717 if (!ep) {
1718 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1719 return 0;
1720 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001721 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001722 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001723 switch (ep->com.state) {
1724 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001725 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001726 __state_set(&ep->com, DEAD);
1727 release = 1;
1728 break;
1729 default:
1730 printk(KERN_ERR "%s ep %p state %d\n",
1731 __func__, ep, ep->com.state);
1732 break;
1733 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001734 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001735
1736 if (release)
1737 release_ep_resources(ep);
1738 return 0;
1739}
1740
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001741static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1742{
1743 struct sk_buff *skb;
1744 struct fw_ofld_connection_wr *req;
1745 unsigned int mtu_idx;
1746 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301747 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301748 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001749
1750 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1751 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1752 memset(req, 0, sizeof(*req));
1753 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1754 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301755 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1756 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001757 ep->l2t));
Steve Wise9eccfe12014-03-26 17:08:09 -05001758 sin = (struct sockaddr_in *)&ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301759 req->le.lport = sin->sin_port;
1760 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05001761 sin = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301762 req->le.pport = sin->sin_port;
1763 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001764 req->tcb.t_state_to_astid =
1765 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1766 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1767 req->tcb.cplrxdataack_cplpassacceptrpl =
1768 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001769 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001770 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301771 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301772 enable_tcp_timestamps,
1773 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001774 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301775
1776 /*
1777 * Specify the largest window that will fit in opt0. The
1778 * remainder will be specified in the rx_data_ack.
1779 */
1780 win = ep->rcv_win >> 10;
1781 if (win > RCV_BUFSIZ_MASK)
1782 win = RCV_BUFSIZ_MASK;
1783
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001784 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001785 (nocong ? NO_CONG(1) : 0) |
1786 KEEP_ALIVE(1) |
1787 DELACK(1) |
1788 WND_SCALE(wscale) |
1789 MSS_IDX(mtu_idx) |
1790 L2T_IDX(ep->l2t->idx) |
1791 TX_CHAN(ep->tx_chan) |
1792 SMAC_SEL(ep->smac_idx) |
1793 DSCP(ep->tos) |
1794 ULP_MODE(ULP_MODE_TCPDDP) |
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301795 RCV_BUFSIZ(win));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001796 req->tcb.opt2 = (__force __be32) (PACE(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001797 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1798 RX_CHANNEL(0) |
1799 CCTRL_ECN(enable_ecn) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001800 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001801 if (enable_tcp_timestamps)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001802 req->tcb.opt2 |= (__force __be32) TSTAMPS_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001803 if (enable_tcp_sack)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001804 req->tcb.opt2 |= (__force __be32) SACK_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001805 if (wscale && enable_tcp_window_scaling)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001806 req->tcb.opt2 |= (__force __be32) WND_SCALE_EN(1);
1807 req->tcb.opt0 = cpu_to_be64((__force u64) req->tcb.opt0);
1808 req->tcb.opt2 = cpu_to_be32((__force u32) req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001809 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1810 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001811 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1812}
1813
Steve Wisecfdda9d2010-04-21 15:30:06 -07001814/*
1815 * Return whether a failed active open has allocated a TID
1816 */
1817static inline int act_open_has_tid(int status)
1818{
1819 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1820 status != CPL_ERR_ARP_MISS;
1821}
1822
Steve Wise7a2cea22014-03-14 21:52:07 +05301823/* Returns whether a CPL status conveys negative advice.
1824 */
1825static int is_neg_adv(unsigned int status)
1826{
1827 return status == CPL_ERR_RTX_NEG_ADVICE ||
1828 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1829 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1830}
1831
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301832static char *neg_adv_str(unsigned int status)
1833{
1834 switch (status) {
1835 case CPL_ERR_RTX_NEG_ADVICE:
1836 return "Retransmit timeout";
1837 case CPL_ERR_PERSIST_NEG_ADVICE:
1838 return "Persist timeout";
1839 case CPL_ERR_KEEPALV_NEG_ADVICE:
1840 return "Keepalive timeout";
1841 default:
1842 return "Unknown";
1843 }
1844}
1845
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301846static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1847{
1848 ep->snd_win = snd_win;
1849 ep->rcv_win = rcv_win;
1850 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1851}
1852
Vipul Pandya793dad92012-12-10 09:30:56 +00001853#define ACT_OPEN_RETRY_COUNT 2
1854
Vipul Pandya830662f2013-07-04 16:10:47 +05301855static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1856 struct dst_entry *dst, struct c4iw_dev *cdev,
1857 bool clear_mpa_v1)
1858{
1859 struct neighbour *n;
1860 int err, step;
1861 struct net_device *pdev;
1862
1863 n = dst_neigh_lookup(dst, peer_ip);
1864 if (!n)
1865 return -ENODEV;
1866
1867 rcu_read_lock();
1868 err = -ENOMEM;
1869 if (n->dev->flags & IFF_LOOPBACK) {
1870 if (iptype == 4)
1871 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1872 else if (IS_ENABLED(CONFIG_IPV6))
1873 for_each_netdev(&init_net, pdev) {
1874 if (ipv6_chk_addr(&init_net,
1875 (struct in6_addr *)peer_ip,
1876 pdev, 1))
1877 break;
1878 }
1879 else
1880 pdev = NULL;
1881
1882 if (!pdev) {
1883 err = -ENODEV;
1884 goto out;
1885 }
1886 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1887 n, pdev, 0);
1888 if (!ep->l2t)
1889 goto out;
1890 ep->mtu = pdev->mtu;
1891 ep->tx_chan = cxgb4_port_chan(pdev);
1892 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1893 step = cdev->rdev.lldi.ntxq /
1894 cdev->rdev.lldi.nchan;
1895 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1896 step = cdev->rdev.lldi.nrxq /
1897 cdev->rdev.lldi.nchan;
1898 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1899 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1900 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301901 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301902 dev_put(pdev);
1903 } else {
1904 pdev = get_real_dev(n->dev);
1905 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1906 n, pdev, 0);
1907 if (!ep->l2t)
1908 goto out;
1909 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05001910 ep->tx_chan = cxgb4_port_chan(pdev);
1911 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
Vipul Pandya830662f2013-07-04 16:10:47 +05301912 step = cdev->rdev.lldi.ntxq /
1913 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05001914 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1915 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05301916 step = cdev->rdev.lldi.nrxq /
1917 cdev->rdev.lldi.nchan;
1918 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05001919 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301920 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301921
1922 if (clear_mpa_v1) {
1923 ep->retry_with_mpa_v1 = 0;
1924 ep->tried_with_mpa_v1 = 0;
1925 }
1926 }
1927 err = 0;
1928out:
1929 rcu_read_unlock();
1930
1931 neigh_release(n);
1932
1933 return err;
1934}
1935
Vipul Pandya793dad92012-12-10 09:30:56 +00001936static int c4iw_reconnect(struct c4iw_ep *ep)
1937{
1938 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05301939 struct sockaddr_in *laddr = (struct sockaddr_in *)
1940 &ep->com.cm_id->local_addr;
1941 struct sockaddr_in *raddr = (struct sockaddr_in *)
1942 &ep->com.cm_id->remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301943 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
1944 &ep->com.cm_id->local_addr;
1945 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
1946 &ep->com.cm_id->remote_addr;
1947 int iptype;
1948 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00001949
1950 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1951 init_timer(&ep->timer);
1952
1953 /*
1954 * Allocate an active TID to initiate a TCP connection.
1955 */
1956 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1957 if (ep->atid == -1) {
1958 pr_err("%s - cannot alloc atid.\n", __func__);
1959 err = -ENOMEM;
1960 goto fail2;
1961 }
1962 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1963
1964 /* find a route */
Vipul Pandya830662f2013-07-04 16:10:47 +05301965 if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
1966 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
1967 raddr->sin_addr.s_addr, laddr->sin_port,
1968 raddr->sin_port, 0);
1969 iptype = 4;
1970 ra = (__u8 *)&raddr->sin_addr;
1971 } else {
1972 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
1973 raddr6->sin6_addr.s6_addr,
1974 laddr6->sin6_port, raddr6->sin6_port, 0,
1975 raddr6->sin6_scope_id);
1976 iptype = 6;
1977 ra = (__u8 *)&raddr6->sin6_addr;
1978 }
1979 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001980 pr_err("%s - cannot find route.\n", __func__);
1981 err = -EHOSTUNREACH;
1982 goto fail3;
1983 }
Vipul Pandya830662f2013-07-04 16:10:47 +05301984 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false);
1985 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001986 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00001987 goto fail4;
1988 }
1989
1990 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1991 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1992 ep->l2t->idx);
1993
1994 state_set(&ep->com, CONNECTING);
1995 ep->tos = 0;
1996
1997 /* send connect request to rnic */
1998 err = send_connect(ep);
1999 if (!err)
2000 goto out;
2001
2002 cxgb4_l2t_release(ep->l2t);
2003fail4:
2004 dst_release(ep->dst);
2005fail3:
2006 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2007 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2008fail2:
2009 /*
2010 * remember to send notification to upper layer.
2011 * We are in here so the upper layer is not aware that this is
2012 * re-connect attempt and so, upper layer is still waiting for
2013 * response of 1st connect request.
2014 */
2015 connect_reply_upcall(ep, -ECONNRESET);
2016 c4iw_put_ep(&ep->com);
2017out:
2018 return err;
2019}
2020
Steve Wisecfdda9d2010-04-21 15:30:06 -07002021static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2022{
2023 struct c4iw_ep *ep;
2024 struct cpl_act_open_rpl *rpl = cplhdr(skb);
2025 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
2026 ntohl(rpl->atid_status)));
2027 struct tid_info *t = dev->rdev.lldi.tids;
2028 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302029 struct sockaddr_in *la;
2030 struct sockaddr_in *ra;
2031 struct sockaddr_in6 *la6;
2032 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002033
2034 ep = lookup_atid(t, atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05002035 la = (struct sockaddr_in *)&ep->com.mapped_local_addr;
2036 ra = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
2037 la6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
2038 ra6 = (struct sockaddr_in6 *)&ep->com.mapped_remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002039
2040 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2041 status, status2errno(status));
2042
Steve Wise7a2cea22014-03-14 21:52:07 +05302043 if (is_neg_adv(status)) {
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05302044 dev_warn(&dev->rdev.lldi.pdev->dev,
2045 "Connection problems for atid %u status %u (%s)\n",
2046 atid, status, neg_adv_str(status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002047 return 0;
2048 }
2049
Vipul Pandya793dad92012-12-10 09:30:56 +00002050 set_bit(ACT_OPEN_RPL, &ep->com.history);
2051
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302052 /*
2053 * Log interesting failures.
2054 */
2055 switch (status) {
2056 case CPL_ERR_CONN_RESET:
2057 case CPL_ERR_CONN_TIMEDOUT:
2058 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002059 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302060 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002061 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302062 mutex_unlock(&dev->rdev.stats.lock);
2063 if (ep->com.local_addr.ss_family == AF_INET &&
2064 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002065 send_fw_act_open_req(ep,
2066 GET_TID_TID(GET_AOPEN_ATID(
2067 ntohl(rpl->atid_status))));
2068 return 0;
2069 }
2070 break;
2071 case CPL_ERR_CONN_EXIST:
2072 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2073 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2074 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2075 atid);
2076 cxgb4_free_atid(t, atid);
2077 dst_release(ep->dst);
2078 cxgb4_l2t_release(ep->l2t);
2079 c4iw_reconnect(ep);
2080 return 0;
2081 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002082 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302083 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302084 if (ep->com.local_addr.ss_family == AF_INET) {
2085 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2086 atid, status, status2errno(status),
2087 &la->sin_addr.s_addr, ntohs(la->sin_port),
2088 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2089 } else {
2090 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2091 atid, status, status2errno(status),
2092 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2093 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2094 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302095 break;
2096 }
2097
Steve Wisecfdda9d2010-04-21 15:30:06 -07002098 connect_reply_upcall(ep, status2errno(status));
2099 state_set(&ep->com, DEAD);
2100
2101 if (status && act_open_has_tid(status))
2102 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2103
Vipul Pandya793dad92012-12-10 09:30:56 +00002104 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002105 cxgb4_free_atid(t, atid);
2106 dst_release(ep->dst);
2107 cxgb4_l2t_release(ep->l2t);
2108 c4iw_put_ep(&ep->com);
2109
2110 return 0;
2111}
2112
2113static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2114{
2115 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2116 struct tid_info *t = dev->rdev.lldi.tids;
2117 unsigned int stid = GET_TID(rpl);
2118 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2119
2120 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002121 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2122 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002123 }
2124 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2125 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002126 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002127
Vipul Pandya1cab7752012-12-10 09:30:55 +00002128out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002129 return 0;
2130}
2131
Steve Wisecfdda9d2010-04-21 15:30:06 -07002132static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2133{
2134 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2135 struct tid_info *t = dev->rdev.lldi.tids;
2136 unsigned int stid = GET_TID(rpl);
2137 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2138
2139 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002140 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002141 return 0;
2142}
2143
Vipul Pandya830662f2013-07-04 16:10:47 +05302144static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002145 struct cpl_pass_accept_req *req)
2146{
2147 struct cpl_pass_accept_rpl *rpl;
2148 unsigned int mtu_idx;
2149 u64 opt0;
2150 u32 opt2;
2151 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302152 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302153 int win;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002154
2155 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2156 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302157
Steve Wisecfdda9d2010-04-21 15:30:06 -07002158 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302159 rpl = cplhdr(skb);
2160 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
2161 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2162 rpl5 = (void *)rpl;
2163 INIT_TP_WR(rpl5, ep->hwtid);
2164 } else {
2165 skb_trim(skb, sizeof(*rpl));
2166 INIT_TP_WR(rpl, ep->hwtid);
2167 }
2168 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2169 ep->hwtid));
2170
2171 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302172 enable_tcp_timestamps && req->tcpopt.tstamp,
2173 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002174 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302175
2176 /*
2177 * Specify the largest window that will fit in opt0. The
2178 * remainder will be specified in the rx_data_ack.
2179 */
2180 win = ep->rcv_win >> 10;
2181 if (win > RCV_BUFSIZ_MASK)
2182 win = RCV_BUFSIZ_MASK;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002183 opt0 = (nocong ? NO_CONG(1) : 0) |
2184 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +00002185 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07002186 WND_SCALE(wscale) |
2187 MSS_IDX(mtu_idx) |
2188 L2T_IDX(ep->l2t->idx) |
2189 TX_CHAN(ep->tx_chan) |
2190 SMAC_SEL(ep->smac_idx) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002191 DSCP(ep->tos >> 2) |
Steve Wiseb48f3b92011-03-11 22:30:21 +00002192 ULP_MODE(ULP_MODE_TCPDDP) |
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302193 RCV_BUFSIZ(win);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002194 opt2 = RX_CHANNEL(0) |
2195 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
2196
2197 if (enable_tcp_timestamps && req->tcpopt.tstamp)
2198 opt2 |= TSTAMPS_EN(1);
2199 if (enable_tcp_sack && req->tcpopt.sack)
2200 opt2 |= SACK_EN(1);
2201 if (wscale && enable_tcp_window_scaling)
2202 opt2 |= WND_SCALE_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002203 if (enable_ecn) {
2204 const struct tcphdr *tcph;
2205 u32 hlen = ntohl(req->hdr_len);
2206
2207 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
2208 G_IP_HDR_LEN(hlen);
2209 if (tcph->ece && tcph->cwr)
2210 opt2 |= CCTRL_ECN(1);
2211 }
Steve Wise92e50112014-04-24 14:31:59 -05002212 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302213 u32 isn = (prandom_u32() & ~7UL) - 1;
Steve Wise92e50112014-04-24 14:31:59 -05002214 opt2 |= T5_OPT_2_VALID;
2215 opt2 |= V_CONG_CNTRL(CONG_ALG_TAHOE);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302216 opt2 |= CONG_CNTRL_VALID; /* OPT_2_ISS for T5 */
2217 rpl5 = (void *)rpl;
2218 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2219 if (peer2peer)
2220 isn += 4;
2221 rpl5->iss = cpu_to_be32(isn);
2222 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002223 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002224
Steve Wisecfdda9d2010-04-21 15:30:06 -07002225 rpl->opt0 = cpu_to_be64(opt0);
2226 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002227 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wiseb38a0ad2013-08-06 21:04:37 +05302228 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002229 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2230
2231 return;
2232}
2233
Vipul Pandya830662f2013-07-04 16:10:47 +05302234static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002235{
Vipul Pandya830662f2013-07-04 16:10:47 +05302236 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002237 BUG_ON(skb_cloned(skb));
2238 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002239 release_tid(&dev->rdev, hwtid, skb);
2240 return;
2241}
2242
Vipul Pandya830662f2013-07-04 16:10:47 +05302243static void get_4tuple(struct cpl_pass_accept_req *req, int *iptype,
2244 __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002245 __be16 *local_port, __be16 *peer_port)
2246{
2247 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
2248 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
2249 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302250 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002251 struct tcphdr *tcp = (struct tcphdr *)
2252 ((u8 *)(req + 1) + eth_len + ip_len);
2253
Vipul Pandya830662f2013-07-04 16:10:47 +05302254 if (ip->version == 4) {
2255 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2256 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2257 ntohs(tcp->dest));
2258 *iptype = 4;
2259 memcpy(peer_ip, &ip->saddr, 4);
2260 memcpy(local_ip, &ip->daddr, 4);
2261 } else {
2262 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2263 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2264 ntohs(tcp->dest));
2265 *iptype = 6;
2266 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2267 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2268 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002269 *peer_port = tcp->source;
2270 *local_port = tcp->dest;
2271
2272 return;
2273}
2274
2275static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2276{
Vipul Pandya793dad92012-12-10 09:30:56 +00002277 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002278 struct cpl_pass_accept_req *req = cplhdr(skb);
2279 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
2280 struct tid_info *t = dev->rdev.lldi.tids;
2281 unsigned int hwtid = GET_TID(req);
2282 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302283 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002284 __be16 local_port, peer_port;
David Miller3786cf12011-12-02 16:52:31 +00002285 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002286 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302287 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302288 unsigned short hdrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002289
2290 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002291 if (!parent_ep) {
2292 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2293 goto reject;
2294 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002295
Steve Wisecfdda9d2010-04-21 15:30:06 -07002296 if (state_read(&parent_ep->com) != LISTEN) {
2297 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
2298 __func__);
2299 goto reject;
2300 }
2301
Vipul Pandya830662f2013-07-04 16:10:47 +05302302 get_4tuple(req, &iptype, local_ip, peer_ip, &local_port, &peer_port);
2303
Steve Wisecfdda9d2010-04-21 15:30:06 -07002304 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302305 if (iptype == 4) {
2306 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2307 , __func__, parent_ep, hwtid,
2308 local_ip, peer_ip, ntohs(local_port),
2309 ntohs(peer_port), peer_mss);
2310 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2311 local_port, peer_port,
2312 GET_POPEN_TOS(ntohl(req->tos_stid)));
2313 } else {
2314 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2315 , __func__, parent_ep, hwtid,
2316 local_ip, peer_ip, ntohs(local_port),
2317 ntohs(peer_port), peer_mss);
2318 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
2319 PASS_OPEN_TOS(ntohl(req->tos_stid)),
2320 ((struct sockaddr_in6 *)
2321 &parent_ep->com.local_addr)->sin6_scope_id);
2322 }
2323 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002324 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2325 __func__);
2326 goto reject;
2327 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002328
2329 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2330 if (!child_ep) {
2331 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2332 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002333 dst_release(dst);
2334 goto reject;
2335 }
David Miller3786cf12011-12-02 16:52:31 +00002336
Vipul Pandya830662f2013-07-04 16:10:47 +05302337 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false);
David Miller3786cf12011-12-02 16:52:31 +00002338 if (err) {
2339 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2340 __func__);
2341 dst_release(dst);
2342 kfree(child_ep);
2343 goto reject;
2344 }
2345
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302346 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2347 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2348 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2349 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002350
Steve Wisecfdda9d2010-04-21 15:30:06 -07002351 state_set(&child_ep->com, CONNECTING);
2352 child_ep->com.dev = dev;
2353 child_ep->com.cm_id = NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +05302354 if (iptype == 4) {
2355 struct sockaddr_in *sin = (struct sockaddr_in *)
2356 &child_ep->com.local_addr;
2357 sin->sin_family = PF_INET;
2358 sin->sin_port = local_port;
2359 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2360 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
2361 sin->sin_family = PF_INET;
2362 sin->sin_port = peer_port;
2363 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2364 } else {
2365 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
2366 &child_ep->com.local_addr;
2367 sin6->sin6_family = PF_INET6;
2368 sin6->sin6_port = local_port;
2369 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2370 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
2371 sin6->sin6_family = PF_INET6;
2372 sin6->sin6_port = peer_port;
2373 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2374 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002375 c4iw_get_ep(&parent_ep->com);
2376 child_ep->parent_ep = parent_ep;
2377 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002378 child_ep->dst = dst;
2379 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002380
2381 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002382 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002383
2384 init_timer(&child_ep->timer);
2385 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002386 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Vipul Pandya830662f2013-07-04 16:10:47 +05302387 accept_cr(child_ep, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00002388 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002389 goto out;
2390reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302391 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002392out:
2393 return 0;
2394}
2395
2396static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2397{
2398 struct c4iw_ep *ep;
2399 struct cpl_pass_establish *req = cplhdr(skb);
2400 struct tid_info *t = dev->rdev.lldi.tids;
2401 unsigned int tid = GET_TID(req);
2402
2403 ep = lookup_tid(t, tid);
2404 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2405 ep->snd_seq = be32_to_cpu(req->snd_isn);
2406 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2407
Vipul Pandya1cab7752012-12-10 09:30:55 +00002408 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2409 ntohs(req->tcp_opt));
2410
Steve Wisecfdda9d2010-04-21 15:30:06 -07002411 set_emss(ep, ntohs(req->tcp_opt));
2412
2413 dst_confirm(ep->dst);
2414 state_set(&ep->com, MPA_REQ_WAIT);
2415 start_ep_timer(ep);
2416 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002417 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002418
2419 return 0;
2420}
2421
2422static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2423{
2424 struct cpl_peer_close *hdr = cplhdr(skb);
2425 struct c4iw_ep *ep;
2426 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002427 int disconnect = 1;
2428 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002429 struct tid_info *t = dev->rdev.lldi.tids;
2430 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002431 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002432
2433 ep = lookup_tid(t, tid);
2434 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2435 dst_confirm(ep->dst);
2436
Vipul Pandya793dad92012-12-10 09:30:56 +00002437 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002438 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002439 switch (ep->com.state) {
2440 case MPA_REQ_WAIT:
2441 __state_set(&ep->com, CLOSING);
2442 break;
2443 case MPA_REQ_SENT:
2444 __state_set(&ep->com, CLOSING);
2445 connect_reply_upcall(ep, -ECONNRESET);
2446 break;
2447 case MPA_REQ_RCVD:
2448
2449 /*
2450 * We're gonna mark this puppy DEAD, but keep
2451 * the reference on it until the ULP accepts or
2452 * rejects the CR. Also wake up anyone waiting
2453 * in rdma connection migration (see c4iw_accept_cr()).
2454 */
2455 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002456 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002457 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002458 break;
2459 case MPA_REP_SENT:
2460 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002461 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002462 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002463 break;
2464 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002465 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002466 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002467 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002468 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002469 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002470 if (ret != -ECONNRESET) {
2471 peer_close_upcall(ep);
2472 disconnect = 1;
2473 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002474 break;
2475 case ABORTING:
2476 disconnect = 0;
2477 break;
2478 case CLOSING:
2479 __state_set(&ep->com, MORIBUND);
2480 disconnect = 0;
2481 break;
2482 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002483 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002484 if (ep->com.cm_id && ep->com.qp) {
2485 attrs.next_state = C4IW_QP_STATE_IDLE;
2486 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2487 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2488 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302489 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002490 __state_set(&ep->com, DEAD);
2491 release = 1;
2492 disconnect = 0;
2493 break;
2494 case DEAD:
2495 disconnect = 0;
2496 break;
2497 default:
2498 BUG_ON(1);
2499 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002500 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002501 if (disconnect)
2502 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2503 if (release)
2504 release_ep_resources(ep);
2505 return 0;
2506}
2507
Steve Wisecfdda9d2010-04-21 15:30:06 -07002508static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2509{
2510 struct cpl_abort_req_rss *req = cplhdr(skb);
2511 struct c4iw_ep *ep;
2512 struct cpl_abort_rpl *rpl;
2513 struct sk_buff *rpl_skb;
2514 struct c4iw_qp_attributes attrs;
2515 int ret;
2516 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002517 struct tid_info *t = dev->rdev.lldi.tids;
2518 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002519
2520 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302521 if (is_neg_adv(req->status)) {
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05302522 dev_warn(&dev->rdev.lldi.pdev->dev,
2523 "Negative advice on abort - tid %u status %d (%s)\n",
2524 ep->hwtid, req->status, neg_adv_str(req->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002525 return 0;
2526 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002527 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2528 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002529 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002530
2531 /*
2532 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302533 * However, this is not needed if com state is just
2534 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002535 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302536 if (ep->com.state != MPA_REQ_SENT)
2537 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002538
2539 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002540 switch (ep->com.state) {
2541 case CONNECTING:
2542 break;
2543 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002544 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002545 break;
2546 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002547 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002548 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302549 connect_reply_upcall(ep, -ECONNRESET);
2550 else {
2551 /*
2552 * we just don't send notification upwards because we
2553 * want to retry with mpa_v1 without upper layers even
2554 * knowing it.
2555 *
2556 * do some housekeeping so as to re-initiate the
2557 * connection
2558 */
2559 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2560 mpa_rev);
2561 ep->retry_with_mpa_v1 = 1;
2562 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002563 break;
2564 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002565 break;
2566 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002567 break;
2568 case MORIBUND:
2569 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002570 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002571 /*FALLTHROUGH*/
2572 case FPDU_MODE:
2573 if (ep->com.cm_id && ep->com.qp) {
2574 attrs.next_state = C4IW_QP_STATE_ERROR;
2575 ret = c4iw_modify_qp(ep->com.qp->rhp,
2576 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2577 &attrs, 1);
2578 if (ret)
2579 printk(KERN_ERR MOD
2580 "%s - qp <- error failed!\n",
2581 __func__);
2582 }
2583 peer_abort_upcall(ep);
2584 break;
2585 case ABORTING:
2586 break;
2587 case DEAD:
2588 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002589 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002590 return 0;
2591 default:
2592 BUG_ON(1);
2593 break;
2594 }
2595 dst_confirm(ep->dst);
2596 if (ep->com.state != ABORTING) {
2597 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302598 /* we don't release if we want to retry with mpa_v1 */
2599 if (!ep->retry_with_mpa_v1)
2600 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002601 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002602 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002603
2604 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2605 if (!rpl_skb) {
2606 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2607 __func__);
2608 release = 1;
2609 goto out;
2610 }
2611 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2612 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2613 INIT_TP_WR(rpl, ep->hwtid);
2614 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2615 rpl->cmd = CPL_ABORT_NO_RST;
2616 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2617out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002618 if (release)
2619 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002620 else if (ep->retry_with_mpa_v1) {
2621 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302622 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2623 dst_release(ep->dst);
2624 cxgb4_l2t_release(ep->l2t);
2625 c4iw_reconnect(ep);
2626 }
2627
Steve Wisecfdda9d2010-04-21 15:30:06 -07002628 return 0;
2629}
2630
2631static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2632{
2633 struct c4iw_ep *ep;
2634 struct c4iw_qp_attributes attrs;
2635 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002636 int release = 0;
2637 struct tid_info *t = dev->rdev.lldi.tids;
2638 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002639
2640 ep = lookup_tid(t, tid);
2641
2642 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2643 BUG_ON(!ep);
2644
2645 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002646 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002647 switch (ep->com.state) {
2648 case CLOSING:
2649 __state_set(&ep->com, MORIBUND);
2650 break;
2651 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002652 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002653 if ((ep->com.cm_id) && (ep->com.qp)) {
2654 attrs.next_state = C4IW_QP_STATE_IDLE;
2655 c4iw_modify_qp(ep->com.qp->rhp,
2656 ep->com.qp,
2657 C4IW_QP_ATTR_NEXT_STATE,
2658 &attrs, 1);
2659 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302660 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002661 __state_set(&ep->com, DEAD);
2662 release = 1;
2663 break;
2664 case ABORTING:
2665 case DEAD:
2666 break;
2667 default:
2668 BUG_ON(1);
2669 break;
2670 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002671 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002672 if (release)
2673 release_ep_resources(ep);
2674 return 0;
2675}
2676
2677static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2678{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002679 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002680 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002681 unsigned int tid = GET_TID(rpl);
2682 struct c4iw_ep *ep;
2683 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002684
2685 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002686 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002687
Steve Wise30c95c22011-05-09 22:06:22 -07002688 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002689 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2690 ep->com.qp->wq.sq.qid);
2691 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2692 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2693 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2694 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002695 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002696
Steve Wisecfdda9d2010-04-21 15:30:06 -07002697 return 0;
2698}
2699
2700/*
2701 * Upcall from the adapter indicating data has been transmitted.
2702 * For us its just the single MPA request or reply. We can now free
2703 * the skb holding the mpa message.
2704 */
2705static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2706{
2707 struct c4iw_ep *ep;
2708 struct cpl_fw4_ack *hdr = cplhdr(skb);
2709 u8 credits = hdr->credits;
2710 unsigned int tid = GET_TID(hdr);
2711 struct tid_info *t = dev->rdev.lldi.tids;
2712
2713
2714 ep = lookup_tid(t, tid);
2715 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2716 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002717 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2718 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002719 return 0;
2720 }
2721
2722 dst_confirm(ep->dst);
2723 if (ep->mpa_skb) {
2724 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2725 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2726 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2727 kfree_skb(ep->mpa_skb);
2728 ep->mpa_skb = NULL;
2729 }
2730 return 0;
2731}
2732
Steve Wisecfdda9d2010-04-21 15:30:06 -07002733int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2734{
Steve Wisea7db89e2014-03-21 20:40:35 +05302735 int err = 0;
2736 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002737 struct c4iw_ep *ep = to_ep(cm_id);
2738 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2739
Steve Wisea7db89e2014-03-21 20:40:35 +05302740 mutex_lock(&ep->com.mutex);
2741 if (ep->com.state == DEAD) {
2742 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002743 c4iw_put_ep(&ep->com);
2744 return -ECONNRESET;
2745 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002746 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302747 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002748 if (mpa_rev == 0)
2749 abort_connection(ep, NULL, GFP_KERNEL);
2750 else {
2751 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302752 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002753 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302754 mutex_unlock(&ep->com.mutex);
2755 if (disconnect)
2756 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002757 c4iw_put_ep(&ep->com);
2758 return 0;
2759}
2760
2761int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2762{
2763 int err;
2764 struct c4iw_qp_attributes attrs;
2765 enum c4iw_qp_attr_mask mask;
2766 struct c4iw_ep *ep = to_ep(cm_id);
2767 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2768 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2769
2770 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302771
2772 mutex_lock(&ep->com.mutex);
2773 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002774 err = -ECONNRESET;
2775 goto err;
2776 }
2777
Steve Wisea7db89e2014-03-21 20:40:35 +05302778 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002779 BUG_ON(!qp);
2780
Vipul Pandya793dad92012-12-10 09:30:56 +00002781 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302782 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2783 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002784 abort_connection(ep, NULL, GFP_KERNEL);
2785 err = -EINVAL;
2786 goto err;
2787 }
2788
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302789 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2790 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302791 if (RELAXED_IRD_NEGOTIATION) {
2792 ep->ord = ep->ird;
2793 } else {
2794 ep->ird = conn_param->ird;
2795 ep->ord = conn_param->ord;
2796 send_mpa_reject(ep, conn_param->private_data,
2797 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302798 abort_connection(ep, NULL, GFP_KERNEL);
2799 err = -ENOMEM;
2800 goto err;
2801 }
2802 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302803 if (conn_param->ird < ep->ord) {
2804 if (RELAXED_IRD_NEGOTIATION &&
2805 ep->ord <= h->rdev.lldi.max_ordird_qp) {
2806 conn_param->ird = ep->ord;
2807 } else {
2808 abort_connection(ep, NULL, GFP_KERNEL);
2809 err = -ENOMEM;
2810 goto err;
2811 }
2812 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302813 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002814 ep->ird = conn_param->ird;
2815 ep->ord = conn_param->ord;
2816
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302817 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302818 if (peer2peer && ep->ird == 0)
2819 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302820 } else {
2821 if (peer2peer &&
2822 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
2823 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ord == 0)
2824 ep->ird = 1;
2825 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002826
2827 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2828
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302829 cm_id->add_ref(cm_id);
2830 ep->com.cm_id = cm_id;
2831 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00002832 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302833
Steve Wisecfdda9d2010-04-21 15:30:06 -07002834 /* bind QP to EP and move to RTS */
2835 attrs.mpa_attr = ep->mpa_attr;
2836 attrs.max_ird = ep->ird;
2837 attrs.max_ord = ep->ord;
2838 attrs.llp_stream_handle = ep;
2839 attrs.next_state = C4IW_QP_STATE_RTS;
2840
2841 /* bind QP and TID with INIT_WR */
2842 mask = C4IW_QP_ATTR_NEXT_STATE |
2843 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2844 C4IW_QP_ATTR_MPA_ATTR |
2845 C4IW_QP_ATTR_MAX_IRD |
2846 C4IW_QP_ATTR_MAX_ORD;
2847
2848 err = c4iw_modify_qp(ep->com.qp->rhp,
2849 ep->com.qp, mask, &attrs, 1);
2850 if (err)
2851 goto err1;
2852 err = send_mpa_reply(ep, conn_param->private_data,
2853 conn_param->private_data_len);
2854 if (err)
2855 goto err1;
2856
Steve Wisea7db89e2014-03-21 20:40:35 +05302857 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002858 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05302859 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002860 c4iw_put_ep(&ep->com);
2861 return 0;
2862err1:
2863 ep->com.cm_id = NULL;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302864 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002865 cm_id->rem_ref(cm_id);
2866err:
Steve Wisea7db89e2014-03-21 20:40:35 +05302867 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002868 c4iw_put_ep(&ep->com);
2869 return err;
2870}
2871
Vipul Pandya830662f2013-07-04 16:10:47 +05302872static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2873{
2874 struct in_device *ind;
2875 int found = 0;
2876 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2877 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
2878
2879 ind = in_dev_get(dev->rdev.lldi.ports[0]);
2880 if (!ind)
2881 return -EADDRNOTAVAIL;
2882 for_primary_ifa(ind) {
2883 laddr->sin_addr.s_addr = ifa->ifa_address;
2884 raddr->sin_addr.s_addr = ifa->ifa_address;
2885 found = 1;
2886 break;
2887 }
2888 endfor_ifa(ind);
2889 in_dev_put(ind);
2890 return found ? 0 : -EADDRNOTAVAIL;
2891}
2892
2893static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
2894 unsigned char banned_flags)
2895{
2896 struct inet6_dev *idev;
2897 int err = -EADDRNOTAVAIL;
2898
2899 rcu_read_lock();
2900 idev = __in6_dev_get(dev);
2901 if (idev != NULL) {
2902 struct inet6_ifaddr *ifp;
2903
2904 read_lock_bh(&idev->lock);
2905 list_for_each_entry(ifp, &idev->addr_list, if_list) {
2906 if (ifp->scope == IFA_LINK &&
2907 !(ifp->flags & banned_flags)) {
2908 memcpy(addr, &ifp->addr, 16);
2909 err = 0;
2910 break;
2911 }
2912 }
2913 read_unlock_bh(&idev->lock);
2914 }
2915 rcu_read_unlock();
2916 return err;
2917}
2918
2919static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2920{
2921 struct in6_addr uninitialized_var(addr);
2922 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2923 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
2924
2925 if (get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
2926 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
2927 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
2928 return 0;
2929 }
2930 return -EADDRNOTAVAIL;
2931}
2932
Steve Wisecfdda9d2010-04-21 15:30:06 -07002933int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2934{
Steve Wisecfdda9d2010-04-21 15:30:06 -07002935 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2936 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00002937 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05002938 struct sockaddr_in *laddr;
2939 struct sockaddr_in *raddr;
2940 struct sockaddr_in6 *laddr6;
2941 struct sockaddr_in6 *raddr6;
2942 struct iwpm_dev_data pm_reg_msg;
2943 struct iwpm_sa_data pm_msg;
Vipul Pandya830662f2013-07-04 16:10:47 +05302944 __u8 *ra;
2945 int iptype;
Steve Wise9eccfe12014-03-26 17:08:09 -05002946 int iwpm_err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002947
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302948 if ((conn_param->ord > cur_max_read_depth(dev)) ||
2949 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002950 err = -EINVAL;
2951 goto out;
2952 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002953 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2954 if (!ep) {
2955 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2956 err = -ENOMEM;
2957 goto out;
2958 }
2959 init_timer(&ep->timer);
2960 ep->plen = conn_param->private_data_len;
2961 if (ep->plen)
2962 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2963 conn_param->private_data, ep->plen);
2964 ep->ird = conn_param->ird;
2965 ep->ord = conn_param->ord;
2966
2967 if (peer2peer && ep->ord == 0)
2968 ep->ord = 1;
2969
2970 cm_id->add_ref(cm_id);
2971 ep->com.dev = dev;
2972 ep->com.cm_id = cm_id;
2973 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05302974 if (!ep->com.qp) {
2975 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
2976 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05002977 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05302978 }
Vipul Pandya325abea2013-01-07 13:11:53 +00002979 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002980 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2981 ep->com.qp, cm_id);
2982
2983 /*
2984 * Allocate an active TID to initiate a TCP connection.
2985 */
2986 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2987 if (ep->atid == -1) {
2988 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2989 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05002990 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002991 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002992 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002993
Steve Wise9eccfe12014-03-26 17:08:09 -05002994 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2995 sizeof(ep->com.local_addr));
2996 memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
2997 sizeof(ep->com.remote_addr));
2998
2999 /* No port mapper available, go with the specified peer information */
3000 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3001 sizeof(ep->com.mapped_local_addr));
3002 memcpy(&ep->com.mapped_remote_addr, &cm_id->remote_addr,
3003 sizeof(ep->com.mapped_remote_addr));
3004
3005 c4iw_form_reg_msg(dev, &pm_reg_msg);
3006 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3007 if (iwpm_err) {
3008 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3009 __func__, iwpm_err);
3010 }
3011 if (iwpm_valid_pid() && !iwpm_err) {
3012 c4iw_form_pm_msg(ep, &pm_msg);
3013 iwpm_err = iwpm_add_and_query_mapping(&pm_msg, RDMA_NL_C4IW);
3014 if (iwpm_err)
3015 PDBG("%s: Port Mapper query fail (err = %d).\n",
3016 __func__, iwpm_err);
3017 else
3018 c4iw_record_pm_msg(ep, &pm_msg);
3019 }
3020 if (iwpm_create_mapinfo(&ep->com.local_addr,
3021 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3022 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
3023 err = -ENOMEM;
3024 goto fail1;
3025 }
3026 print_addr(&ep->com, __func__, "add_query/create_mapinfo");
3027 set_bit(RELEASE_MAPINFO, &ep->com.flags);
3028
3029 laddr = (struct sockaddr_in *)&ep->com.mapped_local_addr;
3030 raddr = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
3031 laddr6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
3032 raddr6 = (struct sockaddr_in6 *) &ep->com.mapped_remote_addr;
3033
Vipul Pandya830662f2013-07-04 16:10:47 +05303034 if (cm_id->remote_addr.ss_family == AF_INET) {
3035 iptype = 4;
3036 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003037
Vipul Pandya830662f2013-07-04 16:10:47 +05303038 /*
3039 * Handle loopback requests to INADDR_ANY.
3040 */
3041 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3042 err = pick_local_ipaddrs(dev, cm_id);
3043 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003044 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303045 }
3046
3047 /* find a route */
3048 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3049 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3050 ra, ntohs(raddr->sin_port));
3051 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3052 raddr->sin_addr.s_addr, laddr->sin_port,
3053 raddr->sin_port, 0);
3054 } else {
3055 iptype = 6;
3056 ra = (__u8 *)&raddr6->sin6_addr;
3057
3058 /*
3059 * Handle loopback requests to INADDR_ANY.
3060 */
3061 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3062 err = pick_local_ip6addrs(dev, cm_id);
3063 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003064 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303065 }
3066
3067 /* find a route */
3068 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3069 __func__, laddr6->sin6_addr.s6_addr,
3070 ntohs(laddr6->sin6_port),
3071 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3072 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3073 raddr6->sin6_addr.s6_addr,
3074 laddr6->sin6_port, raddr6->sin6_port, 0,
3075 raddr6->sin6_scope_id);
3076 }
3077 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003078 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3079 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003080 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003081 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003082
Vipul Pandya830662f2013-07-04 16:10:47 +05303083 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true);
David Miller3786cf12011-12-02 16:52:31 +00003084 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003085 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003086 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003087 }
3088
3089 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3090 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3091 ep->l2t->idx);
3092
3093 state_set(&ep->com, CONNECTING);
3094 ep->tos = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003095
3096 /* send connect request to rnic */
3097 err = send_connect(ep);
3098 if (!err)
3099 goto out;
3100
3101 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003102fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003103 dst_release(ep->dst);
3104fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003105 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003106 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003107fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003108 cm_id->rem_ref(cm_id);
3109 c4iw_put_ep(&ep->com);
3110out:
3111 return err;
3112}
3113
Vipul Pandya830662f2013-07-04 16:10:47 +05303114static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3115{
3116 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003117 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
3118 &ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303119
3120 c4iw_init_wr_wait(&ep->com.wr_wait);
3121 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3122 ep->stid, &sin6->sin6_addr,
3123 sin6->sin6_port,
3124 ep->com.dev->rdev.lldi.rxq_ids[0]);
3125 if (!err)
3126 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3127 &ep->com.wr_wait,
3128 0, 0, __func__);
3129 if (err)
3130 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3131 err, ep->stid,
3132 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
3133 return err;
3134}
3135
3136static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3137{
3138 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003139 struct sockaddr_in *sin = (struct sockaddr_in *)
3140 &ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303141
3142 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3143 do {
3144 err = cxgb4_create_server_filter(
3145 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3146 sin->sin_addr.s_addr, sin->sin_port, 0,
3147 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3148 if (err == -EBUSY) {
3149 set_current_state(TASK_UNINTERRUPTIBLE);
3150 schedule_timeout(usecs_to_jiffies(100));
3151 }
3152 } while (err == -EBUSY);
3153 } else {
3154 c4iw_init_wr_wait(&ep->com.wr_wait);
3155 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3156 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3157 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3158 if (!err)
3159 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3160 &ep->com.wr_wait,
3161 0, 0, __func__);
3162 }
3163 if (err)
3164 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3165 , err, ep->stid,
3166 &sin->sin_addr, ntohs(sin->sin_port));
3167 return err;
3168}
3169
Steve Wisecfdda9d2010-04-21 15:30:06 -07003170int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3171{
3172 int err = 0;
3173 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3174 struct c4iw_listen_ep *ep;
Steve Wise9eccfe12014-03-26 17:08:09 -05003175 struct iwpm_dev_data pm_reg_msg;
3176 struct iwpm_sa_data pm_msg;
3177 int iwpm_err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003178
Steve Wisecfdda9d2010-04-21 15:30:06 -07003179 might_sleep();
3180
3181 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3182 if (!ep) {
3183 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3184 err = -ENOMEM;
3185 goto fail1;
3186 }
3187 PDBG("%s ep %p\n", __func__, ep);
3188 cm_id->add_ref(cm_id);
3189 ep->com.cm_id = cm_id;
3190 ep->com.dev = dev;
3191 ep->backlog = backlog;
Steve Wise24d44a32013-07-04 16:10:44 +05303192 memcpy(&ep->com.local_addr, &cm_id->local_addr,
3193 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003194
3195 /*
3196 * Allocate a server TID.
3197 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303198 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3199 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303200 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
3201 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003202 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303203 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
3204 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003205
Steve Wisecfdda9d2010-04-21 15:30:06 -07003206 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003207 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003208 err = -ENOMEM;
3209 goto fail2;
3210 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003211 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003212
3213 /* No port mapper available, go with the specified info */
3214 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3215 sizeof(ep->com.mapped_local_addr));
3216
3217 c4iw_form_reg_msg(dev, &pm_reg_msg);
3218 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3219 if (iwpm_err) {
3220 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3221 __func__, iwpm_err);
3222 }
3223 if (iwpm_valid_pid() && !iwpm_err) {
3224 memcpy(&pm_msg.loc_addr, &ep->com.local_addr,
3225 sizeof(ep->com.local_addr));
3226 iwpm_err = iwpm_add_mapping(&pm_msg, RDMA_NL_C4IW);
3227 if (iwpm_err)
3228 PDBG("%s: Port Mapper query fail (err = %d).\n",
3229 __func__, iwpm_err);
3230 else
3231 memcpy(&ep->com.mapped_local_addr,
3232 &pm_msg.mapped_loc_addr,
3233 sizeof(ep->com.mapped_local_addr));
3234 }
3235 if (iwpm_create_mapinfo(&ep->com.local_addr,
3236 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3237 err = -ENOMEM;
3238 goto fail3;
3239 }
3240 print_addr(&ep->com, __func__, "add_mapping/create_mapinfo");
3241
3242 set_bit(RELEASE_MAPINFO, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003243 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303244 if (ep->com.local_addr.ss_family == AF_INET)
3245 err = create_server4(dev, ep);
3246 else
3247 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003248 if (!err) {
3249 cm_id->provider_data = ep;
3250 goto out;
3251 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003252
3253fail3:
Vipul Pandya830662f2013-07-04 16:10:47 +05303254 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3255 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003256fail2:
3257 cm_id->rem_ref(cm_id);
3258 c4iw_put_ep(&ep->com);
3259fail1:
3260out:
3261 return err;
3262}
3263
3264int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3265{
3266 int err;
3267 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3268
3269 PDBG("%s ep %p\n", __func__, ep);
3270
3271 might_sleep();
3272 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303273 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3274 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003275 err = cxgb4_remove_server_filter(
3276 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3277 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3278 } else {
3279 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303280 err = cxgb4_remove_server(
3281 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3282 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003283 if (err)
3284 goto done;
3285 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3286 0, 0, __func__);
3287 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003288 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303289 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3290 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003291done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003292 cm_id->rem_ref(cm_id);
3293 c4iw_put_ep(&ep->com);
3294 return err;
3295}
3296
3297int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3298{
3299 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003300 int close = 0;
3301 int fatal = 0;
3302 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003303
Steve Wise2f5b48c2010-09-10 11:15:36 -05003304 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003305
3306 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3307 states[ep->com.state], abrupt);
3308
3309 rdev = &ep->com.dev->rdev;
3310 if (c4iw_fatal_error(rdev)) {
3311 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303312 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003313 ep->com.state = DEAD;
3314 }
3315 switch (ep->com.state) {
3316 case MPA_REQ_WAIT:
3317 case MPA_REQ_SENT:
3318 case MPA_REQ_RCVD:
3319 case MPA_REP_SENT:
3320 case FPDU_MODE:
3321 close = 1;
3322 if (abrupt)
3323 ep->com.state = ABORTING;
3324 else {
3325 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003326 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003327 }
3328 set_bit(CLOSE_SENT, &ep->com.flags);
3329 break;
3330 case CLOSING:
3331 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3332 close = 1;
3333 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003334 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003335 ep->com.state = ABORTING;
3336 } else
3337 ep->com.state = MORIBUND;
3338 }
3339 break;
3340 case MORIBUND:
3341 case ABORTING:
3342 case DEAD:
3343 PDBG("%s ignoring disconnect ep %p state %u\n",
3344 __func__, ep, ep->com.state);
3345 break;
3346 default:
3347 BUG();
3348 break;
3349 }
3350
Steve Wisecfdda9d2010-04-21 15:30:06 -07003351 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003352 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003353 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303354 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003355 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003356 } else {
3357 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003358 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003359 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003360 if (ret)
3361 fatal = 1;
3362 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003363 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003364 if (fatal)
3365 release_ep_resources(ep);
3366 return ret;
3367}
3368
Vipul Pandya1cab7752012-12-10 09:30:55 +00003369static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3370 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3371{
3372 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003373 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003374
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003375 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3376 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003377 if (!ep)
3378 return;
3379
3380 switch (req->retval) {
3381 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003382 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3383 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3384 send_fw_act_open_req(ep, atid);
3385 return;
3386 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003387 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003388 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3389 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3390 send_fw_act_open_req(ep, atid);
3391 return;
3392 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003393 break;
3394 default:
3395 pr_info("%s unexpected ofld conn wr retval %d\n",
3396 __func__, req->retval);
3397 break;
3398 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003399 pr_err("active ofld_connect_wr failure %d atid %d\n",
3400 req->retval, atid);
3401 mutex_lock(&dev->rdev.stats.lock);
3402 dev->rdev.stats.act_ofld_conn_fails++;
3403 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003404 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003405 state_set(&ep->com, DEAD);
3406 remove_handle(dev, &dev->atid_idr, atid);
3407 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3408 dst_release(ep->dst);
3409 cxgb4_l2t_release(ep->l2t);
3410 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003411}
3412
3413static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3414 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3415{
3416 struct sk_buff *rpl_skb;
3417 struct cpl_pass_accept_req *cpl;
3418 int ret;
3419
Paul Bolle710a3112013-02-05 20:51:30 +00003420 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003421 BUG_ON(!rpl_skb);
3422 if (req->retval) {
3423 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003424 mutex_lock(&dev->rdev.stats.lock);
3425 dev->rdev.stats.pas_ofld_conn_fails++;
3426 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003427 kfree_skb(rpl_skb);
3428 } else {
3429 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3430 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003431 (__force u32) htonl(
3432 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003433 ret = pass_accept_req(dev, rpl_skb);
3434 if (!ret)
3435 kfree_skb(rpl_skb);
3436 }
3437 return;
3438}
3439
3440static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003441{
3442 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003443 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3444
3445 switch (rpl->type) {
3446 case FW6_TYPE_CQE:
3447 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3448 break;
3449 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3450 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3451 switch (req->t_state) {
3452 case TCP_SYN_SENT:
3453 active_ofld_conn_reply(dev, skb, req);
3454 break;
3455 case TCP_SYN_RECV:
3456 passive_ofld_conn_reply(dev, skb, req);
3457 break;
3458 default:
3459 pr_err("%s unexpected ofld conn wr state %d\n",
3460 __func__, req->t_state);
3461 break;
3462 }
3463 break;
3464 }
3465 return 0;
3466}
3467
3468static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3469{
3470 u32 l2info;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003471 u16 vlantag, len, hdr_len, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003472 u8 intf;
3473 struct cpl_rx_pkt *cpl = cplhdr(skb);
3474 struct cpl_pass_accept_req *req;
3475 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003476 struct c4iw_dev *dev;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003477
Vipul Pandyaf079af72013-03-14 05:08:58 +00003478 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003479 /* Store values from cpl_rx_pkt in temporary location. */
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003480 vlantag = (__force u16) cpl->vlan;
3481 len = (__force u16) cpl->len;
3482 l2info = (__force u32) cpl->l2info;
3483 hdr_len = (__force u16) cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003484 intf = cpl->iff;
3485
3486 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3487
3488 /*
3489 * We need to parse the TCP options from SYN packet.
3490 * to generate cpl_pass_accept_req.
3491 */
3492 memset(&tmp_opt, 0, sizeof(tmp_opt));
3493 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003494 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003495
3496 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3497 memset(req, 0, sizeof(*req));
3498 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003499 V_SYN_MAC_IDX(G_RX_MACIDX(
3500 (__force int) htonl(l2info))) |
Vipul Pandya1cab7752012-12-10 09:30:55 +00003501 F_SYN_XACT_MATCH);
Vipul Pandyaf079af72013-03-14 05:08:58 +00003502 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3503 G_RX_ETHHDR_LEN((__force int) htonl(l2info)) :
3504 G_RX_T5_ETHHDR_LEN((__force int) htonl(l2info));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003505 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(
3506 (__force int) htonl(l2info))) |
3507 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(
3508 (__force int) htons(hdr_len))) |
3509 V_IP_HDR_LEN(G_RX_IPHDR_LEN(
3510 (__force int) htons(hdr_len))) |
Vipul Pandyaf079af72013-03-14 05:08:58 +00003511 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(eth_hdr_len)));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003512 req->vlan = (__force __be16) vlantag;
3513 req->len = (__force __be16) len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003514 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
3515 PASS_OPEN_TOS(tos));
3516 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3517 if (tmp_opt.wscale_ok)
3518 req->tcpopt.wsf = tmp_opt.snd_wscale;
3519 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3520 if (tmp_opt.sack_ok)
3521 req->tcpopt.sack = 1;
3522 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3523 return;
3524}
3525
3526static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3527 __be32 laddr, __be16 lport,
3528 __be32 raddr, __be16 rport,
3529 u32 rcv_isn, u32 filter, u16 window,
3530 u32 rss_qid, u8 port_id)
3531{
3532 struct sk_buff *req_skb;
3533 struct fw_ofld_connection_wr *req;
3534 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303535 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003536
3537 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3538 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3539 memset(req, 0, sizeof(*req));
3540 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
3541 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
3542 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003543 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003544 req->le.lport = lport;
3545 req->le.pport = rport;
3546 req->le.u.ipv4.lip = laddr;
3547 req->le.u.ipv4.pip = raddr;
3548 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3549 req->tcb.rcv_adv = htons(window);
3550 req->tcb.t_state_to_astid =
3551 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
3552 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
3553 V_FW_OFLD_CONNECTION_WR_ASTID(
3554 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
3555
3556 /*
3557 * We store the qid in opt2 which will be used by the firmware
3558 * to send us the wr response.
3559 */
3560 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
3561
3562 /*
3563 * We initialize the MSS index in TCB to 0xF.
3564 * So that when driver sends cpl_pass_accept_rpl
3565 * TCB picks up the correct value. If this was 0
3566 * TP will ignore any value > 0 for MSS index.
3567 */
3568 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
Paul Bolle710a3112013-02-05 20:51:30 +00003569 req->cookie = (unsigned long)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003570
3571 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303572 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3573 if (ret < 0) {
3574 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3575 ret);
3576 kfree_skb(skb);
3577 kfree_skb(req_skb);
3578 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003579}
3580
3581/*
3582 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3583 * messages when a filter is being used instead of server to
3584 * redirect a syn packet. When packets hit filter they are redirected
3585 * to the offload queue and driver tries to establish the connection
3586 * using firmware work request.
3587 */
3588static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3589{
3590 int stid;
3591 unsigned int filter;
3592 struct ethhdr *eh = NULL;
3593 struct vlan_ethhdr *vlan_eh = NULL;
3594 struct iphdr *iph;
3595 struct tcphdr *tcph;
3596 struct rss_header *rss = (void *)skb->data;
3597 struct cpl_rx_pkt *cpl = (void *)skb->data;
3598 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3599 struct l2t_entry *e;
3600 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003601 struct c4iw_ep *lep;
3602 u16 window;
3603 struct port_info *pi;
3604 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003605 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003606 int step;
3607 u32 tx_chan;
3608 struct neighbour *neigh;
3609
3610 /* Drop all non-SYN packets */
3611 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
3612 goto reject;
3613
3614 /*
3615 * Drop all packets which did not hit the filter.
3616 * Unlikely to happen.
3617 */
3618 if (!(rss->filter_hit && rss->filter_tid))
3619 goto reject;
3620
3621 /*
3622 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3623 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303624 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003625
3626 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3627 if (!lep) {
3628 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3629 goto reject;
3630 }
3631
Vipul Pandyaf079af72013-03-14 05:08:58 +00003632 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3633 G_RX_ETHHDR_LEN(htonl(cpl->l2info)) :
3634 G_RX_T5_ETHHDR_LEN(htonl(cpl->l2info));
3635 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003636 eh = (struct ethhdr *)(req + 1);
3637 iph = (struct iphdr *)(eh + 1);
3638 } else {
3639 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3640 iph = (struct iphdr *)(vlan_eh + 1);
3641 skb->vlan_tci = ntohs(cpl->vlan);
3642 }
3643
3644 if (iph->version != 0x4)
3645 goto reject;
3646
3647 tcph = (struct tcphdr *)(iph + 1);
3648 skb_set_network_header(skb, (void *)iph - (void *)rss);
3649 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3650 skb_get(skb);
3651
3652 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3653 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3654 ntohs(tcph->source), iph->tos);
3655
Vipul Pandya830662f2013-07-04 16:10:47 +05303656 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3657 iph->tos);
3658 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003659 pr_err("%s - failed to find dst entry!\n",
3660 __func__);
3661 goto reject;
3662 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003663 neigh = dst_neigh_lookup_skb(dst, skb);
3664
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003665 if (!neigh) {
3666 pr_err("%s - failed to allocate neigh!\n",
3667 __func__);
3668 goto free_dst;
3669 }
3670
Vipul Pandya1cab7752012-12-10 09:30:55 +00003671 if (neigh->dev->flags & IFF_LOOPBACK) {
3672 pdev = ip_dev_find(&init_net, iph->daddr);
3673 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3674 pdev, 0);
3675 pi = (struct port_info *)netdev_priv(pdev);
3676 tx_chan = cxgb4_port_chan(pdev);
3677 dev_put(pdev);
3678 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303679 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003680 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303681 pdev, 0);
3682 pi = (struct port_info *)netdev_priv(pdev);
3683 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003684 }
Steve Wiseebf00062014-03-19 17:44:40 +05303685 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003686 if (!e) {
3687 pr_err("%s - failed to allocate l2t entry!\n",
3688 __func__);
3689 goto free_dst;
3690 }
3691
3692 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3693 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003694 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003695
3696 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303697 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3698 dev->rdev.lldi.ports[0],
3699 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003700
3701 /*
3702 * Synthesize the cpl_pass_accept_req. We have everything except the
3703 * TID. Once firmware sends a reply with TID we update the TID field
3704 * in cpl and pass it through the regular cpl_pass_accept_req path.
3705 */
3706 build_cpl_pass_accept_req(skb, stid, iph->tos);
3707 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3708 tcph->source, ntohl(tcph->seq), filter, window,
3709 rss_qid, pi->port_id);
3710 cxgb4_l2t_release(e);
3711free_dst:
3712 dst_release(dst);
3713reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003714 return 0;
3715}
3716
Steve Wisecfdda9d2010-04-21 15:30:06 -07003717/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003718 * These are the real handlers that are called from a
3719 * work queue.
3720 */
3721static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3722 [CPL_ACT_ESTABLISH] = act_establish,
3723 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3724 [CPL_RX_DATA] = rx_data,
3725 [CPL_ABORT_RPL_RSS] = abort_rpl,
3726 [CPL_ABORT_RPL] = abort_rpl,
3727 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3728 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3729 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3730 [CPL_PASS_ESTABLISH] = pass_establish,
3731 [CPL_PEER_CLOSE] = peer_close,
3732 [CPL_ABORT_REQ_RSS] = peer_abort,
3733 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3734 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003735 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003736 [CPL_FW6_MSG] = deferred_fw6_msg,
3737 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003738};
3739
3740static void process_timeout(struct c4iw_ep *ep)
3741{
3742 struct c4iw_qp_attributes attrs;
3743 int abort = 1;
3744
Steve Wise2f5b48c2010-09-10 11:15:36 -05003745 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003746 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3747 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003748 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003749 switch (ep->com.state) {
3750 case MPA_REQ_SENT:
3751 __state_set(&ep->com, ABORTING);
3752 connect_reply_upcall(ep, -ETIMEDOUT);
3753 break;
3754 case MPA_REQ_WAIT:
3755 __state_set(&ep->com, ABORTING);
3756 break;
3757 case CLOSING:
3758 case MORIBUND:
3759 if (ep->com.cm_id && ep->com.qp) {
3760 attrs.next_state = C4IW_QP_STATE_ERROR;
3761 c4iw_modify_qp(ep->com.qp->rhp,
3762 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3763 &attrs, 1);
3764 }
3765 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303766 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003767 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003768 case ABORTING:
3769 case DEAD:
3770
3771 /*
3772 * These states are expected if the ep timed out at the same
3773 * time as another thread was calling stop_ep_timer().
3774 * So we silently do nothing for these states.
3775 */
3776 abort = 0;
3777 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003778 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003779 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003780 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003781 abort = 0;
3782 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003783 if (abort)
3784 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecc18b932014-04-24 14:31:53 -05003785 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003786 c4iw_put_ep(&ep->com);
3787}
3788
3789static void process_timedout_eps(void)
3790{
3791 struct c4iw_ep *ep;
3792
3793 spin_lock_irq(&timeout_lock);
3794 while (!list_empty(&timeout_list)) {
3795 struct list_head *tmp;
3796
3797 tmp = timeout_list.next;
3798 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003799 tmp->next = NULL;
3800 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003801 spin_unlock_irq(&timeout_lock);
3802 ep = list_entry(tmp, struct c4iw_ep, entry);
3803 process_timeout(ep);
3804 spin_lock_irq(&timeout_lock);
3805 }
3806 spin_unlock_irq(&timeout_lock);
3807}
3808
3809static void process_work(struct work_struct *work)
3810{
3811 struct sk_buff *skb = NULL;
3812 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003813 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003814 unsigned int opcode;
3815 int ret;
3816
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003817 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003818 while ((skb = skb_dequeue(&rxq))) {
3819 rpl = cplhdr(skb);
3820 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3821 opcode = rpl->ot.opcode;
3822
3823 BUG_ON(!work_handlers[opcode]);
3824 ret = work_handlers[opcode](dev, skb);
3825 if (!ret)
3826 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003827 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003828 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003829}
3830
3831static DECLARE_WORK(skb_work, process_work);
3832
3833static void ep_timeout(unsigned long arg)
3834{
3835 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003836 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003837
3838 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003839 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003840 /*
3841 * Only insert if it is not already on the list.
3842 */
3843 if (!ep->entry.next) {
3844 list_add_tail(&ep->entry, &timeout_list);
3845 kickit = 1;
3846 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003847 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003848 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003849 if (kickit)
3850 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003851}
3852
3853/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07003854 * All the CM events are handled on a work queue to have a safe context.
3855 */
3856static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3857{
3858
3859 /*
3860 * Save dev in the skb->cb area.
3861 */
3862 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3863
3864 /*
3865 * Queue the skb and schedule the worker thread.
3866 */
3867 skb_queue_tail(&rxq, skb);
3868 queue_work(workq, &skb_work);
3869 return 0;
3870}
3871
3872static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3873{
3874 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3875
3876 if (rpl->status != CPL_ERR_NONE) {
3877 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3878 "for tid %u\n", rpl->status, GET_TID(rpl));
3879 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003880 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003881 return 0;
3882}
3883
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003884static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3885{
3886 struct cpl_fw6_msg *rpl = cplhdr(skb);
3887 struct c4iw_wr_wait *wr_waitp;
3888 int ret;
3889
3890 PDBG("%s type %u\n", __func__, rpl->type);
3891
3892 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003893 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003894 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07003895 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003896 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07003897 if (wr_waitp)
3898 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003899 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003900 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003901 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003902 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00003903 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003904 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003905 default:
3906 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3907 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003908 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003909 break;
3910 }
3911 return 0;
3912}
3913
Steve Wise8da7e7a2011-06-14 20:59:27 +00003914static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3915{
3916 struct cpl_abort_req_rss *req = cplhdr(skb);
3917 struct c4iw_ep *ep;
3918 struct tid_info *t = dev->rdev.lldi.tids;
3919 unsigned int tid = GET_TID(req);
3920
3921 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05003922 if (!ep) {
3923 printk(KERN_WARNING MOD
3924 "Abort on non-existent endpoint, tid %d\n", tid);
3925 kfree_skb(skb);
3926 return 0;
3927 }
Steve Wise7a2cea22014-03-14 21:52:07 +05303928 if (is_neg_adv(req->status)) {
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05303929 dev_warn(&dev->rdev.lldi.pdev->dev,
3930 "Negative advice on abort - tid %u status %d (%s)\n",
3931 ep->hwtid, req->status, neg_adv_str(req->status));
Steve Wise8da7e7a2011-06-14 20:59:27 +00003932 kfree_skb(skb);
3933 return 0;
3934 }
3935 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3936 ep->com.state);
3937
3938 /*
3939 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003940 * However, if we are on MPAv2 and want to retry with MPAv1
3941 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00003942 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003943 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
3944 if (ep->com.state != MPA_REQ_SENT)
3945 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3946 } else
3947 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003948 sched(dev, skb);
3949 return 0;
3950}
3951
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003952/*
3953 * Most upcalls from the T4 Core go to sched() to
3954 * schedule the processing on a work queue.
3955 */
3956c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3957 [CPL_ACT_ESTABLISH] = sched,
3958 [CPL_ACT_OPEN_RPL] = sched,
3959 [CPL_RX_DATA] = sched,
3960 [CPL_ABORT_RPL_RSS] = sched,
3961 [CPL_ABORT_RPL] = sched,
3962 [CPL_PASS_OPEN_RPL] = sched,
3963 [CPL_CLOSE_LISTSRV_RPL] = sched,
3964 [CPL_PASS_ACCEPT_REQ] = sched,
3965 [CPL_PASS_ESTABLISH] = sched,
3966 [CPL_PEER_CLOSE] = sched,
3967 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00003968 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003969 [CPL_RDMA_TERMINATE] = sched,
3970 [CPL_FW4_ACK] = sched,
3971 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003972 [CPL_FW6_MSG] = fw6_msg,
3973 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003974};
3975
Steve Wisecfdda9d2010-04-21 15:30:06 -07003976int __init c4iw_cm_init(void)
3977{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003978 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003979 skb_queue_head_init(&rxq);
3980
3981 workq = create_singlethread_workqueue("iw_cxgb4");
3982 if (!workq)
3983 return -ENOMEM;
3984
Steve Wisecfdda9d2010-04-21 15:30:06 -07003985 return 0;
3986}
3987
Steve Wise46c13762014-06-20 14:26:25 -05003988void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07003989{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003990 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003991 flush_workqueue(workq);
3992 destroy_workqueue(workq);
3993}