@@ -310,9 +310,9 @@ static void mlx5e_macsec_destroy_object(struct mlx5_core_dev *mdev, u32 macsec_o
310310	mlx5_cmd_exec (mdev , in , sizeof (in ), out , sizeof (out ));
311311}
312312
313- static  void  mlx5e_macsec_cleanup_sa (struct  mlx5e_macsec  * macsec ,
314- 				    struct  mlx5e_macsec_sa  * sa ,
315- 				    bool   is_tx ,  struct  net_device  * netdev , u32  fs_id )
313+ static  void  mlx5e_macsec_cleanup_sa_fs (struct  mlx5e_macsec  * macsec ,
314+ 				        struct  mlx5e_macsec_sa  * sa ,  bool   is_tx ,
315+ 				        struct  net_device  * netdev , u32  fs_id )
316316{
317317	int  action  =   (is_tx ) ?  MLX5_ACCEL_MACSEC_ACTION_ENCRYPT  :
318318				 MLX5_ACCEL_MACSEC_ACTION_DECRYPT ;
@@ -322,20 +322,49 @@ static void mlx5e_macsec_cleanup_sa(struct mlx5e_macsec *macsec,
322322
323323	mlx5_macsec_fs_del_rule (macsec -> mdev -> macsec_fs , sa -> macsec_rule , action , netdev ,
324324				fs_id );
325- 	mlx5e_macsec_destroy_object (macsec -> mdev , sa -> macsec_obj_id );
326325	sa -> macsec_rule  =  NULL ;
327326}
328327
328+ static  void  mlx5e_macsec_cleanup_sa (struct  mlx5e_macsec  * macsec ,
329+ 				    struct  mlx5e_macsec_sa  * sa , bool  is_tx ,
330+ 				    struct  net_device  * netdev , u32  fs_id )
331+ {
332+ 	mlx5e_macsec_cleanup_sa_fs (macsec , sa , is_tx , netdev , fs_id );
333+ 	mlx5e_macsec_destroy_object (macsec -> mdev , sa -> macsec_obj_id );
334+ }
335+ 
336+ static  int  mlx5e_macsec_init_sa_fs (struct  macsec_context  * ctx ,
337+ 				   struct  mlx5e_macsec_sa  * sa , bool  encrypt ,
338+ 				   bool  is_tx , u32  * fs_id )
339+ {
340+ 	struct  mlx5e_priv  * priv  =  macsec_netdev_priv (ctx -> netdev );
341+ 	struct  mlx5_macsec_fs  * macsec_fs  =  priv -> mdev -> macsec_fs ;
342+ 	struct  mlx5_macsec_rule_attrs  rule_attrs ;
343+ 	union  mlx5_macsec_rule  * macsec_rule ;
344+ 
345+ 	rule_attrs .macsec_obj_id  =  sa -> macsec_obj_id ;
346+ 	rule_attrs .sci  =  sa -> sci ;
347+ 	rule_attrs .assoc_num  =  sa -> assoc_num ;
348+ 	rule_attrs .action  =  (is_tx ) ? MLX5_ACCEL_MACSEC_ACTION_ENCRYPT  :
349+ 				      MLX5_ACCEL_MACSEC_ACTION_DECRYPT ;
350+ 
351+ 	macsec_rule  =  mlx5_macsec_fs_add_rule (macsec_fs , ctx , & rule_attrs , fs_id );
352+ 	if  (!macsec_rule )
353+ 		return  - ENOMEM ;
354+ 
355+ 	sa -> macsec_rule  =  macsec_rule ;
356+ 
357+ 	return  0 ;
358+ }
359+ 
329360static  int  mlx5e_macsec_init_sa (struct  macsec_context  * ctx ,
330361				struct  mlx5e_macsec_sa  * sa ,
331362				bool  encrypt , bool  is_tx , u32  * fs_id )
332363{
333364	struct  mlx5e_priv  * priv  =  macsec_netdev_priv (ctx -> netdev );
334365	struct  mlx5e_macsec  * macsec  =  priv -> macsec ;
335- 	struct  mlx5_macsec_rule_attrs  rule_attrs ;
336366	struct  mlx5_core_dev  * mdev  =  priv -> mdev ;
337367	struct  mlx5_macsec_obj_attrs  obj_attrs ;
338- 	union  mlx5_macsec_rule  * macsec_rule ;
339368	int  err ;
340369
341370	obj_attrs .next_pn  =  sa -> next_pn ;
@@ -357,20 +386,12 @@ static int mlx5e_macsec_init_sa(struct macsec_context *ctx,
357386	if  (err )
358387		return  err ;
359388
360- 	rule_attrs .macsec_obj_id  =  sa -> macsec_obj_id ;
361- 	rule_attrs .sci  =  sa -> sci ;
362- 	rule_attrs .assoc_num  =  sa -> assoc_num ;
363- 	rule_attrs .action  =  (is_tx ) ? MLX5_ACCEL_MACSEC_ACTION_ENCRYPT  :
364- 				      MLX5_ACCEL_MACSEC_ACTION_DECRYPT ;
365- 
366- 	macsec_rule  =  mlx5_macsec_fs_add_rule (mdev -> macsec_fs , ctx , & rule_attrs , fs_id );
367- 	if  (!macsec_rule ) {
368- 		err  =  - ENOMEM ;
369- 		goto destroy_macsec_object ;
389+ 	if  (sa -> active ) {
390+ 		err  =  mlx5e_macsec_init_sa_fs (ctx , sa , encrypt , is_tx , fs_id );
391+ 		if  (err )
392+ 			goto destroy_macsec_object ;
370393	}
371394
372- 	sa -> macsec_rule  =  macsec_rule ;
373- 
374395	return  0 ;
375396
376397destroy_macsec_object :
@@ -526,9 +547,7 @@ static int mlx5e_macsec_add_txsa(struct macsec_context *ctx)
526547		goto destroy_sa ;
527548
528549	macsec_device -> tx_sa [assoc_num ] =  tx_sa ;
529- 	if  (!secy -> operational  || 
530- 	    assoc_num  !=  tx_sc -> encoding_sa  || 
531- 	    !tx_sa -> active )
550+ 	if  (!secy -> operational )
532551		goto out ;
533552
534553	err  =  mlx5e_macsec_init_sa (ctx , tx_sa , tx_sc -> encrypt , true, NULL );
@@ -595,7 +614,7 @@ static int mlx5e_macsec_upd_txsa(struct macsec_context *ctx)
595614		goto out ;
596615
597616	if  (ctx_tx_sa -> active ) {
598- 		err  =  mlx5e_macsec_init_sa (ctx , tx_sa , tx_sc -> encrypt , true, NULL );
617+ 		err  =  mlx5e_macsec_init_sa_fs (ctx , tx_sa , tx_sc -> encrypt , true, NULL );
599618		if  (err )
600619			goto out ;
601620	} else  {
@@ -604,7 +623,7 @@ static int mlx5e_macsec_upd_txsa(struct macsec_context *ctx)
604623			goto out ;
605624		}
606625
607- 		mlx5e_macsec_cleanup_sa (macsec , tx_sa , true, ctx -> secy -> netdev , 0 );
626+ 		mlx5e_macsec_cleanup_sa_fs (macsec , tx_sa , true, ctx -> secy -> netdev , 0 );
608627	}
609628out :
610629	mutex_unlock (& macsec -> lock );
@@ -1030,8 +1049,9 @@ static int mlx5e_macsec_del_rxsa(struct macsec_context *ctx)
10301049		goto out ;
10311050	}
10321051
1033- 	mlx5e_macsec_cleanup_sa (macsec , rx_sa , false, ctx -> secy -> netdev ,
1034- 				rx_sc -> sc_xarray_element -> fs_id );
1052+ 	if  (rx_sa -> active )
1053+ 		mlx5e_macsec_cleanup_sa (macsec , rx_sa , false, ctx -> secy -> netdev ,
1054+ 					rx_sc -> sc_xarray_element -> fs_id );
10351055	mlx5_destroy_encryption_key (macsec -> mdev , rx_sa -> enc_key_id );
10361056	kfree (rx_sa );
10371057	rx_sc -> rx_sa [assoc_num ] =  NULL ;
@@ -1112,8 +1132,8 @@ static int macsec_upd_secy_hw_address(struct macsec_context *ctx,
11121132			if  (!rx_sa  ||  !rx_sa -> macsec_rule )
11131133				continue ;
11141134
1115- 			mlx5e_macsec_cleanup_sa (macsec , rx_sa , false, ctx -> secy -> netdev ,
1116- 						rx_sc -> sc_xarray_element -> fs_id );
1135+ 			mlx5e_macsec_cleanup_sa_fs (macsec , rx_sa , false, ctx -> secy -> netdev ,
1136+ 						    rx_sc -> sc_xarray_element -> fs_id );
11171137		}
11181138	}
11191139
@@ -1124,8 +1144,8 @@ static int macsec_upd_secy_hw_address(struct macsec_context *ctx,
11241144				continue ;
11251145
11261146			if  (rx_sa -> active ) {
1127- 				err  =  mlx5e_macsec_init_sa (ctx , rx_sa , true, false,
1128- 							   & rx_sc -> sc_xarray_element -> fs_id );
1147+ 				err  =  mlx5e_macsec_init_sa_fs (ctx , rx_sa , true, false,
1148+ 							       & rx_sc -> sc_xarray_element -> fs_id );
11291149				if  (err )
11301150					goto out ;
11311151			}
@@ -1178,7 +1198,7 @@ static int mlx5e_macsec_upd_secy(struct macsec_context *ctx)
11781198		if  (!tx_sa )
11791199			continue ;
11801200
1181- 		mlx5e_macsec_cleanup_sa (macsec , tx_sa , true, ctx -> secy -> netdev , 0 );
1201+ 		mlx5e_macsec_cleanup_sa_fs (macsec , tx_sa , true, ctx -> secy -> netdev , 0 );
11821202	}
11831203
11841204	for  (i  =  0 ; i  <  MACSEC_NUM_AN ; ++ i ) {
@@ -1187,7 +1207,7 @@ static int mlx5e_macsec_upd_secy(struct macsec_context *ctx)
11871207			continue ;
11881208
11891209		if  (tx_sa -> assoc_num  ==  tx_sc -> encoding_sa  &&  tx_sa -> active ) {
1190- 			err  =  mlx5e_macsec_init_sa (ctx , tx_sa , tx_sc -> encrypt , true, NULL );
1210+ 			err  =  mlx5e_macsec_init_sa_fs (ctx , tx_sa , tx_sc -> encrypt , true, NULL );
11911211			if  (err )
11921212				goto out ;
11931213		}
0 commit comments