]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/dpdk/drivers/net/mlx4/mlx4_utils.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / dpdk / drivers / net / mlx4 / mlx4_utils.h
CommitLineData
11fdf7f2
TL
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2017 6WIND S.A.
3 * Copyright 2017 Mellanox Technologies, Ltd
4 */
5
6#ifndef MLX4_UTILS_H_
7#define MLX4_UTILS_H_
8
11fdf7f2
TL
9#include <stddef.h>
10#include <stdio.h>
11
12#include <rte_common.h>
13#include <rte_log.h>
14
15#include "mlx4.h"
16
f67539c2
TL
17/*
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.
20 */
21#if defined(__PPC64__) && !defined(__APPLE_ALTIVEC__)
22#undef bool
23/* redefine as in stdbool.h */
24#define bool _Bool
25#endif
26
27extern int mlx4_logtype;
28
29#ifdef RTE_LIBRTE_MLX4_DEBUG
11fdf7f2
TL
30
31/*
f67539c2 32 * When debugging is enabled (MLX4_DEBUG is defined), file, line and function
11fdf7f2
TL
33 * information replace the driver name (MLX4_DRIVER_NAME) in log messages.
34 */
35
36/** Return the file name part of a path. */
37static inline const char *
38pmd_drv_log_basename(const char *s)
39{
40 const char *n = s;
41
42 while (*n)
43 if (*(n++) == '/')
44 s = n;
45 return s;
46}
47
48#define PMD_DRV_LOG(level, ...) \
f67539c2 49 rte_log(RTE_LOG_ ## level, mlx4_logtype, \
11fdf7f2
TL
50 RTE_FMT("%s:%u: %s(): " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
51 pmd_drv_log_basename(__FILE__), \
52 __LINE__, \
53 __func__, \
54 RTE_FMT_TAIL(__VA_ARGS__,)))
55#define DEBUG(...) PMD_DRV_LOG(DEBUG, __VA_ARGS__)
f67539c2
TL
56#define MLX4_ASSERT(exp) RTE_VERIFY(exp)
57#define claim_zero(...) MLX4_ASSERT((__VA_ARGS__) == 0)
11fdf7f2 58
f67539c2 59#else /* RTE_LIBRTE_MLX4_DEBUG */
11fdf7f2
TL
60
61/*
f67539c2 62 * Like MLX4_ASSERT(), DEBUG() becomes a no-op and claim_zero() does not perform
11fdf7f2
TL
63 * any check when debugging is disabled.
64 */
65
66#define PMD_DRV_LOG(level, ...) \
f67539c2 67 rte_log(RTE_LOG_ ## level, mlx4_logtype, \
11fdf7f2
TL
68 RTE_FMT(MLX4_DRIVER_NAME ": " \
69 RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
70 RTE_FMT_TAIL(__VA_ARGS__,)))
71#define DEBUG(...) (void)0
f67539c2 72#define MLX4_ASSERT(exp) RTE_ASSERT(exp)
11fdf7f2
TL
73#define claim_zero(...) (__VA_ARGS__)
74
f67539c2 75#endif /* RTE_LIBRTE_MLX4_DEBUG */
11fdf7f2
TL
76
77#define INFO(...) PMD_DRV_LOG(INFO, __VA_ARGS__)
78#define WARN(...) PMD_DRV_LOG(WARNING, __VA_ARGS__)
79#define ERROR(...) PMD_DRV_LOG(ERR, __VA_ARGS__)
80
81/** Allocate a buffer on the stack and fill it with a printf format string. */
82#define MKSTR(name, ...) \
f67539c2
TL
83 int mkstr_size_##name = snprintf(NULL, 0, "" __VA_ARGS__); \
84 char name[mkstr_size_##name + 1]; \
11fdf7f2 85 \
f67539c2 86 snprintf(name, sizeof(name), "" __VA_ARGS__)
11fdf7f2
TL
87
88/** Generate a string out of the provided arguments. */
89#define MLX4_STR(...) # __VA_ARGS__
90
91/** Similar to MLX4_STR() with enclosed macros expanded first. */
92#define MLX4_STR_EXPAND(...) MLX4_STR(__VA_ARGS__)
93
94/** Object description used with mlx4_mallocv() and similar functions. */
95struct mlx4_malloc_vec {
96 size_t align; /**< Alignment constraint (power of 2), 0 if unknown. */
97 size_t size; /**< Object size. */
98 void **addr; /**< Storage for allocation address. */
99};
100
101/* mlx4_utils.c */
102
103int mlx4_fd_set_non_blocking(int fd);
104size_t mlx4_mallocv(const char *type, const struct mlx4_malloc_vec *vec,
105 unsigned int cnt);
106size_t mlx4_zmallocv(const char *type, const struct mlx4_malloc_vec *vec,
107 unsigned int cnt);
108size_t mlx4_mallocv_socket(const char *type, const struct mlx4_malloc_vec *vec,
109 unsigned int cnt, int socket);
110size_t mlx4_zmallocv_socket(const char *type, const struct mlx4_malloc_vec *vec,
111 unsigned int cnt, int socket);
112
113#endif /* MLX4_UTILS_H_ */