From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-cys01nam02on0063.outbound.protection.outlook.com [104.47.37.63]) by dpdk.org (Postfix) with ESMTP id 427BC558D for ; Mon, 26 Dec 2016 13:50:45 +0100 (CET) Received: from BN6PR03CA0032.namprd03.prod.outlook.com (10.175.124.18) by CY1PR0301MB0747.namprd03.prod.outlook.com (10.160.159.153) 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:43 +0000 Received: from BN1BFFO11FD030.protection.gbl (2a01:111:f400:7c10::1:166) by BN6PR03CA0032.outlook.office365.com (2603:10b6:404:10c::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:42 +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 BN1BFFO11FD030.mail.protection.outlook.com (10.58.144.93) 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:42 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id uBQCl90L011201; Mon, 26 Dec 2016 05:50:39 -0700 From: Shreyansh Jain To: CC: , , Shreyansh Jain Date: Mon, 26 Dec 2016 18:20:35 +0530 Message-ID: <1482756644-13726-4-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: 131272302427866732; (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)(39410400002)(39400400002)(39850400002)(39450400003)(39860400002)(39840400002)(39380400002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(356003)(2906002)(5890100001)(47776003)(106466001)(4326007)(305945005)(105606002)(8936002)(81166006)(8676002)(92566002)(81156014)(50466002)(8656002)(2351001)(48376002)(86362001)(36756003)(50986999)(189998001)(33646002)(110136003)(69596002)(104016004)(76176999)(5003940100001)(68736007)(626004)(85426001)(50226002)(77096006)(6916009)(38730400001)(5660300001)(2950100002)(6666003)(97736004)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR0301MB0747; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD030; 1:/wdp5/JXfS8cBZvxXXAe+oH25cDQiFl7Z9MFcKHZBjicbfG/f+W83sU2c6EBy+eda3iYSIyAIlH6HdkBsnrjosid8XTeZAwOW3wi41RNtBWS/Y582bYTxjy4PZDERNtyNqMFYgzdeGLQU2RYwk/4TWmNgAuQqbauSaYUUz4a9BqfGRm9umYLR8SzjRwawTY6MferaFzA80/EaB0LiTHE+vx6OHZ5kKAnpU2CKQ8L1AHVg4TXPlseP7Dk8Cv394h0ao9Pse42K4nVw7Dp0ullskGGj42vAfpZfeoCh/ob2bBJkeajPmBhVo9z8xD9yJncppCxN7vU74H8YZgbaJkNh5mZ6pg/FxaskC+0pnsnWjQC1Occo23RkRicn8lwtfwjyCyDK4JOnb8KW1qVO3fENEviwszZwwHt0okJRI6tfyrpQqSHuF+D8OelsgOv7yBijbJ9WsmUj+xBzC/9ipMw2tNJ95tywMZH1utH0a+DbyrOhFm6DRhoj8BeBqT33kgKkvbdk0yqlXCXkAeeu0TLyWAznXzPjHLTQ1UdHt+I3Bas2yPHFz4SDSwLcDj8lXQDFxxAaKSrA5bJQgk8kJw4T0jXz/xXh406p2ki031dNPbPegiElF5cqDdj3c5JDknEUSeVEs7i9uNlmPN54ZIshkQO2HRrpnlr54dpLUw1RBf/YZnwnOabojGiGG6OIhRNcW6umbIVHhpPrRiEto1GvT5x4t5m8GBBkWESUIbcLDQ= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 7aab6606-8a73-4442-c3aa-08d42d8dcd81 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:CY1PR0301MB0747; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0747; 3:rjVjc9pSwWtnXebSn/rvVUtDIWww7888M5QKnHk2TODf8GpPC8R5XXEdYhQVEp4CKjJn4OOaF2WjLV2yxnD3ikdVkWGEDKG6H2qYcaIfyp+v65wLvpTo4+0FPYfGxytSBMgTZvMl+AB374okIjNBo1Zu+nfQ8nxPmn5SdPRhb3Njk6k9cTuPDp2nGG624BRYUc/PhD0mYZrppRxW+7wo/WMNxjENjwEdnnJcFEZpWXd02C7u1L98PZshDsswYSITmTledcABqgKlxR2Qd3XH9wcRessNNjcPQgcE70lVt3H/BfoAP2prXp5n4xupIJ+6IJWZgjCmpvkyi/fGUhaCseR4ckkZXNMldp6YN2F94gY=; 25:n3k5toSWmHAONtzGVs+eNZjaDq13gNiu77VNU5/oHWAywyLgagCwYblMbEOD4KcdN+r2TZTrvNU0ZvFFFocZ/+FaGJaqXAsvW/E3AeP3T9laxB/9aRhFGaZqrKwBgxqLDn+6UtXCRIE5G81OOvRot3szrCXe9gxxNKjR2G3sD3wjZ6RiaKgNyRzfycHC+2Eun9sNBqKbE1kboCwR74vqwtc54g9Iu+ENmuqQSnH1G1WlLhkCeJEFuKuQaLosBHC46Rxe1wLtNVEq/UIS21snRQsFapDrcRgm0Qh3chCXwnnuEAauTlSC2JSysVvyWVKLTcsIt6oWY+Hx2p5OwippBOFUL0ThuZmgnGDvwpz71IKXfRxXLMHPyG95peEV//S8md2Cutx7gAyACn8mAQu4JkvPFdSNds5SJxnkVKA2/iroXHF4Wp/o1V7ZkyJfvTfaJd51pHL+wDj99DfbyU/BFg== X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0747; 31:ccQ1Nv1g4X7fZI5SVRBmbwKXB7l18hW8NvnuO4AfZBZZNBJV8Amon3WoTKzIFe93sGIsH3kmaNtjIZHZxBhYrs7JUpj91lwrsga1U3KBrBAldjhohQ541nTviyU/gS1gHvxXeUMCia//QppQEIbpu3msTufXdWdVZWOkwEUdRJSOkjL3tZiEbKqDVbUQEI60LbSgHeg5la9IM9n+hOF8q46NQnrWSj6DGkxSkQJ9elMov3DkqyAwtkfVYe1nxMRj+G4PUVLMPj1Sir6es+OO2uk6ccNWPqq5WTL/Dp6hbYFjTEP5L0Slushy3/XJWNnI 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:CY1PR0301MB0747; BCL:0; PCL:0; RULEID:(400006); SRVR:CY1PR0301MB0747; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0747; 4:UkDiuHAomjkizeTfNY/0QqHJzwyRhftUJUam5oqPcAX3MIuPyXk2sZWybbpGBOxLzB0wx4njbbSHLriSNaTs66c/P734poMEVFDXZ2VW0126GF1dGHsz3qEiWR05M7n/CVUS+5s3M/l4Xu8s5A/weyP/mdt6GNJXYhdSHPRZwcZ+TaQ89ca4DzxAczLW2ytTL5+P1L6uSR5Kzmn1u30Iho7x1DZrk0Fd/XSiuLCotSxsp91qNARTUJ168mwUToEU5x7LlAHVskO52fVIeiMxzkF4UKFpCrY7ybYqbL9n2xXdGv4wlaOj9pYm78JlK/XRvQ8DsbKjjn0I8HwW9U95PPpM+T01+70zrffsDvnaeP0ghxvRYSbSpDnpSGAfiJ6puvlO1B/yw/QX2WT9cHcZj4bec5INaY3Yi6Fd3PcIu8nNBLW3iRFAOOqjr2d+YjYCK4ClmMzUt6+OVQahcfIgoNUGgC9YtjK3q5FPaH51xqHoKV4KUrbffus1a0MlIz42UM52KjJp+uEfIdhsaCGYq1hKV2ka+9lgh31/3+CjbYLypScffJjO55dWE14kk71F1OmFQazznRbS6y7RhAWHSWPivcS/jQFqojvjUuFicQGtvy9q72+swhUg3ozkObe1/McU9YZSJD8HJ8WIqsXdI7oia/fvFY1fJLkA2yf7GsZ5NLf6nHJwjnF/NGwau+mwUAurqjI/RGu4dO1RFDxDqFVVHhctezx5dZDpBIf1osA0JtvdnqJfHDbu+0MdtJSe X-Forefront-PRVS: 016885DD9B X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR0301MB0747; 23:ahDr+L5XNQUpUk2+8giF9oXSuM0bBkg0XDYoRVz?= =?us-ascii?Q?f1QmW3yd+LdSgLrS4X4Gina5EewQpYw+IbZjVx8NDQBQ7wttKTUtEF2igcMb?= =?us-ascii?Q?m4SpwGzVbq9C7tNHnOgUZ9li2/hlYk4W+UJ8E4FSD/yr+athoFyXrA+NieNE?= =?us-ascii?Q?YYJAahGDF7Xtw+kCSUHXSlf1cdEerLKHeYfex/px/s7I1J/C210rd/E9gvEZ?= =?us-ascii?Q?8u7vF5kWctChmIzRhSvCCHIgrRee9jVuPh1e8gNh9UGSNZHNTcyjNTyBBDYa?= =?us-ascii?Q?WWU54EVVPbbOrKQ8vOaR31yppb4fXI4hYT72RknDlkgi3/2iHAkVlVS+kIjw?= =?us-ascii?Q?tZejAPMq4iLIni1/DlGZbbnQ5ixBKWoI1TpvQfd4vmS8QBhDHEtlFtNvGavc?= =?us-ascii?Q?bl3VCtRnAVCkPBQ55alxdMB+xg2Fo8CdhlddO2kT9llXH+03LNpC+swfdYLm?= =?us-ascii?Q?osAADwc2DwzTGh1I1i390YWld8NgXId3d6nQBbNEZGVW3fG5M4NGod2DmHlG?= =?us-ascii?Q?3+ezcy6YjZGutYYKUfrrQb+/8smeCzRANMK2XIBgHbAgGnjf4lC0Sas9loC7?= =?us-ascii?Q?DKIBooQMTqpHBngK5+XdiXqzuxEWgfma0V+4xp5W/u3ObCPVFeyNM30xnF/M?= =?us-ascii?Q?gUGWu5Zq0o9UXjC1CgzOYuim0i5Vep/smtmJoH8bIVklT3/WpnD4tagijwCO?= =?us-ascii?Q?TNQM6w09t0jBQdcpkB47civCjO/gbstI7KXlZ/KMODPfHeaEbT9G2Ss4Jutg?= =?us-ascii?Q?AaXEj2KW4cUQIeaz1V1GyBhLKUvM7rm/TL3kfB9F0YRR6J0PPeso2YClGror?= =?us-ascii?Q?X5kthXQ2T14SztsTIRXdha+pWN1RT2ZJIz+NETIzkUikbLtTn1+4XKtlC8F4?= =?us-ascii?Q?vZZz02ZEI8GsVaUBD3KmdSiNB1tJCi0f17tPQuASPDH360FA0raX7qzBgv5P?= =?us-ascii?Q?ClPZsh0CShQoVDSayK6nMUHVAh6QQsBVNzrJxhcffamzZ7jU/TpLsNHGgorP?= =?us-ascii?Q?45+DXXze01DiLAKscbMOfyb/1oYYhRdEuwn3G/O4tfdK+upJIqkEsQCRO353?= =?us-ascii?Q?47JVHma4zBb39rOpR28Ve2RidDu1SUkX9nMZ6UnauuVck7IM7/xHLRYRhxSn?= =?us-ascii?Q?h9nvBf+jsSq6TqMNmy71sS6S9w5kEcPBziKNQKM+Yyztd7ecYTWWM+BaUuUu?= =?us-ascii?Q?B63r//7Fx8U/OxZq6B3Zpwo8mrm9JuLK5YfTrBMpLeUBELeDhxJqRz49Wd0+?= =?us-ascii?Q?JT1J750Gez8XYZruGu4PDOS5HvlarMylBMLAbCd+ZVSvOgMBsn6ViTVAzYN1?= =?us-ascii?Q?BJmXzdrV0vRL8QJxbmY7kl/uX8B9rPrOSR7vEPQ22GAHX?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0747; 6:4Q4Aq6gQkJhfz/KOkJbKkYRobkspdpVIQ6C73LwqxkP2g97tu/IqolTTk4nVSH54iHTVVmMNA0ul8sfGmJupMTf6XRlTlPsEzs4eAFwTdvVHkpqlle+6lri46pN2J9pTYq2C/DN68/cryP7bJWhypRIMhPHL92rrehH0FnsTj/yHYwVShkjduMvsRATrd19Yj0ABR8t3VA5hXuGWjpLsiKMLF01PV1EyLh4lvG7bqpheSVpKhzfwFayWBXsM2w4cPIuxME6xSDNgGBZs79O/zKxYsUhBmnqdfnch88/dEQ84x/IrMozjiStjQlEPaNaSzo2uoNiHfHDDPXX06EwKO8QP4K9mEYOcSl1VRW0rWgfak0zI7nEraoCl/NRXEgJYcN8z3VYo0debixN1QpgboEaW4eKxLr8LcE4K8g7IlZh2A8KPCMOFmmXpIRmNegUd; 5:v2qNK7TaebTUyt18oOIc/O/kIZlDLiDbxGndkEoBwHVzsSGhB71VIC5svs2TmQU29qw5nilAc3biXTlWiJ38FQv4a4LOiYABoWWS+TAiVMnth3gMfKhWJUmNCIXm98GsQDQNOhLyFrrdMGjYhoHMKlL2AENTu+DMHlqxxk7Ab+WmtVLTHxzMrU4FAHmggRbG; 24:sxyt/Nh2LkjhSeGHdvfmtsCA+T4VOCb8p85E1LBAdZiKM7B26j1Cbk7TFGS/x+MEqJUvHvmLYS5vJr/0mkUnC/p0cSPezmgDj/MtQkpHRoo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0747; 7:3KHFtL054ySmGk2nywX7u2ZeAYDY/fZ4CjE7CMyx82F563rDPCYdXX5X2HTjsOP35wvpES/+D1xKiqXkdhBYp/wG+JqVWrvpydSYYCsen6fkYg+mA989tsOlNH5QaV5rO1v4uqLe8HDYeQKMi7sBZA0coJWLXkQn5g5+QW5tLs2rk59gXHz0kksySTQUsDCuU0Zo2U9iq9cbM92nSoCegMrzjUf6nr3JdctFMmHFrJrnKXy7Gj18SaN1cmcZk5sTsNOsKnYDBYc7PPZSK3wowEzIwb1/du6aJXBX1FYFJYfaqlHGVjNLOCHYljK83+3lf80W+K2WyjZrk1o4ApRjvGncrTm9zhsUCaw7gn93vkMroXy+gr3sa5h2hLR82gXDNyO1aQuu7/FRuzt7Az24+90XHR2rwyPayXHR78j4uCdc/L1DHgRlmn2Qd7KhuSkGFny6iDne/2jzA2KmjGhEuQ== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2016 12:50:42.5370 (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: CY1PR0301MB0747 Subject: [dpdk-dev] [PATCH v4 03/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: Mon, 26 Dec 2016 12:50:46 -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 60950d3..98250c8 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) { @@ -392,6 +498,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_bus_get(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_bus_get(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_bus_get + */ + 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) { @@ -408,6 +663,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 01730f8..5a5ae75 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. */ @@ -130,6 +142,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 ad2873c..da76db3 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -60,6 +60,49 @@ TAILQ_HEAD(rte_bus_list, rte_bus); 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); + +/** * A structure describing a generic bus. */ struct rte_bus { @@ -69,6 +112,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 @@ -85,6 +131,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