Skip to contentSkip to conversation

vDPA driver for legacy virtio-pci device

PATCH Superseded Wu Zongyong 6 participants 150 messages Sep 8, 2021 – Nov 1, 2021 3 messages not in the archive Page 2 of 2

Subsystems (2)
lore
Share & tools
lore
#85 lore raw

Re: [PATCH v4 1/7] virtio-pci: introduce legacy device module

In reply to Wu Zongyong
Quoted 609 lines · Wu Zongyong

Split common codes from virtio-pci-legacy so vDPA driver can reuse it later.

---
  drivers/virtio/Kconfig                 |  10 ++
  drivers/virtio/Makefile                |   1 +
  drivers/virtio/virtio_pci_common.c     |  10 +-
  drivers/virtio/virtio_pci_common.h     |   9 +-
  drivers/virtio/virtio_pci_legacy.c     | 101 +++---------
  drivers/virtio/virtio_pci_legacy_dev.c | 220 +++++++++++++++++++++++++
  include/linux/virtio_pci_legacy.h      |  44 +++++
  7 files changed, 312 insertions(+), 83 deletions(-)

create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c create mode 100644 include/linux/virtio_pci_legacy.h

drivers/virtio/Kconfig +10 -0
index ce1b3f6ec325..8fcf94cd2c96 100644
@@ -20,6 +20,15 @@ config VIRTIO_PCI_LIB
  	  PCI device with possible vendor specific extensions. Any
  	  module that selects this module must depend on PCI.
 
+config VIRTIO_PCI_LIB_LEGACY
+	tristate
+	help
+	  Legacy PCI device (Virtio PCI Card 0.9.x Draft and older device)
+	  implementation.
+	  This module implements the basic probe and control for devices
+	  which are based on legacy PCI device. Any module that selects this
+	  module must depend on PCI.
+
  menuconfig VIRTIO_MENU
  	bool "Virtio drivers"
  	default y
@@ -43,6 +52,7 @@ config VIRTIO_PCI_LEGACY
  	bool "Support for legacy virtio draft 0.9.X and older devices"
  	default y
  	depends on VIRTIO_PCI
+	select VIRTIO_PCI_LIB_LEGACY
  	help
            Virtio PCI Card 0.9.X Draft (circa 2014) and older device support.
 
drivers/virtio/Makefile +1 -0
index 699bbea0465f..0a82d0873248 100644
@@ -1,6 +1,7 @@
  # SPDX-License-Identifier: GPL-2.0
  obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
  obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o
+obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_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.c +6 -4
index b35bb2d57f62..d724f676608b 100644
@@ -549,6 +549,8 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 
  	pci_set_master(pci_dev);
 
+	vp_dev->is_legacy = vp_dev->ldev.ioaddr ? true : false;
+
  	rc = register_virtio_device(&vp_dev->vdev);
  	reg_dev = vp_dev;
  	if (rc)
@@ -557,10 +559,10 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
  	return 0;
 
  err_register:
-	if (vp_dev->ioaddr)
-	     virtio_pci_legacy_remove(vp_dev);
+	if (vp_dev->is_legacy)
+		virtio_pci_legacy_remove(vp_dev);
  	else
-	     virtio_pci_modern_remove(vp_dev);
+		virtio_pci_modern_remove(vp_dev);
  err_probe:
  	pci_disable_device(pci_dev);
  err_enable_device:
@@ -587,7 +589,7 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
 
  	unregister_virtio_device(&vp_dev->vdev);
 
-	if (vp_dev->ioaddr)
+	if (vp_dev->is_legacy)
  		virtio_pci_legacy_remove(vp_dev);
  	else
  		virtio_pci_modern_remove(vp_dev);
drivers/virtio/virtio_pci_common.h +4 -5
index beec047a8f8d..eb17a29fc7ef 100644
@@ -25,6 +25,7 @@
  #include <linux/virtio_config.h>
  #include <linux/virtio_ring.h>
  #include <linux/virtio_pci.h>
+#include <linux/virtio_pci_legacy.h>
  #include <linux/virtio_pci_modern.h>
  #include <linux/highmem.h>
  #include <linux/spinlock.h>
