ramips: switch to linux 4.14
[openwrt/openwrt.git] / target / linux / ramips / files-4.9 / drivers / net / ethernet / mtk / mt7530.c
index e61f9fd8d32e5e2deb66f9bb79ef35497d439dbb..5216cb5c6618d018c4075791037cf91bb0398795 100644 (file)
@@ -478,6 +478,14 @@ mt7530_set_vid(struct switch_dev *dev, const struct switch_attr *attr,
        return 0;
 }
 
+static int
+mt7621_get_vid(struct switch_dev *dev, const struct switch_attr *attr,
+               struct switch_val *val)
+{
+       val->value.i = val->port_vlan;
+       return 0;
+}
+
 static int
 mt7530_get_vid(struct switch_dev *dev, const struct switch_attr *attr,
                struct switch_val *val)
@@ -616,10 +624,16 @@ mt7530_apply_config(struct switch_dev *dev)
 
        /* Port Default PVID */
        for (i = 0; i < MT7530_NUM_PORTS; i++) {
+               int vlan = priv->port_entries[i].pvid;
+               u16 pvid = 0;
                u32 val;
+
+               if (vlan < MT7530_NUM_VLANS && priv->vlan_entries[vlan].member)
+                       pvid = priv->vlan_entries[vlan].vid;
+
                val = mt7530_r32(priv, REG_ESW_PORT_PPBV1(i));
                val &= ~0xfff;
-               val |= priv->port_entries[i].pvid;
+               val |= pvid;
                mt7530_w32(priv, REG_ESW_PORT_PPBV1(i), val);
        }
 
@@ -829,6 +843,17 @@ static const struct switch_attr mt7621_port[] = {
        },
 };
 
+static const struct switch_attr mt7621_vlan[] = {
+       {
+               .type = SWITCH_TYPE_INT,
+               .name = "vid",
+               .description = "VLAN ID (0-4094)",
+               .set = mt7530_set_vid,
+               .get = mt7621_get_vid,
+               .max = 4094,
+       },
+};
+
 static const struct switch_attr mt7530_port[] = {
        {
                .type = SWITCH_TYPE_STRING,
@@ -860,8 +885,8 @@ static const struct switch_dev_ops mt7621_ops = {
                .n_attr = ARRAY_SIZE(mt7621_port),
        },
        .attr_vlan = {
-               .attr = mt7530_vlan,
-               .n_attr = ARRAY_SIZE(mt7530_vlan),
+               .attr = mt7621_vlan,
+               .n_attr = ARRAY_SIZE(mt7621_vlan),
        },
        .get_vlan_ports = mt7530_get_vlan_ports,
        .set_vlan_ports = mt7530_set_vlan_ports,