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 write_seqlock_irqsave(&ptp->ptp_lock, flags); in bnxt_ptp_settime()
71 timecounter_init(&ptp->tc, &ptp->cc, ns); in bnxt_ptp_settime()
72 write_sequnlock_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()
104 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_refclk_read() local
109 read_seqlock_excl_irqsave(&ptp->ptp_lock, flags); in bnxt_refclk_read()
111 read_sequnlock_excl_irqrestore(&ptp->ptp_lock, flags); in bnxt_refclk_read()
118 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_refclk_read_low() local
122 read_seqlock_excl_irqsave(&ptp->ptp_lock, flags); in bnxt_refclk_read_low()
125 read_sequnlock_excl_irqrestore(&ptp->ptp_lock, flags); in bnxt_refclk_read_low()
130 *low = readl(bp->bar0 + ptp->refclk_mapped_regs[0]); in bnxt_refclk_read_low()
133 read_sequnlock_excl_irqrestore(&ptp->ptp_lock, flags); in bnxt_refclk_read_low()
139 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_get_current_time() local
141 if (!ptp) in bnxt_ptp_get_current_time()
143 WRITE_ONCE(ptp->old_time, ptp->current_time >> BNXT_HI_TIMER_SHIFT); in bnxt_ptp_get_current_time()
144 bnxt_refclk_read(bp, NULL, &ptp->current_time); in bnxt_ptp_get_current_time()
185 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_gettimex() local
191 rc = bnxt_refclk_read_low(ptp->bp, sts, &low); in bnxt_ptp_gettimex()
195 cycles = bnxt_extend_cycles_32b_to_48b(ptp, low); in bnxt_ptp_gettimex()
196 ns = bnxt_timecounter_cyc2time(ptp, cycles); in bnxt_ptp_gettimex()
204 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_update_current_time() local
206 bnxt_refclk_read(ptp->bp, NULL, &ptp->current_time); in bnxt_ptp_update_current_time()
207 WRITE_ONCE(ptp->old_time, ptp->current_time >> BNXT_HI_TIMER_SHIFT); in bnxt_ptp_update_current_time()
210 static int bnxt_ptp_adjphc(struct bnxt_ptp_cfg *ptp, s64 delta) in bnxt_ptp_adjphc() argument
215 rc = hwrm_req_init(ptp->bp, req, HWRM_PORT_MAC_CFG); in bnxt_ptp_adjphc()
222 rc = hwrm_req_send(ptp->bp, req); in bnxt_ptp_adjphc()
224 netdev_err(ptp->bp->dev, "ptp adjphc failed. rc = %x\n", rc); in bnxt_ptp_adjphc()
226 bnxt_ptp_update_current_time(ptp->bp); in bnxt_ptp_adjphc()
234 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_adjtime() local
238 if (BNXT_PTP_USE_RTC(ptp->bp)) in bnxt_ptp_adjtime()
239 return bnxt_ptp_adjphc(ptp, delta); in bnxt_ptp_adjtime()
241 write_seqlock_irqsave(&ptp->ptp_lock, flags); in bnxt_ptp_adjtime()
242 timecounter_adjtime(&ptp->tc, delta); in bnxt_ptp_adjtime()
243 write_sequnlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_ptp_adjtime()
262 "ptp adjfine failed. rc = %d\n", rc); in bnxt_ptp_adjfine_rtc()
268 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_adjfine() local
270 struct bnxt *bp = ptp->bp; in bnxt_ptp_adjfine()
276 write_seqlock_irqsave(&ptp->ptp_lock, flags); in bnxt_ptp_adjfine()
277 timecounter_read(&ptp->tc); in bnxt_ptp_adjfine()
278 ptp->cc.mult = adjust_by_scaled_ppm(ptp->cmult, scaled_ppm); in bnxt_ptp_adjfine()
279 write_sequnlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_ptp_adjfine()
285 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_pps_event() local
290 ns = bnxt_timecounter_cyc2time(ptp, pps_ts); in bnxt_ptp_pps_event()
311 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_cfg_pin() local
318 netdev_err(ptp->bp->dev, "1PPS: Invalid pin. Check pin-function configuration\n"); in bnxt_ptp_cfg_pin()
322 rc = hwrm_req_init(ptp->bp, req, HWRM_FUNC_PTP_PIN_CFG); in bnxt_ptp_cfg_pin()
336 rc = hwrm_req_send(ptp->bp, req); in bnxt_ptp_cfg_pin()
340 ptp->pps_info.pins[pin].usage = usage; in bnxt_ptp_cfg_pin()
341 ptp->pps_info.pins[pin].state = state; in bnxt_ptp_cfg_pin()
362 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_cfg_tstamp_filters() local
366 if (!ptp || !ptp->tstamp_filters) in bnxt_ptp_cfg_tstamp_filters()
373 if (!(bp->fw_cap & BNXT_FW_CAP_RX_ALL_PKT_TS) && (ptp->tstamp_filters & in bnxt_ptp_cfg_tstamp_filters()
376 ptp->tstamp_filters &= ~(PORT_MAC_CFG_REQ_FLAGS_ALL_RX_TS_CAPTURE_ENABLE | in bnxt_ptp_cfg_tstamp_filters()
381 req->flags = cpu_to_le32(ptp->tstamp_filters); in bnxt_ptp_cfg_tstamp_filters()
383 req->rx_ts_capture_ptp_msg_type = cpu_to_le16(ptp->rxctl); in bnxt_ptp_cfg_tstamp_filters()
387 bp->ptp_all_rx_tstamp = !!(ptp->tstamp_filters & in bnxt_ptp_cfg_tstamp_filters()
391 ptp->tstamp_filters = 0; in bnxt_ptp_cfg_tstamp_filters()
400 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_reapply_pps() local
405 if (!ptp || !(bp->fw_cap & BNXT_FW_CAP_PTP_PPS) || in bnxt_ptp_reapply_pps()
406 !(ptp->ptp_info.pin_config)) in bnxt_ptp_reapply_pps()
408 pps = &ptp->pps_info; in bnxt_ptp_reapply_pps()
422 static int bnxt_get_target_cycles(struct bnxt_ptp_cfg *ptp, u64 target_ns, in bnxt_get_target_cycles() argument
429 rc = bnxt_refclk_read(ptp->bp, NULL, &cycles_now); in bnxt_get_target_cycles()
433 nsec_now = bnxt_timecounter_cyc2time(ptp, cycles_now); in bnxt_get_target_cycles()
436 *cycles_delta = div64_u64(nsec_delta << ptp->cc.shift, ptp->cc.mult); in bnxt_get_target_cycles()
440 static int bnxt_ptp_perout_cfg(struct bnxt_ptp_cfg *ptp, in bnxt_ptp_perout_cfg() argument
444 struct bnxt *bp = ptp->bp; in bnxt_ptp_perout_cfg()
454 rc = bnxt_get_target_cycles(ptp, target_ns, &delta); in bnxt_ptp_perout_cfg()
479 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_enable() local
481 struct bnxt *bp = ptp->bp; in bnxt_ptp_enable()
488 pin_id = ptp_find_pin(ptp->ptp_clock, PTP_PF_EXTTS, in bnxt_ptp_enable()
499 ptp->pps_info.pins[pin_id].event = BNXT_PPS_EVENT_EXTERNAL; in bnxt_ptp_enable()
503 pin_id = ptp_find_pin(ptp->ptp_clock, PTP_PF_PEROUT, in bnxt_ptp_enable()
512 rc = bnxt_ptp_perout_cfg(ptp, rq); in bnxt_ptp_enable()
522 ptp->pps_info.pins[0].event = BNXT_PPS_EVENT_INTERNAL; in bnxt_ptp_enable()
525 netdev_err(ptp->bp->dev, "Unrecognized PIN function\n"); in bnxt_ptp_enable()
534 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_hwrm_ptp_cfg() local
537 switch (ptp->rx_filter) { in bnxt_hwrm_ptp_cfg()
553 if (ptp->tx_tstamp_en) in bnxt_hwrm_ptp_cfg()
558 ptp->tstamp_filters = flags; in bnxt_hwrm_ptp_cfg()
567 struct bnxt_ptp_cfg *ptp; in bnxt_hwtstamp_set() local
572 ptp = bp->ptp_cfg; in bnxt_hwtstamp_set()
573 if (!ptp) in bnxt_hwtstamp_set()
583 old_rx_filter = ptp->rx_filter; in bnxt_hwtstamp_set()
584 old_rxctl = ptp->rxctl; in bnxt_hwtstamp_set()
585 old_tx_tstamp_en = ptp->tx_tstamp_en; in bnxt_hwtstamp_set()
588 ptp->rxctl = 0; in bnxt_hwtstamp_set()
589 ptp->rx_filter = HWTSTAMP_FILTER_NONE; in bnxt_hwtstamp_set()
593 ptp->rx_filter = HWTSTAMP_FILTER_ALL; in bnxt_hwtstamp_set()
600 ptp->rxctl = BNXT_PTP_MSG_EVENTS; in bnxt_hwtstamp_set()
601 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; in bnxt_hwtstamp_set()
606 ptp->rxctl = BNXT_PTP_MSG_SYNC; in bnxt_hwtstamp_set()
607 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_SYNC; in bnxt_hwtstamp_set()
612 ptp->rxctl = BNXT_PTP_MSG_DELAY_REQ; in bnxt_hwtstamp_set()
613 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_DELAY_REQ; in bnxt_hwtstamp_set()
620 ptp->tx_tstamp_en = 1; in bnxt_hwtstamp_set()
622 ptp->tx_tstamp_en = 0; in bnxt_hwtstamp_set()
628 stmpconf.rx_filter = ptp->rx_filter; in bnxt_hwtstamp_set()
633 ptp->rx_filter = old_rx_filter; in bnxt_hwtstamp_set()
634 ptp->rxctl = old_rxctl; in bnxt_hwtstamp_set()
635 ptp->tx_tstamp_en = old_tx_tstamp_en; in bnxt_hwtstamp_set()
643 struct bnxt_ptp_cfg *ptp; in bnxt_hwtstamp_get() local
645 ptp = bp->ptp_cfg; in bnxt_hwtstamp_get()
646 if (!ptp) in bnxt_hwtstamp_get()
650 stmpconf.tx_type = ptp->tx_tstamp_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF; in bnxt_hwtstamp_get()
652 stmpconf.rx_filter = ptp->rx_filter; in bnxt_hwtstamp_get()
674 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_map_ptp_regs() local
678 reg_arr = ptp->refclk_regs; in bnxt_map_ptp_regs()
684 ptp->refclk_mapped_regs[i] = BNXT_PTP_GRC_WIN_BASE + in bnxt_map_ptp_regs()
685 (ptp->refclk_regs[i] & BNXT_GRC_OFFSET_MASK); in bnxt_map_ptp_regs()
692 ptp->refclk_mapped_regs[i] = reg_arr[i]; in bnxt_map_ptp_regs()
707 struct bnxt_ptp_cfg *ptp = container_of(cc, struct bnxt_ptp_cfg, cc); in bnxt_cc_read() local
710 __bnxt_refclk_read(ptp->bp, NULL, &ns); in bnxt_cc_read()
716 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_stamp_tx_skb() local
724 txts_req = &ptp->txts_req[slot]; in bnxt_stamp_tx_skb()
733 ns = bnxt_timecounter_cyc2time(ptp, ts); in bnxt_stamp_tx_skb()
736 ptp->stats.ts_pkts++; in bnxt_stamp_tx_skb()
741 ptp->stats.ts_lost++; in bnxt_stamp_tx_skb()
754 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_ts_aux_work() local
757 struct bnxt *bp = ptp->bp; in bnxt_ptp_ts_aux_work()
758 u16 cons = ptp->txts_cons; in bnxt_ptp_ts_aux_work()
763 num_requests = BNXT_MAX_TX_TS - READ_ONCE(ptp->tx_avail); in bnxt_ptp_ts_aux_work()
765 if (IS_ERR(ptp->txts_req[cons].tx_skb)) in bnxt_ptp_ts_aux_work()
767 if (!ptp->txts_req[cons].tx_skb) in bnxt_ptp_ts_aux_work()
773 BNXT_PTP_INC_TX_AVAIL(ptp); in bnxt_ptp_ts_aux_work()
776 ptp->txts_cons = cons; in bnxt_ptp_ts_aux_work()
778 if (!time_after_eq(now, ptp->next_period)) { in bnxt_ptp_ts_aux_work()
781 return ptp->next_period - now; in bnxt_ptp_ts_aux_work()
785 ptp->next_period = now + HZ; in bnxt_ptp_ts_aux_work()
786 if (time_after_eq(now, ptp->next_overflow_check)) { in bnxt_ptp_ts_aux_work()
787 write_seqlock_irqsave(&ptp->ptp_lock, flags); in bnxt_ptp_ts_aux_work()
788 timecounter_read(&ptp->tc); in bnxt_ptp_ts_aux_work()
789 write_sequnlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_ptp_ts_aux_work()
790 ptp->next_overflow_check = now + BNXT_PHC_OVERFLOW_PERIOD; in bnxt_ptp_ts_aux_work()
797 int bnxt_ptp_get_txts_prod(struct bnxt_ptp_cfg *ptp, u16 *prod) in bnxt_ptp_get_txts_prod() argument
799 spin_lock_bh(&ptp->ptp_tx_lock); in bnxt_ptp_get_txts_prod()
800 if (ptp->tx_avail) { in bnxt_ptp_get_txts_prod()
801 *prod = ptp->txts_prod; in bnxt_ptp_get_txts_prod()
802 ptp->txts_prod = NEXT_TXTS(*prod); in bnxt_ptp_get_txts_prod()
803 ptp->tx_avail--; in bnxt_ptp_get_txts_prod()
804 spin_unlock_bh(&ptp->ptp_tx_lock); in bnxt_ptp_get_txts_prod()
807 spin_unlock_bh(&ptp->ptp_tx_lock); in bnxt_ptp_get_txts_prod()
808 atomic64_inc(&ptp->stats.ts_err); in bnxt_ptp_get_txts_prod()
814 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_get_tx_ts_p5() local
817 txts_req = &ptp->txts_req[prod]; in bnxt_get_tx_ts_p5()
818 txts_req->abs_txts_tmo = jiffies + msecs_to_jiffies(ptp->txts_tmo); in bnxt_get_tx_ts_p5()
822 ptp_schedule_worker(ptp->ptp_clock, 0); in bnxt_get_tx_ts_p5()
827 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_get_rx_ts_p5() local
829 if (!ptp) in bnxt_get_rx_ts_p5()
832 *ts = bnxt_extend_cycles_32b_to_48b(ptp, pkt_ts); in bnxt_get_rx_ts_p5()
841 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_tx_ts_cmp() local
859 ns = bnxt_timecounter_cyc2time(ptp, ts); in bnxt_tx_ts_cmp()
887 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, in bnxt_ptp_verify() local
890 if (ptp->pps_info.pins[pin].usage <= BNXT_PPS_PIN_PPS_OUT && in bnxt_ptp_verify()
901 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_pps_init() local
919 ptp_info = &ptp->ptp_info; in bnxt_ptp_pps_init()
920 pps_info = &ptp->pps_info; in bnxt_ptp_pps_init()
960 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_pps_config_ok() local
962 return !(bp->fw_cap & BNXT_FW_CAP_PTP_PPS) == !ptp->ptp_info.pin_config; in bnxt_pps_config_ok()
967 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_timecounter_init() local
970 if (!ptp->ptp_clock) { in bnxt_ptp_timecounter_init()
971 memset(&ptp->cc, 0, sizeof(ptp->cc)); in bnxt_ptp_timecounter_init()
972 ptp->cc.read = bnxt_cc_read; in bnxt_ptp_timecounter_init()
973 ptp->cc.mask = CYCLECOUNTER_MASK(48); in bnxt_ptp_timecounter_init()
976 ptp->cc.shift = BNXT_CYCLES_SHIFT; in bnxt_ptp_timecounter_init()
977 ptp->cc.mult = clocksource_khz2mult(BNXT_DEVCLK_FREQ, ptp->cc.shift); in bnxt_ptp_timecounter_init()
978 ptp->cmult = ptp->cc.mult; in bnxt_ptp_timecounter_init()
980 ptp->cc.shift = 0; in bnxt_ptp_timecounter_init()
981 ptp->cc.mult = 1; in bnxt_ptp_timecounter_init()
983 ptp->next_overflow_check = jiffies + BNXT_PHC_OVERFLOW_PERIOD; in bnxt_ptp_timecounter_init()
986 write_seqlock_irqsave(&ptp->ptp_lock, flags); in bnxt_ptp_timecounter_init()
987 timecounter_init(&ptp->tc, &ptp->cc, ktime_to_ns(ktime_get_real())); in bnxt_ptp_timecounter_init()
988 write_sequnlock_irqrestore(&ptp->ptp_lock, flags); in bnxt_ptp_timecounter_init()
993 void bnxt_ptp_rtc_timecounter_init(struct bnxt_ptp_cfg *ptp, u64 ns) in bnxt_ptp_rtc_timecounter_init() argument
995 timecounter_init(&ptp->tc, &ptp->cc, ns); in bnxt_ptp_rtc_timecounter_init()
997 ptp->tc.cycle_last = ns & ptp->cc.mask; in bnxt_ptp_rtc_timecounter_init()
1031 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_free() local
1033 if (ptp->ptp_clock) { in bnxt_ptp_free()
1034 ptp_clock_unregister(ptp->ptp_clock); in bnxt_ptp_free()
1035 ptp->ptp_clock = NULL; in bnxt_ptp_free()
1036 kfree(ptp->ptp_info.pin_config); in bnxt_ptp_free()
1037 ptp->ptp_info.pin_config = NULL; in bnxt_ptp_free()
1043 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_init() local
1046 if (!ptp) in bnxt_ptp_init()
1053 if (ptp->ptp_clock && bnxt_pps_config_ok(bp)) in bnxt_ptp_init()
1058 WRITE_ONCE(ptp->tx_avail, BNXT_MAX_TX_TS); in bnxt_ptp_init()
1059 seqlock_init(&ptp->ptp_lock); in bnxt_ptp_init()
1060 spin_lock_init(&ptp->ptp_tx_lock); in bnxt_ptp_init()
1064 rc = bnxt_ptp_init_rtc(bp, ptp->rtc_configured); in bnxt_ptp_init()
1073 ptp->ptp_info = bnxt_ptp_caps; in bnxt_ptp_init()
1078 ptp->ptp_clock = ptp_clock_register(&ptp->ptp_info, &bp->pdev->dev); in bnxt_ptp_init()
1079 if (IS_ERR(ptp->ptp_clock)) { in bnxt_ptp_init()
1080 int err = PTR_ERR(ptp->ptp_clock); in bnxt_ptp_init()
1082 ptp->ptp_clock = NULL; in bnxt_ptp_init()
1087 ptp->stats.ts_pkts = 0; in bnxt_ptp_init()
1088 ptp->stats.ts_lost = 0; in bnxt_ptp_init()
1089 atomic64_set(&ptp->stats.ts_err, 0); in bnxt_ptp_init()
1092 bnxt_refclk_read(bp, NULL, &ptp->current_time); in bnxt_ptp_init()
1093 WRITE_ONCE(ptp->old_time, ptp->current_time >> BNXT_HI_TIMER_SHIFT); in bnxt_ptp_init()
1094 ptp_schedule_worker(ptp->ptp_clock, 0); in bnxt_ptp_init()
1096 ptp->txts_tmo = BNXT_PTP_DFLT_TX_TMO; in bnxt_ptp_init()
1107 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; in bnxt_ptp_clear() local
1110 if (!ptp) in bnxt_ptp_clear()
1113 if (ptp->ptp_clock) in bnxt_ptp_clear()
1114 ptp_clock_unregister(ptp->ptp_clock); in bnxt_ptp_clear()
1116 ptp->ptp_clock = NULL; in bnxt_ptp_clear()
1117 kfree(ptp->ptp_info.pin_config); in bnxt_ptp_clear()
1118 ptp->ptp_info.pin_config = NULL; in bnxt_ptp_clear()
1121 if (ptp->txts_req[i].tx_skb) { in bnxt_ptp_clear()
1122 dev_kfree_skb_any(ptp->txts_req[i].tx_skb); in bnxt_ptp_clear()
1123 ptp->txts_req[i].tx_skb = NULL; in bnxt_ptp_clear()