drivers: update registration macro usage
[dpdk.git] / lib / librte_eal / common / include / rte_dev.h
index f601d21..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);
@@ -125,12 +178,30 @@ int rte_eal_vdev_init(const char *name, const char *args);
  */
 int rte_eal_vdev_uninit(const char *name);
 
-#define PMD_REGISTER_DRIVER(d)\
-void devinitfn_ ##d(void);\
-void __attribute__((constructor, used)) devinitfn_ ##d(void)\
+#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
 }