From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0071.outbound.protection.outlook.com [104.47.33.71]) by dpdk.org (Postfix) with ESMTP id A948D4CE4 for ; Fri, 16 Dec 2016 14:09:32 +0100 (CET) Received: from BY2PR03CA046.namprd03.prod.outlook.com (10.141.249.19) by BN1PR0301MB0739.namprd03.prod.outlook.com (10.160.78.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.771.8; Fri, 16 Dec 2016 13:09:28 +0000 Received: from BN1AFFO11FD009.protection.gbl (2a01:111:f400:7c10::180) by BY2PR03CA046.outlook.office365.com (2a01:111:e400:2c5d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.789.14 via Frontend Transport; Fri, 16 Dec 2016 13:09:27 +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 BN1AFFO11FD009.mail.protection.outlook.com (10.58.52.69) 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:24 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:; UpperCasedChecksum:; SizeAsReceived:809; 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 uBGD8BtM028345; Fri, 16 Dec 2016 06:09:20 -0700 From: Shreyansh Jain To: , CC: , , , Shreyansh Jain Date: Fri, 16 Dec 2016 18:40:52 +0530 Message-ID: <1481893853-31790-12-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: 131263673663829262; (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)(39380400002)(39840400002)(39410400002)(39450400003)(39860400002)(39850400002)(39400400002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(50466002)(50226002)(356003)(48376002)(8936002)(81166006)(8676002)(81156014)(38730400001)(77096006)(575784001)(86362001)(85426001)(33646002)(2906002)(4326007)(68736007)(305945005)(189998001)(626004)(105606002)(5660300001)(5003940100001)(76176999)(50986999)(6666003)(2950100002)(5001770100001)(97736004)(106466001)(47776003)(104016004)(36756003)(92566002)(8666005)(7059030)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BN1PR0301MB0739; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD009; 1:Z3cFKacmIXooFVUbmEaNO9wbyzDO+mjvwmFPoTfe5OSqbQk5BDapAleYgwX2dkXRB8MlRzyiW4sWg6bI/buRjGsEB6lQI4S8K5gzovxgDKxX0zo7MnSAQEIrueeeg+OoszmZThed0iEtjFEkCwE/m38UGgL87wFxcGP1s1aE/EC9Khb0A3O61/+yWhxoG24LnitMdahXwZagL5DBoBQLEMcMfNz88x30FOz2Uoz8vtdWcF3QwQPMEBjiQ0TTbLMYEt7rWZpiesztwzPU1xJPj+q7KtLQi7LHwEzIHUczNgySDmUdm1NFHQ9IpVfMwp3JBnt1f9XIDCoO3qURMQlrHZtfNweIyDyYaDWgixIk4Eg8wLjfVyKvuNCT9u7MekC942F8/bsfYhZ38NGkh52Em0SZ9Fsj7/m0pwlJH9b19lfg1nFOJ5cFsQDvUsqVCQkTLOJVYPHh8yELxhqEpPFDI+mDACm4Uzb7Lgz5+Ijh7FAOtuBDkoFoI2muIwi5/ZX/ltrFC1rQ408erRIA7ph2yd7u/CoV1vHJIk2Xe6hoCqipDBQmJfcSVGLzwArCtI/o9Ck4trG9rswaQKm8JHOIBC0hyamHS+LEOI+P4iycYEaj5P0b+DWALHXDSKPocyCgAweIk6IIbLWBUPNCXwkQy6J8yguGDawUc9LYqz7ck3+sSSbpvORZTCYpAnmcM6x9w4hXdOGbELLOgYWC0cuMT+06q+IlGkNawkdlrg0Yg/x+i4Zz/PBabt9f9SdyYHLqIWigZZbQqHyyB59aOqu/ng== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 6d47c16c-70e9-4f75-d3af-08d425b4c319 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BN1PR0301MB0739; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0739; 3:gshGMHxmsdaeqPLawU3BsWzXwnPutxHI/KMGvdVhfZEwQV5XbGRoESgG49lbFpezU4L2lnZow65stWWo7FrldqCpocoExHXh1vo+/QDbDWFGTdid3gQ6bK42hXvzbWOADsLNKWqg0hAupRyiKMut1IrdBNKYyOKRwv77pBKijW93V21Wd1gL81A3EyaR8ZQwwBr1gHjLE4e3jB9CH6zPpBahKWLoxl++Ry8+T+uca5aavQ6g4hdhGZcckizdsr2msdE0PcwPGkBRXF0XEYAM6p1nsKVDfEZuFrp3qS7kPQcMoc6Zw3NrDogc9sKKljYGnewzo0hOWsgazg/OmD88v2bvHnn51x1SkSjQOKgmhi7k8b/fFpUTeFxWKk4HOHVc X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0739; 25:+0dzhwkU81dl+F7sl10ixGjBXa7YuIsSUDdlHohe9TxMr5COeP6bOstBJ9t8OQ7r0BRAMReFwmup6fAFXZsD372eKsKM6PfAlxzj4sVGbenLvw0lU30qs+8iv8jJiaSvBfbCG9c+zGnR4lJ936q6B7O9zsapKBpN4BRC33YHvgyDflFRhgIfF0T2dHE33fxotMPZ9pkjWNOFxfImmJrioMJhiZmUW3KDc/P5MpyADSwzrDD1hM1Hz5ohRqOAH0Q4MYr0fmvXc4clKSL6ik8RwjN6G4is0Prn0fyZ0VGb6sdhaDWu2DJfx6zsCeyL3PO7fg8yUuBt4MJiygCkKy3vQtybh9+Ij3PUmb4kgLFQva8cY10cItCzP/AbK6ysubPUrVk3soPVlc1R5mmceWroO7UY/5/YcP/FtgzVRa7huji4VtO0TLFsnRv8PVET9h3QuDpgOlDrFYx7jDTnlko62dA1PXUpUSX9r3B28urgt3x0KxJC5ylvPD4FkNS2YHw6N1ipDdaOT4IHWZuTnhXiIzGWhnY9L0rUgPW1MprapDms98LJt9PjtIWLPUFwfMXxxebNSKX5Y0gaR310pj/84qf/GA5sM8pu0/bb+lXTSHvFyRn379yKjJEANLAzCDaS/YejTeS4Ga05iLHuNo44TkkKwLlncUt6U7u4DcNGPxfp/Hw3V7dzAsvgCmUcCbCoUXSbcJZ2rNtuR9ug+FOTQU9G/OQw5wOn9Ve1K/Iv74HghreXmspgy8d38ziEvtLnKDaavNG5Zx2//i2swywEg7Cng2FYoWljPK7ttG02ukU= X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0739; 31:ZOBA6/+VXW/WZYZRM8ygPCVYsO2VaGMIlwYusbDKk2cCo0zqK1Fuoiyrf9L0ToQYXJSJTLJgU3nym9zX4XoT4fqtQOSGisyuWFy/J+QH2YWBdVqkD+CN9LkWchSVYxy5Je1MfXQfVgcvg5ecbIMNQsEKHxExBiSY+vn80RiVUj4kAFSIbQI2jf4uSuXNY+vFlpzALzZMwexoNM5C6qVR1cEtApAP0ZXah6u4xzyOwbUnXPKQnEmQBeaC8qQ0Xx5ZLnft/BAFXsZFdDtc2ZeORahXGDf9kMq+tdRJvnmEkBw= 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)(13015025)(13023025)(13018025)(5005006)(13024025)(8121501046)(10201501046)(3002001)(6055026)(6096035)(20161123561025)(20161123565025)(20161123556025)(20161123559025)(20161123563025); SRVR:BN1PR0301MB0739; BCL:0; PCL:0; RULEID:(400006); SRVR:BN1PR0301MB0739; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0739; 4:NsELwQNegyBWOfBlh3GnUsiBh2pQjFV5PEIlwmF8+CvH9JzilGYdN3I97YFYP5P8TAqZgoZNv+O+02n/PsszrvOtupPzJ5OCSWpvaH+BbqdPT2gtJz9Jl6guwy3u4a5hmjou8nIAqkFFL8N64ZUDJeL5xmFnhCDCCBOLGTiF2vzoYZsEzNSQS+MCLpudgxkRbxdIo0+e71MV4fyiaHUNIPFbSNGc4alYOe3sacNhSM7cklT8QAuCoiUTMpLiMJnsYYAezf+4CBpXxY+g86nTLCFiRCMwdx1B5L1nX/uYDl9eNWGOsWctyZWySna5esh8vkzgGfC7dC9LCItVFTOYHegvSe/BgFA8G5MDAxpFD8ohlz/+jhsVqI8n2GJid44bX2tafERwX9vPM3msWaZHQ418usRqBVsT23QCSfSUC8StquQ8TK04biwX8Or92zg72cbYqNPHJLTm8/hKDKMjeAOp1KOrpwOeRlp80tvlCipF7PucJDg1lc+uwbgRUDyMJ7fHeqdLnTXcMMknfShW0crJwIsELG3M+bxPw4OKxNO/ll61ZokuJeySsa3jIBZmS+qEXUlZCl/7pclZC8VOu7MQTtO5NOtfhXp0Exca110GG9hGTWZPo2pAo7n1lEsj8UszDzwrBCcXHAcB/TdLvEs43z6lH2xV8AWUU7Qs+g9YrOOBtLOrChyIsBPePWKenEFNZzDUmT71DoVmxhezgze8P9y6Xxn2HO6veQVCb423CvBYR6oEUUtzSh7W2YrG X-Forefront-PRVS: 01583E185C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN1PR0301MB0739; 23:P7fhFpxwg5bNJeKnTa0dbH4RfIMPAh9xTIiAebb?= =?us-ascii?Q?Bm0fLw4DMgypEOItB5Ee036nnpRPK+zHUG4G19wMmDnRSyp6O80B1/rc00CH?= =?us-ascii?Q?R5WGo1jux0mT0CNvKoHdAysjHGcjWRolz3iGPadCgNT+JGGaHc2UsgiZkkvw?= =?us-ascii?Q?Z2mL0nFvq2B95waRmVgStsXX2dU9a77LxxN8JsO/oLlrbA+wDoquMiSA2c3F?= =?us-ascii?Q?PPbtqb2z5Zr0eACSYhssPaWze2jjGmRMKJYuHwrqwhg+VUUGG2qnhEuxaRT3?= =?us-ascii?Q?o/bBVKN8l7qrGtYgpB9GtwFbgkh0JG+fwjk391WYB0ADJaZw6MjcAvYkfqyX?= =?us-ascii?Q?PAmJ9CoYC709nCfgcJRQ+38RsrUobTp/tO6x5OQtlfn0x7vQOEUiC0UglUGU?= =?us-ascii?Q?3NrBN4QTlZT6/W0B/WkXur6lkYFDIOYmDn39eBUbKmMeDX68ZGNp4M6LFdWc?= =?us-ascii?Q?6XfI+dxP8+b0T6jhRgS5Zb4D788tcs/oHA/R1tWG6PcZQ8eI+SsRoJIIt1T1?= =?us-ascii?Q?nSEfWZ+GzWIy2Cs0LN59JI4INNQ4tvm6XjTXbnQH+FQzpwXF/bQb7bSjGe8X?= =?us-ascii?Q?+sKo5uCzibMims3XwebQuxZoqGMDlianzkKrtKvLQVqKmy2ArWl7xxHMdCkz?= =?us-ascii?Q?lp6tkZgHkikuD2ucfgX7kpmNIlPmgufRj0Y0myYZaGNAR/fUf1HcMzrHaHEd?= =?us-ascii?Q?tHgFA2JJD3o6OjFX/wrPhmVD4SFzR7Dl8JAZpuGAvuHQI+b52UReNHRAyn+p?= =?us-ascii?Q?l8+3gyZ9qouAtZtoKSgXM4vYpZPRpCSit7TBdBBjpGRp5vdmG1DEU//YS/O0?= =?us-ascii?Q?ZFvZLK1SBfd3gj+/oaE1o2sDfJERiyOT51TZFTNcC+ReMUz3subr3uQEwcdi?= =?us-ascii?Q?a8Nuy/OjoTGPp1IM6Hqk7Ol9zQcPPchiNUxnJGnxGNs4XsNSgai89nJKUOv+?= =?us-ascii?Q?HWgBoyXNynYoDt2g2ObtSkPPQq/+VFNJ7ta9NNo5xsE9aerMdmPc2mZYq8IB?= =?us-ascii?Q?mQj90sJXHex8ch5KhNl5MMnFD5F6Isg39haG0I5vJ8KdFWca82RD/Q2/1A2o?= =?us-ascii?Q?AHqYd07X1t32uSuymKTxSNY/sBP8jP9Al3z+S8m7Vo+PH5gqUHKuINZjSvyz?= =?us-ascii?Q?pMmgeDfH5+MDYcU04CZkqptGLQT6dSpOfnzPyH2i83BocL7+7PTx4ylcpk67?= =?us-ascii?Q?l3BiVJEDZOpvbfIfLF+oq8Sd5UlatltssA9BoWCnPTNiyJe5y/Vt1a61KVBi?= =?us-ascii?Q?5CqNBjvs8TSCvcQUepybR+tb8yOLkEP4frpLjyUxD0GFyRNSUUxtzPf7dtIv?= =?us-ascii?Q?R+A=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0739; 6:D8sZ8UPEYVLdlrgfRG8ITik1gvH46YmJ3DqDc26NoS366EqXvuNXgEVXTOxw60iBCHgj3EkiUU6YnU8rDtjV2Sljr1gYhgCS0FDN+OcvaHCwyMbPO6Oyg1q/URU+yoZ5VjEZhYae9Yd76BYpKcr6Bd5fl2ARX+W3NMcmHprFVuTA1AirTYcrWzSvvI+eSQJZYv5tCJr8s0KDnkQZ23k8ZWvSXqseSYlVUNOa/z0A5Dix0Sp4MzXxIQ+sSjBr1TEEuvH/E1GC6RqlgOmua5iIl9OcqgshYDpvc0/rxtq7DT35V46L9B5t9KYJAYFq08y0kT/N09r9jXoY53R2RKEoiG4kgRpA+e0YXB6dS4SEbFtTOLI4sZS7K7qJjy8UwYxod2JXQo0uhkjntYzacXngbJpCX5b7brBltiWpW/btJPsY9h0KWH84bMJ1p7XUmq0M; 5:UiPk3tBf5ZWS7643nEVqX7fZoJmhK3f+1p3ppKLGM8rMlPR6tapGdiZU2sFez41em5rMVNTDklR2i3pHiZM+kX1nafWkg633aanP4I+yCicWm6cfXwK7Oiv//sbFoQ8SpZWQZOMAEWtcT3bgvyyaLwtqBJ1eCWv/tagyzm5aGcqSVGFuKHOZNWLubbM8SoTF; 24:c8Cp5VkJizqvLOKbfvmIQUBlLvKqOEfFTE5EhoMKKRrJOYAo1bncAF2pnAywPVjzUnPpXsEooikstrQ16+a21dtPISeIPZ1C9r1Qmbix27k= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0739; 7:+aGsmOLWSIujS9B5hXC3IB+nCTKh7xXjGYcSHDArIG1yueA3nnNd9NJhA9Ue1RRC0GWQaaax/vMwQnJD7rEXteGM7TyB0VCEeNWsufGOl5E4+/cqmOjtVDmQvgLIIJIiQrn+ohGnYLLjqeC3LRdnHeedN/DwX3cIM5NKxy53VFcIM7yk7ApveV+vIT8uZLbXA9p5r9fvjPx9AHLZU+6yRg/B4ihftnXAPiq4SQHa53CkTOB61gHJf8soejFAJuHwq767aVwKULuKqP76/P1WMJGgS12aojW7UcqtJeFgS/xp81Wbv8fWDw6RxyXeUXlJxTViSfAoDtzeRnCeCkGjpMQOg20y1py8402IbC++7ABiEMvX3rtL3JJBad5gWKI7eT/+IcnfbiKNs+64+RiTJdDXUso9LsbUAEV0V4Wk8IROA1AXqsL9kfgiCgF8IC7seO9d0jrQ6EhiwQ9gHGXnwQ== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Dec 2016 13:09:24.0897 (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: BN1PR0301MB0739 Subject: [dpdk-dev] [PATCH v3 11/12] eal: enable PCI bus and PCI test framework 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:33 -0000 Register a PCI bus with Scan/match and probe callbacks. Necessary changes in EAL layer for enabling bus interfaces. PCI devices and drivers now reside within the Bus object. Now that PCI bus handles the scan/probe methods, independent calls to PCI scan and probe can be removed from the code. PCI device and driver list are also removed. rte_device and rte_driver list continue to exist. As does the VDEV lists. Changes to test_pci: - use a dummy test_pci_bus for all PCI test driver registrations - this reduces the need for cleaning global list - add necessary callbacks for invoking scan and probing/matching using EAL PCI scan code Note: With this patch, all PCI PMDs would cease to work because of lack rte_driver->probe/remove implementations. Next patch would do that. Signed-off-by: Shreyansh Jain --- app/test/test_pci.c | 154 +++++++++++------ lib/librte_eal/bsdapp/eal/eal.c | 7 - lib/librte_eal/bsdapp/eal/eal_pci.c | 52 +++--- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 7 +- lib/librte_eal/common/eal_common_pci.c | 212 ++++++++++++++---------- lib/librte_eal/common/eal_private.h | 14 +- lib/librte_eal/common/include/rte_pci.h | 53 +++--- lib/librte_eal/linuxapp/eal/eal.c | 7 - lib/librte_eal/linuxapp/eal/eal_pci.c | 57 ++++--- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 7 +- 10 files changed, 330 insertions(+), 240 deletions(-) diff --git a/app/test/test_pci.c b/app/test/test_pci.c index f9b84db..e95b758 100644 --- a/app/test/test_pci.c +++ b/app/test/test_pci.c @@ -38,6 +38,7 @@ #include #include +#include #include #include #include @@ -61,10 +62,18 @@ int test_pci_run = 0; /* value checked by the multiprocess test */ static unsigned pci_dev_count; +static struct rte_bus *pci_bus; /* global reference to a Test PCI bus */ static int my_driver_init(struct rte_pci_driver *dr, struct rte_pci_device *dev); +/* Test PCI bus. */ +struct rte_bus test_pci_bus = { + .name = "test_pci_bus", + .scan = rte_eal_pci_scan, + .match = rte_eal_pci_match, +}; + /* IXGBE NICS */ struct rte_pci_id my_driver_id[] = { {RTE_PCI_DEVICE(0x0001, 0x1234)}, @@ -79,7 +88,9 @@ struct rte_pci_id my_driver_id2[] = { struct rte_pci_driver my_driver = { .driver = { - .name = "test_driver" + .name = "test_driver", + .probe = rte_eal_pci_probe, + .remove = rte_eal_pci_remove, }, .probe = my_driver_init, .id_table = my_driver_id, @@ -88,7 +99,9 @@ struct rte_pci_driver my_driver = { struct rte_pci_driver my_driver2 = { .driver = { - .name = "test_driver2" + .name = "test_driver2", + .probe = rte_eal_pci_probe, + .remove = rte_eal_pci_remove, }, .probe = my_driver_init, .id_table = my_driver_id2, @@ -108,14 +121,67 @@ my_driver_init(__attribute__((unused)) struct rte_pci_driver *dr, return 0; } +/* dump devices on the bus */ +static void +do_pci_device_dump(FILE *f) +{ + int i; + struct rte_pci_device *dev = NULL; + struct rte_device *r_dev = NULL; + + TAILQ_FOREACH(r_dev, &pci_bus->device_list, next) { + dev = container_of(r_dev, struct rte_pci_device, device); + + fprintf(f, PCI_PRI_FMT, dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); + fprintf(f, " - vendor:%x device:%x\n", dev->id.vendor_id, + dev->id.device_id); + + for (i = 0; i != sizeof(dev->mem_resource) / + sizeof(dev->mem_resource[0]); i++) { + fprintf(f, " %16.16"PRIx64" %16.16"PRIx64"\n", + dev->mem_resource[i].phys_addr, + dev->mem_resource[i].len); + } + } +} + +/* Dummy implementation for rte_eal_pci_probe() over test_pci_bus */ +static int +do_pci_bus_probe(void) +{ + int ret; + struct rte_device *device; + struct rte_driver *driver; + + TAILQ_FOREACH(device, &pci_bus->device_list, next) { + TAILQ_FOREACH(driver, &pci_bus->driver_list, next) { + ret = pci_bus->match(driver, device); + if (!ret) { + if (!driver->probe) + continue; + + device->driver = driver; + ret = driver->probe(driver, device); + if (ret != 0) + return ret; + } + } + } + + return 0; +} + static void blacklist_all_devices(void) { struct rte_pci_device *dev = NULL; + struct rte_device *device = NULL; unsigned i = 0; char pci_addr_str[16]; - TAILQ_FOREACH(dev, &pci_device_list, next) { + TAILQ_FOREACH(device, &(pci_bus->device_list), next) { + 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, dev->addr.function); @@ -142,19 +208,11 @@ static void free_devargs_list(void) } } -/* backup real devices & drivers (not used for testing) */ -struct pci_driver_list real_pci_driver_list = - TAILQ_HEAD_INITIALIZER(real_pci_driver_list); -struct pci_device_list real_pci_device_list = - TAILQ_HEAD_INITIALIZER(real_pci_device_list); - REGISTER_LINKED_RESOURCE(test_pci_sysfs); static int test_pci_setup(void) { - struct rte_pci_device *dev; - struct rte_pci_driver *dr; const struct resource *r; int ret; @@ -167,22 +225,19 @@ test_pci_setup(void) ret = setenv("SYSFS_PCI_DEVICES", "test_pci_sysfs/bus/pci/devices", 1); TEST_ASSERT_SUCCESS(ret, "failed to setenv"); - /* Unregister original devices & drivers lists */ - while (!TAILQ_EMPTY(&pci_driver_list)) { - dr = TAILQ_FIRST(&pci_driver_list); - rte_eal_pci_unregister(dr); - TAILQ_INSERT_TAIL(&real_pci_driver_list, dr, next); - } + /* Create a new Bus called 'test_pci_bus' */ + /* Bus doesn't exist; Create the test bus */ + printf("Creating a Test PCI bus\n"); + rte_eal_bus_register(&test_pci_bus); + pci_bus = &test_pci_bus; - while (!TAILQ_EMPTY(&pci_device_list)) { - dev = TAILQ_FIRST(&pci_device_list); - TAILQ_REMOVE(&pci_device_list, dev, next); - TAILQ_INSERT_TAIL(&real_pci_device_list, dev, next); - } + printf("Scan for Test devices and add to bus\n"); + ret = pci_bus->scan(pci_bus); - ret = rte_eal_pci_scan(NULL); TEST_ASSERT_SUCCESS(ret, "failed to scan PCI bus"); - rte_eal_pci_dump(stdout); + + printf("Dump of all devices scanned:\n"); + do_pci_device_dump(stdout); return 0; } @@ -190,8 +245,8 @@ test_pci_setup(void) static int test_pci_cleanup(void) { - struct rte_pci_device *dev; - struct rte_pci_driver *dr; + struct rte_device *dev = NULL; + struct rte_driver *dr = NULL; const struct resource *r; int ret; @@ -203,28 +258,23 @@ test_pci_cleanup(void) ret = resource_rm_by_tar(r); TEST_ASSERT_SUCCESS(ret, "Failed to delete resource %s", r->name); + TEST_ASSERT_NOT_NULL(pci_bus, "Invalid bus specified"); + /* * FIXME: there is no API in DPDK to free a rte_pci_device so we * cannot free the devices in the right way. Let's assume that we * don't care for tests. */ - while (!TAILQ_EMPTY(&pci_device_list)) { - dev = TAILQ_FIRST(&pci_device_list); - TAILQ_REMOVE(&pci_device_list, dev, next); + TAILQ_FOREACH(dev, &(pci_bus->device_list), next) { + rte_eal_bus_remove_device(dev); + dev->driver = NULL; } - /* Restore original devices & drivers lists */ - while (!TAILQ_EMPTY(&real_pci_driver_list)) { - dr = TAILQ_FIRST(&real_pci_driver_list); - TAILQ_REMOVE(&real_pci_driver_list, dr, next); - rte_eal_pci_register(dr); + TAILQ_FOREACH(dr, &(pci_bus->driver_list), next) { + rte_eal_bus_remove_driver(dr); } - while (!TAILQ_EMPTY(&real_pci_device_list)) { - dev = TAILQ_FIRST(&real_pci_device_list); - TAILQ_REMOVE(&real_pci_device_list, dev, next); - TAILQ_INSERT_TAIL(&pci_device_list, dev, next); - } + rte_eal_bus_unregister(pci_bus); return 0; } @@ -234,16 +284,19 @@ test_pci_blacklist(void) { struct rte_devargs_list save_devargs_list; - printf("Dump all devices\n"); - TEST_ASSERT(TAILQ_EMPTY(&pci_driver_list), - "pci_driver_list not empty"); + TEST_ASSERT_NOT_NULL(pci_bus, "Invalid bus specified"); + + TEST_ASSERT(TAILQ_EMPTY(&pci_bus->driver_list), + "PCI Driver list not empty"); - rte_eal_pci_register(&my_driver); - rte_eal_pci_register(&my_driver2); + /* Add test drivers to Bus */ + rte_eal_bus_add_driver(pci_bus, &(my_driver.driver)); + rte_eal_bus_add_driver(pci_bus, &(my_driver2.driver)); pci_dev_count = 0; - printf("Scan bus\n"); - rte_eal_pci_probe(); + + printf("Probe the Test Bus\n"); + do_pci_bus_probe(); if (pci_dev_count == 0) { printf("no device detected\n"); @@ -257,8 +310,8 @@ test_pci_blacklist(void) blacklist_all_devices(); pci_dev_count = 0; - printf("Scan bus with all devices blacklisted\n"); - rte_eal_pci_probe(); + printf("Probe bus with all devices blacklisted\n"); + do_pci_bus_probe(); free_devargs_list(); devargs_list = save_devargs_list; @@ -270,8 +323,9 @@ test_pci_blacklist(void) test_pci_run = 1; - rte_eal_pci_unregister(&my_driver); - rte_eal_pci_unregister(&my_driver2); + /* Clear the test drivers added to Test Bus */ + rte_eal_bus_remove_driver(&(my_driver.driver)); + rte_eal_bus_remove_driver(&(my_driver2.driver)); return 0; } diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 30afc6b..79d82d4 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -562,9 +562,6 @@ rte_eal_init(int argc, char **argv) if (rte_eal_timer_init() < 0) rte_panic("Cannot init HPET or TSC timers\n"); - if (rte_eal_pci_init() < 0) - rte_panic("Cannot init PCI\n"); - eal_check_mem_on_local_socket(); if (eal_plugins_init() < 0) @@ -616,10 +613,6 @@ rte_eal_init(int argc, char **argv) rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER); rte_eal_mp_wait_lcore(); - /* Probe & Initialize PCI devices */ - if (rte_eal_pci_probe()) - rte_panic("Cannot probe PCI\n"); - if (rte_eal_bus_probe()) rte_panic("Cannot probe devices\n"); diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 10b234e..ab9f9d2 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -58,6 +58,7 @@ #include #include +#include #include #include #include @@ -249,7 +250,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, } static int -pci_scan_one(int dev_pci_fd, struct pci_conf *conf) +pci_scan_one(struct rte_bus *bus, int dev_pci_fd, struct pci_conf *conf) { struct rte_pci_device *dev; struct pci_bar_io bar; @@ -322,19 +323,23 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf) } /* device is valid, add in list (sorted) */ - if (TAILQ_EMPTY(&pci_device_list)) { - TAILQ_INSERT_TAIL(&pci_device_list, dev, next); + if (TAILQ_EMPTY(&bus->device_list)) { + rte_eal_bus_add_device(bus, &dev->device); } else { struct rte_pci_device *dev2 = NULL; + struct rte_device *r_dev2; int ret; - TAILQ_FOREACH(dev2, &pci_device_list, next) { + TAILQ_FOREACH(r_dev2, &bus->device_list, next) { + dev2 = container_of(r_dev2, struct rte_pci_device, + device); ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr); if (ret > 0) continue; else if (ret < 0) { - TAILQ_INSERT_BEFORE(dev2, dev, next); + rte_eal_bus_insert_device(bus, &dev2->device, + &dev->device); return 0; } else { /* already registered */ dev2->kdrv = dev->kdrv; @@ -346,7 +351,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf) return 0; } } - TAILQ_INSERT_TAIL(&pci_device_list, dev, next); + rte_eal_bus_add_device(bus, &dev->device); } return 0; @@ -361,7 +366,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf) * list. Call pci_scan_one() for each pci entry found. */ int -rte_eal_pci_scan(struct rte_bus *bus __rte_unused) +rte_eal_pci_scan(struct rte_bus *bus) { int fd; unsigned dev_count = 0; @@ -374,6 +379,10 @@ rte_eal_pci_scan(struct rte_bus *bus __rte_unused) .matches = &matches[0], }; + /* for debug purposes, PCI can be disabled */ + if (internal_config.no_pci) + return 0; + fd = open("/dev/pci", O_RDONLY); if (fd < 0) { RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__); @@ -389,7 +398,7 @@ rte_eal_pci_scan(struct rte_bus *bus __rte_unused) } for (i = 0; i < conf_io.num_matches; i++) - if (pci_scan_one(fd, &matches[i]) < 0) + if (pci_scan_one(bus, fd, &matches[i]) < 0) goto error; dev_count += conf_io.num_matches; @@ -407,9 +416,9 @@ rte_eal_pci_scan(struct rte_bus *bus __rte_unused) } int -pci_update_device(const struct rte_pci_addr *addr) +pci_update_device(struct rte_bus *bus, const struct rte_pci_addr *addr) { - int fd; + int fd = -1; struct pci_conf matches[2]; struct pci_match_conf match = { .pc_sel = { @@ -427,6 +436,9 @@ pci_update_device(const struct rte_pci_addr *addr) .matches = &matches[0], }; + if (!bus) + goto error; + fd = open("/dev/pci", O_RDONLY); if (fd < 0) { RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__); @@ -442,7 +454,7 @@ pci_update_device(const struct rte_pci_addr *addr) if (conf_io.num_matches != 1) goto error; - if (pci_scan_one(fd, &matches[0]) < 0) + if (pci_scan_one(bus, fd, &matches[0]) < 0) goto error; close(fd); @@ -668,17 +680,9 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p) return ret; } -/* Init the PCI EAL subsystem */ -int -rte_eal_pci_init(void) -{ - /* for debug purposes, PCI can be disabled */ - if (internal_config.no_pci) - return 0; +struct rte_bus pci_bus = { + .scan = rte_eal_pci_scan, + .match = rte_eal_pci_match, +}; - if (rte_eal_pci_scan(NULL) < 0) { - RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__); - return -1; - } - return 0; -} +RTE_REGISTER_BUS(pci, pci_bus); diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 23fc1c1..3dcf439 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -6,8 +6,6 @@ DPDK_2.0 { eal_parse_sysfs_value; eal_timer_source; lcore_config; - pci_device_list; - pci_driver_list; per_lcore__lcore_id; per_lcore__rte_errno; rte_calloc; @@ -41,7 +39,6 @@ DPDK_2.0 { rte_eal_mp_wait_lcore; rte_eal_parse_devargs_str; rte_eal_pci_dump; - rte_eal_pci_probe; rte_eal_pci_probe_one; rte_eal_pci_register; rte_eal_pci_scan; @@ -187,5 +184,9 @@ DPDK_17.02 { rte_eal_bus_remove_device; rte_eal_bus_remove_driver; rte_eal_bus_unregister; + rte_eal_pci_match; + rte_eal_pci_probe; + rte_eal_pci_remove; + rte_eal_pci_scan; } DPDK_16.11; diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 562c0fd..e6d8d87 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -71,6 +71,7 @@ #include #include +#include #include #include #include @@ -82,11 +83,6 @@ #include "eal_private.h" -struct pci_driver_list pci_driver_list = - TAILQ_HEAD_INITIALIZER(pci_driver_list); -struct pci_device_list pci_device_list = - TAILQ_HEAD_INITIALIZER(pci_device_list); - #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices" const char *pci_get_sysfs_path(void) @@ -206,39 +202,10 @@ 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; - 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; - } - - /* The device is not blacklisted; Check if driver supports it */ - ret = rte_eal_pci_match(driver, device); - 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); @@ -276,23 +243,11 @@ static int rte_eal_pci_detach_dev(struct rte_pci_driver *dr, struct rte_pci_device *dev) { - int ret; - struct rte_driver *driver = NULL; - struct rte_device *device; struct rte_pci_addr *loc; if ((dr == NULL) || (dev == NULL)) return -EINVAL; - driver = &(dr->driver); - device = &(dev->device); - - ret = rte_eal_pci_match(driver, device); - if (ret) { - /* Device and driver don't match */ - return 1; - } - loc = &dev->addr; RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", @@ -321,9 +276,9 @@ rte_eal_pci_detach_dev(struct rte_pci_driver *dr, * failed, return 1 if no driver is found for this device. */ static int -pci_probe_all_drivers(struct rte_pci_device *dev) +pci_probe_all_drivers(struct rte_bus *bus, struct rte_pci_device *dev) { - struct rte_pci_driver *dr = NULL; + struct rte_driver *r_dr = NULL; int rc = 0; if (dev == NULL) @@ -333,8 +288,8 @@ pci_probe_all_drivers(struct rte_pci_device *dev) if (dev->driver != NULL) return 0; - TAILQ_FOREACH(dr, &pci_driver_list, next) { - rc = rte_eal_pci_probe_one_driver(dr, dev); + TAILQ_FOREACH(r_dr, &bus->driver_list, next) { + rc = rte_eal_pci_probe(r_dr, &dev->device); if (rc < 0) /* negative value is an error */ return -1; @@ -352,15 +307,17 @@ pci_probe_all_drivers(struct rte_pci_device *dev) * failed, return 1 if no driver is found for this device. */ static int -pci_detach_all_drivers(struct rte_pci_device *dev) +pci_detach_all_drivers(struct rte_bus *bus, struct rte_pci_device *dev) { struct rte_pci_driver *dr = NULL; + struct rte_driver *r_dr = NULL; int rc = 0; if (dev == NULL) return -1; - TAILQ_FOREACH(dr, &pci_driver_list, next) { + TAILQ_FOREACH(r_dr, &bus->driver_list, next) { + dr = container_of(r_dr, struct rte_pci_driver, driver); rc = rte_eal_pci_detach_dev(dr, dev); if (rc < 0) /* negative value is an error */ @@ -381,22 +338,31 @@ int rte_eal_pci_probe_one(const struct rte_pci_addr *addr) { struct rte_pci_device *dev = NULL; + struct rte_device *r_dev = NULL; + struct rte_bus *bus; int ret = 0; if (addr == NULL) return -1; + bus = rte_eal_get_bus("pci"); + if (!bus) { + RTE_LOG(ERR, EAL, "PCI Bus not registered\n"); + return -1; + } + /* update current pci device in global list, kernel bindings might have * changed since last time we looked at it. */ - if (pci_update_device(addr) < 0) + if (pci_update_device(bus, addr) < 0) goto err_return; - TAILQ_FOREACH(dev, &pci_device_list, next) { + TAILQ_FOREACH(r_dev, &bus->device_list, next) { + dev = container_of(r_dev, struct rte_pci_device, device); if (rte_eal_compare_pci_addr(&dev->addr, addr)) continue; - ret = pci_probe_all_drivers(dev); + ret = pci_probe_all_drivers(bus, dev); if (ret) goto err_return; return 0; @@ -417,20 +383,29 @@ int rte_eal_pci_detach(const struct rte_pci_addr *addr) { struct rte_pci_device *dev = NULL; + struct rte_device *r_dev = NULL; + struct rte_bus *bus; int ret = 0; if (addr == NULL) return -1; - TAILQ_FOREACH(dev, &pci_device_list, next) { + bus = rte_eal_get_bus("pci"); + if (!bus) { + RTE_LOG(ERR, EAL, "PCI Bus is not registered\n"); + return -1; + } + + TAILQ_FOREACH(r_dev, &bus->device_list, next) { + dev = container_of(r_dev, struct rte_pci_device, device); if (rte_eal_compare_pci_addr(&dev->addr, addr)) continue; - ret = pci_detach_all_drivers(dev); + ret = pci_detach_all_drivers(bus, dev); if (ret < 0) goto err_return; - TAILQ_REMOVE(&pci_device_list, dev, next); + rte_eal_bus_remove_device(r_dev); free(dev); return 0; } @@ -443,41 +418,73 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr) return -1; } -/* - * Scan the content of the PCI bus, and call the probe() function for - * all registered drivers that have a matching entry in its id_table - * for discovered devices. - */ int -rte_eal_pci_probe(void) +rte_eal_pci_probe(struct rte_driver *driver, struct rte_device *device) { - struct rte_pci_device *dev = NULL; - struct rte_devargs *devargs; - int probe_all = 0; int ret = 0; + struct rte_devargs *devargs; + struct rte_pci_device *pci_dev; + struct rte_pci_driver *pci_drv; + struct rte_pci_addr *loc; - if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) == 0) - probe_all = 1; + if (!driver || !device) + return -1; - TAILQ_FOREACH(dev, &pci_device_list, next) { + pci_dev = container_of(device, struct rte_pci_device, device); + pci_drv = container_of(driver, struct rte_pci_driver, driver); - /* set devargs in PCI structure */ - devargs = pci_devargs_lookup(dev); - if (devargs != NULL) - dev->device.devargs = devargs; + loc = &pci_dev->addr; - /* probe all or only whitelisted devices */ - if (probe_all) - ret = pci_probe_all_drivers(dev); - else if (devargs != NULL && - devargs->type == RTE_DEVTYPE_WHITELISTED_PCI) - ret = pci_probe_all_drivers(dev); - if (ret < 0) - rte_exit(EXIT_FAILURE, "Requested device " PCI_PRI_FMT - " cannot be used\n", dev->addr.domain, dev->addr.bus, - dev->addr.devid, dev->addr.function); + RTE_LOG(INFO, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", + loc->domain, loc->bus, loc->devid, loc->function, + pci_dev->device.numa_node); + + /* Fetch the devargs associated with the device */ + devargs = pci_devargs_lookup(pci_dev); + if (devargs != NULL) + pci_dev->device.devargs = devargs; + + /* no initialization when blacklisted, return without error */ + if (pci_dev->device.devargs != NULL && + pci_dev->device.devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) { + RTE_LOG(INFO, EAL, " Device is blacklisted, not" + " initializing\n"); + return 1; } + ret = rte_eal_pci_probe_one_driver(pci_drv, pci_dev); + if (ret < 0) { + RTE_LOG(ERR, EAL, "Requested device " PCI_PRI_FMT + " cannot be used\n", pci_dev->addr.domain, + pci_dev->addr.bus, pci_dev->addr.devid, + pci_dev->addr.function); + return ret; + } + return 0; +} + +int +rte_eal_pci_remove(struct rte_device *device) +{ + int ret = 0; + struct rte_pci_device *pci_dev; + + if (!device) + return -1; + + pci_dev = container_of(device, struct rte_pci_device, device); + + if (!pci_dev->driver) + return -1; + + ret = rte_eal_pci_detach_dev(pci_dev->driver, pci_dev); + if (ret < 0) { + RTE_LOG(ERR, EAL, "Requested device " PCI_PRI_FMT + " cannot be used\n", pci_dev->addr.domain, + pci_dev->addr.bus, pci_dev->addr.devid, + pci_dev->addr.function); + return ret; + } return 0; } @@ -506,8 +513,17 @@ void rte_eal_pci_dump(FILE *f) { struct rte_pci_device *dev = NULL; + struct rte_device *r_dev = NULL; + struct rte_bus *bus; - TAILQ_FOREACH(dev, &pci_device_list, next) { + bus = rte_eal_get_bus("pci"); + if (!bus) { + RTE_LOG(ERR, EAL, "PCI Bus not registered\n"); + return; + } + + TAILQ_FOREACH(r_dev, &bus->device_list, next) { + dev = container_of(r_dev, struct rte_pci_device, device); pci_dump_one_device(f, dev); } } @@ -516,14 +532,32 @@ rte_eal_pci_dump(FILE *f) void rte_eal_pci_register(struct rte_pci_driver *driver) { - TAILQ_INSERT_TAIL(&pci_driver_list, driver, next); - rte_eal_driver_register(&driver->driver); + struct rte_bus *bus; + + RTE_VERIFY(driver); + + bus = rte_eal_get_bus("pci"); + if (!bus) { + RTE_LOG(ERR, EAL, "PCI Bus not registered\n"); + return; + } + + rte_eal_bus_add_driver(bus, &driver->driver); } /* unregister a driver */ void rte_eal_pci_unregister(struct rte_pci_driver *driver) { - rte_eal_driver_unregister(&driver->driver); - TAILQ_REMOVE(&pci_driver_list, driver, next); + struct rte_bus *bus; + + RTE_VERIFY(driver); + + bus = driver->driver.bus; + if (!bus) { + RTE_LOG(ERR, EAL, "PCI Bus not registered\n"); + return; + } + + rte_eal_bus_remove_driver(&driver->driver); } diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index 9e7d8f6..06ec172 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -108,16 +108,6 @@ int rte_eal_timer_init(void); */ int rte_eal_log_init(const char *id, int facility); -/** - * Init the PCI infrastructure - * - * This function is private to EAL. - * - * @return - * 0 on success, negative on error - */ -int rte_eal_pci_init(void); - struct rte_pci_driver; struct rte_pci_device; @@ -126,13 +116,15 @@ struct rte_pci_device; * * This function is private to EAL. * + * @param bus + * The PCI bus on which device is connected * @param addr * The PCI Bus-Device-Function address to look for * @return * - 0 on success. * - negative on error. */ -int pci_update_device(const struct rte_pci_addr *addr); +int pci_update_device(struct rte_bus *bus, const struct rte_pci_addr *addr); /** * Unbind kernel driver for this device diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 10108a4..ec8f672 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -86,12 +86,6 @@ extern "C" { #include #include -TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */ -TAILQ_HEAD(pci_driver_list, rte_pci_driver); /**< PCI drivers in D-linked Q. */ - -extern struct pci_driver_list pci_driver_list; /**< Global list of PCI drivers. */ -extern struct pci_device_list pci_device_list; /**< Global list of PCI devices. */ - /** Pathname of PCI devices directory. */ const char *pci_get_sysfs_path(void); @@ -372,6 +366,40 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr, int rte_eal_pci_scan(struct rte_bus *bus); /** + * Probe callback for the PCI bus + * + * For each matched pair of PCI device and driver on PCI bus, perform devargs + * check, and call a series of callbacks to allocate ethdev/cryptodev instances + * and intializing them. + * + * @param driver + * Generic driver object matched with the device + * @param device + * Generic device object to initialize + * @return + * - 0 on success. + * - !0 on error. + */ +int +rte_eal_pci_probe(struct rte_driver *driver, struct rte_device *device); + +/** + * Remove callback for the PCI bus + * + * Called when a device needs to be removed from a bus; wraps around the + * PCI specific implementation layered over rte_pci_driver->remove. Default + * handler used by PCI PMDs + * + * @param device + * rte_device object referring to device to be removed + * @return + * - 0 for successful removal + * - !0 for failure in removal of device + */ +int +rte_eal_pci_remove(struct rte_device *device); + +/** * Match the PCI Driver and Device using the ID Table * * @param drv @@ -387,19 +415,6 @@ rte_eal_pci_match(struct rte_driver *drv, struct rte_device *dev); /** - * Probe the PCI bus for registered drivers. - * - * Scan the content of the PCI bus, and call the probe() function for - * all registered drivers that have a matching entry in its id_table - * for discovered devices. - * - * @return - * - 0 on success. - * - Negative on error. - */ -int rte_eal_pci_probe(void); - -/** * Map the PCI device resources in user space virtual memory address * * Note that driver should not call this function when flag diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index 01d0cee..ff92de2 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -803,9 +803,6 @@ rte_eal_init(int argc, char **argv) if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0) rte_panic("Cannot init logs\n"); - if (rte_eal_pci_init() < 0) - rte_panic("Cannot init PCI\n"); - #ifdef VFIO_PRESENT if (rte_eal_vfio_setup() < 0) rte_panic("Cannot init VFIO\n"); @@ -887,10 +884,6 @@ rte_eal_init(int argc, char **argv) rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER); rte_eal_mp_wait_lcore(); - /* Probe & Initialize PCI devices */ - if (rte_eal_pci_probe()) - rte_panic("Cannot probe PCI\n"); - if (rte_eal_bus_probe()) rte_panic("Cannot probe devices\n"); diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index cbd25df..5c66aa7 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -267,7 +268,8 @@ pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev) /* Scan one pci sysfs entry, and fill the devices list from it. */ static int -pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) +pci_scan_one(struct rte_bus *bus, const char *dirname, + const struct rte_pci_addr *addr) { char filename[PATH_MAX]; unsigned long tmp; @@ -385,21 +387,23 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) dev->kdrv = RTE_KDRV_NONE; /* device is valid, add in list (sorted) */ - if (TAILQ_EMPTY(&pci_device_list)) { - rte_eal_device_insert(&dev->device); - TAILQ_INSERT_TAIL(&pci_device_list, dev, next); + if (TAILQ_EMPTY(&bus->device_list)) { + rte_eal_bus_add_device(bus, &dev->device); } else { struct rte_pci_device *dev2; + struct rte_device *r_dev2; int ret; - TAILQ_FOREACH(dev2, &pci_device_list, next) { + TAILQ_FOREACH(r_dev2, &bus->device_list, next) { + dev2 = container_of(r_dev2, struct rte_pci_device, + device); ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr); if (ret > 0) continue; if (ret < 0) { - TAILQ_INSERT_BEFORE(dev2, dev, next); - rte_eal_device_insert(&dev->device); + rte_eal_bus_insert_device(bus, &dev2->device, + &dev->device); } else { /* already registered */ dev2->kdrv = dev->kdrv; dev2->max_vfs = dev->max_vfs; @@ -409,15 +413,14 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) } return 0; } - rte_eal_device_insert(&dev->device); - TAILQ_INSERT_TAIL(&pci_device_list, dev, next); + rte_eal_bus_add_device(bus, &dev->device); } return 0; } int -pci_update_device(const struct rte_pci_addr *addr) +pci_update_device(struct rte_bus *bus, const struct rte_pci_addr *addr) { char filename[PATH_MAX]; @@ -425,7 +428,7 @@ pci_update_device(const struct rte_pci_addr *addr) pci_get_sysfs_path(), addr->domain, addr->bus, addr->devid, addr->function); - return pci_scan_one(filename, addr); + return pci_scan_one(bus, filename, addr); } /* @@ -479,13 +482,22 @@ parse_pci_addr_format(const char *buf, int bufsize, struct rte_pci_addr *addr) * list */ int -rte_eal_pci_scan(struct rte_bus *bus_p __rte_unused) +rte_eal_pci_scan(struct rte_bus *bus_p) { struct dirent *e; DIR *dir; char dirname[PATH_MAX]; struct rte_pci_addr addr; + if (!bus_p) { + RTE_LOG(ERR, EAL, "PCI Bus is not registered\n"); + return -1; + } + + /* for debug purposes, PCI can be disabled */ + if (internal_config.no_pci) + return 0; + dir = opendir(pci_get_sysfs_path()); if (dir == NULL) { RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n", @@ -504,7 +516,7 @@ rte_eal_pci_scan(struct rte_bus *bus_p __rte_unused) snprintf(dirname, sizeof(dirname), "%s/%s", pci_get_sysfs_path(), e->d_name); - if (pci_scan_one(dirname, &addr) < 0) + if (pci_scan_one(bus_p, dirname, &addr) < 0) goto error; } closedir(dir); @@ -750,18 +762,9 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p) return ret; } -/* Init the PCI EAL subsystem */ -int -rte_eal_pci_init(void) -{ - /* for debug purposes, PCI can be disabled */ - if (internal_config.no_pci) - return 0; - - if (rte_eal_pci_scan(NULL) < 0) { - RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__); - return -1; - } +struct rte_bus pci_bus = { + .scan = rte_eal_pci_scan, + .match = rte_eal_pci_match, +}; - return 0; -} +RTE_REGISTER_BUS(pci, pci_bus); diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index c873a7f..6e0ec51 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -6,8 +6,6 @@ DPDK_2.0 { eal_parse_sysfs_value; eal_timer_source; lcore_config; - pci_device_list; - pci_driver_list; per_lcore__lcore_id; per_lcore__rte_errno; rte_calloc; @@ -41,7 +39,6 @@ DPDK_2.0 { rte_eal_mp_wait_lcore; rte_eal_parse_devargs_str; rte_eal_pci_dump; - rte_eal_pci_probe; rte_eal_pci_probe_one; rte_eal_pci_register; rte_eal_pci_scan; @@ -191,5 +188,9 @@ DPDK_17.02 { rte_eal_bus_remove_device; rte_eal_bus_remove_driver; rte_eal_bus_unregister; + rte_eal_pci_match; + rte_eal_pci_probe; + rte_eal_pci_remove; + rte_eal_pci_scan; } DPDK_16.11; -- 2.7.4