Skip to content

Commit

Permalink
Merge branch 'dsa-cross-chip-notifier-cleanup'
Browse files Browse the repository at this point in the history
Vladimir Oltean says:

====================
DSA cross-chip notifier cleanups

This patch set makes the following improvements:

- Cross-chip notifiers pass a switch index, port index, sometimes tree
  index, all as integers. Sometimes we need to recover the struct
  dsa_port based on those integers. That recovery involves traversing a
  list. By passing directly a pointer to the struct dsa_port we can
  avoid that, and the indices passed previously can still be obtained
  from the passed struct dsa_port.

- Resetting VLAN filtering on a switch has explicit code to make it run
  on a single switch, so it has no place to stay in the cross-chip
  notifier code. Move it out.

- Changing the MTU on a user port affects only that single port, yet the
  code passes through the cross-chip notifier layer where all switches
  are notified. Avoid that.

- Other related cosmetic changes in the MTU changing procedure.

Apart from the slight improvement in performance given by
(a) doing less work in cross-chip notifiers
(b) emitting less cross-chip notifiers
we also end up with about 100 less lines of code.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
davem330 committed Apr 20, 2022
2 parents cc4bdef + be6ff96 commit 8ab38ed
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 239 deletions.
28 changes: 8 additions & 20 deletions net/dsa/dsa_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,15 @@ struct dsa_notifier_ageing_time_info {

/* DSA_NOTIFIER_BRIDGE_* */
struct dsa_notifier_bridge_info {
const struct dsa_port *dp;
struct dsa_bridge bridge;
int tree_index;
int sw_index;
int port;
bool tx_fwd_offload;
struct netlink_ext_ack *extack;
};

/* DSA_NOTIFIER_FDB_* */
struct dsa_notifier_fdb_info {
int sw_index;
int port;
const struct dsa_port *dp;
const unsigned char *addr;
u16 vid;
struct dsa_db db;
Expand All @@ -81,34 +78,28 @@ struct dsa_notifier_lag_fdb_info {

/* DSA_NOTIFIER_MDB_* */
struct dsa_notifier_mdb_info {
const struct dsa_port *dp;
const struct switchdev_obj_port_mdb *mdb;
int sw_index;
int port;
struct dsa_db db;
};

/* DSA_NOTIFIER_LAG_* */
struct dsa_notifier_lag_info {
const struct dsa_port *dp;
struct dsa_lag lag;
int sw_index;
int port;

struct netdev_lag_upper_info *info;
};

/* DSA_NOTIFIER_VLAN_* */
struct dsa_notifier_vlan_info {
const struct dsa_port *dp;
const struct switchdev_obj_port_vlan *vlan;
int sw_index;
int port;
struct netlink_ext_ack *extack;
};

/* DSA_NOTIFIER_MTU */
struct dsa_notifier_mtu_info {
bool targeted_match;
int sw_index;
int port;
const struct dsa_port *dp;
int mtu;
};

Expand All @@ -119,9 +110,7 @@ struct dsa_notifier_tag_proto_info {

/* DSA_NOTIFIER_TAG_8021Q_VLAN_* */
struct dsa_notifier_tag_8021q_vlan_info {
int tree_index;
int sw_index;
int port;
const struct dsa_port *dp;
u16 vid;
};

Expand Down Expand Up @@ -241,8 +230,7 @@ int dsa_port_mst_enable(struct dsa_port *dp, bool on,
struct netlink_ext_ack *extack);
int dsa_port_vlan_msti(struct dsa_port *dp,
const struct switchdev_vlan_msti *msti);
int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu,
bool targeted_match);
int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu);
int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
u16 vid);
int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr,
Expand Down
128 changes: 78 additions & 50 deletions net/dsa/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,59 @@ void dsa_port_disable(struct dsa_port *dp)
rtnl_unlock();
}

