1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Thu, 27 Aug 2020 06:32:03 +0200
3 Subject: [PATCH] net: ethernet: mtk_eth_soc: cache hardware pointer of last
6 The value is only updated by the CPU, so it is cheaper to access from the ring
7 data structure than from a hardware register
9 Signed-off-by: Felix Fietkau <nbd@nbd.name>
12 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
13 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
14 @@ -1379,7 +1379,7 @@ static int mtk_poll_tx_qdma(struct mtk_e
15 struct mtk_tx_buf *tx_buf;
18 - cpu = mtk_r32(eth, MTK_QTX_CRX_PTR);
19 + cpu = ring->last_free_ptr;
20 dma = mtk_r32(eth, MTK_QTX_DRX_PTR);
22 desc = mtk_qdma_phys_to_virt(ring, cpu);
23 @@ -1413,6 +1413,7 @@ static int mtk_poll_tx_qdma(struct mtk_e
27 + ring->last_free_ptr = cpu;
28 mtk_w32(eth, cpu, MTK_QTX_CRX_PTR);
31 @@ -1613,6 +1614,7 @@ static int mtk_tx_alloc(struct mtk_eth *
32 atomic_set(&ring->free_count, MTK_DMA_SIZE - 2);
33 ring->next_free = &ring->dma[0];
34 ring->last_free = &ring->dma[MTK_DMA_SIZE - 1];
35 + ring->last_free_ptr = (u32)(ring->phys + ((MTK_DMA_SIZE - 1) * sz));
36 ring->thresh = MAX_SKB_FRAGS;
38 /* make sure that all changes to the dma ring are flushed before we
39 @@ -1626,9 +1628,7 @@ static int mtk_tx_alloc(struct mtk_eth *
41 ring->phys + ((MTK_DMA_SIZE - 1) * sz),
44 - ring->phys + ((MTK_DMA_SIZE - 1) * sz),
46 + mtk_w32(eth, ring->last_free_ptr, MTK_QTX_DRX_PTR);
47 mtk_w32(eth, (QDMA_RES_THRES << 8) | QDMA_RES_THRES,
50 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
51 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
52 @@ -644,6 +644,7 @@ struct mtk_tx_buf {
53 * @phys: The physical addr of tx_buf
54 * @next_free: Pointer to the next free descriptor
55 * @last_free: Pointer to the last free descriptor
56 + * @last_free_ptr: Hardware pointer value of the last free descriptor
57 * @thresh: The threshold of minimum amount of free descriptors
58 * @free_count: QDMA uses a linked list. Track how many free descriptors
60 @@ -654,6 +655,7 @@ struct mtk_tx_ring {
62 struct mtk_tx_dma *next_free;
63 struct mtk_tx_dma *last_free;