From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0062.outbound.protection.outlook.com [104.47.33.62]) by dpdk.org (Postfix) with ESMTP id 4950A567A for ; Fri, 16 Dec 2016 14:09:05 +0100 (CET) Received: from BY2PR03CA063.namprd03.prod.outlook.com (10.141.249.36) by DM2PR0301MB0752.namprd03.prod.outlook.com (10.160.97.148) 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:04 +0000 Received: from BL2FFO11FD018.protection.gbl (2a01:111:f400:7c09::168) by BY2PR03CA063.outlook.office365.com (2a01:111:e400:2c5d::36) 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:03 +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 BL2FFO11FD018.mail.protection.outlook.com (10.173.161.36) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.761.6 via Frontend Transport; Fri, 16 Dec 2016 13:09:02 +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 uBGD8BtF028345; Fri, 16 Dec 2016 06:08:59 -0700 From: Shreyansh Jain To: , CC: , , , Shreyansh Jain Date: Fri, 16 Dec 2016 18:40:45 +0530 Message-ID: <1481893853-31790-5-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: 131263673428473197; (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)(39860400002)(39380400002)(39840400002)(39850400002)(39400400002)(39410400002)(39450400003)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(33646002)(8676002)(50986999)(36756003)(356003)(86362001)(8666005)(4326007)(5890100001)(81166006)(81156014)(8936002)(104016004)(68736007)(50226002)(6666003)(2950100002)(5660300001)(2906002)(106466001)(77096006)(47776003)(38730400001)(305945005)(92566002)(50466002)(105606002)(5003940100001)(626004)(189998001)(97736004)(48376002)(76176999)(5001770100001)(85426001)(7059030)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR0301MB0752; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD018; 1:c0H/inP9j4DYIrLN0AhqQcxpTslozqjVx1Rf2IKnS9EHhcJsmiMhLjA5wegFQ7IEbGucyqml8LMFvGPB8CaZ1NE1RcOz/UMBCrK9fpYvfTo0BQD0bhnOX9MrW+YG+jDLqQbNpc6hutHmwZEXbj71vQr9nszMBtTBzCiioka3UvIC4imf7CBc+yD7byZQdKZhH8HCm+YvI9L9NWiUoBwZ8mQc6HnF22c/9CMfeBIMq9DMuWzgIzKIl5DMQW7D/YuZeW0+sXfUVk6F844PLV1uQWLJriSuItwSQcEIXy2ceMEHE9CR5nwL0GMEM8WcnR5jipqd8NfGRro/J4hzuoks3WyfwVsrL9bbCVZRlzKaqCZZXG7u3aTiZ2D1m+lz/zIStXG1T9hybmcZPAmjN9tNn3LtjDRLbe7Jg4osotaawTfYXPGbJ8fxVmu77A8jy+ynunbJ5mU52PqApR/z7U0pdLfhWlyJhuLMyBnFql452rFhBChy+FYz4h191KuunlRInNkFiffBuAicsWW3GIEzuAOg87weyz+x1xfrSs7s9j/aK3TBkAeXqI9JV7SPkRyFcBbETF1bk/zaLw9Ba+C0NBXtXci2qSBxlvEZiBpshLR8DefL06Bx1dqwn7kgSKjWMMh3NpvZxaQNeSPnL1Hdch8TntezsmQzqUTlkUDp/ckr0vB9NEvCOlkzUDNrUEx+OIN6zXgDVrYn7Ll6KtWy0nbdvCyS2mjb9sKasfnhAfPCY/dfp3yTVOPrhuDSeec2MnCXvS/HZ0K0mOP3aM+cKw== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 51d42e8b-68fa-469b-f56d-08d425b4b514 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DM2PR0301MB0752; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0752; 3:buuQMPeSSWl2DE/jG8sxLbnfRD1qx0JEJTedeFQ3H9q4W57OZSzBhgGdtNcyg/ycRXDtZi3gTAznHNv5ffB5g2UGCv2mu4SuwDrs8wpSrnqLAC3Haar1Bc8PRpS7audR2kFrpP1GRJSibP1VPQNA0gsMj+vy8m+6z44CwvkIrGj504vhlplLWHmXxmyYrLpX0uUMqspLBX/SXPa3OUZO28hD1DmRoEx8SupX6LZK07F1aaiaF85Ya2di5II+DskRDyatftoEI76iaCoiGSkK/0+skj1Pnvk94h4kSvUd53bAqwsXs+pRf8Sfw+8qJ3gNyEUGhjK6Uhb9zG10A5SmCZSfRvWSwOzkrcEtG5eJ169bDNng8ktczYHOUPmtiye5; 25:6WsEVa5lydrv04qQDWR6uoGBDn/ZVU6vxcn7JlwI9u7pA2rWBv9lB2wiECRWRKYj74OARbHON3tJBctrpH+xVHAjdpTpxWrnCxxuShd5eXr3Q4vC3lnn8R8/Tm9Nl0p8e5NNVGBSWx55Cpilkcj7MJpgdl+h20pe8BHSH34e9dbw6W5Ge94xRm2slT3CIPNcUvfEvAhdYpWjmzWaxHNy60/k+P0dhD9iY3c1Pp8B3qZWKpmD/o7+PA14rgA8QtDJ2zXHBM7Ti0K5RmeLJwz/AyHNdLXZIlABAkG3Z2KAdWIizLPXoUvn4Ad8I5Otg8ckJGzW8Kkze4ICay1d0rOjVnR6aE0XvbFjKtgVKDh7x38Ik1regyN6oPnLoHRrwUCZH4Rk7MtRb5QRigUmbdAan7cAtyi5sb9uRge1z2pBrF51ZbVvFiyAGd/+wFZKUe20fivskpcCOHHtXtzCTVFmow== X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0752; 31:rCxh+AHMjMlYc10gDvrObyoXnmouriBQgeS92Y2aHC19loOG49cUBHEWZ2M6QmyPrwNgsjvyLK3DlNo9jTTzFWs6rCEZGn8Y7shVHlHJZ/mVHOHV8G+uRY0M/SbTKZxlD62ZJA8jNRUn6zgzB133IqIAZFg5zAuOvt1ayT8rkO5vJV5tWkMymWDpcM4J38lj4P8mWRgVDlDk5Uue3PcjFWIy60+lR7vyWVljzRmAMAvEuMYlm0zS71mqOjpvfq5dzikquILlmYvymhPAZ0Afa0mCLp4zogUrsr0d2Q8BE3w= 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)(13018025)(13015025)(13024025)(13023025)(13017025)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6096035)(20161123561025)(20161123559025)(20161123563025)(20161123565025)(20161123556025); SRVR:DM2PR0301MB0752; BCL:0; PCL:0; RULEID:(400006); SRVR:DM2PR0301MB0752; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0752; 4:W+Pn+1oNGH4YrdMGbNd/zeHrO2dDlpjpOhLbDcXbIeYC66ad03488Il1pLVRhqBCbyDpUc0W1NEEkp02pbJDys1SJatRTKFfSRujBoQkNClpHBKMdyz/w3a8jZ9WRny/yErYGKpSJWEbW6xvtOW9eULOGJDqxGq3TJvvCd+PYXe3rPOPTxUxFoddl1pBPwGG6OU/iFIiid6T+pgg/dSZA38VCrYlUmUd4n/v2cVl3C+calSMA741H/C8HWowYPYi0ZUFJ6Ls6hY5ccFAELgnKnQZw8BtCmKO0sxVHOst0jlVuSU95WbZIhvtjECswRVjpR2QDgaV3HFI4vQ3YUyB+1oZtW54YW5RsqpyXad9dH1GcTPEpCtFmkCuVTiM1pdOuxkNMfzccYsL5JOEQtjal7oWeHrKeq5q5tuZLJcNX1CcNbsCYGzvDi5qXdnkkXlfHOBhsDNUKtpKKbVoDcu/UDlL/xndbLD9uscJiFFPig9Htb+HwCX43Y07IH6qNdUsrWsSftHJg4YOcU6UC33uSls5j3UgRwUvSihfVlLLuJcx5gnJPgbumMAPWIsgGs+z8Oe6K3sIthRG/gzWY/94F5qNIqmVlAfLTHrQcDAC8Gfkmpcjyf05dmSoicltshLMDvaUfWnx7+PVzZlKlxPHSOgpAI/DvjJZppHwAzRB7mEuOq4UTBb2PF8d2lRSTqgQcMcPa6D7nnLt6Iqair+0n2cPdezYOo2Th+2aQjwLJotZhbyliQqT9UDVdeH1hnig X-Forefront-PRVS: 01583E185C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR0301MB0752; 23:sujf06Zb0TSTeXusJsO6156G7TsMl0JBtPzbRF0?= =?us-ascii?Q?j/XEN2w916MJZ1TRepQ0ScROwqwOdJP3rRsffVHnJHPoW0E2MSn0+E0oA0M5?= =?us-ascii?Q?VQvXpi+kpVU3yJgiU9traljprLvoS56REDRnUHl31OXjhKcRYdfy/rj5hHhT?= =?us-ascii?Q?OydXjDPbmFBRAkWoylkRomrUCWRl5NWcQDN4OOTmtZGKtr5fvvcsOSc/sDAY?= =?us-ascii?Q?gxOkCjB5rRho+53Il+q7vFvzS3KloAkA6Z6BhAu7A4LhsuRjLQ/E+qH5CVOt?= =?us-ascii?Q?aVSzHaNd9XB9Nwb4BJmen8DRkvucW5WMzJ45iErUodj4kdyhhXLW4O235LY3?= =?us-ascii?Q?0t84tRtHvS/2y2Nvs+BRhA9RZPvVHh3FaKunquHwUJLPTDzoa85al894jzan?= =?us-ascii?Q?EXUw3usfMrAw+jdwNa45P81ibaoTL6SG57lJi/og8LzgIPrL5DcoVttJmTct?= =?us-ascii?Q?oHaBLRW3woW3X2+9NbARro7DI/H3HFbix5oikyeF1qqpsD9BDWo8YhCApPs8?= =?us-ascii?Q?FdLrU88tuSx+07UetIbIBICdJ7FHbI7+oe//SGjEigD9l7dVBhKRc8tcCuL0?= =?us-ascii?Q?TG/+9HQzNjlROZ0a1q62yRP0GDw4EqhMwtmxMGwXb2qMK1ENiRWnFJXGwPrJ?= =?us-ascii?Q?OPzUmuBmYBjIj58+SpfN19vZ0XLzr5pr0ICJmGJWyL1QWZr92qL/5KuxywkH?= =?us-ascii?Q?NRX37B26l3tbGOyyrkSqVJP23DjTzTypRIMRPBihtVHEzAv7zpKf/3q7nXeg?= =?us-ascii?Q?9Ui+a95s6Dikz5uwemVi3TGFAqG45I64NGf7Wxvazp0SwhPeQbgYszVNTOoj?= =?us-ascii?Q?XUnbMPacJgoff6vdVoPFZMREead3i0iVarHK5wK9zLxMDql/QAaEcEMlrN03?= =?us-ascii?Q?AGeVr9NkRHMTlE820WDFATIW0fpA8TkXOvFmHf3HcDKl4IIm6HEFjO0NsycP?= =?us-ascii?Q?4rByNNEidjjDGVvGHUP5E2wZj9cDnFBUPrxCR6E9G7Vork/N0hBLcSPFB7nq?= =?us-ascii?Q?0vxDLVb0WvOA+8GQ4VeEjiCFfhizgTNB7R309JrTtC4DzNQ8xDJMlB+Gt4a7?= =?us-ascii?Q?Gx9mQMyZHpatqvHUy8QT9By/FbJfSknfRi/5T1nNMZEDML6Avth8tB1evR+h?= =?us-ascii?Q?qNfV4PNHdw+7r9TyEQwkKNgDc7fnRBwhPJi5GPt++cYalOlIMqB6XSEvuQXY?= =?us-ascii?Q?kIEIkpOF4xi0DnsuS+KQTesSDAv6UZhuJ9taLHcUnzvBZeePc9ycyjehJIqE?= =?us-ascii?Q?AGsfj+c1FfrvVwgrgtsTnGbZQsEqZ/CiHR90Dq8IBdHtSPjpjTDYe/98hrCM?= =?us-ascii?Q?zCWjzOubc7gWFXLnfboD92pM=3D?= X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0752; 6:H2YHrgYA9U2pQWYUJkeb6K0KkYh02aRmAyXn4MBmMvVGMzKUSm7sDowozOf8/8UrWe/0ZBbfzpTbyZDhBVl2CbX9rWgWROUspimPgaYX+xCDmsWQq2/bjbAETEHI/lI7oJU0K70seD4cZSF8a0lRaQ+MEJDiC0XpTOsdg9E4sDON2qPN/XOSQB+rgJgcXxaHqa8A6E8oF7XxaD3S5OVT1AwnYpkLnsjySPb4GjFgUl8BzhDSaCEZeZgWtkaxifR4+/YzKhkHAwLElg2hX6DIxVrDjXZMOEJDZDrkh+1Dr9SHn+JzDXhYos43Oj31Gi3ZuycBaUD6iZecwCVI8eE51J0/UX5jKo9HySh5K7Rt0OsfQux0onVTAV7eLvg5P1jZmg62hUP/0nBlmu/bi7l2Dlbc22cdAMw8OmAheQZ72oEOulADjn3yPfWx+6nPxPsZ; 5:qqSdI0ZNpnJKQ6Bx8Sp5Vc2msTwoDu4XlJsZcB83n3mU5oplLkcHWFGE647ZhGZrHb9gbkukUqRL/9+ZAi5OKb0C20sSSAx6hRQ8ovZqpZVMN/1MbXvuk4mOD6FnWWqGwlkwwkAwI5CkyGN1OpuilGOwvC6axUyk8tevSDaRCUVjH/l7bQjaM/pkWDQ87fSX; 24:ReOUB2x77ov8ZyM67L4+PPjc4HhombX6mh8SClATlsFRuFA1Qu2benU3EE0jCYBOMw/EpdH1So2YTfEJVPJoil3hdJ6R/ydDADlnEkUqQwc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0752; 7:43FzOcSjUUgwoigcEyLO/vGI+42dTYzPlfdEiz/pVRr3nvekcb3/1QmAhvufvHjDOoG2YwgCvwCVZ1GuAhPRKLarz+O5HGczF3VRkaznn8IN4TQzUSN5W6m/0tN9ABspMT65bFrFDRew2Htxt1ShjRyFQPL6f9JLc1hRvnXX+tDZvcEOnDelt+QlJJUPGB1+x+QrYgPpjRHv6dEPQ3UovRC75/YDfmVq4ERqSrm8jsvVOxGN/2y3LQPl+C2bEDFDnzIO7z2hd84Aogglt375GLkh2mwAKZPMAzjf0MMpbuauCMYd/4aIhGKNXVjdRdoQKG3DlqiUsMCvhFaVeTjuzCDgLerT+MW2FXAchzf40Aa1HwN3xFm6b4xluKZtleJAnlFs2T6GNZMNkrVLqpB3i8i8hOiWYRYs0wPNMjZyHpWyA92foQjtRJOYmi33kpYuvzUmbprX5QJXc5Xuuars+A== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Dec 2016 13:09:02.6757 (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: DM2PR0301MB0752 Subject: [dpdk-dev] [PATCH v3 04/12] eal/bus: add scan, match and insert support 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:05 -0000 When a PMD is registred, it will associate itself with a bus. A bus is responsible for 'scan' of all the devices attached to it. All the scanned devices are attached to bus specific device_list. During the probe operation, 'match' of the drivers and devices would be done. Also, rather than adding a device to tail, a new device might be added to the list (pivoted on bus) at a predefined position, for example, adding it in order of addressing. Support for this is added as '*bus_insert'. This patch also adds necessary test framework to test the scan and match callbacks. Signed-off-by: Shreyansh Jain --- app/test/test_bus.c | 265 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_common_bus.c | 15 ++ lib/librte_eal/common/include/rte_bus.h | 64 ++++++++ 3 files changed, 344 insertions(+) diff --git a/app/test/test_bus.c b/app/test/test_bus.c index 760d40a..ed95479 100644 --- a/app/test/test_bus.c +++ b/app/test/test_bus.c @@ -80,12 +80,32 @@ struct dummy_bus { struct rte_bus_list orig_bus_list = TAILQ_HEAD_INITIALIZER(orig_bus_list); +/* Forward declarations for callbacks from bus */ + +/* Bus A + * Scan would register devA1 and devA2 to bus + */ +int scan_fn_for_busA(struct rte_bus *bus); + +/* Bus B + * Scan would register devB1 and devB2 to bus + */ +int scan_fn_for_busB(struct rte_bus *bus); + +/* generic implementations wrapped around by above declarations */ +static int generic_scan_fn(struct rte_bus *bus); +static int generic_match_fn(struct rte_driver *drv, struct rte_device *dev); + struct rte_bus busA = { .name = "busA", /* "busA" */ + .scan = scan_fn_for_busA, + .match = generic_match_fn, }; struct rte_bus busB = { .name = "busB", /* "busB */ + .scan = scan_fn_for_busB, + .match = generic_match_fn, }; struct rte_driver driverA = { @@ -184,6 +204,92 @@ dump_device_tree(void) printf("------>8-------\n"); } +/* @internal + * Move over the dummy_buses and find the entry matching the bus object + * passed as argument. + * For each device in that dummy_buses list, register. + * + * @param bus + * bus to scan againt test entry + * @return + * 0 for successful scan, even if no devices are found + * !0 for any error in scanning (like, invalid bus) + */ +static int +generic_scan_fn(struct rte_bus *bus) +{ + int i = 0; + struct rte_device *dev = NULL; + struct dummy_bus *db = NULL; + + if (!bus) + return -1; + + /* Extract the device tree node using the bus passed */ + for (i = 0; dummy_buses[i].name; i++) { + if (!strcmp(dummy_buses[i].name, bus->name)) { + db = &dummy_buses[i]; + break; + } + } + + if (!db) + return -1; + + /* For all the devices in the device tree (dummy_buses), add device */ + for (i = 0; db->devices[i]; i++) { + dev = &(db->devices[i]->dev); + rte_eal_bus_add_device(bus, dev); + } + + return 0; +} + +/* @internal + * Obtain bus from driver object. Match the address of rte_device object + * with all the devices associated with that bus. + * + * Being a test function, all this does is validate that device object + * provided is available on the same bus to which driver is registered. + * + * @param drv + * driver to which matching is to be performed + * @param dev + * device object to match with driver + * @return + * 0 for successful match + * !0 for failed match + */ +static int +generic_match_fn(struct rte_driver *drv, struct rte_device *dev) +{ + struct rte_bus *bus; + struct rte_device *dev_p = NULL; + + /* Match is based entirely on address of 'dev' and 'dev_p' extracted + * from bus->device_list. + */ + + /* a driver is registered with the bus *before* the scan. */ + bus = drv->bus; + TAILQ_FOREACH(dev_p, &bus->device_list, next) { + if (dev == dev_p) + return 0; + } + + return 1; +} + +int +scan_fn_for_busA(struct rte_bus *bus) { + return generic_scan_fn(bus); +} + +int +scan_fn_for_busB(struct rte_bus *bus) { + return generic_scan_fn(bus); +} + static int test_bus_setup(void) { @@ -391,6 +497,155 @@ test_driver_unregistration_on_bus(void) } +static int +test_device_unregistration_on_bus(void) +{ + int i; + struct rte_bus *bus = NULL; + struct rte_device *dev; + + for (i = 0; dummy_buses[i].name; i++) { + bus = rte_eal_get_bus(dummy_buses[i].name); + if (!bus) { + printf("Unable to find bus (%s)\n", + dummy_buses[i].name); + return -1; + } + + /* For bus 'bus', unregister all devices */ + TAILQ_FOREACH(dev, &bus->device_list, next) { + rte_eal_bus_remove_device(dev); + } + } + + for (i = 0; dummy_buses[i].name; i++) { + bus = rte_eal_get_bus(dummy_buses[i].name); + + if (!TAILQ_EMPTY(&bus->device_list)) { + printf("Unable to remove all devices on bus (%s)\n", + bus->name); + return -1; + } + } + + /* All devices from all buses have been removed */ + printf("All devices on all buses unregistered.\n"); + dump_device_tree(); + + return 0; +} + +/* @internal + * For each bus registered, call the scan function to identify devices + * on the bus. + * + * @param void + * @return + * 0 for successful scan + * !0 for unsuccessful scan + * + */ +static int +test_bus_scan(void) +{ + int ret; + struct rte_bus *bus; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + /* Call the scan function for each bus */ + ret = bus->scan(bus); + if (ret) { + printf("Scan of buses failed.\n"); + return -1; + } + } + + printf("Scan of all buses completed.\n"); + dump_device_tree(); + + return 0; +} + +/* @internal + * Function to perform 'probe' and link devices and drivers on a bus. + * This would work over all the buses registered, and all devices and drivers + * registered with it - call match on each pair. + * Aim is to test the match_fn for each bus. + * + * @param void + * @return + * 0 for successful probe + * !0 for failure in probe + * + */ +static int +test_probe_on_bus(void) +{ + int ret = 0; + int i, j; + struct rte_bus *bus = NULL; + struct rte_device *dev = NULL; + struct rte_driver *drv = NULL; + + /* In case of this test: + * 1. for each bus in rte_bus_list + * 2. for each device in bus->device_list + * 3. for each driver in bus->driver_list + * 4. call match + * 5. link driver and device + * 6. Verify the linkage. + */ + for (i = 0; dummy_buses[i].name; i++) { + /* get bus pointer from dummy_buses itself rather than + * rte_eal_get_bus + */ + bus = dummy_buses[i].bus; + + TAILQ_FOREACH(dev, &bus->device_list, next) { + TAILQ_FOREACH(drv, &bus->driver_list, next) { + if (!bus->match) { + printf("Incorrect bus without match " + "fn: (%s).\n", bus->name); + return -1; + } + + ret = bus->match(drv, dev); + if (ret) { + printf("Device and driver don't " + "belong to same bus.\n"); + return -1; + } + dev->driver = drv; + + /* As match is generic, it always results in + * dev->drv pointing to first driver entry in + * dummy_buses[i] + */ + } + } + } + + /* Verify the linkage. All devices belonging to a dummy_buses[i] + * should have same driver (first driver entry of dummy_buses[i]) + */ + for (i = 0; dummy_buses[i].name; i++) { + drv = dummy_buses[i].drivers[0]; + + for (j = 0; dummy_buses[i].devices[j]; j++) { + dev = &(dummy_buses[i].devices[j]->dev); + if (dev->driver != drv) { + printf("Incorrect driver<->device linkage.\n"); + return -1; + } + } + } + + printf("Probe on all buses successful.\n"); + dump_device_tree(); + + return 0; +} + int test_bus(void) { @@ -407,6 +662,16 @@ test_bus(void) if (test_driver_registration_on_bus()) return -1; + if (test_bus_scan()) + return -1; + + /* Now that the devices and drivers are registered, perform probe */ + if (test_probe_on_bus()) + return -1; + + if (test_device_unregistration_on_bus()) + return -1; + if (test_driver_unregistration_on_bus()) return -1; diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index 612f64e..162a16f 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -58,6 +58,18 @@ rte_eal_bus_add_device(struct rte_bus *bus, struct rte_device *dev) dev->bus = bus; } +void +rte_eal_bus_insert_device(struct rte_bus *bus, struct rte_device *old_dev, + struct rte_device *new_dev) +{ + RTE_VERIFY(bus); + RTE_VERIFY(old_dev); + RTE_VERIFY(new_dev); + + TAILQ_INSERT_BEFORE(old_dev, new_dev, next); + new_dev->bus = bus; +} + /** @internal * Remove a device from its bus. */ @@ -132,6 +144,9 @@ rte_eal_bus_register(struct rte_bus *bus) { RTE_VERIFY(bus); RTE_VERIFY(bus->name && strlen(bus->name)); + /* A bus should mandatorily have the scan and match implemented */ + RTE_VERIFY(bus->scan); + RTE_VERIFY(bus->match); /* Initialize the driver and device list associated with the bus */ TAILQ_INIT(&(bus->driver_list)); diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index f0297a9..d1bd2e8 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -59,6 +59,49 @@ TAILQ_HEAD(rte_bus_list, rte_bus); /* Global Bus list */ extern struct rte_bus_list rte_bus_list; +/** + * Bus specific scan for devices attached on the bus. + * For each bus object, the scan would be reponsible for finding devices and + * adding them to its private device list. + * + * Successful detection of a device results in rte_device object which is + * embedded within the respective device type (rte_pci_device, for example). + * Thereafter, PCI specific bus would need to perform + * container_of(rte_pci_device) to obtain PCI device object. + * + * Scan failure of a bus is not treated as exit criteria for application. Scan + * for all other buses would still continue. + * + * A bus should mandatorily implement this method. + * + * @param bus + * Reference to the bus on which device is added + * @return + * 0 for successful scan + * !0 (<0) for unsuccessful scan with error value + */ +typedef int (*bus_scan_t)(struct rte_bus *bus); + +/** + * Bus specific match for devices and drivers which can service them. + * For each scanned device, rte_driver->probe would be called for driver + * specific initialization of the device. + * + * It is the work of each bus handler to obtain the specific device object + * using container_of (or typecasting, as a less preferred way). + * + * A bus should mandatorily implement this method. + * + * @param drv + * Driver object attached to the bus + * @param dev + * Device object which is being probed. + * @return + * 0 for successful match + * !0 for unsuccessful match + */ +typedef int (*bus_match_t)(struct rte_driver *drv, struct rte_device *dev); + struct rte_bus { TAILQ_ENTRY(rte_bus) next; /**< Next bus object in linked list */ struct rte_driver_list driver_list; @@ -66,6 +109,9 @@ struct rte_bus { struct rte_device_list device_list; /**< List of all devices on bus */ const char *name; /**< Name of the bus */ + bus_scan_t scan; /**< Scan for devices attached to bus */ + bus_match_t match; + /**< Match device with drivers associated with the bus */ }; /** @internal @@ -82,6 +128,24 @@ void rte_eal_bus_add_device(struct rte_bus *bus, struct rte_device *dev); /** @internal + * Rather than adding a device to tail, insert at a predefined location. + * This is specifically useful for update device cases, or where addition + * of devices in the list needs to be ordered (addressing, for example). + * + * @param bus + * Handle for bus on which device is to be added + * @param old_dev + * Existing rte_device object before which new device needs to be added + * @param new_dev + * Object for device to be added before old_dev + * @return + * void + */ +void +rte_eal_bus_insert_device(struct rte_bus *bus, struct rte_device *old_device, + struct rte_device *new_device); + +/** @internal * Remove a device from its bus. * * @param dev -- 2.7.4