Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[safe/jmp/linux-2.6] / drivers / net / virtio_net.c
index 556512d..6b92e38 100644 (file)
@@ -22,7 +22,6 @@
 #include <linux/ethtool.h>
 #include <linux/module.h>
 #include <linux/virtio.h>
-#include <linux/virtio_ids.h>
 #include <linux/virtio_net.h>
 #include <linux/scatterlist.h>
 #include <linux/if_vlan.h>
@@ -396,8 +395,7 @@ static void refill_work(struct work_struct *work)
 
        vi = container_of(work, struct virtnet_info, refill.work);
        napi_disable(&vi->napi);
-       try_fill_recv(vi, GFP_KERNEL);
-       still_empty = (vi->num == 0);
+       still_empty = !try_fill_recv(vi, GFP_KERNEL);
        napi_enable(&vi->napi);
 
        /* In theory, this can happen: if we don't get any buffers in
@@ -429,8 +427,8 @@ again:
        /* Out of packets? */
        if (received < budget) {
                napi_complete(napi);
-               if (unlikely(!vi->rvq->vq_ops->enable_cb(vi->rvq))
-                   && napi_schedule_prep(napi)) {
+               if (unlikely(!vi->rvq->vq_ops->enable_cb(vi->rvq)) &&
+                   napi_schedule_prep(napi)) {
                        vi->rvq->vq_ops->disable_cb(vi->rvq);
                        __napi_schedule(napi);
                        goto again;
@@ -451,7 +449,7 @@ static unsigned int free_old_xmit_skbs(struct virtnet_info *vi)
                vi->dev->stats.tx_bytes += skb->len;
                vi->dev->stats.tx_packets++;
                tot_sgs += skb_vnet_hdr(skb)->num_sg;
-               kfree_skb(skb);
+               dev_kfree_skb_any(skb);
        }
        return tot_sgs;
 }
@@ -514,8 +512,7 @@ again:
        /* Free up any pending old buffers before queueing new ones. */
        free_old_xmit_skbs(vi);
 
-       /* Put new one in send queue and do transmit */
-       __skb_queue_head(&vi->send, skb);
+       /* Try to transmit */
        capacity = xmit_skb(vi, skb);
 
        /* This can happen with OOM and indirect buffers. */
@@ -529,8 +526,17 @@ again:
                }
                return NETDEV_TX_BUSY;
        }
-
        vi->svq->vq_ops->kick(vi->svq);
+
+       /*
+        * Put new one in send queue.  You'd expect we'd need this before
+        * xmit_skb calls add_buf(), since the callback can be triggered
+        * immediately after that.  But since the callback just triggers
+        * another call back here, normal network xmit locking prevents the
+        * race.
+        */
+       __skb_queue_head(&vi->send, skb);
+
        /* Don't wait up for transmitted skbs to be freed. */
        skb_orphan(skb);
        nf_reset(skb);
@@ -668,6 +674,7 @@ static void virtnet_set_rx_mode(struct net_device *dev)
        struct virtio_net_ctrl_mac *mac_data;
        struct dev_addr_list *addr;
        struct netdev_hw_addr *ha;
+       int uc_count;
        void *buf;
        int i;
 
@@ -694,8 +701,9 @@ static void virtnet_set_rx_mode(struct net_device *dev)
                dev_warn(&dev->dev, "Failed to %sable allmulti mode.\n",
                         allmulti ? "en" : "dis");
 
+       uc_count = netdev_uc_count(dev);
        /* MAC filter - use one buffer for both lists */
-       mac_data = buf = kzalloc(((dev->uc.count + dev->mc_count) * ETH_ALEN) +
+       mac_data = buf = kzalloc(((uc_count + dev->mc_count) * ETH_ALEN) +
                                 (2 * sizeof(mac_data->entries)), GFP_ATOMIC);
        if (!buf) {
                dev_warn(&dev->dev, "No memory for MAC address buffer\n");
@@ -705,16 +713,16 @@ static void virtnet_set_rx_mode(struct net_device *dev)
        sg_init_table(sg, 2);
 
        /* Store the unicast list and count in the front of the buffer */
-       mac_data->entries = dev->uc.count;
+       mac_data->entries = uc_count;
        i = 0;
-       list_for_each_entry(ha, &dev->uc.list, list)
+       netdev_for_each_uc_addr(ha, dev)
                memcpy(&mac_data->macs[i++][0], ha->addr, ETH_ALEN);
 
        sg_set_buf(&sg[0], mac_data,
-                  sizeof(mac_data->entries) + (dev->uc.count * ETH_ALEN));
+                  sizeof(mac_data->entries) + (uc_count * ETH_ALEN));
 
        /* multicast list and count fill the end */
-       mac_data = (void *)&mac_data->macs[dev->uc.count][0];
+       mac_data = (void *)&mac_data->macs[uc_count][0];
 
        mac_data->entries = dev->mc_count;
        addr = dev->mc_list;
@@ -883,9 +891,9 @@ static int virtnet_probe(struct virtio_device *vdev)
        INIT_DELAYED_WORK(&vi->refill, refill_work);
 
        /* If we can receive ANY GSO packets, we must allocate large ones. */
-       if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4)
-           || virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6)
-           || virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN))
+       if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) ||
+           virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6) ||
+           virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN))
                vi->big_packets = true;
 
        if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF))
@@ -988,7 +996,7 @@ static unsigned int features[] = {
        VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN,
 };
 
-static struct virtio_driver virtio_net = {
+static struct virtio_driver virtio_net_driver = {
        .feature_table = features,
        .feature_table_size = ARRAY_SIZE(features),
        .driver.name =  KBUILD_MODNAME,
@@ -1001,12 +1009,12 @@ static struct virtio_driver virtio_net = {
 
 static int __init init(void)
 {
-       return register_virtio_driver(&virtio_net);
+       return register_virtio_driver(&virtio_net_driver);
 }
 
 static void __exit fini(void)
 {
-       unregister_virtio_driver(&virtio_net);
+       unregister_virtio_driver(&virtio_net_driver);
 }
 module_init(init);
 module_exit(fini);