blob: 9f32dd2610d2cda9f67de0bbd1838da5f6935511 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From: Felix Fietkau <nbd@nbd.name>
2Date: Thu, 27 Aug 2020 06:32:03 +0200
3Subject: [PATCH] net: ethernet: mtk_eth_soc: cache hardware pointer of last
4 freed tx descriptor
5
6The value is only updated by the CPU, so it is cheaper to access from the ring
7data structure than from a hardware register
8
9Signed-off-by: Felix Fietkau <nbd@nbd.name>
10---
11
12--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
13+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
14@@ -1393,7 +1393,7 @@ static int mtk_poll_tx_qdma(struct mtk_e
15 struct mtk_tx_buf *tx_buf;
16 u32 cpu, dma;
17
18- cpu = mtk_r32(eth, MTK_QTX_CRX_PTR);
19+ cpu = ring->last_free_ptr;
20 dma = mtk_r32(eth, MTK_QTX_DRX_PTR);
21
22 desc = mtk_qdma_phys_to_virt(ring, cpu);
23@@ -1427,6 +1427,7 @@ static int mtk_poll_tx_qdma(struct mtk_e
24 cpu = next_cpu;
25 }
26
27+ ring->last_free_ptr = cpu;
28 mtk_w32(eth, cpu, MTK_QTX_CRX_PTR);
29
30 return budget;
31@@ -1627,6 +1628,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;
37
38 /* make sure that all changes to the dma ring are flushed before we
39@@ -1640,9 +1642,7 @@ static int mtk_tx_alloc(struct mtk_eth *
40 mtk_w32(eth,
41 ring->phys + ((MTK_DMA_SIZE - 1) * sz),
42 MTK_QTX_CRX_PTR);
43- mtk_w32(eth,
44- ring->phys + ((MTK_DMA_SIZE - 1) * sz),
45- MTK_QTX_DRX_PTR);
46+ mtk_w32(eth, ring->last_free_ptr, MTK_QTX_DRX_PTR);
47 mtk_w32(eth, (QDMA_RES_THRES << 8) | QDMA_RES_THRES,
48 MTK_QTX_CFG(0));
49 } else {
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
59 * are present
60@@ -654,6 +655,7 @@ struct mtk_tx_ring {
61 dma_addr_t phys;
62 struct mtk_tx_dma *next_free;
63 struct mtk_tx_dma *last_free;
64+ u32 last_free_ptr;
65 u16 thresh;
66 atomic_t free_count;
67 int dma_size;