Lines Matching full:ptp
62 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_settime() local
67 if (BNXT_PTP_USE_RTC(ptp->bp)) in bnxt_ptp_settime()
68 return bnxt_ptp_cfg_settime(ptp->bp, ns); in bnxt_ptp_settime()
70 spin_lock_irqsave(&ptp->ptp_lock, flags); in bnxt_ptp_settime()
71 timecounter_init(&ptp->tc, &ptp->cc, ns); in bnxt_ptp_settime()
72 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_ptp_settime()
80 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_refclk_read() local
86 high_before = readl(bp->bar0 + ptp->refclk_mapped_regs[1]); in bnxt_refclk_read()
88 low = readl(bp->bar0 + ptp->refclk_mapped_regs[0]); in bnxt_refclk_read()
90 high_now = readl(bp->bar0 + ptp->refclk_mapped_regs[1]); in bnxt_refclk_read()
93 low = readl(bp->bar0 + ptp->refclk_mapped_regs[0]); in bnxt_refclk_read()
103 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_get_current_time() local
106 if (!ptp) in bnxt_ptp_get_current_time()
108 spin_lock_irqsave(&ptp->ptp_lock, flags); in bnxt_ptp_get_current_time()
109 WRITE_ONCE(ptp->old_time, ptp->current_time); in bnxt_ptp_get_current_time()
110 bnxt_refclk_read(bp, NULL, &ptp->current_time); in bnxt_ptp_get_current_time()
111 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_ptp_get_current_time()
152 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_gettimex() local
158 spin_lock_irqsave(&ptp->ptp_lock, flags); in bnxt_ptp_gettimex()
159 rc = bnxt_refclk_read(ptp->bp, sts, &cycles); in bnxt_ptp_gettimex()
161 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_ptp_gettimex()
164 ns = timecounter_cyc2time(&ptp->tc, cycles); in bnxt_ptp_gettimex()
165 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_ptp_gettimex()
174 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_update_current_time() local
176 bnxt_refclk_read(ptp->bp, NULL, &ptp->current_time); in bnxt_ptp_update_current_time()
177 WRITE_ONCE(ptp->old_time, ptp->current_time); in bnxt_ptp_update_current_time()
180 static int bnxt_ptp_adjphc(struct bnxt_ptp_cfg *ptp, s64 delta) in bnxt_ptp_adjphc() argument
186 rc = hwrm_req_init(ptp->bp, req, HWRM_PORT_MAC_CFG); in bnxt_ptp_adjphc()
193 rc = hwrm_req_send(ptp->bp, req); in bnxt_ptp_adjphc()
195 netdev_err(ptp->bp->dev, "ptp adjphc failed. rc = %x\n", rc); in bnxt_ptp_adjphc()
197 spin_lock_irqsave(&ptp->ptp_lock, flags); in bnxt_ptp_adjphc()
198 bnxt_ptp_update_current_time(ptp->bp); in bnxt_ptp_adjphc()
199 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_ptp_adjphc()
207 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_adjtime() local
211 if (BNXT_PTP_USE_RTC(ptp->bp)) in bnxt_ptp_adjtime()
212 return bnxt_ptp_adjphc(ptp, delta); in bnxt_ptp_adjtime()
214 spin_lock_irqsave(&ptp->ptp_lock, flags); in bnxt_ptp_adjtime()
215 timecounter_adjtime(&ptp->tc, delta); in bnxt_ptp_adjtime()
216 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_ptp_adjtime()
235 "ptp adjfine failed. rc = %d\n", rc); in bnxt_ptp_adjfine_rtc()
241 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_adjfine() local
243 struct bnxt *bp = ptp->bp; in bnxt_ptp_adjfine()
249 spin_lock_irqsave(&ptp->ptp_lock, flags); in bnxt_ptp_adjfine()
250 timecounter_read(&ptp->tc); in bnxt_ptp_adjfine()
251 ptp->cc.mult = adjust_by_scaled_ppm(ptp->cmult, scaled_ppm); in bnxt_ptp_adjfine()
252 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_ptp_adjfine()
258 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_pps_event() local
264 spin_lock_irqsave(&ptp->ptp_lock, flags); in bnxt_ptp_pps_event()
265 ns = timecounter_cyc2time(&ptp->tc, pps_ts); in bnxt_ptp_pps_event()
266 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_ptp_pps_event()
287 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_cfg_pin() local
294 netdev_err(ptp->bp->dev, "1PPS: Invalid pin. Check pin-function configuration\n"); in bnxt_ptp_cfg_pin()
298 rc = hwrm_req_init(ptp->bp, req, HWRM_FUNC_PTP_PIN_CFG); in bnxt_ptp_cfg_pin()
312 rc = hwrm_req_send(ptp->bp, req); in bnxt_ptp_cfg_pin()
316 ptp->pps_info.pins[pin].usage = usage; in bnxt_ptp_cfg_pin()
317 ptp->pps_info.pins[pin].state = state; in bnxt_ptp_cfg_pin()
338 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_cfg_tstamp_filters() local
342 if (!ptp || !ptp->tstamp_filters) in bnxt_ptp_cfg_tstamp_filters()
349 if (!(bp->fw_cap & BNXT_FW_CAP_RX_ALL_PKT_TS) && (ptp->tstamp_filters & in bnxt_ptp_cfg_tstamp_filters()
352 ptp->tstamp_filters &= ~(PORT_MAC_CFG_REQ_FLAGS_ALL_RX_TS_CAPTURE_ENABLE | in bnxt_ptp_cfg_tstamp_filters()
357 req->flags = cpu_to_le32(ptp->tstamp_filters); in bnxt_ptp_cfg_tstamp_filters()
359 req->rx_ts_capture_ptp_msg_type = cpu_to_le16(ptp->rxctl); in bnxt_ptp_cfg_tstamp_filters()
363 bp->ptp_all_rx_tstamp = !!(ptp->tstamp_filters & in bnxt_ptp_cfg_tstamp_filters()
367 ptp->tstamp_filters = 0; in bnxt_ptp_cfg_tstamp_filters()
376 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_reapply_pps() local
381 if (!ptp || !(bp->fw_cap & BNXT_FW_CAP_PTP_PPS) || in bnxt_ptp_reapply_pps()
382 !(ptp->ptp_info.pin_config)) in bnxt_ptp_reapply_pps()
384 pps = &ptp->pps_info; in bnxt_ptp_reapply_pps()
398 static int bnxt_get_target_cycles(struct bnxt_ptp_cfg *ptp, u64 target_ns, in bnxt_get_target_cycles() argument
406 spin_lock_irqsave(&ptp->ptp_lock, flags); in bnxt_get_target_cycles()
407 rc = bnxt_refclk_read(ptp->bp, NULL, &cycles_now); in bnxt_get_target_cycles()
409 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_get_target_cycles()
412 nsec_now = timecounter_cyc2time(&ptp->tc, cycles_now); in bnxt_get_target_cycles()
413 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_get_target_cycles()
416 *cycles_delta = div64_u64(nsec_delta << ptp->cc.shift, ptp->cc.mult); in bnxt_get_target_cycles()
420 static int bnxt_ptp_perout_cfg(struct bnxt_ptp_cfg *ptp, in bnxt_ptp_perout_cfg() argument
424 struct bnxt *bp = ptp->bp; in bnxt_ptp_perout_cfg()
434 rc = bnxt_get_target_cycles(ptp, target_ns, &delta); in bnxt_ptp_perout_cfg()
459 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_enable() local
461 struct bnxt *bp = ptp->bp; in bnxt_ptp_enable()
468 pin_id = ptp_find_pin(ptp->ptp_clock, PTP_PF_EXTTS, in bnxt_ptp_enable()
479 ptp->pps_info.pins[pin_id].event = BNXT_PPS_EVENT_EXTERNAL; in bnxt_ptp_enable()
483 pin_id = ptp_find_pin(ptp->ptp_clock, PTP_PF_PEROUT, in bnxt_ptp_enable()
492 rc = bnxt_ptp_perout_cfg(ptp, rq); in bnxt_ptp_enable()
502 ptp->pps_info.pins[0].event = BNXT_PPS_EVENT_INTERNAL; in bnxt_ptp_enable()
505 netdev_err(ptp->bp->dev, "Unrecognized PIN function\n"); in bnxt_ptp_enable()
514 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_hwrm_ptp_cfg() local
517 switch (ptp->rx_filter) { in bnxt_hwrm_ptp_cfg()
533 if (ptp->tx_tstamp_en) in bnxt_hwrm_ptp_cfg()
538 ptp->tstamp_filters = flags; in bnxt_hwrm_ptp_cfg()
547 struct bnxt_ptp_cfg *ptp; in bnxt_hwtstamp_set() local
552 ptp = bp->ptp_cfg; in bnxt_hwtstamp_set()
553 if (!ptp) in bnxt_hwtstamp_set()
563 old_rx_filter = ptp->rx_filter; in bnxt_hwtstamp_set()
564 old_rxctl = ptp->rxctl; in bnxt_hwtstamp_set()
565 old_tx_tstamp_en = ptp->tx_tstamp_en; in bnxt_hwtstamp_set()
568 ptp->rxctl = 0; in bnxt_hwtstamp_set()
569 ptp->rx_filter = HWTSTAMP_FILTER_NONE; in bnxt_hwtstamp_set()
573 ptp->rx_filter = HWTSTAMP_FILTER_ALL; in bnxt_hwtstamp_set()
580 ptp->rxctl = BNXT_PTP_MSG_EVENTS; in bnxt_hwtstamp_set()
581 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; in bnxt_hwtstamp_set()
586 ptp->rxctl = BNXT_PTP_MSG_SYNC; in bnxt_hwtstamp_set()
587 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_SYNC; in bnxt_hwtstamp_set()
592 ptp->rxctl = BNXT_PTP_MSG_DELAY_REQ; in bnxt_hwtstamp_set()
593 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_DELAY_REQ; in bnxt_hwtstamp_set()
600 ptp->tx_tstamp_en = 1; in bnxt_hwtstamp_set()
602 ptp->tx_tstamp_en = 0; in bnxt_hwtstamp_set()
608 stmpconf.rx_filter = ptp->rx_filter; in bnxt_hwtstamp_set()
613 ptp->rx_filter = old_rx_filter; in bnxt_hwtstamp_set()
614 ptp->rxctl = old_rxctl; in bnxt_hwtstamp_set()
615 ptp->tx_tstamp_en = old_tx_tstamp_en; in bnxt_hwtstamp_set()
623 struct bnxt_ptp_cfg *ptp; in bnxt_hwtstamp_get() local
625 ptp = bp->ptp_cfg; in bnxt_hwtstamp_get()
626 if (!ptp) in bnxt_hwtstamp_get()
630 stmpconf.tx_type = ptp->tx_tstamp_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF; in bnxt_hwtstamp_get()
632 stmpconf.rx_filter = ptp->rx_filter; in bnxt_hwtstamp_get()
654 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_map_ptp_regs() local
658 reg_arr = ptp->refclk_regs; in bnxt_map_ptp_regs()
664 ptp->refclk_mapped_regs[i] = BNXT_PTP_GRC_WIN_BASE + in bnxt_map_ptp_regs()
665 (ptp->refclk_regs[i] & BNXT_GRC_OFFSET_MASK); in bnxt_map_ptp_regs()
672 ptp->refclk_mapped_regs[i] = reg_arr[i]; in bnxt_map_ptp_regs()
687 struct bnxt_ptp_cfg *ptp = container_of(cc, struct bnxt_ptp_cfg, cc); in bnxt_cc_read() local
690 bnxt_refclk_read(ptp->bp, NULL, &ns); in bnxt_cc_read()
696 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_stamp_tx_skb() local
705 txts_req = &ptp->txts_req[slot]; in bnxt_stamp_tx_skb()
714 spin_lock_irqsave(&ptp->ptp_lock, flags); in bnxt_stamp_tx_skb()
715 ns = timecounter_cyc2time(&ptp->tc, ts); in bnxt_stamp_tx_skb()
716 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_stamp_tx_skb()
719 ptp->stats.ts_pkts++; in bnxt_stamp_tx_skb()
724 ptp->stats.ts_lost++; in bnxt_stamp_tx_skb()
737 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_ts_aux_work() local
740 struct bnxt *bp = ptp->bp; in bnxt_ptp_ts_aux_work()
741 u16 cons = ptp->txts_cons; in bnxt_ptp_ts_aux_work()
746 num_requests = BNXT_MAX_TX_TS - READ_ONCE(ptp->tx_avail); in bnxt_ptp_ts_aux_work()
748 if (IS_ERR(ptp->txts_req[cons].tx_skb)) in bnxt_ptp_ts_aux_work()
750 if (!ptp->txts_req[cons].tx_skb) in bnxt_ptp_ts_aux_work()
756 BNXT_PTP_INC_TX_AVAIL(ptp); in bnxt_ptp_ts_aux_work()
759 ptp->txts_cons = cons; in bnxt_ptp_ts_aux_work()
761 if (!time_after_eq(now, ptp->next_period)) { in bnxt_ptp_ts_aux_work()
764 return ptp->next_period - now; in bnxt_ptp_ts_aux_work()
768 ptp->next_period = now + HZ; in bnxt_ptp_ts_aux_work()
769 if (time_after_eq(now, ptp->next_overflow_check)) { in bnxt_ptp_ts_aux_work()
770 spin_lock_irqsave(&ptp->ptp_lock, flags); in bnxt_ptp_ts_aux_work()
771 timecounter_read(&ptp->tc); in bnxt_ptp_ts_aux_work()
772 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_ptp_ts_aux_work()
773 ptp->next_overflow_check = now + BNXT_PHC_OVERFLOW_PERIOD; in bnxt_ptp_ts_aux_work()
780 int bnxt_ptp_get_txts_prod(struct bnxt_ptp_cfg *ptp, u16 *prod) in bnxt_ptp_get_txts_prod() argument
782 spin_lock_bh(&ptp->ptp_tx_lock); in bnxt_ptp_get_txts_prod()
783 if (ptp->tx_avail) { in bnxt_ptp_get_txts_prod()
784 *prod = ptp->txts_prod; in bnxt_ptp_get_txts_prod()
785 ptp->txts_prod = NEXT_TXTS(*prod); in bnxt_ptp_get_txts_prod()
786 ptp->tx_avail--; in bnxt_ptp_get_txts_prod()
787 spin_unlock_bh(&ptp->ptp_tx_lock); in bnxt_ptp_get_txts_prod()
790 spin_unlock_bh(&ptp->ptp_tx_lock); in bnxt_ptp_get_txts_prod()
791 atomic64_inc(&ptp->stats.ts_err); in bnxt_ptp_get_txts_prod()
797 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_get_tx_ts_p5() local
800 txts_req = &ptp->txts_req[prod]; in bnxt_get_tx_ts_p5()
801 txts_req->abs_txts_tmo = jiffies + msecs_to_jiffies(ptp->txts_tmo); in bnxt_get_tx_ts_p5()
805 ptp_schedule_worker(ptp->ptp_clock, 0); in bnxt_get_tx_ts_p5()
810 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_get_rx_ts_p5() local
813 if (!ptp) in bnxt_get_rx_ts_p5()
816 BNXT_READ_TIME64(ptp, time, ptp->old_time); in bnxt_get_rx_ts_p5()
828 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_tx_ts_cmp() local
847 spin_lock_irqsave(&ptp->ptp_lock, flags); in bnxt_tx_ts_cmp()
848 ns = timecounter_cyc2time(&ptp->tc, ts); in bnxt_tx_ts_cmp()
849 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_tx_ts_cmp()
877 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_verify() local
880 if (ptp->pps_info.pins[pin].usage <= BNXT_PPS_PIN_PPS_OUT && in bnxt_ptp_verify()
891 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_pps_init() local
909 ptp_info = &ptp->ptp_info; in bnxt_ptp_pps_init()
910 pps_info = &ptp->pps_info; in bnxt_ptp_pps_init()
950 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_pps_config_ok() local
952 return !(bp->fw_cap & BNXT_FW_CAP_PTP_PPS) == !ptp->ptp_info.pin_config; in bnxt_pps_config_ok()
957 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_timecounter_init() local
959 if (!ptp->ptp_clock) { in bnxt_ptp_timecounter_init()
960 memset(&ptp->cc, 0, sizeof(ptp->cc)); in bnxt_ptp_timecounter_init()
961 ptp->cc.read = bnxt_cc_read; in bnxt_ptp_timecounter_init()
962 ptp->cc.mask = CYCLECOUNTER_MASK(48); in bnxt_ptp_timecounter_init()
965 ptp->cc.shift = BNXT_CYCLES_SHIFT; in bnxt_ptp_timecounter_init()
966 ptp->cc.mult = clocksource_khz2mult(BNXT_DEVCLK_FREQ, ptp->cc.shift); in bnxt_ptp_timecounter_init()
967 ptp->cmult = ptp->cc.mult; in bnxt_ptp_timecounter_init()
969 ptp->cc.shift = 0; in bnxt_ptp_timecounter_init()
970 ptp->cc.mult = 1; in bnxt_ptp_timecounter_init()
972 ptp->next_overflow_check = jiffies + BNXT_PHC_OVERFLOW_PERIOD; in bnxt_ptp_timecounter_init()
975 timecounter_init(&ptp->tc, &ptp->cc, ktime_to_ns(ktime_get_real())); in bnxt_ptp_timecounter_init()
979 void bnxt_ptp_rtc_timecounter_init(struct bnxt_ptp_cfg *ptp, u64 ns) in bnxt_ptp_rtc_timecounter_init() argument
981 timecounter_init(&ptp->tc, &ptp->cc, ns); in bnxt_ptp_rtc_timecounter_init()
983 ptp->tc.cycle_last = ns & ptp->cc.mask; in bnxt_ptp_rtc_timecounter_init()
1017 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_free() local
1019 if (ptp->ptp_clock) { in bnxt_ptp_free()
1020 ptp_clock_unregister(ptp->ptp_clock); in bnxt_ptp_free()
1021 ptp->ptp_clock = NULL; in bnxt_ptp_free()
1022 kfree(ptp->ptp_info.pin_config); in bnxt_ptp_free()
1023 ptp->ptp_info.pin_config = NULL; in bnxt_ptp_free()
1029 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_init() local
1032 if (!ptp) in bnxt_ptp_init()
1039 if (ptp->ptp_clock && bnxt_pps_config_ok(bp)) in bnxt_ptp_init()
1044 WRITE_ONCE(ptp->tx_avail, BNXT_MAX_TX_TS); in bnxt_ptp_init()
1045 spin_lock_init(&ptp->ptp_lock); in bnxt_ptp_init()
1046 spin_lock_init(&ptp->ptp_tx_lock); in bnxt_ptp_init()
1059 ptp->ptp_info = bnxt_ptp_caps; in bnxt_ptp_init()
1064 ptp->ptp_clock = ptp_clock_register(&ptp->ptp_info, &bp->pdev->dev); in bnxt_ptp_init()
1065 if (IS_ERR(ptp->ptp_clock)) { in bnxt_ptp_init()
1066 int err = PTR_ERR(ptp->ptp_clock); in bnxt_ptp_init()
1068 ptp->ptp_clock = NULL; in bnxt_ptp_init()
1073 ptp->stats.ts_pkts = 0; in bnxt_ptp_init()
1074 ptp->stats.ts_lost = 0; in bnxt_ptp_init()
1075 atomic64_set(&ptp->stats.ts_err, 0); in bnxt_ptp_init()
1080 spin_lock_irqsave(&ptp->ptp_lock, flags); in bnxt_ptp_init()
1081 bnxt_refclk_read(bp, NULL, &ptp->current_time); in bnxt_ptp_init()
1082 WRITE_ONCE(ptp->old_time, ptp->current_time); in bnxt_ptp_init()
1083 spin_unlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_ptp_init()
1084 ptp_schedule_worker(ptp->ptp_clock, 0); in bnxt_ptp_init()
1086 ptp->txts_tmo = BNXT_PTP_DFLT_TX_TMO; in bnxt_ptp_init()
1097 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_clear() local
1100 if (!ptp) in bnxt_ptp_clear()
1103 if (ptp->ptp_clock) in bnxt_ptp_clear()
1104 ptp_clock_unregister(ptp->ptp_clock); in bnxt_ptp_clear()
1106 ptp->ptp_clock = NULL; in bnxt_ptp_clear()
1107 kfree(ptp->ptp_info.pin_config); in bnxt_ptp_clear()
1108 ptp->ptp_info.pin_config = NULL; in bnxt_ptp_clear()
1111 if (ptp->txts_req[i].tx_skb) { in bnxt_ptp_clear()
1112 dev_kfree_skb_any(ptp->txts_req[i].tx_skb); in bnxt_ptp_clear()
1113 ptp->txts_req[i].tx_skb = NULL; in bnxt_ptp_clear()