92f4c98dcae64dc5075342c25396e09b0ba3c801
[openwrt/openwrt.git] / target / linux / mediatek / patches-4.14 / 0033-dsa-multi-cpu.patch
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,
7 int port)
8 {
9 + u8 port_mask = 0;
10 + int i;
11 +
12 /* Enable Mediatek header mode on the cpu port */
13 mt7530_write(priv, MT7530_PVC_P(port),
14 PORT_SPEC_TAG);
15 @@ -686,8 +689,12 @@ mt7530_cpu_port_enable(struct mt7530_pri
16 /* CPU port gets connected to all user ports of
17 * the switch
18 */
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));
26
27 return 0;
28 }
29 @@ -697,6 +704,7 @@ mt7530_port_enable(struct dsa_switch *ds
30 struct phy_device *phy)
31 {
32 struct mt7530_priv *priv = ds->priv;
33 + u8 upstream = dsa_port_upstream_port(ds, port);
34
35 mutex_lock(&priv->reg_mutex);
36
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
39 * bridge.
40 */
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)
48 {
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);
53 int i;
54
55 mutex_lock(&priv->reg_mutex);
56 @@ -808,6 +817,7 @@ mt7530_port_bridge_leave(struct dsa_swit
57 struct net_device *bridge)
58 {
59 struct mt7530_priv *priv = ds->priv;
60 + u8 upstream = dsa_port_upstream_port(ds, port);
61 int i;
62
63 mutex_lock(&priv->reg_mutex);
64 @@ -832,8 +842,8 @@ mt7530_port_bridge_leave(struct dsa_swit
65 */
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));
72
73 mutex_unlock(&priv->reg_mutex);
74 }
75 @@ -908,15 +918,7 @@ err:
76 static enum dsa_tag_protocol
77 mtk_get_tag_protocol(struct dsa_switch *ds)
78 {
79 - struct mt7530_priv *priv = ds->priv;
80 -
81 - if (!dsa_is_cpu_port(ds, MT7530_CPU_PORT)) {
82 - dev_warn(priv->dev,
83 - "port not matched with tagging CPU port\n");
84 - return DSA_TAG_PROTO_NONE;
85 - } else {
86 - return DSA_TAG_PROTO_MTK;
87 - }
88 + return DSA_TAG_PROTO_MTK;
89 }
90
91 static int
92 @@ -989,7 +991,7 @@ mt7530_setup(struct dsa_switch *ds)
93
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 {
106 u8 stp_state;
107 struct net_device *bridge_dev;
108 struct devlink_port devlink_port;
109 +
110 + struct net_device *ethernet;
111 + int upstream;
112 +
113 /*
114 * Original copy of the master netdev ethtool_ops
115 */
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);
118 }
119
120 +static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int p)
121 +{
122 + return dsa_is_cpu_port(ds, p) || dsa_is_dsa_port(ds, p);
123 +}
124 +
125 static inline u8 dsa_upstream_port(struct dsa_switch *ds)
126 {
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];
130 }
131
132 +static inline u8 dsa_port_upstream_port(struct dsa_switch *ds, int port)
133 +{
134 + /*
135 + * If this port has a specific upstream cpu port, use it,
136 + * otherwise use the switch default.
137 + */
138 + if (ds->ports[port].upstream)
139 + return ds->ports[port].upstream;
140 + else
141 + return dsa_upstream_port(ds);
142 +}
143 +
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,
154 port->index);
155 + if (port->netdev)
156 + port->netdev->dsa_ptr = ds->dst;
157 return err;
158 }
159
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);
163
164 + if (port->netdev)
165 + port->netdev->dsa_ptr = NULL;
166 + if (port->ethernet) {
167 + dev_put(port->ethernet);
168 + port->ethernet = NULL;
169 + }
170 }
171
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);
175 }
176
177 - if (!dst->cpu_dp) {
178 + if (!dst->cpu_dp)
179 dst->cpu_dp = port;
180 - dst->cpu_dp->netdev = ethernet_dev;
181 - }
182 + port->netdev = ethernet_dev;
183
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
187
188 dst->rcv = dst->tag_ops->rcv;
189
190 + dev_hold(ethernet_dev);
191 + ds->ports[index].ethernet = ethernet_dev;
192 + ds->cpu_port_mask |= BIT(index);
193 +
194 + return 0;
195 +}
196 +
197 +static int dsa_user_parse(struct dsa_port *port, u32 index,
198 + struct dsa_switch *ds)
199 +{
200 + struct device_node *cpu_port;
201 + const unsigned int *cpu_port_reg;
202 + int cpu_port_index;
203 +
204 + cpu_port = of_parse_phandle(port->dn, "cpu", 0);
205 + if (cpu_port) {
206 + cpu_port_reg = of_get_property(cpu_port, "reg", NULL);
207 + if (!cpu_port_reg)
208 + return -EINVAL;
209 + cpu_port_index = be32_to_cpup(cpu_port_reg);
210 + ds->ports[index].upstream = cpu_port_index;
211 + }
212 +
213 return 0;
214 }
215
216 @@ -533,7 +563,7 @@ static int dsa_ds_parse(struct dsa_switc
217 {
218 struct dsa_port *port;
219 u32 index;
220 - int err;
221 + int err = 0;
222
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
226 if (err)
227 return err;
228 } else {
229 + err = dsa_user_parse(port, index, ds);
230 + if (err)
231 + return err;
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 {
240
241 /* TC context */
242 struct list_head mall_tc_list;
243 +
244 + struct net_device *master;
245 };
246
247 /* dsa.c */
248 @@ -177,6 +179,9 @@ extern const struct dsa_device_ops trail
249
250 static inline struct net_device *dsa_master_netdev(struct dsa_slave_priv *p)
251 {
252 + if (p->master)
253 + return p->master;
254 +
255 return p->dp->cpu_dp->netdev;
256 }
257
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
263 int ret;
264
265 cpu_dp = ds->dst->cpu_dp;
266 - master = cpu_dp->netdev;
267 + master = ds->ports[port->upstream].ethernet;
268
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
272 p->dp = port;
273 INIT_LIST_HEAD(&p->mall_tc_list);
274 p->xmit = dst->tag_ops->xmit;
275 + p->master = master;
276
277 p->old_pause = -1;
278 p->old_link = -1;