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
6 This patch transforms the ocelot_vlan_port_apply function ("apply
7 what?") into 3 standalone functions:
9 - ocelot_port_vlan_filtering
10 - ocelot_port_set_native_vlan
11 - ocelot_port_set_pvid
13 These functions have a prototype that is better aligned to the DSA API.
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).
20 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
21 Signed-off-by: David S. Miller <davem@davemloft.net>
23 drivers/net/ethernet/mscc/ocelot.c | 168 ++++++++++++++++++++++---------------
24 1 file changed, 100 insertions(+), 68 deletions(-)
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);
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,
37 + struct ocelot_port *ocelot_port = ocelot->ports[port];
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);
48 + val = ANA_PORT_VLAN_CFG_VLAN_AWARE_ENA |
49 + ANA_PORT_VLAN_CFG_VLAN_POP_CNT(1);
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);
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
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;
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);
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);
83 - if (port->vlan_aware) {
86 + if (ocelot_port->vid)
87 /* Tag all frames except when VID == DEFAULT_VLAN */
88 val |= REW_TAG_CFG_TAG_CFG(1);
91 val |= REW_TAG_CFG_TAG_CFG(3);
93 + /* Port tagging disabled. */
94 + val = REW_TAG_CFG_TAG_CFG(0);
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);
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;
110 +static int ocelot_port_set_native_vlan(struct ocelot *ocelot, int port,
113 + struct ocelot_port *ocelot_port = ocelot->ports[port];
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",
123 + ocelot_port->vid = vid;
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);
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)
137 + struct ocelot_port *ocelot_port = ocelot->ports[port];
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);
144 + ocelot_port->pvid = pvid;
147 static int ocelot_vlan_vid_add(struct net_device *dev, u16 vid, bool pvid,
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;
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
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]);
168 /* Default ingress vlan classification */
171 + ocelot_port_set_pvid(ocelot, port, vid);
173 /* Untagged egress vlan clasification */
174 - if (untagged && port->vid != vid) {
176 - dev_err(ocelot->dev,
177 - "Port already has a native VLAN: %d\n",
183 + ret = ocelot_port_set_native_vlan(ocelot, port, vid);
188 - ocelot_vlan_port_apply(ocelot, port);
193 static int ocelot_vlan_vid_del(struct net_device *dev, u16 vid)
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;
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);
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]);
214 - if (port->pvid == vid)
216 + if (ocelot_port->pvid == vid)
217 + ocelot_port_set_pvid(ocelot, port, 0);
220 - if (port->vid == vid)
223 - ocelot_vlan_port_apply(ocelot, port);
224 + if (ocelot_port->vid == vid)
225 + ocelot_port_set_native_vlan(ocelot, port, 0);
229 @@ -1303,6 +1328,7 @@ static int ocelot_port_attr_set(struct n
230 struct switchdev_trans *trans)
232 struct ocelot_port *ocelot_port = netdev_priv(dev);
233 + struct ocelot *ocelot = ocelot_port->ocelot;
237 @@ -1314,8 +1340,8 @@ static int ocelot_port_attr_set(struct n
238 ocelot_port_attr_ageing_set(ocelot_port, attr->u.ageing_time);
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);
246 case SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED:
247 ocelot_port_attr_mc_set(ocelot_port, !attr->u.mc_disabled);
248 @@ -1517,20 +1543,20 @@ static int ocelot_port_bridge_join(struc
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)
257 struct ocelot *ocelot = ocelot_port->ocelot;
258 + int port = ocelot_port->chip_port;
260 - ocelot->bridge_mask &= ~BIT(ocelot_port->chip_port);
261 + ocelot->bridge_mask &= ~BIT(port);
263 if (!ocelot->bridge_mask)
264 ocelot->hw_bridge_dev = NULL;
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);
275 static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
276 @@ -1684,11 +1710,8 @@ static int ocelot_netdevice_port_event(s
277 err = ocelot_port_bridge_join(ocelot_port,
280 - ocelot_port_bridge_leave(ocelot_port,
283 - ocelot_vlan_port_apply(ocelot_port->ocelot,
285 + err = ocelot_port_bridge_leave(ocelot_port,
288 if (netif_is_lag_master(info->upper_dev)) {
290 @@ -2006,6 +2029,7 @@ int ocelot_probe_port(struct ocelot *oce
292 struct ocelot_port *ocelot_port;
293 struct net_device *dev;
297 dev = alloc_etherdev(sizeof(struct ocelot_port));
298 @@ -2041,7 +2065,15 @@ int ocelot_probe_port(struct ocelot *oce
301 /* Basic L2 initialization */
302 - ocelot_vlan_port_apply(ocelot, ocelot_port);
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);
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);
313 /* Enable vcap lookups */
314 ocelot_vcap_enable(ocelot, ocelot_port);