From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matan Azrad Subject: [PATCH v5 1/6] ethdev: add devop to check removal status Date: Wed, 17 Jan 2018 20:19:12 +0000 Message-ID: <1516220357-13013-2-git-send-email-matan@mellanox.com> References: <1515587465-9304-1-git-send-email-matan@mellanox.com> <1516220357-13013-1-git-send-email-matan@mellanox.com> Mime-Version: 1.0 Content-Type: text/plain Cc: Thomas Monjalon , dev@dpdk.org To: Ferruh Yigit , Adrien Mazarguil , Gaetan Rivet Return-path: Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10077.outbound.protection.outlook.com [40.107.1.77]) by dpdk.org (Postfix) with ESMTP id 02CA61B2CC for ; Wed, 17 Jan 2018 21:19:53 +0100 (CET) In-Reply-To: <1516220357-13013-1-git-send-email-matan@mellanox.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Acked-by: Thomas Monjalon --- lib/librte_ether/rte_ethdev.c | 28 +++++++++++++++++++++++++--- lib/librte_ether/rte_ethdev.h | 17 +++++++++++++++++ lib/librte_ether/rte_ethdev_version.map | 7 +++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index b349599..c93cec1 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -114,7 +114,8 @@ enum { 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) @@ -262,8 +263,7 @@ struct rte_eth_dev * 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; @@ -1094,6 +1094,28 @@ struct rte_eth_dev * } 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]; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->is_removed, 0); + + if (dev->state == RTE_ETH_DEV_REMOVED) + return 1; + + ret = dev->dev_ops->is_removed(dev); + if (ret != 0) + 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, const struct rte_eth_rxconf *rx_conf, diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index f0eeefe..da0c5cf 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1169,6 +1169,9 @@ struct rte_eth_dcb_info { 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. */ @@ -1498,6 +1501,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. */ @@ -1684,6 +1689,7 @@ enum rte_eth_dev_state { RTE_ETH_DEV_UNUSED = 0, RTE_ETH_DEV_ATTACHED, RTE_ETH_DEV_DEFERRED, + RTE_ETH_DEV_REMOVED, }; /** @@ -1970,6 +1976,17 @@ int rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_queue, void _rte_eth_dev_reset(struct rte_eth_dev *dev); /** + * Check if an Ethernet device was physically removed. + * + * @param port_id + * The port identifier of the Ethernet device. + * @return + * - 0 when the Ethernet device is removed, otherwise 1. + */ +int +rte_eth_dev_is_removed(uint16_t port_id); + +/** * Allocate and set up a receive queue for an Ethernet device. * * The function allocates a contiguous block of memory for *nb_rx_desc* diff --git a/lib/librte_ether/rte_ethdev_version.map b/lib/librte_ether/rte_ethdev_version.map index e9681ac..78547ff 100644 --- a/lib/librte_ether/rte_ethdev_version.map +++ b/lib/librte_ether/rte_ethdev_version.map @@ -198,6 +198,13 @@ DPDK_17.11 { } DPDK_17.08; +DPDK_18.02 { + global: + + rte_eth_dev_is_removed; + +} DPDK_17.11; + EXPERIMENTAL { global: -- 1.8.3.1