1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
8 #ifndef __RTA_COMPAT_H__
9 #define __RTA_COMPAT_H__
14 #ifdef RTE_EXEC_ENV_LINUX
20 #include <rte_byteorder.h>
21 #include <rte_common.h>
23 #ifndef __BYTE_ORDER__
24 #error "Undefined endianness"
27 #else /* !RTE_EXEC_ENV_LINUX */
28 #error Environment not supported!
31 #ifndef __always_inline
32 #define __always_inline __rte_always_inline
35 #ifndef __always_unused
36 #define __always_unused __rte_unused
39 #ifndef __maybe_unused
40 #define __maybe_unused __rte_unused
43 #if defined(SUPPRESS_PRINTS)
44 #define pr_msg(l, fmt, ...) do { } while (0)
46 #define pr_msg(l, fmt, ...) \
47 RTE_LOG(l, PMD, "%s(): " fmt "\n", __func__, ##__VA_ARGS__)
50 #if !defined(pr_debug)
51 #if defined(RTA_DEBUG)
52 #define pr_debug(fmt, ...) pr_msg(DEBUG, fmt, ##__VA_ARGS__)
54 #define pr_debug(fmt, ...) do { } while (0)
59 #define pr_err(fmt, ...) pr_msg(ERR, fmt, ##__VA_ARGS__)
63 #define pr_warn(fmt, ...) pr_msg(WARNING, fmt, ##__VA_ARGS__)
67 * ARRAY_SIZE - returns the number of elements in an array
71 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
75 #define ALIGN(x, a) (((x) + ((__typeof__(x))(a) - 1)) & \
76 ~((__typeof__(x))(a) - 1))
80 #define BIT(nr) (1UL << (nr))
85 * upper_32_bits - return bits 32-63 of a number
86 * @n: the number we're accessing
88 #define upper_32_bits(n) ((uint32_t)(((n) >> 16) >> 16))
93 * lower_32_bits - return bits 0-31 of a number
94 * @n: the number we're accessing
96 #define lower_32_bits(n) ((uint32_t)(n))
99 /* Use Linux naming convention */
100 #if defined(RTE_EXEC_ENV_LINUX) || defined(__GLIBC__)
101 #define swab16(x) rte_bswap16(x)
102 #define swab32(x) rte_bswap32(x)
103 #define swab64(x) rte_bswap64(x)
104 /* Define cpu_to_be32 macro if not defined in the build environment */
105 #if !defined(cpu_to_be32)
106 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
107 #define cpu_to_be32(x) (x)
109 #define cpu_to_be32(x) swab32(x)
112 /* Define cpu_to_le32 macro if not defined in the build environment */
113 #if !defined(cpu_to_le32)
114 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
115 #define cpu_to_le32(x) swab32(x)
117 #define cpu_to_le32(x) (x)
122 #endif /* __RTA_COMPAT_H__ */