Skip to content

Commit 2e554a7

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: propagate switchdev vlan_filtering prepare phase to drivers
A driver may refuse to enable VLAN filtering for any reason beyond what the DSA framework cares about, such as: - having tc-flower rules that rely on the switch being VLAN-aware - the particular switch does not support VLAN, even if the driver does (the DSA framework just checks for the presence of the .port_vlan_add and .port_vlan_del pointers) - simply not supporting this configuration to be toggled at runtime Currently, when a driver rejects a configuration it cannot support, it does this from the commit phase, which triggers various warnings in switchdev. So propagate the prepare phase to drivers, to give them the ability to refuse invalid configurations cleanly and avoid the warnings. Since we need to modify all function prototypes and check for the prepare phase from within the drivers, take that opportunity and move the existing driver restrictions within the prepare phase where that is possible and easy. Cc: Florian Fainelli <f.fainelli@gmail.com> Cc: Martin Blumenstingl <martin.blumenstingl@googlemail.com> Cc: Hauke Mehrtens <hauke@hauke-m.de> Cc: Woojung Huh <woojung.huh@microchip.com> Cc: Microchip Linux Driver Support <UNGLinuxDriver@microchip.com> Cc: Sean Wang <sean.wang@mediatek.com> Cc: Landen Chao <Landen.Chao@mediatek.com> Cc: Andrew Lunn <andrew@lunn.ch> Cc: Vivien Didelot <vivien.didelot@gmail.com> Cc: Jonathan McDowell <noodles@earth.li> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com> Cc: Claudiu Manoil <claudiu.manoil@nxp.com> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c2568c8 commit 2e554a7

21 files changed

Lines changed: 130 additions & 47 deletions

File tree

‎drivers/net/dsa/b53/b53_common.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,10 +1374,14 @@ void b53_phylink_mac_link_up(struct dsa_switch *ds, int port,
13741374
}
13751375
EXPORT_SYMBOL(b53_phylink_mac_link_up);
13761376

1377-
int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering)
1377+
int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
1378+
struct switchdev_trans *trans)
13781379
{
13791380
struct b53_device *dev = ds->priv;
13801381

1382+
if (switchdev_trans_ph_prepare(trans))
1383+
return 0;
1384+
13811385
b53_enable_vlan(dev, dev->vlan_enabled, vlan_filtering);
13821386

13831387
return 0;

‎drivers/net/dsa/b53/b53_priv.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ void b53_phylink_mac_link_up(struct dsa_switch *ds, int port,
347347
struct phy_device *phydev,
348348
int speed, int duplex,
349349
bool tx_pause, bool rx_pause);
350-
int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering);
350+
int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
351+
struct switchdev_trans *trans);
351352
int b53_vlan_prepare(struct dsa_switch *ds, int port,
352353
const struct switchdev_obj_port_vlan *vlan);
353354
void b53_vlan_add(struct dsa_switch *ds, int port,

‎drivers/net/dsa/dsa_loop.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ static void dsa_loop_port_stp_state_set(struct dsa_switch *ds, int port,
190190
}
191191

192192
static int dsa_loop_port_vlan_filtering(struct dsa_switch *ds, int port,
193-
bool vlan_filtering)
193+
bool vlan_filtering,
194+
struct switchdev_trans *trans)
194195
{
195196
dev_dbg(ds->dev, "%s: port: %d, vlan_filtering: %d\n",
196197
__func__, port, vlan_filtering);

‎drivers/net/dsa/lantiq_gswip.c‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -736,14 +736,23 @@ static int gswip_pce_load_microcode(struct gswip_priv *priv)
736736
}
737737

