4 #include <linux/list.h>
5 #include <linux/spinlock.h>
6 #include <linux/workqueue.h>
7 #include <linux/linkage.h>
8 #include <asm/atomic.h>
11 /* DMA-Interrupt reasons. */
12 #define BCM43xx_DMAIRQ_FATALMASK ((1 << 10) | (1 << 11) | (1 << 12) \
13 | (1 << 14) | (1 << 15))
14 #define BCM43xx_DMAIRQ_NONFATALMASK (1 << 13)
15 #define BCM43xx_DMAIRQ_RX_DONE (1 << 16)
18 /*** 32-bit DMA Engine. ***/
20 /* 32-bit DMA controller registers. */
21 #define BCM43xx_DMA32_TXCTL 0x00
22 #define BCM43xx_DMA32_TXENABLE 0x00000001
23 #define BCM43xx_DMA32_TXSUSPEND 0x00000002
24 #define BCM43xx_DMA32_TXLOOPBACK 0x00000004
25 #define BCM43xx_DMA32_TXFLUSH 0x00000010
26 #define BCM43xx_DMA32_TXADDREXT_MASK 0x00030000
27 #define BCM43xx_DMA32_TXADDREXT_SHIFT 16
28 #define BCM43xx_DMA32_TXRING 0x04
29 #define BCM43xx_DMA32_TXINDEX 0x08
30 #define BCM43xx_DMA32_TXSTATUS 0x0C
31 #define BCM43xx_DMA32_TXDPTR 0x00000FFF
32 #define BCM43xx_DMA32_TXSTATE 0x0000F000
33 #define BCM43xx_DMA32_TXSTAT_DISABLED 0x00000000
34 #define BCM43xx_DMA32_TXSTAT_ACTIVE 0x00001000
35 #define BCM43xx_DMA32_TXSTAT_IDLEWAIT 0x00002000
36 #define BCM43xx_DMA32_TXSTAT_STOPPED 0x00003000
37 #define BCM43xx_DMA32_TXSTAT_SUSP 0x00004000
38 #define BCM43xx_DMA32_TXERROR 0x000F0000
39 #define BCM43xx_DMA32_TXERR_NOERR 0x00000000
40 #define BCM43xx_DMA32_TXERR_PROT 0x00010000
41 #define BCM43xx_DMA32_TXERR_UNDERRUN 0x00020000
42 #define BCM43xx_DMA32_TXERR_BUFREAD 0x00030000
43 #define BCM43xx_DMA32_TXERR_DESCREAD 0x00040000
44 #define BCM43xx_DMA32_TXACTIVE 0xFFF00000
45 #define BCM43xx_DMA32_RXCTL 0x10
46 #define BCM43xx_DMA32_RXENABLE 0x00000001
47 #define BCM43xx_DMA32_RXFROFF_MASK 0x000000FE
48 #define BCM43xx_DMA32_RXFROFF_SHIFT 1
49 #define BCM43xx_DMA32_RXDIRECTFIFO 0x00000100
50 #define BCM43xx_DMA32_RXADDREXT_MASK 0x00030000
51 #define BCM43xx_DMA32_RXADDREXT_SHIFT 16
52 #define BCM43xx_DMA32_RXRING 0x14
53 #define BCM43xx_DMA32_RXINDEX 0x18
54 #define BCM43xx_DMA32_RXSTATUS 0x1C
55 #define BCM43xx_DMA32_RXDPTR 0x00000FFF
56 #define BCM43xx_DMA32_RXSTATE 0x0000F000
57 #define BCM43xx_DMA32_RXSTAT_DISABLED 0x00000000
58 #define BCM43xx_DMA32_RXSTAT_ACTIVE 0x00001000
59 #define BCM43xx_DMA32_RXSTAT_IDLEWAIT 0x00002000
60 #define BCM43xx_DMA32_RXSTAT_STOPPED 0x00003000
61 #define BCM43xx_DMA32_RXERROR 0x000F0000
62 #define BCM43xx_DMA32_RXERR_NOERR 0x00000000
63 #define BCM43xx_DMA32_RXERR_PROT 0x00010000
64 #define BCM43xx_DMA32_RXERR_OVERFLOW 0x00020000
65 #define BCM43xx_DMA32_RXERR_BUFWRITE 0x00030000
66 #define BCM43xx_DMA32_RXERR_DESCREAD 0x00040000
67 #define BCM43xx_DMA32_RXACTIVE 0xFFF00000
69 /* 32-bit DMA descriptor. */
70 struct bcm43xx_dmadesc32
{
73 } __attribute__((__packed__
));
74 #define BCM43xx_DMA32_DCTL_BYTECNT 0x00001FFF
75 #define BCM43xx_DMA32_DCTL_ADDREXT_MASK 0x00030000
76 #define BCM43xx_DMA32_DCTL_ADDREXT_SHIFT 16
77 #define BCM43xx_DMA32_DCTL_DTABLEEND 0x10000000
78 #define BCM43xx_DMA32_DCTL_IRQ 0x20000000
79 #define BCM43xx_DMA32_DCTL_FRAMEEND 0x40000000
80 #define BCM43xx_DMA32_DCTL_FRAMESTART 0x80000000
82 /* Address field Routing value. */
83 #define BCM43xx_DMA32_ROUTING 0xC0000000
84 #define BCM43xx_DMA32_ROUTING_SHIFT 30
85 #define BCM43xx_DMA32_NOTRANS 0x00000000
86 #define BCM43xx_DMA32_CLIENTTRANS 0x40000000
90 /*** 64-bit DMA Engine. ***/
92 /* 64-bit DMA controller registers. */
93 #define BCM43xx_DMA64_TXCTL 0x00
94 #define BCM43xx_DMA64_TXENABLE 0x00000001
95 #define BCM43xx_DMA64_TXSUSPEND 0x00000002
96 #define BCM43xx_DMA64_TXLOOPBACK 0x00000004
97 #define BCM43xx_DMA64_TXFLUSH 0x00000010
98 #define BCM43xx_DMA64_TXADDREXT_MASK 0x00030000
99 #define BCM43xx_DMA64_TXADDREXT_SHIFT 16
100 #define BCM43xx_DMA64_TXINDEX 0x04
101 #define BCM43xx_DMA64_TXRINGLO 0x08
102 #define BCM43xx_DMA64_TXRINGHI 0x0C
103 #define BCM43xx_DMA64_TXSTATUS 0x10
104 #define BCM43xx_DMA64_TXSTATDPTR 0x00001FFF
105 #define BCM43xx_DMA64_TXSTAT 0xF0000000
106 #define BCM43xx_DMA64_TXSTAT_DISABLED 0x00000000
107 #define BCM43xx_DMA64_TXSTAT_ACTIVE 0x10000000
108 #define BCM43xx_DMA64_TXSTAT_IDLEWAIT 0x20000000
109 #define BCM43xx_DMA64_TXSTAT_STOPPED 0x30000000
110 #define BCM43xx_DMA64_TXSTAT_SUSP 0x40000000
111 #define BCM43xx_DMA64_TXERROR 0x14
112 #define BCM43xx_DMA64_TXERRDPTR 0x0001FFFF
113 #define BCM43xx_DMA64_TXERR 0xF0000000
114 #define BCM43xx_DMA64_TXERR_NOERR 0x00000000
115 #define BCM43xx_DMA64_TXERR_PROT 0x10000000
116 #define BCM43xx_DMA64_TXERR_UNDERRUN 0x20000000
117 #define BCM43xx_DMA64_TXERR_TRANSFER 0x30000000
118 #define BCM43xx_DMA64_TXERR_DESCREAD 0x40000000
119 #define BCM43xx_DMA64_TXERR_CORE 0x50000000
120 #define BCM43xx_DMA64_RXCTL 0x20
121 #define BCM43xx_DMA64_RXENABLE 0x00000001
122 #define BCM43xx_DMA64_RXFROFF_MASK 0x000000FE
123 #define BCM43xx_DMA64_RXFROFF_SHIFT 1
124 #define BCM43xx_DMA64_RXDIRECTFIFO 0x00000100
125 #define BCM43xx_DMA64_RXADDREXT_MASK 0x00030000
126 #define BCM43xx_DMA64_RXADDREXT_SHIFT 16
127 #define BCM43xx_DMA64_RXINDEX 0x24
128 #define BCM43xx_DMA64_RXRINGLO 0x28
129 #define BCM43xx_DMA64_RXRINGHI 0x2C
130 #define BCM43xx_DMA64_RXSTATUS 0x30
131 #define BCM43xx_DMA64_RXSTATDPTR 0x00001FFF
132 #define BCM43xx_DMA64_RXSTAT 0xF0000000
133 #define BCM43xx_DMA64_RXSTAT_DISABLED 0x00000000
134 #define BCM43xx_DMA64_RXSTAT_ACTIVE 0x10000000
135 #define BCM43xx_DMA64_RXSTAT_IDLEWAIT 0x20000000
136 #define BCM43xx_DMA64_RXSTAT_STOPPED 0x30000000
137 #define BCM43xx_DMA64_RXSTAT_SUSP 0x40000000
138 #define BCM43xx_DMA64_RXERROR 0x34
139 #define BCM43xx_DMA64_RXERRDPTR 0x0001FFFF
140 #define BCM43xx_DMA64_RXERR 0xF0000000
141 #define BCM43xx_DMA64_RXERR_NOERR 0x00000000
142 #define BCM43xx_DMA64_RXERR_PROT 0x10000000
143 #define BCM43xx_DMA64_RXERR_UNDERRUN 0x20000000
144 #define BCM43xx_DMA64_RXERR_TRANSFER 0x30000000
145 #define BCM43xx_DMA64_RXERR_DESCREAD 0x40000000
146 #define BCM43xx_DMA64_RXERR_CORE 0x50000000
148 /* 64-bit DMA descriptor. */
149 struct bcm43xx_dmadesc64
{
154 } __attribute__((__packed__
));
155 #define BCM43xx_DMA64_DCTL0_DTABLEEND 0x10000000
156 #define BCM43xx_DMA64_DCTL0_IRQ 0x20000000
157 #define BCM43xx_DMA64_DCTL0_FRAMEEND 0x40000000
158 #define BCM43xx_DMA64_DCTL0_FRAMESTART 0x80000000
159 #define BCM43xx_DMA64_DCTL1_BYTECNT 0x00001FFF
160 #define BCM43xx_DMA64_DCTL1_ADDREXT_MASK 0x00030000
161 #define BCM43xx_DMA64_DCTL1_ADDREXT_SHIFT 16
163 /* Address field Routing value. */
164 #define BCM43xx_DMA64_ROUTING 0xC0000000
165 #define BCM43xx_DMA64_ROUTING_SHIFT 30
166 #define BCM43xx_DMA64_NOTRANS 0x00000000
167 #define BCM43xx_DMA64_CLIENTTRANS 0x80000000
171 struct bcm43xx_dmadesc_generic
{
173 struct bcm43xx_dmadesc32 dma32
;
174 struct bcm43xx_dmadesc64 dma64
;
175 } __attribute__((__packed__
));
176 } __attribute__((__packed__
));
179 /* Misc DMA constants */
180 #define BCM43xx_DMA_RINGMEMSIZE PAGE_SIZE
181 #define BCM43xx_DMA0_RX_FRAMEOFFSET 30
182 #define BCM43xx_DMA3_RX_FRAMEOFFSET 0
185 /* DMA engine tuning knobs */
186 #define BCM43xx_TXRING_SLOTS 512
187 #define BCM43xx_RXRING_SLOTS 64
188 #define BCM43xx_DMA0_RX_BUFFERSIZE (2304 + 100)
189 #define BCM43xx_DMA3_RX_BUFFERSIZE 16
190 /* Suspend the tx queue, if less than this percent slots are free. */
191 #define BCM43xx_TXSUSPEND_PERCENT 20
192 /* Resume the tx queue, if more than this percent slots are free. */
193 #define BCM43xx_TXRESUME_PERCENT 50
197 #ifdef CONFIG_BCM43XX_DMA
201 struct bcm43xx_private
;
202 struct bcm43xx_xmitstatus
;
205 struct bcm43xx_dmadesc_meta
{
206 /* The kernel DMA-able buffer. */
208 /* DMA base bus-address of the descriptor buffer. */
212 struct bcm43xx_dmaring
{
213 /* Kernel virtual base address of the ring memory. */
215 /* Meta data about all descriptors. */
216 struct bcm43xx_dmadesc_meta
*meta
;
217 /* DMA Routing value. */
219 /* (Unadjusted) DMA base bus-address of the ring memory. */
221 /* Number of descriptor slots in the ring. */
223 /* Number of used descriptor slots. */
225 /* Currently used slot in the ring. */
227 /* Marks to suspend/resume the queue. */
230 /* Frameoffset in octets. */
232 /* Descriptor buffer size. */
234 /* The MMIO base register of the DMA controller. */
236 /* DMA controller index number (0-5). */
238 u8 tx
:1, /* TRUE, if this is a TX ring. */
239 dma64
:1, /* TRUE, if 64-bit DMA is enabled (FALSE if 32bit). */
240 suspended
:1; /* TRUE, if transfers are suspended on this ring. */
241 struct bcm43xx_private
*bcm
;
242 #ifdef CONFIG_BCM43XX_DEBUG
243 /* Maximum number of used slots. */
245 #endif /* CONFIG_BCM43XX_DEBUG*/
250 int bcm43xx_dma_desc2idx(struct bcm43xx_dmaring
*ring
,
251 struct bcm43xx_dmadesc_generic
*desc
)
254 struct bcm43xx_dmadesc64
*dd64
= ring
->descbase
;
255 return (int)(&(desc
->dma64
) - dd64
);
257 struct bcm43xx_dmadesc32
*dd32
= ring
->descbase
;
258 return (int)(&(desc
->dma32
) - dd32
);
263 struct bcm43xx_dmadesc_generic
* bcm43xx_dma_idx2desc(struct bcm43xx_dmaring
*ring
,
265 struct bcm43xx_dmadesc_meta
**meta
)
267 *meta
= &(ring
->meta
[slot
]);
269 struct bcm43xx_dmadesc64
*dd64
= ring
->descbase
;
270 return (struct bcm43xx_dmadesc_generic
*)(&(dd64
[slot
]));
272 struct bcm43xx_dmadesc32
*dd32
= ring
->descbase
;
273 return (struct bcm43xx_dmadesc_generic
*)(&(dd32
[slot
]));
278 u32
bcm43xx_dma_read(struct bcm43xx_dmaring
*ring
,
281 return bcm43xx_read32(ring
->bcm
, ring
->mmio_base
+ offset
);
285 void bcm43xx_dma_write(struct bcm43xx_dmaring
*ring
,
286 u16 offset
, u32 value
)
288 bcm43xx_write32(ring
->bcm
, ring
->mmio_base
+ offset
, value
);
292 int bcm43xx_dma_init(struct bcm43xx_private
*bcm
);
293 void bcm43xx_dma_free(struct bcm43xx_private
*bcm
);
295 int bcm43xx_dmacontroller_rx_reset(struct bcm43xx_private
*bcm
,
296 u16 dmacontroller_mmio_base
,
298 int bcm43xx_dmacontroller_tx_reset(struct bcm43xx_private
*bcm
,
299 u16 dmacontroller_mmio_base
,
302 u16
bcm43xx_dmacontroller_base(int dma64bit
, int dmacontroller_idx
);
304 void bcm43xx_dma_tx_suspend(struct bcm43xx_dmaring
*ring
);
305 void bcm43xx_dma_tx_resume(struct bcm43xx_dmaring
*ring
);
307 void bcm43xx_dma_handle_xmitstatus(struct bcm43xx_private
*bcm
,
308 struct bcm43xx_xmitstatus
*status
);
310 int bcm43xx_dma_tx(struct bcm43xx_private
*bcm
,
311 struct ieee80211_txb
*txb
);
312 void bcm43xx_dma_rx(struct bcm43xx_dmaring
*ring
);
314 #else /* CONFIG_BCM43XX_DMA */
318 int bcm43xx_dma_init(struct bcm43xx_private
*bcm
)
323 void bcm43xx_dma_free(struct bcm43xx_private
*bcm
)
327 int bcm43xx_dmacontroller_rx_reset(struct bcm43xx_private
*bcm
,
328 u16 dmacontroller_mmio_base
,
334 int bcm43xx_dmacontroller_tx_reset(struct bcm43xx_private
*bcm
,
335 u16 dmacontroller_mmio_base
,
341 int bcm43xx_dma_tx(struct bcm43xx_private
*bcm
,
342 struct ieee80211_txb
*txb
)
347 void bcm43xx_dma_handle_xmitstatus(struct bcm43xx_private
*bcm
,
348 struct bcm43xx_xmitstatus
*status
)
352 void bcm43xx_dma_rx(struct bcm43xx_dmaring
*ring
)
356 void bcm43xx_dma_tx_suspend(struct bcm43xx_dmaring
*ring
)
360 void bcm43xx_dma_tx_resume(struct bcm43xx_dmaring
*ring
)
364 #endif /* CONFIG_BCM43XX_DMA */
365 #endif /* BCM43xx_DMA_H_ */