[iw] Update iw to version 0.9.13.
[openwrt.git] / package / broadcom-wl / src / driver / linux_osl.h
1 /*
2 * Linux OS Independent Layer
3 *
4 * Copyright 2007, Broadcom Corporation
5 * All Rights Reserved.
6 *
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
11 *
12 */
13
14 #ifndef _linux_osl_h_
15 #define _linux_osl_h_
16
17 #include <typedefs.h>
18 #include <linuxver.h>
19 #include <osl.h>
20
21 #define OSL_PKTTAG_SZ 32 /* Size of PktTag */
22
23 /* microsecond delay */
24 extern void osl_delay(uint usec);
25
26 /* OSL initialization */
27 extern osl_t *osl_attach(void *pdev, uint bustype, bool pkttag);
28 extern void osl_detach(osl_t *osh);
29
30 #define PKTFREESETCB(osh, _tx_fn, _tx_ctx) \
31 do { \
32 ((osl_pubinfo_t*)osh)->tx_fn = _tx_fn; \
33 ((osl_pubinfo_t*)osh)->tx_ctx = _tx_ctx; \
34 } while (0)
35
36 /* host/bus architecture-specific byte swap */
37 #define BUS_SWAP32(v) (v)
38
39
40 #define MALLOC_FAILED(osh) osl_malloc_failed((osh))
41
42 extern void *osl_malloc(osl_t *osh, uint size);
43 extern void osl_mfree(osl_t *osh, void *addr, uint size);
44 extern uint osl_malloced(osl_t *osh);
45 extern uint osl_malloc_failed(osl_t *osh);
46
47 /* allocate/free shared (dma-able) consistent memory */
48 #define DMA_CONSISTENT_ALIGN PAGE_SIZE
49 #define DMA_ALLOC_CONSISTENT(osh, size, pap, dmah) \
50 osl_dma_alloc_consistent((osh), (size), (pap))
51 #define DMA_FREE_CONSISTENT(osh, va, size, pa, dmah) \
52 osl_dma_free_consistent((osh), (void*)(va), (size), (pa))
53 extern void *osl_dma_alloc_consistent(osl_t *osh, uint size, ulong *pap);
54 extern void osl_dma_free_consistent(osl_t *osh, void *va, uint size, ulong pa);
55
56 /* map/unmap direction */
57 #define DMA_TX 1 /* TX direction for DMA */
58 #define DMA_RX 2 /* RX direction for DMA */
59
60 /* map/unmap shared (dma-able) memory */
61 #define DMA_MAP(osh, va, size, direction, p, dmah) \
62 osl_dma_map((osh), (va), (size), (direction))
63 #define DMA_UNMAP(osh, pa, size, direction, p, dmah) \
64 osl_dma_unmap((osh), (pa), (size), (direction))
65 extern uint osl_dma_map(osl_t *osh, void *va, uint size, int direction);
66 extern void osl_dma_unmap(osl_t *osh, uint pa, uint size, int direction);
67
68 /* API for DMA addressing capability */
69 #define OSL_DMADDRWIDTH(osh, addrwidth) do {} while (0)
70
71 /* register access macros */
72 #if defined(BCMJTAG)
73 #include <bcmjtag.h>
74 #define OSL_WRITE_REG(osh, r, v) (bcmjtag_write(NULL, (uintptr)(r), (v), sizeof(*(r))))
75 #define OSL_READ_REG(osh, r) (bcmjtag_read(NULL, (uintptr)(r), sizeof(*(r))))
76 #endif
77
78 #if defined(BCMJTAG)
79 #define SELECT_BUS_WRITE(osh, mmap_op, bus_op) if (((osl_pubinfo_t*)(osh))->mmbus) \
80 mmap_op else bus_op
81 #define SELECT_BUS_READ(osh, mmap_op, bus_op) (((osl_pubinfo_t*)(osh))->mmbus) ? \
82 mmap_op : bus_op
83 #else
84 #define SELECT_BUS_WRITE(osh, mmap_op, bus_op) mmap_op
85 #define SELECT_BUS_READ(osh, mmap_op, bus_op) mmap_op
86 #endif
87
88 /*
89 * BINOSL selects the slightly slower function-call-based binary compatible osl.
90 * Macros expand to calls to functions defined in linux_osl.c .
91 */
92 #ifndef BINOSL
93
94 /* string library, kernel mode */
95 #ifndef printf
96 #define printf(fmt, args...) printk(fmt, ## args)
97 #endif /* printf */
98 #include <linux/kernel.h>
99 #include <linux/string.h>
100
101 /* register access macros */
102 #define AND_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) & (v))
103 #define OR_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) | (v))
104
105 /* bcopy, bcmp, and bzero */
106 #define bcopy(src, dst, len) memcpy((dst), (src), (len))
107 #define bcmp(b1, b2, len) memcmp((b1), (b2), (len))
108 #define bzero(b, len) memset((b), '\0', (len))
109
110 /* uncached virtual address */
111 #ifdef mips
112 #define OSL_UNCACHED(va) KSEG1ADDR((va))
113 #include <asm/addrspace.h>
114 #else
115 #define OSL_UNCACHED(va) (va)
116 #endif /* mips */
117
118 /* get processor cycle count */
119 #if defined(mips)
120 #define OSL_GETCYCLES(x) ((x) = read_c0_count() * 2)
121 #elif defined(__i386__)
122 #define OSL_GETCYCLES(x) rdtscl((x))
123 #else
124 #define OSL_GETCYCLES(x) ((x) = 0)
125 #endif /* defined(mips) */
126
127 /* dereference an address that may cause a bus exception */
128 #ifdef mips
129 #if defined(MODULE) && (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 17))
130 #define BUSPROBE(val, addr) panic("get_dbe() will not fixup a bus exception when compiled into"\
131 " a module")
132 #else
133 #define BUSPROBE(val, addr) get_dbe((val), (addr))
134 #include <asm/paccess.h>
135 #endif /* defined(MODULE) && (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 17)) */
136 #else
137 #define BUSPROBE(val, addr) ({ (val) = R_REG(NULL, (addr)); 0; })
138 #endif /* mips */
139
140 /* map/unmap physical to virtual I/O */
141 #define REG_MAP(pa, size) ioremap_nocache((unsigned long)(pa), (unsigned long)(size))
142 #define REG_UNMAP(va) iounmap((void *)(va))
143
144 /* shared (dma-able) memory access macros */
145 #define R_SM(r) *(r)
146 #define W_SM(r, v) (*(r) = (v))
147 #define BZERO_SM(r, len) memset((r), '\0', (len))
148
149 /* packet primitives */
150 #define PKTGET(osh, len, send) osl_pktget((osh), (len))
151 #define PKTFREE(osh, skb, send) osl_pktfree((osh), (skb), (send))
152 #define PKTDATA(osh, skb) (((struct sk_buff*)(skb))->data)
153 #define PKTLEN(osh, skb) (((struct sk_buff*)(skb))->len)
154 #define PKTHEADROOM(osh, skb) (PKTDATA(osh, skb)-(((struct sk_buff*)(skb))->head))
155 #define PKTTAILROOM(osh, skb) ((((struct sk_buff*)(skb))->end)-(((struct sk_buff*)(skb))->tail))
156 #define PKTNEXT(osh, skb) (((struct sk_buff*)(skb))->next)
157 #define PKTSETNEXT(osh, skb, x) (((struct sk_buff*)(skb))->next = (struct sk_buff*)(x))
158 #define PKTSETLEN(osh, skb, len) __skb_trim((struct sk_buff*)(skb), (len))
159 #define PKTPUSH(osh, skb, bytes) skb_push((struct sk_buff*)(skb), (bytes))
160 #define PKTPULL(osh, skb, bytes) skb_pull((struct sk_buff*)(skb), (bytes))
161 #define PKTDUP(osh, skb) osl_pktdup((osh), (skb))
162 #define PKTTAG(skb) ((void*)(((struct sk_buff*)(skb))->cb))
163 #define PKTALLOCED(osh) ((osl_pubinfo_t *)(osh))->pktalloced
164 #ifdef BCMDBG_PKT /* pkt logging for debugging */
165 #define PKTLIST_DUMP(osh, buf) osl_pktlist_dump(osh, buf)
166 #else /* BCMDBG_PKT */
167 #define PKTLIST_DUMP(osh, buf)
168 #endif /* BCMDBG_PKT */
169
170 #ifdef BCMDBG_PKT /* pkt logging for debugging */
171 extern void osl_pktlist_add(osl_t *osh, void *p);
172 extern void osl_pktlist_remove(osl_t *osh, void *p);
173 extern char *osl_pktlist_dump(osl_t *osh, char *buf);
174 #endif /* BCMDBG_PKT */
175
176 /* Convert a native(OS) packet to driver packet.
177 * In the process, native packet is destroyed, there is no copying
178 * Also, a packettag is zeroed out
179 */
180 static INLINE void *
181 osl_pkt_frmnative(osl_pubinfo_t *osh, struct sk_buff *skb)
182 {
183 struct sk_buff *nskb;
184
185 if (osh->pkttag)
186 bzero((void*)skb->cb, OSL_PKTTAG_SZ);
187
188 /* Increment the packet counter */
189 for (nskb = skb; nskb; nskb = nskb->next) {
190 #ifdef BCMDBG_PKT
191 osl_pktlist_add((osl_t *)osh, (void *) nskb);
192 #endif /* BCMDBG_PKT */
193 osh->pktalloced++;
194 }
195
196 return (void *)skb;
197 }
198 #define PKTFRMNATIVE(osh, skb) osl_pkt_frmnative(((osl_pubinfo_t *)osh), (struct sk_buff*)(skb))
199
200 /* Convert a driver packet to native(OS) packet
201 * In the process, packettag is zeroed out before sending up
202 * IP code depends on skb->cb to be setup correctly with various options
203 * In our case, that means it should be 0
204 */
205 static INLINE struct sk_buff *
206 osl_pkt_tonative(osl_pubinfo_t *osh, void *pkt)
207 {
208 struct sk_buff *nskb;
209
210 if (osh->pkttag)
211 bzero(((struct sk_buff*)pkt)->cb, OSL_PKTTAG_SZ);
212
213 /* Decrement the packet counter */
214 for (nskb = (struct sk_buff *)pkt; nskb; nskb = nskb->next) {
215 #ifdef BCMDBG_PKT
216 osl_pktlist_remove((osl_t *)osh, (void *) nskb);
217 #endif /* BCMDBG_PKT */
218 osh->pktalloced--;
219 }
220
221 return (struct sk_buff *)pkt;
222 }
223 #define PKTTONATIVE(osh, pkt) osl_pkt_tonative((osl_pubinfo_t *)(osh), (pkt))
224
225 #define PKTLINK(skb) (((struct sk_buff*)(skb))->prev)
226 #define PKTSETLINK(skb, x) (((struct sk_buff*)(skb))->prev = (struct sk_buff*)(x))
227 #define PKTPRIO(skb) (((struct sk_buff*)(skb))->priority)
228 #define PKTSETPRIO(skb, x) (((struct sk_buff*)(skb))->priority = (x))
229 #define PKTSUMNEEDED(skb) (((struct sk_buff*)(skb))->ip_summed == CHECKSUM_HW)
230 #define PKTSETSUMGOOD(skb, x) (((struct sk_buff*)(skb))->ip_summed = \
231 ((x) ? CHECKSUM_UNNECESSARY : CHECKSUM_NONE))
232 /* PKTSETSUMNEEDED and PKTSUMGOOD are not possible because skb->ip_summed is overloaded */
233 #define PKTSHARED(skb) (((struct sk_buff*)(skb))->cloned)
234
235 extern void *osl_pktget(osl_t *osh, uint len);
236 extern void osl_pktfree(osl_t *osh, void *skb, bool send);
237 extern void *osl_pktdup(osl_t *osh, void *skb);
238 #else /* BINOSL */
239
240 /* string library */
241 #ifndef LINUX_OSL
242 #undef printf
243 #define printf(fmt, args...) osl_printf((fmt), ## args)
244 #undef sprintf
245 #define sprintf(buf, fmt, args...) osl_sprintf((buf), (fmt), ## args)
246 #undef strcmp
247 #define strcmp(s1, s2) osl_strcmp((s1), (s2))
248 #undef strncmp
249 #define strncmp(s1, s2, n) osl_strncmp((s1), (s2), (n))
250 #undef strlen
251 #define strlen(s) osl_strlen((s))
252 #undef strcpy
253 #define strcpy(d, s) osl_strcpy((d), (s))
254 #undef strncpy
255 #define strncpy(d, s, n) osl_strncpy((d), (s), (n))
256 #endif /* LINUX_OSL */
257 extern int osl_printf(const char *format, ...);
258 extern int osl_sprintf(char *buf, const char *format, ...);
259 extern int osl_strcmp(const char *s1, const char *s2);
260 extern int osl_strncmp(const char *s1, const char *s2, uint n);
261 extern int osl_strlen(const char *s);
262 extern char* osl_strcpy(char *d, const char *s);
263 extern char* osl_strncpy(char *d, const char *s, uint n);
264
265 /* register access macros */
266 #if !defined(BCMJTAG)
267 #define R_REG(osh, r) (\
268 sizeof(*(r)) == sizeof(uint8) ? osl_readb((volatile uint8*)(r)) : \
269 sizeof(*(r)) == sizeof(uint16) ? osl_readw((volatile uint16*)(r)) : \
270 osl_readl((volatile uint32*)(r)) \
271 )
272 #define W_REG(osh, r, v) do { \
273 switch (sizeof(*(r))) { \
274 case sizeof(uint8): osl_writeb((uint8)(v), (volatile uint8*)(r)); break; \
275 case sizeof(uint16): osl_writew((uint16)(v), (volatile uint16*)(r)); break; \
276 case sizeof(uint32): osl_writel((uint32)(v), (volatile uint32*)(r)); break; \
277 } \
278 } while (0)
279 #endif
280
281 #define AND_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) & (v))
282 #define OR_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) | (v))
283 extern uint8 osl_readb(volatile uint8 *r);
284 extern uint16 osl_readw(volatile uint16 *r);
285 extern uint32 osl_readl(volatile uint32 *r);
286 extern void osl_writeb(uint8 v, volatile uint8 *r);
287 extern void osl_writew(uint16 v, volatile uint16 *r);
288 extern void osl_writel(uint32 v, volatile uint32 *r);
289
290 /* bcopy, bcmp, and bzero */
291 extern void bcopy(const void *src, void *dst, int len);
292 extern int bcmp(const void *b1, const void *b2, int len);
293 extern void bzero(void *b, int len);
294
295 /* uncached virtual address */
296 #define OSL_UNCACHED(va) osl_uncached((va))
297 extern void *osl_uncached(void *va);
298
299 /* get processor cycle count */
300 #define OSL_GETCYCLES(x) ((x) = osl_getcycles())
301 extern uint osl_getcycles(void);
302
303 /* dereference an address that may target abort */
304 #define BUSPROBE(val, addr) osl_busprobe(&(val), (addr))
305 extern int osl_busprobe(uint32 *val, uint32 addr);
306
307 /* map/unmap physical to virtual */
308 #define REG_MAP(pa, size) osl_reg_map((pa), (size))
309 #define REG_UNMAP(va) osl_reg_unmap((va))
310 extern void *osl_reg_map(uint32 pa, uint size);
311 extern void osl_reg_unmap(void *va);
312
313 /* shared (dma-able) memory access macros */
314 #define R_SM(r) *(r)
315 #define W_SM(r, v) (*(r) = (v))
316 #define BZERO_SM(r, len) bzero((r), (len))
317
318 /* packet primitives */
319 #define PKTGET(osh, len, send) osl_pktget((osh), (len))
320 #define PKTFREE(osh, skb, send) osl_pktfree((osh), (skb), (send))
321 #define PKTDATA(osh, skb) osl_pktdata((osh), (skb))
322 #define PKTLEN(osh, skb) osl_pktlen((osh), (skb))
323 #define PKTHEADROOM(osh, skb) osl_pktheadroom((osh), (skb))
324 #define PKTTAILROOM(osh, skb) osl_pkttailroom((osh), (skb))
325 #define PKTNEXT(osh, skb) osl_pktnext((osh), (skb))
326 #define PKTSETNEXT(osh, skb, x) osl_pktsetnext((skb), (x))
327 #define PKTSETLEN(osh, skb, len) osl_pktsetlen((osh), (skb), (len))
328 #define PKTPUSH(osh, skb, bytes) osl_pktpush((osh), (skb), (bytes))
329 #define PKTPULL(osh, skb, bytes) osl_pktpull((osh), (skb), (bytes))
330 #define PKTDUP(osh, skb) osl_pktdup((osh), (skb))
331 #define PKTTAG(skb) osl_pkttag((skb))
332 #define PKTFRMNATIVE(osh, skb) osl_pkt_frmnative((osh), (struct sk_buff*)(skb))
333 #define PKTTONATIVE(osh, pkt) osl_pkt_tonative((osh), (pkt))
334 #define PKTLINK(skb) osl_pktlink((skb))
335 #define PKTSETLINK(skb, x) osl_pktsetlink((skb), (x))
336 #define PKTPRIO(skb) osl_pktprio((skb))
337 #define PKTSETPRIO(skb, x) osl_pktsetprio((skb), (x))
338 #define PKTSHARED(skb) osl_pktshared((skb))
339 #define PKTALLOCED(osh) osl_pktalloced((osh))
340 #ifdef BCMDBG_PKT
341 #define PKTLIST_DUMP(osh, buf) osl_pktlist_dump(osh, buf)
342 #else /* BCMDBG_PKT */
343 #define PKTLIST_DUMP(osh, buf)
344 #endif /* BCMDBG_PKT */
345
346 extern void *osl_pktget(osl_t *osh, uint len);
347 extern void osl_pktfree(osl_t *osh, void *skb, bool send);
348 extern uchar *osl_pktdata(osl_t *osh, void *skb);
349 extern uint osl_pktlen(osl_t *osh, void *skb);
350 extern uint osl_pktheadroom(osl_t *osh, void *skb);
351 extern uint osl_pkttailroom(osl_t *osh, void *skb);
352 extern void *osl_pktnext(osl_t *osh, void *skb);
353 extern void osl_pktsetnext(void *skb, void *x);
354 extern void osl_pktsetlen(osl_t *osh, void *skb, uint len);
355 extern uchar *osl_pktpush(osl_t *osh, void *skb, int bytes);
356 extern uchar *osl_pktpull(osl_t *osh, void *skb, int bytes);
357 extern void *osl_pktdup(osl_t *osh, void *skb);
358 extern void *osl_pkttag(void *skb);
359 extern void *osl_pktlink(void *skb);
360 extern void osl_pktsetlink(void *skb, void *x);
361 extern uint osl_pktprio(void *skb);
362 extern void osl_pktsetprio(void *skb, uint x);
363 extern void *osl_pkt_frmnative(osl_t *osh, struct sk_buff *skb);
364 extern struct sk_buff *osl_pkt_tonative(osl_t *osh, void *pkt);
365 extern bool osl_pktshared(void *skb);
366 extern uint osl_pktalloced(osl_t *osh);
367
368 #ifdef BCMDBG_PKT /* pkt logging for debugging */
369 extern char *osl_pktlist_dump(osl_t *osh, char *buf);
370 extern void osl_pktlist_add(osl_t *osh, void *p);
371 extern void osl_pktlist_remove(osl_t *osh, void *p);
372 #endif /* BCMDBG_PKT */
373
374 #endif /* BINOSL */
375
376 #define OSL_ERROR(bcmerror) osl_error(bcmerror)
377 extern int osl_error(int bcmerror);
378
379 /* the largest reasonable packet buffer driver uses for ethernet MTU in bytes */
380 #define PKTBUFSZ 2048 /* largest reasonable packet buffer, driver uses for ethernet MTU */
381
382 #endif /* _linux_osl_h_ */
This page took 0.082978 seconds and 5 git commands to generate.