Commit 5420683a authored by David S. Miller's avatar David S. Miller

Merge branch 'dsa-simplify-switchdev-prepare-phase'

Vivien Didelot says:

====================
net: dsa: simplify switchdev prepare phase

This patch series brings no functional changes.

It removes the unused switchdev_trans arguments from the dsa_switch_ops
for both MDB and VLAN operations, and provides functions to prepare and
add these objects for a given bitmap of ports.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 183dea58 e6db98db
...@@ -1029,8 +1029,7 @@ int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering) ...@@ -1029,8 +1029,7 @@ int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering)
EXPORT_SYMBOL(b53_vlan_filtering); EXPORT_SYMBOL(b53_vlan_filtering);
int b53_vlan_prepare(struct dsa_switch *ds, int port, int b53_vlan_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan, const struct switchdev_obj_port_vlan *vlan)
struct switchdev_trans *trans)
{ {
struct b53_device *dev = ds->priv; struct b53_device *dev = ds->priv;
...@@ -1047,8 +1046,7 @@ int b53_vlan_prepare(struct dsa_switch *ds, int port, ...@@ -1047,8 +1046,7 @@ int b53_vlan_prepare(struct dsa_switch *ds, int port,
EXPORT_SYMBOL(b53_vlan_prepare); EXPORT_SYMBOL(b53_vlan_prepare);
void b53_vlan_add(struct dsa_switch *ds, int port, void b53_vlan_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan, const struct switchdev_obj_port_vlan *vlan)
struct switchdev_trans *trans)
{ {
struct b53_device *dev = ds->priv; struct b53_device *dev = ds->priv;
bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
......
...@@ -295,11 +295,9 @@ void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state); ...@@ -295,11 +295,9 @@ void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state);
void b53_br_fast_age(struct dsa_switch *ds, int port); void b53_br_fast_age(struct dsa_switch *ds, int port);
int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering); int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering);
int b53_vlan_prepare(struct dsa_switch *ds, int port, int b53_vlan_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan, const struct switchdev_obj_port_vlan *vlan);
struct switchdev_trans *trans);
void b53_vlan_add(struct dsa_switch *ds, int port, void b53_vlan_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan, const struct switchdev_obj_port_vlan *vlan);
struct switchdev_trans *trans);
int b53_vlan_del(struct dsa_switch *ds, int port, int b53_vlan_del(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan); const struct switchdev_obj_port_vlan *vlan);
int b53_fdb_add(struct dsa_switch *ds, int port, int b53_fdb_add(struct dsa_switch *ds, int port,
......
...@@ -174,9 +174,9 @@ static int dsa_loop_port_vlan_filtering(struct dsa_switch *ds, int port, ...@@ -174,9 +174,9 @@ static int dsa_loop_port_vlan_filtering(struct dsa_switch *ds, int port,
return 0; return 0;
} }
static int dsa_loop_port_vlan_prepare(struct dsa_switch *ds, int port, static int
const struct switchdev_obj_port_vlan *vlan, dsa_loop_port_vlan_prepare(struct dsa_switch *ds, int port,
struct switchdev_trans *trans) const struct switchdev_obj_port_vlan *vlan)
{ {
struct dsa_loop_priv *ps = ds->priv; struct dsa_loop_priv *ps = ds->priv;
struct mii_bus *bus = ps->bus; struct mii_bus *bus = ps->bus;
...@@ -193,8 +193,7 @@ static int dsa_loop_port_vlan_prepare(struct dsa_switch *ds, int port, ...@@ -193,8 +193,7 @@ static int dsa_loop_port_vlan_prepare(struct dsa_switch *ds, int port,
} }
static void dsa_loop_port_vlan_add(struct dsa_switch *ds, int port, static void dsa_loop_port_vlan_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan, const struct switchdev_obj_port_vlan *vlan)
struct switchdev_trans *trans)
{ {
bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
......
...@@ -1217,8 +1217,7 @@ static int lan9303_port_fdb_dump(struct dsa_switch *ds, int port, ...@@ -1217,8 +1217,7 @@ static int lan9303_port_fdb_dump(struct dsa_switch *ds, int port,
} }
static int lan9303_port_mdb_prepare(struct dsa_switch *ds, int port, static int lan9303_port_mdb_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_mdb *mdb, const struct switchdev_obj_port_mdb *mdb)
struct switchdev_trans *trans)
{ {
struct lan9303 *chip = ds->priv; struct lan9303 *chip = ds->priv;
...@@ -1235,8 +1234,7 @@ static int lan9303_port_mdb_prepare(struct dsa_switch *ds, int port, ...@@ -1235,8 +1234,7 @@ static int lan9303_port_mdb_prepare(struct dsa_switch *ds, int port,
} }
static void lan9303_port_mdb_add(struct dsa_switch *ds, int port, static void lan9303_port_mdb_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_mdb *mdb, const struct switchdev_obj_port_mdb *mdb)
struct switchdev_trans *trans)
{ {
struct lan9303 *chip = ds->priv; struct lan9303 *chip = ds->priv;
......
...@@ -559,8 +559,7 @@ static int ksz_port_vlan_filtering(struct dsa_switch *ds, int port, bool flag) ...@@ -559,8 +559,7 @@ static int ksz_port_vlan_filtering(struct dsa_switch *ds, int port, bool flag)
} }
static int ksz_port_vlan_prepare(struct dsa_switch *ds, int port, static int ksz_port_vlan_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan, const struct switchdev_obj_port_vlan *vlan)
struct switchdev_trans *trans)
{ {
/* nothing needed */ /* nothing needed */
...@@ -568,8 +567,7 @@ static int ksz_port_vlan_prepare(struct dsa_switch *ds, int port, ...@@ -568,8 +567,7 @@ static int ksz_port_vlan_prepare(struct dsa_switch *ds, int port,
} }
static void ksz_port_vlan_add(struct dsa_switch *ds, int port, static void ksz_port_vlan_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan, const struct switchdev_obj_port_vlan *vlan)
struct switchdev_trans *trans)
{ {
struct ksz_device *dev = ds->priv; struct ksz_device *dev = ds->priv;
u32 vlan_table[3]; u32 vlan_table[3];
...@@ -858,16 +856,14 @@ static int ksz_port_fdb_dump(struct dsa_switch *ds, int port, ...@@ -858,16 +856,14 @@ static int ksz_port_fdb_dump(struct dsa_switch *ds, int port,
} }
static int ksz_port_mdb_prepare(struct dsa_switch *ds, int port, static int ksz_port_mdb_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_mdb *mdb, const struct switchdev_obj_port_mdb *mdb)
struct switchdev_trans *trans)
{ {
/* nothing to do */ /* nothing to do */
return 0; return 0;
} }
static void ksz_port_mdb_add(struct dsa_switch *ds, int port, static void ksz_port_mdb_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_mdb *mdb, const struct switchdev_obj_port_mdb *mdb)
struct switchdev_trans *trans)
{ {
struct ksz_device *dev = ds->priv; struct ksz_device *dev = ds->priv;
u32 static_table[4]; u32 static_table[4];
......
...@@ -1185,8 +1185,7 @@ static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port, ...@@ -1185,8 +1185,7 @@ static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
static int static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port, mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan, const struct switchdev_obj_port_vlan *vlan)
struct switchdev_trans *trans)
{ {
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
int err; int err;
...@@ -1295,8 +1294,7 @@ static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port, ...@@ -1295,8 +1294,7 @@ static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
} }
static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port, static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan, const struct switchdev_obj_port_vlan *vlan)
struct switchdev_trans *trans)
{ {
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
...@@ -3788,8 +3786,7 @@ static const char *mv88e6xxx_drv_probe(struct device *dsa_dev, ...@@ -3788,8 +3786,7 @@ static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
} }
static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port, static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_mdb *mdb, const struct switchdev_obj_port_mdb *mdb)
struct switchdev_trans *trans)
{ {
/* We don't need any dynamic resource from the kernel (yet), /* We don't need any dynamic resource from the kernel (yet),
* so skip the prepare phase. * so skip the prepare phase.
...@@ -3799,8 +3796,7 @@ static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port, ...@@ -3799,8 +3796,7 @@ static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
} }
static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port, static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_mdb *mdb, const struct switchdev_obj_port_mdb *mdb)
struct switchdev_trans *trans)
{ {
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
......
...@@ -412,12 +412,10 @@ struct dsa_switch_ops { ...@@ -412,12 +412,10 @@ struct dsa_switch_ops {
*/ */
int (*port_vlan_filtering)(struct dsa_switch *ds, int port, int (*port_vlan_filtering)(struct dsa_switch *ds, int port,
bool vlan_filtering); bool vlan_filtering);
int (*port_vlan_prepare)(struct dsa_switch *ds, int port, int (*port_vlan_prepare)(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan, const struct switchdev_obj_port_vlan *vlan);
struct switchdev_trans *trans); void (*port_vlan_add)(struct dsa_switch *ds, int port,
void (*port_vlan_add)(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan);
const struct switchdev_obj_port_vlan *vlan,
struct switchdev_trans *trans);
int (*port_vlan_del)(struct dsa_switch *ds, int port, int (*port_vlan_del)(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan); const struct switchdev_obj_port_vlan *vlan);
/* /*
...@@ -433,12 +431,10 @@ struct dsa_switch_ops { ...@@ -433,12 +431,10 @@ struct dsa_switch_ops {
/* /*
* Multicast database * Multicast database
*/ */
int (*port_mdb_prepare)(struct dsa_switch *ds, int port, int (*port_mdb_prepare)(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_mdb *mdb, const struct switchdev_obj_port_mdb *mdb);
struct switchdev_trans *trans); void (*port_mdb_add)(struct dsa_switch *ds, int port,
void (*port_mdb_add)(struct dsa_switch *ds, int port, const struct switchdev_obj_port_mdb *mdb);
const struct switchdev_obj_port_mdb *mdb,
struct switchdev_trans *trans);
int (*port_mdb_del)(struct dsa_switch *ds, int port, int (*port_mdb_del)(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_mdb *mdb); const struct switchdev_obj_port_mdb *mdb);
/* /*
......
...@@ -108,13 +108,42 @@ static int dsa_switch_fdb_del(struct dsa_switch *ds, ...@@ -108,13 +108,42 @@ static int dsa_switch_fdb_del(struct dsa_switch *ds,
info->vid); info->vid);
} }
static int
dsa_switch_mdb_prepare_bitmap(struct dsa_switch *ds,
const struct switchdev_obj_port_mdb *mdb,
const unsigned long *bitmap)
{
int port, err;
if (!ds->ops->port_mdb_prepare || !ds->ops->port_mdb_add)
return -EOPNOTSUPP;
for_each_set_bit(port, bitmap, ds->num_ports) {
err = ds->ops->port_mdb_prepare(ds, port, mdb);
if (err)
return err;
}
return 0;
}
static void dsa_switch_mdb_add_bitmap(struct dsa_switch *ds,
const struct switchdev_obj_port_mdb *mdb,
const unsigned long *bitmap)
{
int port;
for_each_set_bit(port, bitmap, ds->num_ports)
ds->ops->port_mdb_add(ds, port, mdb);
}
static int dsa_switch_mdb_add(struct dsa_switch *ds, static int dsa_switch_mdb_add(struct dsa_switch *ds,
struct dsa_notifier_mdb_info *info) struct dsa_notifier_mdb_info *info)
{ {
const struct switchdev_obj_port_mdb *mdb = info->mdb; const struct switchdev_obj_port_mdb *mdb = info->mdb;
struct switchdev_trans *trans = info->trans; struct switchdev_trans *trans = info->trans;
DECLARE_BITMAP(group, ds->num_ports); DECLARE_BITMAP(group, ds->num_ports);
int port, err; int port;
/* Build a mask of Multicast group members */ /* Build a mask of Multicast group members */
bitmap_zero(group, ds->num_ports); bitmap_zero(group, ds->num_ports);
...@@ -124,21 +153,10 @@ static int dsa_switch_mdb_add(struct dsa_switch *ds, ...@@ -124,21 +153,10 @@ static int dsa_switch_mdb_add(struct dsa_switch *ds,
if (dsa_is_dsa_port(ds, port)) if (dsa_is_dsa_port(ds, port))
set_bit(port, group); set_bit(port, group);
if (switchdev_trans_ph_prepare(trans)) { if (switchdev_trans_ph_prepare(trans))
if (!ds->ops->port_mdb_prepare || !ds->ops->port_mdb_add) return dsa_switch_mdb_prepare_bitmap(ds, mdb, group);
return -EOPNOTSUPP;
for_each_set_bit(port, group, ds->num_ports) {
err = ds->ops->port_mdb_prepare(ds, port, mdb, trans);
if (err)
return err;
}
return 0;
}
for_each_set_bit(port, group, ds->num_ports) dsa_switch_mdb_add_bitmap(ds, mdb, group);
ds->ops->port_mdb_add(ds, port, mdb, trans);
return 0; return 0;
} }
...@@ -157,13 +175,43 @@ static int dsa_switch_mdb_del(struct dsa_switch *ds, ...@@ -157,13 +175,43 @@ static int dsa_switch_mdb_del(struct dsa_switch *ds,
return 0; return 0;
} }
static int
dsa_switch_vlan_prepare_bitmap(struct dsa_switch *ds,
const struct switchdev_obj_port_vlan *vlan,
const unsigned long *bitmap)
{
int port, err;
if (!ds->ops->port_vlan_prepare || !ds->ops->port_vlan_add)
return -EOPNOTSUPP;
for_each_set_bit(port, bitmap, ds->num_ports) {
err = ds->ops->port_vlan_prepare(ds, port, vlan);
if (err)
return err;
}
return 0;
}
static void
dsa_switch_vlan_add_bitmap(struct dsa_switch *ds,
const struct switchdev_obj_port_vlan *vlan,
const unsigned long *bitmap)
{
int port;
for_each_set_bit(port, bitmap, ds->num_ports)
ds->ops->port_vlan_add(ds, port, vlan);
}
static int dsa_switch_vlan_add(struct dsa_switch *ds, static int dsa_switch_vlan_add(struct dsa_switch *ds,
struct dsa_notifier_vlan_info *info) struct dsa_notifier_vlan_info *info)
{ {
const struct switchdev_obj_port_vlan *vlan = info->vlan; const struct switchdev_obj_port_vlan *vlan = info->vlan;
struct switchdev_trans *trans = info->trans; struct switchdev_trans *trans = info->trans;
DECLARE_BITMAP(members, ds->num_ports); DECLARE_BITMAP(members, ds->num_ports);
int port, err; int port;
/* Build a mask of VLAN members */ /* Build a mask of VLAN members */
bitmap_zero(members, ds->num_ports); bitmap_zero(members, ds->num_ports);
...@@ -173,21 +221,10 @@ static int dsa_switch_vlan_add(struct dsa_switch *ds, ...@@ -173,21 +221,10 @@ static int dsa_switch_vlan_add(struct dsa_switch *ds,
if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
set_bit(port, members); set_bit(port, members);
if (switchdev_trans_ph_prepare(trans)) { if (switchdev_trans_ph_prepare(trans))
if (!ds->ops->port_vlan_prepare || !ds->ops->port_vlan_add) return dsa_switch_vlan_prepare_bitmap(ds, vlan, members);
return -EOPNOTSUPP;
for_each_set_bit(port, members, ds->num_ports) {
err = ds->ops->port_vlan_prepare(ds, port, vlan, trans);
if (err)
return err;
}
return 0;
}
for_each_set_bit(port, members, ds->num_ports) dsa_switch_vlan_add_bitmap(ds, vlan, members);
ds->ops->port_vlan_add(ds, port, vlan, trans);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment