From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by dpdk.org (Postfix) with ESMTP id 35BBC2B83 for ; Thu, 19 Jan 2017 05:45:24 +0100 (CET) Received: by mail-wm0-f52.google.com with SMTP id c85so272769770wmi.1 for ; Wed, 18 Jan 2017 20:45:24 -0800 (PST) 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; bh=VIXUi+A2109q3y9ZW5jqiN76neMIvho7KtfDt9PhKq4=; b=hVAzVbtHM43RMc5jXsFjIHw/VS4z+Z6SCD5LxsTjsrVkjPQWkJc+le7SNF1UWzPcyI hGrXBIEt/io2tU280I23p8taWoZkk0ogTmrW7+nRmbdScSyBY+1SAK639IIiOiag8mw5 9YyKNN92QMu/sXhvjLMO4nz3bc97Fs7L3rgIYv2BGoocxBE20Tr350b85EYUHh49Kn8y lLPtvo7Qo4cACagm3wTp//VlHJ+7wJMP+yHJ6rMng0Iq9NK+LnEwqHPAKXSfVIjIJE1r nm70rS98EljRJ7fj/UIO3vQroucx3zTzFm0tqamD14I4XdPMTbCPzdBoPuwDXHEMmw/n R3Mw== 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; bh=VIXUi+A2109q3y9ZW5jqiN76neMIvho7KtfDt9PhKq4=; b=t7TIGMxNKFhmvUQz3JkD3vBq+I36pXKKxFLs5r66wqfELCSnEspwTbS7mGlIFdA3AW SHybxShKpp/qheIPDUN/OvObmxmTyyKemm5aE/V6UMvfBNL7QdMv6IbCTDL18/NsQHAr 48J/NBvaX5gfwTUkQ8E5t7k9/lwsLeatZnV7ObC3t8e/elcROSgtpqUSAg91et8N3w/B Q4a8gW1GBBR6jszM1nKQ32pGrNY8cvgSuxvGOiRTFUd6sHYfQMPwtr/kcC28ertEKXFJ uVh46UMDt+ZDksNUvAO8JZJCKapPTCRpZvfbobTQLzAMSaUV1SK27KcBnFvGPReDF+eH JWYQ== X-Gm-Message-State: AIkVDXIuufxG+DUekAZ9t0z5Axqa7WfXEoNyrkdMdQdXrQnvYQpPMUlo1wdjkBB/kY5wyz/V X-Received: by 10.223.160.43 with SMTP id k40mr6451551wrk.24.1484801123769; Wed, 18 Jan 2017 20:45:23 -0800 (PST) Received: from XPS13.localdomain (184.203.134.77.rev.sfr.net. [77.134.203.184]) by smtp.gmail.com with ESMTPSA id t194sm2568586wmd.1.2017.01.18.20.45.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jan 2017 20:45:23 -0800 (PST) From: Thomas Monjalon To: Shreyansh Jain Cc: dev@dpdk.org Date: Thu, 19 Jan 2017 05:45:06 +0100 Message-Id: <1484801117-779-3-git-send-email-thomas.monjalon@6wind.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1484801117-779-1-git-send-email-thomas.monjalon@6wind.com> References: <1484748329-5418-1-git-send-email-shreyansh.jain@nxp.com> <1484801117-779-1-git-send-email-thomas.monjalon@6wind.com> Subject: [dpdk-dev] [PATCH v11 02/13] bus: add scanning 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, 19 Jan 2017 04:45:24 -0000 From: Shreyansh Jain Scan for bus discovers the devices available on the bus and adds them to a bus specific device list. Each bus mandatorily implements this method. Signed-off-by: Shreyansh Jain Reviewed-by: Ferruh Yigit Signed-off-by: Thomas Monjalon --- lib/librte_eal/bsdapp/eal/eal.c | 3 +++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/eal_common_bus.c | 21 +++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 23 +++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal.c | 4 ++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 6 files changed, 53 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 2206277..be5d295 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -577,6 +577,9 @@ rte_eal_init(int argc, char **argv) rte_config.master_lcore, thread_id, cpuset, ret == 0 ? "" : "..."); + if (rte_bus_scan()) + rte_panic("Cannot scan the buses for devices\n"); + RTE_LCORE_FOREACH_SLAVE(i) { /* diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 12298f2..931afeb 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -180,6 +180,7 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; + rte_bus_scan; rte_bus_unregister; } DPDK_16.11; diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index e9b1470..ef10390 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -47,6 +47,8 @@ rte_bus_register(struct rte_bus *bus) { RTE_VERIFY(bus); RTE_VERIFY(bus->name && strlen(bus->name)); + /* A bus should mandatorily have the scan implemented */ + RTE_VERIFY(bus->scan); TAILQ_INSERT_TAIL(&rte_bus_list, bus, next); RTE_LOG(DEBUG, EAL, "Registered [%s] bus.\n", bus->name); @@ -59,6 +61,25 @@ rte_bus_unregister(struct rte_bus *bus) RTE_LOG(DEBUG, EAL, "Unregistered [%s] bus.\n", bus->name); } +/* Scan all the buses for registered devices */ +int +rte_bus_scan(void) +{ + int ret; + struct rte_bus *bus = NULL; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + ret = bus->scan(); + if (ret) { + RTE_LOG(ERR, EAL, "Scan for (%s) bus failed.\n", + bus->name); + return ret; + } + } + + return 0; +} + /* Dump information of a single bus */ static int bus_dump_one(FILE *f, struct rte_bus *bus) diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index b8ea5ae..b01930a 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -57,11 +57,25 @@ extern "C" { TAILQ_HEAD(rte_bus_list, rte_bus); /** + * Bus specific scan for devices attached on the bus. + * For each bus object, the scan would be reponsible for finding devices and + * adding them to its private device list. + * + * A bus should mandatorily implement this method. + * + * @return + * 0 for successful scan + * <0 for unsuccessful scan with error value + */ +typedef int (*rte_bus_scan_t)(void); + +/** * A structure describing a generic bus. */ struct rte_bus { TAILQ_ENTRY(rte_bus) next; /**< Next bus object in linked list */ const char *name; /**< Name of the bus */ + rte_bus_scan_t scan; /**< Scan for devices attached to bus */ }; /** @@ -83,6 +97,15 @@ void rte_bus_register(struct rte_bus *bus); void rte_bus_unregister(struct rte_bus *bus); /** + * Scan all the buses. + * + * @return + * 0 in case of success in scanning all buses + * !0 in case of failure to scan + */ +int rte_bus_scan(void); + +/** * Dump information of all the buses registered with EAL. * * @param f diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index 16dd5b9..1d2a16a 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -69,6 +69,7 @@ #include #include #include +#include #include #include #include @@ -844,6 +845,9 @@ rte_eal_init(int argc, char **argv) if (rte_eal_intr_init() < 0) rte_panic("Cannot init interrupt-handling thread\n"); + if (rte_bus_scan()) + rte_panic("Cannot scan the buses for devices\n"); + RTE_LCORE_FOREACH_SLAVE(i) { /* diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index d996cbc..c238381 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -184,6 +184,7 @@ DPDK_17.02 { rte_bus_dump; rte_bus_register; + rte_bus_scan; rte_bus_unregister; } DPDK_16.11; -- 2.7.0