2 * Copyright (c) 1996, 2003 VIA Networking, Inc. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose: define kernel compatibility header
31 #include <linux/version.h>
49 #ifndef MODULE_LICENSE
50 #define MODULE_LICENSE(license)
53 #ifndef MOD_INC_USE_COUNT
54 #define MOD_INC_USE_COUNT do {} while (0)
57 #ifndef MOD_DEC_USE_COUNT
58 #define MOD_DEC_USE_COUNT do {} while (0)
61 #ifndef HAVE_NETDEV_PRIV
62 #define netdev_priv(dev) (dev->priv)
66 typedef void irqreturn_t;
73 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
75 #define vntwusb_submit_urb(val) usb_submit_urb(val, GFP_ATOMIC)
76 #define vntwusb_alloc_urb(val) usb_alloc_urb(val, GFP_ATOMIC)
78 #define vntwusb_alloc_urb(val) usb_alloc_urb(val)
79 #define vntwusb_submit_urb(val) usb_submit_urb(val)
84 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
86 #define vntwusb_unlink_urb(val) usb_kill_urb(val)
89 #define vntwusb_unlink_urb(val) usb_unlink_urb(val)
94 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)
96 typedef unsigned long dma_addr_t;
97 typedef struct wait_queue *wait_queue_head_t;
98 #define init_waitqueue_head(x) *(x)=NULL
99 #define set_current_state(status) { current->state = (status); mb(); }
103 #define module_init(fn) int init_module (void) { return fn(); }
104 #define module_exit(fn) void cleanup_module(void) { return fn(); }
108 #define module_init(fn) int e100_probe (void) { return fn(); }
109 #define module_exit(fn) /* NOTHING */
113 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18) */
115 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
118 #include <linux/modversions.h>
121 #include <linux/types.h>
122 #include <linux/pci.h>
123 #include <linux/slab.h>
126 #define pci_resource_start(dev, bar) \
127 (((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_SPACE_IO) ? \
128 ((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_IO_MASK) : \
129 ((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_MEM_MASK))
131 static inline int pci_enable_device(struct pci_dev *dev) { return 0; }
132 #define __constant_cpu_to_le32 cpu_to_le32
133 #define __constant_cpu_to_le16 cpu_to_le16
135 #define PCI_DMA_TODEVICE 1
136 #define PCI_DMA_FROMDEVICE 2
138 extern inline void *pci_alloc_consistent (struct pci_dev *dev,
140 dma_addr_t *dma_handle) {
141 void *vaddr = kmalloc(size, GFP_ATOMIC);
143 *dma_handle = virt_to_bus(vaddr);
148 #define pci_dma_sync_single(dev,dma_handle,size,direction) do{} while(0)
149 #define pci_dma_supported(dev, addr_mask) (1)
150 #define pci_free_consistent(dev, size, cpu_addr, dma_handle) kfree(cpu_addr)
151 #define pci_map_single(dev, addr, size, direction) virt_to_bus(addr)
152 #define pci_unmap_single(dev, dma_handle, size, direction) do{} while(0)
155 #define spin_lock_bh spin_lock_irq
156 #define spin_unlock_bh spin_unlock_irq
157 #define del_timer_sync(timer) del_timer(timer)
158 #define net_device device
160 #define netif_start_queue(dev) ( clear_bit(0, &(dev)->tbusy))
161 #define netif_stop_queue(dev) ( set_bit(0, &(dev)->tbusy))
162 #define netif_wake_queue(dev) { clear_bit(0, &(dev)->tbusy); \
164 #define netif_running(dev) ( test_bit(0, &(dev)->start))
165 #define netif_queue_stopped(dev) ( test_bit(0, &(dev)->tbusy))
167 #define netif_device_attach(dev) \
168 do{ (dev)->start = 1; netif_start_queue(dev); } while (0)
169 #define netif_device_detach(dev) \
170 do{ (dev)->start = 0; netif_stop_queue(dev); } while (0)
172 #define dev_kfree_skb_irq(skb) dev_kfree_skb(skb)
174 #define netif_carrier_on(dev) do {} while (0)
175 #define netif_carrier_off(dev) do {} while (0)
178 #define PCI_ANY_ID (~0U)
180 struct pci_device_id {
181 unsigned int vendor, device;
182 unsigned int subvendor, subdevice;
183 unsigned int class, classmask;
184 unsigned long driver_data;
187 #define MODULE_DEVICE_TABLE(bus, dev_table)
188 #define PCI_MAX_NUM_NICS 256
192 struct pci_device_id *id_table;
193 int (*probe)(struct pci_dev *dev, const struct pci_device_id *id);
194 void (*remove)(struct pci_dev *dev);
195 void (*suspend)(struct pci_dev *dev);
196 void (*resume)(struct pci_dev *dev);
197 struct pci_dev *pcimap[PCI_MAX_NUM_NICS];
200 static inline int pci_module_init(struct pci_driver *drv)
202 struct pci_dev *pdev;
203 struct pci_device_id *pcid;
204 uint16_t subvendor, subdevice;
207 /* walk the global pci device list looking for matches */
208 for (pdev = pci_devices; pdev && (board_count < PCI_MAX_NUM_NICS); pdev = pdev->next) {
210 pcid = &drv->id_table[0];
211 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &subvendor);
212 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subdevice);
214 while (pcid->vendor != 0) {
215 if (((pcid->vendor == pdev->vendor) || (pcid->vendor == PCI_ANY_ID)) &&
216 ((pcid->device == pdev->device) || (pcid->device == PCI_ANY_ID)) &&
217 ((pcid->subvendor == subvendor) || (pcid->subvendor == PCI_ANY_ID)) &&
218 ((pcid->subdevice == subdevice) || (pcid->subdevice == PCI_ANY_ID))) {
220 if (drv->probe(pdev, pcid) == 0) {
221 drv->pcimap[board_count] = pdev;
230 if (board_count < PCI_MAX_NUM_NICS) {
231 drv->pcimap[board_count] = NULL;
234 return (board_count > 0) ? 0 : -ENODEV;
237 static inline void pci_unregister_driver(struct pci_driver *drv)
241 for (i = 0; i < PCI_MAX_NUM_NICS; i++) {
245 drv->remove(drv->pcimap[i]);
250 #define pci_set_drvdata(pcid, data)
252 #define pci_get_drvdata(pcid) ({ \
254 for (pInfo = pDevice_Infos; \
255 pInfo; pInfo = pInfo->next) { \
256 if (pInfo->pcid == pcid) \
261 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) */
263 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)
265 #define skb_linearize(skb, gfp_mask) ({ \
266 struct sk_buff *tmp_skb; \
268 skb = skb_copy(tmp_skb, gfp_mask); \
269 dev_kfree_skb_irq(tmp_skb); })
271 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */
273 #ifndef MODULE_LICESEN
274 #define MODULE_LICESEN(x)
277 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6)
279 #include <linux/types.h>
280 #include <linux/pci.h>
282 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,2)
283 static inline int pci_set_power_state(struct pci_dev* pcid, int state) { return 0; }
287 #define PM_ENABLE_BIT 0x0100
288 #define PM_CLEAR_BIT 0x8000
289 #define PM_STATE_MASK 0xFFFC
290 #define PM_STATE_D1 0x0001
293 pci_enable_wake(struct pci_dev *dev, u32 state, int enable)
297 pci_read_config_word(dev, PMCSR, &p_state);
298 pci_write_config_word(dev, PMCSR, p_state | PM_CLEAR_BIT);
301 p_state &= ~PM_ENABLE_BIT;
303 p_state |= PM_ENABLE_BIT;
305 p_state &= PM_STATE_MASK;
308 pci_write_config_word(dev, PMCSR, p_state);
312 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6) */