Skip to content

Commit c30e0b9

Browse files
nbd168kuba-moo
authored andcommitted
net: ethernet: mtk_eth_soc: increase tx ring size for QDMA devices
In order to use the hardware traffic shaper feature, a larger tx ring is needed, especially for the scratch ring, which the hardware shaper uses to reorder packets. Signed-off-by: Felix Fietkau <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent dbc4af7 commit c30e0b9

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

drivers/net/ethernet/mediatek/mtk_eth_soc.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ static int mtk_init_fq_dma(struct mtk_eth *eth)
938938
{
939939
const struct mtk_soc_data *soc = eth->soc;
940940
dma_addr_t phy_ring_tail;
941-
int cnt = MTK_DMA_SIZE;
941+
int cnt = MTK_QDMA_RING_SIZE;
942942
dma_addr_t dma_addr;
943943
int i;
944944

@@ -2208,19 +2208,25 @@ static int mtk_tx_alloc(struct mtk_eth *eth)
22082208
struct mtk_tx_ring *ring = &eth->tx_ring;
22092209
int i, sz = soc->txrx.txd_size;
22102210
struct mtk_tx_dma_v2 *txd;
2211+
int ring_size;
22112212

2212-
ring->buf = kcalloc(MTK_DMA_SIZE, sizeof(*ring->buf),
2213+
if (MTK_HAS_CAPS(soc->caps, MTK_QDMA))
2214+
ring_size = MTK_QDMA_RING_SIZE;
2215+
else
2216+
ring_size = MTK_DMA_SIZE;
2217+
2218+
ring->buf = kcalloc(ring_size, sizeof(*ring->buf),
22132219
GFP_KERNEL);
22142220
if (!ring->buf)
22152221
goto no_tx_mem;
22162222

2217-
ring->dma = dma_alloc_coherent(eth->dma_dev, MTK_DMA_SIZE * sz,
2223+
ring->dma = dma_alloc_coherent(eth->dma_dev, ring_size * sz,
22182224
&ring->phys, GFP_KERNEL);
22192225
if (!ring->dma)
22202226
goto no_tx_mem;
22212227

2222-
for (i = 0; i < MTK_DMA_SIZE; i++) {
2223-
int next = (i + 1) % MTK_DMA_SIZE;
2228+
for (i = 0; i < ring_size; i++) {
2229+
int next = (i + 1) % ring_size;
22242230
u32 next_ptr = ring->phys + next * sz;
22252231

22262232
txd = ring->dma + i * sz;
@@ -2240,22 +2246,22 @@ static int mtk_tx_alloc(struct mtk_eth *eth)
22402246
* descriptors in ring->dma_pdma.
22412247
*/
22422248
if (!MTK_HAS_CAPS(soc->caps, MTK_QDMA)) {
2243-
ring->dma_pdma = dma_alloc_coherent(eth->dma_dev, MTK_DMA_SIZE * sz,
2249+
ring->dma_pdma = dma_alloc_coherent(eth->dma_dev, ring_size * sz,
22442250
&ring->phys_pdma, GFP_KERNEL);
22452251
if (!ring->dma_pdma)
22462252
goto no_tx_mem;
22472253

2248-
for (i = 0; i < MTK_DMA_SIZE; i++) {
2254+
for (i = 0; i < ring_size; i++) {
22492255
ring->dma_pdma[i].txd2 = TX_DMA_DESP2_DEF;
22502256
ring->dma_pdma[i].txd4 = 0;
22512257
}
22522258
}
22532259

2254-
ring->dma_size = MTK_DMA_SIZE;
2255-
atomic_set(&ring->free_count, MTK_DMA_SIZE - 2);
2260+
ring->dma_size = ring_size;
2261+
atomic_set(&ring->free_count, ring_size - 2);
22562262
ring->next_free = ring->dma;
22572263
ring->last_free = (void *)txd;
2258-
ring->last_free_ptr = (u32)(ring->phys + ((MTK_DMA_SIZE - 1) * sz));
2264+
ring->last_free_ptr = (u32)(ring->phys + ((ring_size - 1) * sz));
22592265
ring->thresh = MAX_SKB_FRAGS;
22602266

22612267
/* make sure that all changes to the dma ring are flushed before we
@@ -2267,14 +2273,14 @@ static int mtk_tx_alloc(struct mtk_eth *eth)
22672273
mtk_w32(eth, ring->phys, soc->reg_map->qdma.ctx_ptr);
22682274
mtk_w32(eth, ring->phys, soc->reg_map->qdma.dtx_ptr);
22692275
mtk_w32(eth,
2270-
ring->phys + ((MTK_DMA_SIZE - 1) * sz),
2276+
ring->phys + ((ring_size - 1) * sz),
22712277
soc->reg_map->qdma.crx_ptr);
22722278
mtk_w32(eth, ring->last_free_ptr, soc->reg_map->qdma.drx_ptr);
22732279
mtk_w32(eth, (QDMA_RES_THRES << 8) | QDMA_RES_THRES,
22742280
soc->reg_map->qdma.qtx_cfg);
22752281
} else {
22762282
mtk_w32(eth, ring->phys_pdma, MT7628_TX_BASE_PTR0);
2277-
mtk_w32(eth, MTK_DMA_SIZE, MT7628_TX_MAX_CNT0);
2283+
mtk_w32(eth, ring_size, MT7628_TX_MAX_CNT0);
22782284
mtk_w32(eth, 0, MT7628_TX_CTX_IDX0);
22792285
mtk_w32(eth, MT7628_PST_DTX_IDX0, soc->reg_map->pdma.rst_idx);
22802286
}
@@ -2292,22 +2298,22 @@ static void mtk_tx_clean(struct mtk_eth *eth)
22922298
int i;
22932299

22942300
if (ring->buf) {
2295-
for (i = 0; i < MTK_DMA_SIZE; i++)
2301+
for (i = 0; i < ring->dma_size; i++)
22962302
mtk_tx_unmap(eth, &ring->buf[i], NULL, false);
22972303
kfree(ring->buf);
22982304
ring->buf = NULL;
22992305
}
23002306

23012307
if (ring->dma) {
23022308
dma_free_coherent(eth->dma_dev,
2303-
MTK_DMA_SIZE * soc->txrx.txd_size,
2309+
ring->dma_size * soc->txrx.txd_size,
23042310
ring->dma, ring->phys);
23052311
ring->dma = NULL;
23062312
}
23072313

23082314
if (ring->dma_pdma) {
23092315
dma_free_coherent(eth->dma_dev,
2310-
MTK_DMA_SIZE * soc->txrx.txd_size,
2316+
ring->dma_size * soc->txrx.txd_size,
23112317
ring->dma_pdma, ring->phys_pdma);
23122318
ring->dma_pdma = NULL;
23132319
}
@@ -2842,7 +2848,7 @@ static void mtk_dma_free(struct mtk_eth *eth)
28422848
netdev_reset_queue(eth->netdev[i]);
28432849
if (eth->scratch_ring) {
28442850
dma_free_coherent(eth->dma_dev,
2845-
MTK_DMA_SIZE * soc->txrx.txd_size,
2851+
MTK_QDMA_RING_SIZE * soc->txrx.txd_size,
28462852
eth->scratch_ring, eth->phy_scratch_ring);
28472853
eth->scratch_ring = NULL;
28482854
eth->phy_scratch_ring = 0;

drivers/net/ethernet/mediatek/mtk_eth_soc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define MTK_MAX_RX_LENGTH_2K 2048
3131
#define MTK_TX_DMA_BUF_LEN 0x3fff
3232
#define MTK_TX_DMA_BUF_LEN_V2 0xffff
33+
#define MTK_QDMA_RING_SIZE 2048
3334
#define MTK_DMA_SIZE 512
3435
#define MTK_MAC_COUNT 2
3536
#define MTK_RX_ETH_HLEN (ETH_HLEN + ETH_FCS_LEN)

0 commit comments

Comments
 (0)