Lines Matching +full:tx +full:- +full:level +full:- +full:trig

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()
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()
102 ts->tv_nsec = rd32(IGC_SYSTIML); in igc_ptp_gettimex64_i225()
103 ts->tv_sec = rd32(IGC_SYSTIMH); 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()
360 int i = rq->perout.index; in igc_ptp_feature_enable_i225()
377 if (rq->perout.start.sec < safe_start.tv_sec) in igc_ptp_feature_enable_i225()
378 igc->perout[i].start.tv_sec = safe_start.tv_sec; in igc_ptp_feature_enable_i225()
380 igc->perout[i].start.tv_sec = rq->perout.start.sec; in igc_ptp_feature_enable_i225()
381 igc->perout[i].start.tv_nsec = rq->perout.start.nsec; in igc_ptp_feature_enable_i225()
382 igc->perout[i].period.tv_sec = ts.tv_sec; in igc_ptp_feature_enable_i225()
383 igc->perout[i].period.tv_nsec = ts.tv_nsec; in igc_ptp_feature_enable_i225()
384 wr32(trgttimh, (u32)igc->perout[i].start.tv_sec); in igc_ptp_feature_enable_i225()
386 wr32(trgttiml, (u32)(igc->perout[i].start.tv_nsec | in igc_ptp_feature_enable_i225()
395 spin_unlock_irqrestore(&igc->tmreg_lock, flags); in igc_ptp_feature_enable_i225()
399 spin_lock_irqsave(&igc->tmreg_lock, flags); in igc_ptp_feature_enable_i225()
405 igc->pps_sys_wrap_on = on; in igc_ptp_feature_enable_i225()
407 spin_unlock_irqrestore(&igc->tmreg_lock, flags); in igc_ptp_feature_enable_i225()
414 return -EOPNOTSUPP; in igc_ptp_feature_enable_i225()
426 return -1; in igc_ptp_verify_pin()
432 * igc_ptp_systim_to_hwtstamp - convert system time value to HW timestamp
438 * into a hwtstamp which can be used by the upper level timestamping functions.
446 switch (adapter->hw.mac.type) { in igc_ptp_systim_to_hwtstamp()
450 hwtstamps->hwtstamp = ktime_set(systim >> 32, in igc_ptp_systim_to_hwtstamp()
454 return -EINVAL; in igc_ptp_systim_to_hwtstamp()
460 * igc_ptp_rx_pktstamp - Retrieve timestamp from Rx packet buffer
462 * @buf: Pointer to start of timestamp in HW format (2 32-bit words)
481 switch (adapter->link_speed) { in igc_ptp_rx_pktstamp()
496 netdev_warn_once(adapter->netdev, "Imprecise timestamp\n"); in igc_ptp_rx_pktstamp()
505 struct igc_hw *hw = &adapter->hw; in igc_ptp_disable_rx_timestamp()
511 for (i = 0; i < adapter->num_rx_queues; i++) { in igc_ptp_disable_rx_timestamp()
524 struct igc_hw *hw = &adapter->hw; in igc_ptp_enable_rx_timestamp()
532 for (i = 0; i < adapter->num_rx_queues; i++) { in igc_ptp_enable_rx_timestamp()
553 spin_lock_irqsave(&adapter->ptp_tx_lock, flags); in igc_ptp_clear_tx_tstamp()
556 struct igc_tx_timestamp_request *tstamp = &adapter->tx_tstamp[i]; in igc_ptp_clear_tx_tstamp()
558 dev_kfree_skb_any(tstamp->skb); in igc_ptp_clear_tx_tstamp()
559 tstamp->skb = NULL; in igc_ptp_clear_tx_tstamp()
562 spin_unlock_irqrestore(&adapter->ptp_tx_lock, flags); in igc_ptp_clear_tx_tstamp()
567 struct igc_hw *hw = &adapter->hw; in igc_ptp_disable_tx_timestamp()
571 * for TX timestamping. in igc_ptp_disable_tx_timestamp()
573 for (i = 0; i < adapter->num_tx_queues; i++) { in igc_ptp_disable_tx_timestamp()
574 struct igc_ring *tx_ring = adapter->tx_ring[i]; in igc_ptp_disable_tx_timestamp()
576 clear_bit(IGC_RING_FLAG_TX_HWTSTAMP, &tx_ring->flags); in igc_ptp_disable_tx_timestamp()
579 /* Now we can clean the pending TX timestamp requests. */ in igc_ptp_disable_tx_timestamp()
587 struct igc_hw *hw = &adapter->hw; in igc_ptp_enable_tx_timestamp()
596 /* The hardware is ready to accept TX timestamp requests, in igc_ptp_enable_tx_timestamp()
599 for (i = 0; i < adapter->num_tx_queues; i++) { in igc_ptp_enable_tx_timestamp()
600 struct igc_ring *tx_ring = adapter->tx_ring[i]; in igc_ptp_enable_tx_timestamp()
602 set_bit(IGC_RING_FLAG_TX_HWTSTAMP, &tx_ring->flags); in igc_ptp_enable_tx_timestamp()
608 * igc_ptp_set_timestamp_mode - setup hardware for timestamping
617 switch (config->tx_type) { in igc_ptp_set_timestamp_mode()
625 return -ERANGE; in igc_ptp_set_timestamp_mode()
628 switch (config->rx_filter) { in igc_ptp_set_timestamp_mode()
647 config->rx_filter = HWTSTAMP_FILTER_ALL; in igc_ptp_set_timestamp_mode()
650 return -ERANGE; in igc_ptp_set_timestamp_mode()
656 /* Requires adapter->ptp_tx_lock held by caller. */
660 dev_kfree_skb_any(tstamp->skb); in igc_ptp_tx_timeout()
661 tstamp->skb = NULL; in igc_ptp_tx_timeout()
662 adapter->tx_hwtstamp_timeouts++; in igc_ptp_tx_timeout()
664 netdev_warn(adapter->netdev, "Tx timestamp timeout\n"); in igc_ptp_tx_timeout()
670 struct igc_hw *hw = &adapter->hw; in igc_ptp_tx_hang()
675 spin_lock_irqsave(&adapter->ptp_tx_lock, flags); in igc_ptp_tx_hang()
678 tstamp = &adapter->tx_tstamp[i]; in igc_ptp_tx_hang()
680 if (!tstamp->skb) in igc_ptp_tx_hang()
683 if (time_is_after_jiffies(tstamp->start + IGC_PTP_TX_TIMEOUT)) in igc_ptp_tx_hang()
697 spin_unlock_irqrestore(&adapter->ptp_tx_lock, flags); in igc_ptp_tx_hang()
707 skb = tstamp->skb; in igc_ptp_tx_reg_to_stamp()
714 switch (adapter->link_speed) { in igc_ptp_tx_reg_to_stamp()
732 tstamp->skb = NULL; in igc_ptp_tx_reg_to_stamp()
739 * igc_ptp_tx_hwtstamp - utility function which checks for TX time stamp
746 * Context: Expects adapter->ptp_tx_lock to be held by caller.
750 struct igc_hw *hw = &adapter->hw; in igc_ptp_tx_hwtstamp()
761 * missing interrupts for TX timestamping. The issue in igc_ptp_tx_hwtstamp()
791 igc_ptp_tx_reg_to_stamp(adapter, &adapter->tx_tstamp[0], regval); in igc_ptp_tx_hwtstamp()
799 struct igc_tx_timestamp_request *tstamp = &adapter->tx_tstamp[i]; in igc_ptp_tx_hwtstamp()
801 if (!(tstamp->mask & mask)) in igc_ptp_tx_hwtstamp()
804 regval = rd32(tstamp->regl); in igc_ptp_tx_hwtstamp()
805 regval |= (u64)rd32(tstamp->regh) << 32; in igc_ptp_tx_hwtstamp()
815 * Called when a TX timestamp interrupt happens to retrieve the
822 spin_lock_irqsave(&adapter->ptp_tx_lock, flags); in igc_ptp_tx_tstamp_event()
826 spin_unlock_irqrestore(&adapter->ptp_tx_lock, flags); in igc_ptp_tx_tstamp_event()
830 * igc_ptp_set_ts_config - set hardware time stamping config
841 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) in igc_ptp_set_ts_config()
842 return -EFAULT; in igc_ptp_set_ts_config()
849 memcpy(&adapter->tstamp_config, &config, in igc_ptp_set_ts_config()
850 sizeof(adapter->tstamp_config)); in igc_ptp_set_ts_config()
852 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? in igc_ptp_set_ts_config()
853 -EFAULT : 0; in igc_ptp_set_ts_config()
857 * igc_ptp_get_ts_config - get hardware time stamping config
868 struct hwtstamp_config *config = &adapter->tstamp_config; in igc_ptp_get_ts_config()
870 return copy_to_user(ifr->ifr_data, config, sizeof(*config)) ? in igc_ptp_get_ts_config()
871 -EFAULT : 0; in igc_ptp_get_ts_config()
889 * some i225-V models could cause lockups when bringing the in igc_is_crosststamp_supported()
891 * disabling crosstimestamping support for i225-V, as it in igc_is_crosststamp_supported()
895 if (adapter->pdev->device == IGC_DEV_ID_I225_V) in igc_is_crosststamp_supported()
898 return pcie_ptm_enabled(adapter->pdev); in igc_is_crosststamp_supported()
912 struct net_device *netdev = adapter->netdev; in igc_ptm_log_error()
928 netdev_err(netdev, "PTM Error: 1588 timer adjusted during non-first PTM cycle\n"); in igc_ptm_log_error()
942 struct igc_hw *hw = &adapter->hw; in igc_phc_get_syncdevicetime()
947 ktime_get_snapshot(&adapter->snapshot); in igc_phc_get_syncdevicetime()
958 * then set again the TRIG bit. in igc_phc_get_syncdevicetime()
976 netdev_err(adapter->netdev, "Timeout reading IGC_PTM_STAT register\n"); in igc_phc_get_syncdevicetime()
986 /* The STAT register is write-1-to-clear (W1C), in igc_phc_get_syncdevicetime()
992 } while (--count); in igc_phc_get_syncdevicetime()
995 netdev_err(adapter->netdev, "Exceeded number of tries for PTM cycle\n"); in igc_phc_get_syncdevicetime()
996 return -ETIMEDOUT; in igc_phc_get_syncdevicetime()
1025 adapter, &adapter->snapshot, cts); in igc_ptp_getcrosststamp()
1033 struct igc_hw *hw = &igc->hw; in igc_ptp_getcyclesx64()
1036 spin_lock_irqsave(&igc->free_timer_lock, flags); in igc_ptp_getcyclesx64()
1039 ts->tv_nsec = rd32(IGC_SYSTIML_1); in igc_ptp_getcyclesx64()
1040 ts->tv_sec = rd32(IGC_SYSTIMH_1); in igc_ptp_getcyclesx64()
1043 spin_unlock_irqrestore(&igc->free_timer_lock, flags); in igc_ptp_getcyclesx64()
1049 * igc_ptp_init - Initialize PTP functionality
1057 struct net_device *netdev = adapter->netdev; in igc_ptp_init()
1059 struct igc_hw *hw = &adapter->hw; in igc_ptp_init()
1062 tstamp = &adapter->tx_tstamp[0]; in igc_ptp_init()
1063 tstamp->mask = IGC_TSYNCTXCTL_TXTT_0; in igc_ptp_init()
1064 tstamp->regl = IGC_TXSTMPL_0; in igc_ptp_init()
1065 tstamp->regh = IGC_TXSTMPH_0; in igc_ptp_init()
1066 tstamp->flags = 0; in igc_ptp_init()
1068 tstamp = &adapter->tx_tstamp[1]; in igc_ptp_init()
1069 tstamp->mask = IGC_TSYNCTXCTL_TXTT_1; in igc_ptp_init()
1070 tstamp->regl = IGC_TXSTMPL_1; in igc_ptp_init()
1071 tstamp->regh = IGC_TXSTMPH_1; in igc_ptp_init()
1072 tstamp->flags = IGC_TX_FLAGS_TSTAMP_1; in igc_ptp_init()
1074 tstamp = &adapter->tx_tstamp[2]; in igc_ptp_init()
1075 tstamp->mask = IGC_TSYNCTXCTL_TXTT_2; in igc_ptp_init()
1076 tstamp->regl = IGC_TXSTMPL_2; in igc_ptp_init()
1077 tstamp->regh = IGC_TXSTMPH_2; in igc_ptp_init()
1078 tstamp->flags = IGC_TX_FLAGS_TSTAMP_2; in igc_ptp_init()
1080 tstamp = &adapter->tx_tstamp[3]; in igc_ptp_init()
1081 tstamp->mask = IGC_TSYNCTXCTL_TXTT_3; in igc_ptp_init()
1082 tstamp->regl = IGC_TXSTMPL_3; in igc_ptp_init()
1083 tstamp->regh = IGC_TXSTMPH_3; in igc_ptp_init()
1084 tstamp->flags = IGC_TX_FLAGS_TSTAMP_3; in igc_ptp_init()
1086 switch (hw->mac.type) { in igc_ptp_init()
1089 struct ptp_pin_desc *ppd = &adapter->sdp_config[i]; in igc_ptp_init()
1091 snprintf(ppd->name, sizeof(ppd->name), "SDP%d", i); in igc_ptp_init()
1092 ppd->index = i; in igc_ptp_init()
1093 ppd->func = PTP_PF_NONE; in igc_ptp_init()
1095 snprintf(adapter->ptp_caps.name, 16, "%pm", netdev->dev_addr); in igc_ptp_init()
1096 adapter->ptp_caps.owner = THIS_MODULE; in igc_ptp_init()
1097 adapter->ptp_caps.max_adj = 62499999; in igc_ptp_init()
1098 adapter->ptp_caps.adjfine = igc_ptp_adjfine_i225; in igc_ptp_init()
1099 adapter->ptp_caps.adjtime = igc_ptp_adjtime_i225; in igc_ptp_init()
1100 adapter->ptp_caps.gettimex64 = igc_ptp_gettimex64_i225; in igc_ptp_init()
1101 adapter->ptp_caps.getcyclesx64 = igc_ptp_getcyclesx64; in igc_ptp_init()
1102 adapter->ptp_caps.settime64 = igc_ptp_settime_i225; in igc_ptp_init()
1103 adapter->ptp_caps.enable = igc_ptp_feature_enable_i225; in igc_ptp_init()
1104 adapter->ptp_caps.pps = 1; in igc_ptp_init()
1105 adapter->ptp_caps.pin_config = adapter->sdp_config; in igc_ptp_init()
1106 adapter->ptp_caps.n_ext_ts = IGC_N_EXTTS; in igc_ptp_init()
1107 adapter->ptp_caps.n_per_out = IGC_N_PEROUT; in igc_ptp_init()
1108 adapter->ptp_caps.n_pins = IGC_N_SDP; in igc_ptp_init()
1109 adapter->ptp_caps.verify = igc_ptp_verify_pin; in igc_ptp_init()
1114 adapter->ptp_caps.getcrosststamp = igc_ptp_getcrosststamp; in igc_ptp_init()
1117 adapter->ptp_clock = NULL; in igc_ptp_init()
1121 spin_lock_init(&adapter->ptp_tx_lock); in igc_ptp_init()
1122 spin_lock_init(&adapter->free_timer_lock); in igc_ptp_init()
1123 spin_lock_init(&adapter->tmreg_lock); in igc_ptp_init()
1125 adapter->tstamp_config.rx_filter = HWTSTAMP_FILTER_NONE; in igc_ptp_init()
1126 adapter->tstamp_config.tx_type = HWTSTAMP_TX_OFF; in igc_ptp_init()
1128 adapter->prev_ptp_time = ktime_to_timespec64(ktime_get_real()); in igc_ptp_init()
1129 adapter->ptp_reset_start = ktime_get(); in igc_ptp_init()
1131 adapter->ptp_clock = ptp_clock_register(&adapter->ptp_caps, in igc_ptp_init()
1132 &adapter->pdev->dev); in igc_ptp_init()
1133 if (IS_ERR(adapter->ptp_clock)) { in igc_ptp_init()
1134 adapter->ptp_clock = NULL; in igc_ptp_init()
1136 } else if (adapter->ptp_clock) { in igc_ptp_init()
1138 adapter->ptp_flags |= IGC_PTP_ENABLED; in igc_ptp_init()
1144 igc_ptp_read(adapter, &adapter->prev_ptp_time); in igc_ptp_time_save()
1145 adapter->ptp_reset_start = ktime_get(); in igc_ptp_time_save()
1150 struct timespec64 ts = adapter->prev_ptp_time; in igc_ptp_time_restore()
1153 delta = ktime_sub(ktime_get(), adapter->ptp_reset_start); in igc_ptp_time_restore()
1162 struct igc_hw *hw = &adapter->hw; in igc_ptm_stop()
1172 * igc_ptp_suspend - Disable PTP work items and prepare for suspend
1175 * This function stops the overflow check work and PTP Tx timestamp work, and
1180 if (!(adapter->ptp_flags & IGC_PTP_ENABLED)) in igc_ptp_suspend()
1185 if (pci_device_is_present(adapter->pdev)) { in igc_ptp_suspend()
1192 * igc_ptp_stop - Disable PTP device and stop the overflow check.
1201 if (adapter->ptp_clock) { in igc_ptp_stop()
1202 ptp_clock_unregister(adapter->ptp_clock); in igc_ptp_stop()
1203 netdev_info(adapter->netdev, "PHC removed\n"); in igc_ptp_stop()
1204 adapter->ptp_flags &= ~IGC_PTP_ENABLED; in igc_ptp_stop()
1209 * igc_ptp_reset - Re-enable the adapter for PTP following a reset.
1212 * This function handles the reset work required to re-enable the PTP device.
1216 struct igc_hw *hw = &adapter->hw; in igc_ptp_reset()
1222 igc_ptp_set_timestamp_mode(adapter, &adapter->tstamp_config); in igc_ptp_reset()
1224 spin_lock_irqsave(&adapter->tmreg_lock, flags); in igc_ptp_reset()
1226 switch (adapter->hw.mac.type) { in igc_ptp_reset()
1236 (adapter->pps_sys_wrap_on ? IGC_TSICR_SYS_WRAP : 0)); in igc_ptp_reset()
1266 /* Re-initialize the timer. */ in igc_ptp_reset()
1267 if (hw->mac.type == igc_i225) { in igc_ptp_reset()
1270 timecounter_init(&adapter->tc, &adapter->cc, in igc_ptp_reset()
1274 spin_unlock_irqrestore(&adapter->tmreg_lock, flags); in igc_ptp_reset()