1 From edf8afeecfbb0b8c1a2edb8c8892d2f759d35321 Mon Sep 17 00:00:00 2001
2 From: Lorenzo Bianconi <lorenzo@kernel.org>
3 Date: Thu, 19 Jun 2025 09:07:24 +0200
4 Subject: [PATCH 1/2] net: airoha: Compute number of descriptors according to
7 In order to not exceed the reserved memory size for hwfd buffers,
8 compute the number of hwfd buffers/descriptors according to the
9 reserved memory size and the size of each hwfd buffer (2KB).
11 Fixes: 3a1ce9e3d01b ("net: airoha: Add the capability to allocate hwfd buffers via reserved-memory")
12 Reviewed-by: Simon Horman <horms@kernel.org>
13 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
14 Link: https://patch.msgid.link/20250619-airoha-hw-num-desc-v4-1-49600a9b319a@kernel.org
15 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
17 drivers/net/ethernet/airoha/airoha_eth.c | 21 ++++++++++++---------
18 1 file changed, 12 insertions(+), 9 deletions(-)
20 --- a/drivers/net/ethernet/airoha/airoha_eth.c
21 +++ b/drivers/net/ethernet/airoha/airoha_eth.c
22 @@ -1066,19 +1066,13 @@ static void airoha_qdma_cleanup_tx_queue
24 static int airoha_qdma_init_hfwd_queues(struct airoha_qdma *qdma)
26 + int size, index, num_desc = HW_DSCP_NUM;
27 struct airoha_eth *eth = qdma->eth;
28 int id = qdma - ð->qdma[0];
34 - size = HW_DSCP_NUM * sizeof(struct airoha_qdma_fwd_desc);
35 - if (!dmam_alloc_coherent(eth->dev, size, &dma_addr, GFP_KERNEL))
38 - airoha_qdma_wr(qdma, REG_FWD_DSCP_BASE, dma_addr);
40 name = devm_kasprintf(eth->dev, GFP_KERNEL, "qdma%d-buf", id);
43 @@ -1100,8 +1094,12 @@ static int airoha_qdma_init_hfwd_queues(
44 rmem = of_reserved_mem_lookup(np);
46 dma_addr = rmem->base;
47 + /* Compute the number of hw descriptors according to the
48 + * reserved memory size and the payload buffer size
50 + num_desc = rmem->size / AIROHA_MAX_PACKET_SIZE;
52 - size = AIROHA_MAX_PACKET_SIZE * HW_DSCP_NUM;
53 + size = AIROHA_MAX_PACKET_SIZE * num_desc;
54 if (!dmam_alloc_coherent(eth->dev, size, &dma_addr,
57 @@ -1109,6 +1107,11 @@ static int airoha_qdma_init_hfwd_queues(
59 airoha_qdma_wr(qdma, REG_FWD_BUF_BASE, dma_addr);
61 + size = num_desc * sizeof(struct airoha_qdma_fwd_desc);
62 + if (!dmam_alloc_coherent(eth->dev, size, &dma_addr, GFP_KERNEL))
65 + airoha_qdma_wr(qdma, REG_FWD_DSCP_BASE, dma_addr);
66 airoha_qdma_rmw(qdma, REG_HW_FWD_DSCP_CFG,
67 HW_FWD_DSCP_PAYLOAD_SIZE_MASK,
68 FIELD_PREP(HW_FWD_DSCP_PAYLOAD_SIZE_MASK, 0));
69 @@ -1117,7 +1120,7 @@ static int airoha_qdma_init_hfwd_queues(
70 airoha_qdma_rmw(qdma, REG_LMGR_INIT_CFG,
71 LMGR_INIT_START | LMGR_SRAM_MODE_MASK |
73 - FIELD_PREP(HW_FWD_DESC_NUM_MASK, HW_DSCP_NUM) |
74 + FIELD_PREP(HW_FWD_DESC_NUM_MASK, num_desc) |
75 LMGR_INIT_START | LMGR_SRAM_MODE_MASK);
77 return read_poll_timeout(airoha_qdma_rr, status,