]>
Commit | Line | Data |
---|---|---|
11fdf7f2 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
7c673cae FG |
2 | /* |
3 | * Minimal wrappers to allow compiling kni on older kernels. | |
4 | */ | |
5 | ||
11fdf7f2 TL |
6 | #include <linux/version.h> |
7 | ||
7c673cae FG |
8 | #ifndef RHEL_RELEASE_VERSION |
9 | #define RHEL_RELEASE_VERSION(a, b) (((a) << 8) + (b)) | |
10 | #endif | |
11 | ||
11fdf7f2 TL |
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 | ||
7c673cae FG |
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 | ||
11fdf7f2 TL |
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)) | |
7c673cae FG |
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 | |
11fdf7f2 | 104 | |
9f95a23c TL |
105 | /* |
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 | |
109 | */ | |
11fdf7f2 | 110 | #if (defined(RHEL_RELEASE_CODE) && \ |
9f95a23c TL |
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))) | |
11fdf7f2 TL |
114 | #define ndo_change_mtu ndo_change_mtu_rh74 |
115 | #endif | |
116 | ||
9f95a23c TL |
117 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) |
118 | #define HAVE_MAX_MTU_PARAM | |
119 | #endif | |
120 | ||
11fdf7f2 TL |
121 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) |
122 | #define HAVE_SIGNAL_FUNCTIONS_OWN_HEADER | |
123 | #endif | |
f67539c2 TL |
124 | |
125 | /* | |
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 | |
129 | */ | |
130 | #if KERNEL_VERSION(4, 10, 0) <= LINUX_VERSION_CODE | |
131 | #define HAVE_IOVA_TO_KVA_MAPPING_SUPPORT | |
132 | #endif | |
133 | ||
134 | #if KERNEL_VERSION(5, 6, 0) <= LINUX_VERSION_CODE | |
135 | #define HAVE_TX_TIMEOUT_TXQUEUE | |
136 | #endif |