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>
10 #include <linux/mmc/sdio_func.h>
13 * Backports da68c4eb25
14 * sdio: introduce API for special power management features
16 * We wimply carry around the data structures and flags, and
17 * make the host return no flags set by the driver.
19 typedef unsigned int mmc_pm_flag_t;
21 #define MMC_PM_KEEP_POWER (1 << 0) /* preserve card power during suspend */
22 #define MMC_PM_WAKE_SDIO_IRQ (1 << 1) /* wake up host system on SDIO IRQ assertion */
24 extern mmc_pm_flag_t sdio_get_host_pm_caps(struct sdio_func *func);
25 extern int sdio_set_host_pm_flags(struct sdio_func *func, mmc_pm_flag_t flags);
27 #define netdev_uc_count(dev) ((dev)->uc.count)
28 #define netdev_uc_empty(dev) ((dev)->uc.count == 0)
29 #define netdev_for_each_uc_addr(ha, dev) \
30 list_for_each_entry(ha, &dev->uc.list, list)
32 #define netdev_mc_count(dev) ((dev)->mc_count)
33 #define netdev_mc_empty(dev) (netdev_mc_count(dev) == 0)
35 #define netdev_for_each_mc_addr(mclist, dev) \
36 for (mclist = dev->mc_list; mclist; mclist = mclist->next)
37 /* source: include/linux/netdevice.h */
40 /* Logging, debugging and troubleshooting/diagnostic helpers. */
42 /* netdev_printk helpers, similar to dev_printk */
45 #define netdev_name(__dev) \
46 ((__dev->reg_state != NETREG_REGISTERED) ? \
47 "(unregistered net_device)" : __dev->name)
50 #define netdev_printk(level, netdev, format, args...) \
51 dev_printk(level, (netdev)->dev.parent, \
53 netdev_name(netdev), ##args)
55 #define netdev_emerg(dev, format, args...) \
56 netdev_printk(KERN_EMERG, dev, format, ##args)
57 #define netdev_alert(dev, format, args...) \
58 netdev_printk(KERN_ALERT, dev, format, ##args)
59 #define netdev_crit(dev, format, args...) \
60 netdev_printk(KERN_CRIT, dev, format, ##args)
61 #define netdev_err(dev, format, args...) \
62 netdev_printk(KERN_ERR, dev, format, ##args)
63 #define netdev_warn(dev, format, args...) \
64 netdev_printk(KERN_WARNING, dev, format, ##args)
65 #define netdev_notice(dev, format, args...) \
66 netdev_printk(KERN_NOTICE, dev, format, ##args)
67 #define netdev_info(dev, format, args...) \
68 netdev_printk(KERN_INFO, dev, format, ##args)
70 /* mask netdev_dbg as RHEL6 backports this */
71 #if !defined(netdev_dbg)
74 #define netdev_dbg(__dev, format, args...) \
75 netdev_printk(KERN_DEBUG, __dev, format, ##args)
76 #elif defined(CONFIG_DYNAMIC_DEBUG)
77 #define netdev_dbg(__dev, format, args...) \
79 dynamic_dev_dbg((__dev)->dev.parent, "%s: " format, \
80 netdev_name(__dev), ##args); \
83 #define netdev_dbg(__dev, format, args...) \
86 netdev_printk(KERN_DEBUG, __dev, format, ##args); \
93 /* mask netdev_vdbg as RHEL6 backports this */
94 #if !defined(netdev_dbg)
96 #if defined(VERBOSE_DEBUG)
97 #define netdev_vdbg netdev_dbg
100 #define netdev_vdbg(dev, format, args...) \
103 netdev_printk(KERN_DEBUG, dev, format, ##args); \
111 * netdev_WARN() acts like dev_printk(), but with the key difference
112 * of using a WARN/WARN_ON to get the message out, including the
113 * file/line information and a backtrace.
115 #define netdev_WARN(dev, format, args...) \
116 WARN(1, "netdevice: %s\n" format, netdev_name(dev), ##args);
118 /* netif printk helpers, similar to netdev_printk */
120 #define netif_printk(priv, type, level, dev, fmt, args...) \
122 if (netif_msg_##type(priv)) \
123 netdev_printk(level, (dev), fmt, ##args); \
126 #define netif_emerg(priv, type, dev, fmt, args...) \
127 netif_printk(priv, type, KERN_EMERG, dev, fmt, ##args)
128 #define netif_alert(priv, type, dev, fmt, args...) \
129 netif_printk(priv, type, KERN_ALERT, dev, fmt, ##args)
130 #define netif_crit(priv, type, dev, fmt, args...) \
131 netif_printk(priv, type, KERN_CRIT, dev, fmt, ##args)
132 #define netif_err(priv, type, dev, fmt, args...) \
133 netif_printk(priv, type, KERN_ERR, dev, fmt, ##args)
134 #define netif_warn(priv, type, dev, fmt, args...) \
135 netif_printk(priv, type, KERN_WARNING, dev, fmt, ##args)
136 #define netif_notice(priv, type, dev, fmt, args...) \
137 netif_printk(priv, type, KERN_NOTICE, dev, fmt, ##args)
138 #define netif_info(priv, type, dev, fmt, args...) \
139 netif_printk(priv, type, KERN_INFO, (dev), fmt, ##args)
141 /* mask netif_dbg as RHEL6 backports this */
142 #if !defined(netif_dbg)
145 #define netif_dbg(priv, type, dev, format, args...) \
146 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args)
147 #elif defined(CONFIG_DYNAMIC_DEBUG)
148 #define netif_dbg(priv, type, netdev, format, args...) \
150 if (netif_msg_##type(priv)) \
151 dynamic_dev_dbg((netdev)->dev.parent, \
153 netdev_name(netdev), ##args); \
156 #define netif_dbg(priv, type, dev, format, args...) \
159 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
166 /* mask netif_vdbg as RHEL6 backports this */
167 #if !defined(netif_vdbg)
169 #if defined(VERBOSE_DEBUG)
170 #define netif_vdbg netdev_dbg
172 #define netif_vdbg(priv, type, dev, format, args...) \
175 netif_printk(KERN_DEBUG, dev, format, ##args); \
180 /* source: include/linux/netdevice.h */
183 #define device_lock LINUX_BACKPORT(device_lock)
184 static inline void device_lock(struct device *dev)
186 #if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_PREEMPT_DESKTOP)
187 mutex_lock(&dev->mutex);
193 #define device_trylock LINUX_BACKPORT(device_trylock)
194 static inline int device_trylock(struct device *dev)
196 #if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_PREEMPT_DESKTOP)
197 return mutex_trylock(&dev->mutex);
199 return down_trylock(&dev->sem);
203 #define device_unlock LINUX_BACKPORT(device_unlock)
204 static inline void device_unlock(struct device *dev)
206 #if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_PREEMPT_DESKTOP)
207 mutex_unlock(&dev->mutex);
213 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
214 #define PCMCIA_DEVICE_PROD_ID3(v3, vh3) { \
215 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID3, \
216 .prod_id = { NULL, NULL, (v3), NULL }, \
217 .prod_id_hash = { 0, 0, (vh3), 0 }, }
220 #define rcu_dereference_check(p, c) rcu_dereference(p)
222 #ifndef sysfs_attr_init
224 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
225 * @attr: struct attribute to initialize
227 #define sysfs_attr_init(attr) do {} while(0)
228 #endif /* sysfs_attr_init */
231 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
232 * @attr: struct bin_attribute to initialize
234 * Initialize a dynamically allocated struct bin_attribute so we
235 * can make lockdep happy. This is a new requirement for
236 * attributes and initially this is only needed when lockdep is
237 * enabled. Lockdep gives a nice error when your attribute is
238 * added to sysfs if you don't have this.
240 #ifndef sysfs_bin_attr_init
241 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
242 #endif /* sysfs_bin_attr_init */
244 #define usb_alloc_coherent(dev, size, mem_flags, dma) usb_buffer_alloc(dev, size, mem_flags, dma)
245 #define usb_free_coherent(dev, size, addr, dma) usb_buffer_free(dev, size, addr, dma)
247 /* only include this if DEFINE_DMA_UNMAP_ADDR is not set as debian squeeze also backports this */
248 #ifndef DEFINE_DMA_UNMAP_ADDR
249 #ifdef CONFIG_NEED_DMA_MAP_STATE
250 #define DEFINE_DMA_UNMAP_ADDR(ADDR_NAME) dma_addr_t ADDR_NAME
251 #define DEFINE_DMA_UNMAP_LEN(LEN_NAME) __u32 LEN_NAME
252 #define dma_unmap_addr(PTR, ADDR_NAME) ((PTR)->ADDR_NAME)
253 #define dma_unmap_addr_set(PTR, ADDR_NAME, VAL) (((PTR)->ADDR_NAME) = (VAL))
254 #define dma_unmap_len(PTR, LEN_NAME) ((PTR)->LEN_NAME)
255 #define dma_unmap_len_set(PTR, LEN_NAME, VAL) (((PTR)->LEN_NAME) = (VAL))
257 #define DEFINE_DMA_UNMAP_ADDR(ADDR_NAME)
258 #define DEFINE_DMA_UNMAP_LEN(LEN_NAME)
259 #define dma_unmap_addr(PTR, ADDR_NAME) (0)
260 #define dma_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0)
261 #define dma_unmap_len(PTR, LEN_NAME) (0)
262 #define dma_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0)
266 /* mask dma_set_coherent_mask as debian squeeze also backports this */
267 #define dma_set_coherent_mask(a, b) compat_dma_set_coherent_mask(a, b)
269 static inline int dma_set_coherent_mask(struct device *dev, u64 mask)
271 if (!dma_supported(dev, mask))
273 dev->coherent_dma_mask = mask;
277 /* USB autosuspend and autoresume */
278 static inline int usb_enable_autosuspend(struct usb_device *udev)
280 static inline int usb_disable_autosuspend(struct usb_device *udev)
283 #ifndef rcu_dereference_protected
284 #define rcu_dereference_protected(p, c) (p)
287 #define rcu_access_pointer(p) ACCESS_ONCE(p)
289 #define rcu_dereference_raw(p) rcu_dereference(p)
291 #define KEY_WPS_BUTTON 0x211 /* WiFi Protected Setup key */
294 * This looks more complex than it should be. But we need to
295 * get the type for the ~ right in round_down (it needs to be
296 * as wide as the result!), and we want to evaluate the macro
297 * arguments just once each.
299 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
300 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
301 #define round_down(x, y) ((x) & ~__round_mask(x, y))
303 #ifdef CONFIG_PROVE_LOCKING
305 * Obviously, this is wrong. But the base kernel will have rtnl_mutex
306 * declared static, with no way to access it. I think this is the best
309 static inline int lockdep_rtnl_is_held(void)
313 #endif /* #ifdef CONFIG_PROVE_LOCKING */
315 #ifndef NETIF_F_NTUPLE
316 #define NETIF_F_NTUPLE (1 << 27) /* N-tuple filters supported */
321 #define PCI_VPD_LRDT 0x80 /* Large Resource Data Type */
322 #define PCI_VPD_LRDT_ID(x) (x | PCI_VPD_LRDT)
324 /* Large Resource Data Type Tag Item Names */
325 #define PCI_VPD_LTIN_ID_STRING 0x02 /* Identifier String */
326 #define PCI_VPD_LTIN_RO_DATA 0x10 /* Read-Only Data */
327 #define PCI_VPD_LTIN_RW_DATA 0x11 /* Read-Write Data */
329 #define PCI_VPD_LRDT_ID_STRING PCI_VPD_LRDT_ID(PCI_VPD_LTIN_ID_STRING)
330 #define PCI_VPD_LRDT_RO_DATA PCI_VPD_LRDT_ID(PCI_VPD_LTIN_RO_DATA)
331 #define PCI_VPD_LRDT_RW_DATA PCI_VPD_LRDT_ID(PCI_VPD_LTIN_RW_DATA)
332 #define PCI_VPD_LRDT_TAG_SIZE 3
333 #define PCI_VPD_SRDT_TAG_SIZE 1
335 #define PCI_VPD_INFO_FLD_HDR_SIZE 3
337 /* Small Resource Data Type Tag Item Names */
338 #define PCI_VPD_STIN_END 0x78 /* End */
340 #define PCI_VPD_SRDT_END PCI_VPD_STIN_END
342 #define PCI_VPD_SRDT_TIN_MASK 0x78
343 #define PCI_VPD_SRDT_LEN_MASK 0x07
344 #endif /* PCI_VPD_LRDT */
347 * pci_vpd_info_field_size - Extracts the information field length
348 * @lrdt: Pointer to the beginning of an information field header
350 * Returns the extracted information field length.
352 #define pci_vpd_info_field_size LINUX_BACKPORT(pci_vpd_info_field_size)
353 static inline u8 pci_vpd_info_field_size(const u8 *info_field)
355 return info_field[2];
359 * pci_vpd_lrdt_size - Extracts the Large Resource Data Type length
360 * @lrdt: Pointer to the beginning of the Large Resource Data Type tag
362 * Returns the extracted Large Resource Data Type length.
364 #define pci_vpd_lrdt_size LINUX_BACKPORT(pci_vpd_lrdt_size)
365 static inline u16 pci_vpd_lrdt_size(const u8 *lrdt)
367 return (u16)lrdt[1] + ((u16)lrdt[2] << 8);
371 * pci_vpd_find_info_keyword - Locates an information field keyword in the VPD
372 * @buf: Pointer to buffered vpd data
373 * @off: The offset into the buffer at which to begin the search
374 * @len: The length of the buffer area, relative to off, in which to search
375 * @kw: The keyword to search for
377 * Returns the index where the information field keyword was found or
380 #define pci_vpd_find_info_keyword LINUX_BACKPORT(pci_vpd_find_info_keyword)
381 int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
382 unsigned int len, const char *kw);
385 * pci_vpd_find_tag - Locates the Resource Data Type tag provided
386 * @buf: Pointer to buffered vpd data
387 * @off: The offset into the buffer at which to begin the search
388 * @len: The length of the vpd buffer
389 * @rdt: The Resource Data Type to search for
391 * Returns the index where the Resource Data Type was found or
394 #define pci_vpd_find_tag LINUX_BACKPORT(pci_vpd_find_tag)
395 int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt);
398 * pci_vpd_srdt_size - Extracts the Small Resource Data Type length
399 * @lrdt: Pointer to the beginning of the Small Resource Data Type tag
401 * Returns the extracted Small Resource Data Type length.
403 #define pci_vpd_srdt_size LINUX_BACKPORT(pci_vpd_srdt_size)
404 static inline u8 pci_vpd_srdt_size(const u8 *srdt)
406 return (*srdt) & PCI_VPD_SRDT_LEN_MASK;
409 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34)) */
412 #endif /* LINUX_26_34_COMPAT_H */