From 58af59172b038709768f6709420de89b7b982e5a Mon Sep 17 00:00:00 2001 From: Ivan Ilchenko Date: Thu, 15 Oct 2020 14:30:35 +0100 Subject: [PATCH] ethdev: allow stop function to return an error Change rte_eth_dev_stop() return value from void to int and return negative errno values in case of error conditions. Also update the usage of the function in ethdev according to the new return type. Signed-off-by: Ivan Ilchenko Signed-off-by: Andrew Rybchenko Acked-by: Thomas Monjalon Reviewed-by: Ferruh Yigit --- doc/guides/rel_notes/deprecation.rst | 6 ------ doc/guides/rel_notes/release_20_11.rst | 3 +++ lib/librte_ethdev/rte_ethdev.c | 27 +++++++++++++++++++------- lib/librte_ethdev/rte_ethdev.h | 5 ++++- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst index b5582491ff..de0f3277bb 100644 --- a/doc/guides/rel_notes/deprecation.rst +++ b/doc/guides/rel_notes/deprecation.rst @@ -123,12 +123,6 @@ Deprecation Notices ``rte_eth_dev_l2_tunnel_offload_set`` which were not marked as deprecated, will be removed in DPDK 20.11. -* ethdev: Update API functions returning ``void`` to return ``int`` with - negative errno values to indicate various error conditions (e.g. - invalid port ID, unsupported operation, failed operation): - - - ``rte_eth_dev_stop`` - * ethdev: New offload flags ``DEV_RX_OFFLOAD_FLOW_MARK`` will be added in 19.11. This will allow application to enable or disable PMDs from updating ``rte_mbuf::hash::fdir``. diff --git a/doc/guides/rel_notes/release_20_11.rst b/doc/guides/rel_notes/release_20_11.rst index 5f1ef125ba..c1c2b0d2b1 100644 --- a/doc/guides/rel_notes/release_20_11.rst +++ b/doc/guides/rel_notes/release_20_11.rst @@ -422,6 +422,9 @@ API Changes * ethdev: Added capability to query age flow action. +* ethdev: Changed ``rte_eth_dev_stop`` return value from ``void`` to + ``int`` to provide a way to report various error conditions. + * ethdev: Added ``int`` return type to ``rte_eth_dev_close()``. * ethdev: Renamed internal functions: diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 9e838be8bc..9e1167169f 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -1677,7 +1677,7 @@ rte_eth_dev_start(uint16_t port_id) struct rte_eth_dev *dev; struct rte_eth_dev_info dev_info; int diag; - int ret; + int ret, ret_stop; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); @@ -1711,7 +1711,13 @@ rte_eth_dev_start(uint16_t port_id) RTE_ETHDEV_LOG(ERR, "Error during restoring configuration for device (port %u): %s\n", port_id, rte_strerror(-ret)); - rte_eth_dev_stop(port_id); + ret_stop = rte_eth_dev_stop(port_id); + if (ret_stop != 0) { + RTE_ETHDEV_LOG(ERR, + "Failed to stop device (port %u): %s\n", + port_id, rte_strerror(-ret_stop)); + } + return ret; } @@ -1724,26 +1730,28 @@ rte_eth_dev_start(uint16_t port_id) return 0; } -void +int rte_eth_dev_stop(uint16_t port_id) { struct rte_eth_dev *dev; - RTE_ETH_VALID_PORTID_OR_RET(port_id); + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); dev = &rte_eth_devices[port_id]; - RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop); + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_stop, -ENOTSUP); if (dev->data->dev_started == 0) { RTE_ETHDEV_LOG(INFO, "Device with port_id=%"PRIu16" already stopped\n", port_id); - return; + return 0; } dev->data->dev_started = 0; (*dev->dev_ops->dev_stop)(dev); rte_ethdev_trace_stop(port_id); + + return 0; } int @@ -1804,7 +1812,12 @@ rte_eth_dev_reset(uint16_t port_id) RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_reset, -ENOTSUP); - rte_eth_dev_stop(port_id); + ret = rte_eth_dev_stop(port_id); + if (ret != 0) { + RTE_ETHDEV_LOG(ERR, + "Failed to stop device (port %u) before reset: %s - ignore\n", + port_id, rte_strerror(-ret)); + } ret = dev->dev_ops->dev_reset(dev); return eth_err(port_id, ret); diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h index f4c0624308..77f9df7e5a 100644 --- a/lib/librte_ethdev/rte_ethdev.h +++ b/lib/librte_ethdev/rte_ethdev.h @@ -2479,8 +2479,11 @@ int rte_eth_dev_start(uint16_t port_id); * * @param port_id * The port identifier of the Ethernet device. + * @return + * - 0: Success, Ethernet device stopped. + * - <0: Error code of the driver device stop function. */ -void rte_eth_dev_stop(uint16_t port_id); +int rte_eth_dev_stop(uint16_t port_id); /** * Link up an Ethernet device. -- 2.20.1