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 10182A0566 for ; Sat, 12 Nov 2022 08:57:29 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D811840150; Sat, 12 Nov 2022 08:57:28 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 31A244003F for ; Sat, 12 Nov 2022 08:57:25 +0100 (CET) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N8SbB3bMMzRp6d for ; Sat, 12 Nov 2022 15:57:10 +0800 (CST) Received: from kwepemm600004.china.huawei.com (7.193.23.242) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 12 Nov 2022 15:57:24 +0800 Received: from localhost.localdomain (10.69.192.56) 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.2375.31; Sat, 12 Nov 2022 15:57:23 +0800 From: Huisong Li To: , CC: , , , Subject: [PATCH 20.11 1/3] net/hns3: extract functions to create RSS and FDIR flow rule Date: Sat, 12 Nov 2022 15:57:48 +0800 Message-ID: <20221112075750.55623-2-lihuisong@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20221112075750.55623-1-lihuisong@huawei.com> References: <20221112075750.55623-1-lihuisong@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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 c48499171f5df62a71697dce517b9fa22bc30985 ] Extract two functions to create the RSS and FDIR flow rule for clearer code logic. Signed-off-by: Huisong Li Acked-by: Min Hu (Connor) --- drivers/net/hns3/hns3_flow.c | 174 +++++++++++++++++++++-------------- 1 file changed, 106 insertions(+), 68 deletions(-) diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c index b1317d7311..13a795b1f0 100644 --- a/drivers/net/hns3/hns3_flow.c +++ b/drivers/net/hns3/hns3_flow.c @@ -1722,6 +1722,105 @@ hns3_flow_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, return hns3_parse_fdir_filter(dev, pattern, actions, &fdir_rule, error); } +static int +hns3_flow_create_rss_rule(struct rte_eth_dev *dev, + const struct rte_flow_action *act, + struct rte_flow *flow) +{ + struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct hns3_rss_conf_ele *rss_filter_ptr; + const struct hns3_rss_conf *rss_conf; + int ret; + + rss_filter_ptr = rte_zmalloc("hns3 rss filter", + sizeof(struct hns3_rss_conf_ele), 0); + if (rss_filter_ptr == NULL) { + hns3_err(hw, "failed to allocate hns3_rss_filter memory"); + return -ENOMEM; + } + + /* + * After all the preceding tasks are successfully configured, configure + * rules to the hardware to simplify the rollback of rules in the + * hardware. + */ + rss_conf = (const struct hns3_rss_conf *)act->conf; + ret = hns3_flow_parse_rss(dev, rss_conf, true); + if (ret != 0) { + rte_free(rss_filter_ptr); + return ret; + } + + hns3_rss_conf_copy(&rss_filter_ptr->filter_info, &rss_conf->conf); + rss_filter_ptr->filter_info.valid = true; + TAILQ_INSERT_TAIL(&hw->flow_rss_list, rss_filter_ptr, entries); + flow->rule = rss_filter_ptr; + flow->filter_type = RTE_ETH_FILTER_HASH; + + return 0; +} + +static int +hns3_flow_create_fdir_rule(struct rte_eth_dev *dev, + const struct rte_flow_item pattern[], + const struct rte_flow_action actions[], + struct rte_flow_error *error, + struct rte_flow *flow) +{ + struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw); + struct hns3_fdir_rule_ele *fdir_rule_ptr; + struct hns3_fdir_rule fdir_rule; + int ret; + + memset(&fdir_rule, 0, sizeof(struct hns3_fdir_rule)); + ret = hns3_parse_fdir_filter(dev, pattern, actions, &fdir_rule, error); + if (ret != 0) + return ret; + + if (fdir_rule.flags & HNS3_RULE_FLAG_COUNTER) { + ret = hns3_counter_new(dev, fdir_rule.act_cnt.shared, + fdir_rule.act_cnt.id, error); + if (ret != 0) + return ret; + + flow->counter_id = fdir_rule.act_cnt.id; + } + + fdir_rule_ptr = rte_zmalloc("hns3 fdir rule", + sizeof(struct hns3_fdir_rule_ele), 0); + if (fdir_rule_ptr == NULL) { + hns3_err(hw, "failed to allocate fdir_rule memory."); + ret = -ENOMEM; + goto err_malloc; + } + + /* + * After all the preceding tasks are successfully configured, configure + * rules to the hardware to simplify the rollback of rules in the + * hardware. + */ + ret = hns3_fdir_filter_program(hns, &fdir_rule, false); + if (ret != 0) + goto err_fdir_filter; + + memcpy(&fdir_rule_ptr->fdir_conf, &fdir_rule, + sizeof(struct hns3_fdir_rule)); + TAILQ_INSERT_TAIL(&hw->flow_fdir_list, fdir_rule_ptr, entries); + flow->rule = fdir_rule_ptr; + flow->filter_type = RTE_ETH_FILTER_FDIR; + + return 0; + +err_fdir_filter: + rte_free(fdir_rule_ptr); +err_malloc: + if (fdir_rule.flags & HNS3_RULE_FLAG_COUNTER) + hns3_counter_release(dev, fdir_rule.act_cnt.id); + + return ret; +} + /* * Create or destroy a flow rule. * Theorically one rule can match more than one filters. @@ -1736,13 +1835,9 @@ hns3_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, { struct hns3_adapter *hns = dev->data->dev_private; struct hns3_hw *hw = &hns->hw; - const struct hns3_rss_conf *rss_conf; - struct hns3_fdir_rule_ele *fdir_rule_ptr; - struct hns3_rss_conf_ele *rss_filter_ptr; struct hns3_flow_mem *flow_node; const struct rte_flow_action *act; struct rte_flow *flow; - struct hns3_fdir_rule fdir_rule; int ret; ret = hns3_flow_validate(dev, attr, pattern, actions, error); @@ -1768,77 +1863,20 @@ hns3_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, TAILQ_INSERT_TAIL(&hw->flow_list, flow_node, entries); act = hns3_find_rss_general_action(pattern, actions); - if (act) { - rss_conf = act->conf; - - ret = hns3_flow_parse_rss(dev, rss_conf, true); - if (ret) - goto err; - - rss_filter_ptr = rte_zmalloc("hns3 rss filter", - sizeof(struct hns3_rss_conf_ele), - 0); - if (rss_filter_ptr == NULL) { - hns3_err(hw, - "Failed to allocate hns3_rss_filter memory"); - ret = -ENOMEM; - goto err; - } - hns3_rss_conf_copy(&rss_filter_ptr->filter_info, - &rss_conf->conf); - rss_filter_ptr->filter_info.valid = true; - TAILQ_INSERT_TAIL(&hw->flow_rss_list, rss_filter_ptr, entries); - - flow->rule = rss_filter_ptr; - flow->filter_type = RTE_ETH_FILTER_HASH; - return flow; - } - - memset(&fdir_rule, 0, sizeof(struct hns3_fdir_rule)); - ret = hns3_parse_fdir_filter(dev, pattern, actions, &fdir_rule, error); - if (ret) - goto out; - - if (fdir_rule.flags & HNS3_RULE_FLAG_COUNTER) { - ret = hns3_counter_new(dev, fdir_rule.act_cnt.shared, - fdir_rule.act_cnt.id, error); - if (ret) - goto out; - - flow->counter_id = fdir_rule.act_cnt.id; - } - - fdir_rule_ptr = rte_zmalloc("hns3 fdir rule", - sizeof(struct hns3_fdir_rule_ele), - 0); - if (fdir_rule_ptr == NULL) { - hns3_err(hw, "failed to allocate fdir_rule memory."); - ret = -ENOMEM; - goto err_fdir; - } - - ret = hns3_fdir_filter_program(hns, &fdir_rule, false); - if (!ret) { - memcpy(&fdir_rule_ptr->fdir_conf, &fdir_rule, - sizeof(struct hns3_fdir_rule)); - TAILQ_INSERT_TAIL(&hw->flow_fdir_list, fdir_rule_ptr, entries); - flow->rule = fdir_rule_ptr; - flow->filter_type = RTE_ETH_FILTER_FDIR; - + if (act) + ret = hns3_flow_create_rss_rule(dev, act, flow); + else + ret = hns3_flow_create_fdir_rule(dev, pattern, actions, + error, flow); + if (ret == 0) return flow; - } - rte_free(fdir_rule_ptr); -err_fdir: - if (fdir_rule.flags & HNS3_RULE_FLAG_COUNTER) - hns3_counter_release(dev, fdir_rule.act_cnt.id); -err: rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, "Failed to create flow"); -out: TAILQ_REMOVE(&hw->flow_list, flow_node, entries); rte_free(flow_node); rte_free(flow); + return NULL; } -- 2.33.0