[dpdk-dev,v4,10/23] virtio: Add vtpci_intr_handle() helper to get rte_intr_handle

Message ID 1482332986-7599-11-git-send-email-jblunck@infradead.org (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel compilation fail Compilation issues

Commit Message

Jan Blunck Dec. 21, 2016, 3:09 p.m. UTC
  This adds a helper to get the rte_intr_handle from the virtio_hw. This is
safe to do since the usage of the helper is guarded by RTE_ETH_DEV_INTR_LSC
which is only set if we found a PCI device during initialization.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 drivers/net/virtio/virtio_ethdev.c | 12 +++++++-----
 drivers/net/virtio/virtio_pci.h    |  6 ++++++
 2 files changed, 13 insertions(+), 5 deletions(-)
  

Comments

Stephen Hemminger Dec. 21, 2016, 8:08 p.m. UTC | #1
On Wed, 21 Dec 2016 16:09:33 +0100
Jan Blunck <jblunck@infradead.org> wrote:

> This adds a helper to get the rte_intr_handle from the virtio_hw. This is
> safe to do since the usage of the helper is guarded by RTE_ETH_DEV_INTR_LSC
> which is only set if we found a PCI device during initialization.
> 
> Signed-off-by: Jan Blunck <jblunck@infradead.org>
> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
> ---
>  drivers/net/virtio/virtio_ethdev.c | 12 +++++++-----
>  drivers/net/virtio/virtio_pci.h    |  6 ++++++
>  2 files changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
> index 741688e..da9668e 100644
> --- a/drivers/net/virtio/virtio_ethdev.c
> +++ b/drivers/net/virtio/virtio_ethdev.c
> @@ -1162,7 +1162,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 (rte_intr_enable(vtpci_intr_handle(hw)) < 0)
>  		PMD_DRV_LOG(ERR, "interrupt enable failed");
>  
>  	if (isr & VIRTIO_PCI_ISR_CONFIG) {

Since intr_handle is already an argument to interrupt handler, why not use it?
That is what I did in the Intel driver changes.
  
Jan Blunck Dec. 23, 2016, 11:04 a.m. UTC | #2
On Wed, Dec 21, 2016 at 9:08 PM, Stephen Hemminger
<stephen@networkplumber.org> wrote:
> On Wed, 21 Dec 2016 16:09:33 +0100
> Jan Blunck <jblunck@infradead.org> wrote:
>
>> This adds a helper to get the rte_intr_handle from the virtio_hw. This is
>> safe to do since the usage of the helper is guarded by RTE_ETH_DEV_INTR_LSC
>> which is only set if we found a PCI device during initialization.
>>
>> Signed-off-by: Jan Blunck <jblunck@infradead.org>
>> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>> ---
>>  drivers/net/virtio/virtio_ethdev.c | 12 +++++++-----
>>  drivers/net/virtio/virtio_pci.h    |  6 ++++++
>>  2 files changed, 13 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
>> index 741688e..da9668e 100644
>> --- a/drivers/net/virtio/virtio_ethdev.c
>> +++ b/drivers/net/virtio/virtio_ethdev.c
>> @@ -1162,7 +1162,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 (rte_intr_enable(vtpci_intr_handle(hw)) < 0)
>>               PMD_DRV_LOG(ERR, "interrupt enable failed");
>>
>>       if (isr & VIRTIO_PCI_ISR_CONFIG) {
>
> Since intr_handle is already an argument to interrupt handler, why not use it?
> That is what I did in the Intel driver changes.

Thanks for the review. I'll fix this for v5.
  

Patch

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 741688e..da9668e 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1162,7 +1162,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 (rte_intr_enable(vtpci_intr_handle(hw)) < 0)
 		PMD_DRV_LOG(ERR, "interrupt enable failed");
 
 	if (isr & VIRTIO_PCI_ISR_CONFIG) {
@@ -1334,7 +1334,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,
+		rte_intr_callback_register(vtpci_intr_handle(hw),
 			virtio_interrupt_handler, eth_dev);
 
 	return 0;
@@ -1344,6 +1344,7 @@  static int
 eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
 {
 	struct rte_pci_device *pci_dev;
+	struct virtio_hw *hw = eth_dev->data->dev_private;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -1363,7 +1364,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,
+		rte_intr_callback_unregister(vtpci_intr_handle(hw),
 						virtio_interrupt_handler,
 						eth_dev);
 	rte_eal_pci_unmap_device(pci_dev);
@@ -1481,7 +1482,7 @@  virtio_dev_start(struct rte_eth_dev *dev)
 			return -ENOTSUP;
 		}
 
-		if (rte_intr_enable(&dev->pci_dev->intr_handle) < 0) {
+		if (rte_intr_enable(vtpci_intr_handle(hw)) < 0) {
 			PMD_DRV_LOG(ERR, "interrupt enable failed");
 			return -EIO;
 		}
@@ -1573,12 +1574,13 @@  static void virtio_dev_free_mbufs(struct rte_eth_dev *dev)
 static void
 virtio_dev_stop(struct rte_eth_dev *dev)
 {
+	struct virtio_hw *hw = dev->data->dev_private;
 	struct rte_eth_link link;
 
 	PMD_INIT_LOG(DEBUG, "stop");
 
 	if (dev->data->dev_conf.intr_conf.lsc)
-		rte_intr_disable(&dev->pci_dev->intr_handle);
+		rte_intr_disable(vtpci_intr_handle(hw));
 
 	memset(&link, 0, sizeof(link));
 	virtio_dev_atomic_write_link_status(dev, &link);
diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h
index de271bf..5373e39 100644
--- a/drivers/net/virtio/virtio_pci.h
+++ b/drivers/net/virtio/virtio_pci.h
@@ -317,4 +317,10 @@  uint8_t vtpci_isr(struct virtio_hw *);
 
 uint16_t vtpci_irq_config(struct virtio_hw *, uint16_t);
 
+static inline struct rte_intr_handle *
+vtpci_intr_handle(struct virtio_hw *hw)
+{
+	return hw->dev ? &hw->dev->intr_handle : NULL;
+}
+
 #endif /* _VIRTIO_PCI_H_ */