Skip to contentSkip to conversation

Generalize rte_eth_dev model

RFC In review Stephen Hemminger 4 participants 25 messages Dec 19, 2016 – Dec 20, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover Generalize rte_eth_dev model

This set of patches generalize the ethernet device model sufficently to support virtual, pci, and vmbus devices.

All this is based on the XP principal of only building what is necessary and no more than that. The rationale is NOT to rework the DPDK to have same level of bus and parent information as the Linux device model. This would be unnecessary, fragile and unnecessarily OS dependent.

Instead, this set of patches does the simple change of refactoring so that the object relationship between ethernet (rte_eth_dev), PCI (rte_pci_device) and generic (rte_device) is properly broken apart.

It does make the simplifying assumption that the device driver knows what type of bus it is on. For a future case where a device has to be able to handle different bus families; then the device driver can have multiple device drivers in one code base (like ixgbe PF/VF).

Jan Blunck (1):
eal: define container_of macro

Stephen Hemminger (12):
ethdev: increase length ethernet device internal name
rte_device: make driver pointer const
eal: introduce driver type
pmd: remove useless reset of dev_info->dev_pci
ethdev: make dev_info generic (not just 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
virtio: localize mapping from rte_eth to pci
broadcom: localize mapping from eth_dev to pci
ethdev: change pci_dev to generic device
hyperv: VMBUS support infrastucture

 app/test-pmd/config.c                       |  32 +++++++-
 app/test-pmd/testpmd.c                      |  11 ++-
 app/test-pmd/testpmd.h                      |  32 ++++----
 app/test/test_kni.c                         |  39 +++++++--
 app/test/virtual_pmd.c                      |   4 +-
 doc/guides/rel_notes/deprecation.rst        |   3 +
 doc/guides/rel_notes/release_17_02.rst      |  10 +--
 drivers/net/af_packet/rte_eth_af_packet.c   |   1 -
 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            |   2 +-
 drivers/net/cxgbe/cxgbe_main.c              |   5 +-
 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 +-
 drivers/net/ena/ena_ethdev.c                |   2 +-
 drivers/net/enic/enic_ethdev.c              |   2 +-
 drivers/net/enic/enic_rxtx.c                |   2 -
 drivers/net/fm10k/fm10k_ethdev.c            |  90 +++++++++++++--------
 drivers/net/i40e/i40e_ethdev.c              |  77 +++++++++++-------
 drivers/net/i40e/i40e_ethdev.h              |   3 +
 drivers/net/i40e/i40e_ethdev_vf.c           |  59 ++++++++------
 drivers/net/ixgbe/ixgbe_ethdev.c            | 120 ++++++++++++++++------------
 drivers/net/ixgbe/ixgbe_ethdev.h            |   3 +
 drivers/net/ixgbe/ixgbe_pf.c                |   4 +-
 drivers/net/null/rte_eth_null.c             |   1 -
 drivers/net/pcap/rte_eth_pcap.c             |   1 -
 drivers/net/qede/qede_ethdev.c              |  24 +++---
 drivers/net/qede/qede_ethdev.h              |   4 +
 drivers/net/ring/rte_eth_ring.c             |   1 -
 drivers/net/virtio/virtio_ethdev.c          |  95 +++++++++++++++-------
 drivers/net/virtio/virtio_user_ethdev.c     |   2 +-
 drivers/net/vmxnet3/vmxnet3_ethdev.c        |   3 +-
 drivers/net/xenvirt/rte_eth_xenvirt.c       |   1 -
 lib/librte_eal/common/Makefile              |   2 +-
 lib/librte_eal/common/eal_common_devargs.c  |   7 ++
 lib/librte_eal/common/eal_common_options.c  |  38 +++++++++
 lib/librte_eal/common/eal_internal_cfg.h    |   3 +-
 lib/librte_eal/common/eal_options.h         |   6 ++
 lib/librte_eal/common/eal_private.h         |   5 ++
 lib/librte_eal/common/include/rte_common.h  |  20 +++++
 lib/librte_eal/common/include/rte_dev.h     |  17 +++-
 lib/librte_eal/common/include/rte_devargs.h |   8 ++
 lib/librte_eal/common/include/rte_pci.h     |   1 +
 lib/librte_eal/common/include/rte_vdev.h    |   1 +
 lib/librte_eal/linuxapp/eal/Makefile        |   6 ++
 lib/librte_eal/linuxapp/eal/eal.c           |  11 +++
 lib/librte_ether/rte_ethdev.c               | 114 ++++++++++++++++++++++++--
 lib/librte_ether/rte_ethdev.h               |  38 +++++++--
 mk/rte.app.mk                               |   1 +
 53 files changed, 776 insertions(+), 343 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v2 1/13 ethdev: increase length ethernet device internal name

Allow sufficicent space for UUID in string form (36+1). Needed to use UUID with Hyper-V

---
 doc/guides/rel_notes/deprecation.rst | 3 +++
 lib/librte_ether/rte_ethdev.h        | 6 +++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
doc/guides/rel_notes/deprecation.rst +3 -0
index 2d17bc6e..b83f23a1 100644
@@ -58,6 +58,9 @@ Deprecation Notices
   ``port`` field, may be moved or removed as part of this mbuf work. A
   ``timestamp`` will also be added.
 
+* ethdev: for 17.02 the size of internal device name will be increased
+  to 40 characters to allow for storing UUID.
+
 * The mbuf flags PKT_RX_VLAN_PKT and PKT_RX_QINQ_PKT are deprecated and
   are respectively replaced by PKT_RX_VLAN_STRIPPED and
   PKT_RX_QINQ_STRIPPED, that are better described. The old flags and
lib/librte_ether/rte_ethdev.h +5 -1
index 96781792..3c85e331 100644
@@ -1652,7 +1652,11 @@ struct rte_eth_dev_sriov {
 };
 #define RTE_ETH_DEV_SRIOV(dev)         ((dev)->data->sriov)
 
-#define RTE_ETH_NAME_MAX_LEN (32)
+/*
+ * Internal identifier length
+ * Sufficiently large to allow for UUID or PCI address
+ */
+#define RTE_ETH_NAME_MAX_LEN 40
 
 /**
  * @internal
Signature · 1 line
2.11.0
#4 lore raw

PATCH v2 2/13 rte_device: make driver pointer const

In reply to Stephen Hemminger

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

---
 lib/librte_eal/common/include/rte_dev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eal/common/include/rte_dev.h +1 -1
index 8840380d..e5471a22 100644
@@ -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 */
 };
Signature · 1 line
2.11.0
#6 lore raw

PATCH v2 3/13 eal: define container_of macro

In reply to Stephen Hemminger

From: Jan Blunck <[email protected]>

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.

[[email protected]: add type checking and __extension__]
---
 lib/librte_eal/common/include/rte_common.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
lib/librte_eal/common/include/rte_common.h +20 -0
index db5ac91c..8dda3e29 100644
@@ -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)
Signature · 1 line
2.11.0
#7 lore raw

PATCH v2 4/13 eal: introduce driver type

In reply to Stephen Hemminger

Since multiple buses and device types need to be supported. Provide type field in driver.

---
 lib/librte_eal/common/include/rte_dev.h  | 15 ++++++++++++---
 lib/librte_eal/common/include/rte_pci.h  |  1 +
 lib/librte_eal/common/include/rte_vdev.h |  1 +
 3 files changed, 14 insertions(+), 3 deletions(-)
lib/librte_eal/common/include/rte_dev.h +12 -3
index e5471a22..3f4e26e6 100644
@@ -144,12 +144,21 @@ void rte_eal_device_insert(struct rte_device *dev);
 void rte_eal_device_remove(struct rte_device *dev);
 
 /**
+ * Type of device driver
+ */
+enum rte_driver_type {
+	PMD_VIRTUAL,
+	PMD_PCI,
+};
+
+/**
  * A structure describing a device driver.
  */
 struct rte_driver {
 	TAILQ_ENTRY(rte_driver) next;  /**< Next in list. */
-	const char *name;                   /**< Driver name. */
-	const char *alias;              /**< Driver alias. */
+	const char *name;              /**< Driver name. */
+	const char *alias;             /**< Driver alias. */
+	enum rte_driver_type type;     /**< Driver type. */
 };
 
 /**
@@ -243,4 +252,4 @@ __attribute__((used)) = str
 }
 #endif
 
-#endif /* _RTE_VDEV_H_ */
+#endif /* _RTE_DEV_H_ */
lib/librte_eal/common/include/rte_pci.h +1 -0
index 9ce88472..d377d539 100644
@@ -492,6 +492,7 @@ RTE_INIT(pciinitfn_ ##nm); \
 static void pciinitfn_ ##nm(void) \
 {\
 	(pci_drv).driver.name = RTE_STR(nm);\
+	(pci_drv).driver.type = PMD_PCI; \
 	rte_eal_pci_register(&pci_drv); \
 } \
 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
lib/librte_eal/common/include/rte_vdev.h +1 -0
index 784e837d..98fb5bb5 100644
@@ -88,6 +88,7 @@ static void vdrvinitfn_ ##vdrv(void)\
 {\
 	(vdrv).driver.name = RTE_STR(nm);\
 	(vdrv).driver.alias = vdrvinit_ ## nm ## _alias;\
+	(vdrv).driver.type = PMD_VIRTUAL;\
 	rte_eal_vdrv_register(&vdrv);\
 } \
 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
Signature · 1 line
2.11.0
#13 lore raw

PATCH v2 5/13 pmd: remove useless reset of dev_info->dev_pci

In reply to Stephen Hemminger

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.

---
 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(-)
app/test/virtual_pmd.c +0 -1
index 65b44c64..e0447fda 100644
@@ -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
drivers/net/af_packet/rte_eth_af_packet.c +0 -1
index ff450685..2951f86c 100644
@@ -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
drivers/net/bonding/rte_eth_bond_pmd.c +0 -1
index a80b6fa9..74af6589 100644
@@ -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;
drivers/net/null/rte_eth_null.c +0 -1
index 836d982a..b4f253ad 100644
@@ -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;
 }
drivers/net/pcap/rte_eth_pcap.c +0 -1
index 0162f446..7253b9ad 100644
@@ -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
drivers/net/ring/rte_eth_ring.c +0 -1
index c1767c48..dc99a1fe 100644
@@ -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
drivers/net/xenvirt/rte_eth_xenvirt.c +0 -1
index c08a0568..609824b6 100644
@@ -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
Signature · 1 line
2.11.0
#15 lore raw

PATCH v2 6/13 ethdev: make dev_info generic (not just PCI)

In reply to Stephen Hemminger

The result from rte_eth_dev_info_get should have pointer to device not PCI device. This breaks ABI but is necessary.

---
 app/test-pmd/config.c                  | 32 ++++++++++++++++++++++++++--
 app/test-pmd/testpmd.c                 | 11 ++++++++--
 app/test-pmd/testpmd.h                 | 32 ++++++++++++++++------------
 app/test/test_kni.c                    | 39 ++++++++++++++++++++++++++++------
 doc/guides/rel_notes/release_17_02.rst | 10 +++------
 lib/librte_ether/rte_ethdev.c          |  3 ++-
 lib/librte_ether/rte_ethdev.h          |  2 +-
 7 files changed, 96 insertions(+), 33 deletions(-)
app/test-pmd/config.c +30 -2
index 8cf537d5..1d0974ad 100644
@@ -553,6 +553,16 @@ port_id_is_invalid(portid_t port_id, enum print_warning warning)
 	return 1;
 }
 
