4 /* Parts taken from the Linux kernel, GPL, version 2. */
6 #include <linux/if_packet.h>
10 #include <asm/byteorder.h>
18 #ifndef CO_CACHE_LINE_SIZE
19 # define CO_CACHE_LINE_SIZE (1 << CO_IN_CACHE_SHIFT)
23 # define __aligned_16 __attribute__((aligned(16)))
26 #ifndef __cacheline_aligned
27 # define __cacheline_aligned __attribute__((aligned(CO_CACHE_LINE_SIZE)))
30 #ifndef __aligned_tpacket
31 # define __aligned_tpacket __attribute__((aligned(TPACKET_ALIGNMENT)))
34 #ifndef __align_tpacket
35 # define __align_tpacket(x) __attribute__((aligned(TPACKET_ALIGN(x))))
38 #ifndef __check_format_printf
39 # define __check_format_printf(pos_fmtstr, pos_fmtargs) \
40 __attribute__ ((format (printf, (pos_fmtstr), (pos_fmtargs))))
44 # define __packed __attribute__((packed))
48 # define round_up(x, alignment) (((x) + (alignment) - 1) & ~((alignment) - 1))
51 #ifndef round_up_cacheline
52 # define round_up_cacheline(x) round_up((x), CO_CACHE_LINE_SIZE)
56 # define likely(x) __builtin_expect(!!(x), 1)
60 # define unlikely(x) __builtin_expect(!!(x), 0)
64 # define constant(x) __builtin_constant_p(x)
68 # define fmemset __builtin_memset
72 # define fmemcpy __builtin_memcpy
75 #ifndef __maybe_unused
76 # define __maybe_unused __attribute__ ((__unused__))
80 # define noinline __attribute__((noinline))
84 # define __noreturn __attribute__((noreturn))
88 # define __hidden __attribute__((visibility("hidden")))
92 # define __pure __attribute__ ((pure))
96 # define __force /* unimplemented */
99 /* see config_enabled et al. in linux/kconfig.h for details. */
100 #define __ARG_PLACEHOLDER_1 0,
101 #define is_defined(cfg) _is_defined(cfg)
102 #define _is_defined(value) __is_defined(__ARG_PLACEHOLDER_##value)
103 #define __is_defined(arg1_or_junk) ___is_defined(arg1_or_junk 1, 0)
104 #define ___is_defined(__ignored, val, ...) val
109 typeof (a) _a = (a); \
110 typeof (b) _b = (b); \
116 # define max_t(type, a, b) \
118 type ___max1 = (a); \
119 type ___max2 = (b); \
120 ___max1 > ___max2 ? ___max1 : ___max2; \
127 typeof (a) _a = (a); \
128 typeof (b) _b = (b); \
134 # define min_t(type, a, b) \
136 type ___min1 = (a); \
137 type ___min2 = (b); \
138 ___min1 < ___min2 ? ___min1 : ___min2; \
143 # define ispow2(x) ({ !!((x) && !((x) & ((x) - 1))); })
147 # define offsetof(type, member) ((size_t) &((type *) 0)->member)
151 # define container_of(ptr, type, member) \
153 const typeof(((type *) 0)->member) * __mptr = (ptr); \
154 (type *) ((char *) __mptr - offsetof(type, member)); \
159 # define array_size(x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x))
162 #ifndef __must_be_array
163 # define __must_be_array(x) \
164 build_bug_on_zero(__builtin_types_compatible_p(typeof(x), \
168 #ifndef build_bug_on_zero
169 # define build_bug_on_zero(e) (sizeof(char[1 - 2 * !!(e)]) - 1)
173 # define build_bug_on(e) ((void)sizeof(char[1 - 2*!!(e)]))
177 # define bug_on(cond) assert(!(cond))
181 # define bug() assert(0)
184 #define RUNTIME_PAGE_SIZE (sysconf(_SC_PAGE_SIZE))
185 #define PAGE_MASK (~(RUNTIME_PAGE_SIZE - 1))
186 #define PAGE_ALIGN(addr) (((addr) + RUNTIME_PAGE_SIZE - 1) & PAGE_MASK)
188 #if __BYTE_ORDER == __LITTLE_ENDIAN
189 static inline uint64_t htonll(uint64_t x
)
194 static inline uint64_t ntohll(uint64_t x
)
198 #elif __BYTE_ORDER == __BIG_ENDIAN
199 static inline uint64_t htonll(uint64_t x
)
204 static inline uint64_t ntohll(uint64_t x
)
209 # error __BYTE_ORDER is neither __LITTLE_ENDIAN nor __BIG_ENDIAN
211 #ifndef ___constant_swab16
212 # define ___constant_swab16(x) ((__u16)( \
213 (((__u16)(x) & (__u16)0x00ffU) << 8) | \
214 (((__u16)(x) & (__u16)0xff00U) >> 8)))
216 #ifndef ___constant_swab32
217 # define ___constant_swab32(x) ((__u32)( \
218 (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
219 (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
220 (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
221 (((__u32)(x) & (__u32)0xff000000UL) >> 24)))
223 #if __BYTE_ORDER == __LITTLE_ENDIAN
224 static inline u16
cpu_to_be16(u16 val
)
226 return bswap_16(val
);
229 static inline u32
cpu_to_be32(u32 val
)
231 return bswap_32(val
);
234 static inline u64
cpu_to_be64(u64 val
)
236 return bswap_64(val
);
239 static inline u16
cpu_to_le16(u16 val
)
244 static inline u32
cpu_to_le32(u32 val
)
249 static inline u64
cpu_to_le64(u64 val
)
254 # ifndef __constant_htonl
255 # define __constant_htonl(x) ((__force __be32)___constant_swab32((x)))
257 # ifndef __constant_ntohl
258 # define __constant_ntohl(x) ___constant_swab32((__force __be32)(x))
260 # ifndef __constant_htons
261 # define __constant_htons(x) ((__force __be16)___constant_swab16((x)))
263 # ifndef __constant_ntohs
264 # define __constant_ntohs(x) ___constant_swab16((__force __be16)(x))
266 #elif __BYTE_ORDER == __BIG_ENDIAN
267 static inline u16
cpu_to_be16(u16 val
)
272 static inline u32
cpu_to_be32(u32 val
)
277 static inline u64
cpu_to_be64(u64 val
)
282 static inline u16
cpu_to_le16(u16 val
)
284 return bswap_16(val
);
287 static inline u32
cpu_to_le32(u32 val
)
289 return bswap_32(val
);
292 static inline u64
cpu_to_le64(u64 val
)
294 return bswap_64(val
);
297 # ifndef __constant_htonl
298 # define __constant_htonl(x) ((__force __be32)(__u32)(x))
300 # ifndef __constant_ntohl
301 # define __constant_ntohl(x) ((__force __u32)(__be32)(x))
303 # ifndef __constant_htons
304 # define __constant_htons(x) ((__force __be16)(__u16)(x))
306 # ifndef __constant_ntohs
307 # define __constant_ntohs(x) ((__force __u16)(__be16)(x))
310 # error __BYTE_ORDER is neither __LITTLE_ENDIAN nor __BIG_ENDIAN
313 #define le64_to_cpu cpu_to_le64
314 #define le32_to_cpu cpu_to_le32
315 #define le16_to_cpu cpu_to_le16
316 #define be64_to_cpu cpu_to_be64
317 #define be32_to_cpu cpu_to_be32
318 #define be16_to_cpu cpu_to_be16
323 #define memset fmemset
324 #define memcpy fmemcpy
326 #if defined(__amd64__) || defined(__x86_64__) || defined(__AMD64__) || \
327 defined(_M_X64) || defined(__amd64)
328 # define CO_IN_CACHE_SHIFT 7
329 #elif defined(__i386__) || defined(__x86__) || defined(__X86__) || \
330 defined(_M_IX86) || defined(__i386)
331 # define CO_IN_CACHE_SHIFT 7
332 #elif defined(__ia64__) || defined(__IA64__) || defined(__M_IA64)
333 # define CO_IN_CACHE_SHIFT 6
334 #elif defined(__SPU__)
335 # define CO_IN_CACHE_SHIFT 7
336 #elif defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || \
338 # define CO_IN_CACHE_SHIFT 8
339 #elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || \
341 # define CO_IN_CACHE_SHIFT 7
342 #elif defined(__sparcv9__) || defined(__sparcv9)
343 # define CO_IN_CACHE_SHIFT 6
344 #elif defined(__sparc_v8__)
345 # define CO_IN_CACHE_SHIFT 5
346 #elif defined(__sparc__) || defined(__sparc)
347 # define CO_IN_CACHE_SHIFT 5
348 #elif defined(__ARM_EABI__)
349 # define CO_IN_CACHE_SHIFT 5
350 #elif defined(__arm__)
351 # define CO_IN_CACHE_SHIFT 5
352 #elif defined(__mips__) || defined(__mips) || defined(__MIPS__)
353 # if defined(_ABIO32)
354 # define CO_IN_CACHE_SHIFT 5
355 # elif defined(_ABIN32)
356 # define CO_IN_CACHE_SHIFT 5
358 # define CO_IN_CACHE_SHIFT 6
361 # define CO_IN_CACHE_SHIFT 5
364 #ifndef TP_STATUS_TS_SOFTWARE
365 # define TP_STATUS_TS_SOFTWARE (1 << 29)
368 #ifndef TP_STATUS_TS_SYS_HARDWARE
369 # define TP_STATUS_TS_SYS_HARDWARE (1 << 30)
372 #ifndef TP_STATUS_TS_RAW_HARDWARE
373 # define TP_STATUS_TS_RAW_HARDWARE (1 << 31)
376 #ifndef PACKET_QDISC_BYPASS
377 # define PACKET_QDISC_BYPASS 20
380 #ifndef ARPHRD_IEEE802154_MONITOR
381 # define ARPHRD_IEEE802154_MONITOR 805
384 #ifndef ARPHRD_IP6GRE
385 # define ARPHRD_IP6GRE 823
388 #ifndef ARPHRD_NETLINK
389 # define ARPHRD_NETLINK 824
393 # define PACKET_USER 6
396 #ifndef PACKET_KERNEL
397 # define PACKET_KERNEL 7
401 # define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) /* 0666 */
404 #endif /* BUILT_IN_H */