ethdev: unify error code if port ID is invalid

Use ENODEV as the error code if specified port ID is invalid.

Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
This commit is contained in:
Andrew Rybchenko 2020-10-13 15:53:38 +01:00 committed by Ferruh Yigit
parent a72cb3e765
commit f6c763fbed
3 changed files with 60 additions and 42 deletions

View File

@ -99,8 +99,8 @@ test_stats_bitrate_calc_invalid_portid_1(void)
int ret = 0;
ret = rte_stats_bitrate_calc(bitrate_data, 33);
TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for higher "
"portid rte_stats_bitrate_calc ret:%d", EINVAL, ret);
TEST_ASSERT(ret == -ENODEV, "Test Failed: Expected -%d for higher "
"portid rte_stats_bitrate_calc ret:%d", ENODEV, ret);
return TEST_SUCCESS;
}
@ -112,8 +112,8 @@ test_stats_bitrate_calc_invalid_portid_2(void)
int ret = 0;
ret = rte_stats_bitrate_calc(bitrate_data, -1);
TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for invalid "
"portid rte_stats_bitrate_calc ret:%d", EINVAL, ret);
TEST_ASSERT(ret == -ENODEV, "Test Failed: Expected -%d for invalid "
"portid rte_stats_bitrate_calc ret:%d", ENODEV, ret);
return TEST_SUCCESS;
}
@ -125,9 +125,9 @@ test_stats_bitrate_calc_non_existing_portid(void)
int ret = 0;
ret = rte_stats_bitrate_calc(bitrate_data, 31);
TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for "
TEST_ASSERT(ret == -ENODEV, "Test Failed: Expected -%d for "
"non-existing portid rte_stats_bitrate_calc ret:%d",
EINVAL, ret);
ENODEV, ret);
return TEST_SUCCESS;
}

View File

