Skip to content

Commit

Permalink
ethdev: change promiscuous mode controllers to return errors
Browse files Browse the repository at this point in the history
Change rte_eth_promiscuous_enable()/rte_eth_promiscuous_disable()
return value from void to int and return negative errno values
in case of error conditions.
Modify usage of these functions across the ethdev according
to new return type.

Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
  • Loading branch information
ol-vanyaio authored and Ferruh Yigit committed Oct 7, 2019
1 parent 7440e85 commit 69d0e70
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 23 deletions.
1 change: 0 additions & 1 deletion doc/guides/rel_notes/deprecation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ Deprecation Notices
negative errno values to indicate various error conditions (e.g.
invalid port ID, unsupported operation, failed operation):

- ``rte_eth_promiscuous_enable`` and ``rte_eth_promiscuous_disable``
- ``rte_eth_allmulticast_enable`` and ``rte_eth_allmulticast_disable``
- ``rte_eth_link_get`` and ``rte_eth_link_get_nowait``
- ``rte_eth_dev_stop``
Expand Down
4 changes: 4 additions & 0 deletions doc/guides/rel_notes/release_19_11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ API Changes
* ethdev: changed ``rte_eth_dev_infos_get`` return value from ``void`` to
``int`` to provide a way to report various error conditions.

* ethdev: changed ``rte_eth_promiscuous_enable`` and
``rte_eth_promiscuous_disable`` return value from ``void`` to ``int`` to
provide a way to report various error conditions.


ABI Changes
-----------
Expand Down
6 changes: 4 additions & 2 deletions doc/guides/sample_app_ug/flow_classify.rst
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ Forwarding application is shown below:
addr.addr_bytes[4], addr.addr_bytes[5]);
/* Enable RX in promiscuous mode for the Ethernet device. */
rte_eth_promiscuous_enable(port);
retval = rte_eth_promiscuous_enable(port);
if (retval != 0)
return retval;
return 0;
}
Expand Down Expand Up @@ -343,7 +345,7 @@ Finally the RX port is set in promiscuous mode:

.. code-block:: c
rte_eth_promiscuous_enable(port);
retval = rte_eth_promiscuous_enable(port);
The Add Rules function
~~~~~~~~~~~~~~~~~~~~~~
Expand Down
15 changes: 13 additions & 2 deletions doc/guides/sample_app_ug/flow_filtering.rst
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,13 @@ application is shown below:
}
}
rte_eth_promiscuous_enable(port_id);
ret = rte_eth_promiscuous_enable(port_id);
if (ret != 0) {
rte_exit(EXIT_FAILURE,
":: cannot enable promiscuous mode: err=%d, port=%u\n",
ret, port_id);
}
ret = rte_eth_dev_start(port_id);
if (ret < 0) {
rte_exit(EXIT_FAILURE,
Expand Down Expand Up @@ -278,7 +284,12 @@ We are setting the RX port to promiscuous mode:

.. code-block:: c
rte_eth_promiscuous_enable(port_id);
ret = rte_eth_promiscuous_enable(port_id);
if (ret != 0) {
rte_exit(EXIT_FAILURE,
":: cannot enable promiscuous mode: err=%d, port=%u\n",
ret, port_id);
}
The last step is to start the port.

Expand Down
5 changes: 3 additions & 2 deletions doc/guides/sample_app_ug/rxtx_callbacks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ comments:
return retval;
/* Enable RX in promiscuous mode for the Ethernet device. */
rte_eth_promiscuous_enable(port);
retval = rte_eth_promiscuous_enable(port);
if (retval != 0)
return retval;
/* Add the callbacks for RX and TX.*/
rte_eth_add_rx_callback(port, 0, add_timestamps, NULL);
Expand Down
6 changes: 4 additions & 2 deletions doc/guides/sample_app_ug/skeleton.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ Forwarding application is shown below:
return retval;
/* Enable RX in promiscuous mode for the Ethernet device. */
rte_eth_promiscuous_enable(port);
retval = rte_eth_promiscuous_enable(port);
if (retval != 0)
return retval;
return 0;
}
Expand Down Expand Up @@ -177,7 +179,7 @@ Finally the RX port is set in promiscuous mode:

.. code-block:: c
rte_eth_promiscuous_enable(port);
retval = rte_eth_promiscuous_enable(port);
The Lcores Main
Expand Down
52 changes: 40 additions & 12 deletions lib/librte_ethdev/rte_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1381,24 +1381,41 @@ rte_eth_dev_mac_restore(struct rte_eth_dev *dev,
}
}

