[1/7] ethdev: add function to test port ownership

Message ID 20200312172047.19973-2-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Headers
Series checking for owned ports in portmask |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Stephen Hemminger March 12, 2020, 5:20 p.m. UTC
  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

Matan Azrad March 15, 2020, 7:45 a.m. UTC | #1
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
  

Patch

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;
 };