@@ -310,9 +310,9 @@ static void mlx5e_macsec_destroy_object(struct mlx5_core_dev *mdev, u32 macsec_o
310
310
mlx5_cmd_exec (mdev , in , sizeof (in ), out , sizeof (out ));
311
311
}
312
312
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 )
316
316
{
317
317
int action = (is_tx ) ? MLX5_ACCEL_MACSEC_ACTION_ENCRYPT :
318
318
MLX5_ACCEL_MACSEC_ACTION_DECRYPT ;
@@ -322,20 +322,49 @@ static void mlx5e_macsec_cleanup_sa(struct mlx5e_macsec *macsec,
322
322
323
323
mlx5_macsec_fs_del_rule (macsec -> mdev -> macsec_fs , sa -> macsec_rule , action , netdev ,
324
324
fs_id );
325
- mlx5e_macsec_destroy_object (macsec -> mdev , sa -> macsec_obj_id );
326
325
sa -> macsec_rule = NULL ;
327
326
}
328
327
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
+
329
360
static int mlx5e_macsec_init_sa (struct macsec_context * ctx ,
330
361
struct mlx5e_macsec_sa * sa ,
331
362
bool encrypt , bool is_tx , u32 * fs_id )
332
363
{
333
364
struct mlx5e_priv * priv = macsec_netdev_priv (ctx -> netdev );
334
365
struct mlx5e_macsec * macsec = priv -> macsec ;
335
- struct mlx5_macsec_rule_attrs rule_attrs ;
336
366
struct mlx5_core_dev * mdev = priv -> mdev ;
337
367
struct mlx5_macsec_obj_attrs obj_attrs ;
338
- union mlx5_macsec_rule * macsec_rule ;
339
368
int err ;
340
369
341
370
obj_attrs .next_pn = sa -> next_pn ;
@@ -357,20 +386,12 @@ static int mlx5e_macsec_init_sa(struct macsec_context *ctx,
357
386
if (err )
358
387
return err ;
359
388
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 ;
370
393
}
371
394
372
- sa -> macsec_rule = macsec_rule ;
373
-
374
395
return 0 ;
375
396
376
397
destroy_macsec_object :
@@ -526,9 +547,7 @@ static int mlx5e_macsec_add_txsa(struct macsec_context *ctx)
526
547
goto destroy_sa ;
527
548
528
549
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 )
532
551
goto out ;
533
552
534
553
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)
595
614
goto out ;
596
615
597
616
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 );
599
618
if (err )
600
619
goto out ;
601
620
} else {
@@ -604,7 +623,7 @@ static int mlx5e_macsec_upd_txsa(struct macsec_context *ctx)
604
623
goto out ;
605
624
}
606
625
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 );
608
627
}
609
628
out :
610
629
mutex_unlock (& macsec -> lock );
@@ -1030,8 +1049,9 @@ static int mlx5e_macsec_del_rxsa(struct macsec_context *ctx)
1030
1049
goto out ;
1031
1050
}
1032
1051
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 );
1035
1055
mlx5_destroy_encryption_key (macsec -> mdev , rx_sa -> enc_key_id );
1036
1056
kfree (rx_sa );
1037
1057
rx_sc -> rx_sa [assoc_num ] = NULL ;
@@ -1112,8 +1132,8 @@ static int macsec_upd_secy_hw_address(struct macsec_context *ctx,
1112
1132
if (!rx_sa || !rx_sa -> macsec_rule )
1113
1133
continue ;
1114
1134
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 );
1117
1137
}
1118
1138
}
1119
1139
@@ -1124,8 +1144,8 @@ static int macsec_upd_secy_hw_address(struct macsec_context *ctx,
1124
1144
continue ;
1125
1145
1126
1146
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 );
1129
1149
if (err )
1130
1150
goto out ;
1131
1151
}
@@ -1178,7 +1198,7 @@ static int mlx5e_macsec_upd_secy(struct macsec_context *ctx)
1178
1198
if (!tx_sa )
1179
1199
continue ;
1180
1200
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 );
1182
1202
}
1183
1203
1184
1204
for (i = 0 ; i < MACSEC_NUM_AN ; ++ i ) {
@@ -1187,7 +1207,7 @@ static int mlx5e_macsec_upd_secy(struct macsec_context *ctx)
1187
1207
continue ;
1188
1208
1189
1209
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 );
1191
1211
if (err )
1192
1212
goto out ;
1193
1213
}
0 commit comments