datapath: add rounddown() definition into compatibility code
[sliver-openvswitch.git] / datapath / linux / compat / include / linux / kernel.h
1 #ifndef __KERNEL_H_WRAPPER
2 #define __KERNEL_H_WRAPPER 1
3
4 #include_next <linux/kernel.h>
5 #ifndef HAVE_LOG2_H
6 #include <linux/log2.h>
7 #endif
8
9 #include <linux/version.h>
10
11 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
12 #undef pr_emerg
13 #define pr_emerg(fmt, ...) \
14         printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
15 #undef pr_alert
16 #define pr_alert(fmt, ...) \
17         printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
18 #undef pr_crit
19 #define pr_crit(fmt, ...) \
20         printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
21 #undef pr_err
22 #define pr_err(fmt, ...) \
23         printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
24 #undef pr_warning
25 #define pr_warning(fmt, ...) \
26         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
27 #undef pr_notice
28 #define pr_notice(fmt, ...) \
29         printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
30 #undef pr_info
31 #define pr_info(fmt, ...) \
32         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
33 #undef pr_cont
34 #define pr_cont(fmt, ...) \
35         printk(KERN_CONT fmt, ##__VA_ARGS__)
36 #endif
37
38 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
39 #define pr_warn pr_warning
40 #endif
41
42 /*
43  * Print a one-time message (analogous to WARN_ONCE() et al):
44  */
45 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 38)
46 #undef printk_once
47 #define printk_once(fmt, ...)                   \
48 ({                                              \
49         static bool __print_once;               \
50                                                 \
51         if (!__print_once) {                    \
52                 __print_once = true;            \
53                 printk(fmt, ##__VA_ARGS__);     \
54         }                                       \
55 })
56
57 #define pr_emerg_once(fmt, ...)                                 \
58         printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
59 #define pr_alert_once(fmt, ...)                                 \
60         printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
61 #define pr_crit_once(fmt, ...)                                  \
62         printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
63 #define pr_err_once(fmt, ...)                                   \
64         printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
65 #define pr_warn_once(fmt, ...)                                  \
66         printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
67 #define pr_notice_once(fmt, ...)                                \
68         printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
69 #define pr_info_once(fmt, ...)                                  \
70         printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
71 #define pr_cont_once(fmt, ...)                                  \
72         printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
73
74 #endif
75
76 #if defined(CONFIG_PREEMPT) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
77 #error "CONFIG_PREEMPT is broken before 2.6.21--see commit 4498121ca3, \"[NET]: Handle disabled preemption in gfp_any()\""
78 #endif
79
80 #ifndef USHRT_MAX
81 #define USHRT_MAX       ((u16)(~0U))
82 #define SHRT_MAX        ((s16)(USHRT_MAX>>1))
83 #define SHRT_MIN        ((s16)(-SHRT_MAX - 1))
84 #endif
85
86 #ifndef DIV_ROUND_UP
87 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
88 #endif
89
90 #ifndef rounddown
91 #define rounddown(x, y) (                               \
92 {                                                       \
93         typeof(x) __x = (x);                            \
94         __x - (__x % (y));                              \
95 }                                                       \
96 )
97 #endif
98
99 #endif /* linux/kernel.h */