From patchwork Thu Jan 19 04:45:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 19762 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 17A9AFB4D; Thu, 19 Jan 2017 05:45:46 +0100 (CET) Received: from mail-wm0-f50.google.com (mail-wm0-f50.google.com [74.125.82.50]) by dpdk.org (Postfix) with ESMTP id 3864CFB27 for ; Thu, 19 Jan 2017 05:45:28 +0100 (CET) Received: by mail-wm0-f50.google.com with SMTP id c85so272770995wmi.1 for ; Wed, 18 Jan 2017 20:45:28 -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=M2oKPOElLZ0Mv4Zb0rjdu0rDaSr/bfRrGEojWyXuzkQ=; b=JJkfQnJnVlSF9Sb843Pr7n0GZALGfs4ug1tiM796X39jK8y9fUmsmXWbt3s5+9izV9 K93DiGSyveGcMx3cH1O4uGF7k0Nwy0To/V6ZQsZQ+N2inaN2l9XTICN3lk0Y+R+8GFaI kRxWB06JlKDm4YJpUc/6oMKKoqjh7Ar3YlOmx7FK32WhVKRGJ2lEoU9AXAfJTaBbcZEj Tt2h9CBk8JUqjFvqIMmq2Ro0yQl+ZSK/pfwH1KLuNY+1TQ3JW6X4AXt9KqChWHpxAtfJ SbtIZ88Inz5C1h8eWFVKtRex2ycfgPRsJuhUlwsI1amGVD/HTkQFCbEmO5y8bjJu9RSb 2NKg== 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=M2oKPOElLZ0Mv4Zb0rjdu0rDaSr/bfRrGEojWyXuzkQ=; b=EaF6JQHBxpDGMtH42OgtMOnI/VYorDIUVcLQuz4pxLxjuYYdCYmNPVEThgMLC/Alu2 UV6qO3abYqZNWUaOxdoDF8GqDiZPHtSaJ1c+884M/qmSMmu/ZvM/zwGwojsOn3MJcW9w prUcK8DmuLYoqqhaHrsGbma6bk4uH2czY0SGUlSNYPgip6rYu7oxBKHtdsaAMQnVPbUv HtKJTGDmwL9CKeZ9ZlAe67XQ0WcrmJmBYKGVDux7hnfRzQUeSbSSO6kDbizqEUPwrW5W 36JUPVvezH9n/S3UbaCP4aZ7VpR5R31Q32WlSMuq8hmywEXLhu4AYxsTFNETW6Dd5MVs OfMQ== X-Gm-Message-State: AIkVDXKi1I1YzUpKxmjESzlLaR/4gtPEUgJ1ur3H/ZryTCOuXonqQflP1qRQaezo7kCue5k3 X-Received: by 10.223.135.69 with SMTP id 5mr6301783wrz.174.1484801127908; Wed, 18 Jan 2017 20:45:27 -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.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jan 2017 20:45:27 -0800 (PST) From: Thomas Monjalon To: Shreyansh Jain Cc: dev@dpdk.org Date: Thu, 19 Jan 2017 05:45:10 +0100 Message-Id: <1484801117-779-7-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 06/13] app/test: check bus probe 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 | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/app/test/test_bus.c b/app/test/test_bus.c index de4f1ab..a3220f3 100644 --- a/app/test/test_bus.c +++ b/app/test/test_bus.c @@ -120,12 +120,15 @@ static int scan_fn_for_busB(void); /* generic implementations wrapped around by above declarations */ static int generic_scan_fn(struct rte_bus *bus); +static int generic_probe_fn(void); +static int dummy_match_fn(struct rte_driver *drv, struct rte_device *dev); struct dummy_bus busA = { .name = "busA_impl", /* busA */ .bus = { .name = "busA", .scan = scan_fn_for_busA, + .probe = generic_probe_fn, }, }; @@ -134,6 +137,7 @@ struct dummy_bus busB = { .bus = { .name = "busB", .scan = scan_fn_for_busB, + .probe = generic_probe_fn, }, }; @@ -283,6 +287,44 @@ generic_scan_fn(struct rte_bus *bus) return 0; } +/* @internal + * Obtain bus from driver object. Match the address of rte_device object + * with all the devices associated with that bus. + * + * Being a test function, all this does is validate that device object + * provided is available on the same bus to which driver is registered. + * + * @param drv + * driver to match with + * @param dev + * device object + * @return + * 0 for successful match + * !0 for failed match + */ +static int +dummy_match_fn(struct rte_driver *drv __rte_unused, struct rte_device *dev) +{ + struct dummy_device *ddev = NULL; + struct dummy_device *ddev_as_arg; + struct dummy_bus *dbus = NULL; + + /* Match is based entirely on address of 'dev' and 'dev_p' extracted + * from bus->device_list. + */ + + /* a driver is registered with the bus *before* the scan. */ + dbus = &busA; /* FIXME: bus cannot be retrieved without knowing the driver */ + ddev_as_arg = container_of(dev, struct dummy_device, dev); + + TAILQ_FOREACH(ddev, &dbus->device_list, next) { + if (ddev == ddev_as_arg) + return 0; + } + + return 1; +} + int scan_fn_for_busA(void) { struct dummy_bus_map *dbm; @@ -499,6 +541,109 @@ test_bus_scan(void) return 0; } +/* + * + */ +static int +generic_probe_fn(void) +{ + int ret = 0; + int i, j; + struct rte_driver *drv; + struct rte_device *dev; + struct dummy_bus *dbus = NULL; + struct dummy_device *ddev = NULL; + struct dummy_driver *ddrv = NULL; + + /* In case of this test: + * 1. for each bus in rte_bus_list + * 2. for each device on that bus (bus specific->device_list) + * 3. for each driver on that bus (bus specific->driver_list) + * 4. call match + * 5. link driver and device + * 6. Verify the linkage. + */ + for (i = 0; bus_map[i].name; i++) { + /* get bus pointer from bus_map itself */ + dbus = bus_map[i].dbus; + + /* Looping over all scanned devices */ + TAILQ_FOREACH(ddev, &dbus->device_list, next) { + /* There is a list of drivers within dummy_bus_map. + * In case of PMDs, this would be driver registration + * APIs/list + */ + for (j = 0; bus_map[i].ddrivers[j]; j++) { + ddrv = bus_map[i].ddrivers[j]; + + drv = &ddrv->drv; + dev = &ddev->dev; + ret = dummy_match_fn(drv, dev); + if (!ret) { + /* As match is generic, it always + * results in dev->drv pointing to + * first driver entry in bus_map[i] + */ + dev->driver = drv; + } + /* Else, continue */ + } + } + } + + /* Verify the linkage. All devices belonging to a bus_map[i] + * should have same driver (first driver entry of bus_map[i]) + */ + for (i = 0; bus_map[i].name; i++) { + ddrv = bus_map[i].ddrivers[0]; + drv = &ddrv->drv; + + for (j = 0; bus_map[i].ddevices[j]; j++) { + ddev = bus_map[i].ddevices[j]; + dev = &ddev->dev; + if (dev->driver != drv) { + printf("Incorrect driver<->device linkage.\n"); + return -1; + } + } + } + + return 0; +} + +/* @internal + * Function to perform 'probe' and link devices and drivers on a bus. + * This would work over all the buses registered, and all devices and drivers + * registered with it - call match on each pair. + * + * @param void + * @return + * 0 for successful probe + * !0 for failure in probe + * + */ +static int +test_probe_on_bus(void) +{ + int ret = 0; + int i; + struct dummy_bus *dbus; + struct rte_bus *bus; + + for (i = 0; bus_map[i].name; i++) { + /* get bus pointer from bus_map itself */ + dbus = bus_map[i].dbus; + bus = &dbus->bus; + ret = bus->probe(); + if (ret) + printf("Probe for %s failed.\n", bus_map[i].name); + } + + printf("Probe on all buses successful.\n"); + dump_device_tree(); + + return 0; +} int test_bus(void) @@ -513,6 +658,10 @@ test_bus(void) if (test_bus_scan()) return -1; + /* Now that the devices and drivers are registered, perform probe */ + if (test_probe_on_bus()) + return -1; + if (test_device_unregistration_on_bus()) return -1;