blob: 28114e6b02e96bda7cf503e8e74a73fde19399d0 [file] [log] [blame]
Steve Wisecfdda9d2010-04-21 15:30:06 -07001/*
2 * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
3 *
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
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070082int c4iw_max_read_depth = 8;
83module_param(c4iw_max_read_depth, int, 0644);
84MODULE_PARM_DESC(c4iw_max_read_depth, "Per-connection max ORD/IRD (default=8)");
85
Steve Wisecfdda9d2010-04-21 15:30:06 -070086static int enable_tcp_timestamps;
87module_param(enable_tcp_timestamps, int, 0644);
88MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
89
90static int enable_tcp_sack;
91module_param(enable_tcp_sack, int, 0644);
92MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
93
94static int enable_tcp_window_scaling = 1;
95module_param(enable_tcp_window_scaling, int, 0644);
96MODULE_PARM_DESC(enable_tcp_window_scaling,
97 "Enable tcp window scaling (default=1)");
98
99int c4iw_debug;
100module_param(c4iw_debug, int, 0644);
101MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
102
Steve Wisedf2d5132014-03-19 17:44:44 +0530103static int peer2peer = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700104module_param(peer2peer, int, 0644);
Steve Wisedf2d5132014-03-19 17:44:44 +0530105MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700106
107static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
108module_param(p2p_type, int, 0644);
109MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
110 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
111
112static int ep_timeout_secs = 60;
113module_param(ep_timeout_secs, int, 0644);
114MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
115 "in seconds (default=60)");
116
117static int mpa_rev = 1;
118module_param(mpa_rev, int, 0644);
119MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530120 "1 is RFC0544 spec compliant, 2 is IETF MPA Peer Connect Draft"
121 " compliant (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700122
123static int markers_enabled;
124module_param(markers_enabled, int, 0644);
125MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
126
127static int crc_enabled = 1;
128module_param(crc_enabled, int, 0644);
129MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
130
131static int rcv_win = 256 * 1024;
132module_param(rcv_win, int, 0644);
133MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
134
Steve Wise98ae68b2010-09-10 11:15:41 -0500135static int snd_win = 128 * 1024;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700136module_param(snd_win, int, 0644);
Steve Wise98ae68b2010-09-10 11:15:41 -0500137MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700138
Steve Wisecfdda9d2010-04-21 15:30:06 -0700139static struct workqueue_struct *workq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700140
141static struct sk_buff_head rxq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700142
143static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
144static void ep_timeout(unsigned long arg);
145static void connect_reply_upcall(struct c4iw_ep *ep, int status);
146
Roland Dreierbe4c9ba2010-05-05 14:45:40 -0700147static LIST_HEAD(timeout_list);
148static spinlock_t timeout_lock;
149
Vipul Pandya325abea2013-01-07 13:11:53 +0000150static void deref_qp(struct c4iw_ep *ep)
151{
152 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
153 clear_bit(QP_REFERENCED, &ep->com.flags);
154}
155
156static void ref_qp(struct c4iw_ep *ep)
157{
158 set_bit(QP_REFERENCED, &ep->com.flags);
159 c4iw_qp_add_ref(&ep->com.qp->ibqp);
160}
161
Steve Wisecfdda9d2010-04-21 15:30:06 -0700162static void start_ep_timer(struct c4iw_ep *ep)
163{
164 PDBG("%s ep %p\n", __func__, ep);
165 if (timer_pending(&ep->timer)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000166 pr_err("%s timer already started! ep %p\n",
167 __func__, ep);
168 return;
169 }
170 clear_bit(TIMEOUT, &ep->com.flags);
171 c4iw_get_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700172 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
173 ep->timer.data = (unsigned long)ep;
174 ep->timer.function = ep_timeout;
175 add_timer(&ep->timer);
176}
177
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500178static int stop_ep_timer(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700179{
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000180 PDBG("%s ep %p stopping\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700181 del_timer_sync(&ep->timer);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500182 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000183 c4iw_put_ep(&ep->com);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500184 return 0;
185 }
186 return 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700187}
188
189static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
190 struct l2t_entry *l2e)
191{
192 int error = 0;
193
194 if (c4iw_fatal_error(rdev)) {
195 kfree_skb(skb);
196 PDBG("%s - device in error state - dropping\n", __func__);
197 return -EIO;
198 }
199 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
200 if (error < 0)
201 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500202 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700203}
204
205int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
206{
207 int error = 0;
208
209 if (c4iw_fatal_error(rdev)) {
210 kfree_skb(skb);
211 PDBG("%s - device in error state - dropping\n", __func__);
212 return -EIO;
213 }
214 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
215 if (error < 0)
216 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500217 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700218}
219
220static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
221{
222 struct cpl_tid_release *req;
223
224 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
225 if (!skb)
226 return;
227 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
228 INIT_TP_WR(req, hwtid);
229 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
230 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
231 c4iw_ofld_send(rdev, skb);
232 return;
233}
234
235static void set_emss(struct c4iw_ep *ep, u16 opt)
236{
237 ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
238 ep->mss = ep->emss;
239 if (GET_TCPOPT_TSTAMP(opt))
240 ep->emss -= 12;
241 if (ep->emss < 128)
242 ep->emss = 128;
243 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
244 ep->mss, ep->emss);
245}
246
247static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
248{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700249 enum c4iw_ep_state state;
250
Steve Wise2f5b48c2010-09-10 11:15:36 -0500251 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700252 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500253 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700254 return state;
255}
256
257static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
258{
259 epc->state = new;
260}
261
262static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
263{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500264 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700265 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
266 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500267 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700268 return;
269}
270
271static void *alloc_ep(int size, gfp_t gfp)
272{
273 struct c4iw_ep_common *epc;
274
275 epc = kzalloc(size, gfp);
276 if (epc) {
277 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500278 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500279 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700280 }
281 PDBG("%s alloc ep %p\n", __func__, epc);
282 return epc;
283}
284
285void _c4iw_free_ep(struct kref *kref)
286{
287 struct c4iw_ep *ep;
288
289 ep = container_of(kref, struct c4iw_ep, com.kref);
290 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000291 if (test_bit(QP_REFERENCED, &ep->com.flags))
292 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700293 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000294 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700295 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
296 dst_release(ep->dst);
297 cxgb4_l2t_release(ep->l2t);
298 }
299 kfree(ep);
300}
301
302static void release_ep_resources(struct c4iw_ep *ep)
303{
304 set_bit(RELEASE_RESOURCES, &ep->com.flags);
305 c4iw_put_ep(&ep->com);
306}
307
Steve Wisecfdda9d2010-04-21 15:30:06 -0700308static int status2errno(int status)
309{
310 switch (status) {
311 case CPL_ERR_NONE:
312 return 0;
313 case CPL_ERR_CONN_RESET:
314 return -ECONNRESET;
315 case CPL_ERR_ARP_MISS:
316 return -EHOSTUNREACH;
317 case CPL_ERR_CONN_TIMEDOUT:
318 return -ETIMEDOUT;
319 case CPL_ERR_TCAM_FULL:
320 return -ENOMEM;
321 case CPL_ERR_CONN_EXIST:
322 return -EADDRINUSE;
323 default:
324 return -EIO;
325 }
326}
327
328/*
329 * Try and reuse skbs already allocated...
330 */
331static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
332{
333 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
334 skb_trim(skb, 0);
335 skb_get(skb);
336 skb_reset_transport_header(skb);
337 } else {
338 skb = alloc_skb(len, gfp);
339 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530340 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700341 return skb;
342}
343
Vipul Pandya830662f2013-07-04 16:10:47 +0530344static struct net_device *get_real_dev(struct net_device *egress_dev)
345{
Steve Wise11b8e222014-05-16 12:42:46 -0500346 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530347}
348
349static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
350{
351 int i;
352
353 egress_dev = get_real_dev(egress_dev);
354 for (i = 0; i < dev->rdev.lldi.nports; i++)
355 if (dev->rdev.lldi.ports[i] == egress_dev)
356 return 1;
357 return 0;
358}
359
360static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
361 __u8 *peer_ip, __be16 local_port,
362 __be16 peer_port, u8 tos,
363 __u32 sin6_scope_id)
364{
365 struct dst_entry *dst = NULL;
366
367 if (IS_ENABLED(CONFIG_IPV6)) {
368 struct flowi6 fl6;
369
370 memset(&fl6, 0, sizeof(fl6));
371 memcpy(&fl6.daddr, peer_ip, 16);
372 memcpy(&fl6.saddr, local_ip, 16);
373 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
374 fl6.flowi6_oif = sin6_scope_id;
375 dst = ip6_route_output(&init_net, NULL, &fl6);
376 if (!dst)
377 goto out;
378 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
379 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
380 dst_release(dst);
381 dst = NULL;
382 }
383 }
384
385out:
386 return dst;
387}
388
389static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700390 __be32 peer_ip, __be16 local_port,
391 __be16 peer_port, u8 tos)
392{
393 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700394 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530395 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700396
David S. Miller31e4543d2011-05-03 20:25:42 -0700397 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500398 peer_port, local_port, IPPROTO_TCP,
399 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800400 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700401 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530402 n = dst_neigh_lookup(&rt->dst, &peer_ip);
403 if (!n)
404 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530405 if (!our_interface(dev, n->dev) &&
406 !(n->dev->flags & IFF_LOOPBACK)) {
Vipul Pandya830662f2013-07-04 16:10:47 +0530407 dst_release(&rt->dst);
408 return NULL;
409 }
410 neigh_release(n);
411 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700412}
413
414static void arp_failure_discard(void *handle, struct sk_buff *skb)
415{
416 PDBG("%s c4iw_dev %p\n", __func__, handle);
417 kfree_skb(skb);
418}
419
420/*
421 * Handle an ARP failure for an active open.
422 */
423static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
424{
425 printk(KERN_ERR MOD "ARP failure duing connect\n");
426 kfree_skb(skb);
427}
428
429/*
430 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
431 * and send it along.
432 */
433static void abort_arp_failure(void *handle, struct sk_buff *skb)
434{
435 struct c4iw_rdev *rdev = handle;
436 struct cpl_abort_req *req = cplhdr(skb);
437
438 PDBG("%s rdev %p\n", __func__, rdev);
439 req->cmd = CPL_ABORT_NO_RST;
440 c4iw_ofld_send(rdev, skb);
441}
442
443static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
444{
445 unsigned int flowclen = 80;
446 struct fw_flowc_wr *flowc;
447 int i;
448
449 skb = get_skb(skb, flowclen, GFP_KERNEL);
450 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
451
452 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
453 FW_FLOWC_WR_NPARAMS(8));
454 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
455 16)) | FW_WR_FLOWID(ep->hwtid));
456
457 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Steve Wise94788652011-01-21 17:00:34 +0000458 flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700459 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
460 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
461 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
462 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
463 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
464 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
465 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
466 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
467 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
468 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
469 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
470 flowc->mnemval[6].val = cpu_to_be32(snd_win);
471 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
472 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
473 /* Pad WR to 16 byte boundary */
474 flowc->mnemval[8].mnemonic = 0;
475 flowc->mnemval[8].val = 0;
476 for (i = 0; i < 9; i++) {
477 flowc->mnemval[i].r4[0] = 0;
478 flowc->mnemval[i].r4[1] = 0;
479 flowc->mnemval[i].r4[2] = 0;
480 }
481
482 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
483 c4iw_ofld_send(&ep->com.dev->rdev, skb);
484}
485
486static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
487{
488 struct cpl_close_con_req *req;
489 struct sk_buff *skb;
490 int wrlen = roundup(sizeof *req, 16);
491
492 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
493 skb = get_skb(NULL, wrlen, gfp);
494 if (!skb) {
495 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
496 return -ENOMEM;
497 }
498 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
499 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
500 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
501 memset(req, 0, wrlen);
502 INIT_TP_WR(req, ep->hwtid);
503 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
504 ep->hwtid));
505 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
506}
507
508static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
509{
510 struct cpl_abort_req *req;
511 int wrlen = roundup(sizeof *req, 16);
512
513 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
514 skb = get_skb(skb, wrlen, gfp);
515 if (!skb) {
516 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
517 __func__);
518 return -ENOMEM;
519 }
520 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
521 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
522 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
523 memset(req, 0, wrlen);
524 INIT_TP_WR(req, ep->hwtid);
525 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
526 req->cmd = CPL_ABORT_SEND_RST;
527 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
528}
529
530static int send_connect(struct c4iw_ep *ep)
531{
532 struct cpl_act_open_req *req;
Vipul Pandyaf079af72013-03-14 05:08:58 +0000533 struct cpl_t5_act_open_req *t5_req;
Vipul Pandya830662f2013-07-04 16:10:47 +0530534 struct cpl_act_open_req6 *req6;
535 struct cpl_t5_act_open_req6 *t5_req6;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700536 struct sk_buff *skb;
537 u64 opt0;
538 u32 opt2;
539 unsigned int mtu_idx;
540 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +0530541 int wrlen;
542 int sizev4 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
543 sizeof(struct cpl_act_open_req) :
544 sizeof(struct cpl_t5_act_open_req);
545 int sizev6 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
546 sizeof(struct cpl_act_open_req6) :
547 sizeof(struct cpl_t5_act_open_req6);
548 struct sockaddr_in *la = (struct sockaddr_in *)&ep->com.local_addr;
549 struct sockaddr_in *ra = (struct sockaddr_in *)&ep->com.remote_addr;
550 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
551 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
552
553 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
554 roundup(sizev4, 16) :
555 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700556
557 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
558
559 skb = get_skb(NULL, wrlen, GFP_KERNEL);
560 if (!skb) {
561 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
562 __func__);
563 return -ENOMEM;
564 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000565 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700566
567 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
568 wscale = compute_wscale(rcv_win);
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000569 opt0 = (nocong ? NO_CONG(1) : 0) |
570 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +0000571 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700572 WND_SCALE(wscale) |
573 MSS_IDX(mtu_idx) |
574 L2T_IDX(ep->l2t->idx) |
575 TX_CHAN(ep->tx_chan) |
576 SMAC_SEL(ep->smac_idx) |
577 DSCP(ep->tos) |
Steve Wiseb48f3b92011-03-11 22:30:21 +0000578 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700579 RCV_BUFSIZ(rcv_win>>10);
580 opt2 = RX_CHANNEL(0) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000581 CCTRL_ECN(enable_ecn) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700582 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
583 if (enable_tcp_timestamps)
584 opt2 |= TSTAMPS_EN(1);
585 if (enable_tcp_sack)
586 opt2 |= SACK_EN(1);
587 if (wscale && enable_tcp_window_scaling)
588 opt2 |= WND_SCALE_EN(1);
Steve Wise92e50112014-04-24 14:31:59 -0500589 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
590 opt2 |= T5_OPT_2_VALID;
591 opt2 |= V_CONG_CNTRL(CONG_ALG_TAHOE);
592 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700593 t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
594
Vipul Pandyaf079af72013-03-14 05:08:58 +0000595 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Vipul Pandya830662f2013-07-04 16:10:47 +0530596 if (ep->com.remote_addr.ss_family == AF_INET) {
597 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
598 INIT_TP_WR(req, 0);
599 OPCODE_TID(req) = cpu_to_be32(
Vipul Pandyaf079af72013-03-14 05:08:58 +0000600 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
601 ((ep->rss_qid << 14) | ep->atid)));
Vipul Pandya830662f2013-07-04 16:10:47 +0530602 req->local_port = la->sin_port;
603 req->peer_port = ra->sin_port;
604 req->local_ip = la->sin_addr.s_addr;
605 req->peer_ip = ra->sin_addr.s_addr;
606 req->opt0 = cpu_to_be64(opt0);
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530607 req->params = cpu_to_be32(cxgb4_select_ntuple(
608 ep->com.dev->rdev.lldi.ports[0],
609 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530610 req->opt2 = cpu_to_be32(opt2);
611 } else {
612 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
613
614 INIT_TP_WR(req6, 0);
615 OPCODE_TID(req6) = cpu_to_be32(
616 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
617 ((ep->rss_qid<<14)|ep->atid)));
618 req6->local_port = la6->sin6_port;
619 req6->peer_port = ra6->sin6_port;
620 req6->local_ip_hi = *((__be64 *)
621 (la6->sin6_addr.s6_addr));
622 req6->local_ip_lo = *((__be64 *)
623 (la6->sin6_addr.s6_addr + 8));
624 req6->peer_ip_hi = *((__be64 *)
625 (ra6->sin6_addr.s6_addr));
626 req6->peer_ip_lo = *((__be64 *)
627 (ra6->sin6_addr.s6_addr + 8));
628 req6->opt0 = cpu_to_be64(opt0);
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530629 req6->params = cpu_to_be32(cxgb4_select_ntuple(
630 ep->com.dev->rdev.lldi.ports[0],
631 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530632 req6->opt2 = cpu_to_be32(opt2);
633 }
634 } else {
635 if (ep->com.remote_addr.ss_family == AF_INET) {
636 t5_req = (struct cpl_t5_act_open_req *)
637 skb_put(skb, wrlen);
638 INIT_TP_WR(t5_req, 0);
639 OPCODE_TID(t5_req) = cpu_to_be32(
640 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
641 ((ep->rss_qid << 14) | ep->atid)));
642 t5_req->local_port = la->sin_port;
643 t5_req->peer_port = ra->sin_port;
644 t5_req->local_ip = la->sin_addr.s_addr;
645 t5_req->peer_ip = ra->sin_addr.s_addr;
646 t5_req->opt0 = cpu_to_be64(opt0);
647 t5_req->params = cpu_to_be64(V_FILTER_TUPLE(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530648 cxgb4_select_ntuple(
649 ep->com.dev->rdev.lldi.ports[0],
650 ep->l2t)));
Vipul Pandya830662f2013-07-04 16:10:47 +0530651 t5_req->opt2 = cpu_to_be32(opt2);
652 } else {
653 t5_req6 = (struct cpl_t5_act_open_req6 *)
654 skb_put(skb, wrlen);
655 INIT_TP_WR(t5_req6, 0);
656 OPCODE_TID(t5_req6) = cpu_to_be32(
657 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
658 ((ep->rss_qid<<14)|ep->atid)));
659 t5_req6->local_port = la6->sin6_port;
660 t5_req6->peer_port = ra6->sin6_port;
661 t5_req6->local_ip_hi = *((__be64 *)
662 (la6->sin6_addr.s6_addr));
663 t5_req6->local_ip_lo = *((__be64 *)
664 (la6->sin6_addr.s6_addr + 8));
665 t5_req6->peer_ip_hi = *((__be64 *)
666 (ra6->sin6_addr.s6_addr));
667 t5_req6->peer_ip_lo = *((__be64 *)
668 (ra6->sin6_addr.s6_addr + 8));
669 t5_req6->opt0 = cpu_to_be64(opt0);
670 t5_req6->params = (__force __be64)cpu_to_be32(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530671 cxgb4_select_ntuple(
672 ep->com.dev->rdev.lldi.ports[0],
673 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530674 t5_req6->opt2 = cpu_to_be32(opt2);
675 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000676 }
677
Vipul Pandya793dad92012-12-10 09:30:56 +0000678 set_bit(ACT_OPEN_REQ, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700679 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
680}
681
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530682static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
683 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700684{
685 int mpalen, wrlen;
686 struct fw_ofld_tx_data_wr *req;
687 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530688 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700689
690 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
691
692 BUG_ON(skb_cloned(skb));
693
694 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530695 if (mpa_rev_to_use == 2)
696 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700697 wrlen = roundup(mpalen + sizeof *req, 16);
698 skb = get_skb(skb, wrlen, GFP_KERNEL);
699 if (!skb) {
700 connect_reply_upcall(ep, -ENOMEM);
701 return;
702 }
703 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
704
705 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
706 memset(req, 0, wrlen);
707 req->op_to_immdlen = cpu_to_be32(
708 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
709 FW_WR_COMPL(1) |
710 FW_WR_IMMDLEN(mpalen));
711 req->flowid_len16 = cpu_to_be32(
712 FW_WR_FLOWID(ep->hwtid) |
713 FW_WR_LEN16(wrlen >> 4));
714 req->plen = cpu_to_be32(mpalen);
715 req->tunnel_to_proxy = cpu_to_be32(
716 FW_OFLD_TX_DATA_WR_FLUSH(1) |
717 FW_OFLD_TX_DATA_WR_SHOVE(1));
718
719 mpa = (struct mpa_message *)(req + 1);
720 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
721 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530722 (markers_enabled ? MPA_MARKERS : 0) |
723 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700724 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530725 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530726 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530727 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530728 ep->retry_with_mpa_v1 = 0;
729 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700730
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530731 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700732 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
733 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530734 mpa_v2_params.ird = htons((u16)ep->ird);
735 mpa_v2_params.ord = htons((u16)ep->ord);
736
737 if (peer2peer) {
738 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
739 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
740 mpa_v2_params.ord |=
741 htons(MPA_V2_RDMA_WRITE_RTR);
742 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
743 mpa_v2_params.ord |=
744 htons(MPA_V2_RDMA_READ_RTR);
745 }
746 memcpy(mpa->private_data, &mpa_v2_params,
747 sizeof(struct mpa_v2_conn_params));
748
749 if (ep->plen)
750 memcpy(mpa->private_data +
751 sizeof(struct mpa_v2_conn_params),
752 ep->mpa_pkt + sizeof(*mpa), ep->plen);
753 } else
754 if (ep->plen)
755 memcpy(mpa->private_data,
756 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700757
758 /*
759 * Reference the mpa skb. This ensures the data area
760 * will remain in memory until the hw acks the tx.
761 * Function fw4_ack() will deref it.
762 */
763 skb_get(skb);
764 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
765 BUG_ON(ep->mpa_skb);
766 ep->mpa_skb = skb;
767 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
768 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530769 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700770 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530771 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700772 return;
773}
774
775static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
776{
777 int mpalen, wrlen;
778 struct fw_ofld_tx_data_wr *req;
779 struct mpa_message *mpa;
780 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530781 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700782
783 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
784
785 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530786 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
787 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700788 wrlen = roundup(mpalen + sizeof *req, 16);
789
790 skb = get_skb(NULL, wrlen, GFP_KERNEL);
791 if (!skb) {
792 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
793 return -ENOMEM;
794 }
795 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
796
797 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
798 memset(req, 0, wrlen);
799 req->op_to_immdlen = cpu_to_be32(
800 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
801 FW_WR_COMPL(1) |
802 FW_WR_IMMDLEN(mpalen));
803 req->flowid_len16 = cpu_to_be32(
804 FW_WR_FLOWID(ep->hwtid) |
805 FW_WR_LEN16(wrlen >> 4));
806 req->plen = cpu_to_be32(mpalen);
807 req->tunnel_to_proxy = cpu_to_be32(
808 FW_OFLD_TX_DATA_WR_FLUSH(1) |
809 FW_OFLD_TX_DATA_WR_SHOVE(1));
810
811 mpa = (struct mpa_message *)(req + 1);
812 memset(mpa, 0, sizeof(*mpa));
813 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
814 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000815 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700816 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530817
818 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
819 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700820 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
821 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530822 mpa_v2_params.ird = htons(((u16)ep->ird) |
823 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
824 0));
825 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
826 (p2p_type ==
827 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
828 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
829 FW_RI_INIT_P2PTYPE_READ_REQ ?
830 MPA_V2_RDMA_READ_RTR : 0) : 0));
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), pdata, plen);
837 } else
838 if (plen)
839 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700840
841 /*
842 * Reference the mpa skb again. This ensures the data area
843 * will remain in memory until the hw acks the tx.
844 * Function fw4_ack() will deref it.
845 */
846 skb_get(skb);
847 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
848 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
849 BUG_ON(ep->mpa_skb);
850 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +0530851 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700852 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
853}
854
855static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
856{
857 int mpalen, wrlen;
858 struct fw_ofld_tx_data_wr *req;
859 struct mpa_message *mpa;
860 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530861 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700862
863 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
864
865 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530866 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
867 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700868 wrlen = roundup(mpalen + sizeof *req, 16);
869
870 skb = get_skb(NULL, wrlen, GFP_KERNEL);
871 if (!skb) {
872 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
873 return -ENOMEM;
874 }
875 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
876
877 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
878 memset(req, 0, wrlen);
879 req->op_to_immdlen = cpu_to_be32(
880 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
881 FW_WR_COMPL(1) |
882 FW_WR_IMMDLEN(mpalen));
883 req->flowid_len16 = cpu_to_be32(
884 FW_WR_FLOWID(ep->hwtid) |
885 FW_WR_LEN16(wrlen >> 4));
886 req->plen = cpu_to_be32(mpalen);
887 req->tunnel_to_proxy = cpu_to_be32(
888 FW_OFLD_TX_DATA_WR_FLUSH(1) |
889 FW_OFLD_TX_DATA_WR_SHOVE(1));
890
891 mpa = (struct mpa_message *)(req + 1);
892 memset(mpa, 0, sizeof(*mpa));
893 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
894 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
895 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530896 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700897 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530898
899 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
900 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700901 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
902 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530903 mpa_v2_params.ird = htons((u16)ep->ird);
904 mpa_v2_params.ord = htons((u16)ep->ord);
905 if (peer2peer && (ep->mpa_attr.p2p_type !=
906 FW_RI_INIT_P2PTYPE_DISABLED)) {
907 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
908
909 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
910 mpa_v2_params.ord |=
911 htons(MPA_V2_RDMA_WRITE_RTR);
912 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
913 mpa_v2_params.ord |=
914 htons(MPA_V2_RDMA_READ_RTR);
915 }
916
917 memcpy(mpa->private_data, &mpa_v2_params,
918 sizeof(struct mpa_v2_conn_params));
919
920 if (ep->plen)
921 memcpy(mpa->private_data +
922 sizeof(struct mpa_v2_conn_params), pdata, plen);
923 } else
924 if (plen)
925 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700926
927 /*
928 * Reference the mpa skb. This ensures the data area
929 * will remain in memory until the hw acks the tx.
930 * Function fw4_ack() will deref it.
931 */
932 skb_get(skb);
933 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
934 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +0530935 __state_set(&ep->com, MPA_REP_SENT);
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 act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
941{
942 struct c4iw_ep *ep;
943 struct cpl_act_establish *req = cplhdr(skb);
944 unsigned int tid = GET_TID(req);
945 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
946 struct tid_info *t = dev->rdev.lldi.tids;
947
948 ep = lookup_atid(t, atid);
949
950 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
951 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
952
Steve Wisea7db89e2014-03-21 20:40:35 +0530953 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700954 dst_confirm(ep->dst);
955
956 /* setup the hwtid for this connection */
957 ep->hwtid = tid;
958 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +0000959 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700960
961 ep->snd_seq = be32_to_cpu(req->snd_isn);
962 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
963
964 set_emss(ep, ntohs(req->tcp_opt));
965
966 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +0000967 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700968 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +0000969 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700970
971 /* start MPA negotiation */
972 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530973 if (ep->retry_with_mpa_v1)
974 send_mpa_req(ep, skb, 1);
975 else
976 send_mpa_req(ep, skb, mpa_rev);
Steve Wisea7db89e2014-03-21 20:40:35 +0530977 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700978 return 0;
979}
980
Steve Wisebe13b2d2014-03-21 20:40:33 +0530981static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700982{
983 struct iw_cm_event event;
984
985 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
986 memset(&event, 0, sizeof(event));
987 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +0530988 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700989 if (ep->com.cm_id) {
990 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
991 ep, ep->com.cm_id, ep->hwtid);
992 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
993 ep->com.cm_id->rem_ref(ep->com.cm_id);
994 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +0000995 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700996 }
997}
998
999static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
1000{
1001 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecc18b932014-04-24 14:31:53 -05001002 __state_set(&ep->com, ABORTING);
Vipul Pandya793dad92012-12-10 09:30:56 +00001003 set_bit(ABORT_CONN, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001004 return send_abort(ep, skb, gfp);
1005}
1006
1007static void peer_close_upcall(struct c4iw_ep *ep)
1008{
1009 struct iw_cm_event event;
1010
1011 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1012 memset(&event, 0, sizeof(event));
1013 event.event = IW_CM_EVENT_DISCONNECT;
1014 if (ep->com.cm_id) {
1015 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1016 ep, ep->com.cm_id, ep->hwtid);
1017 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001018 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001019 }
1020}
1021
1022static void peer_abort_upcall(struct c4iw_ep *ep)
1023{
1024 struct iw_cm_event event;
1025
1026 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1027 memset(&event, 0, sizeof(event));
1028 event.event = IW_CM_EVENT_CLOSE;
1029 event.status = -ECONNRESET;
1030 if (ep->com.cm_id) {
1031 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1032 ep->com.cm_id, ep->hwtid);
1033 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1034 ep->com.cm_id->rem_ref(ep->com.cm_id);
1035 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001036 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001037 }
1038}
1039
1040static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1041{
1042 struct iw_cm_event event;
1043
1044 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1045 memset(&event, 0, sizeof(event));
1046 event.event = IW_CM_EVENT_CONNECT_REPLY;
1047 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301048 memcpy(&event.local_addr, &ep->com.local_addr,
1049 sizeof(ep->com.local_addr));
1050 memcpy(&event.remote_addr, &ep->com.remote_addr,
1051 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001052
1053 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301054 if (!ep->tried_with_mpa_v1) {
1055 /* this means MPA_v2 is used */
1056 event.private_data_len = ep->plen -
1057 sizeof(struct mpa_v2_conn_params);
1058 event.private_data = ep->mpa_pkt +
1059 sizeof(struct mpa_message) +
1060 sizeof(struct mpa_v2_conn_params);
1061 } else {
1062 /* this means MPA_v1 is used */
1063 event.private_data_len = ep->plen;
1064 event.private_data = ep->mpa_pkt +
1065 sizeof(struct mpa_message);
1066 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001067 }
Roland Dreier85963e42010-07-19 13:13:09 -07001068
1069 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1070 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001071 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001072 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1073
Steve Wisecfdda9d2010-04-21 15:30:06 -07001074 if (status < 0) {
1075 ep->com.cm_id->rem_ref(ep->com.cm_id);
1076 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001077 }
1078}
1079
Steve Wisebe13b2d2014-03-21 20:40:33 +05301080static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001081{
1082 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301083 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001084
1085 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1086 memset(&event, 0, sizeof(event));
1087 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301088 memcpy(&event.local_addr, &ep->com.local_addr,
1089 sizeof(ep->com.local_addr));
1090 memcpy(&event.remote_addr, &ep->com.remote_addr,
1091 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001092 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301093 if (!ep->tried_with_mpa_v1) {
1094 /* this means MPA_v2 is used */
1095 event.ord = ep->ord;
1096 event.ird = ep->ird;
1097 event.private_data_len = ep->plen -
1098 sizeof(struct mpa_v2_conn_params);
1099 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1100 sizeof(struct mpa_v2_conn_params);
1101 } else {
1102 /* this means MPA_v1 is used. Send max supported */
1103 event.ord = c4iw_max_read_depth;
1104 event.ird = c4iw_max_read_depth;
1105 event.private_data_len = ep->plen;
1106 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1107 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301108 c4iw_get_ep(&ep->com);
1109 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1110 &event);
1111 if (ret)
1112 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001113 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001114 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301115 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001116}
1117
1118static void established_upcall(struct c4iw_ep *ep)
1119{
1120 struct iw_cm_event event;
1121
1122 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1123 memset(&event, 0, sizeof(event));
1124 event.event = IW_CM_EVENT_ESTABLISHED;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301125 event.ird = ep->ird;
1126 event.ord = ep->ord;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001127 if (ep->com.cm_id) {
1128 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1129 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001130 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001131 }
1132}
1133
1134static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1135{
1136 struct cpl_rx_data_ack *req;
1137 struct sk_buff *skb;
1138 int wrlen = roundup(sizeof *req, 16);
1139
1140 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1141 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1142 if (!skb) {
1143 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1144 return 0;
1145 }
1146
1147 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1148 memset(req, 0, wrlen);
1149 INIT_TP_WR(req, ep->hwtid);
1150 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1151 ep->hwtid));
Steve Wiseba6d3922010-06-23 15:46:49 +00001152 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1153 F_RX_DACK_CHANGE |
1154 V_RX_DACK_MODE(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001155 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001156 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1157 return credits;
1158}
1159
Steve Wisecc18b932014-04-24 14:31:53 -05001160static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001161{
1162 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301163 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001164 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301165 u16 resp_ird, resp_ord;
1166 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001167 struct c4iw_qp_attributes attrs;
1168 enum c4iw_qp_attr_mask mask;
1169 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001170 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001171
1172 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1173
1174 /*
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001175 * Stop mpa timer. If it expired, then
1176 * we ignore the MPA reply. process_timeout()
1177 * will abort the connection.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001178 */
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001179 if (stop_ep_timer(ep))
Steve Wisecc18b932014-04-24 14:31:53 -05001180 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001181
1182 /*
1183 * If we get more than the supported amount of private data
1184 * then we must fail this connection.
1185 */
1186 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1187 err = -EINVAL;
1188 goto err;
1189 }
1190
1191 /*
1192 * copy the new data into our accumulation buffer.
1193 */
1194 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1195 skb->len);
1196 ep->mpa_pkt_len += skb->len;
1197
1198 /*
1199 * if we don't even have the mpa message, then bail.
1200 */
1201 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001202 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001203 mpa = (struct mpa_message *) ep->mpa_pkt;
1204
1205 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301206 if (mpa->revision > mpa_rev) {
1207 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1208 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001209 err = -EPROTO;
1210 goto err;
1211 }
1212 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1213 err = -EPROTO;
1214 goto err;
1215 }
1216
1217 plen = ntohs(mpa->private_data_size);
1218
1219 /*
1220 * Fail if there's too much private data.
1221 */
1222 if (plen > MPA_MAX_PRIVATE_DATA) {
1223 err = -EPROTO;
1224 goto err;
1225 }
1226
1227 /*
1228 * If plen does not account for pkt size
1229 */
1230 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1231 err = -EPROTO;
1232 goto err;
1233 }
1234
1235 ep->plen = (u8) plen;
1236
1237 /*
1238 * If we don't have all the pdata yet, then bail.
1239 * We'll continue process when more data arrives.
1240 */
1241 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001242 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001243
1244 if (mpa->flags & MPA_REJECT) {
1245 err = -ECONNREFUSED;
1246 goto err;
1247 }
1248
1249 /*
1250 * If we get here we have accumulated the entire mpa
1251 * start reply message including private data. And
1252 * the MPA header is valid.
1253 */
Steve Wisec529fb52014-03-21 20:40:37 +05301254 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001255 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1256 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1257 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301258 ep->mpa_attr.version = mpa->revision;
1259 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1260
1261 if (mpa->revision == 2) {
1262 ep->mpa_attr.enhanced_rdma_conn =
1263 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1264 if (ep->mpa_attr.enhanced_rdma_conn) {
1265 mpa_v2_params = (struct mpa_v2_conn_params *)
1266 (ep->mpa_pkt + sizeof(*mpa));
1267 resp_ird = ntohs(mpa_v2_params->ird) &
1268 MPA_V2_IRD_ORD_MASK;
1269 resp_ord = ntohs(mpa_v2_params->ord) &
1270 MPA_V2_IRD_ORD_MASK;
1271
1272 /*
1273 * This is a double-check. Ideally, below checks are
1274 * not required since ird/ord stuff has been taken
1275 * care of in c4iw_accept_cr
1276 */
1277 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1278 err = -ENOMEM;
1279 ep->ird = resp_ord;
1280 ep->ord = resp_ird;
1281 insuff_ird = 1;
1282 }
1283
1284 if (ntohs(mpa_v2_params->ird) &
1285 MPA_V2_PEER2PEER_MODEL) {
1286 if (ntohs(mpa_v2_params->ord) &
1287 MPA_V2_RDMA_WRITE_RTR)
1288 ep->mpa_attr.p2p_type =
1289 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1290 else if (ntohs(mpa_v2_params->ord) &
1291 MPA_V2_RDMA_READ_RTR)
1292 ep->mpa_attr.p2p_type =
1293 FW_RI_INIT_P2PTYPE_READ_REQ;
1294 }
1295 }
1296 } else if (mpa->revision == 1)
1297 if (peer2peer)
1298 ep->mpa_attr.p2p_type = p2p_type;
1299
Steve Wisecfdda9d2010-04-21 15:30:06 -07001300 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301301 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1302 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1303 ep->mpa_attr.recv_marker_enabled,
1304 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1305 ep->mpa_attr.p2p_type, p2p_type);
1306
1307 /*
1308 * If responder's RTR does not match with that of initiator, assign
1309 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1310 * generated when moving QP to RTS state.
1311 * A TERM message will be sent after QP has moved to RTS state
1312 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001313 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301314 (ep->mpa_attr.p2p_type != p2p_type)) {
1315 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1316 rtr_mismatch = 1;
1317 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001318
1319 attrs.mpa_attr = ep->mpa_attr;
1320 attrs.max_ird = ep->ird;
1321 attrs.max_ord = ep->ord;
1322 attrs.llp_stream_handle = ep;
1323 attrs.next_state = C4IW_QP_STATE_RTS;
1324
1325 mask = C4IW_QP_ATTR_NEXT_STATE |
1326 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1327 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1328
1329 /* bind QP and TID with INIT_WR */
1330 err = c4iw_modify_qp(ep->com.qp->rhp,
1331 ep->com.qp, mask, &attrs, 1);
1332 if (err)
1333 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301334
1335 /*
1336 * If responder's RTR requirement did not match with what initiator
1337 * supports, generate TERM message
1338 */
1339 if (rtr_mismatch) {
1340 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1341 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1342 attrs.ecode = MPA_NOMATCH_RTR;
1343 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001344 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301345 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001346 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301347 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001348 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301349 goto out;
1350 }
1351
1352 /*
1353 * Generate TERM if initiator IRD is not sufficient for responder
1354 * provided ORD. Currently, we do the same behaviour even when
1355 * responder provided IRD is also not sufficient as regards to
1356 * initiator ORD.
1357 */
1358 if (insuff_ird) {
1359 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1360 __func__);
1361 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1362 attrs.ecode = MPA_INSUFF_IRD;
1363 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001364 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301365 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001366 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301367 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001368 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301369 goto out;
1370 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001371 goto out;
1372err:
Steve Wisec529fb52014-03-21 20:40:37 +05301373 __state_set(&ep->com, ABORTING);
Steve Wiseb21ef162010-06-10 19:02:55 +00001374 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001375out:
1376 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001377 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001378}
1379
1380static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1381{
1382 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301383 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001384 u16 plen;
1385
1386 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1387
Steve Wisecfdda9d2010-04-21 15:30:06 -07001388 /*
1389 * If we get more than the supported amount of private data
1390 * then we must fail this connection.
1391 */
1392 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001393 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001394 abort_connection(ep, skb, GFP_KERNEL);
1395 return;
1396 }
1397
1398 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1399
1400 /*
1401 * Copy the new data into our accumulation buffer.
1402 */
1403 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1404 skb->len);
1405 ep->mpa_pkt_len += skb->len;
1406
1407 /*
1408 * If we don't even have the mpa message, then bail.
1409 * We'll continue process when more data arrives.
1410 */
1411 if (ep->mpa_pkt_len < sizeof(*mpa))
1412 return;
1413
1414 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001415 mpa = (struct mpa_message *) ep->mpa_pkt;
1416
1417 /*
1418 * Validate MPA Header.
1419 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301420 if (mpa->revision > mpa_rev) {
1421 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1422 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001423 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001424 abort_connection(ep, skb, GFP_KERNEL);
1425 return;
1426 }
1427
1428 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001429 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001430 abort_connection(ep, skb, GFP_KERNEL);
1431 return;
1432 }
1433
1434 plen = ntohs(mpa->private_data_size);
1435
1436 /*
1437 * Fail if there's too much private data.
1438 */
1439 if (plen > MPA_MAX_PRIVATE_DATA) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001440 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001441 abort_connection(ep, skb, GFP_KERNEL);
1442 return;
1443 }
1444
1445 /*
1446 * If plen does not account for pkt size
1447 */
1448 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001449 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001450 abort_connection(ep, skb, GFP_KERNEL);
1451 return;
1452 }
1453 ep->plen = (u8) plen;
1454
1455 /*
1456 * If we don't have all the pdata yet, then bail.
1457 */
1458 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1459 return;
1460
1461 /*
1462 * If we get here we have accumulated the entire mpa
1463 * start reply message including private data.
1464 */
1465 ep->mpa_attr.initiator = 0;
1466 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1467 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1468 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301469 ep->mpa_attr.version = mpa->revision;
1470 if (mpa->revision == 1)
1471 ep->tried_with_mpa_v1 = 1;
1472 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1473
1474 if (mpa->revision == 2) {
1475 ep->mpa_attr.enhanced_rdma_conn =
1476 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1477 if (ep->mpa_attr.enhanced_rdma_conn) {
1478 mpa_v2_params = (struct mpa_v2_conn_params *)
1479 (ep->mpa_pkt + sizeof(*mpa));
1480 ep->ird = ntohs(mpa_v2_params->ird) &
1481 MPA_V2_IRD_ORD_MASK;
1482 ep->ord = ntohs(mpa_v2_params->ord) &
1483 MPA_V2_IRD_ORD_MASK;
1484 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1485 if (peer2peer) {
1486 if (ntohs(mpa_v2_params->ord) &
1487 MPA_V2_RDMA_WRITE_RTR)
1488 ep->mpa_attr.p2p_type =
1489 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1490 else if (ntohs(mpa_v2_params->ord) &
1491 MPA_V2_RDMA_READ_RTR)
1492 ep->mpa_attr.p2p_type =
1493 FW_RI_INIT_P2PTYPE_READ_REQ;
1494 }
1495 }
1496 } else if (mpa->revision == 1)
1497 if (peer2peer)
1498 ep->mpa_attr.p2p_type = p2p_type;
1499
Steve Wisecfdda9d2010-04-21 15:30:06 -07001500 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1501 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1502 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1503 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1504 ep->mpa_attr.p2p_type);
1505
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001506 /*
1507 * If the endpoint timer already expired, then we ignore
1508 * the start request. process_timeout() will abort
1509 * the connection.
1510 */
1511 if (!stop_ep_timer(ep)) {
1512 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001513
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001514 /* drive upcall */
1515 mutex_lock(&ep->parent_ep->com.mutex);
1516 if (ep->parent_ep->com.state != DEAD) {
1517 if (connect_request_upcall(ep))
1518 abort_connection(ep, skb, GFP_KERNEL);
1519 } else {
Steve Wisebe13b2d2014-03-21 20:40:33 +05301520 abort_connection(ep, skb, GFP_KERNEL);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001521 }
1522 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301523 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001524 return;
1525}
1526
1527static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1528{
1529 struct c4iw_ep *ep;
1530 struct cpl_rx_data *hdr = cplhdr(skb);
1531 unsigned int dlen = ntohs(hdr->len);
1532 unsigned int tid = GET_TID(hdr);
1533 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001534 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001535 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001536
1537 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301538 if (!ep)
1539 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001540 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1541 skb_pull(skb, sizeof(*hdr));
1542 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301543 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001544
Steve Wisecfdda9d2010-04-21 15:30:06 -07001545 /* update RX credits */
1546 update_rx_credits(ep, dlen);
1547
Steve Wisec529fb52014-03-21 20:40:37 +05301548 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001549 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001550 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001551 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001552 break;
1553 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001554 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001555 process_mpa_request(ep, skb);
1556 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001557 case FPDU_MODE: {
1558 struct c4iw_qp_attributes attrs;
1559 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001560 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001561 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001562 " qpid %u ep %p state %d tid %u status %d\n",
1563 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301564 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301565 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001566 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001567 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1568 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001569 break;
1570 }
Vipul Pandya15579672013-01-07 13:11:52 +00001571 default:
1572 break;
1573 }
Steve Wisec529fb52014-03-21 20:40:37 +05301574 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001575 if (disconnect)
1576 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001577 return 0;
1578}
1579
1580static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1581{
1582 struct c4iw_ep *ep;
1583 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001584 int release = 0;
1585 unsigned int tid = GET_TID(rpl);
1586 struct tid_info *t = dev->rdev.lldi.tids;
1587
1588 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301589 if (!ep) {
1590 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1591 return 0;
1592 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001593 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001594 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001595 switch (ep->com.state) {
1596 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001597 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001598 __state_set(&ep->com, DEAD);
1599 release = 1;
1600 break;
1601 default:
1602 printk(KERN_ERR "%s ep %p state %d\n",
1603 __func__, ep, ep->com.state);
1604 break;
1605 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001606 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001607
1608 if (release)
1609 release_ep_resources(ep);
1610 return 0;
1611}
1612
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001613static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1614{
1615 struct sk_buff *skb;
1616 struct fw_ofld_connection_wr *req;
1617 unsigned int mtu_idx;
1618 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301619 struct sockaddr_in *sin;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001620
1621 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1622 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1623 memset(req, 0, sizeof(*req));
1624 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1625 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301626 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1627 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001628 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +05301629 sin = (struct sockaddr_in *)&ep->com.local_addr;
1630 req->le.lport = sin->sin_port;
1631 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
1632 sin = (struct sockaddr_in *)&ep->com.remote_addr;
1633 req->le.pport = sin->sin_port;
1634 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001635 req->tcb.t_state_to_astid =
1636 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1637 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1638 req->tcb.cplrxdataack_cplpassacceptrpl =
1639 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001640 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001641 req->tcb.rcv_adv = htons(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001642 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1643 wscale = compute_wscale(rcv_win);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001644 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001645 (nocong ? NO_CONG(1) : 0) |
1646 KEEP_ALIVE(1) |
1647 DELACK(1) |
1648 WND_SCALE(wscale) |
1649 MSS_IDX(mtu_idx) |
1650 L2T_IDX(ep->l2t->idx) |
1651 TX_CHAN(ep->tx_chan) |
1652 SMAC_SEL(ep->smac_idx) |
1653 DSCP(ep->tos) |
1654 ULP_MODE(ULP_MODE_TCPDDP) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001655 RCV_BUFSIZ(rcv_win >> 10));
1656 req->tcb.opt2 = (__force __be32) (PACE(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001657 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1658 RX_CHANNEL(0) |
1659 CCTRL_ECN(enable_ecn) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001660 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001661 if (enable_tcp_timestamps)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001662 req->tcb.opt2 |= (__force __be32) TSTAMPS_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001663 if (enable_tcp_sack)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001664 req->tcb.opt2 |= (__force __be32) SACK_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001665 if (wscale && enable_tcp_window_scaling)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001666 req->tcb.opt2 |= (__force __be32) WND_SCALE_EN(1);
1667 req->tcb.opt0 = cpu_to_be64((__force u64) req->tcb.opt0);
1668 req->tcb.opt2 = cpu_to_be32((__force u32) req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001669 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1670 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001671 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1672}
1673
Steve Wisecfdda9d2010-04-21 15:30:06 -07001674/*
1675 * Return whether a failed active open has allocated a TID
1676 */
1677static inline int act_open_has_tid(int status)
1678{
1679 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1680 status != CPL_ERR_ARP_MISS;
1681}
1682
Steve Wise7a2cea22014-03-14 21:52:07 +05301683/* Returns whether a CPL status conveys negative advice.
1684 */
1685static int is_neg_adv(unsigned int status)
1686{
1687 return status == CPL_ERR_RTX_NEG_ADVICE ||
1688 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1689 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1690}
1691
Vipul Pandya793dad92012-12-10 09:30:56 +00001692#define ACT_OPEN_RETRY_COUNT 2
1693
Vipul Pandya830662f2013-07-04 16:10:47 +05301694static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1695 struct dst_entry *dst, struct c4iw_dev *cdev,
1696 bool clear_mpa_v1)
1697{
1698 struct neighbour *n;
1699 int err, step;
1700 struct net_device *pdev;
1701
1702 n = dst_neigh_lookup(dst, peer_ip);
1703 if (!n)
1704 return -ENODEV;
1705
1706 rcu_read_lock();
1707 err = -ENOMEM;
1708 if (n->dev->flags & IFF_LOOPBACK) {
1709 if (iptype == 4)
1710 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1711 else if (IS_ENABLED(CONFIG_IPV6))
1712 for_each_netdev(&init_net, pdev) {
1713 if (ipv6_chk_addr(&init_net,
1714 (struct in6_addr *)peer_ip,
1715 pdev, 1))
1716 break;
1717 }
1718 else
1719 pdev = NULL;
1720
1721 if (!pdev) {
1722 err = -ENODEV;
1723 goto out;
1724 }
1725 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1726 n, pdev, 0);
1727 if (!ep->l2t)
1728 goto out;
1729 ep->mtu = pdev->mtu;
1730 ep->tx_chan = cxgb4_port_chan(pdev);
1731 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1732 step = cdev->rdev.lldi.ntxq /
1733 cdev->rdev.lldi.nchan;
1734 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1735 step = cdev->rdev.lldi.nrxq /
1736 cdev->rdev.lldi.nchan;
1737 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1738 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1739 cxgb4_port_idx(pdev) * step];
1740 dev_put(pdev);
1741 } else {
1742 pdev = get_real_dev(n->dev);
1743 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1744 n, pdev, 0);
1745 if (!ep->l2t)
1746 goto out;
1747 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05001748 ep->tx_chan = cxgb4_port_chan(pdev);
1749 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
Vipul Pandya830662f2013-07-04 16:10:47 +05301750 step = cdev->rdev.lldi.ntxq /
1751 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05001752 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1753 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05301754 step = cdev->rdev.lldi.nrxq /
1755 cdev->rdev.lldi.nchan;
1756 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05001757 cxgb4_port_idx(pdev) * step];
Vipul Pandya830662f2013-07-04 16:10:47 +05301758
1759 if (clear_mpa_v1) {
1760 ep->retry_with_mpa_v1 = 0;
1761 ep->tried_with_mpa_v1 = 0;
1762 }
1763 }
1764 err = 0;
1765out:
1766 rcu_read_unlock();
1767
1768 neigh_release(n);
1769
1770 return err;
1771}
1772
Vipul Pandya793dad92012-12-10 09:30:56 +00001773static int c4iw_reconnect(struct c4iw_ep *ep)
1774{
1775 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05301776 struct sockaddr_in *laddr = (struct sockaddr_in *)
1777 &ep->com.cm_id->local_addr;
1778 struct sockaddr_in *raddr = (struct sockaddr_in *)
1779 &ep->com.cm_id->remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301780 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
1781 &ep->com.cm_id->local_addr;
1782 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
1783 &ep->com.cm_id->remote_addr;
1784 int iptype;
1785 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00001786
1787 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1788 init_timer(&ep->timer);
1789
1790 /*
1791 * Allocate an active TID to initiate a TCP connection.
1792 */
1793 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1794 if (ep->atid == -1) {
1795 pr_err("%s - cannot alloc atid.\n", __func__);
1796 err = -ENOMEM;
1797 goto fail2;
1798 }
1799 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1800
1801 /* find a route */
Vipul Pandya830662f2013-07-04 16:10:47 +05301802 if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
1803 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
1804 raddr->sin_addr.s_addr, laddr->sin_port,
1805 raddr->sin_port, 0);
1806 iptype = 4;
1807 ra = (__u8 *)&raddr->sin_addr;
1808 } else {
1809 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
1810 raddr6->sin6_addr.s6_addr,
1811 laddr6->sin6_port, raddr6->sin6_port, 0,
1812 raddr6->sin6_scope_id);
1813 iptype = 6;
1814 ra = (__u8 *)&raddr6->sin6_addr;
1815 }
1816 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001817 pr_err("%s - cannot find route.\n", __func__);
1818 err = -EHOSTUNREACH;
1819 goto fail3;
1820 }
Vipul Pandya830662f2013-07-04 16:10:47 +05301821 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false);
1822 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001823 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00001824 goto fail4;
1825 }
1826
1827 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1828 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1829 ep->l2t->idx);
1830
1831 state_set(&ep->com, CONNECTING);
1832 ep->tos = 0;
1833
1834 /* send connect request to rnic */
1835 err = send_connect(ep);
1836 if (!err)
1837 goto out;
1838
1839 cxgb4_l2t_release(ep->l2t);
1840fail4:
1841 dst_release(ep->dst);
1842fail3:
1843 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1844 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1845fail2:
1846 /*
1847 * remember to send notification to upper layer.
1848 * We are in here so the upper layer is not aware that this is
1849 * re-connect attempt and so, upper layer is still waiting for
1850 * response of 1st connect request.
1851 */
1852 connect_reply_upcall(ep, -ECONNRESET);
1853 c4iw_put_ep(&ep->com);
1854out:
1855 return err;
1856}
1857
Steve Wisecfdda9d2010-04-21 15:30:06 -07001858static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1859{
1860 struct c4iw_ep *ep;
1861 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1862 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1863 ntohl(rpl->atid_status)));
1864 struct tid_info *t = dev->rdev.lldi.tids;
1865 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05301866 struct sockaddr_in *la;
1867 struct sockaddr_in *ra;
1868 struct sockaddr_in6 *la6;
1869 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001870
1871 ep = lookup_atid(t, atid);
Vipul Pandya830662f2013-07-04 16:10:47 +05301872 la = (struct sockaddr_in *)&ep->com.local_addr;
1873 ra = (struct sockaddr_in *)&ep->com.remote_addr;
1874 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
1875 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001876
1877 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1878 status, status2errno(status));
1879
Steve Wise7a2cea22014-03-14 21:52:07 +05301880 if (is_neg_adv(status)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001881 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1882 atid);
1883 return 0;
1884 }
1885
Vipul Pandya793dad92012-12-10 09:30:56 +00001886 set_bit(ACT_OPEN_RPL, &ep->com.history);
1887
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301888 /*
1889 * Log interesting failures.
1890 */
1891 switch (status) {
1892 case CPL_ERR_CONN_RESET:
1893 case CPL_ERR_CONN_TIMEDOUT:
1894 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001895 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05301896 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00001897 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05301898 mutex_unlock(&dev->rdev.stats.lock);
1899 if (ep->com.local_addr.ss_family == AF_INET &&
1900 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001901 send_fw_act_open_req(ep,
1902 GET_TID_TID(GET_AOPEN_ATID(
1903 ntohl(rpl->atid_status))));
1904 return 0;
1905 }
1906 break;
1907 case CPL_ERR_CONN_EXIST:
1908 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
1909 set_bit(ACT_RETRY_INUSE, &ep->com.history);
1910 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
1911 atid);
1912 cxgb4_free_atid(t, atid);
1913 dst_release(ep->dst);
1914 cxgb4_l2t_release(ep->l2t);
1915 c4iw_reconnect(ep);
1916 return 0;
1917 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001918 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301919 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05301920 if (ep->com.local_addr.ss_family == AF_INET) {
1921 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
1922 atid, status, status2errno(status),
1923 &la->sin_addr.s_addr, ntohs(la->sin_port),
1924 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
1925 } else {
1926 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
1927 atid, status, status2errno(status),
1928 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
1929 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
1930 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301931 break;
1932 }
1933
Steve Wisecfdda9d2010-04-21 15:30:06 -07001934 connect_reply_upcall(ep, status2errno(status));
1935 state_set(&ep->com, DEAD);
1936
1937 if (status && act_open_has_tid(status))
1938 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1939
Vipul Pandya793dad92012-12-10 09:30:56 +00001940 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001941 cxgb4_free_atid(t, atid);
1942 dst_release(ep->dst);
1943 cxgb4_l2t_release(ep->l2t);
1944 c4iw_put_ep(&ep->com);
1945
1946 return 0;
1947}
1948
1949static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1950{
1951 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1952 struct tid_info *t = dev->rdev.lldi.tids;
1953 unsigned int stid = GET_TID(rpl);
1954 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1955
1956 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00001957 PDBG("%s stid %d lookup failure!\n", __func__, stid);
1958 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001959 }
1960 PDBG("%s ep %p status %d error %d\n", __func__, ep,
1961 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07001962 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001963
Vipul Pandya1cab7752012-12-10 09:30:55 +00001964out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07001965 return 0;
1966}
1967
Steve Wisecfdda9d2010-04-21 15:30:06 -07001968static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1969{
1970 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
1971 struct tid_info *t = dev->rdev.lldi.tids;
1972 unsigned int stid = GET_TID(rpl);
1973 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1974
1975 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07001976 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001977 return 0;
1978}
1979
Vipul Pandya830662f2013-07-04 16:10:47 +05301980static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
Steve Wisecfdda9d2010-04-21 15:30:06 -07001981 struct cpl_pass_accept_req *req)
1982{
1983 struct cpl_pass_accept_rpl *rpl;
1984 unsigned int mtu_idx;
1985 u64 opt0;
1986 u32 opt2;
1987 int wscale;
1988
1989 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1990 BUG_ON(skb_cloned(skb));
1991 skb_trim(skb, sizeof(*rpl));
1992 skb_get(skb);
1993 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1994 wscale = compute_wscale(rcv_win);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001995 opt0 = (nocong ? NO_CONG(1) : 0) |
1996 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +00001997 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001998 WND_SCALE(wscale) |
1999 MSS_IDX(mtu_idx) |
2000 L2T_IDX(ep->l2t->idx) |
2001 TX_CHAN(ep->tx_chan) |
2002 SMAC_SEL(ep->smac_idx) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002003 DSCP(ep->tos >> 2) |
Steve Wiseb48f3b92011-03-11 22:30:21 +00002004 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07002005 RCV_BUFSIZ(rcv_win>>10);
2006 opt2 = RX_CHANNEL(0) |
2007 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
2008
2009 if (enable_tcp_timestamps && req->tcpopt.tstamp)
2010 opt2 |= TSTAMPS_EN(1);
2011 if (enable_tcp_sack && req->tcpopt.sack)
2012 opt2 |= SACK_EN(1);
2013 if (wscale && enable_tcp_window_scaling)
2014 opt2 |= WND_SCALE_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002015 if (enable_ecn) {
2016 const struct tcphdr *tcph;
2017 u32 hlen = ntohl(req->hdr_len);
2018
2019 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
2020 G_IP_HDR_LEN(hlen);
2021 if (tcph->ece && tcph->cwr)
2022 opt2 |= CCTRL_ECN(1);
2023 }
Steve Wise92e50112014-04-24 14:31:59 -05002024 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
2025 opt2 |= T5_OPT_2_VALID;
2026 opt2 |= V_CONG_CNTRL(CONG_ALG_TAHOE);
2027 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002028
2029 rpl = cplhdr(skb);
2030 INIT_TP_WR(rpl, ep->hwtid);
2031 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2032 ep->hwtid));
2033 rpl->opt0 = cpu_to_be64(opt0);
2034 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002035 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wiseb38a0ad2013-08-06 21:04:37 +05302036 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002037 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2038
2039 return;
2040}
2041
Vipul Pandya830662f2013-07-04 16:10:47 +05302042static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002043{
Vipul Pandya830662f2013-07-04 16:10:47 +05302044 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002045 BUG_ON(skb_cloned(skb));
2046 skb_trim(skb, sizeof(struct cpl_tid_release));
2047 skb_get(skb);
2048 release_tid(&dev->rdev, hwtid, skb);
2049 return;
2050}
2051
Vipul Pandya830662f2013-07-04 16:10:47 +05302052static void get_4tuple(struct cpl_pass_accept_req *req, int *iptype,
2053 __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002054 __be16 *local_port, __be16 *peer_port)
2055{
2056 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
2057 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
2058 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302059 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002060 struct tcphdr *tcp = (struct tcphdr *)
2061 ((u8 *)(req + 1) + eth_len + ip_len);
2062
Vipul Pandya830662f2013-07-04 16:10:47 +05302063 if (ip->version == 4) {
2064 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2065 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2066 ntohs(tcp->dest));
2067 *iptype = 4;
2068 memcpy(peer_ip, &ip->saddr, 4);
2069 memcpy(local_ip, &ip->daddr, 4);
2070 } else {
2071 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2072 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2073 ntohs(tcp->dest));
2074 *iptype = 6;
2075 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2076 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2077 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002078 *peer_port = tcp->source;
2079 *local_port = tcp->dest;
2080
2081 return;
2082}
2083
2084static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2085{
Vipul Pandya793dad92012-12-10 09:30:56 +00002086 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002087 struct cpl_pass_accept_req *req = cplhdr(skb);
2088 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
2089 struct tid_info *t = dev->rdev.lldi.tids;
2090 unsigned int hwtid = GET_TID(req);
2091 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302092 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002093 __be16 local_port, peer_port;
David Miller3786cf12011-12-02 16:52:31 +00002094 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002095 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302096 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002097
2098 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002099 if (!parent_ep) {
2100 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2101 goto reject;
2102 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002103
Steve Wisecfdda9d2010-04-21 15:30:06 -07002104 if (state_read(&parent_ep->com) != LISTEN) {
2105 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
2106 __func__);
2107 goto reject;
2108 }
2109
Vipul Pandya830662f2013-07-04 16:10:47 +05302110 get_4tuple(req, &iptype, local_ip, peer_ip, &local_port, &peer_port);
2111
Steve Wisecfdda9d2010-04-21 15:30:06 -07002112 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302113 if (iptype == 4) {
2114 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2115 , __func__, parent_ep, hwtid,
2116 local_ip, peer_ip, ntohs(local_port),
2117 ntohs(peer_port), peer_mss);
2118 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2119 local_port, peer_port,
2120 GET_POPEN_TOS(ntohl(req->tos_stid)));
2121 } else {
2122 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2123 , __func__, parent_ep, hwtid,
2124 local_ip, peer_ip, ntohs(local_port),
2125 ntohs(peer_port), peer_mss);
2126 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
2127 PASS_OPEN_TOS(ntohl(req->tos_stid)),
2128 ((struct sockaddr_in6 *)
2129 &parent_ep->com.local_addr)->sin6_scope_id);
2130 }
2131 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002132 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2133 __func__);
2134 goto reject;
2135 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002136
2137 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2138 if (!child_ep) {
2139 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2140 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002141 dst_release(dst);
2142 goto reject;
2143 }
David Miller3786cf12011-12-02 16:52:31 +00002144
Vipul Pandya830662f2013-07-04 16:10:47 +05302145 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false);
David Miller3786cf12011-12-02 16:52:31 +00002146 if (err) {
2147 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2148 __func__);
2149 dst_release(dst);
2150 kfree(child_ep);
2151 goto reject;
2152 }
2153
Vipul Pandya1cab7752012-12-10 09:30:55 +00002154 if (peer_mss && child_ep->mtu > (peer_mss + 40))
2155 child_ep->mtu = peer_mss + 40;
2156
Steve Wisecfdda9d2010-04-21 15:30:06 -07002157 state_set(&child_ep->com, CONNECTING);
2158 child_ep->com.dev = dev;
2159 child_ep->com.cm_id = NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +05302160 if (iptype == 4) {
2161 struct sockaddr_in *sin = (struct sockaddr_in *)
2162 &child_ep->com.local_addr;
2163 sin->sin_family = PF_INET;
2164 sin->sin_port = local_port;
2165 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2166 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
2167 sin->sin_family = PF_INET;
2168 sin->sin_port = peer_port;
2169 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2170 } else {
2171 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
2172 &child_ep->com.local_addr;
2173 sin6->sin6_family = PF_INET6;
2174 sin6->sin6_port = local_port;
2175 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2176 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
2177 sin6->sin6_family = PF_INET6;
2178 sin6->sin6_port = peer_port;
2179 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2180 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002181 c4iw_get_ep(&parent_ep->com);
2182 child_ep->parent_ep = parent_ep;
2183 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002184 child_ep->dst = dst;
2185 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002186
2187 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002188 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002189
2190 init_timer(&child_ep->timer);
2191 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002192 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Vipul Pandya830662f2013-07-04 16:10:47 +05302193 accept_cr(child_ep, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00002194 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002195 goto out;
2196reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302197 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002198out:
2199 return 0;
2200}
2201
2202static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2203{
2204 struct c4iw_ep *ep;
2205 struct cpl_pass_establish *req = cplhdr(skb);
2206 struct tid_info *t = dev->rdev.lldi.tids;
2207 unsigned int tid = GET_TID(req);
2208
2209 ep = lookup_tid(t, tid);
2210 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2211 ep->snd_seq = be32_to_cpu(req->snd_isn);
2212 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2213
Vipul Pandya1cab7752012-12-10 09:30:55 +00002214 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2215 ntohs(req->tcp_opt));
2216
Steve Wisecfdda9d2010-04-21 15:30:06 -07002217 set_emss(ep, ntohs(req->tcp_opt));
2218
2219 dst_confirm(ep->dst);
2220 state_set(&ep->com, MPA_REQ_WAIT);
2221 start_ep_timer(ep);
2222 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002223 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002224
2225 return 0;
2226}
2227
2228static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2229{
2230 struct cpl_peer_close *hdr = cplhdr(skb);
2231 struct c4iw_ep *ep;
2232 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002233 int disconnect = 1;
2234 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002235 struct tid_info *t = dev->rdev.lldi.tids;
2236 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002237 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002238
2239 ep = lookup_tid(t, tid);
2240 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2241 dst_confirm(ep->dst);
2242
Vipul Pandya793dad92012-12-10 09:30:56 +00002243 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002244 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002245 switch (ep->com.state) {
2246 case MPA_REQ_WAIT:
2247 __state_set(&ep->com, CLOSING);
2248 break;
2249 case MPA_REQ_SENT:
2250 __state_set(&ep->com, CLOSING);
2251 connect_reply_upcall(ep, -ECONNRESET);
2252 break;
2253 case MPA_REQ_RCVD:
2254
2255 /*
2256 * We're gonna mark this puppy DEAD, but keep
2257 * the reference on it until the ULP accepts or
2258 * rejects the CR. Also wake up anyone waiting
2259 * in rdma connection migration (see c4iw_accept_cr()).
2260 */
2261 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002262 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002263 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002264 break;
2265 case MPA_REP_SENT:
2266 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002267 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002268 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002269 break;
2270 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002271 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002272 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002273 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002274 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002275 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002276 if (ret != -ECONNRESET) {
2277 peer_close_upcall(ep);
2278 disconnect = 1;
2279 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002280 break;
2281 case ABORTING:
2282 disconnect = 0;
2283 break;
2284 case CLOSING:
2285 __state_set(&ep->com, MORIBUND);
2286 disconnect = 0;
2287 break;
2288 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002289 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002290 if (ep->com.cm_id && ep->com.qp) {
2291 attrs.next_state = C4IW_QP_STATE_IDLE;
2292 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2293 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2294 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302295 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002296 __state_set(&ep->com, DEAD);
2297 release = 1;
2298 disconnect = 0;
2299 break;
2300 case DEAD:
2301 disconnect = 0;
2302 break;
2303 default:
2304 BUG_ON(1);
2305 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002306 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002307 if (disconnect)
2308 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2309 if (release)
2310 release_ep_resources(ep);
2311 return 0;
2312}
2313
Steve Wisecfdda9d2010-04-21 15:30:06 -07002314static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2315{
2316 struct cpl_abort_req_rss *req = cplhdr(skb);
2317 struct c4iw_ep *ep;
2318 struct cpl_abort_rpl *rpl;
2319 struct sk_buff *rpl_skb;
2320 struct c4iw_qp_attributes attrs;
2321 int ret;
2322 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002323 struct tid_info *t = dev->rdev.lldi.tids;
2324 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002325
2326 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302327 if (is_neg_adv(req->status)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002328 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2329 ep->hwtid);
2330 return 0;
2331 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002332 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2333 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002334 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002335
2336 /*
2337 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302338 * However, this is not needed if com state is just
2339 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002340 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302341 if (ep->com.state != MPA_REQ_SENT)
2342 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002343
2344 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002345 switch (ep->com.state) {
2346 case CONNECTING:
2347 break;
2348 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002349 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002350 break;
2351 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002352 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002353 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302354 connect_reply_upcall(ep, -ECONNRESET);
2355 else {
2356 /*
2357 * we just don't send notification upwards because we
2358 * want to retry with mpa_v1 without upper layers even
2359 * knowing it.
2360 *
2361 * do some housekeeping so as to re-initiate the
2362 * connection
2363 */
2364 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2365 mpa_rev);
2366 ep->retry_with_mpa_v1 = 1;
2367 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002368 break;
2369 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002370 break;
2371 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002372 break;
2373 case MORIBUND:
2374 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002375 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002376 /*FALLTHROUGH*/
2377 case FPDU_MODE:
2378 if (ep->com.cm_id && ep->com.qp) {
2379 attrs.next_state = C4IW_QP_STATE_ERROR;
2380 ret = c4iw_modify_qp(ep->com.qp->rhp,
2381 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2382 &attrs, 1);
2383 if (ret)
2384 printk(KERN_ERR MOD
2385 "%s - qp <- error failed!\n",
2386 __func__);
2387 }
2388 peer_abort_upcall(ep);
2389 break;
2390 case ABORTING:
2391 break;
2392 case DEAD:
2393 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002394 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002395 return 0;
2396 default:
2397 BUG_ON(1);
2398 break;
2399 }
2400 dst_confirm(ep->dst);
2401 if (ep->com.state != ABORTING) {
2402 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302403 /* we don't release if we want to retry with mpa_v1 */
2404 if (!ep->retry_with_mpa_v1)
2405 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002406 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002407 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002408
2409 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2410 if (!rpl_skb) {
2411 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2412 __func__);
2413 release = 1;
2414 goto out;
2415 }
2416 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2417 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2418 INIT_TP_WR(rpl, ep->hwtid);
2419 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2420 rpl->cmd = CPL_ABORT_NO_RST;
2421 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2422out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002423 if (release)
2424 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002425 else if (ep->retry_with_mpa_v1) {
2426 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302427 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2428 dst_release(ep->dst);
2429 cxgb4_l2t_release(ep->l2t);
2430 c4iw_reconnect(ep);
2431 }
2432
Steve Wisecfdda9d2010-04-21 15:30:06 -07002433 return 0;
2434}
2435
2436static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2437{
2438 struct c4iw_ep *ep;
2439 struct c4iw_qp_attributes attrs;
2440 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002441 int release = 0;
2442 struct tid_info *t = dev->rdev.lldi.tids;
2443 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002444
2445 ep = lookup_tid(t, tid);
2446
2447 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2448 BUG_ON(!ep);
2449
2450 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002451 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002452 switch (ep->com.state) {
2453 case CLOSING:
2454 __state_set(&ep->com, MORIBUND);
2455 break;
2456 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002457 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002458 if ((ep->com.cm_id) && (ep->com.qp)) {
2459 attrs.next_state = C4IW_QP_STATE_IDLE;
2460 c4iw_modify_qp(ep->com.qp->rhp,
2461 ep->com.qp,
2462 C4IW_QP_ATTR_NEXT_STATE,
2463 &attrs, 1);
2464 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302465 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002466 __state_set(&ep->com, DEAD);
2467 release = 1;
2468 break;
2469 case ABORTING:
2470 case DEAD:
2471 break;
2472 default:
2473 BUG_ON(1);
2474 break;
2475 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002476 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002477 if (release)
2478 release_ep_resources(ep);
2479 return 0;
2480}
2481
2482static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2483{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002484 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002485 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002486 unsigned int tid = GET_TID(rpl);
2487 struct c4iw_ep *ep;
2488 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002489
2490 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002491 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002492
Steve Wise30c95c22011-05-09 22:06:22 -07002493 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002494 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2495 ep->com.qp->wq.sq.qid);
2496 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2497 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2498 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2499 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002500 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002501
Steve Wisecfdda9d2010-04-21 15:30:06 -07002502 return 0;
2503}
2504
2505/*
2506 * Upcall from the adapter indicating data has been transmitted.
2507 * For us its just the single MPA request or reply. We can now free
2508 * the skb holding the mpa message.
2509 */
2510static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2511{
2512 struct c4iw_ep *ep;
2513 struct cpl_fw4_ack *hdr = cplhdr(skb);
2514 u8 credits = hdr->credits;
2515 unsigned int tid = GET_TID(hdr);
2516 struct tid_info *t = dev->rdev.lldi.tids;
2517
2518
2519 ep = lookup_tid(t, tid);
2520 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2521 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002522 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2523 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002524 return 0;
2525 }
2526
2527 dst_confirm(ep->dst);
2528 if (ep->mpa_skb) {
2529 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2530 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2531 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2532 kfree_skb(ep->mpa_skb);
2533 ep->mpa_skb = NULL;
2534 }
2535 return 0;
2536}
2537
Steve Wisecfdda9d2010-04-21 15:30:06 -07002538int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2539{
Steve Wisea7db89e2014-03-21 20:40:35 +05302540 int err = 0;
2541 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002542 struct c4iw_ep *ep = to_ep(cm_id);
2543 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2544
Steve Wisea7db89e2014-03-21 20:40:35 +05302545 mutex_lock(&ep->com.mutex);
2546 if (ep->com.state == DEAD) {
2547 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002548 c4iw_put_ep(&ep->com);
2549 return -ECONNRESET;
2550 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002551 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302552 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002553 if (mpa_rev == 0)
2554 abort_connection(ep, NULL, GFP_KERNEL);
2555 else {
2556 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302557 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002558 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302559 mutex_unlock(&ep->com.mutex);
2560 if (disconnect)
2561 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002562 c4iw_put_ep(&ep->com);
2563 return 0;
2564}
2565
2566int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2567{
2568 int err;
2569 struct c4iw_qp_attributes attrs;
2570 enum c4iw_qp_attr_mask mask;
2571 struct c4iw_ep *ep = to_ep(cm_id);
2572 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2573 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2574
2575 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302576
2577 mutex_lock(&ep->com.mutex);
2578 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002579 err = -ECONNRESET;
2580 goto err;
2581 }
2582
Steve Wisea7db89e2014-03-21 20:40:35 +05302583 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002584 BUG_ON(!qp);
2585
Vipul Pandya793dad92012-12-10 09:30:56 +00002586 set_bit(ULP_ACCEPT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002587 if ((conn_param->ord > c4iw_max_read_depth) ||
2588 (conn_param->ird > c4iw_max_read_depth)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002589 abort_connection(ep, NULL, GFP_KERNEL);
2590 err = -EINVAL;
2591 goto err;
2592 }
2593
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302594 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2595 if (conn_param->ord > ep->ird) {
2596 ep->ird = conn_param->ird;
2597 ep->ord = conn_param->ord;
2598 send_mpa_reject(ep, conn_param->private_data,
2599 conn_param->private_data_len);
2600 abort_connection(ep, NULL, GFP_KERNEL);
2601 err = -ENOMEM;
2602 goto err;
2603 }
2604 if (conn_param->ird > ep->ord) {
2605 if (!ep->ord)
2606 conn_param->ird = 1;
2607 else {
2608 abort_connection(ep, NULL, GFP_KERNEL);
2609 err = -ENOMEM;
2610 goto err;
2611 }
2612 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002613
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302614 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002615 ep->ird = conn_param->ird;
2616 ep->ord = conn_param->ord;
2617
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302618 if (ep->mpa_attr.version != 2)
2619 if (peer2peer && ep->ird == 0)
2620 ep->ird = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002621
2622 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2623
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302624 cm_id->add_ref(cm_id);
2625 ep->com.cm_id = cm_id;
2626 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00002627 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302628
Steve Wisecfdda9d2010-04-21 15:30:06 -07002629 /* bind QP to EP and move to RTS */
2630 attrs.mpa_attr = ep->mpa_attr;
2631 attrs.max_ird = ep->ird;
2632 attrs.max_ord = ep->ord;
2633 attrs.llp_stream_handle = ep;
2634 attrs.next_state = C4IW_QP_STATE_RTS;
2635
2636 /* bind QP and TID with INIT_WR */
2637 mask = C4IW_QP_ATTR_NEXT_STATE |
2638 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2639 C4IW_QP_ATTR_MPA_ATTR |
2640 C4IW_QP_ATTR_MAX_IRD |
2641 C4IW_QP_ATTR_MAX_ORD;
2642
2643 err = c4iw_modify_qp(ep->com.qp->rhp,
2644 ep->com.qp, mask, &attrs, 1);
2645 if (err)
2646 goto err1;
2647 err = send_mpa_reply(ep, conn_param->private_data,
2648 conn_param->private_data_len);
2649 if (err)
2650 goto err1;
2651
Steve Wisea7db89e2014-03-21 20:40:35 +05302652 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002653 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05302654 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002655 c4iw_put_ep(&ep->com);
2656 return 0;
2657err1:
2658 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002659 cm_id->rem_ref(cm_id);
2660err:
Steve Wisea7db89e2014-03-21 20:40:35 +05302661 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002662 c4iw_put_ep(&ep->com);
2663 return err;
2664}
2665
Vipul Pandya830662f2013-07-04 16:10:47 +05302666static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2667{
2668 struct in_device *ind;
2669 int found = 0;
2670 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2671 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
2672
2673 ind = in_dev_get(dev->rdev.lldi.ports[0]);
2674 if (!ind)
2675 return -EADDRNOTAVAIL;
2676 for_primary_ifa(ind) {
2677 laddr->sin_addr.s_addr = ifa->ifa_address;
2678 raddr->sin_addr.s_addr = ifa->ifa_address;
2679 found = 1;
2680 break;
2681 }
2682 endfor_ifa(ind);
2683 in_dev_put(ind);
2684 return found ? 0 : -EADDRNOTAVAIL;
2685}
2686
2687static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
2688 unsigned char banned_flags)
2689{
2690 struct inet6_dev *idev;
2691 int err = -EADDRNOTAVAIL;
2692
2693 rcu_read_lock();
2694 idev = __in6_dev_get(dev);
2695 if (idev != NULL) {
2696 struct inet6_ifaddr *ifp;
2697
2698 read_lock_bh(&idev->lock);
2699 list_for_each_entry(ifp, &idev->addr_list, if_list) {
2700 if (ifp->scope == IFA_LINK &&
2701 !(ifp->flags & banned_flags)) {
2702 memcpy(addr, &ifp->addr, 16);
2703 err = 0;
2704 break;
2705 }
2706 }
2707 read_unlock_bh(&idev->lock);
2708 }
2709 rcu_read_unlock();
2710 return err;
2711}
2712
2713static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2714{
2715 struct in6_addr uninitialized_var(addr);
2716 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2717 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
2718
2719 if (get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
2720 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
2721 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
2722 return 0;
2723 }
2724 return -EADDRNOTAVAIL;
2725}
2726
Steve Wisecfdda9d2010-04-21 15:30:06 -07002727int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2728{
Steve Wisecfdda9d2010-04-21 15:30:06 -07002729 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2730 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00002731 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302732 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2733 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302734 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2735 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
2736 &cm_id->remote_addr;
2737 __u8 *ra;
2738 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002739
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002740 if ((conn_param->ord > c4iw_max_read_depth) ||
2741 (conn_param->ird > c4iw_max_read_depth)) {
2742 err = -EINVAL;
2743 goto out;
2744 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002745 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2746 if (!ep) {
2747 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2748 err = -ENOMEM;
2749 goto out;
2750 }
2751 init_timer(&ep->timer);
2752 ep->plen = conn_param->private_data_len;
2753 if (ep->plen)
2754 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2755 conn_param->private_data, ep->plen);
2756 ep->ird = conn_param->ird;
2757 ep->ord = conn_param->ord;
2758
2759 if (peer2peer && ep->ord == 0)
2760 ep->ord = 1;
2761
2762 cm_id->add_ref(cm_id);
2763 ep->com.dev = dev;
2764 ep->com.cm_id = cm_id;
2765 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05302766 if (!ep->com.qp) {
2767 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
2768 err = -EINVAL;
2769 goto fail2;
2770 }
Vipul Pandya325abea2013-01-07 13:11:53 +00002771 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002772 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2773 ep->com.qp, cm_id);
2774
2775 /*
2776 * Allocate an active TID to initiate a TCP connection.
2777 */
2778 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2779 if (ep->atid == -1) {
2780 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2781 err = -ENOMEM;
2782 goto fail2;
2783 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002784 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002785
Vipul Pandya830662f2013-07-04 16:10:47 +05302786 if (cm_id->remote_addr.ss_family == AF_INET) {
2787 iptype = 4;
2788 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002789
Vipul Pandya830662f2013-07-04 16:10:47 +05302790 /*
2791 * Handle loopback requests to INADDR_ANY.
2792 */
2793 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
2794 err = pick_local_ipaddrs(dev, cm_id);
2795 if (err)
2796 goto fail2;
2797 }
2798
2799 /* find a route */
2800 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
2801 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
2802 ra, ntohs(raddr->sin_port));
2803 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
2804 raddr->sin_addr.s_addr, laddr->sin_port,
2805 raddr->sin_port, 0);
2806 } else {
2807 iptype = 6;
2808 ra = (__u8 *)&raddr6->sin6_addr;
2809
2810 /*
2811 * Handle loopback requests to INADDR_ANY.
2812 */
2813 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
2814 err = pick_local_ip6addrs(dev, cm_id);
2815 if (err)
2816 goto fail2;
2817 }
2818
2819 /* find a route */
2820 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
2821 __func__, laddr6->sin6_addr.s6_addr,
2822 ntohs(laddr6->sin6_port),
2823 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
2824 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
2825 raddr6->sin6_addr.s6_addr,
2826 laddr6->sin6_port, raddr6->sin6_port, 0,
2827 raddr6->sin6_scope_id);
2828 }
2829 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002830 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
2831 err = -EHOSTUNREACH;
2832 goto fail3;
2833 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002834
Vipul Pandya830662f2013-07-04 16:10:47 +05302835 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true);
David Miller3786cf12011-12-02 16:52:31 +00002836 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002837 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002838 goto fail4;
2839 }
2840
2841 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2842 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2843 ep->l2t->idx);
2844
2845 state_set(&ep->com, CONNECTING);
2846 ep->tos = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302847 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2848 sizeof(ep->com.local_addr));
2849 memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
2850 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002851
2852 /* send connect request to rnic */
2853 err = send_connect(ep);
2854 if (!err)
2855 goto out;
2856
2857 cxgb4_l2t_release(ep->l2t);
2858fail4:
2859 dst_release(ep->dst);
2860fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00002861 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002862 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2863fail2:
2864 cm_id->rem_ref(cm_id);
2865 c4iw_put_ep(&ep->com);
2866out:
2867 return err;
2868}
2869
Vipul Pandya830662f2013-07-04 16:10:47 +05302870static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
2871{
2872 int err;
2873 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2874
2875 c4iw_init_wr_wait(&ep->com.wr_wait);
2876 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
2877 ep->stid, &sin6->sin6_addr,
2878 sin6->sin6_port,
2879 ep->com.dev->rdev.lldi.rxq_ids[0]);
2880 if (!err)
2881 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2882 &ep->com.wr_wait,
2883 0, 0, __func__);
2884 if (err)
2885 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
2886 err, ep->stid,
2887 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
2888 return err;
2889}
2890
2891static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
2892{
2893 int err;
2894 struct sockaddr_in *sin = (struct sockaddr_in *)&ep->com.local_addr;
2895
2896 if (dev->rdev.lldi.enable_fw_ofld_conn) {
2897 do {
2898 err = cxgb4_create_server_filter(
2899 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2900 sin->sin_addr.s_addr, sin->sin_port, 0,
2901 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
2902 if (err == -EBUSY) {
2903 set_current_state(TASK_UNINTERRUPTIBLE);
2904 schedule_timeout(usecs_to_jiffies(100));
2905 }
2906 } while (err == -EBUSY);
2907 } else {
2908 c4iw_init_wr_wait(&ep->com.wr_wait);
2909 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
2910 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
2911 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
2912 if (!err)
2913 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2914 &ep->com.wr_wait,
2915 0, 0, __func__);
2916 }
2917 if (err)
2918 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
2919 , err, ep->stid,
2920 &sin->sin_addr, ntohs(sin->sin_port));
2921 return err;
2922}
2923
Steve Wisecfdda9d2010-04-21 15:30:06 -07002924int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
2925{
2926 int err = 0;
2927 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2928 struct c4iw_listen_ep *ep;
2929
Steve Wisecfdda9d2010-04-21 15:30:06 -07002930 might_sleep();
2931
2932 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2933 if (!ep) {
2934 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2935 err = -ENOMEM;
2936 goto fail1;
2937 }
2938 PDBG("%s ep %p\n", __func__, ep);
2939 cm_id->add_ref(cm_id);
2940 ep->com.cm_id = cm_id;
2941 ep->com.dev = dev;
2942 ep->backlog = backlog;
Steve Wise24d44a32013-07-04 16:10:44 +05302943 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2944 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002945
2946 /*
2947 * Allocate a server TID.
2948 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05302949 if (dev->rdev.lldi.enable_fw_ofld_conn &&
2950 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05302951 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
2952 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002953 else
Vipul Pandya830662f2013-07-04 16:10:47 +05302954 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
2955 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002956
Steve Wisecfdda9d2010-04-21 15:30:06 -07002957 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002958 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002959 err = -ENOMEM;
2960 goto fail2;
2961 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002962 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002963 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05302964 if (ep->com.local_addr.ss_family == AF_INET)
2965 err = create_server4(dev, ep);
2966 else
2967 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002968 if (!err) {
2969 cm_id->provider_data = ep;
2970 goto out;
2971 }
Vipul Pandya830662f2013-07-04 16:10:47 +05302972 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
2973 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002974fail2:
2975 cm_id->rem_ref(cm_id);
2976 c4iw_put_ep(&ep->com);
2977fail1:
2978out:
2979 return err;
2980}
2981
2982int c4iw_destroy_listen(struct iw_cm_id *cm_id)
2983{
2984 int err;
2985 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
2986
2987 PDBG("%s ep %p\n", __func__, ep);
2988
2989 might_sleep();
2990 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05302991 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
2992 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002993 err = cxgb4_remove_server_filter(
2994 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2995 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
2996 } else {
2997 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05302998 err = cxgb4_remove_server(
2999 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3000 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003001 if (err)
3002 goto done;
3003 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3004 0, 0, __func__);
3005 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003006 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303007 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3008 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003009done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003010 cm_id->rem_ref(cm_id);
3011 c4iw_put_ep(&ep->com);
3012 return err;
3013}
3014
3015int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3016{
3017 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003018 int close = 0;
3019 int fatal = 0;
3020 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003021
Steve Wise2f5b48c2010-09-10 11:15:36 -05003022 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003023
3024 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3025 states[ep->com.state], abrupt);
3026
3027 rdev = &ep->com.dev->rdev;
3028 if (c4iw_fatal_error(rdev)) {
3029 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303030 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003031 ep->com.state = DEAD;
3032 }
3033 switch (ep->com.state) {
3034 case MPA_REQ_WAIT:
3035 case MPA_REQ_SENT:
3036 case MPA_REQ_RCVD:
3037 case MPA_REP_SENT:
3038 case FPDU_MODE:
3039 close = 1;
3040 if (abrupt)
3041 ep->com.state = ABORTING;
3042 else {
3043 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003044 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003045 }
3046 set_bit(CLOSE_SENT, &ep->com.flags);
3047 break;
3048 case CLOSING:
3049 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3050 close = 1;
3051 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003052 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003053 ep->com.state = ABORTING;
3054 } else
3055 ep->com.state = MORIBUND;
3056 }
3057 break;
3058 case MORIBUND:
3059 case ABORTING:
3060 case DEAD:
3061 PDBG("%s ignoring disconnect ep %p state %u\n",
3062 __func__, ep, ep->com.state);
3063 break;
3064 default:
3065 BUG();
3066 break;
3067 }
3068
Steve Wisecfdda9d2010-04-21 15:30:06 -07003069 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003070 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003071 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303072 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003073 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003074 } else {
3075 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003076 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003077 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003078 if (ret)
3079 fatal = 1;
3080 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003081 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003082 if (fatal)
3083 release_ep_resources(ep);
3084 return ret;
3085}
3086
Vipul Pandya1cab7752012-12-10 09:30:55 +00003087static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3088 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3089{
3090 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003091 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003092
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003093 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3094 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003095 if (!ep)
3096 return;
3097
3098 switch (req->retval) {
3099 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003100 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3101 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3102 send_fw_act_open_req(ep, atid);
3103 return;
3104 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003105 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003106 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3107 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3108 send_fw_act_open_req(ep, atid);
3109 return;
3110 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003111 break;
3112 default:
3113 pr_info("%s unexpected ofld conn wr retval %d\n",
3114 __func__, req->retval);
3115 break;
3116 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003117 pr_err("active ofld_connect_wr failure %d atid %d\n",
3118 req->retval, atid);
3119 mutex_lock(&dev->rdev.stats.lock);
3120 dev->rdev.stats.act_ofld_conn_fails++;
3121 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003122 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003123 state_set(&ep->com, DEAD);
3124 remove_handle(dev, &dev->atid_idr, atid);
3125 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3126 dst_release(ep->dst);
3127 cxgb4_l2t_release(ep->l2t);
3128 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003129}
3130
3131static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3132 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3133{
3134 struct sk_buff *rpl_skb;
3135 struct cpl_pass_accept_req *cpl;
3136 int ret;
3137
Paul Bolle710a3112013-02-05 20:51:30 +00003138 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003139 BUG_ON(!rpl_skb);
3140 if (req->retval) {
3141 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003142 mutex_lock(&dev->rdev.stats.lock);
3143 dev->rdev.stats.pas_ofld_conn_fails++;
3144 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003145 kfree_skb(rpl_skb);
3146 } else {
3147 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3148 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003149 (__force u32) htonl(
3150 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003151 ret = pass_accept_req(dev, rpl_skb);
3152 if (!ret)
3153 kfree_skb(rpl_skb);
3154 }
3155 return;
3156}
3157
3158static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003159{
3160 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003161 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3162
3163 switch (rpl->type) {
3164 case FW6_TYPE_CQE:
3165 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3166 break;
3167 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3168 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3169 switch (req->t_state) {
3170 case TCP_SYN_SENT:
3171 active_ofld_conn_reply(dev, skb, req);
3172 break;
3173 case TCP_SYN_RECV:
3174 passive_ofld_conn_reply(dev, skb, req);
3175 break;
3176 default:
3177 pr_err("%s unexpected ofld conn wr state %d\n",
3178 __func__, req->t_state);
3179 break;
3180 }
3181 break;
3182 }
3183 return 0;
3184}
3185
3186static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3187{
3188 u32 l2info;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003189 u16 vlantag, len, hdr_len, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003190 u8 intf;
3191 struct cpl_rx_pkt *cpl = cplhdr(skb);
3192 struct cpl_pass_accept_req *req;
3193 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003194 struct c4iw_dev *dev;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003195
Vipul Pandyaf079af72013-03-14 05:08:58 +00003196 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003197 /* Store values from cpl_rx_pkt in temporary location. */
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003198 vlantag = (__force u16) cpl->vlan;
3199 len = (__force u16) cpl->len;
3200 l2info = (__force u32) cpl->l2info;
3201 hdr_len = (__force u16) cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003202 intf = cpl->iff;
3203
3204 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3205
3206 /*
3207 * We need to parse the TCP options from SYN packet.
3208 * to generate cpl_pass_accept_req.
3209 */
3210 memset(&tmp_opt, 0, sizeof(tmp_opt));
3211 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003212 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003213
3214 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3215 memset(req, 0, sizeof(*req));
3216 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003217 V_SYN_MAC_IDX(G_RX_MACIDX(
3218 (__force int) htonl(l2info))) |
Vipul Pandya1cab7752012-12-10 09:30:55 +00003219 F_SYN_XACT_MATCH);
Vipul Pandyaf079af72013-03-14 05:08:58 +00003220 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3221 G_RX_ETHHDR_LEN((__force int) htonl(l2info)) :
3222 G_RX_T5_ETHHDR_LEN((__force int) htonl(l2info));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003223 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(
3224 (__force int) htonl(l2info))) |
3225 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(
3226 (__force int) htons(hdr_len))) |
3227 V_IP_HDR_LEN(G_RX_IPHDR_LEN(
3228 (__force int) htons(hdr_len))) |
Vipul Pandyaf079af72013-03-14 05:08:58 +00003229 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(eth_hdr_len)));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003230 req->vlan = (__force __be16) vlantag;
3231 req->len = (__force __be16) len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003232 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
3233 PASS_OPEN_TOS(tos));
3234 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3235 if (tmp_opt.wscale_ok)
3236 req->tcpopt.wsf = tmp_opt.snd_wscale;
3237 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3238 if (tmp_opt.sack_ok)
3239 req->tcpopt.sack = 1;
3240 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3241 return;
3242}
3243
3244static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3245 __be32 laddr, __be16 lport,
3246 __be32 raddr, __be16 rport,
3247 u32 rcv_isn, u32 filter, u16 window,
3248 u32 rss_qid, u8 port_id)
3249{
3250 struct sk_buff *req_skb;
3251 struct fw_ofld_connection_wr *req;
3252 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303253 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003254
3255 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3256 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3257 memset(req, 0, sizeof(*req));
3258 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
3259 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
3260 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003261 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003262 req->le.lport = lport;
3263 req->le.pport = rport;
3264 req->le.u.ipv4.lip = laddr;
3265 req->le.u.ipv4.pip = raddr;
3266 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3267 req->tcb.rcv_adv = htons(window);
3268 req->tcb.t_state_to_astid =
3269 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
3270 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
3271 V_FW_OFLD_CONNECTION_WR_ASTID(
3272 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
3273
3274 /*
3275 * We store the qid in opt2 which will be used by the firmware
3276 * to send us the wr response.
3277 */
3278 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
3279
3280 /*
3281 * We initialize the MSS index in TCB to 0xF.
3282 * So that when driver sends cpl_pass_accept_rpl
3283 * TCB picks up the correct value. If this was 0
3284 * TP will ignore any value > 0 for MSS index.
3285 */
3286 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
Paul Bolle710a3112013-02-05 20:51:30 +00003287 req->cookie = (unsigned long)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003288
3289 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303290 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3291 if (ret < 0) {
3292 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3293 ret);
3294 kfree_skb(skb);
3295 kfree_skb(req_skb);
3296 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003297}
3298
3299/*
3300 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3301 * messages when a filter is being used instead of server to
3302 * redirect a syn packet. When packets hit filter they are redirected
3303 * to the offload queue and driver tries to establish the connection
3304 * using firmware work request.
3305 */
3306static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3307{
3308 int stid;
3309 unsigned int filter;
3310 struct ethhdr *eh = NULL;
3311 struct vlan_ethhdr *vlan_eh = NULL;
3312 struct iphdr *iph;
3313 struct tcphdr *tcph;
3314 struct rss_header *rss = (void *)skb->data;
3315 struct cpl_rx_pkt *cpl = (void *)skb->data;
3316 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3317 struct l2t_entry *e;
3318 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003319 struct c4iw_ep *lep;
3320 u16 window;
3321 struct port_info *pi;
3322 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003323 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003324 int step;
3325 u32 tx_chan;
3326 struct neighbour *neigh;
3327
3328 /* Drop all non-SYN packets */
3329 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
3330 goto reject;
3331
3332 /*
3333 * Drop all packets which did not hit the filter.
3334 * Unlikely to happen.
3335 */
3336 if (!(rss->filter_hit && rss->filter_tid))
3337 goto reject;
3338
3339 /*
3340 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3341 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303342 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003343
3344 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3345 if (!lep) {
3346 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3347 goto reject;
3348 }
3349
Vipul Pandyaf079af72013-03-14 05:08:58 +00003350 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3351 G_RX_ETHHDR_LEN(htonl(cpl->l2info)) :
3352 G_RX_T5_ETHHDR_LEN(htonl(cpl->l2info));
3353 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003354 eh = (struct ethhdr *)(req + 1);
3355 iph = (struct iphdr *)(eh + 1);
3356 } else {
3357 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3358 iph = (struct iphdr *)(vlan_eh + 1);
3359 skb->vlan_tci = ntohs(cpl->vlan);
3360 }
3361
3362 if (iph->version != 0x4)
3363 goto reject;
3364
3365 tcph = (struct tcphdr *)(iph + 1);
3366 skb_set_network_header(skb, (void *)iph - (void *)rss);
3367 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3368 skb_get(skb);
3369
3370 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3371 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3372 ntohs(tcph->source), iph->tos);
3373
Vipul Pandya830662f2013-07-04 16:10:47 +05303374 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3375 iph->tos);
3376 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003377 pr_err("%s - failed to find dst entry!\n",
3378 __func__);
3379 goto reject;
3380 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003381 neigh = dst_neigh_lookup_skb(dst, skb);
3382
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003383 if (!neigh) {
3384 pr_err("%s - failed to allocate neigh!\n",
3385 __func__);
3386 goto free_dst;
3387 }
3388
Vipul Pandya1cab7752012-12-10 09:30:55 +00003389 if (neigh->dev->flags & IFF_LOOPBACK) {
3390 pdev = ip_dev_find(&init_net, iph->daddr);
3391 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3392 pdev, 0);
3393 pi = (struct port_info *)netdev_priv(pdev);
3394 tx_chan = cxgb4_port_chan(pdev);
3395 dev_put(pdev);
3396 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303397 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003398 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303399 pdev, 0);
3400 pi = (struct port_info *)netdev_priv(pdev);
3401 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003402 }
Steve Wiseebf00062014-03-19 17:44:40 +05303403 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003404 if (!e) {
3405 pr_err("%s - failed to allocate l2t entry!\n",
3406 __func__);
3407 goto free_dst;
3408 }
3409
3410 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3411 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003412 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003413
3414 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303415 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3416 dev->rdev.lldi.ports[0],
3417 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003418
3419 /*
3420 * Synthesize the cpl_pass_accept_req. We have everything except the
3421 * TID. Once firmware sends a reply with TID we update the TID field
3422 * in cpl and pass it through the regular cpl_pass_accept_req path.
3423 */
3424 build_cpl_pass_accept_req(skb, stid, iph->tos);
3425 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3426 tcph->source, ntohl(tcph->seq), filter, window,
3427 rss_qid, pi->port_id);
3428 cxgb4_l2t_release(e);
3429free_dst:
3430 dst_release(dst);
3431reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003432 return 0;
3433}
3434
Steve Wisecfdda9d2010-04-21 15:30:06 -07003435/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003436 * These are the real handlers that are called from a
3437 * work queue.
3438 */
3439static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3440 [CPL_ACT_ESTABLISH] = act_establish,
3441 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3442 [CPL_RX_DATA] = rx_data,
3443 [CPL_ABORT_RPL_RSS] = abort_rpl,
3444 [CPL_ABORT_RPL] = abort_rpl,
3445 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3446 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3447 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3448 [CPL_PASS_ESTABLISH] = pass_establish,
3449 [CPL_PEER_CLOSE] = peer_close,
3450 [CPL_ABORT_REQ_RSS] = peer_abort,
3451 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3452 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003453 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003454 [CPL_FW6_MSG] = deferred_fw6_msg,
3455 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003456};
3457
3458static void process_timeout(struct c4iw_ep *ep)
3459{
3460 struct c4iw_qp_attributes attrs;
3461 int abort = 1;
3462
Steve Wise2f5b48c2010-09-10 11:15:36 -05003463 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003464 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3465 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003466 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003467 switch (ep->com.state) {
3468 case MPA_REQ_SENT:
3469 __state_set(&ep->com, ABORTING);
3470 connect_reply_upcall(ep, -ETIMEDOUT);
3471 break;
3472 case MPA_REQ_WAIT:
3473 __state_set(&ep->com, ABORTING);
3474 break;
3475 case CLOSING:
3476 case MORIBUND:
3477 if (ep->com.cm_id && ep->com.qp) {
3478 attrs.next_state = C4IW_QP_STATE_ERROR;
3479 c4iw_modify_qp(ep->com.qp->rhp,
3480 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3481 &attrs, 1);
3482 }
3483 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303484 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003485 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003486 case ABORTING:
3487 case DEAD:
3488
3489 /*
3490 * These states are expected if the ep timed out at the same
3491 * time as another thread was calling stop_ep_timer().
3492 * So we silently do nothing for these states.
3493 */
3494 abort = 0;
3495 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003496 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003497 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003498 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003499 abort = 0;
3500 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003501 if (abort)
3502 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecc18b932014-04-24 14:31:53 -05003503 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003504 c4iw_put_ep(&ep->com);
3505}
3506
3507static void process_timedout_eps(void)
3508{
3509 struct c4iw_ep *ep;
3510
3511 spin_lock_irq(&timeout_lock);
3512 while (!list_empty(&timeout_list)) {
3513 struct list_head *tmp;
3514
3515 tmp = timeout_list.next;
3516 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003517 tmp->next = NULL;
3518 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003519 spin_unlock_irq(&timeout_lock);
3520 ep = list_entry(tmp, struct c4iw_ep, entry);
3521 process_timeout(ep);
3522 spin_lock_irq(&timeout_lock);
3523 }
3524 spin_unlock_irq(&timeout_lock);
3525}
3526
3527static void process_work(struct work_struct *work)
3528{
3529 struct sk_buff *skb = NULL;
3530 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003531 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003532 unsigned int opcode;
3533 int ret;
3534
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003535 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003536 while ((skb = skb_dequeue(&rxq))) {
3537 rpl = cplhdr(skb);
3538 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3539 opcode = rpl->ot.opcode;
3540
3541 BUG_ON(!work_handlers[opcode]);
3542 ret = work_handlers[opcode](dev, skb);
3543 if (!ret)
3544 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003545 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003546 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003547}
3548
3549static DECLARE_WORK(skb_work, process_work);
3550
3551static void ep_timeout(unsigned long arg)
3552{
3553 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003554 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003555
3556 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003557 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003558 /*
3559 * Only insert if it is not already on the list.
3560 */
3561 if (!ep->entry.next) {
3562 list_add_tail(&ep->entry, &timeout_list);
3563 kickit = 1;
3564 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003565 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003566 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003567 if (kickit)
3568 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003569}
3570
3571/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07003572 * All the CM events are handled on a work queue to have a safe context.
3573 */
3574static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3575{
3576
3577 /*
3578 * Save dev in the skb->cb area.
3579 */
3580 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3581
3582 /*
3583 * Queue the skb and schedule the worker thread.
3584 */
3585 skb_queue_tail(&rxq, skb);
3586 queue_work(workq, &skb_work);
3587 return 0;
3588}
3589
3590static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3591{
3592 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3593
3594 if (rpl->status != CPL_ERR_NONE) {
3595 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3596 "for tid %u\n", rpl->status, GET_TID(rpl));
3597 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003598 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003599 return 0;
3600}
3601
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003602static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3603{
3604 struct cpl_fw6_msg *rpl = cplhdr(skb);
3605 struct c4iw_wr_wait *wr_waitp;
3606 int ret;
3607
3608 PDBG("%s type %u\n", __func__, rpl->type);
3609
3610 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003611 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003612 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07003613 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003614 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07003615 if (wr_waitp)
3616 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003617 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003618 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003619 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003620 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00003621 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003622 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003623 default:
3624 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3625 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003626 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003627 break;
3628 }
3629 return 0;
3630}
3631
Steve Wise8da7e7a2011-06-14 20:59:27 +00003632static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3633{
3634 struct cpl_abort_req_rss *req = cplhdr(skb);
3635 struct c4iw_ep *ep;
3636 struct tid_info *t = dev->rdev.lldi.tids;
3637 unsigned int tid = GET_TID(req);
3638
3639 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05003640 if (!ep) {
3641 printk(KERN_WARNING MOD
3642 "Abort on non-existent endpoint, tid %d\n", tid);
3643 kfree_skb(skb);
3644 return 0;
3645 }
Steve Wise7a2cea22014-03-14 21:52:07 +05303646 if (is_neg_adv(req->status)) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003647 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3648 ep->hwtid);
3649 kfree_skb(skb);
3650 return 0;
3651 }
3652 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3653 ep->com.state);
3654
3655 /*
3656 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003657 * However, if we are on MPAv2 and want to retry with MPAv1
3658 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00003659 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003660 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
3661 if (ep->com.state != MPA_REQ_SENT)
3662 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3663 } else
3664 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003665 sched(dev, skb);
3666 return 0;
3667}
3668
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003669/*
3670 * Most upcalls from the T4 Core go to sched() to
3671 * schedule the processing on a work queue.
3672 */
3673c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3674 [CPL_ACT_ESTABLISH] = sched,
3675 [CPL_ACT_OPEN_RPL] = sched,
3676 [CPL_RX_DATA] = sched,
3677 [CPL_ABORT_RPL_RSS] = sched,
3678 [CPL_ABORT_RPL] = sched,
3679 [CPL_PASS_OPEN_RPL] = sched,
3680 [CPL_CLOSE_LISTSRV_RPL] = sched,
3681 [CPL_PASS_ACCEPT_REQ] = sched,
3682 [CPL_PASS_ESTABLISH] = sched,
3683 [CPL_PEER_CLOSE] = sched,
3684 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00003685 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003686 [CPL_RDMA_TERMINATE] = sched,
3687 [CPL_FW4_ACK] = sched,
3688 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003689 [CPL_FW6_MSG] = fw6_msg,
3690 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003691};
3692
Steve Wisecfdda9d2010-04-21 15:30:06 -07003693int __init c4iw_cm_init(void)
3694{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003695 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003696 skb_queue_head_init(&rxq);
3697
3698 workq = create_singlethread_workqueue("iw_cxgb4");
3699 if (!workq)
3700 return -ENOMEM;
3701
Steve Wisecfdda9d2010-04-21 15:30:06 -07003702 return 0;
3703}
3704
3705void __exit c4iw_cm_term(void)
3706{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003707 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003708 flush_workqueue(workq);
3709 destroy_workqueue(workq);
3710}