diff --git a/0022-net-hns3-remove-unnecessary-assignment.patch b/0022-net-hns3-remove-unnecessary-assignment.patch new file mode 100644 index 0000000000000000000000000000000000000000..dd750979cd3d4c3f37010dbc21af2ceaf9f37d59 --- /dev/null +++ b/0022-net-hns3-remove-unnecessary-assignment.patch @@ -0,0 +1,28 @@ +From b70e96833a753239454c660b71cbab6e0dcbbeae Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Sat, 22 Jan 2022 09:51:28 +0800 +Subject: [PATCH] net/hns3: remove unnecessary assignment + +Remove unnecessary assignment. + +Signed-off-by: Huisong Li +Acked-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_flow.c | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c +index 0dbc3f6502..5f2b279546 100644 +--- a/drivers/net/hns3/hns3_flow.c ++++ b/drivers/net/hns3/hns3_flow.c +@@ -1890,7 +1890,6 @@ hns3_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow, + } + } + rte_free(flow); +- flow = NULL; + + return 0; + } +-- +2.33.0 + diff --git a/0023-net-hns3-fix-using-enum-as-boolean.patch b/0023-net-hns3-fix-using-enum-as-boolean.patch new file mode 100644 index 0000000000000000000000000000000000000000..80ee21dc97cfbf1557239dfa1bb7f335adc00be9 --- /dev/null +++ b/0023-net-hns3-fix-using-enum-as-boolean.patch @@ -0,0 +1,34 @@ +From 67d0b17947d6936147f4cbfff6ff938884f14776 Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Sat, 22 Jan 2022 09:51:29 +0800 +Subject: [PATCH] net/hns3: fix using enum as boolean + +The enum type variables cannot be used as bool variables. This patch +fixes for "with->func" in hns3_action_rss_same(). + +Fixes: eb158fc756a5 ("net/hns3: fix config when creating RSS rule after flush") +Cc: stable@dpdk.org + +Signed-off-by: Huisong Li +Acked-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_flow.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c +index 5f2b279546..00084872ad 100644 +--- a/drivers/net/hns3/hns3_flow.c ++++ b/drivers/net/hns3/hns3_flow.c +@@ -1251,7 +1251,8 @@ hns3_action_rss_same(const struct rte_flow_action_rss *comp, + if (comp->func == RTE_ETH_HASH_FUNCTION_MAX) + func_is_same = false; + else +- func_is_same = with->func ? (comp->func == with->func) : true; ++ func_is_same = (with->func != RTE_ETH_HASH_FUNCTION_DEFAULT) ? ++ (comp->func == with->func) : true; + + return (func_is_same && + comp->types == (with->types & HNS3_ETH_RSS_SUPPORT) && +-- +2.33.0 + diff --git a/0024-net-hns3-extract-common-function-to-initialize-MAC-a.patch b/0024-net-hns3-extract-common-function-to-initialize-MAC-a.patch new file mode 100644 index 0000000000000000000000000000000000000000..af051287a8908a6d50948b94d6895b39bbdf7ccf --- /dev/null +++ b/0024-net-hns3-extract-common-function-to-initialize-MAC-a.patch @@ -0,0 +1,205 @@ +From 2665a92054019bdb73cd2c43e5a581d081772915 Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Sat, 22 Jan 2022 09:51:30 +0800 +Subject: [PATCH] net/hns3: extract common function to initialize MAC address + +The code logic to initialize "data->mac_addrs" for PF and VF is similar. +This patch extracts a common API to initialize it to improve code +maintainability. + +Signed-off-by: Huisong Li +Acked-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_common.c | 54 +++++++++++++++++++++++++++++++ + drivers/net/hns3/hns3_common.h | 1 + + drivers/net/hns3/hns3_ethdev.c | 31 +++--------------- + drivers/net/hns3/hns3_ethdev_vf.c | 33 +++---------------- + 4 files changed, 63 insertions(+), 56 deletions(-) + +diff --git a/drivers/net/hns3/hns3_common.c b/drivers/net/hns3/hns3_common.c +index 78158401f2..0f39d51a87 100644 +--- a/drivers/net/hns3/hns3_common.c ++++ b/drivers/net/hns3/hns3_common.c +@@ -587,6 +587,60 @@ hns3_remove_mac_addr(struct rte_eth_dev *dev, uint32_t idx) + } + } + ++int ++hns3_init_mac_addrs(struct rte_eth_dev *dev) ++{ ++ struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private); ++ struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw); ++ const char *memory_name = hns->is_vf ? "hns3vf-mac" : "hns3-mac"; ++ uint16_t mac_addrs_capa = hns->is_vf ? HNS3_VF_UC_MACADDR_NUM : ++ HNS3_UC_MACADDR_NUM; ++ char mac_str[RTE_ETHER_ADDR_FMT_SIZE]; ++ struct rte_ether_addr *eth_addr; ++ ++ /* Allocate memory for storing MAC addresses */ ++ dev->data->mac_addrs = rte_zmalloc(memory_name, ++ sizeof(struct rte_ether_addr) * mac_addrs_capa, ++ 0); ++ if (dev->data->mac_addrs == NULL) { ++ hns3_err(hw, "failed to allocate %zx bytes needed to store MAC addresses", ++ sizeof(struct rte_ether_addr) * mac_addrs_capa); ++ return -ENOMEM; ++ } ++ ++ eth_addr = (struct rte_ether_addr *)hw->mac.mac_addr; ++ if (!hns->is_vf) { ++ if (!rte_is_valid_assigned_ether_addr(eth_addr)) { ++ rte_eth_random_addr(hw->mac.mac_addr); ++ hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE, ++ (struct rte_ether_addr *)hw->mac.mac_addr); ++ hns3_warn(hw, "default mac_addr from firmware is an invalid " ++ "unicast address, using random MAC address %s", ++ mac_str); ++ } ++ } else { ++ /* ++ * The hns3 PF ethdev driver in kernel support setting VF MAC ++ * address on the host by "ip link set ..." command. To avoid ++ * some incorrect scenes, for example, hns3 VF PMD driver fails ++ * to receive and send packets after user configure the MAC ++ * address by using the "ip link set ..." command, hns3 VF PMD ++ * driver keep the same MAC address strategy as the hns3 kernel ++ * ethdev driver in the initialization. If user configure a MAC ++ * address by the ip command for VF device, then hns3 VF PMD ++ * driver will start with it, otherwise start with a random MAC ++ * address in the initialization. ++ */ ++ if (rte_is_zero_ether_addr(eth_addr)) ++ rte_eth_random_addr(hw->mac.mac_addr); ++ } ++ ++ rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.mac_addr, ++ &dev->data->mac_addrs[0]); ++ ++ return 0; ++} ++ + int + hns3_init_ring_with_vector(struct hns3_hw *hw) + { +diff --git a/drivers/net/hns3/hns3_common.h b/drivers/net/hns3/hns3_common.h +index 0dbb1c0413..a9e8a9cccf 100644 +--- a/drivers/net/hns3/hns3_common.h ++++ b/drivers/net/hns3/hns3_common.h +@@ -52,6 +52,7 @@ int hns3_set_mc_mac_addr_list(struct rte_eth_dev *dev, + uint32_t nb_mc_addr); + void hns3_ether_format_addr(char *buf, uint16_t size, + const struct rte_ether_addr *ether_addr); ++int hns3_init_mac_addrs(struct rte_eth_dev *dev); + + int hns3_init_ring_with_vector(struct hns3_hw *hw); + int hns3_map_rx_interrupt(struct rte_eth_dev *dev); +diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c +index ef13d31d19..722660d0cc 100644 +--- a/drivers/net/hns3/hns3_ethdev.c ++++ b/drivers/net/hns3/hns3_ethdev.c +@@ -6617,8 +6617,6 @@ static int + hns3_dev_init(struct rte_eth_dev *eth_dev) + { + struct hns3_adapter *hns = eth_dev->data->dev_private; +- char mac_str[RTE_ETHER_ADDR_FMT_SIZE]; +- struct rte_ether_addr *eth_addr; + struct hns3_hw *hw = &hns->hw; + int ret; + +@@ -6661,30 +6659,9 @@ hns3_dev_init(struct rte_eth_dev *eth_dev) + goto err_init_pf; + } + +- /* Allocate memory for storing MAC addresses */ +- eth_dev->data->mac_addrs = rte_zmalloc("hns3-mac", +- sizeof(struct rte_ether_addr) * +- HNS3_UC_MACADDR_NUM, 0); +- if (eth_dev->data->mac_addrs == NULL) { +- PMD_INIT_LOG(ERR, "Failed to allocate %zx bytes needed " +- "to store MAC addresses", +- sizeof(struct rte_ether_addr) * +- HNS3_UC_MACADDR_NUM); +- ret = -ENOMEM; +- goto err_rte_zmalloc; +- } +- +- eth_addr = (struct rte_ether_addr *)hw->mac.mac_addr; +- if (!rte_is_valid_assigned_ether_addr(eth_addr)) { +- rte_eth_random_addr(hw->mac.mac_addr); +- hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE, +- (struct rte_ether_addr *)hw->mac.mac_addr); +- hns3_warn(hw, "default mac_addr from firmware is an invalid " +- "unicast address, using random MAC address %s", +- mac_str); +- } +- rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.mac_addr, +- ð_dev->data->mac_addrs[0]); ++ ret = hns3_init_mac_addrs(eth_dev); ++ if (ret != 0) ++ goto err_init_mac_addrs; + + hw->adapter_state = HNS3_NIC_INITIALIZED; + +@@ -6700,7 +6677,7 @@ hns3_dev_init(struct rte_eth_dev *eth_dev) + hns3_info(hw, "hns3 dev initialization successful!"); + return 0; + +-err_rte_zmalloc: ++err_init_mac_addrs: + hns3_uninit_pf(eth_dev); + + err_init_pf: +diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c +index 5015fe0d5f..5a1286e17b 100644 +--- a/drivers/net/hns3/hns3_ethdev_vf.c ++++ b/drivers/net/hns3/hns3_ethdev_vf.c +@@ -2400,34 +2400,9 @@ hns3vf_dev_init(struct rte_eth_dev *eth_dev) + goto err_init_vf; + } + +- /* Allocate memory for storing MAC addresses */ +- eth_dev->data->mac_addrs = rte_zmalloc("hns3vf-mac", +- sizeof(struct rte_ether_addr) * +- HNS3_VF_UC_MACADDR_NUM, 0); +- if (eth_dev->data->mac_addrs == NULL) { +- PMD_INIT_LOG(ERR, "Failed to allocate %zx bytes needed " +- "to store MAC addresses", +- sizeof(struct rte_ether_addr) * +- HNS3_VF_UC_MACADDR_NUM); +- ret = -ENOMEM; +- goto err_rte_zmalloc; +- } +- +- /* +- * The hns3 PF ethdev driver in kernel support setting VF MAC address +- * on the host by "ip link set ..." command. To avoid some incorrect +- * scenes, for example, hns3 VF PMD fails to receive and send +- * packets after user configure the MAC address by using the +- * "ip link set ..." command, hns3 VF PMD keep the same MAC +- * address strategy as the hns3 kernel ethdev driver in the +- * initialization. If user configure a MAC address by the ip command +- * for VF device, then hns3 VF PMD will start with it, otherwise +- * start with a random MAC address in the initialization. +- */ +- if (rte_is_zero_ether_addr((struct rte_ether_addr *)hw->mac.mac_addr)) +- rte_eth_random_addr(hw->mac.mac_addr); +- rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.mac_addr, +- ð_dev->data->mac_addrs[0]); ++ ret = hns3_init_mac_addrs(eth_dev); ++ if (ret != 0) ++ goto err_init_mac_addrs; + + hw->adapter_state = HNS3_NIC_INITIALIZED; + +@@ -2443,7 +2418,7 @@ hns3vf_dev_init(struct rte_eth_dev *eth_dev) + eth_dev); + return 0; + +-err_rte_zmalloc: ++err_init_mac_addrs: + hns3vf_uninit_vf(eth_dev); + + err_init_vf: +-- +2.33.0 + diff --git a/0025-net-hns3-make-control-plane-function-non-inline.patch b/0025-net-hns3-make-control-plane-function-non-inline.patch new file mode 100644 index 0000000000000000000000000000000000000000..4f658d1ae630226c22e76e247a3af85b790de6dc --- /dev/null +++ b/0025-net-hns3-make-control-plane-function-non-inline.patch @@ -0,0 +1,30 @@ +From 7be11baa6e5fd2143f5574403c44e45fc9c5e393 Mon Sep 17 00:00:00 2001 +From: Jie Hai +Date: Sat, 22 Jan 2022 09:51:31 +0800 +Subject: [PATCH] net/hns3: make control plane function non-inline + +This function is a control-plane interface and does +not need to use inline. + +Signed-off-by: Jie Hai +Acked-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_ethdev.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c +index 722660d0cc..f92832a4aa 100644 +--- a/drivers/net/hns3/hns3_ethdev.c ++++ b/drivers/net/hns3/hns3_ethdev.c +@@ -4853,7 +4853,7 @@ hns3_check_port_speed(struct hns3_hw *hw, uint32_t link_speeds) + return 0; + } + +-static inline uint32_t ++static uint32_t + hns3_get_link_speed(uint32_t link_speeds) + { + uint32_t speed = RTE_ETH_SPEED_NUM_NONE; +-- +2.33.0 + diff --git a/0026-net-hns3-remove-unnecessary-blank-lines.patch b/0026-net-hns3-remove-unnecessary-blank-lines.patch new file mode 100644 index 0000000000000000000000000000000000000000..4cdecd0f407e8dfcb395f6c40203aa91de12fcde --- /dev/null +++ b/0026-net-hns3-remove-unnecessary-blank-lines.patch @@ -0,0 +1,49 @@ +From fbbcf80a9dc6d2f2d553b1c0b8762b5a35f4afc0 Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Sat, 22 Jan 2022 09:51:32 +0800 +Subject: [PATCH] net/hns3: remove unnecessary blank lines + +Remove unnecessary blank lines. + +Signed-off-by: Huisong Li +Acked-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_ethdev.c | 1 - + drivers/net/hns3/hns3_rxtx.h | 2 -- + 2 files changed, 3 deletions(-) + +diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c +index f92832a4aa..0f6d238f6f 100644 +--- a/drivers/net/hns3/hns3_ethdev.c ++++ b/drivers/net/hns3/hns3_ethdev.c +@@ -6295,7 +6295,6 @@ hns3_fec_set(struct rte_eth_dev *dev, uint32_t mode) + struct hns3_adapter *hns = dev->data->dev_private; + struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(hns); + struct hns3_pf *pf = &hns->pf; +- + struct rte_eth_fec_capa fec_capa[FEC_CAPA_NUM]; + uint32_t cur_capa; + uint32_t num = FEC_CAPA_NUM; +diff --git a/drivers/net/hns3/hns3_rxtx.h b/drivers/net/hns3/hns3_rxtx.h +index e202eb9c30..094b65b7de 100644 +--- a/drivers/net/hns3/hns3_rxtx.h ++++ b/drivers/net/hns3/hns3_rxtx.h +@@ -344,7 +344,6 @@ struct hns3_rx_queue { + + struct rte_mbuf fake_mbuf; /* fake mbuf used with vector rx */ + +- + /* + * The following fields are not accessed in the I/O path, so they are + * placed at the end. +@@ -518,7 +517,6 @@ struct hns3_tx_queue { + struct hns3_tx_basic_stats basic_stats; + struct hns3_tx_dfx_stats dfx_stats; + +- + /* + * The following fields are not accessed in the I/O path, so they are + * placed at the end. +-- +2.33.0 + diff --git a/0027-net-hns3-extract-reset-failure-handling-to-function.patch b/0027-net-hns3-extract-reset-failure-handling-to-function.patch new file mode 100644 index 0000000000000000000000000000000000000000..0b685f5e773d7eca3f16d32646d6288e2534396a --- /dev/null +++ b/0027-net-hns3-extract-reset-failure-handling-to-function.patch @@ -0,0 +1,95 @@ +From f13c07a570fabe362b55d2e3643b5ff96513597f Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Sat, 22 Jan 2022 09:51:33 +0800 +Subject: [PATCH] net/hns3: extract reset failure handling to function + +Extract a function to handle reset fail for clearer code logic. + +Signed-off-by: Huisong Li +Acked-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_intr.c | 54 +++++++++++++++++++++--------------- + 1 file changed, 32 insertions(+), 22 deletions(-) + +diff --git a/drivers/net/hns3/hns3_intr.c b/drivers/net/hns3/hns3_intr.c +index 66dc509086..3ca2e1e338 100644 +--- a/drivers/net/hns3/hns3_intr.c ++++ b/drivers/net/hns3/hns3_intr.c +@@ -2770,6 +2770,37 @@ hns3_reset_post(struct hns3_adapter *hns) + return -EIO; + } + ++static void ++hns3_reset_fail_handle(struct hns3_adapter *hns) ++{ ++ struct hns3_hw *hw = &hns->hw; ++ struct timeval tv_delta; ++ struct timeval tv; ++ ++ hns3_clear_reset_level(hw, &hw->reset.pending); ++ if (hns3_reset_err_handle(hns)) { ++ hw->reset.stage = RESET_STAGE_PREWAIT; ++ hns3_schedule_reset(hns); ++ return; ++ } ++ ++ rte_spinlock_lock(&hw->lock); ++ if (hw->reset.mbuf_deferred_free) { ++ hns3_dev_release_mbufs(hns); ++ hw->reset.mbuf_deferred_free = false; ++ } ++ rte_spinlock_unlock(&hw->lock); ++ __atomic_store_n(&hns->hw.reset.resetting, 0, __ATOMIC_RELAXED); ++ hw->reset.stage = RESET_STAGE_NONE; ++ hns3_clock_gettime(&tv); ++ timersub(&tv, &hw->reset.start_time, &tv_delta); ++ hns3_warn(hw, "%s reset fail delta %" PRIu64 " ms time=%ld.%.6ld", ++ reset_string[hw->reset.level], ++ hns3_clock_calctime_ms(&tv_delta), ++ tv.tv_sec, tv.tv_usec); ++ hw->reset.level = HNS3_NONE_RESET; ++} ++ + /* + * There are three scenarios as follows: + * When the reset is not in progress, the reset process starts. +@@ -2784,7 +2815,6 @@ int + hns3_reset_process(struct hns3_adapter *hns, enum hns3_reset_level new_level) + { + struct hns3_hw *hw = &hns->hw; +- struct timeval tv_delta; + struct timeval tv; + int ret; + +@@ -2843,27 +2873,7 @@ hns3_reset_process(struct hns3_adapter *hns, enum hns3_reset_level new_level) + if (ret == -EAGAIN) + return ret; + err: +- hns3_clear_reset_level(hw, &hw->reset.pending); +- if (hns3_reset_err_handle(hns)) { +- hw->reset.stage = RESET_STAGE_PREWAIT; +- hns3_schedule_reset(hns); +- } else { +- rte_spinlock_lock(&hw->lock); +- if (hw->reset.mbuf_deferred_free) { +- hns3_dev_release_mbufs(hns); +- hw->reset.mbuf_deferred_free = false; +- } +- rte_spinlock_unlock(&hw->lock); +- __atomic_store_n(&hns->hw.reset.resetting, 0, __ATOMIC_RELAXED); +- hw->reset.stage = RESET_STAGE_NONE; +- hns3_clock_gettime(&tv); +- timersub(&tv, &hw->reset.start_time, &tv_delta); +- hns3_warn(hw, "%s reset fail delta %" PRIu64 " ms time=%ld.%.6ld", +- reset_string[hw->reset.level], +- hns3_clock_calctime_ms(&tv_delta), +- tv.tv_sec, tv.tv_usec); +- hw->reset.level = HNS3_NONE_RESET; +- } ++ hns3_reset_fail_handle(hns); + + return -EIO; + } +-- +2.33.0 + diff --git a/0028-net-hns3-remove-unused-variables.patch b/0028-net-hns3-remove-unused-variables.patch new file mode 100644 index 0000000000000000000000000000000000000000..b913c6093c79e2698935f19b60b7534a08a93ed3 --- /dev/null +++ b/0028-net-hns3-remove-unused-variables.patch @@ -0,0 +1,77 @@ +From a65941e9c461bfc050778ed318a90e621d903163 Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Sat, 22 Jan 2022 09:51:34 +0800 +Subject: [PATCH] net/hns3: remove unused variables + +Remove unused variables. + +Signed-off-by: Huisong Li +Acked-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_dcb.c | 12 +----------- + drivers/net/hns3/hns3_ethdev.c | 3 --- + drivers/net/hns3/hns3_ethdev.h | 2 -- + 3 files changed, 1 insertion(+), 16 deletions(-) + +diff --git a/drivers/net/hns3/hns3_dcb.c b/drivers/net/hns3/hns3_dcb.c +index e4417e87fd..73693786d1 100644 +--- a/drivers/net/hns3/hns3_dcb.c ++++ b/drivers/net/hns3/hns3_dcb.c +@@ -750,19 +750,9 @@ static int + hns3_dcb_update_tc_queue_mapping(struct hns3_hw *hw, uint16_t nb_rx_q, + uint16_t nb_tx_q) + { +- struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw); +- struct hns3_pf *pf = &hns->pf; +- int ret; +- + hw->num_tc = hw->dcb_info.num_tc; +- ret = hns3_queue_to_tc_mapping(hw, nb_rx_q, nb_tx_q); +- if (ret) +- return ret; + +- if (!hns->is_vf) +- memcpy(pf->prio_tc, hw->dcb_info.prio_tc, HNS3_MAX_USER_PRIO); +- +- return 0; ++ return hns3_queue_to_tc_mapping(hw, nb_rx_q, nb_tx_q); + } + + int +diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c +index 0f6d238f6f..90eb6340a9 100644 +--- a/drivers/net/hns3/hns3_ethdev.c ++++ b/drivers/net/hns3/hns3_ethdev.c +@@ -2546,9 +2546,6 @@ hns3_parse_cfg(struct hns3_cfg *cfg, struct hns3_cmd_desc *desc) + cfg->media_type = hns3_get_field(rte_le_to_cpu_32(req->param[1]), + HNS3_CFG_MEDIA_TP_M, + HNS3_CFG_MEDIA_TP_S); +- cfg->rx_buf_len = hns3_get_field(rte_le_to_cpu_32(req->param[1]), +- HNS3_CFG_RX_BUF_LEN_M, +- HNS3_CFG_RX_BUF_LEN_S); + /* get mac address */ + mac_addr_tmp = rte_le_to_cpu_32(req->param[2]); + mac_addr_tmp_high = hns3_get_field(rte_le_to_cpu_32(req->param[3]), +diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h +index 153e67337f..1dd388625b 100644 +--- a/drivers/net/hns3/hns3_ethdev.h ++++ b/drivers/net/hns3/hns3_ethdev.h +@@ -156,7 +156,6 @@ struct hns3_tc_queue_info { + struct hns3_cfg { + uint8_t tc_num; + uint16_t tqp_desc_num; +- uint16_t rx_buf_len; + uint16_t rss_size_max; + uint8_t phy_addr; + uint8_t media_type; +@@ -804,7 +803,6 @@ struct hns3_pf { + uint8_t tc_max; /* max number of tc driver supported */ + uint8_t local_max_tc; /* max number of local tc */ + uint8_t pfc_max; +- uint8_t prio_tc[HNS3_MAX_USER_PRIO]; /* TC indexed by prio */ + uint16_t pause_time; + bool support_fc_autoneg; /* support FC autonegotiate */ + bool support_multi_tc_pause; +-- +2.33.0 + diff --git a/0029-net-hns3-remove-getting-number-of-queue-descriptors-.patch b/0029-net-hns3-remove-getting-number-of-queue-descriptors-.patch new file mode 100644 index 0000000000000000000000000000000000000000..ddb9a476ea535b6dfdd955f02040661d019a5bd8 --- /dev/null +++ b/0029-net-hns3-remove-getting-number-of-queue-descriptors-.patch @@ -0,0 +1,107 @@ +From af1f62b3d1e6bf12830facbb0161981bdce6685d Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Sat, 22 Jan 2022 09:51:35 +0800 +Subject: [PATCH] net/hns3: remove getting number of queue descriptors from FW + +Application can specify the number of Rx/Tx queue descriptors in DPDK. +So driver does not obtain the default value from firmware and PF. + +Signed-off-by: Huisong Li +Acked-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_ethdev.c | 5 ----- + drivers/net/hns3/hns3_ethdev.h | 3 --- + drivers/net/hns3/hns3_ethdev_vf.c | 26 -------------------------- + 3 files changed, 34 deletions(-) + +diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c +index 90eb6340a9..aa9301c561 100644 +--- a/drivers/net/hns3/hns3_ethdev.c ++++ b/drivers/net/hns3/hns3_ethdev.c +@@ -2536,9 +2536,6 @@ hns3_parse_cfg(struct hns3_cfg *cfg, struct hns3_cmd_desc *desc) + /* get the configuration */ + cfg->tc_num = hns3_get_field(rte_le_to_cpu_32(req->param[0]), + HNS3_CFG_TC_NUM_M, HNS3_CFG_TC_NUM_S); +- cfg->tqp_desc_num = hns3_get_field(rte_le_to_cpu_32(req->param[0]), +- HNS3_CFG_TQP_DESC_N_M, +- HNS3_CFG_TQP_DESC_N_S); + + cfg->phy_addr = hns3_get_field(rte_le_to_cpu_32(req->param[1]), + HNS3_CFG_PHY_ADDR_M, +@@ -2849,8 +2846,6 @@ hns3_get_board_configuration(struct hns3_hw *hw) + hw->rss_dis_flag = false; + memcpy(hw->mac.mac_addr, cfg.mac_addr, RTE_ETHER_ADDR_LEN); + hw->mac.phy_addr = cfg.phy_addr; +- hw->num_tx_desc = cfg.tqp_desc_num; +- hw->num_rx_desc = cfg.tqp_desc_num; + hw->dcb_info.num_pg = 1; + hw->dcb_info.hw_pfc_map = 0; + +diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h +index 1dd388625b..cf6380ebb2 100644 +--- a/drivers/net/hns3/hns3_ethdev.h ++++ b/drivers/net/hns3/hns3_ethdev.h +@@ -155,7 +155,6 @@ struct hns3_tc_queue_info { + + struct hns3_cfg { + uint8_t tc_num; +- uint16_t tqp_desc_num; + uint16_t rss_size_max; + uint8_t phy_addr; + uint8_t media_type; +@@ -512,8 +511,6 @@ struct hns3_hw { + uint16_t intr_tqps_num; /* num queue pairs mapping interrupt */ + uint16_t rss_size_max; /* HW defined max RSS task queue */ + uint16_t rx_buf_len; /* hold min hardware rx buf len */ +- uint16_t num_tx_desc; /* desc num of per tx queue */ +- uint16_t num_rx_desc; /* desc num of per rx queue */ + uint32_t mng_entry_num; /* number of manager table entry */ + uint32_t mac_entry_num; /* number of mac-vlan table entry */ + +diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c +index 5a1286e17b..36d860d08a 100644 +--- a/drivers/net/hns3/hns3_ethdev_vf.c ++++ b/drivers/net/hns3/hns3_ethdev_vf.c +@@ -941,27 +941,6 @@ hns3vf_get_queue_info(struct hns3_hw *hw) + return hns3vf_check_tqp_info(hw); + } + +-static int +-hns3vf_get_queue_depth(struct hns3_hw *hw) +-{ +-#define HNS3VF_TQPS_DEPTH_INFO_LEN 4 +- uint8_t resp_msg[HNS3VF_TQPS_DEPTH_INFO_LEN]; +- int ret; +- +- ret = hns3_send_mbx_msg(hw, HNS3_MBX_GET_QDEPTH, 0, NULL, 0, true, +- resp_msg, HNS3VF_TQPS_DEPTH_INFO_LEN); +- if (ret) { +- PMD_INIT_LOG(ERR, "Failed to get tqp depth info from PF: %d", +- ret); +- return ret; +- } +- +- memcpy(&hw->num_tx_desc, &resp_msg[0], sizeof(uint16_t)); +- memcpy(&hw->num_rx_desc, &resp_msg[2], sizeof(uint16_t)); +- +- return 0; +-} +- + static void + hns3vf_update_caps(struct hns3_hw *hw, uint32_t caps) + { +@@ -1052,11 +1031,6 @@ hns3vf_get_configuration(struct hns3_hw *hw) + if (ret) + return ret; + +- /* Get queue depth info from PF */ +- ret = hns3vf_get_queue_depth(hw); +- if (ret) +- return ret; +- + /* Get user defined VF MAC addr from PF */ + ret = hns3vf_get_host_mac_addr(hw); + if (ret) +-- +2.33.0 + diff --git a/0030-net-hns3-remove-logging-memory-addresses.patch b/0030-net-hns3-remove-logging-memory-addresses.patch new file mode 100644 index 0000000000000000000000000000000000000000..533ba28e1ba3f3d9cd79a972c4932edd2a140f9a --- /dev/null +++ b/0030-net-hns3-remove-logging-memory-addresses.patch @@ -0,0 +1,79 @@ +From 5608b54756d91505e66e58c2562601b3f7e2fe80 Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Sat, 22 Jan 2022 09:51:36 +0800 +Subject: [PATCH] net/hns3: remove logging memory addresses + +Remove the printing of memory addresses. + +Signed-off-by: Huisong Li +Acked-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_cmd.c | 12 ++++-------- + drivers/net/hns3/hns3_rxtx.c | 6 ------ + 2 files changed, 4 insertions(+), 14 deletions(-) + +diff --git a/drivers/net/hns3/hns3_cmd.c b/drivers/net/hns3/hns3_cmd.c +index 5b42d38aa5..5dc874fd7a 100644 +--- a/drivers/net/hns3/hns3_cmd.c ++++ b/drivers/net/hns3/hns3_cmd.c +@@ -60,18 +60,14 @@ hns3_allocate_dma_mem(struct hns3_hw *hw, struct hns3_cmq_ring *ring, + ring->desc = mz->addr; + ring->desc_dma_addr = mz->iova; + ring->zone = (const void *)mz; +- hns3_dbg(hw, "memzone %s allocated with physical address: %" PRIu64, +- mz->name, ring->desc_dma_addr); ++ hns3_dbg(hw, "cmd ring memzone name: %s", mz->name); + + return 0; + } + + static void +-hns3_free_dma_mem(struct hns3_hw *hw, struct hns3_cmq_ring *ring) ++hns3_free_dma_mem(struct hns3_cmq_ring *ring) + { +- hns3_dbg(hw, "memzone %s to be freed with physical address: %" PRIu64, +- ((const struct rte_memzone *)ring->zone)->name, +- ring->desc_dma_addr); + rte_memzone_free((const struct rte_memzone *)ring->zone); + ring->buf_size = 0; + ring->desc = NULL; +@@ -93,10 +89,10 @@ hns3_alloc_cmd_desc(struct hns3_hw *hw, struct hns3_cmq_ring *ring) + } + + static void +-hns3_free_cmd_desc(struct hns3_hw *hw, struct hns3_cmq_ring *ring) ++hns3_free_cmd_desc(__rte_unused struct hns3_hw *hw, struct hns3_cmq_ring *ring) + { + if (ring->desc) +- hns3_free_dma_mem(hw, ring); ++ hns3_free_dma_mem(ring); + } + + static int +diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c +index c43131cac6..3b72c2375a 100644 +--- a/drivers/net/hns3/hns3_rxtx.c ++++ b/drivers/net/hns3/hns3_rxtx.c +@@ -1382,9 +1382,6 @@ hns3_alloc_rxq_and_dma_zone(struct rte_eth_dev *dev, + rxq->rx_ring = (struct hns3_desc *)rx_mz->addr; + rxq->rx_ring_phys_addr = rx_mz->iova; + +- hns3_dbg(hw, "No.%u rx descriptors iova 0x%" PRIx64, q_info->idx, +- rxq->rx_ring_phys_addr); +- + return rxq; + } + +@@ -1469,9 +1466,6 @@ hns3_alloc_txq_and_dma_zone(struct rte_eth_dev *dev, + txq->tx_ring = (struct hns3_desc *)tx_mz->addr; + txq->tx_ring_phys_addr = tx_mz->iova; + +- hns3_dbg(hw, "No.%u tx descriptors iova 0x%" PRIx64, q_info->idx, +- txq->tx_ring_phys_addr); +- + /* Clear tx bd */ + desc = txq->tx_ring; + for (i = 0; i < txq->nb_tx_desc; i++) { +-- +2.33.0 + diff --git a/0031-net-hns3-extract-common-function-to-obtain-revision-.patch b/0031-net-hns3-extract-common-function-to-obtain-revision-.patch new file mode 100644 index 0000000000000000000000000000000000000000..a6d6adca727bab5e7085f9096f23231f21549602 --- /dev/null +++ b/0031-net-hns3-extract-common-function-to-obtain-revision-.patch @@ -0,0 +1,145 @@ +From f5ed7d99cf45d550a69c1430b7c4a5623a9c774a Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Sat, 22 Jan 2022 09:51:37 +0800 +Subject: [PATCH] net/hns3: extract common function to obtain revision ID + +The code logic of obtaining the revision ID of PCI device is the same +for PF and VF driver. This patch extracts a common interface to do it. + +Signed-off-by: Huisong Li +Acked-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_common.c | 22 ++++++++++++++++++++++ + drivers/net/hns3/hns3_common.h | 2 ++ + drivers/net/hns3/hns3_ethdev.c | 16 ++++------------ + drivers/net/hns3/hns3_ethdev_vf.c | 21 ++++----------------- + 4 files changed, 32 insertions(+), 29 deletions(-) + +diff --git a/drivers/net/hns3/hns3_common.c b/drivers/net/hns3/hns3_common.c +index 0f39d51a87..dcdc609654 100644 +--- a/drivers/net/hns3/hns3_common.c ++++ b/drivers/net/hns3/hns3_common.c +@@ -821,3 +821,25 @@ hns3_restore_rx_interrupt(struct hns3_hw *hw) + + return 0; + } ++ ++int ++hns3_get_pci_revision_id(struct hns3_hw *hw, uint8_t *revision_id) ++{ ++ struct rte_pci_device *pci_dev; ++ struct rte_eth_dev *eth_dev; ++ uint8_t revision; ++ int ret; ++ ++ eth_dev = &rte_eth_devices[hw->data->port_id]; ++ pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev); ++ ret = rte_pci_read_config(pci_dev, &revision, HNS3_PCI_REVISION_ID_LEN, ++ HNS3_PCI_REVISION_ID); ++ if (ret != HNS3_PCI_REVISION_ID_LEN) { ++ hns3_err(hw, "failed to read pci revision id, ret = %d", ret); ++ return -EIO; ++ } ++ ++ *revision_id = revision; ++ ++ return 0; ++} +diff --git a/drivers/net/hns3/hns3_common.h b/drivers/net/hns3/hns3_common.h +index a9e8a9cccf..2994e4a269 100644 +--- a/drivers/net/hns3/hns3_common.h ++++ b/drivers/net/hns3/hns3_common.h +@@ -59,4 +59,6 @@ int hns3_map_rx_interrupt(struct rte_eth_dev *dev); + void hns3_unmap_rx_interrupt(struct rte_eth_dev *dev); + int hns3_restore_rx_interrupt(struct hns3_hw *hw); + ++int hns3_get_pci_revision_id(struct hns3_hw *hw, uint8_t *revision_id); ++ + #endif /* _HNS3_COMMON_H_ */ +diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c +index aa9301c561..b417d55e10 100644 +--- a/drivers/net/hns3/hns3_ethdev.c ++++ b/drivers/net/hns3/hns3_ethdev.c +@@ -5,7 +5,6 @@ + #include + #include + #include +-#include + + #include "hns3_ethdev.h" + #include "hns3_common.h" +@@ -2732,7 +2731,6 @@ hns3_get_capability(struct hns3_hw *hw) + struct hns3_pf *pf = &hns->pf; + struct rte_eth_dev *eth_dev; + uint16_t device_id; +- uint8_t revision; + int ret; + + eth_dev = &rte_eth_devices[hw->data->port_id]; +@@ -2745,17 +2743,11 @@ hns3_get_capability(struct hns3_hw *hw) + device_id == HNS3_DEV_ID_200G_RDMA) + hns3_set_bit(hw->capability, HNS3_DEV_SUPPORT_DCB_B, 1); + +- /* Get PCI revision id */ +- ret = rte_pci_read_config(pci_dev, &revision, HNS3_PCI_REVISION_ID_LEN, +- HNS3_PCI_REVISION_ID); +- if (ret != HNS3_PCI_REVISION_ID_LEN) { +- PMD_INIT_LOG(ERR, "failed to read pci revision id, ret = %d", +- ret); +- return -EIO; +- } +- hw->revision = revision; ++ ret = hns3_get_pci_revision_id(hw, &hw->revision); ++ if (ret) ++ return ret; + +- if (revision < PCI_REVISION_ID_HIP09_A) { ++ if (hw->revision < PCI_REVISION_ID_HIP09_A) { + hns3_set_default_dev_specifications(hw); + hw->intr.mapping_mode = HNS3_INTR_MAPPING_VEC_RSV_ONE; + hw->intr.gl_unit = HNS3_INTR_COALESCE_GL_UINT_2US; +diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c +index 36d860d08a..a9e129288b 100644 +--- a/drivers/net/hns3/hns3_ethdev_vf.c ++++ b/drivers/net/hns3/hns3_ethdev_vf.c +@@ -6,7 +6,6 @@ + #include + #include + #include +-#include + #include + + #include "hns3_ethdev.h" +@@ -810,25 +809,13 @@ hns3vf_get_push_lsc_cap(struct hns3_hw *hw) + static int + hns3vf_get_capability(struct hns3_hw *hw) + { +- struct rte_pci_device *pci_dev; +- struct rte_eth_dev *eth_dev; +- uint8_t revision; + int ret; + +- eth_dev = &rte_eth_devices[hw->data->port_id]; +- pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev); +- +- /* Get PCI revision id */ +- ret = rte_pci_read_config(pci_dev, &revision, HNS3_PCI_REVISION_ID_LEN, +- HNS3_PCI_REVISION_ID); +- if (ret != HNS3_PCI_REVISION_ID_LEN) { +- PMD_INIT_LOG(ERR, "failed to read pci revision id, ret = %d", +- ret); +- return -EIO; +- } +- hw->revision = revision; ++ ret = hns3_get_pci_revision_id(hw, &hw->revision); ++ if (ret) ++ return ret; + +- if (revision < PCI_REVISION_ID_HIP09_A) { ++ if (hw->revision < PCI_REVISION_ID_HIP09_A) { + hns3vf_set_default_dev_specifications(hw); + hw->intr.mapping_mode = HNS3_INTR_MAPPING_VEC_RSV_ONE; + hw->intr.gl_unit = HNS3_INTR_COALESCE_GL_UINT_2US; +-- +2.33.0 + diff --git a/0032-net-hns3-replace-single-line-functions.patch b/0032-net-hns3-replace-single-line-functions.patch new file mode 100644 index 0000000000000000000000000000000000000000..d6d89ff4271eaa58153638a0e8c5100fb39d8338 --- /dev/null +++ b/0032-net-hns3-replace-single-line-functions.patch @@ -0,0 +1,114 @@ +From 3340aa9f50da68f20d2cdb6382a9ab6891e7363c Mon Sep 17 00:00:00 2001 +From: Chengwen Feng +Date: Sat, 22 Jan 2022 09:51:38 +0800 +Subject: [PATCH] net/hns3: replace single line functions + +This patch removes single functions with actual calls. + +Signed-off-by: Chengwen Feng +Acked-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_ethdev.c | 27 ++++++++------------------- + drivers/net/hns3/hns3_ethdev_vf.c | 13 ++----------- + 2 files changed, 10 insertions(+), 30 deletions(-) + +diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c +index b417d55e10..a5114662d2 100644 +--- a/drivers/net/hns3/hns3_ethdev.c ++++ b/drivers/net/hns3/hns3_ethdev.c +@@ -587,22 +587,6 @@ hns3_set_vlan_rx_offload_cfg(struct hns3_adapter *hns, + return ret; + } + +-static void +-hns3_update_rx_offload_cfg(struct hns3_adapter *hns, +- struct hns3_rx_vtag_cfg *vcfg) +-{ +- struct hns3_pf *pf = &hns->pf; +- memcpy(&pf->vtag_config.rx_vcfg, vcfg, sizeof(pf->vtag_config.rx_vcfg)); +-} +- +-static void +-hns3_update_tx_offload_cfg(struct hns3_adapter *hns, +- struct hns3_tx_vtag_cfg *vcfg) +-{ +- struct hns3_pf *pf = &hns->pf; +- memcpy(&pf->vtag_config.tx_vcfg, vcfg, sizeof(pf->vtag_config.tx_vcfg)); +-} +- + static int + hns3_en_hw_strip_rxvtag(struct hns3_adapter *hns, bool enable) + { +@@ -632,7 +616,8 @@ hns3_en_hw_strip_rxvtag(struct hns3_adapter *hns, bool enable) + return ret; + } + +- hns3_update_rx_offload_cfg(hns, &rxvlan_cfg); ++ memcpy(&hns->pf.vtag_config.rx_vcfg, &rxvlan_cfg, ++ sizeof(struct hns3_rx_vtag_cfg)); + + return ret; + } +@@ -830,7 +815,9 @@ hns3_vlan_txvlan_cfg(struct hns3_adapter *hns, uint16_t port_base_vlan_state, + return ret; + } + +- hns3_update_tx_offload_cfg(hns, &txvlan_cfg); ++ memcpy(&hns->pf.vtag_config.tx_vcfg, &txvlan_cfg, ++ sizeof(struct hns3_tx_vtag_cfg)); ++ + return ret; + } + +@@ -956,7 +943,9 @@ hns3_en_pvid_strip(struct hns3_adapter *hns, int on) + if (ret) + return ret; + +- hns3_update_rx_offload_cfg(hns, &rx_vlan_cfg); ++ memcpy(&hns->pf.vtag_config.rx_vcfg, &rx_vlan_cfg, ++ sizeof(struct hns3_rx_vtag_cfg)); ++ + return ret; + } + +diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c +index a9e129288b..1af2e07e81 100644 +--- a/drivers/net/hns3/hns3_ethdev_vf.c ++++ b/drivers/net/hns3/hns3_ethdev_vf.c +@@ -1026,15 +1026,6 @@ hns3vf_get_configuration(struct hns3_hw *hw) + return hns3vf_get_port_base_vlan_filter_state(hw); + } + +-static int +-hns3vf_set_tc_queue_mapping(struct hns3_adapter *hns, uint16_t nb_rx_q, +- uint16_t nb_tx_q) +-{ +- struct hns3_hw *hw = &hns->hw; +- +- return hns3_queue_to_tc_mapping(hw, nb_rx_q, nb_tx_q); +-} +- + static void + hns3vf_request_link_info(struct hns3_hw *hw) + { +@@ -1530,7 +1521,7 @@ hns3vf_init_vf(struct rte_eth_dev *eth_dev) + goto err_set_tc_queue; + } + +- ret = hns3vf_set_tc_queue_mapping(hns, hw->tqps_num, hw->tqps_num); ++ ret = hns3_queue_to_tc_mapping(hw, hw->tqps_num, hw->tqps_num); + if (ret) { + PMD_INIT_LOG(ERR, "failed to set tc info, ret = %d.", ret); + goto err_set_tc_queue; +@@ -1739,7 +1730,7 @@ hns3vf_do_start(struct hns3_adapter *hns, bool reset_queue) + uint16_t nb_tx_q = hw->data->nb_tx_queues; + int ret; + +- ret = hns3vf_set_tc_queue_mapping(hns, nb_rx_q, nb_tx_q); ++ ret = hns3_queue_to_tc_mapping(hw, nb_rx_q, nb_tx_q); + if (ret) + return ret; + +-- +2.33.0 + diff --git a/0033-net-hns3-remove-non-re-entrant-strerror-call.patch b/0033-net-hns3-remove-non-re-entrant-strerror-call.patch new file mode 100644 index 0000000000000000000000000000000000000000..2d452171c2aff30a4a0d848461625e461d60db10 --- /dev/null +++ b/0033-net-hns3-remove-non-re-entrant-strerror-call.patch @@ -0,0 +1,30 @@ +From 2a1e7c4782ee21823eb37acbb073bcf9f73b173f Mon Sep 17 00:00:00 2001 +From: Chengwen Feng +Date: Sat, 22 Jan 2022 09:51:39 +0800 +Subject: [PATCH] net/hns3: remove non re-entrant strerror call + +This patch delete strerror invoke which was non re-entrant. + +Signed-off-by: Chengwen Feng +Acked-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_fdir.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/drivers/net/hns3/hns3_fdir.c b/drivers/net/hns3/hns3_fdir.c +index d043f5786d..2a7978ac07 100644 +--- a/drivers/net/hns3/hns3_fdir.c ++++ b/drivers/net/hns3/hns3_fdir.c +@@ -919,8 +919,7 @@ static int hns3_insert_fdir_filter(struct hns3_hw *hw, + sig = rte_hash_crc(key, sizeof(*key), 0); + ret = rte_hash_add_key_with_hash(fdir_info->hash_handle, key, sig); + if (ret < 0) { +- hns3_err(hw, "Hash table full? err:%d(%s)!", ret, +- strerror(-ret)); ++ hns3_err(hw, "Hash table full? err:%d!", ret); + return ret; + } + +-- +2.33.0 + diff --git a/0034-net-hns3-rename-function.patch b/0034-net-hns3-rename-function.patch new file mode 100644 index 0000000000000000000000000000000000000000..6f2e90e98247b3041b2c692d1350fcf4ade11072 --- /dev/null +++ b/0034-net-hns3-rename-function.patch @@ -0,0 +1,39 @@ +From 092ffe854dafe98f3e8e4c412211b80f6932315e Mon Sep 17 00:00:00 2001 +From: Chengwen Feng +Date: Sat, 22 Jan 2022 09:51:40 +0800 +Subject: [PATCH] net/hns3: rename function + +This patch rename hns3_parse_rss_key with hns3_adjust_rss_key to +improve readability. + +Signed-off-by: Chengwen Feng +Acked-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_flow.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c +index 00084872ad..72986abaff 100644 +--- a/drivers/net/hns3/hns3_flow.c ++++ b/drivers/net/hns3/hns3_flow.c +@@ -1405,7 +1405,7 @@ hns3_disable_rss(struct hns3_hw *hw) + } + + static void +-hns3_parse_rss_key(struct hns3_hw *hw, struct rte_flow_action_rss *rss_conf) ++hns3_adjust_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"); +@@ -1449,7 +1449,7 @@ hns3_hw_rss_hash_set(struct hns3_hw *hw, struct rte_flow_action_rss *rss_config) + struct hns3_rss_tuple_cfg *tuple; + int ret; + +- hns3_parse_rss_key(hw, rss_config); ++ hns3_adjust_rss_key(hw, rss_config); + + ret = hns3_parse_rss_algorithm(hw, &rss_config->func, + &hw->rss_info.hash_algo); +-- +2.33.0 + diff --git a/0035-net-hns3-extract-functions-to-create-RSS-and-FDIR-fl.patch b/0035-net-hns3-extract-functions-to-create-RSS-and-FDIR-fl.patch new file mode 100644 index 0000000000000000000000000000000000000000..6c656217a8b8aa742ce980a76c292e2e2f42874b --- /dev/null +++ b/0035-net-hns3-extract-functions-to-create-RSS-and-FDIR-fl.patch @@ -0,0 +1,225 @@ +From c48499171f5df62a71697dce517b9fa22bc30985 Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Sat, 22 Jan 2022 09:51:41 +0800 +Subject: [PATCH] net/hns3: extract functions to create RSS and FDIR flow rule + +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 | 173 +++++++++++++++++++++-------------- + 1 file changed, 106 insertions(+), 67 deletions(-) + +diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c +index 72986abaff..4f271a32dd 100644 +--- a/drivers/net/hns3/hns3_flow.c ++++ b/drivers/net/hns3/hns3_flow.c +@@ -1706,6 +1706,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, 0, ++ 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. +@@ -1720,13 +1819,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); +@@ -1752,76 +1847,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, 0, 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 + diff --git a/0036-net-hns3-support-indirect-counter-flow-action.patch b/0036-net-hns3-support-indirect-counter-flow-action.patch new file mode 100644 index 0000000000000000000000000000000000000000..7251d4d2b2c64b9175572858ffd2607a12db3a68 --- /dev/null +++ b/0036-net-hns3-support-indirect-counter-flow-action.patch @@ -0,0 +1,367 @@ +From fdfcb94d8fb32364a999108baf1e4b835cd807fc Mon Sep 17 00:00:00 2001 +From: Chengwen Feng +Date: Sat, 22 Jan 2022 09:51:42 +0800 +Subject: [PATCH] net/hns3: support indirect counter flow action + +This patch support indirect counter action because the shared counter +attribute has been deprecated in DPDK 21.11. + +Signed-off-by: Chengwen Feng +Acked-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_fdir.h | 1 + + drivers/net/hns3/hns3_flow.c | 222 +++++++++++++++++++++++++++++++++-- + drivers/net/hns3/hns3_flow.h | 11 +- + 3 files changed, 224 insertions(+), 10 deletions(-) + +diff --git a/drivers/net/hns3/hns3_fdir.h b/drivers/net/hns3/hns3_fdir.h +index 07b393393d..8d588ffef3 100644 +--- a/drivers/net/hns3/hns3_fdir.h ++++ b/drivers/net/hns3/hns3_fdir.h +@@ -125,6 +125,7 @@ struct hns3_fd_ad_data { + #define HNS3_RULE_FLAG_FDID 0x1 + #define HNS3_RULE_FLAG_VF_ID 0x2 + #define HNS3_RULE_FLAG_COUNTER 0x4 ++#define HNS3_RULE_FLAG_COUNTER_INDIR 0x8 + + struct hns3_fdir_key_conf { + struct hns3_fd_rule_tuples spec; +diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c +index 4f271a32dd..56ef6f57b2 100644 +--- a/drivers/net/hns3/hns3_flow.c ++++ b/drivers/net/hns3/hns3_flow.c +@@ -154,7 +154,7 @@ hns3_counter_lookup(struct rte_eth_dev *dev, uint32_t id) + } + + static int +-hns3_counter_new(struct rte_eth_dev *dev, uint32_t shared, uint32_t id, ++hns3_counter_new(struct rte_eth_dev *dev, uint32_t indirect, uint32_t id, + struct rte_flow_error *error) + { + struct hns3_adapter *hns = dev->data->dev_private; +@@ -166,11 +166,14 @@ hns3_counter_new(struct rte_eth_dev *dev, uint32_t shared, uint32_t id, + + cnt = hns3_counter_lookup(dev, id); + if (cnt) { +- if (!cnt->shared || cnt->shared != shared) ++ if (!cnt->indirect || cnt->indirect != indirect) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION_CONF, + cnt, +- "Counter id is used, shared flag not match"); ++ "Counter id is used, indirect flag not match"); ++ /* Clear the indirect counter on first use. */ ++ if (cnt->indirect && cnt->ref_cnt == 1) ++ (void)hns3_get_count(hw, id, &value); + cnt->ref_cnt++; + return 0; + } +@@ -188,7 +191,7 @@ hns3_counter_new(struct rte_eth_dev *dev, uint32_t shared, uint32_t id, + RTE_FLOW_ERROR_TYPE_HANDLE, cnt, + "Alloc mem for counter failed"); + cnt->id = id; +- cnt->shared = shared; ++ cnt->indirect = indirect; + cnt->ref_cnt = 1; + cnt->hits = 0; + LIST_INSERT_HEAD(&pf->flow_counters, cnt, next); +@@ -253,16 +256,30 @@ hns3_counter_release(struct rte_eth_dev *dev, uint32_t id) + static void + hns3_counter_flush(struct rte_eth_dev *dev) + { +- struct hns3_adapter *hns = dev->data->dev_private; +- struct hns3_pf *pf = &hns->pf; ++ struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private); ++ LIST_HEAD(counters, hns3_flow_counter) indir_counters; + struct hns3_flow_counter *cnt_ptr; + ++ LIST_INIT(&indir_counters); + cnt_ptr = LIST_FIRST(&pf->flow_counters); + while (cnt_ptr) { + LIST_REMOVE(cnt_ptr, next); +- rte_free(cnt_ptr); ++ if (cnt_ptr->indirect) ++ LIST_INSERT_HEAD(&indir_counters, cnt_ptr, next); ++ else ++ rte_free(cnt_ptr); + cnt_ptr = LIST_FIRST(&pf->flow_counters); + } ++ ++ /* Reset the indirect action and add to pf->flow_counters list. */ ++ cnt_ptr = LIST_FIRST(&indir_counters); ++ while (cnt_ptr) { ++ LIST_REMOVE(cnt_ptr, next); ++ cnt_ptr->ref_cnt = 1; ++ cnt_ptr->hits = 0; ++ LIST_INSERT_HEAD(&pf->flow_counters, cnt_ptr, next); ++ cnt_ptr = LIST_FIRST(&indir_counters); ++ } + } + + static int +@@ -332,6 +349,30 @@ hns3_handle_action_queue_region(struct rte_eth_dev *dev, + return 0; + } + ++static int ++hns3_handle_action_indirect(struct rte_eth_dev *dev, ++ const struct rte_flow_action *action, ++ struct hns3_fdir_rule *rule, ++ struct rte_flow_error *error) ++{ ++ const struct rte_flow_action_handle *indir = action->conf; ++ ++ if (indir->indirect_type != HNS3_INDIRECT_ACTION_TYPE_COUNT) ++ return rte_flow_error_set(error, EINVAL, ++ RTE_FLOW_ERROR_TYPE_ACTION_CONF, ++ action, "Invalid indirect type"); ++ ++ if (hns3_counter_lookup(dev, indir->counter_id) == NULL) ++ return rte_flow_error_set(error, EINVAL, ++ RTE_FLOW_ERROR_TYPE_ACTION_CONF, ++ action, "Counter id not exist"); ++ ++ rule->act_cnt.id = indir->counter_id; ++ rule->flags |= (HNS3_RULE_FLAG_COUNTER | HNS3_RULE_FLAG_COUNTER_INDIR); ++ ++ return 0; ++} ++ + /* + * Parse actions structure from the provided pattern. + * The pattern is validated as the items are copied. +@@ -403,6 +444,13 @@ hns3_handle_actions(struct rte_eth_dev *dev, + "Invalid counter id"); + rule->act_cnt = *act_count; + rule->flags |= HNS3_RULE_FLAG_COUNTER; ++ rule->flags &= ~HNS3_RULE_FLAG_COUNTER_INDIR; ++ break; ++ case RTE_FLOW_ACTION_TYPE_INDIRECT: ++ ret = hns3_handle_action_indirect(dev, actions, rule, ++ error); ++ if (ret) ++ return ret; + break; + case RTE_FLOW_ACTION_TYPE_VOID: + break; +@@ -1755,6 +1803,7 @@ hns3_flow_create_fdir_rule(struct rte_eth_dev *dev, + struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw); + struct hns3_fdir_rule_ele *fdir_rule_ptr; + struct hns3_fdir_rule fdir_rule; ++ bool indir; + int ret; + + memset(&fdir_rule, 0, sizeof(struct hns3_fdir_rule)); +@@ -1762,9 +1811,10 @@ hns3_flow_create_fdir_rule(struct rte_eth_dev *dev, + if (ret != 0) + return ret; + ++ indir = !!(fdir_rule.flags & HNS3_RULE_FLAG_COUNTER_INDIR); + if (fdir_rule.flags & HNS3_RULE_FLAG_COUNTER) { +- ret = hns3_counter_new(dev, 0, +- fdir_rule.act_cnt.id, error); ++ ret = hns3_counter_new(dev, indir, fdir_rule.act_cnt.id, ++ error); + if (ret != 0) + return ret; + +@@ -2086,6 +2136,157 @@ hns3_flow_query_wrap(struct rte_eth_dev *dev, struct rte_flow *flow, + return ret; + } + ++static int ++hns3_check_indir_action(const struct rte_flow_indir_action_conf *conf, ++ const struct rte_flow_action *action, ++ struct rte_flow_error *error) ++{ ++ if (!conf->ingress) ++ return rte_flow_error_set(error, EINVAL, ++ RTE_FLOW_ERROR_TYPE_ACTION, ++ NULL, "Indir action ingress can't be zero"); ++ ++ if (conf->egress) ++ return rte_flow_error_set(error, EINVAL, ++ RTE_FLOW_ERROR_TYPE_ACTION, ++ NULL, "Indir action not support egress"); ++ ++ if (conf->transfer) ++ return rte_flow_error_set(error, EINVAL, ++ RTE_FLOW_ERROR_TYPE_ACTION, ++ NULL, "Indir action not support transfer"); ++ ++ if (action->type != RTE_FLOW_ACTION_TYPE_COUNT) ++ return rte_flow_error_set(error, EINVAL, ++ RTE_FLOW_ERROR_TYPE_ACTION, ++ NULL, "Indir action only support count"); ++ ++ return 0; ++} ++ ++static struct rte_flow_action_handle * ++hns3_flow_action_create(struct rte_eth_dev *dev, ++ const struct rte_flow_indir_action_conf *conf, ++ const struct rte_flow_action *action, ++ struct rte_flow_error *error) ++{ ++ struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private); ++ struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private); ++ const struct rte_flow_action_count *act_count; ++ struct rte_flow_action_handle *handle = NULL; ++ struct hns3_flow_counter *counter; ++ ++ if (hns3_check_indir_action(conf, action, error)) ++ return NULL; ++ ++ handle = rte_zmalloc("hns3 action handle", ++ sizeof(struct rte_flow_action_handle), 0); ++ if (handle == NULL) { ++ rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE, ++ NULL, "Failed to allocate action memory"); ++ return NULL; ++ } ++ ++ pthread_mutex_lock(&hw->flows_lock); ++ ++ act_count = (const struct rte_flow_action_count *)action->conf; ++ if (act_count->id >= pf->fdir.fd_cfg.cnt_num[HNS3_FD_STAGE_1]) { ++ rte_flow_error_set(error, EINVAL, ++ RTE_FLOW_ERROR_TYPE_ACTION_CONF, ++ action, "Invalid counter id"); ++ goto err_exit; ++ } ++ ++ if (hns3_counter_new(dev, false, act_count->id, error)) ++ goto err_exit; ++ ++ counter = hns3_counter_lookup(dev, act_count->id); ++ if (counter == NULL) { ++ rte_flow_error_set(error, EINVAL, ++ RTE_FLOW_ERROR_TYPE_ACTION_CONF, ++ action, "Counter id not found"); ++ goto err_exit; ++ } ++ ++ counter->indirect = true; ++ handle->indirect_type = HNS3_INDIRECT_ACTION_TYPE_COUNT; ++ handle->counter_id = counter->id; ++ ++ pthread_mutex_unlock(&hw->flows_lock); ++ return handle; ++ ++err_exit: ++ pthread_mutex_unlock(&hw->flows_lock); ++ rte_free(handle); ++ return NULL; ++} ++ ++static int ++hns3_flow_action_destroy(struct rte_eth_dev *dev, ++ struct rte_flow_action_handle *handle, ++ struct rte_flow_error *error) ++{ ++ struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private); ++ struct hns3_flow_counter *counter; ++ ++ pthread_mutex_lock(&hw->flows_lock); ++ ++ if (handle->indirect_type != HNS3_INDIRECT_ACTION_TYPE_COUNT) { ++ pthread_mutex_unlock(&hw->flows_lock); ++ return rte_flow_error_set(error, EINVAL, ++ RTE_FLOW_ERROR_TYPE_ACTION_CONF, ++ handle, "Invalid indirect type"); ++ } ++ ++ counter = hns3_counter_lookup(dev, handle->counter_id); ++ if (counter == NULL) { ++ pthread_mutex_unlock(&hw->flows_lock); ++ return rte_flow_error_set(error, EINVAL, ++ RTE_FLOW_ERROR_TYPE_ACTION_CONF, ++ handle, "Counter id not exist"); ++ } ++ ++ if (counter->ref_cnt > 1) { ++ pthread_mutex_unlock(&hw->flows_lock); ++ return rte_flow_error_set(error, EBUSY, ++ RTE_FLOW_ERROR_TYPE_HANDLE, ++ handle, "Counter id in use"); ++ } ++ ++ (void)hns3_counter_release(dev, handle->counter_id); ++ rte_free(handle); ++ ++ pthread_mutex_unlock(&hw->flows_lock); ++ return 0; ++} ++ ++static int ++hns3_flow_action_query(struct rte_eth_dev *dev, ++ const struct rte_flow_action_handle *handle, ++ void *data, ++ struct rte_flow_error *error) ++{ ++ struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private); ++ struct rte_flow flow; ++ int ret; ++ ++ pthread_mutex_lock(&hw->flows_lock); ++ ++ if (handle->indirect_type != HNS3_INDIRECT_ACTION_TYPE_COUNT) { ++ pthread_mutex_unlock(&hw->flows_lock); ++ return rte_flow_error_set(error, EINVAL, ++ RTE_FLOW_ERROR_TYPE_ACTION_CONF, ++ handle, "Invalid indirect type"); ++ } ++ ++ memset(&flow, 0, sizeof(flow)); ++ flow.counter_id = handle->counter_id; ++ ret = hns3_counter_query(dev, &flow, ++ (struct rte_flow_query_count *)data, error); ++ pthread_mutex_unlock(&hw->flows_lock); ++ return ret; ++} ++ + static const struct rte_flow_ops hns3_flow_ops = { + .validate = hns3_flow_validate_wrap, + .create = hns3_flow_create_wrap, +@@ -2093,6 +2294,9 @@ static const struct rte_flow_ops hns3_flow_ops = { + .flush = hns3_flow_flush_wrap, + .query = hns3_flow_query_wrap, + .isolate = NULL, ++ .action_handle_create = hns3_flow_action_create, ++ .action_handle_destroy = hns3_flow_action_destroy, ++ .action_handle_query = hns3_flow_action_query, + }; + + int +diff --git a/drivers/net/hns3/hns3_flow.h b/drivers/net/hns3/hns3_flow.h +index 2eb451b720..1ab3f9f5c6 100644 +--- a/drivers/net/hns3/hns3_flow.h ++++ b/drivers/net/hns3/hns3_flow.h +@@ -9,7 +9,7 @@ + + struct hns3_flow_counter { + LIST_ENTRY(hns3_flow_counter) next; /* Pointer to the next counter. */ +- uint32_t shared:1; /* Share counter ID with other flow rules. */ ++ uint32_t indirect:1; /* Indirect counter flag */ + uint32_t ref_cnt:31; /* Reference counter. */ + uint16_t id; /* Counter ID. */ + uint64_t hits; /* Number of packets matched by the rule. */ +@@ -33,6 +33,15 @@ struct hns3_flow_mem { + struct rte_flow *flow; + }; + ++enum { ++ HNS3_INDIRECT_ACTION_TYPE_COUNT = 1, ++}; ++ ++struct rte_flow_action_handle { ++ int indirect_type; ++ uint32_t counter_id; ++}; ++ + TAILQ_HEAD(hns3_rss_filter_list, hns3_rss_conf_ele); + TAILQ_HEAD(hns3_flow_mem_list, hns3_flow_mem); + +-- +2.33.0 + diff --git a/0037-net-hns3-fix-max-packet-size-rollback-in-PF.patch b/0037-net-hns3-fix-max-packet-size-rollback-in-PF.patch new file mode 100644 index 0000000000000000000000000000000000000000..c825a461ae79c660681dd442cd5702fadb1cfa67 --- /dev/null +++ b/0037-net-hns3-fix-max-packet-size-rollback-in-PF.patch @@ -0,0 +1,63 @@ +From dc55ce9c6253664160b881a1b83b2b4f1e90a587 Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Fri, 28 Jan 2022 10:07:03 +0800 +Subject: [PATCH] net/hns3: fix max packet size rollback in PF + +HNS3 PF driver use the hns->pf.mps to restore the MTU when a reset +occurs. +If user fails to configure the MTU, the MPS of PF may not be restored to +the original value. + +Fixes: 25fb790f7868 ("net/hns3: fix HW buffer size on MTU update") +Fixes: 1f5ca0b460cd ("net/hns3: support some device operations") +Fixes: d51867db65c1 ("net/hns3: add initialization") +Cc: stable@dpdk.org + +Signed-off-by: Huisong Li +Signed-off-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_ethdev.c | 11 ++++------- + 1 file changed, 4 insertions(+), 7 deletions(-) + +diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c +index a5114662d2..73bf209717 100644 +--- a/drivers/net/hns3/hns3_ethdev.c ++++ b/drivers/net/hns3/hns3_ethdev.c +@@ -2075,7 +2075,6 @@ static int + hns3_config_mtu(struct hns3_hw *hw, uint16_t mps) + { + struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw); +- uint16_t original_mps = hns->pf.mps; + int err; + int ret; + +@@ -2085,22 +2084,20 @@ hns3_config_mtu(struct hns3_hw *hw, uint16_t mps) + return ret; + } + +- hns->pf.mps = mps; + ret = hns3_buffer_alloc(hw); + if (ret) { + hns3_err(hw, "failed to allocate buffer, ret = %d", ret); + goto rollback; + } + ++ hns->pf.mps = mps; ++ + return 0; + + rollback: +- err = hns3_set_mac_mtu(hw, original_mps); +- if (err) { ++ err = hns3_set_mac_mtu(hw, hns->pf.mps); ++ if (err) + hns3_err(hw, "fail to rollback MTU, err = %d", err); +- return ret; +- } +- hns->pf.mps = original_mps; + + return ret; + } +-- +2.33.0 + diff --git a/0038-net-hns3-fix-RSS-key-with-null.patch b/0038-net-hns3-fix-RSS-key-with-null.patch new file mode 100644 index 0000000000000000000000000000000000000000..e96ce2813afb292eea9a1a445ea13b9bc1f653f4 --- /dev/null +++ b/0038-net-hns3-fix-RSS-key-with-null.patch @@ -0,0 +1,57 @@ +From ca937bfe5f48de028c25312bcdb30ec1a6a4cd8e Mon Sep 17 00:00:00 2001 +From: Lijun Ou +Date: Fri, 28 Jan 2022 10:07:04 +0800 +Subject: [PATCH] net/hns3: fix RSS key with null + +Since the patch '1848b117' has initialized the variable 'key' in +'struct rte_flow_action_rss' with 'NULL', the PMD will use the +default RSS key when create the first RSS rule with NULL RSS key. +Then, if create a repeated RSS rule with the above, it will not +identify duplicate rules and return an error message. + +To solve the preceding problem, determine whether the current RSS keys +are the same based on whether the length of key_len of rss is 0. + +Fixes: 1848b117cca1 ("app/testpmd: fix RSS key for flow API RSS rule") +Cc: stable@dpdk.org + +Signed-off-by: Lijun Ou +--- + drivers/net/hns3/hns3_flow.c | 12 +++++++++--- + 1 file changed, 9 insertions(+), 3 deletions(-) + +diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c +index 56ef6f57b2..aba07aaa6f 100644 +--- a/drivers/net/hns3/hns3_flow.c ++++ b/drivers/net/hns3/hns3_flow.c +@@ -1286,6 +1286,7 @@ static bool + hns3_action_rss_same(const struct rte_flow_action_rss *comp, + const struct rte_flow_action_rss *with) + { ++ bool rss_key_is_same; + bool func_is_same; + + /* +@@ -1302,11 +1303,16 @@ hns3_action_rss_same(const struct rte_flow_action_rss *comp, + func_is_same = (with->func != RTE_ETH_HASH_FUNCTION_DEFAULT) ? + (comp->func == with->func) : true; + +- return (func_is_same && ++ if (with->key_len == 0 || with->key == NULL) ++ rss_key_is_same = 1; ++ else ++ rss_key_is_same = comp->key_len == with->key_len && ++ !memcmp(comp->key, with->key, with->key_len); ++ ++ return (func_is_same && rss_key_is_same && + comp->types == (with->types & HNS3_ETH_RSS_SUPPORT) && +- comp->level == with->level && comp->key_len == with->key_len && ++ comp->level == with->level && + comp->queue_num == with->queue_num && +- !memcmp(comp->key, with->key, with->key_len) && + !memcmp(comp->queue, with->queue, + sizeof(*with->queue) * with->queue_num)); + } +-- +2.33.0 + diff --git a/0039-net-hns3-fix-insecure-way-to-query-MAC-statistics.patch b/0039-net-hns3-fix-insecure-way-to-query-MAC-statistics.patch new file mode 100644 index 0000000000000000000000000000000000000000..da6c6f55b55a711906fadc360531ca1d1c7e2def --- /dev/null +++ b/0039-net-hns3-fix-insecure-way-to-query-MAC-statistics.patch @@ -0,0 +1,271 @@ +From a29f3b66f858a7e2fabcb6b557aea7bde17d41fb Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Fri, 28 Jan 2022 10:07:05 +0800 +Subject: [PATCH] net/hns3: fix insecure way to query MAC statistics + +The query way of MAC statistics in HNS3 PF driver is as following: +1) get MAC statistics register number and calculate descriptor number. +2) use above descriptor number to send command to firmware to query all + MAC statistics and copy to hns3_mac_stats struct in driver. + +The preceding way does not verify the validity of the number of obtained +register, which may cause memory out-of-bounds. + +Fixes: 8839c5e202f3 ("net/hns3: support device stats") +Cc: stable@dpdk.org + +Signed-off-by: Huisong Li +Signed-off-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_ethdev.c | 4 ++ + drivers/net/hns3/hns3_ethdev.h | 1 + + drivers/net/hns3/hns3_stats.c | 116 ++++++++++++++++----------------- + drivers/net/hns3/hns3_stats.h | 11 ++-- + 4 files changed, 65 insertions(+), 67 deletions(-) + +diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c +index 73bf209717..57f1572340 100644 +--- a/drivers/net/hns3/hns3_ethdev.c ++++ b/drivers/net/hns3/hns3_ethdev.c +@@ -2733,6 +2733,10 @@ hns3_get_capability(struct hns3_hw *hw) + if (ret) + return ret; + ++ ret = hns3_query_mac_stats_reg_num(hw); ++ if (ret) ++ return ret; ++ + if (hw->revision < PCI_REVISION_ID_HIP09_A) { + hns3_set_default_dev_specifications(hw); + hw->intr.mapping_mode = HNS3_INTR_MAPPING_VEC_RSV_ONE; +diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h +index cf6380ebb2..ef028a7b2c 100644 +--- a/drivers/net/hns3/hns3_ethdev.h ++++ b/drivers/net/hns3/hns3_ethdev.h +@@ -500,6 +500,7 @@ struct hns3_hw { + struct hns3_tqp_stats tqp_stats; + /* Include Mac stats | Rx stats | Tx stats */ + struct hns3_mac_stats mac_stats; ++ uint32_t mac_stats_reg_num; + struct hns3_rx_missed_stats imissed_stats; + uint64_t oerror_stats; + uint32_t fw_version; +diff --git a/drivers/net/hns3/hns3_stats.c b/drivers/net/hns3/hns3_stats.c +index 606b72509a..806720faff 100644 +--- a/drivers/net/hns3/hns3_stats.c ++++ b/drivers/net/hns3/hns3_stats.c +@@ -307,24 +307,21 @@ static const struct hns3_xstats_name_offset hns3_imissed_stats_strings[] = { + + static void hns3_tqp_stats_clear(struct hns3_hw *hw); + +-/* +- * Query all the MAC statistics data of Network ICL command ,opcode id: 0x0034. +- * This command is used before send 'query_mac_stat command', the descriptor +- * number of 'query_mac_stat command' must match with reg_num in this command. +- * @praram hw +- * Pointer to structure hns3_hw. +- * @return +- * 0 on success. +- */ + static int +-hns3_update_mac_stats(struct hns3_hw *hw, const uint32_t desc_num) ++hns3_update_mac_stats(struct hns3_hw *hw) + { ++#define HNS3_MAC_STATS_REG_NUM_PER_DESC 4 ++ + uint64_t *data = (uint64_t *)(&hw->mac_stats); + struct hns3_cmd_desc *desc; ++ uint32_t stats_iterms; + uint64_t *desc_data; +- uint16_t i, k, n; ++ uint32_t desc_num; ++ uint16_t i; + int ret; + ++ /* The first desc has a 64-bit header, so need to consider it. */ ++ desc_num = hw->mac_stats_reg_num / HNS3_MAC_STATS_REG_NUM_PER_DESC + 1; + desc = rte_malloc("hns3_mac_desc", + desc_num * sizeof(struct hns3_cmd_desc), 0); + if (desc == NULL) { +@@ -340,65 +337,71 @@ hns3_update_mac_stats(struct hns3_hw *hw, const uint32_t desc_num) + return ret; + } + +- for (i = 0; i < desc_num; i++) { +- /* For special opcode 0034, only the first desc has the head */ +- if (i == 0) { +- desc_data = (uint64_t *)(&desc[i].data[0]); +- n = HNS3_RD_FIRST_STATS_NUM; +- } else { +- desc_data = (uint64_t *)(&desc[i]); +- n = HNS3_RD_OTHER_STATS_NUM; +- } +- +- for (k = 0; k < n; k++) { +- *data += rte_le_to_cpu_64(*desc_data); +- data++; +- desc_data++; +- } ++ stats_iterms = RTE_MIN(sizeof(hw->mac_stats) / sizeof(uint64_t), ++ hw->mac_stats_reg_num); ++ desc_data = (uint64_t *)(&desc[0].data[0]); ++ for (i = 0; i < stats_iterms; i++) { ++ /* ++ * Data memory is continuous and only the first descriptor has a ++ * header in this command. ++ */ ++ *data += rte_le_to_cpu_64(*desc_data); ++ data++; ++ desc_data++; + } + rte_free(desc); + + return 0; + } + +-/* +- * Query Mac stat reg num command ,opcode id: 0x0033. +- * This command is used before send 'query_mac_stat command', the descriptor +- * number of 'query_mac_stat command' must match with reg_num in this command. +- * @praram rte_stats +- * Pointer to structure rte_eth_stats. +- * @return +- * 0 on success. +- */ + static int +-hns3_mac_query_reg_num(struct rte_eth_dev *dev, uint32_t *desc_num) ++hns3_mac_query_reg_num(struct hns3_hw *hw, uint32_t *reg_num) + { +- struct hns3_adapter *hns = dev->data->dev_private; +- struct hns3_hw *hw = &hns->hw; ++#define HNS3_MAC_STATS_RSV_REG_NUM_ON_HIP08_B 3 + struct hns3_cmd_desc desc; +- uint32_t *desc_data; +- uint32_t reg_num; + int ret; + + hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_QUERY_MAC_REG_NUM, true); + ret = hns3_cmd_send(hw, &desc, 1); +- if (ret) ++ if (ret) { ++ hns3_err(hw, "failed to query MAC statistic reg number, ret = %d", ++ ret); + return ret; ++ } + +- /* +- * The num of MAC statistics registers that are provided by IMP in this +- * version. +- */ +- desc_data = (uint32_t *)(&desc.data[0]); +- reg_num = rte_le_to_cpu_32(*desc_data); ++ /* The number of MAC statistics registers are provided by firmware. */ ++ *reg_num = rte_le_to_cpu_32(desc.data[0]); ++ if (*reg_num == 0) { ++ hns3_err(hw, "MAC statistic reg number is invalid!"); ++ return -ENODATA; ++ } + + /* +- * The descriptor number of 'query_additional_mac_stat command' is +- * '1 + (reg_num-3)/4 + ((reg_num-3)%4 !=0)'; +- * This value is 83 in this version ++ * If driver doesn't request the firmware to report more MAC statistics ++ * iterms and the total number of MAC statistics registers by using new ++ * method, firmware will only reports the number of valid statistics ++ * registers. However, structure hns3_mac_stats in driver contains valid ++ * and reserved statistics iterms. In this case, the total register ++ * number must be added to three reserved statistics registers. + */ +- *desc_num = 1 + ((reg_num - 3) >> 2) + +- (uint32_t)(((reg_num - 3) & 0x3) ? 1 : 0); ++ *reg_num += HNS3_MAC_STATS_RSV_REG_NUM_ON_HIP08_B; ++ ++ return 0; ++} ++ ++int ++hns3_query_mac_stats_reg_num(struct hns3_hw *hw) ++{ ++ uint32_t mac_stats_reg_num = 0; ++ int ret; ++ ++ ret = hns3_mac_query_reg_num(hw, &mac_stats_reg_num); ++ if (ret) ++ return ret; ++ ++ hw->mac_stats_reg_num = mac_stats_reg_num; ++ if (hw->mac_stats_reg_num > sizeof(hw->mac_stats) / sizeof(uint64_t)) ++ hns3_warn(hw, "MAC stats reg number from firmware is greater than stats iterms in driver."); + + return 0; + } +@@ -408,15 +411,8 @@ hns3_query_update_mac_stats(struct rte_eth_dev *dev) + { + struct hns3_adapter *hns = dev->data->dev_private; + struct hns3_hw *hw = &hns->hw; +- uint32_t desc_num; +- int ret; + +- ret = hns3_mac_query_reg_num(dev, &desc_num); +- if (ret == 0) +- ret = hns3_update_mac_stats(hw, desc_num); +- else +- hns3_err(hw, "Query mac reg num fail : %d", ret); +- return ret; ++ return hns3_update_mac_stats(hw); + } + + static int +diff --git a/drivers/net/hns3/hns3_stats.h b/drivers/net/hns3/hns3_stats.h +index d1230f94cb..c81d351082 100644 +--- a/drivers/net/hns3/hns3_stats.h ++++ b/drivers/net/hns3/hns3_stats.h +@@ -5,11 +5,6 @@ + #ifndef _HNS3_STATS_H_ + #define _HNS3_STATS_H_ + +-/* stats macro */ +-#define HNS3_MAC_CMD_NUM 21 +-#define HNS3_RD_FIRST_STATS_NUM 2 +-#define HNS3_RD_OTHER_STATS_NUM 4 +- + /* TQP stats */ + struct hns3_tqp_stats { + uint64_t rcb_tx_ring_pktnum_rcd; /* Total num of transmitted packets */ +@@ -22,6 +17,7 @@ struct hns3_tqp_stats { + struct hns3_mac_stats { + uint64_t mac_tx_mac_pause_num; + uint64_t mac_rx_mac_pause_num; ++ uint64_t rsv0; + uint64_t mac_tx_pfc_pri0_pkt_num; + uint64_t mac_tx_pfc_pri1_pkt_num; + uint64_t mac_tx_pfc_pri2_pkt_num; +@@ -58,7 +54,7 @@ struct hns3_mac_stats { + uint64_t mac_tx_1519_2047_oct_pkt_num; + uint64_t mac_tx_2048_4095_oct_pkt_num; + uint64_t mac_tx_4096_8191_oct_pkt_num; +- uint64_t rsv0; ++ uint64_t rsv1; + uint64_t mac_tx_8192_9216_oct_pkt_num; + uint64_t mac_tx_9217_12287_oct_pkt_num; + uint64_t mac_tx_12288_16383_oct_pkt_num; +@@ -85,7 +81,7 @@ struct hns3_mac_stats { + uint64_t mac_rx_1519_2047_oct_pkt_num; + uint64_t mac_rx_2048_4095_oct_pkt_num; + uint64_t mac_rx_4096_8191_oct_pkt_num; +- uint64_t rsv1; ++ uint64_t rsv2; + uint64_t mac_rx_8192_9216_oct_pkt_num; + uint64_t mac_rx_9217_12287_oct_pkt_num; + uint64_t mac_rx_12288_16383_oct_pkt_num; +@@ -168,5 +164,6 @@ int hns3_stats_reset(struct rte_eth_dev *dev); + int hns3_tqp_stats_init(struct hns3_hw *hw); + void hns3_tqp_stats_uninit(struct hns3_hw *hw); + int hns3_update_imissed_stats(struct hns3_hw *hw, bool is_clear); ++int hns3_query_mac_stats_reg_num(struct hns3_hw *hw); + + #endif /* _HNS3_STATS_H_ */ +-- +2.33.0 + diff --git a/0040-net-hns3-fix-double-decrement-of-secondary-count.patch b/0040-net-hns3-fix-double-decrement-of-secondary-count.patch new file mode 100644 index 0000000000000000000000000000000000000000..e6121907471b9e80b45cd728b03b8c582a9374b0 --- /dev/null +++ b/0040-net-hns3-fix-double-decrement-of-secondary-count.patch @@ -0,0 +1,33 @@ +From eb0bbc8fbec6bb10dfcfdca470dc413038e8608c Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Fri, 28 Jan 2022 10:07:06 +0800 +Subject: [PATCH] net/hns3: fix double decrement of secondary count + +The "secondary_cnt" indicates the number of secondary processes on an +Ethernet device. But the variable is double subtracted when detach the +device in secondary processes. + +Fixes: ff6dc76e40b8 ("net/hns3: refactor multi-process initialization") +Cc: stable@dpdk.org + +Signed-off-by: Huisong Li +Signed-off-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_ethdev_vf.c | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c +index 1af2e07e81..dab1130dad 100644 +--- a/drivers/net/hns3/hns3_ethdev_vf.c ++++ b/drivers/net/hns3/hns3_ethdev_vf.c +@@ -2399,7 +2399,6 @@ hns3vf_dev_uninit(struct rte_eth_dev *eth_dev) + PMD_INIT_FUNC_TRACE(); + + if (rte_eal_process_type() != RTE_PROC_PRIMARY) { +- __atomic_fetch_sub(&hw->secondary_cnt, 1, __ATOMIC_RELAXED); + hns3_mp_uninit(eth_dev); + return 0; + } +-- +2.33.0 + diff --git a/0041-net-hns3-fix-operating-queue-when-TCAM-table-is-inva.patch b/0041-net-hns3-fix-operating-queue-when-TCAM-table-is-inva.patch new file mode 100644 index 0000000000000000000000000000000000000000..95b77f7c492b34ec9d1a677417a47fbce10c3c2b --- /dev/null +++ b/0041-net-hns3-fix-operating-queue-when-TCAM-table-is-inva.patch @@ -0,0 +1,57 @@ +From 1c73c33c5ff07ac2a369f0d796e5892ed504e0d3 Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Fri, 28 Jan 2022 10:07:07 +0800 +Subject: [PATCH] net/hns3: fix operating queue when TCAM table is invalid + +Reset queues will query the TCAM table. The table is cleared after global +or imp reset. Currently, PF driver first resets Rx/Tx queues and then +restore the table during the reset recovery process, which will fail to +query the table and trigger a RAS error. + +Fixes: fa29fe45a7b4 ("net/hns3: support queue start and stop") +Cc: stable@dpdk.org + +Signed-off-by: Huisong Li +Signed-off-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_ethdev.c | 12 ++++++++---- + 1 file changed, 8 insertions(+), 4 deletions(-) + +diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c +index 57f1572340..2641b6f79b 100644 +--- a/drivers/net/hns3/hns3_ethdev.c ++++ b/drivers/net/hns3/hns3_ethdev.c +@@ -4378,6 +4378,10 @@ hns3_init_hardware(struct hns3_adapter *hns) + struct hns3_hw *hw = &hns->hw; + int ret; + ++ /* ++ * All queue-related HW operations must be performed after the TCAM ++ * table is configured. ++ */ + ret = hns3_map_tqp(hw); + if (ret) { + PMD_INIT_LOG(ERR, "Failed to map tqp: %d", ret); +@@ -5547,15 +5551,15 @@ hns3_reinit_dev(struct hns3_adapter *hns) + return ret; + } + +- ret = hns3_reset_all_tqps(hns); ++ ret = hns3_init_hardware(hns); + if (ret) { +- hns3_err(hw, "Failed to reset all queues: %d", ret); ++ hns3_err(hw, "Failed to init hardware: %d", ret); + return ret; + } + +- ret = hns3_init_hardware(hns); ++ ret = hns3_reset_all_tqps(hns); + if (ret) { +- hns3_err(hw, "Failed to init hardware: %d", ret); ++ hns3_err(hw, "Failed to reset all queues: %d", ret); + return ret; + } + +-- +2.33.0 + diff --git a/0042-net-hns3-delete-duplicated-RSS-type.patch b/0042-net-hns3-delete-duplicated-RSS-type.patch new file mode 100644 index 0000000000000000000000000000000000000000..3adec9379a0817f9e7b5a021fc45c65c19d6d60f --- /dev/null +++ b/0042-net-hns3-delete-duplicated-RSS-type.patch @@ -0,0 +1,35 @@ +From 6c3c017f980084daef4ddafd111e9ed9aa9619c3 Mon Sep 17 00:00:00 2001 +From: Chengwen Feng +Date: Fri, 28 Jan 2022 10:07:08 +0800 +Subject: [PATCH] net/hns3: delete duplicated RSS type + +The hns3_set_rss_types hold two IPV4_TCP items, this patch deletes +duplicate item. + +Fixes: 806f1d5ab0e3 ("net/hns3: set RSS hash type input configuration") +Cc: stable@dpdk.org + +Signed-off-by: Chengwen Feng +Signed-off-by: Min Hu (Connor) +--- + drivers/net/hns3/hns3_rss.c | 4 ---- + 1 file changed, 4 deletions(-) + +diff --git a/drivers/net/hns3/hns3_rss.c b/drivers/net/hns3/hns3_rss.c +index 3a4b699ae2..1782d63883 100644 +--- a/drivers/net/hns3/hns3_rss.c ++++ b/drivers/net/hns3/hns3_rss.c +@@ -152,10 +152,6 @@ static const struct { + BIT_ULL(HNS3_RSS_FIELD_IPV4_TCP_EN_IP_D) | + BIT_ULL(HNS3_RSS_FIELD_IPV4_TCP_EN_TCP_S) | + BIT_ULL(HNS3_RSS_FIELD_IPV4_TCP_EN_TCP_D) }, +- { RTE_ETH_RSS_NONFRAG_IPV4_TCP, BIT_ULL(HNS3_RSS_FIELD_IPV4_TCP_EN_IP_S) | +- BIT_ULL(HNS3_RSS_FIELD_IPV4_TCP_EN_IP_D) | +- BIT_ULL(HNS3_RSS_FIELD_IPV4_TCP_EN_TCP_S) | +- BIT_ULL(HNS3_RSS_FIELD_IPV4_TCP_EN_TCP_D) }, + { RTE_ETH_RSS_NONFRAG_IPV4_UDP, BIT_ULL(HNS3_RSS_FIELD_IPV4_UDP_EN_IP_S) | + BIT_ULL(HNS3_RSS_FIELD_IPV4_UDP_EN_IP_D) | + BIT_ULL(HNS3_RSS_FIELD_IPV4_UDP_EN_UDP_S) | +-- +2.33.0 + diff --git a/0043-net-bonding-fix-promiscuous-and-allmulticast-state.patch b/0043-net-bonding-fix-promiscuous-and-allmulticast-state.patch new file mode 100644 index 0000000000000000000000000000000000000000..94183f77659bb25843237bd43c88ab9040678125 --- /dev/null +++ b/0043-net-bonding-fix-promiscuous-and-allmulticast-state.patch @@ -0,0 +1,130 @@ +From 905b76987bd194e1356e6fe79949b5119c30f842 Mon Sep 17 00:00:00 2001 +From: "Min Hu (Connor)" +Date: Fri, 28 Jan 2022 10:25:32 +0800 +Subject: [PATCH] net/bonding: fix promiscuous and allmulticast state + +Currently, promiscuous or allmulticast state of bonding port will not be +passed to the new primary slave when active/standby switch-over. It +causes bugs in some scenario. + +For example, promiscuous state of bonding port is off now, primary slave +(called A) is off but secondary slave(called B) is on. +Then active/standby switch-over, promiscuous state of the bonding port +is off, but the new primary slave turns to be B and its promiscuous +state is still on. +It is not consistent with bonding port. And this patch will fix it. + +Fixes: 2efb58cbab6e ("bond: new link bonding library") +Fixes: 68218b87c184 ("net/bonding: prefer allmulti to promiscuous for LACP") +Cc: stable@dpdk.org + +Signed-off-by: Min Hu (Connor) +--- + drivers/net/bonding/rte_eth_bond_pmd.c | 70 ++++++++++++++++++++++++++ + 1 file changed, 70 insertions(+) + +diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c +index e5abe90e07..d2fcfad676 100644 +--- a/drivers/net/bonding/rte_eth_bond_pmd.c ++++ b/drivers/net/bonding/rte_eth_bond_pmd.c +@@ -2691,6 +2691,39 @@ bond_ethdev_promiscuous_disable(struct rte_eth_dev *dev) + return ret; + } + ++static int ++bond_ethdev_promiscuous_update(struct rte_eth_dev *dev) ++{ ++ struct bond_dev_private *internals = dev->data->dev_private; ++ uint16_t port_id = internals->current_primary_port; ++ ++ switch (internals->mode) { ++ case BONDING_MODE_ROUND_ROBIN: ++ case BONDING_MODE_BALANCE: ++ case BONDING_MODE_BROADCAST: ++ case BONDING_MODE_8023AD: ++ /* As promiscuous mode is propagated to all slaves for these ++ * mode, no need to update for bonding device. ++ */ ++ break; ++ case BONDING_MODE_ACTIVE_BACKUP: ++ case BONDING_MODE_TLB: ++ case BONDING_MODE_ALB: ++ default: ++ /* As promiscuous mode is propagated only to primary slave ++ * for these mode. When active/standby switchover, promiscuous ++ * mode should be set to new primary slave according to bonding ++ * device. ++ */ ++ if (rte_eth_promiscuous_get(internals->port_id) == 1) ++ rte_eth_promiscuous_enable(port_id); ++ else ++ rte_eth_promiscuous_disable(port_id); ++ } ++ ++ return 0; ++} ++ + static int + bond_ethdev_allmulticast_enable(struct rte_eth_dev *eth_dev) + { +@@ -2804,6 +2837,39 @@ bond_ethdev_allmulticast_disable(struct rte_eth_dev *eth_dev) + return ret; + } + ++static int ++bond_ethdev_allmulticast_update(struct rte_eth_dev *dev) ++{ ++ struct bond_dev_private *internals = dev->data->dev_private; ++ uint16_t port_id = internals->current_primary_port; ++ ++ switch (internals->mode) { ++ case BONDING_MODE_ROUND_ROBIN: ++ case BONDING_MODE_BALANCE: ++ case BONDING_MODE_BROADCAST: ++ case BONDING_MODE_8023AD: ++ /* As allmulticast mode is propagated to all slaves for these ++ * mode, no need to update for bonding device. ++ */ ++ break; ++ case BONDING_MODE_ACTIVE_BACKUP: ++ case BONDING_MODE_TLB: ++ case BONDING_MODE_ALB: ++ default: ++ /* As allmulticast mode is propagated only to primary slave ++ * for these mode. When active/standby switchover, allmulticast ++ * mode should be set to new primary slave according to bonding ++ * device. ++ */ ++ if (rte_eth_allmulticast_get(internals->port_id) == 1) ++ rte_eth_allmulticast_enable(port_id); ++ else ++ rte_eth_allmulticast_disable(port_id); ++ } ++ ++ return 0; ++} ++ + static void + bond_ethdev_delayed_lsc_propagation(void *arg) + { +@@ -2893,6 +2959,8 @@ bond_ethdev_lsc_event_callback(uint16_t port_id, enum rte_eth_event_type type, + lsc_flag = 1; + + mac_address_slaves_update(bonded_eth_dev); ++ bond_ethdev_promiscuous_update(bonded_eth_dev); ++ bond_ethdev_allmulticast_update(bonded_eth_dev); + } + + activate_slave(bonded_eth_dev, port_id); +@@ -2922,6 +2990,8 @@ bond_ethdev_lsc_event_callback(uint16_t port_id, enum rte_eth_event_type type, + else + internals->current_primary_port = internals->primary_port; + mac_address_slaves_update(bonded_eth_dev); ++ bond_ethdev_promiscuous_update(bonded_eth_dev); ++ bond_ethdev_allmulticast_update(bonded_eth_dev); + } + } + +-- +2.33.0 + diff --git a/0044-net-bonding-fix-reference-count-on-mbufs.patch b/0044-net-bonding-fix-reference-count-on-mbufs.patch new file mode 100644 index 0000000000000000000000000000000000000000..5085cc67372e523719e2fee77f48f00497764d18 --- /dev/null +++ b/0044-net-bonding-fix-reference-count-on-mbufs.patch @@ -0,0 +1,36 @@ +From 2c1857b46ec66643f127301b9466a3b93fa2d42b Mon Sep 17 00:00:00 2001 +From: "Min Hu (Connor)" +Date: Fri, 28 Jan 2022 10:25:33 +0800 +Subject: [PATCH] net/bonding: fix reference count on mbufs + +In bonding Tx broadcast mode, Packets should be sent by every slave, +but only one mbuf exits. The solution is to increment reference count +on mbufs, but it ignores multi segments. + +This patch fixed it by adding reference for every segment in multi +segments Tx scenario. + +Fixes: 2efb58cbab6e ("bond: new link bonding library") +Cc: stable@dpdk.org + +Signed-off-by: Min Hu (Connor) +--- + drivers/net/bonding/rte_eth_bond_pmd.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c +index d2fcfad676..bfa931098e 100644 +--- a/drivers/net/bonding/rte_eth_bond_pmd.c ++++ b/drivers/net/bonding/rte_eth_bond_pmd.c +@@ -1318,7 +1318,7 @@ bond_ethdev_tx_burst_broadcast(void *queue, struct rte_mbuf **bufs, + + /* Increment reference count on mbufs */ + for (i = 0; i < nb_pkts; i++) +- rte_mbuf_refcnt_update(bufs[i], num_of_slaves - 1); ++ rte_pktmbuf_refcnt_update(bufs[i], num_of_slaves - 1); + + /* Transmit burst on each active slave */ + for (i = 0; i < num_of_slaves; i++) { +-- +2.33.0 + diff --git a/0045-app-testpmd-fix-bonding-mode-set.patch b/0045-app-testpmd-fix-bonding-mode-set.patch new file mode 100644 index 0000000000000000000000000000000000000000..572f66625357b2f917710ce5763d507ecc5a3c5e --- /dev/null +++ b/0045-app-testpmd-fix-bonding-mode-set.patch @@ -0,0 +1,70 @@ +From 32d1817dbff6499dd1d126c466d0f7cb1c114713 Mon Sep 17 00:00:00 2001 +From: "Min Hu (Connor)" +Date: Fri, 28 Jan 2022 10:35:19 +0800 +Subject: [PATCH] app/testpmd: fix bonding mode set + +when start testpmd, and type command like this, it will lead to +Segmentation fault, like: + +testpmd> create bonded device 4 0 +testpmd> add bonding slave 0 2 +testpmd> add bonding slave 1 2 +testpmd> port start 2 +testpmd> set bonding mode 0 2 +testpmd> quit +Stopping port 0... +Stopping ports... +... +Bye... +Segmentation fault + +The reason to the bug is that rte timer do not be cancelled when quit. +That is, in 'bond_ethdev_start', resources are allocated according to +different bonding mode. In 'bond_ethdev_stop', resources are free by +the corresponding mode. + +For example, 'bond_ethdev_start' start bond_mode_8023ad_ext_periodic_cb +timer for bonding mode 4. and 'bond_ethdev_stop' cancel the timer only +when the current bonding mode is 4. If the bonding mode is changed, +and directly quit the process, the timer will still on, and freed memory +will be accessed, then segmentation fault. + +'bonding mode' changed means resources changed, reallocate resources for +different mode should be done, that is, device should be restarted. + +Fixes: 2950a769315e ("bond: testpmd support") +Cc: stable@dpdk.org + +Signed-off-by: Min Hu (Connor) +Tested-by: Ferruh Yigit +--- + app/test-pmd/cmdline.c | 13 +++++++++++++ + 1 file changed, 13 insertions(+) + +diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c +index e626b1c7d9..16ad4be005 100644 +--- a/app/test-pmd/cmdline.c ++++ b/app/test-pmd/cmdline.c +@@ -5915,6 +5915,19 @@ static void cmd_set_bonding_mode_parsed(void *parsed_result, + { + struct cmd_set_bonding_mode_result *res = parsed_result; + portid_t port_id = res->port_id; ++ struct rte_port *port = &ports[port_id]; ++ ++ /* ++ * Bonding mode changed means resources of device changed, like whether ++ * started rte timer or not. Device should be restarted when resources ++ * of device changed. ++ */ ++ if (port->port_status != RTE_PORT_STOPPED) { ++ fprintf(stderr, ++ "\t Error: Can't set bonding mode when port %d is not stopped\n", ++ port_id); ++ return; ++ } + + /* Set the bonding mode for the relevant port. */ + if (0 != rte_eth_bond_mode_set(port_id, res->value)) +-- +2.33.0 + diff --git a/dpdk.spec b/dpdk.spec index 9bdca3a6015dd04aa962514ee118b5aeac7c3fd5..87da90be61c69a72178ee614e98529b6c32976cf 100644 --- a/dpdk.spec +++ b/dpdk.spec @@ -1,6 +1,6 @@ Name: dpdk Version: 21.11 -Release: 6 +Release: 7 Packager: packaging@6wind.com URL: http://dpdk.org %global source_version 21.11 @@ -27,6 +27,30 @@ Patch9018: 0018-net-bonding-fix-offloading-configuration.patch Patch9019: 0019-net-hns3-fix-Rx-Tx-when-fast-path-operation-introduc.patch Patch9020: 0020-net-hns3-fix-mailbox-wait-time-uninitialization.patch Patch9021: 0021-net-hns3-fix-vector-burst-when-PTP-enable.patch +Patch9022: 0022-net-hns3-remove-unnecessary-assignment.patch +Patch9023: 0023-net-hns3-fix-using-enum-as-boolean.patch +Patch9024: 0024-net-hns3-extract-common-function-to-initialize-MAC-a.patch +Patch9025: 0025-net-hns3-make-control-plane-function-non-inline.patch +Patch9026: 0026-net-hns3-remove-unnecessary-blank-lines.patch +Patch9027: 0027-net-hns3-extract-reset-failure-handling-to-function.patch +Patch9028: 0028-net-hns3-remove-unused-variables.patch +Patch9029: 0029-net-hns3-remove-getting-number-of-queue-descriptors-.patch +Patch9030: 0030-net-hns3-remove-logging-memory-addresses.patch +Patch9031: 0031-net-hns3-extract-common-function-to-obtain-revision-.patch +Patch9032: 0032-net-hns3-replace-single-line-functions.patch +Patch9033: 0033-net-hns3-remove-non-re-entrant-strerror-call.patch +Patch9034: 0034-net-hns3-rename-function.patch +Patch9035: 0035-net-hns3-extract-functions-to-create-RSS-and-FDIR-fl.patch +Patch9036: 0036-net-hns3-support-indirect-counter-flow-action.patch +Patch9037: 0037-net-hns3-fix-max-packet-size-rollback-in-PF.patch +Patch9038: 0038-net-hns3-fix-RSS-key-with-null.patch +Patch9039: 0039-net-hns3-fix-insecure-way-to-query-MAC-statistics.patch +Patch9040: 0040-net-hns3-fix-double-decrement-of-secondary-count.patch +Patch9041: 0041-net-hns3-fix-operating-queue-when-TCAM-table-is-inva.patch +Patch9042: 0042-net-hns3-delete-duplicated-RSS-type.patch +Patch9043: 0043-net-bonding-fix-promiscuous-and-allmulticast-state.patch +Patch9044: 0044-net-bonding-fix-reference-count-on-mbufs.patch +Patch9045: 0045-app-testpmd-fix-bonding-mode-set.patch Summary: Data Plane Development Kit core Group: System Environment/Libraries @@ -132,6 +156,9 @@ strip -g $RPM_BUILD_ROOT/lib/modules/%{kern_devel_ver}/extra/dpdk/igb_uio.ko /usr/sbin/depmod %changelog +* Wed Feb 09 2022 Min Hu(Connor) - 21.11-7 +- sync patches from upstreaming branch. + * Thu Jan 27 2022 Min Hu(Connor) - 21.11-6 - fix key bugfixes for hns3 PMD.