From patchwork Thu Jan 19 04:45:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 19761 X-Patchwork-Delegate: thomas@monjalon.net 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 D46D6FB48; Thu, 19 Jan 2017 05:45:43 +0100 (CET) Received: from mail-wm0-f54.google.com (mail-wm0-f54.google.com [74.125.82.54]) by dpdk.org (Postfix) with ESMTP id 459A9FB21 for ; Thu, 19 Jan 2017 05:45:27 +0100 (CET) Received: by mail-wm0-f54.google.com with SMTP id c206so58680100wme.0 for ; Wed, 18 Jan 2017 20:45:27 -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=hqGFAbU3UPyPmLwJPGV7yKFzEDmeZJZIXg+zigqUfcE=; b=HRUa3N2vbO3Mx/KyfPiXxtiyyqDW8LH9cp5bcRth/6HIQxoyAX65vwxINFnaSH7Dv8 6ehWgs7Xl74tBYLBX2Ml5QEChY2YWNZAVLxkALBojYugzUYSosnuhb0X8HJyirUAW624 Bc8C+L/NDUduOrXhG4ACqxan6ifQV1Pq89u9PQkFKqVqwGb+yx87ITImSQRSB4F21+sm Nshe+kAyTM2O01bcODACzC3I7R5qToKtiaGrtsHZBfcn4OtuBxfYiqnf/TYb311ZXK4g OeV72/v5RG2TXPNb7w+JfwsBjKZEaFb3aJ2fTWekxJy0BLKon/7quvyr+MYtqCWdzG3Y JvoQ== 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=hqGFAbU3UPyPmLwJPGV7yKFzEDmeZJZIXg+zigqUfcE=; b=rzuQ+UJDbxbmvjf5IHceJQj/ids+9wNcsrvKNL4d6uZB2vnQ0OoTiaHlbxQBAu0hL8 eSeu5NDEYK6Q0CNTw7mXu9/4YrMLuiacC6PBPE9z/8Ud+xGnm0mzFWoHNpIAm315lbZd Jn5E9FxAn1DPhy1zyf+YN3LOrsJMdYj13NIzAyk4nh/v0o16UYdUR9N6oAJyn/ABzaGs cH5Z1oMBAMcelfQpG/h1e2A6LViG9Rk2RHUQBRbXUHn3T6R3tKvai7l9S7klcpMVR5Av O/GXXuIIN1qs8LLePe7wr5jkfxirSm9g7zVn2l1ff98zw7fQsTNzlf9VjX7g17egPDMN 7NIQ== X-Gm-Message-State: AIkVDXIVsol8P/hMV7tBiZspz5kniMVHbzzE2Vb1OQygqOdkKUl4fvxhMhq43g3va8c7Dvmx X-Received: by 10.28.55.68 with SMTP id e65mr5610121wma.62.1484801126765; Wed, 18 Jan 2017 20:45:26 -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.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jan 2017 20:45:26 -0800 (PST) From: Thomas Monjalon To: Shreyansh Jain Cc: dev@dpdk.org Date: Thu, 19 Jan 2017 05:45:09 +0100 Message-Id: <1484801117-779-6-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 05/13] app/test: check bus scan 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: Shreyansh Jain Signed-off-by: Shreyansh Jain --- app/test/test_bus.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/app/test/test_bus.c b/app/test/test_bus.c index e2a58fa..de4f1ab 100644 --- a/app/test/test_bus.c +++ b/app/test/test_bus.c @@ -106,10 +106,26 @@ struct dummy_bus_map { struct rte_bus_list orig_bus_list = TAILQ_HEAD_INITIALIZER(orig_bus_list); +/* Forward declarations for callbacks from bus */ + +/* Bus A + * Scan would register devA1 and devA2 to bus + */ +static int scan_fn_for_busA(void); + +/* Bus B + * Scan would register devB1 and devB2 to bus + */ +static int scan_fn_for_busB(void); + +/* generic implementations wrapped around by above declarations */ +static int generic_scan_fn(struct rte_bus *bus); + struct dummy_bus busA = { .name = "busA_impl", /* busA */ .bus = { .name = "busA", + .scan = scan_fn_for_busA, }, }; @@ -117,6 +133,7 @@ struct dummy_bus busB = { .name = "busB_impl", /* busB */ .bus = { .name = "busB", + .scan = scan_fn_for_busB, }, }; @@ -222,9 +239,80 @@ dump_device_tree(void) printf("------>8-------\n"); } +/* @internal + * Move over the bus_map and find the entry matching the bus object + * passed as argument. + * For each device in that bus_map list, register. + * + * @param bus + * bus to scan againt test entry + * @return + * 0 for successful scan, even if no devices are found + * !0 for any error in scanning (like, invalid bus) + */ +static int +generic_scan_fn(struct rte_bus *bus) +{ + int i = 0; + struct dummy_device *ddev = NULL; + struct dummy_bus_map *dbmap = NULL; + struct dummy_bus *db = NULL; + + if (!bus) + return -1; + + /* Extract the device tree node using the bus passed */ + for (i = 0; bus_map[i].name; i++) { + if (!strcmp(bus_map[i].name, bus->name)) { + dbmap = &bus_map[i]; + break; + } + } + + if (!dbmap) + return -1; + + db = dbmap->dbus; + + /* For all the devices in the device tree (bus_map), add device */ + for (i = 0; dbmap->ddevices[i]; i++) { + ddev = dbmap->ddevices[i]; + TAILQ_INSERT_TAIL(&db->device_list, ddev, next); + } + + return 0; +} + +int +scan_fn_for_busA(void) { + struct dummy_bus_map *dbm; + + dbm = &bus_map[0]; + while (dbm) { + if (strcmp(dbm->name, "busA") == 0) + return generic_scan_fn(&dbm->dbus->bus); + dbm++; + } + return 1; +} + +int +scan_fn_for_busB(void) { + struct dummy_bus_map *dbm; + + dbm = &bus_map[0]; + while (dbm) { + if (strcmp(dbm->name, "busB") == 0) + return generic_scan_fn(&dbm->dbus->bus); + dbm++; + } + return 1; +} + static int test_bus_setup(void) { + int i = 0; struct rte_bus *bus_p = NULL; /* Preserve the original bus list before executing test */ @@ -234,6 +322,13 @@ test_bus_setup(void) TAILQ_INSERT_TAIL(&orig_bus_list, bus_p, next); } + /* Initialize the bus lists */ + for (i = 0; bus_map[i].name; i++) { + TAILQ_INIT(&bus_map[i].dbus->device_list); + TAILQ_INIT(&bus_map[i].dbus->driver_list); + } + + dump_device_tree(); return 0; } @@ -332,6 +427,79 @@ test_bus_unregistration(void) return 0; } +static int +test_device_unregistration_on_bus(void) +{ + int i; + struct rte_bus *bus = NULL; + struct dummy_device *ddev; + struct dummy_bus *dbus; + + for (i = 0; bus_map[i].name; i++) { + bus = &(bus_map[i].dbus->bus); + if (!bus) { + printf("Unable to find bus (%s)\n", + bus_map[i].name); + return -1; + } + + dbus = container_of(bus, struct dummy_bus, bus); + /* For bus 'bus', unregister all devices */ + TAILQ_FOREACH(ddev, &dbus->device_list, next) { + TAILQ_REMOVE(&dbus->device_list, ddev, next); + } + } + + for (i = 0; bus_map[i].name; i++) { + bus = &(bus_map[i].dbus->bus); + dbus = container_of(bus, struct dummy_bus, bus); + + if (!TAILQ_EMPTY(&dbus->device_list)) { + printf("Unable to remove all devices on bus (%s)\n", + bus->name); + return -1; + } + } + + /* All devices from all buses have been removed */ + printf("All devices on all buses unregistered.\n"); + dump_device_tree(); + + return 0; +} + +/* @internal + * For each bus registered, call the scan function to identify devices + * on the bus. + * + * @param void + * @return + * 0 for successful scan + * !0 for unsuccessful scan + * + */ +static int +test_bus_scan(void) +{ + int ret; + struct rte_bus *bus; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + /* Call the scan function for each bus */ + ret = bus->scan(); + if (ret) { + printf("Scan of buses failed.\n"); + return -1; + } + } + + printf("Scan of all buses completed.\n"); + dump_device_tree(); + + return 0; +} + + int test_bus(void) { @@ -342,6 +510,12 @@ test_bus(void) if (test_bus_registration()) return -1; + if (test_bus_scan()) + return -1; + + if (test_device_unregistration_on_bus()) + return -1; + if (test_bus_unregistration()) return -1;