Pull asus into release branch
[pandora-kernel.git] / drivers / infiniband / ulp / ipoib / ipoib_main.c
index af5ee2e..f2a40ae 100644 (file)
@@ -49,8 +49,6 @@
 
 #include <net/dst.h>
 
-#define IPOIB_QPN(ha) (be32_to_cpup((__be32 *) ha) & 0xffffff)
-
 MODULE_AUTHOR("Roland Dreier");
 MODULE_DESCRIPTION("IP-over-InfiniBand net driver");
 MODULE_LICENSE("Dual BSD/GPL");
@@ -145,6 +143,8 @@ static int ipoib_stop(struct net_device *dev)
 
        netif_stop_queue(dev);
 
+       clear_bit(IPOIB_FLAG_NETIF_STOPPED, &priv->flags);
+
        /*
         * Now flush workqueue to make sure a scheduled task doesn't
         * bring our internal state back up.
@@ -178,8 +178,18 @@ static int ipoib_change_mtu(struct net_device *dev, int new_mtu)
 {
        struct ipoib_dev_priv *priv = netdev_priv(dev);
 
-       if (new_mtu > IPOIB_PACKET_SIZE - IPOIB_ENCAP_LEN)
+       /* dev->mtu > 2K ==> connected mode */
+       if (ipoib_cm_admin_enabled(dev) && new_mtu <= IPOIB_CM_MTU) {
+               if (new_mtu > priv->mcast_mtu)
+                       ipoib_warn(priv, "mtu > %d will cause multicast packet drops.\n",
+                                  priv->mcast_mtu);
+               dev->mtu = new_mtu;
+               return 0;
+       }
+
+       if (new_mtu > IPOIB_PACKET_SIZE - IPOIB_ENCAP_LEN) {
                return -EINVAL;
+       }
 
        priv->admin_mtu = new_mtu;
 
