Add the corresponding data structure and logics, to support
the offload of set TTL action.

Signed-off-by: Chaoyong He <chaoyong...@corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderl...@corigine.com>
---
 doc/guides/nics/features/nfp.ini         |  1 +
 doc/guides/rel_notes/release_22_11.rst   |  1 +
 drivers/net/nfp/flower/nfp_flower_cmsg.h | 44 +++++++++++++++++
 drivers/net/nfp/nfp_flow.c               | 84 ++++++++++++++++++++++++++++++++
 4 files changed, 130 insertions(+)

diff --git a/doc/guides/nics/features/nfp.ini b/doc/guides/nics/features/nfp.ini
index c7b560b..2706fd2 100644
--- a/doc/guides/nics/features/nfp.ini
+++ b/doc/guides/nics/features/nfp.ini
@@ -54,3 +54,4 @@ set_mac_dst          = Y
 set_mac_src          = Y
 set_tp_dst           = Y
 set_tp_src           = Y
+set_ttl              = Y
diff --git a/doc/guides/rel_notes/release_22_11.rst 
b/doc/guides/rel_notes/release_22_11.rst
index 12959db..2c8e38d 100644
--- a/doc/guides/rel_notes/release_22_11.rst
+++ b/doc/guides/rel_notes/release_22_11.rst
@@ -182,6 +182,7 @@ New Features
     * POP and PUSH VLAN
     * Set the IP address of IPv4 and IPv6
     * Set the port number
+    * Set the TTL
 
 * **Updated NXP dpaa2 driver.**
 
