ddbd751ead6e6b167b07f16aa947908318e72889
[openwrt/openwrt.git] / target / linux / generic / pending-5.4 / 770-08-net-ethernet-mtk_eth_soc-cache-hardware-pointer-of-l.patch
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
4 freed tx descriptor
5
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
8
9 Signed-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 @@ -1358,7 +1358,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 @@ -1389,6 +1389,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 @@ -1589,6 +1590,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 @@ -1602,9 +1604,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 @@ -622,6 +622,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 @@ -632,6 +633,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;