2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
23 #endif /* _dma_pub_ */
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)
30 /* range param for dma_getnexttxp() and dma_txreclaim */
31 typedef enum txd_range {
33 HNDDMA_RANGE_TRANSMITTED,
34 HNDDMA_RANGE_TRANSFERED
37 /* dma function type */
38 typedef void (*di_detach_t) (struct dma_pub *dmah);
39 typedef bool(*di_txreset_t) (struct dma_pub *dmah);
40 typedef bool(*di_rxreset_t) (struct dma_pub *dmah);
41 typedef bool(*di_rxidle_t) (struct dma_pub *dmah);
42 typedef void (*di_txinit_t) (struct dma_pub *dmah);
43 typedef bool(*di_txenabled_t) (struct dma_pub *dmah);
44 typedef void (*di_rxinit_t) (struct dma_pub *dmah);
45 typedef void (*di_txsuspend_t) (struct dma_pub *dmah);
46 typedef void (*di_txresume_t) (struct dma_pub *dmah);
47 typedef bool(*di_txsuspended_t) (struct dma_pub *dmah);
48 typedef bool(*di_txsuspendedidle_t) (struct dma_pub *dmah);
49 typedef int (*di_txfast_t) (struct dma_pub *dmah, struct sk_buff *p,
51 typedef int (*di_txunframed_t) (struct dma_pub *dmah, void *p, uint len,
53 typedef void *(*di_getpos_t) (struct dma_pub *di, bool direction);
54 typedef void (*di_fifoloopbackenable_t) (struct dma_pub *dmah);
55 typedef bool(*di_txstopped_t) (struct dma_pub *dmah);
56 typedef bool(*di_rxstopped_t) (struct dma_pub *dmah);
57 typedef bool(*di_rxenable_t) (struct dma_pub *dmah);
58 typedef bool(*di_rxenabled_t) (struct dma_pub *dmah);
59 typedef void *(*di_rx_t) (struct dma_pub *dmah);
60 typedef bool(*di_rxfill_t) (struct dma_pub *dmah);
61 typedef void (*di_txreclaim_t) (struct dma_pub *dmah, txd_range_t range);
62 typedef void (*di_rxreclaim_t) (struct dma_pub *dmah);
63 typedef unsigned long (*di_getvar_t) (struct dma_pub *dmah,
65 typedef void *(*di_getnexttxp_t) (struct dma_pub *dmah, txd_range_t range);
66 typedef void *(*di_getnextrxp_t) (struct dma_pub *dmah, bool forceall);
67 typedef void *(*di_peeknexttxp_t) (struct dma_pub *dmah);
68 typedef void *(*di_peeknextrxp_t) (struct dma_pub *dmah);
69 typedef void (*di_rxparam_get_t) (struct dma_pub *dmah, u16 *rxoffset,
71 typedef void (*di_txblock_t) (struct dma_pub *dmah);
72 typedef void (*di_txunblock_t) (struct dma_pub *dmah);
73 typedef uint(*di_txactive_t) (struct dma_pub *dmah);
74 typedef void (*di_txrotate_t) (struct dma_pub *dmah);
75 typedef void (*di_counterreset_t) (struct dma_pub *dmah);
76 typedef uint(*di_ctrlflags_t) (struct dma_pub *dmah, uint mask, uint flags);
77 typedef char *(*di_dump_t) (struct dma_pub *dmah, struct bcmstrbuf *b,
79 typedef char *(*di_dumptx_t) (struct dma_pub *dmah, struct bcmstrbuf *b,
81 typedef char *(*di_dumprx_t) (struct dma_pub *dmah, struct bcmstrbuf *b,
83 typedef uint(*di_rxactive_t) (struct dma_pub *dmah);
84 typedef uint(*di_txpending_t) (struct dma_pub *dmah);
85 typedef uint(*di_txcommitted_t) (struct dma_pub *dmah);
88 typedef struct di_fcn_s {
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;
98 di_txunframed_t txunframed;
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;
110 di_rxreset_t rxreset;
112 di_rxstopped_t rxstopped;
113 di_rxenable_t rxenable;
114 di_rxenabled_t rxenabled;
117 di_rxreclaim_t rxreclaim;
118 di_getnextrxp_t getnextrxp;
119 di_peeknextrxp_t peeknextrxp;
120 di_rxparam_get_t rxparam_get;
122 di_fifoloopbackenable_t fifoloopbackenable;
123 di_getvar_t d_getvar;
124 di_counterreset_t counterreset;
125 di_ctrlflags_t ctrlflags;
129 di_rxactive_t rxactive;
130 di_txpending_t txpending;
131 di_txcommitted_t txcommitted;
136 * Exported data structure (read-only)
138 /* export structure */
140 const di_fcn_t *di_fn; /* DMA function pointers */
141 uint txavail; /* # free tx descriptors */
142 uint dmactrlflags; /* dma control flags */
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 */
151 extern struct dma_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);
156 extern const di_fcn_t dma64proc;
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))
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))
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
204 extern uint dma_addrwidth(si_t *sih, void *dmaregs);
205 void dma_walk_packets(struct dma_pub *dmah, void (*callback_fnc)
206 (void *pkt, void *arg_a), void *arg_a);
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
214 static inline void dma_spin_for_len(uint len, struct sk_buff *head)
216 #if defined(__mips__)
218 while (!(len = *(u16 *) KSEG1ADDR(head->data)))
221 *(u16 *) (head->data) = cpu_to_le16((u16) len);
223 #endif /* defined(__mips__) */
226 #endif /* _bcmdma_h_ */