From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0060.outbound.protection.outlook.com [104.47.40.60]) by dpdk.org (Postfix) with ESMTP id 5E6434B79 for ; Tue, 13 Dec 2016 14:35:11 +0100 (CET) Received: from DM5PR03CA0012.namprd03.prod.outlook.com (10.175.104.22) by BY2PR0301MB0741.namprd03.prod.outlook.com (10.160.63.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.747.13; Tue, 13 Dec 2016 13:35:08 +0000 Received: from BN1AFFO11FD015.protection.gbl (2a01:111:f400:7c10::119) by DM5PR03CA0012.outlook.office365.com (2603:10b6:3:118::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.771.8 via Frontend Transport; Tue, 13 Dec 2016 13:35:07 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) 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.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD015.mail.protection.outlook.com (10.58.52.75) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.761.6 via Frontend Transport; Tue, 13 Dec 2016 13:35:06 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:; UpperCasedChecksum:; SizeAsReceived:798; Count:10 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id uBDDYRwC005048; Tue, 13 Dec 2016 06:35:03 -0700 From: Shreyansh Jain To: , CC: , , , Shreyansh Jain Date: Tue, 13 Dec 2016 19:07:08 +0530 Message-ID: <1481636232-2300-9-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481636232-2300-1-git-send-email-shreyansh.jain@nxp.com> References: <1480846288-2517-1-git-send-email-shreyansh.jain@nxp.com> <1481636232-2300-1-git-send-email-shreyansh.jain@nxp.com> X-IncomingHeaderCount: 10 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131261097069097435; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(7916002)(39840400002)(39410400002)(39850400002)(39860400002)(39450400003)(39380400002)(39400400002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(50466002)(104016004)(86362001)(97736004)(356003)(305945005)(68736007)(92566002)(33646002)(8666005)(106466001)(105606002)(2906002)(189998001)(50226002)(76176999)(8936002)(81156014)(81166006)(38730400001)(4326007)(8676002)(36756003)(5003940100001)(50986999)(77096006)(5001770100001)(48376002)(626004)(85426001)(47776003)(5660300001)(2950100002)(7059030)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR0301MB0741; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD015; 1:ze2K5+6K7tfP+lXnfXmulmVl/gq/HLbr9t4W5eLpgHHzwmlg1nmg9HcY992iWZOWfnySt/mFMHvltyY3Kkx9iS4jchgVjMKIaF/g7kIaaE6oxSK+blLn8omB7QeIAJNSExV7hLZlGcMwcBsuy9ueg+9995u7QJ+oQIaX3RvHk++o7XF1YVc6MzX0yrZVQRyZmXHuyw2IDXFZBwApF0rhEu28Uuze2/WE1a+ZzTcZGjOB0VhAqOys7meavbCKIbMncyf0cIZ0iL9mrUMWuhZ0ez9icC8Dwu3bS8N8xnQ0yjk9SsDyb+PIjqn/uvmPNFLRvnjHDnri0Ej1S++enkmV8435QLoie7Y8uB3uUuo4ocLrjFNKV1kAP8kJ5xA3iiZiKYUvtS1tDL5lNfkG8cuconWcTwMmPMWbVGoKQ8MpivJTIPoPzSw09MOpLFLsR11N2mSl5zbJMHONCVZtuRlOnWa1e5ysquDsLQvd8TMa3tA+KB74gZKHhcrOzedelJNq+6tXIpvLT06upPqw7TxARZZy6Tpo+65DRBhVnNRAaZCvm2bupJxXrV8jmg0nasFVsHji2fuJaw8cxGRaND0q6dS4pgMknIVMNcYZAoIjQrp6WQ6nX77fqoVlG0LsYQuzGBciofO1FfVD65e416JG8wD2xijSZBBlJyGhURSpuiXRY9H8Uz1/mGDLLAFcpAM+xvQMSf+0McCL1ZeEVqS0Q95WyFzo1zn0EpgnXQOjx0yt5XKGcU/o8AeSjjxnFKtfJrbWIXBcc/C/gAKHYSXJZQ== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 76fe1199-6780-474b-a6eb-08d4235cda05 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BY2PR0301MB0741; X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0741; 3:HCoR6UO0O16MwJ5/6W+ZaDV8BNryr6L/HBtILuPM8DDQ0eZf3O8O2QjQj1MT7O1ixFMV2ggHuHN8BmhLdwTATmI/lBpmcyAzLplQqPz5yfp7F9zA3S2vtMFoTayKnQEi3XZi8A+YxXysoqA74YnAm8Ukw8blIYGmOFeALL6eiBfiWR57sSeR7+MJc2CfLj2goLCrfucmC5bdBiP5CN3Op+w0FKlgcKChc0IClyJeCc3U2sISzKRtVoSoUxILnJQN9t3JTfTeeAbZK0JBZrlggGdjt5C6s66xuXkczn1cVnTGxY969U7+pcOOoJYFkWiIL0xAnxhx7CmKLOumC0F69Pc1kpVDYRohUQPKp15z7ZjwEbXSGzWA0M0ZIwpm+3r/; 25:+boVL2l3twdZMjl+BghSpzqKgzoxcNpbUQ/exNK5iTBmAuJL1zPA7zvjoSCVtTteslN0g35pX5EAW+g8YiGp6h7O3+DX3nPeQg3aSf/xvvHv5F8xNCkTPT8rPIKq0dsZKUYb6zlLSdv8eVdxex1OzHgIL1vWKey051S03wyQ367uQY7IQMxv7pQt9fhHgzYx/DjNQU2PJZq1JSz/BSn77kwpkoOuWHyXtCXEaY0nXZCt6jxxq0hjl7r+fJ11vcE6WBHocr9W3Trq1PF1D2Dco+hKZ7DuVpvz2lXPMaWMa0JO4QdaBIiT8Bv3PCgQLXPKRKF4e3vO01+Tv7dAES1vtFDsbdMF1jz45EqWYt2m4wC77nrDOdGCBol+Vakeehncsj55eeA8p9o91yRmwx/5MiJ1RyuVHcReTZ4eRCKTE6fguwfaAzy+Zy5yWT0u24wAX0KAQvQ9xt3Ea/1HXCS98g== X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0741; 31:bFvwam96zd45lOQVokOLnCRxzWrmUC2wzkUoQs3uc3oW92IzShNMoKjV4ydKTOaxCB/1SqhGOqtCztfyPj4ebyIXTa1pTPC6+mJ2WKP1PkC7VPFkm5hnR8ijOX4ZGiPASOpHeycS94E6H7AYroEY1F1ENfrbCFhilMlHfBFoSWFrofxhNFAx/hdaey7qQG9lY7r5ZfnUrL/mr4Ll0GtXM4EvPAJspmvPqllixyc4XOzKqE3GKCK6NRGTm1d2uut9EJsWS9i5LMpeIecvvUi+3Q== 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)(13015025)(8121501046)(5005006)(13018025)(13024025)(13017025)(13023025)(3002001)(10201501046)(6055026)(6096035)(20161123559025)(20161123561025)(20161123563025)(20161123565025)(20161123556025); SRVR:BY2PR0301MB0741; BCL:0; PCL:0; RULEID:(400006); SRVR:BY2PR0301MB0741; X-Microsoft-Exchange-Diagnostics: 1; BY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SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0741; 7:jE0G6tKadHPbHA3fKevLqxm/wGo7bhTSdRWTKcW2DdStix90SFkCrhv5J8Iy37Q0IPzVVOwt6+nvPMHvUqPemohuSL4CX4J6LtoWWSs8b3S8BqGlmvqF/fWNBokXkmaTsy8yyclaOScbx6FQn0c4aGPIVrGVMdMPvoh1Yrh63v2s3KZdXEGn3aWTjhPrenewO97CVqrpE0+Qpu8DSR55rtIiUbOB4jRxI2tVbTAbp3yx6ikjhEqxIxm7uG7FTcLyaTvjflUoE84PEu/VmFR2cd5eZMaXIYdjS9I1OlYtKfpkVRL9DvbZRYmtUe55nraBDzV2ImwuUIgv6t4Wkv8Ag9pcMMQ8ny6ZWsbdBvJuZr7bSYAHWRZovcTL7IU/877TNA25ownpQMLPs55W+NQg2P8C6cAHCHiGE1t2ZWLAnWChr3Kxdm+98I8a4qBemZzVrX3peSAFQf3N7IuO0B2jMQ== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2016 13:35:06.6133 (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.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR0301MB0741 Subject: [dpdk-dev] [PATCH v2 08/12] pci: split match and probe function 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: Tue, 13 Dec 2016 13:35:12 -0000 Matching of PCI device address and driver ID table is being done at two discreet locations duplicating the code. (rte_eal_pci_probe_one_driver and rte_eal_pci_detach_dev). Splitting the matching function into rte_eal_pci_match. Signed-off-by: Shreyansh Jain -- v2: - Change default return in match function --- lib/librte_eal/common/eal_common_pci.c | 198 ++++++++++++++++++-------------- lib/librte_eal/common/include/rte_pci.h | 15 +++ 2 files changed, 125 insertions(+), 88 deletions(-) diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 6bff675..706f91c 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -152,131 +152,153 @@ pci_unmap_resource(void *requested_addr, size_t size) requested_addr); } -/* - * If vendor/device ID match, call the probe() function of the - * driver. - */ -static int -rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev) +int +rte_eal_pci_match(struct rte_pci_driver *pci_drv, + struct rte_pci_device *pci_dev) { - int ret; + int match = 1; const struct rte_pci_id *id_table; - for (id_table = dr->id_table; id_table->vendor_id != 0; id_table++) { + if (!pci_drv || !pci_dev || !pci_drv->id_table) { + RTE_LOG(DEBUG, EAL, "Invalid PCI Driver object\n"); + return -1; + } + for (id_table = pci_drv->id_table; id_table->vendor_id != 0; + id_table++) { /* check if device's identifiers match the driver's ones */ - if (id_table->vendor_id != dev->id.vendor_id && + if (id_table->vendor_id != pci_dev->id.vendor_id && id_table->vendor_id != PCI_ANY_ID) continue; - if (id_table->device_id != dev->id.device_id && + if (id_table->device_id != pci_dev->id.device_id && id_table->device_id != PCI_ANY_ID) continue; - if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id && - id_table->subsystem_vendor_id != PCI_ANY_ID) + if (id_table->subsystem_vendor_id != + pci_dev->id.subsystem_vendor_id && + id_table->subsystem_vendor_id != PCI_ANY_ID) continue; - if (id_table->subsystem_device_id != dev->id.subsystem_device_id && - id_table->subsystem_device_id != PCI_ANY_ID) + if (id_table->subsystem_device_id != + pci_dev->id.subsystem_device_id && + id_table->subsystem_device_id != PCI_ANY_ID) continue; - if (id_table->class_id != dev->id.class_id && + if (id_table->class_id != pci_dev->id.class_id && id_table->class_id != RTE_CLASS_ANY_ID) continue; - struct rte_pci_addr *loc = &dev->addr; - - RTE_LOG(INFO, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", - loc->domain, loc->bus, loc->devid, loc->function, - dev->device.numa_node); - - /* no initialization when blacklisted, return without error */ - if (dev->device.devargs != NULL && - dev->device.devargs->type == - RTE_DEVTYPE_BLACKLISTED_PCI) { - RTE_LOG(INFO, EAL, " Device is blacklisted, not initializing\n"); - return 1; - } - - RTE_LOG(INFO, EAL, " probe driver: %x:%x %s\n", dev->id.vendor_id, - dev->id.device_id, dr->driver.name); - - if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) { - /* map resources for devices that use igb_uio */ - ret = rte_eal_pci_map_device(dev); - if (ret != 0) - return ret; - } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND && - rte_eal_process_type() == RTE_PROC_PRIMARY) { - /* unbind current driver */ - if (pci_unbind_kernel_driver(dev) < 0) - return -1; - } - - /* reference driver structure */ - dev->driver = dr; - - /* call the driver probe() function */ - ret = dr->probe(dr, dev); - if (ret) - dev->driver = NULL; - - return ret; + match = 0; + break; } - /* return positive value if driver doesn't support this device */ - return 1; + + return match; } /* - * If vendor/device ID match, call the remove() function of the + * If vendor/device ID match, call the probe() function of the * driver. */ static int -rte_eal_pci_detach_dev(struct rte_pci_driver *dr, - struct rte_pci_device *dev) +rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, + struct rte_pci_device *dev) { - const struct rte_pci_id *id_table; + int ret; + struct rte_pci_addr *loc; if ((dr == NULL) || (dev == NULL)) return -EINVAL; - for (id_table = dr->id_table; id_table->vendor_id != 0; id_table++) { + loc = &dev->addr; - /* check if device's identifiers match the driver's ones */ - if (id_table->vendor_id != dev->id.vendor_id && - id_table->vendor_id != PCI_ANY_ID) - continue; - if (id_table->device_id != dev->id.device_id && - id_table->device_id != PCI_ANY_ID) - continue; - if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id && - id_table->subsystem_vendor_id != PCI_ANY_ID) - continue; - if (id_table->subsystem_device_id != dev->id.subsystem_device_id && - id_table->subsystem_device_id != PCI_ANY_ID) - continue; + RTE_LOG(INFO, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", + loc->domain, loc->bus, loc->devid, loc->function, + dev->device.numa_node); - struct rte_pci_addr *loc = &dev->addr; + /* no initialization when blacklisted, return without error */ + if (dev->device.devargs != NULL && + dev->device.devargs->type == + RTE_DEVTYPE_BLACKLISTED_PCI) { + RTE_LOG(INFO, EAL, " Device is blacklisted, not" + " initializing\n"); + return 1; + } - RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", - loc->domain, loc->bus, loc->devid, - loc->function, dev->device.numa_node); + /* The device is not blacklisted; Check if driver supports it */ + ret = rte_eal_pci_match(dr, dev); + if (ret) { + /* Match of device and driver failed */ + RTE_LOG(DEBUG, EAL, "Driver (%s) doesn't match the device\n", + dr->driver.name); + return 1; + } - RTE_LOG(DEBUG, EAL, " remove driver: %x:%x %s\n", dev->id.vendor_id, - dev->id.device_id, dr->driver.name); + RTE_LOG(INFO, EAL, " probe driver: %x:%x %s\n", dev->id.vendor_id, + dev->id.device_id, dr->driver.name); + + if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) { + /* map resources for devices that use igb_uio */ + ret = rte_eal_pci_map_device(dev); + if (ret != 0) + return ret; + } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND && + rte_eal_process_type() == RTE_PROC_PRIMARY) { + /* unbind current driver */ + if (pci_unbind_kernel_driver(dev) < 0) + return -1; + } - if (dr->remove && (dr->remove(dev) < 0)) - return -1; /* negative value is an error */ + /* reference driver structure */ + dev->driver = dr; - /* clear driver structure */ + /* call the driver probe() function */ + ret = dr->probe(dr, dev); + if (ret) { + RTE_LOG(DEBUG, EAL, "Driver (%s) probe failed.\n", + dr->driver.name); dev->driver = NULL; + } - if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) - /* unmap resources for devices that use igb_uio */ - rte_eal_pci_unmap_device(dev); + return ret; +} - return 0; +/* + * If vendor/device ID match, call the remove() function of the + * driver. + */ +static int +rte_eal_pci_detach_dev(struct rte_pci_driver *dr, + struct rte_pci_device *dev) +{ + int ret; + struct rte_pci_addr *loc; + + if ((dr == NULL) || (dev == NULL)) + return -EINVAL; + + ret = rte_eal_pci_match(dr, dev); + if (ret) { + /* Device and driver don't match */ + return 1; } - /* return positive value if driver doesn't support this device */ - return 1; + loc = &dev->addr; + + RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", + loc->domain, loc->bus, loc->devid, + loc->function, dev->device.numa_node); + + RTE_LOG(DEBUG, EAL, " remove driver: %x:%x %s\n", dev->id.vendor_id, + dev->id.device_id, dr->driver.name); + + if (dr->remove && (dr->remove(dev) < 0)) + return -1; /* negative value is an error */ + + /* clear driver structure */ + dev->driver = NULL; + + if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) + /* unmap resources for devices that use igb_uio */ + rte_eal_pci_unmap_device(dev); + + return 0; } /* diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 9ce8847..c9b113d 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -369,6 +369,21 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr, int rte_eal_pci_scan(void); /** + * Match the PCI Driver and Device using the ID Table + * + * @param pci_drv + * PCI driver from which ID table would be extracted + * @param pci_dev + * PCI device to match against the driver + * @return + * 0 for successful match + * !0 for unsuccessful match + */ +int +rte_eal_pci_match(struct rte_pci_driver *pci_drv, + struct rte_pci_device *pci_dev); + +/** * Probe the PCI bus for registered drivers. * * Scan the content of the PCI bus, and call the probe() function for -- 2.7.4