The function returns a port identifier of a ethdev specified by pci address.
v3: - Fix if-condition bug while comparing pci addresses. - Add error checking codes. Reported-by: Mark Enright <menrigh at brocade.com> Signed-off-by: Tetsuya Mukawa <mukawa at igel.co.jp> --- lib/librte_ether/rte_ethdev.c | 17 +++++++++++++++++ lib/librte_ether/rte_ethdev.h | 13 +++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index fa75ea9..fa5b928 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -432,6 +432,23 @@ rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr) return 0; } +int +rte_eth_dev_get_port_by_addr(struct rte_pci_addr *addr, uint8_t *port_id) +{ + struct rte_pci_addr *tmp; + + for (*port_id = 0; *port_id < RTE_MAX_ETHPORTS; (*port_id)++) { + if (!rte_eth_devices[*port_id].attached) + continue; + if (!rte_eth_devices[*port_id].pci_dev) + continue; + tmp = &rte_eth_devices[*port_id].pci_dev->addr; + if (eal_compare_pci_addr(tmp, addr) == 0) + return 0; + } + return -1; +} + static int rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues) { diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index fd4aa5a..8bdc8ae 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1672,6 +1672,19 @@ extern int rte_eth_dev_get_addr_by_port( uint8_t port_id, struct rte_pci_addr *addr); /** + * Function for internal use by port hotplug functions. + * Returns a port identifier of a ethdev specified by pci address. + * @param addr + * The pointer to the pci address of the Ethernet device. + * @param port_id + * The pointer to the port identifier + * @return + * - 0 on success, negative on error + */ +extern int rte_eth_dev_get_port_by_addr( + struct rte_pci_addr *addr, uint8_t *port_id); + +/** * Function for internal use by dummy drivers primarily, e.g. ring-based * driver. * Allocates a new ethdev slot for an ethernet device and returns the pointer -- 1.9.1