net/ice: support PPPoE RSS
[dpdk.git] / drivers / net / ice / ice_hash.c
index 346d6cf..eaf6a35 100644 (file)
@@ -25,8 +25,6 @@
 #include "ice_ethdev.h"
 #include "ice_generic_flow.h"
 
-#define ICE_ACTION_RSS_MAX_QUEUE_NUM 32
-
 struct rss_type_match_hdr {
        uint32_t hdr_mask;
        uint64_t eth_rss_hint;
@@ -43,6 +41,11 @@ struct rss_meta {
        uint8_t hash_function;
 };
 
+struct ice_hash_flow_cfg {
+       bool simple_xor;
+       struct ice_rss_cfg rss_cfg;
+};
+
 static int
 ice_hash_init(struct ice_adapter *ad);
 
@@ -76,23 +79,29 @@ ice_hash_parse_pattern_action(struct ice_adapter *ad,
 struct rss_type_match_hdr hint_0 = {
        ICE_FLOW_SEG_HDR_NONE,  0};
 struct rss_type_match_hdr hint_1 = {
-       ICE_FLOW_SEG_HDR_IPV4 ETH_RSS_IPV4};
+       ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER, ETH_RSS_IPV4};
 struct rss_type_match_hdr hint_2 = {
-       ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_UDP, ETH_RSS_NONFRAG_IPV4_UDP};
+       ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_UDP |
+       ICE_FLOW_SEG_HDR_IPV_OTHER, ETH_RSS_NONFRAG_IPV4_UDP};
 struct rss_type_match_hdr hint_3 = {
-       ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_TCP, ETH_RSS_NONFRAG_IPV4_TCP};
+       ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_TCP |
+       ICE_FLOW_SEG_HDR_IPV_OTHER, ETH_RSS_NONFRAG_IPV4_TCP};
 struct rss_type_match_hdr hint_4 = {
-       ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_SCTP, ETH_RSS_NONFRAG_IPV4_SCTP};
+       ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_SCTP |
+       ICE_FLOW_SEG_HDR_IPV_OTHER, ETH_RSS_NONFRAG_IPV4_SCTP};
 struct rss_type_match_hdr hint_5 = {
-       ICE_FLOW_SEG_HDR_IPV6 ETH_RSS_IPV6};
+       ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER, ETH_RSS_IPV6};
 struct rss_type_match_hdr hint_6 = {
-       ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_UDP, ETH_RSS_NONFRAG_IPV6_UDP};
+       ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_UDP |
+       ICE_FLOW_SEG_HDR_IPV_OTHER, ETH_RSS_NONFRAG_IPV6_UDP};
 struct rss_type_match_hdr hint_7 = {
-       ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_TCP, ETH_RSS_NONFRAG_IPV6_TCP};
+       ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_TCP |
+       ICE_FLOW_SEG_HDR_IPV_OTHER, ETH_RSS_NONFRAG_IPV6_TCP};
 struct rss_type_match_hdr hint_8 = {
-       ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_SCTP, ETH_RSS_NONFRAG_IPV6_SCTP};
+       ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_SCTP |
+       ICE_FLOW_SEG_HDR_IPV_OTHER, ETH_RSS_NONFRAG_IPV6_SCTP};
 struct rss_type_match_hdr hint_9 = {
-       ICE_FLOW_SEG_HDR_GTPU_IP,       ETH_RSS_IPV4};
+       ICE_FLOW_SEG_HDR_GTPU_EH, ETH_RSS_IPV4};
 struct rss_type_match_hdr hint_10 = {
        ICE_FLOW_SEG_HDR_PPPOE, ETH_RSS_IPV4};
 struct rss_type_match_hdr hint_11 = {
@@ -101,6 +110,20 @@ struct rss_type_match_hdr hint_12 = {
        ICE_FLOW_SEG_HDR_PPPOE, ETH_RSS_NONFRAG_IPV4_TCP};
 struct rss_type_match_hdr hint_13 = {
        ICE_FLOW_SEG_HDR_PPPOE, ETH_RSS_NONFRAG_IPV4_SCTP};
+struct rss_type_match_hdr hint_14 = {
+       ICE_FLOW_SEG_HDR_GTPU_EH, ETH_RSS_NONFRAG_IPV4_UDP};
+struct rss_type_match_hdr hint_15 = {
+       ICE_FLOW_SEG_HDR_GTPU_EH, ETH_RSS_NONFRAG_IPV4_TCP};
+struct rss_type_match_hdr hint_16 = {
+       ICE_FLOW_SEG_HDR_PPPOE, ETH_RSS_IPV6};
+struct rss_type_match_hdr hint_17 = {
+       ICE_FLOW_SEG_HDR_PPPOE, ETH_RSS_NONFRAG_IPV6_UDP};
+struct rss_type_match_hdr hint_18 = {
+       ICE_FLOW_SEG_HDR_PPPOE, ETH_RSS_NONFRAG_IPV6_TCP};
+struct rss_type_match_hdr hint_19 = {
+       ICE_FLOW_SEG_HDR_PPPOE, ETH_RSS_NONFRAG_IPV6_SCTP};
+struct rss_type_match_hdr hint_20 = {
+       ICE_FLOW_SEG_HDR_PPPOE, ETH_RSS_ETH | ETH_RSS_PPPOE};
 
 /* Supported pattern for os default package. */
 static struct ice_pattern_match_item ice_hash_pattern_list_os[] = {
@@ -117,22 +140,27 @@ static struct ice_pattern_match_item ice_hash_pattern_list_os[] = {
 
 /* Supported pattern for comms package. */
 static struct ice_pattern_match_item ice_hash_pattern_list_comms[] = {
-       {pattern_eth_ipv4,               ICE_INSET_NONE,  &hint_1},
-       {pattern_eth_ipv4_udp,           ICE_INSET_NONE,  &hint_2},
-       {pattern_eth_ipv4_tcp,           ICE_INSET_NONE,  &hint_3},
-       {pattern_eth_ipv4_sctp,          ICE_INSET_NONE,  &hint_4},
-       {pattern_eth_ipv6,               ICE_INSET_NONE,  &hint_5},
-       {pattern_eth_ipv6_udp,           ICE_INSET_NONE,  &hint_6},
-       {pattern_eth_ipv6_tcp,           ICE_INSET_NONE,  &hint_7},
-       {pattern_eth_ipv6_sctp,          ICE_INSET_NONE,  &hint_8},
-       {pattern_empty,                  ICE_INSET_NONE,  &hint_0},
-       {pattern_eth_ipv4_gtpu_ipv4,     ICE_INSET_NONE,  &hint_9},
-       {pattern_eth_ipv4_gtpu_ipv4_udp, ICE_INSET_NONE,  &hint_9},
-       {pattern_eth_ipv4_gtpu_ipv4_tcp, ICE_INSET_NONE,  &hint_9},
-       {pattern_eth_pppoes_ipv4,        ICE_INSET_NONE,  &hint_10},
-       {pattern_eth_pppoes_ipv4_udp,    ICE_INSET_NONE,  &hint_11},
-       {pattern_eth_pppoes_ipv4_tcp,    ICE_INSET_NONE,  &hint_12},
-       {pattern_eth_pppoes_ipv4_sctp,   ICE_INSET_NONE,  &hint_13},
+       {pattern_eth_ipv4,                  ICE_INSET_NONE,  &hint_1},
+       {pattern_eth_ipv4_udp,              ICE_INSET_NONE,  &hint_2},
+       {pattern_eth_ipv4_tcp,              ICE_INSET_NONE,  &hint_3},
+       {pattern_eth_ipv4_sctp,             ICE_INSET_NONE,  &hint_4},
+       {pattern_eth_ipv6,                  ICE_INSET_NONE,  &hint_5},
+       {pattern_eth_ipv6_udp,              ICE_INSET_NONE,  &hint_6},
+       {pattern_eth_ipv6_tcp,              ICE_INSET_NONE,  &hint_7},
+       {pattern_eth_ipv6_sctp,             ICE_INSET_NONE,  &hint_8},
+       {pattern_empty,                     ICE_INSET_NONE,  &hint_0},
+       {pattern_eth_ipv4_gtpu_eh_ipv4,     ICE_INSET_NONE,  &hint_9},
+       {pattern_eth_ipv4_gtpu_eh_ipv4_udp, ICE_INSET_NONE,  &hint_14},
+       {pattern_eth_ipv4_gtpu_eh_ipv4_tcp, ICE_INSET_NONE,  &hint_15},
+       {pattern_eth_pppoes_ipv4,           ICE_INSET_NONE,  &hint_10},
+       {pattern_eth_pppoes_ipv4_udp,       ICE_INSET_NONE,  &hint_11},
+       {pattern_eth_pppoes_ipv4_tcp,       ICE_INSET_NONE,  &hint_12},
+       {pattern_eth_pppoes_ipv4_sctp,      ICE_INSET_NONE,  &hint_13},
+       {pattern_eth_pppoes_ipv6,           ICE_INSET_NONE,  &hint_16},
+       {pattern_eth_pppoes_ipv6_udp,       ICE_INSET_NONE,  &hint_17},
+       {pattern_eth_pppoes_ipv6_tcp,       ICE_INSET_NONE,  &hint_18},
+       {pattern_eth_pppoes_ipv6_sctp,      ICE_INSET_NONE,  &hint_19},
+       {pattern_eth_pppoes,                ICE_INSET_NONE,  &hint_20},
 };
 
 /**
@@ -200,6 +228,9 @@ struct ice_hash_match_type ice_hash_type_list[] = {
        {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L4_SRC_ONLY,                       BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)},
        {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L4_DST_ONLY,                       BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)},
        {ETH_RSS_NONFRAG_IPV6_SCTP,                                             ICE_HASH_SCTP_IPV6},
+       {ETH_RSS_ETH | ETH_RSS_L2_SRC_ONLY,                                     BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_SA)},
+       {ETH_RSS_PPPOE,                                                         ICE_FLOW_HASH_PPPOE_SESS_ID},
+       {ETH_RSS_ETH | ETH_RSS_PPPOE | ETH_RSS_L2_SRC_ONLY,                     ICE_FLOW_HASH_PPPOE_SESS_ID | BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_SA)},
 };
 
 static struct ice_flow_engine ice_hash_engine = {
@@ -240,10 +271,15 @@ ice_hash_init(struct ice_adapter *ad)
 {
        struct ice_flow_parser *parser = NULL;
 
+       if (ad->hw.dcf_enabled)
+               return 0;
+
        if (ad->active_pkg_type == ICE_PKG_TYPE_OS_DEFAULT)
                parser = &ice_hash_parser_os;
        else if (ad->active_pkg_type == ICE_PKG_TYPE_COMMS)
                parser = &ice_hash_parser_comms;
+       else
+               return -EINVAL;
 
        return ice_register_parser(parser, ad);
 }
@@ -313,6 +349,13 @@ ice_hash_parse_action(struct ice_pattern_match_item *pattern_match_item,
                                        RTE_FLOW_ERROR_TYPE_ACTION, action,
                                        "Not supported flow");
 
+                       if ((rss_hf & ETH_RSS_ETH) && (rss_hf & ~ETH_RSS_PPPOE))
+                               m->eth_rss_hint = ETH_RSS_ETH;
+                       else if ((rss_hf & ETH_RSS_PPPOE) && (rss_hf & ~ETH_RSS_ETH))
+                               m->eth_rss_hint = ETH_RSS_PPPOE;
+                       else if ((rss_hf & ETH_RSS_ETH) && (rss_hf & ETH_RSS_PPPOE))
+                               m->eth_rss_hint = ETH_RSS_ETH | ETH_RSS_PPPOE;
+
                        /* Check if rss types match pattern. */
                        if (rss->func != RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
                                if (((rss_hf & ETH_RSS_IPV4) != m->eth_rss_hint) &&
@@ -322,7 +365,11 @@ ice_hash_parse_action(struct ice_pattern_match_item *pattern_match_item,
                                ((rss_hf & ETH_RSS_IPV6) != m->eth_rss_hint) &&
                                ((rss_hf & ETH_RSS_NONFRAG_IPV6_UDP) != m->eth_rss_hint) &&
                                ((rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) != m->eth_rss_hint) &&
-                               ((rss_hf & ETH_RSS_NONFRAG_IPV6_SCTP) != m->eth_rss_hint))
+                               ((rss_hf & ETH_RSS_NONFRAG_IPV6_SCTP) != m->eth_rss_hint) &&
+                               ((rss_hf & ETH_RSS_ETH) != m->eth_rss_hint) &&
+                               ((rss_hf & ETH_RSS_PPPOE) != m->eth_rss_hint) &&
+                               (((rss_hf & (ETH_RSS_ETH | ETH_RSS_PPPOE)) !=
+                                                                       m->eth_rss_hint)))
                                        return rte_flow_error_set(error,
                                        ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
                                        action, "Not supported RSS types");
@@ -333,15 +380,15 @@ ice_hash_parse_action(struct ice_pattern_match_item *pattern_match_item,
                                        RTE_FLOW_ERROR_TYPE_ACTION, action,
                                        "a nonzero RSS encapsulation level is not supported");
 
-                       if (rss->key_len == 0)
+                       if (rss->key_len)
                                return rte_flow_error_set(error, ENOTSUP,
                                        RTE_FLOW_ERROR_TYPE_ACTION, action,
-                                       "RSS hash key_len mustn't be 0");
+                                       "a nonzero RSS key_len is not supported");
 
-                       if (rss->queue_num > ICE_ACTION_RSS_MAX_QUEUE_NUM)
+                       if (rss->queue)
                                return rte_flow_error_set(error, ENOTSUP,
                                        RTE_FLOW_ERROR_TYPE_ACTION, action,
-                                       "too many queues for RSS context");
+                                       "a non-NULL RSS queue is not supported");
 
                        /* Check hash function and save it to rss_meta. */
                        if (rss->func ==
@@ -419,26 +466,31 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad,
        /* Check rss supported pattern and find matched pattern. */
        pattern_match_item = ice_search_pattern_match_item(pattern,
                                        array, array_len, error);
-       if (!pattern_match_item)
-               return -rte_errno;
+       if (!pattern_match_item) {
+               ret = -rte_errno;
+               goto error;
+       }
 
        ret = ice_hash_check_inset(pattern, error);
        if (ret)
-               return -rte_errno;
+               goto error;
 
        /* Save protocol header to rss_meta. */
-       *meta = rss_meta_ptr;
-       ((struct rss_meta *)*meta)->pkt_hdr = ((struct rss_type_match_hdr *)
+       rss_meta_ptr->pkt_hdr = ((struct rss_type_match_hdr *)
                (pattern_match_item->meta))->hdr_mask;
 
        /* Check rss action. */
-       ret = ice_hash_parse_action(pattern_match_item, actions, meta, error);
-       if (ret)
-               return -rte_errno;
+       ret = ice_hash_parse_action(pattern_match_item, actions,
+                                   (void **)&rss_meta_ptr, error);
 
+error:
+       if (!ret && meta)
+               *meta = rss_meta_ptr;
+       else
+               rte_free(rss_meta_ptr);
        rte_free(pattern_match_item);
 
-       return 0;
+       return ret;
 }
 
 static int
@@ -452,14 +504,14 @@ ice_hash_create(struct ice_adapter *ad,
        struct ice_vsi *vsi = pf->main_vsi;
        int ret;
        uint32_t reg;
-       struct ice_rss_cfg *filter_ptr;
+       struct ice_hash_flow_cfg *filter_ptr;
 
        uint32_t headermask = ((struct rss_meta *)meta)->pkt_hdr;
        uint64_t hash_field = ((struct rss_meta *)meta)->hash_flds;
        uint8_t hash_function = ((struct rss_meta *)meta)->hash_function;
 
        filter_ptr = rte_zmalloc("ice_rss_filter",
-                               sizeof(struct ice_rss_cfg), 0);
+                               sizeof(struct ice_hash_flow_cfg), 0);
        if (!filter_ptr) {
                rte_flow_error_set(error, EINVAL,
                                RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
@@ -474,19 +526,20 @@ ice_hash_create(struct ice_adapter *ad,
                        (2 << VSIQF_HASH_CTL_HASH_SCHEME_S);
                ICE_WRITE_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id), reg);
 
-               filter_ptr->symm = 0;
+               filter_ptr->simple_xor = 1;
 
                goto out;
-       } else if (hash_function == RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ) {
-               ret = ice_add_rss_cfg(hw, vsi->idx, hash_field, headermask, 1);
-               if (ret) {
-                       rte_flow_error_set(error, EINVAL,
-                                       RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
-                                       "rss flow create fail");
-                       goto error;
-               }
        } else {
-               ret = ice_add_rss_cfg(hw, vsi->idx, hash_field, headermask, 0);
+               filter_ptr->rss_cfg.packet_hdr = headermask;
+               filter_ptr->rss_cfg.hashed_flds = hash_field;
+               filter_ptr->rss_cfg.symm =
+                       (hash_function ==
+                               RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ);
+
+               ret = ice_add_rss_cfg(hw, vsi->idx,
+                               filter_ptr->rss_cfg.hashed_flds,
+                               filter_ptr->rss_cfg.packet_hdr,
+                               filter_ptr->rss_cfg.symm);
                if (ret) {
                        rte_flow_error_set(error, EINVAL,
                                        RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
@@ -495,9 +548,6 @@ ice_hash_create(struct ice_adapter *ad,
                }
        }
 
-       filter_ptr->packet_hdr = headermask;
-       filter_ptr->hashed_flds = hash_field;
-
 out:
        flow->rule = filter_ptr;
        rte_free(meta);
@@ -519,19 +569,26 @@ ice_hash_destroy(struct ice_adapter *ad,
        struct ice_vsi *vsi = pf->main_vsi;
        int ret;
        uint32_t reg;
-       struct ice_rss_cfg *filter_ptr;
+       struct ice_hash_flow_cfg *filter_ptr;
 
-       filter_ptr = (struct ice_rss_cfg *)flow->rule;
+       filter_ptr = (struct ice_hash_flow_cfg *)flow->rule;
 
-       if (filter_ptr->symm == 0) {
+       if (filter_ptr->simple_xor == 1) {
                /* Return to symmetric_toeplitz state. */
                reg = ICE_READ_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id));
                reg = (reg & (~VSIQF_HASH_CTL_HASH_SCHEME_M)) |
                        (1 << VSIQF_HASH_CTL_HASH_SCHEME_S);
                ICE_WRITE_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id), reg);
        } else {
-               ret = ice_rem_vsi_rss_cfg(hw, vsi->idx);
-               if (ret) {
+               ret = ice_rem_rss_cfg(hw, vsi->idx,
+                               filter_ptr->rss_cfg.hashed_flds,
+                               filter_ptr->rss_cfg.packet_hdr);
+               /* Fixme: Ignore the error if a rule does not exist.
+                * Currently a rule for inputset change or symm turn on/off
+                * will overwrite an exist rule, while application still
+                * have 2 rte_flow handles.
+                **/
+               if (ret && ret != ICE_ERR_DOES_NOT_EXIST) {
                        rte_flow_error_set(error, EINVAL,
                                        RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
                                        "rss flow destroy fail");
@@ -550,6 +607,9 @@ error:
 static void
 ice_hash_uninit(struct ice_adapter *ad)
 {
+       if (ad->hw.dcf_enabled)
+               return;
+
        if (ad->active_pkg_type == ICE_PKG_TYPE_OS_DEFAULT)
                ice_unregister_parser(&ice_hash_parser_os, ad);
        else if (ad->active_pkg_type == ICE_PKG_TYPE_COMMS)