@ -799,7 +799,7 @@ rte_eth_dev_get_name_by_port(uint16_t port_id, char *name)
{
char *tmp;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
if (name == NULL) {
RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
@ -946,7 +946,7 @@ rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id)
struct rte_eth_dev *dev;
int ret;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
if (!dev->data->dev_started) {
@ -987,7 +987,7 @@ rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id)
struct rte_eth_dev *dev;
int ret;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
@ -1021,7 +1021,7 @@ rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id)
struct rte_eth_dev *dev;
int ret;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
if (!dev->data->dev_started) {
@ -1060,7 +1060,7 @@ rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id)
struct rte_eth_dev *dev;
int ret;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
@ -1293,7 +1293,7 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
int diag;
int ret;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
@ -1679,7 +1679,7 @@ rte_eth_dev_start(uint16_t port_id)
int diag;
int ret, ret_stop;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
@ -1760,7 +1760,7 @@ rte_eth_dev_set_link_up(uint16_t port_id)
{
struct rte_eth_dev *dev;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
@ -1773,7 +1773,7 @@ rte_eth_dev_set_link_down(uint16_t port_id)
{
struct rte_eth_dev *dev;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
@ -1808,7 +1808,7 @@ rte_eth_dev_reset(uint16_t port_id)
struct rte_eth_dev *dev;
int ret;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_reset, -ENOTSUP);
@ -1931,7 +1931,7 @@ rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
struct rte_eth_rxconf local_conf;
void **rxq;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
if (rx_queue_id >= dev->data->nb_rx_queues) {
@ -2113,7 +2113,7 @@ rte_eth_rx_hairpin_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
int i;
int count;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
if (rx_queue_id >= dev->data->nb_rx_queues) {
@ -2184,7 +2184,7 @@ rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
void **txq;
int ret;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
if (tx_queue_id >= dev->data->nb_tx_queues) {
@ -2285,7 +2285,7 @@ rte_eth_tx_hairpin_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
int count;
int ret;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
if (tx_queue_id >= dev->data->nb_tx_queues) {
RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id);
@ -2520,7 +2520,7 @@ rte_eth_promiscuous_get(uint16_t port_id)
{
struct rte_eth_dev *dev;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
return dev->data->promiscuous;
@ -2571,7 +2571,7 @@ rte_eth_allmulticast_get(uint16_t port_id)
{
struct rte_eth_dev *dev;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
return dev->data->all_multicast;
@ -2659,7 +2659,7 @@ rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)
{
struct rte_eth_dev *dev;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
memset(stats, 0, sizeof(*stats));
@ -2712,7 +2712,7 @@ get_xstats_count(uint16_t port_id)
struct rte_eth_dev *dev;
int count;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
if (dev->dev_ops->xstats_get_names_by_id != NULL) {
count = (*dev->dev_ops->xstats_get_names_by_id)(dev, NULL,
@ -3124,7 +3124,7 @@ rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
uint16_t nb_rxqs, nb_txqs;
int ret;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
@ -4947,7 +4947,7 @@ rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
return -ENOTSUP;
#endif
/* Check input parameters. */
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
if (user_cb == NULL ||
queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
return -EINVAL;
@ -4981,7 +4981,7 @@ rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
return -ENOTSUP;
#endif
/* Check input parameters. */
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
if (user_cb == NULL ||
queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
return -EINVAL;
@ -5441,7 +5441,7 @@ rte_eth_dev_hairpin_capability_get(uint16_t port_id,
{
struct rte_eth_dev *dev;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_cap_get, -ENOTSUP);

View File

@ -2159,6 +2159,7 @@ rte_eth_dev_is_removed(uint16_t port_id);
* @return
* - 0: Success, receive queue correctly set up.
* - -EIO: if device is removed.
* - -ENODEV: if *port_id* is invalid.
* - -EINVAL: The memory pool pointer is null or the size of network buffers
* which can be allocated from this memory pool does not fit the various
* buffer sizes allowed by the device controller.
@ -2193,6 +2194,7 @@ int rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
*
* @return
* - (0) if successful.
* - (-ENODEV) if *port_id* is invalid.
* - (-ENOTSUP) if hardware doesn't support.
* - (-EINVAL) if bad parameter.
* - (-ENOMEM) if unable to allocate the resources.
@ -2274,6 +2276,7 @@ int rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
*
* @return
* - (0) if successful.
* - (-ENODEV) if *port_id* is invalid.
* - (-ENOTSUP) if hardware doesn't support.
* - (-EINVAL) if bad parameter.
* - (-ENOMEM) if unable to allocate the resources.
@ -2400,7 +2403,8 @@ int rte_eth_dev_is_valid_port(uint16_t port_id);
* to rte_eth_dev_configure().
* @return
* - 0: Success, the receive queue is started.
* - -EINVAL: The port_id or the queue_id out of range or belong to hairpin.
* - -ENODEV: if *port_id* is invalid.
* - -EINVAL: The queue_id out of range or belong to hairpin.
* - -EIO: if device is removed.
* - -ENOTSUP: The function not supported in PMD driver.
*/
@ -2417,7 +2421,8 @@ int rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id);
* to rte_eth_dev_configure().
* @return
* - 0: Success, the receive queue is stopped.
* - -EINVAL: The port_id or the queue_id out of range or belong to hairpin.
* - -ENODEV: if *port_id* is invalid.
* - -EINVAL: The queue_id out of range or belong to hairpin.
* - -EIO: if device is removed.
* - -ENOTSUP: The function not supported in PMD driver.
*/
@ -2435,7 +2440,8 @@ int rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id);
* to rte_eth_dev_configure().
* @return
* - 0: Success, the transmit queue is started.
* - -EINVAL: The port_id or the queue_id out of range or belong to hairpin.
* - -ENODEV: if *port_id* is invalid.
* - -EINVAL: The queue_id out of range or belong to hairpin.
* - -EIO: if device is removed.
* - -ENOTSUP: The function not supported in PMD driver.
*/
@ -2452,7 +2458,8 @@ int rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id);
* to rte_eth_dev_configure().
* @return
* - 0: Success, the transmit queue is stopped.
* - -EINVAL: The port_id or the queue_id out of range or belong to hairpin.
* - -ENODEV: if *port_id* is invalid.
* - -EINVAL: The queue_id out of range or belong to hairpin.
* - -EIO: if device is removed.
* - -ENOTSUP: The function not supported in PMD driver.
*/
@ -2558,7 +2565,7 @@ int rte_eth_dev_close(uint16_t port_id);
*
* @return
* - (0) if successful.
* - (-EINVAL) if port identifier is invalid.
* - (-ENODEV) if *port_id* is invalid.
* - (-ENOTSUP) if hardware doesn't support this function.
* - (-EPERM) if not ran from the primary process.
* - (-EIO) if re-initialisation failed or device is removed.
@ -3834,6 +3841,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id,
* rte_eth_dev_info_get().
* @return
* - (0) if successful.
* - (-ENODEV) if *port_id* is invalid.
* - (-ENOTSUP) if hardware doesn't support.
* - (-EINVAL) if bad parameter.
* - (-EIO) if device is removed.
@ -3855,6 +3863,7 @@ int rte_eth_dev_rss_reta_update(uint16_t port_id,
* rte_eth_dev_info_get().
* @return
* - (0) if successful.
* - (-ENODEV) if *port_id* is invalid.
* - (-ENOTSUP) if hardware doesn't support.
* - (-EINVAL) if bad parameter.
* - (-EIO) if device is removed.
@ -4223,8 +4232,9 @@ rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
*
* @return
* - 0: Success. Callback was removed.
* - -ENODEV: If *port_id* is invalid.
* - -ENOTSUP: Callback support is not available.
* - -EINVAL: The port_id or the queue_id is out of range, or the callback
* - -EINVAL: The queue_id is out of range, or the callback
* is NULL or not found for the port/queue.
*/
int rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
@ -4258,8 +4268,9 @@ int rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
*
* @return
* - 0: Success. Callback was removed.
* - -ENODEV: If *port_id* is invalid.
* - -ENOTSUP: Callback support is not available.
* - -EINVAL: The port_id or the queue_id is out of range, or the callback
* - -EINVAL: The queue_id is out of range, or the callback
* is NULL or not found for the port/queue.
*/
int rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
@ -4279,8 +4290,9 @@ int rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
*
* @return
* - 0: Success
* - -ENODEV: If *port_id* is invalid.
* - -ENOTSUP: routine is not supported by the device PMD.
* - -EINVAL: The port_id or the queue_id is out of range, or the queue
* - -EINVAL: The queue_id is out of range, or the queue
* is hairpin queue.
*/
int rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
@ -4300,8 +4312,9 @@ int rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
*
* @return
* - 0: Success
* - -ENODEV: If *port_id* is invalid.
* - -ENOTSUP: routine is not supported by the device PMD.
* - -EINVAL: The port_id or the queue_id is out of range, or the queue
* - -EINVAL: The queue_id is out of range, or the queue
* is hairpin queue.
*/
int rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
@ -4321,8 +4334,9 @@ int rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
*
* @return
* - 0: Success
* - -ENODEV: If *port_id* is invalid.
* - -ENOTSUP: routine is not supported by the device PMD.
* - -EINVAL: The port_id or the queue_id is out of range.
* - -EINVAL: The queue_id is out of range.
*/
__rte_experimental
int rte_eth_rx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
@ -4342,8 +4356,9 @@ int rte_eth_rx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
*
* @return
* - 0: Success
* - -ENODEV: If *port_id* is invalid.
* - -ENOTSUP: routine is not supported by the device PMD.
* - -EINVAL: The port_id or the queue_id is out of range.
* - -EINVAL: The queue_id is out of range.
*/
__rte_experimental
int rte_eth_tx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
@ -4732,6 +4747,7 @@ rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id);
* Buffer of size RTE_ETH_NAME_MAX_LEN to store the name.
* @return
* - (0) if successful.
* - (-ENODEV) if *port_id* is invalid.
* - (-EINVAL) on failure.
*/
int
@ -4941,7 +4957,8 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
* The queue id on the specific port.
* @return
* The number of used descriptors in the specific queue, or:
* (-EINVAL) if *port_id* or *queue_id* is invalid
* - (-ENODEV) if *port_id* is invalid.
* (-EINVAL) if *queue_id* is invalid
* (-ENOTSUP) if the device does not support this function
*/
static inline int
@ -4949,7 +4966,7 @@ rte_eth_rx_queue_count(uint16_t port_id, uint16_t queue_id)
{
struct rte_eth_dev *dev;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
dev = &rte_eth_devices[port_id];
RTE_FUNC_PTR_OR_ERR_RET(*dev->rx_queue_count, -ENOTSUP);
if (queue_id >= dev->data->nb_rx_queues ||
@ -5257,6 +5274,7 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id,
* meet devices requirements with rte_errno set appropriately:
* - EINVAL: offload flags are not correctly set
* - ENOTSUP: the offload feature is not supported by the hardware
* - ENODEV: if *port_id* is invalid (with debug enabled only)
*
*/
@ -5271,7 +5289,7 @@ rte_eth_tx_prepare(uint16_t port_id, uint16_t queue_id,
#ifdef RTE_LIBRTE_ETHDEV_DEBUG
if (!rte_eth_dev_is_valid_port(port_id)) {
RTE_ETHDEV_LOG(ERR, "Invalid TX port_id=%u\n", port_id);
rte_errno = EINVAL;
rte_errno = ENODEV;
return 0;
}
#endif