Lines Matching +full:per +full:- +full:board
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
28 * i40e_ptp_read - Read the PHC time from the device
29 * @pf: Board private structure
40 struct i40e_hw *hw = &pf->hw; in i40e_ptp_read()
56 * i40e_ptp_write - Write the PHC time to the device
57 * @pf: Board private structure
66 struct i40e_hw *hw = &pf->hw; in i40e_ptp_write()
77 * i40e_ptp_convert_to_hwtstamp - Convert device clock to system time
82 * the upper level timestamping functions. Since the timestamp is simply a 64-
90 hwtstamps->hwtstamp = ns_to_ktime(timestamp); in i40e_ptp_convert_to_hwtstamp()
94 * i40e_ptp_adjfreq - Adjust the PHC frequency
96 * @ppb: Parts per billion adjustment from the base
98 * Adjust the frequency of the PHC by the indicated parts per billion from the
104 struct i40e_hw *hw = &pf->hw; in i40e_ptp_adjfreq()
110 ppb = -ppb; in i40e_ptp_adjfreq()
118 adj = I40E_PTP_40GB_INCVAL - diff; in i40e_ptp_adjfreq()
130 adj *= READ_ONCE(pf->ptp_adj_mult); in i40e_ptp_adjfreq()
139 * i40e_ptp_adjtime - Adjust the PHC time
151 mutex_lock(&pf->tmreg_lock); in i40e_ptp_adjtime()
157 mutex_unlock(&pf->tmreg_lock); in i40e_ptp_adjtime()
163 * i40e_ptp_gettimex - Get the time of the PHC
176 mutex_lock(&pf->tmreg_lock); in i40e_ptp_gettimex()
178 mutex_unlock(&pf->tmreg_lock); in i40e_ptp_gettimex()
184 * i40e_ptp_settime - Set the time of the PHC
196 mutex_lock(&pf->tmreg_lock); in i40e_ptp_settime()
198 mutex_unlock(&pf->tmreg_lock); in i40e_ptp_settime()
204 * i40e_ptp_feature_enable - Enable/disable ancillary features of the PHC subsystem
215 return -EOPNOTSUPP; in i40e_ptp_feature_enable()
219 * i40e_ptp_update_latch_events - Read I40E_PRTTSYN_STAT_1 and latch events
232 struct i40e_hw *hw = &pf->hw; in i40e_ptp_get_rx_events()
237 new_latch_events = prttsyn_stat & ~pf->latch_event_flags; in i40e_ptp_get_rx_events()
250 pf->latch_events[i] = jiffies; in i40e_ptp_get_rx_events()
254 pf->latch_event_flags = prttsyn_stat; in i40e_ptp_get_rx_events()
260 * i40e_ptp_rx_hang - Detect error case when Rx timestamp registers are hung
270 struct i40e_hw *hw = &pf->hw; in i40e_ptp_rx_hang()
278 if (!(pf->flags & I40E_FLAG_PTP) || !pf->ptp_rx) in i40e_ptp_rx_hang()
281 spin_lock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hang()
293 if ((pf->latch_event_flags & BIT(i)) && in i40e_ptp_rx_hang()
294 time_is_before_jiffies(pf->latch_events[i] + HZ)) { in i40e_ptp_rx_hang()
296 pf->latch_event_flags &= ~BIT(i); in i40e_ptp_rx_hang()
301 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hang()
310 dev_dbg(&pf->pdev->dev, in i40e_ptp_rx_hang()
315 pf->rx_hwtstamp_cleared += cleared; in i40e_ptp_rx_hang()
319 * i40e_ptp_tx_hang - Detect error case when Tx timestamp register is hung
331 if (!(pf->flags & I40E_FLAG_PTP) || !pf->ptp_tx) in i40e_ptp_tx_hang()
335 if (!test_bit(__I40E_PTP_TX_IN_PROGRESS, pf->state)) in i40e_ptp_tx_hang()
342 if (time_is_before_jiffies(pf->ptp_tx_start + HZ)) { in i40e_ptp_tx_hang()
343 skb = pf->ptp_tx_skb; in i40e_ptp_tx_hang()
344 pf->ptp_tx_skb = NULL; in i40e_ptp_tx_hang()
345 clear_bit_unlock(__I40E_PTP_TX_IN_PROGRESS, pf->state); in i40e_ptp_tx_hang()
349 pf->tx_hwtstamp_timeouts++; in i40e_ptp_tx_hang()
354 * i40e_ptp_tx_hwtstamp - Utility function which returns the Tx timestamp
355 * @pf: Board private structure
364 struct sk_buff *skb = pf->ptp_tx_skb; in i40e_ptp_tx_hwtstamp()
365 struct i40e_hw *hw = &pf->hw; in i40e_ptp_tx_hwtstamp()
369 if (!(pf->flags & I40E_FLAG_PTP) || !pf->ptp_tx) in i40e_ptp_tx_hwtstamp()
373 if (!pf->ptp_tx_skb) in i40e_ptp_tx_hwtstamp()
387 pf->ptp_tx_skb = NULL; in i40e_ptp_tx_hwtstamp()
388 clear_bit_unlock(__I40E_PTP_TX_IN_PROGRESS, pf->state); in i40e_ptp_tx_hwtstamp()
396 * i40e_ptp_rx_hwtstamp - Utility function which checks for an Rx timestamp
397 * @pf: Board private structure
416 if (!(pf->flags & I40E_FLAG_PTP) || !pf->ptp_rx) in i40e_ptp_rx_hwtstamp()
419 hw = &pf->hw; in i40e_ptp_rx_hwtstamp()
421 spin_lock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hwtstamp()
428 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hwtstamp()
433 pf->latch_event_flags &= ~BIT(index); in i40e_ptp_rx_hwtstamp()
438 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hwtstamp()
446 * i40e_ptp_set_increment - Utility function to update clock increment rate
447 * @pf: Board private structure
451 * we must update the increment value per clock tick.
456 struct i40e_hw *hw = &pf->hw; in i40e_ptp_set_increment()
460 hw_link_info = &hw->phy.link_info; in i40e_ptp_set_increment()
462 i40e_aq_get_link_info(&pf->hw, true, NULL, NULL); in i40e_ptp_set_increment()
464 switch (hw_link_info->link_speed) { in i40e_ptp_set_increment()
476 dev_warn(&pf->pdev->dev, in i40e_ptp_set_increment()
502 WRITE_ONCE(pf->ptp_adj_mult, mult); in i40e_ptp_set_increment()
507 * i40e_ptp_get_ts_config - ioctl interface to read the HW timestamping
508 * @pf: Board private structure
517 struct hwtstamp_config *config = &pf->tstamp_config; in i40e_ptp_get_ts_config()
519 if (!(pf->flags & I40E_FLAG_PTP)) in i40e_ptp_get_ts_config()
520 return -EOPNOTSUPP; in i40e_ptp_get_ts_config()
522 return copy_to_user(ifr->ifr_data, config, sizeof(*config)) ? in i40e_ptp_get_ts_config()
523 -EFAULT : 0; in i40e_ptp_get_ts_config()
527 * i40e_ptp_set_timestamp_mode - setup hardware for requested timestamp mode
528 * @pf: Board private structure
541 struct i40e_hw *hw = &pf->hw; in i40e_ptp_set_timestamp_mode()
545 if (config->flags) in i40e_ptp_set_timestamp_mode()
546 return -EINVAL; in i40e_ptp_set_timestamp_mode()
548 switch (config->tx_type) { in i40e_ptp_set_timestamp_mode()
550 pf->ptp_tx = false; in i40e_ptp_set_timestamp_mode()
553 pf->ptp_tx = true; in i40e_ptp_set_timestamp_mode()
556 return -ERANGE; in i40e_ptp_set_timestamp_mode()
559 switch (config->rx_filter) { in i40e_ptp_set_timestamp_mode()
561 pf->ptp_rx = false; in i40e_ptp_set_timestamp_mode()
572 if (!(pf->hw_features & I40E_HW_PTP_L4_CAPABLE)) in i40e_ptp_set_timestamp_mode()
573 return -ERANGE; in i40e_ptp_set_timestamp_mode()
574 pf->ptp_rx = true; in i40e_ptp_set_timestamp_mode()
578 config->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; in i40e_ptp_set_timestamp_mode()
586 if (!(pf->hw_features & I40E_HW_PTP_L4_CAPABLE)) in i40e_ptp_set_timestamp_mode()
587 return -ERANGE; in i40e_ptp_set_timestamp_mode()
592 pf->ptp_rx = true; in i40e_ptp_set_timestamp_mode()
595 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE) { in i40e_ptp_set_timestamp_mode()
597 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; in i40e_ptp_set_timestamp_mode()
599 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; in i40e_ptp_set_timestamp_mode()
605 return -ERANGE; in i40e_ptp_set_timestamp_mode()
608 /* Clear out all 1588-related registers to clear and unlatch them. */ in i40e_ptp_set_timestamp_mode()
609 spin_lock_bh(&pf->ptp_rx_lock); in i40e_ptp_set_timestamp_mode()
616 pf->latch_event_flags = 0; in i40e_ptp_set_timestamp_mode()
617 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_set_timestamp_mode()
621 if (pf->ptp_tx) in i40e_ptp_set_timestamp_mode()
628 if (pf->ptp_tx) in i40e_ptp_set_timestamp_mode()
638 * ignore Rx timestamps via the pf->ptp_rx flag. in i40e_ptp_set_timestamp_mode()
651 * i40e_ptp_set_ts_config - ioctl interface to control the HW timestamping
652 * @pf: Board private structure
669 if (!(pf->flags & I40E_FLAG_PTP)) in i40e_ptp_set_ts_config()
670 return -EOPNOTSUPP; in i40e_ptp_set_ts_config()
672 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) in i40e_ptp_set_ts_config()
673 return -EFAULT; in i40e_ptp_set_ts_config()
680 pf->tstamp_config = config; in i40e_ptp_set_ts_config()
682 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? in i40e_ptp_set_ts_config()
683 -EFAULT : 0; in i40e_ptp_set_ts_config()
687 * i40e_ptp_create_clock - Create PTP clock device for userspace
688 * @pf: Board private structure
699 if (!IS_ERR_OR_NULL(pf->ptp_clock)) in i40e_ptp_create_clock()
702 strlcpy(pf->ptp_caps.name, i40e_driver_name, in i40e_ptp_create_clock()
703 sizeof(pf->ptp_caps.name) - 1); in i40e_ptp_create_clock()
704 pf->ptp_caps.owner = THIS_MODULE; in i40e_ptp_create_clock()
705 pf->ptp_caps.max_adj = 999999999; in i40e_ptp_create_clock()
706 pf->ptp_caps.n_ext_ts = 0; in i40e_ptp_create_clock()
707 pf->ptp_caps.pps = 0; in i40e_ptp_create_clock()
708 pf->ptp_caps.adjfreq = i40e_ptp_adjfreq; in i40e_ptp_create_clock()
709 pf->ptp_caps.adjtime = i40e_ptp_adjtime; in i40e_ptp_create_clock()
710 pf->ptp_caps.gettimex64 = i40e_ptp_gettimex; in i40e_ptp_create_clock()
711 pf->ptp_caps.settime64 = i40e_ptp_settime; in i40e_ptp_create_clock()
712 pf->ptp_caps.enable = i40e_ptp_feature_enable; in i40e_ptp_create_clock()
715 pf->ptp_clock = ptp_clock_register(&pf->ptp_caps, &pf->pdev->dev); in i40e_ptp_create_clock()
716 if (IS_ERR(pf->ptp_clock)) in i40e_ptp_create_clock()
717 return PTR_ERR(pf->ptp_clock); in i40e_ptp_create_clock()
723 pf->tstamp_config.rx_filter = HWTSTAMP_FILTER_NONE; in i40e_ptp_create_clock()
724 pf->tstamp_config.tx_type = HWTSTAMP_TX_OFF; in i40e_ptp_create_clock()
727 ktime_get_real_ts64(&pf->ptp_prev_hw_time); in i40e_ptp_create_clock()
728 pf->ptp_reset_start = ktime_get(); in i40e_ptp_create_clock()
734 * i40e_ptp_save_hw_time - Save the current PTP time as ptp_prev_hw_time
735 * @pf: Board private structure
737 * Read the current PTP time and save it into pf->ptp_prev_hw_time. This should
745 if (!(pf->flags & I40E_FLAG_PTP)) in i40e_ptp_save_hw_time()
748 i40e_ptp_gettimex(&pf->ptp_caps, &pf->ptp_prev_hw_time, NULL); in i40e_ptp_save_hw_time()
750 pf->ptp_reset_start = ktime_get(); in i40e_ptp_save_hw_time()
754 * i40e_ptp_restore_hw_time - Restore the ptp_prev_hw_time + delta to PTP regs
755 * @pf: Board private structure
758 * hardware time as pf->ptp_prev_hw_time. To be as accurate as possible,
767 ktime_t delta = ktime_sub(ktime_get(), pf->ptp_reset_start); in i40e_ptp_restore_hw_time()
770 timespec64_add_ns(&pf->ptp_prev_hw_time, ktime_to_ns(delta)); in i40e_ptp_restore_hw_time()
773 i40e_ptp_settime(&pf->ptp_caps, &pf->ptp_prev_hw_time); in i40e_ptp_restore_hw_time()
777 * i40e_ptp_init - Initialize the 1588 support after device probe or reset
778 * @pf: Board private structure
785 * pf->ptp_prev_hw_time to the current system time. During resets, it is
791 struct net_device *netdev = pf->vsi[pf->lan_vsi]->netdev; in i40e_ptp_init()
792 struct i40e_hw *hw = &pf->hw; in i40e_ptp_init()
796 /* Only one PF is assigned to control 1588 logic per port. Do not in i40e_ptp_init()
801 if (hw->pf_id != pf_id) { in i40e_ptp_init()
802 pf->flags &= ~I40E_FLAG_PTP; in i40e_ptp_init()
803 dev_info(&pf->pdev->dev, "%s: PTP not supported on %s\n", in i40e_ptp_init()
805 netdev->name); in i40e_ptp_init()
809 mutex_init(&pf->tmreg_lock); in i40e_ptp_init()
810 spin_lock_init(&pf->ptp_rx_lock); in i40e_ptp_init()
815 pf->ptp_clock = NULL; in i40e_ptp_init()
816 dev_err(&pf->pdev->dev, "%s: ptp_clock_register failed\n", in i40e_ptp_init()
818 } else if (pf->ptp_clock) { in i40e_ptp_init()
821 if (pf->hw.debug_mask & I40E_DEBUG_LAN) in i40e_ptp_init()
822 dev_info(&pf->pdev->dev, "PHC enabled\n"); in i40e_ptp_init()
823 pf->flags |= I40E_FLAG_PTP; in i40e_ptp_init()
833 /* Set the increment value per clock tick. */ in i40e_ptp_init()
837 i40e_ptp_set_timestamp_mode(pf, &pf->tstamp_config); in i40e_ptp_init()
845 * i40e_ptp_stop - Disable the driver/hardware support and unregister the PHC
846 * @pf: Board private structure
853 pf->flags &= ~I40E_FLAG_PTP; in i40e_ptp_stop()
854 pf->ptp_tx = false; in i40e_ptp_stop()
855 pf->ptp_rx = false; in i40e_ptp_stop()
857 if (pf->ptp_tx_skb) { in i40e_ptp_stop()
858 struct sk_buff *skb = pf->ptp_tx_skb; in i40e_ptp_stop()
860 pf->ptp_tx_skb = NULL; in i40e_ptp_stop()
861 clear_bit_unlock(__I40E_PTP_TX_IN_PROGRESS, pf->state); in i40e_ptp_stop()
865 if (pf->ptp_clock) { in i40e_ptp_stop()
866 ptp_clock_unregister(pf->ptp_clock); in i40e_ptp_stop()
867 pf->ptp_clock = NULL; in i40e_ptp_stop()
868 dev_info(&pf->pdev->dev, "%s: removed PHC on %s\n", __func__, in i40e_ptp_stop()
869 pf->vsi[pf->lan_vsi]->netdev->name); in i40e_ptp_stop()