static void
static int
rte_eth_dev_config_restore(struct rte_eth_dev *dev,
struct rte_eth_dev_info *dev_info, uint16_t port_id)
{
int ret;

if (!(*dev_info->dev_flags & RTE_ETH_DEV_NOLIVE_MAC_ADDR))
rte_eth_dev_mac_restore(dev, dev_info);

/* replay promiscuous configuration */
if (rte_eth_promiscuous_get(port_id) == 1)
rte_eth_promiscuous_enable(port_id);
else if (rte_eth_promiscuous_get(port_id) == 0)
rte_eth_promiscuous_disable(port_id);
if (rte_eth_promiscuous_get(port_id) == 1) {
ret = rte_eth_promiscuous_enable(port_id);
if (ret != 0 && ret != -ENOTSUP) {
RTE_ETHDEV_LOG(ERR,
"Failed to enable promiscuous mode for device (port %u): %s\n",
port_id, rte_strerror(-ret));
return ret;
}
} else if (rte_eth_promiscuous_get(port_id) == 0) {
ret = rte_eth_promiscuous_disable(port_id);
if (ret != 0 && ret != -ENOTSUP) {
RTE_ETHDEV_LOG(ERR,
"Failed to disable promiscuous mode for device (port %u): %s\n",
port_id, rte_strerror(-ret));
return ret;
}
}

/* replay all multicast configuration */
if (rte_eth_allmulticast_get(port_id) == 1)
rte_eth_allmulticast_enable(port_id);
else if (rte_eth_allmulticast_get(port_id) == 0)
rte_eth_allmulticast_disable(port_id);

return 0;
}

int
Expand Down Expand Up @@ -1436,7 +1453,14 @@ rte_eth_dev_start(uint16_t port_id)
else
return eth_err(port_id, diag);

rte_eth_dev_config_restore(dev, &dev_info, port_id);
ret = rte_eth_dev_config_restore(dev, &dev_info, port_id);
if (ret != 0) {
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);
return ret;
}

if (dev->data->dev_conf.intr_conf.lsc == 0) {
RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
Expand Down Expand Up @@ -1864,30 +1888,34 @@ rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt)
return eth_err(port_id, ret);
}

void
int
rte_eth_promiscuous_enable(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->promiscuous_enable);
RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->promiscuous_enable, -ENOTSUP);
(*dev->dev_ops->promiscuous_enable)(dev);
dev->data->promiscuous = 1;

return 0;
}

void
int
rte_eth_promiscuous_disable(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->promiscuous_disable);
RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->promiscuous_disable, -ENOTSUP);
dev->data->promiscuous = 0;
(*dev->dev_ops->promiscuous_disable)(dev);

return 0;
}

int
Expand Down
14 changes: 12 additions & 2 deletions lib/librte_ethdev/rte_ethdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -2022,16 +2022,26 @@ int rte_eth_dev_reset(uint16_t port_id);
*
* @param port_id
* The port identifier of the Ethernet device.
* @return
* - (0) if successful.
* - (-ENOTSUP) if support for promiscuous_enable() does not exist
* for the device.
* - (-ENODEV) if *port_id* invalid.
*/
void rte_eth_promiscuous_enable(uint16_t port_id);
int rte_eth_promiscuous_enable(uint16_t port_id);

/**
* Disable receipt in promiscuous mode for an Ethernet device.
*
* @param port_id
* The port identifier of the Ethernet device.
* @return
* - (0) if successful.
* - (-ENOTSUP) if support for promiscuous_disable() does not exist
* for the device.
* - (-ENODEV) if *port_id* invalid.
*/
void rte_eth_promiscuous_disable(uint16_t port_id);
int rte_eth_promiscuous_disable(uint16_t port_id);

/**
* Return the value of promiscuous mode for an Ethernet device.
Expand Down

0 comments on commit 69d0e70

Please sign in to comment.