From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0066.outbound.protection.outlook.com [104.47.36.66]) by dpdk.org (Postfix) with ESMTP id 4993AF919 for ; Mon, 26 Dec 2016 13:51:08 +0100 (CET) Received: from BN6PR03CA0034.namprd03.prod.outlook.com (10.175.124.20) by MWHPR03MB2479.namprd03.prod.outlook.com (10.169.200.149) 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 12:51:06 +0000 Received: from BL2FFO11FD009.protection.gbl (2a01:111:f400:7c09::139) by BN6PR03CA0034.outlook.office365.com (2603:10b6:404:10c::20) 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 12:51:06 +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 BL2FFO11FD009.mail.protection.outlook.com (10.173.161.15) 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 12:51:05 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id uBQCl90U011201; Mon, 26 Dec 2016 05:51:03 -0700 From: Shreyansh Jain To: CC: , , Shreyansh Jain Date: Mon, 26 Dec 2016 18:20:44 +0530 Message-ID: <1482756644-13726-13-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482756644-13726-1-git-send-email-shreyansh.jain@nxp.com> References: <1481893853-31790-1-git-send-email-shreyansh.jain@nxp.com> <1482756644-13726-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131272302663254714; (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)(336005)(7916002)(39840400002)(39450400003)(39380400002)(39850400002)(39400400002)(39410400002)(39860400002)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(8936002)(48376002)(50466002)(305945005)(69596002)(97736004)(5003940100001)(8676002)(68736007)(81166006)(81156014)(189998001)(85426001)(36756003)(104016004)(86362001)(105606002)(92566002)(47776003)(38730400001)(76176999)(106466001)(4326007)(2906002)(50986999)(2351001)(626004)(8656002)(356003)(6666003)(50226002)(2950100002)(110136003)(77096006)(5660300001)(33646002)(6916009)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR03MB2479; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD009; 1:N54alK2GHh9brHP6bh3nYkWy7tbUUtGrLtkHh29pNa4TJasrYifSWznSTo+KGci6tAwnenHS/20P6tKfq6SCW3IrivK9IyACfu72VDMtCIS2+7JN6JNWdOwSN/TTuyFqUli9O5FEbHAD9y0UbYCCbpIpe5//RUeHj/xeZh3ZYyNNcURMYLu/Apkato3zzV9Qzf2x0Ir5I34jkf4aSurgYqjE0V0yS5IJ8q4wfoPOlrWCGYkwrcl8ZlZDqg7zxFdJFETb0TXq/aOurImLPXqC85YxpEtw1cM/n2lU+h4wqFEOM3sXqijDbaF+9HyoXFRutDpWNh8DtwaRBtuxW6QgzWH2Zejp/7HD75RT+Q2CEX09OV33tLgifQuxsFEJ1W4X/T6sD4WTxL6L2Lo2A9/WKgostHp0udBB9/jb+t7ICSotnrPhoL1hLTCWsrMmBF7DWf+9MBDiROx9s0XL2pTmuhOwqwja0s8evU+utuYovkB/hv624pk8ITYHf/e+5eGSnt5XCUuCTchg3QzPzhaiecoY4X1OajvcPenTORb6ne1Ia0Zaznp0X3TpsWK/lhcQOIsATHWxtfAZmMHcVx0DJHEmSWDZRHn6ynXafWQdhADRLG4YUccRDNSKr3A8Iu91n+xkjtyusvfYIWXZ4WEyXGYxvzEP6cIt3p59BiKEGlaX+uZ9CzKsK5arIbSr5vRBOtuuhsIlzYTAXi8dhRXxYpSeakKaFKYno2XZc1i0Si8= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: ed5278ac-332e-4bc5-74f0-08d42d8ddb76 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:MWHPR03MB2479; X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2479; 3:NCoGZJta9NFYJvCWcoRJes/ODuHFToH6PGouHAGgRQR1E0ic+9ESUpak2WDRbYxOyU1AEbliSj6Z7svw7BvVysivRB2xGrC65iuEZKQZnDDL7Jz0tsXvRt6rnYgnHxoY4z/+CyoZV72BVhPUKEqUjPSaNDB9iVKYU4AgvNPa2bNoX5w2fLXTCCtnPaRi4yZD+KDTnDc83ZxeC923lUlBMXz/Oe1jh/pVDM9zu/yW5GoVt1yw3StvkENT2EQUUnzxCIv5aOhgZjih/WBg+1e+TzX7Qhyw8GJ9YIt1XO7yu/B8JgoiFDopHYIBYT6qa/La1Epwz0AhKZt23PEebooSeY5JJ7jBfvD1RhECEjke6HI= X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2479; 25:Aq2zTRTduYGO9hX/ababZWr29ak+qLejLaG7eoHmOZQtapCTtfw943NLMrN6TkXyeCOMyPYVS4Fz48zBILr/D+EUeKJi6NCKe1eAz+5Rg+Y75v5QKEdg9JyZz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report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095060)(601004)(2401047)(13023025)(13024025)(13015025)(13017025)(13018025)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6096035)(20161123563025)(20161123565025)(20161123561025)(20161123559025)(20161123556025); SRVR:MWHPR03MB2479; BCL:0; PCL:0; RULEID:(400006); SRVR:MWHPR03MB2479; X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2479; 4:j/UGbrSZrVWXLAbgQxvzVkp00m1KVZkeK47wVAzSSi2E5wrKY5x6ojmsZaYujpxxJQYLqN/3DvW5NT0iPFFJUT6zPoARu8Vhx/xTxl9Py75+OVaQmcbog9DW1R6CdkY0n4qemAjEM/rskkdxuOcSyTdOgKpSn38UdkngYZwOTUaAfGH/JoMEtaVM/NfEK79NudaLwFITu3+xiysa2AUCy/wElKoNOSn4IbpU64LsMmcu/wCvuT8n4TzNmO+cp/rsJfQl6LSZ5sgv9CYUz9/187KipcPe14VI8xmKzhBWeSXOtFN0VSymiww1d+IbXMCXHB0uCglJqMYIiygj24QJCcuVjCkefLnbk+ZFeGU8L+iG+/qGwEEB8zugbUDosm2GIgHLksvY4UKzpObZ4d44lTLISlZ9xW9bFhttGH54o6H84rPym33A6zvOgVpeEBpUmwNquSVH8WZKSKWDfvlkfwkapDDzzhzgc5QgZOmamvyasPNMo3U9XwUhZeUMlnMBV/+HphikD8IDgh1axs69f4BiWeKgq09mTA6WMgZj/DM2Xh6VuW9LiWXulaV74DaPJqA5JasGQc8paJ/pOuufY5NDsqbSfUicD4qJCkQbPHCa/4CajwFwsJbMpYioprTFKQT7HHtyyESXivYDkAT9RgJ/2rhTmQmQSvXpV+3ekOZX04RTfK5TwRkoqFoLDlNdFDxsKyGj3EpRhL/U0P1qYgb3ER1ESTttIzncR6h9U7CcCcnTv7451IePDtnZW2AQ X-Forefront-PRVS: 016885DD9B X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR03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Easww8aj8QKAptyIa7t4fy1ocSTUFLnFKL3maXgEAX3qleXDazpDY78aOSsJ4VKHOJ6ashIW5WsMKpA4O9CvzwI5FZQDQOWs2TxrcAncKZUIahDeWTg0ReRjCOfqt7zFLmyjsGN/0Kh2vv9yU4Dtj48P; 24:y+PoVYN6oEIm/70p7ypj+ro0Nbq1ocKST/b+vRjMHqFpHuc4szGn9iSzrRfcEq2uxErE7v4DX6u/2XPib76kMQOzJcyJYn4uftA48FtEEGU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2479; 7:Cjdeh7Imi4XWTqCfEDYNLibGs5cbLSSp5fkzmUrGUb6oZz5QNvixLZJErxxissoU3dxJYfu6UXyWS/AuJI+iTEQzPTeT7bWBW4PskAAz/4C3c0M5U3t81iRWrmwePGDicg8J8R7LqHbBLW36UnKrjoorxYtdhn8UOL4ZAkgsOcGA22gVfULtGIMBu+6UJ9c0rFN2LaFveYY52hHYdRM8EixjmjS8xZ3GRkl8jzEqkkouvbY91r4aX9z2eUIVre82OrSGL5LFyat76lZ8/Vxt1TVVSaYKjlzIk5c7lna22sUOeHV19xuJLH5/HgNX3E8wzdHlywcspQf5969rV1QzWrfwESWsvlR6M/mjKRNiFVQVyYocLCFKzpNMsw8SktKLdoJaMjcY4YG23kKE9I5lAYFoBN5E0bEPa51+vVi38/82EPfVypUcPAZmGmiuednkrvGB5Ja5tgobW94+OpE6KQ== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2016 12:51:05.9510 (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: MWHPR03MB2479 Subject: [dpdk-dev] [PATCH v4 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 12:51:09 -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