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 5BC36325F for ; Wed, 7 Nov 2018 06:08:46 +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 wA758jAl017858; Wed, 7 Nov 2018 14:08:45 +0900 Received: (from root@localhost) by gwchk03.silk.ntt-tx.co.jp (unknown) id wA758j20030939; Wed, 7 Nov 2018 14:08:45 +0900 Received: from gwchk.silk.ntt-tx.co.jp [10.107.0.110] by gwchk03.silk.ntt-tx.co.jp with ESMTP id QAA30272; Wed, 7 Nov 2018 14:07:33 +0900 Received: from imss03.silk.ntt-tx.co.jp (localhost [127.0.0.1]) by imss03.silk.ntt-tx.co.jp (unknown) with ESMTP id wA757Wsd008892; Wed, 7 Nov 2018 14:07:32 +0900 Received: from mgate02.silk.ntt-tx.co.jp (smtp02.silk.ntt-tx.co.jp [10.107.0.37]) by imss03.silk.ntt-tx.co.jp (unknown) with ESMTP id wA757WFn008883; Wed, 7 Nov 2018 14:07:32 +0900 Message-Id: <201811070507.wA757WFn008883@imss03.silk.ntt-tx.co.jp> Received: from localhost by mgate02.silk.ntt-tx.co.jp (unknown) id wA757WhP024524 ; Wed, 7 Nov 2018 14:07:32 +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, 7 Nov 2018 14:07:30 +0900 X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181107050732.28344-1-x-fn-spp@sl.ntt-tx.co.jp> References: <20181107050732.28344-1-x-fn-spp@sl.ntt-tx.co.jp> X-TM-AS-MML: No Subject: [spp] [PATCH 4/6] shared: addition of detach() 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, 07 Nov 2018 05:08:47 -0000 From: Hideyuki Yamashita >>From DPDK 18.08, rte_eth_dev_detach becomes deprecated and will be deleted in 18.11. There exists several places in spp where uses the API and those should be replaced with rte_eth_hotplug_remove. As the first step, this patch creates new function named spp_rte_eth_dev_detach under shared directory so that primary,nfv,vm, vf can refer this new function. Signed-off-by: Hideyuki Yamashita Signed-off-by: Naoki Takada --- src/shared/common.c | 38 ++++++++++++++++++++++++++++++++++++++ src/shared/common.h | 15 +++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/shared/common.c b/src/shared/common.c index aba2309..b91b16c 100644 --- a/src/shared/common.c +++ b/src/shared/common.c @@ -526,3 +526,41 @@ attach(const char *devargs, uint16_t *port_id) return ret; } + +/* detach the device, then store the name of the device */ +int +detach(uint16_t port_id, char *name __rte_unused) +{ + 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 a97943a..104337a 100644 --- a/src/shared/common.h +++ b/src/shared/common.h @@ -234,4 +234,19 @@ int spp_atoi(const char *str, int *val); int attach(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. + * @param devname + * A pointer to a buffer that will be filled with the device name. + * This buffer must be at least RTE_DEV_NAME_MAX_LEN long. + * @return + * 0 on success and devname is filled, negative on error + */ +int detach(uint16_t port_id, char *devname); + #endif -- 2.18.0