net/iavf: improve default RSS
authorXuan Ding <xuan.ding@intel.com>
Wed, 23 Dec 2020 12:52:28 +0000 (12:52 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 8 Jan 2021 15:03:06 +0000 (16:03 +0100)
Add support to actively configure the RSS through port config.

Any kernel PF enabled default RSS will be disabled during
initialization.

Besides, default RSS will be configured based on
rte_eth_rss_conf->rss_hf.
Currently supported default rss_type: ipv4[6], ipv4[6]_udp, ipv4[6]_tcp,
ipv4[6]_sctp.

Signed-off-by: Xuan Ding <xuan.ding@intel.com>
Acked-by: Qi Zhang <qi.z.zhang@intel.com>
drivers/net/iavf/iavf.h
drivers/net/iavf/iavf_ethdev.c
drivers/net/iavf/iavf_hash.c
drivers/net/iavf/iavf_vchnl.c

index 6d5912d..9754273 100644 (file)
        VIRTCHNL_VF_OFFLOAD_RX_POLLING)
 
 #define IAVF_RSS_OFFLOAD_ALL ( \
+       ETH_RSS_IPV4 | \
        ETH_RSS_FRAG_IPV4 |         \
        ETH_RSS_NONFRAG_IPV4_TCP |  \
        ETH_RSS_NONFRAG_IPV4_UDP |  \
        ETH_RSS_NONFRAG_IPV4_SCTP | \
-       ETH_RSS_NONFRAG_IPV4_OTHER)
+       ETH_RSS_NONFRAG_IPV4_OTHER | \
+       ETH_RSS_IPV6 | \
+       ETH_RSS_FRAG_IPV6 | \
+       ETH_RSS_NONFRAG_IPV6_TCP | \
+       ETH_RSS_NONFRAG_IPV6_UDP | \
+       ETH_RSS_NONFRAG_IPV6_SCTP | \
+       ETH_RSS_NONFRAG_IPV6_OTHER)
 
 #define IAVF_MISC_VEC_ID                RTE_INTR_VEC_ZERO_OFFSET
 #define IAVF_RX_VEC_START               RTE_INTR_VEC_RXTX_OFFSET
@@ -153,6 +160,7 @@ struct iavf_info {
 
        uint8_t *rss_lut;
        uint8_t *rss_key;
+       uint64_t rss_hf;
        uint16_t nb_msix;   /* number of MSI-X interrupts on Rx */
        uint16_t msix_base; /* msix vector base from */
        uint16_t max_rss_qregion; /* max RSS queue region supported by PF */
@@ -321,6 +329,8 @@ int iavf_fdir_check(struct iavf_adapter *adapter,
                struct iavf_fdir_conf *filter);
 int iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
                         struct virtchnl_rss_cfg *rss_cfg, bool add);
+int iavf_set_hena(struct iavf_adapter *adapter, uint64_t hena);
+int iavf_rss_hash_set(struct iavf_adapter *ad, uint64_t rss_hf, bool add);
 int iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
                        struct rte_ether_addr *mc_addrs,
                        uint32_t mc_addrs_num, bool add);
index 7e3c26a..d2fa168 100644 (file)
@@ -267,10 +267,6 @@ iavf_init_rss(struct iavf_adapter *adapter)
                return ret;
        }
 
-       /* In IAVF, RSS enablement is set by PF driver. It is not supported
-        * to set based on rss_conf->rss_hf.
-        */
-
        /* configure RSS key */
        if (!rss_conf->rss_key) {
                /* Calculate the default hash key */
@@ -295,6 +291,13 @@ iavf_init_rss(struct iavf_adapter *adapter)
        if (ret)
                return ret;
 
+       /* Set RSS hash configuration based on rss_conf->rss_hf. */
+       ret = iavf_rss_hash_set(adapter, rss_conf->rss_hf, true);
+       if (ret) {
+               PMD_DRV_LOG(ERR, "fail to set default RSS");
+               return ret;
+       }
+
        return 0;
 }
 
@@ -1102,33 +1105,66 @@ iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
 }
 
 static int
-iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
-                       struct rte_eth_rss_conf *rss_conf)
+iavf_set_rss_key(struct iavf_adapter *adapter, uint8_t *key, uint8_t key_len)
 {
-       struct iavf_adapter *adapter =
-               IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
        struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 
-       if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
-               return -ENOTSUP;
-
        /* HENA setting, it is enabled by default, no change */
-       if (!rss_conf->rss_key || rss_conf->rss_key_len == 0) {
+       if (!key || key_len == 0) {
                PMD_DRV_LOG(DEBUG, "No key to be configured");
                return 0;
-       } else if (rss_conf->rss_key_len != vf->vf_res->rss_key_size) {
+       } else if (key_len != vf->vf_res->rss_key_size) {
                PMD_DRV_LOG(ERR, "The size of hash key configured "
                        "(%d) doesn't match the size of hardware can "
-                       "support (%d)", rss_conf->rss_key_len,
+                       "support (%d)", key_len,
                        vf->vf_res->rss_key_size);
                return -EINVAL;
        }
 
-       rte_memcpy(vf->rss_key, rss_conf->rss_key, rss_conf->rss_key_len);
+       rte_memcpy(vf->rss_key, key, key_len);
 
        return iavf_configure_rss_key(adapter);
 }
 
+static int
+iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
+                       struct rte_eth_rss_conf *rss_conf)
+{
+       struct iavf_adapter *adapter =
+               IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+       struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+       int ret;
+
+       adapter->eth_dev->data->dev_conf.rx_adv_conf.rss_conf = *rss_conf;
+
+       if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
+               return -ENOTSUP;
+
+       /* Set hash key. */
+       ret = iavf_set_rss_key(adapter, rss_conf->rss_key,
+                              rss_conf->rss_key_len);
+       if (ret)
+               return ret;
+
+       if (rss_conf->rss_hf == 0)
+               return 0;
+
+       /* Overwritten default RSS. */
+       ret = iavf_set_hena(adapter, 0);
+       if (ret)
+               PMD_DRV_LOG(ERR, "%s Remove rss vsi fail %d",
+                           __func__, ret);
+
+       /* Set new RSS configuration. */
+       ret = iavf_rss_hash_set(adapter, rss_conf->rss_hf, true);
+       if (ret) {
+               PMD_DRV_LOG(ERR, "fail to set new RSS");
+               return ret;
+       }
+
+       return 0;
+}
+
 static int
 iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
                          struct rte_eth_rss_conf *rss_conf)
@@ -1140,8 +1176,7 @@ iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
        if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
                return -ENOTSUP;
 
-        /* Just set it to default value now. */
-       rss_conf->rss_hf = IAVF_RSS_OFFLOAD_ALL;
+       rss_conf->rss_hf = vf->rss_hf;
 
        if (!rss_conf->rss_key)
                return 0;
@@ -2029,6 +2064,13 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
                return ret;
        }
 
+       /* Set hena = 0 to ask PF to cleanup all existing RSS. */
+       ret = iavf_set_hena(adapter, 0);
+       if (ret) {
+               PMD_DRV_LOG(ERR, "fail to disable default PF RSS");
+               return ret;
+       }
+
        return 0;
 }
 
index a20c33e..7620876 100644 (file)
@@ -443,17 +443,6 @@ static struct iavf_pattern_match_item iavf_hash_pattern_list[] = {
        {iavf_pattern_eth_ipv6_gtpc,                    ETH_RSS_IPV6,                   &ipv6_udp_gtpc_tmplt},
 };
 
