blob: 5e153f6d4b48f2d36abcceec8dcee0996e5bf6d1 [file] [log] [blame]
Steve Wisecfdda9d2010-04-21 15:30:06 -07001/*
Steve Wise9eccfe12014-03-26 17:08:09 -05002 * Copyright (c) 2009-2014 Chelsio, Inc. All rights reserved.
Steve Wisecfdda9d2010-04-21 15:30:06 -07003 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32#include <linux/module.h>
33#include <linux/list.h>
34#include <linux/workqueue.h>
35#include <linux/skbuff.h>
36#include <linux/timer.h>
37#include <linux/notifier.h>
38#include <linux/inetdevice.h>
39#include <linux/ip.h>
40#include <linux/tcp.h>
Vipul Pandya1cab7752012-12-10 09:30:55 +000041#include <linux/if_vlan.h>
Steve Wisecfdda9d2010-04-21 15:30:06 -070042
43#include <net/neighbour.h>
44#include <net/netevent.h>
45#include <net/route.h>
Vipul Pandya1cab7752012-12-10 09:30:55 +000046#include <net/tcp.h>
Vipul Pandya830662f2013-07-04 16:10:47 +053047#include <net/ip6_route.h>
48#include <net/addrconf.h>
Steve Wisecfdda9d2010-04-21 15:30:06 -070049
Steve Wise11b8e222014-05-16 12:42:46 -050050#include <rdma/ib_addr.h>
51
Steve Wisecfdda9d2010-04-21 15:30:06 -070052#include "iw_cxgb4.h"
53
54static char *states[] = {
55 "idle",
56 "listen",
57 "connecting",
58 "mpa_wait_req",
59 "mpa_req_sent",
60 "mpa_req_rcvd",
61 "mpa_rep_sent",
62 "fpdu_mode",
63 "aborting",
64 "closing",
65 "moribund",
66 "dead",
67 NULL,
68};
69
Vipul Pandya5be78ee2012-12-10 09:30:54 +000070static int nocong;
71module_param(nocong, int, 0644);
72MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
73
74static int enable_ecn;
75module_param(enable_ecn, int, 0644);
76MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
77
Steve Wiseb52fe092011-03-11 22:30:01 +000078static int dack_mode = 1;
Steve Wiseba6d3922010-06-23 15:46:49 +000079module_param(dack_mode, int, 0644);
Steve Wiseb52fe092011-03-11 22:30:01 +000080MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
Steve Wiseba6d3922010-06-23 15:46:49 +000081
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{
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530237 ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] -
238 sizeof(struct iphdr) - sizeof(struct tcphdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700239 ep->mss = ep->emss;
240 if (GET_TCPOPT_TSTAMP(opt))
241 ep->emss -= 12;
242 if (ep->emss < 128)
243 ep->emss = 128;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530244 if (ep->emss & 7)
245 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
246 GET_TCPOPT_MSS(opt), ep->mss, ep->emss);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700247 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
248 ep->mss, ep->emss);
249}
250
251static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
252{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700253 enum c4iw_ep_state state;
254
Steve Wise2f5b48c2010-09-10 11:15:36 -0500255 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700256 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500257 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700258 return state;
259}
260
261static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
262{
263 epc->state = new;
264}
265
266static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
267{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500268 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700269 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
270 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500271 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700272 return;
273}
274
275static void *alloc_ep(int size, gfp_t gfp)
276{
277 struct c4iw_ep_common *epc;
278
279 epc = kzalloc(size, gfp);
280 if (epc) {
281 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500282 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500283 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700284 }
285 PDBG("%s alloc ep %p\n", __func__, epc);
286 return epc;
287}
288
289void _c4iw_free_ep(struct kref *kref)
290{
291 struct c4iw_ep *ep;
292
293 ep = container_of(kref, struct c4iw_ep, com.kref);
294 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000295 if (test_bit(QP_REFERENCED, &ep->com.flags))
296 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700297 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000298 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700299 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
300 dst_release(ep->dst);
301 cxgb4_l2t_release(ep->l2t);
302 }
Steve Wise9eccfe12014-03-26 17:08:09 -0500303 if (test_bit(RELEASE_MAPINFO, &ep->com.flags)) {
304 print_addr(&ep->com, __func__, "remove_mapinfo/mapping");
305 iwpm_remove_mapinfo(&ep->com.local_addr,
306 &ep->com.mapped_local_addr);
307 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
308 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700309 kfree(ep);
310}
311
312static void release_ep_resources(struct c4iw_ep *ep)
313{
314 set_bit(RELEASE_RESOURCES, &ep->com.flags);
315 c4iw_put_ep(&ep->com);
316}
317
Steve Wisecfdda9d2010-04-21 15:30:06 -0700318static int status2errno(int status)
319{
320 switch (status) {
321 case CPL_ERR_NONE:
322 return 0;
323 case CPL_ERR_CONN_RESET:
324 return -ECONNRESET;
325 case CPL_ERR_ARP_MISS:
326 return -EHOSTUNREACH;
327 case CPL_ERR_CONN_TIMEDOUT:
328 return -ETIMEDOUT;
329 case CPL_ERR_TCAM_FULL:
330 return -ENOMEM;
331 case CPL_ERR_CONN_EXIST:
332 return -EADDRINUSE;
333 default:
334 return -EIO;
335 }
336}
337
338/*
339 * Try and reuse skbs already allocated...
340 */
341static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
342{
343 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
344 skb_trim(skb, 0);
345 skb_get(skb);
346 skb_reset_transport_header(skb);
347 } else {
348 skb = alloc_skb(len, gfp);
349 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530350 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700351 return skb;
352}
353
Vipul Pandya830662f2013-07-04 16:10:47 +0530354static struct net_device *get_real_dev(struct net_device *egress_dev)
355{
Steve Wise11b8e222014-05-16 12:42:46 -0500356 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530357}
358
359static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
360{
361 int i;
362
363 egress_dev = get_real_dev(egress_dev);
364 for (i = 0; i < dev->rdev.lldi.nports; i++)
365 if (dev->rdev.lldi.ports[i] == egress_dev)
366 return 1;
367 return 0;
368}
369
370static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
371 __u8 *peer_ip, __be16 local_port,
372 __be16 peer_port, u8 tos,
373 __u32 sin6_scope_id)
374{
375 struct dst_entry *dst = NULL;
376
377 if (IS_ENABLED(CONFIG_IPV6)) {
378 struct flowi6 fl6;
379
380 memset(&fl6, 0, sizeof(fl6));
381 memcpy(&fl6.daddr, peer_ip, 16);
382 memcpy(&fl6.saddr, local_ip, 16);
383 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
384 fl6.flowi6_oif = sin6_scope_id;
385 dst = ip6_route_output(&init_net, NULL, &fl6);
386 if (!dst)
387 goto out;
388 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
389 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
390 dst_release(dst);
391 dst = NULL;
392 }
393 }
394
395out:
396 return dst;
397}
398
399static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700400 __be32 peer_ip, __be16 local_port,
401 __be16 peer_port, u8 tos)
402{
403 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700404 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530405 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700406
David S. Miller31e4543d2011-05-03 20:25:42 -0700407 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500408 peer_port, local_port, IPPROTO_TCP,
409 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800410 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700411 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530412 n = dst_neigh_lookup(&rt->dst, &peer_ip);
413 if (!n)
414 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530415 if (!our_interface(dev, n->dev) &&
416 !(n->dev->flags & IFF_LOOPBACK)) {
Vipul Pandya830662f2013-07-04 16:10:47 +0530417 dst_release(&rt->dst);
418 return NULL;
419 }
420 neigh_release(n);
421 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700422}
423
424static void arp_failure_discard(void *handle, struct sk_buff *skb)
425{
426 PDBG("%s c4iw_dev %p\n", __func__, handle);
427 kfree_skb(skb);
428}
429
430/*
431 * Handle an ARP failure for an active open.
432 */
433static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
434{
435 printk(KERN_ERR MOD "ARP failure duing connect\n");
436 kfree_skb(skb);
437}
438
439/*
440 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
441 * and send it along.
442 */
443static void abort_arp_failure(void *handle, struct sk_buff *skb)
444{
445 struct c4iw_rdev *rdev = handle;
446 struct cpl_abort_req *req = cplhdr(skb);
447
448 PDBG("%s rdev %p\n", __func__, rdev);
449 req->cmd = CPL_ABORT_NO_RST;
450 c4iw_ofld_send(rdev, skb);
451}
452
453static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
454{
455 unsigned int flowclen = 80;
456 struct fw_flowc_wr *flowc;
457 int i;
458
459 skb = get_skb(skb, flowclen, GFP_KERNEL);
460 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
461
462 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
463 FW_FLOWC_WR_NPARAMS(8));
464 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
465 16)) | FW_WR_FLOWID(ep->hwtid));
466
467 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Steve Wise94788652011-01-21 17:00:34 +0000468 flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700469 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
470 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
471 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
472 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
473 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
474 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
475 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
476 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
477 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
478 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
479 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530480 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700481 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
482 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
483 /* Pad WR to 16 byte boundary */
484 flowc->mnemval[8].mnemonic = 0;
485 flowc->mnemval[8].val = 0;
486 for (i = 0; i < 9; i++) {
487 flowc->mnemval[i].r4[0] = 0;
488 flowc->mnemval[i].r4[1] = 0;
489 flowc->mnemval[i].r4[2] = 0;
490 }
491
492 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
493 c4iw_ofld_send(&ep->com.dev->rdev, skb);
494}
495
496static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
497{
498 struct cpl_close_con_req *req;
499 struct sk_buff *skb;
500 int wrlen = roundup(sizeof *req, 16);
501
502 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
503 skb = get_skb(NULL, wrlen, gfp);
504 if (!skb) {
505 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
506 return -ENOMEM;
507 }
508 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
509 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
510 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
511 memset(req, 0, wrlen);
512 INIT_TP_WR(req, ep->hwtid);
513 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
514 ep->hwtid));
515 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
516}
517
518static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
519{
520 struct cpl_abort_req *req;
521 int wrlen = roundup(sizeof *req, 16);
522
523 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
524 skb = get_skb(skb, wrlen, gfp);
525 if (!skb) {
526 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
527 __func__);
528 return -ENOMEM;
529 }
530 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
531 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
532 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
533 memset(req, 0, wrlen);
534 INIT_TP_WR(req, ep->hwtid);
535 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
536 req->cmd = CPL_ABORT_SEND_RST;
537 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
538}
539
Steve Wise9eccfe12014-03-26 17:08:09 -0500540/*
541 * c4iw_form_pm_msg - Form a port mapper message with mapping info
542 */
543static void c4iw_form_pm_msg(struct c4iw_ep *ep,
544 struct iwpm_sa_data *pm_msg)
545{
546 memcpy(&pm_msg->loc_addr, &ep->com.local_addr,
547 sizeof(ep->com.local_addr));
548 memcpy(&pm_msg->rem_addr, &ep->com.remote_addr,
549 sizeof(ep->com.remote_addr));
550}
551
552/*
553 * c4iw_form_reg_msg - Form a port mapper message with dev info
554 */
555static void c4iw_form_reg_msg(struct c4iw_dev *dev,
556 struct iwpm_dev_data *pm_msg)
557{
558 memcpy(pm_msg->dev_name, dev->ibdev.name, IWPM_DEVNAME_SIZE);
559 memcpy(pm_msg->if_name, dev->rdev.lldi.ports[0]->name,
560 IWPM_IFNAME_SIZE);
561}
562
563static void c4iw_record_pm_msg(struct c4iw_ep *ep,
564 struct iwpm_sa_data *pm_msg)
565{
566 memcpy(&ep->com.mapped_local_addr, &pm_msg->mapped_loc_addr,
567 sizeof(ep->com.mapped_local_addr));
568 memcpy(&ep->com.mapped_remote_addr, &pm_msg->mapped_rem_addr,
569 sizeof(ep->com.mapped_remote_addr));
570}
571
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530572static void best_mtu(const unsigned short *mtus, unsigned short mtu,
573 unsigned int *idx, int use_ts)
574{
575 unsigned short hdr_size = sizeof(struct iphdr) +
576 sizeof(struct tcphdr) +
577 (use_ts ? 12 : 0);
578 unsigned short data_size = mtu - hdr_size;
579
580 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
581}
582
Steve Wisecfdda9d2010-04-21 15:30:06 -0700583static int send_connect(struct c4iw_ep *ep)
584{
585 struct cpl_act_open_req *req;
Vipul Pandyaf079af72013-03-14 05:08:58 +0000586 struct cpl_t5_act_open_req *t5_req;
Vipul Pandya830662f2013-07-04 16:10:47 +0530587 struct cpl_act_open_req6 *req6;
588 struct cpl_t5_act_open_req6 *t5_req6;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700589 struct sk_buff *skb;
590 u64 opt0;
591 u32 opt2;
592 unsigned int mtu_idx;
593 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +0530594 int wrlen;
595 int sizev4 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
596 sizeof(struct cpl_act_open_req) :
597 sizeof(struct cpl_t5_act_open_req);
598 int sizev6 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
599 sizeof(struct cpl_act_open_req6) :
600 sizeof(struct cpl_t5_act_open_req6);
Steve Wise9eccfe12014-03-26 17:08:09 -0500601 struct sockaddr_in *la = (struct sockaddr_in *)
602 &ep->com.mapped_local_addr;
603 struct sockaddr_in *ra = (struct sockaddr_in *)
604 &ep->com.mapped_remote_addr;
605 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
606 &ep->com.mapped_local_addr;
607 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
608 &ep->com.mapped_remote_addr;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530609 int win;
Vipul Pandya830662f2013-07-04 16:10:47 +0530610
611 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
612 roundup(sizev4, 16) :
613 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700614
615 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
616
617 skb = get_skb(NULL, wrlen, GFP_KERNEL);
618 if (!skb) {
619 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
620 __func__);
621 return -ENOMEM;
622 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000623 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700624
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530625 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
626 enable_tcp_timestamps);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700627 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530628
629 /*
630 * Specify the largest window that will fit in opt0. The
631 * remainder will be specified in the rx_data_ack.
632 */
633 win = ep->rcv_win >> 10;
634 if (win > RCV_BUFSIZ_MASK)
635 win = RCV_BUFSIZ_MASK;
636
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000637 opt0 = (nocong ? NO_CONG(1) : 0) |
638 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +0000639 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700640 WND_SCALE(wscale) |
641 MSS_IDX(mtu_idx) |
642 L2T_IDX(ep->l2t->idx) |
643 TX_CHAN(ep->tx_chan) |
644 SMAC_SEL(ep->smac_idx) |
645 DSCP(ep->tos) |
Steve Wiseb48f3b92011-03-11 22:30:21 +0000646 ULP_MODE(ULP_MODE_TCPDDP) |
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530647 RCV_BUFSIZ(win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700648 opt2 = RX_CHANNEL(0) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000649 CCTRL_ECN(enable_ecn) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700650 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
651 if (enable_tcp_timestamps)
652 opt2 |= TSTAMPS_EN(1);
653 if (enable_tcp_sack)
654 opt2 |= SACK_EN(1);
655 if (wscale && enable_tcp_window_scaling)
656 opt2 |= WND_SCALE_EN(1);
Steve Wise92e50112014-04-24 14:31:59 -0500657 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
658 opt2 |= T5_OPT_2_VALID;
659 opt2 |= V_CONG_CNTRL(CONG_ALG_TAHOE);
660 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700661 t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
662
Vipul Pandyaf079af72013-03-14 05:08:58 +0000663 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Vipul Pandya830662f2013-07-04 16:10:47 +0530664 if (ep->com.remote_addr.ss_family == AF_INET) {
665 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
666 INIT_TP_WR(req, 0);
667 OPCODE_TID(req) = cpu_to_be32(
Vipul Pandyaf079af72013-03-14 05:08:58 +0000668 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
669 ((ep->rss_qid << 14) | ep->atid)));
Vipul Pandya830662f2013-07-04 16:10:47 +0530670 req->local_port = la->sin_port;
671 req->peer_port = ra->sin_port;
672 req->local_ip = la->sin_addr.s_addr;
673 req->peer_ip = ra->sin_addr.s_addr;
674 req->opt0 = cpu_to_be64(opt0);
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530675 req->params = cpu_to_be32(cxgb4_select_ntuple(
676 ep->com.dev->rdev.lldi.ports[0],
677 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530678 req->opt2 = cpu_to_be32(opt2);
679 } else {
680 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
681
682 INIT_TP_WR(req6, 0);
683 OPCODE_TID(req6) = cpu_to_be32(
684 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
685 ((ep->rss_qid<<14)|ep->atid)));
686 req6->local_port = la6->sin6_port;
687 req6->peer_port = ra6->sin6_port;
688 req6->local_ip_hi = *((__be64 *)
689 (la6->sin6_addr.s6_addr));
690 req6->local_ip_lo = *((__be64 *)
691 (la6->sin6_addr.s6_addr + 8));
692 req6->peer_ip_hi = *((__be64 *)
693 (ra6->sin6_addr.s6_addr));
694 req6->peer_ip_lo = *((__be64 *)
695 (ra6->sin6_addr.s6_addr + 8));
696 req6->opt0 = cpu_to_be64(opt0);
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530697 req6->params = cpu_to_be32(cxgb4_select_ntuple(
698 ep->com.dev->rdev.lldi.ports[0],
699 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530700 req6->opt2 = cpu_to_be32(opt2);
701 }
702 } else {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530703 u32 isn = (prandom_u32() & ~7UL) - 1;
704
705 opt2 |= T5_OPT_2_VALID;
706 opt2 |= CONG_CNTRL_VALID; /* OPT_2_ISS for T5 */
707 if (peer2peer)
708 isn += 4;
709
Vipul Pandya830662f2013-07-04 16:10:47 +0530710 if (ep->com.remote_addr.ss_family == AF_INET) {
711 t5_req = (struct cpl_t5_act_open_req *)
712 skb_put(skb, wrlen);
713 INIT_TP_WR(t5_req, 0);
714 OPCODE_TID(t5_req) = cpu_to_be32(
715 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
716 ((ep->rss_qid << 14) | ep->atid)));
717 t5_req->local_port = la->sin_port;
718 t5_req->peer_port = ra->sin_port;
719 t5_req->local_ip = la->sin_addr.s_addr;
720 t5_req->peer_ip = ra->sin_addr.s_addr;
721 t5_req->opt0 = cpu_to_be64(opt0);
722 t5_req->params = cpu_to_be64(V_FILTER_TUPLE(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530723 cxgb4_select_ntuple(
724 ep->com.dev->rdev.lldi.ports[0],
725 ep->l2t)));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530726 t5_req->rsvd = cpu_to_be32(isn);
727 PDBG("%s snd_isn %u\n", __func__,
728 be32_to_cpu(t5_req->rsvd));
Vipul Pandya830662f2013-07-04 16:10:47 +0530729 t5_req->opt2 = cpu_to_be32(opt2);
730 } else {
731 t5_req6 = (struct cpl_t5_act_open_req6 *)
732 skb_put(skb, wrlen);
733 INIT_TP_WR(t5_req6, 0);
734 OPCODE_TID(t5_req6) = cpu_to_be32(
735 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
736 ((ep->rss_qid<<14)|ep->atid)));
737 t5_req6->local_port = la6->sin6_port;
738 t5_req6->peer_port = ra6->sin6_port;
739 t5_req6->local_ip_hi = *((__be64 *)
740 (la6->sin6_addr.s6_addr));
741 t5_req6->local_ip_lo = *((__be64 *)
742 (la6->sin6_addr.s6_addr + 8));
743 t5_req6->peer_ip_hi = *((__be64 *)
744 (ra6->sin6_addr.s6_addr));
745 t5_req6->peer_ip_lo = *((__be64 *)
746 (ra6->sin6_addr.s6_addr + 8));
747 t5_req6->opt0 = cpu_to_be64(opt0);
748 t5_req6->params = (__force __be64)cpu_to_be32(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530749 cxgb4_select_ntuple(
750 ep->com.dev->rdev.lldi.ports[0],
751 ep->l2t));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530752 t5_req6->rsvd = cpu_to_be32(isn);
753 PDBG("%s snd_isn %u\n", __func__,
754 be32_to_cpu(t5_req6->rsvd));
Vipul Pandya830662f2013-07-04 16:10:47 +0530755 t5_req6->opt2 = cpu_to_be32(opt2);
756 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000757 }
758
Vipul Pandya793dad92012-12-10 09:30:56 +0000759 set_bit(ACT_OPEN_REQ, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700760 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
761}
762
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530763static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
764 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700765{
766 int mpalen, wrlen;
767 struct fw_ofld_tx_data_wr *req;
768 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530769 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700770
771 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
772
773 BUG_ON(skb_cloned(skb));
774
775 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530776 if (mpa_rev_to_use == 2)
777 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700778 wrlen = roundup(mpalen + sizeof *req, 16);
779 skb = get_skb(skb, wrlen, GFP_KERNEL);
780 if (!skb) {
781 connect_reply_upcall(ep, -ENOMEM);
782 return;
783 }
784 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
785
786 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
787 memset(req, 0, wrlen);
788 req->op_to_immdlen = cpu_to_be32(
789 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
790 FW_WR_COMPL(1) |
791 FW_WR_IMMDLEN(mpalen));
792 req->flowid_len16 = cpu_to_be32(
793 FW_WR_FLOWID(ep->hwtid) |
794 FW_WR_LEN16(wrlen >> 4));
795 req->plen = cpu_to_be32(mpalen);
796 req->tunnel_to_proxy = cpu_to_be32(
797 FW_OFLD_TX_DATA_WR_FLUSH(1) |
798 FW_OFLD_TX_DATA_WR_SHOVE(1));
799
800 mpa = (struct mpa_message *)(req + 1);
801 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
802 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530803 (markers_enabled ? MPA_MARKERS : 0) |
804 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700805 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530806 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530807 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530808 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530809 ep->retry_with_mpa_v1 = 0;
810 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700811
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530812 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700813 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
814 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530815 mpa_v2_params.ird = htons((u16)ep->ird);
816 mpa_v2_params.ord = htons((u16)ep->ord);
817
818 if (peer2peer) {
819 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
820 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
821 mpa_v2_params.ord |=
822 htons(MPA_V2_RDMA_WRITE_RTR);
823 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
824 mpa_v2_params.ord |=
825 htons(MPA_V2_RDMA_READ_RTR);
826 }
827 memcpy(mpa->private_data, &mpa_v2_params,
828 sizeof(struct mpa_v2_conn_params));
829
830 if (ep->plen)
831 memcpy(mpa->private_data +
832 sizeof(struct mpa_v2_conn_params),
833 ep->mpa_pkt + sizeof(*mpa), ep->plen);
834 } else
835 if (ep->plen)
836 memcpy(mpa->private_data,
837 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700838
839 /*
840 * Reference the mpa skb. This ensures the data area
841 * will remain in memory until the hw acks the tx.
842 * Function fw4_ack() will deref it.
843 */
844 skb_get(skb);
845 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
846 BUG_ON(ep->mpa_skb);
847 ep->mpa_skb = skb;
848 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
849 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530850 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700851 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530852 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700853 return;
854}
855
856static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
857{
858 int mpalen, wrlen;
859 struct fw_ofld_tx_data_wr *req;
860 struct mpa_message *mpa;
861 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530862 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700863
864 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
865
866 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530867 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
868 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700869 wrlen = roundup(mpalen + sizeof *req, 16);
870
871 skb = get_skb(NULL, wrlen, GFP_KERNEL);
872 if (!skb) {
873 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
874 return -ENOMEM;
875 }
876 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
877
878 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
879 memset(req, 0, wrlen);
880 req->op_to_immdlen = cpu_to_be32(
881 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
882 FW_WR_COMPL(1) |
883 FW_WR_IMMDLEN(mpalen));
884 req->flowid_len16 = cpu_to_be32(
885 FW_WR_FLOWID(ep->hwtid) |
886 FW_WR_LEN16(wrlen >> 4));
887 req->plen = cpu_to_be32(mpalen);
888 req->tunnel_to_proxy = cpu_to_be32(
889 FW_OFLD_TX_DATA_WR_FLUSH(1) |
890 FW_OFLD_TX_DATA_WR_SHOVE(1));
891
892 mpa = (struct mpa_message *)(req + 1);
893 memset(mpa, 0, sizeof(*mpa));
894 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
895 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000896 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 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
905 0));
906 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
907 (p2p_type ==
908 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
909 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
910 FW_RI_INIT_P2PTYPE_READ_REQ ?
911 MPA_V2_RDMA_READ_RTR : 0) : 0));
912 memcpy(mpa->private_data, &mpa_v2_params,
913 sizeof(struct mpa_v2_conn_params));
914
915 if (ep->plen)
916 memcpy(mpa->private_data +
917 sizeof(struct mpa_v2_conn_params), pdata, plen);
918 } else
919 if (plen)
920 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700921
922 /*
923 * Reference the mpa skb again. This ensures the data area
924 * will remain in memory until the hw acks the tx.
925 * Function fw4_ack() will deref it.
926 */
927 skb_get(skb);
928 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
929 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
930 BUG_ON(ep->mpa_skb);
931 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +0530932 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700933 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
934}
935
936static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
937{
938 int mpalen, wrlen;
939 struct fw_ofld_tx_data_wr *req;
940 struct mpa_message *mpa;
941 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530942 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700943
944 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
945
946 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530947 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
948 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700949 wrlen = roundup(mpalen + sizeof *req, 16);
950
951 skb = get_skb(NULL, wrlen, GFP_KERNEL);
952 if (!skb) {
953 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
954 return -ENOMEM;
955 }
956 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
957
958 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
959 memset(req, 0, wrlen);
960 req->op_to_immdlen = cpu_to_be32(
961 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
962 FW_WR_COMPL(1) |
963 FW_WR_IMMDLEN(mpalen));
964 req->flowid_len16 = cpu_to_be32(
965 FW_WR_FLOWID(ep->hwtid) |
966 FW_WR_LEN16(wrlen >> 4));
967 req->plen = cpu_to_be32(mpalen);
968 req->tunnel_to_proxy = cpu_to_be32(
969 FW_OFLD_TX_DATA_WR_FLUSH(1) |
970 FW_OFLD_TX_DATA_WR_SHOVE(1));
971
972 mpa = (struct mpa_message *)(req + 1);
973 memset(mpa, 0, sizeof(*mpa));
974 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
975 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
976 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530977 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700978 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530979
980 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
981 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700982 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
983 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530984 mpa_v2_params.ird = htons((u16)ep->ird);
985 mpa_v2_params.ord = htons((u16)ep->ord);
986 if (peer2peer && (ep->mpa_attr.p2p_type !=
987 FW_RI_INIT_P2PTYPE_DISABLED)) {
988 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
989
990 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
991 mpa_v2_params.ord |=
992 htons(MPA_V2_RDMA_WRITE_RTR);
993 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
994 mpa_v2_params.ord |=
995 htons(MPA_V2_RDMA_READ_RTR);
996 }
997
998 memcpy(mpa->private_data, &mpa_v2_params,
999 sizeof(struct mpa_v2_conn_params));
1000
1001 if (ep->plen)
1002 memcpy(mpa->private_data +
1003 sizeof(struct mpa_v2_conn_params), pdata, plen);
1004 } else
1005 if (plen)
1006 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001007
1008 /*
1009 * Reference the mpa skb. This ensures the data area
1010 * will remain in memory until the hw acks the tx.
1011 * Function fw4_ack() will deref it.
1012 */
1013 skb_get(skb);
1014 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1015 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301016 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301017 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001018 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1019}
1020
1021static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1022{
1023 struct c4iw_ep *ep;
1024 struct cpl_act_establish *req = cplhdr(skb);
1025 unsigned int tid = GET_TID(req);
1026 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
1027 struct tid_info *t = dev->rdev.lldi.tids;
1028
1029 ep = lookup_atid(t, atid);
1030
1031 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1032 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1033
Steve Wisea7db89e2014-03-21 20:40:35 +05301034 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001035 dst_confirm(ep->dst);
1036
1037 /* setup the hwtid for this connection */
1038 ep->hwtid = tid;
1039 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001040 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001041
1042 ep->snd_seq = be32_to_cpu(req->snd_isn);
1043 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1044
1045 set_emss(ep, ntohs(req->tcp_opt));
1046
1047 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001048 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001049 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001050 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001051
1052 /* start MPA negotiation */
1053 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301054 if (ep->retry_with_mpa_v1)
1055 send_mpa_req(ep, skb, 1);
1056 else
1057 send_mpa_req(ep, skb, mpa_rev);
Steve Wisea7db89e2014-03-21 20:40:35 +05301058 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001059 return 0;
1060}
1061
Steve Wisebe13b2d2014-03-21 20:40:33 +05301062static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001063{
1064 struct iw_cm_event event;
1065
1066 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1067 memset(&event, 0, sizeof(event));
1068 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301069 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001070 if (ep->com.cm_id) {
1071 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1072 ep, ep->com.cm_id, ep->hwtid);
1073 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1074 ep->com.cm_id->rem_ref(ep->com.cm_id);
1075 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001076 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001077 }
1078}
1079
1080static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
1081{
1082 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecc18b932014-04-24 14:31:53 -05001083 __state_set(&ep->com, ABORTING);
Vipul Pandya793dad92012-12-10 09:30:56 +00001084 set_bit(ABORT_CONN, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001085 return send_abort(ep, skb, gfp);
1086}
1087
1088static void peer_close_upcall(struct c4iw_ep *ep)
1089{
1090 struct iw_cm_event event;
1091
1092 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1093 memset(&event, 0, sizeof(event));
1094 event.event = IW_CM_EVENT_DISCONNECT;
1095 if (ep->com.cm_id) {
1096 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1097 ep, ep->com.cm_id, ep->hwtid);
1098 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001099 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001100 }
1101}
1102
1103static void peer_abort_upcall(struct c4iw_ep *ep)
1104{
1105 struct iw_cm_event event;
1106
1107 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1108 memset(&event, 0, sizeof(event));
1109 event.event = IW_CM_EVENT_CLOSE;
1110 event.status = -ECONNRESET;
1111 if (ep->com.cm_id) {
1112 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1113 ep->com.cm_id, ep->hwtid);
1114 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1115 ep->com.cm_id->rem_ref(ep->com.cm_id);
1116 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001117 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001118 }
1119}
1120
1121static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1122{
1123 struct iw_cm_event event;
1124
1125 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1126 memset(&event, 0, sizeof(event));
1127 event.event = IW_CM_EVENT_CONNECT_REPLY;
1128 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301129 memcpy(&event.local_addr, &ep->com.local_addr,
1130 sizeof(ep->com.local_addr));
1131 memcpy(&event.remote_addr, &ep->com.remote_addr,
1132 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001133
1134 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301135 if (!ep->tried_with_mpa_v1) {
1136 /* this means MPA_v2 is used */
1137 event.private_data_len = ep->plen -
1138 sizeof(struct mpa_v2_conn_params);
1139 event.private_data = ep->mpa_pkt +
1140 sizeof(struct mpa_message) +
1141 sizeof(struct mpa_v2_conn_params);
1142 } else {
1143 /* this means MPA_v1 is used */
1144 event.private_data_len = ep->plen;
1145 event.private_data = ep->mpa_pkt +
1146 sizeof(struct mpa_message);
1147 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001148 }
Roland Dreier85963e42010-07-19 13:13:09 -07001149
1150 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1151 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001152 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001153 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1154
Steve Wisecfdda9d2010-04-21 15:30:06 -07001155 if (status < 0) {
1156 ep->com.cm_id->rem_ref(ep->com.cm_id);
1157 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001158 }
1159}
1160
Steve Wisebe13b2d2014-03-21 20:40:33 +05301161static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001162{
1163 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301164 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001165
1166 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1167 memset(&event, 0, sizeof(event));
1168 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301169 memcpy(&event.local_addr, &ep->com.local_addr,
1170 sizeof(ep->com.local_addr));
1171 memcpy(&event.remote_addr, &ep->com.remote_addr,
1172 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001173 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301174 if (!ep->tried_with_mpa_v1) {
1175 /* this means MPA_v2 is used */
1176 event.ord = ep->ord;
1177 event.ird = ep->ird;
1178 event.private_data_len = ep->plen -
1179 sizeof(struct mpa_v2_conn_params);
1180 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1181 sizeof(struct mpa_v2_conn_params);
1182 } else {
1183 /* this means MPA_v1 is used. Send max supported */
1184 event.ord = c4iw_max_read_depth;
1185 event.ird = c4iw_max_read_depth;
1186 event.private_data_len = ep->plen;
1187 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1188 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301189 c4iw_get_ep(&ep->com);
1190 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1191 &event);
1192 if (ret)
1193 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001194 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001195 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301196 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001197}
1198
1199static void established_upcall(struct c4iw_ep *ep)
1200{
1201 struct iw_cm_event event;
1202
1203 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1204 memset(&event, 0, sizeof(event));
1205 event.event = IW_CM_EVENT_ESTABLISHED;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301206 event.ird = ep->ird;
1207 event.ord = ep->ord;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001208 if (ep->com.cm_id) {
1209 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1210 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001211 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001212 }
1213}
1214
1215static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1216{
1217 struct cpl_rx_data_ack *req;
1218 struct sk_buff *skb;
1219 int wrlen = roundup(sizeof *req, 16);
1220
1221 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1222 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1223 if (!skb) {
1224 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1225 return 0;
1226 }
1227
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301228 /*
1229 * If we couldn't specify the entire rcv window at connection setup
1230 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1231 * then add the overage in to the credits returned.
1232 */
1233 if (ep->rcv_win > RCV_BUFSIZ_MASK * 1024)
1234 credits += ep->rcv_win - RCV_BUFSIZ_MASK * 1024;
1235
Steve Wisecfdda9d2010-04-21 15:30:06 -07001236 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1237 memset(req, 0, wrlen);
1238 INIT_TP_WR(req, ep->hwtid);
1239 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1240 ep->hwtid));
Steve Wiseba6d3922010-06-23 15:46:49 +00001241 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1242 F_RX_DACK_CHANGE |
1243 V_RX_DACK_MODE(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001244 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001245 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1246 return credits;
1247}
1248
Steve Wisecc18b932014-04-24 14:31:53 -05001249static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001250{
1251 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301252 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001253 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301254 u16 resp_ird, resp_ord;
1255 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001256 struct c4iw_qp_attributes attrs;
1257 enum c4iw_qp_attr_mask mask;
1258 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001259 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001260
1261 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1262
1263 /*
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001264 * Stop mpa timer. If it expired, then
1265 * we ignore the MPA reply. process_timeout()
1266 * will abort the connection.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001267 */
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001268 if (stop_ep_timer(ep))
Steve Wisecc18b932014-04-24 14:31:53 -05001269 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001270
1271 /*
1272 * If we get more than the supported amount of private data
1273 * then we must fail this connection.
1274 */
1275 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1276 err = -EINVAL;
1277 goto err;
1278 }
1279
1280 /*
1281 * copy the new data into our accumulation buffer.
1282 */
1283 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1284 skb->len);
1285 ep->mpa_pkt_len += skb->len;
1286
1287 /*
1288 * if we don't even have the mpa message, then bail.
1289 */
1290 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001291 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001292 mpa = (struct mpa_message *) ep->mpa_pkt;
1293
1294 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301295 if (mpa->revision > mpa_rev) {
1296 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1297 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001298 err = -EPROTO;
1299 goto err;
1300 }
1301 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1302 err = -EPROTO;
1303 goto err;
1304 }
1305
1306 plen = ntohs(mpa->private_data_size);
1307
1308 /*
1309 * Fail if there's too much private data.
1310 */
1311 if (plen > MPA_MAX_PRIVATE_DATA) {
1312 err = -EPROTO;
1313 goto err;
1314 }
1315
1316 /*
1317 * If plen does not account for pkt size
1318 */
1319 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1320 err = -EPROTO;
1321 goto err;
1322 }
1323
1324 ep->plen = (u8) plen;
1325
1326 /*
1327 * If we don't have all the pdata yet, then bail.
1328 * We'll continue process when more data arrives.
1329 */
1330 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001331 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001332
1333 if (mpa->flags & MPA_REJECT) {
1334 err = -ECONNREFUSED;
1335 goto err;
1336 }
1337
1338 /*
1339 * If we get here we have accumulated the entire mpa
1340 * start reply message including private data. And
1341 * the MPA header is valid.
1342 */
Steve Wisec529fb52014-03-21 20:40:37 +05301343 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001344 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1345 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1346 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301347 ep->mpa_attr.version = mpa->revision;
1348 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1349
1350 if (mpa->revision == 2) {
1351 ep->mpa_attr.enhanced_rdma_conn =
1352 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1353 if (ep->mpa_attr.enhanced_rdma_conn) {
1354 mpa_v2_params = (struct mpa_v2_conn_params *)
1355 (ep->mpa_pkt + sizeof(*mpa));
1356 resp_ird = ntohs(mpa_v2_params->ird) &
1357 MPA_V2_IRD_ORD_MASK;
1358 resp_ord = ntohs(mpa_v2_params->ord) &
1359 MPA_V2_IRD_ORD_MASK;
1360
1361 /*
1362 * This is a double-check. Ideally, below checks are
1363 * not required since ird/ord stuff has been taken
1364 * care of in c4iw_accept_cr
1365 */
1366 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1367 err = -ENOMEM;
1368 ep->ird = resp_ord;
1369 ep->ord = resp_ird;
1370 insuff_ird = 1;
1371 }
1372
1373 if (ntohs(mpa_v2_params->ird) &
1374 MPA_V2_PEER2PEER_MODEL) {
1375 if (ntohs(mpa_v2_params->ord) &
1376 MPA_V2_RDMA_WRITE_RTR)
1377 ep->mpa_attr.p2p_type =
1378 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1379 else if (ntohs(mpa_v2_params->ord) &
1380 MPA_V2_RDMA_READ_RTR)
1381 ep->mpa_attr.p2p_type =
1382 FW_RI_INIT_P2PTYPE_READ_REQ;
1383 }
1384 }
1385 } else if (mpa->revision == 1)
1386 if (peer2peer)
1387 ep->mpa_attr.p2p_type = p2p_type;
1388
Steve Wisecfdda9d2010-04-21 15:30:06 -07001389 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301390 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1391 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1392 ep->mpa_attr.recv_marker_enabled,
1393 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1394 ep->mpa_attr.p2p_type, p2p_type);
1395
1396 /*
1397 * If responder's RTR does not match with that of initiator, assign
1398 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1399 * generated when moving QP to RTS state.
1400 * A TERM message will be sent after QP has moved to RTS state
1401 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001402 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301403 (ep->mpa_attr.p2p_type != p2p_type)) {
1404 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1405 rtr_mismatch = 1;
1406 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001407
1408 attrs.mpa_attr = ep->mpa_attr;
1409 attrs.max_ird = ep->ird;
1410 attrs.max_ord = ep->ord;
1411 attrs.llp_stream_handle = ep;
1412 attrs.next_state = C4IW_QP_STATE_RTS;
1413
1414 mask = C4IW_QP_ATTR_NEXT_STATE |
1415 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1416 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1417
1418 /* bind QP and TID with INIT_WR */
1419 err = c4iw_modify_qp(ep->com.qp->rhp,
1420 ep->com.qp, mask, &attrs, 1);
1421 if (err)
1422 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301423
1424 /*
1425 * If responder's RTR requirement did not match with what initiator
1426 * supports, generate TERM message
1427 */
1428 if (rtr_mismatch) {
1429 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1430 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1431 attrs.ecode = MPA_NOMATCH_RTR;
1432 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001433 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301434 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001435 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301436 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001437 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301438 goto out;
1439 }
1440
1441 /*
1442 * Generate TERM if initiator IRD is not sufficient for responder
1443 * provided ORD. Currently, we do the same behaviour even when
1444 * responder provided IRD is also not sufficient as regards to
1445 * initiator ORD.
1446 */
1447 if (insuff_ird) {
1448 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1449 __func__);
1450 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1451 attrs.ecode = MPA_INSUFF_IRD;
1452 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001453 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301454 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001455 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301456 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001457 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301458 goto out;
1459 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001460 goto out;
1461err:
Steve Wisec529fb52014-03-21 20:40:37 +05301462 __state_set(&ep->com, ABORTING);
Steve Wiseb21ef162010-06-10 19:02:55 +00001463 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001464out:
1465 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001466 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001467}
1468
1469static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1470{
1471 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301472 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001473 u16 plen;
1474
1475 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1476
Steve Wisecfdda9d2010-04-21 15:30:06 -07001477 /*
1478 * If we get more than the supported amount of private data
1479 * then we must fail this connection.
1480 */
1481 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001482 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001483 abort_connection(ep, skb, GFP_KERNEL);
1484 return;
1485 }
1486
1487 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1488
1489 /*
1490 * Copy the new data into our accumulation buffer.
1491 */
1492 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1493 skb->len);
1494 ep->mpa_pkt_len += skb->len;
1495
1496 /*
1497 * If we don't even have the mpa message, then bail.
1498 * We'll continue process when more data arrives.
1499 */
1500 if (ep->mpa_pkt_len < sizeof(*mpa))
1501 return;
1502
1503 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001504 mpa = (struct mpa_message *) ep->mpa_pkt;
1505
1506 /*
1507 * Validate MPA Header.
1508 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301509 if (mpa->revision > mpa_rev) {
1510 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1511 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001512 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001513 abort_connection(ep, skb, GFP_KERNEL);
1514 return;
1515 }
1516
1517 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001518 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001519 abort_connection(ep, skb, GFP_KERNEL);
1520 return;
1521 }
1522
1523 plen = ntohs(mpa->private_data_size);
1524
1525 /*
1526 * Fail if there's too much private data.
1527 */
1528 if (plen > MPA_MAX_PRIVATE_DATA) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001529 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001530 abort_connection(ep, skb, GFP_KERNEL);
1531 return;
1532 }
1533
1534 /*
1535 * If plen does not account for pkt size
1536 */
1537 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001538 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001539 abort_connection(ep, skb, GFP_KERNEL);
1540 return;
1541 }
1542 ep->plen = (u8) plen;
1543
1544 /*
1545 * If we don't have all the pdata yet, then bail.
1546 */
1547 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1548 return;
1549
1550 /*
1551 * If we get here we have accumulated the entire mpa
1552 * start reply message including private data.
1553 */
1554 ep->mpa_attr.initiator = 0;
1555 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1556 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1557 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301558 ep->mpa_attr.version = mpa->revision;
1559 if (mpa->revision == 1)
1560 ep->tried_with_mpa_v1 = 1;
1561 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1562
1563 if (mpa->revision == 2) {
1564 ep->mpa_attr.enhanced_rdma_conn =
1565 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1566 if (ep->mpa_attr.enhanced_rdma_conn) {
1567 mpa_v2_params = (struct mpa_v2_conn_params *)
1568 (ep->mpa_pkt + sizeof(*mpa));
1569 ep->ird = ntohs(mpa_v2_params->ird) &
1570 MPA_V2_IRD_ORD_MASK;
1571 ep->ord = ntohs(mpa_v2_params->ord) &
1572 MPA_V2_IRD_ORD_MASK;
1573 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1574 if (peer2peer) {
1575 if (ntohs(mpa_v2_params->ord) &
1576 MPA_V2_RDMA_WRITE_RTR)
1577 ep->mpa_attr.p2p_type =
1578 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1579 else if (ntohs(mpa_v2_params->ord) &
1580 MPA_V2_RDMA_READ_RTR)
1581 ep->mpa_attr.p2p_type =
1582 FW_RI_INIT_P2PTYPE_READ_REQ;
1583 }
1584 }
1585 } else if (mpa->revision == 1)
1586 if (peer2peer)
1587 ep->mpa_attr.p2p_type = p2p_type;
1588
Steve Wisecfdda9d2010-04-21 15:30:06 -07001589 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1590 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1591 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1592 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1593 ep->mpa_attr.p2p_type);
1594
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001595 /*
1596 * If the endpoint timer already expired, then we ignore
1597 * the start request. process_timeout() will abort
1598 * the connection.
1599 */
1600 if (!stop_ep_timer(ep)) {
1601 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001602
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001603 /* drive upcall */
1604 mutex_lock(&ep->parent_ep->com.mutex);
1605 if (ep->parent_ep->com.state != DEAD) {
1606 if (connect_request_upcall(ep))
1607 abort_connection(ep, skb, GFP_KERNEL);
1608 } else {
Steve Wisebe13b2d2014-03-21 20:40:33 +05301609 abort_connection(ep, skb, GFP_KERNEL);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001610 }
1611 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301612 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001613 return;
1614}
1615
1616static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1617{
1618 struct c4iw_ep *ep;
1619 struct cpl_rx_data *hdr = cplhdr(skb);
1620 unsigned int dlen = ntohs(hdr->len);
1621 unsigned int tid = GET_TID(hdr);
1622 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001623 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001624 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001625
1626 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301627 if (!ep)
1628 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001629 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1630 skb_pull(skb, sizeof(*hdr));
1631 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301632 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001633
Steve Wisecfdda9d2010-04-21 15:30:06 -07001634 /* update RX credits */
1635 update_rx_credits(ep, dlen);
1636
Steve Wisec529fb52014-03-21 20:40:37 +05301637 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001638 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001639 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001640 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001641 break;
1642 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001643 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001644 process_mpa_request(ep, skb);
1645 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001646 case FPDU_MODE: {
1647 struct c4iw_qp_attributes attrs;
1648 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001649 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001650 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001651 " qpid %u ep %p state %d tid %u status %d\n",
1652 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301653 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301654 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001655 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001656 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1657 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001658 break;
1659 }
Vipul Pandya15579672013-01-07 13:11:52 +00001660 default:
1661 break;
1662 }
Steve Wisec529fb52014-03-21 20:40:37 +05301663 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001664 if (disconnect)
1665 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001666 return 0;
1667}
1668
1669static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1670{
1671 struct c4iw_ep *ep;
1672 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001673 int release = 0;
1674 unsigned int tid = GET_TID(rpl);
1675 struct tid_info *t = dev->rdev.lldi.tids;
1676
1677 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301678 if (!ep) {
1679 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1680 return 0;
1681 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001682 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001683 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001684 switch (ep->com.state) {
1685 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001686 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001687 __state_set(&ep->com, DEAD);
1688 release = 1;
1689 break;
1690 default:
1691 printk(KERN_ERR "%s ep %p state %d\n",
1692 __func__, ep, ep->com.state);
1693 break;
1694 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001695 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001696
1697 if (release)
1698 release_ep_resources(ep);
1699 return 0;
1700}
1701
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001702static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1703{
1704 struct sk_buff *skb;
1705 struct fw_ofld_connection_wr *req;
1706 unsigned int mtu_idx;
1707 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301708 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301709 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001710
1711 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1712 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1713 memset(req, 0, sizeof(*req));
1714 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1715 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301716 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1717 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001718 ep->l2t));
Steve Wise9eccfe12014-03-26 17:08:09 -05001719 sin = (struct sockaddr_in *)&ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301720 req->le.lport = sin->sin_port;
1721 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05001722 sin = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301723 req->le.pport = sin->sin_port;
1724 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001725 req->tcb.t_state_to_astid =
1726 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1727 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1728 req->tcb.cplrxdataack_cplpassacceptrpl =
1729 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001730 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001731 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301732 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
1733 enable_tcp_timestamps);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001734 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301735
1736 /*
1737 * Specify the largest window that will fit in opt0. The
1738 * remainder will be specified in the rx_data_ack.
1739 */
1740 win = ep->rcv_win >> 10;
1741 if (win > RCV_BUFSIZ_MASK)
1742 win = RCV_BUFSIZ_MASK;
1743
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001744 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001745 (nocong ? NO_CONG(1) : 0) |
1746 KEEP_ALIVE(1) |
1747 DELACK(1) |
1748 WND_SCALE(wscale) |
1749 MSS_IDX(mtu_idx) |
1750 L2T_IDX(ep->l2t->idx) |
1751 TX_CHAN(ep->tx_chan) |
1752 SMAC_SEL(ep->smac_idx) |
1753 DSCP(ep->tos) |
1754 ULP_MODE(ULP_MODE_TCPDDP) |
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301755 RCV_BUFSIZ(win));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001756 req->tcb.opt2 = (__force __be32) (PACE(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001757 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1758 RX_CHANNEL(0) |
1759 CCTRL_ECN(enable_ecn) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001760 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001761 if (enable_tcp_timestamps)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001762 req->tcb.opt2 |= (__force __be32) TSTAMPS_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001763 if (enable_tcp_sack)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001764 req->tcb.opt2 |= (__force __be32) SACK_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001765 if (wscale && enable_tcp_window_scaling)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001766 req->tcb.opt2 |= (__force __be32) WND_SCALE_EN(1);
1767 req->tcb.opt0 = cpu_to_be64((__force u64) req->tcb.opt0);
1768 req->tcb.opt2 = cpu_to_be32((__force u32) req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001769 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1770 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001771 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1772}
1773
Steve Wisecfdda9d2010-04-21 15:30:06 -07001774/*
1775 * Return whether a failed active open has allocated a TID
1776 */
1777static inline int act_open_has_tid(int status)
1778{
1779 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1780 status != CPL_ERR_ARP_MISS;
1781}
1782
Steve Wise7a2cea22014-03-14 21:52:07 +05301783/* Returns whether a CPL status conveys negative advice.
1784 */
1785static int is_neg_adv(unsigned int status)
1786{
1787 return status == CPL_ERR_RTX_NEG_ADVICE ||
1788 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1789 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1790}
1791
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301792static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1793{
1794 ep->snd_win = snd_win;
1795 ep->rcv_win = rcv_win;
1796 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1797}
1798
Vipul Pandya793dad92012-12-10 09:30:56 +00001799#define ACT_OPEN_RETRY_COUNT 2
1800
Vipul Pandya830662f2013-07-04 16:10:47 +05301801static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1802 struct dst_entry *dst, struct c4iw_dev *cdev,
1803 bool clear_mpa_v1)
1804{
1805 struct neighbour *n;
1806 int err, step;
1807 struct net_device *pdev;
1808
1809 n = dst_neigh_lookup(dst, peer_ip);
1810 if (!n)
1811 return -ENODEV;
1812
1813 rcu_read_lock();
1814 err = -ENOMEM;
1815 if (n->dev->flags & IFF_LOOPBACK) {
1816 if (iptype == 4)
1817 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1818 else if (IS_ENABLED(CONFIG_IPV6))
1819 for_each_netdev(&init_net, pdev) {
1820 if (ipv6_chk_addr(&init_net,
1821 (struct in6_addr *)peer_ip,
1822 pdev, 1))
1823 break;
1824 }
1825 else
1826 pdev = NULL;
1827
1828 if (!pdev) {
1829 err = -ENODEV;
1830 goto out;
1831 }
1832 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1833 n, pdev, 0);
1834 if (!ep->l2t)
1835 goto out;
1836 ep->mtu = pdev->mtu;
1837 ep->tx_chan = cxgb4_port_chan(pdev);
1838 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1839 step = cdev->rdev.lldi.ntxq /
1840 cdev->rdev.lldi.nchan;
1841 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1842 step = cdev->rdev.lldi.nrxq /
1843 cdev->rdev.lldi.nchan;
1844 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1845 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1846 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301847 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301848 dev_put(pdev);
1849 } else {
1850 pdev = get_real_dev(n->dev);
1851 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1852 n, pdev, 0);
1853 if (!ep->l2t)
1854 goto out;
1855 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05001856 ep->tx_chan = cxgb4_port_chan(pdev);
1857 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
Vipul Pandya830662f2013-07-04 16:10:47 +05301858 step = cdev->rdev.lldi.ntxq /
1859 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05001860 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1861 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05301862 step = cdev->rdev.lldi.nrxq /
1863 cdev->rdev.lldi.nchan;
1864 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05001865 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301866 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301867
1868 if (clear_mpa_v1) {
1869 ep->retry_with_mpa_v1 = 0;
1870 ep->tried_with_mpa_v1 = 0;
1871 }
1872 }
1873 err = 0;
1874out:
1875 rcu_read_unlock();
1876
1877 neigh_release(n);
1878
1879 return err;
1880}
1881
Vipul Pandya793dad92012-12-10 09:30:56 +00001882static int c4iw_reconnect(struct c4iw_ep *ep)
1883{
1884 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05301885 struct sockaddr_in *laddr = (struct sockaddr_in *)
1886 &ep->com.cm_id->local_addr;
1887 struct sockaddr_in *raddr = (struct sockaddr_in *)
1888 &ep->com.cm_id->remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301889 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
1890 &ep->com.cm_id->local_addr;
1891 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
1892 &ep->com.cm_id->remote_addr;
1893 int iptype;
1894 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00001895
1896 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1897 init_timer(&ep->timer);
1898
1899 /*
1900 * Allocate an active TID to initiate a TCP connection.
1901 */
1902 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1903 if (ep->atid == -1) {
1904 pr_err("%s - cannot alloc atid.\n", __func__);
1905 err = -ENOMEM;
1906 goto fail2;
1907 }
1908 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1909
1910 /* find a route */
Vipul Pandya830662f2013-07-04 16:10:47 +05301911 if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
1912 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
1913 raddr->sin_addr.s_addr, laddr->sin_port,
1914 raddr->sin_port, 0);
1915 iptype = 4;
1916 ra = (__u8 *)&raddr->sin_addr;
1917 } else {
1918 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
1919 raddr6->sin6_addr.s6_addr,
1920 laddr6->sin6_port, raddr6->sin6_port, 0,
1921 raddr6->sin6_scope_id);
1922 iptype = 6;
1923 ra = (__u8 *)&raddr6->sin6_addr;
1924 }
1925 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001926 pr_err("%s - cannot find route.\n", __func__);
1927 err = -EHOSTUNREACH;
1928 goto fail3;
1929 }
Vipul Pandya830662f2013-07-04 16:10:47 +05301930 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false);
1931 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001932 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00001933 goto fail4;
1934 }
1935
1936 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1937 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1938 ep->l2t->idx);
1939
1940 state_set(&ep->com, CONNECTING);
1941 ep->tos = 0;
1942
1943 /* send connect request to rnic */
1944 err = send_connect(ep);
1945 if (!err)
1946 goto out;
1947
1948 cxgb4_l2t_release(ep->l2t);
1949fail4:
1950 dst_release(ep->dst);
1951fail3:
1952 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1953 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1954fail2:
1955 /*
1956 * remember to send notification to upper layer.
1957 * We are in here so the upper layer is not aware that this is
1958 * re-connect attempt and so, upper layer is still waiting for
1959 * response of 1st connect request.
1960 */
1961 connect_reply_upcall(ep, -ECONNRESET);
1962 c4iw_put_ep(&ep->com);
1963out:
1964 return err;
1965}
1966
Steve Wisecfdda9d2010-04-21 15:30:06 -07001967static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1968{
1969 struct c4iw_ep *ep;
1970 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1971 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1972 ntohl(rpl->atid_status)));
1973 struct tid_info *t = dev->rdev.lldi.tids;
1974 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05301975 struct sockaddr_in *la;
1976 struct sockaddr_in *ra;
1977 struct sockaddr_in6 *la6;
1978 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001979
1980 ep = lookup_atid(t, atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05001981 la = (struct sockaddr_in *)&ep->com.mapped_local_addr;
1982 ra = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
1983 la6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
1984 ra6 = (struct sockaddr_in6 *)&ep->com.mapped_remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001985
1986 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1987 status, status2errno(status));
1988
Steve Wise7a2cea22014-03-14 21:52:07 +05301989 if (is_neg_adv(status)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001990 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1991 atid);
1992 return 0;
1993 }
1994
Vipul Pandya793dad92012-12-10 09:30:56 +00001995 set_bit(ACT_OPEN_RPL, &ep->com.history);
1996
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301997 /*
1998 * Log interesting failures.
1999 */
2000 switch (status) {
2001 case CPL_ERR_CONN_RESET:
2002 case CPL_ERR_CONN_TIMEDOUT:
2003 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002004 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302005 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002006 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302007 mutex_unlock(&dev->rdev.stats.lock);
2008 if (ep->com.local_addr.ss_family == AF_INET &&
2009 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002010 send_fw_act_open_req(ep,
2011 GET_TID_TID(GET_AOPEN_ATID(
2012 ntohl(rpl->atid_status))));
2013 return 0;
2014 }
2015 break;
2016 case CPL_ERR_CONN_EXIST:
2017 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2018 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2019 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2020 atid);
2021 cxgb4_free_atid(t, atid);
2022 dst_release(ep->dst);
2023 cxgb4_l2t_release(ep->l2t);
2024 c4iw_reconnect(ep);
2025 return 0;
2026 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002027 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302028 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302029 if (ep->com.local_addr.ss_family == AF_INET) {
2030 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2031 atid, status, status2errno(status),
2032 &la->sin_addr.s_addr, ntohs(la->sin_port),
2033 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2034 } else {
2035 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2036 atid, status, status2errno(status),
2037 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2038 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2039 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302040 break;
2041 }
2042
Steve Wisecfdda9d2010-04-21 15:30:06 -07002043 connect_reply_upcall(ep, status2errno(status));
2044 state_set(&ep->com, DEAD);
2045
2046 if (status && act_open_has_tid(status))
2047 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2048
Vipul Pandya793dad92012-12-10 09:30:56 +00002049 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002050 cxgb4_free_atid(t, atid);
2051 dst_release(ep->dst);
2052 cxgb4_l2t_release(ep->l2t);
2053 c4iw_put_ep(&ep->com);
2054
2055 return 0;
2056}
2057
2058static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2059{
2060 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2061 struct tid_info *t = dev->rdev.lldi.tids;
2062 unsigned int stid = GET_TID(rpl);
2063 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2064
2065 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002066 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2067 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002068 }
2069 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2070 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002071 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002072
Vipul Pandya1cab7752012-12-10 09:30:55 +00002073out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002074 return 0;
2075}
2076
Steve Wisecfdda9d2010-04-21 15:30:06 -07002077static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2078{
2079 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2080 struct tid_info *t = dev->rdev.lldi.tids;
2081 unsigned int stid = GET_TID(rpl);
2082 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2083
2084 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002085 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002086 return 0;
2087}
2088
Vipul Pandya830662f2013-07-04 16:10:47 +05302089static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002090 struct cpl_pass_accept_req *req)
2091{
2092 struct cpl_pass_accept_rpl *rpl;
2093 unsigned int mtu_idx;
2094 u64 opt0;
2095 u32 opt2;
2096 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302097 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302098 int win;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002099
2100 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2101 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302102
Steve Wisecfdda9d2010-04-21 15:30:06 -07002103 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302104 rpl = cplhdr(skb);
2105 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
2106 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2107 rpl5 = (void *)rpl;
2108 INIT_TP_WR(rpl5, ep->hwtid);
2109 } else {
2110 skb_trim(skb, sizeof(*rpl));
2111 INIT_TP_WR(rpl, ep->hwtid);
2112 }
2113 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2114 ep->hwtid));
2115
2116 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
2117 enable_tcp_timestamps && req->tcpopt.tstamp);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002118 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302119
2120 /*
2121 * Specify the largest window that will fit in opt0. The
2122 * remainder will be specified in the rx_data_ack.
2123 */
2124 win = ep->rcv_win >> 10;
2125 if (win > RCV_BUFSIZ_MASK)
2126 win = RCV_BUFSIZ_MASK;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002127 opt0 = (nocong ? NO_CONG(1) : 0) |
2128 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +00002129 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07002130 WND_SCALE(wscale) |
2131 MSS_IDX(mtu_idx) |
2132 L2T_IDX(ep->l2t->idx) |
2133 TX_CHAN(ep->tx_chan) |
2134 SMAC_SEL(ep->smac_idx) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002135 DSCP(ep->tos >> 2) |
Steve Wiseb48f3b92011-03-11 22:30:21 +00002136 ULP_MODE(ULP_MODE_TCPDDP) |
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302137 RCV_BUFSIZ(win);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002138 opt2 = RX_CHANNEL(0) |
2139 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
2140
2141 if (enable_tcp_timestamps && req->tcpopt.tstamp)
2142 opt2 |= TSTAMPS_EN(1);
2143 if (enable_tcp_sack && req->tcpopt.sack)
2144 opt2 |= SACK_EN(1);
2145 if (wscale && enable_tcp_window_scaling)
2146 opt2 |= WND_SCALE_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002147 if (enable_ecn) {
2148 const struct tcphdr *tcph;
2149 u32 hlen = ntohl(req->hdr_len);
2150
2151 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
2152 G_IP_HDR_LEN(hlen);
2153 if (tcph->ece && tcph->cwr)
2154 opt2 |= CCTRL_ECN(1);
2155 }
Steve Wise92e50112014-04-24 14:31:59 -05002156 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302157 u32 isn = (prandom_u32() & ~7UL) - 1;
Steve Wise92e50112014-04-24 14:31:59 -05002158 opt2 |= T5_OPT_2_VALID;
2159 opt2 |= V_CONG_CNTRL(CONG_ALG_TAHOE);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302160 opt2 |= CONG_CNTRL_VALID; /* OPT_2_ISS for T5 */
2161 rpl5 = (void *)rpl;
2162 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2163 if (peer2peer)
2164 isn += 4;
2165 rpl5->iss = cpu_to_be32(isn);
2166 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002167 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002168
Steve Wisecfdda9d2010-04-21 15:30:06 -07002169 rpl->opt0 = cpu_to_be64(opt0);
2170 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002171 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wiseb38a0ad2013-08-06 21:04:37 +05302172 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002173 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2174
2175 return;
2176}
2177
Vipul Pandya830662f2013-07-04 16:10:47 +05302178static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002179{
Vipul Pandya830662f2013-07-04 16:10:47 +05302180 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002181 BUG_ON(skb_cloned(skb));
2182 skb_trim(skb, sizeof(struct cpl_tid_release));
2183 skb_get(skb);
2184 release_tid(&dev->rdev, hwtid, skb);
2185 return;
2186}
2187
Vipul Pandya830662f2013-07-04 16:10:47 +05302188static void get_4tuple(struct cpl_pass_accept_req *req, int *iptype,
2189 __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002190 __be16 *local_port, __be16 *peer_port)
2191{
2192 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
2193 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
2194 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302195 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002196 struct tcphdr *tcp = (struct tcphdr *)
2197 ((u8 *)(req + 1) + eth_len + ip_len);
2198
Vipul Pandya830662f2013-07-04 16:10:47 +05302199 if (ip->version == 4) {
2200 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2201 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2202 ntohs(tcp->dest));
2203 *iptype = 4;
2204 memcpy(peer_ip, &ip->saddr, 4);
2205 memcpy(local_ip, &ip->daddr, 4);
2206 } else {
2207 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2208 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2209 ntohs(tcp->dest));
2210 *iptype = 6;
2211 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2212 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2213 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002214 *peer_port = tcp->source;
2215 *local_port = tcp->dest;
2216
2217 return;
2218}
2219
2220static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2221{
Vipul Pandya793dad92012-12-10 09:30:56 +00002222 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002223 struct cpl_pass_accept_req *req = cplhdr(skb);
2224 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
2225 struct tid_info *t = dev->rdev.lldi.tids;
2226 unsigned int hwtid = GET_TID(req);
2227 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302228 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002229 __be16 local_port, peer_port;
David Miller3786cf12011-12-02 16:52:31 +00002230 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002231 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302232 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302233 unsigned short hdrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002234
2235 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002236 if (!parent_ep) {
2237 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2238 goto reject;
2239 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002240
Steve Wisecfdda9d2010-04-21 15:30:06 -07002241 if (state_read(&parent_ep->com) != LISTEN) {
2242 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
2243 __func__);
2244 goto reject;
2245 }
2246
Vipul Pandya830662f2013-07-04 16:10:47 +05302247 get_4tuple(req, &iptype, local_ip, peer_ip, &local_port, &peer_port);
2248
Steve Wisecfdda9d2010-04-21 15:30:06 -07002249 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302250 if (iptype == 4) {
2251 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2252 , __func__, parent_ep, hwtid,
2253 local_ip, peer_ip, ntohs(local_port),
2254 ntohs(peer_port), peer_mss);
2255 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2256 local_port, peer_port,
2257 GET_POPEN_TOS(ntohl(req->tos_stid)));
2258 } else {
2259 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2260 , __func__, parent_ep, hwtid,
2261 local_ip, peer_ip, ntohs(local_port),
2262 ntohs(peer_port), peer_mss);
2263 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
2264 PASS_OPEN_TOS(ntohl(req->tos_stid)),
2265 ((struct sockaddr_in6 *)
2266 &parent_ep->com.local_addr)->sin6_scope_id);
2267 }
2268 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002269 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2270 __func__);
2271 goto reject;
2272 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002273
2274 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2275 if (!child_ep) {
2276 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2277 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002278 dst_release(dst);
2279 goto reject;
2280 }
David Miller3786cf12011-12-02 16:52:31 +00002281
Vipul Pandya830662f2013-07-04 16:10:47 +05302282 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false);
David Miller3786cf12011-12-02 16:52:31 +00002283 if (err) {
2284 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2285 __func__);
2286 dst_release(dst);
2287 kfree(child_ep);
2288 goto reject;
2289 }
2290
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302291 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2292 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2293 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2294 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002295
Steve Wisecfdda9d2010-04-21 15:30:06 -07002296 state_set(&child_ep->com, CONNECTING);
2297 child_ep->com.dev = dev;
2298 child_ep->com.cm_id = NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +05302299 if (iptype == 4) {
2300 struct sockaddr_in *sin = (struct sockaddr_in *)
2301 &child_ep->com.local_addr;
2302 sin->sin_family = PF_INET;
2303 sin->sin_port = local_port;
2304 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2305 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
2306 sin->sin_family = PF_INET;
2307 sin->sin_port = peer_port;
2308 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2309 } else {
2310 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
2311 &child_ep->com.local_addr;
2312 sin6->sin6_family = PF_INET6;
2313 sin6->sin6_port = local_port;
2314 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2315 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
2316 sin6->sin6_family = PF_INET6;
2317 sin6->sin6_port = peer_port;
2318 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2319 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002320 c4iw_get_ep(&parent_ep->com);
2321 child_ep->parent_ep = parent_ep;
2322 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002323 child_ep->dst = dst;
2324 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002325
2326 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002327 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002328
2329 init_timer(&child_ep->timer);
2330 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002331 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Vipul Pandya830662f2013-07-04 16:10:47 +05302332 accept_cr(child_ep, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00002333 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002334 goto out;
2335reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302336 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002337out:
2338 return 0;
2339}
2340
2341static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2342{
2343 struct c4iw_ep *ep;
2344 struct cpl_pass_establish *req = cplhdr(skb);
2345 struct tid_info *t = dev->rdev.lldi.tids;
2346 unsigned int tid = GET_TID(req);
2347
2348 ep = lookup_tid(t, tid);
2349 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2350 ep->snd_seq = be32_to_cpu(req->snd_isn);
2351 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2352
Vipul Pandya1cab7752012-12-10 09:30:55 +00002353 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2354 ntohs(req->tcp_opt));
2355
Steve Wisecfdda9d2010-04-21 15:30:06 -07002356 set_emss(ep, ntohs(req->tcp_opt));
2357
2358 dst_confirm(ep->dst);
2359 state_set(&ep->com, MPA_REQ_WAIT);
2360 start_ep_timer(ep);
2361 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002362 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002363
2364 return 0;
2365}
2366
2367static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2368{
2369 struct cpl_peer_close *hdr = cplhdr(skb);
2370 struct c4iw_ep *ep;
2371 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002372 int disconnect = 1;
2373 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002374 struct tid_info *t = dev->rdev.lldi.tids;
2375 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002376 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002377
2378 ep = lookup_tid(t, tid);
2379 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2380 dst_confirm(ep->dst);
2381
Vipul Pandya793dad92012-12-10 09:30:56 +00002382 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002383 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002384 switch (ep->com.state) {
2385 case MPA_REQ_WAIT:
2386 __state_set(&ep->com, CLOSING);
2387 break;
2388 case MPA_REQ_SENT:
2389 __state_set(&ep->com, CLOSING);
2390 connect_reply_upcall(ep, -ECONNRESET);
2391 break;
2392 case MPA_REQ_RCVD:
2393
2394 /*
2395 * We're gonna mark this puppy DEAD, but keep
2396 * the reference on it until the ULP accepts or
2397 * rejects the CR. Also wake up anyone waiting
2398 * in rdma connection migration (see c4iw_accept_cr()).
2399 */
2400 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002401 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002402 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002403 break;
2404 case MPA_REP_SENT:
2405 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002406 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002407 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002408 break;
2409 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002410 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002411 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002412 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002413 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002414 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002415 if (ret != -ECONNRESET) {
2416 peer_close_upcall(ep);
2417 disconnect = 1;
2418 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002419 break;
2420 case ABORTING:
2421 disconnect = 0;
2422 break;
2423 case CLOSING:
2424 __state_set(&ep->com, MORIBUND);
2425 disconnect = 0;
2426 break;
2427 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002428 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002429 if (ep->com.cm_id && ep->com.qp) {
2430 attrs.next_state = C4IW_QP_STATE_IDLE;
2431 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2432 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2433 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302434 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002435 __state_set(&ep->com, DEAD);
2436 release = 1;
2437 disconnect = 0;
2438 break;
2439 case DEAD:
2440 disconnect = 0;
2441 break;
2442 default:
2443 BUG_ON(1);
2444 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002445 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002446 if (disconnect)
2447 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2448 if (release)
2449 release_ep_resources(ep);
2450 return 0;
2451}
2452
Steve Wisecfdda9d2010-04-21 15:30:06 -07002453static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2454{
2455 struct cpl_abort_req_rss *req = cplhdr(skb);
2456 struct c4iw_ep *ep;
2457 struct cpl_abort_rpl *rpl;
2458 struct sk_buff *rpl_skb;
2459 struct c4iw_qp_attributes attrs;
2460 int ret;
2461 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002462 struct tid_info *t = dev->rdev.lldi.tids;
2463 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002464
2465 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302466 if (is_neg_adv(req->status)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002467 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2468 ep->hwtid);
2469 return 0;
2470 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002471 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2472 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002473 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002474
2475 /*
2476 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302477 * However, this is not needed if com state is just
2478 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002479 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302480 if (ep->com.state != MPA_REQ_SENT)
2481 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002482
2483 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002484 switch (ep->com.state) {
2485 case CONNECTING:
2486 break;
2487 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002488 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002489 break;
2490 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002491 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002492 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302493 connect_reply_upcall(ep, -ECONNRESET);
2494 else {
2495 /*
2496 * we just don't send notification upwards because we
2497 * want to retry with mpa_v1 without upper layers even
2498 * knowing it.
2499 *
2500 * do some housekeeping so as to re-initiate the
2501 * connection
2502 */
2503 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2504 mpa_rev);
2505 ep->retry_with_mpa_v1 = 1;
2506 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002507 break;
2508 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002509 break;
2510 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002511 break;
2512 case MORIBUND:
2513 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002514 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002515 /*FALLTHROUGH*/
2516 case FPDU_MODE:
2517 if (ep->com.cm_id && ep->com.qp) {
2518 attrs.next_state = C4IW_QP_STATE_ERROR;
2519 ret = c4iw_modify_qp(ep->com.qp->rhp,
2520 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2521 &attrs, 1);
2522 if (ret)
2523 printk(KERN_ERR MOD
2524 "%s - qp <- error failed!\n",
2525 __func__);
2526 }
2527 peer_abort_upcall(ep);
2528 break;
2529 case ABORTING:
2530 break;
2531 case DEAD:
2532 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002533 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002534 return 0;
2535 default:
2536 BUG_ON(1);
2537 break;
2538 }
2539 dst_confirm(ep->dst);
2540 if (ep->com.state != ABORTING) {
2541 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302542 /* we don't release if we want to retry with mpa_v1 */
2543 if (!ep->retry_with_mpa_v1)
2544 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002545 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002546 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002547
2548 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2549 if (!rpl_skb) {
2550 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2551 __func__);
2552 release = 1;
2553 goto out;
2554 }
2555 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2556 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2557 INIT_TP_WR(rpl, ep->hwtid);
2558 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2559 rpl->cmd = CPL_ABORT_NO_RST;
2560 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2561out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002562 if (release)
2563 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002564 else if (ep->retry_with_mpa_v1) {
2565 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302566 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2567 dst_release(ep->dst);
2568 cxgb4_l2t_release(ep->l2t);
2569 c4iw_reconnect(ep);
2570 }
2571
Steve Wisecfdda9d2010-04-21 15:30:06 -07002572 return 0;
2573}
2574
2575static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2576{
2577 struct c4iw_ep *ep;
2578 struct c4iw_qp_attributes attrs;
2579 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002580 int release = 0;
2581 struct tid_info *t = dev->rdev.lldi.tids;
2582 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002583
2584 ep = lookup_tid(t, tid);
2585
2586 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2587 BUG_ON(!ep);
2588
2589 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002590 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002591 switch (ep->com.state) {
2592 case CLOSING:
2593 __state_set(&ep->com, MORIBUND);
2594 break;
2595 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002596 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002597 if ((ep->com.cm_id) && (ep->com.qp)) {
2598 attrs.next_state = C4IW_QP_STATE_IDLE;
2599 c4iw_modify_qp(ep->com.qp->rhp,
2600 ep->com.qp,
2601 C4IW_QP_ATTR_NEXT_STATE,
2602 &attrs, 1);
2603 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302604 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002605 __state_set(&ep->com, DEAD);
2606 release = 1;
2607 break;
2608 case ABORTING:
2609 case DEAD:
2610 break;
2611 default:
2612 BUG_ON(1);
2613 break;
2614 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002615 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002616 if (release)
2617 release_ep_resources(ep);
2618 return 0;
2619}
2620
2621static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2622{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002623 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002624 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002625 unsigned int tid = GET_TID(rpl);
2626 struct c4iw_ep *ep;
2627 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002628
2629 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002630 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002631
Steve Wise30c95c22011-05-09 22:06:22 -07002632 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002633 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2634 ep->com.qp->wq.sq.qid);
2635 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2636 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2637 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2638 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002639 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002640
Steve Wisecfdda9d2010-04-21 15:30:06 -07002641 return 0;
2642}
2643
2644/*
2645 * Upcall from the adapter indicating data has been transmitted.
2646 * For us its just the single MPA request or reply. We can now free
2647 * the skb holding the mpa message.
2648 */
2649static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2650{
2651 struct c4iw_ep *ep;
2652 struct cpl_fw4_ack *hdr = cplhdr(skb);
2653 u8 credits = hdr->credits;
2654 unsigned int tid = GET_TID(hdr);
2655 struct tid_info *t = dev->rdev.lldi.tids;
2656
2657
2658 ep = lookup_tid(t, tid);
2659 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2660 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002661 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2662 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002663 return 0;
2664 }
2665
2666 dst_confirm(ep->dst);
2667 if (ep->mpa_skb) {
2668 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2669 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2670 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2671 kfree_skb(ep->mpa_skb);
2672 ep->mpa_skb = NULL;
2673 }
2674 return 0;
2675}
2676
Steve Wisecfdda9d2010-04-21 15:30:06 -07002677int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2678{
Steve Wisea7db89e2014-03-21 20:40:35 +05302679 int err = 0;
2680 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002681 struct c4iw_ep *ep = to_ep(cm_id);
2682 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2683
Steve Wisea7db89e2014-03-21 20:40:35 +05302684 mutex_lock(&ep->com.mutex);
2685 if (ep->com.state == DEAD) {
2686 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002687 c4iw_put_ep(&ep->com);
2688 return -ECONNRESET;
2689 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002690 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302691 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002692 if (mpa_rev == 0)
2693 abort_connection(ep, NULL, GFP_KERNEL);
2694 else {
2695 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302696 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002697 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302698 mutex_unlock(&ep->com.mutex);
2699 if (disconnect)
2700 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002701 c4iw_put_ep(&ep->com);
2702 return 0;
2703}
2704
2705int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2706{
2707 int err;
2708 struct c4iw_qp_attributes attrs;
2709 enum c4iw_qp_attr_mask mask;
2710 struct c4iw_ep *ep = to_ep(cm_id);
2711 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2712 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2713
2714 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302715
2716 mutex_lock(&ep->com.mutex);
2717 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002718 err = -ECONNRESET;
2719 goto err;
2720 }
2721
Steve Wisea7db89e2014-03-21 20:40:35 +05302722 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002723 BUG_ON(!qp);
2724
Vipul Pandya793dad92012-12-10 09:30:56 +00002725 set_bit(ULP_ACCEPT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002726 if ((conn_param->ord > c4iw_max_read_depth) ||
2727 (conn_param->ird > c4iw_max_read_depth)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002728 abort_connection(ep, NULL, GFP_KERNEL);
2729 err = -EINVAL;
2730 goto err;
2731 }
2732
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302733 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2734 if (conn_param->ord > ep->ird) {
2735 ep->ird = conn_param->ird;
2736 ep->ord = conn_param->ord;
2737 send_mpa_reject(ep, conn_param->private_data,
2738 conn_param->private_data_len);
2739 abort_connection(ep, NULL, GFP_KERNEL);
2740 err = -ENOMEM;
2741 goto err;
2742 }
2743 if (conn_param->ird > ep->ord) {
2744 if (!ep->ord)
2745 conn_param->ird = 1;
2746 else {
2747 abort_connection(ep, NULL, GFP_KERNEL);
2748 err = -ENOMEM;
2749 goto err;
2750 }
2751 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002752
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302753 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002754 ep->ird = conn_param->ird;
2755 ep->ord = conn_param->ord;
2756
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302757 if (ep->mpa_attr.version != 2)
2758 if (peer2peer && ep->ird == 0)
2759 ep->ird = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002760
2761 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2762
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302763 cm_id->add_ref(cm_id);
2764 ep->com.cm_id = cm_id;
2765 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00002766 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302767
Steve Wisecfdda9d2010-04-21 15:30:06 -07002768 /* bind QP to EP and move to RTS */
2769 attrs.mpa_attr = ep->mpa_attr;
2770 attrs.max_ird = ep->ird;
2771 attrs.max_ord = ep->ord;
2772 attrs.llp_stream_handle = ep;
2773 attrs.next_state = C4IW_QP_STATE_RTS;
2774
2775 /* bind QP and TID with INIT_WR */
2776 mask = C4IW_QP_ATTR_NEXT_STATE |
2777 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2778 C4IW_QP_ATTR_MPA_ATTR |
2779 C4IW_QP_ATTR_MAX_IRD |
2780 C4IW_QP_ATTR_MAX_ORD;
2781
2782 err = c4iw_modify_qp(ep->com.qp->rhp,
2783 ep->com.qp, mask, &attrs, 1);
2784 if (err)
2785 goto err1;
2786 err = send_mpa_reply(ep, conn_param->private_data,
2787 conn_param->private_data_len);
2788 if (err)
2789 goto err1;
2790
Steve Wisea7db89e2014-03-21 20:40:35 +05302791 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002792 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05302793 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002794 c4iw_put_ep(&ep->com);
2795 return 0;
2796err1:
2797 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002798 cm_id->rem_ref(cm_id);
2799err:
Steve Wisea7db89e2014-03-21 20:40:35 +05302800 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002801 c4iw_put_ep(&ep->com);
2802 return err;
2803}
2804
Vipul Pandya830662f2013-07-04 16:10:47 +05302805static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2806{
2807 struct in_device *ind;
2808 int found = 0;
2809 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2810 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
2811
2812 ind = in_dev_get(dev->rdev.lldi.ports[0]);
2813 if (!ind)
2814 return -EADDRNOTAVAIL;
2815 for_primary_ifa(ind) {
2816 laddr->sin_addr.s_addr = ifa->ifa_address;
2817 raddr->sin_addr.s_addr = ifa->ifa_address;
2818 found = 1;
2819 break;
2820 }
2821 endfor_ifa(ind);
2822 in_dev_put(ind);
2823 return found ? 0 : -EADDRNOTAVAIL;
2824}
2825
2826static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
2827 unsigned char banned_flags)
2828{
2829 struct inet6_dev *idev;
2830 int err = -EADDRNOTAVAIL;
2831
2832 rcu_read_lock();
2833 idev = __in6_dev_get(dev);
2834 if (idev != NULL) {
2835 struct inet6_ifaddr *ifp;
2836
2837 read_lock_bh(&idev->lock);
2838 list_for_each_entry(ifp, &idev->addr_list, if_list) {
2839 if (ifp->scope == IFA_LINK &&
2840 !(ifp->flags & banned_flags)) {
2841 memcpy(addr, &ifp->addr, 16);
2842 err = 0;
2843 break;
2844 }
2845 }
2846 read_unlock_bh(&idev->lock);
2847 }
2848 rcu_read_unlock();
2849 return err;
2850}
2851
2852static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2853{
2854 struct in6_addr uninitialized_var(addr);
2855 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2856 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
2857
2858 if (get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
2859 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
2860 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
2861 return 0;
2862 }
2863 return -EADDRNOTAVAIL;
2864}
2865
Steve Wisecfdda9d2010-04-21 15:30:06 -07002866int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2867{
Steve Wisecfdda9d2010-04-21 15:30:06 -07002868 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2869 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00002870 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05002871 struct sockaddr_in *laddr;
2872 struct sockaddr_in *raddr;
2873 struct sockaddr_in6 *laddr6;
2874 struct sockaddr_in6 *raddr6;
2875 struct iwpm_dev_data pm_reg_msg;
2876 struct iwpm_sa_data pm_msg;
Vipul Pandya830662f2013-07-04 16:10:47 +05302877 __u8 *ra;
2878 int iptype;
Steve Wise9eccfe12014-03-26 17:08:09 -05002879 int iwpm_err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002880
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002881 if ((conn_param->ord > c4iw_max_read_depth) ||
2882 (conn_param->ird > c4iw_max_read_depth)) {
2883 err = -EINVAL;
2884 goto out;
2885 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002886 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2887 if (!ep) {
2888 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2889 err = -ENOMEM;
2890 goto out;
2891 }
2892 init_timer(&ep->timer);
2893 ep->plen = conn_param->private_data_len;
2894 if (ep->plen)
2895 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2896 conn_param->private_data, ep->plen);
2897 ep->ird = conn_param->ird;
2898 ep->ord = conn_param->ord;
2899
2900 if (peer2peer && ep->ord == 0)
2901 ep->ord = 1;
2902
2903 cm_id->add_ref(cm_id);
2904 ep->com.dev = dev;
2905 ep->com.cm_id = cm_id;
2906 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05302907 if (!ep->com.qp) {
2908 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
2909 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05002910 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05302911 }
Vipul Pandya325abea2013-01-07 13:11:53 +00002912 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002913 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2914 ep->com.qp, cm_id);
2915
2916 /*
2917 * Allocate an active TID to initiate a TCP connection.
2918 */
2919 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2920 if (ep->atid == -1) {
2921 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2922 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05002923 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002924 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002925 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002926
Steve Wise9eccfe12014-03-26 17:08:09 -05002927 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2928 sizeof(ep->com.local_addr));
2929 memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
2930 sizeof(ep->com.remote_addr));
2931
2932 /* No port mapper available, go with the specified peer information */
2933 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
2934 sizeof(ep->com.mapped_local_addr));
2935 memcpy(&ep->com.mapped_remote_addr, &cm_id->remote_addr,
2936 sizeof(ep->com.mapped_remote_addr));
2937
2938 c4iw_form_reg_msg(dev, &pm_reg_msg);
2939 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
2940 if (iwpm_err) {
2941 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
2942 __func__, iwpm_err);
2943 }
2944 if (iwpm_valid_pid() && !iwpm_err) {
2945 c4iw_form_pm_msg(ep, &pm_msg);
2946 iwpm_err = iwpm_add_and_query_mapping(&pm_msg, RDMA_NL_C4IW);
2947 if (iwpm_err)
2948 PDBG("%s: Port Mapper query fail (err = %d).\n",
2949 __func__, iwpm_err);
2950 else
2951 c4iw_record_pm_msg(ep, &pm_msg);
2952 }
2953 if (iwpm_create_mapinfo(&ep->com.local_addr,
2954 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
2955 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
2956 err = -ENOMEM;
2957 goto fail1;
2958 }
2959 print_addr(&ep->com, __func__, "add_query/create_mapinfo");
2960 set_bit(RELEASE_MAPINFO, &ep->com.flags);
2961
2962 laddr = (struct sockaddr_in *)&ep->com.mapped_local_addr;
2963 raddr = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
2964 laddr6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
2965 raddr6 = (struct sockaddr_in6 *) &ep->com.mapped_remote_addr;
2966
Vipul Pandya830662f2013-07-04 16:10:47 +05302967 if (cm_id->remote_addr.ss_family == AF_INET) {
2968 iptype = 4;
2969 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002970
Vipul Pandya830662f2013-07-04 16:10:47 +05302971 /*
2972 * Handle loopback requests to INADDR_ANY.
2973 */
2974 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
2975 err = pick_local_ipaddrs(dev, cm_id);
2976 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05002977 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05302978 }
2979
2980 /* find a route */
2981 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
2982 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
2983 ra, ntohs(raddr->sin_port));
2984 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
2985 raddr->sin_addr.s_addr, laddr->sin_port,
2986 raddr->sin_port, 0);
2987 } else {
2988 iptype = 6;
2989 ra = (__u8 *)&raddr6->sin6_addr;
2990
2991 /*
2992 * Handle loopback requests to INADDR_ANY.
2993 */
2994 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
2995 err = pick_local_ip6addrs(dev, cm_id);
2996 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05002997 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05302998 }
2999
3000 /* find a route */
3001 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3002 __func__, laddr6->sin6_addr.s6_addr,
3003 ntohs(laddr6->sin6_port),
3004 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3005 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3006 raddr6->sin6_addr.s6_addr,
3007 laddr6->sin6_port, raddr6->sin6_port, 0,
3008 raddr6->sin6_scope_id);
3009 }
3010 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003011 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3012 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003013 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003014 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003015
Vipul Pandya830662f2013-07-04 16:10:47 +05303016 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true);
David Miller3786cf12011-12-02 16:52:31 +00003017 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003018 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003019 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003020 }
3021
3022 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3023 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3024 ep->l2t->idx);
3025
3026 state_set(&ep->com, CONNECTING);
3027 ep->tos = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003028
3029 /* send connect request to rnic */
3030 err = send_connect(ep);
3031 if (!err)
3032 goto out;
3033
3034 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003035fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003036 dst_release(ep->dst);
3037fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003038 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003039 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003040fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003041 cm_id->rem_ref(cm_id);
3042 c4iw_put_ep(&ep->com);
3043out:
3044 return err;
3045}
3046
Vipul Pandya830662f2013-07-04 16:10:47 +05303047static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3048{
3049 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003050 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
3051 &ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303052
3053 c4iw_init_wr_wait(&ep->com.wr_wait);
3054 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3055 ep->stid, &sin6->sin6_addr,
3056 sin6->sin6_port,
3057 ep->com.dev->rdev.lldi.rxq_ids[0]);
3058 if (!err)
3059 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3060 &ep->com.wr_wait,
3061 0, 0, __func__);
3062 if (err)
3063 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3064 err, ep->stid,
3065 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
3066 return err;
3067}
3068
3069static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3070{
3071 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003072 struct sockaddr_in *sin = (struct sockaddr_in *)
3073 &ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303074
3075 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3076 do {
3077 err = cxgb4_create_server_filter(
3078 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3079 sin->sin_addr.s_addr, sin->sin_port, 0,
3080 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3081 if (err == -EBUSY) {
3082 set_current_state(TASK_UNINTERRUPTIBLE);
3083 schedule_timeout(usecs_to_jiffies(100));
3084 }
3085 } while (err == -EBUSY);
3086 } else {
3087 c4iw_init_wr_wait(&ep->com.wr_wait);
3088 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3089 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3090 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3091 if (!err)
3092 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3093 &ep->com.wr_wait,
3094 0, 0, __func__);
3095 }
3096 if (err)
3097 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3098 , err, ep->stid,
3099 &sin->sin_addr, ntohs(sin->sin_port));
3100 return err;
3101}
3102
Steve Wisecfdda9d2010-04-21 15:30:06 -07003103int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3104{
3105 int err = 0;
3106 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3107 struct c4iw_listen_ep *ep;
Steve Wise9eccfe12014-03-26 17:08:09 -05003108 struct iwpm_dev_data pm_reg_msg;
3109 struct iwpm_sa_data pm_msg;
3110 int iwpm_err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003111
Steve Wisecfdda9d2010-04-21 15:30:06 -07003112 might_sleep();
3113
3114 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3115 if (!ep) {
3116 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3117 err = -ENOMEM;
3118 goto fail1;
3119 }
3120 PDBG("%s ep %p\n", __func__, ep);
3121 cm_id->add_ref(cm_id);
3122 ep->com.cm_id = cm_id;
3123 ep->com.dev = dev;
3124 ep->backlog = backlog;
Steve Wise24d44a32013-07-04 16:10:44 +05303125 memcpy(&ep->com.local_addr, &cm_id->local_addr,
3126 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003127
3128 /*
3129 * Allocate a server TID.
3130 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303131 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3132 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303133 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
3134 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003135 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303136 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
3137 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003138
Steve Wisecfdda9d2010-04-21 15:30:06 -07003139 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003140 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003141 err = -ENOMEM;
3142 goto fail2;
3143 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003144 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003145
3146 /* No port mapper available, go with the specified info */
3147 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3148 sizeof(ep->com.mapped_local_addr));
3149
3150 c4iw_form_reg_msg(dev, &pm_reg_msg);
3151 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3152 if (iwpm_err) {
3153 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3154 __func__, iwpm_err);
3155 }
3156 if (iwpm_valid_pid() && !iwpm_err) {
3157 memcpy(&pm_msg.loc_addr, &ep->com.local_addr,
3158 sizeof(ep->com.local_addr));
3159 iwpm_err = iwpm_add_mapping(&pm_msg, RDMA_NL_C4IW);
3160 if (iwpm_err)
3161 PDBG("%s: Port Mapper query fail (err = %d).\n",
3162 __func__, iwpm_err);
3163 else
3164 memcpy(&ep->com.mapped_local_addr,
3165 &pm_msg.mapped_loc_addr,
3166 sizeof(ep->com.mapped_local_addr));
3167 }
3168 if (iwpm_create_mapinfo(&ep->com.local_addr,
3169 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3170 err = -ENOMEM;
3171 goto fail3;
3172 }
3173 print_addr(&ep->com, __func__, "add_mapping/create_mapinfo");
3174
3175 set_bit(RELEASE_MAPINFO, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003176 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303177 if (ep->com.local_addr.ss_family == AF_INET)
3178 err = create_server4(dev, ep);
3179 else
3180 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003181 if (!err) {
3182 cm_id->provider_data = ep;
3183 goto out;
3184 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003185
3186fail3:
Vipul Pandya830662f2013-07-04 16:10:47 +05303187 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3188 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003189fail2:
3190 cm_id->rem_ref(cm_id);
3191 c4iw_put_ep(&ep->com);
3192fail1:
3193out:
3194 return err;
3195}
3196
3197int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3198{
3199 int err;
3200 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3201
3202 PDBG("%s ep %p\n", __func__, ep);
3203
3204 might_sleep();
3205 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303206 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3207 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003208 err = cxgb4_remove_server_filter(
3209 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3210 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3211 } else {
3212 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303213 err = cxgb4_remove_server(
3214 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3215 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003216 if (err)
3217 goto done;
3218 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3219 0, 0, __func__);
3220 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003221 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303222 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3223 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003224done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003225 cm_id->rem_ref(cm_id);
3226 c4iw_put_ep(&ep->com);
3227 return err;
3228}
3229
3230int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3231{
3232 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003233 int close = 0;
3234 int fatal = 0;
3235 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003236
Steve Wise2f5b48c2010-09-10 11:15:36 -05003237 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003238
3239 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3240 states[ep->com.state], abrupt);
3241
3242 rdev = &ep->com.dev->rdev;
3243 if (c4iw_fatal_error(rdev)) {
3244 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303245 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003246 ep->com.state = DEAD;
3247 }
3248 switch (ep->com.state) {
3249 case MPA_REQ_WAIT:
3250 case MPA_REQ_SENT:
3251 case MPA_REQ_RCVD:
3252 case MPA_REP_SENT:
3253 case FPDU_MODE:
3254 close = 1;
3255 if (abrupt)
3256 ep->com.state = ABORTING;
3257 else {
3258 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003259 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003260 }
3261 set_bit(CLOSE_SENT, &ep->com.flags);
3262 break;
3263 case CLOSING:
3264 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3265 close = 1;
3266 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003267 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003268 ep->com.state = ABORTING;
3269 } else
3270 ep->com.state = MORIBUND;
3271 }
3272 break;
3273 case MORIBUND:
3274 case ABORTING:
3275 case DEAD:
3276 PDBG("%s ignoring disconnect ep %p state %u\n",
3277 __func__, ep, ep->com.state);
3278 break;
3279 default:
3280 BUG();
3281 break;
3282 }
3283
Steve Wisecfdda9d2010-04-21 15:30:06 -07003284 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003285 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003286 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303287 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003288 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003289 } else {
3290 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003291 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003292 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003293 if (ret)
3294 fatal = 1;
3295 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003296 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003297 if (fatal)
3298 release_ep_resources(ep);
3299 return ret;
3300}
3301
Vipul Pandya1cab7752012-12-10 09:30:55 +00003302static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3303 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3304{
3305 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003306 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003307
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003308 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3309 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003310 if (!ep)
3311 return;
3312
3313 switch (req->retval) {
3314 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003315 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3316 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3317 send_fw_act_open_req(ep, atid);
3318 return;
3319 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003320 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003321 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3322 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3323 send_fw_act_open_req(ep, atid);
3324 return;
3325 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003326 break;
3327 default:
3328 pr_info("%s unexpected ofld conn wr retval %d\n",
3329 __func__, req->retval);
3330 break;
3331 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003332 pr_err("active ofld_connect_wr failure %d atid %d\n",
3333 req->retval, atid);
3334 mutex_lock(&dev->rdev.stats.lock);
3335 dev->rdev.stats.act_ofld_conn_fails++;
3336 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003337 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003338 state_set(&ep->com, DEAD);
3339 remove_handle(dev, &dev->atid_idr, atid);
3340 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3341 dst_release(ep->dst);
3342 cxgb4_l2t_release(ep->l2t);
3343 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003344}
3345
3346static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3347 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3348{
3349 struct sk_buff *rpl_skb;
3350 struct cpl_pass_accept_req *cpl;
3351 int ret;
3352
Paul Bolle710a3112013-02-05 20:51:30 +00003353 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003354 BUG_ON(!rpl_skb);
3355 if (req->retval) {
3356 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003357 mutex_lock(&dev->rdev.stats.lock);
3358 dev->rdev.stats.pas_ofld_conn_fails++;
3359 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003360 kfree_skb(rpl_skb);
3361 } else {
3362 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3363 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003364 (__force u32) htonl(
3365 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003366 ret = pass_accept_req(dev, rpl_skb);
3367 if (!ret)
3368 kfree_skb(rpl_skb);
3369 }
3370 return;
3371}
3372
3373static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003374{
3375 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003376 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3377
3378 switch (rpl->type) {
3379 case FW6_TYPE_CQE:
3380 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3381 break;
3382 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3383 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3384 switch (req->t_state) {
3385 case TCP_SYN_SENT:
3386 active_ofld_conn_reply(dev, skb, req);
3387 break;
3388 case TCP_SYN_RECV:
3389 passive_ofld_conn_reply(dev, skb, req);
3390 break;
3391 default:
3392 pr_err("%s unexpected ofld conn wr state %d\n",
3393 __func__, req->t_state);
3394 break;
3395 }
3396 break;
3397 }
3398 return 0;
3399}
3400
3401static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3402{
3403 u32 l2info;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003404 u16 vlantag, len, hdr_len, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003405 u8 intf;
3406 struct cpl_rx_pkt *cpl = cplhdr(skb);
3407 struct cpl_pass_accept_req *req;
3408 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003409 struct c4iw_dev *dev;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003410
Vipul Pandyaf079af72013-03-14 05:08:58 +00003411 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003412 /* Store values from cpl_rx_pkt in temporary location. */
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003413 vlantag = (__force u16) cpl->vlan;
3414 len = (__force u16) cpl->len;
3415 l2info = (__force u32) cpl->l2info;
3416 hdr_len = (__force u16) cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003417 intf = cpl->iff;
3418
3419 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3420
3421 /*
3422 * We need to parse the TCP options from SYN packet.
3423 * to generate cpl_pass_accept_req.
3424 */
3425 memset(&tmp_opt, 0, sizeof(tmp_opt));
3426 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003427 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003428
3429 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3430 memset(req, 0, sizeof(*req));
3431 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003432 V_SYN_MAC_IDX(G_RX_MACIDX(
3433 (__force int) htonl(l2info))) |
Vipul Pandya1cab7752012-12-10 09:30:55 +00003434 F_SYN_XACT_MATCH);
Vipul Pandyaf079af72013-03-14 05:08:58 +00003435 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3436 G_RX_ETHHDR_LEN((__force int) htonl(l2info)) :
3437 G_RX_T5_ETHHDR_LEN((__force int) htonl(l2info));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003438 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(
3439 (__force int) htonl(l2info))) |
3440 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(
3441 (__force int) htons(hdr_len))) |
3442 V_IP_HDR_LEN(G_RX_IPHDR_LEN(
3443 (__force int) htons(hdr_len))) |
Vipul Pandyaf079af72013-03-14 05:08:58 +00003444 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(eth_hdr_len)));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003445 req->vlan = (__force __be16) vlantag;
3446 req->len = (__force __be16) len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003447 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
3448 PASS_OPEN_TOS(tos));
3449 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3450 if (tmp_opt.wscale_ok)
3451 req->tcpopt.wsf = tmp_opt.snd_wscale;
3452 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3453 if (tmp_opt.sack_ok)
3454 req->tcpopt.sack = 1;
3455 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3456 return;
3457}
3458
3459static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3460 __be32 laddr, __be16 lport,
3461 __be32 raddr, __be16 rport,
3462 u32 rcv_isn, u32 filter, u16 window,
3463 u32 rss_qid, u8 port_id)
3464{
3465 struct sk_buff *req_skb;
3466 struct fw_ofld_connection_wr *req;
3467 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303468 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003469
3470 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3471 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3472 memset(req, 0, sizeof(*req));
3473 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
3474 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
3475 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003476 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003477 req->le.lport = lport;
3478 req->le.pport = rport;
3479 req->le.u.ipv4.lip = laddr;
3480 req->le.u.ipv4.pip = raddr;
3481 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3482 req->tcb.rcv_adv = htons(window);
3483 req->tcb.t_state_to_astid =
3484 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
3485 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
3486 V_FW_OFLD_CONNECTION_WR_ASTID(
3487 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
3488
3489 /*
3490 * We store the qid in opt2 which will be used by the firmware
3491 * to send us the wr response.
3492 */
3493 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
3494
3495 /*
3496 * We initialize the MSS index in TCB to 0xF.
3497 * So that when driver sends cpl_pass_accept_rpl
3498 * TCB picks up the correct value. If this was 0
3499 * TP will ignore any value > 0 for MSS index.
3500 */
3501 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
Paul Bolle710a3112013-02-05 20:51:30 +00003502 req->cookie = (unsigned long)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003503
3504 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303505 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3506 if (ret < 0) {
3507 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3508 ret);
3509 kfree_skb(skb);
3510 kfree_skb(req_skb);
3511 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003512}
3513
3514/*
3515 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3516 * messages when a filter is being used instead of server to
3517 * redirect a syn packet. When packets hit filter they are redirected
3518 * to the offload queue and driver tries to establish the connection
3519 * using firmware work request.
3520 */
3521static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3522{
3523 int stid;
3524 unsigned int filter;
3525 struct ethhdr *eh = NULL;
3526 struct vlan_ethhdr *vlan_eh = NULL;
3527 struct iphdr *iph;
3528 struct tcphdr *tcph;
3529 struct rss_header *rss = (void *)skb->data;
3530 struct cpl_rx_pkt *cpl = (void *)skb->data;
3531 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3532 struct l2t_entry *e;
3533 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003534 struct c4iw_ep *lep;
3535 u16 window;
3536 struct port_info *pi;
3537 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003538 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003539 int step;
3540 u32 tx_chan;
3541 struct neighbour *neigh;
3542
3543 /* Drop all non-SYN packets */
3544 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
3545 goto reject;
3546
3547 /*
3548 * Drop all packets which did not hit the filter.
3549 * Unlikely to happen.
3550 */
3551 if (!(rss->filter_hit && rss->filter_tid))
3552 goto reject;
3553
3554 /*
3555 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3556 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303557 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003558
3559 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3560 if (!lep) {
3561 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3562 goto reject;
3563 }
3564
Vipul Pandyaf079af72013-03-14 05:08:58 +00003565 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3566 G_RX_ETHHDR_LEN(htonl(cpl->l2info)) :
3567 G_RX_T5_ETHHDR_LEN(htonl(cpl->l2info));
3568 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003569 eh = (struct ethhdr *)(req + 1);
3570 iph = (struct iphdr *)(eh + 1);
3571 } else {
3572 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3573 iph = (struct iphdr *)(vlan_eh + 1);
3574 skb->vlan_tci = ntohs(cpl->vlan);
3575 }
3576
3577 if (iph->version != 0x4)
3578 goto reject;
3579
3580 tcph = (struct tcphdr *)(iph + 1);
3581 skb_set_network_header(skb, (void *)iph - (void *)rss);
3582 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3583 skb_get(skb);
3584
3585 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3586 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3587 ntohs(tcph->source), iph->tos);
3588
Vipul Pandya830662f2013-07-04 16:10:47 +05303589 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3590 iph->tos);
3591 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003592 pr_err("%s - failed to find dst entry!\n",
3593 __func__);
3594 goto reject;
3595 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003596 neigh = dst_neigh_lookup_skb(dst, skb);
3597
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003598 if (!neigh) {
3599 pr_err("%s - failed to allocate neigh!\n",
3600 __func__);
3601 goto free_dst;
3602 }
3603
Vipul Pandya1cab7752012-12-10 09:30:55 +00003604 if (neigh->dev->flags & IFF_LOOPBACK) {
3605 pdev = ip_dev_find(&init_net, iph->daddr);
3606 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3607 pdev, 0);
3608 pi = (struct port_info *)netdev_priv(pdev);
3609 tx_chan = cxgb4_port_chan(pdev);
3610 dev_put(pdev);
3611 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303612 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003613 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303614 pdev, 0);
3615 pi = (struct port_info *)netdev_priv(pdev);
3616 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003617 }
Steve Wiseebf00062014-03-19 17:44:40 +05303618 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003619 if (!e) {
3620 pr_err("%s - failed to allocate l2t entry!\n",
3621 __func__);
3622 goto free_dst;
3623 }
3624
3625 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3626 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003627 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003628
3629 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303630 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3631 dev->rdev.lldi.ports[0],
3632 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003633
3634 /*
3635 * Synthesize the cpl_pass_accept_req. We have everything except the
3636 * TID. Once firmware sends a reply with TID we update the TID field
3637 * in cpl and pass it through the regular cpl_pass_accept_req path.
3638 */
3639 build_cpl_pass_accept_req(skb, stid, iph->tos);
3640 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3641 tcph->source, ntohl(tcph->seq), filter, window,
3642 rss_qid, pi->port_id);
3643 cxgb4_l2t_release(e);
3644free_dst:
3645 dst_release(dst);
3646reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003647 return 0;
3648}
3649
Steve Wisecfdda9d2010-04-21 15:30:06 -07003650/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003651 * These are the real handlers that are called from a
3652 * work queue.
3653 */
3654static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3655 [CPL_ACT_ESTABLISH] = act_establish,
3656 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3657 [CPL_RX_DATA] = rx_data,
3658 [CPL_ABORT_RPL_RSS] = abort_rpl,
3659 [CPL_ABORT_RPL] = abort_rpl,
3660 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3661 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3662 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3663 [CPL_PASS_ESTABLISH] = pass_establish,
3664 [CPL_PEER_CLOSE] = peer_close,
3665 [CPL_ABORT_REQ_RSS] = peer_abort,
3666 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3667 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003668 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003669 [CPL_FW6_MSG] = deferred_fw6_msg,
3670 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003671};
3672
3673static void process_timeout(struct c4iw_ep *ep)
3674{
3675 struct c4iw_qp_attributes attrs;
3676 int abort = 1;
3677
Steve Wise2f5b48c2010-09-10 11:15:36 -05003678 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003679 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3680 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003681 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003682 switch (ep->com.state) {
3683 case MPA_REQ_SENT:
3684 __state_set(&ep->com, ABORTING);
3685 connect_reply_upcall(ep, -ETIMEDOUT);
3686 break;
3687 case MPA_REQ_WAIT:
3688 __state_set(&ep->com, ABORTING);
3689 break;
3690 case CLOSING:
3691 case MORIBUND:
3692 if (ep->com.cm_id && ep->com.qp) {
3693 attrs.next_state = C4IW_QP_STATE_ERROR;
3694 c4iw_modify_qp(ep->com.qp->rhp,
3695 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3696 &attrs, 1);
3697 }
3698 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303699 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003700 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003701 case ABORTING:
3702 case DEAD:
3703
3704 /*
3705 * These states are expected if the ep timed out at the same
3706 * time as another thread was calling stop_ep_timer().
3707 * So we silently do nothing for these states.
3708 */
3709 abort = 0;
3710 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003711 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003712 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003713 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003714 abort = 0;
3715 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003716 if (abort)
3717 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecc18b932014-04-24 14:31:53 -05003718 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003719 c4iw_put_ep(&ep->com);
3720}
3721
3722static void process_timedout_eps(void)
3723{
3724 struct c4iw_ep *ep;
3725
3726 spin_lock_irq(&timeout_lock);
3727 while (!list_empty(&timeout_list)) {
3728 struct list_head *tmp;
3729
3730 tmp = timeout_list.next;
3731 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003732 tmp->next = NULL;
3733 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003734 spin_unlock_irq(&timeout_lock);
3735 ep = list_entry(tmp, struct c4iw_ep, entry);
3736 process_timeout(ep);
3737 spin_lock_irq(&timeout_lock);
3738 }
3739 spin_unlock_irq(&timeout_lock);
3740}
3741
3742static void process_work(struct work_struct *work)
3743{
3744 struct sk_buff *skb = NULL;
3745 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003746 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003747 unsigned int opcode;
3748 int ret;
3749
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003750 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003751 while ((skb = skb_dequeue(&rxq))) {
3752 rpl = cplhdr(skb);
3753 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3754 opcode = rpl->ot.opcode;
3755
3756 BUG_ON(!work_handlers[opcode]);
3757 ret = work_handlers[opcode](dev, skb);
3758 if (!ret)
3759 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003760 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003761 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003762}
3763
3764static DECLARE_WORK(skb_work, process_work);
3765
3766static void ep_timeout(unsigned long arg)
3767{
3768 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003769 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003770
3771 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003772 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003773 /*
3774 * Only insert if it is not already on the list.
3775 */
3776 if (!ep->entry.next) {
3777 list_add_tail(&ep->entry, &timeout_list);
3778 kickit = 1;
3779 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003780 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003781 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003782 if (kickit)
3783 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003784}
3785
3786/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07003787 * All the CM events are handled on a work queue to have a safe context.
3788 */
3789static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3790{
3791
3792 /*
3793 * Save dev in the skb->cb area.
3794 */
3795 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3796
3797 /*
3798 * Queue the skb and schedule the worker thread.
3799 */
3800 skb_queue_tail(&rxq, skb);
3801 queue_work(workq, &skb_work);
3802 return 0;
3803}
3804
3805static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3806{
3807 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3808
3809 if (rpl->status != CPL_ERR_NONE) {
3810 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3811 "for tid %u\n", rpl->status, GET_TID(rpl));
3812 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003813 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003814 return 0;
3815}
3816
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003817static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3818{
3819 struct cpl_fw6_msg *rpl = cplhdr(skb);
3820 struct c4iw_wr_wait *wr_waitp;
3821 int ret;
3822
3823 PDBG("%s type %u\n", __func__, rpl->type);
3824
3825 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003826 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003827 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07003828 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003829 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07003830 if (wr_waitp)
3831 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003832 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003833 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003834 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003835 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00003836 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003837 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003838 default:
3839 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3840 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003841 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003842 break;
3843 }
3844 return 0;
3845}
3846
Steve Wise8da7e7a2011-06-14 20:59:27 +00003847static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3848{
3849 struct cpl_abort_req_rss *req = cplhdr(skb);
3850 struct c4iw_ep *ep;
3851 struct tid_info *t = dev->rdev.lldi.tids;
3852 unsigned int tid = GET_TID(req);
3853
3854 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05003855 if (!ep) {
3856 printk(KERN_WARNING MOD
3857 "Abort on non-existent endpoint, tid %d\n", tid);
3858 kfree_skb(skb);
3859 return 0;
3860 }
Steve Wise7a2cea22014-03-14 21:52:07 +05303861 if (is_neg_adv(req->status)) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003862 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3863 ep->hwtid);
3864 kfree_skb(skb);
3865 return 0;
3866 }
3867 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3868 ep->com.state);
3869
3870 /*
3871 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003872 * However, if we are on MPAv2 and want to retry with MPAv1
3873 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00003874 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003875 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
3876 if (ep->com.state != MPA_REQ_SENT)
3877 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3878 } else
3879 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003880 sched(dev, skb);
3881 return 0;
3882}
3883
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003884/*
3885 * Most upcalls from the T4 Core go to sched() to
3886 * schedule the processing on a work queue.
3887 */
3888c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3889 [CPL_ACT_ESTABLISH] = sched,
3890 [CPL_ACT_OPEN_RPL] = sched,
3891 [CPL_RX_DATA] = sched,
3892 [CPL_ABORT_RPL_RSS] = sched,
3893 [CPL_ABORT_RPL] = sched,
3894 [CPL_PASS_OPEN_RPL] = sched,
3895 [CPL_CLOSE_LISTSRV_RPL] = sched,
3896 [CPL_PASS_ACCEPT_REQ] = sched,
3897 [CPL_PASS_ESTABLISH] = sched,
3898 [CPL_PEER_CLOSE] = sched,
3899 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00003900 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003901 [CPL_RDMA_TERMINATE] = sched,
3902 [CPL_FW4_ACK] = sched,
3903 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003904 [CPL_FW6_MSG] = fw6_msg,
3905 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003906};
3907
Steve Wisecfdda9d2010-04-21 15:30:06 -07003908int __init c4iw_cm_init(void)
3909{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003910 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003911 skb_queue_head_init(&rxq);
3912
3913 workq = create_singlethread_workqueue("iw_cxgb4");
3914 if (!workq)
3915 return -ENOMEM;
3916
Steve Wisecfdda9d2010-04-21 15:30:06 -07003917 return 0;
3918}
3919
3920void __exit c4iw_cm_term(void)
3921{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003922 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003923 flush_workqueue(workq);
3924 destroy_workqueue(workq);
3925}