|
|
1.1 ! root 1: #ifndef _KERN_COMPAT_H ! 2: #define _KERN_COMPAT_H ! 3: /* kern_compat.h: Linux PCI network adapter backward compatibility code. */ ! 4: /* ! 5: $Revision: 1.1.2.2 $ $Date: 2007/08/04 21:02:21 $ ! 6: ! 7: Kernel compatibility defines. ! 8: This file provides macros to mask the difference between kernel versions. ! 9: It is designed primarily to allow device drivers to be written so that ! 10: they work with a range of kernel versions. ! 11: ! 12: Written 1999-2003 Donald Becker, Scyld Computing Corporation ! 13: This software may be used and distributed according to the terms ! 14: of the GNU General Public License (GPL), incorporated herein by ! 15: reference. Drivers interacting with these functions are derivative ! 16: works and thus are covered the GPL. They must include an explicit ! 17: GPL notice. ! 18: ! 19: This code also provides inline scan and activate functions for PCI network ! 20: interfaces. It has an interface identical to pci-scan.c, but is ! 21: intended as an include file to simplify using updated drivers with older ! 22: kernel versions. ! 23: This code version matches pci-scan.c:v0.05 9/16/99 ! 24: ! 25: The author may be reached as [email protected], or ! 26: Donald Becker ! 27: Penguin Computing Corporation ! 28: 914 Bay Ridge Road, Suite 220 ! 29: Annapolis MD 21403 ! 30: ! 31: Other contributers: ! 32: <none> ! 33: */ ! 34: ! 35: /* We try to use defined values to decide when an interface has changed or ! 36: added features, but we must have the kernel version number for a few. */ ! 37: #if ! defined(LINUX_VERSION_CODE) || (LINUX_VERSION_CODE < 0x10000) ! 38: #include <linux/version.h> ! 39: #endif ! 40: /* Older kernel versions didn't include modversions automatically. */ ! 41: #if LINUX_VERSION_CODE < 0x20300 && defined(MODVERSIONS) ! 42: #include <linux/modversions.h> ! 43: #endif ! 44: ! 45: /* There was no support for PCI address space mapping in 2.0, but the ! 46: Alpha needed it. See the 2.2 documentation. */ ! 47: #if LINUX_VERSION_CODE < 0x20100 && ! defined(__alpha__) ! 48: #define ioremap(a,b)\ ! 49: (((unsigned long)(a) >= 0x100000) ? vremap(a,b) : (void*)(a)) ! 50: #define iounmap(v)\ ! 51: do { if ((unsigned long)(v) >= 0x100000) vfree(v);} while (0) ! 52: #endif ! 53: ! 54: /* Support for adding info about the purpose of and parameters for kernel ! 55: modules was added in 2.1. */ ! 56: #if LINUX_VERSION_CODE < 0x20115 ! 57: #define MODULE_AUTHOR(name) extern int nonesuch ! 58: #define MODULE_DESCRIPTION(string) extern int nonesuch ! 59: #define MODULE_PARM(varname, typestring) extern int nonesuch ! 60: #define MODULE_PARM_DESC(var,desc) extern int nonesuch ! 61: #endif ! 62: #if !defined(MODULE_LICENSE) ! 63: #define MODULE_LICENSE(license) \ ! 64: static const char __module_license[] __attribute__((section(".modinfo"))) = \ ! 65: "license=" license ! 66: #endif ! 67: #if !defined(MODULE_PARM_DESC) ! 68: #define MODULE_PARM_DESC(var,desc) \ ! 69: const char __module_parm_desc_##var[] \ ! 70: __attribute__((section(".modinfo"))) = \ ! 71: "parm_desc_" __MODULE_STRING(var) "=" desc ! 72: #endif ! 73: ! 74: /* SMP and better multiarchitecture support were added. ! 75: Using an older kernel means we assume a little-endian uniprocessor. ! 76: */ ! 77: #if LINUX_VERSION_CODE < 0x20123 ! 78: #define hard_smp_processor_id() smp_processor_id() ! 79: //#define test_and_set_bit(val, addr) set_bit(val, addr) ! 80: #define cpu_to_le16(val) (val) ! 81: #define cpu_to_le32(val) (val) ! 82: #define le16_to_cpu(val) (val) ! 83: #define le16_to_cpus(val) /* In-place conversion. */ ! 84: #define le32_to_cpu(val) (val) ! 85: #define cpu_to_be16(val) ((((val) & 0xff) << 8) + (((val) >> 8) & 0xff)) ! 86: #define cpu_to_be32(val) ((cpu_to_be16(val) << 16) + cpu_to_be16((val) >> 16)) ! 87: typedef long spinlock_t; ! 88: #define SPIN_LOCK_UNLOCKED 0 ! 89: #define spin_lock(lock) ! 90: #define spin_unlock(lock) ! 91: #define spin_lock_irqsave(lock, flags) do {save_flags(flags); cli();} while(0) ! 92: #define spin_unlock_irqrestore(lock, flags) restore_flags(flags) ! 93: #endif ! 94: ! 95: #if LINUX_VERSION_CODE <= 0x20139 ! 96: #define net_device_stats enet_statistics ! 97: #else ! 98: #define NETSTATS_VER2 ! 99: #endif ! 100: ! 101: /* These are used by the netdrivers to report values from the ! 102: MII (Media Indpendent Interface) management registers. ! 103: */ ! 104: #ifndef SIOCGMIIPHY ! 105: #define SIOCGMIIPHY (SIOCDEVPRIVATE) /* Get the PHY in use. */ ! 106: #define SIOCGMIIREG (SIOCDEVPRIVATE+1) /* Read a PHY register. */ ! 107: #define SIOCSMIIREG (SIOCDEVPRIVATE+2) /* Write a PHY register. */ ! 108: #endif ! 109: #ifndef SIOCGPARAMS ! 110: #define SIOCGPARAMS (SIOCDEVPRIVATE+3) /* Read operational parameters. */ ! 111: #define SIOCSPARAMS (SIOCDEVPRIVATE+4) /* Set operational parameters. */ ! 112: #endif ! 113: ! 114: #if !defined(HAVE_NETIF_MSG) ! 115: enum { ! 116: NETIF_MSG_DRV = 0x0001, ! 117: NETIF_MSG_PROBE = 0x0002, ! 118: NETIF_MSG_LINK = 0x0004, ! 119: NETIF_MSG_TIMER = 0x0008, ! 120: NETIF_MSG_IFDOWN = 0x0010, ! 121: NETIF_MSG_IFUP = 0x0020, ! 122: NETIF_MSG_RX_ERR = 0x0040, ! 123: NETIF_MSG_TX_ERR = 0x0080, ! 124: NETIF_MSG_TX_QUEUED = 0x0100, ! 125: NETIF_MSG_INTR = 0x0200, ! 126: NETIF_MSG_TX_DONE = 0x0400, ! 127: NETIF_MSG_RX_STATUS = 0x0800, ! 128: NETIF_MSG_PKTDATA = 0x1000, ! 129: /* 2000 is reserved. */ ! 130: NETIF_MSG_WOL = 0x4000, ! 131: NETIF_MSG_MISC = 0x8000, ! 132: NETIF_MSG_RXFILTER = 0x10000, ! 133: }; ! 134: #define NETIF_MSG_MAX 0x10000 ! 135: #endif ! 136: ! 137: #if !defined(NETIF_MSG_MAX) || NETIF_MSG_MAX < 0x8000 ! 138: #define NETIF_MSG_MISC 0x8000 ! 139: #endif ! 140: #if !defined(NETIF_MSG_MAX) || NETIF_MSG_MAX < 0x10000 ! 141: #define NETIF_MSG_RXFILTER 0x10000 ! 142: #endif ! 143: ! 144: #if LINUX_VERSION_CODE < 0x20155 ! 145: #include <linux/bios32.h> ! 146: #define PCI_SUPPORT_VER1 ! 147: /* A minimal version of the 2.2.* PCI support that handles configuration ! 148: space access. ! 149: Drivers that actually use pci_dev fields must do explicit compatibility. ! 150: Note that the struct pci_dev * "pointer" is actually a byte mapped integer! ! 151: */ ! 152: #if LINUX_VERSION_CODE < 0x20014 ! 153: struct pci_dev { int not_used; }; ! 154: #endif ! 155: ! 156: #define pci_find_slot(bus, devfn) (struct pci_dev*)((bus<<8) | devfn | 0xf0000) ! 157: #define bus_number(pci_dev) ((((int)(pci_dev))>>8) & 0xff) ! 158: #define devfn_number(pci_dev) (((int)(pci_dev)) & 0xff) ! 159: #define pci_bus_number(pci_dev) ((((int)(pci_dev))>>8) & 0xff) ! 160: #define pci_devfn(pci_dev) (((int)(pci_dev)) & 0xff) ! 161: ! 162: #ifndef CONFIG_PCI ! 163: extern inline int pci_present(void) { return 0; } ! 164: #else ! 165: #define pci_present pcibios_present ! 166: #endif ! 167: ! 168: #define pci_read_config_byte(pdev, where, valp)\ ! 169: pcibios_read_config_byte(bus_number(pdev), devfn_number(pdev), where, valp) ! 170: #define pci_read_config_word(pdev, where, valp)\ ! 171: pcibios_read_config_word(bus_number(pdev), devfn_number(pdev), where, valp) ! 172: #define pci_read_config_dword(pdev, where, valp)\ ! 173: pcibios_read_config_dword(bus_number(pdev), devfn_number(pdev), where, valp) ! 174: #define pci_write_config_byte(pdev, where, val)\ ! 175: pcibios_write_config_byte(bus_number(pdev), devfn_number(pdev), where, val) ! 176: #define pci_write_config_word(pdev, where, val)\ ! 177: pcibios_write_config_word(bus_number(pdev), devfn_number(pdev), where, val) ! 178: #define pci_write_config_dword(pdev, where, val)\ ! 179: pcibios_write_config_dword(bus_number(pdev), devfn_number(pdev), where, val) ! 180: #else ! 181: #define PCI_SUPPORT_VER2 ! 182: #define pci_bus_number(pci_dev) ((pci_dev)->bus->number) ! 183: #define pci_devfn(pci_dev) ((pci_dev)->devfn) ! 184: #endif ! 185: ! 186: /* The arg count changed, but function name did not. ! 187: We cover that bad choice by defining a new name. ! 188: */ ! 189: #if LINUX_VERSION_CODE < 0x20159 ! 190: #define dev_free_skb(skb) dev_kfree_skb(skb, FREE_WRITE) ! 191: #define dev_free_skb_irq(skb) dev_kfree_skb(skb, FREE_WRITE) ! 192: #elif LINUX_VERSION_CODE < 0x20400 ! 193: #define dev_free_skb(skb) dev_kfree_skb(skb) ! 194: #define dev_free_skb_irq(skb) dev_kfree_skb(skb) ! 195: #else ! 196: #define dev_free_skb(skb) dev_kfree_skb(skb) ! 197: #define dev_free_skb_irq(skb) dev_kfree_skb_irq(skb) ! 198: #endif ! 199: ! 200: /* Added at the suggestion of Jes Sorensen. */ ! 201: #if LINUX_VERSION_CODE > 0x20153 ! 202: #include <linux/init.h> ! 203: #else ! 204: #define __init ! 205: #define __initdata ! 206: #define __initfunc(__arginit) __arginit ! 207: #endif ! 208: ! 209: /* The old 'struct device' used a too-generic name. */ ! 210: #if LINUX_VERSION_CODE < 0x2030d ! 211: #define net_device device ! 212: #endif ! 213: ! 214: /* More changes for the 2.4 kernel, some in the zillion 2.3.99 releases. */ ! 215: #if LINUX_VERSION_CODE < 0x20363 ! 216: #define DECLARE_MUTEX(name) struct semaphore (name) = MUTEX; ! 217: #define down_write(semaphore_p) down(semaphore_p) ! 218: #define down_read(semaphore_p) down(semaphore_p) ! 219: #define up_write(semaphore_p) up(semaphore_p) ! 220: #define up_read(semaphore_p) up(semaphore_p) ! 221: /* Note that the kernel version has a broken time_before()! */ ! 222: #define time_after(a,b) ((long)(b) - (long)(a) < 0) ! 223: #define time_before(a,b) ((long)(a) - (long)(b) < 0) ! 224: #else ! 225: #define get_free_page get_zeroed_page ! 226: #endif ! 227: ! 228: /* The 2.2 kernels added the start of capability-based security for operations ! 229: that formerally could only be done by root. ! 230: */ ! 231: #if ! defined(CAP_NET_ADMIN) ! 232: #define capable(CAP_XXX) (suser()) ! 233: #endif ! 234: ! 235: #if ! defined(HAVE_NETIF_QUEUE) ! 236: #define netif_wake_queue(dev) do { clear_bit( 0, (void*)&(dev)->tbusy); mark_bh(NET_BH); } while (0) ! 237: #define netif_start_tx_queue(dev) do { (dev)->tbusy = 0; dev->start = 1; } while (0) ! 238: #define netif_stop_tx_queue(dev) do { (dev)->tbusy = 1; dev->start = 0; } while (0) ! 239: #define netif_queue_paused(dev) ((dev)->tbusy != 0) ! 240: /* Splitting these lines exposes a bug in some preprocessors. */ ! 241: #define netif_pause_tx_queue(dev) (test_and_set_bit( 0, (void*)&(dev)->tbusy)) ! 242: #define netif_unpause_tx_queue(dev) do { clear_bit( 0, (void*)&(dev)->tbusy); } while (0) ! 243: #define netif_resume_tx_queue(dev) do { clear_bit( 0, (void*)&(dev)->tbusy); mark_bh(NET_BH); } while (0) ! 244: ! 245: #define netif_running(dev) ((dev)->start != 0) ! 246: #define netif_device_attach(dev) do {; } while (0) ! 247: #define netif_device_detach(dev) do {; } while (0) ! 248: #define netif_device_present(dev) (1) ! 249: #define netif_set_tx_timeout(dev, func, deltajiffs) do {; } while (0) ! 250: #define netif_link_down(dev) (dev)->flags &= ~IFF_RUNNING ! 251: #define netif_link_up(dev) (dev)->flags |= IFF_RUNNING ! 252: ! 253: #else ! 254: ! 255: #define netif_start_tx_queue(dev) netif_start_queue(dev) ! 256: #define netif_stop_tx_queue(dev) netif_stop_queue(dev) ! 257: #define netif_queue_paused(dev) netif_queue_stopped(dev) ! 258: #define netif_resume_tx_queue(dev) netif_wake_queue(dev) ! 259: /* Only used in transmit path. No function in 2.4. */ ! 260: #define netif_pause_tx_queue(dev) 0 ! 261: #define netif_unpause_tx_queue(dev) do {; } while (0) ! 262: ! 263: #ifdef __LINK_STATE_NOCARRIER ! 264: #define netif_link_down(dev) netif_carrier_off(dev) ! 265: #define netif_link_up(dev) netif_carrier_on(dev) ! 266: #else ! 267: #define netif_link_down(dev) (dev)->flags &= ~IFF_RUNNING ! 268: #define netif_link_up(dev) (dev)->flags |= IFF_RUNNING ! 269: #endif ! 270: ! 271: #endif ! 272: #ifndef PCI_DMA_BUS_IS_PHYS ! 273: #define pci_dma_sync_single(pci_dev, base_addr, extent, tofrom) do {; } while (0) ! 274: #define pci_map_single(pci_dev, base_addr, extent, dir) virt_to_bus(base_addr) ! 275: #define pci_unmap_single(pci_dev, base_addr, extent, dir) do {; } while (0) ! 276: #endif ! 277: ! 278: #endif ! 279: /* ! 280: * Local variables: ! 281: * c-indent-level: 4 ! 282: * c-basic-offset: 4 ! 283: * tab-width: 4 ! 284: * End: ! 285: */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.