@@ -253,6 +253,48 @@ int rtl8366_reset_vlan(struct realtek_smi *smi)
}
EXPORT_SYMBOL_GPL(rtl8366_reset_vlan);
+static int rtl8366_set_default_vlan_and_pvid(struct realtek_smi *smi,
+ int port)
+{
+ u32 mask;
+ u16 vid;
+ int ret;
+
+ /* This is the reserved default VLAN for this port */
+ vid = port + 1;
+
+ if (port == smi->cpu_port)
+ /* For the CPU port, make all ports members of this
+ * VLAN.
+ */
+ mask = GENMASK((int)smi->num_ports - 1, 0);
+ else
+ /* For all other ports, enable itself plus the
+ * CPU port.
+ */
+ mask = BIT(port) | BIT(smi->cpu_port);
+
+ /* For each port, set the port as member of VLAN (port+1)
+ * and untagged, except for the CPU port: the CPU port (5) is
+ * member of VLAN 6 and so are ALL the other ports as well.
+ * Use filter 0 (no filter).
+ */
+ dev_info(smi->dev, "Set VLAN %04x portmask to %08x (port %d %s)\n",
+ vid, mask, port, (port == smi->cpu_port) ?
+ "CPU PORT and all other ports" : "and CPU port");
+ ret = rtl8366_set_vlan(smi, vid, mask, mask, 0);
+ if (ret)
+ return ret;
+
+ dev_info(smi->dev, "Set PVID %04x on port %d\n",
+ vid, port);
+ ret = rtl8366_set_pvid(smi, port, vid);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
int rtl8366_init_vlan(struct realtek_smi *smi)
{
int port;
@@ -266,33 +308,7 @@ int rtl8366_init_vlan(struct realtek_smi *smi)
* it with the VLAN (port+1)
*/
for (port = 0; port < smi->num_ports; port++) {
- u32 mask;
-
- if (port == smi->cpu_port)
- /* For the CPU port, make all ports members of this
- * VLAN.
- */
- mask = GENMASK((int)smi->num_ports - 1, 0);
- else
- /* For all other ports, enable itself plus the
- * CPU port.
- */
- mask = BIT(port) | BIT(smi->cpu_port);
-
- /* For each port, set the port as member of VLAN (port+1)
- * and untagged, except for the CPU port: the CPU port (5) is
- * member of VLAN 6 and so are ALL the other ports as well.
- * Use filter 0 (no filter).
- */
- dev_info(smi->dev, "VLAN%d port mask for port %d, %08x\n",
- (port + 1), port, mask);
- ret = rtl8366_set_vlan(smi, (port + 1), mask, mask, 0);
- if (ret)
- return ret;
-
- dev_info(smi->dev, "VLAN%d port %d, PVID set to %d\n",
- (port + 1), port, (port + 1));
- ret = rtl8366_set_pvid(smi, port, (port + 1));
+ ret = rtl8366_set_default_vlan_and_pvid(smi, port);
if (ret)
return ret;
}