In order to release the DR actions and reuse the context of a CT,
the reference count should be handled correctly, especially in the
flow destroying.

The CT index will be recorded in the rte_flow by reusing the age
index. The action context type should be saved for CT also. When
destroying a flow, if the context type is CT and the index valid.
The release process should be handled.

By default, the handling will fall back to release the age.

Signed-off-by: Bing Zhao <bi...@nvidia.com>
---
 drivers/net/mlx5/mlx5_flow.h    | 6 +++++-
 drivers/net/mlx5/mlx5_flow_dv.c | 7 ++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 3b896e3..4ad9910 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -977,11 +977,15 @@ struct rte_flow {
        uint32_t drv_type:2; /**< Driver type. */
        uint32_t tunnel:1;
        uint32_t meter:24; /**< Holds flow meter id. */
+       uint32_t indirect_type:2; /**< Indirect action type. */
        uint32_t rix_mreg_copy;
        /**< Index to metadata register copy table resource. */
        uint32_t counter; /**< Holds flow counter. */
        uint32_t tunnel_id;  /**< Tunnel id */
-       uint32_t age; /**< Holds ASO age bit index. */
+       union {
+               uint32_t age; /**< Holds ASO age bit index. */
+               uint32_t ct; /**< Holds ASO CT index. */
+       };
        uint32_t geneve_tlv_option; /**< Holds Geneve TLV option id. > */
 } __rte_packed;
 
diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index 6478625..3e85d5e 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -12185,6 +12185,8 @@ flow_dv_translate(struct rte_eth_dev *dev,
                        else
                                dev_flow->dv.actions[actions_n] =
                                                        ct->dr_action_rply;
+                       flow->indirect_type = MLX5_INDIRECT_ACTION_TYPE_CT;
+                       flow->ct = ct_idx;
                        __atomic_fetch_add(&ct->refcnt, 1, __ATOMIC_RELAXED);
                        actions_n++;
                        action_flags |= MLX5_FLOW_ACTION_CT;
@@ -13328,7 +13330,10 @@ flow_dv_destroy(struct rte_eth_dev *dev, struct 
rte_flow *flow)
                        mlx5_flow_meter_detach(priv, fm);
                flow->meter = 0;
        }
-       if (flow->age)
+       /* Keep the current age handling by default. */
+       if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
+               flow_dv_aso_ct_release(dev, flow->ct);
+       else if (flow->age)
                flow_dv_aso_age_release(dev, flow->age);
        if (flow->geneve_tlv_option) {
                flow_dv_geneve_tlv_option_resource_release(dev);
-- 
2.5.5

Reply via email to