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 */
100 # define force_cast(type, arg) ((type) (arg))
106 typeof (a) _a = (a); \
107 typeof (b) _b = (b); \
113 # define max_t(type, a, b) \
115 type ___max1 = (a); \
116 type ___max2 = (b); \
117 ___max1 > ___max2 ? ___max1 : ___max2; \
124 typeof (a) _a = (a); \
125 typeof (b) _b = (b); \
131 # define min_t(type, a, b) \
133 type ___min1 = (a); \
134 type ___min2 = (b); \
135 ___min1 < ___min2 ? ___min1 : ___min2; \
140 # define ispow2(x) ({ !!((x) && !((x) & ((x) - 1))); })
144 # define offsetof(type, member) ((size_t) &((type *) 0)->member)
148 # define container_of(ptr, type, member) \
150 const typeof(((type *) 0)->member) * __mptr = (ptr); \
151 (type *) ((char *) __mptr - offsetof(type, member)); \
156 # define array_size(x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x))
159 #ifndef __must_be_array
160 # define __must_be_array(x) \
161 build_bug_on_zero(__builtin_types_compatible_p(typeof(x), \
165 #ifndef build_bug_on_zero
166 # define build_bug_on_zero(e) (sizeof(char[1 - 2 * !!(e)]) - 1)
170 # define build_bug_on(e) ((void)sizeof(char[1 - 2*!!(e)]))
174 # define bug_on(cond) assert(!(cond))
178 # define bug() assert(0)
182 # define PAGE_SIZE (getpagesize())
184 #define PAGE_MASK (~(PAGE_SIZE - 1))
185 #define PAGE_ALIGN(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK)
187 #if __BYTE_ORDER == __LITTLE_ENDIAN
188 static inline uint64_t htonll(uint64_t x
)
193 static inline uint64_t ntohll(uint64_t x
)
197 #elif __BYTE_ORDER == __BIG_ENDIAN
198 static inline uint64_t htonll(uint64_t x
)
203 static inline uint64_t ntohll(uint64_t x
)
208 # error __BYTE_ORDER is neither __LITTLE_ENDIAN nor __BIG_ENDIAN
210 #ifndef ___constant_swab16
211 # define ___constant_swab16(x) ((__u16)( \
212 (((__u16)(x) & (__u16)0x00ffU) << 8) | \
213 (((__u16)(x) & (__u16)0xff00U) >> 8)))
215 #ifndef ___constant_swab32
216 # define ___constant_swab32(x) ((__u32)( \
217 (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
218 (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
219 (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
220 (((__u32)(x) & (__u32)0xff000000UL) >> 24)))
222 #if __BYTE_ORDER == __LITTLE_ENDIAN
223 static inline u16
cpu_to_be16(u16 val
)
225 return bswap_16(val
);
228 static inline u32
cpu_to_be32(u32 val
)
230 return bswap_32(val
);
233 static inline u64
cpu_to_be64(u64 val
)
235 return bswap_64(val
);
238 static inline u16
cpu_to_le16(u16 val
)
243 static inline u32
cpu_to_le32(u32 val
)
248 static inline u64
cpu_to_le64(u64 val
)
253 # ifndef __constant_htonl
254 # define __constant_htonl(x) ((__force __be32)___constant_swab32((x)))
256 # ifndef __constant_ntohl
257 # define __constant_ntohl(x) ___constant_swab32((__force __be32)(x))
259 # ifndef __constant_htons
260 # define __constant_htons(x) ((__force __be16)___constant_swab16((x)))
262 # ifndef __constant_ntohs
263 # define __constant_ntohs(x) ___constant_swab16((__force __be16)(x))
265 #elif __BYTE_ORDER == __BIG_ENDIAN
266 static inline u16
cpu_to_be16(u16 val
)
271 static inline u32
cpu_to_be32(u32 val
)
276 static inline u64
cpu_to_be64(u64 val
)
281 static inline u16
cpu_to_le16(u16 val
)
283 return bswap_16(val
);
286 static inline u32
cpu_to_le32(u32 val
)
288 return bswap_32(val
);
291 static inline u64
cpu_to_le64(u64 val
)
293 return bswap_64(val
);
296 # ifndef __constant_htonl
297 # define __constant_htonl(x) ((__force __be32)(__u32)(x))
299 # ifndef __constant_ntohl
300 # define __constant_ntohl(x) ((__force __u32)(__be32)(x))
302 # ifndef __constant_htons
303 # define __constant_htons(x) ((__force __be16)(__u16)(x))
305 # ifndef __constant_ntohs
306 # define __constant_ntohs(x) ((__force __u16)(__be16)(x))
309 # error __BYTE_ORDER is neither __LITTLE_ENDIAN nor __BIG_ENDIAN
312 #define le64_to_cpu cpu_to_le64
313 #define le32_to_cpu cpu_to_le32
314 #define le16_to_cpu cpu_to_le16
315 #define be64_to_cpu cpu_to_be64
316 #define be32_to_cpu cpu_to_be32
317 #define be16_to_cpu cpu_to_be16
322 #define memset fmemset
323 #define memcpy fmemcpy
325 #if defined(__amd64__) || defined(__x86_64__) || defined(__AMD64__) || \
326 defined(_M_X64) || defined(__amd64)
327 # define CO_IN_CACHE_SHIFT 7
328 #elif defined(__i386__) || defined(__x86__) || defined(__X86__) || \
329 defined(_M_IX86) || defined(__i386)
330 # define CO_IN_CACHE_SHIFT 7
331 #elif defined(__ia64__) || defined(__IA64__) || defined(__M_IA64)
332 # define CO_IN_CACHE_SHIFT 6
333 #elif defined(__SPU__)
334 # define CO_IN_CACHE_SHIFT 7
335 #elif defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || \
337 # define CO_IN_CACHE_SHIFT 8
338 #elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || \
340 # define CO_IN_CACHE_SHIFT 7
341 #elif defined(__sparcv9__) || defined(__sparcv9)
342 # define CO_IN_CACHE_SHIFT 6
343 #elif defined(__sparc_v8__)
344 # define CO_IN_CACHE_SHIFT 5
345 #elif defined(__sparc__) || defined(__sparc)
346 # define CO_IN_CACHE_SHIFT 5
347 #elif defined(__ARM_EABI__)
348 # define CO_IN_CACHE_SHIFT 5
349 #elif defined(__arm__)
350 # define CO_IN_CACHE_SHIFT 5
351 #elif defined(__mips__) || defined(__mips) || defined(__MIPS__)
352 # if defined(_ABIO32)
353 # define CO_IN_CACHE_SHIFT 5
354 # elif defined(_ABIN32)
355 # define CO_IN_CACHE_SHIFT 5
357 # define CO_IN_CACHE_SHIFT 6
360 # define CO_IN_CACHE_SHIFT 5
363 #ifndef TP_STATUS_TS_SOFTWARE
364 # define TP_STATUS_TS_SOFTWARE (1 << 29)
367 #ifndef TP_STATUS_TS_SYS_HARDWARE
368 # define TP_STATUS_TS_SYS_HARDWARE (1 << 30)
371 #ifndef TP_STATUS_TS_RAW_HARDWARE
372 # define TP_STATUS_TS_RAW_HARDWARE (1 << 31)
375 #ifndef PACKET_QDISC_BYPASS
376 # define PACKET_QDISC_BYPASS 20
380 # define POLLRDNORM 0x0040
384 # define POLLWRNORM 0x0100
388 # define POLLRDHUP 0x2000
391 #ifndef ARPHRD_IEEE802154_MONITOR
392 # define ARPHRD_IEEE802154_MONITOR 805
395 #ifndef ARPHRD_IP6GRE
396 # define ARPHRD_IP6GRE 823
399 #ifndef ARPHRD_NETLINK
400 # define ARPHRD_NETLINK 824
404 # define PACKET_USER 6
407 #ifndef PACKET_KERNEL
408 # define PACKET_KERNEL 7
412 # define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) /* 0666 */
415 #endif /* BUILT_IN_H */