]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: enetc: dynamically allocate rxmsg based on VF count
authorWei Fang <wei.fang@nxp.com>
Fri, 22 May 2026 09:24:38 +0000 (17:24 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 26 May 2026 11:20:13 +0000 (13:20 +0200)
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>
drivers/net/ethernet/freescale/enetc/enetc_hw.h
drivers/net/ethernet/freescale/enetc/enetc_pf.h
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c

index e58cc81d199d2a17c66a89d4ba4f3f0d3dcb1a3d..bf99b65d7598ab1029d86f41ed9a375909ba4182 100644 (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
index 64e2c738e8e7444c1f0c655ab55780aa4ada08ea..285b7e5c48fdc7f58867f1e7f4a463e277d8dedc 100644 (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];
 
index c423eed6bc789879d1c9f02843b0f3b218adda96..6e5d2f8699150beceded64f86f0423e471cb72de 100644 (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);