Lines Matching +full:comp +full:- +full:disable
1 // SPDX-License-Identifier: GPL-2.0
67 #define is_rev_A0(ptp) (((ptp)->pdev->revision & 0x0F) == 0x0)
68 #define is_rev_A1(ptp) (((ptp)->pdev->revision & 0x0F) == 0x1)
82 return ptp->pdev->subsystem_device == PCI_SUBSYS_DEVID_CNF10K_A_PTP; in is_ptp_dev_cnf10ka()
87 return ptp->pdev->subsystem_device == PCI_SUBSYS_DEVID_CN10K_A_PTP; in is_ptp_dev_cn10ka()
101 struct ptp *ptp = rvu->ptp; in is_tstmp_atomic_update_supported()
124 delta_ns = ktime_to_ns(ktime_sub(curr_ts, ptp->last_ts)); in ptp_reset_thresh()
130 ptp_clock_hi = readq(ptp->reg_base + PTP_CLOCK_HI); in ptp_reset_thresh()
132 period_ns = ktime_set(0, (NSEC_PER_SEC + 100 - ptp_clock_hi)); in ptp_reset_thresh()
134 writeq(500000000, ptp->reg_base + PTP_PPS_THRESH_HI); in ptp_reset_thresh()
135 period_ns = ktime_set(0, (NSEC_PER_SEC + 100 - delta_ns)); in ptp_reset_thresh()
139 ptp->last_ts = curr_ts; in ptp_reset_thresh()
148 period_ns = ktime_set(0, (NSEC_PER_SEC + 100 - start_ns)); in ptp_hrtimer_start()
149 hrtimer_start(&ptp->hrtimer, period_ns, HRTIMER_MODE_REL); in ptp_hrtimer_start()
150 ptp->last_ts = ktime_get(); in ptp_hrtimer_start()
158 spin_lock_irqsave(&ptp->ptp_lock, flags); in read_ptp_tstmp_sec_nsec()
159 sec = readq(ptp->reg_base + PTP_CLOCK_SEC) & 0xFFFFFFFFUL; in read_ptp_tstmp_sec_nsec()
160 nsec = readq(ptp->reg_base + PTP_CLOCK_HI); in read_ptp_tstmp_sec_nsec()
161 sec1 = readq(ptp->reg_base + PTP_CLOCK_SEC) & 0xFFFFFFFFUL; in read_ptp_tstmp_sec_nsec()
164 nsec = readq(ptp->reg_base + PTP_CLOCK_HI); in read_ptp_tstmp_sec_nsec()
167 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in read_ptp_tstmp_sec_nsec()
174 return readq(ptp->reg_base + PTP_CLOCK_HI); in read_ptp_tstmp_nsec()
179 u64 comp, adj = 0, cycles_per_sec, ns_drift = 0; in ptp_calc_adjusted_comp() local
184 * Issue #1: At the time of 1 sec rollover of the nano-second counter, in ptp_calc_adjusted_comp()
185 * the nano-second counter is set to 0. However, it should be set to in ptp_calc_adjusted_comp()
186 * (existing counter_value - 10^9). in ptp_calc_adjusted_comp()
188 * Issue #2: The nano-second counter rolls over at 0x3B9A_C9FF. in ptp_calc_adjusted_comp()
193 comp = ((u64)1000000000ULL << 32) / ptp_clock_freq; in ptp_calc_adjusted_comp()
200 cycle = cycles_per_sec - 1; in ptp_calc_adjusted_comp()
201 ptp_clock_nsec = (cycle * comp) >> 32; in ptp_calc_adjusted_comp()
206 ptp_clock_nsec = (cycle * comp) >> 32; in ptp_calc_adjusted_comp()
209 ns_drift = ptp_clock_nsec - NSEC_PER_SEC; in ptp_calc_adjusted_comp()
212 adj = comp * ns_drift; in ptp_calc_adjusted_comp()
216 comp += adj; in ptp_calc_adjusted_comp()
217 return comp; in ptp_calc_adjusted_comp()
221 adj = comp * cycle_time; in ptp_calc_adjusted_comp()
224 comp -= adj; in ptp_calc_adjusted_comp()
226 return comp; in ptp_calc_adjusted_comp()
235 return ERR_PTR(-ENODEV); in ptp_get()
238 ptp = ERR_PTR(-EPROBE_DEFER); in ptp_get()
240 pci_dev_get(ptp->pdev); in ptp_get()
250 pci_dev_put(ptp->pdev); in ptp_put()
258 writeq(timestamp, ptp->reg_base + PTP_NANO_TIMESTAMP); in ptp_atomic_update()
259 writeq(0, ptp->reg_base + PTP_FRNS_TIMESTAMP); in ptp_atomic_update()
261 ptp->reg_base + PTP_SEC_TIMESTAMP); in ptp_atomic_update()
264 curr_rollover_set = nxt_rollover_set - NSEC_PER_SEC; in ptp_atomic_update()
265 writeq(nxt_rollover_set, ptp->reg_base + PTP_NXT_ROLLOVER_SET); in ptp_atomic_update()
266 writeq(curr_rollover_set, ptp->reg_base + PTP_CURR_ROLLOVER_SET); in ptp_atomic_update()
269 regval = readq(ptp->reg_base + PTP_CLOCK_CFG); in ptp_atomic_update()
272 writeq(regval, ptp->reg_base + PTP_CLOCK_CFG); in ptp_atomic_update()
281 delta = -delta; in ptp_atomic_adjtime()
290 ptp_clock_hi = readq(ptp->reg_base + PTP_CLOCK_HI); in ptp_atomic_adjtime()
293 ptp_clock_hi -= delta; in ptp_atomic_adjtime()
295 ptp_clock_hi = delta - ptp_clock_hi; in ptp_atomic_adjtime()
301 writeq(delta, ptp->reg_base + PTP_NANO_TIMESTAMP); in ptp_atomic_adjtime()
302 writeq(0, ptp->reg_base + PTP_FRNS_TIMESTAMP); in ptp_atomic_adjtime()
305 regval = readq(ptp->reg_base + PTP_CLOCK_CFG); in ptp_atomic_adjtime()
308 writeq(regval, ptp->reg_base + PTP_CLOCK_CFG); in ptp_atomic_adjtime()
316 u64 comp, adj; in ptp_adjfine() local
321 scaled_ppm = -scaled_ppm; in ptp_adjfine()
327 * convention compensation value is in 64 bit fixed-point in ptp_adjfine()
334 * comp = tbase + tbase * scaled_ppm / (1M * 2^16) in ptp_adjfine()
345 freq_adj = (ptp->clock_rate * ppb) / 1000000000ULL; in ptp_adjfine()
346 freq = neg_adj ? ptp->clock_rate + freq_adj : ptp->clock_rate - freq_adj; in ptp_adjfine()
347 comp = ptp_calc_adjusted_comp(freq); in ptp_adjfine()
349 comp = ((u64)1000000000ull << 32) / ptp->clock_rate; in ptp_adjfine()
350 adj = comp * ppb; in ptp_adjfine()
352 comp = neg_adj ? comp - adj : comp + adj; in ptp_adjfine()
354 writeq(comp, ptp->reg_base + PTP_CLOCK_COMP); in ptp_adjfine()
362 *clk = ptp->read_ptp_tstmp(ptp); in ptp_get_clock()
369 struct ptp *ptp = rvu->ptp; in ptp_start()
377 pdev = ptp->pdev; in ptp_start()
380 dev_err(&pdev->dev, "PTP input clock cannot be zero\n"); in ptp_start()
385 ptp->clock_rate = sclk * 1000000; in ptp_start()
389 writeq(0, ptp->reg_base + PTP_NANO_TIMESTAMP); in ptp_start()
390 writeq(0, ptp->reg_base + PTP_FRNS_TIMESTAMP); in ptp_start()
391 writeq(0, ptp->reg_base + PTP_SEC_TIMESTAMP); in ptp_start()
392 writeq(0, ptp->reg_base + PTP_CURR_ROLLOVER_SET); in ptp_start()
393 writeq(0x3b9aca00, ptp->reg_base + PTP_NXT_ROLLOVER_SET); in ptp_start()
394 writeq(0x3b9aca00, ptp->reg_base + PTP_SEC_ROLLOVER); in ptp_start()
398 clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG); in ptp_start()
401 ptp->clock_rate = ext_clk_freq; in ptp_start()
415 writeq(clock_cfg, ptp->reg_base + PTP_CLOCK_CFG); in ptp_start()
416 clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG); in ptp_start()
419 writeq(clock_cfg, ptp->reg_base + PTP_CLOCK_CFG); in ptp_start()
422 clock_comp = ptp_calc_adjusted_comp(ptp->clock_rate); in ptp_start()
424 clock_comp = ((u64)1000000000ull << 32) / ptp->clock_rate; in ptp_start()
427 writeq(clock_comp, ptp->reg_base + PTP_CLOCK_COMP); in ptp_start()
435 timestamp = readq(ptp->reg_base + PTP_TIMESTAMP); in ptp_get_tstmp()
438 *clk = readq(ptp->reg_base + PTP_TIMESTAMP); in ptp_get_tstmp()
447 writeq(thresh, ptp->reg_base + PTP_PPS_THRESH_HI); in ptp_set_thresh()
457 ptp_clock_hi = readq(ptp->reg_base + PTP_CLOCK_HI); in ptp_config_hrtimer()
460 if (hrtimer_active(&ptp->hrtimer)) in ptp_config_hrtimer()
461 hrtimer_cancel(&ptp->hrtimer); in ptp_config_hrtimer()
471 clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG); in ptp_pps_on()
474 dev_err(&ptp->pdev->dev, "Supports max period value as 1 second\n"); in ptp_pps_on()
475 return -EINVAL; in ptp_pps_on()
479 dev_err(&ptp->pdev->dev, "Supports max period as 8 seconds\n"); in ptp_pps_on()
480 return -EINVAL; in ptp_pps_on()
484 writeq(clock_cfg, ptp->reg_base + PTP_CLOCK_CFG); in ptp_pps_on()
486 writeq(0, ptp->reg_base + PTP_PPS_THRESH_HI); in ptp_pps_on()
487 writeq(0, ptp->reg_base + PTP_PPS_THRESH_LO); in ptp_pps_on()
491 writeq(((u64)period << 32), ptp->reg_base + PTP_PPS_HI_INCR); in ptp_pps_on()
492 writeq(((u64)period << 32), ptp->reg_base + PTP_PPS_LO_INCR); in ptp_pps_on()
495 writeq(clock_cfg, ptp->reg_base + PTP_CLOCK_CFG); in ptp_pps_on()
506 ptp->clock_period = NSEC_PER_SEC / ptp->clock_rate; in ptp_pps_on()
507 writeq((0x1dcd6500ULL - ptp->clock_period) << 32, in ptp_pps_on()
508 ptp->reg_base + PTP_PPS_LO_INCR); in ptp_pps_on()
525 err = -ENOMEM; in ptp_probe()
529 ptp->pdev = pdev; in ptp_probe()
539 ptp->reg_base = pcim_iomap_table(pdev)[PCI_PTP_BAR_NO]; in ptp_probe()
545 spin_lock_init(&ptp->ptp_lock); in ptp_probe()
547 ptp->read_ptp_tstmp = &read_ptp_tstmp_sec_nsec; in ptp_probe()
548 hrtimer_init(&ptp->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in ptp_probe()
549 ptp->hrtimer.function = ptp_reset_thresh; in ptp_probe()
551 ptp->read_ptp_tstmp = &read_ptp_tstmp_nsec; in ptp_probe()
563 * `dev->driver_data`. in ptp_probe()
580 if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer)) in ptp_remove()
581 hrtimer_cancel(&ptp->hrtimer); in ptp_remove()
583 /* Disable PTP clock */ in ptp_remove()
584 clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG); in ptp_remove()
586 writeq(clock_cfg, ptp->reg_base + PTP_CLOCK_CFG); in ptp_remove()
632 if (!rvu->ptp) in rvu_mbox_handler_ptp_op()
633 return -ENODEV; in rvu_mbox_handler_ptp_op()
635 switch (req->op) { in rvu_mbox_handler_ptp_op()
637 err = ptp_adjfine(rvu->ptp, req->scaled_ppm); in rvu_mbox_handler_ptp_op()
640 err = ptp_get_clock(rvu->ptp, &rsp->clk); in rvu_mbox_handler_ptp_op()
643 err = ptp_get_tstmp(rvu->ptp, &rsp->clk); in rvu_mbox_handler_ptp_op()
646 err = ptp_set_thresh(rvu->ptp, req->thresh); in rvu_mbox_handler_ptp_op()
649 err = ptp_pps_on(rvu->ptp, req->pps_on, req->period); in rvu_mbox_handler_ptp_op()
652 ptp_atomic_adjtime(rvu->ptp, req->delta); in rvu_mbox_handler_ptp_op()
655 ptp_atomic_update(rvu->ptp, (u64)req->clk); in rvu_mbox_handler_ptp_op()
658 err = -EINVAL; in rvu_mbox_handler_ptp_op()
668 if (!rvu->ptp) in rvu_mbox_handler_ptp_get_cap()
669 return -ENODEV; in rvu_mbox_handler_ptp_get_cap()
672 rsp->cap |= PTP_CAP_HW_ATOMIC_UPDATE; in rvu_mbox_handler_ptp_get_cap()
674 rsp->cap &= ~BIT_ULL_MASK(0); in rvu_mbox_handler_ptp_get_cap()