From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f175.google.com (mail-wr0-f175.google.com [209.85.128.175]) by dpdk.org (Postfix) with ESMTP id B0601548B for ; Wed, 21 Jun 2017 01:29:56 +0200 (CEST) Received: by mail-wr0-f175.google.com with SMTP id r103so111473559wrb.0 for ; Tue, 20 Jun 2017 16:29:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=4PMkY431ukR31e26nxQ1v8B84g/q8Wyj3pAKi7BU7WI=; b=aebQUm1iRl+x78cBmCTUOmd8DI7rT6m4wrWtN/hf4SAmw5to8cUKbWOALR5EIt4zDs 2NRGqGoIROTv4xa4+LJtDw1dNGKtTex4Xc3cbilWzfkOA0BC+OR0v69biVILrinvFGcR p78m5OwtWHqJdSwnXSMdQ8oZbiwph/vlFH8Kj5xL/Mlm8Zu8MhzFchEISJMEiDxH+K0K OkpAoJmf76bdk8jy+JR2shvVr8mAimOcC0BevOArFUx41RYlFVcfvtwj+P7x1QxolhN4 sO6S++K/EKsM7hAPM/nAuxIGab/KfX6DxN23L0kdJ6VjTHcvw2pNmARNruxUxwRI6qbU qGWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=4PMkY431ukR31e26nxQ1v8B84g/q8Wyj3pAKi7BU7WI=; b=itVuwCmniBvRRFvZEkv39vNT1Y0DR+UkTb4SRKZUKYNjRck+PisysuD5dFPzE3AZaz S2vh2GmNshRaEuX49foqEx+Z0xzExAo/YZ9zXl/Xdl8EHDTr4jKedQsKimxVU0Ebnw8c 2eNev1v049BrawWBqat3MBjO5qV4mayy8CW9mSMHAv7znfg/xWcMS37uei0EoOW2Hacr GIiFTnDuzzNilSUmWihwFMABp3xKDJqvcTLMmNpYaGeCeeC+aIJAGY+r8T3eVfSckDv9 5pw5XLwS3u5VAESUvUl0iRC5csLrPyEj4wi3CeAuRfMnWvKe6QtnglUwv7nqwB1ERt1D RzCA== X-Gm-Message-State: AKS2vOx4aDWQcTB5trYBNUzeVrTtuz/t3ZjuqxVNUIE/y9MDffKZ1AKY pP87ckf+X2GOWybUxM4= X-Received: by 10.223.163.152 with SMTP id l24mr14601547wrb.203.1498001396136; Tue, 20 Jun 2017 16:29:56 -0700 (PDT) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id l127sm8592248wml.26.2017.06.20.16.29.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Jun 2017 16:29:55 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck , Gaetan Rivet Date: Wed, 21 Jun 2017 01:29:30 +0200 Message-Id: <03c66edf68830f0a2172692e4aa994551b610df8.1497999601.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v4 9/9] ethdev: use embedded rte_device to detach driver X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Jun 2017 23:29:57 -0000 From: Jan Blunck Signed-off-by: Jan Blunck Signed-off-by: Gaetan Rivet --- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/eal_common_dev.c | 43 ++++++++++++++++----------- lib/librte_eal/common/include/rte_dev.h | 11 +++++++ lib/librte_ether/rte_ethdev.c | 31 +++++++------------ 4 files changed, 47 insertions(+), 39 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 21640d6..150b0f7 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -162,6 +162,7 @@ DPDK_17.02 { DPDK_17.05 { global: + rte_eal_device_detach; rte_bus_find; rte_bus_find_by_device; rte_bus_find_device; diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 733da91..8ef9b98 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -100,6 +100,30 @@ int rte_eal_dev_attach(const char *name, const char *devargs) return ret; } +int rte_eal_device_detach(struct rte_device *dev) +{ + struct rte_bus *bus; + int ret; + + bus = rte_bus_find_by_device(dev); + if (!bus) { + RTE_LOG(ERR, EAL, "Cannot find bus for device (%s)\n", + dev->name); + return -EINVAL; + } + + if (!bus->unplug) { + RTE_LOG(ERR, EAL, "Bus function not supported\n"); + return -ENOTSUP; + } + + ret = bus->unplug(dev); + if (ret) + RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", + dev->name); + return ret; +} + static int cmp_dev_name(const struct rte_device *dev, const void *_name) { const char *name = _name; @@ -110,8 +134,6 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name) int rte_eal_dev_detach(const char *name) { struct rte_device *dev; - struct rte_bus *bus; - int ret; if (name == NULL) { RTE_LOG(ERR, EAL, "Invalid device provided.\n"); @@ -124,20 +146,5 @@ int rte_eal_dev_detach(const char *name) return -EINVAL; } - bus = rte_bus_find_by_device(dev); - if (!bus) { - RTE_LOG(ERR, EAL, "Cannot find bus for device (%s)\n", name); - return -EINVAL; - } - - if (!bus->unplug) { - RTE_LOG(ERR, EAL, "Bus function not supported\n"); - return -ENOTSUP; - } - - ret = bus->unplug(dev); - if (ret) - RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", - name); - return ret; + return rte_eal_device_detach(dev); } diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index 724855e..9f35b1f 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -123,6 +123,17 @@ struct rte_mem_resource { void *addr; /**< Virtual address, NULL when not mapped. */ }; +/* FIXME: Forward declare */ +struct rte_device; + +/** + * Unplug the device from the device driver. + * + * @param dev + * A pointer to a rte_device structure. + */ +int rte_eal_device_detach(struct rte_device *dev); + /** * A structure describing a device driver. */ diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 03a42a6..4a1d0b9 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -354,26 +354,14 @@ rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id) static int rte_eth_dev_is_detachable(uint8_t port_id) { - uint32_t dev_flags; + struct rte_eth_dev *dev; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); - switch (rte_eth_devices[port_id].data->kdrv) { - case RTE_KDRV_IGB_UIO: - case RTE_KDRV_UIO_GENERIC: - case RTE_KDRV_NIC_UIO: - case RTE_KDRV_NONE: - case RTE_KDRV_VFIO: - break; - default: - return -ENOTSUP; - } - dev_flags = rte_eth_devices[port_id].data->dev_flags; - if ((dev_flags & RTE_ETH_DEV_DETACHABLE) && - (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE))) + dev = &rte_eth_devices[port_id]; + if (dev->data->dev_flags & RTE_ETH_DEV_BONDED_SLAVE) return 0; - else - return 1; + return !!dev->device->devargs->bus->unplug; } /* attach the new device, then store port_id of the device */ @@ -426,6 +414,7 @@ rte_eth_dev_attach(const char *devargs, uint8_t *port_id) int rte_eth_dev_detach(uint8_t port_id, char *name) { + struct rte_eth_dev *dev; int ret = -1; if (name == NULL) { @@ -434,15 +423,15 @@ rte_eth_dev_detach(uint8_t port_id, char *name) } /* FIXME: move this to eal, once device flags are relocated there */ - if (rte_eth_dev_is_detachable(port_id)) + if (!rte_eth_dev_is_detachable(port_id)) goto err; - snprintf(name, sizeof(rte_eth_devices[port_id].data->name), - "%s", rte_eth_devices[port_id].data->name); - ret = rte_eal_dev_detach(name); + dev = &rte_eth_devices[port_id]; + snprintf(name, RTE_ETH_NAME_MAX_LEN - 1, "%s", dev->device->name); + ret = rte_eal_device_detach(dev->device); if (ret < 0) goto err; - + dev->state = RTE_ETH_DEV_UNUSED; return 0; err: -- 2.1.4