@@ -254,8 +254,6 @@ static void rx_destroy(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
254254 mlx5_del_flow_rules (rx -> sa .rule );
255255 mlx5_destroy_flow_group (rx -> sa .group );
256256 mlx5_destroy_flow_table (rx -> ft .sa );
257- if (rx -> allow_tunnel_mode )
258- mlx5_eswitch_unblock_encap (mdev );
259257 if (rx == ipsec -> rx_esw ) {
260258 mlx5_esw_ipsec_rx_status_destroy (ipsec , rx );
261259 } else {
@@ -359,8 +357,6 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
359357 goto err_add ;
360358
361359 /* Create FT */
362- if (mlx5_ipsec_device_caps (mdev ) & MLX5_IPSEC_CAP_TUNNEL )
363- rx -> allow_tunnel_mode = mlx5_eswitch_block_encap (mdev );
364360 if (rx -> allow_tunnel_mode )
365361 flags = MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT ;
366362 ft = ipsec_ft_create (attr .ns , attr .sa_level , attr .prio , 2 , flags );
@@ -415,8 +411,6 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
415411err_fs :
416412 mlx5_destroy_flow_table (rx -> ft .sa );
417413err_fs_ft :
418- if (rx -> allow_tunnel_mode )
419- mlx5_eswitch_unblock_encap (mdev );
420414 mlx5_del_flow_rules (rx -> status .rule );
421415 mlx5_modify_header_dealloc (mdev , rx -> status .modify_hdr );
422416err_add :
@@ -434,13 +428,26 @@ static int rx_get(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
434428 if (rx -> ft .refcnt )
435429 goto skip ;
436430
431+ if (mlx5_ipsec_device_caps (mdev ) & MLX5_IPSEC_CAP_TUNNEL )
432+ rx -> allow_tunnel_mode = mlx5_eswitch_block_encap (mdev );
433+
434+ err = mlx5_eswitch_block_mode_trylock (mdev );
435+ if (err )
436+ goto err_out ;
437+
437438 err = rx_create (mdev , ipsec , rx , family );
439+ mlx5_eswitch_block_mode_unlock (mdev , err );
438440 if (err )
439- return err ;
441+ goto err_out ;
440442
441443skip :
442444 rx -> ft .refcnt ++ ;
443445 return 0 ;
446+
447+ err_out :
448+ if (rx -> allow_tunnel_mode )
449+ mlx5_eswitch_unblock_encap (mdev );
450+ return err ;
444451}
445452
446453static void rx_put (struct mlx5e_ipsec * ipsec , struct mlx5e_ipsec_rx * rx ,
@@ -449,7 +456,12 @@ static void rx_put(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_rx *rx,
449456 if (-- rx -> ft .refcnt )
450457 return ;
451458
459+ mlx5_eswitch_unblock_mode_lock (ipsec -> mdev );
452460 rx_destroy (ipsec -> mdev , ipsec , rx , family );
461+ mlx5_eswitch_unblock_mode_unlock (ipsec -> mdev );
462+
463+ if (rx -> allow_tunnel_mode )
464+ mlx5_eswitch_unblock_encap (ipsec -> mdev );
453465}
454466
455467static struct mlx5e_ipsec_rx * rx_ft_get (struct mlx5_core_dev * mdev ,
@@ -569,8 +581,6 @@ static void tx_destroy(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_tx *tx,
569581 mlx5_destroy_flow_group (tx -> sa .group );
570582 }
571583 mlx5_destroy_flow_table (tx -> ft .sa );
572- if (tx -> allow_tunnel_mode )
573- mlx5_eswitch_unblock_encap (ipsec -> mdev );
574584 mlx5_del_flow_rules (tx -> status .rule );
575585 mlx5_destroy_flow_table (tx -> ft .status );
576586}
@@ -611,8 +621,6 @@ static int tx_create(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_tx *tx,
611621 if (err )
612622 goto err_status_rule ;
613623
614- if (mlx5_ipsec_device_caps (mdev ) & MLX5_IPSEC_CAP_TUNNEL )
615- tx -> allow_tunnel_mode = mlx5_eswitch_block_encap (mdev );
616624 if (tx -> allow_tunnel_mode )
617625 flags = MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT ;
618626 ft = ipsec_ft_create (tx -> ns , attr .sa_level , attr .prio , 4 , flags );
@@ -679,8 +687,6 @@ static int tx_create(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_tx *tx,
679687err_sa_miss :
680688 mlx5_destroy_flow_table (tx -> ft .sa );
681689err_sa_ft :
682- if (tx -> allow_tunnel_mode )
683- mlx5_eswitch_unblock_encap (mdev );
684690 mlx5_del_flow_rules (tx -> status .rule );
685691err_status_rule :
686692 mlx5_destroy_flow_table (tx -> ft .status );
@@ -714,27 +720,50 @@ static int tx_get(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
714720 if (tx -> ft .refcnt )
715721 goto skip ;
716722
717- err = tx_create (ipsec , tx , ipsec -> roce );
723+ if (mlx5_ipsec_device_caps (mdev ) & MLX5_IPSEC_CAP_TUNNEL )
724+ tx -> allow_tunnel_mode = mlx5_eswitch_block_encap (mdev );
725+
726+ err = mlx5_eswitch_block_mode_trylock (mdev );
718727 if (err )
719- return err ;
728+ goto err_out ;
729+
730+ err = tx_create (ipsec , tx , ipsec -> roce );
731+ if (err ) {
732+ mlx5_eswitch_block_mode_unlock (mdev , err );
733+ goto err_out ;
734+ }
720735
721736 if (tx == ipsec -> tx_esw )
722737 ipsec_esw_tx_ft_policy_set (mdev , tx -> ft .pol );
723738
739+ mlx5_eswitch_block_mode_unlock (mdev , err );
740+
724741skip :
725742 tx -> ft .refcnt ++ ;
726743 return 0 ;
744+
745+ err_out :
746+ if (tx -> allow_tunnel_mode )
747+ mlx5_eswitch_unblock_encap (mdev );
748+ return err ;
727749}
728750
729751static void tx_put (struct mlx5e_ipsec * ipsec , struct mlx5e_ipsec_tx * tx )
730752{
731753 if (-- tx -> ft .refcnt )
732754 return ;
733755
756+ mlx5_eswitch_unblock_mode_lock (ipsec -> mdev );
757+
734758 if (tx == ipsec -> tx_esw )
735759 ipsec_esw_tx_ft_policy_set (ipsec -> mdev , NULL );
736760
737761 tx_destroy (ipsec , tx , ipsec -> roce );
762+
763+ mlx5_eswitch_unblock_mode_unlock (ipsec -> mdev );
764+
765+ if (tx -> allow_tunnel_mode )
766+ mlx5_eswitch_unblock_encap (ipsec -> mdev );
738767}
739768
740769static struct mlx5_flow_table * tx_ft_get_policy (struct mlx5_core_dev * mdev ,
0 commit comments