• Vladimir Oltean's avatar
    net: mscc: ocelot: allow a config where all bridge VLANs are egress-untagged · 0da1a1c4
    Vladimir Oltean authored
    At present, the ocelot driver accepts a single egress-untagged bridge
    VLAN, meaning that this sequence of operations:
    
    ip link add br0 type bridge vlan_filtering 1
    ip link set swp0 master br0
    bridge vlan add dev swp0 vid 2 pvid untagged
    
    fails because the bridge automatically installs VID 1 as a pvid & untagged
    VLAN, and vid 2 would be the second untagged VLAN on this port. It is
    necessary to delete VID 1 before proceeding to add VID 2.
    
    This limitation comes from the fact that we operate the port tag, when
    it has an egress-untagged VID, in the OCELOT_PORT_TAG_NATIVE mode.
    The ocelot switches do not have full flexibility and can either have one
    single VID as egress-untagged, or all of them.
    
    There are use cases for having all VLANs as egress-untagged as well, and
    this patch adds support for that.
    
    The change rewrites ocelot_port_set_native_vlan() into a more generic
    ocelot_port_manage_port_tag() function. Because the software bridge's
    state, transmitted to us via switchdev, can become very complex, we
    don't attempt to track all possible state transitions, but instead take
    a more declarative approach and just make ocelot_port_manage_port_tag()
    figure out which more to operate in:
    
    - port is VLAN-unaware: the classified VLAN (internal, unrelated to the
                            802.1Q header) is not inserted into packets on egress
    - port is VLAN-aware:
      - port has tagged VLANs:
        -> port has no untagged VLAN: set up as pure trunk
        -> port has one untagged VLAN: set up as trunk port + native VLAN
        -> port has more than one untagged VLAN: this is an invalid config
           which is rejected by ocelot_vlan_prepare
      - port has no tagged VLANs
        -> set up as pure egress-untagged port
    
    We don't keep the number of tagged and untagged VLANs, we just count the
    structures we keep.
    Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    0da1a1c4
ocelot.h 26.6 KB