Add support for PPP over L2TPv2 over UDP over outer IPv4 protocol
RSS Hash based on inner IP src/dst address and TCP/UDP src/dst port.

Signed-off-by: Wenjun Wu <wenjun1...@intel.com>
Signed-off-by: Jie Wang <jie1x.w...@intel.com>
---
 drivers/net/iavf/iavf_generic_flow.c |  67 ++++++++++++++++++
 drivers/net/iavf/iavf_generic_flow.h |   9 +++
 drivers/net/iavf/iavf_hash.c         | 102 ++++++++++++++++++++++++++-
 3 files changed, 176 insertions(+), 2 deletions(-)

diff --git a/drivers/net/iavf/iavf_generic_flow.c 
b/drivers/net/iavf/iavf_generic_flow.c
index 1fe270fb22..ab2f91c57c 100644
--- a/drivers/net/iavf/iavf_generic_flow.c
+++ b/drivers/net/iavf/iavf_generic_flow.c
@@ -1611,6 +1611,73 @@ enum rte_flow_item_type 
iavf_pattern_eth_ipv6_gre_ipv6_udp[] = {
        RTE_FLOW_ITEM_TYPE_END,
 };
 
+/* PPPoL2TPv2oUDP */
+enum rte_flow_item_type iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv4[] = {
+       RTE_FLOW_ITEM_TYPE_ETH,
+       RTE_FLOW_ITEM_TYPE_IPV4,
+       RTE_FLOW_ITEM_TYPE_UDP,
+       RTE_FLOW_ITEM_TYPE_L2TPV2,
+       RTE_FLOW_ITEM_TYPE_PPP,
+       RTE_FLOW_ITEM_TYPE_IPV4,
+       RTE_FLOW_ITEM_TYPE_END,
+};
+
+enum rte_flow_item_type iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv6[] = {
+       RTE_FLOW_ITEM_TYPE_ETH,
+       RTE_FLOW_ITEM_TYPE_IPV4,
+       RTE_FLOW_ITEM_TYPE_UDP,
+       RTE_FLOW_ITEM_TYPE_L2TPV2,
+       RTE_FLOW_ITEM_TYPE_PPP,
+       RTE_FLOW_ITEM_TYPE_IPV6,
+       RTE_FLOW_ITEM_TYPE_END,
+};
+
+enum rte_flow_item_type iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv4_udp[] = {
+       RTE_FLOW_ITEM_TYPE_ETH,
+       RTE_FLOW_ITEM_TYPE_IPV4,
+       RTE_FLOW_ITEM_TYPE_UDP,
+       RTE_FLOW_ITEM_TYPE_L2TPV2,
+       RTE_FLOW_ITEM_TYPE_PPP,
+       RTE_FLOW_ITEM_TYPE_IPV4,
+       RTE_FLOW_ITEM_TYPE_UDP,
+       RTE_FLOW_ITEM_TYPE_END,
+};
+
+enum rte_flow_item_type iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv4_tcp[] = {
+       RTE_FLOW_ITEM_TYPE_ETH,
+       RTE_FLOW_ITEM_TYPE_IPV4,
+       RTE_FLOW_ITEM_TYPE_UDP,
+       RTE_FLOW_ITEM_TYPE_L2TPV2,
+       RTE_FLOW_ITEM_TYPE_PPP,
+       RTE_FLOW_ITEM_TYPE_IPV4,
+       RTE_FLOW_ITEM_TYPE_TCP,
+       RTE_FLOW_ITEM_TYPE_END,
+};
+
+enum rte_flow_item_type iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv6_udp[] = {
+       RTE_FLOW_ITEM_TYPE_ETH,
+       RTE_FLOW_ITEM_TYPE_IPV4,
+       RTE_FLOW_ITEM_TYPE_UDP,
+       RTE_FLOW_ITEM_TYPE_L2TPV2,
+       RTE_FLOW_ITEM_TYPE_PPP,
+       RTE_FLOW_ITEM_TYPE_IPV6,
+       RTE_FLOW_ITEM_TYPE_UDP,
+       RTE_FLOW_ITEM_TYPE_END,
+};
+
+enum rte_flow_item_type iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv6_tcp[] = {
+       RTE_FLOW_ITEM_TYPE_ETH,
+       RTE_FLOW_ITEM_TYPE_IPV4,
+       RTE_FLOW_ITEM_TYPE_UDP,
+       RTE_FLOW_ITEM_TYPE_L2TPV2,
+       RTE_FLOW_ITEM_TYPE_PPP,
+       RTE_FLOW_ITEM_TYPE_IPV6,
+       RTE_FLOW_ITEM_TYPE_TCP,
+       RTE_FLOW_ITEM_TYPE_END,
+};
+
+
+
 typedef struct iavf_flow_engine * (*parse_engine_t)(struct iavf_adapter *ad,
                struct rte_flow *flow,
                struct iavf_parser_list *parser_list,
diff --git a/drivers/net/iavf/iavf_generic_flow.h 
b/drivers/net/iavf/iavf_generic_flow.h
index 4794d1fb80..c976b60c79 100644
--- a/drivers/net/iavf/iavf_generic_flow.h
+++ b/drivers/net/iavf/iavf_generic_flow.h
@@ -410,6 +410,15 @@ extern enum rte_flow_item_type 
iavf_pattern_eth_ipv6_gre_ipv6_tcp[];
 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gre_ipv4_udp[];
 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gre_ipv6_udp[];
 
+/* PPPoL2TPv2oUDP */
+extern enum rte_flow_item_type iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv4[];
+extern enum rte_flow_item_type iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv6[];
+extern enum rte_flow_item_type iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv4_udp[];
+extern enum rte_flow_item_type iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv4_tcp[];
+extern enum rte_flow_item_type iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv6_udp[];
+extern enum rte_flow_item_type iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv6_tcp[];
+
+
 extern const struct rte_flow_ops iavf_flow_ops;
 
 /* pattern structure */
diff --git a/drivers/net/iavf/iavf_hash.c b/drivers/net/iavf/iavf_hash.c
index eba55ecea5..e725326d5c 100644
--- a/drivers/net/iavf/iavf_hash.c
+++ b/drivers/net/iavf/iavf_hash.c
@@ -34,6 +34,8 @@
 /* the second IP header of GTPoGRE */
 #define IAVF_PHINT_MID_IPV4                    BIT_ULL(7)
 #define IAVF_PHINT_MID_IPV6                    BIT_ULL(8)
+/* L2TPV2 */
+#define IAVF_PHINT_L2TPV2                      BIT_ULL(9)
 
 #define IAVF_PHINT_GTPU_MSK    (IAVF_PHINT_GTPU        | \
                                 IAVF_PHINT_GTPU_EH     | \
@@ -164,6 +166,12 @@ iavf_hash_parse_pattern_action(struct iavf_adapter *ad,
        VIRTCHNL_PROTO_HDR_ECPRI, \
        FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ECPRI_PC_RTC_ID), {BUFF_NOUSED} }
 