+int
+port_is_not_pci(portid_t port_id)
+{
+	if (ports[port_id].pci_dev)
+		return 0;
+
+	printf("Port %u is not a PCI device\n", port_id);
+	return 1;
+}
+
 static int
 vlan_id_is_invalid(uint16_t vlan_id)
 {
@@ -565,15 +575,22 @@ vlan_id_is_invalid(uint16_t vlan_id)
 static int
 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
 {
+	struct rte_pci_device *pci_dev = ports[port_id].pci_dev;
 	uint64_t pci_len;
 
+	if (pci_dev == NULL) {
+		printf("Port %u is not a PCI device\n", port_id);
+		return 1;
+	}
+
 	if (reg_off & 0x3) {
 		printf("Port register offset 0x%X not aligned on a 4-byte "
 		       "boundary\n",
 		       (unsigned)reg_off);
 		return 1;
 	}
-	pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
+
+	pci_len = pci_dev->mem_resource[0].len;
 	if (reg_off >= pci_len) {
 		printf("Port %d: register offset %u (0x%X) out of port PCI "
 		       "resource (length=%"PRIu64")\n",
@@ -607,9 +624,10 @@ port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
 {
 	uint32_t reg_v;
 
-
 	if (port_id_is_invalid(port_id, ENABLED_WARN))
 		return;
+	if (port_is_not_pci(port_id))
+		return;
 	if (port_reg_off_is_invalid(port_id, reg_off))
 		return;
 	if (reg_bit_pos_is_invalid(bit_x))
@@ -629,6 +647,8 @@ port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
 
 	if (port_id_is_invalid(port_id, ENABLED_WARN))
 		return;
+	if (port_is_not_pci(port_id))
+		return;
 	if (port_reg_off_is_invalid(port_id, reg_off))
 		return;
 	if (reg_bit_pos_is_invalid(bit1_pos))
@@ -658,6 +678,8 @@ port_reg_display(portid_t port_id, uint32_t reg_off)
 		return;
 	if (port_reg_off_is_invalid(port_id, reg_off))
 		return;
+	if (port_is_not_pci(port_id))
+		return;
 	reg_v = port_id_pci_reg_read(port_id, reg_off);
 	display_port_reg_value(port_id, reg_off, reg_v);
 }
@@ -670,6 +692,8 @@ port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
 
 	if (port_id_is_invalid(port_id, ENABLED_WARN))
 		return;
+	if (port_is_not_pci(port_id))
+		return;
 	if (port_reg_off_is_invalid(port_id, reg_off))
 		return;
 	if (reg_bit_pos_is_invalid(bit_pos))
@@ -698,6 +722,8 @@ port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
 
 	if (port_id_is_invalid(port_id, ENABLED_WARN))
 		return;
+	if (port_is_not_pci(port_id))
+		return;
 	if (port_reg_off_is_invalid(port_id, reg_off))
 		return;
 	if (reg_bit_pos_is_invalid(bit1_pos))
@@ -732,6 +758,8 @@ port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
 {
 	if (port_id_is_invalid(port_id, ENABLED_WARN))
 		return;
+	if (port_is_not_pci(port_id))
+		return;
 	if (port_reg_off_is_invalid(port_id, reg_off))
 		return;
 	port_id_pci_reg_write(port_id, reg_off, reg_v);
app/test-pmd/testpmd.c +9 -2
index a0332c26..faf1e16d 100644
@@ -492,7 +492,6 @@ static void
 init_config(void)
 {
 	portid_t pid;
-	struct rte_port *port;
 	struct rte_mempool *mbp;
 	unsigned int nb_mbuf_per_pool;
 	lcoreid_t  lc_id;
@@ -547,9 +546,17 @@ init_config(void)
 	}
 
 	FOREACH_PORT(pid, ports) {
-		port = &ports[pid];
+		struct rte_port *port = &ports[pid];
+		struct rte_device *dev;
+
 		rte_eth_dev_info_get(pid, &port->dev_info);
 
+		dev = port->dev_info.device;
+		if (dev->driver->type == PMD_PCI)
+			port->pci_dev = container_of(dev, struct rte_pci_device, device);
+		else
+			port->pci_dev = NULL;
+
 		if (numa_support) {
 			if (port_numa[pid] != NUMA_NO_CONFIG)
 				port_per_socket[port_numa[pid]]++;
app/test-pmd/testpmd.h +18 -14
index 9c1e7039..e8aca32a 100644
@@ -149,6 +149,7 @@ struct fwd_stream {
  */
 struct rte_port {
 	uint8_t                 enabled;    /**< Port enabled or not */
+	struct rte_pci_device	*pci_dev;
 	struct rte_eth_dev_info dev_info;   /**< PCI info + driver name */
 	struct rte_eth_conf     dev_conf;   /**< Port configuration. */
 	struct ether_addr       eth_addr;   /**< Port ethernet address */
@@ -442,34 +443,36 @@ mbuf_pool_find(unsigned int sock_id)
  * Read/Write operations on a PCI register of a port.
  */
 static inline uint32_t
-port_pci_reg_read(struct rte_port *port, uint32_t reg_off)
+pci_reg_read(struct rte_pci_device *pci_dev, uint32_t reg_off)
 {
-	void *reg_addr;
+	void *reg_addr
+		= (char *)pci_dev->mem_resource[0].addr + reg_off;
 	uint32_t reg_v;
 
-	reg_addr = (void *)
-		((char *)port->dev_info.pci_dev->mem_resource[0].addr +
-			reg_off);
 	reg_v = *((volatile uint32_t *)reg_addr);
 	return rte_le_to_cpu_32(reg_v);
 }
 
-#define port_id_pci_reg_read(pt_id, reg_off) \
-	port_pci_reg_read(&ports[(pt_id)], (reg_off))
+static inline uint32_t
+port_id_pci_reg_read(portid_t pt_id, uint32_t reg_off)
+{
+	return pci_reg_read(ports[pt_id].pci_dev, reg_off);
+}
 
 static inline void
-port_pci_reg_write(struct rte_port *port, uint32_t reg_off, uint32_t reg_v)
+pci_reg_write(struct rte_pci_device *pci_dev, uint32_t reg_off, uint32_t reg_v)
 {
-	void *reg_addr;
+	void *reg_addr
+		= (char *)pci_dev->mem_resource[0].addr + reg_off;
 
-	reg_addr = (void *)
-		((char *)port->dev_info.pci_dev->mem_resource[0].addr +
-			reg_off);
 	*((volatile uint32_t *)reg_addr) = rte_cpu_to_le_32(reg_v);
 }
 
-#define port_id_pci_reg_write(pt_id, reg_off, reg_value) \
-	port_pci_reg_write(&ports[(pt_id)], (reg_off), (reg_value))
+static inline void
+port_id_pci_reg_write(portid_t pt_id, uint32_t reg_off, uint32_t reg_v)
+{
+	return pci_reg_write(ports[pt_id].pci_dev, reg_off, reg_v);
+}
 
 /* Prototypes */
 unsigned int parse_item_list(char* str, const char* item_name,
@@ -598,6 +601,7 @@ enum print_warning {
 	ENABLED_WARN = 0,
 	DISABLED_WARN
 };
+int port_is_not_pci(portid_t port_id);
 int port_id_is_invalid(portid_t port_id, enum print_warning warning);
 
 /*
app/test/test_kni.c +33 -6
index 309741cb..6b2ebbed 100644
@@ -370,6 +370,8 @@ test_kni_processing(uint8_t port_id, struct rte_mempool *mp)
 	struct rte_kni_conf conf;
 	struct rte_eth_dev_info info;
 	struct rte_kni_ops ops;
+	struct rte_device *dev;
+	struct rte_pci_device *pci_dev;
 
 	if (!mp)
 		return -1;
@@ -379,8 +381,16 @@ test_kni_processing(uint8_t port_id, struct rte_mempool *mp)
 	memset(&ops, 0, sizeof(ops));
 
 	rte_eth_dev_info_get(port_id, &info);
-	conf.addr = info.pci_dev->addr;
-	conf.id = info.pci_dev->id;
+
+	dev = info.device;
+	if (dev->driver->type != PMD_PCI) {
+		printf("device is not PCI\n");
+		return -1;
+	}
+
+	pci_dev = container_of(dev, struct rte_pci_device, device);
+	conf.addr = pci_dev->addr;
+	conf.id = pci_dev->id;
 	snprintf(conf.name, sizeof(conf.name), TEST_KNI_PORT);
 
 	/* core id 1 configured for kernel thread */
@@ -478,6 +488,8 @@ test_kni(void)
 	struct rte_kni_conf conf;
 	struct rte_eth_dev_info info;
 	struct rte_kni_ops ops;
+	struct rte_device *dev;
+	struct rte_pci_device *pci_dev;
 
 	/* Initialize KNI subsytem */
 	rte_kni_init(KNI_TEST_MAX_PORTS);
@@ -536,8 +548,16 @@ test_kni(void)
 	memset(&conf, 0, sizeof(conf));
 	memset(&ops, 0, sizeof(ops));
 	rte_eth_dev_info_get(port_id, &info);
-	conf.addr = info.pci_dev->addr;
-	conf.id = info.pci_dev->id;
+
+	dev = info.device;
+	if (dev->driver->type != PMD_PCI) {
+		printf("device is not PCI\n");
+		return -1;
+	}
+
+	pci_dev = container_of(dev, struct rte_pci_device, device);
+	conf.addr = pci_dev->addr;
+	conf.id = pci_dev->id;
 	conf.group_id = (uint16_t)port_id;
 	conf.mbuf_size = MAX_PACKET_SZ;
 
@@ -565,8 +585,15 @@ test_kni(void)
 	memset(&info, 0, sizeof(info));
 	memset(&ops, 0, sizeof(ops));
 	rte_eth_dev_info_get(port_id, &info);
-	conf.addr = info.pci_dev->addr;
-	conf.id = info.pci_dev->id;
+	dev = info.device;
+	if (dev->driver->type != PMD_PCI) {
+		printf("device is not PCI\n");
+		return -1;
+	}
+
+	pci_dev = container_of(dev, struct rte_pci_device, device);
+	conf.addr = pci_dev->addr;
+	conf.id = pci_dev->id;
 	conf.group_id = (uint16_t)port_id;
 	conf.mbuf_size = MAX_PACKET_SZ;
 
doc/guides/rel_notes/release_17_02.rst +3 -7
index 3b650388..30b23703 100644
@@ -106,16 +106,12 @@ API Changes
 ABI Changes
 -----------
 
-.. This section should contain ABI changes. Sample format:
-
-   * Add a short 1-2 sentence description of the ABI change that was announced in
+.. * Add a short 1-2 sentence description of the ABI change that was announced in
      the previous releases and made in this release. Use fixed width quotes for
      ``rte_function_names`` or ``rte_struct_names``. Use the past tense.
 
-   This section is a comment. do not overwrite or remove it.
-   Also, make sure to start the actual text at the margin.
-   =========================================================
-
+* The ``rte_eth_dev_info`` structure no longer has pointer to PCI device, but
+  instead has new_field ``device`` which is a pointer to a generic ethernet device.
 
 
 Shared Library Versions
lib/librte_ether/rte_ethdev.c +2 -1
index 1e0f2061..71a8e9b9 100644
@@ -1568,7 +1568,8 @@ 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->device = &dev->pci_dev->device;
 	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;
lib/librte_ether/rte_ethdev.h +1 -1
index 3c85e331..2b3b4014 100644
@@ -879,7 +879,7 @@ struct rte_eth_conf {
  * Ethernet device information
  */
 struct rte_eth_dev_info {
-	struct rte_pci_device *pci_dev; /**< Device PCI information. */
+	struct rte_device *device; /**< Device information. */
 	const char *driver_name; /**< Device Driver name. */
 	unsigned int if_index; /**< Index to bound host interface, or 0 if none.
 		Use if_indextoname() to translate into an interface name. */
Signature · 1 line
2.11.0
#17 lore raw

PATCH v2 7/13 e1000: localize mapping from eth_dev to pci

In reply to Stephen Hemminger

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

---
 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(-)
drivers/net/e1000/e1000_ethdev.h +2 -0
index 6c25c8da..134f8b91 100644
@@ -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
  */
drivers/net/e1000/em_ethdev.c +28 -22

143 lines not on this page · raw message

drivers/net/e1000/igb_ethdev.c +54 -45

289 lines not on this page · raw message

drivers/net/e1000/igb_pf.c +3 -1
index 5845bc22..67da3c24 100644
@@ -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
Signature · 1 line
2.11.0
#18 lore raw

PATCH v2 8/13 ixgbe: localize mapping from eth_dev to pci_device

In reply to Stephen Hemminger

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

---
 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(-)
drivers/net/ixgbe/ixgbe_ethdev.c +68 -52
index edc9b22c..2d057513 100644
@@ -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;
 	}
 
drivers/net/ixgbe/ixgbe_ethdev.h +3 -0
index 4ff6338e..a0e02aab 100644
@@ -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)
 
drivers/net/ixgbe/ixgbe_pf.c +3 -1
index 26395e41..cb102654 100644
@@ -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
Signature · 1 line
2.11.0
#19 lore raw

PATCH v2 9/13 i40e: localize mapping of eth_dev to pci

In reply to Stephen Hemminger

Simplify later changes to eth_dev.

---
 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(-)
drivers/net/i40e/i40e_ethdev.c +47 -30
index 67778baf..ba5795e3 100644
@@ -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;
 
drivers/net/i40e/i40e_ethdev.h +3 -0
index 298cef48..da8dd7ef 100644
@@ -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)
drivers/net/i40e/i40e_ethdev_vf.c +33 -25

144 lines not on this page · raw message

Signature · 1 line
2.11.0
#20 lore raw

PATCH v2 10/13 virtio: localize mapping from rte_eth to pci

In reply to Stephen Hemminger

Use one function to get mapping from rte_eth_dev to pci_device. Safely handle some possible misconfiguration of virtio_user related to link state interrupt.

---
 drivers/net/virtio/virtio_ethdev.c | 90 ++++++++++++++++++++++++++------------
 1 file changed, 63 insertions(+), 27 deletions(-)
drivers/net/virtio/virtio_ethdev.c +63 -27
index 079fd6c8..4db4568a 100644
@@ -152,6 +152,20 @@ static const struct rte_virtio_xstats_name_off rte_virtio_txq_stat_strings[] = {
 #define VIRTIO_NB_TXQ_XSTATS (sizeof(rte_virtio_txq_stat_strings) / \
 			    sizeof(rte_virtio_txq_stat_strings[0]))
 
+static inline struct rte_pci_device *
+virtio_dev_to_pci(struct rte_eth_dev *eth_dev)
+{
+	return eth_dev->pci_dev;
+}
+
+static inline struct rte_intr_handle *
+virtio_dev_to_intr_handle(struct rte_eth_dev *eth_dev)
+{
+	struct rte_pci_device *pci_dev	= virtio_dev_to_pci(eth_dev);
+
+	return pci_dev ? &pci_dev->intr_handle : NULL;
+}
+
 static int
 virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
 		int *dlen, int pkt_num)
@@ -1151,7 +1165,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 *intr_handle,
 			 void *param)
 {
 	struct rte_eth_dev *dev = param;
@@ -1162,7 +1176,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(intr_handle) < 0)
 		PMD_DRV_LOG(ERR, "interrupt enable failed");
 
 	if (isr & VIRTIO_PCI_ISR_CONFIG) {
@@ -1190,7 +1204,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;
 	int ret;
 
 	/* Reset the device although not necessary at startup */
@@ -1210,7 +1224,9 @@ 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);
+	pci_dev = virtio_dev_to_pci(eth_dev);
+	if (pci_dev)
+		rte_eth_copy_pci_info(eth_dev, pci_dev);
 
 	rx_func_get(eth_dev);
 
@@ -1278,10 +1294,9 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 		return ret;
 	vtpci_reinit_complete(hw);
 
-	if (pci_dev)
-		PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
-			eth_dev->data->port_id, pci_dev->id.vendor_id,
-			pci_dev->id.device_id);
+	PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
+		     eth_dev->data->port_id, pci_dev->id.vendor_id,
+		     pci_dev->id.device_id);
 
 	return 0;
 }
@@ -1294,7 +1309,7 @@ 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;
+	struct rte_pci_device *pci_dev = virtio_dev_to_pci(eth_dev);
 	uint32_t dev_flags = RTE_ETH_DEV_DETACHABLE;
 	int ret;
 
@@ -1317,8 +1332,6 @@ 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);
 		if (ret)
@@ -1333,9 +1346,19 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 		return ret;
 
 	/* Setup interrupt callback  */
-	if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
-		rte_intr_callback_register(&pci_dev->intr_handle,
-			virtio_interrupt_handler, eth_dev);
+	if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC) {
+		struct rte_intr_handle *intr_handle
+			= virtio_dev_to_intr_handle(eth_dev);
+
+		if (!intr_handle) {
+			PMD_INIT_LOG(ERR,
+				     "Link state option not valid without pci");
+			return -EINVAL;
+		}
+
+		rte_intr_callback_register(intr_handle,
+					   virtio_interrupt_handler, eth_dev);
+	}
 
 	return 0;
 }
@@ -1343,7 +1366,7 @@ 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 rte_pci_device *pci_dev = virtio_dev_to_pci(eth_dev);
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -1352,7 +1375,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;
@@ -1362,11 +1384,18 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
 	eth_dev->data->mac_addrs = NULL;
 
 	/* reset interrupt callback  */
-	if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
-		rte_intr_callback_unregister(&pci_dev->intr_handle,
-						virtio_interrupt_handler,
-						eth_dev);
-	rte_eal_pci_unmap_device(pci_dev);
+	if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC) {
+		struct rte_intr_handle *intr_handle
+			= virtio_dev_to_intr_handle(eth_dev);
+
+		if (intr_handle)
+			rte_intr_callback_unregister(intr_handle,
+						     virtio_interrupt_handler,
+						     eth_dev);
+	}
+
+	if (pci_dev)
+		rte_eal_pci_unmap_device(pci_dev);
 
 	PMD_INIT_LOG(DEBUG, "dev_uninit completed");
 
