Skip to content

Commit e3386ec

Browse files
CHKDSK88kuba-moo
authored andcommitted
net: dsa: vsc73xx: Implement the tag_8021q VLAN operations
This patch is a simple implementation of 802.1q tagging in the vsc73xx driver. Currently, devices with DSA_TAG_PROTO_NONE are not functional. The VSC73XX family doesn't provide any tag support for external Ethernet ports. The only option available is VLAN-based tagging, which requires constant hardware VLAN filtering. While the VSC73XX family supports provider bridging, it only supports QinQ without full implementation of 802.1AD. This means it only allows the doubled 0x8100 TPID. In the simple port mode, QinQ is enabled to preserve forwarding of VLAN-tagged frames. Signed-off-by: Pawel Dembicki <[email protected]> Reviewed-by: Vladimir Oltean <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 6c87e1a commit e3386ec

File tree

2 files changed

+71
-4
lines changed

2 files changed

+71
-4
lines changed

drivers/net/dsa/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ config NET_DSA_SMSC_LAN9303_MDIO
127127

128128
config NET_DSA_VITESSE_VSC73XX
129129
tristate
130-
select NET_DSA_TAG_NONE
130+
select NET_DSA_TAG_VSC73XX_8021Q
131131
select FIXED_PHY
132132
select VITESSE_PHY
133133
select GPIOLIB

drivers/net/dsa/vitesse-vsc73xx-core.c

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ static enum dsa_tag_protocol vsc73xx_get_tag_protocol(struct dsa_switch *ds,
597597
* cannot access the tag. (See "Internal frame header" section
598598
* 3.9.1 in the manual.)
599599
*/
600-
return DSA_TAG_PROTO_NONE;
600+
return DSA_TAG_PROTO_VSC73XX_8021Q;
601601
}
602602

603603
static int vsc73xx_wait_for_vlan_table_cmd(struct vsc73xx *vsc)
@@ -687,7 +687,7 @@ vsc73xx_update_vlan_table(struct vsc73xx *vsc, int port, u16 vid, bool set)
687687
static int vsc73xx_setup(struct dsa_switch *ds)
688688
{
689689
struct vsc73xx *vsc = ds->priv;
690-
int i;
690+
int i, ret;
691691

692692
dev_info(vsc->dev, "set up the switch\n");
693693

@@ -768,7 +768,18 @@ static int vsc73xx_setup(struct dsa_switch *ds)
768768

769769
INIT_LIST_HEAD(&vsc->vlans);
770770

771-
return 0;
771+
rtnl_lock();
772+
ret = dsa_tag_8021q_register(ds, htons(ETH_P_8021Q));
773+
rtnl_unlock();
774+
775+
return ret;
776+
}
777+
778+
static void vsc73xx_teardown(struct dsa_switch *ds)
779+
{
780+
rtnl_lock();
781+
dsa_tag_8021q_unregister(ds);
782+
rtnl_unlock();
772783
}
773784

774785
static void vsc73xx_init_port(struct vsc73xx *vsc, int port)
@@ -1549,12 +1560,65 @@ static int vsc73xx_port_vlan_del(struct dsa_switch *ds, int port,
15491560
vsc73xx_bridge_vlan_remove_port(vsc73xx_vlan, port);
15501561

15511562
commit_to_hardware = !vsc73xx_tag_8021q_active(dsa_to_port(ds, port));
1563+
15521564
if (commit_to_hardware)
15531565
return vsc73xx_vlan_commit_settings(vsc, port);
15541566

15551567
return 0;
15561568
}
15571569

1570+
static int vsc73xx_tag_8021q_vlan_add(struct dsa_switch *ds, int port, u16 vid,
1571+
u16 flags)
1572+
{
1573+
bool pvid = flags & BRIDGE_VLAN_INFO_PVID;
1574+
struct vsc73xx_portinfo *portinfo;
1575+
struct vsc73xx *vsc = ds->priv;
1576+
bool commit_to_hardware;
1577+
int ret;
1578+
1579+
portinfo = &vsc->portinfo[port];
1580+
1581+
if (pvid) {
1582+
portinfo->pvid_tag_8021q_configured = true;
1583+
portinfo->pvid_tag_8021q = vid;
1584+
}
1585+
1586+
commit_to_hardware = vsc73xx_tag_8021q_active(dsa_to_port(ds, port));
1587+
if (commit_to_hardware) {
1588+
ret = vsc73xx_vlan_commit_settings(vsc, port);
1589+
if (ret)
1590+
return ret;
1591+
}
1592+
1593+
return vsc73xx_update_vlan_table(vsc, port, vid, true);
1594+
}
1595+
1596+
static int vsc73xx_tag_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid)
1597+
{
1598+
struct vsc73xx_portinfo *portinfo;
1599+
struct vsc73xx *vsc = ds->priv;
1600+
1601+
portinfo = &vsc->portinfo[port];
1602+
1603+
if (portinfo->pvid_tag_8021q_configured &&
1604+
portinfo->pvid_tag_8021q == vid) {
1605+
struct dsa_port *dp = dsa_to_port(ds, port);
1606+
bool commit_to_hardware;
1607+
int err;
1608+
1609+
portinfo->pvid_tag_8021q_configured = false;
1610+
1611+
commit_to_hardware = vsc73xx_tag_8021q_active(dp);
1612+
if (commit_to_hardware) {
1613+
err = vsc73xx_vlan_commit_settings(vsc, port);
1614+
if (err)
1615+
return err;
1616+
}
1617+
}
1618+
1619+
return vsc73xx_update_vlan_table(vsc, port, vid, false);
1620+
}
1621+
15581622
static void vsc73xx_refresh_fwd_map(struct dsa_switch *ds, int port, u8 state)
15591623
{
15601624
struct dsa_port *other_dp, *dp = dsa_to_port(ds, port);
@@ -1644,6 +1708,7 @@ static const struct phylink_mac_ops vsc73xx_phylink_mac_ops = {
16441708
static const struct dsa_switch_ops vsc73xx_ds_ops = {
16451709
.get_tag_protocol = vsc73xx_get_tag_protocol,
16461710
.setup = vsc73xx_setup,
1711+
.teardown = vsc73xx_teardown,
16471712
.phy_read = vsc73xx_phy_read,
16481713
.phy_write = vsc73xx_phy_write,
16491714
.get_strings = vsc73xx_get_strings,
@@ -1658,6 +1723,8 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = {
16581723
.port_vlan_add = vsc73xx_port_vlan_add,
16591724
.port_vlan_del = vsc73xx_port_vlan_del,
16601725
.phylink_get_caps = vsc73xx_phylink_get_caps,
1726+
.tag_8021q_vlan_add = vsc73xx_tag_8021q_vlan_add,
1727+
.tag_8021q_vlan_del = vsc73xx_tag_8021q_vlan_del,
16611728
};
16621729

16631730
static int vsc73xx_gpio_get(struct gpio_chip *chip, unsigned int offset)

0 commit comments

Comments
 (0)