Lines Matching refs:ptp

66 #define is_rev_A0(ptp) (((ptp)->pdev->revision & 0x0F) == 0x0)  argument
67 #define is_rev_A1(ptp) (((ptp)->pdev->revision & 0x0F) == 0x1) argument
76 static struct ptp *first_ptp_block;
79 static bool is_ptp_dev_cnf10ka(struct ptp *ptp) in is_ptp_dev_cnf10ka() argument
81 return ptp->pdev->subsystem_device == PCI_SUBSYS_DEVID_CNF10K_A_PTP; in is_ptp_dev_cnf10ka()
84 static bool is_ptp_dev_cn10ka(struct ptp *ptp) in is_ptp_dev_cn10ka() argument
86 return ptp->pdev->subsystem_device == PCI_SUBSYS_DEVID_CN10K_A_PTP; in is_ptp_dev_cn10ka()
89 static bool cn10k_ptp_errata(struct ptp *ptp) in cn10k_ptp_errata() argument
91 if ((is_ptp_dev_cn10ka(ptp) || is_ptp_dev_cnf10ka(ptp)) && in cn10k_ptp_errata()
92 (is_rev_A0(ptp) || is_rev_A1(ptp))) in cn10k_ptp_errata()
100 struct ptp *ptp = rvu->ptp; in is_tstmp_atomic_update_supported() local
108 if ((is_ptp_dev_cn10ka(ptp) || is_ptp_dev_cnf10ka(ptp)) && in is_tstmp_atomic_update_supported()
109 (is_rev_A0(ptp) || is_rev_A1(ptp))) in is_tstmp_atomic_update_supported()
117 struct ptp *ptp = container_of(hrtimer, struct ptp, hrtimer); in ptp_reset_thresh() local
123 delta_ns = ktime_to_ns(ktime_sub(curr_ts, ptp->last_ts)); in ptp_reset_thresh()
129 ptp_clock_hi = readq(ptp->reg_base + PTP_CLOCK_HI); in ptp_reset_thresh()
133 writeq(500000000, ptp->reg_base + PTP_PPS_THRESH_HI); in ptp_reset_thresh()
138 ptp->last_ts = curr_ts; in ptp_reset_thresh()
143 static void ptp_hrtimer_start(struct ptp *ptp, ktime_t start_ns) in ptp_hrtimer_start() argument
148 hrtimer_start(&ptp->hrtimer, period_ns, HRTIMER_MODE_REL); in ptp_hrtimer_start()
149 ptp->last_ts = ktime_get(); in ptp_hrtimer_start()
152 static u64 read_ptp_tstmp_sec_nsec(struct ptp *ptp) in read_ptp_tstmp_sec_nsec() argument
157 spin_lock_irqsave(&ptp->ptp_lock, flags); in read_ptp_tstmp_sec_nsec()
158 sec = readq(ptp->reg_base + PTP_CLOCK_SEC) & 0xFFFFFFFFUL; in read_ptp_tstmp_sec_nsec()
159 nsec = readq(ptp->reg_base + PTP_CLOCK_HI); in read_ptp_tstmp_sec_nsec()
160 sec1 = readq(ptp->reg_base + PTP_CLOCK_SEC) & 0xFFFFFFFFUL; in read_ptp_tstmp_sec_nsec()
163 nsec = readq(ptp->reg_base + PTP_CLOCK_HI); in read_ptp_tstmp_sec_nsec()
166 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in read_ptp_tstmp_sec_nsec()
171 static u64 read_ptp_tstmp_nsec(struct ptp *ptp) in read_ptp_tstmp_nsec() argument
173 return readq(ptp->reg_base + PTP_CLOCK_HI); in read_ptp_tstmp_nsec()
228 struct ptp *ptp_get(void) in ptp_get()
230 struct ptp *ptp = first_ptp_block; in ptp_get() local
236 if (!ptp) in ptp_get()
237 ptp = ERR_PTR(-EPROBE_DEFER); in ptp_get()
238 else if (!IS_ERR(ptp)) in ptp_get()
239 pci_dev_get(ptp->pdev); in ptp_get()
241 return ptp; in ptp_get()
244 void ptp_put(struct ptp *ptp) in ptp_put() argument
246 if (!ptp) in ptp_put()
249 pci_dev_put(ptp->pdev); in ptp_put()
252 static void ptp_atomic_update(struct ptp *ptp, u64 timestamp) in ptp_atomic_update() argument
257 writeq(timestamp, ptp->reg_base + PTP_NANO_TIMESTAMP); in ptp_atomic_update()
258 writeq(0, ptp->reg_base + PTP_FRNS_TIMESTAMP); in ptp_atomic_update()
260 ptp->reg_base + PTP_SEC_TIMESTAMP); in ptp_atomic_update()
264 writeq(nxt_rollover_set, ptp->reg_base + PTP_NXT_ROLLOVER_SET); in ptp_atomic_update()
265 writeq(curr_rollover_set, ptp->reg_base + PTP_CURR_ROLLOVER_SET); in ptp_atomic_update()
268 regval = readq(ptp->reg_base + PTP_CLOCK_CFG); in ptp_atomic_update()
271 writeq(regval, ptp->reg_base + PTP_CLOCK_CFG); in ptp_atomic_update()
274 static void ptp_atomic_adjtime(struct ptp *ptp, s64 delta) in ptp_atomic_adjtime() argument
289 ptp_clock_hi = readq(ptp->reg_base + PTP_CLOCK_HI); in ptp_atomic_adjtime()
298 ptp_atomic_update(ptp, ptp_clock_hi); in ptp_atomic_adjtime()
300 writeq(delta, ptp->reg_base + PTP_NANO_TIMESTAMP); in ptp_atomic_adjtime()
301 writeq(0, ptp->reg_base + PTP_FRNS_TIMESTAMP); in ptp_atomic_adjtime()
304 regval = readq(ptp->reg_base + PTP_CLOCK_CFG); in ptp_atomic_adjtime()
307 writeq(regval, ptp->reg_base + PTP_CLOCK_CFG); in ptp_atomic_adjtime()
311 static int ptp_adjfine(struct ptp *ptp, long scaled_ppm) in ptp_adjfine() argument
342 if (cn10k_ptp_errata(ptp)) { in ptp_adjfine()
344 freq_adj = (ptp->clock_rate * ppb) / 1000000000ULL; in ptp_adjfine()
345 freq = neg_adj ? ptp->clock_rate + freq_adj : ptp->clock_rate - freq_adj; in ptp_adjfine()
348 comp = ((u64)1000000000ull << 32) / ptp->clock_rate; in ptp_adjfine()
353 writeq(comp, ptp->reg_base + PTP_CLOCK_COMP); in ptp_adjfine()
358 static int ptp_get_clock(struct ptp *ptp, u64 *clk) in ptp_get_clock() argument
361 *clk = ptp->read_ptp_tstmp(ptp); in ptp_get_clock()
368 struct ptp *ptp = rvu->ptp; in ptp_start() local
373 if (!ptp) in ptp_start()
376 pdev = ptp->pdev; in ptp_start()
384 ptp->clock_rate = sclk * 1000000; in ptp_start()
388 writeq(0, ptp->reg_base + PTP_NANO_TIMESTAMP); in ptp_start()
389 writeq(0, ptp->reg_base + PTP_FRNS_TIMESTAMP); in ptp_start()
390 writeq(0, ptp->reg_base + PTP_SEC_TIMESTAMP); in ptp_start()
391 writeq(0, ptp->reg_base + PTP_CURR_ROLLOVER_SET); in ptp_start()
392 writeq(0x3b9aca00, ptp->reg_base + PTP_NXT_ROLLOVER_SET); in ptp_start()
393 writeq(0x3b9aca00, ptp->reg_base + PTP_SEC_ROLLOVER); in ptp_start()
397 clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG); in ptp_start()
400 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 writeq(0x1dcd650000000000, ptp->reg_base + PTP_PPS_HI_INCR); in ptp_start()
423 writeq(0x1dcd650000000000, ptp->reg_base + PTP_PPS_LO_INCR); in ptp_start()
424 if (cn10k_ptp_errata(ptp)) { in ptp_start()
432 ptp->clock_period = NSEC_PER_SEC / ptp->clock_rate; in ptp_start()
433 writeq((0x1dcd6500ULL - ptp->clock_period) << 32, in ptp_start()
434 ptp->reg_base + PTP_PPS_LO_INCR); in ptp_start()
437 if (cn10k_ptp_errata(ptp)) in ptp_start()
438 clock_comp = ptp_calc_adjusted_comp(ptp->clock_rate); in ptp_start()
440 clock_comp = ((u64)1000000000ull << 32) / ptp->clock_rate; in ptp_start()
443 writeq(clock_comp, ptp->reg_base + PTP_CLOCK_COMP); in ptp_start()
446 static int ptp_get_tstmp(struct ptp *ptp, u64 *clk) in ptp_get_tstmp() argument
450 if (is_ptp_dev_cn10ka(ptp) || is_ptp_dev_cnf10ka(ptp)) { in ptp_get_tstmp()
451 timestamp = readq(ptp->reg_base + PTP_TIMESTAMP); in ptp_get_tstmp()
454 *clk = readq(ptp->reg_base + PTP_TIMESTAMP); in ptp_get_tstmp()
460 static int ptp_set_thresh(struct ptp *ptp, u64 thresh) in ptp_set_thresh() argument
462 if (!cn10k_ptp_errata(ptp)) in ptp_set_thresh()
463 writeq(thresh, ptp->reg_base + PTP_PPS_THRESH_HI); in ptp_set_thresh()
468 static int ptp_extts_on(struct ptp *ptp, int on) in ptp_extts_on() argument
472 if (cn10k_ptp_errata(ptp)) { in ptp_extts_on()
474 ptp_clock_hi = readq(ptp->reg_base + PTP_CLOCK_HI); in ptp_extts_on()
475 ptp_hrtimer_start(ptp, (ktime_t)ptp_clock_hi); in ptp_extts_on()
477 if (hrtimer_active(&ptp->hrtimer)) in ptp_extts_on()
478 hrtimer_cancel(&ptp->hrtimer); in ptp_extts_on()
488 struct ptp *ptp; in ptp_probe() local
491 ptp = kzalloc(sizeof(*ptp), GFP_KERNEL); in ptp_probe()
492 if (!ptp) { in ptp_probe()
497 ptp->pdev = pdev; in ptp_probe()
507 ptp->reg_base = pcim_iomap_table(pdev)[PCI_PTP_BAR_NO]; in ptp_probe()
509 pci_set_drvdata(pdev, ptp); in ptp_probe()
511 first_ptp_block = ptp; in ptp_probe()
513 spin_lock_init(&ptp->ptp_lock); in ptp_probe()
514 if (cn10k_ptp_errata(ptp)) { in ptp_probe()
515 ptp->read_ptp_tstmp = &read_ptp_tstmp_sec_nsec; in ptp_probe()
516 hrtimer_init(&ptp->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in ptp_probe()
517 ptp->hrtimer.function = ptp_reset_thresh; in ptp_probe()
519 ptp->read_ptp_tstmp = &read_ptp_tstmp_nsec; in ptp_probe()
525 kfree(ptp); in ptp_probe()
542 struct ptp *ptp = pci_get_drvdata(pdev); in ptp_remove() local
545 if (IS_ERR_OR_NULL(ptp)) in ptp_remove()
548 if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer)) in ptp_remove()
549 hrtimer_cancel(&ptp->hrtimer); in ptp_remove()
552 clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG); in ptp_remove()
554 writeq(clock_cfg, ptp->reg_base + PTP_CLOCK_CFG); in ptp_remove()
555 kfree(ptp); in ptp_remove()
600 if (!rvu->ptp) in rvu_mbox_handler_ptp_op()
605 err = ptp_adjfine(rvu->ptp, req->scaled_ppm); in rvu_mbox_handler_ptp_op()
608 err = ptp_get_clock(rvu->ptp, &rsp->clk); in rvu_mbox_handler_ptp_op()
611 err = ptp_get_tstmp(rvu->ptp, &rsp->clk); in rvu_mbox_handler_ptp_op()
614 err = ptp_set_thresh(rvu->ptp, req->thresh); in rvu_mbox_handler_ptp_op()
617 err = ptp_extts_on(rvu->ptp, req->extts_on); in rvu_mbox_handler_ptp_op()
620 ptp_atomic_adjtime(rvu->ptp, req->delta); in rvu_mbox_handler_ptp_op()
623 ptp_atomic_update(rvu->ptp, (u64)req->clk); in rvu_mbox_handler_ptp_op()
636 if (!rvu->ptp) in rvu_mbox_handler_ptp_get_cap()