net/ice: fix GTPU TEID hash
[dpdk.git] / drivers / net / hns3 / hns3_rss.c
index b8c20e6..247bd7d 100644 (file)
@@ -28,7 +28,7 @@ static const uint8_t hns3_hash_key[] = {
  * Used to set algorithm, key_offset and hash key of rss.
  */
 int
-hns3_set_rss_algo_key(struct hns3_hw *hw, uint8_t hash_algo, const uint8_t *key)
+hns3_set_rss_algo_key(struct hns3_hw *hw, const uint8_t *key)
 {
 #define HNS3_KEY_OFFSET_MAX    3
 #define HNS3_SET_HASH_KEY_BYTE_FOUR    2
@@ -51,7 +51,8 @@ hns3_set_rss_algo_key(struct hns3_hw *hw, uint8_t hash_algo, const uint8_t *key)
                hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_GENERIC_CONFIG,
                                          false);
 
-               req->hash_config |= (hash_algo & HNS3_RSS_HASH_ALGO_MASK);
+               req->hash_config |=
+                       (hw->rss_info.hash_algo & HNS3_RSS_HASH_ALGO_MASK);
                req->hash_config |= (key_offset << HNS3_RSS_HASH_KEY_OFFSET_B);
 
                if (key_offset == HNS3_SET_HASH_KEY_BYTE_FOUR)
@@ -127,7 +128,7 @@ hns3_set_rss_indir_table(struct hns3_hw *hw, uint8_t *indir, uint16_t size)
                req->rss_set_bitmap = rte_cpu_to_le_16(HNS3_RSS_SET_BITMAP_MSK);
                for (j = 0; j < HNS3_RSS_CFG_TBL_SIZE; j++) {
                        num = i * HNS3_RSS_CFG_TBL_SIZE + j;
-                       req->rss_result[j] = indir[num] % hw->alloc_rss_size;
+                       req->rss_result[j] = indir[num];
                }
                ret = hns3_cmd_send(hw, &desc, 1);
                if (ret) {
@@ -211,7 +212,11 @@ hns3_set_rss_tuple_by_rss_hf(struct hns3_hw *hw,
                        req->ipv6_fragment_en |= HNS3_IP_OTHER_BIT_MASK;
                        break;
                default:
-                       /* Other unsupported flow types won't change tuples */
+                       /*
+                        * rss_hf doesn't include unsupported flow types
+                        * because the API framework has checked it, and
+                        * this branch will never go unless rss_hf is zero.
+                        */
                        break;
                }
        }
@@ -251,12 +256,14 @@ hns3_dev_rss_hash_update(struct rte_eth_dev *dev,
        struct hns3_hw *hw = &hns->hw;
        struct hns3_rss_tuple_cfg *tuple = &hw->rss_info.rss_tuple_sets;
        struct hns3_rss_conf *rss_cfg = &hw->rss_info;
-       uint8_t algo = rss_cfg->conf.func;
        uint8_t key_len = rss_conf->rss_key_len;
        uint64_t rss_hf = rss_conf->rss_hf;
        uint8_t *key = rss_conf->rss_key;
        int ret;
 
+       if (hw->rss_dis_flag)
+               return -EINVAL;
+
        rte_spinlock_lock(&hw->lock);
        ret = hns3_set_rss_tuple_by_rss_hf(hw, tuple, rss_hf);
        if (ret)
@@ -285,7 +292,7 @@ hns3_dev_rss_hash_update(struct rte_eth_dev *dev,
                        ret = -EINVAL;
                        goto conf_err;
                }
-               ret = hns3_set_rss_algo_key(hw, algo, key);
+               ret = hns3_set_rss_algo_key(hw, key);
                if (ret)
                        goto conf_err;
        }
@@ -319,8 +326,10 @@ hns3_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
        rss_conf->rss_hf = rss_cfg->conf.types;
 
        /* Get the RSS Key required by the user */
-       if (rss_conf->rss_key)
+       if (rss_conf->rss_key && rss_conf->rss_key_len >= HNS3_RSS_KEY_SIZE) {
                memcpy(rss_conf->rss_key, rss_cfg->key, HNS3_RSS_KEY_SIZE);
+               rss_conf->rss_key_len = HNS3_RSS_KEY_SIZE;
+       }
        rte_spinlock_unlock(&hw->lock);
 
        return 0;
@@ -417,7 +426,7 @@ hns3_dev_rss_reta_query(struct rte_eth_dev *dev,
                shift = i % RTE_RETA_GROUP_SIZE;
                if (reta_conf[idx].mask & (1ULL << shift))
                        reta_conf[idx].reta[shift] =
-                         rss_cfg->rss_indirection_tbl[i] % hw->alloc_rss_size;
+                                               rss_cfg->rss_indirection_tbl[i];
        }
        rte_spinlock_unlock(&hw->lock);
        return 0;
@@ -500,7 +509,9 @@ hns3_set_default_rss_args(struct hns3_hw *hw)
        int i;
 
        /* Default hash algorithm */
-       rss_cfg->conf.func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
+       rss_cfg->conf.func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
+
+       /* Default RSS key */
        memcpy(rss_cfg->key, hns3_hash_key, HNS3_RSS_KEY_SIZE);
 
        /* Initialize RSS indirection table */
@@ -516,20 +527,29 @@ hns3_config_rss(struct hns3_adapter *hns)
 {
        struct hns3_hw *hw = &hns->hw;
        struct hns3_rss_conf *rss_cfg = &hw->rss_info;
-       uint8_t hash_algo =
-               (hw->rss_info.conf.func == RTE_ETH_HASH_FUNCTION_TOEPLITZ ?
-                HNS3_RSS_HASH_ALGO_TOEPLITZ : HNS3_RSS_HASH_ALGO_SIMPLE);
        uint8_t *hash_key = rss_cfg->key;
        int ret, ret1;
 
        enum rte_eth_rx_mq_mode mq_mode = hw->data->dev_conf.rxmode.mq_mode;
 
-       /* When there is no open RSS, redirect the packet queue 0 */
+       switch (hw->rss_info.conf.func) {
+       case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
+               hw->rss_info.hash_algo = HNS3_RSS_HASH_ALGO_SIMPLE;
+               break;
+       case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
+               hw->rss_info.hash_algo = HNS3_RSS_HASH_ALGO_SYMMETRIC_TOEP;
+               break;
+       default:
+               hw->rss_info.hash_algo = HNS3_RSS_HASH_ALGO_TOEPLITZ;
+               break;
+       }
+
+       /* When RSS is off, redirect the packet queue 0 */
        if (((uint32_t)mq_mode & ETH_MQ_RX_RSS_FLAG) == 0)
                hns3_rss_uninit(hns);
 
        /* Configure RSS hash algorithm and hash key offset */
-       ret = hns3_set_rss_algo_key(hw, hash_algo, hash_key);
+       ret = hns3_set_rss_algo_key(hw, hash_key);
        if (ret)
                return ret;
 
@@ -538,10 +558,16 @@ hns3_config_rss(struct hns3_adapter *hns)
        if (ret)
                return ret;
 
-       ret = hns3_set_rss_indir_table(hw, rss_cfg->rss_indirection_tbl,
-                                      HNS3_RSS_IND_TBL_SIZE);
-       if (ret)
-               goto rss_tuple_uninit;
+       /*
+        * When RSS is off, it doesn't need to configure rss redirection table
+        * to hardware.
+        */
+       if (((uint32_t)mq_mode & ETH_MQ_RX_RSS_FLAG)) {
+               ret = hns3_set_rss_indir_table(hw, rss_cfg->rss_indirection_tbl,
+                                              HNS3_RSS_IND_TBL_SIZE);
+               if (ret)
+                       goto rss_tuple_uninit;
+       }
 
        ret = hns3_set_rss_tc_mode(hw);
        if (ret)
@@ -550,9 +576,11 @@ hns3_config_rss(struct hns3_adapter *hns)
        return ret;
 
 rss_indir_table_uninit:
-       ret1 = hns3_rss_reset_indir_table(hw);
-       if (ret1 != 0)
-               return ret;
+       if (((uint32_t)mq_mode & ETH_MQ_RX_RSS_FLAG)) {
+               ret1 = hns3_rss_reset_indir_table(hw);
+               if (ret1 != 0)
+                       return ret;
+       }
 
 rss_tuple_uninit:
        hns3_rss_tuple_uninit(hw);