From patchwork Wed May 31 13:17:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 24903 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 8D5097CC3; Wed, 31 May 2017 15:18:56 +0200 (CEST) Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by dpdk.org (Postfix) with ESMTP id 2C5062C02 for ; Wed, 31 May 2017 15:18:21 +0200 (CEST) Received: by mail-wm0-f52.google.com with SMTP id e127so19928920wmg.1 for ; Wed, 31 May 2017 06:18:21 -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=pTkiQXI+LrZ+DXRiU5OzM2ky23tGHfPCAtG3aMW7J3s=; b=qR3zQMIEwB2fr9s1CL99C8hL1KxTqEzOUyzvAa9vD1OrIdgNPOI6UWylKfBfAkWZTv sM8FmjKsBkZxEfDwZztZHt+htw2+srM6C1I+Fu3nwLs/szbfbgYTkVvipopJpVVAokhd sy1TiXfPuc+OHUd+WQr60FUrNArlHao7LLwCV8fxme9dNl/Y9lfLIBTEv9KKKsje+Chq XN6vLS8vbw079nKxmiucahRphmfuzfLtjl0RCL8VNdOnxqjaDxPPrc5XYqD+af2ngkXZ q0Y3JeZ1hzV4ofqnM3x5WaZFRJa4J/PxSUuq3+damlN+eGC9VA1SnaI1JB7pAS0SC3gd CqkQ== 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=pTkiQXI+LrZ+DXRiU5OzM2ky23tGHfPCAtG3aMW7J3s=; b=YtiuECdcMtIp9QhFNHGMgEMuiMZTrC1glk2h+kQWYmQrTY6AtXN4MJpq19ZmjSIQNu +DmQ57yRMy+bvAwj3ZbPZK/HpKKIxOJkQQZDMXWd/LadTD7lLXrN/9HipO1j+V6dGIUR rAd99E14W/h6DIDskRawslsY9RtGvI1mJJPgaFUXTWhY9pHA279G6nb3cXj9SN7Hz5Rm ITVFoOPjhIgBuRzaCqta2ED2SP+4YexTeZmD0tKrFAwGWfJE9pi6wJuEohwtRQkw/Njc YiutEcTbPuMAeATnvKLmH+hvbshkmpkCkg8VLeDZsvW3FLvIR571M0qy4wNDRjixJzSg 9dCA== X-Gm-Message-State: AODbwcCOoYKkmV3ER/9dQ2VLBhGeKCYK6uaxO/ulxkfZ892XWy9aomxn T4HtiB5wP3hiWBdgX50= X-Received: by 10.28.135.82 with SMTP id j79mr5844944wmd.10.1496236700794; Wed, 31 May 2017 06:18:20 -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 g77sm10045744wmd.19.2017.05.31.06.18.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 May 2017 06:18:19 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck , Gaetan Rivet Date: Wed, 31 May 2017 15:17:55 +0200 Message-Id: <3e6830ce1bd72a5b8d6abac2f8512cf0c8fa8005.1496235017.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 v2 10/11] 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 | 3 +- 4 files changed, 39 insertions(+), 19 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 7508b70..968c66e 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->devargs); + 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->devargs); - 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 f017814..c530797 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 83898a8..ff4f5ab 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -440,7 +440,8 @@ rte_eth_dev_detach(uint8_t port_id, char *name) snprintf(name, sizeof(rte_eth_devices[port_id].data->name), "%s", rte_eth_devices[port_id].data->name); - ret = rte_eal_dev_detach(name); + + ret = rte_eal_device_detach(rte_eth_devices[0].device); if (ret < 0) goto err;