2 * Copyright 2013-2016 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: BSD-3-Clause or GPL-2.0+
7 #ifndef __RTA_COMPAT_H__
8 #define __RTA_COMPAT_H__
18 #include <rte_byteorder.h>
20 #ifndef __BYTE_ORDER__
21 #error "Undefined endianness"
25 #error Environment not supported!
28 #ifndef __always_inline
29 #define __always_inline (inline __attribute__((always_inline)))
32 #ifndef __always_unused
33 #define __always_unused __attribute__((unused))
36 #ifndef __maybe_unused
37 #define __maybe_unused __attribute__((unused))
40 #if defined(__GLIBC__) && !defined(pr_debug)
41 #if !defined(SUPPRESS_PRINTS) && defined(RTA_DEBUG)
42 #define pr_debug(fmt, ...) \
43 RTE_LOG(DEBUG, PMD, "%s(): " fmt "\n", __func__, ##__VA_ARGS__)
45 #define pr_debug(fmt, ...) do { } while (0)
49 #if defined(__GLIBC__) && !defined(pr_err)
50 #if !defined(SUPPRESS_PRINTS)
51 #define pr_err(fmt, ...) \
52 RTE_LOG(ERR, PMD, "%s(): " fmt "\n", __func__, ##__VA_ARGS__)
54 #define pr_err(fmt, ...) do { } while (0)
58 #if defined(__GLIBC__) && !defined(pr_warn)
59 #if !defined(SUPPRESS_PRINTS)
60 #define pr_warn(fmt, ...) \
61 RTE_LOG(WARNING, PMD, "%s(): " fmt "\n", __func__, ##__VA_ARGS__)
63 #define pr_warn(fmt, ...) do { } while (0)
68 * ARRAY_SIZE - returns the number of elements in an array
72 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
76 #define ALIGN(x, a) (((x) + ((__typeof__(x))(a) - 1)) & \
77 ~((__typeof__(x))(a) - 1))
81 #define BIT(nr) (1UL << (nr))
86 * upper_32_bits - return bits 32-63 of a number
87 * @n: the number we're accessing
89 #define upper_32_bits(n) ((uint32_t)(((n) >> 16) >> 16))
94 * lower_32_bits - return bits 0-31 of a number
95 * @n: the number we're accessing
97 #define lower_32_bits(n) ((uint32_t)(n))
100 /* Use Linux naming convention */
102 #define swab16(x) rte_bswap16(x)
103 #define swab32(x) rte_bswap32(x)
104 #define swab64(x) rte_bswap64(x)
105 /* Define cpu_to_be32 macro if not defined in the build environment */
106 #if !defined(cpu_to_be32)
107 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
108 #define cpu_to_be32(x) (x)
110 #define cpu_to_be32(x) swab32(x)
113 /* Define cpu_to_le32 macro if not defined in the build environment */
114 #if !defined(cpu_to_le32)
115 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
116 #define cpu_to_le32(x) swab32(x)
118 #define cpu_to_le32(x) (x)
123 #endif /* __RTA_COMPAT_H__ */