1 #ifndef LINUX_26_27_COMPAT_H
2 #define LINUX_26_27_COMPAT_H
4 #include <linux/version.h>
6 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27))
8 #include <linux/debugfs.h>
9 #include <linux/list.h>
10 #include <linux/pci.h>
11 #include <linux/dma-mapping.h>
12 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
13 #include <linux/mmc/sdio.h>
14 #include <linux/mmc/sdio_func.h>
15 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) */
16 #include <linux/netdevice.h>
17 #include <linux/workqueue.h>
18 #include <net/iw_handler.h>
19 #include <asm-generic/bug.h>
20 #include <linux/wireless.h>
21 #include <linux/skbuff.h>
22 #include <net/sch_generic.h>
23 #include <linux/ethtool.h>
25 #define PCI_PM_CAP_PME_SHIFT 11
27 /* I can't find a more suitable replacement... */
28 #define flush_work(work) cancel_work_sync(work)
37 * On older kernels we do not have net_device Multi Queue support, but
38 * since we no longer use MQ on mac80211 we can simply use the 0 queue.
39 * Note that if other fullmac drivers make use of this they then need
40 * to be backported somehow or deal with just 1 queueue from MQ.
42 static inline void netif_tx_wake_all_queues(struct net_device *dev)
44 netif_wake_queue(dev);
46 static inline void netif_tx_start_all_queues(struct net_device *dev)
48 netif_start_queue(dev);
50 static inline void netif_tx_stop_all_queues(struct net_device *dev)
52 netif_stop_queue(dev);
55 /* Are all TX queues of the device empty? */
56 static inline bool qdisc_all_tx_empty(const struct net_device *dev)
58 return skb_queue_empty(&dev->qdisc->q);
61 bool pci_pme_capable(struct pci_dev *dev, pci_power_t state);
64 * The net_device has a spin_lock on newer kernels, on older kernels we're out of luck
66 #define netif_addr_lock_bh(dev)
67 #define netif_addr_unlock_bh(dev)
70 * To port this properly we'd have to port warn_slowpath_null(),
71 * which I'm lazy to do so just do a regular print for now. If you
72 * want to port this read kernel/panic.c
74 #define __WARN_printf(arg...) do { printk(arg); __WARN(); } while (0)
76 /* This is ported directly as-is on newer kernels */
78 #define WARN(condition, format...) ({ \
79 int __ret_warn_on = !!(condition); \
80 if (unlikely(__ret_warn_on)) \
81 __WARN_printf(format); \
82 unlikely(__ret_warn_on); \
86 /* On 2.6.27 a second argument was added, on older kernels we ignore it */
87 #define dma_mapping_error(pdev, dma_addr) dma_mapping_error(dma_addr)
88 #define pci_dma_mapping_error(pdev, dma_addr) dma_mapping_error(pdev, dma_addr)
90 /* This is from include/linux/ieee80211.h */
91 #define IEEE80211_HT_CAP_DSSSCCK40 0x1000
93 /* New link list changes added as of 2.6.27, needed for ath9k */
95 static inline void __list_cut_position(struct list_head *list,
96 struct list_head *head, struct list_head *entry)
98 struct list_head *new_first = entry->next;
99 list->next = head->next;
100 list->next->prev = list;
103 head->next = new_first;
104 new_first->prev = head;
108 * list_cut_position - cut a list into two
109 * @list: a new list to add all removed entries
110 * @head: a list with entries
111 * @entry: an entry within head, could be the head itself
112 * and if so we won't cut the list
114 * This helper moves the initial part of @head, up to and
115 * including @entry, from @head to @list. You should
116 * pass on @entry an element you know is on @head. @list
117 * should be an empty list or a list you do not care about
121 static inline void list_cut_position(struct list_head *list,
122 struct list_head *head, struct list_head *entry)
124 if (list_empty(head))
126 if (list_is_singular(head) &&
127 (head->next != entry && head != entry))
130 INIT_LIST_HEAD(list);
132 __list_cut_position(list, head, entry);
136 /* __list_splice as re-implemented on 2.6.27, we backport it */
137 static inline void __compat_list_splice_new_27(const struct list_head *list,
138 struct list_head *prev,
139 struct list_head *next)
141 struct list_head *first = list->next;
142 struct list_head *last = list->prev;
152 * list_splice_tail - join two lists, each list being a queue
153 * @list: the new list to add.
154 * @head: the place to add it in the first list.
156 static inline void list_splice_tail(struct list_head *list,
157 struct list_head *head)
159 if (!list_empty(list))
160 __compat_list_splice_new_27(list, head->prev, head);
164 * list_splice_tail_init - join two lists and reinitialise the emptied list
165 * @list: the new list to add.
166 * @head: the place to add it in the first list.
168 * Each of the lists is a queue.
169 * The list at @list is reinitialised
171 static inline void list_splice_tail_init(struct list_head *list,
172 struct list_head *head)
174 if (!list_empty(list)) {
175 __compat_list_splice_new_27(list, head->prev, head);
176 INIT_LIST_HEAD(list);
180 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
181 extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int);
182 extern unsigned int sdio_align_size(struct sdio_func *func, unsigned int sz);
183 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) */
185 #define iwe_stream_add_value(info, event, value, ends, iwe, event_len) iwe_stream_add_value(event, value, ends, iwe, event_len)
186 #define iwe_stream_add_point(info, stream, ends, iwe, extra) iwe_stream_add_point(stream, ends, iwe, extra)
187 #define iwe_stream_add_event(info, stream, ends, iwe, event_len) iwe_stream_add_event(stream, ends, iwe, event_len)
189 /* Flags available in struct iw_request_info */
190 #define IW_REQUEST_FLAG_COMPAT 0x0001 /* Compat ioctl call */
192 static inline int iwe_stream_lcp_len(struct iw_request_info *info)
195 if (info->flags & IW_REQUEST_FLAG_COMPAT)
196 return IW_EV_COMPAT_LCP_LEN;
198 return IW_EV_LCP_LEN;
204 * The caller asks to handle a range between offset and offset + size,
205 * but we process a larger range from 0 to offset + size due to lack of
209 static inline void dma_sync_single_range_for_cpu(struct device *dev,
210 dma_addr_t handle, unsigned long offset, size_t size,
211 enum dma_data_direction dir)
213 dma_sync_single_for_cpu(dev, handle, offset + size, dir);
216 static inline void dma_sync_single_range_for_device(struct device *dev,
217 dma_addr_t handle, unsigned long offset, size_t size,
218 enum dma_data_direction dir)
220 dma_sync_single_for_device(dev, handle, offset + size, dir);
225 #if defined(CONFIG_DEBUG_FS)
226 void debugfs_remove_recursive(struct dentry *dentry);
228 static inline void debugfs_remove_recursive(struct dentry *dentry)
232 #define device_create(cls, parent, devt, drvdata, fmt, ...) \
234 struct device *_dev; \
235 _dev = (device_create)(cls, parent, devt, fmt, __VA_ARGS__); \
236 dev_set_drvdata(_dev, drvdata); \
240 #define dev_name(dev) dev_name((struct device *)dev)
242 static inline void ethtool_cmd_speed_set(struct ethtool_cmd *ep,
245 ep->speed = (__u16)speed;
248 static inline __u32 ethtool_cmd_speed(const struct ethtool_cmd *ep)
253 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)) */
255 #endif /* LINUX_26_27_COMPAT_H */