2 * Linux-specific abstractions to gain some independence from linux kernel versions.
3 * Pave over some 2.2 versus 2.4 versus 2.6 kernel differences.
5 * Copyright (C) 1999-2010, Broadcom Corporation
7 * Unless you and Broadcom execute a separate written software license
8 * agreement governing use of this software, this software is licensed to you
9 * under the terms of the GNU General Public License version 2 (the "GPL"),
10 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
11 * following added to such license:
13 * As a special exception, the copyright holders of this software give you
14 * permission to link this software with independent modules, and to copy and
15 * distribute the resulting executable under terms of your choice, provided that
16 * you also meet, for each linked independent module, the terms and conditions of
17 * the license of that module. An independent module is a module which is not
18 * derived from this software. The special exception does not apply to any
19 * modifications of the software.
21 * Notwithstanding the above, under no circumstances may you combine this
22 * software in any way with any other Broadcom software provided under a license
23 * other than the GPL, without Broadcom's express prior written consent.
25 * $Id: linuxver.h,v 13.38.8.1.8.6 2010/04/29 05:00:46 Exp $
32 #include <linux/version.h>
33 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
34 #include <linux/config.h>
35 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33))
36 #include <linux/autoconf.h>
38 #include <linux/module.h>
40 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0))
42 #ifdef __UNDEF_NO_VERSION__
45 #define __NO_VERSION__
49 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
50 #define module_param(_name_, _type_, _perm_) MODULE_PARM(_name_, "i")
51 #define module_param_string(_name_, _string_, _size_, _perm_) \
52 MODULE_PARM(_string_, "c" __MODULE_STRING(_size_))
56 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 9))
57 #include <linux/malloc.h>
59 #include <linux/slab.h>
62 #include <linux/types.h>
63 #include <linux/init.h>
65 #include <linux/string.h>
66 #include <linux/pci.h>
67 #include <linux/interrupt.h>
68 #include <linux/netdevice.h>
69 #include <linux/semaphore.h>
70 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
75 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41))
76 #include <linux/workqueue.h>
78 #include <linux/tqueue.h>
80 #define work_struct tq_struct
83 #define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data))
86 #define schedule_work(_work) schedule_task((_work))
88 #ifndef flush_scheduled_work
89 #define flush_scheduled_work() flush_scheduled_tasks()
93 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
94 #define MY_INIT_WORK(_work, _func, _data) INIT_WORK(_work, _func)
96 #define MY_INIT_WORK(_work, _func, _data) INIT_WORK(_work, _func, _data)
97 typedef void (*work_func_t)(void *work);
100 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
103 typedef void irqreturn_t;
106 #define IRQ_RETVAL(x)
109 typedef irqreturn_t(*FN_ISR) (int irq, void *dev_id, struct pt_regs *ptregs);
112 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
113 #define IRQF_SHARED SA_SHIRQ
116 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 17)
117 #ifdef CONFIG_NET_RADIO
118 #define CONFIG_WIRELESS_EXT
122 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 67)
124 #define MOD_INC_USE_COUNT
136 #define __devinit __init
138 #ifndef __devinitdata
139 #define __devinitdata
142 #define __devexit_p(x) x
145 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0))
147 #define pci_get_drvdata(dev) (dev)->sysdata
148 #define pci_set_drvdata(dev, value) (dev)->sysdata = (value)
152 struct pci_device_id {
153 unsigned int vendor, device;
154 unsigned int subvendor, subdevice;
155 unsigned int class, class_mask;
156 unsigned long driver_data;
160 struct list_head node;
162 const struct pci_device_id *id_table;
163 int (*probe)(struct pci_dev *dev,
164 const struct pci_device_id *id);
165 void (*remove)(struct pci_dev *dev);
166 void (*suspend)(struct pci_dev *dev);
167 void (*resume)(struct pci_dev *dev);
170 #define MODULE_DEVICE_TABLE(type, name)
171 #define PCI_ANY_ID (~0)
174 #define pci_module_init pci_register_driver
175 extern int pci_register_driver(struct pci_driver *drv);
176 extern void pci_unregister_driver(struct pci_driver *drv);
180 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18))
181 #define pci_module_init pci_register_driver
184 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18))
186 #define module_init(x) int init_module(void) { return x(); }
187 #define module_exit(x) void cleanup_module(void) { x(); }
189 #define module_init(x) __initcall(x);
190 #define module_exit(x) __exitcall(x);
194 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 48))
195 #define list_for_each(pos, head) \
196 for (pos = (head)->next; pos != (head); pos = pos->next)
199 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 13))
200 #define pci_resource_start(dev, bar) ((dev)->base_address[(bar)])
201 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 44))
202 #define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
205 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 23))
206 #define pci_enable_device(dev) do { } while (0)
209 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 14))
210 #define net_device device
213 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 42))
217 #ifndef PCI_DMA_TODEVICE
218 #define PCI_DMA_TODEVICE 1
219 #define PCI_DMA_FROMDEVICE 2
222 typedef u32 dma_addr_t;
225 static inline int get_order(unsigned long size)
229 size = (size-1) >> (PAGE_SHIFT-1);
238 static inline void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
239 dma_addr_t *dma_handle)
242 int gfp = GFP_ATOMIC | GFP_DMA;
244 ret = (void *)__get_free_pages(gfp, get_order(size));
247 memset(ret, 0, size);
248 *dma_handle = virt_to_bus(ret);
252 static inline void pci_free_consistent(struct pci_dev *hwdev, size_t size,
253 void *vaddr, dma_addr_t dma_handle)
255 free_pages((unsigned long)vaddr, get_order(size));
257 #define pci_map_single(cookie, address, size, dir) virt_to_bus(address)
258 #define pci_unmap_single(cookie, address, size, dir)
262 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43))
264 #define dev_kfree_skb_any(a) dev_kfree_skb(a)
265 #define netif_down(dev) do { (dev)->start = 0; } while (0)
268 #ifndef _COMPAT_NETDEVICE_H
272 #define dev_kfree_skb_irq(a) dev_kfree_skb(a)
273 #define netif_wake_queue(dev) \
274 do { clear_bit(0, &(dev)->tbusy); mark_bh(NET_BH); } while (0)
275 #define netif_stop_queue(dev) set_bit(0, &(dev)->tbusy)
277 static inline void netif_start_queue(struct net_device *dev)
284 #define netif_queue_stopped(dev) (dev)->tbusy
285 #define netif_running(dev) (dev)->start
289 #define netif_device_attach(dev) netif_start_queue(dev)
290 #define netif_device_detach(dev) netif_stop_queue(dev)
293 #define tasklet_struct tq_struct
294 static inline void tasklet_schedule(struct tasklet_struct *tasklet)
296 queue_task(tasklet, &tq_immediate);
297 mark_bh(IMMEDIATE_BH);
300 static inline void tasklet_init(struct tasklet_struct *tasklet,
301 void (*func)(unsigned long),
304 tasklet->next = NULL;
306 tasklet->routine = (void (*)(void *))func;
307 tasklet->data = (void *)data;
309 #define tasklet_kill(tasklet) { do {} while (0); }
312 #define del_timer_sync(timer) del_timer(timer)
316 #define netif_down(dev)
320 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3))
323 #define PREPARE_TQUEUE(_tq, _routine, _data) \
325 (_tq)->routine = _routine; \
326 (_tq)->data = _data; \
330 #define INIT_TQUEUE(_tq, _routine, _data) \
332 INIT_LIST_HEAD(&(_tq)->list); \
334 PREPARE_TQUEUE((_tq), (_routine), (_data)); \
339 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6))
344 pci_save_state(struct pci_dev *dev, u32 *buffer)
348 for (i = 0; i < 16; i++)
349 pci_read_config_dword(dev, i * 4, &buffer[i]);
355 pci_restore_state(struct pci_dev *dev, u32 *buffer)
360 for (i = 0; i < 16; i++)
361 pci_write_config_dword(dev, i * 4, buffer[i]);
365 for (i = 0; i < 6; i ++)
366 pci_write_config_dword(dev,
367 PCI_BASE_ADDRESS_0 + (i * 4),
368 pci_resource_start(dev, i));
369 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
377 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 19))
378 #define read_c0_count() read_32bit_cp0_register(CP0_COUNT)
382 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24))
383 #ifndef SET_MODULE_OWNER
384 #define SET_MODULE_OWNER(dev) do {} while (0)
385 #define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
386 #define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
388 #define OLD_MOD_INC_USE_COUNT do {} while (0)
389 #define OLD_MOD_DEC_USE_COUNT do {} while (0)
392 #ifndef SET_MODULE_OWNER
393 #define SET_MODULE_OWNER(dev) do {} while (0)
395 #ifndef MOD_INC_USE_COUNT
396 #define MOD_INC_USE_COUNT do {} while (0)
398 #ifndef MOD_DEC_USE_COUNT
399 #define MOD_DEC_USE_COUNT do {} while (0)
401 #define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
402 #define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
405 #ifndef SET_NETDEV_DEV
406 #define SET_NETDEV_DEV(net, pdev) do {} while (0)
409 #ifndef HAVE_FREE_NETDEV
410 #define free_netdev(dev) kfree(dev)
413 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
415 #define af_packet_priv data
419 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
420 #define DRV_SUSPEND_STATE_TYPE pm_message_t
422 #define DRV_SUSPEND_STATE_TYPE uint32
425 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
426 #define CHECKSUM_HW CHECKSUM_PARTIAL
429 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
430 #define KILL_PROC(pid, sig) \
432 struct task_struct *tsk; \
433 tsk = pid_task(find_vpid(pid), PIDTYPE_PID); \
434 if (tsk) send_sig(sig, tsk, 1); \
437 #define KILL_PROC(pid, sig) \
439 kill_proc(pid, sig, 1); \
443 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
444 #define netdev_priv(dev) dev->priv