Lines Matching refs:ptp
59 static struct ptp *first_ptp_block;
62 static bool is_ptp_dev_cnf10kb(struct ptp *ptp) in is_ptp_dev_cnf10kb() argument
64 return (ptp->pdev->subsystem_device == PCI_SUBSYS_DEVID_CNF10K_B_PTP) ? true : false; in is_ptp_dev_cnf10kb()
67 static bool is_ptp_dev_cn10k(struct ptp *ptp) in is_ptp_dev_cn10k() argument
69 return (ptp->pdev->device == PCI_DEVID_CN10K_PTP) ? true : false; in is_ptp_dev_cn10k()
72 static bool cn10k_ptp_errata(struct ptp *ptp) in cn10k_ptp_errata() argument
74 if (ptp->pdev->subsystem_device == PCI_SUBSYS_DEVID_CN10K_A_PTP || in cn10k_ptp_errata()
75 ptp->pdev->subsystem_device == PCI_SUBSYS_DEVID_CNF10K_A_PTP) in cn10k_ptp_errata()
80 static bool is_ptp_tsfmt_sec_nsec(struct ptp *ptp) in is_ptp_tsfmt_sec_nsec() argument
82 if (ptp->pdev->subsystem_device == PCI_SUBSYS_DEVID_CN10K_A_PTP || in is_ptp_tsfmt_sec_nsec()
83 ptp->pdev->subsystem_device == PCI_SUBSYS_DEVID_CNF10K_A_PTP) in is_ptp_tsfmt_sec_nsec()
90 struct ptp *ptp = container_of(hrtimer, struct ptp, hrtimer); in ptp_reset_thresh() local
96 delta_ns = ktime_to_ns(ktime_sub(curr_ts, ptp->last_ts)); in ptp_reset_thresh()
102 ptp_clock_hi = readq(ptp->reg_base + PTP_CLOCK_HI); in ptp_reset_thresh()
106 writeq(500000000, ptp->reg_base + PTP_PPS_THRESH_HI); in ptp_reset_thresh()
111 ptp->last_ts = curr_ts; in ptp_reset_thresh()
116 static void ptp_hrtimer_start(struct ptp *ptp, ktime_t start_ns) in ptp_hrtimer_start() argument
121 hrtimer_start(&ptp->hrtimer, period_ns, HRTIMER_MODE_REL); in ptp_hrtimer_start()
122 ptp->last_ts = ktime_get(); in ptp_hrtimer_start()
125 static u64 read_ptp_tstmp_sec_nsec(struct ptp *ptp) in read_ptp_tstmp_sec_nsec() argument
130 spin_lock_irqsave(&ptp->ptp_lock, flags); in read_ptp_tstmp_sec_nsec()
131 sec = readq(ptp->reg_base + PTP_CLOCK_SEC) & 0xFFFFFFFFUL; in read_ptp_tstmp_sec_nsec()
132 nsec = readq(ptp->reg_base + PTP_CLOCK_HI); in read_ptp_tstmp_sec_nsec()
133 sec1 = readq(ptp->reg_base + PTP_CLOCK_SEC) & 0xFFFFFFFFUL; in read_ptp_tstmp_sec_nsec()
136 nsec = readq(ptp->reg_base + PTP_CLOCK_HI); in read_ptp_tstmp_sec_nsec()
139 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in read_ptp_tstmp_sec_nsec()
144 static u64 read_ptp_tstmp_nsec(struct ptp *ptp) in read_ptp_tstmp_nsec() argument
146 return readq(ptp->reg_base + PTP_CLOCK_HI); in read_ptp_tstmp_nsec()
201 struct ptp *ptp_get(void) in ptp_get()
203 struct ptp *ptp = first_ptp_block; in ptp_get() local
209 if (!ptp) in ptp_get()
210 ptp = ERR_PTR(-EPROBE_DEFER); in ptp_get()
212 pci_dev_get(ptp->pdev); in ptp_get()
214 return ptp; in ptp_get()
217 void ptp_put(struct ptp *ptp) in ptp_put() argument
219 if (!ptp) in ptp_put()
222 pci_dev_put(ptp->pdev); in ptp_put()
225 static int ptp_adjfine(struct ptp *ptp, long scaled_ppm) in ptp_adjfine() argument
256 if (cn10k_ptp_errata(ptp)) { in ptp_adjfine()
258 freq_adj = (ptp->clock_rate * ppb) / 1000000000ULL; in ptp_adjfine()
259 freq = neg_adj ? ptp->clock_rate + freq_adj : ptp->clock_rate - freq_adj; in ptp_adjfine()
262 comp = ((u64)1000000000ull << 32) / ptp->clock_rate; in ptp_adjfine()
267 writeq(comp, ptp->reg_base + PTP_CLOCK_COMP); in ptp_adjfine()
272 static int ptp_get_clock(struct ptp *ptp, u64 *clk) in ptp_get_clock() argument
275 *clk = ptp->read_ptp_tstmp(ptp); in ptp_get_clock()
280 void ptp_start(struct ptp *ptp, u64 sclk, u32 ext_clk_freq, u32 extts) in ptp_start() argument
286 if (!ptp) in ptp_start()
289 pdev = ptp->pdev; in ptp_start()
297 ptp->clock_rate = sclk * 1000000; in ptp_start()
300 if (is_ptp_dev_cnf10kb(ptp)) in ptp_start()
301 writeq(0x3b9aca00, ptp->reg_base + PTP_SEC_ROLLOVER); in ptp_start()
304 clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG); in ptp_start()
307 ptp->clock_rate = ext_clk_freq; in ptp_start()
322 writeq(clock_cfg, ptp->reg_base + PTP_CLOCK_CFG); in ptp_start()
325 writeq(0x1dcd650000000000, ptp->reg_base + PTP_PPS_HI_INCR); in ptp_start()
326 writeq(0x1dcd650000000000, ptp->reg_base + PTP_PPS_LO_INCR); in ptp_start()
327 if (cn10k_ptp_errata(ptp)) { in ptp_start()
335 ptp->clock_period = NSEC_PER_SEC / ptp->clock_rate; in ptp_start()
336 writeq((0x1dcd6500ULL - ptp->clock_period) << 32, in ptp_start()
337 ptp->reg_base + PTP_PPS_LO_INCR); in ptp_start()
340 if (cn10k_ptp_errata(ptp)) in ptp_start()
341 clock_comp = ptp_calc_adjusted_comp(ptp->clock_rate); in ptp_start()
343 clock_comp = ((u64)1000000000ull << 32) / ptp->clock_rate; in ptp_start()
346 writeq(clock_comp, ptp->reg_base + PTP_CLOCK_COMP); in ptp_start()
349 static int ptp_get_tstmp(struct ptp *ptp, u64 *clk) in ptp_get_tstmp() argument
353 if (is_ptp_dev_cn10k(ptp)) { in ptp_get_tstmp()
354 timestamp = readq(ptp->reg_base + PTP_TIMESTAMP); in ptp_get_tstmp()
357 *clk = readq(ptp->reg_base + PTP_TIMESTAMP); in ptp_get_tstmp()
363 static int ptp_set_thresh(struct ptp *ptp, u64 thresh) in ptp_set_thresh() argument
365 if (!cn10k_ptp_errata(ptp)) in ptp_set_thresh()
366 writeq(thresh, ptp->reg_base + PTP_PPS_THRESH_HI); in ptp_set_thresh()
371 static int ptp_extts_on(struct ptp *ptp, int on) in ptp_extts_on() argument
375 if (cn10k_ptp_errata(ptp)) { in ptp_extts_on()
377 ptp_clock_hi = readq(ptp->reg_base + PTP_CLOCK_HI); in ptp_extts_on()
378 ptp_hrtimer_start(ptp, (ktime_t)ptp_clock_hi); in ptp_extts_on()
380 if (hrtimer_active(&ptp->hrtimer)) in ptp_extts_on()
381 hrtimer_cancel(&ptp->hrtimer); in ptp_extts_on()
392 struct ptp *ptp; in ptp_probe() local
395 ptp = devm_kzalloc(dev, sizeof(*ptp), GFP_KERNEL); in ptp_probe()
396 if (!ptp) { in ptp_probe()
401 ptp->pdev = pdev; in ptp_probe()
411 ptp->reg_base = pcim_iomap_table(pdev)[PCI_PTP_BAR_NO]; in ptp_probe()
413 pci_set_drvdata(pdev, ptp); in ptp_probe()
415 first_ptp_block = ptp; in ptp_probe()
417 spin_lock_init(&ptp->ptp_lock); in ptp_probe()
418 if (is_ptp_tsfmt_sec_nsec(ptp)) in ptp_probe()
419 ptp->read_ptp_tstmp = &read_ptp_tstmp_sec_nsec; in ptp_probe()
421 ptp->read_ptp_tstmp = &read_ptp_tstmp_nsec; in ptp_probe()
423 if (cn10k_ptp_errata(ptp)) { in ptp_probe()
424 hrtimer_init(&ptp->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in ptp_probe()
425 ptp->hrtimer.function = ptp_reset_thresh; in ptp_probe()
431 devm_kfree(dev, ptp); in ptp_probe()
449 struct ptp *ptp = pci_get_drvdata(pdev); in ptp_remove() local
452 if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer)) in ptp_remove()
453 hrtimer_cancel(&ptp->hrtimer); in ptp_remove()
455 if (IS_ERR_OR_NULL(ptp)) in ptp_remove()
459 clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG); in ptp_remove()
461 writeq(clock_cfg, ptp->reg_base + PTP_CLOCK_CFG); in ptp_remove()
506 if (!rvu->ptp) in rvu_mbox_handler_ptp_op()
511 err = ptp_adjfine(rvu->ptp, req->scaled_ppm); in rvu_mbox_handler_ptp_op()
514 err = ptp_get_clock(rvu->ptp, &rsp->clk); in rvu_mbox_handler_ptp_op()
517 err = ptp_get_tstmp(rvu->ptp, &rsp->clk); in rvu_mbox_handler_ptp_op()
520 err = ptp_set_thresh(rvu->ptp, req->thresh); in rvu_mbox_handler_ptp_op()
523 err = ptp_extts_on(rvu->ptp, req->extts_on); in rvu_mbox_handler_ptp_op()