drivers: update registration macro usage
[dpdk.git] / lib / librte_eal / common / include / rte_dev.h
index d89f1a5..e6f0d4c 100644 (file)
 extern "C" {
 #endif
 
+#include <stdio.h>
 #include <sys/queue.h>
+#include <rte_pci.h>
+#include <rte_log.h>
+
+__attribute__((format(printf, 2, 0)))
+static inline void
+rte_pmd_debug_trace(const char *func_name, const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+
+       char buffer[vsnprintf(NULL, 0, fmt, ap) + 1];
+
+       va_end(ap);
+
+       va_start(ap, fmt);
+       vsnprintf(buffer, sizeof(buffer), fmt, ap);
+       va_end(ap);
+
+       rte_log(RTE_LOG_ERR, RTE_LOGTYPE_PMD, "%s: %s", func_name, buffer);
+}
+
+/* Macros for checking for restricting functions to primary instance only */
+#define RTE_PROC_PRIMARY_OR_ERR_RET(retval) do { \
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
+               RTE_PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
+               return retval; \
+       } \
+} while (0)
+
+#define RTE_PROC_PRIMARY_OR_RET() do { \
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
+               RTE_PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
+               return; \
+       } \
+} while (0)
+
+/* Macros to check for invalid function pointers */
+#define RTE_FUNC_PTR_OR_ERR_RET(func, retval) do { \
+       if ((func) == NULL) { \
+               RTE_PMD_DEBUG_TRACE("Function not supported\n"); \
+               return retval; \
+       } \
+} while (0)
+
+#define RTE_FUNC_PTR_OR_RET(func) do { \
+       if ((func) == NULL) { \
+               RTE_PMD_DEBUG_TRACE("Function not supported\n"); \
+               return; \
+       } \
+} while (0)
+
 
 /** Double linked list of device drivers. */
 TAILQ_HEAD(rte_driver_list, rte_driver);
@@ -56,22 +109,17 @@ TAILQ_HEAD(rte_driver_list, rte_driver);
  */
 typedef int (rte_dev_init_t)(const char *name, const char *args);
 
+/**
+ * Uninitilization function called for each device driver once.
+ */
+typedef int (rte_dev_uninit_t)(const char *name);
+
 /**
  * Driver type enumeration
  */
 enum pmd_type {
        PMD_VDEV = 0,
        PMD_PDEV = 1,
-       PMD_BDEV = 2,   /**< Poll Mode Driver Bonded Device*/
-};
-
-#define PMD_BOND_NAME "eth_bond"
-
-/**
- * Driver initialization */
-enum pmd_init_priority {
-       PMD_INIT_PRE_PCI_PROBE = 0,
-       PMD_INIT_POST_PCI_PROBE = 1,
 };
 
 /**
@@ -82,6 +130,7 @@ struct rte_driver {
        enum pmd_type type;                /**< PMD Driver type */
        const char *name;                   /**< Driver name. */
        rte_dev_init_t *init;              /**< Device init. function. */
+       rte_dev_uninit_t *uninit;          /**< Device uninit. function. */
 };
 
 /**
@@ -103,16 +152,56 @@ void rte_eal_driver_register(struct rte_driver *driver);
 void rte_eal_driver_unregister(struct rte_driver *driver);
 
 /**
- * Initialize all the registered drivers in this process
+ * Initalize all the registered drivers in this process
+ */
+int rte_eal_dev_init(void);
+
+/**
+ * Initialize a driver specified by name.
+ *
+ * @param name
+ *   The pointer to a driver name to be initialized.
+ * @param args
+ *   The pointer to arguments used by driver initialization.
+ * @return
+ *  0 on success, negative on error
  */
-int rte_eal_dev_init(uint8_t init_priority);
+int rte_eal_vdev_init(const char *name, const char *args);
 
-#define PMD_REGISTER_DRIVER(d)\
-void devinitfn_ ##d(void);\
-void __attribute__((constructor, used)) devinitfn_ ##d(void)\
+/**
+ * Uninitalize a driver specified by name.
+ *
+ * @param name
+ *   The pointer to a driver name to be initialized.
+ * @return
+ *  0 on success, negative on error
+ */
+int rte_eal_vdev_uninit(const char *name);
+
+#define DRIVER_EXPORT_NAME_ARRAY(n, idx) n##idx[]
+
+#define DRIVER_EXPORT_NAME(name, idx) \
+static const char DRIVER_EXPORT_NAME_ARRAY(this_pmd_name, idx) \
+__attribute__((used)) = RTE_STR(name)
+
+#define PMD_REGISTER_DRIVER(drv, nm)\
+void devinitfn_ ##drv(void);\
+void __attribute__((constructor, used)) devinitfn_ ##drv(void)\
 {\
-       rte_eal_driver_register(&d);\
-}
+       (drv).name = RTE_STR(nm);\
+       rte_eal_driver_register(&drv);\
+} \
+DRIVER_EXPORT_NAME(nm, __COUNTER__)
+
+#define DRV_EXP_TAG(name, tag) __##name##_##tag
+
+#define DRIVER_REGISTER_PCI_TABLE(name, table) \
+static const char DRV_EXP_TAG(name, pci_tbl_export)[] __attribute__((used)) = \
+RTE_STR(table)
+
+#define DRIVER_REGISTER_PARAM_STRING(name, str) \
+static const char DRV_EXP_TAG(name, param_string_export)[] \
+__attribute__((used)) = str
 
 #ifdef __cplusplus
 }