Commit 330af90c authored by Rahul Rameshbabu's avatar Rahul Rameshbabu Committed by Saeed Mahameed

net/mlx5: Refactor real time clock operation checks for PHC

Check if the MTUTC register of the NIC can be modified before attempting to
execute a real-time clock operation. Previous implementation aborted the
real-time clock operation pre-emptively when the MTUTC register used to
control the real-time clock was not modifiable, indicating real-time clock
mode was not enabled on the NIC. The original control flow was confusing
since the noop-if-RTC-disabled branch looked similar to an error handling
guard clause. The purpose of this patch is purely for improving readability
and should lead to no functional change.
Signed-off-by: default avatarRahul Rameshbabu <rrameshbabu@nvidia.com>
Reviewed-by: default avatarTariq Toukan <tariqt@nvidia.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@nvidia.com>
parent 88e928b2
...@@ -266,9 +266,6 @@ static int mlx5_ptp_settime_real_time(struct mlx5_core_dev *mdev, ...@@ -266,9 +266,6 @@ static int mlx5_ptp_settime_real_time(struct mlx5_core_dev *mdev,
{ {
u32 in[MLX5_ST_SZ_DW(mtutc_reg)] = {}; u32 in[MLX5_ST_SZ_DW(mtutc_reg)] = {};
if (!mlx5_modify_mtutc_allowed(mdev))
return 0;
if (ts->tv_sec < 0 || ts->tv_sec > U32_MAX || if (ts->tv_sec < 0 || ts->tv_sec > U32_MAX ||
ts->tv_nsec < 0 || ts->tv_nsec > NSEC_PER_SEC) ts->tv_nsec < 0 || ts->tv_nsec > NSEC_PER_SEC)
return -EINVAL; return -EINVAL;
...@@ -286,12 +283,15 @@ static int mlx5_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64 ...@@ -286,12 +283,15 @@ static int mlx5_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64
struct mlx5_timer *timer = &clock->timer; struct mlx5_timer *timer = &clock->timer;
struct mlx5_core_dev *mdev; struct mlx5_core_dev *mdev;
unsigned long flags; unsigned long flags;
int err;
mdev = container_of(clock, struct mlx5_core_dev, clock); mdev = container_of(clock, struct mlx5_core_dev, clock);
err = mlx5_ptp_settime_real_time(mdev, ts);
if (mlx5_modify_mtutc_allowed(mdev)) {
int err = mlx5_ptp_settime_real_time(mdev, ts);
if (err) if (err)
return err; return err;
}
write_seqlock_irqsave(&clock->lock, flags); write_seqlock_irqsave(&clock->lock, flags);
timecounter_init(&timer->tc, &timer->cycles, timespec64_to_ns(ts)); timecounter_init(&timer->tc, &timer->cycles, timespec64_to_ns(ts));
...@@ -341,9 +341,6 @@ static int mlx5_ptp_adjtime_real_time(struct mlx5_core_dev *mdev, s64 delta) ...@@ -341,9 +341,6 @@ static int mlx5_ptp_adjtime_real_time(struct mlx5_core_dev *mdev, s64 delta)
{ {
u32 in[MLX5_ST_SZ_DW(mtutc_reg)] = {}; u32 in[MLX5_ST_SZ_DW(mtutc_reg)] = {};
if (!mlx5_modify_mtutc_allowed(mdev))
return 0;
/* HW time adjustment range is checked. If out of range, settime instead */ /* HW time adjustment range is checked. If out of range, settime instead */
if (!mlx5_is_mtutc_time_adj_cap(mdev, delta)) { if (!mlx5_is_mtutc_time_adj_cap(mdev, delta)) {
struct timespec64 ts; struct timespec64 ts;
...@@ -367,13 +364,16 @@ static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) ...@@ -367,13 +364,16 @@ static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
struct mlx5_timer *timer = &clock->timer; struct mlx5_timer *timer = &clock->timer;
struct mlx5_core_dev *mdev; struct mlx5_core_dev *mdev;
unsigned long flags; unsigned long flags;
int err;
mdev = container_of(clock, struct mlx5_core_dev, clock); mdev = container_of(clock, struct mlx5_core_dev, clock);
err = mlx5_ptp_adjtime_real_time(mdev, delta); if (mlx5_modify_mtutc_allowed(mdev)) {
int err = mlx5_ptp_adjtime_real_time(mdev, delta);
if (err) if (err)
return err; return err;
}
write_seqlock_irqsave(&clock->lock, flags); write_seqlock_irqsave(&clock->lock, flags);
timecounter_adjtime(&timer->tc, delta); timecounter_adjtime(&timer->tc, delta);
mlx5_update_clock_info_page(mdev); mlx5_update_clock_info_page(mdev);
...@@ -391,9 +391,6 @@ static int mlx5_ptp_freq_adj_real_time(struct mlx5_core_dev *mdev, long scaled_p ...@@ -391,9 +391,6 @@ static int mlx5_ptp_freq_adj_real_time(struct mlx5_core_dev *mdev, long scaled_p
{ {
u32 in[MLX5_ST_SZ_DW(mtutc_reg)] = {}; u32 in[MLX5_ST_SZ_DW(mtutc_reg)] = {};
if (!mlx5_modify_mtutc_allowed(mdev))
return 0;
MLX5_SET(mtutc_reg, in, operation, MLX5_MTUTC_OPERATION_ADJUST_FREQ_UTC); MLX5_SET(mtutc_reg, in, operation, MLX5_MTUTC_OPERATION_ADJUST_FREQ_UTC);
if (MLX5_CAP_MCAM_FEATURE(mdev, mtutc_freq_adj_units)) { if (MLX5_CAP_MCAM_FEATURE(mdev, mtutc_freq_adj_units)) {
...@@ -415,13 +412,15 @@ static int mlx5_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) ...@@ -415,13 +412,15 @@ static int mlx5_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
struct mlx5_core_dev *mdev; struct mlx5_core_dev *mdev;
unsigned long flags; unsigned long flags;
u32 mult; u32 mult;
int err;
mdev = container_of(clock, struct mlx5_core_dev, clock); mdev = container_of(clock, struct mlx5_core_dev, clock);
err = mlx5_ptp_freq_adj_real_time(mdev, scaled_ppm); if (mlx5_modify_mtutc_allowed(mdev)) {
int err = mlx5_ptp_freq_adj_real_time(mdev, scaled_ppm);
if (err) if (err)
return err; return err;
}
mult = (u32)adjust_by_scaled_ppm(timer->nominal_c_mult, scaled_ppm); mult = (u32)adjust_by_scaled_ppm(timer->nominal_c_mult, scaled_ppm);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment