diff mbox series

[RFC] lib/ethdev: add dev configured flag

Message ID 1620460836-38506-1-git-send-email-lihuisong@huawei.com (mailing list archive)
State New
Delegated to: Andrew Rybchenko
Headers show
Series [RFC] lib/ethdev: add dev configured flag | expand

Checks

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

Commit Message

Huisong Li May 8, 2021, 8 a.m. UTC
Currently, if dev_configure is not invoked or fails to be invoked, users
can still invoke dev_start successfully. This patch adds a "dev_configured"
flag in "rte_eth_dev_data" to control whether dev_start can be invoked.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 lib/ethdev/rte_ethdev.c      | 11 +++++++++++
 lib/ethdev/rte_ethdev_core.h |  6 +++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

Comments

Huisong Li May 31, 2021, 8:51 a.m. UTC | #1
Hi, All & Ferruh

What do you think about this patch?


在 2021/5/8 16:00, Huisong Li 写道:
> Currently, if dev_configure is not invoked or fails to be invoked, users
> can still invoke dev_start successfully. This patch adds a "dev_configured"
> flag in "rte_eth_dev_data" to control whether dev_start can be invoked.
>
> Signed-off-by: Huisong Li <lihuisong@huawei.com>
> ---
>   lib/ethdev/rte_ethdev.c      | 11 +++++++++++
>   lib/ethdev/rte_ethdev_core.h |  6 +++++-
>   2 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
> index a187976..7d74b17 100644
> --- a/lib/ethdev/rte_ethdev.c
> +++ b/lib/ethdev/rte_ethdev.c
> @@ -1604,6 +1604,8 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
>   	}
>   
>   	rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, 0);
> +	dev->data->dev_configured = 1;
> +
>   	return 0;
>   reset_queues:
>   	eth_dev_rx_queue_config(dev, 0);
> @@ -1614,6 +1616,8 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
>   		dev->data->mtu = old_mtu;
>   
>   	rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, ret);
> +	dev->data->dev_configured = 0;
> +
>   	return ret;
>   }
>   
> @@ -1749,6 +1753,13 @@ rte_eth_dev_start(uint16_t port_id)
>   
>   	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
>   
> +	if (dev->data->dev_configured == 0) {
> +		RTE_ETHDEV_LOG(INFO,
> +			"Device with port_id=%"PRIu16" is not configured.\n",
> +			port_id);
> +		return -EINVAL;
> +	}
> +
>   	if (dev->data->dev_started != 0) {
>   		RTE_ETHDEV_LOG(INFO,
>   			"Device with port_id=%"PRIu16" already started\n",
> diff --git a/lib/ethdev/rte_ethdev_core.h b/lib/ethdev/rte_ethdev_core.h
> index 4679d94..b508769 100644
> --- a/lib/ethdev/rte_ethdev_core.h
> +++ b/lib/ethdev/rte_ethdev_core.h
> @@ -167,7 +167,11 @@ struct rte_eth_dev_data {
>   		scattered_rx : 1,  /**< RX of scattered packets is ON(1) / OFF(0) */
>   		all_multicast : 1, /**< RX all multicast mode ON(1) / OFF(0). */
>   		dev_started : 1,   /**< Device state: STARTED(1) / STOPPED(0). */
> -		lro         : 1;   /**< RX LRO is ON(1) / OFF(0) */
> +		lro         : 1,  /**< RX LRO is ON(1) / OFF(0) */
> +		dev_configured : 1;
> +		/**< Device configuration state:
> +		 * CONFIGURED(1) / NOT CONFIGURED(0).
> +		 */
>   	uint8_t rx_queue_state[RTE_MAX_QUEUES_PER_PORT];
>   		/**< Queues state: HAIRPIN(2) / STARTED(1) / STOPPED(0). */
>   	uint8_t tx_queue_state[RTE_MAX_QUEUES_PER_PORT];
Andrew Rybchenko June 14, 2021, 3:37 p.m. UTC | #2
Summary should start from "ethdev: "

Don't forget to include all maintainers in Cc the next time.
Just use --cc-cmd or --to-cmd options.

Adding Thomas.

On 5/8/21 11:00 AM, Huisong Li wrote:
> Currently, if dev_configure is not invoked or fails to be invoked, users
> can still invoke dev_start successfully. This patch adds a "dev_configured"
> flag in "rte_eth_dev_data" to control whether dev_start can be invoked.

In theory there is an indirect condition. If number of configured Tx
*and* Rx queues is 0, device is not configured.

I have no strong opinion on the topic. Extra flag requires
extra housekeeping. Indirect conditions are not always good
and could be a subject to change.

> Signed-off-by: Huisong Li <lihuisong@huawei.com>
> ---
>   lib/ethdev/rte_ethdev.c      | 11 +++++++++++
>   lib/ethdev/rte_ethdev_core.h |  6 +++++-
>   2 files changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
> index a187976..7d74b17 100644
> --- a/lib/ethdev/rte_ethdev.c
> +++ b/lib/ethdev/rte_ethdev.c
> @@ -1604,6 +1604,8 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
>   	}
>   
>   	rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, 0);
> +	dev->data->dev_configured = 1;
> +
>   	return 0;
>   reset_queues:
>   	eth_dev_rx_queue_config(dev, 0);
> @@ -1614,6 +1616,8 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
>   		dev->data->mtu = old_mtu;
>   
>   	rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, ret);
> +	dev->data->dev_configured = 0;
> +
>   	return ret;
>   }
>   
> @@ -1749,6 +1753,13 @@ rte_eth_dev_start(uint16_t port_id)
>   
>   	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
>   
> +	if (dev->data->dev_configured == 0) {
> +		RTE_ETHDEV_LOG(INFO,
> +			"Device with port_id=%"PRIu16" is not configured.\n",
> +			port_id);
> +		return -EINVAL;
> +	}
> +
>   	if (dev->data->dev_started != 0) {
>   		RTE_ETHDEV_LOG(INFO,
>   			"Device with port_id=%"PRIu16" already started\n",
> diff --git a/lib/ethdev/rte_ethdev_core.h b/lib/ethdev/rte_ethdev_core.h
> index 4679d94..b508769 100644
> --- a/lib/ethdev/rte_ethdev_core.h
> +++ b/lib/ethdev/rte_ethdev_core.h
> @@ -167,7 +167,11 @@ struct rte_eth_dev_data {
>   		scattered_rx : 1,  /**< RX of scattered packets is ON(1) / OFF(0) */
>   		all_multicast : 1, /**< RX all multicast mode ON(1) / OFF(0). */
>   		dev_started : 1,   /**< Device state: STARTED(1) / STOPPED(0). */
> -		lro         : 1;   /**< RX LRO is ON(1) / OFF(0) */
> +		lro         : 1,  /**< RX LRO is ON(1) / OFF(0) */
> +		dev_configured : 1;
> +		/**< Device configuration state:
> +		 * CONFIGURED(1) / NOT CONFIGURED(0).
> +		 */
>   	uint8_t rx_queue_state[RTE_MAX_QUEUES_PER_PORT];
>   		/**< Queues state: HAIRPIN(2) / STARTED(1) / STOPPED(0). */
>   	uint8_t tx_queue_state[RTE_MAX_QUEUES_PER_PORT];
>
diff mbox series

Patch

diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index a187976..7d74b17 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -1604,6 +1604,8 @@  rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 	}
 
 	rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, 0);
+	dev->data->dev_configured = 1;
+
 	return 0;
 reset_queues:
 	eth_dev_rx_queue_config(dev, 0);
@@ -1614,6 +1616,8 @@  rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 		dev->data->mtu = old_mtu;
 
 	rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, ret);
+	dev->data->dev_configured = 0;
+
 	return ret;
 }
 
@@ -1749,6 +1753,13 @@  rte_eth_dev_start(uint16_t port_id)
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
 
+	if (dev->data->dev_configured == 0) {
+		RTE_ETHDEV_LOG(INFO,
+			"Device with port_id=%"PRIu16" is not configured.\n",
+			port_id);
+		return -EINVAL;
+	}
+
 	if (dev->data->dev_started != 0) {
 		RTE_ETHDEV_LOG(INFO,
 			"Device with port_id=%"PRIu16" already started\n",
diff --git a/lib/ethdev/rte_ethdev_core.h b/lib/ethdev/rte_ethdev_core.h
index 4679d94..b508769 100644
--- a/lib/ethdev/rte_ethdev_core.h
+++ b/lib/ethdev/rte_ethdev_core.h
@@ -167,7 +167,11 @@  struct rte_eth_dev_data {
 		scattered_rx : 1,  /**< RX of scattered packets is ON(1) / OFF(0) */
 		all_multicast : 1, /**< RX all multicast mode ON(1) / OFF(0). */
 		dev_started : 1,   /**< Device state: STARTED(1) / STOPPED(0). */
-		lro         : 1;   /**< RX LRO is ON(1) / OFF(0) */
+		lro         : 1,  /**< RX LRO is ON(1) / OFF(0) */
+		dev_configured : 1;
+		/**< Device configuration state:
+		 * CONFIGURED(1) / NOT CONFIGURED(0).
+		 */
 	uint8_t rx_queue_state[RTE_MAX_QUEUES_PER_PORT];
 		/**< Queues state: HAIRPIN(2) / STARTED(1) / STOPPED(0). */
 	uint8_t tx_queue_state[RTE_MAX_QUEUES_PER_PORT];