1 /*
2 * Copyright (c) 2009-2014 Chelsio, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32 #include <linux/module.h>
33 #include <linux/list.h>
34 #include <linux/workqueue.h>
35 #include <linux/skbuff.h>
36 #include <linux/timer.h>
37 #include <linux/notifier.h>
38 #include <linux/inetdevice.h>
39 #include <linux/ip.h>
40 #include <linux/tcp.h>
41 #include <linux/if_vlan.h>
42
43 #include <net/neighbour.h>
44 #include <net/netevent.h>
45 #include <net/route.h>
46 #include <net/tcp.h>
47 #include <net/ip6_route.h>
48 #include <net/addrconf.h>
49
50 #include <rdma/ib_addr.h>
51
52 #include "iw_cxgb4.h"
53 #include "clip_tbl.h"
54
55 static 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
71 static int nocong;
72 module_param(nocong, int, 0644);
73 MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
74
75 static int enable_ecn;
76 module_param(enable_ecn, int, 0644);
77 MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
78
79 static int dack_mode = 1;
80 module_param(dack_mode, int, 0644);
81 MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
82
83 uint c4iw_max_read_depth = 32;
84 module_param(c4iw_max_read_depth, int, 0644);
85 MODULE_PARM_DESC(c4iw_max_read_depth,
86 "Per-connection max ORD/IRD (default=32)");
87
88 static int enable_tcp_timestamps;
89 module_param(enable_tcp_timestamps, int, 0644);
90 MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
91
92 static int enable_tcp_sack;
93 module_param(enable_tcp_sack, int, 0644);
94 MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
95
96 static int enable_tcp_window_scaling = 1;
97 module_param(enable_tcp_window_scaling, int, 0644);
98 MODULE_PARM_DESC(enable_tcp_window_scaling,
99 "Enable tcp window scaling (default=1)");
100
101 int c4iw_debug;
102 module_param(c4iw_debug, int, 0644);
103 MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
104
105 static int peer2peer = 1;
106 module_param(peer2peer, int, 0644);
107 MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
108
109 static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
110 module_param(p2p_type, int, 0644);
111 MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
112 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
113
114 static int ep_timeout_secs = 60;
115 module_param(ep_timeout_secs, int, 0644);
116 MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
117 "in seconds (default=60)");
118
119 static int mpa_rev = 2;
120 module_param(mpa_rev, int, 0644);
121 MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
122 "1 is RFC0544 spec compliant, 2 is IETF MPA Peer Connect Draft"
123 " compliant (default=2)");
124
125 static int markers_enabled;
126 module_param(markers_enabled, int, 0644);
127 MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
128
129 static int crc_enabled = 1;
130 module_param(crc_enabled, int, 0644);
131 MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
132
133 static int rcv_win = 256 * 1024;
134 module_param(rcv_win, int, 0644);
135 MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
136
137 static int snd_win = 128 * 1024;
138 module_param(snd_win, int, 0644);
139 MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
140
141 static struct workqueue_struct *workq;
142
143 static struct sk_buff_head rxq;
144
145 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
146 static void ep_timeout(unsigned long arg);
147 static void connect_reply_upcall(struct c4iw_ep *ep, int status);
148
149 static LIST_HEAD(timeout_list);
150 static spinlock_t timeout_lock;
151
deref_qp(struct c4iw_ep * ep)152 static 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
ref_qp(struct c4iw_ep * ep)158 static 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
start_ep_timer(struct c4iw_ep * ep)164 static void start_ep_timer(struct c4iw_ep *ep)
165 {
166 PDBG("%s ep %p\n", __func__, ep);
167 if (timer_pending(&ep->timer)) {
168 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);
174 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
stop_ep_timer(struct c4iw_ep * ep)180 static int stop_ep_timer(struct c4iw_ep *ep)
181 {
182 PDBG("%s ep %p stopping\n", __func__, ep);
183 del_timer_sync(&ep->timer);
184 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
185 c4iw_put_ep(&ep->com);
186 return 0;
187 }
188 return 1;
189 }
190
c4iw_l2t_send(struct c4iw_rdev * rdev,struct sk_buff * skb,struct l2t_entry * l2e)191 static 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);
204 return error < 0 ? error : 0;
205 }
206
c4iw_ofld_send(struct c4iw_rdev * rdev,struct sk_buff * skb)207 int 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);
219 return error < 0 ? error : 0;
220 }
221
release_tid(struct c4iw_rdev * rdev,u32 hwtid,struct sk_buff * skb)222 static 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
set_emss(struct c4iw_ep * ep,u16 opt)237 static void set_emss(struct c4iw_ep *ep, u16 opt)
238 {
239 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
240 ((AF_INET == ep->com.remote_addr.ss_family) ?
241 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
242 sizeof(struct tcphdr);
243 ep->mss = ep->emss;
244 if (TCPOPT_TSTAMP_G(opt))
245 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
246 if (ep->emss < 128)
247 ep->emss = 128;
248 if (ep->emss & 7)
249 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
250 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
251 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt),
252 ep->mss, ep->emss);
253 }
254
state_read(struct c4iw_ep_common * epc)255 static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
256 {
257 enum c4iw_ep_state state;
258
259 mutex_lock(&epc->mutex);
260 state = epc->state;
261 mutex_unlock(&epc->mutex);
262 return state;
263 }
264
__state_set(struct c4iw_ep_common * epc,enum c4iw_ep_state new)265 static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
266 {
267 epc->state = new;
268 }
269
state_set(struct c4iw_ep_common * epc,enum c4iw_ep_state new)270 static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
271 {
272 mutex_lock(&epc->mutex);
273 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
274 __state_set(epc, new);
275 mutex_unlock(&epc->mutex);
276 return;
277 }
278
alloc_ep(int size,gfp_t gfp)279 static 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);
286 mutex_init(&epc->mutex);
287 c4iw_init_wr_wait(&epc->wr_wait);
288 }
289 PDBG("%s alloc ep %p\n", __func__, epc);
290 return epc;
291 }
292
_c4iw_free_ep(struct kref * kref)293 void _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)]);
299 if (test_bit(QP_REFERENCED, &ep->com.flags))
300 deref_qp(ep);
301 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
302 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 }
312 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
313 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
314 dst_release(ep->dst);
315 cxgb4_l2t_release(ep->l2t);
316 }
317 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 }
323 kfree(ep);
324 }
325
release_ep_resources(struct c4iw_ep * ep)326 static 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
status2errno(int status)332 static 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 */
get_skb(struct sk_buff * skb,int len,gfp_t gfp)355 static 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 if (!skb)
364 return NULL;
365 }
366 t4_set_arp_err_handler(skb, NULL, NULL);
367 return skb;
368 }
369
get_real_dev(struct net_device * egress_dev)370 static struct net_device *get_real_dev(struct net_device *egress_dev)
371 {
372 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
373 }
374
our_interface(struct c4iw_dev * dev,struct net_device * egress_dev)375 static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
376 {
377 int i;
378
379 egress_dev = get_real_dev(egress_dev);
380 for (i = 0; i < dev->rdev.lldi.nports; i++)
381 if (dev->rdev.lldi.ports[i] == egress_dev)
382 return 1;
383 return 0;
384 }
385
find_route6(struct c4iw_dev * dev,__u8 * local_ip,__u8 * peer_ip,__be16 local_port,__be16 peer_port,u8 tos,__u32 sin6_scope_id)386 static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
387 __u8 *peer_ip, __be16 local_port,
388 __be16 peer_port, u8 tos,
389 __u32 sin6_scope_id)
390 {
391 struct dst_entry *dst = NULL;
392
393 if (IS_ENABLED(CONFIG_IPV6)) {
394 struct flowi6 fl6;
395
396 memset(&fl6, 0, sizeof(fl6));
397 memcpy(&fl6.daddr, peer_ip, 16);
398 memcpy(&fl6.saddr, local_ip, 16);
399 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
400 fl6.flowi6_oif = sin6_scope_id;
401 dst = ip6_route_output(&init_net, NULL, &fl6);
402 if (!dst)
403 goto out;
404 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
405 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
406 dst_release(dst);
407 dst = NULL;
408 }
409 }
410
411 out:
412 return dst;
413 }
414
find_route(struct c4iw_dev * dev,__be32 local_ip,__be32 peer_ip,__be16 local_port,__be16 peer_port,u8 tos)415 static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
416 __be32 peer_ip, __be16 local_port,
417 __be16 peer_port, u8 tos)
418 {
419 struct rtable *rt;
420 struct flowi4 fl4;
421 struct neighbour *n;
422
423 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
424 peer_port, local_port, IPPROTO_TCP,
425 tos, 0);
426 if (IS_ERR(rt))
427 return NULL;
428 n = dst_neigh_lookup(&rt->dst, &peer_ip);
429 if (!n)
430 return NULL;
431 if (!our_interface(dev, n->dev) &&
432 !(n->dev->flags & IFF_LOOPBACK)) {
433 neigh_release(n);
434 dst_release(&rt->dst);
435 return NULL;
436 }
437 neigh_release(n);
438 return &rt->dst;
439 }
440
arp_failure_discard(void * handle,struct sk_buff * skb)441 static void arp_failure_discard(void *handle, struct sk_buff *skb)
442 {
443 PDBG("%s c4iw_dev %p\n", __func__, handle);
444 kfree_skb(skb);
445 }
446
447 /*
448 * Handle an ARP failure for an active open.
449 */
act_open_req_arp_failure(void * handle,struct sk_buff * skb)450 static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
451 {
452 struct c4iw_ep *ep = handle;
453
454 printk(KERN_ERR MOD "ARP failure duing connect\n");
455 kfree_skb(skb);
456 connect_reply_upcall(ep, -EHOSTUNREACH);
457 state_set(&ep->com, DEAD);
458 if (ep->com.remote_addr.ss_family == AF_INET6) {
459 struct sockaddr_in6 *sin6 =
460 (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
461 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
462 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
463 }
464 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
465 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
466 dst_release(ep->dst);
467 cxgb4_l2t_release(ep->l2t);
468 c4iw_put_ep(&ep->com);
469 }
470
471 /*
472 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
473 * and send it along.
474 */
abort_arp_failure(void * handle,struct sk_buff * skb)475 static void abort_arp_failure(void *handle, struct sk_buff *skb)
476 {
477 struct c4iw_rdev *rdev = handle;
478 struct cpl_abort_req *req = cplhdr(skb);
479
480 PDBG("%s rdev %p\n", __func__, rdev);
481 req->cmd = CPL_ABORT_NO_RST;
482 c4iw_ofld_send(rdev, skb);
483 }
484
send_flowc(struct c4iw_ep * ep,struct sk_buff * skb)485 static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
486 {
487 unsigned int flowclen = 80;
488 struct fw_flowc_wr *flowc;
489 int i;
490
491 skb = get_skb(skb, flowclen, GFP_KERNEL);
492 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
493
494 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
495 FW_FLOWC_WR_NPARAMS_V(8));
496 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(flowclen,
497 16)) | FW_WR_FLOWID_V(ep->hwtid));
498
499 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
500 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
501 (ep->com.dev->rdev.lldi.pf));
502 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
503 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
504 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
505 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
506 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
507 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
508 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
509 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
510 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
511 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
512 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
513 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
514 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
515 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
516 /* Pad WR to 16 byte boundary */
517 flowc->mnemval[8].mnemonic = 0;
518 flowc->mnemval[8].val = 0;
519 for (i = 0; i < 9; i++) {
520 flowc->mnemval[i].r4[0] = 0;
521 flowc->mnemval[i].r4[1] = 0;
522 flowc->mnemval[i].r4[2] = 0;
523 }
524
525 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
526 c4iw_ofld_send(&ep->com.dev->rdev, skb);
527 }
528
send_halfclose(struct c4iw_ep * ep,gfp_t gfp)529 static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
530 {
531 struct cpl_close_con_req *req;
532 struct sk_buff *skb;
533 int wrlen = roundup(sizeof *req, 16);
534
535 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
536 skb = get_skb(NULL, wrlen, gfp);
537 if (!skb) {
538 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
539 return -ENOMEM;
540 }
541 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
542 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
543 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
544 memset(req, 0, wrlen);
545 INIT_TP_WR(req, ep->hwtid);
546 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
547 ep->hwtid));
548 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
549 }
550
send_abort(struct c4iw_ep * ep,struct sk_buff * skb,gfp_t gfp)551 static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
552 {
553 struct cpl_abort_req *req;
554 int wrlen = roundup(sizeof *req, 16);
555
556 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
557 skb = get_skb(skb, wrlen, gfp);
558 if (!skb) {
559 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
560 __func__);
561 return -ENOMEM;
562 }
563 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
564 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
565 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
566 memset(req, 0, wrlen);
567 INIT_TP_WR(req, ep->hwtid);
568 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
569 req->cmd = CPL_ABORT_SEND_RST;
570 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
571 }
572
573 /*
574 * c4iw_form_pm_msg - Form a port mapper message with mapping info
575 */
c4iw_form_pm_msg(struct c4iw_ep * ep,struct iwpm_sa_data * pm_msg)576 static void c4iw_form_pm_msg(struct c4iw_ep *ep,
577 struct iwpm_sa_data *pm_msg)
578 {
579 memcpy(&pm_msg->loc_addr, &ep->com.local_addr,
580 sizeof(ep->com.local_addr));
581 memcpy(&pm_msg->rem_addr, &ep->com.remote_addr,
582 sizeof(ep->com.remote_addr));
583 }
584
585 /*
586 * c4iw_form_reg_msg - Form a port mapper message with dev info
587 */
c4iw_form_reg_msg(struct c4iw_dev * dev,struct iwpm_dev_data * pm_msg)588 static void c4iw_form_reg_msg(struct c4iw_dev *dev,
589 struct iwpm_dev_data *pm_msg)
590 {
591 memcpy(pm_msg->dev_name, dev->ibdev.name, IWPM_DEVNAME_SIZE);
592 memcpy(pm_msg->if_name, dev->rdev.lldi.ports[0]->name,
593 IWPM_IFNAME_SIZE);
594 }
595
c4iw_record_pm_msg(struct c4iw_ep * ep,struct iwpm_sa_data * pm_msg)596 static void c4iw_record_pm_msg(struct c4iw_ep *ep,
597 struct iwpm_sa_data *pm_msg)
598 {
599 memcpy(&ep->com.mapped_local_addr, &pm_msg->mapped_loc_addr,
600 sizeof(ep->com.mapped_local_addr));
601 memcpy(&ep->com.mapped_remote_addr, &pm_msg->mapped_rem_addr,
602 sizeof(ep->com.mapped_remote_addr));
603 }
604
get_remote_addr(struct c4iw_ep * parent_ep,struct c4iw_ep * child_ep)605 static int get_remote_addr(struct c4iw_ep *parent_ep, struct c4iw_ep *child_ep)
606 {
607 int ret;
608
609 print_addr(&parent_ep->com, __func__, "get_remote_addr parent_ep ");
610 print_addr(&child_ep->com, __func__, "get_remote_addr child_ep ");
611
612 ret = iwpm_get_remote_info(&parent_ep->com.mapped_local_addr,
613 &child_ep->com.mapped_remote_addr,
614 &child_ep->com.remote_addr, RDMA_NL_C4IW);
615 if (ret)
616 PDBG("Unable to find remote peer addr info - err %d\n", ret);
617
618 return ret;
619 }
620
best_mtu(const unsigned short * mtus,unsigned short mtu,unsigned int * idx,int use_ts,int ipv6)621 static void best_mtu(const unsigned short *mtus, unsigned short mtu,
622 unsigned int *idx, int use_ts, int ipv6)
623 {
624 unsigned short hdr_size = (ipv6 ?
625 sizeof(struct ipv6hdr) :
626 sizeof(struct iphdr)) +
627 sizeof(struct tcphdr) +
628 (use_ts ?
629 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
630 unsigned short data_size = mtu - hdr_size;
631
632 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
633 }
634
send_connect(struct c4iw_ep * ep)635 static int send_connect(struct c4iw_ep *ep)
636 {
637 struct cpl_act_open_req *req = NULL;
638 struct cpl_t5_act_open_req *t5req = NULL;
639 struct cpl_t6_act_open_req *t6req = NULL;
640 struct cpl_act_open_req6 *req6 = NULL;
641 struct cpl_t5_act_open_req6 *t5req6 = NULL;
642 struct cpl_t6_act_open_req6 *t6req6 = NULL;
643 struct sk_buff *skb;
644 u64 opt0;
645 u32 opt2;
646 unsigned int mtu_idx;
647 int wscale;
648 int win, sizev4, sizev6, wrlen;
649 struct sockaddr_in *la = (struct sockaddr_in *)
650 &ep->com.mapped_local_addr;
651 struct sockaddr_in *ra = (struct sockaddr_in *)
652 &ep->com.mapped_remote_addr;
653 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
654 &ep->com.mapped_local_addr;
655 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
656 &ep->com.mapped_remote_addr;
657 int ret;
658 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
659 u32 isn = (prandom_u32() & ~7UL) - 1;
660
661 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
662 case CHELSIO_T4:
663 sizev4 = sizeof(struct cpl_act_open_req);
664 sizev6 = sizeof(struct cpl_act_open_req6);
665 break;
666 case CHELSIO_T5:
667 sizev4 = sizeof(struct cpl_t5_act_open_req);
668 sizev6 = sizeof(struct cpl_t5_act_open_req6);
669 break;
670 case CHELSIO_T6:
671 sizev4 = sizeof(struct cpl_t6_act_open_req);
672 sizev6 = sizeof(struct cpl_t6_act_open_req6);
673 break;
674 default:
675 pr_err("T%d Chip is not supported\n",
676 CHELSIO_CHIP_VERSION(adapter_type));
677 return -EINVAL;
678 }
679
680 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
681 roundup(sizev4, 16) :
682 roundup(sizev6, 16);
683
684 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
685
686 skb = get_skb(NULL, wrlen, GFP_KERNEL);
687 if (!skb) {
688 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
689 __func__);
690 return -ENOMEM;
691 }
692 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
693
694 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
695 enable_tcp_timestamps,
696 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
697 wscale = compute_wscale(rcv_win);
698
699 /*
700 * Specify the largest window that will fit in opt0. The
701 * remainder will be specified in the rx_data_ack.
702 */
703 win = ep->rcv_win >> 10;
704 if (win > RCV_BUFSIZ_M)
705 win = RCV_BUFSIZ_M;
706
707 opt0 = (nocong ? NO_CONG_F : 0) |
708 KEEP_ALIVE_F |
709 DELACK_F |
710 WND_SCALE_V(wscale) |
711 MSS_IDX_V(mtu_idx) |
712 L2T_IDX_V(ep->l2t->idx) |
713 TX_CHAN_V(ep->tx_chan) |
714 SMAC_SEL_V(ep->smac_idx) |
715 DSCP_V(ep->tos) |
716 ULP_MODE_V(ULP_MODE_TCPDDP) |
717 RCV_BUFSIZ_V(win);
718 opt2 = RX_CHANNEL_V(0) |
719 CCTRL_ECN_V(enable_ecn) |
720 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
721 if (enable_tcp_timestamps)
722 opt2 |= TSTAMPS_EN_F;
723 if (enable_tcp_sack)
724 opt2 |= SACK_EN_F;
725 if (wscale && enable_tcp_window_scaling)
726 opt2 |= WND_SCALE_EN_F;
727 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
728 if (peer2peer)
729 isn += 4;
730
731 opt2 |= T5_OPT_2_VALID_F;
732 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
733 opt2 |= T5_ISS_F;
734 }
735
736 if (ep->com.remote_addr.ss_family == AF_INET6)
737 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
738 (const u32 *)&la6->sin6_addr.s6_addr, 1);
739
740 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
741
742 if (ep->com.remote_addr.ss_family == AF_INET) {
743 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
744 case CHELSIO_T4:
745 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
746 INIT_TP_WR(req, 0);
747 break;
748 case CHELSIO_T5:
749 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
750 wrlen);
751 INIT_TP_WR(t5req, 0);
752 req = (struct cpl_act_open_req *)t5req;
753 break;
754 case CHELSIO_T6:
755 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
756 wrlen);
757 INIT_TP_WR(t6req, 0);
758 req = (struct cpl_act_open_req *)t6req;
759 t5req = (struct cpl_t5_act_open_req *)t6req;
760 break;
761 default:
762 pr_err("T%d Chip is not supported\n",
763 CHELSIO_CHIP_VERSION(adapter_type));
764 ret = -EINVAL;
765 goto clip_release;
766 }
767
768 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
769 ((ep->rss_qid<<14) | ep->atid)));
770 req->local_port = la->sin_port;
771 req->peer_port = ra->sin_port;
772 req->local_ip = la->sin_addr.s_addr;
773 req->peer_ip = ra->sin_addr.s_addr;
774 req->opt0 = cpu_to_be64(opt0);
775
776 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
777 req->params = cpu_to_be32(cxgb4_select_ntuple(
778 ep->com.dev->rdev.lldi.ports[0],
779 ep->l2t));
780 req->opt2 = cpu_to_be32(opt2);
781 } else {
782 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
783 cxgb4_select_ntuple(
784 ep->com.dev->rdev.lldi.ports[0],
785 ep->l2t)));
786 t5req->rsvd = cpu_to_be32(isn);
787 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
788 t5req->opt2 = cpu_to_be32(opt2);
789 }
790 } else {
791 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
792 case CHELSIO_T4:
793 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
794 INIT_TP_WR(req6, 0);
795 break;
796 case CHELSIO_T5:
797 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
798 wrlen);
799 INIT_TP_WR(t5req6, 0);
800 req6 = (struct cpl_act_open_req6 *)t5req6;
801 break;
802 case CHELSIO_T6:
803 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
804 wrlen);
805 INIT_TP_WR(t6req6, 0);
806 req6 = (struct cpl_act_open_req6 *)t6req6;
807 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
808 break;
809 default:
810 pr_err("T%d Chip is not supported\n",
811 CHELSIO_CHIP_VERSION(adapter_type));
812 ret = -EINVAL;
813 goto clip_release;
814 }
815
816 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
817 ((ep->rss_qid<<14)|ep->atid)));
818 req6->local_port = la6->sin6_port;
819 req6->peer_port = ra6->sin6_port;
820 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
821 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
822 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
823 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
824 req6->opt0 = cpu_to_be64(opt0);
825
826 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
827 req6->params = cpu_to_be32(cxgb4_select_ntuple(
828 ep->com.dev->rdev.lldi.ports[0],
829 ep->l2t));
830 req6->opt2 = cpu_to_be32(opt2);
831 } else {
832 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
833 cxgb4_select_ntuple(
834 ep->com.dev->rdev.lldi.ports[0],
835 ep->l2t)));
836 t5req6->rsvd = cpu_to_be32(isn);
837 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
838 t5req6->opt2 = cpu_to_be32(opt2);
839 }
840 }
841
842 set_bit(ACT_OPEN_REQ, &ep->com.history);
843 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
844 clip_release:
845 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
846 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
847 (const u32 *)&la6->sin6_addr.s6_addr, 1);
848 return ret;
849 }
850
send_mpa_req(struct c4iw_ep * ep,struct sk_buff * skb,u8 mpa_rev_to_use)851 static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
852 u8 mpa_rev_to_use)
853 {
854 int mpalen, wrlen;
855 struct fw_ofld_tx_data_wr *req;
856 struct mpa_message *mpa;
857 struct mpa_v2_conn_params mpa_v2_params;
858
859 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
860
861 BUG_ON(skb_cloned(skb));
862
863 mpalen = sizeof(*mpa) + ep->plen;
864 if (mpa_rev_to_use == 2)
865 mpalen += sizeof(struct mpa_v2_conn_params);
866 wrlen = roundup(mpalen + sizeof *req, 16);
867 skb = get_skb(skb, wrlen, GFP_KERNEL);
868 if (!skb) {
869 connect_reply_upcall(ep, -ENOMEM);
870 return;
871 }
872 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
873
874 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
875 memset(req, 0, wrlen);
876 req->op_to_immdlen = cpu_to_be32(
877 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
878 FW_WR_COMPL_F |
879 FW_WR_IMMDLEN_V(mpalen));
880 req->flowid_len16 = cpu_to_be32(
881 FW_WR_FLOWID_V(ep->hwtid) |
882 FW_WR_LEN16_V(wrlen >> 4));
883 req->plen = cpu_to_be32(mpalen);
884 req->tunnel_to_proxy = cpu_to_be32(
885 FW_OFLD_TX_DATA_WR_FLUSH_F |
886 FW_OFLD_TX_DATA_WR_SHOVE_F);
887
888 mpa = (struct mpa_message *)(req + 1);
889 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
890 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
891 (markers_enabled ? MPA_MARKERS : 0) |
892 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
893 mpa->private_data_size = htons(ep->plen);
894 mpa->revision = mpa_rev_to_use;
895 if (mpa_rev_to_use == 1) {
896 ep->tried_with_mpa_v1 = 1;
897 ep->retry_with_mpa_v1 = 0;
898 }
899
900 if (mpa_rev_to_use == 2) {
901 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
902 sizeof (struct mpa_v2_conn_params));
903 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
904 ep->ord);
905 mpa_v2_params.ird = htons((u16)ep->ird);
906 mpa_v2_params.ord = htons((u16)ep->ord);
907
908 if (peer2peer) {
909 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
910 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
911 mpa_v2_params.ord |=
912 htons(MPA_V2_RDMA_WRITE_RTR);
913 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
914 mpa_v2_params.ord |=
915 htons(MPA_V2_RDMA_READ_RTR);
916 }
917 memcpy(mpa->private_data, &mpa_v2_params,
918 sizeof(struct mpa_v2_conn_params));
919
920 if (ep->plen)
921 memcpy(mpa->private_data +
922 sizeof(struct mpa_v2_conn_params),
923 ep->mpa_pkt + sizeof(*mpa), ep->plen);
924 } else
925 if (ep->plen)
926 memcpy(mpa->private_data,
927 ep->mpa_pkt + sizeof(*mpa), ep->plen);
928
929 /*
930 * Reference the mpa skb. This ensures the data area
931 * will remain in memory until the hw acks the tx.
932 * Function fw4_ack() will deref it.
933 */
934 skb_get(skb);
935 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
936 BUG_ON(ep->mpa_skb);
937 ep->mpa_skb = skb;
938 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
939 start_ep_timer(ep);
940 __state_set(&ep->com, MPA_REQ_SENT);
941 ep->mpa_attr.initiator = 1;
942 ep->snd_seq += mpalen;
943 return;
944 }
945
send_mpa_reject(struct c4iw_ep * ep,const void * pdata,u8 plen)946 static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
947 {
948 int mpalen, wrlen;
949 struct fw_ofld_tx_data_wr *req;
950 struct mpa_message *mpa;
951 struct sk_buff *skb;
952 struct mpa_v2_conn_params mpa_v2_params;
953
954 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
955
956 mpalen = sizeof(*mpa) + plen;
957 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
958 mpalen += sizeof(struct mpa_v2_conn_params);
959 wrlen = roundup(mpalen + sizeof *req, 16);
960
961 skb = get_skb(NULL, wrlen, GFP_KERNEL);
962 if (!skb) {
963 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
964 return -ENOMEM;
965 }
966 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
967
968 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
969 memset(req, 0, wrlen);
970 req->op_to_immdlen = cpu_to_be32(
971 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
972 FW_WR_COMPL_F |
973 FW_WR_IMMDLEN_V(mpalen));
974 req->flowid_len16 = cpu_to_be32(
975 FW_WR_FLOWID_V(ep->hwtid) |
976 FW_WR_LEN16_V(wrlen >> 4));
977 req->plen = cpu_to_be32(mpalen);
978 req->tunnel_to_proxy = cpu_to_be32(
979 FW_OFLD_TX_DATA_WR_FLUSH_F |
980 FW_OFLD_TX_DATA_WR_SHOVE_F);
981
982 mpa = (struct mpa_message *)(req + 1);
983 memset(mpa, 0, sizeof(*mpa));
984 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
985 mpa->flags = MPA_REJECT;
986 mpa->revision = ep->mpa_attr.version;
987 mpa->private_data_size = htons(plen);
988
989 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
990 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
991 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
992 sizeof (struct mpa_v2_conn_params));
993 mpa_v2_params.ird = htons(((u16)ep->ird) |
994 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
995 0));
996 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
997 (p2p_type ==
998 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
999 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1000 FW_RI_INIT_P2PTYPE_READ_REQ ?
1001 MPA_V2_RDMA_READ_RTR : 0) : 0));
1002 memcpy(mpa->private_data, &mpa_v2_params,
1003 sizeof(struct mpa_v2_conn_params));
1004
1005 if (ep->plen)
1006 memcpy(mpa->private_data +
1007 sizeof(struct mpa_v2_conn_params), pdata, plen);
1008 } else
1009 if (plen)
1010 memcpy(mpa->private_data, pdata, plen);
1011
1012 /*
1013 * Reference the mpa skb again. This ensures the data area
1014 * will remain in memory until the hw acks the tx.
1015 * Function fw4_ack() will deref it.
1016 */
1017 skb_get(skb);
1018 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1019 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1020 BUG_ON(ep->mpa_skb);
1021 ep->mpa_skb = skb;
1022 ep->snd_seq += mpalen;
1023 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1024 }
1025
send_mpa_reply(struct c4iw_ep * ep,const void * pdata,u8 plen)1026 static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1027 {
1028 int mpalen, wrlen;
1029 struct fw_ofld_tx_data_wr *req;
1030 struct mpa_message *mpa;
1031 struct sk_buff *skb;
1032 struct mpa_v2_conn_params mpa_v2_params;
1033
1034 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1035
1036 mpalen = sizeof(*mpa) + plen;
1037 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1038 mpalen += sizeof(struct mpa_v2_conn_params);
1039 wrlen = roundup(mpalen + sizeof *req, 16);
1040
1041 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1042 if (!skb) {
1043 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1044 return -ENOMEM;
1045 }
1046 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1047
1048 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1049 memset(req, 0, wrlen);
1050 req->op_to_immdlen = cpu_to_be32(
1051 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1052 FW_WR_COMPL_F |
1053 FW_WR_IMMDLEN_V(mpalen));
1054 req->flowid_len16 = cpu_to_be32(
1055 FW_WR_FLOWID_V(ep->hwtid) |
1056 FW_WR_LEN16_V(wrlen >> 4));
1057 req->plen = cpu_to_be32(mpalen);
1058 req->tunnel_to_proxy = cpu_to_be32(
1059 FW_OFLD_TX_DATA_WR_FLUSH_F |
1060 FW_OFLD_TX_DATA_WR_SHOVE_F);
1061
1062 mpa = (struct mpa_message *)(req + 1);
1063 memset(mpa, 0, sizeof(*mpa));
1064 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1065 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
1066 (markers_enabled ? MPA_MARKERS : 0);
1067 mpa->revision = ep->mpa_attr.version;
1068 mpa->private_data_size = htons(plen);
1069
1070 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1071 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
1072 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1073 sizeof (struct mpa_v2_conn_params));
1074 mpa_v2_params.ird = htons((u16)ep->ird);
1075 mpa_v2_params.ord = htons((u16)ep->ord);
1076 if (peer2peer && (ep->mpa_attr.p2p_type !=
1077 FW_RI_INIT_P2PTYPE_DISABLED)) {
1078 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1079
1080 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1081 mpa_v2_params.ord |=
1082 htons(MPA_V2_RDMA_WRITE_RTR);
1083 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1084 mpa_v2_params.ord |=
1085 htons(MPA_V2_RDMA_READ_RTR);
1086 }
1087
1088 memcpy(mpa->private_data, &mpa_v2_params,
1089 sizeof(struct mpa_v2_conn_params));
1090
1091 if (ep->plen)
1092 memcpy(mpa->private_data +
1093 sizeof(struct mpa_v2_conn_params), pdata, plen);
1094 } else
1095 if (plen)
1096 memcpy(mpa->private_data, pdata, plen);
1097
1098 /*
1099 * Reference the mpa skb. This ensures the data area
1100 * will remain in memory until the hw acks the tx.
1101 * Function fw4_ack() will deref it.
1102 */
1103 skb_get(skb);
1104 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1105 ep->mpa_skb = skb;
1106 __state_set(&ep->com, MPA_REP_SENT);
1107 ep->snd_seq += mpalen;
1108 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1109 }
1110
act_establish(struct c4iw_dev * dev,struct sk_buff * skb)1111 static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1112 {
1113 struct c4iw_ep *ep;
1114 struct cpl_act_establish *req = cplhdr(skb);
1115 unsigned int tid = GET_TID(req);
1116 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
1117 struct tid_info *t = dev->rdev.lldi.tids;
1118
1119 ep = lookup_atid(t, atid);
1120
1121 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1122 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1123
1124 mutex_lock(&ep->com.mutex);
1125 dst_confirm(ep->dst);
1126
1127 /* setup the hwtid for this connection */
1128 ep->hwtid = tid;
1129 cxgb4_insert_tid(t, ep, tid);
1130 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
1131
1132 ep->snd_seq = be32_to_cpu(req->snd_isn);
1133 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1134
1135 set_emss(ep, ntohs(req->tcp_opt));
1136
1137 /* dealloc the atid */
1138 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
1139 cxgb4_free_atid(t, atid);
1140 set_bit(ACT_ESTAB, &ep->com.history);
1141
1142 /* start MPA negotiation */
1143 send_flowc(ep, NULL);
1144 if (ep->retry_with_mpa_v1)
1145 send_mpa_req(ep, skb, 1);
1146 else
1147 send_mpa_req(ep, skb, mpa_rev);
1148 mutex_unlock(&ep->com.mutex);
1149 return 0;
1150 }
1151
close_complete_upcall(struct c4iw_ep * ep,int status)1152 static void close_complete_upcall(struct c4iw_ep *ep, int status)
1153 {
1154 struct iw_cm_event event;
1155
1156 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1157 memset(&event, 0, sizeof(event));
1158 event.event = IW_CM_EVENT_CLOSE;
1159 event.status = status;
1160 if (ep->com.cm_id) {
1161 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1162 ep, ep->com.cm_id, ep->hwtid);
1163 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1164 ep->com.cm_id->rem_ref(ep->com.cm_id);
1165 ep->com.cm_id = NULL;
1166 set_bit(CLOSE_UPCALL, &ep->com.history);
1167 }
1168 }
1169
abort_connection(struct c4iw_ep * ep,struct sk_buff * skb,gfp_t gfp)1170 static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
1171 {
1172 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1173 __state_set(&ep->com, ABORTING);
1174 set_bit(ABORT_CONN, &ep->com.history);
1175 return send_abort(ep, skb, gfp);
1176 }
1177
peer_close_upcall(struct c4iw_ep * ep)1178 static void peer_close_upcall(struct c4iw_ep *ep)
1179 {
1180 struct iw_cm_event event;
1181
1182 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1183 memset(&event, 0, sizeof(event));
1184 event.event = IW_CM_EVENT_DISCONNECT;
1185 if (ep->com.cm_id) {
1186 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1187 ep, ep->com.cm_id, ep->hwtid);
1188 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1189 set_bit(DISCONN_UPCALL, &ep->com.history);
1190 }
1191 }
1192
peer_abort_upcall(struct c4iw_ep * ep)1193 static void peer_abort_upcall(struct c4iw_ep *ep)
1194 {
1195 struct iw_cm_event event;
1196
1197 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1198 memset(&event, 0, sizeof(event));
1199 event.event = IW_CM_EVENT_CLOSE;
1200 event.status = -ECONNRESET;
1201 if (ep->com.cm_id) {
1202 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1203 ep->com.cm_id, ep->hwtid);
1204 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1205 ep->com.cm_id->rem_ref(ep->com.cm_id);
1206 ep->com.cm_id = NULL;
1207 set_bit(ABORT_UPCALL, &ep->com.history);
1208 }
1209 }
1210
connect_reply_upcall(struct c4iw_ep * ep,int status)1211 static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1212 {
1213 struct iw_cm_event event;
1214
1215 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1216 memset(&event, 0, sizeof(event));
1217 event.event = IW_CM_EVENT_CONNECT_REPLY;
1218 event.status = status;
1219 memcpy(&event.local_addr, &ep->com.local_addr,
1220 sizeof(ep->com.local_addr));
1221 memcpy(&event.remote_addr, &ep->com.remote_addr,
1222 sizeof(ep->com.remote_addr));
1223
1224 if ((status == 0) || (status == -ECONNREFUSED)) {
1225 if (!ep->tried_with_mpa_v1) {
1226 /* this means MPA_v2 is used */
1227 event.ord = ep->ird;
1228 event.ird = ep->ord;
1229 event.private_data_len = ep->plen -
1230 sizeof(struct mpa_v2_conn_params);
1231 event.private_data = ep->mpa_pkt +
1232 sizeof(struct mpa_message) +
1233 sizeof(struct mpa_v2_conn_params);
1234 } else {
1235 /* this means MPA_v1 is used */
1236 event.ord = cur_max_read_depth(ep->com.dev);
1237 event.ird = cur_max_read_depth(ep->com.dev);
1238 event.private_data_len = ep->plen;
1239 event.private_data = ep->mpa_pkt +
1240 sizeof(struct mpa_message);
1241 }
1242 }
1243
1244 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1245 ep->hwtid, status);
1246 set_bit(CONN_RPL_UPCALL, &ep->com.history);
1247 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1248
1249 if (status < 0) {
1250 ep->com.cm_id->rem_ref(ep->com.cm_id);
1251 ep->com.cm_id = NULL;
1252 }
1253 }
1254
connect_request_upcall(struct c4iw_ep * ep)1255 static int connect_request_upcall(struct c4iw_ep *ep)
1256 {
1257 struct iw_cm_event event;
1258 int ret;
1259
1260 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1261 memset(&event, 0, sizeof(event));
1262 event.event = IW_CM_EVENT_CONNECT_REQUEST;
1263 memcpy(&event.local_addr, &ep->com.local_addr,
1264 sizeof(ep->com.local_addr));
1265 memcpy(&event.remote_addr, &ep->com.remote_addr,
1266 sizeof(ep->com.remote_addr));
1267 event.provider_data = ep;
1268 if (!ep->tried_with_mpa_v1) {
1269 /* this means MPA_v2 is used */
1270 event.ord = ep->ord;
1271 event.ird = ep->ird;
1272 event.private_data_len = ep->plen -
1273 sizeof(struct mpa_v2_conn_params);
1274 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1275 sizeof(struct mpa_v2_conn_params);
1276 } else {
1277 /* this means MPA_v1 is used. Send max supported */
1278 event.ord = cur_max_read_depth(ep->com.dev);
1279 event.ird = cur_max_read_depth(ep->com.dev);
1280 event.private_data_len = ep->plen;
1281 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1282 }
1283 c4iw_get_ep(&ep->com);
1284 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1285 &event);
1286 if (ret)
1287 c4iw_put_ep(&ep->com);
1288 set_bit(CONNREQ_UPCALL, &ep->com.history);
1289 c4iw_put_ep(&ep->parent_ep->com);
1290 return ret;
1291 }
1292
established_upcall(struct c4iw_ep * ep)1293 static void established_upcall(struct c4iw_ep *ep)
1294 {
1295 struct iw_cm_event event;
1296
1297 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1298 memset(&event, 0, sizeof(event));
1299 event.event = IW_CM_EVENT_ESTABLISHED;
1300 event.ird = ep->ord;
1301 event.ord = ep->ird;
1302 if (ep->com.cm_id) {
1303 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1304 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1305 set_bit(ESTAB_UPCALL, &ep->com.history);
1306 }
1307 }
1308
update_rx_credits(struct c4iw_ep * ep,u32 credits)1309 static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1310 {
1311 struct cpl_rx_data_ack *req;
1312 struct sk_buff *skb;
1313 int wrlen = roundup(sizeof *req, 16);
1314
1315 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1316 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1317 if (!skb) {
1318 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1319 return 0;
1320 }
1321
1322 /*
1323 * If we couldn't specify the entire rcv window at connection setup
1324 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1325 * then add the overage in to the credits returned.
1326 */
1327 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1328 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
1329
1330 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1331 memset(req, 0, wrlen);
1332 INIT_TP_WR(req, ep->hwtid);
1333 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1334 ep->hwtid));
1335 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
1336 RX_DACK_CHANGE_F |
1337 RX_DACK_MODE_V(dack_mode));
1338 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
1339 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1340 return credits;
1341 }
1342
1343 #define RELAXED_IRD_NEGOTIATION 1
1344
process_mpa_reply(struct c4iw_ep * ep,struct sk_buff * skb)1345 static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
1346 {
1347 struct mpa_message *mpa;
1348 struct mpa_v2_conn_params *mpa_v2_params;
1349 u16 plen;
1350 u16 resp_ird, resp_ord;
1351 u8 rtr_mismatch = 0, insuff_ird = 0;
1352 struct c4iw_qp_attributes attrs;
1353 enum c4iw_qp_attr_mask mask;
1354 int err;
1355 int disconnect = 0;
1356
1357 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1358
1359 /*
1360 * Stop mpa timer. If it expired, then
1361 * we ignore the MPA reply. process_timeout()
1362 * will abort the connection.
1363 */
1364 if (stop_ep_timer(ep))
1365 return 0;
1366
1367 /*
1368 * If we get more than the supported amount of private data
1369 * then we must fail this connection.
1370 */
1371 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1372 err = -EINVAL;
1373 goto err;
1374 }
1375
1376 /*
1377 * copy the new data into our accumulation buffer.
1378 */
1379 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1380 skb->len);
1381 ep->mpa_pkt_len += skb->len;
1382
1383 /*
1384 * if we don't even have the mpa message, then bail.
1385 */
1386 if (ep->mpa_pkt_len < sizeof(*mpa))
1387 return 0;
1388 mpa = (struct mpa_message *) ep->mpa_pkt;
1389
1390 /* Validate MPA header. */
1391 if (mpa->revision > mpa_rev) {
1392 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1393 " Received = %d\n", __func__, mpa_rev, mpa->revision);
1394 err = -EPROTO;
1395 goto err;
1396 }
1397 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1398 err = -EPROTO;
1399 goto err;
1400 }
1401
1402 plen = ntohs(mpa->private_data_size);
1403
1404 /*
1405 * Fail if there's too much private data.
1406 */
1407 if (plen > MPA_MAX_PRIVATE_DATA) {
1408 err = -EPROTO;
1409 goto err;
1410 }
1411
1412 /*
1413 * If plen does not account for pkt size
1414 */
1415 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1416 err = -EPROTO;
1417 goto err;
1418 }
1419
1420 ep->plen = (u8) plen;
1421
1422 /*
1423 * If we don't have all the pdata yet, then bail.
1424 * We'll continue process when more data arrives.
1425 */
1426 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1427 return 0;
1428
1429 if (mpa->flags & MPA_REJECT) {
1430 err = -ECONNREFUSED;
1431 goto err;
1432 }
1433
1434 /*
1435 * If we get here we have accumulated the entire mpa
1436 * start reply message including private data. And
1437 * the MPA header is valid.
1438 */
1439 __state_set(&ep->com, FPDU_MODE);
1440 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1441 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1442 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1443 ep->mpa_attr.version = mpa->revision;
1444 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1445
1446 if (mpa->revision == 2) {
1447 ep->mpa_attr.enhanced_rdma_conn =
1448 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1449 if (ep->mpa_attr.enhanced_rdma_conn) {
1450 mpa_v2_params = (struct mpa_v2_conn_params *)
1451 (ep->mpa_pkt + sizeof(*mpa));
1452 resp_ird = ntohs(mpa_v2_params->ird) &
1453 MPA_V2_IRD_ORD_MASK;
1454 resp_ord = ntohs(mpa_v2_params->ord) &
1455 MPA_V2_IRD_ORD_MASK;
1456 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1457 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
1458
1459 /*
1460 * This is a double-check. Ideally, below checks are
1461 * not required since ird/ord stuff has been taken
1462 * care of in c4iw_accept_cr
1463 */
1464 if (ep->ird < resp_ord) {
1465 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1466 ep->com.dev->rdev.lldi.max_ordird_qp)
1467 ep->ird = resp_ord;
1468 else
1469 insuff_ird = 1;
1470 } else if (ep->ird > resp_ord) {
1471 ep->ird = resp_ord;
1472 }
1473 if (ep->ord > resp_ird) {
1474 if (RELAXED_IRD_NEGOTIATION)
1475 ep->ord = resp_ird;
1476 else
1477 insuff_ird = 1;
1478 }
1479 if (insuff_ird) {
1480 err = -ENOMEM;
1481 ep->ird = resp_ord;
1482 ep->ord = resp_ird;
1483 }
1484
1485 if (ntohs(mpa_v2_params->ird) &
1486 MPA_V2_PEER2PEER_MODEL) {
1487 if (ntohs(mpa_v2_params->ord) &
1488 MPA_V2_RDMA_WRITE_RTR)
1489 ep->mpa_attr.p2p_type =
1490 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1491 else if (ntohs(mpa_v2_params->ord) &
1492 MPA_V2_RDMA_READ_RTR)
1493 ep->mpa_attr.p2p_type =
1494 FW_RI_INIT_P2PTYPE_READ_REQ;
1495 }
1496 }
1497 } else if (mpa->revision == 1)
1498 if (peer2peer)
1499 ep->mpa_attr.p2p_type = p2p_type;
1500
1501 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1502 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1503 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1504 ep->mpa_attr.recv_marker_enabled,
1505 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1506 ep->mpa_attr.p2p_type, p2p_type);
1507
1508 /*
1509 * If responder's RTR does not match with that of initiator, assign
1510 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1511 * generated when moving QP to RTS state.
1512 * A TERM message will be sent after QP has moved to RTS state
1513 */
1514 if ((ep->mpa_attr.version == 2) && peer2peer &&
1515 (ep->mpa_attr.p2p_type != p2p_type)) {
1516 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1517 rtr_mismatch = 1;
1518 }
1519
1520 attrs.mpa_attr = ep->mpa_attr;
1521 attrs.max_ird = ep->ird;
1522 attrs.max_ord = ep->ord;
1523 attrs.llp_stream_handle = ep;
1524 attrs.next_state = C4IW_QP_STATE_RTS;
1525
1526 mask = C4IW_QP_ATTR_NEXT_STATE |
1527 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1528 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1529
1530 /* bind QP and TID with INIT_WR */
1531 err = c4iw_modify_qp(ep->com.qp->rhp,
1532 ep->com.qp, mask, &attrs, 1);
1533 if (err)
1534 goto err;
1535
1536 /*
1537 * If responder's RTR requirement did not match with what initiator
1538 * supports, generate TERM message
1539 */
1540 if (rtr_mismatch) {
1541 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1542 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1543 attrs.ecode = MPA_NOMATCH_RTR;
1544 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1545 attrs.send_term = 1;
1546 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1547 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1548 err = -ENOMEM;
1549 disconnect = 1;
1550 goto out;
1551 }
1552
1553 /*
1554 * Generate TERM if initiator IRD is not sufficient for responder
1555 * provided ORD. Currently, we do the same behaviour even when
1556 * responder provided IRD is also not sufficient as regards to
1557 * initiator ORD.
1558 */
1559 if (insuff_ird) {
1560 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1561 __func__);
1562 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1563 attrs.ecode = MPA_INSUFF_IRD;
1564 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1565 attrs.send_term = 1;
1566 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1567 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1568 err = -ENOMEM;
1569 disconnect = 1;
1570 goto out;
1571 }
1572 goto out;
1573 err:
1574 __state_set(&ep->com, ABORTING);
1575 send_abort(ep, skb, GFP_KERNEL);
1576 out:
1577 connect_reply_upcall(ep, err);
1578 return disconnect;
1579 }
1580
process_mpa_request(struct c4iw_ep * ep,struct sk_buff * skb)1581 static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1582 {
1583 struct mpa_message *mpa;
1584 struct mpa_v2_conn_params *mpa_v2_params;
1585 u16 plen;
1586
1587 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1588
1589 /*
1590 * If we get more than the supported amount of private data
1591 * then we must fail this connection.
1592 */
1593 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1594 (void)stop_ep_timer(ep);
1595 abort_connection(ep, skb, GFP_KERNEL);
1596 return;
1597 }
1598
1599 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1600
1601 /*
1602 * Copy the new data into our accumulation buffer.
1603 */
1604 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1605 skb->len);
1606 ep->mpa_pkt_len += skb->len;
1607
1608 /*
1609 * If we don't even have the mpa message, then bail.
1610 * We'll continue process when more data arrives.
1611 */
1612 if (ep->mpa_pkt_len < sizeof(*mpa))
1613 return;
1614
1615 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1616 mpa = (struct mpa_message *) ep->mpa_pkt;
1617
1618 /*
1619 * Validate MPA Header.
1620 */
1621 if (mpa->revision > mpa_rev) {
1622 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1623 " Received = %d\n", __func__, mpa_rev, mpa->revision);
1624 (void)stop_ep_timer(ep);
1625 abort_connection(ep, skb, GFP_KERNEL);
1626 return;
1627 }
1628
1629 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
1630 (void)stop_ep_timer(ep);
1631 abort_connection(ep, skb, GFP_KERNEL);
1632 return;
1633 }
1634
1635 plen = ntohs(mpa->private_data_size);
1636
1637 /*
1638 * Fail if there's too much private data.
1639 */
1640 if (plen > MPA_MAX_PRIVATE_DATA) {
1641 (void)stop_ep_timer(ep);
1642 abort_connection(ep, skb, GFP_KERNEL);
1643 return;
1644 }
1645
1646 /*
1647 * If plen does not account for pkt size
1648 */
1649 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1650 (void)stop_ep_timer(ep);
1651 abort_connection(ep, skb, GFP_KERNEL);
1652 return;
1653 }
1654 ep->plen = (u8) plen;
1655
1656 /*
1657 * If we don't have all the pdata yet, then bail.
1658 */
1659 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1660 return;
1661
1662 /*
1663 * If we get here we have accumulated the entire mpa
1664 * start reply message including private data.
1665 */
1666 ep->mpa_attr.initiator = 0;
1667 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1668 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1669 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1670 ep->mpa_attr.version = mpa->revision;
1671 if (mpa->revision == 1)
1672 ep->tried_with_mpa_v1 = 1;
1673 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1674
1675 if (mpa->revision == 2) {
1676 ep->mpa_attr.enhanced_rdma_conn =
1677 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1678 if (ep->mpa_attr.enhanced_rdma_conn) {
1679 mpa_v2_params = (struct mpa_v2_conn_params *)
1680 (ep->mpa_pkt + sizeof(*mpa));
1681 ep->ird = ntohs(mpa_v2_params->ird) &
1682 MPA_V2_IRD_ORD_MASK;
1683 ep->ord = ntohs(mpa_v2_params->ord) &
1684 MPA_V2_IRD_ORD_MASK;
1685 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1686 ep->ord);
1687 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1688 if (peer2peer) {
1689 if (ntohs(mpa_v2_params->ord) &
1690 MPA_V2_RDMA_WRITE_RTR)
1691 ep->mpa_attr.p2p_type =
1692 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1693 else if (ntohs(mpa_v2_params->ord) &
1694 MPA_V2_RDMA_READ_RTR)
1695 ep->mpa_attr.p2p_type =
1696 FW_RI_INIT_P2PTYPE_READ_REQ;
1697 }
1698 }
1699 } else if (mpa->revision == 1)
1700 if (peer2peer)
1701 ep->mpa_attr.p2p_type = p2p_type;
1702
1703 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1704 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1705 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1706 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1707 ep->mpa_attr.p2p_type);
1708
1709 /*
1710 * If the endpoint timer already expired, then we ignore
1711 * the start request. process_timeout() will abort
1712 * the connection.
1713 */
1714 if (!stop_ep_timer(ep)) {
1715 __state_set(&ep->com, MPA_REQ_RCVD);
1716
1717 /* drive upcall */
1718 mutex_lock_nested(&ep->parent_ep->com.mutex,
1719 SINGLE_DEPTH_NESTING);
1720 if (ep->parent_ep->com.state != DEAD) {
1721 if (connect_request_upcall(ep))
1722 abort_connection(ep, skb, GFP_KERNEL);
1723 } else {
1724 abort_connection(ep, skb, GFP_KERNEL);
1725 }
1726 mutex_unlock(&ep->parent_ep->com.mutex);
1727 }
1728 return;
1729 }
1730
rx_data(struct c4iw_dev * dev,struct sk_buff * skb)1731 static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1732 {
1733 struct c4iw_ep *ep;
1734 struct cpl_rx_data *hdr = cplhdr(skb);
1735 unsigned int dlen = ntohs(hdr->len);
1736 unsigned int tid = GET_TID(hdr);
1737 struct tid_info *t = dev->rdev.lldi.tids;
1738 __u8 status = hdr->status;
1739 int disconnect = 0;
1740
1741 ep = lookup_tid(t, tid);
1742 if (!ep)
1743 return 0;
1744 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1745 skb_pull(skb, sizeof(*hdr));
1746 skb_trim(skb, dlen);
1747 mutex_lock(&ep->com.mutex);
1748
1749 /* update RX credits */
1750 update_rx_credits(ep, dlen);
1751
1752 switch (ep->com.state) {
1753 case MPA_REQ_SENT:
1754 ep->rcv_seq += dlen;
1755 disconnect = process_mpa_reply(ep, skb);
1756 break;
1757 case MPA_REQ_WAIT:
1758 ep->rcv_seq += dlen;
1759 process_mpa_request(ep, skb);
1760 break;
1761 case FPDU_MODE: {
1762 struct c4iw_qp_attributes attrs;
1763 BUG_ON(!ep->com.qp);
1764 if (status)
1765 pr_err("%s Unexpected streaming data." \
1766 " qpid %u ep %p state %d tid %u status %d\n",
1767 __func__, ep->com.qp->wq.sq.qid, ep,
1768 ep->com.state, ep->hwtid, status);
1769 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1770 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1771 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1772 disconnect = 1;
1773 break;
1774 }
1775 default:
1776 break;
1777 }
1778 mutex_unlock(&ep->com.mutex);
1779 if (disconnect)
1780 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1781 return 0;
1782 }
1783
abort_rpl(struct c4iw_dev * dev,struct sk_buff * skb)1784 static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1785 {
1786 struct c4iw_ep *ep;
1787 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
1788 int release = 0;
1789 unsigned int tid = GET_TID(rpl);
1790 struct tid_info *t = dev->rdev.lldi.tids;
1791
1792 ep = lookup_tid(t, tid);
1793 if (!ep) {
1794 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1795 return 0;
1796 }
1797 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1798 mutex_lock(&ep->com.mutex);
1799 switch (ep->com.state) {
1800 case ABORTING:
1801 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
1802 __state_set(&ep->com, DEAD);
1803 release = 1;
1804 break;
1805 default:
1806 printk(KERN_ERR "%s ep %p state %d\n",
1807 __func__, ep, ep->com.state);
1808 break;
1809 }
1810 mutex_unlock(&ep->com.mutex);
1811
1812 if (release)
1813 release_ep_resources(ep);
1814 return 0;
1815 }
1816
send_fw_act_open_req(struct c4iw_ep * ep,unsigned int atid)1817 static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1818 {
1819 struct sk_buff *skb;
1820 struct fw_ofld_connection_wr *req;
1821 unsigned int mtu_idx;
1822 int wscale;
1823 struct sockaddr_in *sin;
1824 int win;
1825
1826 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1827 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1828 memset(req, 0, sizeof(*req));
1829 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
1830 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
1831 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1832 ep->com.dev->rdev.lldi.ports[0],
1833 ep->l2t));
1834 sin = (struct sockaddr_in *)&ep->com.mapped_local_addr;
1835 req->le.lport = sin->sin_port;
1836 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
1837 sin = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
1838 req->le.pport = sin->sin_port;
1839 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
1840 req->tcb.t_state_to_astid =
1841 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1842 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
1843 req->tcb.cplrxdataack_cplpassacceptrpl =
1844 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
1845 req->tcb.tx_max = (__force __be32) jiffies;
1846 req->tcb.rcv_adv = htons(1);
1847 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
1848 enable_tcp_timestamps,
1849 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
1850 wscale = compute_wscale(rcv_win);
1851
1852 /*
1853 * Specify the largest window that will fit in opt0. The
1854 * remainder will be specified in the rx_data_ack.
1855 */
1856 win = ep->rcv_win >> 10;
1857 if (win > RCV_BUFSIZ_M)
1858 win = RCV_BUFSIZ_M;
1859
1860 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1861 (nocong ? NO_CONG_F : 0) |
1862 KEEP_ALIVE_F |
1863 DELACK_F |
1864 WND_SCALE_V(wscale) |
1865 MSS_IDX_V(mtu_idx) |
1866 L2T_IDX_V(ep->l2t->idx) |
1867 TX_CHAN_V(ep->tx_chan) |
1868 SMAC_SEL_V(ep->smac_idx) |
1869 DSCP_V(ep->tos) |
1870 ULP_MODE_V(ULP_MODE_TCPDDP) |
1871 RCV_BUFSIZ_V(win));
1872 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1873 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1874 RX_CHANNEL_V(0) |
1875 CCTRL_ECN_V(enable_ecn) |
1876 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
1877 if (enable_tcp_timestamps)
1878 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
1879 if (enable_tcp_sack)
1880 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
1881 if (wscale && enable_tcp_window_scaling)
1882 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1883 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1884 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
1885 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1886 set_bit(ACT_OFLD_CONN, &ep->com.history);
1887 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1888 }
1889
1890 /*
1891 * Return whether a failed active open has allocated a TID
1892 */
act_open_has_tid(int status)1893 static inline int act_open_has_tid(int status)
1894 {
1895 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1896 status != CPL_ERR_ARP_MISS;
1897 }
1898
1899 /* Returns whether a CPL status conveys negative advice.
1900 */
is_neg_adv(unsigned int status)1901 static int is_neg_adv(unsigned int status)
1902 {
1903 return status == CPL_ERR_RTX_NEG_ADVICE ||
1904 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1905 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1906 }
1907
neg_adv_str(unsigned int status)1908 static char *neg_adv_str(unsigned int status)
1909 {
1910 switch (status) {
1911 case CPL_ERR_RTX_NEG_ADVICE:
1912 return "Retransmit timeout";
1913 case CPL_ERR_PERSIST_NEG_ADVICE:
1914 return "Persist timeout";
1915 case CPL_ERR_KEEPALV_NEG_ADVICE:
1916 return "Keepalive timeout";
1917 default:
1918 return "Unknown";
1919 }
1920 }
1921
set_tcp_window(struct c4iw_ep * ep,struct port_info * pi)1922 static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1923 {
1924 ep->snd_win = snd_win;
1925 ep->rcv_win = rcv_win;
1926 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1927 }
1928
1929 #define ACT_OPEN_RETRY_COUNT 2
1930
import_ep(struct c4iw_ep * ep,int iptype,__u8 * peer_ip,struct dst_entry * dst,struct c4iw_dev * cdev,bool clear_mpa_v1,enum chip_type adapter_type)1931 static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1932 struct dst_entry *dst, struct c4iw_dev *cdev,
1933 bool clear_mpa_v1, enum chip_type adapter_type)
1934 {
1935 struct neighbour *n;
1936 int err, step;
1937 struct net_device *pdev;
1938
1939 n = dst_neigh_lookup(dst, peer_ip);
1940 if (!n)
1941 return -ENODEV;
1942
1943 rcu_read_lock();
1944 err = -ENOMEM;
1945 if (n->dev->flags & IFF_LOOPBACK) {
1946 if (iptype == 4)
1947 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1948 else if (IS_ENABLED(CONFIG_IPV6))
1949 for_each_netdev(&init_net, pdev) {
1950 if (ipv6_chk_addr(&init_net,
1951 (struct in6_addr *)peer_ip,
1952 pdev, 1))
1953 break;
1954 }
1955 else
1956 pdev = NULL;
1957
1958 if (!pdev) {
1959 err = -ENODEV;
1960 goto out;
1961 }
1962 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1963 n, pdev, 0);
1964 if (!ep->l2t)
1965 goto out;
1966 ep->mtu = pdev->mtu;
1967 ep->tx_chan = cxgb4_port_chan(pdev);
1968 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
1969 cxgb4_port_viid(pdev));
1970 step = cdev->rdev.lldi.ntxq /
1971 cdev->rdev.lldi.nchan;
1972 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1973 step = cdev->rdev.lldi.nrxq /
1974 cdev->rdev.lldi.nchan;
1975 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1976 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1977 cxgb4_port_idx(pdev) * step];
1978 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
1979 dev_put(pdev);
1980 } else {
1981 pdev = get_real_dev(n->dev);
1982 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1983 n, pdev, 0);
1984 if (!ep->l2t)
1985 goto out;
1986 ep->mtu = dst_mtu(dst);
1987 ep->tx_chan = cxgb4_port_chan(pdev);
1988 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
1989 cxgb4_port_viid(pdev));
1990 step = cdev->rdev.lldi.ntxq /
1991 cdev->rdev.lldi.nchan;
1992 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1993 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1994 step = cdev->rdev.lldi.nrxq /
1995 cdev->rdev.lldi.nchan;
1996 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1997 cxgb4_port_idx(pdev) * step];
1998 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
1999
2000 if (clear_mpa_v1) {
2001 ep->retry_with_mpa_v1 = 0;
2002 ep->tried_with_mpa_v1 = 0;
2003 }
2004 }
2005 err = 0;
2006 out:
2007 rcu_read_unlock();
2008
2009 neigh_release(n);
2010
2011 return err;
2012 }
2013
c4iw_reconnect(struct c4iw_ep * ep)2014 static int c4iw_reconnect(struct c4iw_ep *ep)
2015 {
2016 int err = 0;
2017 struct sockaddr_in *laddr = (struct sockaddr_in *)
2018 &ep->com.cm_id->local_addr;
2019 struct sockaddr_in *raddr = (struct sockaddr_in *)
2020 &ep->com.cm_id->remote_addr;
2021 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
2022 &ep->com.cm_id->local_addr;
2023 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
2024 &ep->com.cm_id->remote_addr;
2025 int iptype;
2026 __u8 *ra;
2027
2028 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2029 init_timer(&ep->timer);
2030
2031 /*
2032 * Allocate an active TID to initiate a TCP connection.
2033 */
2034 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2035 if (ep->atid == -1) {
2036 pr_err("%s - cannot alloc atid.\n", __func__);
2037 err = -ENOMEM;
2038 goto fail2;
2039 }
2040 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2041
2042 /* find a route */
2043 if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
2044 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2045 raddr->sin_addr.s_addr, laddr->sin_port,
2046 raddr->sin_port, 0);
2047 iptype = 4;
2048 ra = (__u8 *)&raddr->sin_addr;
2049 } else {
2050 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2051 raddr6->sin6_addr.s6_addr,
2052 laddr6->sin6_port, raddr6->sin6_port, 0,
2053 raddr6->sin6_scope_id);
2054 iptype = 6;
2055 ra = (__u8 *)&raddr6->sin6_addr;
2056 }
2057 if (!ep->dst) {
2058 pr_err("%s - cannot find route.\n", __func__);
2059 err = -EHOSTUNREACH;
2060 goto fail3;
2061 }
2062 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
2063 ep->com.dev->rdev.lldi.adapter_type);
2064 if (err) {
2065 pr_err("%s - cannot alloc l2e.\n", __func__);
2066 goto fail4;
2067 }
2068
2069 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2070 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2071 ep->l2t->idx);
2072
2073 state_set(&ep->com, CONNECTING);
2074 ep->tos = 0;
2075
2076 /* send connect request to rnic */
2077 err = send_connect(ep);
2078 if (!err)
2079 goto out;
2080
2081 cxgb4_l2t_release(ep->l2t);
2082 fail4:
2083 dst_release(ep->dst);
2084 fail3:
2085 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2086 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2087 fail2:
2088 /*
2089 * remember to send notification to upper layer.
2090 * We are in here so the upper layer is not aware that this is
2091 * re-connect attempt and so, upper layer is still waiting for
2092 * response of 1st connect request.
2093 */
2094 connect_reply_upcall(ep, -ECONNRESET);
2095 c4iw_put_ep(&ep->com);
2096 out:
2097 return err;
2098 }
2099
act_open_rpl(struct c4iw_dev * dev,struct sk_buff * skb)2100 static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2101 {
2102 struct c4iw_ep *ep;
2103 struct cpl_act_open_rpl *rpl = cplhdr(skb);
2104 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2105 ntohl(rpl->atid_status)));
2106 struct tid_info *t = dev->rdev.lldi.tids;
2107 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
2108 struct sockaddr_in *la;
2109 struct sockaddr_in *ra;
2110 struct sockaddr_in6 *la6;
2111 struct sockaddr_in6 *ra6;
2112
2113 ep = lookup_atid(t, atid);
2114 la = (struct sockaddr_in *)&ep->com.mapped_local_addr;
2115 ra = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
2116 la6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
2117 ra6 = (struct sockaddr_in6 *)&ep->com.mapped_remote_addr;
2118
2119 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2120 status, status2errno(status));
2121
2122 if (is_neg_adv(status)) {
2123 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2124 __func__, atid, status, neg_adv_str(status));
2125 ep->stats.connect_neg_adv++;
2126 mutex_lock(&dev->rdev.stats.lock);
2127 dev->rdev.stats.neg_adv++;
2128 mutex_unlock(&dev->rdev.stats.lock);
2129 return 0;
2130 }
2131
2132 set_bit(ACT_OPEN_RPL, &ep->com.history);
2133
2134 /*
2135 * Log interesting failures.
2136 */
2137 switch (status) {
2138 case CPL_ERR_CONN_RESET:
2139 case CPL_ERR_CONN_TIMEDOUT:
2140 break;
2141 case CPL_ERR_TCAM_FULL:
2142 mutex_lock(&dev->rdev.stats.lock);
2143 dev->rdev.stats.tcam_full++;
2144 mutex_unlock(&dev->rdev.stats.lock);
2145 if (ep->com.local_addr.ss_family == AF_INET &&
2146 dev->rdev.lldi.enable_fw_ofld_conn) {
2147 send_fw_act_open_req(ep,
2148 TID_TID_G(AOPEN_ATID_G(
2149 ntohl(rpl->atid_status))));
2150 return 0;
2151 }
2152 break;
2153 case CPL_ERR_CONN_EXIST:
2154 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2155 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2156 if (ep->com.remote_addr.ss_family == AF_INET6) {
2157 struct sockaddr_in6 *sin6 =
2158 (struct sockaddr_in6 *)
2159 &ep->com.mapped_local_addr;
2160 cxgb4_clip_release(
2161 ep->com.dev->rdev.lldi.ports[0],
2162 (const u32 *)
2163 &sin6->sin6_addr.s6_addr, 1);
2164 }
2165 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2166 atid);
2167 cxgb4_free_atid(t, atid);
2168 dst_release(ep->dst);
2169 cxgb4_l2t_release(ep->l2t);
2170 c4iw_reconnect(ep);
2171 return 0;
2172 }
2173 break;
2174 default:
2175 if (ep->com.local_addr.ss_family == AF_INET) {
2176 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2177 atid, status, status2errno(status),
2178 &la->sin_addr.s_addr, ntohs(la->sin_port),
2179 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2180 } else {
2181 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2182 atid, status, status2errno(status),
2183 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2184 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2185 }
2186 break;
2187 }
2188
2189 connect_reply_upcall(ep, status2errno(status));
2190 state_set(&ep->com, DEAD);
2191
2192 if (ep->com.remote_addr.ss_family == AF_INET6) {
2193 struct sockaddr_in6 *sin6 =
2194 (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
2195 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2196 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2197 }
2198 if (status && act_open_has_tid(status))
2199 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2200
2201 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
2202 cxgb4_free_atid(t, atid);
2203 dst_release(ep->dst);
2204 cxgb4_l2t_release(ep->l2t);
2205 c4iw_put_ep(&ep->com);
2206
2207 return 0;
2208 }
2209
pass_open_rpl(struct c4iw_dev * dev,struct sk_buff * skb)2210 static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2211 {
2212 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2213 struct tid_info *t = dev->rdev.lldi.tids;
2214 unsigned int stid = GET_TID(rpl);
2215 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2216
2217 if (!ep) {
2218 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2219 goto out;
2220 }
2221 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2222 rpl->status, status2errno(rpl->status));
2223 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
2224
2225 out:
2226 return 0;
2227 }
2228
close_listsrv_rpl(struct c4iw_dev * dev,struct sk_buff * skb)2229 static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2230 {
2231 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2232 struct tid_info *t = dev->rdev.lldi.tids;
2233 unsigned int stid = GET_TID(rpl);
2234 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2235
2236 PDBG("%s ep %p\n", __func__, ep);
2237 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
2238 return 0;
2239 }
2240
accept_cr(struct c4iw_ep * ep,struct sk_buff * skb,struct cpl_pass_accept_req * req)2241 static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2242 struct cpl_pass_accept_req *req)
2243 {
2244 struct cpl_pass_accept_rpl *rpl;
2245 unsigned int mtu_idx;
2246 u64 opt0;
2247 u32 opt2;
2248 int wscale;
2249 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
2250 int win;
2251 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
2252
2253 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2254 BUG_ON(skb_cloned(skb));
2255
2256 skb_get(skb);
2257 rpl = cplhdr(skb);
2258 if (!is_t4(adapter_type)) {
2259 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2260 rpl5 = (void *)rpl;
2261 INIT_TP_WR(rpl5, ep->hwtid);
2262 } else {
2263 skb_trim(skb, sizeof(*rpl));
2264 INIT_TP_WR(rpl, ep->hwtid);
2265 }
2266 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2267 ep->hwtid));
2268
2269 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
2270 enable_tcp_timestamps && req->tcpopt.tstamp,
2271 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
2272 wscale = compute_wscale(rcv_win);
2273
2274 /*
2275 * Specify the largest window that will fit in opt0. The
2276 * remainder will be specified in the rx_data_ack.
2277 */
2278 win = ep->rcv_win >> 10;
2279 if (win > RCV_BUFSIZ_M)
2280 win = RCV_BUFSIZ_M;
2281 opt0 = (nocong ? NO_CONG_F : 0) |
2282 KEEP_ALIVE_F |
2283 DELACK_F |
2284 WND_SCALE_V(wscale) |
2285 MSS_IDX_V(mtu_idx) |
2286 L2T_IDX_V(ep->l2t->idx) |
2287 TX_CHAN_V(ep->tx_chan) |
2288 SMAC_SEL_V(ep->smac_idx) |
2289 DSCP_V(ep->tos >> 2) |
2290 ULP_MODE_V(ULP_MODE_TCPDDP) |
2291 RCV_BUFSIZ_V(win);
2292 opt2 = RX_CHANNEL_V(0) |
2293 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
2294
2295 if (enable_tcp_timestamps && req->tcpopt.tstamp)
2296 opt2 |= TSTAMPS_EN_F;
2297 if (enable_tcp_sack && req->tcpopt.sack)
2298 opt2 |= SACK_EN_F;
2299 if (wscale && enable_tcp_window_scaling)
2300 opt2 |= WND_SCALE_EN_F;
2301 if (enable_ecn) {
2302 const struct tcphdr *tcph;
2303 u32 hlen = ntohl(req->hdr_len);
2304
2305 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2306 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2307 IP_HDR_LEN_G(hlen);
2308 else
2309 tcph = (const void *)(req + 1) +
2310 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
2311 if (tcph->ece && tcph->cwr)
2312 opt2 |= CCTRL_ECN_V(1);
2313 }
2314 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
2315 u32 isn = (prandom_u32() & ~7UL) - 1;
2316 opt2 |= T5_OPT_2_VALID_F;
2317 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
2318 opt2 |= T5_ISS_F;
2319 rpl5 = (void *)rpl;
2320 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2321 if (peer2peer)
2322 isn += 4;
2323 rpl5->iss = cpu_to_be32(isn);
2324 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
2325 }
2326
2327 rpl->opt0 = cpu_to_be64(opt0);
2328 rpl->opt2 = cpu_to_be32(opt2);
2329 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
2330 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
2331 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2332
2333 return;
2334 }
2335
reject_cr(struct c4iw_dev * dev,u32 hwtid,struct sk_buff * skb)2336 static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
2337 {
2338 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
2339 BUG_ON(skb_cloned(skb));
2340 skb_trim(skb, sizeof(struct cpl_tid_release));
2341 release_tid(&dev->rdev, hwtid, skb);
2342 return;
2343 }
2344
get_4tuple(struct cpl_pass_accept_req * req,enum chip_type type,int * iptype,__u8 * local_ip,__u8 * peer_ip,__be16 * local_port,__be16 * peer_port)2345 static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2346 int *iptype, __u8 *local_ip, __u8 *peer_ip,
2347 __be16 *local_port, __be16 *peer_port)
2348 {
2349 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2350 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2351 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2352 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2353 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2354 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2355 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
2356 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
2357 struct tcphdr *tcp = (struct tcphdr *)
2358 ((u8 *)(req + 1) + eth_len + ip_len);
2359
2360 if (ip->version == 4) {
2361 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2362 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2363 ntohs(tcp->dest));
2364 *iptype = 4;
2365 memcpy(peer_ip, &ip->saddr, 4);
2366 memcpy(local_ip, &ip->daddr, 4);
2367 } else {
2368 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2369 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2370 ntohs(tcp->dest));
2371 *iptype = 6;
2372 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2373 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2374 }
2375 *peer_port = tcp->source;
2376 *local_port = tcp->dest;
2377
2378 return;
2379 }
2380
pass_accept_req(struct c4iw_dev * dev,struct sk_buff * skb)2381 static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2382 {
2383 struct c4iw_ep *child_ep = NULL, *parent_ep;
2384 struct cpl_pass_accept_req *req = cplhdr(skb);
2385 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
2386 struct tid_info *t = dev->rdev.lldi.tids;
2387 unsigned int hwtid = GET_TID(req);
2388 struct dst_entry *dst;
2389 __u8 local_ip[16], peer_ip[16];
2390 __be16 local_port, peer_port;
2391 struct sockaddr_in6 *sin6;
2392 int err;
2393 u16 peer_mss = ntohs(req->tcpopt.mss);
2394 int iptype;
2395 unsigned short hdrs;
2396
2397 parent_ep = lookup_stid(t, stid);
2398 if (!parent_ep) {
2399 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2400 goto reject;
2401 }
2402
2403 if (state_read(&parent_ep->com) != LISTEN) {
2404 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
2405 __func__);
2406 goto reject;
2407 }
2408
2409 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2410 local_ip, peer_ip, &local_port, &peer_port);
2411
2412 /* Find output route */
2413 if (iptype == 4) {
2414 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2415 , __func__, parent_ep, hwtid,
2416 local_ip, peer_ip, ntohs(local_port),
2417 ntohs(peer_port), peer_mss);
2418 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2419 local_port, peer_port,
2420 PASS_OPEN_TOS_G(ntohl(req->tos_stid)));
2421 } else {
2422 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2423 , __func__, parent_ep, hwtid,
2424 local_ip, peer_ip, ntohs(local_port),
2425 ntohs(peer_port), peer_mss);
2426 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
2427 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
2428 ((struct sockaddr_in6 *)
2429 &parent_ep->com.local_addr)->sin6_scope_id);
2430 }
2431 if (!dst) {
2432 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2433 __func__);
2434 goto reject;
2435 }
2436
2437 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2438 if (!child_ep) {
2439 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2440 __func__);
2441 dst_release(dst);
2442 goto reject;
2443 }
2444
2445 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
2446 parent_ep->com.dev->rdev.lldi.adapter_type);
2447 if (err) {
2448 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2449 __func__);
2450 dst_release(dst);
2451 kfree(child_ep);
2452 goto reject;
2453 }
2454
2455 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2456 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2457 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2458 child_ep->mtu = peer_mss + hdrs;
2459
2460 state_set(&child_ep->com, CONNECTING);
2461 child_ep->com.dev = dev;
2462 child_ep->com.cm_id = NULL;
2463
2464 /*
2465 * The mapped_local and mapped_remote addresses get setup with
2466 * the actual 4-tuple. The local address will be based on the
2467 * actual local address of the connection, but on the port number
2468 * of the parent listening endpoint. The remote address is
2469 * setup based on a query to the IWPM since we don't know what it
2470 * originally was before mapping. If no mapping was done, then
2471 * mapped_remote == remote, and mapped_local == local.
2472 */
2473 if (iptype == 4) {
2474 struct sockaddr_in *sin = (struct sockaddr_in *)
2475 &child_ep->com.mapped_local_addr;
2476
2477 sin->sin_family = PF_INET;
2478 sin->sin_port = local_port;
2479 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2480
2481 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2482 sin->sin_family = PF_INET;
2483 sin->sin_port = ((struct sockaddr_in *)
2484 &parent_ep->com.local_addr)->sin_port;
2485 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2486
2487 sin = (struct sockaddr_in *)&child_ep->com.mapped_remote_addr;
2488 sin->sin_family = PF_INET;
2489 sin->sin_port = peer_port;
2490 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2491 } else {
2492 sin6 = (struct sockaddr_in6 *)&child_ep->com.mapped_local_addr;
2493 sin6->sin6_family = PF_INET6;
2494 sin6->sin6_port = local_port;
2495 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2496
2497 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2498 sin6->sin6_family = PF_INET6;
2499 sin6->sin6_port = ((struct sockaddr_in6 *)
2500 &parent_ep->com.local_addr)->sin6_port;
2501 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2502
2503 sin6 = (struct sockaddr_in6 *)&child_ep->com.mapped_remote_addr;
2504 sin6->sin6_family = PF_INET6;
2505 sin6->sin6_port = peer_port;
2506 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2507 }
2508 memcpy(&child_ep->com.remote_addr, &child_ep->com.mapped_remote_addr,
2509 sizeof(child_ep->com.remote_addr));
2510 get_remote_addr(parent_ep, child_ep);
2511
2512 c4iw_get_ep(&parent_ep->com);
2513 child_ep->parent_ep = parent_ep;
2514 child_ep->tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
2515 child_ep->dst = dst;
2516 child_ep->hwtid = hwtid;
2517
2518 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
2519 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
2520
2521 init_timer(&child_ep->timer);
2522 cxgb4_insert_tid(t, child_ep, hwtid);
2523 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
2524 accept_cr(child_ep, skb, req);
2525 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2526 if (iptype == 6) {
2527 sin6 = (struct sockaddr_in6 *)&child_ep->com.mapped_local_addr;
2528 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2529 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2530 }
2531 goto out;
2532 reject:
2533 reject_cr(dev, hwtid, skb);
2534 out:
2535 return 0;
2536 }
2537
pass_establish(struct c4iw_dev * dev,struct sk_buff * skb)2538 static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2539 {
2540 struct c4iw_ep *ep;
2541 struct cpl_pass_establish *req = cplhdr(skb);
2542 struct tid_info *t = dev->rdev.lldi.tids;
2543 unsigned int tid = GET_TID(req);
2544
2545 ep = lookup_tid(t, tid);
2546 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2547 ep->snd_seq = be32_to_cpu(req->snd_isn);
2548 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2549
2550 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2551 ntohs(req->tcp_opt));
2552
2553 set_emss(ep, ntohs(req->tcp_opt));
2554
2555 dst_confirm(ep->dst);
2556 state_set(&ep->com, MPA_REQ_WAIT);
2557 start_ep_timer(ep);
2558 send_flowc(ep, skb);
2559 set_bit(PASS_ESTAB, &ep->com.history);
2560
2561 return 0;
2562 }
2563
peer_close(struct c4iw_dev * dev,struct sk_buff * skb)2564 static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2565 {
2566 struct cpl_peer_close *hdr = cplhdr(skb);
2567 struct c4iw_ep *ep;
2568 struct c4iw_qp_attributes attrs;
2569 int disconnect = 1;
2570 int release = 0;
2571 struct tid_info *t = dev->rdev.lldi.tids;
2572 unsigned int tid = GET_TID(hdr);
2573 int ret;
2574
2575 ep = lookup_tid(t, tid);
2576 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2577 dst_confirm(ep->dst);
2578
2579 set_bit(PEER_CLOSE, &ep->com.history);
2580 mutex_lock(&ep->com.mutex);
2581 switch (ep->com.state) {
2582 case MPA_REQ_WAIT:
2583 __state_set(&ep->com, CLOSING);
2584 break;
2585 case MPA_REQ_SENT:
2586 __state_set(&ep->com, CLOSING);
2587 connect_reply_upcall(ep, -ECONNRESET);
2588 break;
2589 case MPA_REQ_RCVD:
2590
2591 /*
2592 * We're gonna mark this puppy DEAD, but keep
2593 * the reference on it until the ULP accepts or
2594 * rejects the CR. Also wake up anyone waiting
2595 * in rdma connection migration (see c4iw_accept_cr()).
2596 */
2597 __state_set(&ep->com, CLOSING);
2598 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
2599 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2600 break;
2601 case MPA_REP_SENT:
2602 __state_set(&ep->com, CLOSING);
2603 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
2604 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2605 break;
2606 case FPDU_MODE:
2607 start_ep_timer(ep);
2608 __state_set(&ep->com, CLOSING);
2609 attrs.next_state = C4IW_QP_STATE_CLOSING;
2610 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2611 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2612 if (ret != -ECONNRESET) {
2613 peer_close_upcall(ep);
2614 disconnect = 1;
2615 }
2616 break;
2617 case ABORTING:
2618 disconnect = 0;
2619 break;
2620 case CLOSING:
2621 __state_set(&ep->com, MORIBUND);
2622 disconnect = 0;
2623 break;
2624 case MORIBUND:
2625 (void)stop_ep_timer(ep);
2626 if (ep->com.cm_id && ep->com.qp) {
2627 attrs.next_state = C4IW_QP_STATE_IDLE;
2628 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2629 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2630 }
2631 close_complete_upcall(ep, 0);
2632 __state_set(&ep->com, DEAD);
2633 release = 1;
2634 disconnect = 0;
2635 break;
2636 case DEAD:
2637 disconnect = 0;
2638 break;
2639 default:
2640 BUG_ON(1);
2641 }
2642 mutex_unlock(&ep->com.mutex);
2643 if (disconnect)
2644 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2645 if (release)
2646 release_ep_resources(ep);
2647 return 0;
2648 }
2649
peer_abort(struct c4iw_dev * dev,struct sk_buff * skb)2650 static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2651 {
2652 struct cpl_abort_req_rss *req = cplhdr(skb);
2653 struct c4iw_ep *ep;
2654 struct cpl_abort_rpl *rpl;
2655 struct sk_buff *rpl_skb;
2656 struct c4iw_qp_attributes attrs;
2657 int ret;
2658 int release = 0;
2659 struct tid_info *t = dev->rdev.lldi.tids;
2660 unsigned int tid = GET_TID(req);
2661
2662 ep = lookup_tid(t, tid);
2663 if (is_neg_adv(req->status)) {
2664 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2665 __func__, ep->hwtid, req->status,
2666 neg_adv_str(req->status));
2667 ep->stats.abort_neg_adv++;
2668 mutex_lock(&dev->rdev.stats.lock);
2669 dev->rdev.stats.neg_adv++;
2670 mutex_unlock(&dev->rdev.stats.lock);
2671 return 0;
2672 }
2673 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2674 ep->com.state);
2675 set_bit(PEER_ABORT, &ep->com.history);
2676
2677 /*
2678 * Wake up any threads in rdma_init() or rdma_fini().
2679 * However, this is not needed if com state is just
2680 * MPA_REQ_SENT
2681 */
2682 if (ep->com.state != MPA_REQ_SENT)
2683 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2684
2685 mutex_lock(&ep->com.mutex);
2686 switch (ep->com.state) {
2687 case CONNECTING:
2688 break;
2689 case MPA_REQ_WAIT:
2690 (void)stop_ep_timer(ep);
2691 break;
2692 case MPA_REQ_SENT:
2693 (void)stop_ep_timer(ep);
2694 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
2695 connect_reply_upcall(ep, -ECONNRESET);
2696 else {
2697 /*
2698 * we just don't send notification upwards because we
2699 * want to retry with mpa_v1 without upper layers even
2700 * knowing it.
2701 *
2702 * do some housekeeping so as to re-initiate the
2703 * connection
2704 */
2705 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2706 mpa_rev);
2707 ep->retry_with_mpa_v1 = 1;
2708 }
2709 break;
2710 case MPA_REP_SENT:
2711 break;
2712 case MPA_REQ_RCVD:
2713 break;
2714 case MORIBUND:
2715 case CLOSING:
2716 stop_ep_timer(ep);
2717 /*FALLTHROUGH*/
2718 case FPDU_MODE:
2719 if (ep->com.cm_id && ep->com.qp) {
2720 attrs.next_state = C4IW_QP_STATE_ERROR;
2721 ret = c4iw_modify_qp(ep->com.qp->rhp,
2722 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2723 &attrs, 1);
2724 if (ret)
2725 printk(KERN_ERR MOD
2726 "%s - qp <- error failed!\n",
2727 __func__);
2728 }
2729 peer_abort_upcall(ep);
2730 break;
2731 case ABORTING:
2732 break;
2733 case DEAD:
2734 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
2735 mutex_unlock(&ep->com.mutex);
2736 return 0;
2737 default:
2738 BUG_ON(1);
2739 break;
2740 }
2741 dst_confirm(ep->dst);
2742 if (ep->com.state != ABORTING) {
2743 __state_set(&ep->com, DEAD);
2744 /* we don't release if we want to retry with mpa_v1 */
2745 if (!ep->retry_with_mpa_v1)
2746 release = 1;
2747 }
2748 mutex_unlock(&ep->com.mutex);
2749
2750 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2751 if (!rpl_skb) {
2752 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2753 __func__);
2754 release = 1;
2755 goto out;
2756 }
2757 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2758 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2759 INIT_TP_WR(rpl, ep->hwtid);
2760 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2761 rpl->cmd = CPL_ABORT_NO_RST;
2762 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2763 out:
2764 if (release)
2765 release_ep_resources(ep);
2766 else if (ep->retry_with_mpa_v1) {
2767 if (ep->com.remote_addr.ss_family == AF_INET6) {
2768 struct sockaddr_in6 *sin6 =
2769 (struct sockaddr_in6 *)
2770 &ep->com.mapped_local_addr;
2771 cxgb4_clip_release(
2772 ep->com.dev->rdev.lldi.ports[0],
2773 (const u32 *)&sin6->sin6_addr.s6_addr,
2774 1);
2775 }
2776 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
2777 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2778 dst_release(ep->dst);
2779 cxgb4_l2t_release(ep->l2t);
2780 c4iw_reconnect(ep);
2781 }
2782
2783 return 0;
2784 }
2785
close_con_rpl(struct c4iw_dev * dev,struct sk_buff * skb)2786 static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2787 {
2788 struct c4iw_ep *ep;
2789 struct c4iw_qp_attributes attrs;
2790 struct cpl_close_con_rpl *rpl = cplhdr(skb);
2791 int release = 0;
2792 struct tid_info *t = dev->rdev.lldi.tids;
2793 unsigned int tid = GET_TID(rpl);
2794
2795 ep = lookup_tid(t, tid);
2796
2797 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2798 BUG_ON(!ep);
2799
2800 /* The cm_id may be null if we failed to connect */
2801 mutex_lock(&ep->com.mutex);
2802 switch (ep->com.state) {
2803 case CLOSING:
2804 __state_set(&ep->com, MORIBUND);
2805 break;
2806 case MORIBUND:
2807 (void)stop_ep_timer(ep);
2808 if ((ep->com.cm_id) && (ep->com.qp)) {
2809 attrs.next_state = C4IW_QP_STATE_IDLE;
2810 c4iw_modify_qp(ep->com.qp->rhp,
2811 ep->com.qp,
2812 C4IW_QP_ATTR_NEXT_STATE,
2813 &attrs, 1);
2814 }
2815 close_complete_upcall(ep, 0);
2816 __state_set(&ep->com, DEAD);
2817 release = 1;
2818 break;
2819 case ABORTING:
2820 case DEAD:
2821 break;
2822 default:
2823 BUG_ON(1);
2824 break;
2825 }
2826 mutex_unlock(&ep->com.mutex);
2827 if (release)
2828 release_ep_resources(ep);
2829 return 0;
2830 }
2831
terminate(struct c4iw_dev * dev,struct sk_buff * skb)2832 static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2833 {
2834 struct cpl_rdma_terminate *rpl = cplhdr(skb);
2835 struct tid_info *t = dev->rdev.lldi.tids;
2836 unsigned int tid = GET_TID(rpl);
2837 struct c4iw_ep *ep;
2838 struct c4iw_qp_attributes attrs;
2839
2840 ep = lookup_tid(t, tid);
2841 BUG_ON(!ep);
2842
2843 if (ep && ep->com.qp) {
2844 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2845 ep->com.qp->wq.sq.qid);
2846 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2847 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2848 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2849 } else
2850 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
2851
2852 return 0;
2853 }
2854
2855 /*
2856 * Upcall from the adapter indicating data has been transmitted.
2857 * For us its just the single MPA request or reply. We can now free
2858 * the skb holding the mpa message.
2859 */
fw4_ack(struct c4iw_dev * dev,struct sk_buff * skb)2860 static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2861 {
2862 struct c4iw_ep *ep;
2863 struct cpl_fw4_ack *hdr = cplhdr(skb);
2864 u8 credits = hdr->credits;
2865 unsigned int tid = GET_TID(hdr);
2866 struct tid_info *t = dev->rdev.lldi.tids;
2867
2868
2869 ep = lookup_tid(t, tid);
2870 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2871 if (credits == 0) {
2872 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2873 __func__, ep, ep->hwtid, state_read(&ep->com));
2874 return 0;
2875 }
2876
2877 dst_confirm(ep->dst);
2878 if (ep->mpa_skb) {
2879 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2880 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2881 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2882 kfree_skb(ep->mpa_skb);
2883 ep->mpa_skb = NULL;
2884 }
2885 return 0;
2886 }
2887
c4iw_reject_cr(struct iw_cm_id * cm_id,const void * pdata,u8 pdata_len)2888 int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2889 {
2890 int err = 0;
2891 int disconnect = 0;
2892 struct c4iw_ep *ep = to_ep(cm_id);
2893 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2894
2895 mutex_lock(&ep->com.mutex);
2896 if (ep->com.state == DEAD) {
2897 mutex_unlock(&ep->com.mutex);
2898 c4iw_put_ep(&ep->com);
2899 return -ECONNRESET;
2900 }
2901 set_bit(ULP_REJECT, &ep->com.history);
2902 BUG_ON(ep->com.state != MPA_REQ_RCVD);
2903 if (mpa_rev == 0)
2904 abort_connection(ep, NULL, GFP_KERNEL);
2905 else {
2906 err = send_mpa_reject(ep, pdata, pdata_len);
2907 disconnect = 1;
2908 }
2909 mutex_unlock(&ep->com.mutex);
2910 if (disconnect)
2911 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2912 c4iw_put_ep(&ep->com);
2913 return 0;
2914 }
2915
c4iw_accept_cr(struct iw_cm_id * cm_id,struct iw_cm_conn_param * conn_param)2916 int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2917 {
2918 int err;
2919 struct c4iw_qp_attributes attrs;
2920 enum c4iw_qp_attr_mask mask;
2921 struct c4iw_ep *ep = to_ep(cm_id);
2922 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2923 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2924
2925 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2926
2927 mutex_lock(&ep->com.mutex);
2928 if (ep->com.state == DEAD) {
2929 err = -ECONNRESET;
2930 goto err;
2931 }
2932
2933 BUG_ON(ep->com.state != MPA_REQ_RCVD);
2934 BUG_ON(!qp);
2935
2936 set_bit(ULP_ACCEPT, &ep->com.history);
2937 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2938 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
2939 abort_connection(ep, NULL, GFP_KERNEL);
2940 err = -EINVAL;
2941 goto err;
2942 }
2943
2944 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2945 if (conn_param->ord > ep->ird) {
2946 if (RELAXED_IRD_NEGOTIATION) {
2947 ep->ord = ep->ird;
2948 } else {
2949 ep->ird = conn_param->ird;
2950 ep->ord = conn_param->ord;
2951 send_mpa_reject(ep, conn_param->private_data,
2952 conn_param->private_data_len);
2953 abort_connection(ep, NULL, GFP_KERNEL);
2954 err = -ENOMEM;
2955 goto err;
2956 }
2957 }
2958 if (conn_param->ird < ep->ord) {
2959 if (RELAXED_IRD_NEGOTIATION &&
2960 ep->ord <= h->rdev.lldi.max_ordird_qp) {
2961 conn_param->ird = ep->ord;
2962 } else {
2963 abort_connection(ep, NULL, GFP_KERNEL);
2964 err = -ENOMEM;
2965 goto err;
2966 }
2967 }
2968 }
2969 ep->ird = conn_param->ird;
2970 ep->ord = conn_param->ord;
2971
2972 if (ep->mpa_attr.version == 1) {
2973 if (peer2peer && ep->ird == 0)
2974 ep->ird = 1;
2975 } else {
2976 if (peer2peer &&
2977 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
2978 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
2979 ep->ird = 1;
2980 }
2981
2982 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2983
2984 cm_id->add_ref(cm_id);
2985 ep->com.cm_id = cm_id;
2986 ep->com.qp = qp;
2987 ref_qp(ep);
2988
2989 /* bind QP to EP and move to RTS */
2990 attrs.mpa_attr = ep->mpa_attr;
2991 attrs.max_ird = ep->ird;
2992 attrs.max_ord = ep->ord;
2993 attrs.llp_stream_handle = ep;
2994 attrs.next_state = C4IW_QP_STATE_RTS;
2995
2996 /* bind QP and TID with INIT_WR */
2997 mask = C4IW_QP_ATTR_NEXT_STATE |
2998 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2999 C4IW_QP_ATTR_MPA_ATTR |
3000 C4IW_QP_ATTR_MAX_IRD |
3001 C4IW_QP_ATTR_MAX_ORD;
3002
3003 err = c4iw_modify_qp(ep->com.qp->rhp,
3004 ep->com.qp, mask, &attrs, 1);
3005 if (err)
3006 goto err1;
3007 err = send_mpa_reply(ep, conn_param->private_data,
3008 conn_param->private_data_len);
3009 if (err)
3010 goto err1;
3011
3012 __state_set(&ep->com, FPDU_MODE);
3013 established_upcall(ep);
3014 mutex_unlock(&ep->com.mutex);
3015 c4iw_put_ep(&ep->com);
3016 return 0;
3017 err1:
3018 ep->com.cm_id = NULL;
3019 abort_connection(ep, NULL, GFP_KERNEL);
3020 cm_id->rem_ref(cm_id);
3021 err:
3022 mutex_unlock(&ep->com.mutex);
3023 c4iw_put_ep(&ep->com);
3024 return err;
3025 }
3026
pick_local_ipaddrs(struct c4iw_dev * dev,struct iw_cm_id * cm_id)3027 static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3028 {
3029 struct in_device *ind;
3030 int found = 0;
3031 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
3032 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
3033
3034 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3035 if (!ind)
3036 return -EADDRNOTAVAIL;
3037 for_primary_ifa(ind) {
3038 laddr->sin_addr.s_addr = ifa->ifa_address;
3039 raddr->sin_addr.s_addr = ifa->ifa_address;
3040 found = 1;
3041 break;
3042 }
3043 endfor_ifa(ind);
3044 in_dev_put(ind);
3045 return found ? 0 : -EADDRNOTAVAIL;
3046 }
3047
get_lladdr(struct net_device * dev,struct in6_addr * addr,unsigned char banned_flags)3048 static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3049 unsigned char banned_flags)
3050 {
3051 struct inet6_dev *idev;
3052 int err = -EADDRNOTAVAIL;
3053
3054 rcu_read_lock();
3055 idev = __in6_dev_get(dev);
3056 if (idev != NULL) {
3057 struct inet6_ifaddr *ifp;
3058
3059 read_lock_bh(&idev->lock);
3060 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3061 if (ifp->scope == IFA_LINK &&
3062 !(ifp->flags & banned_flags)) {
3063 memcpy(addr, &ifp->addr, 16);
3064 err = 0;
3065 break;
3066 }
3067 }
3068 read_unlock_bh(&idev->lock);
3069 }
3070 rcu_read_unlock();
3071 return err;
3072 }
3073
pick_local_ip6addrs(struct c4iw_dev * dev,struct iw_cm_id * cm_id)3074 static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3075 {
3076 struct in6_addr uninitialized_var(addr);
3077 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
3078 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
3079
3080 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
3081 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3082 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3083 return 0;
3084 }
3085 return -EADDRNOTAVAIL;
3086 }
3087
c4iw_connect(struct iw_cm_id * cm_id,struct iw_cm_conn_param * conn_param)3088 int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3089 {
3090 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3091 struct c4iw_ep *ep;
3092 int err = 0;
3093 struct sockaddr_in *laddr;
3094 struct sockaddr_in *raddr;
3095 struct sockaddr_in6 *laddr6;
3096 struct sockaddr_in6 *raddr6;
3097 struct iwpm_dev_data pm_reg_msg;
3098 struct iwpm_sa_data pm_msg;
3099 __u8 *ra;
3100 int iptype;
3101 int iwpm_err = 0;
3102
3103 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3104 (conn_param->ird > cur_max_read_depth(dev))) {
3105 err = -EINVAL;
3106 goto out;
3107 }
3108 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3109 if (!ep) {
3110 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3111 err = -ENOMEM;
3112 goto out;
3113 }
3114 init_timer(&ep->timer);
3115 ep->plen = conn_param->private_data_len;
3116 if (ep->plen)
3117 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3118 conn_param->private_data, ep->plen);
3119 ep->ird = conn_param->ird;
3120 ep->ord = conn_param->ord;
3121
3122 if (peer2peer && ep->ord == 0)
3123 ep->ord = 1;
3124
3125 cm_id->add_ref(cm_id);
3126 ep->com.dev = dev;
3127 ep->com.cm_id = cm_id;
3128 ep->com.qp = get_qhp(dev, conn_param->qpn);
3129 if (!ep->com.qp) {
3130 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3131 err = -EINVAL;
3132 goto fail1;
3133 }
3134 ref_qp(ep);
3135 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3136 ep->com.qp, cm_id);
3137
3138 /*
3139 * Allocate an active TID to initiate a TCP connection.
3140 */
3141 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3142 if (ep->atid == -1) {
3143 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3144 err = -ENOMEM;
3145 goto fail1;
3146 }
3147 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
3148
3149 memcpy(&ep->com.local_addr, &cm_id->local_addr,
3150 sizeof(ep->com.local_addr));
3151 memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
3152 sizeof(ep->com.remote_addr));
3153
3154 /* No port mapper available, go with the specified peer information */
3155 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3156 sizeof(ep->com.mapped_local_addr));
3157 memcpy(&ep->com.mapped_remote_addr, &cm_id->remote_addr,
3158 sizeof(ep->com.mapped_remote_addr));
3159
3160 c4iw_form_reg_msg(dev, &pm_reg_msg);
3161 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3162 if (iwpm_err) {
3163 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3164 __func__, iwpm_err);
3165 }
3166 if (iwpm_valid_pid() && !iwpm_err) {
3167 c4iw_form_pm_msg(ep, &pm_msg);
3168 iwpm_err = iwpm_add_and_query_mapping(&pm_msg, RDMA_NL_C4IW);
3169 if (iwpm_err)
3170 PDBG("%s: Port Mapper query fail (err = %d).\n",
3171 __func__, iwpm_err);
3172 else
3173 c4iw_record_pm_msg(ep, &pm_msg);
3174 }
3175 if (iwpm_create_mapinfo(&ep->com.local_addr,
3176 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3177 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
3178 err = -ENOMEM;
3179 goto fail1;
3180 }
3181 print_addr(&ep->com, __func__, "add_query/create_mapinfo");
3182 set_bit(RELEASE_MAPINFO, &ep->com.flags);
3183
3184 laddr = (struct sockaddr_in *)&ep->com.mapped_local_addr;
3185 raddr = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
3186 laddr6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
3187 raddr6 = (struct sockaddr_in6 *) &ep->com.mapped_remote_addr;
3188
3189 if (cm_id->remote_addr.ss_family == AF_INET) {
3190 iptype = 4;
3191 ra = (__u8 *)&raddr->sin_addr;
3192
3193 /*
3194 * Handle loopback requests to INADDR_ANY.
3195 */
3196 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3197 err = pick_local_ipaddrs(dev, cm_id);
3198 if (err)
3199 goto fail1;
3200 }
3201
3202 /* find a route */
3203 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3204 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3205 ra, ntohs(raddr->sin_port));
3206 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3207 raddr->sin_addr.s_addr, laddr->sin_port,
3208 raddr->sin_port, 0);
3209 } else {
3210 iptype = 6;
3211 ra = (__u8 *)&raddr6->sin6_addr;
3212
3213 /*
3214 * Handle loopback requests to INADDR_ANY.
3215 */
3216 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3217 err = pick_local_ip6addrs(dev, cm_id);
3218 if (err)
3219 goto fail1;
3220 }
3221
3222 /* find a route */
3223 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3224 __func__, laddr6->sin6_addr.s6_addr,
3225 ntohs(laddr6->sin6_port),
3226 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3227 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3228 raddr6->sin6_addr.s6_addr,
3229 laddr6->sin6_port, raddr6->sin6_port, 0,
3230 raddr6->sin6_scope_id);
3231 }
3232 if (!ep->dst) {
3233 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3234 err = -EHOSTUNREACH;
3235 goto fail2;
3236 }
3237
3238 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
3239 ep->com.dev->rdev.lldi.adapter_type);
3240 if (err) {
3241 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
3242 goto fail3;
3243 }
3244
3245 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3246 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3247 ep->l2t->idx);
3248
3249 state_set(&ep->com, CONNECTING);
3250 ep->tos = 0;
3251
3252 /* send connect request to rnic */
3253 err = send_connect(ep);
3254 if (!err)
3255 goto out;
3256
3257 cxgb4_l2t_release(ep->l2t);
3258 fail3:
3259 dst_release(ep->dst);
3260 fail2:
3261 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
3262 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
3263 fail1:
3264 cm_id->rem_ref(cm_id);
3265 c4iw_put_ep(&ep->com);
3266 out:
3267 return err;
3268 }
3269
create_server6(struct c4iw_dev * dev,struct c4iw_listen_ep * ep)3270 static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3271 {
3272 int err;
3273 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
3274 &ep->com.mapped_local_addr;
3275
3276 c4iw_init_wr_wait(&ep->com.wr_wait);
3277 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3278 ep->stid, &sin6->sin6_addr,
3279 sin6->sin6_port,
3280 ep->com.dev->rdev.lldi.rxq_ids[0]);
3281 if (!err)
3282 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3283 &ep->com.wr_wait,
3284 0, 0, __func__);
3285 else if (err > 0)
3286 err = net_xmit_errno(err);
3287 if (err)
3288 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3289 err, ep->stid,
3290 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
3291 else
3292 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3293 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3294 return err;
3295 }
3296
create_server4(struct c4iw_dev * dev,struct c4iw_listen_ep * ep)3297 static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3298 {
3299 int err;
3300 struct sockaddr_in *sin = (struct sockaddr_in *)
3301 &ep->com.mapped_local_addr;
3302
3303 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3304 do {
3305 err = cxgb4_create_server_filter(
3306 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3307 sin->sin_addr.s_addr, sin->sin_port, 0,
3308 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3309 if (err == -EBUSY) {
3310 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3311 err = -EIO;
3312 break;
3313 }
3314 set_current_state(TASK_UNINTERRUPTIBLE);
3315 schedule_timeout(usecs_to_jiffies(100));
3316 }
3317 } while (err == -EBUSY);
3318 } else {
3319 c4iw_init_wr_wait(&ep->com.wr_wait);
3320 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3321 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3322 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3323 if (!err)
3324 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3325 &ep->com.wr_wait,
3326 0, 0, __func__);
3327 else if (err > 0)
3328 err = net_xmit_errno(err);
3329 }
3330 if (err)
3331 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3332 , err, ep->stid,
3333 &sin->sin_addr, ntohs(sin->sin_port));
3334 return err;
3335 }
3336
c4iw_create_listen(struct iw_cm_id * cm_id,int backlog)3337 int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3338 {
3339 int err = 0;
3340 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3341 struct c4iw_listen_ep *ep;
3342 struct iwpm_dev_data pm_reg_msg;
3343 struct iwpm_sa_data pm_msg;
3344 int iwpm_err = 0;
3345
3346 might_sleep();
3347
3348 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3349 if (!ep) {
3350 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3351 err = -ENOMEM;
3352 goto fail1;
3353 }
3354 PDBG("%s ep %p\n", __func__, ep);
3355 cm_id->add_ref(cm_id);
3356 ep->com.cm_id = cm_id;
3357 ep->com.dev = dev;
3358 ep->backlog = backlog;
3359 memcpy(&ep->com.local_addr, &cm_id->local_addr,
3360 sizeof(ep->com.local_addr));
3361
3362 /*
3363 * Allocate a server TID.
3364 */
3365 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3366 ep->com.local_addr.ss_family == AF_INET)
3367 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
3368 cm_id->local_addr.ss_family, ep);
3369 else
3370 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
3371 cm_id->local_addr.ss_family, ep);
3372
3373 if (ep->stid == -1) {
3374 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
3375 err = -ENOMEM;
3376 goto fail2;
3377 }
3378 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
3379
3380 /* No port mapper available, go with the specified info */
3381 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3382 sizeof(ep->com.mapped_local_addr));
3383
3384 c4iw_form_reg_msg(dev, &pm_reg_msg);
3385 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3386 if (iwpm_err) {
3387 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3388 __func__, iwpm_err);
3389 }
3390 if (iwpm_valid_pid() && !iwpm_err) {
3391 memcpy(&pm_msg.loc_addr, &ep->com.local_addr,
3392 sizeof(ep->com.local_addr));
3393 iwpm_err = iwpm_add_mapping(&pm_msg, RDMA_NL_C4IW);
3394 if (iwpm_err)
3395 PDBG("%s: Port Mapper query fail (err = %d).\n",
3396 __func__, iwpm_err);
3397 else
3398 memcpy(&ep->com.mapped_local_addr,
3399 &pm_msg.mapped_loc_addr,
3400 sizeof(ep->com.mapped_local_addr));
3401 }
3402 if (iwpm_create_mapinfo(&ep->com.local_addr,
3403 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3404 err = -ENOMEM;
3405 goto fail3;
3406 }
3407 print_addr(&ep->com, __func__, "add_mapping/create_mapinfo");
3408
3409 set_bit(RELEASE_MAPINFO, &ep->com.flags);
3410 state_set(&ep->com, LISTEN);
3411 if (ep->com.local_addr.ss_family == AF_INET)
3412 err = create_server4(dev, ep);
3413 else
3414 err = create_server6(dev, ep);
3415 if (!err) {
3416 cm_id->provider_data = ep;
3417 goto out;
3418 }
3419
3420 fail3:
3421 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3422 ep->com.local_addr.ss_family);
3423 fail2:
3424 cm_id->rem_ref(cm_id);
3425 c4iw_put_ep(&ep->com);
3426 fail1:
3427 out:
3428 return err;
3429 }
3430
c4iw_destroy_listen(struct iw_cm_id * cm_id)3431 int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3432 {
3433 int err;
3434 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3435
3436 PDBG("%s ep %p\n", __func__, ep);
3437
3438 might_sleep();
3439 state_set(&ep->com, DEAD);
3440 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3441 ep->com.local_addr.ss_family == AF_INET) {
3442 err = cxgb4_remove_server_filter(
3443 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3444 ep->com.dev->rdev.lldi.rxq_ids[0], false);
3445 } else {
3446 struct sockaddr_in6 *sin6;
3447 c4iw_init_wr_wait(&ep->com.wr_wait);
3448 err = cxgb4_remove_server(
3449 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3450 ep->com.dev->rdev.lldi.rxq_ids[0],
3451 ep->com.local_addr.ss_family == AF_INET6);
3452 if (err)
3453 goto done;
3454 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3455 0, 0, __func__);
3456 sin6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
3457 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3458 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3459 }
3460 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
3461 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3462 ep->com.local_addr.ss_family);
3463 done:
3464 cm_id->rem_ref(cm_id);
3465 c4iw_put_ep(&ep->com);
3466 return err;
3467 }
3468
c4iw_ep_disconnect(struct c4iw_ep * ep,int abrupt,gfp_t gfp)3469 int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3470 {
3471 int ret = 0;
3472 int close = 0;
3473 int fatal = 0;
3474 struct c4iw_rdev *rdev;
3475
3476 mutex_lock(&ep->com.mutex);
3477
3478 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3479 states[ep->com.state], abrupt);
3480
3481 rdev = &ep->com.dev->rdev;
3482 if (c4iw_fatal_error(rdev)) {
3483 fatal = 1;
3484 close_complete_upcall(ep, -EIO);
3485 ep->com.state = DEAD;
3486 }
3487 switch (ep->com.state) {
3488 case MPA_REQ_WAIT:
3489 case MPA_REQ_SENT:
3490 case MPA_REQ_RCVD:
3491 case MPA_REP_SENT:
3492 case FPDU_MODE:
3493 close = 1;
3494 if (abrupt)
3495 ep->com.state = ABORTING;
3496 else {
3497 ep->com.state = CLOSING;
3498 start_ep_timer(ep);
3499 }
3500 set_bit(CLOSE_SENT, &ep->com.flags);
3501 break;
3502 case CLOSING:
3503 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3504 close = 1;
3505 if (abrupt) {
3506 (void)stop_ep_timer(ep);
3507 ep->com.state = ABORTING;
3508 } else
3509 ep->com.state = MORIBUND;
3510 }
3511 break;
3512 case MORIBUND:
3513 case ABORTING:
3514 case DEAD:
3515 PDBG("%s ignoring disconnect ep %p state %u\n",
3516 __func__, ep, ep->com.state);
3517 break;
3518 default:
3519 BUG();
3520 break;
3521 }
3522
3523 if (close) {
3524 if (abrupt) {
3525 set_bit(EP_DISC_ABORT, &ep->com.history);
3526 close_complete_upcall(ep, -ECONNRESET);
3527 ret = send_abort(ep, NULL, gfp);
3528 } else {
3529 set_bit(EP_DISC_CLOSE, &ep->com.history);
3530 ret = send_halfclose(ep, gfp);
3531 }
3532 if (ret)
3533 fatal = 1;
3534 }
3535 mutex_unlock(&ep->com.mutex);
3536 if (fatal)
3537 release_ep_resources(ep);
3538 return ret;
3539 }
3540
active_ofld_conn_reply(struct c4iw_dev * dev,struct sk_buff * skb,struct cpl_fw6_msg_ofld_connection_wr_rpl * req)3541 static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3542 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3543 {
3544 struct c4iw_ep *ep;
3545 int atid = be32_to_cpu(req->tid);
3546
3547 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3548 (__force u32) req->tid);
3549 if (!ep)
3550 return;
3551
3552 switch (req->retval) {
3553 case FW_ENOMEM:
3554 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3555 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3556 send_fw_act_open_req(ep, atid);
3557 return;
3558 }
3559 case FW_EADDRINUSE:
3560 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3561 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3562 send_fw_act_open_req(ep, atid);
3563 return;
3564 }
3565 break;
3566 default:
3567 pr_info("%s unexpected ofld conn wr retval %d\n",
3568 __func__, req->retval);
3569 break;
3570 }
3571 pr_err("active ofld_connect_wr failure %d atid %d\n",
3572 req->retval, atid);
3573 mutex_lock(&dev->rdev.stats.lock);
3574 dev->rdev.stats.act_ofld_conn_fails++;
3575 mutex_unlock(&dev->rdev.stats.lock);
3576 connect_reply_upcall(ep, status2errno(req->retval));
3577 state_set(&ep->com, DEAD);
3578 if (ep->com.remote_addr.ss_family == AF_INET6) {
3579 struct sockaddr_in6 *sin6 =
3580 (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
3581 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3582 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3583 }
3584 remove_handle(dev, &dev->atid_idr, atid);
3585 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3586 dst_release(ep->dst);
3587 cxgb4_l2t_release(ep->l2t);
3588 c4iw_put_ep(&ep->com);
3589 }
3590
passive_ofld_conn_reply(struct c4iw_dev * dev,struct sk_buff * skb,struct cpl_fw6_msg_ofld_connection_wr_rpl * req)3591 static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3592 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3593 {
3594 struct sk_buff *rpl_skb;
3595 struct cpl_pass_accept_req *cpl;
3596 int ret;
3597
3598 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
3599 BUG_ON(!rpl_skb);
3600 if (req->retval) {
3601 PDBG("%s passive open failure %d\n", __func__, req->retval);
3602 mutex_lock(&dev->rdev.stats.lock);
3603 dev->rdev.stats.pas_ofld_conn_fails++;
3604 mutex_unlock(&dev->rdev.stats.lock);
3605 kfree_skb(rpl_skb);
3606 } else {
3607 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3608 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
3609 (__force u32) htonl(
3610 (__force u32) req->tid)));
3611 ret = pass_accept_req(dev, rpl_skb);
3612 if (!ret)
3613 kfree_skb(rpl_skb);
3614 }
3615 return;
3616 }
3617
deferred_fw6_msg(struct c4iw_dev * dev,struct sk_buff * skb)3618 static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3619 {
3620 struct cpl_fw6_msg *rpl = cplhdr(skb);
3621 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3622
3623 switch (rpl->type) {
3624 case FW6_TYPE_CQE:
3625 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3626 break;
3627 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3628 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3629 switch (req->t_state) {
3630 case TCP_SYN_SENT:
3631 active_ofld_conn_reply(dev, skb, req);
3632 break;
3633 case TCP_SYN_RECV:
3634 passive_ofld_conn_reply(dev, skb, req);
3635 break;
3636 default:
3637 pr_err("%s unexpected ofld conn wr state %d\n",
3638 __func__, req->t_state);
3639 break;
3640 }
3641 break;
3642 }
3643 return 0;
3644 }
3645
build_cpl_pass_accept_req(struct sk_buff * skb,int stid,u8 tos)3646 static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3647 {
3648 __be32 l2info;
3649 __be16 hdr_len, vlantag, len;
3650 u16 eth_hdr_len;
3651 int tcp_hdr_len, ip_hdr_len;
3652 u8 intf;
3653 struct cpl_rx_pkt *cpl = cplhdr(skb);
3654 struct cpl_pass_accept_req *req;
3655 struct tcp_options_received tmp_opt;
3656 struct c4iw_dev *dev;
3657 enum chip_type type;
3658
3659 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3660 /* Store values from cpl_rx_pkt in temporary location. */
3661 vlantag = cpl->vlan;
3662 len = cpl->len;
3663 l2info = cpl->l2info;
3664 hdr_len = cpl->hdr_len;
3665 intf = cpl->iff;
3666
3667 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3668
3669 /*
3670 * We need to parse the TCP options from SYN packet.
3671 * to generate cpl_pass_accept_req.
3672 */
3673 memset(&tmp_opt, 0, sizeof(tmp_opt));
3674 tcp_clear_options(&tmp_opt);
3675 tcp_parse_options(skb, &tmp_opt, 0, NULL);
3676
3677 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3678 memset(req, 0, sizeof(*req));
3679 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3680 SYN_MAC_IDX_V(RX_MACIDX_G(
3681 be32_to_cpu(l2info))) |
3682 SYN_XACT_MATCH_F);
3683 type = dev->rdev.lldi.adapter_type;
3684 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3685 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3686 req->hdr_len =
3687 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3688 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3689 eth_hdr_len = is_t4(type) ?
3690 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3691 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3692 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3693 IP_HDR_LEN_V(ip_hdr_len) |
3694 ETH_HDR_LEN_V(eth_hdr_len));
3695 } else { /* T6 and later */
3696 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3697 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3698 T6_IP_HDR_LEN_V(ip_hdr_len) |
3699 T6_ETH_HDR_LEN_V(eth_hdr_len));
3700 }
3701 req->vlan = vlantag;
3702 req->len = len;
3703 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3704 PASS_OPEN_TOS_V(tos));
3705 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3706 if (tmp_opt.wscale_ok)
3707 req->tcpopt.wsf = tmp_opt.snd_wscale;
3708 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3709 if (tmp_opt.sack_ok)
3710 req->tcpopt.sack = 1;
3711 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3712 return;
3713 }
3714
send_fw_pass_open_req(struct c4iw_dev * dev,struct sk_buff * skb,__be32 laddr,__be16 lport,__be32 raddr,__be16 rport,u32 rcv_isn,u32 filter,u16 window,u32 rss_qid,u8 port_id)3715 static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3716 __be32 laddr, __be16 lport,
3717 __be32 raddr, __be16 rport,
3718 u32 rcv_isn, u32 filter, u16 window,
3719 u32 rss_qid, u8 port_id)
3720 {
3721 struct sk_buff *req_skb;
3722 struct fw_ofld_connection_wr *req;
3723 struct cpl_pass_accept_req *cpl = cplhdr(skb);
3724 int ret;
3725
3726 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3727 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3728 memset(req, 0, sizeof(*req));
3729 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
3730 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
3731 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
3732 req->le.filter = (__force __be32) filter;
3733 req->le.lport = lport;
3734 req->le.pport = rport;
3735 req->le.u.ipv4.lip = laddr;
3736 req->le.u.ipv4.pip = raddr;
3737 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3738 req->tcb.rcv_adv = htons(window);
3739 req->tcb.t_state_to_astid =
3740 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3741 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3742 FW_OFLD_CONNECTION_WR_ASTID_V(
3743 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
3744
3745 /*
3746 * We store the qid in opt2 which will be used by the firmware
3747 * to send us the wr response.
3748 */
3749 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
3750
3751 /*
3752 * We initialize the MSS index in TCB to 0xF.
3753 * So that when driver sends cpl_pass_accept_rpl
3754 * TCB picks up the correct value. If this was 0
3755 * TP will ignore any value > 0 for MSS index.
3756 */
3757 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
3758 req->cookie = (uintptr_t)skb;
3759
3760 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
3761 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3762 if (ret < 0) {
3763 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3764 ret);
3765 kfree_skb(skb);
3766 kfree_skb(req_skb);
3767 }
3768 }
3769
3770 /*
3771 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3772 * messages when a filter is being used instead of server to
3773 * redirect a syn packet. When packets hit filter they are redirected
3774 * to the offload queue and driver tries to establish the connection
3775 * using firmware work request.
3776 */
rx_pkt(struct c4iw_dev * dev,struct sk_buff * skb)3777 static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3778 {
3779 int stid;
3780 unsigned int filter;
3781 struct ethhdr *eh = NULL;
3782 struct vlan_ethhdr *vlan_eh = NULL;
3783 struct iphdr *iph;
3784 struct tcphdr *tcph;
3785 struct rss_header *rss = (void *)skb->data;
3786 struct cpl_rx_pkt *cpl = (void *)skb->data;
3787 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3788 struct l2t_entry *e;
3789 struct dst_entry *dst;
3790 struct c4iw_ep *lep;
3791 u16 window;
3792 struct port_info *pi;
3793 struct net_device *pdev;
3794 u16 rss_qid, eth_hdr_len;
3795 int step;
3796 u32 tx_chan;
3797 struct neighbour *neigh;
3798
3799 /* Drop all non-SYN packets */
3800 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
3801 goto reject;
3802
3803 /*
3804 * Drop all packets which did not hit the filter.
3805 * Unlikely to happen.
3806 */
3807 if (!(rss->filter_hit && rss->filter_tid))
3808 goto reject;
3809
3810 /*
3811 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3812 */
3813 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
3814
3815 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3816 if (!lep) {
3817 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3818 goto reject;
3819 }
3820
3821 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3822 case CHELSIO_T4:
3823 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3824 break;
3825 case CHELSIO_T5:
3826 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3827 break;
3828 case CHELSIO_T6:
3829 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3830 break;
3831 default:
3832 pr_err("T%d Chip is not supported\n",
3833 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3834 goto reject;
3835 }
3836
3837 if (eth_hdr_len == ETH_HLEN) {
3838 eh = (struct ethhdr *)(req + 1);
3839 iph = (struct iphdr *)(eh + 1);
3840 } else {
3841 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3842 iph = (struct iphdr *)(vlan_eh + 1);
3843 skb->vlan_tci = ntohs(cpl->vlan);
3844 }
3845
3846 if (iph->version != 0x4)
3847 goto reject;
3848
3849 tcph = (struct tcphdr *)(iph + 1);
3850 skb_set_network_header(skb, (void *)iph - (void *)rss);
3851 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3852 skb_get(skb);
3853
3854 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3855 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3856 ntohs(tcph->source), iph->tos);
3857
3858 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3859 iph->tos);
3860 if (!dst) {
3861 pr_err("%s - failed to find dst entry!\n",
3862 __func__);
3863 goto reject;
3864 }
3865 neigh = dst_neigh_lookup_skb(dst, skb);
3866
3867 if (!neigh) {
3868 pr_err("%s - failed to allocate neigh!\n",
3869 __func__);
3870 goto free_dst;
3871 }
3872
3873 if (neigh->dev->flags & IFF_LOOPBACK) {
3874 pdev = ip_dev_find(&init_net, iph->daddr);
3875 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3876 pdev, 0);
3877 pi = (struct port_info *)netdev_priv(pdev);
3878 tx_chan = cxgb4_port_chan(pdev);
3879 dev_put(pdev);
3880 } else {
3881 pdev = get_real_dev(neigh->dev);
3882 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3883 pdev, 0);
3884 pi = (struct port_info *)netdev_priv(pdev);
3885 tx_chan = cxgb4_port_chan(pdev);
3886 }
3887 neigh_release(neigh);
3888 if (!e) {
3889 pr_err("%s - failed to allocate l2t entry!\n",
3890 __func__);
3891 goto free_dst;
3892 }
3893
3894 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3895 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
3896 window = (__force u16) htons((__force u16)tcph->window);
3897
3898 /* Calcuate filter portion for LE region. */
3899 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3900 dev->rdev.lldi.ports[0],
3901 e));
3902
3903 /*
3904 * Synthesize the cpl_pass_accept_req. We have everything except the
3905 * TID. Once firmware sends a reply with TID we update the TID field
3906 * in cpl and pass it through the regular cpl_pass_accept_req path.
3907 */
3908 build_cpl_pass_accept_req(skb, stid, iph->tos);
3909 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3910 tcph->source, ntohl(tcph->seq), filter, window,
3911 rss_qid, pi->port_id);
3912 cxgb4_l2t_release(e);
3913 free_dst:
3914 dst_release(dst);
3915 reject:
3916 return 0;
3917 }
3918
3919 /*
3920 * These are the real handlers that are called from a
3921 * work queue.
3922 */
3923 static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3924 [CPL_ACT_ESTABLISH] = act_establish,
3925 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3926 [CPL_RX_DATA] = rx_data,
3927 [CPL_ABORT_RPL_RSS] = abort_rpl,
3928 [CPL_ABORT_RPL] = abort_rpl,
3929 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3930 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3931 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3932 [CPL_PASS_ESTABLISH] = pass_establish,
3933 [CPL_PEER_CLOSE] = peer_close,
3934 [CPL_ABORT_REQ_RSS] = peer_abort,
3935 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3936 [CPL_RDMA_TERMINATE] = terminate,
3937 [CPL_FW4_ACK] = fw4_ack,
3938 [CPL_FW6_MSG] = deferred_fw6_msg,
3939 [CPL_RX_PKT] = rx_pkt
3940 };
3941
process_timeout(struct c4iw_ep * ep)3942 static void process_timeout(struct c4iw_ep *ep)
3943 {
3944 struct c4iw_qp_attributes attrs;
3945 int abort = 1;
3946
3947 mutex_lock(&ep->com.mutex);
3948 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3949 ep->com.state);
3950 set_bit(TIMEDOUT, &ep->com.history);
3951 switch (ep->com.state) {
3952 case MPA_REQ_SENT:
3953 __state_set(&ep->com, ABORTING);
3954 connect_reply_upcall(ep, -ETIMEDOUT);
3955 break;
3956 case MPA_REQ_WAIT:
3957 __state_set(&ep->com, ABORTING);
3958 break;
3959 case CLOSING:
3960 case MORIBUND:
3961 if (ep->com.cm_id && ep->com.qp) {
3962 attrs.next_state = C4IW_QP_STATE_ERROR;
3963 c4iw_modify_qp(ep->com.qp->rhp,
3964 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3965 &attrs, 1);
3966 }
3967 __state_set(&ep->com, ABORTING);
3968 close_complete_upcall(ep, -ETIMEDOUT);
3969 break;
3970 case ABORTING:
3971 case DEAD:
3972
3973 /*
3974 * These states are expected if the ep timed out at the same
3975 * time as another thread was calling stop_ep_timer().
3976 * So we silently do nothing for these states.
3977 */
3978 abort = 0;
3979 break;
3980 default:
3981 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
3982 __func__, ep, ep->hwtid, ep->com.state);
3983 abort = 0;
3984 }
3985 if (abort)
3986 abort_connection(ep, NULL, GFP_KERNEL);
3987 mutex_unlock(&ep->com.mutex);
3988 c4iw_put_ep(&ep->com);
3989 }
3990
process_timedout_eps(void)3991 static void process_timedout_eps(void)
3992 {
3993 struct c4iw_ep *ep;
3994
3995 spin_lock_irq(&timeout_lock);
3996 while (!list_empty(&timeout_list)) {
3997 struct list_head *tmp;
3998
3999 tmp = timeout_list.next;
4000 list_del(tmp);
4001 tmp->next = NULL;
4002 tmp->prev = NULL;
4003 spin_unlock_irq(&timeout_lock);
4004 ep = list_entry(tmp, struct c4iw_ep, entry);
4005 process_timeout(ep);
4006 spin_lock_irq(&timeout_lock);
4007 }
4008 spin_unlock_irq(&timeout_lock);
4009 }
4010
process_work(struct work_struct * work)4011 static void process_work(struct work_struct *work)
4012 {
4013 struct sk_buff *skb = NULL;
4014 struct c4iw_dev *dev;
4015 struct cpl_act_establish *rpl;
4016 unsigned int opcode;
4017 int ret;
4018
4019 process_timedout_eps();
4020 while ((skb = skb_dequeue(&rxq))) {
4021 rpl = cplhdr(skb);
4022 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4023 opcode = rpl->ot.opcode;
4024
4025 BUG_ON(!work_handlers[opcode]);
4026 ret = work_handlers[opcode](dev, skb);
4027 if (!ret)
4028 kfree_skb(skb);
4029 process_timedout_eps();
4030 }
4031 }
4032
4033 static DECLARE_WORK(skb_work, process_work);
4034
ep_timeout(unsigned long arg)4035 static void ep_timeout(unsigned long arg)
4036 {
4037 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
4038 int kickit = 0;
4039
4040 spin_lock(&timeout_lock);
4041 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
4042 /*
4043 * Only insert if it is not already on the list.
4044 */
4045 if (!ep->entry.next) {
4046 list_add_tail(&ep->entry, &timeout_list);
4047 kickit = 1;
4048 }
4049 }
4050 spin_unlock(&timeout_lock);
4051 if (kickit)
4052 queue_work(workq, &skb_work);
4053 }
4054
4055 /*
4056 * All the CM events are handled on a work queue to have a safe context.
4057 */
sched(struct c4iw_dev * dev,struct sk_buff * skb)4058 static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4059 {
4060
4061 /*
4062 * Save dev in the skb->cb area.
4063 */
4064 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4065
4066 /*
4067 * Queue the skb and schedule the worker thread.
4068 */
4069 skb_queue_tail(&rxq, skb);
4070 queue_work(workq, &skb_work);
4071 return 0;
4072 }
4073
set_tcb_rpl(struct c4iw_dev * dev,struct sk_buff * skb)4074 static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4075 {
4076 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4077
4078 if (rpl->status != CPL_ERR_NONE) {
4079 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4080 "for tid %u\n", rpl->status, GET_TID(rpl));
4081 }
4082 kfree_skb(skb);
4083 return 0;
4084 }
4085
fw6_msg(struct c4iw_dev * dev,struct sk_buff * skb)4086 static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4087 {
4088 struct cpl_fw6_msg *rpl = cplhdr(skb);
4089 struct c4iw_wr_wait *wr_waitp;
4090 int ret;
4091
4092 PDBG("%s type %u\n", __func__, rpl->type);
4093
4094 switch (rpl->type) {
4095 case FW6_TYPE_WR_RPL:
4096 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
4097 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
4098 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
4099 if (wr_waitp)
4100 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
4101 kfree_skb(skb);
4102 break;
4103 case FW6_TYPE_CQE:
4104 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
4105 sched(dev, skb);
4106 break;
4107 default:
4108 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4109 rpl->type);
4110 kfree_skb(skb);
4111 break;
4112 }
4113 return 0;
4114 }
4115
peer_abort_intr(struct c4iw_dev * dev,struct sk_buff * skb)4116 static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4117 {
4118 struct cpl_abort_req_rss *req = cplhdr(skb);
4119 struct c4iw_ep *ep;
4120 struct tid_info *t = dev->rdev.lldi.tids;
4121 unsigned int tid = GET_TID(req);
4122
4123 ep = lookup_tid(t, tid);
4124 if (!ep) {
4125 printk(KERN_WARNING MOD
4126 "Abort on non-existent endpoint, tid %d\n", tid);
4127 kfree_skb(skb);
4128 return 0;
4129 }
4130 if (is_neg_adv(req->status)) {
4131 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4132 __func__, ep->hwtid, req->status,
4133 neg_adv_str(req->status));
4134 ep->stats.abort_neg_adv++;
4135 dev->rdev.stats.neg_adv++;
4136 kfree_skb(skb);
4137 return 0;
4138 }
4139 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4140 ep->com.state);
4141
4142 /*
4143 * Wake up any threads in rdma_init() or rdma_fini().
4144 * However, if we are on MPAv2 and want to retry with MPAv1
4145 * then, don't wake up yet.
4146 */
4147 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4148 if (ep->com.state != MPA_REQ_SENT)
4149 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4150 } else
4151 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4152 sched(dev, skb);
4153 return 0;
4154 }
4155
4156 /*
4157 * Most upcalls from the T4 Core go to sched() to
4158 * schedule the processing on a work queue.
4159 */
4160 c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4161 [CPL_ACT_ESTABLISH] = sched,
4162 [CPL_ACT_OPEN_RPL] = sched,
4163 [CPL_RX_DATA] = sched,
4164 [CPL_ABORT_RPL_RSS] = sched,
4165 [CPL_ABORT_RPL] = sched,
4166 [CPL_PASS_OPEN_RPL] = sched,
4167 [CPL_CLOSE_LISTSRV_RPL] = sched,
4168 [CPL_PASS_ACCEPT_REQ] = sched,
4169 [CPL_PASS_ESTABLISH] = sched,
4170 [CPL_PEER_CLOSE] = sched,
4171 [CPL_CLOSE_CON_RPL] = sched,
4172 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
4173 [CPL_RDMA_TERMINATE] = sched,
4174 [CPL_FW4_ACK] = sched,
4175 [CPL_SET_TCB_RPL] = set_tcb_rpl,
4176 [CPL_FW6_MSG] = fw6_msg,
4177 [CPL_RX_PKT] = sched
4178 };
4179
c4iw_cm_init(void)4180 int __init c4iw_cm_init(void)
4181 {
4182 spin_lock_init(&timeout_lock);
4183 skb_queue_head_init(&rxq);
4184
4185 workq = create_singlethread_workqueue("iw_cxgb4");
4186 if (!workq)
4187 return -ENOMEM;
4188
4189 return 0;
4190 }
4191
c4iw_cm_term(void)4192 void c4iw_cm_term(void)
4193 {
4194 WARN_ON(!list_empty(&timeout_list));
4195 flush_workqueue(workq);
4196 destroy_workqueue(workq);
4197 }
4198