From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0069.outbound.protection.outlook.com [104.47.41.69]) by dpdk.org (Postfix) with ESMTP id 119B46A94 for ; Fri, 16 Dec 2016 14:09:18 +0100 (CET) Received: from CY1PR03CA0016.namprd03.prod.outlook.com (10.174.128.26) by BN6PR03MB2466.namprd03.prod.outlook.com (10.168.223.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.789.14; Fri, 16 Dec 2016 13:09:15 +0000 Received: from BN1AFFO11FD041.protection.gbl (2a01:111:f400:7c10::141) by CY1PR03CA0016.outlook.office365.com (2603:10b6:600::26) 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; Fri, 16 Dec 2016 13:09:15 +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 BN1AFFO11FD041.mail.protection.outlook.com (10.58.52.252) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.771.7 via Frontend Transport; Fri, 16 Dec 2016 13:09:14 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:; UpperCasedChecksum:; SizeAsReceived:801; 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 uBGD8BtJ028345; Fri, 16 Dec 2016 06:09:11 -0700 From: Shreyansh Jain To: , CC: , , , Shreyansh Jain Date: Fri, 16 Dec 2016 18:40:49 +0530 Message-ID: <1481893853-31790-9-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481893853-31790-1-git-send-email-shreyansh.jain@nxp.com> References: <1481636232-2300-1-git-send-email-shreyansh.jain@nxp.com> <1481893853-31790-1-git-send-email-shreyansh.jain@nxp.com> X-IncomingHeaderCount: 10 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131263673548078811; (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)(7916002)(336005)(39410400002)(39380400002)(39840400002)(39400400002)(39860400002)(39850400002)(39450400003)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(5001770100001)(8936002)(76176999)(189998001)(86362001)(38730400001)(50986999)(68736007)(5003940100001)(77096006)(50226002)(33646002)(50466002)(104016004)(97736004)(48376002)(356003)(47776003)(6666003)(2950100002)(8666005)(626004)(36756003)(5660300001)(92566002)(305945005)(85426001)(81156014)(81166006)(8676002)(4326007)(106466001)(2906002)(105606002)(7059030)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR03MB2466; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD041; 1:yYjDyQboHf5fDh2Y1sK3T5GfAi291sKIakBSQ2kTC81hFpfOlcKAUwtAmHH0sPb3htRCYBX8MBEZqdl42N3xtCueaKgMATu76SEZlzrh6Y9cBG1MGe4kXwOqGXuwduX0tbDLASrV9h3rg5lj/rnH+gzq2KM+5rkrOCcvArJ8Oj8GUKYC03baXnRrcHAMbFOv3qQLwP0sbdATJOTb8XPM8E6Xf1+ZOmBFRiOWAP0shuE4Vqpgm+oCHDQgCk9YOQWYbDfgJvP9J/Fpwq/mHQcyxQhmYWD3uTDvEHl813yLgMMdEBKgCJhTBEmVXhJsSvGFz651kHQU0F36lhNehrq/EubnTY9Q5OjuHgbLr9vuvI5iSEDGHR4Sa9bIJ3V0blMdU8vJegWq2QZ4NYNWHgmuS5lEViM2SndohrN3/onsH8ongg6Fie8wtfAZGOlqO2shxHYB9Sw6JFoOKGZsZ4CXpUAE5cgy3mUU/7Gy/4nZgu1nn1c6F04j4noxfBpUUKl748mGKaSTUihtzOGv09u9kBEUFZwccEGs6j/AXEoQVgn17JshscTV3kqA7EbC+IUcjG8Q9xzgqw6aj6xQeFYvte+hv8XGL7X/tvFyqMUqJY0G5jy365lEVm0y8OEckLbhfSDAABFUPyvap3Gum5Ot7OO2p2jFuS3lG3sSJqACsyHIPtKTGNo8ZYxyVaGszwrurF6HdR03NF8QUIAAgpmBSv11K5JJprAIFjA0X6jpi9hoEmMsDeh0daEc+0c9s+qo8ovBBTX1iqoofnsERvJwQw== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 07a42226-6123-4a35-f3db-08d425b4bc22 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:BN6PR03MB2466; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2466; 3:s/O5sMmqO5oCTDbjeca+ziYETToQL9XixqO37pb3U5N7tt26eW1pMGZnkeX40C3RdycyQoT9U3iNd8tB9AOBYb2bueePKTcTaZcstd7x3YltpolKDHAaB6Zp42kDW9afVTEf/rIOhtEXVGuJBk+FmD/OrhWuN4idB1CLF1pSzesDfHoTrbFfpHscsTAepPdOZCLHmwZUNqjYsXAnv4osAnIt4hG+5DB63lmUh3d9MjAiahdoiWpcfGPmLp31sGZOiNoegCmElkYGuUzpv8JqhPXWkiu5rwmg4od4THi8ix10rdHd7hXhqzl6Q70rI0yhfLmaBZKpWTSrRF37SY6ne0oyBjKyQCqdyZbSb1XG+86iVmHiwj0QmV06Jl/1XZD+; 25:jUnw9fm/akcveOyiLrJImmH+euriNKBdKPjeuLKjBEq82UaNnxbMDf4EkTPM9zuIdQilyrlbDmKCqML/zzv/dG+UoVs5blh16AOjY+B+BM+U5MeiVInKBfryNS9g8sRijKYDtgCEjRYFiuCtTUU9slbTiR/+2TS1KuJzQcGl90t4EkTLyFWd4Y/45JZY7Tapubqhxnyin+ptN3EhQxwor6OA9BUQOA2oy043dy3BfisTj54ySvQBZTKL0bvlcFs31vawcD5ejCyTfqGUWxpm/kzBEFmlUiMucrVDe4jcXTN4Z86cvzWPI0Z1KGOfTxZTuJ4EA5cx2VFBDOGyIt2/ICV1+ZRA8Fj8i6gbZtFt299UanxpZ1SaC/aS6a7ldnoMT/aS3xihBzRCy7wvYdfV0yDKxdvSo5RIT4hyY3QuIt1/m7xQd00VgFHJyApoBP3SMzJq5EuaPJMd7f35XaCFOA== X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2466; 31:gV9qlOiLB64Mw9Q4yC9AE430KP82hMZcqf/dL/5Za62p4clOSkM/4exjeLmwd1djfq5H50Vbu4/ik4OU1yIYAM/rVQ8pE1ZZvy4uybqaPIka0BReuDV7d3WfbbL52s2udmyiP38oYki7ndO/7vRpVexoFZeVyRMtT5/NtxlSScNL9/DF4V0Lxqj+8ywvBUX46u+/oQ/O12HJoQgOMV/FDcsql588BVvkdEGyfaBJm6FvjxKRr26AsjxA/73TyT4wgusq3SW6aQea90IUtmfG2db9xgGsjXXtwBntaMWEY/Y= 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)(13024025)(13023025)(13017025)(5005006)(8121501046)(13018025)(10201501046)(3002001)(6055026)(6096035)(20161123561025)(20161123559025)(20161123556025)(20161123563025)(20161123565025); SRVR:BN6PR03MB2466; BCL:0; PCL:0; RULEID:(400006); SRVR:BN6PR03MB2466; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2466;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HoycFD4F40OtqQSOrMwXHaj/FIsQr4xCebLAg7ojiOM?= =?us-ascii?Q?PHBkocUNmsi2piB3UJev+q1C4tDPYxiYTVed5HQC9VYI+TdaTaTQfVS1accZ?= =?us-ascii?Q?GA6y0bbn4cZWHXosnq98HPv2Zj1/NSTMp7cJJRxJWWHc+IHt9SxhUJ5w99Vs?= =?us-ascii?Q?BStaEhND71Wmo+SbIfZo9uetDntt5fmxXxJqHLB?= X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2466; 6:vRISnxyTrPu0d4lhmRJFP1//FWVFz8b4oSItYu7RaSuIFysWTD1lYd1EfD2euaP8Ni4V3dp+5xqR3qO3HlGyCVa7IUXTWHoN3PYTZO1OlRIuB11vAAlRw80Eqo4wjfVZpXo2X2pVetboZUJwqLzEyHYllCfYWX76dDSFzpPn66Wg0o0//9MmTA9DOr5VrbDBFyW/cQC3Tk4itNxb6127wEC1RTzA2wAVRz0zrH6hRuy80922bF19ypN105ht2EbxO/p8CHlZcPGi6/Rhref337mtJFtEVJqe/TXGlwgi/Y7mfTOx4GGb6/IPncWbCL5fA+5unBgk0LCZiPcCmZbuyJDtwKp67VU1YdYUVkLdNZMcwJ/StEjDhP5+xaJHUv2O+/zona5q3xlfMA6E2IC9HEdbYEXsiEAAyTC1nO8xn0KX6kG+stpl2+Y9wZk5jCRX; 5:ZNP8vDixr72Tl4ZSjhIm3LZMOq1gR8rsNxc3VuPtXdR7k9zab3b9f0iP7ys1ec4R5G3L620+RbDMbGA4zfEI691nC0bv5S5ULgK4UiypCza+SCLv86wVU4xTaXJ925EUo8+XwsK+19Ku0HvUqATpWytB87GsSSfGaI2qkUnAn7iTVGV8CWBZKveKwLWSbcCo; 24:TWnYwdxiL061MXjIaeBNXB4pfAlsEgImaLdnu8yZ9QgDOqFW5eZTp6U99B16/6/ZZqp2BUMlhkewMxgprKtfaXz82TQTiMyjZyecXUYrkQo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2466; 7:dm5ZRSnUk4lBADRYXFltiDyjZDqNkXFuvq1PY3zvz0yvcY4bY05iI3XFRivrIHQvRmny9a4Flb+bmNmlTmKJ0SXGRLrmyxQcbWJtWkecLNa1kox1RSvvRbLxWWbQChQ4h7PMeZ9ZbWeLMt1HuYwqKIKU74vNN5UQQia2vViKd9Lob38YWqF1OPIsU3fvZuKbBbpqGfOvKj1MTImn6unmF/d+yTX9s5r6gK6ZpCu2yyBy97hdEg8zaq5yw/KOOn6mpP5NFSSkgZ2bKfLWuuqUUaIpNiBTxciC02TzCBSGMzlc1PnAP1Z7D5o8tMy9cqrHKYR+vLdqUFiXqnhbdqiX8/oFaSaD/XXZzVddEmifoWYvvYGM2LiVz+HWkTAYMixfgT5DM+Skx0ilZav8K3bauHtM9ic/6UIeCfN2Bm1vA8LwIpsxJgHnThHRrU4Lyf0DybjWtgOplOqrH1ut03NN8g== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Dec 2016 13:09:14.5114 (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: BN6PR03MB2466 Subject: [dpdk-dev] [PATCH v3 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: Fri, 16 Dec 2016 13:09:18 -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 --- 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