12
12
#include <net/flow_offload.h>
13
13
#include <net/netfilter/nf_flow_table.h>
14
14
#include <linux/workqueue.h>
15
+ #include <linux/xarray.h>
15
16
16
17
#include "esw/chains.h"
17
18
#include "en/tc_ct.h"
@@ -35,7 +36,7 @@ struct mlx5_tc_ct_priv {
35
36
struct mlx5_eswitch * esw ;
36
37
const struct net_device * netdev ;
37
38
struct idr fte_ids ;
38
- struct idr tuple_ids ;
39
+ struct xarray tuple_ids ;
39
40
struct rhashtable zone_ht ;
40
41
struct mlx5_flow_table * ct ;
41
42
struct mlx5_flow_table * ct_nat ;
@@ -238,7 +239,7 @@ mlx5_tc_ct_entry_del_rule(struct mlx5_tc_ct_priv *ct_priv,
238
239
239
240
mlx5_eswitch_del_offloaded_rule (esw , zone_rule -> rule , attr );
240
241
mlx5_modify_header_dealloc (esw -> dev , attr -> modify_hdr );
241
- idr_remove (& ct_priv -> tuple_ids , zone_rule -> tupleid );
242
+ xa_erase (& ct_priv -> tuple_ids , zone_rule -> tupleid );
242
243
}
243
244
244
245
static void
@@ -483,7 +484,7 @@ mlx5_tc_ct_entry_add_rule(struct mlx5_tc_ct_priv *ct_priv,
483
484
struct mlx5_esw_flow_attr * attr = & zone_rule -> attr ;
484
485
struct mlx5_eswitch * esw = ct_priv -> esw ;
485
486
struct mlx5_flow_spec * spec = NULL ;
486
- u32 tupleid = 1 ;
487
+ u32 tupleid ;
487
488
int err ;
488
489
489
490
zone_rule -> nat = nat ;
@@ -493,12 +494,12 @@ mlx5_tc_ct_entry_add_rule(struct mlx5_tc_ct_priv *ct_priv,
493
494
return - ENOMEM ;
494
495
495
496
/* Get tuple unique id */
496
- err = idr_alloc_u32 (& ct_priv -> tuple_ids , zone_rule , & tupleid ,
497
- TUPLE_ID_MAX , GFP_KERNEL );
497
+ err = xa_alloc (& ct_priv -> tuple_ids , & tupleid , zone_rule ,
498
+ XA_LIMIT ( 1 , TUPLE_ID_MAX ) , GFP_KERNEL );
498
499
if (err ) {
499
500
netdev_warn (ct_priv -> netdev ,
500
501
"Failed to allocate tuple id, err: %d\n" , err );
501
- goto err_idr_alloc ;
502
+ goto err_xa_alloc ;
502
503
}
503
504
zone_rule -> tupleid = tupleid ;
504
505
@@ -539,8 +540,8 @@ mlx5_tc_ct_entry_add_rule(struct mlx5_tc_ct_priv *ct_priv,
539
540
err_rule :
540
541
mlx5_modify_header_dealloc (esw -> dev , attr -> modify_hdr );
541
542
err_mod_hdr :
542
- idr_remove (& ct_priv -> tuple_ids , zone_rule -> tupleid );
543
- err_idr_alloc :
543
+ xa_erase (& ct_priv -> tuple_ids , zone_rule -> tupleid );
544
+ err_xa_alloc :
544
545
kfree (spec );
545
546
return err ;
546
547
}
@@ -1299,7 +1300,7 @@ mlx5_tc_ct_init(struct mlx5_rep_uplink_priv *uplink_priv)
1299
1300
}
1300
1301
1301
1302
idr_init (& ct_priv -> fte_ids );
1302
- idr_init (& ct_priv -> tuple_ids );
1303
+ xa_init_flags (& ct_priv -> tuple_ids , XA_FLAGS_ALLOC1 );
1303
1304
mutex_init (& ct_priv -> control_lock );
1304
1305
rhashtable_init (& ct_priv -> zone_ht , & zone_params );
1305
1306
@@ -1334,7 +1335,7 @@ mlx5_tc_ct_clean(struct mlx5_rep_uplink_priv *uplink_priv)
1334
1335
1335
1336
rhashtable_destroy (& ct_priv -> zone_ht );
1336
1337
mutex_destroy (& ct_priv -> control_lock );
1337
- idr_destroy (& ct_priv -> tuple_ids );
1338
+ xa_destroy (& ct_priv -> tuple_ids );
1338
1339
idr_destroy (& ct_priv -> fte_ids );
1339
1340
kfree (ct_priv );
1340
1341
@@ -1352,7 +1353,7 @@ mlx5e_tc_ct_restore_flow(struct mlx5_rep_uplink_priv *uplink_priv,
1352
1353
if (!ct_priv || !tupleid )
1353
1354
return true;
1354
1355
1355
- zone_rule = idr_find (& ct_priv -> tuple_ids , tupleid );
1356
+ zone_rule = xa_load (& ct_priv -> tuple_ids , tupleid );
1356
1357
if (!zone_rule )
1357
1358
return false;
1358
1359
0 commit comments