Skip to content

Commit acc1092

Browse files
rleonkuba-moo
authored andcommitted
net/mlx5: Allow blocking encap changes in eswitch
Existing eswitch encap option enables header encapsulation. Unfortunately currently available hardware isn't able to perform double encapsulation, which can happen once IPsec packet offload tunnel mode is used together with encap mode set to BASIC. So as a solution for misconfiguration, provide an option to block encap changes, which will be used for IPsec packet offload. Reviewed-by: Emeel Hakim <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Sridhar Samudrala <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 4c24272 commit acc1092

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ struct mlx5_esw_offload {
263263
const struct mlx5_eswitch_rep_ops *rep_ops[NUM_REP_TYPES];
264264
u8 inline_mode;
265265
atomic64_t num_flows;
266+
u64 num_block_encap;
266267
enum devlink_eswitch_encap_mode encap;
267268
struct ida vport_metadata_ida;
268269
unsigned int host_number; /* ECPF supports one external host */
@@ -748,6 +749,9 @@ void mlx5_eswitch_offloads_destroy_single_fdb(struct mlx5_eswitch *master_esw,
748749
struct mlx5_eswitch *slave_esw);
749750
int mlx5_eswitch_reload_reps(struct mlx5_eswitch *esw);
750751

752+
bool mlx5_eswitch_block_encap(struct mlx5_core_dev *dev);
753+
void mlx5_eswitch_unblock_encap(struct mlx5_core_dev *dev);
754+
751755
static inline int mlx5_eswitch_num_vfs(struct mlx5_eswitch *esw)
752756
{
753757
if (mlx5_esw_allowed(esw))
@@ -761,6 +765,7 @@ mlx5_eswitch_get_slow_fdb(struct mlx5_eswitch *esw)
761765
{
762766
return esw->fdb_table.offloads.slow_fdb;
763767
}
768+
764769
#else /* CONFIG_MLX5_ESWITCH */
765770
/* eswitch API stubs */
766771
static inline int mlx5_eswitch_init(struct mlx5_core_dev *dev) { return 0; }
@@ -805,6 +810,15 @@ mlx5_eswitch_reload_reps(struct mlx5_eswitch *esw)
805810
{
806811
return 0;
807812
}
813+
814+
static inline bool mlx5_eswitch_block_encap(struct mlx5_core_dev *dev)
815+
{
816+
return true;
817+
}
818+
819+
static inline void mlx5_eswitch_unblock_encap(struct mlx5_core_dev *dev)
820+
{
821+
}
808822
#endif /* CONFIG_MLX5_ESWITCH */
809823

810824
#endif /* __MLX5_ESWITCH_H__ */

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3586,6 +3586,47 @@ int mlx5_devlink_eswitch_inline_mode_get(struct devlink *devlink, u8 *mode)
35863586
return err;
35873587
}
35883588

3589+
bool mlx5_eswitch_block_encap(struct mlx5_core_dev *dev)
3590+
{
3591+
struct devlink *devlink = priv_to_devlink(dev);
3592+
struct mlx5_eswitch *esw;
3593+
3594+
devl_lock(devlink);
3595+
esw = mlx5_devlink_eswitch_get(devlink);
3596+
if (IS_ERR(esw)) {
3597+
devl_unlock(devlink);
3598+
/* Failure means no eswitch => not possible to change encap */
3599+
return true;
3600+
}
3601+
3602+
down_write(&esw->mode_lock);
3603+
if (esw->mode != MLX5_ESWITCH_LEGACY &&
3604+
esw->offloads.encap != DEVLINK_ESWITCH_ENCAP_MODE_NONE) {
3605+
up_write(&esw->mode_lock);
3606+
devl_unlock(devlink);
3607+
return false;
3608+
}
3609+
3610+
esw->offloads.num_block_encap++;
3611+
up_write(&esw->mode_lock);
3612+
devl_unlock(devlink);
3613+
return true;
3614+
}
3615+
3616+
void mlx5_eswitch_unblock_encap(struct mlx5_core_dev *dev)
3617+
{
3618+
struct devlink *devlink = priv_to_devlink(dev);
3619+
struct mlx5_eswitch *esw;
3620+
3621+
esw = mlx5_devlink_eswitch_get(devlink);
3622+
if (IS_ERR(esw))
3623+
return;
3624+
3625+
down_write(&esw->mode_lock);
3626+
esw->offloads.num_block_encap--;
3627+
up_write(&esw->mode_lock);
3628+
}
3629+
35893630
int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink,
35903631
enum devlink_eswitch_encap_mode encap,
35913632
struct netlink_ext_ack *extack)
@@ -3627,6 +3668,13 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink,
36273668
goto unlock;
36283669
}
36293670

3671+
if (esw->offloads.num_block_encap) {
3672+
NL_SET_ERR_MSG_MOD(extack,
3673+
"Can't set encapsulation when IPsec SA and/or policies are configured");
3674+
err = -EOPNOTSUPP;
3675+
goto unlock;
3676+
}
3677+
36303678
esw_destroy_offloads_fdb_tables(esw);
36313679

36323680
esw->offloads.encap = encap;

0 commit comments

Comments
 (0)