1 Index: linux-4.14.14/drivers/net/dsa/mt7530.c
2 ===================================================================
3 --- linux-4.14.14.orig/drivers/net/dsa/mt7530.c
4 +++ linux-4.14.14/drivers/net/dsa/mt7530.c
5 @@ -670,6 +670,9 @@ static int
6 mt7530_cpu_port_enable(struct mt7530_priv *priv,
12 /* Enable Mediatek header mode on the cpu port */
13 mt7530_write(priv, MT7530_PVC_P(port),
15 @@ -686,8 +689,12 @@ mt7530_cpu_port_enable(struct mt7530_pri
16 /* CPU port gets connected to all user ports of
19 + for (i = 0; i < MT7530_NUM_PORTS; i++)
20 + if ((priv->ds->enabled_port_mask & BIT(i)) &&
21 + (dsa_port_upstream_port(priv->ds, i) == port))
22 + port_mask |= BIT(i);
23 mt7530_write(priv, MT7530_PCR_P(port),
24 - PCR_MATRIX(priv->ds->enabled_port_mask));
25 + PCR_MATRIX(port_mask));
29 @@ -697,6 +704,7 @@ mt7530_port_enable(struct dsa_switch *ds
30 struct phy_device *phy)
32 struct mt7530_priv *priv = ds->priv;
33 + u8 upstream = dsa_port_upstream_port(ds, port);
35 mutex_lock(&priv->reg_mutex);
37 @@ -707,7 +715,7 @@ mt7530_port_enable(struct dsa_switch *ds
38 * restore the port matrix if the port is the member of a certain
41 - priv->ports[port].pm |= PCR_MATRIX(BIT(MT7530_CPU_PORT));
42 + priv->ports[port].pm |= PCR_MATRIX(BIT(upstream));
43 priv->ports[port].enable = true;
44 mt7530_rmw(priv, MT7530_PCR_P(port), PCR_MATRIX_MASK,
45 priv->ports[port].pm);
46 @@ -770,7 +778,8 @@ mt7530_port_bridge_join(struct dsa_switc
47 struct net_device *bridge)
49 struct mt7530_priv *priv = ds->priv;
50 - u32 port_bitmap = BIT(MT7530_CPU_PORT);
51 + u8 upstream = dsa_port_upstream_port(ds, port);
52 + u32 port_bitmap = BIT(upstream);
55 mutex_lock(&priv->reg_mutex);
56 @@ -808,6 +817,7 @@ mt7530_port_bridge_leave(struct dsa_swit
57 struct net_device *bridge)
59 struct mt7530_priv *priv = ds->priv;
60 + u8 upstream = dsa_port_upstream_port(ds, port);
63 mutex_lock(&priv->reg_mutex);
64 @@ -832,8 +842,8 @@ mt7530_port_bridge_leave(struct dsa_swit
66 if (priv->ports[port].enable)
67 mt7530_rmw(priv, MT7530_PCR_P(port), PCR_MATRIX_MASK,
68 - PCR_MATRIX(BIT(MT7530_CPU_PORT)));
69 - priv->ports[port].pm = PCR_MATRIX(BIT(MT7530_CPU_PORT));
70 + PCR_MATRIX(BIT(upstream)));
71 + priv->ports[port].pm = PCR_MATRIX(BIT(upstream));
73 mutex_unlock(&priv->reg_mutex);
75 @@ -908,15 +918,7 @@ err:
76 static enum dsa_tag_protocol
77 mtk_get_tag_protocol(struct dsa_switch *ds)
79 - struct mt7530_priv *priv = ds->priv;
81 - if (!dsa_is_cpu_port(ds, MT7530_CPU_PORT)) {
83 - "port not matched with tagging CPU port\n");
84 - return DSA_TAG_PROTO_NONE;
86 - return DSA_TAG_PROTO_MTK;
88 + return DSA_TAG_PROTO_MTK;
92 @@ -989,7 +991,7 @@ mt7530_setup(struct dsa_switch *ds)
94 /* Enable Port 6 only; P5 as GMAC5 which currently is not supported */
95 val = mt7530_read(priv, MT7530_MHWTRAP);
96 - val &= ~MHWTRAP_P6_DIS & ~MHWTRAP_PHY_ACCESS;
97 + val &= ~MHWTRAP_P5_DIS & ~MHWTRAP_P6_DIS & ~MHWTRAP_PHY_ACCESS;
98 val |= MHWTRAP_MANUAL;
99 if (!dsa_is_cpu_port(ds, 5)) {
100 val |= MHWTRAP_P5_DIS;
101 Index: linux-4.14.14/include/net/dsa.h
102 ===================================================================
103 --- linux-4.14.14.orig/include/net/dsa.h
104 +++ linux-4.14.14/include/net/dsa.h
105 @@ -185,6 +185,10 @@ struct dsa_port {
107 struct net_device *bridge_dev;
108 struct devlink_port devlink_port;
110 + struct net_device *ethernet;
114 * Original copy of the master netdev ethtool_ops
116 @@ -266,6 +270,11 @@ static inline bool dsa_is_normal_port(st
117 return !dsa_is_cpu_port(ds, p) && !dsa_is_dsa_port(ds, p);
120 +static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int p)
122 + return dsa_is_cpu_port(ds, p) || dsa_is_dsa_port(ds, p);
125 static inline u8 dsa_upstream_port(struct dsa_switch *ds)
127 struct dsa_switch_tree *dst = ds->dst;
128 @@ -282,6 +291,18 @@ static inline u8 dsa_upstream_port(struc
129 return ds->rtable[dst->cpu_dp->ds->index];
132 +static inline u8 dsa_port_upstream_port(struct dsa_switch *ds, int port)
135 + * If this port has a specific upstream cpu port, use it,
136 + * otherwise use the switch default.
138 + if (ds->ports[port].upstream)
139 + return ds->ports[port].upstream;
141 + return dsa_upstream_port(ds);
144 typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid,
145 bool is_static, void *data);
146 struct dsa_switch_ops {
147 Index: linux-4.14.14/net/dsa/dsa2.c
148 ===================================================================
149 --- linux-4.14.14.orig/net/dsa/dsa2.c
150 +++ linux-4.14.14/net/dsa/dsa2.c
151 @@ -253,6 +253,8 @@ static int dsa_cpu_port_apply(struct dsa
152 memset(&port->devlink_port, 0, sizeof(port->devlink_port));
153 err = devlink_port_register(ds->devlink, &port->devlink_port,
156 + port->netdev->dsa_ptr = ds->dst;
160 @@ -262,6 +264,12 @@ static void dsa_cpu_port_unapply(struct
161 dsa_cpu_dsa_destroy(port);
162 port->ds->cpu_port_mask &= ~BIT(port->index);
165 + port->netdev->dsa_ptr = NULL;
166 + if (port->ethernet) {
167 + dev_put(port->ethernet);
168 + port->ethernet = NULL;
172 static int dsa_user_port_apply(struct dsa_port *port)
173 @@ -505,10 +513,9 @@ static int dsa_cpu_parse(struct dsa_port
174 dev_put(ethernet_dev);
177 - if (!dst->cpu_dp) {
180 - dst->cpu_dp->netdev = ethernet_dev;
182 + port->netdev = ethernet_dev;
184 /* Initialize cpu_port_mask now for drv->setup()
185 * to have access to a correct value, just like what
186 @@ -526,6 +533,29 @@ static int dsa_cpu_parse(struct dsa_port
188 dst->rcv = dst->tag_ops->rcv;
190 + dev_hold(ethernet_dev);
191 + ds->ports[index].ethernet = ethernet_dev;
192 + ds->cpu_port_mask |= BIT(index);
197 +static int dsa_user_parse(struct dsa_port *port, u32 index,
198 + struct dsa_switch *ds)
200 + struct device_node *cpu_port;
201 + const unsigned int *cpu_port_reg;
202 + int cpu_port_index;
204 + cpu_port = of_parse_phandle(port->dn, "cpu", 0);
206 + cpu_port_reg = of_get_property(cpu_port, "reg", NULL);
209 + cpu_port_index = be32_to_cpup(cpu_port_reg);
210 + ds->ports[index].upstream = cpu_port_index;
216 @@ -533,7 +563,7 @@ static int dsa_ds_parse(struct dsa_switc
218 struct dsa_port *port;
223 for (index = 0; index < ds->num_ports; index++) {
224 port = &ds->ports[index];
225 @@ -546,6 +576,9 @@ static int dsa_ds_parse(struct dsa_switc
229 + err = dsa_user_parse(port, index, ds);
232 /* Initialize enabled_port_mask now for drv->setup()
233 * to have access to a correct value, just like what
234 * net/dsa/dsa.c::dsa_switch_setup_one does.
235 Index: linux-4.14.14/net/dsa/dsa_priv.h
236 ===================================================================
237 --- linux-4.14.14.orig/net/dsa/dsa_priv.h
238 +++ linux-4.14.14/net/dsa/dsa_priv.h
239 @@ -91,6 +91,8 @@ struct dsa_slave_priv {
242 struct list_head mall_tc_list;
244 + struct net_device *master;
248 @@ -177,6 +179,9 @@ extern const struct dsa_device_ops trail
250 static inline struct net_device *dsa_master_netdev(struct dsa_slave_priv *p)
255 return p->dp->cpu_dp->netdev;
258 Index: linux-4.14.14/net/dsa/slave.c
259 ===================================================================
260 --- linux-4.14.14.orig/net/dsa/slave.c
261 +++ linux-4.14.14/net/dsa/slave.c
262 @@ -1257,7 +1257,7 @@ int dsa_slave_create(struct dsa_port *po
265 cpu_dp = ds->dst->cpu_dp;
266 - master = cpu_dp->netdev;
267 + master = ds->ports[port->upstream].ethernet;
269 if (!ds->num_tx_queues)
270 ds->num_tx_queues = 1;
271 @@ -1295,6 +1295,7 @@ int dsa_slave_create(struct dsa_port *po
273 INIT_LIST_HEAD(&p->mall_tc_list);
274 p->xmit = dst->tag_ops->xmit;
275 + p->master = master;