From ca2d559e1a41d62a5b49fb9ab513025ea27f1e7c Mon Sep 17 00:00:00 2001 From: Michael Buesch Date: Thu, 19 Feb 2009 20:17:36 +0100 Subject: b43: Move DMA stop sanity check Move the DMA stop sanity check up a few lines, so it's actually theoretically possible to trigger. (But it still shouldn't trigger, of course). Signed-off-by: Michael Buesch Signed-off-by: John W. Linville --- drivers/net/wireless/b43/dma.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'drivers/net/wireless/b43/dma.c') diff --git a/drivers/net/wireless/b43/dma.c b/drivers/net/wireless/b43/dma.c index 6d65a02b705..0f021c666d0 100644 --- a/drivers/net/wireless/b43/dma.c +++ b/drivers/net/wireless/b43/dma.c @@ -1306,16 +1306,18 @@ int b43_dma_tx(struct b43_wldev *dev, struct sk_buff *skb) } spin_lock_irqsave(&ring->lock, flags); + B43_WARN_ON(!ring->tx); + /* Check if the queue was stopped in mac80211, + * but we got called nevertheless. + * That would be a mac80211 bug. */ + B43_WARN_ON(ring->stopped); + if (unlikely(free_slots(ring) < SLOTS_PER_PACKET)) { b43warn(dev->wl, "DMA queue overflow\n"); err = -ENOSPC; goto out_unlock; } - /* Check if the queue was stopped in mac80211, - * but we got called nevertheless. - * That would be a mac80211 bug. */ - B43_WARN_ON(ring->stopped); /* Assign the queue number to the ring (if not already done before) * so TX status handling can use it. The queue to ring mapping is -- cgit v1.2.3 From 8eccb53f1b858c9bd0b745f839174725b76508ec Mon Sep 17 00:00:00 2001 From: Michael Buesch Date: Thu, 19 Feb 2009 23:39:26 +0100 Subject: b43: Fix DMA buffer size handling This fixes hidden bugs in the size handling of the DMA buffers. This sets the RX buffer size to the theoretical max packet size and fixes passing of the size values to the device (must not subtract the header offset). These bugs are hidden and don't actually trigger due to the magic +100 offset for the buffer size. Signed-off-by: Michael Buesch Signed-off-by: John W. Linville --- drivers/net/wireless/b43/dma.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'drivers/net/wireless/b43/dma.c') diff --git a/drivers/net/wireless/b43/dma.c b/drivers/net/wireless/b43/dma.c index 0f021c666d0..38246046a42 100644 --- a/drivers/net/wireless/b43/dma.c +++ b/drivers/net/wireless/b43/dma.c @@ -74,8 +74,7 @@ static void op32_fill_descriptor(struct b43_dmaring *ring, addrext = (u32) (dmaaddr & SSB_DMA_TRANSLATION_MASK) >> SSB_DMA_TRANSLATION_SHIFT; addr |= ssb_dma_translation(ring->dev->dev); - ctl = (bufsize - ring->frameoffset) - & B43_DMA32_DCTL_BYTECNT; + ctl = bufsize & B43_DMA32_DCTL_BYTECNT; if (slot == ring->nr_slots - 1) ctl |= B43_DMA32_DCTL_DTABLEEND; if (start) @@ -177,8 +176,7 @@ static void op64_fill_descriptor(struct b43_dmaring *ring, ctl0 |= B43_DMA64_DCTL0_FRAMEEND; if (irq) ctl0 |= B43_DMA64_DCTL0_IRQ; - ctl1 |= (bufsize - ring->frameoffset) - & B43_DMA64_DCTL1_BYTECNT; + ctl1 |= bufsize & B43_DMA64_DCTL1_BYTECNT; ctl1 |= (addrext << B43_DMA64_DCTL1_ADDREXT_SHIFT) & B43_DMA64_DCTL1_ADDREXT_MASK; @@ -830,9 +828,6 @@ struct b43_dmaring *b43_setup_dmaring(struct b43_wldev *dev, if (ring->index == 0) { ring->rx_buffersize = B43_DMA0_RX_BUFFERSIZE; ring->frameoffset = B43_DMA0_RX_FRAMEOFFSET; - } else if (ring->index == 3) { - ring->rx_buffersize = B43_DMA3_RX_BUFFERSIZE; - ring->frameoffset = B43_DMA3_RX_FRAMEOFFSET; } else B43_WARN_ON(1); } -- cgit v1.2.3 From bdceeb2dad5c8487ffeb4d0fa949686e4350ec7f Mon Sep 17 00:00:00 2001 From: Michael Buesch Date: Thu, 19 Feb 2009 23:45:43 +0100 Subject: b43: Optimize DMA buffers In the old days we used one slot per frame. But when we changed that to 2, we didn't raise the overall slot count. Which resulted in an effective division of two to the number of slots. Double the number of TX slots, so we have an effective hardware queue of 128 frames per QoS queue. Also optimize the TX header cache handling. We don't need a cached TX header for slots that will never carry an actual header. So we reduce the memory consumption of the cache by 50%. So as a net result we end up with more or less the same memory usage before and after this patch (except a few tiny meta structures), but have twice the number of TX slots available. Signed-off-by: Michael Buesch Signed-off-by: John W. Linville --- drivers/net/wireless/b43/dma.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'drivers/net/wireless/b43/dma.c') diff --git a/drivers/net/wireless/b43/dma.c b/drivers/net/wireless/b43/dma.c index 38246046a42..189b2ec1bac 100644 --- a/drivers/net/wireless/b43/dma.c +++ b/drivers/net/wireless/b43/dma.c @@ -41,6 +41,12 @@ #include +/* Required number of TX DMA slots per TX frame. + * This currently is 2, because we put the header and the ieee80211 frame + * into separate slots. */ +#define TX_SLOTS_PER_FRAME 2 + + /* 32bit DMA ops. */ static struct b43_dmadesc_generic *op32_idx2desc(struct b43_dmaring *ring, @@ -574,12 +580,11 @@ static int setup_rx_descbuffer(struct b43_dmaring *ring, return -ENOMEM; dmaaddr = map_descbuffer(ring, skb->data, ring->rx_buffersize, 0); - } - - if (b43_dma_mapping_error(ring, dmaaddr, ring->rx_buffersize, 0)) { - b43err(ring->dev->wl, "RX DMA buffer allocation failed\n"); - dev_kfree_skb_any(skb); - return -EIO; + if (b43_dma_mapping_error(ring, dmaaddr, ring->rx_buffersize, 0)) { + b43err(ring->dev->wl, "RX DMA buffer allocation failed\n"); + dev_kfree_skb_any(skb); + return -EIO; + } } meta->skb = skb; @@ -837,7 +842,7 @@ struct b43_dmaring *b43_setup_dmaring(struct b43_wldev *dev, #endif if (for_tx) { - ring->txhdr_cache = kcalloc(ring->nr_slots, + ring->txhdr_cache = kcalloc(ring->nr_slots / TX_SLOTS_PER_FRAME, b43_txhdr_size(dev), GFP_KERNEL); if (!ring->txhdr_cache) @@ -853,7 +858,7 @@ struct b43_dmaring *b43_setup_dmaring(struct b43_wldev *dev, b43_txhdr_size(dev), 1)) { /* ugh realloc */ kfree(ring->txhdr_cache); - ring->txhdr_cache = kcalloc(ring->nr_slots, + ring->txhdr_cache = kcalloc(ring->nr_slots / TX_SLOTS_PER_FRAME, b43_txhdr_size(dev), GFP_KERNEL | GFP_DMA); if (!ring->txhdr_cache) @@ -1144,7 +1149,10 @@ static int dma_tx_fragment(struct b43_dmaring *ring, u16 cookie; size_t hdrsize = b43_txhdr_size(ring->dev); -#define SLOTS_PER_PACKET 2 + /* Important note: If the number of used DMA slots per TX frame + * is changed here, the TX_SLOTS_PER_FRAME definition at the top of + * the file has to be updated, too! + */ old_top_slot = ring->current_slot; old_used_slots = ring->used_slots; @@ -1154,7 +1162,7 @@ static int dma_tx_fragment(struct b43_dmaring *ring, desc = ops->idx2desc(ring, slot, &meta_hdr); memset(meta_hdr, 0, sizeof(*meta_hdr)); - header = &(ring->txhdr_cache[slot * hdrsize]); + header = &(ring->txhdr_cache[(slot / TX_SLOTS_PER_FRAME) * hdrsize]); cookie = generate_cookie(ring, slot); err = b43_generate_txhdr(ring->dev, header, skb->data, skb->len, info, cookie); @@ -1308,7 +1316,7 @@ int b43_dma_tx(struct b43_wldev *dev, struct sk_buff *skb) * That would be a mac80211 bug. */ B43_WARN_ON(ring->stopped); - if (unlikely(free_slots(ring) < SLOTS_PER_PACKET)) { + if (unlikely(free_slots(ring) < TX_SLOTS_PER_FRAME)) { b43warn(dev->wl, "DMA queue overflow\n"); err = -ENOSPC; goto out_unlock; @@ -1332,7 +1340,7 @@ int b43_dma_tx(struct b43_wldev *dev, struct sk_buff *skb) goto out_unlock; } ring->nr_tx_packets++; - if ((free_slots(ring) < SLOTS_PER_PACKET) || + if ((free_slots(ring) < TX_SLOTS_PER_FRAME) || should_inject_overflow(ring)) { /* This TX ring is full. */ ieee80211_stop_queue(dev->wl->hw, skb_get_queue_mapping(skb)); @@ -1416,7 +1424,7 @@ void b43_dma_handle_txstatus(struct b43_wldev *dev, } dev->stats.last_tx = jiffies; if (ring->stopped) { - B43_WARN_ON(free_slots(ring) < SLOTS_PER_PACKET); + B43_WARN_ON(free_slots(ring) < TX_SLOTS_PER_FRAME); ieee80211_wake_queue(dev->wl->hw, ring->queue_prio); ring->stopped = 0; if (b43_debug(dev, B43_DBG_DMAVERBOSE)) { @@ -1439,8 +1447,8 @@ void b43_dma_get_tx_stats(struct b43_wldev *dev, ring = select_ring_by_priority(dev, i); spin_lock_irqsave(&ring->lock, flags); - stats[i].len = ring->used_slots / SLOTS_PER_PACKET; - stats[i].limit = ring->nr_slots / SLOTS_PER_PACKET; + stats[i].len = ring->used_slots / TX_SLOTS_PER_FRAME; + stats[i].limit = ring->nr_slots / TX_SLOTS_PER_FRAME; stats[i].count = ring->nr_tx_packets; spin_unlock_irqrestore(&ring->lock, flags); } -- cgit v1.2.3 From 2d071ca50e9f20bf0203a7e8dbb1c784934e324d Mon Sep 17 00:00:00 2001 From: Michael Buesch Date: Fri, 20 Feb 2009 12:24:52 +0100 Subject: b43: Add slot count compiletime assertion This adds a compiletime assertion for a recently introduced assumption on the slot counts. The tx header cache handling code assumes that the TX slot count can be divided evenly by the number of TX slots per frame. Signed-off-by: Michael Buesch Signed-off-by: John W. Linville --- drivers/net/wireless/b43/dma.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers/net/wireless/b43/dma.c') diff --git a/drivers/net/wireless/b43/dma.c b/drivers/net/wireless/b43/dma.c index 189b2ec1bac..c69b70e0a72 100644 --- a/drivers/net/wireless/b43/dma.c +++ b/drivers/net/wireless/b43/dma.c @@ -842,6 +842,9 @@ struct b43_dmaring *b43_setup_dmaring(struct b43_wldev *dev, #endif if (for_tx) { + /* Assumption: B43_TXRING_SLOTS can be divided by TX_SLOTS_PER_FRAME */ + BUILD_BUG_ON(B43_TXRING_SLOTS % TX_SLOTS_PER_FRAME != 0); + ring->txhdr_cache = kcalloc(ring->nr_slots / TX_SLOTS_PER_FRAME, b43_txhdr_size(dev), GFP_KERNEL); -- cgit v1.2.3 From 99da185a72ba685a5aaf49dff6a5fe83885112e4 Mon Sep 17 00:00:00 2001 From: John Daiker Date: Tue, 24 Feb 2009 02:16:42 -0800 Subject: b43: checkpatch.pl cleanups Keeping this one simple. Changing a few "foo * bar" to "foo *bar" Removes 22 checkpatch.pl errors, with no introduced warnings. Signed-off-by: John Daiker Signed-off-by: John W. Linville --- drivers/net/wireless/b43/dma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/net/wireless/b43/dma.c') diff --git a/drivers/net/wireless/b43/dma.c b/drivers/net/wireless/b43/dma.c index c69b70e0a72..92e1c0189a6 100644 --- a/drivers/net/wireless/b43/dma.c +++ b/drivers/net/wireless/b43/dma.c @@ -1260,8 +1260,8 @@ static inline int should_inject_overflow(struct b43_dmaring *ring) } /* Static mapping of mac80211's queues (priorities) to b43 DMA rings. */ -static struct b43_dmaring * select_ring_by_priority(struct b43_wldev *dev, - u8 queue_prio) +static struct b43_dmaring *select_ring_by_priority(struct b43_wldev *dev, + u8 queue_prio) { struct b43_dmaring *ring; -- cgit v1.2.3 From ce4fbdbf161b2676b3833412367113572d739253 Mon Sep 17 00:00:00 2001 From: Michael Buesch Date: Mon, 2 Mar 2009 23:18:37 +0100 Subject: b43: Pass more RX flags to mac80211 This changes the RX handler to pass more status flags to mac80211. It also changes part of the drop policy, if bad frames were requested. (Note that currently mac80211 will throw a WARN_ON in that case. But nothing bad will happen). This also removes some obsolete unused timestamping code. Signed-off-by: Michael Buesch Signed-off-by: John W. Linville --- drivers/net/wireless/b43/dma.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/net/wireless/b43/dma.c') diff --git a/drivers/net/wireless/b43/dma.c b/drivers/net/wireless/b43/dma.c index 92e1c0189a6..0cc804d0a21 100644 --- a/drivers/net/wireless/b43/dma.c +++ b/drivers/net/wireless/b43/dma.c @@ -1425,7 +1425,6 @@ void b43_dma_handle_txstatus(struct b43_wldev *dev, break; slot = next_slot(ring, slot); } - dev->stats.last_tx = jiffies; if (ring->stopped) { B43_WARN_ON(free_slots(ring) < TX_SLOTS_PER_FRAME); ieee80211_wake_queue(dev->wl->hw, ring->queue_prio); -- cgit v1.2.3