Lines Matching refs:ptp
62 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_settime() local
66 if (BNXT_PTP_USE_RTC(ptp->bp)) in bnxt_ptp_settime()
67 return bnxt_ptp_cfg_settime(ptp->bp, ns); in bnxt_ptp_settime()
69 spin_lock_bh(&ptp->ptp_lock); in bnxt_ptp_settime()
70 timecounter_init(&ptp->tc, &ptp->cc, ns); in bnxt_ptp_settime()
71 spin_unlock_bh(&ptp->ptp_lock); in bnxt_ptp_settime()
79 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_refclk_read() local
85 high_before = readl(bp->bar0 + ptp->refclk_mapped_regs[1]); in bnxt_refclk_read()
87 low = readl(bp->bar0 + ptp->refclk_mapped_regs[0]); in bnxt_refclk_read()
89 high_now = readl(bp->bar0 + ptp->refclk_mapped_regs[1]); in bnxt_refclk_read()
92 low = readl(bp->bar0 + ptp->refclk_mapped_regs[0]); in bnxt_refclk_read()
102 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_get_current_time() local
104 if (!ptp) in bnxt_ptp_get_current_time()
106 spin_lock_bh(&ptp->ptp_lock); in bnxt_ptp_get_current_time()
107 WRITE_ONCE(ptp->old_time, ptp->current_time); in bnxt_ptp_get_current_time()
108 bnxt_refclk_read(bp, NULL, &ptp->current_time); in bnxt_ptp_get_current_time()
109 spin_unlock_bh(&ptp->ptp_lock); in bnxt_ptp_get_current_time()
143 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_gettimex() local
148 spin_lock_bh(&ptp->ptp_lock); in bnxt_ptp_gettimex()
149 rc = bnxt_refclk_read(ptp->bp, sts, &cycles); in bnxt_ptp_gettimex()
151 spin_unlock_bh(&ptp->ptp_lock); in bnxt_ptp_gettimex()
154 ns = timecounter_cyc2time(&ptp->tc, cycles); in bnxt_ptp_gettimex()
155 spin_unlock_bh(&ptp->ptp_lock); in bnxt_ptp_gettimex()
164 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_update_current_time() local
166 bnxt_refclk_read(ptp->bp, NULL, &ptp->current_time); in bnxt_ptp_update_current_time()
167 WRITE_ONCE(ptp->old_time, ptp->current_time); in bnxt_ptp_update_current_time()
170 static int bnxt_ptp_adjphc(struct bnxt_ptp_cfg *ptp, s64 delta) in bnxt_ptp_adjphc() argument
175 rc = hwrm_req_init(ptp->bp, req, HWRM_PORT_MAC_CFG); in bnxt_ptp_adjphc()
182 rc = hwrm_req_send(ptp->bp, req); in bnxt_ptp_adjphc()
184 netdev_err(ptp->bp->dev, "ptp adjphc failed. rc = %x\n", rc); in bnxt_ptp_adjphc()
186 spin_lock_bh(&ptp->ptp_lock); in bnxt_ptp_adjphc()
187 bnxt_ptp_update_current_time(ptp->bp); in bnxt_ptp_adjphc()
188 spin_unlock_bh(&ptp->ptp_lock); in bnxt_ptp_adjphc()
196 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_adjtime() local
199 if (BNXT_PTP_USE_RTC(ptp->bp)) in bnxt_ptp_adjtime()
200 return bnxt_ptp_adjphc(ptp, delta); in bnxt_ptp_adjtime()
202 spin_lock_bh(&ptp->ptp_lock); in bnxt_ptp_adjtime()
203 timecounter_adjtime(&ptp->tc, delta); in bnxt_ptp_adjtime()
204 spin_unlock_bh(&ptp->ptp_lock); in bnxt_ptp_adjtime()
229 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_adjfine() local
231 struct bnxt *bp = ptp->bp; in bnxt_ptp_adjfine()
236 spin_lock_bh(&ptp->ptp_lock); in bnxt_ptp_adjfine()
237 timecounter_read(&ptp->tc); in bnxt_ptp_adjfine()
238 ptp->cc.mult = adjust_by_scaled_ppm(ptp->cmult, scaled_ppm); in bnxt_ptp_adjfine()
239 spin_unlock_bh(&ptp->ptp_lock); in bnxt_ptp_adjfine()
245 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_pps_event() local
250 spin_lock_bh(&ptp->ptp_lock); in bnxt_ptp_pps_event()
251 ns = timecounter_cyc2time(&ptp->tc, pps_ts); in bnxt_ptp_pps_event()
252 spin_unlock_bh(&ptp->ptp_lock); in bnxt_ptp_pps_event()
273 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_cfg_pin() local
280 netdev_err(ptp->bp->dev, "1PPS: Invalid pin. Check pin-function configuration\n"); in bnxt_ptp_cfg_pin()
284 rc = hwrm_req_init(ptp->bp, req, HWRM_FUNC_PTP_PIN_CFG); in bnxt_ptp_cfg_pin()
298 rc = hwrm_req_send(ptp->bp, req); in bnxt_ptp_cfg_pin()
302 ptp->pps_info.pins[pin].usage = usage; in bnxt_ptp_cfg_pin()
303 ptp->pps_info.pins[pin].state = state; in bnxt_ptp_cfg_pin()
324 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_cfg_tstamp_filters() local
327 if (!ptp || !ptp->tstamp_filters) in bnxt_ptp_cfg_tstamp_filters()
333 if (!(bp->fw_cap & BNXT_FW_CAP_RX_ALL_PKT_TS) && (ptp->tstamp_filters & in bnxt_ptp_cfg_tstamp_filters()
336 ptp->tstamp_filters &= ~(PORT_MAC_CFG_REQ_FLAGS_ALL_RX_TS_CAPTURE_ENABLE | in bnxt_ptp_cfg_tstamp_filters()
341 req->flags = cpu_to_le32(ptp->tstamp_filters); in bnxt_ptp_cfg_tstamp_filters()
343 req->rx_ts_capture_ptp_msg_type = cpu_to_le16(ptp->rxctl); in bnxt_ptp_cfg_tstamp_filters()
346 bp->ptp_all_rx_tstamp = !!(ptp->tstamp_filters & in bnxt_ptp_cfg_tstamp_filters()
350 ptp->tstamp_filters = 0; in bnxt_ptp_cfg_tstamp_filters()
358 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_reapply_pps() local
363 if (!ptp || !(bp->fw_cap & BNXT_FW_CAP_PTP_PPS) || in bnxt_ptp_reapply_pps()
364 !(ptp->ptp_info.pin_config)) in bnxt_ptp_reapply_pps()
366 pps = &ptp->pps_info; in bnxt_ptp_reapply_pps()
380 static int bnxt_get_target_cycles(struct bnxt_ptp_cfg *ptp, u64 target_ns, in bnxt_get_target_cycles() argument
387 spin_lock_bh(&ptp->ptp_lock); in bnxt_get_target_cycles()
388 rc = bnxt_refclk_read(ptp->bp, NULL, &cycles_now); in bnxt_get_target_cycles()
390 spin_unlock_bh(&ptp->ptp_lock); in bnxt_get_target_cycles()
393 nsec_now = timecounter_cyc2time(&ptp->tc, cycles_now); in bnxt_get_target_cycles()
394 spin_unlock_bh(&ptp->ptp_lock); in bnxt_get_target_cycles()
397 *cycles_delta = div64_u64(nsec_delta << ptp->cc.shift, ptp->cc.mult); in bnxt_get_target_cycles()
401 static int bnxt_ptp_perout_cfg(struct bnxt_ptp_cfg *ptp, in bnxt_ptp_perout_cfg() argument
405 struct bnxt *bp = ptp->bp; in bnxt_ptp_perout_cfg()
415 rc = bnxt_get_target_cycles(ptp, target_ns, &delta); in bnxt_ptp_perout_cfg()
440 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_enable() local
442 struct bnxt *bp = ptp->bp; in bnxt_ptp_enable()
449 pin_id = ptp_find_pin(ptp->ptp_clock, PTP_PF_EXTTS, in bnxt_ptp_enable()
460 ptp->pps_info.pins[pin_id].event = BNXT_PPS_EVENT_EXTERNAL; in bnxt_ptp_enable()
464 pin_id = ptp_find_pin(ptp->ptp_clock, PTP_PF_PEROUT, in bnxt_ptp_enable()
473 rc = bnxt_ptp_perout_cfg(ptp, rq); in bnxt_ptp_enable()
483 ptp->pps_info.pins[0].event = BNXT_PPS_EVENT_INTERNAL; in bnxt_ptp_enable()
486 netdev_err(ptp->bp->dev, "Unrecognized PIN function\n"); in bnxt_ptp_enable()
495 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_hwrm_ptp_cfg() local
499 switch (ptp->rx_filter) { in bnxt_hwrm_ptp_cfg()
515 if (ptp->tx_tstamp_en) in bnxt_hwrm_ptp_cfg()
520 ptp->tstamp_filters = flags; in bnxt_hwrm_ptp_cfg()
523 if (ptp->rx_filter == HWTSTAMP_FILTER_ALL) { in bnxt_hwrm_ptp_cfg()
529 if (!rc && !ptp->tstamp_filters) in bnxt_hwrm_ptp_cfg()
540 struct bnxt_ptp_cfg *ptp; in bnxt_hwtstamp_set() local
545 ptp = bp->ptp_cfg; in bnxt_hwtstamp_set()
546 if (!ptp) in bnxt_hwtstamp_set()
556 old_rx_filter = ptp->rx_filter; in bnxt_hwtstamp_set()
557 old_rxctl = ptp->rxctl; in bnxt_hwtstamp_set()
558 old_tx_tstamp_en = ptp->tx_tstamp_en; in bnxt_hwtstamp_set()
561 ptp->rxctl = 0; in bnxt_hwtstamp_set()
562 ptp->rx_filter = HWTSTAMP_FILTER_NONE; in bnxt_hwtstamp_set()
566 ptp->rx_filter = HWTSTAMP_FILTER_ALL; in bnxt_hwtstamp_set()
573 ptp->rxctl = BNXT_PTP_MSG_EVENTS; in bnxt_hwtstamp_set()
574 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; in bnxt_hwtstamp_set()
579 ptp->rxctl = BNXT_PTP_MSG_SYNC; in bnxt_hwtstamp_set()
580 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_SYNC; in bnxt_hwtstamp_set()
585 ptp->rxctl = BNXT_PTP_MSG_DELAY_REQ; in bnxt_hwtstamp_set()
586 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_DELAY_REQ; in bnxt_hwtstamp_set()
593 ptp->tx_tstamp_en = 1; in bnxt_hwtstamp_set()
595 ptp->tx_tstamp_en = 0; in bnxt_hwtstamp_set()
601 stmpconf.rx_filter = ptp->rx_filter; in bnxt_hwtstamp_set()
606 ptp->rx_filter = old_rx_filter; in bnxt_hwtstamp_set()
607 ptp->rxctl = old_rxctl; in bnxt_hwtstamp_set()
608 ptp->tx_tstamp_en = old_tx_tstamp_en; in bnxt_hwtstamp_set()
616 struct bnxt_ptp_cfg *ptp; in bnxt_hwtstamp_get() local
618 ptp = bp->ptp_cfg; in bnxt_hwtstamp_get()
619 if (!ptp) in bnxt_hwtstamp_get()
623 stmpconf.tx_type = ptp->tx_tstamp_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF; in bnxt_hwtstamp_get()
625 stmpconf.rx_filter = ptp->rx_filter; in bnxt_hwtstamp_get()
647 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_map_ptp_regs() local
651 reg_arr = ptp->refclk_regs; in bnxt_map_ptp_regs()
657 ptp->refclk_mapped_regs[i] = BNXT_PTP_GRC_WIN_BASE + in bnxt_map_ptp_regs()
658 (ptp->refclk_regs[i] & BNXT_GRC_OFFSET_MASK); in bnxt_map_ptp_regs()
672 struct bnxt_ptp_cfg *ptp = container_of(cc, struct bnxt_ptp_cfg, cc); in bnxt_cc_read() local
675 bnxt_refclk_read(ptp->bp, NULL, &ns); in bnxt_cc_read()
681 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_stamp_tx_skb() local
689 spin_lock_bh(&ptp->ptp_lock); in bnxt_stamp_tx_skb()
690 ns = timecounter_cyc2time(&ptp->tc, ts); in bnxt_stamp_tx_skb()
691 spin_unlock_bh(&ptp->ptp_lock); in bnxt_stamp_tx_skb()
693 skb_tstamp_tx(ptp->tx_skb, ×tamp); in bnxt_stamp_tx_skb()
699 dev_kfree_skb_any(ptp->tx_skb); in bnxt_stamp_tx_skb()
700 ptp->tx_skb = NULL; in bnxt_stamp_tx_skb()
701 atomic_inc(&ptp->tx_avail); in bnxt_stamp_tx_skb()
706 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_ts_aux_work() local
709 struct bnxt *bp = ptp->bp; in bnxt_ptp_ts_aux_work()
711 if (ptp->tx_skb) in bnxt_ptp_ts_aux_work()
712 bnxt_stamp_tx_skb(bp, ptp->tx_skb); in bnxt_ptp_ts_aux_work()
714 if (!time_after_eq(now, ptp->next_period)) in bnxt_ptp_ts_aux_work()
715 return ptp->next_period - now; in bnxt_ptp_ts_aux_work()
718 ptp->next_period = now + HZ; in bnxt_ptp_ts_aux_work()
719 if (time_after_eq(now, ptp->next_overflow_check)) { in bnxt_ptp_ts_aux_work()
720 spin_lock_bh(&ptp->ptp_lock); in bnxt_ptp_ts_aux_work()
721 timecounter_read(&ptp->tc); in bnxt_ptp_ts_aux_work()
722 spin_unlock_bh(&ptp->ptp_lock); in bnxt_ptp_ts_aux_work()
723 ptp->next_overflow_check = now + BNXT_PHC_OVERFLOW_PERIOD; in bnxt_ptp_ts_aux_work()
730 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_get_tx_ts_p5() local
732 if (ptp->tx_skb) { in bnxt_get_tx_ts_p5()
736 ptp->tx_skb = skb; in bnxt_get_tx_ts_p5()
737 ptp_schedule_worker(ptp->ptp_clock, 0); in bnxt_get_tx_ts_p5()
743 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_get_rx_ts_p5() local
746 if (!ptp) in bnxt_get_rx_ts_p5()
749 BNXT_READ_TIME64(ptp, time, ptp->old_time); in bnxt_get_rx_ts_p5()
777 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_verify() local
780 if (ptp->pps_info.pins[pin].usage <= BNXT_PPS_PIN_PPS_OUT && in bnxt_ptp_verify()
791 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_pps_init() local
809 ptp_info = &ptp->ptp_info; in bnxt_ptp_pps_init()
810 pps_info = &ptp->pps_info; in bnxt_ptp_pps_init()
850 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_pps_config_ok() local
852 return !(bp->fw_cap & BNXT_FW_CAP_PTP_PPS) == !ptp->ptp_info.pin_config; in bnxt_pps_config_ok()
857 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_timecounter_init() local
859 if (!ptp->ptp_clock) { in bnxt_ptp_timecounter_init()
860 memset(&ptp->cc, 0, sizeof(ptp->cc)); in bnxt_ptp_timecounter_init()
861 ptp->cc.read = bnxt_cc_read; in bnxt_ptp_timecounter_init()
862 ptp->cc.mask = CYCLECOUNTER_MASK(48); in bnxt_ptp_timecounter_init()
865 ptp->cc.shift = BNXT_CYCLES_SHIFT; in bnxt_ptp_timecounter_init()
866 ptp->cc.mult = clocksource_khz2mult(BNXT_DEVCLK_FREQ, ptp->cc.shift); in bnxt_ptp_timecounter_init()
867 ptp->cmult = ptp->cc.mult; in bnxt_ptp_timecounter_init()
869 ptp->cc.shift = 0; in bnxt_ptp_timecounter_init()
870 ptp->cc.mult = 1; in bnxt_ptp_timecounter_init()
872 ptp->next_overflow_check = jiffies + BNXT_PHC_OVERFLOW_PERIOD; in bnxt_ptp_timecounter_init()
875 timecounter_init(&ptp->tc, &ptp->cc, ktime_to_ns(ktime_get_real())); in bnxt_ptp_timecounter_init()
879 void bnxt_ptp_rtc_timecounter_init(struct bnxt_ptp_cfg *ptp, u64 ns) in bnxt_ptp_rtc_timecounter_init() argument
881 timecounter_init(&ptp->tc, &ptp->cc, ns); in bnxt_ptp_rtc_timecounter_init()
883 ptp->tc.cycle_last = ns & ptp->cc.mask; in bnxt_ptp_rtc_timecounter_init()
915 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_free() local
917 if (ptp->ptp_clock) { in bnxt_ptp_free()
918 ptp_clock_unregister(ptp->ptp_clock); in bnxt_ptp_free()
919 ptp->ptp_clock = NULL; in bnxt_ptp_free()
920 kfree(ptp->ptp_info.pin_config); in bnxt_ptp_free()
921 ptp->ptp_info.pin_config = NULL; in bnxt_ptp_free()
927 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_init() local
930 if (!ptp) in bnxt_ptp_init()
937 if (ptp->ptp_clock && bnxt_pps_config_ok(bp)) in bnxt_ptp_init()
942 atomic_set(&ptp->tx_avail, BNXT_MAX_TX_TS); in bnxt_ptp_init()
943 spin_lock_init(&ptp->ptp_lock); in bnxt_ptp_init()
956 ptp->ptp_info = bnxt_ptp_caps; in bnxt_ptp_init()
961 ptp->ptp_clock = ptp_clock_register(&ptp->ptp_info, &bp->pdev->dev); in bnxt_ptp_init()
962 if (IS_ERR(ptp->ptp_clock)) { in bnxt_ptp_init()
963 int err = PTR_ERR(ptp->ptp_clock); in bnxt_ptp_init()
965 ptp->ptp_clock = NULL; in bnxt_ptp_init()
970 spin_lock_bh(&ptp->ptp_lock); in bnxt_ptp_init()
971 bnxt_refclk_read(bp, NULL, &ptp->current_time); in bnxt_ptp_init()
972 WRITE_ONCE(ptp->old_time, ptp->current_time); in bnxt_ptp_init()
973 spin_unlock_bh(&ptp->ptp_lock); in bnxt_ptp_init()
974 ptp_schedule_worker(ptp->ptp_clock, 0); in bnxt_ptp_init()
986 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_clear() local
988 if (!ptp) in bnxt_ptp_clear()
991 if (ptp->ptp_clock) in bnxt_ptp_clear()
992 ptp_clock_unregister(ptp->ptp_clock); in bnxt_ptp_clear()
994 ptp->ptp_clock = NULL; in bnxt_ptp_clear()
995 kfree(ptp->ptp_info.pin_config); in bnxt_ptp_clear()
996 ptp->ptp_info.pin_config = NULL; in bnxt_ptp_clear()
998 if (ptp->tx_skb) { in bnxt_ptp_clear()
999 dev_kfree_skb_any(ptp->tx_skb); in bnxt_ptp_clear()
1000 ptp->tx_skb = NULL; in bnxt_ptp_clear()