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