1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2017 6WIND S.A.
3 * Copyright 2017 Mellanox Technologies, Ltd
13 #include <rte_common.h>
18 extern int mlx4_logtype;
23 * When debugging is enabled (NDEBUG not defined), file, line and function
24 * information replace the driver name (MLX4_DRIVER_NAME) in log messages.
27 /** Return the file name part of a path. */
28 static inline const char *
29 pmd_drv_log_basename(const char *s)
39 #define PMD_DRV_LOG(level, ...) \
40 rte_log(RTE_LOG_ ## level, mlx4_logtype, \
41 RTE_FMT("%s:%u: %s(): " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
42 pmd_drv_log_basename(__FILE__), \
45 RTE_FMT_TAIL(__VA_ARGS__,)))
46 #define DEBUG(...) PMD_DRV_LOG(DEBUG, __VA_ARGS__)
47 #define claim_zero(...) assert((__VA_ARGS__) == 0)
52 * Like assert(), DEBUG() becomes a no-op and claim_zero() does not perform
53 * any check when debugging is disabled.
56 #define PMD_DRV_LOG(level, ...) \
57 rte_log(RTE_LOG_ ## level, mlx4_logtype, \
58 RTE_FMT(MLX4_DRIVER_NAME ": " \
59 RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
60 RTE_FMT_TAIL(__VA_ARGS__,)))
61 #define DEBUG(...) (void)0
62 #define claim_zero(...) (__VA_ARGS__)
66 #define INFO(...) PMD_DRV_LOG(INFO, __VA_ARGS__)
67 #define WARN(...) PMD_DRV_LOG(WARNING, __VA_ARGS__)
68 #define ERROR(...) PMD_DRV_LOG(ERR, __VA_ARGS__)
70 /** Allocate a buffer on the stack and fill it with a printf format string. */
71 #define MKSTR(name, ...) \
72 char name[snprintf(NULL, 0, __VA_ARGS__) + 1]; \
74 snprintf(name, sizeof(name), __VA_ARGS__)
76 /** Generate a string out of the provided arguments. */
77 #define MLX4_STR(...) # __VA_ARGS__
79 /** Similar to MLX4_STR() with enclosed macros expanded first. */
80 #define MLX4_STR_EXPAND(...) MLX4_STR(__VA_ARGS__)
82 /** Object description used with mlx4_mallocv() and similar functions. */
83 struct mlx4_malloc_vec {
84 size_t align; /**< Alignment constraint (power of 2), 0 if unknown. */
85 size_t size; /**< Object size. */
86 void **addr; /**< Storage for allocation address. */
91 int mlx4_fd_set_non_blocking(int fd);
92 size_t mlx4_mallocv(const char *type, const struct mlx4_malloc_vec *vec,
94 size_t mlx4_zmallocv(const char *type, const struct mlx4_malloc_vec *vec,
96 size_t mlx4_mallocv_socket(const char *type, const struct mlx4_malloc_vec *vec,
97 unsigned int cnt, int socket);
98 size_t mlx4_zmallocv_socket(const char *type, const struct mlx4_malloc_vec *vec,
99 unsigned int cnt, int socket);
101 #endif /* MLX4_UTILS_H_ */