DPDK patches and discussions
 help / color / mirror / Atom feed
From: Neil Horman <nhorman@tuxdriver.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 02/19] pmd: Add PMD_INIT_NONPCI macros
Date: Thu, 10 Apr 2014 16:49:52 -0400	[thread overview]
Message-ID: <1397163009-29950-2-git-send-email-nhorman@tuxdriver.com> (raw)
In-Reply-To: <1397163009-29950-1-git-send-email-nhorman@tuxdriver.com>

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 <nhorman@tuxdriver.com>
---
 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 <string.h>
 #include <inttypes.h>
+#include <string.h>
+#include <sys/queue.h>
 #include <rte_string_fns.h>
 #ifdef RTE_LIBRTE_PMD_RING
 #include <rte_eth_ring.h>
@@ -46,6 +48,8 @@
 #endif
 #include <rte_debug.h>
 #include <rte_devargs.h>
+#include <rte_pmd.h>
+#include <rte_log.h>
 #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 <nhorman@tuxdriver.com. 
+ *   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 Intel Corporation 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.
+ */
+
+/**
+ * @file
+ *
+ * API for error cause tracking
+ */
+
+#ifndef _RTE_PMD_H_
+#define _RTE_PMD_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void rte_eal_nonpci_dev_init_register(const char *name, int (*dev_initfn)(const char *, const char *));
+#define PMD_INIT_NONPCI(x,n)\
+void devinitfn_ ##x(void);\
+void __attribute__((constructor, used)) devinitfn_ ##x(void)\
+{\
+	rte_eal_nonpci_dev_init_register(n,x);\
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_PMD_H_ */
-- 
1.8.3.1

  reply	other threads:[~2014-04-10 20:48 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-10 20:47 [dpdk-dev] [PATCH 0/19] Separate compile time linkage between eal lib and pmd's Neil Horman
2014-04-10 20:49 ` [dpdk-dev] [PATCH 01/19] makefiles: Fixed -share command line option error Neil Horman
2014-04-10 20:49   ` Neil Horman [this message]
2014-04-10 20:49   ` [dpdk-dev] [PATCH 03/19] eal: dlopen the DSO built poll mode drivers before init Neil Horman
2014-04-10 20:49   ` [dpdk-dev] [PATCH 04/19] pcap: Convert pcap poll mode driver to use new PMD_INIT_NONPCI macro Neil Horman
2014-04-10 20:49   ` [dpdk-dev] [PATCH 05/19] ring: convert the ring pmd driver to use the " Neil Horman
2014-04-10 20:49   ` [dpdk-dev] [PATCH 06/19] xenvert: Convert xenvirt pmd to use " Neil Horman
2014-04-10 20:49   ` [dpdk-dev] [PATCH 07/19] pmd: remove dead code Neil Horman
2014-04-10 20:49   ` [dpdk-dev] [PATCH 08/19] test: fix test app to dynamically link pmd_pcap when needed Neil Horman
2014-04-10 20:49   ` [dpdk-dev] [PATCH 09/19] testpmd: only link pcap pmd when statically linking Neil Horman
2014-04-10 20:50   ` [dpdk-dev] [PATCH 10/19] make: include whole archive on static link Neil Horman
2014-04-10 20:50   ` [dpdk-dev] [PATCH 11/19] pmd: Move rte_pmd_init_all to be non-inline Neil Horman
2014-04-10 20:50   ` [dpdk-dev] [PATCH 12/19] pmd: Add PMD_INIT macro for use in pci based PMDs Neil Horman
2014-04-10 20:50   ` [dpdk-dev] [PATCH 13/19] igb: Convert PMD to use new PMD_INIT macro Neil Horman
2014-04-10 20:50   ` [dpdk-dev] [PATCH 14/19] igbvf: move igbvf pmd to use " Neil Horman
2014-04-10 20:50   ` [dpdk-dev] [PATCH 15/19] em: move em/e1000 " Neil Horman
2014-04-10 20:50   ` [dpdk-dev] [PATCH 16/19] ixgbe: move ixgbe[vf] pmd's " Neil Horman
2014-04-10 20:50   ` [dpdk-dev] [PATCH 17/19] virtio: Move to using " Neil Horman
2014-04-10 20:50   ` [dpdk-dev] [PATCH 18/19] vmxnet3: move " Neil Horman
2014-04-10 20:50   ` [dpdk-dev] [PATCH 19/19] pmd: Not having any pci dev pmds shouldn't be fatal Neil Horman
2014-04-12 11:04 ` [dpdk-dev] [PATCH 0/19] Separate compile time linkage between eal lib and pmd's Neil Horman
2014-04-15  8:31   ` Thomas Monjalon
2014-04-15 13:46     ` Neil Horman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1397163009-29950-2-git-send-email-nhorman@tuxdriver.com \
    --to=nhorman@tuxdriver.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).