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.
17 #include <linux/slab.h>
18 #include <linux/delay.h>
19 #include <linux/pci.h>
20 #include <net/cfg80211.h>
21 #include <net/mac80211.h>
23 #include <brcmu_utils.h>
32 #include "brcms_trace_events.h"
35 * dma register field offset calculation
37 #define DMA64REGOFFS(field) offsetof(struct dma64regs, field)
38 #define DMA64TXREGOFFS(di, field) (di->d64txregbase + DMA64REGOFFS(field))
39 #define DMA64RXREGOFFS(di, field) (di->d64rxregbase + DMA64REGOFFS(field))
42 * DMA hardware requires each descriptor ring to be 8kB aligned, and fit within
43 * a contiguous 8kB physical address.
45 #define D64RINGALIGN_BITS 13
46 #define D64MAXRINGSZ (1 << D64RINGALIGN_BITS)
47 #define D64RINGALIGN (1 << D64RINGALIGN_BITS)
49 #define D64MAXDD (D64MAXRINGSZ / sizeof(struct dma64desc))
51 /* transmit channel control */
52 #define D64_XC_XE 0x00000001 /* transmit enable */
53 #define D64_XC_SE 0x00000002 /* transmit suspend request */
54 #define D64_XC_LE 0x00000004 /* loopback enable */
55 #define D64_XC_FL 0x00000010 /* flush request */
56 #define D64_XC_PD 0x00000800 /* parity check disable */
57 #define D64_XC_AE 0x00030000 /* address extension bits */
58 #define D64_XC_AE_SHIFT 16
60 /* transmit descriptor table pointer */
61 #define D64_XP_LD_MASK 0x00000fff /* last valid descriptor */
63 /* transmit channel status */
64 #define D64_XS0_CD_MASK 0x00001fff /* current descriptor pointer */
65 #define D64_XS0_XS_MASK 0xf0000000 /* transmit state */
66 #define D64_XS0_XS_SHIFT 28
67 #define D64_XS0_XS_DISABLED 0x00000000 /* disabled */
68 #define D64_XS0_XS_ACTIVE 0x10000000 /* active */
69 #define D64_XS0_XS_IDLE 0x20000000 /* idle wait */
70 #define D64_XS0_XS_STOPPED 0x30000000 /* stopped */
71 #define D64_XS0_XS_SUSP 0x40000000 /* suspend pending */
73 #define D64_XS1_AD_MASK 0x00001fff /* active descriptor */
74 #define D64_XS1_XE_MASK 0xf0000000 /* transmit errors */
75 #define D64_XS1_XE_SHIFT 28
76 #define D64_XS1_XE_NOERR 0x00000000 /* no error */
77 #define D64_XS1_XE_DPE 0x10000000 /* descriptor protocol error */
78 #define D64_XS1_XE_DFU 0x20000000 /* data fifo underrun */
79 #define D64_XS1_XE_DTE 0x30000000 /* data transfer error */
80 #define D64_XS1_XE_DESRE 0x40000000 /* descriptor read error */
81 #define D64_XS1_XE_COREE 0x50000000 /* core error */
83 /* receive channel control */
85 #define D64_RC_RE 0x00000001
86 /* receive frame offset */
87 #define D64_RC_RO_MASK 0x000000fe
88 #define D64_RC_RO_SHIFT 1
89 /* direct fifo receive (pio) mode */
90 #define D64_RC_FM 0x00000100
91 /* separate rx header descriptor enable */
92 #define D64_RC_SH 0x00000200
93 /* overflow continue */
94 #define D64_RC_OC 0x00000400
95 /* parity check disable */
96 #define D64_RC_PD 0x00000800
97 /* address extension bits */
98 #define D64_RC_AE 0x00030000
99 #define D64_RC_AE_SHIFT 16
101 /* flags for dma controller */
103 #define DMA_CTRL_PEN (1 << 0)
104 /* rx overflow continue */
105 #define DMA_CTRL_ROC (1 << 1)
106 /* allow rx scatter to multiple descriptors */
107 #define DMA_CTRL_RXMULTI (1 << 2)
108 /* Unframed Rx/Tx data */
109 #define DMA_CTRL_UNFRAMED (1 << 3)
111 /* receive descriptor table pointer */
112 #define D64_RP_LD_MASK 0x00000fff /* last valid descriptor */
114 /* receive channel status */
115 #define D64_RS0_CD_MASK 0x00001fff /* current descriptor pointer */
116 #define D64_RS0_RS_MASK 0xf0000000 /* receive state */
117 #define D64_RS0_RS_SHIFT 28
118 #define D64_RS0_RS_DISABLED 0x00000000 /* disabled */
119 #define D64_RS0_RS_ACTIVE 0x10000000 /* active */
120 #define D64_RS0_RS_IDLE 0x20000000 /* idle wait */
121 #define D64_RS0_RS_STOPPED 0x30000000 /* stopped */
122 #define D64_RS0_RS_SUSP 0x40000000 /* suspend pending */
124 #define D64_RS1_AD_MASK 0x0001ffff /* active descriptor */
125 #define D64_RS1_RE_MASK 0xf0000000 /* receive errors */
126 #define D64_RS1_RE_SHIFT 28
127 #define D64_RS1_RE_NOERR 0x00000000 /* no error */
128 #define D64_RS1_RE_DPO 0x10000000 /* descriptor protocol error */
129 #define D64_RS1_RE_DFU 0x20000000 /* data fifo overflow */
130 #define D64_RS1_RE_DTE 0x30000000 /* data transfer error */
131 #define D64_RS1_RE_DESRE 0x40000000 /* descriptor read error */
132 #define D64_RS1_RE_COREE 0x50000000 /* core error */
135 #define D64_FA_OFF_MASK 0xffff /* offset */
136 #define D64_FA_SEL_MASK 0xf0000 /* select */
137 #define D64_FA_SEL_SHIFT 16
138 #define D64_FA_SEL_XDD 0x00000 /* transmit dma data */
139 #define D64_FA_SEL_XDP 0x10000 /* transmit dma pointers */
140 #define D64_FA_SEL_RDD 0x40000 /* receive dma data */
141 #define D64_FA_SEL_RDP 0x50000 /* receive dma pointers */
142 #define D64_FA_SEL_XFD 0x80000 /* transmit fifo data */
143 #define D64_FA_SEL_XFP 0x90000 /* transmit fifo pointers */
144 #define D64_FA_SEL_RFD 0xc0000 /* receive fifo data */
145 #define D64_FA_SEL_RFP 0xd0000 /* receive fifo pointers */
146 #define D64_FA_SEL_RSD 0xe0000 /* receive frame status data */
147 #define D64_FA_SEL_RSP 0xf0000 /* receive frame status pointers */
149 /* descriptor control flags 1 */
150 #define D64_CTRL_COREFLAGS 0x0ff00000 /* core specific flags */
151 #define D64_CTRL1_EOT ((u32)1 << 28) /* end of descriptor table */
152 #define D64_CTRL1_IOC ((u32)1 << 29) /* interrupt on completion */
153 #define D64_CTRL1_EOF ((u32)1 << 30) /* end of frame */
154 #define D64_CTRL1_SOF ((u32)1 << 31) /* start of frame */
156 /* descriptor control flags 2 */
157 /* buffer byte count. real data len must <= 16KB */
158 #define D64_CTRL2_BC_MASK 0x00007fff
159 /* address extension bits */
160 #define D64_CTRL2_AE 0x00030000
161 #define D64_CTRL2_AE_SHIFT 16
163 #define D64_CTRL2_PARITY 0x00040000
165 /* control flags in the range [27:20] are core-specific and not defined here */
166 #define D64_CTRL_CORE_MASK 0x0ff00000
168 #define D64_RX_FRM_STS_LEN 0x0000ffff /* frame length mask */
169 #define D64_RX_FRM_STS_OVFL 0x00800000 /* RxOverFlow */
170 #define D64_RX_FRM_STS_DSCRCNT 0x0f000000 /* no. of descriptors used - 1 */
171 #define D64_RX_FRM_STS_DATATYPE 0xf0000000 /* core-dependent data type */
174 * packet headroom necessary to accommodate the largest header
175 * in the system, (i.e TXOFF). By doing, we avoid the need to
176 * allocate an extra buffer for the header when bridging to WL.
177 * There is a compile time check in wlc.c which ensure that this
178 * value is at least as big as TXOFF. This value is used in
182 #define BCMEXTRAHDROOM 172
184 #define MAXNAMEL 8 /* 8 char names */
186 /* macros to convert between byte offsets and indexes */
187 #define B2I(bytes, type) ((bytes) / sizeof(type))
188 #define I2B(index, type) ((index) * sizeof(type))
190 #define PCI32ADDR_HIGH 0xc0000000 /* address[31:30] */
191 #define PCI32ADDR_HIGH_SHIFT 30 /* address[31:30] */
193 #define PCI64ADDR_HIGH 0x80000000 /* address[63] */
194 #define PCI64ADDR_HIGH_SHIFT 31 /* address[63] */
198 * Descriptors are only read by the hardware, never written back.
201 __le32 ctrl1
; /* misc control bits & bufcount */
202 __le32 ctrl2
; /* buffer count and address extension */
203 __le32 addrlow
; /* memory address of the date buffer, bits 31:0 */
204 __le32 addrhigh
; /* memory address of the date buffer, bits 63:32 */
207 /* dma engine software state */
209 struct dma_pub dma
; /* exported structure */
210 char name
[MAXNAMEL
]; /* callers name for diag msgs */
212 struct bcma_device
*core
;
213 struct device
*dmadev
;
215 /* session information for AMPDU */
216 struct brcms_ampdu_session ampdu_session
;
218 bool dma64
; /* this dma engine is operating in 64-bit mode */
219 bool addrext
; /* this dma engine supports DmaExtendedAddrChanges */
221 /* 64-bit dma tx engine registers */
223 /* 64-bit dma rx engine registers */
225 /* pointer to dma64 tx descriptor ring */
226 struct dma64desc
*txd64
;
227 /* pointer to dma64 rx descriptor ring */
228 struct dma64desc
*rxd64
;
230 u16 dmadesc_align
; /* alignment requirement for dma descriptors */
232 u16 ntxd
; /* # tx descriptors tunable */
233 u16 txin
; /* index of next descriptor to reclaim */
234 u16 txout
; /* index of next descriptor to post */
235 /* pointer to parallel array of pointers to packets */
236 struct sk_buff
**txp
;
237 /* Aligned physical address of descriptor ring */
239 /* Original physical address of descriptor ring */
240 dma_addr_t txdpaorig
;
241 u16 txdalign
; /* #bytes added to alloc'd mem to align txd */
242 u32 txdalloc
; /* #bytes allocated for the ring */
243 u32 xmtptrbase
; /* When using unaligned descriptors, the ptr register
244 * is not just an index, it needs all 13 bits to be
245 * an offset from the addr register.
248 u16 nrxd
; /* # rx descriptors tunable */
249 u16 rxin
; /* index of next descriptor to reclaim */
250 u16 rxout
; /* index of next descriptor to post */
251 /* pointer to parallel array of pointers to packets */
252 struct sk_buff
**rxp
;
253 /* Aligned physical address of descriptor ring */
255 /* Original physical address of descriptor ring */
256 dma_addr_t rxdpaorig
;
257 u16 rxdalign
; /* #bytes added to alloc'd mem to align rxd */
258 u32 rxdalloc
; /* #bytes allocated for the ring */
259 u32 rcvptrbase
; /* Base for ptr reg when using unaligned descriptors */
262 unsigned int rxbufsize
; /* rx buffer size in bytes, not including
265 uint rxextrahdrroom
; /* extra rx headroom, reverseved to assist upper
266 * stack, e.g. some rx pkt buffers will be
267 * bridged to tx side without byte copying.
268 * The extra headroom needs to be large enough
269 * to fit txheader needs. Some dongle driver may
272 uint nrxpost
; /* # rx buffers to keep posted */
273 unsigned int rxoffset
; /* rxcontrol offset */
274 /* add to get dma address of descriptor ring, low 32 bits */
278 /* add to get dma address of data buffer, low 32 bits */
282 /* descriptor base need to be aligned or not */
286 /* Check for odd number of 1's */
287 static u32
parity32(__le32 data
)
289 /* no swap needed for counting 1's */
290 u32 par_data
= *(u32
*)&data
;
292 par_data
^= par_data
>> 16;
293 par_data
^= par_data
>> 8;
294 par_data
^= par_data
>> 4;
295 par_data
^= par_data
>> 2;
296 par_data
^= par_data
>> 1;
301 static bool dma64_dd_parity(struct dma64desc
*dd
)
303 return parity32(dd
->addrlow
^ dd
->addrhigh
^ dd
->ctrl1
^ dd
->ctrl2
);
306 /* descriptor bumping functions */
308 static uint
xxd(uint x
, uint n
)
310 return x
& (n
- 1); /* faster than %, but n must be power of 2 */
313 static uint
txd(struct dma_info
*di
, uint x
)
315 return xxd(x
, di
->ntxd
);
318 static uint
rxd(struct dma_info
*di
, uint x
)
320 return xxd(x
, di
->nrxd
);
323 static uint
nexttxd(struct dma_info
*di
, uint i
)
325 return txd(di
, i
+ 1);
328 static uint
prevtxd(struct dma_info
*di
, uint i
)
330 return txd(di
, i
- 1);
333 static uint
nextrxd(struct dma_info
*di
, uint i
)
335 return rxd(di
, i
+ 1);
338 static uint
ntxdactive(struct dma_info
*di
, uint h
, uint t
)
343 static uint
nrxdactive(struct dma_info
*di
, uint h
, uint t
)
348 static uint
_dma_ctrlflags(struct dma_info
*di
, uint mask
, uint flags
)
355 dmactrlflags
= di
->dma
.dmactrlflags
;
356 dmactrlflags
&= ~mask
;
357 dmactrlflags
|= flags
;
359 /* If trying to enable parity, check if parity is actually supported */
360 if (dmactrlflags
& DMA_CTRL_PEN
) {
363 control
= bcma_read32(di
->core
, DMA64TXREGOFFS(di
, control
));
364 bcma_write32(di
->core
, DMA64TXREGOFFS(di
, control
),
365 control
| D64_XC_PD
);
366 if (bcma_read32(di
->core
, DMA64TXREGOFFS(di
, control
)) &
368 /* We *can* disable it so it is supported,
369 * restore control register
371 bcma_write32(di
->core
, DMA64TXREGOFFS(di
, control
),
374 /* Not supported, don't allow it to be enabled */
375 dmactrlflags
&= ~DMA_CTRL_PEN
;
378 di
->dma
.dmactrlflags
= dmactrlflags
;
383 static bool _dma64_addrext(struct dma_info
*di
, uint ctrl_offset
)
386 bcma_set32(di
->core
, ctrl_offset
, D64_XC_AE
);
387 w
= bcma_read32(di
->core
, ctrl_offset
);
388 bcma_mask32(di
->core
, ctrl_offset
, ~D64_XC_AE
);
389 return (w
& D64_XC_AE
) == D64_XC_AE
;
393 * return true if this dma engine supports DmaExtendedAddrChanges,
396 static bool _dma_isaddrext(struct dma_info
*di
)
398 /* DMA64 supports full 32- or 64-bit operation. AE is always valid */
400 /* not all tx or rx channel are available */
401 if (di
->d64txregbase
!= 0) {
402 if (!_dma64_addrext(di
, DMA64TXREGOFFS(di
, control
)))
403 brcms_dbg_dma(di
->core
,
404 "%s: DMA64 tx doesn't have AE set\n",
407 } else if (di
->d64rxregbase
!= 0) {
408 if (!_dma64_addrext(di
, DMA64RXREGOFFS(di
, control
)))
409 brcms_dbg_dma(di
->core
,
410 "%s: DMA64 rx doesn't have AE set\n",
418 static bool _dma_descriptor_align(struct dma_info
*di
)
422 /* Check to see if the descriptors need to be aligned on 4K/8K or not */
423 if (di
->d64txregbase
!= 0) {
424 bcma_write32(di
->core
, DMA64TXREGOFFS(di
, addrlow
), 0xff0);
425 addrl
= bcma_read32(di
->core
, DMA64TXREGOFFS(di
, addrlow
));
428 } else if (di
->d64rxregbase
!= 0) {
429 bcma_write32(di
->core
, DMA64RXREGOFFS(di
, addrlow
), 0xff0);
430 addrl
= bcma_read32(di
->core
, DMA64RXREGOFFS(di
, addrlow
));
438 * Descriptor table must start at the DMA hardware dictated alignment, so
439 * allocated memory must be large enough to support this requirement.
441 static void *dma_alloc_consistent(struct dma_info
*di
, uint size
,
442 u16 align_bits
, uint
*alloced
,
446 u16 align
= (1 << align_bits
);
447 if (!IS_ALIGNED(PAGE_SIZE
, align
))
451 return dma_alloc_coherent(di
->dmadev
, size
, pap
, GFP_ATOMIC
);
455 u8
dma_align_sizetobits(uint size
)
463 /* This function ensures that the DMA descriptor ring will not get allocated
464 * across Page boundary. If the allocation is done across the page boundary
465 * at the first time, then it is freed and the allocation is done at
466 * descriptor ring size aligned location. This will ensure that the ring will
467 * not cross page boundary
469 static void *dma_ringalloc(struct dma_info
*di
, u32 boundary
, uint size
,
470 u16
*alignbits
, uint
*alloced
,
475 u32 alignbytes
= 1 << *alignbits
;
477 va
= dma_alloc_consistent(di
, size
, *alignbits
, alloced
, descpa
);
482 desc_strtaddr
= (u32
) roundup((unsigned long)va
, alignbytes
);
483 if (((desc_strtaddr
+ size
- 1) & boundary
) != (desc_strtaddr
485 *alignbits
= dma_align_sizetobits(size
);
486 dma_free_coherent(di
->dmadev
, size
, va
, *descpa
);
487 va
= dma_alloc_consistent(di
, size
, *alignbits
,
493 static bool dma64_alloc(struct dma_info
*di
, uint direction
)
502 ddlen
= sizeof(struct dma64desc
);
504 size
= (direction
== DMA_TX
) ? (di
->ntxd
* ddlen
) : (di
->nrxd
* ddlen
);
505 align_bits
= di
->dmadesc_align
;
506 align
= (1 << align_bits
);
508 if (direction
== DMA_TX
) {
509 va
= dma_ringalloc(di
, D64RINGALIGN
, size
, &align_bits
,
510 &alloced
, &di
->txdpaorig
);
512 brcms_dbg_dma(di
->core
,
513 "%s: DMA_ALLOC_CONSISTENT(ntxd) failed\n",
517 align
= (1 << align_bits
);
518 di
->txd64
= (struct dma64desc
*)
519 roundup((unsigned long)va
, align
);
520 di
->txdalign
= (uint
) ((s8
*)di
->txd64
- (s8
*) va
);
521 di
->txdpa
= di
->txdpaorig
+ di
->txdalign
;
522 di
->txdalloc
= alloced
;
524 va
= dma_ringalloc(di
, D64RINGALIGN
, size
, &align_bits
,
525 &alloced
, &di
->rxdpaorig
);
527 brcms_dbg_dma(di
->core
,
528 "%s: DMA_ALLOC_CONSISTENT(nrxd) failed\n",
532 align
= (1 << align_bits
);
533 di
->rxd64
= (struct dma64desc
*)
534 roundup((unsigned long)va
, align
);
535 di
->rxdalign
= (uint
) ((s8
*)di
->rxd64
- (s8
*) va
);
536 di
->rxdpa
= di
->rxdpaorig
+ di
->rxdalign
;
537 di
->rxdalloc
= alloced
;
543 static bool _dma_alloc(struct dma_info
*di
, uint direction
)
545 return dma64_alloc(di
, direction
);
548 struct dma_pub
*dma_attach(char *name
, struct brcms_c_info
*wlc
,
549 uint txregbase
, uint rxregbase
, uint ntxd
, uint nrxd
,
550 uint rxbufsize
, int rxextheadroom
,
551 uint nrxpost
, uint rxoffset
)
553 struct si_pub
*sih
= wlc
->hw
->sih
;
554 struct bcma_device
*core
= wlc
->hw
->d11core
;
556 u8 rev
= core
->id
.rev
;
558 struct si_info
*sii
= container_of(sih
, struct si_info
, pub
);
560 /* allocate private info structure */
561 di
= kzalloc(sizeof(struct dma_info
), GFP_ATOMIC
);
566 ((bcma_aread32(core
, BCMA_IOST
) & SISF_DMA64
) == SISF_DMA64
);
568 /* init dma reg info */
570 di
->d64txregbase
= txregbase
;
571 di
->d64rxregbase
= rxregbase
;
574 * Default flags (which can be changed by the driver calling
575 * dma_ctrlflags before enable): For backwards compatibility
576 * both Rx Overflow Continue and Parity are DISABLED.
578 _dma_ctrlflags(di
, DMA_CTRL_ROC
| DMA_CTRL_PEN
, 0);
580 brcms_dbg_dma(di
->core
, "%s: %s flags 0x%x ntxd %d nrxd %d "
581 "rxbufsize %d rxextheadroom %d nrxpost %d rxoffset %d "
582 "txregbase %u rxregbase %u\n", name
, "DMA64",
583 di
->dma
.dmactrlflags
, ntxd
, nrxd
, rxbufsize
,
584 rxextheadroom
, nrxpost
, rxoffset
, txregbase
, rxregbase
);
586 /* make a private copy of our callers name */
587 strncpy(di
->name
, name
, MAXNAMEL
);
588 di
->name
[MAXNAMEL
- 1] = '\0';
590 di
->dmadev
= core
->dma_dev
;
593 di
->ntxd
= (u16
) ntxd
;
594 di
->nrxd
= (u16
) nrxd
;
596 /* the actual dma size doesn't include the extra headroom */
598 (rxextheadroom
== -1) ? BCMEXTRAHDROOM
: rxextheadroom
;
599 if (rxbufsize
> BCMEXTRAHDROOM
)
600 di
->rxbufsize
= (u16
) (rxbufsize
- di
->rxextrahdrroom
);
602 di
->rxbufsize
= (u16
) rxbufsize
;
604 di
->nrxpost
= (u16
) nrxpost
;
605 di
->rxoffset
= (u8
) rxoffset
;
608 * figure out the DMA physical address offset for dd and data
609 * PCI/PCIE: they map silicon backplace address to zero
610 * based memory, need offset
611 * Other bus: use zero SI_BUS BIGENDIAN kludge: use sdram
612 * swapped region for data buffer, not descriptor
615 di
->dataoffsetlow
= 0;
616 /* for pci bus, add offset */
617 if (sii
->icbus
->hosttype
== BCMA_HOSTTYPE_PCI
) {
618 /* add offset for pcie with DMA64 bus */
620 di
->ddoffsethigh
= SI_PCIE_DMA_H32
;
622 di
->dataoffsetlow
= di
->ddoffsetlow
;
623 di
->dataoffsethigh
= di
->ddoffsethigh
;
625 /* WAR64450 : DMACtl.Addr ext fields are not supported in SDIOD core. */
626 if ((core
->id
.id
== BCMA_CORE_SDIO_DEV
)
627 && ((rev
> 0) && (rev
<= 2)))
629 else if ((core
->id
.id
== BCMA_CORE_I2S
) &&
630 ((rev
== 0) || (rev
== 1)))
633 di
->addrext
= _dma_isaddrext(di
);
635 /* does the descriptor need to be aligned and if yes, on 4K/8K or not */
636 di
->aligndesc_4k
= _dma_descriptor_align(di
);
637 if (di
->aligndesc_4k
) {
638 di
->dmadesc_align
= D64RINGALIGN_BITS
;
639 if ((ntxd
< D64MAXDD
/ 2) && (nrxd
< D64MAXDD
/ 2))
640 /* for smaller dd table, HW relax alignment reqmnt */
641 di
->dmadesc_align
= D64RINGALIGN_BITS
- 1;
643 di
->dmadesc_align
= 4; /* 16 byte alignment */
646 brcms_dbg_dma(di
->core
, "DMA descriptor align_needed %d, align %d\n",
647 di
->aligndesc_4k
, di
->dmadesc_align
);
649 /* allocate tx packet pointer vector */
651 size
= ntxd
* sizeof(void *);
652 di
->txp
= kzalloc(size
, GFP_ATOMIC
);
657 /* allocate rx packet pointer vector */
659 size
= nrxd
* sizeof(void *);
660 di
->rxp
= kzalloc(size
, GFP_ATOMIC
);
666 * allocate transmit descriptor ring, only need ntxd descriptors
667 * but it must be aligned
670 if (!_dma_alloc(di
, DMA_TX
))
675 * allocate receive descriptor ring, only need nrxd descriptors
676 * but it must be aligned
679 if (!_dma_alloc(di
, DMA_RX
))
683 if ((di
->ddoffsetlow
!= 0) && !di
->addrext
) {
684 if (di
->txdpa
> SI_PCI_DMA_SZ
) {
685 brcms_dbg_dma(di
->core
,
686 "%s: txdpa 0x%x: addrext not supported\n",
687 di
->name
, (u32
)di
->txdpa
);
690 if (di
->rxdpa
> SI_PCI_DMA_SZ
) {
691 brcms_dbg_dma(di
->core
,
692 "%s: rxdpa 0x%x: addrext not supported\n",
693 di
->name
, (u32
)di
->rxdpa
);
698 /* Initialize AMPDU session */
699 brcms_c_ampdu_reset_session(&di
->ampdu_session
, wlc
);
701 brcms_dbg_dma(di
->core
,
702 "ddoffsetlow 0x%x ddoffsethigh 0x%x dataoffsetlow 0x%x dataoffsethigh 0x%x addrext %d\n",
703 di
->ddoffsetlow
, di
->ddoffsethigh
,
704 di
->dataoffsetlow
, di
->dataoffsethigh
,
707 return (struct dma_pub
*) di
;
710 dma_detach((struct dma_pub
*)di
);
715 dma64_dd_upd(struct dma_info
*di
, struct dma64desc
*ddring
,
716 dma_addr_t pa
, uint outidx
, u32
*flags
, u32 bufcount
)
718 u32 ctrl2
= bufcount
& D64_CTRL2_BC_MASK
;
720 /* PCI bus with big(>1G) physical address, use address extension */
721 if ((di
->dataoffsetlow
== 0) || !(pa
& PCI32ADDR_HIGH
)) {
722 ddring
[outidx
].addrlow
= cpu_to_le32(pa
+ di
->dataoffsetlow
);
723 ddring
[outidx
].addrhigh
= cpu_to_le32(di
->dataoffsethigh
);
724 ddring
[outidx
].ctrl1
= cpu_to_le32(*flags
);
725 ddring
[outidx
].ctrl2
= cpu_to_le32(ctrl2
);
727 /* address extension for 32-bit PCI */
730 ae
= (pa
& PCI32ADDR_HIGH
) >> PCI32ADDR_HIGH_SHIFT
;
731 pa
&= ~PCI32ADDR_HIGH
;
733 ctrl2
|= (ae
<< D64_CTRL2_AE_SHIFT
) & D64_CTRL2_AE
;
734 ddring
[outidx
].addrlow
= cpu_to_le32(pa
+ di
->dataoffsetlow
);
735 ddring
[outidx
].addrhigh
= cpu_to_le32(di
->dataoffsethigh
);
736 ddring
[outidx
].ctrl1
= cpu_to_le32(*flags
);
737 ddring
[outidx
].ctrl2
= cpu_to_le32(ctrl2
);
739 if (di
->dma
.dmactrlflags
& DMA_CTRL_PEN
) {
740 if (dma64_dd_parity(&ddring
[outidx
]))
741 ddring
[outidx
].ctrl2
=
742 cpu_to_le32(ctrl2
| D64_CTRL2_PARITY
);
746 /* !! may be called with core in reset */
747 void dma_detach(struct dma_pub
*pub
)
749 struct dma_info
*di
= (struct dma_info
*)pub
;
751 brcms_dbg_dma(di
->core
, "%s:\n", di
->name
);
753 /* free dma descriptor rings */
755 dma_free_coherent(di
->dmadev
, di
->txdalloc
,
756 ((s8
*)di
->txd64
- di
->txdalign
),
759 dma_free_coherent(di
->dmadev
, di
->rxdalloc
,
760 ((s8
*)di
->rxd64
- di
->rxdalign
),
763 /* free packet pointer vectors */
767 /* free our private info structure */
772 /* initialize descriptor table base address */
774 _dma_ddtable_init(struct dma_info
*di
, uint direction
, dma_addr_t pa
)
776 if (!di
->aligndesc_4k
) {
777 if (direction
== DMA_TX
)
783 if ((di
->ddoffsetlow
== 0)
784 || !(pa
& PCI32ADDR_HIGH
)) {
785 if (direction
== DMA_TX
) {
786 bcma_write32(di
->core
, DMA64TXREGOFFS(di
, addrlow
),
787 pa
+ di
->ddoffsetlow
);
788 bcma_write32(di
->core
, DMA64TXREGOFFS(di
, addrhigh
),
791 bcma_write32(di
->core
, DMA64RXREGOFFS(di
, addrlow
),
792 pa
+ di
->ddoffsetlow
);
793 bcma_write32(di
->core
, DMA64RXREGOFFS(di
, addrhigh
),
797 /* DMA64 32bits address extension */
800 /* shift the high bit(s) from pa to ae */
801 ae
= (pa
& PCI32ADDR_HIGH
) >> PCI32ADDR_HIGH_SHIFT
;
802 pa
&= ~PCI32ADDR_HIGH
;
804 if (direction
== DMA_TX
) {
805 bcma_write32(di
->core
, DMA64TXREGOFFS(di
, addrlow
),
806 pa
+ di
->ddoffsetlow
);
807 bcma_write32(di
->core
, DMA64TXREGOFFS(di
, addrhigh
),
809 bcma_maskset32(di
->core
, DMA64TXREGOFFS(di
, control
),
810 D64_XC_AE
, (ae
<< D64_XC_AE_SHIFT
));
812 bcma_write32(di
->core
, DMA64RXREGOFFS(di
, addrlow
),
813 pa
+ di
->ddoffsetlow
);
814 bcma_write32(di
->core
, DMA64RXREGOFFS(di
, addrhigh
),
816 bcma_maskset32(di
->core
, DMA64RXREGOFFS(di
, control
),
817 D64_RC_AE
, (ae
<< D64_RC_AE_SHIFT
));
822 static void _dma_rxenable(struct dma_info
*di
)
824 uint dmactrlflags
= di
->dma
.dmactrlflags
;
827 brcms_dbg_dma(di
->core
, "%s:\n", di
->name
);
829 control
= D64_RC_RE
| (bcma_read32(di
->core
,
830 DMA64RXREGOFFS(di
, control
)) &
833 if ((dmactrlflags
& DMA_CTRL_PEN
) == 0)
834 control
|= D64_RC_PD
;
836 if (dmactrlflags
& DMA_CTRL_ROC
)
837 control
|= D64_RC_OC
;
839 bcma_write32(di
->core
, DMA64RXREGOFFS(di
, control
),
840 ((di
->rxoffset
<< D64_RC_RO_SHIFT
) | control
));
843 void dma_rxinit(struct dma_pub
*pub
)
845 struct dma_info
*di
= (struct dma_info
*)pub
;
847 brcms_dbg_dma(di
->core
, "%s:\n", di
->name
);
852 di
->rxin
= di
->rxout
= 0;
854 /* clear rx descriptor ring */
855 memset(di
->rxd64
, '\0', di
->nrxd
* sizeof(struct dma64desc
));
857 /* DMA engine with out alignment requirement requires table to be inited
858 * before enabling the engine
860 if (!di
->aligndesc_4k
)
861 _dma_ddtable_init(di
, DMA_RX
, di
->rxdpa
);
865 if (di
->aligndesc_4k
)
866 _dma_ddtable_init(di
, DMA_RX
, di
->rxdpa
);
869 static struct sk_buff
*dma64_getnextrxp(struct dma_info
*di
, bool forceall
)
877 /* return if no packets posted */
882 B2I(((bcma_read32(di
->core
,
883 DMA64RXREGOFFS(di
, status0
)) & D64_RS0_CD_MASK
) -
884 di
->rcvptrbase
) & D64_RS0_CD_MASK
, struct dma64desc
);
886 /* ignore curr if forceall */
887 if (!forceall
&& (i
== curr
))
890 /* get the packet pointer that corresponds to the rx descriptor */
894 pa
= le32_to_cpu(di
->rxd64
[i
].addrlow
) - di
->dataoffsetlow
;
896 /* clear this packet from the descriptor ring */
897 dma_unmap_single(di
->dmadev
, pa
, di
->rxbufsize
, DMA_FROM_DEVICE
);
899 di
->rxd64
[i
].addrlow
= cpu_to_le32(0xdeadbeef);
900 di
->rxd64
[i
].addrhigh
= cpu_to_le32(0xdeadbeef);
902 di
->rxin
= nextrxd(di
, i
);
907 static struct sk_buff
*_dma_getnextrxp(struct dma_info
*di
, bool forceall
)
912 return dma64_getnextrxp(di
, forceall
);
916 * !! rx entry routine
917 * returns the number packages in the next frame, or 0 if there are no more
918 * if DMA_CTRL_RXMULTI is defined, DMA scattering(multiple buffers) is
919 * supported with pkts chain
920 * otherwise, it's treated as giant pkt and will be tossed.
921 * The DMA scattering starts with normal DMA header, followed by first
922 * buffer data. After it reaches the max size of buffer, the data continues
923 * in next DMA descriptor buffer WITHOUT DMA header
925 int dma_rx(struct dma_pub
*pub
, struct sk_buff_head
*skb_list
)
927 struct dma_info
*di
= (struct dma_info
*)pub
;
928 struct sk_buff_head dma_frames
;
929 struct sk_buff
*p
, *next
;
935 skb_queue_head_init(&dma_frames
);
937 p
= _dma_getnextrxp(di
, false);
941 len
= le16_to_cpu(*(__le16
*) (p
->data
));
942 brcms_dbg_dma(di
->core
, "%s: dma_rx len %d\n", di
->name
, len
);
943 dma_spin_for_len(len
, p
);
945 /* set actual length */
946 pkt_len
= min((di
->rxoffset
+ len
), di
->rxbufsize
);
947 __skb_trim(p
, pkt_len
);
948 skb_queue_tail(&dma_frames
, p
);
949 resid
= len
- (di
->rxbufsize
- di
->rxoffset
);
951 /* check for single or multi-buffer rx */
953 while ((resid
> 0) && (p
= _dma_getnextrxp(di
, false))) {
954 pkt_len
= min_t(uint
, resid
, di
->rxbufsize
);
955 __skb_trim(p
, pkt_len
);
956 skb_queue_tail(&dma_frames
, p
);
957 resid
-= di
->rxbufsize
;
965 B2I(((bcma_read32(di
->core
,
966 DMA64RXREGOFFS(di
, status0
)) &
967 D64_RS0_CD_MASK
) - di
->rcvptrbase
) &
968 D64_RS0_CD_MASK
, struct dma64desc
);
969 brcms_dbg_dma(di
->core
,
970 "rxin %d rxout %d, hw_curr %d\n",
971 di
->rxin
, di
->rxout
, cur
);
975 if ((di
->dma
.dmactrlflags
& DMA_CTRL_RXMULTI
) == 0) {
976 brcms_dbg_dma(di
->core
, "%s: bad frame length (%d)\n",
978 skb_queue_walk_safe(&dma_frames
, p
, next
) {
979 skb_unlink(p
, &dma_frames
);
980 brcmu_pkt_buf_free_skb(p
);
988 skb_queue_splice_tail(&dma_frames
, skb_list
);
992 static bool dma64_rxidle(struct dma_info
*di
)
994 brcms_dbg_dma(di
->core
, "%s:\n", di
->name
);
999 return ((bcma_read32(di
->core
,
1000 DMA64RXREGOFFS(di
, status0
)) & D64_RS0_CD_MASK
) ==
1001 (bcma_read32(di
->core
, DMA64RXREGOFFS(di
, ptr
)) &
1005 static bool dma64_txidle(struct dma_info
*di
)
1010 return ((bcma_read32(di
->core
,
1011 DMA64TXREGOFFS(di
, status0
)) & D64_XS0_CD_MASK
) ==
1012 (bcma_read32(di
->core
, DMA64TXREGOFFS(di
, ptr
)) &
1017 * post receive buffers
1018 * Return false if refill failed completely or dma mapping failed. The ring
1019 * is empty, which will stall the rx dma and user might want to call rxfill
1020 * again asap. This is unlikely to happen on a memory-rich NIC, but often on
1021 * memory-constrained dongle.
1023 bool dma_rxfill(struct dma_pub
*pub
)
1025 struct dma_info
*di
= (struct dma_info
*)pub
;
1032 uint extra_offset
= 0;
1038 * Determine how many receive buffers we're lacking
1039 * from the full complement, allocate, initialize,
1040 * and post them, then update the chip rx lastdscr.
1046 n
= di
->nrxpost
- nrxdactive(di
, rxin
, rxout
);
1048 brcms_dbg_dma(di
->core
, "%s: post %d\n", di
->name
, n
);
1050 if (di
->rxbufsize
> BCMEXTRAHDROOM
)
1051 extra_offset
= di
->rxextrahdrroom
;
1053 for (i
= 0; i
< n
; i
++) {
1055 * the di->rxbufsize doesn't include the extra headroom,
1056 * we need to add it to the size to be allocated
1058 p
= brcmu_pkt_buf_get_skb(di
->rxbufsize
+ extra_offset
);
1061 brcms_dbg_dma(di
->core
, "%s: out of rxbufs\n",
1063 if (i
== 0 && dma64_rxidle(di
)) {
1064 brcms_dbg_dma(di
->core
, "%s: ring is empty !\n",
1071 /* reserve an extra headroom, if applicable */
1073 skb_pull(p
, extra_offset
);
1075 /* Do a cached write instead of uncached write since DMA_MAP
1076 * will flush the cache.
1078 *(u32
*) (p
->data
) = 0;
1080 pa
= dma_map_single(di
->dmadev
, p
->data
, di
->rxbufsize
,
1082 if (dma_mapping_error(di
->dmadev
, pa
))
1085 /* save the free packet pointer */
1088 /* reset flags for each descriptor */
1090 if (rxout
== (di
->nrxd
- 1))
1091 flags
= D64_CTRL1_EOT
;
1093 dma64_dd_upd(di
, di
->rxd64
, pa
, rxout
, &flags
,
1095 rxout
= nextrxd(di
, rxout
);
1100 /* update the chip lastdscr pointer */
1101 bcma_write32(di
->core
, DMA64RXREGOFFS(di
, ptr
),
1102 di
->rcvptrbase
+ I2B(rxout
, struct dma64desc
));
1107 void dma_rxreclaim(struct dma_pub
*pub
)
1109 struct dma_info
*di
= (struct dma_info
*)pub
;
1112 brcms_dbg_dma(di
->core
, "%s:\n", di
->name
);
1114 while ((p
= _dma_getnextrxp(di
, true)))
1115 brcmu_pkt_buf_free_skb(p
);
1118 void dma_counterreset(struct dma_pub
*pub
)
1120 /* reset all software counters */
1126 /* get the address of the var in order to change later */
1127 unsigned long dma_getvar(struct dma_pub
*pub
, const char *name
)
1129 struct dma_info
*di
= (struct dma_info
*)pub
;
1131 if (!strcmp(name
, "&txavail"))
1132 return (unsigned long)&(di
->dma
.txavail
);
1136 /* 64-bit DMA functions */
1138 void dma_txinit(struct dma_pub
*pub
)
1140 struct dma_info
*di
= (struct dma_info
*)pub
;
1141 u32 control
= D64_XC_XE
;
1143 brcms_dbg_dma(di
->core
, "%s:\n", di
->name
);
1148 di
->txin
= di
->txout
= 0;
1149 di
->dma
.txavail
= di
->ntxd
- 1;
1151 /* clear tx descriptor ring */
1152 memset(di
->txd64
, '\0', (di
->ntxd
* sizeof(struct dma64desc
)));
1154 /* DMA engine with out alignment requirement requires table to be inited
1155 * before enabling the engine
1157 if (!di
->aligndesc_4k
)
1158 _dma_ddtable_init(di
, DMA_TX
, di
->txdpa
);
1160 if ((di
->dma
.dmactrlflags
& DMA_CTRL_PEN
) == 0)
1161 control
|= D64_XC_PD
;
1162 bcma_set32(di
->core
, DMA64TXREGOFFS(di
, control
), control
);
1164 /* DMA engine with alignment requirement requires table to be inited
1165 * before enabling the engine
1167 if (di
->aligndesc_4k
)
1168 _dma_ddtable_init(di
, DMA_TX
, di
->txdpa
);
1171 void dma_txsuspend(struct dma_pub
*pub
)
1173 struct dma_info
*di
= (struct dma_info
*)pub
;
1175 brcms_dbg_dma(di
->core
, "%s:\n", di
->name
);
1180 bcma_set32(di
->core
, DMA64TXREGOFFS(di
, control
), D64_XC_SE
);
1183 void dma_txresume(struct dma_pub
*pub
)
1185 struct dma_info
*di
= (struct dma_info
*)pub
;
1187 brcms_dbg_dma(di
->core
, "%s:\n", di
->name
);
1192 bcma_mask32(di
->core
, DMA64TXREGOFFS(di
, control
), ~D64_XC_SE
);
1195 bool dma_txsuspended(struct dma_pub
*pub
)
1197 struct dma_info
*di
= (struct dma_info
*)pub
;
1199 return (di
->ntxd
== 0) ||
1200 ((bcma_read32(di
->core
,
1201 DMA64TXREGOFFS(di
, control
)) & D64_XC_SE
) ==
1205 void dma_txreclaim(struct dma_pub
*pub
, enum txd_range range
)
1207 struct dma_info
*di
= (struct dma_info
*)pub
;
1210 brcms_dbg_dma(di
->core
, "%s: %s\n",
1212 range
== DMA_RANGE_ALL
? "all" :
1213 range
== DMA_RANGE_TRANSMITTED
? "transmitted" :
1216 if (di
->txin
== di
->txout
)
1219 while ((p
= dma_getnexttxp(pub
, range
))) {
1220 /* For unframed data, we don't have any packets to free */
1221 if (!(di
->dma
.dmactrlflags
& DMA_CTRL_UNFRAMED
))
1222 brcmu_pkt_buf_free_skb(p
);
1226 bool dma_txreset(struct dma_pub
*pub
)
1228 struct dma_info
*di
= (struct dma_info
*)pub
;
1234 /* suspend tx DMA first */
1235 bcma_write32(di
->core
, DMA64TXREGOFFS(di
, control
), D64_XC_SE
);
1237 (bcma_read32(di
->core
, DMA64TXREGOFFS(di
, status0
)) &
1238 D64_XS0_XS_MASK
)) != D64_XS0_XS_DISABLED
) &&
1239 (status
!= D64_XS0_XS_IDLE
) && (status
!= D64_XS0_XS_STOPPED
),
1242 bcma_write32(di
->core
, DMA64TXREGOFFS(di
, control
), 0);
1244 (bcma_read32(di
->core
, DMA64TXREGOFFS(di
, status0
)) &
1245 D64_XS0_XS_MASK
)) != D64_XS0_XS_DISABLED
), 10000);
1247 /* wait for the last transaction to complete */
1250 return status
== D64_XS0_XS_DISABLED
;
1253 bool dma_rxreset(struct dma_pub
*pub
)
1255 struct dma_info
*di
= (struct dma_info
*)pub
;
1261 bcma_write32(di
->core
, DMA64RXREGOFFS(di
, control
), 0);
1263 (bcma_read32(di
->core
, DMA64RXREGOFFS(di
, status0
)) &
1264 D64_RS0_RS_MASK
)) != D64_RS0_RS_DISABLED
), 10000);
1266 return status
== D64_RS0_RS_DISABLED
;
1269 static void dma_txenq(struct dma_info
*di
, struct sk_buff
*p
)
1271 unsigned char *data
;
1279 if (WARN_ON(nexttxd(di
, txout
) == di
->txin
))
1283 * obtain and initialize transmit descriptor entry.
1288 /* get physical address of buffer start */
1289 pa
= dma_map_single(di
->dmadev
, data
, len
, DMA_TO_DEVICE
);
1290 /* if mapping failed, free skb */
1291 if (dma_mapping_error(di
->dmadev
, pa
)) {
1292 brcmu_pkt_buf_free_skb(p
);
1295 /* With a DMA segment list, Descriptor table is filled
1296 * using the segment list instead of looping over
1297 * buffers in multi-chain DMA. Therefore, EOF for SGLIST
1298 * is when end of segment list is reached.
1300 flags
= D64_CTRL1_SOF
| D64_CTRL1_IOC
| D64_CTRL1_EOF
;
1301 if (txout
== (di
->ntxd
- 1))
1302 flags
|= D64_CTRL1_EOT
;
1304 dma64_dd_upd(di
, di
->txd64
, pa
, txout
, &flags
, len
);
1306 txout
= nexttxd(di
, txout
);
1308 /* save the packet */
1309 di
->txp
[prevtxd(di
, txout
)] = p
;
1311 /* bump the tx descriptor index */
1315 static void ampdu_finalize(struct dma_info
*di
)
1317 struct brcms_ampdu_session
*session
= &di
->ampdu_session
;
1320 trace_brcms_ampdu_session(&session
->wlc
->hw
->d11core
->dev
,
1321 session
->max_ampdu_len
,
1322 session
->max_ampdu_frames
,
1324 skb_queue_len(&session
->skb_list
),
1327 if (WARN_ON(skb_queue_empty(&session
->skb_list
)))
1330 brcms_c_ampdu_finalize(session
);
1332 while (!skb_queue_empty(&session
->skb_list
)) {
1333 p
= skb_dequeue(&session
->skb_list
);
1337 bcma_write32(di
->core
, DMA64TXREGOFFS(di
, ptr
),
1338 di
->xmtptrbase
+ I2B(di
->txout
, struct dma64desc
));
1339 brcms_c_ampdu_reset_session(session
, session
->wlc
);
1342 static void prep_ampdu_frame(struct dma_info
*di
, struct sk_buff
*p
)
1344 struct brcms_ampdu_session
*session
= &di
->ampdu_session
;
1347 ret
= brcms_c_ampdu_add_frame(session
, p
);
1348 if (ret
== -ENOSPC
) {
1350 * AMPDU cannot accomodate this frame. Close out the in-
1351 * progress AMPDU session and start a new one.
1354 ret
= brcms_c_ampdu_add_frame(session
, p
);
1360 /* Update count of available tx descriptors based on current DMA state */
1361 static void dma_update_txavail(struct dma_info
*di
)
1364 * Available space is number of descriptors less the number of
1365 * active descriptors and the number of queued AMPDU frames.
1367 di
->dma
.txavail
= di
->ntxd
- ntxdactive(di
, di
->txin
, di
->txout
) -
1368 skb_queue_len(&di
->ampdu_session
.skb_list
) - 1;
1372 * !! tx entry routine
1373 * WARNING: call must check the return value for error.
1374 * the error(toss frames) could be fatal and cause many subsequent hard
1377 int dma_txfast(struct brcms_c_info
*wlc
, struct dma_pub
*pub
,
1380 struct dma_info
*di
= (struct dma_info
*)pub
;
1381 struct brcms_ampdu_session
*session
= &di
->ampdu_session
;
1382 struct ieee80211_tx_info
*tx_info
;
1385 /* no use to transmit a zero length packet */
1389 /* return nonzero if out of tx descriptors */
1390 if (di
->dma
.txavail
== 0 || nexttxd(di
, di
->txout
) == di
->txin
)
1393 tx_info
= IEEE80211_SKB_CB(p
);
1394 is_ampdu
= tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
;
1396 prep_ampdu_frame(di
, p
);
1400 /* tx flow control */
1401 dma_update_txavail(di
);
1406 * Start sending data if we've got a full AMPDU, there's
1407 * no more space in the DMA ring, or the ring isn't
1408 * currently transmitting.
1410 if (skb_queue_len(&session
->skb_list
) == session
->max_ampdu_frames
||
1411 di
->dma
.txavail
== 0 || dma64_txidle(di
))
1414 bcma_write32(di
->core
, DMA64TXREGOFFS(di
, ptr
),
1415 di
->xmtptrbase
+ I2B(di
->txout
, struct dma64desc
));
1421 brcms_dbg_dma(di
->core
, "%s: out of txds !!!\n", di
->name
);
1422 brcmu_pkt_buf_free_skb(p
);
1423 di
->dma
.txavail
= 0;
1428 void dma_txflush(struct dma_pub
*pub
)
1430 struct dma_info
*di
= (struct dma_info
*)pub
;
1431 struct brcms_ampdu_session
*session
= &di
->ampdu_session
;
1433 if (!skb_queue_empty(&session
->skb_list
))
1437 int dma_txpending(struct dma_pub
*pub
)
1439 struct dma_info
*di
= (struct dma_info
*)pub
;
1440 return ntxdactive(di
, di
->txin
, di
->txout
);
1444 * If we have an active AMPDU session and are not transmitting,
1445 * this function will force tx to start.
1447 void dma_kick_tx(struct dma_pub
*pub
)
1449 struct dma_info
*di
= (struct dma_info
*)pub
;
1450 struct brcms_ampdu_session
*session
= &di
->ampdu_session
;
1452 if (!skb_queue_empty(&session
->skb_list
) && dma64_txidle(di
))
1457 * Reclaim next completed txd (txds if using chained buffers) in the range
1458 * specified and return associated packet.
1459 * If range is DMA_RANGE_TRANSMITTED, reclaim descriptors that have be
1460 * transmitted as noted by the hardware "CurrDescr" pointer.
1461 * If range is DMA_RANGE_TRANSFERED, reclaim descriptors that have be
1462 * transferred by the DMA as noted by the hardware "ActiveDescr" pointer.
1463 * If range is DMA_RANGE_ALL, reclaim all txd(s) posted to the ring and
1464 * return associated packet regardless of the value of hardware pointers.
1466 struct sk_buff
*dma_getnexttxp(struct dma_pub
*pub
, enum txd_range range
)
1468 struct dma_info
*di
= (struct dma_info
*)pub
;
1471 struct sk_buff
*txp
;
1473 brcms_dbg_dma(di
->core
, "%s: %s\n",
1475 range
== DMA_RANGE_ALL
? "all" :
1476 range
== DMA_RANGE_TRANSMITTED
? "transmitted" :
1485 if (range
== DMA_RANGE_ALL
)
1488 end
= (u16
) (B2I(((bcma_read32(di
->core
,
1489 DMA64TXREGOFFS(di
, status0
)) &
1490 D64_XS0_CD_MASK
) - di
->xmtptrbase
) &
1491 D64_XS0_CD_MASK
, struct dma64desc
));
1493 if (range
== DMA_RANGE_TRANSFERED
) {
1495 (u16
)(bcma_read32(di
->core
,
1496 DMA64TXREGOFFS(di
, status1
)) &
1499 (active_desc
- di
->xmtptrbase
) & D64_XS0_CD_MASK
;
1500 active_desc
= B2I(active_desc
, struct dma64desc
);
1501 if (end
!= active_desc
)
1502 end
= prevtxd(di
, active_desc
);
1506 if ((start
== 0) && (end
> di
->txout
))
1509 for (i
= start
; i
!= end
&& !txp
; i
= nexttxd(di
, i
)) {
1513 pa
= le32_to_cpu(di
->txd64
[i
].addrlow
) - di
->dataoffsetlow
;
1516 (le32_to_cpu(di
->txd64
[i
].ctrl2
) &
1519 di
->txd64
[i
].addrlow
= cpu_to_le32(0xdeadbeef);
1520 di
->txd64
[i
].addrhigh
= cpu_to_le32(0xdeadbeef);
1525 dma_unmap_single(di
->dmadev
, pa
, size
, DMA_TO_DEVICE
);
1530 /* tx flow control */
1531 dma_update_txavail(di
);
1536 brcms_dbg_dma(di
->core
, "bogus curr: start %d end %d txout %d\n",
1537 start
, end
, di
->txout
);
1542 * Mac80211 initiated actions sometimes require packets in the DMA queue to be
1543 * modified. The modified portion of the packet is not under control of the DMA
1544 * engine. This function calls a caller-supplied function for each packet in
1545 * the caller specified dma chain.
1547 void dma_walk_packets(struct dma_pub
*dmah
, void (*callback_fnc
)
1548 (void *pkt
, void *arg_a
), void *arg_a
)
1550 struct dma_info
*di
= (struct dma_info
*) dmah
;
1552 uint end
= di
->txout
;
1553 struct sk_buff
*skb
;
1554 struct ieee80211_tx_info
*tx_info
;
1559 tx_info
= (struct ieee80211_tx_info
*)skb
->cb
;
1560 (callback_fnc
)(tx_info
, arg_a
);