Skip to content

Commit 3095f51

Browse files
committed
Merge branch 'bridge-replay-helpers'
Vladimir Oltean says: ==================== Cleanup for the bridge replay helpers This patch series brings some improvements to the logic added to the bridge and DSA to handle LAG interfaces sandwiched between a bridge and a DSA switch port. br0 / \ / \ bond0 swp2 / \ / \ swp0 swp1 In particular, it ensures that the switchdev object additions and deletions are well balanced per physical port. This is important for future work in the area of offloading local bridge FDB entries to hardware in the context of DSA requesting a replay of those entries at bridge join time (this will be submitted in a future patch series). Due to some difficulty ensuring that the deletion of local FDB entries pointing towards the bridge device itself is notified to switchdev in time (before the switchdev port disconnects from the bridge), this is potentially still not the final form in which the replay helpers will exist. I'm thinking about moving from the pull mode (in which DSA requests the replay) to a push mode (in which the bridge initiates the replay). Nonetheless, these preliminary changes are needed either way. The patch series also addresses some feedback from Nikolai which is long overdue by now (sorry). Switchdev driver maintainers were deliberately omitted due to the trivial nature of the driver changes (just a function prototype). Changes in v2: - fix build issue in patch 4 (function prototype mismatch) - move switchdev object unsync to the NETDEV_PRECHANGEUPPER code path ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents a1b0563 + 7491894 commit 3095f51

File tree

18 files changed

+267
-98
lines changed

18 files changed

+267
-98
lines changed

drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,7 @@ static int dpaa2_switch_port_bridge_flags(struct net_device *netdev,
16251625
return 0;
16261626
}
16271627