+#define proto_hdr_l2tpv2 { \
+       VIRTCHNL_PROTO_HDR_L2TPV2, 0, {BUFF_NOUSED} }
+
+#define proto_hdr_ppp { \
+       VIRTCHNL_PROTO_HDR_PPP, 0, {BUFF_NOUSED} }
+
 #define TUNNEL_LEVEL_OUTER             0
 #define TUNNEL_LEVEL_INNER             1
 
@@ -338,6 +346,52 @@ struct virtchnl_proto_hdrs ipv4_ecpri_tmplt = {
        TUNNEL_LEVEL_OUTER, 3, {proto_hdr_ipv4, proto_hdr_udp, proto_hdr_ecpri}
 };
 
+struct virtchnl_proto_hdrs udp_l2tpv2_ppp_ipv4_tmplt = {
+       TUNNEL_LEVEL_INNER, 3,
+       {proto_hdr_l2tpv2,
+        proto_hdr_ppp,
+        proto_hdr_ipv4}
+};
+
+struct virtchnl_proto_hdrs udp_l2tpv2_ppp_ipv6_tmplt = {
+       TUNNEL_LEVEL_INNER, 3,
+       {proto_hdr_l2tpv2,
+        proto_hdr_ppp,
+        proto_hdr_ipv6}
+};
+
+struct virtchnl_proto_hdrs udp_l2tpv2_ppp_ipv4_udp_tmplt = {
+       TUNNEL_LEVEL_INNER, 4,
+       {proto_hdr_l2tpv2,
+        proto_hdr_ppp,
+        proto_hdr_ipv4_with_prot,
+        proto_hdr_udp}
+};
+
+struct virtchnl_proto_hdrs udp_l2tpv2_ppp_ipv4_tcp_tmplt = {
+       TUNNEL_LEVEL_INNER, 4,
+       {proto_hdr_l2tpv2,
+        proto_hdr_ppp,
+        proto_hdr_ipv4_with_prot,
+        proto_hdr_tcp}
+};
+
+struct virtchnl_proto_hdrs udp_l2tpv2_ppp_ipv6_udp_tmplt = {
+       TUNNEL_LEVEL_INNER, 4,
+       {proto_hdr_l2tpv2,
+        proto_hdr_ppp,
+        proto_hdr_ipv6_with_prot,
+        proto_hdr_udp}
+};
+
+struct virtchnl_proto_hdrs udp_l2tpv2_ppp_ipv6_tcp_tmplt = {
+       TUNNEL_LEVEL_INNER, 4,
+       {proto_hdr_l2tpv2,
+        proto_hdr_ppp,
+        proto_hdr_ipv6_with_prot,
+        proto_hdr_tcp}
+};
+
 /* rss type super set */
 
 /* IPv4 outer */
