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