MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / drivers / net / ks8695 / ks8695_kcompat.h
blobe1ec5fd4d162f3c10eff0424cc2bf0a308c44d5f
1 /*****************************************************************************
2 *****************************************************************************
4 Copyright (c) 1999 - 2001, Intel Corporation
6 All rights reserved.
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
11 1. Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
18 3. Neither the name of Intel Corporation nor the names of its contributors
19 may be used to endorse or promote products derived from this software
20 without specific prior written permission.
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
23 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *****************************************************************************
34 *****************************************************************************/
36 /* Macros to make drivers compatible with 2.2, 2.4 Linux kernels
38 * In order to make a single network driver work with all 2.2, 2.4 kernels
39 * these compatibility macros can be used.
40 * They are backwards compatible implementations of the latest APIs.
41 * The idea is that these macros will let you use the newest driver with old
42 * kernels, but can be removed when working with the latest and greatest.
45 #ifndef __KS8695_LINUX_KERNEL_COMPAT_H
46 #define __KS8695_LINUX_KERNEL_COMPAT_H
48 #include <linux/version.h>
50 /* a good type to have */
51 /* in Linux a long is always the same length as a pointer */
52 typedef unsigned long int uintptr_t;
54 /*****************************************************************************
56 ** PCI Bus Changes
58 *****************************************************************************/
60 /* Accessing the BAR registers from the PCI device structure
61 * Changed from base_address[bar] to resource[bar].start in 2.3.13
62 * The pci_resource_start inline function was introduced in 2.3.43
64 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,3,13) )
65 #define pci_resource_start(dev, bar) \
66 (((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_SPACE_IO) ? \
67 ((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_IO_MASK) : \
68 ((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_MEM_MASK))
69 #elif ( LINUX_VERSION_CODE < KERNEL_VERSION(2,3,43) )
70 #define pci_resource_start(dev, bar) \
71 (((dev)->resource[(bar)] & PCI_BASE_ADDRESS_SPACE_IO) ? \
72 ((dev)->resource[(bar)] & PCI_BASE_ADDRESS_IO_MASK) : \
73 ((dev)->resource[(bar)] & PCI_BASE_ADDRESS_MEM_MASK))
74 #endif
76 /* Starting with 2.3.23 drivers are supposed to call pci_enable_device
77 * to make sure I/O and memory regions have been mapped and potentially
78 * bring the device out of a low power state
80 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,3,23) )
81 #define pci_enable_device(dev) (0)
82 #endif
84 /* Dynamic DMA mapping
85 * Instead of using virt_to_bus, bus mastering PCI drivers should use the DMA
86 * mapping API to get bus addresses. This lets some platforms use dynamic
87 * mapping to use PCI devices that do not support DAC in a 64-bit address space
89 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,3,41) )
90 #include <linux/types.h>
91 #include <linux/pci.h>
92 #include <linux/slab.h>
93 #include <asm/io.h>
95 #if (( LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18) ) || \
96 ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0) ) )
97 typedef unsigned long dma_addr_t;
98 #endif
100 #define PCI_DMA_TODEVICE 1
101 #define PCI_DMA_FROMDEVICE 2
103 extern inline void *pci_alloc_consistent (struct pci_dev *dev,
104 size_t size,
105 dma_addr_t *dma_handle) {
106 void *vaddr = kmalloc(size, GFP_KERNEL);
107 if(vaddr != NULL) {
108 *dma_handle = virt_to_phys(vaddr);
110 return vaddr;
113 extern inline int pci_dma_supported(struct pci_dev *hwdev, dma_addr_t mask)
114 { return 1; }
116 extern inline void pci_free_consistent(struct pci_dev *hwdev, size_t size,
117 void *cpu_addr, dma_addr_t dma_handle)
118 { kfree(cpu_addr); return; }
120 static inline dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr,
121 size_t size, int direction)
122 { return virt_to_phys(ptr); }
124 static inline void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
125 size_t size, int direction)
126 { return; }
127 /* Ug, this is ks8695 specific */
128 #define pci_resource_len(a,b) (128 * 1024)
130 static inline int request_mem_region(uintptr_t addr, ...) { return 1; }
131 static inline int release_mem_region(uintptr_t addr, ...) { return 0; }
132 #endif
135 /*****************************************************************************
137 ** Network Device API Changes
139 *****************************************************************************/
141 /* In 2.3.14 the device structure was renamed to net_device
143 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,3,14) )
144 #define net_device device
145 #endif
147 /* 'Softnet' network stack changes merged in 2.3.43
148 * these are 2.2 compatible defines for the new network interface API
149 * 2.3.47 added some more inline functions for softnet to remove explicit
150 * bit tests in drivers
152 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,3,43) )
153 #define netif_start_queue(dev) clear_bit (0, &(dev)->tbusy)
154 #define netif_stop_queue(dev) set_bit (0, &(dev)->tbusy)
155 #define netif_wake_queue(dev) { clear_bit(0, &(dev)->tbusy); \
156 mark_bh(NET_BH); }
157 #define netif_running(dev) test_bit(0, &(dev)->start)
158 #define netif_queue_stopped(dev) test_bit(0, &(dev)->tbusy)
159 #elif ( LINUX_VERSION_CODE < KERNEL_VERSION(2,3,47) )
160 #define netif_running(dev) test_bit(LINK_STATE_START, &(dev)->state)
161 #define netif_queue_stopped(dev) test_bit(LINK_STATE_XOFF, &(dev)->state)
162 #endif
164 /* Softnet changes also affected how SKBs are handled
165 * Special calls need to be made now while in an interrupt handler
167 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,3,43) )
168 #define dev_kfree_skb_irq(skb) dev_kfree_skb(skb)
169 #endif
171 /*****************************************************************************
173 ** General Module / Driver / Kernel API Changes
175 *****************************************************************************/
177 /* New module_init macro added in 2.3.13 - replaces init_module entry point
178 * If MODULE is defined, it expands to an init_module definition
179 * If the driver is staticly linked to the kernel, it creates the proper
180 * function pointer for the initialization routine to be called
181 * (no more Space.c)
182 * module_exit does the same thing for cleanup_module
184 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,3,13) )
185 #define module_init(fn) int init_module (void) { return fn(); }
186 #define module_exit(fn) void cleanup_module(void) { return fn(); }
187 #endif
189 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) )
190 #ifndef __KS8695_MAIN__
191 #define __NO_VERSION__
192 #endif
193 #endif
195 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,3,47) )
196 #define PCI_ANY_ID (~0U)
198 struct pci_device_id {
199 unsigned int vendor, device;
200 unsigned int subvendor, subdevice;
201 unsigned int class, classmask;
202 unsigned long driver_data;
205 #define MODULE_DEVICE_TABLE(bus, dev_table)
207 struct pci_driver {
208 char *name;
209 struct pci_device_id *id_table;
210 int (*probe)(struct pci_dev *dev, const struct pci_device_id *id);
211 void (*remove)(struct pci_dev *dev);
212 void (*suspend)(struct pci_dev *dev);
213 void (*resume)(struct pci_dev *dev);
214 /* track devices on Linux 2.2, used by module_init and unregister_driver */
215 /* not to be used by the driver directly */
216 /* assumes single function device with function #0 to simplify */
217 uint32_t pcimap[256];
220 static inline int pci_module_init(struct pci_driver *drv)
222 struct pci_dev *pdev;
223 struct pci_device_id *pciid;
224 uint16_t subvendor, subdevice;
225 int board_count = 0;
227 /* walk the global pci device list looking for matches */
228 for (pdev = pci_devices; pdev != NULL; pdev = pdev->next) {
229 pciid = &drv->id_table[0];
230 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &subvendor);
231 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subdevice);
233 while (pciid->vendor != 0) {
234 if(((pciid->vendor == pdev->vendor) ||
235 (pciid->vendor == PCI_ANY_ID)) &&
237 ((pciid->device == pdev->device) ||
238 (pciid->device == PCI_ANY_ID)) &&
240 ((pciid->subvendor == subvendor) ||
241 (pciid->subvendor == PCI_ANY_ID)) &&
243 ((pciid->subdevice == subdevice) ||
244 (pciid->subdevice == PCI_ANY_ID))) {
246 if(drv->probe(pdev, pciid) == 0) {
247 board_count++;
249 /* keep track of pci devices found */
250 set_bit((pdev->devfn >> 3),
251 &(drv->pcimap[pdev->bus->number]));
253 break;
255 pciid++;
259 return (board_count > 0) ? 0 : -ENODEV;
262 static inline void pci_unregister_driver(struct pci_driver *drv)
264 int i, bit;
265 struct pci_dev *pdev;
267 /* search the pci device bitmap and release them all */
268 for(i = 0; i < 256; i++) {
269 /* ffs = find first set bit */
270 for(bit = ffs(drv->pcimap[i]); bit > 0; bit = ffs(drv->pcimap[i])) {
271 bit--;
272 pdev = pci_find_slot(i, (bit << 3));
273 drv->remove(pdev);
274 clear_bit(bit, &drv->pcimap[i]);
278 #endif
280 /* Taslets */
282 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,3,43) )
284 #include <linux/interrupt.h>
285 #define tasklet_struct tq_struct
287 static inline void tasklet_init(struct tasklet_struct *t,
288 void (*func)(unsigned long), unsigned long data)
290 t->next = NULL;
291 t->sync = 0;
292 t->routine = (void *)(void *)func;
293 t->data = (void *)data;
296 static inline void tasklet_schedule(struct tasklet_struct *t)
298 queue_task(t, &tq_immediate);
299 mark_bh(IMMEDIATE_BH);
300 return;
303 static inline void tasklet_disable(struct tasklet_struct *t)
305 return;
308 static inline void tasklet_enable(struct tasklet_struct *t)
310 return;
313 #endif
315 #endif /* __KS8695_LINUX_KERNEL_COMPAT_H */