[dpdk-dev] [PATCH v1 1/2] virtio: Handle interrupt things under vtpci abstraction

Tetsuya Mukawa mukawa at igel.co.jp
Thu Jun 2 05:30:22 CEST 2016


So far, interrupts from PCI devices are handled in virtio_ethdev
directly. The patch changes it, and try to handle it under vtpci
abstraction. The patch is needed because virtio-qtest needs to handle
interrupts from virtual pci devices.

Signed-off-by: Tetsuya Mukawa <mukawa at igel.co.jp>
---
 drivers/net/virtio/virtio_ethdev.c | 10 ++---
 drivers/net/virtio/virtio_pci.c    | 86 ++++++++++++++++++++++++++------------
 drivers/net/virtio/virtio_pci.h    |  7 ++++
 3 files changed, 72 insertions(+), 31 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index c35d1c0..8b5fb66 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1011,7 +1011,7 @@ virtio_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
 	isr = vtpci_isr(hw);
 	PMD_DRV_LOG(INFO, "interrupt status = %#x", isr);
 
-	if (rte_intr_enable(&dev->pci_dev->intr_handle) < 0)
+	if (hw->vtpci_ops->intr_enable(hw) < 0)
 		PMD_DRV_LOG(ERR, "interrupt enable failed");
 
 	if (isr & VIRTIO_PCI_ISR_CONFIG) {
@@ -1170,7 +1170,7 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 
 	/* Setup interrupt callback  */
 	if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
-		rte_intr_callback_register(&pci_dev->intr_handle,
+		hw->vtpci_ops->intr_cb_register(hw,
 				   virtio_interrupt_handler, eth_dev);
 
 	virtio_dev_cq_start(eth_dev);
@@ -1205,7 +1205,7 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
 
 	/* reset interrupt callback  */
 	if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
-		rte_intr_callback_unregister(&pci_dev->intr_handle,
+		hw->vtpci_ops->intr_cb_unregister(hw,
 						virtio_interrupt_handler,
 						eth_dev);
 	rte_eal_pci_unmap_device(pci_dev);
@@ -1294,7 +1294,7 @@ virtio_dev_start(struct rte_eth_dev *dev)
 			return -ENOTSUP;
 		}
 
-		if (rte_intr_enable(&dev->pci_dev->intr_handle) < 0) {
+		if (hw->vtpci_ops->intr_enable(hw) < 0) {
 			PMD_DRV_LOG(ERR, "interrupt enable failed");
 			return -EIO;
 		}
@@ -1398,7 +1398,7 @@ virtio_dev_stop(struct rte_eth_dev *dev)
 	hw->started = 0;
 
 	if (dev->data->dev_conf.intr_conf.lsc)
-		rte_intr_disable(&dev->pci_dev->intr_handle);
+		hw->vtpci_ops->intr_disable(hw);
 
 	memset(&link, 0, sizeof(link));
 	virtio_dev_atomic_write_link_status(dev, &link);
diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c
index 6bd239c..acbc9b1 100644
--- a/drivers/net/virtio/virtio_pci.c
+++ b/drivers/net/virtio/virtio_pci.c
@@ -71,6 +71,32 @@ check_vq_phys_addr_ok(struct virtqueue *vq)
 	return 1;
 }
 
+static int
+intr_cb_register(struct virtio_hw *hw,
+			rte_intr_callback_fn cb, void *cb_arg)
+{
+	return rte_intr_callback_register(&hw->dev->intr_handle, cb, cb_arg);
+}
+
+static int
+intr_cb_unregister(struct virtio_hw *hw,
+			rte_intr_callback_fn cb, void *cb_arg)
+{
+	return rte_intr_callback_register(&hw->dev->intr_handle, cb, cb_arg);
+}
+
+static int
+intr_enable(struct virtio_hw *hw)
+{
+	return rte_intr_enable(&hw->dev->intr_handle);
+}
+
+static int
+intr_disable(struct virtio_hw *hw)
+{
+	return rte_intr_disable(&hw->dev->intr_handle);
+}
+
 static void
 legacy_read_dev_config(struct virtio_hw *hw, size_t offset,
 		       void *dst, int length)
@@ -234,19 +260,23 @@ legacy_virtio_resource_init(struct rte_pci_device *pci_dev,
 }
 
 static const struct virtio_pci_ops legacy_ops = {
-	.read_dev_cfg	= legacy_read_dev_config,
-	.write_dev_cfg	= legacy_write_dev_config,
-	.reset		= legacy_reset,
-	.get_status	= legacy_get_status,
-	.set_status	= legacy_set_status,
-	.get_features	= legacy_get_features,
-	.set_features	= legacy_set_features,
-	.get_isr	= legacy_get_isr,
-	.set_config_irq	= legacy_set_config_irq,
-	.get_queue_num	= legacy_get_queue_num,
-	.setup_queue	= legacy_setup_queue,
-	.del_queue	= legacy_del_queue,
-	.notify_queue	= legacy_notify_queue,
+	.read_dev_cfg		= legacy_read_dev_config,
+	.write_dev_cfg		= legacy_write_dev_config,
+	.reset			= legacy_reset,
+	.get_status		= legacy_get_status,
+	.set_status		= legacy_set_status,
+	.get_features		= legacy_get_features,
+	.set_features		= legacy_set_features,
+	.get_isr		= legacy_get_isr,
+	.set_config_irq		= legacy_set_config_irq,
+	.get_queue_num		= legacy_get_queue_num,
+	.setup_queue		= legacy_setup_queue,
+	.del_queue		= legacy_del_queue,
+	.notify_queue		= legacy_notify_queue,
+	.intr_cb_register	= intr_cb_register,
+	.intr_cb_unregister	= intr_cb_unregister,
+	.intr_enable		= intr_enable,
+	.intr_disable		= intr_disable,
 };
 
 
@@ -450,19 +480,23 @@ modern_notify_queue(struct virtio_hw *hw __rte_unused, struct virtqueue *vq)
 }
 
 static const struct virtio_pci_ops modern_ops = {
-	.read_dev_cfg	= modern_read_dev_config,
-	.write_dev_cfg	= modern_write_dev_config,
-	.reset		= modern_reset,
-	.get_status	= modern_get_status,
-	.set_status	= modern_set_status,
-	.get_features	= modern_get_features,
-	.set_features	= modern_set_features,
-	.get_isr	= modern_get_isr,
-	.set_config_irq	= modern_set_config_irq,
-	.get_queue_num	= modern_get_queue_num,
-	.setup_queue	= modern_setup_queue,
-	.del_queue	= modern_del_queue,
-	.notify_queue	= modern_notify_queue,
+	.read_dev_cfg		= modern_read_dev_config,
+	.write_dev_cfg		= modern_write_dev_config,
+	.reset			= modern_reset,
+	.get_status		= modern_get_status,
+	.set_status		= modern_set_status,
+	.get_features		= modern_get_features,
+	.set_features		= modern_set_features,
+	.get_isr		= modern_get_isr,
+	.set_config_irq		= modern_set_config_irq,
+	.get_queue_num		= modern_get_queue_num,
+	.setup_queue		= modern_setup_queue,
+	.del_queue		= modern_del_queue,
+	.notify_queue		= modern_notify_queue,
+	.intr_cb_register	= intr_cb_register,
+	.intr_cb_unregister	= intr_cb_unregister,
+	.intr_enable		= intr_enable,
+	.intr_disable		= intr_disable,
 };
 
 
diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h
index d10d013..a74aa02 100644
--- a/drivers/net/virtio/virtio_pci.h
+++ b/drivers/net/virtio/virtio_pci.h
@@ -237,6 +237,13 @@ struct virtio_pci_ops {
 	int (*setup_queue)(struct virtio_hw *hw, struct virtqueue *vq);
 	void (*del_queue)(struct virtio_hw *hw, struct virtqueue *vq);
 	void (*notify_queue)(struct virtio_hw *hw, struct virtqueue *vq);
+
+	int (*intr_cb_register)(struct virtio_hw *hw,
+			rte_intr_callback_fn cb, void *cb_arg);
+	int (*intr_cb_unregister)(struct virtio_hw *hw,
+			rte_intr_callback_fn cb, void *cb_arg);
+	int (*intr_enable)(struct virtio_hw *hw);
+	int (*intr_disable)(struct virtio_hw *hw);
 };
 
 struct virtio_net_config;
-- 
2.7.4



More information about the dev mailing list