Merge branch 'modsplit-Oct31_2011' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-flexiantxendom0-3.2.10.git] / drivers / infiniband / ulp / ipoib / ipoib_cm.c
index 87f9f3e..014504d 100644 (file)
  */
 
 #include <rdma/ib_cm.h>
-#include <rdma/ib_cache.h>
 #include <net/dst.h>
 #include <net/icmp.h>
 #include <linux/icmpv6.h>
 #include <linux/delay.h>
+#include <linux/slab.h>
 #include <linux/vmalloc.h>
+#include <linux/moduleparam.h>
 
 #include "ipoib.h"
 
@@ -84,7 +85,7 @@ static void ipoib_cm_dma_unmap_rx(struct ipoib_dev_priv *priv, int frags,
        ib_dma_unmap_single(priv->ca, mapping[0], IPOIB_CM_HEAD_SIZE, DMA_FROM_DEVICE);
 
        for (i = 0; i < frags; ++i)
-               ib_dma_unmap_single(priv->ca, mapping[i + 1], PAGE_SIZE, DMA_FROM_DEVICE);
+               ib_dma_unmap_page(priv->ca, mapping[i + 1], PAGE_SIZE, DMA_FROM_DEVICE);
 }
 
 static int ipoib_cm_post_receive_srq(struct net_device *dev, int id)
