1 #ifndef LINUX_26_34_COMPAT_H
2 #define LINUX_26_34_COMPAT_H
4 #include <linux/version.h>
6 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34))
8 #include <linux/netdevice.h>
11 #define netdev_mc_count(dev) ((dev)->mc_count)
12 #define netdev_mc_empty(dev) (netdev_mc_count(dev) == 0)
14 #define netdev_for_each_mc_addr(mclist, dev) \
15 for (mclist = dev->mc_list; mclist; mclist = mclist->next)
16 /* source: include/linux/netdevice.h */
19 /* Logging, debugging and troubleshooting/diagnostic helpers. */
21 /* netdev_printk helpers, similar to dev_printk */
24 #define netdev_name(__dev) \
25 ((__dev->reg_state != NETREG_REGISTERED) ? \
26 "(unregistered net_device)" : __dev->name)
29 #define netdev_printk(level, netdev, format, args...) \
30 dev_printk(level, (netdev)->dev.parent, \
32 netdev_name(netdev), ##args)
34 #define netdev_emerg(dev, format, args...) \
35 netdev_printk(KERN_EMERG, dev, format, ##args)
36 #define netdev_alert(dev, format, args...) \
37 netdev_printk(KERN_ALERT, dev, format, ##args)
38 #define netdev_crit(dev, format, args...) \
39 netdev_printk(KERN_CRIT, dev, format, ##args)
40 #define netdev_err(dev, format, args...) \
41 netdev_printk(KERN_ERR, dev, format, ##args)
42 #define netdev_warn(dev, format, args...) \
43 netdev_printk(KERN_WARNING, dev, format, ##args)
44 #define netdev_notice(dev, format, args...) \
45 netdev_printk(KERN_NOTICE, dev, format, ##args)
46 #define netdev_info(dev, format, args...) \
47 netdev_printk(KERN_INFO, dev, format, ##args)
49 /* mask netdev_dbg as RHEL6 backports this */
50 #if !defined(netdev_dbg)
53 #define netdev_dbg(__dev, format, args...) \
54 netdev_printk(KERN_DEBUG, __dev, format, ##args)
55 #elif defined(CONFIG_DYNAMIC_DEBUG)
56 #define netdev_dbg(__dev, format, args...) \
58 dynamic_dev_dbg((__dev)->dev.parent, "%s: " format, \
59 netdev_name(__dev), ##args); \
62 #define netdev_dbg(__dev, format, args...) \
65 netdev_printk(KERN_DEBUG, __dev, format, ##args); \
72 /* mask netdev_vdbg as RHEL6 backports this */
73 #if !defined(netdev_dbg)
75 #if defined(VERBOSE_DEBUG)
76 #define netdev_vdbg netdev_dbg
79 #define netdev_vdbg(dev, format, args...) \
82 netdev_printk(KERN_DEBUG, dev, format, ##args); \
90 * netdev_WARN() acts like dev_printk(), but with the key difference
91 * of using a WARN/WARN_ON to get the message out, including the
92 * file/line information and a backtrace.
94 #define netdev_WARN(dev, format, args...) \
95 WARN(1, "netdevice: %s\n" format, netdev_name(dev), ##args);
97 /* netif printk helpers, similar to netdev_printk */
99 #define netif_printk(priv, type, level, dev, fmt, args...) \
101 if (netif_msg_##type(priv)) \
102 netdev_printk(level, (dev), fmt, ##args); \
105 #define netif_emerg(priv, type, dev, fmt, args...) \
106 netif_printk(priv, type, KERN_EMERG, dev, fmt, ##args)
107 #define netif_alert(priv, type, dev, fmt, args...) \
108 netif_printk(priv, type, KERN_ALERT, dev, fmt, ##args)
109 #define netif_crit(priv, type, dev, fmt, args...) \
110 netif_printk(priv, type, KERN_CRIT, dev, fmt, ##args)
111 #define netif_err(priv, type, dev, fmt, args...) \
112 netif_printk(priv, type, KERN_ERR, dev, fmt, ##args)
113 #define netif_warn(priv, type, dev, fmt, args...) \
114 netif_printk(priv, type, KERN_WARNING, dev, fmt, ##args)
115 #define netif_notice(priv, type, dev, fmt, args...) \
116 netif_printk(priv, type, KERN_NOTICE, dev, fmt, ##args)
117 #define netif_info(priv, type, dev, fmt, args...) \
118 netif_printk(priv, type, KERN_INFO, (dev), fmt, ##args)
120 /* mask netif_dbg as RHEL6 backports this */
121 #if !defined(netif_dbg)
124 #define netif_dbg(priv, type, dev, format, args...) \
125 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args)
126 #elif defined(CONFIG_DYNAMIC_DEBUG)
127 #define netif_dbg(priv, type, netdev, format, args...) \
129 if (netif_msg_##type(priv)) \
130 dynamic_dev_dbg((netdev)->dev.parent, \
132 netdev_name(netdev), ##args); \
135 #define netif_dbg(priv, type, dev, format, args...) \
138 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
145 /* mask netif_vdbg as RHEL6 backports this */
146 #if !defined(netif_vdbg)
148 #if defined(VERBOSE_DEBUG)
149 #define netif_vdbg netdev_dbg
151 #define netif_vdbg(priv, type, dev, format, args...) \
154 netif_printk(KERN_DEBUG, dev, format, ##args); \
159 /* source: include/linux/netdevice.h */
162 static inline void device_lock(struct device *dev)
164 #if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_PREEMPT_DESKTOP)
165 mutex_lock(&dev->mutex);
171 static inline int device_trylock(struct device *dev)
173 #if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_PREEMPT_DESKTOP)
174 return mutex_trylock(&dev->mutex);
176 return down_trylock(&dev->sem);
180 static inline void device_unlock(struct device *dev)
182 #if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_PREEMPT_DESKTOP)
183 mutex_unlock(&dev->mutex);
189 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
190 #define PCMCIA_DEVICE_PROD_ID3(v3, vh3) { \
191 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID3, \
192 .prod_id = { NULL, NULL, (v3), NULL }, \
193 .prod_id_hash = { 0, 0, (vh3), 0 }, }
196 #define rcu_dereference_check(p, c) rcu_dereference(p)
199 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
200 * @attr: struct attribute to initialize
202 * Initialize a dynamically allocated struct attribute so we can
203 * make lockdep happy. This is a new requirement for attributes
204 * and initially this is only needed when lockdep is enabled.
205 * Lockdep gives a nice error when your attribute is added to
206 * sysfs if you don't have this.
208 #ifdef CONFIG_DEBUG_LOCK_ALLOC
209 #define sysfs_attr_init(attr) \
211 static struct lock_class_key __key; \
213 (attr)->key = &__key; \
216 #define sysfs_attr_init(attr) do {} while(0)
220 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
221 * @attr: struct bin_attribute to initialize
223 * Initialize a dynamically allocated struct bin_attribute so we
224 * can make lockdep happy. This is a new requirement for
225 * attributes and initially this is only needed when lockdep is
226 * enabled. Lockdep gives a nice error when your attribute is
227 * added to sysfs if you don't have this.
229 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
231 #define usb_alloc_coherent(dev, size, mem_flags, dma) usb_buffer_alloc(dev, size, mem_flags, dma)
232 #define usb_free_coherent(dev, size, addr, dma) usb_buffer_free(dev, size, addr, dma)
234 /* only include this if DEFINE_DMA_UNMAP_ADDR is not set as debian squeeze also backports this */
235 #ifndef DEFINE_DMA_UNMAP_ADDR
236 #ifdef CONFIG_NEED_DMA_MAP_STATE
237 #define DEFINE_DMA_UNMAP_ADDR(ADDR_NAME) dma_addr_t ADDR_NAME
238 #define DEFINE_DMA_UNMAP_LEN(LEN_NAME) __u32 LEN_NAME
239 #define dma_unmap_addr(PTR, ADDR_NAME) ((PTR)->ADDR_NAME)
240 #define dma_unmap_addr_set(PTR, ADDR_NAME, VAL) (((PTR)->ADDR_NAME) = (VAL))
241 #define dma_unmap_len(PTR, LEN_NAME) ((PTR)->LEN_NAME)
242 #define dma_unmap_len_set(PTR, LEN_NAME, VAL) (((PTR)->LEN_NAME) = (VAL))
244 #define DEFINE_DMA_UNMAP_ADDR(ADDR_NAME)
245 #define DEFINE_DMA_UNMAP_LEN(LEN_NAME)
246 #define dma_unmap_addr(PTR, ADDR_NAME) (0)
247 #define dma_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0)
248 #define dma_unmap_len(PTR, LEN_NAME) (0)
249 #define dma_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0)
253 /* mask dma_set_coherent_mask as debian squeeze also backports this */
254 #define dma_set_coherent_mask(a, b) compat_dma_set_coherent_mask(a, b)
256 static inline int dma_set_coherent_mask(struct device *dev, u64 mask)
258 if (!dma_supported(dev, mask))
260 dev->coherent_dma_mask = mask;
264 /* USB autosuspend and autoresume */
265 static inline int usb_enable_autosuspend(struct usb_device *udev)
267 static inline int usb_disable_autosuspend(struct usb_device *udev)
270 #define MMC_PM_KEEP_POWER (1 << 0) /* preserve card power during suspend */
271 #define sdio_set_host_pm_flags(a, b) 0
273 #define rcu_dereference_protected(p, c) (p)
274 #define rcu_access_pointer(p) ACCESS_ONCE(p)
276 #define rcu_dereference_raw(p) rcu_dereference(p)
278 #define KEY_WPS_BUTTON 0x211 /* WiFi Protected Setup key */
281 * This looks more complex than it should be. But we need to
282 * get the type for the ~ right in round_down (it needs to be
283 * as wide as the result!), and we want to evaluate the macro
284 * arguments just once each.
286 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
287 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
288 #define round_down(x, y) ((x) & ~__round_mask(x, y))
290 static inline int rcu_read_lock_held(void)
295 #ifdef CONFIG_PROVE_LOCKING
297 * Obviously, this is wrong. But the base kernel will have rtnl_mutex
298 * declared static, with no way to access it. I think this is the best
301 static inline int lockdep_rtnl_is_held(void)
305 #endif /* #ifdef CONFIG_PROVE_LOCKING */
307 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34)) */
309 #endif /* LINUX_26_34_COMPAT_H */