crypto/dpaa2_sec: add run-time assembler for descriptor
[dpdk.git] / drivers / crypto / dpaa2_sec / hw / compat.h
1 /*
2  * Copyright 2013-2016 Freescale Semiconductor, Inc.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause or GPL-2.0+
5  */
6
7 #ifndef __RTA_COMPAT_H__
8 #define __RTA_COMPAT_H__
9
10 #include <stdint.h>
11 #include <errno.h>
12
13 #ifdef __GLIBC__
14 #include <string.h>
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <stdbool.h>
18 #include <rte_byteorder.h>
19
20 #ifndef __BYTE_ORDER__
21 #error "Undefined endianness"
22 #endif
23
24 #else
25 #error Environment not supported!
26 #endif
27
28 #ifndef __always_inline
29 #define __always_inline (inline __attribute__((always_inline)))
30 #endif
31
32 #ifndef __always_unused
33 #define __always_unused __attribute__((unused))
34 #endif
35
36 #ifndef __maybe_unused
37 #define __maybe_unused __attribute__((unused))
38 #endif
39
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__)
44 #else
45 #define pr_debug(fmt, ...)     do { } while (0)
46 #endif
47 #endif /* pr_debug */
48
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__)
53 #else
54 #define pr_err(fmt, ...)    do { } while (0)
55 #endif
56 #endif /* pr_err */
57
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__)
62 #else
63 #define pr_warn(fmt, ...)    do { } while (0)
64 #endif
65 #endif /* pr_warn */
66
67 /**
68  * ARRAY_SIZE - returns the number of elements in an array
69  * @x: array
70  */
71 #ifndef ARRAY_SIZE
72 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
73 #endif
74
75 #ifndef ALIGN
76 #define ALIGN(x, a) (((x) + ((__typeof__(x))(a) - 1)) & \
77                         ~((__typeof__(x))(a) - 1))
78 #endif
79
80 #ifndef BIT
81 #define BIT(nr)         (1UL << (nr))
82 #endif
83
84 #ifndef upper_32_bits
85 /**
86  * upper_32_bits - return bits 32-63 of a number
87  * @n: the number we're accessing
88  */
89 #define upper_32_bits(n) ((uint32_t)(((n) >> 16) >> 16))
90 #endif
91
92 #ifndef lower_32_bits
93 /**
94  * lower_32_bits - return bits 0-31 of a number
95  * @n: the number we're accessing
96  */
97 #define lower_32_bits(n) ((uint32_t)(n))
98 #endif
99
100 /* Use Linux naming convention */
101 #ifdef __GLIBC__
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)
109                 #else
110                         #define cpu_to_be32(x)  swab32(x)
111                 #endif
112         #endif
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)
117                 #else
118                         #define cpu_to_le32(x)  (x)
119                 #endif
120         #endif
121 #endif
122
123 #endif /* __RTA_COMPAT_H__ */