awx: fix a typo
[openwrt.git] / package / broadcom-wl / src / kmod / linux_osl.h
1 /*
2 * Linux OS Independent Layer
3 *
4 * Copyright 2006, 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 * $Id: linux_osl.h,v 1.1.1.13 2006/04/08 06:13:39 honor Exp $
13 */
14
15 #ifndef _linux_osl_h_
16 #define _linux_osl_h_
17
18 #include <typedefs.h>
19 #include <linuxver.h>
20 #include <osl.h>
21
22 #define OSL_PKTTAG_SZ 32 /* Size of PktTag */
23
24 /* osl handle type forward declaration */
25 typedef struct osl_dmainfo osldma_t;
26
27 /* OSL initialization */
28 extern osl_t *osl_attach(void *pdev, bool pkttag);
29 extern void osl_detach(osl_t *osh);
30
31 /* host/bus architecture-specific byte swap */
32 #define BUS_SWAP32(v) (v)
33 #define MALLOC_FAILED(osh) osl_malloc_failed((osh))
34
35 extern void *osl_malloc(osl_t *osh, uint size);
36 extern void osl_mfree(osl_t *osh, void *addr, uint size);
37 extern uint osl_malloced(osl_t *osh);
38 extern uint osl_malloc_failed(osl_t *osh);
39
40 /* API for DMA addressing capability */
41 #define DMA_MAP(osh, va, size, direction, p) \
42 osl_dma_map((osh), (va), (size), (direction))
43 #define DMA_UNMAP(osh, pa, size, direction, p) \
44 osl_dma_unmap((osh), (pa), (size), (direction))
45 static inline uint
46 osl_dma_map(void *osh, void *va, uint size, int direction)
47 {
48 int dir;
49 struct pci_dev *dev;
50
51 dev = (osh == NULL ? NULL : ((osl_t *)osh)->pdev);
52 dir = (direction == DMA_TX)? PCI_DMA_TODEVICE: PCI_DMA_FROMDEVICE;
53 return (pci_map_single(dev, va, size, dir));
54 }
55
56 static inline void
57 osl_dma_unmap(void *osh, uint pa, uint size, int direction)
58 {
59 int dir;
60 struct pci_dev *dev;
61
62 dev = (osh == NULL ? NULL : ((osl_t *)osh)->pdev);
63 dir = (direction == DMA_TX)? PCI_DMA_TODEVICE: PCI_DMA_FROMDEVICE;
64 pci_unmap_single(dev, (uint32)pa, size, dir);
65 }
66
67 #define OSL_DMADDRWIDTH(osh, addrwidth) do {} while (0)
68 #define DMA_CONSISTENT_ALIGN PAGE_SIZE
69 #define DMA_ALLOC_CONSISTENT(osh, size, pap, dmah) \
70 osl_dma_alloc_consistent((osh), (size), (pap))
71 #define DMA_FREE_CONSISTENT(osh, va, size, pa, dmah) \
72 osl_dma_free_consistent((osh), (void*)(va), (size), (pa))
73 static inline void*
74 osl_dma_alloc_consistent(osl_t *osh, uint size, ulong *pap)
75 {
76 return (pci_alloc_consistent(osh->pdev, size, (dma_addr_t*)pap));
77 }
78
79 static inline void
80 osl_dma_free_consistent(osl_t *osh, void *va, uint size, ulong pa)
81 {
82 pci_free_consistent(osh->pdev, size, va, (dma_addr_t)pa);
83 }
84
85
86 /* register access macros */
87 #if defined(BCMJTAG)
88 #include <bcmjtag.h>
89 #define R_REG(osh, r) bcmjtag_read(NULL, (uint32)(r), sizeof(*(r)))
90 #define W_REG(osh, r, v) bcmjtag_write(NULL, (uint32)(r), (uint32)(v), sizeof(*(r)))
91 #endif /* defined(BCMSDIO) */
92
93 /* packet primitives */
94 #define PKTGET(osh, len, send) osl_pktget((osh), (len), (send))
95 #define PKTFREE(osh, skb, send) osl_pktfree((osh), (skb), (send))
96 #define PKTDATA(osh, skb) (((struct sk_buff*)(skb))->data)
97 #define PKTLEN(osh, skb) (((struct sk_buff*)(skb))->len)
98 #define PKTHEADROOM(osh, skb) (PKTDATA(osh, skb)-(((struct sk_buff*)(skb))->head))
99 #define PKTTAILROOM(osh, skb) ((((struct sk_buff*)(skb))->end)-(((struct sk_buff*)(skb))->tail))
100 #define PKTNEXT(osh, skb) (((struct sk_buff*)(skb))->next)
101 #define PKTSETNEXT(osh, skb, x) (((struct sk_buff*)(skb))->next = (struct sk_buff*)(x))
102 #define PKTSETLEN(osh, skb, len) __skb_trim((struct sk_buff*)(skb), (len))
103 #define PKTPUSH(osh, skb, bytes) skb_push((struct sk_buff*)(skb), (bytes))
104 #define PKTPULL(osh, skb, bytes) skb_pull((struct sk_buff*)(skb), (bytes))
105 #define PKTDUP(osh, skb) osl_pktdup((osh), (skb))
106 #define PKTTAG(skb) ((void*)(((struct sk_buff*)(skb))->cb))
107 #define PKTALLOCED(osh) osl_pktalloced((osh))
108 #define PKTLIST_DUMP(osh, buf)
109
110 /* Convert a native(OS) packet to driver packet.
111 * In the process, native packet is destroyed, there is no copying
112 * Also, a packettag is zeroed out
113 */
114 static INLINE void *
115 osl_pkt_frmnative(osl_pubinfo_t*osh, struct sk_buff *skb)
116 {
117 struct sk_buff *nskb;
118
119 if (osh->pkttag)
120 bzero((void*)skb->cb, OSL_PKTTAG_SZ);
121
122 /* Increment the packet counter */
123 for (nskb = skb; nskb; nskb = nskb->next) {
124 osh->pktalloced++;
125 }
126
127 return (void *)skb;
128 }
129 #define PKTFRMNATIVE(osh, skb) osl_pkt_frmnative(((osl_pubinfo_t*)osh), \
130 (struct sk_buff*)(skb))
131
132 /* Convert a driver packet to native(OS) packet
133 * In the process, packettag is zeroed out before sending up
134 * IP code depends on skb->cb to be setup correctly with various options
135 * In our case, that means it should be 0
136 */
137 static INLINE struct sk_buff *
138 osl_pkt_tonative(osl_pubinfo_t*osh, void *pkt)
139 {
140 struct sk_buff *nskb;
141
142 if (osh->pkttag)
143 bzero(((struct sk_buff*)pkt)->cb, OSL_PKTTAG_SZ);
144
145 /* Decrement the packet counter */
146 for (nskb = (struct sk_buff *)pkt; nskb; nskb = nskb->next) {
147 osh->pktalloced--;
148 }
149
150 return (struct sk_buff *)pkt;
151 }
152 #define PKTTONATIVE(osh, pkt) osl_pkt_tonative((osl_pubinfo_t*)(osh), (pkt))
153
154 #define PKTLINK(skb) (((struct sk_buff*)(skb))->prev)
155 #define PKTSETLINK(skb, x) (((struct sk_buff*)(skb))->prev = (struct sk_buff*)(x))
156 #define PKTPRIO(skb) (((struct sk_buff*)(skb))->priority)
157 #define PKTSETPRIO(skb, x) (((struct sk_buff*)(skb))->priority = (x))
158 #define PKTSHARED(skb) (((struct sk_buff*)(skb))->cloned)
159
160 extern void *osl_pktget(osl_t *osh, uint len, bool send);
161 extern void osl_pktfree(osl_t *osh, void *skb, bool send);
162 extern void *osl_pktdup(osl_t *osh, void *skb);
163 extern uint osl_pktalloced(osl_t *osh);
164
165 #define OSL_ERROR(bcmerror) osl_error(bcmerror)
166 extern int osl_error(int bcmerror);
167
168 /* the largest reasonable packet buffer driver uses for ethernet MTU in bytes */
169 #define PKTBUFSZ 2048 /* largest reasonable packet buffer, driver uses for ethernet MTU */
170
171 #endif /* _linux_osl_h_ */
This page took 0.062928 seconds and 5 git commands to generate.