New upstream version 18.02
[deb_dpdk.git] / kernel / linux / kni / compat.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Minimal wrappers to allow compiling kni on older kernels.
4  */
5
6 #include <linux/version.h>
7
8 #ifndef RHEL_RELEASE_VERSION
9 #define RHEL_RELEASE_VERSION(a, b) (((a) << 8) + (b))
10 #endif
11
12 /* SuSE version macro is the same as Linux kernel version */
13 #ifndef SLE_VERSION
14 #define SLE_VERSION(a, b, c) KERNEL_VERSION(a, b, c)
15 #endif
16 #ifdef CONFIG_SUSE_KERNEL
17 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 57))
18 /* SLES12SP3 is at least 4.4.57+ based */
19 #define SLE_VERSION_CODE SLE_VERSION(12, 3, 0)
20 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 28))
21 /* SLES12 is at least 3.12.28+ based */
22 #define SLE_VERSION_CODE SLE_VERSION(12, 0, 0)
23 #elif ((LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 61)) && \
24         (LINUX_VERSION_CODE < KERNEL_VERSION(3, 1, 0)))
25 /* SLES11 SP3 is at least 3.0.61+ based */
26 #define SLE_VERSION_CODE SLE_VERSION(11, 3, 0)
27 #elif (LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 32))
28 /* SLES11 SP1 is 2.6.32 based */
29 #define SLE_VERSION_CODE SLE_VERSION(11, 1, 0)
30 #elif (LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 27))
31 /* SLES11 GA is 2.6.27 based */
32 #define SLE_VERSION_CODE SLE_VERSION(11, 0, 0)
33 #endif /* LINUX_VERSION_CODE == KERNEL_VERSION(x,y,z) */
34 #endif /* CONFIG_SUSE_KERNEL */
35 #ifndef SLE_VERSION_CODE
36 #define SLE_VERSION_CODE 0
37 #endif /* SLE_VERSION_CODE */
38
39
40 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39) && \
41         (!(defined(RHEL_RELEASE_CODE) && \
42            RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6, 4)))
43
44 #define kstrtoul strict_strtoul
45
46 #endif /* < 2.6.39 */
47
48 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33)
49 #define HAVE_SIMPLIFIED_PERNET_OPERATIONS
50 #endif
51
52 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
53 #define sk_sleep(s) ((s)->sk_sleep)
54 #else
55 #define HAVE_SOCKET_WQ
56 #endif
57
58 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)
59 #define HAVE_STATIC_SOCK_MAP_FD
60 #else
61 #define kni_sock_map_fd(s) sock_map_fd(s, 0)
62 #endif
63
64 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
65 #define HAVE_CHANGE_CARRIER_CB
66 #endif
67
68 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0)
69 #define ether_addr_copy(dst, src) memcpy(dst, src, ETH_ALEN)
70 #endif
71
72 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
73 #define HAVE_IOV_ITER_MSGHDR
74 #endif
75
76 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)
77 #define HAVE_KIOCB_MSG_PARAM
78 #define HAVE_REBUILD_HEADER
79 #endif
80
81 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
82 #define HAVE_SK_ALLOC_KERN_PARAM
83 #endif
84
85 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) || \
86         (defined(RHEL_RELEASE_CODE) && \
87          RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 4)) || \
88         (SLE_VERSION_CODE && SLE_VERSION_CODE == SLE_VERSION(12, 3, 0))
89 #define HAVE_TRANS_START_HELPER
90 #endif
91
92 /*
93  * KNI uses NET_NAME_UNKNOWN macro to select correct version of alloc_netdev()
94  * For old kernels just backported the commit that enables the macro
95  * (685343fc3ba6) but still uses old API, it is required to undefine macro to
96  * select correct version of API, this is safe since KNI doesn't use the value.
97  * This fix is specific to RedHat/CentOS kernels.
98  */
99 #if (defined(RHEL_RELEASE_CODE) && \
100         (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6, 8)) && \
101         (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34)))
102 #undef NET_NAME_UNKNOWN
103 #endif
104
105 #if (defined(RHEL_RELEASE_CODE) && \
106         (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 5)))
107 #define ndo_change_mtu ndo_change_mtu_rh74
108 #endif
109
110 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
111 #define HAVE_SIGNAL_FUNCTIONS_OWN_HEADER
112 #endif