From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D63EC427F6 for ; Tue, 21 Mar 2023 10:24:29 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9557D42BC9; Tue, 21 Mar 2023 10:24:28 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 1110340A7F for ; Tue, 21 Mar 2023 10:24:26 +0100 (CET) Received: from kwepemm600004.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4PgmP84P8bzrVL7; Tue, 21 Mar 2023 17:23:24 +0800 (CST) Received: from localhost.localdomain (10.28.79.22) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Tue, 21 Mar 2023 17:24:24 +0800 From: Huisong Li To: , CC: , , , Subject: [PATCH 21.11 03/17] net/hns3: fix RSS key size compatibility Date: Tue, 21 Mar 2023 17:22:52 +0800 Message-ID: <20230321092306.16918-4-lihuisong@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20230321092306.16918-1-lihuisong@huawei.com> References: <20230321092306.16918-1-lihuisong@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.28.79.22] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600004.china.huawei.com (7.193.23.242) X-CFilter-Loop: Reflected X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org [ upstream commit 5172f9c464aa315a9d45b9177af71b4f99d55cdb ] For better compatibility, the RSS key size of PF and VF are obtained from firmware. However, the outdated HNS3_RSS_KEY_SIZE macro is still utilized in many locations as the key size. Fixes: 9c740336f024 ("net/hns3: get device specifications from firmware") Signed-off-by: Huisong Li Signed-off-by: Dongdong Liu --- drivers/net/hns3/hns3_common.c | 12 +++++++++++- drivers/net/hns3/hns3_flow.c | 26 ++++++++++++-------------- drivers/net/hns3/hns3_rss.c | 25 ++++++++++++------------- drivers/net/hns3/hns3_rss.h | 5 +++-- 4 files changed, 38 insertions(+), 30 deletions(-) diff --git a/drivers/net/hns3/hns3_common.c b/drivers/net/hns3/hns3_common.c index 2532c3b770..07e9b3f979 100644 --- a/drivers/net/hns3/hns3_common.c +++ b/drivers/net/hns3/hns3_common.c @@ -130,7 +130,7 @@ hns3_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info) }; info->reta_size = hw->rss_ind_tbl_size; - info->hash_key_size = HNS3_RSS_KEY_SIZE; + info->hash_key_size = hw->rss_key_size; info->flow_type_rss_offloads = HNS3_ETH_RSS_SUPPORT; info->default_rxportconf.burst_size = HNS3_DEFAULT_PORT_CONF_BURST_SIZE; @@ -827,6 +827,16 @@ hns3_check_dev_specifications(struct hns3_hw *hw) return -EINVAL; } + if (hw->rss_key_size == 0 || hw->rss_key_size > HNS3_RSS_KEY_SIZE_MAX) { + hns3_err(hw, "the RSS key size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)", + hw->rss_key_size, HNS3_RSS_KEY_SIZE_MAX); + return -EINVAL; + } + + if (hw->rss_key_size > HNS3_RSS_KEY_SIZE) + hns3_warn(hw, "the RSS key size obtained (%u) is greater than the default key size (%u)", + hw->rss_key_size, HNS3_RSS_KEY_SIZE); + return 0; } diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c index 617a6e5a71..97ea4e4de7 100644 --- a/drivers/net/hns3/hns3_flow.c +++ b/drivers/net/hns3/hns3_flow.c @@ -1355,10 +1355,10 @@ hns3_parse_rss_filter(struct rte_eth_dev *dev, return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION_CONF, act, "a nonzero RSS encapsulation level is not supported"); - if (rss->key_len && rss->key_len != RTE_DIM(rss_conf->key)) + if (rss->key_len && rss->key_len != hw->rss_key_size) return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION_CONF, act, - "RSS hash key must be exactly 40 bytes"); + "invalid RSS key length"); if (!hns3_rss_input_tuple_supported(hw, rss)) return rte_flow_error_set(error, EINVAL, @@ -1390,16 +1390,6 @@ hns3_disable_rss(struct hns3_hw *hw) return 0; } -static void -hns3_parse_rss_key(struct hns3_hw *hw, struct rte_flow_action_rss *rss_conf) -{ - if (rss_conf->key == NULL || rss_conf->key_len < HNS3_RSS_KEY_SIZE) { - hns3_warn(hw, "Default RSS hash key to be set"); - rss_conf->key = hns3_hash_key; - rss_conf->key_len = HNS3_RSS_KEY_SIZE; - } -} - static int hns3_parse_rss_algorithm(struct hns3_hw *hw, enum rte_eth_hash_function *func, uint8_t *hash_algo) @@ -1432,9 +1422,16 @@ hns3_parse_rss_algorithm(struct hns3_hw *hw, enum rte_eth_hash_function *func, static int hns3_hw_rss_hash_set(struct hns3_hw *hw, struct rte_flow_action_rss *rss_config) { + uint8_t rss_key[HNS3_RSS_KEY_SIZE_MAX] = {0}; + bool use_default_key = false; int ret; - hns3_parse_rss_key(hw, rss_config); + if (rss_config->key == NULL || rss_config->key_len != hw->rss_key_size) { + hns3_warn(hw, "Default RSS hash key to be set"); + memcpy(rss_key, hns3_hash_key, + RTE_MIN(sizeof(hns3_hash_key), hw->rss_key_size)); + use_default_key = true; + } ret = hns3_parse_rss_algorithm(hw, &rss_config->func, &hw->rss_info.hash_algo); @@ -1442,7 +1439,8 @@ hns3_hw_rss_hash_set(struct hns3_hw *hw, struct rte_flow_action_rss *rss_config) return ret; ret = hns3_rss_set_algo_key(hw, hw->rss_info.hash_algo, - rss_config->key, HNS3_RSS_KEY_SIZE); + use_default_key ? rss_key : rss_config->key, + hw->rss_key_size); if (ret) return ret; diff --git a/drivers/net/hns3/hns3_rss.c b/drivers/net/hns3/hns3_rss.c index 67e33a2765..bf031e6ad7 100644 --- a/drivers/net/hns3/hns3_rss.c +++ b/drivers/net/hns3/hns3_rss.c @@ -10,7 +10,7 @@ #include "hns3_logs.h" /* Default hash keys */ -const uint8_t hns3_hash_key[] = { +const uint8_t hns3_hash_key[HNS3_RSS_KEY_SIZE] = { 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2, 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0, 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4, @@ -317,7 +317,7 @@ hns3_rss_set_algo_key(struct hns3_hw *hw, uint8_t hash_algo, } } /* Update the shadow RSS key with user specified */ - memcpy(hw->rss_info.key, key, HNS3_RSS_KEY_SIZE); + memcpy(hw->rss_info.key, key, hw->rss_key_size); return 0; } @@ -553,9 +553,9 @@ hns3_dev_rss_hash_update(struct rte_eth_dev *dev, uint8_t *key = rss_conf->rss_key; int ret; - if (key && key_len != HNS3_RSS_KEY_SIZE) { + if (key && key_len != hw->rss_key_size) { hns3_err(hw, "the hash key len(%u) is invalid, must be %u", - key_len, HNS3_RSS_KEY_SIZE); + key_len, hw->rss_key_size); return -EINVAL; } @@ -566,7 +566,7 @@ hns3_dev_rss_hash_update(struct rte_eth_dev *dev, if (key) { ret = hns3_rss_set_algo_key(hw, hw->rss_info.hash_algo, - key, HNS3_RSS_KEY_SIZE); + key, hw->rss_key_size); if (ret) goto set_algo_key_fail; } @@ -602,9 +602,9 @@ 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 && 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; + if (rss_conf->rss_key && rss_conf->rss_key_len >= hw->rss_key_size) { + memcpy(rss_conf->rss_key, rss_cfg->key, hw->rss_key_size); + rss_conf->rss_key_len = hw->rss_key_size; } rte_spinlock_unlock(&hw->lock); @@ -824,8 +824,8 @@ hns3_rss_set_default_args(struct hns3_hw *hw) /* Default hash algorithm */ rss_cfg->conf.func = RTE_ETH_HASH_FUNCTION_TOEPLITZ; - /* Default RSS key */ - memcpy(rss_cfg->key, hns3_hash_key, HNS3_RSS_KEY_SIZE); + memcpy(rss_cfg->key, hns3_hash_key, + RTE_MIN(sizeof(hns3_hash_key), hw->rss_key_size)); /* Initialize RSS indirection table */ for (i = 0; i < hw->rss_ind_tbl_size; i++) @@ -858,9 +858,8 @@ hns3_config_rss(struct hns3_adapter *hns) break; } - /* Configure RSS hash algorithm and hash key */ - ret = hns3_rss_set_algo_key(hw, hw->rss_info.hash_algo, hash_key, - HNS3_RSS_KEY_SIZE); + ret = hns3_rss_set_algo_key(hw, rss_cfg->hash_algo, + hash_key, hw->rss_key_size); if (ret) return ret; diff --git a/drivers/net/hns3/hns3_rss.h b/drivers/net/hns3/hns3_rss.h index bc5b14e17b..68069d6120 100644 --- a/drivers/net/hns3/hns3_rss.h +++ b/drivers/net/hns3/hns3_rss.h @@ -28,6 +28,7 @@ #define HNS3_RSS_IND_TBL_SIZE 512 /* The size of hash lookup table */ #define HNS3_RSS_IND_TBL_SIZE_MAX 2048 #define HNS3_RSS_KEY_SIZE 40 +#define HNS3_RSS_KEY_SIZE_MAX 128 #define HNS3_RSS_SET_BITMAP_MSK 0xffff #define HNS3_RSS_HASH_ALGO_TOEPLITZ 0 @@ -44,7 +45,7 @@ struct hns3_rss_conf { /* RSS parameters :algorithm, flow_types, key, queue */ struct rte_flow_action_rss conf; uint8_t hash_algo; /* hash function type defined by hardware */ - uint8_t key[HNS3_RSS_KEY_SIZE]; /* Hash key */ + uint8_t key[HNS3_RSS_KEY_SIZE_MAX]; /* Hash key */ uint16_t rss_indirection_tbl[HNS3_RSS_IND_TBL_SIZE_MAX]; uint16_t queue[HNS3_RSS_QUEUES_BUFFER_NUM]; /* Queues indices to use */ bool valid; /* check if RSS rule is valid */ @@ -90,7 +91,7 @@ static inline uint32_t roundup_pow_of_two(uint32_t x) return 1UL << fls(x - 1); } -extern const uint8_t hns3_hash_key[]; +extern const uint8_t hns3_hash_key[HNS3_RSS_KEY_SIZE]; struct hns3_adapter; -- 2.22.0