summaryrefslogtreecommitdiff
path: root/drivers/staging/vt6656/kcompat.h
blob: 370483d36f1272ddf851d826529ed31ff4656aec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*
 * Copyright (c) 1996, 2003 VIA Networking, Inc. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *
 * File: kcompat.h
 *
 * Purpose: define kernel compatibility header
 *
 * Author: Lyndon Chen
 *
 * Date: Apr 8, 2002
 *
 */
#ifndef _KCOMPAT_H
#define _KCOMPAT_H

#include <linux/version.h>

#ifndef __init
#define __init
#endif

#ifndef __exit
#define __exit
#endif

#ifndef __devexit
#define __devexit
#endif

#ifndef __devinitdata
#define __devinitdata
#endif

#ifndef MODULE_LICENSE
#define MODULE_LICENSE(license)
#endif

#ifndef MOD_INC_USE_COUNT
#define MOD_INC_USE_COUNT do {} while (0)
#endif

#ifndef MOD_DEC_USE_COUNT
#define MOD_DEC_USE_COUNT do {} while (0)
#endif

#ifndef HAVE_NETDEV_PRIV
#define netdev_priv(dev) (dev->priv)
#endif

#ifndef IRQ_RETVAL
typedef void irqreturn_t;


#define IRQ_RETVAL(x)

#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)

#define vntwusb_submit_urb(val) usb_submit_urb(val, GFP_ATOMIC)
#define vntwusb_alloc_urb(val)  usb_alloc_urb(val, GFP_ATOMIC)
#else
#define vntwusb_alloc_urb(val)  usb_alloc_urb(val)
#define vntwusb_submit_urb(val) usb_submit_urb(val)

#endif


#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)

#define vntwusb_unlink_urb(val) usb_kill_urb(val)

#else
#define vntwusb_unlink_urb(val) usb_unlink_urb(val)

#endif


#if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)

typedef unsigned long dma_addr_t;
typedef struct wait_queue *wait_queue_head_t;
#define init_waitqueue_head(x)                  *(x)=NULL
#define set_current_state(status)       { current->state = (status); mb(); }

#ifdef MODULE

#define module_init(fn) int  init_module   (void) { return fn(); }
#define module_exit(fn) void cleanup_module(void) { return fn(); }

#else /* MODULE */

#define module_init(fn) int  e100_probe    (void) { return fn(); }
#define module_exit(fn)  /* NOTHING */

#endif /* MODULE */

#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18) */

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)

#ifdef MODVERSIONS
#include <linux/modversions.h>
#endif

#include <linux/types.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <asm/io.h>

#define pci_resource_start(dev, bar)                            \
    (((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_SPACE_IO) ? \
    ((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_IO_MASK) :   \
    ((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_MEM_MASK))

static inline int pci_enable_device(struct pci_dev *dev) { return 0; }
#define __constant_cpu_to_le32 cpu_to_le32
#define __constant_cpu_to_le16 cpu_to_le16

#define PCI_DMA_TODEVICE   1
#define PCI_DMA_FROMDEVICE 2

extern inline void *pci_alloc_consistent (struct pci_dev *dev,
                                          size_t size,
                                          dma_addr_t *dma_handle) {
    void *vaddr = kmalloc(size, GFP_ATOMIC);
    if(vaddr != NULL) {
        *dma_handle = virt_to_bus(vaddr);
    }
    return vaddr;
}

#define pci_dma_sync_single(dev,dma_handle,size,direction)   do{} while(0)
#define pci_dma_supported(dev, addr_mask)                    (1)
#define pci_free_consistent(dev, size, cpu_addr, dma_handle) kfree(cpu_addr)
#define pci_map_single(dev, addr, size, direction)           virt_to_bus(addr)
#define pci_unmap_single(dev, dma_handle, size, direction)   do{} while(0)


#define spin_lock_bh            spin_lock_irq
#define spin_unlock_bh          spin_unlock_irq
#define del_timer_sync(timer)   del_timer(timer)
#define net_device              device

#define netif_start_queue(dev)   ( clear_bit(0, &(dev)->tbusy))
#define netif_stop_queue(dev)    (   set_bit(0, &(dev)->tbusy))
#define netif_wake_queue(dev)    { clear_bit(0, &(dev)->tbusy); \
                                   mark_bh(NET_BH); }
#define netif_running(dev)       (  test_bit(0, &(dev)->start))
#define netif_queue_stopped(dev) (  test_bit(0, &(dev)->tbusy))

#define netif_device_attach(dev) \
    do{ (dev)->start = 1; netif_start_queue(dev); } while (0)
#define netif_device_detach(dev) \
    do{ (dev)->start = 0; netif_stop_queue(dev); } while (0)

#define dev_kfree_skb_irq(skb) dev_kfree_skb(skb)

#define netif_carrier_on(dev)  do {} while (0)
#define netif_carrier_off(dev) do {} while (0)


#define PCI_ANY_ID (~0U)

struct pci_device_id {
    unsigned int vendor, device;
    unsigned int subvendor, subdevice;
    unsigned int class, classmask;
    unsigned long driver_data;
};

#define MODULE_DEVICE_TABLE(bus, dev_table)
#define PCI_MAX_NUM_NICS 256

struct pci_driver {
    char *name;
    struct pci_device_id *id_table;
    int (*probe)(struct pci_dev *dev, const struct pci_device_id *id);
    void (*remove)(struct pci_dev *dev);
    void (*suspend)(struct pci_dev *dev);
    void (*resume)(struct pci_dev *dev);
    struct pci_dev *pcimap[PCI_MAX_NUM_NICS];
};

static inline int pci_module_init(struct pci_driver *drv)
{
    struct pci_dev *pdev;
    struct pci_device_id *pcid;
    uint16_t subvendor, subdevice;
    int board_count = 0;

    /* walk the global pci device list looking for matches */
    for (pdev = pci_devices; pdev && (board_count < PCI_MAX_NUM_NICS); pdev = pdev->next) {

        pcid = &drv->id_table[0];
        pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &subvendor);
        pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subdevice);

        while (pcid->vendor != 0) {
            if (((pcid->vendor == pdev->vendor) || (pcid->vendor == PCI_ANY_ID)) &&
                ((pcid->device == pdev->device) || (pcid->device == PCI_ANY_ID)) &&
                ((pcid->subvendor == subvendor) || (pcid->subvendor == PCI_ANY_ID)) &&
                ((pcid->subdevice == subdevice) || (pcid->subdevice == PCI_ANY_ID))) {

                if (drv->probe(pdev, pcid) == 0) {
                    drv->pcimap[board_count] = pdev;
                    board_count++;
                }
                break;
            }
            pcid++;
        }
    }

    if (board_count < PCI_MAX_NUM_NICS) {
        drv->pcimap[board_count] = NULL;
    }

    return (board_count > 0) ? 0 : -ENODEV;
}

static inline void pci_unregister_driver(struct pci_driver *drv)
{
    int i;

    for (i = 0; i < PCI_MAX_NUM_NICS; i++) {
        if (!drv->pcimap[i])
            break;

        drv->remove(drv->pcimap[i]);
    }
}


#define pci_set_drvdata(pcid, data)

#define pci_get_drvdata(pcid) ({                            \
    PSDevice pInfo;                                         \
    for (pInfo = pDevice_Infos;                             \
        pInfo; pInfo = pInfo->next) {                       \
        if (pInfo->pcid == pcid)                            \
            break;                                          \
    }                                                       \
    pInfo; })

#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) */

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)

#define skb_linearize(skb, gfp_mask) ({     \
    struct sk_buff *tmp_skb;                \
    tmp_skb = skb;                          \
    skb = skb_copy(tmp_skb, gfp_mask);      \
    dev_kfree_skb_irq(tmp_skb); })

#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */

#ifndef MODULE_LICESEN
#define MODULE_LICESEN(x)
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6)

#include <linux/types.h>
#include <linux/pci.h>

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,2)
static inline int pci_set_power_state(struct pci_dev* pcid, int state) { return 0; }
#endif

#define PMCSR       0xe0
#define PM_ENABLE_BIT   0x0100
#define PM_CLEAR_BIT    0x8000
#define PM_STATE_MASK   0xFFFC
#define PM_STATE_D1 0x0001

static inline int
pci_enable_wake(struct pci_dev *dev, u32 state, int enable)
{
    u16 p_state;

    pci_read_config_word(dev, PMCSR, &p_state);
    pci_write_config_word(dev, PMCSR, p_state | PM_CLEAR_BIT);

    if (enable == 0) {
        p_state &= ~PM_ENABLE_BIT;
    } else {
        p_state |= PM_ENABLE_BIT;
    }
    p_state &= PM_STATE_MASK;
    p_state |= state;

    pci_write_config_word(dev, PMCSR, p_state);

    return 0;
}
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6) */

#endif