@@ -150,28 +150,30 @@ static void mlx5_pps_out(struct work_struct *work)
150150static void mlx5_timestamp_overflow (struct work_struct * work )
151151{
152152 struct delayed_work * dwork = to_delayed_work (work );
153- struct mlx5_clock * clock = container_of ( dwork , struct mlx5_clock ,
154- overflow_work ) ;
153+ struct mlx5_core_dev * mdev ;
154+ struct mlx5_clock * clock ;
155155 unsigned long flags ;
156156
157+ clock = container_of (dwork , struct mlx5_clock , overflow_work );
158+ mdev = container_of (clock , struct mlx5_core_dev , clock );
157159 write_seqlock_irqsave (& clock -> lock , flags );
158160 timecounter_read (& clock -> tc );
159- mlx5_update_clock_info_page (clock -> mdev );
161+ mlx5_update_clock_info_page (mdev );
160162 write_sequnlock_irqrestore (& clock -> lock , flags );
161163 schedule_delayed_work (& clock -> overflow_work , clock -> overflow_period );
162164}
163165
164- static int mlx5_ptp_settime (struct ptp_clock_info * ptp ,
165- const struct timespec64 * ts )
166+ static int mlx5_ptp_settime (struct ptp_clock_info * ptp , const struct timespec64 * ts )
166167{
167- struct mlx5_clock * clock = container_of (ptp , struct mlx5_clock ,
168- ptp_info );
168+ struct mlx5_clock * clock = container_of (ptp , struct mlx5_clock , ptp_info );
169169 u64 ns = timespec64_to_ns (ts );
170+ struct mlx5_core_dev * mdev ;
170171 unsigned long flags ;
171172
173+ mdev = container_of (clock , struct mlx5_core_dev , clock );
172174 write_seqlock_irqsave (& clock -> lock , flags );
173175 timecounter_init (& clock -> tc , & clock -> cycles , ns );
174- mlx5_update_clock_info_page (clock -> mdev );
176+ mlx5_update_clock_info_page (mdev );
175177 write_sequnlock_irqrestore (& clock -> lock , flags );
176178
177179 return 0 ;
@@ -180,13 +182,12 @@ static int mlx5_ptp_settime(struct ptp_clock_info *ptp,
180182static int mlx5_ptp_gettimex (struct ptp_clock_info * ptp , struct timespec64 * ts ,
181183 struct ptp_system_timestamp * sts )
182184{
183- struct mlx5_clock * clock = container_of (ptp , struct mlx5_clock ,
184- ptp_info );
185- struct mlx5_core_dev * mdev = container_of (clock , struct mlx5_core_dev ,
186- clock );
185+ struct mlx5_clock * clock = container_of (ptp , struct mlx5_clock , ptp_info );
186+ struct mlx5_core_dev * mdev ;
187187 unsigned long flags ;
188188 u64 cycles , ns ;
189189
190+ mdev = container_of (clock , struct mlx5_core_dev , clock );
190191 write_seqlock_irqsave (& clock -> lock , flags );
191192 cycles = mlx5_read_internal_timer (mdev , sts );
192193 ns = timecounter_cyc2time (& clock -> tc , cycles );
@@ -199,26 +200,28 @@ static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts,
199200
200201static int mlx5_ptp_adjtime (struct ptp_clock_info * ptp , s64 delta )
201202{
202- struct mlx5_clock * clock = container_of (ptp , struct mlx5_clock ,
203- ptp_info ) ;
203+ struct mlx5_clock * clock = container_of (ptp , struct mlx5_clock , ptp_info );
204+ struct mlx5_core_dev * mdev ;
204205 unsigned long flags ;
205206
207+ mdev = container_of (clock , struct mlx5_core_dev , clock );
206208 write_seqlock_irqsave (& clock -> lock , flags );
207209 timecounter_adjtime (& clock -> tc , delta );
208- mlx5_update_clock_info_page (clock -> mdev );
210+ mlx5_update_clock_info_page (mdev );
209211 write_sequnlock_irqrestore (& clock -> lock , flags );
210212
211213 return 0 ;
212214}
213215
214216static int mlx5_ptp_adjfreq (struct ptp_clock_info * ptp , s32 delta )
215217{
216- u64 adj ;
217- u32 diff ;
218+ struct mlx5_clock * clock = container_of ( ptp , struct mlx5_clock , ptp_info ) ;
219+ struct mlx5_core_dev * mdev ;
218220 unsigned long flags ;
219221 int neg_adj = 0 ;
220- struct mlx5_clock * clock = container_of (ptp , struct mlx5_clock ,
221- ptp_info );
222+ u32 diff ;
223+ u64 adj ;
224+
222225
223226 if (delta < 0 ) {
224227 neg_adj = 1 ;
@@ -229,11 +232,12 @@ static int mlx5_ptp_adjfreq(struct ptp_clock_info *ptp, s32 delta)
229232 adj *= delta ;
230233 diff = div_u64 (adj , 1000000000ULL );
231234
235+ mdev = container_of (clock , struct mlx5_core_dev , clock );
232236 write_seqlock_irqsave (& clock -> lock , flags );
233237 timecounter_read (& clock -> tc );
234238 clock -> cycles .mult = neg_adj ? clock -> nominal_c_mult - diff :
235239 clock -> nominal_c_mult + diff ;
236- mlx5_update_clock_info_page (clock -> mdev );
240+ mlx5_update_clock_info_page (mdev );
237241 write_sequnlock_irqrestore (& clock -> lock , flags );
238242
239243 return 0 ;
@@ -465,7 +469,8 @@ static int mlx5_query_mtpps_pin_mode(struct mlx5_core_dev *mdev, u8 pin,
465469
466470static int mlx5_get_pps_pin_mode (struct mlx5_clock * clock , u8 pin )
467471{
468- struct mlx5_core_dev * mdev = clock -> mdev ;
472+ struct mlx5_core_dev * mdev = container_of (clock , struct mlx5_core_dev , clock );
473+
469474 u32 out [MLX5_ST_SZ_DW (mtpps_reg )] = {};
470475 u8 mode ;
471476 int err ;
@@ -538,15 +543,17 @@ static int mlx5_pps_event(struct notifier_block *nb,
538543 unsigned long type , void * data )
539544{
540545 struct mlx5_clock * clock = mlx5_nb_cof (nb , struct mlx5_clock , pps_nb );
541- struct mlx5_core_dev * mdev = clock -> mdev ;
542546 struct ptp_clock_event ptp_event ;
543547 u64 cycles_now , cycles_delta ;
544548 u64 nsec_now , nsec_delta , ns ;
545549 struct mlx5_eqe * eqe = data ;
546550 int pin = eqe -> data .pps .pin ;
551+ struct mlx5_core_dev * mdev ;
547552 struct timespec64 ts ;
548553 unsigned long flags ;
549554
555+ mdev = container_of (clock , struct mlx5_core_dev , clock );
556+
550557 switch (clock -> ptp_info .pin_config [pin ].func ) {
551558 case PTP_PF_EXTTS :
552559 ptp_event .index = pin ;
@@ -605,7 +612,6 @@ void mlx5_init_clock(struct mlx5_core_dev *mdev)
605612 clock -> cycles .shift );
606613 clock -> nominal_c_mult = clock -> cycles .mult ;
607614 clock -> cycles .mask = CLOCKSOURCE_MASK (41 );
608- clock -> mdev = mdev ;
609615
610616 timecounter_init (& clock -> tc , & clock -> cycles ,
611617 ktime_to_ns (ktime_get_real ()));
0 commit comments