1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2017 6WIND S.A.
3 * Copyright 2017 Mellanox Technologies, Ltd
12 #include <rte_common.h>
18 * Compilation workaround for PPC64 when AltiVec is fully enabled, e.g. std=c11.
19 * Otherwise there would be a type conflict between stdbool and altivec.
21 #if defined(__PPC64__) && !defined(__APPLE_ALTIVEC__)
23 /* redefine as in stdbool.h */
27 extern int mlx4_logtype;
29 #ifdef RTE_LIBRTE_MLX4_DEBUG
32 * When debugging is enabled (MLX4_DEBUG is defined), file, line and function
33 * information replace the driver name (MLX4_DRIVER_NAME) in log messages.
36 /** Return the file name part of a path. */
37 static inline const char *
38 pmd_drv_log_basename(const char *s)
48 #define PMD_DRV_LOG(level, ...) \
49 rte_log(RTE_LOG_ ## level, mlx4_logtype, \
50 RTE_FMT("%s:%u: %s(): " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
51 pmd_drv_log_basename(__FILE__), \
54 RTE_FMT_TAIL(__VA_ARGS__,)))
55 #define MLX4_ASSERT(exp) RTE_VERIFY(exp)
56 #define claim_zero(...) MLX4_ASSERT((__VA_ARGS__) == 0)
58 #else /* RTE_LIBRTE_MLX4_DEBUG */
61 * Like MLX4_ASSERT(), claim_zero() does not perform
62 * any check when debugging is disabled.
65 #define PMD_DRV_LOG(level, ...) \
66 rte_log(RTE_LOG_ ## level, mlx4_logtype, \
67 RTE_FMT(MLX4_DRIVER_NAME ": " \
68 RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
69 RTE_FMT_TAIL(__VA_ARGS__,)))
70 #define MLX4_ASSERT(exp) RTE_ASSERT(exp)
71 #define claim_zero(...) (__VA_ARGS__)
73 #endif /* RTE_LIBRTE_MLX4_DEBUG */
75 #define DEBUG(...) PMD_DRV_LOG(DEBUG, __VA_ARGS__)
76 #define INFO(...) PMD_DRV_LOG(INFO, __VA_ARGS__)
77 #define WARN(...) PMD_DRV_LOG(WARNING, __VA_ARGS__)
78 #define ERROR(...) PMD_DRV_LOG(ERR, __VA_ARGS__)
80 /** Allocate a buffer on the stack and fill it with a printf format string. */
81 #define MKSTR(name, ...) \
82 int mkstr_size_##name = snprintf(NULL, 0, "" __VA_ARGS__); \
83 char name[mkstr_size_##name + 1]; \
85 snprintf(name, sizeof(name), "" __VA_ARGS__)
87 /** Generate a string out of the provided arguments. */
88 #define MLX4_STR(...) # __VA_ARGS__
90 /** Similar to MLX4_STR() with enclosed macros expanded first. */
91 #define MLX4_STR_EXPAND(...) MLX4_STR(__VA_ARGS__)
93 /** Object description used with mlx4_mallocv() and similar functions. */
94 struct mlx4_malloc_vec {
95 size_t align; /**< Alignment constraint (power of 2), 0 if unknown. */
96 size_t size; /**< Object size. */
97 void **addr; /**< Storage for allocation address. */
102 int mlx4_fd_set_non_blocking(int fd);
103 size_t mlx4_mallocv(const char *type, const struct mlx4_malloc_vec *vec,
105 size_t mlx4_zmallocv(const char *type, const struct mlx4_malloc_vec *vec,
107 size_t mlx4_mallocv_socket(const char *type, const struct mlx4_malloc_vec *vec,
108 unsigned int cnt, int socket);
109 size_t mlx4_zmallocv_socket(const char *type, const struct mlx4_malloc_vec *vec,
110 unsigned int cnt, int socket);
112 #endif /* MLX4_UTILS_H_ */