@@ -1476,12 +1505,20 @@ virtio_dev_start(struct rte_eth_dev *dev)
 
 	/* check if lsc interrupt feature is enabled */
 	if (dev->data->dev_conf.intr_conf.lsc) {
+		struct rte_intr_handle *intr_handle
+			= virtio_dev_to_intr_handle(dev);
+
+		if (!intr_handle) {
+			PMD_DRV_LOG(ERR, "link status not supported by bus");
+			return -ENOTSUP;
+		}
+
 		if (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)) {
 			PMD_DRV_LOG(ERR, "link status not supported by host");
 			return -ENOTSUP;
 		}
 
-		if (rte_intr_enable(&dev->pci_dev->intr_handle) < 0) {
+		if (rte_intr_enable(intr_handle) < 0) {
 			PMD_DRV_LOG(ERR, "interrupt enable failed");
 			return -EIO;
 		}
@@ -1573,12 +1610,13 @@ static void virtio_dev_free_mbufs(struct rte_eth_dev *dev)
 static void
 virtio_dev_stop(struct rte_eth_dev *dev)
 {
+	struct rte_intr_handle *intr_handle = virtio_dev_to_intr_handle(dev);
 	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);
+	if (dev->data->dev_conf.intr_conf.lsc && intr_handle)
+		rte_intr_disable(intr_handle);
 
 	memset(&link, 0, sizeof(link));
 	virtio_dev_atomic_write_link_status(dev, &link);
@@ -1624,9 +1662,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;
 
-	if (dev->pci_dev)
-		dev_info->driver_name = dev->driver->pci_drv.driver.name;
-	else
+	if (!dev->pci_dev)
 		dev_info->driver_name = "virtio_user PMD";
 	dev_info->max_rx_queues =
 		RTE_MIN(hw->max_queue_pairs, VIRTIO_MAX_RX_QUEUES);
Signature · 1 line
2.11.0
#21 lore raw

PATCH v2 11/13 broadcom: localize mapping from eth_dev to pci

In reply to Stephen Hemminger

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

---
 drivers/net/bnxt/bnxt_ethdev.c | 22 +++++++++++++---------
 drivers/net/bnxt/bnxt_ring.c   | 16 ++++++----------
 2 files changed, 19 insertions(+), 19 deletions(-)
drivers/net/bnxt/bnxt_ethdev.c +13 -9
index 035fe07a..529b6c86 100644
@@ -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;
 
drivers/net/bnxt/bnxt_ring.c +6 -10
index 3f81ffcc..0fafa13f 100644
@@ -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;
 	}
 
Signature · 1 line
2.11.0
#22 lore raw

PATCH v2 12/13 ethdev: change pci_dev to generic device

In reply to Stephen Hemminger

The rte_eth_dev structure had a long standing assumption that all devices were either virtual or associated with PCI. This is not so going forward with SOC and VMBUS.

---
 app/test/virtual_pmd.c                  |  3 +-
 drivers/net/bnxt/bnxt_ethdev.c          |  6 ++-
 drivers/net/bonding/rte_eth_bond_args.c | 12 ++---
 drivers/net/cxgbe/cxgbe_ethdev.c        |  2 +-
 drivers/net/cxgbe/cxgbe_main.c          |  5 +-
 drivers/net/e1000/e1000_ethdev.h        |  2 +-
 drivers/net/ena/ena_ethdev.c            |  2 +-
 drivers/net/enic/enic_ethdev.c          |  2 +-
 drivers/net/enic/enic_rxtx.c            |  2 -
 drivers/net/fm10k/fm10k_ethdev.c        | 90 ++++++++++++++++++++-------------
 drivers/net/i40e/i40e_ethdev.h          |  2 +-
 drivers/net/i40e/i40e_ethdev_vf.c       |  1 +
 drivers/net/ixgbe/ixgbe_ethdev.h        |  2 +-
 drivers/net/qede/qede_ethdev.c          | 24 +++++----
 drivers/net/qede/qede_ethdev.h          |  4 ++
 drivers/net/virtio/virtio_ethdev.c      |  9 ++--
 drivers/net/virtio/virtio_user_ethdev.c |  2 +-
 drivers/net/vmxnet3/vmxnet3_ethdev.c    |  3 +-
 lib/librte_ether/rte_ethdev.c           | 23 ++++++---
 lib/librte_ether/rte_ethdev.h           |  8 +--
 20 files changed, 123 insertions(+), 81 deletions(-)
app/test/virtual_pmd.c +1 -2
index e0447fda..16ab24e0 100644
@@ -624,8 +624,7 @@ 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;
+	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;
drivers/net/bnxt/bnxt_ethdev.c +4 -2
index 529b6c86..fed2c205 100644
@@ -1012,7 +1012,8 @@ 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 =
+		container_of((eth_dev)->device, struct rte_pci_device, device);
 	int rc;
 
 	/* enable device (incl. PCI PM wakeup), and bus-mastering */
@@ -1046,7 +1047,8 @@ 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 =
+		container_of((eth_dev)->device, struct rte_pci_device, device);
 	static int version_printed;
 	struct bnxt *bp;
 	int rc;
drivers/net/bonding/rte_eth_bond_args.c +5 -7
index 02ecde64..c5c7f153 100644
@@ -54,20 +54,18 @@ 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_addr *eth_pci_addr;
 	unsigned i;
 
 	for (i = 0; i < rte_eth_dev_count(); i++) {
+		struct rte_device *dev = rte_eth_devices[i].device;
+		struct rte_pci_device *pdev;
 
-		if (rte_eth_devices[i].pci_dev == NULL)
+		if (dev == NULL || dev->driver->type != PMD_PCI)
 			continue;
 
-		eth_pci_addr = &(rte_eth_devices[i].pci_dev->addr);
+		pdev = container_of(dev, struct rte_pci_device, device);
 
-		if (pci_addr->bus == eth_pci_addr->bus &&
-			pci_addr->devid == eth_pci_addr->devid &&
-			pci_addr->domain == eth_pci_addr->domain &&
-			pci_addr->function == eth_pci_addr->function)
+		if (rte_eal_compare_pci_addr(pci_addr, &pdev->addr) == 0)
 			return i;
 	}
 	return -1;
drivers/net/cxgbe/cxgbe_ethdev.c +1 -1
index b7f28ebb..4fa09fa9 100644
@@ -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 = container_of(eth_dev->device, struct rte_pci_device, device);
 
 	snprintf(name, sizeof(name), "cxgbeadapter%d", eth_dev->data->port_id);
 	adapter = rte_zmalloc(name, sizeof(*adapter), 0);
