[PATCH] IB: move include files to include/rdma
[linux-2.6] / drivers / infiniband / ulp / ipoib / ipoib_ib.c
1 /*
2  * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
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.
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
41 #include <rdma/ib_cache.h>
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
53 #define IPOIB_OP_RECV   (1ul << 31)
54
55 static DECLARE_MUTEX(pkey_sem);
56
57 struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
58                                  struct ib_pd *pd, struct ib_ah_attr *attr)
59 {
60         struct ipoib_ah *ah;
61
62         ah = kmalloc(sizeof *ah, GFP_KERNEL);
63         if (!ah)
64                 return NULL;
65
66         ah->dev       = dev;
67         ah->last_send = 0;
68         kref_init(&ah->ref);
69
70         ah->ah = ib_create_ah(pd, attr);
71         if (IS_ERR(ah->ah)) {
72                 kfree(ah);
73                 ah = NULL;
74         } else
75                 ipoib_dbg(netdev_priv(dev), "Created ah %p\n", ah->ah);
76
77         return ah;
78 }
79
80 void ipoib_free_ah(struct kref *kref)
81 {
82         struct ipoib_ah *ah = container_of(kref, struct ipoib_ah, ref);
83         struct ipoib_dev_priv *priv = netdev_priv(ah->dev);
84
85         unsigned long flags;
86
87         if ((int) priv->tx_tail - (int) ah->last_send >= 0) {
88                 ipoib_dbg(priv, "Freeing ah %p\n", ah->ah);
89                 ib_destroy_ah(ah->ah);
90                 kfree(ah);
91         } else {
92                 spin_lock_irqsave(&priv->lock, flags);
93                 list_add_tail(&ah->list, &priv->dead_ahs);
94                 spin_unlock_irqrestore(&priv->lock, flags);
95         }
96 }
97
98 static inline int ipoib_ib_receive(struct ipoib_dev_priv *priv,
99                                    unsigned int wr_id,
100                                    dma_addr_t addr)
101 {
102         struct ib_sge list = {
103                 .addr    = addr,
104                 .length  = IPOIB_BUF_SIZE,
105                 .lkey    = priv->mr->lkey,
106         };
107         struct ib_recv_wr param = {
108                 .wr_id      = wr_id | IPOIB_OP_RECV,
109                 .sg_list    = &list,
110                 .num_sge    = 1,
111         };
112         struct ib_recv_wr *bad_wr;
113
114         return ib_post_recv(priv->qp, &param, &bad_wr);
115 }
116
117 static int ipoib_ib_post_receive(struct net_device *dev, int id)
118 {
119         struct ipoib_dev_priv *priv = netdev_priv(dev);
120         struct sk_buff *skb;
121         dma_addr_t addr;
122         int ret;
123
124         skb = dev_alloc_skb(IPOIB_BUF_SIZE + 4);
125         if (!skb) {
126                 ipoib_warn(priv, "failed to allocate receive buffer\n");
127
128                 priv->rx_ring[id].skb = NULL;
129                 return -ENOMEM;
130         }
131         skb_reserve(skb, 4);    /* 16 byte align IP header */
132         priv->rx_ring[id].skb = skb;
133         addr = dma_map_single(priv->ca->dma_device,
134                               skb->data, IPOIB_BUF_SIZE,
135                               DMA_FROM_DEVICE);
136         pci_unmap_addr_set(&priv->rx_ring[id], mapping, addr);
137
138         ret = ipoib_ib_receive(priv, id, addr);
139         if (ret) {
140                 ipoib_warn(priv, "ipoib_ib_receive failed for buf %d (%d)\n",
141                            id, ret);
142                 dma_unmap_single(priv->ca->dma_device, addr,
143                                  IPOIB_BUF_SIZE, DMA_FROM_DEVICE);
144                 dev_kfree_skb_any(skb);
145                 priv->rx_ring[id].skb = NULL;
146         }
147
148         return ret;
149 }
150
151 static int ipoib_ib_post_receives(struct net_device *dev)
152 {
153         struct ipoib_dev_priv *priv = netdev_priv(dev);
154         int i;
155
156         for (i = 0; i < IPOIB_RX_RING_SIZE; ++i) {
157                 if (ipoib_ib_post_receive(dev, i)) {
158                         ipoib_warn(priv, "ipoib_ib_post_receive failed for buf %d\n", i);
159                         return -EIO;
160                 }
161         }
162
163         return 0;
164 }
165
166 static void ipoib_ib_handle_wc(struct net_device *dev,
167                                struct ib_wc *wc)
168 {
169         struct ipoib_dev_priv *priv = netdev_priv(dev);
170         unsigned int wr_id = wc->wr_id;
171
172         ipoib_dbg_data(priv, "called: id %d, op %d, status: %d\n",
173                        wr_id, wc->opcode, wc->status);
174
175         if (wr_id & IPOIB_OP_RECV) {
176                 wr_id &= ~IPOIB_OP_RECV;
177
178                 if (wr_id < IPOIB_RX_RING_SIZE) {
179                         struct sk_buff *skb = priv->rx_ring[wr_id].skb;
180
181                         priv->rx_ring[wr_id].skb = NULL;
182
183                         dma_unmap_single(priv->ca->dma_device,
184                                          pci_unmap_addr(&priv->rx_ring[wr_id],
185                                                         mapping),
186                                          IPOIB_BUF_SIZE,
187                                          DMA_FROM_DEVICE);
188
189                         if (wc->status != IB_WC_SUCCESS) {
190                                 if (wc->status != IB_WC_WR_FLUSH_ERR)
191                                         ipoib_warn(priv, "failed recv event "
192                                                    "(status=%d, wrid=%d vend_err %x)\n",
193                                                    wc->status, wr_id, wc->vendor_err);
194                                 dev_kfree_skb_any(skb);
195                                 return;
196                         }
197
198                         ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n",
199                                        wc->byte_len, wc->slid);
200
201                         skb_put(skb, wc->byte_len);
202                         skb_pull(skb, IB_GRH_BYTES);
203
204                         if (wc->slid != priv->local_lid ||
205                             wc->src_qp != priv->qp->qp_num) {
206                                 skb->protocol = ((struct ipoib_header *) skb->data)->proto;
207                                 skb->mac.raw = skb->data;
208                                 skb_pull(skb, IPOIB_ENCAP_LEN);
209
210                                 dev->last_rx = jiffies;
211                                 ++priv->stats.rx_packets;
212                                 priv->stats.rx_bytes += skb->len;
213
214                                 skb->dev = dev;
215                                 /* XXX get correct PACKET_ type here */
216                                 skb->pkt_type = PACKET_HOST;
217                                 netif_rx_ni(skb);
218                         } else {
219                                 ipoib_dbg_data(priv, "dropping loopback packet\n");
220                                 dev_kfree_skb_any(skb);
221                         }
222
223                         /* repost receive */
224                         if (ipoib_ib_post_receive(dev, wr_id))
225                                 ipoib_warn(priv, "ipoib_ib_post_receive failed "
226                                            "for buf %d\n", wr_id);
227                 } else
228                         ipoib_warn(priv, "completion event with wrid %d\n",
229                                    wr_id);
230
231         } else {
232                 struct ipoib_buf *tx_req;
233                 unsigned long flags;
234
235                 if (wr_id >= IPOIB_TX_RING_SIZE) {
236                         ipoib_warn(priv, "completion event with wrid %d (> %d)\n",
237                                    wr_id, IPOIB_TX_RING_SIZE);
238                         return;
239                 }
240
241                 ipoib_dbg_data(priv, "send complete, wrid %d\n", wr_id);
242
243                 tx_req = &priv->tx_ring[wr_id];
244
245                 dma_unmap_single(priv->ca->dma_device,
246                                  pci_unmap_addr(tx_req, mapping),
247                                  tx_req->skb->len,
248                                  DMA_TO_DEVICE);
249
250                 ++priv->stats.tx_packets;
251                 priv->stats.tx_bytes += tx_req->skb->len;
252
253                 dev_kfree_skb_any(tx_req->skb);
254
255                 spin_lock_irqsave(&priv->tx_lock, flags);
256                 ++priv->tx_tail;
257                 if (netif_queue_stopped(dev) &&
258                     priv->tx_head - priv->tx_tail <= IPOIB_TX_RING_SIZE / 2)
259                         netif_wake_queue(dev);
260                 spin_unlock_irqrestore(&priv->tx_lock, flags);
261
262                 if (wc->status != IB_WC_SUCCESS &&
263                     wc->status != IB_WC_WR_FLUSH_ERR)
264                         ipoib_warn(priv, "failed send event "
265                                    "(status=%d, wrid=%d vend_err %x)\n",
266                                    wc->status, wr_id, wc->vendor_err);
267         }
268 }
269
270 void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr)
271 {
272         struct net_device *dev = (struct net_device *) dev_ptr;
273         struct ipoib_dev_priv *priv = netdev_priv(dev);
274         int n, i;
275
276         ib_req_notify_cq(cq, IB_CQ_NEXT_COMP);
277         do {
278                 n = ib_poll_cq(cq, IPOIB_NUM_WC, priv->ibwc);
279                 for (i = 0; i < n; ++i)
280                         ipoib_ib_handle_wc(dev, priv->ibwc + i);
281         } while (n == IPOIB_NUM_WC);
282 }
283
284 static inline int post_send(struct ipoib_dev_priv *priv,
285                             unsigned int wr_id,
286                             struct ib_ah *address, u32 qpn,
287                             dma_addr_t addr, int len)
288 {
289         struct ib_send_wr *bad_wr;
290
291         priv->tx_sge.addr             = addr;
292         priv->tx_sge.length           = len;
293
294         priv->tx_wr.wr_id             = wr_id;
295         priv->tx_wr.wr.ud.remote_qpn  = qpn;
296         priv->tx_wr.wr.ud.ah          = address;
297
298         return ib_post_send(priv->qp, &priv->tx_wr, &bad_wr);
299 }
300
301 void ipoib_send(struct net_device *dev, struct sk_buff *skb,
302                 struct ipoib_ah *address, u32 qpn)
303 {
304         struct ipoib_dev_priv *priv = netdev_priv(dev);
305         struct ipoib_buf *tx_req;
306         dma_addr_t addr;
307
308         if (skb->len > dev->mtu + INFINIBAND_ALEN) {
309                 ipoib_warn(priv, "packet len %d (> %d) too long to send, dropping\n",
310                            skb->len, dev->mtu + INFINIBAND_ALEN);
311                 ++priv->stats.tx_dropped;
312                 ++priv->stats.tx_errors;
313                 dev_kfree_skb_any(skb);
314                 return;
315         }
316
317         ipoib_dbg_data(priv, "sending packet, length=%d address=%p qpn=0x%06x\n",
318                        skb->len, address, qpn);
319
320         /*
321          * We put the skb into the tx_ring _before_ we call post_send()
322          * because it's entirely possible that the completion handler will
323          * run before we execute anything after the post_send().  That
324          * means we have to make sure everything is properly recorded and
325          * our state is consistent before we call post_send().
326          */
327         tx_req = &priv->tx_ring[priv->tx_head & (IPOIB_TX_RING_SIZE - 1)];
328         tx_req->skb = skb;
329         addr = dma_map_single(priv->ca->dma_device, skb->data, skb->len,
330                               DMA_TO_DEVICE);
331         pci_unmap_addr_set(tx_req, mapping, addr);
332
333         if (unlikely(post_send(priv, priv->tx_head & (IPOIB_TX_RING_SIZE - 1),
334                                address->ah, qpn, addr, skb->len))) {
335                 ipoib_warn(priv, "post_send failed\n");
336                 ++priv->stats.tx_errors;
337                 dma_unmap_single(priv->ca->dma_device, addr, skb->len,
338                                  DMA_TO_DEVICE);
339                 dev_kfree_skb_any(skb);
340         } else {
341                 dev->trans_start = jiffies;
342
343                 address->last_send = priv->tx_head;
344                 ++priv->tx_head;
345
346                 if (priv->tx_head - priv->tx_tail == IPOIB_TX_RING_SIZE) {
347                         ipoib_dbg(priv, "TX ring full, stopping kernel net queue\n");
348                         netif_stop_queue(dev);
349                 }
350         }
351 }
352
353 static void __ipoib_reap_ah(struct net_device *dev)
354 {
355         struct ipoib_dev_priv *priv = netdev_priv(dev);
356         struct ipoib_ah *ah, *tah;
357         LIST_HEAD(remove_list);
358
359         spin_lock_irq(&priv->lock);
360         list_for_each_entry_safe(ah, tah, &priv->dead_ahs, list)
361                 if ((int) priv->tx_tail - (int) ah->last_send >= 0) {
362                         list_del(&ah->list);
363                         list_add_tail(&ah->list, &remove_list);
364                 }
365         spin_unlock_irq(&priv->lock);
366
367         list_for_each_entry_safe(ah, tah, &remove_list, list) {
368                 ipoib_dbg(priv, "Reaping ah %p\n", ah->ah);
369                 ib_destroy_ah(ah->ah);
370                 kfree(ah);
371         }
372 }
373
374 void ipoib_reap_ah(void *dev_ptr)
375 {
376         struct net_device *dev = dev_ptr;
377         struct ipoib_dev_priv *priv = netdev_priv(dev);
378
379         __ipoib_reap_ah(dev);
380
381         if (!test_bit(IPOIB_STOP_REAPER, &priv->flags))
382                 queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, HZ);
383 }
384
385 int ipoib_ib_dev_open(struct net_device *dev)
386 {
387         struct ipoib_dev_priv *priv = netdev_priv(dev);
388         int ret;
389
390         ret = ipoib_qp_create(dev);
391         if (ret) {
392                 ipoib_warn(priv, "ipoib_qp_create returned %d\n", ret);
393                 return -1;
394         }
395
396         ret = ipoib_ib_post_receives(dev);
397         if (ret) {
398                 ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret);
399                 return -1;
400         }
401
402         clear_bit(IPOIB_STOP_REAPER, &priv->flags);
403         queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, HZ);
404
405         return 0;
406 }
407
408 int ipoib_ib_dev_up(struct net_device *dev)
409 {
410         struct ipoib_dev_priv *priv = netdev_priv(dev);
411
412         set_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
413
414         return ipoib_mcast_start_thread(dev);
415 }
416
417 int ipoib_ib_dev_down(struct net_device *dev)
418 {
419         struct ipoib_dev_priv *priv = netdev_priv(dev);
420
421         ipoib_dbg(priv, "downing ib_dev\n");
422
423         clear_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
424         netif_carrier_off(dev);
425
426         /* Shutdown the P_Key thread if still active */
427         if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
428                 down(&pkey_sem);
429                 set_bit(IPOIB_PKEY_STOP, &priv->flags);
430                 cancel_delayed_work(&priv->pkey_task);
431                 up(&pkey_sem);
432                 flush_workqueue(ipoib_workqueue);
433         }
434
435         ipoib_mcast_stop_thread(dev);
436
437         /*
438          * Flush the multicast groups first so we stop any multicast joins. The
439          * completion thread may have already died and we may deadlock waiting
440          * for the completion thread to finish some multicast joins.
441          */
442         ipoib_mcast_dev_flush(dev);
443
444         /* Delete broadcast and local addresses since they will be recreated */
445         ipoib_mcast_dev_down(dev);
446
447         ipoib_flush_paths(dev);
448
449         return 0;
450 }
451
452 static int recvs_pending(struct net_device *dev)
453 {
454         struct ipoib_dev_priv *priv = netdev_priv(dev);
455         int pending = 0;
456         int i;
457
458         for (i = 0; i < IPOIB_RX_RING_SIZE; ++i)
459                 if (priv->rx_ring[i].skb)
460                         ++pending;
461
462         return pending;
463 }
464
465 int ipoib_ib_dev_stop(struct net_device *dev)
466 {
467         struct ipoib_dev_priv *priv = netdev_priv(dev);
468         struct ib_qp_attr qp_attr;
469         int attr_mask;
470         unsigned long begin;
471         struct ipoib_buf *tx_req;
472         int i;
473
474         /* Kill the existing QP and allocate a new one */
475         qp_attr.qp_state = IB_QPS_ERR;
476         attr_mask        = IB_QP_STATE;
477         if (ib_modify_qp(priv->qp, &qp_attr, attr_mask))
478                 ipoib_warn(priv, "Failed to modify QP to ERROR state\n");
479
480         /* Wait for all sends and receives to complete */
481         begin = jiffies;
482
483         while (priv->tx_head != priv->tx_tail || recvs_pending(dev)) {
484                 if (time_after(jiffies, begin + 5 * HZ)) {
485                         ipoib_warn(priv, "timing out; %d sends %d receives not completed\n",
486                                    priv->tx_head - priv->tx_tail, recvs_pending(dev));
487
488                         /*
489                          * assume the HW is wedged and just free up
490                          * all our pending work requests.
491                          */
492                         while ((int) priv->tx_tail - (int) priv->tx_head < 0) {
493                                 tx_req = &priv->tx_ring[priv->tx_tail &
494                                                         (IPOIB_TX_RING_SIZE - 1)];
495                                 dma_unmap_single(priv->ca->dma_device,
496                                                  pci_unmap_addr(tx_req, mapping),
497                                                  tx_req->skb->len,
498                                                  DMA_TO_DEVICE);
499                                 dev_kfree_skb_any(tx_req->skb);
500                                 ++priv->tx_tail;
501                         }
502
503                         for (i = 0; i < IPOIB_RX_RING_SIZE; ++i)
504                                 if (priv->rx_ring[i].skb) {
505                                         dma_unmap_single(priv->ca->dma_device,
506                                                          pci_unmap_addr(&priv->rx_ring[i],
507                                                                         mapping),
508                                                          IPOIB_BUF_SIZE,
509                                                          DMA_FROM_DEVICE);
510                                         dev_kfree_skb_any(priv->rx_ring[i].skb);
511                                         priv->rx_ring[i].skb = NULL;
512                                 }
513
514                         goto timeout;
515                 }
516
517                 msleep(1);
518         }
519
520         ipoib_dbg(priv, "All sends and receives done.\n");
521
522 timeout:
523         qp_attr.qp_state = IB_QPS_RESET;
524         attr_mask        = IB_QP_STATE;
525         if (ib_modify_qp(priv->qp, &qp_attr, attr_mask))
526                 ipoib_warn(priv, "Failed to modify QP to RESET state\n");
527
528         /* Wait for all AHs to be reaped */
529         set_bit(IPOIB_STOP_REAPER, &priv->flags);
530         cancel_delayed_work(&priv->ah_reap_task);
531         flush_workqueue(ipoib_workqueue);
532
533         begin = jiffies;
534
535         while (!list_empty(&priv->dead_ahs)) {
536                 __ipoib_reap_ah(dev);
537
538                 if (time_after(jiffies, begin + HZ)) {
539                         ipoib_warn(priv, "timing out; will leak address handles\n");
540                         break;
541                 }
542
543                 msleep(1);
544         }
545
546         return 0;
547 }
548
549 int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
550 {
551         struct ipoib_dev_priv *priv = netdev_priv(dev);
552
553         priv->ca = ca;
554         priv->port = port;
555         priv->qp = NULL;
556
557         if (ipoib_transport_dev_init(dev, ca)) {
558                 printk(KERN_WARNING "%s: ipoib_transport_dev_init failed\n", ca->name);
559                 return -ENODEV;
560         }
561
562         if (dev->flags & IFF_UP) {
563                 if (ipoib_ib_dev_open(dev)) {
564                         ipoib_transport_dev_cleanup(dev);
565                         return -ENODEV;
566                 }
567         }
568
569         return 0;
570 }
571
572 void ipoib_ib_dev_flush(void *_dev)
573 {
574         struct net_device *dev = (struct net_device *)_dev;
575         struct ipoib_dev_priv *priv = netdev_priv(dev), *cpriv;
576
577         if (!test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
578                 return;
579
580         ipoib_dbg(priv, "flushing\n");
581
582         ipoib_ib_dev_down(dev);
583
584         /*
585          * The device could have been brought down between the start and when
586          * we get here, don't bring it back up if it's not configured up
587          */
588         if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
589                 ipoib_ib_dev_up(dev);
590
591         /* Flush any child interfaces too */
592         list_for_each_entry(cpriv, &priv->child_intfs, list)
593                 ipoib_ib_dev_flush(&cpriv->dev);
594 }
595
596 void ipoib_ib_dev_cleanup(struct net_device *dev)
597 {
598         struct ipoib_dev_priv *priv = netdev_priv(dev);
599
600         ipoib_dbg(priv, "cleaning up ib_dev\n");
601
602         ipoib_mcast_stop_thread(dev);
603
604         /* Delete the broadcast address and the local address */
605         ipoib_mcast_dev_down(dev);
606
607         ipoib_transport_dev_cleanup(dev);
608 }
609
610 /*
611  * Delayed P_Key Assigment Interim Support
612  *
613  * The following is initial implementation of delayed P_Key assigment
614  * mechanism. It is using the same approach implemented for the multicast
615  * group join. The single goal of this implementation is to quickly address
616  * Bug #2507. This implementation will probably be removed when the P_Key
617  * change async notification is available.
618  */
619 int ipoib_open(struct net_device *dev);
620
621 static void ipoib_pkey_dev_check_presence(struct net_device *dev)
622 {
623         struct ipoib_dev_priv *priv = netdev_priv(dev);
624         u16 pkey_index = 0;
625
626         if (ib_find_cached_pkey(priv->ca, priv->port, priv->pkey, &pkey_index))
627                 clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
628         else
629                 set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
630 }
631
632 void ipoib_pkey_poll(void *dev_ptr)
633 {
634         struct net_device *dev = dev_ptr;
635         struct ipoib_dev_priv *priv = netdev_priv(dev);
636
637         ipoib_pkey_dev_check_presence(dev);
638
639         if (test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags))
640                 ipoib_open(dev);
641         else {
642                 down(&pkey_sem);
643                 if (!test_bit(IPOIB_PKEY_STOP, &priv->flags))
644                         queue_delayed_work(ipoib_workqueue,
645                                            &priv->pkey_task,
646                                            HZ);
647                 up(&pkey_sem);
648         }
649 }
650
651 int ipoib_pkey_dev_delay_open(struct net_device *dev)
652 {
653         struct ipoib_dev_priv *priv = netdev_priv(dev);
654
655         /* Look for the interface pkey value in the IB Port P_Key table and */
656         /* set the interface pkey assigment flag                            */
657         ipoib_pkey_dev_check_presence(dev);
658
659         /* P_Key value not assigned yet - start polling */
660         if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
661                 down(&pkey_sem);
662                 clear_bit(IPOIB_PKEY_STOP, &priv->flags);
663                 queue_delayed_work(ipoib_workqueue,
664                                    &priv->pkey_task,
665                                    HZ);
666                 up(&pkey_sem);
667                 return 1;
668         }
669
670         return 0;
671 }