From 16b5ecbb2f93fa577a0f665b7e1aaf07c63525f1 Mon Sep 17 00:00:00 2001
From: Dengdui Huang <huangdengdui@huawei.com>
Date: Mon, 5 Jun 2023 10:27:40 +0800
Subject: ethdev: add API to check if queue is valid

[ upstream commit dcf6ce9c2100c604fd0cf602841d290d8236b504 ]

The API rte_eth_dev_is_valid_rxq/txq which
is used to check if Rx/Tx queue is valid.
If the queue has been setup, it is considered valid.

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
Acked-by: Ferruh Yigit <ferruh.yigit@amd.com>
---
 lib/ethdev/rte_ethdev.c | 22 ++++++++++++++++++++++
 lib/ethdev/rte_ethdev.h | 38 ++++++++++++++++++++++++++++++++++++++
 lib/ethdev/version.map  |  2 ++
 3 files changed, 62 insertions(+)

diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 61731ec83e..1a25515148 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -1009,6 +1009,28 @@ eth_dev_validate_tx_queue(const struct rte_eth_dev *dev, uint16_t tx_queue_id)
 	return 0;
 }
 
+int
+rte_eth_dev_is_valid_rxq(uint16_t port_id, uint16_t queue_id)
+{
+	struct rte_eth_dev *dev;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
+
+	return eth_dev_validate_rx_queue(dev, queue_id);
+}
+
+int
+rte_eth_dev_is_valid_txq(uint16_t port_id, uint16_t queue_id)
+{
+	struct rte_eth_dev *dev;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
+
+	return eth_dev_validate_tx_queue(dev, queue_id);
+}
+
 int
 rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id)
 {
diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h
index 2064d439c8..c555ecb840 100644
--- a/lib/ethdev/rte_ethdev.h
+++ b/lib/ethdev/rte_ethdev.h
@@ -2692,6 +2692,44 @@ int rte_eth_dev_socket_id(uint16_t port_id);
  */
 int rte_eth_dev_is_valid_port(uint16_t port_id);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ * Check if Rx queue is valid. If the queue has been setup,
+ * it is considered valid.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param queue_id
+ *  The index of the receive queue.
+ * @return
+ *   - -ENODEV: if *port_id* is invalid.
+ *   - -EINVAL: if queue_id is out of range or queue is not been setup.
+ *   - 0 if Rx queue is valid.
+ */
+__rte_experimental
+int rte_eth_dev_is_valid_rxq(uint16_t port_id, uint16_t queue_id);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ * Check if Tx queue is valid. If the queue has been setup,
+ * it is considered valid.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param queue_id
+ *  The index of the transmit queue.
+ * @return
+ *   - -ENODEV: if *port_id* is invalid.
+ *   - -EINVAL: if queue_id is out of range or queue is not been setup.
+ *   - 0 if Tx queue is valid.
+ */
+__rte_experimental
+int rte_eth_dev_is_valid_txq(uint16_t port_id, uint16_t queue_id);
+
 /**
  * Start specified Rx queue of a port. It is used when rx_deferred_start
  * flag of the specified queue is true.
diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map
index 590aa5a0a6..f593f64ea9 100644
--- a/lib/ethdev/version.map
+++ b/lib/ethdev/version.map
@@ -263,6 +263,8 @@ EXPERIMENTAL {
 	# added in 22.11
 	rte_eth_rx_descriptor_dump;
 	rte_eth_tx_descriptor_dump;
+	rte_eth_dev_is_valid_rxq;
+	rte_eth_dev_is_valid_txq;
 };
 
 INTERNAL {
-- 
2.23.0