Commit 42cb87a1 authored by Felix Fietkau's avatar Felix Fietkau Committed by Ben Hutchings

ath9k: fix rx descriptor related race condition

commit e96542e5 upstream.

Similar to a race condition that exists in the tx path, the hardware
might re-read the 'next' pointer of a descriptor of the last completed
frame. This only affects non-EDMA (pre-AR93xx) devices.

To deal with this race, defer clearing and re-linking a completed rx
descriptor until the next one has been processed.
Signed-off-by: default avatarFelix Fietkau <nbd@openwrt.org>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent f4dc9ffc
...@@ -77,10 +77,6 @@ struct ath_config { ...@@ -77,10 +77,6 @@ struct ath_config {
sizeof(struct ath_buf_state)); \ sizeof(struct ath_buf_state)); \
} while (0) } while (0)
#define ATH_RXBUF_RESET(_bf) do { \
(_bf)->bf_stale = false; \
} while (0)
/** /**
* enum buffer_type - Buffer type flags * enum buffer_type - Buffer type flags
* *
...@@ -308,6 +304,7 @@ struct ath_rx { ...@@ -308,6 +304,7 @@ struct ath_rx {
struct ath_buf *rx_bufptr; struct ath_buf *rx_bufptr;
struct ath_rx_edma rx_edma[ATH9K_RX_QUEUE_MAX]; struct ath_rx_edma rx_edma[ATH9K_RX_QUEUE_MAX];
struct ath_buf *buf_hold;
struct sk_buff *frag; struct sk_buff *frag;
}; };
......
...@@ -78,8 +78,6 @@ static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf) ...@@ -78,8 +78,6 @@ static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
struct ath_desc *ds; struct ath_desc *ds;
struct sk_buff *skb; struct sk_buff *skb;
ATH_RXBUF_RESET(bf);
ds = bf->bf_desc; ds = bf->bf_desc;
ds->ds_link = 0; /* link to null */ ds->ds_link = 0; /* link to null */
ds->ds_data = bf->bf_buf_addr; ds->ds_data = bf->bf_buf_addr;
...@@ -106,6 +104,14 @@ static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf) ...@@ -106,6 +104,14 @@ static void ath_rx_buf_link(struct ath_softc *sc, struct ath_buf *bf)
sc->rx.rxlink = &ds->ds_link; sc->rx.rxlink = &ds->ds_link;
} }
static void ath_rx_buf_relink(struct ath_softc *sc, struct ath_buf *bf)
{
if (sc->rx.buf_hold)
ath_rx_buf_link(sc, sc->rx.buf_hold);
sc->rx.buf_hold = bf;
}
static void ath_setdefantenna(struct ath_softc *sc, u32 antenna) static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
{ {
/* XXX block beacon interrupts */ /* XXX block beacon interrupts */
...@@ -153,7 +159,6 @@ static bool ath_rx_edma_buf_link(struct ath_softc *sc, ...@@ -153,7 +159,6 @@ static bool ath_rx_edma_buf_link(struct ath_softc *sc,
skb = bf->bf_mpdu; skb = bf->bf_mpdu;
ATH_RXBUF_RESET(bf);
memset(skb->data, 0, ah->caps.rx_status_len); memset(skb->data, 0, ah->caps.rx_status_len);
dma_sync_single_for_device(sc->dev, bf->bf_buf_addr, dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
ah->caps.rx_status_len, DMA_TO_DEVICE); ah->caps.rx_status_len, DMA_TO_DEVICE);
...@@ -492,6 +497,7 @@ int ath_startrecv(struct ath_softc *sc) ...@@ -492,6 +497,7 @@ int ath_startrecv(struct ath_softc *sc)
if (list_empty(&sc->rx.rxbuf)) if (list_empty(&sc->rx.rxbuf))
goto start_recv; goto start_recv;
sc->rx.buf_hold = NULL;
sc->rx.rxlink = NULL; sc->rx.rxlink = NULL;
list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) { list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
ath_rx_buf_link(sc, bf); ath_rx_buf_link(sc, bf);
...@@ -742,6 +748,9 @@ static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc, ...@@ -742,6 +748,9 @@ static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
} }
bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list); bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
if (bf == sc->rx.buf_hold)
return NULL;
ds = bf->bf_desc; ds = bf->bf_desc;
/* /*
...@@ -1974,7 +1983,7 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp) ...@@ -1974,7 +1983,7 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
if (edma) { if (edma) {
ath_rx_edma_buf_link(sc, qtype); ath_rx_edma_buf_link(sc, qtype);
} else { } else {
ath_rx_buf_link(sc, bf); ath_rx_buf_relink(sc, bf);
ath9k_hw_rxena(ah); ath9k_hw_rxena(ah);
} }
} while (1); } while (1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment