From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0061.outbound.protection.outlook.com [104.47.42.61]) by dpdk.org (Postfix) with ESMTP id 0A1C691AC for ; Wed, 7 Sep 2016 16:10:13 +0200 (CEST) Received: from BN6PR03CA0059.namprd03.prod.outlook.com (10.173.137.21) by BLUPR0301MB2004.namprd03.prod.outlook.com (10.164.22.18) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.599.9; Wed, 7 Sep 2016 14:10:09 +0000 Received: from BY2FFO11FD055.protection.gbl (2a01:111:f400:7c0c::179) by BN6PR03CA0059.outlook.office365.com (2603:10b6:404:4c::21) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.609.9 via Frontend Transport; Wed, 7 Sep 2016 14:10:09 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; rehivetech.com; dkim=none (message not signed) header.d=none;rehivetech.com; dmarc=fail action=none header.from=nxp.com; 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 BY2FFO11FD055.mail.protection.outlook.com (10.1.15.192) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.587.6 via Frontend Transport; Wed, 7 Sep 2016 14:10:08 +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 u87E8BD0013556; Wed, 7 Sep 2016 07:10:06 -0700 From: Shreyansh Jain To: CC: , Shreyansh Jain , "Jan Viktorin" Date: Wed, 7 Sep 2016 19:38:07 +0530 Message-ID: <1473257297-7221-16-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473257297-7221-1-git-send-email-shreyansh.jain@nxp.com> References: <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> <1473257297-7221-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131177310091811253; (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)(189002)(199003)(2351001)(2950100001)(19580405001)(305945005)(19580395003)(586003)(86362001)(189998001)(575784001)(8676002)(626004)(7846002)(5890100001)(8936002)(48376002)(36756003)(8666005)(68736007)(77096005)(5660300001)(5003940100001)(2906002)(110136002)(85426001)(47776003)(50466002)(229853001)(33646002)(356003)(104016004)(11100500001)(106466001)(76176999)(4326007)(50986999)(87936001)(92566002)(81166006)(81156014)(97736004)(105606002)(50226002)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR0301MB2004; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD055; 1:gQzAaPCKf77z4oSxfp+H336i+ZzeiYgMchKh7HqiotGMdA3yUWJzhQIU4CI4FAhrmL3jmXFy+lZLklVjrKnGC1RnFG7dU7/DYH6HZncFYqkpoyz83eNe/UJ6uOcwuftxIuTtsMgcjclxQAbfNsgcB5saP/6lVp4D+eZnGeJI1qtkS+xHaTVxqreJtSqy5Mqn1xQaoOeegeJFk9G400p1SCSRy/I5jfgNp3j6D8rp3KuboIVsTk1RJnJEvEZ8Ej47VxBAd1DcBQ3GBhjzgMT1g0hYoVyYJD7fzAORi4Jw1G4SuYqnBbhLmxhNERyNDJ2TECs2Tvk7FIC3dKch2opTsHLqcadUj2pMpzq7ln+dgNrWUiTjY3xW5ecTNh/GECLU/87SBy37cjAL53IhEAaRChKybxhdCvr2xHNiqh5vpwCgRsAG9DXsN5u/bF1EiGJN/b0SAHR+KIBA+UQMVWKrfQJ75ssyQbmqMSGH+tpXracHEMp7XO4JnCiOZ7gwmSOie5SXuy/mKY6VLbWgFi++ucq3umnc8WG/X//lPvy9kSopot5JUHMPUX6n0Mw6vxdB0sh1FfYwGtnPtiiKpcDIfpl6UgMfvcGHLGcaCacRtFq5AYtbJ67yKLDbhIykD3/9 MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 9cb338ac-bb90-4a5c-19b5-08d3d728ad14 X-Microsoft-Exchange-Diagnostics: 1; BLUPR0301MB2004; 2:cDO6gc4KK2DV3/Oi0W2gueEXvTVAIqX9hXrpcfQv8dasy7l3bFmlcyscWywxB9FnHz3bJu1ZQj3fle+lQ9A3frZz8ZojBlEMUTF6qnFtRcwSmC6UbRP4lUkJlufyy4rnH2eon1x6xb0DtX8c15jnTzRASPzxNqj5wF7Y3O1qxIVPQtp4siuPM9x9NXi4SrfF; 3:C0dPvabu9strnDSLeItckaC6U7P69+G3zRbNao4AQDiLKxQSOqvMm0GWQ+4p2eeZt/l08nES2l7fDjvWt1a/nUUhORGM0HSUZG5WNNq7lcYa48IwgG6sCcNNFuZoqbs3kTTeva/zcG+nrnLXEaTJrt19grEAWTcDzvMNRriz/pzgLaE34dUXund9BEea9gIhPVPnq0sKyle2on2pW18gYcwocTs1SS6xnQp7+wp2g5g=; 25:jFLE7WkuNqilGu5uwLRBlMEuvZPUiAInJnwK0S+UCoMfJbjyi9XST5zDmkYtOIDdrGE188RHZqxu2zT2xOXnU88kjYb0DOjOusBOdnCrnHg6Q9I+zxwDRGVfy7c88qYjQD9IVJcudR9AiyHi+diKMX8PNNzKB8v3GjXNRDemEwcttlHkFrOeXOJMY7AqAIJrkbn7bfmTC8JQLkfMCXYCkcTEduUM4dQ1/MPTLoZUzh0hluxyAg7VRCYvyVrleGP9CLgG8ee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6F8a94vq5Ae7yGZrtw5g== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(17755550239193); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(13015025)(13017025)(13023025)(13024025)(13018025)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:BLUPR0301MB2004; BCL:0; PCL:0; RULEID:(400006); SRVR:BLUPR0301MB2004; X-Forefront-PRVS: 0058ABBBC7 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR0301MB2004; 23:fB+7Dqjr0LiBmWpaG0N364lPtfZdZYFYv9SynU8?= =?us-ascii?Q?5iCa5po2ACpV2xC8h+2gT8VQ45cfpqkvx3gw3mRpDj4MIUggIi6vZ8gEVl3q?= =?us-ascii?Q?HoYXRJY1CQrzEti1Yrt1C6QIlg/s50+Io5BP1LPbeD6Vg3S/v/DxE8j+UxMi?= =?us-ascii?Q?adGIzDI05XTPVp6kLF7TcGCBWFIKTqsCPmWiLO4GX2G5NWm6wdeqvJYyqkFi?= =?us-ascii?Q?52CsT5/Y02qJGKJEnf+pRTCik60Byz1gQv3moCc1qPKcdsT4unkViYt0R/a7?= =?us-ascii?Q?PRNNIHL3ia3WZsjwWJRaq3ZClHqVr1vMbh7um/xQ71xce6h+iuPTu2GVRT/B?= =?us-ascii?Q?kP1yj5GV2v7GSj8h0Cr9NuKaDPC7wCBDn9SP9s8sEerbYNbqVuQd1/3uCIT+?= =?us-ascii?Q?M8zeVVqiVjdXxqouwFh0dnuiVstxqbt0OBJSfAOPHXBqwZau1TElainowXvT?= =?us-ascii?Q?WCd7La8fXoRQzjpbgJlrx3v0ozdT79n+ENE7w6mv5qJsO+LwdGzs5rUM75RX?= =?us-ascii?Q?O35dUfmJQlqfhIws2pvBg1k4pRlSYvUdVyZ772L/TIB+3CqtzEzaiVdT88FK?= =?us-ascii?Q?cImMJAP8GA3Qth6TO1neht6f/qRMYoqaS+oJxqL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FRRDgeo6X0wRwQ7AK1p1eH/1fNZN952bhznMkHhCWNNAE=; 5:4XNqnnl/P/YwlQbGC1+kPgdtwOhwl0gUaF2+Z9+qiATP86Z6N7R0SUog7rdwqycYkVHIkGl4cJYky6NslykqicpbVpFXHbuI24NmTWbDm6ZuQpDyT+9L6/5c01A/GIesUpfjnEA5aLqP9sOyJtdaWYrJrB+u15chRw5x3c4/9d4=; 24:NM035ZsUmQR671ApvXhzhHIJXwvpmQEjkS7342vPYTUw3qu4ejrIpmnOOaC4YR7NW8wdVWZhyP0BfJY3waXKc+PpJrVDQpP4a/zAgVMakog=; 7:5bXHkN2KOK2JDVVYyEMUamyd8bqxCLD+9bhG9yMlfMZsai2dqZM5bq4BP4gjYm2uoPEoJvnc+wwPhwCB65Jqzdgf3Bs2ZRlAK2GYTdwGK54Vpqv3s4MgGz2QZb0DVwMUhhyqd6mL1pB6zOL8hVBMi/QHwNtlkptOJewglZ8usXvB/5y4zsoyxlRcnkVhi1Yq47eJP5+af8YkKjv52tQ6RxXFyvsJlz6/6apGvE0SYAq9gOiROwwdJW5fKPTEncgq SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2016 14:10:08.9783 (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: BLUPR0301MB2004 Subject: [dpdk-dev] [PATCH v9 15/25] eal: extract vdev infra 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: Wed, 07 Sep 2016 14:10:13 -0000 Move all PMD_VDEV-specific code into a separate module and header file to not polute the generic code anymore. There is now a list of virtual devices available. The rte_vdev_driver integrates the original rte_driver inside (C inheritance). The rte_driver will be however change in the future to serve as a common base for all other types of drivers. The existing PMDs (PMD_VDEV) are to be modified later (there is no change for them at the moment). Unlike DRIVER_REGISTER_PCI, DRIVER_EXPORT_NAME is not being called on vdev registration. Signed-off-by: Jan Viktorin Signed-off-by: Shreyansh Jain --- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_dev.c | 54 +-------------- lib/librte_eal/common/eal_common_vdev.c | 110 +++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_vdev.h | 84 +++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + 6 files changed, 198 insertions(+), 54 deletions(-) create mode 100644 lib/librte_eal/common/eal_common_vdev.c create mode 100644 lib/librte_eal/common/include/rte_vdev.h diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile index 7a0fea5..5a3fc1d 100644 --- a/lib/librte_eal/bsdapp/eal/Makefile +++ b/lib/librte_eal/bsdapp/eal/Makefile @@ -69,6 +69,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_memzone.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_log.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_launch.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_vdev.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_pci.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_pci_uio.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_memory.c diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile index bb9810d..dfd64aa 100644 --- a/lib/librte_eal/common/Makefile +++ b/lib/librte_eal/common/Makefile @@ -38,7 +38,7 @@ INC += rte_per_lcore.h rte_random.h INC += rte_tailq.h rte_interrupts.h rte_alarm.h INC += rte_string_fns.h rte_version.h INC += rte_eal_memconfig.h rte_malloc_heap.h -INC += rte_hexdump.h rte_devargs.h rte_dev.h +INC += rte_hexdump.h rte_devargs.h rte_dev.h rte_vdev.h INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h INC += rte_malloc.h rte_keepalive.h rte_time.h diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 88f9d3f..555e0d9 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -64,32 +64,6 @@ rte_eal_driver_unregister(struct rte_driver *driver) } int -rte_eal_vdev_init(const char *name, const char *args) -{ - struct rte_driver *driver; - - if (name == NULL) - return -EINVAL; - - TAILQ_FOREACH(driver, &dev_driver_list, next) { - if (driver->type != PMD_VDEV) - continue; - - /* - * search a driver prefix in virtual device name. - * For example, if the driver is pcap PMD, driver->name - * will be "eth_pcap", but "name" will be "eth_pcapN". - * So use strncmp to compare. - */ - if (!strncmp(driver->name, name, strlen(driver->name))) - return driver->init(name, args); - } - - RTE_LOG(ERR, EAL, "no driver found for %s\n", name); - return -EINVAL; -} - -int rte_eal_dev_init(void) { struct rte_devargs *devargs; @@ -98,7 +72,7 @@ rte_eal_dev_init(void) /* * Note that the dev_driver_list is populated here * from calls made to rte_eal_driver_register from constructor functions - * embedded into PMD modules via the PMD_REGISTER_DRIVER macro + * embedded into PMD modules via the DRIVER_REGISTER_VDEV macro */ /* call the init function for each virtual device */ @@ -125,32 +99,6 @@ rte_eal_dev_init(void) return 0; } -int -rte_eal_vdev_uninit(const char *name) -{ - struct rte_driver *driver; - - if (name == NULL) - return -EINVAL; - - TAILQ_FOREACH(driver, &dev_driver_list, next) { - if (driver->type != PMD_VDEV) - continue; - - /* - * search a driver prefix in virtual device name. - * For example, if the driver is pcap PMD, driver->name - * will be "eth_pcap", but "name" will be "eth_pcapN". - * So use strncmp to compare. - */ - if (!strncmp(driver->name, name, strlen(driver->name))) - return driver->uninit(name); - } - - RTE_LOG(ERR, EAL, "no driver found for %s\n", name); - return -EINVAL; -} - int rte_eal_dev_attach(const char *name, const char *devargs) { struct rte_pci_addr addr; diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c new file mode 100644 index 0000000..d225e86 --- /dev/null +++ b/lib/librte_eal/common/eal_common_vdev.c @@ -0,0 +1,110 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2016 RehiveTech. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of RehiveTech nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +struct vdev_driver_list vdev_driver_list = + TAILQ_HEAD_INITIALIZER(vdev_driver_list); + +/* register a driver */ +void +rte_eal_vdrv_register(struct rte_vdev_driver *driver) +{ + TAILQ_INSERT_TAIL(&vdev_driver_list, driver, next); +} + +/* unregister a driver */ +void +rte_eal_vdrv_unregister(struct rte_vdev_driver *driver) +{ + TAILQ_REMOVE(&vdev_driver_list, driver, next); +} + +int +rte_eal_vdev_init(const char *name, const char *args) +{ + struct rte_vdev_driver *driver; + + if (name == NULL) + return -EINVAL; + + TAILQ_FOREACH(driver, &vdev_driver_list, next) { + if (driver->driver.type != PMD_VDEV) + continue; + + /* + * search a driver prefix in virtual device name. + * For example, if the driver is pcap PMD, driver->name + * will be "eth_pcap", but "name" will be "eth_pcapN". + * So use strncmp to compare. + */ + if (!strncmp(driver->driver.name, name, strlen(driver->driver.name))) + return driver->driver.init(name, args); + } + + RTE_LOG(ERR, EAL, "no driver found for %s\n", name); + return -EINVAL; +} + +int +rte_eal_vdev_uninit(const char *name) +{ + struct rte_vdev_driver *driver; + + if (name == NULL) + return -EINVAL; + + TAILQ_FOREACH(driver, &vdev_driver_list, next) { + if (driver->driver.type != PMD_VDEV) + continue; + + /* + * search a driver prefix in virtual device name. + * For example, if the driver is pcap PMD, driver->name + * will be "eth_pcap", but "name" will be "eth_pcapN". + * So use strncmp to compare. + */ + if (!strncmp(driver->driver.name, name, strlen(driver->driver.name))) + return driver->driver.uninit(name); + } + + RTE_LOG(ERR, EAL, "no driver found for %s\n", name); + return -EINVAL; +} diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h new file mode 100644 index 0000000..9a2e2d5 --- /dev/null +++ b/lib/librte_eal/common/include/rte_vdev.h @@ -0,0 +1,84 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2016 RehiveTech. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of RehiveTech nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef RTE_VDEV_H +#define RTE_VDEV_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +/** Double linked list of virtual device drivers. */ +TAILQ_HEAD(vdev_driver_list, rte_vdev_driver); + +/** + * A virtual device driver abstraction. + */ +struct rte_vdev_driver { + TAILQ_ENTRY(rte_vdev_driver) next; /**< Next in list. */ + struct rte_driver driver; /**< Inherited general driver. */ +}; + +/** + * Register a virtual device driver. + * + * @param driver + * A pointer to a rte_vdev_driver structure describing the driver + * to be registered. + */ +void rte_eal_vdrv_register(struct rte_vdev_driver *driver); + +/** + * Unregister a virtual device driver. + * + * @param driver + * A pointer to a rte_vdev_driver structure describing the driver + * to be unregistered. + */ +void rte_eal_vdrv_unregister(struct rte_vdev_driver *driver); + +#define DRIVER_REGISTER_VDEV(nm, vdrv)\ +RTE_INIT(vdrvinitfn_ ##vdrv);\ +static void vdrvinitfn_ ##vdrv(void)\ +{\ + (vdrv).driver.name = RTE_STR(nm);\ + rte_eal_vdrv_register(&vdrv);\ +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile index 193957f..4e206f0 100644 --- a/lib/librte_eal/linuxapp/eal/Makefile +++ b/lib/librte_eal/linuxapp/eal/Makefile @@ -77,6 +77,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memzone.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_log.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_launch.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_vdev.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_pci.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_pci_uio.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memory.c -- 2.7.4