virtio_net: enable VQs early
[firefly-linux-kernel-4.4.55.git] / drivers / net / virtio_net.c
index 59caa06f34a6b3b17fa3cbce41ea3fb1b08b14a3..aba7b93286b3f243e925be66e3abdef0d970a3da 100644 (file)
@@ -123,9 +123,6 @@ struct virtnet_info {
        /* Host can handle any s/g split between our header and packet data */
        bool any_header_sg;
 
-       /* enable config space updates */
-       bool config_enable;
-
        /* Active statistics */
        struct virtnet_stats __percpu *stats;
 
@@ -135,9 +132,6 @@ struct virtnet_info {
        /* Work struct for config space updates */
        struct work_struct config_work;
 
-       /* Lock for config space updates */
-       struct mutex config_lock;
-
        /* Does the affinity hint is set for virtqueues? */
        bool affinity_hint_set;
 
@@ -1407,13 +1401,9 @@ static void virtnet_config_changed_work(struct work_struct *work)
                container_of(work, struct virtnet_info, config_work);
        u16 v;
 
-       mutex_lock(&vi->config_lock);
-       if (!vi->config_enable)
-               goto done;
-
        if (virtio_cread_feature(vi->vdev, VIRTIO_NET_F_STATUS,
                                 struct virtio_net_config, status, &v) < 0)
-               goto done;
+               return;
 
        if (v & VIRTIO_NET_S_ANNOUNCE) {
                netdev_notify_peers(vi->dev);
@@ -1424,7 +1414,7 @@ static void virtnet_config_changed_work(struct work_struct *work)
        v &= VIRTIO_NET_S_LINK_UP;
 
        if (vi->status == v)
-               goto done;
+               return;
 
        vi->status = v;
 
@@ -1435,8 +1425,6 @@ static void virtnet_config_changed_work(struct work_struct *work)
                netif_carrier_off(vi->dev);
                netif_tx_stop_all_queues(vi->dev);
        }
-done:
-       mutex_unlock(&vi->config_lock);
 }
 
 static void virtnet_config_changed(struct virtio_device *vdev)
@@ -1757,8 +1745,6 @@ static int virtnet_probe(struct virtio_device *vdev)
                u64_stats_init(&virtnet_stats->rx_syncp);
        }
 
-       mutex_init(&vi->config_lock);
-       vi->config_enable = true;
        INIT_WORK(&vi->config_work, virtnet_config_changed_work);
 
        /* If we can receive ANY GSO packets, we must allocate large ones. */
@@ -1806,6 +1792,8 @@ static int virtnet_probe(struct virtio_device *vdev)
                goto free_vqs;
        }
 
+       virtio_device_ready(vdev);
+
        /* Last of all, set up some receive buffers. */
        for (i = 0; i < vi->curr_queue_pairs; i++) {
                try_fill_recv(&vi->rq[i], GFP_KERNEL);
@@ -1875,17 +1863,13 @@ static void virtnet_remove(struct virtio_device *vdev)
 
        unregister_hotcpu_notifier(&vi->nb);
 
-       /* Prevent config work handler from accessing the device. */
-       mutex_lock(&vi->config_lock);
-       vi->config_enable = false;
-       mutex_unlock(&vi->config_lock);
+       /* Make sure no work handler is accessing the device. */
+       flush_work(&vi->config_work);
 
        unregister_netdev(vi->dev);
 
        remove_vq_common(vi);
 
-       flush_work(&vi->config_work);
-
        free_percpu(vi->stats);
        free_netdev(vi->dev);
 }
@@ -1898,10 +1882,8 @@ static int virtnet_freeze(struct virtio_device *vdev)
 
        unregister_hotcpu_notifier(&vi->nb);
 
-       /* Prevent config work handler from accessing the device */
-       mutex_lock(&vi->config_lock);
-       vi->config_enable = false;
-       mutex_unlock(&vi->config_lock);
+       /* Make sure no work handler is accessing the device */
+       flush_work(&vi->config_work);
 
        netif_device_detach(vi->dev);
        cancel_delayed_work_sync(&vi->refill);
@@ -1916,8 +1898,6 @@ static int virtnet_freeze(struct virtio_device *vdev)
 
        remove_vq_common(vi);
 
-       flush_work(&vi->config_work);
-
        return 0;
 }
 
@@ -1941,10 +1921,6 @@ static int virtnet_restore(struct virtio_device *vdev)
 
        netif_device_attach(vi->dev);
 
-       mutex_lock(&vi->config_lock);
-       vi->config_enable = true;
-       mutex_unlock(&vi->config_lock);
-
        rtnl_lock();
        virtnet_set_queues(vi, vi->curr_queue_pairs);
        rtnl_unlock();