Skip to content

Commit 5313a37

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: sja1105: rely on DSA core tracking of port learning state
Now that DSA keeps track of the port learning state, it becomes superfluous to keep an additional variable with this information in the sja1105 driver. Remove it. The DSA core's learning state is present in struct dsa_port *dp. To avoid the antipattern where we iterate through a DSA switch's ports and then call dsa_to_port to obtain the "dp" reference (which is bad because dsa_to_port iterates through the DSA switch tree once again), just iterate through the dst->ports and operate on those directly. The sja1105 had an extra use of priv->learn_ena on non-user ports. DSA does not touch the learning state of those ports - drivers are free to do what they wish on them. Mark that information with a comment in struct dsa_port and let sja1105 set dp->learning for cascade ports. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9264e4a commit 5313a37

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

drivers/net/dsa/sja1105/sja1105.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ struct sja1105_private {
233233
phy_interface_t phy_mode[SJA1105_MAX_NUM_PORTS];
234234
bool fixed_link[SJA1105_MAX_NUM_PORTS];
235235
bool vlan_aware;
236-
unsigned long learn_ena;
237236
unsigned long ucast_egress_floods;
238237
unsigned long bcast_egress_floods;
239238
const struct sja1105_info *info;

drivers/net/dsa/sja1105/sja1105_main.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static int sja1105_init_mac_settings(struct sja1105_private *priv)
176176
struct sja1105_mac_config_entry *mac;
177177
struct dsa_switch *ds = priv->ds;
178178
struct sja1105_table *table;
179-
int i;
179+
struct dsa_port *dp;
180180

181181
table = &priv->static_config.tables[BLK_IDX_MAC_CONFIG];
182182

@@ -195,8 +195,11 @@ static int sja1105_init_mac_settings(struct sja1105_private *priv)
195195

196196
mac = table->entries;
197197

198-
for (i = 0; i < ds->num_ports; i++) {
199-
mac[i] = default_mac;
198+
list_for_each_entry(dp, &ds->dst->ports, list) {
199+
if (dp->ds != ds)
200+
continue;
201+
202+
mac[dp->index] = default_mac;
200203

201204
/* Let sja1105_bridge_stp_state_set() keep address learning
202205
* enabled for the DSA ports. CPU ports use software-assisted
@@ -205,8 +208,8 @@ static int sja1105_init_mac_settings(struct sja1105_private *priv)
205208
* CPU ports in a cross-chip topology if multiple CPU ports
206209
* exist.
207210
*/
208-
if (dsa_is_dsa_port(ds, i))
209-
priv->learn_ena |= BIT(i);
211+
if (dsa_port_is_dsa(dp))
212+
dp->learning = true;
210213
}
211214

212215
return 0;
@@ -1899,6 +1902,7 @@ static int sja1105_bridge_member(struct dsa_switch *ds, int port,
18991902
static void sja1105_bridge_stp_state_set(struct dsa_switch *ds, int port,
19001903
u8 state)
19011904
{
1905+
struct dsa_port *dp = dsa_to_port(ds, port);
19021906
struct sja1105_private *priv = ds->priv;
19031907
struct sja1105_mac_config_entry *mac;
19041908

@@ -1924,12 +1928,12 @@ static void sja1105_bridge_stp_state_set(struct dsa_switch *ds, int port,
19241928
case BR_STATE_LEARNING:
19251929
mac[port].ingress = true;
19261930
mac[port].egress = false;
1927-
mac[port].dyn_learn = !!(priv->learn_ena & BIT(port));
1931+
mac[port].dyn_learn = dp->learning;
19281932
break;
19291933
case BR_STATE_FORWARDING:
19301934
mac[port].ingress = true;
19311935
mac[port].egress = true;
1932-
mac[port].dyn_learn = !!(priv->learn_ena & BIT(port));
1936+
mac[port].dyn_learn = dp->learning;
19331937
break;
19341938
default:
19351939
dev_err(ds->dev, "invalid STP state: %d\n", state);
@@ -2891,23 +2895,13 @@ static int sja1105_port_set_learning(struct sja1105_private *priv, int port,
28912895
bool enabled)
28922896
{
28932897
struct sja1105_mac_config_entry *mac;
2894-
int rc;
28952898

28962899
mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG].entries;
28972900

28982901
mac[port].dyn_learn = enabled;
28992902

2900-
rc = sja1105_dynamic_config_write(priv, BLK_IDX_MAC_CONFIG, port,
2901-
&mac[port], true);
2902-
if (rc)
2903-
return rc;
2904-
2905-
if (enabled)
2906-
priv->learn_ena |= BIT(port);
2907-
else
2908-
priv->learn_ena &= ~BIT(port);
2909-
2910-
return 0;
2903+
return sja1105_dynamic_config_write(priv, BLK_IDX_MAC_CONFIG, port,
2904+
&mac[port], true);
29112905
}
29122906

29132907
static int sja1105_port_ucast_bcast_flood(struct sja1105_private *priv, int to,

include/net/dsa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ struct dsa_port {
254254
struct device_node *dn;
255255
unsigned int ageing_time;
256256
bool vlan_filtering;
257+
/* Managed by DSA on user ports and by drivers on CPU and DSA ports */
257258
bool learning;
258259
u8 stp_state;
259260
struct net_device *bridge_dev;

0 commit comments

Comments
 (0)