1 From 4e6bf609569c59b6bd6acf4a607c096cbd820d79 Mon Sep 17 00:00:00 2001
2 From: Felix Fietkau <nbd@nbd.name>
3 Date: Thu, 22 Apr 2021 22:21:03 -0700
4 Subject: [PATCH] net: ethernet: mtk_eth_soc: cache HW pointer of last freed TX
7 The value is only updated by the CPU, so it is cheaper to access from the
8 ring data structure than from a hardware register.
10 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
12 Signed-off-by: David S. Miller <davem@davemloft.net>
14 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 8 ++++----
15 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 ++
16 2 files changed, 6 insertions(+), 4 deletions(-)
18 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
19 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
20 @@ -1400,7 +1400,7 @@ static int mtk_poll_tx_qdma(struct mtk_e
21 struct mtk_tx_buf *tx_buf;
24 - cpu = mtk_r32(eth, MTK_QTX_CRX_PTR);
25 + cpu = ring->last_free_ptr;
26 dma = mtk_r32(eth, MTK_QTX_DRX_PTR);
28 desc = mtk_qdma_phys_to_virt(ring, cpu);
29 @@ -1434,6 +1434,7 @@ static int mtk_poll_tx_qdma(struct mtk_e
33 + ring->last_free_ptr = cpu;
34 mtk_w32(eth, cpu, MTK_QTX_CRX_PTR);
37 @@ -1634,6 +1635,7 @@ static int mtk_tx_alloc(struct mtk_eth *
38 atomic_set(&ring->free_count, MTK_DMA_SIZE - 2);
39 ring->next_free = &ring->dma[0];
40 ring->last_free = &ring->dma[MTK_DMA_SIZE - 1];
41 + ring->last_free_ptr = (u32)(ring->phys + ((MTK_DMA_SIZE - 1) * sz));
42 ring->thresh = MAX_SKB_FRAGS;
44 /* make sure that all changes to the dma ring are flushed before we
45 @@ -1647,9 +1649,7 @@ static int mtk_tx_alloc(struct mtk_eth *
47 ring->phys + ((MTK_DMA_SIZE - 1) * sz),
50 - ring->phys + ((MTK_DMA_SIZE - 1) * sz),
52 + mtk_w32(eth, ring->last_free_ptr, MTK_QTX_DRX_PTR);
53 mtk_w32(eth, (QDMA_RES_THRES << 8) | QDMA_RES_THRES,
56 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
57 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
58 @@ -657,6 +657,7 @@ struct mtk_tx_buf {
59 * @phys: The physical addr of tx_buf
60 * @next_free: Pointer to the next free descriptor
61 * @last_free: Pointer to the last free descriptor
62 + * @last_free_ptr: Hardware pointer value of the last free descriptor
63 * @thresh: The threshold of minimum amount of free descriptors
64 * @free_count: QDMA uses a linked list. Track how many free descriptors
66 @@ -667,6 +668,7 @@ struct mtk_tx_ring {
68 struct mtk_tx_dma *next_free;
69 struct mtk_tx_dma *last_free;