From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id C930A7CB4 for ; Thu, 29 Jun 2017 20:22:42 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id u23so4076243wma.2 for ; Thu, 29 Jun 2017 11:22:42 -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=HmuGTnsoQVl/yOEgudo4WSIeLosuWmgFkNjP2KQUZtg=; b=nMgVKsQI1TUWBbbprc6kWIPXScF8AjhC8VqMNNPvdRpfM0uA+DIngF3UUNqSUwsofr 8KwtgYFAdQsf3X1GgMqpQcfrRwhB9KSb+PbkXlu8iuskgBk4NDuHOnpFxXG5+3Ev0uIw SynsyJdyJfZc3jvShalw2bzcqVedfjtg+C38PWqgRxgY5vpmX3BCcg250GOB1RVWcqis qVdKMY5G8+7oNLASVVu4apWtJSZtcRsMe2G+ugCMtmpa07HJyLzvp6ob9VIiCdgbDapT T6GGixBwAHSm7woqO+JW71Hx3WcsrXbAsNVRoMdADj2ZmoOviXTahlXLOwj8qygc7v9e 8S/A== 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=HmuGTnsoQVl/yOEgudo4WSIeLosuWmgFkNjP2KQUZtg=; b=SgE3k66+/K8CkMddmw/WPTpdGj+7e7htY3MZxUiBWpOH1q7unx2B8qk/AlVmIbP8uw 7d1P7/TRfbNkaLbGABYYbQ75LuaPMxMdd9KVWOhWRqppDpn6/MU68NevCGuGtAzsKR1d 9qunAkLF67zMC2gWp/q/QyIsBB0nYd/dpUuKfYVZzmkSQK7c/w0xdftKGfn7dNCdpInV i1Yfo3LWQVZQCYTudDoIlN202svwLPUCZBQs1vYq1XF6xWIFT4tkWsaC7ag3VSsgOvdM vRxAw/dsMy/GJCTga9Sn8pwPKKARDkDPlSYd49YdampzqdA5xhWlHny2Nr48CG3NMNJB hBFQ== X-Gm-Message-State: AKS2vOzR9ZZ3d4wfazaSdkvU56ACDXq67bCPGGcBcyugUKHc5tT7RnaM la6p3cNcJpd3To51 X-Received: by 10.80.129.4 with SMTP id 4mr2642378edc.120.1498760562401; Thu, 29 Jun 2017 11:22:42 -0700 (PDT) Received: from weierstrass.local ([91.200.110.13]) by smtp.gmail.com with ESMTPSA id e28sm1446366ede.14.2017.06.29.11.22.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2017 11:22:41 -0700 (PDT) Sender: Jan Blunck From: Jan Blunck To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, shreyansh.jain@nxp.com Date: Thu, 29 Jun 2017 20:22:04 +0200 Message-Id: <20170629182206.1072-14-jblunck@infradead.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170629182206.1072-1-jblunck@infradead.org> References: <20170629182206.1072-1-jblunck@infradead.org> Subject: [dpdk-dev] [PATCH v7 13/15] 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: Thu, 29 Jun 2017 18:22:43 -0000 Signed-off-by: Jan Blunck --- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 + lib/librte_eal/common/eal_common_dev.c | 68 +++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 28 ++++++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 + 4 files changed, 100 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 21640d6..b7d26b2 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -166,6 +166,8 @@ DPDK_17.05 { rte_bus_find_by_device; rte_bus_find_device; rte_cpu_is_supported; + rte_eal_hotplug_add; + rte_eal_hotplug_remove; rte_log_dump; rte_log_register; rte_log_get_global_level; diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index a400ddd..477b4cf 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -92,3 +92,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) { + RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", busname); + return -ENOENT; + } + + if (!bus->plug) { + 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) { + 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) { + RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", busname); + return -ENOENT; + } + + if (!bus->unplug) { + 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) { + 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..95440eb 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -192,6 +192,34 @@ int rte_eal_dev_attach(const char *name, const char *devargs); int rte_eal_dev_detach(const char *name); /** + * 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); + +/** + * 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 e0a056d..a94cb7a 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -170,6 +170,8 @@ DPDK_17.05 { rte_bus_find_by_device; rte_bus_find_device; rte_cpu_is_supported; + rte_eal_hotplug_add; + rte_eal_hotplug_remove; rte_intr_free_epoll_fd; rte_log_dump; rte_log_get_global_level; -- 2.9.4