2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice unmodified, this list of conditions, and the following
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef _LINUX_KERNEL_H_
30 #define _LINUX_KERNEL_H_
32 #include <sys/systm.h>
33 #include <sys/param.h>
34 #include <sys/libkern.h>
37 #include <sys/stddef.h>
38 #include <sys/syslog.h>
40 #include <linux/bitops.h>
41 #include <linux/compiler.h>
42 #include <linux/errno.h>
43 #include <linux/kthread.h>
44 #include <linux/types.h>
45 #include <linux/jiffies.h>
46 #include <linux/wait.h>
47 #include <linux/log2.h>
48 #include <asm/byteorder.h>
51 #define KERN_EMERG "<0>"
52 #define KERN_ALERT "<1>"
53 #define KERN_CRIT "<2>"
54 #define KERN_ERR "<3>"
55 #define KERN_WARNING "<4>"
56 #define KERN_NOTICE "<5>"
57 #define KERN_INFO "<6>"
58 #define KERN_DEBUG "<7>"
60 #define BUG() panic("BUG")
61 #define BUG_ON(condition) do { if (condition) BUG(); } while(0)
62 #define WARN_ON BUG_ON
65 #define ALIGN(x, y) roundup2((x), (y))
66 #define DIV_ROUND_UP howmany
68 #define printk(X...) printf(X)
71 * The "pr_debug()" and "pr_devel()" macros should produce zero code
72 * unless DEBUG is defined:
75 #define pr_debug(fmt, ...) \
76 log(LOG_DEBUG, fmt, ##__VA_ARGS__)
77 #define pr_devel(fmt, ...) \
78 log(LOG_DEBUG, pr_fmt(fmt), ##__VA_ARGS__)
80 #define pr_debug(fmt, ...) \
81 ({ if (0) log(LOG_DEBUG, fmt, ##__VA_ARGS__); 0; })
82 #define pr_devel(fmt, ...) \
83 ({ if (0) log(LOG_DEBUG, pr_fmt(fmt), ##__VA_ARGS__); 0; })
86 #define udelay(t) DELAY(t)
89 #define pr_fmt(fmt) fmt
93 * Print a one-time message (analogous to WARN_ONCE() et al):
95 #define printk_once(...) do { \
96 static bool __print_once; \
98 if (!__print_once) { \
99 __print_once = true; \
100 printk(__VA_ARGS__); \
105 * Log a one-time message (analogous to WARN_ONCE() et al):
107 #define log_once(level,...) do { \
108 static bool __log_once; \
112 log(level, __VA_ARGS__); \
116 #define pr_emerg(fmt, ...) \
117 log(LOG_EMERG, pr_fmt(fmt), ##__VA_ARGS__)
118 #define pr_alert(fmt, ...) \
119 log(LOG_ALERT, pr_fmt(fmt), ##__VA_ARGS__)
120 #define pr_crit(fmt, ...) \
121 log(LOG_CRIT, pr_fmt(fmt), ##__VA_ARGS__)
122 #define pr_err(fmt, ...) \
123 log(LOG_ERR, pr_fmt(fmt), ##__VA_ARGS__)
124 #define pr_warning(fmt, ...) \
125 log(LOG_WARNING, pr_fmt(fmt), ##__VA_ARGS__)
126 #define pr_warn pr_warning
127 #define pr_notice(fmt, ...) \
128 log(LOG_NOTICE, pr_fmt(fmt), ##__VA_ARGS__)
129 #define pr_info(fmt, ...) \
130 log(LOG_INFO, pr_fmt(fmt), ##__VA_ARGS__)
131 #define pr_info_once(fmt, ...) \
132 log_once(LOG_INFO, pr_fmt(fmt), ##__VA_ARGS__)
133 #define pr_cont(fmt, ...) \
134 printk(KERN_CONT fmt, ##__VA_ARGS__)
137 #define WARN(condition, format...) ({ \
138 int __ret_warn_on = !!(condition); \
139 if (unlikely(__ret_warn_on)) \
140 pr_warning(format); \
141 unlikely(__ret_warn_on); \
145 #define container_of(ptr, type, member) \
147 __typeof(((type *)0)->member) *_p = (ptr); \
148 (type *)((char *)_p - offsetof(type, member)); \
151 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
153 #define simple_strtoul strtoul
154 #define simple_strtol strtol
155 #define kstrtol(a,b,c) ({*(c) = strtol(a,0,b);})
157 #define min(x, y) ((x) < (y) ? (x) : (y))
158 #define max(x, y) ((x) > (y) ? (x) : (y))
159 #define min_t(type, _x, _y) ((type)(_x) < (type)(_y) ? (type)(_x) : (type)(_y))
160 #define max_t(type, _x, _y) ((type)(_x) > (type)(_y) ? (type)(_x) : (type)(_y))
163 * This looks more complex than it should be. But we need to
164 * get the type for the ~ right in round_down (it needs to be
165 * as wide as the result!), and we want to evaluate the macro
166 * arguments just once each.
168 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
169 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
170 #define round_down(x, y) ((x) & ~__round_mask(x, y))
172 #define num_possible_cpus() mp_ncpus
174 typedef struct pm_message {
178 #endif /* _LINUX_KERNEL_H_ */