From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f180.google.com (mail-wr0-f180.google.com [209.85.128.180]) by dpdk.org (Postfix) with ESMTP id 80FAA3250 for ; Sun, 9 Jul 2017 03:46:00 +0200 (CEST) Received: by mail-wr0-f180.google.com with SMTP id r103so93870058wrb.0 for ; Sat, 08 Jul 2017 18:46:00 -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=4HdXX5/OaiGFFafjizPbCywJNCFR84+k9OnmqWi7Dk0=; b=2JG5x4gOo6pdz3cdV1dF88s9AiuCeb7RxLe99KyEe8PYKQ0mms9qFxx+jHOidBOzsp jy7qWPcU3MCFu13dI+ASCP6PJGEuOmSEGCd8LNjPQFvI89PcNPmIqHmkd3SJpnKc/xrS kM2pdCK2OBjPfp+MIU0S+a1KLgGEcfGBZfJPrbwT0JmwdAGSh+K/XriHdXiofsHsuq6D rxsPrxC+q0qZQwp/TKwOvxFW+R9uTkrr3gv81DIlukrnXxHps1CAH1DN6WHbRtd9GK7F YvSn76d7I7DH4hRSp8l5m0q+6EMTfS3o+n5GmePddIQ9slkFmIZSKpFTqFGSbeZKCuZr zVsQ== 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=4HdXX5/OaiGFFafjizPbCywJNCFR84+k9OnmqWi7Dk0=; b=MEv8kBDPqxBtK8riwNFZRzIq4YTyatPTgqGVAnnLT6tz3GYKMvWwDw2jMFT9liC5o1 mk/Cppa4LSlX6PxdXV/P5JTI4lpUUvpYLFYq5ALygU2UJI4bQkXH5QW1wlHrbt/0LveY ibwLT/sOraEFD/ciD7HevsYAFr7w5OFM01+a7Jwnev/ju8JHeyadYjhhmCwJg9xpzD1K KFTb7i3gf6azBHoreYlGvwPXJ1gw0sI1ceQZa6sMZ2PLeB8kr3Prsh6NyWntkQJeqiYs mYHJhU9JMhV9vjmQKqO1nO8Rm3eK8bVimV+Q4ue4QjqAjRvVrIqoBdMhYUYGCR7pBQx3 wzfA== X-Gm-Message-State: AIVw110k0wJ45KRPBu92KlB2K6pv5DMvZz/RfU+aKOMvMGEAn9aa++KY 7yu7oK4YCwWQaOl9TAc= X-Received: by 10.28.156.202 with SMTP id f193mr3326437wme.22.1499564759819; Sat, 08 Jul 2017 18:45:59 -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 h130sm2430609wmd.34.2017.07.08.18.45.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 08 Jul 2017 18:45:59 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Sun, 9 Jul 2017 03:45:37 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH 1/9] eal: return device handle upon plugin 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: Sun, 09 Jul 2017 01:46:00 -0000 This device handle can be useful for other systems calling hotplug functions, to retrieve for example any associated ethdev. This change avoids unecessary calls to rte_bus_find, as the handle is already known and available. Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_dev.c | 40 +++++++++++++++++++++++---------- lib/librte_eal/common/include/rte_dev.h | 10 +++++---- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 32e12b5..292fefe 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include "eal_private.h" @@ -67,6 +68,7 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name) int rte_eal_dev_attach(const char *name, const char *devargs) { + struct rte_device *dev; int ret; if (name == NULL || devargs == NULL) { @@ -74,9 +76,9 @@ int rte_eal_dev_attach(const char *name, const char *devargs) return -EINVAL; } - ret = rte_eal_hotplug_add("pci", name, devargs); - if (ret && ret != -EINVAL) - return ret; + dev = rte_eal_hotplug_add("pci", name, devargs); + if (dev == NULL && rte_errno != EINVAL) + return -rte_errno; /* * If we haven't found a bus device the user meant to "hotplug" a @@ -118,7 +120,8 @@ int rte_eal_dev_detach(struct rte_device *dev) return ret; } -int rte_eal_hotplug_add(const char *busname, const char *devname, +struct rte_device * +rte_eal_hotplug_add(const char *busname, const char *devname, const char *devargs) { struct rte_bus *bus; @@ -128,31 +131,39 @@ int rte_eal_hotplug_add(const char *busname, const char *devname, bus = rte_bus_find_by_name(busname); if (bus == NULL) { RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", busname); - return -ENOENT; + rte_errno = ENOENT; + return NULL; } if (bus->plug == NULL) { RTE_LOG(ERR, EAL, "Function plug not supported by bus (%s)\n", bus->name); - return -ENOTSUP; + rte_errno = ENOTSUP; + return NULL; } ret = bus->scan(); - if (ret) - return ret; + if (ret) { + rte_errno = -ret; + return NULL; + } 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; + rte_errno = EINVAL; + return NULL; } ret = bus->plug(dev, devargs); - if (ret) + if (ret) { RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", dev->name); - return ret; + rte_errno = -ret; + return NULL; + } + return dev; } int rte_eal_hotplug_remove(const char *busname, const char *devname) @@ -164,24 +175,29 @@ int rte_eal_hotplug_remove(const char *busname, const char *devname) bus = rte_bus_find_by_name(busname); if (bus == NULL) { RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", busname); + rte_errno = ENOENT; return -ENOENT; } if (bus->unplug == NULL) { RTE_LOG(ERR, EAL, "Function unplug not supported by bus (%s)\n", bus->name); + rte_errno = ENOTSUP; 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); + rte_errno = EINVAL; return -EINVAL; } ret = bus->unplug(dev); - if (ret) + if (ret) { RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", dev->name); + rte_errno = -ret; + } return ret; } diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index bcd8b1e..30d1f2e 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -218,10 +218,12 @@ int rte_eal_dev_detach(struct rte_device *dev); * @param devargs * Device arguments to be passed to the driver. * @return - * 0 on success, negative on error. + * The pointer to the plugged rte_device on success. + * NULL on error. rte_errno is then set. */ -int rte_eal_hotplug_add(const char *busname, const char *devname, - const char *devargs); +struct rte_device *rte_eal_hotplug_add(const char *busname, + const char *devname, + const char *devargs); /** * @warning @@ -234,7 +236,7 @@ int rte_eal_hotplug_add(const char *busname, const char *devname, * @param devname * The device name being removed. * @return - * 0 on success, negative on error. + * 0 on success, negative on error. rte_errno is then set. */ int rte_eal_hotplug_remove(const char *busname, const char *devname); -- 2.1.4