From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0079.outbound.protection.outlook.com [104.47.42.79]) by dpdk.org (Postfix) with ESMTP id BB343F927 for ; Mon, 26 Dec 2016 14:21:45 +0100 (CET) Received: from BN3PR03CA0106.namprd03.prod.outlook.com (10.174.66.24) by DM5PR03MB2474.namprd03.prod.outlook.com (10.168.233.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.803.11; Mon, 26 Dec 2016 13:21:44 +0000 Received: from BL2FFO11FD035.protection.gbl (2a01:111:f400:7c09::166) by BN3PR03CA0106.outlook.office365.com (2603:10b6:400:4::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.803.11 via Frontend Transport; Mon, 26 Dec 2016 13:21:44 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com;nxp.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BL2FFO11FD035.mail.protection.outlook.com (10.173.161.131) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.789.10 via Frontend Transport; Mon, 26 Dec 2016 13:21:43 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id uBQDKVCc029786; Mon, 26 Dec 2016 06:21:38 -0700 From: Shreyansh Jain To: CC: , , Shreyansh Jain Date: Mon, 26 Dec 2016 18:54:05 +0530 Message-ID: <1482758645-23057-13-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482758645-23057-1-git-send-email-shreyansh.jain@nxp.com> References: <1482756644-13726-1-git-send-email-shreyansh.jain@nxp.com> <1482758645-23057-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131272321038033734; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.158.2; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(336005)(39400400002)(39380400002)(39850400002)(39840400002)(39450400003)(39860400002)(39410400002)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(92566002)(2906002)(4326007)(8656002)(48376002)(50466002)(50226002)(33646002)(50986999)(76176999)(8676002)(81156014)(38730400001)(81166006)(68736007)(8936002)(77096006)(5003940100001)(5660300001)(69596002)(6666003)(2950100002)(6916009)(110136003)(189998001)(47776003)(626004)(36756003)(105606002)(305945005)(106466001)(97736004)(356003)(2351001)(86362001)(85426001)(104016004)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR03MB2474; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD035; 1:fnRgTAlf2h+xJVhJfASO1mcqJ/+aGSrVQ+9oipn+HyzZ1Imz9HkNZxpXRNkq2GDxKauRlar5cMXkk8DE5WJes9USPYbzkXqWg4MEjSw1vm6nrFFVU6zJ8kGptAY9BkZ54QipKOwv3GDkqS+cH3tFl3F9f8Gfgk9UB2GhZPKT6bplLojd4j3aeX32uIKEHk9AN8GeqStxTPrFhM25Yp20xCtPLfL0MWxy9R23D/0otl9t8ovb6znikuI8UFAcBKa44bvRB/BLd5pGKFh5KvW76IxSTzXSs0SuAZwFus0T+pMbMz36mSSPn411xn/vt/ThA2iuefub8pKPEVOTC2Ix+Lfdb8qrAUaD65Gipnh2pGcfamt3DOrR+DcBfTDhzDbJqpe0ItF4+KMnrYRjJcjAciFBKi1paQmhC8jzL3XvG4RT4d93ySyTjhS95acNvDQuBw81VoTqLJx7GJKX5MdUtS7KwLd/VaWqIvw1mI5emsCFDWGJqt1hC3dTZ0JXqZ9MS1/vSwuOO0Uy+mDj+RksnUmis7BrLhpH3UeIOZpTGsIhlKEq/OUWSLxTRjgrCOHqTKqWzjctPP9ime2bxxv2pMls5f86I+o1i6tKugiHns3Ja83vKFFkllEvx9no4Bc26kuix9jiNPSzP0f9+3fssq7g2jPOMz6GBsHq++9kgv0iVNIfPAi7p0As9O0QlM7PhjA+jGasXL4qfILeevHEEXO3RL+hdB7miFWZdG4Qyj8= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 62e4fd76-5cce-4ca8-c1e6-08d42d9222c4 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:DM5PR03MB2474; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2474; 3:C+AOI3AGqPOp1h/jsUBoRb41MHU6S3u2fy0p3Ww8amnKsuTproEKq90yNIVQLWfc6lkJ+HPoKgP9qpNs4ZDeincS6qgKmgFSknPoQEf+HTOsyxTpF23MeapGZJjPtY91JbN3zejZ5/kew4A5DDED1l4i5qFW90aJGJfhezy+a1XeVY3xdntXrBjPKbxLoGjvKpierWFmZqas1R3AP4Jiy+rofe2fFQJI2JlhZlRu1x2wxq5tJEFk4GXgpNBC3BkDGKeEX17ENsboaqlrG62E3pXQMbQ0ORUw6a0lpkwwoT6kPsN+py2Feza7D2H4tM8eGG6b1hfhZnlThZM3cFyYNRL1bI9CXd4qukbS4rRYl1DhhwLcvrxNStWZcV42wl7W; 25:mSH/xMOWl05Bhi/ITMTBa9WhmbOBHM120/o/O5cKs7OUmWgV+jK44eZM1YgevUIJXwYGsgRd219UqproDxMyNdX1IQ/Z4jtyTMxqVkWE162uHgUQ7rNU/KweipSCPNDsQ+vkLd0E7R5SrDROWcmGBM+zMBUtInp9qINk3eg8ILkTElBKwFX8ia3zEDHETFu8v+FcgGMDy57g4XZMRolks3dKQJhI+dO+s0YsbM2xCixjXcrs3Vjm397yps/0JDcDpUIpP2olTuMtbqJUb6anjzbLWRuOHoU+aUt7iorh1Gj+dY2ZNp07xiO4ks9TAi/n6a/AmGaOeLu0xM47phI9A2xrdcdNINwmWJn475Cx0wDuBoXxWtdWI/9VyqnbC+0Uoo7bFBEfdc+zaJm+570wWTPmFs+m2LFv19CDpEKvbMQgUOqZKkHlprQz4ei7m+Hep+NkiyfFXgzQLw6obDHfTg== X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2474; 31:Du+MxOEExZn0XkwjSBlMVm2aJTdzSLWXQOHGzfeWN3JFhNgE8ssT6XimOFhTRlUQJaZJZaz0ellgf6cT07TA5KqSI9BN1Uv0DS4dME22MUChSOs4QXEGxpoQtu8MwahSpvc9mzdkPPnGgcbblaZIsmS4X+RO2ieLZ1LyUaflvaq9OdOtUufwY7d3zpBkagu3uDdhqyiXXb98nngW2AdPK3uzR1QR+KZXhPLO5A3ZEM7owFqX/mNHQv3uh2swxv7lHRvJkwV/EiCm4nLpNv5SrwNFPZCg3HR2MKzfR6CaIpE= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095060)(601004)(2401047)(13024025)(13023025)(13015025)(13017025)(13018025)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6096035)(20161123561025)(20161123559025)(20161123556025)(20161123565025)(20161123563025); SRVR:DM5PR03MB2474; BCL:0; PCL:0; RULEID:(400006); SRVR:DM5PR03MB2474; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2474; 4:FFuaxwbB9ZvAj2rg46dncOLbbNBdb8auDQwSpVad1P41x4NnBO13dsOHZxfI0EbFnlBHsRfX58bStwDzamzgRKzbygz79lf2RLenrOUyF4fbRUS2ZZ6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8VW9F3lXi?= =?us-ascii?Q?Tke3Kogzs0g9OtAOp1lTVl/5mpgWqKLETqrnOU3Nc9La6nv7JG/+LNNXz2hP?= =?us-ascii?Q?suzHm8H+YeFSKqCOPR+CTyaws0peKJ5/kaEbO5cqHTMNQSV77PYe5w8n61dL?= =?us-ascii?Q?vCTx01pk4NKwL1CNaNJDz0=3D?= X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2474; 6:dT/FhLyqihoTrQL1uCDP/uctt3EGJEgmJPcpWFf/C6IN0VpPlZS61xgbtPZeF2LfyXTfvTXhg9Pzsu2X9fBJdXoVgVnu+DXALg8ZZJBhH9TGtsYA9ReSF61iuuHgRbWcYooV/BaTFFYuWQGGTiyl+pxsZBwZLKLCZuRfCe6hR3k46HANJSvvU5zvRIT69fLCc5IkoRVGI8FDEKBmCgDoo4Bs0cYpvp82r5kWDU3l5NFengOp+83X00T21icoxn7wdRDItZPQxeRv1se2kD5U/K7JSPwIAjbK8G0jwqD9Go2nhHoyppSLRsSd4UjZjyvatPwBEWeuS/yBWoT6QC5b2EGmGtZuee1C5UP9sPPD1aMR1bla8ISnxx4HNNLfsUxM8POFJ4HMu6lb8aUAvICEwx4NJalhaw4xCeXcdSS0fisvf91Cwwaq1EtXqGmfIk39; 5:9e4K/WxFH6IpXmuCXWZidxSzboEuRPSfcLO5C88C51Ed99R1BhcMmdF9pEl9QfCvSZe+042aCkTXrnZyTIuT6EJy2r1gRVqdiVeXtIclv8cGLJXs35hk/LIptDQsjpVg53TF5so1I096ENONw+yhfPrmjkbdrv3bjOymUuUaHG6ZGZZXZQbwaN62ZmfKO7Ci; 24:YQQBRFA0ytoxaT6jad45N6oR0xsCSH13y+zVFvXQfH8oaib31Etf8arcdeLsDMOai6wVHas04o7DmfKE1WWIswut47opHF+6PclQik5nCc4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2474; 7:BwY3/mybmGJ25p85zRRox8rc4VSRIE4PPnFkL4Qh6Cm4L4JRcVGSIchIWByO5XpBq98mrFKhNeoS73OZOruXbHfyratP3erVcaGZenupe212ogMCiJCGXVtITzLFASqQ7feeJSKbCvmGwZBd89ALKaZaBaQFiFAWOVfjyCd8qBcyc4l6bzc1Ki6PrfsFE9VlNfZzNIK/AYpALI5r8PutQLn3VPPG6Pn8TWfF/wXWKZ5WX/qX5hi0XW25NJAN7b7WyvCIr2z2u+I6VXm27RkVcPkR1dh+o+pF87BdzFNCuZhc5rg85WQSC+nYxvw8JgT++P1WY6SXAYENr8FC8UCsk4kTiRcRIWXWMlUKOGYUbWUFYWpn9goeJw7P2ljuKw75aZCEHtGhbDObB5QUBFy3s1KZQOdW9Oq/Wx8mUz01UQQIS9Nabct6d1HDu4lUUj+3q5Es/69IjFq1wMqLs0EiJg== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2016 13:21:43.5537 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2474 Subject: [dpdk-dev] [PATCH v5 12/12] eal/bus: add bus iteration macros 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: Mon, 26 Dec 2016 13:21:46 -0000 Three macros: FOREACH_BUS FOREACH_DEVICE_ON_BUS FOREACH_DRIVER_ON_BUS are introduced to make looping over bus (on global list), devices and drivers (on a specific bus) prettier. Signed-off-by: Shreyansh Jain --- app/test/test_pci.c | 12 ++++++------ lib/librte_eal/common/eal_common_bus.c | 12 ++++++------ lib/librte_eal/common/eal_common_pci.c | 10 +++++----- lib/librte_eal/common/include/rte_bus.h | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/app/test/test_pci.c b/app/test/test_pci.c index e95b758..6a413e8 100644 --- a/app/test/test_pci.c +++ b/app/test/test_pci.c @@ -129,7 +129,7 @@ do_pci_device_dump(FILE *f) struct rte_pci_device *dev = NULL; struct rte_device *r_dev = NULL; - TAILQ_FOREACH(r_dev, &pci_bus->device_list, next) { + FOREACH_DEVICE_ON_BUS(pci_bus, r_dev) { dev = container_of(r_dev, struct rte_pci_device, device); fprintf(f, PCI_PRI_FMT, dev->addr.domain, dev->addr.bus, @@ -154,8 +154,8 @@ do_pci_bus_probe(void) struct rte_device *device; struct rte_driver *driver; - TAILQ_FOREACH(device, &pci_bus->device_list, next) { - TAILQ_FOREACH(driver, &pci_bus->driver_list, next) { + FOREACH_DEVICE_ON_BUS(pci_bus, device) { + FOREACH_DRIVER_ON_BUS(pci_bus, driver) { ret = pci_bus->match(driver, device); if (!ret) { if (!driver->probe) @@ -180,7 +180,7 @@ blacklist_all_devices(void) unsigned i = 0; char pci_addr_str[16]; - TAILQ_FOREACH(device, &(pci_bus->device_list), next) { + FOREACH_DEVICE_ON_BUS(pci_bus, device) { dev = container_of(device, struct rte_pci_device, device); snprintf(pci_addr_str, sizeof(pci_addr_str), PCI_PRI_FMT, dev->addr.domain, dev->addr.bus, dev->addr.devid, @@ -265,12 +265,12 @@ test_pci_cleanup(void) * cannot free the devices in the right way. Let's assume that we * don't care for tests. */ - TAILQ_FOREACH(dev, &(pci_bus->device_list), next) { + FOREACH_DEVICE_ON_BUS(pci_bus, dev) { rte_eal_bus_remove_device(dev); dev->driver = NULL; } - TAILQ_FOREACH(dr, &(pci_bus->driver_list), next) { + FOREACH_DRIVER_ON_BUS(pci_bus, dr) { rte_eal_bus_remove_driver(dr); } diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index 6dc7b73..f8c2e03 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -125,7 +125,7 @@ rte_eal_bus_get(const char *bus_name) RTE_VERIFY(bus_name); - TAILQ_FOREACH(bus, &rte_bus_list, next) { + FOREACH_BUS(bus) { RTE_VERIFY(bus->name); if (!strcmp(bus_name, bus->name)) @@ -179,7 +179,7 @@ rte_eal_bus_scan(void) int ret; struct rte_bus *bus = NULL; - TAILQ_FOREACH(bus, &rte_bus_list, next) { + FOREACH_BUS(bus) { ret = bus->scan(bus); if (ret) { RTE_LOG(ERR, EAL, "Scan for (%s) bus failed.\n", @@ -228,9 +228,9 @@ rte_eal_bus_probe(void) struct rte_driver *driver; /* For each bus registered with EAL */ - TAILQ_FOREACH(bus, &rte_bus_list, next) { - TAILQ_FOREACH(device, &bus->device_list, next) { - TAILQ_FOREACH(driver, &bus->driver_list, next) { + FOREACH_BUS(bus) { + FOREACH_DEVICE_ON_BUS(bus, device) { + FOREACH_DRIVER_ON_BUS(bus, driver) { ret = bus->match(driver, device); if (!ret) { ret = perform_probe(bus, driver, @@ -273,7 +273,7 @@ rte_eal_bus_dump(FILE *f) int ret; struct rte_bus *bus; - TAILQ_FOREACH(bus, &rte_bus_list, next) { + FOREACH_BUS(bus) { ret = bus_dump_one(f, bus); if (ret) { RTE_LOG(ERR, EAL, "Unable to write to stream (%d)\n", diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index ce19b9a..2d5a399 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -283,7 +283,7 @@ pci_probe_all_drivers(struct rte_bus *bus, struct rte_pci_device *dev) if (dev->driver != NULL) return 0; - TAILQ_FOREACH(r_dr, &bus->driver_list, next) { + FOREACH_DRIVER_ON_BUS(bus, r_dr) { rc = rte_eal_pci_probe(r_dr, &dev->device); if (rc < 0) /* negative value is an error */ @@ -311,7 +311,7 @@ pci_detach_all_drivers(struct rte_bus *bus, struct rte_pci_device *dev) if (dev == NULL) return -1; - TAILQ_FOREACH(r_dr, &bus->driver_list, next) { + FOREACH_DRIVER_ON_BUS(bus, r_dr) { dr = container_of(r_dr, struct rte_pci_driver, driver); rc = rte_eal_pci_detach_dev(dr, dev); if (rc < 0) @@ -352,7 +352,7 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr) if (pci_update_device(bus, addr) < 0) goto err_return; - TAILQ_FOREACH(r_dev, &bus->device_list, next) { + FOREACH_DEVICE_ON_BUS(bus, r_dev) { dev = container_of(r_dev, struct rte_pci_device, device); if (rte_eal_compare_pci_addr(&dev->addr, addr)) continue; @@ -391,7 +391,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr) return -1; } - TAILQ_FOREACH(r_dev, &bus->device_list, next) { + FOREACH_DEVICE_ON_BUS(bus, r_dev) { dev = container_of(r_dev, struct rte_pci_device, device); if (rte_eal_compare_pci_addr(&dev->addr, addr)) continue; @@ -517,7 +517,7 @@ rte_eal_pci_dump(FILE *f) return; } - TAILQ_FOREACH(r_dev, &bus->device_list, next) { + FOREACH_DEVICE_ON_BUS(bus, r_dev) { dev = container_of(r_dev, struct rte_pci_device, device); pci_dump_one_device(f, dev); } diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index 3bd3ab5..07c30c4 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -56,6 +56,39 @@ extern "C" { /** Double linked list of buses */ TAILQ_HEAD(rte_bus_list, rte_bus); +/* Helpers for Bus, device and driver list traversal */ + +/** + * Iterate over all the buses registered + * + * @param bus + * A rte_bus type NULL initialized pointer + */ +#define FOREACH_BUS(bus) \ + TAILQ_FOREACH((bus), &rte_bus_list, next) + +/** + * Iterate over all the drivers registered with a particular bus + * + * @param bus + * Valid reference of bus to iterate over + * @param drv + * NULL initialized rte_driver type pointer + */ +#define FOREACH_DRIVER_ON_BUS(bus, drv) \ + TAILQ_FOREACH((drv), &(bus)->driver_list, next) + +/** + * Iterate over all the devices scanned/found on a particular bus + * + * @param bus + * Valid reference of bus to iterate over + * @param dev + * NULL initialized rte_device type pointer + */ +#define FOREACH_DEVICE_ON_BUS(bus, dev) \ + TAILQ_FOREACH((dev), &(bus)->device_list, next) + /* Global Bus list */ extern struct rte_bus_list rte_bus_list; -- 2.7.4