1c0ded849SHemant Agrawal /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0) 2c0ded849SHemant Agrawal * 3c0ded849SHemant Agrawal * Copyright 2013-2016 Freescale Semiconductor Inc. 4c0ded849SHemant Agrawal * Copyright 2016 NXP 5c0ded849SHemant Agrawal * 6c0ded849SHemant Agrawal */ 7c0ded849SHemant Agrawal 8c0ded849SHemant Agrawal #ifndef __RTA_COMPAT_H__ 9c0ded849SHemant Agrawal #define __RTA_COMPAT_H__ 10c0ded849SHemant Agrawal 11c0ded849SHemant Agrawal #include <stdint.h> 12c0ded849SHemant Agrawal #include <errno.h> 13c0ded849SHemant Agrawal 148bf3ff3cSNatanael Copa #ifdef RTE_EXEC_ENV_LINUX 15c0ded849SHemant Agrawal #include <string.h> 16c0ded849SHemant Agrawal #include <stdlib.h> 17c0ded849SHemant Agrawal #include <stdio.h> 18c0ded849SHemant Agrawal #include <stdbool.h> 19c0ded849SHemant Agrawal 20c0ded849SHemant Agrawal #include <rte_byteorder.h> 21c0ded849SHemant Agrawal #include <rte_common.h> 22c0ded849SHemant Agrawal 23*3178e37cSDavid Marchand #include "dpaax_logs.h" 24*3178e37cSDavid Marchand 25c0ded849SHemant Agrawal #ifndef __BYTE_ORDER__ 26c0ded849SHemant Agrawal #error "Undefined endianness" 27c0ded849SHemant Agrawal #endif 28c0ded849SHemant Agrawal 298bf3ff3cSNatanael Copa #else /* !RTE_EXEC_ENV_LINUX */ 30c0ded849SHemant Agrawal #error Environment not supported! 31c0ded849SHemant Agrawal #endif 32c0ded849SHemant Agrawal 33c0ded849SHemant Agrawal #ifndef __always_inline 34c0ded849SHemant Agrawal #define __always_inline __rte_always_inline 35c0ded849SHemant Agrawal #endif 36c0ded849SHemant Agrawal 37c0ded849SHemant Agrawal #ifndef __always_unused 38f2fc83b4SThomas Monjalon #define __always_unused __rte_unused 39c0ded849SHemant Agrawal #endif 40c0ded849SHemant Agrawal 41c0ded849SHemant Agrawal #ifndef __maybe_unused 42f2fc83b4SThomas Monjalon #define __maybe_unused __rte_unused 43c0ded849SHemant Agrawal #endif 44c0ded849SHemant Agrawal 4569cb3917SNatanael Copa #if defined(SUPPRESS_PRINTS) 4669cb3917SNatanael Copa #define pr_msg(l, fmt, ...) do { } while (0) 4769cb3917SNatanael Copa #else 4869cb3917SNatanael Copa #define pr_msg(l, fmt, ...) \ 49*3178e37cSDavid Marchand RTE_LOG(l, DPAAX_LOGGER, "%s(): " fmt "\n", __func__, ##__VA_ARGS__) 5069cb3917SNatanael Copa #endif 5169cb3917SNatanael Copa 528bf3ff3cSNatanael Copa #if !defined(pr_debug) 5369cb3917SNatanael Copa #if defined(RTA_DEBUG) 5469cb3917SNatanael Copa #define pr_debug(fmt, ...) pr_msg(DEBUG, fmt, ##__VA_ARGS__) 55c0ded849SHemant Agrawal #else 56c0ded849SHemant Agrawal #define pr_debug(fmt, ...) do { } while (0) 57c0ded849SHemant Agrawal #endif 58c0ded849SHemant Agrawal #endif /* pr_debug */ 59c0ded849SHemant Agrawal 608bf3ff3cSNatanael Copa #if !defined(pr_err) 6169cb3917SNatanael Copa #define pr_err(fmt, ...) pr_msg(ERR, fmt, ##__VA_ARGS__) 62c0ded849SHemant Agrawal #endif /* pr_err */ 63c0ded849SHemant Agrawal 648bf3ff3cSNatanael Copa #if !defined(pr_warn) 6569cb3917SNatanael Copa #define pr_warn(fmt, ...) pr_msg(WARNING, fmt, ##__VA_ARGS__) 66c0ded849SHemant Agrawal #endif /* pr_warn */ 67c0ded849SHemant Agrawal 68c0ded849SHemant Agrawal /** 69c0ded849SHemant Agrawal * ARRAY_SIZE - returns the number of elements in an array 70c0ded849SHemant Agrawal * @x: array 71c0ded849SHemant Agrawal */ 72c0ded849SHemant Agrawal #ifndef ARRAY_SIZE 73c0ded849SHemant Agrawal #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 74c0ded849SHemant Agrawal #endif 75c0ded849SHemant Agrawal 76c0ded849SHemant Agrawal #ifndef ALIGN 77c0ded849SHemant Agrawal #define ALIGN(x, a) (((x) + ((__typeof__(x))(a) - 1)) & \ 78c0ded849SHemant Agrawal ~((__typeof__(x))(a) - 1)) 79c0ded849SHemant Agrawal #endif 80c0ded849SHemant Agrawal 81c0ded849SHemant Agrawal #ifndef BIT 82c0ded849SHemant Agrawal #define BIT(nr) (1UL << (nr)) 83c0ded849SHemant Agrawal #endif 84c0ded849SHemant Agrawal 85c0ded849SHemant Agrawal #ifndef upper_32_bits 86c0ded849SHemant Agrawal /** 87c0ded849SHemant Agrawal * upper_32_bits - return bits 32-63 of a number 88c0ded849SHemant Agrawal * @n: the number we're accessing 89c0ded849SHemant Agrawal */ 90c0ded849SHemant Agrawal #define upper_32_bits(n) ((uint32_t)(((n) >> 16) >> 16)) 91c0ded849SHemant Agrawal #endif 92c0ded849SHemant Agrawal 93c0ded849SHemant Agrawal #ifndef lower_32_bits 94c0ded849SHemant Agrawal /** 95c0ded849SHemant Agrawal * lower_32_bits - return bits 0-31 of a number 96c0ded849SHemant Agrawal * @n: the number we're accessing 97c0ded849SHemant Agrawal */ 98c0ded849SHemant Agrawal #define lower_32_bits(n) ((uint32_t)(n)) 99c0ded849SHemant Agrawal #endif 100c0ded849SHemant Agrawal 101c0ded849SHemant Agrawal /* Use Linux naming convention */ 1028bf3ff3cSNatanael Copa #if defined(RTE_EXEC_ENV_LINUX) || defined(__GLIBC__) 103c0ded849SHemant Agrawal #define swab16(x) rte_bswap16(x) 104c0ded849SHemant Agrawal #define swab32(x) rte_bswap32(x) 105c0ded849SHemant Agrawal #define swab64(x) rte_bswap64(x) 106c0ded849SHemant Agrawal /* Define cpu_to_be32 macro if not defined in the build environment */ 107c0ded849SHemant Agrawal #if !defined(cpu_to_be32) 108c0ded849SHemant Agrawal #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 109c0ded849SHemant Agrawal #define cpu_to_be32(x) (x) 110c0ded849SHemant Agrawal #else 111c0ded849SHemant Agrawal #define cpu_to_be32(x) swab32(x) 112c0ded849SHemant Agrawal #endif 113c0ded849SHemant Agrawal #endif 114c0ded849SHemant Agrawal /* Define cpu_to_le32 macro if not defined in the build environment */ 115c0ded849SHemant Agrawal #if !defined(cpu_to_le32) 116c0ded849SHemant Agrawal #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 117c0ded849SHemant Agrawal #define cpu_to_le32(x) swab32(x) 118c0ded849SHemant Agrawal #else 119c0ded849SHemant Agrawal #define cpu_to_le32(x) (x) 120c0ded849SHemant Agrawal #endif 121c0ded849SHemant Agrawal #endif 122c0ded849SHemant Agrawal #endif 123c0ded849SHemant Agrawal 124c0ded849SHemant Agrawal #endif /* __RTA_COMPAT_H__ */ 125