@@ -169,7 +170,7 @@ static struct sk_buff *ipoib_cm_alloc_rx_skb(struct net_device *dev,
                        goto partial_error;
                skb_fill_page_desc(skb, i, page, 0, PAGE_SIZE);
 
-               mapping[i + 1] = ib_dma_map_page(priv->ca, skb_shinfo(skb)->frags[i].page,
+               mapping[i + 1] = ib_dma_map_page(priv->ca, page,
                                                 0, PAGE_SIZE, DMA_FROM_DEVICE);
                if (unlikely(ib_dma_mapping_error(priv->ca, mapping[i + 1])))
                        goto partial_error;
@@ -183,7 +184,7 @@ partial_error:
        ib_dma_unmap_single(priv->ca, mapping[0], IPOIB_CM_HEAD_SIZE, DMA_FROM_DEVICE);
 
        for (; i > 0; --i)
-               ib_dma_unmap_single(priv->ca, mapping[i], PAGE_SIZE, DMA_FROM_DEVICE);
+               ib_dma_unmap_page(priv->ca, mapping[i], PAGE_SIZE, DMA_FROM_DEVICE);
 
        dev_kfree_skb_any(skb);
        return NULL;
@@ -202,7 +203,7 @@ static void ipoib_cm_free_rx_ring(struct net_device *dev,
                        dev_kfree_skb_any(rx_ring[i].skb);
                }
 
-       kfree(rx_ring);
+       vfree(rx_ring);
 }
 
 static void ipoib_cm_start_rx_drain(struct ipoib_dev_priv *priv)
@@ -337,7 +338,7 @@ static void ipoib_cm_init_rx_wr(struct net_device *dev,
                sge[i].length = PAGE_SIZE;
 
        wr->next    = NULL;
-       wr->sg_list = priv->cm.rx_sge;
+       wr->sg_list = sge;
        wr->num_sge = priv->cm.num_frags;
 }
 
@@ -352,9 +353,12 @@ static int ipoib_cm_nonsrq_init_rx(struct net_device *dev, struct ib_cm_id *cm_i
        int ret;
        int i;
 
-       rx->rx_ring = kcalloc(ipoib_recvq_size, sizeof *rx->rx_ring, GFP_KERNEL);
-       if (!rx->rx_ring)
+       rx->rx_ring = vzalloc(ipoib_recvq_size * sizeof *rx->rx_ring);
+       if (!rx->rx_ring) {
+               printk(KERN_WARNING "%s: failed to allocate CM non-SRQ ring (%d entries)\n",
+                      priv->ca->name, ipoib_recvq_size);
                return -ENOMEM;
+       }
 
        t = kmalloc(sizeof *t, GFP_KERNEL);
        if (!t) {
@@ -534,12 +538,13 @@ static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space,
 
                if (length == 0) {
                        /* don't need this page */
-                       skb_fill_page_desc(toskb, i, frag->page, 0, PAGE_SIZE);
+                       skb_fill_page_desc(toskb, i, skb_frag_page(frag),
+                                          0, PAGE_SIZE);
                        --skb_shinfo(skb)->nr_frags;
                } else {
                        size = min(length, (unsigned) PAGE_SIZE);
 
-                       frag->size = size;
+                       skb_frag_size_set(frag, size);
                        skb->data_len += size;
                        skb->truesize += size;
                        skb->len += size;
@@ -658,7 +663,6 @@ copied:
        skb_reset_mac_header(skb);
        skb_pull(skb, IPOIB_ENCAP_LEN);
 
-       dev->last_rx = jiffies;
        ++dev->stats.rx_packets;
        dev->stats.rx_bytes += skb->len;
 
@@ -703,8 +707,9 @@ static inline int post_send(struct ipoib_dev_priv *priv,
 void ipoib_cm_send(struct net_device *dev, struct sk_buff *skb, struct ipoib_cm_tx *tx)
 {
        struct ipoib_dev_priv *priv = netdev_priv(dev);
-       struct ipoib_tx_buf *tx_req;
+       struct ipoib_cm_tx_buf *tx_req;
        u64 addr;
+       int rc;
 
        if (unlikely(skb->len > tx->mtu)) {
                ipoib_warn(priv, "packet len %d (> %d) too long to send, dropping\n",
@@ -734,11 +739,12 @@ void ipoib_cm_send(struct net_device *dev, struct sk_buff *skb, struct ipoib_cm_
                return;
        }
 
-       tx_req->mapping[0] = addr;
+       tx_req->mapping = addr;
 
-       if (unlikely(post_send(priv, tx, tx->tx_head & (ipoib_sendq_size - 1),
-                              addr, skb->len))) {
-               ipoib_warn(priv, "post_send failed\n");
+       rc = post_send(priv, tx, tx->tx_head & (ipoib_sendq_size - 1),
+                      addr, skb->len);
+       if (unlikely(rc)) {
+               ipoib_warn(priv, "post_send failed, error %d\n", rc);
                ++dev->stats.tx_errors;
                ib_dma_unmap_single(priv->ca, addr, skb->len, DMA_TO_DEVICE);
                dev_kfree_skb_any(skb);
@@ -749,6 +755,8 @@ void ipoib_cm_send(struct net_device *dev, struct sk_buff *skb, struct ipoib_cm_
                if (++priv->tx_outstanding == ipoib_sendq_size) {
                        ipoib_dbg(priv, "TX ring 0x%x full, stopping kernel net queue\n",
                                  tx->qp->qp_num);
+                       if (ib_req_notify_cq(priv->send_cq, IB_CQ_NEXT_COMP))
+                               ipoib_warn(priv, "request notify on send CQ failed\n");
                        netif_stop_queue(dev);
                }
        }
@@ -759,7 +767,7 @@ void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
        struct ipoib_dev_priv *priv = netdev_priv(dev);
        struct ipoib_cm_tx *tx = wc->qp->qp_context;
        unsigned int wr_id = wc->wr_id & ~IPOIB_OP_CM;
-       struct ipoib_tx_buf *tx_req;
+       struct ipoib_cm_tx_buf *tx_req;
        unsigned long flags;
 
        ipoib_dbg_data(priv, "cm send completion: id %d, status: %d\n",
@@ -773,7 +781,7 @@ void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
 
        tx_req = &tx->tx_ring[wr_id];
 
-       ib_dma_unmap_single(priv->ca, tx_req->mapping[0], tx_req->skb->len, DMA_TO_DEVICE);
+       ib_dma_unmap_single(priv->ca, tx_req->mapping, tx_req->skb->len, DMA_TO_DEVICE);
 
        /* FIXME: is this right? Shouldn't we only increment on success? */
        ++dev->stats.tx_packets;
@@ -781,7 +789,8 @@ void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
 
        dev_kfree_skb_any(tx_req->skb);
 
-       spin_lock_irqsave(&priv->tx_lock, flags);
+       netif_tx_lock(dev);
+
        ++tx->tx_tail;
        if (unlikely(--priv->tx_outstanding == ipoib_sendq_size >> 1) &&
            netif_queue_stopped(dev) &&
@@ -796,7 +805,7 @@ void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
                           "(status=%d, wrid=%d vend_err %x)\n",
                           wc->status, wr_id, wc->vendor_err);
 
-               spin_lock(&priv->lock);
+               spin_lock_irqsave(&priv->lock, flags);
                neigh = tx->neigh;
 
                if (neigh) {
@@ -816,10 +825,10 @@ void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
 
                clear_bit(IPOIB_FLAG_OPER_UP, &tx->flags);
 
-               spin_unlock(&priv->lock);
+               spin_unlock_irqrestore(&priv->lock, flags);
        }
 
-       spin_unlock_irqrestore(&priv->tx_lock, flags);
+       netif_tx_unlock(dev);
 }
 
 int ipoib_cm_dev_open(struct net_device *dev)
@@ -1088,13 +1097,12 @@ static int ipoib_cm_tx_init(struct ipoib_cm_tx *p, u32 qpn,
        struct ipoib_dev_priv *priv = netdev_priv(p->dev);
        int ret;
 
-       p->tx_ring = vmalloc(ipoib_sendq_size * sizeof *p->tx_ring);
+       p->tx_ring = vzalloc(ipoib_sendq_size * sizeof *p->tx_ring);
        if (!p->tx_ring) {
                ipoib_warn(priv, "failed to allocate tx ring\n");
                ret = -ENOMEM;
                goto err_tx;
        }
-       memset(p->tx_ring, 0, ipoib_sendq_size * sizeof *p->tx_ring);
 
        p->qp = ipoib_cm_create_tx_qp(p->dev, p);
        if (IS_ERR(p->qp)) {
@@ -1122,8 +1130,8 @@ static int ipoib_cm_tx_init(struct ipoib_cm_tx *p, u32 qpn,
                goto err_send_cm;
        }
 
-       ipoib_dbg(priv, "Request connection 0x%x for gid " IPOIB_GID_FMT " qpn 0x%x\n",
-                 p->qp->qp_num, IPOIB_GID_ARG(pathrec->dgid), qpn);
+       ipoib_dbg(priv, "Request connection 0x%x for gid %pI6 qpn 0x%x\n",
+                 p->qp->qp_num, pathrec->dgid.raw, qpn);
 
        return 0;
 
@@ -1143,8 +1151,7 @@ err_tx:
 static void ipoib_cm_tx_destroy(struct ipoib_cm_tx *p)
 {
        struct ipoib_dev_priv *priv = netdev_priv(p->dev);
-       struct ipoib_tx_buf *tx_req;
-       unsigned long flags;
+       struct ipoib_cm_tx_buf *tx_req;
        unsigned long begin;
 
        ipoib_dbg(priv, "Destroy active connection 0x%x head 0x%x tail 0x%x\n",
@@ -1171,16 +1178,16 @@ timeout:
 
        while ((int) p->tx_tail - (int) p->tx_head < 0) {
                tx_req = &p->tx_ring[p->tx_tail & (ipoib_sendq_size - 1)];
-               ib_dma_unmap_single(priv->ca, tx_req->mapping[0], tx_req->skb->len,
+               ib_dma_unmap_single(priv->ca, tx_req->mapping, tx_req->skb->len,
                                    DMA_TO_DEVICE);
                dev_kfree_skb_any(tx_req->skb);
                ++p->tx_tail;
-               spin_lock_irqsave(&priv->tx_lock, flags);
+               netif_tx_lock_bh(p->dev);
                if (unlikely(--priv->tx_outstanding == ipoib_sendq_size >> 1) &&
                    netif_queue_stopped(p->dev) &&
                    test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
                        netif_wake_queue(p->dev);
-               spin_unlock_irqrestore(&priv->tx_lock, flags);
+               netif_tx_unlock_bh(p->dev);
        }
 
        if (p->qp)
@@ -1197,6 +1204,7 @@ static int ipoib_cm_tx_handler(struct ib_cm_id *cm_id,
        struct ipoib_dev_priv *priv = netdev_priv(tx->dev);
        struct net_device *dev = priv->dev;
        struct ipoib_neigh *neigh;
+       unsigned long flags;
        int ret;
 
        switch (event->event) {
@@ -1215,8 +1223,8 @@ static int ipoib_cm_tx_handler(struct ib_cm_id *cm_id,
        case IB_CM_REJ_RECEIVED:
        case IB_CM_TIMEWAIT_EXIT:
                ipoib_dbg(priv, "CM error %d.\n", event->event);
-               spin_lock_irq(&priv->tx_lock);
-               spin_lock(&priv->lock);
+               netif_tx_lock_bh(dev);
+               spin_lock_irqsave(&priv->lock, flags);
                neigh = tx->neigh;
 
                if (neigh) {
@@ -1234,8 +1242,8 @@ static int ipoib_cm_tx_handler(struct ib_cm_id *cm_id,
                        queue_work(ipoib_workqueue, &priv->cm.reap_task);
                }
 
-               spin_unlock(&priv->lock);
-               spin_unlock_irq(&priv->tx_lock);
+               spin_unlock_irqrestore(&priv->lock, flags);
+               netif_tx_unlock_bh(dev);
                break;
        default:
                break;
@@ -1270,8 +1278,8 @@ void ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx)
        if (test_and_clear_bit(IPOIB_FLAG_INITIALIZED, &tx->flags)) {
                list_move(&tx->list, &priv->cm.reap_list);
                queue_work(ipoib_workqueue, &priv->cm.reap_task);
-               ipoib_dbg(priv, "Reap connection for gid " IPOIB_GID_FMT "\n",
-                         IPOIB_GID_ARG(tx->neigh->dgid));
+               ipoib_dbg(priv, "Reap connection for gid %pI6\n",
+                         tx->neigh->dgid.raw);
                tx->neigh = NULL;
        }
 }
@@ -1289,19 +1297,24 @@ static void ipoib_cm_tx_start(struct work_struct *work)
        struct ib_sa_path_rec pathrec;
        u32 qpn;
 
-       spin_lock_irqsave(&priv->tx_lock, flags);
-       spin_lock(&priv->lock);
+       netif_tx_lock_bh(dev);
+       spin_lock_irqsave(&priv->lock, flags);
+
        while (!list_empty(&priv->cm.start_list)) {
                p = list_entry(priv->cm.start_list.next, typeof(*p), list);
                list_del_init(&p->list);
                neigh = p->neigh;
                qpn = IPOIB_QPN(neigh->neighbour->ha);
                memcpy(&pathrec, &p->path->pathrec, sizeof pathrec);
-               spin_unlock(&priv->lock);
-               spin_unlock_irqrestore(&priv->tx_lock, flags);
+
+               spin_unlock_irqrestore(&priv->lock, flags);
+               netif_tx_unlock_bh(dev);
+
                ret = ipoib_cm_tx_init(p, qpn, &pathrec);
-               spin_lock_irqsave(&priv->tx_lock, flags);
-               spin_lock(&priv->lock);
+
+               netif_tx_lock_bh(dev);
+               spin_lock_irqsave(&priv->lock, flags);
+
                if (ret) {
                        neigh = p->neigh;
                        if (neigh) {
@@ -1315,56 +1328,66 @@ static void ipoib_cm_tx_start(struct work_struct *work)
                        kfree(p);
                }
        }
-       spin_unlock(&priv->lock);
-       spin_unlock_irqrestore(&priv->tx_lock, flags);
+
+       spin_unlock_irqrestore(&priv->lock, flags);
+       netif_tx_unlock_bh(dev);
 }
 
 static void ipoib_cm_tx_reap(struct work_struct *work)
 {
        struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv,
                                                   cm.reap_task);
+       struct net_device *dev = priv->dev;
        struct ipoib_cm_tx *p;
+       unsigned long flags;
+
+       netif_tx_lock_bh(dev);
+       spin_lock_irqsave(&priv->lock, flags);
 
-       spin_lock_irq(&priv->tx_lock);
-       spin_lock(&priv->lock);
        while (!list_empty(&priv->cm.reap_list)) {
                p = list_entry(priv->cm.reap_list.next, typeof(*p), list);
                list_del(&p->list);
-               spin_unlock(&priv->lock);
-               spin_unlock_irq(&priv->tx_lock);
+               spin_unlock_irqrestore(&priv->lock, flags);
+               netif_tx_unlock_bh(dev);
                ipoib_cm_tx_destroy(p);
-               spin_lock_irq(&priv->tx_lock);
-               spin_lock(&priv->lock);
+               netif_tx_lock_bh(dev);
+               spin_lock_irqsave(&priv->lock, flags);
        }
-       spin_unlock(&priv->lock);
-       spin_unlock_irq(&priv->tx_lock);
+
+       spin_unlock_irqrestore(&priv->lock, flags);
+       netif_tx_unlock_bh(dev);
 }
 
 static void ipoib_cm_skb_reap(struct work_struct *work)
 {
        struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv,
                                                   cm.skb_task);
+       struct net_device *dev = priv->dev;
        struct sk_buff *skb;
-
+       unsigned long flags;
        unsigned mtu = priv->mcast_mtu;
 
-       spin_lock_irq(&priv->tx_lock);
-       spin_lock(&priv->lock);
+       netif_tx_lock_bh(dev);
+       spin_lock_irqsave(&priv->lock, flags);
+
        while ((skb = skb_dequeue(&priv->cm.skb_queue))) {
-               spin_unlock(&priv->lock);
-               spin_unlock_irq(&priv->tx_lock);
+               spin_unlock_irqrestore(&priv->lock, flags);
+               netif_tx_unlock_bh(dev);
+
                if (skb->protocol == htons(ETH_P_IP))
                        icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
                else if (skb->protocol == htons(ETH_P_IPV6))
-                       icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, priv->dev);
+                       icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
 #endif
                dev_kfree_skb_any(skb);
-               spin_lock_irq(&priv->tx_lock);
-               spin_lock(&priv->lock);
+
+               netif_tx_lock_bh(dev);
+               spin_lock_irqsave(&priv->lock, flags);
        }
-       spin_unlock(&priv->lock);
-       spin_unlock_irq(&priv->tx_lock);
+
+       spin_unlock_irqrestore(&priv->lock, flags);
+       netif_tx_unlock_bh(dev);
 }
 
 void ipoib_cm_skb_too_long(struct net_device *dev, struct sk_buff *skb,
@@ -1373,8 +1396,8 @@ void ipoib_cm_skb_too_long(struct net_device *dev, struct sk_buff *skb,
        struct ipoib_dev_priv *priv = netdev_priv(dev);
        int e = skb_queue_empty(&priv->cm.skb_queue);
 
-       if (skb->dst)
-               skb->dst->ops->update_pmtu(skb->dst, mtu);
+       if (skb_dst(skb))
+               skb_dst(skb)->ops->update_pmtu(skb_dst(skb), mtu);
 
        skb_queue_tail(&priv->cm.skb_queue, skb);
        if (e)
@@ -1434,14 +1457,15 @@ static ssize_t set_mode(struct device *d, struct device_attribute *attr,
        struct net_device *dev = to_net_dev(d);
        struct ipoib_dev_priv *priv = netdev_priv(dev);
 
+       if (!rtnl_trylock())
+               return restart_syscall();
+
        /* flush paths if we switch modes so that connections are restarted */
        if (IPOIB_CM_SUPPORTED(dev->dev_addr) && !strcmp(buf, "connected\n")) {
                set_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
                ipoib_warn(priv, "enabling connected mode "
                           "will cause multicast packet drops\n");
-
-               rtnl_lock();
-               dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_TSO);
+               netdev_update_features(dev);
                rtnl_unlock();
                priv->tx_wr.send_flags &= ~IB_SEND_IP_CSUM;
 
@@ -1451,19 +1475,14 @@ static ssize_t set_mode(struct device *d, struct device_attribute *attr,
 
        if (!strcmp(buf, "datagram\n")) {
                clear_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
-
-               rtnl_lock();
-               if (test_bit(IPOIB_FLAG_CSUM, &priv->flags)) {
-                       dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
-                       if (priv->hca_caps & IB_DEVICE_UD_TSO)
-                               dev->features |= NETIF_F_TSO;
-               }
+               netdev_update_features(dev);
                dev_set_mtu(dev, min(priv->mcast_mtu, dev->mtu));
                rtnl_unlock();
                ipoib_flush_paths(dev);
 
                return count;
        }
+       rtnl_unlock();
 
        return -EINVAL;
 }
@@ -1479,6 +1498,7 @@ static void ipoib_cm_create_srq(struct net_device *dev, int max_sge)
 {
        struct ipoib_dev_priv *priv = netdev_priv(dev);
        struct ib_srq_init_attr srq_init_attr = {
+               .srq_type = IB_SRQT_BASIC,
                .attr = {
                        .max_wr  = ipoib_recvq_size,
                        .max_sge = max_sge
@@ -1494,14 +1514,15 @@ static void ipoib_cm_create_srq(struct net_device *dev, int max_sge)
                return;
        }
 
-       priv->cm.srq_ring = kzalloc(ipoib_recvq_size * sizeof *priv->cm.srq_ring,
-                                   GFP_KERNEL);
+       priv->cm.srq_ring = vzalloc(ipoib_recvq_size * sizeof *priv->cm.srq_ring);
        if (!priv->cm.srq_ring) {
                printk(KERN_WARNING "%s: failed to allocate CM SRQ ring (%d entries)\n",
                       priv->ca->name, ipoib_recvq_size);
                ib_destroy_srq(priv->cm.srq);
                priv->cm.srq = NULL;
+               return;
        }
+
 }
 
 int ipoib_cm_dev_init(struct net_device *dev)