From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.tuxdriver.com (charlotte.tuxdriver.com [70.61.120.58]) by dpdk.org (Postfix) with ESMTP id 61AAF307 for ; Thu, 10 Apr 2014 22:48:58 +0200 (CEST) Received: from hmsreliant.think-freely.org ([2001:470:8:a08:7aac:c0ff:fec2:933b] helo=localhost) by smtp.tuxdriver.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.63) (envelope-from ) id 1WYLvb-0004NY-Q6; Thu, 10 Apr 2014 16:50:34 -0400 From: Neil Horman To: dev@dpdk.org Date: Thu, 10 Apr 2014 16:49:52 -0400 Message-Id: <1397163009-29950-2-git-send-email-nhorman@tuxdriver.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1397163009-29950-1-git-send-email-nhorman@tuxdriver.com> References: <1397162846-28912-1-git-send-email-nhorman@tuxdriver.com> <1397163009-29950-1-git-send-email-nhorman@tuxdriver.com> X-Spam-Score: -2.9 (--) X-Spam-Status: No Subject: [dpdk-dev] [PATCH 02/19] pmd: Add PMD_INIT_NONPCI macros 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: Thu, 10 Apr 2014 20:48:58 -0000 This macro will allow nonpci based pmd driver to register an init function with the core eal library so that they don't need to be referenced at link time. The macro expands to a constructor that calls an eal library registration function, passing a pointer to the pmd's init routine. Signed-off-by: Neil Horman --- lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_nonpci_devs.c | 60 +++++++++++++++++++++++++- lib/librte_eal/common/include/rte_pmd.h | 59 +++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 lib/librte_eal/common/include/rte_pmd.h diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile index b9f3b88..e52b665 100644 --- a/lib/librte_eal/common/Makefile +++ b/lib/librte_eal/common/Makefile @@ -38,7 +38,7 @@ INC += rte_pci_dev_ids.h rte_per_lcore.h rte_prefetch.h rte_random.h INC += rte_rwlock.h rte_spinlock.h rte_tailq.h rte_interrupts.h rte_alarm.h INC += rte_string_fns.h rte_cpuflags.h rte_version.h rte_tailq_elem.h INC += rte_eal_memconfig.h rte_malloc_heap.h -INC += rte_hexdump.h rte_devargs.h +INC += rte_hexdump.h rte_devargs.h rte_pmd.h ifeq ($(CONFIG_RTE_INSECURE_FUNCTION_WARNING),y) INC += rte_warnings.h diff --git a/lib/librte_eal/common/eal_common_nonpci_devs.c b/lib/librte_eal/common/eal_common_nonpci_devs.c index 71cbb1e..0f94b65 100644 --- a/lib/librte_eal/common/eal_common_nonpci_devs.c +++ b/lib/librte_eal/common/eal_common_nonpci_devs.c @@ -34,6 +34,8 @@ #include #include +#include +#include #include #ifdef RTE_LIBRTE_PMD_RING #include @@ -46,6 +48,8 @@ #endif #include #include +#include +#include #include "eal_private.h" struct device_init { @@ -79,17 +83,54 @@ struct device_init dev_types[] = { } }; +TAILQ_HEAD(pmd_nonpci_list, pmd_nonpci_entry); + +/* Definition for shared object drivers. */ +struct pmd_nonpci_entry { + TAILQ_ENTRY(pmd_noncpi_entry) next; + + char name[PATH_MAX]; + int (*pmd_initfn)(const char *, const char *); +}; + +/* List of external loadable drivers */ +static struct pmd_nonpci_list pmd_nonpci_init_list = +TAILQ_HEAD_INITIALIZER(pmd_nonpci_init_list); + +void rte_eal_nonpci_dev_init_register(const char *name, int (*dev_initfn)(const char *, const char *)) +{ + struct pmd_nonpci_entry *new = malloc(sizeof(struct pmd_nonpci_entry)); + + if (!new) { + printf("Not enough memory to register %s\n", name); + goto out; + } + + memset(new->name, 0, PATH_MAX); + strncpy(new->name, name, PATH_MAX); + new->name[PATH_MAX-1] = 0; + new->pmd_initfn = dev_initfn; + printf("REGISTERING INIT ROUTINE FOR %s\n", new->name); + TAILQ_INSERT_TAIL(&pmd_nonpci_init_list, new, next); +out: + return; +} + + int rte_eal_non_pci_ethdev_init(void) { struct rte_devargs *devargs; + struct pmd_nonpci_entry *entry; uint8_t i; + int found = 0; /* call the init function for each virtual device */ TAILQ_FOREACH(devargs, &devargs_list, next) { if (devargs->type != RTE_DEVTYPE_VIRTUAL) continue; + found = 0; for (i = 0; i < NUM_DEV_TYPES; i++) { /* search a driver prefix in virtual device name */ @@ -98,14 +139,31 @@ rte_eal_non_pci_ethdev_init(void) sizeof(dev_types[i].dev_prefix) - 1)) { dev_types[i].init_fn(devargs->virtual.drv_name, devargs->args); + found = 1; break; } } - if (i == NUM_DEV_TYPES) { + if (found) + continue; + + TAILQ_FOREACH(entry, &pmd_nonpci_init_list, next) { + if (!entry->name) + continue; + if (!strncmp(entry->name, + devargs->virtual.drv_name, + strlen(entry->name))) { + RTE_LOG(INFO, PMD, "Initalizing pmd %s\n", devargs->virtual.drv_name); + found = 1; + entry->pmd_initfn(devargs->virtual.drv_name, devargs->args); + } + } + + if (!found) { rte_panic("no driver found for %s\n", devargs->virtual.drv_name); } } + return 0; } diff --git a/lib/librte_eal/common/include/rte_pmd.h b/lib/librte_eal/common/include/rte_pmd.h new file mode 100644 index 0000000..75a4895 --- /dev/null +++ b/lib/librte_eal/common/include/rte_pmd.h @@ -0,0 +1,59 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2010-2014 Neil Horman