From 30683a8cce8019aa4314c37e629da5c185017166 Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Thu, 11 Dec 2014 13:37:13 +0200 Subject: virtio: set VIRTIO_CONFIG_S_FEATURES_OK on restore virtio 1.0 devices require that drivers set VIRTIO_CONFIG_S_FEATURES_OK after finalizing features. virtio core missed doing this on restore, fix it up. Signed-off-by: Michael S. Tsirkin Reviewed-by: Cornelia Huck --- drivers/virtio/virtio.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'drivers/virtio') diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index f22665868781..b9f70dfc4751 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -162,6 +162,27 @@ static void virtio_config_enable(struct virtio_device *dev) spin_unlock_irq(&dev->config_lock); } +static int virtio_finalize_features(struct virtio_device *dev) +{ + int ret = dev->config->finalize_features(dev); + unsigned status; + + if (ret) + return ret; + + if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) + return 0; + + add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); + status = dev->config->get_status(dev); + if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) { + dev_err(&dev->dev, "virtio: device refuses features: %x\n", + status); + return -ENODEV; + } + return 0; +} + static int virtio_dev_probe(struct device *_d) { int err, i; @@ -170,7 +191,6 @@ static int virtio_dev_probe(struct device *_d) u64 device_features; u64 driver_features; u64 driver_features_legacy; - unsigned status; /* We have a driver! */ add_status(dev, VIRTIO_CONFIG_S_DRIVER); @@ -208,21 +228,10 @@ static int virtio_dev_probe(struct device *_d) if (device_features & (1ULL << i)) __virtio_set_bit(dev, i); - err = dev->config->finalize_features(dev); + err = virtio_finalize_features(dev); if (err) goto err; - if (virtio_has_feature(dev, VIRTIO_F_VERSION_1)) { - add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); - status = dev->config->get_status(dev); - if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) { - dev_err(_d, "virtio: device refuses features: %x\n", - status); - err = -ENODEV; - goto err; - } - } - err = drv->probe(dev); if (err) goto err; @@ -372,7 +381,7 @@ int virtio_device_restore(struct virtio_device *dev) /* We have a driver! */ add_status(dev, VIRTIO_CONFIG_S_DRIVER); - ret = dev->config->finalize_features(dev); + ret = virtio_finalize_features(dev); if (ret) goto err; -- cgit v1.2.3 From de2b48d581e522298eefa9c75abdcd87549a2465 Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Thu, 11 Dec 2014 14:13:16 +0200 Subject: virtio_pci_common.h: drop VIRTIO_PCI_NO_LEGACY Legacy drivers use virtio_pci_common.h too, we should not define VIRTIO_PCI_NO_LEGACY there. Signed-off-by: Michael S. Tsirkin --- drivers/virtio/virtio_pci_common.h | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/virtio') diff --git a/drivers/virtio/virtio_pci_common.h b/drivers/virtio/virtio_pci_common.h index d840dad4149d..38d99adcc74a 100644 --- a/drivers/virtio/virtio_pci_common.h +++ b/drivers/virtio/virtio_pci_common.h @@ -27,7 +27,6 @@ #include #include #include -#define VIRTIO_PCI_NO_LEGACY #include #include #include -- cgit v1.2.3 From 9a4253db0c4ea1b6b15aa289203bc0584298278e Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Thu, 11 Dec 2014 21:47:49 +0200 Subject: virtio_pci: move probe to common file It turns out this make everything easier. Signed-off-by: Michael S. Tsirkin --- drivers/virtio/virtio_pci_common.c | 34 +++++++++++++++++++++++++++++++++- drivers/virtio/virtio_pci_common.h | 6 +++--- drivers/virtio/virtio_pci_legacy.c | 24 ++---------------------- 3 files changed, 38 insertions(+), 26 deletions(-) (limited to 'drivers/virtio') diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c index 953057d84185..59d3685c31b4 100644 --- a/drivers/virtio/virtio_pci_common.c +++ b/drivers/virtio/virtio_pci_common.c @@ -458,7 +458,39 @@ static int virtio_pci_restore(struct device *dev) return virtio_device_restore(&vp_dev->vdev); } -const struct dev_pm_ops virtio_pci_pm_ops = { +static const struct dev_pm_ops virtio_pci_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(virtio_pci_freeze, virtio_pci_restore) }; #endif + + +/* Qumranet donated their vendor ID for devices 0x1000 thru 0x10FF. */ +static const struct pci_device_id virtio_pci_id_table[] = { + { PCI_DEVICE(0x1af4, PCI_ANY_ID) }, + { 0 } +}; + +MODULE_DEVICE_TABLE(pci, virtio_pci_id_table); + +static int virtio_pci_probe(struct pci_dev *pci_dev, + const struct pci_device_id *id) +{ + return virtio_pci_legacy_probe(pci_dev, id); +} + +static void virtio_pci_remove(struct pci_dev *pci_dev) +{ + virtio_pci_legacy_remove(pci_dev); +} + +static struct pci_driver virtio_pci_driver = { + .name = "virtio-pci", + .id_table = virtio_pci_id_table, + .probe = virtio_pci_probe, + .remove = virtio_pci_remove, +#ifdef CONFIG_PM_SLEEP + .driver.pm = &virtio_pci_pm_ops, +#endif +}; + +module_pci_driver(virtio_pci_driver); diff --git a/drivers/virtio/virtio_pci_common.h b/drivers/virtio/virtio_pci_common.h index 38d99adcc74a..adddb647b21d 100644 --- a/drivers/virtio/virtio_pci_common.h +++ b/drivers/virtio/virtio_pci_common.h @@ -128,8 +128,8 @@ const char *vp_bus_name(struct virtio_device *vdev); int vp_set_vq_affinity(struct virtqueue *vq, int cpu); void virtio_pci_release_dev(struct device *); -#ifdef CONFIG_PM_SLEEP -extern const struct dev_pm_ops virtio_pci_pm_ops; -#endif +int virtio_pci_legacy_probe(struct pci_dev *pci_dev, + const struct pci_device_id *id); +void virtio_pci_legacy_remove(struct pci_dev *pci_dev); #endif diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c index 2588252e5c1c..6c76f0f5658c 100644 --- a/drivers/virtio/virtio_pci_legacy.c +++ b/drivers/virtio/virtio_pci_legacy.c @@ -19,14 +19,6 @@ #include "virtio_pci_common.h" -/* Qumranet donated their vendor ID for devices 0x1000 thru 0x10FF. */ -static const struct pci_device_id virtio_pci_id_table[] = { - { PCI_DEVICE(0x1af4, PCI_ANY_ID) }, - { 0 } -}; - -MODULE_DEVICE_TABLE(pci, virtio_pci_id_table); - /* virtio config->get_features() implementation */ static u64 vp_get_features(struct virtio_device *vdev) { @@ -220,7 +212,7 @@ static const struct virtio_config_ops virtio_pci_config_ops = { }; /* the PCI probing function */ -static int virtio_pci_probe(struct pci_dev *pci_dev, +int virtio_pci_legacy_probe(struct pci_dev *pci_dev, const struct pci_device_id *id) { struct virtio_pci_device *vp_dev; @@ -300,7 +292,7 @@ out: return err; } -static void virtio_pci_remove(struct pci_dev *pci_dev) +void virtio_pci_legacy_remove(struct pci_dev *pci_dev) { struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev); @@ -312,15 +304,3 @@ static void virtio_pci_remove(struct pci_dev *pci_dev) pci_disable_device(pci_dev); kfree(vp_dev); } - -static struct pci_driver virtio_pci_driver = { - .name = "virtio-pci", - .id_table = virtio_pci_id_table, - .probe = virtio_pci_probe, - .remove = virtio_pci_remove, -#ifdef CONFIG_PM_SLEEP - .driver.pm = &virtio_pci_pm_ops, -#endif -}; - -module_pci_driver(virtio_pci_driver); -- cgit v1.2.3 From 5ff16110c637726111662c1df41afd9df7ef36bd Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Wed, 17 Dec 2014 00:54:03 +0200 Subject: virtio_pci: restore module attributes When the virtio_pci driver was moved into virtio_pci_legacy.c the module licence and other attributes went AWOL. This patch restores them. Signed-off-by: Herbert Xu Signed-off-by: Michael S. Tsirkin --- drivers/virtio/virtio_pci_common.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'drivers/virtio') diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c index 59d3685c31b4..2ef9529809d8 100644 --- a/drivers/virtio/virtio_pci_common.c +++ b/drivers/virtio/virtio_pci_common.c @@ -494,3 +494,8 @@ static struct pci_driver virtio_pci_driver = { }; module_pci_driver(virtio_pci_driver); + +MODULE_AUTHOR("Anthony Liguori "); +MODULE_DESCRIPTION("virtio-pci"); +MODULE_LICENSE("GPL"); +MODULE_VERSION("1"); -- cgit v1.2.3