[1/7] ethdev: add function to test port ownership
Checks
Commit Message
Applications using a port mask need a method to be able
to test for (and reject) ethdev ports that are in use for
other purposes.
Fixes: 5b7ba31148a8 ("ethdev: add port ownership")
Cc: matan@mellanox.com
Cc: stable@dpdk.org
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/librte_ethdev/rte_ethdev.c | 9 +++++++++
lib/librte_ethdev/rte_ethdev.h | 15 +++++++++++++++
lib/librte_ethdev/rte_ethdev_version.map | 3 +++
3 files changed, 27 insertions(+)
Comments
Hi Stephen
From: Stephen Hemminger
> Applications using a port mask need a method to be able to test for (and
> reject) ethdev ports that are in use for other purposes.
>
There is already function which is thread safe to get this information:
rte_eth_dev_owner_get.
I don't think we need one more.
> Fixes: 5b7ba31148a8 ("ethdev: add port ownership")
> Cc: matan@mellanox.com
> Cc: stable@dpdk.org
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> lib/librte_ethdev/rte_ethdev.c | 9 +++++++++
> lib/librte_ethdev/rte_ethdev.h | 15 +++++++++++++++
> lib/librte_ethdev/rte_ethdev_version.map | 3 +++
> 3 files changed, 27 insertions(+)
>
> diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
> index 774c721b3484..38f99f417dba 100644
> --- a/lib/librte_ethdev/rte_ethdev.c
> +++ b/lib/librte_ethdev/rte_ethdev.c
> @@ -685,6 +685,15 @@ rte_eth_dev_owner_unset(const uint16_t port_id,
> const uint64_t owner_id)
> return ret;
> }
>
> +int
> +rte_eth_dev_is_owned_by(uint16_t port_id, uint64_t owner_id) {
> + if (!rte_eth_dev_is_valid_port(port_id))
> + return 0;
> +
> + return rte_eth_devices[port_id].data->owner.id == owner_id; }
> +
> int
> rte_eth_dev_owner_delete(const uint64_t owner_id) { diff --git
> a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h index
> d1a593ad112a..91a8f9578282 100644
> --- a/lib/librte_ethdev/rte_ethdev.h
> +++ b/lib/librte_ethdev/rte_ethdev.h
> @@ -1530,6 +1530,21 @@ uint64_t rte_eth_find_next_owned_by(uint16_t
> port_id,
> (unsigned int)p < (unsigned int)RTE_MAX_ETHPORTS; \
> p = rte_eth_find_next_owned_by(p + 1, o))
>
> +/**
> + * Test if a port is owned
> + *
> + * @param port_id
> + * The port identifier of the Ethernet device
> + * @param owner_id
> + * The owner identifier.
> + * RTE_ETH_DEV_NO_OWNER means test if port is not owned.
> + * @return
> + * - 0 if port is out of range or not owned by owner_id
> + * - 1 if device is associated with owner_id
> + */
> +__rte_experimental
> +int rte_eth_dev_is_owned_by(uint16_t port_id, uint64_t owner_id);
> +
> /**
> * Iterates over valid ethdev ports.
> *
> diff --git a/lib/librte_ethdev/rte_ethdev_version.map
> b/lib/librte_ethdev/rte_ethdev_version.map
> index 3f32fdecf722..95231fe3410c 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_by;
> };
> --
> 2.20.1
@@ -685,6 +685,15 @@ rte_eth_dev_owner_unset(const uint16_t port_id, const uint64_t owner_id)
return ret;
}
+int
+rte_eth_dev_is_owned_by(uint16_t port_id, uint64_t owner_id)
+{
+ if (!rte_eth_dev_is_valid_port(port_id))
+ return 0;
+
+ return rte_eth_devices[port_id].data->owner.id == owner_id;
+}
+
int
rte_eth_dev_owner_delete(const uint64_t owner_id)
{
@@ -1530,6 +1530,21 @@ uint64_t rte_eth_find_next_owned_by(uint16_t port_id,
(unsigned int)p < (unsigned int)RTE_MAX_ETHPORTS; \
p = rte_eth_find_next_owned_by(p + 1, o))
+/**
+ * Test if a port is owned
+ *
+ * @param port_id
+ * The port identifier of the Ethernet device
+ * @param owner_id
+ * The owner identifier.
+ * RTE_ETH_DEV_NO_OWNER means test if port is not owned.
+ * @return
+ * - 0 if port is out of range or not owned by owner_id
+ * - 1 if device is associated with owner_id
+ */
+__rte_experimental
+int rte_eth_dev_is_owned_by(uint16_t port_id, uint64_t owner_id);
+
/**
* Iterates over valid ethdev ports.
*
@@ -230,4 +230,7 @@ EXPERIMENTAL {
# added in 20.02
rte_flow_dev_dump;
+
+ # added in 20.05
+ rte_eth_dev_is_owned_by;
};