xref: /dpdk/kernel/linux/kni/compat.h (revision c28e2165)
17aa838bcSHemant Agrawal /* SPDX-License-Identifier: GPL-2.0 */
2acaa9ee9SHemant Agrawal /*
3acaa9ee9SHemant Agrawal  * Minimal wrappers to allow compiling kni on older kernels.
4acaa9ee9SHemant Agrawal  */
5acaa9ee9SHemant Agrawal 
6acaa9ee9SHemant Agrawal #include <linux/version.h>
7acaa9ee9SHemant Agrawal 
8acaa9ee9SHemant Agrawal #ifndef RHEL_RELEASE_VERSION
9acaa9ee9SHemant Agrawal #define RHEL_RELEASE_VERSION(a, b) (((a) << 8) + (b))
10acaa9ee9SHemant Agrawal #endif
11acaa9ee9SHemant Agrawal 
12acaa9ee9SHemant Agrawal /* SuSE version macro is the same as Linux kernel version */
13acaa9ee9SHemant Agrawal #ifndef SLE_VERSION
14acaa9ee9SHemant Agrawal #define SLE_VERSION(a, b, c) KERNEL_VERSION(a, b, c)
15acaa9ee9SHemant Agrawal #endif
16acaa9ee9SHemant Agrawal #ifdef CONFIG_SUSE_KERNEL
17acaa9ee9SHemant Agrawal #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 57))
18acaa9ee9SHemant Agrawal /* SLES12SP3 is at least 4.4.57+ based */
19acaa9ee9SHemant Agrawal #define SLE_VERSION_CODE SLE_VERSION(12, 3, 0)
20acaa9ee9SHemant Agrawal #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 28))
21acaa9ee9SHemant Agrawal /* SLES12 is at least 3.12.28+ based */
22acaa9ee9SHemant Agrawal #define SLE_VERSION_CODE SLE_VERSION(12, 0, 0)
23acaa9ee9SHemant Agrawal #elif ((LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 61)) && \
24acaa9ee9SHemant Agrawal 	(LINUX_VERSION_CODE < KERNEL_VERSION(3, 1, 0)))
25acaa9ee9SHemant Agrawal /* SLES11 SP3 is at least 3.0.61+ based */
26acaa9ee9SHemant Agrawal #define SLE_VERSION_CODE SLE_VERSION(11, 3, 0)
27acaa9ee9SHemant Agrawal #elif (LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 32))
28acaa9ee9SHemant Agrawal /* SLES11 SP1 is 2.6.32 based */
29acaa9ee9SHemant Agrawal #define SLE_VERSION_CODE SLE_VERSION(11, 1, 0)
30acaa9ee9SHemant Agrawal #elif (LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 27))
31acaa9ee9SHemant Agrawal /* SLES11 GA is 2.6.27 based */
32acaa9ee9SHemant Agrawal #define SLE_VERSION_CODE SLE_VERSION(11, 0, 0)
33acaa9ee9SHemant Agrawal #endif /* LINUX_VERSION_CODE == KERNEL_VERSION(x,y,z) */
34acaa9ee9SHemant Agrawal #endif /* CONFIG_SUSE_KERNEL */
35acaa9ee9SHemant Agrawal #ifndef SLE_VERSION_CODE
36acaa9ee9SHemant Agrawal #define SLE_VERSION_CODE 0
37acaa9ee9SHemant Agrawal #endif /* SLE_VERSION_CODE */
38acaa9ee9SHemant Agrawal 
39acaa9ee9SHemant Agrawal 
40acaa9ee9SHemant Agrawal #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39) && \
41acaa9ee9SHemant Agrawal 	(!(defined(RHEL_RELEASE_CODE) && \
42acaa9ee9SHemant Agrawal 	   RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6, 4)))
43acaa9ee9SHemant Agrawal 
44acaa9ee9SHemant Agrawal #define kstrtoul strict_strtoul
45acaa9ee9SHemant Agrawal 
46acaa9ee9SHemant Agrawal #endif /* < 2.6.39 */
47acaa9ee9SHemant Agrawal 
48acaa9ee9SHemant Agrawal #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33)
49acaa9ee9SHemant Agrawal #define HAVE_SIMPLIFIED_PERNET_OPERATIONS
50acaa9ee9SHemant Agrawal #endif
51acaa9ee9SHemant Agrawal 
52acaa9ee9SHemant Agrawal #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
53acaa9ee9SHemant Agrawal #define sk_sleep(s) ((s)->sk_sleep)
54acaa9ee9SHemant Agrawal #else
55acaa9ee9SHemant Agrawal #define HAVE_SOCKET_WQ
56acaa9ee9SHemant Agrawal #endif
57acaa9ee9SHemant Agrawal 
58acaa9ee9SHemant Agrawal #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)
59acaa9ee9SHemant Agrawal #define HAVE_STATIC_SOCK_MAP_FD
60acaa9ee9SHemant Agrawal #else
61acaa9ee9SHemant Agrawal #define kni_sock_map_fd(s) sock_map_fd(s, 0)
62acaa9ee9SHemant Agrawal #endif
63acaa9ee9SHemant Agrawal 
64acaa9ee9SHemant Agrawal #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
65acaa9ee9SHemant Agrawal #define HAVE_CHANGE_CARRIER_CB
66acaa9ee9SHemant Agrawal #endif
67acaa9ee9SHemant Agrawal 
68acaa9ee9SHemant Agrawal #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0)
69acaa9ee9SHemant Agrawal #define ether_addr_copy(dst, src) memcpy(dst, src, ETH_ALEN)
70acaa9ee9SHemant Agrawal #endif
71acaa9ee9SHemant Agrawal 
72acaa9ee9SHemant Agrawal #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
73acaa9ee9SHemant Agrawal #define HAVE_IOV_ITER_MSGHDR
74acaa9ee9SHemant Agrawal #endif
75acaa9ee9SHemant Agrawal 
76acaa9ee9SHemant Agrawal #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)
77acaa9ee9SHemant Agrawal #define HAVE_KIOCB_MSG_PARAM
78acaa9ee9SHemant Agrawal #define HAVE_REBUILD_HEADER
79acaa9ee9SHemant Agrawal #endif
80acaa9ee9SHemant Agrawal 
81acaa9ee9SHemant Agrawal #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
82acaa9ee9SHemant Agrawal #define HAVE_SK_ALLOC_KERN_PARAM
83acaa9ee9SHemant Agrawal #endif
84acaa9ee9SHemant Agrawal 
85acaa9ee9SHemant Agrawal #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) || \
86acaa9ee9SHemant Agrawal 	(defined(RHEL_RELEASE_CODE) && \
87acaa9ee9SHemant Agrawal 	 RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 4)) || \
88acaa9ee9SHemant Agrawal 	(SLE_VERSION_CODE && SLE_VERSION_CODE == SLE_VERSION(12, 3, 0))
89acaa9ee9SHemant Agrawal #define HAVE_TRANS_START_HELPER
90acaa9ee9SHemant Agrawal #endif
91acaa9ee9SHemant Agrawal 
92acaa9ee9SHemant Agrawal /*
93acaa9ee9SHemant Agrawal  * KNI uses NET_NAME_UNKNOWN macro to select correct version of alloc_netdev()
94acaa9ee9SHemant Agrawal  * For old kernels just backported the commit that enables the macro
95acaa9ee9SHemant Agrawal  * (685343fc3ba6) but still uses old API, it is required to undefine macro to
96acaa9ee9SHemant Agrawal  * select correct version of API, this is safe since KNI doesn't use the value.
97acaa9ee9SHemant Agrawal  * This fix is specific to RedHat/CentOS kernels.
98acaa9ee9SHemant Agrawal  */
99acaa9ee9SHemant Agrawal #if (defined(RHEL_RELEASE_CODE) && \
100acaa9ee9SHemant Agrawal 	(RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6, 8)) && \
101acaa9ee9SHemant Agrawal 	(LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34)))
102acaa9ee9SHemant Agrawal #undef NET_NAME_UNKNOWN
103acaa9ee9SHemant Agrawal #endif
104acaa9ee9SHemant Agrawal 
1053d5501d5SDavid Zeng /*
1063d5501d5SDavid Zeng  * RHEL has two different version with different kernel version:
1073d5501d5SDavid Zeng  * 3.10 is for AMD, Intel, IBM POWER7 and POWER8;
1083d5501d5SDavid Zeng  * 4.14 is for ARM and IBM POWER9
1093d5501d5SDavid Zeng  */
11037d477b6SLee Roberts #if (defined(RHEL_RELEASE_CODE) && \
1114c820b22SXiao Liang 	(RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 5)) && \
1123d5501d5SDavid Zeng 	(RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(8, 0)) && \
1133d5501d5SDavid Zeng 	(LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)))
11437d477b6SLee Roberts #define ndo_change_mtu ndo_change_mtu_rh74
11537d477b6SLee Roberts #endif
11637d477b6SLee Roberts 
117ff1e35fbSLiron Himi #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
118ff1e35fbSLiron Himi #define HAVE_MAX_MTU_PARAM
119ff1e35fbSLiron Himi #endif
120ff1e35fbSLiron Himi 
121acaa9ee9SHemant Agrawal #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
122acaa9ee9SHemant Agrawal #define HAVE_SIGNAL_FUNCTIONS_OWN_HEADER
123acaa9ee9SHemant Agrawal #endif
124e73831dcSVamsi Attunuru 
125d965af9eSFerruh Yigit /*
126d965af9eSFerruh Yigit  * iova to kva mapping support can be provided since 4.6.0, but required
127de480bbfSFerruh Yigit  * kernel version increased to >= 4.10.0 because of the updates in
128d965af9eSFerruh Yigit  * get_user_pages_remote() kernel API
129d965af9eSFerruh Yigit  */
130de480bbfSFerruh Yigit #if KERNEL_VERSION(4, 10, 0) <= LINUX_VERSION_CODE
131e73831dcSVamsi Attunuru #define HAVE_IOVA_TO_KVA_MAPPING_SUPPORT
132e73831dcSVamsi Attunuru #endif
13338ad54f3SFerruh Yigit 
13495e08719SOlivier Matz #if KERNEL_VERSION(5, 6, 0) <= LINUX_VERSION_CODE || \
13595e08719SOlivier Matz 	(defined(RHEL_RELEASE_CODE) && \
136*c28e2165SAman Singh 	 RHEL_RELEASE_VERSION(8, 3) <= RHEL_RELEASE_CODE) || \
137*c28e2165SAman Singh 	 (defined(CONFIG_SUSE_KERNEL) && defined(HAVE_ARG_TX_QUEUE))
13838ad54f3SFerruh Yigit #define HAVE_TX_TIMEOUT_TXQUEUE
13938ad54f3SFerruh Yigit #endif
14087efaea6SFerruh Yigit 
14187efaea6SFerruh Yigit #if KERNEL_VERSION(5, 9, 0) > LINUX_VERSION_CODE
14287efaea6SFerruh Yigit #define HAVE_TSK_IN_GUP
14387efaea6SFerruh Yigit #endif
144