Skip to content

Commit 3a1ce9e

Browse files
LorenzoBianconiPaolo Abeni
authored andcommitted
net: airoha: Add the capability to allocate hwfd buffers via reserved-memory
In some configurations QDMA blocks require a contiguous block of system memory for hwfd buffers queue. Introduce the capability to allocate hw buffers forwarding queue via the reserved-memory DTS property instead of running dmam_alloc_coherent(). Signed-off-by: Lorenzo Bianconi <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 09aa788 commit 3a1ce9e

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

drivers/net/ethernet/airoha/airoha_eth.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#include <linux/of.h>
77
#include <linux/of_net.h>
8+
#include <linux/of_reserved_mem.h>
89
#include <linux/platform_device.h>
910
#include <linux/tcp.h>
1011
#include <linux/u64_stats_sync.h>
@@ -1072,20 +1073,46 @@ static void airoha_qdma_cleanup_tx_queue(struct airoha_queue *q)
10721073
static int airoha_qdma_init_hfwd_queues(struct airoha_qdma *qdma)
10731074
{
10741075
struct airoha_eth *eth = qdma->eth;
1076+
int id = qdma - &eth->qdma[0];
10751077
dma_addr_t dma_addr;
1078+
const char *name;
1079+
int size, index;
10761080
u32 status;
1077-
int size;
10781081

10791082
size = HW_DSCP_NUM * sizeof(struct airoha_qdma_fwd_desc);
10801083
if (!dmam_alloc_coherent(eth->dev, size, &dma_addr, GFP_KERNEL))
10811084
return -ENOMEM;
10821085

10831086
airoha_qdma_wr(qdma, REG_FWD_DSCP_BASE, dma_addr);
10841087

1085-
size = AIROHA_MAX_PACKET_SIZE * HW_DSCP_NUM;
1086-
if (!dmam_alloc_coherent(eth->dev, size, &dma_addr, GFP_KERNEL))
1088+
name = devm_kasprintf(eth->dev, GFP_KERNEL, "qdma%d-buf", id);
1089+
if (!name)
10871090
return -ENOMEM;
10881091

1092+
index = of_property_match_string(eth->dev->of_node,
1093+
"memory-region-names", name);
1094+
if (index >= 0) {
1095+
struct reserved_mem *rmem;
1096+
struct device_node *np;
1097+
1098+
/* Consume reserved memory for hw forwarding buffers queue if
1099+
* available in the DTS
1100+
*/
1101+
np = of_parse_phandle(eth->dev->of_node, "memory-region",
1102+
index);
1103+
if (!np)
1104+
return -ENODEV;
1105+
1106+
rmem = of_reserved_mem_lookup(np);
1107+
of_node_put(np);
1108+
dma_addr = rmem->base;
1109+
} else {
1110+
size = AIROHA_MAX_PACKET_SIZE * HW_DSCP_NUM;
1111+
if (!dmam_alloc_coherent(eth->dev, size, &dma_addr,
1112+
GFP_KERNEL))
1113+
return -ENOMEM;
1114+
}
1115+
10891116
airoha_qdma_wr(qdma, REG_FWD_BUF_BASE, dma_addr);
10901117

10911118
airoha_qdma_rmw(qdma, REG_HW_FWD_DSCP_CFG,

0 commit comments

Comments
 (0)