From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-cys01nam02on0079.outbound.protection.outlook.com [104.47.37.79]) by dpdk.org (Postfix) with ESMTP id 023DB4A59 for ; Sun, 4 Dec 2016 11:09:25 +0100 (CET) Received: from BLUPR0301CA0032.namprd03.prod.outlook.com (10.162.113.170) by BY2PR0301MB0744.namprd03.prod.outlook.com (10.160.63.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.747.13; Sun, 4 Dec 2016 10:09:24 +0000 Received: from BL2FFO11OLC003.protection.gbl (2a01:111:f400:7c09::118) by BLUPR0301CA0032.outlook.office365.com (2a01:111:e400:5259::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.761.9 via Frontend Transport; Sun, 4 Dec 2016 10:09:23 +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 BL2FFO11OLC003.mail.protection.outlook.com (10.173.161.187) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.734.4 via Frontend Transport; Sun, 4 Dec 2016 10:09:23 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:; UpperCasedChecksum:; SizeAsReceived:685; Count:10 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id uB4A8pKD019825; Sun, 4 Dec 2016 03:09:20 -0700 From: Shreyansh Jain To: CC: , , Shreyansh Jain Date: Sun, 4 Dec 2016 15:41:24 +0530 Message-ID: <1480846288-2517-10-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1480846288-2517-1-git-send-email-shreyansh.jain@nxp.com> References: <1480846288-2517-1-git-send-email-shreyansh.jain@nxp.com> X-IncomingHeaderCount: 10 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131253197635949594; (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)(2980300002)(1109001)(1110001)(339900001)(336004)(199003)(189002)(2950100002)(33646002)(38730400001)(85426001)(7846002)(2906002)(4326007)(77096006)(356003)(626004)(106466001)(2351001)(5660300001)(110136003)(68736007)(50986999)(76176999)(8666005)(6916009)(104016004)(50226002)(8676002)(47776003)(189998001)(8936002)(97736004)(105606002)(5003940100001)(81156014)(81166006)(50466002)(39380400001)(39410400001)(92566002)(36756003)(39400400001)(48376002)(86362001)(305945005)(69596002)(39450400002)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR0301MB0744; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11OLC003; 1:Fw3IE55tysNOgQU1zRI2teSGmbuI9pY+kcDfzPwWBdoOs1696jbokiq2+GyEJtp2EKSlg1jOV2JiEuPkqTp7AJAqWZbMgfF+lCXY3WqA1YUEOOn06SnahyGYiY2K7kM+h8LAJdrGQfXPAjMxsDg3QnluWTsvnVXC0DNFR8ISRYADlWNj0UoA1fgyR3h7NeLjzUdcpxW6fstNbJvNM/T8UKzcQJTQjx3J1jPV0loiwmH3KW+FyICk6edTiX2mgAkbOjD5G2qISeCtkPj7b1MCFv71f1MDLRh1ROEATHQa5P2GP7TrXGj9+1R/ASFowSQXyx9RLxjq00NA9/ZxuNVCvGoBHcenIwvcKlirqha/5mxwsKODa54Lcqg/VoSGAzbpk/b3kS9Pf1TSXZoOdI9xjqCuCasCGu70HPHR45GMH3/8zfXVbUDBYbelZ+u3Ac1Pa7jcE7ii+ZFQ/drbTRSONF3zI7cNV9CkPDZXiqsNSdeBHLwj7x6T+2Yz+0oLC9bnl8gP8j5QxhBStkcoW0S3gkv7F7CVrNKD16UgXAdKkBDhDXSFeyQS3FRt2gi8cV7/q0ZdBo3E5csxwJnx9zO8HTLKrUwXb5FOdSohNH+eSwcu5NahLmTSVDV/m4iiIrPAsJgpdZuY9zVat21oUwwY6pRuCv6hmHbvwh7YZGEp5ghXoLFTpuav6I9H4mafjPgpO6DgFLRcejZclITnek04pzKP8WMT2k8VK1lHC5emrgo= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 432f4794-cb36-4292-27cc-08d41c2d9f1b X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BY2PR0301MB0744; X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0744; 3:S9aqKsjOx+C4alojb7Y7f3b6zcPCCKSbG3M/A4cFrt1rcGFfw+CXaOsVTA+jOGhp65vnmLE8gtjquh2vDsScPmOcZHPcEr1MInIUdW1UIzmhwXAo/ncjBNKSpmC+2xrgF3CcUMXWfYqhLJxjTmO+VcFvuV7nIG/vE2jOvGV81ZOY78teSrAGHDxDHtXXyVKTKRH6eRL6LKmigvzG8lOAXvHqmJQF8PsDCeSpfwZ/G5nUXKLYmB1Oc8DY5bTVgaD7s6jyei9Cxkr7iVx86ins99qhZ3N/0122Ghh6y3nKZ/eZB+t77tBboN4IRyv8Gf1YxaH4I7NbzxQtE7GMoKk4lpJtOh2Ce9Vq8O2at0x7PCeCoaKMmmqG+nVUHuDgGwRg X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0744; 25:QsxsTi/0uR/gcipR4+E/yK1BhDS6PWB8K+eN8Cpv1w1Y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RvRzIZggItU6lxNM4koTLsonHQ== 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)(13017025)(13023025)(13015025)(13024025)(13018025)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6096035)(20161123565025)(20161123561025)(20161123559025)(20161123556025)(20161123563025); SRVR:BY2PR0301MB0744; BCL:0; PCL:0; RULEID:(400006); SRVR:BY2PR0301MB0744; X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0744; 4:aF6Yd7pHhXUCHUDXoZ6K2U6Z8bZURF8cewg/w+OtCo1YablB+zla7ZjQmcdRDii8wIyAn4sP+3yFKicku87rEd5Y93nr1/Rm/m/7iBan0DWAsEWP/jjUL3kRIH/I4wAsLLifv6b49l+dPwFJaxfI3YmuYsKRb2vZsmJ1HVOLou1HZGscmB+0YQCw3+WRdlm8lQ+0F9ViFCUoqHO2ZffZk8wyZ6+bEFsA0I5vfLAlfX8hf6ClJ0nQtspBcKaT4HieJGKK/j3CuJYltpJz5hWLL3wPTR1tsqYf7BwQkZxA/MfJ6Nj+mtaVysp3qtwmpq9f3tLU+T8eMMjlMRwI3fWXP7WJP9pZwK+BWj2MuZbUTcUGkMGJDFYVsgVo+CqXbiwd4q4y1bp2lEl4GqXMvPaThZv98FDTmy5zz2+pc7bwlLJFxfR41SiHrJWlPTQBqdDvTqEmAasLT1ajUIn63Kje5RVMfnKApUAOvC3kcYhOrsqj1w5goD5BbuCqi8UXZh67i6KTXJXwxDCOgwqs6OWd/97po4wN8z4c+lZrTmJyfZT6ITwEMx+8HOpLt4F94XJqMZEqVfMa/Ip3dTZu24bVncoAsnOvzVwi6XV4hT6Ek8CeWPnIxND+WgK9oHrM/agN0P65gncrDWjgvhn82oj1Im0pEvnvI4cRDxnwWICyJb8hsKYvP0b56RIiELqqcx8usrfdL3NepxNseKnc2zoCUJ1q66tC0QHGLfIVeW9p6PVLPUUVureeU8wds+z3XEXu X-Forefront-PRVS: 014617085B X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR0301MB0744; 23:DCKqZgM4vfeDBkIu74wPikwCfIRDGE0KQztfHw3?= =?us-ascii?Q?diJR+9TEbcdn5Xu7q+/OJI4lgYngWyh3Qku/3PKyxOtFTIcYQ+30xri6hXNn?= =?us-ascii?Q?TwZ43QJehpxqqf12BVEc3GyvC2zUWhELYGGyEVMe2/eFKjA0vbUn5hF/1CtT?= =?us-ascii?Q?HQ0k9M7gs38a4r9ZKV3S0vukpbcipflOBvlt6PPid8EWJz4KmhN7diN1pgL2?= =?us-ascii?Q?ThUsrreRtox5qY80y7BTR+mEKHxIDgTL8pmLcM5g3j2fa7i/E32BujlMU4UO?= =?us-ascii?Q?fI6Uvq5qLPQLMaEn1SNqEOsTJjtajuKxb2GA7NrVq5dR5kp+4HOuDhuGNT+z?= =?us-ascii?Q?l4xtgOhX+cWbKkJSRogODR06u/N4B+IGqQZXvsPx1Pd8ewvRBofufUV6LsLp?= =?us-ascii?Q?avACE7boAA5E/6hupV8/txH8RLFiG7NlpphQW9tAQW7k6NXmy+ab2TXED8Ik?= =?us-ascii?Q?tCiUHZY6xvYLM+QB1P1rWrFS88vKjaRLjqn6tAZdFcCTKKy1Qy27b+Nf51Zz?= =?us-ascii?Q?oLWrm8fagLOdRxH96S/GVbrt9WKO30qSp55zcecMHkYmkYb2B8N/4xnoBkGi?= =?us-ascii?Q?nNBAsP0vycThjBPwzNb2tG+oxpDCYRJXQkDqnCtDtHR1/34sfa+DLWBLyqjT?= =?us-ascii?Q?YOUkIhY4lgsbOdiZbOWkMft/zKtaPl3NL0xrAeT9XM4O5Ya+LHTT4xOByIGn?= =?us-ascii?Q?u3Gjv62+yScj9OSUbQHB1lahSItHaXLPvwpfYpjfmWTWqztUWP1v99m2poT0?= =?us-ascii?Q?CrpJ4CkBgN3Vn5/U1bkADy+nBrHudM5HcLKWor6nUqC54hvHDuJeA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brnEOT8KZX/j5cdqzx4R6OF4jwfarUEvHSlPP7/3xtpc8QLncco1Lf31qbR98hk36l5pP1CRgtWDtpJ+XZGk6d/XxM5AESVUwX9+e4dlo3FudrDCOWqeJMdLMrZ4sonrjxzqiiN7UCc+yqUWOGjJl7sTY44ucgGyBf; 24:wmg3XXLz+PTmfFpstNhD1arqNjiUJc9CVY8BdEy78qfXLpWq0/BQTBBBslN0vrvFX8AyXaU+KfmvUWgb6ytZwEC7gXX290Sm0hGVJq+WUh4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0744; 7:Ywwtztqa0OdiD7DJmfau8ADEqa2tTCNPgo4yqgNh3mp+y4yL/HXvLHrCI6hpHnipj5ZUqIDYZ/VubZ9IpPbTcqf4C8MmEhdVYG4uLkRAWfW5qZu8r5lx/Neigi9QKq/ZBPkFKEjfddO6dKSNjBbNf/u7yspHOwztu7DG2exoCeS3sEHtQ0zR7MXz2Z+FSjSm7Y0XTPsjmC/KaiNo/AgPRWIBGvDt4EhBTgPp+EloC8e5/Oc0pQ2SxEcmQuAHY45jf1c22/Lnjavl75uf4hLsfpFPMd50yyitgF5bdzC3bx4HAXh8304Ta1xDWm8bIdjxEI31BtWQtmbDLt839k1qTBYhizkRBNAheaKJtjhZ4zGRmNwVAbzvqKQGL0MmSXcjb9NnePdmRkf1pB/C4Ugf88p+3NoMiSfTMPUSpVFmTvhbfP5EUim+gDRy0i9pJQ7gzeVpFILhYIQL+PzG2QB3xg== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2016 10:09:23.2205 (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: BY2PR0301MB0744 Subject: [dpdk-dev] [PATCH 09/13] 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: Sun, 04 Dec 2016 10:09:26 -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_default. Signed-off-by: Shreyansh Jain --- lib/librte_eal/common/eal_common_pci.c | 210 ++++++++++++++++++-------------- lib/librte_eal/common/include/rte_pci.h | 15 +++ 2 files changed, 133 insertions(+), 92 deletions(-) diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 3082b1a..793ac59 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -152,80 +152,115 @@ 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_default(struct rte_pci_driver *pci_drv, + struct rte_pci_device *pci_dev) { - int ret; + int match = 0; const struct rte_pci_id *id_table; - struct rte_driver *driver; - struct rte_device *device; - 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; - driver = &dr->driver; - device = &dev->device; - - /* call the driver probe() function */ - ret = driver->probe(driver, device); - if (ret) - dev->driver = NULL; + match = 1; + break; + } + + return !match; +} + +/* + * 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 ret; + struct rte_driver *driver; + struct rte_device *device; + struct rte_pci_addr *loc; + + if ((dr == NULL) || (dev == NULL)) + return -EINVAL; - return ret; + driver = &dr->driver; + device = &dev->device; + 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; } - /* return positive value if driver doesn't support this device */ - return 1; + + /* The device is not blacklisted; Check if driver supports it */ + ret = rte_eal_pci_match_default(dr, dev); + if (ret) { + /* Match of device and driver failed */ + RTE_LOG(DEBUG, EAL, "Driver (%s) doesn't match the device\n", + driver->name); + 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 = driver->probe(driver, device); + if (ret) { + RTE_LOG(DEBUG, EAL, "Driver (%s) probe failed.\n", + driver->name); + dev->driver = NULL; + } + + return ret; } /* @@ -236,53 +271,44 @@ static int rte_eal_pci_detach_dev(struct rte_pci_driver *dr, struct rte_pci_device *dev) { + int ret; struct rte_driver *driver = NULL; - const struct rte_pci_id *id_table; + struct rte_device *device; + 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++) { + driver = &(dr->driver); + device = &(dev->device); - /* 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; + ret = rte_eal_pci_match_default(dr, dev); + if (ret) { + /* Device and driver don't match */ + return 1; + } - struct rte_pci_addr *loc = &dev->addr; + 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, "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); + RTE_LOG(DEBUG, EAL, " remove driver: %x:%x %s\n", dev->id.vendor_id, + dev->id.device_id, dr->driver.name); - driver = &(dr->driver); - if (driver->remove && (driver->remove(&(dev->device)) < 0)) - return -1; /* negative value is an error */ + driver = &(dr->driver); + if (driver->remove && (driver->remove(device) < 0)) + return -1; /* negative value is an error */ - /* clear driver structure */ - dev->driver = NULL; + /* 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); + 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; - } - - /* return positive value if driver doesn't support this device */ - return 1; + return 0; } /* diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 9ce8847..eb9ef7d 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_default(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