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