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