Lines Matching +full:timer1 +full:- +full:sts
1 // SPDX-License-Identifier: GPL-2.0
26 struct igc_hw *hw = &adapter->hw; in igc_ptp_read()
33 ts->tv_sec = sec; in igc_ptp_read()
34 ts->tv_nsec = nsec; in igc_ptp_read()
40 struct igc_hw *hw = &adapter->hw; in igc_ptp_write_i225()
42 wr32(IGC_SYSTIML, ts->tv_nsec); in igc_ptp_write_i225()
43 wr32(IGC_SYSTIMH, ts->tv_sec); in igc_ptp_write_i225()
50 struct igc_hw *hw = &igc->hw; in igc_ptp_adjfine_i225()
57 scaled_ppm = -scaled_ppm; in igc_ptp_adjfine_i225()
79 spin_lock_irqsave(&igc->tmreg_lock, flags); in igc_ptp_adjtime_i225()
85 spin_unlock_irqrestore(&igc->tmreg_lock, flags); in igc_ptp_adjtime_i225()
92 struct ptp_system_timestamp *sts) in igc_ptp_gettimex64_i225() argument
96 struct igc_hw *hw = &igc->hw; in igc_ptp_gettimex64_i225()
99 spin_lock_irqsave(&igc->tmreg_lock, flags); in igc_ptp_gettimex64_i225()
101 ptp_read_system_prets(sts); in igc_ptp_gettimex64_i225()
102 ts->tv_nsec = rd32(IGC_SYSTIML); in igc_ptp_gettimex64_i225()
103 ts->tv_sec = rd32(IGC_SYSTIMH); in igc_ptp_gettimex64_i225()
104 ptp_read_system_postts(sts); in igc_ptp_gettimex64_i225()
106 spin_unlock_irqrestore(&igc->tmreg_lock, flags); in igc_ptp_gettimex64_i225()
118 spin_lock_irqsave(&igc->tmreg_lock, flags); in igc_ptp_settime_i225()
122 spin_unlock_irqrestore(&igc->tmreg_lock, flags); in igc_ptp_settime_i225()
174 struct igc_hw *hw = &igc->hw; in igc_pin_perout()
220 struct igc_hw *hw = &igc->hw; in igc_pin_extts()
250 struct igc_hw *hw = &igc->hw; in igc_ptp_feature_enable_i225()
253 int use_freq = 0, pin = -1; in igc_ptp_feature_enable_i225()
257 switch (rq->type) { in igc_ptp_feature_enable_i225()
260 if (rq->extts.flags & ~(PTP_ENABLE_FEATURE | in igc_ptp_feature_enable_i225()
264 return -EOPNOTSUPP; in igc_ptp_feature_enable_i225()
267 if ((rq->extts.flags & PTP_STRICT_FLAGS) && in igc_ptp_feature_enable_i225()
268 (rq->extts.flags & PTP_ENABLE_FEATURE) && in igc_ptp_feature_enable_i225()
269 (rq->extts.flags & PTP_EXTTS_EDGES) != PTP_EXTTS_EDGES) in igc_ptp_feature_enable_i225()
270 return -EOPNOTSUPP; in igc_ptp_feature_enable_i225()
273 pin = ptp_find_pin(igc->ptp_clock, PTP_PF_EXTTS, in igc_ptp_feature_enable_i225()
274 rq->extts.index); in igc_ptp_feature_enable_i225()
276 return -EBUSY; in igc_ptp_feature_enable_i225()
278 if (rq->extts.index == 1) { in igc_ptp_feature_enable_i225()
285 spin_lock_irqsave(&igc->tmreg_lock, flags); in igc_ptp_feature_enable_i225()
289 igc_pin_extts(igc, rq->extts.index, pin); in igc_ptp_feature_enable_i225()
298 spin_unlock_irqrestore(&igc->tmreg_lock, flags); in igc_ptp_feature_enable_i225()
303 if (rq->perout.flags) in igc_ptp_feature_enable_i225()
304 return -EOPNOTSUPP; in igc_ptp_feature_enable_i225()
307 pin = ptp_find_pin(igc->ptp_clock, PTP_PF_PEROUT, in igc_ptp_feature_enable_i225()
308 rq->perout.index); in igc_ptp_feature_enable_i225()
310 return -EBUSY; in igc_ptp_feature_enable_i225()
312 ts.tv_sec = rq->perout.period.sec; in igc_ptp_feature_enable_i225()
313 ts.tv_nsec = rq->perout.period.nsec; in igc_ptp_feature_enable_i225()
319 return -EINVAL; in igc_ptp_feature_enable_i225()
323 if (rq->perout.index == 1) { in igc_ptp_feature_enable_i225()
346 spin_lock_irqsave(&igc->tmreg_lock, flags); in igc_ptp_feature_enable_i225()
349 if (rq->perout.index == 1) { in igc_ptp_feature_enable_i225()
357 int i = rq->perout.index; in igc_ptp_feature_enable_i225()
360 igc->perout[i].start.tv_sec = rq->perout.start.sec; in igc_ptp_feature_enable_i225()
361 igc->perout[i].start.tv_nsec = rq->perout.start.nsec; in igc_ptp_feature_enable_i225()
362 igc->perout[i].period.tv_sec = ts.tv_sec; in igc_ptp_feature_enable_i225()
363 igc->perout[i].period.tv_nsec = ts.tv_nsec; in igc_ptp_feature_enable_i225()
364 wr32(trgttimh, rq->perout.start.sec); in igc_ptp_feature_enable_i225()
366 wr32(trgttiml, rq->perout.start.nsec | IGC_TT_IO_TIMER_SEL_SYSTIM0); in igc_ptp_feature_enable_i225()
374 spin_unlock_irqrestore(&igc->tmreg_lock, flags); in igc_ptp_feature_enable_i225()
378 spin_lock_irqsave(&igc->tmreg_lock, flags); in igc_ptp_feature_enable_i225()
384 igc->pps_sys_wrap_on = on; in igc_ptp_feature_enable_i225()
386 spin_unlock_irqrestore(&igc->tmreg_lock, flags); in igc_ptp_feature_enable_i225()
393 return -EOPNOTSUPP; in igc_ptp_feature_enable_i225()
405 return -1; in igc_ptp_verify_pin()
411 * igc_ptp_systim_to_hwtstamp - convert system time value to HW timestamp
423 switch (adapter->hw.mac.type) { in igc_ptp_systim_to_hwtstamp()
427 hwtstamps->hwtstamp = ktime_set(systim >> 32, in igc_ptp_systim_to_hwtstamp()
436 * igc_ptp_rx_pktstamp - Retrieve timestamp from Rx packet buffer
442 * other in timer1 reference, this function considers only the timestamp in
457 * Field: | Timer1 SYSTIML | Timer1 SYSTIMH | Timer0 SYSTIML | Timer0 SYSTIMH | in igc_ptp_rx_pktstamp()
468 switch (adapter->link_speed) { in igc_ptp_rx_pktstamp()
483 netdev_warn_once(adapter->netdev, "Imprecise timestamp\n"); in igc_ptp_rx_pktstamp()
492 struct igc_hw *hw = &adapter->hw; in igc_ptp_disable_rx_timestamp()
498 for (i = 0; i < adapter->num_rx_queues; i++) { in igc_ptp_disable_rx_timestamp()
511 struct igc_hw *hw = &adapter->hw; in igc_ptp_enable_rx_timestamp()
519 for (i = 0; i < adapter->num_rx_queues; i++) { in igc_ptp_enable_rx_timestamp()
536 struct igc_hw *hw = &adapter->hw; in igc_ptp_disable_tx_timestamp()
543 struct igc_hw *hw = &adapter->hw; in igc_ptp_enable_tx_timestamp()
553 * igc_ptp_set_timestamp_mode - setup hardware for timestamping
562 switch (config->tx_type) { in igc_ptp_set_timestamp_mode()
570 return -ERANGE; in igc_ptp_set_timestamp_mode()
573 switch (config->rx_filter) { in igc_ptp_set_timestamp_mode()
592 config->rx_filter = HWTSTAMP_FILTER_ALL; in igc_ptp_set_timestamp_mode()
595 return -ERANGE; in igc_ptp_set_timestamp_mode()
603 struct igc_hw *hw = &adapter->hw; in igc_ptp_tx_timeout()
605 dev_kfree_skb_any(adapter->ptp_tx_skb); in igc_ptp_tx_timeout()
606 adapter->ptp_tx_skb = NULL; in igc_ptp_tx_timeout()
607 adapter->tx_hwtstamp_timeouts++; in igc_ptp_tx_timeout()
608 clear_bit_unlock(__IGC_PTP_TX_IN_PROGRESS, &adapter->state); in igc_ptp_tx_timeout()
611 netdev_warn(adapter->netdev, "Tx timestamp timeout\n"); in igc_ptp_tx_timeout()
616 bool timeout = time_is_before_jiffies(adapter->ptp_tx_start + in igc_ptp_tx_hang()
619 if (!test_bit(__IGC_PTP_TX_IN_PROGRESS, &adapter->state)) in igc_ptp_tx_hang()
627 cancel_work_sync(&adapter->ptp_tx_work); in igc_ptp_tx_hang()
633 * igc_ptp_tx_hwtstamp - utility function which checks for TX time stamp
642 struct sk_buff *skb = adapter->ptp_tx_skb; in igc_ptp_tx_hwtstamp()
644 struct igc_hw *hw = &adapter->hw; in igc_ptp_tx_hwtstamp()
655 switch (adapter->link_speed) { in igc_ptp_tx_hwtstamp()
678 adapter->ptp_tx_skb = NULL; in igc_ptp_tx_hwtstamp()
679 clear_bit_unlock(__IGC_PTP_TX_IN_PROGRESS, &adapter->state); in igc_ptp_tx_hwtstamp()
697 struct igc_hw *hw = &adapter->hw; in igc_ptp_tx_work()
700 if (!test_bit(__IGC_PTP_TX_IN_PROGRESS, &adapter->state)) in igc_ptp_tx_work()
711 * igc_ptp_set_ts_config - set hardware time stamping config
722 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) in igc_ptp_set_ts_config()
723 return -EFAULT; in igc_ptp_set_ts_config()
730 memcpy(&adapter->tstamp_config, &config, in igc_ptp_set_ts_config()
731 sizeof(adapter->tstamp_config)); in igc_ptp_set_ts_config()
733 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? in igc_ptp_set_ts_config()
734 -EFAULT : 0; in igc_ptp_set_ts_config()
738 * igc_ptp_get_ts_config - get hardware time stamping config
749 struct hwtstamp_config *config = &adapter->tstamp_config; in igc_ptp_get_ts_config()
751 return copy_to_user(ifr->ifr_data, config, sizeof(*config)) ? in igc_ptp_get_ts_config()
752 -EFAULT : 0; in igc_ptp_get_ts_config()
770 * some i225-V models could cause lockups when bringing the in igc_is_crosststamp_supported()
772 * disabling crosstimestamping support for i225-V, as it in igc_is_crosststamp_supported()
776 if (adapter->pdev->device == IGC_DEV_ID_I225_V) in igc_is_crosststamp_supported()
779 return pcie_ptm_enabled(adapter->pdev); in igc_is_crosststamp_supported()
793 struct net_device *netdev = adapter->netdev; in igc_ptm_log_error()
809 netdev_err(netdev, "PTM Error: 1588 timer adjusted during non-first PTM cycle\n"); in igc_ptm_log_error()
823 struct igc_hw *hw = &adapter->hw; in igc_phc_get_syncdevicetime()
828 ktime_get_snapshot(&adapter->snapshot); in igc_phc_get_syncdevicetime()
857 netdev_err(adapter->netdev, "Timeout reading IGC_PTM_STAT register\n"); in igc_phc_get_syncdevicetime()
867 /* The STAT register is write-1-to-clear (W1C), in igc_phc_get_syncdevicetime()
873 } while (--count); in igc_phc_get_syncdevicetime()
876 netdev_err(adapter->netdev, "Exceeded number of tries for PTM cycle\n"); in igc_phc_get_syncdevicetime()
877 return -ETIMEDOUT; in igc_phc_get_syncdevicetime()
906 adapter, &adapter->snapshot, cts); in igc_ptp_getcrosststamp()
910 * igc_ptp_init - Initialize PTP functionality
918 struct net_device *netdev = adapter->netdev; in igc_ptp_init()
919 struct igc_hw *hw = &adapter->hw; in igc_ptp_init()
922 switch (hw->mac.type) { in igc_ptp_init()
925 struct ptp_pin_desc *ppd = &adapter->sdp_config[i]; in igc_ptp_init()
927 snprintf(ppd->name, sizeof(ppd->name), "SDP%d", i); in igc_ptp_init()
928 ppd->index = i; in igc_ptp_init()
929 ppd->func = PTP_PF_NONE; in igc_ptp_init()
931 snprintf(adapter->ptp_caps.name, 16, "%pm", netdev->dev_addr); in igc_ptp_init()
932 adapter->ptp_caps.owner = THIS_MODULE; in igc_ptp_init()
933 adapter->ptp_caps.max_adj = 62499999; in igc_ptp_init()
934 adapter->ptp_caps.adjfine = igc_ptp_adjfine_i225; in igc_ptp_init()
935 adapter->ptp_caps.adjtime = igc_ptp_adjtime_i225; in igc_ptp_init()
936 adapter->ptp_caps.gettimex64 = igc_ptp_gettimex64_i225; in igc_ptp_init()
937 adapter->ptp_caps.settime64 = igc_ptp_settime_i225; in igc_ptp_init()
938 adapter->ptp_caps.enable = igc_ptp_feature_enable_i225; in igc_ptp_init()
939 adapter->ptp_caps.pps = 1; in igc_ptp_init()
940 adapter->ptp_caps.pin_config = adapter->sdp_config; in igc_ptp_init()
941 adapter->ptp_caps.n_ext_ts = IGC_N_EXTTS; in igc_ptp_init()
942 adapter->ptp_caps.n_per_out = IGC_N_PEROUT; in igc_ptp_init()
943 adapter->ptp_caps.n_pins = IGC_N_SDP; in igc_ptp_init()
944 adapter->ptp_caps.verify = igc_ptp_verify_pin; in igc_ptp_init()
949 adapter->ptp_caps.getcrosststamp = igc_ptp_getcrosststamp; in igc_ptp_init()
952 adapter->ptp_clock = NULL; in igc_ptp_init()
956 spin_lock_init(&adapter->tmreg_lock); in igc_ptp_init()
957 INIT_WORK(&adapter->ptp_tx_work, igc_ptp_tx_work); in igc_ptp_init()
959 adapter->tstamp_config.rx_filter = HWTSTAMP_FILTER_NONE; in igc_ptp_init()
960 adapter->tstamp_config.tx_type = HWTSTAMP_TX_OFF; in igc_ptp_init()
962 adapter->prev_ptp_time = ktime_to_timespec64(ktime_get_real()); in igc_ptp_init()
963 adapter->ptp_reset_start = ktime_get(); in igc_ptp_init()
965 adapter->ptp_clock = ptp_clock_register(&adapter->ptp_caps, in igc_ptp_init()
966 &adapter->pdev->dev); in igc_ptp_init()
967 if (IS_ERR(adapter->ptp_clock)) { in igc_ptp_init()
968 adapter->ptp_clock = NULL; in igc_ptp_init()
970 } else if (adapter->ptp_clock) { in igc_ptp_init()
972 adapter->ptp_flags |= IGC_PTP_ENABLED; in igc_ptp_init()
978 igc_ptp_read(adapter, &adapter->prev_ptp_time); in igc_ptp_time_save()
979 adapter->ptp_reset_start = ktime_get(); in igc_ptp_time_save()
984 struct timespec64 ts = adapter->prev_ptp_time; in igc_ptp_time_restore()
987 delta = ktime_sub(ktime_get(), adapter->ptp_reset_start); in igc_ptp_time_restore()
996 struct igc_hw *hw = &adapter->hw; in igc_ptm_stop()
1006 * igc_ptp_suspend - Disable PTP work items and prepare for suspend
1014 if (!(adapter->ptp_flags & IGC_PTP_ENABLED)) in igc_ptp_suspend()
1017 cancel_work_sync(&adapter->ptp_tx_work); in igc_ptp_suspend()
1018 dev_kfree_skb_any(adapter->ptp_tx_skb); in igc_ptp_suspend()
1019 adapter->ptp_tx_skb = NULL; in igc_ptp_suspend()
1020 clear_bit_unlock(__IGC_PTP_TX_IN_PROGRESS, &adapter->state); in igc_ptp_suspend()
1022 if (pci_device_is_present(adapter->pdev)) { in igc_ptp_suspend()
1029 * igc_ptp_stop - Disable PTP device and stop the overflow check.
1038 if (adapter->ptp_clock) { in igc_ptp_stop()
1039 ptp_clock_unregister(adapter->ptp_clock); in igc_ptp_stop()
1040 netdev_info(adapter->netdev, "PHC removed\n"); in igc_ptp_stop()
1041 adapter->ptp_flags &= ~IGC_PTP_ENABLED; in igc_ptp_stop()
1046 * igc_ptp_reset - Re-enable the adapter for PTP following a reset.
1049 * This function handles the reset work required to re-enable the PTP device.
1053 struct igc_hw *hw = &adapter->hw; in igc_ptp_reset()
1059 igc_ptp_set_timestamp_mode(adapter, &adapter->tstamp_config); in igc_ptp_reset()
1061 spin_lock_irqsave(&adapter->tmreg_lock, flags); in igc_ptp_reset()
1063 switch (adapter->hw.mac.type) { in igc_ptp_reset()
1073 (adapter->pps_sys_wrap_on ? IGC_TSICR_SYS_WRAP : 0)); in igc_ptp_reset()
1103 /* Re-initialize the timer. */ in igc_ptp_reset()
1104 if (hw->mac.type == igc_i225) { in igc_ptp_reset()
1107 timecounter_init(&adapter->tc, &adapter->cc, in igc_ptp_reset()
1111 spin_unlock_irqrestore(&adapter->tmreg_lock, flags); in igc_ptp_reset()