From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0068.outbound.protection.outlook.com [104.47.32.68]) by dpdk.org (Postfix) with ESMTP id EE03958CF for ; Mon, 26 Dec 2016 13:50:55 +0100 (CET) Received: from BN3PR0301CA0050.namprd03.prod.outlook.com (10.160.152.146) by DM5PR03MB2475.namprd03.prod.outlook.com (10.168.233.21) 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:50:53 +0000 Received: from BY2FFO11FD017.protection.gbl (2a01:111:f400:7c0c::105) by BN3PR0301CA0050.outlook.office365.com (2a01:111:e400:401e::18) 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:50:53 +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 BY2FFO11FD017.mail.protection.outlook.com (10.1.14.105) 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:50:52 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id uBQCl90P011201; Mon, 26 Dec 2016 05:50:49 -0700 From: Shreyansh Jain To: CC: , , Shreyansh Jain Date: Mon, 26 Dec 2016 18:20:39 +0530 Message-ID: <1482756644-13726-8-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: 131272302528301900; (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)(39450400003)(39410400002)(39840400002)(39860400002)(39400400002)(39850400002)(39380400002)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(5003940100001)(85426001)(104016004)(92566002)(2351001)(38730400001)(110136003)(50466002)(36756003)(77096006)(6666003)(2950100002)(6916009)(189998001)(76176999)(50986999)(305945005)(48376002)(356003)(105606002)(33646002)(8656002)(106466001)(81166006)(2906002)(69596002)(81156014)(626004)(97736004)(8676002)(8936002)(4326007)(47776003)(5660300001)(68736007)(86362001)(50226002)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR03MB2475; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD017; 1:H8YlPjNjNyxwErv+g7V6n974MfJPQV9i+Vxj5saJIx3nyQzFUqjJrhwihG5OxOzisCuN7fDrJg3vgF+jY9F2rE3OsUN99FH7E94kCMFGt32KX7x5VUF1AoQl7fakRtmrQBmHLrTnuI02uP1qVUxhIaj8CzhWu7EYGluBFXaM8rmb3Mdkr/INhnIFF9iayPO00VAgEts6o3PoDwzxnGdoUJJw9G7KKE9IKtUBEa8YGvTsrkVko87Zau0pD3Z6MM9vRuRfAXZaWBmIlaoLoq7rnc+4E58ETN2zAsAhrrQrfDNGg3GWLZVbVCPFiJtIvMRAPAKeCX4/w1UVR5HM8M8SQ/JHXu9yFMk4kEaoLPrIIKgjGnzguSgFM6QmFoYbyslgBPYk6SIMxls1Od6VJqZURzvyX8qBT/Cq7tnaXW9/fHO/u+Oap/50AbeRzNC0g+2+89hfUq9NSAsWgKKOhCJx5hCP8xdHYOZJJ6UrrCSbVDAfwbzl01P7OR7DR+ItQSr9ZZ63GYEcEASdb9Ms65GBA3ANyKs9xKb9CS1+8fgUyJW+se2R0YoDqh3HdGEY2ZXlTI87wWXqbYUM/t0hfPFz1W1WzuiAYonBDJDzCnh6xqe7bVAWxOVWBB2697LqlOLlLuGq/EBvnLHwcp/KaC3SXV/N6kJtG3DgaXdi0rSu+U4EWdLXI9Oeb4Q24i2AR7AyLM2qvcf57HYmRIiF5nVxwT3yQIOFRxcHGONRDDH61ZY= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 6bee1e49-03ba-4484-9ee3-08d42d8dd36d X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:DM5PR03MB2475; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2475; 3:z++LTeqqpCyfpX++HEgiELtcbkZPnyL75F9vzloUE5K8TIMhCQ0/JaXra7OUEU27k9uP+IDhcydb8yQwCO59A75KiOEp1sz2QZYXQS6BQnAZiSvgiJ5qSfvjMiAwr4dMg9ff62SaFdH/FG0FmSkfHijoE64N11o60qdzXwgaPqgTXzQ0oGKZpAdAKM5LGXMrqQ0+iY0+ZR587p0fOn9zWM89EKxT7BFAlO7KRFRHfpOw9Nr5txLe1E8wpNWw4n7+I6slM9ui9pzB9xwvVWbtRdV6db5mzniLF9a+h7553wYajds+bLe8hECTwJoGv/HQcAYyoJVH/rmKYKT74jtMPrGMckvzGsxMkSEOXFD7XVg=; 25:Kfd8q0hfyeHkVj+FUlndRZcb8mKjU0L4TdHsvfj71H6GTUvCHUHXPBinYDSme3NolCplxAgHNavINQ1ASMRn6TGZkleV0ZELLpmxNJYOq+Iim7Rj0ZcT7+E/LMv4CLYcU0GZOmKtwx4d7qG8ETn5VMYjmh5Z9DHUes1xZDlFb0G7DMwAUF7lEN6VEggLB3FoPcn77TMd90veo3bnS8FfLh1TK+BxEvr2H2SKTqL4V9PZVqtu/nBflvdMAL3LQ1C6PaS9MPcolG9gj6pklgMdKj18LatEwXrZ3vJGl3IP6Uo2UutwXvourHesQBjgkSC+TgdruNb3FzVyOHI+ZThAp2yiltRQ/p41Ol08MjdMhCUcJus7KCrjgcvFUaGU2GUFYXCPhsNIWmAK0YtDq0uKmrI8zQnOwjAEV8Ov5hXjx8T/OnkpWg4x87Zlfl9x2l88JJPKHHMUTvU6DjGKLCrOEw== X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2475; 31:IbEum4e6BFbxH2Qt7JA1YyFfsjIQkXfSeF0eJmNDc3TV8Z1b9yXLhn+ksC9xg5vJtJLgNLLjOAiFPJWWQmyj5o9Gr8hytzMWf2qWrKMCkD8ujAFjj1Hc0ZptMJfnOwunPaKaonnklDrOT1GIG+JX9JKTLVS+mri1qY4mz/nwwEEl4tBW4O1P1vUXEeErsjSNHAtG8vJlRRb1xZzGXeNHof3cKCEYHzwuHmoXItHd+UrZNBkTvThqCVWVlsTKbEq15dV1QB4tJ+6ih6Rb7ClIWQ== 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:DM5PR03MB2475; BCL:0; PCL:0; RULEID:(400006); SRVR:DM5PR03MB2475; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2475; 4:tDDLoGl51jSu+TaPoQoOdfJ0OqtRj39U5xdRjKqR+UlzqIisc7aMxRhMIWqmFx/KaZ0T3wtHL+NnkB/kUBBcKEK1os1l/QwgqUhT0IU3saR6YWU1HdklQI+o3JQG69gRFia43RjX6EtPuKlSlK7UPCvCnmbR9+S5gnkZfjyZtNiWv/KeNphMvz4PFEmKQfp10OYctBI5dyDishen9QpbFewlNA0RKpldZujrAz7vFrmm8Ciu+xSYCZdgL23C22BGfB9Lc2mGC0D5A/oV8b6k+P8r+moWTWzZxG04UdH1Ex62r+gks5hR/Y2SjLovgx8HJlONS073Y6HfbD5NZTt1XLiqTr72Li4urN+3NkCvwCi/t+/QsxMp6NiHb/fO8I9M4l0RmrY72YjuY75Vi59ZvC71AyQQXccCjqbISAO0o+cSpyFwyVX7dRb5Lw3cnxk31znn2qeXqZ90ckBxehXuoFdb3YXjOT/jOkCn23Mb2aC+Rfhl9mjfd1NowKboKbNUYVWINMFGe/IBKTvOou+9JIErILrXidtdmM+3P+MOxMK7+AC7Lbg1znvrPY0xfWlqSCGTg2s/0DcOunAR9kG7zW9tgAUGp7uFVVa/UgajSHVeO2whCinxfRwS1wl2eTH3qT/etdjtC0D8lsUXTeQNRhS7nn5n3TojerKKsLTl62UuPdPYneRzrMPwraqsvJUpifRPIYC3p5KKJ8VCOAZM9c4i53OUhiBxfqdJeW4hKd2HjZOImRaY0OHt5PZ7ucuN X-Forefront-PRVS: 016885DD9B X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR03MB2475; 23:+mGSmzL3CxMM30JFnymJIYZmfjbtUANRUb/saiYhB?= =?us-ascii?Q?OtW1KV/8llBXgbkPFjk4K9P7qjijhfaQUas3FbiRBByBqwoT/dpH2T+T1+Q3?= =?us-ascii?Q?y6cqCcWDYks9wZyFYtu1HsuvO0p4iA67wy8tTRwzSg1KDuylqvAS1zTDLCLq?= =?us-ascii?Q?o9XngdBW4Simh0NkpYfYBcs92idNVcaARiC6FgijBzOxbZErU5Ak2esy4uUK?= =?us-ascii?Q?8dhSSpOh9/+29IZRjNn8iU1plg77mZZkhMW6nnHCoSw5KK015WvqjxFauX6Z?= =?us-ascii?Q?C5MvCzR9bfp6EInv4Whzq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a87k8/LgCkUAy9RIz/PCXMweCGEU5v1BDQQID6nBOCAieir1h1picGDf6ecSRt7FQZaNSddvNVUAnIEXy7kIbkQs1+ZndoMYTXbWeZlJ2Pgmc35dSN2OWFORgs2/zU5AsWhBAA5Llj0KSRwK53rABYg3t3oV86dY4MMR9TpA0Brk4jECvcPI+jrjVoKudhcKGluZnANziZ+ybpzzEoO+02/cf652liNGf3n+ek8g36jFPTOyayaHpExtTB9vV/A4rRKi+6GIzx1WbX7ATNMBweVbR9Ih/tG7EleHwa4Vu1GjeRd5IRLVoWuSCSxHLmG6BfgpgdUdK8cBD9T9fBNuN4jGCFcAS1AzyeFBaRlydGdrztyORRP8Hc+aOfBS5tvUcAQ1Ru9VrAilMGPUjyp4qzvkips9nTOU4A0kgAiE3pD113wUUZmTyAmiSfCl4RgBgqj3gsQ== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2016 12:50:52.3621 (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: DM5PR03MB2475 Subject: [dpdk-dev] [PATCH v4 07/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: Mon, 26 Dec 2016 12:50:56 -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 | 176 ++++++++++++++++++-------------- lib/librte_eal/common/include/rte_pci.h | 15 +++ 2 files changed, 114 insertions(+), 77 deletions(-) diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 33485bc..f466448 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -152,71 +152,106 @@ 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; + match = 0; + break; + } - 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); + return match; +} - /* 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; - } +/* + * 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_pci_addr *loc; - RTE_LOG(INFO, EAL, " probe driver: %x:%x %s\n", dev->id.vendor_id, - dev->id.device_id, dr->driver.name); + if ((dr == NULL) || (dev == NULL)) + return -EINVAL; - 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; - } + loc = &dev->addr; - /* reference driver structure */ - dev->driver = dr; + 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); - /* call the driver probe() function */ - ret = dr->probe(dr, dev); - if (ret) - dev->driver = NULL; + /* 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 ret; + /* 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; } - /* return positive value if driver doesn't support this device */ - 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; + } + + /* reference driver structure */ + dev->driver = dr; + + /* 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; + } + + return ret; } /* @@ -227,51 +262,38 @@ static int rte_eal_pci_detach_dev(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++) { - - /* 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; - - struct rte_pci_addr *loc = &dev->addr; + ret = rte_eal_pci_match(dr, dev); + if (ret) { + /* Device and driver don't match */ + 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); + loc = &dev->addr; - 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, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", + loc->domain, loc->bus, loc->devid, + loc->function, dev->device.numa_node); - if (dr->remove && (dr->remove(dev) < 0)) - return -1; /* negative value is an error */ + RTE_LOG(DEBUG, EAL, " remove driver: %x:%x %s\n", dev->id.vendor_id, + dev->id.device_id, dr->driver.name); - /* clear driver structure */ - dev->driver = NULL; + if (dr->remove && (dr->remove(dev) < 0)) + return -1; /* negative value is an error */ - if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) - /* unmap resources for devices that use igb_uio */ - rte_eal_pci_unmap_device(dev); + /* clear driver structure */ + dev->driver = NULL; - return 0; - } + if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) + /* unmap resources for devices that use igb_uio */ + rte_eal_pci_unmap_device(dev); - /* 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 87cad59..34ff3d1 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -373,6 +373,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