From: Wei Fang Date: Fri, 22 May 2026 09:24:38 +0000 (+0800) Subject: net: enetc: dynamically allocate rxmsg based on VF count X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d7b650888ff532f3d2f92722143c39ab780a6f6;p=thirdparty%2Flinux.git net: enetc: dynamically allocate rxmsg based on VF count 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 Link: https://patch.msgid.link/20260522092438.1264020-13-wei.fang@nxp.com Signed-off-by: Paolo Abeni --- diff --git a/drivers/net/ethernet/freescale/enetc/enetc_hw.h b/drivers/net/ethernet/freescale/enetc/enetc_hw.h index e58cc81d199d..bf99b65d7598 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_hw.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_hw.h @@ -681,7 +681,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 64e2c738e8e7..285b7e5c48fd 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.h +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.h @@ -43,7 +43,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 c423eed6bc78..6e5d2f869915 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c @@ -443,6 +443,12 @@ int enetc_init_sriov_resources(struct enetc_pf *pf) if (!pf->total_vfs) return 0; + pf->rxmsg = devm_kcalloc(dev, pf->total_vfs, + sizeof(struct enetc_msg_swbd), + GFP_KERNEL); + if (!pf->rxmsg) + return -ENOMEM; + pf->vf_state = devm_kcalloc(dev, pf->total_vfs, sizeof(struct enetc_vf_state), GFP_KERNEL);