@@ -370,12 +380,12 @@ static void path_rec_completion(int status,
        struct net_device *dev = path->dev;
        struct ipoib_dev_priv *priv = netdev_priv(dev);
        struct ipoib_ah *ah = NULL;
-       struct ipoib_neigh *neigh;
+       struct ipoib_neigh *neigh, *tn;
        struct sk_buff_head skqueue;
        struct sk_buff *skb;
        unsigned long flags;
 
-       if (pathrec)
+       if (!status)
                ipoib_dbg(priv, "PathRec LID 0x%04x for GID " IPOIB_GID_FMT "\n",
                          be16_to_cpu(pathrec->dlid), IPOIB_GID_ARG(pathrec->dgid));
        else
@@ -408,12 +418,26 @@ static void path_rec_completion(int status,
                while ((skb = __skb_dequeue(&path->queue)))
                        __skb_queue_tail(&skqueue, skb);
 
-               list_for_each_entry(neigh, &path->neigh_list, list) {
+               list_for_each_entry_safe(neigh, tn, &path->neigh_list, list) {
                        kref_get(&path->ah->ref);
                        neigh->ah = path->ah;
                        memcpy(&neigh->dgid.raw, &path->pathrec.dgid.raw,
                               sizeof(union ib_gid));
 
+                       if (ipoib_cm_enabled(dev, neigh->neighbour)) {
+                               if (!ipoib_cm_get(neigh))
+                                       ipoib_cm_set(neigh, ipoib_cm_create_tx(dev,
+                                                                              path,
+                                                                              neigh));
+                               if (!ipoib_cm_get(neigh)) {
+                                       list_del(&neigh->list);
+                                       if (neigh->ah)
+                                               ipoib_put_ah(neigh->ah);
+                                       ipoib_neigh_free(dev, neigh);
+                                       continue;
+                               }
+                       }
+
                        while ((skb = __skb_dequeue(&neigh->queue)))
                                __skb_queue_tail(&skqueue, skb);
                }
@@ -520,7 +544,25 @@ static void neigh_add_path(struct sk_buff *skb, struct net_device *dev)
                memcpy(&neigh->dgid.raw, &path->pathrec.dgid.raw,
                       sizeof(union ib_gid));
 
-               ipoib_send(dev, skb, path->ah, IPOIB_QPN(skb->dst->neighbour->ha));
+               if (ipoib_cm_enabled(dev, neigh->neighbour)) {
+                       if (!ipoib_cm_get(neigh))
+                               ipoib_cm_set(neigh, ipoib_cm_create_tx(dev, path, neigh));
+                       if (!ipoib_cm_get(neigh)) {
+                               list_del(&neigh->list);
+                               if (neigh->ah)
+                                       ipoib_put_ah(neigh->ah);
+                               ipoib_neigh_free(dev, neigh);
+                               goto err_drop;
+                       }
+                       if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE)
+                               __skb_queue_tail(&neigh->queue, skb);
+                       else {
+                               ipoib_warn(priv, "queue length limit %d. Packet drop.\n",
+                                          skb_queue_len(&neigh->queue));
+                               goto err_drop;
+                       }
+               } else
+                       ipoib_send(dev, skb, path->ah, IPOIB_QPN(skb->dst->neighbour->ha));
        } else {
                neigh->ah  = NULL;
 
@@ -538,6 +580,7 @@ err_list:
 
 err_path:
        ipoib_neigh_free(dev, neigh);
+err_drop:
        ++priv->stats.tx_dropped;
        dev_kfree_skb_any(skb);
 
@@ -640,7 +683,12 @@ static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
                neigh = *to_ipoib_neigh(skb->dst->neighbour);
 
-               if (likely(neigh->ah)) {
+               if (ipoib_cm_get(neigh)) {
+                       if (ipoib_cm_up(neigh)) {
+                               ipoib_cm_send(dev, skb, ipoib_cm_get(neigh));
+                               goto out;
+                       }
+               } else if (neigh->ah) {
                        if (unlikely(memcmp(&neigh->dgid.raw,
                                            skb->dst->neighbour->ha + 4,
                                            sizeof(union ib_gid)))) {
@@ -766,7 +814,7 @@ static void ipoib_set_mcast_list(struct net_device *dev)
        queue_work(ipoib_workqueue, &priv->restart_task);
 }
 
-static void ipoib_neigh_destructor(struct neighbour *n)
+static void ipoib_neigh_cleanup(struct neighbour *n)
 {
        struct ipoib_neigh *neigh;
        struct ipoib_dev_priv *priv = netdev_priv(n->dev);
@@ -774,7 +822,7 @@ static void ipoib_neigh_destructor(struct neighbour *n)
        struct ipoib_ah *ah = NULL;
 
        ipoib_dbg(priv,
-                 "neigh_destructor for %06x " IPOIB_GID_FMT "\n",
+                 "neigh_cleanup for %06x " IPOIB_GID_FMT "\n",
                  IPOIB_QPN(n->ha),
                  IPOIB_GID_RAW_ARG(n->ha + 4));
 
@@ -805,6 +853,7 @@ struct ipoib_neigh *ipoib_neigh_alloc(struct neighbour *neighbour)
        neigh->neighbour = neighbour;
        *to_ipoib_neigh(neighbour) = neigh;
        skb_queue_head_init(&neigh->queue);
+       ipoib_cm_set(neigh, NULL);
 
        return neigh;
 }
@@ -818,12 +867,14 @@ void ipoib_neigh_free(struct net_device *dev, struct ipoib_neigh *neigh)
                ++priv->stats.tx_dropped;
                dev_kfree_skb_any(skb);
        }
+       if (ipoib_cm_get(neigh))
+               ipoib_cm_destroy_tx(ipoib_cm_get(neigh));
        kfree(neigh);
 }
 
 static int ipoib_neigh_setup_dev(struct net_device *dev, struct neigh_parms *parms)
 {
-       parms->neigh_destructor = ipoib_neigh_destructor;
+       parms->neigh_cleanup = ipoib_neigh_cleanup;
 
        return 0;
 }
@@ -1080,6 +1131,8 @@ static struct net_device *ipoib_add_port(const char *format,
 
        ipoib_create_debug_files(priv->dev);
 
+       if (ipoib_cm_add_mode_attr(priv->dev))
+               goto sysfs_failed;
        if (ipoib_add_pkey_attr(priv->dev))
                goto sysfs_failed;
        if (device_create_file(&priv->dev->dev, &dev_attr_create_child))