diff mbox series

[net,2/2] net: enetc: prevent PF from configuring MAC address for an enabled VF

Message ID 20241031060247.1290941-3-wei.fang@nxp.com (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series Fix issues when PF sets MAC address for VF | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-10-31--09-00 (tests: 779)

Commit Message

Wei Fang Oct. 31, 2024, 6:02 a.m. UTC
If PF changes the MAC address of VF after VF is enabled, VF cannot sense
the change of its own MAC address, and the MAC address in VF's net_device
is still the original MAC address, which will cause the VF's network to
not work properly. Therefore, we should restrict PF to configure VF's MAC
address only when VF is disabled.

Of course, another solution is to notify VF of this event when PF changes
VF's MAC address, but the PSI-to-VSI messaging is not implemented in the
current PF and VF drivers, so this solution is not suitable at present,
If PSI-to-VSI messaging is supported in the future, we can remove the
current restriction to enhance the PF's ability to configure the VF's MAC
address.

Fixes: d4fd0404c1c9 ("enetc: Introduce basic PF and VF ENETC ethernet drivers")
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
 drivers/net/ethernet/freescale/enetc/enetc_pf.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
index c95a7c083b0f..a295236cd931 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
@@ -343,11 +343,18 @@  static int enetc_pf_set_vf_mac(struct net_device *ndev, int vf, u8 *mac)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
 	struct enetc_pf *pf = enetc_si_priv(priv->si);
+	struct device *dev = &pf->si->pdev->dev;
 	struct enetc_vf_state *vf_state;
 
 	if (vf >= pf->total_vfs)
 		return -EINVAL;
 
+	if (vf + 1 <= pf->num_vfs) {
+		dev_err(dev, "Cannot set MAC address for an enabled VF\n");
+
+		return -EPERM;
+	}
+
 	if (!is_valid_ether_addr(mac))
 		return -EADDRNOTAVAIL;