• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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.
4  *
5  * Copyright (C) 1999-2009, Broadcom Corporation
6  *
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:
12  *
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.
20  *
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.
24  *
25  * $Id: linuxver.h,v 13.38.8.1.8.3 2009/06/19 04:42:45 Exp $
26  */
27 
28 
29 #ifndef _linuxver_h_
30 #define _linuxver_h_
31 
32 #include <linux/version.h>
33 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
34 #include <linux/config.h>
35 #else
36 #include <linux/autoconf.h>
37 #endif
38 #include <linux/module.h>
39 
40 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0))
41 
42 #ifdef __UNDEF_NO_VERSION__
43 #undef __NO_VERSION__
44 #else
45 #define __NO_VERSION__
46 #endif
47 #endif
48 
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_))
53 #endif
54 
55 
56 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 9))
57 #include <linux/malloc.h>
58 #else
59 #include <linux/slab.h>
60 #endif
61 
62 #include <linux/types.h>
63 #include <linux/init.h>
64 #include <linux/mm.h>
65 #include <linux/string.h>
66 #include <linux/pci.h>
67 #include <linux/interrupt.h>
68 #include <linux/netdevice.h>
69 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
70 #undef IP_TOS
71 #endif
72 #include <asm/io.h>
73 
74 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41))
75 #include <linux/workqueue.h>
76 #else
77 #include <linux/tqueue.h>
78 #ifndef work_struct
79 #define work_struct tq_struct
80 #endif
81 #ifndef INIT_WORK
82 #define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data))
83 #endif
84 #ifndef schedule_work
85 #define schedule_work(_work) schedule_task((_work))
86 #endif
87 #ifndef flush_scheduled_work
88 #define flush_scheduled_work() flush_scheduled_tasks()
89 #endif
90 #endif
91 
92 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
93 #define	MY_INIT_WORK(_work, _func, _data)	INIT_WORK(_work, _func)
94 #else
95 #define	MY_INIT_WORK(_work, _func, _data)	INIT_WORK(_work, _func, _data)
96 typedef void (*work_func_t)(void *work);
97 #endif
98 
99 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
100 
101 #ifndef IRQ_NONE
102 typedef void irqreturn_t;
103 #define IRQ_NONE
104 #define IRQ_HANDLED
105 #define IRQ_RETVAL(x)
106 #endif
107 #else
108 typedef irqreturn_t(*FN_ISR) (int irq, void *dev_id, struct pt_regs *ptregs);
109 #endif
110 
111 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
112 #define IRQF_SHARED	SA_SHIRQ
113 #endif
114 
115 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 17)
116 #ifdef	CONFIG_NET_RADIO
117 #define	CONFIG_WIRELESS_EXT
118 #endif
119 #endif
120 
121 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 67)
122 #ifndef SANDGATE2G
123 #define MOD_INC_USE_COUNT
124 #endif
125 #endif
126 
127 
128 #ifndef __exit
129 #define __exit
130 #endif
131 #ifndef __devexit
132 #define __devexit
133 #endif
134 #ifndef __devinit
135 #define __devinit	__init
136 #endif
137 #ifndef __devinitdata
138 #define __devinitdata
139 #endif
140 #ifndef __devexit_p
141 #define __devexit_p(x)	x
142 #endif
143 
144 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0))
145 
146 #define pci_get_drvdata(dev)		(dev)->sysdata
147 #define pci_set_drvdata(dev, value)	(dev)->sysdata = (value)
148 
149 
150 
151 struct pci_device_id {
152 	unsigned int vendor, device;
153 	unsigned int subvendor, subdevice;
154 	unsigned int class, class_mask;
155 	unsigned long driver_data;
156 };
157 
158 struct pci_driver {
159 	struct list_head node;
160 	char *name;
161 	const struct pci_device_id *id_table;
162 	int (*probe)(struct pci_dev *dev,
163 	             const struct pci_device_id *id);
164 	void (*remove)(struct pci_dev *dev);
165 	void (*suspend)(struct pci_dev *dev);
166 	void (*resume)(struct pci_dev *dev);
167 };
168 
169 #define MODULE_DEVICE_TABLE(type, name)
170 #define PCI_ANY_ID (~0)
171 
172 
173 #define pci_module_init pci_register_driver
174 extern int pci_register_driver(struct pci_driver *drv);
175 extern void pci_unregister_driver(struct pci_driver *drv);
176 
177 #endif
178 
179 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18))
180 #define pci_module_init pci_register_driver
181 #endif
182 
183 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18))
184 #ifdef MODULE
185 #define module_init(x) int init_module(void) { return x(); }
186 #define module_exit(x) void cleanup_module(void) { x(); }
187 #else
188 #define module_init(x)	__initcall(x);
189 #define module_exit(x)	__exitcall(x);
190 #endif
191 #endif
192 
193 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 48))
194 #define list_for_each(pos, head) \
195 	for (pos = (head)->next; pos != (head); pos = pos->next)
196 #endif
197 
198 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 13))
199 #define pci_resource_start(dev, bar)	((dev)->base_address[(bar)])
200 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 44))
201 #define pci_resource_start(dev, bar)	((dev)->resource[(bar)].start)
202 #endif
203 
204 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 23))
205 #define pci_enable_device(dev) do { } while (0)
206 #endif
207 
208 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 14))
209 #define net_device device
210 #endif
211 
212 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 42))
213 
214 
215 
216 #ifndef PCI_DMA_TODEVICE
217 #define	PCI_DMA_TODEVICE	1
218 #define	PCI_DMA_FROMDEVICE	2
219 #endif
220 
221 typedef u32 dma_addr_t;
222 
223 
get_order(unsigned long size)224 static inline int get_order(unsigned long size)
225 {
226 	int order;
227 
228 	size = (size-1) >> (PAGE_SHIFT-1);
229 	order = -1;
230 	do {
231 		size >>= 1;
232 		order++;
233 	} while (size);
234 	return order;
235 }
236 
pci_alloc_consistent(struct pci_dev * hwdev,size_t size,dma_addr_t * dma_handle)237 static inline void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
238                                          dma_addr_t *dma_handle)
239 {
240 	void *ret;
241 	int gfp = GFP_ATOMIC | GFP_DMA;
242 
243 	ret = (void *)__get_free_pages(gfp, get_order(size));
244 
245 	if (ret != NULL) {
246 		memset(ret, 0, size);
247 		*dma_handle = virt_to_bus(ret);
248 	}
249 	return ret;
250 }
pci_free_consistent(struct pci_dev * hwdev,size_t size,void * vaddr,dma_addr_t dma_handle)251 static inline void pci_free_consistent(struct pci_dev *hwdev, size_t size,
252                                        void *vaddr, dma_addr_t dma_handle)
253 {
254 	free_pages((unsigned long)vaddr, get_order(size));
255 }
256 #define pci_map_single(cookie, address, size, dir)	virt_to_bus(address)
257 #define pci_unmap_single(cookie, address, size, dir)
258 
259 #endif
260 
261 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43))
262 
263 #define dev_kfree_skb_any(a)		dev_kfree_skb(a)
264 #define netif_down(dev)			do { (dev)->start = 0; } while (0)
265 
266 
267 #ifndef _COMPAT_NETDEVICE_H
268 
269 
270 
271 #define dev_kfree_skb_irq(a)	dev_kfree_skb(a)
272 #define netif_wake_queue(dev) \
273 		do { clear_bit(0, &(dev)->tbusy); mark_bh(NET_BH); } while (0)
274 #define netif_stop_queue(dev)	set_bit(0, &(dev)->tbusy)
275 
netif_start_queue(struct net_device * dev)276 static inline void netif_start_queue(struct net_device *dev)
277 {
278 	dev->tbusy = 0;
279 	dev->interrupt = 0;
280 	dev->start = 1;
281 }
282 
283 #define netif_queue_stopped(dev)	(dev)->tbusy
284 #define netif_running(dev)		(dev)->start
285 
286 #endif
287 
288 #define netif_device_attach(dev)	netif_start_queue(dev)
289 #define netif_device_detach(dev)	netif_stop_queue(dev)
290 
291 
292 #define tasklet_struct				tq_struct
tasklet_schedule(struct tasklet_struct * tasklet)293 static inline void tasklet_schedule(struct tasklet_struct *tasklet)
294 {
295 	queue_task(tasklet, &tq_immediate);
296 	mark_bh(IMMEDIATE_BH);
297 }
298 
tasklet_init(struct tasklet_struct * tasklet,void (* func)(unsigned long),unsigned long data)299 static inline void tasklet_init(struct tasklet_struct *tasklet,
300                                 void (*func)(unsigned long),
301                                 unsigned long data)
302 {
303 	tasklet->next = NULL;
304 	tasklet->sync = 0;
305 	tasklet->routine = (void (*)(void *))func;
306 	tasklet->data = (void *)data;
307 }
308 #define tasklet_kill(tasklet)	{ do {} while (0); }
309 
310 
311 #define del_timer_sync(timer) del_timer(timer)
312 
313 #else
314 
315 #define netif_down(dev)
316 
317 #endif
318 
319 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3))
320 
321 
322 #define PREPARE_TQUEUE(_tq, _routine, _data)			\
323 	do {							\
324 		(_tq)->routine = _routine;			\
325 		(_tq)->data = _data;				\
326 	} while (0)
327 
328 
329 #define INIT_TQUEUE(_tq, _routine, _data)			\
330 	do {							\
331 		INIT_LIST_HEAD(&(_tq)->list);			\
332 		(_tq)->sync = 0;				\
333 		PREPARE_TQUEUE((_tq), (_routine), (_data));	\
334 	} while (0)
335 
336 #endif
337 
338 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6))
339 
340 
341 
342 static inline int
pci_save_state(struct pci_dev * dev,u32 * buffer)343 pci_save_state(struct pci_dev *dev, u32 *buffer)
344 {
345 	int i;
346 	if (buffer) {
347 		for (i = 0; i < 16; i++)
348 			pci_read_config_dword(dev, i * 4, &buffer[i]);
349 	}
350 	return 0;
351 }
352 
353 static inline int
pci_restore_state(struct pci_dev * dev,u32 * buffer)354 pci_restore_state(struct pci_dev *dev, u32 *buffer)
355 {
356 	int i;
357 
358 	if (buffer) {
359 		for (i = 0; i < 16; i++)
360 			pci_write_config_dword(dev, i * 4, buffer[i]);
361 	}
362 
363 	else {
364 		for (i = 0; i < 6; i ++)
365 			pci_write_config_dword(dev,
366 			                       PCI_BASE_ADDRESS_0 + (i * 4),
367 			                       pci_resource_start(dev, i));
368 		pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
369 	}
370 	return 0;
371 }
372 
373 #endif
374 
375 
376 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 19))
377 #define read_c0_count() read_32bit_cp0_register(CP0_COUNT)
378 #endif
379 
380 
381 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24))
382 #ifndef SET_MODULE_OWNER
383 #define SET_MODULE_OWNER(dev)		do {} while (0)
384 #define OLD_MOD_INC_USE_COUNT		MOD_INC_USE_COUNT
385 #define OLD_MOD_DEC_USE_COUNT		MOD_DEC_USE_COUNT
386 #else
387 #define OLD_MOD_INC_USE_COUNT		do {} while (0)
388 #define OLD_MOD_DEC_USE_COUNT		do {} while (0)
389 #endif
390 #else
391 #ifndef SET_MODULE_OWNER
392 #define SET_MODULE_OWNER(dev)		do {} while (0)
393 #endif
394 #ifndef MOD_INC_USE_COUNT
395 #define MOD_INC_USE_COUNT			do {} while (0)
396 #endif
397 #ifndef MOD_DEC_USE_COUNT
398 #define MOD_DEC_USE_COUNT			do {} while (0)
399 #endif
400 #define OLD_MOD_INC_USE_COUNT		MOD_INC_USE_COUNT
401 #define OLD_MOD_DEC_USE_COUNT		MOD_DEC_USE_COUNT
402 #endif
403 
404 #ifndef SET_NETDEV_DEV
405 #define SET_NETDEV_DEV(net, pdev)	do {} while (0)
406 #endif
407 
408 #ifndef HAVE_FREE_NETDEV
409 #define free_netdev(dev)		kfree(dev)
410 #endif
411 
412 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
413 
414 #define af_packet_priv			data
415 #endif
416 
417 
418 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
419 #define DRV_SUSPEND_STATE_TYPE pm_message_t
420 #else
421 #define DRV_SUSPEND_STATE_TYPE uint32
422 #endif
423 
424 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
425 #define CHECKSUM_HW	CHECKSUM_PARTIAL
426 #endif
427 
428 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
429 #define KILL_PROC(pid, sig) \
430 { \
431 	struct task_struct *tsk; \
432 	tsk = find_task_by_vpid(pid); \
433 	if (tsk) send_sig(sig, tsk, 1); \
434 }
435 #else
436 #define KILL_PROC(pid, sig) \
437 { \
438 	kill_proc(pid, sig, 1); \
439 }
440 #endif
441 
442 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
443 #define netdev_priv(dev) dev->priv
444 #endif
445 
446 #endif
447