1 /*
2 * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #ifndef _NET_DEFS_H_
16 #define _NET_DEFS_H_
17
18 #define __LINUX_ERRNO_EXTENSIONS__
19
20 #include "plat_types.h"
21 #ifdef RTOS
22 #include "cmsis.h"
23 #endif
24 #include <string.h>
25 #include "hal_location.h"
26
27 #ifndef __ASSEMBLY__
28
29 //#define NEED_KEEP
30
31 #ifndef USHRT_MAX
32 #define USHRT_MAX ((u16)(~0U))
33 #endif
34
35 #ifndef SHRT_MAX
36 #define SHRT_MAX ((s16)(USHRT_MAX>>1))
37 #endif
38
39 #ifndef SHRT_MIN
40 #define SHRT_MIN ((s16)(-SHRT_MAX - 1))
41 #endif
42
43 #ifndef INT_MAX
44 #define INT_MAX ((int)(~0U>>1))
45 #endif
46
47 #ifndef INT_MIN
48 #define INT_MIN (-INT_MAX - 1)
49 #endif
50
51 #ifndef UINT_MAX
52 #define UINT_MAX (~0U)
53 #endif
54
55 #ifndef LONG_MAX
56 #define LONG_MAX ((long)(~0UL>>1))
57 #endif
58
59 #ifndef LONG_MIN
60 #define LONG_MIN (-LONG_MAX - 1)
61 #endif
62
63 #ifndef ULONG_MAX
64 #define ULONG_MAX (~0UL)
65 #endif
66
67 #ifndef LLONG_MIN
68 #define LLONG_MIN (-LLONG_MAX - 1)
69 #endif
70
71 #ifndef ULLONG_MAX
72 #define ULLONG_MAX (~0ULL)
73 #endif
74
75 #define N_FALSE 0
76 #define N_TRUE (!N_FALSE)
77
78 #define BIT(nr) (1UL << (nr))
79
80 #define MAX_SCHEDULE_TIMEOUT (osWaitForever)
81
82 #ifndef min
83 #define min(a,b) (((a) < (b)) ? (a) : (b))
84 #endif /* min */
85
86 #ifndef max
87 #define max(a,b) (((a) > (b)) ? (a) : (b))
88 #endif /* max */
89
90 #define min_t(type, x, y) ({ \
91 type __min1 = (x); \
92 type __min2 = (y); \
93 __min1 < __min2 ? __min1: __min2; })
94
95 #define max_t(type, x, y) ({ \
96 type __max1 = (x); \
97 type __max2 = (y); \
98 __max1 > __max2 ? __max1: __max2; })
99
100 #ifndef NULL
101 #define NULL ((void *) 0)
102 #endif
103
104 //#ifndef __PLAT_TYPES_H__
105 typedef char __s8;
106 typedef unsigned char __u8;
107
108 typedef short __s16;
109 typedef unsigned short __u16;
110
111 typedef int __s32;
112 typedef unsigned int __u32;
113
114 typedef long long __s64;
115 //#endif
116 typedef unsigned long long __u64;
117
118 //#ifndef __PLAT_TYPES_H__
119 typedef unsigned char UCHAR;
120 typedef signed char CHAR;
121 typedef unsigned char *PUCHAR;
122 typedef signed char *PCHAR;
123
124 typedef unsigned char UINT8;
125 typedef unsigned short UINT16;
126 typedef unsigned int UINT32;
127
128 typedef char INT8;
129 typedef short INT16;
130 typedef int INT32;
131
132 typedef unsigned char u8_t;
133 typedef signed char s8_t;
134 typedef unsigned short u16_t;
135 typedef signed short s16_t;
136 typedef unsigned int u32_t;
137 typedef signed int s32_t;
138 //#endif
139
140 typedef unsigned char uint8;
141 typedef signed char int8;
142 typedef unsigned short uint16;
143 typedef signed short int16;
144 typedef unsigned int uint32;
145 typedef signed int int32;
146
147 /*
148 * Below are truly Linux-specific types that should never collide with
149 * any application/library that wants linux/types.h.
150 */
151
152 #ifdef __CHECKER__
153 #define __bitwise__ __attribute__((bitwise))
154 #else
155 #define __bitwise__
156 #endif
157 #ifdef __CHECK_ENDIAN__
158 #define __bitwise __bitwise__
159 #else
160 #define __bitwise
161 #endif
162
163 //#ifndef __PLAT_TYPES_H__
164 typedef __u16 __bitwise __le16;
165 typedef __u16 __bitwise __be16;
166 typedef __u32 __bitwise __le32;
167 typedef __u32 __bitwise __be32;
168 typedef __u64 __bitwise __le64;
169 //#endif
170 typedef __u64 __bitwise __be64;
171
172 typedef __u16 __bitwise __sum16;
173 typedef __u32 __bitwise __wsum;
174
175
176 /*
177 * aligned_u64 should be used in defining kernel<->userspace ABIs to avoid
178 * common 32/64-bit compat problems.
179 * 64-bit values align to 4-byte boundaries on x86_32 (and possibly other
180 * architectures) and to 8-byte boundaries on 64-bit architectures. The new
181 * aligned_64 type enforces 8-byte alignment so that structs containing
182 * aligned_64 values have the same alignment on 32-bit and 64-bit architectures.
183 * No conversions are necessary between 32-bit user-space and a 64-bit kernel.
184 */
185 #define __aligned_16 __attribute__((aligned(2)))
186 #define __aligned_u16 __u16 __attribute__((aligned(2)))
187 #define __aligned_u32 __u32 __attribute__((aligned(4)))
188 #define __aligned_u64 __u64 __attribute__((aligned(8)))
189 #define __aligned_be64 __be64 __attribute__((aligned(8)))
190 #define __aligned_le64 __le64 __attribute__((aligned(8)))
191
192 #define __init
193 #define __must_check
194 #ifndef __pure
195 #define __pure
196 #endif
197 #define might_sleep()
198 #ifndef offsetof
199 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
200 #endif
201 #define likely(x) (x)
202 #define unlikely(x) (x)
203
204 #define PTR_ERR(x) ((int)x)
205 #define IS_ERR(x) (((int)x > 0)?N_FALSE:N_TRUE)
206
207 #define __RX_CODE SRAM_TEXT_LOC
208
209 #ifndef _ALIGN
210 #define _ALIGN(val,exp) (((val) + ((exp)-1)) & ~((exp)-1))
211 #endif
212 #ifndef ARRAY_SIZE
213 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
214 #endif
215
216
217 typedef struct {
218 int counter;
219 } atomic32_t;
220
221 typedef struct {
222 uint64_t counter;
223 } atomic64_t;
224
225 typedef enum {
226 GFP_KERNEL = 0,
227 GFP_ATOMIC,
228 __GFP_HIGHMEM,
229 __GFP_HIGH
230 } gfp_t;
231
232 #define GFP_DMA GFP_KERNEL
233
234 #define barrier
235 #define EXPORT_SYMBOL(x)
236 #define EXPORT_SYMBOL_GPL(x)
237
238 #define smp_mb(x)
239
240 #define net_swap(a, b) \
241 do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
242
243 #ifndef container_of
244 #define container_of(ptr, type, member) \
245 ((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
246 #endif
247
248 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
249 /**
250 * struct rcu_head - callback structure for use with RCU
251 * @next: next update requests in a list
252 * @func: actual update function to call after the grace period.
253 */
254 struct rcu_head {
255 struct rcu_head *next;
256 void (*func)(struct rcu_head *head);
257 };
258
ERR_PTR(long error)259 static inline void *__must_check ERR_PTR(long error)
260 {
261 return (void *) error;
262 }
263
264 #define BITS_PER_LONG 32
265
266 /* Defined for the NFSv3 protocol */
267 #define EBADHANDLE 521 /* Illegal NFS file handle */
268 #define ENOTSYNC 522 /* Update synchronization mismatch */
269 #define EBADCOOKIE 523 /* Cookie is stale */
270 #define ENOTSUPP 524 /* Operation is not supported */
271 #define ETOOSMALL 525 /* Buffer or request is too small */
272 #define ESERVERFAULT 526 /* An untranslatable error occurred */
273 #define EBADTYPE 527 /* Type not supported by server */
274 #define EJUKEBOX 528 /* Request initiated, but will not complete before timeout */
275 #define EIOCBQUEUED 529 /* iocb queued, will get completion event */
276
277 typedef struct {
278 unsigned int tm_year;
279 unsigned int tm_mon;
280 unsigned int tm_mday;
281 unsigned int tm_hour;
282 unsigned int tm_min;
283 unsigned int tm_sec;
284 bool tm_isdst;
285 } tm_t;
286
287 #endif /* __ASSEMBLY__ */
288 #endif /* _NET_DEFS_H_ */
289
290