Commit fb609b51 authored by Eran Ben Elisha's avatar Eran Ben Elisha Committed by Saeed Mahameed

net/mlx5: Always use container_of to find mdev pointer from clock struct

Clock struct is part of struct mlx5_core_dev. Code was inconsistent, on
some cases used container_of and on another used clock->mdev.

Align code to use container_of amd remove clock->mdev pointer.
While here, fix reverse xmas tree coding style.
Signed-off-by: default avatarEran Ben Elisha <eranbe@mellanox.com>
Reviewed-by: default avatarMoshe Shemesh <moshe@mellanox.com>
parent ec529b44
...@@ -150,28 +150,30 @@ static void mlx5_pps_out(struct work_struct *work) ...@@ -150,28 +150,30 @@ static void mlx5_pps_out(struct work_struct *work)
static void mlx5_timestamp_overflow(struct work_struct *work) static void mlx5_timestamp_overflow(struct work_struct *work)
{ {
struct delayed_work *dwork = to_delayed_work(work); struct delayed_work *dwork = to_delayed_work(work);
struct mlx5_clock *clock = container_of(dwork, struct mlx5_clock, struct mlx5_core_dev *mdev;
overflow_work); struct mlx5_clock *clock;
unsigned long flags; unsigned long flags;
clock = container_of(dwork, struct mlx5_clock, overflow_work);
mdev = container_of(clock, struct mlx5_core_dev, clock);
write_seqlock_irqsave(&clock->lock, flags); write_seqlock_irqsave(&clock->lock, flags);
timecounter_read(&clock->tc); timecounter_read(&clock->tc);
mlx5_update_clock_info_page(clock->mdev); mlx5_update_clock_info_page(mdev);
write_sequnlock_irqrestore(&clock->lock, flags); write_sequnlock_irqrestore(&clock->lock, flags);
schedule_delayed_work(&clock->overflow_work, clock->overflow_period); schedule_delayed_work(&clock->overflow_work, clock->overflow_period);
} }
static int mlx5_ptp_settime(struct ptp_clock_info *ptp, static int mlx5_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64 *ts)
const struct timespec64 *ts)
{ {
struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);
ptp_info);
u64 ns = timespec64_to_ns(ts); u64 ns = timespec64_to_ns(ts);
struct mlx5_core_dev *mdev;
unsigned long flags; unsigned long flags;
mdev = container_of(clock, struct mlx5_core_dev, clock);
write_seqlock_irqsave(&clock->lock, flags); write_seqlock_irqsave(&clock->lock, flags);
timecounter_init(&clock->tc, &clock->cycles, ns); timecounter_init(&clock->tc, &clock->cycles, ns);
mlx5_update_clock_info_page(clock->mdev); mlx5_update_clock_info_page(mdev);
write_sequnlock_irqrestore(&clock->lock, flags); write_sequnlock_irqrestore(&clock->lock, flags);
return 0; return 0;
...@@ -180,13 +182,12 @@ static int mlx5_ptp_settime(struct ptp_clock_info *ptp, ...@@ -180,13 +182,12 @@ static int mlx5_ptp_settime(struct ptp_clock_info *ptp,
static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts, static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts,
struct ptp_system_timestamp *sts) struct ptp_system_timestamp *sts)
{ {
struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);
ptp_info); struct mlx5_core_dev *mdev;
struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev,
clock);
unsigned long flags; unsigned long flags;
u64 cycles, ns; u64 cycles, ns;
mdev = container_of(clock, struct mlx5_core_dev, clock);
write_seqlock_irqsave(&clock->lock, flags); write_seqlock_irqsave(&clock->lock, flags);
cycles = mlx5_read_internal_timer(mdev, sts); cycles = mlx5_read_internal_timer(mdev, sts);
ns = timecounter_cyc2time(&clock->tc, cycles); ns = timecounter_cyc2time(&clock->tc, cycles);
...@@ -199,13 +200,14 @@ static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts, ...@@ -199,13 +200,14 @@ static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts,
static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
{ {
struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);
ptp_info); struct mlx5_core_dev *mdev;
unsigned long flags; unsigned long flags;
mdev = container_of(clock, struct mlx5_core_dev, clock);
write_seqlock_irqsave(&clock->lock, flags); write_seqlock_irqsave(&clock->lock, flags);
timecounter_adjtime(&clock->tc, delta); timecounter_adjtime(&clock->tc, delta);
mlx5_update_clock_info_page(clock->mdev); mlx5_update_clock_info_page(mdev);
write_sequnlock_irqrestore(&clock->lock, flags); write_sequnlock_irqrestore(&clock->lock, flags);
return 0; return 0;
...@@ -213,12 +215,13 @@ static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) ...@@ -213,12 +215,13 @@ static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
static int mlx5_ptp_adjfreq(struct ptp_clock_info *ptp, s32 delta) static int mlx5_ptp_adjfreq(struct ptp_clock_info *ptp, s32 delta)
{ {
u64 adj; struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);
u32 diff; struct mlx5_core_dev *mdev;
unsigned long flags; unsigned long flags;
int neg_adj = 0; int neg_adj = 0;
struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, u32 diff;
ptp_info); u64 adj;
if (delta < 0) { if (delta < 0) {
neg_adj = 1; neg_adj = 1;
...@@ -229,11 +232,12 @@ static int mlx5_ptp_adjfreq(struct ptp_clock_info *ptp, s32 delta) ...@@ -229,11 +232,12 @@ static int mlx5_ptp_adjfreq(struct ptp_clock_info *ptp, s32 delta)
adj *= delta; adj *= delta;
diff = div_u64(adj, 1000000000ULL); diff = div_u64(adj, 1000000000ULL);
mdev = container_of(clock, struct mlx5_core_dev, clock);
write_seqlock_irqsave(&clock->lock, flags); write_seqlock_irqsave(&clock->lock, flags);
timecounter_read(&clock->tc); timecounter_read(&clock->tc);
clock->cycles.mult = neg_adj ? clock->nominal_c_mult - diff : clock->cycles.mult = neg_adj ? clock->nominal_c_mult - diff :
clock->nominal_c_mult + diff; clock->nominal_c_mult + diff;
mlx5_update_clock_info_page(clock->mdev); mlx5_update_clock_info_page(mdev);
write_sequnlock_irqrestore(&clock->lock, flags); write_sequnlock_irqrestore(&clock->lock, flags);
return 0; return 0;
...@@ -465,7 +469,8 @@ static int mlx5_query_mtpps_pin_mode(struct mlx5_core_dev *mdev, u8 pin, ...@@ -465,7 +469,8 @@ static int mlx5_query_mtpps_pin_mode(struct mlx5_core_dev *mdev, u8 pin,
static int mlx5_get_pps_pin_mode(struct mlx5_clock *clock, u8 pin) static int mlx5_get_pps_pin_mode(struct mlx5_clock *clock, u8 pin)
{ {
struct mlx5_core_dev *mdev = clock->mdev; struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev, clock);
u32 out[MLX5_ST_SZ_DW(mtpps_reg)] = {}; u32 out[MLX5_ST_SZ_DW(mtpps_reg)] = {};
u8 mode; u8 mode;
int err; int err;
...@@ -538,15 +543,17 @@ static int mlx5_pps_event(struct notifier_block *nb, ...@@ -538,15 +543,17 @@ static int mlx5_pps_event(struct notifier_block *nb,
unsigned long type, void *data) unsigned long type, void *data)
{ {
struct mlx5_clock *clock = mlx5_nb_cof(nb, struct mlx5_clock, pps_nb); struct mlx5_clock *clock = mlx5_nb_cof(nb, struct mlx5_clock, pps_nb);
struct mlx5_core_dev *mdev = clock->mdev;
struct ptp_clock_event ptp_event; struct ptp_clock_event ptp_event;
u64 cycles_now, cycles_delta; u64 cycles_now, cycles_delta;
u64 nsec_now, nsec_delta, ns; u64 nsec_now, nsec_delta, ns;
struct mlx5_eqe *eqe = data; struct mlx5_eqe *eqe = data;
int pin = eqe->data.pps.pin; int pin = eqe->data.pps.pin;
struct mlx5_core_dev *mdev;
struct timespec64 ts; struct timespec64 ts;
unsigned long flags; unsigned long flags;
mdev = container_of(clock, struct mlx5_core_dev, clock);
switch (clock->ptp_info.pin_config[pin].func) { switch (clock->ptp_info.pin_config[pin].func) {
case PTP_PF_EXTTS: case PTP_PF_EXTTS:
ptp_event.index = pin; ptp_event.index = pin;
...@@ -605,7 +612,6 @@ void mlx5_init_clock(struct mlx5_core_dev *mdev) ...@@ -605,7 +612,6 @@ void mlx5_init_clock(struct mlx5_core_dev *mdev)
clock->cycles.shift); clock->cycles.shift);
clock->nominal_c_mult = clock->cycles.mult; clock->nominal_c_mult = clock->cycles.mult;
clock->cycles.mask = CLOCKSOURCE_MASK(41); clock->cycles.mask = CLOCKSOURCE_MASK(41);
clock->mdev = mdev;
timecounter_init(&clock->tc, &clock->cycles, timecounter_init(&clock->tc, &clock->cycles,
ktime_to_ns(ktime_get_real())); ktime_to_ns(ktime_get_real()));
......
...@@ -643,7 +643,6 @@ struct mlx5_pps { ...@@ -643,7 +643,6 @@ struct mlx5_pps {
}; };
struct mlx5_clock { struct mlx5_clock {
struct mlx5_core_dev *mdev;
struct mlx5_nb pps_nb; struct mlx5_nb pps_nb;
seqlock_t lock; seqlock_t lock;
struct cyclecounter cycles; struct cyclecounter cycles;
......
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