vDPA driver for virtio-pci device
v2 cover vDPA driver for virtio-pci device
Hi all:
This series tries to implement a vDPA driver for virtio-pci device which will bridge between vDPA bus and virtio-pci device.
This could be used for future feature prototyping and testing.
Please review
Changes from V2:
- don't try to use devres for virtio-pci core
- tweak the commit log
- split the patches furtherly to ease the reviewing
Changes from V1:
- Split common codes from virito-pci and share it with vDPA driver
- Use dynamic id in order to be less confusing with virtio-pci driver
- No feature whitelist, supporting any features (mq, config etc)
Thanks
Jason Wang (19):
virtio-pci: do not access iomem via struct virtio_pci_device directly
virtio-pci: split out modern device
virtio-pci-modern: factor out modern device initialization logic
virtio-pci-modern: introduce vp_modern_remove()
virtio-pci-modern: introduce helper to set config vector
virtio-pci-modern: introduce helpers for setting and getting status
virtio-pci-modern: introduce helpers for setting and getting features
virtio-pci-modern: introduce vp_modern_generation()
virtio-pci-modern: introduce vp_modern_set_queue_vector()
virtio-pci-modern: introduce vp_modern_queue_address()
virtio-pci-modern: introduce helper to set/get queue_enable
virtio-pci-modern: introduce helper for setting/geting queue size
virtio-pci-modern: introduce helper for getting queue nums
virtio-pci-modern: introduce helper to get notification offset
virito-pci-modern: rename map_capability() to
vp_modern_map_capability()
virtio-pci: introduce modern device module
vdpa: set the virtqueue num during register
virtio_vdpa: don't warn when fail to disable vq
vdpa: introduce virtio pci driver
drivers/vdpa/Kconfig | 6 + drivers/vdpa/Makefile | 1 + drivers/vdpa/ifcvf/ifcvf_main.c | 5 +- drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +- drivers/vdpa/vdpa.c | 8 +- drivers/vdpa/vdpa_sim/vdpa_sim.c | 4 +- drivers/vdpa/virtio_pci/Makefile | 2 + drivers/vdpa/virtio_pci/vp_vdpa.c | 455 +++++++++++++++++++ drivers/virtio/Kconfig | 10 +- drivers/virtio/Makefile | 1 + drivers/virtio/virtio_pci_common.h | 22 +- drivers/virtio/virtio_pci_modern.c | 506 +++------------------ drivers/virtio/virtio_pci_modern_dev.c | 599 +++++++++++++++++++++++++ drivers/virtio/virtio_vdpa.c | 3 +- include/linux/vdpa.h | 7 +- include/linux/virtio_pci_modern.h | 111 +++++ 16 files changed, 1273 insertions(+), 472 deletions(-) create mode 100644 drivers/vdpa/virtio_pci/Makefile create mode 100644 drivers/vdpa/virtio_pci/vp_vdpa.c create mode 100644 drivers/virtio/virtio_pci_modern_dev.c create mode 100644 include/linux/virtio_pci_modern.h
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 1/19 virtio-pci: do not access iomem via struct virtio_pci_device directly
Instead of accessing iomem via struct virito_pci_device directly, tweak to call the io accessors through the iomem structure. This will ease the splitting of modern virtio device logic.
--- drivers/virtio/virtio_pci_modern.c | 76 ++++++++++++++++++------------ 1 file changed, 46 insertions(+), 30 deletions(-)
drivers/virtio/virtio_pci_modern.c +46 -30
@@ -141,12 +141,13 @@ static void __iomem *map_capability(struct pci_dev *dev, int off,static u64 vp_get_features (struct virtio_device *vdev) {struct virtio_pci_device *vp_dev =to_vp_device (vdev); +struct virtio_pci_common_cfg __iomem *cfg = vp_dev->common;u64 features; -vp_iowrite32 (0 , &vp_dev->common->device_feature_select); - features =vp_ioread32 (&vp_dev->common->device_feature); -vp_iowrite32 (1 , &vp_dev->common->device_feature_select); - features |= ((u64 )vp_ioread32 (&vp_dev->common->device_feature) <<32 ); +vp_iowrite32 (0 , &cfg->device_feature_select); + features =vp_ioread32 (&cfg->device_feature); +vp_iowrite32 (1 , &cfg->device_feature_select); + features |= ((u64 )vp_ioread32 (&cfg->device_feature) <<32 );return features; }
@@ -165,6 +166,7 @@ static void vp_transport_features(struct virtio_device *vdev, u64 features)static int vp_finalize_features (struct virtio_device *vdev) {struct virtio_pci_device *vp_dev =to_vp_device (vdev); +struct virtio_pci_common_cfg __iomem *cfg = vp_dev->common;u64 features = vdev->features;/* Give virtio_ring a chance to accept features. */
@@ -179,10 +181,10 @@ static int vp_finalize_features(struct virtio_device *vdev)return -EINVAL ; } -vp_iowrite32 (0 , &vp_dev->common->guest_feature_select); -vp_iowrite32 ((u32 )vdev->features, &vp_dev->common->guest_feature); -vp_iowrite32 (1 , &vp_dev->common->guest_feature_select); -vp_iowrite32 (vdev->features >>32 , &vp_dev->common->guest_feature); +vp_iowrite32 (0 , &cfg->guest_feature_select); +vp_iowrite32 ((u32 )vdev->features, &cfg->guest_feature); +vp_iowrite32 (1 , &cfg->guest_feature_select); +vp_iowrite32 (vdev->features >>32 , &cfg->guest_feature);return 0 ; }
@@ -192,6 +194,7 @@ static void vp_get(struct virtio_device *vdev, unsigned offset, void *buf, unsigned len) {struct virtio_pci_device *vp_dev =to_vp_device (vdev); +void __iomem *device = vp_dev->device;u8 b;__le16 w;__le32 l;
@@ -200,21 +203,21 @@ static void vp_get(struct virtio_device *vdev, unsigned offset,switch (len) {case 1 : - b =ioread8 (vp_dev->device + offset); + b =ioread8 (device + offset);memcpy (buf, &b,sizeof b);break ;case 2 : - w =cpu_to_le16 (ioread16 (vp_dev->device + offset)); + w =cpu_to_le16 (ioread16 (device + offset));memcpy (buf, &w,sizeof w);break ;case 4 : - l =cpu_to_le32 (ioread32 (vp_dev->device + offset)); + l =cpu_to_le32 (ioread32 (device + offset));memcpy (buf, &l,sizeof l);break ;case 8 : - l =cpu_to_le32 (ioread32 (vp_dev->device + offset)); + l =cpu_to_le32 (ioread32 (device + offset));memcpy (buf, &l,sizeof l); - l =cpu_to_le32 (ioread32 (vp_dev->device + offset +sizeof l)); + l =cpu_to_le32 (ioread32 (device + offset +sizeof l));memcpy (buf +sizeof l, &l,sizeof l);break ;default :
@@ -228,6 +231,7 @@ static void vp_set(struct virtio_device *vdev, unsigned offset, const void *buf, unsigned len) {struct virtio_pci_device *vp_dev =to_vp_device (vdev); +void __iomem *device = vp_dev->device;u8 b;__le16 w;__le32 l;
@@ -237,21 +241,21 @@ static void vp_set(struct virtio_device *vdev, unsigned offset,switch (len) {case 1 :memcpy (&b, buf,sizeof b); -iowrite8 (b, vp_dev->device + offset); +iowrite8 (b, device + offset);break ;case 2 :memcpy (&w, buf,sizeof w); -iowrite16 (le16_to_cpu (w), vp_dev->device + offset); +iowrite16 (le16_to_cpu (w), device + offset);break ;case 4 :memcpy (&l, buf,sizeof l); -iowrite32 (le32_to_cpu (l), vp_dev->device + offset); +iowrite32 (le32_to_cpu (l), device + offset);break ;case 8 :memcpy (&l, buf,sizeof l); -iowrite32 (le32_to_cpu (l), vp_dev->device + offset); +iowrite32 (le32_to_cpu (l), device + offset);memcpy (&l, buf +sizeof l,sizeof l); -iowrite32 (le32_to_cpu (l), vp_dev->device + offset +sizeof l); +iowrite32 (le32_to_cpu (l), device + offset +sizeof l);break ;default :BUG ();
@@ -261,35 +265,43 @@ static void vp_set(struct virtio_device *vdev, unsigned offset,static u32 vp_generation (struct virtio_device *vdev) {struct virtio_pci_device *vp_dev =to_vp_device (vdev); -return vp_ioread8 (&vp_dev->common->config_generation); +struct virtio_pci_common_cfg __iomem *cfg = vp_dev->common; + +return vp_ioread8 (&cfg->config_generation); }/* config->{get,set}_status() implementations */ static u8 vp_get_status (struct virtio_device *vdev) {struct virtio_pci_device *vp_dev =to_vp_device (vdev); -return vp_ioread8 (&vp_dev->common->device_status); +struct virtio_pci_common_cfg __iomem *cfg = vp_dev->common; + +return vp_ioread8 (&cfg->device_status); }static void vp_set_status (struct virtio_device *vdev,u8 status) {struct virtio_pci_device *vp_dev =to_vp_device (vdev); +struct virtio_pci_common_cfg __iomem *cfg = vp_dev->common; +/* We should never be setting status to 0. */ BUG_ON (status ==0 ); -vp_iowrite8 (status, &vp_dev->common->device_status); +vp_iowrite8 (status, &cfg->device_status); }static void vp_reset (struct virtio_device *vdev) {struct virtio_pci_device *vp_dev =to_vp_device (vdev); +struct virtio_pci_common_cfg __iomem *cfg = vp_dev->common; +/* 0 status means a reset. */ -vp_iowrite8 (0 , &vp_dev->common->device_status); +vp_iowrite8 (0 , &cfg->device_status);/* After writing 0 to device_status, the driver MUST wait for a read of * device_status to return 0 before reinitializing the device. * This will flush out the status write, and flush in device writes, * including MSI-X interrupts, if any. */ -while (vp_ioread8 (&vp_dev->common->device_status)) +while (vp_ioread8 (&cfg->device_status))msleep (1 );/* Flush pending VQ/configuration callbacks. */ vp_synchronize_vectors (vdev);
@@ -297,11 +309,13 @@ static void vp_reset(struct virtio_device *vdev)static u16 vp_config_vector (struct virtio_pci_device *vp_dev,u16 vector) { +struct virtio_pci_common_cfg __iomem *cfg = vp_dev->common; +/* Setup the vector used for configuration events */ -vp_iowrite16 (vector, &vp_dev->common->msix_config); +vp_iowrite16 (vector, &cfg->msix_config);/* Verify we had enough resources to assign the vector */ /* Will also flush the write out to device */ -return vp_ioread16 (&vp_dev->common->msix_config); +return vp_ioread16 (&cfg->msix_config); } static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
@@ -407,6 +421,7 @@ static int vp_modern_find_vqs(struct virtio_device *vdev, unsigned nvqs, struct irq_affinity *desc) {struct virtio_pci_device *vp_dev =to_vp_device (vdev); +struct virtio_pci_common_cfg __iomem *cfg = vp_dev->common;struct virtqueue *vq;int rc =vp_find_vqs (vdev, nvqs, vqs, callbacks, names, ctx, desc);
@@ -417,8 +432,8 @@ static int vp_modern_find_vqs(struct virtio_device *vdev, unsigned nvqs,* this, there's no way to go back except reset. */ list_for_each_entry (vq, &vdev->vqs, list) { -vp_iowrite16 (vq->index, &vp_dev->common->queue_select); -vp_iowrite16 (1 , &vp_dev->common->queue_enable); +vp_iowrite16 (vq->index, &cfg->queue_select); +vp_iowrite16 (1 , &cfg->queue_enable); }return 0 ;
@@ -428,14 +443,15 @@ static void del_vq(struct virtio_pci_vq_info *info) {struct virtqueue *vq = info->vq;struct virtio_pci_device *vp_dev =to_vp_device (vq->vdev); +struct virtio_pci_common_cfg __iomem *cfg = vp_dev->common; -vp_iowrite16 (vq->index, &vp_dev->common->queue_select); +vp_iowrite16 (vq->index, &cfg->queue_select);if (vp_dev->msix_enabled) {vp_iowrite16 (VIRTIO_MSI_NO_VECTOR , - &vp_dev->common->queue_msix_vector); + &cfg->queue_msix_vector);/* Flush the write out to device */ -vp_ioread16 (&vp_dev->common->queue_msix_vector); +vp_ioread16 (&cfg->queue_msix_vector); }if (!vp_dev->notify_base)
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 2/19 virtio-pci: split out modern device
In reply to Jason WangThis patch splits out the virtio-pci modern device only attributes into another structure. While at it, a dedicated probe method for modern only attributes is introduced. This may help for split the logic into a dedicated module.
--- drivers/virtio/virtio_pci_common.h | 25 +++-- drivers/virtio/virtio_pci_modern.c | 159 ++++++++++++++++------------- 2 files changed, 105 insertions(+), 79 deletions(-)
drivers/virtio/virtio_pci_common.h +16 -9
@@ -39,22 +39,16 @@ struct virtio_pci_vq_info {unsigned msix_vector; }; -/* Our device structure */ -struct virtio_pci_device { -struct virtio_device vdev; +struct virtio_pci_modern_device {struct pci_dev *pci_dev; -/* In legacy mode, these two point to within ->legacy. */ -/* Where to read and clear interrupt */ -u8 __iomem *isr; - -/* Modern only fields */ -/* The IO mapping for the PCI config space (non-legacy mode) */ struct virtio_pci_common_cfg __iomem *common;/* Device-specific data (non-legacy mode) */ void __iomem *device;/* Base of vq notifications (non-legacy mode). */ void __iomem *notify_base; +/* Where to read and clear interrupt */ +u8 __iomem *isr;/* So we can sanity-check accesses. */ size_t notify_len;
@@ -68,6 +62,19 @@ struct virtio_pci_device {int modern_bars; +struct virtio_device_id id; +}; + +/* Our device structure */ +struct virtio_pci_device { +struct virtio_device vdev; +struct pci_dev *pci_dev; +struct virtio_pci_modern_device mdev; + +/* In legacy mode, these two point to within ->legacy. */ +/* Where to read and clear interrupt */ +u8 __iomem *isr; +/* Legacy only field */ /* the IO mapping for the PCI config space */ void __iomem *ioaddr;
drivers/virtio/virtio_pci_modern.c +89 -70
346 lines not on this page · raw message
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 3/19 virtio-pci-modern: factor out modern device initialization logic
In reply to Jason WangThis patch factors out the modern device initialization logic into a helper. Note that it still depends on the caller to enable pci device which allows the caller to use e.g devres.
--- drivers/virtio/virtio_pci_modern.c | 50 +++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 14 deletions(-)
drivers/virtio/virtio_pci_modern.c +36 -14
@@ -703,11 +703,16 @@ static inline void check_offsets(void) offsetof(struct virtio_pci_common_cfg, queue_used_hi)); } -/* the PCI probing function */ -int virtio_pci_modern_probe (struct virtio_pci_device *vp_dev) +/* +* vp_modern_probe: probe the modern virtio pci device, note that the +* caller is required to enable PCI device before calling this function. +* @mdev: the modern virtio-pci device +* +* Return 0 on succeed otherwise fail +*/ +static int vp_modern_probe (struct virtio_pci_modern_device *mdev) { -struct virtio_pci_modern_device *mdev = &vp_dev->mdev; -struct pci_dev *pci_dev = vp_dev->pci_dev; +struct pci_dev *pci_dev = mdev->pci_dev;int err, common, isr, notify, device;u32 notify_length;u32 notify_offset;
@@ -826,18 +831,8 @@ int virtio_pci_modern_probe(struct virtio_pci_device *vp_dev) &mdev->device_len);if (!mdev->device) goto err_map_device; - - vp_dev->vdev.config = &virtio_pci_config_ops; - }else { - vp_dev->vdev.config = &virtio_pci_config_nodev_ops; } - vp_dev->config_vector = vp_config_vector; - vp_dev->setup_vq = setup_vq; - vp_dev->del_vq = del_vq; - vp_dev->isr = mdev->isr; - vp_dev->vdev.id = mdev->id; -return 0 ; err_map_device:
@@ -851,6 +846,33 @@ int virtio_pci_modern_probe(struct virtio_pci_device *vp_dev)return err; } +/* the PCI probing function */ +int virtio_pci_modern_probe (struct virtio_pci_device *vp_dev) +{ +struct virtio_pci_modern_device *mdev = &vp_dev->mdev; +struct pci_dev *pci_dev = vp_dev->pci_dev; +int err; + + mdev->pci_dev = pci_dev; + + err =vp_modern_probe (mdev); +if (err) +return err; + +if (mdev->device) + vp_dev->vdev.config = &virtio_pci_config_ops; +else + vp_dev->vdev.config = &virtio_pci_config_nodev_ops; + + vp_dev->config_vector = vp_config_vector; + vp_dev->setup_vq = setup_vq; + vp_dev->del_vq = del_vq; + vp_dev->isr = mdev->isr; + vp_dev->vdev.id = mdev->id; + +return 0 ; +} +void virtio_pci_modern_remove (struct virtio_pci_device *vp_dev) {struct virtio_pci_modern_device *mdev = &vp_dev->mdev;
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 4/19 virtio-pci-modern: introduce vp_modern_remove()
In reply to Jason WangThis patch introduces vp_modern_remove() doing device resources cleanup to make it can be used.
--- drivers/virtio/virtio_pci_modern.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/virtio/virtio_pci_modern.c +12 -2
@@ -873,9 +873,12 @@ int virtio_pci_modern_probe(struct virtio_pci_device *vp_dev)return 0 ; } -void virtio_pci_modern_remove (struct virtio_pci_device *vp_dev) +/* +* vp_modern_probe: remove and cleanup the modern virtio pci device +* @mdev: the modern virtio-pci device +*/ +static void vp_modern_remove (struct virtio_pci_modern_device *mdev) { -struct virtio_pci_modern_device *mdev = &vp_dev->mdev;struct pci_dev *pci_dev = mdev->pci_dev;if (mdev->device)
@@ -886,3 +889,10 @@ void virtio_pci_modern_remove(struct virtio_pci_device *vp_dev)pci_iounmap (pci_dev, mdev->common);pci_release_selected_regions (pci_dev, mdev->modern_bars); } + +void virtio_pci_modern_remove (struct virtio_pci_device *vp_dev) +{ +struct virtio_pci_modern_device *mdev = &vp_dev->mdev; + +vp_modern_remove (mdev); +}
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 5/19 virtio-pci-modern: introduce helper to set config vector
In reply to Jason WangThis patch introduces vp_modern_config_vector() for setting config vector.
--- drivers/virtio/virtio_pci_modern.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/virtio/virtio_pci_modern.c +14 -2
@@ -315,9 +315,16 @@ static void vp_reset(struct virtio_device *vdev)vp_synchronize_vectors (vdev); } -static u16 vp_config_vector (struct virtio_pci_device *vp_dev,u16 vector) +/* +* vp_modern_config_vector - set the vector for config interrupt +* @mdev: the modern virtio-pci device +* @vector: the config vector +* +* Returns the config vector read from the device +*/ +static u16 vp_modern_config_vector (struct virtio_pci_modern_device *mdev, +u16 vector) { -struct virtio_pci_modern_device *mdev = &vp_dev->mdev;struct virtio_pci_common_cfg __iomem *cfg = mdev->common;/* Setup the vector used for configuration events */
@@ -327,6 +334,11 @@ static u16 vp_config_vector(struct virtio_pci_device *vp_dev, u16 vector)return vp_ioread16 (&cfg->msix_config); } +static u16 vp_config_vector (struct virtio_pci_device *vp_dev,u16 vector) +{ +return vp_modern_config_vector (&vp_dev->mdev, vector); +} + static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, struct virtio_pci_vq_info *info, unsigned index,
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 6/19 virtio-pci-modern: introduce helpers for setting and getting status
In reply to Jason WangThis patch introduces helpers to allow set and get device status.
--- drivers/virtio/virtio_pci_modern.c | 37 +++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 8 deletions(-)
drivers/virtio/virtio_pci_modern.c +29 -8
@@ -275,41 +275,62 @@ static u32 vp_generation(struct virtio_device *vdev)return vp_ioread8 (&cfg->config_generation); } +/* +* vp_modern_get_status - get the device status +* @mdev: the modern virtio-pci device +* +* Returns the status read from device +*/ +static u8 vp_modern_get_status (struct virtio_pci_modern_device *mdev) +{ +struct virtio_pci_common_cfg __iomem *cfg = mdev->common; + +return vp_ioread8 (&cfg->device_status); +} +/* config->{get,set}_status() implementations */ static u8 vp_get_status (struct virtio_device *vdev) {struct virtio_pci_device *vp_dev =to_vp_device (vdev); -struct virtio_pci_modern_device *mdev = &vp_dev->mdev; + +return vp_modern_get_status (&vp_dev->mdev); +} + +/* +* vp_modern_set_status - set status to device +* @mdev: the modern virtio-pci device +* @status: the status set to device +*/ +static void vp_modern_set_status (struct virtio_pci_modern_device *mdev, +u8 status) +{struct virtio_pci_common_cfg __iomem *cfg = mdev->common; -return vp_ioread8 (&cfg->device_status); +vp_iowrite8 (status, &cfg->device_status); }static void vp_set_status (struct virtio_device *vdev,u8 status) {struct virtio_pci_device *vp_dev =to_vp_device (vdev); -struct virtio_pci_modern_device *mdev = &vp_dev->mdev; -struct virtio_pci_common_cfg __iomem *cfg = mdev->common;/* We should never be setting status to 0. */ BUG_ON (status ==0 ); -vp_iowrite8 (status, &cfg->device_status); +vp_modern_set_status (&vp_dev->mdev, status); }static void vp_reset (struct virtio_device *vdev) {struct virtio_pci_device *vp_dev =to_vp_device (vdev);struct virtio_pci_modern_device *mdev = &vp_dev->mdev; -struct virtio_pci_common_cfg __iomem *cfg = mdev->common;/* 0 status means a reset. */ -vp_iowrite8 (0 , &cfg->device_status); +vp_modern_set_status (mdev,0 );/* After writing 0 to device_status, the driver MUST wait for a read of * device_status to return 0 before reinitializing the device. * This will flush out the status write, and flush in device writes, * including MSI-X interrupts, if any. */ -while (vp_ioread8 (&cfg->device_status)) +while (vp_modern_get_status (mdev))msleep (1 );/* Flush pending VQ/configuration callbacks. */ vp_synchronize_vectors (vdev);
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 7/19 virtio-pci-modern: introduce helpers for setting and getting features
In reply to Jason WangThis patch introduces helpers for setting and getting features.
--- drivers/virtio/virtio_pci_modern.c | 43 +++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 10 deletions(-)
drivers/virtio/virtio_pci_modern.c +33 -10
@@ -137,12 +137,16 @@ static void __iomem *map_capability(struct pci_dev *dev, int off,return p; } -/* virtio config->get_features() implementation */ -static u64 vp_get_features (struct virtio_device *vdev) +/* +* vp_modern_get_features - get features from device +* @mdev: the modern virtio-pci device +* +* Returns the features read from the device +*/ +static u64 vp_modern_get_features (struct virtio_pci_modern_device *mdev) { -struct virtio_pci_device *vp_dev =to_vp_device (vdev); -struct virtio_pci_modern_device *mdev = &vp_dev->mdev;struct virtio_pci_common_cfg __iomem *cfg = mdev->common; +u64 features;vp_iowrite32 (0 , &cfg->device_feature_select);
@@ -153,6 +157,14 @@ static u64 vp_get_features(struct virtio_device *vdev)return features; } +/* virtio config->get_features() implementation */ +static u64 vp_get_features (struct virtio_device *vdev) +{ +struct virtio_pci_device *vp_dev =to_vp_device (vdev); + +return vp_modern_get_features (&vp_dev->mdev); +} +static void vp_transport_features (struct virtio_device *vdev,u64 features) {struct virtio_pci_device *vp_dev =to_vp_device (vdev);
@@ -163,12 +175,26 @@ static void vp_transport_features(struct virtio_device *vdev, u64 features)__virtio_set_bit (vdev,VIRTIO_F_SR_IOV ); } +/* +* vp_modern_set_features - set features to device +* @mdev: the modern virtio-pci device +* @features: the features set to device +*/ +static void vp_modern_set_features (struct virtio_pci_modern_device *mdev, +u64 features) +{ +struct virtio_pci_common_cfg __iomem *cfg = mdev->common; + +vp_iowrite32 (0 , &cfg->guest_feature_select); +vp_iowrite32 ((u32 )features, &cfg->guest_feature); +vp_iowrite32 (1 , &cfg->guest_feature_select); +vp_iowrite32 (features >>32 , &cfg->guest_feature); +} +/* virtio config->finalize_features() implementation */ static int vp_finalize_features (struct virtio_device *vdev) {struct virtio_pci_device *vp_dev =to_vp_device (vdev); -struct virtio_pci_modern_device *mdev = &vp_dev->mdev; -struct virtio_pci_common_cfg __iomem *cfg = mdev->common;u64 features = vdev->features;/* Give virtio_ring a chance to accept features. */
@@ -183,10 +209,7 @@ static int vp_finalize_features(struct virtio_device *vdev)return -EINVAL ; } -vp_iowrite32 (0 , &cfg->guest_feature_select); -vp_iowrite32 ((u32 )vdev->features, &cfg->guest_feature); -vp_iowrite32 (1 , &cfg->guest_feature_select); -vp_iowrite32 (vdev->features >>32 , &cfg->guest_feature); +vp_modern_set_features (&vp_dev->mdev, vdev->features);return 0 ; }
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 8/19 virtio-pci-modern: introduce vp_modern_generation()
In reply to Jason WangThis patch introduces vp_modern_generation() to get device generation.
--- drivers/virtio/virtio_pci_modern.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/virtio/virtio_pci_modern.c +14 -3
@@ -289,15 +289,26 @@ static void vp_set(struct virtio_device *vdev, unsigned offset, } } -static u32 vp_generation (struct virtio_device *vdev) +/* +* vp_modern_generation - get the device genreation +* @mdev: the modern virtio-pci device +* +* Returns the genreation read from device +*/ +static u32 vp_modern_generation (struct virtio_pci_modern_device *mdev) { -struct virtio_pci_device *vp_dev =to_vp_device (vdev); -struct virtio_pci_modern_device *mdev = &vp_dev->mdev;struct virtio_pci_common_cfg __iomem *cfg = mdev->common;return vp_ioread8 (&cfg->config_generation); } +static u32 vp_generation (struct virtio_device *vdev) +{ +struct virtio_pci_device *vp_dev =to_vp_device (vdev); + +return vp_modern_generation (&vp_dev->mdev); +} +/* * vp_modern_get_status - get the device status * @mdev: the modern virtio-pci device
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 9/19 virtio-pci-modern: introduce vp_modern_set_queue_vector()
In reply to Jason WangThis patch introduces a helper to set virtqueue MSI vector.
--- drivers/virtio/virtio_pci_modern.c | 35 ++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 12 deletions(-)
drivers/virtio/virtio_pci_modern.c +23 -12
@@ -191,6 +191,25 @@ static void vp_modern_set_features(struct virtio_pci_modern_device *mdev,vp_iowrite32 (features >>32 , &cfg->guest_feature); } +/* +* vp_modern_queue_vector - set the MSIX vector for a specific virtqueue +* @mdev: the modern virtio-pci device +* @index: queue index +* @vector: the config vector +* +* Returns the config vector read from the device +*/ +static u16 vp_modern_queue_vector (struct virtio_pci_modern_device *mdev, +u16 index,u16 vector) +{ +struct virtio_pci_common_cfg __iomem *cfg = mdev->common; + +vp_iowrite16 (index, &cfg->queue_select); +vp_iowrite16 (vector, &cfg->queue_msix_vector); +/* Flush the write out to device */ +return vp_ioread16 (&cfg->queue_msix_vector); +} +/* virtio config->finalize_features() implementation */ static int vp_finalize_features (struct virtio_device *vdev) {
@@ -474,8 +493,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, }if (msix_vec !=VIRTIO_MSI_NO_VECTOR ) { -vp_iowrite16 (msix_vec, &cfg->queue_msix_vector); - msix_vec =vp_ioread16 (&cfg->queue_msix_vector); + msix_vec =vp_modern_queue_vector (mdev, index, msix_vec);if (msix_vec ==VIRTIO_MSI_NO_VECTOR ) { err = -EBUSY ; goto err_assign_vector;
@@ -522,17 +540,10 @@ static void del_vq(struct virtio_pci_vq_info *info)struct virtqueue *vq = info->vq;struct virtio_pci_device *vp_dev =to_vp_device (vq->vdev);struct virtio_pci_modern_device *mdev = &vp_dev->mdev; -struct virtio_pci_common_cfg __iomem *cfg = mdev->common; - -vp_iowrite16 (vq->index, &cfg->queue_select); - -if (vp_dev->msix_enabled) { -vp_iowrite16 (VIRTIO_MSI_NO_VECTOR , - &cfg->queue_msix_vector); -/* Flush the write out to device */ -vp_ioread16 (&cfg->queue_msix_vector); - } +if (vp_dev->msix_enabled) +vp_modern_queue_vector (mdev, vq->index, +VIRTIO_MSI_NO_VECTOR );if (!mdev->notify_base)pci_iounmap (mdev->pci_dev, (void __force __iomem *)vq->priv);
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 10/19 virtio-pci-modern: introduce vp_modern_queue_address()
In reply to Jason WangThis patch introduce a helper to set virtqueue address for modern address.
--- drivers/virtio/virtio_pci_modern.c | 33 ++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-)
drivers/virtio/virtio_pci_modern.c +27 -6
@@ -210,6 +210,30 @@ static u16 vp_modern_queue_vector(struct virtio_pci_modern_device *mdev,return vp_ioread16 (&cfg->queue_msix_vector); } +/* +* vp_modern_queue_address - set the virtqueue address +* @mdev: the modern virtio-pci device +* @index: the queue index +* @desc_addr: address of the descriptor area +* @driver_addr: address of the driver area +* @device_addr: address of the device area +*/ +static void vp_modern_queue_address (struct virtio_pci_modern_device *mdev, +u16 index,u64 desc_addr,u64 driver_addr, +u64 device_addr) +{ +struct virtio_pci_common_cfg __iomem *cfg = mdev->common; + +vp_iowrite16 (index, &cfg->queue_select); + +vp_iowrite64_twopart (desc_addr, &cfg->queue_desc_lo, + &cfg->queue_desc_hi); +vp_iowrite64_twopart (driver_addr, &cfg->queue_avail_lo, + &cfg->queue_avail_hi); +vp_iowrite64_twopart (device_addr, &cfg->queue_used_lo, + &cfg->queue_used_hi); +} +/* virtio config->finalize_features() implementation */ static int vp_finalize_features (struct virtio_device *vdev) {
@@ -459,12 +483,9 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,/* activate the queue */ vp_iowrite16 (virtqueue_get_vring_size (vq), &cfg->queue_size); -vp_iowrite64_twopart (virtqueue_get_desc_addr (vq), - &cfg->queue_desc_lo, &cfg->queue_desc_hi); -vp_iowrite64_twopart (virtqueue_get_avail_addr (vq), - &cfg->queue_avail_lo, &cfg->queue_avail_hi); -vp_iowrite64_twopart (virtqueue_get_used_addr (vq), - &cfg->queue_used_lo, &cfg->queue_used_hi); +vp_modern_queue_address (mdev, index,virtqueue_get_desc_addr (vq), +virtqueue_get_avail_addr (vq), +virtqueue_get_used_addr (vq));if (mdev->notify_base) {/* offset should not wrap */
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 11/19 virtio-pci-modern: introduce helper to set/get queue_enable
In reply to Jason WangThis patch introduces a helper to set/get queue_enable for modern device.
--- drivers/virtio/virtio_pci_modern.c | 37 +++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-)
drivers/virtio/virtio_pci_modern.c +31 -6
@@ -234,6 +234,34 @@ static void vp_modern_queue_address(struct virtio_pci_modern_device *mdev, &cfg->queue_used_hi); } +/* +* vp_modern_set_queue_enable - enable a virtqueue +* @mdev: the modern virtio-pci device +* @index: the queue index +* @enable: whether the virtqueue is enable or not +*/ +static void vp_modern_set_queue_enable (struct virtio_pci_modern_device *mdev, +u16 index,bool enable) +{ +vp_iowrite16 (index, &mdev->common->queue_select); +vp_iowrite16 (enable, &mdev->common->queue_enable); +} + +/* +* vp_modern_get_queue_enable - enable a virtqueue +* @mdev: the modern virtio-pci device +* @index: the queue index +* +* Returns whether a virtqueue is enabled or not +*/ +static bool vp_modern_get_queue_enable (struct virtio_pci_modern_device *mdev, +u16 index) +{ +vp_iowrite16 (index, &mdev->common->queue_select); + +return vp_ioread16 (&mdev->common->queue_enable); +} +/* virtio config->finalize_features() implementation */ static int vp_finalize_features (struct virtio_device *vdev) {
@@ -460,7 +488,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,/* Check if queue is either not available or already active. */ num =vp_ioread16 (&cfg->queue_size); -if (!num ||vp_ioread16 (&cfg->queue_enable)) +if (!num ||vp_modern_get_queue_enable (mdev, index))return ERR_PTR (-ENOENT );if (num & (num -1 )) {
@@ -538,7 +566,6 @@ static int vp_modern_find_vqs(struct virtio_device *vdev, unsigned nvqs, struct irq_affinity *desc) {struct virtio_pci_device *vp_dev =to_vp_device (vdev); -struct virtio_pci_common_cfg __iomem *cfg = vp_dev->mdev.common;struct virtqueue *vq;int rc =vp_find_vqs (vdev, nvqs, vqs, callbacks, names, ctx, desc);
@@ -548,10 +575,8 @@ static int vp_modern_find_vqs(struct virtio_device *vdev, unsigned nvqs,/* Select and activate all queues. Has to be done last: once we do * this, there's no way to go back except reset. */ -list_for_each_entry (vq, &vdev->vqs, list) { -vp_iowrite16 (vq->index, &cfg->queue_select); -vp_iowrite16 (1 , &cfg->queue_enable); - } +list_for_each_entry (vq, &vdev->vqs, list) +vp_modern_set_queue_enable (&vp_dev->mdev, vq->index, true);return 0 ; }
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 12/19 virtio-pci-modern: introduce helper for setting/geting queue size
In reply to Jason WangThis patch introduces helper for setting/getting queue size for modern device.
--- drivers/virtio/virtio_pci_modern.c | 34 ++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-)
drivers/virtio/virtio_pci_modern.c +32 -2
@@ -262,6 +262,36 @@ static bool vp_modern_get_queue_enable(struct virtio_pci_modern_device *mdev,return vp_ioread16 (&mdev->common->queue_enable); } +/* +* vp_modern_set_queue_size - set size for a virtqueue +* @mdev: the modern virtio-pci device +* @index: the queue index +* @size: the size of the virtqueue +*/ +static void vp_modern_set_queue_size (struct virtio_pci_modern_device *mdev, +u16 index,u16 size) +{ +vp_iowrite16 (index, &mdev->common->queue_select); +vp_iowrite16 (size, &mdev->common->queue_size); + +} + +/* +* vp_modern_get_queue_size - get size for a virtqueue +* @mdev: the modern virtio-pci device +* @index: the queue index +* +* Returns the size of the virtqueue +*/ +static u16 vp_modern_get_queue_size (struct virtio_pci_modern_device *mdev, +u16 index) +{ +vp_iowrite16 (index, &mdev->common->queue_select); + +return vp_ioread16 (&mdev->common->queue_size); + +} +/* virtio config->finalize_features() implementation */ static int vp_finalize_features (struct virtio_device *vdev) {
@@ -487,7 +517,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,vp_iowrite16 (index, &cfg->queue_select);/* Check if queue is either not available or already active. */ - num =vp_ioread16 (&cfg->queue_size); + num =vp_modern_get_queue_size (mdev, index);if (!num ||vp_modern_get_queue_enable (mdev, index))return ERR_PTR (-ENOENT );
@@ -510,7 +540,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,return ERR_PTR (-ENOMEM );/* activate the queue */ -vp_iowrite16 (virtqueue_get_vring_size (vq), &cfg->queue_size); +vp_modern_set_queue_size (mdev, index,virtqueue_get_vring_size (vq));vp_modern_queue_address (mdev, index,virtqueue_get_desc_addr (vq),virtqueue_get_avail_addr (vq),virtqueue_get_used_addr (vq));
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 13/19 virtio-pci-modern: introduce helper for getting queue nums
In reply to Jason WangThis patch introduces helper for getting queue num of modern device.
--- drivers/virtio/virtio_pci_modern.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/virtio/virtio_pci_modern.c +12 -1
@@ -292,6 +292,17 @@ static u16 vp_modern_get_queue_size(struct virtio_pci_modern_device *mdev, } +/* +* vp_modern_get_num_queues - get the number of virtqueues +* @mdev: the modern virtio-pci device +* +* Returns the number of virtqueues +*/ +static u16 vp_modern_get_num_queues (struct virtio_pci_modern_device *mdev) +{ +return vp_ioread16 (&mdev->common->num_queues); +} +/* virtio config->finalize_features() implementation */ static int vp_finalize_features (struct virtio_device *vdev) {
@@ -510,7 +521,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,u16 num, off;int err; -if (index >=vp_ioread16 (&cfg->num_queues)) +if (index >=vp_modern_get_num_queues (mdev))return ERR_PTR (-ENOENT );/* Select the queue we're interested in */
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 14/19 virtio-pci-modern: introduce helper to get notification offset
In reply to Jason WangThis patch introduces help to get notification offset of modern device.
--- drivers/virtio/virtio_pci_modern.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/virtio/virtio_pci_modern.c +16 -5
@@ -303,6 +303,21 @@ static u16 vp_modern_get_num_queues(struct virtio_pci_modern_device *mdev)return vp_ioread16 (&mdev->common->num_queues); } +/* +* vp_modern_get_queue_notify_off - get notification offset for a virtqueue +* @mdev: the modern virtio-pci device +* @index: the queue index +* +* Returns the notification offset for a virtqueue +*/ +static u16 vp_modern_get_queue_notify_off (struct virtio_pci_modern_device *mdev, +u16 index) +{ +vp_iowrite16 (index, &mdev->common->queue_select); + +return vp_ioread16 (&mdev->common->queue_notify_off); +} +/* virtio config->finalize_features() implementation */ static int vp_finalize_features (struct virtio_device *vdev) {
@@ -516,7 +531,6 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, {struct virtio_pci_modern_device *mdev = &vp_dev->mdev; -struct virtio_pci_common_cfg __iomem *cfg = mdev->common;struct virtqueue *vq;u16 num, off;int err;
@@ -524,9 +538,6 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,if (index >=vp_modern_get_num_queues (mdev))return ERR_PTR (-ENOENT ); -/* Select the queue we're interested in */ -vp_iowrite16 (index, &cfg->queue_select); -/* Check if queue is either not available or already active. */ num =vp_modern_get_queue_size (mdev, index);if (!num ||vp_modern_get_queue_enable (mdev, index))
@@ -538,7 +549,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, }/* get offset of notification word for this vq */ - off =vp_ioread16 (&cfg->queue_notify_off); + off =vp_modern_get_queue_notify_off (mdev, index); info->msix_vector = msix_vec;
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 15/19 virito-pci-modern: rename map_capability() to vp_modern_map_capability()
In reply to Jason WangTo ease the split, map_capability() was renamed to vp_modern_map_capability(). While at it, add the comments for the arguments and switch to use virtio_pci_modern_device as the first parameter.
--- drivers/virtio/virtio_pci_modern.c | 46 +++++++++++++++++++----------- 1 file changed, 30 insertions(+), 16 deletions(-)
drivers/virtio/virtio_pci_modern.c +30 -16
@@ -63,12 +63,25 @@ static void vp_iowrite64_twopart(u64 val,vp_iowrite32 (val >>32 , hi); } -static void __iomem *map_capability (struct pci_dev *dev,int off, -size_t minlen, -u32 align, -u32 start,u32 size, -size_t *len) +/* +* vp_modern_map_capability - map a part of virtio pci capability +* @mdev: the modern virtio-pci device +* @off: offset of the capability +* @minlen: minimal length of the capability +* @align: align requirement +* @start: start from the capability +* @size: map size +* @len: the length that is actually mapped +* +* Returns the io address of for the part of the capability +*/ +void __iomem *vp_modern_map_capability (struct virtio_pci_modern_device *mdev,int off, +size_t minlen, +u32 align, +u32 start,u32 size, +size_t *len) { +struct pci_dev *dev = mdev->pci_dev;u8 bar;u32 offset, length;void __iomem *p;
@@ -582,7 +595,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, vq->priv = (void __force *)mdev->notify_base + off * mdev->notify_offset_multiplier; }else { - vq->priv = (void __force *)map_capability (mdev->pci_dev, + vq->priv = (void __force *)vp_modern_map_capability (mdev, mdev->notify_map_cap,2 ,2 , off * mdev->notify_offset_multiplier,2 ,NULL );
@@ -956,15 +969,15 @@ static int vp_modern_probe(struct virtio_pci_modern_device *mdev)return err; err = -EINVAL ; - mdev->common =map_capability (pci_dev, common, + mdev->common =vp_modern_map_capability (mdev, common,sizeof (struct virtio_pci_common_cfg ),4 ,0 ,sizeof (struct virtio_pci_common_cfg ),NULL );if (!mdev->common) goto err_map_common; - mdev->isr =map_capability (pci_dev, isr,sizeof (u8),1 , -0 ,1 , -NULL ); + mdev->isr =vp_modern_map_capability (mdev, isr,sizeof (u8),1 , +0 ,1 , +NULL );if (!mdev->isr) goto err_map_isr;
@@ -989,9 +1002,10 @@ static int vp_modern_probe(struct virtio_pci_modern_device *mdev)* Otherwise, map each VQ individually later. */ if ((u64 )notify_length + (notify_offset %PAGE_SIZE ) <=PAGE_SIZE ) { - mdev->notify_base =map_capability (pci_dev, notify,2 ,2 , -0 , notify_length, - &mdev->notify_len); + mdev->notify_base =vp_modern_map_capability (mdev, notify, +2 ,2 , +0 , notify_length, + &mdev->notify_len);if (!mdev->notify_base) goto err_map_notify; }else {
@@ -1002,9 +1016,9 @@ static int vp_modern_probe(struct virtio_pci_modern_device *mdev)* is more than enough for all existing devices. */ if (device) { - mdev->device =map_capability (pci_dev, device,0 ,4 , -0 ,PAGE_SIZE , - &mdev->device_len); + mdev->device =vp_modern_map_capability (mdev, device,0 ,4 , +0 ,PAGE_SIZE , + &mdev->device_len);if (!mdev->device) goto err_map_device; }
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 16/19 virtio-pci: introduce modern device module
In reply to Jason Wang--- drivers/virtio/Kconfig | 10 +- drivers/virtio/Makefile | 1 + drivers/virtio/virtio_pci_common.h | 27 +- drivers/virtio/virtio_pci_modern.c | 617 ------------------------- drivers/virtio/virtio_pci_modern_dev.c | 599 ++++++++++++++++++++++++ include/linux/virtio_pci_modern.h | 111 +++++ 6 files changed, 721 insertions(+), 644 deletions(-) create mode 100644 drivers/virtio/virtio_pci_modern_dev.c create mode 100644 include/linux/virtio_pci_modern.h
drivers/virtio/Kconfig +9 -1
@@ -12,6 +12,14 @@ config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS This option is selected if the architecture may need to enforce VIRTIO_F_ACCESS_PLATFORM +config VIRTIO_PCI_MODERN + tristate "Modern Virtio PCI Device" + depends on PCI + help + Modern PCI device implementation. This module implement the + basic probe and control for devices which is based on modern + PCI device with possible vendor specific extensions. + menuconfig VIRTIO_MENU bool "Virtio drivers" default y
@@ -20,7 +28,7 @@ if VIRTIO_MENU config VIRTIO_PCI tristate "PCI driver for virtio devices" - depends on PCI + depends on VIRTIO_PCI_MODERN select VIRTIO help This driver provides support for virtio based paravirtual device
drivers/virtio/Makefile +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o +obj-$(CONFIG_VIRTIO_PCI_MODERN) += virtio_pci_modern_dev.o obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
drivers/virtio/virtio_pci_common.h +1 -26
@@ -25,6 +25,7 @@#include <linux/virtio_config.h> #include <linux/virtio_ring.h> #include <linux/virtio_pci.h> +#include <linux/virtio_pci_modern.h> #include <linux/highmem.h> #include <linux/spinlock.h>
@@ -39,32 +40,6 @@ struct virtio_pci_vq_info {unsigned msix_vector; }; -struct virtio_pci_modern_device { -struct pci_dev *pci_dev; - -struct virtio_pci_common_cfg __iomem *common; -/* Device-specific data (non-legacy mode) */ -void __iomem *device; -/* Base of vq notifications (non-legacy mode). */ -void __iomem *notify_base; -/* Where to read and clear interrupt */ -u8 __iomem *isr; - -/* So we can sanity-check accesses. */ -size_t notify_len; -size_t device_len; - -/* Capability for when we need to map notifications per-vq. */ -int notify_map_cap; - -/* Multiply queue_notify_off by this value. (non-legacy mode). */ -u32 notify_offset_multiplier; - -int modern_bars; - -struct virtio_device_id id; -}; -/* Our device structure */ struct virtio_pci_device {struct virtio_device vdev;
drivers/virtio/virtio_pci_modern.c +0 -617
665 lines not on this page · raw message
drivers/virtio/virtio_pci_modern_dev.c new file +599 -0
599 lines not on this page · raw message
include/linux/virtio_pci_modern.h new file +111 -0
111 lines not on this page · raw message
Signature · 7 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 16/19] virtio-pci: introduce modern device module
Hi Jason--
drivers/virtio/Kconfig config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS · line 19
Quoted 13 lines · Jason Wang
drivers/virtio/Kconfig +5
-0@@ -12,6 +12,14 @@ config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS This option is selected if the architecture may need to enforce VIRTIO_F_ACCESS_PLATFORM +config VIRTIO_PCI_MODERN + tristate "Modern Virtio PCI Device" + depends on PCI + help + Modern PCI device implementation. This module implement the
implements
drivers/virtio/Kconfig config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS · line 20
Quoted 1 line
drivers/virtio/Kconfig +1
-0+ basic probe and control for devices which is based on modern
are
drivers/virtio/Kconfig config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS · line 21
Quoted 1 line
drivers/virtio/Kconfig +1
-0+ PCI device with possible vendor specific extensions.
devices
drivers/virtio/Kconfig config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS · line 22
Quoted 1 line
drivers/virtio/Kconfig +1
-0+
cheers.
Signature · 6 lines
~Randy _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 16/19] virtio-pci: introduce modern device module
Quoted 18 lines · Randy Dunlap
Hi Jason--
drivers/virtio/Kconfig config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS · line 19
Quoted 13 lines · Jason Wang
drivers/virtio/Kconfig +5
-0@@ -12,6 +12,14 @@ config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS This option is selected if the architecture may need to enforce VIRTIO_F_ACCESS_PLATFORM +config VIRTIO_PCI_MODERN + tristate "Modern Virtio PCI Device" + depends on PCI + help + Modern PCI device implementation. This module implement theimplements
Quoted 8 lines
drivers/virtio/Kconfig config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS · line 20
Quoted 1 line
drivers/virtio/Kconfig +1
-0+ basic probe and control for devices which is based on modernare
drivers/virtio/Kconfig config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS · line 21
Quoted 1 line
drivers/virtio/Kconfig +1
-0+ PCI device with possible vendor specific extensions.devices
drivers/virtio/Kconfig config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS · line 22
Quoted 1 line
drivers/virtio/Kconfig +1
-0+cheers.
All fixed.
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 17/19 vdpa: set the virtqueue num during register
In reply to Jason WangThis patch delay the queue number setting to vDPA device registering. This allows us to probe the virtqueue numbers between device allocation and registering.
--- drivers/vdpa/ifcvf/ifcvf_main.c | 5 ++--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 ++--- drivers/vdpa/vdpa.c | 8 ++++---- drivers/vdpa/vdpa_sim/vdpa_sim.c | 4 ++-- include/linux/vdpa.h | 7 +++---- 5 files changed, 13 insertions(+), 16 deletions(-)
drivers/vdpa/ifcvf/ifcvf_main.c +2 -3
@@ -438,8 +438,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) } adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa, - dev, &ifc_vdpa_ops, -IFCVF_MAX_QUEUE_PAIRS *2 ); + dev, &ifc_vdpa_ops);if (adapter ==NULL ) {IFCVF_ERR (pdev,"Failed to allocate vDPA structure" );return -ENOMEM ;
@@ -463,7 +462,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id)for (i =0 ; i <IFCVF_MAX_QUEUE_PAIRS *2 ; i++) vf->vring[i].irq = -EINVAL ; - ret =vdpa_register_device (&adapter->vdpa); + ret =vdpa_register_device (&adapter->vdpa,IFCVF_MAX_QUEUE_PAIRS *2 );if (ret) {IFCVF_ERR (pdev,"Failed to register ifcvf to vdpa bus" ); goto err;
drivers/vdpa/mlx5/net/mlx5_vnet.c +2 -3
@@ -1940,8 +1940,7 @@ void *mlx5_vdpa_add_dev(struct mlx5_core_dev *mdev) max_vqs =MLX5_CAP_DEV_VDPA_EMULATION (mdev, max_num_virtio_queues); max_vqs =min_t (u32, max_vqs,MLX5_MAX_SUPPORTED_VQS ); - ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mlx5_vdpa_ops, -2 *mlx5_vdpa_max_qps (max_vqs)); + ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mlx5_vdpa_ops);if (IS_ERR (ndev))return ndev;
@@ -1968,7 +1967,7 @@ void *mlx5_vdpa_add_dev(struct mlx5_core_dev *mdev)if (err) goto err_res; - err =vdpa_register_device (&mvdev->vdev); + err =vdpa_register_device (&mvdev->vdev,2 *mlx5_vdpa_max_qps (max_vqs));if (err) goto err_reg;
drivers/vdpa/vdpa.c +4 -4
@@ -61,7 +61,6 @@ static void vdpa_release_dev(struct device *d)* initialized but before registered. * @parent: the parent device * @config: the bus operations that is supported by this device -* @nvqs: number of virtqueues supported by this device * @size: size of the parent structure that contains private data * * Driver should use vdpa_alloc_device() wrapper macro instead of
@@ -72,7 +71,6 @@ static void vdpa_release_dev(struct device *d)*/ struct vdpa_device *__vdpa_alloc_device (struct device *parent,const struct vdpa_config_ops *config, -int nvqs,size_t size) {struct vdpa_device *vdev;
@@ -99,7 +97,6 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent, vdev->index = err; vdev->config = config; vdev->features_valid = false; - vdev->nvqs = nvqs; err =dev_set_name (&vdev->dev,"vdpa%u" , vdev->index);if (err)
@@ -122,11 +119,14 @@ EXPORT_SYMBOL_GPL(__vdpa_alloc_device);* vdpa_register_device - register a vDPA device * Callers must have a succeed call of vdpa_alloc_device() before. * @vdev: the vdpa device to be registered to vDPA bus +* @nvqs: number of virtqueues supported by this device * * Returns an error when fail to add to vDPA bus */ -int vdpa_register_device (struct vdpa_device *vdev) +int vdpa_register_device (struct vdpa_device *vdev,int nvqs) { + vdev->nvqs = nvqs; +return device_add (&vdev->dev); }EXPORT_SYMBOL_GPL (vdpa_register_device);
drivers/vdpa/vdpa_sim/vdpa_sim.c +2 -2
@@ -357,7 +357,7 @@ static struct vdpasim *vdpasim_create(void)else ops = &vdpasim_net_config_ops; - vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, VDPASIM_VQ_NUM); + vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops);if (!vdpasim) goto err_alloc;
@@ -393,7 +393,7 @@ static struct vdpasim *vdpasim_create(void)vringh_set_iotlb (&vdpasim->vqs[1 ].vring, vdpasim->iommu); vdpasim->vdpa.dma_dev = dev; - ret =vdpa_register_device (&vdpasim->vdpa); + ret =vdpa_register_device (&vdpasim->vdpa,VDPASIM_VQ_NUM );if (ret) goto err_iommu;
include/linux/vdpa.h +3 -4
@@ -244,18 +244,17 @@ struct vdpa_config_ops {struct vdpa_device *__vdpa_alloc_device (struct device *parent,const struct vdpa_config_ops *config, -int nvqs,size_t size); -#define vdpa_alloc_device (dev_struct, member, parent, config, nvqs) \ +#define vdpa_alloc_device (dev_struct, member, parent, config) \ container_of(__vdpa_alloc_device( \ - parent, config, nvqs, \ + parent, config, \ sizeof(dev_struct) + \ BUILD_BUG_ON_ZERO(offsetof( \ dev_struct, member))), \ dev_struct, member) -int vdpa_register_device (struct vdpa_device *vdev); +int vdpa_register_device (struct vdpa_device *vdev,int nvqs);void vdpa_unregister_device (struct vdpa_device *vdev);/**
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 17/19] vdpa: set the virtqueue num during register
Quoted 4 lines · Jason Wang
This patch delay the queue number setting to vDPA device registering. This allows us to probe the virtqueue numbers between device allocation and registering.
Quoted 8 lines
Signed-off-by Jason Wang <[email protected]>---
drivers/vdpa/ifcvf/ifcvf_main.c | 5 ++--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 ++--- drivers/vdpa/vdpa.c | 8 ++++---- drivers/vdpa/vdpa_sim/vdpa_sim.c | 4 ++-- include/linux/vdpa.h | 7 +++---- 5 files changed, 13 insertions(+), 16 deletions(-)
Quoted 147 lines
drivers/vdpa/ifcvf/ifcvf_main.c +2
-3@@ -438,8 +438,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) } adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa, - dev, &ifc_vdpa_ops, -IFCVF_MAX_QUEUE_PAIRS *2 ); + dev, &ifc_vdpa_ops);if (adapter ==NULL ) {IFCVF_ERR (pdev,"Failed to allocate vDPA structure" );return -ENOMEM ;@@ -463,7 +462,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id)for (i =0 ; i <IFCVF_MAX_QUEUE_PAIRS *2 ; i++) vf->vring[i].irq = -EINVAL ; - ret =vdpa_register_device (&adapter->vdpa); + ret =vdpa_register_device (&adapter->vdpa,IFCVF_MAX_QUEUE_PAIRS *2 );if (ret) {IFCVF_ERR (pdev,"Failed to register ifcvf to vdpa bus" ); goto err;drivers/vdpa/mlx5/net/mlx5_vnet.c +2
-3@@ -1940,8 +1940,7 @@ void *mlx5_vdpa_add_dev(struct mlx5_core_dev *mdev) max_vqs =MLX5_CAP_DEV_VDPA_EMULATION (mdev, max_num_virtio_queues); max_vqs =min_t (u32, max_vqs,MLX5_MAX_SUPPORTED_VQS ); - ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mlx5_vdpa_ops, -2 *mlx5_vdpa_max_qps (max_vqs)); + ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mlx5_vdpa_ops);if (IS_ERR (ndev))return ndev;@@ -1968,7 +1967,7 @@ void *mlx5_vdpa_add_dev(struct mlx5_core_dev *mdev)if (err) goto err_res; - err =vdpa_register_device (&mvdev->vdev); + err =vdpa_register_device (&mvdev->vdev,2 *mlx5_vdpa_max_qps (max_vqs));if (err) goto err_reg;drivers/vdpa/vdpa.c +4
-4@@ -61,7 +61,6 @@ static void vdpa_release_dev(struct device *d)* initialized but before registered. * @parent: the parent device * @config: the bus operations that is supported by this device -* @nvqs: number of virtqueues supported by this device * @size: size of the parent structure that contains private data * * Driver should use vdpa_alloc_device() wrapper macro instead of @@ -72,7 +71,6 @@ static void vdpa_release_dev(struct device *d)*/ struct vdpa_device *__vdpa_alloc_device (struct device *parent,const struct vdpa_config_ops *config, -int nvqs,size_t size) {struct vdpa_device *vdev;@@ -99,7 +97,6 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent, vdev->index = err; vdev->config = config; vdev->features_valid = false; - vdev->nvqs = nvqs; err =dev_set_name (&vdev->dev,"vdpa%u" , vdev->index);if (err)@@ -122,11 +119,14 @@ EXPORT_SYMBOL_GPL(__vdpa_alloc_device);* vdpa_register_device - register a vDPA device * Callers must have a succeed call of vdpa_alloc_device() before. * @vdev: the vdpa device to be registered to vDPA bus +* @nvqs: number of virtqueues supported by this device * * Returns an error when fail to add to vDPA bus */ -int vdpa_register_device (struct vdpa_device *vdev) +int vdpa_register_device (struct vdpa_device *vdev,int nvqs) { + vdev->nvqs = nvqs; +return device_add (&vdev->dev); }EXPORT_SYMBOL_GPL (vdpa_register_device);drivers/vdpa/vdpa_sim/vdpa_sim.c +2
-2@@ -357,7 +357,7 @@ static struct vdpasim *vdpasim_create(void)else ops = &vdpasim_net_config_ops; - vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, VDPASIM_VQ_NUM); + vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops);if (!vdpasim) goto err_alloc;@@ -393,7 +393,7 @@ static struct vdpasim *vdpasim_create(void)vringh_set_iotlb (&vdpasim->vqs[1 ].vring, vdpasim->iommu); vdpasim->vdpa.dma_dev = dev; - ret =vdpa_register_device (&vdpasim->vdpa); + ret =vdpa_register_device (&vdpasim->vdpa,VDPASIM_VQ_NUM );if (ret) goto err_iommu;include/linux/vdpa.h +3
-4@@ -244,18 +244,17 @@ struct vdpa_config_ops {struct vdpa_device *__vdpa_alloc_device (struct device *parent,const struct vdpa_config_ops *config, -int nvqs,size_t size); -#define vdpa_alloc_device (dev_struct, member, parent, config, nvqs) \ +#define vdpa_alloc_device (dev_struct, member, parent, config) \ container_of(__vdpa_alloc_device( \ - parent, config, nvqs, \ + parent, config, \ sizeof(dev_struct) + \ BUILD_BUG_ON_ZERO(offsetof( \ dev_struct, member))), \ dev_struct, member) -int vdpa_register_device (struct vdpa_device *vdev); +int vdpa_register_device (struct vdpa_device *vdev,int nvqs);void vdpa_unregister_device (struct vdpa_device *vdev);/** Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 18/19 virtio_vdpa: don't warn when fail to disable vq
In reply to Jason WangThere's no guarantee that the device can disable a specific virtqueue through set_vq_ready(). One example is the modern virtio-pci device. So this patch removes the warning.
--- drivers/virtio/virtio_vdpa.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/virtio/virtio_vdpa.c +1 -2
@@ -225,9 +225,8 @@ static void virtio_vdpa_del_vq(struct virtqueue *vq)list_del (&info->node);spin_unlock_irqrestore (&vd_dev->lock, flags); -/* Select and deactivate the queue */ +/* Select and deactivate the queue (best effort) */ ops->set_vq_ready (vdpa, index,0 ); -WARN_ON (ops->get_vq_ready (vdpa, index));vring_del_virtqueue (vq);
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 19/19 vdpa: introduce virtio pci driver
In reply to Jason WangThis patch introduce a vDPA driver for virtio-pci device. It bridges the virtio-pci control command to the vDPA bus. This will be used for features prototyping and testing.
Note that get/restore virtqueue state is not supported which needs extension on the virtio specification.
--- drivers/vdpa/Kconfig | 6 + drivers/vdpa/Makefile | 1 + drivers/vdpa/virtio_pci/Makefile | 2 + drivers/vdpa/virtio_pci/vp_vdpa.c | 455 ++++++++++++++++++++++++++++++ 4 files changed, 464 insertions(+) create mode 100644 drivers/vdpa/virtio_pci/Makefile create mode 100644 drivers/vdpa/virtio_pci/vp_vdpa.c
drivers/vdpa/Kconfig +6 -0
@@ -48,4 +48,10 @@ config MLX5_VDPA_NET be executed by the hardware. It also supports a variety of stateless offloads depending on the actual device used and firmware version. +config VP_VDPA + tristate "Virtio PCI bridge vDPA driver" + depends on PCI_MSI && VIRTIO_PCI_MODERN + help + This kernel module that bridges virtio PCI device to vDPA bus. + endif # VDPA
drivers/vdpa/Makefile +1 -0
@@ -3,3 +3,4 @@ obj-$(CONFIG_VDPA) += vdpa.o obj-$(CONFIG_VDPA_SIM) += vdpa_sim/ obj-$(CONFIG_IFCVF) += ifcvf/ obj-$(CONFIG_MLX5_VDPA) += mlx5/ +obj-$(CONFIG_VP_VDPA) += virtio_pci/
drivers/vdpa/virtio_pci/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_VP_VDPA) += vp_vdpa.o
drivers/vdpa/virtio_pci/vp_vdpa.c new file +455 -0
455 lines not on this page · raw message
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 19/19] vdpa: introduce virtio pci driver
Quoted 22 lines · Jason Wang
This patch introduce a vDPA driver for virtio-pci device. It bridges the virtio-pci control command to the vDPA bus. This will be used for features prototyping and testing.
Note that get/restore virtqueue state is not supported which needs extension on the virtio specification.
Signed-off-by Jason Wang <[email protected]>---
drivers/vdpa/Kconfig | 6 + drivers/vdpa/Makefile | 1 + drivers/vdpa/virtio_pci/Makefile | 2 + drivers/vdpa/virtio_pci/vp_vdpa.c | 455 ++++++++++++++++++++++++++++++ 4 files changed, 464 insertions(+)create mode 100644
drivers/vdpa/virtio_pci/Makefilecreate mode 100644drivers/vdpa/virtio_pci/vp_vdpa.cdrivers/vdpa/Kconfig +0
-0
drivers/vdpa/Kconfig config MLX5_VDPA_NET · line 55
Quoted 8 lines
drivers/vdpa/Kconfig +5
-0@@ -48,4 +48,10 @@ config MLX5_VDPA_NET be executed by the hardware. It also supports a variety of stateless offloads depending on the actual device used and firmware version. +config VP_VDPA + tristate "Virtio PCI bridge vDPA driver" + depends on PCI_MSI && VIRTIO_PCI_MODERN + help + This kernel module that bridges virtio PCI device to vDPA bus.
^
Without 'that' maybe sound better, but I'm not a native speaker :-)
Quoted 41 lines
drivers/vdpa/Kconfig +1
-0+endif # VDPA
drivers/vdpa/Makefile +0
-0@@ -3,3 +3,4 @@ obj-$(CONFIG_VDPA) += vdpa.oobj-$(CONFIG_VDPA_SIM) += vdpa_sim/
obj-$(CONFIG_IFCVF) += ifcvf/
obj-$(CONFIG_MLX5_VDPA) += mlx5/drivers/vdpa/Makefile +1
-0+obj-$(CONFIG_VP_VDPA) += virtio_pci/drivers/vdpa/virtio_pci/Makefile new file +2
-0@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_VP_VDPA) += vp_vdpa.odrivers/vdpa/virtio_pci/vp_vdpa.c new file +16
-0@@ -0,0 +1,455 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* vDPA bridge driver for modern virtio-pci device +* +* Copyright (c) 2020, Red Hat Inc. All rights reserved. +* Author: Jason Wang <[email protected]> +* +* Based on virtio_pci_modern.c. +*/ + +#include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/pci.h> +#include <linux/vdpa.h> +#include <linux/virtio.h> +#include <linux/virtio_config.h>
drivers/vdpa/virtio_pci/vp_vdpa.c line 26
Quoted 10 lines
drivers/vdpa/virtio_pci/vp_vdpa.c new file +10
-0+#include <linux/virtio_ring.h> +#include <linux/virtio_pci.h> +#include <linux/virtio_pci_modern.h> + +#define VP_VDPA_QUEUE_MAX 256 +#define VP_VDPA_DRIVER_NAME "vp_vdpa" + +struct vp_vring { +void __iomem *notify; +char msix_name[256 ];
Can we use a macro for the msix_name size, since we use 256 in multiple places?
drivers/vdpa/virtio_pci/vp_vdpa.c line 35
Quoted 9 lines
drivers/vdpa/virtio_pci/vp_vdpa.c new file +9
-0+struct vdpa_callback cb; +int irq; +}; + +struct vp_vdpa { +struct vdpa_device vdpa; +struct virtio_pci_modern_device mdev; +struct vp_vring *vring; +struct vdpa_callback cb;
^
It is not relevant, but 'config_cb' is maybe clearer to read.
The rest looks good.
Thanks,
Stefano
Quoted 429 lines
drivers/vdpa/virtio_pci/vp_vdpa.c new file +331
-0+char msix_name[256 ]; +int config_irq; +int queues; +int vectors; +}; + +static struct vp_vdpa *vdpa_to_vp (struct vdpa_device *vdpa) +{ + return container_of(vdpa, struct vp_vdpa, vdpa); +} + +static struct virtio_pci_modern_device *vdpa_to_mdev (struct vdpa_device *vdpa) +{ +struct vp_vdpa *vp_vdpa =vdpa_to_vp (vdpa); + +return &vp_vdpa->mdev; +} + +static u64 vp_vdpa_get_features (struct vdpa_device *vdpa) +{ +struct virtio_pci_modern_device *mdev =vdpa_to_mdev (vdpa); + +return vp_modern_get_features (mdev); +} + +static int vp_vdpa_set_features (struct vdpa_device *vdpa,u64 features) +{ +struct virtio_pci_modern_device *mdev =vdpa_to_mdev (vdpa); + +vp_modern_set_features (mdev, features); + +return 0 ; +} + +static u8 vp_vdpa_get_status (struct vdpa_device *vdpa) +{ +struct virtio_pci_modern_device *mdev =vdpa_to_mdev (vdpa); + +return vp_modern_get_status (mdev); +} + +static void vp_vdpa_free_irq (struct vp_vdpa *vp_vdpa) +{ +struct virtio_pci_modern_device *mdev = &vp_vdpa->mdev; +struct pci_dev *pdev = mdev->pci_dev; +int i; + +for (i =0 ; i < vp_vdpa->queues; i++) { +if (vp_vdpa->vring[i].irq !=VIRTIO_MSI_NO_VECTOR ) { +vp_modern_queue_vector (mdev, i,VIRTIO_MSI_NO_VECTOR ); +devm_free_irq (&pdev->dev, vp_vdpa->vring[i].irq, + &vp_vdpa->vring[i]); + vp_vdpa->vring[i].irq =VIRTIO_MSI_NO_VECTOR ; + } + } + +if (vp_vdpa->config_irq !=VIRTIO_MSI_NO_VECTOR ) { +vp_modern_config_vector (mdev,VIRTIO_MSI_NO_VECTOR ); +devm_free_irq (&pdev->dev, vp_vdpa->config_irq, vp_vdpa); + vp_vdpa->config_irq =VIRTIO_MSI_NO_VECTOR ; + } + +if (vp_vdpa->vectors) { +pci_free_irq_vectors (pdev); + vp_vdpa->vectors =0 ; + } +} + +static irqreturn_t vp_vdpa_vq_handler (int irq,void *arg) +{ +struct vp_vring *vring = arg; + +if (vring->cb.callback) +return vring->cb.callback (vring->cb.private); + +return IRQ_HANDLED ; +} + +static irqreturn_t vp_vdpa_config_handler (int irq,void *arg) +{ +struct vp_vdpa *vp_vdpa = arg; + +if (vp_vdpa->cb.callback) +return vp_vdpa->cb.callback (vp_vdpa->cb.private); + +return IRQ_HANDLED ; +} + +static int vp_vdpa_request_irq (struct vp_vdpa *vp_vdpa) +{ +struct virtio_pci_modern_device *mdev = &vp_vdpa->mdev; +struct pci_dev *pdev = mdev->pci_dev; +int i, ret, irq; +int queues = vp_vdpa->queues; +int vectors = queues +1 ; + + ret =pci_alloc_irq_vectors (pdev, vectors, vectors,PCI_IRQ_MSIX ); +if (ret != vectors) { +dev_err (&pdev->dev, +"vp_vdpa: fail to allocate irq vectors want %d but %d\n" , + vectors, ret); +return ret; + } + + vp_vdpa->vectors = vectors; + +for (i =0 ; i < queues; i++) { +snprintf (vp_vdpa->vring[i].msix_name,256 , +"vp-vdpa[%s]-%d\n" ,pci_name (pdev), i); + irq =pci_irq_vector (pdev, i); + ret =devm_request_irq (&pdev->dev, irq, + vp_vdpa_vq_handler, +0 , vp_vdpa->vring[i].msix_name, + &vp_vdpa->vring[i]); +if (ret) { +dev_err (&pdev->dev, +"vp_vdpa: fail to request irq for vq %d\n" , i); + goto err; + } +vp_modern_queue_vector (mdev, i, i); + vp_vdpa->vring[i].irq = irq; + } + +snprintf (vp_vdpa->msix_name,256 ,"vp-vdpa[%s]-config\n" , +pci_name (pdev)); + irq =pci_irq_vector (pdev, queues); + ret =devm_request_irq (&pdev->dev, irq, vp_vdpa_config_handler,0 , + vp_vdpa->msix_name, vp_vdpa); +if (ret) { +dev_err (&pdev->dev, +"vp_vdpa: fail to request irq for vq %d\n" , i); + goto err; + } +vp_modern_config_vector (mdev, queues); + vp_vdpa->config_irq = irq; + +return 0 ; +err: +vp_vdpa_free_irq (vp_vdpa); +return ret; +} + +static void vp_vdpa_set_status (struct vdpa_device *vdpa,u8 status) +{ +struct vp_vdpa *vp_vdpa =vdpa_to_vp (vdpa); +struct virtio_pci_modern_device *mdev = &vp_vdpa->mdev; +u8 s =vp_vdpa_get_status (vdpa); + +if (status &VIRTIO_CONFIG_S_DRIVER_OK && + !(s &VIRTIO_CONFIG_S_DRIVER_OK )) { +vp_vdpa_request_irq (vp_vdpa); + } + +vp_modern_set_status (mdev, status); + +if (!(status &VIRTIO_CONFIG_S_DRIVER_OK ) && + (s &VIRTIO_CONFIG_S_DRIVER_OK )) +vp_vdpa_free_irq (vp_vdpa); +} + +static u16 vp_vdpa_get_vq_num_max (struct vdpa_device *vdpa) +{ +return VP_VDPA_QUEUE_MAX ; +} + +static int vp_vdpa_get_vq_state (struct vdpa_device *vdpa,u16 qid, +struct vdpa_vq_state *state) +{ +/* Note that this is not supported by virtio specification, so +* we return -EOPNOTSUPP here. This means we can't support live +* migration, vhost device start/stop. +*/ +return -EOPNOTSUPP ; +} + +static int vp_vdpa_set_vq_state (struct vdpa_device *vdpa,u16 qid, +const struct vdpa_vq_state *state) +{ +/* Note that this is not supported by virtio specification, so +* we return -ENOPOTSUPP here. This means we can't support live +* migration, vhost device start/stop. +*/ +return -EOPNOTSUPP ; +} + +static void vp_vdpa_set_vq_cb (struct vdpa_device *vdpa,u16 qid, +struct vdpa_callback *cb) +{ +struct vp_vdpa *vp_vdpa =vdpa_to_vp (vdpa); + + vp_vdpa->vring[qid].cb = *cb; +} + +static void vp_vdpa_set_vq_ready (struct vdpa_device *vdpa, +u16 qid,bool ready) +{ +struct virtio_pci_modern_device *mdev =vdpa_to_mdev (vdpa); + +vp_modern_set_queue_enable (mdev, qid, ready); +} + +static bool vp_vdpa_get_vq_ready (struct vdpa_device *vdpa,u16 qid) +{ +struct virtio_pci_modern_device *mdev =vdpa_to_mdev (vdpa); + +return vp_modern_get_queue_enable (mdev, qid); +} + +static void vp_vdpa_set_vq_num (struct vdpa_device *vdpa,u16 qid, +u32 num) +{ +struct virtio_pci_modern_device *mdev =vdpa_to_mdev (vdpa); + +vp_modern_set_queue_size (mdev, qid, num); +} + +static int vp_vdpa_set_vq_address (struct vdpa_device *vdpa,u16 qid, +u64 desc_area,u64 driver_area, +u64 device_area) +{ +struct virtio_pci_modern_device *mdev =vdpa_to_mdev (vdpa); + +vp_modern_queue_address (mdev, qid, desc_area, + driver_area, device_area); + +return 0 ; +} + +static void vp_vdpa_kick_vq (struct vdpa_device *vdpa,u16 qid) +{ +struct vp_vdpa *vp_vdpa =vdpa_to_vp (vdpa); + +vp_iowrite16 (qid, vp_vdpa->vring[qid].notify); +} + +static u32 vp_vdpa_get_generation (struct vdpa_device *vdpa) +{ +struct virtio_pci_modern_device *mdev =vdpa_to_mdev (vdpa); + +return vp_modern_generation (mdev); +} + +static u32 vp_vdpa_get_device_id (struct vdpa_device *vdpa) +{ +struct virtio_pci_modern_device *mdev =vdpa_to_mdev (vdpa); + +return mdev->id.device; +} + +static u32 vp_vdpa_get_vendor_id (struct vdpa_device *vdpa) +{ +struct virtio_pci_modern_device *mdev =vdpa_to_mdev (vdpa); + +return mdev->id.vendor; +} + +static u32 vp_vdpa_get_vq_align (struct vdpa_device *vdpa) +{ +return PAGE_SIZE ; +} + +static void vp_vdpa_get_config (struct vdpa_device *vdpa, +unsigned int offset, +void *buf,unsigned int len) +{ +struct vp_vdpa *vp_vdpa =vdpa_to_vp (vdpa); +struct virtio_pci_modern_device *mdev = &vp_vdpa->mdev; +u8 old, new; +u8 *p; +int i; + +do { + old =vp_ioread8 (&mdev->common->config_generation); + p = buf; +for (i =0 ; i < len; i++) + *p++ =vp_ioread8 (mdev->device + offset + i); + + new =vp_ioread8 (&mdev->common->config_generation); + }while (old != new); +} + +static void vp_vdpa_set_config (struct vdpa_device *vdpa, +unsigned int offset,const void *buf, +unsigned int len) +{ +struct vp_vdpa *vp_vdpa =vdpa_to_vp (vdpa); +struct virtio_pci_modern_device *mdev = &vp_vdpa->mdev; +const u8 *p = buf; +int i; + +for (i =0 ; i < len; i++) +vp_iowrite8 (*p++, mdev->device + offset + i); +} + +static void vp_vdpa_set_config_cb (struct vdpa_device *vdpa, +struct vdpa_callback *cb) +{ +struct vp_vdpa *vp_vdpa =vdpa_to_vp (vdpa); + + vp_vdpa->cb = *cb; +} + +static const struct vdpa_config_ops vp_vdpa_ops = { + .get_features = vp_vdpa_get_features, + .set_features = vp_vdpa_set_features, + .get_status = vp_vdpa_get_status, + .set_status = vp_vdpa_set_status, + .get_vq_num_max = vp_vdpa_get_vq_num_max, + .get_vq_state = vp_vdpa_get_vq_state, + .set_vq_state = vp_vdpa_set_vq_state, + .set_vq_cb = vp_vdpa_set_vq_cb, + .set_vq_ready = vp_vdpa_set_vq_ready, + .get_vq_ready = vp_vdpa_get_vq_ready, + .set_vq_num = vp_vdpa_set_vq_num, + .set_vq_address = vp_vdpa_set_vq_address, + .kick_vq = vp_vdpa_kick_vq, + .get_generation = vp_vdpa_get_generation, + .get_device_id = vp_vdpa_get_device_id, + .get_vendor_id = vp_vdpa_get_vendor_id, + .get_vq_align = vp_vdpa_get_vq_align, + .get_config = vp_vdpa_get_config, + .set_config = vp_vdpa_set_config, + .set_config_cb = vp_vdpa_set_config_cb, +}; + +static void vp_vdpa_free_irq_vectors (void *data) +{ +pci_free_irq_vectors (data); +} + +static int vp_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id*id)
drivers/vdpa/virtio_pci/vp_vdpa.c new file +89
-0+{ +struct virtio_pci_modern_device *mdev; +struct device *dev = &pdev->dev; +struct vp_vdpa *vp_vdpa; +u16 notify_off; +int ret, i; + + ret =pcim_enable_device (pdev); +if (ret) +return ret; + + vp_vdpa = vdpa_alloc_device(struct vp_vdpa, vdpa, + dev, &vp_vdpa_ops); +if (vp_vdpa ==NULL ) { +dev_err (dev,"vp_vdpa: Failed to allocate vDPA structure\n" ); +return -ENOMEM ; + } + + mdev = &vp_vdpa->mdev; + mdev->pci_dev = pdev; + +if (vp_modern_probe (mdev)) { +dev_err (&pdev->dev,"Failed to probe modern PCI device\n" ); + goto err; + } + +pci_set_master (pdev); +pci_set_drvdata (pdev, vp_vdpa); + + vp_vdpa->vdpa.dma_dev = &pdev->dev; + vp_vdpa->queues =vp_modern_get_num_queues (mdev); + + ret =devm_add_action_or_reset (dev, vp_vdpa_free_irq_vectors, pdev); +if (ret) { +dev_err (&pdev->dev, +"Failed for adding devres for freeing irq vectors\n" ); + goto err; + } + + vp_vdpa->vring =devm_kcalloc (&pdev->dev, vp_vdpa->queues, +sizeof (*vp_vdpa->vring), +GFP_KERNEL ); +if (!vp_vdpa->vring) { +dev_err (&pdev->dev,"Fail to allocate virtqueues\n" ); + goto err; + } + +for (i =0 ; i < vp_vdpa->queues; i++) { + notify_off =vp_modern_get_queue_notify_off (mdev, i); + vp_vdpa->vring[i].irq =VIRTIO_MSI_NO_VECTOR ; + vp_vdpa->vring[i].notify = mdev->notify_base + + notify_off * mdev->notify_offset_multiplier; + } + vp_vdpa->config_irq =VIRTIO_MSI_NO_VECTOR ; + + ret =vdpa_register_device (&vp_vdpa->vdpa, vp_vdpa->queues); +if (ret) { +dev_err (&pdev->dev,"Failed to register to vdpa bus\n" ); + goto err; + } + +return 0 ; + +err: +put_device (&vp_vdpa->vdpa.dev); +return ret; +} + +static void vp_vdpa_remove (struct pci_dev *pdev) +{ +struct vp_vdpa *vp_vdpa =pci_get_drvdata (pdev); + +vdpa_unregister_device (&vp_vdpa->vdpa); +vp_modern_remove (&vp_vdpa->mdev); +} + +static struct pci_driver vp_vdpa_driver = { + .name ="vp-vdpa" , + .id_table =NULL ,/* only dynamic ids */ + .probe = vp_vdpa_probe, + .remove = vp_vdpa_remove, +}; + +module_pci_driver (vp_vdpa_driver); + +MODULE_AUTHOR ("Jason Wang <[email protected]>" ); +MODULE_DESCRIPTION ("vp-vdpa" ); +MODULE_LICENSE ("GPL" ); +MODULE_VERSION ("1" );Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 19/19] vdpa: introduce virtio pci driver
Quoted 26 lines · Stefano Garzarella
Quoted 25 lines · Jason Wang
This patch introduce a vDPA driver for virtio-pci device. It bridges the virtio-pci control command to the vDPA bus. This will be used for features prototyping and testing.
Note that get/restore virtqueue state is not supported which needs extension on the virtio specification.
Signed-off-by Jason Wang <[email protected]>---
drivers/vdpa/Kconfig | 6 + drivers/vdpa/Makefile | 1 + drivers/vdpa/virtio_pci/Makefile | 2 +drivers/vdpa/virtio_pci/vp_vdpa.c| 455 ++++++++++++++++++++++++++++++4 files changed, 464 insertions(+)create mode 100644
drivers/vdpa/virtio_pci/Makefilecreate mode 100644drivers/vdpa/virtio_pci/vp_vdpa.cdrivers/vdpa/Kconfig +0
-0@@ -48,4 +48,10 @@ config MLX5_VDPA_NETbe executed by the hardware. It also supports a variety of stateless offloads depending on the actual device used and firmware version.
Quoted 7 lines
Quoted 5 lines
+config
VP_VDPA
+ tristate "Virtio PCI bridge vDPA driver"
+ depends onPCI_MSI&&VIRTIO_PCI_MODERN
+ help
+ This kernel module that bridges virtio PCI device to vDPA bus.^
Without 'that' maybe sound better, but I'm not a native speaker :-)
Yes, drop 'that', please.
Quoted 2 lines
Quoted 2 lines
+
endif # VDPA
Signature · 6 lines
~Randy _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 19/19] vdpa: introduce virtio pci driver
Quoted 27 lines · Randy Dunlap
Quoted 26 lines · Stefano Garzarella
Quoted 25 lines · Jason Wang
This patch introduce a vDPA driver for virtio-pci device. It bridges the virtio-pci control command to the vDPA bus. This will be used for features prototyping and testing.
Note that get/restore virtqueue state is not supported which needs extension on the virtio specification.
Signed-off-by Jason Wang <[email protected]>---
drivers/vdpa/Kconfig | 6 + drivers/vdpa/Makefile | 1 + drivers/vdpa/virtio_pci/Makefile | 2 +drivers/vdpa/virtio_pci/vp_vdpa.c| 455 ++++++++++++++++++++++++++++++4 files changed, 464 insertions(+)create mode 100644
drivers/vdpa/virtio_pci/Makefilecreate mode 100644drivers/vdpa/virtio_pci/vp_vdpa.cdrivers/vdpa/Kconfig +0
-0@@ -48,4 +48,10 @@ config MLX5_VDPA_NET be executed by the hardware. It also supports a variety of stateless offloads depending on the actual device used and firmware version.
Quoted 8 lines
Quoted 7 lines
drivers/vdpa/Kconfig config MLX5_VDPA_NET · line 55
Quoted 5 lines
drivers/vdpa/Kconfig +5
-0+config VP_VDPA + tristate "Virtio PCI bridge vDPA driver" + depends on PCI_MSI && VIRTIO_PCI_MODERN + help + This kernel module that bridges virtio PCI device to vDPA bus.^
Without 'that' maybe sound better, but I'm not a native speaker :-)Yes, drop 'that', please.
Will fix.
Thanks
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/vdpa/Kconfig +1
-0+endif # VDPA
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 19/19] vdpa: introduce virtio pci driver
In reply to Stefano GarzarellaQuoted 8 lines · Stefano Garzarella
drivers/vdpa/virtio_pci/vp_vdpa.c line 26
Quoted 6 lines
drivers/vdpa/virtio_pci/vp_vdpa.c new file +6
-0+#define VP_VDPA_QUEUE_MAX 256 +#define VP_VDPA_DRIVER_NAME "vp_vdpa" + +struct vp_vring { + void __iomem *notify; + char msix_name[256];Can we use a macro for the
msix_namesize, since we use 256 in multiple places?
Yes, will switch to use a macro.
Quoted 13 lines
drivers/vdpa/virtio_pci/vp_vdpa.c line 35
Quoted 10 lines
+ struct
vdpa_callbackcb;
+ int irq;drivers/vdpa/virtio_pci/vp_vdpa.c new file +7
-0+}; + +struct vp_vdpa { + struct vdpa_device vdpa; + struct virtio_pci_modern_device mdev; + struct vp_vring *vring; + struct vdpa_callback cb;^
It is not relevant, but 'config_cb' is maybe clearer to read.
Will change to config_cb.
Quoted 1 line
The rest looks good.
Thanks
Quoted 3 lines
Thanks,
Stefano
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 15 lines · Jason Wang
Hi all:
This series tries to implement a vDPA driver for virtio-pci device which will bridge between vDPA bus and virtio-pci device.
This could be used for future feature prototyping and testing.
Please review
Changes from V2:
- don't try to use devres for virtio-pci core
- tweak the commit log
- split the patches furtherly to ease the reviewing
Quoted 7 lines
Changes from V1:
- Split common codes from virito-pci and share it with vDPA driver
- Use dynamic id in order to be less confusing with virtio-pci driver
- No feature whitelist, supporting any features (mq, config etc)Thanks
Michael, any comment for this series?
It's needed for testing doorbell mapping and config interrupt support.
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerQuoted 23 lines · Jason Wang
Quoted 21 lines · Jason Wang
Hi all:
This series tries to implement a vDPA driver for virtio-pci device which will bridge between vDPA bus and virtio-pci device.
This could be used for future feature prototyping and testing.
Please review
Changes from V2:
- don't try to use devres for virtio-pci core
- tweak the commit log
- split the patches furtherly to ease the reviewingChanges from V1:
- Split common codes from virito-pci and share it with vDPA driver
- Use dynamic id in order to be less confusing with virtio-pci driver
- No feature whitelist, supporting any features (mq, config etc)
Quoted 8 lines
Quoted 1 line
Thanks
Michael, any comment for this series?
It's needed for testing doorbell mapping and config interrupt support.
Thanks
I saw you got some comments back in december so was expecting another version. If you'd rather I reviewed this one, let me know.
Signature · 6 lines
MST _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 25 lines · Michael S. Tsirkin
Quoted 24 lines · Jason Wang
Quoted 22 lines · Jason Wang
Hi all:
This series tries to implement a vDPA driver for virtio-pci device which will bridge between vDPA bus and virtio-pci device.
This could be used for future feature prototyping and testing.
Please review
Changes from V2:
- don't try to use devres for virtio-pci core
- tweak the commit log
- split the patches furtherly to ease the reviewingChanges from V1:
- Split common codes from virito-pci and share it with vDPA driver
- Use dynamic id in order to be less confusing with virtio-pci driver
- No feature whitelist, supporting any features (mq, config etc)Thanks
Quoted 7 lines
Quoted 5 lines
Michael, any comment for this series?
It's needed for testing doorbell mapping and config interrupt support.
Thanks
I saw you got some comments back in december so was expecting another version. If you'd rather I reviewed this one, let me know.
Right. So I've posted a new version that tries to address the previous comments.
Please review that version.
Thanks
Quoted 1 line
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization