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 */
23 static inline const char *netdev_name(const struct net_device *dev)
25 if (dev->reg_state != NETREG_REGISTERED)
26 return "(unregistered net_device)";
30 #define netdev_printk(level, netdev, format, args...) \
31 dev_printk(level, (netdev)->dev.parent, \
33 netdev_name(netdev), ##args)
35 #define netdev_emerg(dev, format, args...) \
36 netdev_printk(KERN_EMERG, dev, format, ##args)
37 #define netdev_alert(dev, format, args...) \
38 netdev_printk(KERN_ALERT, dev, format, ##args)
39 #define netdev_crit(dev, format, args...) \
40 netdev_printk(KERN_CRIT, dev, format, ##args)
41 #define netdev_err(dev, format, args...) \
42 netdev_printk(KERN_ERR, dev, format, ##args)
43 #define netdev_warn(dev, format, args...) \
44 netdev_printk(KERN_WARNING, dev, format, ##args)
45 #define netdev_notice(dev, format, args...) \
46 netdev_printk(KERN_NOTICE, dev, format, ##args)
47 #define netdev_info(dev, format, args...) \
48 netdev_printk(KERN_INFO, dev, format, ##args)
51 #define netdev_dbg(__dev, format, args...) \
52 netdev_printk(KERN_DEBUG, __dev, format, ##args)
53 #elif defined(CONFIG_DYNAMIC_DEBUG)
54 #define netdev_dbg(__dev, format, args...) \
56 dynamic_dev_dbg((__dev)->dev.parent, "%s: " format, \
57 netdev_name(__dev), ##args); \
60 #define netdev_dbg(__dev, format, args...) \
63 netdev_printk(KERN_DEBUG, __dev, format, ##args); \
68 #if defined(VERBOSE_DEBUG)
69 #define netdev_vdbg netdev_dbg
72 #define netdev_vdbg(dev, format, args...) \
75 netdev_printk(KERN_DEBUG, dev, format, ##args); \
81 * netdev_WARN() acts like dev_printk(), but with the key difference
82 * of using a WARN/WARN_ON to get the message out, including the
83 * file/line information and a backtrace.
85 #define netdev_WARN(dev, format, args...) \
86 WARN(1, "netdevice: %s\n" format, netdev_name(dev), ##args);
88 /* netif printk helpers, similar to netdev_printk */
90 #define netif_printk(priv, type, level, dev, fmt, args...) \
92 if (netif_msg_##type(priv)) \
93 netdev_printk(level, (dev), fmt, ##args); \
96 #define netif_emerg(priv, type, dev, fmt, args...) \
97 netif_printk(priv, type, KERN_EMERG, dev, fmt, ##args)
98 #define netif_alert(priv, type, dev, fmt, args...) \
99 netif_printk(priv, type, KERN_ALERT, dev, fmt, ##args)
100 #define netif_crit(priv, type, dev, fmt, args...) \
101 netif_printk(priv, type, KERN_CRIT, dev, fmt, ##args)
102 #define netif_err(priv, type, dev, fmt, args...) \
103 netif_printk(priv, type, KERN_ERR, dev, fmt, ##args)
104 #define netif_warn(priv, type, dev, fmt, args...) \
105 netif_printk(priv, type, KERN_WARNING, dev, fmt, ##args)
106 #define netif_notice(priv, type, dev, fmt, args...) \
107 netif_printk(priv, type, KERN_NOTICE, dev, fmt, ##args)
108 #define netif_info(priv, type, dev, fmt, args...) \
109 netif_printk(priv, type, KERN_INFO, (dev), fmt, ##args)
112 #define netif_dbg(priv, type, dev, format, args...) \
113 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args)
114 #elif defined(CONFIG_DYNAMIC_DEBUG)
115 #define netif_dbg(priv, type, netdev, format, args...) \
117 if (netif_msg_##type(priv)) \
118 dynamic_dev_dbg((netdev)->dev.parent, \
120 netdev_name(netdev), ##args); \
123 #define netif_dbg(priv, type, dev, format, args...) \
126 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
131 #if defined(VERBOSE_DEBUG)
132 #define netif_vdbg netdev_dbg
134 #define netif_vdbg(priv, type, dev, format, args...) \
137 netif_printk(KERN_DEBUG, dev, format, ##args); \
141 /* source: include/linux/netdevice.h */
144 static inline void device_lock(struct device *dev)
146 #if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_PREEMPT_DESKTOP)
147 mutex_lock(&dev->mutex);
153 static inline int device_trylock(struct device *dev)
155 #if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_PREEMPT_DESKTOP)
156 return mutex_trylock(&dev->mutex);
158 return down_trylock(&dev->sem);
162 static inline void device_unlock(struct device *dev)
164 #if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_PREEMPT_DESKTOP)
165 mutex_unlock(&dev->mutex);
171 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
172 #define PCMCIA_DEVICE_PROD_ID3(v3, vh3) { \
173 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID3, \
174 .prod_id = { NULL, NULL, (v3), NULL }, \
175 .prod_id_hash = { 0, 0, (vh3), 0 }, }
178 #define rcu_dereference_check(p, c) rcu_dereference(p)
181 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
182 * @attr: struct attribute to initialize
184 * Initialize a dynamically allocated struct attribute so we can
185 * make lockdep happy. This is a new requirement for attributes
186 * and initially this is only needed when lockdep is enabled.
187 * Lockdep gives a nice error when your attribute is added to
188 * sysfs if you don't have this.
190 #ifdef CONFIG_DEBUG_LOCK_ALLOC
191 #define sysfs_attr_init(attr) \
193 static struct lock_class_key __key; \
195 (attr)->key = &__key; \
198 #define sysfs_attr_init(attr) do {} while(0)
202 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
203 * @attr: struct bin_attribute to initialize
205 * Initialize a dynamically allocated struct bin_attribute so we
206 * can make lockdep happy. This is a new requirement for
207 * attributes and initially this is only needed when lockdep is
208 * enabled. Lockdep gives a nice error when your attribute is
209 * added to sysfs if you don't have this.
211 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
213 #define usb_alloc_coherent(dev, size, mem_flags, dma) usb_buffer_alloc(dev, size, mem_flags, dma)
214 #define usb_free_coherent(dev, size, addr, dma) usb_buffer_free(dev, size, addr, dma)
216 #ifdef CONFIG_NEED_DMA_MAP_STATE
217 #define DEFINE_DMA_UNMAP_ADDR(ADDR_NAME) dma_addr_t ADDR_NAME
218 #define DEFINE_DMA_UNMAP_LEN(LEN_NAME) __u32 LEN_NAME
219 #define dma_unmap_addr(PTR, ADDR_NAME) ((PTR)->ADDR_NAME)
220 #define dma_unmap_addr_set(PTR, ADDR_NAME, VAL) (((PTR)->ADDR_NAME) = (VAL))
221 #define dma_unmap_len(PTR, LEN_NAME) ((PTR)->LEN_NAME)
222 #define dma_unmap_len_set(PTR, LEN_NAME, VAL) (((PTR)->LEN_NAME) = (VAL))
224 #define DEFINE_DMA_UNMAP_ADDR(ADDR_NAME)
225 #define DEFINE_DMA_UNMAP_LEN(LEN_NAME)
226 #define dma_unmap_addr(PTR, ADDR_NAME) (0)
227 #define dma_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0)
228 #define dma_unmap_len(PTR, LEN_NAME) (0)
229 #define dma_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0)
232 static inline int dma_set_coherent_mask(struct device *dev, u64 mask)
234 if (!dma_supported(dev, mask))
236 dev->coherent_dma_mask = mask;
240 /* USB autosuspend and autoresume */
241 static inline int usb_enable_autosuspend(struct usb_device *udev)
243 static inline int usb_disable_autosuspend(struct usb_device *udev)
246 #define MMC_PM_KEEP_POWER (1 << 0) /* preserve card power during suspend */
247 #define sdio_set_host_pm_flags(a, b) 0
249 #define rcu_dereference_protected(p, c) (p)
250 #define rcu_access_pointer(p) ACCESS_ONCE(p)
252 #define rcu_dereference_raw(p) rcu_dereference(p)
254 #define KEY_WPS_BUTTON 0x211 /* WiFi Protected Setup key */
256 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34)) */
258 #endif /* LINUX_26_34_COMPAT_H */