1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Minimal wrappers to allow compiling kni on older kernels.
6 #include <linux/version.h>
8 #ifndef RHEL_RELEASE_VERSION
9 #define RHEL_RELEASE_VERSION(a, b) (((a) << 8) + (b))
12 /* SuSE version macro is the same as Linux kernel version */
14 #define SLE_VERSION(a, b, c) KERNEL_VERSION(a, b, c)
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 */
40 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39) && \
41 (!(defined(RHEL_RELEASE_CODE) && \
42 RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6, 4)))
44 #define kstrtoul strict_strtoul
48 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33)
49 #define HAVE_SIMPLIFIED_PERNET_OPERATIONS
52 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
53 #define sk_sleep(s) ((s)->sk_sleep)
55 #define HAVE_SOCKET_WQ
58 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)
59 #define HAVE_STATIC_SOCK_MAP_FD
61 #define kni_sock_map_fd(s) sock_map_fd(s, 0)
64 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
65 #define HAVE_CHANGE_CARRIER_CB
68 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0)
69 #define ether_addr_copy(dst, src) memcpy(dst, src, ETH_ALEN)
72 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
73 #define HAVE_IOV_ITER_MSGHDR
76 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)
77 #define HAVE_KIOCB_MSG_PARAM
78 #define HAVE_REBUILD_HEADER
81 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
82 #define HAVE_SK_ALLOC_KERN_PARAM
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
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.
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
106 * RHEL has two different version with different kernel version:
107 * 3.10 is for AMD, Intel, IBM POWER7 and POWER8;
108 * 4.14 is for ARM and IBM POWER9
110 #if (defined(RHEL_RELEASE_CODE) && \
111 (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 5)) && \
112 (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(8, 0)) && \
113 (LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)))
114 #define ndo_change_mtu ndo_change_mtu_rh74
117 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
118 #define HAVE_MAX_MTU_PARAM
121 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
122 #define HAVE_SIGNAL_FUNCTIONS_OWN_HEADER
126 * iova to kva mapping support can be provided since 4.6.0, but required
127 * kernel version increased to >= 4.10.0 because of the updates in
128 * get_user_pages_remote() kernel API
130 #if KERNEL_VERSION(4, 10, 0) <= LINUX_VERSION_CODE
131 #define HAVE_IOVA_TO_KVA_MAPPING_SUPPORT
134 #if KERNEL_VERSION(5, 6, 0) <= LINUX_VERSION_CODE
135 #define HAVE_TX_TIMEOUT_TXQUEUE