3 Broadcom B43legacy wireless driver
5 DMA ringbuffer and descriptor allocation/management
7 Copyright (c) 2005, 2006 Michael Buesch <m@bues.ch>
9 Some code in this file is derived from the b44.c driver
10 Copyright (C) 2002 David S. Miller
11 Copyright (C) Pekka Pietikainen
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; see the file COPYING. If not, write to
25 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
26 Boston, MA 02110-1301, USA.
30 #include "b43legacy.h"
36 #include <linux/dma-mapping.h>
37 #include <linux/pci.h>
38 #include <linux/delay.h>
39 #include <linux/skbuff.h>
40 #include <linux/slab.h>
45 struct b43legacy_dmadesc_generic
*op32_idx2desc(
46 struct b43legacy_dmaring
*ring
,
48 struct b43legacy_dmadesc_meta
**meta
)
50 struct b43legacy_dmadesc32
*desc
;
52 *meta
= &(ring
->meta
[slot
]);
53 desc
= ring
->descbase
;
56 return (struct b43legacy_dmadesc_generic
*)desc
;
59 static void op32_fill_descriptor(struct b43legacy_dmaring
*ring
,
60 struct b43legacy_dmadesc_generic
*desc
,
61 dma_addr_t dmaaddr
, u16 bufsize
,
62 int start
, int end
, int irq
)
64 struct b43legacy_dmadesc32
*descbase
= ring
->descbase
;
70 slot
= (int)(&(desc
->dma32
) - descbase
);
71 B43legacy_WARN_ON(!(slot
>= 0 && slot
< ring
->nr_slots
));
73 addr
= (u32
)(dmaaddr
& ~SSB_DMA_TRANSLATION_MASK
);
74 addrext
= (u32
)(dmaaddr
& SSB_DMA_TRANSLATION_MASK
)
75 >> SSB_DMA_TRANSLATION_SHIFT
;
76 addr
|= ring
->dev
->dma
.translation
;
77 ctl
= (bufsize
- ring
->frameoffset
)
78 & B43legacy_DMA32_DCTL_BYTECNT
;
79 if (slot
== ring
->nr_slots
- 1)
80 ctl
|= B43legacy_DMA32_DCTL_DTABLEEND
;
82 ctl
|= B43legacy_DMA32_DCTL_FRAMESTART
;
84 ctl
|= B43legacy_DMA32_DCTL_FRAMEEND
;
86 ctl
|= B43legacy_DMA32_DCTL_IRQ
;
87 ctl
|= (addrext
<< B43legacy_DMA32_DCTL_ADDREXT_SHIFT
)
88 & B43legacy_DMA32_DCTL_ADDREXT_MASK
;
90 desc
->dma32
.control
= cpu_to_le32(ctl
);
91 desc
->dma32
.address
= cpu_to_le32(addr
);
94 static void op32_poke_tx(struct b43legacy_dmaring
*ring
, int slot
)
96 b43legacy_dma_write(ring
, B43legacy_DMA32_TXINDEX
,
97 (u32
)(slot
* sizeof(struct b43legacy_dmadesc32
)));
100 static void op32_tx_suspend(struct b43legacy_dmaring
*ring
)
102 b43legacy_dma_write(ring
, B43legacy_DMA32_TXCTL
,
103 b43legacy_dma_read(ring
, B43legacy_DMA32_TXCTL
)
104 | B43legacy_DMA32_TXSUSPEND
);
107 static void op32_tx_resume(struct b43legacy_dmaring
*ring
)
109 b43legacy_dma_write(ring
, B43legacy_DMA32_TXCTL
,
110 b43legacy_dma_read(ring
, B43legacy_DMA32_TXCTL
)
111 & ~B43legacy_DMA32_TXSUSPEND
);
114 static int op32_get_current_rxslot(struct b43legacy_dmaring
*ring
)
118 val
= b43legacy_dma_read(ring
, B43legacy_DMA32_RXSTATUS
);
119 val
&= B43legacy_DMA32_RXDPTR
;
121 return (val
/ sizeof(struct b43legacy_dmadesc32
));
124 static void op32_set_current_rxslot(struct b43legacy_dmaring
*ring
,
127 b43legacy_dma_write(ring
, B43legacy_DMA32_RXINDEX
,
128 (u32
)(slot
* sizeof(struct b43legacy_dmadesc32
)));
131 static const struct b43legacy_dma_ops dma32_ops
= {
132 .idx2desc
= op32_idx2desc
,
133 .fill_descriptor
= op32_fill_descriptor
,
134 .poke_tx
= op32_poke_tx
,
135 .tx_suspend
= op32_tx_suspend
,
136 .tx_resume
= op32_tx_resume
,
137 .get_current_rxslot
= op32_get_current_rxslot
,
138 .set_current_rxslot
= op32_set_current_rxslot
,
143 struct b43legacy_dmadesc_generic
*op64_idx2desc(
144 struct b43legacy_dmaring
*ring
,
146 struct b43legacy_dmadesc_meta
149 struct b43legacy_dmadesc64
*desc
;
151 *meta
= &(ring
->meta
[slot
]);
152 desc
= ring
->descbase
;
153 desc
= &(desc
[slot
]);
155 return (struct b43legacy_dmadesc_generic
*)desc
;
158 static void op64_fill_descriptor(struct b43legacy_dmaring
*ring
,
159 struct b43legacy_dmadesc_generic
*desc
,
160 dma_addr_t dmaaddr
, u16 bufsize
,
161 int start
, int end
, int irq
)
163 struct b43legacy_dmadesc64
*descbase
= ring
->descbase
;
171 slot
= (int)(&(desc
->dma64
) - descbase
);
172 B43legacy_WARN_ON(!(slot
>= 0 && slot
< ring
->nr_slots
));
174 addrlo
= (u32
)(dmaaddr
& 0xFFFFFFFF);
175 addrhi
= (((u64
)dmaaddr
>> 32) & ~SSB_DMA_TRANSLATION_MASK
);
176 addrext
= (((u64
)dmaaddr
>> 32) & SSB_DMA_TRANSLATION_MASK
)
177 >> SSB_DMA_TRANSLATION_SHIFT
;
178 addrhi
|= ring
->dev
->dma
.translation
;
179 if (slot
== ring
->nr_slots
- 1)
180 ctl0
|= B43legacy_DMA64_DCTL0_DTABLEEND
;
182 ctl0
|= B43legacy_DMA64_DCTL0_FRAMESTART
;
184 ctl0
|= B43legacy_DMA64_DCTL0_FRAMEEND
;
186 ctl0
|= B43legacy_DMA64_DCTL0_IRQ
;
187 ctl1
|= (bufsize
- ring
->frameoffset
)
188 & B43legacy_DMA64_DCTL1_BYTECNT
;
189 ctl1
|= (addrext
<< B43legacy_DMA64_DCTL1_ADDREXT_SHIFT
)
190 & B43legacy_DMA64_DCTL1_ADDREXT_MASK
;
192 desc
->dma64
.control0
= cpu_to_le32(ctl0
);
193 desc
->dma64
.control1
= cpu_to_le32(ctl1
);
194 desc
->dma64
.address_low
= cpu_to_le32(addrlo
);
195 desc
->dma64
.address_high
= cpu_to_le32(addrhi
);
198 static void op64_poke_tx(struct b43legacy_dmaring
*ring
, int slot
)
200 b43legacy_dma_write(ring
, B43legacy_DMA64_TXINDEX
,
201 (u32
)(slot
* sizeof(struct b43legacy_dmadesc64
)));
204 static void op64_tx_suspend(struct b43legacy_dmaring
*ring
)
206 b43legacy_dma_write(ring
, B43legacy_DMA64_TXCTL
,
207 b43legacy_dma_read(ring
, B43legacy_DMA64_TXCTL
)
208 | B43legacy_DMA64_TXSUSPEND
);
211 static void op64_tx_resume(struct b43legacy_dmaring
*ring
)
213 b43legacy_dma_write(ring
, B43legacy_DMA64_TXCTL
,
214 b43legacy_dma_read(ring
, B43legacy_DMA64_TXCTL
)
215 & ~B43legacy_DMA64_TXSUSPEND
);
218 static int op64_get_current_rxslot(struct b43legacy_dmaring
*ring
)
222 val
= b43legacy_dma_read(ring
, B43legacy_DMA64_RXSTATUS
);
223 val
&= B43legacy_DMA64_RXSTATDPTR
;
225 return (val
/ sizeof(struct b43legacy_dmadesc64
));
228 static void op64_set_current_rxslot(struct b43legacy_dmaring
*ring
,
231 b43legacy_dma_write(ring
, B43legacy_DMA64_RXINDEX
,
232 (u32
)(slot
* sizeof(struct b43legacy_dmadesc64
)));
235 static const struct b43legacy_dma_ops dma64_ops
= {
236 .idx2desc
= op64_idx2desc
,
237 .fill_descriptor
= op64_fill_descriptor
,
238 .poke_tx
= op64_poke_tx
,
239 .tx_suspend
= op64_tx_suspend
,
240 .tx_resume
= op64_tx_resume
,
241 .get_current_rxslot
= op64_get_current_rxslot
,
242 .set_current_rxslot
= op64_set_current_rxslot
,
246 static inline int free_slots(struct b43legacy_dmaring
*ring
)
248 return (ring
->nr_slots
- ring
->used_slots
);
251 static inline int next_slot(struct b43legacy_dmaring
*ring
, int slot
)
253 B43legacy_WARN_ON(!(slot
>= -1 && slot
<= ring
->nr_slots
- 1));
254 if (slot
== ring
->nr_slots
- 1)
259 static inline int prev_slot(struct b43legacy_dmaring
*ring
, int slot
)
261 B43legacy_WARN_ON(!(slot
>= 0 && slot
<= ring
->nr_slots
- 1));
263 return ring
->nr_slots
- 1;
267 #ifdef CONFIG_B43LEGACY_DEBUG
268 static void update_max_used_slots(struct b43legacy_dmaring
*ring
,
269 int current_used_slots
)
271 if (current_used_slots
<= ring
->max_used_slots
)
273 ring
->max_used_slots
= current_used_slots
;
274 if (b43legacy_debug(ring
->dev
, B43legacy_DBG_DMAVERBOSE
))
275 b43legacydbg(ring
->dev
->wl
,
276 "max_used_slots increased to %d on %s ring %d\n",
277 ring
->max_used_slots
,
278 ring
->tx
? "TX" : "RX",
283 void update_max_used_slots(struct b43legacy_dmaring
*ring
,
284 int current_used_slots
)
288 /* Request a slot for usage. */
290 int request_slot(struct b43legacy_dmaring
*ring
)
294 B43legacy_WARN_ON(!ring
->tx
);
295 B43legacy_WARN_ON(ring
->stopped
);
296 B43legacy_WARN_ON(free_slots(ring
) == 0);
298 slot
= next_slot(ring
, ring
->current_slot
);
299 ring
->current_slot
= slot
;
302 update_max_used_slots(ring
, ring
->used_slots
);
307 /* Mac80211-queue to b43legacy-ring mapping */
308 static struct b43legacy_dmaring
*priority_to_txring(
309 struct b43legacy_wldev
*dev
,
312 struct b43legacy_dmaring
*ring
;
314 /*FIXME: For now we always run on TX-ring-1 */
315 return dev
->dma
.tx_ring1
;
317 /* 0 = highest priority */
318 switch (queue_priority
) {
320 B43legacy_WARN_ON(1);
323 ring
= dev
->dma
.tx_ring3
;
326 ring
= dev
->dma
.tx_ring2
;
329 ring
= dev
->dma
.tx_ring1
;
332 ring
= dev
->dma
.tx_ring0
;
335 ring
= dev
->dma
.tx_ring4
;
338 ring
= dev
->dma
.tx_ring5
;
345 /* Bcm4301-ring to mac80211-queue mapping */
346 static inline int txring_to_priority(struct b43legacy_dmaring
*ring
)
348 static const u8 idx_to_prio
[] =
349 { 3, 2, 1, 0, 4, 5, };
351 /*FIXME: have only one queue, for now */
354 return idx_to_prio
[ring
->index
];
358 static u16
b43legacy_dmacontroller_base(enum b43legacy_dmatype type
,
361 static const u16 map64
[] = {
362 B43legacy_MMIO_DMA64_BASE0
,
363 B43legacy_MMIO_DMA64_BASE1
,
364 B43legacy_MMIO_DMA64_BASE2
,
365 B43legacy_MMIO_DMA64_BASE3
,
366 B43legacy_MMIO_DMA64_BASE4
,
367 B43legacy_MMIO_DMA64_BASE5
,
369 static const u16 map32
[] = {
370 B43legacy_MMIO_DMA32_BASE0
,
371 B43legacy_MMIO_DMA32_BASE1
,
372 B43legacy_MMIO_DMA32_BASE2
,
373 B43legacy_MMIO_DMA32_BASE3
,
374 B43legacy_MMIO_DMA32_BASE4
,
375 B43legacy_MMIO_DMA32_BASE5
,
378 if (type
== B43legacy_DMA_64BIT
) {
379 B43legacy_WARN_ON(!(controller_idx
>= 0 &&
380 controller_idx
< ARRAY_SIZE(map64
)));
381 return map64
[controller_idx
];
383 B43legacy_WARN_ON(!(controller_idx
>= 0 &&
384 controller_idx
< ARRAY_SIZE(map32
)));
385 return map32
[controller_idx
];
389 dma_addr_t
map_descbuffer(struct b43legacy_dmaring
*ring
,
397 dmaaddr
= dma_map_single(ring
->dev
->dev
->dma_dev
,
401 dmaaddr
= dma_map_single(ring
->dev
->dev
->dma_dev
,
409 void unmap_descbuffer(struct b43legacy_dmaring
*ring
,
415 dma_unmap_single(ring
->dev
->dev
->dma_dev
,
419 dma_unmap_single(ring
->dev
->dev
->dma_dev
,
425 void sync_descbuffer_for_cpu(struct b43legacy_dmaring
*ring
,
429 B43legacy_WARN_ON(ring
->tx
);
431 dma_sync_single_for_cpu(ring
->dev
->dev
->dma_dev
,
432 addr
, len
, DMA_FROM_DEVICE
);
436 void sync_descbuffer_for_device(struct b43legacy_dmaring
*ring
,
440 B43legacy_WARN_ON(ring
->tx
);
442 dma_sync_single_for_device(ring
->dev
->dev
->dma_dev
,
443 addr
, len
, DMA_FROM_DEVICE
);
447 void free_descriptor_buffer(struct b43legacy_dmaring
*ring
,
448 struct b43legacy_dmadesc_meta
*meta
,
453 dev_kfree_skb_irq(meta
->skb
);
455 dev_kfree_skb(meta
->skb
);
460 static int alloc_ringmemory(struct b43legacy_dmaring
*ring
)
462 /* GFP flags must match the flags in free_ringmemory()! */
463 ring
->descbase
= dma_alloc_coherent(ring
->dev
->dev
->dma_dev
,
464 B43legacy_DMA_RINGMEMSIZE
,
467 if (!ring
->descbase
) {
468 b43legacyerr(ring
->dev
->wl
, "DMA ringmemory allocation"
472 memset(ring
->descbase
, 0, B43legacy_DMA_RINGMEMSIZE
);
477 static void free_ringmemory(struct b43legacy_dmaring
*ring
)
479 dma_free_coherent(ring
->dev
->dev
->dma_dev
, B43legacy_DMA_RINGMEMSIZE
,
480 ring
->descbase
, ring
->dmabase
);
483 /* Reset the RX DMA channel */
484 static int b43legacy_dmacontroller_rx_reset(struct b43legacy_wldev
*dev
,
486 enum b43legacy_dmatype type
)
494 offset
= (type
== B43legacy_DMA_64BIT
) ?
495 B43legacy_DMA64_RXCTL
: B43legacy_DMA32_RXCTL
;
496 b43legacy_write32(dev
, mmio_base
+ offset
, 0);
497 for (i
= 0; i
< 10; i
++) {
498 offset
= (type
== B43legacy_DMA_64BIT
) ?
499 B43legacy_DMA64_RXSTATUS
: B43legacy_DMA32_RXSTATUS
;
500 value
= b43legacy_read32(dev
, mmio_base
+ offset
);
501 if (type
== B43legacy_DMA_64BIT
) {
502 value
&= B43legacy_DMA64_RXSTAT
;
503 if (value
== B43legacy_DMA64_RXSTAT_DISABLED
) {
508 value
&= B43legacy_DMA32_RXSTATE
;
509 if (value
== B43legacy_DMA32_RXSTAT_DISABLED
) {
517 b43legacyerr(dev
->wl
, "DMA RX reset timed out\n");
524 /* Reset the RX DMA channel */
525 static int b43legacy_dmacontroller_tx_reset(struct b43legacy_wldev
*dev
,
527 enum b43legacy_dmatype type
)
535 for (i
= 0; i
< 10; i
++) {
536 offset
= (type
== B43legacy_DMA_64BIT
) ?
537 B43legacy_DMA64_TXSTATUS
: B43legacy_DMA32_TXSTATUS
;
538 value
= b43legacy_read32(dev
, mmio_base
+ offset
);
539 if (type
== B43legacy_DMA_64BIT
) {
540 value
&= B43legacy_DMA64_TXSTAT
;
541 if (value
== B43legacy_DMA64_TXSTAT_DISABLED
||
542 value
== B43legacy_DMA64_TXSTAT_IDLEWAIT
||
543 value
== B43legacy_DMA64_TXSTAT_STOPPED
)
546 value
&= B43legacy_DMA32_TXSTATE
;
547 if (value
== B43legacy_DMA32_TXSTAT_DISABLED
||
548 value
== B43legacy_DMA32_TXSTAT_IDLEWAIT
||
549 value
== B43legacy_DMA32_TXSTAT_STOPPED
)
554 offset
= (type
== B43legacy_DMA_64BIT
) ? B43legacy_DMA64_TXCTL
:
555 B43legacy_DMA32_TXCTL
;
556 b43legacy_write32(dev
, mmio_base
+ offset
, 0);
557 for (i
= 0; i
< 10; i
++) {
558 offset
= (type
== B43legacy_DMA_64BIT
) ?
559 B43legacy_DMA64_TXSTATUS
: B43legacy_DMA32_TXSTATUS
;
560 value
= b43legacy_read32(dev
, mmio_base
+ offset
);
561 if (type
== B43legacy_DMA_64BIT
) {
562 value
&= B43legacy_DMA64_TXSTAT
;
563 if (value
== B43legacy_DMA64_TXSTAT_DISABLED
) {
568 value
&= B43legacy_DMA32_TXSTATE
;
569 if (value
== B43legacy_DMA32_TXSTAT_DISABLED
) {
577 b43legacyerr(dev
->wl
, "DMA TX reset timed out\n");
580 /* ensure the reset is completed. */
586 /* Check if a DMA mapping address is invalid. */
587 static bool b43legacy_dma_mapping_error(struct b43legacy_dmaring
*ring
,
592 if (unlikely(dma_mapping_error(ring
->dev
->dev
->dma_dev
, addr
)))
595 switch (ring
->type
) {
596 case B43legacy_DMA_30BIT
:
597 if ((u64
)addr
+ buffersize
> (1ULL << 30))
600 case B43legacy_DMA_32BIT
:
601 if ((u64
)addr
+ buffersize
> (1ULL << 32))
604 case B43legacy_DMA_64BIT
:
605 /* Currently we can't have addresses beyond 64 bits in the kernel. */
609 /* The address is OK. */
613 /* We can't support this address. Unmap it again. */
614 unmap_descbuffer(ring
, addr
, buffersize
, dma_to_device
);
619 static int setup_rx_descbuffer(struct b43legacy_dmaring
*ring
,
620 struct b43legacy_dmadesc_generic
*desc
,
621 struct b43legacy_dmadesc_meta
*meta
,
624 struct b43legacy_rxhdr_fw3
*rxhdr
;
625 struct b43legacy_hwtxstatus
*txstat
;
629 B43legacy_WARN_ON(ring
->tx
);
631 skb
= __dev_alloc_skb(ring
->rx_buffersize
, gfp_flags
);
634 dmaaddr
= map_descbuffer(ring
, skb
->data
,
635 ring
->rx_buffersize
, 0);
636 if (b43legacy_dma_mapping_error(ring
, dmaaddr
, ring
->rx_buffersize
, 0)) {
637 /* ugh. try to realloc in zone_dma */
638 gfp_flags
|= GFP_DMA
;
640 dev_kfree_skb_any(skb
);
642 skb
= __dev_alloc_skb(ring
->rx_buffersize
, gfp_flags
);
645 dmaaddr
= map_descbuffer(ring
, skb
->data
,
646 ring
->rx_buffersize
, 0);
649 if (b43legacy_dma_mapping_error(ring
, dmaaddr
, ring
->rx_buffersize
, 0)) {
650 dev_kfree_skb_any(skb
);
655 meta
->dmaaddr
= dmaaddr
;
656 ring
->ops
->fill_descriptor(ring
, desc
, dmaaddr
,
657 ring
->rx_buffersize
, 0, 0, 0);
659 rxhdr
= (struct b43legacy_rxhdr_fw3
*)(skb
->data
);
660 rxhdr
->frame_len
= 0;
661 txstat
= (struct b43legacy_hwtxstatus
*)(skb
->data
);
667 /* Allocate the initial descbuffers.
668 * This is used for an RX ring only.
670 static int alloc_initial_descbuffers(struct b43legacy_dmaring
*ring
)
674 struct b43legacy_dmadesc_generic
*desc
;
675 struct b43legacy_dmadesc_meta
*meta
;
677 for (i
= 0; i
< ring
->nr_slots
; i
++) {
678 desc
= ring
->ops
->idx2desc(ring
, i
, &meta
);
680 err
= setup_rx_descbuffer(ring
, desc
, meta
, GFP_KERNEL
);
682 b43legacyerr(ring
->dev
->wl
,
683 "Failed to allocate initial descbuffers\n");
687 mb(); /* all descbuffer setup before next line */
688 ring
->used_slots
= ring
->nr_slots
;
694 for (i
--; i
>= 0; i
--) {
695 desc
= ring
->ops
->idx2desc(ring
, i
, &meta
);
697 unmap_descbuffer(ring
, meta
->dmaaddr
, ring
->rx_buffersize
, 0);
698 dev_kfree_skb(meta
->skb
);
703 /* Do initial setup of the DMA controller.
704 * Reset the controller, write the ring busaddress
705 * and switch the "enable" bit on.
707 static int dmacontroller_setup(struct b43legacy_dmaring
*ring
)
712 u32 trans
= ring
->dev
->dma
.translation
;
715 if (ring
->type
== B43legacy_DMA_64BIT
) {
716 u64 ringbase
= (u64
)(ring
->dmabase
);
718 addrext
= ((ringbase
>> 32) & SSB_DMA_TRANSLATION_MASK
)
719 >> SSB_DMA_TRANSLATION_SHIFT
;
720 value
= B43legacy_DMA64_TXENABLE
;
721 value
|= (addrext
<< B43legacy_DMA64_TXADDREXT_SHIFT
)
722 & B43legacy_DMA64_TXADDREXT_MASK
;
723 b43legacy_dma_write(ring
, B43legacy_DMA64_TXCTL
,
725 b43legacy_dma_write(ring
, B43legacy_DMA64_TXRINGLO
,
726 (ringbase
& 0xFFFFFFFF));
727 b43legacy_dma_write(ring
, B43legacy_DMA64_TXRINGHI
,
729 & ~SSB_DMA_TRANSLATION_MASK
)
732 u32 ringbase
= (u32
)(ring
->dmabase
);
734 addrext
= (ringbase
& SSB_DMA_TRANSLATION_MASK
)
735 >> SSB_DMA_TRANSLATION_SHIFT
;
736 value
= B43legacy_DMA32_TXENABLE
;
737 value
|= (addrext
<< B43legacy_DMA32_TXADDREXT_SHIFT
)
738 & B43legacy_DMA32_TXADDREXT_MASK
;
739 b43legacy_dma_write(ring
, B43legacy_DMA32_TXCTL
,
741 b43legacy_dma_write(ring
, B43legacy_DMA32_TXRING
,
743 ~SSB_DMA_TRANSLATION_MASK
)
747 err
= alloc_initial_descbuffers(ring
);
750 if (ring
->type
== B43legacy_DMA_64BIT
) {
751 u64 ringbase
= (u64
)(ring
->dmabase
);
753 addrext
= ((ringbase
>> 32) & SSB_DMA_TRANSLATION_MASK
)
754 >> SSB_DMA_TRANSLATION_SHIFT
;
755 value
= (ring
->frameoffset
<<
756 B43legacy_DMA64_RXFROFF_SHIFT
);
757 value
|= B43legacy_DMA64_RXENABLE
;
758 value
|= (addrext
<< B43legacy_DMA64_RXADDREXT_SHIFT
)
759 & B43legacy_DMA64_RXADDREXT_MASK
;
760 b43legacy_dma_write(ring
, B43legacy_DMA64_RXCTL
,
762 b43legacy_dma_write(ring
, B43legacy_DMA64_RXRINGLO
,
763 (ringbase
& 0xFFFFFFFF));
764 b43legacy_dma_write(ring
, B43legacy_DMA64_RXRINGHI
,
766 ~SSB_DMA_TRANSLATION_MASK
) |
768 b43legacy_dma_write(ring
, B43legacy_DMA64_RXINDEX
,
771 u32 ringbase
= (u32
)(ring
->dmabase
);
773 addrext
= (ringbase
& SSB_DMA_TRANSLATION_MASK
)
774 >> SSB_DMA_TRANSLATION_SHIFT
;
775 value
= (ring
->frameoffset
<<
776 B43legacy_DMA32_RXFROFF_SHIFT
);
777 value
|= B43legacy_DMA32_RXENABLE
;
779 B43legacy_DMA32_RXADDREXT_SHIFT
)
780 & B43legacy_DMA32_RXADDREXT_MASK
;
781 b43legacy_dma_write(ring
, B43legacy_DMA32_RXCTL
,
783 b43legacy_dma_write(ring
, B43legacy_DMA32_RXRING
,
785 ~SSB_DMA_TRANSLATION_MASK
)
787 b43legacy_dma_write(ring
, B43legacy_DMA32_RXINDEX
,
796 /* Shutdown the DMA controller. */
797 static void dmacontroller_cleanup(struct b43legacy_dmaring
*ring
)
800 b43legacy_dmacontroller_tx_reset(ring
->dev
, ring
->mmio_base
,
802 if (ring
->type
== B43legacy_DMA_64BIT
) {
803 b43legacy_dma_write(ring
, B43legacy_DMA64_TXRINGLO
, 0);
804 b43legacy_dma_write(ring
, B43legacy_DMA64_TXRINGHI
, 0);
806 b43legacy_dma_write(ring
, B43legacy_DMA32_TXRING
, 0);
808 b43legacy_dmacontroller_rx_reset(ring
->dev
, ring
->mmio_base
,
810 if (ring
->type
== B43legacy_DMA_64BIT
) {
811 b43legacy_dma_write(ring
, B43legacy_DMA64_RXRINGLO
, 0);
812 b43legacy_dma_write(ring
, B43legacy_DMA64_RXRINGHI
, 0);
814 b43legacy_dma_write(ring
, B43legacy_DMA32_RXRING
, 0);
818 static void free_all_descbuffers(struct b43legacy_dmaring
*ring
)
820 struct b43legacy_dmadesc_meta
*meta
;
823 if (!ring
->used_slots
)
825 for (i
= 0; i
< ring
->nr_slots
; i
++) {
826 ring
->ops
->idx2desc(ring
, i
, &meta
);
829 B43legacy_WARN_ON(!ring
->tx
);
833 unmap_descbuffer(ring
, meta
->dmaaddr
,
836 unmap_descbuffer(ring
, meta
->dmaaddr
,
837 ring
->rx_buffersize
, 0);
838 free_descriptor_buffer(ring
, meta
, 0);
842 static u64
supported_dma_mask(struct b43legacy_wldev
*dev
)
847 tmp
= b43legacy_read32(dev
, SSB_TMSHIGH
);
848 if (tmp
& SSB_TMSHIGH_DMA64
)
849 return DMA_BIT_MASK(64);
850 mmio_base
= b43legacy_dmacontroller_base(0, 0);
851 b43legacy_write32(dev
,
852 mmio_base
+ B43legacy_DMA32_TXCTL
,
853 B43legacy_DMA32_TXADDREXT_MASK
);
854 tmp
= b43legacy_read32(dev
, mmio_base
+
855 B43legacy_DMA32_TXCTL
);
856 if (tmp
& B43legacy_DMA32_TXADDREXT_MASK
)
857 return DMA_BIT_MASK(32);
859 return DMA_BIT_MASK(30);
862 static enum b43legacy_dmatype
dma_mask_to_engine_type(u64 dmamask
)
864 if (dmamask
== DMA_BIT_MASK(30))
865 return B43legacy_DMA_30BIT
;
866 if (dmamask
== DMA_BIT_MASK(32))
867 return B43legacy_DMA_32BIT
;
868 if (dmamask
== DMA_BIT_MASK(64))
869 return B43legacy_DMA_64BIT
;
870 B43legacy_WARN_ON(1);
871 return B43legacy_DMA_30BIT
;
874 /* Main initialization function. */
876 struct b43legacy_dmaring
*b43legacy_setup_dmaring(struct b43legacy_wldev
*dev
,
877 int controller_index
,
879 enum b43legacy_dmatype type
)
881 struct b43legacy_dmaring
*ring
;
886 ring
= kzalloc(sizeof(*ring
), GFP_KERNEL
);
892 nr_slots
= B43legacy_RXRING_SLOTS
;
894 nr_slots
= B43legacy_TXRING_SLOTS
;
896 ring
->meta
= kcalloc(nr_slots
, sizeof(struct b43legacy_dmadesc_meta
),
901 ring
->txhdr_cache
= kcalloc(nr_slots
,
902 sizeof(struct b43legacy_txhdr_fw3
),
904 if (!ring
->txhdr_cache
)
907 /* test for ability to dma to txhdr_cache */
908 dma_test
= dma_map_single(dev
->dev
->dma_dev
, ring
->txhdr_cache
,
909 sizeof(struct b43legacy_txhdr_fw3
),
912 if (b43legacy_dma_mapping_error(ring
, dma_test
,
913 sizeof(struct b43legacy_txhdr_fw3
), 1)) {
915 kfree(ring
->txhdr_cache
);
916 ring
->txhdr_cache
= kcalloc(nr_slots
,
917 sizeof(struct b43legacy_txhdr_fw3
),
918 GFP_KERNEL
| GFP_DMA
);
919 if (!ring
->txhdr_cache
)
922 dma_test
= dma_map_single(dev
->dev
->dma_dev
,
924 sizeof(struct b43legacy_txhdr_fw3
),
927 if (b43legacy_dma_mapping_error(ring
, dma_test
,
928 sizeof(struct b43legacy_txhdr_fw3
), 1))
929 goto err_kfree_txhdr_cache
;
932 dma_unmap_single(dev
->dev
->dma_dev
, dma_test
,
933 sizeof(struct b43legacy_txhdr_fw3
),
937 ring
->nr_slots
= nr_slots
;
938 ring
->mmio_base
= b43legacy_dmacontroller_base(type
, controller_index
);
939 ring
->index
= controller_index
;
940 if (type
== B43legacy_DMA_64BIT
)
941 ring
->ops
= &dma64_ops
;
943 ring
->ops
= &dma32_ops
;
946 ring
->current_slot
= -1;
948 if (ring
->index
== 0) {
949 ring
->rx_buffersize
= B43legacy_DMA0_RX_BUFFERSIZE
;
950 ring
->frameoffset
= B43legacy_DMA0_RX_FRAMEOFFSET
;
951 } else if (ring
->index
== 3) {
952 ring
->rx_buffersize
= B43legacy_DMA3_RX_BUFFERSIZE
;
953 ring
->frameoffset
= B43legacy_DMA3_RX_FRAMEOFFSET
;
955 B43legacy_WARN_ON(1);
957 spin_lock_init(&ring
->lock
);
958 #ifdef CONFIG_B43LEGACY_DEBUG
959 ring
->last_injected_overflow
= jiffies
;
962 err
= alloc_ringmemory(ring
);
964 goto err_kfree_txhdr_cache
;
965 err
= dmacontroller_setup(ring
);
967 goto err_free_ringmemory
;
973 free_ringmemory(ring
);
974 err_kfree_txhdr_cache
:
975 kfree(ring
->txhdr_cache
);
984 /* Main cleanup function. */
985 static void b43legacy_destroy_dmaring(struct b43legacy_dmaring
*ring
)
990 b43legacydbg(ring
->dev
->wl
, "DMA-%u 0x%04X (%s) max used slots:"
991 " %d/%d\n", (unsigned int)(ring
->type
), ring
->mmio_base
,
992 (ring
->tx
) ? "TX" : "RX", ring
->max_used_slots
,
994 /* Device IRQs are disabled prior entering this function,
995 * so no need to take care of concurrency with rx handler stuff.
997 dmacontroller_cleanup(ring
);
998 free_all_descbuffers(ring
);
999 free_ringmemory(ring
);
1001 kfree(ring
->txhdr_cache
);
1006 void b43legacy_dma_free(struct b43legacy_wldev
*dev
)
1008 struct b43legacy_dma
*dma
;
1010 if (b43legacy_using_pio(dev
))
1014 b43legacy_destroy_dmaring(dma
->rx_ring3
);
1015 dma
->rx_ring3
= NULL
;
1016 b43legacy_destroy_dmaring(dma
->rx_ring0
);
1017 dma
->rx_ring0
= NULL
;
1019 b43legacy_destroy_dmaring(dma
->tx_ring5
);
1020 dma
->tx_ring5
= NULL
;
1021 b43legacy_destroy_dmaring(dma
->tx_ring4
);
1022 dma
->tx_ring4
= NULL
;
1023 b43legacy_destroy_dmaring(dma
->tx_ring3
);
1024 dma
->tx_ring3
= NULL
;
1025 b43legacy_destroy_dmaring(dma
->tx_ring2
);
1026 dma
->tx_ring2
= NULL
;
1027 b43legacy_destroy_dmaring(dma
->tx_ring1
);
1028 dma
->tx_ring1
= NULL
;
1029 b43legacy_destroy_dmaring(dma
->tx_ring0
);
1030 dma
->tx_ring0
= NULL
;
1033 static int b43legacy_dma_set_mask(struct b43legacy_wldev
*dev
, u64 mask
)
1035 u64 orig_mask
= mask
;
1039 /* Try to set the DMA mask. If it fails, try falling back to a
1040 * lower mask, as we can always also support a lower one. */
1042 err
= dma_set_mask(dev
->dev
->dma_dev
, mask
);
1044 err
= dma_set_coherent_mask(dev
->dev
->dma_dev
, mask
);
1048 if (mask
== DMA_BIT_MASK(64)) {
1049 mask
= DMA_BIT_MASK(32);
1053 if (mask
== DMA_BIT_MASK(32)) {
1054 mask
= DMA_BIT_MASK(30);
1058 b43legacyerr(dev
->wl
, "The machine/kernel does not support "
1059 "the required %u-bit DMA mask\n",
1060 (unsigned int)dma_mask_to_engine_type(orig_mask
));
1064 b43legacyinfo(dev
->wl
, "DMA mask fallback from %u-bit to %u-"
1066 (unsigned int)dma_mask_to_engine_type(orig_mask
),
1067 (unsigned int)dma_mask_to_engine_type(mask
));
1073 int b43legacy_dma_init(struct b43legacy_wldev
*dev
)
1075 struct b43legacy_dma
*dma
= &dev
->dma
;
1076 struct b43legacy_dmaring
*ring
;
1079 enum b43legacy_dmatype type
;
1081 dmamask
= supported_dma_mask(dev
);
1082 type
= dma_mask_to_engine_type(dmamask
);
1083 err
= b43legacy_dma_set_mask(dev
, dmamask
);
1085 #ifdef CONFIG_B43LEGACY_PIO
1086 b43legacywarn(dev
->wl
, "DMA for this device not supported. "
1087 "Falling back to PIO\n");
1088 dev
->__using_pio
= 1;
1091 b43legacyerr(dev
->wl
, "DMA for this device not supported and "
1092 "no PIO support compiled in\n");
1096 dma
->translation
= ssb_dma_translation(dev
->dev
);
1099 /* setup TX DMA channels. */
1100 ring
= b43legacy_setup_dmaring(dev
, 0, 1, type
);
1103 dma
->tx_ring0
= ring
;
1105 ring
= b43legacy_setup_dmaring(dev
, 1, 1, type
);
1107 goto err_destroy_tx0
;
1108 dma
->tx_ring1
= ring
;
1110 ring
= b43legacy_setup_dmaring(dev
, 2, 1, type
);
1112 goto err_destroy_tx1
;
1113 dma
->tx_ring2
= ring
;
1115 ring
= b43legacy_setup_dmaring(dev
, 3, 1, type
);
1117 goto err_destroy_tx2
;
1118 dma
->tx_ring3
= ring
;
1120 ring
= b43legacy_setup_dmaring(dev
, 4, 1, type
);
1122 goto err_destroy_tx3
;
1123 dma
->tx_ring4
= ring
;
1125 ring
= b43legacy_setup_dmaring(dev
, 5, 1, type
);
1127 goto err_destroy_tx4
;
1128 dma
->tx_ring5
= ring
;
1130 /* setup RX DMA channels. */
1131 ring
= b43legacy_setup_dmaring(dev
, 0, 0, type
);
1133 goto err_destroy_tx5
;
1134 dma
->rx_ring0
= ring
;
1136 if (dev
->dev
->id
.revision
< 5) {
1137 ring
= b43legacy_setup_dmaring(dev
, 3, 0, type
);
1139 goto err_destroy_rx0
;
1140 dma
->rx_ring3
= ring
;
1143 b43legacydbg(dev
->wl
, "%u-bit DMA initialized\n", (unsigned int)type
);
1149 b43legacy_destroy_dmaring(dma
->rx_ring0
);
1150 dma
->rx_ring0
= NULL
;
1152 b43legacy_destroy_dmaring(dma
->tx_ring5
);
1153 dma
->tx_ring5
= NULL
;
1155 b43legacy_destroy_dmaring(dma
->tx_ring4
);
1156 dma
->tx_ring4
= NULL
;
1158 b43legacy_destroy_dmaring(dma
->tx_ring3
);
1159 dma
->tx_ring3
= NULL
;
1161 b43legacy_destroy_dmaring(dma
->tx_ring2
);
1162 dma
->tx_ring2
= NULL
;
1164 b43legacy_destroy_dmaring(dma
->tx_ring1
);
1165 dma
->tx_ring1
= NULL
;
1167 b43legacy_destroy_dmaring(dma
->tx_ring0
);
1168 dma
->tx_ring0
= NULL
;
1172 /* Generate a cookie for the TX header. */
1173 static u16
generate_cookie(struct b43legacy_dmaring
*ring
,
1176 u16 cookie
= 0x1000;
1178 /* Use the upper 4 bits of the cookie as
1179 * DMA controller ID and store the slot number
1180 * in the lower 12 bits.
1181 * Note that the cookie must never be 0, as this
1182 * is a special value used in RX path.
1184 switch (ring
->index
) {
1204 B43legacy_WARN_ON(!(((u16
)slot
& 0xF000) == 0x0000));
1205 cookie
|= (u16
)slot
;
1210 /* Inspect a cookie and find out to which controller/slot it belongs. */
1212 struct b43legacy_dmaring
*parse_cookie(struct b43legacy_wldev
*dev
,
1213 u16 cookie
, int *slot
)
1215 struct b43legacy_dma
*dma
= &dev
->dma
;
1216 struct b43legacy_dmaring
*ring
= NULL
;
1218 switch (cookie
& 0xF000) {
1220 ring
= dma
->tx_ring0
;
1223 ring
= dma
->tx_ring1
;
1226 ring
= dma
->tx_ring2
;
1229 ring
= dma
->tx_ring3
;
1232 ring
= dma
->tx_ring4
;
1235 ring
= dma
->tx_ring5
;
1238 B43legacy_WARN_ON(1);
1240 *slot
= (cookie
& 0x0FFF);
1241 B43legacy_WARN_ON(!(ring
&& *slot
>= 0 && *slot
< ring
->nr_slots
));
1246 static int dma_tx_fragment(struct b43legacy_dmaring
*ring
,
1247 struct sk_buff
**in_skb
)
1249 struct sk_buff
*skb
= *in_skb
;
1250 const struct b43legacy_dma_ops
*ops
= ring
->ops
;
1251 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1253 int slot
, old_top_slot
, old_used_slots
;
1255 struct b43legacy_dmadesc_generic
*desc
;
1256 struct b43legacy_dmadesc_meta
*meta
;
1257 struct b43legacy_dmadesc_meta
*meta_hdr
;
1258 struct sk_buff
*bounce_skb
;
1260 #define SLOTS_PER_PACKET 2
1261 B43legacy_WARN_ON(skb_shinfo(skb
)->nr_frags
!= 0);
1263 old_top_slot
= ring
->current_slot
;
1264 old_used_slots
= ring
->used_slots
;
1266 /* Get a slot for the header. */
1267 slot
= request_slot(ring
);
1268 desc
= ops
->idx2desc(ring
, slot
, &meta_hdr
);
1269 memset(meta_hdr
, 0, sizeof(*meta_hdr
));
1271 header
= &(ring
->txhdr_cache
[slot
* sizeof(
1272 struct b43legacy_txhdr_fw3
)]);
1273 err
= b43legacy_generate_txhdr(ring
->dev
, header
,
1274 skb
->data
, skb
->len
, info
,
1275 generate_cookie(ring
, slot
));
1276 if (unlikely(err
)) {
1277 ring
->current_slot
= old_top_slot
;
1278 ring
->used_slots
= old_used_slots
;
1282 meta_hdr
->dmaaddr
= map_descbuffer(ring
, (unsigned char *)header
,
1283 sizeof(struct b43legacy_txhdr_fw3
), 1);
1284 if (b43legacy_dma_mapping_error(ring
, meta_hdr
->dmaaddr
,
1285 sizeof(struct b43legacy_txhdr_fw3
), 1)) {
1286 ring
->current_slot
= old_top_slot
;
1287 ring
->used_slots
= old_used_slots
;
1290 ops
->fill_descriptor(ring
, desc
, meta_hdr
->dmaaddr
,
1291 sizeof(struct b43legacy_txhdr_fw3
), 1, 0, 0);
1293 /* Get a slot for the payload. */
1294 slot
= request_slot(ring
);
1295 desc
= ops
->idx2desc(ring
, slot
, &meta
);
1296 memset(meta
, 0, sizeof(*meta
));
1299 meta
->is_last_fragment
= 1;
1301 meta
->dmaaddr
= map_descbuffer(ring
, skb
->data
, skb
->len
, 1);
1302 /* create a bounce buffer in zone_dma on mapping failure. */
1303 if (b43legacy_dma_mapping_error(ring
, meta
->dmaaddr
, skb
->len
, 1)) {
1304 bounce_skb
= __dev_alloc_skb(skb
->len
, GFP_ATOMIC
| GFP_DMA
);
1306 ring
->current_slot
= old_top_slot
;
1307 ring
->used_slots
= old_used_slots
;
1312 memcpy(skb_put(bounce_skb
, skb
->len
), skb
->data
, skb
->len
);
1313 memcpy(bounce_skb
->cb
, skb
->cb
, sizeof(skb
->cb
));
1314 bounce_skb
->dev
= skb
->dev
;
1315 skb_set_queue_mapping(bounce_skb
, skb_get_queue_mapping(skb
));
1316 info
= IEEE80211_SKB_CB(bounce_skb
);
1318 dev_kfree_skb_any(skb
);
1320 *in_skb
= bounce_skb
;
1322 meta
->dmaaddr
= map_descbuffer(ring
, skb
->data
, skb
->len
, 1);
1323 if (b43legacy_dma_mapping_error(ring
, meta
->dmaaddr
, skb
->len
, 1)) {
1324 ring
->current_slot
= old_top_slot
;
1325 ring
->used_slots
= old_used_slots
;
1327 goto out_free_bounce
;
1331 ops
->fill_descriptor(ring
, desc
, meta
->dmaaddr
,
1334 wmb(); /* previous stuff MUST be done */
1335 /* Now transfer the whole frame. */
1336 ops
->poke_tx(ring
, next_slot(ring
, slot
));
1340 dev_kfree_skb_any(skb
);
1342 unmap_descbuffer(ring
, meta_hdr
->dmaaddr
,
1343 sizeof(struct b43legacy_txhdr_fw3
), 1);
1348 int should_inject_overflow(struct b43legacy_dmaring
*ring
)
1350 #ifdef CONFIG_B43LEGACY_DEBUG
1351 if (unlikely(b43legacy_debug(ring
->dev
,
1352 B43legacy_DBG_DMAOVERFLOW
))) {
1353 /* Check if we should inject another ringbuffer overflow
1354 * to test handling of this situation in the stack. */
1355 unsigned long next_overflow
;
1357 next_overflow
= ring
->last_injected_overflow
+ HZ
;
1358 if (time_after(jiffies
, next_overflow
)) {
1359 ring
->last_injected_overflow
= jiffies
;
1360 b43legacydbg(ring
->dev
->wl
,
1361 "Injecting TX ring overflow on "
1362 "DMA controller %d\n", ring
->index
);
1366 #endif /* CONFIG_B43LEGACY_DEBUG */
1370 int b43legacy_dma_tx(struct b43legacy_wldev
*dev
,
1371 struct sk_buff
*skb
)
1373 struct b43legacy_dmaring
*ring
;
1375 unsigned long flags
;
1377 ring
= priority_to_txring(dev
, skb_get_queue_mapping(skb
));
1378 spin_lock_irqsave(&ring
->lock
, flags
);
1379 B43legacy_WARN_ON(!ring
->tx
);
1381 if (unlikely(ring
->stopped
)) {
1382 /* We get here only because of a bug in mac80211.
1383 * Because of a race, one packet may be queued after
1384 * the queue is stopped, thus we got called when we shouldn't.
1385 * For now, just refuse the transmit. */
1386 if (b43legacy_debug(dev
, B43legacy_DBG_DMAVERBOSE
))
1387 b43legacyerr(dev
->wl
, "Packet after queue stopped\n");
1392 if (unlikely(WARN_ON(free_slots(ring
) < SLOTS_PER_PACKET
))) {
1393 /* If we get here, we have a real error with the queue
1394 * full, but queues not stopped. */
1395 b43legacyerr(dev
->wl
, "DMA queue overflow\n");
1400 /* dma_tx_fragment might reallocate the skb, so invalidate pointers pointing
1401 * into the skb data or cb now. */
1402 err
= dma_tx_fragment(ring
, &skb
);
1403 if (unlikely(err
== -ENOKEY
)) {
1404 /* Drop this packet, as we don't have the encryption key
1405 * anymore and must not transmit it unencrypted. */
1406 dev_kfree_skb_any(skb
);
1410 if (unlikely(err
)) {
1411 b43legacyerr(dev
->wl
, "DMA tx mapping failure\n");
1414 if ((free_slots(ring
) < SLOTS_PER_PACKET
) ||
1415 should_inject_overflow(ring
)) {
1416 /* This TX ring is full. */
1417 ieee80211_stop_queue(dev
->wl
->hw
, txring_to_priority(ring
));
1419 if (b43legacy_debug(dev
, B43legacy_DBG_DMAVERBOSE
))
1420 b43legacydbg(dev
->wl
, "Stopped TX ring %d\n",
1424 spin_unlock_irqrestore(&ring
->lock
, flags
);
1429 void b43legacy_dma_handle_txstatus(struct b43legacy_wldev
*dev
,
1430 const struct b43legacy_txstatus
*status
)
1432 const struct b43legacy_dma_ops
*ops
;
1433 struct b43legacy_dmaring
*ring
;
1434 struct b43legacy_dmadesc_meta
*meta
;
1438 ring
= parse_cookie(dev
, status
->cookie
, &slot
);
1439 if (unlikely(!ring
))
1441 B43legacy_WARN_ON(!irqs_disabled());
1442 spin_lock(&ring
->lock
);
1444 B43legacy_WARN_ON(!ring
->tx
);
1447 B43legacy_WARN_ON(!(slot
>= 0 && slot
< ring
->nr_slots
));
1448 ops
->idx2desc(ring
, slot
, &meta
);
1451 unmap_descbuffer(ring
, meta
->dmaaddr
,
1454 unmap_descbuffer(ring
, meta
->dmaaddr
,
1455 sizeof(struct b43legacy_txhdr_fw3
),
1458 if (meta
->is_last_fragment
) {
1459 struct ieee80211_tx_info
*info
;
1461 info
= IEEE80211_SKB_CB(meta
->skb
);
1463 /* preserve the confiured retry limit before clearing the status
1464 * The xmit function has overwritten the rc's value with the actual
1465 * retry limit done by the hardware */
1466 retry_limit
= info
->status
.rates
[0].count
;
1467 ieee80211_tx_info_clear_status(info
);
1470 info
->flags
|= IEEE80211_TX_STAT_ACK
;
1472 if (status
->rts_count
> dev
->wl
->hw
->conf
.short_frame_max_tx_count
) {
1474 * If the short retries (RTS, not data frame) have exceeded
1475 * the limit, the hw will not have tried the selected rate,
1476 * but will have used the fallback rate instead.
1477 * Don't let the rate control count attempts for the selected
1478 * rate in this case, otherwise the statistics will be off.
1480 info
->status
.rates
[0].count
= 0;
1481 info
->status
.rates
[1].count
= status
->frame_count
;
1483 if (status
->frame_count
> retry_limit
) {
1484 info
->status
.rates
[0].count
= retry_limit
;
1485 info
->status
.rates
[1].count
= status
->frame_count
-
1489 info
->status
.rates
[0].count
= status
->frame_count
;
1490 info
->status
.rates
[1].idx
= -1;
1494 /* Call back to inform the ieee80211 subsystem about the
1495 * status of the transmission.
1496 * Some fields of txstat are already filled in dma_tx().
1498 ieee80211_tx_status_irqsafe(dev
->wl
->hw
, meta
->skb
);
1499 /* skb is freed by ieee80211_tx_status_irqsafe() */
1502 /* No need to call free_descriptor_buffer here, as
1503 * this is only the txhdr, which is not allocated.
1505 B43legacy_WARN_ON(meta
->skb
!= NULL
);
1508 /* Everything unmapped and free'd. So it's not used anymore. */
1511 if (meta
->is_last_fragment
)
1513 slot
= next_slot(ring
, slot
);
1515 dev
->stats
.last_tx
= jiffies
;
1516 if (ring
->stopped
) {
1517 B43legacy_WARN_ON(free_slots(ring
) < SLOTS_PER_PACKET
);
1518 ieee80211_wake_queue(dev
->wl
->hw
, txring_to_priority(ring
));
1520 if (b43legacy_debug(dev
, B43legacy_DBG_DMAVERBOSE
))
1521 b43legacydbg(dev
->wl
, "Woke up TX ring %d\n",
1525 spin_unlock(&ring
->lock
);
1528 static void dma_rx(struct b43legacy_dmaring
*ring
,
1531 const struct b43legacy_dma_ops
*ops
= ring
->ops
;
1532 struct b43legacy_dmadesc_generic
*desc
;
1533 struct b43legacy_dmadesc_meta
*meta
;
1534 struct b43legacy_rxhdr_fw3
*rxhdr
;
1535 struct sk_buff
*skb
;
1540 desc
= ops
->idx2desc(ring
, *slot
, &meta
);
1542 sync_descbuffer_for_cpu(ring
, meta
->dmaaddr
, ring
->rx_buffersize
);
1545 if (ring
->index
== 3) {
1546 /* We received an xmit status. */
1547 struct b43legacy_hwtxstatus
*hw
=
1548 (struct b43legacy_hwtxstatus
*)skb
->data
;
1551 while (hw
->cookie
== 0) {
1558 b43legacy_handle_hwtxstatus(ring
->dev
, hw
);
1559 /* recycle the descriptor buffer. */
1560 sync_descbuffer_for_device(ring
, meta
->dmaaddr
,
1561 ring
->rx_buffersize
);
1565 rxhdr
= (struct b43legacy_rxhdr_fw3
*)skb
->data
;
1566 len
= le16_to_cpu(rxhdr
->frame_len
);
1573 len
= le16_to_cpu(rxhdr
->frame_len
);
1574 } while (len
== 0 && i
++ < 5);
1575 if (unlikely(len
== 0)) {
1576 /* recycle the descriptor buffer. */
1577 sync_descbuffer_for_device(ring
, meta
->dmaaddr
,
1578 ring
->rx_buffersize
);
1582 if (unlikely(len
> ring
->rx_buffersize
)) {
1583 /* The data did not fit into one descriptor buffer
1584 * and is split over multiple buffers.
1585 * This should never happen, as we try to allocate buffers
1586 * big enough. So simply ignore this packet.
1592 desc
= ops
->idx2desc(ring
, *slot
, &meta
);
1593 /* recycle the descriptor buffer. */
1594 sync_descbuffer_for_device(ring
, meta
->dmaaddr
,
1595 ring
->rx_buffersize
);
1596 *slot
= next_slot(ring
, *slot
);
1598 tmp
-= ring
->rx_buffersize
;
1602 b43legacyerr(ring
->dev
->wl
, "DMA RX buffer too small "
1603 "(len: %u, buffer: %u, nr-dropped: %d)\n",
1604 len
, ring
->rx_buffersize
, cnt
);
1608 dmaaddr
= meta
->dmaaddr
;
1609 err
= setup_rx_descbuffer(ring
, desc
, meta
, GFP_ATOMIC
);
1610 if (unlikely(err
)) {
1611 b43legacydbg(ring
->dev
->wl
, "DMA RX: setup_rx_descbuffer()"
1613 sync_descbuffer_for_device(ring
, dmaaddr
,
1614 ring
->rx_buffersize
);
1618 unmap_descbuffer(ring
, dmaaddr
, ring
->rx_buffersize
, 0);
1619 skb_put(skb
, len
+ ring
->frameoffset
);
1620 skb_pull(skb
, ring
->frameoffset
);
1622 b43legacy_rx(ring
->dev
, skb
, rxhdr
);
1627 void b43legacy_dma_rx(struct b43legacy_dmaring
*ring
)
1629 const struct b43legacy_dma_ops
*ops
= ring
->ops
;
1634 B43legacy_WARN_ON(ring
->tx
);
1635 current_slot
= ops
->get_current_rxslot(ring
);
1636 B43legacy_WARN_ON(!(current_slot
>= 0 && current_slot
<
1639 slot
= ring
->current_slot
;
1640 for (; slot
!= current_slot
; slot
= next_slot(ring
, slot
)) {
1641 dma_rx(ring
, &slot
);
1642 update_max_used_slots(ring
, ++used_slots
);
1644 ops
->set_current_rxslot(ring
, slot
);
1645 ring
->current_slot
= slot
;
1648 static void b43legacy_dma_tx_suspend_ring(struct b43legacy_dmaring
*ring
)
1650 unsigned long flags
;
1652 spin_lock_irqsave(&ring
->lock
, flags
);
1653 B43legacy_WARN_ON(!ring
->tx
);
1654 ring
->ops
->tx_suspend(ring
);
1655 spin_unlock_irqrestore(&ring
->lock
, flags
);
1658 static void b43legacy_dma_tx_resume_ring(struct b43legacy_dmaring
*ring
)
1660 unsigned long flags
;
1662 spin_lock_irqsave(&ring
->lock
, flags
);
1663 B43legacy_WARN_ON(!ring
->tx
);
1664 ring
->ops
->tx_resume(ring
);
1665 spin_unlock_irqrestore(&ring
->lock
, flags
);
1668 void b43legacy_dma_tx_suspend(struct b43legacy_wldev
*dev
)
1670 b43legacy_power_saving_ctl_bits(dev
, -1, 1);
1671 b43legacy_dma_tx_suspend_ring(dev
->dma
.tx_ring0
);
1672 b43legacy_dma_tx_suspend_ring(dev
->dma
.tx_ring1
);
1673 b43legacy_dma_tx_suspend_ring(dev
->dma
.tx_ring2
);
1674 b43legacy_dma_tx_suspend_ring(dev
->dma
.tx_ring3
);
1675 b43legacy_dma_tx_suspend_ring(dev
->dma
.tx_ring4
);
1676 b43legacy_dma_tx_suspend_ring(dev
->dma
.tx_ring5
);
1679 void b43legacy_dma_tx_resume(struct b43legacy_wldev
*dev
)
1681 b43legacy_dma_tx_resume_ring(dev
->dma
.tx_ring5
);
1682 b43legacy_dma_tx_resume_ring(dev
->dma
.tx_ring4
);
1683 b43legacy_dma_tx_resume_ring(dev
->dma
.tx_ring3
);
1684 b43legacy_dma_tx_resume_ring(dev
->dma
.tx_ring2
);
1685 b43legacy_dma_tx_resume_ring(dev
->dma
.tx_ring1
);
1686 b43legacy_dma_tx_resume_ring(dev
->dma
.tx_ring0
);
1687 b43legacy_power_saving_ctl_bits(dev
, -1, -1);