Skip to content

Commit 60c007b

Browse files
bwh-mindgregkh
authored andcommitted
net: dsa: microchip: ksz8795: Fix PVID tag insertion
commit ef3b02a upstream. ksz8795 has never actually enabled PVID tag insertion, and it also programmed the PVID incorrectly. To fix this: * Allow tag insertion to be controlled per ingress port. On most chips, set bit 2 in Global Control 19. On KSZ88x3 this control flag doesn't exist. * When adding a PVID: - Set the appropriate register bits to enable tag insertion on egress at every other port if this was the packet's ingress port. - Mask *out* the VID from the default tag, before or-ing in the new PVID. * When removing a PVID: - Clear the same control bits to disable tag insertion. - Don't update the default tag. This wasn't doing anything useful. Fixes: e66f840 ("net: dsa: ksz: Add Microchip KSZ8795 DSA driver") Signed-off-by: Ben Hutchings <ben.hutchings@mind.be> Signed-off-by: David S. Miller <davem@davemloft.net> [bwh: Backport to 5.10: - Drop the KSZ88x3 cases as those chips are not supported here - Handle VID ranges in ksz8795_port_vlan_del()] Signed-off-by: Ben Hutchings <ben.hutchings@mind.be> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f365d53 commit 60c007b

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

drivers/net/dsa/microchip/ksz8795.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -833,9 +833,11 @@ static void ksz8795_port_vlan_add(struct dsa_switch *ds, int port,
833833

834834
if (new_pvid) {
835835
ksz_pread16(dev, port, REG_PORT_CTRL_VID, &vid);
836-
vid &= 0xfff;
836+
vid &= ~VLAN_VID_MASK;
837837
vid |= new_pvid;
838838
ksz_pwrite16(dev, port, REG_PORT_CTRL_VID, vid);
839+
840+
ksz_pwrite8(dev, port, REG_PORT_CTRL_12, 0x0f);
839841
}
840842
}
841843

@@ -844,8 +846,9 @@ static int ksz8795_port_vlan_del(struct dsa_switch *ds, int port,
844846
{
845847
bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
846848
struct ksz_device *dev = ds->priv;
847-
u16 data, vid, pvid, new_pvid = 0;
849+
u16 data, vid, pvid;
848850
u8 fid, member, valid;
851+
bool del_pvid = false;
849852

850853
ksz_pread16(dev, port, REG_PORT_CTRL_VID, &pvid);
851854
pvid = pvid & 0xFFF;
@@ -865,14 +868,14 @@ static int ksz8795_port_vlan_del(struct dsa_switch *ds, int port,
865868
}
866869

867870
if (pvid == vid)
868-
new_pvid = 1;
871+
del_pvid = true;
869872

870873
ksz8795_to_vlan(fid, member, valid, &data);
871874
ksz8795_w_vlan_table(dev, vid, data);
872875
}
873876

874-
if (new_pvid != pvid)
875-
ksz_pwrite16(dev, port, REG_PORT_CTRL_VID, pvid);
877+
if (del_pvid)
878+
ksz_pwrite8(dev, port, REG_PORT_CTRL_12, 0x00);
876879

877880
return 0;
878881
}
@@ -1085,6 +1088,8 @@ static int ksz8795_setup(struct dsa_switch *ds)
10851088

10861089
ksz_cfg(dev, S_MIRROR_CTRL, SW_MIRROR_RX_TX, false);
10871090

1091+
ksz_cfg(dev, REG_SW_CTRL_19, SW_INS_TAG_ENABLE, true);
1092+
10881093
/* set broadcast storm protection 10% rate */
10891094
regmap_update_bits(dev->regmap[1], S_REPLACE_VID_CTRL,
10901095
BROADCAST_STORM_RATE,

0 commit comments

Comments
 (0)