static void dsa_port_reset_vlan_filtering(struct dsa_port *dp,
struct dsa_bridge bridge)
{
struct netlink_ext_ack extack = {0};
bool change_vlan_filtering = false;
struct dsa_switch *ds = dp->ds;
bool vlan_filtering;
int err;

if (ds->needs_standalone_vlan_filtering &&
!br_vlan_enabled(bridge.dev)) {
change_vlan_filtering = true;
vlan_filtering = true;
} else if (!ds->needs_standalone_vlan_filtering &&
br_vlan_enabled(bridge.dev)) {
change_vlan_filtering = true;
vlan_filtering = false;
}

/* If the bridge was vlan_filtering, the bridge core doesn't trigger an
* event for changing vlan_filtering setting upon slave ports leaving
* it. That is a good thing, because that lets us handle it and also
* handle the case where the switch's vlan_filtering setting is global
* (not per port). When that happens, the correct moment to trigger the
* vlan_filtering callback is only when the last port leaves the last
* VLAN-aware bridge.
*/
if (change_vlan_filtering && ds->vlan_filtering_is_global) {
dsa_switch_for_each_port(dp, ds) {
struct net_device *br = dsa_port_bridge_dev_get(dp);

if (br && br_vlan_enabled(br)) {
change_vlan_filtering = false;
break;
}
}
}

if (!change_vlan_filtering)
return;

err = dsa_port_vlan_filtering(dp, vlan_filtering, &extack);
if (extack._msg) {
dev_err(ds->dev, "port %d: %s\n", dp->index,
extack._msg);
}
if (err && err != -EOPNOTSUPP) {
dev_err(ds->dev,
"port %d failed to reset VLAN filtering to %d: %pe\n",
dp->index, vlan_filtering, ERR_PTR(err));
}
}