drivers/net/cxgbe/cxgbe_main.c +3 -2
index 922155b4..237cae37 100644
@@ -1071,6 +1071,7 @@ void cxgbe_close(struct adapter *adapter)
 
 int cxgbe_probe(struct adapter *adapter)
 {
+	struct rte_pci_device *pci_dev = adapter->pdev;
 	struct port_info *pi;
 	int func, i;
 	int err = 0;
@@ -1163,14 +1164,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 = &pci_dev->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, pci_dev);
 
 		TAILQ_INIT(&pi->eth_dev->link_intr_cbs);
 
drivers/net/e1000/e1000_ethdev.h +1 -1
index 134f8b91..e034ddc3 100644
@@ -287,7 +287,7 @@ struct e1000_adapter {
 	(&((struct e1000_adapter *)adapter)->filter)
 
 #define E1000_DEV_TO_PCI(eth_dev) \
-	(eth_dev->pci_dev)
+	container_of((eth_dev)->device, struct rte_pci_device, device)
 /*
  * RX/TX IGB function prototypes
  */
drivers/net/ena/ena_ethdev.c +1 -1
index ab9a178f..46d6a5f2 100644
@@ -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 = container_of(eth_dev->device, struct rte_pci_device, device);
 	adapter->pdev = pci_dev;
 
 	PMD_INIT_LOG(INFO, "Initializing %x:%x:%x.%d\n",
drivers/net/enic/enic_ethdev.c +1 -1
index 2b154ec2..9e5d21a1 100644
@@ -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 = container_of(eth_dev->device, struct rte_pci_device, device);
 	rte_eth_copy_pci_info(eth_dev, pdev);
 	enic->pdev = pdev;
 	addr = &pdev->addr;
drivers/net/enic/enic_rxtx.c +0 -2
index f762a26c..09ad6251 100644
@@ -557,5 +557,3 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 
 	return index;
 }
-
-
drivers/net/fm10k/fm10k_ethdev.c +55 -35

260 lines not on this page · raw message

drivers/net/i40e/i40e_ethdev.h +1 -1
index da8dd7ef..5a6a4e05 100644
@@ -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)
+	container_of((eth_dev)->device, struct rte_pci_device, device)
 
 /* I40E_DEV_PRIVATE_TO */
 #define I40E_DEV_PRIVATE_TO_PF(adapter) \
drivers/net/i40e/i40e_ethdev_vf.c +1 -0
index a4d8a66e..c177d2e8 100644
@@ -64,6 +64,7 @@
 #include "base/i40e_adminq_cmd.h"
 #include "base/i40e_type.h"
 
+
 #include "i40e_rxtx.h"
 #include "i40e_ethdev.h"
 #include "i40e_pf.h"
drivers/net/ixgbe/ixgbe_ethdev.h +1 -1
index a0e02aab..cbfd8b0f 100644
@@ -292,7 +292,7 @@ struct ixgbe_adapter {
 };
 
 #define IXGBE_DEV_TO_PCI(eth_dev) \
-	(eth_dev->pci_dev)
+	container_of((eth_dev)->device, struct rte_pci_device, device)
 
 #define IXGBE_DEV_PRIVATE_TO_HW(adapter)\
 	(&((struct ixgbe_adapter *)adapter)->hw)
drivers/net/qede/qede_ethdev.c +14 -10
index d106dd0f..b1ff6989 100644
@@ -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 *intr_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(intr_handle))
 		DP_ERR(edev, "rte_intr_enable failed\n");
 }
 
@@ -809,6 +809,8 @@ static void qede_poll_sp_sb_cb(void *param)
 
 static void qede_dev_close(struct rte_eth_dev *eth_dev)
 {
+	struct rte_pci_device *pdev = QEDE_INIT_PDEV(eth_dev);
+	struct rte_intr_handle *intr_handle = &pdev->intr_handle;
 	struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
 	struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
 	int rc;
@@ -835,10 +837,10 @@ 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(intr_handle);
 
-	rte_intr_callback_unregister(&eth_dev->pci_dev->intr_handle,
-				     qede_interrupt_handler, (void *)eth_dev);
+	rte_intr_callback_unregister(intr_handle,
+				     qede_interrupt_handler, eth_dev);
 
 	if (edev->num_hwfns > 1)
 		rte_eal_alarm_cancel(qede_poll_sp_sb_cb, (void *)eth_dev);
@@ -1383,6 +1385,7 @@ static void qede_update_pf_params(struct ecore_dev *edev)
 
 static int qede_common_dev_init(struct rte_eth_dev *eth_dev, bool is_vf)
 {
+	struct rte_intr_handle *intr_handle;
 	struct rte_pci_device *pci_dev;
 	struct rte_pci_addr pci_addr;
 	struct qede_dev *adapter;
@@ -1401,9 +1404,11 @@ static int qede_common_dev_init(struct rte_eth_dev *eth_dev, bool is_vf)
 	int rc;
 
 	/* Extract key data structures */
+	pci_dev = QEDE_INIT_PDEV(eth_dev);
+	intr_handle = &pci_dev->intr_handle;
 	adapter = eth_dev->data->dev_private;
 	edev = &adapter->edev;
-	pci_addr = eth_dev->pci_dev->addr;
+	pci_addr = pci_dev->addr;
 
 	PMD_INIT_FUNC_TRACE(edev);
 
@@ -1420,7 +1425,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);
 
@@ -1442,10 +1446,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,
-				   qede_interrupt_handler, (void *)eth_dev);
+	rte_intr_callback_register(intr_handle,
+				   qede_interrupt_handler, eth_dev);
 
-	if (rte_intr_enable(&eth_dev->pci_dev->intr_handle)) {
+	if (rte_intr_enable(intr_handle)) {
 		DP_ERR(edev, "rte_intr_enable() failed\n");
 		return -ENODEV;
 	}
drivers/net/qede/qede_ethdev.h +4 -0
index a97e3d96..454eae63 100644
@@ -80,6 +80,10 @@
 #define QEDE_SUPPORTED_AUTONEG (1 << 6)
 #define QEDE_SUPPORTED_PAUSE   (1 << 13)
 
+
+#define QEDE_INIT_PDEV(eth_dev) \
+	container_of((eth_dev)->device, struct rte_pci_device, device)
+
 #define QEDE_INIT_QDEV(eth_dev) (eth_dev->data->dev_private)
 
 #define QEDE_INIT_EDEV(adapter) (&((struct qede_dev *)adapter)->edev)
drivers/net/virtio/virtio_ethdev.c +6 -3
index 4db4568a..21022cf3 100644
@@ -155,7 +155,9 @@ static const struct rte_virtio_xstats_name_off rte_virtio_txq_stat_strings[] = {
 static inline struct rte_pci_device *
 virtio_dev_to_pci(struct rte_eth_dev *eth_dev)
 {
-	return eth_dev->pci_dev;
+	struct rte_device *dev = eth_dev->device;
+
+	return dev ? container_of(dev, struct rte_pci_device, device) : NULL;
 }
 
 static inline struct rte_intr_handle *
@@ -501,7 +503,8 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 	 * 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 (dev->device)
 		vq->offset = offsetof(struct rte_mbuf, buf_physaddr);
 	else {
 		vq->vq_ring_mem = (uintptr_t)mz->addr;
@@ -1662,7 +1665,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;
 
-	if (!dev->pci_dev)
+	if (!dev->device)
 		dev_info->driver_name = "virtio_user PMD";
 	dev_info->max_rx_queues =
 		RTE_MIN(hw->max_queue_pairs, VIRTIO_MAX_RX_QUEUES);
drivers/net/virtio/virtio_user_ethdev.c +1 -1
index 406beeac..293078e3 100644
@@ -310,7 +310,7 @@ 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->device = NULL;
 	eth_dev->driver = NULL;
 	return eth_dev;
 }
drivers/net/vmxnet3/vmxnet3_ethdev.c +2 -1
index 8bb13e52..ae6d081f 100644
@@ -237,7 +237,8 @@ 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 = container_of(eth_dev->device, struct rte_pci_device, device);
+
 
 	/*
 	 * for secondary processes, we don't initialize any further as primary
lib/librte_ether/rte_ethdev.c +17 -6
index 71a8e9b9..3f7dc79e 100644
@@ -257,7 +257,8 @@ 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->driver = eth_drv;
 	eth_dev->data->rx_mbuf_alloc_failed = 0;
 
@@ -317,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;
 
@@ -1569,7 +1570,7 @@ 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->device = &dev->pci_dev->device;
+	dev_info->device = dev->device;
 	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;
@@ -2550,6 +2551,7 @@ rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
 {
 	uint32_t vec;
 	struct rte_eth_dev *dev;
+	struct rte_pci_device *pci_dev;
 	struct rte_intr_handle *intr_handle;
 	uint16_t qid;
 	int rc;
@@ -2557,7 +2559,11 @@ 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->device->driver->type != PMD_PCI)
+		return -ENOTSUP;
+
+	pci_dev = container_of(dev->device, struct rte_pci_device, device);
+	intr_handle = &pci_dev->intr_handle;
 	if (!intr_handle->intr_vec) {
 		RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
 		return -EPERM;
@@ -2606,6 +2612,7 @@ rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
 {
 	uint32_t vec;
 	struct rte_eth_dev *dev;
+	struct rte_pci_device *pci_dev;
 	struct rte_intr_handle *intr_handle;
 	int rc;
 
@@ -2617,7 +2624,11 @@ 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->device->driver->type != PMD_PCI)
+		return -ENOTSUP;
+
+	pci_dev = container_of(dev->device, struct rte_pci_device, device);
+	intr_handle = &pci_dev->intr_handle;
 	if (!intr_handle->intr_vec) {
 		RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
 		return -EPERM;
@@ -3211,7 +3222,7 @@ rte_eth_dev_get_dcb_info(uint8_t port_id,
 }
 
 void
-rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
+rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, const struct rte_pci_device *pci_dev)
 {
 	if ((eth_dev == NULL) || (pci_dev == NULL)) {
 		RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
lib/librte_ether/rte_ethdev.h +4 -4
index 2b3b4014..f7e156eb 100644
@@ -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;   /**< Device info. supplied by probing */
 	/** User application callbacks for NIC interrupts */
 	struct rte_eth_dev_cb_list link_intr_cbs;
 	/**
@@ -1813,8 +1813,8 @@ struct eth_driver;
  *   The *eth_dev* structure is supplied to the driver initialization function
  *   with the following fields already initialized:
  *
- *   - *pci_dev*: Holds the pointers to the *rte_pci_device* structure which
- *     contains the generic PCI information of the matching device.
+ *   - *device*: Holds the pointers to the *rte_device* structure which
+ *     contains the generic device information of the matching device.
  *
  *   - *driver*: Holds the pointer to the *eth_driver* structure.
  *
@@ -4266,7 +4266,7 @@ int rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *time);
  *   - 0 on success, negative on error
  */
 void rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev,
-		struct rte_pci_device *pci_dev);
+			   const struct rte_pci_device *pci_dev);
 
 /**
  * Create memzone for HW rings.
Signature · 1 line
2.11.0
#23 lore raw

PATCH v2 13/13 hyperv: VMBUS support infrastucture

In reply to Stephen Hemminger

Generalize existing bus support to handle VMBUS in Hyper-V. Most of the code is based of existing model for PCI, the difference is how bus is represented in sysfs and how addressing works.

This is based on earlier code contributed by Brocade.

---
 lib/librte_eal/common/Makefile              |  2 +-
 lib/librte_eal/common/eal_common_devargs.c  |  7 +++
 lib/librte_eal/common/eal_common_options.c  | 38 ++++++++++++
 lib/librte_eal/common/eal_internal_cfg.h    |  3 +-
 lib/librte_eal/common/eal_options.h         |  6 ++
 lib/librte_eal/common/eal_private.h         |  5 ++
 lib/librte_eal/common/include/rte_devargs.h |  8 +++
 lib/librte_eal/linuxapp/eal/Makefile        |  6 ++
 lib/librte_eal/linuxapp/eal/eal.c           | 11 ++++
 lib/librte_ether/rte_ethdev.c               | 90 +++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.h               | 22 ++++++-
 mk/rte.app.mk                               |  1 +
 12 files changed, 196 insertions(+), 3 deletions(-)
lib/librte_eal/common/Makefile +1 -1
index a92c984b..9254bae4 100644
@@ -33,7 +33,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 
 INC := rte_branch_prediction.h rte_common.h
 INC += rte_debug.h rte_eal.h rte_errno.h rte_launch.h rte_lcore.h
-INC += rte_log.h rte_memory.h rte_memzone.h rte_pci.h
+INC += rte_log.h rte_memory.h rte_memzone.h rte_pci.h rte_vmbus.h
 INC += rte_per_lcore.h rte_random.h
 INC += rte_tailq.h rte_interrupts.h rte_alarm.h
 INC += rte_string_fns.h rte_version.h
lib/librte_eal/common/eal_common_devargs.c +7 -0
index e403717b..934ca840 100644
@@ -113,6 +113,13 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 			goto fail;
 
 		break;
+	case RTE_DEVTYPE_WHITELISTED_VMBUS:
+	case RTE_DEVTYPE_BLACKLISTED_VMBUS:
+#ifdef RTE_LIBRTE_HV_PMD
+		if (uuid_parse(buf, devargs->uuid) == 0)
+			break;
+#endif
+		goto fail;
 	}
 
 	free(buf);
lib/librte_eal/common/eal_common_options.c +38 -0
index 6ca8af17..6aea87d9 100644
@@ -95,6 +95,11 @@ eal_long_options[] = {
 	{OPT_VFIO_INTR,         1, NULL, OPT_VFIO_INTR_NUM        },
 	{OPT_VMWARE_TSC_MAP,    0, NULL, OPT_VMWARE_TSC_MAP_NUM   },
 	{OPT_XEN_DOM0,          0, NULL, OPT_XEN_DOM0_NUM         },
+#ifdef RTE_LIBRTE_HV_PMD
+	{OPT_NO_VMBUS,          0, NULL, OPT_NO_VMBUS_NUM         },
+	{OPT_VMBUS_BLACKLIST,   1, NULL, OPT_VMBUS_BLACKLIST_NUM  },
+	{OPT_VMBUS_WHITELIST,   1, NULL, OPT_VMBUS_WHITELIST_NUM  },
+#endif
 	{0,                     0, NULL, 0                        }
 };
 
@@ -855,6 +860,21 @@ eal_parse_common_option(int opt, const char *optarg,
 		conf->no_pci = 1;
 		break;
 
+#ifdef RTE_LIBRTE_HV_PMD
+	case OPT_NO_VMBUS_NUM:
+		conf->no_vmbus = 1;
+		break;
+	case OPT_VMBUS_BLACKLIST_NUM:
+		if (rte_eal_devargs_add(RTE_DEVTYPE_BLACKLISTED_VMBUS,
+					optarg) < 0)
+			return -1;
+		break;
+	case OPT_VMBUS_WHITELIST_NUM:
+		if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_VMBUS,
+				optarg) < 0)
+			return -1;
+		break;
+#endif
 	case OPT_NO_HPET_NUM:
 		conf->no_hpet = 1;
 		break;
@@ -987,6 +1007,14 @@ eal_check_common_options(struct internal_config *internal_cfg)
 		return -1;
 	}
 
+#ifdef RTE_LIBRTE_HV_PMD
+	if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_VMBUS) != 0 &&
+		rte_eal_devargs_type_count(RTE_DEVTYPE_BLACKLISTED_VMBUS) != 0) {
+		RTE_LOG(ERR, EAL, "Options vmbus blacklist and whitelist "
+			"cannot be used at the same time\n");
+		return -1;
+	}
+#endif
 	return 0;
 }
 
@@ -1036,5 +1064,15 @@ eal_common_usage(void)
 	       "  --"OPT_NO_PCI"            Disable PCI\n"
 	       "  --"OPT_NO_HPET"           Disable HPET\n"
 	       "  --"OPT_NO_SHCONF"         No shared config (mmap'd files)\n"
+#ifdef RTE_LIBRTE_HV_PMD
+	       "  --"OPT_NO_VMBUS"          Disable VMBUS\n"
+	       "  --"OPT_VMBUS_BLACKLIST" Add a VMBUS device to black list.\n"
+	       "                      Prevent EAL from using this PCI device. The argument\n"
+	       "                      format is device UUID.\n"
+	       "  --"OPT_VMBUS_WHITELIST" Add a VMBUS device to white list.\n"
+	       "                      Only use the specified VMBUS devices. The argument format\n"
+	       "                      is device UUID This option can be present\n"
+	       "                      several times (once per device).\n"
+#endif
 	       "\n", RTE_MAX_LCORE);
 }
lib/librte_eal/common/eal_internal_cfg.h +2 -1
index 5f1367eb..18271943 100644
@@ -69,7 +69,8 @@ struct internal_config {
 	volatile unsigned no_pci;         /**< true to disable PCI */
 	volatile unsigned no_hpet;        /**< true to disable HPET */
 	volatile unsigned vmware_tsc_map; /**< true to use VMware TSC mapping
-										* instead of native TSC */
+					   * instead of native TSC */
+	volatile unsigned no_vmbus;       /**< true to disable VMBUS */
 	volatile unsigned no_shconf;      /**< true if there is no shared config */
 	volatile unsigned create_uio_dev; /**< true to create /dev/uioX devices */
 	volatile enum rte_proc_type_t process_type; /**< multi-process proc type */
lib/librte_eal/common/eal_options.h +6 -0
index a881c62e..156727e7 100644
@@ -83,6 +83,12 @@ enum {
 	OPT_VMWARE_TSC_MAP_NUM,
 #define OPT_XEN_DOM0          "xen-dom0"
 	OPT_XEN_DOM0_NUM,
+#define OPT_NO_VMBUS          "no-vmbus"
+	OPT_NO_VMBUS_NUM,
+#define OPT_VMBUS_BLACKLIST   "vmbus-blacklist"
+	OPT_VMBUS_BLACKLIST_NUM,
+#define OPT_VMBUS_WHITELIST   "vmbus-whitelist"
+	OPT_VMBUS_WHITELIST_NUM,
 	OPT_LONG_MAX_NUM
 };
 
lib/librte_eal/common/eal_private.h +5 -0
index 9e7d8f6b..c856c63e 100644
@@ -210,6 +210,11 @@ int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
 		struct mapped_pci_resource *uio_res, int map_idx);
 
 /**
+ * VMBUS related functions and structures
+ */
+int rte_eal_vmbus_init(void);
+
+/**
  * Init tail queues for non-EAL library structures. This is to allow
  * the rings, mempools, etc. lists to be shared among multiple processes
  *
lib/librte_eal/common/include/rte_devargs.h +8 -0
index 88120a1c..c079d289 100644
@@ -51,6 +51,9 @@ extern "C" {
 #include <stdio.h>
 #include <sys/queue.h>
 #include <rte_pci.h>
+#ifdef RTE_LIBRTE_HV_PMD
+#include <uuid/uuid.h>
+#endif
 
 /**
  * Type of generic device
@@ -59,6 +62,8 @@ enum rte_devtype {
 	RTE_DEVTYPE_WHITELISTED_PCI,
 	RTE_DEVTYPE_BLACKLISTED_PCI,
 	RTE_DEVTYPE_VIRTUAL,
+	RTE_DEVTYPE_WHITELISTED_VMBUS,
+	RTE_DEVTYPE_BLACKLISTED_VMBUS,
 };
 
 /**
@@ -88,6 +93,9 @@ struct rte_devargs {
 			/** Driver name. */
 			char drv_name[32];
 		} virt;
+#ifdef RTE_LIBRTE_HV_PMD
+		uuid_t uuid;
+#endif
 	};
 	/** Arguments string as given by user or "" for no argument. */
 	char *args;
lib/librte_eal/linuxapp/eal/Makefile +6 -0
index 4e206f09..f6ca3848 100644
@@ -71,6 +71,11 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c
 
+ifeq ($(CONFIG_RTE_LIBRTE_HV_PMD),y)
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_vmbus.c
+LDLIBS += -luuid
+endif
+
 # from common dir
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_timer.c
@@ -114,6 +119,7 @@ CFLAGS_eal_hugepage_info.o := -D_GNU_SOURCE
 CFLAGS_eal_pci.o := -D_GNU_SOURCE
 CFLAGS_eal_pci_uio.o := -D_GNU_SOURCE
 CFLAGS_eal_pci_vfio.o := -D_GNU_SOURCE
+CFLAGS_eal_vmbux.o := -D_GNU_SOURCE
 CFLAGS_eal_common_whitelist.o := -D_GNU_SOURCE
 CFLAGS_eal_common_options.o := -D_GNU_SOURCE
 CFLAGS_eal_common_thread.o := -D_GNU_SOURCE
lib/librte_eal/linuxapp/eal/eal.c +11 -0
index 2075282e..71083ec5 100644
@@ -70,6 +70,7 @@
 #include <rte_cpuflags.h>
 #include <rte_interrupts.h>
 #include <rte_pci.h>
+#include <rte_vmbus.h>
 #include <rte_dev.h>
 #include <rte_devargs.h>
 #include <rte_common.h>
@@ -830,6 +831,11 @@ rte_eal_init(int argc, char **argv)
 
 	eal_check_mem_on_local_socket();
 
+#ifdef RTE_LIBRTE_HV_PMD
+	if (rte_eal_vmbus_init() < 0)
+		RTE_LOG(ERR, EAL, "Cannot init VMBUS\n");
+#endif
+
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
@@ -887,6 +893,11 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+#ifdef RTE_LIBRTE_HV_PMD
+	if (rte_eal_vmbus_probe() < 0)
+		rte_panic("Cannot probe VMBUS\n");
+#endif
+
 	rte_eal_mcfg_complete();
 
 	return fctret;
lib/librte_ether/rte_ethdev.c +90 -0

93 lines not on this page · raw message

lib/librte_ether/rte_ethdev.h +21 -1
index f7e156eb..00a70964 100644
@@ -180,6 +180,7 @@ extern "C" {
 #include <rte_log.h>
 #include <rte_interrupts.h>
 #include <rte_pci.h>
+#include <rte_vmbus.h>
 #include <rte_dev.h>
 #include <rte_devargs.h>
 #include "rte_ether.h"
@@ -1866,7 +1867,11 @@ typedef int (*eth_dev_uninit_t)(struct rte_eth_dev *eth_dev);
  * - The size of the private data to allocate for each matching device.
  */
 struct eth_driver {
-	struct rte_pci_driver pci_drv;    /**< The PMD is also a PCI driver. */
+	union {
+		struct rte_pci_driver pci_drv;    /**< The PMD PCI driver. */
+		struct rte_vmbus_driver vmbus_drv;/**< The PMD VMBUS drv. */
+	};
+
 	eth_dev_init_t eth_dev_init;      /**< Device init function. */
 	eth_dev_uninit_t eth_dev_uninit;  /**< Device uninit function. */
 	unsigned int dev_private_size;    /**< Size of device private data. */
@@ -4383,6 +4388,21 @@ int rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
  */
 int rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev);
 
+/**
+ * @internal
+ * Wrapper for use by vmbus drivers as a .probe function to attach to a ethdev
+ * interface.
+ */
+int rte_eth_dev_vmbus_probe(struct rte_vmbus_driver *vmbus_drv,
+			  struct rte_vmbus_device *vmbus_dev);
+
+/**
+ * @internal
+ * Wrapper for use by vmbus drivers as a .remove function to detach a ethdev
+ * interface.
+ */
+int rte_eth_dev_vmbus_remove(struct rte_vmbus_device *vmbus_dev);
+
 #ifdef __cplusplus
 }
 #endif
mk/rte.app.mk +1 -0
index f75f0e24..6b304084 100644
@@ -130,6 +130,7 @@ ifeq ($(CONFIG_RTE_LIBRTE_VHOST),y)
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_VHOST)      += -lrte_pmd_vhost
 endif # $(CONFIG_RTE_LIBRTE_VHOST)
 _LDLIBS-$(CONFIG_RTE_LIBRTE_VMXNET3_PMD)    += -lrte_pmd_vmxnet3_uio
+_LDLIBS-$(CONFIG_RTE_LIBRTE_HV_PMD)	    += -luuid
 
 ifeq ($(CONFIG_RTE_LIBRTE_CRYPTODEV),y)
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AESNI_MB)    += -lrte_pmd_aesni_mb
Signature · 1 line
2.11.0
#2 lore raw

Re: [PATCH 01/13] ethdev: increase length ethernet device internal name

In reply to Stephen Hemminger
Quoted 28 lines · Stephen Hemminger

Allow sufficicent space for UUID in string form (36+1). Needed to use UUID with Hyper-V

---
 doc/guides/rel_notes/deprecation.rst | 3 +++
 lib/librte_ether/rte_ethdev.h        | 6 +++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
doc/guides/rel_notes/deprecation.rst +3 -0
index 2d17bc6e..b83f23a1 100644
@@ -58,6 +58,9 @@ Deprecation Notices
   ``port`` field, may be moved or removed as part of this mbuf work. A
   ``timestamp`` will also be added.
 
+* ethdev: for 17.02 the size of internal device name will be increased
+  to 40 characters to allow for storing UUID.
+
 * The mbuf flags PKT_RX_VLAN_PKT and PKT_RX_QINQ_PKT are deprecated and
   are respectively replaced by PKT_RX_VLAN_STRIPPED and
   PKT_RX_QINQ_STRIPPED, that are better described. The old flags and
lib/librte_ether/rte_ethdev.h +0 -0
index 96781792..3c85e331 100644

lib/librte_ether/rte_ethdev.h struct rte_eth_dev_sriov { · line 1659

Quoted 9 lines
lib/librte_ether/rte_ethdev.h +5 -1
@@ -1652,7 +1652,11 @@ struct rte_eth_dev_sriov {
 };
 #define RTE_ETH_DEV_SRIOV(dev)         ((dev)->data->sriov)
 
-#define RTE_ETH_NAME_MAX_LEN (32)
+/*
+ * Internal identifier length
+ * Sufficiently large to allow for UUID or PCI address
+ */
+#define RTE_ETH_NAME_MAX_LEN 40

Just to clarify my doubt: UUID is 36 byte long. So, 4 extra bytes are to keep the name length 4 byte aligned (along with one byte of \0)?

Or, PCI based addressing can stretch 40 bytes?

Quoted 4 lines
lib/librte_ether/rte_ethdev.h +0 -0
 /**
  * @internal
 
#8 lore raw

Re: [PATCH 04/13] eal: introduce driver type

In reply to Stephen Hemminger
Quoted 13 lines · Stephen Hemminger

Since multiple buses and device types need to be supported. Provide type field in driver.

---
 lib/librte_eal/common/include/rte_dev.h  | 15 ++++++++++++---
 lib/librte_eal/common/include/rte_pci.h  |  1 +
 lib/librte_eal/common/include/rte_vdev.h |  1 +
 3 files changed, 14 insertions(+), 3 deletions(-)
lib/librte_eal/common/include/rte_dev.h +0 -0
index e5471a22..3f4e26e6 100644

lib/librte_eal/common/include/rte_dev.h void rte_eal_device_insert(struct rte_device *dev); · line 152

Quoted 9 lines
lib/librte_eal/common/include/rte_dev.h +6 -0
@@ -144,12 +144,21 @@ void rte_eal_device_insert(struct rte_device *dev);
 void rte_eal_device_remove(struct rte_device *dev);
 
 /**
+ * Type of device driver
+ */
+enum rte_driver_type {
+	PMD_VIRTUAL,
+	PMD_PCI,
+};

So the expectation is that if a new device type is introduced (anything other than virtual or PCI), this enum is expanded?

Broadly, we have two possible ways being discussed on ML for device relationship with PMD/APIs:

1. the way you have done: each device belongs to a particular type (enum rte_driver_type) and based on its type, operations would be performed on it (using conditional operators, for example). We continue to have a common device list containing all type of devices.

2. disassociating the device (rte_device) completely from its type and basing it on a Bus type. So, we have separate buses for each device type and hence no need for separation of logic based on device type.

I think implementation similar to (1) existed before it was removed in 6751f6de.

I have an (obvious) inclination towards (2) because that helps plugging in more drivers/device types without expecting the contributor to change the EAL - however trivial the change is.

Quoted 45 lines
lib/librte_eal/common/include/rte_dev.h +6 -3
+
+/**
  * A structure describing a device driver.
  */
 struct rte_driver {
 	TAILQ_ENTRY(rte_driver) next;  /**< Next in list. */
-	const char *name;                   /**< Driver name. */
-	const char *alias;              /**< Driver alias. */
+	const char *name;              /**< Driver name. */
+	const char *alias;             /**< Driver alias. */
+	enum rte_driver_type type;     /**< Driver type. */
 };
 
 /**
@@ -243,4 +252,4 @@ __attribute__((used)) = str
 }
 #endif
 
-#endif /* _RTE_VDEV_H_ */
+#endif /* _RTE_DEV_H_ */
lib/librte_eal/common/include/rte_pci.h +1 -0
index 9ce88472..d377d539 100644
@@ -492,6 +492,7 @@ RTE_INIT(pciinitfn_ ##nm); \
 static void pciinitfn_ ##nm(void) \
 {\
 	(pci_drv).driver.name = RTE_STR(nm);\
+	(pci_drv).driver.type = PMD_PCI; \
 	rte_eal_pci_register(&pci_drv); \
 } \
 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
lib/librte_eal/common/include/rte_vdev.h +1 -0
index 784e837d..98fb5bb5 100644
@@ -88,6 +88,7 @@ static void vdrvinitfn_ ##vdrv(void)\
 {\
 	(vdrv).driver.name = RTE_STR(nm);\
 	(vdrv).driver.alias = vdrvinit_ ## nm ## _alias;\
+	(vdrv).driver.type = PMD_VIRTUAL;\
 	rte_eal_vdrv_register(&vdrv);\
 } \
 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
Acked-by on v2 2/13
#5 lore raw

Re: [PATCH 02/13] rte_device: make driver pointer const

In reply to Stephen Hemminger
Quoted 20 lines · Stephen Hemminger

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

---
 lib/librte_eal/common/include/rte_dev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eal/common/include/rte_dev.h +1 -2
index 8840380d..e5471a22 100644
@@ -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 */
 };
--
Quoted 2 lines

2.11.0

Acked-by on v2 5/13
#14 lore raw

Re: [PATCH 05/13] pmd: remove useless reset of dev_info->dev_pci

In reply to Stephen Hemminger
Quoted 100 lines · Stephen Hemminger

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.

---
 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(-)
app/test/virtual_pmd.c +0 -1
index 65b44c64..e0447fda 100644
@@ -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
drivers/net/af_packet/rte_eth_af_packet.c +0 -1
index ff450685..2951f86c 100644
@@ -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
drivers/net/bonding/rte_eth_bond_pmd.c +0 -1
index a80b6fa9..74af6589 100644
@@ -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;
drivers/net/null/rte_eth_null.c +0 -1
index 836d982a..b4f253ad 100644
@@ -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;
 }
drivers/net/pcap/rte_eth_pcap.c +0 -1
index 0162f446..7253b9ad 100644
@@ -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
drivers/net/ring/rte_eth_ring.c +0 -1
index c1767c48..dc99a1fe 100644
@@ -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
drivers/net/xenvirt/rte_eth_xenvirt.c +0 -2
index c08a0568..609824b6 100644
@@ -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
--
Quoted 2 lines

2.11.0

#16 lore raw

Re: [PATCH 06/13] ethdev: make dev_info generic (not just PCI)

In reply to Stephen Hemminger
Quoted 325 lines · Stephen Hemminger

The result from rte_eth_dev_info_get should have pointer to device not PCI device. This breaks ABI but is necessary.

---
 app/test-pmd/config.c                  | 32 ++++++++++++++++++++++++++--
 app/test-pmd/testpmd.c                 | 11 ++++++++--
 app/test-pmd/testpmd.h                 | 32 ++++++++++++++++------------
 app/test/test_kni.c                    | 39 ++++++++++++++++++++++++++++------
 doc/guides/rel_notes/release_17_02.rst | 10 +++------
 lib/librte_ether/rte_ethdev.c          |  3 ++-
 lib/librte_ether/rte_ethdev.h          |  2 +-
 7 files changed, 96 insertions(+), 33 deletions(-)
app/test-pmd/config.c +30 -2
index 8cf537d5..1d0974ad 100644
@@ -553,6 +553,16 @@ port_id_is_invalid(portid_t port_id, enum print_warning warning)
        return 1;
 }
 
