Lines Matching full: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()
223 "ptp adjfine failed. rc = %d\n", rc); in bnxt_ptp_adjfine_rtc()
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
328 if (!ptp || !ptp->tstamp_filters) in bnxt_ptp_cfg_tstamp_filters()
335 if (!(bp->fw_cap & BNXT_FW_CAP_RX_ALL_PKT_TS) && (ptp->tstamp_filters & in bnxt_ptp_cfg_tstamp_filters()
338 ptp->tstamp_filters &= ~(PORT_MAC_CFG_REQ_FLAGS_ALL_RX_TS_CAPTURE_ENABLE | in bnxt_ptp_cfg_tstamp_filters()
343 req->flags = cpu_to_le32(ptp->tstamp_filters); in bnxt_ptp_cfg_tstamp_filters()
345 req->rx_ts_capture_ptp_msg_type = cpu_to_le16(ptp->rxctl); in bnxt_ptp_cfg_tstamp_filters()
349 bp->ptp_all_rx_tstamp = !!(ptp->tstamp_filters & in bnxt_ptp_cfg_tstamp_filters()
353 ptp->tstamp_filters = 0; in bnxt_ptp_cfg_tstamp_filters()
362 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_reapply_pps() local
367 if (!ptp || !(bp->fw_cap & BNXT_FW_CAP_PTP_PPS) || in bnxt_ptp_reapply_pps()
368 !(ptp->ptp_info.pin_config)) in bnxt_ptp_reapply_pps()
370 pps = &ptp->pps_info; in bnxt_ptp_reapply_pps()
384 static int bnxt_get_target_cycles(struct bnxt_ptp_cfg *ptp, u64 target_ns, in bnxt_get_target_cycles() argument
391 spin_lock_bh(&ptp->ptp_lock); in bnxt_get_target_cycles()
392 rc = bnxt_refclk_read(ptp->bp, NULL, &cycles_now); in bnxt_get_target_cycles()
394 spin_unlock_bh(&ptp->ptp_lock); in bnxt_get_target_cycles()
397 nsec_now = timecounter_cyc2time(&ptp->tc, cycles_now); in bnxt_get_target_cycles()
398 spin_unlock_bh(&ptp->ptp_lock); in bnxt_get_target_cycles()
401 *cycles_delta = div64_u64(nsec_delta << ptp->cc.shift, ptp->cc.mult); in bnxt_get_target_cycles()
405 static int bnxt_ptp_perout_cfg(struct bnxt_ptp_cfg *ptp, in bnxt_ptp_perout_cfg() argument
409 struct bnxt *bp = ptp->bp; in bnxt_ptp_perout_cfg()
419 rc = bnxt_get_target_cycles(ptp, target_ns, &delta); in bnxt_ptp_perout_cfg()
444 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_enable() local
446 struct bnxt *bp = ptp->bp; in bnxt_ptp_enable()
453 pin_id = ptp_find_pin(ptp->ptp_clock, PTP_PF_EXTTS, in bnxt_ptp_enable()
464 ptp->pps_info.pins[pin_id].event = BNXT_PPS_EVENT_EXTERNAL; in bnxt_ptp_enable()
468 pin_id = ptp_find_pin(ptp->ptp_clock, PTP_PF_PEROUT, in bnxt_ptp_enable()
477 rc = bnxt_ptp_perout_cfg(ptp, rq); in bnxt_ptp_enable()
487 ptp->pps_info.pins[0].event = BNXT_PPS_EVENT_INTERNAL; in bnxt_ptp_enable()
490 netdev_err(ptp->bp->dev, "Unrecognized PIN function\n"); in bnxt_ptp_enable()
499 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_hwrm_ptp_cfg() local
502 switch (ptp->rx_filter) { in bnxt_hwrm_ptp_cfg()
518 if (ptp->tx_tstamp_en) in bnxt_hwrm_ptp_cfg()
523 ptp->tstamp_filters = flags; in bnxt_hwrm_ptp_cfg()
532 struct bnxt_ptp_cfg *ptp; in bnxt_hwtstamp_set() local
537 ptp = bp->ptp_cfg; in bnxt_hwtstamp_set()
538 if (!ptp) in bnxt_hwtstamp_set()
548 old_rx_filter = ptp->rx_filter; in bnxt_hwtstamp_set()
549 old_rxctl = ptp->rxctl; in bnxt_hwtstamp_set()
550 old_tx_tstamp_en = ptp->tx_tstamp_en; in bnxt_hwtstamp_set()
553 ptp->rxctl = 0; in bnxt_hwtstamp_set()
554 ptp->rx_filter = HWTSTAMP_FILTER_NONE; in bnxt_hwtstamp_set()
558 ptp->rx_filter = HWTSTAMP_FILTER_ALL; in bnxt_hwtstamp_set()
565 ptp->rxctl = BNXT_PTP_MSG_EVENTS; in bnxt_hwtstamp_set()
566 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; in bnxt_hwtstamp_set()
571 ptp->rxctl = BNXT_PTP_MSG_SYNC; in bnxt_hwtstamp_set()
572 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_SYNC; in bnxt_hwtstamp_set()
577 ptp->rxctl = BNXT_PTP_MSG_DELAY_REQ; in bnxt_hwtstamp_set()
578 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_DELAY_REQ; in bnxt_hwtstamp_set()
585 ptp->tx_tstamp_en = 1; in bnxt_hwtstamp_set()
587 ptp->tx_tstamp_en = 0; in bnxt_hwtstamp_set()
593 stmpconf.rx_filter = ptp->rx_filter; in bnxt_hwtstamp_set()
598 ptp->rx_filter = old_rx_filter; in bnxt_hwtstamp_set()
599 ptp->rxctl = old_rxctl; in bnxt_hwtstamp_set()
600 ptp->tx_tstamp_en = old_tx_tstamp_en; in bnxt_hwtstamp_set()
608 struct bnxt_ptp_cfg *ptp; in bnxt_hwtstamp_get() local
610 ptp = bp->ptp_cfg; in bnxt_hwtstamp_get()
611 if (!ptp) in bnxt_hwtstamp_get()
615 stmpconf.tx_type = ptp->tx_tstamp_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF; in bnxt_hwtstamp_get()
617 stmpconf.rx_filter = ptp->rx_filter; in bnxt_hwtstamp_get()
639 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_map_ptp_regs() local
643 reg_arr = ptp->refclk_regs; in bnxt_map_ptp_regs()
649 ptp->refclk_mapped_regs[i] = BNXT_PTP_GRC_WIN_BASE + in bnxt_map_ptp_regs()
650 (ptp->refclk_regs[i] & BNXT_GRC_OFFSET_MASK); in bnxt_map_ptp_regs()
664 struct bnxt_ptp_cfg *ptp = container_of(cc, struct bnxt_ptp_cfg, cc); in bnxt_cc_read() local
667 bnxt_refclk_read(ptp->bp, NULL, &ns); in bnxt_cc_read()
673 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_stamp_tx_skb() local
681 spin_lock_bh(&ptp->ptp_lock); in bnxt_stamp_tx_skb()
682 ns = timecounter_cyc2time(&ptp->tc, ts); in bnxt_stamp_tx_skb()
683 spin_unlock_bh(&ptp->ptp_lock); in bnxt_stamp_tx_skb()
685 skb_tstamp_tx(ptp->tx_skb, &timestamp); in bnxt_stamp_tx_skb()
691 dev_kfree_skb_any(ptp->tx_skb); in bnxt_stamp_tx_skb()
692 ptp->tx_skb = NULL; in bnxt_stamp_tx_skb()
693 atomic_inc(&ptp->tx_avail); in bnxt_stamp_tx_skb()
698 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_ts_aux_work() local
701 struct bnxt *bp = ptp->bp; in bnxt_ptp_ts_aux_work()
703 if (ptp->tx_skb) in bnxt_ptp_ts_aux_work()
704 bnxt_stamp_tx_skb(bp, ptp->tx_skb); in bnxt_ptp_ts_aux_work()
706 if (!time_after_eq(now, ptp->next_period)) in bnxt_ptp_ts_aux_work()
707 return ptp->next_period - now; in bnxt_ptp_ts_aux_work()
710 ptp->next_period = now + HZ; in bnxt_ptp_ts_aux_work()
711 if (time_after_eq(now, ptp->next_overflow_check)) { in bnxt_ptp_ts_aux_work()
712 spin_lock_bh(&ptp->ptp_lock); in bnxt_ptp_ts_aux_work()
713 timecounter_read(&ptp->tc); in bnxt_ptp_ts_aux_work()
714 spin_unlock_bh(&ptp->ptp_lock); in bnxt_ptp_ts_aux_work()
715 ptp->next_overflow_check = now + BNXT_PHC_OVERFLOW_PERIOD; in bnxt_ptp_ts_aux_work()
722 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_get_tx_ts_p5() local
724 if (ptp->tx_skb) { in bnxt_get_tx_ts_p5()
728 ptp->tx_skb = skb; in bnxt_get_tx_ts_p5()
729 ptp_schedule_worker(ptp->ptp_clock, 0); in bnxt_get_tx_ts_p5()
735 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_get_rx_ts_p5() local
738 if (!ptp) in bnxt_get_rx_ts_p5()
741 BNXT_READ_TIME64(ptp, time, ptp->old_time); in bnxt_get_rx_ts_p5()
769 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_verify() local
772 if (ptp->pps_info.pins[pin].usage <= BNXT_PPS_PIN_PPS_OUT && in bnxt_ptp_verify()
783 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_pps_init() local
801 ptp_info = &ptp->ptp_info; in bnxt_ptp_pps_init()
802 pps_info = &ptp->pps_info; in bnxt_ptp_pps_init()
842 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_pps_config_ok() local
844 return !(bp->fw_cap & BNXT_FW_CAP_PTP_PPS) == !ptp->ptp_info.pin_config; in bnxt_pps_config_ok()
849 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_timecounter_init() local
851 if (!ptp->ptp_clock) { in bnxt_ptp_timecounter_init()
852 memset(&ptp->cc, 0, sizeof(ptp->cc)); in bnxt_ptp_timecounter_init()
853 ptp->cc.read = bnxt_cc_read; in bnxt_ptp_timecounter_init()
854 ptp->cc.mask = CYCLECOUNTER_MASK(48); in bnxt_ptp_timecounter_init()
857 ptp->cc.shift = BNXT_CYCLES_SHIFT; in bnxt_ptp_timecounter_init()
858 ptp->cc.mult = clocksource_khz2mult(BNXT_DEVCLK_FREQ, ptp->cc.shift); in bnxt_ptp_timecounter_init()
859 ptp->cmult = ptp->cc.mult; in bnxt_ptp_timecounter_init()
861 ptp->cc.shift = 0; in bnxt_ptp_timecounter_init()
862 ptp->cc.mult = 1; in bnxt_ptp_timecounter_init()
864 ptp->next_overflow_check = jiffies + BNXT_PHC_OVERFLOW_PERIOD; in bnxt_ptp_timecounter_init()
867 timecounter_init(&ptp->tc, &ptp->cc, ktime_to_ns(ktime_get_real())); in bnxt_ptp_timecounter_init()
871 void bnxt_ptp_rtc_timecounter_init(struct bnxt_ptp_cfg *ptp, u64 ns) in bnxt_ptp_rtc_timecounter_init() argument
873 timecounter_init(&ptp->tc, &ptp->cc, ns); in bnxt_ptp_rtc_timecounter_init()
875 ptp->tc.cycle_last = ns & ptp->cc.mask; in bnxt_ptp_rtc_timecounter_init()
907 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_free() local
909 if (ptp->ptp_clock) { in bnxt_ptp_free()
910 ptp_clock_unregister(ptp->ptp_clock); in bnxt_ptp_free()
911 ptp->ptp_clock = NULL; in bnxt_ptp_free()
912 kfree(ptp->ptp_info.pin_config); in bnxt_ptp_free()
913 ptp->ptp_info.pin_config = NULL; in bnxt_ptp_free()
919 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_init() local
922 if (!ptp) in bnxt_ptp_init()
929 if (ptp->ptp_clock && bnxt_pps_config_ok(bp)) in bnxt_ptp_init()
934 atomic_set(&ptp->tx_avail, BNXT_MAX_TX_TS); in bnxt_ptp_init()
935 spin_lock_init(&ptp->ptp_lock); in bnxt_ptp_init()
948 ptp->ptp_info = bnxt_ptp_caps; in bnxt_ptp_init()
953 ptp->ptp_clock = ptp_clock_register(&ptp->ptp_info, &bp->pdev->dev); in bnxt_ptp_init()
954 if (IS_ERR(ptp->ptp_clock)) { in bnxt_ptp_init()
955 int err = PTR_ERR(ptp->ptp_clock); in bnxt_ptp_init()
957 ptp->ptp_clock = NULL; in bnxt_ptp_init()
962 spin_lock_bh(&ptp->ptp_lock); in bnxt_ptp_init()
963 bnxt_refclk_read(bp, NULL, &ptp->current_time); in bnxt_ptp_init()
964 WRITE_ONCE(ptp->old_time, ptp->current_time); in bnxt_ptp_init()
965 spin_unlock_bh(&ptp->ptp_lock); in bnxt_ptp_init()
966 ptp_schedule_worker(ptp->ptp_clock, 0); in bnxt_ptp_init()
978 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_clear() local
980 if (!ptp) in bnxt_ptp_clear()
983 if (ptp->ptp_clock) in bnxt_ptp_clear()
984 ptp_clock_unregister(ptp->ptp_clock); in bnxt_ptp_clear()
986 ptp->ptp_clock = NULL; in bnxt_ptp_clear()
987 kfree(ptp->ptp_info.pin_config); in bnxt_ptp_clear()
988 ptp->ptp_info.pin_config = NULL; in bnxt_ptp_clear()
990 if (ptp->tx_skb) { in bnxt_ptp_clear()
991 dev_kfree_skb_any(ptp->tx_skb); in bnxt_ptp_clear()
992 ptp->tx_skb = NULL; in bnxt_ptp_clear()