blob: df5bd3df08a2a114d49d123789d6acc02204b40a [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)] -
239 sizeof(struct iphdr) - sizeof(struct tcphdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700240 ep->mss = ep->emss;
241 if (GET_TCPOPT_TSTAMP(opt))
242 ep->emss -= 12;
243 if (ep->emss < 128)
244 ep->emss = 128;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530245 if (ep->emss & 7)
246 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
247 GET_TCPOPT_MSS(opt), ep->mss, ep->emss);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700248 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
249 ep->mss, ep->emss);
250}
251
252static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
253{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700254 enum c4iw_ep_state state;
255
Steve Wise2f5b48c2010-09-10 11:15:36 -0500256 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700257 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500258 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700259 return state;
260}
261
262static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
263{
264 epc->state = new;
265}
266
267static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
268{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500269 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700270 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
271 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500272 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700273 return;
274}
275
276static void *alloc_ep(int size, gfp_t gfp)
277{
278 struct c4iw_ep_common *epc;
279
280 epc = kzalloc(size, gfp);
281 if (epc) {
282 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500283 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500284 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700285 }
286 PDBG("%s alloc ep %p\n", __func__, epc);
287 return epc;
288}
289
290void _c4iw_free_ep(struct kref *kref)
291{
292 struct c4iw_ep *ep;
293
294 ep = container_of(kref, struct c4iw_ep, com.kref);
295 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000296 if (test_bit(QP_REFERENCED, &ep->com.flags))
297 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700298 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000299 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700300 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
301 dst_release(ep->dst);
302 cxgb4_l2t_release(ep->l2t);
303 }
Steve Wise9eccfe12014-03-26 17:08:09 -0500304 if (test_bit(RELEASE_MAPINFO, &ep->com.flags)) {
305 print_addr(&ep->com, __func__, "remove_mapinfo/mapping");
306 iwpm_remove_mapinfo(&ep->com.local_addr,
307 &ep->com.mapped_local_addr);
308 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
309 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700310 kfree(ep);
311}
312
313static void release_ep_resources(struct c4iw_ep *ep)
314{
315 set_bit(RELEASE_RESOURCES, &ep->com.flags);
316 c4iw_put_ep(&ep->com);
317}
318
Steve Wisecfdda9d2010-04-21 15:30:06 -0700319static int status2errno(int status)
320{
321 switch (status) {
322 case CPL_ERR_NONE:
323 return 0;
324 case CPL_ERR_CONN_RESET:
325 return -ECONNRESET;
326 case CPL_ERR_ARP_MISS:
327 return -EHOSTUNREACH;
328 case CPL_ERR_CONN_TIMEDOUT:
329 return -ETIMEDOUT;
330 case CPL_ERR_TCAM_FULL:
331 return -ENOMEM;
332 case CPL_ERR_CONN_EXIST:
333 return -EADDRINUSE;
334 default:
335 return -EIO;
336 }
337}
338
339/*
340 * Try and reuse skbs already allocated...
341 */
342static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
343{
344 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
345 skb_trim(skb, 0);
346 skb_get(skb);
347 skb_reset_transport_header(skb);
348 } else {
349 skb = alloc_skb(len, gfp);
350 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530351 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700352 return skb;
353}
354
Vipul Pandya830662f2013-07-04 16:10:47 +0530355static struct net_device *get_real_dev(struct net_device *egress_dev)
356{
Steve Wise11b8e222014-05-16 12:42:46 -0500357 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530358}
359
360static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
361{
362 int i;
363
364 egress_dev = get_real_dev(egress_dev);
365 for (i = 0; i < dev->rdev.lldi.nports; i++)
366 if (dev->rdev.lldi.ports[i] == egress_dev)
367 return 1;
368 return 0;
369}
370
371static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
372 __u8 *peer_ip, __be16 local_port,
373 __be16 peer_port, u8 tos,
374 __u32 sin6_scope_id)
375{
376 struct dst_entry *dst = NULL;
377
378 if (IS_ENABLED(CONFIG_IPV6)) {
379 struct flowi6 fl6;
380
381 memset(&fl6, 0, sizeof(fl6));
382 memcpy(&fl6.daddr, peer_ip, 16);
383 memcpy(&fl6.saddr, local_ip, 16);
384 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
385 fl6.flowi6_oif = sin6_scope_id;
386 dst = ip6_route_output(&init_net, NULL, &fl6);
387 if (!dst)
388 goto out;
389 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
390 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
391 dst_release(dst);
392 dst = NULL;
393 }
394 }
395
396out:
397 return dst;
398}
399
400static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700401 __be32 peer_ip, __be16 local_port,
402 __be16 peer_port, u8 tos)
403{
404 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700405 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530406 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700407
David S. Miller31e4543d2011-05-03 20:25:42 -0700408 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500409 peer_port, local_port, IPPROTO_TCP,
410 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800411 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700412 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530413 n = dst_neigh_lookup(&rt->dst, &peer_ip);
414 if (!n)
415 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530416 if (!our_interface(dev, n->dev) &&
417 !(n->dev->flags & IFF_LOOPBACK)) {
Vipul Pandya830662f2013-07-04 16:10:47 +0530418 dst_release(&rt->dst);
419 return NULL;
420 }
421 neigh_release(n);
422 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700423}
424
425static void arp_failure_discard(void *handle, struct sk_buff *skb)
426{
427 PDBG("%s c4iw_dev %p\n", __func__, handle);
428 kfree_skb(skb);
429}
430
431/*
432 * Handle an ARP failure for an active open.
433 */
434static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
435{
436 printk(KERN_ERR MOD "ARP failure duing connect\n");
437 kfree_skb(skb);
438}
439
440/*
441 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
442 * and send it along.
443 */
444static void abort_arp_failure(void *handle, struct sk_buff *skb)
445{
446 struct c4iw_rdev *rdev = handle;
447 struct cpl_abort_req *req = cplhdr(skb);
448
449 PDBG("%s rdev %p\n", __func__, rdev);
450 req->cmd = CPL_ABORT_NO_RST;
451 c4iw_ofld_send(rdev, skb);
452}
453
454static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
455{
456 unsigned int flowclen = 80;
457 struct fw_flowc_wr *flowc;
458 int i;
459
460 skb = get_skb(skb, flowclen, GFP_KERNEL);
461 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
462
463 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
464 FW_FLOWC_WR_NPARAMS(8));
465 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
466 16)) | FW_WR_FLOWID(ep->hwtid));
467
468 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530469 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN
470 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700471 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
472 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
473 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
474 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
475 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
476 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
477 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
478 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
479 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
480 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
481 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530482 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700483 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
484 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
485 /* Pad WR to 16 byte boundary */
486 flowc->mnemval[8].mnemonic = 0;
487 flowc->mnemval[8].val = 0;
488 for (i = 0; i < 9; i++) {
489 flowc->mnemval[i].r4[0] = 0;
490 flowc->mnemval[i].r4[1] = 0;
491 flowc->mnemval[i].r4[2] = 0;
492 }
493
494 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
495 c4iw_ofld_send(&ep->com.dev->rdev, skb);
496}
497
498static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
499{
500 struct cpl_close_con_req *req;
501 struct sk_buff *skb;
502 int wrlen = roundup(sizeof *req, 16);
503
504 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
505 skb = get_skb(NULL, wrlen, gfp);
506 if (!skb) {
507 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
508 return -ENOMEM;
509 }
510 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
511 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
512 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
513 memset(req, 0, wrlen);
514 INIT_TP_WR(req, ep->hwtid);
515 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
516 ep->hwtid));
517 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
518}
519
520static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
521{
522 struct cpl_abort_req *req;
523 int wrlen = roundup(sizeof *req, 16);
524
525 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
526 skb = get_skb(skb, wrlen, gfp);
527 if (!skb) {
528 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
529 __func__);
530 return -ENOMEM;
531 }
532 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
533 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
534 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
535 memset(req, 0, wrlen);
536 INIT_TP_WR(req, ep->hwtid);
537 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
538 req->cmd = CPL_ABORT_SEND_RST;
539 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
540}
541
Steve Wise9eccfe12014-03-26 17:08:09 -0500542/*
543 * c4iw_form_pm_msg - Form a port mapper message with mapping info
544 */
545static void c4iw_form_pm_msg(struct c4iw_ep *ep,
546 struct iwpm_sa_data *pm_msg)
547{
548 memcpy(&pm_msg->loc_addr, &ep->com.local_addr,
549 sizeof(ep->com.local_addr));
550 memcpy(&pm_msg->rem_addr, &ep->com.remote_addr,
551 sizeof(ep->com.remote_addr));
552}
553
554/*
555 * c4iw_form_reg_msg - Form a port mapper message with dev info
556 */
557static void c4iw_form_reg_msg(struct c4iw_dev *dev,
558 struct iwpm_dev_data *pm_msg)
559{
560 memcpy(pm_msg->dev_name, dev->ibdev.name, IWPM_DEVNAME_SIZE);
561 memcpy(pm_msg->if_name, dev->rdev.lldi.ports[0]->name,
562 IWPM_IFNAME_SIZE);
563}
564
565static void c4iw_record_pm_msg(struct c4iw_ep *ep,
566 struct iwpm_sa_data *pm_msg)
567{
568 memcpy(&ep->com.mapped_local_addr, &pm_msg->mapped_loc_addr,
569 sizeof(ep->com.mapped_local_addr));
570 memcpy(&ep->com.mapped_remote_addr, &pm_msg->mapped_rem_addr,
571 sizeof(ep->com.mapped_remote_addr));
572}
573
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530574static void best_mtu(const unsigned short *mtus, unsigned short mtu,
575 unsigned int *idx, int use_ts)
576{
577 unsigned short hdr_size = sizeof(struct iphdr) +
578 sizeof(struct tcphdr) +
579 (use_ts ? 12 : 0);
580 unsigned short data_size = mtu - hdr_size;
581
582 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
583}
584
Steve Wisecfdda9d2010-04-21 15:30:06 -0700585static int send_connect(struct c4iw_ep *ep)
586{
587 struct cpl_act_open_req *req;
Vipul Pandyaf079af72013-03-14 05:08:58 +0000588 struct cpl_t5_act_open_req *t5_req;
Vipul Pandya830662f2013-07-04 16:10:47 +0530589 struct cpl_act_open_req6 *req6;
590 struct cpl_t5_act_open_req6 *t5_req6;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700591 struct sk_buff *skb;
592 u64 opt0;
593 u32 opt2;
594 unsigned int mtu_idx;
595 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +0530596 int wrlen;
597 int sizev4 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
598 sizeof(struct cpl_act_open_req) :
599 sizeof(struct cpl_t5_act_open_req);
600 int sizev6 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
601 sizeof(struct cpl_act_open_req6) :
602 sizeof(struct cpl_t5_act_open_req6);
Steve Wise9eccfe12014-03-26 17:08:09 -0500603 struct sockaddr_in *la = (struct sockaddr_in *)
604 &ep->com.mapped_local_addr;
605 struct sockaddr_in *ra = (struct sockaddr_in *)
606 &ep->com.mapped_remote_addr;
607 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
608 &ep->com.mapped_local_addr;
609 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
610 &ep->com.mapped_remote_addr;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530611 int win;
Vipul Pandya830662f2013-07-04 16:10:47 +0530612
613 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
614 roundup(sizev4, 16) :
615 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700616
617 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
618
619 skb = get_skb(NULL, wrlen, GFP_KERNEL);
620 if (!skb) {
621 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
622 __func__);
623 return -ENOMEM;
624 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000625 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700626
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530627 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
628 enable_tcp_timestamps);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700629 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530630
631 /*
632 * Specify the largest window that will fit in opt0. The
633 * remainder will be specified in the rx_data_ack.
634 */
635 win = ep->rcv_win >> 10;
636 if (win > RCV_BUFSIZ_MASK)
637 win = RCV_BUFSIZ_MASK;
638
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000639 opt0 = (nocong ? NO_CONG(1) : 0) |
640 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +0000641 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700642 WND_SCALE(wscale) |
643 MSS_IDX(mtu_idx) |
644 L2T_IDX(ep->l2t->idx) |
645 TX_CHAN(ep->tx_chan) |
646 SMAC_SEL(ep->smac_idx) |
647 DSCP(ep->tos) |
Steve Wiseb48f3b92011-03-11 22:30:21 +0000648 ULP_MODE(ULP_MODE_TCPDDP) |
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530649 RCV_BUFSIZ(win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700650 opt2 = RX_CHANNEL(0) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000651 CCTRL_ECN(enable_ecn) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700652 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
653 if (enable_tcp_timestamps)
654 opt2 |= TSTAMPS_EN(1);
655 if (enable_tcp_sack)
656 opt2 |= SACK_EN(1);
657 if (wscale && enable_tcp_window_scaling)
658 opt2 |= WND_SCALE_EN(1);
Steve Wise92e50112014-04-24 14:31:59 -0500659 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
660 opt2 |= T5_OPT_2_VALID;
661 opt2 |= V_CONG_CNTRL(CONG_ALG_TAHOE);
662 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700663 t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
664
Vipul Pandyaf079af72013-03-14 05:08:58 +0000665 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Vipul Pandya830662f2013-07-04 16:10:47 +0530666 if (ep->com.remote_addr.ss_family == AF_INET) {
667 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
668 INIT_TP_WR(req, 0);
669 OPCODE_TID(req) = cpu_to_be32(
Vipul Pandyaf079af72013-03-14 05:08:58 +0000670 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
671 ((ep->rss_qid << 14) | ep->atid)));
Vipul Pandya830662f2013-07-04 16:10:47 +0530672 req->local_port = la->sin_port;
673 req->peer_port = ra->sin_port;
674 req->local_ip = la->sin_addr.s_addr;
675 req->peer_ip = ra->sin_addr.s_addr;
676 req->opt0 = cpu_to_be64(opt0);
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530677 req->params = cpu_to_be32(cxgb4_select_ntuple(
678 ep->com.dev->rdev.lldi.ports[0],
679 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530680 req->opt2 = cpu_to_be32(opt2);
681 } else {
682 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
683
684 INIT_TP_WR(req6, 0);
685 OPCODE_TID(req6) = cpu_to_be32(
686 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
687 ((ep->rss_qid<<14)|ep->atid)));
688 req6->local_port = la6->sin6_port;
689 req6->peer_port = ra6->sin6_port;
690 req6->local_ip_hi = *((__be64 *)
691 (la6->sin6_addr.s6_addr));
692 req6->local_ip_lo = *((__be64 *)
693 (la6->sin6_addr.s6_addr + 8));
694 req6->peer_ip_hi = *((__be64 *)
695 (ra6->sin6_addr.s6_addr));
696 req6->peer_ip_lo = *((__be64 *)
697 (ra6->sin6_addr.s6_addr + 8));
698 req6->opt0 = cpu_to_be64(opt0);
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530699 req6->params = cpu_to_be32(cxgb4_select_ntuple(
700 ep->com.dev->rdev.lldi.ports[0],
701 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530702 req6->opt2 = cpu_to_be32(opt2);
703 }
704 } else {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530705 u32 isn = (prandom_u32() & ~7UL) - 1;
706
707 opt2 |= T5_OPT_2_VALID;
708 opt2 |= CONG_CNTRL_VALID; /* OPT_2_ISS for T5 */
709 if (peer2peer)
710 isn += 4;
711
Vipul Pandya830662f2013-07-04 16:10:47 +0530712 if (ep->com.remote_addr.ss_family == AF_INET) {
713 t5_req = (struct cpl_t5_act_open_req *)
714 skb_put(skb, wrlen);
715 INIT_TP_WR(t5_req, 0);
716 OPCODE_TID(t5_req) = cpu_to_be32(
717 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
718 ((ep->rss_qid << 14) | ep->atid)));
719 t5_req->local_port = la->sin_port;
720 t5_req->peer_port = ra->sin_port;
721 t5_req->local_ip = la->sin_addr.s_addr;
722 t5_req->peer_ip = ra->sin_addr.s_addr;
723 t5_req->opt0 = cpu_to_be64(opt0);
724 t5_req->params = cpu_to_be64(V_FILTER_TUPLE(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530725 cxgb4_select_ntuple(
726 ep->com.dev->rdev.lldi.ports[0],
727 ep->l2t)));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530728 t5_req->rsvd = cpu_to_be32(isn);
729 PDBG("%s snd_isn %u\n", __func__,
730 be32_to_cpu(t5_req->rsvd));
Vipul Pandya830662f2013-07-04 16:10:47 +0530731 t5_req->opt2 = cpu_to_be32(opt2);
732 } else {
733 t5_req6 = (struct cpl_t5_act_open_req6 *)
734 skb_put(skb, wrlen);
735 INIT_TP_WR(t5_req6, 0);
736 OPCODE_TID(t5_req6) = cpu_to_be32(
737 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
738 ((ep->rss_qid<<14)|ep->atid)));
739 t5_req6->local_port = la6->sin6_port;
740 t5_req6->peer_port = ra6->sin6_port;
741 t5_req6->local_ip_hi = *((__be64 *)
742 (la6->sin6_addr.s6_addr));
743 t5_req6->local_ip_lo = *((__be64 *)
744 (la6->sin6_addr.s6_addr + 8));
745 t5_req6->peer_ip_hi = *((__be64 *)
746 (ra6->sin6_addr.s6_addr));
747 t5_req6->peer_ip_lo = *((__be64 *)
748 (ra6->sin6_addr.s6_addr + 8));
749 t5_req6->opt0 = cpu_to_be64(opt0);
750 t5_req6->params = (__force __be64)cpu_to_be32(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530751 cxgb4_select_ntuple(
752 ep->com.dev->rdev.lldi.ports[0],
753 ep->l2t));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530754 t5_req6->rsvd = cpu_to_be32(isn);
755 PDBG("%s snd_isn %u\n", __func__,
756 be32_to_cpu(t5_req6->rsvd));
Vipul Pandya830662f2013-07-04 16:10:47 +0530757 t5_req6->opt2 = cpu_to_be32(opt2);
758 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000759 }
760
Vipul Pandya793dad92012-12-10 09:30:56 +0000761 set_bit(ACT_OPEN_REQ, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700762 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
763}
764
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530765static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
766 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700767{
768 int mpalen, wrlen;
769 struct fw_ofld_tx_data_wr *req;
770 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530771 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700772
773 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
774
775 BUG_ON(skb_cloned(skb));
776
777 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530778 if (mpa_rev_to_use == 2)
779 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700780 wrlen = roundup(mpalen + sizeof *req, 16);
781 skb = get_skb(skb, wrlen, GFP_KERNEL);
782 if (!skb) {
783 connect_reply_upcall(ep, -ENOMEM);
784 return;
785 }
786 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
787
788 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
789 memset(req, 0, wrlen);
790 req->op_to_immdlen = cpu_to_be32(
791 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
792 FW_WR_COMPL(1) |
793 FW_WR_IMMDLEN(mpalen));
794 req->flowid_len16 = cpu_to_be32(
795 FW_WR_FLOWID(ep->hwtid) |
796 FW_WR_LEN16(wrlen >> 4));
797 req->plen = cpu_to_be32(mpalen);
798 req->tunnel_to_proxy = cpu_to_be32(
799 FW_OFLD_TX_DATA_WR_FLUSH(1) |
800 FW_OFLD_TX_DATA_WR_SHOVE(1));
801
802 mpa = (struct mpa_message *)(req + 1);
803 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
804 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530805 (markers_enabled ? MPA_MARKERS : 0) |
806 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700807 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530808 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530809 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530810 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530811 ep->retry_with_mpa_v1 = 0;
812 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700813
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530814 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700815 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
816 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530817 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
818 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530819 mpa_v2_params.ird = htons((u16)ep->ird);
820 mpa_v2_params.ord = htons((u16)ep->ord);
821
822 if (peer2peer) {
823 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
824 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
825 mpa_v2_params.ord |=
826 htons(MPA_V2_RDMA_WRITE_RTR);
827 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
828 mpa_v2_params.ord |=
829 htons(MPA_V2_RDMA_READ_RTR);
830 }
831 memcpy(mpa->private_data, &mpa_v2_params,
832 sizeof(struct mpa_v2_conn_params));
833
834 if (ep->plen)
835 memcpy(mpa->private_data +
836 sizeof(struct mpa_v2_conn_params),
837 ep->mpa_pkt + sizeof(*mpa), ep->plen);
838 } else
839 if (ep->plen)
840 memcpy(mpa->private_data,
841 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700842
843 /*
844 * Reference the mpa skb. This ensures the data area
845 * will remain in memory until the hw acks the tx.
846 * Function fw4_ack() will deref it.
847 */
848 skb_get(skb);
849 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
850 BUG_ON(ep->mpa_skb);
851 ep->mpa_skb = skb;
852 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
853 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530854 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700855 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530856 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700857 return;
858}
859
860static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
861{
862 int mpalen, wrlen;
863 struct fw_ofld_tx_data_wr *req;
864 struct mpa_message *mpa;
865 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530866 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700867
868 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
869
870 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530871 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
872 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700873 wrlen = roundup(mpalen + sizeof *req, 16);
874
875 skb = get_skb(NULL, wrlen, GFP_KERNEL);
876 if (!skb) {
877 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
878 return -ENOMEM;
879 }
880 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
881
882 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
883 memset(req, 0, wrlen);
884 req->op_to_immdlen = cpu_to_be32(
885 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
886 FW_WR_COMPL(1) |
887 FW_WR_IMMDLEN(mpalen));
888 req->flowid_len16 = cpu_to_be32(
889 FW_WR_FLOWID(ep->hwtid) |
890 FW_WR_LEN16(wrlen >> 4));
891 req->plen = cpu_to_be32(mpalen);
892 req->tunnel_to_proxy = cpu_to_be32(
893 FW_OFLD_TX_DATA_WR_FLUSH(1) |
894 FW_OFLD_TX_DATA_WR_SHOVE(1));
895
896 mpa = (struct mpa_message *)(req + 1);
897 memset(mpa, 0, sizeof(*mpa));
898 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
899 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000900 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700901 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530902
903 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
904 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700905 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
906 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530907 mpa_v2_params.ird = htons(((u16)ep->ird) |
908 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
909 0));
910 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
911 (p2p_type ==
912 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
913 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
914 FW_RI_INIT_P2PTYPE_READ_REQ ?
915 MPA_V2_RDMA_READ_RTR : 0) : 0));
916 memcpy(mpa->private_data, &mpa_v2_params,
917 sizeof(struct mpa_v2_conn_params));
918
919 if (ep->plen)
920 memcpy(mpa->private_data +
921 sizeof(struct mpa_v2_conn_params), pdata, plen);
922 } else
923 if (plen)
924 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700925
926 /*
927 * Reference the mpa skb again. This ensures the data area
928 * will remain in memory until the hw acks the tx.
929 * Function fw4_ack() will deref it.
930 */
931 skb_get(skb);
932 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
933 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
934 BUG_ON(ep->mpa_skb);
935 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +0530936 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700937 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
938}
939
940static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
941{
942 int mpalen, wrlen;
943 struct fw_ofld_tx_data_wr *req;
944 struct mpa_message *mpa;
945 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530946 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700947
948 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
949
950 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530951 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
952 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700953 wrlen = roundup(mpalen + sizeof *req, 16);
954
955 skb = get_skb(NULL, wrlen, GFP_KERNEL);
956 if (!skb) {
957 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
958 return -ENOMEM;
959 }
960 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
961
962 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
963 memset(req, 0, wrlen);
964 req->op_to_immdlen = cpu_to_be32(
965 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
966 FW_WR_COMPL(1) |
967 FW_WR_IMMDLEN(mpalen));
968 req->flowid_len16 = cpu_to_be32(
969 FW_WR_FLOWID(ep->hwtid) |
970 FW_WR_LEN16(wrlen >> 4));
971 req->plen = cpu_to_be32(mpalen);
972 req->tunnel_to_proxy = cpu_to_be32(
973 FW_OFLD_TX_DATA_WR_FLUSH(1) |
974 FW_OFLD_TX_DATA_WR_SHOVE(1));
975
976 mpa = (struct mpa_message *)(req + 1);
977 memset(mpa, 0, sizeof(*mpa));
978 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
979 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
980 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530981 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700982 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530983
984 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
985 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700986 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
987 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530988 mpa_v2_params.ird = htons((u16)ep->ird);
989 mpa_v2_params.ord = htons((u16)ep->ord);
990 if (peer2peer && (ep->mpa_attr.p2p_type !=
991 FW_RI_INIT_P2PTYPE_DISABLED)) {
992 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
993
994 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
995 mpa_v2_params.ord |=
996 htons(MPA_V2_RDMA_WRITE_RTR);
997 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
998 mpa_v2_params.ord |=
999 htons(MPA_V2_RDMA_READ_RTR);
1000 }
1001
1002 memcpy(mpa->private_data, &mpa_v2_params,
1003 sizeof(struct mpa_v2_conn_params));
1004
1005 if (ep->plen)
1006 memcpy(mpa->private_data +
1007 sizeof(struct mpa_v2_conn_params), pdata, plen);
1008 } else
1009 if (plen)
1010 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001011
1012 /*
1013 * Reference the mpa skb. This ensures the data area
1014 * will remain in memory until the hw acks the tx.
1015 * Function fw4_ack() will deref it.
1016 */
1017 skb_get(skb);
1018 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1019 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301020 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301021 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001022 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1023}
1024
1025static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1026{
1027 struct c4iw_ep *ep;
1028 struct cpl_act_establish *req = cplhdr(skb);
1029 unsigned int tid = GET_TID(req);
1030 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
1031 struct tid_info *t = dev->rdev.lldi.tids;
1032
1033 ep = lookup_atid(t, atid);
1034
1035 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1036 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1037
Steve Wisea7db89e2014-03-21 20:40:35 +05301038 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001039 dst_confirm(ep->dst);
1040
1041 /* setup the hwtid for this connection */
1042 ep->hwtid = tid;
1043 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001044 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001045
1046 ep->snd_seq = be32_to_cpu(req->snd_isn);
1047 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1048
1049 set_emss(ep, ntohs(req->tcp_opt));
1050
1051 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001052 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001053 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001054 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001055
1056 /* start MPA negotiation */
1057 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301058 if (ep->retry_with_mpa_v1)
1059 send_mpa_req(ep, skb, 1);
1060 else
1061 send_mpa_req(ep, skb, mpa_rev);
Steve Wisea7db89e2014-03-21 20:40:35 +05301062 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001063 return 0;
1064}
1065
Steve Wisebe13b2d2014-03-21 20:40:33 +05301066static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001067{
1068 struct iw_cm_event event;
1069
1070 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1071 memset(&event, 0, sizeof(event));
1072 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301073 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001074 if (ep->com.cm_id) {
1075 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1076 ep, ep->com.cm_id, ep->hwtid);
1077 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1078 ep->com.cm_id->rem_ref(ep->com.cm_id);
1079 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001080 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001081 }
1082}
1083
1084static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
1085{
1086 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecc18b932014-04-24 14:31:53 -05001087 __state_set(&ep->com, ABORTING);
Vipul Pandya793dad92012-12-10 09:30:56 +00001088 set_bit(ABORT_CONN, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001089 return send_abort(ep, skb, gfp);
1090}
1091
1092static void peer_close_upcall(struct c4iw_ep *ep)
1093{
1094 struct iw_cm_event event;
1095
1096 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1097 memset(&event, 0, sizeof(event));
1098 event.event = IW_CM_EVENT_DISCONNECT;
1099 if (ep->com.cm_id) {
1100 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1101 ep, ep->com.cm_id, ep->hwtid);
1102 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001103 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001104 }
1105}
1106
1107static void peer_abort_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_CLOSE;
1114 event.status = -ECONNRESET;
1115 if (ep->com.cm_id) {
1116 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1117 ep->com.cm_id, ep->hwtid);
1118 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1119 ep->com.cm_id->rem_ref(ep->com.cm_id);
1120 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001121 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001122 }
1123}
1124
1125static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1126{
1127 struct iw_cm_event event;
1128
1129 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1130 memset(&event, 0, sizeof(event));
1131 event.event = IW_CM_EVENT_CONNECT_REPLY;
1132 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301133 memcpy(&event.local_addr, &ep->com.local_addr,
1134 sizeof(ep->com.local_addr));
1135 memcpy(&event.remote_addr, &ep->com.remote_addr,
1136 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001137
1138 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301139 if (!ep->tried_with_mpa_v1) {
1140 /* this means MPA_v2 is used */
1141 event.private_data_len = ep->plen -
1142 sizeof(struct mpa_v2_conn_params);
1143 event.private_data = ep->mpa_pkt +
1144 sizeof(struct mpa_message) +
1145 sizeof(struct mpa_v2_conn_params);
1146 } else {
1147 /* this means MPA_v1 is used */
1148 event.private_data_len = ep->plen;
1149 event.private_data = ep->mpa_pkt +
1150 sizeof(struct mpa_message);
1151 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001152 }
Roland Dreier85963e42010-07-19 13:13:09 -07001153
1154 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1155 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001156 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001157 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1158
Steve Wisecfdda9d2010-04-21 15:30:06 -07001159 if (status < 0) {
1160 ep->com.cm_id->rem_ref(ep->com.cm_id);
1161 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001162 }
1163}
1164
Steve Wisebe13b2d2014-03-21 20:40:33 +05301165static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001166{
1167 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301168 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001169
1170 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1171 memset(&event, 0, sizeof(event));
1172 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301173 memcpy(&event.local_addr, &ep->com.local_addr,
1174 sizeof(ep->com.local_addr));
1175 memcpy(&event.remote_addr, &ep->com.remote_addr,
1176 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001177 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301178 if (!ep->tried_with_mpa_v1) {
1179 /* this means MPA_v2 is used */
1180 event.ord = ep->ord;
1181 event.ird = ep->ird;
1182 event.private_data_len = ep->plen -
1183 sizeof(struct mpa_v2_conn_params);
1184 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1185 sizeof(struct mpa_v2_conn_params);
1186 } else {
1187 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301188 event.ord = cur_max_read_depth(ep->com.dev);
1189 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301190 event.private_data_len = ep->plen;
1191 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1192 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301193 c4iw_get_ep(&ep->com);
1194 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1195 &event);
1196 if (ret)
1197 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001198 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001199 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301200 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001201}
1202
1203static void established_upcall(struct c4iw_ep *ep)
1204{
1205 struct iw_cm_event event;
1206
1207 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1208 memset(&event, 0, sizeof(event));
1209 event.event = IW_CM_EVENT_ESTABLISHED;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301210 event.ird = ep->ird;
1211 event.ord = ep->ord;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001212 if (ep->com.cm_id) {
1213 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1214 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001215 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001216 }
1217}
1218
1219static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1220{
1221 struct cpl_rx_data_ack *req;
1222 struct sk_buff *skb;
1223 int wrlen = roundup(sizeof *req, 16);
1224
1225 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1226 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1227 if (!skb) {
1228 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1229 return 0;
1230 }
1231
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301232 /*
1233 * If we couldn't specify the entire rcv window at connection setup
1234 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1235 * then add the overage in to the credits returned.
1236 */
1237 if (ep->rcv_win > RCV_BUFSIZ_MASK * 1024)
1238 credits += ep->rcv_win - RCV_BUFSIZ_MASK * 1024;
1239
Steve Wisecfdda9d2010-04-21 15:30:06 -07001240 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1241 memset(req, 0, wrlen);
1242 INIT_TP_WR(req, ep->hwtid);
1243 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1244 ep->hwtid));
Steve Wiseba6d3922010-06-23 15:46:49 +00001245 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1246 F_RX_DACK_CHANGE |
1247 V_RX_DACK_MODE(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001248 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001249 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1250 return credits;
1251}
1252
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301253#define RELAXED_IRD_NEGOTIATION 1
1254
Steve Wisecc18b932014-04-24 14:31:53 -05001255static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001256{
1257 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301258 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001259 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301260 u16 resp_ird, resp_ord;
1261 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001262 struct c4iw_qp_attributes attrs;
1263 enum c4iw_qp_attr_mask mask;
1264 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001265 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001266
1267 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1268
1269 /*
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001270 * Stop mpa timer. If it expired, then
1271 * we ignore the MPA reply. process_timeout()
1272 * will abort the connection.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001273 */
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001274 if (stop_ep_timer(ep))
Steve Wisecc18b932014-04-24 14:31:53 -05001275 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001276
1277 /*
1278 * If we get more than the supported amount of private data
1279 * then we must fail this connection.
1280 */
1281 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1282 err = -EINVAL;
1283 goto err;
1284 }
1285
1286 /*
1287 * copy the new data into our accumulation buffer.
1288 */
1289 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1290 skb->len);
1291 ep->mpa_pkt_len += skb->len;
1292
1293 /*
1294 * if we don't even have the mpa message, then bail.
1295 */
1296 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001297 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001298 mpa = (struct mpa_message *) ep->mpa_pkt;
1299
1300 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301301 if (mpa->revision > mpa_rev) {
1302 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1303 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001304 err = -EPROTO;
1305 goto err;
1306 }
1307 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1308 err = -EPROTO;
1309 goto err;
1310 }
1311
1312 plen = ntohs(mpa->private_data_size);
1313
1314 /*
1315 * Fail if there's too much private data.
1316 */
1317 if (plen > MPA_MAX_PRIVATE_DATA) {
1318 err = -EPROTO;
1319 goto err;
1320 }
1321
1322 /*
1323 * If plen does not account for pkt size
1324 */
1325 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1326 err = -EPROTO;
1327 goto err;
1328 }
1329
1330 ep->plen = (u8) plen;
1331
1332 /*
1333 * If we don't have all the pdata yet, then bail.
1334 * We'll continue process when more data arrives.
1335 */
1336 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001337 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001338
1339 if (mpa->flags & MPA_REJECT) {
1340 err = -ECONNREFUSED;
1341 goto err;
1342 }
1343
1344 /*
1345 * If we get here we have accumulated the entire mpa
1346 * start reply message including private data. And
1347 * the MPA header is valid.
1348 */
Steve Wisec529fb52014-03-21 20:40:37 +05301349 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001350 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1351 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1352 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301353 ep->mpa_attr.version = mpa->revision;
1354 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1355
1356 if (mpa->revision == 2) {
1357 ep->mpa_attr.enhanced_rdma_conn =
1358 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1359 if (ep->mpa_attr.enhanced_rdma_conn) {
1360 mpa_v2_params = (struct mpa_v2_conn_params *)
1361 (ep->mpa_pkt + sizeof(*mpa));
1362 resp_ird = ntohs(mpa_v2_params->ird) &
1363 MPA_V2_IRD_ORD_MASK;
1364 resp_ord = ntohs(mpa_v2_params->ord) &
1365 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301366 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1367 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301368
1369 /*
1370 * This is a double-check. Ideally, below checks are
1371 * not required since ird/ord stuff has been taken
1372 * care of in c4iw_accept_cr
1373 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301374 if (ep->ird < resp_ord) {
1375 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1376 ep->com.dev->rdev.lldi.max_ordird_qp)
1377 ep->ird = resp_ord;
1378 else
1379 insuff_ird = 1;
1380 } else if (ep->ird > resp_ord) {
1381 ep->ird = resp_ord;
1382 }
1383 if (ep->ord > resp_ird) {
1384 if (RELAXED_IRD_NEGOTIATION)
1385 ep->ord = resp_ird;
1386 else
1387 insuff_ird = 1;
1388 }
1389 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301390 err = -ENOMEM;
1391 ep->ird = resp_ord;
1392 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301393 }
1394
1395 if (ntohs(mpa_v2_params->ird) &
1396 MPA_V2_PEER2PEER_MODEL) {
1397 if (ntohs(mpa_v2_params->ord) &
1398 MPA_V2_RDMA_WRITE_RTR)
1399 ep->mpa_attr.p2p_type =
1400 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1401 else if (ntohs(mpa_v2_params->ord) &
1402 MPA_V2_RDMA_READ_RTR)
1403 ep->mpa_attr.p2p_type =
1404 FW_RI_INIT_P2PTYPE_READ_REQ;
1405 }
1406 }
1407 } else if (mpa->revision == 1)
1408 if (peer2peer)
1409 ep->mpa_attr.p2p_type = p2p_type;
1410
Steve Wisecfdda9d2010-04-21 15:30:06 -07001411 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301412 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1413 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1414 ep->mpa_attr.recv_marker_enabled,
1415 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1416 ep->mpa_attr.p2p_type, p2p_type);
1417
1418 /*
1419 * If responder's RTR does not match with that of initiator, assign
1420 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1421 * generated when moving QP to RTS state.
1422 * A TERM message will be sent after QP has moved to RTS state
1423 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001424 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301425 (ep->mpa_attr.p2p_type != p2p_type)) {
1426 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1427 rtr_mismatch = 1;
1428 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001429
1430 attrs.mpa_attr = ep->mpa_attr;
1431 attrs.max_ird = ep->ird;
1432 attrs.max_ord = ep->ord;
1433 attrs.llp_stream_handle = ep;
1434 attrs.next_state = C4IW_QP_STATE_RTS;
1435
1436 mask = C4IW_QP_ATTR_NEXT_STATE |
1437 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1438 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1439
1440 /* bind QP and TID with INIT_WR */
1441 err = c4iw_modify_qp(ep->com.qp->rhp,
1442 ep->com.qp, mask, &attrs, 1);
1443 if (err)
1444 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301445
1446 /*
1447 * If responder's RTR requirement did not match with what initiator
1448 * supports, generate TERM message
1449 */
1450 if (rtr_mismatch) {
1451 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1452 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1453 attrs.ecode = MPA_NOMATCH_RTR;
1454 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001455 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301456 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001457 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301458 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001459 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301460 goto out;
1461 }
1462
1463 /*
1464 * Generate TERM if initiator IRD is not sufficient for responder
1465 * provided ORD. Currently, we do the same behaviour even when
1466 * responder provided IRD is also not sufficient as regards to
1467 * initiator ORD.
1468 */
1469 if (insuff_ird) {
1470 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1471 __func__);
1472 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1473 attrs.ecode = MPA_INSUFF_IRD;
1474 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001475 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301476 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001477 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301478 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001479 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301480 goto out;
1481 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001482 goto out;
1483err:
Steve Wisec529fb52014-03-21 20:40:37 +05301484 __state_set(&ep->com, ABORTING);
Steve Wiseb21ef162010-06-10 19:02:55 +00001485 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001486out:
1487 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001488 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001489}
1490
1491static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1492{
1493 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301494 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001495 u16 plen;
1496
1497 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1498
Steve Wisecfdda9d2010-04-21 15:30:06 -07001499 /*
1500 * If we get more than the supported amount of private data
1501 * then we must fail this connection.
1502 */
1503 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001504 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001505 abort_connection(ep, skb, GFP_KERNEL);
1506 return;
1507 }
1508
1509 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1510
1511 /*
1512 * Copy the new data into our accumulation buffer.
1513 */
1514 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1515 skb->len);
1516 ep->mpa_pkt_len += skb->len;
1517
1518 /*
1519 * If we don't even have the mpa message, then bail.
1520 * We'll continue process when more data arrives.
1521 */
1522 if (ep->mpa_pkt_len < sizeof(*mpa))
1523 return;
1524
1525 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001526 mpa = (struct mpa_message *) ep->mpa_pkt;
1527
1528 /*
1529 * Validate MPA Header.
1530 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301531 if (mpa->revision > mpa_rev) {
1532 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1533 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001534 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001535 abort_connection(ep, skb, GFP_KERNEL);
1536 return;
1537 }
1538
1539 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001540 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001541 abort_connection(ep, skb, GFP_KERNEL);
1542 return;
1543 }
1544
1545 plen = ntohs(mpa->private_data_size);
1546
1547 /*
1548 * Fail if there's too much private data.
1549 */
1550 if (plen > MPA_MAX_PRIVATE_DATA) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001551 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001552 abort_connection(ep, skb, GFP_KERNEL);
1553 return;
1554 }
1555
1556 /*
1557 * If plen does not account for pkt size
1558 */
1559 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001560 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001561 abort_connection(ep, skb, GFP_KERNEL);
1562 return;
1563 }
1564 ep->plen = (u8) plen;
1565
1566 /*
1567 * If we don't have all the pdata yet, then bail.
1568 */
1569 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1570 return;
1571
1572 /*
1573 * If we get here we have accumulated the entire mpa
1574 * start reply message including private data.
1575 */
1576 ep->mpa_attr.initiator = 0;
1577 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1578 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1579 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301580 ep->mpa_attr.version = mpa->revision;
1581 if (mpa->revision == 1)
1582 ep->tried_with_mpa_v1 = 1;
1583 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1584
1585 if (mpa->revision == 2) {
1586 ep->mpa_attr.enhanced_rdma_conn =
1587 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1588 if (ep->mpa_attr.enhanced_rdma_conn) {
1589 mpa_v2_params = (struct mpa_v2_conn_params *)
1590 (ep->mpa_pkt + sizeof(*mpa));
1591 ep->ird = ntohs(mpa_v2_params->ird) &
1592 MPA_V2_IRD_ORD_MASK;
1593 ep->ord = ntohs(mpa_v2_params->ord) &
1594 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301595 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1596 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301597 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1598 if (peer2peer) {
1599 if (ntohs(mpa_v2_params->ord) &
1600 MPA_V2_RDMA_WRITE_RTR)
1601 ep->mpa_attr.p2p_type =
1602 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1603 else if (ntohs(mpa_v2_params->ord) &
1604 MPA_V2_RDMA_READ_RTR)
1605 ep->mpa_attr.p2p_type =
1606 FW_RI_INIT_P2PTYPE_READ_REQ;
1607 }
1608 }
1609 } else if (mpa->revision == 1)
1610 if (peer2peer)
1611 ep->mpa_attr.p2p_type = p2p_type;
1612
Steve Wisecfdda9d2010-04-21 15:30:06 -07001613 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1614 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1615 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1616 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1617 ep->mpa_attr.p2p_type);
1618
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001619 /*
1620 * If the endpoint timer already expired, then we ignore
1621 * the start request. process_timeout() will abort
1622 * the connection.
1623 */
1624 if (!stop_ep_timer(ep)) {
1625 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001626
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001627 /* drive upcall */
1628 mutex_lock(&ep->parent_ep->com.mutex);
1629 if (ep->parent_ep->com.state != DEAD) {
1630 if (connect_request_upcall(ep))
1631 abort_connection(ep, skb, GFP_KERNEL);
1632 } else {
Steve Wisebe13b2d2014-03-21 20:40:33 +05301633 abort_connection(ep, skb, GFP_KERNEL);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001634 }
1635 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301636 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001637 return;
1638}
1639
1640static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1641{
1642 struct c4iw_ep *ep;
1643 struct cpl_rx_data *hdr = cplhdr(skb);
1644 unsigned int dlen = ntohs(hdr->len);
1645 unsigned int tid = GET_TID(hdr);
1646 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001647 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001648 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001649
1650 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301651 if (!ep)
1652 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001653 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1654 skb_pull(skb, sizeof(*hdr));
1655 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301656 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001657
Steve Wisecfdda9d2010-04-21 15:30:06 -07001658 /* update RX credits */
1659 update_rx_credits(ep, dlen);
1660
Steve Wisec529fb52014-03-21 20:40:37 +05301661 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001662 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001663 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001664 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001665 break;
1666 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001667 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001668 process_mpa_request(ep, skb);
1669 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001670 case FPDU_MODE: {
1671 struct c4iw_qp_attributes attrs;
1672 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001673 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001674 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001675 " qpid %u ep %p state %d tid %u status %d\n",
1676 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301677 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301678 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001679 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001680 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1681 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001682 break;
1683 }
Vipul Pandya15579672013-01-07 13:11:52 +00001684 default:
1685 break;
1686 }
Steve Wisec529fb52014-03-21 20:40:37 +05301687 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001688 if (disconnect)
1689 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001690 return 0;
1691}
1692
1693static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1694{
1695 struct c4iw_ep *ep;
1696 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001697 int release = 0;
1698 unsigned int tid = GET_TID(rpl);
1699 struct tid_info *t = dev->rdev.lldi.tids;
1700
1701 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301702 if (!ep) {
1703 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1704 return 0;
1705 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001706 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001707 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001708 switch (ep->com.state) {
1709 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001710 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001711 __state_set(&ep->com, DEAD);
1712 release = 1;
1713 break;
1714 default:
1715 printk(KERN_ERR "%s ep %p state %d\n",
1716 __func__, ep, ep->com.state);
1717 break;
1718 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001719 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001720
1721 if (release)
1722 release_ep_resources(ep);
1723 return 0;
1724}
1725
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001726static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1727{
1728 struct sk_buff *skb;
1729 struct fw_ofld_connection_wr *req;
1730 unsigned int mtu_idx;
1731 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301732 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301733 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001734
1735 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1736 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1737 memset(req, 0, sizeof(*req));
1738 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1739 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301740 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1741 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001742 ep->l2t));
Steve Wise9eccfe12014-03-26 17:08:09 -05001743 sin = (struct sockaddr_in *)&ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301744 req->le.lport = sin->sin_port;
1745 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05001746 sin = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301747 req->le.pport = sin->sin_port;
1748 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001749 req->tcb.t_state_to_astid =
1750 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1751 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1752 req->tcb.cplrxdataack_cplpassacceptrpl =
1753 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001754 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001755 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301756 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
1757 enable_tcp_timestamps);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001758 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301759
1760 /*
1761 * Specify the largest window that will fit in opt0. The
1762 * remainder will be specified in the rx_data_ack.
1763 */
1764 win = ep->rcv_win >> 10;
1765 if (win > RCV_BUFSIZ_MASK)
1766 win = RCV_BUFSIZ_MASK;
1767
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001768 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001769 (nocong ? NO_CONG(1) : 0) |
1770 KEEP_ALIVE(1) |
1771 DELACK(1) |
1772 WND_SCALE(wscale) |
1773 MSS_IDX(mtu_idx) |
1774 L2T_IDX(ep->l2t->idx) |
1775 TX_CHAN(ep->tx_chan) |
1776 SMAC_SEL(ep->smac_idx) |
1777 DSCP(ep->tos) |
1778 ULP_MODE(ULP_MODE_TCPDDP) |
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301779 RCV_BUFSIZ(win));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001780 req->tcb.opt2 = (__force __be32) (PACE(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001781 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1782 RX_CHANNEL(0) |
1783 CCTRL_ECN(enable_ecn) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001784 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001785 if (enable_tcp_timestamps)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001786 req->tcb.opt2 |= (__force __be32) TSTAMPS_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001787 if (enable_tcp_sack)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001788 req->tcb.opt2 |= (__force __be32) SACK_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001789 if (wscale && enable_tcp_window_scaling)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001790 req->tcb.opt2 |= (__force __be32) WND_SCALE_EN(1);
1791 req->tcb.opt0 = cpu_to_be64((__force u64) req->tcb.opt0);
1792 req->tcb.opt2 = cpu_to_be32((__force u32) req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001793 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1794 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001795 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1796}
1797
Steve Wisecfdda9d2010-04-21 15:30:06 -07001798/*
1799 * Return whether a failed active open has allocated a TID
1800 */
1801static inline int act_open_has_tid(int status)
1802{
1803 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1804 status != CPL_ERR_ARP_MISS;
1805}
1806
Steve Wise7a2cea22014-03-14 21:52:07 +05301807/* Returns whether a CPL status conveys negative advice.
1808 */
1809static int is_neg_adv(unsigned int status)
1810{
1811 return status == CPL_ERR_RTX_NEG_ADVICE ||
1812 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1813 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1814}
1815
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301816static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1817{
1818 ep->snd_win = snd_win;
1819 ep->rcv_win = rcv_win;
1820 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1821}
1822
Vipul Pandya793dad92012-12-10 09:30:56 +00001823#define ACT_OPEN_RETRY_COUNT 2
1824
Vipul Pandya830662f2013-07-04 16:10:47 +05301825static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1826 struct dst_entry *dst, struct c4iw_dev *cdev,
1827 bool clear_mpa_v1)
1828{
1829 struct neighbour *n;
1830 int err, step;
1831 struct net_device *pdev;
1832
1833 n = dst_neigh_lookup(dst, peer_ip);
1834 if (!n)
1835 return -ENODEV;
1836
1837 rcu_read_lock();
1838 err = -ENOMEM;
1839 if (n->dev->flags & IFF_LOOPBACK) {
1840 if (iptype == 4)
1841 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1842 else if (IS_ENABLED(CONFIG_IPV6))
1843 for_each_netdev(&init_net, pdev) {
1844 if (ipv6_chk_addr(&init_net,
1845 (struct in6_addr *)peer_ip,
1846 pdev, 1))
1847 break;
1848 }
1849 else
1850 pdev = NULL;
1851
1852 if (!pdev) {
1853 err = -ENODEV;
1854 goto out;
1855 }
1856 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1857 n, pdev, 0);
1858 if (!ep->l2t)
1859 goto out;
1860 ep->mtu = pdev->mtu;
1861 ep->tx_chan = cxgb4_port_chan(pdev);
1862 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1863 step = cdev->rdev.lldi.ntxq /
1864 cdev->rdev.lldi.nchan;
1865 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1866 step = cdev->rdev.lldi.nrxq /
1867 cdev->rdev.lldi.nchan;
1868 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1869 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1870 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301871 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301872 dev_put(pdev);
1873 } else {
1874 pdev = get_real_dev(n->dev);
1875 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1876 n, pdev, 0);
1877 if (!ep->l2t)
1878 goto out;
1879 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05001880 ep->tx_chan = cxgb4_port_chan(pdev);
1881 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
Vipul Pandya830662f2013-07-04 16:10:47 +05301882 step = cdev->rdev.lldi.ntxq /
1883 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05001884 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1885 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05301886 step = cdev->rdev.lldi.nrxq /
1887 cdev->rdev.lldi.nchan;
1888 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05001889 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301890 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301891
1892 if (clear_mpa_v1) {
1893 ep->retry_with_mpa_v1 = 0;
1894 ep->tried_with_mpa_v1 = 0;
1895 }
1896 }
1897 err = 0;
1898out:
1899 rcu_read_unlock();
1900
1901 neigh_release(n);
1902
1903 return err;
1904}
1905
Vipul Pandya793dad92012-12-10 09:30:56 +00001906static int c4iw_reconnect(struct c4iw_ep *ep)
1907{
1908 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05301909 struct sockaddr_in *laddr = (struct sockaddr_in *)
1910 &ep->com.cm_id->local_addr;
1911 struct sockaddr_in *raddr = (struct sockaddr_in *)
1912 &ep->com.cm_id->remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301913 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
1914 &ep->com.cm_id->local_addr;
1915 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
1916 &ep->com.cm_id->remote_addr;
1917 int iptype;
1918 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00001919
1920 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1921 init_timer(&ep->timer);
1922
1923 /*
1924 * Allocate an active TID to initiate a TCP connection.
1925 */
1926 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1927 if (ep->atid == -1) {
1928 pr_err("%s - cannot alloc atid.\n", __func__);
1929 err = -ENOMEM;
1930 goto fail2;
1931 }
1932 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1933
1934 /* find a route */
Vipul Pandya830662f2013-07-04 16:10:47 +05301935 if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
1936 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
1937 raddr->sin_addr.s_addr, laddr->sin_port,
1938 raddr->sin_port, 0);
1939 iptype = 4;
1940 ra = (__u8 *)&raddr->sin_addr;
1941 } else {
1942 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
1943 raddr6->sin6_addr.s6_addr,
1944 laddr6->sin6_port, raddr6->sin6_port, 0,
1945 raddr6->sin6_scope_id);
1946 iptype = 6;
1947 ra = (__u8 *)&raddr6->sin6_addr;
1948 }
1949 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001950 pr_err("%s - cannot find route.\n", __func__);
1951 err = -EHOSTUNREACH;
1952 goto fail3;
1953 }
Vipul Pandya830662f2013-07-04 16:10:47 +05301954 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false);
1955 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001956 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00001957 goto fail4;
1958 }
1959
1960 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1961 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1962 ep->l2t->idx);
1963
1964 state_set(&ep->com, CONNECTING);
1965 ep->tos = 0;
1966
1967 /* send connect request to rnic */
1968 err = send_connect(ep);
1969 if (!err)
1970 goto out;
1971
1972 cxgb4_l2t_release(ep->l2t);
1973fail4:
1974 dst_release(ep->dst);
1975fail3:
1976 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1977 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1978fail2:
1979 /*
1980 * remember to send notification to upper layer.
1981 * We are in here so the upper layer is not aware that this is
1982 * re-connect attempt and so, upper layer is still waiting for
1983 * response of 1st connect request.
1984 */
1985 connect_reply_upcall(ep, -ECONNRESET);
1986 c4iw_put_ep(&ep->com);
1987out:
1988 return err;
1989}
1990
Steve Wisecfdda9d2010-04-21 15:30:06 -07001991static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1992{
1993 struct c4iw_ep *ep;
1994 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1995 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1996 ntohl(rpl->atid_status)));
1997 struct tid_info *t = dev->rdev.lldi.tids;
1998 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05301999 struct sockaddr_in *la;
2000 struct sockaddr_in *ra;
2001 struct sockaddr_in6 *la6;
2002 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002003
2004 ep = lookup_atid(t, atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05002005 la = (struct sockaddr_in *)&ep->com.mapped_local_addr;
2006 ra = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
2007 la6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
2008 ra6 = (struct sockaddr_in6 *)&ep->com.mapped_remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002009
2010 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2011 status, status2errno(status));
2012
Steve Wise7a2cea22014-03-14 21:52:07 +05302013 if (is_neg_adv(status)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002014 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
2015 atid);
2016 return 0;
2017 }
2018
Vipul Pandya793dad92012-12-10 09:30:56 +00002019 set_bit(ACT_OPEN_RPL, &ep->com.history);
2020
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302021 /*
2022 * Log interesting failures.
2023 */
2024 switch (status) {
2025 case CPL_ERR_CONN_RESET:
2026 case CPL_ERR_CONN_TIMEDOUT:
2027 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002028 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302029 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002030 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302031 mutex_unlock(&dev->rdev.stats.lock);
2032 if (ep->com.local_addr.ss_family == AF_INET &&
2033 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002034 send_fw_act_open_req(ep,
2035 GET_TID_TID(GET_AOPEN_ATID(
2036 ntohl(rpl->atid_status))));
2037 return 0;
2038 }
2039 break;
2040 case CPL_ERR_CONN_EXIST:
2041 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2042 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2043 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2044 atid);
2045 cxgb4_free_atid(t, atid);
2046 dst_release(ep->dst);
2047 cxgb4_l2t_release(ep->l2t);
2048 c4iw_reconnect(ep);
2049 return 0;
2050 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002051 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302052 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302053 if (ep->com.local_addr.ss_family == AF_INET) {
2054 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2055 atid, status, status2errno(status),
2056 &la->sin_addr.s_addr, ntohs(la->sin_port),
2057 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2058 } else {
2059 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2060 atid, status, status2errno(status),
2061 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2062 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2063 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302064 break;
2065 }
2066
Steve Wisecfdda9d2010-04-21 15:30:06 -07002067 connect_reply_upcall(ep, status2errno(status));
2068 state_set(&ep->com, DEAD);
2069
2070 if (status && act_open_has_tid(status))
2071 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2072
Vipul Pandya793dad92012-12-10 09:30:56 +00002073 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002074 cxgb4_free_atid(t, atid);
2075 dst_release(ep->dst);
2076 cxgb4_l2t_release(ep->l2t);
2077 c4iw_put_ep(&ep->com);
2078
2079 return 0;
2080}
2081
2082static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2083{
2084 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2085 struct tid_info *t = dev->rdev.lldi.tids;
2086 unsigned int stid = GET_TID(rpl);
2087 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2088
2089 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002090 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2091 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002092 }
2093 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2094 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002095 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002096
Vipul Pandya1cab7752012-12-10 09:30:55 +00002097out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002098 return 0;
2099}
2100
Steve Wisecfdda9d2010-04-21 15:30:06 -07002101static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2102{
2103 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2104 struct tid_info *t = dev->rdev.lldi.tids;
2105 unsigned int stid = GET_TID(rpl);
2106 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2107
2108 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002109 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002110 return 0;
2111}
2112
Vipul Pandya830662f2013-07-04 16:10:47 +05302113static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002114 struct cpl_pass_accept_req *req)
2115{
2116 struct cpl_pass_accept_rpl *rpl;
2117 unsigned int mtu_idx;
2118 u64 opt0;
2119 u32 opt2;
2120 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302121 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302122 int win;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002123
2124 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2125 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302126
Steve Wisecfdda9d2010-04-21 15:30:06 -07002127 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302128 rpl = cplhdr(skb);
2129 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
2130 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2131 rpl5 = (void *)rpl;
2132 INIT_TP_WR(rpl5, ep->hwtid);
2133 } else {
2134 skb_trim(skb, sizeof(*rpl));
2135 INIT_TP_WR(rpl, ep->hwtid);
2136 }
2137 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2138 ep->hwtid));
2139
2140 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
2141 enable_tcp_timestamps && req->tcpopt.tstamp);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002142 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302143
2144 /*
2145 * Specify the largest window that will fit in opt0. The
2146 * remainder will be specified in the rx_data_ack.
2147 */
2148 win = ep->rcv_win >> 10;
2149 if (win > RCV_BUFSIZ_MASK)
2150 win = RCV_BUFSIZ_MASK;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002151 opt0 = (nocong ? NO_CONG(1) : 0) |
2152 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +00002153 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07002154 WND_SCALE(wscale) |
2155 MSS_IDX(mtu_idx) |
2156 L2T_IDX(ep->l2t->idx) |
2157 TX_CHAN(ep->tx_chan) |
2158 SMAC_SEL(ep->smac_idx) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002159 DSCP(ep->tos >> 2) |
Steve Wiseb48f3b92011-03-11 22:30:21 +00002160 ULP_MODE(ULP_MODE_TCPDDP) |
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302161 RCV_BUFSIZ(win);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002162 opt2 = RX_CHANNEL(0) |
2163 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
2164
2165 if (enable_tcp_timestamps && req->tcpopt.tstamp)
2166 opt2 |= TSTAMPS_EN(1);
2167 if (enable_tcp_sack && req->tcpopt.sack)
2168 opt2 |= SACK_EN(1);
2169 if (wscale && enable_tcp_window_scaling)
2170 opt2 |= WND_SCALE_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002171 if (enable_ecn) {
2172 const struct tcphdr *tcph;
2173 u32 hlen = ntohl(req->hdr_len);
2174
2175 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
2176 G_IP_HDR_LEN(hlen);
2177 if (tcph->ece && tcph->cwr)
2178 opt2 |= CCTRL_ECN(1);
2179 }
Steve Wise92e50112014-04-24 14:31:59 -05002180 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302181 u32 isn = (prandom_u32() & ~7UL) - 1;
Steve Wise92e50112014-04-24 14:31:59 -05002182 opt2 |= T5_OPT_2_VALID;
2183 opt2 |= V_CONG_CNTRL(CONG_ALG_TAHOE);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302184 opt2 |= CONG_CNTRL_VALID; /* OPT_2_ISS for T5 */
2185 rpl5 = (void *)rpl;
2186 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2187 if (peer2peer)
2188 isn += 4;
2189 rpl5->iss = cpu_to_be32(isn);
2190 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002191 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002192
Steve Wisecfdda9d2010-04-21 15:30:06 -07002193 rpl->opt0 = cpu_to_be64(opt0);
2194 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002195 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wiseb38a0ad2013-08-06 21:04:37 +05302196 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002197 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2198
2199 return;
2200}
2201
Vipul Pandya830662f2013-07-04 16:10:47 +05302202static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002203{
Vipul Pandya830662f2013-07-04 16:10:47 +05302204 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002205 BUG_ON(skb_cloned(skb));
2206 skb_trim(skb, sizeof(struct cpl_tid_release));
2207 skb_get(skb);
2208 release_tid(&dev->rdev, hwtid, skb);
2209 return;
2210}
2211
Vipul Pandya830662f2013-07-04 16:10:47 +05302212static void get_4tuple(struct cpl_pass_accept_req *req, int *iptype,
2213 __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002214 __be16 *local_port, __be16 *peer_port)
2215{
2216 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
2217 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
2218 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302219 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002220 struct tcphdr *tcp = (struct tcphdr *)
2221 ((u8 *)(req + 1) + eth_len + ip_len);
2222
Vipul Pandya830662f2013-07-04 16:10:47 +05302223 if (ip->version == 4) {
2224 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2225 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2226 ntohs(tcp->dest));
2227 *iptype = 4;
2228 memcpy(peer_ip, &ip->saddr, 4);
2229 memcpy(local_ip, &ip->daddr, 4);
2230 } else {
2231 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2232 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2233 ntohs(tcp->dest));
2234 *iptype = 6;
2235 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2236 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2237 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002238 *peer_port = tcp->source;
2239 *local_port = tcp->dest;
2240
2241 return;
2242}
2243
2244static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2245{
Vipul Pandya793dad92012-12-10 09:30:56 +00002246 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002247 struct cpl_pass_accept_req *req = cplhdr(skb);
2248 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
2249 struct tid_info *t = dev->rdev.lldi.tids;
2250 unsigned int hwtid = GET_TID(req);
2251 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302252 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002253 __be16 local_port, peer_port;
David Miller3786cf12011-12-02 16:52:31 +00002254 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002255 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302256 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302257 unsigned short hdrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002258
2259 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002260 if (!parent_ep) {
2261 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2262 goto reject;
2263 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002264
Steve Wisecfdda9d2010-04-21 15:30:06 -07002265 if (state_read(&parent_ep->com) != LISTEN) {
2266 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
2267 __func__);
2268 goto reject;
2269 }
2270
Vipul Pandya830662f2013-07-04 16:10:47 +05302271 get_4tuple(req, &iptype, local_ip, peer_ip, &local_port, &peer_port);
2272
Steve Wisecfdda9d2010-04-21 15:30:06 -07002273 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302274 if (iptype == 4) {
2275 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2276 , __func__, parent_ep, hwtid,
2277 local_ip, peer_ip, ntohs(local_port),
2278 ntohs(peer_port), peer_mss);
2279 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2280 local_port, peer_port,
2281 GET_POPEN_TOS(ntohl(req->tos_stid)));
2282 } else {
2283 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2284 , __func__, parent_ep, hwtid,
2285 local_ip, peer_ip, ntohs(local_port),
2286 ntohs(peer_port), peer_mss);
2287 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
2288 PASS_OPEN_TOS(ntohl(req->tos_stid)),
2289 ((struct sockaddr_in6 *)
2290 &parent_ep->com.local_addr)->sin6_scope_id);
2291 }
2292 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002293 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2294 __func__);
2295 goto reject;
2296 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002297
2298 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2299 if (!child_ep) {
2300 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2301 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002302 dst_release(dst);
2303 goto reject;
2304 }
David Miller3786cf12011-12-02 16:52:31 +00002305
Vipul Pandya830662f2013-07-04 16:10:47 +05302306 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false);
David Miller3786cf12011-12-02 16:52:31 +00002307 if (err) {
2308 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2309 __func__);
2310 dst_release(dst);
2311 kfree(child_ep);
2312 goto reject;
2313 }
2314
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302315 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2316 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2317 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2318 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002319
Steve Wisecfdda9d2010-04-21 15:30:06 -07002320 state_set(&child_ep->com, CONNECTING);
2321 child_ep->com.dev = dev;
2322 child_ep->com.cm_id = NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +05302323 if (iptype == 4) {
2324 struct sockaddr_in *sin = (struct sockaddr_in *)
2325 &child_ep->com.local_addr;
2326 sin->sin_family = PF_INET;
2327 sin->sin_port = local_port;
2328 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2329 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
2330 sin->sin_family = PF_INET;
2331 sin->sin_port = peer_port;
2332 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2333 } else {
2334 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
2335 &child_ep->com.local_addr;
2336 sin6->sin6_family = PF_INET6;
2337 sin6->sin6_port = local_port;
2338 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2339 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
2340 sin6->sin6_family = PF_INET6;
2341 sin6->sin6_port = peer_port;
2342 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2343 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002344 c4iw_get_ep(&parent_ep->com);
2345 child_ep->parent_ep = parent_ep;
2346 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002347 child_ep->dst = dst;
2348 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002349
2350 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002351 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002352
2353 init_timer(&child_ep->timer);
2354 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002355 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Vipul Pandya830662f2013-07-04 16:10:47 +05302356 accept_cr(child_ep, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00002357 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002358 goto out;
2359reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302360 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002361out:
2362 return 0;
2363}
2364
2365static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2366{
2367 struct c4iw_ep *ep;
2368 struct cpl_pass_establish *req = cplhdr(skb);
2369 struct tid_info *t = dev->rdev.lldi.tids;
2370 unsigned int tid = GET_TID(req);
2371
2372 ep = lookup_tid(t, tid);
2373 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2374 ep->snd_seq = be32_to_cpu(req->snd_isn);
2375 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2376
Vipul Pandya1cab7752012-12-10 09:30:55 +00002377 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2378 ntohs(req->tcp_opt));
2379
Steve Wisecfdda9d2010-04-21 15:30:06 -07002380 set_emss(ep, ntohs(req->tcp_opt));
2381
2382 dst_confirm(ep->dst);
2383 state_set(&ep->com, MPA_REQ_WAIT);
2384 start_ep_timer(ep);
2385 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002386 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002387
2388 return 0;
2389}
2390
2391static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2392{
2393 struct cpl_peer_close *hdr = cplhdr(skb);
2394 struct c4iw_ep *ep;
2395 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002396 int disconnect = 1;
2397 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002398 struct tid_info *t = dev->rdev.lldi.tids;
2399 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002400 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002401
2402 ep = lookup_tid(t, tid);
2403 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2404 dst_confirm(ep->dst);
2405
Vipul Pandya793dad92012-12-10 09:30:56 +00002406 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002407 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002408 switch (ep->com.state) {
2409 case MPA_REQ_WAIT:
2410 __state_set(&ep->com, CLOSING);
2411 break;
2412 case MPA_REQ_SENT:
2413 __state_set(&ep->com, CLOSING);
2414 connect_reply_upcall(ep, -ECONNRESET);
2415 break;
2416 case MPA_REQ_RCVD:
2417
2418 /*
2419 * We're gonna mark this puppy DEAD, but keep
2420 * the reference on it until the ULP accepts or
2421 * rejects the CR. Also wake up anyone waiting
2422 * in rdma connection migration (see c4iw_accept_cr()).
2423 */
2424 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002425 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002426 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002427 break;
2428 case MPA_REP_SENT:
2429 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002430 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002431 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002432 break;
2433 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002434 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002435 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002436 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002437 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002438 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002439 if (ret != -ECONNRESET) {
2440 peer_close_upcall(ep);
2441 disconnect = 1;
2442 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002443 break;
2444 case ABORTING:
2445 disconnect = 0;
2446 break;
2447 case CLOSING:
2448 __state_set(&ep->com, MORIBUND);
2449 disconnect = 0;
2450 break;
2451 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002452 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002453 if (ep->com.cm_id && ep->com.qp) {
2454 attrs.next_state = C4IW_QP_STATE_IDLE;
2455 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2456 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2457 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302458 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002459 __state_set(&ep->com, DEAD);
2460 release = 1;
2461 disconnect = 0;
2462 break;
2463 case DEAD:
2464 disconnect = 0;
2465 break;
2466 default:
2467 BUG_ON(1);
2468 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002469 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002470 if (disconnect)
2471 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2472 if (release)
2473 release_ep_resources(ep);
2474 return 0;
2475}
2476
Steve Wisecfdda9d2010-04-21 15:30:06 -07002477static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2478{
2479 struct cpl_abort_req_rss *req = cplhdr(skb);
2480 struct c4iw_ep *ep;
2481 struct cpl_abort_rpl *rpl;
2482 struct sk_buff *rpl_skb;
2483 struct c4iw_qp_attributes attrs;
2484 int ret;
2485 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002486 struct tid_info *t = dev->rdev.lldi.tids;
2487 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002488
2489 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302490 if (is_neg_adv(req->status)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002491 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2492 ep->hwtid);
2493 return 0;
2494 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002495 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2496 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002497 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002498
2499 /*
2500 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302501 * However, this is not needed if com state is just
2502 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002503 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302504 if (ep->com.state != MPA_REQ_SENT)
2505 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002506
2507 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002508 switch (ep->com.state) {
2509 case CONNECTING:
2510 break;
2511 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002512 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002513 break;
2514 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002515 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002516 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302517 connect_reply_upcall(ep, -ECONNRESET);
2518 else {
2519 /*
2520 * we just don't send notification upwards because we
2521 * want to retry with mpa_v1 without upper layers even
2522 * knowing it.
2523 *
2524 * do some housekeeping so as to re-initiate the
2525 * connection
2526 */
2527 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2528 mpa_rev);
2529 ep->retry_with_mpa_v1 = 1;
2530 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002531 break;
2532 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002533 break;
2534 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002535 break;
2536 case MORIBUND:
2537 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002538 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002539 /*FALLTHROUGH*/
2540 case FPDU_MODE:
2541 if (ep->com.cm_id && ep->com.qp) {
2542 attrs.next_state = C4IW_QP_STATE_ERROR;
2543 ret = c4iw_modify_qp(ep->com.qp->rhp,
2544 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2545 &attrs, 1);
2546 if (ret)
2547 printk(KERN_ERR MOD
2548 "%s - qp <- error failed!\n",
2549 __func__);
2550 }
2551 peer_abort_upcall(ep);
2552 break;
2553 case ABORTING:
2554 break;
2555 case DEAD:
2556 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002557 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002558 return 0;
2559 default:
2560 BUG_ON(1);
2561 break;
2562 }
2563 dst_confirm(ep->dst);
2564 if (ep->com.state != ABORTING) {
2565 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302566 /* we don't release if we want to retry with mpa_v1 */
2567 if (!ep->retry_with_mpa_v1)
2568 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002569 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002570 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002571
2572 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2573 if (!rpl_skb) {
2574 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2575 __func__);
2576 release = 1;
2577 goto out;
2578 }
2579 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2580 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2581 INIT_TP_WR(rpl, ep->hwtid);
2582 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2583 rpl->cmd = CPL_ABORT_NO_RST;
2584 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2585out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002586 if (release)
2587 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002588 else if (ep->retry_with_mpa_v1) {
2589 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302590 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2591 dst_release(ep->dst);
2592 cxgb4_l2t_release(ep->l2t);
2593 c4iw_reconnect(ep);
2594 }
2595
Steve Wisecfdda9d2010-04-21 15:30:06 -07002596 return 0;
2597}
2598
2599static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2600{
2601 struct c4iw_ep *ep;
2602 struct c4iw_qp_attributes attrs;
2603 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002604 int release = 0;
2605 struct tid_info *t = dev->rdev.lldi.tids;
2606 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002607
2608 ep = lookup_tid(t, tid);
2609
2610 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2611 BUG_ON(!ep);
2612
2613 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002614 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002615 switch (ep->com.state) {
2616 case CLOSING:
2617 __state_set(&ep->com, MORIBUND);
2618 break;
2619 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002620 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002621 if ((ep->com.cm_id) && (ep->com.qp)) {
2622 attrs.next_state = C4IW_QP_STATE_IDLE;
2623 c4iw_modify_qp(ep->com.qp->rhp,
2624 ep->com.qp,
2625 C4IW_QP_ATTR_NEXT_STATE,
2626 &attrs, 1);
2627 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302628 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002629 __state_set(&ep->com, DEAD);
2630 release = 1;
2631 break;
2632 case ABORTING:
2633 case DEAD:
2634 break;
2635 default:
2636 BUG_ON(1);
2637 break;
2638 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002639 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002640 if (release)
2641 release_ep_resources(ep);
2642 return 0;
2643}
2644
2645static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2646{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002647 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002648 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002649 unsigned int tid = GET_TID(rpl);
2650 struct c4iw_ep *ep;
2651 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002652
2653 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002654 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002655
Steve Wise30c95c22011-05-09 22:06:22 -07002656 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002657 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2658 ep->com.qp->wq.sq.qid);
2659 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2660 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2661 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2662 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002663 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002664
Steve Wisecfdda9d2010-04-21 15:30:06 -07002665 return 0;
2666}
2667
2668/*
2669 * Upcall from the adapter indicating data has been transmitted.
2670 * For us its just the single MPA request or reply. We can now free
2671 * the skb holding the mpa message.
2672 */
2673static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2674{
2675 struct c4iw_ep *ep;
2676 struct cpl_fw4_ack *hdr = cplhdr(skb);
2677 u8 credits = hdr->credits;
2678 unsigned int tid = GET_TID(hdr);
2679 struct tid_info *t = dev->rdev.lldi.tids;
2680
2681
2682 ep = lookup_tid(t, tid);
2683 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2684 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002685 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2686 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002687 return 0;
2688 }
2689
2690 dst_confirm(ep->dst);
2691 if (ep->mpa_skb) {
2692 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2693 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2694 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2695 kfree_skb(ep->mpa_skb);
2696 ep->mpa_skb = NULL;
2697 }
2698 return 0;
2699}
2700
Steve Wisecfdda9d2010-04-21 15:30:06 -07002701int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2702{
Steve Wisea7db89e2014-03-21 20:40:35 +05302703 int err = 0;
2704 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002705 struct c4iw_ep *ep = to_ep(cm_id);
2706 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2707
Steve Wisea7db89e2014-03-21 20:40:35 +05302708 mutex_lock(&ep->com.mutex);
2709 if (ep->com.state == DEAD) {
2710 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002711 c4iw_put_ep(&ep->com);
2712 return -ECONNRESET;
2713 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002714 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302715 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002716 if (mpa_rev == 0)
2717 abort_connection(ep, NULL, GFP_KERNEL);
2718 else {
2719 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302720 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002721 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302722 mutex_unlock(&ep->com.mutex);
2723 if (disconnect)
2724 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002725 c4iw_put_ep(&ep->com);
2726 return 0;
2727}
2728
2729int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2730{
2731 int err;
2732 struct c4iw_qp_attributes attrs;
2733 enum c4iw_qp_attr_mask mask;
2734 struct c4iw_ep *ep = to_ep(cm_id);
2735 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2736 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2737
2738 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302739
2740 mutex_lock(&ep->com.mutex);
2741 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002742 err = -ECONNRESET;
2743 goto err;
2744 }
2745
Steve Wisea7db89e2014-03-21 20:40:35 +05302746 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002747 BUG_ON(!qp);
2748
Vipul Pandya793dad92012-12-10 09:30:56 +00002749 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302750 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2751 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002752 abort_connection(ep, NULL, GFP_KERNEL);
2753 err = -EINVAL;
2754 goto err;
2755 }
2756
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302757 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2758 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302759 if (RELAXED_IRD_NEGOTIATION) {
2760 ep->ord = ep->ird;
2761 } else {
2762 ep->ird = conn_param->ird;
2763 ep->ord = conn_param->ord;
2764 send_mpa_reject(ep, conn_param->private_data,
2765 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302766 abort_connection(ep, NULL, GFP_KERNEL);
2767 err = -ENOMEM;
2768 goto err;
2769 }
2770 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302771 if (conn_param->ird < ep->ord) {
2772 if (RELAXED_IRD_NEGOTIATION &&
2773 ep->ord <= h->rdev.lldi.max_ordird_qp) {
2774 conn_param->ird = ep->ord;
2775 } else {
2776 abort_connection(ep, NULL, GFP_KERNEL);
2777 err = -ENOMEM;
2778 goto err;
2779 }
2780 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302781 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002782 ep->ird = conn_param->ird;
2783 ep->ord = conn_param->ord;
2784
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302785 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302786 if (peer2peer && ep->ird == 0)
2787 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302788 } else {
2789 if (peer2peer &&
2790 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
2791 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ord == 0)
2792 ep->ird = 1;
2793 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002794
2795 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2796
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302797 cm_id->add_ref(cm_id);
2798 ep->com.cm_id = cm_id;
2799 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00002800 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302801
Steve Wisecfdda9d2010-04-21 15:30:06 -07002802 /* bind QP to EP and move to RTS */
2803 attrs.mpa_attr = ep->mpa_attr;
2804 attrs.max_ird = ep->ird;
2805 attrs.max_ord = ep->ord;
2806 attrs.llp_stream_handle = ep;
2807 attrs.next_state = C4IW_QP_STATE_RTS;
2808
2809 /* bind QP and TID with INIT_WR */
2810 mask = C4IW_QP_ATTR_NEXT_STATE |
2811 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2812 C4IW_QP_ATTR_MPA_ATTR |
2813 C4IW_QP_ATTR_MAX_IRD |
2814 C4IW_QP_ATTR_MAX_ORD;
2815
2816 err = c4iw_modify_qp(ep->com.qp->rhp,
2817 ep->com.qp, mask, &attrs, 1);
2818 if (err)
2819 goto err1;
2820 err = send_mpa_reply(ep, conn_param->private_data,
2821 conn_param->private_data_len);
2822 if (err)
2823 goto err1;
2824
Steve Wisea7db89e2014-03-21 20:40:35 +05302825 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002826 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05302827 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002828 c4iw_put_ep(&ep->com);
2829 return 0;
2830err1:
2831 ep->com.cm_id = NULL;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302832 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002833 cm_id->rem_ref(cm_id);
2834err:
Steve Wisea7db89e2014-03-21 20:40:35 +05302835 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002836 c4iw_put_ep(&ep->com);
2837 return err;
2838}
2839
Vipul Pandya830662f2013-07-04 16:10:47 +05302840static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2841{
2842 struct in_device *ind;
2843 int found = 0;
2844 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2845 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
2846
2847 ind = in_dev_get(dev->rdev.lldi.ports[0]);
2848 if (!ind)
2849 return -EADDRNOTAVAIL;
2850 for_primary_ifa(ind) {
2851 laddr->sin_addr.s_addr = ifa->ifa_address;
2852 raddr->sin_addr.s_addr = ifa->ifa_address;
2853 found = 1;
2854 break;
2855 }
2856 endfor_ifa(ind);
2857 in_dev_put(ind);
2858 return found ? 0 : -EADDRNOTAVAIL;
2859}
2860
2861static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
2862 unsigned char banned_flags)
2863{
2864 struct inet6_dev *idev;
2865 int err = -EADDRNOTAVAIL;
2866
2867 rcu_read_lock();
2868 idev = __in6_dev_get(dev);
2869 if (idev != NULL) {
2870 struct inet6_ifaddr *ifp;
2871
2872 read_lock_bh(&idev->lock);
2873 list_for_each_entry(ifp, &idev->addr_list, if_list) {
2874 if (ifp->scope == IFA_LINK &&
2875 !(ifp->flags & banned_flags)) {
2876 memcpy(addr, &ifp->addr, 16);
2877 err = 0;
2878 break;
2879 }
2880 }
2881 read_unlock_bh(&idev->lock);
2882 }
2883 rcu_read_unlock();
2884 return err;
2885}
2886
2887static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2888{
2889 struct in6_addr uninitialized_var(addr);
2890 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2891 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
2892
2893 if (get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
2894 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
2895 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
2896 return 0;
2897 }
2898 return -EADDRNOTAVAIL;
2899}
2900
Steve Wisecfdda9d2010-04-21 15:30:06 -07002901int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2902{
Steve Wisecfdda9d2010-04-21 15:30:06 -07002903 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2904 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00002905 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05002906 struct sockaddr_in *laddr;
2907 struct sockaddr_in *raddr;
2908 struct sockaddr_in6 *laddr6;
2909 struct sockaddr_in6 *raddr6;
2910 struct iwpm_dev_data pm_reg_msg;
2911 struct iwpm_sa_data pm_msg;
Vipul Pandya830662f2013-07-04 16:10:47 +05302912 __u8 *ra;
2913 int iptype;
Steve Wise9eccfe12014-03-26 17:08:09 -05002914 int iwpm_err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002915
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302916 if ((conn_param->ord > cur_max_read_depth(dev)) ||
2917 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002918 err = -EINVAL;
2919 goto out;
2920 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002921 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2922 if (!ep) {
2923 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2924 err = -ENOMEM;
2925 goto out;
2926 }
2927 init_timer(&ep->timer);
2928 ep->plen = conn_param->private_data_len;
2929 if (ep->plen)
2930 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2931 conn_param->private_data, ep->plen);
2932 ep->ird = conn_param->ird;
2933 ep->ord = conn_param->ord;
2934
2935 if (peer2peer && ep->ord == 0)
2936 ep->ord = 1;
2937
2938 cm_id->add_ref(cm_id);
2939 ep->com.dev = dev;
2940 ep->com.cm_id = cm_id;
2941 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05302942 if (!ep->com.qp) {
2943 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
2944 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05002945 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05302946 }
Vipul Pandya325abea2013-01-07 13:11:53 +00002947 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002948 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2949 ep->com.qp, cm_id);
2950
2951 /*
2952 * Allocate an active TID to initiate a TCP connection.
2953 */
2954 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2955 if (ep->atid == -1) {
2956 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2957 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05002958 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002959 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002960 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002961
Steve Wise9eccfe12014-03-26 17:08:09 -05002962 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2963 sizeof(ep->com.local_addr));
2964 memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
2965 sizeof(ep->com.remote_addr));
2966
2967 /* No port mapper available, go with the specified peer information */
2968 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
2969 sizeof(ep->com.mapped_local_addr));
2970 memcpy(&ep->com.mapped_remote_addr, &cm_id->remote_addr,
2971 sizeof(ep->com.mapped_remote_addr));
2972
2973 c4iw_form_reg_msg(dev, &pm_reg_msg);
2974 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
2975 if (iwpm_err) {
2976 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
2977 __func__, iwpm_err);
2978 }
2979 if (iwpm_valid_pid() && !iwpm_err) {
2980 c4iw_form_pm_msg(ep, &pm_msg);
2981 iwpm_err = iwpm_add_and_query_mapping(&pm_msg, RDMA_NL_C4IW);
2982 if (iwpm_err)
2983 PDBG("%s: Port Mapper query fail (err = %d).\n",
2984 __func__, iwpm_err);
2985 else
2986 c4iw_record_pm_msg(ep, &pm_msg);
2987 }
2988 if (iwpm_create_mapinfo(&ep->com.local_addr,
2989 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
2990 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
2991 err = -ENOMEM;
2992 goto fail1;
2993 }
2994 print_addr(&ep->com, __func__, "add_query/create_mapinfo");
2995 set_bit(RELEASE_MAPINFO, &ep->com.flags);
2996
2997 laddr = (struct sockaddr_in *)&ep->com.mapped_local_addr;
2998 raddr = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
2999 laddr6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
3000 raddr6 = (struct sockaddr_in6 *) &ep->com.mapped_remote_addr;
3001
Vipul Pandya830662f2013-07-04 16:10:47 +05303002 if (cm_id->remote_addr.ss_family == AF_INET) {
3003 iptype = 4;
3004 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003005
Vipul Pandya830662f2013-07-04 16:10:47 +05303006 /*
3007 * Handle loopback requests to INADDR_ANY.
3008 */
3009 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3010 err = pick_local_ipaddrs(dev, cm_id);
3011 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003012 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303013 }
3014
3015 /* find a route */
3016 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3017 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3018 ra, ntohs(raddr->sin_port));
3019 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3020 raddr->sin_addr.s_addr, laddr->sin_port,
3021 raddr->sin_port, 0);
3022 } else {
3023 iptype = 6;
3024 ra = (__u8 *)&raddr6->sin6_addr;
3025
3026 /*
3027 * Handle loopback requests to INADDR_ANY.
3028 */
3029 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3030 err = pick_local_ip6addrs(dev, cm_id);
3031 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003032 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303033 }
3034
3035 /* find a route */
3036 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3037 __func__, laddr6->sin6_addr.s6_addr,
3038 ntohs(laddr6->sin6_port),
3039 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3040 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3041 raddr6->sin6_addr.s6_addr,
3042 laddr6->sin6_port, raddr6->sin6_port, 0,
3043 raddr6->sin6_scope_id);
3044 }
3045 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003046 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3047 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003048 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003049 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003050
Vipul Pandya830662f2013-07-04 16:10:47 +05303051 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true);
David Miller3786cf12011-12-02 16:52:31 +00003052 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003053 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003054 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003055 }
3056
3057 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3058 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3059 ep->l2t->idx);
3060
3061 state_set(&ep->com, CONNECTING);
3062 ep->tos = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003063
3064 /* send connect request to rnic */
3065 err = send_connect(ep);
3066 if (!err)
3067 goto out;
3068
3069 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003070fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003071 dst_release(ep->dst);
3072fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003073 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003074 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003075fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003076 cm_id->rem_ref(cm_id);
3077 c4iw_put_ep(&ep->com);
3078out:
3079 return err;
3080}
3081
Vipul Pandya830662f2013-07-04 16:10:47 +05303082static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3083{
3084 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003085 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
3086 &ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303087
3088 c4iw_init_wr_wait(&ep->com.wr_wait);
3089 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3090 ep->stid, &sin6->sin6_addr,
3091 sin6->sin6_port,
3092 ep->com.dev->rdev.lldi.rxq_ids[0]);
3093 if (!err)
3094 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3095 &ep->com.wr_wait,
3096 0, 0, __func__);
3097 if (err)
3098 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3099 err, ep->stid,
3100 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
3101 return err;
3102}
3103
3104static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3105{
3106 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003107 struct sockaddr_in *sin = (struct sockaddr_in *)
3108 &ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303109
3110 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3111 do {
3112 err = cxgb4_create_server_filter(
3113 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3114 sin->sin_addr.s_addr, sin->sin_port, 0,
3115 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3116 if (err == -EBUSY) {
3117 set_current_state(TASK_UNINTERRUPTIBLE);
3118 schedule_timeout(usecs_to_jiffies(100));
3119 }
3120 } while (err == -EBUSY);
3121 } else {
3122 c4iw_init_wr_wait(&ep->com.wr_wait);
3123 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3124 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3125 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3126 if (!err)
3127 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3128 &ep->com.wr_wait,
3129 0, 0, __func__);
3130 }
3131 if (err)
3132 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3133 , err, ep->stid,
3134 &sin->sin_addr, ntohs(sin->sin_port));
3135 return err;
3136}
3137
Steve Wisecfdda9d2010-04-21 15:30:06 -07003138int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3139{
3140 int err = 0;
3141 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3142 struct c4iw_listen_ep *ep;
Steve Wise9eccfe12014-03-26 17:08:09 -05003143 struct iwpm_dev_data pm_reg_msg;
3144 struct iwpm_sa_data pm_msg;
3145 int iwpm_err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003146
Steve Wisecfdda9d2010-04-21 15:30:06 -07003147 might_sleep();
3148
3149 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3150 if (!ep) {
3151 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3152 err = -ENOMEM;
3153 goto fail1;
3154 }
3155 PDBG("%s ep %p\n", __func__, ep);
3156 cm_id->add_ref(cm_id);
3157 ep->com.cm_id = cm_id;
3158 ep->com.dev = dev;
3159 ep->backlog = backlog;
Steve Wise24d44a32013-07-04 16:10:44 +05303160 memcpy(&ep->com.local_addr, &cm_id->local_addr,
3161 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003162
3163 /*
3164 * Allocate a server TID.
3165 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303166 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3167 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303168 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
3169 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003170 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303171 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
3172 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003173
Steve Wisecfdda9d2010-04-21 15:30:06 -07003174 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003175 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003176 err = -ENOMEM;
3177 goto fail2;
3178 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003179 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003180
3181 /* No port mapper available, go with the specified info */
3182 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3183 sizeof(ep->com.mapped_local_addr));
3184
3185 c4iw_form_reg_msg(dev, &pm_reg_msg);
3186 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3187 if (iwpm_err) {
3188 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3189 __func__, iwpm_err);
3190 }
3191 if (iwpm_valid_pid() && !iwpm_err) {
3192 memcpy(&pm_msg.loc_addr, &ep->com.local_addr,
3193 sizeof(ep->com.local_addr));
3194 iwpm_err = iwpm_add_mapping(&pm_msg, RDMA_NL_C4IW);
3195 if (iwpm_err)
3196 PDBG("%s: Port Mapper query fail (err = %d).\n",
3197 __func__, iwpm_err);
3198 else
3199 memcpy(&ep->com.mapped_local_addr,
3200 &pm_msg.mapped_loc_addr,
3201 sizeof(ep->com.mapped_local_addr));
3202 }
3203 if (iwpm_create_mapinfo(&ep->com.local_addr,
3204 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3205 err = -ENOMEM;
3206 goto fail3;
3207 }
3208 print_addr(&ep->com, __func__, "add_mapping/create_mapinfo");
3209
3210 set_bit(RELEASE_MAPINFO, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003211 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303212 if (ep->com.local_addr.ss_family == AF_INET)
3213 err = create_server4(dev, ep);
3214 else
3215 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003216 if (!err) {
3217 cm_id->provider_data = ep;
3218 goto out;
3219 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003220
3221fail3:
Vipul Pandya830662f2013-07-04 16:10:47 +05303222 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3223 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003224fail2:
3225 cm_id->rem_ref(cm_id);
3226 c4iw_put_ep(&ep->com);
3227fail1:
3228out:
3229 return err;
3230}
3231
3232int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3233{
3234 int err;
3235 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3236
3237 PDBG("%s ep %p\n", __func__, ep);
3238
3239 might_sleep();
3240 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303241 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3242 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003243 err = cxgb4_remove_server_filter(
3244 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3245 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3246 } else {
3247 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303248 err = cxgb4_remove_server(
3249 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3250 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003251 if (err)
3252 goto done;
3253 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3254 0, 0, __func__);
3255 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003256 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303257 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3258 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003259done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003260 cm_id->rem_ref(cm_id);
3261 c4iw_put_ep(&ep->com);
3262 return err;
3263}
3264
3265int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3266{
3267 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003268 int close = 0;
3269 int fatal = 0;
3270 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003271
Steve Wise2f5b48c2010-09-10 11:15:36 -05003272 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003273
3274 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3275 states[ep->com.state], abrupt);
3276
3277 rdev = &ep->com.dev->rdev;
3278 if (c4iw_fatal_error(rdev)) {
3279 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303280 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003281 ep->com.state = DEAD;
3282 }
3283 switch (ep->com.state) {
3284 case MPA_REQ_WAIT:
3285 case MPA_REQ_SENT:
3286 case MPA_REQ_RCVD:
3287 case MPA_REP_SENT:
3288 case FPDU_MODE:
3289 close = 1;
3290 if (abrupt)
3291 ep->com.state = ABORTING;
3292 else {
3293 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003294 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003295 }
3296 set_bit(CLOSE_SENT, &ep->com.flags);
3297 break;
3298 case CLOSING:
3299 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3300 close = 1;
3301 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003302 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003303 ep->com.state = ABORTING;
3304 } else
3305 ep->com.state = MORIBUND;
3306 }
3307 break;
3308 case MORIBUND:
3309 case ABORTING:
3310 case DEAD:
3311 PDBG("%s ignoring disconnect ep %p state %u\n",
3312 __func__, ep, ep->com.state);
3313 break;
3314 default:
3315 BUG();
3316 break;
3317 }
3318
Steve Wisecfdda9d2010-04-21 15:30:06 -07003319 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003320 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003321 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303322 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003323 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003324 } else {
3325 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003326 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003327 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003328 if (ret)
3329 fatal = 1;
3330 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003331 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003332 if (fatal)
3333 release_ep_resources(ep);
3334 return ret;
3335}
3336
Vipul Pandya1cab7752012-12-10 09:30:55 +00003337static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3338 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3339{
3340 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003341 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003342
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003343 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3344 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003345 if (!ep)
3346 return;
3347
3348 switch (req->retval) {
3349 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003350 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3351 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3352 send_fw_act_open_req(ep, atid);
3353 return;
3354 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003355 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003356 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3357 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3358 send_fw_act_open_req(ep, atid);
3359 return;
3360 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003361 break;
3362 default:
3363 pr_info("%s unexpected ofld conn wr retval %d\n",
3364 __func__, req->retval);
3365 break;
3366 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003367 pr_err("active ofld_connect_wr failure %d atid %d\n",
3368 req->retval, atid);
3369 mutex_lock(&dev->rdev.stats.lock);
3370 dev->rdev.stats.act_ofld_conn_fails++;
3371 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003372 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003373 state_set(&ep->com, DEAD);
3374 remove_handle(dev, &dev->atid_idr, atid);
3375 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3376 dst_release(ep->dst);
3377 cxgb4_l2t_release(ep->l2t);
3378 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003379}
3380
3381static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3382 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3383{
3384 struct sk_buff *rpl_skb;
3385 struct cpl_pass_accept_req *cpl;
3386 int ret;
3387
Paul Bolle710a3112013-02-05 20:51:30 +00003388 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003389 BUG_ON(!rpl_skb);
3390 if (req->retval) {
3391 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003392 mutex_lock(&dev->rdev.stats.lock);
3393 dev->rdev.stats.pas_ofld_conn_fails++;
3394 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003395 kfree_skb(rpl_skb);
3396 } else {
3397 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3398 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003399 (__force u32) htonl(
3400 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003401 ret = pass_accept_req(dev, rpl_skb);
3402 if (!ret)
3403 kfree_skb(rpl_skb);
3404 }
3405 return;
3406}
3407
3408static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003409{
3410 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003411 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3412
3413 switch (rpl->type) {
3414 case FW6_TYPE_CQE:
3415 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3416 break;
3417 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3418 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3419 switch (req->t_state) {
3420 case TCP_SYN_SENT:
3421 active_ofld_conn_reply(dev, skb, req);
3422 break;
3423 case TCP_SYN_RECV:
3424 passive_ofld_conn_reply(dev, skb, req);
3425 break;
3426 default:
3427 pr_err("%s unexpected ofld conn wr state %d\n",
3428 __func__, req->t_state);
3429 break;
3430 }
3431 break;
3432 }
3433 return 0;
3434}
3435
3436static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3437{
3438 u32 l2info;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003439 u16 vlantag, len, hdr_len, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003440 u8 intf;
3441 struct cpl_rx_pkt *cpl = cplhdr(skb);
3442 struct cpl_pass_accept_req *req;
3443 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003444 struct c4iw_dev *dev;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003445
Vipul Pandyaf079af72013-03-14 05:08:58 +00003446 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003447 /* Store values from cpl_rx_pkt in temporary location. */
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003448 vlantag = (__force u16) cpl->vlan;
3449 len = (__force u16) cpl->len;
3450 l2info = (__force u32) cpl->l2info;
3451 hdr_len = (__force u16) cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003452 intf = cpl->iff;
3453
3454 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3455
3456 /*
3457 * We need to parse the TCP options from SYN packet.
3458 * to generate cpl_pass_accept_req.
3459 */
3460 memset(&tmp_opt, 0, sizeof(tmp_opt));
3461 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003462 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003463
3464 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3465 memset(req, 0, sizeof(*req));
3466 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003467 V_SYN_MAC_IDX(G_RX_MACIDX(
3468 (__force int) htonl(l2info))) |
Vipul Pandya1cab7752012-12-10 09:30:55 +00003469 F_SYN_XACT_MATCH);
Vipul Pandyaf079af72013-03-14 05:08:58 +00003470 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3471 G_RX_ETHHDR_LEN((__force int) htonl(l2info)) :
3472 G_RX_T5_ETHHDR_LEN((__force int) htonl(l2info));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003473 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(
3474 (__force int) htonl(l2info))) |
3475 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(
3476 (__force int) htons(hdr_len))) |
3477 V_IP_HDR_LEN(G_RX_IPHDR_LEN(
3478 (__force int) htons(hdr_len))) |
Vipul Pandyaf079af72013-03-14 05:08:58 +00003479 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(eth_hdr_len)));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003480 req->vlan = (__force __be16) vlantag;
3481 req->len = (__force __be16) len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003482 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
3483 PASS_OPEN_TOS(tos));
3484 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3485 if (tmp_opt.wscale_ok)
3486 req->tcpopt.wsf = tmp_opt.snd_wscale;
3487 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3488 if (tmp_opt.sack_ok)
3489 req->tcpopt.sack = 1;
3490 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3491 return;
3492}
3493
3494static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3495 __be32 laddr, __be16 lport,
3496 __be32 raddr, __be16 rport,
3497 u32 rcv_isn, u32 filter, u16 window,
3498 u32 rss_qid, u8 port_id)
3499{
3500 struct sk_buff *req_skb;
3501 struct fw_ofld_connection_wr *req;
3502 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303503 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003504
3505 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3506 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3507 memset(req, 0, sizeof(*req));
3508 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
3509 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
3510 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003511 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003512 req->le.lport = lport;
3513 req->le.pport = rport;
3514 req->le.u.ipv4.lip = laddr;
3515 req->le.u.ipv4.pip = raddr;
3516 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3517 req->tcb.rcv_adv = htons(window);
3518 req->tcb.t_state_to_astid =
3519 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
3520 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
3521 V_FW_OFLD_CONNECTION_WR_ASTID(
3522 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
3523
3524 /*
3525 * We store the qid in opt2 which will be used by the firmware
3526 * to send us the wr response.
3527 */
3528 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
3529
3530 /*
3531 * We initialize the MSS index in TCB to 0xF.
3532 * So that when driver sends cpl_pass_accept_rpl
3533 * TCB picks up the correct value. If this was 0
3534 * TP will ignore any value > 0 for MSS index.
3535 */
3536 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
Paul Bolle710a3112013-02-05 20:51:30 +00003537 req->cookie = (unsigned long)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003538
3539 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303540 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3541 if (ret < 0) {
3542 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3543 ret);
3544 kfree_skb(skb);
3545 kfree_skb(req_skb);
3546 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003547}
3548
3549/*
3550 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3551 * messages when a filter is being used instead of server to
3552 * redirect a syn packet. When packets hit filter they are redirected
3553 * to the offload queue and driver tries to establish the connection
3554 * using firmware work request.
3555 */
3556static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3557{
3558 int stid;
3559 unsigned int filter;
3560 struct ethhdr *eh = NULL;
3561 struct vlan_ethhdr *vlan_eh = NULL;
3562 struct iphdr *iph;
3563 struct tcphdr *tcph;
3564 struct rss_header *rss = (void *)skb->data;
3565 struct cpl_rx_pkt *cpl = (void *)skb->data;
3566 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3567 struct l2t_entry *e;
3568 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003569 struct c4iw_ep *lep;
3570 u16 window;
3571 struct port_info *pi;
3572 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003573 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003574 int step;
3575 u32 tx_chan;
3576 struct neighbour *neigh;
3577
3578 /* Drop all non-SYN packets */
3579 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
3580 goto reject;
3581
3582 /*
3583 * Drop all packets which did not hit the filter.
3584 * Unlikely to happen.
3585 */
3586 if (!(rss->filter_hit && rss->filter_tid))
3587 goto reject;
3588
3589 /*
3590 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3591 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303592 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003593
3594 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3595 if (!lep) {
3596 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3597 goto reject;
3598 }
3599
Vipul Pandyaf079af72013-03-14 05:08:58 +00003600 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3601 G_RX_ETHHDR_LEN(htonl(cpl->l2info)) :
3602 G_RX_T5_ETHHDR_LEN(htonl(cpl->l2info));
3603 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003604 eh = (struct ethhdr *)(req + 1);
3605 iph = (struct iphdr *)(eh + 1);
3606 } else {
3607 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3608 iph = (struct iphdr *)(vlan_eh + 1);
3609 skb->vlan_tci = ntohs(cpl->vlan);
3610 }
3611
3612 if (iph->version != 0x4)
3613 goto reject;
3614
3615 tcph = (struct tcphdr *)(iph + 1);
3616 skb_set_network_header(skb, (void *)iph - (void *)rss);
3617 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3618 skb_get(skb);
3619
3620 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3621 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3622 ntohs(tcph->source), iph->tos);
3623
Vipul Pandya830662f2013-07-04 16:10:47 +05303624 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3625 iph->tos);
3626 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003627 pr_err("%s - failed to find dst entry!\n",
3628 __func__);
3629 goto reject;
3630 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003631 neigh = dst_neigh_lookup_skb(dst, skb);
3632
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003633 if (!neigh) {
3634 pr_err("%s - failed to allocate neigh!\n",
3635 __func__);
3636 goto free_dst;
3637 }
3638
Vipul Pandya1cab7752012-12-10 09:30:55 +00003639 if (neigh->dev->flags & IFF_LOOPBACK) {
3640 pdev = ip_dev_find(&init_net, iph->daddr);
3641 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3642 pdev, 0);
3643 pi = (struct port_info *)netdev_priv(pdev);
3644 tx_chan = cxgb4_port_chan(pdev);
3645 dev_put(pdev);
3646 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303647 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003648 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303649 pdev, 0);
3650 pi = (struct port_info *)netdev_priv(pdev);
3651 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003652 }
Steve Wiseebf00062014-03-19 17:44:40 +05303653 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003654 if (!e) {
3655 pr_err("%s - failed to allocate l2t entry!\n",
3656 __func__);
3657 goto free_dst;
3658 }
3659
3660 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3661 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003662 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003663
3664 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303665 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3666 dev->rdev.lldi.ports[0],
3667 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003668
3669 /*
3670 * Synthesize the cpl_pass_accept_req. We have everything except the
3671 * TID. Once firmware sends a reply with TID we update the TID field
3672 * in cpl and pass it through the regular cpl_pass_accept_req path.
3673 */
3674 build_cpl_pass_accept_req(skb, stid, iph->tos);
3675 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3676 tcph->source, ntohl(tcph->seq), filter, window,
3677 rss_qid, pi->port_id);
3678 cxgb4_l2t_release(e);
3679free_dst:
3680 dst_release(dst);
3681reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003682 return 0;
3683}
3684
Steve Wisecfdda9d2010-04-21 15:30:06 -07003685/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003686 * These are the real handlers that are called from a
3687 * work queue.
3688 */
3689static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3690 [CPL_ACT_ESTABLISH] = act_establish,
3691 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3692 [CPL_RX_DATA] = rx_data,
3693 [CPL_ABORT_RPL_RSS] = abort_rpl,
3694 [CPL_ABORT_RPL] = abort_rpl,
3695 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3696 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3697 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3698 [CPL_PASS_ESTABLISH] = pass_establish,
3699 [CPL_PEER_CLOSE] = peer_close,
3700 [CPL_ABORT_REQ_RSS] = peer_abort,
3701 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3702 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003703 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003704 [CPL_FW6_MSG] = deferred_fw6_msg,
3705 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003706};
3707
3708static void process_timeout(struct c4iw_ep *ep)
3709{
3710 struct c4iw_qp_attributes attrs;
3711 int abort = 1;
3712
Steve Wise2f5b48c2010-09-10 11:15:36 -05003713 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003714 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3715 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003716 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003717 switch (ep->com.state) {
3718 case MPA_REQ_SENT:
3719 __state_set(&ep->com, ABORTING);
3720 connect_reply_upcall(ep, -ETIMEDOUT);
3721 break;
3722 case MPA_REQ_WAIT:
3723 __state_set(&ep->com, ABORTING);
3724 break;
3725 case CLOSING:
3726 case MORIBUND:
3727 if (ep->com.cm_id && ep->com.qp) {
3728 attrs.next_state = C4IW_QP_STATE_ERROR;
3729 c4iw_modify_qp(ep->com.qp->rhp,
3730 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3731 &attrs, 1);
3732 }
3733 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303734 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003735 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003736 case ABORTING:
3737 case DEAD:
3738
3739 /*
3740 * These states are expected if the ep timed out at the same
3741 * time as another thread was calling stop_ep_timer().
3742 * So we silently do nothing for these states.
3743 */
3744 abort = 0;
3745 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003746 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003747 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003748 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003749 abort = 0;
3750 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003751 if (abort)
3752 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecc18b932014-04-24 14:31:53 -05003753 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003754 c4iw_put_ep(&ep->com);
3755}
3756
3757static void process_timedout_eps(void)
3758{
3759 struct c4iw_ep *ep;
3760
3761 spin_lock_irq(&timeout_lock);
3762 while (!list_empty(&timeout_list)) {
3763 struct list_head *tmp;
3764
3765 tmp = timeout_list.next;
3766 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003767 tmp->next = NULL;
3768 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003769 spin_unlock_irq(&timeout_lock);
3770 ep = list_entry(tmp, struct c4iw_ep, entry);
3771 process_timeout(ep);
3772 spin_lock_irq(&timeout_lock);
3773 }
3774 spin_unlock_irq(&timeout_lock);
3775}
3776
3777static void process_work(struct work_struct *work)
3778{
3779 struct sk_buff *skb = NULL;
3780 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003781 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003782 unsigned int opcode;
3783 int ret;
3784
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003785 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003786 while ((skb = skb_dequeue(&rxq))) {
3787 rpl = cplhdr(skb);
3788 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3789 opcode = rpl->ot.opcode;
3790
3791 BUG_ON(!work_handlers[opcode]);
3792 ret = work_handlers[opcode](dev, skb);
3793 if (!ret)
3794 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003795 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003796 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003797}
3798
3799static DECLARE_WORK(skb_work, process_work);
3800
3801static void ep_timeout(unsigned long arg)
3802{
3803 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003804 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003805
3806 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003807 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003808 /*
3809 * Only insert if it is not already on the list.
3810 */
3811 if (!ep->entry.next) {
3812 list_add_tail(&ep->entry, &timeout_list);
3813 kickit = 1;
3814 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003815 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003816 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003817 if (kickit)
3818 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003819}
3820
3821/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07003822 * All the CM events are handled on a work queue to have a safe context.
3823 */
3824static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3825{
3826
3827 /*
3828 * Save dev in the skb->cb area.
3829 */
3830 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3831
3832 /*
3833 * Queue the skb and schedule the worker thread.
3834 */
3835 skb_queue_tail(&rxq, skb);
3836 queue_work(workq, &skb_work);
3837 return 0;
3838}
3839
3840static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3841{
3842 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3843
3844 if (rpl->status != CPL_ERR_NONE) {
3845 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3846 "for tid %u\n", rpl->status, GET_TID(rpl));
3847 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003848 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003849 return 0;
3850}
3851
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003852static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3853{
3854 struct cpl_fw6_msg *rpl = cplhdr(skb);
3855 struct c4iw_wr_wait *wr_waitp;
3856 int ret;
3857
3858 PDBG("%s type %u\n", __func__, rpl->type);
3859
3860 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003861 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003862 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07003863 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003864 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07003865 if (wr_waitp)
3866 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003867 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003868 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003869 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003870 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00003871 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003872 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003873 default:
3874 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3875 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003876 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003877 break;
3878 }
3879 return 0;
3880}
3881
Steve Wise8da7e7a2011-06-14 20:59:27 +00003882static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3883{
3884 struct cpl_abort_req_rss *req = cplhdr(skb);
3885 struct c4iw_ep *ep;
3886 struct tid_info *t = dev->rdev.lldi.tids;
3887 unsigned int tid = GET_TID(req);
3888
3889 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05003890 if (!ep) {
3891 printk(KERN_WARNING MOD
3892 "Abort on non-existent endpoint, tid %d\n", tid);
3893 kfree_skb(skb);
3894 return 0;
3895 }
Steve Wise7a2cea22014-03-14 21:52:07 +05303896 if (is_neg_adv(req->status)) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003897 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3898 ep->hwtid);
3899 kfree_skb(skb);
3900 return 0;
3901 }
3902 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3903 ep->com.state);
3904
3905 /*
3906 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003907 * However, if we are on MPAv2 and want to retry with MPAv1
3908 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00003909 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003910 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
3911 if (ep->com.state != MPA_REQ_SENT)
3912 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3913 } else
3914 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003915 sched(dev, skb);
3916 return 0;
3917}
3918
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003919/*
3920 * Most upcalls from the T4 Core go to sched() to
3921 * schedule the processing on a work queue.
3922 */
3923c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3924 [CPL_ACT_ESTABLISH] = sched,
3925 [CPL_ACT_OPEN_RPL] = sched,
3926 [CPL_RX_DATA] = sched,
3927 [CPL_ABORT_RPL_RSS] = sched,
3928 [CPL_ABORT_RPL] = sched,
3929 [CPL_PASS_OPEN_RPL] = sched,
3930 [CPL_CLOSE_LISTSRV_RPL] = sched,
3931 [CPL_PASS_ACCEPT_REQ] = sched,
3932 [CPL_PASS_ESTABLISH] = sched,
3933 [CPL_PEER_CLOSE] = sched,
3934 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00003935 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003936 [CPL_RDMA_TERMINATE] = sched,
3937 [CPL_FW4_ACK] = sched,
3938 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003939 [CPL_FW6_MSG] = fw6_msg,
3940 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003941};
3942
Steve Wisecfdda9d2010-04-21 15:30:06 -07003943int __init c4iw_cm_init(void)
3944{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003945 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003946 skb_queue_head_init(&rxq);
3947
3948 workq = create_singlethread_workqueue("iw_cxgb4");
3949 if (!workq)
3950 return -ENOMEM;
3951
Steve Wisecfdda9d2010-04-21 15:30:06 -07003952 return 0;
3953}
3954
3955void __exit c4iw_cm_term(void)
3956{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003957 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003958 flush_workqueue(workq);
3959 destroy_workqueue(workq);
3960}