Skip to content

Commit 7f14937

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: sja1105: keep the VLAN awareness state in a driver variable
Soon we'll add a third operating mode to the driver. Introduce a vlan_state to make things more easy to manage, and use it where applicable. Signed-off-by: Vladimir Oltean <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1f66b0f commit 7f14937

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

drivers/net/dsa/sja1105/sja1105.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ struct sja1105_flow_block {
178178
int num_virtual_links;
179179
};
180180

181+
enum sja1105_vlan_state {
182+
SJA1105_VLAN_UNAWARE,
183+
SJA1105_VLAN_FILTERING_FULL,
184+
};
185+
181186
struct sja1105_private {
182187
struct sja1105_static_config static_config;
183188
bool rgmii_rx_delay[SJA1105_NUM_PORTS];
@@ -193,6 +198,7 @@ struct sja1105_private {
193198
* the switch doesn't confuse them with one another.
194199
*/
195200
struct mutex mgmt_lock;
201+
enum sja1105_vlan_state vlan_state;
196202
struct sja1105_tagger_data tagger_data;
197203
struct sja1105_ptp_data ptp_data;
198204
struct sja1105_tas_data tas_data;

drivers/net/dsa/sja1105/sja1105_main.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ int sja1105pqrs_fdb_add(struct dsa_switch *ds, int port,
13031303
l2_lookup.vlanid = vid;
13041304
l2_lookup.iotag = SJA1105_S_TAG;
13051305
l2_lookup.mask_macaddr = GENMASK_ULL(ETH_ALEN * 8 - 1, 0);
1306-
if (dsa_port_is_vlan_filtering(dsa_to_port(ds, port))) {
1306+
if (priv->vlan_state != SJA1105_VLAN_UNAWARE) {
13071307
l2_lookup.mask_vlanid = VLAN_VID_MASK;
13081308
l2_lookup.mask_iotag = BIT(0);
13091309
} else {
@@ -1366,7 +1366,7 @@ int sja1105pqrs_fdb_del(struct dsa_switch *ds, int port,
13661366
l2_lookup.vlanid = vid;
13671367
l2_lookup.iotag = SJA1105_S_TAG;
13681368
l2_lookup.mask_macaddr = GENMASK_ULL(ETH_ALEN * 8 - 1, 0);
1369-
if (dsa_port_is_vlan_filtering(dsa_to_port(ds, port))) {
1369+
if (priv->vlan_state != SJA1105_VLAN_UNAWARE) {
13701370
l2_lookup.mask_vlanid = VLAN_VID_MASK;
13711371
l2_lookup.mask_iotag = BIT(0);
13721372
} else {
@@ -1412,7 +1412,7 @@ static int sja1105_fdb_add(struct dsa_switch *ds, int port,
14121412
* for what gets printed in 'bridge fdb show'. In the case of zero,
14131413
* no VID gets printed at all.
14141414
*/
1415-
if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
1415+
if (priv->vlan_state != SJA1105_VLAN_FILTERING_FULL)
14161416
vid = 0;
14171417

14181418
return priv->info->fdb_add_cmd(ds, port, addr, vid);
@@ -1423,7 +1423,7 @@ static int sja1105_fdb_del(struct dsa_switch *ds, int port,
14231423
{
14241424
struct sja1105_private *priv = ds->priv;
14251425

1426-
if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
1426+
if (priv->vlan_state != SJA1105_VLAN_FILTERING_FULL)
14271427
vid = 0;
14281428

14291429
return priv->info->fdb_del_cmd(ds, port, addr, vid);
@@ -1462,7 +1462,7 @@ static int sja1105_fdb_dump(struct dsa_switch *ds, int port,
14621462
u64_to_ether_addr(l2_lookup.macaddr, macaddr);
14631463

14641464
/* We need to hide the dsa_8021q VLANs from the user. */
1465-
if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
1465+
if (priv->vlan_state == SJA1105_VLAN_UNAWARE)
14661466
l2_lookup.vlanid = 0;
14671467
cb(macaddr, l2_lookup.vlanid, l2_lookup.lockeds, data);
14681468
}
@@ -1917,6 +1917,7 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)
19171917
struct sja1105_l2_lookup_params_entry *l2_lookup_params;
19181918
struct sja1105_general_params_entry *general_params;
19191919
struct sja1105_private *priv = ds->priv;
1920+
enum sja1105_vlan_state state;
19201921
struct sja1105_table *table;
19211922
struct sja1105_rule *rule;
19221923
u16 tpid, tpid2;
@@ -1940,6 +1941,13 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)
19401941
tpid2 = ETH_P_SJA1105;
19411942
}
19421943

1944+
if (!enabled)
1945+
state = SJA1105_VLAN_UNAWARE;
1946+
else
1947+
state = SJA1105_VLAN_FILTERING_FULL;
1948+
1949+
priv->vlan_state = state;
1950+
19431951
table = &priv->static_config.tables[BLK_IDX_GENERAL_PARAMS];
19441952
general_params = table->entries;
19451953
/* EtherType used to identify inner tagged (C-tag) VLAN traffic */

drivers/net/dsa/sja1105/sja1105_vl.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,14 @@ int sja1105_vl_redirect(struct sja1105_private *priv, int port,
353353
struct sja1105_rule *rule = sja1105_rule_find(priv, cookie);
354354
int rc;
355355

356-
if (dsa_port_is_vlan_filtering(dsa_to_port(priv->ds, port)) &&
357-
key->type != SJA1105_KEY_VLAN_AWARE_VL) {
356+
if (priv->vlan_state == SJA1105_VLAN_UNAWARE &&
357+
key->type != SJA1105_KEY_VLAN_UNAWARE_VL) {
358358
NL_SET_ERR_MSG_MOD(extack,
359-
"Can only redirect based on {DMAC, VID, PCP}");
359+
"Can only redirect based on DMAC");
360360
return -EOPNOTSUPP;
361-
} else if (key->type != SJA1105_KEY_VLAN_UNAWARE_VL) {
361+
} else if (key->type != SJA1105_KEY_VLAN_AWARE_VL) {
362362
NL_SET_ERR_MSG_MOD(extack,
363-
"Can only redirect based on DMAC");
363+
"Can only redirect based on {DMAC, VID, PCP}");
364364
return -EOPNOTSUPP;
365365
}
366366

@@ -602,14 +602,18 @@ int sja1105_vl_gate(struct sja1105_private *priv, int port,
602602
return -ERANGE;
603603
}
604604

605-
if (dsa_port_is_vlan_filtering(dsa_to_port(priv->ds, port)) &&
606-
key->type != SJA1105_KEY_VLAN_AWARE_VL) {
605+
if (priv->vlan_state == SJA1105_VLAN_UNAWARE &&
606+
key->type != SJA1105_KEY_VLAN_UNAWARE_VL) {
607+
dev_err(priv->ds->dev, "1: vlan state %d key type %d\n",
608+
priv->vlan_state, key->type);
607609
NL_SET_ERR_MSG_MOD(extack,
608-
"Can only gate based on {DMAC, VID, PCP}");
610+
"Can only gate based on DMAC");
609611
return -EOPNOTSUPP;
610-
} else if (key->type != SJA1105_KEY_VLAN_UNAWARE_VL) {
612+
} else if (key->type != SJA1105_KEY_VLAN_AWARE_VL) {
613+
dev_err(priv->ds->dev, "2: vlan state %d key type %d\n",
614+
priv->vlan_state, key->type);
611615
NL_SET_ERR_MSG_MOD(extack,
612-
"Can only gate based on DMAC");
616+
"Can only gate based on {DMAC, VID, PCP}");
613617
return -EOPNOTSUPP;
614618
}
615619

0 commit comments

Comments
 (0)