1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Thu, 27 Oct 2022 19:53:57 +0200
3 Subject: [PATCH] net: ethernet: mtk_eth_soc: increase tx ring side for
6 In order to use the hardware traffic shaper feature, a larger tx ring is
7 needed, especially for the scratch ring, which the hardware shaper uses to
10 Signed-off-by: Felix Fietkau <nbd@nbd.name>
13 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
14 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
15 @@ -901,7 +901,7 @@ static int mtk_init_fq_dma(struct mtk_et
17 const struct mtk_soc_data *soc = eth->soc;
18 dma_addr_t phy_ring_tail;
19 - int cnt = MTK_DMA_SIZE;
20 + int cnt = MTK_QDMA_RING_SIZE;
24 @@ -2155,19 +2155,25 @@ static int mtk_tx_alloc(struct mtk_eth *
25 struct mtk_tx_ring *ring = ð->tx_ring;
26 int i, sz = soc->txrx.txd_size;
27 struct mtk_tx_dma_v2 *txd;
30 - ring->buf = kcalloc(MTK_DMA_SIZE, sizeof(*ring->buf),
31 + if (MTK_HAS_CAPS(soc->caps, MTK_QDMA))
32 + ring_size = MTK_QDMA_RING_SIZE;
34 + ring_size = MTK_DMA_SIZE;
36 + ring->buf = kcalloc(ring_size, sizeof(*ring->buf),
41 - ring->dma = dma_alloc_coherent(eth->dma_dev, MTK_DMA_SIZE * sz,
42 + ring->dma = dma_alloc_coherent(eth->dma_dev, ring_size * sz,
43 &ring->phys, GFP_KERNEL);
47 - for (i = 0; i < MTK_DMA_SIZE; i++) {
48 - int next = (i + 1) % MTK_DMA_SIZE;
49 + for (i = 0; i < ring_size; i++) {
50 + int next = (i + 1) % ring_size;
51 u32 next_ptr = ring->phys + next * sz;
53 txd = ring->dma + i * sz;
54 @@ -2187,22 +2193,22 @@ static int mtk_tx_alloc(struct mtk_eth *
55 * descriptors in ring->dma_pdma.
57 if (!MTK_HAS_CAPS(soc->caps, MTK_QDMA)) {
58 - ring->dma_pdma = dma_alloc_coherent(eth->dma_dev, MTK_DMA_SIZE * sz,
59 + ring->dma_pdma = dma_alloc_coherent(eth->dma_dev, ring_size * sz,
60 &ring->phys_pdma, GFP_KERNEL);
64 - for (i = 0; i < MTK_DMA_SIZE; i++) {
65 + for (i = 0; i < ring_size; i++) {
66 ring->dma_pdma[i].txd2 = TX_DMA_DESP2_DEF;
67 ring->dma_pdma[i].txd4 = 0;
71 - ring->dma_size = MTK_DMA_SIZE;
72 - atomic_set(&ring->free_count, MTK_DMA_SIZE - 2);
73 + ring->dma_size = ring_size;
74 + atomic_set(&ring->free_count, ring_size - 2);
75 ring->next_free = ring->dma;
76 ring->last_free = (void *)txd;
77 - ring->last_free_ptr = (u32)(ring->phys + ((MTK_DMA_SIZE - 1) * sz));
78 + ring->last_free_ptr = (u32)(ring->phys + ((ring_size - 1) * sz));
79 ring->thresh = MAX_SKB_FRAGS;
81 /* make sure that all changes to the dma ring are flushed before we
82 @@ -2214,14 +2220,14 @@ static int mtk_tx_alloc(struct mtk_eth *
83 mtk_w32(eth, ring->phys, soc->reg_map->qdma.ctx_ptr);
84 mtk_w32(eth, ring->phys, soc->reg_map->qdma.dtx_ptr);
86 - ring->phys + ((MTK_DMA_SIZE - 1) * sz),
87 + ring->phys + ((ring_size - 1) * sz),
88 soc->reg_map->qdma.crx_ptr);
89 mtk_w32(eth, ring->last_free_ptr, soc->reg_map->qdma.drx_ptr);
90 mtk_w32(eth, (QDMA_RES_THRES << 8) | QDMA_RES_THRES,
91 soc->reg_map->qdma.qtx_cfg);
93 mtk_w32(eth, ring->phys_pdma, MT7628_TX_BASE_PTR0);
94 - mtk_w32(eth, MTK_DMA_SIZE, MT7628_TX_MAX_CNT0);
95 + mtk_w32(eth, ring_size, MT7628_TX_MAX_CNT0);
96 mtk_w32(eth, 0, MT7628_TX_CTX_IDX0);
97 mtk_w32(eth, MT7628_PST_DTX_IDX0, soc->reg_map->pdma.rst_idx);
99 @@ -2239,7 +2245,7 @@ static void mtk_tx_clean(struct mtk_eth
103 - for (i = 0; i < MTK_DMA_SIZE; i++)
104 + for (i = 0; i < ring->dma_size; i++)
105 mtk_tx_unmap(eth, &ring->buf[i], false);
108 @@ -2247,14 +2253,14 @@ static void mtk_tx_clean(struct mtk_eth
111 dma_free_coherent(eth->dma_dev,
112 - MTK_DMA_SIZE * soc->txrx.txd_size,
113 + ring->dma_size * soc->txrx.txd_size,
114 ring->dma, ring->phys);
118 if (ring->dma_pdma) {
119 dma_free_coherent(eth->dma_dev,
120 - MTK_DMA_SIZE * soc->txrx.txd_size,
121 + ring->dma_size * soc->txrx.txd_size,
122 ring->dma_pdma, ring->phys_pdma);
123 ring->dma_pdma = NULL;
125 @@ -2774,7 +2780,7 @@ static void mtk_dma_free(struct mtk_eth
126 netdev_reset_queue(eth->netdev[i]);
127 if (eth->scratch_ring) {
128 dma_free_coherent(eth->dma_dev,
129 - MTK_DMA_SIZE * soc->txrx.txd_size,
130 + MTK_QDMA_RING_SIZE * soc->txrx.txd_size,
131 eth->scratch_ring, eth->phy_scratch_ring);
132 eth->scratch_ring = NULL;
133 eth->phy_scratch_ring = 0;
134 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
135 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
137 #define MTK_MAX_RX_LENGTH_2K 2048
138 #define MTK_TX_DMA_BUF_LEN 0x3fff
139 #define MTK_TX_DMA_BUF_LEN_V2 0xffff
140 +#define MTK_QDMA_RING_SIZE 2048
141 #define MTK_DMA_SIZE 512
142 #define MTK_MAC_COUNT 2
143 #define MTK_RX_ETH_HLEN (VLAN_ETH_HLEN + ETH_FCS_LEN)