Add the related data structure and logics, prepare for
the decap action of IPv4 GRE tunnel.

Signed-off-by: Chaoyong He <chaoyong...@corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderl...@corigine.com>
---
 drivers/net/nfp/flower/nfp_flower_cmsg.h | 29 +++++++++++++++++++++++
 drivers/net/nfp/nfp_flow.c               | 40 +++++++++++++++++++++++++-------
 drivers/net/nfp/nfp_flow.h               |  3 +++
 3 files changed, 63 insertions(+), 9 deletions(-)

diff --git a/drivers/net/nfp/flower/nfp_flower_cmsg.h 
b/drivers/net/nfp/flower/nfp_flower_cmsg.h
index 61f2f83..8bca7c2 100644
--- a/drivers/net/nfp/flower/nfp_flower_cmsg.h
+++ b/drivers/net/nfp/flower/nfp_flower_cmsg.h
@@ -575,6 +575,35 @@ struct nfp_flower_ipv6_udp_tun {
        rte_be32_t tun_id;
 };
 
+/*
+ * Flow Frame GRE TUNNEL --> Tunnel details (6W/24B)
+ * -----------------------------------------------------------------
+ *    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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |                         ipv4_addr_src                         |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |                         ipv4_addr_dst                         |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |           tun_flags           |       tos     |       ttl     |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |            Reserved           |           Ethertype           |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |                              Key                              |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |                           Reserved                            |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+struct nfp_flower_ipv4_gre_tun {
+       struct nfp_flower_tun_ipv4 ipv4;
+       rte_be16_t tun_flags;
+       struct nfp_flower_tun_ip_ext ip_ext;
+       rte_be16_t reserved1;
+       rte_be16_t ethertype;
+       rte_be32_t tun_key;
+       rte_be32_t reserved2;
+};
+
 struct nfp_fl_act_head {
        uint8_t jump_id;
        uint8_t len_lw;
diff --git a/drivers/net/nfp/nfp_flow.c b/drivers/net/nfp/nfp_flow.c
index fd64da8..01c6e9a 100644
--- a/drivers/net/nfp/nfp_flow.c
+++ b/drivers/net/nfp/nfp_flow.c
@@ -564,6 +564,7 @@ struct nfp_pre_tun_entry {
        uint32_t key_layer2 = 0;
        struct nfp_flower_ipv4_udp_tun *udp4;
        struct nfp_flower_ipv6_udp_tun *udp6;
+       struct nfp_flower_ipv4_gre_tun *gre4;
        struct nfp_flower_meta_tci *meta_tci;
        struct nfp_flower_ext_meta *ext_meta = NULL;
 
@@ -579,9 +580,15 @@ struct nfp_pre_tun_entry {
                                sizeof(struct nfp_flower_ipv6_udp_tun));
                ret = nfp_tun_del_ipv6_off(repr->app_fw_flower, 
udp6->ipv6.ipv6_dst);
        } else {
-               udp4 = (struct nfp_flower_ipv4_udp_tun 
*)(nfp_flow->payload.mask_data -
-                               sizeof(struct nfp_flower_ipv4_udp_tun));
-               ret = nfp_tun_del_ipv4_off(repr->app_fw_flower, udp4->ipv4.dst);
+               if (key_layer2 & NFP_FLOWER_LAYER2_GRE) {
+                       gre4 = (struct nfp_flower_ipv4_gre_tun 
*)(nfp_flow->payload.mask_data -
+                                       sizeof(struct nfp_flower_ipv4_gre_tun));
+                       ret = nfp_tun_del_ipv4_off(repr->app_fw_flower, 
gre4->ipv4.dst);
+               } else {
+                       udp4 = (struct nfp_flower_ipv4_udp_tun 
*)(nfp_flow->payload.mask_data -
+                                       sizeof(struct nfp_flower_ipv4_udp_tun));
+                       ret = nfp_tun_del_ipv4_off(repr->app_fw_flower, 
udp4->ipv4.dst);
+               }
        }
 
        return ret;
@@ -1013,7 +1020,7 @@ struct nfp_pre_tun_entry {
 
        ext_meta = (struct nfp_flower_ext_meta *)(meta_tci + 1);
        key_layer2 = rte_be_to_cpu_32(ext_meta->nfp_flow_key_layer2);
-       if (key_layer2 & NFP_FLOWER_LAYER2_GENEVE)
+       if (key_layer2 & (NFP_FLOWER_LAYER2_GENEVE | NFP_FLOWER_LAYER2_GRE))
                return true;
 
        return false;
@@ -1102,11 +1109,15 @@ struct nfp_pre_tun_entry {
        struct nfp_flower_meta_tci *meta_tci;
        const struct rte_flow_item_ipv4 *spec;
        const struct rte_flow_item_ipv4 *mask;
+       struct nfp_flower_ext_meta *ext_meta = NULL;
        struct nfp_flower_ipv4_udp_tun *ipv4_udp_tun;
+       struct nfp_flower_ipv4_gre_tun *ipv4_gre_tun;
 
        spec = item->spec;
        mask = item->mask ? item->mask : proc->mask_default;
        meta_tci = (struct nfp_flower_meta_tci 
*)nfp_flow->payload.unmasked_data;
+       if (meta_tci->nfp_flow_key_layer & NFP_FLOWER_LAYER_EXT_META)
+               ext_meta = (struct nfp_flower_ext_meta *)(meta_tci + 1);
 
        if (is_outer_layer && nfp_flow_is_tunnel(nfp_flow)) {
                if (spec == NULL) {
@@ -1115,12 +1126,23 @@ struct nfp_pre_tun_entry {
                }
 
                hdr = is_mask ? &mask->hdr : &spec->hdr;
-               ipv4_udp_tun = (struct nfp_flower_ipv4_udp_tun *)*mbuf_off;
 
-               ipv4_udp_tun->ip_ext.tos = hdr->type_of_service;
-               ipv4_udp_tun->ip_ext.ttl = hdr->time_to_live;
-               ipv4_udp_tun->ipv4.src   = hdr->src_addr;
-               ipv4_udp_tun->ipv4.dst   = hdr->dst_addr;
+               if (ext_meta && 
(rte_be_to_cpu_32(ext_meta->nfp_flow_key_layer2) &
+                               NFP_FLOWER_LAYER2_GRE)) {
+                       ipv4_gre_tun = (struct nfp_flower_ipv4_gre_tun 
*)*mbuf_off;
+
+                       ipv4_gre_tun->ip_ext.tos = hdr->type_of_service;
+                       ipv4_gre_tun->ip_ext.ttl = hdr->time_to_live;
+                       ipv4_gre_tun->ipv4.src   = hdr->src_addr;
+                       ipv4_gre_tun->ipv4.dst   = hdr->dst_addr;
+               } else {
+                       ipv4_udp_tun = (struct nfp_flower_ipv4_udp_tun 
*)*mbuf_off;
+
+                       ipv4_udp_tun->ip_ext.tos = hdr->type_of_service;
+                       ipv4_udp_tun->ip_ext.ttl = hdr->time_to_live;
+                       ipv4_udp_tun->ipv4.src   = hdr->src_addr;
+                       ipv4_udp_tun->ipv4.dst   = hdr->dst_addr;
+               }
        } else {
                if (spec == NULL) {
                        PMD_DRV_LOG(DEBUG, "nfp flow merge ipv4: no 
item->spec!");
diff --git a/drivers/net/nfp/nfp_flow.h b/drivers/net/nfp/nfp_flow.h
index a6994e0..b0c2aaf 100644
--- a/drivers/net/nfp/nfp_flow.h
+++ b/drivers/net/nfp/nfp_flow.h
@@ -49,6 +49,9 @@
 #define NFP_FL_SC_ACT_POPV      0x6A000000
 #define NFP_FL_SC_ACT_NULL      0x00000000
 
+/* GRE Tunnel flags */
+#define NFP_FL_GRE_FLAG_KEY         (1 << 2)
+
 /* Action opcodes */
 #define NFP_FL_ACTION_OPCODE_OUTPUT             0
 #define NFP_FL_ACTION_OPCODE_PUSH_VLAN          1
-- 
1.8.3.1

Reply via email to