The send to kernel action was supported in NIC and FDB tables,
Currently, the send to kernel action is created in NIC RX only.

With some TC rules (example: roce packets, redirects into rep ports)
and DPDK RTE rules for the rest of the traffic. Then it needs the
specific rule to re-route the packets into the kernel through the FDB
table.

This patch adds the FDB and NIC-TX tables support for sending to the kernel
action.

Signed-off-by: Jiawei Wang <jiaw...@nvidia.com>
---
 drivers/net/mlx5/linux/mlx5_os.c | 25 +++++++++++++++----------
 drivers/net/mlx5/mlx5.h          |  4 +++-
 drivers/net/mlx5/mlx5_flow.h     |  1 +
 drivers/net/mlx5/mlx5_flow_dv.c  | 17 +++++++++++------
 4 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c
index d8f1adfe3d..38572eb652 100644
--- a/drivers/net/mlx5/linux/mlx5_os.c
+++ b/drivers/net/mlx5/linux/mlx5_os.c
@@ -675,6 +675,9 @@ void
 mlx5_os_free_shared_dr(struct mlx5_priv *priv)
 {
        struct mlx5_dev_ctx_shared *sh = priv->sh;
+#ifdef HAVE_MLX5DV_DR
+       int i;
+#endif
 
        MLX5_ASSERT(sh && sh->refcnt);
        if (sh->refcnt > 1)
@@ -703,18 +706,20 @@ mlx5_os_free_shared_dr(struct mlx5_priv *priv)
                mlx5_glue->destroy_flow_action(sh->pop_vlan_action);
                sh->pop_vlan_action = NULL;
        }
-       if (sh->send_to_kernel_action.action) {
-               void *action = sh->send_to_kernel_action.action;
+       for (i = 0; i < MLX5DR_TABLE_TYPE_MAX; i++) {
+               if (sh->send_to_kernel_action[i].action) {
+                       void *action = sh->send_to_kernel_action[i].action;
 
-               mlx5_glue->destroy_flow_action(action);
-               sh->send_to_kernel_action.action = NULL;
-       }
-       if (sh->send_to_kernel_action.tbl) {
-               struct mlx5_flow_tbl_resource *tbl =
-                               sh->send_to_kernel_action.tbl;
+                       mlx5_glue->destroy_flow_action(action);
+                       sh->send_to_kernel_action[i].action = NULL;
+               }
+               if (sh->send_to_kernel_action[i].tbl) {
+                       struct mlx5_flow_tbl_resource *tbl =
+                                       sh->send_to_kernel_action[i].tbl;
 
-               flow_dv_tbl_resource_release(sh, tbl);
-               sh->send_to_kernel_action.tbl = NULL;
+                       flow_dv_tbl_resource_release(sh, tbl);
+                       sh->send_to_kernel_action[i].tbl = NULL;
+               }
        }
 #endif /* HAVE_MLX5DV_DR */
        if (sh->default_miss_action)
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 3785103308..6960a07d40 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -1432,7 +1432,9 @@ struct mlx5_dev_ctx_shared {
        /* Direct Rules tables for FDB, NIC TX+RX */
        void *dr_drop_action; /* Pointer to DR drop action, any domain. */
        void *pop_vlan_action; /* Pointer to DR pop VLAN action. */
-       struct mlx5_send_to_kernel_action send_to_kernel_action;
+#if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
+       struct mlx5_send_to_kernel_action 
send_to_kernel_action[MLX5DR_TABLE_TYPE_MAX];
+#endif
        struct mlx5_hlist *encaps_decaps; /* Encap/decap action hash list. */
        struct mlx5_hlist *modify_cmds;
        struct mlx5_hlist *tag_table;
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 3a97975d69..6beac3902c 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -331,6 +331,7 @@ enum mlx5_feature_name {
 
 #define MLX5_FLOW_FATE_ESWITCH_ACTIONS \
        (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_PORT_ID | \
+        MLX5_FLOW_ACTION_SEND_TO_KERNEL | \
         MLX5_FLOW_ACTION_JUMP | MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
 
 #define MLX5_FLOW_MODIFY_HDR_ACTIONS (MLX5_FLOW_ACTION_SET_IPV4_SRC | \
diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index a8dd9920e6..fe0814a2eb 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -12724,17 +12724,22 @@ flow_dv_translate_action_sample(struct rte_eth_dev 
*dev,
 
 static void *
 flow_dv_translate_action_send_to_kernel(struct rte_eth_dev *dev,
+                                       const struct rte_flow_attr *attr,
                                        struct rte_flow_error *error)
 {
        struct mlx5_flow_tbl_resource *tbl;
        struct mlx5_dev_ctx_shared *sh;
        uint32_t priority;
        void *action;
+       int ft_type;
        int ret;
 
        sh = MLX5_SH(dev);
-       if (sh->send_to_kernel_action.action)
-               return sh->send_to_kernel_action.action;
+       ft_type = (attr->ingress) ? MLX5DR_TABLE_TYPE_NIC_RX :
+                 ((attr->transfer) ? MLX5DR_TABLE_TYPE_FDB :
+                 MLX5DR_TABLE_TYPE_NIC_TX);
+       if (sh->send_to_kernel_action[ft_type].action)
+               return sh->send_to_kernel_action[ft_type].action;
        priority = mlx5_get_send_to_kernel_priority(dev);
        if (priority == (uint32_t)-1) {
                rte_flow_error_set(error, ENOTSUP,
@@ -12742,7 +12747,7 @@ flow_dv_translate_action_send_to_kernel(struct 
rte_eth_dev *dev,
                                   "required priority is not available");
                return NULL;
        }
-       tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL, 0, 0, 0,
+       tbl = flow_dv_tbl_resource_get(dev, 0, attr->egress, attr->transfer, 
false, NULL, 0, 0, 0,
                                       error);
        if (!tbl) {
                rte_flow_error_set(error, ENODATA,
@@ -12759,8 +12764,8 @@ flow_dv_translate_action_send_to_kernel(struct 
rte_eth_dev *dev,
                goto err;
        }
        MLX5_ASSERT(action);
-       sh->send_to_kernel_action.action = action;
-       sh->send_to_kernel_action.tbl = tbl;
+       sh->send_to_kernel_action[ft_type].action = action;
+       sh->send_to_kernel_action[ft_type].tbl = tbl;
        return action;
 err:
        flow_dv_tbl_resource_release(sh, tbl);
@@ -14511,7 +14516,7 @@ flow_dv_translate(struct rte_eth_dev *dev,
                        break;
                case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
                        dev_flow->dv.actions[actions_n] =
-                               flow_dv_translate_action_send_to_kernel(dev,
+                               flow_dv_translate_action_send_to_kernel(dev, 
attr,
                                                        error);
                        if (!dev_flow->dv.actions[actions_n])
                                return -rte_errno;
-- 
2.18.1

Reply via email to