Skip to content

Commit d0c19a3

Browse files
raed-salemrleon
authored andcommitted
net/mlx5e: Use one rule to count all IPsec Tx offloaded traffic
Currently one counter is shared between all IPsec Tx offloaded rules to count the total amount of packets/bytes that was IPsec Tx offloaded, replace this scheme by adding a new flow table (ft) with one rule that counts all flows that passes through this table (like Rx status ft), this ft is pointed by all IPsec Tx offloaded rules. The above allows to have a counter per tx flow rule in while keeping a separate global counter that store the aggregation outcome of all these per flow counters. Signed-off-by: Raed Salem <raeds@nvidia.com> Link: https://lore.kernel.org/r/09b9119d1deb6e482fd2d17e1f5760d7c5be1e48.1678714336.git.leon@kernel.org Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent aa8bd0c commit d0c19a3

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct mlx5e_ipsec_rx {
4141
struct mlx5e_ipsec_tx {
4242
struct mlx5e_ipsec_ft ft;
4343
struct mlx5e_ipsec_miss pol;
44+
struct mlx5e_ipsec_rule status;
4445
struct mlx5_flow_namespace *ns;
4546
struct mlx5e_ipsec_fc *fc;
4647
struct mlx5_fs_chains *chains;
@@ -455,6 +456,39 @@ static void rx_ft_put_policy(struct mlx5e_ipsec *ipsec, u32 family, u32 prio)
455456
mutex_unlock(&rx->ft.mutex);
456457
}
457458

459+
static int ipsec_counter_rule_tx(struct mlx5_core_dev *mdev, struct mlx5e_ipsec_tx *tx)
460+
{
461+
struct mlx5_flow_destination dest = {};
462+
struct mlx5_flow_act flow_act = {};
463+
struct mlx5_flow_handle *fte;
464+
struct mlx5_flow_spec *spec;
465+
int err;
466+
467+
spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
468+
if (!spec)
469+
return -ENOMEM;
470+
471+
/* create fte */
472+
flow_act.action = MLX5_FLOW_CONTEXT_ACTION_ALLOW |
473+
MLX5_FLOW_CONTEXT_ACTION_COUNT;
474+
dest.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
475+
dest.counter_id = mlx5_fc_id(tx->fc->cnt);
476+
fte = mlx5_add_flow_rules(tx->ft.status, spec, &flow_act, &dest, 1);
477+
if (IS_ERR(fte)) {
478+
err = PTR_ERR(fte);
479+
mlx5_core_err(mdev, "Fail to add ipsec tx counter rule err=%d\n", err);
480+
goto err_rule;
481+
}
482+
483+
kvfree(spec);
484+
tx->status.rule = fte;
485+
return 0;
486+
487+
err_rule:
488+
kvfree(spec);
489+
return err;
490+
}
491+
458492
/* IPsec TX flow steering */
459493
static void tx_destroy(struct mlx5e_ipsec_tx *tx, struct mlx5_ipsec_fs *roce)
460494
{
@@ -468,6 +502,8 @@ static void tx_destroy(struct mlx5e_ipsec_tx *tx, struct mlx5_ipsec_fs *roce)
468502
}
469503

470504
mlx5_destroy_flow_table(tx->ft.sa);
505+
mlx5_del_flow_rules(tx->status.rule);
506+
mlx5_destroy_flow_table(tx->ft.status);
471507
}
472508

473509
static int tx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec_tx *tx,
@@ -477,10 +513,20 @@ static int tx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec_tx *tx,
477513
struct mlx5_flow_table *ft;
478514
int err;
479515

480-
ft = ipsec_ft_create(tx->ns, 1, 0, 4);
516+
ft = ipsec_ft_create(tx->ns, 2, 0, 1);
481517
if (IS_ERR(ft))
482518
return PTR_ERR(ft);
519+
tx->ft.status = ft;
483520

521+
err = ipsec_counter_rule_tx(mdev, tx);
522+
if (err)
523+
goto err_status_rule;
524+
525+
ft = ipsec_ft_create(tx->ns, 1, 0, 4);
526+
if (IS_ERR(ft)) {
527+
err = PTR_ERR(ft);
528+
goto err_sa_ft;
529+
}
484530
tx->ft.sa = ft;
485531

486532
if (mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_PRIO) {
@@ -525,6 +571,10 @@ static int tx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec_tx *tx,
525571
}
526572
err_pol_ft:
527573
mlx5_destroy_flow_table(tx->ft.sa);
574+
err_sa_ft:
575+
mlx5_del_flow_rules(tx->status.rule);
576+
err_status_rule:
577+
mlx5_destroy_flow_table(tx->ft.status);
528578
return err;
529579
}
530580

@@ -949,11 +999,11 @@ static int tx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
949999
flow_act.crypto.type = MLX5_FLOW_CONTEXT_ENCRYPT_DECRYPT_TYPE_IPSEC;
9501000
flow_act.crypto.obj_id = sa_entry->ipsec_obj_id;
9511001
flow_act.flags |= FLOW_ACT_NO_APPEND;
952-
flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_ALLOW |
1002+
flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
9531003
MLX5_FLOW_CONTEXT_ACTION_CRYPTO_ENCRYPT |
9541004
MLX5_FLOW_CONTEXT_ACTION_COUNT;
955-
dest.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
956-
dest.counter_id = mlx5_fc_id(tx->fc->cnt);
1005+
dest.ft = tx->ft.status;
1006+
dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
9571007
rule = mlx5_add_flow_rules(tx->ft.sa, spec, &flow_act, &dest, 1);
9581008
if (IS_ERR(rule)) {
9591009
err = PTR_ERR(rule);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
#define LAG_MIN_LEVEL (OFFLOADS_MIN_LEVEL + KERNEL_RX_MACSEC_MIN_LEVEL + 1)
138138

139139
#define KERNEL_TX_IPSEC_NUM_PRIOS 1
140-
#define KERNEL_TX_IPSEC_NUM_LEVELS 2
140+
#define KERNEL_TX_IPSEC_NUM_LEVELS 3
141141
#define KERNEL_TX_IPSEC_MIN_LEVEL (KERNEL_TX_IPSEC_NUM_LEVELS)
142142

143143
#define KERNEL_TX_MACSEC_NUM_PRIOS 1

0 commit comments

Comments
 (0)