Skip to content

Commit edf8afe

Browse files
LorenzoBianconikuba-moo
authored andcommitted
net: airoha: Compute number of descriptors according to reserved memory size
In order to not exceed the reserved memory size for hwfd buffers, compute the number of hwfd buffers/descriptors according to the reserved memory size and the size of each hwfd buffer (2KB). Fixes: 3a1ce9e ("net: airoha: Add the capability to allocate hwfd buffers via reserved-memory") Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Lorenzo Bianconi <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent dccf87e commit edf8afe

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

drivers/net/ethernet/airoha/airoha_eth.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,19 +1065,13 @@ static void airoha_qdma_cleanup_tx_queue(struct airoha_queue *q)
10651065

10661066
static int airoha_qdma_init_hfwd_queues(struct airoha_qdma *qdma)
10671067
{
1068+
int size, index, num_desc = HW_DSCP_NUM;
10681069
struct airoha_eth *eth = qdma->eth;
10691070
int id = qdma - &eth->qdma[0];
10701071
dma_addr_t dma_addr;
10711072
const char *name;
1072-
int size, index;
10731073
u32 status;
10741074

1075-
size = HW_DSCP_NUM * sizeof(struct airoha_qdma_fwd_desc);
1076-
if (!dmam_alloc_coherent(eth->dev, size, &dma_addr, GFP_KERNEL))
1077-
return -ENOMEM;
1078-
1079-
airoha_qdma_wr(qdma, REG_FWD_DSCP_BASE, dma_addr);
1080-
10811075
name = devm_kasprintf(eth->dev, GFP_KERNEL, "qdma%d-buf", id);
10821076
if (!name)
10831077
return -ENOMEM;
@@ -1099,15 +1093,24 @@ static int airoha_qdma_init_hfwd_queues(struct airoha_qdma *qdma)
10991093
rmem = of_reserved_mem_lookup(np);
11001094
of_node_put(np);
11011095
dma_addr = rmem->base;
1096+
/* Compute the number of hw descriptors according to the
1097+
* reserved memory size and the payload buffer size
1098+
*/
1099+
num_desc = rmem->size / AIROHA_MAX_PACKET_SIZE;
11021100
} else {
1103-
size = AIROHA_MAX_PACKET_SIZE * HW_DSCP_NUM;
1101+
size = AIROHA_MAX_PACKET_SIZE * num_desc;
11041102
if (!dmam_alloc_coherent(eth->dev, size, &dma_addr,
11051103
GFP_KERNEL))
11061104
return -ENOMEM;
11071105
}
11081106

11091107
airoha_qdma_wr(qdma, REG_FWD_BUF_BASE, dma_addr);
11101108

1109+
size = num_desc * sizeof(struct airoha_qdma_fwd_desc);
1110+
if (!dmam_alloc_coherent(eth->dev, size, &dma_addr, GFP_KERNEL))
1111+
return -ENOMEM;
1112+
1113+
airoha_qdma_wr(qdma, REG_FWD_DSCP_BASE, dma_addr);
11111114
airoha_qdma_rmw(qdma, REG_HW_FWD_DSCP_CFG,
11121115
HW_FWD_DSCP_PAYLOAD_SIZE_MASK,
11131116
FIELD_PREP(HW_FWD_DSCP_PAYLOAD_SIZE_MASK, 0));
@@ -1116,7 +1119,7 @@ static int airoha_qdma_init_hfwd_queues(struct airoha_qdma *qdma)
11161119
airoha_qdma_rmw(qdma, REG_LMGR_INIT_CFG,
11171120
LMGR_INIT_START | LMGR_SRAM_MODE_MASK |
11181121
HW_FWD_DESC_NUM_MASK,
1119-
FIELD_PREP(HW_FWD_DESC_NUM_MASK, HW_DSCP_NUM) |
1122+
FIELD_PREP(HW_FWD_DESC_NUM_MASK, num_desc) |
11201123
LMGR_INIT_START | LMGR_SRAM_MODE_MASK);
11211124

11221125
return read_poll_timeout(airoha_qdma_rr, status,

0 commit comments

Comments
 (0)