git: ab177386aa87 - stable/12 - e1000: Correct promisc multicast filter handling

Kevin Bowling kbowling at FreeBSD.org
Fri May 28 06:14:27 UTC 2021


The branch stable/12 has been updated by kbowling (ports committer):

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

commit ab177386aa8790c66826be227a1d9e6b482444bb
Author:     Kevin Bowling <kbowling at FreeBSD.org>
AuthorDate: 2021-04-16 23:15:50 +0000
Commit:     Kevin Bowling <kbowling at FreeBSD.org>
CommitDate: 2021-05-28 06:10:48 +0000

    e1000: Correct promisc multicast filter handling
    
    There are a number of issues in the e1000 multicast filter handling
    that have been present for a long time. Take the updated approach from
    ixgbe(4) which does not have the issues.
    
    The issues are outlined in the PR, in particular this solves crossing
    over and under the hardware's filter limit, not programming the
    hardware filter when we are above its limit, disabling SBP (show bad
    packets) when the tunable is enabled and exiting promiscuous mode, and
    an off-by-one error in the em_copy_maddr function.
    
    PR:             140647
    Reported by:    jtl
    Reviewed by:    markj
    MFC after:      1 month
    Differential Revision:  https://reviews.freebsd.org/D29789
    
    (cherry picked from commit 4b38eed76da9c36f09bff33b5cf15687cd99016f)
---
 sys/dev/e1000/if_em.c | 54 +++++++++++++++++++++++----------------------------
 1 file changed, 24 insertions(+), 30 deletions(-)

diff --git a/sys/dev/e1000/if_em.c b/sys/dev/e1000/if_em.c
index 819ae802e654..afafeed7602f 100644
--- a/sys/dev/e1000/if_em.c
+++ b/sys/dev/e1000/if_em.c
@@ -317,7 +317,6 @@ static int	em_enable_phy_wakeup(struct adapter *);
 static void	em_disable_aspm(struct adapter *);
 
 int		em_intr(void *arg);
-static void	em_disable_promisc(if_ctx_t ctx);
 
 /* MSI-X handlers */
 static int	em_if_msix_intr_assign(if_ctx_t, int);
@@ -1662,11 +1661,20 @@ static int
 em_if_set_promisc(if_ctx_t ctx, int flags)
 {
 	struct adapter *adapter = iflib_get_softc(ctx);
+	struct ifnet *ifp = iflib_get_ifp(ctx);
 	u32 reg_rctl;
-
-	em_disable_promisc(ctx);
+	int mcnt = 0;
 
 	reg_rctl = E1000_READ_REG(&adapter->hw, E1000_RCTL);
+	reg_rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_UPE);
+	if (flags & IFF_ALLMULTI)
+		mcnt = MAX_NUM_MULTICAST_ADDRESSES;
+	else
+		mcnt = if_multiaddr_count(ifp, MAX_NUM_MULTICAST_ADDRESSES);
+
+	if (mcnt < MAX_NUM_MULTICAST_ADDRESSES)
+		reg_rctl &= (~E1000_RCTL_MPE);
+	E1000_WRITE_REG(&adapter->hw, E1000_RCTL, reg_rctl);
 
 	if (flags & IFF_PROMISC) {
 		reg_rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
@@ -1682,42 +1690,19 @@ em_if_set_promisc(if_ctx_t ctx, int flags)
 	return (0);
 }
 
-static void
-em_disable_promisc(if_ctx_t ctx)
-{
-	struct adapter *adapter = iflib_get_softc(ctx);
-	struct ifnet *ifp = iflib_get_ifp(ctx);
-	u32 reg_rctl;
-	int mcnt = 0;
-
-	reg_rctl = E1000_READ_REG(&adapter->hw, E1000_RCTL);
-	reg_rctl &= (~E1000_RCTL_UPE);
-	if (if_getflags(ifp) & IFF_ALLMULTI)
-		mcnt = MAX_NUM_MULTICAST_ADDRESSES;
-	else
-		mcnt = if_multiaddr_count(ifp, MAX_NUM_MULTICAST_ADDRESSES);
-	/* Don't disable if in MAX groups */
-	if (mcnt < MAX_NUM_MULTICAST_ADDRESSES)
-		reg_rctl &=  (~E1000_RCTL_MPE);
-	reg_rctl &=  (~E1000_RCTL_SBP);
-	E1000_WRITE_REG(&adapter->hw, E1000_RCTL, reg_rctl);
-}
-
-
 /*********************************************************************
  *  Multicast Update
  *
  *  This routine is called whenever multicast address list is updated.
  *
  **********************************************************************/
-
 static void
 em_if_multi_set(if_ctx_t ctx)
 {
 	struct adapter *adapter = iflib_get_softc(ctx);
 	struct ifnet *ifp = iflib_get_ifp(ctx);
-	u32 reg_rctl = 0;
 	u8  *mta; /* Multicast array memory */
+	u32 reg_rctl = 0;
 	int mcnt = 0;
 
 	IOCTL_DEBUGOUT("em_set_multi: begin");
@@ -1737,11 +1722,20 @@ em_if_multi_set(if_ctx_t ctx)
 
 	if_multiaddr_array(ifp, mta, &mcnt, MAX_NUM_MULTICAST_ADDRESSES);
 
-	if (mcnt >= MAX_NUM_MULTICAST_ADDRESSES) {
-		reg_rctl = E1000_READ_REG(&adapter->hw, E1000_RCTL);
+	reg_rctl = E1000_READ_REG(&adapter->hw, E1000_RCTL);
+
+	if (if_getflags(ifp) & IFF_PROMISC)
+		reg_rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
+	else if (mcnt >= MAX_NUM_MULTICAST_ADDRESSES ||
+	    if_getflags(ifp) & IFF_ALLMULTI) {
 		reg_rctl |= E1000_RCTL_MPE;
-		E1000_WRITE_REG(&adapter->hw, E1000_RCTL, reg_rctl);
+		reg_rctl &= ~E1000_RCTL_UPE;
 	} else
+		reg_rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
+
+	E1000_WRITE_REG(&adapter->hw, E1000_RCTL, reg_rctl);
+
+	if (mcnt < MAX_NUM_MULTICAST_ADDRESSES)
 		e1000_update_mc_addr_list(&adapter->hw, mta, mcnt);
 
 	if (adapter->hw.mac.type == e1000_82542 &&


More information about the dev-commits-src-all mailing list