Skip to content

Commit 355f58f

Browse files
Jianbo LiuPaolo Abeni
authored andcommitted
net/mlx5: Add API to get mlx5_core_dev from mlx5_clock
The mdev is calculated directly from mlx5_clock, as it's one of the fields in mlx5_core_dev. Move to a function so it can be easily changed in next patch. Signed-off-by: Jianbo Liu <jianbol@nvidia.com> Reviewed-by: Carolina Jubran <cjubran@nvidia.com> Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent ccb717a commit 355f58f

File tree

1 file changed

+18
-17
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core/lib

1 file changed

+18
-17
lines changed

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ enum {
7777
MLX5_MTUTC_OPERATION_ADJUST_TIME_EXTENDED_MAX = 200000,
7878
};
7979

80+
static struct mlx5_core_dev *mlx5_clock_mdev_get(struct mlx5_clock *clock)
81+
{
82+
return container_of(clock, struct mlx5_core_dev, clock);
83+
}
84+
8085
static bool mlx5_real_time_mode(struct mlx5_core_dev *mdev)
8186
{
8287
return (mlx5_is_real_time_rq(mdev) || mlx5_is_real_time_sq(mdev));
@@ -131,7 +136,7 @@ static s32 mlx5_ptp_getmaxphase(struct ptp_clock_info *ptp)
131136
struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);
132137
struct mlx5_core_dev *mdev;
133138

134-
mdev = container_of(clock, struct mlx5_core_dev, clock);
139+
mdev = mlx5_clock_mdev_get(clock);
135140

136141
return mlx5_clock_getmaxphase(mdev);
137142
}
@@ -226,7 +231,7 @@ static int mlx5_ptp_getcrosststamp(struct ptp_clock_info *ptp,
226231
struct system_time_snapshot history_begin = {0};
227232
struct mlx5_core_dev *mdev;
228233

229-
mdev = container_of(clock, struct mlx5_core_dev, clock);
234+
mdev = mlx5_clock_mdev_get(clock);
230235

231236
if (!mlx5_is_ptm_source_time_available(mdev))
232237
return -EBUSY;
@@ -268,8 +273,7 @@ static u64 read_internal_timer(const struct cyclecounter *cc)
268273
{
269274
struct mlx5_timer *timer = container_of(cc, struct mlx5_timer, cycles);
270275
struct mlx5_clock *clock = container_of(timer, struct mlx5_clock, timer);
271-
struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev,
272-
clock);
276+
struct mlx5_core_dev *mdev = mlx5_clock_mdev_get(clock);
273277

274278
return mlx5_read_time(mdev, NULL, false) & cc->mask;
275279
}
@@ -304,8 +308,7 @@ static void mlx5_pps_out(struct work_struct *work)
304308
out_work);
305309
struct mlx5_clock *clock = container_of(pps_info, struct mlx5_clock,
306310
pps_info);
307-
struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev,
308-
clock);
311+
struct mlx5_core_dev *mdev = mlx5_clock_mdev_get(clock);
309312
u32 in[MLX5_ST_SZ_DW(mtpps_reg)] = {0};
310313
unsigned long flags;
311314
int i;
@@ -335,7 +338,7 @@ static long mlx5_timestamp_overflow(struct ptp_clock_info *ptp_info)
335338
unsigned long flags;
336339

337340
clock = container_of(ptp_info, struct mlx5_clock, ptp_info);
338-
mdev = container_of(clock, struct mlx5_core_dev, clock);
341+
mdev = mlx5_clock_mdev_get(clock);
339342
timer = &clock->timer;
340343

341344
if (mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR)
@@ -392,7 +395,7 @@ static int mlx5_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64
392395
struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);
393396
struct mlx5_core_dev *mdev;
394397

395-
mdev = container_of(clock, struct mlx5_core_dev, clock);
398+
mdev = mlx5_clock_mdev_get(clock);
396399

397400
return mlx5_clock_settime(mdev, clock, ts);
398401
}
@@ -416,7 +419,7 @@ static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts,
416419
struct mlx5_core_dev *mdev;
417420
u64 cycles, ns;
418421

419-
mdev = container_of(clock, struct mlx5_core_dev, clock);
422+
mdev = mlx5_clock_mdev_get(clock);
420423
if (mlx5_real_time_mode(mdev)) {
421424
*ts = mlx5_ptp_gettimex_real_time(mdev, sts);
422425
goto out;
@@ -457,7 +460,7 @@ static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
457460
struct mlx5_core_dev *mdev;
458461
unsigned long flags;
459462

460-
mdev = container_of(clock, struct mlx5_core_dev, clock);
463+
mdev = mlx5_clock_mdev_get(clock);
461464

462465
if (mlx5_modify_mtutc_allowed(mdev)) {
463466
int err = mlx5_ptp_adjtime_real_time(mdev, delta);
@@ -479,7 +482,7 @@ static int mlx5_ptp_adjphase(struct ptp_clock_info *ptp, s32 delta)
479482
struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);
480483
struct mlx5_core_dev *mdev;
481484

482-
mdev = container_of(clock, struct mlx5_core_dev, clock);
485+
mdev = mlx5_clock_mdev_get(clock);
483486

484487
return mlx5_ptp_adjtime_real_time(mdev, delta);
485488
}
@@ -512,7 +515,7 @@ static int mlx5_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
512515
unsigned long flags;
513516
u32 mult;
514517

515-
mdev = container_of(clock, struct mlx5_core_dev, clock);
518+
mdev = mlx5_clock_mdev_get(clock);
516519

517520
if (mlx5_modify_mtutc_allowed(mdev)) {
518521
int err = mlx5_ptp_freq_adj_real_time(mdev, scaled_ppm);
@@ -539,8 +542,7 @@ static int mlx5_extts_configure(struct ptp_clock_info *ptp,
539542
{
540543
struct mlx5_clock *clock =
541544
container_of(ptp, struct mlx5_clock, ptp_info);
542-
struct mlx5_core_dev *mdev =
543-
container_of(clock, struct mlx5_core_dev, clock);
545+
struct mlx5_core_dev *mdev = mlx5_clock_mdev_get(clock);
544546
u32 in[MLX5_ST_SZ_DW(mtpps_reg)] = {0};
545547
u32 field_select = 0;
546548
u8 pin_mode = 0;
@@ -724,8 +726,7 @@ static int mlx5_perout_configure(struct ptp_clock_info *ptp,
724726
{
725727
struct mlx5_clock *clock =
726728
container_of(ptp, struct mlx5_clock, ptp_info);
727-
struct mlx5_core_dev *mdev =
728-
container_of(clock, struct mlx5_core_dev, clock);
729+
struct mlx5_core_dev *mdev = mlx5_clock_mdev_get(clock);
729730
bool rt_mode = mlx5_real_time_mode(mdev);
730731
u32 in[MLX5_ST_SZ_DW(mtpps_reg)] = {0};
731732
u32 out_pulse_duration_ns = 0;
@@ -987,7 +988,7 @@ static int mlx5_pps_event(struct notifier_block *nb,
987988
unsigned long flags;
988989
u64 ns;
989990

990-
mdev = container_of(clock, struct mlx5_core_dev, clock);
991+
mdev = mlx5_clock_mdev_get(clock);
991992

992993
switch (clock->ptp_info.pin_config[pin].func) {
993994
case PTP_PF_EXTTS:

0 commit comments

Comments
 (0)