@@ -44,16 +45,14 @@ struct virtio_pci_vq_info {
  struct virtio_pci_device {
  	struct virtio_device vdev;
  	struct pci_dev *pci_dev;
+	struct virtio_pci_legacy_device ldev;
  	struct virtio_pci_modern_device mdev;
 
-	/* In legacy mode, these two point to within ->legacy. */
+	bool is_legacy;
+
  	/* Where to read and clear interrupt */
  	u8 __iomem *isr;
 
-	/* Legacy only field */
-	/* the IO mapping for the PCI config space */
-	void __iomem *ioaddr;
-
  	/* a list of queues so we can dispatch IRQs */
  	spinlock_t lock;
  	struct list_head virtqueues;
drivers/virtio/virtio_pci_legacy.c +27 -74
index d62e9835aeec..82eb437ad920 100644
@@ -14,6 +14,7 @@
   *  Michael S. Tsirkin <[email protected]>
   */
 
+#include "linux/virtio_pci_legacy.h"
  #include "virtio_pci_common.h"
 
  /* virtio config->get_features() implementation */
@@ -23,7 +24,7 @@ static u64 vp_get_features(struct virtio_device *vdev)
 
  	/* When someone needs more than 32 feature bits, we'll need to
  	 * steal a bit to indicate that the rest are somewhere else. */
-	return ioread32(vp_dev->ioaddr + VIRTIO_PCI_HOST_FEATURES);
+	return vp_legacy_get_features(&vp_dev->ldev);
  }
 
  /* virtio config->finalize_features() implementation */
@@ -38,7 +39,7 @@ static int vp_finalize_features(struct virtio_device *vdev)
  	BUG_ON((u32)vdev->features != vdev->features);
 
  	/* We only support 32 feature bits. */
-	iowrite32(vdev->features, vp_dev->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
+	vp_legacy_set_features(&vp_dev->ldev, vdev->features);
 
  	return 0;
  }
@@ -48,7 +49,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 *ioaddr = vp_dev->ioaddr +
+	void __iomem *ioaddr = vp_dev->ldev.ioaddr +
  			VIRTIO_PCI_CONFIG_OFF(vp_dev->msix_enabled) +
  			offset;
  	u8 *ptr = buf;
@@ -64,7 +65,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 *ioaddr = vp_dev->ioaddr +
+	void __iomem *ioaddr = vp_dev->ldev.ioaddr +
  			VIRTIO_PCI_CONFIG_OFF(vp_dev->msix_enabled) +
  			offset;
  	const u8 *ptr = buf;
@@ -78,7 +79,7 @@ static void vp_set(struct virtio_device *vdev, unsigned offset,
  static u8 vp_get_status(struct virtio_device *vdev)
  {
  	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-	return ioread8(vp_dev->ioaddr + VIRTIO_PCI_STATUS);
+	return vp_legacy_get_status(&vp_dev->ldev);
  }
 
  static void vp_set_status(struct virtio_device *vdev, u8 status)
@@ -86,28 +87,24 @@ static void vp_set_status(struct virtio_device *vdev, u8 status)
  	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
  	/* We should never be setting status to 0. */
  	BUG_ON(status == 0);
-	iowrite8(status, vp_dev->ioaddr + VIRTIO_PCI_STATUS);
+	vp_legacy_set_status(&vp_dev->ldev, status);
  }
 
  static void vp_reset(struct virtio_device *vdev)
  {
  	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
  	/* 0 status means a reset. */
-	iowrite8(0, vp_dev->ioaddr + VIRTIO_PCI_STATUS);
+	vp_legacy_set_status(&vp_dev->ldev, 0);
  	/* Flush out the status write, and flush in device writes,
  	 * including MSi-X interrupts, if any. */
-	ioread8(vp_dev->ioaddr + VIRTIO_PCI_STATUS);
+	vp_legacy_get_status(&vp_dev->ldev);
  	/* Flush pending VQ/configuration callbacks. */
  	vp_synchronize_vectors(vdev);
  }
 
  static u16 vp_config_vector(struct virtio_pci_device *vp_dev, u16 vector)
  {
-	/* Setup the vector used for configuration events */
-	iowrite16(vector, vp_dev->ioaddr + VIRTIO_MSI_CONFIG_VECTOR);
-	/* Verify we had enough resources to assign the vector */
-	/* Will also flush the write out to device */
-	return ioread16(vp_dev->ioaddr + VIRTIO_MSI_CONFIG_VECTOR);
+	return vp_legacy_config_vector(&vp_dev->ldev, vector);
  }
 
  static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
@@ -123,12 +120,9 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
  	int err;
  	u64 q_pfn;
 
-	/* Select the queue we're interested in */
-	iowrite16(index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
-
  	/* Check if queue is either not available or already active. */
-	num = ioread16(vp_dev->ioaddr + VIRTIO_PCI_QUEUE_NUM);
-	if (!num || ioread32(vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN))
+	num = vp_legacy_get_queue_size(&vp_dev->ldev, index);
+	if (!num || vp_legacy_get_queue_enable(&vp_dev->ldev, index))
  		return ERR_PTR(-ENOENT);
 
  	info->msix_vector = msix_vec;
@@ -151,13 +145,12 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
  	}
 
  	/* activate the queue */
-	iowrite32(q_pfn, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
+	vp_legacy_set_queue_address(&vp_dev->ldev, index, q_pfn);
 
-	vq->priv = (void __force *)vp_dev->ioaddr + VIRTIO_PCI_QUEUE_NOTIFY;
+	vq->priv = (void __force *)vp_dev->ldev.ioaddr + VIRTIO_PCI_QUEUE_NOTIFY;
 
  	if (msix_vec != VIRTIO_MSI_NO_VECTOR) {
-		iowrite16(msix_vec, vp_dev->ioaddr + VIRTIO_MSI_QUEUE_VECTOR);
-		msix_vec = ioread16(vp_dev->ioaddr + VIRTIO_MSI_QUEUE_VECTOR);
+		msix_vec = vp_legacy_queue_vector(&vp_dev->ldev, index, msix_vec);
  		if (msix_vec == VIRTIO_MSI_NO_VECTOR) {
  			err = -EBUSY;
  			goto out_deactivate;
@@ -167,7 +160,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
  	return vq;
 
  out_deactivate:
-	iowrite32(0, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
+	vp_legacy_set_queue_address(&vp_dev->ldev, index, 0);
  out_del_vq:
  	vring_del_virtqueue(vq);
  	return ERR_PTR(err);
@@ -178,17 +171,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);
 
-	iowrite16(vq->index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
-
  	if (vp_dev->msix_enabled) {
-		iowrite16(VIRTIO_MSI_NO_VECTOR,
-			  vp_dev->ioaddr + VIRTIO_MSI_QUEUE_VECTOR);
+		vp_legacy_queue_vector(&vp_dev->ldev, vq->index,
+				VIRTIO_MSI_NO_VECTOR);
  		/* Flush the write out to device */
-		ioread8(vp_dev->ioaddr + VIRTIO_PCI_ISR);
+		ioread8(vp_dev->ldev.ioaddr + VIRTIO_PCI_ISR);
  	}
 
  	/* Select and deactivate the queue */
-	iowrite32(0, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
+	vp_legacy_set_queue_address(&vp_dev->ldev, vq->index, 0);
 
  	vring_del_virtqueue(vq);
  }
@@ -211,51 +202,18 @@ static const struct virtio_config_ops virtio_pci_config_ops = {
  /* the PCI probing function */
  int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)
  {
+	struct virtio_pci_legacy_device *ldev = &vp_dev->ldev;
  	struct pci_dev *pci_dev = vp_dev->pci_dev;
  	int rc;
 
-	/* We only own devices >= 0x1000 and <= 0x103f: leave the rest. */
-	if (pci_dev->device < 0x1000 || pci_dev->device > 0x103f)
-		return -ENODEV;
-
-	if (pci_dev->revision != VIRTIO_PCI_ABI_VERSION) {
-		printk(KERN_ERR "virtio_pci: expected ABI version %d, got %d\n",
-		       VIRTIO_PCI_ABI_VERSION, pci_dev->revision);
-		return -ENODEV;
-	}
-
-	rc = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(64));
-	if (rc) {
-		rc = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(32));
-	} else {
-		/*
-		 * The virtio ring base address is expressed as a 32-bit PFN,
-		 * with a page size of 1 << VIRTIO_PCI_QUEUE_ADDR_SHIFT.
-		 */
-		dma_set_coherent_mask(&pci_dev->dev,
-				DMA_BIT_MASK(32 + VIRTIO_PCI_QUEUE_ADDR_SHIFT));
-	}
-
-	if (rc)
-		dev_warn(&pci_dev->dev, "Failed to enable 64-bit or 32-bit DMA.  Trying to continue, but this might not work.\n");
+	ldev->pci_dev = pci_dev;
 
-	rc = pci_request_region(pci_dev, 0, "virtio-pci-legacy");
+	rc = vp_legacy_probe(ldev);
  	if (rc)
  		return rc;
 
-	rc = -ENOMEM;
-	vp_dev->ioaddr = pci_iomap(pci_dev, 0, 0);
-	if (!vp_dev->ioaddr)
-		goto err_iomap;
-
-	vp_dev->isr = vp_dev->ioaddr + VIRTIO_PCI_ISR;
-
-	/* we use the subsystem vendor/device id as the virtio vendor/device
-	 * id.  this allows us to use the same PCI vendor/device id for all
-	 * virtio devices and to identify the particular virtio driver by
-	 * the subsystem ids */
-	vp_dev->vdev.id.vendor = pci_dev->subsystem_vendor;
-	vp_dev->vdev.id.device = pci_dev->subsystem_device;
+	vp_dev->isr = ldev->isr;
+	vp_dev->vdev.id = ldev->id;
 
  	vp_dev->vdev.config = &virtio_pci_config_ops;
 
@@ -264,16 +222,11 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)
  	vp_dev->del_vq = del_vq;
 
  	return 0;
-
-err_iomap:
-	pci_release_region(pci_dev, 0);
-	return rc;
  }
 
  void virtio_pci_legacy_remove(struct virtio_pci_device *vp_dev)
  {
-	struct pci_dev *pci_dev = vp_dev->pci_dev;
+	struct virtio_pci_legacy_device *ldev = &vp_dev->ldev;
 
-	pci_iounmap(pci_dev, vp_dev->ioaddr);
-	pci_release_region(pci_dev, 0);
+	vp_legacy_remove(ldev);
  }
drivers/virtio/virtio_pci_legacy_dev.c new file +220 -0
new file mode 100644
index 000000000000..9b97680dd02b
@@ -0,0 +1,220 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "linux/virtio_pci.h"
+#include <linux/virtio_pci_legacy.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+
+
+/*
+ * vp_legacy_probe: probe the legacy virtio pci device, note that the
+ * caller is required to enable PCI device before calling this function.
+ * @ldev: the legacy virtio-pci device
+ *
+ * Return 0 on succeed otherwise fail
+ */
+int vp_legacy_probe(struct virtio_pci_legacy_device *ldev)
+{
+	struct pci_dev *pci_dev = ldev->pci_dev;
+	int rc;
+
+	/* We only own devices >= 0x1000 and <= 0x103f: leave the rest. */
+	if (pci_dev->device < 0x1000 || pci_dev->device > 0x103f)
+		return -ENODEV;
+
+	if (pci_dev->revision != VIRTIO_PCI_ABI_VERSION)
+		return -ENODEV;
+
+	rc = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(64));
+	if (rc) {
+		rc = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(32));
+	} else {
+		/*
+		 * The virtio ring base address is expressed as a 32-bit PFN,
+		 * with a page size of 1 << VIRTIO_PCI_QUEUE_ADDR_SHIFT.
+		 */
+		dma_set_coherent_mask(&pci_dev->dev,
+				DMA_BIT_MASK(32 + VIRTIO_PCI_QUEUE_ADDR_SHIFT));
+	}
+
+	if (rc)
+		dev_warn(&pci_dev->dev, "Failed to enable 64-bit or 32-bit DMA.  Trying to continue, but this might not work.\n");
+
+	rc = pci_request_region(pci_dev, 0, "virtio-pci-legacy");
+	if (rc)
+		return rc;
+
+	ldev->ioaddr = pci_iomap(pci_dev, 0, 0);
+	if (!ldev->ioaddr)
+		goto err_iomap;
+
+	ldev->isr = ldev->ioaddr + VIRTIO_PCI_ISR;
+
+	ldev->id.vendor = pci_dev->subsystem_vendor;
+	ldev->id.device = pci_dev->subsystem_device;
+
+	return 0;
+err_iomap:
+	pci_release_region(pci_dev, 0);
+	return rc;
+}
+EXPORT_SYMBOL_GPL(vp_legacy_probe);
+
+/*
+ * vp_legacy_probe: remove and cleanup the legacy virtio pci device
+ * @ldev: the legacy virtio-pci device
+ */
+void vp_legacy_remove(struct virtio_pci_legacy_device *ldev)
+{
+	struct pci_dev *pci_dev = ldev->pci_dev;
+
+	pci_iounmap(pci_dev, ldev->ioaddr);
+	pci_release_region(pci_dev, 0);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_remove);
+
+/*
+ * vp_legacy_get_features - get features from device
+ * @ldev: the legacy virtio-pci device
+ *
+ * Returns the features read from the device
+ */
+u64 vp_legacy_get_features(struct virtio_pci_legacy_device *ldev)
+{
+
+	return ioread32(ldev->ioaddr + VIRTIO_PCI_HOST_FEATURES);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_get_features);
+
+/*
+ * vp_legacy_get_driver_features - get driver features from device
+ * @ldev: the legacy virtio-pci device
+ *
+ * Returns the driver features read from the device
+ */
+u64 vp_legacy_get_driver_features(struct virtio_pci_legacy_device *ldev)
+{
+	return ioread32(ldev->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_get_driver_features);
+
+/*
+ * vp_legacy_set_features - set features to device
+ * @ldev: the legacy virtio-pci device
+ * @features: the features set to device
+ */
+void vp_legacy_set_features(struct virtio_pci_legacy_device *ldev,
+			    u32 features)
+{
+	iowrite32(features, ldev->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_set_features);
+
+/*
+ * vp_legacy_get_status - get the device status
+ * @ldev: the legacy virtio-pci device
+ *
+ * Returns the status read from device
+ */
+u8 vp_legacy_get_status(struct virtio_pci_legacy_device *ldev)
+{
+	return ioread8(ldev->ioaddr + VIRTIO_PCI_STATUS);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_get_status);
+
+/*
+ * vp_legacy_set_status - set status to device
+ * @ldev: the legacy virtio-pci device
+ * @status: the status set to device
+ */
+void vp_legacy_set_status(struct virtio_pci_legacy_device *ldev,
+				 u8 status)
+{
+	iowrite8(status, ldev->ioaddr + VIRTIO_PCI_STATUS);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_set_status);
+
+/*
+ * vp_legacy_queue_vector - set the MSIX vector for a specific virtqueue
+ * @ldev: the legacy virtio-pci device
+ * @index: queue index
+ * @vector: the config vector
+ *
+ * Returns the config vector read from the device
+ */
+u16 vp_legacy_queue_vector(struct virtio_pci_legacy_device *ldev,
+			   u16 index, u16 vector)
+{
+	iowrite16(index, ldev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
+	iowrite16(vector, ldev->ioaddr + VIRTIO_MSI_QUEUE_VECTOR);
+	/* Flush the write out to device */
+	return ioread16(ldev->ioaddr + VIRTIO_MSI_QUEUE_VECTOR);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_queue_vector);
+
+/*
+ * vp_legacy_config_vector - set the vector for config interrupt
+ * @ldev: the legacy virtio-pci device
+ * @vector: the config vector
+ *
+ * Returns the config vector read from the device
+ */
+u16 vp_legacy_config_vector(struct virtio_pci_legacy_device *ldev,
+			    u16 vector)
+{
+	/* Setup the vector used for configuration events */
+	iowrite16(vector, ldev->ioaddr + VIRTIO_MSI_CONFIG_VECTOR);
+	/* Verify we had enough resources to assign the vector */
+	/* Will also flush the write out to device */
+	return ioread16(ldev->ioaddr + VIRTIO_MSI_CONFIG_VECTOR);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_config_vector);
+
+/*
+ * vp_legacy_set_queue_address - set the virtqueue address
+ * @ldev: the legacy virtio-pci device
+ * @index: the queue index
+ * @queue_pfn: pfn of the virtqueue
+ */
+void vp_legacy_set_queue_address(struct virtio_pci_legacy_device *ldev,
+			     u16 index, u32 queue_pfn)
+{
+	iowrite16(index, ldev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
+	iowrite32(queue_pfn, ldev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_set_queue_address);
+
+/*
+ * vp_legacy_get_queue_enable - enable a virtqueue
+ * @ldev: the legacy virtio-pci device
+ * @index: the queue index
+ *
+ * Returns whether a virtqueue is enabled or not
+ */
+bool vp_legacy_get_queue_enable(struct virtio_pci_legacy_device *ldev,
+				u16 index)
+{
+	iowrite16(index, ldev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
+	return ioread32(ldev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_get_queue_enable);
+
+/*
+ * vp_legacy_get_queue_size - get size for a virtqueue
+ * @ldev: the legacy virtio-pci device
+ * @index: the queue index
+ *
+ * Returns the size of the virtqueue
+ */
+u16 vp_legacy_get_queue_size(struct virtio_pci_legacy_device *ldev,
+			     u16 index)
+{
+	iowrite16(index, ldev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
+	return ioread16(ldev->ioaddr + VIRTIO_PCI_QUEUE_NUM);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_get_queue_size);
+
+MODULE_VERSION("0.1");
+MODULE_DESCRIPTION("Legacy Virtio PCI Device");
+MODULE_AUTHOR("Wu Zongyong <[email protected]>");
+MODULE_LICENSE("GPL");
include/linux/virtio_pci_legacy.h new file +24 -0
new file mode 100644
index 000000000000..ee2c6157215f
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_VIRTIO_PCI_LEGACY_H
+#define _LINUX_VIRTIO_PCI_LEGACY_H
+
+#include "linux/mod_devicetable.h"
+#include <linux/pci.h>
+#include <linux/virtio_pci.h>
+
+struct virtio_pci_legacy_device {
+	struct pci_dev *pci_dev;
+
+	/* Where to read and clear interrupt */
+	u8 __iomem *isr;
+	/* The IO mapping for the PCI config space (legacy mode only) */
+	void __iomem *ioaddr;
+
+	struct virtio_device_id id;
+};
+
+u64 vp_legacy_get_features(struct virtio_pci_legacy_device *ldev);
+u64 vp_legacy_get_driver_features(struct virtio_pci_legacy_device *ldev);
+void vp_legacy_set_features(struct virtio_pci_legacy_device *ldev,
+			u32 features);
+u8 vp_legacy_get_status(struct virtio_pci_legacy_device *ldev);

include/linux/virtio_pci_legacy.h line 34

Quoted 10 lines
include/linux/virtio_pci_legacy.h new file +10 -0
+void vp_legacy_set_status(struct virtio_pci_legacy_device *ldev,
+			u8 status);
+u16 vp_legacy_queue_vector(struct virtio_pci_legacy_device *ldev,
+			   u16 idx, u16 vector);
+u16 vp_legacy_config_vector(struct virtio_pci_legacy_device *ldev,
+		     u16 vector);
+void vp_legacy_set_queue_address(struct virtio_pci_legacy_device *ldev,
+			     u16 index, u32 queue_pfn);
+void vp_legacy_set_queue_enable(struct virtio_pci_legacy_device *ldev,
+				u16 idx, bool enable);

Just spot this. This is never defined in this patch?

Thanks

Quoted 10 lines
include/linux/virtio_pci_legacy.h new file +10 -0
+bool vp_legacy_get_queue_enable(struct virtio_pci_legacy_device *ldev,
+				u16 idx);
+void vp_legacy_set_queue_size(struct virtio_pci_legacy_device *ldev,
+			      u16 idx, u16 size);
+u16 vp_legacy_get_queue_size(struct virtio_pci_legacy_device *ldev,
+			     u16 idx);
+int vp_legacy_probe(struct virtio_pci_legacy_device *ldev);
+void vp_legacy_remove(struct virtio_pci_legacy_device *ldev);
+
+#endif
#86 lore raw

PATCH v4 2/7 vdpa: fix typo

In reply to Wu Zongyong
---
 include/linux/vdpa.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/vdpa.h +1 -1
index 3972ab765de1..a896ee021e5f 100644
@@ -257,7 +257,7 @@ struct vdpa_config_ops {
 	struct vdpa_notification_area
 	(*get_vq_notification)(struct vdpa_device *vdev, u16 idx);
 	/* vq irq is not expected to be changed once DRIVER_OK is set */
-	int (*get_vq_irq)(struct vdpa_device *vdv, u16 idx);
+	int (*get_vq_irq)(struct vdpa_device *vdev, u16 idx);
 
 	/* Device ops */
 	u32 (*get_vq_align)(struct vdpa_device *vdev);
Signature · 1 line
2.31.1
Acked-by on v4 2/7
#87 lore raw

Re: [PATCH v4 2/7] vdpa: fix typo

Quoted 1 line · Wu Zongyong
Quoted 17 lines
---
  include/linux/vdpa.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/vdpa.h +1 -1
index 3972ab765de1..a896ee021e5f 100644
@@ -257,7 +257,7 @@ struct vdpa_config_ops {
  	struct vdpa_notification_area
  	(*get_vq_notification)(struct vdpa_device *vdev, u16 idx);
  	/* vq irq is not expected to be changed once DRIVER_OK is set */
-	int (*get_vq_irq)(struct vdpa_device *vdv, u16 idx);
+	int (*get_vq_irq)(struct vdpa_device *vdev, u16 idx);
 
  	/* Device ops */
  	u32 (*get_vq_align)(struct vdpa_device *vdev);
#88 lore raw

PATCH v4 3/7 vp_vdpa: add vq irq offloading support

In reply to Wu Zongyong

This patch implements the get_vq_irq() callback for virtio pci devices to allow irq offloading.

---
 drivers/vdpa/virtio_pci/vp_vdpa.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/vdpa/virtio_pci/vp_vdpa.c +12 -0
index 5bcd00246d2e..e3ff7875e123 100644
@@ -76,6 +76,17 @@ static u8 vp_vdpa_get_status(struct vdpa_device *vdpa)
 	return vp_modern_get_status(mdev);
 }
 
+static int vp_vdpa_get_vq_irq(struct vdpa_device *vdpa, u16 idx)
+{
+	struct vp_vdpa *vp_vdpa = vdpa_to_vp(vdpa);
+	int irq = vp_vdpa->vring[idx].irq;
+
+	if (irq == VIRTIO_MSI_NO_VECTOR)
+		return -EINVAL;
+
+	return irq;
+}
+
 static void vp_vdpa_free_irq(struct vp_vdpa *vp_vdpa)
 {
 	struct virtio_pci_modern_device *mdev = &vp_vdpa->mdev;
@@ -427,6 +438,7 @@ static const struct vdpa_config_ops vp_vdpa_ops = {
 	.get_config	= vp_vdpa_get_config,
 	.set_config	= vp_vdpa_set_config,
 	.set_config_cb  = vp_vdpa_set_config_cb,
+	.get_vq_irq	= vp_vdpa_get_vq_irq,
 };
 
 static void vp_vdpa_free_irq_vectors(void *data)
Signature · 1 line
2.31.1
#89 lore raw

PATCH v4 4/7 vdpa: add new callback get_vq_num_min in vdpa_config_ops

In reply to Wu Zongyong

This callback is optional. For vdpa devices that not support to change virtqueue size, get_vq_num_min and get_vq_num_max will return the same value, so that users can choose a correct value for that device.

---
 include/linux/vdpa.h | 4 ++++
 1 file changed, 4 insertions(+)
include/linux/vdpa.h +4 -0
index a896ee021e5f..30864848950b 100644
@@ -171,6 +171,9 @@ struct vdpa_map_file {
  * @get_vq_num_max:		Get the max size of virtqueue
  *				@vdev: vdpa device
  *				Returns u16: max size of virtqueue
+ * @get_vq_num_min:		Get the min size of virtqueue (optional)
+ *				@vdev: vdpa device
+ *				Returns u16: min size of virtqueue
  * @get_device_id:		Get virtio device id
  *				@vdev: vdpa device
  *				Returns u32: virtio device id
@@ -266,6 +269,7 @@ struct vdpa_config_ops {
 	void (*set_config_cb)(struct vdpa_device *vdev,
 			      struct vdpa_callback *cb);
 	u16 (*get_vq_num_max)(struct vdpa_device *vdev);
+	u16 (*get_vq_num_min)(struct vdpa_device *vdev);
 	u32 (*get_device_id)(struct vdpa_device *vdev);
 	u32 (*get_vendor_id)(struct vdpa_device *vdev);
 	u8 (*get_status)(struct vdpa_device *vdev);
Signature · 1 line
2.31.1
Acked-by on v4 4/7
#90 lore raw

Re: [PATCH v4 4/7] vdpa: add new callback get_vq_num_min in vdpa_config_ops

Quoted 6 lines · Wu Zongyong

This callback is optional. For vdpa devices that not support to change virtqueue size, get_vq_num_min and get_vq_num_max will return the same value, so that users can choose a correct value for that device.

Quoted 19 lines
---
  include/linux/vdpa.h | 4 ++++
  1 file changed, 4 insertions(+)
include/linux/vdpa.h +3 -0
index a896ee021e5f..30864848950b 100644
@@ -171,6 +171,9 @@ struct vdpa_map_file {
   * @get_vq_num_max:		Get the max size of virtqueue
   *				@vdev: vdpa device
   *				Returns u16: max size of virtqueue
+ * @get_vq_num_min:		Get the min size of virtqueue (optional)
+ *				@vdev: vdpa device
+ *				Returns u16: min size of virtqueue
   * @get_device_id:		Get virtio device id
   *				@vdev: vdpa device
   *				Returns u32: virtio device id

include/linux/vdpa.h struct vdpa_config_ops { · line 275

Quoted 7 lines
include/linux/vdpa.h +1 -0
@@ -266,6 +269,7 @@ struct vdpa_config_ops {
  	void (*set_config_cb)(struct vdpa_device *vdev,
  			      struct vdpa_callback *cb);
  	u16 (*get_vq_num_max)(struct vdpa_device *vdev);
+	u16 (*get_vq_num_min)(struct vdpa_device *vdev);
  	u32 (*get_device_id)(struct vdpa_device *vdev);
  	u32 (*get_vendor_id)(struct vdpa_device *vdev);
  	u8 (*get_status)(struct vdpa_device *vdev);

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#91 lore raw

PATCH v4 5/7 virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}

In reply to Wu Zongyong
---
 drivers/virtio/virtio_vdpa.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
drivers/virtio/virtio_vdpa.c +20 -5
index 72eaef2caeb1..8aa4ebe2a2a2 100644
@@ -145,7 +145,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 	/* Assume split virtqueue, switch to packed if necessary */
 	struct vdpa_vq_state state = {0};
 	unsigned long flags;
-	u32 align, num;
+	u32 align, max_num, min_num = 0;
+	bool may_reduce_num = true;
 	int err;
 
 	if (!name)
@@ -163,22 +164,36 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 	if (!info)
 		return ERR_PTR(-ENOMEM);
 
-	num = ops->get_vq_num_max(vdpa);
-	if (num == 0) {
+	max_num = ops->get_vq_num_max(vdpa);
+	if (max_num == 0) {
 		err = -ENOENT;
 		goto error_new_virtqueue;
 	}
 
+	if (ops->get_vq_num_min)
+		min_num = ops->get_vq_num_min(vdpa);
+	if (min_num > max_num) {
+		err = -ENOENT;
+		goto error_new_virtqueue;
+	}
+
+	may_reduce_num = (max_num == min_num) ? false : true;
+
 	/* Create the vring */
 	align = ops->get_vq_align(vdpa);
-	vq = vring_create_virtqueue(index, num, align, vdev,
-				    true, true, ctx,
+	vq = vring_create_virtqueue(index, max_num, align, vdev,
+				    true, may_reduce_num, ctx,
 				    virtio_vdpa_notify, callback, name);
 	if (!vq) {
 		err = -ENOMEM;
 		goto error_new_virtqueue;
 	}
 
+	if (virtqueue_get_vring_size(vq) < min_num) {
+		err = -EINVAL;
+		goto err_vq;
+	}
+
 	/* Setup virtqueue callback */
 	cb.callback = virtio_vdpa_virtqueue_cb;
 	cb.private = info;
Signature · 1 line
2.31.1
#92 lore raw

Re: [PATCH v4 5/7] virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}

Quoted 1 line · Wu Zongyong

Commit log please.

Quoted 26 lines
---
  drivers/virtio/virtio_vdpa.c | 25 ++++++++++++++++++++-----
  1 file changed, 20 insertions(+), 5 deletions(-)
drivers/virtio/virtio_vdpa.c +4 -3
index 72eaef2caeb1..8aa4ebe2a2a2 100644
@@ -145,7 +145,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
  	/* Assume split virtqueue, switch to packed if necessary */
  	struct vdpa_vq_state state = {0};
  	unsigned long flags;
-	u32 align, num;
+	u32 align, max_num, min_num = 0;
+	bool may_reduce_num = true;
  	int err;
 
  	if (!name)
@@ -163,22 +164,36 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
  	if (!info)
  		return ERR_PTR(-ENOMEM);
 
-	num = ops->get_vq_num_max(vdpa);
-	if (num == 0) {
+	max_num = ops->get_vq_num_max(vdpa);
+	if (max_num == 0) {

drivers/virtio/virtio_vdpa.c virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, · line 178

Quoted 10 lines
drivers/virtio/virtio_vdpa.c +6 -0
  		err = -ENOENT;
  		goto error_new_virtqueue;
  	}
 
+	if (ops->get_vq_num_min)
+		min_num = ops->get_vq_num_min(vdpa);
+	if (min_num > max_num) {
+		err = -ENOENT;
+		goto error_new_virtqueue;
+	}

If we really want to do this, let's move this to vdpa core during device probing.

Or just leave it as is (device risk itself).

Thanks

Quoted 13 lines
drivers/virtio/virtio_vdpa.c +5 -2
+
+	may_reduce_num = (max_num == min_num) ? false : true;
+
  	/* Create the vring */
  	align = ops->get_vq_align(vdpa);
-	vq = vring_create_virtqueue(index, num, align, vdev,
-				    true, true, ctx,
+	vq = vring_create_virtqueue(index, max_num, align, vdev,
+				    true, may_reduce_num, ctx,
  				    virtio_vdpa_notify, callback, name);
  	if (!vq) {
  		err = -ENOMEM;
  		goto error_new_virtqueue;

drivers/virtio/virtio_vdpa.c virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, · line 199

Quoted 10 lines
drivers/virtio/virtio_vdpa.c +5 -0
  	}
 
+	if (virtqueue_get_vring_size(vq) < min_num) {
+		err = -EINVAL;
+		goto err_vq;
+	}
+
  	/* Setup virtqueue callback */
  	cb.callback = virtio_vdpa_virtqueue_cb;
  	cb.private = info;

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#93 lore raw

PATCH v4 6/7 vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE

In reply to Wu Zongyong

This attribute advertises the min value of virtqueue size. The value is 0 by default.

---
 drivers/vdpa/vdpa.c       | 5 +++++
 include/uapi/linux/vdpa.h | 1 +
 2 files changed, 6 insertions(+)
drivers/vdpa/vdpa.c +5 -0
index 1dc121a07a93..6ed79fba33e4 100644
@@ -492,6 +492,7 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
 	      int flags, struct netlink_ext_ack *extack)
 {
 	u16 max_vq_size;
+	u16 min_vq_size = 0;
 	u32 device_id;
 	u32 vendor_id;
 	void *hdr;
@@ -508,6 +509,8 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
 	device_id = vdev->config->get_device_id(vdev);
 	vendor_id = vdev->config->get_vendor_id(vdev);
 	max_vq_size = vdev->config->get_vq_num_max(vdev);
+	if (vdev->config->get_vq_num_min)
+		min_vq_size = vdev->config->get_vq_num_min(vdev);
 
 	err = -EMSGSIZE;
 	if (nla_put_string(msg, VDPA_ATTR_DEV_NAME, dev_name(&vdev->dev)))
@@ -520,6 +523,8 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
 		goto msg_err;
 	if (nla_put_u16(msg, VDPA_ATTR_DEV_MAX_VQ_SIZE, max_vq_size))
 		goto msg_err;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_MIN_VQ_SIZE, min_vq_size))
+		goto msg_err;
 
 	genlmsg_end(msg, hdr);
 	return 0;
include/uapi/linux/vdpa.h +1 -0
index 66a41e4ec163..e3b87879514c 100644
@@ -32,6 +32,7 @@ enum vdpa_attr {
 	VDPA_ATTR_DEV_VENDOR_ID,		/* u32 */
 	VDPA_ATTR_DEV_MAX_VQS,			/* u32 */
 	VDPA_ATTR_DEV_MAX_VQ_SIZE,		/* u16 */
+	VDPA_ATTR_DEV_MIN_VQ_SIZE,		/* u16 */
 
 	/* new attributes must be added above here */
 	VDPA_ATTR_MAX,
Signature · 1 line
2.31.1
#94 lore raw

Re: [PATCH v4 6/7] vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE

Quoted 2 lines · Wu Zongyong

This attribute advertises the min value of virtqueue size. The value is 0 by default.

I think 0 is not a correct value. If I understand the spec correctly, it should be 1.

Thanks

Quoted 42 lines
---
  drivers/vdpa/vdpa.c       | 5 +++++
  include/uapi/linux/vdpa.h | 1 +
  2 files changed, 6 insertions(+)
drivers/vdpa/vdpa.c +5 -0
index 1dc121a07a93..6ed79fba33e4 100644
@@ -492,6 +492,7 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
  	      int flags, struct netlink_ext_ack *extack)
  {
  	u16 max_vq_size;
+	u16 min_vq_size = 0;
  	u32 device_id;
  	u32 vendor_id;
  	void *hdr;
@@ -508,6 +509,8 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
  	device_id = vdev->config->get_device_id(vdev);
  	vendor_id = vdev->config->get_vendor_id(vdev);
  	max_vq_size = vdev->config->get_vq_num_max(vdev);
+	if (vdev->config->get_vq_num_min)
+		min_vq_size = vdev->config->get_vq_num_min(vdev);
 
  	err = -EMSGSIZE;
  	if (nla_put_string(msg, VDPA_ATTR_DEV_NAME, dev_name(&vdev->dev)))
@@ -520,6 +523,8 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
  		goto msg_err;
  	if (nla_put_u16(msg, VDPA_ATTR_DEV_MAX_VQ_SIZE, max_vq_size))
  		goto msg_err;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_MIN_VQ_SIZE, min_vq_size))
+		goto msg_err;
 
  	genlmsg_end(msg, hdr);
  	return 0;
include/uapi/linux/vdpa.h +0 -0
index 66a41e4ec163..e3b87879514c 100644

include/uapi/linux/vdpa.h enum vdpa_attr { · line 38

Quoted 7 lines
include/uapi/linux/vdpa.h +1 -0
@@ -32,6 +32,7 @@ enum vdpa_attr {
  	VDPA_ATTR_DEV_VENDOR_ID,		/* u32 */
  	VDPA_ATTR_DEV_MAX_VQS,			/* u32 */
  	VDPA_ATTR_DEV_MAX_VQ_SIZE,		/* u16 */
+	VDPA_ATTR_DEV_MIN_VQ_SIZE,		/* u16 */
 
  	/* new attributes must be added above here */
  	VDPA_ATTR_MAX,

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#95 lore raw

PATCH v4 7/7 eni_vdpa: add vDPA driver for Alibaba ENI

In reply to Wu Zongyong

This patch adds a new vDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon virtio 0.9.5 specification. And this driver doesn't support to run on BE host.

---
 drivers/vdpa/Kconfig            |   8 +
 drivers/vdpa/Makefile           |   1 +
 drivers/vdpa/alibaba/Makefile   |   3 +
 drivers/vdpa/alibaba/eni_vdpa.c | 553 ++++++++++++++++++++++++++++++++
 4 files changed, 565 insertions(+)
 create mode 100644 drivers/vdpa/alibaba/Makefile
 create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
drivers/vdpa/Kconfig +8 -0
index 3d91982d8371..9587b9177b05 100644
@@ -78,4 +78,12 @@ config VP_VDPA
 	help
 	  This kernel module bridges virtio PCI device to vDPA bus.
 
+config ALIBABA_ENI_VDPA
+	tristate "vDPA driver for Alibaba ENI"
+	select VIRTIO_PCI_LEGACY_LIB
+	depends on PCI_MSI
+	help
+	  VDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon
+	  virtio 0.9.5 specification.
+
 endif # VDPA
drivers/vdpa/Makefile +1 -0
index f02ebed33f19..15665563a7f4 100644
@@ -5,3 +5,4 @@ obj-$(CONFIG_VDPA_USER) += vdpa_user/
 obj-$(CONFIG_IFCVF)    += ifcvf/
 obj-$(CONFIG_MLX5_VDPA) += mlx5/
 obj-$(CONFIG_VP_VDPA)    += virtio_pci/
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += alibaba/
drivers/vdpa/alibaba/Makefile new file +3 -0
new file mode 100644
index 000000000000..ef4aae69f87a
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += eni_vdpa.o
+
drivers/vdpa/alibaba/eni_vdpa.c new file +553 -0

553 lines not on this page · raw message

Signature · 1 line
2.31.1
#96 lore raw

Re: [PATCH v4 7/7] eni_vdpa: add vDPA driver for Alibaba ENI

Quoted 3 lines · Wu Zongyong

This patch adds a new vDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon virtio 0.9.5 specification. And this driver doesn't support to run on BE host.

If this is true, I think it's still better to exclude this driver via Kconfig.

Quoted 109 lines
---
  drivers/vdpa/Kconfig            |   8 +
  drivers/vdpa/Makefile           |   1 +
  drivers/vdpa/alibaba/Makefile   |   3 +
  drivers/vdpa/alibaba/eni_vdpa.c | 553 ++++++++++++++++++++++++++++++++
  4 files changed, 565 insertions(+)

create mode 100644 drivers/vdpa/alibaba/Makefile create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c

drivers/vdpa/Kconfig +8 -0
index 3d91982d8371..9587b9177b05 100644
@@ -78,4 +78,12 @@ config VP_VDPA
  	help
  	  This kernel module bridges virtio PCI device to vDPA bus.
 
+config ALIBABA_ENI_VDPA
+	tristate "vDPA driver for Alibaba ENI"
+	select VIRTIO_PCI_LEGACY_LIB
+	depends on PCI_MSI
+	help
+	  VDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon
+	  virtio 0.9.5 specification.
+
  endif # VDPA
drivers/vdpa/Makefile +1 -0
index f02ebed33f19..15665563a7f4 100644
@@ -5,3 +5,4 @@ obj-$(CONFIG_VDPA_USER) += vdpa_user/
  obj-$(CONFIG_IFCVF)    += ifcvf/
  obj-$(CONFIG_MLX5_VDPA) += mlx5/
  obj-$(CONFIG_VP_VDPA)    += virtio_pci/
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += alibaba/
drivers/vdpa/alibaba/Makefile new file +3 -0
new file mode 100644
index 000000000000..ef4aae69f87a
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += eni_vdpa.o
+
drivers/vdpa/alibaba/eni_vdpa.c new file +57 -0
new file mode 100644
index 000000000000..6a09f157d810
@@ -0,0 +1,553 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * vDPA bridge driver for Alibaba ENI(Elastic Network Interface)
+ *
+ * Copyright (c) 2021, Alibaba Inc. All rights reserved.
+ * Author: Wu Zongyong <[email protected]>
+ *
+ */
+
+#include "linux/bits.h"
+#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>
+#include <linux/virtio_ring.h>
+#include <linux/virtio_pci.h>
+#include <linux/virtio_pci_legacy.h>
+#include <uapi/linux/virtio_net.h>
+
+#define ENI_MSIX_NAME_SIZE 256
+
+#define ENI_ERR(pdev, fmt, ...)	\
+	dev_err(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+#define ENI_DBG(pdev, fmt, ...)	\
+	dev_dbg(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+#define ENI_INFO(pdev, fmt, ...) \
+	dev_info(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+
+struct eni_vring {
+	void __iomem *notify;
+	char msix_name[ENI_MSIX_NAME_SIZE];
+	struct vdpa_callback cb;
+	int irq;
+};
+
+struct eni_vdpa {
+	struct vdpa_device vdpa;
+	struct virtio_pci_legacy_device ldev;
+	struct eni_vring *vring;
+	struct vdpa_callback config_cb;
+	char msix_name[ENI_MSIX_NAME_SIZE];
+	int config_irq;
+	int queues;
+	int vectors;
+};
+
+static struct eni_vdpa *vdpa_to_eni(struct vdpa_device *vdpa)
+{
+	return container_of(vdpa, struct eni_vdpa, vdpa);
+}
+
+static struct virtio_pci_legacy_device *vdpa_to_ldev(struct vdpa_device *vdpa)
+{
+	struct eni_vdpa *eni_vdpa = vdpa_to_eni(vdpa);
+

drivers/vdpa/alibaba/eni_vdpa.c line 67

Quoted 10 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +10 -0
+	return &eni_vdpa->ldev;
+}
+
+static u64 eni_vdpa_get_features(struct vdpa_device *vdpa)
+{
+	struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+	u64 features = vp_legacy_get_features(ldev);
+
+	features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM);
+	features |= BIT_ULL(VIRTIO_F_ORDER_PLATFORM);

VERSION_1 is also needed?

drivers/vdpa/alibaba/eni_vdpa.c line 79

Quoted 12 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +12 -0
+
+	return features;
+}
+
+static int eni_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
+{
+	struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+	if (!(features & BIT_ULL(VIRTIO_NET_F_MRG_RXBUF)) && features) {
+		ENI_ERR(ldev->pci_dev,
+			"VIRTIO_NET_F_MRG_RXBUF is not negotiated\n");
+		return -EINVAL;

Do we need to make sure FEATURE_OK is not set in this case or the ENI can do this for us?

Other looks good.

Thanks

Quoted 474 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +474 -0
+	}
+
+	vp_legacy_set_features(ldev, (u32)features);
+
+	return 0;
+}
+
+static u8 eni_vdpa_get_status(struct vdpa_device *vdpa)
+{
+	struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+	return vp_legacy_get_status(ldev);
+}
+
+static int eni_vdpa_get_vq_irq(struct vdpa_device *vdpa, u16 idx)
+{
+	struct eni_vdpa *eni_vdpa = vdpa_to_eni(vdpa);
+	int irq = eni_vdpa->vring[idx].irq;
+
+	if (irq == VIRTIO_MSI_NO_VECTOR)
+		return -EINVAL;
+
+	return irq;
+}
+
+static void eni_vdpa_free_irq(struct eni_vdpa *eni_vdpa)
+{
+	struct virtio_pci_legacy_device *ldev = &eni_vdpa->ldev;
+	struct pci_dev *pdev = ldev->pci_dev;
+	int i;
+
+	for (i = 0; i < eni_vdpa->queues; i++) {
+		if (eni_vdpa->vring[i].irq != VIRTIO_MSI_NO_VECTOR) {
+			vp_legacy_queue_vector(ldev, i, VIRTIO_MSI_NO_VECTOR);
+			devm_free_irq(&pdev->dev, eni_vdpa->vring[i].irq,
+				      &eni_vdpa->vring[i]);
+			eni_vdpa->vring[i].irq = VIRTIO_MSI_NO_VECTOR;
+		}
+	}
+
+	if (eni_vdpa->config_irq != VIRTIO_MSI_NO_VECTOR) {
+		vp_legacy_config_vector(ldev, VIRTIO_MSI_NO_VECTOR);
+		devm_free_irq(&pdev->dev, eni_vdpa->config_irq, eni_vdpa);
+		eni_vdpa->config_irq = VIRTIO_MSI_NO_VECTOR;
+	}
+
+	if (eni_vdpa->vectors) {
+		pci_free_irq_vectors(pdev);
+		eni_vdpa->vectors = 0;
+	}
+}
+
+static irqreturn_t eni_vdpa_vq_handler(int irq, void *arg)
+{
+	struct eni_vring *vring = arg;
+
+	if (vring->cb.callback)
+		return vring->cb.callback(vring->cb.private);
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t eni_vdpa_config_handler(int irq, void *arg)
+{
+	struct eni_vdpa *eni_vdpa = arg;
+
+	if (eni_vdpa->config_cb.callback)
+		return eni_vdpa->config_cb.callback(eni_vdpa->config_cb.private);
+
+	return IRQ_HANDLED;
+}
+
+static int eni_vdpa_request_irq(struct eni_vdpa *eni_vdpa)
+{
+	struct virtio_pci_legacy_device *ldev = &eni_vdpa->ldev;
+	struct pci_dev *pdev = ldev->pci_dev;
+	int i, ret, irq;
+	int queues = eni_vdpa->queues;
+	int vectors = queues + 1;
+
+	ret = pci_alloc_irq_vectors(pdev, vectors, vectors, PCI_IRQ_MSIX);
+	if (ret != vectors) {
+		ENI_ERR(pdev,
+			"failed to allocate irq vectors want %d but %d\n",
+			vectors, ret);
+		return ret;
+	}
+
+	eni_vdpa->vectors = vectors;
+
+	for (i = 0; i < queues; i++) {
+		snprintf(eni_vdpa->vring[i].msix_name, ENI_MSIX_NAME_SIZE,
+			 "eni-vdpa[%s]-%d\n", pci_name(pdev), i);
+		irq = pci_irq_vector(pdev, i);
+		ret = devm_request_irq(&pdev->dev, irq,
+				       eni_vdpa_vq_handler,
+				       0, eni_vdpa->vring[i].msix_name,
+				       &eni_vdpa->vring[i]);
+		if (ret) {
+			ENI_ERR(pdev, "failed to request irq for vq %d\n", i);
+			goto err;
+		}
+		vp_legacy_queue_vector(ldev, i, i);
+		eni_vdpa->vring[i].irq = irq;
+	}
+
+	snprintf(eni_vdpa->msix_name, ENI_MSIX_NAME_SIZE, "eni-vdpa[%s]-config\n",
+		 pci_name(pdev));
+	irq = pci_irq_vector(pdev, queues);
+	ret = devm_request_irq(&pdev->dev, irq, eni_vdpa_config_handler, 0,
+			       eni_vdpa->msix_name, eni_vdpa);
+	if (ret) {
+		ENI_ERR(pdev, "failed to request irq for config vq %d\n", i);
+		goto err;
+	}
+	vp_legacy_config_vector(ldev, queues);
+	eni_vdpa->config_irq = irq;
+
+	return 0;
+err:
+	eni_vdpa_free_irq(eni_vdpa);
+	return ret;
+}
+
+static void eni_vdpa_set_status(struct vdpa_device *vdpa, u8 status)
+{
+	struct eni_vdpa *eni_vdpa = vdpa_to_eni(vdpa);
+	struct virtio_pci_legacy_device *ldev = &eni_vdpa->ldev;
+	u8 s = eni_vdpa_get_status(vdpa);
+
+	if (status & VIRTIO_CONFIG_S_DRIVER_OK &&
+	    !(s & VIRTIO_CONFIG_S_DRIVER_OK)) {
+		eni_vdpa_request_irq(eni_vdpa);
+	}
+
+	vp_legacy_set_status(ldev, status);
+
+	if (!(status & VIRTIO_CONFIG_S_DRIVER_OK) &&
+	    (s & VIRTIO_CONFIG_S_DRIVER_OK))
+		eni_vdpa_free_irq(eni_vdpa);
+}
+
+static int eni_vdpa_reset(struct vdpa_device *vdpa)
+{
+	struct eni_vdpa *eni_vdpa = vdpa_to_eni(vdpa);
+	struct virtio_pci_legacy_device *ldev = &eni_vdpa->ldev;
+	u8 s = eni_vdpa_get_status(vdpa);
+
+	vp_legacy_set_status(ldev, 0);
+
+	if (s & VIRTIO_CONFIG_S_DRIVER_OK)
+		eni_vdpa_free_irq(eni_vdpa);
+
+	return 0;
+}
+
+static u16 eni_vdpa_get_vq_num_max(struct vdpa_device *vdpa)
+{
+	struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+	return vp_legacy_get_queue_size(ldev, 0);
+}
+
+static u16 eni_vdpa_get_vq_num_min(struct vdpa_device *vdpa)
+{
+	struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+	return vp_legacy_get_queue_size(ldev, 0);
+}
+
+static int eni_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 qid,
+				struct vdpa_vq_state *state)
+{
+	return -EOPNOTSUPP;
+}
+
+static int eni_vdpa_set_vq_state(struct vdpa_device *vdpa, u16 qid,
+				 const struct vdpa_vq_state *state)
+{
+	struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+	const struct vdpa_vq_state_split *split = &state->split;
+
+	/* ENI is build upon virtio-pci specfication which not support
+	 * to set state of virtqueue. But if the state is equal to the
+	 * device initial state by chance, we can let it go.
+	 */
+	if (!vp_legacy_get_queue_enable(ldev, qid)
+	    && split->avail_index == 0)
+		return 0;
+
+	return -EOPNOTSUPP;
+}
+
+
+static void eni_vdpa_set_vq_cb(struct vdpa_device *vdpa, u16 qid,
+			       struct vdpa_callback *cb)
+{
+	struct eni_vdpa *eni_vdpa = vdpa_to_eni(vdpa);
+
+	eni_vdpa->vring[qid].cb = *cb;
+}
+
+static void eni_vdpa_set_vq_ready(struct vdpa_device *vdpa, u16 qid,
+				  bool ready)
+{
+	struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+	/* ENI is a legacy virtio-pci device. This is not supported
+	 * by specification. But we can disable virtqueue by setting
+	 * address to 0.
+	 */
+	if (!ready)
+		vp_legacy_set_queue_address(ldev, qid, 0);
+}
+
+static bool eni_vdpa_get_vq_ready(struct vdpa_device *vdpa, u16 qid)
+{
+	struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+	return vp_legacy_get_queue_enable(ldev, qid);
+}
+
+static void eni_vdpa_set_vq_num(struct vdpa_device *vdpa, u16 qid,
+			       u32 num)
+{
+	struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+	struct pci_dev *pdev = ldev->pci_dev;
+	u16 n = vp_legacy_get_queue_size(ldev, qid);
+
+	/* ENI is a legacy virtio-pci device which not allow to change
+	 * virtqueue size. Just report a error if someone tries to
+	 * change it.
+	 */
+	if (num != n)
+		ENI_ERR(pdev,
+			"not support to set vq %u fixed num %u to %u\n",
+			qid, n, num);
+}
+
+static int eni_vdpa_set_vq_address(struct vdpa_device *vdpa, u16 qid,
+				   u64 desc_area, u64 driver_area,
+				   u64 device_area)
+{
+	struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+	u32 pfn = desc_area >> VIRTIO_PCI_QUEUE_ADDR_SHIFT;
+
+	vp_legacy_set_queue_address(ldev, qid, pfn);
+
+	return 0;
+}
+
+static void eni_vdpa_kick_vq(struct vdpa_device *vdpa, u16 qid)
+{
+	struct eni_vdpa *eni_vdpa = vdpa_to_eni(vdpa);
+
+	iowrite16(qid, eni_vdpa->vring[qid].notify);
+}
+
+static u32 eni_vdpa_get_device_id(struct vdpa_device *vdpa)
+{
+	struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+	return ldev->id.device;
+}
+
+static u32 eni_vdpa_get_vendor_id(struct vdpa_device *vdpa)
+{
+	struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+	return ldev->id.vendor;
+}
+
+static u32 eni_vdpa_get_vq_align(struct vdpa_device *vdpa)
+{
+	return PAGE_SIZE;
+}
+
+static size_t eni_vdpa_get_config_size(struct vdpa_device *vdpa)
+{
+	return sizeof(struct virtio_net_config);
+}
+
+
+static void eni_vdpa_get_config(struct vdpa_device *vdpa,
+				unsigned int offset,
+				void *buf, unsigned int len)
+{
+	struct eni_vdpa *eni_vdpa = vdpa_to_eni(vdpa);
+	struct virtio_pci_legacy_device *ldev = &eni_vdpa->ldev;
+	void __iomem *ioaddr = ldev->ioaddr +
+		VIRTIO_PCI_CONFIG_OFF(eni_vdpa->vectors) +
+		offset;
+	u8 *p = buf;
+	int i;
+
+	for (i = 0; i < len; i++)
+		*p++ = ioread8(ioaddr + i);
+}
+
+static void eni_vdpa_set_config(struct vdpa_device *vdpa,
+				unsigned int offset, const void *buf,
+				unsigned int len)
+{
+	struct eni_vdpa *eni_vdpa = vdpa_to_eni(vdpa);
+	struct virtio_pci_legacy_device *ldev = &eni_vdpa->ldev;
+	void __iomem *ioaddr = ldev->ioaddr +
+		VIRTIO_PCI_CONFIG_OFF(eni_vdpa->vectors) +
+		offset;
+	const u8 *p = buf;
+	int i;
+
+	for (i = 0; i < len; i++)
+		iowrite8(*p++, ioaddr + i);
+}
+
+static void eni_vdpa_set_config_cb(struct vdpa_device *vdpa,
+				   struct vdpa_callback *cb)
+{
+	struct eni_vdpa *eni_vdpa = vdpa_to_eni(vdpa);
+
+	eni_vdpa->config_cb = *cb;
+}
+
+static const struct vdpa_config_ops eni_vdpa_ops = {
+	.get_features	= eni_vdpa_get_features,
+	.set_features	= eni_vdpa_set_features,
+	.get_status	= eni_vdpa_get_status,
+	.set_status	= eni_vdpa_set_status,
+	.reset		= eni_vdpa_reset,
+	.get_vq_num_max	= eni_vdpa_get_vq_num_max,
+	.get_vq_num_min	= eni_vdpa_get_vq_num_min,
+	.get_vq_state	= eni_vdpa_get_vq_state,
+	.set_vq_state	= eni_vdpa_set_vq_state,
+	.set_vq_cb	= eni_vdpa_set_vq_cb,
+	.set_vq_ready	= eni_vdpa_set_vq_ready,
+	.get_vq_ready	= eni_vdpa_get_vq_ready,
+	.set_vq_num	= eni_vdpa_set_vq_num,
+	.set_vq_address	= eni_vdpa_set_vq_address,
+	.kick_vq	= eni_vdpa_kick_vq,
+	.get_device_id	= eni_vdpa_get_device_id,
+	.get_vendor_id	= eni_vdpa_get_vendor_id,
+	.get_vq_align	= eni_vdpa_get_vq_align,
+	.get_config_size = eni_vdpa_get_config_size,
+	.get_config	= eni_vdpa_get_config,
+	.set_config	= eni_vdpa_set_config,
+	.set_config_cb  = eni_vdpa_set_config_cb,
+	.get_vq_irq	= eni_vdpa_get_vq_irq,
+};
+
+
+static u16 eni_vdpa_get_num_queues(struct eni_vdpa *eni_vdpa)
+{
+	struct virtio_pci_legacy_device *ldev = &eni_vdpa->ldev;
+	u32 features = vp_legacy_get_features(ldev);
+	u16 num = 2;
+
+	if (features & BIT_ULL(VIRTIO_NET_F_MQ)) {
+		__virtio16 max_virtqueue_pairs;
+
+		eni_vdpa_get_config(&eni_vdpa->vdpa,
+			offsetof(struct virtio_net_config, max_virtqueue_pairs),
+			&max_virtqueue_pairs,
+			sizeof(max_virtqueue_pairs));
+		num = 2 * __virtio16_to_cpu(virtio_legacy_is_little_endian(),
+				max_virtqueue_pairs);
+	}
+
+	if (features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ))
+		num += 1;
+
+	return num;
+}
+
+static void eni_vdpa_free_irq_vectors(void *data)
+{
+	pci_free_irq_vectors(data);
+}
+
+static int eni_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+	struct device *dev = &pdev->dev;
+	struct eni_vdpa *eni_vdpa;
+	struct virtio_pci_legacy_device *ldev;
+	int ret, i;
+
+	ret = pcim_enable_device(pdev);
+	if (ret)
+		return ret;
+
+	eni_vdpa = vdpa_alloc_device(struct eni_vdpa, vdpa,
+				     dev, &eni_vdpa_ops, NULL, false);
+	if (IS_ERR(eni_vdpa)) {
+		ENI_ERR(pdev, "failed to allocate vDPA structure\n");
+		return PTR_ERR(eni_vdpa);
+	}
+
+	ldev = &eni_vdpa->ldev;
+	ldev->pci_dev = pdev;
+
+	ret = vp_legacy_probe(ldev);
+	if (ret) {
+		ENI_ERR(pdev, "failed to probe legacy PCI device\n");
+		goto err;
+	}
+
+	pci_set_master(pdev);
+	pci_set_drvdata(pdev, eni_vdpa);
+
+	eni_vdpa->vdpa.dma_dev = &pdev->dev;
+	eni_vdpa->queues = eni_vdpa_get_num_queues(eni_vdpa);
+
+	ret = devm_add_action_or_reset(dev, eni_vdpa_free_irq_vectors, pdev);
+	if (ret) {
+		ENI_ERR(pdev,
+			"failed for adding devres for freeing irq vectors\n");
+		goto err;
+	}
+
+	eni_vdpa->vring = devm_kcalloc(&pdev->dev, eni_vdpa->queues,
+				      sizeof(*eni_vdpa->vring),
+				      GFP_KERNEL);
+	if (!eni_vdpa->vring) {
+		ret = -ENOMEM;
+		ENI_ERR(pdev, "failed to allocate virtqueues\n");
+		goto err;
+	}
+
+	for (i = 0; i < eni_vdpa->queues; i++) {
+		eni_vdpa->vring[i].irq = VIRTIO_MSI_NO_VECTOR;
+		eni_vdpa->vring[i].notify = ldev->ioaddr + VIRTIO_PCI_QUEUE_NOTIFY;
+	}
+	eni_vdpa->config_irq = VIRTIO_MSI_NO_VECTOR;
+
+	ret = vdpa_register_device(&eni_vdpa->vdpa, eni_vdpa->queues);
+	if (ret) {
+		ENI_ERR(pdev, "failed to register to vdpa bus\n");
+		goto err;
+	}
+
+	return 0;
+
+err:
+	put_device(&eni_vdpa->vdpa.dev);
+	return ret;
+}
+
+static void eni_vdpa_remove(struct pci_dev *pdev)
+{
+	struct eni_vdpa *eni_vdpa = pci_get_drvdata(pdev);
+
+	vdpa_unregister_device(&eni_vdpa->vdpa);
+	vp_legacy_remove(&eni_vdpa->ldev);
+}
+
+static struct pci_device_id eni_pci_ids[] = {
+	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_REDHAT_QUMRANET,
+			 VIRTIO_TRANS_ID_NET,
+			 PCI_SUBVENDOR_ID_REDHAT_QUMRANET,
+			 VIRTIO_ID_NET) },
+	{ 0 },
+};
+
+static struct pci_driver eni_vdpa_driver = {
+	.name		= "alibaba-eni-vdpa",
+	.id_table	= eni_pci_ids,
+	.probe		= eni_vdpa_probe,
+	.remove		= eni_vdpa_remove,
+};
+
+module_pci_driver(eni_vdpa_driver);
+
+MODULE_AUTHOR("Wu Zongyong <[email protected]>");
+MODULE_DESCRIPTION("Alibaba ENI vDPA driver");
+MODULE_LICENSE("GPL v2");
#97 lore raw

v5 cover vDPA driver for Alibaba ENI

In reply to Wu Zongyong

This series implements the vDPA driver for Alibaba ENI(Elastic Network Interface) which is build based on virtio-pci 0.9.5 specification.

Changes since V4:
- check return values of get_vq_num_{max,min} when probing devices
- disable the driver on BE host via Kconfig
- add missing commit message

Changes since V3:
- validate VIRTIO_NET_F_MRG_RXBUF when negotiate features
- present F_ORDER_PLATFORM in get_features
- remove endian check since ENI always use litter endian

Changes since V2:
- add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE instead VDPA_ATTR_DEV_F_VERSION_1 to guide users to choose correct virtqueue size as suggested by Jason Wang
- present ACCESS_PLATFORM in get_features callback as suggested by Jason Wang
- disable this driver on Big Endian host as suggested by Jason Wang
- fix a typo

Changes since V1:
- add new vdpa attribute VDPA_ATTR_DEV_F_VERSION_1 to indicate whether the vdpa device is legacy
- implement dedicated driver for Alibaba ENI instead a legacy virtio-pci driver as suggested by Jason Wang
- some bugs fixed

Wu Zongyong (8):
virtio-pci: introduce legacy device module
vdpa: fix typo
vp_vdpa: add vq irq offloading support
vdpa: add new callback get_vq_num_min in vdpa_config_ops
vdpa: min vq num of vdpa device cannot be greater than max vq num
virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}
vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE
eni_vdpa: add vDPA driver for Alibaba ENI

 drivers/vdpa/Kconfig                   |   8 +
 drivers/vdpa/Makefile                  |   1 +
 drivers/vdpa/alibaba/Makefile          |   3 +
 drivers/vdpa/alibaba/eni_vdpa.c        | 553 +++++++++++++++++++++++++
 drivers/vdpa/vdpa.c                    |  13 +
 drivers/vdpa/virtio_pci/vp_vdpa.c      |  12 +
 drivers/virtio/Kconfig                 |  10 +
 drivers/virtio/Makefile                |   1 +
 drivers/virtio/virtio_pci_common.c     |  10 +-
 drivers/virtio/virtio_pci_common.h     |   9 +-
 drivers/virtio/virtio_pci_legacy.c     | 101 ++---
 drivers/virtio/virtio_pci_legacy_dev.c | 220 ++++++++++
 drivers/virtio/virtio_vdpa.c           |  21 +-
 include/linux/vdpa.h                   |   6 +-
 include/linux/virtio_pci_legacy.h      |  44 ++
 include/uapi/linux/vdpa.h              |   1 +
 16 files changed, 924 insertions(+), 89 deletions(-)
 create mode 100644 drivers/vdpa/alibaba/Makefile
 create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
 create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c
 create mode 100644 include/linux/virtio_pci_legacy.h
Signature · 1 line
2.31.1
#98 lore raw

PATCH v5 1/8 virtio-pci: introduce legacy device module

Split common codes from virtio-pci-legacy so vDPA driver can reuse it later.

---
 drivers/virtio/Kconfig                 |  10 ++
 drivers/virtio/Makefile                |   1 +
 drivers/virtio/virtio_pci_common.c     |  10 +-
 drivers/virtio/virtio_pci_common.h     |   9 +-
 drivers/virtio/virtio_pci_legacy.c     | 101 +++---------
 drivers/virtio/virtio_pci_legacy_dev.c | 220 +++++++++++++++++++++++++
 include/linux/virtio_pci_legacy.h      |  44 +++++
 7 files changed, 312 insertions(+), 83 deletions(-)
 create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c
 create mode 100644 include/linux/virtio_pci_legacy.h
drivers/virtio/Kconfig +10 -0
index ce1b3f6ec325..8fcf94cd2c96 100644
@@ -20,6 +20,15 @@ config VIRTIO_PCI_LIB
 	  PCI device with possible vendor specific extensions. Any
 	  module that selects this module must depend on PCI.
 
+config VIRTIO_PCI_LIB_LEGACY
+	tristate
+	help
+	  Legacy PCI device (Virtio PCI Card 0.9.x Draft and older device)
+	  implementation.
+	  This module implements the basic probe and control for devices
+	  which are based on legacy PCI device. Any module that selects this
+	  module must depend on PCI.
+
 menuconfig VIRTIO_MENU
 	bool "Virtio drivers"
 	default y
@@ -43,6 +52,7 @@ config VIRTIO_PCI_LEGACY
 	bool "Support for legacy virtio draft 0.9.X and older devices"
 	default y
 	depends on VIRTIO_PCI
+	select VIRTIO_PCI_LIB_LEGACY
 	help
           Virtio PCI Card 0.9.X Draft (circa 2014) and older device support.
 
drivers/virtio/Makefile +1 -0
index 699bbea0465f..0a82d0873248 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
 obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o
+obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_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.c +6 -4
index b35bb2d57f62..d724f676608b 100644
@@ -549,6 +549,8 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 
 	pci_set_master(pci_dev);
 
+	vp_dev->is_legacy = vp_dev->ldev.ioaddr ? true : false;
+
 	rc = register_virtio_device(&vp_dev->vdev);
 	reg_dev = vp_dev;
 	if (rc)
@@ -557,10 +559,10 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 	return 0;
 
 err_register:
-	if (vp_dev->ioaddr)
-	     virtio_pci_legacy_remove(vp_dev);
+	if (vp_dev->is_legacy)
+		virtio_pci_legacy_remove(vp_dev);
 	else
-	     virtio_pci_modern_remove(vp_dev);
+		virtio_pci_modern_remove(vp_dev);
 err_probe:
 	pci_disable_device(pci_dev);
 err_enable_device:
@@ -587,7 +589,7 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
 
 	unregister_virtio_device(&vp_dev->vdev);
 
-	if (vp_dev->ioaddr)
+	if (vp_dev->is_legacy)
 		virtio_pci_legacy_remove(vp_dev);
 	else
 		virtio_pci_modern_remove(vp_dev);
drivers/virtio/virtio_pci_common.h +4 -5
index beec047a8f8d..eb17a29fc7ef 100644
@@ -25,6 +25,7 @@
 #include <linux/virtio_config.h>
 #include <linux/virtio_ring.h>
 #include <linux/virtio_pci.h>
+#include <linux/virtio_pci_legacy.h>
 #include <linux/virtio_pci_modern.h>
 #include <linux/highmem.h>
 #include <linux/spinlock.h>
@@ -44,16 +45,14 @@ struct virtio_pci_vq_info {
 struct virtio_pci_device {
 	struct virtio_device vdev;
 	struct pci_dev *pci_dev;
+	struct virtio_pci_legacy_device ldev;
 	struct virtio_pci_modern_device mdev;
 
-	/* In legacy mode, these two point to within ->legacy. */
+	bool is_legacy;
+
 	/* Where to read and clear interrupt */
 	u8 __iomem *isr;
 
-	/* Legacy only field */
-	/* the IO mapping for the PCI config space */
-	void __iomem *ioaddr;
-
 	/* a list of queues so we can dispatch IRQs */
 	spinlock_t lock;
 	struct list_head virtqueues;
drivers/virtio/virtio_pci_legacy.c +27 -74

212 lines not on this page · raw message

drivers/virtio/virtio_pci_legacy_dev.c new file +220 -0

220 lines not on this page · raw message

include/linux/virtio_pci_legacy.h new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
2.31.1
#99 lore raw

Re: [PATCH v5 1/8] virtio-pci: introduce legacy device module

include/linux/virtio_pci_legacy.h line 34

Quoted 2 lines · Wu Zongyong
include/linux/virtio_pci_legacy.h new file +2 -0
+void vp_legacy_set_queue_enable(struct virtio_pci_legacy_device *ldev,
+				u16 idx, bool enable);

Similar to previous one, this function is not implemented in this patch.

Thanks

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#100 lore raw

PATCH v5 2/8 vdpa: fix typo

In reply to Wu Zongyong
---
 include/linux/vdpa.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/vdpa.h +1 -1
index 3972ab765de1..a896ee021e5f 100644
@@ -257,7 +257,7 @@ struct vdpa_config_ops {
 	struct vdpa_notification_area
 	(*get_vq_notification)(struct vdpa_device *vdev, u16 idx);
 	/* vq irq is not expected to be changed once DRIVER_OK is set */
-	int (*get_vq_irq)(struct vdpa_device *vdv, u16 idx);
+	int (*get_vq_irq)(struct vdpa_device *vdev, u16 idx);
 
 	/* Device ops */
 	u32 (*get_vq_align)(struct vdpa_device *vdev);
Signature · 1 line
2.31.1
#101 lore raw

PATCH v5 3/8 vp_vdpa: add vq irq offloading support

In reply to Wu Zongyong

This patch implements the get_vq_irq() callback for virtio pci devices to allow irq offloading.

---
 drivers/vdpa/virtio_pci/vp_vdpa.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/vdpa/virtio_pci/vp_vdpa.c +12 -0
index 5bcd00246d2e..e3ff7875e123 100644
@@ -76,6 +76,17 @@ static u8 vp_vdpa_get_status(struct vdpa_device *vdpa)
 	return vp_modern_get_status(mdev);
 }
 
+static int vp_vdpa_get_vq_irq(struct vdpa_device *vdpa, u16 idx)
+{
+	struct vp_vdpa *vp_vdpa = vdpa_to_vp(vdpa);
+	int irq = vp_vdpa->vring[idx].irq;
+
+	if (irq == VIRTIO_MSI_NO_VECTOR)
+		return -EINVAL;
+
+	return irq;
+}
+
 static void vp_vdpa_free_irq(struct vp_vdpa *vp_vdpa)
 {
 	struct virtio_pci_modern_device *mdev = &vp_vdpa->mdev;
@@ -427,6 +438,7 @@ static const struct vdpa_config_ops vp_vdpa_ops = {
 	.get_config	= vp_vdpa_get_config,
 	.set_config	= vp_vdpa_set_config,
 	.set_config_cb  = vp_vdpa_set_config_cb,
+	.get_vq_irq	= vp_vdpa_get_vq_irq,
 };
 
 static void vp_vdpa_free_irq_vectors(void *data)
Signature · 1 line
2.31.1
#102 lore raw

PATCH v5 4/8 vdpa: add new callback get_vq_num_min in vdpa_config_ops

In reply to Wu Zongyong

This callback is optional. For vdpa devices that not support to change virtqueue size, get_vq_num_min and get_vq_num_max will return the same value, so that users can choose a correct value for that device.

---
 include/linux/vdpa.h | 4 ++++
 1 file changed, 4 insertions(+)
include/linux/vdpa.h +4 -0
index a896ee021e5f..30864848950b 100644
@@ -171,6 +171,9 @@ struct vdpa_map_file {
  * @get_vq_num_max:		Get the max size of virtqueue
  *				@vdev: vdpa device
  *				Returns u16: max size of virtqueue
+ * @get_vq_num_min:		Get the min size of virtqueue (optional)
+ *				@vdev: vdpa device
+ *				Returns u16: min size of virtqueue
  * @get_device_id:		Get virtio device id
  *				@vdev: vdpa device
  *				Returns u32: virtio device id
@@ -266,6 +269,7 @@ struct vdpa_config_ops {
 	void (*set_config_cb)(struct vdpa_device *vdev,
 			      struct vdpa_callback *cb);
 	u16 (*get_vq_num_max)(struct vdpa_device *vdev);
+	u16 (*get_vq_num_min)(struct vdpa_device *vdev);
 	u32 (*get_device_id)(struct vdpa_device *vdev);
 	u32 (*get_vendor_id)(struct vdpa_device *vdev);
 	u8 (*get_status)(struct vdpa_device *vdev);
Signature · 1 line
2.31.1
Acked-by on v5 4/8
#103 lore raw

Re: [PATCH v5 4/8] vdpa: add new callback get_vq_num_min in vdpa_config_ops

Quoted 6 lines · Wu Zongyong

This callback is optional. For vdpa devices that not support to change virtqueue size, get_vq_num_min and get_vq_num_max will return the same value, so that users can choose a correct value for that device.

Quoted 19 lines
---
  include/linux/vdpa.h | 4 ++++
  1 file changed, 4 insertions(+)
include/linux/vdpa.h +3 -0
index a896ee021e5f..30864848950b 100644
@@ -171,6 +171,9 @@ struct vdpa_map_file {
   * @get_vq_num_max:		Get the max size of virtqueue
   *				@vdev: vdpa device
   *				Returns u16: max size of virtqueue
+ * @get_vq_num_min:		Get the min size of virtqueue (optional)
+ *				@vdev: vdpa device
+ *				Returns u16: min size of virtqueue
   * @get_device_id:		Get virtio device id
   *				@vdev: vdpa device
   *				Returns u32: virtio device id

include/linux/vdpa.h struct vdpa_config_ops { · line 275

Quoted 7 lines
include/linux/vdpa.h +1 -0
@@ -266,6 +269,7 @@ struct vdpa_config_ops {
  	void (*set_config_cb)(struct vdpa_device *vdev,
  			      struct vdpa_callback *cb);
  	u16 (*get_vq_num_max)(struct vdpa_device *vdev);
+	u16 (*get_vq_num_min)(struct vdpa_device *vdev);
  	u32 (*get_device_id)(struct vdpa_device *vdev);
  	u32 (*get_vendor_id)(struct vdpa_device *vdev);
  	u8 (*get_status)(struct vdpa_device *vdev);

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#104 lore raw

PATCH v5 5/8 vdpa: min vq num of vdpa device cannot be greater than max vq num

In reply to Wu Zongyong

Just failed to probe the vdpa device if the min virtqueue num returned by get_vq_num_min is greater than the max virtqueue num returned by get_vq_num_max.

---
 drivers/vdpa/vdpa.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/vdpa/vdpa.c +8 -0
index 1dc121a07a93..fd014ecec711 100644
@@ -26,8 +26,16 @@ static int vdpa_dev_probe(struct device *d)
 {
 	struct vdpa_device *vdev = dev_to_vdpa(d);
 	struct vdpa_driver *drv = drv_to_vdpa(vdev->dev.driver);
+	const struct vdpa_config_ops *ops = vdev->config;
+	u32 max_num, min_num = 0;
 	int ret = 0;
 
+	max_num = ops->get_vq_num_max(vdev);
+	if (ops->get_vq_num_min)
+		min_num = ops->get_vq_num_min(vdev);
+	if (max_num < min_num)
+		return -EINVAL;
+
 	if (drv && drv->probe)
 		ret = drv->probe(vdev);
 
Signature · 1 line
2.31.1
#105 lore raw

Re: [PATCH v5 5/8] vdpa: min vq num of vdpa device cannot be greater than max vq num

Quoted 14 lines · Wu Zongyong

Just failed to probe the vdpa device if the min virtqueue num returned by get_vq_num_min is greater than the max virtqueue num returned by get_vq_num_max.

---
  drivers/vdpa/vdpa.c | 8 ++++++++
  1 file changed, 8 insertions(+)
drivers/vdpa/vdpa.c +0 -0
index 1dc121a07a93..fd014ecec711 100644

drivers/vdpa/vdpa.c static int vdpa_dev_probe(struct device *d) · line 30

Quoted 5 lines
drivers/vdpa/vdpa.c +2 -0
@@ -26,8 +26,16 @@ static int vdpa_dev_probe(struct device *d)
  {
  	struct vdpa_device *vdev = dev_to_vdpa(d);
  	struct vdpa_driver *drv = drv_to_vdpa(vdev->dev.driver);
+	const struct vdpa_config_ops *ops = vdev->config;
+	u32 max_num, min_num = 0;

As discussed in previous version, 1 seems better?

Thanks

drivers/vdpa/vdpa.c static int vdpa_dev_probe(struct device *d) · line 41

Quoted 11 lines
drivers/vdpa/vdpa.c +6 -0
  	int ret = 0;
 
+	max_num = ops->get_vq_num_max(vdev);
+	if (ops->get_vq_num_min)
+		min_num = ops->get_vq_num_min(vdev);
+	if (max_num < min_num)
+		return -EINVAL;
+
  	if (drv && drv->probe)
  		ret = drv->probe(vdev);
 

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#106 lore raw

PATCH v5 6/8 virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}

In reply to Wu Zongyong

For the devices which implement the get_vq_num_min callback, the driver should not negotiate with virtqueue size with the backend vdpa device if the value returned by get_vq_num_min equals to the value returned by get_vq_num_max.
This is useful for vdpa devices based on legacy virtio specfication.

---
 drivers/virtio/virtio_vdpa.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/virtio/virtio_vdpa.c +16 -5
index 72eaef2caeb1..e42ace29daa1 100644
@@ -145,7 +145,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 	/* Assume split virtqueue, switch to packed if necessary */
 	struct vdpa_vq_state state = {0};
 	unsigned long flags;
-	u32 align, num;
+	u32 align, max_num, min_num = 0;
+	bool may_reduce_num = true;
 	int err;
 
 	if (!name)
@@ -163,22 +164,32 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 	if (!info)
 		return ERR_PTR(-ENOMEM);
 
-	num = ops->get_vq_num_max(vdpa);
-	if (num == 0) {
+	max_num = ops->get_vq_num_max(vdpa);
+	if (max_num == 0) {
 		err = -ENOENT;
 		goto error_new_virtqueue;
 	}
 
+	if (ops->get_vq_num_min)
+		min_num = ops->get_vq_num_min(vdpa);
+
+	may_reduce_num = (max_num == min_num) ? false : true;
+
 	/* Create the vring */
 	align = ops->get_vq_align(vdpa);
-	vq = vring_create_virtqueue(index, num, align, vdev,
-				    true, true, ctx,
+	vq = vring_create_virtqueue(index, max_num, align, vdev,
+				    true, may_reduce_num, ctx,
 				    virtio_vdpa_notify, callback, name);
 	if (!vq) {
 		err = -ENOMEM;
 		goto error_new_virtqueue;
 	}
 
+	if (virtqueue_get_vring_size(vq) < min_num) {
+		err = -EINVAL;
+		goto err_vq;
+	}
+
 	/* Setup virtqueue callback */
 	cb.callback = virtio_vdpa_virtqueue_cb;
 	cb.private = info;
Signature · 1 line
2.31.1
#107 lore raw

Re: [PATCH v5 6/8] virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}

Quoted 48 lines · Wu Zongyong

For the devices which implement the get_vq_num_min callback, the driver should not negotiate with virtqueue size with the backend vdpa device if the value returned by get_vq_num_min equals to the value returned by get_vq_num_max.
This is useful for vdpa devices based on legacy virtio specfication.

---
  drivers/virtio/virtio_vdpa.c | 21 ++++++++++++++++-----
  1 file changed, 16 insertions(+), 5 deletions(-)
drivers/virtio/virtio_vdpa.c +11 -5
index 72eaef2caeb1..e42ace29daa1 100644
@@ -145,7 +145,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
  	/* Assume split virtqueue, switch to packed if necessary */
  	struct vdpa_vq_state state = {0};
  	unsigned long flags;
-	u32 align, num;
+	u32 align, max_num, min_num = 0;
+	bool may_reduce_num = true;
  	int err;
 
  	if (!name)
@@ -163,22 +164,32 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
  	if (!info)
  		return ERR_PTR(-ENOMEM);
 
-	num = ops->get_vq_num_max(vdpa);
-	if (num == 0) {
+	max_num = ops->get_vq_num_max(vdpa);
+	if (max_num == 0) {
  		err = -ENOENT;
  		goto error_new_virtqueue;
  	}
 
+	if (ops->get_vq_num_min)
+		min_num = ops->get_vq_num_min(vdpa);
+
+	may_reduce_num = (max_num == min_num) ? false : true;
+
  	/* Create the vring */
  	align = ops->get_vq_align(vdpa);
-	vq = vring_create_virtqueue(index, num, align, vdev,
-				    true, true, ctx,
+	vq = vring_create_virtqueue(index, max_num, align, vdev,
+				    true, may_reduce_num, ctx,

drivers/virtio/virtio_vdpa.c virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, · line 191

Quoted 10 lines
drivers/virtio/virtio_vdpa.c +4 -0
  				    virtio_vdpa_notify, callback, name);
  	if (!vq) {
  		err = -ENOMEM;
  		goto error_new_virtqueue;
  	}
 
+	if (virtqueue_get_vring_size(vq) < min_num) {
+		err = -EINVAL;
+		goto err_vq;
+	}

Under which condition can we hit this error?

Thanks

Quoted 4 lines
drivers/virtio/virtio_vdpa.c +1 -0
+
  	/* Setup virtqueue callback */
  	cb.callback = virtio_vdpa_virtqueue_cb;
  	cb.private = info;
#108 lore raw

PATCH v5 7/8 vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE

In reply to Wu Zongyong

This attribute advertises the min value of virtqueue size. The value is 0 by default.

---
 drivers/vdpa/vdpa.c       | 5 +++++
 include/uapi/linux/vdpa.h | 1 +
 2 files changed, 6 insertions(+)
drivers/vdpa/vdpa.c +5 -0
index fd014ecec711..4aeb1458b924 100644
@@ -500,6 +500,7 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
 	      int flags, struct netlink_ext_ack *extack)
 {
 	u16 max_vq_size;
+	u16 min_vq_size = 0;
 	u32 device_id;
 	u32 vendor_id;
 	void *hdr;
@@ -516,6 +517,8 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
 	device_id = vdev->config->get_device_id(vdev);
 	vendor_id = vdev->config->get_vendor_id(vdev);
 	max_vq_size = vdev->config->get_vq_num_max(vdev);
+	if (vdev->config->get_vq_num_min)
+		min_vq_size = vdev->config->get_vq_num_min(vdev);
 
 	err = -EMSGSIZE;
 	if (nla_put_string(msg, VDPA_ATTR_DEV_NAME, dev_name(&vdev->dev)))
@@ -528,6 +531,8 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
 		goto msg_err;
 	if (nla_put_u16(msg, VDPA_ATTR_DEV_MAX_VQ_SIZE, max_vq_size))
 		goto msg_err;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_MIN_VQ_SIZE, min_vq_size))
+		goto msg_err;
 
 	genlmsg_end(msg, hdr);
 	return 0;
include/uapi/linux/vdpa.h +1 -0
index 66a41e4ec163..e3b87879514c 100644
@@ -32,6 +32,7 @@ enum vdpa_attr {
 	VDPA_ATTR_DEV_VENDOR_ID,		/* u32 */
 	VDPA_ATTR_DEV_MAX_VQS,			/* u32 */
 	VDPA_ATTR_DEV_MAX_VQ_SIZE,		/* u16 */
+	VDPA_ATTR_DEV_MIN_VQ_SIZE,		/* u16 */
 
 	/* new attributes must be added above here */
 	VDPA_ATTR_MAX,
Signature · 1 line
2.31.1
#109 lore raw

PATCH v5 8/8 eni_vdpa: add vDPA driver for Alibaba ENI

In reply to Wu Zongyong

This patch adds a new vDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon virtio 0.9.5 specification. And this driver doesn't support to run on BE host.

---
 drivers/vdpa/Kconfig            |   8 +
 drivers/vdpa/Makefile           |   1 +
 drivers/vdpa/alibaba/Makefile   |   3 +
 drivers/vdpa/alibaba/eni_vdpa.c | 553 ++++++++++++++++++++++++++++++++
 4 files changed, 565 insertions(+)
 create mode 100644 drivers/vdpa/alibaba/Makefile
 create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
drivers/vdpa/Kconfig +8 -0
index 3d91982d8371..c0232a2148a7 100644
@@ -78,4 +78,12 @@ config VP_VDPA
 	help
 	  This kernel module bridges virtio PCI device to vDPA bus.
 
+config ALIBABA_ENI_VDPA
+	tristate "vDPA driver for Alibaba ENI"
+	select VIRTIO_PCI_LEGACY_LIB
+	depends on PCI_MSI && !CPU_BIG_ENDIAN
+	help
+	  VDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon
+	  virtio 0.9.5 specification.
+
 endif # VDPA
drivers/vdpa/Makefile +1 -0
index f02ebed33f19..15665563a7f4 100644
@@ -5,3 +5,4 @@ obj-$(CONFIG_VDPA_USER) += vdpa_user/
 obj-$(CONFIG_IFCVF)    += ifcvf/
 obj-$(CONFIG_MLX5_VDPA) += mlx5/
 obj-$(CONFIG_VP_VDPA)    += virtio_pci/
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += alibaba/
drivers/vdpa/alibaba/Makefile new file +3 -0
new file mode 100644
index 000000000000..ef4aae69f87a
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += eni_vdpa.o
+
drivers/vdpa/alibaba/eni_vdpa.c new file +553 -0

553 lines not on this page · raw message

Signature · 1 line
2.31.1
#110 lore raw

Re: [PATCH v5 8/8] eni_vdpa: add vDPA driver for Alibaba ENI

Quoted 16 lines · Wu Zongyong
drivers/vdpa/alibaba/eni_vdpa.c new file +16 -0
+
+static u64 eni_vdpa_get_features(struct vdpa_device *vdpa)
+{
+	struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+	u64 features = vp_legacy_get_features(ldev);
+
+	features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM);
+	features |= BIT_ULL(VIRTIO_F_ORDER_PLATFORM);
+
+	return features;
+}
+
+static int eni_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
+{
+	struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+

drivers/vdpa/alibaba/eni_vdpa.c line 85

Quoted 10 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +10 -0
+	if (!(features & BIT_ULL(VIRTIO_NET_F_MRG_RXBUF)) && features) {
+		ENI_ERR(ldev->pci_dev,
+			"VIRTIO_NET_F_MRG_RXBUF is not negotiated\n");
+		return -EINVAL;
+	}
+
+	vp_legacy_set_features(ldev, (u32)features);
+
+	return 0;
+}

Hi:

It looks like some of my previous comments were ignored?

drivers/vdpa/alibaba/eni_vdpa.c line 67

Quoted 7 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +7 -0
+static u64 eni_vdpa_get_features(struct vdpa_device *vdpa)
+{
+	struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+	u64 features = vp_legacy_get_features(ldev);
+
+	features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM);
+	features |= BIT_ULL(VIRTIO_F_ORDER_PLATFORM);

VERSION_1 is also needed?

drivers/vdpa/alibaba/eni_vdpa.c line 79

Quoted 12 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +12 -0
+
+	return features;
+}
+
+static int eni_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
+{
+	struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+	if (!(features & BIT_ULL(VIRTIO_NET_F_MRG_RXBUF)) && features) {
+		ENI_ERR(ldev->pci_dev,
+			"VIRTIO_NET_F_MRG_RXBUF is not negotiated\n");
+		return -EINVAL;

Do we need to make sure FEATURE_OK is not set in this case or the ENI can do this for us?

Other looks good.

Thanks

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#111 lore raw

Re: [PATCH v5 8/8] eni_vdpa: add vDPA driver for Alibaba ENI

In reply to Wu Zongyong
Quoted 5 lines · Wu Zongyong
drivers/vdpa/Kconfig +0 -0
index 3d91982d8371..c0232a2148a7 100644

drivers/vdpa/Kconfig config VP_VDPA · line 86

Quoted 9 lines
drivers/vdpa/Kconfig +6 -0
@@ -78,4 +78,12 @@ config VP_VDPA
  	help
  	  This kernel module bridges virtio PCI device to vDPA bus.
 
+config ALIBABA_ENI_VDPA
+	tristate "vDPA driver for Alibaba ENI"
+	select VIRTIO_PCI_LEGACY_LIB
+	depends on PCI_MSI && !CPU_BIG_ENDIAN
+	help
+	  VDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon

ENI (Elastic Network Interface) built

Quoted 1 line
drivers/vdpa/Kconfig +1 -0
+	  virtio 0.9.5 specification.
Signature · 1 line
~Randy
#112 lore raw

v6 cover vDPA driver for Alibaba ENI

In reply to Wu Zongyong

This series implements the vDPA driver for Alibaba ENI(Elastic Network Interface) which is build based on virtio-pci 0.9.5 specification.

Changes since V5:
- remove unused codes

Changes since V4:
- check return values of get_vq_num_{max,min} when probing devices
- disable the driver on BE host via Kconfig
- add missing commit message

Changes since V3:
- validate VIRTIO_NET_F_MRG_RXBUF when negotiate features
- present F_ORDER_PLATFORM in get_features
- remove endian check since ENI always use litter endian

Changes since V2:
- add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE instead VDPA_ATTR_DEV_F_VERSION_1 to guide users to choose correct virtqueue size as suggested by Jason Wang
- present ACCESS_PLATFORM in get_features callback as suggested by Jason Wang
- disable this driver on Big Endian host as suggested by Jason Wang
- fix a typo

Changes since V1:
- add new vdpa attribute VDPA_ATTR_DEV_F_VERSION_1 to indicate whether the vdpa device is legacy
- implement dedicated driver for Alibaba ENI instead a legacy virtio-pci driver as suggested by Jason Wang
- some bugs fixed

Wu Zongyong (8):
virtio-pci: introduce legacy device module
vdpa: fix typo
vp_vdpa: add vq irq offloading support
vdpa: add new callback get_vq_num_min in vdpa_config_ops
vdpa: min vq num of vdpa device cannot be greater than max vq num
virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}
vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE
eni_vdpa: add vDPA driver for Alibaba ENI

 drivers/vdpa/Kconfig                   |   8 +
 drivers/vdpa/Makefile                  |   1 +
 drivers/vdpa/alibaba/Makefile          |   3 +
 drivers/vdpa/alibaba/eni_vdpa.c        | 553 +++++++++++++++++++++++++
 drivers/vdpa/vdpa.c                    |  13 +
 drivers/vdpa/virtio_pci/vp_vdpa.c      |  12 +
 drivers/virtio/Kconfig                 |  10 +
 drivers/virtio/Makefile                |   1 +
 drivers/virtio/virtio_pci_common.c     |  10 +-
 drivers/virtio/virtio_pci_common.h     |   9 +-
 drivers/virtio/virtio_pci_legacy.c     | 101 ++---
 drivers/virtio/virtio_pci_legacy_dev.c | 220 ++++++++++
 drivers/virtio/virtio_vdpa.c           |  21 +-
 include/linux/vdpa.h                   |   6 +-
 include/linux/virtio_pci_legacy.h      |  42 ++
 include/uapi/linux/vdpa.h              |   1 +
 16 files changed, 922 insertions(+), 89 deletions(-)
 create mode 100644 drivers/vdpa/alibaba/Makefile
 create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
 create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c
 create mode 100644 include/linux/virtio_pci_legacy.h
Signature · 1 line
2.31.1
#113 lore raw

PATCH v6 1/8 virtio-pci: introduce legacy device module

Split common codes from virtio-pci-legacy so vDPA driver can reuse it later.

---
 drivers/virtio/Kconfig                 |  10 ++
 drivers/virtio/Makefile                |   1 +
 drivers/virtio/virtio_pci_common.c     |  10 +-
 drivers/virtio/virtio_pci_common.h     |   9 +-
 drivers/virtio/virtio_pci_legacy.c     | 101 +++---------
 drivers/virtio/virtio_pci_legacy_dev.c | 220 +++++++++++++++++++++++++
 include/linux/virtio_pci_legacy.h      |  42 +++++
 7 files changed, 310 insertions(+), 83 deletions(-)
 create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c
 create mode 100644 include/linux/virtio_pci_legacy.h
drivers/virtio/Kconfig +10 -0
index ce1b3f6ec325..8fcf94cd2c96 100644
@@ -20,6 +20,15 @@ config VIRTIO_PCI_LIB
 	  PCI device with possible vendor specific extensions. Any
 	  module that selects this module must depend on PCI.
 
+config VIRTIO_PCI_LIB_LEGACY
+	tristate
+	help
+	  Legacy PCI device (Virtio PCI Card 0.9.x Draft and older device)
+	  implementation.
+	  This module implements the basic probe and control for devices
+	  which are based on legacy PCI device. Any module that selects this
+	  module must depend on PCI.
+
 menuconfig VIRTIO_MENU
 	bool "Virtio drivers"
 	default y
@@ -43,6 +52,7 @@ config VIRTIO_PCI_LEGACY
 	bool "Support for legacy virtio draft 0.9.X and older devices"
 	default y
 	depends on VIRTIO_PCI
+	select VIRTIO_PCI_LIB_LEGACY
 	help
           Virtio PCI Card 0.9.X Draft (circa 2014) and older device support.
 
drivers/virtio/Makefile +1 -0
index 699bbea0465f..0a82d0873248 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
 obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o
+obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_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.c +6 -4
index b35bb2d57f62..d724f676608b 100644
@@ -549,6 +549,8 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 
 	pci_set_master(pci_dev);
 
+	vp_dev->is_legacy = vp_dev->ldev.ioaddr ? true : false;
+
 	rc = register_virtio_device(&vp_dev->vdev);
 	reg_dev = vp_dev;
 	if (rc)
@@ -557,10 +559,10 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 	return 0;
 
 err_register:
-	if (vp_dev->ioaddr)
-	     virtio_pci_legacy_remove(vp_dev);
+	if (vp_dev->is_legacy)
+		virtio_pci_legacy_remove(vp_dev);
 	else
-	     virtio_pci_modern_remove(vp_dev);
+		virtio_pci_modern_remove(vp_dev);
 err_probe:
 	pci_disable_device(pci_dev);
 err_enable_device:
@@ -587,7 +589,7 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
 
 	unregister_virtio_device(&vp_dev->vdev);
 
-	if (vp_dev->ioaddr)
+	if (vp_dev->is_legacy)
 		virtio_pci_legacy_remove(vp_dev);
 	else
 		virtio_pci_modern_remove(vp_dev);
drivers/virtio/virtio_pci_common.h +4 -5
index beec047a8f8d..eb17a29fc7ef 100644
@@ -25,6 +25,7 @@
 #include <linux/virtio_config.h>
 #include <linux/virtio_ring.h>
 #include <linux/virtio_pci.h>
+#include <linux/virtio_pci_legacy.h>
 #include <linux/virtio_pci_modern.h>
 #include <linux/highmem.h>
 #include <linux/spinlock.h>
@@ -44,16 +45,14 @@ struct virtio_pci_vq_info {
 struct virtio_pci_device {
 	struct virtio_device vdev;
 	struct pci_dev *pci_dev;
+	struct virtio_pci_legacy_device ldev;
 	struct virtio_pci_modern_device mdev;
 
-	/* In legacy mode, these two point to within ->legacy. */
+	bool is_legacy;
+
 	/* Where to read and clear interrupt */
 	u8 __iomem *isr;
 
-	/* Legacy only field */
-	/* the IO mapping for the PCI config space */
-	void __iomem *ioaddr;
-
 	/* a list of queues so we can dispatch IRQs */
 	spinlock_t lock;
 	struct list_head virtqueues;
drivers/virtio/virtio_pci_legacy.c +27 -74

212 lines not on this page · raw message

drivers/virtio/virtio_pci_legacy_dev.c new file +220 -0

220 lines not on this page · raw message

include/linux/virtio_pci_legacy.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.31.1
Acked-by on v6 1/8
#114 lore raw

Re: [PATCH v6 1/8] virtio-pci: introduce legacy device module

Quoted 5 lines · Wu Zongyong

Split common codes from virtio-pci-legacy so vDPA driver can reuse it later.

Quoted 626 lines
---
 drivers/virtio/Kconfig                 |  10 ++
 drivers/virtio/Makefile                |   1 +
 drivers/virtio/virtio_pci_common.c     |  10 +-
 drivers/virtio/virtio_pci_common.h     |   9 +-
 drivers/virtio/virtio_pci_legacy.c     | 101 +++---------
 drivers/virtio/virtio_pci_legacy_dev.c | 220 +++++++++++++++++++++++++
 include/linux/virtio_pci_legacy.h      |  42 +++++
 7 files changed, 310 insertions(+), 83 deletions(-)
 create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c
 create mode 100644 include/linux/virtio_pci_legacy.h
drivers/virtio/Kconfig +10 -0
index ce1b3f6ec325..8fcf94cd2c96 100644
@@ -20,6 +20,15 @@ config VIRTIO_PCI_LIB
          PCI device with possible vendor specific extensions. Any
          module that selects this module must depend on PCI.
 
+config VIRTIO_PCI_LIB_LEGACY
+       tristate
+       help
+         Legacy PCI device (Virtio PCI Card 0.9.x Draft and older device)
+         implementation.
+         This module implements the basic probe and control for devices
+         which are based on legacy PCI device. Any module that selects this
+         module must depend on PCI.
+
 menuconfig VIRTIO_MENU
        bool "Virtio drivers"
        default y
@@ -43,6 +52,7 @@ config VIRTIO_PCI_LEGACY
        bool "Support for legacy virtio draft 0.9.X and older devices"
        default y
        depends on VIRTIO_PCI
+       select VIRTIO_PCI_LIB_LEGACY
        help
           Virtio PCI Card 0.9.X Draft (circa 2014) and older device support.
 
drivers/virtio/Makefile +1 -0
index 699bbea0465f..0a82d0873248 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
 obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o
+obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_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.c +6 -4
index b35bb2d57f62..d724f676608b 100644
@@ -549,6 +549,8 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 
        pci_set_master(pci_dev);
 
+       vp_dev->is_legacy = vp_dev->ldev.ioaddr ? true : false;
+
        rc = register_virtio_device(&vp_dev->vdev);
        reg_dev = vp_dev;
        if (rc)
@@ -557,10 +559,10 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
        return 0;
 
 err_register:
-       if (vp_dev->ioaddr)
-            virtio_pci_legacy_remove(vp_dev);
+       if (vp_dev->is_legacy)
+               virtio_pci_legacy_remove(vp_dev);
        else
-            virtio_pci_modern_remove(vp_dev);
+               virtio_pci_modern_remove(vp_dev);
 err_probe:
        pci_disable_device(pci_dev);
 err_enable_device:
@@ -587,7 +589,7 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
 
        unregister_virtio_device(&vp_dev->vdev);
 
-       if (vp_dev->ioaddr)
+       if (vp_dev->is_legacy)
                virtio_pci_legacy_remove(vp_dev);
        else
                virtio_pci_modern_remove(vp_dev);
drivers/virtio/virtio_pci_common.h +4 -5
index beec047a8f8d..eb17a29fc7ef 100644
@@ -25,6 +25,7 @@
 #include <linux/virtio_config.h>
 #include <linux/virtio_ring.h>
 #include <linux/virtio_pci.h>
+#include <linux/virtio_pci_legacy.h>
 #include <linux/virtio_pci_modern.h>
 #include <linux/highmem.h>
 #include <linux/spinlock.h>
@@ -44,16 +45,14 @@ struct virtio_pci_vq_info {
 struct virtio_pci_device {
        struct virtio_device vdev;
        struct pci_dev *pci_dev;
+       struct virtio_pci_legacy_device ldev;
        struct virtio_pci_modern_device mdev;
 
-       /* In legacy mode, these two point to within ->legacy. */
+       bool is_legacy;
+
        /* Where to read and clear interrupt */
        u8 __iomem *isr;
 
-       /* Legacy only field */
-       /* the IO mapping for the PCI config space */
-       void __iomem *ioaddr;
-
        /* a list of queues so we can dispatch IRQs */
        spinlock_t lock;
        struct list_head virtqueues;
drivers/virtio/virtio_pci_legacy.c +27 -74
index d62e9835aeec..82eb437ad920 100644
@@ -14,6 +14,7 @@
  *  Michael S. Tsirkin <[email protected]>
  */
 
+#include "linux/virtio_pci_legacy.h"
 #include "virtio_pci_common.h"
 
 /* virtio config->get_features() implementation */
@@ -23,7 +24,7 @@ static u64 vp_get_features(struct virtio_device *vdev)
 
        /* When someone needs more than 32 feature bits, we'll need to
         * steal a bit to indicate that the rest are somewhere else. */
-       return ioread32(vp_dev->ioaddr + VIRTIO_PCI_HOST_FEATURES);
+       return vp_legacy_get_features(&vp_dev->ldev);
 }
 
 /* virtio config->finalize_features() implementation */
@@ -38,7 +39,7 @@ static int vp_finalize_features(struct virtio_device *vdev)
        BUG_ON((u32)vdev->features != vdev->features);
 
        /* We only support 32 feature bits. */
-       iowrite32(vdev->features, vp_dev->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
+       vp_legacy_set_features(&vp_dev->ldev, vdev->features);
 
        return 0;
 }
@@ -48,7 +49,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 *ioaddr = vp_dev->ioaddr +
+       void __iomem *ioaddr = vp_dev->ldev.ioaddr +
                        VIRTIO_PCI_CONFIG_OFF(vp_dev->msix_enabled) +
                        offset;
        u8 *ptr = buf;
@@ -64,7 +65,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 *ioaddr = vp_dev->ioaddr +
+       void __iomem *ioaddr = vp_dev->ldev.ioaddr +
                        VIRTIO_PCI_CONFIG_OFF(vp_dev->msix_enabled) +
                        offset;
        const u8 *ptr = buf;
@@ -78,7 +79,7 @@ static void vp_set(struct virtio_device *vdev, unsigned offset,
 static u8 vp_get_status(struct virtio_device *vdev)
 {
        struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-       return ioread8(vp_dev->ioaddr + VIRTIO_PCI_STATUS);
+       return vp_legacy_get_status(&vp_dev->ldev);
 }
 
 static void vp_set_status(struct virtio_device *vdev, u8 status)
@@ -86,28 +87,24 @@ static void vp_set_status(struct virtio_device *vdev, u8 status)
        struct virtio_pci_device *vp_dev = to_vp_device(vdev);
        /* We should never be setting status to 0. */
        BUG_ON(status == 0);
-       iowrite8(status, vp_dev->ioaddr + VIRTIO_PCI_STATUS);
+       vp_legacy_set_status(&vp_dev->ldev, status);
 }
 
 static void vp_reset(struct virtio_device *vdev)
 {
        struct virtio_pci_device *vp_dev = to_vp_device(vdev);
        /* 0 status means a reset. */
-       iowrite8(0, vp_dev->ioaddr + VIRTIO_PCI_STATUS);
+       vp_legacy_set_status(&vp_dev->ldev, 0);
        /* Flush out the status write, and flush in device writes,
         * including MSi-X interrupts, if any. */
-       ioread8(vp_dev->ioaddr + VIRTIO_PCI_STATUS);
+       vp_legacy_get_status(&vp_dev->ldev);
        /* Flush pending VQ/configuration callbacks. */
        vp_synchronize_vectors(vdev);
 }
 
 static u16 vp_config_vector(struct virtio_pci_device *vp_dev, u16 vector)
 {
-       /* Setup the vector used for configuration events */
-       iowrite16(vector, vp_dev->ioaddr + VIRTIO_MSI_CONFIG_VECTOR);
-       /* Verify we had enough resources to assign the vector */
-       /* Will also flush the write out to device */
-       return ioread16(vp_dev->ioaddr + VIRTIO_MSI_CONFIG_VECTOR);
+       return vp_legacy_config_vector(&vp_dev->ldev, vector);
 }
 
 static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
@@ -123,12 +120,9 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
        int err;
        u64 q_pfn;
 
-       /* Select the queue we're interested in */
-       iowrite16(index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
-
        /* Check if queue is either not available or already active. */
-       num = ioread16(vp_dev->ioaddr + VIRTIO_PCI_QUEUE_NUM);
-       if (!num || ioread32(vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN))
+       num = vp_legacy_get_queue_size(&vp_dev->ldev, index);
+       if (!num || vp_legacy_get_queue_enable(&vp_dev->ldev, index))
                return ERR_PTR(-ENOENT);
 
        info->msix_vector = msix_vec;
@@ -151,13 +145,12 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
        }
 
        /* activate the queue */
-       iowrite32(q_pfn, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
+       vp_legacy_set_queue_address(&vp_dev->ldev, index, q_pfn);
 
-       vq->priv = (void __force *)vp_dev->ioaddr + VIRTIO_PCI_QUEUE_NOTIFY;
+       vq->priv = (void __force *)vp_dev->ldev.ioaddr + VIRTIO_PCI_QUEUE_NOTIFY;
 
        if (msix_vec != VIRTIO_MSI_NO_VECTOR) {
-               iowrite16(msix_vec, vp_dev->ioaddr + VIRTIO_MSI_QUEUE_VECTOR);
-               msix_vec = ioread16(vp_dev->ioaddr + VIRTIO_MSI_QUEUE_VECTOR);
+               msix_vec = vp_legacy_queue_vector(&vp_dev->ldev, index, msix_vec);
                if (msix_vec == VIRTIO_MSI_NO_VECTOR) {
                        err = -EBUSY;
                        goto out_deactivate;
@@ -167,7 +160,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
        return vq;
 
 out_deactivate:
-       iowrite32(0, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
+       vp_legacy_set_queue_address(&vp_dev->ldev, index, 0);
 out_del_vq:
        vring_del_virtqueue(vq);
        return ERR_PTR(err);
@@ -178,17 +171,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);
 
-       iowrite16(vq->index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
-
        if (vp_dev->msix_enabled) {
-               iowrite16(VIRTIO_MSI_NO_VECTOR,
-                         vp_dev->ioaddr + VIRTIO_MSI_QUEUE_VECTOR);
+               vp_legacy_queue_vector(&vp_dev->ldev, vq->index,
+                               VIRTIO_MSI_NO_VECTOR);
                /* Flush the write out to device */
-               ioread8(vp_dev->ioaddr + VIRTIO_PCI_ISR);
+               ioread8(vp_dev->ldev.ioaddr + VIRTIO_PCI_ISR);
        }
 
        /* Select and deactivate the queue */
-       iowrite32(0, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
+       vp_legacy_set_queue_address(&vp_dev->ldev, vq->index, 0);
 
        vring_del_virtqueue(vq);
 }
@@ -211,51 +202,18 @@ static const struct virtio_config_ops virtio_pci_config_ops = {
 /* the PCI probing function */
 int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)
 {
+       struct virtio_pci_legacy_device *ldev = &vp_dev->ldev;
        struct pci_dev *pci_dev = vp_dev->pci_dev;
        int rc;
 
-       /* We only own devices >= 0x1000 and <= 0x103f: leave the rest. */
-       if (pci_dev->device < 0x1000 || pci_dev->device > 0x103f)
-               return -ENODEV;
-
-       if (pci_dev->revision != VIRTIO_PCI_ABI_VERSION) {
-               printk(KERN_ERR "virtio_pci: expected ABI version %d, got %d\n",
-                      VIRTIO_PCI_ABI_VERSION, pci_dev->revision);
-               return -ENODEV;
-       }
-
-       rc = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(64));
-       if (rc) {
-               rc = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(32));
-       } else {
-               /*
-                * The virtio ring base address is expressed as a 32-bit PFN,
-                * with a page size of 1 << VIRTIO_PCI_QUEUE_ADDR_SHIFT.
-                */
-               dma_set_coherent_mask(&pci_dev->dev,
-                               DMA_BIT_MASK(32 + VIRTIO_PCI_QUEUE_ADDR_SHIFT));
-       }
-
-       if (rc)
-               dev_warn(&pci_dev->dev, "Failed to enable 64-bit or 32-bit DMA.  Trying to continue, but this might not work.\n");
+       ldev->pci_dev = pci_dev;
 
-       rc = pci_request_region(pci_dev, 0, "virtio-pci-legacy");
+       rc = vp_legacy_probe(ldev);
        if (rc)
                return rc;
 
-       rc = -ENOMEM;
-       vp_dev->ioaddr = pci_iomap(pci_dev, 0, 0);
-       if (!vp_dev->ioaddr)
-               goto err_iomap;
-
-       vp_dev->isr = vp_dev->ioaddr + VIRTIO_PCI_ISR;
-
-       /* we use the subsystem vendor/device id as the virtio vendor/device
-        * id.  this allows us to use the same PCI vendor/device id for all
-        * virtio devices and to identify the particular virtio driver by
-        * the subsystem ids */
-       vp_dev->vdev.id.vendor = pci_dev->subsystem_vendor;
-       vp_dev->vdev.id.device = pci_dev->subsystem_device;
+       vp_dev->isr = ldev->isr;
+       vp_dev->vdev.id = ldev->id;
 
        vp_dev->vdev.config = &virtio_pci_config_ops;
 
@@ -264,16 +222,11 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)
        vp_dev->del_vq = del_vq;
 
        return 0;
-
-err_iomap:
-       pci_release_region(pci_dev, 0);
-       return rc;
 }
 
 void virtio_pci_legacy_remove(struct virtio_pci_device *vp_dev)
 {
-       struct pci_dev *pci_dev = vp_dev->pci_dev;
+       struct virtio_pci_legacy_device *ldev = &vp_dev->ldev;
 
-       pci_iounmap(pci_dev, vp_dev->ioaddr);
-       pci_release_region(pci_dev, 0);
+       vp_legacy_remove(ldev);
 }
drivers/virtio/virtio_pci_legacy_dev.c new file +220 -0
new file mode 100644
index 000000000000..9b97680dd02b
@@ -0,0 +1,220 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "linux/virtio_pci.h"
+#include <linux/virtio_pci_legacy.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+
+
+/*
+ * vp_legacy_probe: probe the legacy virtio pci device, note that the
+ * caller is required to enable PCI device before calling this function.
+ * @ldev: the legacy virtio-pci device
+ *
+ * Return 0 on succeed otherwise fail
+ */
+int vp_legacy_probe(struct virtio_pci_legacy_device *ldev)
+{
+       struct pci_dev *pci_dev = ldev->pci_dev;
+       int rc;
+
+       /* We only own devices >= 0x1000 and <= 0x103f: leave the rest. */
+       if (pci_dev->device < 0x1000 || pci_dev->device > 0x103f)
+               return -ENODEV;
+
+       if (pci_dev->revision != VIRTIO_PCI_ABI_VERSION)
+               return -ENODEV;
+
+       rc = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(64));
+       if (rc) {
+               rc = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(32));
+       } else {
+               /*
+                * The virtio ring base address is expressed as a 32-bit PFN,
+                * with a page size of 1 << VIRTIO_PCI_QUEUE_ADDR_SHIFT.
+                */
+               dma_set_coherent_mask(&pci_dev->dev,
+                               DMA_BIT_MASK(32 + VIRTIO_PCI_QUEUE_ADDR_SHIFT));
+       }
+
+       if (rc)
+               dev_warn(&pci_dev->dev, "Failed to enable 64-bit or 32-bit DMA.  Trying to continue, but this might not work.\n");
+
+       rc = pci_request_region(pci_dev, 0, "virtio-pci-legacy");
+       if (rc)
+               return rc;
+
+       ldev->ioaddr = pci_iomap(pci_dev, 0, 0);
+       if (!ldev->ioaddr)
+               goto err_iomap;
+
+       ldev->isr = ldev->ioaddr + VIRTIO_PCI_ISR;
+
+       ldev->id.vendor = pci_dev->subsystem_vendor;
+       ldev->id.device = pci_dev->subsystem_device;
+
+       return 0;
+err_iomap:
+       pci_release_region(pci_dev, 0);
+       return rc;
+}
+EXPORT_SYMBOL_GPL(vp_legacy_probe);
+
+/*
+ * vp_legacy_probe: remove and cleanup the legacy virtio pci device
+ * @ldev: the legacy virtio-pci device
+ */
+void vp_legacy_remove(struct virtio_pci_legacy_device *ldev)
+{
+       struct pci_dev *pci_dev = ldev->pci_dev;
+
+       pci_iounmap(pci_dev, ldev->ioaddr);
+       pci_release_region(pci_dev, 0);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_remove);
+
+/*
+ * vp_legacy_get_features - get features from device
+ * @ldev: the legacy virtio-pci device
+ *
+ * Returns the features read from the device
+ */
+u64 vp_legacy_get_features(struct virtio_pci_legacy_device *ldev)
+{
+
+       return ioread32(ldev->ioaddr + VIRTIO_PCI_HOST_FEATURES);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_get_features);
+
+/*
+ * vp_legacy_get_driver_features - get driver features from device
+ * @ldev: the legacy virtio-pci device
+ *
+ * Returns the driver features read from the device
+ */
+u64 vp_legacy_get_driver_features(struct virtio_pci_legacy_device *ldev)
+{
+       return ioread32(ldev->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_get_driver_features);
+
+/*
+ * vp_legacy_set_features - set features to device
+ * @ldev: the legacy virtio-pci device
+ * @features: the features set to device
+ */
+void vp_legacy_set_features(struct virtio_pci_legacy_device *ldev,
+                           u32 features)
+{
+       iowrite32(features, ldev->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_set_features);
+
+/*
+ * vp_legacy_get_status - get the device status
+ * @ldev: the legacy virtio-pci device
+ *
+ * Returns the status read from device
+ */
+u8 vp_legacy_get_status(struct virtio_pci_legacy_device *ldev)
+{
+       return ioread8(ldev->ioaddr + VIRTIO_PCI_STATUS);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_get_status);
+
+/*
+ * vp_legacy_set_status - set status to device
+ * @ldev: the legacy virtio-pci device
+ * @status: the status set to device
+ */
+void vp_legacy_set_status(struct virtio_pci_legacy_device *ldev,
+                                u8 status)
+{
+       iowrite8(status, ldev->ioaddr + VIRTIO_PCI_STATUS);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_set_status);
+
+/*
+ * vp_legacy_queue_vector - set the MSIX vector for a specific virtqueue
+ * @ldev: the legacy virtio-pci device
+ * @index: queue index
+ * @vector: the config vector
+ *
+ * Returns the config vector read from the device
+ */
+u16 vp_legacy_queue_vector(struct virtio_pci_legacy_device *ldev,
+                          u16 index, u16 vector)
+{
+       iowrite16(index, ldev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
+       iowrite16(vector, ldev->ioaddr + VIRTIO_MSI_QUEUE_VECTOR);
+       /* Flush the write out to device */
+       return ioread16(ldev->ioaddr + VIRTIO_MSI_QUEUE_VECTOR);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_queue_vector);
+
+/*
+ * vp_legacy_config_vector - set the vector for config interrupt
+ * @ldev: the legacy virtio-pci device
+ * @vector: the config vector
+ *
+ * Returns the config vector read from the device
+ */
+u16 vp_legacy_config_vector(struct virtio_pci_legacy_device *ldev,
+                           u16 vector)
+{
+       /* Setup the vector used for configuration events */
+       iowrite16(vector, ldev->ioaddr + VIRTIO_MSI_CONFIG_VECTOR);
+       /* Verify we had enough resources to assign the vector */
+       /* Will also flush the write out to device */
+       return ioread16(ldev->ioaddr + VIRTIO_MSI_CONFIG_VECTOR);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_config_vector);
+
+/*
+ * vp_legacy_set_queue_address - set the virtqueue address
+ * @ldev: the legacy virtio-pci device
+ * @index: the queue index
+ * @queue_pfn: pfn of the virtqueue
+ */
+void vp_legacy_set_queue_address(struct virtio_pci_legacy_device *ldev,
+                            u16 index, u32 queue_pfn)
+{
+       iowrite16(index, ldev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
+       iowrite32(queue_pfn, ldev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_set_queue_address);
+
+/*
+ * vp_legacy_get_queue_enable - enable a virtqueue
+ * @ldev: the legacy virtio-pci device
+ * @index: the queue index
+ *
+ * Returns whether a virtqueue is enabled or not
+ */
+bool vp_legacy_get_queue_enable(struct virtio_pci_legacy_device *ldev,
+                               u16 index)
+{
+       iowrite16(index, ldev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
+       return ioread32(ldev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_get_queue_enable);
+
+/*
+ * vp_legacy_get_queue_size - get size for a virtqueue
+ * @ldev: the legacy virtio-pci device
+ * @index: the queue index
+ *
+ * Returns the size of the virtqueue
+ */
+u16 vp_legacy_get_queue_size(struct virtio_pci_legacy_device *ldev,
+                            u16 index)
+{
+       iowrite16(index, ldev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
+       return ioread16(ldev->ioaddr + VIRTIO_PCI_QUEUE_NUM);
+}
+EXPORT_SYMBOL_GPL(vp_legacy_get_queue_size);
+
+MODULE_VERSION("0.1");
+MODULE_DESCRIPTION("Legacy Virtio PCI Device");
+MODULE_AUTHOR("Wu Zongyong <[email protected]>");
+MODULE_LICENSE("GPL");
include/linux/virtio_pci_legacy.h new file +42 -1
new file mode 100644
index 000000000000..e5d665faf00e
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_VIRTIO_PCI_LEGACY_H
+#define _LINUX_VIRTIO_PCI_LEGACY_H
+
+#include "linux/mod_devicetable.h"
+#include <linux/pci.h>
+#include <linux/virtio_pci.h>
+
+struct virtio_pci_legacy_device {
+       struct pci_dev *pci_dev;
+
+       /* Where to read and clear interrupt */
+       u8 __iomem *isr;
+       /* The IO mapping for the PCI config space (legacy mode only) */
+       void __iomem *ioaddr;
+
+       struct virtio_device_id id;
+};
+
+u64 vp_legacy_get_features(struct virtio_pci_legacy_device *ldev);
+u64 vp_legacy_get_driver_features(struct virtio_pci_legacy_device *ldev);
+void vp_legacy_set_features(struct virtio_pci_legacy_device *ldev,
+                       u32 features);
+u8 vp_legacy_get_status(struct virtio_pci_legacy_device *ldev);
+void vp_legacy_set_status(struct virtio_pci_legacy_device *ldev,
+                       u8 status);
+u16 vp_legacy_queue_vector(struct virtio_pci_legacy_device *ldev,
+                          u16 idx, u16 vector);
+u16 vp_legacy_config_vector(struct virtio_pci_legacy_device *ldev,
+                    u16 vector);
+void vp_legacy_set_queue_address(struct virtio_pci_legacy_device *ldev,
+                            u16 index, u32 queue_pfn);
+bool vp_legacy_get_queue_enable(struct virtio_pci_legacy_device *ldev,
+                               u16 idx);
+void vp_legacy_set_queue_size(struct virtio_pci_legacy_device *ldev,
+                             u16 idx, u16 size);
+u16 vp_legacy_get_queue_size(struct virtio_pci_legacy_device *ldev,
+                            u16 idx);
+int vp_legacy_probe(struct virtio_pci_legacy_device *ldev);
+void vp_legacy_remove(struct virtio_pci_legacy_device *ldev);
+
+#endif
--

2.31.1

#115 lore raw

PATCH v6 2/8 vdpa: fix typo

In reply to Wu Zongyong
---
 include/linux/vdpa.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/vdpa.h +1 -1
index 3972ab765de1..a896ee021e5f 100644
@@ -257,7 +257,7 @@ struct vdpa_config_ops {
 	struct vdpa_notification_area
 	(*get_vq_notification)(struct vdpa_device *vdev, u16 idx);
 	/* vq irq is not expected to be changed once DRIVER_OK is set */
-	int (*get_vq_irq)(struct vdpa_device *vdv, u16 idx);
+	int (*get_vq_irq)(struct vdpa_device *vdev, u16 idx);
 
 	/* Device ops */
 	u32 (*get_vq_align)(struct vdpa_device *vdev);
Signature · 1 line
2.31.1
#116 lore raw

PATCH v6 3/8 vp_vdpa: add vq irq offloading support

In reply to Wu Zongyong

This patch implements the get_vq_irq() callback for virtio pci devices to allow irq offloading.

---
 drivers/vdpa/virtio_pci/vp_vdpa.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/vdpa/virtio_pci/vp_vdpa.c +12 -0
index 5bcd00246d2e..e3ff7875e123 100644
@@ -76,6 +76,17 @@ static u8 vp_vdpa_get_status(struct vdpa_device *vdpa)
 	return vp_modern_get_status(mdev);
 }
 
+static int vp_vdpa_get_vq_irq(struct vdpa_device *vdpa, u16 idx)
+{
+	struct vp_vdpa *vp_vdpa = vdpa_to_vp(vdpa);
+	int irq = vp_vdpa->vring[idx].irq;
+
+	if (irq == VIRTIO_MSI_NO_VECTOR)
+		return -EINVAL;
+
+	return irq;
+}
+
 static void vp_vdpa_free_irq(struct vp_vdpa *vp_vdpa)
 {
 	struct virtio_pci_modern_device *mdev = &vp_vdpa->mdev;
@@ -427,6 +438,7 @@ static const struct vdpa_config_ops vp_vdpa_ops = {
 	.get_config	= vp_vdpa_get_config,
 	.set_config	= vp_vdpa_set_config,
 	.set_config_cb  = vp_vdpa_set_config_cb,
+	.get_vq_irq	= vp_vdpa_get_vq_irq,
 };
 
 static void vp_vdpa_free_irq_vectors(void *data)
Signature · 1 line
2.31.1
#117 lore raw

PATCH v6 4/8 vdpa: add new callback get_vq_num_min in vdpa_config_ops

In reply to Wu Zongyong

This callback is optional. For vdpa devices that not support to change virtqueue size, get_vq_num_min and get_vq_num_max will return the same value, so that users can choose a correct value for that device.

---
 include/linux/vdpa.h | 4 ++++
 1 file changed, 4 insertions(+)
include/linux/vdpa.h +4 -0
index a896ee021e5f..30864848950b 100644
@@ -171,6 +171,9 @@ struct vdpa_map_file {
  * @get_vq_num_max:		Get the max size of virtqueue
  *				@vdev: vdpa device
  *				Returns u16: max size of virtqueue
+ * @get_vq_num_min:		Get the min size of virtqueue (optional)
+ *				@vdev: vdpa device
+ *				Returns u16: min size of virtqueue
  * @get_device_id:		Get virtio device id
  *				@vdev: vdpa device
  *				Returns u32: virtio device id
@@ -266,6 +269,7 @@ struct vdpa_config_ops {
 	void (*set_config_cb)(struct vdpa_device *vdev,
 			      struct vdpa_callback *cb);
 	u16 (*get_vq_num_max)(struct vdpa_device *vdev);
+	u16 (*get_vq_num_min)(struct vdpa_device *vdev);
 	u32 (*get_device_id)(struct vdpa_device *vdev);
 	u32 (*get_vendor_id)(struct vdpa_device *vdev);
 	u8 (*get_status)(struct vdpa_device *vdev);
Signature · 1 line
2.31.1
Acked-by on v6 4/8
#118 lore raw

Re: [PATCH v6 4/8] vdpa: add new callback get_vq_num_min in vdpa_config_ops

Quoted 7 lines · Wu Zongyong

This callback is optional. For vdpa devices that not support to change virtqueue size, get_vq_num_min and get_vq_num_max will return the same value, so that users can choose a correct value for that device.

Quoted 29 lines
---
 include/linux/vdpa.h | 4 ++++
 1 file changed, 4 insertions(+)
include/linux/vdpa.h +4 -1
index a896ee021e5f..30864848950b 100644
@@ -171,6 +171,9 @@ struct vdpa_map_file {
  * @get_vq_num_max:            Get the max size of virtqueue
  *                             @vdev: vdpa device
  *                             Returns u16: max size of virtqueue
+ * @get_vq_num_min:            Get the min size of virtqueue (optional)
+ *                             @vdev: vdpa device
+ *                             Returns u16: min size of virtqueue
  * @get_device_id:             Get virtio device id
  *                             @vdev: vdpa device
  *                             Returns u32: virtio device id
@@ -266,6 +269,7 @@ struct vdpa_config_ops {
        void (*set_config_cb)(struct vdpa_device *vdev,
                              struct vdpa_callback *cb);
        u16 (*get_vq_num_max)(struct vdpa_device *vdev);
+       u16 (*get_vq_num_min)(struct vdpa_device *vdev);
        u32 (*get_device_id)(struct vdpa_device *vdev);
        u32 (*get_vendor_id)(struct vdpa_device *vdev);
        u8 (*get_status)(struct vdpa_device *vdev);
--

2.31.1

#119 lore raw

PATCH v6 5/8 vdpa: min vq num of vdpa device cannot be greater than max vq num

In reply to Wu Zongyong

Just failed to probe the vdpa device if the min virtqueue num returned by get_vq_num_min is greater than the max virtqueue num returned by get_vq_num_max.

---
 drivers/vdpa/vdpa.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/vdpa/vdpa.c +8 -0
index 1dc121a07a93..fd014ecec711 100644
@@ -26,8 +26,16 @@ static int vdpa_dev_probe(struct device *d)
 {
 	struct vdpa_device *vdev = dev_to_vdpa(d);
 	struct vdpa_driver *drv = drv_to_vdpa(vdev->dev.driver);
+	const struct vdpa_config_ops *ops = vdev->config;
+	u32 max_num, min_num = 0;
 	int ret = 0;
 
+	max_num = ops->get_vq_num_max(vdev);
+	if (ops->get_vq_num_min)
+		min_num = ops->get_vq_num_min(vdev);
+	if (max_num < min_num)
+		return -EINVAL;
+
 	if (drv && drv->probe)
 		ret = drv->probe(vdev);
 
Signature · 1 line
2.31.1
Acked-by on v6 5/8
#120 lore raw

Re: [PATCH v6 5/8] vdpa: min vq num of vdpa device cannot be greater than max vq num

Quoted 6 lines · Wu Zongyong

Just failed to probe the vdpa device if the min virtqueue num returned by get_vq_num_min is greater than the max virtqueue num returned by get_vq_num_max.

Quoted 26 lines
---
 drivers/vdpa/vdpa.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/vdpa/vdpa.c +8 -1
index 1dc121a07a93..fd014ecec711 100644
@@ -26,8 +26,16 @@ static int vdpa_dev_probe(struct device *d)
 {
        struct vdpa_device *vdev = dev_to_vdpa(d);
        struct vdpa_driver *drv = drv_to_vdpa(vdev->dev.driver);
+       const struct vdpa_config_ops *ops = vdev->config;
+       u32 max_num, min_num = 0;
        int ret = 0;
 
+       max_num = ops->get_vq_num_max(vdev);
+       if (ops->get_vq_num_min)
+               min_num = ops->get_vq_num_min(vdev);
+       if (max_num < min_num)
+               return -EINVAL;
+
        if (drv && drv->probe)
                ret = drv->probe(vdev);
 
--
Quoted 2 lines

2.31.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#121 lore raw

PATCH v6 6/8 virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}

In reply to Wu Zongyong

For the devices which implement the get_vq_num_min callback, the driver should not negotiate with virtqueue size with the backend vdpa device if the value returned by get_vq_num_min equals to the value returned by get_vq_num_max.
This is useful for vdpa devices based on legacy virtio specfication.

---
 drivers/virtio/virtio_vdpa.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/virtio/virtio_vdpa.c +16 -5
index 72eaef2caeb1..e42ace29daa1 100644
@@ -145,7 +145,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 	/* Assume split virtqueue, switch to packed if necessary */
 	struct vdpa_vq_state state = {0};
 	unsigned long flags;
-	u32 align, num;
+	u32 align, max_num, min_num = 0;
+	bool may_reduce_num = true;
 	int err;
 
 	if (!name)
@@ -163,22 +164,32 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 	if (!info)
 		return ERR_PTR(-ENOMEM);
 
-	num = ops->get_vq_num_max(vdpa);
-	if (num == 0) {
+	max_num = ops->get_vq_num_max(vdpa);
+	if (max_num == 0) {
 		err = -ENOENT;
 		goto error_new_virtqueue;
 	}
 
+	if (ops->get_vq_num_min)
+		min_num = ops->get_vq_num_min(vdpa);
+
+	may_reduce_num = (max_num == min_num) ? false : true;
+
 	/* Create the vring */
 	align = ops->get_vq_align(vdpa);
-	vq = vring_create_virtqueue(index, num, align, vdev,
-				    true, true, ctx,
+	vq = vring_create_virtqueue(index, max_num, align, vdev,
+				    true, may_reduce_num, ctx,
 				    virtio_vdpa_notify, callback, name);
 	if (!vq) {
 		err = -ENOMEM;
 		goto error_new_virtqueue;
 	}
 
+	if (virtqueue_get_vring_size(vq) < min_num) {
+		err = -EINVAL;
+		goto err_vq;
+	}
+
 	/* Setup virtqueue callback */
 	cb.callback = virtio_vdpa_virtqueue_cb;
 	cb.private = info;
Signature · 1 line
2.31.1
#122 lore raw

Re: [PATCH v6 6/8] virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}

Quoted 49 lines · Wu Zongyong

For the devices which implement the get_vq_num_min callback, the driver should not negotiate with virtqueue size with the backend vdpa device if the value returned by get_vq_num_min equals to the value returned by get_vq_num_max.
This is useful for vdpa devices based on legacy virtio specfication.

---
 drivers/virtio/virtio_vdpa.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/virtio/virtio_vdpa.c +11 -5
index 72eaef2caeb1..e42ace29daa1 100644
@@ -145,7 +145,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
        /* Assume split virtqueue, switch to packed if necessary */
        struct vdpa_vq_state state = {0};
        unsigned long flags;
-       u32 align, num;
+       u32 align, max_num, min_num = 0;
+       bool may_reduce_num = true;
        int err;
 
        if (!name)
@@ -163,22 +164,32 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
        if (!info)
                return ERR_PTR(-ENOMEM);
 
-       num = ops->get_vq_num_max(vdpa);
-       if (num == 0) {
+       max_num = ops->get_vq_num_max(vdpa);
+       if (max_num == 0) {
                err = -ENOENT;
                goto error_new_virtqueue;
        }
 
+       if (ops->get_vq_num_min)
+               min_num = ops->get_vq_num_min(vdpa);
+
+       may_reduce_num = (max_num == min_num) ? false : true;
+
        /* Create the vring */
        align = ops->get_vq_align(vdpa);
-       vq = vring_create_virtqueue(index, num, align, vdev,
-                                   true, true, ctx,
+       vq = vring_create_virtqueue(index, max_num, align, vdev,
+                                   true, may_reduce_num, ctx,

drivers/virtio/virtio_vdpa.c virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, · line 191

Quoted 10 lines
drivers/virtio/virtio_vdpa.c +4 -0
                                    virtio_vdpa_notify, callback, name);
        if (!vq) {
                err = -ENOMEM;
                goto error_new_virtqueue;
        }
 
+       if (virtqueue_get_vring_size(vq) < min_num) {
+               err = -EINVAL;
+               goto err_vq;
+       }

I wonder under which case can we hit this?

Thanks

Quoted 7 lines
drivers/virtio/virtio_vdpa.c +1 -1
+
        /* Setup virtqueue callback */
        cb.callback = virtio_vdpa_virtqueue_cb;
        cb.private = info;
--

2.31.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

#124 lore raw

Re: [PATCH v6 6/8] virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}

Quoted 71 lines · Wu Zongyong
Quoted 56 lines · Jason Wang
Quoted 54 lines · Wu Zongyong

For the devices which implement the get_vq_num_min callback, the driver should not negotiate with virtqueue size with the backend vdpa device if the value returned by get_vq_num_min equals to the value returned by get_vq_num_max.
This is useful for vdpa devices based on legacy virtio specfication.

---
  drivers/virtio/virtio_vdpa.c | 21 ++++++++++++++++-----
  1 file changed, 16 insertions(+), 5 deletions(-)
drivers/virtio/virtio_vdpa.c +11 -5
index 72eaef2caeb1..e42ace29daa1 100644
@@ -145,7 +145,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
         /* Assume split virtqueue, switch to packed if necessary */
         struct vdpa_vq_state state = {0};
         unsigned long flags;
-       u32 align, num;
+       u32 align, max_num, min_num = 0;
+       bool may_reduce_num = true;
         int err;
 
         if (!name)
@@ -163,22 +164,32 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
         if (!info)
                 return ERR_PTR(-ENOMEM);
 
-       num = ops->get_vq_num_max(vdpa);
-       if (num == 0) {
+       max_num = ops->get_vq_num_max(vdpa);
+       if (max_num == 0) {
                 err = -ENOENT;
                 goto error_new_virtqueue;
         }
 
+       if (ops->get_vq_num_min)
+               min_num = ops->get_vq_num_min(vdpa);
+
+       may_reduce_num = (max_num == min_num) ? false : true;
+
         /* Create the vring */
         align = ops->get_vq_align(vdpa);
-       vq = vring_create_virtqueue(index, num, align, vdev,
-                                   true, true, ctx,
+       vq = vring_create_virtqueue(index, max_num, align, vdev,
+                                   true, may_reduce_num, ctx,
                                     virtio_vdpa_notify, callback, name);
         if (!vq) {
                 err = -ENOMEM;
                 goto error_new_virtqueue;
         }
 
Quoted 7 lines

drivers/virtio/virtio_vdpa.c virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, · line 191

Quoted 4 lines
drivers/virtio/virtio_vdpa.c +4 -0
+       if (virtqueue_get_vring_size(vq) < min_num) {
+               err = -EINVAL;
+               goto err_vq;
+       }

I wonder under which case can we hit this?

Thanks

If min_vq_num < max_vq_num, may_reduce_num should be true, then it is possible to allocate a virtqueue with a small size which value is less than the min_vq_num since we only set the upper bound for virtqueue size when creating virtqueue.

Refers to vring_create_virtqueue_split in driver/virtio/virtio_vring.c:

Quoted 9 lines
	for (; num && vring_size(num, vring_align) > PAGE_SIZE; num /= 2) {
		queue = vring_alloc_queue(vdev, vring_size(num, vring_align),
					  &dma_addr,
					  GFP_KERNEL|__GFP_NOWARN|__GFP_ZERO);
		if (queue)
			break;
		if (!may_reduce_num)
			return NULL;
	}

It looks to me it's better to fix this function instead of checking it in the caller?

Quoted 2 lines

BTW, I have replied this mail on Nov.18, have you ever received it?

For some reason I dont' get that.

Thanks

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/virtio/virtio_vdpa.c +1 -1
+
         /* Setup virtqueue callback */
         cb.callback = virtio_vdpa_virtqueue_cb;
         cb.private = info;
--

2.31.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

#126 lore raw

Re: [PATCH v6 6/8] virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}

Quoted 86 lines · Wu Zongyong
Quoted 84 lines · Jason Wang
Quoted 80 lines · Wu Zongyong
Quoted 56 lines · Jason Wang
Quoted 54 lines · Wu Zongyong

For the devices which implement the get_vq_num_min callback, the driver should not negotiate with virtqueue size with the backend vdpa device if the value returned by get_vq_num_min equals to the value returned by get_vq_num_max.
This is useful for vdpa devices based on legacy virtio specfication.

---
  drivers/virtio/virtio_vdpa.c | 21 ++++++++++++++++-----
  1 file changed, 16 insertions(+), 5 deletions(-)
drivers/virtio/virtio_vdpa.c +11 -5
index 72eaef2caeb1..e42ace29daa1 100644
@@ -145,7 +145,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
         /* Assume split virtqueue, switch to packed if necessary */
         struct vdpa_vq_state state = {0};
         unsigned long flags;
-       u32 align, num;
+       u32 align, max_num, min_num = 0;
+       bool may_reduce_num = true;
         int err;
 
         if (!name)
@@ -163,22 +164,32 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
         if (!info)
                 return ERR_PTR(-ENOMEM);
 
-       num = ops->get_vq_num_max(vdpa);
-       if (num == 0) {
+       max_num = ops->get_vq_num_max(vdpa);
+       if (max_num == 0) {
                 err = -ENOENT;
                 goto error_new_virtqueue;
         }
 
+       if (ops->get_vq_num_min)
+               min_num = ops->get_vq_num_min(vdpa);
+
+       may_reduce_num = (max_num == min_num) ? false : true;
+
         /* Create the vring */
         align = ops->get_vq_align(vdpa);
-       vq = vring_create_virtqueue(index, num, align, vdev,
-                                   true, true, ctx,
+       vq = vring_create_virtqueue(index, max_num, align, vdev,
+                                   true, may_reduce_num, ctx,
                                     virtio_vdpa_notify, callback, name);
         if (!vq) {
                 err = -ENOMEM;
                 goto error_new_virtqueue;
         }
 
Quoted 7 lines

drivers/virtio/virtio_vdpa.c virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, · line 191

Quoted 4 lines
drivers/virtio/virtio_vdpa.c +4 -0
+       if (virtqueue_get_vring_size(vq) < min_num) {
+               err = -EINVAL;
+               goto err_vq;
+       }

I wonder under which case can we hit this?

Thanks

If min_vq_num < max_vq_num, may_reduce_num should be true, then it is possible to allocate a virtqueue with a small size which value is less than the min_vq_num since we only set the upper bound for virtqueue size when creating virtqueue.

Refers to vring_create_virtqueue_split in driver/virtio/virtio_vring.c:

    for (; num && vring_size(num, vring_align) > PAGE_SIZE; num /= 2) {
            queue = vring_alloc_queue(vdev, vring_size(num, vring_align),
                                      &dma_addr,
                                      GFP_KERNEL|__GFP_NOWARN|__GFP_ZERO);
            if (queue)
                    break;
            if (!may_reduce_num)
                    return NULL;
    }
Quoted 5 lines
Quoted 2 lines

It looks to me it's better to fix this function instead of checking it in the caller?

Or we can simply remove that code since this case only exists in theory, and there is no real usecase for now.

(Adding list back)

Somehow, it can't happen if you stick to a 256 as both min and max.

Another question, can ENI support vring size which is less than 256?

Thanks

Quoted 20 lines
Quoted 19 lines
Quoted 5 lines

BTW, I have replied this mail on Nov.18, have you ever received it?

For some reason I dont' get that.

Thanks

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/virtio/virtio_vdpa.c +1 -1
+
         /* Setup virtqueue callback */
         cb.callback = virtio_vdpa_virtqueue_cb;
         cb.private = info;
--

2.31.1

#127 lore raw

PATCH v6 7/8 vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE

In reply to Wu Zongyong

This attribute advertises the min value of virtqueue size. The value is 0 by default.

---
 drivers/vdpa/vdpa.c       | 5 +++++
 include/uapi/linux/vdpa.h | 1 +
 2 files changed, 6 insertions(+)
drivers/vdpa/vdpa.c +5 -0
index fd014ecec711..4aeb1458b924 100644
@@ -500,6 +500,7 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
 	      int flags, struct netlink_ext_ack *extack)
 {
 	u16 max_vq_size;
+	u16 min_vq_size = 0;
 	u32 device_id;
 	u32 vendor_id;
 	void *hdr;
@@ -516,6 +517,8 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
 	device_id = vdev->config->get_device_id(vdev);
 	vendor_id = vdev->config->get_vendor_id(vdev);
 	max_vq_size = vdev->config->get_vq_num_max(vdev);
+	if (vdev->config->get_vq_num_min)
+		min_vq_size = vdev->config->get_vq_num_min(vdev);
 
 	err = -EMSGSIZE;
 	if (nla_put_string(msg, VDPA_ATTR_DEV_NAME, dev_name(&vdev->dev)))
@@ -528,6 +531,8 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
 		goto msg_err;
 	if (nla_put_u16(msg, VDPA_ATTR_DEV_MAX_VQ_SIZE, max_vq_size))
 		goto msg_err;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_MIN_VQ_SIZE, min_vq_size))
+		goto msg_err;
 
 	genlmsg_end(msg, hdr);
 	return 0;
include/uapi/linux/vdpa.h +1 -0
index 66a41e4ec163..e3b87879514c 100644
@@ -32,6 +32,7 @@ enum vdpa_attr {
 	VDPA_ATTR_DEV_VENDOR_ID,		/* u32 */
 	VDPA_ATTR_DEV_MAX_VQS,			/* u32 */
 	VDPA_ATTR_DEV_MAX_VQ_SIZE,		/* u16 */
+	VDPA_ATTR_DEV_MIN_VQ_SIZE,		/* u16 */
 
 	/* new attributes must be added above here */
 	VDPA_ATTR_MAX,
Signature · 1 line
2.31.1
#128 lore raw

Re: [PATCH v6 7/8] vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE

Quoted 3 lines · Wu Zongyong

This attribute advertises the min value of virtqueue size. The value is 0 by default.

As discussed previously, 0 seems an invalid value. We should use 1 at least.

Thanks

Quoted 52 lines
---
 drivers/vdpa/vdpa.c       | 5 +++++
 include/uapi/linux/vdpa.h | 1 +
 2 files changed, 6 insertions(+)
drivers/vdpa/vdpa.c +5 -0
index fd014ecec711..4aeb1458b924 100644
@@ -500,6 +500,7 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
              int flags, struct netlink_ext_ack *extack)
 {
        u16 max_vq_size;
+       u16 min_vq_size = 0;
        u32 device_id;
        u32 vendor_id;
        void *hdr;
@@ -516,6 +517,8 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
        device_id = vdev->config->get_device_id(vdev);
        vendor_id = vdev->config->get_vendor_id(vdev);
        max_vq_size = vdev->config->get_vq_num_max(vdev);
+       if (vdev->config->get_vq_num_min)
+               min_vq_size = vdev->config->get_vq_num_min(vdev);
 
        err = -EMSGSIZE;
        if (nla_put_string(msg, VDPA_ATTR_DEV_NAME, dev_name(&vdev->dev)))
@@ -528,6 +531,8 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
                goto msg_err;
        if (nla_put_u16(msg, VDPA_ATTR_DEV_MAX_VQ_SIZE, max_vq_size))
                goto msg_err;
+       if (nla_put_u16(msg, VDPA_ATTR_DEV_MIN_VQ_SIZE, min_vq_size))
+               goto msg_err;
 
        genlmsg_end(msg, hdr);
        return 0;
include/uapi/linux/vdpa.h +1 -1
index 66a41e4ec163..e3b87879514c 100644
@@ -32,6 +32,7 @@ enum vdpa_attr {
        VDPA_ATTR_DEV_VENDOR_ID,                /* u32 */
        VDPA_ATTR_DEV_MAX_VQS,                  /* u32 */
        VDPA_ATTR_DEV_MAX_VQ_SIZE,              /* u16 */
+       VDPA_ATTR_DEV_MIN_VQ_SIZE,              /* u16 */
 
        /* new attributes must be added above here */
        VDPA_ATTR_MAX,
--

2.31.1

#129 lore raw

PATCH v6 8/8 eni_vdpa: add vDPA driver for Alibaba ENI

In reply to Wu Zongyong

This patch adds a new vDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon virtio 0.9.5 specification. And this driver doesn't support to run on BE host.

---
 drivers/vdpa/Kconfig            |   8 +
 drivers/vdpa/Makefile           |   1 +
 drivers/vdpa/alibaba/Makefile   |   3 +
 drivers/vdpa/alibaba/eni_vdpa.c | 553 ++++++++++++++++++++++++++++++++
 4 files changed, 565 insertions(+)
 create mode 100644 drivers/vdpa/alibaba/Makefile
 create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
drivers/vdpa/Kconfig +8 -0
index 3d91982d8371..c0232a2148a7 100644
@@ -78,4 +78,12 @@ config VP_VDPA
 	help
 	  This kernel module bridges virtio PCI device to vDPA bus.
 
+config ALIBABA_ENI_VDPA
+	tristate "vDPA driver for Alibaba ENI"
+	select VIRTIO_PCI_LEGACY_LIB
+	depends on PCI_MSI && !CPU_BIG_ENDIAN
+	help
+	  VDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon
+	  virtio 0.9.5 specification.
+
 endif # VDPA
drivers/vdpa/Makefile +1 -0
index f02ebed33f19..15665563a7f4 100644
@@ -5,3 +5,4 @@ obj-$(CONFIG_VDPA_USER) += vdpa_user/
 obj-$(CONFIG_IFCVF)    += ifcvf/
 obj-$(CONFIG_MLX5_VDPA) += mlx5/
 obj-$(CONFIG_VP_VDPA)    += virtio_pci/
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += alibaba/
drivers/vdpa/alibaba/Makefile new file +3 -0
new file mode 100644
index 000000000000..ef4aae69f87a
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += eni_vdpa.o
+
drivers/vdpa/alibaba/eni_vdpa.c new file +553 -0

553 lines not on this page · raw message

Signature · 1 line
2.31.1
#130 lore raw

Re: [PATCH v6 8/8] eni_vdpa: add vDPA driver for Alibaba ENI

Quoted 132 lines · Wu Zongyong

This patch adds a new vDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon virtio 0.9.5 specification. And this driver doesn't support to run on BE host.

---
 drivers/vdpa/Kconfig            |   8 +
 drivers/vdpa/Makefile           |   1 +
 drivers/vdpa/alibaba/Makefile   |   3 +
 drivers/vdpa/alibaba/eni_vdpa.c | 553 ++++++++++++++++++++++++++++++++
 4 files changed, 565 insertions(+)
 create mode 100644 drivers/vdpa/alibaba/Makefile
 create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
drivers/vdpa/Kconfig +8 -0
index 3d91982d8371..c0232a2148a7 100644
@@ -78,4 +78,12 @@ config VP_VDPA
        help
          This kernel module bridges virtio PCI device to vDPA bus.
 
+config ALIBABA_ENI_VDPA
+       tristate "vDPA driver for Alibaba ENI"
+       select VIRTIO_PCI_LEGACY_LIB
+       depends on PCI_MSI && !CPU_BIG_ENDIAN
+       help
+         VDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon
+         virtio 0.9.5 specification.
+
 endif # VDPA
drivers/vdpa/Makefile +1 -0
index f02ebed33f19..15665563a7f4 100644
@@ -5,3 +5,4 @@ obj-$(CONFIG_VDPA_USER) += vdpa_user/
 obj-$(CONFIG_IFCVF)    += ifcvf/
 obj-$(CONFIG_MLX5_VDPA) += mlx5/
 obj-$(CONFIG_VP_VDPA)    += virtio_pci/
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += alibaba/
drivers/vdpa/alibaba/Makefile new file +3 -0
new file mode 100644
index 000000000000..ef4aae69f87a
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += eni_vdpa.o
+
drivers/vdpa/alibaba/eni_vdpa.c new file +76 -0
new file mode 100644
index 000000000000..6a09f157d810
@@ -0,0 +1,553 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * vDPA bridge driver for Alibaba ENI(Elastic Network Interface)
+ *
+ * Copyright (c) 2021, Alibaba Inc. All rights reserved.
+ * Author: Wu Zongyong <[email protected]>
+ *
+ */
+
+#include "linux/bits.h"
+#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>
+#include <linux/virtio_ring.h>
+#include <linux/virtio_pci.h>
+#include <linux/virtio_pci_legacy.h>
+#include <uapi/linux/virtio_net.h>
+
+#define ENI_MSIX_NAME_SIZE 256
+
+#define ENI_ERR(pdev, fmt, ...)        \
+       dev_err(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+#define ENI_DBG(pdev, fmt, ...)        \
+       dev_dbg(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+#define ENI_INFO(pdev, fmt, ...) \
+       dev_info(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+
+struct eni_vring {
+       void __iomem *notify;
+       char msix_name[ENI_MSIX_NAME_SIZE];
+       struct vdpa_callback cb;
+       int irq;
+};
+
+struct eni_vdpa {
+       struct vdpa_device vdpa;
+       struct virtio_pci_legacy_device ldev;
+       struct eni_vring *vring;
+       struct vdpa_callback config_cb;
+       char msix_name[ENI_MSIX_NAME_SIZE];
+       int config_irq;
+       int queues;
+       int vectors;
+};
+
+static struct eni_vdpa *vdpa_to_eni(struct vdpa_device *vdpa)
+{
+       return container_of(vdpa, struct eni_vdpa, vdpa);
+}
+
+static struct virtio_pci_legacy_device *vdpa_to_ldev(struct vdpa_device *vdpa)
+{
+       struct eni_vdpa *eni_vdpa = vdpa_to_eni(vdpa);
+
+       return &eni_vdpa->ldev;
+}
+
+static u64 eni_vdpa_get_features(struct vdpa_device *vdpa)
+{
+       struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+       u64 features = vp_legacy_get_features(ldev);
+
+       features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM);
+       features |= BIT_ULL(VIRTIO_F_ORDER_PLATFORM);
+
+       return features;
+}
+
+static int eni_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
+{
+       struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+       if (!(features & BIT_ULL(VIRTIO_NET_F_MRG_RXBUF)) && features) {

drivers/vdpa/alibaba/eni_vdpa.c line 86

Quoted 10 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +10 -0
+               ENI_ERR(ldev->pci_dev,
+                       "VIRTIO_NET_F_MRG_RXBUF is not negotiated\n");
+               return -EINVAL;
+       }
+
+       vp_legacy_set_features(ldev, (u32)features);
+
+       return 0;
+}
+

So my comments have not been addressed since v4. Please address or answer the questions before posting a new version.

Thanks

drivers/vdpa/alibaba/eni_vdpa.c line 67

Quoted 7 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +7 -0
+static u64 eni_vdpa_get_features(struct vdpa_device *vdpa)
+{
+     struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+     u64 features = vp_legacy_get_features(ldev);
+
+     features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM);
+     features |= BIT_ULL(VIRTIO_F_ORDER_PLATFORM);

VERSION_1 is also needed?

drivers/vdpa/alibaba/eni_vdpa.c line 79

Quoted 12 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +12 -0
+
+     return features;
+}
+
+static int eni_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
+{
+     struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+     if (!(features & BIT_ULL(VIRTIO_NET_F_MRG_RXBUF)) && features) {
+             ENI_ERR(ldev->pci_dev,
+                     "VIRTIO_NET_F_MRG_RXBUF is not negotiated\n");
+             return -EINVAL;

Do we need to make sure FEATURE_OK is not set in this case or the ENI can do this for us?

Other looks good.

Thanks

A message that is not in the archive (sent off-list or not yet received): [email protected]

#132 lore raw

Re: [PATCH v6 8/8] eni_vdpa: add vDPA driver for Alibaba ENI

Quoted 160 lines · Wu Zongyong
Quoted 146 lines · Jason Wang
Quoted 131 lines · Wu Zongyong

This patch adds a new vDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon virtio 0.9.5 specification. And this driver doesn't support to run on BE host.

---
  drivers/vdpa/Kconfig            |   8 +
  drivers/vdpa/Makefile           |   1 +
  drivers/vdpa/alibaba/Makefile   |   3 +
  drivers/vdpa/alibaba/eni_vdpa.c | 553 ++++++++++++++++++++++++++++++++
  4 files changed, 565 insertions(+)

create mode 100644 drivers/vdpa/alibaba/Makefile create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c

drivers/vdpa/Kconfig +8 -0
index 3d91982d8371..c0232a2148a7 100644
@@ -78,4 +78,12 @@ config VP_VDPA
         help
           This kernel module bridges virtio PCI device to vDPA bus.
 
+config ALIBABA_ENI_VDPA
+       tristate "vDPA driver for Alibaba ENI"
+       select VIRTIO_PCI_LEGACY_LIB
+       depends on PCI_MSI && !CPU_BIG_ENDIAN
+       help
+         VDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon
+         virtio 0.9.5 specification.
+
  endif # VDPA
drivers/vdpa/Makefile +1 -0
index f02ebed33f19..15665563a7f4 100644
@@ -5,3 +5,4 @@ obj-$(CONFIG_VDPA_USER) += vdpa_user/
  obj-$(CONFIG_IFCVF)    += ifcvf/
  obj-$(CONFIG_MLX5_VDPA) += mlx5/
  obj-$(CONFIG_VP_VDPA)    += virtio_pci/
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += alibaba/
drivers/vdpa/alibaba/Makefile new file +3 -0
new file mode 100644
index 000000000000..ef4aae69f87a
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += eni_vdpa.o
+
drivers/vdpa/alibaba/eni_vdpa.c new file +76 -0
new file mode 100644
index 000000000000..6a09f157d810
@@ -0,0 +1,553 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * vDPA bridge driver for Alibaba ENI(Elastic Network Interface)
+ *
+ * Copyright (c) 2021, Alibaba Inc. All rights reserved.
+ * Author: Wu Zongyong <[email protected]>
+ *
+ */
+
+#include "linux/bits.h"
+#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>
+#include <linux/virtio_ring.h>
+#include <linux/virtio_pci.h>
+#include <linux/virtio_pci_legacy.h>
+#include <uapi/linux/virtio_net.h>
+
+#define ENI_MSIX_NAME_SIZE 256
+
+#define ENI_ERR(pdev, fmt, ...)        \
+       dev_err(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+#define ENI_DBG(pdev, fmt, ...)        \
+       dev_dbg(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+#define ENI_INFO(pdev, fmt, ...) \
+       dev_info(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+
+struct eni_vring {
+       void __iomem *notify;
+       char msix_name[ENI_MSIX_NAME_SIZE];
+       struct vdpa_callback cb;
+       int irq;
+};
+
+struct eni_vdpa {
+       struct vdpa_device vdpa;
+       struct virtio_pci_legacy_device ldev;
+       struct eni_vring *vring;
+       struct vdpa_callback config_cb;
+       char msix_name[ENI_MSIX_NAME_SIZE];
+       int config_irq;
+       int queues;
+       int vectors;
+};
+
+static struct eni_vdpa *vdpa_to_eni(struct vdpa_device *vdpa)
+{
+       return container_of(vdpa, struct eni_vdpa, vdpa);
+}
+
+static struct virtio_pci_legacy_device *vdpa_to_ldev(struct vdpa_device *vdpa)
+{
+       struct eni_vdpa *eni_vdpa = vdpa_to_eni(vdpa);
+
+       return &eni_vdpa->ldev;
+}
+
+static u64 eni_vdpa_get_features(struct vdpa_device *vdpa)
+{
+       struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+       u64 features = vp_legacy_get_features(ldev);
+
+       features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM);
+       features |= BIT_ULL(VIRTIO_F_ORDER_PLATFORM);
+
+       return features;
+}
+
+static int eni_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
+{
+       struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+       if (!(features & BIT_ULL(VIRTIO_NET_F_MRG_RXBUF)) && features) {

drivers/vdpa/alibaba/eni_vdpa.c line 86

Quoted 10 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +10 -0
+               ENI_ERR(ldev->pci_dev,
+                       "VIRTIO_NET_F_MRG_RXBUF is not negotiated\n");
+               return -EINVAL;
+       }
+
+       vp_legacy_set_features(ldev, (u32)features);
+
+       return 0;
+}
+

So my comments have not been addressed since v4. Please address or answer the questions before posting a new version.

Quoted 1 line

Thanks

Sorry, I forgot to reply the comments on this patch.

Quoted 9 lines

drivers/vdpa/alibaba/eni_vdpa.c line 67

Quoted 7 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +7 -0
+static u64 eni_vdpa_get_features(struct vdpa_device *vdpa)
+{
+     struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+     u64 features = vp_legacy_get_features(ldev);
+
+     features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM);
+     features |= BIT_ULL(VIRTIO_F_ORDER_PLATFORM);

VERSION_1 is also needed?

Quoted 1 line

No, queue align of legacy devices should be 4096,

Let's use VIRTIO_PCI_VRING_ALIGN instead of PAGE_SIZE in get_vq_align then since PAGE_SIZE is not necessarily 4096.

Quoted 4 lines

but queue align of
devices with VERSION_1 are SMP_CACHE_BYTES which may not equals to 4096.
If we set the VERSION_1, ENI will not work due to the queue align.

Interesting, so I think it can only be used with legacy virtio drivers in the guest.

One major drawbacks is that guest can only see 32 feature bits which means we can't advertise VIRTIO_F_ACCESS_PLATFORM and VIRTIO_F_ORDER_PLATFORM to guest:

/* virtio config->get_features() implementation */ static u64 vp_get_features(struct virtio_device *vdev) {
        struct virtio_pci_device *vp_dev = to_vp_device(vdev);

        /* When someone needs more than 32 feature bits, we'll need to
         * steal a bit to indicate that the rest are somewhere else. */ return ioread32(vp_dev->ioaddr + VIRTIO_PCI_HOST_FEATURES); }

For VIRTIO_F_ACCESS_PLATFORM, it should be fine. But how about VIRTIO_F_ORDER_PLATFORM?

Quoted 15 lines
Quoted 15 lines

drivers/vdpa/alibaba/eni_vdpa.c line 79

Quoted 13 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +12 -0
+
+     return features;
+}
+
+static int eni_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
+{
+     struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+     if (!(features & BIT_ULL(VIRTIO_NET_F_MRG_RXBUF)) && features) {
+             ENI_ERR(ldev->pci_dev,
+                     "VIRTIO_NET_F_MRG_RXBUF is not negotiated\n");
+             return -EINVAL;

Do we need to make sure FEATURE_OK is not set in this case or the ENI can do this for us?

Quoted 1 line

Why we need to check this? I don't get what you worried about.

I thought the plan is to advertise the VERSION_1, so failing when without mrg_rxbuf is a must. But looks like I was wrong, and there's no need to mandate mrg_rxbuf in future versions.

Thanks

Quoted 4 lines
Quoted 4 lines

Other looks good.

Thanks

#133 lore raw

Re: [PATCH v6 8/8] eni_vdpa: add vDPA driver for Alibaba ENI

Quoted 162 lines · Jason Wang
Quoted 160 lines · Wu Zongyong
Quoted 146 lines · Jason Wang
Quoted 131 lines · Wu Zongyong

This patch adds a new vDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon virtio 0.9.5 specification. And this driver doesn't support to run on BE host.

---
  drivers/vdpa/Kconfig            |   8 +
  drivers/vdpa/Makefile           |   1 +
  drivers/vdpa/alibaba/Makefile   |   3 +
  drivers/vdpa/alibaba/eni_vdpa.c | 553 ++++++++++++++++++++++++++++++++
  4 files changed, 565 insertions(+)

create mode 100644 drivers/vdpa/alibaba/Makefile create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c

drivers/vdpa/Kconfig +8 -0
index 3d91982d8371..c0232a2148a7 100644
@@ -78,4 +78,12 @@ config VP_VDPA
         help
           This kernel module bridges virtio PCI device to vDPA bus.
 
+config ALIBABA_ENI_VDPA
+       tristate "vDPA driver for Alibaba ENI"
+       select VIRTIO_PCI_LEGACY_LIB
+       depends on PCI_MSI && !CPU_BIG_ENDIAN
+       help
+         VDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon
+         virtio 0.9.5 specification.
+
  endif # VDPA
drivers/vdpa/Makefile +1 -0
index f02ebed33f19..15665563a7f4 100644
@@ -5,3 +5,4 @@ obj-$(CONFIG_VDPA_USER) += vdpa_user/
  obj-$(CONFIG_IFCVF)    += ifcvf/
  obj-$(CONFIG_MLX5_VDPA) += mlx5/
  obj-$(CONFIG_VP_VDPA)    += virtio_pci/
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += alibaba/
drivers/vdpa/alibaba/Makefile new file +3 -0
new file mode 100644
index 000000000000..ef4aae69f87a
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += eni_vdpa.o
+
drivers/vdpa/alibaba/eni_vdpa.c new file +76 -0
new file mode 100644
index 000000000000..6a09f157d810
@@ -0,0 +1,553 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * vDPA bridge driver for Alibaba ENI(Elastic Network Interface)
+ *
+ * Copyright (c) 2021, Alibaba Inc. All rights reserved.
+ * Author: Wu Zongyong <[email protected]>
+ *
+ */
+
+#include "linux/bits.h"
+#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>
+#include <linux/virtio_ring.h>
+#include <linux/virtio_pci.h>
+#include <linux/virtio_pci_legacy.h>
+#include <uapi/linux/virtio_net.h>
+
+#define ENI_MSIX_NAME_SIZE 256
+
+#define ENI_ERR(pdev, fmt, ...)        \
+       dev_err(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+#define ENI_DBG(pdev, fmt, ...)        \
+       dev_dbg(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+#define ENI_INFO(pdev, fmt, ...) \
+       dev_info(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+
+struct eni_vring {
+       void __iomem *notify;
+       char msix_name[ENI_MSIX_NAME_SIZE];
+       struct vdpa_callback cb;
+       int irq;
+};
+
+struct eni_vdpa {
+       struct vdpa_device vdpa;
+       struct virtio_pci_legacy_device ldev;
+       struct eni_vring *vring;
+       struct vdpa_callback config_cb;
+       char msix_name[ENI_MSIX_NAME_SIZE];
+       int config_irq;
+       int queues;
+       int vectors;
+};
+
+static struct eni_vdpa *vdpa_to_eni(struct vdpa_device *vdpa)
+{
+       return container_of(vdpa, struct eni_vdpa, vdpa);
+}
+
+static struct virtio_pci_legacy_device *vdpa_to_ldev(struct vdpa_device *vdpa)
+{
+       struct eni_vdpa *eni_vdpa = vdpa_to_eni(vdpa);
+
+       return &eni_vdpa->ldev;
+}
+
+static u64 eni_vdpa_get_features(struct vdpa_device *vdpa)
+{
+       struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+       u64 features = vp_legacy_get_features(ldev);
+
+       features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM);
+       features |= BIT_ULL(VIRTIO_F_ORDER_PLATFORM);
+
+       return features;
+}
+
+static int eni_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
+{
+       struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+       if (!(features & BIT_ULL(VIRTIO_NET_F_MRG_RXBUF)) && features) {

drivers/vdpa/alibaba/eni_vdpa.c line 86

Quoted 10 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +10 -0
+               ENI_ERR(ldev->pci_dev,
+                       "VIRTIO_NET_F_MRG_RXBUF is not negotiated\n");
+               return -EINVAL;
+       }
+
+       vp_legacy_set_features(ldev, (u32)features);
+
+       return 0;
+}
+

So my comments have not been addressed since v4. Please address or answer the questions before posting a new version.

Quoted 1 line

Thanks

Sorry, I forgot to reply the comments on this patch.

Quoted 9 lines

drivers/vdpa/alibaba/eni_vdpa.c line 67

Quoted 7 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +7 -0
+static u64 eni_vdpa_get_features(struct vdpa_device *vdpa)
+{
+     struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+     u64 features = vp_legacy_get_features(ldev);
+
+     features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM);
+     features |= BIT_ULL(VIRTIO_F_ORDER_PLATFORM);

VERSION_1 is also needed?

Quoted 5 lines
Quoted 1 line

No, queue align of legacy devices should be 4096,

Let's use VIRTIO_PCI_VRING_ALIGN instead of PAGE_SIZE in get_vq_align then since PAGE_SIZE is not necessarily 4096.

I will fix it.

Quoted 10 lines
Quoted 6 lines

but queue align of
devices with VERSION_1 are SMP_CACHE_BYTES which may not equals to 4096.
If we set the VERSION_1, ENI will not work due to the queue align.

Interesting, so I think it can only be used with legacy virtio drivers in the guest.

Yes, ENI can only work well with legacy virtio drivers in the guest from my test.

Quoted 10 lines

One major drawbacks is that guest can only see 32 feature bits which means we can't advertise VIRTIO_F_ACCESS_PLATFORM and VIRTIO_F_ORDER_PLATFORM to guest:

/* virtio config->get_features() implementation */ static u64 vp_get_features(struct virtio_device *vdev) {
        struct virtio_pci_device *vp_dev = to_vp_device(vdev);

Quoted 8 lines

        /* When someone needs more than 32 feature bits, we'll need to
         * steal a bit to indicate that the rest are somewhere else. */ return ioread32(vp_dev->ioaddr + VIRTIO_PCI_HOST_FEATURES); }

For VIRTIO_F_ACCESS_PLATFORM, it should be fine. But how about VIRTIO_F_ORDER_PLATFORM?

Is it necessary to advertise these two bits?
ENI works well without these two bits regardless of baremetal or virtual machine.

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 4 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +2 -0
+
+     return features;

drivers/vdpa/alibaba/eni_vdpa.c line 79

Quoted 10 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +10 -0
+}
+
+static int eni_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
+{
+     struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+     if (!(features & BIT_ULL(VIRTIO_NET_F_MRG_RXBUF)) && features) {
+             ENI_ERR(ldev->pci_dev,
+                     "VIRTIO_NET_F_MRG_RXBUF is not negotiated\n");
+             return -EINVAL;

Do we need to make sure FEATURE_OK is not set in this case or the ENI can do this for us?

Quoted 6 lines
Quoted 1 line

Why we need to check this? I don't get what you worried about.

I thought the plan is to advertise the VERSION_1, so failing when without mrg_rxbuf is a must. But looks like I was wrong, and there's no need to mandate mrg_rxbuf in future versions.

I think it is necessary to check F_MRG_RXBUF here, since ENI will not work when use qemu with mrx_rxbuf=off.

Quoted 8 lines

Thanks

Quoted 4 lines
Quoted 4 lines

Other looks good.

Thanks

#134 lore raw

Re: [PATCH v6 8/8] eni_vdpa: add vDPA driver for Alibaba ENI

Quoted 199 lines · Wu Zongyong
Quoted 162 lines · Jason Wang
Quoted 160 lines · Wu Zongyong
Quoted 146 lines · Jason Wang
Quoted 131 lines · Wu Zongyong

This patch adds a new vDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon virtio 0.9.5 specification. And this driver doesn't support to run on BE host.

---
  drivers/vdpa/Kconfig            |   8 +
  drivers/vdpa/Makefile           |   1 +
  drivers/vdpa/alibaba/Makefile   |   3 +
  drivers/vdpa/alibaba/eni_vdpa.c | 553 ++++++++++++++++++++++++++++++++
  4 files changed, 565 insertions(+)

create mode 100644 drivers/vdpa/alibaba/Makefile create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c

drivers/vdpa/Kconfig +8 -0
index 3d91982d8371..c0232a2148a7 100644
@@ -78,4 +78,12 @@ config VP_VDPA
         help
           This kernel module bridges virtio PCI device to vDPA bus.
 
+config ALIBABA_ENI_VDPA
+       tristate "vDPA driver for Alibaba ENI"
+       select VIRTIO_PCI_LEGACY_LIB
+       depends on PCI_MSI && !CPU_BIG_ENDIAN
+       help
+         VDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon
+         virtio 0.9.5 specification.
+
  endif # VDPA
drivers/vdpa/Makefile +1 -0
index f02ebed33f19..15665563a7f4 100644
@@ -5,3 +5,4 @@ obj-$(CONFIG_VDPA_USER) += vdpa_user/
  obj-$(CONFIG_IFCVF)    += ifcvf/
  obj-$(CONFIG_MLX5_VDPA) += mlx5/
  obj-$(CONFIG_VP_VDPA)    += virtio_pci/
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += alibaba/
drivers/vdpa/alibaba/Makefile new file +3 -0
new file mode 100644
index 000000000000..ef4aae69f87a
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += eni_vdpa.o
+
drivers/vdpa/alibaba/eni_vdpa.c new file +76 -0
new file mode 100644
index 000000000000..6a09f157d810
@@ -0,0 +1,553 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * vDPA bridge driver for Alibaba ENI(Elastic Network Interface)
+ *
+ * Copyright (c) 2021, Alibaba Inc. All rights reserved.
+ * Author: Wu Zongyong <[email protected]>
+ *
+ */
+
+#include "linux/bits.h"
+#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>
+#include <linux/virtio_ring.h>
+#include <linux/virtio_pci.h>
+#include <linux/virtio_pci_legacy.h>
+#include <uapi/linux/virtio_net.h>
+
+#define ENI_MSIX_NAME_SIZE 256
+
+#define ENI_ERR(pdev, fmt, ...)        \
+       dev_err(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+#define ENI_DBG(pdev, fmt, ...)        \
+       dev_dbg(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+#define ENI_INFO(pdev, fmt, ...) \
+       dev_info(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+
+struct eni_vring {
+       void __iomem *notify;
+       char msix_name[ENI_MSIX_NAME_SIZE];
+       struct vdpa_callback cb;
+       int irq;
+};
+
+struct eni_vdpa {
+       struct vdpa_device vdpa;
+       struct virtio_pci_legacy_device ldev;
+       struct eni_vring *vring;
+       struct vdpa_callback config_cb;
+       char msix_name[ENI_MSIX_NAME_SIZE];
+       int config_irq;
+       int queues;
+       int vectors;
+};
+
+static struct eni_vdpa *vdpa_to_eni(struct vdpa_device *vdpa)
+{
+       return container_of(vdpa, struct eni_vdpa, vdpa);
+}
+
+static struct virtio_pci_legacy_device *vdpa_to_ldev(struct vdpa_device *vdpa)
+{
+       struct eni_vdpa *eni_vdpa = vdpa_to_eni(vdpa);
+
+       return &eni_vdpa->ldev;
+}
+
+static u64 eni_vdpa_get_features(struct vdpa_device *vdpa)
+{
+       struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+       u64 features = vp_legacy_get_features(ldev);
+
+       features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM);
+       features |= BIT_ULL(VIRTIO_F_ORDER_PLATFORM);
+
+       return features;
+}
+
+static int eni_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
+{
+       struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+       if (!(features & BIT_ULL(VIRTIO_NET_F_MRG_RXBUF)) && features) {

drivers/vdpa/alibaba/eni_vdpa.c line 86

Quoted 10 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +10 -0
+               ENI_ERR(ldev->pci_dev,
+                       "VIRTIO_NET_F_MRG_RXBUF is not negotiated\n");
+               return -EINVAL;
+       }
+
+       vp_legacy_set_features(ldev, (u32)features);
+
+       return 0;
+}
+

So my comments have not been addressed since v4. Please address or answer the questions before posting a new version.

Quoted 1 line

Thanks

Sorry, I forgot to reply the comments on this patch.

Quoted 9 lines

drivers/vdpa/alibaba/eni_vdpa.c line 67

Quoted 7 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +7 -0
+static u64 eni_vdpa_get_features(struct vdpa_device *vdpa)
+{
+     struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+     u64 features = vp_legacy_get_features(ldev);
+
+     features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM);
+     features |= BIT_ULL(VIRTIO_F_ORDER_PLATFORM);

VERSION_1 is also needed?

Quoted 5 lines
Quoted 1 line

No, queue align of legacy devices should be 4096,

Let's use VIRTIO_PCI_VRING_ALIGN instead of PAGE_SIZE in get_vq_align then since PAGE_SIZE is not necessarily 4096.

I will fix it.

Quoted 10 lines
Quoted 6 lines

but queue align of
devices with VERSION_1 are SMP_CACHE_BYTES which may not equals to 4096.
If we set the VERSION_1, ENI will not work due to the queue align.

Interesting, so I think it can only be used with legacy virtio drivers in the guest.

Yes, ENI can only work well with legacy virtio drivers in the guest from my test.

Quoted 15 lines

One major drawbacks is that guest can only see 32 feature bits which means we can't advertise VIRTIO_F_ACCESS_PLATFORM and VIRTIO_F_ORDER_PLATFORM to guest:

/* virtio config->get_features() implementation */ static u64 vp_get_features(struct virtio_device *vdev)

{
        struct virtio_pci_device *vp_dev = to_vp_device(vdev);

        /* When someone needs more than 32 feature bits, we'll need to
         * steal a bit to indicate that the rest are somewhere else. */
        return ioread32(vp_dev->ioaddr + VIRTIO_PCI_HOST_FEATURES);
}
Quoted 6 lines
Quoted 3 lines

For VIRTIO_F_ACCESS_PLATFORM, it should be fine. But how about VIRTIO_F_ORDER_PLATFORM?

Is it necessary to advertise these two bits?
ENI works well without these two bits regardless of bare metal or virtual machine.

For VIRTIO_F_ACCESS_PLATFORM. When using with virtio-vDPA it should be fine since it will be negotiated. When using with vhost-vDPA, it can't be advertised to the guest, so vIOMMU will be bypassed.

For VITIO_F_ORDER_PLATFORM, it's basically a question that whether platform specific barrier (DMA barrier) is needed, see virtio_rmb():

static inline void virtio_rmb(bool weak_barriers)

{
        if (weak_barriers)
                virt_rmb();
        else
                dma_rmb();
}

So it looks to me x86 should be fine, but for others platform it might not. Maybe we can enable this driver for x86 first.

Thanks

Quoted 19 lines
Quoted 19 lines
Quoted 17 lines
Quoted 16 lines
Quoted 4 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +2 -0
+
+     return features;

drivers/vdpa/alibaba/eni_vdpa.c line 79

Quoted 10 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +10 -0
+}
+
+static int eni_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
+{
+     struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+     if (!(features & BIT_ULL(VIRTIO_NET_F_MRG_RXBUF)) && features) {
+             ENI_ERR(ldev->pci_dev,
+                     "VIRTIO_NET_F_MRG_RXBUF is not negotiated\n");
+             return -EINVAL;

Do we need to make sure FEATURE_OK is not set in this case or the ENI can do this for us?

Why we need to check this? I don't get what you worried about.

Quoted 15 lines
Quoted 3 lines

I thought the plan is to advertise the VERSION_1, so failing when without mrg_rxbuf is a must. But looks like I was wrong, and there's no need to mandate mrg_rxbuf in future versions.

I think it is necessary to check F_MRG_RXBUF here, since ENI will not work when use qemu with mrx_rxbuf=off.

Quoted 8 lines

Thanks

Quoted 4 lines
Quoted 4 lines

Other looks good.

Thanks

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#135 lore raw

Re: [PATCH v6 8/8] eni_vdpa: add vDPA driver for Alibaba ENI

Quoted 223 lines · Jason Wang
Quoted 199 lines · Wu Zongyong
Quoted 162 lines · Jason Wang
Quoted 160 lines · Wu Zongyong
Quoted 146 lines · Jason Wang
Quoted 131 lines · Wu Zongyong

This patch adds a new vDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon virtio 0.9.5 specification. And this driver doesn't support to run on BE host.

---
  drivers/vdpa/Kconfig            |   8 +
  drivers/vdpa/Makefile           |   1 +
  drivers/vdpa/alibaba/Makefile   |   3 +
  drivers/vdpa/alibaba/eni_vdpa.c | 553 ++++++++++++++++++++++++++++++++
  4 files changed, 565 insertions(+)

create mode 100644 drivers/vdpa/alibaba/Makefile create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c

drivers/vdpa/Kconfig +8 -0
index 3d91982d8371..c0232a2148a7 100644
@@ -78,4 +78,12 @@ config VP_VDPA
         help
           This kernel module bridges virtio PCI device to vDPA bus.
 
+config ALIBABA_ENI_VDPA
+       tristate "vDPA driver for Alibaba ENI"
+       select VIRTIO_PCI_LEGACY_LIB
+       depends on PCI_MSI && !CPU_BIG_ENDIAN
+       help
+         VDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon
+         virtio 0.9.5 specification.
+
  endif # VDPA
drivers/vdpa/Makefile +1 -0
index f02ebed33f19..15665563a7f4 100644
@@ -5,3 +5,4 @@ obj-$(CONFIG_VDPA_USER) += vdpa_user/
  obj-$(CONFIG_IFCVF)    += ifcvf/
  obj-$(CONFIG_MLX5_VDPA) += mlx5/
  obj-$(CONFIG_VP_VDPA)    += virtio_pci/
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += alibaba/
drivers/vdpa/alibaba/Makefile new file +3 -0
new file mode 100644
index 000000000000..ef4aae69f87a
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += eni_vdpa.o
+
drivers/vdpa/alibaba/eni_vdpa.c new file +76 -0
new file mode 100644
index 000000000000..6a09f157d810
@@ -0,0 +1,553 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * vDPA bridge driver for Alibaba ENI(Elastic Network Interface)
+ *
+ * Copyright (c) 2021, Alibaba Inc. All rights reserved.
+ * Author: Wu Zongyong <[email protected]>
+ *
+ */
+
+#include "linux/bits.h"
+#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>
+#include <linux/virtio_ring.h>
+#include <linux/virtio_pci.h>
+#include <linux/virtio_pci_legacy.h>
+#include <uapi/linux/virtio_net.h>
+
+#define ENI_MSIX_NAME_SIZE 256
+
+#define ENI_ERR(pdev, fmt, ...)        \
+       dev_err(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+#define ENI_DBG(pdev, fmt, ...)        \
+       dev_dbg(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+#define ENI_INFO(pdev, fmt, ...) \
+       dev_info(&pdev->dev, "%s"fmt, "eni_vdpa: ", ##__VA_ARGS__)
+
+struct eni_vring {
+       void __iomem *notify;
+       char msix_name[ENI_MSIX_NAME_SIZE];
+       struct vdpa_callback cb;
+       int irq;
+};
+
+struct eni_vdpa {
+       struct vdpa_device vdpa;
+       struct virtio_pci_legacy_device ldev;
+       struct eni_vring *vring;
+       struct vdpa_callback config_cb;
+       char msix_name[ENI_MSIX_NAME_SIZE];
+       int config_irq;
+       int queues;
+       int vectors;
+};
+
+static struct eni_vdpa *vdpa_to_eni(struct vdpa_device *vdpa)
+{
+       return container_of(vdpa, struct eni_vdpa, vdpa);
+}
+
+static struct virtio_pci_legacy_device *vdpa_to_ldev(struct vdpa_device *vdpa)
+{
+       struct eni_vdpa *eni_vdpa = vdpa_to_eni(vdpa);
+
+       return &eni_vdpa->ldev;
+}
+
+static u64 eni_vdpa_get_features(struct vdpa_device *vdpa)
+{
+       struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+       u64 features = vp_legacy_get_features(ldev);
+
+       features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM);
+       features |= BIT_ULL(VIRTIO_F_ORDER_PLATFORM);
+
+       return features;
+}
+
+static int eni_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
+{
+       struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+       if (!(features & BIT_ULL(VIRTIO_NET_F_MRG_RXBUF)) && features) {

drivers/vdpa/alibaba/eni_vdpa.c line 86

Quoted 10 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +10 -0
+               ENI_ERR(ldev->pci_dev,
+                       "VIRTIO_NET_F_MRG_RXBUF is not negotiated\n");
+               return -EINVAL;
+       }
+
+       vp_legacy_set_features(ldev, (u32)features);
+
+       return 0;
+}
+

So my comments have not been addressed since v4. Please address or answer the questions before posting a new version.

Quoted 1 line

Thanks

Sorry, I forgot to reply the comments on this patch.

Quoted 9 lines

drivers/vdpa/alibaba/eni_vdpa.c line 67

Quoted 7 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +7 -0
+static u64 eni_vdpa_get_features(struct vdpa_device *vdpa)
+{
+     struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+     u64 features = vp_legacy_get_features(ldev);
+
+     features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM);
+     features |= BIT_ULL(VIRTIO_F_ORDER_PLATFORM);

VERSION_1 is also needed?

Quoted 5 lines
Quoted 1 line

No, queue align of legacy devices should be 4096,

Let's use VIRTIO_PCI_VRING_ALIGN instead of PAGE_SIZE in get_vq_align then since PAGE_SIZE is not necessarily 4096.

I will fix it.

Quoted 10 lines
Quoted 6 lines

but queue align of
devices with VERSION_1 are SMP_CACHE_BYTES which may not equals to 4096.
If we set the VERSION_1, ENI will not work due to the queue align.

Interesting, so I think it can only be used with legacy virtio drivers in the guest.

Yes, ENI can only work well with legacy virtio drivers in the guest from my test.

Quoted 15 lines

One major drawbacks is that guest can only see 32 feature bits which means we can't advertise VIRTIO_F_ACCESS_PLATFORM and VIRTIO_F_ORDER_PLATFORM to guest:

/* virtio config->get_features() implementation */ static u64 vp_get_features(struct virtio_device *vdev)

{
        struct virtio_pci_device *vp_dev = to_vp_device(vdev);

        /* When someone needs more than 32 feature bits, we'll need to
         * steal a bit to indicate that the rest are somewhere else. */
        return ioread32(vp_dev->ioaddr + VIRTIO_PCI_HOST_FEATURES);
}
Quoted 6 lines
Quoted 3 lines

For VIRTIO_F_ACCESS_PLATFORM, it should be fine. But how about VIRTIO_F_ORDER_PLATFORM?

Is it necessary to advertise these two bits?
ENI works well without these two bits regardless of bare metal or virtual machine.

For VIRTIO_F_ACCESS_PLATFORM. When using with virtio-vDPA it should be fine since it will be negotiated. When using with vhost-vDPA, it can't be advertised to the guest, so vIOMMU will be bypassed.

For VITIO_F_ORDER_PLATFORM, it's basically a question that whether platform specific barrier (DMA barrier) is needed, see virtio_rmb():

static inline void virtio_rmb(bool weak_barriers)

{
        if (weak_barriers)
                virt_rmb();
        else
                dma_rmb();
}
Quoted 2 lines

So it looks to me x86 should be fine, but for others platform it might not. Maybe we can enable this driver for x86 first.

It's okay for me to enable it only for x86 via Kconfig since ENI can only be used in x86 machines on Alibaba Cloud for now.

Quoted 37 lines

Thanks

Quoted 34 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 4 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +2 -0
+
+     return features;

drivers/vdpa/alibaba/eni_vdpa.c line 79

Quoted 10 lines
drivers/vdpa/alibaba/eni_vdpa.c new file +10 -0
+}
+
+static int eni_vdpa_set_features(struct vdpa_device *vdpa, u64 features)
+{
+     struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa);
+
+     if (!(features & BIT_ULL(VIRTIO_NET_F_MRG_RXBUF)) && features) {
+             ENI_ERR(ldev->pci_dev,
+                     "VIRTIO_NET_F_MRG_RXBUF is not negotiated\n");
+             return -EINVAL;

Do we need to make sure FEATURE_OK is not set in this case or the ENI can do this for us?

Quoted 6 lines
Quoted 1 line

Why we need to check this? I don't get what you worried about.

I thought the plan is to advertise the VERSION_1, so failing when without mrg_rxbuf is a must. But looks like I was wrong, and there's no need to mandate mrg_rxbuf in future versions.

I think it is necessary to check F_MRG_RXBUF here, since ENI will not work when use qemu with mrx_rxbuf=off.

Quoted 8 lines

Thanks

Quoted 4 lines
Quoted 4 lines

Other looks good.

Thanks

#136 lore raw

v7 cover vDPA driver for Alibaba ENI

In reply to Wu Zongyong

This series implements the vDPA driver for Alibaba ENI (Elastic Network Interface) which is built based on virtio-pci 0.9.5 specification.

Changes since V6:
- set default min vq size to 1 intead of 0
- enable eni vdpa driver only on X86 hosts
- fix some typos

Changes since V5:
- remove unused codes

Changes since V4:
- check return values of get_vq_num_{max,min} when probing devices
- disable the driver on BE host via Kconfig
- add missing commit message

Changes since V3:
- validate VIRTIO_NET_F_MRG_RXBUF when negotiate features
- present F_ORDER_PLATFORM in get_features
- remove endian check since ENI always use litter endian

Changes since V2:
- add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE instead VDPA_ATTR_DEV_F_VERSION_1 to guide users to choose correct virtqueue size as suggested by Jason Wang
- present ACCESS_PLATFORM in get_features callback as suggested by Jason Wang
- disable this driver on Big Endian host as suggested by Jason Wang
- fix a typo

Changes since V1:
- add new vdpa attribute VDPA_ATTR_DEV_F_VERSION_1 to indicate whether the vdpa device is legacy
- implement dedicated driver for Alibaba ENI instead a legacy virtio-pci driver as suggested by Jason Wang
- some bugs fixed

Wu Zongyong (9):
virtio-pci: introduce legacy device module
vdpa: fix typo
vp_vdpa: add vq irq offloading support
vdpa: add new callback get_vq_num_min in vdpa_config_ops
vdpa: min vq num of vdpa device cannot be greater than max vq num
virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}
vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE
eni_vdpa: add vDPA driver for Alibaba ENI
eni_vdpa: alibaba: fix Kconfig typo

 drivers/vdpa/Kconfig                   |   8 +
 drivers/vdpa/Makefile                  |   1 +
 drivers/vdpa/alibaba/Makefile          |   3 +
 drivers/vdpa/alibaba/eni_vdpa.c        | 553 +++++++++++++++++++++++++
 drivers/vdpa/vdpa.c                    |  13 +
 drivers/vdpa/virtio_pci/vp_vdpa.c      |  12 +
 drivers/virtio/Kconfig                 |  10 +
 drivers/virtio/Makefile                |   1 +
 drivers/virtio/virtio_pci_common.c     |  10 +-
 drivers/virtio/virtio_pci_common.h     |   9 +-
 drivers/virtio/virtio_pci_legacy.c     | 101 ++---
 drivers/virtio/virtio_pci_legacy_dev.c | 220 ++++++++++
 drivers/virtio/virtio_vdpa.c           |  16 +-
 include/linux/vdpa.h                   |   6 +-
 include/linux/virtio_pci_legacy.h      |  42 ++
 include/uapi/linux/vdpa.h              |   1 +
 16 files changed, 917 insertions(+), 89 deletions(-)
 create mode 100644 drivers/vdpa/alibaba/Makefile
 create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
 create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c
 create mode 100644 include/linux/virtio_pci_legacy.h
Signature · 1 line
2.31.1
#137 lore raw

PATCH v7 1/9 virtio-pci: introduce legacy device module

Split common codes from virtio-pci-legacy so vDPA driver can reuse it later.

---
 drivers/virtio/Kconfig                 |  10 ++
 drivers/virtio/Makefile                |   1 +
 drivers/virtio/virtio_pci_common.c     |  10 +-
 drivers/virtio/virtio_pci_common.h     |   9 +-
 drivers/virtio/virtio_pci_legacy.c     | 101 +++---------
 drivers/virtio/virtio_pci_legacy_dev.c | 220 +++++++++++++++++++++++++
 include/linux/virtio_pci_legacy.h      |  42 +++++
 7 files changed, 310 insertions(+), 83 deletions(-)
 create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c
 create mode 100644 include/linux/virtio_pci_legacy.h
drivers/virtio/Kconfig +10 -0
index ce1b3f6ec325..8fcf94cd2c96 100644
@@ -20,6 +20,15 @@ config VIRTIO_PCI_LIB
 	  PCI device with possible vendor specific extensions. Any
 	  module that selects this module must depend on PCI.
 
+config VIRTIO_PCI_LIB_LEGACY
+	tristate
+	help
+	  Legacy PCI device (Virtio PCI Card 0.9.x Draft and older device)
+	  implementation.
+	  This module implements the basic probe and control for devices
+	  which are based on legacy PCI device. Any module that selects this
+	  module must depend on PCI.
+
 menuconfig VIRTIO_MENU
 	bool "Virtio drivers"
 	default y
@@ -43,6 +52,7 @@ config VIRTIO_PCI_LEGACY
 	bool "Support for legacy virtio draft 0.9.X and older devices"
 	default y
 	depends on VIRTIO_PCI
+	select VIRTIO_PCI_LIB_LEGACY
 	help
           Virtio PCI Card 0.9.X Draft (circa 2014) and older device support.
 
drivers/virtio/Makefile +1 -0
index 699bbea0465f..0a82d0873248 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
 obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o
+obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_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.c +6 -4
index b35bb2d57f62..d724f676608b 100644
@@ -549,6 +549,8 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 
 	pci_set_master(pci_dev);
 
+	vp_dev->is_legacy = vp_dev->ldev.ioaddr ? true : false;
+
 	rc = register_virtio_device(&vp_dev->vdev);
 	reg_dev = vp_dev;
 	if (rc)
@@ -557,10 +559,10 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 	return 0;
 
 err_register:
-	if (vp_dev->ioaddr)
-	     virtio_pci_legacy_remove(vp_dev);
+	if (vp_dev->is_legacy)
+		virtio_pci_legacy_remove(vp_dev);
 	else
-	     virtio_pci_modern_remove(vp_dev);
+		virtio_pci_modern_remove(vp_dev);
 err_probe:
 	pci_disable_device(pci_dev);
 err_enable_device:
@@ -587,7 +589,7 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
 
 	unregister_virtio_device(&vp_dev->vdev);
 
-	if (vp_dev->ioaddr)
+	if (vp_dev->is_legacy)
 		virtio_pci_legacy_remove(vp_dev);
 	else
 		virtio_pci_modern_remove(vp_dev);
drivers/virtio/virtio_pci_common.h +4 -5
index beec047a8f8d..eb17a29fc7ef 100644
@@ -25,6 +25,7 @@
 #include <linux/virtio_config.h>
 #include <linux/virtio_ring.h>
 #include <linux/virtio_pci.h>
+#include <linux/virtio_pci_legacy.h>
 #include <linux/virtio_pci_modern.h>
 #include <linux/highmem.h>
 #include <linux/spinlock.h>
@@ -44,16 +45,14 @@ struct virtio_pci_vq_info {
 struct virtio_pci_device {
 	struct virtio_device vdev;
 	struct pci_dev *pci_dev;
+	struct virtio_pci_legacy_device ldev;
 	struct virtio_pci_modern_device mdev;
 
-	/* In legacy mode, these two point to within ->legacy. */
+	bool is_legacy;
+
 	/* Where to read and clear interrupt */
 	u8 __iomem *isr;
 
-	/* Legacy only field */
-	/* the IO mapping for the PCI config space */
-	void __iomem *ioaddr;
-
 	/* a list of queues so we can dispatch IRQs */
 	spinlock_t lock;
 	struct list_head virtqueues;
drivers/virtio/virtio_pci_legacy.c +27 -74

212 lines not on this page · raw message

drivers/virtio/virtio_pci_legacy_dev.c new file +220 -0

220 lines not on this page · raw message

include/linux/virtio_pci_legacy.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.31.1
#138 lore raw

PATCH v7 2/9 vdpa: fix typo

In reply to Wu Zongyong
---
 include/linux/vdpa.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/vdpa.h +1 -1
index 3972ab765de1..a896ee021e5f 100644
@@ -257,7 +257,7 @@ struct vdpa_config_ops {
 	struct vdpa_notification_area
 	(*get_vq_notification)(struct vdpa_device *vdev, u16 idx);
 	/* vq irq is not expected to be changed once DRIVER_OK is set */
-	int (*get_vq_irq)(struct vdpa_device *vdv, u16 idx);
+	int (*get_vq_irq)(struct vdpa_device *vdev, u16 idx);
 
 	/* Device ops */
 	u32 (*get_vq_align)(struct vdpa_device *vdev);
Signature · 1 line
2.31.1
#139 lore raw

PATCH v7 3/9 vp_vdpa: add vq irq offloading support

In reply to Wu Zongyong

This patch implements the get_vq_irq() callback for virtio pci devices to allow irq offloading.

---
 drivers/vdpa/virtio_pci/vp_vdpa.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/vdpa/virtio_pci/vp_vdpa.c +12 -0
index 5bcd00246d2e..e3ff7875e123 100644
@@ -76,6 +76,17 @@ static u8 vp_vdpa_get_status(struct vdpa_device *vdpa)
 	return vp_modern_get_status(mdev);
 }
 
+static int vp_vdpa_get_vq_irq(struct vdpa_device *vdpa, u16 idx)
+{
+	struct vp_vdpa *vp_vdpa = vdpa_to_vp(vdpa);
+	int irq = vp_vdpa->vring[idx].irq;
+
+	if (irq == VIRTIO_MSI_NO_VECTOR)
+		return -EINVAL;
+
+	return irq;
+}
+
 static void vp_vdpa_free_irq(struct vp_vdpa *vp_vdpa)
 {
 	struct virtio_pci_modern_device *mdev = &vp_vdpa->mdev;
@@ -427,6 +438,7 @@ static const struct vdpa_config_ops vp_vdpa_ops = {
 	.get_config	= vp_vdpa_get_config,
 	.set_config	= vp_vdpa_set_config,
 	.set_config_cb  = vp_vdpa_set_config_cb,
+	.get_vq_irq	= vp_vdpa_get_vq_irq,
 };
 
 static void vp_vdpa_free_irq_vectors(void *data)
Signature · 1 line
2.31.1
#140 lore raw

PATCH v7 4/9 vdpa: add new callback get_vq_num_min in vdpa_config_ops

In reply to Wu Zongyong

This callback is optional. For vdpa devices that not support to change virtqueue size, get_vq_num_min and get_vq_num_max will return the same value, so that users can choose a correct value for that device.

---
 include/linux/vdpa.h | 4 ++++
 1 file changed, 4 insertions(+)
include/linux/vdpa.h +4 -0
index a896ee021e5f..30864848950b 100644
@@ -171,6 +171,9 @@ struct vdpa_map_file {
  * @get_vq_num_max:		Get the max size of virtqueue
  *				@vdev: vdpa device
  *				Returns u16: max size of virtqueue
+ * @get_vq_num_min:		Get the min size of virtqueue (optional)
+ *				@vdev: vdpa device
+ *				Returns u16: min size of virtqueue
  * @get_device_id:		Get virtio device id
  *				@vdev: vdpa device
  *				Returns u32: virtio device id
@@ -266,6 +269,7 @@ struct vdpa_config_ops {
 	void (*set_config_cb)(struct vdpa_device *vdev,
 			      struct vdpa_callback *cb);
 	u16 (*get_vq_num_max)(struct vdpa_device *vdev);
+	u16 (*get_vq_num_min)(struct vdpa_device *vdev);
 	u32 (*get_device_id)(struct vdpa_device *vdev);
 	u32 (*get_vendor_id)(struct vdpa_device *vdev);
 	u8 (*get_status)(struct vdpa_device *vdev);
Signature · 1 line
2.31.1
#141 lore raw

PATCH v7 5/9 vdpa: min vq num of vdpa device cannot be greater than max vq num

In reply to Wu Zongyong

Just failed to probe the vdpa device if the min virtqueue num returned by get_vq_num_min is greater than the max virtqueue num returned by get_vq_num_max.

---
 drivers/vdpa/vdpa.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/vdpa/vdpa.c +8 -0
index 1dc121a07a93..d783a943647d 100644
@@ -26,8 +26,16 @@ static int vdpa_dev_probe(struct device *d)
 {
 	struct vdpa_device *vdev = dev_to_vdpa(d);
 	struct vdpa_driver *drv = drv_to_vdpa(vdev->dev.driver);
+	const struct vdpa_config_ops *ops = vdev->config;
+	u32 max_num, min_num = 1;
 	int ret = 0;
 
+	max_num = ops->get_vq_num_max(vdev);
+	if (ops->get_vq_num_min)
+		min_num = ops->get_vq_num_min(vdev);
+	if (max_num < min_num)
+		return -EINVAL;
+
 	if (drv && drv->probe)
 		ret = drv->probe(vdev);
 
Signature · 1 line
2.31.1
#142 lore raw

PATCH v7 6/9 virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}

In reply to Wu Zongyong

For the devices which implement the get_vq_num_min callback, the driver should not negotiate with virtqueue size with the backend vdpa device if the value returned by get_vq_num_min equals to the value returned by get_vq_num_max.
This is useful for vdpa devices based on legacy virtio specfication.

---
 drivers/virtio/virtio_vdpa.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/virtio/virtio_vdpa.c +11 -5
index 72eaef2caeb1..6b62aaf08cc5 100644
@@ -145,7 +145,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 	/* Assume split virtqueue, switch to packed if necessary */
 	struct vdpa_vq_state state = {0};
 	unsigned long flags;
-	u32 align, num;
+	u32 align, max_num, min_num = 1;
+	bool may_reduce_num = true;
 	int err;
 
 	if (!name)
@@ -163,16 +164,21 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 	if (!info)
 		return ERR_PTR(-ENOMEM);
 
-	num = ops->get_vq_num_max(vdpa);
-	if (num == 0) {
+	max_num = ops->get_vq_num_max(vdpa);
+	if (max_num == 0) {
 		err = -ENOENT;
 		goto error_new_virtqueue;
 	}
 
+	if (ops->get_vq_num_min)
+		min_num = ops->get_vq_num_min(vdpa);
+
+	may_reduce_num = (max_num == min_num) ? false : true;
+
 	/* Create the vring */
 	align = ops->get_vq_align(vdpa);
-	vq = vring_create_virtqueue(index, num, align, vdev,
-				    true, true, ctx,
+	vq = vring_create_virtqueue(index, max_num, align, vdev,
+				    true, may_reduce_num, ctx,
 				    virtio_vdpa_notify, callback, name);
 	if (!vq) {
 		err = -ENOMEM;
Signature · 1 line
2.31.1
#143 lore raw

PATCH v7 7/9 vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE

In reply to Wu Zongyong

This attribute advertises the min value of virtqueue size. The value is 1 by default.

---
 drivers/vdpa/vdpa.c       | 5 +++++
 include/uapi/linux/vdpa.h | 1 +
 2 files changed, 6 insertions(+)
drivers/vdpa/vdpa.c +5 -0
index d783a943647d..fcf02a364878 100644
@@ -500,6 +500,7 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
 	      int flags, struct netlink_ext_ack *extack)
 {
 	u16 max_vq_size;
+	u16 min_vq_size = 1;
 	u32 device_id;
 	u32 vendor_id;
 	void *hdr;
@@ -516,6 +517,8 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
 	device_id = vdev->config->get_device_id(vdev);
 	vendor_id = vdev->config->get_vendor_id(vdev);
 	max_vq_size = vdev->config->get_vq_num_max(vdev);
+	if (vdev->config->get_vq_num_min)
+		min_vq_size = vdev->config->get_vq_num_min(vdev);
 
 	err = -EMSGSIZE;
 	if (nla_put_string(msg, VDPA_ATTR_DEV_NAME, dev_name(&vdev->dev)))
@@ -528,6 +531,8 @@ vdpa_dev_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq
 		goto msg_err;
 	if (nla_put_u16(msg, VDPA_ATTR_DEV_MAX_VQ_SIZE, max_vq_size))
 		goto msg_err;
+	if (nla_put_u16(msg, VDPA_ATTR_DEV_MIN_VQ_SIZE, min_vq_size))
+		goto msg_err;
 
 	genlmsg_end(msg, hdr);
 	return 0;
include/uapi/linux/vdpa.h +1 -0
index 66a41e4ec163..e3b87879514c 100644
@@ -32,6 +32,7 @@ enum vdpa_attr {
 	VDPA_ATTR_DEV_VENDOR_ID,		/* u32 */
 	VDPA_ATTR_DEV_MAX_VQS,			/* u32 */
 	VDPA_ATTR_DEV_MAX_VQ_SIZE,		/* u16 */
+	VDPA_ATTR_DEV_MIN_VQ_SIZE,		/* u16 */
 
 	/* new attributes must be added above here */
 	VDPA_ATTR_MAX,
Signature · 1 line
2.31.1
#144 lore raw

PATCH v7 8/9 eni_vdpa: add vDPA driver for Alibaba ENI

In reply to Wu Zongyong

This patch adds a new vDPA driver for Alibaba ENI(Elastic Network Interface) which is build upon virtio 0.9.5 specification. And this driver is only enabled on X86 host currently.

---
 drivers/vdpa/Kconfig            |   8 +
 drivers/vdpa/Makefile           |   1 +
 drivers/vdpa/alibaba/Makefile   |   3 +
 drivers/vdpa/alibaba/eni_vdpa.c | 553 ++++++++++++++++++++++++++++++++
 4 files changed, 565 insertions(+)
 create mode 100644 drivers/vdpa/alibaba/Makefile
 create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
drivers/vdpa/Kconfig +8 -0
index 3d91982d8371..07b0c73212aa 100644
@@ -78,4 +78,12 @@ config VP_VDPA
 	help
 	  This kernel module bridges virtio PCI device to vDPA bus.
 
+config ALIBABA_ENI_VDPA
+	tristate "vDPA driver for Alibaba ENI"
+	select VIRTIO_PCI_LEGACY_LIB
+	depends on PCI_MSI && X86
+	help
+	  VDPA driver for Alibaba ENI (Elastic Network Interface) which is built upon
+	  virtio 0.9.5 specification.
+
 endif # VDPA
drivers/vdpa/Makefile +1 -0
index f02ebed33f19..15665563a7f4 100644
@@ -5,3 +5,4 @@ obj-$(CONFIG_VDPA_USER) += vdpa_user/
 obj-$(CONFIG_IFCVF)    += ifcvf/
 obj-$(CONFIG_MLX5_VDPA) += mlx5/
 obj-$(CONFIG_VP_VDPA)    += virtio_pci/
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += alibaba/
drivers/vdpa/alibaba/Makefile new file +3 -0
new file mode 100644
index 000000000000..ef4aae69f87a
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_ALIBABA_ENI_VDPA) += eni_vdpa.o
+
drivers/vdpa/alibaba/eni_vdpa.c new file +553 -0

553 lines not on this page · raw message

Signature · 1 line
2.31.1
#145 lore raw

PATCH v7 9/9 eni_vdpa: alibaba: fix Kconfig typo

In reply to Wu Zongyong

The Kconfig symbol was misspelled, which leads to randconfig link failures:

ld.lld: error: undefined symbol: vp_legacy_probe

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by eni_vdpa.c
vdpa/alibaba/eni_vdpa.o:(eni_vdpa_probe) in archive drivers/built-in.a

Fixes 6a9f32c00609 ("eni_vdpa: add vDPA driver for Alibaba ENI")
---
 drivers/vdpa/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vdpa/Kconfig +1 -1
index 07b0c73212aa..50f45d037611 100644
@@ -80,7 +80,7 @@ config VP_VDPA
 
 config ALIBABA_ENI_VDPA
 	tristate "vDPA driver for Alibaba ENI"
-	select VIRTIO_PCI_LEGACY_LIB
+	select VIRTIO_PCI_LIB_LEGACY
 	depends on PCI_MSI && X86
 	help
 	  VDPA driver for Alibaba ENI (Elastic Network Interface) which is built upon
Signature · 1 line
2.31.1
#146 lore raw

Re: [PATCH v7 9/9] eni_vdpa: alibaba: fix Kconfig typo

Quoted 11 lines · Wu Zongyong

The Kconfig symbol was misspelled, which leads to randconfig link failures:

ld.lld: error: undefined symbol: vp_legacy_probe

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by eni_vdpa.c
vdpa/alibaba/eni_vdpa.o:(eni_vdpa_probe) in archive drivers/built-in.a

Fixes 6a9f32c00609 ("eni_vdpa: add vDPA driver for Alibaba ENI")

This one I'll squash into the previous one. That commit hash is not going to match anything useful.

Quoted 19 lines
---
 drivers/vdpa/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vdpa/Kconfig +1 -1
index 07b0c73212aa..50f45d037611 100644
@@ -80,7 +80,7 @@ config VP_VDPA
 
 config ALIBABA_ENI_VDPA
 	tristate "vDPA driver for Alibaba ENI"
-	select VIRTIO_PCI_LEGACY_LIB
+	select VIRTIO_PCI_LIB_LEGACY
 	depends on PCI_MSI && X86
 	help
 	  VDPA driver for Alibaba ENI (Elastic Network Interface) which is built upon
Signature · 1 line
2.31.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#147 lore raw

Re: [PATCH v7 0/9] vDPA driver for Alibaba ENI

In reply to Wu Zongyong
Quoted 3 lines · Wu Zongyong

This series implements the vDPA driver for Alibaba ENI (Elastic Network Interface) which is built based on virtio-pci 0.9.5 specification.

It looks to me Michael has applied the patches, if this is the case, we probably need to send patches on top.

Thanks

Quoted 71 lines

Changes since V6:
- set default min vq size to 1 intead of 0
- enable eni vdpa driver only on X86 hosts
- fix some typos

Changes since V5:
- remove unused codes

Changes since V4:
- check return values of get_vq_num_{max,min} when probing devices
- disable the driver on BE host via Kconfig
- add missing commit message

Changes since V3:
- validate VIRTIO_NET_F_MRG_RXBUF when negotiate features
- present F_ORDER_PLATFORM in get_features
- remove endian check since ENI always use litter endian

Changes since V2:
- add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE instead VDPA_ATTR_DEV_F_VERSION_1 to guide users to choose correct virtqueue size as suggested by Jason Wang
- present ACCESS_PLATFORM in get_features callback as suggested by Jason Wang
- disable this driver on Big Endian host as suggested by Jason Wang
- fix a typo

Changes since V1:
- add new vdpa attribute VDPA_ATTR_DEV_F_VERSION_1 to indicate whether the vdpa device is legacy
- implement dedicated driver for Alibaba ENI instead a legacy virtio-pci driver as suggested by Jason Wang
- some bugs fixed

Wu Zongyong (9):
virtio-pci: introduce legacy device module
vdpa: fix typo
vp_vdpa: add vq irq offloading support
vdpa: add new callback get_vq_num_min in vdpa_config_ops
vdpa: min vq num of vdpa device cannot be greater than max vq num
virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}
vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE
eni_vdpa: add vDPA driver for Alibaba ENI
eni_vdpa: alibaba: fix Kconfig typo

 drivers/vdpa/Kconfig                   |   8 +
 drivers/vdpa/Makefile                  |   1 +
 drivers/vdpa/alibaba/Makefile          |   3 +
 drivers/vdpa/alibaba/eni_vdpa.c        | 553 +++++++++++++++++++++++++
 drivers/vdpa/vdpa.c                    |  13 +
 drivers/vdpa/virtio_pci/vp_vdpa.c      |  12 +
 drivers/virtio/Kconfig                 |  10 +
 drivers/virtio/Makefile                |   1 +
 drivers/virtio/virtio_pci_common.c     |  10 +-
 drivers/virtio/virtio_pci_common.h     |   9 +-
 drivers/virtio/virtio_pci_legacy.c     | 101 ++---
 drivers/virtio/virtio_pci_legacy_dev.c | 220 ++++++++++
 drivers/virtio/virtio_vdpa.c           |  16 +-
 include/linux/vdpa.h                   |   6 +-
 include/linux/virtio_pci_legacy.h      |  42 ++
 include/uapi/linux/vdpa.h              |   1 +
 16 files changed, 917 insertions(+), 89 deletions(-)
 create mode 100644 drivers/vdpa/alibaba/Makefile
 create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
 create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c
 create mode 100644 include/linux/virtio_pci_legacy.h

--
2.31.1

#148 lore raw

Re: [PATCH v7 0/9] vDPA driver for Alibaba ENI

Quoted 8 lines · Jason Wang
Quoted 3 lines · Wu Zongyong

This series implements the vDPA driver for Alibaba ENI (Elastic Network Interface) which is built based on virtio-pci 0.9.5 specification.

It looks to me Michael has applied the patches, if this is the case, we probably need to send patches on top.

What do you mean by saying "send patches on top"?
Sorry, I'm a newbie to contribute for kernel, could you please explain it in detail?

Thanks

Quoted 73 lines

Thanks

Quoted 71 lines

Changes since V6:
- set default min vq size to 1 intead of 0
- enable eni vdpa driver only on X86 hosts
- fix some typos

Changes since V5:
- remove unused codes

Changes since V4:
- check return values of get_vq_num_{max,min} when probing devices
- disable the driver on BE host via Kconfig
- add missing commit message

Changes since V3:
- validate VIRTIO_NET_F_MRG_RXBUF when negotiate features
- present F_ORDER_PLATFORM in get_features
- remove endian check since ENI always use litter endian

Changes since V2:
- add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE instead VDPA_ATTR_DEV_F_VERSION_1 to guide users to choose correct virtqueue size as suggested by Jason Wang
- present ACCESS_PLATFORM in get_features callback as suggested by Jason Wang
- disable this driver on Big Endian host as suggested by Jason Wang
- fix a typo

Changes since V1:
- add new vdpa attribute VDPA_ATTR_DEV_F_VERSION_1 to indicate whether the vdpa device is legacy
- implement dedicated driver for Alibaba ENI instead a legacy virtio-pci driver as suggested by Jason Wang
- some bugs fixed

Wu Zongyong (9):
virtio-pci: introduce legacy device module
vdpa: fix typo
vp_vdpa: add vq irq offloading support
vdpa: add new callback get_vq_num_min in vdpa_config_ops
vdpa: min vq num of vdpa device cannot be greater than max vq num
virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}
vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE
eni_vdpa: add vDPA driver for Alibaba ENI
eni_vdpa: alibaba: fix Kconfig typo

 drivers/vdpa/Kconfig                   |   8 +
 drivers/vdpa/Makefile                  |   1 +
 drivers/vdpa/alibaba/Makefile          |   3 +
 drivers/vdpa/alibaba/eni_vdpa.c        | 553 +++++++++++++++++++++++++
 drivers/vdpa/vdpa.c                    |  13 +
 drivers/vdpa/virtio_pci/vp_vdpa.c      |  12 +
 drivers/virtio/Kconfig                 |  10 +
 drivers/virtio/Makefile                |   1 +
 drivers/virtio/virtio_pci_common.c     |  10 +-
 drivers/virtio/virtio_pci_common.h     |   9 +-
 drivers/virtio/virtio_pci_legacy.c     | 101 ++---
 drivers/virtio/virtio_pci_legacy_dev.c | 220 ++++++++++
 drivers/virtio/virtio_vdpa.c           |  16 +-
 include/linux/vdpa.h                   |   6 +-
 include/linux/virtio_pci_legacy.h      |  42 ++
 include/uapi/linux/vdpa.h              |   1 +
 16 files changed, 917 insertions(+), 89 deletions(-)
 create mode 100644 drivers/vdpa/alibaba/Makefile
 create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
 create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c
 create mode 100644 include/linux/virtio_pci_legacy.h

--
2.31.1

#149 lore raw

Re: [PATCH v7 0/9] vDPA driver for Alibaba ENI

Quoted 8 lines · Wu Zongyong
Quoted 6 lines · Jason Wang
Quoted 3 lines · Wu Zongyong

This series implements the vDPA driver for Alibaba ENI (Elastic Network Interface) which is built based on virtio-pci 0.9.5 specification.

Quoted 6 lines
Quoted 2 lines

It looks to me Michael has applied the patches, if this is the case, we probably need to send patches on top.

What do you mean by saying "send patches on top"?
Sorry, I'm a newbie to contribute for kernel, could you please explain it in detail?

I meant you probably need to send incremental patch on top of:

git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next.

Thanks

Quoted 76 lines

Thanks

Quoted 73 lines

Thanks

Quoted 71 lines

Changes since V6:
- set default min vq size to 1 intead of 0
- enable eni vdpa driver only on X86 hosts
- fix some typos

Changes since V5:
- remove unused codes

Changes since V4:
- check return values of get_vq_num_{max,min} when probing devices
- disable the driver on BE host via Kconfig
- add missing commit message

Changes since V3:
- validate VIRTIO_NET_F_MRG_RXBUF when negotiate features
- present F_ORDER_PLATFORM in get_features
- remove endian check since ENI always use litter endian

Changes since V2:
- add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE instead VDPA_ATTR_DEV_F_VERSION_1 to guide users to choose correct virtqueue size as suggested by Jason Wang
- present ACCESS_PLATFORM in get_features callback as suggested by Jason Wang
- disable this driver on Big Endian host as suggested by Jason Wang
- fix a typo

Changes since V1:
- add new vdpa attribute VDPA_ATTR_DEV_F_VERSION_1 to indicate whether the vdpa device is legacy
- implement dedicated driver for Alibaba ENI instead a legacy virtio-pci driver as suggested by Jason Wang
- some bugs fixed

Wu Zongyong (9):
virtio-pci: introduce legacy device module
vdpa: fix typo
vp_vdpa: add vq irq offloading support
vdpa: add new callback get_vq_num_min in vdpa_config_ops
vdpa: min vq num of vdpa device cannot be greater than max vq num
virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}
vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE
eni_vdpa: add vDPA driver for Alibaba ENI
eni_vdpa: alibaba: fix Kconfig typo

 drivers/vdpa/Kconfig                   |   8 +
 drivers/vdpa/Makefile                  |   1 +
 drivers/vdpa/alibaba/Makefile          |   3 +
 drivers/vdpa/alibaba/eni_vdpa.c        | 553 +++++++++++++++++++++++++
 drivers/vdpa/vdpa.c                    |  13 +
 drivers/vdpa/virtio_pci/vp_vdpa.c      |  12 +
 drivers/virtio/Kconfig                 |  10 +
 drivers/virtio/Makefile                |   1 +
 drivers/virtio/virtio_pci_common.c     |  10 +-
 drivers/virtio/virtio_pci_common.h     |   9 +-
 drivers/virtio/virtio_pci_legacy.c     | 101 ++---
 drivers/virtio/virtio_pci_legacy_dev.c | 220 ++++++++++
 drivers/virtio/virtio_vdpa.c           |  16 +-
 include/linux/vdpa.h                   |   6 +-
 include/linux/virtio_pci_legacy.h      |  42 ++
 include/uapi/linux/vdpa.h              |   1 +
 16 files changed, 917 insertions(+), 89 deletions(-)
 create mode 100644 drivers/vdpa/alibaba/Makefile
 create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
 create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c
 create mode 100644 include/linux/virtio_pci_legacy.h

--
2.31.1

#150 lore raw

Re: [PATCH v7 0/9] vDPA driver for Alibaba ENI

Quoted 12 lines · Jason Wang
Quoted 11 lines · Wu Zongyong
Quoted 8 lines · Jason Wang
Quoted 3 lines · Wu Zongyong

This series implements the vDPA driver for Alibaba ENI (Elastic Network Interface) which is built based on virtio-pci 0.9.5 specification.

It looks to me Michael has applied the patches, if this is the case, we probably need to send patches on top.

Quoted 7 lines
Quoted 3 lines

What do you mean by saying "send patches on top"?
Sorry, I'm a newbie to contribute for kernel, could you please explain it in detail?

I meant you probably need to send incremental patch on top of:

git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next.

Get it.

Thanks

Quoted 80 lines

Thanks

Quoted 76 lines

Thanks

Quoted 73 lines

Thanks

Quoted 71 lines

Changes since V6:
- set default min vq size to 1 intead of 0
- enable eni vdpa driver only on X86 hosts
- fix some typos

Changes since V5:
- remove unused codes

Changes since V4:
- check return values of get_vq_num_{max,min} when probing devices
- disable the driver on BE host via Kconfig
- add missing commit message

Changes since V3:
- validate VIRTIO_NET_F_MRG_RXBUF when negotiate features
- present F_ORDER_PLATFORM in get_features
- remove endian check since ENI always use litter endian

Changes since V2:
- add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE instead VDPA_ATTR_DEV_F_VERSION_1 to guide users to choose correct virtqueue size as suggested by Jason Wang
- present ACCESS_PLATFORM in get_features callback as suggested by Jason Wang
- disable this driver on Big Endian host as suggested by Jason Wang
- fix a typo

Changes since V1:
- add new vdpa attribute VDPA_ATTR_DEV_F_VERSION_1 to indicate whether the vdpa device is legacy
- implement dedicated driver for Alibaba ENI instead a legacy virtio-pci driver as suggested by Jason Wang
- some bugs fixed

Wu Zongyong (9):
virtio-pci: introduce legacy device module
vdpa: fix typo
vp_vdpa: add vq irq offloading support
vdpa: add new callback get_vq_num_min in vdpa_config_ops
vdpa: min vq num of vdpa device cannot be greater than max vq num
virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}
vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE
eni_vdpa: add vDPA driver for Alibaba ENI
eni_vdpa: alibaba: fix Kconfig typo

 drivers/vdpa/Kconfig                   |   8 +
 drivers/vdpa/Makefile                  |   1 +
 drivers/vdpa/alibaba/Makefile          |   3 +
 drivers/vdpa/alibaba/eni_vdpa.c        | 553 +++++++++++++++++++++++++
 drivers/vdpa/vdpa.c                    |  13 +
 drivers/vdpa/virtio_pci/vp_vdpa.c      |  12 +
 drivers/virtio/Kconfig                 |  10 +
 drivers/virtio/Makefile                |   1 +
 drivers/virtio/virtio_pci_common.c     |  10 +-
 drivers/virtio/virtio_pci_common.h     |   9 +-
 drivers/virtio/virtio_pci_legacy.c     | 101 ++---
 drivers/virtio/virtio_pci_legacy_dev.c | 220 ++++++++++
 drivers/virtio/virtio_vdpa.c           |  16 +-
 include/linux/vdpa.h                   |   6 +-
 include/linux/virtio_pci_legacy.h      |  42 ++
 include/uapi/linux/vdpa.h              |   1 +
 16 files changed, 917 insertions(+), 89 deletions(-)
 create mode 100644 drivers/vdpa/alibaba/Makefile
 create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
 create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c
 create mode 100644 include/linux/virtio_pci_legacy.h

--
2.31.1

#151 lore raw

Re: [PATCH v7 0/9] vDPA driver for Alibaba ENI

Quoted 17 lines · Wu Zongyong
Quoted 16 lines · Jason Wang
Quoted 14 lines · Wu Zongyong
Quoted 8 lines · Jason Wang
Quoted 3 lines · Wu Zongyong

This series implements the vDPA driver for Alibaba ENI (Elastic Network Interface) which is built based on virtio-pci 0.9.5 specification.

It looks to me Michael has applied the patches, if this is the case, we probably need to send patches on top.

What do you mean by saying "send patches on top"?
Sorry, I'm a newbie to contribute for kernel, could you please explain it in detail?

Quoted 7 lines
Quoted 3 lines

I meant you probably need to send incremental patch on top of:

git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next.

Get it.

Thanks

No need, I rebased.

Quoted 80 lines
Quoted 80 lines

Thanks

Quoted 76 lines

Thanks

Quoted 73 lines

Thanks

Quoted 71 lines

Changes since V6:
- set default min vq size to 1 intead of 0
- enable eni vdpa driver only on X86 hosts
- fix some typos

Changes since V5:
- remove unused codes

Changes since V4:
- check return values of get_vq_num_{max,min} when probing devices
- disable the driver on BE host via Kconfig
- add missing commit message

Changes since V3:
- validate VIRTIO_NET_F_MRG_RXBUF when negotiate features
- present F_ORDER_PLATFORM in get_features
- remove endian check since ENI always use litter endian

Changes since V2:
- add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE instead VDPA_ATTR_DEV_F_VERSION_1 to guide users to choose correct virtqueue size as suggested by Jason Wang
- present ACCESS_PLATFORM in get_features callback as suggested by Jason Wang
- disable this driver on Big Endian host as suggested by Jason Wang
- fix a typo

Changes since V1:
- add new vdpa attribute VDPA_ATTR_DEV_F_VERSION_1 to indicate whether the vdpa device is legacy
- implement dedicated driver for Alibaba ENI instead a legacy virtio-pci driver as suggested by Jason Wang
- some bugs fixed

Wu Zongyong (9):
virtio-pci: introduce legacy device module
vdpa: fix typo
vp_vdpa: add vq irq offloading support
vdpa: add new callback get_vq_num_min in vdpa_config_ops
vdpa: min vq num of vdpa device cannot be greater than max vq num
virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}
vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE
eni_vdpa: add vDPA driver for Alibaba ENI
eni_vdpa: alibaba: fix Kconfig typo

 drivers/vdpa/Kconfig                   |   8 +
 drivers/vdpa/Makefile                  |   1 +
 drivers/vdpa/alibaba/Makefile          |   3 +
 drivers/vdpa/alibaba/eni_vdpa.c        | 553 +++++++++++++++++++++++++
 drivers/vdpa/vdpa.c                    |  13 +
 drivers/vdpa/virtio_pci/vp_vdpa.c      |  12 +
 drivers/virtio/Kconfig                 |  10 +
 drivers/virtio/Makefile                |   1 +
 drivers/virtio/virtio_pci_common.c     |  10 +-
 drivers/virtio/virtio_pci_common.h     |   9 +-
 drivers/virtio/virtio_pci_legacy.c     | 101 ++---
 drivers/virtio/virtio_pci_legacy_dev.c | 220 ++++++++++
 drivers/virtio/virtio_vdpa.c           |  16 +-
 include/linux/vdpa.h                   |   6 +-
 include/linux/virtio_pci_legacy.h      |  42 ++
 include/uapi/linux/vdpa.h              |   1 +
 16 files changed, 917 insertions(+), 89 deletions(-)
 create mode 100644 drivers/vdpa/alibaba/Makefile
 create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
 create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c
 create mode 100644 include/linux/virtio_pci_legacy.h

--
2.31.1

#152 lore raw

Re: [PATCH v7 0/9] vDPA driver for Alibaba ENI

In reply to Wu Zongyong
Quoted 2 lines · Wu Zongyong

This series implements the vDPA driver for Alibaba ENI (Elastic Network Interface) which is built based on virtio-pci 0.9.5 specification.

In the future pls do not send v7 as a reply to v6. Start a new thread with each version.

Quoted 58 lines

Changes since V6:
- set default min vq size to 1 intead of 0
- enable eni vdpa driver only on X86 hosts
- fix some typos

Changes since V5:
- remove unused codes

Changes since V4:
- check return values of get_vq_num_{max,min} when probing devices
- disable the driver on BE host via Kconfig
- add missing commit message

Changes since V3:
- validate VIRTIO_NET_F_MRG_RXBUF when negotiate features
- present F_ORDER_PLATFORM in get_features
- remove endian check since ENI always use litter endian

Changes since V2:
- add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE instead VDPA_ATTR_DEV_F_VERSION_1 to guide users to choose correct virtqueue size as suggested by Jason Wang
- present ACCESS_PLATFORM in get_features callback as suggested by Jason Wang
- disable this driver on Big Endian host as suggested by Jason Wang
- fix a typo

Changes since V1:
- add new vdpa attribute VDPA_ATTR_DEV_F_VERSION_1 to indicate whether the vdpa device is legacy
- implement dedicated driver for Alibaba ENI instead a legacy virtio-pci driver as suggested by Jason Wang
- some bugs fixed

Wu Zongyong (9):
virtio-pci: introduce legacy device module
vdpa: fix typo
vp_vdpa: add vq irq offloading support
vdpa: add new callback get_vq_num_min in vdpa_config_ops
vdpa: min vq num of vdpa device cannot be greater than max vq num
virtio_vdpa: setup correct vq size with callbacks get_vq_num_{max,min}
vdpa: add new attribute VDPA_ATTR_DEV_MIN_VQ_SIZE
eni_vdpa: add vDPA driver for Alibaba ENI
eni_vdpa: alibaba: fix Kconfig typo

 drivers/vdpa/Kconfig                   |   8 +
 drivers/vdpa/Makefile                  |   1 +
 drivers/vdpa/alibaba/Makefile          |   3 +
 drivers/vdpa/alibaba/eni_vdpa.c        | 553 +++++++++++++++++++++++++
 drivers/vdpa/vdpa.c                    |  13 +
 drivers/vdpa/virtio_pci/vp_vdpa.c      |  12 +
 drivers/virtio/Kconfig                 |  10 +
 drivers/virtio/Makefile                |   1 +
 drivers/virtio/virtio_pci_common.c     |  10 +-
 drivers/virtio/virtio_pci_common.h     |   9 +-
 drivers/virtio/virtio_pci_legacy.c     | 101 ++---
 drivers/virtio/virtio_pci_legacy_dev.c | 220 ++++++++++
 drivers/virtio/virtio_vdpa.c           |  16 +-
Quoted 11 lines
 include/linux/vdpa.h                   |   6 +-
 include/linux/virtio_pci_legacy.h      |  42 ++
 include/uapi/linux/vdpa.h              |   1 +
 16 files changed, 917 insertions(+), 89 deletions(-)
 create mode 100644 drivers/vdpa/alibaba/Makefile
 create mode 100644 drivers/vdpa/alibaba/eni_vdpa.c
 create mode 100644 drivers/virtio/virtio_pci_legacy_dev.c
 create mode 100644 include/linux/virtio_pci_legacy.h
Signature · 1 line
2.31.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization