All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 00/23] Decouple ethdev from PCI device
@ 2016-12-21 15:09 Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 01/23] eal: define container_of macro Jan Blunck
                   ` (44 more replies)
  0 siblings, 45 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

This is a partial merge of Stephens and my patches to make the rte_eth_dev
independent of the rte_pci_device.

Changes between v4 and v3:
 - broken out refactorings of drivers similar to Stephens example
 - use inline function instead of macro
 - fix build issues with bnx2x and mlx4/5

Changes between v3 and v2:
 - converted PCI device users I've missed in previous version

Jan Blunck (17):
  eal: define container_of macro
  eal: Allow passing const rte_intr_handle
  virtio: Don't fill dev_info->driver_name
  virtio: Add vtpci_intr_handle() helper to get rte_intr_handle
  virtio: Don't depend on struct rte_eth_dev's pci_dev
  bnx2x: localize mapping from eth_dev to pci
  fm10k: localize mapping from eth_dev to pci
  qede: localize mapping of eth_dev to pci
  szedata2: localize handling of pci resources
  nfp: localize rte_pci_device handling
  vmxnet3: use eth_dev->data->drv_name instead of pci_drv name
  ethdev: Helper to map to struct rte_pci_device
  drivers: Replace per-PMD macros with rte_eth_dev_to_pci() helper
  drivers: Use rte_eth_dev_to_pci() helper
  ethdev: Move filling of rte_eth_dev_info->pci_dev to dev_infos_get()
  ethdev: Decouple interrupt handling from PCI device
  ethdev: Decouple struct rte_eth_dev from struct rte_pci_device

Stephen Hemminger (6):
  rte_device: make driver pointer const
  pmd: remove useless reset of dev_info->dev_pci
  e1000: localize mapping from eth_dev to pci
  ixgbe: localize mapping from eth_dev to pci_device
  i40e: localize mapping of eth_dev to pci
  broadcom: localize mapping from eth_dev to pci

 app/test/virtual_pmd.c                         |   5 +-
 drivers/net/af_packet/rte_eth_af_packet.c      |   1 -
 drivers/net/bnx2x/bnx2x_ethdev.c               |  15 +--
 drivers/net/bnxt/bnxt_ethdev.c                 |  24 +++--
 drivers/net/bnxt/bnxt_ring.c                   |  16 ++--
 drivers/net/bonding/rte_eth_bond_args.c        |  12 ++-
 drivers/net/bonding/rte_eth_bond_pmd.c         |   1 -
 drivers/net/cxgbe/cxgbe_ethdev.c               |   4 +-
 drivers/net/cxgbe/cxgbe_main.c                 |   4 +-
 drivers/net/e1000/em_ethdev.c                  |  50 +++++-----
 drivers/net/e1000/igb_ethdev.c                 | 100 +++++++++++---------
 drivers/net/e1000/igb_pf.c                     |   4 +-
 drivers/net/ena/ena_ethdev.c                   |   4 +-
 drivers/net/enic/enic_ethdev.c                 |   3 +-
 drivers/net/fm10k/fm10k_ethdev.c               |  84 +++++++++--------
 drivers/net/i40e/i40e_ethdev.c                 |  78 ++++++++++------
 drivers/net/i40e/i40e_ethdev_vf.c              |  59 +++++++-----
 drivers/net/ixgbe/ixgbe_ethdev.c               | 122 ++++++++++++++-----------
 drivers/net/ixgbe/ixgbe_pf.c                   |   4 +-
 drivers/net/mlx4/mlx4.c                        |   4 +-
 drivers/net/mlx5/mlx5.c                        |   2 +-
 drivers/net/mlx5/mlx5_ethdev.c                 |   2 +
 drivers/net/nfp/nfp_net.c                      |  19 ++--
 drivers/net/null/rte_eth_null.c                |   1 -
 drivers/net/pcap/rte_eth_pcap.c                |   1 -
 drivers/net/qede/qede_ethdev.c                 |  19 ++--
 drivers/net/ring/rte_eth_ring.c                |   1 -
 drivers/net/szedata2/rte_eth_szedata2.c        |  73 +++++++++------
 drivers/net/szedata2/rte_eth_szedata2.h        |  58 +++++-------
 drivers/net/thunderx/nicvf_ethdev.c            |   7 +-
 drivers/net/virtio/virtio_ethdev.c             |  41 ++++-----
 drivers/net/virtio/virtio_pci.h                |   6 ++
 drivers/net/virtio/virtio_user_ethdev.c        |   1 -
 drivers/net/vmxnet3/vmxnet3_ethdev.c           |   8 +-
 drivers/net/xenvirt/rte_eth_xenvirt.c          |   1 -
 lib/librte_eal/common/include/rte_common.h     |  20 ++++
 lib/librte_eal/common/include/rte_dev.h        |   2 +-
 lib/librte_eal/common/include/rte_interrupts.h |   8 +-
 lib/librte_eal/common/include/rte_pci.h        |   6 ++
 lib/librte_eal/linuxapp/eal/eal_interrupts.c   |  62 +++++++++----
 lib/librte_ether/rte_ethdev.c                  |  25 +++--
 lib/librte_ether/rte_ethdev.h                  |  13 ++-
 42 files changed, 577 insertions(+), 393 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 81+ messages in thread

* [PATCH v4 01/23] eal: define container_of macro
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 02/23] eal: Allow passing const rte_intr_handle Jan Blunck
                   ` (43 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen, Jan Viktorin

This macro is based on Jan Viktorin's original patch but also checks the
type of the passed pointer against the type of the member.

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
[jblunck@infradead.org: add type checking and __extension__]
Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/include/rte_common.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index db5ac91..8dda3e2 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -331,6 +331,26 @@ rte_bsf32(uint32_t v)
 #define offsetof(TYPE, MEMBER)  __builtin_offsetof (TYPE, MEMBER)
 #endif
 
+/**
+ * Return pointer to the wrapping struct instance.
+ *
+ * Example:
+ *
+ *  struct wrapper {
+ *      ...
+ *      struct child c;
+ *      ...
+ *  };
+ *
+ *  struct child *x = obtain(...);
+ *  struct wrapper *w = container_of(x, struct wrapper, c);
+ */
+#ifndef container_of
+#define container_of(ptr, type, member)	__extension__ ({		\
+			typeof(((type *)0)->member) *_ptr = (ptr);	\
+			(type *)(((char *)_ptr) - offsetof(type, member)); })
+#endif
+
 #define _RTE_STR(x) #x
 /** Take a macro value and get a string version of it */
 #define RTE_STR(x) _RTE_STR(x)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 02/23] eal: Allow passing const rte_intr_handle
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 01/23] eal: define container_of macro Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 03/23] rte_device: make driver pointer const Jan Blunck
                   ` (42 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

Both register/unregister and enable/disable don't necessarily require the
rte_intr_handle to be modifiable. Therefore lets constify it.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/include/rte_interrupts.h |  8 ++--
 lib/librte_eal/linuxapp/eal/eal_interrupts.c   | 62 ++++++++++++++++++--------
 2 files changed, 47 insertions(+), 23 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_interrupts.h b/lib/librte_eal/common/include/rte_interrupts.h
index fd3c6ef..6cade01 100644
--- a/lib/librte_eal/common/include/rte_interrupts.h
+++ b/lib/librte_eal/common/include/rte_interrupts.h
@@ -70,7 +70,7 @@ typedef void (*rte_intr_callback_fn)(struct rte_intr_handle *intr_handle,
  *  - On success, zero.
  *  - On failure, a negative value.
  */
-int rte_intr_callback_register(struct rte_intr_handle *intr_handle,
+int rte_intr_callback_register(const struct rte_intr_handle *intr_handle,
 				rte_intr_callback_fn cb, void *cb_arg);
 
 /**
@@ -88,7 +88,7 @@ int rte_intr_callback_register(struct rte_intr_handle *intr_handle,
  *  - On success, return the number of callback entities removed.
  *  - On failure, a negative value.
  */
-int rte_intr_callback_unregister(struct rte_intr_handle *intr_handle,
+int rte_intr_callback_unregister(const struct rte_intr_handle *intr_handle,
 				rte_intr_callback_fn cb, void *cb_arg);
 
 /**
@@ -101,7 +101,7 @@ int rte_intr_callback_unregister(struct rte_intr_handle *intr_handle,
  *  - On success, zero.
  *  - On failure, a negative value.
  */
-int rte_intr_enable(struct rte_intr_handle *intr_handle);
+int rte_intr_enable(const struct rte_intr_handle *intr_handle);
 
 /**
  * It disables the interrupt for the specified handle.
@@ -113,7 +113,7 @@ int rte_intr_enable(struct rte_intr_handle *intr_handle);
  *  - On success, zero.
  *  - On failure, a negative value.
  */
-int rte_intr_disable(struct rte_intr_handle *intr_handle);
+int rte_intr_disable(const struct rte_intr_handle *intr_handle);
 
 #ifdef __cplusplus
 }
diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
index 47a3b20..cb55751 100644
--- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c
+++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
@@ -136,7 +136,7 @@ static pthread_t intr_thread;
 
 /* enable legacy (INTx) interrupts */
 static int
-vfio_enable_intx(struct rte_intr_handle *intr_handle) {
+vfio_enable_intx(const struct rte_intr_handle *intr_handle) {
 	struct vfio_irq_set *irq_set;
 	char irq_set_buf[IRQ_SET_BUF_LEN];
 	int len, ret;
@@ -183,7 +183,7 @@ vfio_enable_intx(struct rte_intr_handle *intr_handle) {
 
 /* disable legacy (INTx) interrupts */
 static int
-vfio_disable_intx(struct rte_intr_handle *intr_handle) {
+vfio_disable_intx(const struct rte_intr_handle *intr_handle) {
 	struct vfio_irq_set *irq_set;
 	char irq_set_buf[IRQ_SET_BUF_LEN];
 	int len, ret;
@@ -226,7 +226,7 @@ vfio_disable_intx(struct rte_intr_handle *intr_handle) {
 
 /* enable MSI interrupts */
 static int
-vfio_enable_msi(struct rte_intr_handle *intr_handle) {
+vfio_enable_msi(const struct rte_intr_handle *intr_handle) {
 	int len, ret;
 	char irq_set_buf[IRQ_SET_BUF_LEN];
 	struct vfio_irq_set *irq_set;
@@ -255,7 +255,7 @@ vfio_enable_msi(struct rte_intr_handle *intr_handle) {
 
 /* disable MSI interrupts */
 static int
-vfio_disable_msi(struct rte_intr_handle *intr_handle) {
+vfio_disable_msi(const struct rte_intr_handle *intr_handle) {
 	struct vfio_irq_set *irq_set;
 	char irq_set_buf[IRQ_SET_BUF_LEN];
 	int len, ret;
@@ -278,9 +278,30 @@ vfio_disable_msi(struct rte_intr_handle *intr_handle) {
 	return ret;
 }
 
+static int
+get_max_intr(const struct rte_intr_handle *intr_handle)
+{
+	struct rte_intr_source *src;
+
+	TAILQ_FOREACH(src, &intr_sources, next) {
+		if (src->intr_handle.fd != intr_handle->fd)
+			continue;
+
+		if (!src->intr_handle.max_intr)
+			src->intr_handle.max_intr = 1;
+		else if (src->intr_handle.max_intr > RTE_MAX_RXTX_INTR_VEC_ID)
+			src->intr_handle.max_intr
+				= RTE_MAX_RXTX_INTR_VEC_ID + 1;
+
+		return src->intr_handle.max_intr;
+	}
+
+	return -1;
+}
+
 /* enable MSI-X interrupts */
 static int
-vfio_enable_msix(struct rte_intr_handle *intr_handle) {
+vfio_enable_msix(const struct rte_intr_handle *intr_handle) {
 	int len, ret;
 	char irq_set_buf[MSIX_IRQ_SET_BUF_LEN];
 	struct vfio_irq_set *irq_set;
@@ -290,12 +311,15 @@ vfio_enable_msix(struct rte_intr_handle *intr_handle) {
 
 	irq_set = (struct vfio_irq_set *) irq_set_buf;
 	irq_set->argsz = len;
-	if (!intr_handle->max_intr)
-		intr_handle->max_intr = 1;
-	else if (intr_handle->max_intr > RTE_MAX_RXTX_INTR_VEC_ID)
-		intr_handle->max_intr = RTE_MAX_RXTX_INTR_VEC_ID + 1;
 
-	irq_set->count = intr_handle->max_intr;
+	ret = get_max_intr(intr_handle);
+	if (ret < 0) {
+		RTE_LOG(ERR, EAL, "Invalid number of MSI-X irqs for fd %d\n",
+			intr_handle->fd);
+		return -1;
+	}
+
+	irq_set->count = ret;
 	irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER;
 	irq_set->index = VFIO_PCI_MSIX_IRQ_INDEX;
 	irq_set->start = 0;
@@ -318,7 +342,7 @@ vfio_enable_msix(struct rte_intr_handle *intr_handle) {
 
 /* disable MSI-X interrupts */
 static int
-vfio_disable_msix(struct rte_intr_handle *intr_handle) {
+vfio_disable_msix(const struct rte_intr_handle *intr_handle) {
 	struct vfio_irq_set *irq_set;
 	char irq_set_buf[MSIX_IRQ_SET_BUF_LEN];
 	int len, ret;
@@ -343,7 +367,7 @@ vfio_disable_msix(struct rte_intr_handle *intr_handle) {
 #endif
 
 static int
-uio_intx_intr_disable(struct rte_intr_handle *intr_handle)
+uio_intx_intr_disable(const struct rte_intr_handle *intr_handle)
 {
 	unsigned char command_high;
 
@@ -367,7 +391,7 @@ uio_intx_intr_disable(struct rte_intr_handle *intr_handle)
 }
 
 static int
-uio_intx_intr_enable(struct rte_intr_handle *intr_handle)
+uio_intx_intr_enable(const struct rte_intr_handle *intr_handle)
 {
 	unsigned char command_high;
 
@@ -391,7 +415,7 @@ uio_intx_intr_enable(struct rte_intr_handle *intr_handle)
 }
 
 static int
-uio_intr_disable(struct rte_intr_handle *intr_handle)
+uio_intr_disable(const struct rte_intr_handle *intr_handle)
 {
 	const int value = 0;
 
@@ -405,7 +429,7 @@ uio_intr_disable(struct rte_intr_handle *intr_handle)
 }
 
 static int
-uio_intr_enable(struct rte_intr_handle *intr_handle)
+uio_intr_enable(const struct rte_intr_handle *intr_handle)
 {
 	const int value = 1;
 
@@ -419,7 +443,7 @@ uio_intr_enable(struct rte_intr_handle *intr_handle)
 }
 
 int
-rte_intr_callback_register(struct rte_intr_handle *intr_handle,
+rte_intr_callback_register(const struct rte_intr_handle *intr_handle,
 			rte_intr_callback_fn cb, void *cb_arg)
 {
 	int ret, wake_thread;
@@ -491,7 +515,7 @@ rte_intr_callback_register(struct rte_intr_handle *intr_handle,
 }
 
 int
-rte_intr_callback_unregister(struct rte_intr_handle *intr_handle,
+rte_intr_callback_unregister(const struct rte_intr_handle *intr_handle,
 			rte_intr_callback_fn cb_fn, void *cb_arg)
 {
 	int ret;
@@ -555,7 +579,7 @@ rte_intr_callback_unregister(struct rte_intr_handle *intr_handle,
 }
 
 int
-rte_intr_enable(struct rte_intr_handle *intr_handle)
+rte_intr_enable(const struct rte_intr_handle *intr_handle)
 {
 	if (!intr_handle || intr_handle->fd < 0 || intr_handle->uio_cfg_fd < 0)
 		return -1;
@@ -599,7 +623,7 @@ rte_intr_enable(struct rte_intr_handle *intr_handle)
 }
 
 int
-rte_intr_disable(struct rte_intr_handle *intr_handle)
+rte_intr_disable(const struct rte_intr_handle *intr_handle)
 {
 	if (!intr_handle || intr_handle->fd < 0 || intr_handle->uio_cfg_fd < 0)
 		return -1;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 03/23] rte_device: make driver pointer const
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 01/23] eal: define container_of macro Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 02/23] eal: Allow passing const rte_intr_handle Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-22  7:18   ` Shreyansh Jain
  2016-12-21 15:09 ` [PATCH v4 04/23] pmd: remove useless reset of dev_info->dev_pci Jan Blunck
                   ` (41 subsequent siblings)
  44 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, shreyansh.jain, david.marchand

From: Stephen Hemminger <stephen@networkplumber.org>

The info in rte_device about driver is immutable and
shouldn't change.
Acked-by: Jan Blunck <jblunck@infradead.org>

Acked-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/include/rte_dev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index 8840380..e5471a2 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -122,7 +122,7 @@ struct rte_driver;
  */
 struct rte_device {
 	TAILQ_ENTRY(rte_device) next; /**< Next device */
-	struct rte_driver *driver;    /**< Associated driver */
+	const struct rte_driver *driver;/**< Associated driver */
 	int numa_node;                /**< NUMA node connection */
 	struct rte_devargs *devargs;  /**< Device user arguments */
 };
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 04/23] pmd: remove useless reset of dev_info->dev_pci
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (2 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 03/23] rte_device: make driver pointer const Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 05/23] e1000: localize mapping from eth_dev to pci Jan Blunck
                   ` (40 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, shreyansh.jain, david.marchand, Stephen Hemminger

From: Stephen Hemminger <stephen@networkplumber.org>

Since rte_eth_dev_info_get does memset() on dev_info before
calling device specific code, the explicit assignment of NULL
in all these virtual drivers has no effect.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
Acked-by: Jan Blunck <jblunck@infradead.org>
---
 app/test/virtual_pmd.c                    | 1 -
 drivers/net/af_packet/rte_eth_af_packet.c | 1 -
 drivers/net/bonding/rte_eth_bond_pmd.c    | 1 -
 drivers/net/null/rte_eth_null.c           | 1 -
 drivers/net/pcap/rte_eth_pcap.c           | 1 -
 drivers/net/ring/rte_eth_ring.c           | 1 -
 drivers/net/xenvirt/rte_eth_xenvirt.c     | 1 -
 7 files changed, 7 deletions(-)

diff --git a/app/test/virtual_pmd.c b/app/test/virtual_pmd.c
index 65b44c6..e0447fd 100644
--- a/app/test/virtual_pmd.c
+++ b/app/test/virtual_pmd.c
@@ -117,7 +117,6 @@ virtual_ethdev_info_get(struct rte_eth_dev *dev __rte_unused,
 	dev_info->max_tx_queues = (uint16_t)512;
 
 	dev_info->min_rx_bufsize = 0;
-	dev_info->pci_dev = NULL;
 }
 
 static int
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index ff45068..2951f86 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -287,7 +287,6 @@ eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	dev_info->max_rx_queues = (uint16_t)internals->nb_queues;
 	dev_info->max_tx_queues = (uint16_t)internals->nb_queues;
 	dev_info->min_rx_bufsize = 0;
-	dev_info->pci_dev = NULL;
 }
 
 static void
diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c
index a80b6fa..74af658 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -1675,7 +1675,6 @@ bond_ethdev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	dev_info->max_tx_queues = (uint16_t)512;
 
 	dev_info->min_rx_bufsize = 0;
-	dev_info->pci_dev = NULL;
 
 	dev_info->rx_offload_capa = internals->rx_offload_capa;
 	dev_info->tx_offload_capa = internals->tx_offload_capa;
diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
index 836d982..b4f253a 100644
--- a/drivers/net/null/rte_eth_null.c
+++ b/drivers/net/null/rte_eth_null.c
@@ -301,7 +301,6 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = RTE_DIM(internals->rx_null_queues);
 	dev_info->max_tx_queues = RTE_DIM(internals->tx_null_queues);
 	dev_info->min_rx_bufsize = 0;
-	dev_info->pci_dev = NULL;
 	dev_info->reta_size = internals->reta_size;
 	dev_info->flow_type_rss_offloads = internals->flow_type_rss_offloads;
 }
diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index 0162f44..7253b9a 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -559,7 +559,6 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
-	dev_info->pci_dev = NULL;
 }
 
 static void
diff --git a/drivers/net/ring/rte_eth_ring.c b/drivers/net/ring/rte_eth_ring.c
index c1767c4..dc99a1f 100644
--- a/drivers/net/ring/rte_eth_ring.c
+++ b/drivers/net/ring/rte_eth_ring.c
@@ -179,7 +179,6 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = (uint16_t)internals->max_rx_queues;
 	dev_info->max_tx_queues = (uint16_t)internals->max_tx_queues;
 	dev_info->min_rx_bufsize = 0;
-	dev_info->pci_dev = NULL;
 }
 
 static void
diff --git a/drivers/net/xenvirt/rte_eth_xenvirt.c b/drivers/net/xenvirt/rte_eth_xenvirt.c
index c08a056..609824b 100644
--- a/drivers/net/xenvirt/rte_eth_xenvirt.c
+++ b/drivers/net/xenvirt/rte_eth_xenvirt.c
@@ -337,7 +337,6 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = (uint16_t)1;
 	dev_info->max_tx_queues = (uint16_t)1;
 	dev_info->min_rx_bufsize = 0;
-	dev_info->pci_dev = NULL;
 }
 
 static void
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 05/23] e1000: localize mapping from eth_dev to pci
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (3 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 04/23] pmd: remove useless reset of dev_info->dev_pci Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 06/23] ixgbe: localize mapping from eth_dev to pci_device Jan Blunck
                   ` (39 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, shreyansh.jain, david.marchand

From: Stephen Hemminger <stephen@networkplumber.org>

Create one macro for where PCI device information is extracted
from ethernet device. Makes later changes easier to review, and test.

Acked-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/e1000/e1000_ethdev.h |  2 +
 drivers/net/e1000/em_ethdev.c    | 50 +++++++++++---------
 drivers/net/e1000/igb_ethdev.c   | 99 ++++++++++++++++++++++------------------
 drivers/net/e1000/igb_pf.c       |  4 +-
 4 files changed, 87 insertions(+), 68 deletions(-)

diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h
index 6c25c8d..134f8b9 100644
--- a/drivers/net/e1000/e1000_ethdev.h
+++ b/drivers/net/e1000/e1000_ethdev.h
@@ -286,6 +286,8 @@ struct e1000_adapter {
 #define E1000_DEV_PRIVATE_TO_FILTER_INFO(adapter) \
 	(&((struct e1000_adapter *)adapter)->filter)
 
+#define E1000_DEV_TO_PCI(eth_dev) \
+	(eth_dev->pci_dev)
 /*
  * RX/TX IGB function prototypes
  */
diff --git a/drivers/net/e1000/em_ethdev.c b/drivers/net/e1000/em_ethdev.c
index aee3d34..014e575 100644
--- a/drivers/net/e1000/em_ethdev.c
+++ b/drivers/net/e1000/em_ethdev.c
@@ -83,7 +83,8 @@ static int eth_em_flow_ctrl_set(struct rte_eth_dev *dev,
 static int eth_em_interrupt_setup(struct rte_eth_dev *dev);
 static int eth_em_rxq_interrupt_setup(struct rte_eth_dev *dev);
 static int eth_em_interrupt_get_status(struct rte_eth_dev *dev);
-static int eth_em_interrupt_action(struct rte_eth_dev *dev);
+static int eth_em_interrupt_action(struct rte_eth_dev *dev,
+				   struct rte_intr_handle *handle);
 static void eth_em_interrupt_handler(struct rte_intr_handle *handle,
 							void *param);
 
@@ -287,7 +288,8 @@ eth_em_dev_is_ich8(struct e1000_hw *hw)
 static int
 eth_em_dev_init(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(eth_dev->data->dev_private);
 	struct e1000_hw *hw =
@@ -295,8 +297,6 @@ eth_em_dev_init(struct rte_eth_dev *eth_dev)
 	struct e1000_vfta * shadow_vfta =
 		E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
 
-	pci_dev = eth_dev->pci_dev;
-
 	eth_dev->dev_ops = &eth_em_ops;
 	eth_dev->rx_pkt_burst = (eth_rx_burst_t)&eth_em_recv_pkts;
 	eth_dev->tx_pkt_burst = (eth_tx_burst_t)&eth_em_xmit_pkts;
@@ -351,8 +351,8 @@ eth_em_dev_init(struct rte_eth_dev *eth_dev)
 		     eth_dev->data->port_id, pci_dev->id.vendor_id,
 		     pci_dev->id.device_id);
 
-	rte_intr_callback_register(&(pci_dev->intr_handle),
-		eth_em_interrupt_handler, (void *)eth_dev);
+	rte_intr_callback_register(intr_handle,
+				   eth_em_interrupt_handler, eth_dev);
 
 	return 0;
 }
@@ -360,17 +360,16 @@ eth_em_dev_init(struct rte_eth_dev *eth_dev)
 static int
 eth_em_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(eth_dev->data->dev_private);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	PMD_INIT_FUNC_TRACE();
 
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return -EPERM;
 
-	pci_dev = eth_dev->pci_dev;
-
 	if (adapter->stopped == 0)
 		eth_em_close(eth_dev);
 
@@ -382,9 +381,9 @@ eth_em_dev_uninit(struct rte_eth_dev *eth_dev)
 	eth_dev->data->mac_addrs = NULL;
 
 	/* disable uio intr before callback unregister */
-	rte_intr_disable(&(pci_dev->intr_handle));
-	rte_intr_callback_unregister(&(pci_dev->intr_handle),
-		eth_em_interrupt_handler, (void *)eth_dev);
+	rte_intr_disable(intr_handle);
+	rte_intr_callback_unregister(intr_handle,
+				     eth_em_interrupt_handler, eth_dev);
 
 	return 0;
 }
@@ -556,7 +555,9 @@ eth_em_start(struct rte_eth_dev *dev)
 		E1000_DEV_PRIVATE(dev->data->dev_private);
 	struct e1000_hw *hw =
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev =
+		E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	int ret, mask;
 	uint32_t intr_vector = 0;
 	uint32_t *speeds;
@@ -738,7 +739,8 @@ eth_em_stop(struct rte_eth_dev *dev)
 {
 	struct rte_eth_link link;
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	em_rxq_intr_disable(hw);
 	em_lsc_intr_disable(hw);
@@ -999,9 +1001,11 @@ static int
 eth_em_rx_queue_intr_enable(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id)
 {
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	em_rxq_intr_enable(hw);
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(intr_handle);
 
 	return 0;
 }
@@ -1536,8 +1540,10 @@ eth_em_interrupt_get_status(struct rte_eth_dev *dev)
  *  - On failure, a negative value.
  */
 static int
-eth_em_interrupt_action(struct rte_eth_dev *dev)
+eth_em_interrupt_action(struct rte_eth_dev *dev,
+			struct rte_intr_handle *intr_handle)
 {
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
 	struct e1000_hw *hw =
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct e1000_interrupt *intr =
@@ -1550,7 +1556,7 @@ eth_em_interrupt_action(struct rte_eth_dev *dev)
 		return -1;
 
 	intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
-	rte_intr_enable(&(dev->pci_dev->intr_handle));
+	rte_intr_enable(intr_handle);
 
 	/* set get_link_status to check register later */
 	hw->mac.get_link_status = 1;
@@ -1571,8 +1577,8 @@ eth_em_interrupt_action(struct rte_eth_dev *dev)
 		PMD_INIT_LOG(INFO, " Port %d: Link Down", dev->data->port_id);
 	}
 	PMD_INIT_LOG(DEBUG, "PCI Address: %04d:%02d:%02d:%d",
-		     dev->pci_dev->addr.domain, dev->pci_dev->addr.bus,
-		     dev->pci_dev->addr.devid, dev->pci_dev->addr.function);
+		     pci_dev->addr.domain, pci_dev->addr.bus,
+		     pci_dev->addr.devid, pci_dev->addr.function);
 
 	tctl = E1000_READ_REG(hw, E1000_TCTL);
 	rctl = E1000_READ_REG(hw, E1000_RCTL);
@@ -1604,13 +1610,13 @@ eth_em_interrupt_action(struct rte_eth_dev *dev)
  *  void
  */
 static void
-eth_em_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
-							void *param)
+eth_em_interrupt_handler(struct rte_intr_handle *handle,
+			 void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
 
 	eth_em_interrupt_get_status(dev);
-	eth_em_interrupt_action(dev);
+	eth_em_interrupt_action(dev, handle);
 	_rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
 }
 
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index 2fddf0c..e0115ea 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -132,7 +132,8 @@ static int  eth_igb_flow_ctrl_set(struct rte_eth_dev *dev,
 static int eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev);
 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev);
 static int eth_igb_interrupt_get_status(struct rte_eth_dev *dev);
-static int eth_igb_interrupt_action(struct rte_eth_dev *dev);
+static int eth_igb_interrupt_action(struct rte_eth_dev *dev,
+				    struct rte_intr_handle *handle);
 static void eth_igb_interrupt_handler(struct rte_intr_handle *handle,
 							void *param);
 static int  igb_hardware_init(struct e1000_hw *hw);
@@ -668,15 +669,16 @@ igb_pf_reset_hw(struct e1000_hw *hw)
 }
 
 static void
-igb_identify_hardware(struct rte_eth_dev *dev)
+igb_identify_hardware(struct rte_eth_dev *dev, struct rte_pci_device *pci_dev)
 {
 	struct e1000_hw *hw =
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
-	hw->vendor_id = dev->pci_dev->id.vendor_id;
-	hw->device_id = dev->pci_dev->id.device_id;
-	hw->subsystem_vendor_id = dev->pci_dev->id.subsystem_vendor_id;
-	hw->subsystem_device_id = dev->pci_dev->id.subsystem_device_id;
+
+	hw->vendor_id = pci_dev->id.vendor_id;
+	hw->device_id = pci_dev->id.device_id;
+	hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
+	hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
 
 	e1000_set_mac_type(hw);
 
@@ -743,7 +745,7 @@ static int
 eth_igb_dev_init(struct rte_eth_dev *eth_dev)
 {
 	int error = 0;
-	struct rte_pci_device *pci_dev;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
 	struct e1000_hw *hw =
 		E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
 	struct e1000_vfta * shadow_vfta =
@@ -755,8 +757,6 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
 
 	uint32_t ctrl_ext;
 
-	pci_dev = eth_dev->pci_dev;
-
 	eth_dev->dev_ops = &eth_igb_ops;
 	eth_dev->rx_pkt_burst = &eth_igb_recv_pkts;
 	eth_dev->tx_pkt_burst = &eth_igb_xmit_pkts;
@@ -774,7 +774,7 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
 
 	hw->hw_addr= (void *)pci_dev->mem_resource[0].addr;
 
-	igb_identify_hardware(eth_dev);
+	igb_identify_hardware(eth_dev, pci_dev);
 	if (e1000_setup_init_funcs(hw, FALSE) != E1000_SUCCESS) {
 		error = -EIO;
 		goto err_late;
@@ -908,6 +908,7 @@ static int
 eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
 {
 	struct rte_pci_device *pci_dev;
+	struct rte_intr_handle *intr_handle;
 	struct e1000_hw *hw;
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(eth_dev->data->dev_private);
@@ -918,7 +919,8 @@ eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
 		return -EPERM;
 
 	hw = E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
-	pci_dev = eth_dev->pci_dev;
+	pci_dev = E1000_DEV_TO_PCI(eth_dev);
+	intr_handle = &pci_dev->intr_handle;
 
 	if (adapter->stopped == 0)
 		eth_igb_close(eth_dev);
@@ -937,9 +939,9 @@ eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
 	igb_pf_host_uninit(eth_dev);
 
 	/* disable uio intr before callback unregister */
-	rte_intr_disable(&(pci_dev->intr_handle));
-	rte_intr_callback_unregister(&(pci_dev->intr_handle),
-		eth_igb_interrupt_handler, (void *)eth_dev);
+	rte_intr_disable(intr_handle);
+	rte_intr_callback_unregister(intr_handle,
+				     eth_igb_interrupt_handler, eth_dev);
 
 	return 0;
 }
@@ -951,6 +953,7 @@ static int
 eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
 {
 	struct rte_pci_device *pci_dev;
+	struct rte_intr_handle *intr_handle;
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(eth_dev->data->dev_private);
 	struct e1000_hw *hw =
@@ -973,8 +976,7 @@ eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
 		return 0;
 	}
 
-	pci_dev = eth_dev->pci_dev;
-
+	pci_dev = E1000_DEV_TO_PCI(eth_dev);
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
 	hw->device_id = pci_dev->id.device_id;
@@ -1038,9 +1040,9 @@ eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
 		     eth_dev->data->port_id, pci_dev->id.vendor_id,
 		     pci_dev->id.device_id, "igb_mac_82576_vf");
 
-	rte_intr_callback_register(&pci_dev->intr_handle,
-				   eth_igbvf_interrupt_handler,
-				   (void *)eth_dev);
+	intr_handle = &pci_dev->intr_handle;
+	rte_intr_callback_register(intr_handle,
+				   eth_igbvf_interrupt_handler, eth_dev);
 
 	return 0;
 }
@@ -1050,7 +1052,7 @@ eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
 {
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(eth_dev->data->dev_private);
-	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -1217,7 +1219,8 @@ eth_igb_start(struct rte_eth_dev *dev)
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	int ret, mask;
 	uint32_t intr_vector = 0;
 	uint32_t ctrl_ext;
@@ -1425,11 +1428,12 @@ eth_igb_stop(struct rte_eth_dev *dev)
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct e1000_filter_info *filter_info =
 		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
 	struct rte_eth_link link;
 	struct e1000_flex_filter *p_flex;
 	struct e1000_5tuple_filter *p_5tuple, *p_5tuple_next;
 	struct e1000_2tuple_filter *p_2tuple, *p_2tuple_next;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	igb_intr_disable(hw);
 
@@ -1529,7 +1533,8 @@ eth_igb_close(struct rte_eth_dev *dev)
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(dev->data->dev_private);
 	struct rte_eth_link link;
-	struct rte_pci_device *pci_dev;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	eth_igb_stop(dev);
 	adapter->stopped = 1;
@@ -1549,10 +1554,9 @@ eth_igb_close(struct rte_eth_dev *dev)
 
 	igb_dev_free_queues(dev);
 
-	pci_dev = dev->pci_dev;
-	if (pci_dev->intr_handle.intr_vec) {
-		rte_free(pci_dev->intr_handle.intr_vec);
-		pci_dev->intr_handle.intr_vec = NULL;
+	if (intr_handle->intr_vec) {
+		rte_free(intr_handle->intr_vec);
+		intr_handle->intr_vec = NULL;
 	}
 
 	memset(&link, 0, sizeof(link));
@@ -2633,12 +2637,14 @@ eth_igb_interrupt_get_status(struct rte_eth_dev *dev)
  *  - On failure, a negative value.
  */
 static int
-eth_igb_interrupt_action(struct rte_eth_dev *dev)
+eth_igb_interrupt_action(struct rte_eth_dev *dev,
+			 struct rte_intr_handle *intr_handle)
 {
 	struct e1000_hw *hw =
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct e1000_interrupt *intr =
 		E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
 	uint32_t tctl, rctl;
 	struct rte_eth_link link;
 	int ret;
@@ -2649,7 +2655,7 @@ eth_igb_interrupt_action(struct rte_eth_dev *dev)
 	}
 
 	igb_intr_enable(dev);
-	rte_intr_enable(&(dev->pci_dev->intr_handle));
+	rte_intr_enable(intr_handle);
 
 	if (intr->flags & E1000_FLAG_NEED_LINK_UPDATE) {
 		intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
@@ -2677,10 +2683,10 @@ eth_igb_interrupt_action(struct rte_eth_dev *dev)
 		}
 
 		PMD_INIT_LOG(DEBUG, "PCI Address: %04d:%02d:%02d:%d",
-			     dev->pci_dev->addr.domain,
-			     dev->pci_dev->addr.bus,
-			     dev->pci_dev->addr.devid,
-			     dev->pci_dev->addr.function);
+			     pci_dev->addr.domain,
+			     pci_dev->addr.bus,
+			     pci_dev->addr.devid,
+			     pci_dev->addr.function);
 		tctl = E1000_READ_REG(hw, E1000_TCTL);
 		rctl = E1000_READ_REG(hw, E1000_RCTL);
 		if (link.link_status) {
@@ -2713,13 +2719,12 @@ eth_igb_interrupt_action(struct rte_eth_dev *dev)
  *  void
  */
 static void
-eth_igb_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
-							void *param)
+eth_igb_interrupt_handler(struct rte_intr_handle *handle, void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
 
 	eth_igb_interrupt_get_status(dev);
-	eth_igb_interrupt_action(dev);
+	eth_igb_interrupt_action(dev, handle);
 }
 
 static int
@@ -2759,7 +2764,7 @@ void igbvf_mbx_process(struct rte_eth_dev *dev)
 }
 
 static int
-eth_igbvf_interrupt_action(struct rte_eth_dev *dev)
+eth_igbvf_interrupt_action(struct rte_eth_dev *dev, struct rte_intr_handle *intr_handle)
 {
 	struct e1000_interrupt *intr =
 		E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
@@ -2770,19 +2775,19 @@ eth_igbvf_interrupt_action(struct rte_eth_dev *dev)
 	}
 
 	igbvf_intr_enable(dev);
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(intr_handle);
 
 	return 0;
 }
 
 static void
-eth_igbvf_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
+eth_igbvf_interrupt_handler(struct rte_intr_handle *handle,
 			    void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
 
 	eth_igbvf_interrupt_get_status(dev);
-	eth_igbvf_interrupt_action(dev);
+	eth_igbvf_interrupt_action(dev, handle);
 }
 
 static int
@@ -3055,8 +3060,9 @@ igbvf_dev_start(struct rte_eth_dev *dev)
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(dev->data->dev_private);
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	int ret;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
 	uint32_t intr_vector = 0;
 
 	PMD_INIT_FUNC_TRACE();
@@ -3110,7 +3116,8 @@ igbvf_dev_start(struct rte_eth_dev *dev)
 static void
 igbvf_dev_stop(struct rte_eth_dev *dev)
 {
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -5095,6 +5102,8 @@ eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
 	struct e1000_hw *hw =
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t mask = 1 << queue_id;
 	uint32_t regval;
 
@@ -5102,7 +5111,7 @@ eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 	E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
 	E1000_WRITE_FLUSH(hw);
 
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(intr_handle);
 
 	return 0;
 }
@@ -5166,8 +5175,8 @@ eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
 	uint32_t vec = E1000_MISC_VEC_ID;
 	uint32_t base = E1000_MISC_VEC_ID;
 	uint32_t misc_shift = 0;
-
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	/* won't configure msix register if no mapping is done
 	 * between intr vector and event fd
diff --git a/drivers/net/e1000/igb_pf.c b/drivers/net/e1000/igb_pf.c
index 5845bc2..67da3c2 100644
--- a/drivers/net/e1000/igb_pf.c
+++ b/drivers/net/e1000/igb_pf.c
@@ -57,7 +57,9 @@
 static inline uint16_t
 dev_num_vf(struct rte_eth_dev *eth_dev)
 {
-	return eth_dev->pci_dev->max_vfs;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
+
+	return pci_dev->max_vfs;
 }
 
 static inline
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 06/23] ixgbe: localize mapping from eth_dev to pci_device
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (4 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 05/23] e1000: localize mapping from eth_dev to pci Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 07/23] i40e: localize mapping of eth_dev to pci Jan Blunck
                   ` (38 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, shreyansh.jain, david.marchand, Stephen Hemminger

From: Stephen Hemminger <stephen@networkplumber.org>

Since later changes will change where PCI information is,
localize mapping in one macro.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
Acked-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/ixgbe/ixgbe_ethdev.c | 120 ++++++++++++++++++++++-----------------
 drivers/net/ixgbe/ixgbe_ethdev.h |   3 +
 drivers/net/ixgbe/ixgbe_pf.c     |   4 +-
 3 files changed, 74 insertions(+), 53 deletions(-)

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index edc9b22..2d05751 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -233,7 +233,8 @@ static void ixgbe_dev_link_status_print(struct rte_eth_dev *dev);
 static int ixgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev);
 static int ixgbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev);
 static int ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev);
-static int ixgbe_dev_interrupt_action(struct rte_eth_dev *dev);
+static int ixgbe_dev_interrupt_action(struct rte_eth_dev *dev,
+				      struct rte_intr_handle *handle);
 static void ixgbe_dev_interrupt_handler(struct rte_intr_handle *handle,
 		void *param);
 static void ixgbe_dev_interrupt_delayed_handler(void *param);
@@ -1083,7 +1084,8 @@ ixgbe_swfw_lock_reset(struct ixgbe_hw *hw)
 static int
 eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
 	struct ixgbe_vfta *shadow_vfta =
@@ -1127,7 +1129,6 @@ eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev)
 
 		return 0;
 	}
-	pci_dev = eth_dev->pci_dev;
 
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
@@ -1272,12 +1273,11 @@ eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev)
 		     eth_dev->data->port_id, pci_dev->id.vendor_id,
 		     pci_dev->id.device_id);
 
-	rte_intr_callback_register(&pci_dev->intr_handle,
-				   ixgbe_dev_interrupt_handler,
-				   (void *)eth_dev);
+	rte_intr_callback_register(intr_handle,
+				   ixgbe_dev_interrupt_handler, eth_dev);
 
 	/* enable uio/vfio intr/eventfd mapping */
-	rte_intr_enable(&pci_dev->intr_handle);
+	rte_intr_enable(intr_handle);
 
 	/* enable support intr */
 	ixgbe_enable_intr(eth_dev);
@@ -1293,7 +1293,8 @@ eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev)
 static int
 eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw;
 
 	PMD_INIT_FUNC_TRACE();
@@ -1302,7 +1303,6 @@ eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev)
 		return -EPERM;
 
 	hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
-	pci_dev = eth_dev->pci_dev;
 
 	if (hw->adapter_stopped == 0)
 		ixgbe_dev_close(eth_dev);
@@ -1315,9 +1315,9 @@ eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev)
 	ixgbe_swfw_lock_reset(hw);
 
 	/* disable uio intr before callback unregister */
-	rte_intr_disable(&(pci_dev->intr_handle));
-	rte_intr_callback_unregister(&(pci_dev->intr_handle),
-		ixgbe_dev_interrupt_handler, (void *)eth_dev);
+	rte_intr_disable(intr_handle);
+	rte_intr_callback_unregister(intr_handle, 
+				     ixgbe_dev_interrupt_handler, eth_dev);
 
 	/* uninitialize PF if max_vfs not zero */
 	ixgbe_pf_host_uninit(eth_dev);
@@ -1381,7 +1381,8 @@ eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
 {
 	int diag;
 	uint32_t tc, tcs;
-	struct rte_pci_device *pci_dev;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
 	struct ixgbe_vfta *shadow_vfta =
@@ -1419,8 +1420,6 @@ eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
 		return 0;
 	}
 
-	pci_dev = eth_dev->pci_dev;
-
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
 	hw->device_id = pci_dev->id.device_id;
@@ -1513,10 +1512,9 @@ eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
 		return -EIO;
 	}
 
-	rte_intr_callback_register(&pci_dev->intr_handle,
-				   ixgbevf_dev_interrupt_handler,
-				   (void *)eth_dev);
-	rte_intr_enable(&pci_dev->intr_handle);
+	rte_intr_callback_register(intr_handle,
+				   ixgbevf_dev_interrupt_handler, eth_dev);
+	rte_intr_enable(intr_handle);
 	ixgbevf_intr_enable(hw);
 
 	PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x mac.type=%s",
@@ -1531,8 +1529,9 @@ eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
 static int
 eth_ixgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw;
-	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -1554,10 +1553,9 @@ eth_ixgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
 	rte_free(eth_dev->data->mac_addrs);
 	eth_dev->data->mac_addrs = NULL;
 
-	rte_intr_disable(&pci_dev->intr_handle);
-	rte_intr_callback_unregister(&pci_dev->intr_handle,
-				     ixgbevf_dev_interrupt_handler,
-				     (void *)eth_dev);
+	rte_intr_disable(intr_handle);
+	rte_intr_callback_unregister(intr_handle,
+				     ixgbevf_dev_interrupt_handler, eth_dev);
 
 	return 0;
 }
@@ -1947,6 +1945,8 @@ ixgbe_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
 static int
 ixgbe_check_vf_rss_rxq_num(struct rte_eth_dev *dev, uint16_t nb_rx_q)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+
 	switch (nb_rx_q) {
 	case 1:
 	case 2:
@@ -1960,7 +1960,7 @@ ixgbe_check_vf_rss_rxq_num(struct rte_eth_dev *dev, uint16_t nb_rx_q)
 	}
 
 	RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
-	RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx = dev->pci_dev->max_vfs * nb_rx_q;
+	RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx = pci_dev->max_vfs * nb_rx_q;
 
 	return 0;
 }
@@ -2191,7 +2191,8 @@ ixgbe_dev_start(struct rte_eth_dev *dev)
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct ixgbe_vf_info *vfinfo =
 		*IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t intr_vector = 0;
 	int err, link_up = 0, negotiate = 0;
 	uint32_t speed = 0;
@@ -2291,7 +2292,7 @@ ixgbe_dev_start(struct rte_eth_dev *dev)
 
 	/* Restore vf rate limit */
 	if (vfinfo != NULL) {
-		for (vf = 0; vf < dev->pci_dev->max_vfs; vf++)
+		for (vf = 0; vf < pci_dev->max_vfs; vf++)
 			for (idx = 0; idx < IXGBE_MAX_QUEUE_NUM_PER_VF; idx++)
 				if (vfinfo[vf].tx_rate[idx] != 0)
 					ixgbe_set_vf_rate_limit(dev, vf,
@@ -2368,8 +2369,7 @@ ixgbe_dev_start(struct rte_eth_dev *dev)
 			ixgbe_dev_lsc_interrupt_setup(dev);
 	} else {
 		rte_intr_callback_unregister(intr_handle,
-					     ixgbe_dev_interrupt_handler,
-					     (void *)dev);
+					     ixgbe_dev_interrupt_handler, dev);
 		if (dev->data->dev_conf.intr_conf.lsc != 0)
 			PMD_INIT_LOG(INFO, "lsc won't enable because of"
 				     " no intr multiplex\n");
@@ -2408,7 +2408,8 @@ ixgbe_dev_stop(struct rte_eth_dev *dev)
 	struct ixgbe_filter_info *filter_info =
 		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
 	struct ixgbe_5tuple_filter *p_5tuple, *p_5tuple_next;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	int vf;
 
 	PMD_INIT_FUNC_TRACE();
@@ -2423,8 +2424,7 @@ ixgbe_dev_stop(struct rte_eth_dev *dev)
 	/* stop adapter */
 	ixgbe_stop_adapter(hw);
 
-	for (vf = 0; vfinfo != NULL &&
-		     vf < dev->pci_dev->max_vfs; vf++)
+	for (vf = 0; vfinfo != NULL && vf < pci_dev->max_vfs; vf++)
 		vfinfo[vf].clear_to_send = false;
 
 	if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
@@ -3031,6 +3031,7 @@ ixgbevf_dev_stats_reset(struct rte_eth_dev *dev)
 static void
 ixgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
 
@@ -3049,7 +3050,7 @@ ixgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	dev_info->max_rx_pktlen = 15872; /* includes CRC, cf MAXFRS register */
 	dev_info->max_mac_addrs = hw->mac.num_rar_entries;
 	dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
-	dev_info->max_vfs = dev->pci_dev->max_vfs;
+	dev_info->max_vfs = pci_dev->max_vfs;
 	if (hw->mac.type == ixgbe_mac_82598EB)
 		dev_info->max_vmdq_pools = ETH_16_POOLS;
 	else
@@ -3163,6 +3164,7 @@ static void
 ixgbevf_dev_info_get(struct rte_eth_dev *dev,
 		     struct rte_eth_dev_info *dev_info)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
 	dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
@@ -3171,7 +3173,7 @@ ixgbevf_dev_info_get(struct rte_eth_dev *dev,
 	dev_info->max_rx_pktlen = 15872; /* includes CRC, cf MAXFRS reg */
 	dev_info->max_mac_addrs = hw->mac.num_rar_entries;
 	dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
-	dev_info->max_vfs = dev->pci_dev->max_vfs;
+	dev_info->max_vfs = pci_dev->max_vfs;
 	if (hw->mac.type == ixgbe_mac_82598EB)
 		dev_info->max_vmdq_pools = ETH_16_POOLS;
 	else
@@ -3433,6 +3435,7 @@ ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev)
 static void
 ixgbe_dev_link_status_print(struct rte_eth_dev *dev)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
 	struct rte_eth_link link;
 
 	memset(&link, 0, sizeof(link));
@@ -3448,10 +3451,10 @@ ixgbe_dev_link_status_print(struct rte_eth_dev *dev)
 				(int)(dev->data->port_id));
 	}
 	PMD_INIT_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
-				dev->pci_dev->addr.domain,
-				dev->pci_dev->addr.bus,
-				dev->pci_dev->addr.devid,
-				dev->pci_dev->addr.function);
+				pci_dev->addr.domain,
+				pci_dev->addr.bus,
+				pci_dev->addr.devid,
+				pci_dev->addr.function);
 }
 
 /*
@@ -3465,7 +3468,8 @@ ixgbe_dev_link_status_print(struct rte_eth_dev *dev)
  *  - On failure, a negative value.
  */
 static int
-ixgbe_dev_interrupt_action(struct rte_eth_dev *dev)
+ixgbe_dev_interrupt_action(struct rte_eth_dev *dev,
+			   struct rte_intr_handle *intr_handle)
 {
 	struct ixgbe_interrupt *intr =
 		IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
@@ -3515,7 +3519,7 @@ ixgbe_dev_interrupt_action(struct rte_eth_dev *dev)
 	} else {
 		PMD_DRV_LOG(DEBUG, "enable intr immediately");
 		ixgbe_enable_intr(dev);
-		rte_intr_enable(&(dev->pci_dev->intr_handle));
+		rte_intr_enable(intr_handle);
 	}
 
 
@@ -3540,6 +3544,8 @@ static void
 ixgbe_dev_interrupt_delayed_handler(void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_interrupt *intr =
 		IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
 	struct ixgbe_hw *hw =
@@ -3564,7 +3570,7 @@ ixgbe_dev_interrupt_delayed_handler(void *param)
 
 	PMD_DRV_LOG(DEBUG, "enable intr in delayed handler S[%08x]", eicr);
 	ixgbe_enable_intr(dev);
-	rte_intr_enable(&(dev->pci_dev->intr_handle));
+	rte_intr_enable(intr_handle);
 }
 
 /**
@@ -3580,13 +3586,13 @@ ixgbe_dev_interrupt_delayed_handler(void *param)
  *  void
  */
 static void
-ixgbe_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
+ixgbe_dev_interrupt_handler(struct rte_intr_handle *handle,
 			    void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
 
 	ixgbe_dev_interrupt_get_status(dev);
-	ixgbe_dev_interrupt_action(dev);
+	ixgbe_dev_interrupt_action(dev, handle);
 }
 
 static int
@@ -4196,7 +4202,8 @@ ixgbevf_dev_start(struct rte_eth_dev *dev)
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint32_t intr_vector = 0;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	int err, mask = 0;
 
@@ -4259,7 +4266,8 @@ static void
 ixgbevf_dev_stop(struct rte_eth_dev *dev)
 {
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -5061,6 +5069,8 @@ ixgbe_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t rule_id)
 static int
 ixgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t mask;
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -5070,7 +5080,7 @@ ixgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 	RTE_SET_USED(queue_id);
 	IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
 
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(intr_handle);
 
 	return 0;
 }
@@ -5093,6 +5103,8 @@ ixgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 static int
 ixgbe_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t mask;
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -5112,7 +5124,7 @@ ixgbe_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 		mask &= (1 << (queue_id - 32));
 		IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
 	}
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(intr_handle);
 
 	return 0;
 }
@@ -5216,7 +5228,8 @@ ixgbe_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
 static void
 ixgbevf_configure_msix(struct rte_eth_dev *dev)
 {
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint32_t q_idx;
@@ -5249,7 +5262,8 @@ ixgbevf_configure_msix(struct rte_eth_dev *dev)
 static void
 ixgbe_configure_msix(struct rte_eth_dev *dev)
 {
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint32_t queue_id, base = IXGBE_MISC_VEC_ID;
@@ -5367,6 +5381,7 @@ static int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
 static int ixgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
 	uint16_t tx_rate, uint64_t q_msk)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct ixgbe_vf_info *vfinfo =
 		*(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
@@ -5381,7 +5396,7 @@ static int ixgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
 		return -EINVAL;
 
 	if (vfinfo != NULL) {
-		for (vf_idx = 0; vf_idx < dev->pci_dev->max_vfs; vf_idx++) {
+		for (vf_idx = 0; vf_idx < pci_dev->max_vfs; vf_idx++) {
 			if (vf_idx == vf)
 				continue;
 			for (idx = 0; idx < RTE_DIM(vfinfo[vf_idx].tx_rate);
@@ -7194,15 +7209,16 @@ ixgbe_e_tag_insertion_en_dis(struct rte_eth_dev *dev,
 			     struct rte_eth_l2_tunnel_conf *l2_tunnel,
 			     bool en)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
 	int ret = 0;
 	uint32_t vmtir, vmvir;
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
-	if (l2_tunnel->vf_id >= dev->pci_dev->max_vfs) {
+	if (l2_tunnel->vf_id >= pci_dev->max_vfs) {
 		PMD_DRV_LOG(ERR,
 			    "VF id %u should be less than %u",
 			    l2_tunnel->vf_id,
-			    dev->pci_dev->max_vfs);
+			    pci_dev->max_vfs);
 		return -EINVAL;
 	}
 
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h
index 4ff6338..a0e02aa 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.h
+++ b/drivers/net/ixgbe/ixgbe_ethdev.h
@@ -291,6 +291,9 @@ struct ixgbe_adapter {
 	struct rte_timecounter      tx_tstamp_tc;
 };
 
+#define IXGBE_DEV_TO_PCI(eth_dev) \
+	(eth_dev->pci_dev)
+
 #define IXGBE_DEV_PRIVATE_TO_HW(adapter)\
 	(&((struct ixgbe_adapter *)adapter)->hw)
 
diff --git a/drivers/net/ixgbe/ixgbe_pf.c b/drivers/net/ixgbe/ixgbe_pf.c
index 26395e4..cb10265 100644
--- a/drivers/net/ixgbe/ixgbe_pf.c
+++ b/drivers/net/ixgbe/ixgbe_pf.c
@@ -61,7 +61,9 @@
 static inline uint16_t
 dev_num_vf(struct rte_eth_dev *eth_dev)
 {
-	return eth_dev->pci_dev->max_vfs;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
+
+	return pci_dev->max_vfs;
 }
 
 static inline
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 07/23] i40e: localize mapping of eth_dev to pci
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (5 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 06/23] ixgbe: localize mapping from eth_dev to pci_device Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 08/23] broadcom: localize mapping from " Jan Blunck
                   ` (37 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, shreyansh.jain, david.marchand, Stephen Hemminger

From: Stephen Hemminger <stephen@networkplumber.org>

Simplify later changes to eth_dev.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
Acked-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/i40e/i40e_ethdev.c    | 77 ++++++++++++++++++++++++---------------
 drivers/net/i40e/i40e_ethdev.h    |  3 ++
 drivers/net/i40e/i40e_ethdev_vf.c | 58 ++++++++++++++++-------------
 3 files changed, 83 insertions(+), 55 deletions(-)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 67778ba..ba5795e 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -373,8 +373,8 @@ static void i40e_stat_update_48(struct i40e_hw *hw,
 			       uint64_t *offset,
 			       uint64_t *stat);
 static void i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue);
-static void i40e_dev_interrupt_handler(
-		__rte_unused struct rte_intr_handle *handle, void *param);
+static void i40e_dev_interrupt_handler(struct rte_intr_handle *handle,
+				       void *param);
 static int i40e_res_pool_init(struct i40e_res_pool_info *pool,
 				uint32_t base, uint32_t num);
 static void i40e_res_pool_destroy(struct i40e_res_pool_info *pool);
@@ -907,7 +907,7 @@ is_floating_veb_supported(struct rte_devargs *devargs)
 static void
 config_floating_veb(struct rte_eth_dev *dev)
 {
-	struct rte_pci_device *pci_dev = dev->pci_dev;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
@@ -931,6 +931,7 @@ static int
 eth_i40e_dev_init(struct rte_eth_dev *dev)
 {
 	struct rte_pci_device *pci_dev;
+	struct rte_intr_handle *intr_handle;
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct i40e_vsi *vsi;
@@ -952,7 +953,8 @@ eth_i40e_dev_init(struct rte_eth_dev *dev)
 		i40e_set_tx_function(dev);
 		return 0;
 	}
-	pci_dev = dev->pci_dev;
+	pci_dev = I40E_DEV_TO_PCI(dev);
+	intr_handle = &pci_dev->intr_handle;
 
 	rte_eth_copy_pci_info(dev, pci_dev);
 
@@ -1148,15 +1150,15 @@ eth_i40e_dev_init(struct rte_eth_dev *dev)
 	i40e_pf_host_init(dev);
 
 	/* register callback func to eal lib */
-	rte_intr_callback_register(&(pci_dev->intr_handle),
-		i40e_dev_interrupt_handler, (void *)dev);
+	rte_intr_callback_register(intr_handle,
+				   i40e_dev_interrupt_handler, dev);
 
 	/* configure and enable device interrupt */
 	i40e_pf_config_irq0(hw, TRUE);
 	i40e_pf_enable_irq0(hw);
 
 	/* enable uio intr after callback register */
-	rte_intr_enable(&(pci_dev->intr_handle));
+	rte_intr_enable(intr_handle);
 	/*
 	 * Add an ethertype filter to drop all flow control frames transmitted
 	 * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC
@@ -1204,6 +1206,7 @@ static int
 eth_i40e_dev_uninit(struct rte_eth_dev *dev)
 {
 	struct rte_pci_device *pci_dev;
+	struct rte_intr_handle *intr_handle;
 	struct i40e_hw *hw;
 	struct i40e_filter_control_settings settings;
 	int ret;
@@ -1215,7 +1218,8 @@ eth_i40e_dev_uninit(struct rte_eth_dev *dev)
 		return 0;
 
 	hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	pci_dev = dev->pci_dev;
+	pci_dev = I40E_DEV_TO_PCI(dev);
+	intr_handle = &pci_dev->intr_handle;
 
 	if (hw->adapter_stopped == 0)
 		i40e_dev_close(dev);
@@ -1245,11 +1249,11 @@ eth_i40e_dev_uninit(struct rte_eth_dev *dev)
 	dev->data->mac_addrs = NULL;
 
 	/* disable uio intr before callback unregister */
-	rte_intr_disable(&(pci_dev->intr_handle));
+	rte_intr_disable(intr_handle);
 
 	/* register callback func to eal lib */
-	rte_intr_callback_unregister(&(pci_dev->intr_handle),
-		i40e_dev_interrupt_handler, (void *)dev);
+	rte_intr_callback_unregister(intr_handle,
+				     i40e_dev_interrupt_handler, dev);
 
 	return 0;
 }
@@ -1335,7 +1339,8 @@ void
 i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
 {
 	struct rte_eth_dev *dev = vsi->adapter->eth_dev;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
 	uint16_t msix_vect = vsi->msix_intr;
 	uint16_t i;
@@ -1448,7 +1453,8 @@ void
 i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi)
 {
 	struct rte_eth_dev *dev = vsi->adapter->eth_dev;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
 	uint16_t msix_vect = vsi->msix_intr;
 	uint16_t nb_msix = RTE_MIN(vsi->nb_msix, intr_handle->nb_efd);
@@ -1519,7 +1525,8 @@ static void
 i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
 {
 	struct rte_eth_dev *dev = vsi->adapter->eth_dev;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
 	uint16_t interval = i40e_calc_itr_interval(\
 		RTE_LIBRTE_I40E_ITR_INTERVAL);
@@ -1550,7 +1557,8 @@ static void
 i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
 {
 	struct rte_eth_dev *dev = vsi->adapter->eth_dev;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
 	uint16_t msix_intr, i;
 
@@ -1675,7 +1683,8 @@ i40e_dev_start(struct rte_eth_dev *dev)
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct i40e_vsi *main_vsi = pf->main_vsi;
 	int ret, i;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t intr_vector = 0;
 
 	hw->adapter_stopped = 0;
@@ -1808,7 +1817,8 @@ i40e_dev_stop(struct rte_eth_dev *dev)
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_vsi *main_vsi = pf->main_vsi;
 	struct i40e_mirror_rule *p_mirror;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	int i;
 
 	/* Disable all queues */
@@ -1859,6 +1869,8 @@ i40e_dev_close(struct rte_eth_dev *dev)
 {
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t reg;
 	int i;
 
@@ -1870,7 +1882,7 @@ i40e_dev_close(struct rte_eth_dev *dev)
 
 	/* Disable interrupt */
 	i40e_pf_disable_irq0(hw);
-	rte_intr_disable(&(dev->pci_dev->intr_handle));
+	rte_intr_disable(intr_handle);
 
 	/* shutdown and destroy the HMC */
 	i40e_shutdown_lan_hmc(hw);
@@ -2582,13 +2594,14 @@ i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct i40e_vsi *vsi = pf->main_vsi;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
 
 	dev_info->max_rx_queues = vsi->nb_qps;
 	dev_info->max_tx_queues = vsi->nb_qps;
 	dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
 	dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
 	dev_info->max_mac_addrs = vsi->max_macaddrs;
-	dev_info->max_vfs = dev->pci_dev->max_vfs;
+	dev_info->max_vfs = pci_dev->max_vfs;
 	dev_info->rx_offload_capa =
 		DEV_RX_OFFLOAD_VLAN_STRIP |
 		DEV_RX_OFFLOAD_QINQ_STRIP |
@@ -3490,9 +3503,10 @@ i40e_pf_parameter_init(struct rte_eth_dev *dev)
 {
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_PF_TO_HW(pf);
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
 	uint16_t qp_count = 0, vsi_count = 0;
 
-	if (dev->pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
+	if (pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
 		PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
 		return -EINVAL;
 	}
@@ -3533,10 +3547,10 @@ i40e_pf_parameter_init(struct rte_eth_dev *dev)
 
 	/* VF queue/VSI allocation */
 	pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
-	if (hw->func_caps.sr_iov_1_1 && dev->pci_dev->max_vfs) {
+	if (hw->func_caps.sr_iov_1_1 && pci_dev->max_vfs) {
 		pf->flags |= I40E_FLAG_SRIOV;
 		pf->vf_nb_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
-		pf->vf_num = dev->pci_dev->max_vfs;
+		pf->vf_num = pci_dev->max_vfs;
 		PMD_DRV_LOG(DEBUG, "%u VF VSIs, %u queues per VF VSI, "
 			    "in total %u queues", pf->vf_num, pf->vf_nb_qps,
 			    pf->vf_nb_qps * pf->vf_num);
@@ -5526,7 +5540,7 @@ i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
  *  void
  */
 static void
-i40e_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
+i40e_dev_interrupt_handler(struct rte_intr_handle *intr_handle,
 			   void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
@@ -5573,7 +5587,7 @@ i40e_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
 done:
 	/* Enable interrupt */
 	i40e_pf_enable_irq0(hw);
-	rte_intr_enable(&(dev->pci_dev->intr_handle));
+	rte_intr_enable(intr_handle);
 }
 
 static int
@@ -8124,10 +8138,11 @@ i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
 static void
 i40e_enable_extended_tag(struct rte_eth_dev *dev)
 {
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
 	uint32_t buf = 0;
 	int ret;
 
-	ret = rte_eal_pci_read_config(dev->pci_dev, &buf, sizeof(buf),
+	ret = rte_eal_pci_read_config(pci_dev, &buf, sizeof(buf),
 				      PCI_DEV_CAP_REG);
 	if (ret < 0) {
 		PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
@@ -8140,7 +8155,7 @@ i40e_enable_extended_tag(struct rte_eth_dev *dev)
 	}
 
 	buf = 0;
-	ret = rte_eal_pci_read_config(dev->pci_dev, &buf, sizeof(buf),
+	ret = rte_eal_pci_read_config(pci_dev, &buf, sizeof(buf),
 				      PCI_DEV_CTRL_REG);
 	if (ret < 0) {
 		PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
@@ -8152,7 +8167,7 @@ i40e_enable_extended_tag(struct rte_eth_dev *dev)
 		return;
 	}
 	buf |= PCI_DEV_CTRL_EXT_TAG_MASK;
-	ret = rte_eal_pci_write_config(dev->pci_dev, &buf, sizeof(buf),
+	ret = rte_eal_pci_write_config(pci_dev, &buf, sizeof(buf),
 				       PCI_DEV_CTRL_REG);
 	if (ret < 0) {
 		PMD_DRV_LOG(ERR, "Failed to write PCI offset 0x%x",
@@ -9555,7 +9570,8 @@ i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
 static int
 i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint16_t interval =
 		i40e_calc_itr_interval(RTE_LIBRTE_I40E_ITR_INTERVAL);
@@ -9580,7 +9596,7 @@ i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 				I40E_PFINT_DYN_CTLN_INTERVAL_SHIFT));
 
 	I40E_WRITE_FLUSH(hw);
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(&pci_dev->intr_handle);
 
 	return 0;
 }
@@ -9588,7 +9604,8 @@ i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 static int
 i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint16_t msix_intr;
 
diff --git a/drivers/net/i40e/i40e_ethdev.h b/drivers/net/i40e/i40e_ethdev.h
index 298cef4..da8dd7e 100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -617,6 +617,9 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
 void i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
 	struct rte_eth_txq_info *qinfo);
 
+#define I40E_DEV_TO_PCI(eth_dev) \
+	(eth_dev->pci_dev)
+
 /* I40E_DEV_PRIVATE_TO */
 #define I40E_DEV_PRIVATE_TO_PF(adapter) \
 	(&((struct i40e_adapter *)adapter)->pf)
diff --git a/drivers/net/i40e/i40e_ethdev_vf.c b/drivers/net/i40e/i40e_ethdev_vf.c
index aa306d6..a4d8a66 100644
--- a/drivers/net/i40e/i40e_ethdev_vf.c
+++ b/drivers/net/i40e/i40e_ethdev_vf.c
@@ -718,7 +718,8 @@ i40evf_config_irq_map(struct rte_eth_dev *dev)
 	uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_irq_map_info) + \
 		sizeof(struct i40e_virtchnl_vector_map)];
 	struct i40e_virtchnl_irq_map_info *map_info;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t vector_id;
 	int i, err;
 
@@ -1401,7 +1402,7 @@ i40evf_handle_aq_msg(struct rte_eth_dev *dev)
  *  void
  */
 static void
-i40evf_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
+i40evf_dev_interrupt_handler(struct rte_intr_handle *intr_handle,
 			     void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
@@ -1431,15 +1432,15 @@ i40evf_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
 
 done:
 	i40evf_enable_irq0(hw);
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(intr_handle);
 }
 
 static int
 i40evf_dev_init(struct rte_eth_dev *eth_dev)
 {
-	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(\
-			eth_dev->data->dev_private);
-	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
+	struct i40e_hw *hw
+		= I40E_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(eth_dev);
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -1458,15 +1459,15 @@ i40evf_dev_init(struct rte_eth_dev *eth_dev)
 		return 0;
 	}
 
-	rte_eth_copy_pci_info(eth_dev, eth_dev->pci_dev);
+	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
-	hw->vendor_id = eth_dev->pci_dev->id.vendor_id;
-	hw->device_id = eth_dev->pci_dev->id.device_id;
-	hw->subsystem_vendor_id = eth_dev->pci_dev->id.subsystem_vendor_id;
-	hw->subsystem_device_id = eth_dev->pci_dev->id.subsystem_device_id;
-	hw->bus.device = eth_dev->pci_dev->addr.devid;
-	hw->bus.func = eth_dev->pci_dev->addr.function;
-	hw->hw_addr = (void *)eth_dev->pci_dev->mem_resource[0].addr;
+	hw->vendor_id = pci_dev->id.vendor_id;
+	hw->device_id = pci_dev->id.device_id;
+	hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
+	hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
+	hw->bus.device = pci_dev->addr.devid;
+	hw->bus.func = pci_dev->addr.function;
+	hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
 	hw->adapter_stopped = 0;
 
 	if(i40evf_init_vf(eth_dev) != 0) {
@@ -1853,7 +1854,8 @@ i40evf_enable_queues_intr(struct rte_eth_dev *dev)
 {
 	struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	if (!rte_intr_allow_others(intr_handle)) {
 		I40E_WRITE_REG(hw,
@@ -1885,7 +1887,8 @@ i40evf_disable_queues_intr(struct rte_eth_dev *dev)
 {
 	struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	if (!rte_intr_allow_others(intr_handle)) {
 		I40E_WRITE_REG(hw, I40E_VFINT_DYN_CTL01,
@@ -1911,7 +1914,8 @@ i40evf_disable_queues_intr(struct rte_eth_dev *dev)
 static int
 i40evf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint16_t interval =
 		i40e_calc_itr_interval(RTE_LIBRTE_I40E_ITR_INTERVAL);
@@ -1937,7 +1941,7 @@ i40evf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 
 	I40EVF_WRITE_FLUSH(hw);
 
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(&pci_dev->intr_handle);
 
 	return 0;
 }
@@ -1945,7 +1949,8 @@ i40evf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 static int
 i40evf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint16_t msix_intr;
 
@@ -2025,7 +2030,8 @@ i40evf_dev_start(struct rte_eth_dev *dev)
 {
 	struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t intr_vector = 0;
 
 	PMD_INIT_FUNC_TRACE();
@@ -2090,7 +2096,8 @@ i40evf_dev_start(struct rte_eth_dev *dev)
 static void
 i40evf_dev_stop(struct rte_eth_dev *dev)
 {
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -2285,7 +2292,8 @@ static void
 i40evf_dev_close(struct rte_eth_dev *dev)
 {
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pci_dev = dev->pci_dev;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	i40evf_dev_stop(dev);
 	hw->adapter_stopped = 1;
@@ -2293,11 +2301,11 @@ i40evf_dev_close(struct rte_eth_dev *dev)
 	i40evf_reset_vf(hw);
 	i40e_shutdown_adminq(hw);
 	/* disable uio intr before callback unregister */
-	rte_intr_disable(&pci_dev->intr_handle);
+	rte_intr_disable(intr_handle);
 
 	/* unregister callback func from eal lib */
-	rte_intr_callback_unregister(&pci_dev->intr_handle,
-		i40evf_dev_interrupt_handler, (void *)dev);
+	rte_intr_callback_unregister(intr_handle,
+				     i40evf_dev_interrupt_handler, dev);
 	i40evf_disable_irq0(hw);
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 08/23] broadcom: localize mapping from eth_dev to pci
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (6 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 07/23] i40e: localize mapping of eth_dev to pci Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 09/23] virtio: Don't fill dev_info->driver_name Jan Blunck
                   ` (36 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, shreyansh.jain, david.marchand, Stephen Hemminger

From: Stephen Hemminger <stephen@networkplumber.org>

Use existing information about pci and interrupt handle to minimize
the number of places that assume eth_dev contains pci_device
information.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
Acked-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/bnxt/bnxt_ethdev.c | 22 +++++++++++++---------
 drivers/net/bnxt/bnxt_ring.c   | 16 ++++++----------
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index 035fe07..529b6c8 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -743,6 +743,8 @@ static int bnxt_reta_query_op(struct rte_eth_dev *eth_dev,
 {
 	struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
 	struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
+	struct rte_intr_handle *intr_handle
+		= &bp->pdev->intr_handle;
 
 	/* Retrieve from the default VNIC */
 	if (!vnic)
@@ -759,7 +761,7 @@ static int bnxt_reta_query_op(struct rte_eth_dev *eth_dev,
 	/* EW - need to revisit here copying from u64 to u16 */
 	memcpy(reta_conf, vnic->rss_table, reta_size);
 
-	if (rte_intr_allow_others(&eth_dev->pci_dev->intr_handle)) {
+	if (rte_intr_allow_others(intr_handle)) {
 		if (eth_dev->data->dev_conf.intr_conf.lsc != 0)
 			bnxt_dev_lsc_intr_setup(eth_dev);
 	}
@@ -1009,11 +1011,12 @@ static bool bnxt_vf_pciid(uint16_t id)
 
 static int bnxt_init_board(struct rte_eth_dev *eth_dev)
 {
-	int rc;
 	struct bnxt *bp = eth_dev->data->dev_private;
+	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
+	int rc;
 
 	/* enable device (incl. PCI PM wakeup), and bus-mastering */
-	if (!eth_dev->pci_dev->mem_resource[0].addr) {
+	if (!pci_dev->mem_resource[0].addr) {
 		RTE_LOG(ERR, PMD,
 			"Cannot find PCI device base address, aborting\n");
 		rc = -ENODEV;
@@ -1021,9 +1024,9 @@ static int bnxt_init_board(struct rte_eth_dev *eth_dev)
 	}
 
 	bp->eth_dev = eth_dev;
-	bp->pdev = eth_dev->pci_dev;
+	bp->pdev = pci_dev;
 
-	bp->bar0 = (void *)eth_dev->pci_dev->mem_resource[0].addr;
+	bp->bar0 = (void *)pci_dev->mem_resource[0].addr;
 	if (!bp->bar0) {
 		RTE_LOG(ERR, PMD, "Cannot map device registers, aborting\n");
 		rc = -ENOMEM;
@@ -1043,6 +1046,7 @@ static int bnxt_init_board(struct rte_eth_dev *eth_dev)
 static int
 bnxt_dev_init(struct rte_eth_dev *eth_dev)
 {
+	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
 	static int version_printed;
 	struct bnxt *bp;
 	int rc;
@@ -1050,10 +1054,10 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
 	if (version_printed++ == 0)
 		RTE_LOG(INFO, PMD, "%s", bnxt_version);
 
-	rte_eth_copy_pci_info(eth_dev, eth_dev->pci_dev);
+	rte_eth_copy_pci_info(eth_dev, pci_dev);
 	bp = eth_dev->data->dev_private;
 
-	if (bnxt_vf_pciid(eth_dev->pci_dev->id.device_id))
+	if (bnxt_vf_pciid(pci_dev->id.device_id))
 		bp->flags |= BNXT_FLAG_VF;
 
 	rc = bnxt_init_board(eth_dev);
@@ -1121,8 +1125,8 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
 
 	RTE_LOG(INFO, PMD,
 		DRV_MODULE_NAME " found at mem %" PRIx64 ", node addr %pM\n",
-		eth_dev->pci_dev->mem_resource[0].phys_addr,
-		eth_dev->pci_dev->mem_resource[0].addr);
+		pci_dev->mem_resource[0].phys_addr,
+		pci_dev->mem_resource[0].addr);
 
 	bp->dev_stopped = 0;
 
diff --git a/drivers/net/bnxt/bnxt_ring.c b/drivers/net/bnxt/bnxt_ring.c
index 3f81ffc..0fafa13 100644
--- a/drivers/net/bnxt/bnxt_ring.c
+++ b/drivers/net/bnxt/bnxt_ring.c
@@ -209,6 +209,7 @@ int bnxt_alloc_rings(struct bnxt *bp, uint16_t qidx,
  */
 int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 {
+	struct rte_pci_device *pci_dev = bp->pdev;
 	unsigned int i;
 	int rc = 0;
 
@@ -222,8 +223,7 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 					  0, HWRM_NA_SIGNATURE);
 		if (rc)
 			goto err_out;
-		cpr->cp_doorbell =
-		    (char *)bp->eth_dev->pci_dev->mem_resource[2].addr;
+		cpr->cp_doorbell = pci_dev->mem_resource[2].addr;
 		B_CP_DIS_DB(cpr, cpr->cp_raw_cons);
 		bp->grp_info[0].cp_fw_ring_id = cp_ring->fw_ring_id;
 	}
@@ -242,8 +242,7 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 					idx, HWRM_NA_SIGNATURE);
 		if (rc)
 			goto err_out;
-		cpr->cp_doorbell =
-		    (char *)bp->eth_dev->pci_dev->mem_resource[2].addr +
+		cpr->cp_doorbell = (char *)pci_dev->mem_resource[2].addr +
 		    idx * 0x80;
 		bp->grp_info[idx].cp_fw_ring_id = cp_ring->fw_ring_id;
 		B_CP_DIS_DB(cpr, cpr->cp_raw_cons);
@@ -255,8 +254,7 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 		if (rc)
 			goto err_out;
 		rxr->rx_prod = 0;
-		rxr->rx_doorbell =
-		    (char *)bp->eth_dev->pci_dev->mem_resource[2].addr +
+		rxr->rx_doorbell = (char *)pci_dev->mem_resource[2].addr +
 		    idx * 0x80;
 		bp->grp_info[idx].rx_fw_ring_id = ring->fw_ring_id;
 		B_RX_DB(rxr->rx_doorbell, rxr->rx_prod);
@@ -283,8 +281,7 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 		if (rc)
 			goto err_out;
 
-		cpr->cp_doorbell =
-		    (char *)bp->eth_dev->pci_dev->mem_resource[2].addr +
+		cpr->cp_doorbell = (char *)pci_dev->mem_resource[2].addr +
 		    idx * 0x80;
 		bp->grp_info[idx].cp_fw_ring_id = cp_ring->fw_ring_id;
 		B_CP_DIS_DB(cpr, cpr->cp_raw_cons);
@@ -296,8 +293,7 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 		if (rc)
 			goto err_out;
 
-		txr->tx_doorbell =
-		    (char *)bp->eth_dev->pci_dev->mem_resource[2].addr +
+		txr->tx_doorbell = (char *)pci_dev->mem_resource[2].addr +
 		    idx * 0x80;
 	}
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 09/23] virtio: Don't fill dev_info->driver_name
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (7 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 08/23] broadcom: localize mapping from " Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 10/23] virtio: Add vtpci_intr_handle() helper to get rte_intr_handle Jan Blunck
                   ` (35 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

This is overwritten in rte_eth_dev_info_get().

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Reviewed-by: David Marchand <david.marchand@6wind.com>
---
 drivers/net/virtio/virtio_ethdev.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 079fd6c..741688e 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1624,10 +1624,6 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	uint64_t tso_mask;
 	struct virtio_hw *hw = dev->data->dev_private;
 
-	if (dev->pci_dev)
-		dev_info->driver_name = dev->driver->pci_drv.driver.name;
-	else
-		dev_info->driver_name = "virtio_user PMD";
 	dev_info->max_rx_queues =
 		RTE_MIN(hw->max_queue_pairs, VIRTIO_MAX_RX_QUEUES);
 	dev_info->max_tx_queues =
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 10/23] virtio: Add vtpci_intr_handle() helper to get rte_intr_handle
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (8 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 09/23] virtio: Don't fill dev_info->driver_name Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 20:08   ` Stephen Hemminger
  2016-12-21 15:09 ` [PATCH v4 11/23] virtio: Don't depend on struct rte_eth_dev's pci_dev Jan Blunck
                   ` (34 subsequent siblings)
  44 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

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) {
@@ -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_ */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 11/23] virtio: Don't depend on struct rte_eth_dev's pci_dev
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (9 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 10/23] virtio: Add vtpci_intr_handle() helper to get rte_intr_handle Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 12/23] bnx2x: localize mapping from eth_dev to pci Jan Blunck
                   ` (33 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

We don't need to depend on rte_eth_dev->pci_dev to differentiate between
the virtio_user and the virtio_pci case. Instead we can use the private
virtio_hw struct to get that information.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 drivers/net/virtio/virtio_ethdev.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index da9668e..58c03d8 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -483,11 +483,11 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 		hw->cvq = cvq;
 	}
 
-	/* For virtio_user case (that is when dev->pci_dev is NULL), we use
+	/* For virtio_user case (that is when hw->dev is NULL), we use
 	 * virtual address. And we need properly set _offset_, please see
 	 * VIRTIO_MBUF_DATA_DMA_ADDR in virtqueue.h for more information.
 	 */
-	if (dev->pci_dev)
+	if (hw->dev)
 		vq->offset = offsetof(struct rte_mbuf, buf_physaddr);
 	else {
 		vq->vq_ring_mem = (uintptr_t)mz->addr;
@@ -1190,7 +1190,7 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 	struct virtio_hw *hw = eth_dev->data->dev_private;
 	struct virtio_net_config *config;
 	struct virtio_net_config local_config;
-	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
+	struct rte_pci_device *pci_dev = hw->dev;
 	int ret;
 
 	/* Reset the device although not necessary at startup */
@@ -1210,7 +1210,8 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 	else
 		eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
 
-	rte_eth_copy_pci_info(eth_dev, pci_dev);
+	if (pci_dev)
+		rte_eth_copy_pci_info(eth_dev, pci_dev);
 
 	rx_func_get(eth_dev);
 
@@ -1294,7 +1295,6 @@ int
 eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 {
 	struct virtio_hw *hw = eth_dev->data->dev_private;
-	struct rte_pci_device *pci_dev;
 	uint32_t dev_flags = RTE_ETH_DEV_DETACHABLE;
 	int ret;
 
@@ -1317,10 +1317,11 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 		return -ENOMEM;
 	}
 
-	pci_dev = eth_dev->pci_dev;
-
-	if (pci_dev) {
-		ret = vtpci_init(pci_dev, hw, &dev_flags);
+	/* For virtio_user case the hw->virtio_user_dev is populated by
+	 * virtio_user_eth_dev_alloc() before eth_virtio_dev_init() is called.
+	 */
+	if (!hw->virtio_user_dev) {
+		ret = vtpci_init(eth_dev->pci_dev, hw, &dev_flags);
 		if (ret)
 			return ret;
 	}
@@ -1343,7 +1344,6 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 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();
@@ -1353,7 +1353,6 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
 
 	virtio_dev_stop(eth_dev);
 	virtio_dev_close(eth_dev);
-	pci_dev = eth_dev->pci_dev;
 
 	eth_dev->dev_ops = NULL;
 	eth_dev->tx_pkt_burst = NULL;
@@ -1367,7 +1366,8 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
 		rte_intr_callback_unregister(vtpci_intr_handle(hw),
 						virtio_interrupt_handler,
 						eth_dev);
-	rte_eal_pci_unmap_device(pci_dev);
+	if (hw->dev)
+		rte_eal_pci_unmap_device(hw->dev);
 
 	PMD_INIT_LOG(DEBUG, "dev_uninit completed");
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 12/23] bnx2x: localize mapping from eth_dev to pci
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (10 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 11/23] virtio: Don't depend on struct rte_eth_dev's pci_dev Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 16:35   ` Harish Patil
  2016-12-21 15:09 ` [PATCH v4 13/23] fm10k: " Jan Blunck
                   ` (32 subsequent siblings)
  44 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

Use device private information to minimize the places that assume eth_dev
contains pci_dev.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/bnx2x/bnx2x_ethdev.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/bnx2x/bnx2x_ethdev.c b/drivers/net/bnx2x/bnx2x_ethdev.c
index 0eae433..ef2026a 100644
--- a/drivers/net/bnx2x/bnx2x_ethdev.c
+++ b/drivers/net/bnx2x/bnx2x_ethdev.c
@@ -119,12 +119,12 @@ bnx2x_interrupt_action(struct rte_eth_dev *dev)
 }
 
 static __rte_unused void
-bnx2x_interrupt_handler(__rte_unused struct rte_intr_handle *handle, void *param)
+bnx2x_interrupt_handler(struct rte_intr_handle *handle, void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
 
 	bnx2x_interrupt_action(dev);
-	rte_intr_enable(&(dev->pci_dev->intr_handle));
+	rte_intr_enable(handle);
 }
 
 /*
@@ -187,10 +187,10 @@ bnx2x_dev_start(struct rte_eth_dev *dev)
 	}
 
 	if (IS_PF(sc)) {
-		rte_intr_callback_register(&(dev->pci_dev->intr_handle),
+		rte_intr_callback_register(&sc->pci_dev->intr_handle,
 				bnx2x_interrupt_handler, (void *)dev);
 
-		if(rte_intr_enable(&(dev->pci_dev->intr_handle)))
+		if (rte_intr_enable(&sc->pci_dev->intr_handle))
 			PMD_DRV_LOG(ERR, "rte_intr_enable failed");
 	}
 
@@ -215,8 +215,8 @@ bnx2x_dev_stop(struct rte_eth_dev *dev)
 	PMD_INIT_FUNC_TRACE();
 
 	if (IS_PF(sc)) {
-		rte_intr_disable(&(dev->pci_dev->intr_handle));
-		rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
+		rte_intr_disable(&sc->pci_dev->intr_handle);
+		rte_intr_callback_unregister(&sc->pci_dev->intr_handle,
 				bnx2x_interrupt_handler, (void *)dev);
 	}
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 13/23] fm10k: localize mapping from eth_dev to pci
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (11 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 12/23] bnx2x: localize mapping from eth_dev to pci Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 14/23] qede: localize mapping of " Jan Blunck
                   ` (31 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

This simplifies later changes to ethdev.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/fm10k/fm10k_ethdev.c | 77 ++++++++++++++++++++++------------------
 1 file changed, 43 insertions(+), 34 deletions(-)

diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c
index 923690c..2f6c628 100644
--- a/drivers/net/fm10k/fm10k_ethdev.c
+++ b/drivers/net/fm10k/fm10k_ethdev.c
@@ -59,7 +59,7 @@
 #define BIT_MASK_PER_UINT32 ((1 << CHARS_PER_UINT32) - 1)
 
 /* default 1:1 map from queue ID to interrupt vector ID */
-#define Q2V(dev, queue_id) (dev->pci_dev->intr_handle.intr_vec[queue_id])
+#define Q2V(pci_dev, queue_id) ((pci_dev)->intr_handle.intr_vec[queue_id])
 
 /* First 64 Logical ports for PF/VMDQ, second 64 for Flow director */
 #define MAX_LPORT_NUM    128
@@ -711,7 +711,8 @@ fm10k_dev_rx_init(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct fm10k_macvlan_filter_info *macvlan;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	int i, ret;
 	struct fm10k_rx_queue *rxq;
 	uint64_t base_addr;
@@ -725,13 +726,13 @@ fm10k_dev_rx_init(struct rte_eth_dev *dev)
 	i = 0;
 	if (rte_intr_dp_is_en(intr_handle)) {
 		for (; i < dev->data->nb_rx_queues; i++) {
-			FM10K_WRITE_REG(hw, FM10K_RXINT(i), Q2V(dev, i));
+			FM10K_WRITE_REG(hw, FM10K_RXINT(i), Q2V(pdev, i));
 			if (hw->mac.type == fm10k_mac_pf)
-				FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(dev, i)),
+				FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, i)),
 					FM10K_ITR_AUTOMASK |
 					FM10K_ITR_MASK_CLEAR);
 			else
-				FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(dev, i)),
+				FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, i)),
 					FM10K_ITR_AUTOMASK |
 					FM10K_ITR_MASK_CLEAR);
 		}
@@ -1171,7 +1172,8 @@ static void
 fm10k_dev_stop(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	int i;
 
 	PMD_INIT_FUNC_TRACE();
@@ -1190,10 +1192,10 @@ fm10k_dev_stop(struct rte_eth_dev *dev)
 			FM10K_WRITE_REG(hw, FM10K_RXINT(i),
 				3 << FM10K_RXINT_TIMER_SHIFT);
 			if (hw->mac.type == fm10k_mac_pf)
-				FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(dev, i)),
+				FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, i)),
 					FM10K_ITR_MASK_SET);
 			else
-				FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(dev, i)),
+				FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, i)),
 					FM10K_ITR_MASK_SET);
 		}
 	}
@@ -1387,6 +1389,7 @@ fm10k_dev_infos_get(struct rte_eth_dev *dev,
 	struct rte_eth_dev_info *dev_info)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_pci_device *pdev = dev->pci_dev;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -1396,7 +1399,7 @@ fm10k_dev_infos_get(struct rte_eth_dev *dev,
 	dev_info->max_tx_queues      = hw->mac.max_queues;
 	dev_info->max_mac_addrs      = FM10K_MAX_MACADDR_NUM;
 	dev_info->max_hash_mac_addrs = 0;
-	dev_info->max_vfs            = dev->pci_dev->max_vfs;
+	dev_info->max_vfs            = pdev->max_vfs;
 	dev_info->vmdq_pool_base     = 0;
 	dev_info->vmdq_queue_base    = 0;
 	dev_info->max_vmdq_pools     = ETH_32_POOLS;
@@ -2333,15 +2336,16 @@ static int
 fm10k_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_pci_device *pdev = dev->pci_dev;
 
 	/* Enable ITR */
 	if (hw->mac.type == fm10k_mac_pf)
-		FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(dev, queue_id)),
+		FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, queue_id)),
 			FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR);
 	else
-		FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(dev, queue_id)),
+		FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, queue_id)),
 			FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR);
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(&pdev->intr_handle);
 	return 0;
 }
 
@@ -2349,13 +2353,14 @@ static int
 fm10k_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_pci_device *pdev = dev->pci_dev;
 
 	/* Disable ITR */
 	if (hw->mac.type == fm10k_mac_pf)
-		FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(dev, queue_id)),
+		FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, queue_id)),
 			FM10K_ITR_MASK_SET);
 	else
-		FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(dev, queue_id)),
+		FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, queue_id)),
 			FM10K_ITR_MASK_SET);
 	return 0;
 }
@@ -2364,7 +2369,8 @@ static int
 fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	uint32_t intr_vector, vec;
 	uint16_t queue_id;
 	int result = 0;
@@ -2380,7 +2386,7 @@ fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
 	intr_vector = dev->data->nb_rx_queues;
 
 	/* disable interrupt first */
-	rte_intr_disable(&dev->pci_dev->intr_handle);
+	rte_intr_disable(intr_handle);
 	if (hw->mac.type == fm10k_mac_pf)
 		fm10k_dev_disable_intr_pf(dev);
 	else
@@ -2415,7 +2421,7 @@ fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
 		fm10k_dev_enable_intr_pf(dev);
 	else
 		fm10k_dev_enable_intr_vf(dev);
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(intr_handle);
 	hw->mac.ops.update_int_moderator(hw);
 	return result;
 }
@@ -2530,7 +2536,7 @@ fm10k_dev_handle_fault(struct fm10k_hw *hw, uint32_t eicr)
  */
 static void
 fm10k_dev_interrupt_handler_pf(
-			__rte_unused struct rte_intr_handle *handle,
+			struct rte_intr_handle *handle,
 			void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
@@ -2581,7 +2587,7 @@ fm10k_dev_interrupt_handler_pf(
 	FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_AUTOMASK |
 					FM10K_ITR_MASK_CLEAR);
 	/* Re-enable interrupt from host side */
-	rte_intr_enable(&(dev->pci_dev->intr_handle));
+	rte_intr_enable(handle);
 }
 
 /**
@@ -2597,7 +2603,7 @@ fm10k_dev_interrupt_handler_pf(
  */
 static void
 fm10k_dev_interrupt_handler_vf(
-			__rte_unused struct rte_intr_handle *handle,
+			struct rte_intr_handle *handle,
 			void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
@@ -2615,7 +2621,7 @@ fm10k_dev_interrupt_handler_vf(
 	FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_AUTOMASK |
 					FM10K_ITR_MASK_CLEAR);
 	/* Re-enable interrupt from host side */
-	rte_intr_enable(&(dev->pci_dev->intr_handle));
+	rte_intr_enable(handle);
 }
 
 /* Mailbox message handler in VF */
@@ -2827,6 +2833,8 @@ static int
 eth_fm10k_dev_init(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	int diag, i;
 	struct fm10k_macvlan_filter_info *macvlan;
 
@@ -2840,18 +2848,18 @@ eth_fm10k_dev_init(struct rte_eth_dev *dev)
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return 0;
 
-	rte_eth_copy_pci_info(dev, dev->pci_dev);
+	rte_eth_copy_pci_info(dev, pdev);
 
 	macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
 	memset(macvlan, 0, sizeof(*macvlan));
 	/* Vendor and Device ID need to be set before init of shared code */
 	memset(hw, 0, sizeof(*hw));
-	hw->device_id = dev->pci_dev->id.device_id;
-	hw->vendor_id = dev->pci_dev->id.vendor_id;
-	hw->subsystem_device_id = dev->pci_dev->id.subsystem_device_id;
-	hw->subsystem_vendor_id = dev->pci_dev->id.subsystem_vendor_id;
+	hw->device_id = pdev->id.device_id;
+	hw->vendor_id = pdev->id.vendor_id;
+	hw->subsystem_device_id = pdev->id.subsystem_device_id;
+	hw->subsystem_vendor_id = pdev->id.subsystem_vendor_id;
 	hw->revision_id = 0;
-	hw->hw_addr = (void *)dev->pci_dev->mem_resource[0].addr;
+	hw->hw_addr = (void *)pdev->mem_resource[0].addr;
 	if (hw->hw_addr == NULL) {
 		PMD_INIT_LOG(ERR, "Bad mem resource."
 			" Try to blacklist unused devices.");
@@ -2921,20 +2929,20 @@ eth_fm10k_dev_init(struct rte_eth_dev *dev)
 	/*PF/VF has different interrupt handling mechanism */
 	if (hw->mac.type == fm10k_mac_pf) {
 		/* register callback func to eal lib */
-		rte_intr_callback_register(&(dev->pci_dev->intr_handle),
+		rte_intr_callback_register(intr_handle,
 			fm10k_dev_interrupt_handler_pf, (void *)dev);
 
 		/* enable MISC interrupt */
 		fm10k_dev_enable_intr_pf(dev);
 	} else { /* VF */
-		rte_intr_callback_register(&(dev->pci_dev->intr_handle),
+		rte_intr_callback_register(intr_handle,
 			fm10k_dev_interrupt_handler_vf, (void *)dev);
 
 		fm10k_dev_enable_intr_vf(dev);
 	}
 
 	/* Enable intr after callback registered */
-	rte_intr_enable(&(dev->pci_dev->intr_handle));
+	rte_intr_enable(intr_handle);
 
 	hw->mac.ops.update_int_moderator(hw);
 
@@ -3004,7 +3012,8 @@ static int
 eth_fm10k_dev_uninit(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-
+	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	PMD_INIT_FUNC_TRACE();
 
 	/* only uninitialize in the primary process */
@@ -3019,7 +3028,7 @@ eth_fm10k_dev_uninit(struct rte_eth_dev *dev)
 	dev->tx_pkt_burst = NULL;
 
 	/* disable uio/vfio intr */
-	rte_intr_disable(&(dev->pci_dev->intr_handle));
+	rte_intr_disable(intr_handle);
 
 	/*PF/VF has different interrupt handling mechanism */
 	if (hw->mac.type == fm10k_mac_pf) {
@@ -3027,13 +3036,13 @@ eth_fm10k_dev_uninit(struct rte_eth_dev *dev)
 		fm10k_dev_disable_intr_pf(dev);
 
 		/* unregister callback func to eal lib */
-		rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
+		rte_intr_callback_unregister(intr_handle,
 			fm10k_dev_interrupt_handler_pf, (void *)dev);
 	} else {
 		/* disable interrupt */
 		fm10k_dev_disable_intr_vf(dev);
 
-		rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
+		rte_intr_callback_unregister(intr_handle,
 			fm10k_dev_interrupt_handler_vf, (void *)dev);
 	}
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 14/23] qede: localize mapping of eth_dev to pci
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (12 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 13/23] fm10k: " Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 16:35   ` Harish Patil
  2016-12-21 15:09 ` [PATCH v4 15/23] szedata2: localize handling of pci resources Jan Blunck
                   ` (30 subsequent siblings)
  44 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

This simplifies later changes to ethdev.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/qede/qede_ethdev.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/qede/qede_ethdev.c b/drivers/net/qede/qede_ethdev.c
index d106dd0..a50bd5f 100644
--- a/drivers/net/qede/qede_ethdev.c
+++ b/drivers/net/qede/qede_ethdev.c
@@ -175,14 +175,14 @@ static void qede_interrupt_action(struct ecore_hwfn *p_hwfn)
 }
 
 static void
-qede_interrupt_handler(__rte_unused struct rte_intr_handle *handle, void *param)
+qede_interrupt_handler(struct rte_intr_handle *handle, void *param)
 {
 	struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)param;
 	struct qede_dev *qdev = eth_dev->data->dev_private;
 	struct ecore_dev *edev = &qdev->edev;
 
 	qede_interrupt_action(ECORE_LEADING_HWFN(edev));
-	if (rte_intr_enable(&eth_dev->pci_dev->intr_handle))
+	if (rte_intr_enable(handle))
 		DP_ERR(edev, "rte_intr_enable failed\n");
 }
 
@@ -809,6 +809,7 @@ static void qede_poll_sp_sb_cb(void *param)
 
 static void qede_dev_close(struct rte_eth_dev *eth_dev)
 {
+	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
 	struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
 	struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
 	int rc;
@@ -835,9 +836,9 @@ static void qede_dev_close(struct rte_eth_dev *eth_dev)
 
 	qdev->ops->common->remove(edev);
 
-	rte_intr_disable(&eth_dev->pci_dev->intr_handle);
+	rte_intr_disable(&pci_dev->intr_handle);
 
-	rte_intr_callback_unregister(&eth_dev->pci_dev->intr_handle,
+	rte_intr_callback_unregister(&pci_dev->intr_handle,
 				     qede_interrupt_handler, (void *)eth_dev);
 
 	if (edev->num_hwfns > 1)
@@ -1403,7 +1404,8 @@ static int qede_common_dev_init(struct rte_eth_dev *eth_dev, bool is_vf)
 	/* Extract key data structures */
 	adapter = eth_dev->data->dev_private;
 	edev = &adapter->edev;
-	pci_addr = eth_dev->pci_dev->addr;
+	pci_dev = eth_dev->pci_dev;
+	pci_addr = pci_dev->addr;
 
 	PMD_INIT_FUNC_TRACE(edev);
 
@@ -1420,8 +1422,6 @@ static int qede_common_dev_init(struct rte_eth_dev *eth_dev, bool is_vf)
 		return 0;
 	}
 
-	pci_dev = eth_dev->pci_dev;
-
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
 	qed_ops = qed_get_eth_ops();
@@ -1442,10 +1442,10 @@ static int qede_common_dev_init(struct rte_eth_dev *eth_dev, bool is_vf)
 
 	qede_update_pf_params(edev);
 
-	rte_intr_callback_register(&eth_dev->pci_dev->intr_handle,
+	rte_intr_callback_register(&pci_dev->intr_handle,
 				   qede_interrupt_handler, (void *)eth_dev);
 
-	if (rte_intr_enable(&eth_dev->pci_dev->intr_handle)) {
+	if (rte_intr_enable(&pci_dev->intr_handle)) {
 		DP_ERR(edev, "rte_intr_enable() failed\n");
 		return -ENODEV;
 	}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 15/23] szedata2: localize handling of pci resources
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (13 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 14/23] qede: localize mapping of " Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 16/23] nfp: localize rte_pci_device handling Jan Blunck
                   ` (29 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

This changes the driver to handle the PCI resource directly instead
of repeatedly going through eth_dev.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/szedata2/rte_eth_szedata2.c | 72 ++++++++++++++++++++-------------
 drivers/net/szedata2/rte_eth_szedata2.h | 58 +++++++++++---------------
 2 files changed, 67 insertions(+), 63 deletions(-)

diff --git a/drivers/net/szedata2/rte_eth_szedata2.c b/drivers/net/szedata2/rte_eth_szedata2.c
index f3cd52d..8dc94c5 100644
--- a/drivers/net/szedata2/rte_eth_szedata2.c
+++ b/drivers/net/szedata2/rte_eth_szedata2.c
@@ -91,6 +91,7 @@ struct pmd_internals {
 	uint16_t max_rx_queues;
 	uint16_t max_tx_queues;
 	char sze_dev[PATH_MAX];
+	struct rte_mem_resource *pci_rsc;
 };
 
 static struct ether_addr eth_addr = {
@@ -1144,8 +1145,10 @@ eth_link_update(struct rte_eth_dev *dev,
 	struct rte_eth_link link;
 	struct rte_eth_link *link_ptr = &link;
 	struct rte_eth_link *dev_link = &dev->data->dev_link;
+	struct pmd_internals *internals = (struct pmd_internals *)
+		dev->data->dev_private;
 	volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_IBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_ibuf *);
 
 	switch (cgmii_link_speed(ibuf)) {
@@ -1180,11 +1183,13 @@ eth_link_update(struct rte_eth_dev *dev,
 static int
 eth_dev_set_link_up(struct rte_eth_dev *dev)
 {
+	struct pmd_internals *internals = (struct pmd_internals *)
+		dev->data->dev_private;
 	volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_IBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_ibuf *);
 	volatile struct szedata2_cgmii_obuf *obuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_OBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_OBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_obuf *);
 
 	cgmii_ibuf_enable(ibuf);
@@ -1195,11 +1200,13 @@ eth_dev_set_link_up(struct rte_eth_dev *dev)
 static int
 eth_dev_set_link_down(struct rte_eth_dev *dev)
 {
+	struct pmd_internals *internals = (struct pmd_internals *)
+		dev->data->dev_private;
 	volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_IBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_ibuf *);
 	volatile struct szedata2_cgmii_obuf *obuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_OBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_OBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_obuf *);
 
 	cgmii_ibuf_disable(ibuf);
@@ -1281,8 +1288,10 @@ eth_mac_addr_set(struct rte_eth_dev *dev __rte_unused,
 static void
 eth_promiscuous_enable(struct rte_eth_dev *dev)
 {
+	struct pmd_internals *internals = (struct pmd_internals *)
+		dev->data->dev_private;
 	volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_IBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_ibuf *);
 	cgmii_ibuf_mac_mode_write(ibuf, SZEDATA2_MAC_CHMODE_PROMISC);
 }
@@ -1290,8 +1299,10 @@ eth_promiscuous_enable(struct rte_eth_dev *dev)
 static void
 eth_promiscuous_disable(struct rte_eth_dev *dev)
 {
+	struct pmd_internals *internals = (struct pmd_internals *)
+		dev->data->dev_private;
 	volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_IBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_ibuf *);
 	cgmii_ibuf_mac_mode_write(ibuf, SZEDATA2_MAC_CHMODE_ONLY_VALID);
 }
@@ -1299,8 +1310,10 @@ eth_promiscuous_disable(struct rte_eth_dev *dev)
 static void
 eth_allmulticast_enable(struct rte_eth_dev *dev)
 {
+	struct pmd_internals *internals = (struct pmd_internals *)
+		dev->data->dev_private;
 	volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_IBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_ibuf *);
 	cgmii_ibuf_mac_mode_write(ibuf, SZEDATA2_MAC_CHMODE_ALL_MULTICAST);
 }
@@ -1308,8 +1321,10 @@ eth_allmulticast_enable(struct rte_eth_dev *dev)
 static void
 eth_allmulticast_disable(struct rte_eth_dev *dev)
 {
+	struct pmd_internals *internals = (struct pmd_internals *)
+		dev->data->dev_private;
 	volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_IBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_ibuf *);
 	cgmii_ibuf_mac_mode_write(ibuf, SZEDATA2_MAC_CHMODE_ONLY_VALID);
 }
@@ -1349,7 +1364,7 @@ static const struct eth_dev_ops ops = {
  *          -1 on error
  */
 static int
-get_szedata2_index(struct rte_eth_dev *dev, uint32_t *index)
+get_szedata2_index(const struct rte_pci_addr *pcislot_addr, uint32_t *index)
 {
 	DIR *dir;
 	struct dirent *entry;
@@ -1357,7 +1372,6 @@ get_szedata2_index(struct rte_eth_dev *dev, uint32_t *index)
 	uint32_t tmp_index;
 	FILE *fd;
 	char pcislot_path[PATH_MAX];
-	struct rte_pci_addr pcislot_addr = dev->pci_dev->addr;
 	uint32_t domain;
 	uint32_t bus;
 	uint32_t devid;
@@ -1392,10 +1406,10 @@ get_szedata2_index(struct rte_eth_dev *dev, uint32_t *index)
 		if (ret != 4)
 			continue;
 
-		if (pcislot_addr.domain == domain &&
-				pcislot_addr.bus == bus &&
-				pcislot_addr.devid == devid &&
-				pcislot_addr.function == function) {
+		if (pcislot_addr->domain == domain &&
+				pcislot_addr->bus == bus &&
+				pcislot_addr->devid == devid &&
+				pcislot_addr->function == function) {
 			*index = tmp_index;
 			closedir(dir);
 			return 0;
@@ -1415,9 +1429,10 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 	struct szedata *szedata_temp;
 	int ret;
 	uint32_t szedata2_index;
-	struct rte_pci_addr *pci_addr = &dev->pci_dev->addr;
+	struct rte_pci_device *pci_dev = dev->pci_dev;
+	struct rte_pci_addr *pci_addr = &pci_dev->addr;
 	struct rte_mem_resource *pci_rsc =
-		&dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER];
+		&pci_dev->mem_resource[PCI_RESOURCE_NUMBER];
 	char rsc_filename[PATH_MAX];
 	void *pci_resource_ptr = NULL;
 	int fd;
@@ -1427,7 +1442,7 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 			pci_addr->function);
 
 	/* Get index of szedata2 device file and create path to device file */
-	ret = get_szedata2_index(dev, &szedata2_index);
+	ret = get_szedata2_index(pci_addr, &szedata2_index);
 	if (ret != 0) {
 		RTE_LOG(ERR, PMD, "Failed to get szedata2 device index!\n");
 		return -ENODEV;
@@ -1471,10 +1486,10 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 	/* Set function callbacks for Ethernet API */
 	dev->dev_ops = &ops;
 
-	rte_eth_copy_pci_info(dev, dev->pci_dev);
+	rte_eth_copy_pci_info(dev, pci_dev);
 
 	/* mmap pci resource0 file to rte_mem_resource structure */
-	if (dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].phys_addr ==
+	if (pci_dev->mem_resource[PCI_RESOURCE_NUMBER].phys_addr ==
 			0) {
 		RTE_LOG(ERR, PMD, "Missing resource%u file\n",
 				PCI_RESOURCE_NUMBER);
@@ -1491,7 +1506,7 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 	}
 
 	pci_resource_ptr = mmap(0,
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len,
+			pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len,
 			PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 	close(fd);
 	if (pci_resource_ptr == NULL) {
@@ -1499,8 +1514,8 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 				rsc_filename, fd);
 		return -EINVAL;
 	}
-	dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr =
-		pci_resource_ptr;
+	pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr = pci_resource_ptr;
+	internals->pci_rsc = pci_rsc;
 
 	RTE_LOG(DEBUG, PMD, "resource%u phys_addr = 0x%llx len = %llu "
 			"virt addr = %llx\n", PCI_RESOURCE_NUMBER,
@@ -1516,8 +1531,8 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 			RTE_CACHE_LINE_SIZE);
 	if (data->mac_addrs == NULL) {
 		RTE_LOG(ERR, PMD, "Could not alloc space for MAC address!\n");
-		munmap(dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr,
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len);
+		munmap(pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr,
+		       pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len);
 		return -EINVAL;
 	}
 
@@ -1537,12 +1552,13 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 static int
 rte_szedata2_eth_dev_uninit(struct rte_eth_dev *dev)
 {
-	struct rte_pci_addr *pci_addr = &dev->pci_dev->addr;
+	struct rte_pci_device *pci_dev = dev->pci_dev;
+	struct rte_pci_addr *pci_addr = &pci_dev->addr;
 
 	rte_free(dev->data->mac_addrs);
 	dev->data->mac_addrs = NULL;
-	munmap(dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr,
-		dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len);
+	munmap(pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr,
+	       pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len);
 
 	RTE_LOG(INFO, PMD, "szedata2 device ("
 			PCI_PRI_FMT ") successfully uninitialized\n",
diff --git a/drivers/net/szedata2/rte_eth_szedata2.h b/drivers/net/szedata2/rte_eth_szedata2.h
index 522cf47..3b90924 100644
--- a/drivers/net/szedata2/rte_eth_szedata2.h
+++ b/drivers/net/szedata2/rte_eth_szedata2.h
@@ -117,94 +117,82 @@ struct szedata {
  * @return Byte from PCI resource at offset "offset".
  */
 static inline uint8_t
-pci_resource_read8(struct rte_eth_dev *dev, uint32_t offset)
+pci_resource_read8(struct rte_mem_resource *rsc, uint32_t offset)
 {
-	return *((uint8_t *)((uint8_t *)
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr +
-			offset));
+	return *((uint8_t *)((uint8_t *)rsc->addr + offset));
 }
 
 /*
  * @return Two bytes from PCI resource starting at offset "offset".
  */
 static inline uint16_t
-pci_resource_read16(struct rte_eth_dev *dev, uint32_t offset)
+pci_resource_read16(struct rte_mem_resource *rsc, uint32_t offset)
 {
-	return rte_le_to_cpu_16(*((uint16_t *)((uint8_t *)
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr +
-			offset)));
+	return rte_le_to_cpu_16(*((uint16_t *)((uint8_t *)rsc->addr +
+					       offset)));
 }
 
 /*
  * @return Four bytes from PCI resource starting at offset "offset".
  */
 static inline uint32_t
-pci_resource_read32(struct rte_eth_dev *dev, uint32_t offset)
+pci_resource_read32(struct rte_mem_resource *rsc, uint32_t offset)
 {
-	return rte_le_to_cpu_32(*((uint32_t *)((uint8_t *)
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr +
-			offset)));
+	return rte_le_to_cpu_32(*((uint32_t *)((uint8_t *)rsc->addr +
+					       offset)));
 }
 
 /*
  * @return Eight bytes from PCI resource starting at offset "offset".
  */
 static inline uint64_t
-pci_resource_read64(struct rte_eth_dev *dev, uint32_t offset)
+pci_resource_read64(struct rte_mem_resource *rsc, uint32_t offset)
 {
-	return rte_le_to_cpu_64(*((uint64_t *)((uint8_t *)
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr +
-			offset)));
+	return rte_le_to_cpu_64(*((uint64_t *)((uint8_t *)rsc->addr +
+					       offset)));
 }
 
 /*
  * Write one byte to PCI resource address space at offset "offset".
  */
 static inline void
-pci_resource_write8(struct rte_eth_dev *dev, uint32_t offset, uint8_t val)
+pci_resource_write8(struct rte_mem_resource *rsc, uint32_t offset, uint8_t val)
 {
-	*((uint8_t *)((uint8_t *)
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr +
-			offset)) = val;
+	*((uint8_t *)((uint8_t *)rsc->addr + offset)) = val;
 }
 
 /*
  * Write two bytes to PCI resource address space at offset "offset".
  */
 static inline void
-pci_resource_write16(struct rte_eth_dev *dev, uint32_t offset, uint16_t val)
+pci_resource_write16(struct rte_mem_resource *rsc, uint32_t offset,
+		     uint16_t val)
 {
-	*((uint16_t *)((uint8_t *)
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr +
-			offset)) = rte_cpu_to_le_16(val);
+	*((uint16_t *)((uint8_t *)rsc->addr + offset)) = rte_cpu_to_le_16(val);
 }
 
 /*
  * Write four bytes to PCI resource address space at offset "offset".
  */
 static inline void
-pci_resource_write32(struct rte_eth_dev *dev, uint32_t offset, uint32_t val)
+pci_resource_write32(struct rte_mem_resource *rsc, uint32_t offset,
+		     uint32_t val)
 {
-	*((uint32_t *)((uint8_t *)
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr +
-			offset)) = rte_cpu_to_le_32(val);
+	*((uint32_t *)((uint8_t *)rsc->addr + offset)) = rte_cpu_to_le_32(val);
 }
 
 /*
  * Write eight bytes to PCI resource address space at offset "offset".
  */
 static inline void
-pci_resource_write64(struct rte_eth_dev *dev, uint32_t offset, uint64_t val)
+pci_resource_write64(struct rte_mem_resource *rsc, uint32_t offset,
+		     uint64_t val)
 {
-	*((uint64_t *)((uint8_t *)
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr +
-			offset)) = rte_cpu_to_le_64(val);
+	*((uint64_t *)((uint8_t *)rsc->addr + offset)) = rte_cpu_to_le_64(val);
 }
 
 #define SZEDATA2_PCI_RESOURCE_PTR(dev, offset, type) \
-	((type)((uint8_t *) \
-	((dev)->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr) \
-	+ (offset)))
+	((type)((uint8_t *)(rsc)->addr) + (offset)))
 
 enum szedata2_link_speed {
 	SZEDATA2_LINK_SPEED_DEFAULT = 0,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 16/23] nfp: localize rte_pci_device handling
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (14 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 15/23] szedata2: localize handling of pci resources Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 17/23] vmxnet3: use eth_dev->data->drv_name instead of pci_drv name Jan Blunck
                   ` (28 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

This simplifies later changes to ethdev.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/nfp/nfp_net.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index de80b46..2609f97 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -718,10 +718,12 @@ static void
 nfp_net_close(struct rte_eth_dev *dev)
 {
 	struct nfp_net_hw *hw;
+	struct rte_pci_device *pci_dev;
 
 	PMD_INIT_LOG(DEBUG, "Close\n");
 
 	hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	pci_dev = dev->pci_dev;
 
 	/*
 	 * We assume that the DPDK application is stopping all the
@@ -730,11 +732,11 @@ nfp_net_close(struct rte_eth_dev *dev)
 
 	nfp_net_stop(dev);
 
-	rte_intr_disable(&dev->pci_dev->intr_handle);
+	rte_intr_disable(&pci_dev->intr_handle);
 	nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff);
 
 	/* unregister callback func from eal lib */
-	rte_intr_callback_unregister(&dev->pci_dev->intr_handle,
+	rte_intr_callback_unregister(&pci_dev->intr_handle,
 				     nfp_net_dev_interrupt_handler,
 				     (void *)dev);
 
@@ -1122,6 +1124,7 @@ nfp_net_rx_queue_count(struct rte_eth_dev *dev, uint16_t queue_idx)
 static void
 nfp_net_dev_link_status_print(struct rte_eth_dev *dev)
 {
+	struct rte_pci_device *pci_dev = dev->pci_dev;
 	struct rte_eth_link link;
 
 	memset(&link, 0, sizeof(link));
@@ -1136,8 +1139,8 @@ nfp_net_dev_link_status_print(struct rte_eth_dev *dev)
 			(int)(dev->data->port_id));
 
 	RTE_LOG(INFO, PMD, "PCI Address: %04d:%02d:%02d:%d\n",
-		dev->pci_dev->addr.domain, dev->pci_dev->addr.bus,
-		dev->pci_dev->addr.devid, dev->pci_dev->addr.function);
+		pci_dev->addr.domain, pci_dev->addr.bus,
+		pci_dev->addr.devid, pci_dev->addr.function);
 }
 
 /* Interrupt configuration and handling */
@@ -1152,13 +1155,15 @@ static void
 nfp_net_irq_unmask(struct rte_eth_dev *dev)
 {
 	struct nfp_net_hw *hw;
+	struct rte_pci_device *pci_dev;
 
 	hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	pci_dev = dev->pci_dev;
 
 	if (hw->ctrl & NFP_NET_CFG_CTRL_MSIXAUTO) {
 		/* If MSI-X auto-masking is used, clear the entry */
 		rte_wmb();
-		rte_intr_enable(&dev->pci_dev->intr_handle);
+		rte_intr_enable(&pci_dev->intr_handle);
 	} else {
 		/* Make sure all updates are written before un-masking */
 		rte_wmb();
@@ -2400,7 +2405,6 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
 		     hw->cap & NFP_NET_CFG_CTRL_LSO     ? "TSO "     : "",
 		     hw->cap & NFP_NET_CFG_CTRL_RSS     ? "RSS "     : "");
 
-	pci_dev = eth_dev->pci_dev;
 	hw->ctrl = 0;
 
 	hw->stride_rx = stride;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 17/23] vmxnet3: use eth_dev->data->drv_name instead of pci_drv name
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (15 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 16/23] nfp: localize rte_pci_device handling Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 18/23] ethdev: Helper to map to struct rte_pci_device Jan Blunck
                   ` (27 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/vmxnet3/vmxnet3_ethdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.c b/drivers/net/vmxnet3/vmxnet3_ethdev.c
index 8bb13e5..20a7966 100644
--- a/drivers/net/vmxnet3/vmxnet3_ethdev.c
+++ b/drivers/net/vmxnet3/vmxnet3_ethdev.c
@@ -138,7 +138,7 @@ gpa_zone_reserve(struct rte_eth_dev *dev, uint32_t size,
 	const struct rte_memzone *mz;
 
 	snprintf(z_name, sizeof(z_name), "%s_%d_%s",
-		 dev->driver->pci_drv.driver.name, dev->data->port_id, post_string);
+		 dev->data->drv_name, dev->data->port_id, post_string);
 
 	mz = rte_memzone_lookup(z_name);
 	if (!reuse) {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 18/23] ethdev: Helper to map to struct rte_pci_device
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (16 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 17/23] vmxnet3: use eth_dev->data->drv_name instead of pci_drv name Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-22 15:21   ` Thomas Monjalon
  2016-12-21 15:09 ` [PATCH v4 19/23] drivers: Replace per-PMD macros with rte_eth_dev_to_pci() helper Jan Blunck
                   ` (26 subsequent siblings)
  44 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

PCI drivers could use this helper instead of directly accessing fields of
rte_eth_dev to map to rte_pci_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_ether/rte_ethdev.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 9678179..d6e367c 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1644,6 +1644,16 @@ struct rte_eth_dev {
 	uint8_t attached; /**< Flag indicating the port is attached */
 } __rte_cache_aligned;
 
+/**
+ * @internal
+ * Helper for drivers that need to convert from rte_eth_dev to rte_pci_device.
+ */
+static inline struct rte_pci_device *__attribute__((always_inline))
+rte_eth_dev_to_pci(struct rte_eth_dev *eth_dev)
+{
+	return eth_dev->pci_dev;
+}
+
 struct rte_eth_dev_sriov {
 	uint8_t active;               /**< SRIOV is active with 16, 32 or 64 pools */
 	uint8_t nb_q_per_pool;        /**< rx queue number per pool */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 19/23] drivers: Replace per-PMD macros with rte_eth_dev_to_pci() helper
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (17 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 18/23] ethdev: Helper to map to struct rte_pci_device Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 20/23] drivers: Use " Jan Blunck
                   ` (25 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

Instead of duplicating this macro with different names lets use the helper
provided by ethdev.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/e1000/e1000_ethdev.h  |  2 --
 drivers/net/e1000/em_ethdev.c     | 13 ++++++-------
 drivers/net/e1000/igb_ethdev.c    | 25 +++++++++++++------------
 drivers/net/e1000/igb_pf.c        |  2 +-
 drivers/net/i40e/i40e_ethdev.c    | 30 +++++++++++++++---------------
 drivers/net/i40e/i40e_ethdev.h    |  3 ---
 drivers/net/i40e/i40e_ethdev_vf.c | 18 +++++++++---------
 drivers/net/ixgbe/ixgbe_ethdev.c  | 38 +++++++++++++++++++-------------------
 drivers/net/ixgbe/ixgbe_ethdev.h  |  3 ---
 drivers/net/ixgbe/ixgbe_pf.c      |  2 +-
 10 files changed, 64 insertions(+), 72 deletions(-)

diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h
index 134f8b9..6c25c8d 100644
--- a/drivers/net/e1000/e1000_ethdev.h
+++ b/drivers/net/e1000/e1000_ethdev.h
@@ -286,8 +286,6 @@ struct e1000_adapter {
 #define E1000_DEV_PRIVATE_TO_FILTER_INFO(adapter) \
 	(&((struct e1000_adapter *)adapter)->filter)
 
-#define E1000_DEV_TO_PCI(eth_dev) \
-	(eth_dev->pci_dev)
 /*
  * RX/TX IGB function prototypes
  */
diff --git a/drivers/net/e1000/em_ethdev.c b/drivers/net/e1000/em_ethdev.c
index 014e575..b4160f2 100644
--- a/drivers/net/e1000/em_ethdev.c
+++ b/drivers/net/e1000/em_ethdev.c
@@ -288,7 +288,7 @@ eth_em_dev_is_ich8(struct e1000_hw *hw)
 static int
 eth_em_dev_init(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(eth_dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(eth_dev->data->dev_private);
@@ -360,7 +360,7 @@ eth_em_dev_init(struct rte_eth_dev *eth_dev)
 static int
 eth_em_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(eth_dev);
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(eth_dev->data->dev_private);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
@@ -555,8 +555,7 @@ eth_em_start(struct rte_eth_dev *dev)
 		E1000_DEV_PRIVATE(dev->data->dev_private);
 	struct e1000_hw *hw =
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pci_dev =
-		E1000_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	int ret, mask;
 	uint32_t intr_vector = 0;
@@ -739,7 +738,7 @@ eth_em_stop(struct rte_eth_dev *dev)
 {
 	struct rte_eth_link link;
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	em_rxq_intr_disable(hw);
@@ -1001,7 +1000,7 @@ static int
 eth_em_rx_queue_intr_enable(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id)
 {
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	em_rxq_intr_enable(hw);
@@ -1543,7 +1542,7 @@ static int
 eth_em_interrupt_action(struct rte_eth_dev *dev,
 			struct rte_intr_handle *intr_handle)
 {
-	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct e1000_hw *hw =
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct e1000_interrupt *intr =
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index e0115ea..f0e5271 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -745,7 +745,7 @@ static int
 eth_igb_dev_init(struct rte_eth_dev *eth_dev)
 {
 	int error = 0;
-	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(eth_dev);
 	struct e1000_hw *hw =
 		E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
 	struct e1000_vfta * shadow_vfta =
@@ -919,7 +919,7 @@ eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
 		return -EPERM;
 
 	hw = E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
-	pci_dev = E1000_DEV_TO_PCI(eth_dev);
+	pci_dev = rte_eth_dev_to_pci(eth_dev);
 	intr_handle = &pci_dev->intr_handle;
 
 	if (adapter->stopped == 0)
@@ -976,7 +976,8 @@ eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
 		return 0;
 	}
 
-	pci_dev = E1000_DEV_TO_PCI(eth_dev);
+	pci_dev = rte_eth_dev_to_pci(eth_dev);
+
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
 	hw->device_id = pci_dev->id.device_id;
@@ -1052,7 +1053,7 @@ eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
 {
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(eth_dev->data->dev_private);
-	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(eth_dev);
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -1219,7 +1220,7 @@ eth_igb_start(struct rte_eth_dev *dev)
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(dev->data->dev_private);
-	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	int ret, mask;
 	uint32_t intr_vector = 0;
@@ -1428,7 +1429,7 @@ eth_igb_stop(struct rte_eth_dev *dev)
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct e1000_filter_info *filter_info =
 		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
-	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_eth_link link;
 	struct e1000_flex_filter *p_flex;
 	struct e1000_5tuple_filter *p_5tuple, *p_5tuple_next;
@@ -1533,7 +1534,7 @@ eth_igb_close(struct rte_eth_dev *dev)
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(dev->data->dev_private);
 	struct rte_eth_link link;
-	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	eth_igb_stop(dev);
@@ -2644,7 +2645,7 @@ eth_igb_interrupt_action(struct rte_eth_dev *dev,
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct e1000_interrupt *intr =
 		E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
-	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	uint32_t tctl, rctl;
 	struct rte_eth_link link;
 	int ret;
@@ -3060,7 +3061,7 @@ igbvf_dev_start(struct rte_eth_dev *dev)
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(dev->data->dev_private);
-	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	int ret;
 	uint32_t intr_vector = 0;
@@ -3116,7 +3117,7 @@ igbvf_dev_start(struct rte_eth_dev *dev)
 static void
 igbvf_dev_stop(struct rte_eth_dev *dev)
 {
-	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	PMD_INIT_FUNC_TRACE();
@@ -5102,7 +5103,7 @@ eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
 	struct e1000_hw *hw =
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t mask = 1 << queue_id;
 	uint32_t regval;
@@ -5175,7 +5176,7 @@ eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
 	uint32_t vec = E1000_MISC_VEC_ID;
 	uint32_t base = E1000_MISC_VEC_ID;
 	uint32_t misc_shift = 0;
-	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	/* won't configure msix register if no mapping is done
diff --git a/drivers/net/e1000/igb_pf.c b/drivers/net/e1000/igb_pf.c
index 67da3c2..62ff58f 100644
--- a/drivers/net/e1000/igb_pf.c
+++ b/drivers/net/e1000/igb_pf.c
@@ -57,7 +57,7 @@
 static inline uint16_t
 dev_num_vf(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(eth_dev);
 
 	return pci_dev->max_vfs;
 }
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index ba5795e..51a90e8 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -907,7 +907,7 @@ is_floating_veb_supported(struct rte_devargs *devargs)
 static void
 config_floating_veb(struct rte_eth_dev *dev)
 {
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
@@ -953,7 +953,7 @@ eth_i40e_dev_init(struct rte_eth_dev *dev)
 		i40e_set_tx_function(dev);
 		return 0;
 	}
-	pci_dev = I40E_DEV_TO_PCI(dev);
+	pci_dev = rte_eth_dev_to_pci(dev);
 	intr_handle = &pci_dev->intr_handle;
 
 	rte_eth_copy_pci_info(dev, pci_dev);
@@ -1218,7 +1218,7 @@ eth_i40e_dev_uninit(struct rte_eth_dev *dev)
 		return 0;
 
 	hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	pci_dev = I40E_DEV_TO_PCI(dev);
+	pci_dev = rte_eth_dev_to_pci(dev);
 	intr_handle = &pci_dev->intr_handle;
 
 	if (hw->adapter_stopped == 0)
@@ -1339,7 +1339,7 @@ void
 i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
 {
 	struct rte_eth_dev *dev = vsi->adapter->eth_dev;
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
 	uint16_t msix_vect = vsi->msix_intr;
@@ -1453,7 +1453,7 @@ void
 i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi)
 {
 	struct rte_eth_dev *dev = vsi->adapter->eth_dev;
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
 	uint16_t msix_vect = vsi->msix_intr;
@@ -1525,7 +1525,7 @@ static void
 i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
 {
 	struct rte_eth_dev *dev = vsi->adapter->eth_dev;
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
 	uint16_t interval = i40e_calc_itr_interval(\
@@ -1557,7 +1557,7 @@ static void
 i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
 {
 	struct rte_eth_dev *dev = vsi->adapter->eth_dev;
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
 	uint16_t msix_intr, i;
@@ -1683,7 +1683,7 @@ i40e_dev_start(struct rte_eth_dev *dev)
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct i40e_vsi *main_vsi = pf->main_vsi;
 	int ret, i;
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t intr_vector = 0;
 
@@ -1817,7 +1817,7 @@ i40e_dev_stop(struct rte_eth_dev *dev)
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_vsi *main_vsi = pf->main_vsi;
 	struct i40e_mirror_rule *p_mirror;
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	int i;
 
@@ -1869,7 +1869,7 @@ i40e_dev_close(struct rte_eth_dev *dev)
 {
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t reg;
 	int i;
@@ -2594,7 +2594,7 @@ i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct i40e_vsi *vsi = pf->main_vsi;
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 
 	dev_info->max_rx_queues = vsi->nb_qps;
 	dev_info->max_tx_queues = vsi->nb_qps;
@@ -3503,7 +3503,7 @@ i40e_pf_parameter_init(struct rte_eth_dev *dev)
 {
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_PF_TO_HW(pf);
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	uint16_t qp_count = 0, vsi_count = 0;
 
 	if (pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
@@ -8138,7 +8138,7 @@ i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
 static void
 i40e_enable_extended_tag(struct rte_eth_dev *dev)
 {
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	uint32_t buf = 0;
 	int ret;
 
@@ -9570,7 +9570,7 @@ i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
 static int
 i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint16_t interval =
@@ -9604,7 +9604,7 @@ i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 static int
 i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint16_t msix_intr;
diff --git a/drivers/net/i40e/i40e_ethdev.h b/drivers/net/i40e/i40e_ethdev.h
index da8dd7e..298cef4 100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -617,9 +617,6 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
 void i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
 	struct rte_eth_txq_info *qinfo);
 
-#define I40E_DEV_TO_PCI(eth_dev) \
-	(eth_dev->pci_dev)
-
 /* I40E_DEV_PRIVATE_TO */
 #define I40E_DEV_PRIVATE_TO_PF(adapter) \
 	(&((struct i40e_adapter *)adapter)->pf)
diff --git a/drivers/net/i40e/i40e_ethdev_vf.c b/drivers/net/i40e/i40e_ethdev_vf.c
index a4d8a66..fbb9e02 100644
--- a/drivers/net/i40e/i40e_ethdev_vf.c
+++ b/drivers/net/i40e/i40e_ethdev_vf.c
@@ -718,7 +718,7 @@ i40evf_config_irq_map(struct rte_eth_dev *dev)
 	uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_irq_map_info) + \
 		sizeof(struct i40e_virtchnl_vector_map)];
 	struct i40e_virtchnl_irq_map_info *map_info;
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t vector_id;
 	int i, err;
@@ -1440,7 +1440,7 @@ i40evf_dev_init(struct rte_eth_dev *eth_dev)
 {
 	struct i40e_hw *hw
 		= I40E_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(eth_dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(eth_dev);
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -1854,7 +1854,7 @@ i40evf_enable_queues_intr(struct rte_eth_dev *dev)
 {
 	struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	if (!rte_intr_allow_others(intr_handle)) {
@@ -1887,7 +1887,7 @@ i40evf_disable_queues_intr(struct rte_eth_dev *dev)
 {
 	struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	if (!rte_intr_allow_others(intr_handle)) {
@@ -1914,7 +1914,7 @@ i40evf_disable_queues_intr(struct rte_eth_dev *dev)
 static int
 i40evf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint16_t interval =
@@ -1949,7 +1949,7 @@ i40evf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 static int
 i40evf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint16_t msix_intr;
@@ -2030,7 +2030,7 @@ i40evf_dev_start(struct rte_eth_dev *dev)
 {
 	struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t intr_vector = 0;
 
@@ -2096,7 +2096,7 @@ i40evf_dev_start(struct rte_eth_dev *dev)
 static void
 i40evf_dev_stop(struct rte_eth_dev *dev)
 {
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	PMD_INIT_FUNC_TRACE();
@@ -2292,7 +2292,7 @@ static void
 i40evf_dev_close(struct rte_eth_dev *dev)
 {
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	i40evf_dev_stop(dev);
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 2d05751..44aafa3 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -1084,7 +1084,7 @@ ixgbe_swfw_lock_reset(struct ixgbe_hw *hw)
 static int
 eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(eth_dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
@@ -1293,7 +1293,7 @@ eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev)
 static int
 eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(eth_dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw;
 
@@ -1381,7 +1381,7 @@ eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
 {
 	int diag;
 	uint32_t tc, tcs;
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(eth_dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
@@ -1529,7 +1529,7 @@ eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
 static int
 eth_ixgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(eth_dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw;
 
@@ -1945,7 +1945,7 @@ ixgbe_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
 static int
 ixgbe_check_vf_rss_rxq_num(struct rte_eth_dev *dev, uint16_t nb_rx_q)
 {
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 
 	switch (nb_rx_q) {
 	case 1:
@@ -2191,7 +2191,7 @@ ixgbe_dev_start(struct rte_eth_dev *dev)
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct ixgbe_vf_info *vfinfo =
 		*IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t intr_vector = 0;
 	int err, link_up = 0, negotiate = 0;
@@ -2408,7 +2408,7 @@ ixgbe_dev_stop(struct rte_eth_dev *dev)
 	struct ixgbe_filter_info *filter_info =
 		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
 	struct ixgbe_5tuple_filter *p_5tuple, *p_5tuple_next;
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	int vf;
 
@@ -3031,7 +3031,7 @@ ixgbevf_dev_stats_reset(struct rte_eth_dev *dev)
 static void
 ixgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
 
@@ -3164,7 +3164,7 @@ static void
 ixgbevf_dev_info_get(struct rte_eth_dev *dev,
 		     struct rte_eth_dev_info *dev_info)
 {
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
 	dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
@@ -3435,7 +3435,7 @@ ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev)
 static void
 ixgbe_dev_link_status_print(struct rte_eth_dev *dev)
 {
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_eth_link link;
 
 	memset(&link, 0, sizeof(link));
@@ -3544,7 +3544,7 @@ static void
 ixgbe_dev_interrupt_delayed_handler(void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_interrupt *intr =
 		IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
@@ -4202,7 +4202,7 @@ ixgbevf_dev_start(struct rte_eth_dev *dev)
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint32_t intr_vector = 0;
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	int err, mask = 0;
@@ -4266,7 +4266,7 @@ static void
 ixgbevf_dev_stop(struct rte_eth_dev *dev)
 {
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	PMD_INIT_FUNC_TRACE();
@@ -5069,7 +5069,7 @@ ixgbe_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t rule_id)
 static int
 ixgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t mask;
 	struct ixgbe_hw *hw =
@@ -5103,7 +5103,7 @@ ixgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 static int
 ixgbe_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t mask;
 	struct ixgbe_hw *hw =
@@ -5228,7 +5228,7 @@ ixgbe_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
 static void
 ixgbevf_configure_msix(struct rte_eth_dev *dev)
 {
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -5262,7 +5262,7 @@ ixgbevf_configure_msix(struct rte_eth_dev *dev)
 static void
 ixgbe_configure_msix(struct rte_eth_dev *dev)
 {
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -5381,7 +5381,7 @@ static int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
 static int ixgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
 	uint16_t tx_rate, uint64_t q_msk)
 {
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct ixgbe_vf_info *vfinfo =
 		*(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
@@ -7209,7 +7209,7 @@ ixgbe_e_tag_insertion_en_dis(struct rte_eth_dev *dev,
 			     struct rte_eth_l2_tunnel_conf *l2_tunnel,
 			     bool en)
 {
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	int ret = 0;
 	uint32_t vmtir, vmvir;
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h
index a0e02aa..4ff6338 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.h
+++ b/drivers/net/ixgbe/ixgbe_ethdev.h
@@ -291,9 +291,6 @@ struct ixgbe_adapter {
 	struct rte_timecounter      tx_tstamp_tc;
 };
 
-#define IXGBE_DEV_TO_PCI(eth_dev) \
-	(eth_dev->pci_dev)
-
 #define IXGBE_DEV_PRIVATE_TO_HW(adapter)\
 	(&((struct ixgbe_adapter *)adapter)->hw)
 
diff --git a/drivers/net/ixgbe/ixgbe_pf.c b/drivers/net/ixgbe/ixgbe_pf.c
index cb10265..1ccc1dd 100644
--- a/drivers/net/ixgbe/ixgbe_pf.c
+++ b/drivers/net/ixgbe/ixgbe_pf.c
@@ -61,7 +61,7 @@
 static inline uint16_t
 dev_num_vf(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(eth_dev);
 
 	return pci_dev->max_vfs;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 20/23] drivers: Use rte_eth_dev_to_pci() helper
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (18 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 19/23] drivers: Replace per-PMD macros with rte_eth_dev_to_pci() helper Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 15:09 ` [PATCH v4 21/23] ethdev: Move filling of rte_eth_dev_info->pci_dev to dev_infos_get() Jan Blunck
                   ` (24 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

The drivers should not directly access the rte_eth_dev->pci_dev but use
a helper instead. This is a preparation for replacing the pci_dev with
a struct rte_device member in the future.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 drivers/net/bnx2x/bnx2x_ethdev.c        |  2 +-
 drivers/net/bnxt/bnxt_ethdev.c          |  4 ++--
 drivers/net/cxgbe/cxgbe_ethdev.c        |  2 +-
 drivers/net/ena/ena_ethdev.c            |  2 +-
 drivers/net/enic/enic_ethdev.c          |  2 +-
 drivers/net/fm10k/fm10k_ethdev.c        | 16 ++++++++--------
 drivers/net/nfp/nfp_net.c               |  8 ++++----
 drivers/net/qede/qede_ethdev.c          |  4 ++--
 drivers/net/szedata2/rte_eth_szedata2.c |  4 ++--
 drivers/net/thunderx/nicvf_ethdev.c     |  5 +++--
 drivers/net/virtio/virtio_ethdev.c      |  2 +-
 drivers/net/vmxnet3/vmxnet3_ethdev.c    |  2 +-
 12 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/drivers/net/bnx2x/bnx2x_ethdev.c b/drivers/net/bnx2x/bnx2x_ethdev.c
index ef2026a..f59488e 100644
--- a/drivers/net/bnx2x/bnx2x_ethdev.c
+++ b/drivers/net/bnx2x/bnx2x_ethdev.c
@@ -516,7 +516,7 @@ bnx2x_common_dev_init(struct rte_eth_dev *eth_dev, int is_vf)
 	PMD_INIT_FUNC_TRACE();
 
 	eth_dev->dev_ops = is_vf ? &bnx2xvf_eth_dev_ops : &bnx2x_eth_dev_ops;
-	pci_dev = eth_dev->pci_dev;
+	pci_dev = rte_eth_dev_to_pci(eth_dev);
 
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index 529b6c8..2864ef3 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -1012,7 +1012,7 @@ static bool bnxt_vf_pciid(uint16_t id)
 static int bnxt_init_board(struct rte_eth_dev *eth_dev)
 {
 	struct bnxt *bp = eth_dev->data->dev_private;
-	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(eth_dev);
 	int rc;
 
 	/* enable device (incl. PCI PM wakeup), and bus-mastering */
@@ -1046,7 +1046,7 @@ static int bnxt_init_board(struct rte_eth_dev *eth_dev)
 static int
 bnxt_dev_init(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(eth_dev);
 	static int version_printed;
 	struct bnxt *bp;
 	int rc;
diff --git a/drivers/net/cxgbe/cxgbe_ethdev.c b/drivers/net/cxgbe/cxgbe_ethdev.c
index b7f28eb..bb1f3b3 100644
--- a/drivers/net/cxgbe/cxgbe_ethdev.c
+++ b/drivers/net/cxgbe/cxgbe_ethdev.c
@@ -1005,7 +1005,7 @@ static int eth_cxgbe_dev_init(struct rte_eth_dev *eth_dev)
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return 0;
 
-	pci_dev = eth_dev->pci_dev;
+	pci_dev = rte_eth_dev_to_pci(eth_dev);
 
 	snprintf(name, sizeof(name), "cxgbeadapter%d", eth_dev->data->port_id);
 	adapter = rte_zmalloc(name, sizeof(*adapter), 0);
diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
index ab9a178..552d3ed 100644
--- a/drivers/net/ena/ena_ethdev.c
+++ b/drivers/net/ena/ena_ethdev.c
@@ -1278,7 +1278,7 @@ static int eth_ena_dev_init(struct rte_eth_dev *eth_dev)
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return 0;
 
-	pci_dev = eth_dev->pci_dev;
+	pci_dev = rte_eth_dev_to_pci(eth_dev);
 	adapter->pdev = pci_dev;
 
 	PMD_INIT_LOG(INFO, "Initializing %x:%x:%x.%d\n",
diff --git a/drivers/net/enic/enic_ethdev.c b/drivers/net/enic/enic_ethdev.c
index 2b154ec..92df191 100644
--- a/drivers/net/enic/enic_ethdev.c
+++ b/drivers/net/enic/enic_ethdev.c
@@ -621,7 +621,7 @@ static int eth_enicpmd_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->rx_pkt_burst = &enic_recv_pkts;
 	eth_dev->tx_pkt_burst = &enic_xmit_pkts;
 
-	pdev = eth_dev->pci_dev;
+	pdev = rte_eth_dev_to_pci(eth_dev);
 	rte_eth_copy_pci_info(eth_dev, pdev);
 	enic->pdev = pdev;
 	addr = &pdev->addr;
diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c
index 2f6c628..140e235 100644
--- a/drivers/net/fm10k/fm10k_ethdev.c
+++ b/drivers/net/fm10k/fm10k_ethdev.c
@@ -711,7 +711,7 @@ fm10k_dev_rx_init(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct fm10k_macvlan_filter_info *macvlan;
-	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_pci_device *pdev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	int i, ret;
 	struct fm10k_rx_queue *rxq;
@@ -1172,7 +1172,7 @@ static void
 fm10k_dev_stop(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_pci_device *pdev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	int i;
 
@@ -1389,7 +1389,7 @@ fm10k_dev_infos_get(struct rte_eth_dev *dev,
 	struct rte_eth_dev_info *dev_info)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_pci_device *pdev = rte_eth_dev_to_pci(dev);
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -2336,7 +2336,7 @@ static int
 fm10k_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_pci_device *pdev = rte_eth_dev_to_pci(dev);
 
 	/* Enable ITR */
 	if (hw->mac.type == fm10k_mac_pf)
@@ -2353,7 +2353,7 @@ static int
 fm10k_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_pci_device *pdev = rte_eth_dev_to_pci(dev);
 
 	/* Disable ITR */
 	if (hw->mac.type == fm10k_mac_pf)
@@ -2369,7 +2369,7 @@ static int
 fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_pci_device *pdev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	uint32_t intr_vector, vec;
 	uint16_t queue_id;
@@ -2833,7 +2833,7 @@ static int
 eth_fm10k_dev_init(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_pci_device *pdev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	int diag, i;
 	struct fm10k_macvlan_filter_info *macvlan;
@@ -3012,7 +3012,7 @@ static int
 eth_fm10k_dev_uninit(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_pci_device *pdev = rte_eth_dev_to_pci(dev);
 	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	PMD_INIT_FUNC_TRACE();
 
diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 2609f97..43bd262 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -723,7 +723,7 @@ nfp_net_close(struct rte_eth_dev *dev)
 	PMD_INIT_LOG(DEBUG, "Close\n");
 
 	hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	pci_dev = dev->pci_dev;
+	pci_dev = rte_eth_dev_to_pci(dev);
 
 	/*
 	 * We assume that the DPDK application is stopping all the
@@ -1124,7 +1124,7 @@ nfp_net_rx_queue_count(struct rte_eth_dev *dev, uint16_t queue_idx)
 static void
 nfp_net_dev_link_status_print(struct rte_eth_dev *dev)
 {
-	struct rte_pci_device *pci_dev = dev->pci_dev;
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_eth_link link;
 
 	memset(&link, 0, sizeof(link));
@@ -1158,7 +1158,7 @@ nfp_net_irq_unmask(struct rte_eth_dev *dev)
 	struct rte_pci_device *pci_dev;
 
 	hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	pci_dev = dev->pci_dev;
+	pci_dev = rte_eth_dev_to_pci(dev);
 
 	if (hw->ctrl & NFP_NET_CFG_CTRL_MSIXAUTO) {
 		/* If MSI-X auto-masking is used, clear the entry */
@@ -2335,7 +2335,7 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return 0;
 
-	pci_dev = eth_dev->pci_dev;
+	pci_dev = rte_eth_dev_to_pci(eth_dev);
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
 	hw->device_id = pci_dev->id.device_id;
diff --git a/drivers/net/qede/qede_ethdev.c b/drivers/net/qede/qede_ethdev.c
index a50bd5f..ea65895 100644
--- a/drivers/net/qede/qede_ethdev.c
+++ b/drivers/net/qede/qede_ethdev.c
@@ -809,7 +809,7 @@ static void qede_poll_sp_sb_cb(void *param)
 
 static void qede_dev_close(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(eth_dev);
 	struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
 	struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
 	int rc;
@@ -1404,7 +1404,7 @@ static int qede_common_dev_init(struct rte_eth_dev *eth_dev, bool is_vf)
 	/* Extract key data structures */
 	adapter = eth_dev->data->dev_private;
 	edev = &adapter->edev;
-	pci_dev = eth_dev->pci_dev;
+	pci_dev = rte_eth_dev_to_pci(eth_dev);
 	pci_addr = pci_dev->addr;
 
 	PMD_INIT_FUNC_TRACE(edev);
diff --git a/drivers/net/szedata2/rte_eth_szedata2.c b/drivers/net/szedata2/rte_eth_szedata2.c
index 8dc94c5..7f86dc9 100644
--- a/drivers/net/szedata2/rte_eth_szedata2.c
+++ b/drivers/net/szedata2/rte_eth_szedata2.c
@@ -1429,7 +1429,7 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 	struct szedata *szedata_temp;
 	int ret;
 	uint32_t szedata2_index;
-	struct rte_pci_device *pci_dev = dev->pci_dev;
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_pci_addr *pci_addr = &pci_dev->addr;
 	struct rte_mem_resource *pci_rsc =
 		&pci_dev->mem_resource[PCI_RESOURCE_NUMBER];
@@ -1552,7 +1552,7 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 static int
 rte_szedata2_eth_dev_uninit(struct rte_eth_dev *dev)
 {
-	struct rte_pci_device *pci_dev = dev->pci_dev;
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct rte_pci_addr *pci_addr = &pci_dev->addr;
 
 	rte_free(dev->data->mac_addrs);
diff --git a/drivers/net/thunderx/nicvf_ethdev.c b/drivers/net/thunderx/nicvf_ethdev.c
index 466e49c..113f1e2 100644
--- a/drivers/net/thunderx/nicvf_ethdev.c
+++ b/drivers/net/thunderx/nicvf_ethdev.c
@@ -1335,6 +1335,7 @@ static void
 nicvf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
 	struct nicvf *nic = nicvf_pmd_priv(dev);
+	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -1345,7 +1346,7 @@ nicvf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	dev_info->max_tx_queues =
 			(uint16_t)MAX_SND_QUEUES_PER_QS * (MAX_SQS_PER_VF + 1);
 	dev_info->max_mac_addrs = 1;
-	dev_info->max_vfs = dev->pci_dev->max_vfs;
+	dev_info->max_vfs = pci_dev->max_vfs;
 
 	dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
 	dev_info->tx_offload_capa =
@@ -1975,7 +1976,7 @@ nicvf_eth_dev_init(struct rte_eth_dev *eth_dev)
 		}
 	}
 
-	pci_dev = eth_dev->pci_dev;
+	pci_dev = rte_eth_dev_to_pci(eth_dev);
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
 	nic->device_id = pci_dev->id.device_id;
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 58c03d8..251ef07 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1321,7 +1321,7 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	 * virtio_user_eth_dev_alloc() before eth_virtio_dev_init() is called.
 	 */
 	if (!hw->virtio_user_dev) {
-		ret = vtpci_init(eth_dev->pci_dev, hw, &dev_flags);
+		ret = vtpci_init(rte_eth_dev_to_pci(eth_dev), hw, &dev_flags);
 		if (ret)
 			return ret;
 	}
diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.c b/drivers/net/vmxnet3/vmxnet3_ethdev.c
index 20a7966..1c51619 100644
--- a/drivers/net/vmxnet3/vmxnet3_ethdev.c
+++ b/drivers/net/vmxnet3/vmxnet3_ethdev.c
@@ -237,7 +237,7 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->dev_ops = &vmxnet3_eth_dev_ops;
 	eth_dev->rx_pkt_burst = &vmxnet3_recv_pkts;
 	eth_dev->tx_pkt_burst = &vmxnet3_xmit_pkts;
-	pci_dev = eth_dev->pci_dev;
+	pci_dev = rte_eth_dev_to_pci(eth_dev);
 
 	/*
 	 * for secondary processes, we don't initialize any further as primary
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 21/23] ethdev: Move filling of rte_eth_dev_info->pci_dev to dev_infos_get()
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (19 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 20/23] drivers: Use " Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-21 20:09   ` Stephen Hemminger
  2016-12-21 15:09 ` [PATCH v4 22/23] ethdev: Decouple interrupt handling from PCI device Jan Blunck
                   ` (23 subsequent siblings)
  44 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

Only the device itself can decide its PCI or not.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 drivers/net/bnx2x/bnx2x_ethdev.c        | 1 +
 drivers/net/bnxt/bnxt_ethdev.c          | 2 ++
 drivers/net/cxgbe/cxgbe_ethdev.c        | 2 ++
 drivers/net/e1000/em_ethdev.c           | 1 +
 drivers/net/e1000/igb_ethdev.c          | 2 ++
 drivers/net/ena/ena_ethdev.c            | 2 ++
 drivers/net/enic/enic_ethdev.c          | 1 +
 drivers/net/fm10k/fm10k_ethdev.c        | 1 +
 drivers/net/i40e/i40e_ethdev.c          | 1 +
 drivers/net/i40e/i40e_ethdev_vf.c       | 1 +
 drivers/net/ixgbe/ixgbe_ethdev.c        | 2 ++
 drivers/net/mlx4/mlx4.c                 | 2 ++
 drivers/net/mlx5/mlx5_ethdev.c          | 2 ++
 drivers/net/nfp/nfp_net.c               | 1 +
 drivers/net/qede/qede_ethdev.c          | 1 +
 drivers/net/szedata2/rte_eth_szedata2.c | 1 +
 drivers/net/thunderx/nicvf_ethdev.c     | 2 ++
 drivers/net/virtio/virtio_ethdev.c      | 1 +
 drivers/net/vmxnet3/vmxnet3_ethdev.c    | 4 +++-
 lib/librte_ether/rte_ethdev.c           | 1 -
 20 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/drivers/net/bnx2x/bnx2x_ethdev.c b/drivers/net/bnx2x/bnx2x_ethdev.c
index f59488e..6536f62 100644
--- a/drivers/net/bnx2x/bnx2x_ethdev.c
+++ b/drivers/net/bnx2x/bnx2x_ethdev.c
@@ -431,6 +431,7 @@ static void
 bnx2x_dev_infos_get(struct rte_eth_dev *dev, __rte_unused struct rte_eth_dev_info *dev_info)
 {
 	struct bnx2x_softc *sc = dev->data->dev_private;
+	dev_info->pci_dev = rte_eth_dev_to_pci(dev);
 	dev_info->max_rx_queues  = sc->max_rx_queues;
 	dev_info->max_tx_queues  = sc->max_tx_queues;
 	dev_info->min_rx_bufsize = BNX2X_MIN_RX_BUF_SIZE;
diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index 2864ef3..075c025 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -303,6 +303,8 @@ static void bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
 	struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
 	uint16_t max_vnics, i, j, vpool, vrxq;
 
+	dev_info->pci_dev = rte_eth_dev_to_pci(eth_dev);
+
 	/* MAC Specifics */
 	dev_info->max_mac_addrs = MAX_NUM_MAC_ADDR;
 	dev_info->max_hash_mac_addrs = 0;
diff --git a/drivers/net/cxgbe/cxgbe_ethdev.c b/drivers/net/cxgbe/cxgbe_ethdev.c
index bb1f3b3..9f6700b 100644
--- a/drivers/net/cxgbe/cxgbe_ethdev.c
+++ b/drivers/net/cxgbe/cxgbe_ethdev.c
@@ -147,6 +147,8 @@ static void cxgbe_dev_info_get(struct rte_eth_dev *eth_dev,
 		.nb_align = 1,
 	};
 
+	device_info->pci_dev = rte_eth_dev_to_pci(eth_dev);
+
 	device_info->min_rx_bufsize = CXGBE_MIN_RX_BUFSIZE;
 	device_info->max_rx_pktlen = CXGBE_MAX_RX_PKTLEN;
 	device_info->max_rx_queues = max_queues;
diff --git a/drivers/net/e1000/em_ethdev.c b/drivers/net/e1000/em_ethdev.c
index b4160f2..2f3f941 100644
--- a/drivers/net/e1000/em_ethdev.c
+++ b/drivers/net/e1000/em_ethdev.c
@@ -1048,6 +1048,7 @@ eth_em_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
+	dev_info->pci_dev = rte_eth_dev_to_pci(dev);
 	dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
 	dev_info->max_rx_pktlen = em_get_max_pktlen(hw);
 	dev_info->max_mac_addrs = hw->mac.rar_entry_count;
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index f0e5271..01318ab 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -1986,6 +1986,7 @@ eth_igb_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
+	dev_info->pci_dev = rte_eth_dev_to_pci(dev);
 	dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
 	dev_info->max_rx_pktlen  = 0x3FFF; /* See RLPML register. */
 	dev_info->max_mac_addrs = hw->mac.rar_entry_count;
@@ -2114,6 +2115,7 @@ eth_igbvf_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
+	dev_info->pci_dev = rte_eth_dev_to_pci(dev);
 	dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
 	dev_info->max_rx_pktlen  = 0x3FFF; /* See RLPML register. */
 	dev_info->max_mac_addrs = hw->mac.rar_entry_count;
diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
index 552d3ed..d732e17 100644
--- a/drivers/net/ena/ena_ethdev.c
+++ b/drivers/net/ena/ena_ethdev.c
@@ -1436,6 +1436,8 @@ static void ena_infos_get(struct rte_eth_dev *dev,
 	ena_dev = &adapter->ena_dev;
 	ena_assert_msg(ena_dev != NULL, "Uninitialized device");
 
+	dev_info->pci_dev = rte_eth_dev_to_pci(dev);
+
 	dev_info->speed_capa =
 			ETH_LINK_SPEED_1G   |
 			ETH_LINK_SPEED_2_5G |
diff --git a/drivers/net/enic/enic_ethdev.c b/drivers/net/enic/enic_ethdev.c
index 92df191..7b3a023 100644
--- a/drivers/net/enic/enic_ethdev.c
+++ b/drivers/net/enic/enic_ethdev.c
@@ -459,6 +459,7 @@ static void enicpmd_dev_info_get(struct rte_eth_dev *eth_dev,
 	struct enic *enic = pmd_priv(eth_dev);
 
 	ENICPMD_FUNC_TRACE();
+	device_info->pci_dev = rte_eth_dev_to_pci(eth_dev);
 	/* Scattered Rx uses two receive queues per rx queue exposed to dpdk */
 	device_info->max_rx_queues = enic->conf_rq_count / 2;
 	device_info->max_tx_queues = enic->conf_wq_count;
diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c
index 140e235..43a88f8 100644
--- a/drivers/net/fm10k/fm10k_ethdev.c
+++ b/drivers/net/fm10k/fm10k_ethdev.c
@@ -1393,6 +1393,7 @@ fm10k_dev_infos_get(struct rte_eth_dev *dev,
 
 	PMD_INIT_FUNC_TRACE();
 
+	dev_info->pci_dev            = pdev;
 	dev_info->min_rx_bufsize     = FM10K_MIN_RX_BUF_SIZE;
 	dev_info->max_rx_pktlen      = FM10K_MAX_PKT_SIZE;
 	dev_info->max_rx_queues      = hw->mac.max_queues;
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 51a90e8..3093db0 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -2596,6 +2596,7 @@ i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	struct i40e_vsi *vsi = pf->main_vsi;
 	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 
+	dev_info->pci_dev = pci_dev;
 	dev_info->max_rx_queues = vsi->nb_qps;
 	dev_info->max_tx_queues = vsi->nb_qps;
 	dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
diff --git a/drivers/net/i40e/i40e_ethdev_vf.c b/drivers/net/i40e/i40e_ethdev_vf.c
index fbb9e02..af6a3e0 100644
--- a/drivers/net/i40e/i40e_ethdev_vf.c
+++ b/drivers/net/i40e/i40e_ethdev_vf.c
@@ -2224,6 +2224,7 @@ i40evf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 
 	memset(dev_info, 0, sizeof(*dev_info));
+	dev_info->pci_dev = rte_eth_dev_to_pci(dev);
 	dev_info->max_rx_queues = vf->vsi_res->num_queue_pairs;
 	dev_info->max_tx_queues = vf->vsi_res->num_queue_pairs;
 	dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 44aafa3..4587f56 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -3035,6 +3035,7 @@ ixgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
 
+	dev_info->pci_dev = pci_dev;
 	dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
 	dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
 	if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
@@ -3167,6 +3168,7 @@ ixgbevf_dev_info_get(struct rte_eth_dev *dev,
 	struct rte_pci_device *pci_dev = rte_eth_dev_to_pci(dev);
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
+	dev_info->pci_dev = pci_dev;
 	dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
 	dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
 	dev_info->min_rx_bufsize = 1024; /* cf BSIZEPACKET in SRRCTL reg */
diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c
index da61a85..1df8faa 100644
--- a/drivers/net/mlx4/mlx4.c
+++ b/drivers/net/mlx4/mlx4.c
@@ -4421,6 +4421,8 @@ mlx4_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
 	unsigned int max;
 	char ifname[IF_NAMESIZE];
 
+	info->pci_dev = rte_eth_dev_to_pci(dev);
+
 	if (priv == NULL)
 		return;
 	priv_lock(priv);
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index c0f73e9..5fdf4d8 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -562,6 +562,8 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
 	unsigned int max;
 	char ifname[IF_NAMESIZE];
 
+	info->pci_dev = rte_eth_dev_to_pci(dev);
+
 	priv_lock(priv);
 	/* FIXME: we should ask the device for these values. */
 	info->min_rx_bufsize = 32;
diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 43bd262..66ef393 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -1008,6 +1008,7 @@ nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 
 	hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
+	dev_info->pci_dev = rte_eth_dev_to_pci(dev);
 	dev_info->driver_name = dev->driver->pci_drv.driver.name;
 	dev_info->max_rx_queues = (uint16_t)hw->max_rx_queues;
 	dev_info->max_tx_queues = (uint16_t)hw->max_tx_queues;
diff --git a/drivers/net/qede/qede_ethdev.c b/drivers/net/qede/qede_ethdev.c
index ea65895..80ea158 100644
--- a/drivers/net/qede/qede_ethdev.c
+++ b/drivers/net/qede/qede_ethdev.c
@@ -651,6 +651,7 @@ qede_dev_info_get(struct rte_eth_dev *eth_dev,
 
 	PMD_INIT_FUNC_TRACE(edev);
 
+	dev_info->pci_dev = rte_eth_dev_to_pci(eth_dev);
 	dev_info->min_rx_bufsize = (uint32_t)(ETHER_MIN_MTU +
 					      QEDE_ETH_OVERHEAD);
 	dev_info->max_rx_pktlen = (uint32_t)ETH_TX_MAX_NON_LSO_PKT_LEN;
diff --git a/drivers/net/szedata2/rte_eth_szedata2.c b/drivers/net/szedata2/rte_eth_szedata2.c
index 7f86dc9..fd33f07 100644
--- a/drivers/net/szedata2/rte_eth_szedata2.c
+++ b/drivers/net/szedata2/rte_eth_szedata2.c
@@ -1031,6 +1031,7 @@ eth_dev_info(struct rte_eth_dev *dev,
 		struct rte_eth_dev_info *dev_info)
 {
 	struct pmd_internals *internals = dev->data->dev_private;
+	dev_info->pci_dev = rte_eth_dev_to_pci(dev);
 	dev_info->if_index = 0;
 	dev_info->max_mac_addrs = 1;
 	dev_info->max_rx_pktlen = (uint32_t)-1;
diff --git a/drivers/net/thunderx/nicvf_ethdev.c b/drivers/net/thunderx/nicvf_ethdev.c
index 113f1e2..4b31ff3 100644
--- a/drivers/net/thunderx/nicvf_ethdev.c
+++ b/drivers/net/thunderx/nicvf_ethdev.c
@@ -1339,6 +1339,8 @@ nicvf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 
 	PMD_INIT_FUNC_TRACE();
 
+	dev_info->pci_dev = pci_dev;
+
 	dev_info->min_rx_bufsize = ETHER_MIN_MTU;
 	dev_info->max_rx_pktlen = NIC_HW_MAX_FRS;
 	dev_info->max_rx_queues =
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 251ef07..9ab3ef0 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1626,6 +1626,7 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	uint64_t tso_mask;
 	struct virtio_hw *hw = dev->data->dev_private;
 
+	dev_info->pci_dev = hw->dev;
 	dev_info->max_rx_queues =
 		RTE_MIN(hw->max_queue_pairs, VIRTIO_MAX_RX_QUEUES);
 	dev_info->max_tx_queues =
diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.c b/drivers/net/vmxnet3/vmxnet3_ethdev.c
index 1c51619..fd027fc 100644
--- a/drivers/net/vmxnet3/vmxnet3_ethdev.c
+++ b/drivers/net/vmxnet3/vmxnet3_ethdev.c
@@ -706,9 +706,11 @@ vmxnet3_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
 }
 
 static void
-vmxnet3_dev_info_get(__rte_unused struct rte_eth_dev *dev,
+vmxnet3_dev_info_get(struct rte_eth_dev *dev,
 		     struct rte_eth_dev_info *dev_info)
 {
+	dev_info->pci_dev = rte_eth_dev_to_pci(dev);
+
 	dev_info->max_rx_queues = VMXNET3_MAX_RX_QUEUES;
 	dev_info->max_tx_queues = VMXNET3_MAX_TX_QUEUES;
 	dev_info->min_rx_bufsize = 1518 + RTE_PKTMBUF_HEADROOM;
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 1e0f206..200e068 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -1568,7 +1568,6 @@ rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
 
 	RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
 	(*dev->dev_ops->dev_infos_get)(dev, dev_info);
-	dev_info->pci_dev = dev->pci_dev;
 	dev_info->driver_name = dev->data->drv_name;
 	dev_info->nb_rx_queues = dev->data->nb_rx_queues;
 	dev_info->nb_tx_queues = dev->data->nb_tx_queues;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 22/23] ethdev: Decouple interrupt handling from PCI device
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (20 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 21/23] ethdev: Move filling of rte_eth_dev_info->pci_dev to dev_infos_get() Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-22 15:13   ` Thomas Monjalon
  2016-12-21 15:09 ` [PATCH v4 23/23] ethdev: Decouple struct rte_eth_dev from struct rte_pci_device Jan Blunck
                   ` (22 subsequent siblings)
  44 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

The struct rte_intr_handle is an abstraction layer for different types of
interrupt mechanisms. It is embedded in the low-level device (e.g. PCI).
On allocation of a struct rte_eth_dev a reference to the intr_handle
should be stored for devices supporting interrupts.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_ether/rte_ethdev.c | 18 ++++++++++++++++--
 lib/librte_ether/rte_ethdev.h |  1 +
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 200e068..764b6cd 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -258,6 +258,7 @@ rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
 			rte_panic("Cannot allocate memzone for private port data\n");
 	}
 	eth_dev->pci_dev = pci_dev;
+	eth_dev->intr_handle = &pci_dev->intr_handle;
 	eth_dev->driver = eth_drv;
 	eth_dev->data->rx_mbuf_alloc_failed = 0;
 
@@ -2555,7 +2556,13 @@ rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 
 	dev = &rte_eth_devices[port_id];
-	intr_handle = &dev->pci_dev->intr_handle;
+
+	if (!dev->intr_handle) {
+		RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
+		return -ENOTSUP;
+	}
+
+	intr_handle = dev->intr_handle;
 	if (!intr_handle->intr_vec) {
 		RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
 		return -EPERM;
@@ -2615,7 +2622,12 @@ rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
 		return -EINVAL;
 	}
 
-	intr_handle = &dev->pci_dev->intr_handle;
+	if (!dev->intr_handle) {
+		RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
+		return -ENOTSUP;
+	}
+
+	intr_handle = dev->intr_handle;
 	if (!intr_handle->intr_vec) {
 		RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
 		return -EPERM;
@@ -3217,6 +3229,8 @@ rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_de
 		return;
 	}
 
+	eth_dev->intr_handle = &pci_dev->intr_handle;
+
 	eth_dev->data->dev_flags = 0;
 	if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
 		eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index d6e367c..cc93ca9 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1629,6 +1629,7 @@ struct rte_eth_dev {
 	const struct eth_driver *driver;/**< Driver for this device */
 	const struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */
 	struct rte_pci_device *pci_dev; /**< PCI info. supplied by probing */
+	struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
 	/** User application callbacks for NIC interrupts */
 	struct rte_eth_dev_cb_list link_intr_cbs;
 	/**
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v4 23/23] ethdev: Decouple struct rte_eth_dev from struct rte_pci_device
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (21 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 22/23] ethdev: Decouple interrupt handling from PCI device Jan Blunck
@ 2016-12-21 15:09 ` Jan Blunck
  2016-12-22 15:22   ` Thomas Monjalon
  2016-12-22 15:26 ` [PATCH v4 00/23] Decouple ethdev from PCI device Thomas Monjalon
                   ` (21 subsequent siblings)
  44 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-21 15:09 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 app/test/virtual_pmd.c                  |  4 ++--
 drivers/net/bonding/rte_eth_bond_args.c | 12 ++++++++++--
 drivers/net/cxgbe/cxgbe_main.c          |  4 ++--
 drivers/net/fm10k/fm10k_ethdev.c        |  6 +++---
 drivers/net/mlx4/mlx4.c                 |  2 +-
 drivers/net/mlx5/mlx5.c                 |  2 +-
 drivers/net/virtio/virtio_user_ethdev.c |  1 -
 lib/librte_eal/common/include/rte_pci.h |  6 ++++++
 lib/librte_ether/rte_ethdev.c           |  6 +++---
 lib/librte_ether/rte_ethdev.h           |  4 ++--
 10 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/app/test/virtual_pmd.c b/app/test/virtual_pmd.c
index e0447fd..f4c7f3c 100644
--- a/app/test/virtual_pmd.c
+++ b/app/test/virtual_pmd.c
@@ -624,8 +624,8 @@ virtual_ethdev_create(const char *name, struct ether_addr *mac_addr,
 	dev_private->dev_ops = virtual_ethdev_default_dev_ops;
 	eth_dev->dev_ops = &dev_private->dev_ops;
 
-	eth_dev->pci_dev = pci_dev;
-	eth_dev->pci_dev->device.driver = &eth_drv->pci_drv.driver;
+	pci_dev->device.driver = &eth_drv->pci_drv.driver;
+	eth_dev->device = &pci_dev->device;
 
 	eth_dev->rx_pkt_burst = virtual_ethdev_rx_burst_success;
 	eth_dev->tx_pkt_burst = virtual_ethdev_tx_burst_success;
diff --git a/drivers/net/bonding/rte_eth_bond_args.c b/drivers/net/bonding/rte_eth_bond_args.c
index 02ecde6..ae27a5f 100644
--- a/drivers/net/bonding/rte_eth_bond_args.c
+++ b/drivers/net/bonding/rte_eth_bond_args.c
@@ -54,15 +54,23 @@ const char *pmd_bond_init_valid_arguments[] = {
 static inline int
 find_port_id_by_pci_addr(const struct rte_pci_addr *pci_addr)
 {
+	struct rte_pci_device *pci_dev;
 	struct rte_pci_addr *eth_pci_addr;
 	unsigned i;
 
 	for (i = 0; i < rte_eth_dev_count(); i++) {
 
-		if (rte_eth_devices[i].pci_dev == NULL)
+		/* Currently populated by rte_eth_copy_pci_info().
+		 *
+		 * TODO: Once the PCI bus has arrived we should have a better
+		 * way to test for being a PCI device or not.
+		 */
+		if (rte_eth_devices[i].data->kdrv == RTE_KDRV_UNKNOWN ||
+		    rte_eth_devices[i].data->kdrv == RTE_KDRV_NONE)
 			continue;
 
-		eth_pci_addr = &(rte_eth_devices[i].pci_dev->addr);
+		pci_dev = rte_eth_dev_to_pci(&rte_eth_devices[i]);
+		eth_pci_addr = &pci_dev->addr;
 
 		if (pci_addr->bus == eth_pci_addr->bus &&
 			pci_addr->devid == eth_pci_addr->devid &&
diff --git a/drivers/net/cxgbe/cxgbe_main.c b/drivers/net/cxgbe/cxgbe_main.c
index 922155b..ea13c7e 100644
--- a/drivers/net/cxgbe/cxgbe_main.c
+++ b/drivers/net/cxgbe/cxgbe_main.c
@@ -1163,14 +1163,14 @@ int cxgbe_probe(struct adapter *adapter)
 		pi->eth_dev->data = data;
 
 allocate_mac:
-		pi->eth_dev->pci_dev = adapter->pdev;
+		pi->eth_dev->device = &adapter->pdev->device;
 		pi->eth_dev->data->dev_private = pi;
 		pi->eth_dev->driver = adapter->eth_dev->driver;
 		pi->eth_dev->dev_ops = adapter->eth_dev->dev_ops;
 		pi->eth_dev->tx_pkt_burst = adapter->eth_dev->tx_pkt_burst;
 		pi->eth_dev->rx_pkt_burst = adapter->eth_dev->rx_pkt_burst;
 
-		rte_eth_copy_pci_info(pi->eth_dev, pi->eth_dev->pci_dev);
+		rte_eth_copy_pci_info(pi->eth_dev, adapter->pdev);
 
 		TAILQ_INIT(&pi->eth_dev->link_intr_cbs);
 
diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c
index 43a88f8..8f9ee55 100644
--- a/drivers/net/fm10k/fm10k_ethdev.c
+++ b/drivers/net/fm10k/fm10k_ethdev.c
@@ -677,7 +677,7 @@ fm10k_dev_tx_init(struct rte_eth_dev *dev)
 		/* Enable use of FTAG bit in TX descriptor, PFVTCTL
 		 * register is read-only for VF.
 		 */
-		if (fm10k_check_ftag(dev->pci_dev->device.devargs)) {
+		if (fm10k_check_ftag(dev->device->devargs)) {
 			if (hw->mac.type == fm10k_mac_pf) {
 				FM10K_WRITE_REG(hw, FM10K_PFVTCTL(i),
 						FM10K_PFVTCTL_FTAG_DESC_ENABLE);
@@ -2744,7 +2744,7 @@ fm10k_set_tx_function(struct rte_eth_dev *dev)
 	int use_sse = 1;
 	uint16_t tx_ftag_en = 0;
 
-	if (fm10k_check_ftag(dev->pci_dev->device.devargs))
+	if (fm10k_check_ftag(dev->device->devargs))
 		tx_ftag_en = 1;
 
 	for (i = 0; i < dev->data->nb_tx_queues; i++) {
@@ -2775,7 +2775,7 @@ fm10k_set_rx_function(struct rte_eth_dev *dev)
 	uint16_t i, rx_using_sse;
 	uint16_t rx_ftag_en = 0;
 
-	if (fm10k_check_ftag(dev->pci_dev->device.devargs))
+	if (fm10k_check_ftag(dev->device->devargs))
 		rx_ftag_en = 1;
 
 	/* In order to allow Vector Rx there are a few configuration
diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c
index 1df8faa..3ac3947 100644
--- a/drivers/net/mlx4/mlx4.c
+++ b/drivers/net/mlx4/mlx4.c
@@ -5840,7 +5840,7 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 			eth_dev->data->mtu = ETHER_MTU;
 			eth_dev->data->mac_addrs = priv->mac;
 		}
-		eth_dev->pci_dev = pci_dev;
+		eth_dev->device = &pci_dev->device;
 
 		rte_eth_copy_pci_info(eth_dev, pci_dev);
 
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index 90cc35e..8ed4cef 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -657,7 +657,7 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 			eth_dev->data->mac_addrs = priv->mac;
 		}
 
-		eth_dev->pci_dev = pci_dev;
+		eth_dev->device = &pci_dev->device;
 		rte_eth_copy_pci_info(eth_dev, pci_dev);
 		eth_dev->driver = &mlx5_driver;
 		priv->dev = eth_dev;
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index 406beea..8cb983c 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -310,7 +310,6 @@ virtio_user_eth_dev_alloc(const char *name)
 	data->numa_node = SOCKET_ID_ANY;
 	data->kdrv = RTE_KDRV_NONE;
 	data->dev_flags = RTE_ETH_DEV_DETACHABLE;
-	eth_dev->pci_dev = NULL;
 	eth_dev->driver = NULL;
 	return eth_dev;
 }
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 9ce8847..19deaf6 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -160,6 +160,12 @@ struct rte_pci_device {
 	enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
 };
 
+/**
+ * @internal
+ * Helper macro for drivers that need to convert to struct rte_pci_device.
+ */
+#define DEV_PCI_DEV(ptr) container_of(ptr, struct rte_pci_device, device)
+
 /** Any PCI device identifier (vendor, device, ...) */
 #define PCI_ANY_ID (0xffff)
 #define RTE_CLASS_ANY_ID (0xffffff)
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 764b6cd..29c5ea2 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -257,7 +257,7 @@ rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
 		if (eth_dev->data->dev_private == NULL)
 			rte_panic("Cannot allocate memzone for private port data\n");
 	}
-	eth_dev->pci_dev = pci_dev;
+	eth_dev->device = &pci_dev->device;
 	eth_dev->intr_handle = &pci_dev->intr_handle;
 	eth_dev->driver = eth_drv;
 	eth_dev->data->rx_mbuf_alloc_failed = 0;
@@ -318,7 +318,7 @@ rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
 		rte_free(eth_dev->data->dev_private);
 
-	eth_dev->pci_dev = NULL;
+	eth_dev->device = NULL;
 	eth_dev->driver = NULL;
 	eth_dev->data = NULL;
 
@@ -2590,7 +2590,7 @@ rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
 	const struct rte_memzone *mz;
 
 	snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
-		 dev->driver->pci_drv.driver.name, ring_name,
+		 dev->data->drv_name, ring_name,
 		 dev->data->port_id, queue_id);
 
 	mz = rte_memzone_lookup(z_name);
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index cc93ca9..2431c29 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1628,7 +1628,7 @@ struct rte_eth_dev {
 	struct rte_eth_dev_data *data;  /**< Pointer to device data */
 	const struct eth_driver *driver;/**< Driver for this device */
 	const struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */
-	struct rte_pci_device *pci_dev; /**< PCI info. supplied by probing */
+	struct rte_device *device; /**< Backing device for this device */
 	struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
 	/** User application callbacks for NIC interrupts */
 	struct rte_eth_dev_cb_list link_intr_cbs;
@@ -1652,7 +1652,7 @@ struct rte_eth_dev {
 static inline struct rte_pci_device *__attribute__((always_inline))
 rte_eth_dev_to_pci(struct rte_eth_dev *eth_dev)
 {
-	return eth_dev->pci_dev;
+	return DEV_PCI_DEV(eth_dev->device);
 }
 
 struct rte_eth_dev_sriov {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 14/23] qede: localize mapping of eth_dev to pci
  2016-12-21 15:09 ` [PATCH v4 14/23] qede: localize mapping of " Jan Blunck
@ 2016-12-21 16:35   ` Harish Patil
  0 siblings, 0 replies; 81+ messages in thread
From: Harish Patil @ 2016-12-21 16:35 UTC (permalink / raw)
  To: Jan Blunck, dev; +Cc: shreyansh.jain, david.marchand, stephen

>
>This simplifies later changes to ethdev.
>
>Signed-off-by: Jan Blunck <jblunck@infradead.org>
>---
> drivers/net/qede/qede_ethdev.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
>diff --git a/drivers/net/qede/qede_ethdev.c
>b/drivers/net/qede/qede_ethdev.c
>index d106dd0..a50bd5f 100644
>--- a/drivers/net/qede/qede_ethdev.c
>+++ b/drivers/net/qede/qede_ethdev.c
>@@ -175,14 +175,14 @@ static void qede_interrupt_action(struct ecore_hwfn
>*p_hwfn)
> }
> 
> static void
>-qede_interrupt_handler(__rte_unused struct rte_intr_handle *handle, void
>*param)
>+qede_interrupt_handler(struct rte_intr_handle *handle, void *param)
> {
> 	struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)param;
> 	struct qede_dev *qdev = eth_dev->data->dev_private;
> 	struct ecore_dev *edev = &qdev->edev;
> 
> 	qede_interrupt_action(ECORE_LEADING_HWFN(edev));
>-	if (rte_intr_enable(&eth_dev->pci_dev->intr_handle))
>+	if (rte_intr_enable(handle))
> 		DP_ERR(edev, "rte_intr_enable failed\n");
> }
> 
>@@ -809,6 +809,7 @@ static void qede_poll_sp_sb_cb(void *param)
> 
> static void qede_dev_close(struct rte_eth_dev *eth_dev)
> {
>+	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
> 	struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
> 	struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
> 	int rc;
>@@ -835,9 +836,9 @@ static void qede_dev_close(struct rte_eth_dev
>*eth_dev)
> 
> 	qdev->ops->common->remove(edev);
> 
>-	rte_intr_disable(&eth_dev->pci_dev->intr_handle);
>+	rte_intr_disable(&pci_dev->intr_handle);
> 
>-	rte_intr_callback_unregister(&eth_dev->pci_dev->intr_handle,
>+	rte_intr_callback_unregister(&pci_dev->intr_handle,
> 				     qede_interrupt_handler, (void *)eth_dev);
> 
> 	if (edev->num_hwfns > 1)
>@@ -1403,7 +1404,8 @@ static int qede_common_dev_init(struct rte_eth_dev
>*eth_dev, bool is_vf)
> 	/* Extract key data structures */
> 	adapter = eth_dev->data->dev_private;
> 	edev = &adapter->edev;
>-	pci_addr = eth_dev->pci_dev->addr;
>+	pci_dev = eth_dev->pci_dev;
>+	pci_addr = pci_dev->addr;
> 
> 	PMD_INIT_FUNC_TRACE(edev);
> 
>@@ -1420,8 +1422,6 @@ static int qede_common_dev_init(struct rte_eth_dev
>*eth_dev, bool is_vf)
> 		return 0;
> 	}
> 
>-	pci_dev = eth_dev->pci_dev;
>-
> 	rte_eth_copy_pci_info(eth_dev, pci_dev);
> 
> 	qed_ops = qed_get_eth_ops();
>@@ -1442,10 +1442,10 @@ static int qede_common_dev_init(struct
>rte_eth_dev *eth_dev, bool is_vf)
> 
> 	qede_update_pf_params(edev);
> 
>-	rte_intr_callback_register(&eth_dev->pci_dev->intr_handle,
>+	rte_intr_callback_register(&pci_dev->intr_handle,
> 				   qede_interrupt_handler, (void *)eth_dev);
> 
>-	if (rte_intr_enable(&eth_dev->pci_dev->intr_handle)) {
>+	if (rte_intr_enable(&pci_dev->intr_handle)) {
> 		DP_ERR(edev, "rte_intr_enable() failed\n");
> 		return -ENODEV;
> 	}
>-- 
>2.7.4
>
>
Acked-by: Harish Patil <harish.patil@qlogic.com>



^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 12/23] bnx2x: localize mapping from eth_dev to pci
  2016-12-21 15:09 ` [PATCH v4 12/23] bnx2x: localize mapping from eth_dev to pci Jan Blunck
@ 2016-12-21 16:35   ` Harish Patil
  0 siblings, 0 replies; 81+ messages in thread
From: Harish Patil @ 2016-12-21 16:35 UTC (permalink / raw)
  To: Jan Blunck, dev; +Cc: shreyansh.jain, david.marchand, stephen

>
>Use device private information to minimize the places that assume eth_dev
>contains pci_dev.
>
>Signed-off-by: Jan Blunck <jblunck@infradead.org>
>---
> drivers/net/bnx2x/bnx2x_ethdev.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
>diff --git a/drivers/net/bnx2x/bnx2x_ethdev.c
>b/drivers/net/bnx2x/bnx2x_ethdev.c
>index 0eae433..ef2026a 100644
>--- a/drivers/net/bnx2x/bnx2x_ethdev.c
>+++ b/drivers/net/bnx2x/bnx2x_ethdev.c
>@@ -119,12 +119,12 @@ bnx2x_interrupt_action(struct rte_eth_dev *dev)
> }
> 
> static __rte_unused void
>-bnx2x_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
>void *param)
>+bnx2x_interrupt_handler(struct rte_intr_handle *handle, void *param)
> {
> 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
> 
> 	bnx2x_interrupt_action(dev);
>-	rte_intr_enable(&(dev->pci_dev->intr_handle));
>+	rte_intr_enable(handle);
> }
> 
> /*
>@@ -187,10 +187,10 @@ bnx2x_dev_start(struct rte_eth_dev *dev)
> 	}
> 
> 	if (IS_PF(sc)) {
>-		rte_intr_callback_register(&(dev->pci_dev->intr_handle),
>+		rte_intr_callback_register(&sc->pci_dev->intr_handle,
> 				bnx2x_interrupt_handler, (void *)dev);
> 
>-		if(rte_intr_enable(&(dev->pci_dev->intr_handle)))
>+		if (rte_intr_enable(&sc->pci_dev->intr_handle))
> 			PMD_DRV_LOG(ERR, "rte_intr_enable failed");
> 	}
> 
>@@ -215,8 +215,8 @@ bnx2x_dev_stop(struct rte_eth_dev *dev)
> 	PMD_INIT_FUNC_TRACE();
> 
> 	if (IS_PF(sc)) {
>-		rte_intr_disable(&(dev->pci_dev->intr_handle));
>-		rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
>+		rte_intr_disable(&sc->pci_dev->intr_handle);
>+		rte_intr_callback_unregister(&sc->pci_dev->intr_handle,
> 				bnx2x_interrupt_handler, (void *)dev);
> 	}
> 
>-- 
>2.7.4
>
>
Acked-by: Harish Patil <harish.patil@qlogic.com>



^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 10/23] virtio: Add vtpci_intr_handle() helper to get rte_intr_handle
  2016-12-21 15:09 ` [PATCH v4 10/23] virtio: Add vtpci_intr_handle() helper to get rte_intr_handle Jan Blunck
@ 2016-12-21 20:08   ` Stephen Hemminger
  2016-12-23 11:04     ` Jan Blunck
  0 siblings, 1 reply; 81+ messages in thread
From: Stephen Hemminger @ 2016-12-21 20:08 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, shreyansh.jain, david.marchand

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.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 21/23] ethdev: Move filling of rte_eth_dev_info->pci_dev to dev_infos_get()
  2016-12-21 15:09 ` [PATCH v4 21/23] ethdev: Move filling of rte_eth_dev_info->pci_dev to dev_infos_get() Jan Blunck
@ 2016-12-21 20:09   ` Stephen Hemminger
  2016-12-22  8:11     ` Shreyansh Jain
  0 siblings, 1 reply; 81+ messages in thread
From: Stephen Hemminger @ 2016-12-21 20:09 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, shreyansh.jain, david.marchand

On Wed, 21 Dec 2016 16:09:44 +0100
Jan Blunck <jblunck@infradead.org> wrote:

> Only the device itself can decide its PCI or not.
> 
> Signed-off-by: Jan Blunck <jblunck@infradead.org>
> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
> ---

I would still like to kill dev_pci from the dev_info API.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 03/23] rte_device: make driver pointer const
  2016-12-21 15:09 ` [PATCH v4 03/23] rte_device: make driver pointer const Jan Blunck
@ 2016-12-22  7:18   ` Shreyansh Jain
  0 siblings, 0 replies; 81+ messages in thread
From: Shreyansh Jain @ 2016-12-22  7:18 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, Stephen Hemminger, david.marchand

On Wednesday 21 December 2016 08:39 PM, Jan Blunck wrote:
> From: Stephen Hemminger <stephen@networkplumber.org>
>
> The info in rte_device about driver is immutable and
> shouldn't change.
> Acked-by: Jan Blunck <jblunck@infradead.org>
>
> Acked-by: Jan Blunck <jblunck@infradead.org>

Not being picky - but, multiple Acked-by can be removed when this is 
applied.

> ---
>  lib/librte_eal/common/include/rte_dev.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
> index 8840380..e5471a2 100644
> --- a/lib/librte_eal/common/include/rte_dev.h
> +++ b/lib/librte_eal/common/include/rte_dev.h
> @@ -122,7 +122,7 @@ struct rte_driver;
>   */
>  struct rte_device {
>  	TAILQ_ENTRY(rte_device) next; /**< Next device */
> -	struct rte_driver *driver;    /**< Associated driver */
> +	const struct rte_driver *driver;/**< Associated driver */
>  	int numa_node;                /**< NUMA node connection */
>  	struct rte_devargs *devargs;  /**< Device user arguments */
>  };
>

Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 21/23] ethdev: Move filling of rte_eth_dev_info->pci_dev to dev_infos_get()
  2016-12-21 20:09   ` Stephen Hemminger
@ 2016-12-22  8:11     ` Shreyansh Jain
  2016-12-23 10:50       ` Jan Blunck
  0 siblings, 1 reply; 81+ messages in thread
From: Shreyansh Jain @ 2016-12-22  8:11 UTC (permalink / raw)
  To: Stephen Hemminger, Jan Blunck; +Cc: dev, david.marchand

On Thursday 22 December 2016 01:39 AM, Stephen Hemminger wrote:
> On Wed, 21 Dec 2016 16:09:44 +0100
> Jan Blunck <jblunck@infradead.org> wrote:
>
>> Only the device itself can decide its PCI or not.
>>
>> Signed-off-by: Jan Blunck <jblunck@infradead.org>
>> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>> ---
>
> I would still like to kill dev_pci from the dev_info API.
>

+1. It should be rte_dev reference instead.

(But, I am also OK about doing that immediately over this set.)

-
Shreyansh

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 22/23] ethdev: Decouple interrupt handling from PCI device
  2016-12-21 15:09 ` [PATCH v4 22/23] ethdev: Decouple interrupt handling from PCI device Jan Blunck
@ 2016-12-22 15:13   ` Thomas Monjalon
  2016-12-22 18:26     ` Jan Blunck
  0 siblings, 1 reply; 81+ messages in thread
From: Thomas Monjalon @ 2016-12-22 15:13 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, shreyansh.jain, david.marchand, stephen

2016-12-21 16:09, Jan Blunck:
> The struct rte_intr_handle is an abstraction layer for different types of
> interrupt mechanisms. It is embedded in the low-level device (e.g. PCI).
> On allocation of a struct rte_eth_dev a reference to the intr_handle
> should be stored for devices supporting interrupts.
[...]
> --- a/lib/librte_ether/rte_ethdev.h
> +++ b/lib/librte_ether/rte_ethdev.h
> @@ -1629,6 +1629,7 @@ struct rte_eth_dev {
>  	const struct eth_driver *driver;/**< Driver for this device */
>  	const struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */
>  	struct rte_pci_device *pci_dev; /**< PCI info. supplied by probing */
> +	struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
>  	/** User application callbacks for NIC interrupts */
>  	struct rte_eth_dev_cb_list link_intr_cbs;
>  	/**

Why adding interrupt in ethdev?
Shouldn't it be a property of rte_device?

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 18/23] ethdev: Helper to map to struct rte_pci_device
  2016-12-21 15:09 ` [PATCH v4 18/23] ethdev: Helper to map to struct rte_pci_device Jan Blunck
@ 2016-12-22 15:21   ` Thomas Monjalon
  2016-12-22 18:13     ` Jan Blunck
  0 siblings, 1 reply; 81+ messages in thread
From: Thomas Monjalon @ 2016-12-22 15:21 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, shreyansh.jain, david.marchand, stephen

2016-12-21 16:09, Jan Blunck:
> PCI drivers could use this helper instead of directly accessing fields of
> rte_eth_dev to map to rte_pci_device.
[...]
> +/**
> + * @internal
> + * Helper for drivers that need to convert from rte_eth_dev to rte_pci_device.
> + */
> +static inline struct rte_pci_device *__attribute__((always_inline))
> +rte_eth_dev_to_pci(struct rte_eth_dev *eth_dev)
> +{
> +	return eth_dev->pci_dev;
> +}

Why adding this function instead of just using DEV_PCI_DEV(eth_dev->device)?

I think we must try to avoid any PCI (or other bus) reference inside ethdev.h.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 23/23] ethdev: Decouple struct rte_eth_dev from struct rte_pci_device
  2016-12-21 15:09 ` [PATCH v4 23/23] ethdev: Decouple struct rte_eth_dev from struct rte_pci_device Jan Blunck
@ 2016-12-22 15:22   ` Thomas Monjalon
  0 siblings, 0 replies; 81+ messages in thread
From: Thomas Monjalon @ 2016-12-22 15:22 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, shreyansh.jain, david.marchand, stephen

2016-12-21 16:09, Jan Blunck:
> +/**
> + * @internal
> + * Helper macro for drivers that need to convert to struct rte_pci_device.
> + */
> +#define DEV_PCI_DEV(ptr) container_of(ptr, struct rte_pci_device, device)

Please use RTE_ prefix. RTE_PCI_DEV?

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 00/23] Decouple ethdev from PCI device
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (22 preceding siblings ...)
  2016-12-21 15:09 ` [PATCH v4 23/23] ethdev: Decouple struct rte_eth_dev from struct rte_pci_device Jan Blunck
@ 2016-12-22 15:26 ` Thomas Monjalon
  2016-12-23 14:28   ` Thomas Monjalon
  2016-12-23 15:57 ` [PATCH v5 00/20] " Jan Blunck
                   ` (20 subsequent siblings)
  44 siblings, 1 reply; 81+ messages in thread
From: Thomas Monjalon @ 2016-12-22 15:26 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, shreyansh.jain, david.marchand, stephen

2016-12-21 16:09, Jan Blunck:
> This is a partial merge of Stephens and my patches to make the rte_eth_dev
> independent of the rte_pci_device.

Thanks for the hard work.

> Jan Blunck (17):
>   eal: define container_of macro
>   eal: Allow passing const rte_intr_handle
>   virtio: Don't fill dev_info->driver_name
>   virtio: Add vtpci_intr_handle() helper to get rte_intr_handle
>   virtio: Don't depend on struct rte_eth_dev's pci_dev
>   bnx2x: localize mapping from eth_dev to pci
>   fm10k: localize mapping from eth_dev to pci
>   qede: localize mapping of eth_dev to pci
>   szedata2: localize handling of pci resources
>   nfp: localize rte_pci_device handling
>   vmxnet3: use eth_dev->data->drv_name instead of pci_drv name
>   ethdev: Helper to map to struct rte_pci_device
>   drivers: Replace per-PMD macros with rte_eth_dev_to_pci() helper
>   drivers: Use rte_eth_dev_to_pci() helper
>   ethdev: Move filling of rte_eth_dev_info->pci_dev to dev_infos_get()
>   ethdev: Decouple interrupt handling from PCI device
>   ethdev: Decouple struct rte_eth_dev from struct rte_pci_device
> 
> Stephen Hemminger (6):
>   rte_device: make driver pointer const
>   pmd: remove useless reset of dev_info->dev_pci
>   e1000: localize mapping from eth_dev to pci
>   ixgbe: localize mapping from eth_dev to pci_device
>   i40e: localize mapping of eth_dev to pci
>   broadcom: localize mapping from eth_dev to pci

I think it would easier to read if RTE_PCI_DEV macro was introduced at
the beginning with container_of macro and used in the "localize patches".
So the patches
	[PATCH v4 19/23] drivers: Replace per-PMD macros with rte_eth_dev_to_pci() helper
and
	[PATCH v4 20/23] drivers: Use rte_eth_dev_to_pci() helper
could be squashed in the "localize patches".

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 18/23] ethdev: Helper to map to struct rte_pci_device
  2016-12-22 15:21   ` Thomas Monjalon
@ 2016-12-22 18:13     ` Jan Blunck
  2016-12-23  8:30       ` Thomas Monjalon
  0 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-22 18:13 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Shreyansh Jain, David Marchand, Stephen Hemminger

On Thu, Dec 22, 2016 at 4:21 PM, Thomas Monjalon
<thomas.monjalon@6wind.com> wrote:
> 2016-12-21 16:09, Jan Blunck:
>> PCI drivers could use this helper instead of directly accessing fields of
>> rte_eth_dev to map to rte_pci_device.
> [...]
>> +/**
>> + * @internal
>> + * Helper for drivers that need to convert from rte_eth_dev to rte_pci_device.
>> + */
>> +static inline struct rte_pci_device *__attribute__((always_inline))
>> +rte_eth_dev_to_pci(struct rte_eth_dev *eth_dev)
>> +{
>> +     return eth_dev->pci_dev;
>> +}
>
> Why adding this function instead of just using DEV_PCI_DEV(eth_dev->device)?
>
> I think we must try to avoid any PCI (or other bus) reference inside ethdev.h.

David requested to move it from rte_pci.h to rte_ethdev.h.

It could get forward declared here if one doesn't use it. On the other
hand the rte_pci.h would be required to include rte_ethdev.h if we
move it.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 22/23] ethdev: Decouple interrupt handling from PCI device
  2016-12-22 15:13   ` Thomas Monjalon
@ 2016-12-22 18:26     ` Jan Blunck
  0 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-22 18:26 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Shreyansh Jain, David Marchand, Stephen Hemminger

On Thu, Dec 22, 2016 at 4:13 PM, Thomas Monjalon
<thomas.monjalon@6wind.com> wrote:
> 2016-12-21 16:09, Jan Blunck:
>> The struct rte_intr_handle is an abstraction layer for different types of
>> interrupt mechanisms. It is embedded in the low-level device (e.g. PCI).
>> On allocation of a struct rte_eth_dev a reference to the intr_handle
>> should be stored for devices supporting interrupts.
> [...]
>> --- a/lib/librte_ether/rte_ethdev.h
>> +++ b/lib/librte_ether/rte_ethdev.h
>> @@ -1629,6 +1629,7 @@ struct rte_eth_dev {
>>       const struct eth_driver *driver;/**< Driver for this device */
>>       const struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */
>>       struct rte_pci_device *pci_dev; /**< PCI info. supplied by probing */
>> +     struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
>>       /** User application callbacks for NIC interrupts */
>>       struct rte_eth_dev_cb_list link_intr_cbs;
>>       /**
>
> Why adding interrupt in ethdev?
> Shouldn't it be a property of rte_device?

Good question. I don't think that rte_device should become an
abstraction layer for all kind of real/virtual devices functionality.
There are devices that do not support interrupts and this
functionality is around enabling irqs per queue. Since this is a
concept of the ethdev I believe the right place to keep a reference to
the IRQ implementation is the rte_eth_dev.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 18/23] ethdev: Helper to map to struct rte_pci_device
  2016-12-22 18:13     ` Jan Blunck
@ 2016-12-23  8:30       ` Thomas Monjalon
  2016-12-23 10:27         ` Jan Blunck
  0 siblings, 1 reply; 81+ messages in thread
From: Thomas Monjalon @ 2016-12-23  8:30 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, Shreyansh Jain, David Marchand, Stephen Hemminger

2016-12-22 19:13, Jan Blunck:
> On Thu, Dec 22, 2016 at 4:21 PM, Thomas Monjalon
> <thomas.monjalon@6wind.com> wrote:
> > 2016-12-21 16:09, Jan Blunck:
> >> PCI drivers could use this helper instead of directly accessing fields of
> >> rte_eth_dev to map to rte_pci_device.
> > [...]
> >> +/**
> >> + * @internal
> >> + * Helper for drivers that need to convert from rte_eth_dev to rte_pci_device.
> >> + */
> >> +static inline struct rte_pci_device *__attribute__((always_inline))
> >> +rte_eth_dev_to_pci(struct rte_eth_dev *eth_dev)
> >> +{
> >> +     return eth_dev->pci_dev;
> >> +}
> >
> > Why adding this function instead of just using DEV_PCI_DEV(eth_dev->device)?
> >
> > I think we must try to avoid any PCI (or other bus) reference inside ethdev.h.
> 
> David requested to move it from rte_pci.h to rte_ethdev.h.
> 
> It could get forward declared here if one doesn't use it. On the other
> hand the rte_pci.h would be required to include rte_ethdev.h if we
> move it.

I think there is a misunderstanding.
I was just suggesting to drop this function.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 18/23] ethdev: Helper to map to struct rte_pci_device
  2016-12-23  8:30       ` Thomas Monjalon
@ 2016-12-23 10:27         ` Jan Blunck
  2016-12-23 12:47           ` Thomas Monjalon
  0 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 10:27 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Shreyansh Jain, David Marchand, Stephen Hemminger

On Fri, Dec 23, 2016 at 9:30 AM, Thomas Monjalon
<thomas.monjalon@6wind.com> wrote:
> 2016-12-22 19:13, Jan Blunck:
>> On Thu, Dec 22, 2016 at 4:21 PM, Thomas Monjalon
>> <thomas.monjalon@6wind.com> wrote:
>> > 2016-12-21 16:09, Jan Blunck:
>> >> PCI drivers could use this helper instead of directly accessing fields of
>> >> rte_eth_dev to map to rte_pci_device.
>> > [...]
>> >> +/**
>> >> + * @internal
>> >> + * Helper for drivers that need to convert from rte_eth_dev to rte_pci_device.
>> >> + */
>> >> +static inline struct rte_pci_device *__attribute__((always_inline))
>> >> +rte_eth_dev_to_pci(struct rte_eth_dev *eth_dev)
>> >> +{
>> >> +     return eth_dev->pci_dev;
>> >> +}
>> >
>> > Why adding this function instead of just using DEV_PCI_DEV(eth_dev->device)?
>> >
>> > I think we must try to avoid any PCI (or other bus) reference inside ethdev.h.
>>
>> David requested to move it from rte_pci.h to rte_ethdev.h.
>>
>> It could get forward declared here if one doesn't use it. On the other
>> hand the rte_pci.h would be required to include rte_ethdev.h if we
>> move it.
>
> I think there is a misunderstanding.
> I was just suggesting to drop this function.

But that would undo the whole purpose of adding a helper. The purpose
of the helper is to map from ethdev to the low-level rte_pci_device.
If we remove this helper all users still need to know how to map to
the embedded device structure. What you ask for also means that the
patch "ethdev: Decouple struct rte_eth_dev from struct rte_pci_device"
needs to change all users of the DEV_PCI_DEV() instead of changing the
helper introduced in this patch.

Let me summarize the workable options from my perspective:
1. helper macro to map from eth_dev to pci_dev in rte_pci.h
2. helper inline function to map from eth_dev to pci_dev in rte_ethdev.h
3. put helpers into new header file rte_ethdrv.h

I'm still in favor of the first option but David suggested to remove
it from eal. I could also counter the type-safety argument from
Stephen by adding a type check to it.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 21/23] ethdev: Move filling of rte_eth_dev_info->pci_dev to dev_infos_get()
  2016-12-22  8:11     ` Shreyansh Jain
@ 2016-12-23 10:50       ` Jan Blunck
  2016-12-23 11:11         ` Shreyansh Jain
  0 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 10:50 UTC (permalink / raw)
  To: Shreyansh Jain; +Cc: Stephen Hemminger, dev, David Marchand

On Thu, Dec 22, 2016 at 9:11 AM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> On Thursday 22 December 2016 01:39 AM, Stephen Hemminger wrote:
>>
>> On Wed, 21 Dec 2016 16:09:44 +0100
>> Jan Blunck <jblunck@infradead.org> wrote:
>>
>>> Only the device itself can decide its PCI or not.
>>>
>>> Signed-off-by: Jan Blunck <jblunck@infradead.org>
>>> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>>> ---
>>
>>
>> I would still like to kill dev_pci from the dev_info API.
>>

I'm fine with that too.

>
> +1. It should be rte_dev reference instead.
>

Only if you can give use-cases for what users should be able to do
with it. If that is the case we need to clearly define what that
means. Do we want to enable users to control the low-level EAL device
directly and shortcut the ethdev driver? If that is necessary we need
to give control to the driver first to decide if it is safe to do so.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 10/23] virtio: Add vtpci_intr_handle() helper to get rte_intr_handle
  2016-12-21 20:08   ` Stephen Hemminger
@ 2016-12-23 11:04     ` Jan Blunck
  0 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 11:04 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev, Shreyansh Jain, David Marchand

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.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 21/23] ethdev: Move filling of rte_eth_dev_info->pci_dev to dev_infos_get()
  2016-12-23 10:50       ` Jan Blunck
@ 2016-12-23 11:11         ` Shreyansh Jain
  2016-12-23 11:27           ` Jan Blunck
  0 siblings, 1 reply; 81+ messages in thread
From: Shreyansh Jain @ 2016-12-23 11:11 UTC (permalink / raw)
  To: Jan Blunck; +Cc: Stephen Hemminger, dev, David Marchand

On Friday 23 December 2016 04:20 PM, Jan Blunck wrote:
> On Thu, Dec 22, 2016 at 9:11 AM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>> On Thursday 22 December 2016 01:39 AM, Stephen Hemminger wrote:
>>>
>>> On Wed, 21 Dec 2016 16:09:44 +0100
>>> Jan Blunck <jblunck@infradead.org> wrote:
>>>
>>>> Only the device itself can decide its PCI or not.
>>>>
>>>> Signed-off-by: Jan Blunck <jblunck@infradead.org>
>>>> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>>>> ---
>>>
>>>
>>> I would still like to kill dev_pci from the dev_info API.
>>>
>
> I'm fine with that too.
>
>>
>> +1. It should be rte_dev reference instead.
>>
>
> Only if you can give use-cases for what users should be able to do
> with it. If that is the case we need to clearly define what that
> means. Do we want to enable users to control the low-level EAL device
> directly and shortcut the ethdev driver? If that is necessary we need
> to give control to the driver first to decide if it is safe to do so.
>

An ethernet device is not necessarily a PCI device. With planned removal 
of rte_pci_device from rte_eth_device, this will be realized.
Similarly, the info is also not PCI device specific.

With the '+1', my intention was not to say we should do it in this 
patch. We should prepare eth_dev_info in similar manner as done for 
pci_dev of rte_eth_dev (ETH_DEV_PCI_DEV() style macro, or inline).

And now for whether we should expose lower level device details or not, 
I was of the view that keeping pci_dev linked to this structure exposes 
more lower level info than keeping rte_dev. Another view point could be 
to completely do away with pci_info within eth_dev_info - but, I am not 
sure of dependencies on it.

-
Shreyansh

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 21/23] ethdev: Move filling of rte_eth_dev_info->pci_dev to dev_infos_get()
  2016-12-23 11:11         ` Shreyansh Jain
@ 2016-12-23 11:27           ` Jan Blunck
  2016-12-23 11:39             ` Shreyansh Jain
  0 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 11:27 UTC (permalink / raw)
  To: Shreyansh Jain; +Cc: Stephen Hemminger, dev, David Marchand

On Fri, Dec 23, 2016 at 12:11 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> On Friday 23 December 2016 04:20 PM, Jan Blunck wrote:
>>
>> On Thu, Dec 22, 2016 at 9:11 AM, Shreyansh Jain <shreyansh.jain@nxp.com>
>> wrote:
>>>
>>> On Thursday 22 December 2016 01:39 AM, Stephen Hemminger wrote:
>>>>
>>>>
>>>> On Wed, 21 Dec 2016 16:09:44 +0100
>>>> Jan Blunck <jblunck@infradead.org> wrote:
>>>>
>>>>> Only the device itself can decide its PCI or not.
>>>>>
>>>>> Signed-off-by: Jan Blunck <jblunck@infradead.org>
>>>>> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>>>>> ---
>>>>
>>>>
>>>>
>>>> I would still like to kill dev_pci from the dev_info API.
>>>>
>>
>> I'm fine with that too.
>>
>>>
>>> +1. It should be rte_dev reference instead.
>>>
>>
>> Only if you can give use-cases for what users should be able to do
>> with it. If that is the case we need to clearly define what that
>> means. Do we want to enable users to control the low-level EAL device
>> directly and shortcut the ethdev driver? If that is necessary we need
>> to give control to the driver first to decide if it is safe to do so.
>>
>
> An ethernet device is not necessarily a PCI device. With planned removal of
> rte_pci_device from rte_eth_device, this will be realized.
> Similarly, the info is also not PCI device specific.
>
> With the '+1', my intention was not to say we should do it in this patch. We
> should prepare eth_dev_info in similar manner as done for pci_dev of
> rte_eth_dev (ETH_DEV_PCI_DEV() style macro, or inline).

Which is exactly what this patch is doing. I'm moving the filling of
the PCI information out of the generic code because only the driver
could know if it is actually handling a PCI device. The generic code
can not use the ETH_DEV_PCI_DEV() macro in a safe manner.

> And now for whether we should expose lower level device details or not, I
> was of the view that keeping pci_dev linked to this structure exposes more
> lower level info than keeping rte_dev. Another view point could be to
> completely do away with pci_info within eth_dev_info - but, I am not sure of
> dependencies on it.

If I understand Stephen correctly he questions the benefit of pushing
down the code to the drivers instead of killing that code completely.
I'll see what I can do here.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 21/23] ethdev: Move filling of rte_eth_dev_info->pci_dev to dev_infos_get()
  2016-12-23 11:27           ` Jan Blunck
@ 2016-12-23 11:39             ` Shreyansh Jain
  0 siblings, 0 replies; 81+ messages in thread
From: Shreyansh Jain @ 2016-12-23 11:39 UTC (permalink / raw)
  To: Jan Blunck; +Cc: Stephen Hemminger, dev, David Marchand

On Friday 23 December 2016 04:57 PM, Jan Blunck wrote:
> On Fri, Dec 23, 2016 at 12:11 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>> On Friday 23 December 2016 04:20 PM, Jan Blunck wrote:
>>>
>>> On Thu, Dec 22, 2016 at 9:11 AM, Shreyansh Jain <shreyansh.jain@nxp.com>
>>> wrote:
>>>>
>>>> On Thursday 22 December 2016 01:39 AM, Stephen Hemminger wrote:
>>>>>
>>>>>
>>>>> On Wed, 21 Dec 2016 16:09:44 +0100
>>>>> Jan Blunck <jblunck@infradead.org> wrote:
>>>>>
>>>>>> Only the device itself can decide its PCI or not.
>>>>>>
>>>>>> Signed-off-by: Jan Blunck <jblunck@infradead.org>
>>>>>> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>>>>>> ---
>>>>>
>>>>>
>>>>>
>>>>> I would still like to kill dev_pci from the dev_info API.
>>>>>
>>>
>>> I'm fine with that too.
>>>
>>>>
>>>> +1. It should be rte_dev reference instead.
>>>>
>>>
>>> Only if you can give use-cases for what users should be able to do
>>> with it. If that is the case we need to clearly define what that
>>> means. Do we want to enable users to control the low-level EAL device
>>> directly and shortcut the ethdev driver? If that is necessary we need
>>> to give control to the driver first to decide if it is safe to do so.
>>>
>>
>> An ethernet device is not necessarily a PCI device. With planned removal of
>> rte_pci_device from rte_eth_device, this will be realized.
>> Similarly, the info is also not PCI device specific.
>>
>> With the '+1', my intention was not to say we should do it in this patch. We
>> should prepare eth_dev_info in similar manner as done for pci_dev of
>> rte_eth_dev (ETH_DEV_PCI_DEV() style macro, or inline).
>
> Which is exactly what this patch is doing. I'm moving the filling of
> the PCI information out of the generic code because only the driver
> could know if it is actually handling a PCI device. The generic code
> can not use the ETH_DEV_PCI_DEV() macro in a safe manner.

I fully agree with you and support this series.

Probably I went a step further in my eagerness - I was only hinting that 
now info filling part is relatively free of pci-ness, we should remove 
eth_dev_info linkage to PCI.

There is no change I am expecting in your patch in this regard. Yours is 
the first step to this change.

>
>> And now for whether we should expose lower level device details or not, I
>> was of the view that keeping pci_dev linked to this structure exposes more
>> lower level info than keeping rte_dev. Another view point could be to
>> completely do away with pci_info within eth_dev_info - but, I am not sure of
>> dependencies on it.
>
> If I understand Stephen correctly he questions the benefit of pushing
> down the code to the drivers instead of killing that code completely.
> I'll see what I can do here.
>

Ok. Then I read it wrong. I read it in the sense that we should remove 
PCI dependency of eth_info. Except, I considered that removal more as 
replacement with rte_device. My mistake!

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 18/23] ethdev: Helper to map to struct rte_pci_device
  2016-12-23 10:27         ` Jan Blunck
@ 2016-12-23 12:47           ` Thomas Monjalon
  0 siblings, 0 replies; 81+ messages in thread
From: Thomas Monjalon @ 2016-12-23 12:47 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, Shreyansh Jain, David Marchand, Stephen Hemminger

2016-12-23 11:27, Jan Blunck:
> On Fri, Dec 23, 2016 at 9:30 AM, Thomas Monjalon
> <thomas.monjalon@6wind.com> wrote:
> > 2016-12-22 19:13, Jan Blunck:
> >> On Thu, Dec 22, 2016 at 4:21 PM, Thomas Monjalon
> >> <thomas.monjalon@6wind.com> wrote:
> >> > 2016-12-21 16:09, Jan Blunck:
> >> >> PCI drivers could use this helper instead of directly accessing fields of
> >> >> rte_eth_dev to map to rte_pci_device.
> >> > [...]
> >> >> +/**
> >> >> + * @internal
> >> >> + * Helper for drivers that need to convert from rte_eth_dev to rte_pci_device.
> >> >> + */
> >> >> +static inline struct rte_pci_device *__attribute__((always_inline))
> >> >> +rte_eth_dev_to_pci(struct rte_eth_dev *eth_dev)
> >> >> +{
> >> >> +     return eth_dev->pci_dev;
> >> >> +}
> >> >
> >> > Why adding this function instead of just using DEV_PCI_DEV(eth_dev->device)?
> >> >
> >> > I think we must try to avoid any PCI (or other bus) reference inside ethdev.h.
> >>
> >> David requested to move it from rte_pci.h to rte_ethdev.h.
> >>
> >> It could get forward declared here if one doesn't use it. On the other
> >> hand the rte_pci.h would be required to include rte_ethdev.h if we
> >> move it.
> >
> > I think there is a misunderstanding.
> > I was just suggesting to drop this function.
> 
> But that would undo the whole purpose of adding a helper. The purpose
> of the helper is to map from ethdev to the low-level rte_pci_device.
> If we remove this helper all users still need to know how to map to
> the embedded device structure. What you ask for also means that the
> patch "ethdev: Decouple struct rte_eth_dev from struct rte_pci_device"
> needs to change all users of the DEV_PCI_DEV() instead of changing the
> helper introduced in this patch.

Yes, using RTE_PCI_DEV(eth_dev->device) instead of rte_eth_dev_to_pci(eth_dev).
Is it a problem to know that the field name is "device" to access the
underlying device characteristics?

> Let me summarize the workable options from my perspective:
> 1. helper macro to map from eth_dev to pci_dev in rte_pci.h
> 2. helper inline function to map from eth_dev to pci_dev in rte_ethdev.h
> 3. put helpers into new header file rte_ethdrv.h
> 
> I'm still in favor of the first option but David suggested to remove
> it from eal. I could also counter the type-safety argument from
> Stephen by adding a type check to it.

My proposal is:
4. no helper, use eth_dev->device

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v4 00/23] Decouple ethdev from PCI device
  2016-12-22 15:26 ` [PATCH v4 00/23] Decouple ethdev from PCI device Thomas Monjalon
@ 2016-12-23 14:28   ` Thomas Monjalon
  0 siblings, 0 replies; 81+ messages in thread
From: Thomas Monjalon @ 2016-12-23 14:28 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, shreyansh.jain, david.marchand, stephen

2016-12-22 16:26, Thomas Monjalon:
> I think it would easier to read if RTE_PCI_DEV macro was introduced at
> the beginning with container_of macro and used in the "localize patches".
> So the patches
> 	[PATCH v4 19/23] drivers: Replace per-PMD macros with rte_eth_dev_to_pci() helper
> and
> 	[PATCH v4 20/23] drivers: Use rte_eth_dev_to_pci() helper
> could be squashed in the "localize patches".

After a private discussion, I've understood that my proposal was stupid :)
RTE_PCI_DEV is used when the ethdev field is converted from pci_dev to device.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* [PATCH v5 00/20] Decouple ethdev from PCI device
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (23 preceding siblings ...)
  2016-12-22 15:26 ` [PATCH v4 00/23] Decouple ethdev from PCI device Thomas Monjalon
@ 2016-12-23 15:57 ` Jan Blunck
  2016-12-25 22:33   ` Thomas Monjalon
  2016-12-23 15:57 ` [PATCH v5 01/20] eal: define container_of macro Jan Blunck
                   ` (19 subsequent siblings)
  44 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:57 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

This repost addresses the review comments of Thomas Monjalon to completely
remove the ethdev helper to further decrease the coupling of the ethdev and
the eal layers. This required me to squash together all patches using the
rte_eth_dev_to_pci() helper into "Decouple from PCI device" patch. As
discussed privately I'll keep the PCI information in rte_eth_dev_info
untouched.

Changes between v5 and v4:
 - Removed ethdev helper rte_eth_dev_to_pci()

Changes between v4 and v3:
 - broken out refactorings of drivers similar to Stephens example
 - use inline function instead of macro
 - fix build issues with bnx2x and mlx4/5

Changes between v3 and v2:
 - converted PCI device users I've missed in previous version

Jan Blunck (14):
  eal: define container_of macro
  eal: Allow passing const rte_intr_handle
  virtio: Don't fill dev_info->driver_name
  virtio: Add vtpci_intr_handle() helper to get rte_intr_handle
  virtio: Don't depend on struct rte_eth_dev's pci_dev
  bnx2x: localize mapping from eth_dev to pci
  fm10k: localize mapping from eth_dev to pci
  qede: localize mapping of eth_dev to pci
  szedata2: localize handling of pci resources
  nfp: localize rte_pci_device handling
  vmxnet3: use eth_dev->data->drv_name instead of pci_drv name
  ethdev: Decouple interrupt handling from PCI device
  ethdev: Move dev_info filling of PCI information into drivers
  ethdev: Decouple from PCI device

Stephen Hemminger (6):
  rte_device: make driver pointer const
  pmd: remove useless reset of dev_info->dev_pci
  e1000: localize mapping from eth_dev to pci
  ixgbe: localize mapping from eth_dev to pci_device
  i40e: localize mapping of eth_dev to pci
  broadcom: localize mapping from eth_dev to pci

 app/test/virtual_pmd.c                         |   5 +-
 drivers/net/af_packet/rte_eth_af_packet.c      |   1 -
 drivers/net/bnx2x/bnx2x_ethdev.c               |  15 +--
 drivers/net/bnxt/bnxt_ethdev.c                 |  24 +++--
 drivers/net/bnxt/bnxt_ring.c                   |  16 ++--
 drivers/net/bonding/rte_eth_bond_args.c        |  12 ++-
 drivers/net/bonding/rte_eth_bond_pmd.c         |   1 -
 drivers/net/cxgbe/cxgbe_ethdev.c               |   4 +-
 drivers/net/cxgbe/cxgbe_main.c                 |   4 +-
 drivers/net/e1000/e1000_ethdev.h               |   2 +
 drivers/net/e1000/em_ethdev.c                  |  51 ++++++-----
 drivers/net/e1000/igb_ethdev.c                 | 101 +++++++++++---------
 drivers/net/e1000/igb_pf.c                     |   4 +-
 drivers/net/ena/ena_ethdev.c                   |   4 +-
 drivers/net/enic/enic_ethdev.c                 |   3 +-
 drivers/net/fm10k/fm10k_ethdev.c               |  84 +++++++++--------
 drivers/net/i40e/i40e_ethdev.c                 |  78 ++++++++++------
 drivers/net/i40e/i40e_ethdev.h                 |   3 +
 drivers/net/i40e/i40e_ethdev_vf.c              |  59 +++++++-----
 drivers/net/ixgbe/ixgbe_ethdev.c               | 122 ++++++++++++++-----------
 drivers/net/ixgbe/ixgbe_ethdev.h               |   3 +
 drivers/net/ixgbe/ixgbe_pf.c                   |   4 +-
 drivers/net/mlx4/mlx4.c                        |   4 +-
 drivers/net/mlx5/mlx5.c                        |   2 +-
 drivers/net/mlx5/mlx5_ethdev.c                 |   2 +
 drivers/net/nfp/nfp_net.c                      |  19 ++--
 drivers/net/null/rte_eth_null.c                |   1 -
 drivers/net/pcap/rte_eth_pcap.c                |   1 -
 drivers/net/qede/qede_ethdev.c                 |  19 ++--
 drivers/net/ring/rte_eth_ring.c                |   1 -
 drivers/net/szedata2/rte_eth_szedata2.c        |  73 +++++++++------
 drivers/net/szedata2/rte_eth_szedata2.h        |  58 +++++-------
 drivers/net/thunderx/nicvf_ethdev.c            |   7 +-
 drivers/net/virtio/virtio_ethdev.c             |  44 ++++-----
 drivers/net/virtio/virtio_pci.h                |   6 ++
 drivers/net/virtio/virtio_user_ethdev.c        |   1 -
 drivers/net/vmxnet3/vmxnet3_ethdev.c           |   8 +-
 drivers/net/xenvirt/rte_eth_xenvirt.c          |   1 -
 lib/librte_eal/bsdapp/eal/eal_interrupts.c     |  24 +++--
 lib/librte_eal/common/include/rte_common.h     |  20 ++++
 lib/librte_eal/common/include/rte_dev.h        |   2 +-
 lib/librte_eal/common/include/rte_interrupts.h |   8 +-
 lib/librte_eal/common/include/rte_pci.h        |   6 ++
 lib/librte_eal/linuxapp/eal/eal_interrupts.c   |  62 +++++++++----
 lib/librte_ether/rte_ethdev.c                  |  25 +++--
 lib/librte_ether/rte_ethdev.h                  |   3 +-
 46 files changed, 594 insertions(+), 403 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 81+ messages in thread

* [PATCH v5 01/20] eal: define container_of macro
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (24 preceding siblings ...)
  2016-12-23 15:57 ` [PATCH v5 00/20] " Jan Blunck
@ 2016-12-23 15:57 ` Jan Blunck
  2016-12-23 15:57 ` [PATCH v5 02/20] eal: Allow passing const rte_intr_handle Jan Blunck
                   ` (18 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:57 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen, Jan Viktorin

This macro is based on Jan Viktorin's original patch but also checks the
type of the passed pointer against the type of the member.

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
[jblunck@infradead.org: add type checking and __extension__]
Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/include/rte_common.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index db5ac91..8dda3e2 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -331,6 +331,26 @@ rte_bsf32(uint32_t v)
 #define offsetof(TYPE, MEMBER)  __builtin_offsetof (TYPE, MEMBER)
 #endif
 
+/**
+ * Return pointer to the wrapping struct instance.
+ *
+ * Example:
+ *
+ *  struct wrapper {
+ *      ...
+ *      struct child c;
+ *      ...
+ *  };
+ *
+ *  struct child *x = obtain(...);
+ *  struct wrapper *w = container_of(x, struct wrapper, c);
+ */
+#ifndef container_of
+#define container_of(ptr, type, member)	__extension__ ({		\
+			typeof(((type *)0)->member) *_ptr = (ptr);	\
+			(type *)(((char *)_ptr) - offsetof(type, member)); })
+#endif
+
 #define _RTE_STR(x) #x
 /** Take a macro value and get a string version of it */
 #define RTE_STR(x) _RTE_STR(x)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 02/20] eal: Allow passing const rte_intr_handle
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (25 preceding siblings ...)
  2016-12-23 15:57 ` [PATCH v5 01/20] eal: define container_of macro Jan Blunck
@ 2016-12-23 15:57 ` Jan Blunck
  2017-01-17  4:42   ` Tan, Jianfeng
  2016-12-23 15:57 ` [PATCH v5 03/20] rte_device: make driver pointer const Jan Blunck
                   ` (17 subsequent siblings)
  44 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:57 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

Both register/unregister and enable/disable don't necessarily require the
rte_intr_handle to be modifiable. Therefore lets constify it.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/bsdapp/eal/eal_interrupts.c     | 24 ++++++----
 lib/librte_eal/common/include/rte_interrupts.h |  8 ++--
 lib/librte_eal/linuxapp/eal/eal_interrupts.c   | 62 ++++++++++++++++++--------
 3 files changed, 63 insertions(+), 31 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_interrupts.c b/lib/librte_eal/bsdapp/eal/eal_interrupts.c
index 836e483..ea2afff 100644
--- a/lib/librte_eal/bsdapp/eal/eal_interrupts.c
+++ b/lib/librte_eal/bsdapp/eal/eal_interrupts.c
@@ -36,29 +36,37 @@
 #include "eal_private.h"
 
 int
-rte_intr_callback_register(struct rte_intr_handle *intr_handle __rte_unused,
-			rte_intr_callback_fn cb __rte_unused,
-			void *cb_arg __rte_unused)
+rte_intr_callback_register(const struct rte_intr_handle *intr_handle,
+			rte_intr_callback_fn cb,
+			void *cb_arg)
 {
+	RTE_SET_USED(intr_handle);
+	RTE_SET_USED(cb);
+	RTE_SET_USED(cb_arg);
+
 	return -ENOTSUP;
 }
 
 int
-rte_intr_callback_unregister(struct rte_intr_handle *intr_handle __rte_unused,
-			rte_intr_callback_fn cb_fn __rte_unused,
-			void *cb_arg __rte_unused)
+rte_intr_callback_unregister(const struct rte_intr_handle *intr_handle,
+			rte_intr_callback_fn cb,
+			void *cb_arg)
 {
+	RTE_SET_USED(intr_handle);
+	RTE_SET_USED(cb);
+	RTE_SET_USED(cb_arg);
+
 	return -ENOTSUP;
 }
 
 int
-rte_intr_enable(struct rte_intr_handle *intr_handle __rte_unused)
+rte_intr_enable(const struct rte_intr_handle *intr_handle __rte_unused)
 {
 	return -ENOTSUP;
 }
 
 int
-rte_intr_disable(struct rte_intr_handle *intr_handle __rte_unused)
+rte_intr_disable(const struct rte_intr_handle *intr_handle __rte_unused)
 {
 	return -ENOTSUP;
 }
diff --git a/lib/librte_eal/common/include/rte_interrupts.h b/lib/librte_eal/common/include/rte_interrupts.h
index fd3c6ef..6cade01 100644
--- a/lib/librte_eal/common/include/rte_interrupts.h
+++ b/lib/librte_eal/common/include/rte_interrupts.h
@@ -70,7 +70,7 @@ typedef void (*rte_intr_callback_fn)(struct rte_intr_handle *intr_handle,
  *  - On success, zero.
  *  - On failure, a negative value.
  */
-int rte_intr_callback_register(struct rte_intr_handle *intr_handle,
+int rte_intr_callback_register(const struct rte_intr_handle *intr_handle,
 				rte_intr_callback_fn cb, void *cb_arg);
 
 /**
@@ -88,7 +88,7 @@ int rte_intr_callback_register(struct rte_intr_handle *intr_handle,
  *  - On success, return the number of callback entities removed.
  *  - On failure, a negative value.
  */
-int rte_intr_callback_unregister(struct rte_intr_handle *intr_handle,
+int rte_intr_callback_unregister(const struct rte_intr_handle *intr_handle,
 				rte_intr_callback_fn cb, void *cb_arg);
 
 /**
@@ -101,7 +101,7 @@ int rte_intr_callback_unregister(struct rte_intr_handle *intr_handle,
  *  - On success, zero.
  *  - On failure, a negative value.
  */
-int rte_intr_enable(struct rte_intr_handle *intr_handle);
+int rte_intr_enable(const struct rte_intr_handle *intr_handle);
 
 /**
  * It disables the interrupt for the specified handle.
@@ -113,7 +113,7 @@ int rte_intr_enable(struct rte_intr_handle *intr_handle);
  *  - On success, zero.
  *  - On failure, a negative value.
  */
-int rte_intr_disable(struct rte_intr_handle *intr_handle);
+int rte_intr_disable(const struct rte_intr_handle *intr_handle);
 
 #ifdef __cplusplus
 }
diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
index 47a3b20..cb55751 100644
--- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c
+++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
@@ -136,7 +136,7 @@ static pthread_t intr_thread;
 
 /* enable legacy (INTx) interrupts */
 static int
-vfio_enable_intx(struct rte_intr_handle *intr_handle) {
+vfio_enable_intx(const struct rte_intr_handle *intr_handle) {
 	struct vfio_irq_set *irq_set;
 	char irq_set_buf[IRQ_SET_BUF_LEN];
 	int len, ret;
@@ -183,7 +183,7 @@ vfio_enable_intx(struct rte_intr_handle *intr_handle) {
 
 /* disable legacy (INTx) interrupts */
 static int
-vfio_disable_intx(struct rte_intr_handle *intr_handle) {
+vfio_disable_intx(const struct rte_intr_handle *intr_handle) {
 	struct vfio_irq_set *irq_set;
 	char irq_set_buf[IRQ_SET_BUF_LEN];
 	int len, ret;
@@ -226,7 +226,7 @@ vfio_disable_intx(struct rte_intr_handle *intr_handle) {
 
 /* enable MSI interrupts */
 static int
-vfio_enable_msi(struct rte_intr_handle *intr_handle) {
+vfio_enable_msi(const struct rte_intr_handle *intr_handle) {
 	int len, ret;
 	char irq_set_buf[IRQ_SET_BUF_LEN];
 	struct vfio_irq_set *irq_set;
@@ -255,7 +255,7 @@ vfio_enable_msi(struct rte_intr_handle *intr_handle) {
 
 /* disable MSI interrupts */
 static int
-vfio_disable_msi(struct rte_intr_handle *intr_handle) {
+vfio_disable_msi(const struct rte_intr_handle *intr_handle) {
 	struct vfio_irq_set *irq_set;
 	char irq_set_buf[IRQ_SET_BUF_LEN];
 	int len, ret;
@@ -278,9 +278,30 @@ vfio_disable_msi(struct rte_intr_handle *intr_handle) {
 	return ret;
 }
 
+static int
+get_max_intr(const struct rte_intr_handle *intr_handle)
+{
+	struct rte_intr_source *src;
+
+	TAILQ_FOREACH(src, &intr_sources, next) {
+		if (src->intr_handle.fd != intr_handle->fd)
+			continue;
+
+		if (!src->intr_handle.max_intr)
+			src->intr_handle.max_intr = 1;
+		else if (src->intr_handle.max_intr > RTE_MAX_RXTX_INTR_VEC_ID)
+			src->intr_handle.max_intr
+				= RTE_MAX_RXTX_INTR_VEC_ID + 1;
+
+		return src->intr_handle.max_intr;
+	}
+
+	return -1;
+}
+
 /* enable MSI-X interrupts */
 static int
-vfio_enable_msix(struct rte_intr_handle *intr_handle) {
+vfio_enable_msix(const struct rte_intr_handle *intr_handle) {
 	int len, ret;
 	char irq_set_buf[MSIX_IRQ_SET_BUF_LEN];
 	struct vfio_irq_set *irq_set;
@@ -290,12 +311,15 @@ vfio_enable_msix(struct rte_intr_handle *intr_handle) {
 
 	irq_set = (struct vfio_irq_set *) irq_set_buf;
 	irq_set->argsz = len;
-	if (!intr_handle->max_intr)
-		intr_handle->max_intr = 1;
-	else if (intr_handle->max_intr > RTE_MAX_RXTX_INTR_VEC_ID)
-		intr_handle->max_intr = RTE_MAX_RXTX_INTR_VEC_ID + 1;
 
-	irq_set->count = intr_handle->max_intr;
+	ret = get_max_intr(intr_handle);
+	if (ret < 0) {
+		RTE_LOG(ERR, EAL, "Invalid number of MSI-X irqs for fd %d\n",
+			intr_handle->fd);
+		return -1;
+	}
+
+	irq_set->count = ret;
 	irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER;
 	irq_set->index = VFIO_PCI_MSIX_IRQ_INDEX;
 	irq_set->start = 0;
@@ -318,7 +342,7 @@ vfio_enable_msix(struct rte_intr_handle *intr_handle) {
 
 /* disable MSI-X interrupts */
 static int
-vfio_disable_msix(struct rte_intr_handle *intr_handle) {
+vfio_disable_msix(const struct rte_intr_handle *intr_handle) {
 	struct vfio_irq_set *irq_set;
 	char irq_set_buf[MSIX_IRQ_SET_BUF_LEN];
 	int len, ret;
@@ -343,7 +367,7 @@ vfio_disable_msix(struct rte_intr_handle *intr_handle) {
 #endif
 
 static int
-uio_intx_intr_disable(struct rte_intr_handle *intr_handle)
+uio_intx_intr_disable(const struct rte_intr_handle *intr_handle)
 {
 	unsigned char command_high;
 
@@ -367,7 +391,7 @@ uio_intx_intr_disable(struct rte_intr_handle *intr_handle)
 }
 
 static int
-uio_intx_intr_enable(struct rte_intr_handle *intr_handle)
+uio_intx_intr_enable(const struct rte_intr_handle *intr_handle)
 {
 	unsigned char command_high;
 
@@ -391,7 +415,7 @@ uio_intx_intr_enable(struct rte_intr_handle *intr_handle)
 }
 
 static int
-uio_intr_disable(struct rte_intr_handle *intr_handle)
+uio_intr_disable(const struct rte_intr_handle *intr_handle)
 {
 	const int value = 0;
 
@@ -405,7 +429,7 @@ uio_intr_disable(struct rte_intr_handle *intr_handle)
 }
 
 static int
-uio_intr_enable(struct rte_intr_handle *intr_handle)
+uio_intr_enable(const struct rte_intr_handle *intr_handle)
 {
 	const int value = 1;
 
@@ -419,7 +443,7 @@ uio_intr_enable(struct rte_intr_handle *intr_handle)
 }
 
 int
-rte_intr_callback_register(struct rte_intr_handle *intr_handle,
+rte_intr_callback_register(const struct rte_intr_handle *intr_handle,
 			rte_intr_callback_fn cb, void *cb_arg)
 {
 	int ret, wake_thread;
@@ -491,7 +515,7 @@ rte_intr_callback_register(struct rte_intr_handle *intr_handle,
 }
 
 int
-rte_intr_callback_unregister(struct rte_intr_handle *intr_handle,
+rte_intr_callback_unregister(const struct rte_intr_handle *intr_handle,
 			rte_intr_callback_fn cb_fn, void *cb_arg)
 {
 	int ret;
@@ -555,7 +579,7 @@ rte_intr_callback_unregister(struct rte_intr_handle *intr_handle,
 }
 
 int
-rte_intr_enable(struct rte_intr_handle *intr_handle)
+rte_intr_enable(const struct rte_intr_handle *intr_handle)
 {
 	if (!intr_handle || intr_handle->fd < 0 || intr_handle->uio_cfg_fd < 0)
 		return -1;
@@ -599,7 +623,7 @@ rte_intr_enable(struct rte_intr_handle *intr_handle)
 }
 
 int
-rte_intr_disable(struct rte_intr_handle *intr_handle)
+rte_intr_disable(const struct rte_intr_handle *intr_handle)
 {
 	if (!intr_handle || intr_handle->fd < 0 || intr_handle->uio_cfg_fd < 0)
 		return -1;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 03/20] rte_device: make driver pointer const
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (26 preceding siblings ...)
  2016-12-23 15:57 ` [PATCH v5 02/20] eal: Allow passing const rte_intr_handle Jan Blunck
@ 2016-12-23 15:57 ` Jan Blunck
  2016-12-23 16:19   ` Thomas Monjalon
  2016-12-23 22:08   ` Stephen Hemminger
  2016-12-23 15:57 ` [PATCH v5 04/20] pmd: remove useless reset of dev_info->dev_pci Jan Blunck
                   ` (16 subsequent siblings)
  44 siblings, 2 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:57 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, shreyansh.jain, david.marchand

From: Stephen Hemminger <stephen@networkplumber.org>

The info in rte_device about driver is immutable and
shouldn't change.

Acked-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/include/rte_dev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index 1708244..b17791f 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -122,7 +122,7 @@ struct rte_driver;
  */
 struct rte_device {
 	TAILQ_ENTRY(rte_device) next; /**< Next device */
-	struct rte_driver *driver;    /**< Associated driver */
+	const struct rte_driver *driver;/**< Associated driver */
 	int numa_node;                /**< NUMA node connection */
 	struct rte_devargs *devargs;  /**< Device user arguments */
 };
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 04/20] pmd: remove useless reset of dev_info->dev_pci
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (27 preceding siblings ...)
  2016-12-23 15:57 ` [PATCH v5 03/20] rte_device: make driver pointer const Jan Blunck
@ 2016-12-23 15:57 ` Jan Blunck
  2016-12-23 15:57 ` [PATCH v5 05/20] e1000: localize mapping from eth_dev to pci Jan Blunck
                   ` (15 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:57 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, shreyansh.jain, david.marchand, Stephen Hemminger

From: Stephen Hemminger <stephen@networkplumber.org>

Since rte_eth_dev_info_get does memset() on dev_info before
calling device specific code, the explicit assignment of NULL
in all these virtual drivers has no effect.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
Acked-by: Jan Blunck <jblunck@infradead.org>
---
 app/test/virtual_pmd.c                    | 1 -
 drivers/net/af_packet/rte_eth_af_packet.c | 1 -
 drivers/net/bonding/rte_eth_bond_pmd.c    | 1 -
 drivers/net/null/rte_eth_null.c           | 1 -
 drivers/net/pcap/rte_eth_pcap.c           | 1 -
 drivers/net/ring/rte_eth_ring.c           | 1 -
 drivers/net/xenvirt/rte_eth_xenvirt.c     | 1 -
 7 files changed, 7 deletions(-)

diff --git a/app/test/virtual_pmd.c b/app/test/virtual_pmd.c
index bd969f9..2517208 100644
--- a/app/test/virtual_pmd.c
+++ b/app/test/virtual_pmd.c
@@ -117,7 +117,6 @@ virtual_ethdev_info_get(struct rte_eth_dev *dev __rte_unused,
 	dev_info->max_tx_queues = (uint16_t)512;
 
 	dev_info->min_rx_bufsize = 0;
-	dev_info->pci_dev = NULL;
 }
 
 static int
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index ff45068..2951f86 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -287,7 +287,6 @@ eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	dev_info->max_rx_queues = (uint16_t)internals->nb_queues;
 	dev_info->max_tx_queues = (uint16_t)internals->nb_queues;
 	dev_info->min_rx_bufsize = 0;
-	dev_info->pci_dev = NULL;
 }
 
 static void
diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c
index b604642..c1796f2 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -1672,7 +1672,6 @@ bond_ethdev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	dev_info->max_tx_queues = (uint16_t)512;
 
 	dev_info->min_rx_bufsize = 0;
-	dev_info->pci_dev = NULL;
 
 	dev_info->rx_offload_capa = internals->rx_offload_capa;
 	dev_info->tx_offload_capa = internals->tx_offload_capa;
diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
index f09caf1..0b6715e 100644
--- a/drivers/net/null/rte_eth_null.c
+++ b/drivers/net/null/rte_eth_null.c
@@ -301,7 +301,6 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = RTE_DIM(internals->rx_null_queues);
 	dev_info->max_tx_queues = RTE_DIM(internals->tx_null_queues);
 	dev_info->min_rx_bufsize = 0;
-	dev_info->pci_dev = NULL;
 	dev_info->reta_size = internals->reta_size;
 	dev_info->flow_type_rss_offloads = internals->flow_type_rss_offloads;
 }
diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index 0162f44..7253b9a 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -559,7 +559,6 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = dev->data->nb_rx_queues;
 	dev_info->max_tx_queues = dev->data->nb_tx_queues;
 	dev_info->min_rx_bufsize = 0;
-	dev_info->pci_dev = NULL;
 }
 
 static void
diff --git a/drivers/net/ring/rte_eth_ring.c b/drivers/net/ring/rte_eth_ring.c
index c7726f4..975956a 100644
--- a/drivers/net/ring/rte_eth_ring.c
+++ b/drivers/net/ring/rte_eth_ring.c
@@ -179,7 +179,6 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = (uint16_t)internals->max_rx_queues;
 	dev_info->max_tx_queues = (uint16_t)internals->max_tx_queues;
 	dev_info->min_rx_bufsize = 0;
-	dev_info->pci_dev = NULL;
 }
 
 static void
diff --git a/drivers/net/xenvirt/rte_eth_xenvirt.c b/drivers/net/xenvirt/rte_eth_xenvirt.c
index c08a056..609824b 100644
--- a/drivers/net/xenvirt/rte_eth_xenvirt.c
+++ b/drivers/net/xenvirt/rte_eth_xenvirt.c
@@ -337,7 +337,6 @@ eth_dev_info(struct rte_eth_dev *dev,
 	dev_info->max_rx_queues = (uint16_t)1;
 	dev_info->max_tx_queues = (uint16_t)1;
 	dev_info->min_rx_bufsize = 0;
-	dev_info->pci_dev = NULL;
 }
 
 static void
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 05/20] e1000: localize mapping from eth_dev to pci
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (28 preceding siblings ...)
  2016-12-23 15:57 ` [PATCH v5 04/20] pmd: remove useless reset of dev_info->dev_pci Jan Blunck
@ 2016-12-23 15:57 ` Jan Blunck
  2016-12-23 16:20   ` Thomas Monjalon
  2016-12-23 22:06   ` Stephen Hemminger
  2016-12-23 15:57 ` [PATCH v5 06/20] ixgbe: localize mapping from eth_dev to pci_device Jan Blunck
                   ` (14 subsequent siblings)
  44 siblings, 2 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:57 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, shreyansh.jain, david.marchand

From: Stephen Hemminger <stephen@networkplumber.org>

Create one macro for where PCI device information is extracted
from ethernet device. Makes later changes easier to review, and test.

Acked-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/e1000/e1000_ethdev.h |  2 +
 drivers/net/e1000/em_ethdev.c    | 50 +++++++++++---------
 drivers/net/e1000/igb_ethdev.c   | 99 ++++++++++++++++++++++------------------
 drivers/net/e1000/igb_pf.c       |  4 +-
 4 files changed, 87 insertions(+), 68 deletions(-)

diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h
index 6c25c8d..134f8b9 100644
--- a/drivers/net/e1000/e1000_ethdev.h
+++ b/drivers/net/e1000/e1000_ethdev.h
@@ -286,6 +286,8 @@ struct e1000_adapter {
 #define E1000_DEV_PRIVATE_TO_FILTER_INFO(adapter) \
 	(&((struct e1000_adapter *)adapter)->filter)
 
+#define E1000_DEV_TO_PCI(eth_dev) \
+	(eth_dev->pci_dev)
 /*
  * RX/TX IGB function prototypes
  */
diff --git a/drivers/net/e1000/em_ethdev.c b/drivers/net/e1000/em_ethdev.c
index 866a5cf..7a70bde 100644
--- a/drivers/net/e1000/em_ethdev.c
+++ b/drivers/net/e1000/em_ethdev.c
@@ -83,7 +83,8 @@ static int eth_em_flow_ctrl_set(struct rte_eth_dev *dev,
 static int eth_em_interrupt_setup(struct rte_eth_dev *dev);
 static int eth_em_rxq_interrupt_setup(struct rte_eth_dev *dev);
 static int eth_em_interrupt_get_status(struct rte_eth_dev *dev);
-static int eth_em_interrupt_action(struct rte_eth_dev *dev);
+static int eth_em_interrupt_action(struct rte_eth_dev *dev,
+				   struct rte_intr_handle *handle);
 static void eth_em_interrupt_handler(struct rte_intr_handle *handle,
 							void *param);
 
@@ -287,7 +288,8 @@ eth_em_dev_is_ich8(struct e1000_hw *hw)
 static int
 eth_em_dev_init(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(eth_dev->data->dev_private);
 	struct e1000_hw *hw =
@@ -295,8 +297,6 @@ eth_em_dev_init(struct rte_eth_dev *eth_dev)
 	struct e1000_vfta * shadow_vfta =
 		E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
 
-	pci_dev = eth_dev->pci_dev;
-
 	eth_dev->dev_ops = &eth_em_ops;
 	eth_dev->rx_pkt_burst = (eth_rx_burst_t)&eth_em_recv_pkts;
 	eth_dev->tx_pkt_burst = (eth_tx_burst_t)&eth_em_xmit_pkts;
@@ -351,8 +351,8 @@ eth_em_dev_init(struct rte_eth_dev *eth_dev)
 		     eth_dev->data->port_id, pci_dev->id.vendor_id,
 		     pci_dev->id.device_id);
 
-	rte_intr_callback_register(&(pci_dev->intr_handle),
-		eth_em_interrupt_handler, (void *)eth_dev);
+	rte_intr_callback_register(intr_handle,
+				   eth_em_interrupt_handler, eth_dev);
 
 	return 0;
 }
@@ -360,17 +360,16 @@ eth_em_dev_init(struct rte_eth_dev *eth_dev)
 static int
 eth_em_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(eth_dev->data->dev_private);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	PMD_INIT_FUNC_TRACE();
 
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return -EPERM;
 
-	pci_dev = eth_dev->pci_dev;
-
 	if (adapter->stopped == 0)
 		eth_em_close(eth_dev);
 
@@ -382,9 +381,9 @@ eth_em_dev_uninit(struct rte_eth_dev *eth_dev)
 	eth_dev->data->mac_addrs = NULL;
 
 	/* disable uio intr before callback unregister */
-	rte_intr_disable(&(pci_dev->intr_handle));
-	rte_intr_callback_unregister(&(pci_dev->intr_handle),
-		eth_em_interrupt_handler, (void *)eth_dev);
+	rte_intr_disable(intr_handle);
+	rte_intr_callback_unregister(intr_handle,
+				     eth_em_interrupt_handler, eth_dev);
 
 	return 0;
 }
@@ -556,7 +555,9 @@ eth_em_start(struct rte_eth_dev *dev)
 		E1000_DEV_PRIVATE(dev->data->dev_private);
 	struct e1000_hw *hw =
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev =
+		E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	int ret, mask;
 	uint32_t intr_vector = 0;
 	uint32_t *speeds;
@@ -738,7 +739,8 @@ eth_em_stop(struct rte_eth_dev *dev)
 {
 	struct rte_eth_link link;
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	em_rxq_intr_disable(hw);
 	em_lsc_intr_disable(hw);
@@ -999,9 +1001,11 @@ static int
 eth_em_rx_queue_intr_enable(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id)
 {
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	em_rxq_intr_enable(hw);
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(intr_handle);
 
 	return 0;
 }
@@ -1536,8 +1540,10 @@ eth_em_interrupt_get_status(struct rte_eth_dev *dev)
  *  - On failure, a negative value.
  */
 static int
-eth_em_interrupt_action(struct rte_eth_dev *dev)
+eth_em_interrupt_action(struct rte_eth_dev *dev,
+			struct rte_intr_handle *intr_handle)
 {
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
 	struct e1000_hw *hw =
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct e1000_interrupt *intr =
@@ -1550,7 +1556,7 @@ eth_em_interrupt_action(struct rte_eth_dev *dev)
 		return -1;
 
 	intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
-	rte_intr_enable(&(dev->pci_dev->intr_handle));
+	rte_intr_enable(intr_handle);
 
 	/* set get_link_status to check register later */
 	hw->mac.get_link_status = 1;
@@ -1571,8 +1577,8 @@ eth_em_interrupt_action(struct rte_eth_dev *dev)
 		PMD_INIT_LOG(INFO, " Port %d: Link Down", dev->data->port_id);
 	}
 	PMD_INIT_LOG(DEBUG, "PCI Address: %04d:%02d:%02d:%d",
-		     dev->pci_dev->addr.domain, dev->pci_dev->addr.bus,
-		     dev->pci_dev->addr.devid, dev->pci_dev->addr.function);
+		     pci_dev->addr.domain, pci_dev->addr.bus,
+		     pci_dev->addr.devid, pci_dev->addr.function);
 
 	tctl = E1000_READ_REG(hw, E1000_TCTL);
 	rctl = E1000_READ_REG(hw, E1000_RCTL);
@@ -1604,13 +1610,13 @@ eth_em_interrupt_action(struct rte_eth_dev *dev)
  *  void
  */
 static void
-eth_em_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
-							void *param)
+eth_em_interrupt_handler(struct rte_intr_handle *handle,
+			 void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
 
 	eth_em_interrupt_get_status(dev);
-	eth_em_interrupt_action(dev);
+	eth_em_interrupt_action(dev, handle);
 	_rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
 }
 
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index 08f2a68..352ef94 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -132,7 +132,8 @@ static int  eth_igb_flow_ctrl_set(struct rte_eth_dev *dev,
 static int eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev);
 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev);
 static int eth_igb_interrupt_get_status(struct rte_eth_dev *dev);
-static int eth_igb_interrupt_action(struct rte_eth_dev *dev);
+static int eth_igb_interrupt_action(struct rte_eth_dev *dev,
+				    struct rte_intr_handle *handle);
 static void eth_igb_interrupt_handler(struct rte_intr_handle *handle,
 							void *param);
 static int  igb_hardware_init(struct e1000_hw *hw);
@@ -668,15 +669,16 @@ igb_pf_reset_hw(struct e1000_hw *hw)
 }
 
 static void
-igb_identify_hardware(struct rte_eth_dev *dev)
+igb_identify_hardware(struct rte_eth_dev *dev, struct rte_pci_device *pci_dev)
 {
 	struct e1000_hw *hw =
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
-	hw->vendor_id = dev->pci_dev->id.vendor_id;
-	hw->device_id = dev->pci_dev->id.device_id;
-	hw->subsystem_vendor_id = dev->pci_dev->id.subsystem_vendor_id;
-	hw->subsystem_device_id = dev->pci_dev->id.subsystem_device_id;
+
+	hw->vendor_id = pci_dev->id.vendor_id;
+	hw->device_id = pci_dev->id.device_id;
+	hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
+	hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
 
 	e1000_set_mac_type(hw);
 
@@ -743,7 +745,7 @@ static int
 eth_igb_dev_init(struct rte_eth_dev *eth_dev)
 {
 	int error = 0;
-	struct rte_pci_device *pci_dev;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
 	struct e1000_hw *hw =
 		E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
 	struct e1000_vfta * shadow_vfta =
@@ -755,8 +757,6 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
 
 	uint32_t ctrl_ext;
 
-	pci_dev = eth_dev->pci_dev;
-
 	eth_dev->dev_ops = &eth_igb_ops;
 	eth_dev->rx_pkt_burst = &eth_igb_recv_pkts;
 	eth_dev->tx_pkt_burst = &eth_igb_xmit_pkts;
@@ -774,7 +774,7 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
 
 	hw->hw_addr= (void *)pci_dev->mem_resource[0].addr;
 
-	igb_identify_hardware(eth_dev);
+	igb_identify_hardware(eth_dev, pci_dev);
 	if (e1000_setup_init_funcs(hw, FALSE) != E1000_SUCCESS) {
 		error = -EIO;
 		goto err_late;
@@ -908,6 +908,7 @@ static int
 eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
 {
 	struct rte_pci_device *pci_dev;
+	struct rte_intr_handle *intr_handle;
 	struct e1000_hw *hw;
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(eth_dev->data->dev_private);
@@ -918,7 +919,8 @@ eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
 		return -EPERM;
 
 	hw = E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
-	pci_dev = eth_dev->pci_dev;
+	pci_dev = E1000_DEV_TO_PCI(eth_dev);
+	intr_handle = &pci_dev->intr_handle;
 
 	if (adapter->stopped == 0)
 		eth_igb_close(eth_dev);
@@ -937,9 +939,9 @@ eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
 	igb_pf_host_uninit(eth_dev);
 
 	/* disable uio intr before callback unregister */
-	rte_intr_disable(&(pci_dev->intr_handle));
-	rte_intr_callback_unregister(&(pci_dev->intr_handle),
-		eth_igb_interrupt_handler, (void *)eth_dev);
+	rte_intr_disable(intr_handle);
+	rte_intr_callback_unregister(intr_handle,
+				     eth_igb_interrupt_handler, eth_dev);
 
 	return 0;
 }
@@ -951,6 +953,7 @@ static int
 eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
 {
 	struct rte_pci_device *pci_dev;
+	struct rte_intr_handle *intr_handle;
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(eth_dev->data->dev_private);
 	struct e1000_hw *hw =
@@ -973,8 +976,7 @@ eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
 		return 0;
 	}
 
-	pci_dev = eth_dev->pci_dev;
-
+	pci_dev = E1000_DEV_TO_PCI(eth_dev);
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
 	hw->device_id = pci_dev->id.device_id;
@@ -1038,9 +1040,9 @@ eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
 		     eth_dev->data->port_id, pci_dev->id.vendor_id,
 		     pci_dev->id.device_id, "igb_mac_82576_vf");
 
-	rte_intr_callback_register(&pci_dev->intr_handle,
-				   eth_igbvf_interrupt_handler,
-				   (void *)eth_dev);
+	intr_handle = &pci_dev->intr_handle;
+	rte_intr_callback_register(intr_handle,
+				   eth_igbvf_interrupt_handler, eth_dev);
 
 	return 0;
 }
@@ -1050,7 +1052,7 @@ eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
 {
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(eth_dev->data->dev_private);
-	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -1217,7 +1219,8 @@ eth_igb_start(struct rte_eth_dev *dev)
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	int ret, mask;
 	uint32_t intr_vector = 0;
 	uint32_t ctrl_ext;
@@ -1425,11 +1428,12 @@ eth_igb_stop(struct rte_eth_dev *dev)
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct e1000_filter_info *filter_info =
 		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
 	struct rte_eth_link link;
 	struct e1000_flex_filter *p_flex;
 	struct e1000_5tuple_filter *p_5tuple, *p_5tuple_next;
 	struct e1000_2tuple_filter *p_2tuple, *p_2tuple_next;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	igb_intr_disable(hw);
 
@@ -1529,7 +1533,8 @@ eth_igb_close(struct rte_eth_dev *dev)
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(dev->data->dev_private);
 	struct rte_eth_link link;
-	struct rte_pci_device *pci_dev;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	eth_igb_stop(dev);
 	adapter->stopped = 1;
@@ -1549,10 +1554,9 @@ eth_igb_close(struct rte_eth_dev *dev)
 
 	igb_dev_free_queues(dev);
 
-	pci_dev = dev->pci_dev;
-	if (pci_dev->intr_handle.intr_vec) {
-		rte_free(pci_dev->intr_handle.intr_vec);
-		pci_dev->intr_handle.intr_vec = NULL;
+	if (intr_handle->intr_vec) {
+		rte_free(intr_handle->intr_vec);
+		intr_handle->intr_vec = NULL;
 	}
 
 	memset(&link, 0, sizeof(link));
@@ -2633,12 +2637,14 @@ eth_igb_interrupt_get_status(struct rte_eth_dev *dev)
  *  - On failure, a negative value.
  */
 static int
-eth_igb_interrupt_action(struct rte_eth_dev *dev)
+eth_igb_interrupt_action(struct rte_eth_dev *dev,
+			 struct rte_intr_handle *intr_handle)
 {
 	struct e1000_hw *hw =
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct e1000_interrupt *intr =
 		E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
 	uint32_t tctl, rctl;
 	struct rte_eth_link link;
 	int ret;
@@ -2649,7 +2655,7 @@ eth_igb_interrupt_action(struct rte_eth_dev *dev)
 	}
 
 	igb_intr_enable(dev);
-	rte_intr_enable(&(dev->pci_dev->intr_handle));
+	rte_intr_enable(intr_handle);
 
 	if (intr->flags & E1000_FLAG_NEED_LINK_UPDATE) {
 		intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
@@ -2677,10 +2683,10 @@ eth_igb_interrupt_action(struct rte_eth_dev *dev)
 		}
 
 		PMD_INIT_LOG(DEBUG, "PCI Address: %04d:%02d:%02d:%d",
-			     dev->pci_dev->addr.domain,
-			     dev->pci_dev->addr.bus,
-			     dev->pci_dev->addr.devid,
-			     dev->pci_dev->addr.function);
+			     pci_dev->addr.domain,
+			     pci_dev->addr.bus,
+			     pci_dev->addr.devid,
+			     pci_dev->addr.function);
 		tctl = E1000_READ_REG(hw, E1000_TCTL);
 		rctl = E1000_READ_REG(hw, E1000_RCTL);
 		if (link.link_status) {
@@ -2713,13 +2719,12 @@ eth_igb_interrupt_action(struct rte_eth_dev *dev)
  *  void
  */
 static void
-eth_igb_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
-							void *param)
+eth_igb_interrupt_handler(struct rte_intr_handle *handle, void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
 
 	eth_igb_interrupt_get_status(dev);
-	eth_igb_interrupt_action(dev);
+	eth_igb_interrupt_action(dev, handle);
 }
 
 static int
@@ -2759,7 +2764,7 @@ void igbvf_mbx_process(struct rte_eth_dev *dev)
 }
 
 static int
-eth_igbvf_interrupt_action(struct rte_eth_dev *dev)
+eth_igbvf_interrupt_action(struct rte_eth_dev *dev, struct rte_intr_handle *intr_handle)
 {
 	struct e1000_interrupt *intr =
 		E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
@@ -2770,19 +2775,19 @@ eth_igbvf_interrupt_action(struct rte_eth_dev *dev)
 	}
 
 	igbvf_intr_enable(dev);
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(intr_handle);
 
 	return 0;
 }
 
 static void
-eth_igbvf_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
+eth_igbvf_interrupt_handler(struct rte_intr_handle *handle,
 			    void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
 
 	eth_igbvf_interrupt_get_status(dev);
-	eth_igbvf_interrupt_action(dev);
+	eth_igbvf_interrupt_action(dev, handle);
 }
 
 static int
@@ -3055,8 +3060,9 @@ igbvf_dev_start(struct rte_eth_dev *dev)
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct e1000_adapter *adapter =
 		E1000_DEV_PRIVATE(dev->data->dev_private);
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	int ret;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
 	uint32_t intr_vector = 0;
 
 	PMD_INIT_FUNC_TRACE();
@@ -3110,7 +3116,8 @@ igbvf_dev_start(struct rte_eth_dev *dev)
 static void
 igbvf_dev_stop(struct rte_eth_dev *dev)
 {
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -5095,6 +5102,8 @@ eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
 	struct e1000_hw *hw =
 		E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t mask = 1 << queue_id;
 	uint32_t regval;
 
@@ -5102,7 +5111,7 @@ eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 	E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
 	E1000_WRITE_FLUSH(hw);
 
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(intr_handle);
 
 	return 0;
 }
@@ -5166,8 +5175,8 @@ eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
 	uint32_t vec = E1000_MISC_VEC_ID;
 	uint32_t base = E1000_MISC_VEC_ID;
 	uint32_t misc_shift = 0;
-
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	/* won't configure msix register if no mapping is done
 	 * between intr vector and event fd
diff --git a/drivers/net/e1000/igb_pf.c b/drivers/net/e1000/igb_pf.c
index 5845bc2..67da3c2 100644
--- a/drivers/net/e1000/igb_pf.c
+++ b/drivers/net/e1000/igb_pf.c
@@ -57,7 +57,9 @@
 static inline uint16_t
 dev_num_vf(struct rte_eth_dev *eth_dev)
 {
-	return eth_dev->pci_dev->max_vfs;
+	struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
+
+	return pci_dev->max_vfs;
 }
 
 static inline
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 06/20] ixgbe: localize mapping from eth_dev to pci_device
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (29 preceding siblings ...)
  2016-12-23 15:57 ` [PATCH v5 05/20] e1000: localize mapping from eth_dev to pci Jan Blunck
@ 2016-12-23 15:57 ` Jan Blunck
  2016-12-23 15:57 ` [PATCH v5 07/20] i40e: localize mapping of eth_dev to pci Jan Blunck
                   ` (13 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:57 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, shreyansh.jain, david.marchand, Stephen Hemminger

From: Stephen Hemminger <stephen@networkplumber.org>

Since later changes will change where PCI information is,
localize mapping in one macro.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
Acked-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/ixgbe/ixgbe_ethdev.c | 120 ++++++++++++++++++++++-----------------
 drivers/net/ixgbe/ixgbe_ethdev.h |   3 +
 drivers/net/ixgbe/ixgbe_pf.c     |   4 +-
 3 files changed, 74 insertions(+), 53 deletions(-)

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index baffc71..b6c8b98 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -233,7 +233,8 @@ static void ixgbe_dev_link_status_print(struct rte_eth_dev *dev);
 static int ixgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev);
 static int ixgbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev);
 static int ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev);
-static int ixgbe_dev_interrupt_action(struct rte_eth_dev *dev);
+static int ixgbe_dev_interrupt_action(struct rte_eth_dev *dev,
+				      struct rte_intr_handle *handle);
 static void ixgbe_dev_interrupt_handler(struct rte_intr_handle *handle,
 		void *param);
 static void ixgbe_dev_interrupt_delayed_handler(void *param);
@@ -1083,7 +1084,8 @@ ixgbe_swfw_lock_reset(struct ixgbe_hw *hw)
 static int
 eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
 	struct ixgbe_vfta *shadow_vfta =
@@ -1127,7 +1129,6 @@ eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev)
 
 		return 0;
 	}
-	pci_dev = eth_dev->pci_dev;
 
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
@@ -1272,12 +1273,11 @@ eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev)
 		     eth_dev->data->port_id, pci_dev->id.vendor_id,
 		     pci_dev->id.device_id);
 
-	rte_intr_callback_register(&pci_dev->intr_handle,
-				   ixgbe_dev_interrupt_handler,
-				   (void *)eth_dev);
+	rte_intr_callback_register(intr_handle,
+				   ixgbe_dev_interrupt_handler, eth_dev);
 
 	/* enable uio/vfio intr/eventfd mapping */
-	rte_intr_enable(&pci_dev->intr_handle);
+	rte_intr_enable(intr_handle);
 
 	/* enable support intr */
 	ixgbe_enable_intr(eth_dev);
@@ -1293,7 +1293,8 @@ eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev)
 static int
 eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw;
 
 	PMD_INIT_FUNC_TRACE();
@@ -1302,7 +1303,6 @@ eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev)
 		return -EPERM;
 
 	hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
-	pci_dev = eth_dev->pci_dev;
 
 	if (hw->adapter_stopped == 0)
 		ixgbe_dev_close(eth_dev);
@@ -1315,9 +1315,9 @@ eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev)
 	ixgbe_swfw_lock_reset(hw);
 
 	/* disable uio intr before callback unregister */
-	rte_intr_disable(&(pci_dev->intr_handle));
-	rte_intr_callback_unregister(&(pci_dev->intr_handle),
-		ixgbe_dev_interrupt_handler, (void *)eth_dev);
+	rte_intr_disable(intr_handle);
+	rte_intr_callback_unregister(intr_handle, 
+				     ixgbe_dev_interrupt_handler, eth_dev);
 
 	/* uninitialize PF if max_vfs not zero */
 	ixgbe_pf_host_uninit(eth_dev);
@@ -1381,7 +1381,8 @@ eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
 {
 	int diag;
 	uint32_t tc, tcs;
-	struct rte_pci_device *pci_dev;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
 	struct ixgbe_vfta *shadow_vfta =
@@ -1419,8 +1420,6 @@ eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
 		return 0;
 	}
 
-	pci_dev = eth_dev->pci_dev;
-
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
 	hw->device_id = pci_dev->id.device_id;
@@ -1513,10 +1512,9 @@ eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
 		return -EIO;
 	}
 
-	rte_intr_callback_register(&pci_dev->intr_handle,
-				   ixgbevf_dev_interrupt_handler,
-				   (void *)eth_dev);
-	rte_intr_enable(&pci_dev->intr_handle);
+	rte_intr_callback_register(intr_handle,
+				   ixgbevf_dev_interrupt_handler, eth_dev);
+	rte_intr_enable(intr_handle);
 	ixgbevf_intr_enable(hw);
 
 	PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x mac.type=%s",
@@ -1531,8 +1529,9 @@ eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
 static int
 eth_ixgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw;
-	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -1554,10 +1553,9 @@ eth_ixgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
 	rte_free(eth_dev->data->mac_addrs);
 	eth_dev->data->mac_addrs = NULL;
 
-	rte_intr_disable(&pci_dev->intr_handle);
-	rte_intr_callback_unregister(&pci_dev->intr_handle,
-				     ixgbevf_dev_interrupt_handler,
-				     (void *)eth_dev);
+	rte_intr_disable(intr_handle);
+	rte_intr_callback_unregister(intr_handle,
+				     ixgbevf_dev_interrupt_handler, eth_dev);
 
 	return 0;
 }
@@ -1947,6 +1945,8 @@ ixgbe_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
 static int
 ixgbe_check_vf_rss_rxq_num(struct rte_eth_dev *dev, uint16_t nb_rx_q)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+
 	switch (nb_rx_q) {
 	case 1:
 	case 2:
@@ -1960,7 +1960,7 @@ ixgbe_check_vf_rss_rxq_num(struct rte_eth_dev *dev, uint16_t nb_rx_q)
 	}
 
 	RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
-	RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx = dev->pci_dev->max_vfs * nb_rx_q;
+	RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx = pci_dev->max_vfs * nb_rx_q;
 
 	return 0;
 }
@@ -2191,7 +2191,8 @@ ixgbe_dev_start(struct rte_eth_dev *dev)
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct ixgbe_vf_info *vfinfo =
 		*IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t intr_vector = 0;
 	int err, link_up = 0, negotiate = 0;
 	uint32_t speed = 0;
@@ -2291,7 +2292,7 @@ ixgbe_dev_start(struct rte_eth_dev *dev)
 
 	/* Restore vf rate limit */
 	if (vfinfo != NULL) {
-		for (vf = 0; vf < dev->pci_dev->max_vfs; vf++)
+		for (vf = 0; vf < pci_dev->max_vfs; vf++)
 			for (idx = 0; idx < IXGBE_MAX_QUEUE_NUM_PER_VF; idx++)
 				if (vfinfo[vf].tx_rate[idx] != 0)
 					ixgbe_set_vf_rate_limit(dev, vf,
@@ -2368,8 +2369,7 @@ ixgbe_dev_start(struct rte_eth_dev *dev)
 			ixgbe_dev_lsc_interrupt_setup(dev);
 	} else {
 		rte_intr_callback_unregister(intr_handle,
-					     ixgbe_dev_interrupt_handler,
-					     (void *)dev);
+					     ixgbe_dev_interrupt_handler, dev);
 		if (dev->data->dev_conf.intr_conf.lsc != 0)
 			PMD_INIT_LOG(INFO, "lsc won't enable because of"
 				     " no intr multiplex\n");
@@ -2408,7 +2408,8 @@ ixgbe_dev_stop(struct rte_eth_dev *dev)
 	struct ixgbe_filter_info *filter_info =
 		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
 	struct ixgbe_5tuple_filter *p_5tuple, *p_5tuple_next;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	int vf;
 
 	PMD_INIT_FUNC_TRACE();
@@ -2423,8 +2424,7 @@ ixgbe_dev_stop(struct rte_eth_dev *dev)
 	/* stop adapter */
 	ixgbe_stop_adapter(hw);
 
-	for (vf = 0; vfinfo != NULL &&
-		     vf < dev->pci_dev->max_vfs; vf++)
+	for (vf = 0; vfinfo != NULL && vf < pci_dev->max_vfs; vf++)
 		vfinfo[vf].clear_to_send = false;
 
 	if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
@@ -3031,6 +3031,7 @@ ixgbevf_dev_stats_reset(struct rte_eth_dev *dev)
 static void
 ixgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
 
@@ -3049,7 +3050,7 @@ ixgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	dev_info->max_rx_pktlen = 15872; /* includes CRC, cf MAXFRS register */
 	dev_info->max_mac_addrs = hw->mac.num_rar_entries;
 	dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
-	dev_info->max_vfs = dev->pci_dev->max_vfs;
+	dev_info->max_vfs = pci_dev->max_vfs;
 	if (hw->mac.type == ixgbe_mac_82598EB)
 		dev_info->max_vmdq_pools = ETH_16_POOLS;
 	else
@@ -3163,6 +3164,7 @@ static void
 ixgbevf_dev_info_get(struct rte_eth_dev *dev,
 		     struct rte_eth_dev_info *dev_info)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
 	dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
@@ -3171,7 +3173,7 @@ ixgbevf_dev_info_get(struct rte_eth_dev *dev,
 	dev_info->max_rx_pktlen = 15872; /* includes CRC, cf MAXFRS reg */
 	dev_info->max_mac_addrs = hw->mac.num_rar_entries;
 	dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
-	dev_info->max_vfs = dev->pci_dev->max_vfs;
+	dev_info->max_vfs = pci_dev->max_vfs;
 	if (hw->mac.type == ixgbe_mac_82598EB)
 		dev_info->max_vmdq_pools = ETH_16_POOLS;
 	else
@@ -3433,6 +3435,7 @@ ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev)
 static void
 ixgbe_dev_link_status_print(struct rte_eth_dev *dev)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
 	struct rte_eth_link link;
 
 	memset(&link, 0, sizeof(link));
@@ -3448,10 +3451,10 @@ ixgbe_dev_link_status_print(struct rte_eth_dev *dev)
 				(int)(dev->data->port_id));
 	}
 	PMD_INIT_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
-				dev->pci_dev->addr.domain,
-				dev->pci_dev->addr.bus,
-				dev->pci_dev->addr.devid,
-				dev->pci_dev->addr.function);
+				pci_dev->addr.domain,
+				pci_dev->addr.bus,
+				pci_dev->addr.devid,
+				pci_dev->addr.function);
 }
 
 /*
@@ -3465,7 +3468,8 @@ ixgbe_dev_link_status_print(struct rte_eth_dev *dev)
  *  - On failure, a negative value.
  */
 static int
-ixgbe_dev_interrupt_action(struct rte_eth_dev *dev)
+ixgbe_dev_interrupt_action(struct rte_eth_dev *dev,
+			   struct rte_intr_handle *intr_handle)
 {
 	struct ixgbe_interrupt *intr =
 		IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
@@ -3515,7 +3519,7 @@ ixgbe_dev_interrupt_action(struct rte_eth_dev *dev)
 	} else {
 		PMD_DRV_LOG(DEBUG, "enable intr immediately");
 		ixgbe_enable_intr(dev);
-		rte_intr_enable(&(dev->pci_dev->intr_handle));
+		rte_intr_enable(intr_handle);
 	}
 
 
@@ -3540,6 +3544,8 @@ static void
 ixgbe_dev_interrupt_delayed_handler(void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_interrupt *intr =
 		IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
 	struct ixgbe_hw *hw =
@@ -3564,7 +3570,7 @@ ixgbe_dev_interrupt_delayed_handler(void *param)
 
 	PMD_DRV_LOG(DEBUG, "enable intr in delayed handler S[%08x]", eicr);
 	ixgbe_enable_intr(dev);
-	rte_intr_enable(&(dev->pci_dev->intr_handle));
+	rte_intr_enable(intr_handle);
 }
 
 /**
@@ -3580,13 +3586,13 @@ ixgbe_dev_interrupt_delayed_handler(void *param)
  *  void
  */
 static void
-ixgbe_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
+ixgbe_dev_interrupt_handler(struct rte_intr_handle *handle,
 			    void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
 
 	ixgbe_dev_interrupt_get_status(dev);
-	ixgbe_dev_interrupt_action(dev);
+	ixgbe_dev_interrupt_action(dev, handle);
 }
 
 static int
@@ -4196,7 +4202,8 @@ ixgbevf_dev_start(struct rte_eth_dev *dev)
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint32_t intr_vector = 0;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	int err, mask = 0;
 
@@ -4259,7 +4266,8 @@ static void
 ixgbevf_dev_stop(struct rte_eth_dev *dev)
 {
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -5061,6 +5069,8 @@ ixgbe_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t rule_id)
 static int
 ixgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t mask;
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -5070,7 +5080,7 @@ ixgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 	RTE_SET_USED(queue_id);
 	IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
 
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(intr_handle);
 
 	return 0;
 }
@@ -5093,6 +5103,8 @@ ixgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 static int
 ixgbe_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t mask;
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -5112,7 +5124,7 @@ ixgbe_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 		mask &= (1 << (queue_id - 32));
 		IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
 	}
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(intr_handle);
 
 	return 0;
 }
@@ -5216,7 +5228,8 @@ ixgbe_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
 static void
 ixgbevf_configure_msix(struct rte_eth_dev *dev)
 {
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint32_t q_idx;
@@ -5249,7 +5262,8 @@ ixgbevf_configure_msix(struct rte_eth_dev *dev)
 static void
 ixgbe_configure_msix(struct rte_eth_dev *dev)
 {
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct ixgbe_hw *hw =
 		IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint32_t queue_id, base = IXGBE_MISC_VEC_ID;
@@ -5367,6 +5381,7 @@ static int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
 static int ixgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
 	uint16_t tx_rate, uint64_t q_msk)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct ixgbe_vf_info *vfinfo =
 		*(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
@@ -5381,7 +5396,7 @@ static int ixgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
 		return -EINVAL;
 
 	if (vfinfo != NULL) {
-		for (vf_idx = 0; vf_idx < dev->pci_dev->max_vfs; vf_idx++) {
+		for (vf_idx = 0; vf_idx < pci_dev->max_vfs; vf_idx++) {
 			if (vf_idx == vf)
 				continue;
 			for (idx = 0; idx < RTE_DIM(vfinfo[vf_idx].tx_rate);
@@ -7194,15 +7209,16 @@ ixgbe_e_tag_insertion_en_dis(struct rte_eth_dev *dev,
 			     struct rte_eth_l2_tunnel_conf *l2_tunnel,
 			     bool en)
 {
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
 	int ret = 0;
 	uint32_t vmtir, vmvir;
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
-	if (l2_tunnel->vf_id >= dev->pci_dev->max_vfs) {
+	if (l2_tunnel->vf_id >= pci_dev->max_vfs) {
 		PMD_DRV_LOG(ERR,
 			    "VF id %u should be less than %u",
 			    l2_tunnel->vf_id,
-			    dev->pci_dev->max_vfs);
+			    pci_dev->max_vfs);
 		return -EINVAL;
 	}
 
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h
index 4ff6338..a0e02aa 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.h
+++ b/drivers/net/ixgbe/ixgbe_ethdev.h
@@ -291,6 +291,9 @@ struct ixgbe_adapter {
 	struct rte_timecounter      tx_tstamp_tc;
 };
 
+#define IXGBE_DEV_TO_PCI(eth_dev) \
+	(eth_dev->pci_dev)
+
 #define IXGBE_DEV_PRIVATE_TO_HW(adapter)\
 	(&((struct ixgbe_adapter *)adapter)->hw)
 
diff --git a/drivers/net/ixgbe/ixgbe_pf.c b/drivers/net/ixgbe/ixgbe_pf.c
index 26395e4..cb10265 100644
--- a/drivers/net/ixgbe/ixgbe_pf.c
+++ b/drivers/net/ixgbe/ixgbe_pf.c
@@ -61,7 +61,9 @@
 static inline uint16_t
 dev_num_vf(struct rte_eth_dev *eth_dev)
 {
-	return eth_dev->pci_dev->max_vfs;
+	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
+
+	return pci_dev->max_vfs;
 }
 
 static inline
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 07/20] i40e: localize mapping of eth_dev to pci
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (30 preceding siblings ...)
  2016-12-23 15:57 ` [PATCH v5 06/20] ixgbe: localize mapping from eth_dev to pci_device Jan Blunck
@ 2016-12-23 15:57 ` Jan Blunck
  2016-12-23 15:57 ` [PATCH v5 08/20] broadcom: localize mapping from " Jan Blunck
                   ` (12 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:57 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, shreyansh.jain, david.marchand, Stephen Hemminger

From: Stephen Hemminger <stephen@networkplumber.org>

Simplify later changes to eth_dev.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
Acked-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/i40e/i40e_ethdev.c    | 77 ++++++++++++++++++++++++---------------
 drivers/net/i40e/i40e_ethdev.h    |  3 ++
 drivers/net/i40e/i40e_ethdev_vf.c | 58 ++++++++++++++++-------------
 3 files changed, 83 insertions(+), 55 deletions(-)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index b0c0fbf..0341e33 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -373,8 +373,8 @@ static void i40e_stat_update_48(struct i40e_hw *hw,
 			       uint64_t *offset,
 			       uint64_t *stat);
 static void i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue);
-static void i40e_dev_interrupt_handler(
-		__rte_unused struct rte_intr_handle *handle, void *param);
+static void i40e_dev_interrupt_handler(struct rte_intr_handle *handle,
+				       void *param);
 static int i40e_res_pool_init(struct i40e_res_pool_info *pool,
 				uint32_t base, uint32_t num);
 static void i40e_res_pool_destroy(struct i40e_res_pool_info *pool);
@@ -908,7 +908,7 @@ is_floating_veb_supported(struct rte_devargs *devargs)
 static void
 config_floating_veb(struct rte_eth_dev *dev)
 {
-	struct rte_pci_device *pci_dev = dev->pci_dev;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
@@ -932,6 +932,7 @@ static int
 eth_i40e_dev_init(struct rte_eth_dev *dev)
 {
 	struct rte_pci_device *pci_dev;
+	struct rte_intr_handle *intr_handle;
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct i40e_vsi *vsi;
@@ -953,7 +954,8 @@ eth_i40e_dev_init(struct rte_eth_dev *dev)
 		i40e_set_tx_function(dev);
 		return 0;
 	}
-	pci_dev = dev->pci_dev;
+	pci_dev = I40E_DEV_TO_PCI(dev);
+	intr_handle = &pci_dev->intr_handle;
 
 	rte_eth_copy_pci_info(dev, pci_dev);
 
@@ -1149,15 +1151,15 @@ eth_i40e_dev_init(struct rte_eth_dev *dev)
 	i40e_pf_host_init(dev);
 
 	/* register callback func to eal lib */
-	rte_intr_callback_register(&(pci_dev->intr_handle),
-		i40e_dev_interrupt_handler, (void *)dev);
+	rte_intr_callback_register(intr_handle,
+				   i40e_dev_interrupt_handler, dev);
 
 	/* configure and enable device interrupt */
 	i40e_pf_config_irq0(hw, TRUE);
 	i40e_pf_enable_irq0(hw);
 
 	/* enable uio intr after callback register */
-	rte_intr_enable(&(pci_dev->intr_handle));
+	rte_intr_enable(intr_handle);
 	/*
 	 * Add an ethertype filter to drop all flow control frames transmitted
 	 * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC
@@ -1205,6 +1207,7 @@ static int
 eth_i40e_dev_uninit(struct rte_eth_dev *dev)
 {
 	struct rte_pci_device *pci_dev;
+	struct rte_intr_handle *intr_handle;
 	struct i40e_hw *hw;
 	struct i40e_filter_control_settings settings;
 	int ret;
@@ -1216,7 +1219,8 @@ eth_i40e_dev_uninit(struct rte_eth_dev *dev)
 		return 0;
 
 	hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	pci_dev = dev->pci_dev;
+	pci_dev = I40E_DEV_TO_PCI(dev);
+	intr_handle = &pci_dev->intr_handle;
 
 	if (hw->adapter_stopped == 0)
 		i40e_dev_close(dev);
@@ -1246,11 +1250,11 @@ eth_i40e_dev_uninit(struct rte_eth_dev *dev)
 	dev->data->mac_addrs = NULL;
 
 	/* disable uio intr before callback unregister */
-	rte_intr_disable(&(pci_dev->intr_handle));
+	rte_intr_disable(intr_handle);
 
 	/* register callback func to eal lib */
-	rte_intr_callback_unregister(&(pci_dev->intr_handle),
-		i40e_dev_interrupt_handler, (void *)dev);
+	rte_intr_callback_unregister(intr_handle,
+				     i40e_dev_interrupt_handler, dev);
 
 	return 0;
 }
@@ -1336,7 +1340,8 @@ void
 i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
 {
 	struct rte_eth_dev *dev = vsi->adapter->eth_dev;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
 	uint16_t msix_vect = vsi->msix_intr;
 	uint16_t i;
@@ -1449,7 +1454,8 @@ void
 i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi)
 {
 	struct rte_eth_dev *dev = vsi->adapter->eth_dev;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
 	uint16_t msix_vect = vsi->msix_intr;
 	uint16_t nb_msix = RTE_MIN(vsi->nb_msix, intr_handle->nb_efd);
@@ -1520,7 +1526,8 @@ static void
 i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
 {
 	struct rte_eth_dev *dev = vsi->adapter->eth_dev;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
 	uint16_t interval = i40e_calc_itr_interval(\
 		RTE_LIBRTE_I40E_ITR_INTERVAL);
@@ -1551,7 +1558,8 @@ static void
 i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
 {
 	struct rte_eth_dev *dev = vsi->adapter->eth_dev;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
 	uint16_t msix_intr, i;
 
@@ -1676,7 +1684,8 @@ i40e_dev_start(struct rte_eth_dev *dev)
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct i40e_vsi *main_vsi = pf->main_vsi;
 	int ret, i;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t intr_vector = 0;
 
 	hw->adapter_stopped = 0;
@@ -1809,7 +1818,8 @@ i40e_dev_stop(struct rte_eth_dev *dev)
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_vsi *main_vsi = pf->main_vsi;
 	struct i40e_mirror_rule *p_mirror;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	int i;
 
 	/* Disable all queues */
@@ -1860,6 +1870,8 @@ i40e_dev_close(struct rte_eth_dev *dev)
 {
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t reg;
 	int i;
 
@@ -1871,7 +1883,7 @@ i40e_dev_close(struct rte_eth_dev *dev)
 
 	/* Disable interrupt */
 	i40e_pf_disable_irq0(hw);
-	rte_intr_disable(&(dev->pci_dev->intr_handle));
+	rte_intr_disable(intr_handle);
 
 	/* shutdown and destroy the HMC */
 	i40e_shutdown_lan_hmc(hw);
@@ -2583,13 +2595,14 @@ i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct i40e_vsi *vsi = pf->main_vsi;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
 
 	dev_info->max_rx_queues = vsi->nb_qps;
 	dev_info->max_tx_queues = vsi->nb_qps;
 	dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
 	dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
 	dev_info->max_mac_addrs = vsi->max_macaddrs;
-	dev_info->max_vfs = dev->pci_dev->max_vfs;
+	dev_info->max_vfs = pci_dev->max_vfs;
 	dev_info->rx_offload_capa =
 		DEV_RX_OFFLOAD_VLAN_STRIP |
 		DEV_RX_OFFLOAD_QINQ_STRIP |
@@ -3491,9 +3504,10 @@ i40e_pf_parameter_init(struct rte_eth_dev *dev)
 {
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_PF_TO_HW(pf);
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
 	uint16_t qp_count = 0, vsi_count = 0;
 
-	if (dev->pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
+	if (pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
 		PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
 		return -EINVAL;
 	}
@@ -3534,10 +3548,10 @@ i40e_pf_parameter_init(struct rte_eth_dev *dev)
 
 	/* VF queue/VSI allocation */
 	pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
-	if (hw->func_caps.sr_iov_1_1 && dev->pci_dev->max_vfs) {
+	if (hw->func_caps.sr_iov_1_1 && pci_dev->max_vfs) {
 		pf->flags |= I40E_FLAG_SRIOV;
 		pf->vf_nb_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
-		pf->vf_num = dev->pci_dev->max_vfs;
+		pf->vf_num = pci_dev->max_vfs;
 		PMD_DRV_LOG(DEBUG, "%u VF VSIs, %u queues per VF VSI, "
 			    "in total %u queues", pf->vf_num, pf->vf_nb_qps,
 			    pf->vf_nb_qps * pf->vf_num);
@@ -5527,7 +5541,7 @@ i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
  *  void
  */
 static void
-i40e_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
+i40e_dev_interrupt_handler(struct rte_intr_handle *intr_handle,
 			   void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
@@ -5574,7 +5588,7 @@ i40e_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
 done:
 	/* Enable interrupt */
 	i40e_pf_enable_irq0(hw);
-	rte_intr_enable(&(dev->pci_dev->intr_handle));
+	rte_intr_enable(intr_handle);
 }
 
 static int
@@ -8125,10 +8139,11 @@ i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
 static void
 i40e_enable_extended_tag(struct rte_eth_dev *dev)
 {
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
 	uint32_t buf = 0;
 	int ret;
 
-	ret = rte_eal_pci_read_config(dev->pci_dev, &buf, sizeof(buf),
+	ret = rte_eal_pci_read_config(pci_dev, &buf, sizeof(buf),
 				      PCI_DEV_CAP_REG);
 	if (ret < 0) {
 		PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
@@ -8141,7 +8156,7 @@ i40e_enable_extended_tag(struct rte_eth_dev *dev)
 	}
 
 	buf = 0;
-	ret = rte_eal_pci_read_config(dev->pci_dev, &buf, sizeof(buf),
+	ret = rte_eal_pci_read_config(pci_dev, &buf, sizeof(buf),
 				      PCI_DEV_CTRL_REG);
 	if (ret < 0) {
 		PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
@@ -8153,7 +8168,7 @@ i40e_enable_extended_tag(struct rte_eth_dev *dev)
 		return;
 	}
 	buf |= PCI_DEV_CTRL_EXT_TAG_MASK;
-	ret = rte_eal_pci_write_config(dev->pci_dev, &buf, sizeof(buf),
+	ret = rte_eal_pci_write_config(pci_dev, &buf, sizeof(buf),
 				       PCI_DEV_CTRL_REG);
 	if (ret < 0) {
 		PMD_DRV_LOG(ERR, "Failed to write PCI offset 0x%x",
@@ -9556,7 +9571,8 @@ i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
 static int
 i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint16_t interval =
 		i40e_calc_itr_interval(RTE_LIBRTE_I40E_ITR_INTERVAL);
@@ -9581,7 +9597,7 @@ i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 				I40E_PFINT_DYN_CTLN_INTERVAL_SHIFT));
 
 	I40E_WRITE_FLUSH(hw);
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(&pci_dev->intr_handle);
 
 	return 0;
 }
@@ -9589,7 +9605,8 @@ i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 static int
 i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint16_t msix_intr;
 
diff --git a/drivers/net/i40e/i40e_ethdev.h b/drivers/net/i40e/i40e_ethdev.h
index 298cef4..da8dd7e 100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -617,6 +617,9 @@ void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
 void i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
 	struct rte_eth_txq_info *qinfo);
 
+#define I40E_DEV_TO_PCI(eth_dev) \
+	(eth_dev->pci_dev)
+
 /* I40E_DEV_PRIVATE_TO */
 #define I40E_DEV_PRIVATE_TO_PF(adapter) \
 	(&((struct i40e_adapter *)adapter)->pf)
diff --git a/drivers/net/i40e/i40e_ethdev_vf.c b/drivers/net/i40e/i40e_ethdev_vf.c
index 7869b9b..29b31b5 100644
--- a/drivers/net/i40e/i40e_ethdev_vf.c
+++ b/drivers/net/i40e/i40e_ethdev_vf.c
@@ -718,7 +718,8 @@ i40evf_config_irq_map(struct rte_eth_dev *dev)
 	uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_irq_map_info) + \
 		sizeof(struct i40e_virtchnl_vector_map)];
 	struct i40e_virtchnl_irq_map_info *map_info;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t vector_id;
 	int i, err;
 
@@ -1401,7 +1402,7 @@ i40evf_handle_aq_msg(struct rte_eth_dev *dev)
  *  void
  */
 static void
-i40evf_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
+i40evf_dev_interrupt_handler(struct rte_intr_handle *intr_handle,
 			     void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
@@ -1431,15 +1432,15 @@ i40evf_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
 
 done:
 	i40evf_enable_irq0(hw);
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(intr_handle);
 }
 
 static int
 i40evf_dev_init(struct rte_eth_dev *eth_dev)
 {
-	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(\
-			eth_dev->data->dev_private);
-	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
+	struct i40e_hw *hw
+		= I40E_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(eth_dev);
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -1458,15 +1459,15 @@ i40evf_dev_init(struct rte_eth_dev *eth_dev)
 		return 0;
 	}
 
-	rte_eth_copy_pci_info(eth_dev, eth_dev->pci_dev);
+	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
-	hw->vendor_id = eth_dev->pci_dev->id.vendor_id;
-	hw->device_id = eth_dev->pci_dev->id.device_id;
-	hw->subsystem_vendor_id = eth_dev->pci_dev->id.subsystem_vendor_id;
-	hw->subsystem_device_id = eth_dev->pci_dev->id.subsystem_device_id;
-	hw->bus.device = eth_dev->pci_dev->addr.devid;
-	hw->bus.func = eth_dev->pci_dev->addr.function;
-	hw->hw_addr = (void *)eth_dev->pci_dev->mem_resource[0].addr;
+	hw->vendor_id = pci_dev->id.vendor_id;
+	hw->device_id = pci_dev->id.device_id;
+	hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
+	hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
+	hw->bus.device = pci_dev->addr.devid;
+	hw->bus.func = pci_dev->addr.function;
+	hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
 	hw->adapter_stopped = 0;
 
 	if(i40evf_init_vf(eth_dev) != 0) {
@@ -1854,7 +1855,8 @@ i40evf_enable_queues_intr(struct rte_eth_dev *dev)
 {
 	struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	if (!rte_intr_allow_others(intr_handle)) {
 		I40E_WRITE_REG(hw,
@@ -1886,7 +1888,8 @@ i40evf_disable_queues_intr(struct rte_eth_dev *dev)
 {
 	struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	if (!rte_intr_allow_others(intr_handle)) {
 		I40E_WRITE_REG(hw, I40E_VFINT_DYN_CTL01,
@@ -1912,7 +1915,8 @@ i40evf_disable_queues_intr(struct rte_eth_dev *dev)
 static int
 i40evf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint16_t interval =
 		i40e_calc_itr_interval(RTE_LIBRTE_I40E_ITR_INTERVAL);
@@ -1938,7 +1942,7 @@ i40evf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 
 	I40EVF_WRITE_FLUSH(hw);
 
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(&pci_dev->intr_handle);
 
 	return 0;
 }
@@ -1946,7 +1950,8 @@ i40evf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 static int
 i40evf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	uint16_t msix_intr;
 
@@ -2026,7 +2031,8 @@ i40evf_dev_start(struct rte_eth_dev *dev)
 {
 	struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint32_t intr_vector = 0;
 
 	PMD_INIT_FUNC_TRACE();
@@ -2091,7 +2097,8 @@ i40evf_dev_start(struct rte_eth_dev *dev)
 static void
 i40evf_dev_stop(struct rte_eth_dev *dev)
 {
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -2286,7 +2293,8 @@ static void
 i40evf_dev_close(struct rte_eth_dev *dev)
 {
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pci_dev = dev->pci_dev;
+	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
 	i40evf_dev_stop(dev);
 	hw->adapter_stopped = 1;
@@ -2294,11 +2302,11 @@ i40evf_dev_close(struct rte_eth_dev *dev)
 	i40evf_reset_vf(hw);
 	i40e_shutdown_adminq(hw);
 	/* disable uio intr before callback unregister */
-	rte_intr_disable(&pci_dev->intr_handle);
+	rte_intr_disable(intr_handle);
 
 	/* unregister callback func from eal lib */
-	rte_intr_callback_unregister(&pci_dev->intr_handle,
-		i40evf_dev_interrupt_handler, (void *)dev);
+	rte_intr_callback_unregister(intr_handle,
+				     i40evf_dev_interrupt_handler, dev);
 	i40evf_disable_irq0(hw);
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 08/20] broadcom: localize mapping from eth_dev to pci
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (31 preceding siblings ...)
  2016-12-23 15:57 ` [PATCH v5 07/20] i40e: localize mapping of eth_dev to pci Jan Blunck
@ 2016-12-23 15:57 ` Jan Blunck
  2016-12-23 15:58 ` [PATCH v5 09/20] virtio: Don't fill dev_info->driver_name Jan Blunck
                   ` (11 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:57 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, shreyansh.jain, david.marchand, Stephen Hemminger

From: Stephen Hemminger <stephen@networkplumber.org>

Use existing information about pci and interrupt handle to minimize
the number of places that assume eth_dev contains pci_device
information.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
Acked-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/bnxt/bnxt_ethdev.c | 22 +++++++++++++---------
 drivers/net/bnxt/bnxt_ring.c   | 16 ++++++----------
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index a24e153..97f5a79 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -743,6 +743,8 @@ static int bnxt_reta_query_op(struct rte_eth_dev *eth_dev,
 {
 	struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
 	struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
+	struct rte_intr_handle *intr_handle
+		= &bp->pdev->intr_handle;
 
 	/* Retrieve from the default VNIC */
 	if (!vnic)
@@ -759,7 +761,7 @@ static int bnxt_reta_query_op(struct rte_eth_dev *eth_dev,
 	/* EW - need to revisit here copying from u64 to u16 */
 	memcpy(reta_conf, vnic->rss_table, reta_size);
 
-	if (rte_intr_allow_others(&eth_dev->pci_dev->intr_handle)) {
+	if (rte_intr_allow_others(intr_handle)) {
 		if (eth_dev->data->dev_conf.intr_conf.lsc != 0)
 			bnxt_dev_lsc_intr_setup(eth_dev);
 	}
@@ -1009,11 +1011,12 @@ static bool bnxt_vf_pciid(uint16_t id)
 
 static int bnxt_init_board(struct rte_eth_dev *eth_dev)
 {
-	int rc;
 	struct bnxt *bp = eth_dev->data->dev_private;
+	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
+	int rc;
 
 	/* enable device (incl. PCI PM wakeup), and bus-mastering */
-	if (!eth_dev->pci_dev->mem_resource[0].addr) {
+	if (!pci_dev->mem_resource[0].addr) {
 		RTE_LOG(ERR, PMD,
 			"Cannot find PCI device base address, aborting\n");
 		rc = -ENODEV;
@@ -1021,9 +1024,9 @@ static int bnxt_init_board(struct rte_eth_dev *eth_dev)
 	}
 
 	bp->eth_dev = eth_dev;
-	bp->pdev = eth_dev->pci_dev;
+	bp->pdev = pci_dev;
 
-	bp->bar0 = (void *)eth_dev->pci_dev->mem_resource[0].addr;
+	bp->bar0 = (void *)pci_dev->mem_resource[0].addr;
 	if (!bp->bar0) {
 		RTE_LOG(ERR, PMD, "Cannot map device registers, aborting\n");
 		rc = -ENOMEM;
@@ -1043,6 +1046,7 @@ static int bnxt_init_board(struct rte_eth_dev *eth_dev)
 static int
 bnxt_dev_init(struct rte_eth_dev *eth_dev)
 {
+	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
 	static int version_printed;
 	struct bnxt *bp;
 	int rc;
@@ -1050,10 +1054,10 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
 	if (version_printed++ == 0)
 		RTE_LOG(INFO, PMD, "%s", bnxt_version);
 
-	rte_eth_copy_pci_info(eth_dev, eth_dev->pci_dev);
+	rte_eth_copy_pci_info(eth_dev, pci_dev);
 	bp = eth_dev->data->dev_private;
 
-	if (bnxt_vf_pciid(eth_dev->pci_dev->id.device_id))
+	if (bnxt_vf_pciid(pci_dev->id.device_id))
 		bp->flags |= BNXT_FLAG_VF;
 
 	rc = bnxt_init_board(eth_dev);
@@ -1121,8 +1125,8 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
 
 	RTE_LOG(INFO, PMD,
 		DRV_MODULE_NAME " found at mem %" PRIx64 ", node addr %pM\n",
-		eth_dev->pci_dev->mem_resource[0].phys_addr,
-		eth_dev->pci_dev->mem_resource[0].addr);
+		pci_dev->mem_resource[0].phys_addr,
+		pci_dev->mem_resource[0].addr);
 
 	bp->dev_stopped = 0;
 
diff --git a/drivers/net/bnxt/bnxt_ring.c b/drivers/net/bnxt/bnxt_ring.c
index 3f81ffc..0fafa13 100644
--- a/drivers/net/bnxt/bnxt_ring.c
+++ b/drivers/net/bnxt/bnxt_ring.c
@@ -209,6 +209,7 @@ int bnxt_alloc_rings(struct bnxt *bp, uint16_t qidx,
  */
 int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 {
+	struct rte_pci_device *pci_dev = bp->pdev;
 	unsigned int i;
 	int rc = 0;
 
@@ -222,8 +223,7 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 					  0, HWRM_NA_SIGNATURE);
 		if (rc)
 			goto err_out;
-		cpr->cp_doorbell =
-		    (char *)bp->eth_dev->pci_dev->mem_resource[2].addr;
+		cpr->cp_doorbell = pci_dev->mem_resource[2].addr;
 		B_CP_DIS_DB(cpr, cpr->cp_raw_cons);
 		bp->grp_info[0].cp_fw_ring_id = cp_ring->fw_ring_id;
 	}
@@ -242,8 +242,7 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 					idx, HWRM_NA_SIGNATURE);
 		if (rc)
 			goto err_out;
-		cpr->cp_doorbell =
-		    (char *)bp->eth_dev->pci_dev->mem_resource[2].addr +
+		cpr->cp_doorbell = (char *)pci_dev->mem_resource[2].addr +
 		    idx * 0x80;
 		bp->grp_info[idx].cp_fw_ring_id = cp_ring->fw_ring_id;
 		B_CP_DIS_DB(cpr, cpr->cp_raw_cons);
@@ -255,8 +254,7 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 		if (rc)
 			goto err_out;
 		rxr->rx_prod = 0;
-		rxr->rx_doorbell =
-		    (char *)bp->eth_dev->pci_dev->mem_resource[2].addr +
+		rxr->rx_doorbell = (char *)pci_dev->mem_resource[2].addr +
 		    idx * 0x80;
 		bp->grp_info[idx].rx_fw_ring_id = ring->fw_ring_id;
 		B_RX_DB(rxr->rx_doorbell, rxr->rx_prod);
@@ -283,8 +281,7 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 		if (rc)
 			goto err_out;
 
-		cpr->cp_doorbell =
-		    (char *)bp->eth_dev->pci_dev->mem_resource[2].addr +
+		cpr->cp_doorbell = (char *)pci_dev->mem_resource[2].addr +
 		    idx * 0x80;
 		bp->grp_info[idx].cp_fw_ring_id = cp_ring->fw_ring_id;
 		B_CP_DIS_DB(cpr, cpr->cp_raw_cons);
@@ -296,8 +293,7 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp)
 		if (rc)
 			goto err_out;
 
-		txr->tx_doorbell =
-		    (char *)bp->eth_dev->pci_dev->mem_resource[2].addr +
+		txr->tx_doorbell = (char *)pci_dev->mem_resource[2].addr +
 		    idx * 0x80;
 	}
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 09/20] virtio: Don't fill dev_info->driver_name
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (32 preceding siblings ...)
  2016-12-23 15:57 ` [PATCH v5 08/20] broadcom: localize mapping from " Jan Blunck
@ 2016-12-23 15:58 ` Jan Blunck
  2016-12-23 15:58 ` [PATCH v5 10/20] virtio: Add vtpci_intr_handle() helper to get rte_intr_handle Jan Blunck
                   ` (10 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:58 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

This is overwritten in rte_eth_dev_info_get().

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Reviewed-by: David Marchand <david.marchand@6wind.com>
---
 drivers/net/virtio/virtio_ethdev.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 1bd60e9..5c8afb5 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1624,10 +1624,6 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	uint64_t tso_mask;
 	struct virtio_hw *hw = dev->data->dev_private;
 
-	if (dev->pci_dev)
-		dev_info->driver_name = dev->driver->pci_drv.driver.name;
-	else
-		dev_info->driver_name = "virtio_user PMD";
 	dev_info->max_rx_queues =
 		RTE_MIN(hw->max_queue_pairs, VIRTIO_MAX_RX_QUEUES);
 	dev_info->max_tx_queues =
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 10/20] virtio: Add vtpci_intr_handle() helper to get rte_intr_handle
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (33 preceding siblings ...)
  2016-12-23 15:58 ` [PATCH v5 09/20] virtio: Don't fill dev_info->driver_name Jan Blunck
@ 2016-12-23 15:58 ` Jan Blunck
  2016-12-23 15:58 ` [PATCH v5 11/20] virtio: Don't depend on struct rte_eth_dev's pci_dev Jan Blunck
                   ` (9 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:58 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

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 | 14 ++++++++------
 drivers/net/virtio/virtio_pci.h    |  6 ++++++
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 5c8afb5..80b661d 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1151,7 +1151,7 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
  * if link state changed.
  */
 static void
-virtio_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
+virtio_interrupt_handler(struct rte_intr_handle *handle,
 			 void *param)
 {
 	struct rte_eth_dev *dev = param;
@@ -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(handle) < 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_ */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 11/20] virtio: Don't depend on struct rte_eth_dev's pci_dev
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (34 preceding siblings ...)
  2016-12-23 15:58 ` [PATCH v5 10/20] virtio: Add vtpci_intr_handle() helper to get rte_intr_handle Jan Blunck
@ 2016-12-23 15:58 ` Jan Blunck
  2016-12-23 15:58 ` [PATCH v5 12/20] bnx2x: localize mapping from eth_dev to pci Jan Blunck
                   ` (8 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:58 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

We don't need to depend on rte_eth_dev->pci_dev to differentiate between
the virtio_user and the virtio_pci case. Instead we can use the private
virtio_hw struct to get that information.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 drivers/net/virtio/virtio_ethdev.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 80b661d..26848e4 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -483,11 +483,11 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 		hw->cvq = cvq;
 	}
 
-	/* For virtio_user case (that is when dev->pci_dev is NULL), we use
+	/* For virtio_user case (that is when hw->dev is NULL), we use
 	 * virtual address. And we need properly set _offset_, please see
 	 * VIRTIO_MBUF_DATA_DMA_ADDR in virtqueue.h for more information.
 	 */
-	if (dev->pci_dev)
+	if (hw->dev)
 		vq->offset = offsetof(struct rte_mbuf, buf_physaddr);
 	else {
 		vq->vq_ring_mem = (uintptr_t)mz->addr;
@@ -1190,7 +1190,7 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 	struct virtio_hw *hw = eth_dev->data->dev_private;
 	struct virtio_net_config *config;
 	struct virtio_net_config local_config;
-	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
+	struct rte_pci_device *pci_dev = hw->dev;
 	int ret;
 
 	/* Reset the device although not necessary at startup */
@@ -1210,7 +1210,8 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 	else
 		eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
 
-	rte_eth_copy_pci_info(eth_dev, pci_dev);
+	if (pci_dev)
+		rte_eth_copy_pci_info(eth_dev, pci_dev);
 
 	rx_func_get(eth_dev);
 
@@ -1294,7 +1295,6 @@ int
 eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 {
 	struct virtio_hw *hw = eth_dev->data->dev_private;
-	struct rte_pci_device *pci_dev;
 	uint32_t dev_flags = RTE_ETH_DEV_DETACHABLE;
 	int ret;
 
@@ -1317,10 +1317,11 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 		return -ENOMEM;
 	}
 
-	pci_dev = eth_dev->pci_dev;
-
-	if (pci_dev) {
-		ret = vtpci_init(pci_dev, hw, &dev_flags);
+	/* For virtio_user case the hw->virtio_user_dev is populated by
+	 * virtio_user_eth_dev_alloc() before eth_virtio_dev_init() is called.
+	 */
+	if (!hw->virtio_user_dev) {
+		ret = vtpci_init(eth_dev->pci_dev, hw, &dev_flags);
 		if (ret)
 			return ret;
 	}
@@ -1343,7 +1344,6 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 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();
@@ -1353,7 +1353,6 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
 
 	virtio_dev_stop(eth_dev);
 	virtio_dev_close(eth_dev);
-	pci_dev = eth_dev->pci_dev;
 
 	eth_dev->dev_ops = NULL;
 	eth_dev->tx_pkt_burst = NULL;
@@ -1367,7 +1366,8 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
 		rte_intr_callback_unregister(vtpci_intr_handle(hw),
 						virtio_interrupt_handler,
 						eth_dev);
-	rte_eal_pci_unmap_device(pci_dev);
+	if (hw->dev)
+		rte_eal_pci_unmap_device(hw->dev);
 
 	PMD_INIT_LOG(DEBUG, "dev_uninit completed");
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 12/20] bnx2x: localize mapping from eth_dev to pci
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (35 preceding siblings ...)
  2016-12-23 15:58 ` [PATCH v5 11/20] virtio: Don't depend on struct rte_eth_dev's pci_dev Jan Blunck
@ 2016-12-23 15:58 ` Jan Blunck
  2016-12-23 15:58 ` [PATCH v5 13/20] fm10k: " Jan Blunck
                   ` (7 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:58 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

Use device private information to minimize the places that assume eth_dev
contains pci_dev.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Harish Patil <harish.patil@qlogic.com>
---
 drivers/net/bnx2x/bnx2x_ethdev.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/bnx2x/bnx2x_ethdev.c b/drivers/net/bnx2x/bnx2x_ethdev.c
index 0f1e4a2..fd95136 100644
--- a/drivers/net/bnx2x/bnx2x_ethdev.c
+++ b/drivers/net/bnx2x/bnx2x_ethdev.c
@@ -119,12 +119,12 @@ bnx2x_interrupt_action(struct rte_eth_dev *dev)
 }
 
 static __rte_unused void
-bnx2x_interrupt_handler(__rte_unused struct rte_intr_handle *handle, void *param)
+bnx2x_interrupt_handler(struct rte_intr_handle *handle, void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
 
 	bnx2x_interrupt_action(dev);
-	rte_intr_enable(&(dev->pci_dev->intr_handle));
+	rte_intr_enable(handle);
 }
 
 /*
@@ -187,10 +187,10 @@ bnx2x_dev_start(struct rte_eth_dev *dev)
 	}
 
 	if (IS_PF(sc)) {
-		rte_intr_callback_register(&(dev->pci_dev->intr_handle),
+		rte_intr_callback_register(&sc->pci_dev->intr_handle,
 				bnx2x_interrupt_handler, (void *)dev);
 
-		if(rte_intr_enable(&(dev->pci_dev->intr_handle)))
+		if (rte_intr_enable(&sc->pci_dev->intr_handle))
 			PMD_DRV_LOG(ERR, "rte_intr_enable failed");
 	}
 
@@ -215,8 +215,8 @@ bnx2x_dev_stop(struct rte_eth_dev *dev)
 	PMD_INIT_FUNC_TRACE();
 
 	if (IS_PF(sc)) {
-		rte_intr_disable(&(dev->pci_dev->intr_handle));
-		rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
+		rte_intr_disable(&sc->pci_dev->intr_handle);
+		rte_intr_callback_unregister(&sc->pci_dev->intr_handle,
 				bnx2x_interrupt_handler, (void *)dev);
 	}
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 13/20] fm10k: localize mapping from eth_dev to pci
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (36 preceding siblings ...)
  2016-12-23 15:58 ` [PATCH v5 12/20] bnx2x: localize mapping from eth_dev to pci Jan Blunck
@ 2016-12-23 15:58 ` Jan Blunck
  2016-12-23 15:58 ` [PATCH v5 14/20] qede: localize mapping of " Jan Blunck
                   ` (6 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:58 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

This simplifies later changes to ethdev.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/fm10k/fm10k_ethdev.c | 77 ++++++++++++++++++++++------------------
 1 file changed, 43 insertions(+), 34 deletions(-)

diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c
index fe74f6d..95ee9d2 100644
--- a/drivers/net/fm10k/fm10k_ethdev.c
+++ b/drivers/net/fm10k/fm10k_ethdev.c
@@ -59,7 +59,7 @@
 #define BIT_MASK_PER_UINT32 ((1 << CHARS_PER_UINT32) - 1)
 
 /* default 1:1 map from queue ID to interrupt vector ID */
-#define Q2V(dev, queue_id) (dev->pci_dev->intr_handle.intr_vec[queue_id])
+#define Q2V(pci_dev, queue_id) ((pci_dev)->intr_handle.intr_vec[queue_id])
 
 /* First 64 Logical ports for PF/VMDQ, second 64 for Flow director */
 #define MAX_LPORT_NUM    128
@@ -711,7 +711,8 @@ fm10k_dev_rx_init(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct fm10k_macvlan_filter_info *macvlan;
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	int i, ret;
 	struct fm10k_rx_queue *rxq;
 	uint64_t base_addr;
@@ -725,13 +726,13 @@ fm10k_dev_rx_init(struct rte_eth_dev *dev)
 	i = 0;
 	if (rte_intr_dp_is_en(intr_handle)) {
 		for (; i < dev->data->nb_rx_queues; i++) {
-			FM10K_WRITE_REG(hw, FM10K_RXINT(i), Q2V(dev, i));
+			FM10K_WRITE_REG(hw, FM10K_RXINT(i), Q2V(pdev, i));
 			if (hw->mac.type == fm10k_mac_pf)
-				FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(dev, i)),
+				FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, i)),
 					FM10K_ITR_AUTOMASK |
 					FM10K_ITR_MASK_CLEAR);
 			else
-				FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(dev, i)),
+				FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, i)),
 					FM10K_ITR_AUTOMASK |
 					FM10K_ITR_MASK_CLEAR);
 		}
@@ -1171,7 +1172,8 @@ static void
 fm10k_dev_stop(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	int i;
 
 	PMD_INIT_FUNC_TRACE();
@@ -1190,10 +1192,10 @@ fm10k_dev_stop(struct rte_eth_dev *dev)
 			FM10K_WRITE_REG(hw, FM10K_RXINT(i),
 				3 << FM10K_RXINT_TIMER_SHIFT);
 			if (hw->mac.type == fm10k_mac_pf)
-				FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(dev, i)),
+				FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, i)),
 					FM10K_ITR_MASK_SET);
 			else
-				FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(dev, i)),
+				FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, i)),
 					FM10K_ITR_MASK_SET);
 		}
 	}
@@ -1387,6 +1389,7 @@ fm10k_dev_infos_get(struct rte_eth_dev *dev,
 	struct rte_eth_dev_info *dev_info)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_pci_device *pdev = dev->pci_dev;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -1396,7 +1399,7 @@ fm10k_dev_infos_get(struct rte_eth_dev *dev,
 	dev_info->max_tx_queues      = hw->mac.max_queues;
 	dev_info->max_mac_addrs      = FM10K_MAX_MACADDR_NUM;
 	dev_info->max_hash_mac_addrs = 0;
-	dev_info->max_vfs            = dev->pci_dev->max_vfs;
+	dev_info->max_vfs            = pdev->max_vfs;
 	dev_info->vmdq_pool_base     = 0;
 	dev_info->vmdq_queue_base    = 0;
 	dev_info->max_vmdq_pools     = ETH_32_POOLS;
@@ -2333,15 +2336,16 @@ static int
 fm10k_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_pci_device *pdev = dev->pci_dev;
 
 	/* Enable ITR */
 	if (hw->mac.type == fm10k_mac_pf)
-		FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(dev, queue_id)),
+		FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, queue_id)),
 			FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR);
 	else
-		FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(dev, queue_id)),
+		FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, queue_id)),
 			FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR);
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(&pdev->intr_handle);
 	return 0;
 }
 
@@ -2349,13 +2353,14 @@ static int
 fm10k_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_pci_device *pdev = dev->pci_dev;
 
 	/* Disable ITR */
 	if (hw->mac.type == fm10k_mac_pf)
-		FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(dev, queue_id)),
+		FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, queue_id)),
 			FM10K_ITR_MASK_SET);
 	else
-		FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(dev, queue_id)),
+		FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, queue_id)),
 			FM10K_ITR_MASK_SET);
 	return 0;
 }
@@ -2364,7 +2369,8 @@ static int
 fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
+	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	uint32_t intr_vector, vec;
 	uint16_t queue_id;
 	int result = 0;
@@ -2380,7 +2386,7 @@ fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
 	intr_vector = dev->data->nb_rx_queues;
 
 	/* disable interrupt first */
-	rte_intr_disable(&dev->pci_dev->intr_handle);
+	rte_intr_disable(intr_handle);
 	if (hw->mac.type == fm10k_mac_pf)
 		fm10k_dev_disable_intr_pf(dev);
 	else
@@ -2415,7 +2421,7 @@ fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
 		fm10k_dev_enable_intr_pf(dev);
 	else
 		fm10k_dev_enable_intr_vf(dev);
-	rte_intr_enable(&dev->pci_dev->intr_handle);
+	rte_intr_enable(intr_handle);
 	hw->mac.ops.update_int_moderator(hw);
 	return result;
 }
@@ -2530,7 +2536,7 @@ fm10k_dev_handle_fault(struct fm10k_hw *hw, uint32_t eicr)
  */
 static void
 fm10k_dev_interrupt_handler_pf(
-			__rte_unused struct rte_intr_handle *handle,
+			struct rte_intr_handle *handle,
 			void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
@@ -2581,7 +2587,7 @@ fm10k_dev_interrupt_handler_pf(
 	FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_AUTOMASK |
 					FM10K_ITR_MASK_CLEAR);
 	/* Re-enable interrupt from host side */
-	rte_intr_enable(&(dev->pci_dev->intr_handle));
+	rte_intr_enable(handle);
 }
 
 /**
@@ -2597,7 +2603,7 @@ fm10k_dev_interrupt_handler_pf(
  */
 static void
 fm10k_dev_interrupt_handler_vf(
-			__rte_unused struct rte_intr_handle *handle,
+			struct rte_intr_handle *handle,
 			void *param)
 {
 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
@@ -2615,7 +2621,7 @@ fm10k_dev_interrupt_handler_vf(
 	FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_AUTOMASK |
 					FM10K_ITR_MASK_CLEAR);
 	/* Re-enable interrupt from host side */
-	rte_intr_enable(&(dev->pci_dev->intr_handle));
+	rte_intr_enable(handle);
 }
 
 /* Mailbox message handler in VF */
@@ -2827,6 +2833,8 @@ static int
 eth_fm10k_dev_init(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	int diag, i;
 	struct fm10k_macvlan_filter_info *macvlan;
 
@@ -2840,18 +2848,18 @@ eth_fm10k_dev_init(struct rte_eth_dev *dev)
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return 0;
 
-	rte_eth_copy_pci_info(dev, dev->pci_dev);
+	rte_eth_copy_pci_info(dev, pdev);
 
 	macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
 	memset(macvlan, 0, sizeof(*macvlan));
 	/* Vendor and Device ID need to be set before init of shared code */
 	memset(hw, 0, sizeof(*hw));
-	hw->device_id = dev->pci_dev->id.device_id;
-	hw->vendor_id = dev->pci_dev->id.vendor_id;
-	hw->subsystem_device_id = dev->pci_dev->id.subsystem_device_id;
-	hw->subsystem_vendor_id = dev->pci_dev->id.subsystem_vendor_id;
+	hw->device_id = pdev->id.device_id;
+	hw->vendor_id = pdev->id.vendor_id;
+	hw->subsystem_device_id = pdev->id.subsystem_device_id;
+	hw->subsystem_vendor_id = pdev->id.subsystem_vendor_id;
 	hw->revision_id = 0;
-	hw->hw_addr = (void *)dev->pci_dev->mem_resource[0].addr;
+	hw->hw_addr = (void *)pdev->mem_resource[0].addr;
 	if (hw->hw_addr == NULL) {
 		PMD_INIT_LOG(ERR, "Bad mem resource."
 			" Try to blacklist unused devices.");
@@ -2921,20 +2929,20 @@ eth_fm10k_dev_init(struct rte_eth_dev *dev)
 	/*PF/VF has different interrupt handling mechanism */
 	if (hw->mac.type == fm10k_mac_pf) {
 		/* register callback func to eal lib */
-		rte_intr_callback_register(&(dev->pci_dev->intr_handle),
+		rte_intr_callback_register(intr_handle,
 			fm10k_dev_interrupt_handler_pf, (void *)dev);
 
 		/* enable MISC interrupt */
 		fm10k_dev_enable_intr_pf(dev);
 	} else { /* VF */
-		rte_intr_callback_register(&(dev->pci_dev->intr_handle),
+		rte_intr_callback_register(intr_handle,
 			fm10k_dev_interrupt_handler_vf, (void *)dev);
 
 		fm10k_dev_enable_intr_vf(dev);
 	}
 
 	/* Enable intr after callback registered */
-	rte_intr_enable(&(dev->pci_dev->intr_handle));
+	rte_intr_enable(intr_handle);
 
 	hw->mac.ops.update_int_moderator(hw);
 
@@ -3004,7 +3012,8 @@ static int
 eth_fm10k_dev_uninit(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-
+	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	PMD_INIT_FUNC_TRACE();
 
 	/* only uninitialize in the primary process */
@@ -3019,7 +3028,7 @@ eth_fm10k_dev_uninit(struct rte_eth_dev *dev)
 	dev->tx_pkt_burst = NULL;
 
 	/* disable uio/vfio intr */
-	rte_intr_disable(&(dev->pci_dev->intr_handle));
+	rte_intr_disable(intr_handle);
 
 	/*PF/VF has different interrupt handling mechanism */
 	if (hw->mac.type == fm10k_mac_pf) {
@@ -3027,13 +3036,13 @@ eth_fm10k_dev_uninit(struct rte_eth_dev *dev)
 		fm10k_dev_disable_intr_pf(dev);
 
 		/* unregister callback func to eal lib */
-		rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
+		rte_intr_callback_unregister(intr_handle,
 			fm10k_dev_interrupt_handler_pf, (void *)dev);
 	} else {
 		/* disable interrupt */
 		fm10k_dev_disable_intr_vf(dev);
 
-		rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
+		rte_intr_callback_unregister(intr_handle,
 			fm10k_dev_interrupt_handler_vf, (void *)dev);
 	}
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 14/20] qede: localize mapping of eth_dev to pci
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (37 preceding siblings ...)
  2016-12-23 15:58 ` [PATCH v5 13/20] fm10k: " Jan Blunck
@ 2016-12-23 15:58 ` Jan Blunck
  2016-12-23 15:58 ` [PATCH v5 15/20] szedata2: localize handling of pci resources Jan Blunck
                   ` (5 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:58 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

This simplifies later changes to ethdev.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Harish Patil <harish.patil@qlogic.com>
---
 drivers/net/qede/qede_ethdev.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/qede/qede_ethdev.c b/drivers/net/qede/qede_ethdev.c
index 001166a..aefc6f1 100644
--- a/drivers/net/qede/qede_ethdev.c
+++ b/drivers/net/qede/qede_ethdev.c
@@ -175,14 +175,14 @@ static void qede_interrupt_action(struct ecore_hwfn *p_hwfn)
 }
 
 static void
-qede_interrupt_handler(__rte_unused struct rte_intr_handle *handle, void *param)
+qede_interrupt_handler(struct rte_intr_handle *handle, void *param)
 {
 	struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)param;
 	struct qede_dev *qdev = eth_dev->data->dev_private;
 	struct ecore_dev *edev = &qdev->edev;
 
 	qede_interrupt_action(ECORE_LEADING_HWFN(edev));
-	if (rte_intr_enable(&eth_dev->pci_dev->intr_handle))
+	if (rte_intr_enable(handle))
 		DP_ERR(edev, "rte_intr_enable failed\n");
 }
 
@@ -809,6 +809,7 @@ static void qede_poll_sp_sb_cb(void *param)
 
 static void qede_dev_close(struct rte_eth_dev *eth_dev)
 {
+	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
 	struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
 	struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
 	int rc;
@@ -835,9 +836,9 @@ static void qede_dev_close(struct rte_eth_dev *eth_dev)
 
 	qdev->ops->common->remove(edev);
 
-	rte_intr_disable(&eth_dev->pci_dev->intr_handle);
+	rte_intr_disable(&pci_dev->intr_handle);
 
-	rte_intr_callback_unregister(&eth_dev->pci_dev->intr_handle,
+	rte_intr_callback_unregister(&pci_dev->intr_handle,
 				     qede_interrupt_handler, (void *)eth_dev);
 
 	if (edev->num_hwfns > 1)
@@ -1403,7 +1404,8 @@ static int qede_common_dev_init(struct rte_eth_dev *eth_dev, bool is_vf)
 	/* Extract key data structures */
 	adapter = eth_dev->data->dev_private;
 	edev = &adapter->edev;
-	pci_addr = eth_dev->pci_dev->addr;
+	pci_dev = eth_dev->pci_dev;
+	pci_addr = pci_dev->addr;
 
 	PMD_INIT_FUNC_TRACE(edev);
 
@@ -1420,8 +1422,6 @@ static int qede_common_dev_init(struct rte_eth_dev *eth_dev, bool is_vf)
 		return 0;
 	}
 
-	pci_dev = eth_dev->pci_dev;
-
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
 	qed_ops = qed_get_eth_ops();
@@ -1442,10 +1442,10 @@ static int qede_common_dev_init(struct rte_eth_dev *eth_dev, bool is_vf)
 
 	qede_update_pf_params(edev);
 
-	rte_intr_callback_register(&eth_dev->pci_dev->intr_handle,
+	rte_intr_callback_register(&pci_dev->intr_handle,
 				   qede_interrupt_handler, (void *)eth_dev);
 
-	if (rte_intr_enable(&eth_dev->pci_dev->intr_handle)) {
+	if (rte_intr_enable(&pci_dev->intr_handle)) {
 		DP_ERR(edev, "rte_intr_enable() failed\n");
 		return -ENODEV;
 	}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 15/20] szedata2: localize handling of pci resources
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (38 preceding siblings ...)
  2016-12-23 15:58 ` [PATCH v5 14/20] qede: localize mapping of " Jan Blunck
@ 2016-12-23 15:58 ` Jan Blunck
  2016-12-23 18:31   ` Thomas Monjalon
  2016-12-23 15:58 ` [PATCH v5 16/20] nfp: localize rte_pci_device handling Jan Blunck
                   ` (4 subsequent siblings)
  44 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:58 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

This changes the driver to handle the PCI resource directly instead
of repeatedly going through eth_dev.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/szedata2/rte_eth_szedata2.c | 72 ++++++++++++++++++++-------------
 drivers/net/szedata2/rte_eth_szedata2.h | 58 +++++++++++---------------
 2 files changed, 67 insertions(+), 63 deletions(-)

diff --git a/drivers/net/szedata2/rte_eth_szedata2.c b/drivers/net/szedata2/rte_eth_szedata2.c
index 677ba9f..c4f6134 100644
--- a/drivers/net/szedata2/rte_eth_szedata2.c
+++ b/drivers/net/szedata2/rte_eth_szedata2.c
@@ -91,6 +91,7 @@ struct pmd_internals {
 	uint16_t max_rx_queues;
 	uint16_t max_tx_queues;
 	char sze_dev[PATH_MAX];
+	struct rte_mem_resource *pci_rsc;
 };
 
 static struct ether_addr eth_addr = {
@@ -1144,8 +1145,10 @@ eth_link_update(struct rte_eth_dev *dev,
 	struct rte_eth_link link;
 	struct rte_eth_link *link_ptr = &link;
 	struct rte_eth_link *dev_link = &dev->data->dev_link;
+	struct pmd_internals *internals = (struct pmd_internals *)
+		dev->data->dev_private;
 	volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_IBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_ibuf *);
 
 	switch (cgmii_link_speed(ibuf)) {
@@ -1180,11 +1183,13 @@ eth_link_update(struct rte_eth_dev *dev,
 static int
 eth_dev_set_link_up(struct rte_eth_dev *dev)
 {
+	struct pmd_internals *internals = (struct pmd_internals *)
+		dev->data->dev_private;
 	volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_IBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_ibuf *);
 	volatile struct szedata2_cgmii_obuf *obuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_OBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_OBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_obuf *);
 
 	cgmii_ibuf_enable(ibuf);
@@ -1195,11 +1200,13 @@ eth_dev_set_link_up(struct rte_eth_dev *dev)
 static int
 eth_dev_set_link_down(struct rte_eth_dev *dev)
 {
+	struct pmd_internals *internals = (struct pmd_internals *)
+		dev->data->dev_private;
 	volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_IBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_ibuf *);
 	volatile struct szedata2_cgmii_obuf *obuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_OBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_OBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_obuf *);
 
 	cgmii_ibuf_disable(ibuf);
@@ -1281,8 +1288,10 @@ eth_mac_addr_set(struct rte_eth_dev *dev __rte_unused,
 static void
 eth_promiscuous_enable(struct rte_eth_dev *dev)
 {
+	struct pmd_internals *internals = (struct pmd_internals *)
+		dev->data->dev_private;
 	volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_IBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_ibuf *);
 	cgmii_ibuf_mac_mode_write(ibuf, SZEDATA2_MAC_CHMODE_PROMISC);
 }
@@ -1290,8 +1299,10 @@ eth_promiscuous_enable(struct rte_eth_dev *dev)
 static void
 eth_promiscuous_disable(struct rte_eth_dev *dev)
 {
+	struct pmd_internals *internals = (struct pmd_internals *)
+		dev->data->dev_private;
 	volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_IBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_ibuf *);
 	cgmii_ibuf_mac_mode_write(ibuf, SZEDATA2_MAC_CHMODE_ONLY_VALID);
 }
@@ -1299,8 +1310,10 @@ eth_promiscuous_disable(struct rte_eth_dev *dev)
 static void
 eth_allmulticast_enable(struct rte_eth_dev *dev)
 {
+	struct pmd_internals *internals = (struct pmd_internals *)
+		dev->data->dev_private;
 	volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_IBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_ibuf *);
 	cgmii_ibuf_mac_mode_write(ibuf, SZEDATA2_MAC_CHMODE_ALL_MULTICAST);
 }
@@ -1308,8 +1321,10 @@ eth_allmulticast_enable(struct rte_eth_dev *dev)
 static void
 eth_allmulticast_disable(struct rte_eth_dev *dev)
 {
+	struct pmd_internals *internals = (struct pmd_internals *)
+		dev->data->dev_private;
 	volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR(
-			dev, SZEDATA2_CGMII_IBUF_BASE_OFF,
+			internals->pci_rsc, SZEDATA2_CGMII_IBUF_BASE_OFF,
 			volatile struct szedata2_cgmii_ibuf *);
 	cgmii_ibuf_mac_mode_write(ibuf, SZEDATA2_MAC_CHMODE_ONLY_VALID);
 }
@@ -1349,7 +1364,7 @@ static const struct eth_dev_ops ops = {
  *          -1 on error
  */
 static int
-get_szedata2_index(struct rte_eth_dev *dev, uint32_t *index)
+get_szedata2_index(const struct rte_pci_addr *pcislot_addr, uint32_t *index)
 {
 	DIR *dir;
 	struct dirent *entry;
@@ -1357,7 +1372,6 @@ get_szedata2_index(struct rte_eth_dev *dev, uint32_t *index)
 	uint32_t tmp_index;
 	FILE *fd;
 	char pcislot_path[PATH_MAX];
-	struct rte_pci_addr pcislot_addr = dev->pci_dev->addr;
 	uint32_t domain;
 	uint32_t bus;
 	uint32_t devid;
@@ -1392,10 +1406,10 @@ get_szedata2_index(struct rte_eth_dev *dev, uint32_t *index)
 		if (ret != 4)
 			continue;
 
-		if (pcislot_addr.domain == domain &&
-				pcislot_addr.bus == bus &&
-				pcislot_addr.devid == devid &&
-				pcislot_addr.function == function) {
+		if (pcislot_addr->domain == domain &&
+				pcislot_addr->bus == bus &&
+				pcislot_addr->devid == devid &&
+				pcislot_addr->function == function) {
 			*index = tmp_index;
 			closedir(dir);
 			return 0;
@@ -1415,9 +1429,10 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 	struct szedata *szedata_temp;
 	int ret;
 	uint32_t szedata2_index;
-	struct rte_pci_addr *pci_addr = &dev->pci_dev->addr;
+	struct rte_pci_device *pci_dev = dev->pci_dev;
+	struct rte_pci_addr *pci_addr = &pci_dev->addr;
 	struct rte_mem_resource *pci_rsc =
-		&dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER];
+		&pci_dev->mem_resource[PCI_RESOURCE_NUMBER];
 	char rsc_filename[PATH_MAX];
 	void *pci_resource_ptr = NULL;
 	int fd;
@@ -1427,7 +1442,7 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 			pci_addr->function);
 
 	/* Get index of szedata2 device file and create path to device file */
-	ret = get_szedata2_index(dev, &szedata2_index);
+	ret = get_szedata2_index(pci_addr, &szedata2_index);
 	if (ret != 0) {
 		RTE_LOG(ERR, PMD, "Failed to get szedata2 device index!\n");
 		return -ENODEV;
@@ -1471,10 +1486,10 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 	/* Set function callbacks for Ethernet API */
 	dev->dev_ops = &ops;
 
-	rte_eth_copy_pci_info(dev, dev->pci_dev);
+	rte_eth_copy_pci_info(dev, pci_dev);
 
 	/* mmap pci resource0 file to rte_mem_resource structure */
-	if (dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].phys_addr ==
+	if (pci_dev->mem_resource[PCI_RESOURCE_NUMBER].phys_addr ==
 			0) {
 		RTE_LOG(ERR, PMD, "Missing resource%u file\n",
 				PCI_RESOURCE_NUMBER);
@@ -1491,7 +1506,7 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 	}
 
 	pci_resource_ptr = mmap(0,
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len,
+			pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len,
 			PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 	close(fd);
 	if (pci_resource_ptr == NULL) {
@@ -1499,8 +1514,8 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 				rsc_filename, fd);
 		return -EINVAL;
 	}
-	dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr =
-		pci_resource_ptr;
+	pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr = pci_resource_ptr;
+	internals->pci_rsc = pci_rsc;
 
 	RTE_LOG(DEBUG, PMD, "resource%u phys_addr = 0x%llx len = %llu "
 			"virt addr = %llx\n", PCI_RESOURCE_NUMBER,
@@ -1516,8 +1531,8 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 			RTE_CACHE_LINE_SIZE);
 	if (data->mac_addrs == NULL) {
 		RTE_LOG(ERR, PMD, "Could not alloc space for MAC address!\n");
-		munmap(dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr,
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len);
+		munmap(pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr,
+		       pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len);
 		return -EINVAL;
 	}
 
@@ -1537,12 +1552,13 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 static int
 rte_szedata2_eth_dev_uninit(struct rte_eth_dev *dev)
 {
-	struct rte_pci_addr *pci_addr = &dev->pci_dev->addr;
+	struct rte_pci_device *pci_dev = dev->pci_dev;
+	struct rte_pci_addr *pci_addr = &pci_dev->addr;
 
 	rte_free(dev->data->mac_addrs);
 	dev->data->mac_addrs = NULL;
-	munmap(dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr,
-		dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len);
+	munmap(pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr,
+	       pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len);
 
 	RTE_LOG(INFO, PMD, "szedata2 device ("
 			PCI_PRI_FMT ") successfully uninitialized\n",
diff --git a/drivers/net/szedata2/rte_eth_szedata2.h b/drivers/net/szedata2/rte_eth_szedata2.h
index 522cf47..3b90924 100644
--- a/drivers/net/szedata2/rte_eth_szedata2.h
+++ b/drivers/net/szedata2/rte_eth_szedata2.h
@@ -117,94 +117,82 @@ struct szedata {
  * @return Byte from PCI resource at offset "offset".
  */
 static inline uint8_t
-pci_resource_read8(struct rte_eth_dev *dev, uint32_t offset)
+pci_resource_read8(struct rte_mem_resource *rsc, uint32_t offset)
 {
-	return *((uint8_t *)((uint8_t *)
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr +
-			offset));
+	return *((uint8_t *)((uint8_t *)rsc->addr + offset));
 }
 
 /*
  * @return Two bytes from PCI resource starting at offset "offset".
  */
 static inline uint16_t
-pci_resource_read16(struct rte_eth_dev *dev, uint32_t offset)
+pci_resource_read16(struct rte_mem_resource *rsc, uint32_t offset)
 {
-	return rte_le_to_cpu_16(*((uint16_t *)((uint8_t *)
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr +
-			offset)));
+	return rte_le_to_cpu_16(*((uint16_t *)((uint8_t *)rsc->addr +
+					       offset)));
 }
 
 /*
  * @return Four bytes from PCI resource starting at offset "offset".
  */
 static inline uint32_t
-pci_resource_read32(struct rte_eth_dev *dev, uint32_t offset)
+pci_resource_read32(struct rte_mem_resource *rsc, uint32_t offset)
 {
-	return rte_le_to_cpu_32(*((uint32_t *)((uint8_t *)
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr +
-			offset)));
+	return rte_le_to_cpu_32(*((uint32_t *)((uint8_t *)rsc->addr +
+					       offset)));
 }
 
 /*
  * @return Eight bytes from PCI resource starting at offset "offset".
  */
 static inline uint64_t
-pci_resource_read64(struct rte_eth_dev *dev, uint32_t offset)
+pci_resource_read64(struct rte_mem_resource *rsc, uint32_t offset)
 {
-	return rte_le_to_cpu_64(*((uint64_t *)((uint8_t *)
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr +
-			offset)));
+	return rte_le_to_cpu_64(*((uint64_t *)((uint8_t *)rsc->addr +
+					       offset)));
 }
 
 /*
  * Write one byte to PCI resource address space at offset "offset".
  */
 static inline void
-pci_resource_write8(struct rte_eth_dev *dev, uint32_t offset, uint8_t val)
+pci_resource_write8(struct rte_mem_resource *rsc, uint32_t offset, uint8_t val)
 {
-	*((uint8_t *)((uint8_t *)
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr +
-			offset)) = val;
+	*((uint8_t *)((uint8_t *)rsc->addr + offset)) = val;
 }
 
 /*
  * Write two bytes to PCI resource address space at offset "offset".
  */
 static inline void
-pci_resource_write16(struct rte_eth_dev *dev, uint32_t offset, uint16_t val)
+pci_resource_write16(struct rte_mem_resource *rsc, uint32_t offset,
+		     uint16_t val)
 {
-	*((uint16_t *)((uint8_t *)
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr +
-			offset)) = rte_cpu_to_le_16(val);
+	*((uint16_t *)((uint8_t *)rsc->addr + offset)) = rte_cpu_to_le_16(val);
 }
 
 /*
  * Write four bytes to PCI resource address space at offset "offset".
  */
 static inline void
-pci_resource_write32(struct rte_eth_dev *dev, uint32_t offset, uint32_t val)
+pci_resource_write32(struct rte_mem_resource *rsc, uint32_t offset,
+		     uint32_t val)
 {
-	*((uint32_t *)((uint8_t *)
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr +
-			offset)) = rte_cpu_to_le_32(val);
+	*((uint32_t *)((uint8_t *)rsc->addr + offset)) = rte_cpu_to_le_32(val);
 }
 
 /*
  * Write eight bytes to PCI resource address space at offset "offset".
  */
 static inline void
-pci_resource_write64(struct rte_eth_dev *dev, uint32_t offset, uint64_t val)
+pci_resource_write64(struct rte_mem_resource *rsc, uint32_t offset,
+		     uint64_t val)
 {
-	*((uint64_t *)((uint8_t *)
-			dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr +
-			offset)) = rte_cpu_to_le_64(val);
+	*((uint64_t *)((uint8_t *)rsc->addr + offset)) = rte_cpu_to_le_64(val);
 }
 
 #define SZEDATA2_PCI_RESOURCE_PTR(dev, offset, type) \
-	((type)((uint8_t *) \
-	((dev)->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr) \
-	+ (offset)))
+	((type)((uint8_t *)(rsc)->addr) + (offset)))
 
 enum szedata2_link_speed {
 	SZEDATA2_LINK_SPEED_DEFAULT = 0,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 16/20] nfp: localize rte_pci_device handling
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (39 preceding siblings ...)
  2016-12-23 15:58 ` [PATCH v5 15/20] szedata2: localize handling of pci resources Jan Blunck
@ 2016-12-23 15:58 ` Jan Blunck
  2016-12-23 15:58 ` [PATCH v5 17/20] vmxnet3: use eth_dev->data->drv_name instead of pci_drv name Jan Blunck
                   ` (3 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:58 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

This simplifies later changes to ethdev.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/nfp/nfp_net.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index e315dd8..c9b3ef9 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -718,10 +718,12 @@ static void
 nfp_net_close(struct rte_eth_dev *dev)
 {
 	struct nfp_net_hw *hw;
+	struct rte_pci_device *pci_dev;
 
 	PMD_INIT_LOG(DEBUG, "Close\n");
 
 	hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	pci_dev = dev->pci_dev;
 
 	/*
 	 * We assume that the DPDK application is stopping all the
@@ -730,11 +732,11 @@ nfp_net_close(struct rte_eth_dev *dev)
 
 	nfp_net_stop(dev);
 
-	rte_intr_disable(&dev->pci_dev->intr_handle);
+	rte_intr_disable(&pci_dev->intr_handle);
 	nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff);
 
 	/* unregister callback func from eal lib */
-	rte_intr_callback_unregister(&dev->pci_dev->intr_handle,
+	rte_intr_callback_unregister(&pci_dev->intr_handle,
 				     nfp_net_dev_interrupt_handler,
 				     (void *)dev);
 
@@ -1122,6 +1124,7 @@ nfp_net_rx_queue_count(struct rte_eth_dev *dev, uint16_t queue_idx)
 static void
 nfp_net_dev_link_status_print(struct rte_eth_dev *dev)
 {
+	struct rte_pci_device *pci_dev = dev->pci_dev;
 	struct rte_eth_link link;
 
 	memset(&link, 0, sizeof(link));
@@ -1136,8 +1139,8 @@ nfp_net_dev_link_status_print(struct rte_eth_dev *dev)
 			(int)(dev->data->port_id));
 
 	RTE_LOG(INFO, PMD, "PCI Address: %04d:%02d:%02d:%d\n",
-		dev->pci_dev->addr.domain, dev->pci_dev->addr.bus,
-		dev->pci_dev->addr.devid, dev->pci_dev->addr.function);
+		pci_dev->addr.domain, pci_dev->addr.bus,
+		pci_dev->addr.devid, pci_dev->addr.function);
 }
 
 /* Interrupt configuration and handling */
@@ -1152,13 +1155,15 @@ static void
 nfp_net_irq_unmask(struct rte_eth_dev *dev)
 {
 	struct nfp_net_hw *hw;
+	struct rte_pci_device *pci_dev;
 
 	hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	pci_dev = dev->pci_dev;
 
 	if (hw->ctrl & NFP_NET_CFG_CTRL_MSIXAUTO) {
 		/* If MSI-X auto-masking is used, clear the entry */
 		rte_wmb();
-		rte_intr_enable(&dev->pci_dev->intr_handle);
+		rte_intr_enable(&pci_dev->intr_handle);
 	} else {
 		/* Make sure all updates are written before un-masking */
 		rte_wmb();
@@ -2400,7 +2405,6 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
 		     hw->cap & NFP_NET_CFG_CTRL_LSO     ? "TSO "     : "",
 		     hw->cap & NFP_NET_CFG_CTRL_RSS     ? "RSS "     : "");
 
-	pci_dev = eth_dev->pci_dev;
 	hw->ctrl = 0;
 
 	hw->stride_rx = stride;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 17/20] vmxnet3: use eth_dev->data->drv_name instead of pci_drv name
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (40 preceding siblings ...)
  2016-12-23 15:58 ` [PATCH v5 16/20] nfp: localize rte_pci_device handling Jan Blunck
@ 2016-12-23 15:58 ` Jan Blunck
  2016-12-23 15:58 ` [PATCH v5 18/20] ethdev: Decouple interrupt handling from PCI device Jan Blunck
                   ` (2 subsequent siblings)
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:58 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/vmxnet3/vmxnet3_ethdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.c b/drivers/net/vmxnet3/vmxnet3_ethdev.c
index 93c9ac9..9c8b65f 100644
--- a/drivers/net/vmxnet3/vmxnet3_ethdev.c
+++ b/drivers/net/vmxnet3/vmxnet3_ethdev.c
@@ -138,7 +138,7 @@ gpa_zone_reserve(struct rte_eth_dev *dev, uint32_t size,
 	const struct rte_memzone *mz;
 
 	snprintf(z_name, sizeof(z_name), "%s_%d_%s",
-		 dev->driver->pci_drv.driver.name, dev->data->port_id, post_string);
+		 dev->data->drv_name, dev->data->port_id, post_string);
 
 	mz = rte_memzone_lookup(z_name);
 	if (!reuse) {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 18/20] ethdev: Decouple interrupt handling from PCI device
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (41 preceding siblings ...)
  2016-12-23 15:58 ` [PATCH v5 17/20] vmxnet3: use eth_dev->data->drv_name instead of pci_drv name Jan Blunck
@ 2016-12-23 15:58 ` Jan Blunck
  2016-12-23 15:58 ` [PATCH v5 19/20] ethdev: Move dev_info filling of PCI information into drivers Jan Blunck
  2016-12-23 15:58 ` [PATCH v5 20/20] ethdev: Decouple from PCI device Jan Blunck
  44 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:58 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

The struct rte_intr_handle is an abstraction layer for different types of
interrupt mechanisms. It is embedded in the low-level device (e.g. PCI).
On allocation of a struct rte_eth_dev a reference to the intr_handle
should be stored for devices supporting interrupts.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_ether/rte_ethdev.c | 18 ++++++++++++++++--
 lib/librte_ether/rte_ethdev.h |  1 +
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 9f60ff3..b455850 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -262,6 +262,7 @@ rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
 			rte_panic("Cannot allocate memzone for private port data\n");
 	}
 	eth_dev->pci_dev = pci_dev;
+	eth_dev->intr_handle = &pci_dev->intr_handle;
 	eth_dev->driver = eth_drv;
 
 	/* Invoke PMD device initialization function */
@@ -2591,7 +2592,13 @@ rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 
 	dev = &rte_eth_devices[port_id];
-	intr_handle = &dev->pci_dev->intr_handle;
+
+	if (!dev->intr_handle) {
+		RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
+		return -ENOTSUP;
+	}
+
+	intr_handle = dev->intr_handle;
 	if (!intr_handle->intr_vec) {
 		RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
 		return -EPERM;
@@ -2651,7 +2658,12 @@ rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
 		return -EINVAL;
 	}
 
-	intr_handle = &dev->pci_dev->intr_handle;
+	if (!dev->intr_handle) {
+		RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
+		return -ENOTSUP;
+	}
+
+	intr_handle = dev->intr_handle;
 	if (!intr_handle->intr_vec) {
 		RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
 		return -EPERM;
@@ -3253,6 +3265,8 @@ rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_de
 		return;
 	}
 
+	eth_dev->intr_handle = &pci_dev->intr_handle;
+
 	eth_dev->data->dev_flags = 0;
 	if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
 		eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 272fd41..e1eae65 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1625,6 +1625,7 @@ struct rte_eth_dev {
 	const struct eth_driver *driver;/**< Driver for this device */
 	const struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */
 	struct rte_pci_device *pci_dev; /**< PCI info. supplied by probing */
+	struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
 	/** User application callbacks for NIC interrupts */
 	struct rte_eth_dev_cb_list link_intr_cbs;
 	/**
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 19/20] ethdev: Move dev_info filling of PCI information into drivers
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (42 preceding siblings ...)
  2016-12-23 15:58 ` [PATCH v5 18/20] ethdev: Decouple interrupt handling from PCI device Jan Blunck
@ 2016-12-23 15:58 ` Jan Blunck
  2016-12-23 18:45   ` Thomas Monjalon
  2016-12-23 15:58 ` [PATCH v5 20/20] ethdev: Decouple from PCI device Jan Blunck
  44 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:58 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

Only the drivers itself can decide if it could fill PCI information fields
of dev_info.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 drivers/net/bnx2x/bnx2x_ethdev.c        | 1 +
 drivers/net/bnxt/bnxt_ethdev.c          | 2 ++
 drivers/net/cxgbe/cxgbe_ethdev.c        | 2 ++
 drivers/net/e1000/em_ethdev.c           | 1 +
 drivers/net/e1000/igb_ethdev.c          | 2 ++
 drivers/net/ena/ena_ethdev.c            | 2 ++
 drivers/net/enic/enic_ethdev.c          | 1 +
 drivers/net/fm10k/fm10k_ethdev.c        | 1 +
 drivers/net/i40e/i40e_ethdev.c          | 1 +
 drivers/net/i40e/i40e_ethdev_vf.c       | 1 +
 drivers/net/ixgbe/ixgbe_ethdev.c        | 2 ++
 drivers/net/mlx4/mlx4.c                 | 2 ++
 drivers/net/mlx5/mlx5_ethdev.c          | 2 ++
 drivers/net/nfp/nfp_net.c               | 1 +
 drivers/net/qede/qede_ethdev.c          | 1 +
 drivers/net/szedata2/rte_eth_szedata2.c | 1 +
 drivers/net/thunderx/nicvf_ethdev.c     | 2 ++
 drivers/net/virtio/virtio_ethdev.c      | 1 +
 drivers/net/vmxnet3/vmxnet3_ethdev.c    | 4 +++-
 lib/librte_ether/rte_ethdev.c           | 1 -
 20 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/drivers/net/bnx2x/bnx2x_ethdev.c b/drivers/net/bnx2x/bnx2x_ethdev.c
index fd95136..7237bcc 100644
--- a/drivers/net/bnx2x/bnx2x_ethdev.c
+++ b/drivers/net/bnx2x/bnx2x_ethdev.c
@@ -431,6 +431,7 @@ static void
 bnx2x_dev_infos_get(struct rte_eth_dev *dev, __rte_unused struct rte_eth_dev_info *dev_info)
 {
 	struct bnx2x_softc *sc = dev->data->dev_private;
+	dev_info->pci_dev = dev->pci_dev;
 	dev_info->max_rx_queues  = sc->max_rx_queues;
 	dev_info->max_tx_queues  = sc->max_tx_queues;
 	dev_info->min_rx_bufsize = BNX2X_MIN_RX_BUF_SIZE;
diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index 97f5a79..778323b 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -303,6 +303,8 @@ static void bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
 	struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
 	uint16_t max_vnics, i, j, vpool, vrxq;
 
+	dev_info->pci_dev = eth_dev->pci_dev;
+
 	/* MAC Specifics */
 	dev_info->max_mac_addrs = MAX_NUM_MAC_ADDR;
 	dev_info->max_hash_mac_addrs = 0;
diff --git a/drivers/net/cxgbe/cxgbe_ethdev.c b/drivers/net/cxgbe/cxgbe_ethdev.c
index 317598d..70b66b0 100644
--- a/drivers/net/cxgbe/cxgbe_ethdev.c
+++ b/drivers/net/cxgbe/cxgbe_ethdev.c
@@ -147,6 +147,8 @@ static void cxgbe_dev_info_get(struct rte_eth_dev *eth_dev,
 		.nb_align = 1,
 	};
 
+	device_info->pci_dev = eth_dev->pci_dev;
+
 	device_info->min_rx_bufsize = CXGBE_MIN_RX_BUFSIZE;
 	device_info->max_rx_pktlen = CXGBE_MAX_RX_PKTLEN;
 	device_info->max_rx_queues = max_queues;
diff --git a/drivers/net/e1000/em_ethdev.c b/drivers/net/e1000/em_ethdev.c
index 7a70bde..6d071d9 100644
--- a/drivers/net/e1000/em_ethdev.c
+++ b/drivers/net/e1000/em_ethdev.c
@@ -1049,6 +1049,7 @@ eth_em_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
+	dev_info->pci_dev = dev->pci_dev;
 	dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
 	dev_info->max_rx_pktlen = em_get_max_pktlen(hw);
 	dev_info->max_mac_addrs = hw->mac.rar_entry_count;
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index 352ef94..59a8bfd 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -1985,6 +1985,7 @@ eth_igb_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
+	dev_info->pci_dev = dev->pci_dev;
 	dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
 	dev_info->max_rx_pktlen  = 0x3FFF; /* See RLPML register. */
 	dev_info->max_mac_addrs = hw->mac.rar_entry_count;
@@ -2113,6 +2114,7 @@ eth_igbvf_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
+	dev_info->pci_dev = dev->pci_dev;
 	dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
 	dev_info->max_rx_pktlen  = 0x3FFF; /* See RLPML register. */
 	dev_info->max_mac_addrs = hw->mac.rar_entry_count;
diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
index 555fb31..020c02a 100644
--- a/drivers/net/ena/ena_ethdev.c
+++ b/drivers/net/ena/ena_ethdev.c
@@ -1436,6 +1436,8 @@ static void ena_infos_get(struct rte_eth_dev *dev,
 	ena_dev = &adapter->ena_dev;
 	ena_assert_msg(ena_dev != NULL, "Uninitialized device");
 
+	dev_info->pci_dev = dev->pci_dev;
+
 	dev_info->speed_capa =
 			ETH_LINK_SPEED_1G   |
 			ETH_LINK_SPEED_2_5G |
diff --git a/drivers/net/enic/enic_ethdev.c b/drivers/net/enic/enic_ethdev.c
index f997302..ae6f394 100644
--- a/drivers/net/enic/enic_ethdev.c
+++ b/drivers/net/enic/enic_ethdev.c
@@ -459,6 +459,7 @@ static void enicpmd_dev_info_get(struct rte_eth_dev *eth_dev,
 	struct enic *enic = pmd_priv(eth_dev);
 
 	ENICPMD_FUNC_TRACE();
+	device_info->pci_dev = eth_dev->pci_dev;
 	/* Scattered Rx uses two receive queues per rx queue exposed to dpdk */
 	device_info->max_rx_queues = enic->conf_rq_count / 2;
 	device_info->max_tx_queues = enic->conf_wq_count;
diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c
index 95ee9d2..a97a483 100644
--- a/drivers/net/fm10k/fm10k_ethdev.c
+++ b/drivers/net/fm10k/fm10k_ethdev.c
@@ -1393,6 +1393,7 @@ fm10k_dev_infos_get(struct rte_eth_dev *dev,
 
 	PMD_INIT_FUNC_TRACE();
 
+	dev_info->pci_dev            = pdev;
 	dev_info->min_rx_bufsize     = FM10K_MIN_RX_BUF_SIZE;
 	dev_info->max_rx_pktlen      = FM10K_MAX_PKT_SIZE;
 	dev_info->max_rx_queues      = hw->mac.max_queues;
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 0341e33..8f63044 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -2597,6 +2597,7 @@ i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	struct i40e_vsi *vsi = pf->main_vsi;
 	struct rte_pci_device *pci_dev = I40E_DEV_TO_PCI(dev);
 
+	dev_info->pci_dev = pci_dev;
 	dev_info->max_rx_queues = vsi->nb_qps;
 	dev_info->max_tx_queues = vsi->nb_qps;
 	dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
diff --git a/drivers/net/i40e/i40e_ethdev_vf.c b/drivers/net/i40e/i40e_ethdev_vf.c
index 29b31b5..5b8c376 100644
--- a/drivers/net/i40e/i40e_ethdev_vf.c
+++ b/drivers/net/i40e/i40e_ethdev_vf.c
@@ -2225,6 +2225,7 @@ i40evf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 
 	memset(dev_info, 0, sizeof(*dev_info));
+	dev_info->pci_dev = dev->pci_dev;
 	dev_info->max_rx_queues = vf->vsi_res->num_queue_pairs;
 	dev_info->max_tx_queues = vf->vsi_res->num_queue_pairs;
 	dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index b6c8b98..4bd2934 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -3035,6 +3035,7 @@ ixgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
 
+	dev_info->pci_dev = pci_dev;
 	dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
 	dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
 	if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
@@ -3167,6 +3168,7 @@ ixgbevf_dev_info_get(struct rte_eth_dev *dev,
 	struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
 	struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
+	dev_info->pci_dev = pci_dev;
 	dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
 	dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
 	dev_info->min_rx_bufsize = 1024; /* cf BSIZEPACKET in SRRCTL reg */
diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c
index 82b51a7..ebcc9cb 100644
--- a/drivers/net/mlx4/mlx4.c
+++ b/drivers/net/mlx4/mlx4.c
@@ -4421,6 +4421,8 @@ mlx4_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
 	unsigned int max;
 	char ifname[IF_NAMESIZE];
 
+	info->pci_dev = dev->pci_dev;
+
 	if (priv == NULL)
 		return;
 	priv_lock(priv);
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index c0f73e9..da1a3ca 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -562,6 +562,8 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
 	unsigned int max;
 	char ifname[IF_NAMESIZE];
 
+	info->pci_dev = dev->pci_dev;
+
 	priv_lock(priv);
 	/* FIXME: we should ask the device for these values. */
 	info->min_rx_bufsize = 32;
diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index c9b3ef9..590ecb2 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -1008,6 +1008,7 @@ nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 
 	hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
+	dev_info->pci_dev = dev->pci_dev;
 	dev_info->driver_name = dev->driver->pci_drv.driver.name;
 	dev_info->max_rx_queues = (uint16_t)hw->max_rx_queues;
 	dev_info->max_tx_queues = (uint16_t)hw->max_tx_queues;
diff --git a/drivers/net/qede/qede_ethdev.c b/drivers/net/qede/qede_ethdev.c
index aefc6f1..9133fca 100644
--- a/drivers/net/qede/qede_ethdev.c
+++ b/drivers/net/qede/qede_ethdev.c
@@ -651,6 +651,7 @@ qede_dev_info_get(struct rte_eth_dev *eth_dev,
 
 	PMD_INIT_FUNC_TRACE(edev);
 
+	dev_info->pci_dev = eth_dev->pci_dev;
 	dev_info->min_rx_bufsize = (uint32_t)(ETHER_MIN_MTU +
 					      QEDE_ETH_OVERHEAD);
 	dev_info->max_rx_pktlen = (uint32_t)ETH_TX_MAX_NON_LSO_PKT_LEN;
diff --git a/drivers/net/szedata2/rte_eth_szedata2.c b/drivers/net/szedata2/rte_eth_szedata2.c
index c4f6134..a6c2e3b 100644
--- a/drivers/net/szedata2/rte_eth_szedata2.c
+++ b/drivers/net/szedata2/rte_eth_szedata2.c
@@ -1031,6 +1031,7 @@ eth_dev_info(struct rte_eth_dev *dev,
 		struct rte_eth_dev_info *dev_info)
 {
 	struct pmd_internals *internals = dev->data->dev_private;
+	dev_info->pci_dev = dev->pci_dev;
 	dev_info->if_index = 0;
 	dev_info->max_mac_addrs = 1;
 	dev_info->max_rx_pktlen = (uint32_t)-1;
diff --git a/drivers/net/thunderx/nicvf_ethdev.c b/drivers/net/thunderx/nicvf_ethdev.c
index db03fa8..09bbee0 100644
--- a/drivers/net/thunderx/nicvf_ethdev.c
+++ b/drivers/net/thunderx/nicvf_ethdev.c
@@ -1338,6 +1338,8 @@ nicvf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 
 	PMD_INIT_FUNC_TRACE();
 
+	dev_info->pci_dev = pci_dev;
+
 	dev_info->min_rx_bufsize = ETHER_MIN_MTU;
 	dev_info->max_rx_pktlen = NIC_HW_MAX_FRS;
 	dev_info->max_rx_queues =
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 26848e4..6949b39 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1626,6 +1626,7 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	uint64_t tso_mask;
 	struct virtio_hw *hw = dev->data->dev_private;
 
+	dev_info->pci_dev = hw->dev;
 	dev_info->max_rx_queues =
 		RTE_MIN(hw->max_queue_pairs, VIRTIO_MAX_RX_QUEUES);
 	dev_info->max_tx_queues =
diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.c b/drivers/net/vmxnet3/vmxnet3_ethdev.c
index 9c8b65f..5fe1d3f 100644
--- a/drivers/net/vmxnet3/vmxnet3_ethdev.c
+++ b/drivers/net/vmxnet3/vmxnet3_ethdev.c
@@ -706,9 +706,11 @@ vmxnet3_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
 }
 
 static void
-vmxnet3_dev_info_get(__rte_unused struct rte_eth_dev *dev,
+vmxnet3_dev_info_get(struct rte_eth_dev *dev,
 		     struct rte_eth_dev_info *dev_info)
 {
+	dev_info->pci_dev = dev->pci_dev;
+
 	dev_info->max_rx_queues = VMXNET3_MAX_RX_QUEUES;
 	dev_info->max_tx_queues = VMXNET3_MAX_TX_QUEUES;
 	dev_info->min_rx_bufsize = 1518 + RTE_PKTMBUF_HEADROOM;
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index b455850..8e02d2e 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -1604,7 +1604,6 @@ rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
 
 	RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
 	(*dev->dev_ops->dev_infos_get)(dev, dev_info);
-	dev_info->pci_dev = dev->pci_dev;
 	dev_info->driver_name = dev->data->drv_name;
 	dev_info->nb_rx_queues = dev->data->nb_rx_queues;
 	dev_info->nb_tx_queues = dev->data->nb_tx_queues;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* [PATCH v5 20/20] ethdev: Decouple from PCI device
  2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
                   ` (43 preceding siblings ...)
  2016-12-23 15:58 ` [PATCH v5 19/20] ethdev: Move dev_info filling of PCI information into drivers Jan Blunck
@ 2016-12-23 15:58 ` Jan Blunck
  2016-12-23 16:17   ` Thomas Monjalon
  44 siblings, 1 reply; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 15:58 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain, david.marchand, stephen

This makes struct rte_eth_dev independent of struct rte_pci_device by
replacing it with a pointer to the generic struct rte_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 app/test/virtual_pmd.c                  |  4 ++--
 drivers/net/bnx2x/bnx2x_ethdev.c        |  4 ++--
 drivers/net/bnxt/bnxt_ethdev.c          |  6 +++---
 drivers/net/bonding/rte_eth_bond_args.c | 12 ++++++++++--
 drivers/net/cxgbe/cxgbe_ethdev.c        |  4 ++--
 drivers/net/cxgbe/cxgbe_main.c          |  4 ++--
 drivers/net/e1000/e1000_ethdev.h        |  2 +-
 drivers/net/e1000/em_ethdev.c           |  2 +-
 drivers/net/e1000/igb_ethdev.c          |  4 ++--
 drivers/net/ena/ena_ethdev.c            |  4 ++--
 drivers/net/enic/enic_ethdev.c          |  4 ++--
 drivers/net/fm10k/fm10k_ethdev.c        | 22 +++++++++++-----------
 drivers/net/i40e/i40e_ethdev.h          |  2 +-
 drivers/net/i40e/i40e_ethdev_vf.c       |  2 +-
 drivers/net/ixgbe/ixgbe_ethdev.h        |  2 +-
 drivers/net/mlx4/mlx4.c                 |  4 ++--
 drivers/net/mlx5/mlx5.c                 |  2 +-
 drivers/net/mlx5/mlx5_ethdev.c          |  2 +-
 drivers/net/nfp/nfp_net.c               | 10 +++++-----
 drivers/net/qede/qede_ethdev.c          |  6 +++---
 drivers/net/szedata2/rte_eth_szedata2.c |  6 +++---
 drivers/net/thunderx/nicvf_ethdev.c     |  5 +++--
 drivers/net/virtio/virtio_ethdev.c      |  3 ++-
 drivers/net/virtio/virtio_user_ethdev.c |  1 -
 drivers/net/vmxnet3/vmxnet3_ethdev.c    |  4 ++--
 lib/librte_eal/common/include/rte_pci.h |  6 ++++++
 lib/librte_ether/rte_ethdev.c           |  6 +++---
 lib/librte_ether/rte_ethdev.h           |  2 +-
 28 files changed, 75 insertions(+), 60 deletions(-)

diff --git a/app/test/virtual_pmd.c b/app/test/virtual_pmd.c
index 2517208..6e4dcd8 100644
--- a/app/test/virtual_pmd.c
+++ b/app/test/virtual_pmd.c
@@ -622,8 +622,8 @@ virtual_ethdev_create(const char *name, struct ether_addr *mac_addr,
 	dev_private->dev_ops = virtual_ethdev_default_dev_ops;
 	eth_dev->dev_ops = &dev_private->dev_ops;
 
-	eth_dev->pci_dev = pci_dev;
-	eth_dev->pci_dev->device.driver = &eth_drv->pci_drv.driver;
+	pci_dev->device.driver = &eth_drv->pci_drv.driver;
+	eth_dev->device = &pci_dev->device;
 
 	eth_dev->rx_pkt_burst = virtual_ethdev_rx_burst_success;
 	eth_dev->tx_pkt_burst = virtual_ethdev_tx_burst_success;
diff --git a/drivers/net/bnx2x/bnx2x_ethdev.c b/drivers/net/bnx2x/bnx2x_ethdev.c
index 7237bcc..982965a 100644
--- a/drivers/net/bnx2x/bnx2x_ethdev.c
+++ b/drivers/net/bnx2x/bnx2x_ethdev.c
@@ -431,7 +431,7 @@ static void
 bnx2x_dev_infos_get(struct rte_eth_dev *dev, __rte_unused struct rte_eth_dev_info *dev_info)
 {
 	struct bnx2x_softc *sc = dev->data->dev_private;
-	dev_info->pci_dev = dev->pci_dev;
+	dev_info->pci_dev = RTE_DEV_PCI_DEV(dev->device);
 	dev_info->max_rx_queues  = sc->max_rx_queues;
 	dev_info->max_tx_queues  = sc->max_tx_queues;
 	dev_info->min_rx_bufsize = BNX2X_MIN_RX_BUF_SIZE;
@@ -517,7 +517,7 @@ bnx2x_common_dev_init(struct rte_eth_dev *eth_dev, int is_vf)
 	PMD_INIT_FUNC_TRACE();
 
 	eth_dev->dev_ops = is_vf ? &bnx2xvf_eth_dev_ops : &bnx2x_eth_dev_ops;
-	pci_dev = eth_dev->pci_dev;
+	pci_dev = RTE_DEV_PCI_DEV(eth_dev->device);
 
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index 778323b..275c013 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -303,7 +303,7 @@ static void bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
 	struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
 	uint16_t max_vnics, i, j, vpool, vrxq;
 
-	dev_info->pci_dev = eth_dev->pci_dev;
+	dev_info->pci_dev = RTE_DEV_PCI_DEV(eth_dev->device);
 
 	/* MAC Specifics */
 	dev_info->max_mac_addrs = MAX_NUM_MAC_ADDR;
@@ -1014,7 +1014,7 @@ static bool bnxt_vf_pciid(uint16_t id)
 static int bnxt_init_board(struct rte_eth_dev *eth_dev)
 {
 	struct bnxt *bp = eth_dev->data->dev_private;
-	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
+	struct rte_pci_device *pci_dev = RTE_DEV_PCI_DEV(eth_dev->device);
 	int rc;
 
 	/* enable device (incl. PCI PM wakeup), and bus-mastering */
@@ -1048,7 +1048,7 @@ static int bnxt_init_board(struct rte_eth_dev *eth_dev)
 static int
 bnxt_dev_init(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
+	struct rte_pci_device *pci_dev = RTE_DEV_PCI_DEV(eth_dev->device);
 	static int version_printed;
 	struct bnxt *bp;
 	int rc;
diff --git a/drivers/net/bonding/rte_eth_bond_args.c b/drivers/net/bonding/rte_eth_bond_args.c
index 02ecde6..b21b9e5 100644
--- a/drivers/net/bonding/rte_eth_bond_args.c
+++ b/drivers/net/bonding/rte_eth_bond_args.c
@@ -54,15 +54,23 @@ const char *pmd_bond_init_valid_arguments[] = {
 static inline int
 find_port_id_by_pci_addr(const struct rte_pci_addr *pci_addr)
 {
+	struct rte_pci_device *pci_dev;
 	struct rte_pci_addr *eth_pci_addr;
 	unsigned i;
 
 	for (i = 0; i < rte_eth_dev_count(); i++) {
 
-		if (rte_eth_devices[i].pci_dev == NULL)
+		/* Currently populated by rte_eth_copy_pci_info().
+		 *
+		 * TODO: Once the PCI bus has arrived we should have a better
+		 * way to test for being a PCI device or not.
+		 */
+		if (rte_eth_devices[i].data->kdrv == RTE_KDRV_UNKNOWN ||
+		    rte_eth_devices[i].data->kdrv == RTE_KDRV_NONE)
 			continue;
 
-		eth_pci_addr = &(rte_eth_devices[i].pci_dev->addr);
+		pci_dev = RTE_DEV_PCI_DEV(rte_eth_devices[i].device);
+		eth_pci_addr = &pci_dev->addr;
 
 		if (pci_addr->bus == eth_pci_addr->bus &&
 			pci_addr->devid == eth_pci_addr->devid &&
diff --git a/drivers/net/cxgbe/cxgbe_ethdev.c b/drivers/net/cxgbe/cxgbe_ethdev.c
index 70b66b0..2a8836c 100644
--- a/drivers/net/cxgbe/cxgbe_ethdev.c
+++ b/drivers/net/cxgbe/cxgbe_ethdev.c
@@ -147,7 +147,7 @@ static void cxgbe_dev_info_get(struct rte_eth_dev *eth_dev,
 		.nb_align = 1,
 	};
 
-	device_info->pci_dev = eth_dev->pci_dev;
+	device_info->pci_dev = RTE_DEV_PCI_DEV(eth_dev->device);
 
 	device_info->min_rx_bufsize = CXGBE_MIN_RX_BUFSIZE;
 	device_info->max_rx_pktlen = CXGBE_MAX_RX_PKTLEN;
@@ -1007,7 +1007,7 @@ static int eth_cxgbe_dev_init(struct rte_eth_dev *eth_dev)
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return 0;
 
-	pci_dev = eth_dev->pci_dev;
+	pci_dev = RTE_DEV_PCI_DEV(eth_dev->device);
 
 	snprintf(name, sizeof(name), "cxgbeadapter%d", eth_dev->data->port_id);
 	adapter = rte_zmalloc(name, sizeof(*adapter), 0);
diff --git a/drivers/net/cxgbe/cxgbe_main.c b/drivers/net/cxgbe/cxgbe_main.c
index 9e8402b..7ccf434 100644
--- a/drivers/net/cxgbe/cxgbe_main.c
+++ b/drivers/net/cxgbe/cxgbe_main.c
@@ -1163,14 +1163,14 @@ int cxgbe_probe(struct adapter *adapter)
 		pi->eth_dev->data = data;
 
 allocate_mac:
-		pi->eth_dev->pci_dev = adapter->pdev;
+		pi->eth_dev->device = &adapter->pdev->device;
 		pi->eth_dev->data->dev_private = pi;
 		pi->eth_dev->driver = adapter->eth_dev->driver;
 		pi->eth_dev->dev_ops = adapter->eth_dev->dev_ops;
 		pi->eth_dev->tx_pkt_burst = adapter->eth_dev->tx_pkt_burst;
 		pi->eth_dev->rx_pkt_burst = adapter->eth_dev->rx_pkt_burst;
 
-		rte_eth_copy_pci_info(pi->eth_dev, pi->eth_dev->pci_dev);
+		rte_eth_copy_pci_info(pi->eth_dev, adapter->pdev);
 
 		pi->eth_dev->data->mac_addrs = rte_zmalloc(name,
 							   ETHER_ADDR_LEN, 0);
diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h
index 134f8b9..f8b8864 100644
--- a/drivers/net/e1000/e1000_ethdev.h
+++ b/drivers/net/e1000/e1000_ethdev.h
@@ -287,7 +287,7 @@ struct e1000_adapter {
 	(&((struct e1000_adapter *)adapter)->filter)
 
 #define E1000_DEV_TO_PCI(eth_dev) \
-	(eth_dev->pci_dev)
+	RTE_DEV_PCI_DEV((eth_dev)->device)
 /*
  * RX/TX IGB function prototypes
  */
diff --git a/drivers/net/e1000/em_ethdev.c b/drivers/net/e1000/em_ethdev.c
index 6d071d9..a250fd1 100644
--- a/drivers/net/e1000/em_ethdev.c
+++ b/drivers/net/e1000/em_ethdev.c
@@ -1049,7 +1049,7 @@ eth_em_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
-	dev_info->pci_dev = dev->pci_dev;
+	dev_info->pci_dev = RTE_DEV_PCI_DEV(dev->device);
 	dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
 	dev_info->max_rx_pktlen = em_get_max_pktlen(hw);
 	dev_info->max_mac_addrs = hw->mac.rar_entry_count;
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index 59a8bfd..fa6f47a 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -1985,7 +1985,7 @@ eth_igb_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
-	dev_info->pci_dev = dev->pci_dev;
+	dev_info->pci_dev = RTE_DEV_PCI_DEV(dev->device);
 	dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
 	dev_info->max_rx_pktlen  = 0x3FFF; /* See RLPML register. */
 	dev_info->max_mac_addrs = hw->mac.rar_entry_count;
@@ -2114,7 +2114,7 @@ eth_igbvf_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
 	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
-	dev_info->pci_dev = dev->pci_dev;
+	dev_info->pci_dev = RTE_DEV_PCI_DEV(dev->device);
 	dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
 	dev_info->max_rx_pktlen  = 0x3FFF; /* See RLPML register. */
 	dev_info->max_mac_addrs = hw->mac.rar_entry_count;
diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
index 020c02a..a824376 100644
--- a/drivers/net/ena/ena_ethdev.c
+++ b/drivers/net/ena/ena_ethdev.c
@@ -1278,7 +1278,7 @@ static int eth_ena_dev_init(struct rte_eth_dev *eth_dev)
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return 0;
 
-	pci_dev = eth_dev->pci_dev;
+	pci_dev = RTE_DEV_PCI_DEV(eth_dev->device);
 	adapter->pdev = pci_dev;
 
 	PMD_INIT_LOG(INFO, "Initializing %x:%x:%x.%d\n",
@@ -1436,7 +1436,7 @@ static void ena_infos_get(struct rte_eth_dev *dev,
 	ena_dev = &adapter->ena_dev;
 	ena_assert_msg(ena_dev != NULL, "Uninitialized device");
 
-	dev_info->pci_dev = dev->pci_dev;
+	dev_info->pci_dev = RTE_DEV_PCI_DEV(dev->device);
 
 	dev_info->speed_capa =
 			ETH_LINK_SPEED_1G   |
diff --git a/drivers/net/enic/enic_ethdev.c b/drivers/net/enic/enic_ethdev.c
index ae6f394..0255576 100644
--- a/drivers/net/enic/enic_ethdev.c
+++ b/drivers/net/enic/enic_ethdev.c
@@ -459,7 +459,7 @@ static void enicpmd_dev_info_get(struct rte_eth_dev *eth_dev,
 	struct enic *enic = pmd_priv(eth_dev);
 
 	ENICPMD_FUNC_TRACE();
-	device_info->pci_dev = eth_dev->pci_dev;
+	device_info->pci_dev = RTE_DEV_PCI_DEV(eth_dev->device);
 	/* Scattered Rx uses two receive queues per rx queue exposed to dpdk */
 	device_info->max_rx_queues = enic->conf_rq_count / 2;
 	device_info->max_tx_queues = enic->conf_wq_count;
@@ -622,7 +622,7 @@ static int eth_enicpmd_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->rx_pkt_burst = &enic_recv_pkts;
 	eth_dev->tx_pkt_burst = &enic_xmit_pkts;
 
-	pdev = eth_dev->pci_dev;
+	pdev = RTE_DEV_PCI_DEV(eth_dev->device);
 	rte_eth_copy_pci_info(eth_dev, pdev);
 	enic->pdev = pdev;
 	addr = &pdev->addr;
diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c
index a97a483..14a06a0 100644
--- a/drivers/net/fm10k/fm10k_ethdev.c
+++ b/drivers/net/fm10k/fm10k_ethdev.c
@@ -677,7 +677,7 @@ fm10k_dev_tx_init(struct rte_eth_dev *dev)
 		/* Enable use of FTAG bit in TX descriptor, PFVTCTL
 		 * register is read-only for VF.
 		 */
-		if (fm10k_check_ftag(dev->pci_dev->device.devargs)) {
+		if (fm10k_check_ftag(dev->device->devargs)) {
 			if (hw->mac.type == fm10k_mac_pf) {
 				FM10K_WRITE_REG(hw, FM10K_PFVTCTL(i),
 						FM10K_PFVTCTL_FTAG_DESC_ENABLE);
@@ -711,7 +711,7 @@ fm10k_dev_rx_init(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct fm10k_macvlan_filter_info *macvlan;
-	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_pci_device *pdev = RTE_DEV_PCI_DEV(dev->device);
 	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	int i, ret;
 	struct fm10k_rx_queue *rxq;
@@ -1172,7 +1172,7 @@ static void
 fm10k_dev_stop(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_pci_device *pdev = RTE_DEV_PCI_DEV(dev->device);
 	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	int i;
 
@@ -1389,7 +1389,7 @@ fm10k_dev_infos_get(struct rte_eth_dev *dev,
 	struct rte_eth_dev_info *dev_info)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_pci_device *pdev = RTE_DEV_PCI_DEV(dev->device);
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -2337,7 +2337,7 @@ static int
 fm10k_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_pci_device *pdev = RTE_DEV_PCI_DEV(dev->device);
 
 	/* Enable ITR */
 	if (hw->mac.type == fm10k_mac_pf)
@@ -2354,7 +2354,7 @@ static int
 fm10k_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_pci_device *pdev = RTE_DEV_PCI_DEV(dev->device);
 
 	/* Disable ITR */
 	if (hw->mac.type == fm10k_mac_pf)
@@ -2370,7 +2370,7 @@ static int
 fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_pci_device *pdev = RTE_DEV_PCI_DEV(dev->device);
 	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	uint32_t intr_vector, vec;
 	uint16_t queue_id;
@@ -2744,7 +2744,7 @@ fm10k_set_tx_function(struct rte_eth_dev *dev)
 	int use_sse = 1;
 	uint16_t tx_ftag_en = 0;
 
-	if (fm10k_check_ftag(dev->pci_dev->device.devargs))
+	if (fm10k_check_ftag(dev->device->devargs))
 		tx_ftag_en = 1;
 
 	for (i = 0; i < dev->data->nb_tx_queues; i++) {
@@ -2775,7 +2775,7 @@ fm10k_set_rx_function(struct rte_eth_dev *dev)
 	uint16_t i, rx_using_sse;
 	uint16_t rx_ftag_en = 0;
 
-	if (fm10k_check_ftag(dev->pci_dev->device.devargs))
+	if (fm10k_check_ftag(dev->device->devargs))
 		rx_ftag_en = 1;
 
 	/* In order to allow Vector Rx there are a few configuration
@@ -2834,7 +2834,7 @@ static int
 eth_fm10k_dev_init(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_pci_device *pdev = RTE_DEV_PCI_DEV(dev->device);
 	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	int diag, i;
 	struct fm10k_macvlan_filter_info *macvlan;
@@ -3013,7 +3013,7 @@ static int
 eth_fm10k_dev_uninit(struct rte_eth_dev *dev)
 {
 	struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	struct rte_pci_device *pdev = dev->pci_dev;
+	struct rte_pci_device *pdev = RTE_DEV_PCI_DEV(dev->device);
 	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	PMD_INIT_FUNC_TRACE();
 
diff --git a/drivers/net/i40e/i40e_ethdev.h b/drivers/net/i40e/i40e_ethdev.h
index da8dd7e..43e2106 100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -618,7 +618,7 @@ void i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
 	struct rte_eth_txq_info *qinfo);
 
 #define I40E_DEV_TO_PCI(eth_dev) \
-	(eth_dev->pci_dev)
+	RTE_DEV_PCI_DEV((eth_dev)->device)
 
 /* I40E_DEV_PRIVATE_TO */
 #define I40E_DEV_PRIVATE_TO_PF(adapter) \
diff --git a/drivers/net/i40e/i40e_ethdev_vf.c b/drivers/net/i40e/i40e_ethdev_vf.c
index 5b8c376..e6b9575 100644
--- a/drivers/net/i40e/i40e_ethdev_vf.c
+++ b/drivers/net/i40e/i40e_ethdev_vf.c
@@ -2225,7 +2225,7 @@ i40evf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 
 	memset(dev_info, 0, sizeof(*dev_info));
-	dev_info->pci_dev = dev->pci_dev;
+	dev_info->pci_dev = RTE_DEV_PCI_DEV(dev->device);
 	dev_info->max_rx_queues = vf->vsi_res->num_queue_pairs;
 	dev_info->max_tx_queues = vf->vsi_res->num_queue_pairs;
 	dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h
index a0e02aa..581c36d 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.h
+++ b/drivers/net/ixgbe/ixgbe_ethdev.h
@@ -292,7 +292,7 @@ struct ixgbe_adapter {
 };
 
 #define IXGBE_DEV_TO_PCI(eth_dev) \
-	(eth_dev->pci_dev)
+	RTE_DEV_PCI_DEV((eth_dev)->device)
 
 #define IXGBE_DEV_PRIVATE_TO_HW(adapter)\
 	(&((struct ixgbe_adapter *)adapter)->hw)
diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c
index ebcc9cb..c095ec4 100644
--- a/drivers/net/mlx4/mlx4.c
+++ b/drivers/net/mlx4/mlx4.c
@@ -4421,7 +4421,7 @@ mlx4_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
 	unsigned int max;
 	char ifname[IF_NAMESIZE];
 
-	info->pci_dev = dev->pci_dev;
+	info->pci_dev = RTE_DEV_PCI_DEV(dev->device);
 
 	if (priv == NULL)
 		return;
@@ -5838,7 +5838,7 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 			eth_dev->data->dev_private = priv;
 			eth_dev->data->mac_addrs = priv->mac;
 		}
-		eth_dev->pci_dev = pci_dev;
+		eth_dev->device = &pci_dev->device;
 
 		rte_eth_copy_pci_info(eth_dev, pci_dev);
 
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index ca123e4..b97b6d1 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -655,7 +655,7 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 			eth_dev->data->mac_addrs = priv->mac;
 		}
 
-		eth_dev->pci_dev = pci_dev;
+		eth_dev->device = &pci_dev->device;
 		rte_eth_copy_pci_info(eth_dev, pci_dev);
 		eth_dev->driver = &mlx5_driver;
 		priv->dev = eth_dev;
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index da1a3ca..8e0abc5 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -562,7 +562,7 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
 	unsigned int max;
 	char ifname[IF_NAMESIZE];
 
-	info->pci_dev = dev->pci_dev;
+	info->pci_dev = RTE_DEV_PCI_DEV(dev->device);
 
 	priv_lock(priv);
 	/* FIXME: we should ask the device for these values. */
diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 590ecb2..9465f42 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -723,7 +723,7 @@ nfp_net_close(struct rte_eth_dev *dev)
 	PMD_INIT_LOG(DEBUG, "Close\n");
 
 	hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	pci_dev = dev->pci_dev;
+	pci_dev = RTE_DEV_PCI_DEV(dev->device);
 
 	/*
 	 * We assume that the DPDK application is stopping all the
@@ -1008,7 +1008,7 @@ nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 
 	hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
-	dev_info->pci_dev = dev->pci_dev;
+	dev_info->pci_dev = RTE_DEV_PCI_DEV(dev->device);
 	dev_info->driver_name = dev->driver->pci_drv.driver.name;
 	dev_info->max_rx_queues = (uint16_t)hw->max_rx_queues;
 	dev_info->max_tx_queues = (uint16_t)hw->max_tx_queues;
@@ -1125,7 +1125,7 @@ nfp_net_rx_queue_count(struct rte_eth_dev *dev, uint16_t queue_idx)
 static void
 nfp_net_dev_link_status_print(struct rte_eth_dev *dev)
 {
-	struct rte_pci_device *pci_dev = dev->pci_dev;
+	struct rte_pci_device *pci_dev = RTE_DEV_PCI_DEV(dev->device);
 	struct rte_eth_link link;
 
 	memset(&link, 0, sizeof(link));
@@ -1159,7 +1159,7 @@ nfp_net_irq_unmask(struct rte_eth_dev *dev)
 	struct rte_pci_device *pci_dev;
 
 	hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	pci_dev = dev->pci_dev;
+	pci_dev = RTE_DEV_PCI_DEV(dev->device);
 
 	if (hw->ctrl & NFP_NET_CFG_CTRL_MSIXAUTO) {
 		/* If MSI-X auto-masking is used, clear the entry */
@@ -2336,7 +2336,7 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return 0;
 
-	pci_dev = eth_dev->pci_dev;
+	pci_dev = RTE_DEV_PCI_DEV(eth_dev->device);
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
 	hw->device_id = pci_dev->id.device_id;
diff --git a/drivers/net/qede/qede_ethdev.c b/drivers/net/qede/qede_ethdev.c
index 9133fca..6e2ab73 100644
--- a/drivers/net/qede/qede_ethdev.c
+++ b/drivers/net/qede/qede_ethdev.c
@@ -651,7 +651,7 @@ qede_dev_info_get(struct rte_eth_dev *eth_dev,
 
 	PMD_INIT_FUNC_TRACE(edev);
 
-	dev_info->pci_dev = eth_dev->pci_dev;
+	dev_info->pci_dev = RTE_DEV_PCI_DEV(eth_dev->device);
 	dev_info->min_rx_bufsize = (uint32_t)(ETHER_MIN_MTU +
 					      QEDE_ETH_OVERHEAD);
 	dev_info->max_rx_pktlen = (uint32_t)ETH_TX_MAX_NON_LSO_PKT_LEN;
@@ -810,7 +810,7 @@ static void qede_poll_sp_sb_cb(void *param)
 
 static void qede_dev_close(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
+	struct rte_pci_device *pci_dev = RTE_DEV_PCI_DEV(eth_dev->device);
 	struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
 	struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
 	int rc;
@@ -1405,7 +1405,7 @@ static int qede_common_dev_init(struct rte_eth_dev *eth_dev, bool is_vf)
 	/* Extract key data structures */
 	adapter = eth_dev->data->dev_private;
 	edev = &adapter->edev;
-	pci_dev = eth_dev->pci_dev;
+	pci_dev = RTE_DEV_PCI_DEV(eth_dev->device);
 	pci_addr = pci_dev->addr;
 
 	PMD_INIT_FUNC_TRACE(edev);
diff --git a/drivers/net/szedata2/rte_eth_szedata2.c b/drivers/net/szedata2/rte_eth_szedata2.c
index a6c2e3b..7a66b8f 100644
--- a/drivers/net/szedata2/rte_eth_szedata2.c
+++ b/drivers/net/szedata2/rte_eth_szedata2.c
@@ -1031,7 +1031,7 @@ eth_dev_info(struct rte_eth_dev *dev,
 		struct rte_eth_dev_info *dev_info)
 {
 	struct pmd_internals *internals = dev->data->dev_private;
-	dev_info->pci_dev = dev->pci_dev;
+	dev_info->pci_dev = RTE_DEV_PCI_DEV(dev->device);
 	dev_info->if_index = 0;
 	dev_info->max_mac_addrs = 1;
 	dev_info->max_rx_pktlen = (uint32_t)-1;
@@ -1430,7 +1430,7 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 	struct szedata *szedata_temp;
 	int ret;
 	uint32_t szedata2_index;
-	struct rte_pci_device *pci_dev = dev->pci_dev;
+	struct rte_pci_device *pci_dev = RTE_DEV_PCI_DEV(dev->device);
 	struct rte_pci_addr *pci_addr = &pci_dev->addr;
 	struct rte_mem_resource *pci_rsc =
 		&pci_dev->mem_resource[PCI_RESOURCE_NUMBER];
@@ -1553,7 +1553,7 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev)
 static int
 rte_szedata2_eth_dev_uninit(struct rte_eth_dev *dev)
 {
-	struct rte_pci_device *pci_dev = dev->pci_dev;
+	struct rte_pci_device *pci_dev = RTE_DEV_PCI_DEV(dev->device);
 	struct rte_pci_addr *pci_addr = &pci_dev->addr;
 
 	rte_free(dev->data->mac_addrs);
diff --git a/drivers/net/thunderx/nicvf_ethdev.c b/drivers/net/thunderx/nicvf_ethdev.c
index 09bbee0..b894205 100644
--- a/drivers/net/thunderx/nicvf_ethdev.c
+++ b/drivers/net/thunderx/nicvf_ethdev.c
@@ -1335,6 +1335,7 @@ static void
 nicvf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
 	struct nicvf *nic = nicvf_pmd_priv(dev);
+	struct rte_pci_device *pci_dev = RTE_DEV_PCI_DEV(dev->device);
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -1347,7 +1348,7 @@ nicvf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	dev_info->max_tx_queues =
 			(uint16_t)MAX_SND_QUEUES_PER_QS * (MAX_SQS_PER_VF + 1);
 	dev_info->max_mac_addrs = 1;
-	dev_info->max_vfs = dev->pci_dev->max_vfs;
+	dev_info->max_vfs = pci_dev->max_vfs;
 
 	dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
 	dev_info->tx_offload_capa =
@@ -1977,7 +1978,7 @@ nicvf_eth_dev_init(struct rte_eth_dev *eth_dev)
 		}
 	}
 
-	pci_dev = eth_dev->pci_dev;
+	pci_dev = RTE_DEV_PCI_DEV(eth_dev->device);
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 
 	nic->device_id = pci_dev->id.device_id;
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 6949b39..adeacee 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1321,7 +1321,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	 * virtio_user_eth_dev_alloc() before eth_virtio_dev_init() is called.
 	 */
 	if (!hw->virtio_user_dev) {
-		ret = vtpci_init(eth_dev->pci_dev, hw, &dev_flags);
+		ret = vtpci_init(RTE_DEV_PCI_DEV(eth_dev->device), hw,
+				 &dev_flags);
 		if (ret)
 			return ret;
 	}
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index 406beea..8cb983c 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -310,7 +310,6 @@ virtio_user_eth_dev_alloc(const char *name)
 	data->numa_node = SOCKET_ID_ANY;
 	data->kdrv = RTE_KDRV_NONE;
 	data->dev_flags = RTE_ETH_DEV_DETACHABLE;
-	eth_dev->pci_dev = NULL;
 	eth_dev->driver = NULL;
 	return eth_dev;
 }
diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.c b/drivers/net/vmxnet3/vmxnet3_ethdev.c
index 5fe1d3f..86a192b 100644
--- a/drivers/net/vmxnet3/vmxnet3_ethdev.c
+++ b/drivers/net/vmxnet3/vmxnet3_ethdev.c
@@ -237,7 +237,7 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->dev_ops = &vmxnet3_eth_dev_ops;
 	eth_dev->rx_pkt_burst = &vmxnet3_recv_pkts;
 	eth_dev->tx_pkt_burst = &vmxnet3_xmit_pkts;
-	pci_dev = eth_dev->pci_dev;
+	pci_dev = RTE_DEV_PCI_DEV(eth_dev->device);
 
 	/*
 	 * for secondary processes, we don't initialize any further as primary
@@ -709,7 +709,7 @@ static void
 vmxnet3_dev_info_get(struct rte_eth_dev *dev,
 		     struct rte_eth_dev_info *dev_info)
 {
-	dev_info->pci_dev = dev->pci_dev;
+	dev_info->pci_dev = RTE_DEV_PCI_DEV(dev->device);
 
 	dev_info->max_rx_queues = VMXNET3_MAX_RX_QUEUES;
 	dev_info->max_tx_queues = VMXNET3_MAX_TX_QUEUES;
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index fbc4311..6b4f8f4 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -160,6 +160,12 @@ struct rte_pci_device {
 	enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
 };
 
+/**
+ * @internal
+ * Helper macro for drivers that need to convert to struct rte_pci_device.
+ */
+#define RTE_DEV_PCI_DEV(ptr) container_of(ptr, struct rte_pci_device, device)
+
 /** Any PCI device identifier (vendor, device, ...) */
 #define PCI_ANY_ID (0xffff)
 #define RTE_CLASS_ANY_ID (0xffffff)
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 8e02d2e..280f0db 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -261,7 +261,7 @@ rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
 		if (eth_dev->data->dev_private == NULL)
 			rte_panic("Cannot allocate memzone for private port data\n");
 	}
-	eth_dev->pci_dev = pci_dev;
+	eth_dev->device = &pci_dev->device;
 	eth_dev->intr_handle = &pci_dev->intr_handle;
 	eth_dev->driver = eth_drv;
 
@@ -313,7 +313,7 @@ rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
 		rte_free(eth_dev->data->dev_private);
 
-	eth_dev->pci_dev = NULL;
+	eth_dev->device = NULL;
 	eth_dev->driver = NULL;
 	eth_dev->data = NULL;
 
@@ -2625,7 +2625,7 @@ rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
 	const struct rte_memzone *mz;
 
 	snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
-		 dev->driver->pci_drv.driver.name, ring_name,
+		 dev->data->drv_name, ring_name,
 		 dev->data->port_id, queue_id);
 
 	mz = rte_memzone_lookup(z_name);
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index e1eae65..eec1c84 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1624,7 +1624,7 @@ struct rte_eth_dev {
 	struct rte_eth_dev_data *data;  /**< Pointer to device data */
 	const struct eth_driver *driver;/**< Driver for this device */
 	const struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */
-	struct rte_pci_device *pci_dev; /**< PCI info. supplied by probing */
+	struct rte_device *device; /**< Backing device for this device */
 	struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
 	/** User application callbacks for NIC interrupts */
 	struct rte_eth_dev_cb_list link_intr_cbs;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 81+ messages in thread

* Re: [PATCH v5 20/20] ethdev: Decouple from PCI device
  2016-12-23 15:58 ` [PATCH v5 20/20] ethdev: Decouple from PCI device Jan Blunck
@ 2016-12-23 16:17   ` Thomas Monjalon
  2016-12-23 16:20     ` Jan Blunck
  0 siblings, 1 reply; 81+ messages in thread
From: Thomas Monjalon @ 2016-12-23 16:17 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, shreyansh.jain, david.marchand, stephen

2016-12-23 16:58, Jan Blunck:
> +/**
> + * @internal
> + * Helper macro for drivers that need to convert to struct rte_pci_device.
> + */
> +#define RTE_DEV_PCI_DEV(ptr) container_of(ptr, struct rte_pci_device, device)

Do you prefer to rename to RTE_DEV_TO_PCI?

> +       struct rte_device *device; /**< Backing device for this device */

This comment looks strange.
shorten to just "Backing device"?

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v5 03/20] rte_device: make driver pointer const
  2016-12-23 15:57 ` [PATCH v5 03/20] rte_device: make driver pointer const Jan Blunck
@ 2016-12-23 16:19   ` Thomas Monjalon
  2016-12-23 22:08   ` Stephen Hemminger
  1 sibling, 0 replies; 81+ messages in thread
From: Thomas Monjalon @ 2016-12-23 16:19 UTC (permalink / raw)
  To: Jan Blunck, Stephen Hemminger; +Cc: dev, shreyansh.jain, david.marchand

2016-12-23 16:57, Jan Blunck:
> From: Stephen Hemminger <stephen@networkplumber.org>
> 
> The info in rte_device about driver is immutable and
> shouldn't change.
> 
> Acked-by: Jan Blunck <jblunck@infradead.org>
> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>

There's no Signed-off-by

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v5 05/20] e1000: localize mapping from eth_dev to pci
  2016-12-23 15:57 ` [PATCH v5 05/20] e1000: localize mapping from eth_dev to pci Jan Blunck
@ 2016-12-23 16:20   ` Thomas Monjalon
  2016-12-23 22:06   ` Stephen Hemminger
  1 sibling, 0 replies; 81+ messages in thread
From: Thomas Monjalon @ 2016-12-23 16:20 UTC (permalink / raw)
  To: Jan Blunck, Stephen Hemminger; +Cc: dev, shreyansh.jain, david.marchand

2016-12-23 16:57, Jan Blunck:
> From: Stephen Hemminger <stephen@networkplumber.org>
> 
> Create one macro for where PCI device information is extracted
> from ethernet device. Makes later changes easier to review, and test.
> 
> Acked-by: Jan Blunck <jblunck@infradead.org>

Missing Signed-off-by: line

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v5 20/20] ethdev: Decouple from PCI device
  2016-12-23 16:17   ` Thomas Monjalon
@ 2016-12-23 16:20     ` Jan Blunck
  0 siblings, 0 replies; 81+ messages in thread
From: Jan Blunck @ 2016-12-23 16:20 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Shreyansh Jain, David Marchand, Stephen Hemminger

On Fri, Dec 23, 2016 at 5:17 PM, Thomas Monjalon
<thomas.monjalon@6wind.com> wrote:
> 2016-12-23 16:58, Jan Blunck:
>> +/**
>> + * @internal
>> + * Helper macro for drivers that need to convert to struct rte_pci_device.
>> + */
>> +#define RTE_DEV_PCI_DEV(ptr) container_of(ptr, struct rte_pci_device, device)
>
> Do you prefer to rename to RTE_DEV_TO_PCI?

I'm fine with that.

>
>> +       struct rte_device *device; /**< Backing device for this device */
>
> This comment looks strange.
> shorten to just "Backing device"?

Agreed.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v5 15/20] szedata2: localize handling of pci resources
  2016-12-23 15:58 ` [PATCH v5 15/20] szedata2: localize handling of pci resources Jan Blunck
@ 2016-12-23 18:31   ` Thomas Monjalon
  0 siblings, 0 replies; 81+ messages in thread
From: Thomas Monjalon @ 2016-12-23 18:31 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, stephen

2016-12-23 16:58, Jan Blunck:
>  #define SZEDATA2_PCI_RESOURCE_PTR(dev, offset, type) \
> -       ((type)((uint8_t *) \
> -       ((dev)->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr) \
> -       + (offset)))
> +       ((type)((uint8_t *)(rsc)->addr) + (offset)))

There is this error: use of undeclared identifier 'rsc'
Should we rename dev to rsc?

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v5 19/20] ethdev: Move dev_info filling of PCI information into drivers
  2016-12-23 15:58 ` [PATCH v5 19/20] ethdev: Move dev_info filling of PCI information into drivers Jan Blunck
@ 2016-12-23 18:45   ` Thomas Monjalon
  0 siblings, 0 replies; 81+ messages in thread
From: Thomas Monjalon @ 2016-12-23 18:45 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, shreyansh.jain, david.marchand, stephen

2016-12-23 16:58, Jan Blunck:
> --- a/drivers/net/thunderx/nicvf_ethdev.c
> +++ b/drivers/net/thunderx/nicvf_ethdev.c
> @@ -1338,6 +1338,8 @@ nicvf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
>  
>         PMD_INIT_FUNC_TRACE();
>  
> +       dev_info->pci_dev = pci_dev;

It should be dev->pci_dev

No need to resend a v6 for these small errors.
If Stephen confirm his SoB on first patches, I can push this v5 with
some fixes.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v5 05/20] e1000: localize mapping from eth_dev to pci
  2016-12-23 15:57 ` [PATCH v5 05/20] e1000: localize mapping from eth_dev to pci Jan Blunck
  2016-12-23 16:20   ` Thomas Monjalon
@ 2016-12-23 22:06   ` Stephen Hemminger
  1 sibling, 0 replies; 81+ messages in thread
From: Stephen Hemminger @ 2016-12-23 22:06 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, shreyansh.jain, david.marchand

On Fri, 23 Dec 2016 16:57:56 +0100
Jan Blunck <jblunck@infradead.org> wrote:

> From: Stephen Hemminger <stephen@networkplumber.org>
> 
> Create one macro for where PCI device information is extracted
> from ethernet device. Makes later changes easier to review, and test.
> 
> Acked-by: Jan Blunck <jblunck@infradead.org>

Go ahead and add missing signed-off-by. I overlooked it on the
original  RFC set.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

Still want ACK from Intel maintainers.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v5 03/20] rte_device: make driver pointer const
  2016-12-23 15:57 ` [PATCH v5 03/20] rte_device: make driver pointer const Jan Blunck
  2016-12-23 16:19   ` Thomas Monjalon
@ 2016-12-23 22:08   ` Stephen Hemminger
  1 sibling, 0 replies; 81+ messages in thread
From: Stephen Hemminger @ 2016-12-23 22:08 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, shreyansh.jain, david.marchand

On Fri, 23 Dec 2016 16:57:54 +0100
Jan Blunck <jblunck@infradead.org> wrote:

> From: Stephen Hemminger <stephen@networkplumber.org>
> 
> The info in rte_device about driver is immutable and
> shouldn't change.
> 
> Acked-by: Jan Blunck <jblunck@infradead.org>
> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
> ---
>  lib/librte_eal/common/include/rte_dev.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
> index 1708244..b17791f 100644
> --- a/lib/librte_eal/common/include/rte_dev.h
> +++ b/lib/librte_eal/common/include/rte_dev.h
> @@ -122,7 +122,7 @@ struct rte_driver;
>   */
>  struct rte_device {
>  	TAILQ_ENTRY(rte_device) next; /**< Next device */
> -	struct rte_driver *driver;    /**< Associated driver */
> +	const struct rte_driver *driver;/**< Associated driver */
>  	int numa_node;                /**< NUMA node connection */
>  	struct rte_devargs *devargs;  /**< Device user arguments */
>  };


Go ahead and add missing signed-off-by. I overlooked it on the
original  RFC set.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v5 00/20] Decouple ethdev from PCI device
  2016-12-23 15:57 ` [PATCH v5 00/20] " Jan Blunck
@ 2016-12-25 22:33   ` Thomas Monjalon
  2017-01-03 12:20     ` Ferruh Yigit
  2017-01-03 12:24     ` Ferruh Yigit
  0 siblings, 2 replies; 81+ messages in thread
From: Thomas Monjalon @ 2016-12-25 22:33 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, shreyansh.jain, david.marchand, stephen

2016-12-23 16:57, Jan Blunck:
> This repost addresses the review comments of Thomas Monjalon to completely
> remove the ethdev helper to further decrease the coupling of the ethdev and
> the eal layers. This required me to squash together all patches using the
> rte_eth_dev_to_pci() helper into "Decouple from PCI device" patch. As
> discussed privately I'll keep the PCI information in rte_eth_dev_info
> untouched.

Applied with some trivial fixes, thanks

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v5 00/20] Decouple ethdev from PCI device
  2016-12-25 22:33   ` Thomas Monjalon
@ 2017-01-03 12:20     ` Ferruh Yigit
  2017-01-06 10:07       ` Andrew Rybchenko
  2017-01-03 12:24     ` Ferruh Yigit
  1 sibling, 1 reply; 81+ messages in thread
From: Ferruh Yigit @ 2017-01-03 12:20 UTC (permalink / raw)
  To: Thomas Monjalon, Jan Blunck
  Cc: dev, shreyansh.jain, david.marchand, stephen, Andrew Rybchenko,
	Alejandro Lucero

On 12/25/2016 10:33 PM, Thomas Monjalon wrote:
> 2016-12-23 16:57, Jan Blunck:
>> This repost addresses the review comments of Thomas Monjalon to completely
>> remove the ethdev helper to further decrease the coupling of the ethdev and
>> the eal layers. This required me to squash together all patches using the
>> rte_eth_dev_to_pci() helper into "Decouple from PCI device" patch. As
>> discussed privately I'll keep the PCI information in rte_eth_dev_info
>> untouched.
> 
> Applied with some trivial fixes, thanks
> 

I rebased these changes into next-net tree. And need to update some sfc
and nfp patches [1] there.

Andrew, Alejandro,

Can you please review your driver in the latest next-net tree?

Thanks,
ferruh

[1]
nfp:
net/nfp: add Rx interrupts

sfc:
net/sfc: support link status change interrupt
net/sfc: interrupts support sufficient for event queue init
net/sfc: implement driver operation to init device on attach
net/sfc: libefx-based PMD stub sufficient to build and init

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v5 00/20] Decouple ethdev from PCI device
  2016-12-25 22:33   ` Thomas Monjalon
  2017-01-03 12:20     ` Ferruh Yigit
@ 2017-01-03 12:24     ` Ferruh Yigit
  2017-01-03 14:06       ` Thomas Monjalon
  1 sibling, 1 reply; 81+ messages in thread
From: Ferruh Yigit @ 2017-01-03 12:24 UTC (permalink / raw)
  To: Thomas Monjalon, Jan Blunck
  Cc: dev, shreyansh.jain, david.marchand, stephen, Adrien Mazarguil,
	Nelio Laranjeiro

On 12/25/2016 10:33 PM, Thomas Monjalon wrote:
> 2016-12-23 16:57, Jan Blunck:
>> This repost addresses the review comments of Thomas Monjalon to completely
>> remove the ethdev helper to further decrease the coupling of the ethdev and
>> the eal layers. This required me to squash together all patches using the
>> rte_eth_dev_to_pci() helper into "Decouple from PCI device" patch. As
>> discussed privately I'll keep the PCI information in rte_eth_dev_info
>> untouched.
> 
> Applied with some trivial fixes, thanks
> 

Getting following build error for mlx5 [1], it is mainly because verbs.h
also using container_of macro.

[1]
In file included from
.../x86_64-native-linuxapp-gcc/include/rte_mbuf.h:57:0,
                 from .../x86_64-native-linuxapp-gcc/include/rte_ether.h:52,
                 from .../drivers/net/mlx5/mlx5_trigger.c:38:
/usr/include/infiniband/verbs.h: In function ‘verbs_get_device’:
.../x86_64-native-linuxapp-gcc/include/rte_common.h:350:40: error:
initialization discards ‘const’ qualifier from pointer target type
[-Werror=discarded-qualifiers]
    typeof(((type *)0)->member) *_ptr = (ptr); \
                                        ^

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v5 00/20] Decouple ethdev from PCI device
  2017-01-03 12:24     ` Ferruh Yigit
@ 2017-01-03 14:06       ` Thomas Monjalon
  2017-01-03 14:40         ` Ferruh Yigit
  0 siblings, 1 reply; 81+ messages in thread
From: Thomas Monjalon @ 2017-01-03 14:06 UTC (permalink / raw)
  To: Ferruh Yigit
  Cc: Jan Blunck, dev, shreyansh.jain, david.marchand, stephen,
	Adrien Mazarguil, Nelio Laranjeiro

2017-01-03 12:24, Ferruh Yigit:
> On 12/25/2016 10:33 PM, Thomas Monjalon wrote:
> > Applied with some trivial fixes, thanks
> 
> Getting following build error for mlx5 [1], it is mainly because verbs.h
> also using container_of macro.
> 
> [1]
> In file included from
> .../x86_64-native-linuxapp-gcc/include/rte_mbuf.h:57:0,
>                  from .../x86_64-native-linuxapp-gcc/include/rte_ether.h:52,
>                  from .../drivers/net/mlx5/mlx5_trigger.c:38:
> /usr/include/infiniband/verbs.h: In function ‘verbs_get_device’:
> .../x86_64-native-linuxapp-gcc/include/rte_common.h:350:40: error:
> initialization discards ‘const’ qualifier from pointer target type
> [-Werror=discarded-qualifiers]
>     typeof(((type *)0)->member) *_ptr = (ptr); \
>                                         ^

Yes, this issue is fixed by upgrading mofed to version 3.4.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v5 00/20] Decouple ethdev from PCI device
  2017-01-03 14:06       ` Thomas Monjalon
@ 2017-01-03 14:40         ` Ferruh Yigit
  0 siblings, 0 replies; 81+ messages in thread
From: Ferruh Yigit @ 2017-01-03 14:40 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: Jan Blunck, dev, shreyansh.jain, david.marchand, stephen,
	Adrien Mazarguil, Nelio Laranjeiro

On 1/3/2017 2:06 PM, Thomas Monjalon wrote:
> 2017-01-03 12:24, Ferruh Yigit:
>> On 12/25/2016 10:33 PM, Thomas Monjalon wrote:
>>> Applied with some trivial fixes, thanks
>>
>> Getting following build error for mlx5 [1], it is mainly because verbs.h
>> also using container_of macro.
>>
>> [1]
>> In file included from
>> .../x86_64-native-linuxapp-gcc/include/rte_mbuf.h:57:0,
>>                  from .../x86_64-native-linuxapp-gcc/include/rte_ether.h:52,
>>                  from .../drivers/net/mlx5/mlx5_trigger.c:38:
>> /usr/include/infiniband/verbs.h: In function ‘verbs_get_device’:
>> .../x86_64-native-linuxapp-gcc/include/rte_common.h:350:40: error:
>> initialization discards ‘const’ qualifier from pointer target type
>> [-Werror=discarded-qualifiers]
>>     typeof(((type *)0)->member) *_ptr = (ptr); \
>>                                         ^
> 
> Yes, this issue is fixed by upgrading mofed to version 3.4.
> 

Confirmed.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v5 00/20] Decouple ethdev from PCI device
  2017-01-03 12:20     ` Ferruh Yigit
@ 2017-01-06 10:07       ` Andrew Rybchenko
  0 siblings, 0 replies; 81+ messages in thread
From: Andrew Rybchenko @ 2017-01-06 10:07 UTC (permalink / raw)
  To: Ferruh Yigit, Thomas Monjalon, Jan Blunck
  Cc: dev, shreyansh.jain, david.marchand, stephen, Alejandro Lucero

On 01/03/2017 03:20 PM, Ferruh Yigit wrote:
> On 12/25/2016 10:33 PM, Thomas Monjalon wrote:
>> 2016-12-23 16:57, Jan Blunck:
>>> This repost addresses the review comments of Thomas Monjalon to completely
>>> remove the ethdev helper to further decrease the coupling of the ethdev and
>>> the eal layers. This required me to squash together all patches using the
>>> rte_eth_dev_to_pci() helper into "Decouple from PCI device" patch. As
>>> discussed privately I'll keep the PCI information in rte_eth_dev_info
>>> untouched.
>> Applied with some trivial fixes, thanks
>>
> I rebased these changes into next-net tree. And need to update some sfc
> and nfp patches [1] there.
>
> Andrew, Alejandro,
>
> Can you please review your driver in the latest next-net tree?
>
> Thanks,
> ferruh
>
> [1]
> nfp:
> net/nfp: add Rx interrupts
>
> sfc:
> net/sfc: support link status change interrupt
> net/sfc: interrupts support sufficient for event queue init
> net/sfc: implement driver operation to init device on attach
> net/sfc: libefx-based PMD stub sufficient to build and init

Ferruh,

thanks that you care about it. I've reviewed and tested it. It looks and 
works fine for me.

Andrew.

^ permalink raw reply	[flat|nested] 81+ messages in thread

* Re: [PATCH v5 02/20] eal: Allow passing const rte_intr_handle
  2016-12-23 15:57 ` [PATCH v5 02/20] eal: Allow passing const rte_intr_handle Jan Blunck
@ 2017-01-17  4:42   ` Tan, Jianfeng
  0 siblings, 0 replies; 81+ messages in thread
From: Tan, Jianfeng @ 2017-01-17  4:42 UTC (permalink / raw)
  To: Jan Blunck, dev; +Cc: shreyansh.jain, david.marchand, stephen

Hi Jan,

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Jan Blunck
> Sent: Friday, December 23, 2016 11:58 PM
> To: dev@dpdk.org
> Cc: shreyansh.jain@nxp.com; david.marchand@6wind.com;
> stephen@networkplumber.org
> Subject: [dpdk-dev] [PATCH v5 02/20] eal: Allow passing const
> rte_intr_handle
> 
> Both register/unregister and enable/disable don't necessarily require the
> rte_intr_handle to be modifiable. Therefore lets constify it.
> 
> Signed-off-by: Jan Blunck <jblunck@infradead.org>
> ---
>  lib/librte_eal/bsdapp/eal/eal_interrupts.c     | 24 ++++++----
>  lib/librte_eal/common/include/rte_interrupts.h |  8 ++--
>  lib/librte_eal/linuxapp/eal/eal_interrupts.c   | 62 ++++++++++++++++++----
> ----
>  3 files changed, 63 insertions(+), 31 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_interrupts.c
> b/lib/librte_eal/bsdapp/eal/eal_interrupts.c
> index 836e483..ea2afff 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_interrupts.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_interrupts.c
> @@ -36,29 +36,37 @@
>  #include "eal_private.h"
> 
[...]
> 
> +static int
> +get_max_intr(const struct rte_intr_handle *intr_handle)
> +{
> +	struct rte_intr_source *src;
> +
> +	TAILQ_FOREACH(src, &intr_sources, next) {
> +		if (src->intr_handle.fd != intr_handle->fd)
> +			continue;
> +
> +		if (!src->intr_handle.max_intr)
> +			src->intr_handle.max_intr = 1;
> +		else if (src->intr_handle.max_intr >
> RTE_MAX_RXTX_INTR_VEC_ID)

See "src" instead of intr_handle is used here. "src" is only initialized as calling rte_intr_callback_register at device init phase. But max_intr is usually changed as calling rte_intr_efd_enable() after that. How to make sure max_intr in "src" is valid? And, why shall we use src instead of intr_handle here?

Thanks,
Jianfeng

> +			src->intr_handle.max_intr
> +				= RTE_MAX_RXTX_INTR_VEC_ID + 1;
> +
> +		return src->intr_handle.max_intr;
> +	}
> +
> +	return -1;
> +}
> +
>  /* enable MSI-X interrupts */
>  static int
> -vfio_enable_msix(struct rte_intr_handle *intr_handle) {
> +vfio_enable_msix(const struct rte_intr_handle *intr_handle) {
>  	int len, ret;
>  	char irq_set_buf[MSIX_IRQ_SET_BUF_LEN];
>  	struct vfio_irq_set *irq_set;
> @@ -290,12 +311,15 @@ vfio_enable_msix(struct rte_intr_handle
> *intr_handle) {
> 
>  	irq_set = (struct vfio_irq_set *) irq_set_buf;
>  	irq_set->argsz = len;
> -	if (!intr_handle->max_intr)
> -		intr_handle->max_intr = 1;
> -	else if (intr_handle->max_intr > RTE_MAX_RXTX_INTR_VEC_ID)
> -		intr_handle->max_intr = RTE_MAX_RXTX_INTR_VEC_ID + 1;
> 
> -	irq_set->count = intr_handle->max_intr;
> +	ret = get_max_intr(intr_handle);
> +	if (ret < 0) {
> +		RTE_LOG(ERR, EAL, "Invalid number of MSI-X irqs for
> fd %d\n",
> +			intr_handle->fd);
> +		return -1;
> +	}
> +
> +	irq_set->count = ret;
>  	irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD |
> VFIO_IRQ_SET_ACTION_TRIGGER;
>  	irq_set->index = VFIO_PCI_MSIX_IRQ_INDEX;
>  	irq_set->start = 0;
> @@ -318,7 +342,7 @@ vfio_enable_msix(struct rte_intr_handle
> *intr_handle) {
> 

^ permalink raw reply	[flat|nested] 81+ messages in thread

end of thread, other threads:[~2017-01-17  4:42 UTC | newest]

Thread overview: 81+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-21 15:09 [PATCH v4 00/23] Decouple ethdev from PCI device Jan Blunck
2016-12-21 15:09 ` [PATCH v4 01/23] eal: define container_of macro Jan Blunck
2016-12-21 15:09 ` [PATCH v4 02/23] eal: Allow passing const rte_intr_handle Jan Blunck
2016-12-21 15:09 ` [PATCH v4 03/23] rte_device: make driver pointer const Jan Blunck
2016-12-22  7:18   ` Shreyansh Jain
2016-12-21 15:09 ` [PATCH v4 04/23] pmd: remove useless reset of dev_info->dev_pci Jan Blunck
2016-12-21 15:09 ` [PATCH v4 05/23] e1000: localize mapping from eth_dev to pci Jan Blunck
2016-12-21 15:09 ` [PATCH v4 06/23] ixgbe: localize mapping from eth_dev to pci_device Jan Blunck
2016-12-21 15:09 ` [PATCH v4 07/23] i40e: localize mapping of eth_dev to pci Jan Blunck
2016-12-21 15:09 ` [PATCH v4 08/23] broadcom: localize mapping from " Jan Blunck
2016-12-21 15:09 ` [PATCH v4 09/23] virtio: Don't fill dev_info->driver_name Jan Blunck
2016-12-21 15:09 ` [PATCH v4 10/23] virtio: Add vtpci_intr_handle() helper to get rte_intr_handle Jan Blunck
2016-12-21 20:08   ` Stephen Hemminger
2016-12-23 11:04     ` Jan Blunck
2016-12-21 15:09 ` [PATCH v4 11/23] virtio: Don't depend on struct rte_eth_dev's pci_dev Jan Blunck
2016-12-21 15:09 ` [PATCH v4 12/23] bnx2x: localize mapping from eth_dev to pci Jan Blunck
2016-12-21 16:35   ` Harish Patil
2016-12-21 15:09 ` [PATCH v4 13/23] fm10k: " Jan Blunck
2016-12-21 15:09 ` [PATCH v4 14/23] qede: localize mapping of " Jan Blunck
2016-12-21 16:35   ` Harish Patil
2016-12-21 15:09 ` [PATCH v4 15/23] szedata2: localize handling of pci resources Jan Blunck
2016-12-21 15:09 ` [PATCH v4 16/23] nfp: localize rte_pci_device handling Jan Blunck
2016-12-21 15:09 ` [PATCH v4 17/23] vmxnet3: use eth_dev->data->drv_name instead of pci_drv name Jan Blunck
2016-12-21 15:09 ` [PATCH v4 18/23] ethdev: Helper to map to struct rte_pci_device Jan Blunck
2016-12-22 15:21   ` Thomas Monjalon
2016-12-22 18:13     ` Jan Blunck
2016-12-23  8:30       ` Thomas Monjalon
2016-12-23 10:27         ` Jan Blunck
2016-12-23 12:47           ` Thomas Monjalon
2016-12-21 15:09 ` [PATCH v4 19/23] drivers: Replace per-PMD macros with rte_eth_dev_to_pci() helper Jan Blunck
2016-12-21 15:09 ` [PATCH v4 20/23] drivers: Use " Jan Blunck
2016-12-21 15:09 ` [PATCH v4 21/23] ethdev: Move filling of rte_eth_dev_info->pci_dev to dev_infos_get() Jan Blunck
2016-12-21 20:09   ` Stephen Hemminger
2016-12-22  8:11     ` Shreyansh Jain
2016-12-23 10:50       ` Jan Blunck
2016-12-23 11:11         ` Shreyansh Jain
2016-12-23 11:27           ` Jan Blunck
2016-12-23 11:39             ` Shreyansh Jain
2016-12-21 15:09 ` [PATCH v4 22/23] ethdev: Decouple interrupt handling from PCI device Jan Blunck
2016-12-22 15:13   ` Thomas Monjalon
2016-12-22 18:26     ` Jan Blunck
2016-12-21 15:09 ` [PATCH v4 23/23] ethdev: Decouple struct rte_eth_dev from struct rte_pci_device Jan Blunck
2016-12-22 15:22   ` Thomas Monjalon
2016-12-22 15:26 ` [PATCH v4 00/23] Decouple ethdev from PCI device Thomas Monjalon
2016-12-23 14:28   ` Thomas Monjalon
2016-12-23 15:57 ` [PATCH v5 00/20] " Jan Blunck
2016-12-25 22:33   ` Thomas Monjalon
2017-01-03 12:20     ` Ferruh Yigit
2017-01-06 10:07       ` Andrew Rybchenko
2017-01-03 12:24     ` Ferruh Yigit
2017-01-03 14:06       ` Thomas Monjalon
2017-01-03 14:40         ` Ferruh Yigit
2016-12-23 15:57 ` [PATCH v5 01/20] eal: define container_of macro Jan Blunck
2016-12-23 15:57 ` [PATCH v5 02/20] eal: Allow passing const rte_intr_handle Jan Blunck
2017-01-17  4:42   ` Tan, Jianfeng
2016-12-23 15:57 ` [PATCH v5 03/20] rte_device: make driver pointer const Jan Blunck
2016-12-23 16:19   ` Thomas Monjalon
2016-12-23 22:08   ` Stephen Hemminger
2016-12-23 15:57 ` [PATCH v5 04/20] pmd: remove useless reset of dev_info->dev_pci Jan Blunck
2016-12-23 15:57 ` [PATCH v5 05/20] e1000: localize mapping from eth_dev to pci Jan Blunck
2016-12-23 16:20   ` Thomas Monjalon
2016-12-23 22:06   ` Stephen Hemminger
2016-12-23 15:57 ` [PATCH v5 06/20] ixgbe: localize mapping from eth_dev to pci_device Jan Blunck
2016-12-23 15:57 ` [PATCH v5 07/20] i40e: localize mapping of eth_dev to pci Jan Blunck
2016-12-23 15:57 ` [PATCH v5 08/20] broadcom: localize mapping from " Jan Blunck
2016-12-23 15:58 ` [PATCH v5 09/20] virtio: Don't fill dev_info->driver_name Jan Blunck
2016-12-23 15:58 ` [PATCH v5 10/20] virtio: Add vtpci_intr_handle() helper to get rte_intr_handle Jan Blunck
2016-12-23 15:58 ` [PATCH v5 11/20] virtio: Don't depend on struct rte_eth_dev's pci_dev Jan Blunck
2016-12-23 15:58 ` [PATCH v5 12/20] bnx2x: localize mapping from eth_dev to pci Jan Blunck
2016-12-23 15:58 ` [PATCH v5 13/20] fm10k: " Jan Blunck
2016-12-23 15:58 ` [PATCH v5 14/20] qede: localize mapping of " Jan Blunck
2016-12-23 15:58 ` [PATCH v5 15/20] szedata2: localize handling of pci resources Jan Blunck
2016-12-23 18:31   ` Thomas Monjalon
2016-12-23 15:58 ` [PATCH v5 16/20] nfp: localize rte_pci_device handling Jan Blunck
2016-12-23 15:58 ` [PATCH v5 17/20] vmxnet3: use eth_dev->data->drv_name instead of pci_drv name Jan Blunck
2016-12-23 15:58 ` [PATCH v5 18/20] ethdev: Decouple interrupt handling from PCI device Jan Blunck
2016-12-23 15:58 ` [PATCH v5 19/20] ethdev: Move dev_info filling of PCI information into drivers Jan Blunck
2016-12-23 18:45   ` Thomas Monjalon
2016-12-23 15:58 ` [PATCH v5 20/20] ethdev: Decouple from PCI device Jan Blunck
2016-12-23 16:17   ` Thomas Monjalon
2016-12-23 16:20     ` Jan Blunck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.