From 961fb4029b8c52c0e8230d34993c354d70e10e14 Mon Sep 17 00:00:00 2001 From: Kumara Parameshwaran Date: Mon, 31 Jan 2022 20:02:33 +0530 Subject: [PATCH] ethdev: add internal function to device struct from name The PMDs would need a function to access the rte_eth_devices without accessing the global rte_eth_device array. Cc: stable@dpdk.org Signed-off-by: Kumara Parameshwaran Reviewed-by: Ferruh Yigit --- lib/ethdev/ethdev_driver.h | 18 ++++++++++++++++++ lib/ethdev/rte_ethdev.c | 11 +++++++++++ lib/ethdev/version.map | 1 + 3 files changed, 30 insertions(+) diff --git a/lib/ethdev/ethdev_driver.h b/lib/ethdev/ethdev_driver.h index d95605a355..0dac55f9c8 100644 --- a/lib/ethdev/ethdev_driver.h +++ b/lib/ethdev/ethdev_driver.h @@ -1629,6 +1629,24 @@ rte_eth_hairpin_queue_peer_bind(uint16_t cur_port, uint16_t cur_queue, struct rte_hairpin_peer_info *peer_info, uint32_t direction); +/** + * @internal + * Get rte_eth_dev from device name. The device name should be specified + * as below: + * - PCIe address (Domain:Bus:Device.Function), for example 0000:2:00.0 + * - SoC device name, for example fsl-gmac0 + * - vdev dpdk name, for example net_[pcap0|null0|tap0] + * + * @param name + * PCI address or name of the device + * @return + * - rte_eth_dev if successful + * - NULL on failure + */ +__rte_internal +struct rte_eth_dev* +rte_eth_dev_get_by_name(const char *name); + /** * @internal * Reset the current queue state and configuration to disconnect (unbind) it diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 29e21ad580..917a320afa 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -894,6 +894,17 @@ rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id) return -ENODEV; } +struct rte_eth_dev * +rte_eth_dev_get_by_name(const char *name) +{ + uint16_t pid; + + if (rte_eth_dev_get_port_by_name(name, &pid)) + return NULL; + + return &rte_eth_devices[pid]; +} + static int eth_err(uint16_t port_id, int ret) { diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map index c2fb0669a4..1f7359c846 100644 --- a/lib/ethdev/version.map +++ b/lib/ethdev/version.map @@ -267,6 +267,7 @@ INTERNAL { rte_eth_dev_callback_process; rte_eth_dev_create; rte_eth_dev_destroy; + rte_eth_dev_get_by_name; rte_eth_dev_is_rx_hairpin_queue; rte_eth_dev_is_tx_hairpin_queue; rte_eth_dev_probing_finish; -- 2.20.1