Lines Matching +full:sub +full:- +full:sampled
1 // SPDX-License-Identifier: GPL-2.0
116 return -EINVAL; in ice_ptp_set_sma_config_e810t()
121 return -EINVAL; in ice_ptp_set_sma_config_e810t()
193 struct ice_hw *hw = &pf->hw; in ice_ptp_set_sma_e810t()
197 return -EOPNOTSUPP; in ice_ptp_set_sma_e810t()
237 return -EOPNOTSUPP; in ice_verify_pin_e810t()
245 return -EOPNOTSUPP; in ice_verify_pin_e810t()
249 return -EOPNOTSUPP; in ice_verify_pin_e810t()
252 return -EOPNOTSUPP; in ice_verify_pin_e810t()
259 * ice_set_tx_tstamp - Enable or disable Tx timestamping
275 if (!vsi->tx_rings[i]) in ice_set_tx_tstamp()
277 vsi->tx_rings[i]->ptp_tx = on; in ice_set_tx_tstamp()
281 val = rd32(&pf->hw, PFINT_OICR_ENA); in ice_set_tx_tstamp()
286 wr32(&pf->hw, PFINT_OICR_ENA, val); in ice_set_tx_tstamp()
288 pf->ptp.tstamp_config.tx_type = on ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF; in ice_set_tx_tstamp()
292 * ice_set_rx_tstamp - Enable or disable Rx timestamping
307 if (!vsi->rx_rings[i]) in ice_set_rx_tstamp()
309 vsi->rx_rings[i]->ptp_rx = on; in ice_set_rx_tstamp()
312 pf->ptp.tstamp_config.rx_filter = on ? HWTSTAMP_FILTER_ALL : in ice_set_rx_tstamp()
317 * ice_ptp_cfg_timestamp - Configure timestamp for init/deinit
331 * ice_get_ptp_clock_index - Get the PTP clock index
341 * Returns: the index of the PTP clock associated with this device, or -1 if
348 struct ice_hw *hw = &pf->hw; in ice_get_ptp_clock_index()
354 if (pf->ptp.clock) in ice_get_ptp_clock_index()
355 return ptp_clock_index(pf->ptp.clock); in ice_get_ptp_clock_index()
357 tmr_idx = hw->func_caps.ts_func_info.tmr_index_assoc; in ice_get_ptp_clock_index()
366 err, ice_aq_str(hw->adminq.sq_last_status)); in ice_get_ptp_clock_index()
367 return -1; in ice_get_ptp_clock_index()
375 return -1; in ice_get_ptp_clock_index()
381 * ice_set_ptp_clock_index - Set the PTP clock index
394 struct ice_hw *hw = &pf->hw; in ice_set_ptp_clock_index()
399 if (!pf->ptp.clock) in ice_set_ptp_clock_index()
402 tmr_idx = hw->func_caps.ts_func_info.tmr_index_assoc; in ice_set_ptp_clock_index()
408 value = (u32)ptp_clock_index(pf->ptp.clock); in ice_set_ptp_clock_index()
418 err, ice_aq_str(hw->adminq.sq_last_status)); in ice_set_ptp_clock_index()
423 * ice_clear_ptp_clock_index - Clear the PTP clock index
434 struct ice_hw *hw = &pf->hw; in ice_clear_ptp_clock_index()
439 if (!hw->func_caps.ts_func_info.src_tmr_owned) in ice_clear_ptp_clock_index()
442 tmr_idx = hw->func_caps.ts_func_info.tmr_index_assoc; in ice_clear_ptp_clock_index()
451 err, ice_aq_str(hw->adminq.sq_last_status)); in ice_clear_ptp_clock_index()
456 * ice_ptp_read_src_clk_reg - Read the source clock register
464 struct ice_hw *hw = &pf->hw; in ice_ptp_read_src_clk_reg()
494 * ice_ptp_extend_32b_ts - Convert a 32b nanoseconds timestamp to 64b
501 * 8 bits are sub-nanoseconds and generally discarded.
542 delta = (in_tstamp - phc_time_lo); in ice_ptp_extend_32b_ts()
551 delta = (phc_time_lo - in_tstamp); in ice_ptp_extend_32b_ts()
552 ns = cached_phc_time - delta; in ice_ptp_extend_32b_ts()
561 * ice_ptp_extend_40b_ts - Convert a 40b timestamp to 64b nanoseconds
566 * nanoseconds, 7 bits of sub-nanoseconds, and a valid bit.
568 * *--------------------------------------------------------------*
569 * | 32 bits of nanoseconds | 7 high bits of sub ns underflow | v |
570 * *--------------------------------------------------------------*
573 * 7 bits are a capture of the upper 7 bits of the sub-nanosecond underflow,
592 discard_time = pf->ptp.cached_phc_jiffies + msecs_to_jiffies(2000); in ice_ptp_extend_40b_ts()
594 pf->ptp.tx_hwtstamp_discarded++; in ice_ptp_extend_40b_ts()
598 return ice_ptp_extend_32b_ts(pf->ptp.cached_phc_time, in ice_ptp_extend_40b_ts()
603 * ice_ptp_is_tx_tracker_up - Check if Tx tracker is ready for new timestamps
609 * Assumes the tx->lock spinlock is already held.
614 lockdep_assert_held(&tx->lock); in ice_ptp_is_tx_tracker_up()
616 return tx->init && !tx->calibrating; in ice_ptp_is_tx_tracker_up()
620 * ice_ptp_process_tx_tstamp - Process Tx timestamps for a port
644 * removed. A timestamp index will never be re-used until the in_use bit for
648 * right away but we will notice it at the end when we re-queue the task.
651 * interrupt for that timestamp should re-trigger this function once
677 if (!tx->init) in ice_ptp_process_tx_tstamp()
682 hw = &pf->hw; in ice_ptp_process_tx_tstamp()
685 err = ice_get_phy_tx_tstamp_ready(hw, tx->block, &tstamp_ready); in ice_ptp_process_tx_tstamp()
690 link_up = ptp_port->link_up; in ice_ptp_process_tx_tstamp()
692 for_each_set_bit(idx, tx->in_use, tx->len) { in ice_ptp_process_tx_tstamp()
694 u8 phy_idx = idx + tx->offset; in ice_ptp_process_tx_tstamp()
700 if (time_is_before_jiffies(tx->tstamps[idx].start + 2 * HZ)) { in ice_ptp_process_tx_tstamp()
704 pf->ptp.tx_hwtstamp_timeouts++; in ice_ptp_process_tx_tstamp()
722 ice_trace(tx_tstamp_fw_req, tx->tstamps[idx].skb, idx); in ice_ptp_process_tx_tstamp()
724 err = ice_read_phy_tstamp(hw, tx->block, phy_idx, &raw_tstamp); in ice_ptp_process_tx_tstamp()
728 ice_trace(tx_tstamp_fw_done, tx->tstamps[idx].skb, idx); in ice_ptp_process_tx_tstamp()
735 if (!drop_ts && tx->verify_cached && in ice_ptp_process_tx_tstamp()
736 raw_tstamp == tx->tstamps[idx].cached_tstamp) in ice_ptp_process_tx_tstamp()
744 spin_lock(&tx->lock); in ice_ptp_process_tx_tstamp()
745 if (tx->verify_cached && raw_tstamp) in ice_ptp_process_tx_tstamp()
746 tx->tstamps[idx].cached_tstamp = raw_tstamp; in ice_ptp_process_tx_tstamp()
747 clear_bit(idx, tx->in_use); in ice_ptp_process_tx_tstamp()
748 skb = tx->tstamps[idx].skb; in ice_ptp_process_tx_tstamp()
749 tx->tstamps[idx].skb = NULL; in ice_ptp_process_tx_tstamp()
750 if (test_and_clear_bit(idx, tx->stale)) in ice_ptp_process_tx_tstamp()
752 spin_unlock(&tx->lock); in ice_ptp_process_tx_tstamp()
778 * ice_ptp_tx_tstamp - Process Tx timestamps for this function.
788 if (!tx->init) in ice_ptp_tx_tstamp()
795 spin_lock(&tx->lock); in ice_ptp_tx_tstamp()
796 more_timestamps = tx->init && !bitmap_empty(tx->in_use, tx->len); in ice_ptp_tx_tstamp()
797 spin_unlock(&tx->lock); in ice_ptp_tx_tstamp()
806 * ice_ptp_alloc_tx_tracker - Initialize tracking for Tx timestamps
818 tstamps = kcalloc(tx->len, sizeof(*tstamps), GFP_KERNEL); in ice_ptp_alloc_tx_tracker()
819 in_use = bitmap_zalloc(tx->len, GFP_KERNEL); in ice_ptp_alloc_tx_tracker()
820 stale = bitmap_zalloc(tx->len, GFP_KERNEL); in ice_ptp_alloc_tx_tracker()
827 return -ENOMEM; in ice_ptp_alloc_tx_tracker()
830 tx->tstamps = tstamps; in ice_ptp_alloc_tx_tracker()
831 tx->in_use = in_use; in ice_ptp_alloc_tx_tracker()
832 tx->stale = stale; in ice_ptp_alloc_tx_tracker()
833 tx->init = 1; in ice_ptp_alloc_tx_tracker()
835 spin_lock_init(&tx->lock); in ice_ptp_alloc_tx_tracker()
841 * ice_ptp_flush_tx_tracker - Flush any remaining timestamps from the tracker
850 struct ice_hw *hw = &pf->hw; in ice_ptp_flush_tx_tracker()
855 err = ice_get_phy_tx_tstamp_ready(hw, tx->block, &tstamp_ready); in ice_ptp_flush_tx_tracker()
858 tx->block, err); in ice_ptp_flush_tx_tracker()
866 for_each_set_bit(idx, tx->in_use, tx->len) { in ice_ptp_flush_tx_tracker()
867 u8 phy_idx = idx + tx->offset; in ice_ptp_flush_tx_tracker()
871 if (!hw->reset_ongoing && (tstamp_ready & BIT_ULL(phy_idx))) in ice_ptp_flush_tx_tracker()
872 ice_clear_phy_tstamp(hw, tx->block, phy_idx); in ice_ptp_flush_tx_tracker()
874 spin_lock(&tx->lock); in ice_ptp_flush_tx_tracker()
875 skb = tx->tstamps[idx].skb; in ice_ptp_flush_tx_tracker()
876 tx->tstamps[idx].skb = NULL; in ice_ptp_flush_tx_tracker()
877 clear_bit(idx, tx->in_use); in ice_ptp_flush_tx_tracker()
878 clear_bit(idx, tx->stale); in ice_ptp_flush_tx_tracker()
879 spin_unlock(&tx->lock); in ice_ptp_flush_tx_tracker()
882 pf->ptp.tx_hwtstamp_flushed++; in ice_ptp_flush_tx_tracker()
890 * ice_ptp_mark_tx_tracker_stale - Mark unfinished timestamps as stale
903 spin_lock(&tx->lock); in ice_ptp_mark_tx_tracker_stale()
904 bitmap_or(tx->stale, tx->stale, tx->in_use, tx->len); in ice_ptp_mark_tx_tracker_stale()
905 spin_unlock(&tx->lock); in ice_ptp_mark_tx_tracker_stale()
909 * ice_ptp_release_tx_tracker - Release allocated memory for Tx tracker
918 spin_lock(&tx->lock); in ice_ptp_release_tx_tracker()
919 tx->init = 0; in ice_ptp_release_tx_tracker()
920 spin_unlock(&tx->lock); in ice_ptp_release_tx_tracker()
923 synchronize_irq(pf->oicr_irq.virq); in ice_ptp_release_tx_tracker()
927 kfree(tx->tstamps); in ice_ptp_release_tx_tracker()
928 tx->tstamps = NULL; in ice_ptp_release_tx_tracker()
930 bitmap_free(tx->in_use); in ice_ptp_release_tx_tracker()
931 tx->in_use = NULL; in ice_ptp_release_tx_tracker()
933 bitmap_free(tx->stale); in ice_ptp_release_tx_tracker()
934 tx->stale = NULL; in ice_ptp_release_tx_tracker()
936 tx->len = 0; in ice_ptp_release_tx_tracker()
940 * ice_ptp_init_tx_e822 - Initialize tracking for Tx timestamps
953 tx->block = port / ICE_PORTS_PER_QUAD; in ice_ptp_init_tx_e822()
954 tx->offset = (port % ICE_PORTS_PER_QUAD) * INDEX_PER_PORT_E822; in ice_ptp_init_tx_e822()
955 tx->len = INDEX_PER_PORT_E822; in ice_ptp_init_tx_e822()
956 tx->verify_cached = 0; in ice_ptp_init_tx_e822()
962 * ice_ptp_init_tx_e810 - Initialize tracking for Tx timestamps
972 tx->block = pf->hw.port_info->lport; in ice_ptp_init_tx_e810()
973 tx->offset = 0; in ice_ptp_init_tx_e810()
974 tx->len = INDEX_PER_PORT_E810; in ice_ptp_init_tx_e810()
979 tx->verify_cached = 1; in ice_ptp_init_tx_e810()
985 * ice_ptp_update_cached_phctime - Update the cached PHC time values
998 * * 0 - OK, successfully updated
999 * * -EAGAIN - PF was busy, need to reschedule the update
1008 update_before = pf->ptp.cached_phc_jiffies + msecs_to_jiffies(2000); in ice_ptp_update_cached_phctime()
1009 if (pf->ptp.cached_phc_time && in ice_ptp_update_cached_phctime()
1011 unsigned long time_taken = jiffies - pf->ptp.cached_phc_jiffies; in ice_ptp_update_cached_phctime()
1015 pf->ptp.late_cached_phc_updates++; in ice_ptp_update_cached_phctime()
1022 WRITE_ONCE(pf->ptp.cached_phc_time, systime); in ice_ptp_update_cached_phctime()
1023 WRITE_ONCE(pf->ptp.cached_phc_jiffies, jiffies); in ice_ptp_update_cached_phctime()
1025 if (test_and_set_bit(ICE_CFG_BUSY, pf->state)) in ice_ptp_update_cached_phctime()
1026 return -EAGAIN; in ice_ptp_update_cached_phctime()
1029 struct ice_vsi *vsi = pf->vsi[i]; in ice_ptp_update_cached_phctime()
1035 if (vsi->type != ICE_VSI_PF) in ice_ptp_update_cached_phctime()
1039 if (!vsi->rx_rings[j]) in ice_ptp_update_cached_phctime()
1041 WRITE_ONCE(vsi->rx_rings[j]->cached_phctime, systime); in ice_ptp_update_cached_phctime()
1044 clear_bit(ICE_CFG_BUSY, pf->state); in ice_ptp_update_cached_phctime()
1050 * ice_ptp_reset_cached_phctime - Reset cached PHC time after an update
1080 kthread_queue_delayed_work(pf->ptp.kworker, &pf->ptp.work, in ice_ptp_reset_cached_phctime()
1089 ice_ptp_mark_tx_tracker_stale(&pf->ptp.port.tx); in ice_ptp_reset_cached_phctime()
1093 * ice_ptp_read_time - Read the time from the device
1113 * ice_ptp_write_init - Set PHC time to provided value
1122 struct ice_hw *hw = &pf->hw; in ice_ptp_write_init()
1128 * ice_ptp_write_adj - Adjust PHC clock time atomically
1137 struct ice_hw *hw = &pf->hw; in ice_ptp_write_adj()
1143 * ice_base_incval - Get base timer increment value
1153 struct ice_hw *hw = &pf->hw; in ice_base_incval()
1170 * ice_ptp_check_tx_fifo - Check whether Tx FIFO is in an OK state
1175 int quad = port->port_num / ICE_PORTS_PER_QUAD; in ice_ptp_check_tx_fifo()
1176 int offs = port->port_num % ICE_PORTS_PER_QUAD; in ice_ptp_check_tx_fifo()
1183 hw = &pf->hw; in ice_ptp_check_tx_fifo()
1185 if (port->tx_fifo_busy_cnt == FIFO_OK) in ice_ptp_check_tx_fifo()
1198 port->port_num, err); in ice_ptp_check_tx_fifo()
1208 port->tx_fifo_busy_cnt = FIFO_OK; in ice_ptp_check_tx_fifo()
1212 port->tx_fifo_busy_cnt++; in ice_ptp_check_tx_fifo()
1215 port->tx_fifo_busy_cnt, port->port_num); in ice_ptp_check_tx_fifo()
1217 if (port->tx_fifo_busy_cnt == ICE_PTP_FIFO_NUM_CHECKS) { in ice_ptp_check_tx_fifo()
1220 port->port_num, quad); in ice_ptp_check_tx_fifo()
1222 port->tx_fifo_busy_cnt = FIFO_OK; in ice_ptp_check_tx_fifo()
1226 return -EAGAIN; in ice_ptp_check_tx_fifo()
1230 * ice_ptp_wait_for_offsets - Check for valid Tx and Rx offsets
1254 hw = &pf->hw; in ice_ptp_wait_for_offsets()
1256 if (ice_is_reset_in_progress(pf->state)) { in ice_ptp_wait_for_offsets()
1258 kthread_queue_delayed_work(pf->ptp.kworker, in ice_ptp_wait_for_offsets()
1259 &port->ov_work, in ice_ptp_wait_for_offsets()
1266 tx_err = ice_phy_cfg_tx_offset_e822(hw, port->port_num); in ice_ptp_wait_for_offsets()
1267 rx_err = ice_phy_cfg_rx_offset_e822(hw, port->port_num); in ice_ptp_wait_for_offsets()
1270 kthread_queue_delayed_work(pf->ptp.kworker, in ice_ptp_wait_for_offsets()
1271 &port->ov_work, in ice_ptp_wait_for_offsets()
1278 * ice_ptp_port_phy_stop - Stop timestamping for a PHY port
1285 u8 port = ptp_port->port_num; in ice_ptp_port_phy_stop()
1286 struct ice_hw *hw = &pf->hw; in ice_ptp_port_phy_stop()
1292 mutex_lock(&ptp_port->ps_lock); in ice_ptp_port_phy_stop()
1294 kthread_cancel_delayed_work_sync(&ptp_port->ov_work); in ice_ptp_port_phy_stop()
1301 mutex_unlock(&ptp_port->ps_lock); in ice_ptp_port_phy_stop()
1307 * ice_ptp_port_phy_restart - (Re)start and calibrate PHY timestamping
1318 u8 port = ptp_port->port_num; in ice_ptp_port_phy_restart()
1319 struct ice_hw *hw = &pf->hw; in ice_ptp_port_phy_restart()
1325 if (!ptp_port->link_up) in ice_ptp_port_phy_restart()
1328 mutex_lock(&ptp_port->ps_lock); in ice_ptp_port_phy_restart()
1330 kthread_cancel_delayed_work_sync(&ptp_port->ov_work); in ice_ptp_port_phy_restart()
1333 spin_lock(&ptp_port->tx.lock); in ice_ptp_port_phy_restart()
1334 ptp_port->tx.calibrating = true; in ice_ptp_port_phy_restart()
1335 spin_unlock(&ptp_port->tx.lock); in ice_ptp_port_phy_restart()
1336 ptp_port->tx_fifo_busy_cnt = 0; in ice_ptp_port_phy_restart()
1344 spin_lock(&ptp_port->tx.lock); in ice_ptp_port_phy_restart()
1345 ptp_port->tx.calibrating = false; in ice_ptp_port_phy_restart()
1346 spin_unlock(&ptp_port->tx.lock); in ice_ptp_port_phy_restart()
1348 kthread_queue_delayed_work(pf->ptp.kworker, &ptp_port->ov_work, 0); in ice_ptp_port_phy_restart()
1355 mutex_unlock(&ptp_port->ps_lock); in ice_ptp_port_phy_restart()
1361 * ice_ptp_link_change - Reconfigure PTP after link status change
1370 if (!test_bit(ICE_FLAG_PTP, pf->flags)) in ice_ptp_link_change()
1376 ptp_port = &pf->ptp.port; in ice_ptp_link_change()
1377 if (WARN_ON_ONCE(ptp_port->port_num != port)) in ice_ptp_link_change()
1381 ptp_port->link_up = linkup; in ice_ptp_link_change()
1384 if (ice_is_e810(&pf->hw)) in ice_ptp_link_change()
1391 * ice_ptp_tx_ena_intr - Enable or disable the Tx timestamp interrupt
1400 struct ice_hw *hw = &pf->hw; in ice_ptp_tx_ena_intr()
1435 * ice_ptp_reset_phy_timestamping - Reset PHY timestamping block
1440 ice_ptp_port_phy_restart(&pf->ptp.port); in ice_ptp_reset_phy_timestamping()
1444 * ice_ptp_adjfine - Adjust clock increment rate
1446 * @scaled_ppm: Parts per million with 16-bit fractional field
1454 struct ice_hw *hw = &pf->hw; in ice_ptp_adjfine()
1463 return -EIO; in ice_ptp_adjfine()
1470 * ice_ptp_extts_event - Process PTP external clock event
1476 struct ice_hw *hw = &pf->hw; in ice_ptp_extts_event()
1480 tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned; in ice_ptp_extts_event()
1482 * GLTSYN_EVNT_L: 32 LSB of sampled time event in ice_ptp_extts_event()
1483 * GLTSYN_EVNT_H: 32 MSB of sampled time event in ice_ptp_extts_event()
1488 if (pf->ptp.ext_ts_irq & (1 << chan)) { in ice_ptp_extts_event()
1496 ptp_clock_event(pf->ptp.clock, &event); in ice_ptp_extts_event()
1497 pf->ptp.ext_ts_irq &= ~(1 << chan); in ice_ptp_extts_event()
1503 * ice_ptp_cfg_extts - Configure EXTTS pin and channel
1506 * @chan: GPIO channel (0-3)
1515 struct ice_hw *hw = &pf->hw; in ice_ptp_cfg_extts()
1518 if (chan > (unsigned int)pf->ptp.info.n_ext_ts) in ice_ptp_cfg_extts()
1519 return -EINVAL; in ice_ptp_cfg_extts()
1521 tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned; in ice_ptp_cfg_extts()
1540 * 0x1 is input sampled by EVENT register(channel) in ice_ptp_cfg_extts()
1546 pf->ptp.ext_ts_chan |= (1 << chan); in ice_ptp_cfg_extts()
1551 pf->ptp.ext_ts_chan &= ~(1 << chan); in ice_ptp_cfg_extts()
1552 if (!pf->ptp.ext_ts_chan) in ice_ptp_cfg_extts()
1564 * ice_ptp_cfg_clkout - Configure clock to generate periodic wave
1566 * @chan: GPIO channel (0-3)
1577 struct ice_hw *hw = &pf->hw; in ice_ptp_cfg_clkout()
1581 tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned; in ice_ptp_cfg_clkout()
1589 if (!config || !config->ena) { in ice_ptp_cfg_clkout()
1595 gpio_pin = pf->ptp.perout_channels[chan].gpio_pin; in ice_ptp_cfg_clkout()
1600 memset(&pf->ptp.perout_channels[chan], 0, in ice_ptp_cfg_clkout()
1605 period = config->period; in ice_ptp_cfg_clkout()
1606 start_time = config->start_time; in ice_ptp_cfg_clkout()
1608 gpio_pin = config->gpio_pin; in ice_ptp_cfg_clkout()
1636 start_time = div64_u64(current_time + NSEC_PER_SEC - 1, in ice_ptp_cfg_clkout()
1640 start_time -= E810_OUT_PROP_DELAY_NS; in ice_ptp_cfg_clkout()
1642 start_time -= ice_e822_pps_delay(ice_e822_time_ref(hw)); in ice_ptp_cfg_clkout()
1660 memcpy(&pf->ptp.perout_channels[chan], config, in ice_ptp_cfg_clkout()
1662 pf->ptp.perout_channels[chan].start_time = phase; in ice_ptp_cfg_clkout()
1668 return -EFAULT; in ice_ptp_cfg_clkout()
1672 * ice_ptp_disable_all_clkout - Disable all currently configured outputs
1677 * re-enable the clocks again.
1683 for (i = 0; i < pf->ptp.info.n_per_out; i++) in ice_ptp_disable_all_clkout()
1684 if (pf->ptp.perout_channels[i].ena) in ice_ptp_disable_all_clkout()
1689 * ice_ptp_enable_all_clkout - Enable all configured periodic clock outputs
1700 for (i = 0; i < pf->ptp.info.n_per_out; i++) in ice_ptp_enable_all_clkout()
1701 if (pf->ptp.perout_channels[i].ena) in ice_ptp_enable_all_clkout()
1702 ice_ptp_cfg_clkout(pf, i, &pf->ptp.perout_channels[i], in ice_ptp_enable_all_clkout()
1707 * ice_ptp_gpio_enable_e810 - Enable/disable ancillary features of PHC
1726 switch (rq->type) { in ice_ptp_gpio_enable_e810()
1728 chan = rq->perout.index; in ice_ptp_gpio_enable_e810()
1735 return -1; in ice_ptp_gpio_enable_e810()
1736 } else if (ice_is_e810t(&pf->hw)) { in ice_ptp_gpio_enable_e810()
1747 clk_cfg.period = ((rq->perout.period.sec * NSEC_PER_SEC) + in ice_ptp_gpio_enable_e810()
1748 rq->perout.period.nsec); in ice_ptp_gpio_enable_e810()
1749 clk_cfg.start_time = ((rq->perout.start.sec * NSEC_PER_SEC) + in ice_ptp_gpio_enable_e810()
1750 rq->perout.start.nsec); in ice_ptp_gpio_enable_e810()
1756 chan = rq->extts.index; in ice_ptp_gpio_enable_e810()
1762 } else if (ice_is_e810t(&pf->hw)) { in ice_ptp_gpio_enable_e810()
1772 rq->extts.flags); in ice_ptp_gpio_enable_e810()
1775 return -EOPNOTSUPP; in ice_ptp_gpio_enable_e810()
1782 * ice_ptp_gpio_enable_e823 - Enable/disable ancillary features of PHC
1794 switch (rq->type) { in ice_ptp_gpio_enable_e823()
1803 err = ice_ptp_cfg_extts(pf, !!on, rq->extts.index, in ice_ptp_gpio_enable_e823()
1804 TIME_SYNC_PIN_INDEX, rq->extts.flags); in ice_ptp_gpio_enable_e823()
1807 return -EOPNOTSUPP; in ice_ptp_gpio_enable_e823()
1814 * ice_ptp_gettimex64 - Get the time of the clock
1828 struct ice_hw *hw = &pf->hw; in ice_ptp_gettimex64()
1832 return -EBUSY; in ice_ptp_gettimex64()
1842 * ice_ptp_settime64 - Set the time of the clock
1854 struct ice_hw *hw = &pf->hw; in ice_ptp_settime64()
1860 if (pf->ptp.port.link_up) in ice_ptp_settime64()
1861 ice_ptp_port_phy_stop(&pf->ptp.port); in ice_ptp_settime64()
1864 err = -EBUSY; in ice_ptp_settime64()
1880 /* Recalibrate and re-enable timestamp block */ in ice_ptp_settime64()
1881 if (pf->ptp.port.link_up) in ice_ptp_settime64()
1882 ice_ptp_port_phy_restart(&pf->ptp.port); in ice_ptp_settime64()
1893 * ice_ptp_adjtime_nonatomic - Do a non-atomic clock adjustment
1912 * ice_ptp_adjtime - Adjust the time of the clock by the indicated delta
1919 struct ice_hw *hw = &pf->hw; in ice_ptp_adjtime()
1925 /* Hardware only supports atomic adjustments using signed 32-bit in ice_ptp_adjtime()
1927 * a non-atomic get->adjust->set flow. in ice_ptp_adjtime()
1930 dev_dbg(dev, "delta = %lld, adjtime non-atomic\n", delta); in ice_ptp_adjtime()
1936 return -EBUSY; in ice_ptp_adjtime()
1961 * ice_ptp_get_syncdevicetime - Get the cross time stamp info
1975 struct ice_hw *hw = &pf->hw; in ice_ptp_get_syncdevicetime()
1980 hh_lock = rd32(hw, PFHH_SEM + (PFTSYN_SEM_BYTES * hw->pf_id)); in ice_ptp_get_syncdevicetime()
1983 return -EFAULT; in ice_ptp_get_syncdevicetime()
2003 tmr_idx = hw->func_caps.ts_func_info.tmr_index_assoc; in ice_ptp_get_syncdevicetime()
2018 hh_lock = rd32(hw, PFHH_SEM + (PFTSYN_SEM_BYTES * hw->pf_id)); in ice_ptp_get_syncdevicetime()
2020 wr32(hw, PFHH_SEM + (PFTSYN_SEM_BYTES * hw->pf_id), hh_lock); in ice_ptp_get_syncdevicetime()
2023 return -ETIMEDOUT; in ice_ptp_get_syncdevicetime()
2029 * ice_ptp_getcrosststamp_e822 - Capture a device cross timestamp
2055 * ice_ptp_get_ts_config - ioctl interface to read the timestamping config
2065 if (!test_bit(ICE_FLAG_PTP, pf->flags)) in ice_ptp_get_ts_config()
2066 return -EIO; in ice_ptp_get_ts_config()
2068 config = &pf->ptp.tstamp_config; in ice_ptp_get_ts_config()
2070 return copy_to_user(ifr->ifr_data, config, sizeof(*config)) ? in ice_ptp_get_ts_config()
2071 -EFAULT : 0; in ice_ptp_get_ts_config()
2075 * ice_ptp_set_timestamp_mode - Setup driver for requested timestamp mode
2082 switch (config->tx_type) { in ice_ptp_set_timestamp_mode()
2090 return -ERANGE; in ice_ptp_set_timestamp_mode()
2093 switch (config->rx_filter) { in ice_ptp_set_timestamp_mode()
2114 return -ERANGE; in ice_ptp_set_timestamp_mode()
2121 * ice_ptp_set_ts_config - ioctl interface to control the timestamping
2132 if (!test_bit(ICE_FLAG_PTP, pf->flags)) in ice_ptp_set_ts_config()
2133 return -EAGAIN; in ice_ptp_set_ts_config()
2135 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) in ice_ptp_set_ts_config()
2136 return -EFAULT; in ice_ptp_set_ts_config()
2143 config = pf->ptp.tstamp_config; in ice_ptp_set_ts_config()
2145 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? in ice_ptp_set_ts_config()
2146 -EFAULT : 0; in ice_ptp_set_ts_config()
2150 * ice_ptp_rx_hwtstamp - Check for an Rx timestamp
2166 if (!(rx_desc->wb.time_stamp_low & ICE_PTP_TS_VALID)) in ice_ptp_rx_hwtstamp()
2169 cached_time = READ_ONCE(rx_ring->cached_phctime); in ice_ptp_rx_hwtstamp()
2175 /* Use ice_ptp_extend_32b_ts directly, using the ring-specific cached in ice_ptp_rx_hwtstamp()
2181 ts_high = le32_to_cpu(rx_desc->wb.flex_ts.ts_high); in ice_ptp_rx_hwtstamp()
2186 hwtstamps->hwtstamp = ns_to_ktime(ts_ns); in ice_ptp_rx_hwtstamp()
2190 * ice_ptp_disable_sma_pins_e810t - Disable E810-T SMA pins
2195 * indications of pin support when we fail to setup the E810-T SMA control
2203 dev_warn(dev, "Failed to configure E810-T SMA pin control\n"); in ice_ptp_disable_sma_pins_e810t()
2205 info->enable = NULL; in ice_ptp_disable_sma_pins_e810t()
2206 info->verify = NULL; in ice_ptp_disable_sma_pins_e810t()
2207 info->n_pins = 0; in ice_ptp_disable_sma_pins_e810t()
2208 info->n_ext_ts = 0; in ice_ptp_disable_sma_pins_e810t()
2209 info->n_per_out = 0; in ice_ptp_disable_sma_pins_e810t()
2213 * ice_ptp_setup_sma_pins_e810t - Setup the SMA pins
2228 info->pin_config = devm_kcalloc(dev, info->n_pins, in ice_ptp_setup_sma_pins_e810t()
2229 sizeof(*info->pin_config), GFP_KERNEL); in ice_ptp_setup_sma_pins_e810t()
2230 if (!info->pin_config) { in ice_ptp_setup_sma_pins_e810t()
2236 err = ice_get_sma_config_e810t(&pf->hw, info->pin_config); in ice_ptp_setup_sma_pins_e810t()
2242 * ice_ptp_setup_pins_e810 - Setup PTP pins in sysfs
2250 info->n_ext_ts = N_EXT_TS_E810; in ice_ptp_setup_pins_e810()
2251 info->n_per_out = N_PER_OUT_E810T; in ice_ptp_setup_pins_e810()
2252 info->n_pins = NUM_PTP_PINS_E810T; in ice_ptp_setup_pins_e810()
2253 info->verify = ice_verify_pin_e810t; in ice_ptp_setup_pins_e810()
2257 } else if (ice_is_e810t(&pf->hw)) { in ice_ptp_setup_pins_e810()
2258 info->n_ext_ts = N_EXT_TS_NO_SMA_E810T; in ice_ptp_setup_pins_e810()
2259 info->n_per_out = N_PER_OUT_NO_SMA_E810T; in ice_ptp_setup_pins_e810()
2261 info->n_per_out = N_PER_OUT_E810; in ice_ptp_setup_pins_e810()
2262 info->n_ext_ts = N_EXT_TS_E810; in ice_ptp_setup_pins_e810()
2267 * ice_ptp_setup_pins_e823 - Setup PTP pins in sysfs
2274 info->pps = 1; in ice_ptp_setup_pins_e823()
2275 info->n_per_out = 0; in ice_ptp_setup_pins_e823()
2276 info->n_ext_ts = 1; in ice_ptp_setup_pins_e823()
2280 * ice_ptp_set_funcs_e822 - Set specialized functions for E822 support
2295 info->getcrosststamp = ice_ptp_getcrosststamp_e822; in ice_ptp_set_funcs_e822()
2300 * ice_ptp_set_funcs_e810 - Set specialized functions for E810 support
2312 info->enable = ice_ptp_gpio_enable_e810; in ice_ptp_set_funcs_e810()
2317 * ice_ptp_set_funcs_e823 - Set specialized functions for E823 support
2329 info->enable = ice_ptp_gpio_enable_e823; in ice_ptp_set_funcs_e823()
2334 * ice_ptp_set_caps - Set PTP capabilities
2339 struct ptp_clock_info *info = &pf->ptp.info; in ice_ptp_set_caps()
2342 snprintf(info->name, sizeof(info->name) - 1, "%s-%s-clk", in ice_ptp_set_caps()
2344 info->owner = THIS_MODULE; in ice_ptp_set_caps()
2345 info->max_adj = 100000000; in ice_ptp_set_caps()
2346 info->adjtime = ice_ptp_adjtime; in ice_ptp_set_caps()
2347 info->adjfine = ice_ptp_adjfine; in ice_ptp_set_caps()
2348 info->gettimex64 = ice_ptp_gettimex64; in ice_ptp_set_caps()
2349 info->settime64 = ice_ptp_settime64; in ice_ptp_set_caps()
2351 if (ice_is_e810(&pf->hw)) in ice_ptp_set_caps()
2353 else if (ice_is_e823(&pf->hw)) in ice_ptp_set_caps()
2360 * ice_ptp_create_clock - Create PTP clock device for userspace
2375 if (pf->ptp.clock) in ice_ptp_create_clock()
2380 info = &pf->ptp.info; in ice_ptp_create_clock()
2388 pf->ptp.clock = clock; in ice_ptp_create_clock()
2394 * ice_ptp_request_ts - Request an available Tx timestamp index
2402 spin_lock(&tx->lock); in ice_ptp_request_ts()
2406 spin_unlock(&tx->lock); in ice_ptp_request_ts()
2407 return -1; in ice_ptp_request_ts()
2411 idx = find_first_zero_bit(tx->in_use, tx->len); in ice_ptp_request_ts()
2412 if (idx < tx->len) { in ice_ptp_request_ts()
2417 set_bit(idx, tx->in_use); in ice_ptp_request_ts()
2418 clear_bit(idx, tx->stale); in ice_ptp_request_ts()
2419 tx->tstamps[idx].start = jiffies; in ice_ptp_request_ts()
2420 tx->tstamps[idx].skb = skb_get(skb); in ice_ptp_request_ts()
2421 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; in ice_ptp_request_ts()
2425 spin_unlock(&tx->lock); in ice_ptp_request_ts()
2427 /* return the appropriate PHY timestamp register index, -1 if no in ice_ptp_request_ts()
2430 if (idx >= tx->len) in ice_ptp_request_ts()
2431 return -1; in ice_ptp_request_ts()
2433 return idx + tx->offset; in ice_ptp_request_ts()
2437 * ice_ptp_process_ts - Process the PTP Tx timestamps
2445 return ice_ptp_tx_tstamp(&pf->ptp.port.tx); in ice_ptp_process_ts()
2454 if (!test_bit(ICE_FLAG_PTP, pf->flags)) in ice_ptp_periodic_work()
2460 kthread_queue_delayed_work(ptp->kworker, &ptp->work, in ice_ptp_periodic_work()
2465 * ice_ptp_reset - Initialize PTP hardware clock support after reset
2470 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_reset()
2471 struct ice_hw *hw = &pf->hw; in ice_ptp_reset()
2476 if (test_bit(ICE_PFR_REQ, pf->state)) in ice_ptp_reset()
2479 if (!hw->func_caps.ts_func_info.src_tmr_owned) in ice_ptp_reset()
2488 err = -EBUSY; in ice_ptp_reset()
2503 if (ptp->cached_phc_time) { in ice_ptp_reset()
2504 time_diff = ktime_get_real_ns() - ptp->reset_time; in ice_ptp_reset()
2505 ts = ns_to_timespec64(ptp->cached_phc_time + time_diff); in ice_ptp_reset()
2531 if (ice_is_e810(&pf->hw)) { in ice_ptp_reset()
2532 err = ice_ptp_init_tx_e810(pf, &ptp->port.tx); in ice_ptp_reset()
2534 kthread_init_delayed_work(&ptp->port.ov_work, in ice_ptp_reset()
2536 err = ice_ptp_init_tx_e822(pf, &ptp->port.tx, in ice_ptp_reset()
2537 ptp->port.port_num); in ice_ptp_reset()
2542 set_bit(ICE_FLAG_PTP, pf->flags); in ice_ptp_reset()
2545 kthread_queue_delayed_work(ptp->kworker, &ptp->work, 0); in ice_ptp_reset()
2555 * ice_ptp_prepare_for_reset - Prepare PTP for reset
2560 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_prepare_for_reset()
2563 clear_bit(ICE_FLAG_PTP, pf->flags); in ice_ptp_prepare_for_reset()
2568 kthread_cancel_delayed_work_sync(&ptp->work); in ice_ptp_prepare_for_reset()
2570 if (test_bit(ICE_PFR_REQ, pf->state)) in ice_ptp_prepare_for_reset()
2573 ice_ptp_release_tx_tracker(pf, &pf->ptp.port.tx); in ice_ptp_prepare_for_reset()
2578 src_tmr = ice_get_ptp_src_clock_index(&pf->hw); in ice_ptp_prepare_for_reset()
2581 wr32(&pf->hw, GLTSYN_ENA(src_tmr), (u32)~GLTSYN_ENA_TSYN_ENA_M); in ice_ptp_prepare_for_reset()
2584 ptp->reset_time = ktime_get_real_ns(); in ice_ptp_prepare_for_reset()
2588 * ice_ptp_init_owner - Initialize PTP_1588_CLOCK device
2597 struct ice_hw *hw = &pf->hw; in ice_ptp_init_owner()
2610 err = -EBUSY; in ice_ptp_init_owner()
2650 pf->ptp.clock = NULL; in ice_ptp_init_owner()
2656 * ice_ptp_init_work - Initialize PTP work threads
2665 kthread_init_delayed_work(&ptp->work, ice_ptp_periodic_work); in ice_ptp_init_work()
2670 kworker = kthread_create_worker(0, "ice-ptp-%s", in ice_ptp_init_work()
2675 ptp->kworker = kworker; in ice_ptp_init_work()
2678 kthread_queue_delayed_work(ptp->kworker, &ptp->work, 0); in ice_ptp_init_work()
2684 * ice_ptp_init_port - Initialize PTP port structure
2690 mutex_init(&ptp_port->ps_lock); in ice_ptp_init_port()
2692 if (ice_is_e810(&pf->hw)) in ice_ptp_init_port()
2693 return ice_ptp_init_tx_e810(pf, &ptp_port->tx); in ice_ptp_init_port()
2695 kthread_init_delayed_work(&ptp_port->ov_work, in ice_ptp_init_port()
2697 return ice_ptp_init_tx_e822(pf, &ptp_port->tx, ptp_port->port_num); in ice_ptp_init_port()
2701 * ice_ptp_init - Initialize PTP hardware clock support
2714 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_init()
2715 struct ice_hw *hw = &pf->hw; in ice_ptp_init()
2721 if (hw->func_caps.ts_func_info.src_tmr_owned) { in ice_ptp_init()
2727 ptp->port.port_num = hw->pf_id; in ice_ptp_init()
2728 err = ice_ptp_init_port(pf, &ptp->port); in ice_ptp_init()
2735 set_bit(ICE_FLAG_PTP, pf->flags); in ice_ptp_init()
2745 if (pf->ptp.clock) { in ice_ptp_init()
2746 ptp_clock_unregister(ptp->clock); in ice_ptp_init()
2747 pf->ptp.clock = NULL; in ice_ptp_init()
2749 clear_bit(ICE_FLAG_PTP, pf->flags); in ice_ptp_init()
2754 * ice_ptp_release - Disable the driver/HW support and unregister the clock
2762 if (!test_bit(ICE_FLAG_PTP, pf->flags)) in ice_ptp_release()
2768 ice_ptp_release_tx_tracker(pf, &pf->ptp.port.tx); in ice_ptp_release()
2770 clear_bit(ICE_FLAG_PTP, pf->flags); in ice_ptp_release()
2772 kthread_cancel_delayed_work_sync(&pf->ptp.work); in ice_ptp_release()
2774 ice_ptp_port_phy_stop(&pf->ptp.port); in ice_ptp_release()
2775 mutex_destroy(&pf->ptp.port.ps_lock); in ice_ptp_release()
2776 if (pf->ptp.kworker) { in ice_ptp_release()
2777 kthread_destroy_worker(pf->ptp.kworker); in ice_ptp_release()
2778 pf->ptp.kworker = NULL; in ice_ptp_release()
2781 if (!pf->ptp.clock) in ice_ptp_release()
2788 ptp_clock_unregister(pf->ptp.clock); in ice_ptp_release()
2789 pf->ptp.clock = NULL; in ice_ptp_release()