git: c7a2636889a6 - main - axgbe: Fix setting promisc mode

From: Zhenlei Huang <zlei_at_FreeBSD.org>
Date: Sat, 12 Oct 2024 13:58:38 UTC
The branch main has been updated by zlei:

URL: https://cgit.FreeBSD.org/src/commit/?id=c7a2636889a649985e323de23fe495608b6fe483

commit c7a2636889a649985e323de23fe495608b6fe483
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2024-10-12 13:56:56 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2024-10-12 13:56:56 +0000

    axgbe: Fix setting promisc mode
    
    Ethernet drivers should respect IFF_PROMISC rather than IFF_PPROMISC.
    The latter is for user-requested promisc mode, it implies the former
    but not vice versa. Some in-kernel components such as if_bridge(4) and
    bpf(4) will set promisc mode for interfaces on-demand.
    
    While here, update the debugging message to be not confusing.
    
    This was spotted while reviewing markj@ 's work D46524.
    
    Test from Franco shows that the interface seems to be unconditionally
    initialized to promisc mode regardless of this fix. That needs further
    investigation.
    
    Reviewed by:    markj, Franco Fichtner <franco@opnsense.org>
    Tested by:      Franco Fichtner <franco@opnsense.org>
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D46794
---
 sys/dev/axgbe/if_axgbe_pci.c | 10 ++++++----
 sys/dev/axgbe/xgbe-dev.c     |  2 +-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/sys/dev/axgbe/if_axgbe_pci.c b/sys/dev/axgbe/if_axgbe_pci.c
index d3078a1c33c1..290156ff11ca 100644
--- a/sys/dev/axgbe/if_axgbe_pci.c
+++ b/sys/dev/axgbe/if_axgbe_pci.c
@@ -2363,11 +2363,11 @@ axgbe_if_promisc_set(if_ctx_t ctx, int flags)
 
 	axgbe_printf(1, "%s: MAC_PFR 0x%x drv_flags 0x%x if_flags 0x%x\n",
 	    __func__, XGMAC_IOREAD(pdata, MAC_PFR), if_getdrvflags(ifp),
-	    if_getflags(ifp));
+	    flags);
 
-	if (if_getflags(ifp) & IFF_PPROMISC) {
+	if (flags & IFF_PROMISC) {
 
-		axgbe_printf(1, "User requested to enter promisc mode\n");
+		axgbe_printf(1, "Requested to enter promisc mode\n");
 
 		if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == 1) {
 			axgbe_printf(1, "Already in promisc mode\n");
@@ -2376,10 +2376,11 @@ axgbe_if_promisc_set(if_ctx_t ctx, int flags)
 
 		axgbe_printf(1, "Entering promisc mode\n");
 		XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, 1);
+		/* Disable VLAN filtering */
 		XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0);
 	} else {
 
-		axgbe_printf(1, "User requested to leave promisc mode\n");
+		axgbe_printf(1, "Requested to leave promisc mode\n");
 
 		if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == 0) {
 			axgbe_printf(1, "Already not in promisc mode\n");
@@ -2388,6 +2389,7 @@ axgbe_if_promisc_set(if_ctx_t ctx, int flags)
 
 		axgbe_printf(1, "Leaving promisc mode\n");
 		XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, 0);
+		/* Enable VLAN filtering */
 		XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1);
 	}
 
diff --git a/sys/dev/axgbe/xgbe-dev.c b/sys/dev/axgbe/xgbe-dev.c
index 3a7d683ea5a9..48f3f2b587f0 100644
--- a/sys/dev/axgbe/xgbe-dev.c
+++ b/sys/dev/axgbe/xgbe-dev.c
@@ -970,7 +970,7 @@ xgbe_config_rx_mode(struct xgbe_prv_data *pdata)
 {
 	unsigned int pr_mode, am_mode;
 
-	pr_mode = ((if_getflags(pdata->netdev) & IFF_PPROMISC) != 0);
+	pr_mode = ((if_getflags(pdata->netdev) & IFF_PROMISC) != 0);
 	am_mode = ((if_getflags(pdata->netdev) & IFF_ALLMULTI) != 0);
 
 	xgbe_set_promiscuous_mode(pdata, pr_mode);