From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail04.ics.ntt-tx.co.jp (mail05.ics.ntt-tx.co.jp [210.232.35.69]) by dpdk.org (Postfix) with ESMTP id 80D6F5699 for ; Wed, 21 Nov 2018 08:01:22 +0100 (CET) Received: from gwchk03.silk.ntt-tx.co.jp (gwchk03.silk.ntt-tx.co.jp [10.107.0.111]) by mail04.ics.ntt-tx.co.jp (unknown) with ESMTP id wAL71LZD012594; Wed, 21 Nov 2018 16:01:21 +0900 Received: (from root@localhost) by gwchk03.silk.ntt-tx.co.jp (unknown) id wAL71LU8031899; Wed, 21 Nov 2018 16:01:21 +0900 Received: from gwchk.silk.ntt-tx.co.jp [10.107.0.110] by gwchk03.silk.ntt-tx.co.jp with ESMTP id RAA28675; Wed, 21 Nov 2018 15:52:20 +0900 Received: from imss04.silk.ntt-tx.co.jp (localhost [127.0.0.1]) by imss04.silk.ntt-tx.co.jp (unknown) with ESMTP id wAL6qKlt011087; Wed, 21 Nov 2018 15:52:20 +0900 Received: from mgate01.silk.ntt-tx.co.jp (smtp02.silk.ntt-tx.co.jp [10.107.0.37]) by imss04.silk.ntt-tx.co.jp (unknown) with ESMTP id wAL6qKRG011075; Wed, 21 Nov 2018 15:52:20 +0900 Message-Id: <201811210652.wAL6qKRG011075@imss04.silk.ntt-tx.co.jp> Received: from localhost by mgate01.silk.ntt-tx.co.jp (unknown) id wAL6qJ5R008934 ; Wed, 21 Nov 2018 15:52:20 +0900 From: x-fn-spp@sl.ntt-tx.co.jp To: ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp Cc: spp@dpdk.org Date: Wed, 21 Nov 2018 15:52:17 +0900 X-Mailer: git-send-email 2.18.0 In-Reply-To: <201811070507.wA757WWo008866@imss03.silk.ntt-tx.co.jp> References: <201811070507.wA757WWo008866@imss03.silk.ntt-tx.co.jp> X-TM-AS-MML: No Subject: [spp] [PATCH v2 4/6] shared: add dev_detach_by_port_id X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Nov 2018 07:01:23 -0000 From: Hideyuki Yamashita SPP uses deprecated APIs removed in DPDK v18.11. Using rte_eth_hotplug_remove() is recommended instead of rte_eth_dev_detach()[1]. This patch is to add dev_detach_by_port_id() to shared directory so that spp_primary, spp_nfv, spp_vm and spp_vf can refer this new function. [1]https://mails.dpdk.org/archives/dev/2018-October/117115.html Signed-off-by: Hideyuki Yamashita Signed-off-by: Naoki Takada --- src/shared/common.c | 38 ++++++++++++++++++++++++++++++++++++++ src/shared/common.h | 12 ++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/shared/common.c b/src/shared/common.c index c88ce14..0e32fa6 100644 --- a/src/shared/common.c +++ b/src/shared/common.c @@ -526,3 +526,41 @@ dev_attach_by_devargs(const char *devargs, uint16_t *port_id) return ret; } + +/* detach the device, then store the name of the device */ +int +dev_detach_by_port_id(uint16_t port_id) +{ + struct rte_device *dev; + struct rte_bus *bus; + uint32_t dev_flags; + int ret = -1; + + if (rte_eth_devices[port_id].data == NULL) { + RTE_LOG(INFO, APP, + "rte_eth_devices[%d].data is NULL\n", port_id); + return 0; + } + dev_flags = rte_eth_devices[port_id].data->dev_flags; + if (dev_flags & RTE_ETH_DEV_BONDED_SLAVE) { + RTE_LOG(ERR, APP, + "Port %"PRIu16" is bonded, cannot detach\n", port_id); + return -ENOTSUP; + } + + dev = rte_eth_devices[port_id].device; + if (dev == NULL) + return -EINVAL; + + bus = rte_bus_find_by_device(dev); + if (bus == NULL) + return -ENOENT; + + ret = rte_eal_hotplug_remove(bus->name, dev->name); + if (ret < 0) + return ret; + + rte_eth_dev_release_port(&rte_eth_devices[port_id]); + + return 0; +} diff --git a/src/shared/common.h b/src/shared/common.h index 60514e5..09dbf8a 100644 --- a/src/shared/common.h +++ b/src/shared/common.h @@ -234,4 +234,16 @@ int spp_atoi(const char *str, int *val); int dev_attach_by_devargs(const char *devargs, uint16_t *port_id); +/** + * Detach a Ethernet device specified by port identifier. + * This function must be called when the device is in the + * closed state. + * + * @param port_id + * The port identifier of the device to detach. + * @return + * 0 on success and devname is filled, negative on error + */ +int dev_detach_by_port_id(uint16_t port_id); + #endif -- 2.18.0