blob: 768a0fb67dd6d5995545f40037aa2c5157548ce1 [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{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530435 struct c4iw_ep *ep = handle;
436
Steve Wisecfdda9d2010-04-21 15:30:06 -0700437 printk(KERN_ERR MOD "ARP failure duing connect\n");
438 kfree_skb(skb);
Hariprasad S5dab6d32014-06-23 19:12:36 +0530439 connect_reply_upcall(ep, -EHOSTUNREACH);
440 state_set(&ep->com, DEAD);
441 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
442 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
443 dst_release(ep->dst);
444 cxgb4_l2t_release(ep->l2t);
445 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700446}
447
448/*
449 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
450 * and send it along.
451 */
452static void abort_arp_failure(void *handle, struct sk_buff *skb)
453{
454 struct c4iw_rdev *rdev = handle;
455 struct cpl_abort_req *req = cplhdr(skb);
456
457 PDBG("%s rdev %p\n", __func__, rdev);
458 req->cmd = CPL_ABORT_NO_RST;
459 c4iw_ofld_send(rdev, skb);
460}
461
462static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
463{
464 unsigned int flowclen = 80;
465 struct fw_flowc_wr *flowc;
466 int i;
467
468 skb = get_skb(skb, flowclen, GFP_KERNEL);
469 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
470
471 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
472 FW_FLOWC_WR_NPARAMS(8));
473 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
474 16)) | FW_WR_FLOWID(ep->hwtid));
475
476 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Steve Wise94788652011-01-21 17:00:34 +0000477 flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700478 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
479 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
480 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
481 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
482 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
483 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
484 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
485 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
486 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
487 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
488 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530489 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700490 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
491 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
492 /* Pad WR to 16 byte boundary */
493 flowc->mnemval[8].mnemonic = 0;
494 flowc->mnemval[8].val = 0;
495 for (i = 0; i < 9; i++) {
496 flowc->mnemval[i].r4[0] = 0;
497 flowc->mnemval[i].r4[1] = 0;
498 flowc->mnemval[i].r4[2] = 0;
499 }
500
501 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
502 c4iw_ofld_send(&ep->com.dev->rdev, skb);
503}
504
505static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
506{
507 struct cpl_close_con_req *req;
508 struct sk_buff *skb;
509 int wrlen = roundup(sizeof *req, 16);
510
511 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
512 skb = get_skb(NULL, wrlen, gfp);
513 if (!skb) {
514 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
515 return -ENOMEM;
516 }
517 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
518 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
519 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
520 memset(req, 0, wrlen);
521 INIT_TP_WR(req, ep->hwtid);
522 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
523 ep->hwtid));
524 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
525}
526
527static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
528{
529 struct cpl_abort_req *req;
530 int wrlen = roundup(sizeof *req, 16);
531
532 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
533 skb = get_skb(skb, wrlen, gfp);
534 if (!skb) {
535 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
536 __func__);
537 return -ENOMEM;
538 }
539 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
540 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
541 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
542 memset(req, 0, wrlen);
543 INIT_TP_WR(req, ep->hwtid);
544 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
545 req->cmd = CPL_ABORT_SEND_RST;
546 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
547}
548
Steve Wise9eccfe12014-03-26 17:08:09 -0500549/*
550 * c4iw_form_pm_msg - Form a port mapper message with mapping info
551 */
552static void c4iw_form_pm_msg(struct c4iw_ep *ep,
553 struct iwpm_sa_data *pm_msg)
554{
555 memcpy(&pm_msg->loc_addr, &ep->com.local_addr,
556 sizeof(ep->com.local_addr));
557 memcpy(&pm_msg->rem_addr, &ep->com.remote_addr,
558 sizeof(ep->com.remote_addr));
559}
560
561/*
562 * c4iw_form_reg_msg - Form a port mapper message with dev info
563 */
564static void c4iw_form_reg_msg(struct c4iw_dev *dev,
565 struct iwpm_dev_data *pm_msg)
566{
567 memcpy(pm_msg->dev_name, dev->ibdev.name, IWPM_DEVNAME_SIZE);
568 memcpy(pm_msg->if_name, dev->rdev.lldi.ports[0]->name,
569 IWPM_IFNAME_SIZE);
570}
571
572static void c4iw_record_pm_msg(struct c4iw_ep *ep,
573 struct iwpm_sa_data *pm_msg)
574{
575 memcpy(&ep->com.mapped_local_addr, &pm_msg->mapped_loc_addr,
576 sizeof(ep->com.mapped_local_addr));
577 memcpy(&ep->com.mapped_remote_addr, &pm_msg->mapped_rem_addr,
578 sizeof(ep->com.mapped_remote_addr));
579}
580
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530581static void best_mtu(const unsigned short *mtus, unsigned short mtu,
582 unsigned int *idx, int use_ts)
583{
584 unsigned short hdr_size = sizeof(struct iphdr) +
585 sizeof(struct tcphdr) +
586 (use_ts ? 12 : 0);
587 unsigned short data_size = mtu - hdr_size;
588
589 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
590}
591
Steve Wisecfdda9d2010-04-21 15:30:06 -0700592static int send_connect(struct c4iw_ep *ep)
593{
594 struct cpl_act_open_req *req;
Vipul Pandyaf079af72013-03-14 05:08:58 +0000595 struct cpl_t5_act_open_req *t5_req;
Vipul Pandya830662f2013-07-04 16:10:47 +0530596 struct cpl_act_open_req6 *req6;
597 struct cpl_t5_act_open_req6 *t5_req6;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700598 struct sk_buff *skb;
599 u64 opt0;
600 u32 opt2;
601 unsigned int mtu_idx;
602 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +0530603 int wrlen;
604 int sizev4 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
605 sizeof(struct cpl_act_open_req) :
606 sizeof(struct cpl_t5_act_open_req);
607 int sizev6 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
608 sizeof(struct cpl_act_open_req6) :
609 sizeof(struct cpl_t5_act_open_req6);
Steve Wise9eccfe12014-03-26 17:08:09 -0500610 struct sockaddr_in *la = (struct sockaddr_in *)
611 &ep->com.mapped_local_addr;
612 struct sockaddr_in *ra = (struct sockaddr_in *)
613 &ep->com.mapped_remote_addr;
614 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
615 &ep->com.mapped_local_addr;
616 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
617 &ep->com.mapped_remote_addr;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530618 int win;
Vipul Pandya830662f2013-07-04 16:10:47 +0530619
620 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
621 roundup(sizev4, 16) :
622 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700623
624 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
625
626 skb = get_skb(NULL, wrlen, GFP_KERNEL);
627 if (!skb) {
628 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
629 __func__);
630 return -ENOMEM;
631 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000632 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700633
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530634 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
635 enable_tcp_timestamps);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700636 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530637
638 /*
639 * Specify the largest window that will fit in opt0. The
640 * remainder will be specified in the rx_data_ack.
641 */
642 win = ep->rcv_win >> 10;
643 if (win > RCV_BUFSIZ_MASK)
644 win = RCV_BUFSIZ_MASK;
645
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000646 opt0 = (nocong ? NO_CONG(1) : 0) |
647 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +0000648 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700649 WND_SCALE(wscale) |
650 MSS_IDX(mtu_idx) |
651 L2T_IDX(ep->l2t->idx) |
652 TX_CHAN(ep->tx_chan) |
653 SMAC_SEL(ep->smac_idx) |
654 DSCP(ep->tos) |
Steve Wiseb48f3b92011-03-11 22:30:21 +0000655 ULP_MODE(ULP_MODE_TCPDDP) |
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530656 RCV_BUFSIZ(win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700657 opt2 = RX_CHANNEL(0) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000658 CCTRL_ECN(enable_ecn) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700659 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
660 if (enable_tcp_timestamps)
661 opt2 |= TSTAMPS_EN(1);
662 if (enable_tcp_sack)
663 opt2 |= SACK_EN(1);
664 if (wscale && enable_tcp_window_scaling)
665 opt2 |= WND_SCALE_EN(1);
Steve Wise92e50112014-04-24 14:31:59 -0500666 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
667 opt2 |= T5_OPT_2_VALID;
668 opt2 |= V_CONG_CNTRL(CONG_ALG_TAHOE);
669 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530670 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700671
Vipul Pandyaf079af72013-03-14 05:08:58 +0000672 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Vipul Pandya830662f2013-07-04 16:10:47 +0530673 if (ep->com.remote_addr.ss_family == AF_INET) {
674 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
675 INIT_TP_WR(req, 0);
676 OPCODE_TID(req) = cpu_to_be32(
Vipul Pandyaf079af72013-03-14 05:08:58 +0000677 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
678 ((ep->rss_qid << 14) | ep->atid)));
Vipul Pandya830662f2013-07-04 16:10:47 +0530679 req->local_port = la->sin_port;
680 req->peer_port = ra->sin_port;
681 req->local_ip = la->sin_addr.s_addr;
682 req->peer_ip = ra->sin_addr.s_addr;
683 req->opt0 = cpu_to_be64(opt0);
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530684 req->params = cpu_to_be32(cxgb4_select_ntuple(
685 ep->com.dev->rdev.lldi.ports[0],
686 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530687 req->opt2 = cpu_to_be32(opt2);
688 } else {
689 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
690
691 INIT_TP_WR(req6, 0);
692 OPCODE_TID(req6) = cpu_to_be32(
693 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
694 ((ep->rss_qid<<14)|ep->atid)));
695 req6->local_port = la6->sin6_port;
696 req6->peer_port = ra6->sin6_port;
697 req6->local_ip_hi = *((__be64 *)
698 (la6->sin6_addr.s6_addr));
699 req6->local_ip_lo = *((__be64 *)
700 (la6->sin6_addr.s6_addr + 8));
701 req6->peer_ip_hi = *((__be64 *)
702 (ra6->sin6_addr.s6_addr));
703 req6->peer_ip_lo = *((__be64 *)
704 (ra6->sin6_addr.s6_addr + 8));
705 req6->opt0 = cpu_to_be64(opt0);
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530706 req6->params = cpu_to_be32(cxgb4_select_ntuple(
707 ep->com.dev->rdev.lldi.ports[0],
708 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530709 req6->opt2 = cpu_to_be32(opt2);
710 }
711 } else {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530712 u32 isn = (prandom_u32() & ~7UL) - 1;
713
714 opt2 |= T5_OPT_2_VALID;
715 opt2 |= CONG_CNTRL_VALID; /* OPT_2_ISS for T5 */
716 if (peer2peer)
717 isn += 4;
718
Vipul Pandya830662f2013-07-04 16:10:47 +0530719 if (ep->com.remote_addr.ss_family == AF_INET) {
720 t5_req = (struct cpl_t5_act_open_req *)
721 skb_put(skb, wrlen);
722 INIT_TP_WR(t5_req, 0);
723 OPCODE_TID(t5_req) = cpu_to_be32(
724 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
725 ((ep->rss_qid << 14) | ep->atid)));
726 t5_req->local_port = la->sin_port;
727 t5_req->peer_port = ra->sin_port;
728 t5_req->local_ip = la->sin_addr.s_addr;
729 t5_req->peer_ip = ra->sin_addr.s_addr;
730 t5_req->opt0 = cpu_to_be64(opt0);
731 t5_req->params = cpu_to_be64(V_FILTER_TUPLE(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530732 cxgb4_select_ntuple(
733 ep->com.dev->rdev.lldi.ports[0],
734 ep->l2t)));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530735 t5_req->rsvd = cpu_to_be32(isn);
736 PDBG("%s snd_isn %u\n", __func__,
737 be32_to_cpu(t5_req->rsvd));
Vipul Pandya830662f2013-07-04 16:10:47 +0530738 t5_req->opt2 = cpu_to_be32(opt2);
739 } else {
740 t5_req6 = (struct cpl_t5_act_open_req6 *)
741 skb_put(skb, wrlen);
742 INIT_TP_WR(t5_req6, 0);
743 OPCODE_TID(t5_req6) = cpu_to_be32(
744 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
745 ((ep->rss_qid<<14)|ep->atid)));
746 t5_req6->local_port = la6->sin6_port;
747 t5_req6->peer_port = ra6->sin6_port;
748 t5_req6->local_ip_hi = *((__be64 *)
749 (la6->sin6_addr.s6_addr));
750 t5_req6->local_ip_lo = *((__be64 *)
751 (la6->sin6_addr.s6_addr + 8));
752 t5_req6->peer_ip_hi = *((__be64 *)
753 (ra6->sin6_addr.s6_addr));
754 t5_req6->peer_ip_lo = *((__be64 *)
755 (ra6->sin6_addr.s6_addr + 8));
756 t5_req6->opt0 = cpu_to_be64(opt0);
757 t5_req6->params = (__force __be64)cpu_to_be32(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530758 cxgb4_select_ntuple(
759 ep->com.dev->rdev.lldi.ports[0],
760 ep->l2t));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530761 t5_req6->rsvd = cpu_to_be32(isn);
762 PDBG("%s snd_isn %u\n", __func__,
763 be32_to_cpu(t5_req6->rsvd));
Vipul Pandya830662f2013-07-04 16:10:47 +0530764 t5_req6->opt2 = cpu_to_be32(opt2);
765 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000766 }
767
Vipul Pandya793dad92012-12-10 09:30:56 +0000768 set_bit(ACT_OPEN_REQ, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700769 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
770}
771
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530772static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
773 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700774{
775 int mpalen, wrlen;
776 struct fw_ofld_tx_data_wr *req;
777 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530778 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700779
780 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
781
782 BUG_ON(skb_cloned(skb));
783
784 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530785 if (mpa_rev_to_use == 2)
786 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700787 wrlen = roundup(mpalen + sizeof *req, 16);
788 skb = get_skb(skb, wrlen, GFP_KERNEL);
789 if (!skb) {
790 connect_reply_upcall(ep, -ENOMEM);
791 return;
792 }
793 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
794
795 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
796 memset(req, 0, wrlen);
797 req->op_to_immdlen = cpu_to_be32(
798 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
799 FW_WR_COMPL(1) |
800 FW_WR_IMMDLEN(mpalen));
801 req->flowid_len16 = cpu_to_be32(
802 FW_WR_FLOWID(ep->hwtid) |
803 FW_WR_LEN16(wrlen >> 4));
804 req->plen = cpu_to_be32(mpalen);
805 req->tunnel_to_proxy = cpu_to_be32(
806 FW_OFLD_TX_DATA_WR_FLUSH(1) |
807 FW_OFLD_TX_DATA_WR_SHOVE(1));
808
809 mpa = (struct mpa_message *)(req + 1);
810 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
811 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530812 (markers_enabled ? MPA_MARKERS : 0) |
813 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700814 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530815 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530816 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530817 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530818 ep->retry_with_mpa_v1 = 0;
819 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700820
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530821 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700822 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
823 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530824 mpa_v2_params.ird = htons((u16)ep->ird);
825 mpa_v2_params.ord = htons((u16)ep->ord);
826
827 if (peer2peer) {
828 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
829 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
830 mpa_v2_params.ord |=
831 htons(MPA_V2_RDMA_WRITE_RTR);
832 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
833 mpa_v2_params.ord |=
834 htons(MPA_V2_RDMA_READ_RTR);
835 }
836 memcpy(mpa->private_data, &mpa_v2_params,
837 sizeof(struct mpa_v2_conn_params));
838
839 if (ep->plen)
840 memcpy(mpa->private_data +
841 sizeof(struct mpa_v2_conn_params),
842 ep->mpa_pkt + sizeof(*mpa), ep->plen);
843 } else
844 if (ep->plen)
845 memcpy(mpa->private_data,
846 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700847
848 /*
849 * Reference the mpa skb. This ensures the data area
850 * will remain in memory until the hw acks the tx.
851 * Function fw4_ack() will deref it.
852 */
853 skb_get(skb);
854 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
855 BUG_ON(ep->mpa_skb);
856 ep->mpa_skb = skb;
857 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
858 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530859 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700860 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530861 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700862 return;
863}
864
865static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
866{
867 int mpalen, wrlen;
868 struct fw_ofld_tx_data_wr *req;
869 struct mpa_message *mpa;
870 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530871 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700872
873 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
874
875 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530876 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
877 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700878 wrlen = roundup(mpalen + sizeof *req, 16);
879
880 skb = get_skb(NULL, wrlen, GFP_KERNEL);
881 if (!skb) {
882 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
883 return -ENOMEM;
884 }
885 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
886
887 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
888 memset(req, 0, wrlen);
889 req->op_to_immdlen = cpu_to_be32(
890 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
891 FW_WR_COMPL(1) |
892 FW_WR_IMMDLEN(mpalen));
893 req->flowid_len16 = cpu_to_be32(
894 FW_WR_FLOWID(ep->hwtid) |
895 FW_WR_LEN16(wrlen >> 4));
896 req->plen = cpu_to_be32(mpalen);
897 req->tunnel_to_proxy = cpu_to_be32(
898 FW_OFLD_TX_DATA_WR_FLUSH(1) |
899 FW_OFLD_TX_DATA_WR_SHOVE(1));
900
901 mpa = (struct mpa_message *)(req + 1);
902 memset(mpa, 0, sizeof(*mpa));
903 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
904 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000905 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700906 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530907
908 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
909 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700910 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
911 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530912 mpa_v2_params.ird = htons(((u16)ep->ird) |
913 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
914 0));
915 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
916 (p2p_type ==
917 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
918 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
919 FW_RI_INIT_P2PTYPE_READ_REQ ?
920 MPA_V2_RDMA_READ_RTR : 0) : 0));
921 memcpy(mpa->private_data, &mpa_v2_params,
922 sizeof(struct mpa_v2_conn_params));
923
924 if (ep->plen)
925 memcpy(mpa->private_data +
926 sizeof(struct mpa_v2_conn_params), pdata, plen);
927 } else
928 if (plen)
929 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700930
931 /*
932 * Reference the mpa skb again. This ensures the data area
933 * will remain in memory until the hw acks the tx.
934 * Function fw4_ack() will deref it.
935 */
936 skb_get(skb);
937 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
938 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
939 BUG_ON(ep->mpa_skb);
940 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +0530941 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700942 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
943}
944
945static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
946{
947 int mpalen, wrlen;
948 struct fw_ofld_tx_data_wr *req;
949 struct mpa_message *mpa;
950 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530951 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700952
953 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
954
955 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530956 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
957 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700958 wrlen = roundup(mpalen + sizeof *req, 16);
959
960 skb = get_skb(NULL, wrlen, GFP_KERNEL);
961 if (!skb) {
962 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
963 return -ENOMEM;
964 }
965 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
966
967 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
968 memset(req, 0, wrlen);
969 req->op_to_immdlen = cpu_to_be32(
970 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
971 FW_WR_COMPL(1) |
972 FW_WR_IMMDLEN(mpalen));
973 req->flowid_len16 = cpu_to_be32(
974 FW_WR_FLOWID(ep->hwtid) |
975 FW_WR_LEN16(wrlen >> 4));
976 req->plen = cpu_to_be32(mpalen);
977 req->tunnel_to_proxy = cpu_to_be32(
978 FW_OFLD_TX_DATA_WR_FLUSH(1) |
979 FW_OFLD_TX_DATA_WR_SHOVE(1));
980
981 mpa = (struct mpa_message *)(req + 1);
982 memset(mpa, 0, sizeof(*mpa));
983 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
984 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
985 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530986 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700987 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530988
989 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
990 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700991 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
992 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530993 mpa_v2_params.ird = htons((u16)ep->ird);
994 mpa_v2_params.ord = htons((u16)ep->ord);
995 if (peer2peer && (ep->mpa_attr.p2p_type !=
996 FW_RI_INIT_P2PTYPE_DISABLED)) {
997 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
998
999 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1000 mpa_v2_params.ord |=
1001 htons(MPA_V2_RDMA_WRITE_RTR);
1002 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1003 mpa_v2_params.ord |=
1004 htons(MPA_V2_RDMA_READ_RTR);
1005 }
1006
1007 memcpy(mpa->private_data, &mpa_v2_params,
1008 sizeof(struct mpa_v2_conn_params));
1009
1010 if (ep->plen)
1011 memcpy(mpa->private_data +
1012 sizeof(struct mpa_v2_conn_params), pdata, plen);
1013 } else
1014 if (plen)
1015 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001016
1017 /*
1018 * Reference the mpa skb. This ensures the data area
1019 * will remain in memory until the hw acks the tx.
1020 * Function fw4_ack() will deref it.
1021 */
1022 skb_get(skb);
1023 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1024 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301025 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301026 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001027 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1028}
1029
1030static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1031{
1032 struct c4iw_ep *ep;
1033 struct cpl_act_establish *req = cplhdr(skb);
1034 unsigned int tid = GET_TID(req);
1035 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
1036 struct tid_info *t = dev->rdev.lldi.tids;
1037
1038 ep = lookup_atid(t, atid);
1039
1040 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1041 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1042
Steve Wisea7db89e2014-03-21 20:40:35 +05301043 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001044 dst_confirm(ep->dst);
1045
1046 /* setup the hwtid for this connection */
1047 ep->hwtid = tid;
1048 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001049 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001050
1051 ep->snd_seq = be32_to_cpu(req->snd_isn);
1052 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1053
1054 set_emss(ep, ntohs(req->tcp_opt));
1055
1056 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001057 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001058 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001059 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001060
1061 /* start MPA negotiation */
1062 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301063 if (ep->retry_with_mpa_v1)
1064 send_mpa_req(ep, skb, 1);
1065 else
1066 send_mpa_req(ep, skb, mpa_rev);
Steve Wisea7db89e2014-03-21 20:40:35 +05301067 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001068 return 0;
1069}
1070
Steve Wisebe13b2d2014-03-21 20:40:33 +05301071static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001072{
1073 struct iw_cm_event event;
1074
1075 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1076 memset(&event, 0, sizeof(event));
1077 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301078 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001079 if (ep->com.cm_id) {
1080 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1081 ep, ep->com.cm_id, ep->hwtid);
1082 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1083 ep->com.cm_id->rem_ref(ep->com.cm_id);
1084 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001085 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001086 }
1087}
1088
1089static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
1090{
1091 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecc18b932014-04-24 14:31:53 -05001092 __state_set(&ep->com, ABORTING);
Vipul Pandya793dad92012-12-10 09:30:56 +00001093 set_bit(ABORT_CONN, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001094 return send_abort(ep, skb, gfp);
1095}
1096
1097static void peer_close_upcall(struct c4iw_ep *ep)
1098{
1099 struct iw_cm_event event;
1100
1101 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1102 memset(&event, 0, sizeof(event));
1103 event.event = IW_CM_EVENT_DISCONNECT;
1104 if (ep->com.cm_id) {
1105 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1106 ep, ep->com.cm_id, ep->hwtid);
1107 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001108 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001109 }
1110}
1111
1112static void peer_abort_upcall(struct c4iw_ep *ep)
1113{
1114 struct iw_cm_event event;
1115
1116 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1117 memset(&event, 0, sizeof(event));
1118 event.event = IW_CM_EVENT_CLOSE;
1119 event.status = -ECONNRESET;
1120 if (ep->com.cm_id) {
1121 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1122 ep->com.cm_id, ep->hwtid);
1123 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1124 ep->com.cm_id->rem_ref(ep->com.cm_id);
1125 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001126 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001127 }
1128}
1129
1130static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1131{
1132 struct iw_cm_event event;
1133
1134 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1135 memset(&event, 0, sizeof(event));
1136 event.event = IW_CM_EVENT_CONNECT_REPLY;
1137 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301138 memcpy(&event.local_addr, &ep->com.local_addr,
1139 sizeof(ep->com.local_addr));
1140 memcpy(&event.remote_addr, &ep->com.remote_addr,
1141 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001142
1143 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301144 if (!ep->tried_with_mpa_v1) {
1145 /* this means MPA_v2 is used */
1146 event.private_data_len = ep->plen -
1147 sizeof(struct mpa_v2_conn_params);
1148 event.private_data = ep->mpa_pkt +
1149 sizeof(struct mpa_message) +
1150 sizeof(struct mpa_v2_conn_params);
1151 } else {
1152 /* this means MPA_v1 is used */
1153 event.private_data_len = ep->plen;
1154 event.private_data = ep->mpa_pkt +
1155 sizeof(struct mpa_message);
1156 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001157 }
Roland Dreier85963e42010-07-19 13:13:09 -07001158
1159 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1160 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001161 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001162 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1163
Steve Wisecfdda9d2010-04-21 15:30:06 -07001164 if (status < 0) {
1165 ep->com.cm_id->rem_ref(ep->com.cm_id);
1166 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001167 }
1168}
1169
Steve Wisebe13b2d2014-03-21 20:40:33 +05301170static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001171{
1172 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301173 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001174
1175 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1176 memset(&event, 0, sizeof(event));
1177 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301178 memcpy(&event.local_addr, &ep->com.local_addr,
1179 sizeof(ep->com.local_addr));
1180 memcpy(&event.remote_addr, &ep->com.remote_addr,
1181 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001182 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301183 if (!ep->tried_with_mpa_v1) {
1184 /* this means MPA_v2 is used */
1185 event.ord = ep->ord;
1186 event.ird = ep->ird;
1187 event.private_data_len = ep->plen -
1188 sizeof(struct mpa_v2_conn_params);
1189 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1190 sizeof(struct mpa_v2_conn_params);
1191 } else {
1192 /* this means MPA_v1 is used. Send max supported */
1193 event.ord = c4iw_max_read_depth;
1194 event.ird = c4iw_max_read_depth;
1195 event.private_data_len = ep->plen;
1196 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1197 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301198 c4iw_get_ep(&ep->com);
1199 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1200 &event);
1201 if (ret)
1202 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001203 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001204 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301205 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001206}
1207
1208static void established_upcall(struct c4iw_ep *ep)
1209{
1210 struct iw_cm_event event;
1211
1212 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1213 memset(&event, 0, sizeof(event));
1214 event.event = IW_CM_EVENT_ESTABLISHED;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301215 event.ird = ep->ird;
1216 event.ord = ep->ord;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001217 if (ep->com.cm_id) {
1218 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1219 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001220 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001221 }
1222}
1223
1224static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1225{
1226 struct cpl_rx_data_ack *req;
1227 struct sk_buff *skb;
1228 int wrlen = roundup(sizeof *req, 16);
1229
1230 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1231 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1232 if (!skb) {
1233 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1234 return 0;
1235 }
1236
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301237 /*
1238 * If we couldn't specify the entire rcv window at connection setup
1239 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1240 * then add the overage in to the credits returned.
1241 */
1242 if (ep->rcv_win > RCV_BUFSIZ_MASK * 1024)
1243 credits += ep->rcv_win - RCV_BUFSIZ_MASK * 1024;
1244
Steve Wisecfdda9d2010-04-21 15:30:06 -07001245 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1246 memset(req, 0, wrlen);
1247 INIT_TP_WR(req, ep->hwtid);
1248 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1249 ep->hwtid));
Steve Wiseba6d3922010-06-23 15:46:49 +00001250 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1251 F_RX_DACK_CHANGE |
1252 V_RX_DACK_MODE(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001253 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001254 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1255 return credits;
1256}
1257
Steve Wisecc18b932014-04-24 14:31:53 -05001258static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001259{
1260 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301261 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001262 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301263 u16 resp_ird, resp_ord;
1264 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001265 struct c4iw_qp_attributes attrs;
1266 enum c4iw_qp_attr_mask mask;
1267 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001268 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001269
1270 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1271
1272 /*
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001273 * Stop mpa timer. If it expired, then
1274 * we ignore the MPA reply. process_timeout()
1275 * will abort the connection.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001276 */
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001277 if (stop_ep_timer(ep))
Steve Wisecc18b932014-04-24 14:31:53 -05001278 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001279
1280 /*
1281 * If we get more than the supported amount of private data
1282 * then we must fail this connection.
1283 */
1284 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1285 err = -EINVAL;
1286 goto err;
1287 }
1288
1289 /*
1290 * copy the new data into our accumulation buffer.
1291 */
1292 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1293 skb->len);
1294 ep->mpa_pkt_len += skb->len;
1295
1296 /*
1297 * if we don't even have the mpa message, then bail.
1298 */
1299 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001300 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001301 mpa = (struct mpa_message *) ep->mpa_pkt;
1302
1303 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301304 if (mpa->revision > mpa_rev) {
1305 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1306 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001307 err = -EPROTO;
1308 goto err;
1309 }
1310 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1311 err = -EPROTO;
1312 goto err;
1313 }
1314
1315 plen = ntohs(mpa->private_data_size);
1316
1317 /*
1318 * Fail if there's too much private data.
1319 */
1320 if (plen > MPA_MAX_PRIVATE_DATA) {
1321 err = -EPROTO;
1322 goto err;
1323 }
1324
1325 /*
1326 * If plen does not account for pkt size
1327 */
1328 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1329 err = -EPROTO;
1330 goto err;
1331 }
1332
1333 ep->plen = (u8) plen;
1334
1335 /*
1336 * If we don't have all the pdata yet, then bail.
1337 * We'll continue process when more data arrives.
1338 */
1339 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001340 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001341
1342 if (mpa->flags & MPA_REJECT) {
1343 err = -ECONNREFUSED;
1344 goto err;
1345 }
1346
1347 /*
1348 * If we get here we have accumulated the entire mpa
1349 * start reply message including private data. And
1350 * the MPA header is valid.
1351 */
Steve Wisec529fb52014-03-21 20:40:37 +05301352 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001353 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1354 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1355 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301356 ep->mpa_attr.version = mpa->revision;
1357 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1358
1359 if (mpa->revision == 2) {
1360 ep->mpa_attr.enhanced_rdma_conn =
1361 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1362 if (ep->mpa_attr.enhanced_rdma_conn) {
1363 mpa_v2_params = (struct mpa_v2_conn_params *)
1364 (ep->mpa_pkt + sizeof(*mpa));
1365 resp_ird = ntohs(mpa_v2_params->ird) &
1366 MPA_V2_IRD_ORD_MASK;
1367 resp_ord = ntohs(mpa_v2_params->ord) &
1368 MPA_V2_IRD_ORD_MASK;
1369
1370 /*
1371 * This is a double-check. Ideally, below checks are
1372 * not required since ird/ord stuff has been taken
1373 * care of in c4iw_accept_cr
1374 */
1375 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1376 err = -ENOMEM;
1377 ep->ird = resp_ord;
1378 ep->ord = resp_ird;
1379 insuff_ird = 1;
1380 }
1381
1382 if (ntohs(mpa_v2_params->ird) &
1383 MPA_V2_PEER2PEER_MODEL) {
1384 if (ntohs(mpa_v2_params->ord) &
1385 MPA_V2_RDMA_WRITE_RTR)
1386 ep->mpa_attr.p2p_type =
1387 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1388 else if (ntohs(mpa_v2_params->ord) &
1389 MPA_V2_RDMA_READ_RTR)
1390 ep->mpa_attr.p2p_type =
1391 FW_RI_INIT_P2PTYPE_READ_REQ;
1392 }
1393 }
1394 } else if (mpa->revision == 1)
1395 if (peer2peer)
1396 ep->mpa_attr.p2p_type = p2p_type;
1397
Steve Wisecfdda9d2010-04-21 15:30:06 -07001398 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301399 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1400 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1401 ep->mpa_attr.recv_marker_enabled,
1402 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1403 ep->mpa_attr.p2p_type, p2p_type);
1404
1405 /*
1406 * If responder's RTR does not match with that of initiator, assign
1407 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1408 * generated when moving QP to RTS state.
1409 * A TERM message will be sent after QP has moved to RTS state
1410 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001411 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301412 (ep->mpa_attr.p2p_type != p2p_type)) {
1413 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1414 rtr_mismatch = 1;
1415 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001416
1417 attrs.mpa_attr = ep->mpa_attr;
1418 attrs.max_ird = ep->ird;
1419 attrs.max_ord = ep->ord;
1420 attrs.llp_stream_handle = ep;
1421 attrs.next_state = C4IW_QP_STATE_RTS;
1422
1423 mask = C4IW_QP_ATTR_NEXT_STATE |
1424 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1425 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1426
1427 /* bind QP and TID with INIT_WR */
1428 err = c4iw_modify_qp(ep->com.qp->rhp,
1429 ep->com.qp, mask, &attrs, 1);
1430 if (err)
1431 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301432
1433 /*
1434 * If responder's RTR requirement did not match with what initiator
1435 * supports, generate TERM message
1436 */
1437 if (rtr_mismatch) {
1438 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1439 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1440 attrs.ecode = MPA_NOMATCH_RTR;
1441 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001442 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301443 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001444 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301445 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001446 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301447 goto out;
1448 }
1449
1450 /*
1451 * Generate TERM if initiator IRD is not sufficient for responder
1452 * provided ORD. Currently, we do the same behaviour even when
1453 * responder provided IRD is also not sufficient as regards to
1454 * initiator ORD.
1455 */
1456 if (insuff_ird) {
1457 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1458 __func__);
1459 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1460 attrs.ecode = MPA_INSUFF_IRD;
1461 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001462 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301463 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001464 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301465 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001466 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301467 goto out;
1468 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001469 goto out;
1470err:
Steve Wisec529fb52014-03-21 20:40:37 +05301471 __state_set(&ep->com, ABORTING);
Steve Wiseb21ef162010-06-10 19:02:55 +00001472 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001473out:
1474 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001475 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001476}
1477
1478static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1479{
1480 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301481 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001482 u16 plen;
1483
1484 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1485
Steve Wisecfdda9d2010-04-21 15:30:06 -07001486 /*
1487 * If we get more than the supported amount of private data
1488 * then we must fail this connection.
1489 */
1490 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001491 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001492 abort_connection(ep, skb, GFP_KERNEL);
1493 return;
1494 }
1495
1496 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1497
1498 /*
1499 * Copy the new data into our accumulation buffer.
1500 */
1501 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1502 skb->len);
1503 ep->mpa_pkt_len += skb->len;
1504
1505 /*
1506 * If we don't even have the mpa message, then bail.
1507 * We'll continue process when more data arrives.
1508 */
1509 if (ep->mpa_pkt_len < sizeof(*mpa))
1510 return;
1511
1512 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001513 mpa = (struct mpa_message *) ep->mpa_pkt;
1514
1515 /*
1516 * Validate MPA Header.
1517 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301518 if (mpa->revision > mpa_rev) {
1519 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1520 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001521 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001522 abort_connection(ep, skb, GFP_KERNEL);
1523 return;
1524 }
1525
1526 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001527 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001528 abort_connection(ep, skb, GFP_KERNEL);
1529 return;
1530 }
1531
1532 plen = ntohs(mpa->private_data_size);
1533
1534 /*
1535 * Fail if there's too much private data.
1536 */
1537 if (plen > MPA_MAX_PRIVATE_DATA) {
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
1543 /*
1544 * If plen does not account for pkt size
1545 */
1546 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001547 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001548 abort_connection(ep, skb, GFP_KERNEL);
1549 return;
1550 }
1551 ep->plen = (u8) plen;
1552
1553 /*
1554 * If we don't have all the pdata yet, then bail.
1555 */
1556 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1557 return;
1558
1559 /*
1560 * If we get here we have accumulated the entire mpa
1561 * start reply message including private data.
1562 */
1563 ep->mpa_attr.initiator = 0;
1564 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1565 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1566 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301567 ep->mpa_attr.version = mpa->revision;
1568 if (mpa->revision == 1)
1569 ep->tried_with_mpa_v1 = 1;
1570 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1571
1572 if (mpa->revision == 2) {
1573 ep->mpa_attr.enhanced_rdma_conn =
1574 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1575 if (ep->mpa_attr.enhanced_rdma_conn) {
1576 mpa_v2_params = (struct mpa_v2_conn_params *)
1577 (ep->mpa_pkt + sizeof(*mpa));
1578 ep->ird = ntohs(mpa_v2_params->ird) &
1579 MPA_V2_IRD_ORD_MASK;
1580 ep->ord = ntohs(mpa_v2_params->ord) &
1581 MPA_V2_IRD_ORD_MASK;
1582 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1583 if (peer2peer) {
1584 if (ntohs(mpa_v2_params->ord) &
1585 MPA_V2_RDMA_WRITE_RTR)
1586 ep->mpa_attr.p2p_type =
1587 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1588 else if (ntohs(mpa_v2_params->ord) &
1589 MPA_V2_RDMA_READ_RTR)
1590 ep->mpa_attr.p2p_type =
1591 FW_RI_INIT_P2PTYPE_READ_REQ;
1592 }
1593 }
1594 } else if (mpa->revision == 1)
1595 if (peer2peer)
1596 ep->mpa_attr.p2p_type = p2p_type;
1597
Steve Wisecfdda9d2010-04-21 15:30:06 -07001598 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1599 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1600 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1601 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1602 ep->mpa_attr.p2p_type);
1603
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001604 /*
1605 * If the endpoint timer already expired, then we ignore
1606 * the start request. process_timeout() will abort
1607 * the connection.
1608 */
1609 if (!stop_ep_timer(ep)) {
1610 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001611
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001612 /* drive upcall */
1613 mutex_lock(&ep->parent_ep->com.mutex);
1614 if (ep->parent_ep->com.state != DEAD) {
1615 if (connect_request_upcall(ep))
1616 abort_connection(ep, skb, GFP_KERNEL);
1617 } else {
Steve Wisebe13b2d2014-03-21 20:40:33 +05301618 abort_connection(ep, skb, GFP_KERNEL);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001619 }
1620 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301621 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001622 return;
1623}
1624
1625static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1626{
1627 struct c4iw_ep *ep;
1628 struct cpl_rx_data *hdr = cplhdr(skb);
1629 unsigned int dlen = ntohs(hdr->len);
1630 unsigned int tid = GET_TID(hdr);
1631 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001632 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001633 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001634
1635 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301636 if (!ep)
1637 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001638 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1639 skb_pull(skb, sizeof(*hdr));
1640 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301641 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001642
Steve Wisecfdda9d2010-04-21 15:30:06 -07001643 /* update RX credits */
1644 update_rx_credits(ep, dlen);
1645
Steve Wisec529fb52014-03-21 20:40:37 +05301646 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001647 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001648 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001649 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001650 break;
1651 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001652 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001653 process_mpa_request(ep, skb);
1654 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001655 case FPDU_MODE: {
1656 struct c4iw_qp_attributes attrs;
1657 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001658 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001659 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001660 " qpid %u ep %p state %d tid %u status %d\n",
1661 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301662 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301663 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001664 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001665 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1666 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001667 break;
1668 }
Vipul Pandya15579672013-01-07 13:11:52 +00001669 default:
1670 break;
1671 }
Steve Wisec529fb52014-03-21 20:40:37 +05301672 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001673 if (disconnect)
1674 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001675 return 0;
1676}
1677
1678static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1679{
1680 struct c4iw_ep *ep;
1681 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001682 int release = 0;
1683 unsigned int tid = GET_TID(rpl);
1684 struct tid_info *t = dev->rdev.lldi.tids;
1685
1686 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301687 if (!ep) {
1688 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1689 return 0;
1690 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001691 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001692 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001693 switch (ep->com.state) {
1694 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001695 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001696 __state_set(&ep->com, DEAD);
1697 release = 1;
1698 break;
1699 default:
1700 printk(KERN_ERR "%s ep %p state %d\n",
1701 __func__, ep, ep->com.state);
1702 break;
1703 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001704 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001705
1706 if (release)
1707 release_ep_resources(ep);
1708 return 0;
1709}
1710
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001711static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1712{
1713 struct sk_buff *skb;
1714 struct fw_ofld_connection_wr *req;
1715 unsigned int mtu_idx;
1716 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301717 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301718 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001719
1720 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1721 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1722 memset(req, 0, sizeof(*req));
1723 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1724 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301725 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1726 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001727 ep->l2t));
Steve Wise9eccfe12014-03-26 17:08:09 -05001728 sin = (struct sockaddr_in *)&ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301729 req->le.lport = sin->sin_port;
1730 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05001731 sin = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301732 req->le.pport = sin->sin_port;
1733 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001734 req->tcb.t_state_to_astid =
1735 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1736 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1737 req->tcb.cplrxdataack_cplpassacceptrpl =
1738 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001739 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001740 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301741 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
1742 enable_tcp_timestamps);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001743 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301744
1745 /*
1746 * Specify the largest window that will fit in opt0. The
1747 * remainder will be specified in the rx_data_ack.
1748 */
1749 win = ep->rcv_win >> 10;
1750 if (win > RCV_BUFSIZ_MASK)
1751 win = RCV_BUFSIZ_MASK;
1752
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001753 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001754 (nocong ? NO_CONG(1) : 0) |
1755 KEEP_ALIVE(1) |
1756 DELACK(1) |
1757 WND_SCALE(wscale) |
1758 MSS_IDX(mtu_idx) |
1759 L2T_IDX(ep->l2t->idx) |
1760 TX_CHAN(ep->tx_chan) |
1761 SMAC_SEL(ep->smac_idx) |
1762 DSCP(ep->tos) |
1763 ULP_MODE(ULP_MODE_TCPDDP) |
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301764 RCV_BUFSIZ(win));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001765 req->tcb.opt2 = (__force __be32) (PACE(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001766 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1767 RX_CHANNEL(0) |
1768 CCTRL_ECN(enable_ecn) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001769 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001770 if (enable_tcp_timestamps)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001771 req->tcb.opt2 |= (__force __be32) TSTAMPS_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001772 if (enable_tcp_sack)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001773 req->tcb.opt2 |= (__force __be32) SACK_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001774 if (wscale && enable_tcp_window_scaling)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001775 req->tcb.opt2 |= (__force __be32) WND_SCALE_EN(1);
1776 req->tcb.opt0 = cpu_to_be64((__force u64) req->tcb.opt0);
1777 req->tcb.opt2 = cpu_to_be32((__force u32) req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001778 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1779 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001780 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1781}
1782
Steve Wisecfdda9d2010-04-21 15:30:06 -07001783/*
1784 * Return whether a failed active open has allocated a TID
1785 */
1786static inline int act_open_has_tid(int status)
1787{
1788 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1789 status != CPL_ERR_ARP_MISS;
1790}
1791
Steve Wise7a2cea22014-03-14 21:52:07 +05301792/* Returns whether a CPL status conveys negative advice.
1793 */
1794static int is_neg_adv(unsigned int status)
1795{
1796 return status == CPL_ERR_RTX_NEG_ADVICE ||
1797 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1798 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1799}
1800
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301801static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1802{
1803 ep->snd_win = snd_win;
1804 ep->rcv_win = rcv_win;
1805 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1806}
1807
Vipul Pandya793dad92012-12-10 09:30:56 +00001808#define ACT_OPEN_RETRY_COUNT 2
1809
Vipul Pandya830662f2013-07-04 16:10:47 +05301810static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1811 struct dst_entry *dst, struct c4iw_dev *cdev,
1812 bool clear_mpa_v1)
1813{
1814 struct neighbour *n;
1815 int err, step;
1816 struct net_device *pdev;
1817
1818 n = dst_neigh_lookup(dst, peer_ip);
1819 if (!n)
1820 return -ENODEV;
1821
1822 rcu_read_lock();
1823 err = -ENOMEM;
1824 if (n->dev->flags & IFF_LOOPBACK) {
1825 if (iptype == 4)
1826 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1827 else if (IS_ENABLED(CONFIG_IPV6))
1828 for_each_netdev(&init_net, pdev) {
1829 if (ipv6_chk_addr(&init_net,
1830 (struct in6_addr *)peer_ip,
1831 pdev, 1))
1832 break;
1833 }
1834 else
1835 pdev = NULL;
1836
1837 if (!pdev) {
1838 err = -ENODEV;
1839 goto out;
1840 }
1841 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1842 n, pdev, 0);
1843 if (!ep->l2t)
1844 goto out;
1845 ep->mtu = pdev->mtu;
1846 ep->tx_chan = cxgb4_port_chan(pdev);
1847 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1848 step = cdev->rdev.lldi.ntxq /
1849 cdev->rdev.lldi.nchan;
1850 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1851 step = cdev->rdev.lldi.nrxq /
1852 cdev->rdev.lldi.nchan;
1853 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1854 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1855 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301856 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301857 dev_put(pdev);
1858 } else {
1859 pdev = get_real_dev(n->dev);
1860 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1861 n, pdev, 0);
1862 if (!ep->l2t)
1863 goto out;
1864 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05001865 ep->tx_chan = cxgb4_port_chan(pdev);
1866 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
Vipul Pandya830662f2013-07-04 16:10:47 +05301867 step = cdev->rdev.lldi.ntxq /
1868 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05001869 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1870 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05301871 step = cdev->rdev.lldi.nrxq /
1872 cdev->rdev.lldi.nchan;
1873 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05001874 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301875 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301876
1877 if (clear_mpa_v1) {
1878 ep->retry_with_mpa_v1 = 0;
1879 ep->tried_with_mpa_v1 = 0;
1880 }
1881 }
1882 err = 0;
1883out:
1884 rcu_read_unlock();
1885
1886 neigh_release(n);
1887
1888 return err;
1889}
1890
Vipul Pandya793dad92012-12-10 09:30:56 +00001891static int c4iw_reconnect(struct c4iw_ep *ep)
1892{
1893 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05301894 struct sockaddr_in *laddr = (struct sockaddr_in *)
1895 &ep->com.cm_id->local_addr;
1896 struct sockaddr_in *raddr = (struct sockaddr_in *)
1897 &ep->com.cm_id->remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301898 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
1899 &ep->com.cm_id->local_addr;
1900 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
1901 &ep->com.cm_id->remote_addr;
1902 int iptype;
1903 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00001904
1905 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1906 init_timer(&ep->timer);
1907
1908 /*
1909 * Allocate an active TID to initiate a TCP connection.
1910 */
1911 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1912 if (ep->atid == -1) {
1913 pr_err("%s - cannot alloc atid.\n", __func__);
1914 err = -ENOMEM;
1915 goto fail2;
1916 }
1917 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1918
1919 /* find a route */
Vipul Pandya830662f2013-07-04 16:10:47 +05301920 if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
1921 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
1922 raddr->sin_addr.s_addr, laddr->sin_port,
1923 raddr->sin_port, 0);
1924 iptype = 4;
1925 ra = (__u8 *)&raddr->sin_addr;
1926 } else {
1927 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
1928 raddr6->sin6_addr.s6_addr,
1929 laddr6->sin6_port, raddr6->sin6_port, 0,
1930 raddr6->sin6_scope_id);
1931 iptype = 6;
1932 ra = (__u8 *)&raddr6->sin6_addr;
1933 }
1934 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001935 pr_err("%s - cannot find route.\n", __func__);
1936 err = -EHOSTUNREACH;
1937 goto fail3;
1938 }
Vipul Pandya830662f2013-07-04 16:10:47 +05301939 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false);
1940 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001941 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00001942 goto fail4;
1943 }
1944
1945 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1946 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1947 ep->l2t->idx);
1948
1949 state_set(&ep->com, CONNECTING);
1950 ep->tos = 0;
1951
1952 /* send connect request to rnic */
1953 err = send_connect(ep);
1954 if (!err)
1955 goto out;
1956
1957 cxgb4_l2t_release(ep->l2t);
1958fail4:
1959 dst_release(ep->dst);
1960fail3:
1961 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1962 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1963fail2:
1964 /*
1965 * remember to send notification to upper layer.
1966 * We are in here so the upper layer is not aware that this is
1967 * re-connect attempt and so, upper layer is still waiting for
1968 * response of 1st connect request.
1969 */
1970 connect_reply_upcall(ep, -ECONNRESET);
1971 c4iw_put_ep(&ep->com);
1972out:
1973 return err;
1974}
1975
Steve Wisecfdda9d2010-04-21 15:30:06 -07001976static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1977{
1978 struct c4iw_ep *ep;
1979 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1980 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1981 ntohl(rpl->atid_status)));
1982 struct tid_info *t = dev->rdev.lldi.tids;
1983 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05301984 struct sockaddr_in *la;
1985 struct sockaddr_in *ra;
1986 struct sockaddr_in6 *la6;
1987 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001988
1989 ep = lookup_atid(t, atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05001990 la = (struct sockaddr_in *)&ep->com.mapped_local_addr;
1991 ra = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
1992 la6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
1993 ra6 = (struct sockaddr_in6 *)&ep->com.mapped_remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001994
1995 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1996 status, status2errno(status));
1997
Steve Wise7a2cea22014-03-14 21:52:07 +05301998 if (is_neg_adv(status)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001999 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
2000 atid);
2001 return 0;
2002 }
2003
Vipul Pandya793dad92012-12-10 09:30:56 +00002004 set_bit(ACT_OPEN_RPL, &ep->com.history);
2005
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302006 /*
2007 * Log interesting failures.
2008 */
2009 switch (status) {
2010 case CPL_ERR_CONN_RESET:
2011 case CPL_ERR_CONN_TIMEDOUT:
2012 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002013 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302014 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002015 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302016 mutex_unlock(&dev->rdev.stats.lock);
2017 if (ep->com.local_addr.ss_family == AF_INET &&
2018 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002019 send_fw_act_open_req(ep,
2020 GET_TID_TID(GET_AOPEN_ATID(
2021 ntohl(rpl->atid_status))));
2022 return 0;
2023 }
2024 break;
2025 case CPL_ERR_CONN_EXIST:
2026 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2027 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2028 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2029 atid);
2030 cxgb4_free_atid(t, atid);
2031 dst_release(ep->dst);
2032 cxgb4_l2t_release(ep->l2t);
2033 c4iw_reconnect(ep);
2034 return 0;
2035 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002036 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302037 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302038 if (ep->com.local_addr.ss_family == AF_INET) {
2039 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2040 atid, status, status2errno(status),
2041 &la->sin_addr.s_addr, ntohs(la->sin_port),
2042 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2043 } else {
2044 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2045 atid, status, status2errno(status),
2046 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2047 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2048 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302049 break;
2050 }
2051
Steve Wisecfdda9d2010-04-21 15:30:06 -07002052 connect_reply_upcall(ep, status2errno(status));
2053 state_set(&ep->com, DEAD);
2054
2055 if (status && act_open_has_tid(status))
2056 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2057
Vipul Pandya793dad92012-12-10 09:30:56 +00002058 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002059 cxgb4_free_atid(t, atid);
2060 dst_release(ep->dst);
2061 cxgb4_l2t_release(ep->l2t);
2062 c4iw_put_ep(&ep->com);
2063
2064 return 0;
2065}
2066
2067static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2068{
2069 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2070 struct tid_info *t = dev->rdev.lldi.tids;
2071 unsigned int stid = GET_TID(rpl);
2072 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2073
2074 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002075 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2076 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002077 }
2078 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2079 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002080 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002081
Vipul Pandya1cab7752012-12-10 09:30:55 +00002082out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002083 return 0;
2084}
2085
Steve Wisecfdda9d2010-04-21 15:30:06 -07002086static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2087{
2088 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2089 struct tid_info *t = dev->rdev.lldi.tids;
2090 unsigned int stid = GET_TID(rpl);
2091 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2092
2093 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002094 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002095 return 0;
2096}
2097
Vipul Pandya830662f2013-07-04 16:10:47 +05302098static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002099 struct cpl_pass_accept_req *req)
2100{
2101 struct cpl_pass_accept_rpl *rpl;
2102 unsigned int mtu_idx;
2103 u64 opt0;
2104 u32 opt2;
2105 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302106 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302107 int win;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002108
2109 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2110 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302111
Steve Wisecfdda9d2010-04-21 15:30:06 -07002112 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302113 rpl = cplhdr(skb);
2114 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
2115 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2116 rpl5 = (void *)rpl;
2117 INIT_TP_WR(rpl5, ep->hwtid);
2118 } else {
2119 skb_trim(skb, sizeof(*rpl));
2120 INIT_TP_WR(rpl, ep->hwtid);
2121 }
2122 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2123 ep->hwtid));
2124
2125 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
2126 enable_tcp_timestamps && req->tcpopt.tstamp);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002127 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302128
2129 /*
2130 * Specify the largest window that will fit in opt0. The
2131 * remainder will be specified in the rx_data_ack.
2132 */
2133 win = ep->rcv_win >> 10;
2134 if (win > RCV_BUFSIZ_MASK)
2135 win = RCV_BUFSIZ_MASK;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002136 opt0 = (nocong ? NO_CONG(1) : 0) |
2137 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +00002138 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07002139 WND_SCALE(wscale) |
2140 MSS_IDX(mtu_idx) |
2141 L2T_IDX(ep->l2t->idx) |
2142 TX_CHAN(ep->tx_chan) |
2143 SMAC_SEL(ep->smac_idx) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002144 DSCP(ep->tos >> 2) |
Steve Wiseb48f3b92011-03-11 22:30:21 +00002145 ULP_MODE(ULP_MODE_TCPDDP) |
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302146 RCV_BUFSIZ(win);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002147 opt2 = RX_CHANNEL(0) |
2148 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
2149
2150 if (enable_tcp_timestamps && req->tcpopt.tstamp)
2151 opt2 |= TSTAMPS_EN(1);
2152 if (enable_tcp_sack && req->tcpopt.sack)
2153 opt2 |= SACK_EN(1);
2154 if (wscale && enable_tcp_window_scaling)
2155 opt2 |= WND_SCALE_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002156 if (enable_ecn) {
2157 const struct tcphdr *tcph;
2158 u32 hlen = ntohl(req->hdr_len);
2159
2160 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
2161 G_IP_HDR_LEN(hlen);
2162 if (tcph->ece && tcph->cwr)
2163 opt2 |= CCTRL_ECN(1);
2164 }
Steve Wise92e50112014-04-24 14:31:59 -05002165 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302166 u32 isn = (prandom_u32() & ~7UL) - 1;
Steve Wise92e50112014-04-24 14:31:59 -05002167 opt2 |= T5_OPT_2_VALID;
2168 opt2 |= V_CONG_CNTRL(CONG_ALG_TAHOE);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302169 opt2 |= CONG_CNTRL_VALID; /* OPT_2_ISS for T5 */
2170 rpl5 = (void *)rpl;
2171 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2172 if (peer2peer)
2173 isn += 4;
2174 rpl5->iss = cpu_to_be32(isn);
2175 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002176 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002177
Steve Wisecfdda9d2010-04-21 15:30:06 -07002178 rpl->opt0 = cpu_to_be64(opt0);
2179 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002180 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wiseb38a0ad2013-08-06 21:04:37 +05302181 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002182 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2183
2184 return;
2185}
2186
Vipul Pandya830662f2013-07-04 16:10:47 +05302187static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002188{
Vipul Pandya830662f2013-07-04 16:10:47 +05302189 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002190 BUG_ON(skb_cloned(skb));
2191 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002192 release_tid(&dev->rdev, hwtid, skb);
2193 return;
2194}
2195
Vipul Pandya830662f2013-07-04 16:10:47 +05302196static void get_4tuple(struct cpl_pass_accept_req *req, int *iptype,
2197 __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002198 __be16 *local_port, __be16 *peer_port)
2199{
2200 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
2201 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
2202 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302203 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002204 struct tcphdr *tcp = (struct tcphdr *)
2205 ((u8 *)(req + 1) + eth_len + ip_len);
2206
Vipul Pandya830662f2013-07-04 16:10:47 +05302207 if (ip->version == 4) {
2208 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2209 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2210 ntohs(tcp->dest));
2211 *iptype = 4;
2212 memcpy(peer_ip, &ip->saddr, 4);
2213 memcpy(local_ip, &ip->daddr, 4);
2214 } else {
2215 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2216 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2217 ntohs(tcp->dest));
2218 *iptype = 6;
2219 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2220 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2221 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002222 *peer_port = tcp->source;
2223 *local_port = tcp->dest;
2224
2225 return;
2226}
2227
2228static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2229{
Vipul Pandya793dad92012-12-10 09:30:56 +00002230 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002231 struct cpl_pass_accept_req *req = cplhdr(skb);
2232 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
2233 struct tid_info *t = dev->rdev.lldi.tids;
2234 unsigned int hwtid = GET_TID(req);
2235 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302236 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002237 __be16 local_port, peer_port;
David Miller3786cf12011-12-02 16:52:31 +00002238 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002239 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302240 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302241 unsigned short hdrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002242
2243 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002244 if (!parent_ep) {
2245 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2246 goto reject;
2247 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002248
Steve Wisecfdda9d2010-04-21 15:30:06 -07002249 if (state_read(&parent_ep->com) != LISTEN) {
2250 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
2251 __func__);
2252 goto reject;
2253 }
2254
Vipul Pandya830662f2013-07-04 16:10:47 +05302255 get_4tuple(req, &iptype, local_ip, peer_ip, &local_port, &peer_port);
2256
Steve Wisecfdda9d2010-04-21 15:30:06 -07002257 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302258 if (iptype == 4) {
2259 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 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_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2264 local_port, peer_port,
2265 GET_POPEN_TOS(ntohl(req->tos_stid)));
2266 } else {
2267 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2268 , __func__, parent_ep, hwtid,
2269 local_ip, peer_ip, ntohs(local_port),
2270 ntohs(peer_port), peer_mss);
2271 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
2272 PASS_OPEN_TOS(ntohl(req->tos_stid)),
2273 ((struct sockaddr_in6 *)
2274 &parent_ep->com.local_addr)->sin6_scope_id);
2275 }
2276 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002277 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2278 __func__);
2279 goto reject;
2280 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002281
2282 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2283 if (!child_ep) {
2284 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2285 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002286 dst_release(dst);
2287 goto reject;
2288 }
David Miller3786cf12011-12-02 16:52:31 +00002289
Vipul Pandya830662f2013-07-04 16:10:47 +05302290 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false);
David Miller3786cf12011-12-02 16:52:31 +00002291 if (err) {
2292 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2293 __func__);
2294 dst_release(dst);
2295 kfree(child_ep);
2296 goto reject;
2297 }
2298
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302299 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2300 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2301 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2302 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002303
Steve Wisecfdda9d2010-04-21 15:30:06 -07002304 state_set(&child_ep->com, CONNECTING);
2305 child_ep->com.dev = dev;
2306 child_ep->com.cm_id = NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +05302307 if (iptype == 4) {
2308 struct sockaddr_in *sin = (struct sockaddr_in *)
2309 &child_ep->com.local_addr;
2310 sin->sin_family = PF_INET;
2311 sin->sin_port = local_port;
2312 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2313 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
2314 sin->sin_family = PF_INET;
2315 sin->sin_port = peer_port;
2316 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2317 } else {
2318 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
2319 &child_ep->com.local_addr;
2320 sin6->sin6_family = PF_INET6;
2321 sin6->sin6_port = local_port;
2322 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2323 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
2324 sin6->sin6_family = PF_INET6;
2325 sin6->sin6_port = peer_port;
2326 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2327 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002328 c4iw_get_ep(&parent_ep->com);
2329 child_ep->parent_ep = parent_ep;
2330 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002331 child_ep->dst = dst;
2332 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002333
2334 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002335 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002336
2337 init_timer(&child_ep->timer);
2338 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002339 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Vipul Pandya830662f2013-07-04 16:10:47 +05302340 accept_cr(child_ep, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00002341 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002342 goto out;
2343reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302344 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002345out:
2346 return 0;
2347}
2348
2349static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2350{
2351 struct c4iw_ep *ep;
2352 struct cpl_pass_establish *req = cplhdr(skb);
2353 struct tid_info *t = dev->rdev.lldi.tids;
2354 unsigned int tid = GET_TID(req);
2355
2356 ep = lookup_tid(t, tid);
2357 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2358 ep->snd_seq = be32_to_cpu(req->snd_isn);
2359 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2360
Vipul Pandya1cab7752012-12-10 09:30:55 +00002361 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2362 ntohs(req->tcp_opt));
2363
Steve Wisecfdda9d2010-04-21 15:30:06 -07002364 set_emss(ep, ntohs(req->tcp_opt));
2365
2366 dst_confirm(ep->dst);
2367 state_set(&ep->com, MPA_REQ_WAIT);
2368 start_ep_timer(ep);
2369 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002370 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002371
2372 return 0;
2373}
2374
2375static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2376{
2377 struct cpl_peer_close *hdr = cplhdr(skb);
2378 struct c4iw_ep *ep;
2379 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002380 int disconnect = 1;
2381 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002382 struct tid_info *t = dev->rdev.lldi.tids;
2383 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002384 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002385
2386 ep = lookup_tid(t, tid);
2387 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2388 dst_confirm(ep->dst);
2389
Vipul Pandya793dad92012-12-10 09:30:56 +00002390 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002391 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002392 switch (ep->com.state) {
2393 case MPA_REQ_WAIT:
2394 __state_set(&ep->com, CLOSING);
2395 break;
2396 case MPA_REQ_SENT:
2397 __state_set(&ep->com, CLOSING);
2398 connect_reply_upcall(ep, -ECONNRESET);
2399 break;
2400 case MPA_REQ_RCVD:
2401
2402 /*
2403 * We're gonna mark this puppy DEAD, but keep
2404 * the reference on it until the ULP accepts or
2405 * rejects the CR. Also wake up anyone waiting
2406 * in rdma connection migration (see c4iw_accept_cr()).
2407 */
2408 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002409 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002410 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002411 break;
2412 case MPA_REP_SENT:
2413 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002414 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002415 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002416 break;
2417 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002418 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002419 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002420 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002421 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002422 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002423 if (ret != -ECONNRESET) {
2424 peer_close_upcall(ep);
2425 disconnect = 1;
2426 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002427 break;
2428 case ABORTING:
2429 disconnect = 0;
2430 break;
2431 case CLOSING:
2432 __state_set(&ep->com, MORIBUND);
2433 disconnect = 0;
2434 break;
2435 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002436 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002437 if (ep->com.cm_id && ep->com.qp) {
2438 attrs.next_state = C4IW_QP_STATE_IDLE;
2439 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2440 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2441 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302442 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002443 __state_set(&ep->com, DEAD);
2444 release = 1;
2445 disconnect = 0;
2446 break;
2447 case DEAD:
2448 disconnect = 0;
2449 break;
2450 default:
2451 BUG_ON(1);
2452 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002453 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002454 if (disconnect)
2455 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2456 if (release)
2457 release_ep_resources(ep);
2458 return 0;
2459}
2460
Steve Wisecfdda9d2010-04-21 15:30:06 -07002461static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2462{
2463 struct cpl_abort_req_rss *req = cplhdr(skb);
2464 struct c4iw_ep *ep;
2465 struct cpl_abort_rpl *rpl;
2466 struct sk_buff *rpl_skb;
2467 struct c4iw_qp_attributes attrs;
2468 int ret;
2469 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002470 struct tid_info *t = dev->rdev.lldi.tids;
2471 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002472
2473 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302474 if (is_neg_adv(req->status)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002475 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2476 ep->hwtid);
2477 return 0;
2478 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002479 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2480 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002481 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002482
2483 /*
2484 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302485 * However, this is not needed if com state is just
2486 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002487 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302488 if (ep->com.state != MPA_REQ_SENT)
2489 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002490
2491 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002492 switch (ep->com.state) {
2493 case CONNECTING:
2494 break;
2495 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002496 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002497 break;
2498 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002499 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002500 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302501 connect_reply_upcall(ep, -ECONNRESET);
2502 else {
2503 /*
2504 * we just don't send notification upwards because we
2505 * want to retry with mpa_v1 without upper layers even
2506 * knowing it.
2507 *
2508 * do some housekeeping so as to re-initiate the
2509 * connection
2510 */
2511 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2512 mpa_rev);
2513 ep->retry_with_mpa_v1 = 1;
2514 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002515 break;
2516 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002517 break;
2518 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002519 break;
2520 case MORIBUND:
2521 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002522 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002523 /*FALLTHROUGH*/
2524 case FPDU_MODE:
2525 if (ep->com.cm_id && ep->com.qp) {
2526 attrs.next_state = C4IW_QP_STATE_ERROR;
2527 ret = c4iw_modify_qp(ep->com.qp->rhp,
2528 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2529 &attrs, 1);
2530 if (ret)
2531 printk(KERN_ERR MOD
2532 "%s - qp <- error failed!\n",
2533 __func__);
2534 }
2535 peer_abort_upcall(ep);
2536 break;
2537 case ABORTING:
2538 break;
2539 case DEAD:
2540 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002541 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002542 return 0;
2543 default:
2544 BUG_ON(1);
2545 break;
2546 }
2547 dst_confirm(ep->dst);
2548 if (ep->com.state != ABORTING) {
2549 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302550 /* we don't release if we want to retry with mpa_v1 */
2551 if (!ep->retry_with_mpa_v1)
2552 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002553 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002554 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002555
2556 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2557 if (!rpl_skb) {
2558 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2559 __func__);
2560 release = 1;
2561 goto out;
2562 }
2563 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2564 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2565 INIT_TP_WR(rpl, ep->hwtid);
2566 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2567 rpl->cmd = CPL_ABORT_NO_RST;
2568 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2569out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002570 if (release)
2571 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002572 else if (ep->retry_with_mpa_v1) {
2573 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302574 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2575 dst_release(ep->dst);
2576 cxgb4_l2t_release(ep->l2t);
2577 c4iw_reconnect(ep);
2578 }
2579
Steve Wisecfdda9d2010-04-21 15:30:06 -07002580 return 0;
2581}
2582
2583static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2584{
2585 struct c4iw_ep *ep;
2586 struct c4iw_qp_attributes attrs;
2587 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002588 int release = 0;
2589 struct tid_info *t = dev->rdev.lldi.tids;
2590 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002591
2592 ep = lookup_tid(t, tid);
2593
2594 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2595 BUG_ON(!ep);
2596
2597 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002598 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002599 switch (ep->com.state) {
2600 case CLOSING:
2601 __state_set(&ep->com, MORIBUND);
2602 break;
2603 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002604 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002605 if ((ep->com.cm_id) && (ep->com.qp)) {
2606 attrs.next_state = C4IW_QP_STATE_IDLE;
2607 c4iw_modify_qp(ep->com.qp->rhp,
2608 ep->com.qp,
2609 C4IW_QP_ATTR_NEXT_STATE,
2610 &attrs, 1);
2611 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302612 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002613 __state_set(&ep->com, DEAD);
2614 release = 1;
2615 break;
2616 case ABORTING:
2617 case DEAD:
2618 break;
2619 default:
2620 BUG_ON(1);
2621 break;
2622 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002623 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002624 if (release)
2625 release_ep_resources(ep);
2626 return 0;
2627}
2628
2629static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2630{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002631 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002632 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002633 unsigned int tid = GET_TID(rpl);
2634 struct c4iw_ep *ep;
2635 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002636
2637 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002638 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002639
Steve Wise30c95c22011-05-09 22:06:22 -07002640 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002641 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2642 ep->com.qp->wq.sq.qid);
2643 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2644 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2645 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2646 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002647 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002648
Steve Wisecfdda9d2010-04-21 15:30:06 -07002649 return 0;
2650}
2651
2652/*
2653 * Upcall from the adapter indicating data has been transmitted.
2654 * For us its just the single MPA request or reply. We can now free
2655 * the skb holding the mpa message.
2656 */
2657static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2658{
2659 struct c4iw_ep *ep;
2660 struct cpl_fw4_ack *hdr = cplhdr(skb);
2661 u8 credits = hdr->credits;
2662 unsigned int tid = GET_TID(hdr);
2663 struct tid_info *t = dev->rdev.lldi.tids;
2664
2665
2666 ep = lookup_tid(t, tid);
2667 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2668 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002669 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2670 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002671 return 0;
2672 }
2673
2674 dst_confirm(ep->dst);
2675 if (ep->mpa_skb) {
2676 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2677 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2678 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2679 kfree_skb(ep->mpa_skb);
2680 ep->mpa_skb = NULL;
2681 }
2682 return 0;
2683}
2684
Steve Wisecfdda9d2010-04-21 15:30:06 -07002685int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2686{
Steve Wisea7db89e2014-03-21 20:40:35 +05302687 int err = 0;
2688 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002689 struct c4iw_ep *ep = to_ep(cm_id);
2690 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2691
Steve Wisea7db89e2014-03-21 20:40:35 +05302692 mutex_lock(&ep->com.mutex);
2693 if (ep->com.state == DEAD) {
2694 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002695 c4iw_put_ep(&ep->com);
2696 return -ECONNRESET;
2697 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002698 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302699 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002700 if (mpa_rev == 0)
2701 abort_connection(ep, NULL, GFP_KERNEL);
2702 else {
2703 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302704 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002705 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302706 mutex_unlock(&ep->com.mutex);
2707 if (disconnect)
2708 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002709 c4iw_put_ep(&ep->com);
2710 return 0;
2711}
2712
2713int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2714{
2715 int err;
2716 struct c4iw_qp_attributes attrs;
2717 enum c4iw_qp_attr_mask mask;
2718 struct c4iw_ep *ep = to_ep(cm_id);
2719 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2720 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2721
2722 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302723
2724 mutex_lock(&ep->com.mutex);
2725 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002726 err = -ECONNRESET;
2727 goto err;
2728 }
2729
Steve Wisea7db89e2014-03-21 20:40:35 +05302730 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002731 BUG_ON(!qp);
2732
Vipul Pandya793dad92012-12-10 09:30:56 +00002733 set_bit(ULP_ACCEPT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002734 if ((conn_param->ord > c4iw_max_read_depth) ||
2735 (conn_param->ird > c4iw_max_read_depth)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002736 abort_connection(ep, NULL, GFP_KERNEL);
2737 err = -EINVAL;
2738 goto err;
2739 }
2740
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302741 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2742 if (conn_param->ord > ep->ird) {
2743 ep->ird = conn_param->ird;
2744 ep->ord = conn_param->ord;
2745 send_mpa_reject(ep, conn_param->private_data,
2746 conn_param->private_data_len);
2747 abort_connection(ep, NULL, GFP_KERNEL);
2748 err = -ENOMEM;
2749 goto err;
2750 }
2751 if (conn_param->ird > ep->ord) {
2752 if (!ep->ord)
2753 conn_param->ird = 1;
2754 else {
2755 abort_connection(ep, NULL, GFP_KERNEL);
2756 err = -ENOMEM;
2757 goto err;
2758 }
2759 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002760
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302761 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002762 ep->ird = conn_param->ird;
2763 ep->ord = conn_param->ord;
2764
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302765 if (ep->mpa_attr.version != 2)
2766 if (peer2peer && ep->ird == 0)
2767 ep->ird = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002768
2769 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2770
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302771 cm_id->add_ref(cm_id);
2772 ep->com.cm_id = cm_id;
2773 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00002774 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302775
Steve Wisecfdda9d2010-04-21 15:30:06 -07002776 /* bind QP to EP and move to RTS */
2777 attrs.mpa_attr = ep->mpa_attr;
2778 attrs.max_ird = ep->ird;
2779 attrs.max_ord = ep->ord;
2780 attrs.llp_stream_handle = ep;
2781 attrs.next_state = C4IW_QP_STATE_RTS;
2782
2783 /* bind QP and TID with INIT_WR */
2784 mask = C4IW_QP_ATTR_NEXT_STATE |
2785 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2786 C4IW_QP_ATTR_MPA_ATTR |
2787 C4IW_QP_ATTR_MAX_IRD |
2788 C4IW_QP_ATTR_MAX_ORD;
2789
2790 err = c4iw_modify_qp(ep->com.qp->rhp,
2791 ep->com.qp, mask, &attrs, 1);
2792 if (err)
2793 goto err1;
2794 err = send_mpa_reply(ep, conn_param->private_data,
2795 conn_param->private_data_len);
2796 if (err)
2797 goto err1;
2798
Steve Wisea7db89e2014-03-21 20:40:35 +05302799 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002800 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05302801 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002802 c4iw_put_ep(&ep->com);
2803 return 0;
2804err1:
2805 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002806 cm_id->rem_ref(cm_id);
2807err:
Steve Wisea7db89e2014-03-21 20:40:35 +05302808 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002809 c4iw_put_ep(&ep->com);
2810 return err;
2811}
2812
Vipul Pandya830662f2013-07-04 16:10:47 +05302813static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2814{
2815 struct in_device *ind;
2816 int found = 0;
2817 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2818 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
2819
2820 ind = in_dev_get(dev->rdev.lldi.ports[0]);
2821 if (!ind)
2822 return -EADDRNOTAVAIL;
2823 for_primary_ifa(ind) {
2824 laddr->sin_addr.s_addr = ifa->ifa_address;
2825 raddr->sin_addr.s_addr = ifa->ifa_address;
2826 found = 1;
2827 break;
2828 }
2829 endfor_ifa(ind);
2830 in_dev_put(ind);
2831 return found ? 0 : -EADDRNOTAVAIL;
2832}
2833
2834static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
2835 unsigned char banned_flags)
2836{
2837 struct inet6_dev *idev;
2838 int err = -EADDRNOTAVAIL;
2839
2840 rcu_read_lock();
2841 idev = __in6_dev_get(dev);
2842 if (idev != NULL) {
2843 struct inet6_ifaddr *ifp;
2844
2845 read_lock_bh(&idev->lock);
2846 list_for_each_entry(ifp, &idev->addr_list, if_list) {
2847 if (ifp->scope == IFA_LINK &&
2848 !(ifp->flags & banned_flags)) {
2849 memcpy(addr, &ifp->addr, 16);
2850 err = 0;
2851 break;
2852 }
2853 }
2854 read_unlock_bh(&idev->lock);
2855 }
2856 rcu_read_unlock();
2857 return err;
2858}
2859
2860static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2861{
2862 struct in6_addr uninitialized_var(addr);
2863 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2864 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
2865
2866 if (get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
2867 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
2868 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
2869 return 0;
2870 }
2871 return -EADDRNOTAVAIL;
2872}
2873
Steve Wisecfdda9d2010-04-21 15:30:06 -07002874int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2875{
Steve Wisecfdda9d2010-04-21 15:30:06 -07002876 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2877 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00002878 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05002879 struct sockaddr_in *laddr;
2880 struct sockaddr_in *raddr;
2881 struct sockaddr_in6 *laddr6;
2882 struct sockaddr_in6 *raddr6;
2883 struct iwpm_dev_data pm_reg_msg;
2884 struct iwpm_sa_data pm_msg;
Vipul Pandya830662f2013-07-04 16:10:47 +05302885 __u8 *ra;
2886 int iptype;
Steve Wise9eccfe12014-03-26 17:08:09 -05002887 int iwpm_err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002888
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002889 if ((conn_param->ord > c4iw_max_read_depth) ||
2890 (conn_param->ird > c4iw_max_read_depth)) {
2891 err = -EINVAL;
2892 goto out;
2893 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002894 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2895 if (!ep) {
2896 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2897 err = -ENOMEM;
2898 goto out;
2899 }
2900 init_timer(&ep->timer);
2901 ep->plen = conn_param->private_data_len;
2902 if (ep->plen)
2903 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2904 conn_param->private_data, ep->plen);
2905 ep->ird = conn_param->ird;
2906 ep->ord = conn_param->ord;
2907
2908 if (peer2peer && ep->ord == 0)
2909 ep->ord = 1;
2910
2911 cm_id->add_ref(cm_id);
2912 ep->com.dev = dev;
2913 ep->com.cm_id = cm_id;
2914 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05302915 if (!ep->com.qp) {
2916 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
2917 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05002918 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05302919 }
Vipul Pandya325abea2013-01-07 13:11:53 +00002920 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002921 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2922 ep->com.qp, cm_id);
2923
2924 /*
2925 * Allocate an active TID to initiate a TCP connection.
2926 */
2927 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2928 if (ep->atid == -1) {
2929 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2930 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05002931 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002932 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002933 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002934
Steve Wise9eccfe12014-03-26 17:08:09 -05002935 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2936 sizeof(ep->com.local_addr));
2937 memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
2938 sizeof(ep->com.remote_addr));
2939
2940 /* No port mapper available, go with the specified peer information */
2941 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
2942 sizeof(ep->com.mapped_local_addr));
2943 memcpy(&ep->com.mapped_remote_addr, &cm_id->remote_addr,
2944 sizeof(ep->com.mapped_remote_addr));
2945
2946 c4iw_form_reg_msg(dev, &pm_reg_msg);
2947 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
2948 if (iwpm_err) {
2949 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
2950 __func__, iwpm_err);
2951 }
2952 if (iwpm_valid_pid() && !iwpm_err) {
2953 c4iw_form_pm_msg(ep, &pm_msg);
2954 iwpm_err = iwpm_add_and_query_mapping(&pm_msg, RDMA_NL_C4IW);
2955 if (iwpm_err)
2956 PDBG("%s: Port Mapper query fail (err = %d).\n",
2957 __func__, iwpm_err);
2958 else
2959 c4iw_record_pm_msg(ep, &pm_msg);
2960 }
2961 if (iwpm_create_mapinfo(&ep->com.local_addr,
2962 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
2963 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
2964 err = -ENOMEM;
2965 goto fail1;
2966 }
2967 print_addr(&ep->com, __func__, "add_query/create_mapinfo");
2968 set_bit(RELEASE_MAPINFO, &ep->com.flags);
2969
2970 laddr = (struct sockaddr_in *)&ep->com.mapped_local_addr;
2971 raddr = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
2972 laddr6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
2973 raddr6 = (struct sockaddr_in6 *) &ep->com.mapped_remote_addr;
2974
Vipul Pandya830662f2013-07-04 16:10:47 +05302975 if (cm_id->remote_addr.ss_family == AF_INET) {
2976 iptype = 4;
2977 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002978
Vipul Pandya830662f2013-07-04 16:10:47 +05302979 /*
2980 * Handle loopback requests to INADDR_ANY.
2981 */
2982 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
2983 err = pick_local_ipaddrs(dev, cm_id);
2984 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05002985 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05302986 }
2987
2988 /* find a route */
2989 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
2990 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
2991 ra, ntohs(raddr->sin_port));
2992 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
2993 raddr->sin_addr.s_addr, laddr->sin_port,
2994 raddr->sin_port, 0);
2995 } else {
2996 iptype = 6;
2997 ra = (__u8 *)&raddr6->sin6_addr;
2998
2999 /*
3000 * Handle loopback requests to INADDR_ANY.
3001 */
3002 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3003 err = pick_local_ip6addrs(dev, cm_id);
3004 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003005 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303006 }
3007
3008 /* find a route */
3009 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3010 __func__, laddr6->sin6_addr.s6_addr,
3011 ntohs(laddr6->sin6_port),
3012 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3013 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3014 raddr6->sin6_addr.s6_addr,
3015 laddr6->sin6_port, raddr6->sin6_port, 0,
3016 raddr6->sin6_scope_id);
3017 }
3018 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003019 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3020 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003021 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003022 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003023
Vipul Pandya830662f2013-07-04 16:10:47 +05303024 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true);
David Miller3786cf12011-12-02 16:52:31 +00003025 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003026 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003027 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003028 }
3029
3030 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3031 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3032 ep->l2t->idx);
3033
3034 state_set(&ep->com, CONNECTING);
3035 ep->tos = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003036
3037 /* send connect request to rnic */
3038 err = send_connect(ep);
3039 if (!err)
3040 goto out;
3041
3042 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003043fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003044 dst_release(ep->dst);
3045fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003046 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003047 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003048fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003049 cm_id->rem_ref(cm_id);
3050 c4iw_put_ep(&ep->com);
3051out:
3052 return err;
3053}
3054
Vipul Pandya830662f2013-07-04 16:10:47 +05303055static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3056{
3057 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003058 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
3059 &ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303060
3061 c4iw_init_wr_wait(&ep->com.wr_wait);
3062 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3063 ep->stid, &sin6->sin6_addr,
3064 sin6->sin6_port,
3065 ep->com.dev->rdev.lldi.rxq_ids[0]);
3066 if (!err)
3067 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3068 &ep->com.wr_wait,
3069 0, 0, __func__);
3070 if (err)
3071 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3072 err, ep->stid,
3073 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
3074 return err;
3075}
3076
3077static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3078{
3079 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003080 struct sockaddr_in *sin = (struct sockaddr_in *)
3081 &ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303082
3083 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3084 do {
3085 err = cxgb4_create_server_filter(
3086 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3087 sin->sin_addr.s_addr, sin->sin_port, 0,
3088 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3089 if (err == -EBUSY) {
3090 set_current_state(TASK_UNINTERRUPTIBLE);
3091 schedule_timeout(usecs_to_jiffies(100));
3092 }
3093 } while (err == -EBUSY);
3094 } else {
3095 c4iw_init_wr_wait(&ep->com.wr_wait);
3096 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3097 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3098 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3099 if (!err)
3100 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3101 &ep->com.wr_wait,
3102 0, 0, __func__);
3103 }
3104 if (err)
3105 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3106 , err, ep->stid,
3107 &sin->sin_addr, ntohs(sin->sin_port));
3108 return err;
3109}
3110
Steve Wisecfdda9d2010-04-21 15:30:06 -07003111int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3112{
3113 int err = 0;
3114 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3115 struct c4iw_listen_ep *ep;
Steve Wise9eccfe12014-03-26 17:08:09 -05003116 struct iwpm_dev_data pm_reg_msg;
3117 struct iwpm_sa_data pm_msg;
3118 int iwpm_err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003119
Steve Wisecfdda9d2010-04-21 15:30:06 -07003120 might_sleep();
3121
3122 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3123 if (!ep) {
3124 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3125 err = -ENOMEM;
3126 goto fail1;
3127 }
3128 PDBG("%s ep %p\n", __func__, ep);
3129 cm_id->add_ref(cm_id);
3130 ep->com.cm_id = cm_id;
3131 ep->com.dev = dev;
3132 ep->backlog = backlog;
Steve Wise24d44a32013-07-04 16:10:44 +05303133 memcpy(&ep->com.local_addr, &cm_id->local_addr,
3134 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003135
3136 /*
3137 * Allocate a server TID.
3138 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303139 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3140 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303141 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
3142 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003143 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303144 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
3145 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003146
Steve Wisecfdda9d2010-04-21 15:30:06 -07003147 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003148 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003149 err = -ENOMEM;
3150 goto fail2;
3151 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003152 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003153
3154 /* No port mapper available, go with the specified info */
3155 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3156 sizeof(ep->com.mapped_local_addr));
3157
3158 c4iw_form_reg_msg(dev, &pm_reg_msg);
3159 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3160 if (iwpm_err) {
3161 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3162 __func__, iwpm_err);
3163 }
3164 if (iwpm_valid_pid() && !iwpm_err) {
3165 memcpy(&pm_msg.loc_addr, &ep->com.local_addr,
3166 sizeof(ep->com.local_addr));
3167 iwpm_err = iwpm_add_mapping(&pm_msg, RDMA_NL_C4IW);
3168 if (iwpm_err)
3169 PDBG("%s: Port Mapper query fail (err = %d).\n",
3170 __func__, iwpm_err);
3171 else
3172 memcpy(&ep->com.mapped_local_addr,
3173 &pm_msg.mapped_loc_addr,
3174 sizeof(ep->com.mapped_local_addr));
3175 }
3176 if (iwpm_create_mapinfo(&ep->com.local_addr,
3177 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3178 err = -ENOMEM;
3179 goto fail3;
3180 }
3181 print_addr(&ep->com, __func__, "add_mapping/create_mapinfo");
3182
3183 set_bit(RELEASE_MAPINFO, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003184 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303185 if (ep->com.local_addr.ss_family == AF_INET)
3186 err = create_server4(dev, ep);
3187 else
3188 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003189 if (!err) {
3190 cm_id->provider_data = ep;
3191 goto out;
3192 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003193
3194fail3:
Vipul Pandya830662f2013-07-04 16:10:47 +05303195 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3196 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003197fail2:
3198 cm_id->rem_ref(cm_id);
3199 c4iw_put_ep(&ep->com);
3200fail1:
3201out:
3202 return err;
3203}
3204
3205int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3206{
3207 int err;
3208 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3209
3210 PDBG("%s ep %p\n", __func__, ep);
3211
3212 might_sleep();
3213 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303214 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3215 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003216 err = cxgb4_remove_server_filter(
3217 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3218 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3219 } else {
3220 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303221 err = cxgb4_remove_server(
3222 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3223 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003224 if (err)
3225 goto done;
3226 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3227 0, 0, __func__);
3228 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003229 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303230 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3231 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003232done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003233 cm_id->rem_ref(cm_id);
3234 c4iw_put_ep(&ep->com);
3235 return err;
3236}
3237
3238int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3239{
3240 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003241 int close = 0;
3242 int fatal = 0;
3243 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003244
Steve Wise2f5b48c2010-09-10 11:15:36 -05003245 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003246
3247 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3248 states[ep->com.state], abrupt);
3249
3250 rdev = &ep->com.dev->rdev;
3251 if (c4iw_fatal_error(rdev)) {
3252 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303253 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003254 ep->com.state = DEAD;
3255 }
3256 switch (ep->com.state) {
3257 case MPA_REQ_WAIT:
3258 case MPA_REQ_SENT:
3259 case MPA_REQ_RCVD:
3260 case MPA_REP_SENT:
3261 case FPDU_MODE:
3262 close = 1;
3263 if (abrupt)
3264 ep->com.state = ABORTING;
3265 else {
3266 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003267 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003268 }
3269 set_bit(CLOSE_SENT, &ep->com.flags);
3270 break;
3271 case CLOSING:
3272 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3273 close = 1;
3274 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003275 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003276 ep->com.state = ABORTING;
3277 } else
3278 ep->com.state = MORIBUND;
3279 }
3280 break;
3281 case MORIBUND:
3282 case ABORTING:
3283 case DEAD:
3284 PDBG("%s ignoring disconnect ep %p state %u\n",
3285 __func__, ep, ep->com.state);
3286 break;
3287 default:
3288 BUG();
3289 break;
3290 }
3291
Steve Wisecfdda9d2010-04-21 15:30:06 -07003292 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003293 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003294 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303295 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003296 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003297 } else {
3298 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003299 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003300 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003301 if (ret)
3302 fatal = 1;
3303 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003304 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003305 if (fatal)
3306 release_ep_resources(ep);
3307 return ret;
3308}
3309
Vipul Pandya1cab7752012-12-10 09:30:55 +00003310static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3311 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3312{
3313 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003314 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003315
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003316 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3317 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003318 if (!ep)
3319 return;
3320
3321 switch (req->retval) {
3322 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003323 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3324 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3325 send_fw_act_open_req(ep, atid);
3326 return;
3327 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003328 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003329 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3330 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3331 send_fw_act_open_req(ep, atid);
3332 return;
3333 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003334 break;
3335 default:
3336 pr_info("%s unexpected ofld conn wr retval %d\n",
3337 __func__, req->retval);
3338 break;
3339 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003340 pr_err("active ofld_connect_wr failure %d atid %d\n",
3341 req->retval, atid);
3342 mutex_lock(&dev->rdev.stats.lock);
3343 dev->rdev.stats.act_ofld_conn_fails++;
3344 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003345 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003346 state_set(&ep->com, DEAD);
3347 remove_handle(dev, &dev->atid_idr, atid);
3348 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3349 dst_release(ep->dst);
3350 cxgb4_l2t_release(ep->l2t);
3351 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003352}
3353
3354static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3355 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3356{
3357 struct sk_buff *rpl_skb;
3358 struct cpl_pass_accept_req *cpl;
3359 int ret;
3360
Paul Bolle710a3112013-02-05 20:51:30 +00003361 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003362 BUG_ON(!rpl_skb);
3363 if (req->retval) {
3364 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003365 mutex_lock(&dev->rdev.stats.lock);
3366 dev->rdev.stats.pas_ofld_conn_fails++;
3367 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003368 kfree_skb(rpl_skb);
3369 } else {
3370 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3371 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003372 (__force u32) htonl(
3373 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003374 ret = pass_accept_req(dev, rpl_skb);
3375 if (!ret)
3376 kfree_skb(rpl_skb);
3377 }
3378 return;
3379}
3380
3381static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003382{
3383 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003384 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3385
3386 switch (rpl->type) {
3387 case FW6_TYPE_CQE:
3388 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3389 break;
3390 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3391 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3392 switch (req->t_state) {
3393 case TCP_SYN_SENT:
3394 active_ofld_conn_reply(dev, skb, req);
3395 break;
3396 case TCP_SYN_RECV:
3397 passive_ofld_conn_reply(dev, skb, req);
3398 break;
3399 default:
3400 pr_err("%s unexpected ofld conn wr state %d\n",
3401 __func__, req->t_state);
3402 break;
3403 }
3404 break;
3405 }
3406 return 0;
3407}
3408
3409static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3410{
3411 u32 l2info;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003412 u16 vlantag, len, hdr_len, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003413 u8 intf;
3414 struct cpl_rx_pkt *cpl = cplhdr(skb);
3415 struct cpl_pass_accept_req *req;
3416 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003417 struct c4iw_dev *dev;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003418
Vipul Pandyaf079af72013-03-14 05:08:58 +00003419 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003420 /* Store values from cpl_rx_pkt in temporary location. */
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003421 vlantag = (__force u16) cpl->vlan;
3422 len = (__force u16) cpl->len;
3423 l2info = (__force u32) cpl->l2info;
3424 hdr_len = (__force u16) cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003425 intf = cpl->iff;
3426
3427 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3428
3429 /*
3430 * We need to parse the TCP options from SYN packet.
3431 * to generate cpl_pass_accept_req.
3432 */
3433 memset(&tmp_opt, 0, sizeof(tmp_opt));
3434 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003435 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003436
3437 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3438 memset(req, 0, sizeof(*req));
3439 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003440 V_SYN_MAC_IDX(G_RX_MACIDX(
3441 (__force int) htonl(l2info))) |
Vipul Pandya1cab7752012-12-10 09:30:55 +00003442 F_SYN_XACT_MATCH);
Vipul Pandyaf079af72013-03-14 05:08:58 +00003443 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3444 G_RX_ETHHDR_LEN((__force int) htonl(l2info)) :
3445 G_RX_T5_ETHHDR_LEN((__force int) htonl(l2info));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003446 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(
3447 (__force int) htonl(l2info))) |
3448 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(
3449 (__force int) htons(hdr_len))) |
3450 V_IP_HDR_LEN(G_RX_IPHDR_LEN(
3451 (__force int) htons(hdr_len))) |
Vipul Pandyaf079af72013-03-14 05:08:58 +00003452 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(eth_hdr_len)));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003453 req->vlan = (__force __be16) vlantag;
3454 req->len = (__force __be16) len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003455 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
3456 PASS_OPEN_TOS(tos));
3457 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3458 if (tmp_opt.wscale_ok)
3459 req->tcpopt.wsf = tmp_opt.snd_wscale;
3460 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3461 if (tmp_opt.sack_ok)
3462 req->tcpopt.sack = 1;
3463 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3464 return;
3465}
3466
3467static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3468 __be32 laddr, __be16 lport,
3469 __be32 raddr, __be16 rport,
3470 u32 rcv_isn, u32 filter, u16 window,
3471 u32 rss_qid, u8 port_id)
3472{
3473 struct sk_buff *req_skb;
3474 struct fw_ofld_connection_wr *req;
3475 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303476 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003477
3478 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3479 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3480 memset(req, 0, sizeof(*req));
3481 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
3482 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
3483 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003484 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003485 req->le.lport = lport;
3486 req->le.pport = rport;
3487 req->le.u.ipv4.lip = laddr;
3488 req->le.u.ipv4.pip = raddr;
3489 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3490 req->tcb.rcv_adv = htons(window);
3491 req->tcb.t_state_to_astid =
3492 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
3493 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
3494 V_FW_OFLD_CONNECTION_WR_ASTID(
3495 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
3496
3497 /*
3498 * We store the qid in opt2 which will be used by the firmware
3499 * to send us the wr response.
3500 */
3501 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
3502
3503 /*
3504 * We initialize the MSS index in TCB to 0xF.
3505 * So that when driver sends cpl_pass_accept_rpl
3506 * TCB picks up the correct value. If this was 0
3507 * TP will ignore any value > 0 for MSS index.
3508 */
3509 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
Paul Bolle710a3112013-02-05 20:51:30 +00003510 req->cookie = (unsigned long)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003511
3512 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303513 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3514 if (ret < 0) {
3515 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3516 ret);
3517 kfree_skb(skb);
3518 kfree_skb(req_skb);
3519 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003520}
3521
3522/*
3523 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3524 * messages when a filter is being used instead of server to
3525 * redirect a syn packet. When packets hit filter they are redirected
3526 * to the offload queue and driver tries to establish the connection
3527 * using firmware work request.
3528 */
3529static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3530{
3531 int stid;
3532 unsigned int filter;
3533 struct ethhdr *eh = NULL;
3534 struct vlan_ethhdr *vlan_eh = NULL;
3535 struct iphdr *iph;
3536 struct tcphdr *tcph;
3537 struct rss_header *rss = (void *)skb->data;
3538 struct cpl_rx_pkt *cpl = (void *)skb->data;
3539 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3540 struct l2t_entry *e;
3541 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003542 struct c4iw_ep *lep;
3543 u16 window;
3544 struct port_info *pi;
3545 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003546 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003547 int step;
3548 u32 tx_chan;
3549 struct neighbour *neigh;
3550
3551 /* Drop all non-SYN packets */
3552 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
3553 goto reject;
3554
3555 /*
3556 * Drop all packets which did not hit the filter.
3557 * Unlikely to happen.
3558 */
3559 if (!(rss->filter_hit && rss->filter_tid))
3560 goto reject;
3561
3562 /*
3563 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3564 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303565 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003566
3567 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3568 if (!lep) {
3569 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3570 goto reject;
3571 }
3572
Vipul Pandyaf079af72013-03-14 05:08:58 +00003573 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3574 G_RX_ETHHDR_LEN(htonl(cpl->l2info)) :
3575 G_RX_T5_ETHHDR_LEN(htonl(cpl->l2info));
3576 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003577 eh = (struct ethhdr *)(req + 1);
3578 iph = (struct iphdr *)(eh + 1);
3579 } else {
3580 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3581 iph = (struct iphdr *)(vlan_eh + 1);
3582 skb->vlan_tci = ntohs(cpl->vlan);
3583 }
3584
3585 if (iph->version != 0x4)
3586 goto reject;
3587
3588 tcph = (struct tcphdr *)(iph + 1);
3589 skb_set_network_header(skb, (void *)iph - (void *)rss);
3590 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3591 skb_get(skb);
3592
3593 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3594 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3595 ntohs(tcph->source), iph->tos);
3596
Vipul Pandya830662f2013-07-04 16:10:47 +05303597 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3598 iph->tos);
3599 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003600 pr_err("%s - failed to find dst entry!\n",
3601 __func__);
3602 goto reject;
3603 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003604 neigh = dst_neigh_lookup_skb(dst, skb);
3605
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003606 if (!neigh) {
3607 pr_err("%s - failed to allocate neigh!\n",
3608 __func__);
3609 goto free_dst;
3610 }
3611
Vipul Pandya1cab7752012-12-10 09:30:55 +00003612 if (neigh->dev->flags & IFF_LOOPBACK) {
3613 pdev = ip_dev_find(&init_net, iph->daddr);
3614 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3615 pdev, 0);
3616 pi = (struct port_info *)netdev_priv(pdev);
3617 tx_chan = cxgb4_port_chan(pdev);
3618 dev_put(pdev);
3619 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303620 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003621 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303622 pdev, 0);
3623 pi = (struct port_info *)netdev_priv(pdev);
3624 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003625 }
Steve Wiseebf00062014-03-19 17:44:40 +05303626 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003627 if (!e) {
3628 pr_err("%s - failed to allocate l2t entry!\n",
3629 __func__);
3630 goto free_dst;
3631 }
3632
3633 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3634 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003635 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003636
3637 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303638 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3639 dev->rdev.lldi.ports[0],
3640 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003641
3642 /*
3643 * Synthesize the cpl_pass_accept_req. We have everything except the
3644 * TID. Once firmware sends a reply with TID we update the TID field
3645 * in cpl and pass it through the regular cpl_pass_accept_req path.
3646 */
3647 build_cpl_pass_accept_req(skb, stid, iph->tos);
3648 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3649 tcph->source, ntohl(tcph->seq), filter, window,
3650 rss_qid, pi->port_id);
3651 cxgb4_l2t_release(e);
3652free_dst:
3653 dst_release(dst);
3654reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003655 return 0;
3656}
3657
Steve Wisecfdda9d2010-04-21 15:30:06 -07003658/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003659 * These are the real handlers that are called from a
3660 * work queue.
3661 */
3662static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3663 [CPL_ACT_ESTABLISH] = act_establish,
3664 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3665 [CPL_RX_DATA] = rx_data,
3666 [CPL_ABORT_RPL_RSS] = abort_rpl,
3667 [CPL_ABORT_RPL] = abort_rpl,
3668 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3669 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3670 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3671 [CPL_PASS_ESTABLISH] = pass_establish,
3672 [CPL_PEER_CLOSE] = peer_close,
3673 [CPL_ABORT_REQ_RSS] = peer_abort,
3674 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3675 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003676 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003677 [CPL_FW6_MSG] = deferred_fw6_msg,
3678 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003679};
3680
3681static void process_timeout(struct c4iw_ep *ep)
3682{
3683 struct c4iw_qp_attributes attrs;
3684 int abort = 1;
3685
Steve Wise2f5b48c2010-09-10 11:15:36 -05003686 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003687 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3688 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003689 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003690 switch (ep->com.state) {
3691 case MPA_REQ_SENT:
3692 __state_set(&ep->com, ABORTING);
3693 connect_reply_upcall(ep, -ETIMEDOUT);
3694 break;
3695 case MPA_REQ_WAIT:
3696 __state_set(&ep->com, ABORTING);
3697 break;
3698 case CLOSING:
3699 case MORIBUND:
3700 if (ep->com.cm_id && ep->com.qp) {
3701 attrs.next_state = C4IW_QP_STATE_ERROR;
3702 c4iw_modify_qp(ep->com.qp->rhp,
3703 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3704 &attrs, 1);
3705 }
3706 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303707 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003708 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003709 case ABORTING:
3710 case DEAD:
3711
3712 /*
3713 * These states are expected if the ep timed out at the same
3714 * time as another thread was calling stop_ep_timer().
3715 * So we silently do nothing for these states.
3716 */
3717 abort = 0;
3718 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003719 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003720 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003721 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003722 abort = 0;
3723 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003724 if (abort)
3725 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecc18b932014-04-24 14:31:53 -05003726 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003727 c4iw_put_ep(&ep->com);
3728}
3729
3730static void process_timedout_eps(void)
3731{
3732 struct c4iw_ep *ep;
3733
3734 spin_lock_irq(&timeout_lock);
3735 while (!list_empty(&timeout_list)) {
3736 struct list_head *tmp;
3737
3738 tmp = timeout_list.next;
3739 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003740 tmp->next = NULL;
3741 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003742 spin_unlock_irq(&timeout_lock);
3743 ep = list_entry(tmp, struct c4iw_ep, entry);
3744 process_timeout(ep);
3745 spin_lock_irq(&timeout_lock);
3746 }
3747 spin_unlock_irq(&timeout_lock);
3748}
3749
3750static void process_work(struct work_struct *work)
3751{
3752 struct sk_buff *skb = NULL;
3753 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003754 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003755 unsigned int opcode;
3756 int ret;
3757
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003758 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003759 while ((skb = skb_dequeue(&rxq))) {
3760 rpl = cplhdr(skb);
3761 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3762 opcode = rpl->ot.opcode;
3763
3764 BUG_ON(!work_handlers[opcode]);
3765 ret = work_handlers[opcode](dev, skb);
3766 if (!ret)
3767 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003768 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003769 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003770}
3771
3772static DECLARE_WORK(skb_work, process_work);
3773
3774static void ep_timeout(unsigned long arg)
3775{
3776 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003777 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003778
3779 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003780 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003781 /*
3782 * Only insert if it is not already on the list.
3783 */
3784 if (!ep->entry.next) {
3785 list_add_tail(&ep->entry, &timeout_list);
3786 kickit = 1;
3787 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003788 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003789 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003790 if (kickit)
3791 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003792}
3793
3794/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07003795 * All the CM events are handled on a work queue to have a safe context.
3796 */
3797static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3798{
3799
3800 /*
3801 * Save dev in the skb->cb area.
3802 */
3803 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3804
3805 /*
3806 * Queue the skb and schedule the worker thread.
3807 */
3808 skb_queue_tail(&rxq, skb);
3809 queue_work(workq, &skb_work);
3810 return 0;
3811}
3812
3813static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3814{
3815 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3816
3817 if (rpl->status != CPL_ERR_NONE) {
3818 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3819 "for tid %u\n", rpl->status, GET_TID(rpl));
3820 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003821 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003822 return 0;
3823}
3824
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003825static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3826{
3827 struct cpl_fw6_msg *rpl = cplhdr(skb);
3828 struct c4iw_wr_wait *wr_waitp;
3829 int ret;
3830
3831 PDBG("%s type %u\n", __func__, rpl->type);
3832
3833 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003834 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003835 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07003836 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003837 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07003838 if (wr_waitp)
3839 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003840 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003841 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003842 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003843 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00003844 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003845 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003846 default:
3847 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3848 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003849 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003850 break;
3851 }
3852 return 0;
3853}
3854
Steve Wise8da7e7a2011-06-14 20:59:27 +00003855static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3856{
3857 struct cpl_abort_req_rss *req = cplhdr(skb);
3858 struct c4iw_ep *ep;
3859 struct tid_info *t = dev->rdev.lldi.tids;
3860 unsigned int tid = GET_TID(req);
3861
3862 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05003863 if (!ep) {
3864 printk(KERN_WARNING MOD
3865 "Abort on non-existent endpoint, tid %d\n", tid);
3866 kfree_skb(skb);
3867 return 0;
3868 }
Steve Wise7a2cea22014-03-14 21:52:07 +05303869 if (is_neg_adv(req->status)) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003870 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3871 ep->hwtid);
3872 kfree_skb(skb);
3873 return 0;
3874 }
3875 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3876 ep->com.state);
3877
3878 /*
3879 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003880 * However, if we are on MPAv2 and want to retry with MPAv1
3881 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00003882 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003883 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
3884 if (ep->com.state != MPA_REQ_SENT)
3885 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3886 } else
3887 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003888 sched(dev, skb);
3889 return 0;
3890}
3891
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003892/*
3893 * Most upcalls from the T4 Core go to sched() to
3894 * schedule the processing on a work queue.
3895 */
3896c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3897 [CPL_ACT_ESTABLISH] = sched,
3898 [CPL_ACT_OPEN_RPL] = sched,
3899 [CPL_RX_DATA] = sched,
3900 [CPL_ABORT_RPL_RSS] = sched,
3901 [CPL_ABORT_RPL] = sched,
3902 [CPL_PASS_OPEN_RPL] = sched,
3903 [CPL_CLOSE_LISTSRV_RPL] = sched,
3904 [CPL_PASS_ACCEPT_REQ] = sched,
3905 [CPL_PASS_ESTABLISH] = sched,
3906 [CPL_PEER_CLOSE] = sched,
3907 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00003908 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003909 [CPL_RDMA_TERMINATE] = sched,
3910 [CPL_FW4_ACK] = sched,
3911 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003912 [CPL_FW6_MSG] = fw6_msg,
3913 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003914};
3915
Steve Wisecfdda9d2010-04-21 15:30:06 -07003916int __init c4iw_cm_init(void)
3917{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003918 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003919 skb_queue_head_init(&rxq);
3920
3921 workq = create_singlethread_workqueue("iw_cxgb4");
3922 if (!workq)
3923 return -ENOMEM;
3924
Steve Wisecfdda9d2010-04-21 15:30:06 -07003925 return 0;
3926}
3927
Steve Wise46c13762014-06-20 14:26:25 -05003928void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07003929{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003930 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003931 flush_workqueue(workq);
3932 destroy_workqueue(workq);
3933}