bb34e5db2cf5865f92aab56402d286a670f0dda1
[openwrt/openwrt.git] /
1 From d00ac78e74e433109307f365ba90d34cd73aaf20 Mon Sep 17 00:00:00 2001
2 From: Vladimir Oltean <vladimir.oltean@nxp.com>
3 Date: Sat, 9 Nov 2019 15:02:47 +0200
4 Subject: [PATCH] net: mscc: ocelot: break apart ocelot_vlan_port_apply
5
6 This patch transforms the ocelot_vlan_port_apply function ("apply
7 what?") into 3 standalone functions:
8
9 - ocelot_port_vlan_filtering
10 - ocelot_port_set_native_vlan
11 - ocelot_port_set_pvid
12
13 These functions have a prototype that is better aligned to the DSA API.
14
15 The function also had some static initialization (TPID, drop frames with
16 multicast source MAC) which was not being changed from any place, so
17 that was just moved to ocelot_probe_port (one of the 6 callers of
18 ocelot_vlan_port_apply).
19
20 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
21 Signed-off-by: David S. Miller <davem@davemloft.net>
22 ---
23 drivers/net/ethernet/mscc/ocelot.c | 168 ++++++++++++++++++++++---------------
24 1 file changed, 100 insertions(+), 68 deletions(-)
25
26 --- a/drivers/net/ethernet/mscc/ocelot.c
27 +++ b/drivers/net/ethernet/mscc/ocelot.c
28 @@ -185,65 +185,97 @@ static void ocelot_vlan_mode(struct ocel
29 ocelot_write(ocelot, val, ANA_VLANMASK);
30 }
31
32 -static void ocelot_vlan_port_apply(struct ocelot *ocelot,
33 - struct ocelot_port *port)
34 +static void ocelot_port_vlan_filtering(struct ocelot *ocelot, int port,
35 + bool vlan_aware)
36 {
37 + struct ocelot_port *ocelot_port = ocelot->ports[port];
38 u32 val;
39
40 - /* Ingress clasification (ANA_PORT_VLAN_CFG) */
41 - /* Default vlan to clasify for untagged frames (may be zero) */
42 - val = ANA_PORT_VLAN_CFG_VLAN_VID(port->pvid);
43 - if (port->vlan_aware)
44 - val |= ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
45 - ANA_PORT_VLAN_CFG_VLAN_POP_CNT(1);
46 -
47 + if (vlan_aware)
48 + val = ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
49 + ANA_PORT_VLAN_CFG_VLAN_POP_CNT(1);
50 + else
51 + val = 0;
52 ocelot_rmw_gix(ocelot, val,
53 - ANA_PORT_VLAN_CFG_VLAN_VID_M |
54 ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
55 ANA_PORT_VLAN_CFG_VLAN_POP_CNT_M,
56 - ANA_PORT_VLAN_CFG, port->chip_port);
57 + ANA_PORT_VLAN_CFG, port);
58
59 - /* Drop frames with multicast source address */
60 - val = ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA;
61 - if (port->vlan_aware && !port->vid)
62 + if (vlan_aware && !ocelot_port->vid)
63 /* If port is vlan-aware and tagged, drop untagged and priority
64 * tagged frames.
65 */
66 - val |= ANA_PORT_DROP_CFG_DROP_UNTAGGED_ENA |
67 + val = ANA_PORT_DROP_CFG_DROP_UNTAGGED_ENA |
68 + ANA_PORT_DROP_CFG_DROP_PRIO_S_TAGGED_ENA |
69 + ANA_PORT_DROP_CFG_DROP_PRIO_C_TAGGED_ENA;
70 + else
71 + val = 0;
72 + ocelot_rmw_gix(ocelot, val,
73 + ANA_PORT_DROP_CFG_DROP_UNTAGGED_ENA |
74 ANA_PORT_DROP_CFG_DROP_PRIO_S_TAGGED_ENA |
75 - ANA_PORT_DROP_CFG_DROP_PRIO_C_TAGGED_ENA;
76 - ocelot_write_gix(ocelot, val, ANA_PORT_DROP_CFG, port->chip_port);
77 -
78 - /* Egress configuration (REW_TAG_CFG): VLAN tag type to 8021Q. */
79 - val = REW_TAG_CFG_TAG_TPID_CFG(0);
80 + ANA_PORT_DROP_CFG_DROP_PRIO_C_TAGGED_ENA,
81 + ANA_PORT_DROP_CFG, port);
82
83 - if (port->vlan_aware) {
84 - if (port->vid)
85 + if (vlan_aware) {
86 + if (ocelot_port->vid)
87 /* Tag all frames except when VID == DEFAULT_VLAN */
88 val |= REW_TAG_CFG_TAG_CFG(1);
89 else
90 /* Tag all frames */
91 val |= REW_TAG_CFG_TAG_CFG(3);
92 + } else {
93 + /* Port tagging disabled. */
94 + val = REW_TAG_CFG_TAG_CFG(0);
95 }
96 ocelot_rmw_gix(ocelot, val,
97 - REW_TAG_CFG_TAG_TPID_CFG_M |
98 REW_TAG_CFG_TAG_CFG_M,
99 - REW_TAG_CFG, port->chip_port);
100 + REW_TAG_CFG, port);
101
102 - /* Set default VLAN and tag type to 8021Q. */
103 - val = REW_PORT_VLAN_CFG_PORT_TPID(ETH_P_8021Q) |
104 - REW_PORT_VLAN_CFG_PORT_VID(port->vid);
105 - ocelot_rmw_gix(ocelot, val,
106 - REW_PORT_VLAN_CFG_PORT_TPID_M |
107 + ocelot_port->vlan_aware = vlan_aware;
108 +}
109 +
110 +static int ocelot_port_set_native_vlan(struct ocelot *ocelot, int port,
111 + u16 vid)
112 +{
113 + struct ocelot_port *ocelot_port = ocelot->ports[port];
114 +
115 + if (ocelot_port->vid != vid) {
116 + /* Always permit deleting the native VLAN (vid = 0) */
117 + if (ocelot_port->vid && vid) {
118 + dev_err(ocelot->dev,
119 + "Port already has a native VLAN: %d\n",
120 + ocelot_port->vid);
121 + return -EBUSY;
122 + }
123 + ocelot_port->vid = vid;
124 + }
125 +
126 + ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_VID(vid),
127 REW_PORT_VLAN_CFG_PORT_VID_M,
128 - REW_PORT_VLAN_CFG, port->chip_port);
129 + REW_PORT_VLAN_CFG, port);
130 +
131 + return 0;
132 +}
133 +
134 +/* Default vlan to clasify for untagged frames (may be zero) */
135 +static void ocelot_port_set_pvid(struct ocelot *ocelot, int port, u16 pvid)
136 +{
137 + struct ocelot_port *ocelot_port = ocelot->ports[port];
138 +
139 + ocelot_rmw_gix(ocelot,
140 + ANA_PORT_VLAN_CFG_VLAN_VID(pvid),
141 + ANA_PORT_VLAN_CFG_VLAN_VID_M,
142 + ANA_PORT_VLAN_CFG, port);
143 +
144 + ocelot_port->pvid = pvid;
145 }
146
147 static int ocelot_vlan_vid_add(struct net_device *dev, u16 vid, bool pvid,
148 bool untagged)
149 {
150 - struct ocelot_port *port = netdev_priv(dev);
151 - struct ocelot *ocelot = port->ocelot;
152 + struct ocelot_port *ocelot_port = netdev_priv(dev);
153 + struct ocelot *ocelot = ocelot_port->ocelot;
154 + int port = ocelot_port->chip_port;
155 int ret;
156
157 /* Add the port MAC address to with the right VLAN information */
158 @@ -251,35 +283,30 @@ static int ocelot_vlan_vid_add(struct ne
159 ENTRYTYPE_LOCKED);
160
161 /* Make the port a member of the VLAN */
162 - ocelot->vlan_mask[vid] |= BIT(port->chip_port);
163 + ocelot->vlan_mask[vid] |= BIT(port);
164 ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]);
165 if (ret)
166 return ret;
167
168 /* Default ingress vlan classification */
169 if (pvid)
170 - port->pvid = vid;
171 + ocelot_port_set_pvid(ocelot, port, vid);
172
173 /* Untagged egress vlan clasification */
174 - if (untagged && port->vid != vid) {
175 - if (port->vid) {
176 - dev_err(ocelot->dev,
177 - "Port already has a native VLAN: %d\n",
178 - port->vid);
179 - return -EBUSY;
180 - }
181 - port->vid = vid;
182 + if (untagged) {
183 + ret = ocelot_port_set_native_vlan(ocelot, port, vid);
184 + if (ret)
185 + return ret;
186 }
187
188 - ocelot_vlan_port_apply(ocelot, port);
189 -
190 return 0;
191 }
192
193 static int ocelot_vlan_vid_del(struct net_device *dev, u16 vid)
194 {
195 - struct ocelot_port *port = netdev_priv(dev);
196 - struct ocelot *ocelot = port->ocelot;
197 + struct ocelot_port *ocelot_port = netdev_priv(dev);
198 + struct ocelot *ocelot = ocelot_port->ocelot;
199 + int port = ocelot_port->chip_port;
200 int ret;
201
202 /* 8021q removes VID 0 on module unload for all interfaces
203 @@ -293,20 +320,18 @@ static int ocelot_vlan_vid_del(struct ne
204 ocelot_mact_forget(ocelot, dev->dev_addr, vid);
205
206 /* Stop the port from being a member of the vlan */
207 - ocelot->vlan_mask[vid] &= ~BIT(port->chip_port);
208 + ocelot->vlan_mask[vid] &= ~BIT(port);
209 ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]);
210 if (ret)
211 return ret;
212
213 /* Ingress */
214 - if (port->pvid == vid)
215 - port->pvid = 0;
216 + if (ocelot_port->pvid == vid)
217 + ocelot_port_set_pvid(ocelot, port, 0);
218
219 /* Egress */
220 - if (port->vid == vid)
221 - port->vid = 0;
222 -
223 - ocelot_vlan_port_apply(ocelot, port);
224 + if (ocelot_port->vid == vid)
225 + ocelot_port_set_native_vlan(ocelot, port, 0);
226
227 return 0;
228 }
229 @@ -1306,6 +1331,7 @@ static int ocelot_port_attr_set(struct n
230 struct switchdev_trans *trans)
231 {
232 struct ocelot_port *ocelot_port = netdev_priv(dev);
233 + struct ocelot *ocelot = ocelot_port->ocelot;
234 int err = 0;
235
236 switch (attr->id) {
237 @@ -1317,8 +1343,8 @@ static int ocelot_port_attr_set(struct n
238 ocelot_port_attr_ageing_set(ocelot_port, attr->u.ageing_time);
239 break;
240 case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
241 - ocelot_port->vlan_aware = attr->u.vlan_filtering;
242 - ocelot_vlan_port_apply(ocelot_port->ocelot, ocelot_port);
243 + ocelot_port_vlan_filtering(ocelot, ocelot_port->chip_port,
244 + attr->u.vlan_filtering);
245 break;
246 case SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED:
247 ocelot_port_attr_mc_set(ocelot_port, !attr->u.mc_disabled);
248 @@ -1520,20 +1546,20 @@ static int ocelot_port_bridge_join(struc
249 return 0;
250 }
251
252 -static void ocelot_port_bridge_leave(struct ocelot_port *ocelot_port,
253 - struct net_device *bridge)
254 +static int ocelot_port_bridge_leave(struct ocelot_port *ocelot_port,
255 + struct net_device *bridge)
256 {
257 struct ocelot *ocelot = ocelot_port->ocelot;
258 + int port = ocelot_port->chip_port;
259
260 - ocelot->bridge_mask &= ~BIT(ocelot_port->chip_port);
261 + ocelot->bridge_mask &= ~BIT(port);
262
263 if (!ocelot->bridge_mask)
264 ocelot->hw_bridge_dev = NULL;
265
266 - /* Clear bridge vlan settings before calling ocelot_vlan_port_apply */
267 - ocelot_port->vlan_aware = 0;
268 - ocelot_port->pvid = 0;
269 - ocelot_port->vid = 0;
270 + ocelot_port_vlan_filtering(ocelot, port, 0);
271 + ocelot_port_set_pvid(ocelot, port, 0);
272 + return ocelot_port_set_native_vlan(ocelot, port, 0);
273 }
274
275 static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
276 @@ -1687,11 +1713,8 @@ static int ocelot_netdevice_port_event(s
277 err = ocelot_port_bridge_join(ocelot_port,
278 info->upper_dev);
279 else
280 - ocelot_port_bridge_leave(ocelot_port,
281 - info->upper_dev);
282 -
283 - ocelot_vlan_port_apply(ocelot_port->ocelot,
284 - ocelot_port);
285 + err = ocelot_port_bridge_leave(ocelot_port,
286 + info->upper_dev);
287 }
288 if (netif_is_lag_master(info->upper_dev)) {
289 if (info->linking)
290 @@ -2009,6 +2032,7 @@ int ocelot_probe_port(struct ocelot *oce
291 {
292 struct ocelot_port *ocelot_port;
293 struct net_device *dev;
294 + u32 val;
295 int err;
296
297 dev = alloc_etherdev(sizeof(struct ocelot_port));
298 @@ -2044,7 +2068,15 @@ int ocelot_probe_port(struct ocelot *oce
299 }
300
301 /* Basic L2 initialization */
302 - ocelot_vlan_port_apply(ocelot, ocelot_port);
303 +
304 + /* Drop frames with multicast source address */
305 + val = ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA;
306 + ocelot_rmw_gix(ocelot, val, val, ANA_PORT_DROP_CFG, port);
307 +
308 + /* Set default VLAN and tag type to 8021Q. */
309 + ocelot_rmw_gix(ocelot, REW_PORT_VLAN_CFG_PORT_TPID(ETH_P_8021Q),
310 + REW_PORT_VLAN_CFG_PORT_TPID_M,
311 + REW_PORT_VLAN_CFG, port);
312
313 /* Enable vcap lookups */
314 ocelot_vcap_enable(ocelot, ocelot_port);