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__
20 #include <rte_byteorder.h>
21 #include <rte_common.h>
23 #ifndef __BYTE_ORDER__
24 #error "Undefined endianness"
28 #error Environment not supported!
31 #ifndef __always_inline
32 #define __always_inline __rte_always_inline
35 #ifndef __always_unused
36 #define __always_unused __attribute__((unused))
39 #ifndef __maybe_unused
40 #define __maybe_unused __attribute__((unused))
43 #if defined(__GLIBC__) && !defined(pr_debug)
44 #if !defined(SUPPRESS_PRINTS) && defined(RTA_DEBUG)
45 #define pr_debug(fmt, ...) \
46 RTE_LOG(DEBUG, PMD, "%s(): " fmt "\n", __func__, ##__VA_ARGS__)
48 #define pr_debug(fmt, ...) do { } while (0)
52 #if defined(__GLIBC__) && !defined(pr_err)
53 #if !defined(SUPPRESS_PRINTS)
54 #define pr_err(fmt, ...) \
55 RTE_LOG(ERR, PMD, "%s(): " fmt "\n", __func__, ##__VA_ARGS__)
57 #define pr_err(fmt, ...) do { } while (0)
61 #if defined(__GLIBC__) && !defined(pr_warn)
62 #if !defined(SUPPRESS_PRINTS)
63 #define pr_warn(fmt, ...) \
64 RTE_LOG(WARNING, PMD, "%s(): " fmt "\n", __func__, ##__VA_ARGS__)
66 #define pr_warn(fmt, ...) do { } while (0)
71 * ARRAY_SIZE - returns the number of elements in an array
75 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
79 #define ALIGN(x, a) (((x) + ((__typeof__(x))(a) - 1)) & \
80 ~((__typeof__(x))(a) - 1))
84 #define BIT(nr) (1UL << (nr))
89 * upper_32_bits - return bits 32-63 of a number
90 * @n: the number we're accessing
92 #define upper_32_bits(n) ((uint32_t)(((n) >> 16) >> 16))
97 * lower_32_bits - return bits 0-31 of a number
98 * @n: the number we're accessing
100 #define lower_32_bits(n) ((uint32_t)(n))
103 /* Use Linux naming convention */
105 #define swab16(x) rte_bswap16(x)
106 #define swab32(x) rte_bswap32(x)
107 #define swab64(x) rte_bswap64(x)
108 /* Define cpu_to_be32 macro if not defined in the build environment */
109 #if !defined(cpu_to_be32)
110 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
111 #define cpu_to_be32(x) (x)
113 #define cpu_to_be32(x) swab32(x)
116 /* Define cpu_to_le32 macro if not defined in the build environment */
117 #if !defined(cpu_to_le32)
118 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
119 #define cpu_to_le32(x) swab32(x)
121 #define cpu_to_le32(x) (x)
126 #endif /* __RTA_COMPAT_H__ */