738738
static int gswip_port_vlan_filtering(struct dsa_switch *ds, int port,
739-
bool vlan_filtering)
739+
bool vlan_filtering,
740+
struct switchdev_trans *trans)
740741
{
741742
struct gswip_priv *priv = ds->priv;
742-
struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev;
743743

744744
/* Do not allow changing the VLAN filtering options while in bridge */
745-
if (!!(priv->port_vlan_filter & BIT(port)) != vlan_filtering && bridge)
746-
return -EIO;
745+
if (switchdev_trans_ph_prepare(trans)) {
746+
struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev;
747+
748+
if (!bridge)
749+
return 0;
750+
751+
if (!!(priv->port_vlan_filter & BIT(port)) != vlan_filtering)
752+
return -EIO;
753+
754+
return 0;
755+
}
747756

748757
if (vlan_filtering) {
749758
/* Use port based VLAN tag */
@@ -781,8 +790,15 @@ static int gswip_setup(struct dsa_switch *ds)
781790

782791
/* disable port fetch/store dma on all ports */
783792
for (i = 0; i < priv->hw_info->max_ports; i++) {
793+
struct switchdev_trans trans;
794+
795+
/* Skip the prepare phase, this shouldn't return an error
796+
* during setup.
797+
*/
798+
trans.ph_prepare = false;
799+
784800
gswip_port_disable(ds, i);
785-
gswip_port_vlan_filtering(ds, i, false);
801+
gswip_port_vlan_filtering(ds, i, false, &trans);
786802
}
787803

788804
/* enable Switch */

‎drivers/net/dsa/microchip/ksz8795.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,10 +782,14 @@ static void ksz8795_flush_dyn_mac_table(struct ksz_device *dev, int port)
782782
}
783783

784784
static int ksz8795_port_vlan_filtering(struct dsa_switch *ds, int port,
785-
bool flag)
785+
bool flag,
786+
struct switchdev_trans *trans)
786787
{
787788
struct ksz_device *dev = ds->priv;
788789

790+
if (switchdev_trans_ph_prepare(trans))
791+
return 0;
792+
789793
ksz_cfg(dev, S_MIRROR_CTRL, SW_VLAN_ENABLE, flag);
790794

791795
return 0;

‎drivers/net/dsa/microchip/ksz9477.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,14 @@ static void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port)
493493
}
494494

495495
static int ksz9477_port_vlan_filtering(struct dsa_switch *ds, int port,
496-
bool flag)
496+
bool flag,
497+
struct switchdev_trans *trans)
497498
{
498499
struct ksz_device *dev = ds->priv;
499500

501+
if (switchdev_trans_ph_prepare(trans))
502+
return 0;
503+
500504
if (flag) {
501505
ksz_port_cfg(dev, port, REG_PORT_LUE_CTRL,
502506
PORT_VLAN_LOOKUP_VID_0, true);

‎drivers/net/dsa/mt7530.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,8 +1289,12 @@ mt7530_vlan_cmd(struct mt7530_priv *priv, enum mt7530_vlan_cmd cmd, u16 vid)
12891289

12901290
static int
12911291
mt7530_port_vlan_filtering(struct dsa_switch *ds, int port,
1292-
bool vlan_filtering)
1292+
bool vlan_filtering,
1293+
struct switchdev_trans *trans)
12931294
{
1295+
if (switchdev_trans_ph_prepare(trans))
1296+
return 0;
1297+
12941298
if (vlan_filtering) {
12951299
/* The port is being kept as VLAN-unaware port when bridge is
12961300
* set up with vlan_filtering not being set, Otherwise, the

‎drivers/net/dsa/mv88e6xxx/chip.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,15 +1578,16 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
15781578
}
15791579

15801580
static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1581-
bool vlan_filtering)
1581+
bool vlan_filtering,
1582+
struct switchdev_trans *trans)
15821583
{
15831584
struct mv88e6xxx_chip *chip = ds->priv;
15841585
u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
15851586
MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
15861587
int err;
15871588

1588-
if (!chip->info->max_vid)
1589-
return -EOPNOTSUPP;
1589+
if (switchdev_trans_ph_prepare(trans))
1590+
return chip->info->max_vid ? 0 : -EOPNOTSUPP;
15901591

15911592
mv88e6xxx_reg_lock(chip);
15921593
err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);

‎drivers/net/dsa/ocelot/felix.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,12 @@ static int felix_vlan_prepare(struct dsa_switch *ds, int port,
119119
return 0;
120120
}
121121

122-
static int felix_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)
122+
static int felix_vlan_filtering(struct dsa_switch *ds, int port, bool enabled,
123+
struct switchdev_trans *trans)
123124
{
124125
struct ocelot *ocelot = ds->priv;
125126

126-
ocelot_port_vlan_filtering(ocelot, port, enabled);
127-
128-
return 0;
127+
return ocelot_port_vlan_filtering(ocelot, port, enabled, trans);
129128
}
130129

131130
static void felix_vlan_add(struct dsa_switch *ds, int port,

‎drivers/net/dsa/qca8k.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,10 +1294,14 @@ qca8k_port_fdb_dump(struct dsa_switch *ds, int port,
12941294
}
12951295

12961296
static int
1297-
qca8k_port_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering)
1297+
qca8k_port_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
1298+
struct switchdev_trans *trans)
12981299
{
12991300
struct qca8k_priv *priv = ds->priv;
13001301

1302+
if (switchdev_trans_ph_prepare(trans))
1303+
return 0;
1304+
13011305
if (vlan_filtering) {
13021306
qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port),
13031307
QCA8K_PORT_LOOKUP_VLAN_MODE,

0 commit comments

Comments
 (0)