Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. | |
2a1d9b7f RD |
3 | * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. |
4 | * Copyright (c) 2005 Mellanox Technologies. All rights reserved. | |
5 | * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved. | |
1da177e4 LT |
6 | * |
7 | * This software is available to you under a choice of one of two | |
8 | * licenses. You may choose to be licensed under the terms of the GNU | |
9 | * General Public License (GPL) Version 2, available from the file | |
10 | * COPYING in the main directory of this source tree, or the | |
11 | * OpenIB.org BSD license below: | |
12 | * | |
13 | * Redistribution and use in source and binary forms, with or | |
14 | * without modification, are permitted provided that the following | |
15 | * conditions are met: | |
16 | * | |
17 | * - Redistributions of source code must retain the above | |
18 | * copyright notice, this list of conditions and the following | |
19 | * disclaimer. | |
20 | * | |
21 | * - Redistributions in binary form must reproduce the above | |
22 | * copyright notice, this list of conditions and the following | |
23 | * disclaimer in the documentation and/or other materials | |
24 | * provided with the distribution. | |
25 | * | |
26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
27 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
29 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |
30 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
31 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
32 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
33 | * SOFTWARE. | |
1da177e4 LT |
34 | */ |
35 | ||
36 | #include <linux/delay.h> | |
37 | #include <linux/dma-mapping.h> | |
38 | ||
40ca1988 EC |
39 | #include <linux/ip.h> |
40 | #include <linux/tcp.h> | |
1da177e4 LT |
41 | |
42 | #include "ipoib.h" | |
43 | ||
44 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA | |
45 | static int data_debug_level; | |
46 | ||
47 | module_param(data_debug_level, int, 0644); | |
48 | MODULE_PARM_DESC(data_debug_level, | |
49 | "Enable data path debug tracing if > 0"); | |
50 | #endif | |
51 | ||
95ed644f | 52 | static DEFINE_MUTEX(pkey_mutex); |
1da177e4 LT |
53 | |
54 | struct ipoib_ah *ipoib_create_ah(struct net_device *dev, | |
55 | struct ib_pd *pd, struct ib_ah_attr *attr) | |
56 | { | |
57 | struct ipoib_ah *ah; | |
58 | ||
59 | ah = kmalloc(sizeof *ah, GFP_KERNEL); | |
60 | if (!ah) | |
61 | return NULL; | |
62 | ||
63 | ah->dev = dev; | |
64 | ah->last_send = 0; | |
65 | kref_init(&ah->ref); | |
66 | ||
67 | ah->ah = ib_create_ah(pd, attr); | |
68 | if (IS_ERR(ah->ah)) { | |
69 | kfree(ah); | |
70 | ah = NULL; | |
71 | } else | |
72 | ipoib_dbg(netdev_priv(dev), "Created ah %p\n", ah->ah); | |
73 | ||
74 | return ah; | |
75 | } | |
76 | ||
77 | void ipoib_free_ah(struct kref *kref) | |
78 | { | |
79 | struct ipoib_ah *ah = container_of(kref, struct ipoib_ah, ref); | |
80 | struct ipoib_dev_priv *priv = netdev_priv(ah->dev); | |
81 | ||
82 | unsigned long flags; | |
83 | ||
31c02e21 RD |
84 | spin_lock_irqsave(&priv->lock, flags); |
85 | list_add_tail(&ah->list, &priv->dead_ahs); | |
86 | spin_unlock_irqrestore(&priv->lock, flags); | |
1da177e4 LT |
87 | } |
88 | ||
bc7b3a36 SM |
89 | static void ipoib_ud_dma_unmap_rx(struct ipoib_dev_priv *priv, |
90 | u64 mapping[IPOIB_UD_RX_SG]) | |
91 | { | |
92 | if (ipoib_ud_need_sg(priv->max_ib_mtu)) { | |
93 | ib_dma_unmap_single(priv->ca, mapping[0], IPOIB_UD_HEAD_SIZE, | |
94 | DMA_FROM_DEVICE); | |
95 | ib_dma_unmap_page(priv->ca, mapping[1], PAGE_SIZE, | |
96 | DMA_FROM_DEVICE); | |
97 | } else | |
98 | ib_dma_unmap_single(priv->ca, mapping[0], | |
99 | IPOIB_UD_BUF_SIZE(priv->max_ib_mtu), | |
100 | DMA_FROM_DEVICE); | |
101 | } | |
102 | ||
103 | static void ipoib_ud_skb_put_frags(struct ipoib_dev_priv *priv, | |
104 | struct sk_buff *skb, | |
105 | unsigned int length) | |
106 | { | |
107 | if (ipoib_ud_need_sg(priv->max_ib_mtu)) { | |
108 | skb_frag_t *frag = &skb_shinfo(skb)->frags[0]; | |
109 | unsigned int size; | |
110 | /* | |
111 | * There is only two buffers needed for max_payload = 4K, | |
112 | * first buf size is IPOIB_UD_HEAD_SIZE | |
113 | */ | |
114 | skb->tail += IPOIB_UD_HEAD_SIZE; | |
115 | skb->len += length; | |
116 | ||
117 | size = length - IPOIB_UD_HEAD_SIZE; | |
118 | ||
119 | frag->size = size; | |
120 | skb->data_len += size; | |
121 | skb->truesize += size; | |
122 | } else | |
123 | skb_put(skb, length); | |
124 | ||
125 | } | |
126 | ||
1993d683 | 127 | static int ipoib_ib_post_receive(struct net_device *dev, int id) |
1da177e4 | 128 | { |
1993d683 | 129 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
1da177e4 | 130 | struct ib_recv_wr *bad_wr; |
1993d683 RD |
131 | int ret; |
132 | ||
bc7b3a36 SM |
133 | priv->rx_wr.wr_id = id | IPOIB_OP_RECV; |
134 | priv->rx_sge[0].addr = priv->rx_ring[id].mapping[0]; | |
135 | priv->rx_sge[1].addr = priv->rx_ring[id].mapping[1]; | |
1993d683 | 136 | |
1993d683 | 137 | |
bc7b3a36 | 138 | ret = ib_post_recv(priv->qp, &priv->rx_wr, &bad_wr); |
1993d683 RD |
139 | if (unlikely(ret)) { |
140 | ipoib_warn(priv, "receive failed for buf %d (%d)\n", id, ret); | |
bc7b3a36 | 141 | ipoib_ud_dma_unmap_rx(priv, priv->rx_ring[id].mapping); |
1993d683 RD |
142 | dev_kfree_skb_any(priv->rx_ring[id].skb); |
143 | priv->rx_ring[id].skb = NULL; | |
144 | } | |
1da177e4 | 145 | |
1993d683 | 146 | return ret; |
1da177e4 LT |
147 | } |
148 | ||
bc7b3a36 | 149 | static struct sk_buff *ipoib_alloc_rx_skb(struct net_device *dev, int id) |
1da177e4 LT |
150 | { |
151 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
152 | struct sk_buff *skb; | |
bc7b3a36 SM |
153 | int buf_size; |
154 | u64 *mapping; | |
1da177e4 | 155 | |
bc7b3a36 SM |
156 | if (ipoib_ud_need_sg(priv->max_ib_mtu)) |
157 | buf_size = IPOIB_UD_HEAD_SIZE; | |
158 | else | |
159 | buf_size = IPOIB_UD_BUF_SIZE(priv->max_ib_mtu); | |
160 | ||
161 | skb = dev_alloc_skb(buf_size + 4); | |
162 | if (unlikely(!skb)) | |
163 | return NULL; | |
1993d683 RD |
164 | |
165 | /* | |
166 | * IB will leave a 40 byte gap for a GRH and IPoIB adds a 4 byte | |
167 | * header. So we need 4 more bytes to get to 48 and align the | |
168 | * IP header to a multiple of 16. | |
169 | */ | |
170 | skb_reserve(skb, 4); | |
171 | ||
bc7b3a36 SM |
172 | mapping = priv->rx_ring[id].mapping; |
173 | mapping[0] = ib_dma_map_single(priv->ca, skb->data, buf_size, | |
174 | DMA_FROM_DEVICE); | |
175 | if (unlikely(ib_dma_mapping_error(priv->ca, mapping[0]))) | |
176 | goto error; | |
177 | ||
178 | if (ipoib_ud_need_sg(priv->max_ib_mtu)) { | |
179 | struct page *page = alloc_page(GFP_ATOMIC); | |
180 | if (!page) | |
181 | goto partial_error; | |
182 | skb_fill_page_desc(skb, 0, page, 0, PAGE_SIZE); | |
183 | mapping[1] = | |
184 | ib_dma_map_page(priv->ca, skb_shinfo(skb)->frags[0].page, | |
185 | 0, PAGE_SIZE, DMA_FROM_DEVICE); | |
186 | if (unlikely(ib_dma_mapping_error(priv->ca, mapping[1]))) | |
187 | goto partial_error; | |
1da177e4 LT |
188 | } |
189 | ||
bc7b3a36 SM |
190 | priv->rx_ring[id].skb = skb; |
191 | return skb; | |
1993d683 | 192 | |
bc7b3a36 SM |
193 | partial_error: |
194 | ib_dma_unmap_single(priv->ca, mapping[0], buf_size, DMA_FROM_DEVICE); | |
195 | error: | |
196 | dev_kfree_skb_any(skb); | |
197 | return NULL; | |
1da177e4 LT |
198 | } |
199 | ||
200 | static int ipoib_ib_post_receives(struct net_device *dev) | |
201 | { | |
202 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
203 | int i; | |
204 | ||
0f485251 | 205 | for (i = 0; i < ipoib_recvq_size; ++i) { |
bc7b3a36 | 206 | if (!ipoib_alloc_rx_skb(dev, i)) { |
1993d683 RD |
207 | ipoib_warn(priv, "failed to allocate receive buffer %d\n", i); |
208 | return -ENOMEM; | |
209 | } | |
1da177e4 LT |
210 | if (ipoib_ib_post_receive(dev, i)) { |
211 | ipoib_warn(priv, "ipoib_ib_post_receive failed for buf %d\n", i); | |
212 | return -EIO; | |
213 | } | |
214 | } | |
215 | ||
216 | return 0; | |
217 | } | |
218 | ||
2439a6e6 | 219 | static void ipoib_ib_handle_rx_wc(struct net_device *dev, struct ib_wc *wc) |
1da177e4 LT |
220 | { |
221 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
2439a6e6 RD |
222 | unsigned int wr_id = wc->wr_id & ~IPOIB_OP_RECV; |
223 | struct sk_buff *skb; | |
bc7b3a36 | 224 | u64 mapping[IPOIB_UD_RX_SG]; |
1da177e4 | 225 | |
a89875fc RD |
226 | ipoib_dbg_data(priv, "recv completion: id %d, status: %d\n", |
227 | wr_id, wc->status); | |
1da177e4 | 228 | |
2439a6e6 RD |
229 | if (unlikely(wr_id >= ipoib_recvq_size)) { |
230 | ipoib_warn(priv, "recv completion event with wrid %d (> %d)\n", | |
231 | wr_id, ipoib_recvq_size); | |
232 | return; | |
233 | } | |
234 | ||
235 | skb = priv->rx_ring[wr_id].skb; | |
2439a6e6 RD |
236 | |
237 | if (unlikely(wc->status != IB_WC_SUCCESS)) { | |
238 | if (wc->status != IB_WC_WR_FLUSH_ERR) | |
239 | ipoib_warn(priv, "failed recv event " | |
240 | "(status=%d, wrid=%d vend_err %x)\n", | |
241 | wc->status, wr_id, wc->vendor_err); | |
bc7b3a36 | 242 | ipoib_ud_dma_unmap_rx(priv, priv->rx_ring[wr_id].mapping); |
2439a6e6 RD |
243 | dev_kfree_skb_any(skb); |
244 | priv->rx_ring[wr_id].skb = NULL; | |
245 | return; | |
246 | } | |
1da177e4 | 247 | |
1b844afe RD |
248 | /* |
249 | * Drop packets that this interface sent, ie multicast packets | |
250 | * that the HCA has replicated. | |
251 | */ | |
252 | if (wc->slid == priv->local_lid && wc->src_qp == priv->qp->qp_num) | |
253 | goto repost; | |
254 | ||
bc7b3a36 SM |
255 | memcpy(mapping, priv->rx_ring[wr_id].mapping, |
256 | IPOIB_UD_RX_SG * sizeof *mapping); | |
257 | ||
2439a6e6 RD |
258 | /* |
259 | * If we can't allocate a new RX buffer, dump | |
260 | * this packet and reuse the old buffer. | |
261 | */ | |
bc7b3a36 | 262 | if (unlikely(!ipoib_alloc_rx_skb(dev, wr_id))) { |
de903512 | 263 | ++dev->stats.rx_dropped; |
2439a6e6 RD |
264 | goto repost; |
265 | } | |
266 | ||
267 | ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n", | |
268 | wc->byte_len, wc->slid); | |
269 | ||
bc7b3a36 SM |
270 | ipoib_ud_dma_unmap_rx(priv, mapping); |
271 | ipoib_ud_skb_put_frags(priv, skb, wc->byte_len); | |
2439a6e6 | 272 | |
2439a6e6 RD |
273 | skb_pull(skb, IB_GRH_BYTES); |
274 | ||
1b844afe RD |
275 | skb->protocol = ((struct ipoib_header *) skb->data)->proto; |
276 | skb_reset_mac_header(skb); | |
277 | skb_pull(skb, IPOIB_ENCAP_LEN); | |
278 | ||
de903512 RD |
279 | ++dev->stats.rx_packets; |
280 | dev->stats.rx_bytes += skb->len; | |
1b844afe RD |
281 | |
282 | skb->dev = dev; | |
283 | /* XXX get correct PACKET_ type here */ | |
284 | skb->pkt_type = PACKET_HOST; | |
6046136c EC |
285 | |
286 | if (test_bit(IPOIB_FLAG_CSUM, &priv->flags) && likely(wc->csum_ok)) | |
287 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
288 | ||
af40da89 VS |
289 | if (dev->features & NETIF_F_LRO) |
290 | lro_receive_skb(&priv->lro.lro_mgr, skb, NULL); | |
291 | else | |
292 | netif_receive_skb(skb); | |
1da177e4 | 293 | |
2439a6e6 RD |
294 | repost: |
295 | if (unlikely(ipoib_ib_post_receive(dev, wr_id))) | |
296 | ipoib_warn(priv, "ipoib_ib_post_receive failed " | |
297 | "for buf %d\n", wr_id); | |
298 | } | |
1da177e4 | 299 | |
7143740d EC |
300 | static int ipoib_dma_map_tx(struct ib_device *ca, |
301 | struct ipoib_tx_buf *tx_req) | |
302 | { | |
303 | struct sk_buff *skb = tx_req->skb; | |
304 | u64 *mapping = tx_req->mapping; | |
305 | int i; | |
40ca1988 | 306 | int off; |
7143740d | 307 | |
40ca1988 EC |
308 | if (skb_headlen(skb)) { |
309 | mapping[0] = ib_dma_map_single(ca, skb->data, skb_headlen(skb), | |
310 | DMA_TO_DEVICE); | |
311 | if (unlikely(ib_dma_mapping_error(ca, mapping[0]))) | |
312 | return -EIO; | |
313 | ||
314 | off = 1; | |
315 | } else | |
316 | off = 0; | |
7143740d EC |
317 | |
318 | for (i = 0; i < skb_shinfo(skb)->nr_frags; ++i) { | |
319 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | |
40ca1988 | 320 | mapping[i + off] = ib_dma_map_page(ca, frag->page, |
7143740d EC |
321 | frag->page_offset, frag->size, |
322 | DMA_TO_DEVICE); | |
40ca1988 | 323 | if (unlikely(ib_dma_mapping_error(ca, mapping[i + off]))) |
7143740d EC |
324 | goto partial_error; |
325 | } | |
326 | return 0; | |
327 | ||
328 | partial_error: | |
7143740d EC |
329 | for (; i > 0; --i) { |
330 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i - 1]; | |
40ca1988 | 331 | ib_dma_unmap_page(ca, mapping[i - !off], frag->size, DMA_TO_DEVICE); |
7143740d | 332 | } |
40ca1988 EC |
333 | |
334 | if (off) | |
335 | ib_dma_unmap_single(ca, mapping[0], skb_headlen(skb), DMA_TO_DEVICE); | |
336 | ||
7143740d EC |
337 | return -EIO; |
338 | } | |
339 | ||
340 | static void ipoib_dma_unmap_tx(struct ib_device *ca, | |
341 | struct ipoib_tx_buf *tx_req) | |
342 | { | |
343 | struct sk_buff *skb = tx_req->skb; | |
344 | u64 *mapping = tx_req->mapping; | |
345 | int i; | |
40ca1988 | 346 | int off; |
7143740d | 347 | |
40ca1988 EC |
348 | if (skb_headlen(skb)) { |
349 | ib_dma_unmap_single(ca, mapping[0], skb_headlen(skb), DMA_TO_DEVICE); | |
350 | off = 1; | |
351 | } else | |
352 | off = 0; | |
7143740d EC |
353 | |
354 | for (i = 0; i < skb_shinfo(skb)->nr_frags; ++i) { | |
355 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | |
40ca1988 | 356 | ib_dma_unmap_page(ca, mapping[i + off], frag->size, |
7143740d EC |
357 | DMA_TO_DEVICE); |
358 | } | |
359 | } | |
360 | ||
2439a6e6 RD |
361 | static void ipoib_ib_handle_tx_wc(struct net_device *dev, struct ib_wc *wc) |
362 | { | |
363 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
364 | unsigned int wr_id = wc->wr_id; | |
365 | struct ipoib_tx_buf *tx_req; | |
1da177e4 | 366 | |
a89875fc RD |
367 | ipoib_dbg_data(priv, "send completion: id %d, status: %d\n", |
368 | wr_id, wc->status); | |
1da177e4 | 369 | |
2439a6e6 RD |
370 | if (unlikely(wr_id >= ipoib_sendq_size)) { |
371 | ipoib_warn(priv, "send completion event with wrid %d (> %d)\n", | |
372 | wr_id, ipoib_sendq_size); | |
373 | return; | |
1da177e4 | 374 | } |
2439a6e6 RD |
375 | |
376 | tx_req = &priv->tx_ring[wr_id]; | |
377 | ||
7143740d | 378 | ipoib_dma_unmap_tx(priv->ca, tx_req); |
2439a6e6 | 379 | |
de903512 RD |
380 | ++dev->stats.tx_packets; |
381 | dev->stats.tx_bytes += tx_req->skb->len; | |
2439a6e6 RD |
382 | |
383 | dev_kfree_skb_any(tx_req->skb); | |
384 | ||
2439a6e6 | 385 | ++priv->tx_tail; |
1b524963 MT |
386 | if (unlikely(--priv->tx_outstanding == ipoib_sendq_size >> 1) && |
387 | netif_queue_stopped(dev) && | |
388 | test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) | |
2439a6e6 | 389 | netif_wake_queue(dev); |
2439a6e6 RD |
390 | |
391 | if (wc->status != IB_WC_SUCCESS && | |
392 | wc->status != IB_WC_WR_FLUSH_ERR) | |
393 | ipoib_warn(priv, "failed send event " | |
394 | "(status=%d, wrid=%d vend_err %x)\n", | |
395 | wc->status, wr_id, wc->vendor_err); | |
396 | } | |
397 | ||
f56bcd80 EC |
398 | static int poll_tx(struct ipoib_dev_priv *priv) |
399 | { | |
400 | int n, i; | |
401 | ||
402 | n = ib_poll_cq(priv->send_cq, MAX_SEND_CQE, priv->send_wc); | |
403 | for (i = 0; i < n; ++i) | |
404 | ipoib_ib_handle_tx_wc(priv->dev, priv->send_wc + i); | |
405 | ||
406 | return n == MAX_SEND_CQE; | |
407 | } | |
408 | ||
bea3348e | 409 | int ipoib_poll(struct napi_struct *napi, int budget) |
2439a6e6 | 410 | { |
bea3348e SH |
411 | struct ipoib_dev_priv *priv = container_of(napi, struct ipoib_dev_priv, napi); |
412 | struct net_device *dev = priv->dev; | |
8d1cc86a RD |
413 | int done; |
414 | int t; | |
8d1cc86a RD |
415 | int n, i; |
416 | ||
417 | done = 0; | |
8d1cc86a | 418 | |
bea3348e SH |
419 | poll_more: |
420 | while (done < budget) { | |
421 | int max = (budget - done); | |
422 | ||
8d1cc86a | 423 | t = min(IPOIB_NUM_WC, max); |
f56bcd80 | 424 | n = ib_poll_cq(priv->recv_cq, t, priv->ibwc); |
8d1cc86a | 425 | |
bea3348e | 426 | for (i = 0; i < n; i++) { |
8d1cc86a RD |
427 | struct ib_wc *wc = priv->ibwc + i; |
428 | ||
1b524963 | 429 | if (wc->wr_id & IPOIB_OP_RECV) { |
8d1cc86a | 430 | ++done; |
1b524963 MT |
431 | if (wc->wr_id & IPOIB_OP_CM) |
432 | ipoib_cm_handle_rx_wc(dev, wc); | |
433 | else | |
434 | ipoib_ib_handle_rx_wc(dev, wc); | |
f56bcd80 EC |
435 | } else |
436 | ipoib_cm_handle_tx_wc(priv->dev, wc); | |
8d1cc86a RD |
437 | } |
438 | ||
bea3348e | 439 | if (n != t) |
8d1cc86a | 440 | break; |
8d1cc86a RD |
441 | } |
442 | ||
bea3348e | 443 | if (done < budget) { |
af40da89 VS |
444 | if (dev->features & NETIF_F_LRO) |
445 | lro_flush_all(&priv->lro.lro_mgr); | |
446 | ||
288379f0 | 447 | napi_complete(napi); |
f56bcd80 | 448 | if (unlikely(ib_req_notify_cq(priv->recv_cq, |
8d1cc86a RD |
449 | IB_CQ_NEXT_COMP | |
450 | IB_CQ_REPORT_MISSED_EVENTS)) && | |
288379f0 | 451 | napi_reschedule(napi)) |
bea3348e | 452 | goto poll_more; |
8d1cc86a RD |
453 | } |
454 | ||
bea3348e | 455 | return done; |
1da177e4 LT |
456 | } |
457 | ||
458 | void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr) | |
459 | { | |
bea3348e SH |
460 | struct net_device *dev = dev_ptr; |
461 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
462 | ||
288379f0 | 463 | napi_schedule(&priv->napi); |
1da177e4 LT |
464 | } |
465 | ||
57ce41d1 EC |
466 | static void drain_tx_cq(struct net_device *dev) |
467 | { | |
468 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
57ce41d1 | 469 | |
943c246e | 470 | netif_tx_lock(dev); |
57ce41d1 EC |
471 | while (poll_tx(priv)) |
472 | ; /* nothing */ | |
473 | ||
474 | if (netif_queue_stopped(dev)) | |
475 | mod_timer(&priv->poll_timer, jiffies + 1); | |
476 | ||
943c246e | 477 | netif_tx_unlock(dev); |
57ce41d1 EC |
478 | } |
479 | ||
480 | void ipoib_send_comp_handler(struct ib_cq *cq, void *dev_ptr) | |
481 | { | |
943c246e RD |
482 | struct ipoib_dev_priv *priv = netdev_priv(dev_ptr); |
483 | ||
484 | mod_timer(&priv->poll_timer, jiffies); | |
57ce41d1 EC |
485 | } |
486 | ||
1da177e4 LT |
487 | static inline int post_send(struct ipoib_dev_priv *priv, |
488 | unsigned int wr_id, | |
489 | struct ib_ah *address, u32 qpn, | |
40ca1988 EC |
490 | struct ipoib_tx_buf *tx_req, |
491 | void *head, int hlen) | |
1da177e4 LT |
492 | { |
493 | struct ib_send_wr *bad_wr; | |
40ca1988 EC |
494 | int i, off; |
495 | struct sk_buff *skb = tx_req->skb; | |
496 | skb_frag_t *frags = skb_shinfo(skb)->frags; | |
497 | int nr_frags = skb_shinfo(skb)->nr_frags; | |
498 | u64 *mapping = tx_req->mapping; | |
499 | ||
500 | if (skb_headlen(skb)) { | |
501 | priv->tx_sge[0].addr = mapping[0]; | |
502 | priv->tx_sge[0].length = skb_headlen(skb); | |
503 | off = 1; | |
504 | } else | |
505 | off = 0; | |
1da177e4 | 506 | |
7143740d | 507 | for (i = 0; i < nr_frags; ++i) { |
40ca1988 EC |
508 | priv->tx_sge[i + off].addr = mapping[i + off]; |
509 | priv->tx_sge[i + off].length = frags[i].size; | |
7143740d | 510 | } |
40ca1988 | 511 | priv->tx_wr.num_sge = nr_frags + off; |
7143740d EC |
512 | priv->tx_wr.wr_id = wr_id; |
513 | priv->tx_wr.wr.ud.remote_qpn = qpn; | |
514 | priv->tx_wr.wr.ud.ah = address; | |
1da177e4 | 515 | |
40ca1988 EC |
516 | if (head) { |
517 | priv->tx_wr.wr.ud.mss = skb_shinfo(skb)->gso_size; | |
518 | priv->tx_wr.wr.ud.header = head; | |
519 | priv->tx_wr.wr.ud.hlen = hlen; | |
520 | priv->tx_wr.opcode = IB_WR_LSO; | |
521 | } else | |
522 | priv->tx_wr.opcode = IB_WR_SEND; | |
523 | ||
1da177e4 LT |
524 | return ib_post_send(priv->qp, &priv->tx_wr, &bad_wr); |
525 | } | |
526 | ||
527 | void ipoib_send(struct net_device *dev, struct sk_buff *skb, | |
528 | struct ipoib_ah *address, u32 qpn) | |
529 | { | |
530 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
1993d683 | 531 | struct ipoib_tx_buf *tx_req; |
40ca1988 EC |
532 | int hlen; |
533 | void *phead; | |
534 | ||
535 | if (skb_is_gso(skb)) { | |
536 | hlen = skb_transport_offset(skb) + tcp_hdrlen(skb); | |
537 | phead = skb->data; | |
538 | if (unlikely(!skb_pull(skb, hlen))) { | |
539 | ipoib_warn(priv, "linear data too small\n"); | |
540 | ++dev->stats.tx_dropped; | |
541 | ++dev->stats.tx_errors; | |
542 | dev_kfree_skb_any(skb); | |
543 | return; | |
544 | } | |
545 | } else { | |
546 | if (unlikely(skb->len > priv->mcast_mtu + IPOIB_ENCAP_LEN)) { | |
547 | ipoib_warn(priv, "packet len %d (> %d) too long to send, dropping\n", | |
548 | skb->len, priv->mcast_mtu + IPOIB_ENCAP_LEN); | |
549 | ++dev->stats.tx_dropped; | |
550 | ++dev->stats.tx_errors; | |
551 | ipoib_cm_skb_too_long(dev, skb, priv->mcast_mtu); | |
552 | return; | |
553 | } | |
554 | phead = NULL; | |
555 | hlen = 0; | |
1da177e4 LT |
556 | } |
557 | ||
558 | ipoib_dbg_data(priv, "sending packet, length=%d address=%p qpn=0x%06x\n", | |
559 | skb->len, address, qpn); | |
560 | ||
561 | /* | |
562 | * We put the skb into the tx_ring _before_ we call post_send() | |
563 | * because it's entirely possible that the completion handler will | |
564 | * run before we execute anything after the post_send(). That | |
565 | * means we have to make sure everything is properly recorded and | |
566 | * our state is consistent before we call post_send(). | |
567 | */ | |
0f485251 | 568 | tx_req = &priv->tx_ring[priv->tx_head & (ipoib_sendq_size - 1)]; |
1da177e4 | 569 | tx_req->skb = skb; |
7143740d | 570 | if (unlikely(ipoib_dma_map_tx(priv->ca, tx_req))) { |
de903512 | 571 | ++dev->stats.tx_errors; |
73fbe8be RD |
572 | dev_kfree_skb_any(skb); |
573 | return; | |
574 | } | |
1da177e4 | 575 | |
6046136c EC |
576 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
577 | priv->tx_wr.send_flags |= IB_SEND_IP_CSUM; | |
578 | else | |
579 | priv->tx_wr.send_flags &= ~IB_SEND_IP_CSUM; | |
580 | ||
57ce41d1 EC |
581 | if (++priv->tx_outstanding == ipoib_sendq_size) { |
582 | ipoib_dbg(priv, "TX ring full, stopping kernel net queue\n"); | |
583 | if (ib_req_notify_cq(priv->send_cq, IB_CQ_NEXT_COMP)) | |
584 | ipoib_warn(priv, "request notify on send CQ failed\n"); | |
585 | netif_stop_queue(dev); | |
586 | } | |
587 | ||
0f485251 | 588 | if (unlikely(post_send(priv, priv->tx_head & (ipoib_sendq_size - 1), |
40ca1988 | 589 | address->ah, qpn, tx_req, phead, hlen))) { |
1da177e4 | 590 | ipoib_warn(priv, "post_send failed\n"); |
de903512 | 591 | ++dev->stats.tx_errors; |
57ce41d1 | 592 | --priv->tx_outstanding; |
7143740d | 593 | ipoib_dma_unmap_tx(priv->ca, tx_req); |
1da177e4 | 594 | dev_kfree_skb_any(skb); |
57ce41d1 EC |
595 | if (netif_queue_stopped(dev)) |
596 | netif_wake_queue(dev); | |
1da177e4 LT |
597 | } else { |
598 | dev->trans_start = jiffies; | |
599 | ||
600 | address->last_send = priv->tx_head; | |
601 | ++priv->tx_head; | |
f56bcd80 | 602 | skb_orphan(skb); |
1da177e4 | 603 | |
1da177e4 | 604 | } |
f56bcd80 EC |
605 | |
606 | if (unlikely(priv->tx_outstanding > MAX_SEND_CQE)) | |
57ce41d1 EC |
607 | while (poll_tx(priv)) |
608 | ; /* nothing */ | |
1da177e4 LT |
609 | } |
610 | ||
611 | static void __ipoib_reap_ah(struct net_device *dev) | |
612 | { | |
613 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
614 | struct ipoib_ah *ah, *tah; | |
615 | LIST_HEAD(remove_list); | |
943c246e RD |
616 | unsigned long flags; |
617 | ||
618 | netif_tx_lock_bh(dev); | |
619 | spin_lock_irqsave(&priv->lock, flags); | |
1da177e4 | 620 | |
1da177e4 | 621 | list_for_each_entry_safe(ah, tah, &priv->dead_ahs, list) |
2181858b | 622 | if ((int) priv->tx_tail - (int) ah->last_send >= 0) { |
1da177e4 | 623 | list_del(&ah->list); |
31c02e21 RD |
624 | ib_destroy_ah(ah->ah); |
625 | kfree(ah); | |
1da177e4 | 626 | } |
943c246e RD |
627 | |
628 | spin_unlock_irqrestore(&priv->lock, flags); | |
629 | netif_tx_unlock_bh(dev); | |
1da177e4 LT |
630 | } |
631 | ||
c4028958 | 632 | void ipoib_reap_ah(struct work_struct *work) |
1da177e4 | 633 | { |
c4028958 DH |
634 | struct ipoib_dev_priv *priv = |
635 | container_of(work, struct ipoib_dev_priv, ah_reap_task.work); | |
636 | struct net_device *dev = priv->dev; | |
1da177e4 LT |
637 | |
638 | __ipoib_reap_ah(dev); | |
639 | ||
640 | if (!test_bit(IPOIB_STOP_REAPER, &priv->flags)) | |
69fc507a AB |
641 | queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, |
642 | round_jiffies_relative(HZ)); | |
1da177e4 LT |
643 | } |
644 | ||
57ce41d1 EC |
645 | static void ipoib_ib_tx_timer_func(unsigned long ctx) |
646 | { | |
647 | drain_tx_cq((struct net_device *)ctx); | |
648 | } | |
649 | ||
1da177e4 LT |
650 | int ipoib_ib_dev_open(struct net_device *dev) |
651 | { | |
652 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
653 | int ret; | |
654 | ||
26bbf13c YE |
655 | if (ib_find_pkey(priv->ca, priv->port, priv->pkey, &priv->pkey_index)) { |
656 | ipoib_warn(priv, "P_Key 0x%04x not found\n", priv->pkey); | |
657 | clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags); | |
658 | return -1; | |
659 | } | |
660 | set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags); | |
661 | ||
5b6810e0 | 662 | ret = ipoib_init_qp(dev); |
1da177e4 | 663 | if (ret) { |
5b6810e0 | 664 | ipoib_warn(priv, "ipoib_init_qp returned %d\n", ret); |
1da177e4 LT |
665 | return -1; |
666 | } | |
667 | ||
668 | ret = ipoib_ib_post_receives(dev); | |
669 | if (ret) { | |
670 | ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret); | |
26bbf13c | 671 | ipoib_ib_dev_stop(dev, 1); |
1da177e4 LT |
672 | return -1; |
673 | } | |
674 | ||
839fcaba MT |
675 | ret = ipoib_cm_dev_open(dev); |
676 | if (ret) { | |
24bd1e4e | 677 | ipoib_warn(priv, "ipoib_cm_dev_open returned %d\n", ret); |
26bbf13c | 678 | ipoib_ib_dev_stop(dev, 1); |
839fcaba MT |
679 | return -1; |
680 | } | |
681 | ||
1da177e4 | 682 | clear_bit(IPOIB_STOP_REAPER, &priv->flags); |
69fc507a AB |
683 | queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, |
684 | round_jiffies_relative(HZ)); | |
1da177e4 | 685 | |
e028cc55 YE |
686 | if (!test_and_set_bit(IPOIB_FLAG_INITIALIZED, &priv->flags)) |
687 | napi_enable(&priv->napi); | |
7a343d4c | 688 | |
1da177e4 LT |
689 | return 0; |
690 | } | |
691 | ||
7a343d4c LA |
692 | static void ipoib_pkey_dev_check_presence(struct net_device *dev) |
693 | { | |
694 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
695 | u16 pkey_index = 0; | |
696 | ||
9fdd5e5b | 697 | if (ib_find_pkey(priv->ca, priv->port, priv->pkey, &pkey_index)) |
7a343d4c LA |
698 | clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags); |
699 | else | |
700 | set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags); | |
701 | } | |
702 | ||
1da177e4 LT |
703 | int ipoib_ib_dev_up(struct net_device *dev) |
704 | { | |
705 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
706 | ||
7a343d4c LA |
707 | ipoib_pkey_dev_check_presence(dev); |
708 | ||
709 | if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) { | |
710 | ipoib_dbg(priv, "PKEY is not assigned.\n"); | |
711 | return 0; | |
712 | } | |
713 | ||
1da177e4 LT |
714 | set_bit(IPOIB_FLAG_OPER_UP, &priv->flags); |
715 | ||
716 | return ipoib_mcast_start_thread(dev); | |
717 | } | |
718 | ||
0b3ea082 | 719 | int ipoib_ib_dev_down(struct net_device *dev, int flush) |
1da177e4 LT |
720 | { |
721 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
722 | ||
723 | ipoib_dbg(priv, "downing ib_dev\n"); | |
724 | ||
725 | clear_bit(IPOIB_FLAG_OPER_UP, &priv->flags); | |
726 | netif_carrier_off(dev); | |
727 | ||
728 | /* Shutdown the P_Key thread if still active */ | |
729 | if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) { | |
95ed644f | 730 | mutex_lock(&pkey_mutex); |
1da177e4 | 731 | set_bit(IPOIB_PKEY_STOP, &priv->flags); |
26bbf13c | 732 | cancel_delayed_work(&priv->pkey_poll_task); |
95ed644f | 733 | mutex_unlock(&pkey_mutex); |
0b3ea082 JM |
734 | if (flush) |
735 | flush_workqueue(ipoib_workqueue); | |
1da177e4 LT |
736 | } |
737 | ||
0b3ea082 | 738 | ipoib_mcast_stop_thread(dev, flush); |
1da177e4 LT |
739 | ipoib_mcast_dev_flush(dev); |
740 | ||
1da177e4 LT |
741 | ipoib_flush_paths(dev); |
742 | ||
743 | return 0; | |
744 | } | |
745 | ||
746 | static int recvs_pending(struct net_device *dev) | |
747 | { | |
748 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
749 | int pending = 0; | |
750 | int i; | |
751 | ||
0f485251 | 752 | for (i = 0; i < ipoib_recvq_size; ++i) |
1da177e4 LT |
753 | if (priv->rx_ring[i].skb) |
754 | ++pending; | |
755 | ||
756 | return pending; | |
757 | } | |
758 | ||
2dfbfc37 MT |
759 | void ipoib_drain_cq(struct net_device *dev) |
760 | { | |
761 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
762 | int i, n; | |
943c246e RD |
763 | |
764 | /* | |
765 | * We call completion handling routines that expect to be | |
766 | * called from the BH-disabled NAPI poll context, so disable | |
767 | * BHs here too. | |
768 | */ | |
769 | local_bh_disable(); | |
770 | ||
2dfbfc37 | 771 | do { |
f56bcd80 | 772 | n = ib_poll_cq(priv->recv_cq, IPOIB_NUM_WC, priv->ibwc); |
2dfbfc37 | 773 | for (i = 0; i < n; ++i) { |
ce423ef5 RD |
774 | /* |
775 | * Convert any successful completions to flush | |
776 | * errors to avoid passing packets up the | |
777 | * stack after bringing the device down. | |
778 | */ | |
779 | if (priv->ibwc[i].status == IB_WC_SUCCESS) | |
780 | priv->ibwc[i].status = IB_WC_WR_FLUSH_ERR; | |
781 | ||
1b524963 MT |
782 | if (priv->ibwc[i].wr_id & IPOIB_OP_RECV) { |
783 | if (priv->ibwc[i].wr_id & IPOIB_OP_CM) | |
784 | ipoib_cm_handle_rx_wc(dev, priv->ibwc + i); | |
785 | else | |
786 | ipoib_ib_handle_rx_wc(dev, priv->ibwc + i); | |
f56bcd80 EC |
787 | } else |
788 | ipoib_cm_handle_tx_wc(dev, priv->ibwc + i); | |
2dfbfc37 MT |
789 | } |
790 | } while (n == IPOIB_NUM_WC); | |
f56bcd80 EC |
791 | |
792 | while (poll_tx(priv)) | |
793 | ; /* nothing */ | |
943c246e RD |
794 | |
795 | local_bh_enable(); | |
2dfbfc37 MT |
796 | } |
797 | ||
26bbf13c | 798 | int ipoib_ib_dev_stop(struct net_device *dev, int flush) |
1da177e4 LT |
799 | { |
800 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
801 | struct ib_qp_attr qp_attr; | |
1da177e4 | 802 | unsigned long begin; |
1993d683 | 803 | struct ipoib_tx_buf *tx_req; |
2dfbfc37 | 804 | int i; |
1da177e4 | 805 | |
e028cc55 YE |
806 | if (test_and_clear_bit(IPOIB_FLAG_INITIALIZED, &priv->flags)) |
807 | napi_disable(&priv->napi); | |
7a343d4c | 808 | |
839fcaba MT |
809 | ipoib_cm_dev_stop(dev); |
810 | ||
3bc12e75 RD |
811 | /* |
812 | * Move our QP to the error state and then reinitialize in | |
813 | * when all work requests have completed or have been flushed. | |
814 | */ | |
1da177e4 | 815 | qp_attr.qp_state = IB_QPS_ERR; |
3bc12e75 | 816 | if (ib_modify_qp(priv->qp, &qp_attr, IB_QP_STATE)) |
1da177e4 LT |
817 | ipoib_warn(priv, "Failed to modify QP to ERROR state\n"); |
818 | ||
819 | /* Wait for all sends and receives to complete */ | |
820 | begin = jiffies; | |
821 | ||
822 | while (priv->tx_head != priv->tx_tail || recvs_pending(dev)) { | |
823 | if (time_after(jiffies, begin + 5 * HZ)) { | |
824 | ipoib_warn(priv, "timing out; %d sends %d receives not completed\n", | |
825 | priv->tx_head - priv->tx_tail, recvs_pending(dev)); | |
826 | ||
827 | /* | |
828 | * assume the HW is wedged and just free up | |
829 | * all our pending work requests. | |
830 | */ | |
2181858b | 831 | while ((int) priv->tx_tail - (int) priv->tx_head < 0) { |
1da177e4 | 832 | tx_req = &priv->tx_ring[priv->tx_tail & |
0f485251 | 833 | (ipoib_sendq_size - 1)]; |
7143740d | 834 | ipoib_dma_unmap_tx(priv->ca, tx_req); |
1da177e4 LT |
835 | dev_kfree_skb_any(tx_req->skb); |
836 | ++priv->tx_tail; | |
1b524963 | 837 | --priv->tx_outstanding; |
1da177e4 LT |
838 | } |
839 | ||
37ccf9df RC |
840 | for (i = 0; i < ipoib_recvq_size; ++i) { |
841 | struct ipoib_rx_buf *rx_req; | |
842 | ||
843 | rx_req = &priv->rx_ring[i]; | |
844 | if (!rx_req->skb) | |
845 | continue; | |
bc7b3a36 SM |
846 | ipoib_ud_dma_unmap_rx(priv, |
847 | priv->rx_ring[i].mapping); | |
37ccf9df RC |
848 | dev_kfree_skb_any(rx_req->skb); |
849 | rx_req->skb = NULL; | |
850 | } | |
1da177e4 LT |
851 | |
852 | goto timeout; | |
853 | } | |
854 | ||
2dfbfc37 | 855 | ipoib_drain_cq(dev); |
8d1cc86a | 856 | |
1da177e4 LT |
857 | msleep(1); |
858 | } | |
859 | ||
860 | ipoib_dbg(priv, "All sends and receives done.\n"); | |
861 | ||
862 | timeout: | |
57ce41d1 | 863 | del_timer_sync(&priv->poll_timer); |
1da177e4 | 864 | qp_attr.qp_state = IB_QPS_RESET; |
3bc12e75 | 865 | if (ib_modify_qp(priv->qp, &qp_attr, IB_QP_STATE)) |
1da177e4 LT |
866 | ipoib_warn(priv, "Failed to modify QP to RESET state\n"); |
867 | ||
868 | /* Wait for all AHs to be reaped */ | |
869 | set_bit(IPOIB_STOP_REAPER, &priv->flags); | |
870 | cancel_delayed_work(&priv->ah_reap_task); | |
26bbf13c YE |
871 | if (flush) |
872 | flush_workqueue(ipoib_workqueue); | |
1da177e4 LT |
873 | |
874 | begin = jiffies; | |
875 | ||
876 | while (!list_empty(&priv->dead_ahs)) { | |
877 | __ipoib_reap_ah(dev); | |
878 | ||
879 | if (time_after(jiffies, begin + HZ)) { | |
880 | ipoib_warn(priv, "timing out; will leak address handles\n"); | |
881 | break; | |
882 | } | |
883 | ||
884 | msleep(1); | |
885 | } | |
886 | ||
f56bcd80 | 887 | ib_req_notify_cq(priv->recv_cq, IB_CQ_NEXT_COMP); |
8d1cc86a | 888 | |
1da177e4 LT |
889 | return 0; |
890 | } | |
891 | ||
892 | int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port) | |
893 | { | |
894 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
895 | ||
896 | priv->ca = ca; | |
897 | priv->port = port; | |
898 | priv->qp = NULL; | |
899 | ||
900 | if (ipoib_transport_dev_init(dev, ca)) { | |
901 | printk(KERN_WARNING "%s: ipoib_transport_dev_init failed\n", ca->name); | |
902 | return -ENODEV; | |
903 | } | |
904 | ||
2767840a RD |
905 | setup_timer(&priv->poll_timer, ipoib_ib_tx_timer_func, |
906 | (unsigned long) dev); | |
907 | ||
1da177e4 LT |
908 | if (dev->flags & IFF_UP) { |
909 | if (ipoib_ib_dev_open(dev)) { | |
910 | ipoib_transport_dev_cleanup(dev); | |
911 | return -ENODEV; | |
912 | } | |
913 | } | |
914 | ||
915 | return 0; | |
916 | } | |
917 | ||
ee1e2c82 MS |
918 | static void __ipoib_ib_dev_flush(struct ipoib_dev_priv *priv, |
919 | enum ipoib_flush_level level) | |
1da177e4 | 920 | { |
26bbf13c | 921 | struct ipoib_dev_priv *cpriv; |
c4028958 | 922 | struct net_device *dev = priv->dev; |
26bbf13c YE |
923 | u16 new_index; |
924 | ||
925 | mutex_lock(&priv->vlan_mutex); | |
1da177e4 | 926 | |
26bbf13c YE |
927 | /* |
928 | * Flush any child interfaces too -- they might be up even if | |
929 | * the parent is down. | |
930 | */ | |
931 | list_for_each_entry(cpriv, &priv->child_intfs, list) | |
ee1e2c82 | 932 | __ipoib_ib_dev_flush(cpriv, level); |
26bbf13c YE |
933 | |
934 | mutex_unlock(&priv->vlan_mutex); | |
935 | ||
936 | if (!test_bit(IPOIB_FLAG_INITIALIZED, &priv->flags)) { | |
7a343d4c LA |
937 | ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_INITIALIZED not set.\n"); |
938 | return; | |
939 | } | |
940 | ||
941 | if (!test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) { | |
942 | ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_ADMIN_UP not set.\n"); | |
1da177e4 | 943 | return; |
7a343d4c | 944 | } |
1da177e4 | 945 | |
ee1e2c82 | 946 | if (level == IPOIB_FLUSH_HEAVY) { |
26bbf13c YE |
947 | if (ib_find_pkey(priv->ca, priv->port, priv->pkey, &new_index)) { |
948 | clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags); | |
949 | ipoib_ib_dev_down(dev, 0); | |
167c4265 | 950 | ipoib_ib_dev_stop(dev, 0); |
9fdd5e5b RD |
951 | if (ipoib_pkey_dev_delay_open(dev)) |
952 | return; | |
26bbf13c | 953 | } |
26bbf13c YE |
954 | |
955 | /* restart QP only if P_Key index is changed */ | |
9fdd5e5b RD |
956 | if (test_and_set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags) && |
957 | new_index == priv->pkey_index) { | |
26bbf13c YE |
958 | ipoib_dbg(priv, "Not flushing - P_Key index not changed.\n"); |
959 | return; | |
960 | } | |
961 | priv->pkey_index = new_index; | |
962 | } | |
963 | ||
ee1e2c82 MS |
964 | if (level == IPOIB_FLUSH_LIGHT) { |
965 | ipoib_mark_paths_invalid(dev); | |
966 | ipoib_mcast_dev_flush(dev); | |
967 | } | |
1da177e4 | 968 | |
ee1e2c82 MS |
969 | if (level >= IPOIB_FLUSH_NORMAL) |
970 | ipoib_ib_dev_down(dev, 0); | |
1da177e4 | 971 | |
ee1e2c82 | 972 | if (level == IPOIB_FLUSH_HEAVY) { |
26bbf13c YE |
973 | ipoib_ib_dev_stop(dev, 0); |
974 | ipoib_ib_dev_open(dev); | |
975 | } | |
976 | ||
1da177e4 LT |
977 | /* |
978 | * The device could have been brought down between the start and when | |
979 | * we get here, don't bring it back up if it's not configured up | |
980 | */ | |
5ccd0255 | 981 | if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) { |
ee1e2c82 MS |
982 | if (level >= IPOIB_FLUSH_NORMAL) |
983 | ipoib_ib_dev_up(dev); | |
c4028958 | 984 | ipoib_mcast_restart_task(&priv->restart_task); |
5ccd0255 | 985 | } |
26bbf13c | 986 | } |
1da177e4 | 987 | |
ee1e2c82 MS |
988 | void ipoib_ib_dev_flush_light(struct work_struct *work) |
989 | { | |
990 | struct ipoib_dev_priv *priv = | |
991 | container_of(work, struct ipoib_dev_priv, flush_light); | |
992 | ||
993 | __ipoib_ib_dev_flush(priv, IPOIB_FLUSH_LIGHT); | |
994 | } | |
995 | ||
996 | void ipoib_ib_dev_flush_normal(struct work_struct *work) | |
26bbf13c YE |
997 | { |
998 | struct ipoib_dev_priv *priv = | |
ee1e2c82 | 999 | container_of(work, struct ipoib_dev_priv, flush_normal); |
4f71055a | 1000 | |
ee1e2c82 | 1001 | __ipoib_ib_dev_flush(priv, IPOIB_FLUSH_NORMAL); |
26bbf13c | 1002 | } |
4f71055a | 1003 | |
ee1e2c82 | 1004 | void ipoib_ib_dev_flush_heavy(struct work_struct *work) |
26bbf13c YE |
1005 | { |
1006 | struct ipoib_dev_priv *priv = | |
ee1e2c82 | 1007 | container_of(work, struct ipoib_dev_priv, flush_heavy); |
26bbf13c | 1008 | |
ee1e2c82 | 1009 | __ipoib_ib_dev_flush(priv, IPOIB_FLUSH_HEAVY); |
1da177e4 LT |
1010 | } |
1011 | ||
1012 | void ipoib_ib_dev_cleanup(struct net_device *dev) | |
1013 | { | |
1014 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
1015 | ||
1016 | ipoib_dbg(priv, "cleaning up ib_dev\n"); | |
1017 | ||
8d2cae06 | 1018 | ipoib_mcast_stop_thread(dev, 1); |
988bd503 | 1019 | ipoib_mcast_dev_flush(dev); |
1da177e4 LT |
1020 | |
1021 | ipoib_transport_dev_cleanup(dev); | |
1022 | } | |
1023 | ||
1024 | /* | |
1025 | * Delayed P_Key Assigment Interim Support | |
1026 | * | |
1027 | * The following is initial implementation of delayed P_Key assigment | |
1028 | * mechanism. It is using the same approach implemented for the multicast | |
1029 | * group join. The single goal of this implementation is to quickly address | |
1030 | * Bug #2507. This implementation will probably be removed when the P_Key | |
1031 | * change async notification is available. | |
1032 | */ | |
1da177e4 | 1033 | |
c4028958 | 1034 | void ipoib_pkey_poll(struct work_struct *work) |
1da177e4 | 1035 | { |
c4028958 | 1036 | struct ipoib_dev_priv *priv = |
26bbf13c | 1037 | container_of(work, struct ipoib_dev_priv, pkey_poll_task.work); |
c4028958 | 1038 | struct net_device *dev = priv->dev; |
1da177e4 LT |
1039 | |
1040 | ipoib_pkey_dev_check_presence(dev); | |
1041 | ||
1042 | if (test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) | |
1043 | ipoib_open(dev); | |
1044 | else { | |
95ed644f | 1045 | mutex_lock(&pkey_mutex); |
1da177e4 LT |
1046 | if (!test_bit(IPOIB_PKEY_STOP, &priv->flags)) |
1047 | queue_delayed_work(ipoib_workqueue, | |
26bbf13c | 1048 | &priv->pkey_poll_task, |
1da177e4 | 1049 | HZ); |
95ed644f | 1050 | mutex_unlock(&pkey_mutex); |
1da177e4 LT |
1051 | } |
1052 | } | |
1053 | ||
1054 | int ipoib_pkey_dev_delay_open(struct net_device *dev) | |
1055 | { | |
1056 | struct ipoib_dev_priv *priv = netdev_priv(dev); | |
1057 | ||
1058 | /* Look for the interface pkey value in the IB Port P_Key table and */ | |
1059 | /* set the interface pkey assigment flag */ | |
1060 | ipoib_pkey_dev_check_presence(dev); | |
1061 | ||
1062 | /* P_Key value not assigned yet - start polling */ | |
1063 | if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) { | |
95ed644f | 1064 | mutex_lock(&pkey_mutex); |
1da177e4 LT |
1065 | clear_bit(IPOIB_PKEY_STOP, &priv->flags); |
1066 | queue_delayed_work(ipoib_workqueue, | |
26bbf13c | 1067 | &priv->pkey_poll_task, |
1da177e4 | 1068 | HZ); |
95ed644f | 1069 | mutex_unlock(&pkey_mutex); |
1da177e4 LT |
1070 | return 1; |
1071 | } | |
1072 | ||
1073 | return 0; | |
1074 | } |