Lines Matching +full:ptp +full:- +full:timer
14 * - Redistributions of source code must retain the above
18 * - Redistributions in binary form must reproduce the above
39 /* mlx4_en_read_clock - read raw cycle counter (to be used by time counter)
45 struct mlx4_dev *dev = mdev->dev; in mlx4_en_read_clock()
47 return mlx4_read_clock(dev) & tc->mask; in mlx4_en_read_clock()
55 lo = (u64)be16_to_cpu(ts_cqe->timestamp_lo); in mlx4_en_get_cqe_ts()
56 hi = ((u64)be32_to_cpu(ts_cqe->timestamp_hi) + !lo) << 16; in mlx4_en_get_cqe_ts()
67 seq = read_seqbegin(&mdev->clock_lock); in mlx4_en_get_hwtstamp()
68 nsec = timecounter_cyc2time(&mdev->clock, timestamp); in mlx4_en_get_hwtstamp()
69 } while (read_seqretry(&mdev->clock_lock, seq)); in mlx4_en_get_hwtstamp()
79 hwts->hwtstamp = mlx4_en_get_hwtstamp(mdev, timestamp); in mlx4_en_fill_hwtstamps()
83 * mlx4_en_remove_timestamp - disable PTP device
86 * Stop the PTP support.
90 if (mdev->ptp_clock) { in mlx4_en_remove_timestamp()
91 ptp_clock_unregister(mdev->ptp_clock); in mlx4_en_remove_timestamp()
92 mdev->ptp_clock = NULL; in mlx4_en_remove_timestamp()
100 * TODO: Use a timer instead of a work queue to increase the guarantee.
106 bool timeout = time_is_before_jiffies(mdev->last_overflow_check + in mlx4_en_ptp_overflow_check()
111 write_seqlock_irqsave(&mdev->clock_lock, flags); in mlx4_en_ptp_overflow_check()
112 timecounter_read(&mdev->clock); in mlx4_en_ptp_overflow_check()
113 write_sequnlock_irqrestore(&mdev->clock_lock, flags); in mlx4_en_ptp_overflow_check()
114 mdev->last_overflow_check = jiffies; in mlx4_en_ptp_overflow_check()
119 * mlx4_en_phc_adjfine - adjust the frequency of the hardware clock
120 * @ptp: ptp clock structure
126 * Scaled parts per million is ppm with a 16-bit binary fractional field.
128 static int mlx4_en_phc_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) in mlx4_en_phc_adjfine() argument
132 struct mlx4_en_dev *mdev = container_of(ptp, struct mlx4_en_dev, in mlx4_en_phc_adjfine()
135 mult = (u32)adjust_by_scaled_ppm(mdev->nominal_c_mult, scaled_ppm); in mlx4_en_phc_adjfine()
137 write_seqlock_irqsave(&mdev->clock_lock, flags); in mlx4_en_phc_adjfine()
138 timecounter_read(&mdev->clock); in mlx4_en_phc_adjfine()
139 mdev->cycles.mult = mult; in mlx4_en_phc_adjfine()
140 write_sequnlock_irqrestore(&mdev->clock_lock, flags); in mlx4_en_phc_adjfine()
146 * mlx4_en_phc_adjtime - Shift the time of the hardware clock
147 * @ptp: ptp clock structure
150 * Adjust the timer by resetting the timecounter structure.
152 static int mlx4_en_phc_adjtime(struct ptp_clock_info *ptp, s64 delta) in mlx4_en_phc_adjtime() argument
154 struct mlx4_en_dev *mdev = container_of(ptp, struct mlx4_en_dev, in mlx4_en_phc_adjtime()
158 write_seqlock_irqsave(&mdev->clock_lock, flags); in mlx4_en_phc_adjtime()
159 timecounter_adjtime(&mdev->clock, delta); in mlx4_en_phc_adjtime()
160 write_sequnlock_irqrestore(&mdev->clock_lock, flags); in mlx4_en_phc_adjtime()
166 * mlx4_en_phc_gettime - Reads the current time from the hardware clock
167 * @ptp: ptp clock structure
173 static int mlx4_en_phc_gettime(struct ptp_clock_info *ptp, in mlx4_en_phc_gettime() argument
176 struct mlx4_en_dev *mdev = container_of(ptp, struct mlx4_en_dev, in mlx4_en_phc_gettime()
181 write_seqlock_irqsave(&mdev->clock_lock, flags); in mlx4_en_phc_gettime()
182 ns = timecounter_read(&mdev->clock); in mlx4_en_phc_gettime()
183 write_sequnlock_irqrestore(&mdev->clock_lock, flags); in mlx4_en_phc_gettime()
191 * mlx4_en_phc_settime - Set the current time on the hardware clock
192 * @ptp: ptp clock structure
196 * wall timer value.
198 static int mlx4_en_phc_settime(struct ptp_clock_info *ptp, in mlx4_en_phc_settime() argument
201 struct mlx4_en_dev *mdev = container_of(ptp, struct mlx4_en_dev, in mlx4_en_phc_settime()
207 write_seqlock_irqsave(&mdev->clock_lock, flags); in mlx4_en_phc_settime()
208 timecounter_init(&mdev->clock, &mdev->cycles, ns); in mlx4_en_phc_settime()
209 write_sequnlock_irqrestore(&mdev->clock_lock, flags); in mlx4_en_phc_settime()
215 * mlx4_en_phc_enable - enable or disable an ancillary feature
216 * @ptp: ptp clock structure
223 static int mlx4_en_phc_enable(struct ptp_clock_info __always_unused *ptp, in mlx4_en_phc_enable() argument
227 return -EOPNOTSUPP; in mlx4_en_phc_enable()
253 u64 max_val_cycles_rounded = 1ULL << fls64(max_val_cycles - 1); in freq_to_shift()
263 struct mlx4_dev *dev = mdev->dev; in mlx4_en_init_timestamp()
267 * mdev->ptp_clock is common for all ports, skip initialization if in mlx4_en_init_timestamp()
270 if (mdev->ptp_clock) in mlx4_en_init_timestamp()
273 seqlock_init(&mdev->clock_lock); in mlx4_en_init_timestamp()
275 memset(&mdev->cycles, 0, sizeof(mdev->cycles)); in mlx4_en_init_timestamp()
276 mdev->cycles.read = mlx4_en_read_clock; in mlx4_en_init_timestamp()
277 mdev->cycles.mask = CLOCKSOURCE_MASK(48); in mlx4_en_init_timestamp()
278 mdev->cycles.shift = freq_to_shift(dev->caps.hca_core_clock); in mlx4_en_init_timestamp()
279 mdev->cycles.mult = in mlx4_en_init_timestamp()
280 clocksource_khz2mult(1000 * dev->caps.hca_core_clock, mdev->cycles.shift); in mlx4_en_init_timestamp()
281 mdev->nominal_c_mult = mdev->cycles.mult; in mlx4_en_init_timestamp()
283 write_seqlock_irqsave(&mdev->clock_lock, flags); in mlx4_en_init_timestamp()
284 timecounter_init(&mdev->clock, &mdev->cycles, in mlx4_en_init_timestamp()
286 write_sequnlock_irqrestore(&mdev->clock_lock, flags); in mlx4_en_init_timestamp()
289 mdev->ptp_clock_info = mlx4_en_ptp_clock_info; in mlx4_en_init_timestamp()
290 snprintf(mdev->ptp_clock_info.name, 16, "mlx4 ptp"); in mlx4_en_init_timestamp()
292 mdev->ptp_clock = ptp_clock_register(&mdev->ptp_clock_info, in mlx4_en_init_timestamp()
293 &mdev->pdev->dev); in mlx4_en_init_timestamp()
294 if (IS_ERR(mdev->ptp_clock)) { in mlx4_en_init_timestamp()
295 mdev->ptp_clock = NULL; in mlx4_en_init_timestamp()
297 } else if (mdev->ptp_clock) { in mlx4_en_init_timestamp()