Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[deliverable/linux.git] / drivers / staging / brcm80211 / include / osl.h
1 /*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #ifndef _osl_h_
18 #define _osl_h_
19
20 /* osl handle type forward declaration */
21 struct osl_info {
22 uint pktalloced; /* Number of allocated packet buffers */
23 bool mmbus; /* Bus supports memory-mapped registers */
24 uint magic;
25 void *pdev;
26 uint bustype;
27 };
28
29 typedef struct osl_dmainfo osldma_t;
30
31
32 extern struct osl_info *osl_attach(void *pdev, uint bustype);
33 extern void osl_detach(struct osl_info *osh);
34
35 extern u32 g_assert_type;
36
37 #if defined(BCMDBG_ASSERT)
38 #define ASSERT(exp) \
39 do { if (!(exp)) osl_assert(#exp, __FILE__, __LINE__); } while (0)
40 extern void osl_assert(char *exp, char *file, int line);
41 #else
42 #define ASSERT(exp) do {} while (0)
43 #endif /* defined(BCMDBG_ASSERT) */
44
45 /* PCI device bus # and slot # */
46 #define OSL_PCI_BUS(osh) osl_pci_bus(osh)
47 #define OSL_PCI_SLOT(osh) osl_pci_slot(osh)
48 extern uint osl_pci_bus(struct osl_info *osh);
49 extern uint osl_pci_slot(struct osl_info *osh);
50
51 #define BUS_SWAP32(v) (v)
52
53 extern void *osl_dma_alloc_consistent(struct osl_info *osh, uint size,
54 u16 align, uint *tot, unsigned long *pap);
55
56 #ifdef BRCM_FULLMAC
57 #define DMA_ALLOC_CONSISTENT(osh, size, pap, dmah, alignbits) \
58 osl_dma_alloc_consistent((osh), (size), (0), (tot), (pap))
59 #else
60 #define DMA_ALLOC_CONSISTENT(osh, size, align, tot, pap, dmah) \
61 osl_dma_alloc_consistent((osh), (size), (align), (tot), (pap))
62 #endif /* BRCM_FULLMAC */
63
64 #define DMA_FREE_CONSISTENT(osh, va, size, pa, dmah) \
65 osl_dma_free_consistent((osh), (void *)(va), (size), (pa))
66 extern void osl_dma_free_consistent(struct osl_info *osh, void *va,
67 uint size, unsigned long pa);
68
69 /* map/unmap direction */
70 #define DMA_TX 1 /* TX direction for DMA */
71 #define DMA_RX 2 /* RX direction for DMA */
72
73 /* map/unmap shared (dma-able) memory */
74 #define DMA_MAP(osh, va, size, direction, p, dmah) \
75 osl_dma_map((osh), (va), (size), (direction))
76 #define DMA_UNMAP(osh, pa, size, direction, p, dmah) \
77 osl_dma_unmap((osh), (pa), (size), (direction))
78 extern uint osl_dma_map(struct osl_info *osh, void *va, uint size,
79 int direction);
80 extern void osl_dma_unmap(struct osl_info *osh, uint pa, uint size,
81 int direction);
82
83 /* register access macros */
84 #if defined(BCMSDIO)
85 #ifdef BRCM_FULLMAC
86 #include <bcmsdh.h>
87 #endif
88 #define OSL_WRITE_REG(osh, r, v) \
89 (bcmsdh_reg_write(NULL, (unsigned long)(r), sizeof(*(r)), (v)))
90 #define OSL_READ_REG(osh, r) \
91 (bcmsdh_reg_read(NULL, (unsigned long)(r), sizeof(*(r))))
92 #endif
93
94 #if defined(BCMSDIO)
95 #define SELECT_BUS_WRITE(osh, mmap_op, bus_op) \
96 if ((osh)->mmbus) \
97 mmap_op else bus_op
98 #define SELECT_BUS_READ(osh, mmap_op, bus_op) \
99 ((osh)->mmbus) ? mmap_op : bus_op
100 #else
101 #define SELECT_BUS_WRITE(osh, mmap_op, bus_op) mmap_op
102 #define SELECT_BUS_READ(osh, mmap_op, bus_op) mmap_op
103 #endif
104
105 /* the largest reasonable packet buffer driver uses for ethernet MTU in bytes */
106 #define PKTBUFSZ 2048
107
108 #define OSL_SYSUPTIME() ((u32)jiffies * (1000 / HZ))
109 #define printf(fmt, args...) printk(fmt , ## args)
110 #ifdef BRCM_FULLMAC
111 #include <linux/kernel.h> /* for vsn/printf's */
112 #include <linux/string.h> /* for mem*, str* */
113 #endif
114 /* bcopy's: Linux kernel doesn't provide these (anymore) */
115 #define bcopy(src, dst, len) memcpy((dst), (src), (len))
116
117 /* register access macros */
118 #ifndef IL_BIGENDIAN
119 #ifndef __mips__
120 #define R_REG(osh, r) (\
121 SELECT_BUS_READ(osh, sizeof(*(r)) == sizeof(u8) ? \
122 readb((volatile u8*)(r)) : \
123 sizeof(*(r)) == sizeof(u16) ? readw((volatile u16*)(r)) : \
124 readl((volatile u32*)(r)), OSL_READ_REG(osh, r)) \
125 )
126 #else /* __mips__ */
127 #define R_REG(osh, r) (\
128 SELECT_BUS_READ(osh, \
129 ({ \
130 __typeof(*(r)) __osl_v; \
131 __asm__ __volatile__("sync"); \
132 switch (sizeof(*(r))) { \
133 case sizeof(u8): \
134 __osl_v = readb((volatile u8*)(r)); \
135 break; \
136 case sizeof(u16): \
137 __osl_v = readw((volatile u16*)(r)); \
138 break; \
139 case sizeof(u32): \
140 __osl_v = \
141 readl((volatile u32*)(r)); \
142 break; \
143 } \
144 __asm__ __volatile__("sync"); \
145 __osl_v; \
146 }), \
147 ({ \
148 __typeof(*(r)) __osl_v; \
149 __asm__ __volatile__("sync"); \
150 __osl_v = OSL_READ_REG(osh, r); \
151 __asm__ __volatile__("sync"); \
152 __osl_v; \
153 })) \
154 )
155 #endif /* __mips__ */
156
157 #define W_REG(osh, r, v) do { \
158 SELECT_BUS_WRITE(osh, \
159 switch (sizeof(*(r))) { \
160 case sizeof(u8): \
161 writeb((u8)(v), (volatile u8*)(r)); break; \
162 case sizeof(u16): \
163 writew((u16)(v), (volatile u16*)(r)); break; \
164 case sizeof(u32): \
165 writel((u32)(v), (volatile u32*)(r)); break; \
166 }, \
167 (OSL_WRITE_REG(osh, r, v))); \
168 } while (0)
169 #else /* IL_BIGENDIAN */
170 #define R_REG(osh, r) (\
171 SELECT_BUS_READ(osh, \
172 ({ \
173 __typeof(*(r)) __osl_v; \
174 switch (sizeof(*(r))) { \
175 case sizeof(u8): \
176 __osl_v = \
177 readb((volatile u8*)((r)^3)); \
178 break; \
179 case sizeof(u16): \
180 __osl_v = \
181 readw((volatile u16*)((r)^2)); \
182 break; \
183 case sizeof(u32): \
184 __osl_v = readl((volatile u32*)(r)); \
185 break; \
186 } \
187 __osl_v; \
188 }), \
189 OSL_READ_REG(osh, r)) \
190 )
191 #define W_REG(osh, r, v) do { \
192 SELECT_BUS_WRITE(osh, \
193 switch (sizeof(*(r))) { \
194 case sizeof(u8): \
195 writeb((u8)(v), \
196 (volatile u8*)((r)^3)); break; \
197 case sizeof(u16): \
198 writew((u16)(v), \
199 (volatile u16*)((r)^2)); break; \
200 case sizeof(u32): \
201 writel((u32)(v), \
202 (volatile u32*)(r)); break; \
203 }, \
204 (OSL_WRITE_REG(osh, r, v))); \
205 } while (0)
206 #endif /* IL_BIGENDIAN */
207
208 #define bcopy(src, dst, len) memcpy((dst), (src), (len))
209
210 /* packet primitives */
211 extern struct sk_buff *pkt_buf_get_skb(struct osl_info *osh, uint len);
212 extern void pkt_buf_free_skb(struct osl_info *osh, struct sk_buff *skb, bool send);
213
214 #endif /* _osl_h_ */
This page took 0.036386 seconds and 6 git commands to generate.