From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by dpdk.org (Postfix) with ESMTP id 4A3737CAF for ; Fri, 30 Jun 2017 20:20:15 +0200 (CEST) Received: by mail-wm0-f66.google.com with SMTP id u23so9331924wma.2 for ; Fri, 30 Jun 2017 11:20:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=g7CsjrDQyQNnmcIrGyJbaw7YEfiTiGGX/Jfize6EVzU=; b=XCLKzcAsK+tZd1YCxu5rRXYU82HjGOuB1ou+hNtTWtI4u3TDY3Y7CVs4xIL5Cx8d/x Xb1SQd47QUp3JO90kiIiZzdOspCzX0P7hLoelmfVXqnY6ejA+cbRUnYulFHnzHbM5pwp nZRliIQ4Q3Fhk5XracvvwoAq+HTuhib1PeMjU4C+MU6+P9NeqpwJuS35wca1kApRC1vb DI06N3RHZyRDmDarTr1m3Rt9ddO2JzhFXSBgkDNASU1HDGpX4f901UnW9QtZMZ/WEHLg 5YIUtB+QnvM3J6urgaKihOdi6Z0V/I1rRPrQyzGENx7Gba7MhRtWEpXgOx/vAELZNN9Y NmTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=g7CsjrDQyQNnmcIrGyJbaw7YEfiTiGGX/Jfize6EVzU=; b=khHB9WCBK53Cq4I4FcbRtADrVDDK5Qc8vwa2Xi7No1bzxqueZp3pNy8kgf7CMddFaz dCRQgbnirAGlCj3RrZO1/Ga+fHvsEbEoBptWD+Gk332ebqvEusMY2uyGcurgGGKxzbqY f00anKopRuXN286p1+ZLrW0MEI2u8EgZUPLrT2dvr3Grn2pYdFZgpUD5JjdFD9sf+Q+e ejOHjP8Im9QpFi4pCpcG8RdVllsA8sk5kzsva8PRRsptlgp/0sFU6PnBAX+DcDA8vKDW tUpWf1lSec1BaJqRsk6b/u1tb/jNLX6QH9P5BpeMwmH5Xhsw1aMUywiggcrOSOOkQQ1m Xs8A== X-Gm-Message-State: AKS2vOw3vIkrxJXbrgANOOEanxGFMnSL6yMDCYf5HcxlmmGuzWN5/Skp 0qlsKmN3Jda4iVJN X-Received: by 10.80.137.45 with SMTP id e42mr6268552ede.67.1498846814817; Fri, 30 Jun 2017 11:20:14 -0700 (PDT) Received: from weierstrass.local ([91.200.110.13]) by smtp.gmail.com with ESMTPSA id r28sm2826940edd.33.2017.06.30.11.20.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Jun 2017 11:20:14 -0700 (PDT) Sender: Jan Blunck From: Jan Blunck To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, shreyansh.jain@nxp.com Date: Fri, 30 Jun 2017 20:19:41 +0200 Message-Id: <20170630181943.23929-13-jblunck@infradead.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630181943.23929-1-jblunck@infradead.org> References: <20170629182206.1072-1-jblunck@infradead.org> <20170630181943.23929-1-jblunck@infradead.org> Subject: [dpdk-dev] [PATCH v8 12/14] eal: add hotplug add/remove functions 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: Fri, 30 Jun 2017 18:20:15 -0000 Signed-off-by: Jan Blunck --- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 8 +++ lib/librte_eal/common/eal_common_dev.c | 88 +++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 34 ++++++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 8 +++ 4 files changed, 138 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index d138a96..0295ea9 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -202,3 +202,11 @@ DPDK_17.08 { rte_bus_find_by_name; } DPDK_17.05; + +EXPERIMENTAL { + global: + + rte_eal_hotplug_add; + rte_eal_hotplug_remove; + +} DPDK_17.08; diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index a400ddd..3606332 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -45,6 +46,25 @@ #include "eal_private.h" +static int cmp_detached_dev_name(const struct rte_device *dev, + const void *_name) +{ + const char *name = _name; + + /* skip attached devices */ + if (dev->driver != NULL) + return 1; + + return strcmp(dev->name, name); +} + +static int cmp_dev_name(const struct rte_device *dev, const void *_name) +{ + const char *name = _name; + + return strcmp(dev->name, name); +} + int rte_eal_dev_attach(const char *name, const char *devargs) { struct rte_pci_addr addr; @@ -92,3 +112,71 @@ int rte_eal_dev_detach(const char *name) RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", name); return -EINVAL; } + +int rte_eal_hotplug_add(const char *busname, const char *devname, + const char *devargs) +{ + struct rte_bus *bus; + struct rte_device *dev; + int ret; + + bus = rte_bus_find_by_name(busname); + if (bus == NULL) { + RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", busname); + return -ENOENT; + } + + if (bus->plug == NULL) { + RTE_LOG(ERR, EAL, "Function plug not supported by bus (%s)\n", + bus->name); + return -ENOTSUP; + } + + ret = bus->scan(); + if (ret) + return ret; + + dev = bus->find_device(NULL, cmp_detached_dev_name, devname); + if (dev == NULL) { + RTE_LOG(ERR, EAL, "Cannot find unplugged device (%s)\n", + devname); + return -EINVAL; + } + + ret = bus->plug(dev, devargs); + if (ret) + RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", + dev->name); + return ret; +} + +int rte_eal_hotplug_remove(const char *busname, const char *devname) +{ + struct rte_bus *bus; + struct rte_device *dev; + int ret; + + bus = rte_bus_find_by_name(busname); + if (bus == NULL) { + RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", busname); + return -ENOENT; + } + + if (bus->unplug == NULL) { + RTE_LOG(ERR, EAL, "Function unplug not supported by bus (%s)\n", + bus->name); + return -ENOTSUP; + } + + dev = bus->find_device(NULL, cmp_dev_name, devname); + if (dev == NULL) { + RTE_LOG(ERR, EAL, "Cannot find plugged device (%s)\n", devname); + return -EINVAL; + } + + ret = bus->unplug(dev); + if (ret) + RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", + dev->name); + return ret; +} diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index 04d9c28..a0d67d0 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -192,6 +192,40 @@ int rte_eal_dev_attach(const char *name, const char *devargs); int rte_eal_dev_detach(const char *name); /** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Hotplug add a given device to a specific bus. + * + * @param busname + * The bus name the device is added to. + * @param devname + * The device name. Based on this device name, eal will identify a driver + * capable of handling it and pass it to the driver probing function. + * @param devargs + * Device arguments to be passed to the driver. + * @return + * 0 on success, negative on error. + */ +int rte_eal_hotplug_add(const char *busname, const char *devname, + const char *devargs); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Hotplug remove a given device from a specific bus. + * + * @param busname + * The bus name the device is removed from. + * @param devname + * The device name being removed. + * @return + * 0 on success, negative on error. + */ +int rte_eal_hotplug_remove(const char *busname, const char *devname); + +/** * Device comparison function. * * This type of function is used to compare an rte_device with arbitrary diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index 643ec1c..a118fb1 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -207,3 +207,11 @@ DPDK_17.08 { rte_bus_find_by_name; } DPDK_17.05; + +EXPERIMENTAL { + global: + + rte_eal_hotplug_add; + rte_eal_hotplug_remove; + +} DPDK_17.08; -- 2.9.4