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-2010, 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.6 2010/04/29 05:00:46 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 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)) 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 #include <linux/semaphore.h> 70 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28)) 71 #undef IP_TOS 72 #endif 73 #include <asm/io.h> 74 75 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41)) 76 #include <linux/workqueue.h> 77 #else 78 #include <linux/tqueue.h> 79 #ifndef work_struct 80 #define work_struct tq_struct 81 #endif 82 #ifndef INIT_WORK 83 #define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data)) 84 #endif 85 #ifndef schedule_work 86 #define schedule_work(_work) schedule_task((_work)) 87 #endif 88 #ifndef flush_scheduled_work 89 #define flush_scheduled_work() flush_scheduled_tasks() 90 #endif 91 #endif 92 93 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) 94 #define MY_INIT_WORK(_work, _func, _data) INIT_WORK(_work, _func) 95 #else 96 #define MY_INIT_WORK(_work, _func, _data) INIT_WORK(_work, _func, _data) 97 typedef void (*work_func_t)(void *work); 98 #endif 99 100 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) 101 102 #ifndef IRQ_NONE 103 typedef void irqreturn_t; 104 #define IRQ_NONE 105 #define IRQ_HANDLED 106 #define IRQ_RETVAL(x) 107 #endif 108 #else 109 typedef irqreturn_t(*FN_ISR) (int irq, void *dev_id, struct pt_regs *ptregs); 110 #endif 111 112 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18) 113 #define IRQF_SHARED SA_SHIRQ 114 #endif 115 116 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 17) 117 #ifdef CONFIG_NET_RADIO 118 #define CONFIG_WIRELESS_EXT 119 #endif 120 #endif 121 122 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 67) 123 #ifndef SANDGATE2G 124 #define MOD_INC_USE_COUNT 125 #endif 126 #endif 127 128 129 #ifndef __exit 130 #define __exit 131 #endif 132 #ifndef __devexit 133 #define __devexit 134 #endif 135 #ifndef __devinit 136 #define __devinit __init 137 #endif 138 #ifndef __devinitdata 139 #define __devinitdata 140 #endif 141 #ifndef __devexit_p 142 #define __devexit_p(x) x 143 #endif 144 145 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)) 146 147 #define pci_get_drvdata(dev) (dev)->sysdata 148 #define pci_set_drvdata(dev, value) (dev)->sysdata = (value) 149 150 151 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; 157 }; 158 159 struct pci_driver { 160 struct list_head node; 161 char *name; 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); 168 }; 169 170 #define MODULE_DEVICE_TABLE(type, name) 171 #define PCI_ANY_ID (~0) 172 173 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); 177 178 #endif 179 180 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18)) 181 #define pci_module_init pci_register_driver 182 #endif 183 184 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18)) 185 #ifdef MODULE 186 #define module_init(x) int init_module(void) { return x(); } 187 #define module_exit(x) void cleanup_module(void) { x(); } 188 #else 189 #define module_init(x) __initcall(x); 190 #define module_exit(x) __exitcall(x); 191 #endif 192 #endif 193 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) 197 #endif 198 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) 203 #endif 204 205 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 23)) 206 #define pci_enable_device(dev) do { } while (0) 207 #endif 208 209 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 14)) 210 #define net_device device 211 #endif 212 213 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 42)) 214 215 216 217 #ifndef PCI_DMA_TODEVICE 218 #define PCI_DMA_TODEVICE 1 219 #define PCI_DMA_FROMDEVICE 2 220 #endif 221 222 typedef u32 dma_addr_t; 223 224 225 static inline int get_order(unsigned long size) 226 { 227 int order; 228 229 size = (size-1) >> (PAGE_SHIFT-1); 230 order = -1; 231 do { 232 size >>= 1; 233 order++; 234 } while (size); 235 return order; 236 } 237 238 static inline void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size, 239 dma_addr_t *dma_handle) 240 { 241 void *ret; 242 int gfp = GFP_ATOMIC | GFP_DMA; 243 244 ret = (void *)__get_free_pages(gfp, get_order(size)); 245 246 if (ret != NULL) { 247 memset(ret, 0, size); 248 *dma_handle = virt_to_bus(ret); 249 } 250 return ret; 251 } 252 static inline void pci_free_consistent(struct pci_dev *hwdev, size_t size, 253 void *vaddr, dma_addr_t dma_handle) 254 { 255 free_pages((unsigned long)vaddr, get_order(size)); 256 } 257 #define pci_map_single(cookie, address, size, dir) virt_to_bus(address) 258 #define pci_unmap_single(cookie, address, size, dir) 259 260 #endif 261 262 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43)) 263 264 #define dev_kfree_skb_any(a) dev_kfree_skb(a) 265 #define netif_down(dev) do { (dev)->start = 0; } while (0) 266 267 268 #ifndef _COMPAT_NETDEVICE_H 269 270 271 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) 276 277 static inline void netif_start_queue(struct net_device *dev) 278 { 279 dev->tbusy = 0; 280 dev->interrupt = 0; 281 dev->start = 1; 282 } 283 284 #define netif_queue_stopped(dev) (dev)->tbusy 285 #define netif_running(dev) (dev)->start 286 287 #endif 288 289 #define netif_device_attach(dev) netif_start_queue(dev) 290 #define netif_device_detach(dev) netif_stop_queue(dev) 291 292 293 #define tasklet_struct tq_struct 294 static inline void tasklet_schedule(struct tasklet_struct *tasklet) 295 { 296 queue_task(tasklet, &tq_immediate); 297 mark_bh(IMMEDIATE_BH); 298 } 299 300 static inline void tasklet_init(struct tasklet_struct *tasklet, 301 void (*func)(unsigned long), 302 unsigned long data) 303 { 304 tasklet->next = NULL; 305 tasklet->sync = 0; 306 tasklet->routine = (void (*)(void *))func; 307 tasklet->data = (void *)data; 308 } 309 #define tasklet_kill(tasklet) { do {} while (0); } 310 311 312 #define del_timer_sync(timer) del_timer(timer) 313 314 #else 315 316 #define netif_down(dev) 317 318 #endif 319 320 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3)) 321 322 323 #define PREPARE_TQUEUE(_tq, _routine, _data) \ 324 do { \ 325 (_tq)->routine = _routine; \ 326 (_tq)->data = _data; \ 327 } while (0) 328 329 330 #define INIT_TQUEUE(_tq, _routine, _data) \ 331 do { \ 332 INIT_LIST_HEAD(&(_tq)->list); \ 333 (_tq)->sync = 0; \ 334 PREPARE_TQUEUE((_tq), (_routine), (_data)); \ 335 } while (0) 336 337 #endif 338 339 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6)) 340 341 342 343 static inline int 344 pci_save_state(struct pci_dev *dev, u32 *buffer) 345 { 346 int i; 347 if (buffer) { 348 for (i = 0; i < 16; i++) 349 pci_read_config_dword(dev, i * 4, &buffer[i]); 350 } 351 return 0; 352 } 353 354 static inline int 355 pci_restore_state(struct pci_dev *dev, u32 *buffer) 356 { 357 int i; 358 359 if (buffer) { 360 for (i = 0; i < 16; i++) 361 pci_write_config_dword(dev, i * 4, buffer[i]); 362 } 363 364 else { 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); 370 } 371 return 0; 372 } 373 374 #endif 375 376 377 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 19)) 378 #define read_c0_count() read_32bit_cp0_register(CP0_COUNT) 379 #endif 380 381 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 387 #else 388 #define OLD_MOD_INC_USE_COUNT do {} while (0) 389 #define OLD_MOD_DEC_USE_COUNT do {} while (0) 390 #endif 391 #else 392 #ifndef SET_MODULE_OWNER 393 #define SET_MODULE_OWNER(dev) do {} while (0) 394 #endif 395 #ifndef MOD_INC_USE_COUNT 396 #define MOD_INC_USE_COUNT do {} while (0) 397 #endif 398 #ifndef MOD_DEC_USE_COUNT 399 #define MOD_DEC_USE_COUNT do {} while (0) 400 #endif 401 #define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT 402 #define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT 403 #endif 404 405 #ifndef SET_NETDEV_DEV 406 #define SET_NETDEV_DEV(net, pdev) do {} while (0) 407 #endif 408 409 #ifndef HAVE_FREE_NETDEV 410 #define free_netdev(dev) kfree(dev) 411 #endif 412 413 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) 414 415 #define af_packet_priv data 416 #endif 417 418 419 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11) 420 #define DRV_SUSPEND_STATE_TYPE pm_message_t 421 #else 422 #define DRV_SUSPEND_STATE_TYPE uint32 423 #endif 424 425 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) 426 #define CHECKSUM_HW CHECKSUM_PARTIAL 427 #endif 428 429 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) 430 #define KILL_PROC(pid, sig) \ 431 { \ 432 struct task_struct *tsk; \ 433 tsk = pid_task(find_vpid(pid), PIDTYPE_PID); \ 434 if (tsk) send_sig(sig, tsk, 1); \ 435 } 436 #else 437 #define KILL_PROC(pid, sig) \ 438 { \ 439 kill_proc(pid, sig, 1); \ 440 } 441 #endif 442 443 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) 444 #define netdev_priv(dev) dev->priv 445 #endif 446 447 #endif 448