-struct virtchnl_proto_hdrs *iavf_hash_default_hdrs[] = {
-       &inner_ipv4_tmplt,
-       &inner_ipv4_udp_tmplt,
-       &inner_ipv4_tcp_tmplt,
-       &inner_ipv4_sctp_tmplt,
-       &inner_ipv6_tmplt,
-       &inner_ipv6_udp_tmplt,
-       &inner_ipv6_tcp_tmplt,
-       &inner_ipv6_sctp_tmplt,
-};
-
 static struct iavf_flow_engine iavf_hash_engine = {
        .init = iavf_hash_init,
        .create = iavf_hash_create,
@@ -472,24 +461,64 @@ static struct iavf_flow_parser iavf_hash_parser = {
        .stage = IAVF_FLOW_STAGE_RSS,
 };
 
-static int
-iavf_hash_default_set(struct iavf_adapter *ad, bool add)
+int
+iavf_rss_hash_set(struct iavf_adapter *ad, uint64_t rss_hf, bool add)
 {
-       struct virtchnl_rss_cfg *rss_cfg;
-       uint16_t i;
+       struct iavf_info *vf =  IAVF_DEV_PRIVATE_TO_VF(ad);
+       struct virtchnl_rss_cfg rss_cfg;
+
+#define IAVF_RSS_HF_ALL ( \
+       ETH_RSS_IPV4 | \
+       ETH_RSS_IPV6 | \
+       ETH_RSS_NONFRAG_IPV4_UDP | \
+       ETH_RSS_NONFRAG_IPV6_UDP | \
+       ETH_RSS_NONFRAG_IPV4_TCP | \
+       ETH_RSS_NONFRAG_IPV6_TCP | \
+       ETH_RSS_NONFRAG_IPV4_SCTP | \
+       ETH_RSS_NONFRAG_IPV6_SCTP)
+
+       rss_cfg.rss_algorithm = VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC;
+       if (rss_hf & ETH_RSS_IPV4) {
+               rss_cfg.proto_hdrs = inner_ipv4_tmplt;
+               iavf_add_del_rss_cfg(ad, &rss_cfg, add);
+       }
 
-       rss_cfg = rte_zmalloc("iavf rss rule",
-                             sizeof(struct virtchnl_rss_cfg), 0);
-       if (!rss_cfg)
-               return -ENOMEM;
+       if (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) {
+               rss_cfg.proto_hdrs = inner_ipv4_udp_tmplt;
+               iavf_add_del_rss_cfg(ad, &rss_cfg, add);
+       }
 
-       for (i = 0; i < RTE_DIM(iavf_hash_default_hdrs); i++) {
-               rss_cfg->proto_hdrs = *iavf_hash_default_hdrs[i];
-               rss_cfg->rss_algorithm = VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC;
+       if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
+               rss_cfg.proto_hdrs = inner_ipv4_tcp_tmplt;
+               iavf_add_del_rss_cfg(ad, &rss_cfg, add);
+       }
 
-               iavf_add_del_rss_cfg(ad, rss_cfg, add);
+       if (rss_hf & ETH_RSS_NONFRAG_IPV4_SCTP) {
+               rss_cfg.proto_hdrs = inner_ipv4_sctp_tmplt;
+               iavf_add_del_rss_cfg(ad, &rss_cfg, add);
        }
 
+       if (rss_hf & ETH_RSS_IPV6) {
+               rss_cfg.proto_hdrs = inner_ipv6_tmplt;
+               iavf_add_del_rss_cfg(ad, &rss_cfg, add);
+       }
+
+       if (rss_hf & ETH_RSS_NONFRAG_IPV6_UDP) {
+               rss_cfg.proto_hdrs = inner_ipv6_udp_tmplt;
+               iavf_add_del_rss_cfg(ad, &rss_cfg, add);
+       }
+
+       if (rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) {
+               rss_cfg.proto_hdrs = inner_ipv6_tcp_tmplt;
+               iavf_add_del_rss_cfg(ad, &rss_cfg, add);
+       }
+
+       if (rss_hf & ETH_RSS_NONFRAG_IPV6_SCTP) {
+               rss_cfg.proto_hdrs = inner_ipv6_sctp_tmplt;
+               iavf_add_del_rss_cfg(ad, &rss_cfg, add);
+       }
+
+       vf->rss_hf = rss_hf & IAVF_RSS_HF_ALL;
        return 0;
 }
 
@@ -524,12 +553,6 @@ iavf_hash_init(struct iavf_adapter *ad)
                return ret;
        }
 
-       ret = iavf_hash_default_set(ad, true);
-       if (ret) {
-               PMD_DRV_LOG(ERR, "fail to set default RSS");
-               iavf_unregister_parser(parser, ad);
-       }
-
        return ret;
 }
 
@@ -1123,6 +1146,7 @@ static void
 iavf_hash_uninit(struct iavf_adapter *ad)
 {
        struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(ad);
+       struct rte_eth_rss_conf *rss_conf;
 
        if (vf->vf_reset)
                return;
@@ -1133,7 +1157,8 @@ iavf_hash_uninit(struct iavf_adapter *ad)
        if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF))
                return;
 
-       if (iavf_hash_default_set(ad, false))
+       rss_conf = &ad->eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
+       if (iavf_rss_hash_set(ad, rss_conf->rss_hf, false))
                PMD_DRV_LOG(ERR, "fail to delete default RSS");
 
        iavf_unregister_parser(&iavf_hash_parser, ad);
index c17ae06..25d5cda 100644 (file)
@@ -1343,6 +1343,29 @@ iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
        return err;
 }
 
+int
+iavf_set_hena(struct iavf_adapter *adapter, uint64_t hena)
+{
+       struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+       struct virtchnl_rss_hena vrh;
+       struct iavf_cmd_info args;
+       int err;
+
+       vrh.hena = hena;
+       args.ops = VIRTCHNL_OP_SET_RSS_HENA;
+       args.in_args = (u8 *)&vrh;
+       args.in_args_size = sizeof(vrh);
+       args.out_buffer = vf->aq_resp;
+       args.out_size = IAVF_AQ_BUF_SZ;
+
+       err = iavf_execute_vf_cmd(adapter, &args);
+       if (err)
+               PMD_DRV_LOG(ERR,
+                           "Failed to execute command of OP_SET_RSS_HENA");
+
+       return err;
+}
+
 int
 iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
                        struct rte_ether_addr *mc_addrs,