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 <wei.fang@nxp.com>
Link: https://patch.msgid.link/20260522092438.1264020-13-wei.fang@nxp.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
Wei Fang 2026-05-22 17:24:38 +08:00 committed by Paolo Abeni
parent c55a33014b
commit 9d7b650888
3 changed files with 7 additions and 2 deletions

View File

@ -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

View File

@ -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];

View File

@ -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);