blob: 7769ebddc3a5402db6815c6fa87919e4a40829ed [file] [log] [blame]
developerd8b297a2021-06-28 19:15:10 +08001Index: linux-5.4.124/drivers/net/dsa/mt7530.c
2===================================================================
3--- linux-5.4.124.orig/drivers/net/dsa/mt7530.c
4+++ linux-5.4.124/drivers/net/dsa/mt7530.c
5@@ -1021,6 +1021,9 @@ mt7530_stp_state_set(struct dsa_switch *
6 struct mt7530_priv *priv = ds->priv;
7 u32 stp_state;
8
9+ if (dsa_is_unused_port(ds, port))
10+ return;
11+
12 switch (state) {
13 case BR_STATE_DISABLED:
14 stp_state = MT7530_STP_DISABLED;
15@@ -1676,10 +1679,58 @@ mt7530_setup(struct dsa_switch *ds)
16 }
17
18 static int
19+setup_unused_ports(struct dsa_switch *ds, u32 pm)
20+{
21+ struct mt7530_priv *priv = ds->priv;
22+ u32 egtag_mask = 0;
23+ u32 egtag_val = 0;
24+ int i;
25+
26+ if (!pm)
27+ return 0;
28+
29+ for (i = 0; i < MT7530_NUM_PORTS; i++) {
30+ if (!dsa_is_unused_port(ds, i))
31+ continue;
32+
33+ /* Setup MAC port with maximum capability. */
34+ if ((i == 5) || (i == 6))
35+ if (priv->info->cpu_port_config)
36+ priv->info->cpu_port_config(ds, i);
37+
38+ mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK | PCR_PORT_VLAN_MASK,
39+ PCR_MATRIX(pm) | MT7530_PORT_SECURITY_MODE);
40+ egtag_mask |= ETAG_CTRL_P_MASK(i);
41+ egtag_val |= ETAG_CTRL_P(i, MT7530_VLAN_EGRESS_UNTAG);
42+ }
43+
44+ /* Add unused ports to VLAN2 group for using IVL fdb. */
45+ mt7530_write(priv, MT7530_VAWD1,
46+ IVL_MAC | VTAG_EN | PORT_MEM(pm) | VLAN_VALID);
47+ mt7530_rmw(priv, MT7530_VAWD2, egtag_mask, egtag_val);
48+ mt7530_vlan_cmd(priv, MT7530_VTCR_WR_VID, MT753X_RESERVED_VLAN);
49+
50+ for (i = 0; i < MT7530_NUM_PORTS; i++) {
51+ if (!dsa_is_unused_port(ds, i))
52+ continue;
53+
54+ mt7530_rmw(priv, MT7530_PPBV1_P(i), G0_PORT_VID_MASK,
55+ G0_PORT_VID(MT753X_RESERVED_VLAN));
56+ mt7530_rmw(priv, MT7530_SSP_P(i), FID_PST_MASK, MT7530_STP_FORWARDING);
57+
58+ dev_dbg(ds->dev, "Add unused port%d to reserved VLAN%d group\n",
59+ i, MT753X_RESERVED_VLAN);
60+ }
61+
62+ return 0;
63+}
64+
65+static int
66 mt7531_setup(struct dsa_switch *ds)
67 {
68 struct mt7530_priv *priv = ds->priv;
69 struct mt7530_dummy_poll p;
70+ u32 unused_pm = 0;
71 u32 val, id;
72 int ret, i;
73
74@@ -1767,7 +1818,9 @@ mt7531_setup(struct dsa_switch *ds)
75
76 mt7530_set(priv, MT7531_DBG_CNT(i), MT7531_DIS_CLR);
77
78- if (dsa_is_cpu_port(ds, i))
79+ if (dsa_is_unused_port(ds, i))
80+ unused_pm |= BIT(i);
81+ else if (dsa_is_cpu_port(ds, i))
82 mt753x_cpu_port_enable(ds, i);
83 else
84 mt7530_port_disable(ds, i);
85@@ -1777,6 +1830,9 @@ mt7531_setup(struct dsa_switch *ds)
86 PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT));
87 }
88
89+ /* Group and enable unused ports as a standalone dumb switch. */
90+ setup_unused_ports(ds, unused_pm);
91+
92 ds->configure_vlan_while_not_filtering = true;
93
94 /* Flush the FDB table */
95@@ -2101,7 +2157,7 @@ mt7531_mac_config(struct dsa_switch *ds,
96 case PHY_INTERFACE_MODE_RGMII_RXID:
97 case PHY_INTERFACE_MODE_RGMII_TXID:
98 dp = dsa_to_port(ds, port);
99- phydev = dp->slave->phydev;
100+ phydev = (dp->slave) ? dp->slave->phydev : NULL;
101 return mt7531_rgmii_setup(priv, port, interface, phydev);
102 case PHY_INTERFACE_MODE_SGMII:
103 return mt7531_sgmii_setup_mode_an(priv, port, interface);
104@@ -2641,7 +2697,7 @@ mt7530_probe(struct mdio_device *mdiodev
105 if (!priv)
106 return -ENOMEM;
107
108- priv->ds = dsa_switch_alloc(&mdiodev->dev, DSA_MAX_PORTS);
109+ priv->ds = dsa_switch_alloc(&mdiodev->dev, MT7530_NUM_PORTS);
110 if (!priv->ds)
111 return -ENOMEM;
112
113Index: linux-5.4.124/drivers/net/dsa/mt7530.h
114===================================================================
115--- linux-5.4.124.orig/drivers/net/dsa/mt7530.h
116+++ linux-5.4.124/drivers/net/dsa/mt7530.h
117@@ -10,6 +10,7 @@
118 #define MT7530_CPU_PORT 6
119 #define MT7530_NUM_FDB_RECORDS 2048
120 #define MT7530_ALL_MEMBERS 0xff
121+#define MT753X_RESERVED_VLAN 2
122
123 enum mt753x_id {
124 ID_MT7530 = 0,