From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0081.outbound.protection.outlook.com [104.47.41.81]) by dpdk.org (Postfix) with ESMTP id 86F0DBB28 for ; Fri, 28 Oct 2016 14:30:56 +0200 (CEST) Received: from DM5PR03CA0008.namprd03.prod.outlook.com (10.175.104.18) by BN3PR03MB2371.namprd03.prod.outlook.com (10.166.75.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.693.12; Fri, 28 Oct 2016 12:30:55 +0000 Received: from BY2FFO11FD054.protection.gbl (2a01:111:f400:7c0c::189) by DM5PR03CA0008.outlook.office365.com (2603:10b6:3:118::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.679.12 via Frontend Transport; Fri, 28 Oct 2016 12:30:54 +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 BY2FFO11FD054.mail.protection.outlook.com (10.1.15.191) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.679.5 via Frontend Transport; Fri, 28 Oct 2016 12:30:54 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u9SCPEMN019399; Fri, 28 Oct 2016 05:30:51 -0700 From: Shreyansh Jain To: Date: Fri, 28 Oct 2016 17:56:28 +0530 Message-ID: <1477657598-826-12-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477657598-826-1-git-send-email-shreyansh.jain@nxp.com> References: <1477581467-12588-1-git-send-email-shreyansh.jain@nxp.com> <1477657598-826-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131221314545006249; (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)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(356003)(68736007)(8666005)(7846002)(97736004)(2906002)(305945005)(47776003)(81156014)(81166006)(92566002)(8676002)(5890100001)(105606002)(106466001)(586003)(77096005)(86362001)(8936002)(19580395003)(19580405001)(4326007)(50226002)(2950100002)(229853001)(2351001)(33646002)(5003940100001)(85426001)(48376002)(50466002)(87936001)(36756003)(6916009)(104016004)(110136003)(6666003)(626004)(5660300001)(50986999)(11100500001)(76176999)(189998001)(7059030)(473944003); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR03MB2371; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD054; 1:YZSkUkCmVSwb4Q3lxLojCuhh63gCnwo51XMcGlERHLMvoAWlohtM3Z49uDhFHs/bMRCdg64TE90UkM4rWxbvcO2ZRUTm0rVSL1gmOS1Gz8X6QjYLtrDZb9aXnubEZTHHzPCKHdDha9I00MJmN+M3I28uOtD8n/noBGkOF4VLZGufhGesbfQHJCAIuuQ1iQZxDof1js/JVIInZOQzf0OhDoqzDdnDlXNb0xFlq4VVcpOkgZTU5h9Fg333Qs2v0vUQe79iB+t/OjEGNV5zni/Zq4K1mhP+YmjXPzJd5P6ItJfxJpVCbjinpy/mDFdaQtfT3gdFLT/JXcr4687t5WfS7FSTJaIjk0D0rPX4SpZJwTFem17t0keU2yKhoUtlDsK7aSZjJbcdIqIxOKqZz3ux9W2Zf3CLNNI9WiggKXClo82zhRtE1L/4aK80AHfUGeEE901yHjYG6MsDNxue+fw1kua8z9NZuAn8A0TVJGi5zeCMaxwzlzmDGb8F6vtJOe0+YB/xSv4TMJ0DmW6ypEwC9Ob077Za1vEPI/kSA8L0Z90bLA6gO/v3iRGPWFYkLcRU8rB4aimAOPLRc9AuM1QDCZvMApan6PXwJ4bCOwldzkNRuNvQtk6qbxaWz65Oc5twNx7Zf6Dxt4U1HjVpQPCkYzKtXuj+EqOHaXSB+xC0or+HZgraJFBOxGgw8kyYpox7svdrwnyAHZctMlV8vorYxVjQxzvZZZPZm4cb9Nd6sns= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: ad6bc4bb-47eb-47c4-2bb9-08d3ff2e42ce X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2371; 2:/gWXnpaBwFyQHkp8vdvUR+oSzoPVPN/PagBz037dUdRD9sTOyJGZevcndVd2KdQA68YsEQe/0Q2bWwcGgkLVHEsNKiFexo17V9RIysQdaAuq4yR5KPQDaaA2DzevYwrMD11yh1Rpmb60AijyR4JM5CcPD9lKBGGDk1TNkC0r7JwourOLjusTWpMm2pkT2v41XKaNfz7ElLaBcnDaL5AlBQ==; 3:xA0zykZDMpMErjgulTrGBdC4QmCMtS0rDZOBOU+nqW1/BhPTQAe0PIWLIg70rzzlqQLW/1/EDniXkqa7ANwpu64Oh8S5IbBs+UNQlNu2utRaDR+N8kg4F1FKtHqq4qJYpK24braWb+2fOxjUiCLc+QS8EOODy/wYr6rt6aBeHIQ6FECrtJHtFQwrMkyEpNDxmmB67ah4XUbBGiRVJFZD+nnLc2kYYL6hHaDZh6ATAEK/EpXhPAHtNydhO7vTnVnk X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR03MB2371; X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2371; 25:PCsK7uJL4UJimeNKF5Yz68pVzl3LtIOhXLLoYoe8m2XaLkR7KXABCS//Dm576fwgBHWjG8lPCZ+rk7I/w8jxkQ5hN2H2VHhX96GcI5B0Cwywa5DNcxp+2GpMIsrPYYMl8SCEmtm+RdtTjVeK4k7rp7YHiraJzvyMsftdFMkIdj+QbVV++37UiUrmEdCi9dG7b0QOjQucc4AIrOV716dyMzXJ29mbXeUSOpb2JILva6g91idrhTHQm9Zu/8PKL/XOW/8iKZd7ykesxv4ZaPqzjpxc3kBhZfTUna5CPLrmk6fAOUteARJmz/bXNJTSXrxvnByb4rZxc/ErMPiogjTxpNr4X0yPT7qZnZR12XR8Bfxs88kngkyb6aw+cxEa24cCE4lgZ4S5YwfNLwevKJsou6qh39wP/j1qpVWO7B/NO/UT3fJO6RruTInqoLagIZq7kByZhqy0qPTe+Xv+tElw3w==; 31:0gVt38QlYiVqhupsfsBKNA9NV0OIy3ib6nZut0zrIrAd5LGaVYX6sDG6YU0HHQgSsnKb8NStUgtfVStBrsa0cRgtVzWjKFmwhC+U92nDjDrIDDuas+xKh/y011KcjOmxdOjWvUV3kWDSkaDOOXheg7x6w1oIztrU0gJBIcVLx0aadHPed83IuQ1uYJgfoxRA8Y1Ik1PCHjvgkruwZVDdlKjDLTuXH6PK66JimKHUmW772N+qYyLWLf60/48Jxt5aJoHWvCX4R7YkQmIDEzkOcUl6c8Dzq09lztriKN8pfIk= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(13024025)(13018025)(13023025)(13017025)(13015025)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:BN3PR03MB2371; BCL:0; PCL:0; RULEID:(400006); SRVR:BN3PR03MB2371; X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2371; 4:trYa1b4JbJJo6fIp0Mg2i65aADh37yRgfJvRJMH962q6Y7KSv9HjSW9X5fOn/EifddIsxoX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+?= X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2371; 6:n7K+SQ0DV3Udh6NtXJrzRPvy31XWJaufLbfuJmlD6fXADLvNQnHUgJyvNrGN7qED/vVoQNHQ2KXNI5DyWUecmKvAlidO069VqP/Y888lhYmSMIPo82QiXQOFieH92V3F9GBGxLVkBWJu6PeK6Y0B4A9rTgZ5LTRJB1qZFScCpI+yGKH/gOffU5fmo0TDawZnxg8+eNwk2WJ+s72NbXsfKIWpcMpxTrFN1tLlrqC8QhP88kGyGA3jFrAg6QhoeikaoGSR8iB4zi9yGdxu70ff1u9iZYk6MCxCTDKk7uuTQAQHqhijRQep4vMlK07fX4NV; 5:lMae3vg5oFtrfyUix98qfEYQhMXirRfRl8VDiavUBiQ8kV71H3Oi6R45EaadvFZjW7HqPmZ/cGtD0SwedrIynvOEElSErHsLvF7UzivpPqVr5KqGus95BT5NG18BFXkGlRBU3SfMIeKCERTJdmXXaNHPj67TrXLnY7jzYtA7V1DxACQWN4kMZb1beBNMy3LT; 24:BiNs8Jc4WW1g1F7pI2qVwhk7K01umw2+Ulx4PX3R3eiTB5NMpMEHnt8E30gXXE86xIRvJJFFcRzi+IawRj/Y7J8SDVPGxtjSEC5l3d5iDEA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2371; 7:uRFky6Yst1GzIAKDPgzvEbmtSPjRPVHzn4gzXk9M4yQEKXix0hFNLFHDZqtKYnuWhW6Kbttia9Xd1WO3y7z+aP/KU4azwn5iAcUyRw2dT6aq/cla7YoB5/CnfUN5tNSy8vF7b+fSqQd4Q4mb3yqPl+c22fY/rQbNILpciPgQTLrl9vLkwLiLDKOIk/QH0rNBDxoNn9H3U7nT5Ipg1ax86DF2zT8QiX+vTUwlfR2JzPKd0AomvBUKACQrQ2TFgU5KBxewl2ENrquMd81bvtMUnN0OcE9WXPYitn6u1yenkNjsZwyasKGYtAxBCpRn1TkLfj+T3Z0FaQhXHap0iBSIUwSvxdYpSOWIU+Qk06FLdNg= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2016 12:30:54.1730 (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: BN3PR03MB2371 Cc: Shreyansh Jain , thomas.monjalon@6wind.com, viktorin@rehivetech.com Subject: [dpdk-dev] [PATCH v7 11/21] eal/soc: implement probing of drivers X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Oct 2016 12:30:57 -0000 Each SoC PMD registers a set of callback for scanning its own bus/infra and matching devices to drivers when probe is called. This patch introduces the infra for calls to SoC scan on rte_eal_soc_init() and match on rte_eal_soc_probe(). Patch also adds test case for scan and probe. Signed-off-by: Jan Viktorin Signed-off-by: Shreyansh Jain Signed-off-by: Hemant Agrawal -- v4: - Update test_soc for descriptive test function names - Comments over test functions - devinit and devuninint --> probe/remove - RTE_VERIFY at some places --- app/test/test_soc.c | 205 ++++++++++++++++++++++- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 4 + lib/librte_eal/common/eal_common_soc.c | 213 +++++++++++++++++++++++- lib/librte_eal/common/include/rte_soc.h | 75 ++++++++- lib/librte_eal/linuxapp/eal/eal.c | 5 + lib/librte_eal/linuxapp/eal/eal_soc.c | 21 ++- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 4 + 7 files changed, 519 insertions(+), 8 deletions(-) diff --git a/app/test/test_soc.c b/app/test/test_soc.c index ac03e64..b587d5e 100644 --- a/app/test/test_soc.c +++ b/app/test/test_soc.c @@ -87,14 +87,65 @@ static int test_compare_addr(void) */ struct test_wrapper { struct rte_soc_driver soc_drv; + struct rte_soc_device soc_dev; }; +static int empty_pmd0_probe(struct rte_soc_driver *drv, + struct rte_soc_device *dev); +static int empty_pmd0_remove(struct rte_soc_device *dev); + +static void always_find_dev0_cb(void); +static int match_dev0_by_name(struct rte_soc_driver *drv, + struct rte_soc_device *dev); + +static void always_find_dev1_cb(void); +static int match_dev1_by_name(struct rte_soc_driver *drv, + struct rte_soc_device *dev); + +/** + * Dummy probe handler for PMD driver 'pmd0'. + * + * @param drv + * driver object + * @param dev + * device object + * @return + * 0 on success + */ +static int +empty_pmd0_probe(struct rte_soc_driver *drv __rte_unused, + struct rte_soc_device *dev __rte_unused) +{ + return 0; +} + +/** + * Remove handler for PMD driver 'pmd0'. + * + * @param dev + * device to remove + * @return + * 0 on success + */ +static int +empty_pmd0_remove(struct rte_soc_device *dev) +{ + /* Release the memory associated with dev->addr.name */ + free(dev->addr.name); + + return 0; +} + struct test_wrapper empty_pmd0 = { .soc_drv = { .driver = { .name = "empty_pmd0" }, - }, + .probe = empty_pmd0_probe, + .remove = empty_pmd0_remove, + .scan_fn = always_find_dev0_cb, + .match_fn = match_dev0_by_name, + } }; struct test_wrapper empty_pmd1 = { @@ -102,9 +153,87 @@ struct test_wrapper empty_pmd1 = { .driver = { .name = "empty_pmd1" }, + .scan_fn = always_find_dev1_cb, + .match_fn = match_dev1_by_name, }, }; +/** + * Bus scan by PMD 'pmd0' for adding device 'dev0' + * + * @param void + * @return void + */ +static void +always_find_dev0_cb(void) +{ + /* SoC's scan would scan devices on its bus and add to + * soc_device_list + */ + empty_pmd0.soc_dev.addr.name = strdup("empty_pmd0_dev"); + + TAILQ_INSERT_TAIL(&soc_device_list, &empty_pmd0.soc_dev, next); +} + +/** + * Match device 'dev0' with driver PMD pmd0 + * + * @param drv + * Driver with this matching needs to be done; unused here + * @param dev + * device to be matched against driver + * @return + * 0 on successful matched + * 1 if driver<=>device don't match + */ +static int +match_dev0_by_name(struct rte_soc_driver *drv __rte_unused, + struct rte_soc_device *dev) +{ + if (!dev->addr.name || strcmp(dev->addr.name, "empty_pmd0_dev")) + return 0; + + return 1; +} + +/** + * Bus scan by PMD 'pmd0' for adding device 'dev1' + * + * @param void + * @return void + */ +static void +always_find_dev1_cb(void) +{ + /* SoC's scan would scan devices on its bus and add to + * soc_device_list + */ + empty_pmd0.soc_dev.addr.name = strdup("empty_pmd1_dev"); + + TAILQ_INSERT_TAIL(&soc_device_list, &empty_pmd1.soc_dev, next); +} + +/** + * Match device 'dev1' with driver PMD pmd0 + * + * @param drv + * Driver with this matching needs to be done; unused here + * @param dev + * device to be matched against driver + * @return + * 0 on successful matched + * 1 if driver<=>device don't match + */ +static int +match_dev1_by_name(struct rte_soc_driver *drv __rte_unused, + struct rte_soc_device *dev) +{ + if (!dev->addr.name || strcmp(dev->addr.name, "empty_pmd1_dev")) + return 0; + + return 1; +} + static int count_registered_socdrvs(void) { @@ -148,13 +277,68 @@ test_register_unregister(void) return 0; } +/* Test Probe (scan and match) functionality */ +static int +test_soc_scan_and_match(void) +{ + int drv_count = 0; + struct rte_soc_driver *drv; + + /* Registering dummy drivers */ + rte_eal_soc_register(&empty_pmd0.soc_drv); + rte_eal_soc_register(&empty_pmd1.soc_drv); + /* Assuming that test_register_unregister is working, not verifying + * that drivers are indeed registered + */ + + /* rte_eal_soc_init is called by rte_eal_init, which in turn calls the + * scan_fn of each driver. + */ + TAILQ_FOREACH(drv, &soc_driver_list, next) { + if (drv && drv->scan_fn) + drv->scan_fn(); + drv_count++; + } + + /* rte_eal_init() would perform other inits here */ + + /* Probe would link the SoC devices<=>drivers */ + rte_eal_soc_probe(); + + /* Unregistering dummy drivers */ + rte_eal_soc_unregister(&empty_pmd0.soc_drv); + rte_eal_soc_unregister(&empty_pmd1.soc_drv); + + /* Verify the Unregistering has removed the driver from list */ + TAILQ_FOREACH(drv, &soc_driver_list, next) { + if (drv) + drv_count--; + } + + free(empty_pmd0.soc_dev.addr.name); + + /* If drv_count is anything other than 0, Unregistering failed */ + if (drv_count) { + printf("%s has failed\n", __func__); + return 1; + } + + printf("%s has been successful\n", __func__); + return 0; +} + /* save real devices and drivers until the tests finishes */ struct soc_driver_list real_soc_driver_list = TAILQ_HEAD_INITIALIZER(real_soc_driver_list); +/* save real devices and drivers until the tests finishes */ +struct soc_device_list real_soc_device_list = + TAILQ_HEAD_INITIALIZER(real_soc_device_list); + static int test_soc_setup(void) { struct rte_soc_driver *drv; + struct rte_soc_device *dev; /* no real drivers for the test */ while (!TAILQ_EMPTY(&soc_driver_list)) { @@ -163,12 +347,20 @@ static int test_soc_setup(void) TAILQ_INSERT_TAIL(&real_soc_driver_list, drv, next); } + /* And, no real devices for the test */ + while (!TAILQ_EMPTY(&soc_device_list)) { + dev = TAILQ_FIRST(&soc_device_list); + TAILQ_REMOVE(&soc_device_list, dev, next); + TAILQ_INSERT_TAIL(&real_soc_device_list, dev, next); + } + return 0; } static int test_soc_cleanup(void) { struct rte_soc_driver *drv; + struct rte_soc_device *dev; /* bring back real drivers after the test */ while (!TAILQ_EMPTY(&real_soc_driver_list)) { @@ -177,6 +369,13 @@ static int test_soc_cleanup(void) rte_eal_soc_register(drv); } + /* And, bring back real devices after the test */ + while (!TAILQ_EMPTY(&real_soc_device_list)) { + dev = TAILQ_FIRST(&real_soc_device_list); + TAILQ_REMOVE(&real_soc_device_list, dev, next); + TAILQ_INSERT_TAIL(&soc_device_list, dev, next); + } + return 0; } @@ -192,6 +391,10 @@ test_soc(void) if (test_register_unregister()) return -1; + /* Assuming test_register_unregister has succeeded */ + if (test_soc_scan_and_match()) + return -1; + if (test_soc_cleanup()) return -1; diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 86e3cfd..dfbb1ac 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -171,7 +171,11 @@ DPDK_16.11 { rte_eal_dev_attach; rte_eal_dev_detach; rte_eal_map_resource; + rte_eal_soc_detach; rte_eal_soc_dump; + rte_eal_soc_match; + rte_eal_soc_probe; + rte_eal_soc_probe_one; rte_eal_soc_register; rte_eal_soc_unregister; rte_eal_unmap_resource; diff --git a/lib/librte_eal/common/eal_common_soc.c b/lib/librte_eal/common/eal_common_soc.c index 5dcddc5..256cef8 100644 --- a/lib/librte_eal/common/eal_common_soc.c +++ b/lib/librte_eal/common/eal_common_soc.c @@ -36,6 +36,8 @@ #include #include +#include +#include #include "eal_private.h" @@ -45,6 +47,208 @@ struct soc_driver_list soc_driver_list = struct soc_device_list soc_device_list = TAILQ_HEAD_INITIALIZER(soc_device_list); +int +rte_eal_soc_match_compat(struct rte_soc_driver *drv, + struct rte_soc_device *dev) +{ + int i, j; + + RTE_VERIFY(drv != NULL && drv->id_table != NULL); + RTE_VERIFY(dev != NULL && dev->id != NULL); + + for (i = 0; drv->id_table[i].compatible; ++i) { + const char *drv_compat = drv->id_table[i].compatible; + + for (j = 0; dev->id[j].compatible; ++j) { + const char *dev_compat = dev->id[j].compatible; + + if (!strcmp(drv_compat, dev_compat)) + return 0; + } + } + + return 1; +} + +static int +rte_eal_soc_probe_one_driver(struct rte_soc_driver *drv, + struct rte_soc_device *dev) +{ + int ret = 1; + + RTE_VERIFY(drv->match_fn); + + ret = drv->match_fn(drv, dev); + if (ret) { + RTE_LOG(DEBUG, EAL, + " match function failed, skipping\n"); + return ret; + } + + dev->driver = drv; + RTE_VERIFY(drv->probe != NULL); + return drv->probe(drv, dev); +} + +static int +soc_probe_all_drivers(struct rte_soc_device *dev) +{ + struct rte_soc_driver *drv = NULL; + int rc = 0; + + if (dev == NULL) + return -1; + + TAILQ_FOREACH(drv, &soc_driver_list, next) { + rc = rte_eal_soc_probe_one_driver(drv, dev); + if (rc < 0) + /* negative value is an error */ + return -1; + if (rc > 0) + /* positive value means driver doesn't support it */ + continue; + return 0; + } + return 1; +} + +/* If the IDs match, call the remove() function of the driver. */ +static int +rte_eal_soc_detach_dev(struct rte_soc_driver *drv, + struct rte_soc_device *dev) +{ + int ret; + + if ((drv == NULL) || (dev == NULL)) + return -EINVAL; + + ret = drv->match_fn(drv, dev); + if (ret) { + RTE_LOG(DEBUG, EAL, " driver (%s) didn't match device (%s)\n", + drv->driver.name, dev->addr.name); + return ret; + } + + RTE_LOG(DEBUG, EAL, "SoC device %s\n", + dev->addr.name); + + RTE_LOG(DEBUG, EAL, " remove driver: %s\n", drv->driver.name); + + if (drv->remove && (drv->remove(dev) < 0)) + return -1; /* negative value is an error */ + + /* clear driver structure */ + dev->driver = NULL; + + return 0; +} + +/* + * Call the remove() function of all registered drivers for the device. + * + * @param dev + * Device for which detach is to be performed + * @return + * 0 when successful + * -1 if deinitialization fails + * 1 if no driver is found for this device. + */ +static int +soc_detach_all_drivers(struct rte_soc_device *dev) +{ + struct rte_soc_driver *dr = NULL; + int rc = 0; + + if (dev == NULL) + return -1; + + TAILQ_FOREACH(dr, &soc_driver_list, next) { + rc = rte_eal_soc_detach_dev(dr, dev); + if (rc < 0) + /* negative value is an error */ + return -1; + if (rc > 0) + /* positive value means driver doesn't support it */ + continue; + return 0; + } + return 1; +} + +int +rte_eal_soc_detach(const struct rte_soc_addr *addr) +{ + struct rte_soc_device *dev = NULL; + int ret = 0; + + if (addr == NULL) + return -1; + + TAILQ_FOREACH(dev, &soc_device_list, next) { + if (rte_eal_compare_soc_addr(&dev->addr, addr)) + continue; + + ret = soc_detach_all_drivers(dev); + if (ret < 0) + goto err_return; + + TAILQ_REMOVE(&soc_device_list, dev, next); + return 0; + } + return -1; + +err_return: + RTE_LOG(WARNING, EAL, "Requested device %s cannot be used\n", + dev->addr.name); + return -1; +} + +int +rte_eal_soc_probe_one(const struct rte_soc_addr *addr) +{ + struct rte_soc_device *dev = NULL; + int ret = 0; + + if (addr == NULL) + return -1; + + TAILQ_FOREACH(dev, &soc_device_list, next) { + if (rte_eal_compare_soc_addr(&dev->addr, addr)) + continue; + + ret = soc_probe_all_drivers(dev); + if (ret < 0) + goto err_return; + return 0; + } + return -1; + +err_return: + RTE_LOG(WARNING, EAL, + "Requested device %s cannot be used\n", addr->name); + return -1; +} + +int +rte_eal_soc_probe(void) +{ + struct rte_soc_device *dev = NULL; + int ret = 0; + + TAILQ_FOREACH(dev, &soc_device_list, next) { + ret = soc_probe_all_drivers(dev); + if (ret < 0) { + RTE_LOG(DEBUG, EAL, "Requested device %s" + " cannot be used\n", dev->addr.name); + /* Failure for a particular device is logged and + * ignored + */ + } + } + + return ret; +} + /* dump one device */ static int soc_dump_one_device(FILE *f, struct rte_soc_device *dev) @@ -61,7 +265,6 @@ soc_dump_one_device(FILE *f, struct rte_soc_device *dev) return 0; } -/* dump devices on the bus to an output stream */ void rte_eal_soc_dump(FILE *f) { @@ -75,14 +278,18 @@ rte_eal_soc_dump(FILE *f) } } -/* register a driver */ void rte_eal_soc_register(struct rte_soc_driver *driver) { + /* For a valid soc driver, match and scan function + * should be provided. + */ + RTE_VERIFY(driver != NULL); + RTE_VERIFY(driver->match_fn != NULL); + RTE_VERIFY(driver->scan_fn != NULL); TAILQ_INSERT_TAIL(&soc_driver_list, driver, next); } -/* unregister a driver */ void rte_eal_soc_unregister(struct rte_soc_driver *driver) { diff --git a/lib/librte_eal/common/include/rte_soc.h b/lib/librte_eal/common/include/rte_soc.h index 347e611..53a321b 100644 --- a/lib/librte_eal/common/include/rte_soc.h +++ b/lib/librte_eal/common/include/rte_soc.h @@ -62,7 +62,6 @@ extern struct soc_device_list soc_device_list; TAILQ_HEAD(soc_driver_list, rte_soc_driver); /**< SoC drivers in D-linked Q. */ TAILQ_HEAD(soc_device_list, rte_soc_device); /**< SoC devices in D-linked Q. */ - struct rte_soc_id { const char *compatible; /**< OF compatible specification */ uint64_t priv_data; /**< SoC Driver specific data */ @@ -97,6 +96,23 @@ typedef int (soc_probe_t)(struct rte_soc_driver *, struct rte_soc_device *); typedef int (soc_remove_t)(struct rte_soc_device *); /** + * SoC device scan callback, called from rte_eal_soc_init. + * For various SoC, the bus on which devices are attached maynot be compliant + * to a standard platform (or platform bus itself). In which case, extra + * steps are implemented by PMD to scan over the bus and add devices to SoC + * device list. + */ +typedef void (soc_scan_t)(void); + +/** + * Custom device<=>driver match callback for SoC + * Unlike PCI, SoC devices don't have a fixed definition of device + * identification. PMDs can implement a specific matching function in which + * driver and device objects are provided to perform custom match. + */ +typedef int (soc_match_t)(struct rte_soc_driver *, struct rte_soc_device *); + +/** * A structure describing a SoC driver. */ struct rte_soc_driver { @@ -104,6 +120,8 @@ struct rte_soc_driver { struct rte_driver driver; /**< Inherit core driver. */ soc_probe_t *probe; /**< Device probe */ soc_remove_t *remove; /**< Device remove */ + soc_scan_t *scan_fn; /**< Callback for scanning SoC bus*/ + soc_match_t *match_fn; /**< Callback to match dev<->drv */ const struct rte_soc_id *id_table; /**< ID table, NULL terminated */ }; @@ -146,12 +164,63 @@ rte_eal_compare_soc_addr(const struct rte_soc_addr *a0, } /** + * Default function for matching the Soc driver with device. Each driver can + * either use this function or define their own soc matching function. + * This function relies on the compatible string extracted from sysfs. But, + * a SoC might have different way of identifying its devices. Such SoC can + * override match_fn. + * + * @return + * 0 on success + * -1 when no match found + */ +int +rte_eal_soc_match_compat(struct rte_soc_driver *drv, + struct rte_soc_device *dev); + +/** + * Probe SoC devices for registered drivers. + * + * @return + * 0 on success + * !0 in case of any failure in probe + */ +int rte_eal_soc_probe(void); + +/** + * Probe the single SoC device. + */ +int rte_eal_soc_probe_one(const struct rte_soc_addr *addr); + +/** + * Close the single SoC device. + * + * Scan the SoC devices and find the SoC device specified by the SoC + * address, then call the remove() function for registered driver + * that has a matching entry in its id_table for discovered device. + * + * @param addr + * The SoC address to close. + * @return + * - 0 on success. + * - Negative on error. + */ +int rte_eal_soc_detach(const struct rte_soc_addr *addr); + +/** * Dump discovered SoC devices. + * + * @param f + * File to dump device info in. */ void rte_eal_soc_dump(FILE *f); /** * Register a SoC driver. + * + * @param driver + * Object for SoC driver to register + * @return void */ void rte_eal_soc_register(struct rte_soc_driver *driver); @@ -167,6 +236,10 @@ RTE_PMD_EXPORT_NAME(nm, __COUNTER__) /** * Unregister a SoC driver. + * + * @param driver + * Object for SoC driver to unregister + * @return void */ void rte_eal_soc_unregister(struct rte_soc_driver *driver); diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index 098ba02..bd775f3 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include @@ -890,6 +891,10 @@ rte_eal_init(int argc, char **argv) if (rte_eal_pci_probe()) rte_panic("Cannot probe PCI\n"); + /* Probe & Initialize SoC devices */ + if (rte_eal_soc_probe()) + rte_panic("Cannot probe SoC\n"); + rte_eal_mcfg_complete(); return fctret; diff --git a/lib/librte_eal/linuxapp/eal/eal_soc.c b/lib/librte_eal/linuxapp/eal/eal_soc.c index 04848b9..3929a76 100644 --- a/lib/librte_eal/linuxapp/eal/eal_soc.c +++ b/lib/librte_eal/linuxapp/eal/eal_soc.c @@ -44,13 +44,28 @@ #include #include -#include "eal_internal_cfg.h" -#include "eal_filesystem.h" -#include "eal_private.h" +#include +#include +#include /* Init the SoC EAL subsystem */ int rte_eal_soc_init(void) { + struct rte_soc_driver *drv; + + /* SoC is disabled by default */ + if (!internal_config.enable_soc) + return 0; + + /* For each registered driver, call their scan routine to perform any + * custom scan for devices (for example, custom buses) + */ + TAILQ_FOREACH(drv, &soc_driver_list, next) { + RTE_VERIFY(drv->scan_fn); + drv->scan_fn(); + /* Ignore all errors from this */ + } + return 0; } diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index 0155025..c28e093 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -175,7 +175,11 @@ DPDK_16.11 { rte_eal_dev_attach; rte_eal_dev_detach; rte_eal_map_resource; + rte_eal_soc_detach; rte_eal_soc_dump; + rte_eal_soc_match; + rte_eal_soc_probe; + rte_eal_soc_probe_one; rte_eal_soc_register; rte_eal_soc_unregister; rte_eal_unmap_resource; -- 2.7.4