block: fix warning with calling smp_processor_id() in preemptible section
[pandora-kernel.git] / drivers / staging / brcm80211 / include / hnddma.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 _hnddma_h_
18 #define _hnddma_h_
19
20 #ifndef _hnddma_pub_
21 #define _hnddma_pub_
22 struct hnddma_pub;
23 #endif                          /* _hnddma_pub_ */
24
25 /* map/unmap direction */
26 #define DMA_TX  1               /* TX direction for DMA */
27 #define DMA_RX  2               /* RX direction for DMA */
28 #define BUS_SWAP32(v)           (v)
29
30 /* range param for dma_getnexttxp() and dma_txreclaim */
31 typedef enum txd_range {
32         HNDDMA_RANGE_ALL = 1,
33         HNDDMA_RANGE_TRANSMITTED,
34         HNDDMA_RANGE_TRANSFERED
35 } txd_range_t;
36
37 /* dma function type */
38 typedef void (*di_detach_t) (struct hnddma_pub *dmah);
39 typedef bool(*di_txreset_t) (struct hnddma_pub *dmah);
40 typedef bool(*di_rxreset_t) (struct hnddma_pub *dmah);
41 typedef bool(*di_rxidle_t) (struct hnddma_pub *dmah);
42 typedef void (*di_txinit_t) (struct hnddma_pub *dmah);
43 typedef bool(*di_txenabled_t) (struct hnddma_pub *dmah);
44 typedef void (*di_rxinit_t) (struct hnddma_pub *dmah);
45 typedef void (*di_txsuspend_t) (struct hnddma_pub *dmah);
46 typedef void (*di_txresume_t) (struct hnddma_pub *dmah);
47 typedef bool(*di_txsuspended_t) (struct hnddma_pub *dmah);
48 typedef bool(*di_txsuspendedidle_t) (struct hnddma_pub *dmah);
49 typedef int (*di_txfast_t) (struct hnddma_pub *dmah, struct sk_buff *p,
50                             bool commit);
51 typedef int (*di_txunframed_t) (struct hnddma_pub *dmah, void *p, uint len,
52                                 bool commit);
53 typedef void *(*di_getpos_t) (struct hnddma_pub *di, bool direction);
54 typedef void (*di_fifoloopbackenable_t) (struct hnddma_pub *dmah);
55 typedef bool(*di_txstopped_t) (struct hnddma_pub *dmah);
56 typedef bool(*di_rxstopped_t) (struct hnddma_pub *dmah);
57 typedef bool(*di_rxenable_t) (struct hnddma_pub *dmah);
58 typedef bool(*di_rxenabled_t) (struct hnddma_pub *dmah);
59 typedef void *(*di_rx_t) (struct hnddma_pub *dmah);
60 typedef bool(*di_rxfill_t) (struct hnddma_pub *dmah);
61 typedef void (*di_txreclaim_t) (struct hnddma_pub *dmah, txd_range_t range);
62 typedef void (*di_rxreclaim_t) (struct hnddma_pub *dmah);
63 typedef unsigned long (*di_getvar_t) (struct hnddma_pub *dmah,
64                                       const char *name);
65 typedef void *(*di_getnexttxp_t) (struct hnddma_pub *dmah, txd_range_t range);
66 typedef void *(*di_getnextrxp_t) (struct hnddma_pub *dmah, bool forceall);
67 typedef void *(*di_peeknexttxp_t) (struct hnddma_pub *dmah);
68 typedef void *(*di_peeknextrxp_t) (struct hnddma_pub *dmah);
69 typedef void (*di_rxparam_get_t) (struct hnddma_pub *dmah, u16 *rxoffset,
70                                   u16 *rxbufsize);
71 typedef void (*di_txblock_t) (struct hnddma_pub *dmah);
72 typedef void (*di_txunblock_t) (struct hnddma_pub *dmah);
73 typedef uint(*di_txactive_t) (struct hnddma_pub *dmah);
74 typedef void (*di_txrotate_t) (struct hnddma_pub *dmah);
75 typedef void (*di_counterreset_t) (struct hnddma_pub *dmah);
76 typedef uint(*di_ctrlflags_t) (struct hnddma_pub *dmah, uint mask, uint flags);
77 typedef char *(*di_dump_t) (struct hnddma_pub *dmah, struct bcmstrbuf *b,
78                             bool dumpring);
79 typedef char *(*di_dumptx_t) (struct hnddma_pub *dmah, struct bcmstrbuf *b,
80                               bool dumpring);
81 typedef char *(*di_dumprx_t) (struct hnddma_pub *dmah, struct bcmstrbuf *b,
82                               bool dumpring);
83 typedef uint(*di_rxactive_t) (struct hnddma_pub *dmah);
84 typedef uint(*di_txpending_t) (struct hnddma_pub *dmah);
85 typedef uint(*di_txcommitted_t) (struct hnddma_pub *dmah);
86
87 /* dma opsvec */
88 typedef struct di_fcn_s {
89         di_detach_t detach;
90         di_txinit_t txinit;
91         di_txreset_t txreset;
92         di_txenabled_t txenabled;
93         di_txsuspend_t txsuspend;
94         di_txresume_t txresume;
95         di_txsuspended_t txsuspended;
96         di_txsuspendedidle_t txsuspendedidle;
97         di_txfast_t txfast;
98         di_txunframed_t txunframed;
99         di_getpos_t getpos;
100         di_txstopped_t txstopped;
101         di_txreclaim_t txreclaim;
102         di_getnexttxp_t getnexttxp;
103         di_peeknexttxp_t peeknexttxp;
104         di_txblock_t txblock;
105         di_txunblock_t txunblock;
106         di_txactive_t txactive;
107         di_txrotate_t txrotate;
108
109         di_rxinit_t rxinit;
110         di_rxreset_t rxreset;
111         di_rxidle_t rxidle;
112         di_rxstopped_t rxstopped;
113         di_rxenable_t rxenable;
114         di_rxenabled_t rxenabled;
115         di_rx_t rx;
116         di_rxfill_t rxfill;
117         di_rxreclaim_t rxreclaim;
118         di_getnextrxp_t getnextrxp;
119         di_peeknextrxp_t peeknextrxp;
120         di_rxparam_get_t rxparam_get;
121
122         di_fifoloopbackenable_t fifoloopbackenable;
123         di_getvar_t d_getvar;
124         di_counterreset_t counterreset;
125         di_ctrlflags_t ctrlflags;
126         di_dump_t dump;
127         di_dumptx_t dumptx;
128         di_dumprx_t dumprx;
129         di_rxactive_t rxactive;
130         di_txpending_t txpending;
131         di_txcommitted_t txcommitted;
132         uint endnum;
133 } di_fcn_t;
134
135 /*
136  * Exported data structure (read-only)
137  */
138 /* export structure */
139 struct hnddma_pub {
140         const di_fcn_t *di_fn;  /* DMA function pointers */
141         uint txavail;           /* # free tx descriptors */
142         uint dmactrlflags;      /* dma control flags */
143
144         /* rx error counters */
145         uint rxgiants;          /* rx giant frames */
146         uint rxnobuf;           /* rx out of dma descriptors */
147         /* tx error counters */
148         uint txnobuf;           /* tx out of dma descriptors */
149 };
150
151 extern struct hnddma_pub *dma_attach(char *name, si_t *sih,
152                             void *dmaregstx, void *dmaregsrx, uint ntxd,
153                             uint nrxd, uint rxbufsize, int rxextheadroom,
154                             uint nrxpost, uint rxoffset, uint *msg_level);
155
156 extern const di_fcn_t dma64proc;
157
158 #define dma_detach(di)                  (dma64proc.detach(di))
159 #define dma_txreset(di)                 (dma64proc.txreset(di))
160 #define dma_rxreset(di)                 (dma64proc.rxreset(di))
161 #define dma_rxidle(di)                  (dma64proc.rxidle(di))
162 #define dma_txinit(di)                  (dma64proc.txinit(di))
163 #define dma_txenabled(di)               (dma64proc.txenabled(di))
164 #define dma_rxinit(di)                  (dma64proc.rxinit(di))
165 #define dma_txsuspend(di)               (dma64proc.txsuspend(di))
166 #define dma_txresume(di)                (dma64proc.txresume(di))
167 #define dma_txsuspended(di)             (dma64proc.txsuspended(di))
168 #define dma_txsuspendedidle(di)         (dma64proc.txsuspendedidle(di))
169 #define dma_txfast(di, p, commit)       (dma64proc.txfast(di, p, commit))
170 #define dma_txunframed(di, p, l, commit)(dma64proc.txunframed(di, p, l, commit))
171 #define dma_getpos(di, dir)             (dma64proc.getpos(di, dir))
172 #define dma_fifoloopbackenable(di)      (dma64proc.fifoloopbackenable(di))
173 #define dma_txstopped(di)               (dma64proc.txstopped(di))
174 #define dma_rxstopped(di)               (dma64proc.rxstopped(di))
175 #define dma_rxenable(di)                (dma64proc.rxenable(di))
176 #define dma_rxenabled(di)               (dma64proc.rxenabled(di))
177 #define dma_rx(di)                      (dma64proc.rx(di))
178 #define dma_rxfill(di)                  (dma64proc.rxfill(di))
179 #define dma_txreclaim(di, range)        (dma64proc.txreclaim(di, range))
180 #define dma_rxreclaim(di)               (dma64proc.rxreclaim(di))
181 #define dma_getvar(di, name)            (dma64proc.d_getvar(di, name))
182 #define dma_getnexttxp(di, range)       (dma64proc.getnexttxp(di, range))
183 #define dma_getnextrxp(di, forceall)    (dma64proc.getnextrxp(di, forceall))
184 #define dma_peeknexttxp(di)             (dma64proc.peeknexttxp(di))
185 #define dma_peeknextrxp(di)             (dma64proc.peeknextrxp(di))
186 #define dma_rxparam_get(di, off, bufs)  (dma64proc.rxparam_get(di, off, bufs))
187
188 #define dma_txblock(di)                 (dma64proc.txblock(di))
189 #define dma_txunblock(di)               (dma64proc.txunblock(di))
190 #define dma_txactive(di)                (dma64proc.txactive(di))
191 #define dma_rxactive(di)                (dma64proc.rxactive(di))
192 #define dma_txrotate(di)                (dma64proc.txrotate(di))
193 #define dma_counterreset(di)            (dma64proc.counterreset(di))
194 #define dma_ctrlflags(di, mask, flags)  (dma64proc.ctrlflags((di), (mask), (flags)))
195 #define dma_txpending(di)               (dma64proc.txpending(di))
196 #define dma_txcommitted(di)             (dma64proc.txcommitted(di))
197
198
199 /* return addresswidth allowed
200  * This needs to be done after SB attach but before dma attach.
201  * SB attach provides ability to probe backplane and dma core capabilities
202  * This info is needed by DMA_ALLOC_CONSISTENT in dma attach
203  */
204 extern uint dma_addrwidth(si_t *sih, void *dmaregs);
205 void dma_walk_packets(struct hnddma_pub *dmah, void (*callback_fnc)
206                       (void *pkt, void *arg_a), void *arg_a);
207
208 /*
209  * DMA(Bug) on some chips seems to declare that the packet is ready, but the
210  * packet length is not updated yet (by DMA) on the expected time.
211  * Workaround is to hold processor till DMA updates the length, and stay off
212  * the bus to allow DMA update the length in buffer
213  */
214 static inline void dma_spin_for_len(uint len, struct sk_buff *head)
215 {
216 #if defined(__mips__)
217         if (!len) {
218                 while (!(len = *(u16 *) KSEG1ADDR(head->data)))
219                         udelay(1);
220
221                 *(u16 *) (head->data) = cpu_to_le16((u16) len);
222         }
223 #endif                          /* defined(__mips__) */
224 }
225
226 #endif                          /* _hnddma_h_ */