diff --git a/drivers/net/nfp/flower/nfp_flower_cmsg.h 
b/drivers/net/nfp/flower/nfp_flower_cmsg.h
index 26de8b1..6bf8ff7 100644
--- a/drivers/net/nfp/flower/nfp_flower_cmsg.h
+++ b/drivers/net/nfp/flower/nfp_flower_cmsg.h
@@ -400,6 +400,25 @@ struct nfp_fl_act_set_ip4_addrs {
 };
 
 /*
+ * IPv4 ttl tos
+ *    3                   2                   1
+ *  1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |   -   |opcode |       |jump_id|    ttl_mask   |   tos_mask    |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |       ttl     |      tos      |               0               |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+struct nfp_fl_act_set_ip4_ttl_tos {
+       struct nfp_fl_act_head head;
+       uint8_t ipv4_ttl_mask;
+       uint8_t ipv4_tos_mask;
+       uint8_t ipv4_ttl;
+       uint8_t ipv4_tos;
+       rte_be16_t reserved;
+};
+
+/*
  * IPv6 addr
  *    3                   2                   1
  *  1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
@@ -433,6 +452,31 @@ struct nfp_fl_act_set_ipv6_addr {
 };
 
 /*
+ * ipv6 tc hl fl
+ *    3                   2                   1
+ *  1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |   -   |opcode |       |jump_id|  tclass_mask  |  hlimit_mask  |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |               0               |  tclass       |  hlimit       |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |           0           |             flabel_mask               |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |           0           |             flabel                    |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+struct nfp_fl_act_set_ipv6_tc_hl_fl {
+       struct nfp_fl_act_head head;
+       uint8_t ipv6_tc_mask;
+       uint8_t ipv6_hop_limit_mask;
+       rte_be16_t reserved;
+       uint8_t ipv6_tc;
+       uint8_t ipv6_hop_limit;
+       rte_be32_t ipv6_label_mask;
+       rte_be32_t ipv6_label;
+};
+
+/*
  * TCP/UDP/SCTP
  *    3                   2                   1
  *  1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
diff --git a/drivers/net/nfp/nfp_flow.c b/drivers/net/nfp/nfp_flow.c
index 9262164..61315b1 100644
--- a/drivers/net/nfp/nfp_flow.c
+++ b/drivers/net/nfp/nfp_flow.c
@@ -573,9 +573,11 @@ struct nfp_mask_id_entry {
                struct nfp_fl_key_ls *key_ls)
 {
        int ret = 0;
+       bool tc_hl_flag = false;
        bool mac_set_flag = false;
        bool ip_set_flag = false;
        bool tp_set_flag = false;
+       bool ttl_tos_flag = false;
        const struct rte_flow_action *action;
 
        for (action = actions; action->type != RTE_FLOW_ACTION_TYPE_END; 
++action) {
@@ -672,6 +674,22 @@ struct nfp_mask_id_entry {
                                tp_set_flag = true;
                        }
                        break;
+               case RTE_FLOW_ACTION_TYPE_SET_TTL:
+                       PMD_DRV_LOG(DEBUG, "RTE_FLOW_ACTION_TYPE_SET_TTL 
detected");
+                       if (key_ls->key_layer & NFP_FLOWER_LAYER_IPV4) {
+                               if (!ttl_tos_flag) {
+                                       key_ls->act_size +=
+                                               sizeof(struct 
nfp_fl_act_set_ip4_ttl_tos);
+                                       ttl_tos_flag = true;
+                               }
+                       } else {
+                               if (!tc_hl_flag) {
+                                       key_ls->act_size +=
+                                               sizeof(struct 
nfp_fl_act_set_ipv6_tc_hl_fl);
+                                       tc_hl_flag = true;
+                               }
+                       }
+                       break;
                default:
                        PMD_DRV_LOG(ERR, "Action type %d not supported.", 
action->type);
                        return -ENOTSUP;
@@ -1449,6 +1467,52 @@ struct nfp_mask_id_entry {
        return 0;
 }
 
+static void
+nfp_flow_action_set_ttl(char *act_data,
+               const struct rte_flow_action *action,
+               bool ttl_tos_flag)
+{
+       size_t act_size;
+       struct nfp_fl_act_set_ip4_ttl_tos *ttl_tos;
+       const struct rte_flow_action_set_ttl *ttl_conf;
+
+       if (ttl_tos_flag)
+               ttl_tos = (struct nfp_fl_act_set_ip4_ttl_tos *)act_data - 1;
+       else
+               ttl_tos = (struct nfp_fl_act_set_ip4_ttl_tos *)act_data;
+
+       act_size = sizeof(struct nfp_fl_act_set_ip4_ttl_tos);
+       ttl_tos->head.jump_id = NFP_FL_ACTION_OPCODE_SET_IPV4_TTL_TOS;
+       ttl_tos->head.len_lw = act_size >> NFP_FL_LW_SIZ;
+
+       ttl_conf = (const struct rte_flow_action_set_ttl *)action->conf;
+       ttl_tos->ipv4_ttl = ttl_conf->ttl_value;
+       ttl_tos->reserved = 0;
+}
+
+static void
+nfp_flow_action_set_hl(char *act_data,
+               const struct rte_flow_action *action,
+               bool tc_hl_flag)
+{
+       size_t act_size;
+       struct nfp_fl_act_set_ipv6_tc_hl_fl *tc_hl;
+       const struct rte_flow_action_set_ttl *ttl_conf;
+
+       if (tc_hl_flag)
+               tc_hl = (struct nfp_fl_act_set_ipv6_tc_hl_fl *)act_data - 1;
+       else
+               tc_hl = (struct nfp_fl_act_set_ipv6_tc_hl_fl *)act_data;
+
+       act_size = sizeof(struct nfp_fl_act_set_ipv6_tc_hl_fl);
+       tc_hl->head.jump_id = NFP_FL_ACTION_OPCODE_SET_IPV6_TC_HL_FL;
+       tc_hl->head.len_lw = act_size >> NFP_FL_LW_SIZ;
+
+       ttl_conf = (const struct rte_flow_action_set_ttl *)action->conf;
+       tc_hl->ipv6_hop_limit = ttl_conf->ttl_value;
+       tc_hl->reserved = 0;
+}
+
 static int
 nfp_flow_compile_action(__rte_unused struct nfp_flower_representor 
*representor,
                const struct rte_flow_action actions[],
@@ -1457,17 +1521,21 @@ struct nfp_mask_id_entry {
        int ret = 0;
        char *position;
        char *action_data;
+       bool ttl_tos_flag = false;
+       bool tc_hl_flag = false;
        bool drop_flag = false;
        bool ip_set_flag = false;
        bool tp_set_flag = false;
        bool mac_set_flag = false;
        uint32_t total_actions = 0;
        const struct rte_flow_action *action;
+       struct nfp_flower_meta_tci *meta_tci;
        struct nfp_fl_rule_metadata *nfp_flow_meta;
 
        nfp_flow_meta = nfp_flow->payload.meta;
        action_data   = nfp_flow->payload.action_data;
        position      = action_data;
+       meta_tci = (struct nfp_flower_meta_tci 
*)nfp_flow->payload.unmasked_data;
 
        for (action = actions; action->type != RTE_FLOW_ACTION_TYPE_END; 
++action) {
                switch (action->type) {
@@ -1577,6 +1645,22 @@ struct nfp_mask_id_entry {
                                tp_set_flag = true;
                        }
                        break;
+               case RTE_FLOW_ACTION_TYPE_SET_TTL:
+                       PMD_DRV_LOG(DEBUG, "Process 
RTE_FLOW_ACTION_TYPE_SET_TTL");
+                       if (meta_tci->nfp_flow_key_layer & 
NFP_FLOWER_LAYER_IPV4) {
+                               nfp_flow_action_set_ttl(position, action, 
ttl_tos_flag);
+                               if (!ttl_tos_flag) {
+                                       position += sizeof(struct 
nfp_fl_act_set_ip4_ttl_tos);
+                                       ttl_tos_flag = true;
+                               }
+                       } else {
+                               nfp_flow_action_set_hl(position, action, 
ttl_tos_flag);
+                               if (!tc_hl_flag) {
+                                       position += sizeof(struct 
nfp_fl_act_set_ipv6_tc_hl_fl);
+                                       tc_hl_flag = true;
+                               }
+                       }
+                       break;
                default:
                        PMD_DRV_LOG(ERR, "Unsupported action type: %d", 
action->type);
                        return -ENOTSUP;
-- 
1.8.3.1

Reply via email to