Skip to content

Commit

Permalink
net/hns3: fix RTC time on initialization
Browse files Browse the repository at this point in the history
[ upstream commit f901c570e50d042f466de29b186db68e177f93ab ]

Driver doesn't initialize RTC time during probe phase, which
lead to an inaccurate time.

Fixes: 38b539d ("net/hns3: support IEEE 1588 PTP")

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
  • Loading branch information
LiHuiSong1 authored and kevintraynor committed Jul 11, 2023
1 parent 57a458d commit bf28f06
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions drivers/net/hns3/hns3_ptp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit bf28f06

Please sign in to comment.