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