@@ -486,6 +540,10 @@ static struct iavf_pattern_match_item 
iavf_hash_pattern_list[] = {
        {iavf_pattern_eth_ipv6_gre_ipv4_tcp,    IAVF_RSS_TYPE_INNER_IPV4_TCP, 
&inner_ipv4_tcp_tmplt},
        {iavf_pattern_eth_ipv4_gre_ipv4_udp,    IAVF_RSS_TYPE_INNER_IPV4_UDP, 
&inner_ipv4_udp_tmplt},
        {iavf_pattern_eth_ipv6_gre_ipv4_udp,    IAVF_RSS_TYPE_INNER_IPV4_UDP, 
&inner_ipv4_udp_tmplt},
+       {iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv4,     
IAVF_RSS_TYPE_INNER_IPV4,       &udp_l2tpv2_ppp_ipv4_tmplt},
+       {iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv4_udp, 
IAVF_RSS_TYPE_INNER_IPV4_UDP,   &udp_l2tpv2_ppp_ipv4_udp_tmplt},
+       {iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv4_tcp, 
IAVF_RSS_TYPE_INNER_IPV4_TCP,   &udp_l2tpv2_ppp_ipv4_tcp_tmplt},
+
        /* IPv6 */
        {iavf_pattern_eth_ipv6,                         
IAVF_RSS_TYPE_OUTER_IPV6,       &outer_ipv6_tmplt},
        {iavf_pattern_eth_ipv6_frag_ext,                
IAVF_RSS_TYPE_OUTER_IPV6_FRAG,  &outer_ipv6_frag_tmplt},
@@ -546,6 +604,10 @@ static struct iavf_pattern_match_item 
iavf_hash_pattern_list[] = {
        {iavf_pattern_eth_ipv6_gre_ipv6_tcp,    IAVF_RSS_TYPE_INNER_IPV6_TCP, 
&inner_ipv6_tcp_tmplt},
        {iavf_pattern_eth_ipv4_gre_ipv6_udp,    IAVF_RSS_TYPE_INNER_IPV6_UDP, 
&inner_ipv6_udp_tmplt},
        {iavf_pattern_eth_ipv6_gre_ipv6_udp,    IAVF_RSS_TYPE_INNER_IPV6_UDP, 
&inner_ipv6_udp_tmplt},
+       {iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv6,     
IAVF_RSS_TYPE_INNER_IPV6,       &udp_l2tpv2_ppp_ipv6_tmplt},
+       {iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv6_udp, 
IAVF_RSS_TYPE_INNER_IPV6_UDP,   &udp_l2tpv2_ppp_ipv6_udp_tmplt},
+       {iavf_pattern_eth_ipv4_udp_l2tpv2_ppp_ipv6_tcp, 
IAVF_RSS_TYPE_INNER_IPV6_TCP,   &udp_l2tpv2_ppp_ipv6_tcp_tmplt},
+
 };
 
 static struct iavf_flow_engine iavf_hash_engine = {
@@ -690,13 +752,17 @@ iavf_hash_parse_pattern(const struct rte_flow_item 
pattern[], uint64_t *phint,
 
                switch (item->type) {
                case RTE_FLOW_ITEM_TYPE_IPV4:
-                       if (!(*phint & IAVF_PHINT_GTPU_MSK) && !(*phint & 
IAVF_PHINT_GRE))
+                       if (!(*phint & IAVF_PHINT_GTPU_MSK) &&
+                           !(*phint & IAVF_PHINT_GRE) &&
+                           !(*phint & IAVF_PHINT_L2TPV2))
                                *phint |= IAVF_PHINT_OUTER_IPV4;
                        if ((*phint & IAVF_PHINT_GRE) && !(*phint & 
IAVF_PHINT_GTPU_MSK))
                                *phint |= IAVF_PHINT_MID_IPV4;
                        break;
                case RTE_FLOW_ITEM_TYPE_IPV6:
-                       if (!(*phint & IAVF_PHINT_GTPU_MSK) && !(*phint & 
IAVF_PHINT_GRE))
+                       if (!(*phint & IAVF_PHINT_GTPU_MSK) &&
+                           !(*phint & IAVF_PHINT_GRE) &&
+                           !(*phint & IAVF_PHINT_L2TPV2))
                                *phint |= IAVF_PHINT_OUTER_IPV6;
                        if ((*phint & IAVF_PHINT_GRE) && !(*phint & 
IAVF_PHINT_GTPU_MSK))
                                *phint |= IAVF_PHINT_MID_IPV6;
@@ -731,6 +797,10 @@ iavf_hash_parse_pattern(const struct rte_flow_item 
pattern[], uint64_t *phint,
                        break;
                case RTE_FLOW_ITEM_TYPE_GRE:
                        *phint |= IAVF_PHINT_GRE;
+                       break;
+               case RTE_FLOW_ITEM_TYPE_L2TPV2:
+                       *phint |= IAVF_PHINT_L2TPV2;
+                       break;
                default:
                        break;
                }
@@ -1036,12 +1106,40 @@ iavf_refine_proto_hdrs_by_pattern(struct 
virtchnl_proto_hdrs *proto_hdrs,
        proto_hdrs->tunnel_level = tun_lvl;
 }
 
+static void
+iavf_refine_proto_hdrs_l2tpv2(struct virtchnl_proto_hdrs *proto_hdrs,
+                             uint64_t phint)
+{
+       struct virtchnl_proto_hdr *hdr1;
+       int i;
+
+       if (!(phint & IAVF_PHINT_L2TPV2))
+               return;
+
+       if (proto_hdrs->tunnel_level == TUNNEL_LEVEL_INNER) {
+               /* shift headers layer */
+               for (i = proto_hdrs->count - 1 + 1; i > 0; i--)
+                       proto_hdrs->proto_hdr[i] = proto_hdrs->proto_hdr[i - 1];
+
+               /* adding outer ip header at layer 0 */
+               hdr1 = &proto_hdrs->proto_hdr[0];
+               hdr1->field_selector = 0;
+               proto_hdrs->count++;
+               proto_hdrs->tunnel_level = TUNNEL_LEVEL_OUTER;
+               if (phint & IAVF_PHINT_OUTER_IPV4)
+                       VIRTCHNL_SET_PROTO_HDR_TYPE(hdr1, IPV4);
+               else if (phint & IAVF_PHINT_OUTER_IPV6)
+                       VIRTCHNL_SET_PROTO_HDR_TYPE(hdr1, IPV6);
+       }
+}
+
 static void iavf_refine_proto_hdrs(struct virtchnl_proto_hdrs *proto_hdrs,
                                   uint64_t rss_type, uint64_t phint)
 {
        iavf_refine_proto_hdrs_l234(proto_hdrs, rss_type);
        iavf_refine_proto_hdrs_by_pattern(proto_hdrs, phint);
        iavf_refine_proto_hdrs_gtpu(proto_hdrs, rss_type);
+       iavf_refine_proto_hdrs_l2tpv2(proto_hdrs, phint);
 }
 
 static uint64_t invalid_rss_comb[] = {
-- 
2.25.1

Reply via email to