Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. |
Roland Dreier | 2a1d9b7 | 2005-08-10 23:03:10 -0700 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
| 34 | * |
| 35 | * $Id: ipoib_ib.c 1386 2004-12-27 16:23:17Z roland $ |
| 36 | */ |
| 37 | |
| 38 | #include <linux/delay.h> |
| 39 | #include <linux/dma-mapping.h> |
| 40 | |
Roland Dreier | a4d61e8 | 2005-08-25 13:40:04 -0700 | [diff] [blame] | 41 | #include <rdma/ib_cache.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | #include "ipoib.h" |
| 44 | |
| 45 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA |
| 46 | static int data_debug_level; |
| 47 | |
| 48 | module_param(data_debug_level, int, 0644); |
| 49 | MODULE_PARM_DESC(data_debug_level, |
| 50 | "Enable data path debug tracing if > 0"); |
| 51 | #endif |
| 52 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 53 | static DEFINE_MUTEX(pkey_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | struct ipoib_ah *ipoib_create_ah(struct net_device *dev, |
| 56 | struct ib_pd *pd, struct ib_ah_attr *attr) |
| 57 | { |
| 58 | struct ipoib_ah *ah; |
| 59 | |
| 60 | ah = kmalloc(sizeof *ah, GFP_KERNEL); |
| 61 | if (!ah) |
| 62 | return NULL; |
| 63 | |
| 64 | ah->dev = dev; |
| 65 | ah->last_send = 0; |
| 66 | kref_init(&ah->ref); |
| 67 | |
| 68 | ah->ah = ib_create_ah(pd, attr); |
| 69 | if (IS_ERR(ah->ah)) { |
| 70 | kfree(ah); |
| 71 | ah = NULL; |
| 72 | } else |
| 73 | ipoib_dbg(netdev_priv(dev), "Created ah %p\n", ah->ah); |
| 74 | |
| 75 | return ah; |
| 76 | } |
| 77 | |
| 78 | void ipoib_free_ah(struct kref *kref) |
| 79 | { |
| 80 | struct ipoib_ah *ah = container_of(kref, struct ipoib_ah, ref); |
| 81 | struct ipoib_dev_priv *priv = netdev_priv(ah->dev); |
| 82 | |
| 83 | unsigned long flags; |
| 84 | |
Roland Dreier | 31c02e2 | 2006-06-17 20:37:34 -0700 | [diff] [blame] | 85 | spin_lock_irqsave(&priv->lock, flags); |
| 86 | list_add_tail(&ah->list, &priv->dead_ahs); |
| 87 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | static int ipoib_ib_post_receive(struct net_device *dev, int id) |
| 91 | { |
| 92 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Roland Dreier | 1993d68 | 2005-10-28 15:30:34 -0700 | [diff] [blame] | 93 | struct ib_sge list; |
| 94 | struct ib_recv_wr param; |
| 95 | struct ib_recv_wr *bad_wr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | int ret; |
| 97 | |
Roland Dreier | 1993d68 | 2005-10-28 15:30:34 -0700 | [diff] [blame] | 98 | list.addr = priv->rx_ring[id].mapping; |
| 99 | list.length = IPOIB_BUF_SIZE; |
| 100 | list.lkey = priv->mr->lkey; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Roland Dreier | 1993d68 | 2005-10-28 15:30:34 -0700 | [diff] [blame] | 102 | param.next = NULL; |
| 103 | param.wr_id = id | IPOIB_OP_RECV; |
| 104 | param.sg_list = &list; |
| 105 | param.num_sge = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Roland Dreier | 1993d68 | 2005-10-28 15:30:34 -0700 | [diff] [blame] | 107 | ret = ib_post_recv(priv->qp, ¶m, &bad_wr); |
| 108 | if (unlikely(ret)) { |
| 109 | ipoib_warn(priv, "receive failed for buf %d (%d)\n", id, ret); |
Ralph Campbell | 37ccf9d | 2006-12-12 14:30:48 -0800 | [diff] [blame] | 110 | ib_dma_unmap_single(priv->ca, priv->rx_ring[id].mapping, |
| 111 | IPOIB_BUF_SIZE, DMA_FROM_DEVICE); |
Roland Dreier | 1993d68 | 2005-10-28 15:30:34 -0700 | [diff] [blame] | 112 | dev_kfree_skb_any(priv->rx_ring[id].skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | priv->rx_ring[id].skb = NULL; |
| 114 | } |
| 115 | |
| 116 | return ret; |
| 117 | } |
| 118 | |
Roland Dreier | 1993d68 | 2005-10-28 15:30:34 -0700 | [diff] [blame] | 119 | static int ipoib_alloc_rx_skb(struct net_device *dev, int id) |
| 120 | { |
| 121 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 122 | struct sk_buff *skb; |
Ralph Campbell | 37ccf9d | 2006-12-12 14:30:48 -0800 | [diff] [blame] | 123 | u64 addr; |
Roland Dreier | 1993d68 | 2005-10-28 15:30:34 -0700 | [diff] [blame] | 124 | |
| 125 | skb = dev_alloc_skb(IPOIB_BUF_SIZE + 4); |
| 126 | if (!skb) |
| 127 | return -ENOMEM; |
| 128 | |
| 129 | /* |
| 130 | * IB will leave a 40 byte gap for a GRH and IPoIB adds a 4 byte |
| 131 | * header. So we need 4 more bytes to get to 48 and align the |
| 132 | * IP header to a multiple of 16. |
| 133 | */ |
| 134 | skb_reserve(skb, 4); |
| 135 | |
Ralph Campbell | 37ccf9d | 2006-12-12 14:30:48 -0800 | [diff] [blame] | 136 | addr = ib_dma_map_single(priv->ca, skb->data, IPOIB_BUF_SIZE, |
| 137 | DMA_FROM_DEVICE); |
| 138 | if (unlikely(ib_dma_mapping_error(priv->ca, addr))) { |
Roland Dreier | 1993d68 | 2005-10-28 15:30:34 -0700 | [diff] [blame] | 139 | dev_kfree_skb_any(skb); |
| 140 | return -EIO; |
| 141 | } |
| 142 | |
| 143 | priv->rx_ring[id].skb = skb; |
| 144 | priv->rx_ring[id].mapping = addr; |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | static int ipoib_ib_post_receives(struct net_device *dev) |
| 150 | { |
| 151 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 152 | int i; |
| 153 | |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 154 | for (i = 0; i < ipoib_recvq_size; ++i) { |
Roland Dreier | 1993d68 | 2005-10-28 15:30:34 -0700 | [diff] [blame] | 155 | if (ipoib_alloc_rx_skb(dev, i)) { |
| 156 | ipoib_warn(priv, "failed to allocate receive buffer %d\n", i); |
| 157 | return -ENOMEM; |
| 158 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | if (ipoib_ib_post_receive(dev, i)) { |
| 160 | ipoib_warn(priv, "ipoib_ib_post_receive failed for buf %d\n", i); |
| 161 | return -EIO; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
Roland Dreier | 2439a6e | 2006-09-22 15:22:52 -0700 | [diff] [blame] | 168 | static void ipoib_ib_handle_rx_wc(struct net_device *dev, struct ib_wc *wc) |
| 169 | { |
| 170 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 171 | unsigned int wr_id = wc->wr_id & ~IPOIB_OP_RECV; |
| 172 | struct sk_buff *skb; |
Ralph Campbell | 37ccf9d | 2006-12-12 14:30:48 -0800 | [diff] [blame] | 173 | u64 addr; |
Roland Dreier | 2439a6e | 2006-09-22 15:22:52 -0700 | [diff] [blame] | 174 | |
Roland Dreier | a89875f | 2007-04-18 20:20:53 -0700 | [diff] [blame] | 175 | ipoib_dbg_data(priv, "recv completion: id %d, status: %d\n", |
| 176 | wr_id, wc->status); |
Roland Dreier | 2439a6e | 2006-09-22 15:22:52 -0700 | [diff] [blame] | 177 | |
| 178 | if (unlikely(wr_id >= ipoib_recvq_size)) { |
| 179 | ipoib_warn(priv, "recv completion event with wrid %d (> %d)\n", |
| 180 | wr_id, ipoib_recvq_size); |
| 181 | return; |
| 182 | } |
| 183 | |
| 184 | skb = priv->rx_ring[wr_id].skb; |
| 185 | addr = priv->rx_ring[wr_id].mapping; |
| 186 | |
| 187 | if (unlikely(wc->status != IB_WC_SUCCESS)) { |
| 188 | if (wc->status != IB_WC_WR_FLUSH_ERR) |
| 189 | ipoib_warn(priv, "failed recv event " |
| 190 | "(status=%d, wrid=%d vend_err %x)\n", |
| 191 | wc->status, wr_id, wc->vendor_err); |
Ralph Campbell | 37ccf9d | 2006-12-12 14:30:48 -0800 | [diff] [blame] | 192 | ib_dma_unmap_single(priv->ca, addr, |
| 193 | IPOIB_BUF_SIZE, DMA_FROM_DEVICE); |
Roland Dreier | 2439a6e | 2006-09-22 15:22:52 -0700 | [diff] [blame] | 194 | dev_kfree_skb_any(skb); |
| 195 | priv->rx_ring[wr_id].skb = NULL; |
| 196 | return; |
| 197 | } |
| 198 | |
| 199 | /* |
| 200 | * If we can't allocate a new RX buffer, dump |
| 201 | * this packet and reuse the old buffer. |
| 202 | */ |
| 203 | if (unlikely(ipoib_alloc_rx_skb(dev, wr_id))) { |
| 204 | ++priv->stats.rx_dropped; |
| 205 | goto repost; |
| 206 | } |
| 207 | |
| 208 | ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n", |
| 209 | wc->byte_len, wc->slid); |
| 210 | |
Ralph Campbell | 37ccf9d | 2006-12-12 14:30:48 -0800 | [diff] [blame] | 211 | ib_dma_unmap_single(priv->ca, addr, IPOIB_BUF_SIZE, DMA_FROM_DEVICE); |
Roland Dreier | 2439a6e | 2006-09-22 15:22:52 -0700 | [diff] [blame] | 212 | |
| 213 | skb_put(skb, wc->byte_len); |
| 214 | skb_pull(skb, IB_GRH_BYTES); |
| 215 | |
| 216 | if (wc->slid != priv->local_lid || |
| 217 | wc->src_qp != priv->qp->qp_num) { |
| 218 | skb->protocol = ((struct ipoib_header *) skb->data)->proto; |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 219 | skb_reset_mac_header(skb); |
Roland Dreier | 2439a6e | 2006-09-22 15:22:52 -0700 | [diff] [blame] | 220 | skb_pull(skb, IPOIB_ENCAP_LEN); |
| 221 | |
| 222 | dev->last_rx = jiffies; |
| 223 | ++priv->stats.rx_packets; |
| 224 | priv->stats.rx_bytes += skb->len; |
| 225 | |
| 226 | skb->dev = dev; |
| 227 | /* XXX get correct PACKET_ type here */ |
| 228 | skb->pkt_type = PACKET_HOST; |
| 229 | netif_rx_ni(skb); |
| 230 | } else { |
| 231 | ipoib_dbg_data(priv, "dropping loopback packet\n"); |
| 232 | dev_kfree_skb_any(skb); |
| 233 | } |
| 234 | |
| 235 | repost: |
| 236 | if (unlikely(ipoib_ib_post_receive(dev, wr_id))) |
| 237 | ipoib_warn(priv, "ipoib_ib_post_receive failed " |
| 238 | "for buf %d\n", wr_id); |
| 239 | } |
| 240 | |
| 241 | static void ipoib_ib_handle_tx_wc(struct net_device *dev, struct ib_wc *wc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
| 243 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 244 | unsigned int wr_id = wc->wr_id; |
Roland Dreier | 2439a6e | 2006-09-22 15:22:52 -0700 | [diff] [blame] | 245 | struct ipoib_tx_buf *tx_req; |
| 246 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
Roland Dreier | a89875f | 2007-04-18 20:20:53 -0700 | [diff] [blame] | 248 | ipoib_dbg_data(priv, "send completion: id %d, status: %d\n", |
| 249 | wr_id, wc->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
Roland Dreier | 2439a6e | 2006-09-22 15:22:52 -0700 | [diff] [blame] | 251 | if (unlikely(wr_id >= ipoib_sendq_size)) { |
| 252 | ipoib_warn(priv, "send completion event with wrid %d (> %d)\n", |
| 253 | wr_id, ipoib_sendq_size); |
| 254 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
Roland Dreier | 2439a6e | 2006-09-22 15:22:52 -0700 | [diff] [blame] | 256 | |
| 257 | tx_req = &priv->tx_ring[wr_id]; |
| 258 | |
Ralph Campbell | 37ccf9d | 2006-12-12 14:30:48 -0800 | [diff] [blame] | 259 | ib_dma_unmap_single(priv->ca, tx_req->mapping, |
| 260 | tx_req->skb->len, DMA_TO_DEVICE); |
Roland Dreier | 2439a6e | 2006-09-22 15:22:52 -0700 | [diff] [blame] | 261 | |
| 262 | ++priv->stats.tx_packets; |
| 263 | priv->stats.tx_bytes += tx_req->skb->len; |
| 264 | |
| 265 | dev_kfree_skb_any(tx_req->skb); |
| 266 | |
| 267 | spin_lock_irqsave(&priv->tx_lock, flags); |
| 268 | ++priv->tx_tail; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 269 | if (unlikely(test_bit(IPOIB_FLAG_NETIF_STOPPED, &priv->flags)) && |
| 270 | priv->tx_head - priv->tx_tail <= ipoib_sendq_size >> 1) { |
| 271 | clear_bit(IPOIB_FLAG_NETIF_STOPPED, &priv->flags); |
Roland Dreier | 2439a6e | 2006-09-22 15:22:52 -0700 | [diff] [blame] | 272 | netif_wake_queue(dev); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 273 | } |
Roland Dreier | 2439a6e | 2006-09-22 15:22:52 -0700 | [diff] [blame] | 274 | spin_unlock_irqrestore(&priv->tx_lock, flags); |
| 275 | |
| 276 | if (wc->status != IB_WC_SUCCESS && |
| 277 | wc->status != IB_WC_WR_FLUSH_ERR) |
| 278 | ipoib_warn(priv, "failed send event " |
| 279 | "(status=%d, wrid=%d vend_err %x)\n", |
| 280 | wc->status, wr_id, wc->vendor_err); |
| 281 | } |
| 282 | |
| 283 | static void ipoib_ib_handle_wc(struct net_device *dev, struct ib_wc *wc) |
| 284 | { |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 285 | if (wc->wr_id & IPOIB_CM_OP_SRQ) |
| 286 | ipoib_cm_handle_rx_wc(dev, wc); |
| 287 | else if (wc->wr_id & IPOIB_OP_RECV) |
Roland Dreier | 2439a6e | 2006-09-22 15:22:52 -0700 | [diff] [blame] | 288 | ipoib_ib_handle_rx_wc(dev, wc); |
| 289 | else |
| 290 | ipoib_ib_handle_tx_wc(dev, wc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr) |
| 294 | { |
| 295 | struct net_device *dev = (struct net_device *) dev_ptr; |
| 296 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 297 | int n, i; |
| 298 | |
| 299 | ib_req_notify_cq(cq, IB_CQ_NEXT_COMP); |
| 300 | do { |
| 301 | n = ib_poll_cq(cq, IPOIB_NUM_WC, priv->ibwc); |
| 302 | for (i = 0; i < n; ++i) |
| 303 | ipoib_ib_handle_wc(dev, priv->ibwc + i); |
| 304 | } while (n == IPOIB_NUM_WC); |
| 305 | } |
| 306 | |
| 307 | static inline int post_send(struct ipoib_dev_priv *priv, |
| 308 | unsigned int wr_id, |
| 309 | struct ib_ah *address, u32 qpn, |
Ralph Campbell | 37ccf9d | 2006-12-12 14:30:48 -0800 | [diff] [blame] | 310 | u64 addr, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | { |
| 312 | struct ib_send_wr *bad_wr; |
| 313 | |
| 314 | priv->tx_sge.addr = addr; |
| 315 | priv->tx_sge.length = len; |
| 316 | |
| 317 | priv->tx_wr.wr_id = wr_id; |
| 318 | priv->tx_wr.wr.ud.remote_qpn = qpn; |
| 319 | priv->tx_wr.wr.ud.ah = address; |
| 320 | |
| 321 | return ib_post_send(priv->qp, &priv->tx_wr, &bad_wr); |
| 322 | } |
| 323 | |
| 324 | void ipoib_send(struct net_device *dev, struct sk_buff *skb, |
| 325 | struct ipoib_ah *address, u32 qpn) |
| 326 | { |
| 327 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Roland Dreier | 1993d68 | 2005-10-28 15:30:34 -0700 | [diff] [blame] | 328 | struct ipoib_tx_buf *tx_req; |
Ralph Campbell | 37ccf9d | 2006-12-12 14:30:48 -0800 | [diff] [blame] | 329 | u64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Michael S. Tsirkin | 77d8e1e | 2007-03-21 15:45:05 +0200 | [diff] [blame] | 331 | if (unlikely(skb->len > priv->mcast_mtu + IPOIB_ENCAP_LEN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | ipoib_warn(priv, "packet len %d (> %d) too long to send, dropping\n", |
Michael S. Tsirkin | 77d8e1e | 2007-03-21 15:45:05 +0200 | [diff] [blame] | 333 | skb->len, priv->mcast_mtu + IPOIB_ENCAP_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | ++priv->stats.tx_dropped; |
| 335 | ++priv->stats.tx_errors; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 336 | ipoib_cm_skb_too_long(dev, skb, priv->mcast_mtu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | return; |
| 338 | } |
| 339 | |
| 340 | ipoib_dbg_data(priv, "sending packet, length=%d address=%p qpn=0x%06x\n", |
| 341 | skb->len, address, qpn); |
| 342 | |
| 343 | /* |
| 344 | * We put the skb into the tx_ring _before_ we call post_send() |
| 345 | * because it's entirely possible that the completion handler will |
| 346 | * run before we execute anything after the post_send(). That |
| 347 | * means we have to make sure everything is properly recorded and |
| 348 | * our state is consistent before we call post_send(). |
| 349 | */ |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 350 | tx_req = &priv->tx_ring[priv->tx_head & (ipoib_sendq_size - 1)]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | tx_req->skb = skb; |
Ralph Campbell | 37ccf9d | 2006-12-12 14:30:48 -0800 | [diff] [blame] | 352 | addr = ib_dma_map_single(priv->ca, skb->data, skb->len, |
| 353 | DMA_TO_DEVICE); |
| 354 | if (unlikely(ib_dma_mapping_error(priv->ca, addr))) { |
Roland Dreier | 73fbe8b | 2006-10-10 12:50:38 -0700 | [diff] [blame] | 355 | ++priv->stats.tx_errors; |
| 356 | dev_kfree_skb_any(skb); |
| 357 | return; |
| 358 | } |
Ralph Campbell | 37ccf9d | 2006-12-12 14:30:48 -0800 | [diff] [blame] | 359 | tx_req->mapping = addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 361 | if (unlikely(post_send(priv, priv->tx_head & (ipoib_sendq_size - 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | address->ah, qpn, addr, skb->len))) { |
| 363 | ipoib_warn(priv, "post_send failed\n"); |
| 364 | ++priv->stats.tx_errors; |
Ralph Campbell | 37ccf9d | 2006-12-12 14:30:48 -0800 | [diff] [blame] | 365 | ib_dma_unmap_single(priv->ca, addr, skb->len, DMA_TO_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | dev_kfree_skb_any(skb); |
| 367 | } else { |
| 368 | dev->trans_start = jiffies; |
| 369 | |
| 370 | address->last_send = priv->tx_head; |
| 371 | ++priv->tx_head; |
| 372 | |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 373 | if (priv->tx_head - priv->tx_tail == ipoib_sendq_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | ipoib_dbg(priv, "TX ring full, stopping kernel net queue\n"); |
| 375 | netif_stop_queue(dev); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 376 | set_bit(IPOIB_FLAG_NETIF_STOPPED, &priv->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | static void __ipoib_reap_ah(struct net_device *dev) |
| 382 | { |
| 383 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 384 | struct ipoib_ah *ah, *tah; |
| 385 | LIST_HEAD(remove_list); |
| 386 | |
Roland Dreier | 31c02e2 | 2006-06-17 20:37:34 -0700 | [diff] [blame] | 387 | spin_lock_irq(&priv->tx_lock); |
| 388 | spin_lock(&priv->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | list_for_each_entry_safe(ah, tah, &priv->dead_ahs, list) |
Roland Dreier | 2181858 | 2005-07-27 14:41:32 -0700 | [diff] [blame] | 390 | if ((int) priv->tx_tail - (int) ah->last_send >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | list_del(&ah->list); |
Roland Dreier | 31c02e2 | 2006-06-17 20:37:34 -0700 | [diff] [blame] | 392 | ib_destroy_ah(ah->ah); |
| 393 | kfree(ah); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
Roland Dreier | 31c02e2 | 2006-06-17 20:37:34 -0700 | [diff] [blame] | 395 | spin_unlock(&priv->lock); |
| 396 | spin_unlock_irq(&priv->tx_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | } |
| 398 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 399 | void ipoib_reap_ah(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 401 | struct ipoib_dev_priv *priv = |
| 402 | container_of(work, struct ipoib_dev_priv, ah_reap_task.work); |
| 403 | struct net_device *dev = priv->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
| 405 | __ipoib_reap_ah(dev); |
| 406 | |
| 407 | if (!test_bit(IPOIB_STOP_REAPER, &priv->flags)) |
| 408 | queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, HZ); |
| 409 | } |
| 410 | |
| 411 | int ipoib_ib_dev_open(struct net_device *dev) |
| 412 | { |
| 413 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 414 | int ret; |
| 415 | |
Roland Dreier | 5b6810e | 2005-10-11 11:08:24 -0700 | [diff] [blame] | 416 | ret = ipoib_init_qp(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | if (ret) { |
Roland Dreier | 5b6810e | 2005-10-11 11:08:24 -0700 | [diff] [blame] | 418 | ipoib_warn(priv, "ipoib_init_qp returned %d\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | return -1; |
| 420 | } |
| 421 | |
| 422 | ret = ipoib_ib_post_receives(dev); |
| 423 | if (ret) { |
| 424 | ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret); |
Eli Cohen | 54d07e2 | 2006-03-02 11:05:19 -0800 | [diff] [blame] | 425 | ipoib_ib_dev_stop(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | return -1; |
| 427 | } |
| 428 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 429 | ret = ipoib_cm_dev_open(dev); |
| 430 | if (ret) { |
| 431 | ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret); |
| 432 | ipoib_ib_dev_stop(dev); |
| 433 | return -1; |
| 434 | } |
| 435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | clear_bit(IPOIB_STOP_REAPER, &priv->flags); |
| 437 | queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, HZ); |
| 438 | |
Leonid Arsh | 7a343d4 | 2006-03-23 19:52:51 +0200 | [diff] [blame] | 439 | set_bit(IPOIB_FLAG_INITIALIZED, &priv->flags); |
| 440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | return 0; |
| 442 | } |
| 443 | |
Leonid Arsh | 7a343d4 | 2006-03-23 19:52:51 +0200 | [diff] [blame] | 444 | static void ipoib_pkey_dev_check_presence(struct net_device *dev) |
| 445 | { |
| 446 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 447 | u16 pkey_index = 0; |
| 448 | |
| 449 | if (ib_find_cached_pkey(priv->ca, priv->port, priv->pkey, &pkey_index)) |
| 450 | clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags); |
| 451 | else |
| 452 | set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags); |
| 453 | } |
| 454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | int ipoib_ib_dev_up(struct net_device *dev) |
| 456 | { |
| 457 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 458 | |
Leonid Arsh | 7a343d4 | 2006-03-23 19:52:51 +0200 | [diff] [blame] | 459 | ipoib_pkey_dev_check_presence(dev); |
| 460 | |
| 461 | if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) { |
| 462 | ipoib_dbg(priv, "PKEY is not assigned.\n"); |
| 463 | return 0; |
| 464 | } |
| 465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | set_bit(IPOIB_FLAG_OPER_UP, &priv->flags); |
| 467 | |
| 468 | return ipoib_mcast_start_thread(dev); |
| 469 | } |
| 470 | |
Jack Morgenstein | 0b3ea08 | 2006-03-20 10:08:24 -0800 | [diff] [blame] | 471 | int ipoib_ib_dev_down(struct net_device *dev, int flush) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | { |
| 473 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 474 | |
| 475 | ipoib_dbg(priv, "downing ib_dev\n"); |
| 476 | |
| 477 | clear_bit(IPOIB_FLAG_OPER_UP, &priv->flags); |
| 478 | netif_carrier_off(dev); |
| 479 | |
| 480 | /* Shutdown the P_Key thread if still active */ |
| 481 | if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) { |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 482 | mutex_lock(&pkey_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | set_bit(IPOIB_PKEY_STOP, &priv->flags); |
| 484 | cancel_delayed_work(&priv->pkey_task); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 485 | mutex_unlock(&pkey_mutex); |
Jack Morgenstein | 0b3ea08 | 2006-03-20 10:08:24 -0800 | [diff] [blame] | 486 | if (flush) |
| 487 | flush_workqueue(ipoib_workqueue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Jack Morgenstein | 0b3ea08 | 2006-03-20 10:08:24 -0800 | [diff] [blame] | 490 | ipoib_mcast_stop_thread(dev, flush); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | ipoib_mcast_dev_flush(dev); |
| 492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | ipoib_flush_paths(dev); |
| 494 | |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | static int recvs_pending(struct net_device *dev) |
| 499 | { |
| 500 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 501 | int pending = 0; |
| 502 | int i; |
| 503 | |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 504 | for (i = 0; i < ipoib_recvq_size; ++i) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | if (priv->rx_ring[i].skb) |
| 506 | ++pending; |
| 507 | |
| 508 | return pending; |
| 509 | } |
| 510 | |
| 511 | int ipoib_ib_dev_stop(struct net_device *dev) |
| 512 | { |
| 513 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 514 | struct ib_qp_attr qp_attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | unsigned long begin; |
Roland Dreier | 1993d68 | 2005-10-28 15:30:34 -0700 | [diff] [blame] | 516 | struct ipoib_tx_buf *tx_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | int i; |
| 518 | |
Leonid Arsh | 7a343d4 | 2006-03-23 19:52:51 +0200 | [diff] [blame] | 519 | clear_bit(IPOIB_FLAG_INITIALIZED, &priv->flags); |
| 520 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 521 | ipoib_cm_dev_stop(dev); |
| 522 | |
Roland Dreier | 3bc12e7 | 2005-10-30 13:20:09 -0800 | [diff] [blame] | 523 | /* |
| 524 | * Move our QP to the error state and then reinitialize in |
| 525 | * when all work requests have completed or have been flushed. |
| 526 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | qp_attr.qp_state = IB_QPS_ERR; |
Roland Dreier | 3bc12e7 | 2005-10-30 13:20:09 -0800 | [diff] [blame] | 528 | if (ib_modify_qp(priv->qp, &qp_attr, IB_QP_STATE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | ipoib_warn(priv, "Failed to modify QP to ERROR state\n"); |
| 530 | |
| 531 | /* Wait for all sends and receives to complete */ |
| 532 | begin = jiffies; |
| 533 | |
| 534 | while (priv->tx_head != priv->tx_tail || recvs_pending(dev)) { |
| 535 | if (time_after(jiffies, begin + 5 * HZ)) { |
| 536 | ipoib_warn(priv, "timing out; %d sends %d receives not completed\n", |
| 537 | priv->tx_head - priv->tx_tail, recvs_pending(dev)); |
| 538 | |
| 539 | /* |
| 540 | * assume the HW is wedged and just free up |
| 541 | * all our pending work requests. |
| 542 | */ |
Roland Dreier | 2181858 | 2005-07-27 14:41:32 -0700 | [diff] [blame] | 543 | while ((int) priv->tx_tail - (int) priv->tx_head < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | tx_req = &priv->tx_ring[priv->tx_tail & |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 545 | (ipoib_sendq_size - 1)]; |
Ralph Campbell | 37ccf9d | 2006-12-12 14:30:48 -0800 | [diff] [blame] | 546 | ib_dma_unmap_single(priv->ca, |
| 547 | tx_req->mapping, |
| 548 | tx_req->skb->len, |
| 549 | DMA_TO_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | dev_kfree_skb_any(tx_req->skb); |
| 551 | ++priv->tx_tail; |
| 552 | } |
| 553 | |
Ralph Campbell | 37ccf9d | 2006-12-12 14:30:48 -0800 | [diff] [blame] | 554 | for (i = 0; i < ipoib_recvq_size; ++i) { |
| 555 | struct ipoib_rx_buf *rx_req; |
| 556 | |
| 557 | rx_req = &priv->rx_ring[i]; |
| 558 | if (!rx_req->skb) |
| 559 | continue; |
| 560 | ib_dma_unmap_single(priv->ca, |
| 561 | rx_req->mapping, |
| 562 | IPOIB_BUF_SIZE, |
| 563 | DMA_FROM_DEVICE); |
| 564 | dev_kfree_skb_any(rx_req->skb); |
| 565 | rx_req->skb = NULL; |
| 566 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
| 568 | goto timeout; |
| 569 | } |
| 570 | |
| 571 | msleep(1); |
| 572 | } |
| 573 | |
| 574 | ipoib_dbg(priv, "All sends and receives done.\n"); |
| 575 | |
| 576 | timeout: |
| 577 | qp_attr.qp_state = IB_QPS_RESET; |
Roland Dreier | 3bc12e7 | 2005-10-30 13:20:09 -0800 | [diff] [blame] | 578 | if (ib_modify_qp(priv->qp, &qp_attr, IB_QP_STATE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | ipoib_warn(priv, "Failed to modify QP to RESET state\n"); |
| 580 | |
| 581 | /* Wait for all AHs to be reaped */ |
| 582 | set_bit(IPOIB_STOP_REAPER, &priv->flags); |
| 583 | cancel_delayed_work(&priv->ah_reap_task); |
| 584 | flush_workqueue(ipoib_workqueue); |
| 585 | |
| 586 | begin = jiffies; |
| 587 | |
| 588 | while (!list_empty(&priv->dead_ahs)) { |
| 589 | __ipoib_reap_ah(dev); |
| 590 | |
| 591 | if (time_after(jiffies, begin + HZ)) { |
| 592 | ipoib_warn(priv, "timing out; will leak address handles\n"); |
| 593 | break; |
| 594 | } |
| 595 | |
| 596 | msleep(1); |
| 597 | } |
| 598 | |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port) |
| 603 | { |
| 604 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 605 | |
| 606 | priv->ca = ca; |
| 607 | priv->port = port; |
| 608 | priv->qp = NULL; |
| 609 | |
| 610 | if (ipoib_transport_dev_init(dev, ca)) { |
| 611 | printk(KERN_WARNING "%s: ipoib_transport_dev_init failed\n", ca->name); |
| 612 | return -ENODEV; |
| 613 | } |
| 614 | |
| 615 | if (dev->flags & IFF_UP) { |
| 616 | if (ipoib_ib_dev_open(dev)) { |
| 617 | ipoib_transport_dev_cleanup(dev); |
| 618 | return -ENODEV; |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | return 0; |
| 623 | } |
| 624 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 625 | void ipoib_ib_dev_flush(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 627 | struct ipoib_dev_priv *cpriv, *priv = |
| 628 | container_of(work, struct ipoib_dev_priv, flush_task); |
| 629 | struct net_device *dev = priv->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
Leonid Arsh | 7a343d4 | 2006-03-23 19:52:51 +0200 | [diff] [blame] | 631 | if (!test_bit(IPOIB_FLAG_INITIALIZED, &priv->flags) ) { |
| 632 | ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_INITIALIZED not set.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | return; |
Leonid Arsh | 7a343d4 | 2006-03-23 19:52:51 +0200 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | if (!test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) { |
| 637 | ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_ADMIN_UP not set.\n"); |
| 638 | return; |
| 639 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
| 641 | ipoib_dbg(priv, "flushing\n"); |
| 642 | |
Jack Morgenstein | 0b3ea08 | 2006-03-20 10:08:24 -0800 | [diff] [blame] | 643 | ipoib_ib_dev_down(dev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
| 645 | /* |
| 646 | * The device could have been brought down between the start and when |
| 647 | * we get here, don't bring it back up if it's not configured up |
| 648 | */ |
Eli Cohen | 5ccd025 | 2006-09-22 15:22:56 -0700 | [diff] [blame] | 649 | if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | ipoib_ib_dev_up(dev); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 651 | ipoib_mcast_restart_task(&priv->restart_task); |
Eli Cohen | 5ccd025 | 2006-09-22 15:22:56 -0700 | [diff] [blame] | 652 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 654 | mutex_lock(&priv->vlan_mutex); |
Michael S. Tsirkin | 4f71055 | 2005-11-29 10:53:30 -0800 | [diff] [blame] | 655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | /* Flush any child interfaces too */ |
| 657 | list_for_each_entry(cpriv, &priv->child_intfs, list) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 658 | ipoib_ib_dev_flush(&cpriv->flush_task); |
Michael S. Tsirkin | 4f71055 | 2005-11-29 10:53:30 -0800 | [diff] [blame] | 659 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 660 | mutex_unlock(&priv->vlan_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | void ipoib_ib_dev_cleanup(struct net_device *dev) |
| 664 | { |
| 665 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 666 | |
| 667 | ipoib_dbg(priv, "cleaning up ib_dev\n"); |
| 668 | |
Roland Dreier | 8d2cae0 | 2005-09-20 10:52:04 -0700 | [diff] [blame] | 669 | ipoib_mcast_stop_thread(dev, 1); |
Eli Cohen | 988bd50 | 2006-01-12 14:32:20 -0800 | [diff] [blame] | 670 | ipoib_mcast_dev_flush(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
| 672 | ipoib_transport_dev_cleanup(dev); |
| 673 | } |
| 674 | |
| 675 | /* |
| 676 | * Delayed P_Key Assigment Interim Support |
| 677 | * |
| 678 | * The following is initial implementation of delayed P_Key assigment |
| 679 | * mechanism. It is using the same approach implemented for the multicast |
| 680 | * group join. The single goal of this implementation is to quickly address |
| 681 | * Bug #2507. This implementation will probably be removed when the P_Key |
| 682 | * change async notification is available. |
| 683 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 685 | void ipoib_pkey_poll(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 687 | struct ipoib_dev_priv *priv = |
| 688 | container_of(work, struct ipoib_dev_priv, pkey_task.work); |
| 689 | struct net_device *dev = priv->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
| 691 | ipoib_pkey_dev_check_presence(dev); |
| 692 | |
| 693 | if (test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) |
| 694 | ipoib_open(dev); |
| 695 | else { |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 696 | mutex_lock(&pkey_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | if (!test_bit(IPOIB_PKEY_STOP, &priv->flags)) |
| 698 | queue_delayed_work(ipoib_workqueue, |
| 699 | &priv->pkey_task, |
| 700 | HZ); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 701 | mutex_unlock(&pkey_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | |
| 705 | int ipoib_pkey_dev_delay_open(struct net_device *dev) |
| 706 | { |
| 707 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 708 | |
| 709 | /* Look for the interface pkey value in the IB Port P_Key table and */ |
| 710 | /* set the interface pkey assigment flag */ |
| 711 | ipoib_pkey_dev_check_presence(dev); |
| 712 | |
| 713 | /* P_Key value not assigned yet - start polling */ |
| 714 | if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) { |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 715 | mutex_lock(&pkey_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | clear_bit(IPOIB_PKEY_STOP, &priv->flags); |
| 717 | queue_delayed_work(ipoib_workqueue, |
| 718 | &priv->pkey_task, |
| 719 | HZ); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 720 | mutex_unlock(&pkey_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | return 1; |
| 722 | } |
| 723 | |
| 724 | return 0; |
| 725 | } |