mediatek: add DSA multi cpu port support
[openwrt/openwrt.git] / target / linux / mediatek / patches-4.9 / 0097-dsa-mt7530.patch
1 Index: linux-4.9.20/drivers/net/dsa/mt7530.c
2 ===================================================================
3 --- linux-4.9.20.orig/drivers/net/dsa/mt7530.c
4 +++ linux-4.9.20/drivers/net/dsa/mt7530.c
5 @@ -627,7 +627,7 @@ mt7530_setup(struct dsa_switch *ds)
6
7 /* Enable Port 6 only; P5 as GMAC5 which currently is not supported */
8 val = mt7530_read(priv, MT7530_MHWTRAP);
9 - val &= ~MHWTRAP_P6_DIS & ~MHWTRAP_PHY_ACCESS;
10 + val &= ~MHWTRAP_P5_DIS & ~MHWTRAP_P6_DIS & ~MHWTRAP_PHY_ACCESS;
11 val |= MHWTRAP_MANUAL;
12 if (!dsa_is_cpu_port(ds, 5)) {
13 val |= MHWTRAP_P5_DIS;
14 @@ -735,6 +735,9 @@ static int
15 mt7530_cpu_port_enable(struct mt7530_priv *priv,
16 int port)
17 {
18 + u8 port_mask = 0;
19 + int i;
20 +
21 /* Enable Mediatek header mode on the cpu port */
22 mt7530_write(priv, MT7530_PVC_P(port),
23 PORT_SPEC_TAG);
24 @@ -751,8 +754,12 @@ mt7530_cpu_port_enable(struct mt7530_pri
25 /* CPU port gets connected to all user ports of
26 * the switch
27 */
28 + for (i = 0; i < MT7530_NUM_PORTS; i++)
29 + if ((priv->ds->enabled_port_mask & BIT(i)) &&
30 + (dsa_port_upstream_port(priv->ds, i) == port))
31 + port_mask |= BIT(i);
32 mt7530_write(priv, MT7530_PCR_P(port),
33 - PCR_MATRIX(priv->ds->enabled_port_mask));
34 + PCR_MATRIX(port_mask));
35
36 return 0;
37 }
38 @@ -762,6 +769,7 @@ mt7530_port_enable(struct dsa_switch *ds
39 struct phy_device *phy)
40 {
41 struct mt7530_priv *priv = ds->priv;
42 + u8 upstream = dsa_port_upstream_port(ds, port);
43
44 mutex_lock(&priv->reg_mutex);
45
46 @@ -772,7 +780,7 @@ mt7530_port_enable(struct dsa_switch *ds
47 * restore the port matrix if the port is the member of a certain
48 * bridge.
49 */
50 - priv->ports[port].pm |= PCR_MATRIX(BIT(MT7530_CPU_PORT));
51 + priv->ports[port].pm |= PCR_MATRIX(BIT(upstream));
52 priv->ports[port].enable = true;
53 mt7530_rmw(priv, MT7530_PCR_P(port), PCR_MATRIX_MASK,
54 priv->ports[port].pm);
55 @@ -835,7 +843,8 @@ mt7530_port_bridge_join(struct dsa_switc
56 struct net_device *bridge)
57 {
58 struct mt7530_priv *priv = ds->priv;
59 - u32 port_bitmap = BIT(MT7530_CPU_PORT);
60 + u8 upstream = dsa_port_upstream_port(ds, port);
61 + u32 port_bitmap = BIT(upstream);
62 int i;
63
64 mutex_lock(&priv->reg_mutex);
65 @@ -873,6 +882,7 @@ static void
66 mt7530_port_bridge_leave(struct dsa_switch *ds, int port)
67 {
68 struct mt7530_priv *priv = ds->priv;
69 + u8 upstream = dsa_port_upstream_port(ds, port);
70 int i;
71
72 mutex_lock(&priv->reg_mutex);
73 @@ -898,8 +908,8 @@ mt7530_port_bridge_leave(struct dsa_swit
74 priv->bridge_dev[port] = NULL;
75 if (priv->ports[port].enable)
76 mt7530_rmw(priv, MT7530_PCR_P(port), PCR_MATRIX_MASK,
77 - PCR_MATRIX(BIT(MT7530_CPU_PORT)));
78 - priv->ports[port].pm = PCR_MATRIX(BIT(MT7530_CPU_PORT));
79 + PCR_MATRIX(BIT(upstream)));
80 + priv->ports[port].pm = PCR_MATRIX(BIT(upstream));
81
82 mutex_unlock(&priv->reg_mutex);
83 }