2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * Purpose: define kernel compatibility header
32 #include <linux/version.h>
50 #ifndef MODULE_LICENSE
51 #define MODULE_LICENSE(license)
54 #ifndef MOD_INC_USE_COUNT
55 #define MOD_INC_USE_COUNT do {} while (0)
58 #ifndef MOD_DEC_USE_COUNT
59 #define MOD_DEC_USE_COUNT do {} while (0)
62 #ifndef HAVE_NETDEV_PRIV
63 #define netdev_priv(dev) (dev->priv)
67 typedef void irqreturn_t;
70 #define IRQ_RETVAL(x) (int)x
77 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)
79 typedef unsigned long dma_addr_t;
80 typedef struct wait_queue *wait_queue_head_t;
81 #define init_waitqueue_head(x) *(x)=NULL
82 #define set_current_state(status) { current->state = (status); mb(); }
86 #define module_init(fn) int init_module (void) { return fn(); }
87 #define module_exit(fn) void cleanup_module(void) { return fn(); }
91 #define module_init(fn) int e100_probe (void) { return fn(); }
92 #define module_exit(fn) /* NOTHING */
96 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18) */
98 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
101 #include <linux/modversions.h>
104 #include <linux/types.h>
105 #include <linux/pci.h>
106 #include <linux/slab.h>
109 #define pci_resource_start(dev, bar) \
110 (((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_SPACE_IO) ? \
111 ((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_IO_MASK) : \
112 ((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_MEM_MASK))
114 static inline int pci_enable_device(struct pci_dev *dev)
119 #define __constant_cpu_to_le32 cpu_to_le32
120 #define __constant_cpu_to_le16 cpu_to_le16
122 #define PCI_DMA_TODEVICE 1
123 #define PCI_DMA_FROMDEVICE 2
125 extern inline void *pci_alloc_consistent (struct pci_dev *dev,
127 dma_addr_t *dma_handle) {
128 void *vaddr = kmalloc(size, GFP_ATOMIC);
130 *dma_handle = virt_to_bus(vaddr);
135 #define pci_dma_sync_single(dev,dma_handle,size,direction) do{} while(0)
136 #define pci_dma_supported(dev, addr_mask) (1)
137 #define pci_free_consistent(dev, size, cpu_addr, dma_handle) kfree(cpu_addr)
138 #define pci_map_single(dev, addr, size, direction) virt_to_bus(addr)
139 #define pci_unmap_single(dev, dma_handle, size, direction) do{} while(0)
142 #define spin_lock_bh spin_lock_irq
143 #define spin_unlock_bh spin_unlock_irq
144 #define del_timer_sync(timer) del_timer(timer)
145 #define net_device device
147 #define netif_start_queue(dev) ( clear_bit(0, &(dev)->tbusy))
148 #define netif_stop_queue(dev) ( set_bit(0, &(dev)->tbusy))
149 #define netif_wake_queue(dev) { clear_bit(0, &(dev)->tbusy); \
151 #define netif_running(dev) ( test_bit(0, &(dev)->start))
152 #define netif_queue_stopped(dev) ( test_bit(0, &(dev)->tbusy))
154 #define netif_device_attach(dev) \
155 do{ (dev)->start = 1; netif_start_queue(dev); } while (0)
156 #define netif_device_detach(dev) \
157 do{ (dev)->start = 0; netif_stop_queue(dev); } while (0)
159 #define dev_kfree_skb_irq(skb) dev_kfree_skb(skb)
161 #define netif_carrier_on(dev) do {} while (0)
162 #define netif_carrier_off(dev) do {} while (0)
165 #define PCI_ANY_ID (~0U)
167 struct pci_device_id {
168 unsigned int vendor, device;
169 unsigned int subvendor, subdevice;
170 unsigned int class, classmask;
171 unsigned long driver_data;
174 #define MODULE_DEVICE_TABLE(bus, dev_table)
175 #define PCI_MAX_NUM_NICS 256
179 struct pci_device_id *id_table;
180 int (*probe)(struct pci_dev *dev, const struct pci_device_id *id);
181 void (*remove)(struct pci_dev *dev);
182 void (*suspend)(struct pci_dev *dev);
183 void (*resume)(struct pci_dev *dev);
184 struct pci_dev *pcimap[PCI_MAX_NUM_NICS];
187 static inline int pci_module_init(struct pci_driver *drv)
189 struct pci_dev *pdev;
190 struct pci_device_id *pcid;
191 uint16_t subvendor, subdevice;
194 /* walk the global pci device list looking for matches */
195 for (pdev = pci_devices; pdev && (board_count < PCI_MAX_NUM_NICS); pdev = pdev->next) {
197 pcid = &drv->id_table[0];
198 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &subvendor);
199 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subdevice);
201 while (pcid->vendor != 0) {
202 if (((pcid->vendor == pdev->vendor) || (pcid->vendor == PCI_ANY_ID)) &&
203 ((pcid->device == pdev->device) || (pcid->device == PCI_ANY_ID)) &&
204 ((pcid->subvendor == subvendor) || (pcid->subvendor == PCI_ANY_ID)) &&
205 ((pcid->subdevice == subdevice) || (pcid->subdevice == PCI_ANY_ID))) {
207 if (drv->probe(pdev, pcid) == 0) {
208 drv->pcimap[board_count] = pdev;
217 if (board_count < PCI_MAX_NUM_NICS) {
218 drv->pcimap[board_count] = NULL;
221 return (board_count > 0) ? 0 : -ENODEV;
224 static inline void pci_unregister_driver(struct pci_driver *drv)
228 for (i = 0; i < PCI_MAX_NUM_NICS; i++) {
232 drv->remove(drv->pcimap[i]);
237 #define pci_set_drvdata(pcid, data)
239 #define pci_get_drvdata(pcid) ({ \
241 for (pInfo = pDevice_Infos; \
242 pInfo; pInfo = pInfo->next) { \
243 if (pInfo->pcid == pcid) \
248 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) */
250 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)
252 #define skb_linearize(skb, gfp_mask) ({ \
253 struct sk_buff *tmp_skb; \
255 skb = skb_copy(tmp_skb, gfp_mask); \
256 dev_kfree_skb_irq(tmp_skb); })
258 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */
260 #ifndef MODULE_LICESEN
261 #define MODULE_LICESEN(x)
264 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6)
266 #include <linux/types.h>
267 #include <linux/pci.h>
269 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,2)
270 static inline int pci_set_power_state(struct pci_dev* pcid, int state) { return 0; }
274 #define PM_ENABLE_BIT 0x0100
275 #define PM_CLEAR_BIT 0x8000
276 #define PM_STATE_MASK 0xFFFC
277 #define PM_STATE_D1 0x0001
280 pci_enable_wake(struct pci_dev *dev, u32 state, int enable)
284 pci_read_config_word(dev, PMCSR, &p_state);
285 pci_write_config_word(dev, PMCSR, p_state | PM_CLEAR_BIT);
288 p_state &= ~PM_ENABLE_BIT;
290 p_state |= PM_ENABLE_BIT;
292 p_state &= PM_STATE_MASK;
295 pci_write_config_word(dev, PMCSR, p_state);
299 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6) */