linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / infiniband / ulp / ipoib / ipoib_ib.c
index dcd996b..86bcdd7 100644 (file)
@@ -84,9 +84,15 @@ void ipoib_free_ah(struct kref *kref)
 
        unsigned long flags;
 
-       spin_lock_irqsave(&priv->lock, flags);
-       list_add_tail(&ah->list, &priv->dead_ahs);
-       spin_unlock_irqrestore(&priv->lock, flags);
+       if ((int) priv->tx_tail - (int) ah->last_send >= 0) {
+               ipoib_dbg(priv, "Freeing ah %p\n", ah->ah);
+               ib_destroy_ah(ah->ah);
+               kfree(ah);
+       } else {
+               spin_lock_irqsave(&priv->lock, flags);
+               list_add_tail(&ah->list, &priv->dead_ahs);
+               spin_unlock_irqrestore(&priv->lock, flags);
+       }
 }
 
 static int ipoib_ib_post_receive(struct net_device *dev, int id)
@@ -155,7 +161,7 @@ static int ipoib_ib_post_receives(struct net_device *dev)
        struct ipoib_dev_priv *priv = netdev_priv(dev);
        int i;
 
-       for (i = 0; i < ipoib_recvq_size; ++i) {
+       for (i = 0; i < IPOIB_RX_RING_SIZE; ++i) {
                if (ipoib_alloc_rx_skb(dev, i)) {
                        ipoib_warn(priv, "failed to allocate receive buffer %d\n", i);
                        return -ENOMEM;
@@ -181,7 +187,7 @@ static void ipoib_ib_handle_wc(struct net_device *dev,
        if (wr_id & IPOIB_OP_RECV) {
                wr_id &= ~IPOIB_OP_RECV;
 
-               if (wr_id < ipoib_recvq_size) {
+               if (wr_id < IPOIB_RX_RING_SIZE) {
                        struct sk_buff *skb  = priv->rx_ring[wr_id].skb;
                        dma_addr_t      addr = priv->rx_ring[wr_id].mapping;
 
@@ -246,9 +252,9 @@ static void ipoib_ib_handle_wc(struct net_device *dev,
                struct ipoib_tx_buf *tx_req;
                unsigned long flags;
 
-               if (wr_id >= ipoib_sendq_size) {
+               if (wr_id >= IPOIB_TX_RING_SIZE) {
                        ipoib_warn(priv, "completion event with wrid %d (> %d)\n",
-                                  wr_id, ipoib_sendq_size);
+                                  wr_id, IPOIB_TX_RING_SIZE);
                        return;
                }
 
@@ -269,8 +275,7 @@ static void ipoib_ib_handle_wc(struct net_device *dev,
                spin_lock_irqsave(&priv->tx_lock, flags);
                ++priv->tx_tail;
                if (netif_queue_stopped(dev) &&
-                   test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags) &&
-                   priv->tx_head - priv->tx_tail <= ipoib_sendq_size >> 1)
+                   priv->tx_head - priv->tx_tail <= IPOIB_TX_RING_SIZE / 2)
                        netif_wake_queue(dev);
                spin_unlock_irqrestore(&priv->tx_lock, flags);
 
@@ -339,13 +344,13 @@ void ipoib_send(struct net_device *dev, struct sk_buff *skb,
         * means we have to make sure everything is properly recorded and
         * our state is consistent before we call post_send().
         */
-       tx_req = &priv->tx_ring[priv->tx_head & (ipoib_sendq_size - 1)];
+       tx_req = &priv->tx_ring[priv->tx_head & (IPOIB_TX_RING_SIZE - 1)];
        tx_req->skb = skb;
        addr = dma_map_single(priv->ca->dma_device, skb->data, skb->len,
                              DMA_TO_DEVICE);
        pci_unmap_addr_set(tx_req, mapping, addr);
 
-       if (unlikely(post_send(priv, priv->tx_head & (ipoib_sendq_size - 1),
+       if (unlikely(post_send(priv, priv->tx_head & (IPOIB_TX_RING_SIZE - 1),
                               address->ah, qpn, addr, skb->len))) {
                ipoib_warn(priv, "post_send failed\n");
                ++priv->stats.tx_errors;
@@ -358,7 +363,7 @@ void ipoib_send(struct net_device *dev, struct sk_buff *skb,
                address->last_send = priv->tx_head;
                ++priv->tx_head;
 
-               if (priv->tx_head - priv->tx_tail == ipoib_sendq_size) {
+               if (priv->tx_head - priv->tx_tail == IPOIB_TX_RING_SIZE) {
                        ipoib_dbg(priv, "TX ring full, stopping kernel net queue\n");
                        netif_stop_queue(dev);
                }
@@ -371,16 +376,19 @@ static void __ipoib_reap_ah(struct net_device *dev)
        struct ipoib_ah *ah, *tah;
        LIST_HEAD(remove_list);
 
-       spin_lock_irq(&priv->tx_lock);
-       spin_lock(&priv->lock);
+       spin_lock_irq(&priv->lock);
        list_for_each_entry_safe(ah, tah, &priv->dead_ahs, list)
                if ((int) priv->tx_tail - (int) ah->last_send >= 0) {
                        list_del(&ah->list);
-                       ib_destroy_ah(ah->ah);
-                       kfree(ah);
+                       list_add_tail(&ah->list, &remove_list);
                }
-       spin_unlock(&priv->lock);
-       spin_unlock_irq(&priv->tx_lock);
+       spin_unlock_irq(&priv->lock);
+
+       list_for_each_entry_safe(ah, tah, &remove_list, list) {
+               ipoib_dbg(priv, "Reaping ah %p\n", ah->ah);
+               ib_destroy_ah(ah->ah);
+               kfree(ah);
+       }
 }
 
 void ipoib_reap_ah(void *dev_ptr)
@@ -408,46 +416,25 @@ int ipoib_ib_dev_open(struct net_device *dev)
        ret = ipoib_ib_post_receives(dev);
        if (ret) {
                ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret);
-               ipoib_ib_dev_stop(dev);
                return -1;
        }
 
        clear_bit(IPOIB_STOP_REAPER, &priv->flags);
        queue_delayed_work(ipoib_workqueue, &priv->ah_reap_task, HZ);
 
-       set_bit(IPOIB_FLAG_INITIALIZED, &priv->flags);
-
        return 0;
 }
 
-static void ipoib_pkey_dev_check_presence(struct net_device *dev)
-{
-       struct ipoib_dev_priv *priv = netdev_priv(dev);
-       u16 pkey_index = 0;
-
-       if (ib_find_cached_pkey(priv->ca, priv->port, priv->pkey, &pkey_index))
-               clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
-       else
-               set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
-}
-
 int ipoib_ib_dev_up(struct net_device *dev)
 {
        struct ipoib_dev_priv *priv = netdev_priv(dev);
 
-       ipoib_pkey_dev_check_presence(dev);
-
-       if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
-               ipoib_dbg(priv, "PKEY is not assigned.\n");
-               return 0;
-       }
-
        set_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
 
        return ipoib_mcast_start_thread(dev);
 }
 
-int ipoib_ib_dev_down(struct net_device *dev, int flush)
+int ipoib_ib_dev_down(struct net_device *dev)
 {
        struct ipoib_dev_priv *priv = netdev_priv(dev);
 
@@ -462,11 +449,10 @@ int ipoib_ib_dev_down(struct net_device *dev, int flush)
                set_bit(IPOIB_PKEY_STOP, &priv->flags);
                cancel_delayed_work(&priv->pkey_task);
                mutex_unlock(&pkey_mutex);
-               if (flush)
-                       flush_workqueue(ipoib_workqueue);
+               flush_workqueue(ipoib_workqueue);
        }
 
-       ipoib_mcast_stop_thread(dev, flush);
+       ipoib_mcast_stop_thread(dev, 1);
        ipoib_mcast_dev_flush(dev);
 
        ipoib_flush_paths(dev);
@@ -480,7 +466,7 @@ static int recvs_pending(struct net_device *dev)
        int pending = 0;
        int i;
 
-       for (i = 0; i < ipoib_recvq_size; ++i)
+       for (i = 0; i < IPOIB_RX_RING_SIZE; ++i)
                if (priv->rx_ring[i].skb)
                        ++pending;
 
@@ -495,8 +481,6 @@ int ipoib_ib_dev_stop(struct net_device *dev)
        struct ipoib_tx_buf *tx_req;
        int i;
 
-       clear_bit(IPOIB_FLAG_INITIALIZED, &priv->flags);
-
        /*
         * Move our QP to the error state and then reinitialize in
         * when all work requests have completed or have been flushed.
@@ -519,7 +503,7 @@ int ipoib_ib_dev_stop(struct net_device *dev)
                         */
                        while ((int) priv->tx_tail - (int) priv->tx_head < 0) {
                                tx_req = &priv->tx_ring[priv->tx_tail &
-                                                       (ipoib_sendq_size - 1)];
+                                                       (IPOIB_TX_RING_SIZE - 1)];
                                dma_unmap_single(priv->ca->dma_device,
                                                 pci_unmap_addr(tx_req, mapping),
                                                 tx_req->skb->len,
@@ -528,7 +512,7 @@ int ipoib_ib_dev_stop(struct net_device *dev)
                                ++priv->tx_tail;
                        }
 
-                       for (i = 0; i < ipoib_recvq_size; ++i)
+                       for (i = 0; i < IPOIB_RX_RING_SIZE; ++i)
                                if (priv->rx_ring[i].skb) {
                                        dma_unmap_single(priv->ca->dma_device,
                                                         pci_unmap_addr(&priv->rx_ring[i],
@@ -601,34 +585,25 @@ void ipoib_ib_dev_flush(void *_dev)
        struct net_device *dev = (struct net_device *)_dev;
        struct ipoib_dev_priv *priv = netdev_priv(dev), *cpriv;
 
-       if (!test_bit(IPOIB_FLAG_INITIALIZED, &priv->flags) ) {
-               ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_INITIALIZED not set.\n");
-               return;
-       }
-
-       if (!test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) {
-               ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_ADMIN_UP not set.\n");
+       if (!test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
                return;
-       }
 
        ipoib_dbg(priv, "flushing\n");
 
-       ipoib_ib_dev_down(dev, 0);
+       ipoib_ib_dev_down(dev);
 
        /*
         * The device could have been brought down between the start and when
         * we get here, don't bring it back up if it's not configured up
         */
-       if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) {
+       if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
                ipoib_ib_dev_up(dev);
-               ipoib_mcast_restart_task(dev);
-       }
 
        mutex_lock(&priv->vlan_mutex);
 
        /* Flush any child interfaces too */
        list_for_each_entry(cpriv, &priv->child_intfs, list)
-               ipoib_ib_dev_flush(cpriv->dev);
+               ipoib_ib_dev_flush(&cpriv->dev);
 
        mutex_unlock(&priv->vlan_mutex);
 }
@@ -655,6 +630,17 @@ void ipoib_ib_dev_cleanup(struct net_device *dev)
  * change async notification is available.
  */
 
+static void ipoib_pkey_dev_check_presence(struct net_device *dev)
+{
+       struct ipoib_dev_priv *priv = netdev_priv(dev);
+       u16 pkey_index = 0;
+
+       if (ib_find_cached_pkey(priv->ca, priv->port, priv->pkey, &pkey_index))
+               clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
+       else
+               set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
+}
+
 void ipoib_pkey_poll(void *dev_ptr)
 {
        struct net_device *dev = dev_ptr;