DPDK patches and discussions
 help / color / mirror / Atom feed
From: Dengdui Huang <huangdengdui@huawei.com>
To: <dev@dpdk.org>
Cc: <ferruh.yigit@amd.com>, <stephen@networkplumber.org>,
	<thomas@monjalon.net>, <aman.deep.singh@intel.com>,
	<yuying.zhang@intel.com>,  <andrew.rybchenko@oktetlabs.ru>,
	<anatoly.burakov@intel.com>, <lihuisong@huawei.com>,
	<liuyonglong@huawei.com>, <liudongdong3@huawei.com>
Subject: [PATCH v2 1/2] ethdev: add API to check queue ID validity
Date: Mon, 22 May 2023 21:09:46 +0800	[thread overview]
Message-ID: <20230522130947.345390-2-huangdengdui@huawei.com> (raw)
In-Reply-To: <20230522130947.345390-1-huangdengdui@huawei.com>

The API rte_eth_dev_is_valid_rxq/txq checks
the port ID validity and then the Rx/Tx queue ID is valid.

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
---
 doc/guides/rel_notes/release_23_07.rst |  5 ++++
 lib/ethdev/rte_ethdev.c                | 30 +++++++++++++++++++++
 lib/ethdev/rte_ethdev.h                | 36 ++++++++++++++++++++++++++
 lib/ethdev/version.map                 |  4 +++
 4 files changed, 75 insertions(+)

diff --git a/doc/guides/rel_notes/release_23_07.rst b/doc/guides/rel_notes/release_23_07.rst
index a9b1293689..19e645156f 100644
--- a/doc/guides/rel_notes/release_23_07.rst
+++ b/doc/guides/rel_notes/release_23_07.rst
@@ -56,6 +56,11 @@ New Features
      =======================================================
 
 
+* **Added ethdev Rx/Tx queue id check API.**
+
+  Added ethdev Rx/Tx queue id check API which provides functions
+  for check if Rx/Tx queue id is valid.
+
 Removed Items
 -------------
 
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 4d03255683..3d85218127 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -407,6 +407,36 @@ rte_eth_dev_is_valid_port(uint16_t port_id)
 	return is_valid;
 }
 
+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];
+
+	if (queue_id >= dev->data->nb_rx_queues ||
+			dev->data->rx_queues[queue_id] == NULL)
+		return -EINVAL;
+
+	return 0;
+}
+
+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];
+
+	if (queue_id >= dev->data->nb_tx_queues ||
+			dev->data->tx_queues[queue_id] == NULL)
+		return -EINVAL;
+
+	return 0;
+}
+
 static int
 eth_is_valid_owner_id(uint64_t owner_id)
 {
diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h
index 99fe9e238b..abda95b27f 100644
--- a/lib/ethdev/rte_ethdev.h
+++ b/lib/ethdev/rte_ethdev.h
@@ -2665,6 +2665,42 @@ 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 ID is 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 is out of range or not been setup.
+ *   - 0 if queue ID 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 ID is 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 is out of range or not been setup.
+ *   - 0 if Tx queue ID 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 357d1a88c0..d8797310d2 100644
--- a/lib/ethdev/version.map
+++ b/lib/ethdev/version.map
@@ -299,6 +299,10 @@ EXPERIMENTAL {
 	rte_flow_action_handle_query_update;
 	rte_flow_async_action_handle_query_update;
 	rte_flow_async_create_by_index;
+
+	# added in 23.07
+	rte_eth_dev_is_valid_rxq;
+	rte_eth_dev_is_valid_txq;
 };
 
 INTERNAL {
-- 
2.33.0


  reply	other threads:[~2023-05-22 13:10 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16 11:00 [PATCH] app/testpmd: fix segment fault with invalid queue id Dengdui Huang
2023-05-16 15:12 ` Stephen Hemminger
2023-05-19 10:18   ` huangdengdui
2023-05-22 13:09 ` [PATCH v2 0/2] add API and use it to fix a bug Dengdui Huang
2023-05-22 13:09   ` Dengdui Huang [this message]
2023-05-22 13:58     ` [PATCH v2 1/2] ethdev: add API to check queue ID validity Andrew Rybchenko
2023-05-24  7:38       ` huangdengdui
2023-05-24  9:03         ` Andrew Rybchenko
2023-05-31 16:31       ` Ferruh Yigit
2023-06-01 22:13         ` Ferruh Yigit
2023-06-02  1:36           ` huangdengdui
2023-05-22 13:09   ` [PATCH v2 2/2] app/testpmd: fix segment fault with invalid queue id Dengdui Huang
2023-05-25  7:03 ` [PATCH v3 0/2] add Rx/Tx queue ID check API and use it to fix a bug Dengdui Huang
2023-05-25  7:03   ` [PATCH v3 1/2] ethdev: add API to check if queue is available Dengdui Huang
2023-05-25  7:03   ` [PATCH v3 2/2] app/testpmd: fix segment fault with invalid queue ID Dengdui Huang
2023-06-02  7:52 ` [PATCH v4 0/2] add Rx/Tx queue ID check API and use it to fix a bug Dengdui Huang
2023-06-02  7:52   ` [PATCH v4 1/2] ethdev: add API to check if queue is valid Dengdui Huang
2023-06-02 12:47     ` Ferruh Yigit
2023-06-05  1:24       ` huangdengdui
2023-06-02  7:52   ` [PATCH v4 2/2] app/testpmd: fix segment fault with invalid queue ID Dengdui Huang
2023-06-02 12:47     ` Ferruh Yigit
2023-06-05  2:27 ` [PATCH v5 0/2] add Rx/Tx queue ID check API and use it to fix a bug Dengdui Huang
2023-06-05  2:27   ` [PATCH v5 1/2] ethdev: add API to check if queue is valid Dengdui Huang
2023-06-06  9:06     ` Ferruh Yigit
2023-06-05  2:27   ` [PATCH v5 2/2] app/testpmd: fix segment fault with invalid queue ID Dengdui Huang
2023-06-06  9:07   ` [PATCH v5 0/2] add Rx/Tx queue ID check API and use it to fix a bug Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230522130947.345390-2-huangdengdui@huawei.com \
    --to=huangdengdui@huawei.com \
    --cc=aman.deep.singh@intel.com \
    --cc=anatoly.burakov@intel.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=lihuisong@huawei.com \
    --cc=liudongdong3@huawei.com \
    --cc=liuyonglong@huawei.com \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    --cc=yuying.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).