common/cnxk: check BPHY IRQ availability
[dpdk.git] / drivers / common / dpaax / caamflib / compat.h
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 RTE_EXEC_ENV_LINUX
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 /* !RTE_EXEC_ENV_LINUX */
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(SUPPRESS_PRINTS)
44 #define pr_msg(l, fmt, ...) do { } while (0)
45 #else
46 #define pr_msg(l, fmt, ...) \
47         RTE_LOG(l, PMD, "%s(): " fmt "\n", __func__, ##__VA_ARGS__)
48 #endif
49
50 #if !defined(pr_debug)
51 #if defined(RTA_DEBUG)
52 #define pr_debug(fmt, ...) pr_msg(DEBUG, fmt, ##__VA_ARGS__)
53 #else
54 #define pr_debug(fmt, ...) do { } while (0)
55 #endif
56 #endif /* pr_debug */
57
58 #if !defined(pr_err)
59 #define pr_err(fmt, ...) pr_msg(ERR, fmt, ##__VA_ARGS__)
60 #endif /* pr_err */
61
62 #if !defined(pr_warn)
63 #define pr_warn(fmt, ...) pr_msg(WARNING, fmt, ##__VA_ARGS__)
64 #endif /* pr_warn */
65
66 /**
67  * ARRAY_SIZE - returns the number of elements in an array
68  * @x: array
69  */
70 #ifndef ARRAY_SIZE
71 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
72 #endif
73
74 #ifndef ALIGN
75 #define ALIGN(x, a) (((x) + ((__typeof__(x))(a) - 1)) & \
76                         ~((__typeof__(x))(a) - 1))
77 #endif
78
79 #ifndef BIT
80 #define BIT(nr)         (1UL << (nr))
81 #endif
82
83 #ifndef upper_32_bits
84 /**
85  * upper_32_bits - return bits 32-63 of a number
86  * @n: the number we're accessing
87  */
88 #define upper_32_bits(n) ((uint32_t)(((n) >> 16) >> 16))
89 #endif
90
91 #ifndef lower_32_bits
92 /**
93  * lower_32_bits - return bits 0-31 of a number
94  * @n: the number we're accessing
95  */
96 #define lower_32_bits(n) ((uint32_t)(n))
97 #endif
98
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)
108                 #else
109                         #define cpu_to_be32(x)  swab32(x)
110                 #endif
111         #endif
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)
116                 #else
117                         #define cpu_to_le32(x)  (x)
118                 #endif
119         #endif
120 #endif
121
122 #endif /* __RTA_COMPAT_H__ */