From e7abb897018be34f039ad957562fdc2f38aa3562 Mon Sep 17 00:00:00 2001 From: Kristof Provost Date: Thu, 11 Aug 2022 14:45:01 +0200 Subject: [PATCH] ixgbe: fix software vlan handling If hardware vlan tagging is disabled (after a vlan has been added) we receive double-tagged packets, even if the packet on the wire only has a single VLAN tag. That looks like this: 17:29:30.370787 00:51:82:11:22:02 > 90:ec:77:1f:8a:5f, ethertype 802.1Q (0x8100), length 64: vlan 0, p 0, ethertype 802.1Q, vlan 1001, p 0, ethertype ARP, Ethernet (len 6), IPv4 (len 4), Reply 10.101.0.12 is-at 00:51:82:11:22:02, length 42 This happens because the ixgbe driver does not clear the vlan flags in the hardware (such as IXGBE_RXDCTL_VME) if IFCAP_VLAN_HWTAGGING is cleared. Add code to do so, which fixes this issue. Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D36139 --- sys/dev/ixgbe/if_ix.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/sys/dev/ixgbe/if_ix.c b/sys/dev/ixgbe/if_ix.c index ae5c65894f83..54008a24074b 100644 --- a/sys/dev/ixgbe/if_ix.c +++ b/sys/dev/ixgbe/if_ix.c @@ -1925,8 +1925,27 @@ ixgbe_setup_vlan_hw_support(if_ctx_t ctx) * the VFTA and other state, so if there * have been no vlan's registered do nothing. */ - if (sc->num_vlans == 0) + if (sc->num_vlans == 0 || (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) == 0) { + /* Clear the vlan hw flag */ + for (i = 0; i < sc->num_rx_queues; i++) { + rxr = &sc->rx_queues[i].rxr; + /* On 82599 the VLAN enable is per/queue in RXDCTL */ + if (hw->mac.type != ixgbe_mac_82598EB) { + ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxr->me)); + ctrl &= ~IXGBE_RXDCTL_VME; + IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rxr->me), ctrl); + } + rxr->vtag_strip = false; + } + ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); + /* Enable the Filter Table if enabled */ + ctrl |= IXGBE_VLNCTRL_CFIEN; + ctrl &= ~IXGBE_VLNCTRL_VFE; + if (hw->mac.type == ixgbe_mac_82598EB) + ctrl &= ~IXGBE_VLNCTRL_VME; + IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl); return; + } /* Setup the queues for vlans */ if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) {