static int dsa_port_inherit_brport_flags(struct dsa_port *dp,
struct netlink_ext_ack *extack)
{
Expand Down Expand Up @@ -313,7 +366,8 @@ static int dsa_port_switchdev_sync_attrs(struct dsa_port *dp,
return 0;
}

static void dsa_port_switchdev_unsync_attrs(struct dsa_port *dp)
static void dsa_port_switchdev_unsync_attrs(struct dsa_port *dp,
struct dsa_bridge bridge)
{
/* Configure the port for standalone mode (no address learning,
* flood everything).
Expand All @@ -333,7 +387,7 @@ static void dsa_port_switchdev_unsync_attrs(struct dsa_port *dp)
*/
dsa_port_set_state_now(dp, BR_STATE_FORWARDING, true);

/* VLAN filtering is handled by dsa_switch_bridge_leave */
dsa_port_reset_vlan_filtering(dp, bridge);

/* Ageing time may be global to the switch chip, so don't change it
* here because we have no good reason (or value) to change it to.
Expand Down Expand Up @@ -405,9 +459,7 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br,
struct netlink_ext_ack *extack)
{
struct dsa_notifier_bridge_info info = {
.tree_index = dp->ds->dst->index,
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
.extack = extack,
};
struct net_device *dev = dp->slave;
Expand Down Expand Up @@ -476,9 +528,7 @@ void dsa_port_pre_bridge_leave(struct dsa_port *dp, struct net_device *br)
void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br)
{
struct dsa_notifier_bridge_info info = {
.tree_index = dp->ds->dst->index,
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
};
int err;

Expand All @@ -501,15 +551,14 @@ void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br)
"port %d failed to notify DSA_NOTIFIER_BRIDGE_LEAVE: %pe\n",
dp->index, ERR_PTR(err));

dsa_port_switchdev_unsync_attrs(dp);
dsa_port_switchdev_unsync_attrs(dp, info.bridge);
}

int dsa_port_lag_change(struct dsa_port *dp,
struct netdev_lag_lower_state_info *linfo)
{
struct dsa_notifier_lag_info info = {
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
};
bool tx_enabled;

Expand Down Expand Up @@ -578,8 +627,7 @@ int dsa_port_lag_join(struct dsa_port *dp, struct net_device *lag_dev,
struct netlink_ext_ack *extack)
{
struct dsa_notifier_lag_info info = {
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
.info = uinfo,
};
struct net_device *bridge_dev;
Expand Down Expand Up @@ -624,8 +672,7 @@ void dsa_port_lag_leave(struct dsa_port *dp, struct net_device *lag_dev)
{
struct net_device *br = dsa_port_bridge_dev_get(dp);
struct dsa_notifier_lag_info info = {
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
};
int err;

Expand Down Expand Up @@ -883,13 +930,10 @@ int dsa_port_vlan_msti(struct dsa_port *dp,
return ds->ops->vlan_msti_set(ds, *dp->bridge, msti);
}

int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu,
bool targeted_match)
int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu)
{
struct dsa_notifier_mtu_info info = {
.sw_index = dp->ds->index,
.targeted_match = targeted_match,
.port = dp->index,
.dp = dp,
.mtu = new_mtu,
};

Expand All @@ -900,8 +944,7 @@ int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
u16 vid)
{
struct dsa_notifier_fdb_info info = {
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
.addr = addr,
.vid = vid,
.db = {
Expand All @@ -924,8 +967,7 @@ int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr,
u16 vid)
{
struct dsa_notifier_fdb_info info = {
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
.addr = addr,
.vid = vid,
.db = {
Expand All @@ -945,8 +987,7 @@ static int dsa_port_host_fdb_add(struct dsa_port *dp,
struct dsa_db db)
{
struct dsa_notifier_fdb_info info = {
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
.addr = addr,
.vid = vid,
.db = db,
Expand Down Expand Up @@ -997,8 +1038,7 @@ static int dsa_port_host_fdb_del(struct dsa_port *dp,
struct dsa_db db)
{
struct dsa_notifier_fdb_info info = {
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
.addr = addr,
.vid = vid,
.db = db,
Expand Down Expand Up @@ -1093,8 +1133,7 @@ int dsa_port_mdb_add(const struct dsa_port *dp,
const struct switchdev_obj_port_mdb *mdb)
{
struct dsa_notifier_mdb_info info = {
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
.mdb = mdb,
.db = {
.type = DSA_DB_BRIDGE,
Expand All @@ -1112,8 +1151,7 @@ int dsa_port_mdb_del(const struct dsa_port *dp,
const struct switchdev_obj_port_mdb *mdb)
{
struct dsa_notifier_mdb_info info = {
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
.mdb = mdb,
.db = {
.type = DSA_DB_BRIDGE,
Expand All @@ -1132,8 +1170,7 @@ static int dsa_port_host_mdb_add(const struct dsa_port *dp,
struct dsa_db db)
{
struct dsa_notifier_mdb_info info = {
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
.mdb = mdb,
.db = db,
};
Expand Down Expand Up @@ -1177,8 +1214,7 @@ static int dsa_port_host_mdb_del(const struct dsa_port *dp,
struct dsa_db db)
{
struct dsa_notifier_mdb_info info = {
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
.mdb = mdb,
.db = db,
};
Expand Down Expand Up @@ -1222,8 +1258,7 @@ int dsa_port_vlan_add(struct dsa_port *dp,
struct netlink_ext_ack *extack)
{
struct dsa_notifier_vlan_info info = {
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
.vlan = vlan,
.extack = extack,
};
Expand All @@ -1235,8 +1270,7 @@ int dsa_port_vlan_del(struct dsa_port *dp,
const struct switchdev_obj_port_vlan *vlan)
{
struct dsa_notifier_vlan_info info = {
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
.vlan = vlan,
};

Expand All @@ -1248,8 +1282,7 @@ int dsa_port_host_vlan_add(struct dsa_port *dp,
struct netlink_ext_ack *extack)
{
struct dsa_notifier_vlan_info info = {
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
.vlan = vlan,
.extack = extack,
};
Expand All @@ -1269,8 +1302,7 @@ int dsa_port_host_vlan_del(struct dsa_port *dp,
const struct switchdev_obj_port_vlan *vlan)
{
struct dsa_notifier_vlan_info info = {
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
.vlan = vlan,
};
struct dsa_port *cpu_dp = dp->cpu_dp;
Expand Down Expand Up @@ -1689,9 +1721,7 @@ void dsa_port_hsr_leave(struct dsa_port *dp, struct net_device *hsr)
int dsa_port_tag_8021q_vlan_add(struct dsa_port *dp, u16 vid, bool broadcast)
{
struct dsa_notifier_tag_8021q_vlan_info info = {
.tree_index = dp->ds->dst->index,
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
.vid = vid,
};

Expand All @@ -1704,9 +1734,7 @@ int dsa_port_tag_8021q_vlan_add(struct dsa_port *dp, u16 vid, bool broadcast)
void dsa_port_tag_8021q_vlan_del(struct dsa_port *dp, u16 vid, bool broadcast)
{
struct dsa_notifier_tag_8021q_vlan_info info = {
.tree_index = dp->ds->dst->index,
.sw_index = dp->ds->index,
.port = dp->index,
.dp = dp,
.vid = vid,
};
int err;
Expand Down
Loading

0 comments on commit 8ab38ed

Please sign in to comment.