[PATCH net-next 13/15] net: enetc: dynamically allocate rxmsg based on VF count

From: Wei Fang

Date: Mon May 11 2026 - 04:38:41 EST


The constant ENETC_MAX_NUM_VFS is defined as 2 when enabling support for
LS1028A. This works for LS1028A because its ENETC hardware supports up
to 2 VFs. However, ENETC v4 has varying VF capabilities depending on the
SoC:

i.MX94 standalone ENETC: 0 VFs
i.MX94 internal ENETC: 3 VFs
i.MX952: 1 VF

Using a fixed ENETC_MAX_NUM_VFS for memory allocation leads to
over-allocation on SoCs with fewer or no VF support. To better match
hardware capabilities and avoid unnecessary memory usage, change rxmsg
memory allocation from a fixed-size array to dynamic allocation based
on the actual VF count retrieved via pci_sriov_get_totalvfs().

Signed-off-by: Wei Fang <wei.fang@xxxxxxx>
---
drivers/net/ethernet/freescale/enetc/enetc_hw.h | 1 -
drivers/net/ethernet/freescale/enetc/enetc_pf.h | 2 +-
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c | 6 ++++++
3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc_hw.h b/drivers/net/ethernet/freescale/enetc/enetc_hw.h
index 662e4fbafb74..94f53762cea8 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_hw.h
+++ b/drivers/net/ethernet/freescale/enetc/enetc_hw.h
@@ -672,7 +672,6 @@ union enetc_rx_bd {

#define ENETC_MAC_ADDR_FILT_CNT 8 /* # of supported entries per port */
#define EMETC_MAC_ADDR_FILT_RES 3 /* # of reserved entries at the beginning */
-#define ENETC_MAX_NUM_VFS 2

#define ENETC_CBD_FLAGS_SF BIT(7) /* short format */
#define ENETC_CBD_STATUS_MASK 0xf
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.h b/drivers/net/ethernet/freescale/enetc/enetc_pf.h
index 9fcf1c58d59b..d4f1041587f7 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf.h
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.h
@@ -42,7 +42,7 @@ struct enetc_pf {

struct enetc_mac_filter mac_filter[MADDR_TYPE];

- struct enetc_msg_swbd rxmsg[ENETC_MAX_NUM_VFS];
+ struct enetc_msg_swbd *rxmsg;
struct work_struct msg_task;
char msg_int_name[ENETC_INT_NAME_MAX];

diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c
index 60a330ee03b7..43225aaab54e 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c
@@ -449,6 +449,12 @@ int enetc_init_sriov_resources(struct enetc_pf *pf)
if (!pf->vf_state)
return -ENOMEM;

+ pf->rxmsg = devm_kcalloc(dev, pf->total_vfs,
+ sizeof(struct enetc_msg_swbd),
+ GFP_KERNEL);
+ if (!pf->rxmsg)
+ return -ENOMEM;
+
return 0;
}
EXPORT_SYMBOL_GPL(enetc_init_sriov_resources);
--
2.34.1