Skip to content

Commit c8e6a9e

Browse files
mark-blochSaeed Mahameed
authored andcommitted
net/mlx5: E-Switch, Add event callback for representors
This callback will allow to notify representors about relevant events when in OFFLOADS mode. In downstream patches, this will be used to notify about PAIR/UNPAIR devcom events. Signed-off-by: Mark Bloch <mbloch@nvidia.com> Reviewed-by: Mark Zhang <markzhang@nvidia.com> Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
1 parent 2198b93 commit c8e6a9e

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,21 +2316,65 @@ void esw_offloads_unload_rep(struct mlx5_eswitch *esw, u16 vport_num)
23162316
#define ESW_OFFLOADS_DEVCOM_PAIR (0)
23172317
#define ESW_OFFLOADS_DEVCOM_UNPAIR (1)
23182318

2319-
static int mlx5_esw_offloads_pair(struct mlx5_eswitch *esw,
2320-
struct mlx5_eswitch *peer_esw)
2319+
static void mlx5_esw_offloads_rep_event_unpair(struct mlx5_eswitch *esw)
23212320
{
2321+
const struct mlx5_eswitch_rep_ops *ops;
2322+
struct mlx5_eswitch_rep *rep;
2323+
unsigned long i;
2324+
u8 rep_type;
23222325

2323-
return esw_add_fdb_peer_miss_rules(esw, peer_esw->dev);
2326+
mlx5_esw_for_each_rep(esw, i, rep) {
2327+
rep_type = NUM_REP_TYPES;
2328+
while (rep_type--) {
2329+
ops = esw->offloads.rep_ops[rep_type];
2330+
if (atomic_read(&rep->rep_data[rep_type].state) == REP_LOADED &&
2331+
ops->event)
2332+
ops->event(esw, rep, MLX5_SWITCHDEV_EVENT_UNPAIR, NULL);
2333+
}
2334+
}
23242335
}
23252336

23262337
static void mlx5_esw_offloads_unpair(struct mlx5_eswitch *esw)
23272338
{
23282339
#if IS_ENABLED(CONFIG_MLX5_CLS_ACT)
23292340
mlx5e_tc_clean_fdb_peer_flows(esw);
23302341
#endif
2342+
mlx5_esw_offloads_rep_event_unpair(esw);
23312343
esw_del_fdb_peer_miss_rules(esw);
23322344
}
23332345

2346+
static int mlx5_esw_offloads_pair(struct mlx5_eswitch *esw,
2347+
struct mlx5_eswitch *peer_esw)
2348+
{
2349+
const struct mlx5_eswitch_rep_ops *ops;
2350+
struct mlx5_eswitch_rep *rep;
2351+
unsigned long i;
2352+
u8 rep_type;
2353+
int err;
2354+
2355+
err = esw_add_fdb_peer_miss_rules(esw, peer_esw->dev);
2356+
if (err)
2357+
return err;
2358+
2359+
mlx5_esw_for_each_rep(esw, i, rep) {
2360+
for (rep_type = 0; rep_type < NUM_REP_TYPES; rep_type++) {
2361+
ops = esw->offloads.rep_ops[rep_type];
2362+
if (atomic_read(&rep->rep_data[rep_type].state) == REP_LOADED &&
2363+
ops->event) {
2364+
err = ops->event(esw, rep, MLX5_SWITCHDEV_EVENT_PAIR, peer_esw);
2365+
if (err)
2366+
goto err_out;
2367+
}
2368+
}
2369+
}
2370+
2371+
return 0;
2372+
2373+
err_out:
2374+
mlx5_esw_offloads_unpair(esw);
2375+
return err;
2376+
}
2377+
23342378
static int mlx5_esw_offloads_set_ns_peer(struct mlx5_eswitch *esw,
23352379
struct mlx5_eswitch *peer_esw,
23362380
bool pair)

include/linux/mlx5/eswitch.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,20 @@ enum {
2929
REP_LOADED,
3030
};
3131

32+
enum mlx5_switchdev_event {
33+
MLX5_SWITCHDEV_EVENT_PAIR,
34+
MLX5_SWITCHDEV_EVENT_UNPAIR,
35+
};
36+
3237
struct mlx5_eswitch_rep;
3338
struct mlx5_eswitch_rep_ops {
3439
int (*load)(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep);
3540
void (*unload)(struct mlx5_eswitch_rep *rep);
3641
void *(*get_proto_dev)(struct mlx5_eswitch_rep *rep);
42+
int (*event)(struct mlx5_eswitch *esw,
43+
struct mlx5_eswitch_rep *rep,
44+
enum mlx5_switchdev_event event,
45+
void *data);
3746
};
3847

3948
struct mlx5_eswitch_rep_data {

0 commit comments

Comments
 (0)