+int
+port_is_not_pci(portid_t port_id)
+{
+       if (ports[port_id].pci_dev)
+               return 0;
+
+       printf("Port %u is not a PCI device\n", port_id);
+       return 1;
+}
+
 static int
 vlan_id_is_invalid(uint16_t vlan_id)
 {
@@ -565,15 +575,22 @@ vlan_id_is_invalid(uint16_t vlan_id)
 static int
 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
 {
+       struct rte_pci_device *pci_dev = ports[port_id].pci_dev;
        uint64_t pci_len;
 
+       if (pci_dev == NULL) {
+               printf("Port %u is not a PCI device\n", port_id);
+               return 1;
+       }
+
        if (reg_off & 0x3) {
                printf("Port register offset 0x%X not aligned on a 4-byte "
                       "boundary\n",
                       (unsigned)reg_off);
                return 1;
        }
-       pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
+
+       pci_len = pci_dev->mem_resource[0].len;
        if (reg_off >= pci_len) {
                printf("Port %d: register offset %u (0x%X) out of port PCI "
                       "resource (length=%"PRIu64")\n",
@@ -607,9 +624,10 @@ port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
 {
        uint32_t reg_v;
 
-
        if (port_id_is_invalid(port_id, ENABLED_WARN))
                return;
+       if (port_is_not_pci(port_id))
+               return;
        if (port_reg_off_is_invalid(port_id, reg_off))
                return;
        if (reg_bit_pos_is_invalid(bit_x))
@@ -629,6 +647,8 @@ port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
 
        if (port_id_is_invalid(port_id, ENABLED_WARN))
                return;
+       if (port_is_not_pci(port_id))
+               return;
        if (port_reg_off_is_invalid(port_id, reg_off))
                return;
        if (reg_bit_pos_is_invalid(bit1_pos))
@@ -658,6 +678,8 @@ port_reg_display(portid_t port_id, uint32_t reg_off)
                return;
        if (port_reg_off_is_invalid(port_id, reg_off))
                return;
+       if (port_is_not_pci(port_id))
+               return;
        reg_v = port_id_pci_reg_read(port_id, reg_off);
        display_port_reg_value(port_id, reg_off, reg_v);
 }
@@ -670,6 +692,8 @@ port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
 
        if (port_id_is_invalid(port_id, ENABLED_WARN))
                return;
+       if (port_is_not_pci(port_id))
+               return;
        if (port_reg_off_is_invalid(port_id, reg_off))
                return;
        if (reg_bit_pos_is_invalid(bit_pos))
@@ -698,6 +722,8 @@ port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
 
        if (port_id_is_invalid(port_id, ENABLED_WARN))
                return;
+       if (port_is_not_pci(port_id))
+               return;
        if (port_reg_off_is_invalid(port_id, reg_off))
                return;
        if (reg_bit_pos_is_invalid(bit1_pos))
@@ -732,6 +758,8 @@ port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
 {
        if (port_id_is_invalid(port_id, ENABLED_WARN))
                return;
+       if (port_is_not_pci(port_id))
+               return;
        if (port_reg_off_is_invalid(port_id, reg_off))
                return;
        port_id_pci_reg_write(port_id, reg_off, reg_v);
app/test-pmd/testpmd.c +9 -2
index a0332c26..faf1e16d 100644
@@ -492,7 +492,6 @@ static void
 init_config(void)
 {
        portid_t pid;
-       struct rte_port *port;
        struct rte_mempool *mbp;
        unsigned int nb_mbuf_per_pool;
        lcoreid_t  lc_id;
@@ -547,9 +546,17 @@ init_config(void)
        }
 
        FOREACH_PORT(pid, ports) {
-               port = &ports[pid];
+               struct rte_port *port = &ports[pid];
+               struct rte_device *dev;
+
                rte_eth_dev_info_get(pid, &port->dev_info);
 
+               dev = port->dev_info.device;
+               if (dev->driver->type == PMD_PCI)
+                       port->pci_dev = container_of(dev, struct rte_pci_device, device);
+               else
+                       port->pci_dev = NULL;
+
                if (numa_support) {
                        if (port_numa[pid] != NUMA_NO_CONFIG)
                                port_per_socket[port_numa[pid]]++;
app/test-pmd/testpmd.h +18 -14
index 9c1e7039..e8aca32a 100644
@@ -149,6 +149,7 @@ struct fwd_stream {
  */
 struct rte_port {
        uint8_t                 enabled;    /**< Port enabled or not */
+       struct rte_pci_device   *pci_dev;
        struct rte_eth_dev_info dev_info;   /**< PCI info + driver name */
        struct rte_eth_conf     dev_conf;   /**< Port configuration. */
        struct ether_addr       eth_addr;   /**< Port ethernet address */
@@ -442,34 +443,36 @@ mbuf_pool_find(unsigned int sock_id)
  * Read/Write operations on a PCI register of a port.
  */
 static inline uint32_t
-port_pci_reg_read(struct rte_port *port, uint32_t reg_off)
+pci_reg_read(struct rte_pci_device *pci_dev, uint32_t reg_off)
 {
-       void *reg_addr;
+       void *reg_addr
+               = (char *)pci_dev->mem_resource[0].addr + reg_off;
        uint32_t reg_v;
 
-       reg_addr = (void *)
-               ((char *)port->dev_info.pci_dev->mem_resource[0].addr +
-                       reg_off);
        reg_v = *((volatile uint32_t *)reg_addr);
        return rte_le_to_cpu_32(reg_v);
 }
 
-#define port_id_pci_reg_read(pt_id, reg_off) \
-       port_pci_reg_read(&ports[(pt_id)], (reg_off))
+static inline uint32_t
+port_id_pci_reg_read(portid_t pt_id, uint32_t reg_off)
+{
+       return pci_reg_read(ports[pt_id].pci_dev, reg_off);
+}
 
 static inline void
-port_pci_reg_write(struct rte_port *port, uint32_t reg_off, uint32_t reg_v)
+pci_reg_write(struct rte_pci_device *pci_dev, uint32_t reg_off, uint32_t reg_v)
 {
-       void *reg_addr;
+       void *reg_addr
+               = (char *)pci_dev->mem_resource[0].addr + reg_off;
 
-       reg_addr = (void *)
-               ((char *)port->dev_info.pci_dev->mem_resource[0].addr +
-                       reg_off);
        *((volatile uint32_t *)reg_addr) = rte_cpu_to_le_32(reg_v);
 }
 
-#define port_id_pci_reg_write(pt_id, reg_off, reg_value) \
-       port_pci_reg_write(&ports[(pt_id)], (reg_off), (reg_value))
+static inline void
+port_id_pci_reg_write(portid_t pt_id, uint32_t reg_off, uint32_t reg_v)
+{
+       return pci_reg_write(ports[pt_id].pci_dev, reg_off, reg_v);
+}
 
 /* Prototypes */
 unsigned int parse_item_list(char* str, const char* item_name,
@@ -598,6 +601,7 @@ enum print_warning {
        ENABLED_WARN = 0,
        DISABLED_WARN
 };
+int port_is_not_pci(portid_t port_id);
 int port_id_is_invalid(portid_t port_id, enum print_warning warning);
 
 /*
app/test/test_kni.c +33 -6
index 309741cb..6b2ebbed 100644
@@ -370,6 +370,8 @@ test_kni_processing(uint8_t port_id, struct rte_mempool *mp)
        struct rte_kni_conf conf;
        struct rte_eth_dev_info info;
        struct rte_kni_ops ops;
+       struct rte_device *dev;
+       struct rte_pci_device *pci_dev;
 
        if (!mp)
                return -1;
@@ -379,8 +381,16 @@ test_kni_processing(uint8_t port_id, struct rte_mempool *mp)
        memset(&ops, 0, sizeof(ops));
 
        rte_eth_dev_info_get(port_id, &info);
-       conf.addr = info.pci_dev->addr;
-       conf.id = info.pci_dev->id;
+
+       dev = info.device;
+       if (dev->driver->type != PMD_PCI) {
+               printf("device is not PCI\n");
+               return -1;
+       }
+
+       pci_dev = container_of(dev, struct rte_pci_device, device);
+       conf.addr = pci_dev->addr;
+       conf.id = pci_dev->id;
        snprintf(conf.name, sizeof(conf.name), TEST_KNI_PORT);
 
        /* core id 1 configured for kernel thread */
@@ -478,6 +488,8 @@ test_kni(void)
        struct rte_kni_conf conf;
        struct rte_eth_dev_info info;
        struct rte_kni_ops ops;
+       struct rte_device *dev;
+       struct rte_pci_device *pci_dev;
 
        /* Initialize KNI subsytem */
        rte_kni_init(KNI_TEST_MAX_PORTS);
@@ -536,8 +548,16 @@ test_kni(void)
        memset(&conf, 0, sizeof(conf));
        memset(&ops, 0, sizeof(ops));
        rte_eth_dev_info_get(port_id, &info);
-       conf.addr = info.pci_dev->addr;
-       conf.id = info.pci_dev->id;
+
+       dev = info.device;
+       if (dev->driver->type != PMD_PCI) {
+               printf("device is not PCI\n");
+               return -1;
+       }
+
+       pci_dev = container_of(dev, struct rte_pci_device, device);
+       conf.addr = pci_dev->addr;
+       conf.id = pci_dev->id;
        conf.group_id = (uint16_t)port_id;
        conf.mbuf_size = MAX_PACKET_SZ;
 
@@ -565,8 +585,15 @@ test_kni(void)
        memset(&info, 0, sizeof(info));
        memset(&ops, 0, sizeof(ops));
        rte_eth_dev_info_get(port_id, &info);
-       conf.addr = info.pci_dev->addr;
-       conf.id = info.pci_dev->id;
+       dev = info.device;
+       if (dev->driver->type != PMD_PCI) {
+               printf("device is not PCI\n");
+               return -1;
+       }
+
+       pci_dev = container_of(dev, struct rte_pci_device, device);
+       conf.addr = pci_dev->addr;
+       conf.id = pci_dev->id;
        conf.group_id = (uint16_t)port_id;
        conf.mbuf_size = MAX_PACKET_SZ;
 
doc/guides/rel_notes/release_17_02.rst +3 -7
index 3b650388..30b23703 100644
@@ -106,16 +106,12 @@ API Changes
 ABI Changes
 -----------
 
-.. This section should contain ABI changes. Sample format:
-
-   * Add a short 1-2 sentence description of the ABI change that was announced in
+.. * Add a short 1-2 sentence description of the ABI change that was announced in
      the previous releases and made in this release. Use fixed width quotes for
      ``rte_function_names`` or ``rte_struct_names``. Use the past tense.
 
-   This section is a comment. do not overwrite or remove it.
-   Also, make sure to start the actual text at the margin.
-   =========================================================
-
+* The ``rte_eth_dev_info`` structure no longer has pointer to PCI device, but
+  instead has new_field ``device`` which is a pointer to a generic ethernet device.
 
 
 Shared Library Versions
lib/librte_ether/rte_ethdev.c +0 -0
index 1e0f2061..71a8e9b9 100644

lib/librte_ether/rte_ethdev.c rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info) · line 1573

Quoted 7 lines
lib/librte_ether/rte_ethdev.c +2 -1
@@ -1568,7 +1568,8 @@ 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->device = &dev->pci_dev->device;
        dev_info->driver_name = dev->data->drv_name;

I don't think that exposing the device through dev_info makes this a future proof. If we want to model some kind of extensions to dev_info we should instead model this explicitly.

So from my point of view the pci_dev should get removed instead.

Quoted 18 lines
lib/librte_ether/rte_ethdev.c +0 -0
        dev_info->nb_rx_queues = dev->data->nb_rx_queues;
        dev_info->nb_tx_queues = dev->data->nb_tx_queues;
lib/librte_ether/rte_ethdev.h +1 -2
index 3c85e331..2b3b4014 100644
@@ -879,7 +879,7 @@ struct rte_eth_conf {
  * Ethernet device information
  */
 struct rte_eth_dev_info {
-       struct rte_pci_device *pci_dev; /**< Device PCI information. */
+       struct rte_device *device; /**< Device information. */
        const char *driver_name; /**< Device Driver name. */
        unsigned int if_index; /**< Index to bound host interface, or 0 if none.
                Use if_indextoname() to translate into an interface name. */
--

2.11.0

#24 lore raw
In reply to Stephen Hemminger
Quoted 9 lines · Stephen Hemminger

This set of patches generalize the ethernet device model sufficently to support virtual, pci, and vmbus devices.

All this is based on the XP principal of only building what is necessary and no more than that. The rationale is NOT to rework the DPDK to have same level of bus and parent information as the Linux device model. This would be unnecessary, fragile and unnecessarily OS dependent.

Quoted 4 lines

Instead, this set of patches does the simple change of refactoring so that the object relationship between ethernet (rte_eth_dev), PCI (rte_pci_device) and generic (rte_device) is properly broken apart.

Yes, as I pointed out when reviewing the bus related changes the refactoring of the ethdev doesn't depend on the bus work to get merged first.

I've sent a similar series in November already. I guess that is a sign that the review got stuck somewhere.

Jan

Quoted 81 lines

It does make the simplifying assumption that the device driver knows what type of bus it is on. For a future case where a device has to be able to handle different bus families; then the device driver can have multiple device drivers in one code base (like ixgbe PF/VF).

Jan Blunck (1):
eal: define container_of macro

Stephen Hemminger (12):
ethdev: increase length ethernet device internal name
rte_device: make driver pointer const
eal: introduce driver type
pmd: remove useless reset of dev_info->dev_pci
ethdev: make dev_info generic (not just 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
virtio: localize mapping from rte_eth to pci
broadcom: localize mapping from eth_dev to pci
ethdev: change pci_dev to generic device
hyperv: VMBUS support infrastucture

 app/test-pmd/config.c                       |  32 +++++++-
 app/test-pmd/testpmd.c                      |  11 ++-
 app/test-pmd/testpmd.h                      |  32 ++++----
 app/test/test_kni.c                         |  39 +++++++--
 app/test/virtual_pmd.c                      |   4 +-
 doc/guides/rel_notes/deprecation.rst        |   3 +
 doc/guides/rel_notes/release_17_02.rst      |  10 +--
 drivers/net/af_packet/rte_eth_af_packet.c   |   1 -
 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            |   2 +-
 drivers/net/cxgbe/cxgbe_main.c              |   5 +-
 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 +-
 drivers/net/ena/ena_ethdev.c                |   2 +-
 drivers/net/enic/enic_ethdev.c              |   2 +-
 drivers/net/enic/enic_rxtx.c                |   2 -
 drivers/net/fm10k/fm10k_ethdev.c            |  90 +++++++++++++--------
 drivers/net/i40e/i40e_ethdev.c              |  77 +++++++++++-------
 drivers/net/i40e/i40e_ethdev.h              |   3 +
 drivers/net/i40e/i40e_ethdev_vf.c           |  59 ++++++++------
 drivers/net/ixgbe/ixgbe_ethdev.c            | 120 ++++++++++++++++------------
 drivers/net/ixgbe/ixgbe_ethdev.h            |   3 +
 drivers/net/ixgbe/ixgbe_pf.c                |   4 +-
 drivers/net/null/rte_eth_null.c             |   1 -
 drivers/net/pcap/rte_eth_pcap.c             |   1 -
 drivers/net/qede/qede_ethdev.c              |  24 +++---
 drivers/net/qede/qede_ethdev.h              |   4 +
 drivers/net/ring/rte_eth_ring.c             |   1 -
 drivers/net/virtio/virtio_ethdev.c          |  95 +++++++++++++++-------
 drivers/net/virtio/virtio_user_ethdev.c     |   2 +-
 drivers/net/vmxnet3/vmxnet3_ethdev.c        |   3 +-
 drivers/net/xenvirt/rte_eth_xenvirt.c       |   1 -
 lib/librte_eal/common/Makefile              |   2 +-
 lib/librte_eal/common/eal_common_devargs.c  |   7 ++
 lib/librte_eal/common/eal_common_options.c  |  38 +++++++++
 lib/librte_eal/common/eal_internal_cfg.h    |   3 +-
 lib/librte_eal/common/eal_options.h         |   6 ++
 lib/librte_eal/common/eal_private.h         |   5 ++
 lib/librte_eal/common/include/rte_common.h  |  20 +++++
 lib/librte_eal/common/include/rte_dev.h     |  17 +++-
 lib/librte_eal/common/include/rte_devargs.h |   8 ++
 lib/librte_eal/common/include/rte_pci.h     |   1 +
 lib/librte_eal/common/include/rte_vdev.h    |   1 +
 lib/librte_eal/linuxapp/eal/Makefile        |   6 ++
 lib/librte_eal/linuxapp/eal/eal.c           |  11 +++
 lib/librte_ether/rte_ethdev.c               | 114 ++++++++++++++++++++++++--
 lib/librte_ether/rte_ethdev.h               |  38 +++++++--
 mk/rte.app.mk                               |   1 +
 53 files changed, 776 insertions(+), 343 deletions(-)

--
2.11.0

#10 lore raw

Re: [PATCH 04/13] eal: introduce driver type

In reply to Stephen Hemminger
Quoted 24 lines · Stephen Hemminger

Since multiple buses and device types need to be supported. Provide type field in driver.

---
 lib/librte_eal/common/include/rte_dev.h  | 15 ++++++++++++---
 lib/librte_eal/common/include/rte_pci.h  |  1 +
 lib/librte_eal/common/include/rte_vdev.h |  1 +
 3 files changed, 14 insertions(+), 3 deletions(-)
lib/librte_eal/common/include/rte_dev.h +8 -0
index e5471a22..3f4e26e6 100644
@@ -144,12 +144,21 @@ void rte_eal_device_insert(struct rte_device *dev);
 void rte_eal_device_remove(struct rte_device *dev);
 
 /**
+ * Type of device driver
+ */
+enum rte_driver_type {
+       PMD_VIRTUAL,
+       PMD_PCI,
+};
+
+/**

lib/librte_eal/common/include/rte_dev.h void rte_eal_device_insert(struct rte_device *dev); · line 162

Quoted 10 lines
lib/librte_eal/common/include/rte_dev.h +3 -2
  * A structure describing a device driver.
  */
 struct rte_driver {
        TAILQ_ENTRY(rte_driver) next;  /**< Next in list. */
-       const char *name;                   /**< Driver name. */
-       const char *alias;              /**< Driver alias. */
+       const char *name;              /**< Driver name. */
+       const char *alias;             /**< Driver alias. */
+       enum rte_driver_type type;     /**< Driver type. */
 };

I wonder who is the user of the type. It can't be the driver itself because it must be aware of what kind of low-level interface it serves. So this seems to be a helper to allow users of rte_driver to upcast to the object that embeds the rte_driver at runtime. I don't believe that this is a good interface because it often leads to ugly and error prone code.

Quoted 35 lines
lib/librte_eal/common/include/rte_dev.h +1 -1
 /**
@@ -243,4 +252,4 @@ __attribute__((used)) = str
 }
 #endif
 
-#endif /* _RTE_VDEV_H_ */
+#endif /* _RTE_DEV_H_ */
lib/librte_eal/common/include/rte_pci.h +1 -0
index 9ce88472..d377d539 100644
@@ -492,6 +492,7 @@ RTE_INIT(pciinitfn_ ##nm); \
 static void pciinitfn_ ##nm(void) \
 {\
        (pci_drv).driver.name = RTE_STR(nm);\
+       (pci_drv).driver.type = PMD_PCI; \
        rte_eal_pci_register(&pci_drv); \
 } \
 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
lib/librte_eal/common/include/rte_vdev.h +1 -1
index 784e837d..98fb5bb5 100644
@@ -88,6 +88,7 @@ static void vdrvinitfn_ ##vdrv(void)\
 {\
        (vdrv).driver.name = RTE_STR(nm);\
        (vdrv).driver.alias = vdrvinit_ ## nm ## _alias;\
+       (vdrv).driver.type = PMD_VIRTUAL;\
        rte_eal_vdrv_register(&vdrv);\
 } \
 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
--

2.11.0

#12 lore raw

Re: [PATCH 04/13] eal: introduce driver type

In reply to Stephen Hemminger
Quoted 13 lines · Stephen Hemminger

Since multiple buses and device types need to be supported. Provide type field in driver.

---
 lib/librte_eal/common/include/rte_dev.h  | 15 ++++++++++++---
 lib/librte_eal/common/include/rte_pci.h  |  1 +
 lib/librte_eal/common/include/rte_vdev.h |  1 +
 3 files changed, 14 insertions(+), 3 deletions(-)
lib/librte_eal/common/include/rte_dev.h +0 -0
index e5471a22..3f4e26e6 100644

lib/librte_eal/common/include/rte_dev.h void rte_eal_device_insert(struct rte_device *dev); · line 152

Quoted 9 lines
lib/librte_eal/common/include/rte_dev.h +6 -0
@@ -144,12 +144,21 @@ void rte_eal_device_insert(struct rte_device *dev);
 void rte_eal_device_remove(struct rte_device *dev);
 
 /**
+ * Type of device driver
+ */
+enum rte_driver_type {
+	PMD_VIRTUAL,
+	PMD_PCI,
+};

There were types in v16.07 and previous.
Types has been removed in v16.11.
Now are we sure we want to add them back?

#11 lore raw

Re: [PATCH 04/13] eal: introduce driver type

In reply to Jan Blunck
Quoted 35 lines · On Tue, 20 Dec 2016 14:00:55 +0100 Jan Blunck <[email protected]> wrote:
Quoted 33 lines · Stephen Hemminger

Since multiple buses and device types need to be supported. Provide type field in driver.

---
 lib/librte_eal/common/include/rte_dev.h  | 15 ++++++++++++---
 lib/librte_eal/common/include/rte_pci.h  |  1 +
 lib/librte_eal/common/include/rte_vdev.h |  1 +
 3 files changed, 14 insertions(+), 3 deletions(-)
lib/librte_eal/common/include/rte_dev.h +11 -2
index e5471a22..3f4e26e6 100644
@@ -144,12 +144,21 @@ void rte_eal_device_insert(struct rte_device *dev);
 void rte_eal_device_remove(struct rte_device *dev);
 
 /**
+ * Type of device driver
+ */
+enum rte_driver_type {
+       PMD_VIRTUAL,
+       PMD_PCI,
+};
+
+/**
  * A structure describing a device driver.
  */
 struct rte_driver {
        TAILQ_ENTRY(rte_driver) next;  /**< Next in list. */
-       const char *name;                   /**< Driver name. */
-       const char *alias;              /**< Driver alias. */
+       const char *name;              /**< Driver name. */
+       const char *alias;             /**< Driver alias. */
+       enum rte_driver_type type;     /**< Driver type. */
Quoted 8 lines

lib/librte_eal/common/include/rte_dev.h void rte_eal_device_insert(struct rte_device *dev); · line 162

Quoted 1 line
lib/librte_eal/common/include/rte_dev.h +0 -0
 };  

I wonder who is the user of the type. It can't be the driver itself because it must be aware of what kind of low-level interface it serves. So this seems to be a helper to allow users of rte_driver to upcast to the object that embeds the rte_driver at runtime. I don't believe that this is a good interface because it often leads to ugly and error prone code.

The thing I ran into was the test code. The testpmd (and related code) is an example of how some code might want to use dev_info_get to find out about a device then take some action based on the driver type. Testpmd has code that manipulates PCI registers. Right now it is broken when run on virtual devices.

#3 lore raw

Re: [PATCH 01/13] ethdev: increase length ethernet device internal name

In reply to Shreyansh Jain
Quoted 42 lines · On Tue, 20 Dec 2016 12:23:25 +0530 Shreyansh Jain <[email protected]>…
Quoted 28 lines · Stephen Hemminger

Allow sufficicent space for UUID in string form (36+1). Needed to use UUID with Hyper-V

---
 doc/guides/rel_notes/deprecation.rst | 3 +++
 lib/librte_ether/rte_ethdev.h        | 6 +++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
doc/guides/rel_notes/deprecation.rst +3 -0
index 2d17bc6e..b83f23a1 100644
@@ -58,6 +58,9 @@ Deprecation Notices
   ``port`` field, may be moved or removed as part of this mbuf work. A
   ``timestamp`` will also be added.
 
+* ethdev: for 17.02 the size of internal device name will be increased
+  to 40 characters to allow for storing UUID.
+
 * The mbuf flags PKT_RX_VLAN_PKT and PKT_RX_QINQ_PKT are deprecated and
   are respectively replaced by PKT_RX_VLAN_STRIPPED and
   PKT_RX_QINQ_STRIPPED, that are better described. The old flags and
lib/librte_ether/rte_ethdev.h +0 -0
index 96781792..3c85e331 100644

lib/librte_ether/rte_ethdev.h struct rte_eth_dev_sriov { · line 1659

Quoted 9 lines
lib/librte_ether/rte_ethdev.h +5 -1
@@ -1652,7 +1652,11 @@ struct rte_eth_dev_sriov {
 };
 #define RTE_ETH_DEV_SRIOV(dev)         ((dev)->data->sriov)
 
-#define RTE_ETH_NAME_MAX_LEN (32)
+/*
+ * Internal identifier length
+ * Sufficiently large to allow for UUID or PCI address
+ */
+#define RTE_ETH_NAME_MAX_LEN 40  

Just to clarify my doubt: UUID is 36 byte long. So, 4 extra bytes are to keep the name length 4 byte aligned (along with one byte of \0)?

Quoted 1 line

Or, PCI based addressing can stretch 40 bytes?

UUID needs 37 bytes (36 + \0).
I just rounded up to next 4 byte boundary since it seemed like a good idea expecting that it might have to grow later.

Alternatively we could just get rid of NAME_MAX_LEN and allow arbitrary length...

#9 lore raw

Re: [PATCH 04/13] eal: introduce driver type

In reply to Shreyansh Jain
Quoted 27 lines · On Tue, 20 Dec 2016 12:46:17 +0530 Shreyansh Jain <[email protected]>…
Quoted 13 lines · Stephen Hemminger

Since multiple buses and device types need to be supported. Provide type field in driver.

---
 lib/librte_eal/common/include/rte_dev.h  | 15 ++++++++++++---
 lib/librte_eal/common/include/rte_pci.h  |  1 +
 lib/librte_eal/common/include/rte_vdev.h |  1 +
 3 files changed, 14 insertions(+), 3 deletions(-)
lib/librte_eal/common/include/rte_dev.h +0 -0
index e5471a22..3f4e26e6 100644

lib/librte_eal/common/include/rte_dev.h void rte_eal_device_insert(struct rte_device *dev); · line 152

Quoted 9 lines
lib/librte_eal/common/include/rte_dev.h +6 -0
@@ -144,12 +144,21 @@ void rte_eal_device_insert(struct rte_device *dev);
 void rte_eal_device_remove(struct rte_device *dev);
 
 /**
+ * Type of device driver
+ */
+enum rte_driver_type {
+	PMD_VIRTUAL,
+	PMD_PCI,
+};  

So the expectation is that if a new device type is introduced (anything other than virtual or PCI), this enum is expanded?

Quoted 7 lines

Broadly, we have two possible ways being discussed on ML for device relationship with PMD/APIs:

1. the way you have done: each device belongs to a particular type (enum rte_driver_type) and based on its type, operations would be performed on it (using conditional operators, for example). We continue to have a common device list containing all type of devices.

It is more about providing feedback to applications in info_get which is the only place they should care.

Quoted 5 lines

2. disassociating the device (rte_device) completely from its type and basing it on a Bus type. So, we have separate buses for each device type and hence no need for separation of logic based on device type.

Quoted 7 lines

I think implementation similar to (1) existed before it was removed in 6751f6de.

I have an (obvious) inclination towards (2) because that helps plugging in more drivers/device types without expecting the contributor to change the EAL - however trivial the change is.

The difference is that virtual devices don't actually live on bus. So it is really a property of the device not a bus per say.