From 6112eef76795c0c73f9d1010f8723cf9777d6ab3 Mon Sep 17 00:00:00 2001 From: chenjiji09 Date: Mon, 5 Jun 2023 14:20:45 +0800 Subject: [PATCH] net/hns3: fix Rx ring mbuf leakage Sync some patchs from upstreaming for hns3 pmd and modifies are as follow: 1. fix RTC time after reset 2. fix Rx ring mbuf leakage at reset process 3. fix uninitialized variable 4. modify the code that violates the coding standards (cherry picked from commit f98940e02a12dc752a60e786009ee44cb6b32132) --- ...-hns3-fix-RTC-time-on-initialization.patch | 80 +++++++++ 0301-net-hns3-fix-RTC-time-after-reset.patch | 51 ++++++ 0302-net-hns3-uninitialize-PTP.patch | 82 +++++++++ ...3-extract-PTP-to-its-own-header-file.patch | 168 ++++++++++++++++++ ...f-leakage-when-RxQ-started-during-re.patch | 96 ++++++++++ ...f-leakage-when-RxQ-started-after-res.patch | 59 ++++++ ...t-hns3-fix-device-start-return-value.patch | 38 ++++ ...-net-hns3-fix-uninitialized-variable.patch | 38 ++++ 0308-net-hns3-refactor-code.patch | 82 +++++++++ 0309-net-hns3-fix-inaccurate-log.patch | 44 +++++ ...hns3-fix-redundant-line-break-in-log.patch | 71 ++++++++ dpdk.spec | 22 ++- 12 files changed, 830 insertions(+), 1 deletion(-) create mode 100644 0300-net-hns3-fix-RTC-time-on-initialization.patch create mode 100644 0301-net-hns3-fix-RTC-time-after-reset.patch create mode 100644 0302-net-hns3-uninitialize-PTP.patch create mode 100644 0303-net-hns3-extract-PTP-to-its-own-header-file.patch create mode 100644 0304-net-hns3-fix-mbuf-leakage-when-RxQ-started-during-re.patch create mode 100644 0305-net-hns3-fix-mbuf-leakage-when-RxQ-started-after-res.patch create mode 100644 0306-net-hns3-fix-device-start-return-value.patch create mode 100644 0307-net-hns3-fix-uninitialized-variable.patch create mode 100644 0308-net-hns3-refactor-code.patch create mode 100644 0309-net-hns3-fix-inaccurate-log.patch create mode 100644 0310-net-hns3-fix-redundant-line-break-in-log.patch diff --git a/0300-net-hns3-fix-RTC-time-on-initialization.patch b/0300-net-hns3-fix-RTC-time-on-initialization.patch new file mode 100644 index 0000000..2a5d381 --- /dev/null +++ b/0300-net-hns3-fix-RTC-time-on-initialization.patch @@ -0,0 +1,80 @@ +From 6896b9dc63327691df470cc7b1d9bac8e8c673fe Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Fri, 2 Jun 2023 19:41:55 +0800 +Subject: net/hns3: fix RTC time on initialization + +[ upstream commit 27f64ddb711901d06bbe337ab714989e799a36d0 ] + +Driver doesn't initialize RTC time during probe phase, which +lead to an inaccurate time. + +Fixes: 38b539d96eb6 ("net/hns3: support IEEE 1588 PTP") +Cc: stable@dpdk.org + +Signed-off-by: Huisong Li +Signed-off-by: Dongdong Liu +--- + drivers/net/hns3/hns3_ptp.c | 26 +++++++++++++++++++------- + 1 file changed, 19 insertions(+), 7 deletions(-) + +diff --git a/drivers/net/hns3/hns3_ptp.c b/drivers/net/hns3/hns3_ptp.c +index db3c007b12..1e27e4aeca 100644 +--- a/drivers/net/hns3/hns3_ptp.c ++++ b/drivers/net/hns3/hns3_ptp.c +@@ -56,9 +56,23 @@ hns3_ptp_int_en(struct hns3_hw *hw, bool en) + return ret; + } + ++static void ++hns3_ptp_timesync_write_time(struct hns3_hw *hw, const struct timespec *ts) ++{ ++ uint64_t sec = ts->tv_sec; ++ uint64_t ns = ts->tv_nsec; ++ ++ /* Set the timecounters to a new value. */ ++ hns3_write_dev(hw, HNS3_CFG_TIME_SYNC_H, upper_32_bits(sec)); ++ hns3_write_dev(hw, HNS3_CFG_TIME_SYNC_M, lower_32_bits(sec)); ++ hns3_write_dev(hw, HNS3_CFG_TIME_SYNC_L, lower_32_bits(ns)); ++ hns3_write_dev(hw, HNS3_CFG_TIME_SYNC_RDY, 1); ++} ++ + int + hns3_ptp_init(struct hns3_hw *hw) + { ++ struct timespec sys_time; + int ret; + + if (!hns3_dev_get_support(hw, PTP)) +@@ -71,6 +85,10 @@ hns3_ptp_init(struct hns3_hw *hw) + /* Start PTP timer */ + hns3_write_dev(hw, HNS3_CFG_TIME_CYC_EN, 1); + ++ /* Initializing the RTC. */ ++ clock_gettime(CLOCK_REALTIME, &sys_time); ++ hns3_ptp_timesync_write_time(hw, &sys_time); ++ + return 0; + } + +@@ -241,17 +259,11 @@ int + hns3_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts) + { + struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private); +- uint64_t sec = ts->tv_sec; +- uint64_t ns = ts->tv_nsec; + + if (!hns3_dev_get_support(hw, PTP)) + return -ENOTSUP; + +- /* Set the timecounters to a new value. */ +- hns3_write_dev(hw, HNS3_CFG_TIME_SYNC_H, upper_32_bits(sec)); +- hns3_write_dev(hw, HNS3_CFG_TIME_SYNC_M, lower_32_bits(sec)); +- hns3_write_dev(hw, HNS3_CFG_TIME_SYNC_L, lower_32_bits(ns)); +- hns3_write_dev(hw, HNS3_CFG_TIME_SYNC_RDY, 1); ++ hns3_ptp_timesync_write_time(hw, ts); + + return 0; + } +-- +2.23.0 + diff --git a/0301-net-hns3-fix-RTC-time-after-reset.patch b/0301-net-hns3-fix-RTC-time-after-reset.patch new file mode 100644 index 0000000..500dd3c --- /dev/null +++ b/0301-net-hns3-fix-RTC-time-after-reset.patch @@ -0,0 +1,51 @@ +From 974c06500687f166870e57a998fcdbb82f5d3628 Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Fri, 2 Jun 2023 19:41:56 +0800 +Subject: net/hns3: fix RTC time after reset + +[ upstream commit 0335c1f3c43a7da75fe5e2ab7bac0422cfad99e3 ] + +The enabled status of RTC time will be cleared after global +or IMP reset, which cause the local RTC time doesn't work. +So this patch fix it. + +Fixes: 38b539d96eb6 ("net/hns3: support IEEE 1588 PTP") +Cc: stable@dpdk.org + +Signed-off-by: Huisong Li +Signed-off-by: Dongdong Liu +--- + drivers/net/hns3/hns3_ethdev.c | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c +index d6214415b7..cecf6929f7 100644 +--- a/drivers/net/hns3/hns3_ethdev.c ++++ b/drivers/net/hns3/hns3_ethdev.c +@@ -4416,6 +4416,12 @@ hns3_init_hardware(struct hns3_adapter *hns) + goto err_mac_init; + } + ++ ret = hns3_ptp_init(hw); ++ if (ret) { ++ PMD_INIT_LOG(ERR, "Failed to init PTP, ret = %d", ret); ++ goto err_mac_init; ++ } ++ + return 0; + + err_mac_init: +@@ -4577,10 +4583,6 @@ hns3_init_pf(struct rte_eth_dev *eth_dev) + goto err_intr_callback_register; + } + +- ret = hns3_ptp_init(hw); +- if (ret) +- goto err_get_config; +- + /* Enable interrupt */ + rte_intr_enable(pci_dev->intr_handle); + hns3_pf_enable_irq0(hw); +-- +2.23.0 + diff --git a/0302-net-hns3-uninitialize-PTP.patch b/0302-net-hns3-uninitialize-PTP.patch new file mode 100644 index 0000000..fa9d0aa --- /dev/null +++ b/0302-net-hns3-uninitialize-PTP.patch @@ -0,0 +1,82 @@ +From 35a0d98f028f8d1b37fec44dc9b1b5eec5e0a84e Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Fri, 2 Jun 2023 19:41:57 +0800 +Subject: net/hns3: uninitialize PTP + +[ upstream commit edb0f566d8476978fa6c12467fe03c4983a28573 ] + +This patch adds the uninitialization process of PTP in case +of having an impact on PF driver in kernel. + +Fixes: 38b539d96eb6 ("net/hns3: support IEEE 1588 PTP") +Cc: stable@dpdk.org + +Signed-off-by: Huisong Li +Signed-off-by: Dongdong Liu +--- + drivers/net/hns3/hns3_ethdev.c | 2 ++ + drivers/net/hns3/hns3_ethdev.h | 1 + + drivers/net/hns3/hns3_ptp.c | 18 ++++++++++++++++++ + 3 files changed, 21 insertions(+) + +diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c +index cecf6929f7..2e3aaf191d 100644 +--- a/drivers/net/hns3/hns3_ethdev.c ++++ b/drivers/net/hns3/hns3_ethdev.c +@@ -4637,6 +4637,7 @@ hns3_init_pf(struct rte_eth_dev *eth_dev) + hns3_fdir_filter_uninit(hns); + err_fdir: + hns3_uninit_umv_space(hw); ++ hns3_ptp_uninit(hw); + err_init_hw: + hns3_stats_uninit(hw); + err_get_config: +@@ -4672,6 +4673,7 @@ hns3_uninit_pf(struct rte_eth_dev *eth_dev) + hns3_flow_uninit(eth_dev); + hns3_fdir_filter_uninit(hns); + hns3_uninit_umv_space(hw); ++ hns3_ptp_uninit(hw); + hns3_stats_uninit(hw); + hns3_config_mac_tnl_int(hw, false); + hns3_pf_disable_irq0(hw); +diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h +index c04edf622f..9456204422 100644 +--- a/drivers/net/hns3/hns3_ethdev.h ++++ b/drivers/net/hns3/hns3_ethdev.h +@@ -1045,6 +1045,7 @@ int hns3_restore_ptp(struct hns3_adapter *hns); + int hns3_mbuf_dyn_rx_timestamp_register(struct rte_eth_dev *dev, + struct rte_eth_conf *conf); + int hns3_ptp_init(struct hns3_hw *hw); ++void hns3_ptp_uninit(struct hns3_hw *hw); + int hns3_timesync_enable(struct rte_eth_dev *dev); + int hns3_timesync_disable(struct rte_eth_dev *dev); + int hns3_timesync_read_rx_timestamp(struct rte_eth_dev *dev, +diff --git a/drivers/net/hns3/hns3_ptp.c b/drivers/net/hns3/hns3_ptp.c +index 1e27e4aeca..0e17a17034 100644 +--- a/drivers/net/hns3/hns3_ptp.c ++++ b/drivers/net/hns3/hns3_ptp.c +@@ -306,3 +306,21 @@ hns3_restore_ptp(struct hns3_adapter *hns) + + return ret; + } ++ ++void ++hns3_ptp_uninit(struct hns3_hw *hw) ++{ ++ struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw); ++ int ret; ++ ++ if (!hns3_dev_get_support(hw, PTP)) ++ return; ++ ++ ret = hns3_ptp_int_en(hw, false); ++ if (ret != 0) ++ hns3_err(hw, "disable PTP interrupt failed, ret = %d.", ret); ++ ++ ret = hns3_timesync_configure(hns, false); ++ if (ret != 0) ++ hns3_err(hw, "disable timesync failed, ret = %d.", ret); ++} +-- +2.23.0 + diff --git a/0303-net-hns3-extract-PTP-to-its-own-header-file.patch b/0303-net-hns3-extract-PTP-to-its-own-header-file.patch new file mode 100644 index 0000000..2b64c25 --- /dev/null +++ b/0303-net-hns3-extract-PTP-to-its-own-header-file.patch @@ -0,0 +1,168 @@ +From aeddfec842cdd80c6c295045b80a420e3a07170a Mon Sep 17 00:00:00 2001 +From: Huisong Li +Date: Fri, 2 Jun 2023 19:41:58 +0800 +Subject: net/hns3: extract PTP to its own header file + +[ upstream commit 8977e7539f40ac716138dd49456dc26bfbf439c5 ] + +This patch extracts a PTP header file to contain PTP registers +and external API in order to make PTP code structure more clear. + +Fixes: 38b539d96eb6 ("net/hns3: support IEEE 1588 PTP") +Cc: stable@dpdk.org + +Signed-off-by: Huisong Li +Signed-off-by: Dongdong Liu +--- + drivers/net/hns3/hns3_ethdev.c | 1 + + drivers/net/hns3/hns3_ethdev.h | 17 ------------ + drivers/net/hns3/hns3_ptp.c | 2 +- + drivers/net/hns3/hns3_ptp.h | 48 ++++++++++++++++++++++++++++++++++ + drivers/net/hns3/hns3_regs.h | 23 ---------------- + 5 files changed, 50 insertions(+), 41 deletions(-) + create mode 100644 drivers/net/hns3/hns3_ptp.h + +diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c +index 2e3aaf191d..d7443e197c 100644 +--- a/drivers/net/hns3/hns3_ethdev.c ++++ b/drivers/net/hns3/hns3_ethdev.c +@@ -15,6 +15,7 @@ + #include "hns3_dcb.h" + #include "hns3_mp.h" + #include "hns3_flow.h" ++#include "hns3_ptp.h" + #include "hns3_ethdev.h" + + #define HNS3_SERVICE_INTERVAL 1000000 /* us */ +diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h +index 9456204422..c58094d87b 100644 +--- a/drivers/net/hns3/hns3_ethdev.h ++++ b/drivers/net/hns3/hns3_ethdev.h +@@ -1041,23 +1041,6 @@ void hns3vf_update_link_status(struct hns3_hw *hw, uint8_t link_status, + uint32_t link_speed, uint8_t link_duplex); + void hns3vf_update_push_lsc_cap(struct hns3_hw *hw, bool supported); + +-int hns3_restore_ptp(struct hns3_adapter *hns); +-int hns3_mbuf_dyn_rx_timestamp_register(struct rte_eth_dev *dev, +- struct rte_eth_conf *conf); +-int hns3_ptp_init(struct hns3_hw *hw); +-void hns3_ptp_uninit(struct hns3_hw *hw); +-int hns3_timesync_enable(struct rte_eth_dev *dev); +-int hns3_timesync_disable(struct rte_eth_dev *dev); +-int hns3_timesync_read_rx_timestamp(struct rte_eth_dev *dev, +- struct timespec *timestamp, +- uint32_t flags __rte_unused); +-int hns3_timesync_read_tx_timestamp(struct rte_eth_dev *dev, +- struct timespec *timestamp); +-int hns3_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts); +-int hns3_timesync_write_time(struct rte_eth_dev *dev, +- const struct timespec *ts); +-int hns3_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta); +- + const char *hns3_get_media_type_name(uint8_t media_type); + + static inline bool +diff --git a/drivers/net/hns3/hns3_ptp.c b/drivers/net/hns3/hns3_ptp.c +index 0e17a17034..894ac6dd71 100644 +--- a/drivers/net/hns3/hns3_ptp.c ++++ b/drivers/net/hns3/hns3_ptp.c +@@ -7,7 +7,7 @@ + #include + + #include "hns3_ethdev.h" +-#include "hns3_regs.h" ++#include "hns3_ptp.h" + #include "hns3_logs.h" + + uint64_t hns3_timestamp_rx_dynflag; +diff --git a/drivers/net/hns3/hns3_ptp.h b/drivers/net/hns3/hns3_ptp.h +new file mode 100644 +index 0000000000..2b8717fa3c +--- /dev/null ++++ b/drivers/net/hns3/hns3_ptp.h +@@ -0,0 +1,48 @@ ++/* SPDX-License-Identifier: BSD-3-Clause ++ * Copyright(c) 2023 HiSilicon Limited. ++ */ ++ ++#ifndef HNS3_PTP_H ++#define HNS3_PTP_H ++ ++/* Register bit for 1588 event */ ++#define HNS3_VECTOR0_1588_INT_B 0 ++ ++#define HNS3_PTP_BASE_ADDRESS 0x29000 ++ ++#define HNS3_TX_1588_SEQID_BACK (HNS3_PTP_BASE_ADDRESS + 0x0) ++#define HNS3_TX_1588_TSP_BACK_0 (HNS3_PTP_BASE_ADDRESS + 0x4) ++#define HNS3_TX_1588_TSP_BACK_1 (HNS3_PTP_BASE_ADDRESS + 0x8) ++#define HNS3_TX_1588_TSP_BACK_2 (HNS3_PTP_BASE_ADDRESS + 0xc) ++ ++#define HNS3_TX_1588_BACK_TSP_CNT (HNS3_PTP_BASE_ADDRESS + 0x30) ++ ++#define HNS3_CFG_TIME_SYNC_H (HNS3_PTP_BASE_ADDRESS + 0x50) ++#define HNS3_CFG_TIME_SYNC_M (HNS3_PTP_BASE_ADDRESS + 0x54) ++#define HNS3_CFG_TIME_SYNC_L (HNS3_PTP_BASE_ADDRESS + 0x58) ++#define HNS3_CFG_TIME_SYNC_RDY (HNS3_PTP_BASE_ADDRESS + 0x5c) ++ ++#define HNS3_CFG_TIME_CYC_EN (HNS3_PTP_BASE_ADDRESS + 0x70) ++ ++#define HNS3_CURR_TIME_OUT_H (HNS3_PTP_BASE_ADDRESS + 0x74) ++#define HNS3_CURR_TIME_OUT_L (HNS3_PTP_BASE_ADDRESS + 0x78) ++#define HNS3_CURR_TIME_OUT_NS (HNS3_PTP_BASE_ADDRESS + 0x7c) ++ ++int hns3_restore_ptp(struct hns3_adapter *hns); ++int hns3_mbuf_dyn_rx_timestamp_register(struct rte_eth_dev *dev, ++ struct rte_eth_conf *conf); ++int hns3_ptp_init(struct hns3_hw *hw); ++void hns3_ptp_uninit(struct hns3_hw *hw); ++int hns3_timesync_enable(struct rte_eth_dev *dev); ++int hns3_timesync_disable(struct rte_eth_dev *dev); ++int hns3_timesync_read_rx_timestamp(struct rte_eth_dev *dev, ++ struct timespec *timestamp, ++ uint32_t flags __rte_unused); ++int hns3_timesync_read_tx_timestamp(struct rte_eth_dev *dev, ++ struct timespec *timestamp); ++int hns3_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts); ++int hns3_timesync_write_time(struct rte_eth_dev *dev, ++ const struct timespec *ts); ++int hns3_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta); ++ ++#endif /* HNS3_PTP_H */ +diff --git a/drivers/net/hns3/hns3_regs.h b/drivers/net/hns3/hns3_regs.h +index 459bbaf773..6b037f81c1 100644 +--- a/drivers/net/hns3/hns3_regs.h ++++ b/drivers/net/hns3/hns3_regs.h +@@ -124,29 +124,6 @@ + #define HNS3_TQP_INTR_RL_DEFAULT 0 + #define HNS3_TQP_INTR_QL_DEFAULT 0 + +-/* Register bit for 1588 event */ +-#define HNS3_VECTOR0_1588_INT_B 0 +- +-#define HNS3_PTP_BASE_ADDRESS 0x29000 +- +-#define HNS3_TX_1588_SEQID_BACK (HNS3_PTP_BASE_ADDRESS + 0x0) +-#define HNS3_TX_1588_TSP_BACK_0 (HNS3_PTP_BASE_ADDRESS + 0x4) +-#define HNS3_TX_1588_TSP_BACK_1 (HNS3_PTP_BASE_ADDRESS + 0x8) +-#define HNS3_TX_1588_TSP_BACK_2 (HNS3_PTP_BASE_ADDRESS + 0xc) +- +-#define HNS3_TX_1588_BACK_TSP_CNT (HNS3_PTP_BASE_ADDRESS + 0x30) +- +-#define HNS3_CFG_TIME_SYNC_H (HNS3_PTP_BASE_ADDRESS + 0x50) +-#define HNS3_CFG_TIME_SYNC_M (HNS3_PTP_BASE_ADDRESS + 0x54) +-#define HNS3_CFG_TIME_SYNC_L (HNS3_PTP_BASE_ADDRESS + 0x58) +-#define HNS3_CFG_TIME_SYNC_RDY (HNS3_PTP_BASE_ADDRESS + 0x5c) +- +-#define HNS3_CFG_TIME_CYC_EN (HNS3_PTP_BASE_ADDRESS + 0x70) +- +-#define HNS3_CURR_TIME_OUT_H (HNS3_PTP_BASE_ADDRESS + 0x74) +-#define HNS3_CURR_TIME_OUT_L (HNS3_PTP_BASE_ADDRESS + 0x78) +-#define HNS3_CURR_TIME_OUT_NS (HNS3_PTP_BASE_ADDRESS + 0x7c) +- + /* gl_usec convert to hardware count, as writing each 1 represents 2us */ + #define HNS3_GL_USEC_TO_REG(gl_usec) ((gl_usec) >> 1) + /* rl_usec convert to hardware count, as writing each 1 represents 4us */ +-- +2.23.0 + diff --git a/0304-net-hns3-fix-mbuf-leakage-when-RxQ-started-during-re.patch b/0304-net-hns3-fix-mbuf-leakage-when-RxQ-started-during-re.patch new file mode 100644 index 0000000..8a7bf9d --- /dev/null +++ b/0304-net-hns3-fix-mbuf-leakage-when-RxQ-started-during-re.patch @@ -0,0 +1,96 @@ +From e29ec4c79236c53c61a5ca955fee16993b63fe08 Mon Sep 17 00:00:00 2001 +From: Chengwen Feng +Date: Fri, 2 Jun 2023 19:41:59 +0800 +Subject: net/hns3: fix mbuf leakage when RxQ started during reset + +[ upstream commit e2199b1897da9e26bbc700df3a00cd9c3c85eede ] + +In the reset restore-conf phase, the reset process will allocate for +the Rx ring mbufs unconditionlly. + +And the rte_eth_dev_rx_queue_start() will also allocate for the Rx ring +mbufs unconditionlly. + +So if the rte_eth_dev_rx_queue_start() is invoked before restore-conf +phase, then the mbufs allocated by rte_eth_dev_rx_queue_start() will +leak. + +Because the hw->reset.resetting was always true during the phases from +stop-service to restore-conf, so fix it by returning an error if the +hw->reset.resetting is set. + +This patch adds the above logic in both rx_queue_start/rx_queue_stop/ +tx_queue_start/tx_queue_stop ops. + +Fixes: fa29fe45a7b4 ("net/hns3: support queue start and stop") +Cc: stable@dpdk.org + +Signed-off-by: Chengwen Feng +Signed-off-by: Dongdong Liu +--- + drivers/net/hns3/hns3_rxtx.c | 28 ++++++++++++++++++++++++++++ + 1 file changed, 28 insertions(+) + +diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c +index e055b5415d..f766c47072 100644 +--- a/drivers/net/hns3/hns3_rxtx.c ++++ b/drivers/net/hns3/hns3_rxtx.c +@@ -4523,6 +4523,13 @@ hns3_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id) + return -ENOTSUP; + + rte_spinlock_lock(&hw->lock); ++ ++ if (__atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED)) { ++ hns3_err(hw, "fail to start Rx queue during resetting."); ++ rte_spinlock_unlock(&hw->lock); ++ return -EIO; ++ } ++ + ret = hns3_reset_queue(hw, rx_queue_id, HNS3_RING_TYPE_RX); + if (ret) { + hns3_err(hw, "fail to reset Rx queue %u, ret = %d.", +@@ -4569,6 +4576,13 @@ hns3_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id) + return -ENOTSUP; + + rte_spinlock_lock(&hw->lock); ++ ++ if (__atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED)) { ++ hns3_err(hw, "fail to stop Rx queue during resetting."); ++ rte_spinlock_unlock(&hw->lock); ++ return -EIO; ++ } ++ + hns3_enable_rxq(rxq, false); + + hns3_rx_queue_release_mbufs(rxq); +@@ -4591,6 +4605,13 @@ hns3_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id) + return -ENOTSUP; + + rte_spinlock_lock(&hw->lock); ++ ++ if (__atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED)) { ++ hns3_err(hw, "fail to start Tx queue during resetting."); ++ rte_spinlock_unlock(&hw->lock); ++ return -EIO; ++ } ++ + ret = hns3_reset_queue(hw, tx_queue_id, HNS3_RING_TYPE_TX); + if (ret) { + hns3_err(hw, "fail to reset Tx queue %u, ret = %d.", +@@ -4617,6 +4638,13 @@ hns3_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id) + return -ENOTSUP; + + rte_spinlock_lock(&hw->lock); ++ ++ if (__atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED)) { ++ hns3_err(hw, "fail to stop Tx queue during resetting."); ++ rte_spinlock_unlock(&hw->lock); ++ return -EIO; ++ } ++ + hns3_enable_txq(txq, false); + hns3_tx_queue_release_mbufs(txq); + /* +-- +2.23.0 + diff --git a/0305-net-hns3-fix-mbuf-leakage-when-RxQ-started-after-res.patch b/0305-net-hns3-fix-mbuf-leakage-when-RxQ-started-after-res.patch new file mode 100644 index 0000000..9997238 --- /dev/null +++ b/0305-net-hns3-fix-mbuf-leakage-when-RxQ-started-after-res.patch @@ -0,0 +1,59 @@ +From 5f5edfc2aae49af8dee267565ea36852cab4f292 Mon Sep 17 00:00:00 2001 +From: Chengwen Feng +Date: Fri, 2 Jun 2023 19:42:00 +0800 +Subject: net/hns3: fix mbuf leakage when RxQ started after reset + +[ upstream commit 4ec0409b3f3801fa01f45f9dfddfab6a343436af ] + +In the reset restore-conf phase, the reset process will allocate for +the Rx ring mbufs unconditionlly. + +And the rte_eth_dev_rx_queue_start() will also allocate for the Rx ring +mbufs unconditionlly. + +So if the rte_eth_dev_rx_queue_start() is invoked after restore-conf +phase, then the mbufs allocated in restore-conf phase will leak. + +So fix it by conditional release Rx ring mbufs in +rte_eth_dev_rx_queue_start(): if the Rx ring mbufs were allocated then +release them first. + +This patch also set all sw-ring[]'s mbuf is NULL when release Rx ring +mbufs so that we can determine whether the Rx ring mbufs were allocated +based only on the first sw-ring[0]'s mbuf. + +Fixes: fa29fe45a7b4 ("net/hns3: support queue start and stop") +Cc: stable@dpdk.org + +Signed-off-by: Chengwen Feng +Signed-off-by: Dongdong Liu +--- + drivers/net/hns3/hns3_rxtx.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c +index f766c47072..767ce82cc4 100644 +--- a/drivers/net/hns3/hns3_rxtx.c ++++ b/drivers/net/hns3/hns3_rxtx.c +@@ -50,6 +50,8 @@ hns3_rx_queue_release_mbufs(struct hns3_rx_queue *rxq) + rxq->sw_ring[i].mbuf = NULL; + } + } ++ for (i = 0; i < rxq->rx_rearm_nb; i++) ++ rxq->sw_ring[rxq->rx_rearm_start + i].mbuf = NULL; + } + + for (i = 0; i < rxq->bulk_mbuf_num; i++) +@@ -4538,6 +4540,9 @@ hns3_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id) + return ret; + } + ++ if (rxq->sw_ring[0].mbuf != NULL) ++ hns3_rx_queue_release_mbufs(rxq); ++ + ret = hns3_init_rxq(hns, rx_queue_id); + if (ret) { + hns3_err(hw, "fail to init Rx queue %u, ret = %d.", +-- +2.23.0 + diff --git a/0306-net-hns3-fix-device-start-return-value.patch b/0306-net-hns3-fix-device-start-return-value.patch new file mode 100644 index 0000000..63ba0ea --- /dev/null +++ b/0306-net-hns3-fix-device-start-return-value.patch @@ -0,0 +1,38 @@ +From 080088d0626c9b437f41fc0717360c89d294dfdf Mon Sep 17 00:00:00 2001 +From: Chengwen Feng +Date: Fri, 2 Jun 2023 19:42:01 +0800 +Subject: net/hns3: fix device start return value + +[ upstream commit 3c6143436cc6d328bb41f0474040a6e1d0a9ae4c ] + +If hns3_init_queues() return failed, the hns3vf_do_start() should +return errcode. This patch fixes it. + +Fixes: 43d8adf3891c ("net/hns3: fix RSS flow rule restore") +Cc: stable@dpdk.org + +Signed-off-by: Chengwen Feng +Signed-off-by: Dongdong Liu +--- + drivers/net/hns3/hns3_ethdev_vf.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c +index 3a93987409..6898a77407 100644 +--- a/drivers/net/hns3/hns3_ethdev_vf.c ++++ b/drivers/net/hns3/hns3_ethdev_vf.c +@@ -1674,8 +1674,10 @@ hns3vf_do_start(struct hns3_adapter *hns, bool reset_queue) + hns3_enable_rxd_adv_layout(hw); + + ret = hns3_init_queues(hns, reset_queue); +- if (ret) ++ if (ret) { + hns3_err(hw, "failed to init queues, ret = %d.", ret); ++ return ret; ++ } + + return hns3_restore_filter(hns); + } +-- +2.23.0 + diff --git a/0307-net-hns3-fix-uninitialized-variable.patch b/0307-net-hns3-fix-uninitialized-variable.patch new file mode 100644 index 0000000..666ec53 --- /dev/null +++ b/0307-net-hns3-fix-uninitialized-variable.patch @@ -0,0 +1,38 @@ +From 8bd047fb37fbc06fd695f120d9d51a4ffbcc2493 Mon Sep 17 00:00:00 2001 +From: Jie Hai +Date: Fri, 2 Jun 2023 19:42:02 +0800 +Subject: net/hns3: fix uninitialized variable + +[ upstream commit 82d44a304e9a0fe5931b7c68d32c3e30477564f2 ] + +This patch fixes possible use of uninitialized variable +"old_tuple_fields". + +Fixes: e3069658da9f ("net/hns3: reimplement hash flow function") +Cc: stable@dpdk.org + +Signed-off-by: Jie Hai +Signed-off-by: Dongdong Liu +--- + drivers/net/hns3/hns3_flow.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c +index c1f4f5cb0b..d5c9c22633 100644 +--- a/drivers/net/hns3/hns3_flow.c ++++ b/drivers/net/hns3/hns3_flow.c +@@ -1944,8 +1944,9 @@ hns3_flow_set_rss_ptype_tuple(struct hns3_hw *hw, + if (ret != 0) + return ret; + +- hns3_info(hw, "RSS tuple fields changed from 0x%" PRIx64 " to 0x%" PRIx64, +- old_tuple_fields, new_tuple_fields); ++ if (!cfg_global_tuple) ++ hns3_info(hw, "RSS tuple fields changed from 0x%" PRIx64 " to 0x%" PRIx64, ++ old_tuple_fields, new_tuple_fields); + + return 0; + } +-- +2.23.0 + diff --git a/0308-net-hns3-refactor-code.patch b/0308-net-hns3-refactor-code.patch new file mode 100644 index 0000000..7e50dab --- /dev/null +++ b/0308-net-hns3-refactor-code.patch @@ -0,0 +1,82 @@ +From 27ac02da0401a657ea0a6bf3c048be6af13aeace Mon Sep 17 00:00:00 2001 +From: Dengdui Huang +Date: Fri, 2 Jun 2023 19:42:03 +0800 +Subject: net/hns3: refactor code + +[ upstream commit 00dcbfac5f2354de6e769f00159eba942a2c908a ] + +This patch modify the code that violates the coding standards. + +Signed-off-by: Dengdui Huang +Signed-off-by: Dongdong Liu +--- + drivers/net/hns3/hns3_regs.c | 3 +-- + drivers/net/hns3/hns3_rxtx.c | 10 +++------- + 2 files changed, 4 insertions(+), 9 deletions(-) + +diff --git a/drivers/net/hns3/hns3_regs.c b/drivers/net/hns3/hns3_regs.c +index 5d6f92e4bb..be1be6a89c 100644 +--- a/drivers/net/hns3/hns3_regs.c ++++ b/drivers/net/hns3/hns3_regs.c +@@ -385,10 +385,9 @@ hns3_dfx_reg_cmd_send(struct hns3_hw *hw, struct hns3_cmd_desc *desc, + hns3_cmd_setup_basic_desc(&desc[i], opcode, true); + + ret = hns3_cmd_send(hw, desc, bd_num); +- if (ret) { ++ if (ret) + hns3_err(hw, "fail to query dfx registers, opcode = 0x%04X, " + "ret = %d.\n", opcode, ret); +- } + + return ret; + } +diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c +index 767ce82cc4..13b0ad24b5 100644 +--- a/drivers/net/hns3/hns3_rxtx.c ++++ b/drivers/net/hns3/hns3_rxtx.c +@@ -751,7 +751,7 @@ hns3pf_reset_all_tqps(struct hns3_hw *hw) + for (i = 0; i < hw->cfg_max_queues; i++) { + ret = hns3pf_reset_tqp(hw, i); + if (ret) { +- hns3_err(hw, "fail to reset tqp, queue_id = %d, ret = %d.", ++ hns3_err(hw, "fail to reset tqp, queue_id = %u, ret = %d.", + i, ret); + return ret; + } +@@ -829,15 +829,13 @@ hns3_send_reset_queue_cmd(struct hns3_hw *hw, uint16_t queue_id, + { + struct hns3_reset_tqp_queue_cmd *req; + struct hns3_cmd_desc desc; +- int queue_direction; + int ret; + + hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RESET_TQP_QUEUE_INDEP, false); + + req = (struct hns3_reset_tqp_queue_cmd *)desc.data; + req->tqp_id = rte_cpu_to_le_16(queue_id); +- queue_direction = queue_type == HNS3_RING_TYPE_TX ? 0 : 1; +- req->queue_direction = rte_cpu_to_le_16(queue_direction); ++ req->queue_direction = queue_type == HNS3_RING_TYPE_TX ? 0 : 1; + hns3_set_bit(req->reset_req, HNS3_TQP_RESET_B, enable ? 1 : 0); + + ret = hns3_cmd_send(hw, &desc, 1); +@@ -855,15 +853,13 @@ hns3_get_queue_reset_status(struct hns3_hw *hw, uint16_t queue_id, + { + struct hns3_reset_tqp_queue_cmd *req; + struct hns3_cmd_desc desc; +- int queue_direction; + int ret; + + hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RESET_TQP_QUEUE_INDEP, true); + + req = (struct hns3_reset_tqp_queue_cmd *)desc.data; + req->tqp_id = rte_cpu_to_le_16(queue_id); +- queue_direction = queue_type == HNS3_RING_TYPE_TX ? 0 : 1; +- req->queue_direction = rte_cpu_to_le_16(queue_direction); ++ req->queue_direction = queue_type == HNS3_RING_TYPE_TX ? 0 : 1; + + ret = hns3_cmd_send(hw, &desc, 1); + if (ret) { +-- +2.23.0 + diff --git a/0309-net-hns3-fix-inaccurate-log.patch b/0309-net-hns3-fix-inaccurate-log.patch new file mode 100644 index 0000000..531d53f --- /dev/null +++ b/0309-net-hns3-fix-inaccurate-log.patch @@ -0,0 +1,44 @@ +From 599089c15b21493879e6509cda350284e0af4eb3 Mon Sep 17 00:00:00 2001 +From: Dengdui Huang +Date: Fri, 2 Jun 2023 19:42:04 +0800 +Subject: net/hns3: fix inaccurate log + +[ upstream commit 9ff64664c1a1b1fa636ee4d11c7ef4eb54ab0691 ] + +This patch fix inaccurate log + +Fixes: bba636698316 ("net/hns3: support Rx/Tx and related operations") +Fixes: a951c1ed3ab5 ("net/hns3: support different numbers of Rx and Tx queues") +Cc: stable@dpdk.org + +Signed-off-by: Dengdui Huang +Signed-off-by: Dongdong Liu +--- + drivers/net/hns3/hns3_rxtx.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c +index 13b0ad24b5..4c79163e3f 100644 +--- a/drivers/net/hns3/hns3_rxtx.c ++++ b/drivers/net/hns3/hns3_rxtx.c +@@ -586,7 +586,7 @@ hns3_tqp_enable(struct hns3_hw *hw, uint16_t queue_id, bool enable) + + ret = hns3_cmd_send(hw, &desc, 1); + if (ret) +- hns3_err(hw, "TQP enable fail, ret = %d", ret); ++ hns3_err(hw, "TQP %s fail, ret = %d", enable ? "enable" : "disable", ret); + + return ret; + } +@@ -1635,7 +1635,7 @@ hns3_set_fake_rx_or_tx_queues(struct rte_eth_dev *dev, uint16_t nb_rx_q, + + ret = hns3_fake_tx_queue_config(hw, tx_need_add_nb_q); + if (ret) { +- hns3_err(hw, "Fail to configure fake rx queues: %d", ret); ++ hns3_err(hw, "Fail to configure fake tx queues: %d", ret); + goto cfg_fake_tx_q_fail; + } + +-- +2.23.0 + diff --git a/0310-net-hns3-fix-redundant-line-break-in-log.patch b/0310-net-hns3-fix-redundant-line-break-in-log.patch new file mode 100644 index 0000000..b80b884 --- /dev/null +++ b/0310-net-hns3-fix-redundant-line-break-in-log.patch @@ -0,0 +1,71 @@ +From acc1ca225b8618728abd2b971f55354a7f6eebcf Mon Sep 17 00:00:00 2001 +From: Dengdui Huang +Date: Fri, 2 Jun 2023 19:42:05 +0800 +Subject: net/hns3: fix redundant line break in log + +[ upstream commit 1af035107a4da0c5ea528afbde5d3d6ccc016437 ] + +This patch remove log redundant line break + +Fixes: d51867db65c1 ("net/hns3: add initialization") +Fixes: c6332c3cf9f0 ("net/hns3: support module EEPROM dump") +Cc: stable@dpdk.org + +Signed-off-by: Dengdui Huang +Signed-off-by: Dongdong Liu +--- + drivers/net/hns3/hns3_ethdev.c | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c +index d7443e197c..9af08a7748 100644 +--- a/drivers/net/hns3/hns3_ethdev.c ++++ b/drivers/net/hns3/hns3_ethdev.c +@@ -3631,7 +3631,7 @@ hns3_get_mac_ethertype_cmd_status(uint16_t cmdq_resp, uint8_t resp_code) + + if (cmdq_resp) { + PMD_INIT_LOG(ERR, +- "cmdq execute failed for get_mac_ethertype_cmd_status, status=%u.\n", ++ "cmdq execute failed for get_mac_ethertype_cmd_status, status=%u.", + cmdq_resp); + return -EIO; + } +@@ -6235,7 +6235,7 @@ hns3_optical_module_existed(struct hns3_hw *hw) + ret = hns3_cmd_send(hw, &desc, 1); + if (ret) { + hns3_err(hw, +- "fail to get optical module exist state, ret = %d.\n", ++ "fail to get optical module exist state, ret = %d.", + ret); + return false; + } +@@ -6273,7 +6273,7 @@ hns3_get_module_eeprom_data(struct hns3_hw *hw, uint32_t offset, + + ret = hns3_cmd_send(hw, desc, HNS3_SFP_INFO_CMD_NUM); + if (ret) { +- hns3_err(hw, "fail to get module EEPROM info, ret = %d.\n", ++ hns3_err(hw, "fail to get module EEPROM info, ret = %d.", + ret); + return ret; + } +@@ -6310,7 +6310,7 @@ hns3_get_module_eeprom(struct rte_eth_dev *dev, + return -ENOTSUP; + + if (!hns3_optical_module_existed(hw)) { +- hns3_err(hw, "fail to read module EEPROM: no module is connected.\n"); ++ hns3_err(hw, "fail to read module EEPROM: no module is connected."); + return -EIO; + } + +@@ -6373,7 +6373,7 @@ hns3_get_module_info(struct rte_eth_dev *dev, + modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8636_MAX_LEN; + break; + default: +- hns3_err(hw, "unknown module, type = %u, extra_type = %u.\n", ++ hns3_err(hw, "unknown module, type = %u, extra_type = %u.", + sfp_type.type, sfp_type.ext_type); + return -EINVAL; + } +-- +2.23.0 + diff --git a/dpdk.spec b/dpdk.spec index 24d6d4c..36a09ca 100644 --- a/dpdk.spec +++ b/dpdk.spec @@ -1,6 +1,6 @@ Name: dpdk Version: 21.11 -Release: 45 +Release: 46 Packager: packaging@6wind.com URL: http://dpdk.org %global source_version 21.11 @@ -318,6 +318,18 @@ Patch9296: 0296-ethdev-introduce-low-latency-RS-FEC.patch Patch9297: 0297-app-testpmd-add-setting-and-querying-of-LLRS-FEC-mod.patch Patch9298: 0298-net-hns3-add-LLRS-FEC-mode-support-for-200G-ports.patch Patch9299: 0299-net-hns3-get-current-FEC-capability-from-firmware.patch +Patch9300: 0300-net-hns3-fix-RTC-time-on-initialization.patch +Patch9301: 0301-net-hns3-fix-RTC-time-after-reset.patch +Patch9302: 0302-net-hns3-uninitialize-PTP.patch +Patch9303: 0303-net-hns3-extract-PTP-to-its-own-header-file.patch +Patch9304: 0304-net-hns3-fix-mbuf-leakage-when-RxQ-started-during-re.patch +Patch9305: 0305-net-hns3-fix-mbuf-leakage-when-RxQ-started-after-res.patch +Patch9306: 0306-net-hns3-fix-device-start-return-value.patch +Patch9307: 0307-net-hns3-fix-uninitialized-variable.patch +Patch9308: 0308-net-hns3-refactor-code.patch +Patch9309: 0309-net-hns3-fix-inaccurate-log.patch +Patch9310: 0310-net-hns3-fix-redundant-line-break-in-log.patch + Summary: Data Plane Development Kit core Group: System Environment/Libraries @@ -462,6 +474,14 @@ strip -g $RPM_BUILD_ROOT/lib/modules/%{kern_devel_ver}/extra/dpdk/igb_uio.ko /usr/sbin/depmod %changelog +* Mon Jun 05 2023 chenjiji - 21.11-46 + Sync some patchs from upstreaming for hns3 pmd and modifications + are as follow: + 1. fix RTC time after reset + 2. fix Rx ring mbuf leakage at reset process + 3. fix an uninitialized variable + 4. modify the code that violates the coding standards + * Fri Jun 02 2023 chenjiji - 21.11-45 Sync some patchs from upstreaming about FEC feature. Patchs are as follow: -- Gitee