[dpdk-dev] [PATCH 12/19] pmd: Add PMD_INIT macro for use in pci based PMDs
Neil Horman
nhorman at tuxdriver.com
Thu Apr 10 22:50:02 CEST 2014
Like their non-pci counterparts, the PMD_INIT macro can be used by pci based
PMD's to register an init routine without having the core libraries reference
symbols in them directly.
Signed-off-by: Neil Horman <nhorman at tuxdriver.com>
---
lib/librte_eal/common/include/rte_pmd.h | 9 +++++++
lib/librte_ether/rte_ethdev.c | 44 +++++++++++++++++++++++++++++++--
2 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/lib/librte_eal/common/include/rte_pmd.h b/lib/librte_eal/common/include/rte_pmd.h
index 75a4895..bcba8f8 100644
--- a/lib/librte_eal/common/include/rte_pmd.h
+++ b/lib/librte_eal/common/include/rte_pmd.h
@@ -44,7 +44,9 @@
extern "C" {
#endif
+extern void rte_pmd_register_init(int (*pmd_initfn)(void));
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)\
@@ -52,6 +54,13 @@ void __attribute__((constructor, used)) devinitfn_ ##x(void)\
rte_eal_nonpci_dev_init_register(n,x);\
}
+#define PMD_INIT(x)\
+void devinitfn_ ##x(void);\
+void __attribute__((constructor, used)) devinitfn_ ##x(void)\
+{\
+ rte_pmd_register_init(x);\
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index dd378f0..a9efe73 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -64,6 +64,7 @@
#include <rte_mbuf.h>
#include <rte_errno.h>
#include <rte_spinlock.h>
+#include <rte_pmd.h>
#include "rte_ether.h"
#include "rte_ethdev.h"
@@ -112,9 +113,38 @@ static uint8_t nb_ports = 0;
/* spinlock for eth device callbacks */
static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
+TAILQ_HEAD(pmd_list, pmd_entry);
+
+/* Definition for shared object drivers. */
+struct pmd_entry {
+ TAILQ_ENTRY(pmd_entry) next;
+ int (*pmd_initfn)(void);
+};
+
+/* List of external loadable drivers */
+static struct pmd_list pmd_init_list =
+TAILQ_HEAD_INITIALIZER(pmd_init_list);
+
+void rte_pmd_register_init(int (*pmd_initfn)(void))
+{
+ struct pmd_entry *new = malloc(sizeof(struct pmd_entry));
+
+ if (!new) {
+ printf("Not enough memory to register pci pmd\n");
+ goto out;
+ }
+
+ new->pmd_initfn = pmd_initfn;
+ TAILQ_INSERT_TAIL(&pmd_init_list, new, next);
+out:
+ return;
+
+}
+
int rte_pmd_init_all(void)
{
int ret = -ENODEV;
+ struct pmd_entry *entry;
#ifdef RTE_LIBRTE_IGB_PMD
if ((ret = rte_igb_pmd_init()) != 0) {
@@ -159,9 +189,19 @@ int rte_pmd_init_all(void)
}
#endif /* RTE_LIBRTE_VMXNET3_PMD */
- if (ret == -ENODEV)
+ if (ret == -ENODEV) {
RTE_LOG(ERR, PMD, "No PMD(s) are configured\n");
- return (ret);
+ goto out;
+ }
+
+ TAILQ_FOREACH(entry, &pmd_init_list, next) {
+ ret = entry->pmd_initfn();
+ if (ret != 0)
+ break;
+ }
+
+out:
+ return ret;
}
/**
--
1.8.3.1
More information about the dev
mailing list