ethdev: add devop to check removal status

There is time between the physical removal of the device until PMDs get
a RMV interrupt. At this time DPDK PMDs and applications still don't
know about the removal.

Current removal detection is achieved only by registration to device RMV
event and the notification comes asynchronously. So, there is no option
to detect a device removal synchronously.
Applications and other DPDK entities may want to check a device removal
synchronously and to take an immediate decision accordingly.

Add new dev op called is_removed to allow DPDK entities to check an
Ethernet device removal status immediately.

Signed-off-by: Matan Azrad <matan@mellanox.com>
Acked-by: Thomas Monjalon <thomas@monjalon.net>
This commit is contained in:
Matan Azrad 2018-01-20 21:12:19 +00:00 committed by Ferruh Yigit
parent 584f7e9fd9
commit 7106edc123
3 changed files with 47 additions and 3 deletions

View File

@ -170,7 +170,8 @@ uint16_t
rte_eth_find_next(uint16_t port_id)
{
while (port_id < RTE_MAX_ETHPORTS &&
rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED)
rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
rte_eth_devices[port_id].state != RTE_ETH_DEV_REMOVED)
port_id++;
if (port_id >= RTE_MAX_ETHPORTS)
@ -318,8 +319,7 @@ int
rte_eth_dev_is_valid_port(uint16_t port_id)
{
if (port_id >= RTE_MAX_ETHPORTS ||
(rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
rte_eth_devices[port_id].state != RTE_ETH_DEV_DEFERRED))
(rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED))
return 0;
else
return 1;
@ -1181,6 +1181,29 @@ rte_eth_dev_reset(uint16_t port_id)
return ret;
}
int
rte_eth_dev_is_removed(uint16_t port_id)
{
struct rte_eth_dev *dev;
int ret;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
dev = &rte_eth_devices[port_id];
if (dev->state == RTE_ETH_DEV_REMOVED)
return 1;
RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->is_removed, 0);
ret = dev->dev_ops->is_removed(dev);
if (ret != 0)
/* Device is physically removed. */
dev->state = RTE_ETH_DEV_REMOVED;
return ret;
}
int
rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
uint16_t nb_rx_desc, unsigned int socket_id,

View File

@ -1180,6 +1180,9 @@ typedef void (*eth_dev_close_t)(struct rte_eth_dev *dev);
typedef int (*eth_dev_reset_t)(struct rte_eth_dev *dev);
/** <@internal Function used to reset a configured Ethernet device. */
typedef int (*eth_is_removed_t)(struct rte_eth_dev *dev);
/**< @internal Function used to detect an Ethernet device removal. */
typedef void (*eth_promiscuous_enable_t)(struct rte_eth_dev *dev);
/**< @internal Function used to enable the RX promiscuous mode of an Ethernet device. */
@ -1509,6 +1512,8 @@ struct eth_dev_ops {
eth_dev_close_t dev_close; /**< Close device. */
eth_dev_reset_t dev_reset; /**< Reset device. */
eth_link_update_t link_update; /**< Get device link state. */
eth_is_removed_t is_removed;
/**< Check if the device was physically removed. */
eth_promiscuous_enable_t promiscuous_enable; /**< Promiscuous ON. */
eth_promiscuous_disable_t promiscuous_disable;/**< Promiscuous OFF. */
@ -1695,6 +1700,7 @@ enum rte_eth_dev_state {
RTE_ETH_DEV_UNUSED = 0,
RTE_ETH_DEV_ATTACHED,
RTE_ETH_DEV_DEFERRED,
RTE_ETH_DEV_REMOVED,
};
/**
@ -2003,6 +2009,20 @@ int rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_queue,
*/
void _rte_eth_dev_reset(struct rte_eth_dev *dev);
/**
* @warning
* @b EXPERIMENTAL: this API may change without prior notice.
*
* Check if an Ethernet device was physically removed.
*
* @param port_id
* The port identifier of the Ethernet device.
* @return
* 1 when the Ethernet device is removed, otherwise 0.
*/
int
rte_eth_dev_is_removed(uint16_t port_id);
/**
* Allocate and set up a receive queue for an Ethernet device.
*

View File

@ -208,6 +208,7 @@ DPDK_18.02 {
EXPERIMENTAL {
global:
rte_eth_dev_is_removed;
rte_eth_dev_rx_offload_name;
rte_eth_dev_tx_offload_name;
rte_mtr_capabilities_get;