blob: 0c2111b5b2e4ce0d37a012facaac21612a8c7552 [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"
Hariprasad S84cc6ac62015-08-25 14:08:23 +053053#include "clip_tbl.h"
Steve Wisecfdda9d2010-04-21 15:30:06 -070054
55static char *states[] = {
56 "idle",
57 "listen",
58 "connecting",
59 "mpa_wait_req",
60 "mpa_req_sent",
61 "mpa_req_rcvd",
62 "mpa_rep_sent",
63 "fpdu_mode",
64 "aborting",
65 "closing",
66 "moribund",
67 "dead",
68 NULL,
69};
70
Vipul Pandya5be78ee2012-12-10 09:30:54 +000071static int nocong;
72module_param(nocong, int, 0644);
73MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
74
75static int enable_ecn;
76module_param(enable_ecn, int, 0644);
77MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
78
Steve Wiseb52fe092011-03-11 22:30:01 +000079static int dack_mode = 1;
Steve Wiseba6d3922010-06-23 15:46:49 +000080module_param(dack_mode, int, 0644);
Steve Wiseb52fe092011-03-11 22:30:01 +000081MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
Steve Wiseba6d3922010-06-23 15:46:49 +000082
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053083uint c4iw_max_read_depth = 32;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070084module_param(c4iw_max_read_depth, int, 0644);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053085MODULE_PARM_DESC(c4iw_max_read_depth,
86 "Per-connection max ORD/IRD (default=32)");
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070087
Steve Wisecfdda9d2010-04-21 15:30:06 -070088static int enable_tcp_timestamps;
89module_param(enable_tcp_timestamps, int, 0644);
90MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
91
92static int enable_tcp_sack;
93module_param(enable_tcp_sack, int, 0644);
94MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
95
96static int enable_tcp_window_scaling = 1;
97module_param(enable_tcp_window_scaling, int, 0644);
98MODULE_PARM_DESC(enable_tcp_window_scaling,
99 "Enable tcp window scaling (default=1)");
100
101int c4iw_debug;
102module_param(c4iw_debug, int, 0644);
103MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
104
Steve Wisedf2d5132014-03-19 17:44:44 +0530105static int peer2peer = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700106module_param(peer2peer, int, 0644);
Steve Wisedf2d5132014-03-19 17:44:44 +0530107MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700108
109static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
110module_param(p2p_type, int, 0644);
111MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
112 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
113
114static int ep_timeout_secs = 60;
115module_param(ep_timeout_secs, int, 0644);
116MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
117 "in seconds (default=60)");
118
Hariprasad Sb8ac3112015-07-27 14:08:52 +0530119static int mpa_rev = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700120module_param(mpa_rev, int, 0644);
121MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530122 "1 is RFC0544 spec compliant, 2 is IETF MPA Peer Connect Draft"
Hariprasad Sb8ac3112015-07-27 14:08:52 +0530123 " compliant (default=2)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700124
125static int markers_enabled;
126module_param(markers_enabled, int, 0644);
127MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
128
129static int crc_enabled = 1;
130module_param(crc_enabled, int, 0644);
131MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
132
133static int rcv_win = 256 * 1024;
134module_param(rcv_win, int, 0644);
135MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
136
Steve Wise98ae68b2010-09-10 11:15:41 -0500137static int snd_win = 128 * 1024;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700138module_param(snd_win, int, 0644);
Steve Wise98ae68b2010-09-10 11:15:41 -0500139MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700140
Steve Wisecfdda9d2010-04-21 15:30:06 -0700141static struct workqueue_struct *workq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700142
143static struct sk_buff_head rxq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700144
145static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
146static void ep_timeout(unsigned long arg);
147static void connect_reply_upcall(struct c4iw_ep *ep, int status);
148
Roland Dreierbe4c9ba2010-05-05 14:45:40 -0700149static LIST_HEAD(timeout_list);
150static spinlock_t timeout_lock;
151
Vipul Pandya325abea2013-01-07 13:11:53 +0000152static void deref_qp(struct c4iw_ep *ep)
153{
154 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
155 clear_bit(QP_REFERENCED, &ep->com.flags);
156}
157
158static void ref_qp(struct c4iw_ep *ep)
159{
160 set_bit(QP_REFERENCED, &ep->com.flags);
161 c4iw_qp_add_ref(&ep->com.qp->ibqp);
162}
163
Steve Wisecfdda9d2010-04-21 15:30:06 -0700164static void start_ep_timer(struct c4iw_ep *ep)
165{
166 PDBG("%s ep %p\n", __func__, ep);
167 if (timer_pending(&ep->timer)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000168 pr_err("%s timer already started! ep %p\n",
169 __func__, ep);
170 return;
171 }
172 clear_bit(TIMEOUT, &ep->com.flags);
173 c4iw_get_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700174 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
175 ep->timer.data = (unsigned long)ep;
176 ep->timer.function = ep_timeout;
177 add_timer(&ep->timer);
178}
179
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500180static int stop_ep_timer(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700181{
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000182 PDBG("%s ep %p stopping\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700183 del_timer_sync(&ep->timer);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500184 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000185 c4iw_put_ep(&ep->com);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500186 return 0;
187 }
188 return 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700189}
190
191static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
192 struct l2t_entry *l2e)
193{
194 int error = 0;
195
196 if (c4iw_fatal_error(rdev)) {
197 kfree_skb(skb);
198 PDBG("%s - device in error state - dropping\n", __func__);
199 return -EIO;
200 }
201 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
202 if (error < 0)
203 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500204 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700205}
206
207int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
208{
209 int error = 0;
210
211 if (c4iw_fatal_error(rdev)) {
212 kfree_skb(skb);
213 PDBG("%s - device in error state - dropping\n", __func__);
214 return -EIO;
215 }
216 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
217 if (error < 0)
218 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500219 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700220}
221
222static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
223{
224 struct cpl_tid_release *req;
225
226 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
227 if (!skb)
228 return;
229 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
230 INIT_TP_WR(req, hwtid);
231 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
232 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
233 c4iw_ofld_send(rdev, skb);
234 return;
235}
236
237static void set_emss(struct c4iw_ep *ep, u16 opt)
238{
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800239 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
Hariprasad S04524a42014-09-24 03:53:41 +0530240 ((AF_INET == ep->com.remote_addr.ss_family) ?
241 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
242 sizeof(struct tcphdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700243 ep->mss = ep->emss;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800244 if (TCPOPT_TSTAMP_G(opt))
Hariprasad S04524a42014-09-24 03:53:41 +0530245 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700246 if (ep->emss < 128)
247 ep->emss = 128;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530248 if (ep->emss & 7)
249 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800250 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
251 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt),
Steve Wisecfdda9d2010-04-21 15:30:06 -0700252 ep->mss, ep->emss);
253}
254
255static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
256{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700257 enum c4iw_ep_state state;
258
Steve Wise2f5b48c2010-09-10 11:15:36 -0500259 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700260 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500261 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700262 return state;
263}
264
265static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
266{
267 epc->state = new;
268}
269
270static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
271{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500272 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700273 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
274 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500275 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700276 return;
277}
278
279static void *alloc_ep(int size, gfp_t gfp)
280{
281 struct c4iw_ep_common *epc;
282
283 epc = kzalloc(size, gfp);
284 if (epc) {
285 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500286 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500287 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700288 }
289 PDBG("%s alloc ep %p\n", __func__, epc);
290 return epc;
291}
292
293void _c4iw_free_ep(struct kref *kref)
294{
295 struct c4iw_ep *ep;
296
297 ep = container_of(kref, struct c4iw_ep, com.kref);
298 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000299 if (test_bit(QP_REFERENCED, &ep->com.flags))
300 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700301 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530302 if (ep->com.remote_addr.ss_family == AF_INET6) {
303 struct sockaddr_in6 *sin6 =
304 (struct sockaddr_in6 *)
305 &ep->com.mapped_local_addr;
306
307 cxgb4_clip_release(
308 ep->com.dev->rdev.lldi.ports[0],
309 (const u32 *)&sin6->sin6_addr.s6_addr,
310 1);
311 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000312 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700313 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
314 dst_release(ep->dst);
315 cxgb4_l2t_release(ep->l2t);
316 }
Steve Wise9eccfe12014-03-26 17:08:09 -0500317 if (test_bit(RELEASE_MAPINFO, &ep->com.flags)) {
318 print_addr(&ep->com, __func__, "remove_mapinfo/mapping");
319 iwpm_remove_mapinfo(&ep->com.local_addr,
320 &ep->com.mapped_local_addr);
321 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
322 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700323 kfree(ep);
324}
325
326static void release_ep_resources(struct c4iw_ep *ep)
327{
328 set_bit(RELEASE_RESOURCES, &ep->com.flags);
329 c4iw_put_ep(&ep->com);
330}
331
Steve Wisecfdda9d2010-04-21 15:30:06 -0700332static int status2errno(int status)
333{
334 switch (status) {
335 case CPL_ERR_NONE:
336 return 0;
337 case CPL_ERR_CONN_RESET:
338 return -ECONNRESET;
339 case CPL_ERR_ARP_MISS:
340 return -EHOSTUNREACH;
341 case CPL_ERR_CONN_TIMEDOUT:
342 return -ETIMEDOUT;
343 case CPL_ERR_TCAM_FULL:
344 return -ENOMEM;
345 case CPL_ERR_CONN_EXIST:
346 return -EADDRINUSE;
347 default:
348 return -EIO;
349 }
350}
351
352/*
353 * Try and reuse skbs already allocated...
354 */
355static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
356{
357 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
358 skb_trim(skb, 0);
359 skb_get(skb);
360 skb_reset_transport_header(skb);
361 } else {
362 skb = alloc_skb(len, gfp);
363 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530364 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700365 return skb;
366}
367
Vipul Pandya830662f2013-07-04 16:10:47 +0530368static struct net_device *get_real_dev(struct net_device *egress_dev)
369{
Steve Wise11b8e222014-05-16 12:42:46 -0500370 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530371}
372
373static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
374{
375 int i;
376
377 egress_dev = get_real_dev(egress_dev);
378 for (i = 0; i < dev->rdev.lldi.nports; i++)
379 if (dev->rdev.lldi.ports[i] == egress_dev)
380 return 1;
381 return 0;
382}
383
384static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
385 __u8 *peer_ip, __be16 local_port,
386 __be16 peer_port, u8 tos,
387 __u32 sin6_scope_id)
388{
389 struct dst_entry *dst = NULL;
390
391 if (IS_ENABLED(CONFIG_IPV6)) {
392 struct flowi6 fl6;
393
394 memset(&fl6, 0, sizeof(fl6));
395 memcpy(&fl6.daddr, peer_ip, 16);
396 memcpy(&fl6.saddr, local_ip, 16);
397 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
398 fl6.flowi6_oif = sin6_scope_id;
399 dst = ip6_route_output(&init_net, NULL, &fl6);
400 if (!dst)
401 goto out;
402 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
403 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
404 dst_release(dst);
405 dst = NULL;
406 }
407 }
408
409out:
410 return dst;
411}
412
413static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700414 __be32 peer_ip, __be16 local_port,
415 __be16 peer_port, u8 tos)
416{
417 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700418 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530419 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700420
David S. Miller31e4543d2011-05-03 20:25:42 -0700421 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500422 peer_port, local_port, IPPROTO_TCP,
423 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800424 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700425 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530426 n = dst_neigh_lookup(&rt->dst, &peer_ip);
427 if (!n)
428 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530429 if (!our_interface(dev, n->dev) &&
430 !(n->dev->flags & IFF_LOOPBACK)) {
Hariprasad Sd4802012014-09-24 03:53:42 +0530431 neigh_release(n);
Vipul Pandya830662f2013-07-04 16:10:47 +0530432 dst_release(&rt->dst);
433 return NULL;
434 }
435 neigh_release(n);
436 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700437}
438
439static void arp_failure_discard(void *handle, struct sk_buff *skb)
440{
441 PDBG("%s c4iw_dev %p\n", __func__, handle);
442 kfree_skb(skb);
443}
444
445/*
446 * Handle an ARP failure for an active open.
447 */
448static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
449{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530450 struct c4iw_ep *ep = handle;
451
Masanari Iidae3d132d2015-10-16 21:14:29 +0900452 printk(KERN_ERR MOD "ARP failure during connect\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700453 kfree_skb(skb);
Hariprasad S5dab6d32014-06-23 19:12:36 +0530454 connect_reply_upcall(ep, -EHOSTUNREACH);
455 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530456 if (ep->com.remote_addr.ss_family == AF_INET6) {
457 struct sockaddr_in6 *sin6 =
458 (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
459 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
460 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
461 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530462 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
463 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
464 dst_release(ep->dst);
465 cxgb4_l2t_release(ep->l2t);
466 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700467}
468
469/*
470 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
471 * and send it along.
472 */
473static void abort_arp_failure(void *handle, struct sk_buff *skb)
474{
475 struct c4iw_rdev *rdev = handle;
476 struct cpl_abort_req *req = cplhdr(skb);
477
478 PDBG("%s rdev %p\n", __func__, rdev);
479 req->cmd = CPL_ABORT_NO_RST;
480 c4iw_ofld_send(rdev, skb);
481}
482
483static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
484{
485 unsigned int flowclen = 80;
486 struct fw_flowc_wr *flowc;
487 int i;
488
489 skb = get_skb(skb, flowclen, GFP_KERNEL);
490 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
491
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530492 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
493 FW_FLOWC_WR_NPARAMS_V(8));
494 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(flowclen,
495 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700496
497 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530498 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530499 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700500 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
501 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
502 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
503 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
504 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
505 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
506 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
507 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
508 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
509 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
510 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530511 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700512 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
513 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
514 /* Pad WR to 16 byte boundary */
515 flowc->mnemval[8].mnemonic = 0;
516 flowc->mnemval[8].val = 0;
517 for (i = 0; i < 9; i++) {
518 flowc->mnemval[i].r4[0] = 0;
519 flowc->mnemval[i].r4[1] = 0;
520 flowc->mnemval[i].r4[2] = 0;
521 }
522
523 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
524 c4iw_ofld_send(&ep->com.dev->rdev, skb);
525}
526
527static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
528{
529 struct cpl_close_con_req *req;
530 struct sk_buff *skb;
531 int wrlen = roundup(sizeof *req, 16);
532
533 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
534 skb = get_skb(NULL, wrlen, gfp);
535 if (!skb) {
536 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
537 return -ENOMEM;
538 }
539 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
540 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
541 req = (struct cpl_close_con_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_CLOSE_CON_REQ,
545 ep->hwtid));
546 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
547}
548
549static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
550{
551 struct cpl_abort_req *req;
552 int wrlen = roundup(sizeof *req, 16);
553
554 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
555 skb = get_skb(skb, wrlen, gfp);
556 if (!skb) {
557 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
558 __func__);
559 return -ENOMEM;
560 }
561 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
562 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
563 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
564 memset(req, 0, wrlen);
565 INIT_TP_WR(req, ep->hwtid);
566 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
567 req->cmd = CPL_ABORT_SEND_RST;
568 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
569}
570
Steve Wise9eccfe12014-03-26 17:08:09 -0500571/*
572 * c4iw_form_pm_msg - Form a port mapper message with mapping info
573 */
574static void c4iw_form_pm_msg(struct c4iw_ep *ep,
575 struct iwpm_sa_data *pm_msg)
576{
577 memcpy(&pm_msg->loc_addr, &ep->com.local_addr,
578 sizeof(ep->com.local_addr));
579 memcpy(&pm_msg->rem_addr, &ep->com.remote_addr,
580 sizeof(ep->com.remote_addr));
581}
582
583/*
584 * c4iw_form_reg_msg - Form a port mapper message with dev info
585 */
586static void c4iw_form_reg_msg(struct c4iw_dev *dev,
587 struct iwpm_dev_data *pm_msg)
588{
589 memcpy(pm_msg->dev_name, dev->ibdev.name, IWPM_DEVNAME_SIZE);
590 memcpy(pm_msg->if_name, dev->rdev.lldi.ports[0]->name,
591 IWPM_IFNAME_SIZE);
592}
593
594static void c4iw_record_pm_msg(struct c4iw_ep *ep,
595 struct iwpm_sa_data *pm_msg)
596{
597 memcpy(&ep->com.mapped_local_addr, &pm_msg->mapped_loc_addr,
598 sizeof(ep->com.mapped_local_addr));
599 memcpy(&ep->com.mapped_remote_addr, &pm_msg->mapped_rem_addr,
600 sizeof(ep->com.mapped_remote_addr));
601}
602
Steve Wise940fd302015-05-07 16:34:23 -0500603static int get_remote_addr(struct c4iw_ep *parent_ep, struct c4iw_ep *child_ep)
Steve Wise5b6b8fe2015-04-21 16:28:41 -0400604{
605 int ret;
606
Steve Wise940fd302015-05-07 16:34:23 -0500607 print_addr(&parent_ep->com, __func__, "get_remote_addr parent_ep ");
608 print_addr(&child_ep->com, __func__, "get_remote_addr child_ep ");
Steve Wise5b6b8fe2015-04-21 16:28:41 -0400609
Steve Wise940fd302015-05-07 16:34:23 -0500610 ret = iwpm_get_remote_info(&parent_ep->com.mapped_local_addr,
611 &child_ep->com.mapped_remote_addr,
612 &child_ep->com.remote_addr, RDMA_NL_C4IW);
Steve Wise5b6b8fe2015-04-21 16:28:41 -0400613 if (ret)
Steve Wise940fd302015-05-07 16:34:23 -0500614 PDBG("Unable to find remote peer addr info - err %d\n", ret);
Steve Wise5b6b8fe2015-04-21 16:28:41 -0400615
616 return ret;
617}
618
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530619static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530620 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530621{
Hariprasad S04524a42014-09-24 03:53:41 +0530622 unsigned short hdr_size = (ipv6 ?
623 sizeof(struct ipv6hdr) :
624 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530625 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530626 (use_ts ?
627 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530628 unsigned short data_size = mtu - hdr_size;
629
630 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
631}
632
Steve Wisecfdda9d2010-04-21 15:30:06 -0700633static int send_connect(struct c4iw_ep *ep)
634{
Hariprasad S963cab52015-09-23 17:19:27 +0530635 struct cpl_act_open_req *req = NULL;
636 struct cpl_t5_act_open_req *t5req = NULL;
637 struct cpl_t6_act_open_req *t6req = NULL;
638 struct cpl_act_open_req6 *req6 = NULL;
639 struct cpl_t5_act_open_req6 *t5req6 = NULL;
640 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700641 struct sk_buff *skb;
642 u64 opt0;
643 u32 opt2;
644 unsigned int mtu_idx;
645 int wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530646 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500647 struct sockaddr_in *la = (struct sockaddr_in *)
648 &ep->com.mapped_local_addr;
649 struct sockaddr_in *ra = (struct sockaddr_in *)
650 &ep->com.mapped_remote_addr;
651 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
652 &ep->com.mapped_local_addr;
653 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
654 &ep->com.mapped_remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530655 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530656 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
657 u32 isn = (prandom_u32() & ~7UL) - 1;
658
659 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
660 case CHELSIO_T4:
661 sizev4 = sizeof(struct cpl_act_open_req);
662 sizev6 = sizeof(struct cpl_act_open_req6);
663 break;
664 case CHELSIO_T5:
665 sizev4 = sizeof(struct cpl_t5_act_open_req);
666 sizev6 = sizeof(struct cpl_t5_act_open_req6);
667 break;
668 case CHELSIO_T6:
669 sizev4 = sizeof(struct cpl_t6_act_open_req);
670 sizev6 = sizeof(struct cpl_t6_act_open_req6);
671 break;
672 default:
673 pr_err("T%d Chip is not supported\n",
674 CHELSIO_CHIP_VERSION(adapter_type));
675 return -EINVAL;
676 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530677
678 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
679 roundup(sizev4, 16) :
680 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700681
682 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
683
684 skb = get_skb(NULL, wrlen, GFP_KERNEL);
685 if (!skb) {
686 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
687 __func__);
688 return -ENOMEM;
689 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000690 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700691
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530692 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530693 enable_tcp_timestamps,
694 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700695 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530696
697 /*
698 * Specify the largest window that will fit in opt0. The
699 * remainder will be specified in the rx_data_ack.
700 */
701 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800702 if (win > RCV_BUFSIZ_M)
703 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530704
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800705 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800706 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800707 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800708 WND_SCALE_V(wscale) |
709 MSS_IDX_V(mtu_idx) |
710 L2T_IDX_V(ep->l2t->idx) |
711 TX_CHAN_V(ep->tx_chan) |
712 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800713 DSCP_V(ep->tos) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800714 ULP_MODE_V(ULP_MODE_TCPDDP) |
715 RCV_BUFSIZ_V(win);
716 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800717 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800718 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700719 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800720 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700721 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800722 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700723 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800724 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530725 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
726 if (peer2peer)
727 isn += 4;
728
Anish Bhattd7990b02014-11-12 17:15:57 -0800729 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530730 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530731 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500732 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530733
734 if (ep->com.remote_addr.ss_family == AF_INET6)
735 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
736 (const u32 *)&la6->sin6_addr.s6_addr, 1);
737
Hariprasad S5dab6d32014-06-23 19:12:36 +0530738 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700739
Hariprasad S963cab52015-09-23 17:19:27 +0530740 if (ep->com.remote_addr.ss_family == AF_INET) {
741 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
742 case CHELSIO_T4:
743 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530744 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530745 break;
746 case CHELSIO_T5:
747 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
748 wrlen);
749 INIT_TP_WR(t5req, 0);
750 req = (struct cpl_act_open_req *)t5req;
751 break;
752 case CHELSIO_T6:
753 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
754 wrlen);
755 INIT_TP_WR(t6req, 0);
756 req = (struct cpl_act_open_req *)t6req;
757 t5req = (struct cpl_t5_act_open_req *)t6req;
758 break;
759 default:
760 pr_err("T%d Chip is not supported\n",
761 CHELSIO_CHIP_VERSION(adapter_type));
762 ret = -EINVAL;
763 goto clip_release;
764 }
765
766 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
767 ((ep->rss_qid<<14) | ep->atid)));
768 req->local_port = la->sin_port;
769 req->peer_port = ra->sin_port;
770 req->local_ip = la->sin_addr.s_addr;
771 req->peer_ip = ra->sin_addr.s_addr;
772 req->opt0 = cpu_to_be64(opt0);
773
774 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530775 req->params = cpu_to_be32(cxgb4_select_ntuple(
776 ep->com.dev->rdev.lldi.ports[0],
777 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530778 req->opt2 = cpu_to_be32(opt2);
779 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530780 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
781 cxgb4_select_ntuple(
782 ep->com.dev->rdev.lldi.ports[0],
783 ep->l2t)));
784 t5req->rsvd = cpu_to_be32(isn);
785 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
786 t5req->opt2 = cpu_to_be32(opt2);
787 }
788 } else {
789 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
790 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530791 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530792 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530793 break;
794 case CHELSIO_T5:
795 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
796 wrlen);
797 INIT_TP_WR(t5req6, 0);
798 req6 = (struct cpl_act_open_req6 *)t5req6;
799 break;
800 case CHELSIO_T6:
801 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
802 wrlen);
803 INIT_TP_WR(t6req6, 0);
804 req6 = (struct cpl_act_open_req6 *)t6req6;
805 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
806 break;
807 default:
808 pr_err("T%d Chip is not supported\n",
809 CHELSIO_CHIP_VERSION(adapter_type));
810 ret = -EINVAL;
811 goto clip_release;
812 }
813
814 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
815 ((ep->rss_qid<<14)|ep->atid)));
816 req6->local_port = la6->sin6_port;
817 req6->peer_port = ra6->sin6_port;
818 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
819 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
820 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
821 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
822 req6->opt0 = cpu_to_be64(opt0);
823
824 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530825 req6->params = cpu_to_be32(cxgb4_select_ntuple(
826 ep->com.dev->rdev.lldi.ports[0],
827 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530828 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530829 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530830 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
831 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530832 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530833 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530834 t5req6->rsvd = cpu_to_be32(isn);
835 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
836 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530837 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000838 }
839
Vipul Pandya793dad92012-12-10 09:30:56 +0000840 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530841 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530842clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530843 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
844 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
845 (const u32 *)&la6->sin6_addr.s6_addr, 1);
846 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700847}
848
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530849static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
850 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700851{
852 int mpalen, wrlen;
853 struct fw_ofld_tx_data_wr *req;
854 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530855 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700856
857 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
858
859 BUG_ON(skb_cloned(skb));
860
861 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530862 if (mpa_rev_to_use == 2)
863 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700864 wrlen = roundup(mpalen + sizeof *req, 16);
865 skb = get_skb(skb, wrlen, GFP_KERNEL);
866 if (!skb) {
867 connect_reply_upcall(ep, -ENOMEM);
868 return;
869 }
870 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
871
872 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
873 memset(req, 0, wrlen);
874 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530875 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
876 FW_WR_COMPL_F |
877 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700878 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530879 FW_WR_FLOWID_V(ep->hwtid) |
880 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700881 req->plen = cpu_to_be32(mpalen);
882 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530883 FW_OFLD_TX_DATA_WR_FLUSH_F |
884 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700885
886 mpa = (struct mpa_message *)(req + 1);
887 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
888 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530889 (markers_enabled ? MPA_MARKERS : 0) |
890 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700891 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530892 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530893 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530894 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530895 ep->retry_with_mpa_v1 = 0;
896 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700897
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530898 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700899 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
900 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530901 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
902 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530903 mpa_v2_params.ird = htons((u16)ep->ird);
904 mpa_v2_params.ord = htons((u16)ep->ord);
905
906 if (peer2peer) {
907 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
908 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
909 mpa_v2_params.ord |=
910 htons(MPA_V2_RDMA_WRITE_RTR);
911 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
912 mpa_v2_params.ord |=
913 htons(MPA_V2_RDMA_READ_RTR);
914 }
915 memcpy(mpa->private_data, &mpa_v2_params,
916 sizeof(struct mpa_v2_conn_params));
917
918 if (ep->plen)
919 memcpy(mpa->private_data +
920 sizeof(struct mpa_v2_conn_params),
921 ep->mpa_pkt + sizeof(*mpa), ep->plen);
922 } else
923 if (ep->plen)
924 memcpy(mpa->private_data,
925 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700926
927 /*
928 * Reference the mpa skb. This ensures the data area
929 * will remain in memory until the hw acks the tx.
930 * Function fw4_ack() will deref it.
931 */
932 skb_get(skb);
933 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
934 BUG_ON(ep->mpa_skb);
935 ep->mpa_skb = skb;
936 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
937 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530938 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700939 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530940 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700941 return;
942}
943
944static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
945{
946 int mpalen, wrlen;
947 struct fw_ofld_tx_data_wr *req;
948 struct mpa_message *mpa;
949 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530950 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700951
952 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
953
954 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530955 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
956 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700957 wrlen = roundup(mpalen + sizeof *req, 16);
958
959 skb = get_skb(NULL, wrlen, GFP_KERNEL);
960 if (!skb) {
961 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
962 return -ENOMEM;
963 }
964 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
965
966 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
967 memset(req, 0, wrlen);
968 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530969 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
970 FW_WR_COMPL_F |
971 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700972 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530973 FW_WR_FLOWID_V(ep->hwtid) |
974 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700975 req->plen = cpu_to_be32(mpalen);
976 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530977 FW_OFLD_TX_DATA_WR_FLUSH_F |
978 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700979
980 mpa = (struct mpa_message *)(req + 1);
981 memset(mpa, 0, sizeof(*mpa));
982 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
983 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000984 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700985 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530986
987 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
988 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700989 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
990 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530991 mpa_v2_params.ird = htons(((u16)ep->ird) |
992 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
993 0));
994 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
995 (p2p_type ==
996 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
997 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
998 FW_RI_INIT_P2PTYPE_READ_REQ ?
999 MPA_V2_RDMA_READ_RTR : 0) : 0));
1000 memcpy(mpa->private_data, &mpa_v2_params,
1001 sizeof(struct mpa_v2_conn_params));
1002
1003 if (ep->plen)
1004 memcpy(mpa->private_data +
1005 sizeof(struct mpa_v2_conn_params), pdata, plen);
1006 } else
1007 if (plen)
1008 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001009
1010 /*
1011 * Reference the mpa skb again. This ensures the data area
1012 * will remain in memory until the hw acks the tx.
1013 * Function fw4_ack() will deref it.
1014 */
1015 skb_get(skb);
1016 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1017 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1018 BUG_ON(ep->mpa_skb);
1019 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301020 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001021 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1022}
1023
1024static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1025{
1026 int mpalen, wrlen;
1027 struct fw_ofld_tx_data_wr *req;
1028 struct mpa_message *mpa;
1029 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301030 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001031
1032 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1033
1034 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301035 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1036 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001037 wrlen = roundup(mpalen + sizeof *req, 16);
1038
1039 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1040 if (!skb) {
1041 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1042 return -ENOMEM;
1043 }
1044 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1045
1046 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1047 memset(req, 0, wrlen);
1048 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301049 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1050 FW_WR_COMPL_F |
1051 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001052 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301053 FW_WR_FLOWID_V(ep->hwtid) |
1054 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001055 req->plen = cpu_to_be32(mpalen);
1056 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301057 FW_OFLD_TX_DATA_WR_FLUSH_F |
1058 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001059
1060 mpa = (struct mpa_message *)(req + 1);
1061 memset(mpa, 0, sizeof(*mpa));
1062 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1063 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
1064 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301065 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001066 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301067
1068 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1069 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001070 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1071 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301072 mpa_v2_params.ird = htons((u16)ep->ird);
1073 mpa_v2_params.ord = htons((u16)ep->ord);
1074 if (peer2peer && (ep->mpa_attr.p2p_type !=
1075 FW_RI_INIT_P2PTYPE_DISABLED)) {
1076 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1077
1078 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1079 mpa_v2_params.ord |=
1080 htons(MPA_V2_RDMA_WRITE_RTR);
1081 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1082 mpa_v2_params.ord |=
1083 htons(MPA_V2_RDMA_READ_RTR);
1084 }
1085
1086 memcpy(mpa->private_data, &mpa_v2_params,
1087 sizeof(struct mpa_v2_conn_params));
1088
1089 if (ep->plen)
1090 memcpy(mpa->private_data +
1091 sizeof(struct mpa_v2_conn_params), pdata, plen);
1092 } else
1093 if (plen)
1094 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001095
1096 /*
1097 * Reference the mpa skb. This ensures the data area
1098 * will remain in memory until the hw acks the tx.
1099 * Function fw4_ack() will deref it.
1100 */
1101 skb_get(skb);
1102 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1103 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301104 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301105 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001106 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1107}
1108
1109static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1110{
1111 struct c4iw_ep *ep;
1112 struct cpl_act_establish *req = cplhdr(skb);
1113 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001114 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001115 struct tid_info *t = dev->rdev.lldi.tids;
1116
1117 ep = lookup_atid(t, atid);
1118
1119 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1120 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1121
Steve Wisea7db89e2014-03-21 20:40:35 +05301122 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001123 dst_confirm(ep->dst);
1124
1125 /* setup the hwtid for this connection */
1126 ep->hwtid = tid;
1127 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001128 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001129
1130 ep->snd_seq = be32_to_cpu(req->snd_isn);
1131 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1132
1133 set_emss(ep, ntohs(req->tcp_opt));
1134
1135 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001136 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001137 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001138 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001139
1140 /* start MPA negotiation */
1141 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301142 if (ep->retry_with_mpa_v1)
1143 send_mpa_req(ep, skb, 1);
1144 else
1145 send_mpa_req(ep, skb, mpa_rev);
Steve Wisea7db89e2014-03-21 20:40:35 +05301146 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001147 return 0;
1148}
1149
Steve Wisebe13b2d2014-03-21 20:40:33 +05301150static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001151{
1152 struct iw_cm_event event;
1153
1154 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1155 memset(&event, 0, sizeof(event));
1156 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301157 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001158 if (ep->com.cm_id) {
1159 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1160 ep, ep->com.cm_id, ep->hwtid);
1161 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1162 ep->com.cm_id->rem_ref(ep->com.cm_id);
1163 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001164 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001165 }
1166}
1167
1168static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
1169{
1170 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecc18b932014-04-24 14:31:53 -05001171 __state_set(&ep->com, ABORTING);
Vipul Pandya793dad92012-12-10 09:30:56 +00001172 set_bit(ABORT_CONN, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001173 return send_abort(ep, skb, gfp);
1174}
1175
1176static void peer_close_upcall(struct c4iw_ep *ep)
1177{
1178 struct iw_cm_event event;
1179
1180 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1181 memset(&event, 0, sizeof(event));
1182 event.event = IW_CM_EVENT_DISCONNECT;
1183 if (ep->com.cm_id) {
1184 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1185 ep, ep->com.cm_id, ep->hwtid);
1186 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001187 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001188 }
1189}
1190
1191static void peer_abort_upcall(struct c4iw_ep *ep)
1192{
1193 struct iw_cm_event event;
1194
1195 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1196 memset(&event, 0, sizeof(event));
1197 event.event = IW_CM_EVENT_CLOSE;
1198 event.status = -ECONNRESET;
1199 if (ep->com.cm_id) {
1200 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1201 ep->com.cm_id, ep->hwtid);
1202 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1203 ep->com.cm_id->rem_ref(ep->com.cm_id);
1204 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001205 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001206 }
1207}
1208
1209static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1210{
1211 struct iw_cm_event event;
1212
1213 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1214 memset(&event, 0, sizeof(event));
1215 event.event = IW_CM_EVENT_CONNECT_REPLY;
1216 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301217 memcpy(&event.local_addr, &ep->com.local_addr,
1218 sizeof(ep->com.local_addr));
1219 memcpy(&event.remote_addr, &ep->com.remote_addr,
1220 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001221
1222 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301223 if (!ep->tried_with_mpa_v1) {
1224 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301225 event.ord = ep->ird;
1226 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301227 event.private_data_len = ep->plen -
1228 sizeof(struct mpa_v2_conn_params);
1229 event.private_data = ep->mpa_pkt +
1230 sizeof(struct mpa_message) +
1231 sizeof(struct mpa_v2_conn_params);
1232 } else {
1233 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301234 event.ord = cur_max_read_depth(ep->com.dev);
1235 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301236 event.private_data_len = ep->plen;
1237 event.private_data = ep->mpa_pkt +
1238 sizeof(struct mpa_message);
1239 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001240 }
Roland Dreier85963e42010-07-19 13:13:09 -07001241
1242 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1243 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001244 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001245 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1246
Steve Wisecfdda9d2010-04-21 15:30:06 -07001247 if (status < 0) {
1248 ep->com.cm_id->rem_ref(ep->com.cm_id);
1249 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001250 }
1251}
1252
Steve Wisebe13b2d2014-03-21 20:40:33 +05301253static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001254{
1255 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301256 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001257
1258 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1259 memset(&event, 0, sizeof(event));
1260 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301261 memcpy(&event.local_addr, &ep->com.local_addr,
1262 sizeof(ep->com.local_addr));
1263 memcpy(&event.remote_addr, &ep->com.remote_addr,
1264 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001265 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301266 if (!ep->tried_with_mpa_v1) {
1267 /* this means MPA_v2 is used */
1268 event.ord = ep->ord;
1269 event.ird = ep->ird;
1270 event.private_data_len = ep->plen -
1271 sizeof(struct mpa_v2_conn_params);
1272 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1273 sizeof(struct mpa_v2_conn_params);
1274 } else {
1275 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301276 event.ord = cur_max_read_depth(ep->com.dev);
1277 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301278 event.private_data_len = ep->plen;
1279 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1280 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301281 c4iw_get_ep(&ep->com);
1282 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1283 &event);
1284 if (ret)
1285 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001286 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001287 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301288 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001289}
1290
1291static void established_upcall(struct c4iw_ep *ep)
1292{
1293 struct iw_cm_event event;
1294
1295 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1296 memset(&event, 0, sizeof(event));
1297 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301298 event.ird = ep->ord;
1299 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001300 if (ep->com.cm_id) {
1301 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1302 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001303 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001304 }
1305}
1306
1307static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1308{
1309 struct cpl_rx_data_ack *req;
1310 struct sk_buff *skb;
1311 int wrlen = roundup(sizeof *req, 16);
1312
1313 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1314 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1315 if (!skb) {
1316 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1317 return 0;
1318 }
1319
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301320 /*
1321 * If we couldn't specify the entire rcv window at connection setup
1322 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1323 * then add the overage in to the credits returned.
1324 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001325 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1326 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301327
Steve Wisecfdda9d2010-04-21 15:30:06 -07001328 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1329 memset(req, 0, wrlen);
1330 INIT_TP_WR(req, ep->hwtid);
1331 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1332 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001333 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301334 RX_DACK_CHANGE_F |
1335 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001336 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001337 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1338 return credits;
1339}
1340
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301341#define RELAXED_IRD_NEGOTIATION 1
1342
Steve Wisecc18b932014-04-24 14:31:53 -05001343static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001344{
1345 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301346 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001347 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301348 u16 resp_ird, resp_ord;
1349 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001350 struct c4iw_qp_attributes attrs;
1351 enum c4iw_qp_attr_mask mask;
1352 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001353 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001354
1355 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1356
1357 /*
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001358 * Stop mpa timer. If it expired, then
1359 * we ignore the MPA reply. process_timeout()
1360 * will abort the connection.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001361 */
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001362 if (stop_ep_timer(ep))
Steve Wisecc18b932014-04-24 14:31:53 -05001363 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001364
1365 /*
1366 * If we get more than the supported amount of private data
1367 * then we must fail this connection.
1368 */
1369 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1370 err = -EINVAL;
1371 goto err;
1372 }
1373
1374 /*
1375 * copy the new data into our accumulation buffer.
1376 */
1377 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1378 skb->len);
1379 ep->mpa_pkt_len += skb->len;
1380
1381 /*
1382 * if we don't even have the mpa message, then bail.
1383 */
1384 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001385 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001386 mpa = (struct mpa_message *) ep->mpa_pkt;
1387
1388 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301389 if (mpa->revision > mpa_rev) {
1390 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1391 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001392 err = -EPROTO;
1393 goto err;
1394 }
1395 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1396 err = -EPROTO;
1397 goto err;
1398 }
1399
1400 plen = ntohs(mpa->private_data_size);
1401
1402 /*
1403 * Fail if there's too much private data.
1404 */
1405 if (plen > MPA_MAX_PRIVATE_DATA) {
1406 err = -EPROTO;
1407 goto err;
1408 }
1409
1410 /*
1411 * If plen does not account for pkt size
1412 */
1413 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1414 err = -EPROTO;
1415 goto err;
1416 }
1417
1418 ep->plen = (u8) plen;
1419
1420 /*
1421 * If we don't have all the pdata yet, then bail.
1422 * We'll continue process when more data arrives.
1423 */
1424 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001425 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001426
1427 if (mpa->flags & MPA_REJECT) {
1428 err = -ECONNREFUSED;
1429 goto err;
1430 }
1431
1432 /*
1433 * If we get here we have accumulated the entire mpa
1434 * start reply message including private data. And
1435 * the MPA header is valid.
1436 */
Steve Wisec529fb52014-03-21 20:40:37 +05301437 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001438 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1439 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1440 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301441 ep->mpa_attr.version = mpa->revision;
1442 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1443
1444 if (mpa->revision == 2) {
1445 ep->mpa_attr.enhanced_rdma_conn =
1446 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1447 if (ep->mpa_attr.enhanced_rdma_conn) {
1448 mpa_v2_params = (struct mpa_v2_conn_params *)
1449 (ep->mpa_pkt + sizeof(*mpa));
1450 resp_ird = ntohs(mpa_v2_params->ird) &
1451 MPA_V2_IRD_ORD_MASK;
1452 resp_ord = ntohs(mpa_v2_params->ord) &
1453 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301454 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1455 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301456
1457 /*
1458 * This is a double-check. Ideally, below checks are
1459 * not required since ird/ord stuff has been taken
1460 * care of in c4iw_accept_cr
1461 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301462 if (ep->ird < resp_ord) {
1463 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1464 ep->com.dev->rdev.lldi.max_ordird_qp)
1465 ep->ird = resp_ord;
1466 else
1467 insuff_ird = 1;
1468 } else if (ep->ird > resp_ord) {
1469 ep->ird = resp_ord;
1470 }
1471 if (ep->ord > resp_ird) {
1472 if (RELAXED_IRD_NEGOTIATION)
1473 ep->ord = resp_ird;
1474 else
1475 insuff_ird = 1;
1476 }
1477 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301478 err = -ENOMEM;
1479 ep->ird = resp_ord;
1480 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301481 }
1482
1483 if (ntohs(mpa_v2_params->ird) &
1484 MPA_V2_PEER2PEER_MODEL) {
1485 if (ntohs(mpa_v2_params->ord) &
1486 MPA_V2_RDMA_WRITE_RTR)
1487 ep->mpa_attr.p2p_type =
1488 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1489 else if (ntohs(mpa_v2_params->ord) &
1490 MPA_V2_RDMA_READ_RTR)
1491 ep->mpa_attr.p2p_type =
1492 FW_RI_INIT_P2PTYPE_READ_REQ;
1493 }
1494 }
1495 } else if (mpa->revision == 1)
1496 if (peer2peer)
1497 ep->mpa_attr.p2p_type = p2p_type;
1498
Steve Wisecfdda9d2010-04-21 15:30:06 -07001499 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301500 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1501 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1502 ep->mpa_attr.recv_marker_enabled,
1503 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1504 ep->mpa_attr.p2p_type, p2p_type);
1505
1506 /*
1507 * If responder's RTR does not match with that of initiator, assign
1508 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1509 * generated when moving QP to RTS state.
1510 * A TERM message will be sent after QP has moved to RTS state
1511 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001512 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301513 (ep->mpa_attr.p2p_type != p2p_type)) {
1514 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1515 rtr_mismatch = 1;
1516 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001517
1518 attrs.mpa_attr = ep->mpa_attr;
1519 attrs.max_ird = ep->ird;
1520 attrs.max_ord = ep->ord;
1521 attrs.llp_stream_handle = ep;
1522 attrs.next_state = C4IW_QP_STATE_RTS;
1523
1524 mask = C4IW_QP_ATTR_NEXT_STATE |
1525 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1526 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1527
1528 /* bind QP and TID with INIT_WR */
1529 err = c4iw_modify_qp(ep->com.qp->rhp,
1530 ep->com.qp, mask, &attrs, 1);
1531 if (err)
1532 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301533
1534 /*
1535 * If responder's RTR requirement did not match with what initiator
1536 * supports, generate TERM message
1537 */
1538 if (rtr_mismatch) {
1539 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1540 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1541 attrs.ecode = MPA_NOMATCH_RTR;
1542 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001543 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301544 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001545 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301546 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001547 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301548 goto out;
1549 }
1550
1551 /*
1552 * Generate TERM if initiator IRD is not sufficient for responder
1553 * provided ORD. Currently, we do the same behaviour even when
1554 * responder provided IRD is also not sufficient as regards to
1555 * initiator ORD.
1556 */
1557 if (insuff_ird) {
1558 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1559 __func__);
1560 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1561 attrs.ecode = MPA_INSUFF_IRD;
1562 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001563 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301564 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001565 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301566 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001567 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301568 goto out;
1569 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001570 goto out;
1571err:
Steve Wisec529fb52014-03-21 20:40:37 +05301572 __state_set(&ep->com, ABORTING);
Steve Wiseb21ef162010-06-10 19:02:55 +00001573 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001574out:
1575 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001576 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001577}
1578
1579static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1580{
1581 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301582 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001583 u16 plen;
1584
1585 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1586
Steve Wisecfdda9d2010-04-21 15:30:06 -07001587 /*
1588 * If we get more than the supported amount of private data
1589 * then we must fail this connection.
1590 */
1591 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001592 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001593 abort_connection(ep, skb, GFP_KERNEL);
1594 return;
1595 }
1596
1597 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1598
1599 /*
1600 * Copy the new data into our accumulation buffer.
1601 */
1602 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1603 skb->len);
1604 ep->mpa_pkt_len += skb->len;
1605
1606 /*
1607 * If we don't even have the mpa message, then bail.
1608 * We'll continue process when more data arrives.
1609 */
1610 if (ep->mpa_pkt_len < sizeof(*mpa))
1611 return;
1612
1613 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001614 mpa = (struct mpa_message *) ep->mpa_pkt;
1615
1616 /*
1617 * Validate MPA Header.
1618 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301619 if (mpa->revision > mpa_rev) {
1620 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1621 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001622 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001623 abort_connection(ep, skb, GFP_KERNEL);
1624 return;
1625 }
1626
1627 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001628 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001629 abort_connection(ep, skb, GFP_KERNEL);
1630 return;
1631 }
1632
1633 plen = ntohs(mpa->private_data_size);
1634
1635 /*
1636 * Fail if there's too much private data.
1637 */
1638 if (plen > MPA_MAX_PRIVATE_DATA) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001639 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001640 abort_connection(ep, skb, GFP_KERNEL);
1641 return;
1642 }
1643
1644 /*
1645 * If plen does not account for pkt size
1646 */
1647 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001648 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001649 abort_connection(ep, skb, GFP_KERNEL);
1650 return;
1651 }
1652 ep->plen = (u8) plen;
1653
1654 /*
1655 * If we don't have all the pdata yet, then bail.
1656 */
1657 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1658 return;
1659
1660 /*
1661 * If we get here we have accumulated the entire mpa
1662 * start reply message including private data.
1663 */
1664 ep->mpa_attr.initiator = 0;
1665 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1666 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1667 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301668 ep->mpa_attr.version = mpa->revision;
1669 if (mpa->revision == 1)
1670 ep->tried_with_mpa_v1 = 1;
1671 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1672
1673 if (mpa->revision == 2) {
1674 ep->mpa_attr.enhanced_rdma_conn =
1675 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1676 if (ep->mpa_attr.enhanced_rdma_conn) {
1677 mpa_v2_params = (struct mpa_v2_conn_params *)
1678 (ep->mpa_pkt + sizeof(*mpa));
1679 ep->ird = ntohs(mpa_v2_params->ird) &
1680 MPA_V2_IRD_ORD_MASK;
1681 ep->ord = ntohs(mpa_v2_params->ord) &
1682 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301683 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1684 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301685 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1686 if (peer2peer) {
1687 if (ntohs(mpa_v2_params->ord) &
1688 MPA_V2_RDMA_WRITE_RTR)
1689 ep->mpa_attr.p2p_type =
1690 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1691 else if (ntohs(mpa_v2_params->ord) &
1692 MPA_V2_RDMA_READ_RTR)
1693 ep->mpa_attr.p2p_type =
1694 FW_RI_INIT_P2PTYPE_READ_REQ;
1695 }
1696 }
1697 } else if (mpa->revision == 1)
1698 if (peer2peer)
1699 ep->mpa_attr.p2p_type = p2p_type;
1700
Steve Wisecfdda9d2010-04-21 15:30:06 -07001701 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1702 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1703 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1704 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1705 ep->mpa_attr.p2p_type);
1706
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001707 /*
1708 * If the endpoint timer already expired, then we ignore
1709 * the start request. process_timeout() will abort
1710 * the connection.
1711 */
1712 if (!stop_ep_timer(ep)) {
1713 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001714
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001715 /* drive upcall */
Hariprasad Shenai10be6b42014-11-21 09:36:35 -06001716 mutex_lock_nested(&ep->parent_ep->com.mutex,
1717 SINGLE_DEPTH_NESTING);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001718 if (ep->parent_ep->com.state != DEAD) {
1719 if (connect_request_upcall(ep))
1720 abort_connection(ep, skb, GFP_KERNEL);
1721 } else {
Steve Wisebe13b2d2014-03-21 20:40:33 +05301722 abort_connection(ep, skb, GFP_KERNEL);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001723 }
1724 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301725 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001726 return;
1727}
1728
1729static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1730{
1731 struct c4iw_ep *ep;
1732 struct cpl_rx_data *hdr = cplhdr(skb);
1733 unsigned int dlen = ntohs(hdr->len);
1734 unsigned int tid = GET_TID(hdr);
1735 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001736 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001737 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001738
1739 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301740 if (!ep)
1741 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001742 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1743 skb_pull(skb, sizeof(*hdr));
1744 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301745 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001746
Steve Wisecfdda9d2010-04-21 15:30:06 -07001747 /* update RX credits */
1748 update_rx_credits(ep, dlen);
1749
Steve Wisec529fb52014-03-21 20:40:37 +05301750 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001751 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001752 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001753 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001754 break;
1755 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001756 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001757 process_mpa_request(ep, skb);
1758 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001759 case FPDU_MODE: {
1760 struct c4iw_qp_attributes attrs;
1761 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001762 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001763 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001764 " qpid %u ep %p state %d tid %u status %d\n",
1765 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301766 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301767 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001768 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001769 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1770 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001771 break;
1772 }
Vipul Pandya15579672013-01-07 13:11:52 +00001773 default:
1774 break;
1775 }
Steve Wisec529fb52014-03-21 20:40:37 +05301776 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001777 if (disconnect)
1778 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001779 return 0;
1780}
1781
1782static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1783{
1784 struct c4iw_ep *ep;
1785 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001786 int release = 0;
1787 unsigned int tid = GET_TID(rpl);
1788 struct tid_info *t = dev->rdev.lldi.tids;
1789
1790 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301791 if (!ep) {
1792 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1793 return 0;
1794 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001795 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001796 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001797 switch (ep->com.state) {
1798 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001799 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001800 __state_set(&ep->com, DEAD);
1801 release = 1;
1802 break;
1803 default:
1804 printk(KERN_ERR "%s ep %p state %d\n",
1805 __func__, ep, ep->com.state);
1806 break;
1807 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001808 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001809
1810 if (release)
1811 release_ep_resources(ep);
1812 return 0;
1813}
1814
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001815static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1816{
1817 struct sk_buff *skb;
1818 struct fw_ofld_connection_wr *req;
1819 unsigned int mtu_idx;
1820 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301821 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301822 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001823
1824 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1825 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1826 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001827 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301828 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301829 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1830 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001831 ep->l2t));
Steve Wise9eccfe12014-03-26 17:08:09 -05001832 sin = (struct sockaddr_in *)&ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301833 req->le.lport = sin->sin_port;
1834 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05001835 sin = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301836 req->le.pport = sin->sin_port;
1837 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001838 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301839 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1840 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001841 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301842 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001843 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001844 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301845 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301846 enable_tcp_timestamps,
1847 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001848 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301849
1850 /*
1851 * Specify the largest window that will fit in opt0. The
1852 * remainder will be specified in the rx_data_ack.
1853 */
1854 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001855 if (win > RCV_BUFSIZ_M)
1856 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301857
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001858 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1859 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001860 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001861 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001862 WND_SCALE_V(wscale) |
1863 MSS_IDX_V(mtu_idx) |
1864 L2T_IDX_V(ep->l2t->idx) |
1865 TX_CHAN_V(ep->tx_chan) |
1866 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001867 DSCP_V(ep->tos) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001868 ULP_MODE_V(ULP_MODE_TCPDDP) |
1869 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001870 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1871 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001872 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001873 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001874 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001875 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001876 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001877 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001878 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001879 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001880 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1881 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1882 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001883 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1884 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001885 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1886}
1887
Steve Wisecfdda9d2010-04-21 15:30:06 -07001888/*
1889 * Return whether a failed active open has allocated a TID
1890 */
1891static inline int act_open_has_tid(int status)
1892{
1893 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1894 status != CPL_ERR_ARP_MISS;
1895}
1896
Steve Wise7a2cea22014-03-14 21:52:07 +05301897/* Returns whether a CPL status conveys negative advice.
1898 */
1899static int is_neg_adv(unsigned int status)
1900{
1901 return status == CPL_ERR_RTX_NEG_ADVICE ||
1902 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1903 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1904}
1905
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301906static char *neg_adv_str(unsigned int status)
1907{
1908 switch (status) {
1909 case CPL_ERR_RTX_NEG_ADVICE:
1910 return "Retransmit timeout";
1911 case CPL_ERR_PERSIST_NEG_ADVICE:
1912 return "Persist timeout";
1913 case CPL_ERR_KEEPALV_NEG_ADVICE:
1914 return "Keepalive timeout";
1915 default:
1916 return "Unknown";
1917 }
1918}
1919
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301920static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1921{
1922 ep->snd_win = snd_win;
1923 ep->rcv_win = rcv_win;
1924 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1925}
1926
Vipul Pandya793dad92012-12-10 09:30:56 +00001927#define ACT_OPEN_RETRY_COUNT 2
1928
Vipul Pandya830662f2013-07-04 16:10:47 +05301929static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1930 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad S963cab52015-09-23 17:19:27 +05301931 bool clear_mpa_v1, enum chip_type adapter_type)
Vipul Pandya830662f2013-07-04 16:10:47 +05301932{
1933 struct neighbour *n;
1934 int err, step;
1935 struct net_device *pdev;
1936
1937 n = dst_neigh_lookup(dst, peer_ip);
1938 if (!n)
1939 return -ENODEV;
1940
1941 rcu_read_lock();
1942 err = -ENOMEM;
1943 if (n->dev->flags & IFF_LOOPBACK) {
1944 if (iptype == 4)
1945 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1946 else if (IS_ENABLED(CONFIG_IPV6))
1947 for_each_netdev(&init_net, pdev) {
1948 if (ipv6_chk_addr(&init_net,
1949 (struct in6_addr *)peer_ip,
1950 pdev, 1))
1951 break;
1952 }
1953 else
1954 pdev = NULL;
1955
1956 if (!pdev) {
1957 err = -ENODEV;
1958 goto out;
1959 }
1960 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1961 n, pdev, 0);
1962 if (!ep->l2t)
1963 goto out;
1964 ep->mtu = pdev->mtu;
1965 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05301966 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
1967 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301968 step = cdev->rdev.lldi.ntxq /
1969 cdev->rdev.lldi.nchan;
1970 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1971 step = cdev->rdev.lldi.nrxq /
1972 cdev->rdev.lldi.nchan;
1973 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1974 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1975 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301976 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301977 dev_put(pdev);
1978 } else {
1979 pdev = get_real_dev(n->dev);
1980 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1981 n, pdev, 0);
1982 if (!ep->l2t)
1983 goto out;
1984 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05001985 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05301986 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
1987 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301988 step = cdev->rdev.lldi.ntxq /
1989 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05001990 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1991 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05301992 step = cdev->rdev.lldi.nrxq /
1993 cdev->rdev.lldi.nchan;
1994 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05001995 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301996 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301997
1998 if (clear_mpa_v1) {
1999 ep->retry_with_mpa_v1 = 0;
2000 ep->tried_with_mpa_v1 = 0;
2001 }
2002 }
2003 err = 0;
2004out:
2005 rcu_read_unlock();
2006
2007 neigh_release(n);
2008
2009 return err;
2010}
2011
Vipul Pandya793dad92012-12-10 09:30:56 +00002012static int c4iw_reconnect(struct c4iw_ep *ep)
2013{
2014 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302015 struct sockaddr_in *laddr = (struct sockaddr_in *)
2016 &ep->com.cm_id->local_addr;
2017 struct sockaddr_in *raddr = (struct sockaddr_in *)
2018 &ep->com.cm_id->remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302019 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
2020 &ep->com.cm_id->local_addr;
2021 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
2022 &ep->com.cm_id->remote_addr;
2023 int iptype;
2024 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002025
2026 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2027 init_timer(&ep->timer);
2028
2029 /*
2030 * Allocate an active TID to initiate a TCP connection.
2031 */
2032 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2033 if (ep->atid == -1) {
2034 pr_err("%s - cannot alloc atid.\n", __func__);
2035 err = -ENOMEM;
2036 goto fail2;
2037 }
2038 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2039
2040 /* find a route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302041 if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
2042 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2043 raddr->sin_addr.s_addr, laddr->sin_port,
2044 raddr->sin_port, 0);
2045 iptype = 4;
2046 ra = (__u8 *)&raddr->sin_addr;
2047 } else {
2048 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2049 raddr6->sin6_addr.s6_addr,
2050 laddr6->sin6_port, raddr6->sin6_port, 0,
2051 raddr6->sin6_scope_id);
2052 iptype = 6;
2053 ra = (__u8 *)&raddr6->sin6_addr;
2054 }
2055 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002056 pr_err("%s - cannot find route.\n", __func__);
2057 err = -EHOSTUNREACH;
2058 goto fail3;
2059 }
Hariprasad S963cab52015-09-23 17:19:27 +05302060 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
2061 ep->com.dev->rdev.lldi.adapter_type);
Vipul Pandya830662f2013-07-04 16:10:47 +05302062 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002063 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002064 goto fail4;
2065 }
2066
2067 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2068 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2069 ep->l2t->idx);
2070
2071 state_set(&ep->com, CONNECTING);
2072 ep->tos = 0;
2073
2074 /* send connect request to rnic */
2075 err = send_connect(ep);
2076 if (!err)
2077 goto out;
2078
2079 cxgb4_l2t_release(ep->l2t);
2080fail4:
2081 dst_release(ep->dst);
2082fail3:
2083 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2084 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2085fail2:
2086 /*
2087 * remember to send notification to upper layer.
2088 * We are in here so the upper layer is not aware that this is
2089 * re-connect attempt and so, upper layer is still waiting for
2090 * response of 1st connect request.
2091 */
2092 connect_reply_upcall(ep, -ECONNRESET);
2093 c4iw_put_ep(&ep->com);
2094out:
2095 return err;
2096}
2097
Steve Wisecfdda9d2010-04-21 15:30:06 -07002098static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2099{
2100 struct c4iw_ep *ep;
2101 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002102 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2103 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002104 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002105 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302106 struct sockaddr_in *la;
2107 struct sockaddr_in *ra;
2108 struct sockaddr_in6 *la6;
2109 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002110
2111 ep = lookup_atid(t, atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05002112 la = (struct sockaddr_in *)&ep->com.mapped_local_addr;
2113 ra = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
2114 la6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
2115 ra6 = (struct sockaddr_in6 *)&ep->com.mapped_remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002116
2117 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2118 status, status2errno(status));
2119
Steve Wise7a2cea22014-03-14 21:52:07 +05302120 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302121 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2122 __func__, atid, status, neg_adv_str(status));
2123 ep->stats.connect_neg_adv++;
2124 mutex_lock(&dev->rdev.stats.lock);
2125 dev->rdev.stats.neg_adv++;
2126 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002127 return 0;
2128 }
2129
Vipul Pandya793dad92012-12-10 09:30:56 +00002130 set_bit(ACT_OPEN_RPL, &ep->com.history);
2131
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302132 /*
2133 * Log interesting failures.
2134 */
2135 switch (status) {
2136 case CPL_ERR_CONN_RESET:
2137 case CPL_ERR_CONN_TIMEDOUT:
2138 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002139 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302140 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002141 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302142 mutex_unlock(&dev->rdev.stats.lock);
2143 if (ep->com.local_addr.ss_family == AF_INET &&
2144 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002145 send_fw_act_open_req(ep,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002146 TID_TID_G(AOPEN_ATID_G(
Vipul Pandya793dad92012-12-10 09:30:56 +00002147 ntohl(rpl->atid_status))));
2148 return 0;
2149 }
2150 break;
2151 case CPL_ERR_CONN_EXIST:
2152 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2153 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302154 if (ep->com.remote_addr.ss_family == AF_INET6) {
2155 struct sockaddr_in6 *sin6 =
2156 (struct sockaddr_in6 *)
2157 &ep->com.mapped_local_addr;
2158 cxgb4_clip_release(
2159 ep->com.dev->rdev.lldi.ports[0],
2160 (const u32 *)
2161 &sin6->sin6_addr.s6_addr, 1);
2162 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002163 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2164 atid);
2165 cxgb4_free_atid(t, atid);
2166 dst_release(ep->dst);
2167 cxgb4_l2t_release(ep->l2t);
2168 c4iw_reconnect(ep);
2169 return 0;
2170 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002171 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302172 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302173 if (ep->com.local_addr.ss_family == AF_INET) {
2174 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2175 atid, status, status2errno(status),
2176 &la->sin_addr.s_addr, ntohs(la->sin_port),
2177 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2178 } else {
2179 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2180 atid, status, status2errno(status),
2181 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2182 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2183 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302184 break;
2185 }
2186
Steve Wisecfdda9d2010-04-21 15:30:06 -07002187 connect_reply_upcall(ep, status2errno(status));
2188 state_set(&ep->com, DEAD);
2189
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302190 if (ep->com.remote_addr.ss_family == AF_INET6) {
2191 struct sockaddr_in6 *sin6 =
2192 (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
2193 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2194 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2195 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002196 if (status && act_open_has_tid(status))
2197 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2198
Vipul Pandya793dad92012-12-10 09:30:56 +00002199 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002200 cxgb4_free_atid(t, atid);
2201 dst_release(ep->dst);
2202 cxgb4_l2t_release(ep->l2t);
2203 c4iw_put_ep(&ep->com);
2204
2205 return 0;
2206}
2207
2208static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2209{
2210 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2211 struct tid_info *t = dev->rdev.lldi.tids;
2212 unsigned int stid = GET_TID(rpl);
2213 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2214
2215 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002216 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2217 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002218 }
2219 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2220 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002221 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002222
Vipul Pandya1cab7752012-12-10 09:30:55 +00002223out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002224 return 0;
2225}
2226
Steve Wisecfdda9d2010-04-21 15:30:06 -07002227static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2228{
2229 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2230 struct tid_info *t = dev->rdev.lldi.tids;
2231 unsigned int stid = GET_TID(rpl);
2232 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2233
2234 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002235 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002236 return 0;
2237}
2238
Vipul Pandya830662f2013-07-04 16:10:47 +05302239static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002240 struct cpl_pass_accept_req *req)
2241{
2242 struct cpl_pass_accept_rpl *rpl;
2243 unsigned int mtu_idx;
2244 u64 opt0;
2245 u32 opt2;
2246 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302247 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302248 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302249 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002250
2251 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2252 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302253
Steve Wisecfdda9d2010-04-21 15:30:06 -07002254 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302255 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302256 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302257 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2258 rpl5 = (void *)rpl;
2259 INIT_TP_WR(rpl5, ep->hwtid);
2260 } else {
2261 skb_trim(skb, sizeof(*rpl));
2262 INIT_TP_WR(rpl, ep->hwtid);
2263 }
2264 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2265 ep->hwtid));
2266
2267 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302268 enable_tcp_timestamps && req->tcpopt.tstamp,
2269 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002270 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302271
2272 /*
2273 * Specify the largest window that will fit in opt0. The
2274 * remainder will be specified in the rx_data_ack.
2275 */
2276 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002277 if (win > RCV_BUFSIZ_M)
2278 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002279 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002280 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002281 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002282 WND_SCALE_V(wscale) |
2283 MSS_IDX_V(mtu_idx) |
2284 L2T_IDX_V(ep->l2t->idx) |
2285 TX_CHAN_V(ep->tx_chan) |
2286 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002287 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002288 ULP_MODE_V(ULP_MODE_TCPDDP) |
2289 RCV_BUFSIZ_V(win);
2290 opt2 = RX_CHANNEL_V(0) |
2291 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002292
2293 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002294 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002295 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002296 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002297 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002298 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002299 if (enable_ecn) {
2300 const struct tcphdr *tcph;
2301 u32 hlen = ntohl(req->hdr_len);
2302
Hariprasad S963cab52015-09-23 17:19:27 +05302303 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2304 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2305 IP_HDR_LEN_G(hlen);
2306 else
2307 tcph = (const void *)(req + 1) +
2308 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002309 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002310 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002311 }
Hariprasad S963cab52015-09-23 17:19:27 +05302312 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302313 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002314 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302315 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302316 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302317 rpl5 = (void *)rpl;
2318 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2319 if (peer2peer)
2320 isn += 4;
2321 rpl5->iss = cpu_to_be32(isn);
2322 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002323 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002324
Steve Wisecfdda9d2010-04-21 15:30:06 -07002325 rpl->opt0 = cpu_to_be64(opt0);
2326 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002327 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wiseb38a0ad2013-08-06 21:04:37 +05302328 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002329 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2330
2331 return;
2332}
2333
Vipul Pandya830662f2013-07-04 16:10:47 +05302334static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002335{
Vipul Pandya830662f2013-07-04 16:10:47 +05302336 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002337 BUG_ON(skb_cloned(skb));
2338 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002339 release_tid(&dev->rdev, hwtid, skb);
2340 return;
2341}
2342
Hariprasad S963cab52015-09-23 17:19:27 +05302343static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2344 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002345 __be16 *local_port, __be16 *peer_port)
2346{
Hariprasad S963cab52015-09-23 17:19:27 +05302347 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2348 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2349 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2350 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2351 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2352 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002353 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302354 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002355 struct tcphdr *tcp = (struct tcphdr *)
2356 ((u8 *)(req + 1) + eth_len + ip_len);
2357
Vipul Pandya830662f2013-07-04 16:10:47 +05302358 if (ip->version == 4) {
2359 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2360 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2361 ntohs(tcp->dest));
2362 *iptype = 4;
2363 memcpy(peer_ip, &ip->saddr, 4);
2364 memcpy(local_ip, &ip->daddr, 4);
2365 } else {
2366 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2367 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2368 ntohs(tcp->dest));
2369 *iptype = 6;
2370 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2371 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2372 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002373 *peer_port = tcp->source;
2374 *local_port = tcp->dest;
2375
2376 return;
2377}
2378
2379static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2380{
Vipul Pandya793dad92012-12-10 09:30:56 +00002381 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002382 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002383 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002384 struct tid_info *t = dev->rdev.lldi.tids;
2385 unsigned int hwtid = GET_TID(req);
2386 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302387 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002388 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302389 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002390 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002391 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302392 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302393 unsigned short hdrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002394
2395 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002396 if (!parent_ep) {
2397 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2398 goto reject;
2399 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002400
Steve Wisecfdda9d2010-04-21 15:30:06 -07002401 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad Shenai6102c662016-02-05 11:43:29 +05302402 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002403 goto reject;
2404 }
2405
Hariprasad S963cab52015-09-23 17:19:27 +05302406 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2407 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302408
Steve Wisecfdda9d2010-04-21 15:30:06 -07002409 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302410 if (iptype == 4) {
2411 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2412 , __func__, parent_ep, hwtid,
2413 local_ip, peer_ip, ntohs(local_port),
2414 ntohs(peer_port), peer_mss);
2415 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2416 local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002417 PASS_OPEN_TOS_G(ntohl(req->tos_stid)));
Vipul Pandya830662f2013-07-04 16:10:47 +05302418 } else {
2419 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2420 , __func__, parent_ep, hwtid,
2421 local_ip, peer_ip, ntohs(local_port),
2422 ntohs(peer_port), peer_mss);
2423 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002424 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302425 ((struct sockaddr_in6 *)
2426 &parent_ep->com.local_addr)->sin6_scope_id);
2427 }
2428 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002429 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2430 __func__);
2431 goto reject;
2432 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002433
2434 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2435 if (!child_ep) {
2436 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2437 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002438 dst_release(dst);
2439 goto reject;
2440 }
David Miller3786cf12011-12-02 16:52:31 +00002441
Hariprasad S963cab52015-09-23 17:19:27 +05302442 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
2443 parent_ep->com.dev->rdev.lldi.adapter_type);
David Miller3786cf12011-12-02 16:52:31 +00002444 if (err) {
2445 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2446 __func__);
2447 dst_release(dst);
2448 kfree(child_ep);
2449 goto reject;
2450 }
2451
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302452 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2453 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2454 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2455 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002456
Steve Wisecfdda9d2010-04-21 15:30:06 -07002457 state_set(&child_ep->com, CONNECTING);
2458 child_ep->com.dev = dev;
2459 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002460
2461 /*
2462 * The mapped_local and mapped_remote addresses get setup with
2463 * the actual 4-tuple. The local address will be based on the
2464 * actual local address of the connection, but on the port number
2465 * of the parent listening endpoint. The remote address is
2466 * setup based on a query to the IWPM since we don't know what it
2467 * originally was before mapping. If no mapping was done, then
2468 * mapped_remote == remote, and mapped_local == local.
2469 */
Vipul Pandya830662f2013-07-04 16:10:47 +05302470 if (iptype == 4) {
2471 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002472 &child_ep->com.mapped_local_addr;
2473
Vipul Pandya830662f2013-07-04 16:10:47 +05302474 sin->sin_family = PF_INET;
2475 sin->sin_port = local_port;
2476 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002477
2478 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2479 sin->sin_family = PF_INET;
2480 sin->sin_port = ((struct sockaddr_in *)
2481 &parent_ep->com.local_addr)->sin_port;
2482 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2483
2484 sin = (struct sockaddr_in *)&child_ep->com.mapped_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302485 sin->sin_family = PF_INET;
2486 sin->sin_port = peer_port;
2487 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2488 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302489 sin6 = (struct sockaddr_in6 *)&child_ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302490 sin6->sin6_family = PF_INET6;
2491 sin6->sin6_port = local_port;
2492 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002493
2494 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2495 sin6->sin6_family = PF_INET6;
2496 sin6->sin6_port = ((struct sockaddr_in6 *)
2497 &parent_ep->com.local_addr)->sin6_port;
2498 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2499
2500 sin6 = (struct sockaddr_in6 *)&child_ep->com.mapped_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302501 sin6->sin6_family = PF_INET6;
2502 sin6->sin6_port = peer_port;
2503 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2504 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002505 memcpy(&child_ep->com.remote_addr, &child_ep->com.mapped_remote_addr,
2506 sizeof(child_ep->com.remote_addr));
Steve Wise940fd302015-05-07 16:34:23 -05002507 get_remote_addr(parent_ep, child_ep);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002508
Steve Wisecfdda9d2010-04-21 15:30:06 -07002509 c4iw_get_ep(&parent_ep->com);
2510 child_ep->parent_ep = parent_ep;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002511 child_ep->tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002512 child_ep->dst = dst;
2513 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002514
2515 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002516 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002517
2518 init_timer(&child_ep->timer);
2519 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002520 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Vipul Pandya830662f2013-07-04 16:10:47 +05302521 accept_cr(child_ep, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00002522 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302523 if (iptype == 6) {
2524 sin6 = (struct sockaddr_in6 *)&child_ep->com.mapped_local_addr;
2525 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2526 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2527 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002528 goto out;
2529reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302530 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002531out:
2532 return 0;
2533}
2534
2535static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2536{
2537 struct c4iw_ep *ep;
2538 struct cpl_pass_establish *req = cplhdr(skb);
2539 struct tid_info *t = dev->rdev.lldi.tids;
2540 unsigned int tid = GET_TID(req);
2541
2542 ep = lookup_tid(t, tid);
2543 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2544 ep->snd_seq = be32_to_cpu(req->snd_isn);
2545 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2546
Vipul Pandya1cab7752012-12-10 09:30:55 +00002547 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2548 ntohs(req->tcp_opt));
2549
Steve Wisecfdda9d2010-04-21 15:30:06 -07002550 set_emss(ep, ntohs(req->tcp_opt));
2551
2552 dst_confirm(ep->dst);
2553 state_set(&ep->com, MPA_REQ_WAIT);
2554 start_ep_timer(ep);
2555 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002556 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002557
2558 return 0;
2559}
2560
2561static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2562{
2563 struct cpl_peer_close *hdr = cplhdr(skb);
2564 struct c4iw_ep *ep;
2565 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002566 int disconnect = 1;
2567 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002568 struct tid_info *t = dev->rdev.lldi.tids;
2569 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002570 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002571
2572 ep = lookup_tid(t, tid);
2573 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2574 dst_confirm(ep->dst);
2575
Vipul Pandya793dad92012-12-10 09:30:56 +00002576 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002577 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002578 switch (ep->com.state) {
2579 case MPA_REQ_WAIT:
2580 __state_set(&ep->com, CLOSING);
2581 break;
2582 case MPA_REQ_SENT:
2583 __state_set(&ep->com, CLOSING);
2584 connect_reply_upcall(ep, -ECONNRESET);
2585 break;
2586 case MPA_REQ_RCVD:
2587
2588 /*
2589 * We're gonna mark this puppy DEAD, but keep
2590 * the reference on it until the ULP accepts or
2591 * rejects the CR. Also wake up anyone waiting
2592 * in rdma connection migration (see c4iw_accept_cr()).
2593 */
2594 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002595 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002596 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002597 break;
2598 case MPA_REP_SENT:
2599 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002600 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002601 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002602 break;
2603 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002604 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002605 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002606 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002607 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002608 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002609 if (ret != -ECONNRESET) {
2610 peer_close_upcall(ep);
2611 disconnect = 1;
2612 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002613 break;
2614 case ABORTING:
2615 disconnect = 0;
2616 break;
2617 case CLOSING:
2618 __state_set(&ep->com, MORIBUND);
2619 disconnect = 0;
2620 break;
2621 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002622 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002623 if (ep->com.cm_id && ep->com.qp) {
2624 attrs.next_state = C4IW_QP_STATE_IDLE;
2625 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2626 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2627 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302628 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002629 __state_set(&ep->com, DEAD);
2630 release = 1;
2631 disconnect = 0;
2632 break;
2633 case DEAD:
2634 disconnect = 0;
2635 break;
2636 default:
2637 BUG_ON(1);
2638 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002639 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002640 if (disconnect)
2641 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2642 if (release)
2643 release_ep_resources(ep);
2644 return 0;
2645}
2646
Steve Wisecfdda9d2010-04-21 15:30:06 -07002647static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2648{
2649 struct cpl_abort_req_rss *req = cplhdr(skb);
2650 struct c4iw_ep *ep;
2651 struct cpl_abort_rpl *rpl;
2652 struct sk_buff *rpl_skb;
2653 struct c4iw_qp_attributes attrs;
2654 int ret;
2655 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002656 struct tid_info *t = dev->rdev.lldi.tids;
2657 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002658
2659 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302660 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302661 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2662 __func__, ep->hwtid, req->status,
2663 neg_adv_str(req->status));
2664 ep->stats.abort_neg_adv++;
2665 mutex_lock(&dev->rdev.stats.lock);
2666 dev->rdev.stats.neg_adv++;
2667 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002668 return 0;
2669 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002670 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2671 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002672 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002673
2674 /*
2675 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302676 * However, this is not needed if com state is just
2677 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002678 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302679 if (ep->com.state != MPA_REQ_SENT)
2680 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002681
2682 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002683 switch (ep->com.state) {
2684 case CONNECTING:
2685 break;
2686 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002687 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002688 break;
2689 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002690 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002691 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302692 connect_reply_upcall(ep, -ECONNRESET);
2693 else {
2694 /*
2695 * we just don't send notification upwards because we
2696 * want to retry with mpa_v1 without upper layers even
2697 * knowing it.
2698 *
2699 * do some housekeeping so as to re-initiate the
2700 * connection
2701 */
2702 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2703 mpa_rev);
2704 ep->retry_with_mpa_v1 = 1;
2705 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002706 break;
2707 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002708 break;
2709 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002710 break;
2711 case MORIBUND:
2712 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002713 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002714 /*FALLTHROUGH*/
2715 case FPDU_MODE:
2716 if (ep->com.cm_id && ep->com.qp) {
2717 attrs.next_state = C4IW_QP_STATE_ERROR;
2718 ret = c4iw_modify_qp(ep->com.qp->rhp,
2719 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2720 &attrs, 1);
2721 if (ret)
2722 printk(KERN_ERR MOD
2723 "%s - qp <- error failed!\n",
2724 __func__);
2725 }
2726 peer_abort_upcall(ep);
2727 break;
2728 case ABORTING:
2729 break;
2730 case DEAD:
2731 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002732 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002733 return 0;
2734 default:
2735 BUG_ON(1);
2736 break;
2737 }
2738 dst_confirm(ep->dst);
2739 if (ep->com.state != ABORTING) {
2740 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302741 /* we don't release if we want to retry with mpa_v1 */
2742 if (!ep->retry_with_mpa_v1)
2743 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002744 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002745 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002746
2747 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2748 if (!rpl_skb) {
2749 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2750 __func__);
2751 release = 1;
2752 goto out;
2753 }
2754 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2755 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2756 INIT_TP_WR(rpl, ep->hwtid);
2757 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2758 rpl->cmd = CPL_ABORT_NO_RST;
2759 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2760out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002761 if (release)
2762 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002763 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302764 if (ep->com.remote_addr.ss_family == AF_INET6) {
2765 struct sockaddr_in6 *sin6 =
2766 (struct sockaddr_in6 *)
2767 &ep->com.mapped_local_addr;
2768 cxgb4_clip_release(
2769 ep->com.dev->rdev.lldi.ports[0],
2770 (const u32 *)&sin6->sin6_addr.s6_addr,
2771 1);
2772 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002773 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302774 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2775 dst_release(ep->dst);
2776 cxgb4_l2t_release(ep->l2t);
2777 c4iw_reconnect(ep);
2778 }
2779
Steve Wisecfdda9d2010-04-21 15:30:06 -07002780 return 0;
2781}
2782
2783static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2784{
2785 struct c4iw_ep *ep;
2786 struct c4iw_qp_attributes attrs;
2787 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002788 int release = 0;
2789 struct tid_info *t = dev->rdev.lldi.tids;
2790 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002791
2792 ep = lookup_tid(t, tid);
2793
2794 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2795 BUG_ON(!ep);
2796
2797 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002798 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002799 switch (ep->com.state) {
2800 case CLOSING:
2801 __state_set(&ep->com, MORIBUND);
2802 break;
2803 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002804 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002805 if ((ep->com.cm_id) && (ep->com.qp)) {
2806 attrs.next_state = C4IW_QP_STATE_IDLE;
2807 c4iw_modify_qp(ep->com.qp->rhp,
2808 ep->com.qp,
2809 C4IW_QP_ATTR_NEXT_STATE,
2810 &attrs, 1);
2811 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302812 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002813 __state_set(&ep->com, DEAD);
2814 release = 1;
2815 break;
2816 case ABORTING:
2817 case DEAD:
2818 break;
2819 default:
2820 BUG_ON(1);
2821 break;
2822 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002823 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002824 if (release)
2825 release_ep_resources(ep);
2826 return 0;
2827}
2828
2829static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2830{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002831 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002832 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002833 unsigned int tid = GET_TID(rpl);
2834 struct c4iw_ep *ep;
2835 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002836
2837 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002838 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002839
Steve Wise30c95c22011-05-09 22:06:22 -07002840 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002841 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2842 ep->com.qp->wq.sq.qid);
2843 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2844 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2845 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2846 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002847 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002848
Steve Wisecfdda9d2010-04-21 15:30:06 -07002849 return 0;
2850}
2851
2852/*
2853 * Upcall from the adapter indicating data has been transmitted.
2854 * For us its just the single MPA request or reply. We can now free
2855 * the skb holding the mpa message.
2856 */
2857static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2858{
2859 struct c4iw_ep *ep;
2860 struct cpl_fw4_ack *hdr = cplhdr(skb);
2861 u8 credits = hdr->credits;
2862 unsigned int tid = GET_TID(hdr);
2863 struct tid_info *t = dev->rdev.lldi.tids;
2864
2865
2866 ep = lookup_tid(t, tid);
2867 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2868 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002869 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2870 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002871 return 0;
2872 }
2873
2874 dst_confirm(ep->dst);
2875 if (ep->mpa_skb) {
2876 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2877 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2878 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2879 kfree_skb(ep->mpa_skb);
2880 ep->mpa_skb = NULL;
2881 }
2882 return 0;
2883}
2884
Steve Wisecfdda9d2010-04-21 15:30:06 -07002885int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2886{
Steve Wisea7db89e2014-03-21 20:40:35 +05302887 int err = 0;
2888 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002889 struct c4iw_ep *ep = to_ep(cm_id);
2890 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2891
Steve Wisea7db89e2014-03-21 20:40:35 +05302892 mutex_lock(&ep->com.mutex);
2893 if (ep->com.state == DEAD) {
2894 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002895 c4iw_put_ep(&ep->com);
2896 return -ECONNRESET;
2897 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002898 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302899 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002900 if (mpa_rev == 0)
2901 abort_connection(ep, NULL, GFP_KERNEL);
2902 else {
2903 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302904 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002905 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302906 mutex_unlock(&ep->com.mutex);
2907 if (disconnect)
2908 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002909 c4iw_put_ep(&ep->com);
2910 return 0;
2911}
2912
2913int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2914{
2915 int err;
2916 struct c4iw_qp_attributes attrs;
2917 enum c4iw_qp_attr_mask mask;
2918 struct c4iw_ep *ep = to_ep(cm_id);
2919 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2920 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2921
2922 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302923
2924 mutex_lock(&ep->com.mutex);
2925 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002926 err = -ECONNRESET;
2927 goto err;
2928 }
2929
Steve Wisea7db89e2014-03-21 20:40:35 +05302930 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002931 BUG_ON(!qp);
2932
Vipul Pandya793dad92012-12-10 09:30:56 +00002933 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302934 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2935 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002936 abort_connection(ep, NULL, GFP_KERNEL);
2937 err = -EINVAL;
2938 goto err;
2939 }
2940
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302941 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2942 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302943 if (RELAXED_IRD_NEGOTIATION) {
2944 ep->ord = ep->ird;
2945 } else {
2946 ep->ird = conn_param->ird;
2947 ep->ord = conn_param->ord;
2948 send_mpa_reject(ep, conn_param->private_data,
2949 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302950 abort_connection(ep, NULL, GFP_KERNEL);
2951 err = -ENOMEM;
2952 goto err;
2953 }
2954 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302955 if (conn_param->ird < ep->ord) {
2956 if (RELAXED_IRD_NEGOTIATION &&
2957 ep->ord <= h->rdev.lldi.max_ordird_qp) {
2958 conn_param->ird = ep->ord;
2959 } else {
2960 abort_connection(ep, NULL, GFP_KERNEL);
2961 err = -ENOMEM;
2962 goto err;
2963 }
2964 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302965 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002966 ep->ird = conn_param->ird;
2967 ep->ord = conn_param->ord;
2968
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302969 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302970 if (peer2peer && ep->ird == 0)
2971 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302972 } else {
2973 if (peer2peer &&
2974 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05302975 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302976 ep->ird = 1;
2977 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002978
2979 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2980
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302981 cm_id->add_ref(cm_id);
2982 ep->com.cm_id = cm_id;
2983 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00002984 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302985
Steve Wisecfdda9d2010-04-21 15:30:06 -07002986 /* bind QP to EP and move to RTS */
2987 attrs.mpa_attr = ep->mpa_attr;
2988 attrs.max_ird = ep->ird;
2989 attrs.max_ord = ep->ord;
2990 attrs.llp_stream_handle = ep;
2991 attrs.next_state = C4IW_QP_STATE_RTS;
2992
2993 /* bind QP and TID with INIT_WR */
2994 mask = C4IW_QP_ATTR_NEXT_STATE |
2995 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2996 C4IW_QP_ATTR_MPA_ATTR |
2997 C4IW_QP_ATTR_MAX_IRD |
2998 C4IW_QP_ATTR_MAX_ORD;
2999
3000 err = c4iw_modify_qp(ep->com.qp->rhp,
3001 ep->com.qp, mask, &attrs, 1);
3002 if (err)
3003 goto err1;
3004 err = send_mpa_reply(ep, conn_param->private_data,
3005 conn_param->private_data_len);
3006 if (err)
3007 goto err1;
3008
Steve Wisea7db89e2014-03-21 20:40:35 +05303009 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003010 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303011 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003012 c4iw_put_ep(&ep->com);
3013 return 0;
3014err1:
3015 ep->com.cm_id = NULL;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303016 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003017 cm_id->rem_ref(cm_id);
3018err:
Steve Wisea7db89e2014-03-21 20:40:35 +05303019 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003020 c4iw_put_ep(&ep->com);
3021 return err;
3022}
3023
Vipul Pandya830662f2013-07-04 16:10:47 +05303024static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3025{
3026 struct in_device *ind;
3027 int found = 0;
3028 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
3029 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
3030
3031 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3032 if (!ind)
3033 return -EADDRNOTAVAIL;
3034 for_primary_ifa(ind) {
3035 laddr->sin_addr.s_addr = ifa->ifa_address;
3036 raddr->sin_addr.s_addr = ifa->ifa_address;
3037 found = 1;
3038 break;
3039 }
3040 endfor_ifa(ind);
3041 in_dev_put(ind);
3042 return found ? 0 : -EADDRNOTAVAIL;
3043}
3044
3045static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3046 unsigned char banned_flags)
3047{
3048 struct inet6_dev *idev;
3049 int err = -EADDRNOTAVAIL;
3050
3051 rcu_read_lock();
3052 idev = __in6_dev_get(dev);
3053 if (idev != NULL) {
3054 struct inet6_ifaddr *ifp;
3055
3056 read_lock_bh(&idev->lock);
3057 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3058 if (ifp->scope == IFA_LINK &&
3059 !(ifp->flags & banned_flags)) {
3060 memcpy(addr, &ifp->addr, 16);
3061 err = 0;
3062 break;
3063 }
3064 }
3065 read_unlock_bh(&idev->lock);
3066 }
3067 rcu_read_unlock();
3068 return err;
3069}
3070
3071static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3072{
3073 struct in6_addr uninitialized_var(addr);
3074 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
3075 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
3076
Nicholas Krause54b9a962015-08-26 23:00:59 -04003077 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303078 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3079 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3080 return 0;
3081 }
3082 return -EADDRNOTAVAIL;
3083}
3084
Steve Wisecfdda9d2010-04-21 15:30:06 -07003085int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3086{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003087 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3088 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003089 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003090 struct sockaddr_in *laddr;
3091 struct sockaddr_in *raddr;
3092 struct sockaddr_in6 *laddr6;
3093 struct sockaddr_in6 *raddr6;
3094 struct iwpm_dev_data pm_reg_msg;
3095 struct iwpm_sa_data pm_msg;
Vipul Pandya830662f2013-07-04 16:10:47 +05303096 __u8 *ra;
3097 int iptype;
Steve Wise9eccfe12014-03-26 17:08:09 -05003098 int iwpm_err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003099
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303100 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3101 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003102 err = -EINVAL;
3103 goto out;
3104 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003105 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3106 if (!ep) {
3107 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3108 err = -ENOMEM;
3109 goto out;
3110 }
3111 init_timer(&ep->timer);
3112 ep->plen = conn_param->private_data_len;
3113 if (ep->plen)
3114 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3115 conn_param->private_data, ep->plen);
3116 ep->ird = conn_param->ird;
3117 ep->ord = conn_param->ord;
3118
3119 if (peer2peer && ep->ord == 0)
3120 ep->ord = 1;
3121
3122 cm_id->add_ref(cm_id);
3123 ep->com.dev = dev;
3124 ep->com.cm_id = cm_id;
3125 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303126 if (!ep->com.qp) {
3127 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3128 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003129 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303130 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003131 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003132 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3133 ep->com.qp, cm_id);
3134
3135 /*
3136 * Allocate an active TID to initiate a TCP connection.
3137 */
3138 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3139 if (ep->atid == -1) {
3140 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3141 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003142 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003143 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003144 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003145
Steve Wise9eccfe12014-03-26 17:08:09 -05003146 memcpy(&ep->com.local_addr, &cm_id->local_addr,
3147 sizeof(ep->com.local_addr));
3148 memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
3149 sizeof(ep->com.remote_addr));
3150
3151 /* No port mapper available, go with the specified peer information */
3152 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3153 sizeof(ep->com.mapped_local_addr));
3154 memcpy(&ep->com.mapped_remote_addr, &cm_id->remote_addr,
3155 sizeof(ep->com.mapped_remote_addr));
3156
3157 c4iw_form_reg_msg(dev, &pm_reg_msg);
3158 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3159 if (iwpm_err) {
3160 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3161 __func__, iwpm_err);
3162 }
3163 if (iwpm_valid_pid() && !iwpm_err) {
3164 c4iw_form_pm_msg(ep, &pm_msg);
3165 iwpm_err = iwpm_add_and_query_mapping(&pm_msg, RDMA_NL_C4IW);
3166 if (iwpm_err)
3167 PDBG("%s: Port Mapper query fail (err = %d).\n",
3168 __func__, iwpm_err);
3169 else
3170 c4iw_record_pm_msg(ep, &pm_msg);
3171 }
3172 if (iwpm_create_mapinfo(&ep->com.local_addr,
3173 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3174 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
3175 err = -ENOMEM;
3176 goto fail1;
3177 }
3178 print_addr(&ep->com, __func__, "add_query/create_mapinfo");
3179 set_bit(RELEASE_MAPINFO, &ep->com.flags);
3180
3181 laddr = (struct sockaddr_in *)&ep->com.mapped_local_addr;
3182 raddr = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
3183 laddr6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
3184 raddr6 = (struct sockaddr_in6 *) &ep->com.mapped_remote_addr;
3185
Vipul Pandya830662f2013-07-04 16:10:47 +05303186 if (cm_id->remote_addr.ss_family == AF_INET) {
3187 iptype = 4;
3188 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003189
Vipul Pandya830662f2013-07-04 16:10:47 +05303190 /*
3191 * Handle loopback requests to INADDR_ANY.
3192 */
3193 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3194 err = pick_local_ipaddrs(dev, cm_id);
3195 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003196 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303197 }
3198
3199 /* find a route */
3200 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3201 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3202 ra, ntohs(raddr->sin_port));
3203 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3204 raddr->sin_addr.s_addr, laddr->sin_port,
3205 raddr->sin_port, 0);
3206 } else {
3207 iptype = 6;
3208 ra = (__u8 *)&raddr6->sin6_addr;
3209
3210 /*
3211 * Handle loopback requests to INADDR_ANY.
3212 */
3213 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3214 err = pick_local_ip6addrs(dev, cm_id);
3215 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003216 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303217 }
3218
3219 /* find a route */
3220 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3221 __func__, laddr6->sin6_addr.s6_addr,
3222 ntohs(laddr6->sin6_port),
3223 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3224 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3225 raddr6->sin6_addr.s6_addr,
3226 laddr6->sin6_port, raddr6->sin6_port, 0,
3227 raddr6->sin6_scope_id);
3228 }
3229 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003230 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3231 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003232 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003233 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003234
Hariprasad S963cab52015-09-23 17:19:27 +05303235 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
3236 ep->com.dev->rdev.lldi.adapter_type);
David Miller3786cf12011-12-02 16:52:31 +00003237 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003238 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003239 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003240 }
3241
3242 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3243 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3244 ep->l2t->idx);
3245
3246 state_set(&ep->com, CONNECTING);
3247 ep->tos = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003248
3249 /* send connect request to rnic */
3250 err = send_connect(ep);
3251 if (!err)
3252 goto out;
3253
3254 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003255fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003256 dst_release(ep->dst);
3257fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003258 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003259 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003260fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003261 cm_id->rem_ref(cm_id);
3262 c4iw_put_ep(&ep->com);
3263out:
3264 return err;
3265}
3266
Vipul Pandya830662f2013-07-04 16:10:47 +05303267static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3268{
3269 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003270 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
3271 &ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303272
Hariprasad S28de1f72016-01-13 10:03:14 +05303273 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3274 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3275 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3276 if (err)
3277 return err;
3278 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303279 c4iw_init_wr_wait(&ep->com.wr_wait);
3280 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3281 ep->stid, &sin6->sin6_addr,
3282 sin6->sin6_port,
3283 ep->com.dev->rdev.lldi.rxq_ids[0]);
3284 if (!err)
3285 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3286 &ep->com.wr_wait,
3287 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303288 else if (err > 0)
3289 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303290 if (err) {
3291 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3292 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303293 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3294 err, ep->stid,
3295 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303296 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303297 return err;
3298}
3299
3300static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3301{
3302 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003303 struct sockaddr_in *sin = (struct sockaddr_in *)
3304 &ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303305
3306 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3307 do {
3308 err = cxgb4_create_server_filter(
3309 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3310 sin->sin_addr.s_addr, sin->sin_port, 0,
3311 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3312 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303313 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3314 err = -EIO;
3315 break;
3316 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303317 set_current_state(TASK_UNINTERRUPTIBLE);
3318 schedule_timeout(usecs_to_jiffies(100));
3319 }
3320 } while (err == -EBUSY);
3321 } else {
3322 c4iw_init_wr_wait(&ep->com.wr_wait);
3323 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3324 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3325 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3326 if (!err)
3327 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3328 &ep->com.wr_wait,
3329 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303330 else if (err > 0)
3331 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303332 }
3333 if (err)
3334 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3335 , err, ep->stid,
3336 &sin->sin_addr, ntohs(sin->sin_port));
3337 return err;
3338}
3339
Steve Wisecfdda9d2010-04-21 15:30:06 -07003340int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3341{
3342 int err = 0;
3343 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3344 struct c4iw_listen_ep *ep;
Steve Wise9eccfe12014-03-26 17:08:09 -05003345 struct iwpm_dev_data pm_reg_msg;
3346 struct iwpm_sa_data pm_msg;
3347 int iwpm_err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003348
Steve Wisecfdda9d2010-04-21 15:30:06 -07003349 might_sleep();
3350
3351 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3352 if (!ep) {
3353 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3354 err = -ENOMEM;
3355 goto fail1;
3356 }
3357 PDBG("%s ep %p\n", __func__, ep);
3358 cm_id->add_ref(cm_id);
3359 ep->com.cm_id = cm_id;
3360 ep->com.dev = dev;
3361 ep->backlog = backlog;
Steve Wise24d44a32013-07-04 16:10:44 +05303362 memcpy(&ep->com.local_addr, &cm_id->local_addr,
3363 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003364
3365 /*
3366 * Allocate a server TID.
3367 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303368 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3369 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303370 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
3371 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003372 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303373 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
3374 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003375
Steve Wisecfdda9d2010-04-21 15:30:06 -07003376 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003377 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003378 err = -ENOMEM;
3379 goto fail2;
3380 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003381 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003382
3383 /* No port mapper available, go with the specified info */
3384 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3385 sizeof(ep->com.mapped_local_addr));
3386
3387 c4iw_form_reg_msg(dev, &pm_reg_msg);
3388 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3389 if (iwpm_err) {
3390 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3391 __func__, iwpm_err);
3392 }
3393 if (iwpm_valid_pid() && !iwpm_err) {
3394 memcpy(&pm_msg.loc_addr, &ep->com.local_addr,
3395 sizeof(ep->com.local_addr));
3396 iwpm_err = iwpm_add_mapping(&pm_msg, RDMA_NL_C4IW);
3397 if (iwpm_err)
3398 PDBG("%s: Port Mapper query fail (err = %d).\n",
3399 __func__, iwpm_err);
3400 else
3401 memcpy(&ep->com.mapped_local_addr,
3402 &pm_msg.mapped_loc_addr,
3403 sizeof(ep->com.mapped_local_addr));
3404 }
3405 if (iwpm_create_mapinfo(&ep->com.local_addr,
3406 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3407 err = -ENOMEM;
3408 goto fail3;
3409 }
3410 print_addr(&ep->com, __func__, "add_mapping/create_mapinfo");
3411
3412 set_bit(RELEASE_MAPINFO, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003413 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303414 if (ep->com.local_addr.ss_family == AF_INET)
3415 err = create_server4(dev, ep);
3416 else
3417 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003418 if (!err) {
3419 cm_id->provider_data = ep;
3420 goto out;
3421 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003422
3423fail3:
Vipul Pandya830662f2013-07-04 16:10:47 +05303424 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3425 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003426fail2:
3427 cm_id->rem_ref(cm_id);
3428 c4iw_put_ep(&ep->com);
3429fail1:
3430out:
3431 return err;
3432}
3433
3434int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3435{
3436 int err;
3437 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3438
3439 PDBG("%s ep %p\n", __func__, ep);
3440
3441 might_sleep();
3442 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303443 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3444 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003445 err = cxgb4_remove_server_filter(
3446 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3447 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3448 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303449 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003450 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303451 err = cxgb4_remove_server(
3452 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3453 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003454 if (err)
3455 goto done;
3456 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3457 0, 0, __func__);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303458 sin6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
3459 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3460 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003461 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003462 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303463 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3464 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003465done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003466 cm_id->rem_ref(cm_id);
3467 c4iw_put_ep(&ep->com);
3468 return err;
3469}
3470
3471int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3472{
3473 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003474 int close = 0;
3475 int fatal = 0;
3476 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003477
Steve Wise2f5b48c2010-09-10 11:15:36 -05003478 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003479
3480 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3481 states[ep->com.state], abrupt);
3482
3483 rdev = &ep->com.dev->rdev;
3484 if (c4iw_fatal_error(rdev)) {
3485 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303486 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003487 ep->com.state = DEAD;
3488 }
3489 switch (ep->com.state) {
3490 case MPA_REQ_WAIT:
3491 case MPA_REQ_SENT:
3492 case MPA_REQ_RCVD:
3493 case MPA_REP_SENT:
3494 case FPDU_MODE:
3495 close = 1;
3496 if (abrupt)
3497 ep->com.state = ABORTING;
3498 else {
3499 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003500 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003501 }
3502 set_bit(CLOSE_SENT, &ep->com.flags);
3503 break;
3504 case CLOSING:
3505 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3506 close = 1;
3507 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003508 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003509 ep->com.state = ABORTING;
3510 } else
3511 ep->com.state = MORIBUND;
3512 }
3513 break;
3514 case MORIBUND:
3515 case ABORTING:
3516 case DEAD:
3517 PDBG("%s ignoring disconnect ep %p state %u\n",
3518 __func__, ep, ep->com.state);
3519 break;
3520 default:
3521 BUG();
3522 break;
3523 }
3524
Steve Wisecfdda9d2010-04-21 15:30:06 -07003525 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003526 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003527 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303528 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003529 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003530 } else {
3531 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003532 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003533 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003534 if (ret)
3535 fatal = 1;
3536 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003537 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003538 if (fatal)
3539 release_ep_resources(ep);
3540 return ret;
3541}
3542
Vipul Pandya1cab7752012-12-10 09:30:55 +00003543static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3544 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3545{
3546 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003547 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003548
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003549 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3550 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003551 if (!ep)
3552 return;
3553
3554 switch (req->retval) {
3555 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003556 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3557 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3558 send_fw_act_open_req(ep, atid);
3559 return;
3560 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003561 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003562 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3563 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3564 send_fw_act_open_req(ep, atid);
3565 return;
3566 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003567 break;
3568 default:
3569 pr_info("%s unexpected ofld conn wr retval %d\n",
3570 __func__, req->retval);
3571 break;
3572 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003573 pr_err("active ofld_connect_wr failure %d atid %d\n",
3574 req->retval, atid);
3575 mutex_lock(&dev->rdev.stats.lock);
3576 dev->rdev.stats.act_ofld_conn_fails++;
3577 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003578 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003579 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303580 if (ep->com.remote_addr.ss_family == AF_INET6) {
3581 struct sockaddr_in6 *sin6 =
3582 (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
3583 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3584 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3585 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003586 remove_handle(dev, &dev->atid_idr, atid);
3587 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3588 dst_release(ep->dst);
3589 cxgb4_l2t_release(ep->l2t);
3590 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003591}
3592
3593static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3594 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3595{
3596 struct sk_buff *rpl_skb;
3597 struct cpl_pass_accept_req *cpl;
3598 int ret;
3599
Paul Bolle710a3112013-02-05 20:51:30 +00003600 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003601 BUG_ON(!rpl_skb);
3602 if (req->retval) {
3603 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003604 mutex_lock(&dev->rdev.stats.lock);
3605 dev->rdev.stats.pas_ofld_conn_fails++;
3606 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003607 kfree_skb(rpl_skb);
3608 } else {
3609 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3610 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003611 (__force u32) htonl(
3612 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003613 ret = pass_accept_req(dev, rpl_skb);
3614 if (!ret)
3615 kfree_skb(rpl_skb);
3616 }
3617 return;
3618}
3619
3620static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003621{
3622 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003623 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3624
3625 switch (rpl->type) {
3626 case FW6_TYPE_CQE:
3627 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3628 break;
3629 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3630 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3631 switch (req->t_state) {
3632 case TCP_SYN_SENT:
3633 active_ofld_conn_reply(dev, skb, req);
3634 break;
3635 case TCP_SYN_RECV:
3636 passive_ofld_conn_reply(dev, skb, req);
3637 break;
3638 default:
3639 pr_err("%s unexpected ofld conn wr state %d\n",
3640 __func__, req->t_state);
3641 break;
3642 }
3643 break;
3644 }
3645 return 0;
3646}
3647
3648static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3649{
Hariprasad S963cab52015-09-23 17:19:27 +05303650 __be32 l2info;
3651 __be16 hdr_len, vlantag, len;
3652 u16 eth_hdr_len;
3653 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003654 u8 intf;
3655 struct cpl_rx_pkt *cpl = cplhdr(skb);
3656 struct cpl_pass_accept_req *req;
3657 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003658 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303659 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003660
Vipul Pandyaf079af72013-03-14 05:08:58 +00003661 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003662 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303663 vlantag = cpl->vlan;
3664 len = cpl->len;
3665 l2info = cpl->l2info;
3666 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003667 intf = cpl->iff;
3668
3669 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3670
3671 /*
3672 * We need to parse the TCP options from SYN packet.
3673 * to generate cpl_pass_accept_req.
3674 */
3675 memset(&tmp_opt, 0, sizeof(tmp_opt));
3676 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003677 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003678
3679 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3680 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303681 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3682 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303683 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303684 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303685 type = dev->rdev.lldi.adapter_type;
3686 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3687 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3688 req->hdr_len =
3689 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3690 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3691 eth_hdr_len = is_t4(type) ?
3692 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3693 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3694 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3695 IP_HDR_LEN_V(ip_hdr_len) |
3696 ETH_HDR_LEN_V(eth_hdr_len));
3697 } else { /* T6 and later */
3698 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3699 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3700 T6_IP_HDR_LEN_V(ip_hdr_len) |
3701 T6_ETH_HDR_LEN_V(eth_hdr_len));
3702 }
3703 req->vlan = vlantag;
3704 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003705 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3706 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003707 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3708 if (tmp_opt.wscale_ok)
3709 req->tcpopt.wsf = tmp_opt.snd_wscale;
3710 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3711 if (tmp_opt.sack_ok)
3712 req->tcpopt.sack = 1;
3713 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3714 return;
3715}
3716
3717static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3718 __be32 laddr, __be16 lport,
3719 __be32 raddr, __be16 rport,
3720 u32 rcv_isn, u32 filter, u16 window,
3721 u32 rss_qid, u8 port_id)
3722{
3723 struct sk_buff *req_skb;
3724 struct fw_ofld_connection_wr *req;
3725 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303726 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003727
3728 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3729 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3730 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003731 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303732 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303733 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003734 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003735 req->le.lport = lport;
3736 req->le.pport = rport;
3737 req->le.u.ipv4.lip = laddr;
3738 req->le.u.ipv4.pip = raddr;
3739 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3740 req->tcb.rcv_adv = htons(window);
3741 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303742 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3743 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3744 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003745 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003746
3747 /*
3748 * We store the qid in opt2 which will be used by the firmware
3749 * to send us the wr response.
3750 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003751 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003752
3753 /*
3754 * We initialize the MSS index in TCB to 0xF.
3755 * So that when driver sends cpl_pass_accept_rpl
3756 * TCB picks up the correct value. If this was 0
3757 * TP will ignore any value > 0 for MSS index.
3758 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003759 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303760 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003761
3762 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303763 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3764 if (ret < 0) {
3765 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3766 ret);
3767 kfree_skb(skb);
3768 kfree_skb(req_skb);
3769 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003770}
3771
3772/*
3773 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3774 * messages when a filter is being used instead of server to
3775 * redirect a syn packet. When packets hit filter they are redirected
3776 * to the offload queue and driver tries to establish the connection
3777 * using firmware work request.
3778 */
3779static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3780{
3781 int stid;
3782 unsigned int filter;
3783 struct ethhdr *eh = NULL;
3784 struct vlan_ethhdr *vlan_eh = NULL;
3785 struct iphdr *iph;
3786 struct tcphdr *tcph;
3787 struct rss_header *rss = (void *)skb->data;
3788 struct cpl_rx_pkt *cpl = (void *)skb->data;
3789 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3790 struct l2t_entry *e;
3791 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003792 struct c4iw_ep *lep;
3793 u16 window;
3794 struct port_info *pi;
3795 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003796 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003797 int step;
3798 u32 tx_chan;
3799 struct neighbour *neigh;
3800
3801 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003802 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003803 goto reject;
3804
3805 /*
3806 * Drop all packets which did not hit the filter.
3807 * Unlikely to happen.
3808 */
3809 if (!(rss->filter_hit && rss->filter_tid))
3810 goto reject;
3811
3812 /*
3813 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3814 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303815 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003816
3817 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3818 if (!lep) {
3819 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3820 goto reject;
3821 }
3822
Hariprasad S963cab52015-09-23 17:19:27 +05303823 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3824 case CHELSIO_T4:
3825 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3826 break;
3827 case CHELSIO_T5:
3828 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3829 break;
3830 case CHELSIO_T6:
3831 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3832 break;
3833 default:
3834 pr_err("T%d Chip is not supported\n",
3835 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3836 goto reject;
3837 }
3838
Vipul Pandyaf079af72013-03-14 05:08:58 +00003839 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003840 eh = (struct ethhdr *)(req + 1);
3841 iph = (struct iphdr *)(eh + 1);
3842 } else {
3843 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3844 iph = (struct iphdr *)(vlan_eh + 1);
3845 skb->vlan_tci = ntohs(cpl->vlan);
3846 }
3847
3848 if (iph->version != 0x4)
3849 goto reject;
3850
3851 tcph = (struct tcphdr *)(iph + 1);
3852 skb_set_network_header(skb, (void *)iph - (void *)rss);
3853 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3854 skb_get(skb);
3855
3856 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3857 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3858 ntohs(tcph->source), iph->tos);
3859
Vipul Pandya830662f2013-07-04 16:10:47 +05303860 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3861 iph->tos);
3862 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003863 pr_err("%s - failed to find dst entry!\n",
3864 __func__);
3865 goto reject;
3866 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003867 neigh = dst_neigh_lookup_skb(dst, skb);
3868
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003869 if (!neigh) {
3870 pr_err("%s - failed to allocate neigh!\n",
3871 __func__);
3872 goto free_dst;
3873 }
3874
Vipul Pandya1cab7752012-12-10 09:30:55 +00003875 if (neigh->dev->flags & IFF_LOOPBACK) {
3876 pdev = ip_dev_find(&init_net, iph->daddr);
3877 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3878 pdev, 0);
3879 pi = (struct port_info *)netdev_priv(pdev);
3880 tx_chan = cxgb4_port_chan(pdev);
3881 dev_put(pdev);
3882 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303883 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003884 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303885 pdev, 0);
3886 pi = (struct port_info *)netdev_priv(pdev);
3887 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003888 }
Steve Wiseebf00062014-03-19 17:44:40 +05303889 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003890 if (!e) {
3891 pr_err("%s - failed to allocate l2t entry!\n",
3892 __func__);
3893 goto free_dst;
3894 }
3895
3896 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3897 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003898 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003899
3900 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303901 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3902 dev->rdev.lldi.ports[0],
3903 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003904
3905 /*
3906 * Synthesize the cpl_pass_accept_req. We have everything except the
3907 * TID. Once firmware sends a reply with TID we update the TID field
3908 * in cpl and pass it through the regular cpl_pass_accept_req path.
3909 */
3910 build_cpl_pass_accept_req(skb, stid, iph->tos);
3911 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3912 tcph->source, ntohl(tcph->seq), filter, window,
3913 rss_qid, pi->port_id);
3914 cxgb4_l2t_release(e);
3915free_dst:
3916 dst_release(dst);
3917reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003918 return 0;
3919}
3920
Steve Wisecfdda9d2010-04-21 15:30:06 -07003921/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003922 * These are the real handlers that are called from a
3923 * work queue.
3924 */
3925static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3926 [CPL_ACT_ESTABLISH] = act_establish,
3927 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3928 [CPL_RX_DATA] = rx_data,
3929 [CPL_ABORT_RPL_RSS] = abort_rpl,
3930 [CPL_ABORT_RPL] = abort_rpl,
3931 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3932 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3933 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3934 [CPL_PASS_ESTABLISH] = pass_establish,
3935 [CPL_PEER_CLOSE] = peer_close,
3936 [CPL_ABORT_REQ_RSS] = peer_abort,
3937 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3938 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003939 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003940 [CPL_FW6_MSG] = deferred_fw6_msg,
3941 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003942};
3943
3944static void process_timeout(struct c4iw_ep *ep)
3945{
3946 struct c4iw_qp_attributes attrs;
3947 int abort = 1;
3948
Steve Wise2f5b48c2010-09-10 11:15:36 -05003949 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003950 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3951 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003952 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003953 switch (ep->com.state) {
3954 case MPA_REQ_SENT:
3955 __state_set(&ep->com, ABORTING);
3956 connect_reply_upcall(ep, -ETIMEDOUT);
3957 break;
3958 case MPA_REQ_WAIT:
3959 __state_set(&ep->com, ABORTING);
3960 break;
3961 case CLOSING:
3962 case MORIBUND:
3963 if (ep->com.cm_id && ep->com.qp) {
3964 attrs.next_state = C4IW_QP_STATE_ERROR;
3965 c4iw_modify_qp(ep->com.qp->rhp,
3966 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3967 &attrs, 1);
3968 }
3969 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303970 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003971 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003972 case ABORTING:
3973 case DEAD:
3974
3975 /*
3976 * These states are expected if the ep timed out at the same
3977 * time as another thread was calling stop_ep_timer().
3978 * So we silently do nothing for these states.
3979 */
3980 abort = 0;
3981 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003982 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003983 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003984 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003985 abort = 0;
3986 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003987 if (abort)
3988 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecc18b932014-04-24 14:31:53 -05003989 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003990 c4iw_put_ep(&ep->com);
3991}
3992
3993static void process_timedout_eps(void)
3994{
3995 struct c4iw_ep *ep;
3996
3997 spin_lock_irq(&timeout_lock);
3998 while (!list_empty(&timeout_list)) {
3999 struct list_head *tmp;
4000
4001 tmp = timeout_list.next;
4002 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004003 tmp->next = NULL;
4004 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004005 spin_unlock_irq(&timeout_lock);
4006 ep = list_entry(tmp, struct c4iw_ep, entry);
4007 process_timeout(ep);
4008 spin_lock_irq(&timeout_lock);
4009 }
4010 spin_unlock_irq(&timeout_lock);
4011}
4012
4013static void process_work(struct work_struct *work)
4014{
4015 struct sk_buff *skb = NULL;
4016 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004017 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004018 unsigned int opcode;
4019 int ret;
4020
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004021 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004022 while ((skb = skb_dequeue(&rxq))) {
4023 rpl = cplhdr(skb);
4024 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4025 opcode = rpl->ot.opcode;
4026
4027 BUG_ON(!work_handlers[opcode]);
4028 ret = work_handlers[opcode](dev, skb);
4029 if (!ret)
4030 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004031 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004032 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004033}
4034
4035static DECLARE_WORK(skb_work, process_work);
4036
4037static void ep_timeout(unsigned long arg)
4038{
4039 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004040 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004041
4042 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004043 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004044 /*
4045 * Only insert if it is not already on the list.
4046 */
4047 if (!ep->entry.next) {
4048 list_add_tail(&ep->entry, &timeout_list);
4049 kickit = 1;
4050 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004051 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004052 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004053 if (kickit)
4054 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004055}
4056
4057/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004058 * All the CM events are handled on a work queue to have a safe context.
4059 */
4060static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4061{
4062
4063 /*
4064 * Save dev in the skb->cb area.
4065 */
4066 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4067
4068 /*
4069 * Queue the skb and schedule the worker thread.
4070 */
4071 skb_queue_tail(&rxq, skb);
4072 queue_work(workq, &skb_work);
4073 return 0;
4074}
4075
4076static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4077{
4078 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4079
4080 if (rpl->status != CPL_ERR_NONE) {
4081 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4082 "for tid %u\n", rpl->status, GET_TID(rpl));
4083 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004084 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004085 return 0;
4086}
4087
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004088static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4089{
4090 struct cpl_fw6_msg *rpl = cplhdr(skb);
4091 struct c4iw_wr_wait *wr_waitp;
4092 int ret;
4093
4094 PDBG("%s type %u\n", __func__, rpl->type);
4095
4096 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004097 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004098 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004099 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004100 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004101 if (wr_waitp)
4102 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004103 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004104 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004105 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004106 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004107 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004108 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004109 default:
4110 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4111 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004112 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004113 break;
4114 }
4115 return 0;
4116}
4117
Steve Wise8da7e7a2011-06-14 20:59:27 +00004118static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4119{
4120 struct cpl_abort_req_rss *req = cplhdr(skb);
4121 struct c4iw_ep *ep;
4122 struct tid_info *t = dev->rdev.lldi.tids;
4123 unsigned int tid = GET_TID(req);
4124
4125 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05004126 if (!ep) {
4127 printk(KERN_WARNING MOD
4128 "Abort on non-existent endpoint, tid %d\n", tid);
4129 kfree_skb(skb);
4130 return 0;
4131 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304132 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304133 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4134 __func__, ep->hwtid, req->status,
4135 neg_adv_str(req->status));
4136 ep->stats.abort_neg_adv++;
4137 dev->rdev.stats.neg_adv++;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004138 kfree_skb(skb);
4139 return 0;
4140 }
4141 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4142 ep->com.state);
4143
4144 /*
4145 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004146 * However, if we are on MPAv2 and want to retry with MPAv1
4147 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004148 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004149 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4150 if (ep->com.state != MPA_REQ_SENT)
4151 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4152 } else
4153 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00004154 sched(dev, skb);
4155 return 0;
4156}
4157
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004158/*
4159 * Most upcalls from the T4 Core go to sched() to
4160 * schedule the processing on a work queue.
4161 */
4162c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4163 [CPL_ACT_ESTABLISH] = sched,
4164 [CPL_ACT_OPEN_RPL] = sched,
4165 [CPL_RX_DATA] = sched,
4166 [CPL_ABORT_RPL_RSS] = sched,
4167 [CPL_ABORT_RPL] = sched,
4168 [CPL_PASS_OPEN_RPL] = sched,
4169 [CPL_CLOSE_LISTSRV_RPL] = sched,
4170 [CPL_PASS_ACCEPT_REQ] = sched,
4171 [CPL_PASS_ESTABLISH] = sched,
4172 [CPL_PEER_CLOSE] = sched,
4173 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004174 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004175 [CPL_RDMA_TERMINATE] = sched,
4176 [CPL_FW4_ACK] = sched,
4177 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004178 [CPL_FW6_MSG] = fw6_msg,
4179 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004180};
4181
Steve Wisecfdda9d2010-04-21 15:30:06 -07004182int __init c4iw_cm_init(void)
4183{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004184 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004185 skb_queue_head_init(&rxq);
4186
4187 workq = create_singlethread_workqueue("iw_cxgb4");
4188 if (!workq)
4189 return -ENOMEM;
4190
Steve Wisecfdda9d2010-04-21 15:30:06 -07004191 return 0;
4192}
4193
Steve Wise46c13762014-06-20 14:26:25 -05004194void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004195{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004196 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004197 flush_workqueue(workq);
4198 destroy_workqueue(workq);
4199}