Skip to content

Commit 330af90

Browse files
Binary-EaterSaeed Mahameed
authored andcommitted
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: Rahul Rameshbabu <[email protected]> Reviewed-by: Tariq Toukan <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 88e928b commit 330af90

File tree

1 file changed

+20
-21
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core/lib

1 file changed

+20
-21
lines changed

drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,6 @@ static int mlx5_ptp_settime_real_time(struct mlx5_core_dev *mdev,
266266
{
267267
u32 in[MLX5_ST_SZ_DW(mtutc_reg)] = {};
268268

269-
if (!mlx5_modify_mtutc_allowed(mdev))
270-
return 0;
271-
272269
if (ts->tv_sec < 0 || ts->tv_sec > U32_MAX ||
273270
ts->tv_nsec < 0 || ts->tv_nsec > NSEC_PER_SEC)
274271
return -EINVAL;
@@ -286,12 +283,15 @@ static int mlx5_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64
286283
struct mlx5_timer *timer = &clock->timer;
287284
struct mlx5_core_dev *mdev;
288285
unsigned long flags;
289-
int err;
290286

291287
mdev = container_of(clock, struct mlx5_core_dev, clock);
292-
err = mlx5_ptp_settime_real_time(mdev, ts);
293-
if (err)
294-
return err;
288+
289+
if (mlx5_modify_mtutc_allowed(mdev)) {
290+
int err = mlx5_ptp_settime_real_time(mdev, ts);
291+
292+
if (err)
293+
return err;
294+
}
295295

296296
write_seqlock_irqsave(&clock->lock, flags);
297297
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)
341341
{
342342
u32 in[MLX5_ST_SZ_DW(mtutc_reg)] = {};
343343

344-
if (!mlx5_modify_mtutc_allowed(mdev))
345-
return 0;
346-
347344
/* HW time adjustment range is checked. If out of range, settime instead */
348345
if (!mlx5_is_mtutc_time_adj_cap(mdev, delta)) {
349346
struct timespec64 ts;
@@ -367,13 +364,16 @@ static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
367364
struct mlx5_timer *timer = &clock->timer;
368365
struct mlx5_core_dev *mdev;
369366
unsigned long flags;
370-
int err;
371367

372368
mdev = container_of(clock, struct mlx5_core_dev, clock);
373369

374-
err = mlx5_ptp_adjtime_real_time(mdev, delta);
375-
if (err)
376-
return err;
370+
if (mlx5_modify_mtutc_allowed(mdev)) {
371+
int err = mlx5_ptp_adjtime_real_time(mdev, delta);
372+
373+
if (err)
374+
return err;
375+
}
376+
377377
write_seqlock_irqsave(&clock->lock, flags);
378378
timecounter_adjtime(&timer->tc, delta);
379379
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
391391
{
392392
u32 in[MLX5_ST_SZ_DW(mtutc_reg)] = {};
393393

394-
if (!mlx5_modify_mtutc_allowed(mdev))
395-
return 0;
396-
397394
MLX5_SET(mtutc_reg, in, operation, MLX5_MTUTC_OPERATION_ADJUST_FREQ_UTC);
398395

399396
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)
415412
struct mlx5_core_dev *mdev;
416413
unsigned long flags;
417414
u32 mult;
418-
int err;
419415

420416
mdev = container_of(clock, struct mlx5_core_dev, clock);
421417

422-
err = mlx5_ptp_freq_adj_real_time(mdev, scaled_ppm);
423-
if (err)
424-
return err;
418+
if (mlx5_modify_mtutc_allowed(mdev)) {
419+
int err = mlx5_ptp_freq_adj_real_time(mdev, scaled_ppm);
420+
421+
if (err)
422+
return err;
423+
}
425424

426425
mult = (u32)adjust_by_scaled_ppm(timer->nominal_c_mult, scaled_ppm);
427426

0 commit comments

Comments
 (0)