]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/staging/slicoss/slic_os.h
Staging: add Alacritech slicoss network driver
[linux-2.6-omap-h63xx.git] / drivers / staging / slicoss / slic_os.h
1 /**************************************************************************
2  *
3  * Copyright (c)2000-2002 Alacritech, Inc.  All rights reserved.
4  *
5  * $Id: slic_os.h,v 1.2 2006/03/27 15:10:15 mook Exp $
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above
14  *    copyright notice, this list of conditions and the following
15  *    disclaimer in the documentation and/or other materials provided
16  *    with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY ALACRITECH, INC. ``AS IS'' AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ALACRITECH, INC. OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  * The views and conclusions contained in the software and documentation
32  * are those of the authors and should not be interpreted as representing
33  * official policies, either expressed or implied, of Alacritech, Inc.
34  *
35  **************************************************************************/
36
37 /*
38  * FILENAME: slic_os.h
39  *
40  * These are the Linux-specific definitions required for the SLICOSS
41  * driver, which should allow for greater portability to other OSes.
42  */
43 #ifndef _SLIC_OS_SPECIFIC_H_
44 #define _SLIC_OS_SPECIFIC_H_
45
46 typedef unsigned char       uchar;
47 typedef u64               ulong64;
48 typedef char              *pchar;
49 typedef unsigned char     *puchar;
50 typedef u16             *pushort;
51 typedef u32               ulong32;
52 typedef u32             *pulong32;
53 typedef int               *plong32;
54 typedef unsigned int      *puint;
55 typedef void                *pvoid;
56 typedef unsigned long      *pulong;
57 typedef unsigned int        boolean;
58 typedef unsigned int        wchar;
59 typedef unsigned int       *pwchar;
60 typedef unsigned char       UCHAR;
61 typedef u32               ULONG;
62 typedef s32               LONG;
63 #define FALSE               (0)
64 #define TRUE                (1)
65
66 #define SLIC_INIT_SPINLOCK(x)                                                 \
67       {                                                                       \
68         spin_lock_init(&((x).lock));                                         \
69       }
70 #define SLIC_ACQUIRE_SPINLOCK(x)                                              \
71       {                                                                       \
72         spin_lock(&((x).lock));                                              \
73       }
74
75 #define SLIC_RELEASE_SPINLOCK(x)                                              \
76       {                                                                       \
77         spin_unlock(&((x).lock));                                            \
78       }
79
80 #define SLIC_ACQUIRE_IRQ_SPINLOCK(x)                                          \
81       {                                                                       \
82         spin_lock_irqsave(&((x).lock), (x).flags);                           \
83       }
84
85 #define SLIC_RELEASE_IRQ_SPINLOCK(x)                                          \
86       {                                                                       \
87         spin_unlock_irqrestore(&((x).lock), (x).flags);                      \
88       }
89
90 #define ATK_DEBUG  1
91
92 #if ATK_DEBUG
93 #define SLIC_TIMESTAMP(value) {                                             \
94         struct timeval  timev;                                              \
95         do_gettimeofday(&timev);                                            \
96         value = timev.tv_sec*1000000 + timev.tv_usec;                       \
97 }
98 #else
99 #define SLIC_TIMESTAMP(value)
100 #endif
101
102 #define SLIC_ALLOCATE_MEM(len, flag)         kmalloc(len, flag)
103 #define SLIC_DEALLOCATE_MEM(mem)             kfree(mem)
104 #define SLIC_DEALLOCATE_IRQ_MEM(mem)         free(mem)
105 #define SLIC_ALLOCATE_PAGE(x)                (pulong32)get_free_page(GFP_KERNEL)
106 #define SLIC_DEALLOCATE_PAGE(addr)           free_page((ulong32)addr)
107 #define SLIC_ALLOCATE_PCIMEM(a, sz, physp)    \
108                 pci_alloc_consistent((a)->pcidev, (sz), &(physp))
109 #define SLIC_DEALLOCATE_PCIMEM(a, sz, vp, pp) \
110                 pci_free_consistent((a)->pcidev, (sz), (vp), (pp))
111 #define SLIC_GET_PHYSICAL_ADDRESS(addr)       virt_to_bus((addr))
112 #define SLIC_GET_PHYSICAL_ADDRESS_HIGH(addr)  0
113
114 #define SLIC_GET_DMA_ADDRESS_WRITE(a, ptr, sz)  \
115                 pci_map_single((a)->pcidev, (ptr), (sz), PCI_DMA_TODEVICE)
116 #define SLIC_GET_DMA_ADDRESS_READ(a, ptr, sz)   \
117                 pci_map_single((a)->pcidev, (ptr), (sz), PCI_DMA_FROMDEVICE)
118 #define SLIC_UNGET_DMA_ADDRESS_WRITE(a, pa, sz) \
119                 pci_unmap_single((a)->pcidev, (pa), (sz), PCI_DMA_TODEVICE)
120 #define SLIC_UNGET_DMA_ADDRESS_READ(a, pa, sz)  \
121                 pci_unmap_single((a)->pcidev, (pa), (sz), PCI_DMA_FROMDEVICE)
122
123 #define SLIC_ZERO_MEMORY(p, sz)            memset((p), 0, (sz))
124 #define SLIC_EQUAL_MEMORY(src1, src2, len) (!memcmp(src1, src2, len))
125 #define SLIC_MOVE_MEMORY(dst, src, len)    memcpy((dst), (src), (len))
126
127 #define SLIC_SECS_TO_JIFFS(x)  ((x) * HZ)
128 #define SLIC_MS_TO_JIFFIES(x)  (SLIC_SECS_TO_JIFFS((x)) / 1000)
129
130 #ifdef DEBUG_REGISTER_TRACE
131 #define WRITE_REG(reg, value, flush)                                      \
132         {                                                           \
133                 adapter->card->reg_type[adapter->card->debug_ix] = 0;   \
134                 adapter->card->reg_offset[adapter->card->debug_ix] = \
135                         ((puchar)(&reg)) - ((puchar)adapter->slic_regs); \
136                 adapter->card->reg_value[adapter->card->debug_ix++] = value;  \
137                 if (adapter->card->debug_ix == 32) \
138                         adapter->card->debug_ix = 0;                      \
139                 slic_reg32_write((&reg), (value), (flush));            \
140         }
141 #define WRITE_REG64(a, reg, value, regh, valh, flush)                        \
142         {                                                           \
143                 adapter->card->reg_type[adapter->card->debug_ix] = 1;        \
144                 adapter->card->reg_offset[adapter->card->debug_ix] = \
145                         ((puchar)(&reg)) - ((puchar)adapter->slic_regs); \
146                 adapter->card->reg_value[adapter->card->debug_ix] = value;   \
147                 adapter->card->reg_valueh[adapter->card->debug_ix++] = valh;  \
148                 if (adapter->card->debug_ix == 32) \
149                         adapter->card->debug_ix = 0;                      \
150                 slic_reg64_write((a), (&reg), (value), (&regh), (valh), \
151                                 (flush));\
152         }
153 #else
154 #define WRITE_REG(reg, value, flush) \
155         slic_reg32_write((&reg), (value), (flush))
156 #define WRITE_REG64(a, reg, value, regh, valh, flush) \
157         slic_reg64_write((a), (&reg), (value), (&regh), (valh), (flush))
158 #endif
159 #define READ_REG(reg, flush)                    slic_reg32_read((&reg), (flush))
160 #define READ_REGP16(reg, flush)                 slic_reg16_read((&reg), (flush))
161
162 #endif  /* _SLIC_OS_SPECIFIC_H_  */
163