This is a simple helper function to check if device is owned (being used as a sub-device). It is more convienent than having applications call rte_eth_dev_owner_get and check the result.
Signed-off-by: Stephen Hemminger <step...@networkplumber.org> --- v2 - rename the helper function and use rte_eth_dev_owner_get lib/librte_ethdev/rte_ethdev.c | 12 ++++++++++++ lib/librte_ethdev/rte_ethdev.h | 13 +++++++++++++ lib/librte_ethdev/rte_ethdev_version.map | 3 +++ 3 files changed, 28 insertions(+) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 774c721b3484..6e2d0110f65e 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -737,6 +737,18 @@ rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner) return ret; } +int +rte_eth_dev_is_owned(uint16_t port_id) +{ + struct rte_eth_dev_owner owner; + int ret; + + ret = rte_eth_dev_owner_get(port_id, &owner); + if (ret == 0) + ret = (owner.id != RTE_ETH_DEV_NO_OWNER); + return ret; +} + int rte_eth_dev_socket_id(uint16_t port_id) { diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h index d1a593ad112a..3a8a4bcde4b7 100644 --- a/lib/librte_ethdev/rte_ethdev.h +++ b/lib/librte_ethdev/rte_ethdev.h @@ -1693,6 +1693,19 @@ __rte_experimental int rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner); +/** + * Check if port_id is part of a sub-device + * + * @param port_id + * The port identifier of the Ethernet device + * @return + * - 1 if device is associated with an owner + * - 0 if port is not owned + * - negative errno value on error. + */ +__rte_experimental +int rte_eth_dev_is_owned(uint16_t port_id); + /** * Get the number of ports which are usable for the application. * diff --git a/lib/librte_ethdev/rte_ethdev_version.map b/lib/librte_ethdev/rte_ethdev_version.map index 3f32fdecf722..435df2dba149 100644 --- a/lib/librte_ethdev/rte_ethdev_version.map +++ b/lib/librte_ethdev/rte_ethdev_version.map @@ -230,4 +230,7 @@ EXPERIMENTAL { # added in 20.02 rte_flow_dev_dump; + + # added in 20.05 + rte_eth_dev_is_owned; }; -- 2.20.1