Commit | Line | Data |
---|---|---|
92b96797 FB |
1 | /* |
2 | * Copyright (c) 1996, 2003 VIA Networking, Inc. All rights reserved. | |
3 | * | |
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. | |
8 | * | |
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. | |
13 | * | |
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. | |
17 | * | |
18 | * | |
19 | * File: kcompat.h | |
20 | * | |
21 | * Purpose: define kernel compatibility header | |
22 | * | |
23 | * Author: Lyndon Chen | |
24 | * | |
25 | * Date: Apr 8, 2002 | |
26 | * | |
27 | */ | |
28 | #ifndef _KCOMPAT_H | |
29 | #define _KCOMPAT_H | |
30 | ||
31 | #include <linux/version.h> | |
32 | ||
33 | #ifndef __init | |
34 | #define __init | |
35 | #endif | |
36 | ||
37 | #ifndef __exit | |
38 | #define __exit | |
39 | #endif | |
40 | ||
41 | #ifndef __devexit | |
42 | #define __devexit | |
43 | #endif | |
44 | ||
45 | #ifndef __devinitdata | |
46 | #define __devinitdata | |
47 | #endif | |
48 | ||
49 | #ifndef MODULE_LICENSE | |
50 | #define MODULE_LICENSE(license) | |
51 | #endif | |
52 | ||
53 | #ifndef MOD_INC_USE_COUNT | |
54 | #define MOD_INC_USE_COUNT do {} while (0) | |
55 | #endif | |
56 | ||
57 | #ifndef MOD_DEC_USE_COUNT | |
58 | #define MOD_DEC_USE_COUNT do {} while (0) | |
59 | #endif | |
60 | ||
61 | #ifndef HAVE_NETDEV_PRIV | |
62 | #define netdev_priv(dev) (dev->priv) | |
63 | #endif | |
64 | ||
65 | #ifndef IRQ_RETVAL | |
66 | typedef void irqreturn_t; | |
67 | ||
68 | ||
69 | #define IRQ_RETVAL(x) | |
70 | ||
71 | #endif | |
72 | ||
73 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) | |
74 | ||
75 | #define vntwusb_submit_urb(val) usb_submit_urb(val, GFP_ATOMIC) | |
76 | #define vntwusb_alloc_urb(val) usb_alloc_urb(val, GFP_ATOMIC) | |
77 | #else | |
78 | #define vntwusb_alloc_urb(val) usb_alloc_urb(val) | |
79 | #define vntwusb_submit_urb(val) usb_submit_urb(val) | |
80 | ||
81 | #endif | |
82 | ||
83 | ||
84 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10) | |
85 | ||
86 | #define vntwusb_unlink_urb(val) usb_kill_urb(val) | |
87 | ||
88 | #else | |
89 | #define vntwusb_unlink_urb(val) usb_unlink_urb(val) | |
90 | ||
91 | #endif | |
92 | ||
93 | ||
94 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18) | |
95 | ||
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(); } | |
100 | ||
101 | #ifdef MODULE | |
102 | ||
103 | #define module_init(fn) int init_module (void) { return fn(); } | |
104 | #define module_exit(fn) void cleanup_module(void) { return fn(); } | |
105 | ||
106 | #else /* MODULE */ | |
107 | ||
108 | #define module_init(fn) int e100_probe (void) { return fn(); } | |
109 | #define module_exit(fn) /* NOTHING */ | |
110 | ||
111 | #endif /* MODULE */ | |
112 | ||
113 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18) */ | |
114 | ||
115 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) | |
116 | ||
117 | #ifdef MODVERSIONS | |
118 | #include <linux/modversions.h> | |
119 | #endif | |
120 | ||
121 | #include <linux/types.h> | |
122 | #include <linux/pci.h> | |
123 | #include <linux/slab.h> | |
124 | #include <asm/io.h> | |
125 | ||
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)) | |
130 | ||
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 | |
134 | ||
135 | #define PCI_DMA_TODEVICE 1 | |
136 | #define PCI_DMA_FROMDEVICE 2 | |
137 | ||
138 | extern inline void *pci_alloc_consistent (struct pci_dev *dev, | |
139 | size_t size, | |
140 | dma_addr_t *dma_handle) { | |
141 | void *vaddr = kmalloc(size, GFP_ATOMIC); | |
142 | if(vaddr != NULL) { | |
143 | *dma_handle = virt_to_bus(vaddr); | |
144 | } | |
145 | return vaddr; | |
146 | } | |
147 | ||
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) | |
153 | ||
154 | ||
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 | |
159 | ||
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); \ | |
163 | mark_bh(NET_BH); } | |
164 | #define netif_running(dev) ( test_bit(0, &(dev)->start)) | |
165 | #define netif_queue_stopped(dev) ( test_bit(0, &(dev)->tbusy)) | |
166 | ||
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) | |
171 | ||
172 | #define dev_kfree_skb_irq(skb) dev_kfree_skb(skb) | |
173 | ||
174 | #define netif_carrier_on(dev) do {} while (0) | |
175 | #define netif_carrier_off(dev) do {} while (0) | |
176 | ||
177 | ||
178 | #define PCI_ANY_ID (~0U) | |
179 | ||
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; | |
185 | }; | |
186 | ||
187 | #define MODULE_DEVICE_TABLE(bus, dev_table) | |
188 | #define PCI_MAX_NUM_NICS 256 | |
189 | ||
190 | struct pci_driver { | |
191 | char *name; | |
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]; | |
198 | }; | |
199 | ||
200 | static inline int pci_module_init(struct pci_driver *drv) | |
201 | { | |
202 | struct pci_dev *pdev; | |
203 | struct pci_device_id *pcid; | |
204 | uint16_t subvendor, subdevice; | |
205 | int board_count = 0; | |
206 | ||
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) { | |
209 | ||
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); | |
213 | ||
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))) { | |
219 | ||
220 | if (drv->probe(pdev, pcid) == 0) { | |
221 | drv->pcimap[board_count] = pdev; | |
222 | board_count++; | |
223 | } | |
224 | break; | |
225 | } | |
226 | pcid++; | |
227 | } | |
228 | } | |
229 | ||
230 | if (board_count < PCI_MAX_NUM_NICS) { | |
231 | drv->pcimap[board_count] = NULL; | |
232 | } | |
233 | ||
234 | return (board_count > 0) ? 0 : -ENODEV; | |
235 | } | |
236 | ||
237 | static inline void pci_unregister_driver(struct pci_driver *drv) | |
238 | { | |
239 | int i; | |
240 | ||
241 | for (i = 0; i < PCI_MAX_NUM_NICS; i++) { | |
242 | if (!drv->pcimap[i]) | |
243 | break; | |
244 | ||
245 | drv->remove(drv->pcimap[i]); | |
246 | } | |
247 | } | |
248 | ||
249 | ||
250 | #define pci_set_drvdata(pcid, data) | |
251 | ||
252 | #define pci_get_drvdata(pcid) ({ \ | |
253 | PSDevice pInfo; \ | |
254 | for (pInfo = pDevice_Infos; \ | |
255 | pInfo; pInfo = pInfo->next) { \ | |
256 | if (pInfo->pcid == pcid) \ | |
257 | break; \ | |
258 | } \ | |
259 | pInfo; }) | |
260 | ||
261 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) */ | |
262 | ||
263 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) | |
264 | ||
265 | #define skb_linearize(skb, gfp_mask) ({ \ | |
266 | struct sk_buff *tmp_skb; \ | |
267 | tmp_skb = skb; \ | |
268 | skb = skb_copy(tmp_skb, gfp_mask); \ | |
269 | dev_kfree_skb_irq(tmp_skb); }) | |
270 | ||
271 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */ | |
272 | ||
273 | #ifndef MODULE_LICESEN | |
274 | #define MODULE_LICESEN(x) | |
275 | #endif | |
276 | ||
277 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6) | |
278 | ||
279 | #include <linux/types.h> | |
280 | #include <linux/pci.h> | |
281 | ||
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; } | |
284 | #endif | |
285 | ||
286 | #define PMCSR 0xe0 | |
287 | #define PM_ENABLE_BIT 0x0100 | |
288 | #define PM_CLEAR_BIT 0x8000 | |
289 | #define PM_STATE_MASK 0xFFFC | |
290 | #define PM_STATE_D1 0x0001 | |
291 | ||
292 | static inline int | |
293 | pci_enable_wake(struct pci_dev *dev, u32 state, int enable) | |
294 | { | |
295 | u16 p_state; | |
296 | ||
297 | pci_read_config_word(dev, PMCSR, &p_state); | |
298 | pci_write_config_word(dev, PMCSR, p_state | PM_CLEAR_BIT); | |
299 | ||
300 | if (enable == 0) { | |
301 | p_state &= ~PM_ENABLE_BIT; | |
302 | } else { | |
303 | p_state |= PM_ENABLE_BIT; | |
304 | } | |
305 | p_state &= PM_STATE_MASK; | |
306 | p_state |= state; | |
307 | ||
308 | pci_write_config_word(dev, PMCSR, p_state); | |
309 | ||
310 | return 0; | |
311 | } | |
312 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6) */ | |
313 | ||
314 | #endif | |
315 |