blob: 9a389a0aa1749fed9ffd0133b4cc3160d9a41aa8 [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{
635 struct cpl_act_open_req *req;
Vipul Pandyaf079af72013-03-14 05:08:58 +0000636 struct cpl_t5_act_open_req *t5_req;
Vipul Pandya830662f2013-07-04 16:10:47 +0530637 struct cpl_act_open_req6 *req6;
638 struct cpl_t5_act_open_req6 *t5_req6;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700639 struct sk_buff *skb;
640 u64 opt0;
641 u32 opt2;
642 unsigned int mtu_idx;
643 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +0530644 int wrlen;
645 int sizev4 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
646 sizeof(struct cpl_act_open_req) :
647 sizeof(struct cpl_t5_act_open_req);
648 int sizev6 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
649 sizeof(struct cpl_act_open_req6) :
650 sizeof(struct cpl_t5_act_open_req6);
Steve Wise9eccfe12014-03-26 17:08:09 -0500651 struct sockaddr_in *la = (struct sockaddr_in *)
652 &ep->com.mapped_local_addr;
653 struct sockaddr_in *ra = (struct sockaddr_in *)
654 &ep->com.mapped_remote_addr;
655 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
656 &ep->com.mapped_local_addr;
657 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
658 &ep->com.mapped_remote_addr;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530659 int win;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530660 int ret;
Vipul Pandya830662f2013-07-04 16:10:47 +0530661
662 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
663 roundup(sizev4, 16) :
664 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700665
666 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
667
668 skb = get_skb(NULL, wrlen, GFP_KERNEL);
669 if (!skb) {
670 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
671 __func__);
672 return -ENOMEM;
673 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000674 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700675
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530676 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530677 enable_tcp_timestamps,
678 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700679 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530680
681 /*
682 * Specify the largest window that will fit in opt0. The
683 * remainder will be specified in the rx_data_ack.
684 */
685 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800686 if (win > RCV_BUFSIZ_M)
687 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530688
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800689 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800690 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800691 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800692 WND_SCALE_V(wscale) |
693 MSS_IDX_V(mtu_idx) |
694 L2T_IDX_V(ep->l2t->idx) |
695 TX_CHAN_V(ep->tx_chan) |
696 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800697 DSCP_V(ep->tos) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800698 ULP_MODE_V(ULP_MODE_TCPDDP) |
699 RCV_BUFSIZ_V(win);
700 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800701 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800702 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700703 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800704 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700705 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800706 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700707 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800708 opt2 |= WND_SCALE_EN_F;
Steve Wise92e50112014-04-24 14:31:59 -0500709 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
Anish Bhattd7990b02014-11-12 17:15:57 -0800710 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530711 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530712 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500713 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530714
715 if (ep->com.remote_addr.ss_family == AF_INET6)
716 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
717 (const u32 *)&la6->sin6_addr.s6_addr, 1);
718
Hariprasad S5dab6d32014-06-23 19:12:36 +0530719 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700720
Vipul Pandyaf079af72013-03-14 05:08:58 +0000721 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Vipul Pandya830662f2013-07-04 16:10:47 +0530722 if (ep->com.remote_addr.ss_family == AF_INET) {
723 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
724 INIT_TP_WR(req, 0);
725 OPCODE_TID(req) = cpu_to_be32(
Vipul Pandyaf079af72013-03-14 05:08:58 +0000726 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
727 ((ep->rss_qid << 14) | ep->atid)));
Vipul Pandya830662f2013-07-04 16:10:47 +0530728 req->local_port = la->sin_port;
729 req->peer_port = ra->sin_port;
730 req->local_ip = la->sin_addr.s_addr;
731 req->peer_ip = ra->sin_addr.s_addr;
732 req->opt0 = cpu_to_be64(opt0);
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530733 req->params = cpu_to_be32(cxgb4_select_ntuple(
734 ep->com.dev->rdev.lldi.ports[0],
735 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530736 req->opt2 = cpu_to_be32(opt2);
737 } else {
738 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
739
740 INIT_TP_WR(req6, 0);
741 OPCODE_TID(req6) = cpu_to_be32(
742 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
743 ((ep->rss_qid<<14)|ep->atid)));
744 req6->local_port = la6->sin6_port;
745 req6->peer_port = ra6->sin6_port;
746 req6->local_ip_hi = *((__be64 *)
747 (la6->sin6_addr.s6_addr));
748 req6->local_ip_lo = *((__be64 *)
749 (la6->sin6_addr.s6_addr + 8));
750 req6->peer_ip_hi = *((__be64 *)
751 (ra6->sin6_addr.s6_addr));
752 req6->peer_ip_lo = *((__be64 *)
753 (ra6->sin6_addr.s6_addr + 8));
754 req6->opt0 = cpu_to_be64(opt0);
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530755 req6->params = cpu_to_be32(cxgb4_select_ntuple(
756 ep->com.dev->rdev.lldi.ports[0],
757 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530758 req6->opt2 = cpu_to_be32(opt2);
759 }
760 } else {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530761 u32 isn = (prandom_u32() & ~7UL) - 1;
762
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530763 if (peer2peer)
764 isn += 4;
765
Vipul Pandya830662f2013-07-04 16:10:47 +0530766 if (ep->com.remote_addr.ss_family == AF_INET) {
767 t5_req = (struct cpl_t5_act_open_req *)
768 skb_put(skb, wrlen);
769 INIT_TP_WR(t5_req, 0);
770 OPCODE_TID(t5_req) = cpu_to_be32(
771 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
772 ((ep->rss_qid << 14) | ep->atid)));
773 t5_req->local_port = la->sin_port;
774 t5_req->peer_port = ra->sin_port;
775 t5_req->local_ip = la->sin_addr.s_addr;
776 t5_req->peer_ip = ra->sin_addr.s_addr;
777 t5_req->opt0 = cpu_to_be64(opt0);
Anish Bhattd7990b02014-11-12 17:15:57 -0800778 t5_req->params = cpu_to_be64(FILTER_TUPLE_V(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530779 cxgb4_select_ntuple(
780 ep->com.dev->rdev.lldi.ports[0],
781 ep->l2t)));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530782 t5_req->rsvd = cpu_to_be32(isn);
783 PDBG("%s snd_isn %u\n", __func__,
784 be32_to_cpu(t5_req->rsvd));
Vipul Pandya830662f2013-07-04 16:10:47 +0530785 t5_req->opt2 = cpu_to_be32(opt2);
786 } else {
787 t5_req6 = (struct cpl_t5_act_open_req6 *)
788 skb_put(skb, wrlen);
789 INIT_TP_WR(t5_req6, 0);
790 OPCODE_TID(t5_req6) = cpu_to_be32(
791 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
792 ((ep->rss_qid<<14)|ep->atid)));
793 t5_req6->local_port = la6->sin6_port;
794 t5_req6->peer_port = ra6->sin6_port;
795 t5_req6->local_ip_hi = *((__be64 *)
796 (la6->sin6_addr.s6_addr));
797 t5_req6->local_ip_lo = *((__be64 *)
798 (la6->sin6_addr.s6_addr + 8));
799 t5_req6->peer_ip_hi = *((__be64 *)
800 (ra6->sin6_addr.s6_addr));
801 t5_req6->peer_ip_lo = *((__be64 *)
802 (ra6->sin6_addr.s6_addr + 8));
803 t5_req6->opt0 = cpu_to_be64(opt0);
Anish Bhattd7990b02014-11-12 17:15:57 -0800804 t5_req6->params = cpu_to_be64(FILTER_TUPLE_V(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530805 cxgb4_select_ntuple(
806 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530807 ep->l2t)));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530808 t5_req6->rsvd = cpu_to_be32(isn);
809 PDBG("%s snd_isn %u\n", __func__,
810 be32_to_cpu(t5_req6->rsvd));
Vipul Pandya830662f2013-07-04 16:10:47 +0530811 t5_req6->opt2 = cpu_to_be32(opt2);
812 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000813 }
814
Vipul Pandya793dad92012-12-10 09:30:56 +0000815 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530816 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
817 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
818 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
819 (const u32 *)&la6->sin6_addr.s6_addr, 1);
820 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700821}
822
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530823static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
824 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700825{
826 int mpalen, wrlen;
827 struct fw_ofld_tx_data_wr *req;
828 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530829 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700830
831 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
832
833 BUG_ON(skb_cloned(skb));
834
835 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530836 if (mpa_rev_to_use == 2)
837 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700838 wrlen = roundup(mpalen + sizeof *req, 16);
839 skb = get_skb(skb, wrlen, GFP_KERNEL);
840 if (!skb) {
841 connect_reply_upcall(ep, -ENOMEM);
842 return;
843 }
844 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
845
846 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
847 memset(req, 0, wrlen);
848 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530849 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
850 FW_WR_COMPL_F |
851 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700852 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530853 FW_WR_FLOWID_V(ep->hwtid) |
854 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700855 req->plen = cpu_to_be32(mpalen);
856 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530857 FW_OFLD_TX_DATA_WR_FLUSH_F |
858 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700859
860 mpa = (struct mpa_message *)(req + 1);
861 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
862 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530863 (markers_enabled ? MPA_MARKERS : 0) |
864 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700865 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530866 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530867 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530868 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530869 ep->retry_with_mpa_v1 = 0;
870 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700871
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530872 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700873 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
874 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530875 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
876 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530877 mpa_v2_params.ird = htons((u16)ep->ird);
878 mpa_v2_params.ord = htons((u16)ep->ord);
879
880 if (peer2peer) {
881 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
882 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
883 mpa_v2_params.ord |=
884 htons(MPA_V2_RDMA_WRITE_RTR);
885 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
886 mpa_v2_params.ord |=
887 htons(MPA_V2_RDMA_READ_RTR);
888 }
889 memcpy(mpa->private_data, &mpa_v2_params,
890 sizeof(struct mpa_v2_conn_params));
891
892 if (ep->plen)
893 memcpy(mpa->private_data +
894 sizeof(struct mpa_v2_conn_params),
895 ep->mpa_pkt + sizeof(*mpa), ep->plen);
896 } else
897 if (ep->plen)
898 memcpy(mpa->private_data,
899 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700900
901 /*
902 * Reference the mpa skb. This ensures the data area
903 * will remain in memory until the hw acks the tx.
904 * Function fw4_ack() will deref it.
905 */
906 skb_get(skb);
907 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
908 BUG_ON(ep->mpa_skb);
909 ep->mpa_skb = skb;
910 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
911 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530912 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700913 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530914 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700915 return;
916}
917
918static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
919{
920 int mpalen, wrlen;
921 struct fw_ofld_tx_data_wr *req;
922 struct mpa_message *mpa;
923 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530924 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700925
926 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
927
928 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530929 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
930 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700931 wrlen = roundup(mpalen + sizeof *req, 16);
932
933 skb = get_skb(NULL, wrlen, GFP_KERNEL);
934 if (!skb) {
935 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
936 return -ENOMEM;
937 }
938 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
939
940 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
941 memset(req, 0, wrlen);
942 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530943 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
944 FW_WR_COMPL_F |
945 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700946 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530947 FW_WR_FLOWID_V(ep->hwtid) |
948 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700949 req->plen = cpu_to_be32(mpalen);
950 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530951 FW_OFLD_TX_DATA_WR_FLUSH_F |
952 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700953
954 mpa = (struct mpa_message *)(req + 1);
955 memset(mpa, 0, sizeof(*mpa));
956 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
957 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000958 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700959 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530960
961 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
962 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700963 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
964 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530965 mpa_v2_params.ird = htons(((u16)ep->ird) |
966 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
967 0));
968 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
969 (p2p_type ==
970 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
971 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
972 FW_RI_INIT_P2PTYPE_READ_REQ ?
973 MPA_V2_RDMA_READ_RTR : 0) : 0));
974 memcpy(mpa->private_data, &mpa_v2_params,
975 sizeof(struct mpa_v2_conn_params));
976
977 if (ep->plen)
978 memcpy(mpa->private_data +
979 sizeof(struct mpa_v2_conn_params), pdata, plen);
980 } else
981 if (plen)
982 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700983
984 /*
985 * Reference the mpa skb again. This ensures the data area
986 * will remain in memory until the hw acks the tx.
987 * Function fw4_ack() will deref it.
988 */
989 skb_get(skb);
990 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
991 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
992 BUG_ON(ep->mpa_skb);
993 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +0530994 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700995 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
996}
997
998static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
999{
1000 int mpalen, wrlen;
1001 struct fw_ofld_tx_data_wr *req;
1002 struct mpa_message *mpa;
1003 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301004 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001005
1006 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1007
1008 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301009 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1010 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001011 wrlen = roundup(mpalen + sizeof *req, 16);
1012
1013 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1014 if (!skb) {
1015 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1016 return -ENOMEM;
1017 }
1018 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1019
1020 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1021 memset(req, 0, wrlen);
1022 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301023 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1024 FW_WR_COMPL_F |
1025 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001026 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301027 FW_WR_FLOWID_V(ep->hwtid) |
1028 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001029 req->plen = cpu_to_be32(mpalen);
1030 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301031 FW_OFLD_TX_DATA_WR_FLUSH_F |
1032 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001033
1034 mpa = (struct mpa_message *)(req + 1);
1035 memset(mpa, 0, sizeof(*mpa));
1036 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1037 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
1038 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301039 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001040 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301041
1042 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1043 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001044 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1045 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301046 mpa_v2_params.ird = htons((u16)ep->ird);
1047 mpa_v2_params.ord = htons((u16)ep->ord);
1048 if (peer2peer && (ep->mpa_attr.p2p_type !=
1049 FW_RI_INIT_P2PTYPE_DISABLED)) {
1050 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1051
1052 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1053 mpa_v2_params.ord |=
1054 htons(MPA_V2_RDMA_WRITE_RTR);
1055 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1056 mpa_v2_params.ord |=
1057 htons(MPA_V2_RDMA_READ_RTR);
1058 }
1059
1060 memcpy(mpa->private_data, &mpa_v2_params,
1061 sizeof(struct mpa_v2_conn_params));
1062
1063 if (ep->plen)
1064 memcpy(mpa->private_data +
1065 sizeof(struct mpa_v2_conn_params), pdata, plen);
1066 } else
1067 if (plen)
1068 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001069
1070 /*
1071 * Reference the mpa skb. This ensures the data area
1072 * will remain in memory until the hw acks the tx.
1073 * Function fw4_ack() will deref it.
1074 */
1075 skb_get(skb);
1076 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1077 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301078 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301079 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001080 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1081}
1082
1083static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1084{
1085 struct c4iw_ep *ep;
1086 struct cpl_act_establish *req = cplhdr(skb);
1087 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001088 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001089 struct tid_info *t = dev->rdev.lldi.tids;
1090
1091 ep = lookup_atid(t, atid);
1092
1093 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1094 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1095
Steve Wisea7db89e2014-03-21 20:40:35 +05301096 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001097 dst_confirm(ep->dst);
1098
1099 /* setup the hwtid for this connection */
1100 ep->hwtid = tid;
1101 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001102 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001103
1104 ep->snd_seq = be32_to_cpu(req->snd_isn);
1105 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1106
1107 set_emss(ep, ntohs(req->tcp_opt));
1108
1109 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001110 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001111 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001112 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001113
1114 /* start MPA negotiation */
1115 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301116 if (ep->retry_with_mpa_v1)
1117 send_mpa_req(ep, skb, 1);
1118 else
1119 send_mpa_req(ep, skb, mpa_rev);
Steve Wisea7db89e2014-03-21 20:40:35 +05301120 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001121 return 0;
1122}
1123
Steve Wisebe13b2d2014-03-21 20:40:33 +05301124static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001125{
1126 struct iw_cm_event event;
1127
1128 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1129 memset(&event, 0, sizeof(event));
1130 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301131 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001132 if (ep->com.cm_id) {
1133 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1134 ep, ep->com.cm_id, ep->hwtid);
1135 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1136 ep->com.cm_id->rem_ref(ep->com.cm_id);
1137 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001138 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001139 }
1140}
1141
1142static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
1143{
1144 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecc18b932014-04-24 14:31:53 -05001145 __state_set(&ep->com, ABORTING);
Vipul Pandya793dad92012-12-10 09:30:56 +00001146 set_bit(ABORT_CONN, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001147 return send_abort(ep, skb, gfp);
1148}
1149
1150static void peer_close_upcall(struct c4iw_ep *ep)
1151{
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_DISCONNECT;
1157 if (ep->com.cm_id) {
1158 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1159 ep, ep->com.cm_id, ep->hwtid);
1160 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001161 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001162 }
1163}
1164
1165static void peer_abort_upcall(struct c4iw_ep *ep)
1166{
1167 struct iw_cm_event event;
1168
1169 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1170 memset(&event, 0, sizeof(event));
1171 event.event = IW_CM_EVENT_CLOSE;
1172 event.status = -ECONNRESET;
1173 if (ep->com.cm_id) {
1174 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1175 ep->com.cm_id, ep->hwtid);
1176 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1177 ep->com.cm_id->rem_ref(ep->com.cm_id);
1178 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001179 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001180 }
1181}
1182
1183static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1184{
1185 struct iw_cm_event event;
1186
1187 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1188 memset(&event, 0, sizeof(event));
1189 event.event = IW_CM_EVENT_CONNECT_REPLY;
1190 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301191 memcpy(&event.local_addr, &ep->com.local_addr,
1192 sizeof(ep->com.local_addr));
1193 memcpy(&event.remote_addr, &ep->com.remote_addr,
1194 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001195
1196 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301197 if (!ep->tried_with_mpa_v1) {
1198 /* this means MPA_v2 is used */
1199 event.private_data_len = ep->plen -
1200 sizeof(struct mpa_v2_conn_params);
1201 event.private_data = ep->mpa_pkt +
1202 sizeof(struct mpa_message) +
1203 sizeof(struct mpa_v2_conn_params);
1204 } else {
1205 /* this means MPA_v1 is used */
1206 event.private_data_len = ep->plen;
1207 event.private_data = ep->mpa_pkt +
1208 sizeof(struct mpa_message);
1209 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001210 }
Roland Dreier85963e42010-07-19 13:13:09 -07001211
1212 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1213 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001214 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001215 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1216
Steve Wisecfdda9d2010-04-21 15:30:06 -07001217 if (status < 0) {
1218 ep->com.cm_id->rem_ref(ep->com.cm_id);
1219 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001220 }
1221}
1222
Steve Wisebe13b2d2014-03-21 20:40:33 +05301223static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001224{
1225 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301226 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001227
1228 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1229 memset(&event, 0, sizeof(event));
1230 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301231 memcpy(&event.local_addr, &ep->com.local_addr,
1232 sizeof(ep->com.local_addr));
1233 memcpy(&event.remote_addr, &ep->com.remote_addr,
1234 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001235 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301236 if (!ep->tried_with_mpa_v1) {
1237 /* this means MPA_v2 is used */
1238 event.ord = ep->ord;
1239 event.ird = ep->ird;
1240 event.private_data_len = ep->plen -
1241 sizeof(struct mpa_v2_conn_params);
1242 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1243 sizeof(struct mpa_v2_conn_params);
1244 } else {
1245 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301246 event.ord = cur_max_read_depth(ep->com.dev);
1247 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301248 event.private_data_len = ep->plen;
1249 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1250 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301251 c4iw_get_ep(&ep->com);
1252 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1253 &event);
1254 if (ret)
1255 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001256 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001257 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301258 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001259}
1260
1261static void established_upcall(struct c4iw_ep *ep)
1262{
1263 struct iw_cm_event event;
1264
1265 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1266 memset(&event, 0, sizeof(event));
1267 event.event = IW_CM_EVENT_ESTABLISHED;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301268 event.ird = ep->ird;
1269 event.ord = ep->ord;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001270 if (ep->com.cm_id) {
1271 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1272 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001273 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001274 }
1275}
1276
1277static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1278{
1279 struct cpl_rx_data_ack *req;
1280 struct sk_buff *skb;
1281 int wrlen = roundup(sizeof *req, 16);
1282
1283 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1284 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1285 if (!skb) {
1286 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1287 return 0;
1288 }
1289
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301290 /*
1291 * If we couldn't specify the entire rcv window at connection setup
1292 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1293 * then add the overage in to the credits returned.
1294 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001295 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1296 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301297
Steve Wisecfdda9d2010-04-21 15:30:06 -07001298 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1299 memset(req, 0, wrlen);
1300 INIT_TP_WR(req, ep->hwtid);
1301 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1302 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001303 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301304 RX_DACK_CHANGE_F |
1305 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001306 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001307 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1308 return credits;
1309}
1310
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301311#define RELAXED_IRD_NEGOTIATION 1
1312
Steve Wisecc18b932014-04-24 14:31:53 -05001313static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001314{
1315 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301316 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001317 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301318 u16 resp_ird, resp_ord;
1319 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001320 struct c4iw_qp_attributes attrs;
1321 enum c4iw_qp_attr_mask mask;
1322 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001323 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001324
1325 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1326
1327 /*
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001328 * Stop mpa timer. If it expired, then
1329 * we ignore the MPA reply. process_timeout()
1330 * will abort the connection.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001331 */
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001332 if (stop_ep_timer(ep))
Steve Wisecc18b932014-04-24 14:31:53 -05001333 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001334
1335 /*
1336 * If we get more than the supported amount of private data
1337 * then we must fail this connection.
1338 */
1339 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1340 err = -EINVAL;
1341 goto err;
1342 }
1343
1344 /*
1345 * copy the new data into our accumulation buffer.
1346 */
1347 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1348 skb->len);
1349 ep->mpa_pkt_len += skb->len;
1350
1351 /*
1352 * if we don't even have the mpa message, then bail.
1353 */
1354 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001355 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001356 mpa = (struct mpa_message *) ep->mpa_pkt;
1357
1358 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301359 if (mpa->revision > mpa_rev) {
1360 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1361 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001362 err = -EPROTO;
1363 goto err;
1364 }
1365 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1366 err = -EPROTO;
1367 goto err;
1368 }
1369
1370 plen = ntohs(mpa->private_data_size);
1371
1372 /*
1373 * Fail if there's too much private data.
1374 */
1375 if (plen > MPA_MAX_PRIVATE_DATA) {
1376 err = -EPROTO;
1377 goto err;
1378 }
1379
1380 /*
1381 * If plen does not account for pkt size
1382 */
1383 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1384 err = -EPROTO;
1385 goto err;
1386 }
1387
1388 ep->plen = (u8) plen;
1389
1390 /*
1391 * If we don't have all the pdata yet, then bail.
1392 * We'll continue process when more data arrives.
1393 */
1394 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001395 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001396
1397 if (mpa->flags & MPA_REJECT) {
1398 err = -ECONNREFUSED;
1399 goto err;
1400 }
1401
1402 /*
1403 * If we get here we have accumulated the entire mpa
1404 * start reply message including private data. And
1405 * the MPA header is valid.
1406 */
Steve Wisec529fb52014-03-21 20:40:37 +05301407 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001408 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1409 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1410 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301411 ep->mpa_attr.version = mpa->revision;
1412 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1413
1414 if (mpa->revision == 2) {
1415 ep->mpa_attr.enhanced_rdma_conn =
1416 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1417 if (ep->mpa_attr.enhanced_rdma_conn) {
1418 mpa_v2_params = (struct mpa_v2_conn_params *)
1419 (ep->mpa_pkt + sizeof(*mpa));
1420 resp_ird = ntohs(mpa_v2_params->ird) &
1421 MPA_V2_IRD_ORD_MASK;
1422 resp_ord = ntohs(mpa_v2_params->ord) &
1423 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301424 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1425 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301426
1427 /*
1428 * This is a double-check. Ideally, below checks are
1429 * not required since ird/ord stuff has been taken
1430 * care of in c4iw_accept_cr
1431 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301432 if (ep->ird < resp_ord) {
1433 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1434 ep->com.dev->rdev.lldi.max_ordird_qp)
1435 ep->ird = resp_ord;
1436 else
1437 insuff_ird = 1;
1438 } else if (ep->ird > resp_ord) {
1439 ep->ird = resp_ord;
1440 }
1441 if (ep->ord > resp_ird) {
1442 if (RELAXED_IRD_NEGOTIATION)
1443 ep->ord = resp_ird;
1444 else
1445 insuff_ird = 1;
1446 }
1447 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301448 err = -ENOMEM;
1449 ep->ird = resp_ord;
1450 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301451 }
1452
1453 if (ntohs(mpa_v2_params->ird) &
1454 MPA_V2_PEER2PEER_MODEL) {
1455 if (ntohs(mpa_v2_params->ord) &
1456 MPA_V2_RDMA_WRITE_RTR)
1457 ep->mpa_attr.p2p_type =
1458 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1459 else if (ntohs(mpa_v2_params->ord) &
1460 MPA_V2_RDMA_READ_RTR)
1461 ep->mpa_attr.p2p_type =
1462 FW_RI_INIT_P2PTYPE_READ_REQ;
1463 }
1464 }
1465 } else if (mpa->revision == 1)
1466 if (peer2peer)
1467 ep->mpa_attr.p2p_type = p2p_type;
1468
Steve Wisecfdda9d2010-04-21 15:30:06 -07001469 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301470 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1471 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1472 ep->mpa_attr.recv_marker_enabled,
1473 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1474 ep->mpa_attr.p2p_type, p2p_type);
1475
1476 /*
1477 * If responder's RTR does not match with that of initiator, assign
1478 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1479 * generated when moving QP to RTS state.
1480 * A TERM message will be sent after QP has moved to RTS state
1481 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001482 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301483 (ep->mpa_attr.p2p_type != p2p_type)) {
1484 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1485 rtr_mismatch = 1;
1486 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001487
1488 attrs.mpa_attr = ep->mpa_attr;
1489 attrs.max_ird = ep->ird;
1490 attrs.max_ord = ep->ord;
1491 attrs.llp_stream_handle = ep;
1492 attrs.next_state = C4IW_QP_STATE_RTS;
1493
1494 mask = C4IW_QP_ATTR_NEXT_STATE |
1495 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1496 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1497
1498 /* bind QP and TID with INIT_WR */
1499 err = c4iw_modify_qp(ep->com.qp->rhp,
1500 ep->com.qp, mask, &attrs, 1);
1501 if (err)
1502 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301503
1504 /*
1505 * If responder's RTR requirement did not match with what initiator
1506 * supports, generate TERM message
1507 */
1508 if (rtr_mismatch) {
1509 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1510 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1511 attrs.ecode = MPA_NOMATCH_RTR;
1512 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001513 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301514 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001515 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301516 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001517 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301518 goto out;
1519 }
1520
1521 /*
1522 * Generate TERM if initiator IRD is not sufficient for responder
1523 * provided ORD. Currently, we do the same behaviour even when
1524 * responder provided IRD is also not sufficient as regards to
1525 * initiator ORD.
1526 */
1527 if (insuff_ird) {
1528 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1529 __func__);
1530 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1531 attrs.ecode = MPA_INSUFF_IRD;
1532 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001533 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301534 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001535 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301536 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001537 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301538 goto out;
1539 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001540 goto out;
1541err:
Steve Wisec529fb52014-03-21 20:40:37 +05301542 __state_set(&ep->com, ABORTING);
Steve Wiseb21ef162010-06-10 19:02:55 +00001543 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001544out:
1545 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001546 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001547}
1548
1549static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1550{
1551 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301552 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001553 u16 plen;
1554
1555 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1556
Steve Wisecfdda9d2010-04-21 15:30:06 -07001557 /*
1558 * If we get more than the supported amount of private data
1559 * then we must fail this connection.
1560 */
1561 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001562 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001563 abort_connection(ep, skb, GFP_KERNEL);
1564 return;
1565 }
1566
1567 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1568
1569 /*
1570 * Copy the new data into our accumulation buffer.
1571 */
1572 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1573 skb->len);
1574 ep->mpa_pkt_len += skb->len;
1575
1576 /*
1577 * If we don't even have the mpa message, then bail.
1578 * We'll continue process when more data arrives.
1579 */
1580 if (ep->mpa_pkt_len < sizeof(*mpa))
1581 return;
1582
1583 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001584 mpa = (struct mpa_message *) ep->mpa_pkt;
1585
1586 /*
1587 * Validate MPA Header.
1588 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301589 if (mpa->revision > mpa_rev) {
1590 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1591 " Received = %d\n", __func__, mpa_rev, mpa->revision);
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 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001598 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001599 abort_connection(ep, skb, GFP_KERNEL);
1600 return;
1601 }
1602
1603 plen = ntohs(mpa->private_data_size);
1604
1605 /*
1606 * Fail if there's too much private data.
1607 */
1608 if (plen > MPA_MAX_PRIVATE_DATA) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001609 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001610 abort_connection(ep, skb, GFP_KERNEL);
1611 return;
1612 }
1613
1614 /*
1615 * If plen does not account for pkt size
1616 */
1617 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001618 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001619 abort_connection(ep, skb, GFP_KERNEL);
1620 return;
1621 }
1622 ep->plen = (u8) plen;
1623
1624 /*
1625 * If we don't have all the pdata yet, then bail.
1626 */
1627 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1628 return;
1629
1630 /*
1631 * If we get here we have accumulated the entire mpa
1632 * start reply message including private data.
1633 */
1634 ep->mpa_attr.initiator = 0;
1635 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1636 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1637 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301638 ep->mpa_attr.version = mpa->revision;
1639 if (mpa->revision == 1)
1640 ep->tried_with_mpa_v1 = 1;
1641 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1642
1643 if (mpa->revision == 2) {
1644 ep->mpa_attr.enhanced_rdma_conn =
1645 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1646 if (ep->mpa_attr.enhanced_rdma_conn) {
1647 mpa_v2_params = (struct mpa_v2_conn_params *)
1648 (ep->mpa_pkt + sizeof(*mpa));
1649 ep->ird = ntohs(mpa_v2_params->ird) &
1650 MPA_V2_IRD_ORD_MASK;
1651 ep->ord = ntohs(mpa_v2_params->ord) &
1652 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301653 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1654 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301655 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1656 if (peer2peer) {
1657 if (ntohs(mpa_v2_params->ord) &
1658 MPA_V2_RDMA_WRITE_RTR)
1659 ep->mpa_attr.p2p_type =
1660 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1661 else if (ntohs(mpa_v2_params->ord) &
1662 MPA_V2_RDMA_READ_RTR)
1663 ep->mpa_attr.p2p_type =
1664 FW_RI_INIT_P2PTYPE_READ_REQ;
1665 }
1666 }
1667 } else if (mpa->revision == 1)
1668 if (peer2peer)
1669 ep->mpa_attr.p2p_type = p2p_type;
1670
Steve Wisecfdda9d2010-04-21 15:30:06 -07001671 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1672 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1673 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1674 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1675 ep->mpa_attr.p2p_type);
1676
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001677 /*
1678 * If the endpoint timer already expired, then we ignore
1679 * the start request. process_timeout() will abort
1680 * the connection.
1681 */
1682 if (!stop_ep_timer(ep)) {
1683 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001684
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001685 /* drive upcall */
Hariprasad Shenai10be6b42014-11-21 09:36:35 -06001686 mutex_lock_nested(&ep->parent_ep->com.mutex,
1687 SINGLE_DEPTH_NESTING);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001688 if (ep->parent_ep->com.state != DEAD) {
1689 if (connect_request_upcall(ep))
1690 abort_connection(ep, skb, GFP_KERNEL);
1691 } else {
Steve Wisebe13b2d2014-03-21 20:40:33 +05301692 abort_connection(ep, skb, GFP_KERNEL);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001693 }
1694 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301695 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001696 return;
1697}
1698
1699static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1700{
1701 struct c4iw_ep *ep;
1702 struct cpl_rx_data *hdr = cplhdr(skb);
1703 unsigned int dlen = ntohs(hdr->len);
1704 unsigned int tid = GET_TID(hdr);
1705 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001706 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001707 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001708
1709 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301710 if (!ep)
1711 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001712 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1713 skb_pull(skb, sizeof(*hdr));
1714 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301715 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001716
Steve Wisecfdda9d2010-04-21 15:30:06 -07001717 /* update RX credits */
1718 update_rx_credits(ep, dlen);
1719
Steve Wisec529fb52014-03-21 20:40:37 +05301720 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001721 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001722 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001723 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001724 break;
1725 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001726 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001727 process_mpa_request(ep, skb);
1728 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001729 case FPDU_MODE: {
1730 struct c4iw_qp_attributes attrs;
1731 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001732 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001733 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001734 " qpid %u ep %p state %d tid %u status %d\n",
1735 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301736 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301737 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001738 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001739 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1740 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001741 break;
1742 }
Vipul Pandya15579672013-01-07 13:11:52 +00001743 default:
1744 break;
1745 }
Steve Wisec529fb52014-03-21 20:40:37 +05301746 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001747 if (disconnect)
1748 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001749 return 0;
1750}
1751
1752static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1753{
1754 struct c4iw_ep *ep;
1755 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001756 int release = 0;
1757 unsigned int tid = GET_TID(rpl);
1758 struct tid_info *t = dev->rdev.lldi.tids;
1759
1760 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301761 if (!ep) {
1762 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1763 return 0;
1764 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001765 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001766 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001767 switch (ep->com.state) {
1768 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001769 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001770 __state_set(&ep->com, DEAD);
1771 release = 1;
1772 break;
1773 default:
1774 printk(KERN_ERR "%s ep %p state %d\n",
1775 __func__, ep, ep->com.state);
1776 break;
1777 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001778 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001779
1780 if (release)
1781 release_ep_resources(ep);
1782 return 0;
1783}
1784
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001785static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1786{
1787 struct sk_buff *skb;
1788 struct fw_ofld_connection_wr *req;
1789 unsigned int mtu_idx;
1790 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301791 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301792 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001793
1794 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1795 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1796 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001797 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301798 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301799 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1800 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001801 ep->l2t));
Steve Wise9eccfe12014-03-26 17:08:09 -05001802 sin = (struct sockaddr_in *)&ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301803 req->le.lport = sin->sin_port;
1804 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05001805 sin = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301806 req->le.pport = sin->sin_port;
1807 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001808 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301809 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1810 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001811 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301812 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001813 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001814 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301815 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301816 enable_tcp_timestamps,
1817 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001818 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301819
1820 /*
1821 * Specify the largest window that will fit in opt0. The
1822 * remainder will be specified in the rx_data_ack.
1823 */
1824 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001825 if (win > RCV_BUFSIZ_M)
1826 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301827
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001828 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1829 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001830 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001831 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001832 WND_SCALE_V(wscale) |
1833 MSS_IDX_V(mtu_idx) |
1834 L2T_IDX_V(ep->l2t->idx) |
1835 TX_CHAN_V(ep->tx_chan) |
1836 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001837 DSCP_V(ep->tos) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001838 ULP_MODE_V(ULP_MODE_TCPDDP) |
1839 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001840 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1841 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001842 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001843 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001844 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001845 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001846 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001847 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001848 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001849 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001850 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1851 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1852 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001853 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1854 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001855 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1856}
1857
Steve Wisecfdda9d2010-04-21 15:30:06 -07001858/*
1859 * Return whether a failed active open has allocated a TID
1860 */
1861static inline int act_open_has_tid(int status)
1862{
1863 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1864 status != CPL_ERR_ARP_MISS;
1865}
1866
Steve Wise7a2cea22014-03-14 21:52:07 +05301867/* Returns whether a CPL status conveys negative advice.
1868 */
1869static int is_neg_adv(unsigned int status)
1870{
1871 return status == CPL_ERR_RTX_NEG_ADVICE ||
1872 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1873 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1874}
1875
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301876static char *neg_adv_str(unsigned int status)
1877{
1878 switch (status) {
1879 case CPL_ERR_RTX_NEG_ADVICE:
1880 return "Retransmit timeout";
1881 case CPL_ERR_PERSIST_NEG_ADVICE:
1882 return "Persist timeout";
1883 case CPL_ERR_KEEPALV_NEG_ADVICE:
1884 return "Keepalive timeout";
1885 default:
1886 return "Unknown";
1887 }
1888}
1889
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301890static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1891{
1892 ep->snd_win = snd_win;
1893 ep->rcv_win = rcv_win;
1894 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1895}
1896
Vipul Pandya793dad92012-12-10 09:30:56 +00001897#define ACT_OPEN_RETRY_COUNT 2
1898
Vipul Pandya830662f2013-07-04 16:10:47 +05301899static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1900 struct dst_entry *dst, struct c4iw_dev *cdev,
1901 bool clear_mpa_v1)
1902{
1903 struct neighbour *n;
1904 int err, step;
1905 struct net_device *pdev;
1906
1907 n = dst_neigh_lookup(dst, peer_ip);
1908 if (!n)
1909 return -ENODEV;
1910
1911 rcu_read_lock();
1912 err = -ENOMEM;
1913 if (n->dev->flags & IFF_LOOPBACK) {
1914 if (iptype == 4)
1915 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1916 else if (IS_ENABLED(CONFIG_IPV6))
1917 for_each_netdev(&init_net, pdev) {
1918 if (ipv6_chk_addr(&init_net,
1919 (struct in6_addr *)peer_ip,
1920 pdev, 1))
1921 break;
1922 }
1923 else
1924 pdev = NULL;
1925
1926 if (!pdev) {
1927 err = -ENODEV;
1928 goto out;
1929 }
1930 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1931 n, pdev, 0);
1932 if (!ep->l2t)
1933 goto out;
1934 ep->mtu = pdev->mtu;
1935 ep->tx_chan = cxgb4_port_chan(pdev);
1936 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1937 step = cdev->rdev.lldi.ntxq /
1938 cdev->rdev.lldi.nchan;
1939 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1940 step = cdev->rdev.lldi.nrxq /
1941 cdev->rdev.lldi.nchan;
1942 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1943 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1944 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301945 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301946 dev_put(pdev);
1947 } else {
1948 pdev = get_real_dev(n->dev);
1949 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1950 n, pdev, 0);
1951 if (!ep->l2t)
1952 goto out;
1953 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05001954 ep->tx_chan = cxgb4_port_chan(pdev);
1955 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
Vipul Pandya830662f2013-07-04 16:10:47 +05301956 step = cdev->rdev.lldi.ntxq /
1957 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05001958 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1959 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05301960 step = cdev->rdev.lldi.nrxq /
1961 cdev->rdev.lldi.nchan;
1962 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05001963 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301964 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05301965
1966 if (clear_mpa_v1) {
1967 ep->retry_with_mpa_v1 = 0;
1968 ep->tried_with_mpa_v1 = 0;
1969 }
1970 }
1971 err = 0;
1972out:
1973 rcu_read_unlock();
1974
1975 neigh_release(n);
1976
1977 return err;
1978}
1979
Vipul Pandya793dad92012-12-10 09:30:56 +00001980static int c4iw_reconnect(struct c4iw_ep *ep)
1981{
1982 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05301983 struct sockaddr_in *laddr = (struct sockaddr_in *)
1984 &ep->com.cm_id->local_addr;
1985 struct sockaddr_in *raddr = (struct sockaddr_in *)
1986 &ep->com.cm_id->remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301987 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
1988 &ep->com.cm_id->local_addr;
1989 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
1990 &ep->com.cm_id->remote_addr;
1991 int iptype;
1992 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00001993
1994 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1995 init_timer(&ep->timer);
1996
1997 /*
1998 * Allocate an active TID to initiate a TCP connection.
1999 */
2000 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2001 if (ep->atid == -1) {
2002 pr_err("%s - cannot alloc atid.\n", __func__);
2003 err = -ENOMEM;
2004 goto fail2;
2005 }
2006 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2007
2008 /* find a route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302009 if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
2010 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2011 raddr->sin_addr.s_addr, laddr->sin_port,
2012 raddr->sin_port, 0);
2013 iptype = 4;
2014 ra = (__u8 *)&raddr->sin_addr;
2015 } else {
2016 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2017 raddr6->sin6_addr.s6_addr,
2018 laddr6->sin6_port, raddr6->sin6_port, 0,
2019 raddr6->sin6_scope_id);
2020 iptype = 6;
2021 ra = (__u8 *)&raddr6->sin6_addr;
2022 }
2023 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002024 pr_err("%s - cannot find route.\n", __func__);
2025 err = -EHOSTUNREACH;
2026 goto fail3;
2027 }
Vipul Pandya830662f2013-07-04 16:10:47 +05302028 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false);
2029 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002030 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002031 goto fail4;
2032 }
2033
2034 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2035 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2036 ep->l2t->idx);
2037
2038 state_set(&ep->com, CONNECTING);
2039 ep->tos = 0;
2040
2041 /* send connect request to rnic */
2042 err = send_connect(ep);
2043 if (!err)
2044 goto out;
2045
2046 cxgb4_l2t_release(ep->l2t);
2047fail4:
2048 dst_release(ep->dst);
2049fail3:
2050 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2051 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2052fail2:
2053 /*
2054 * remember to send notification to upper layer.
2055 * We are in here so the upper layer is not aware that this is
2056 * re-connect attempt and so, upper layer is still waiting for
2057 * response of 1st connect request.
2058 */
2059 connect_reply_upcall(ep, -ECONNRESET);
2060 c4iw_put_ep(&ep->com);
2061out:
2062 return err;
2063}
2064
Steve Wisecfdda9d2010-04-21 15:30:06 -07002065static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2066{
2067 struct c4iw_ep *ep;
2068 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002069 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2070 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002071 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002072 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302073 struct sockaddr_in *la;
2074 struct sockaddr_in *ra;
2075 struct sockaddr_in6 *la6;
2076 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002077
2078 ep = lookup_atid(t, atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05002079 la = (struct sockaddr_in *)&ep->com.mapped_local_addr;
2080 ra = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
2081 la6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
2082 ra6 = (struct sockaddr_in6 *)&ep->com.mapped_remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002083
2084 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2085 status, status2errno(status));
2086
Steve Wise7a2cea22014-03-14 21:52:07 +05302087 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302088 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2089 __func__, atid, status, neg_adv_str(status));
2090 ep->stats.connect_neg_adv++;
2091 mutex_lock(&dev->rdev.stats.lock);
2092 dev->rdev.stats.neg_adv++;
2093 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002094 return 0;
2095 }
2096
Vipul Pandya793dad92012-12-10 09:30:56 +00002097 set_bit(ACT_OPEN_RPL, &ep->com.history);
2098
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302099 /*
2100 * Log interesting failures.
2101 */
2102 switch (status) {
2103 case CPL_ERR_CONN_RESET:
2104 case CPL_ERR_CONN_TIMEDOUT:
2105 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002106 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302107 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002108 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302109 mutex_unlock(&dev->rdev.stats.lock);
2110 if (ep->com.local_addr.ss_family == AF_INET &&
2111 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002112 send_fw_act_open_req(ep,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002113 TID_TID_G(AOPEN_ATID_G(
Vipul Pandya793dad92012-12-10 09:30:56 +00002114 ntohl(rpl->atid_status))));
2115 return 0;
2116 }
2117 break;
2118 case CPL_ERR_CONN_EXIST:
2119 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2120 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302121 if (ep->com.remote_addr.ss_family == AF_INET6) {
2122 struct sockaddr_in6 *sin6 =
2123 (struct sockaddr_in6 *)
2124 &ep->com.mapped_local_addr;
2125 cxgb4_clip_release(
2126 ep->com.dev->rdev.lldi.ports[0],
2127 (const u32 *)
2128 &sin6->sin6_addr.s6_addr, 1);
2129 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002130 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2131 atid);
2132 cxgb4_free_atid(t, atid);
2133 dst_release(ep->dst);
2134 cxgb4_l2t_release(ep->l2t);
2135 c4iw_reconnect(ep);
2136 return 0;
2137 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002138 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302139 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302140 if (ep->com.local_addr.ss_family == AF_INET) {
2141 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2142 atid, status, status2errno(status),
2143 &la->sin_addr.s_addr, ntohs(la->sin_port),
2144 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2145 } else {
2146 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2147 atid, status, status2errno(status),
2148 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2149 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2150 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302151 break;
2152 }
2153
Steve Wisecfdda9d2010-04-21 15:30:06 -07002154 connect_reply_upcall(ep, status2errno(status));
2155 state_set(&ep->com, DEAD);
2156
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302157 if (ep->com.remote_addr.ss_family == AF_INET6) {
2158 struct sockaddr_in6 *sin6 =
2159 (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
2160 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2161 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2162 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002163 if (status && act_open_has_tid(status))
2164 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2165
Vipul Pandya793dad92012-12-10 09:30:56 +00002166 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002167 cxgb4_free_atid(t, atid);
2168 dst_release(ep->dst);
2169 cxgb4_l2t_release(ep->l2t);
2170 c4iw_put_ep(&ep->com);
2171
2172 return 0;
2173}
2174
2175static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2176{
2177 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2178 struct tid_info *t = dev->rdev.lldi.tids;
2179 unsigned int stid = GET_TID(rpl);
2180 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2181
2182 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002183 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2184 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002185 }
2186 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2187 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002188 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002189
Vipul Pandya1cab7752012-12-10 09:30:55 +00002190out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002191 return 0;
2192}
2193
Steve Wisecfdda9d2010-04-21 15:30:06 -07002194static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2195{
2196 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2197 struct tid_info *t = dev->rdev.lldi.tids;
2198 unsigned int stid = GET_TID(rpl);
2199 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2200
2201 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002202 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002203 return 0;
2204}
2205
Vipul Pandya830662f2013-07-04 16:10:47 +05302206static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002207 struct cpl_pass_accept_req *req)
2208{
2209 struct cpl_pass_accept_rpl *rpl;
2210 unsigned int mtu_idx;
2211 u64 opt0;
2212 u32 opt2;
2213 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302214 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302215 int win;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002216
2217 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2218 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302219
Steve Wisecfdda9d2010-04-21 15:30:06 -07002220 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302221 rpl = cplhdr(skb);
2222 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
2223 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2224 rpl5 = (void *)rpl;
2225 INIT_TP_WR(rpl5, ep->hwtid);
2226 } else {
2227 skb_trim(skb, sizeof(*rpl));
2228 INIT_TP_WR(rpl, ep->hwtid);
2229 }
2230 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2231 ep->hwtid));
2232
2233 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302234 enable_tcp_timestamps && req->tcpopt.tstamp,
2235 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002236 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302237
2238 /*
2239 * Specify the largest window that will fit in opt0. The
2240 * remainder will be specified in the rx_data_ack.
2241 */
2242 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002243 if (win > RCV_BUFSIZ_M)
2244 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002245 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002246 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002247 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002248 WND_SCALE_V(wscale) |
2249 MSS_IDX_V(mtu_idx) |
2250 L2T_IDX_V(ep->l2t->idx) |
2251 TX_CHAN_V(ep->tx_chan) |
2252 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002253 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002254 ULP_MODE_V(ULP_MODE_TCPDDP) |
2255 RCV_BUFSIZ_V(win);
2256 opt2 = RX_CHANNEL_V(0) |
2257 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002258
2259 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002260 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002261 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002262 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002263 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002264 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002265 if (enable_ecn) {
2266 const struct tcphdr *tcph;
2267 u32 hlen = ntohl(req->hdr_len);
2268
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302269 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2270 IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002271 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002272 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002273 }
Steve Wise92e50112014-04-24 14:31:59 -05002274 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302275 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002276 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302277 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302278 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302279 rpl5 = (void *)rpl;
2280 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2281 if (peer2peer)
2282 isn += 4;
2283 rpl5->iss = cpu_to_be32(isn);
2284 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002285 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002286
Steve Wisecfdda9d2010-04-21 15:30:06 -07002287 rpl->opt0 = cpu_to_be64(opt0);
2288 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002289 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wiseb38a0ad2013-08-06 21:04:37 +05302290 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002291 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2292
2293 return;
2294}
2295
Vipul Pandya830662f2013-07-04 16:10:47 +05302296static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002297{
Vipul Pandya830662f2013-07-04 16:10:47 +05302298 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002299 BUG_ON(skb_cloned(skb));
2300 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002301 release_tid(&dev->rdev, hwtid, skb);
2302 return;
2303}
2304
Vipul Pandya830662f2013-07-04 16:10:47 +05302305static void get_4tuple(struct cpl_pass_accept_req *req, int *iptype,
2306 __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002307 __be16 *local_port, __be16 *peer_port)
2308{
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302309 int eth_len = ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2310 int ip_len = IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002311 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302312 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002313 struct tcphdr *tcp = (struct tcphdr *)
2314 ((u8 *)(req + 1) + eth_len + ip_len);
2315
Vipul Pandya830662f2013-07-04 16:10:47 +05302316 if (ip->version == 4) {
2317 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2318 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2319 ntohs(tcp->dest));
2320 *iptype = 4;
2321 memcpy(peer_ip, &ip->saddr, 4);
2322 memcpy(local_ip, &ip->daddr, 4);
2323 } else {
2324 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2325 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2326 ntohs(tcp->dest));
2327 *iptype = 6;
2328 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2329 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2330 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002331 *peer_port = tcp->source;
2332 *local_port = tcp->dest;
2333
2334 return;
2335}
2336
2337static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2338{
Vipul Pandya793dad92012-12-10 09:30:56 +00002339 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002340 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002341 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002342 struct tid_info *t = dev->rdev.lldi.tids;
2343 unsigned int hwtid = GET_TID(req);
2344 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302345 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002346 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302347 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002348 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002349 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302350 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302351 unsigned short hdrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002352
2353 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002354 if (!parent_ep) {
2355 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2356 goto reject;
2357 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002358
Steve Wisecfdda9d2010-04-21 15:30:06 -07002359 if (state_read(&parent_ep->com) != LISTEN) {
2360 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
2361 __func__);
2362 goto reject;
2363 }
2364
Vipul Pandya830662f2013-07-04 16:10:47 +05302365 get_4tuple(req, &iptype, local_ip, peer_ip, &local_port, &peer_port);
2366
Steve Wisecfdda9d2010-04-21 15:30:06 -07002367 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302368 if (iptype == 4) {
2369 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2370 , __func__, parent_ep, hwtid,
2371 local_ip, peer_ip, ntohs(local_port),
2372 ntohs(peer_port), peer_mss);
2373 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2374 local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002375 PASS_OPEN_TOS_G(ntohl(req->tos_stid)));
Vipul Pandya830662f2013-07-04 16:10:47 +05302376 } else {
2377 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2378 , __func__, parent_ep, hwtid,
2379 local_ip, peer_ip, ntohs(local_port),
2380 ntohs(peer_port), peer_mss);
2381 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002382 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302383 ((struct sockaddr_in6 *)
2384 &parent_ep->com.local_addr)->sin6_scope_id);
2385 }
2386 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002387 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2388 __func__);
2389 goto reject;
2390 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002391
2392 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2393 if (!child_ep) {
2394 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2395 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002396 dst_release(dst);
2397 goto reject;
2398 }
David Miller3786cf12011-12-02 16:52:31 +00002399
Vipul Pandya830662f2013-07-04 16:10:47 +05302400 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false);
David Miller3786cf12011-12-02 16:52:31 +00002401 if (err) {
2402 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2403 __func__);
2404 dst_release(dst);
2405 kfree(child_ep);
2406 goto reject;
2407 }
2408
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302409 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2410 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2411 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2412 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002413
Steve Wisecfdda9d2010-04-21 15:30:06 -07002414 state_set(&child_ep->com, CONNECTING);
2415 child_ep->com.dev = dev;
2416 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002417
2418 /*
2419 * The mapped_local and mapped_remote addresses get setup with
2420 * the actual 4-tuple. The local address will be based on the
2421 * actual local address of the connection, but on the port number
2422 * of the parent listening endpoint. The remote address is
2423 * setup based on a query to the IWPM since we don't know what it
2424 * originally was before mapping. If no mapping was done, then
2425 * mapped_remote == remote, and mapped_local == local.
2426 */
Vipul Pandya830662f2013-07-04 16:10:47 +05302427 if (iptype == 4) {
2428 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002429 &child_ep->com.mapped_local_addr;
2430
Vipul Pandya830662f2013-07-04 16:10:47 +05302431 sin->sin_family = PF_INET;
2432 sin->sin_port = local_port;
2433 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002434
2435 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2436 sin->sin_family = PF_INET;
2437 sin->sin_port = ((struct sockaddr_in *)
2438 &parent_ep->com.local_addr)->sin_port;
2439 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2440
2441 sin = (struct sockaddr_in *)&child_ep->com.mapped_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302442 sin->sin_family = PF_INET;
2443 sin->sin_port = peer_port;
2444 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2445 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302446 sin6 = (struct sockaddr_in6 *)&child_ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302447 sin6->sin6_family = PF_INET6;
2448 sin6->sin6_port = local_port;
2449 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002450
2451 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2452 sin6->sin6_family = PF_INET6;
2453 sin6->sin6_port = ((struct sockaddr_in6 *)
2454 &parent_ep->com.local_addr)->sin6_port;
2455 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2456
2457 sin6 = (struct sockaddr_in6 *)&child_ep->com.mapped_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302458 sin6->sin6_family = PF_INET6;
2459 sin6->sin6_port = peer_port;
2460 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2461 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002462 memcpy(&child_ep->com.remote_addr, &child_ep->com.mapped_remote_addr,
2463 sizeof(child_ep->com.remote_addr));
Steve Wise940fd302015-05-07 16:34:23 -05002464 get_remote_addr(parent_ep, child_ep);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002465
Steve Wisecfdda9d2010-04-21 15:30:06 -07002466 c4iw_get_ep(&parent_ep->com);
2467 child_ep->parent_ep = parent_ep;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002468 child_ep->tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002469 child_ep->dst = dst;
2470 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002471
2472 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002473 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002474
2475 init_timer(&child_ep->timer);
2476 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002477 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Vipul Pandya830662f2013-07-04 16:10:47 +05302478 accept_cr(child_ep, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00002479 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302480 if (iptype == 6) {
2481 sin6 = (struct sockaddr_in6 *)&child_ep->com.mapped_local_addr;
2482 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2483 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2484 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002485 goto out;
2486reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302487 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002488out:
2489 return 0;
2490}
2491
2492static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2493{
2494 struct c4iw_ep *ep;
2495 struct cpl_pass_establish *req = cplhdr(skb);
2496 struct tid_info *t = dev->rdev.lldi.tids;
2497 unsigned int tid = GET_TID(req);
2498
2499 ep = lookup_tid(t, tid);
2500 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2501 ep->snd_seq = be32_to_cpu(req->snd_isn);
2502 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2503
Vipul Pandya1cab7752012-12-10 09:30:55 +00002504 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2505 ntohs(req->tcp_opt));
2506
Steve Wisecfdda9d2010-04-21 15:30:06 -07002507 set_emss(ep, ntohs(req->tcp_opt));
2508
2509 dst_confirm(ep->dst);
2510 state_set(&ep->com, MPA_REQ_WAIT);
2511 start_ep_timer(ep);
2512 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002513 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002514
2515 return 0;
2516}
2517
2518static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2519{
2520 struct cpl_peer_close *hdr = cplhdr(skb);
2521 struct c4iw_ep *ep;
2522 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002523 int disconnect = 1;
2524 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002525 struct tid_info *t = dev->rdev.lldi.tids;
2526 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002527 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002528
2529 ep = lookup_tid(t, tid);
2530 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2531 dst_confirm(ep->dst);
2532
Vipul Pandya793dad92012-12-10 09:30:56 +00002533 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002534 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002535 switch (ep->com.state) {
2536 case MPA_REQ_WAIT:
2537 __state_set(&ep->com, CLOSING);
2538 break;
2539 case MPA_REQ_SENT:
2540 __state_set(&ep->com, CLOSING);
2541 connect_reply_upcall(ep, -ECONNRESET);
2542 break;
2543 case MPA_REQ_RCVD:
2544
2545 /*
2546 * We're gonna mark this puppy DEAD, but keep
2547 * the reference on it until the ULP accepts or
2548 * rejects the CR. Also wake up anyone waiting
2549 * in rdma connection migration (see c4iw_accept_cr()).
2550 */
2551 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002552 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002553 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002554 break;
2555 case MPA_REP_SENT:
2556 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002557 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002558 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002559 break;
2560 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002561 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002562 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002563 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002564 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002565 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002566 if (ret != -ECONNRESET) {
2567 peer_close_upcall(ep);
2568 disconnect = 1;
2569 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002570 break;
2571 case ABORTING:
2572 disconnect = 0;
2573 break;
2574 case CLOSING:
2575 __state_set(&ep->com, MORIBUND);
2576 disconnect = 0;
2577 break;
2578 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002579 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002580 if (ep->com.cm_id && ep->com.qp) {
2581 attrs.next_state = C4IW_QP_STATE_IDLE;
2582 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2583 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2584 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302585 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002586 __state_set(&ep->com, DEAD);
2587 release = 1;
2588 disconnect = 0;
2589 break;
2590 case DEAD:
2591 disconnect = 0;
2592 break;
2593 default:
2594 BUG_ON(1);
2595 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002596 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002597 if (disconnect)
2598 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2599 if (release)
2600 release_ep_resources(ep);
2601 return 0;
2602}
2603
Steve Wisecfdda9d2010-04-21 15:30:06 -07002604static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2605{
2606 struct cpl_abort_req_rss *req = cplhdr(skb);
2607 struct c4iw_ep *ep;
2608 struct cpl_abort_rpl *rpl;
2609 struct sk_buff *rpl_skb;
2610 struct c4iw_qp_attributes attrs;
2611 int ret;
2612 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002613 struct tid_info *t = dev->rdev.lldi.tids;
2614 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002615
2616 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302617 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302618 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2619 __func__, ep->hwtid, req->status,
2620 neg_adv_str(req->status));
2621 ep->stats.abort_neg_adv++;
2622 mutex_lock(&dev->rdev.stats.lock);
2623 dev->rdev.stats.neg_adv++;
2624 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002625 return 0;
2626 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002627 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2628 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002629 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002630
2631 /*
2632 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302633 * However, this is not needed if com state is just
2634 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002635 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302636 if (ep->com.state != MPA_REQ_SENT)
2637 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002638
2639 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002640 switch (ep->com.state) {
2641 case CONNECTING:
2642 break;
2643 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002644 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002645 break;
2646 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002647 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002648 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302649 connect_reply_upcall(ep, -ECONNRESET);
2650 else {
2651 /*
2652 * we just don't send notification upwards because we
2653 * want to retry with mpa_v1 without upper layers even
2654 * knowing it.
2655 *
2656 * do some housekeeping so as to re-initiate the
2657 * connection
2658 */
2659 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2660 mpa_rev);
2661 ep->retry_with_mpa_v1 = 1;
2662 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002663 break;
2664 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002665 break;
2666 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002667 break;
2668 case MORIBUND:
2669 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002670 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002671 /*FALLTHROUGH*/
2672 case FPDU_MODE:
2673 if (ep->com.cm_id && ep->com.qp) {
2674 attrs.next_state = C4IW_QP_STATE_ERROR;
2675 ret = c4iw_modify_qp(ep->com.qp->rhp,
2676 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2677 &attrs, 1);
2678 if (ret)
2679 printk(KERN_ERR MOD
2680 "%s - qp <- error failed!\n",
2681 __func__);
2682 }
2683 peer_abort_upcall(ep);
2684 break;
2685 case ABORTING:
2686 break;
2687 case DEAD:
2688 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002689 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002690 return 0;
2691 default:
2692 BUG_ON(1);
2693 break;
2694 }
2695 dst_confirm(ep->dst);
2696 if (ep->com.state != ABORTING) {
2697 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302698 /* we don't release if we want to retry with mpa_v1 */
2699 if (!ep->retry_with_mpa_v1)
2700 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002701 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002702 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002703
2704 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2705 if (!rpl_skb) {
2706 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2707 __func__);
2708 release = 1;
2709 goto out;
2710 }
2711 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2712 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2713 INIT_TP_WR(rpl, ep->hwtid);
2714 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2715 rpl->cmd = CPL_ABORT_NO_RST;
2716 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2717out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002718 if (release)
2719 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002720 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302721 if (ep->com.remote_addr.ss_family == AF_INET6) {
2722 struct sockaddr_in6 *sin6 =
2723 (struct sockaddr_in6 *)
2724 &ep->com.mapped_local_addr;
2725 cxgb4_clip_release(
2726 ep->com.dev->rdev.lldi.ports[0],
2727 (const u32 *)&sin6->sin6_addr.s6_addr,
2728 1);
2729 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002730 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302731 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2732 dst_release(ep->dst);
2733 cxgb4_l2t_release(ep->l2t);
2734 c4iw_reconnect(ep);
2735 }
2736
Steve Wisecfdda9d2010-04-21 15:30:06 -07002737 return 0;
2738}
2739
2740static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2741{
2742 struct c4iw_ep *ep;
2743 struct c4iw_qp_attributes attrs;
2744 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002745 int release = 0;
2746 struct tid_info *t = dev->rdev.lldi.tids;
2747 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002748
2749 ep = lookup_tid(t, tid);
2750
2751 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2752 BUG_ON(!ep);
2753
2754 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002755 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002756 switch (ep->com.state) {
2757 case CLOSING:
2758 __state_set(&ep->com, MORIBUND);
2759 break;
2760 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002761 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002762 if ((ep->com.cm_id) && (ep->com.qp)) {
2763 attrs.next_state = C4IW_QP_STATE_IDLE;
2764 c4iw_modify_qp(ep->com.qp->rhp,
2765 ep->com.qp,
2766 C4IW_QP_ATTR_NEXT_STATE,
2767 &attrs, 1);
2768 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302769 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002770 __state_set(&ep->com, DEAD);
2771 release = 1;
2772 break;
2773 case ABORTING:
2774 case DEAD:
2775 break;
2776 default:
2777 BUG_ON(1);
2778 break;
2779 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002780 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002781 if (release)
2782 release_ep_resources(ep);
2783 return 0;
2784}
2785
2786static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2787{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002788 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002789 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002790 unsigned int tid = GET_TID(rpl);
2791 struct c4iw_ep *ep;
2792 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002793
2794 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002795 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002796
Steve Wise30c95c22011-05-09 22:06:22 -07002797 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002798 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2799 ep->com.qp->wq.sq.qid);
2800 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2801 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2802 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2803 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002804 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002805
Steve Wisecfdda9d2010-04-21 15:30:06 -07002806 return 0;
2807}
2808
2809/*
2810 * Upcall from the adapter indicating data has been transmitted.
2811 * For us its just the single MPA request or reply. We can now free
2812 * the skb holding the mpa message.
2813 */
2814static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2815{
2816 struct c4iw_ep *ep;
2817 struct cpl_fw4_ack *hdr = cplhdr(skb);
2818 u8 credits = hdr->credits;
2819 unsigned int tid = GET_TID(hdr);
2820 struct tid_info *t = dev->rdev.lldi.tids;
2821
2822
2823 ep = lookup_tid(t, tid);
2824 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2825 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002826 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2827 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002828 return 0;
2829 }
2830
2831 dst_confirm(ep->dst);
2832 if (ep->mpa_skb) {
2833 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2834 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2835 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2836 kfree_skb(ep->mpa_skb);
2837 ep->mpa_skb = NULL;
2838 }
2839 return 0;
2840}
2841
Steve Wisecfdda9d2010-04-21 15:30:06 -07002842int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2843{
Steve Wisea7db89e2014-03-21 20:40:35 +05302844 int err = 0;
2845 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002846 struct c4iw_ep *ep = to_ep(cm_id);
2847 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2848
Steve Wisea7db89e2014-03-21 20:40:35 +05302849 mutex_lock(&ep->com.mutex);
2850 if (ep->com.state == DEAD) {
2851 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002852 c4iw_put_ep(&ep->com);
2853 return -ECONNRESET;
2854 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002855 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302856 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002857 if (mpa_rev == 0)
2858 abort_connection(ep, NULL, GFP_KERNEL);
2859 else {
2860 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302861 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002862 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302863 mutex_unlock(&ep->com.mutex);
2864 if (disconnect)
2865 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002866 c4iw_put_ep(&ep->com);
2867 return 0;
2868}
2869
2870int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2871{
2872 int err;
2873 struct c4iw_qp_attributes attrs;
2874 enum c4iw_qp_attr_mask mask;
2875 struct c4iw_ep *ep = to_ep(cm_id);
2876 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2877 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2878
2879 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302880
2881 mutex_lock(&ep->com.mutex);
2882 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002883 err = -ECONNRESET;
2884 goto err;
2885 }
2886
Steve Wisea7db89e2014-03-21 20:40:35 +05302887 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002888 BUG_ON(!qp);
2889
Vipul Pandya793dad92012-12-10 09:30:56 +00002890 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302891 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2892 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002893 abort_connection(ep, NULL, GFP_KERNEL);
2894 err = -EINVAL;
2895 goto err;
2896 }
2897
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302898 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2899 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302900 if (RELAXED_IRD_NEGOTIATION) {
2901 ep->ord = ep->ird;
2902 } else {
2903 ep->ird = conn_param->ird;
2904 ep->ord = conn_param->ord;
2905 send_mpa_reject(ep, conn_param->private_data,
2906 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302907 abort_connection(ep, NULL, GFP_KERNEL);
2908 err = -ENOMEM;
2909 goto err;
2910 }
2911 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302912 if (conn_param->ird < ep->ord) {
2913 if (RELAXED_IRD_NEGOTIATION &&
2914 ep->ord <= h->rdev.lldi.max_ordird_qp) {
2915 conn_param->ird = ep->ord;
2916 } else {
2917 abort_connection(ep, NULL, GFP_KERNEL);
2918 err = -ENOMEM;
2919 goto err;
2920 }
2921 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302922 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002923 ep->ird = conn_param->ird;
2924 ep->ord = conn_param->ord;
2925
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302926 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302927 if (peer2peer && ep->ird == 0)
2928 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302929 } else {
2930 if (peer2peer &&
2931 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
2932 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ord == 0)
2933 ep->ird = 1;
2934 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002935
2936 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2937
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302938 cm_id->add_ref(cm_id);
2939 ep->com.cm_id = cm_id;
2940 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00002941 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302942
Steve Wisecfdda9d2010-04-21 15:30:06 -07002943 /* bind QP to EP and move to RTS */
2944 attrs.mpa_attr = ep->mpa_attr;
2945 attrs.max_ird = ep->ird;
2946 attrs.max_ord = ep->ord;
2947 attrs.llp_stream_handle = ep;
2948 attrs.next_state = C4IW_QP_STATE_RTS;
2949
2950 /* bind QP and TID with INIT_WR */
2951 mask = C4IW_QP_ATTR_NEXT_STATE |
2952 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2953 C4IW_QP_ATTR_MPA_ATTR |
2954 C4IW_QP_ATTR_MAX_IRD |
2955 C4IW_QP_ATTR_MAX_ORD;
2956
2957 err = c4iw_modify_qp(ep->com.qp->rhp,
2958 ep->com.qp, mask, &attrs, 1);
2959 if (err)
2960 goto err1;
2961 err = send_mpa_reply(ep, conn_param->private_data,
2962 conn_param->private_data_len);
2963 if (err)
2964 goto err1;
2965
Steve Wisea7db89e2014-03-21 20:40:35 +05302966 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002967 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05302968 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002969 c4iw_put_ep(&ep->com);
2970 return 0;
2971err1:
2972 ep->com.cm_id = NULL;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302973 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002974 cm_id->rem_ref(cm_id);
2975err:
Steve Wisea7db89e2014-03-21 20:40:35 +05302976 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002977 c4iw_put_ep(&ep->com);
2978 return err;
2979}
2980
Vipul Pandya830662f2013-07-04 16:10:47 +05302981static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2982{
2983 struct in_device *ind;
2984 int found = 0;
2985 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2986 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
2987
2988 ind = in_dev_get(dev->rdev.lldi.ports[0]);
2989 if (!ind)
2990 return -EADDRNOTAVAIL;
2991 for_primary_ifa(ind) {
2992 laddr->sin_addr.s_addr = ifa->ifa_address;
2993 raddr->sin_addr.s_addr = ifa->ifa_address;
2994 found = 1;
2995 break;
2996 }
2997 endfor_ifa(ind);
2998 in_dev_put(ind);
2999 return found ? 0 : -EADDRNOTAVAIL;
3000}
3001
3002static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3003 unsigned char banned_flags)
3004{
3005 struct inet6_dev *idev;
3006 int err = -EADDRNOTAVAIL;
3007
3008 rcu_read_lock();
3009 idev = __in6_dev_get(dev);
3010 if (idev != NULL) {
3011 struct inet6_ifaddr *ifp;
3012
3013 read_lock_bh(&idev->lock);
3014 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3015 if (ifp->scope == IFA_LINK &&
3016 !(ifp->flags & banned_flags)) {
3017 memcpy(addr, &ifp->addr, 16);
3018 err = 0;
3019 break;
3020 }
3021 }
3022 read_unlock_bh(&idev->lock);
3023 }
3024 rcu_read_unlock();
3025 return err;
3026}
3027
3028static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3029{
3030 struct in6_addr uninitialized_var(addr);
3031 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
3032 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
3033
Nicholas Krause54b9a962015-08-26 23:00:59 -04003034 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303035 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3036 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3037 return 0;
3038 }
3039 return -EADDRNOTAVAIL;
3040}
3041
Steve Wisecfdda9d2010-04-21 15:30:06 -07003042int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3043{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003044 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3045 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003046 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003047 struct sockaddr_in *laddr;
3048 struct sockaddr_in *raddr;
3049 struct sockaddr_in6 *laddr6;
3050 struct sockaddr_in6 *raddr6;
3051 struct iwpm_dev_data pm_reg_msg;
3052 struct iwpm_sa_data pm_msg;
Vipul Pandya830662f2013-07-04 16:10:47 +05303053 __u8 *ra;
3054 int iptype;
Steve Wise9eccfe12014-03-26 17:08:09 -05003055 int iwpm_err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003056
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303057 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3058 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003059 err = -EINVAL;
3060 goto out;
3061 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003062 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3063 if (!ep) {
3064 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3065 err = -ENOMEM;
3066 goto out;
3067 }
3068 init_timer(&ep->timer);
3069 ep->plen = conn_param->private_data_len;
3070 if (ep->plen)
3071 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3072 conn_param->private_data, ep->plen);
3073 ep->ird = conn_param->ird;
3074 ep->ord = conn_param->ord;
3075
3076 if (peer2peer && ep->ord == 0)
3077 ep->ord = 1;
3078
3079 cm_id->add_ref(cm_id);
3080 ep->com.dev = dev;
3081 ep->com.cm_id = cm_id;
3082 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303083 if (!ep->com.qp) {
3084 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3085 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003086 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303087 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003088 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003089 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3090 ep->com.qp, cm_id);
3091
3092 /*
3093 * Allocate an active TID to initiate a TCP connection.
3094 */
3095 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3096 if (ep->atid == -1) {
3097 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3098 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003099 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003100 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003101 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003102
Steve Wise9eccfe12014-03-26 17:08:09 -05003103 memcpy(&ep->com.local_addr, &cm_id->local_addr,
3104 sizeof(ep->com.local_addr));
3105 memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
3106 sizeof(ep->com.remote_addr));
3107
3108 /* No port mapper available, go with the specified peer information */
3109 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3110 sizeof(ep->com.mapped_local_addr));
3111 memcpy(&ep->com.mapped_remote_addr, &cm_id->remote_addr,
3112 sizeof(ep->com.mapped_remote_addr));
3113
3114 c4iw_form_reg_msg(dev, &pm_reg_msg);
3115 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3116 if (iwpm_err) {
3117 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3118 __func__, iwpm_err);
3119 }
3120 if (iwpm_valid_pid() && !iwpm_err) {
3121 c4iw_form_pm_msg(ep, &pm_msg);
3122 iwpm_err = iwpm_add_and_query_mapping(&pm_msg, RDMA_NL_C4IW);
3123 if (iwpm_err)
3124 PDBG("%s: Port Mapper query fail (err = %d).\n",
3125 __func__, iwpm_err);
3126 else
3127 c4iw_record_pm_msg(ep, &pm_msg);
3128 }
3129 if (iwpm_create_mapinfo(&ep->com.local_addr,
3130 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3131 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
3132 err = -ENOMEM;
3133 goto fail1;
3134 }
3135 print_addr(&ep->com, __func__, "add_query/create_mapinfo");
3136 set_bit(RELEASE_MAPINFO, &ep->com.flags);
3137
3138 laddr = (struct sockaddr_in *)&ep->com.mapped_local_addr;
3139 raddr = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
3140 laddr6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
3141 raddr6 = (struct sockaddr_in6 *) &ep->com.mapped_remote_addr;
3142
Vipul Pandya830662f2013-07-04 16:10:47 +05303143 if (cm_id->remote_addr.ss_family == AF_INET) {
3144 iptype = 4;
3145 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003146
Vipul Pandya830662f2013-07-04 16:10:47 +05303147 /*
3148 * Handle loopback requests to INADDR_ANY.
3149 */
3150 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3151 err = pick_local_ipaddrs(dev, cm_id);
3152 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003153 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303154 }
3155
3156 /* find a route */
3157 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3158 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3159 ra, ntohs(raddr->sin_port));
3160 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3161 raddr->sin_addr.s_addr, laddr->sin_port,
3162 raddr->sin_port, 0);
3163 } else {
3164 iptype = 6;
3165 ra = (__u8 *)&raddr6->sin6_addr;
3166
3167 /*
3168 * Handle loopback requests to INADDR_ANY.
3169 */
3170 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3171 err = pick_local_ip6addrs(dev, cm_id);
3172 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003173 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303174 }
3175
3176 /* find a route */
3177 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3178 __func__, laddr6->sin6_addr.s6_addr,
3179 ntohs(laddr6->sin6_port),
3180 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3181 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3182 raddr6->sin6_addr.s6_addr,
3183 laddr6->sin6_port, raddr6->sin6_port, 0,
3184 raddr6->sin6_scope_id);
3185 }
3186 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003187 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3188 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003189 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003190 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003191
Vipul Pandya830662f2013-07-04 16:10:47 +05303192 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true);
David Miller3786cf12011-12-02 16:52:31 +00003193 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003194 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003195 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003196 }
3197
3198 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3199 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3200 ep->l2t->idx);
3201
3202 state_set(&ep->com, CONNECTING);
3203 ep->tos = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003204
3205 /* send connect request to rnic */
3206 err = send_connect(ep);
3207 if (!err)
3208 goto out;
3209
3210 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003211fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003212 dst_release(ep->dst);
3213fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003214 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003215 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003216fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003217 cm_id->rem_ref(cm_id);
3218 c4iw_put_ep(&ep->com);
3219out:
3220 return err;
3221}
3222
Vipul Pandya830662f2013-07-04 16:10:47 +05303223static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3224{
3225 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003226 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
3227 &ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303228
3229 c4iw_init_wr_wait(&ep->com.wr_wait);
3230 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3231 ep->stid, &sin6->sin6_addr,
3232 sin6->sin6_port,
3233 ep->com.dev->rdev.lldi.rxq_ids[0]);
3234 if (!err)
3235 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3236 &ep->com.wr_wait,
3237 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303238 else if (err > 0)
3239 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303240 if (err)
3241 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3242 err, ep->stid,
3243 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303244 else
3245 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3246 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303247 return err;
3248}
3249
3250static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3251{
3252 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003253 struct sockaddr_in *sin = (struct sockaddr_in *)
3254 &ep->com.mapped_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303255
3256 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3257 do {
3258 err = cxgb4_create_server_filter(
3259 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3260 sin->sin_addr.s_addr, sin->sin_port, 0,
3261 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3262 if (err == -EBUSY) {
3263 set_current_state(TASK_UNINTERRUPTIBLE);
3264 schedule_timeout(usecs_to_jiffies(100));
3265 }
3266 } while (err == -EBUSY);
3267 } else {
3268 c4iw_init_wr_wait(&ep->com.wr_wait);
3269 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3270 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3271 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3272 if (!err)
3273 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3274 &ep->com.wr_wait,
3275 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303276 else if (err > 0)
3277 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303278 }
3279 if (err)
3280 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3281 , err, ep->stid,
3282 &sin->sin_addr, ntohs(sin->sin_port));
3283 return err;
3284}
3285
Steve Wisecfdda9d2010-04-21 15:30:06 -07003286int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3287{
3288 int err = 0;
3289 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3290 struct c4iw_listen_ep *ep;
Steve Wise9eccfe12014-03-26 17:08:09 -05003291 struct iwpm_dev_data pm_reg_msg;
3292 struct iwpm_sa_data pm_msg;
3293 int iwpm_err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003294
Steve Wisecfdda9d2010-04-21 15:30:06 -07003295 might_sleep();
3296
3297 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3298 if (!ep) {
3299 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3300 err = -ENOMEM;
3301 goto fail1;
3302 }
3303 PDBG("%s ep %p\n", __func__, ep);
3304 cm_id->add_ref(cm_id);
3305 ep->com.cm_id = cm_id;
3306 ep->com.dev = dev;
3307 ep->backlog = backlog;
Steve Wise24d44a32013-07-04 16:10:44 +05303308 memcpy(&ep->com.local_addr, &cm_id->local_addr,
3309 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003310
3311 /*
3312 * Allocate a server TID.
3313 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303314 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3315 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303316 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
3317 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003318 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303319 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
3320 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003321
Steve Wisecfdda9d2010-04-21 15:30:06 -07003322 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003323 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003324 err = -ENOMEM;
3325 goto fail2;
3326 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003327 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003328
3329 /* No port mapper available, go with the specified info */
3330 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3331 sizeof(ep->com.mapped_local_addr));
3332
3333 c4iw_form_reg_msg(dev, &pm_reg_msg);
3334 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3335 if (iwpm_err) {
3336 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3337 __func__, iwpm_err);
3338 }
3339 if (iwpm_valid_pid() && !iwpm_err) {
3340 memcpy(&pm_msg.loc_addr, &ep->com.local_addr,
3341 sizeof(ep->com.local_addr));
3342 iwpm_err = iwpm_add_mapping(&pm_msg, RDMA_NL_C4IW);
3343 if (iwpm_err)
3344 PDBG("%s: Port Mapper query fail (err = %d).\n",
3345 __func__, iwpm_err);
3346 else
3347 memcpy(&ep->com.mapped_local_addr,
3348 &pm_msg.mapped_loc_addr,
3349 sizeof(ep->com.mapped_local_addr));
3350 }
3351 if (iwpm_create_mapinfo(&ep->com.local_addr,
3352 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3353 err = -ENOMEM;
3354 goto fail3;
3355 }
3356 print_addr(&ep->com, __func__, "add_mapping/create_mapinfo");
3357
3358 set_bit(RELEASE_MAPINFO, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003359 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303360 if (ep->com.local_addr.ss_family == AF_INET)
3361 err = create_server4(dev, ep);
3362 else
3363 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003364 if (!err) {
3365 cm_id->provider_data = ep;
3366 goto out;
3367 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003368
3369fail3:
Vipul Pandya830662f2013-07-04 16:10:47 +05303370 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3371 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003372fail2:
3373 cm_id->rem_ref(cm_id);
3374 c4iw_put_ep(&ep->com);
3375fail1:
3376out:
3377 return err;
3378}
3379
3380int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3381{
3382 int err;
3383 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3384
3385 PDBG("%s ep %p\n", __func__, ep);
3386
3387 might_sleep();
3388 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303389 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3390 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003391 err = cxgb4_remove_server_filter(
3392 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3393 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3394 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303395 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003396 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303397 err = cxgb4_remove_server(
3398 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3399 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003400 if (err)
3401 goto done;
3402 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3403 0, 0, __func__);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303404 sin6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
3405 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3406 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003407 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003408 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303409 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3410 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003411done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003412 cm_id->rem_ref(cm_id);
3413 c4iw_put_ep(&ep->com);
3414 return err;
3415}
3416
3417int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3418{
3419 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003420 int close = 0;
3421 int fatal = 0;
3422 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003423
Steve Wise2f5b48c2010-09-10 11:15:36 -05003424 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003425
3426 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3427 states[ep->com.state], abrupt);
3428
3429 rdev = &ep->com.dev->rdev;
3430 if (c4iw_fatal_error(rdev)) {
3431 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303432 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003433 ep->com.state = DEAD;
3434 }
3435 switch (ep->com.state) {
3436 case MPA_REQ_WAIT:
3437 case MPA_REQ_SENT:
3438 case MPA_REQ_RCVD:
3439 case MPA_REP_SENT:
3440 case FPDU_MODE:
3441 close = 1;
3442 if (abrupt)
3443 ep->com.state = ABORTING;
3444 else {
3445 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003446 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003447 }
3448 set_bit(CLOSE_SENT, &ep->com.flags);
3449 break;
3450 case CLOSING:
3451 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3452 close = 1;
3453 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003454 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003455 ep->com.state = ABORTING;
3456 } else
3457 ep->com.state = MORIBUND;
3458 }
3459 break;
3460 case MORIBUND:
3461 case ABORTING:
3462 case DEAD:
3463 PDBG("%s ignoring disconnect ep %p state %u\n",
3464 __func__, ep, ep->com.state);
3465 break;
3466 default:
3467 BUG();
3468 break;
3469 }
3470
Steve Wisecfdda9d2010-04-21 15:30:06 -07003471 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003472 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003473 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303474 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003475 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003476 } else {
3477 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003478 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003479 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003480 if (ret)
3481 fatal = 1;
3482 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003483 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003484 if (fatal)
3485 release_ep_resources(ep);
3486 return ret;
3487}
3488
Vipul Pandya1cab7752012-12-10 09:30:55 +00003489static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3490 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3491{
3492 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003493 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003494
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003495 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3496 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003497 if (!ep)
3498 return;
3499
3500 switch (req->retval) {
3501 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003502 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3503 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3504 send_fw_act_open_req(ep, atid);
3505 return;
3506 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003507 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003508 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3509 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3510 send_fw_act_open_req(ep, atid);
3511 return;
3512 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003513 break;
3514 default:
3515 pr_info("%s unexpected ofld conn wr retval %d\n",
3516 __func__, req->retval);
3517 break;
3518 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003519 pr_err("active ofld_connect_wr failure %d atid %d\n",
3520 req->retval, atid);
3521 mutex_lock(&dev->rdev.stats.lock);
3522 dev->rdev.stats.act_ofld_conn_fails++;
3523 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003524 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003525 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303526 if (ep->com.remote_addr.ss_family == AF_INET6) {
3527 struct sockaddr_in6 *sin6 =
3528 (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
3529 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3530 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3531 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003532 remove_handle(dev, &dev->atid_idr, atid);
3533 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3534 dst_release(ep->dst);
3535 cxgb4_l2t_release(ep->l2t);
3536 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003537}
3538
3539static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3540 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3541{
3542 struct sk_buff *rpl_skb;
3543 struct cpl_pass_accept_req *cpl;
3544 int ret;
3545
Paul Bolle710a3112013-02-05 20:51:30 +00003546 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003547 BUG_ON(!rpl_skb);
3548 if (req->retval) {
3549 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003550 mutex_lock(&dev->rdev.stats.lock);
3551 dev->rdev.stats.pas_ofld_conn_fails++;
3552 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003553 kfree_skb(rpl_skb);
3554 } else {
3555 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3556 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003557 (__force u32) htonl(
3558 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003559 ret = pass_accept_req(dev, rpl_skb);
3560 if (!ret)
3561 kfree_skb(rpl_skb);
3562 }
3563 return;
3564}
3565
3566static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003567{
3568 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003569 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3570
3571 switch (rpl->type) {
3572 case FW6_TYPE_CQE:
3573 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3574 break;
3575 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3576 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3577 switch (req->t_state) {
3578 case TCP_SYN_SENT:
3579 active_ofld_conn_reply(dev, skb, req);
3580 break;
3581 case TCP_SYN_RECV:
3582 passive_ofld_conn_reply(dev, skb, req);
3583 break;
3584 default:
3585 pr_err("%s unexpected ofld conn wr state %d\n",
3586 __func__, req->t_state);
3587 break;
3588 }
3589 break;
3590 }
3591 return 0;
3592}
3593
3594static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3595{
3596 u32 l2info;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003597 u16 vlantag, len, hdr_len, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003598 u8 intf;
3599 struct cpl_rx_pkt *cpl = cplhdr(skb);
3600 struct cpl_pass_accept_req *req;
3601 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003602 struct c4iw_dev *dev;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003603
Vipul Pandyaf079af72013-03-14 05:08:58 +00003604 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003605 /* Store values from cpl_rx_pkt in temporary location. */
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003606 vlantag = (__force u16) cpl->vlan;
3607 len = (__force u16) cpl->len;
3608 l2info = (__force u32) cpl->l2info;
3609 hdr_len = (__force u16) cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003610 intf = cpl->iff;
3611
3612 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3613
3614 /*
3615 * We need to parse the TCP options from SYN packet.
3616 * to generate cpl_pass_accept_req.
3617 */
3618 memset(&tmp_opt, 0, sizeof(tmp_opt));
3619 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003620 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003621
3622 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3623 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303624 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3625 SYN_MAC_IDX_V(RX_MACIDX_G(
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003626 (__force int) htonl(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303627 SYN_XACT_MATCH_F);
Vipul Pandyaf079af72013-03-14 05:08:58 +00003628 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003629 RX_ETHHDR_LEN_G((__force int)htonl(l2info)) :
3630 RX_T5_ETHHDR_LEN_G((__force int)htonl(l2info));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303631 req->hdr_len = cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003632 (__force int) htonl(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303633 TCP_HDR_LEN_V(RX_TCPHDR_LEN_G(
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003634 (__force int) htons(hdr_len))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303635 IP_HDR_LEN_V(RX_IPHDR_LEN_G(
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003636 (__force int) htons(hdr_len))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303637 ETH_HDR_LEN_V(RX_ETHHDR_LEN_G(eth_hdr_len)));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003638 req->vlan = (__force __be16) vlantag;
3639 req->len = (__force __be16) len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003640 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3641 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003642 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3643 if (tmp_opt.wscale_ok)
3644 req->tcpopt.wsf = tmp_opt.snd_wscale;
3645 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3646 if (tmp_opt.sack_ok)
3647 req->tcpopt.sack = 1;
3648 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3649 return;
3650}
3651
3652static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3653 __be32 laddr, __be16 lport,
3654 __be32 raddr, __be16 rport,
3655 u32 rcv_isn, u32 filter, u16 window,
3656 u32 rss_qid, u8 port_id)
3657{
3658 struct sk_buff *req_skb;
3659 struct fw_ofld_connection_wr *req;
3660 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303661 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003662
3663 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3664 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3665 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003666 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303667 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303668 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003669 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003670 req->le.lport = lport;
3671 req->le.pport = rport;
3672 req->le.u.ipv4.lip = laddr;
3673 req->le.u.ipv4.pip = raddr;
3674 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3675 req->tcb.rcv_adv = htons(window);
3676 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303677 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3678 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3679 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003680 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003681
3682 /*
3683 * We store the qid in opt2 which will be used by the firmware
3684 * to send us the wr response.
3685 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003686 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003687
3688 /*
3689 * We initialize the MSS index in TCB to 0xF.
3690 * So that when driver sends cpl_pass_accept_rpl
3691 * TCB picks up the correct value. If this was 0
3692 * TP will ignore any value > 0 for MSS index.
3693 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003694 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303695 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003696
3697 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303698 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3699 if (ret < 0) {
3700 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3701 ret);
3702 kfree_skb(skb);
3703 kfree_skb(req_skb);
3704 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003705}
3706
3707/*
3708 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3709 * messages when a filter is being used instead of server to
3710 * redirect a syn packet. When packets hit filter they are redirected
3711 * to the offload queue and driver tries to establish the connection
3712 * using firmware work request.
3713 */
3714static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3715{
3716 int stid;
3717 unsigned int filter;
3718 struct ethhdr *eh = NULL;
3719 struct vlan_ethhdr *vlan_eh = NULL;
3720 struct iphdr *iph;
3721 struct tcphdr *tcph;
3722 struct rss_header *rss = (void *)skb->data;
3723 struct cpl_rx_pkt *cpl = (void *)skb->data;
3724 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3725 struct l2t_entry *e;
3726 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003727 struct c4iw_ep *lep;
3728 u16 window;
3729 struct port_info *pi;
3730 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003731 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003732 int step;
3733 u32 tx_chan;
3734 struct neighbour *neigh;
3735
3736 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003737 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003738 goto reject;
3739
3740 /*
3741 * Drop all packets which did not hit the filter.
3742 * Unlikely to happen.
3743 */
3744 if (!(rss->filter_hit && rss->filter_tid))
3745 goto reject;
3746
3747 /*
3748 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3749 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303750 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003751
3752 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3753 if (!lep) {
3754 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3755 goto reject;
3756 }
3757
Vipul Pandyaf079af72013-03-14 05:08:58 +00003758 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003759 RX_ETHHDR_LEN_G(htonl(cpl->l2info)) :
3760 RX_T5_ETHHDR_LEN_G(htonl(cpl->l2info));
Vipul Pandyaf079af72013-03-14 05:08:58 +00003761 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003762 eh = (struct ethhdr *)(req + 1);
3763 iph = (struct iphdr *)(eh + 1);
3764 } else {
3765 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3766 iph = (struct iphdr *)(vlan_eh + 1);
3767 skb->vlan_tci = ntohs(cpl->vlan);
3768 }
3769
3770 if (iph->version != 0x4)
3771 goto reject;
3772
3773 tcph = (struct tcphdr *)(iph + 1);
3774 skb_set_network_header(skb, (void *)iph - (void *)rss);
3775 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3776 skb_get(skb);
3777
3778 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3779 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3780 ntohs(tcph->source), iph->tos);
3781
Vipul Pandya830662f2013-07-04 16:10:47 +05303782 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3783 iph->tos);
3784 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003785 pr_err("%s - failed to find dst entry!\n",
3786 __func__);
3787 goto reject;
3788 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003789 neigh = dst_neigh_lookup_skb(dst, skb);
3790
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003791 if (!neigh) {
3792 pr_err("%s - failed to allocate neigh!\n",
3793 __func__);
3794 goto free_dst;
3795 }
3796
Vipul Pandya1cab7752012-12-10 09:30:55 +00003797 if (neigh->dev->flags & IFF_LOOPBACK) {
3798 pdev = ip_dev_find(&init_net, iph->daddr);
3799 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3800 pdev, 0);
3801 pi = (struct port_info *)netdev_priv(pdev);
3802 tx_chan = cxgb4_port_chan(pdev);
3803 dev_put(pdev);
3804 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303805 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003806 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303807 pdev, 0);
3808 pi = (struct port_info *)netdev_priv(pdev);
3809 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003810 }
Steve Wiseebf00062014-03-19 17:44:40 +05303811 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003812 if (!e) {
3813 pr_err("%s - failed to allocate l2t entry!\n",
3814 __func__);
3815 goto free_dst;
3816 }
3817
3818 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3819 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003820 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003821
3822 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303823 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3824 dev->rdev.lldi.ports[0],
3825 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003826
3827 /*
3828 * Synthesize the cpl_pass_accept_req. We have everything except the
3829 * TID. Once firmware sends a reply with TID we update the TID field
3830 * in cpl and pass it through the regular cpl_pass_accept_req path.
3831 */
3832 build_cpl_pass_accept_req(skb, stid, iph->tos);
3833 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3834 tcph->source, ntohl(tcph->seq), filter, window,
3835 rss_qid, pi->port_id);
3836 cxgb4_l2t_release(e);
3837free_dst:
3838 dst_release(dst);
3839reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003840 return 0;
3841}
3842
Steve Wisecfdda9d2010-04-21 15:30:06 -07003843/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003844 * These are the real handlers that are called from a
3845 * work queue.
3846 */
3847static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3848 [CPL_ACT_ESTABLISH] = act_establish,
3849 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3850 [CPL_RX_DATA] = rx_data,
3851 [CPL_ABORT_RPL_RSS] = abort_rpl,
3852 [CPL_ABORT_RPL] = abort_rpl,
3853 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3854 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3855 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3856 [CPL_PASS_ESTABLISH] = pass_establish,
3857 [CPL_PEER_CLOSE] = peer_close,
3858 [CPL_ABORT_REQ_RSS] = peer_abort,
3859 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3860 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003861 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003862 [CPL_FW6_MSG] = deferred_fw6_msg,
3863 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003864};
3865
3866static void process_timeout(struct c4iw_ep *ep)
3867{
3868 struct c4iw_qp_attributes attrs;
3869 int abort = 1;
3870
Steve Wise2f5b48c2010-09-10 11:15:36 -05003871 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003872 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3873 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003874 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003875 switch (ep->com.state) {
3876 case MPA_REQ_SENT:
3877 __state_set(&ep->com, ABORTING);
3878 connect_reply_upcall(ep, -ETIMEDOUT);
3879 break;
3880 case MPA_REQ_WAIT:
3881 __state_set(&ep->com, ABORTING);
3882 break;
3883 case CLOSING:
3884 case MORIBUND:
3885 if (ep->com.cm_id && ep->com.qp) {
3886 attrs.next_state = C4IW_QP_STATE_ERROR;
3887 c4iw_modify_qp(ep->com.qp->rhp,
3888 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3889 &attrs, 1);
3890 }
3891 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303892 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003893 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003894 case ABORTING:
3895 case DEAD:
3896
3897 /*
3898 * These states are expected if the ep timed out at the same
3899 * time as another thread was calling stop_ep_timer().
3900 * So we silently do nothing for these states.
3901 */
3902 abort = 0;
3903 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003904 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003905 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003906 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003907 abort = 0;
3908 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003909 if (abort)
3910 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecc18b932014-04-24 14:31:53 -05003911 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003912 c4iw_put_ep(&ep->com);
3913}
3914
3915static void process_timedout_eps(void)
3916{
3917 struct c4iw_ep *ep;
3918
3919 spin_lock_irq(&timeout_lock);
3920 while (!list_empty(&timeout_list)) {
3921 struct list_head *tmp;
3922
3923 tmp = timeout_list.next;
3924 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003925 tmp->next = NULL;
3926 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003927 spin_unlock_irq(&timeout_lock);
3928 ep = list_entry(tmp, struct c4iw_ep, entry);
3929 process_timeout(ep);
3930 spin_lock_irq(&timeout_lock);
3931 }
3932 spin_unlock_irq(&timeout_lock);
3933}
3934
3935static void process_work(struct work_struct *work)
3936{
3937 struct sk_buff *skb = NULL;
3938 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003939 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003940 unsigned int opcode;
3941 int ret;
3942
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003943 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003944 while ((skb = skb_dequeue(&rxq))) {
3945 rpl = cplhdr(skb);
3946 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3947 opcode = rpl->ot.opcode;
3948
3949 BUG_ON(!work_handlers[opcode]);
3950 ret = work_handlers[opcode](dev, skb);
3951 if (!ret)
3952 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003953 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003954 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003955}
3956
3957static DECLARE_WORK(skb_work, process_work);
3958
3959static void ep_timeout(unsigned long arg)
3960{
3961 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003962 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003963
3964 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003965 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003966 /*
3967 * Only insert if it is not already on the list.
3968 */
3969 if (!ep->entry.next) {
3970 list_add_tail(&ep->entry, &timeout_list);
3971 kickit = 1;
3972 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003973 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003974 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003975 if (kickit)
3976 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003977}
3978
3979/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07003980 * All the CM events are handled on a work queue to have a safe context.
3981 */
3982static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3983{
3984
3985 /*
3986 * Save dev in the skb->cb area.
3987 */
3988 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3989
3990 /*
3991 * Queue the skb and schedule the worker thread.
3992 */
3993 skb_queue_tail(&rxq, skb);
3994 queue_work(workq, &skb_work);
3995 return 0;
3996}
3997
3998static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3999{
4000 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4001
4002 if (rpl->status != CPL_ERR_NONE) {
4003 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4004 "for tid %u\n", rpl->status, GET_TID(rpl));
4005 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004006 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004007 return 0;
4008}
4009
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004010static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4011{
4012 struct cpl_fw6_msg *rpl = cplhdr(skb);
4013 struct c4iw_wr_wait *wr_waitp;
4014 int ret;
4015
4016 PDBG("%s type %u\n", __func__, rpl->type);
4017
4018 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004019 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004020 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004021 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004022 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004023 if (wr_waitp)
4024 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004025 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004026 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004027 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004028 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004029 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004030 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004031 default:
4032 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4033 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004034 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004035 break;
4036 }
4037 return 0;
4038}
4039
Steve Wise8da7e7a2011-06-14 20:59:27 +00004040static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4041{
4042 struct cpl_abort_req_rss *req = cplhdr(skb);
4043 struct c4iw_ep *ep;
4044 struct tid_info *t = dev->rdev.lldi.tids;
4045 unsigned int tid = GET_TID(req);
4046
4047 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05004048 if (!ep) {
4049 printk(KERN_WARNING MOD
4050 "Abort on non-existent endpoint, tid %d\n", tid);
4051 kfree_skb(skb);
4052 return 0;
4053 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304054 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304055 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4056 __func__, ep->hwtid, req->status,
4057 neg_adv_str(req->status));
4058 ep->stats.abort_neg_adv++;
4059 dev->rdev.stats.neg_adv++;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004060 kfree_skb(skb);
4061 return 0;
4062 }
4063 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4064 ep->com.state);
4065
4066 /*
4067 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004068 * However, if we are on MPAv2 and want to retry with MPAv1
4069 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004070 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004071 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4072 if (ep->com.state != MPA_REQ_SENT)
4073 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4074 } else
4075 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00004076 sched(dev, skb);
4077 return 0;
4078}
4079
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004080/*
4081 * Most upcalls from the T4 Core go to sched() to
4082 * schedule the processing on a work queue.
4083 */
4084c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4085 [CPL_ACT_ESTABLISH] = sched,
4086 [CPL_ACT_OPEN_RPL] = sched,
4087 [CPL_RX_DATA] = sched,
4088 [CPL_ABORT_RPL_RSS] = sched,
4089 [CPL_ABORT_RPL] = sched,
4090 [CPL_PASS_OPEN_RPL] = sched,
4091 [CPL_CLOSE_LISTSRV_RPL] = sched,
4092 [CPL_PASS_ACCEPT_REQ] = sched,
4093 [CPL_PASS_ESTABLISH] = sched,
4094 [CPL_PEER_CLOSE] = sched,
4095 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004096 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004097 [CPL_RDMA_TERMINATE] = sched,
4098 [CPL_FW4_ACK] = sched,
4099 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004100 [CPL_FW6_MSG] = fw6_msg,
4101 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004102};
4103
Steve Wisecfdda9d2010-04-21 15:30:06 -07004104int __init c4iw_cm_init(void)
4105{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004106 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004107 skb_queue_head_init(&rxq);
4108
4109 workq = create_singlethread_workqueue("iw_cxgb4");
4110 if (!workq)
4111 return -ENOMEM;
4112
Steve Wisecfdda9d2010-04-21 15:30:06 -07004113 return 0;
4114}
4115
Steve Wise46c13762014-06-20 14:26:25 -05004116void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004117{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004118 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004119 flush_workqueue(workq);
4120 destroy_workqueue(workq);
4121}