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