1628-
static int dpaa2_switch_port_attr_set(struct net_device *netdev,
1628+
static int dpaa2_switch_port_attr_set(struct net_device *netdev, const void *ctx,
16291629
const struct switchdev_attr *attr,
16301630
struct netlink_ext_ack *extack)
16311631
{

drivers/net/ethernet/marvell/prestera/prestera_switchdev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ static int prestera_port_attr_stp_state_set(struct prestera_port *port,
708708
return err;
709709
}
710710

711-
static int prestera_port_obj_attr_set(struct net_device *dev,
711+
static int prestera_port_obj_attr_set(struct net_device *dev, const void *ctx,
712712
const struct switchdev_attr *attr,
713713
struct netlink_ext_ack *extack)
714714
{
@@ -1040,7 +1040,7 @@ static int prestera_port_vlans_add(struct prestera_port *port,
10401040
flag_pvid, extack);
10411041
}
10421042

1043-
static int prestera_port_obj_add(struct net_device *dev,
1043+
static int prestera_port_obj_add(struct net_device *dev, const void *ctx,
10441044
const struct switchdev_obj *obj,
10451045
struct netlink_ext_ack *extack)
10461046
{
@@ -1078,7 +1078,7 @@ static int prestera_port_vlans_del(struct prestera_port *port,
10781078
return 0;
10791079
}
10801080

1081-
static int prestera_port_obj_del(struct net_device *dev,
1081+
static int prestera_port_obj_del(struct net_device *dev, const void *ctx,
10821082
const struct switchdev_obj *obj)
10831083
{
10841084
struct prestera_port *port = netdev_priv(dev);

drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ static int mlx5_esw_bridge_switchdev_port_event(struct notifier_block *nb,
7676
}
7777

7878
static int mlx5_esw_bridge_port_obj_add(struct net_device *dev,
79+
const void *ctx,
7980
const struct switchdev_obj *obj,
8081
struct netlink_ext_ack *extack)
8182
{
@@ -107,6 +108,7 @@ static int mlx5_esw_bridge_port_obj_add(struct net_device *dev,
107108
}
108109

109110
static int mlx5_esw_bridge_port_obj_del(struct net_device *dev,
111+
const void *ctx,
110112
const struct switchdev_obj *obj)
111113
{
112114
const struct switchdev_obj_port_vlan *vlan;
@@ -136,6 +138,7 @@ static int mlx5_esw_bridge_port_obj_del(struct net_device *dev,
136138
}
137139

138140
static int mlx5_esw_bridge_port_obj_attr_set(struct net_device *dev,
141+
const void *ctx,
139142
const struct switchdev_attr *attr,
140143
struct netlink_ext_ack *extack)
141144
{

drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ mlxsw_sp_port_attr_br_mrouter_set(struct mlxsw_sp_port *mlxsw_sp_port,
898898
return 0;
899899
}
900900

901-
static int mlxsw_sp_port_attr_set(struct net_device *dev,
901+
static int mlxsw_sp_port_attr_set(struct net_device *dev, const void *ctx,
902902
const struct switchdev_attr *attr,
903903
struct netlink_ext_ack *extack)
904904
{
@@ -1766,7 +1766,7 @@ mlxsw_sp_port_mrouter_update_mdb(struct mlxsw_sp_port *mlxsw_sp_port,
17661766
}
17671767
}
17681768

1769-
static int mlxsw_sp_port_obj_add(struct net_device *dev,
1769+
static int mlxsw_sp_port_obj_add(struct net_device *dev, const void *ctx,
17701770
const struct switchdev_obj *obj,
17711771
struct netlink_ext_ack *extack)
17721772
{
@@ -1916,7 +1916,7 @@ mlxsw_sp_bridge_port_mdb_flush(struct mlxsw_sp_port *mlxsw_sp_port,
19161916
}
19171917
}
19181918

1919-
static int mlxsw_sp_port_obj_del(struct net_device *dev,
1919+
static int mlxsw_sp_port_obj_del(struct net_device *dev, const void *ctx,
19201920
const struct switchdev_obj *obj)
19211921
{
19221922
struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);

drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static void sparx5_port_attr_ageing_set(struct sparx5_port *port,
6565
sparx5_set_ageing(port->sparx5, ageing_time);
6666
}
6767

68-
static int sparx5_port_attr_set(struct net_device *dev,
68+
static int sparx5_port_attr_set(struct net_device *dev, const void *ctx,
6969
const struct switchdev_attr *attr,
7070
struct netlink_ext_ack *extack)
7171
{

drivers/net/ethernet/mscc/ocelot_net.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ static void ocelot_port_attr_mc_set(struct ocelot *ocelot, int port, bool mc)
939939
ANA_PORT_CPU_FWD_CFG, port);
940940
}
941941

942-
static int ocelot_port_attr_set(struct net_device *dev,
942+
static int ocelot_port_attr_set(struct net_device *dev, const void *ctx,
943943
const struct switchdev_attr *attr,
944944
struct netlink_ext_ack *extack)
945945
{
@@ -948,6 +948,9 @@ static int ocelot_port_attr_set(struct net_device *dev,
948948
int port = priv->chip_port;
949949
int err = 0;
950950

951+
if (ctx && ctx != priv)
952+
return 0;
953+
951954
switch (attr->id) {
952955
case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
953956
ocelot_port_attr_stp_state_set(ocelot, port, attr->u.stp_state);
@@ -1058,12 +1061,16 @@ ocelot_port_obj_mrp_del_ring_role(struct net_device *dev,
10581061
return ocelot_mrp_del_ring_role(ocelot, port, mrp);
10591062
}
10601063

1061-
static int ocelot_port_obj_add(struct net_device *dev,
1064+
static int ocelot_port_obj_add(struct net_device *dev, const void *ctx,
10621065
const struct switchdev_obj *obj,
10631066
struct netlink_ext_ack *extack)
10641067
{
1068+
struct ocelot_port_private *priv = netdev_priv(dev);
10651069
int ret = 0;
10661070

1071+
if (ctx && ctx != priv)
1072+
return 0;
1073+
10671074
switch (obj->id) {
10681075
case SWITCHDEV_OBJ_ID_PORT_VLAN:
10691076
ret = ocelot_port_obj_add_vlan(dev,
@@ -1086,11 +1093,15 @@ static int ocelot_port_obj_add(struct net_device *dev,
10861093
return ret;
10871094
}
10881095

1089-
static int ocelot_port_obj_del(struct net_device *dev,
1096+
static int ocelot_port_obj_del(struct net_device *dev, const void *ctx,
10901097
const struct switchdev_obj *obj)
10911098
{
1099+
struct ocelot_port_private *priv = netdev_priv(dev);
10921100
int ret = 0;
10931101

1102+
if (ctx && ctx != priv)
1103+
return 0;
1104+
10941105
switch (obj->id) {
10951106
case SWITCHDEV_OBJ_ID_PORT_VLAN:
10961107
ret = ocelot_vlan_vid_del(dev,
@@ -1143,10 +1154,14 @@ static int ocelot_switchdev_sync(struct ocelot *ocelot, int port,
11431154
struct net_device *bridge_dev,
11441155
struct netlink_ext_ack *extack)
11451156
{
1157+
struct ocelot_port *ocelot_port = ocelot->ports[port];
1158+
struct ocelot_port_private *priv;
11461159
clock_t ageing_time;
11471160
u8 stp_state;
11481161
int err;
11491162

1163+
priv = container_of(ocelot_port, struct ocelot_port_private, port);
1164+
11501165
ocelot_inherit_brport_flags(ocelot, port, brport_dev);
11511166

11521167
stp_state = br_port_get_stp_state(brport_dev);
@@ -1160,16 +1175,12 @@ static int ocelot_switchdev_sync(struct ocelot *ocelot, int port,
11601175
ageing_time = br_get_ageing_time(bridge_dev);
11611176
ocelot_port_attr_ageing_set(ocelot, port, ageing_time);
11621177

1163-
err = br_mdb_replay(bridge_dev, brport_dev,
1178+
err = br_mdb_replay(bridge_dev, brport_dev, priv, true,
11641179
&ocelot_switchdev_blocking_nb, extack);
11651180
if (err && err != -EOPNOTSUPP)
11661181
return err;
11671182

1168-
err = br_fdb_replay(bridge_dev, brport_dev, &ocelot_switchdev_nb);
1169-
if (err)
1170-
return err;
1171-
1172-
err = br_vlan_replay(bridge_dev, brport_dev,
1183+
err = br_vlan_replay(bridge_dev, brport_dev, priv, true,
11731184
&ocelot_switchdev_blocking_nb, extack);
11741185
if (err && err != -EOPNOTSUPP)
11751186
return err;

drivers/net/ethernet/ti/am65-cpsw-switchdev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static int am65_cpsw_port_attr_br_flags_pre_set(struct net_device *netdev,
8484
return 0;
8585
}
8686

87-
static int am65_cpsw_port_attr_set(struct net_device *ndev,
87+
static int am65_cpsw_port_attr_set(struct net_device *ndev, const void *ctx,
8888
const struct switchdev_attr *attr,
8989
struct netlink_ext_ack *extack)
9090
{
@@ -302,7 +302,7 @@ static int am65_cpsw_port_mdb_del(struct am65_cpsw_port *port,
302302
return 0;
303303
}
304304

305-
static int am65_cpsw_port_obj_add(struct net_device *ndev,
305+
static int am65_cpsw_port_obj_add(struct net_device *ndev, const void *ctx,
306306
const struct switchdev_obj *obj,
307307
struct netlink_ext_ack *extack)
308308
{
@@ -329,7 +329,7 @@ static int am65_cpsw_port_obj_add(struct net_device *ndev,
329329
return err;
330330
}
331331

332-
static int am65_cpsw_port_obj_del(struct net_device *ndev,
332+
static int am65_cpsw_port_obj_del(struct net_device *ndev, const void *ctx,
333333
const struct switchdev_obj *obj)
334334
{
335335
struct switchdev_obj_port_vlan *vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);

drivers/net/ethernet/ti/cpsw_switchdev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static int cpsw_port_attr_br_flags_pre_set(struct net_device *netdev,
8686
return 0;
8787
}
8888

89-
static int cpsw_port_attr_set(struct net_device *ndev,
89+
static int cpsw_port_attr_set(struct net_device *ndev, const void *ctx,
9090
const struct switchdev_attr *attr,
9191
struct netlink_ext_ack *extack)
9292
{
@@ -310,7 +310,7 @@ static int cpsw_port_mdb_del(struct cpsw_priv *priv,
310310
return err;
311311
}
312312

313-
static int cpsw_port_obj_add(struct net_device *ndev,
313+
static int cpsw_port_obj_add(struct net_device *ndev, const void *ctx,
314314
const struct switchdev_obj *obj,
315315
struct netlink_ext_ack *extack)
316316
{
@@ -338,7 +338,7 @@ static int cpsw_port_obj_add(struct net_device *ndev,
338338
return err;
339339
}
340340

341-
static int cpsw_port_obj_del(struct net_device *ndev,
341+
static int cpsw_port_obj_del(struct net_device *ndev, const void *ctx,
342342
const struct switchdev_obj *obj)
343343
{
344344
struct switchdev_obj_port_vlan *vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);

include/linux/if_bridge.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ bool br_multicast_has_router_adjacent(struct net_device *dev, int proto);
7171
bool br_multicast_enabled(const struct net_device *dev);
7272
bool br_multicast_router(const struct net_device *dev);
7373
int br_mdb_replay(struct net_device *br_dev, struct net_device *dev,
74-
struct notifier_block *nb, struct netlink_ext_ack *extack);
74+
const void *ctx, bool adding, struct notifier_block *nb,
75+
struct netlink_ext_ack *extack);
7576
#else
7677
static inline int br_multicast_list_adjacent(struct net_device *dev,
7778
struct list_head *br_ip_list)
@@ -103,9 +104,9 @@ static inline bool br_multicast_router(const struct net_device *dev)
103104
{
104105
return false;
105106
}
106-
static inline int br_mdb_replay(struct net_device *br_dev,
107-
struct net_device *dev,
108-
struct notifier_block *nb,
107+
static inline int br_mdb_replay(const struct net_device *br_dev,
108+
const struct net_device *dev, const void *ctx,
109+
bool adding, struct notifier_block *nb,
109110
struct netlink_ext_ack *extack)
110111
{
111112
return -EOPNOTSUPP;
@@ -120,7 +121,8 @@ int br_vlan_get_proto(const struct net_device *dev, u16 *p_proto);
120121
int br_vlan_get_info(const struct net_device *dev, u16 vid,
121122
struct bridge_vlan_info *p_vinfo);
122123
int br_vlan_replay(struct net_device *br_dev, struct net_device *dev,
123-
struct notifier_block *nb, struct netlink_ext_ack *extack);
124+
const void *ctx, bool adding, struct notifier_block *nb,
125+
struct netlink_ext_ack *extack);
124126
#else
125127
static inline bool br_vlan_enabled(const struct net_device *dev)
126128
{
@@ -149,8 +151,8 @@ static inline int br_vlan_get_info(const struct net_device *dev, u16 vid,
149151
}
150152

151153
static inline int br_vlan_replay(struct net_device *br_dev,
152-
struct net_device *dev,
153-
struct notifier_block *nb,
154+
struct net_device *dev, const void *ctx,
155+
bool adding, struct notifier_block *nb,
154156
struct netlink_ext_ack *extack)
155157
{
156158
return -EOPNOTSUPP;
@@ -164,9 +166,9 @@ struct net_device *br_fdb_find_port(const struct net_device *br_dev,
164166
void br_fdb_clear_offload(const struct net_device *dev, u16 vid);
165167
bool br_port_flag_is_set(const struct net_device *dev, unsigned long flag);
166168
u8 br_port_get_stp_state(const struct net_device *dev);
167-
clock_t br_get_ageing_time(struct net_device *br_dev);
168-
int br_fdb_replay(struct net_device *br_dev, struct net_device *dev,
169-
struct notifier_block *nb);
169+
clock_t br_get_ageing_time(const struct net_device *br_dev);
170+
int br_fdb_replay(const struct net_device *br_dev, const struct net_device *dev,
171+
const void *ctx, bool adding, struct notifier_block *nb);
170172
#else
171173
static inline struct net_device *
172174
br_fdb_find_port(const struct net_device *br_dev,
@@ -191,14 +193,14 @@ static inline u8 br_port_get_stp_state(const struct net_device *dev)
191193
return BR_STATE_DISABLED;
192194
}
193195

194-
static inline clock_t br_get_ageing_time(struct net_device *br_dev)
196+
static inline clock_t br_get_ageing_time(const struct net_device *br_dev)
195197
{
196198
return 0;
197199
}
198200

199-
static inline int br_fdb_replay(struct net_device *br_dev,
200-
struct net_device *dev,
201-
struct notifier_block *nb)
201+
static inline int br_fdb_replay(const struct net_device *br_dev,
202+
const struct net_device *dev, const void *ctx,
203+
bool adding, struct notifier_block *nb)
202204
{
203205
return -EOPNOTSUPP;
204206
}

include/net/switchdev.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ enum switchdev_notifier_type {
202202
struct switchdev_notifier_info {
203203
struct net_device *dev;
204204
struct netlink_ext_ack *extack;
205+
const void *ctx;
205206
};
206207

207208
struct switchdev_notifier_fdb_info {
@@ -268,19 +269,19 @@ void switchdev_port_fwd_mark_set(struct net_device *dev,
268269
int switchdev_handle_port_obj_add(struct net_device *dev,
269270
struct switchdev_notifier_port_obj_info *port_obj_info,
270271
bool (*check_cb)(const struct net_device *dev),
271-
int (*add_cb)(struct net_device *dev,
272+
int (*add_cb)(struct net_device *dev, const void *ctx,
272273
const struct switchdev_obj *obj,
273274
struct netlink_ext_ack *extack));
274275
int switchdev_handle_port_obj_del(struct net_device *dev,
275276
struct switchdev_notifier_port_obj_info *port_obj_info,
276277
bool (*check_cb)(const struct net_device *dev),
277-
int (*del_cb)(struct net_device *dev,
278+
int (*del_cb)(struct net_device *dev, const void *ctx,
278279
const struct switchdev_obj *obj));
279280

280281
int switchdev_handle_port_attr_set(struct net_device *dev,
281282
struct switchdev_notifier_port_attr_info *port_attr_info,
282283
bool (*check_cb)(const struct net_device *dev),
283-
int (*set_cb)(struct net_device *dev,
284+
int (*set_cb)(struct net_device *dev, const void *ctx,
284285
const struct switchdev_attr *attr,
285286
struct netlink_ext_ack *extack));
286287
#else
@@ -352,7 +353,7 @@ static inline int
352353
switchdev_handle_port_obj_add(struct net_device *dev,
353354
struct switchdev_notifier_port_obj_info *port_obj_info,
354355
bool (*check_cb)(const struct net_device *dev),
355-
int (*add_cb)(struct net_device *dev,
356+
int (*add_cb)(struct net_device *dev, const void *ctx,
356357
const struct switchdev_obj *obj,
357358
struct netlink_ext_ack *extack))
358359
{
@@ -363,7 +364,7 @@ static inline int
363364
switchdev_handle_port_obj_del(struct net_device *dev,
364365
struct switchdev_notifier_port_obj_info *port_obj_info,
365366
bool (*check_cb)(const struct net_device *dev),
366-
int (*del_cb)(struct net_device *dev,
367+
int (*del_cb)(struct net_device *dev, const void *ctx,
367368
const struct switchdev_obj *obj))
368369
{
369370
return 0;
@@ -373,7 +374,7 @@ static inline int
373374
switchdev_handle_port_attr_set(struct net_device *dev,
374375
struct switchdev_notifier_port_attr_info *port_attr_info,
375376
bool (*check_cb)(const struct net_device *dev),
376-
int (*set_cb)(struct net_device *dev,
377+
int (*set_cb)(struct net_device *dev, const void *ctx,
377378
const struct switchdev_attr *attr,
378379
struct netlink_ext_ack *extack))
379380
{

0 commit comments

Comments
 (0)