net/hns3: fix inaccurate RTC time to read

Message ID 20230109082344.17253-1-lihuisong@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series net/hns3: fix inaccurate RTC time to read |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

lihuisong (C) Jan. 9, 2023, 8:23 a.m. UTC
  The sequence of reading current RTC time register doesn't meet
the hardware requirements, which causes this time obtained is
the one before modifying RTC time.

Fixes: 38b539d96eb6 ("net/hns3: support IEEE 1588 PTP")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/net/hns3/hns3_ptp.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
  

Comments

Dongdong Liu Jan. 13, 2023, 6:49 a.m. UTC | #1
Hi Huisong

On 2023/1/9 16:23, Huisong Li wrote:
> The sequence of reading current RTC time register doesn't meet
> the hardware requirements, which causes this time obtained is
> the one before modifying RTC time.
>
> Fixes: 38b539d96eb6 ("net/hns3: support IEEE 1588 PTP")
> Cc: stable@dpdk.org
>
> Signed-off-by: Huisong Li <lihuisong@huawei.com>

Acked-by: Dongdong Liu <liudongdong3@huawei.com>

Thanks,
Dongdong
> ---
>  drivers/net/hns3/hns3_ptp.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/hns3/hns3_ptp.c b/drivers/net/hns3/hns3_ptp.c
> index 6bbd85ba23..db3c007b12 100644
> --- a/drivers/net/hns3/hns3_ptp.c
> +++ b/drivers/net/hns3/hns3_ptp.c
> @@ -216,17 +216,21 @@ hns3_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
>  int
>  hns3_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
>  {
> +#define HNS3_PTP_SEC_H_OFFSET	32
> +#define HNS3_PTP_SEC_H_MASK	0xFFFF
> +
>  	struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
> +	uint32_t sec_hi, sec_lo;
>  	uint64_t ns, sec;
>
>  	if (!hns3_dev_get_support(hw, PTP))
>  		return -ENOTSUP;
>
> -	sec = hns3_read_dev(hw, HNS3_CURR_TIME_OUT_L);
> -	sec |= (uint64_t)(hns3_read_dev(hw, HNS3_CURR_TIME_OUT_H) & 0xFFFF)
> -		<< 32;
> -
>  	ns = hns3_read_dev(hw, HNS3_CURR_TIME_OUT_NS);
> +	sec_hi = hns3_read_dev(hw, HNS3_CURR_TIME_OUT_H) & HNS3_PTP_SEC_H_MASK;
> +	sec_lo = hns3_read_dev(hw, HNS3_CURR_TIME_OUT_L);
> +	sec = ((uint64_t)sec_hi << HNS3_PTP_SEC_H_OFFSET) | sec_lo;
> +
>  	ns += sec * NSEC_PER_SEC;
>  	*ts = rte_ns_to_timespec(ns);
>
>
  
Ferruh Yigit Jan. 13, 2023, 11:05 a.m. UTC | #2
On 1/13/2023 6:49 AM, Dongdong Liu wrote:
> Hi Huisong
> 
> On 2023/1/9 16:23, Huisong Li wrote:
>> The sequence of reading current RTC time register doesn't meet
>> the hardware requirements, which causes this time obtained is
>> the one before modifying RTC time.
>>
>> Fixes: 38b539d96eb6 ("net/hns3: support IEEE 1588 PTP")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Huisong Li <lihuisong@huawei.com>
> 
> Acked-by: Dongdong Liu <liudongdong3@huawei.com>
> 

Applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/drivers/net/hns3/hns3_ptp.c b/drivers/net/hns3/hns3_ptp.c
index 6bbd85ba23..db3c007b12 100644
--- a/drivers/net/hns3/hns3_ptp.c
+++ b/drivers/net/hns3/hns3_ptp.c
@@ -216,17 +216,21 @@  hns3_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
 int
 hns3_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
 {
+#define HNS3_PTP_SEC_H_OFFSET	32
+#define HNS3_PTP_SEC_H_MASK	0xFFFF
+
 	struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	uint32_t sec_hi, sec_lo;
 	uint64_t ns, sec;
 
 	if (!hns3_dev_get_support(hw, PTP))
 		return -ENOTSUP;
 
-	sec = hns3_read_dev(hw, HNS3_CURR_TIME_OUT_L);
-	sec |= (uint64_t)(hns3_read_dev(hw, HNS3_CURR_TIME_OUT_H) & 0xFFFF)
-		<< 32;
-
 	ns = hns3_read_dev(hw, HNS3_CURR_TIME_OUT_NS);
+	sec_hi = hns3_read_dev(hw, HNS3_CURR_TIME_OUT_H) & HNS3_PTP_SEC_H_MASK;
+	sec_lo = hns3_read_dev(hw, HNS3_CURR_TIME_OUT_L);
+	sec = ((uint64_t)sec_hi << HNS3_PTP_SEC_H_OFFSET) | sec_lo;
+
 	ns += sec * NSEC_PER_SEC;
 	*ts = rte_ns_to_timespec(ns);