1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0) 2 * 3 * Copyright 2013-2016 Freescale Semiconductor Inc. 4 * Copyright 2016 NXP 5 * 6 */ 7 8 #ifndef __RTA_COMPAT_H__ 9 #define __RTA_COMPAT_H__ 10 11 #include <stdint.h> 12 #include <errno.h> 13 14 #ifdef __GLIBC__ 15 #include <string.h> 16 #include <stdlib.h> 17 #include <stdio.h> 18 #include <stdbool.h> 19 20 #include <rte_byteorder.h> 21 #include <rte_common.h> 22 23 #ifndef __BYTE_ORDER__ 24 #error "Undefined endianness" 25 #endif 26 27 #else 28 #error Environment not supported! 29 #endif 30 31 #ifndef __always_inline 32 #define __always_inline __rte_always_inline 33 #endif 34 35 #ifndef __always_unused 36 #define __always_unused __rte_unused 37 #endif 38 39 #ifndef __maybe_unused 40 #define __maybe_unused __rte_unused 41 #endif 42 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__) 47 #else 48 #define pr_debug(fmt, ...) do { } while (0) 49 #endif 50 #endif /* pr_debug */ 51 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__) 56 #else 57 #define pr_err(fmt, ...) do { } while (0) 58 #endif 59 #endif /* pr_err */ 60 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__) 65 #else 66 #define pr_warn(fmt, ...) do { } while (0) 67 #endif 68 #endif /* pr_warn */ 69 70 /** 71 * ARRAY_SIZE - returns the number of elements in an array 72 * @x: array 73 */ 74 #ifndef ARRAY_SIZE 75 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 76 #endif 77 78 #ifndef ALIGN 79 #define ALIGN(x, a) (((x) + ((__typeof__(x))(a) - 1)) & \ 80 ~((__typeof__(x))(a) - 1)) 81 #endif 82 83 #ifndef BIT 84 #define BIT(nr) (1UL << (nr)) 85 #endif 86 87 #ifndef upper_32_bits 88 /** 89 * upper_32_bits - return bits 32-63 of a number 90 * @n: the number we're accessing 91 */ 92 #define upper_32_bits(n) ((uint32_t)(((n) >> 16) >> 16)) 93 #endif 94 95 #ifndef lower_32_bits 96 /** 97 * lower_32_bits - return bits 0-31 of a number 98 * @n: the number we're accessing 99 */ 100 #define lower_32_bits(n) ((uint32_t)(n)) 101 #endif 102 103 /* Use Linux naming convention */ 104 #ifdef __GLIBC__ 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) 112 #else 113 #define cpu_to_be32(x) swab32(x) 114 #endif 115 #endif 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) 120 #else 121 #define cpu_to_le32(x) (x) 122 #endif 123 #endif 124 #endif 125 126 #endif /* __RTA_COMPAT_H__ */ 127