Lines Matching +full:quad +full:- +full:channel

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()
203 /* Disable the same function on the other pin sharing the channel */ in ice_ptp_set_sma_e810t()
225 * @chan: Assigned channel
235 /* Don't allow channel reassignment */ in ice_verify_pin_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 * *--------------------------------------------------------------*
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_tx_tstamp - Process Tx timestamps for a port
627 * checking if we need to re-queue this task. The only place where bits can be
633 * will notice it at the end when we re-queue the task. If a Tx thread starts
634 * a new timestamp just after this function exits without re-queuing,
646 if (!tx->init) in ice_ptp_tx_tstamp()
652 for_each_set_bit(idx, tx->in_use, tx->len) { in ice_ptp_tx_tstamp()
654 u8 phy_idx = idx + tx->quad_offset; in ice_ptp_tx_tstamp()
659 ice_trace(tx_tstamp_fw_req, tx->tstamps[idx].skb, idx); in ice_ptp_tx_tstamp()
661 err = ice_read_phy_tstamp(&pf->hw, tx->quad, phy_idx, in ice_ptp_tx_tstamp()
666 ice_trace(tx_tstamp_fw_done, tx->tstamps[idx].skb, idx); in ice_ptp_tx_tstamp()
670 raw_tstamp == tx->tstamps[idx].cached_tstamp) in ice_ptp_tx_tstamp()
676 spin_lock(&tx->lock); in ice_ptp_tx_tstamp()
677 tx->tstamps[idx].cached_tstamp = raw_tstamp; in ice_ptp_tx_tstamp()
678 clear_bit(idx, tx->in_use); in ice_ptp_tx_tstamp()
679 skb = tx->tstamps[idx].skb; in ice_ptp_tx_tstamp()
680 tx->tstamps[idx].skb = NULL; in ice_ptp_tx_tstamp()
681 spin_unlock(&tx->lock); in ice_ptp_tx_tstamp()
700 /* Check if we still have work to do. If so, re-queue this task to in ice_ptp_tx_tstamp()
703 spin_lock(&tx->lock); in ice_ptp_tx_tstamp()
704 if (!bitmap_empty(tx->in_use, tx->len)) in ice_ptp_tx_tstamp()
706 spin_unlock(&tx->lock); in ice_ptp_tx_tstamp()
712 * ice_ptp_alloc_tx_tracker - Initialize tracking for Tx timestamps
721 tx->tstamps = kcalloc(tx->len, sizeof(*tx->tstamps), GFP_KERNEL); in ice_ptp_alloc_tx_tracker()
722 if (!tx->tstamps) in ice_ptp_alloc_tx_tracker()
723 return -ENOMEM; in ice_ptp_alloc_tx_tracker()
725 tx->in_use = bitmap_zalloc(tx->len, GFP_KERNEL); in ice_ptp_alloc_tx_tracker()
726 if (!tx->in_use) { in ice_ptp_alloc_tx_tracker()
727 kfree(tx->tstamps); in ice_ptp_alloc_tx_tracker()
728 tx->tstamps = NULL; in ice_ptp_alloc_tx_tracker()
729 return -ENOMEM; in ice_ptp_alloc_tx_tracker()
732 spin_lock_init(&tx->lock); in ice_ptp_alloc_tx_tracker()
734 tx->init = 1; in ice_ptp_alloc_tx_tracker()
740 * ice_ptp_flush_tx_tracker - Flush any remaining timestamps from the tracker
749 for (idx = 0; idx < tx->len; idx++) { in ice_ptp_flush_tx_tracker()
750 u8 phy_idx = idx + tx->quad_offset; in ice_ptp_flush_tx_tracker()
752 spin_lock(&tx->lock); in ice_ptp_flush_tx_tracker()
753 if (tx->tstamps[idx].skb) { in ice_ptp_flush_tx_tracker()
754 dev_kfree_skb_any(tx->tstamps[idx].skb); in ice_ptp_flush_tx_tracker()
755 tx->tstamps[idx].skb = NULL; in ice_ptp_flush_tx_tracker()
756 pf->ptp.tx_hwtstamp_flushed++; in ice_ptp_flush_tx_tracker()
758 clear_bit(idx, tx->in_use); in ice_ptp_flush_tx_tracker()
759 spin_unlock(&tx->lock); in ice_ptp_flush_tx_tracker()
762 if (!pf->hw.reset_ongoing) in ice_ptp_flush_tx_tracker()
763 ice_clear_phy_tstamp(&pf->hw, tx->quad, phy_idx); in ice_ptp_flush_tx_tracker()
768 * ice_ptp_release_tx_tracker - Release allocated memory for Tx tracker
777 tx->init = 0; in ice_ptp_release_tx_tracker()
781 kfree(tx->tstamps); in ice_ptp_release_tx_tracker()
782 tx->tstamps = NULL; in ice_ptp_release_tx_tracker()
784 bitmap_free(tx->in_use); in ice_ptp_release_tx_tracker()
785 tx->in_use = NULL; in ice_ptp_release_tx_tracker()
787 tx->len = 0; in ice_ptp_release_tx_tracker()
791 * ice_ptp_init_tx_e822 - Initialize tracking for Tx timestamps
797 * the timestamp block is shared for all ports in the same quad. To avoid
804 tx->quad = port / ICE_PORTS_PER_QUAD; in ice_ptp_init_tx_e822()
805 tx->quad_offset = (port % ICE_PORTS_PER_QUAD) * INDEX_PER_PORT; in ice_ptp_init_tx_e822()
806 tx->len = INDEX_PER_PORT; in ice_ptp_init_tx_e822()
812 * ice_ptp_init_tx_e810 - Initialize tracking for Tx timestamps
822 tx->quad = pf->hw.port_info->lport; in ice_ptp_init_tx_e810()
823 tx->quad_offset = 0; in ice_ptp_init_tx_e810()
824 tx->len = INDEX_PER_QUAD; in ice_ptp_init_tx_e810()
830 * ice_ptp_tx_tstamp_cleanup - Cleanup old timestamp requests that got dropped
842 struct ice_hw *hw = &pf->hw; in ice_ptp_tx_tstamp_cleanup()
845 if (!tx->init) in ice_ptp_tx_tstamp_cleanup()
848 for_each_set_bit(idx, tx->in_use, tx->len) { in ice_ptp_tx_tstamp_cleanup()
853 if (time_is_after_jiffies(tx->tstamps[idx].start + 2 * HZ)) in ice_ptp_tx_tstamp_cleanup()
857 ice_read_phy_tstamp(hw, tx->quad, idx + tx->quad_offset, in ice_ptp_tx_tstamp_cleanup()
860 spin_lock(&tx->lock); in ice_ptp_tx_tstamp_cleanup()
861 skb = tx->tstamps[idx].skb; in ice_ptp_tx_tstamp_cleanup()
862 tx->tstamps[idx].skb = NULL; in ice_ptp_tx_tstamp_cleanup()
863 clear_bit(idx, tx->in_use); in ice_ptp_tx_tstamp_cleanup()
864 spin_unlock(&tx->lock); in ice_ptp_tx_tstamp_cleanup()
867 pf->ptp.tx_hwtstamp_timeouts++; in ice_ptp_tx_tstamp_cleanup()
875 * ice_ptp_update_cached_phctime - Update the cached PHC time values
888 * * 0 - OK, successfully updated
889 * * -EAGAIN - PF was busy, need to reschedule the update
898 update_before = pf->ptp.cached_phc_jiffies + msecs_to_jiffies(2000); in ice_ptp_update_cached_phctime()
899 if (pf->ptp.cached_phc_time && in ice_ptp_update_cached_phctime()
901 unsigned long time_taken = jiffies - pf->ptp.cached_phc_jiffies; in ice_ptp_update_cached_phctime()
905 pf->ptp.late_cached_phc_updates++; in ice_ptp_update_cached_phctime()
912 WRITE_ONCE(pf->ptp.cached_phc_time, systime); in ice_ptp_update_cached_phctime()
913 WRITE_ONCE(pf->ptp.cached_phc_jiffies, jiffies); in ice_ptp_update_cached_phctime()
915 if (test_and_set_bit(ICE_CFG_BUSY, pf->state)) in ice_ptp_update_cached_phctime()
916 return -EAGAIN; in ice_ptp_update_cached_phctime()
919 struct ice_vsi *vsi = pf->vsi[i]; in ice_ptp_update_cached_phctime()
925 if (vsi->type != ICE_VSI_PF) in ice_ptp_update_cached_phctime()
929 if (!vsi->rx_rings[j]) in ice_ptp_update_cached_phctime()
931 WRITE_ONCE(vsi->rx_rings[j]->cached_phctime, systime); in ice_ptp_update_cached_phctime()
934 clear_bit(ICE_CFG_BUSY, pf->state); in ice_ptp_update_cached_phctime()
940 * ice_ptp_reset_cached_phctime - Reset cached PHC time after an update
977 kthread_queue_delayed_work(pf->ptp.kworker, &pf->ptp.work, in ice_ptp_reset_cached_phctime()
982 ice_ptp_flush_tx_tracker(pf, &pf->ptp.port.tx); in ice_ptp_reset_cached_phctime()
986 * ice_ptp_read_time - Read the time from the device
1006 * ice_ptp_write_init - Set PHC time to provided value
1015 struct ice_hw *hw = &pf->hw; in ice_ptp_write_init()
1021 * ice_ptp_write_adj - Adjust PHC clock time atomically
1030 struct ice_hw *hw = &pf->hw; in ice_ptp_write_adj()
1036 * ice_base_incval - Get base timer increment value
1046 struct ice_hw *hw = &pf->hw; in ice_base_incval()
1063 * ice_ptp_reset_ts_memory_quad - Reset timestamp memory for one quad
1065 * @quad: The quad (0-4)
1067 static void ice_ptp_reset_ts_memory_quad(struct ice_pf *pf, int quad) in ice_ptp_reset_ts_memory_quad() argument
1069 struct ice_hw *hw = &pf->hw; in ice_ptp_reset_ts_memory_quad()
1071 ice_write_quad_reg_e822(hw, quad, Q_REG_TS_CTRL, Q_REG_TS_CTRL_M); in ice_ptp_reset_ts_memory_quad()
1072 ice_write_quad_reg_e822(hw, quad, Q_REG_TS_CTRL, ~(u32)Q_REG_TS_CTRL_M); in ice_ptp_reset_ts_memory_quad()
1076 * ice_ptp_check_tx_fifo - Check whether Tx FIFO is in an OK state
1081 int quad = port->port_num / ICE_PORTS_PER_QUAD; in ice_ptp_check_tx_fifo() local
1082 int offs = port->port_num % ICE_PORTS_PER_QUAD; in ice_ptp_check_tx_fifo()
1089 hw = &pf->hw; in ice_ptp_check_tx_fifo()
1091 if (port->tx_fifo_busy_cnt == FIFO_OK) in ice_ptp_check_tx_fifo()
1096 err = ice_read_quad_reg_e822(hw, quad, Q_REG_FIFO01_STATUS, in ice_ptp_check_tx_fifo()
1099 err = ice_read_quad_reg_e822(hw, quad, Q_REG_FIFO23_STATUS, in ice_ptp_check_tx_fifo()
1104 port->port_num, err); in ice_ptp_check_tx_fifo()
1114 port->tx_fifo_busy_cnt = FIFO_OK; in ice_ptp_check_tx_fifo()
1118 port->tx_fifo_busy_cnt++; in ice_ptp_check_tx_fifo()
1121 port->tx_fifo_busy_cnt, port->port_num); in ice_ptp_check_tx_fifo()
1123 if (port->tx_fifo_busy_cnt == ICE_PTP_FIFO_NUM_CHECKS) { in ice_ptp_check_tx_fifo()
1125 "Port %d Tx FIFO still not empty; resetting quad %d\n", in ice_ptp_check_tx_fifo()
1126 port->port_num, quad); in ice_ptp_check_tx_fifo()
1127 ice_ptp_reset_ts_memory_quad(pf, quad); in ice_ptp_check_tx_fifo()
1128 port->tx_fifo_busy_cnt = FIFO_OK; in ice_ptp_check_tx_fifo()
1132 return -EAGAIN; in ice_ptp_check_tx_fifo()
1136 * ice_ptp_check_tx_offset_valid - Check if the Tx PHY offset is valid
1140 * valid. Returns 0 if the offset is valid, and a non-zero error code if it is
1147 struct ice_hw *hw = &pf->hw; in ice_ptp_check_tx_offset_valid()
1155 err = ice_read_phy_reg_e822(hw, port->port_num, P_REG_TX_OV_STATUS, in ice_ptp_check_tx_offset_valid()
1159 port->port_num, err); in ice_ptp_check_tx_offset_valid()
1160 return -EAGAIN; in ice_ptp_check_tx_offset_valid()
1164 return -EAGAIN; in ice_ptp_check_tx_offset_valid()
1170 * ice_ptp_check_rx_offset_valid - Check if the Rx PHY offset is valid
1174 * valid. Returns 0 if the offset is valid, and a non-zero error code if it is
1181 struct ice_hw *hw = &pf->hw; in ice_ptp_check_rx_offset_valid()
1185 err = ice_read_phy_reg_e822(hw, port->port_num, P_REG_RX_OV_STATUS, in ice_ptp_check_rx_offset_valid()
1189 port->port_num, err); in ice_ptp_check_rx_offset_valid()
1194 return -EAGAIN; in ice_ptp_check_rx_offset_valid()
1200 * ice_ptp_check_offset_valid - Check port offset valid bit
1203 * Returns 0 if both Tx and Rx offset are valid, and -EAGAIN if one of the
1215 return -EAGAIN; in ice_ptp_check_offset_valid()
1221 * ice_ptp_wait_for_offset_valid - Check for valid Tx and Rx offsets
1241 hw = &pf->hw; in ice_ptp_wait_for_offset_valid()
1244 if (ice_is_reset_in_progress(pf->state)) in ice_ptp_wait_for_offset_valid()
1249 kthread_queue_delayed_work(pf->ptp.kworker, in ice_ptp_wait_for_offset_valid()
1250 &port->ov_work, in ice_ptp_wait_for_offset_valid()
1256 err = ice_phy_exit_bypass_e822(hw, port->port_num); in ice_ptp_wait_for_offset_valid()
1259 port->port_num, err); in ice_ptp_wait_for_offset_valid()
1265 * ice_ptp_port_phy_stop - Stop timestamping for a PHY port
1272 u8 port = ptp_port->port_num; in ice_ptp_port_phy_stop()
1273 struct ice_hw *hw = &pf->hw; in ice_ptp_port_phy_stop()
1279 mutex_lock(&ptp_port->ps_lock); in ice_ptp_port_phy_stop()
1281 kthread_cancel_delayed_work_sync(&ptp_port->ov_work); in ice_ptp_port_phy_stop()
1288 mutex_unlock(&ptp_port->ps_lock); in ice_ptp_port_phy_stop()
1294 * ice_ptp_port_phy_restart - (Re)start and calibrate PHY timestamping
1305 u8 port = ptp_port->port_num; in ice_ptp_port_phy_restart()
1306 struct ice_hw *hw = &pf->hw; in ice_ptp_port_phy_restart()
1312 if (!ptp_port->link_up) in ice_ptp_port_phy_restart()
1315 mutex_lock(&ptp_port->ps_lock); in ice_ptp_port_phy_restart()
1317 kthread_cancel_delayed_work_sync(&ptp_port->ov_work); in ice_ptp_port_phy_restart()
1320 ptp_port->tx.calibrating = true; in ice_ptp_port_phy_restart()
1321 ptp_port->tx_fifo_busy_cnt = 0; in ice_ptp_port_phy_restart()
1329 ptp_port->tx.calibrating = false; in ice_ptp_port_phy_restart()
1331 kthread_queue_delayed_work(pf->ptp.kworker, &ptp_port->ov_work, 0); in ice_ptp_port_phy_restart()
1338 mutex_unlock(&ptp_port->ps_lock); in ice_ptp_port_phy_restart()
1344 * ice_ptp_link_change - Set or clear port registers for timestamping
1353 if (!test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags)) in ice_ptp_link_change()
1357 return -EINVAL; in ice_ptp_link_change()
1359 ptp_port = &pf->ptp.port; in ice_ptp_link_change()
1360 if (ptp_port->port_num != port) in ice_ptp_link_change()
1361 return -EINVAL; in ice_ptp_link_change()
1364 ptp_port->link_up = linkup; in ice_ptp_link_change()
1366 if (!test_bit(ICE_FLAG_PTP, pf->flags)) in ice_ptp_link_change()
1368 return -EAGAIN; in ice_ptp_link_change()
1374 * ice_ptp_reset_ts_memory - Reset timestamp memory for all quads
1379 int quad; in ice_ptp_reset_ts_memory() local
1381 quad = pf->hw.port_info->lport / ICE_PORTS_PER_QUAD; in ice_ptp_reset_ts_memory()
1382 ice_ptp_reset_ts_memory_quad(pf, quad); in ice_ptp_reset_ts_memory()
1386 * ice_ptp_tx_ena_intr - Enable or disable the Tx timestamp interrupt
1395 struct ice_hw *hw = &pf->hw; in ice_ptp_tx_ena_intr()
1397 int quad; in ice_ptp_tx_ena_intr() local
1402 for (quad = 0; quad < ICE_MAX_QUAD; quad++) { in ice_ptp_tx_ena_intr()
1403 err = ice_read_quad_reg_e822(hw, quad, Q_REG_TX_MEM_GBL_CFG, in ice_ptp_tx_ena_intr()
1417 err = ice_write_quad_reg_e822(hw, quad, Q_REG_TX_MEM_GBL_CFG, in ice_ptp_tx_ena_intr()
1430 * ice_ptp_reset_phy_timestamping - Reset PHY timestamping block
1435 ice_ptp_port_phy_restart(&pf->ptp.port); in ice_ptp_reset_phy_timestamping()
1439 * ice_ptp_adjfine - Adjust clock increment rate
1441 * @scaled_ppm: Parts per million with 16-bit fractional field
1449 struct ice_hw *hw = &pf->hw; in ice_ptp_adjfine()
1458 scaled_ppm = -scaled_ppm; in ice_ptp_adjfine()
1464 incval -= diff; in ice_ptp_adjfine()
1472 return -EIO; in ice_ptp_adjfine()
1479 * ice_ptp_extts_work - Workqueue task function
1489 struct ice_hw *hw = &pf->hw; in ice_ptp_extts_work()
1493 tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned; in ice_ptp_extts_work()
1500 /* Check if channel is enabled */ in ice_ptp_extts_work()
1501 if (pf->ptp.ext_ts_irq & (1 << chan)) { in ice_ptp_extts_work()
1509 ptp_clock_event(pf->ptp.clock, &event); in ice_ptp_extts_work()
1510 pf->ptp.ext_ts_irq &= ~(1 << chan); in ice_ptp_extts_work()
1516 * ice_ptp_cfg_extts - Configure EXTTS pin and channel
1519 * @chan: GPIO channel (0-3)
1528 struct ice_hw *hw = &pf->hw; in ice_ptp_cfg_extts()
1531 if (chan > (unsigned int)pf->ptp.info.n_ext_ts) in ice_ptp_cfg_extts()
1532 return -EINVAL; in ice_ptp_cfg_extts()
1534 tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned; in ice_ptp_cfg_extts()
1553 * 0x1 is input sampled by EVENT register(channel) in ice_ptp_cfg_extts()
1559 pf->ptp.ext_ts_chan |= (1 << chan); in ice_ptp_cfg_extts()
1564 pf->ptp.ext_ts_chan &= ~(1 << chan); in ice_ptp_cfg_extts()
1565 if (!pf->ptp.ext_ts_chan) in ice_ptp_cfg_extts()
1577 * ice_ptp_cfg_clkout - Configure clock to generate periodic wave
1579 * @chan: GPIO channel (0-3)
1580 * @config: desired periodic clk configuration. NULL will disable channel
1590 struct ice_hw *hw = &pf->hw; in ice_ptp_cfg_clkout()
1594 tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned; in ice_ptp_cfg_clkout()
1602 if (!config || !config->ena) { in ice_ptp_cfg_clkout()
1608 gpio_pin = pf->ptp.perout_channels[chan].gpio_pin; in ice_ptp_cfg_clkout()
1613 memset(&pf->ptp.perout_channels[chan], 0, in ice_ptp_cfg_clkout()
1618 period = config->period; in ice_ptp_cfg_clkout()
1619 start_time = config->start_time; in ice_ptp_cfg_clkout()
1621 gpio_pin = config->gpio_pin; in ice_ptp_cfg_clkout()
1649 start_time = div64_u64(current_time + NSEC_PER_SEC - 1, in ice_ptp_cfg_clkout()
1653 start_time -= E810_OUT_PROP_DELAY_NS; in ice_ptp_cfg_clkout()
1655 start_time -= ice_e822_pps_delay(ice_e822_time_ref(hw)); in ice_ptp_cfg_clkout()
1673 memcpy(&pf->ptp.perout_channels[chan], config, in ice_ptp_cfg_clkout()
1675 pf->ptp.perout_channels[chan].start_time = phase; in ice_ptp_cfg_clkout()
1681 return -EFAULT; in ice_ptp_cfg_clkout()
1685 * ice_ptp_disable_all_clkout - Disable all currently configured outputs
1690 * re-enable the clocks again.
1696 for (i = 0; i < pf->ptp.info.n_per_out; i++) in ice_ptp_disable_all_clkout()
1697 if (pf->ptp.perout_channels[i].ena) in ice_ptp_disable_all_clkout()
1702 * ice_ptp_enable_all_clkout - Enable all configured periodic clock outputs
1713 for (i = 0; i < pf->ptp.info.n_per_out; i++) in ice_ptp_enable_all_clkout()
1714 if (pf->ptp.perout_channels[i].ena) in ice_ptp_enable_all_clkout()
1715 ice_ptp_cfg_clkout(pf, i, &pf->ptp.perout_channels[i], in ice_ptp_enable_all_clkout()
1720 * ice_ptp_gpio_enable_e810 - Enable/disable ancillary features of PHC
1739 switch (rq->type) { in ice_ptp_gpio_enable_e810()
1741 chan = rq->perout.index; in ice_ptp_gpio_enable_e810()
1748 return -1; in ice_ptp_gpio_enable_e810()
1749 } else if (ice_is_e810t(&pf->hw)) { in ice_ptp_gpio_enable_e810()
1760 clk_cfg.period = ((rq->perout.period.sec * NSEC_PER_SEC) + in ice_ptp_gpio_enable_e810()
1761 rq->perout.period.nsec); in ice_ptp_gpio_enable_e810()
1762 clk_cfg.start_time = ((rq->perout.start.sec * NSEC_PER_SEC) + in ice_ptp_gpio_enable_e810()
1763 rq->perout.start.nsec); in ice_ptp_gpio_enable_e810()
1769 chan = rq->extts.index; in ice_ptp_gpio_enable_e810()
1775 } else if (ice_is_e810t(&pf->hw)) { in ice_ptp_gpio_enable_e810()
1785 rq->extts.flags); in ice_ptp_gpio_enable_e810()
1788 return -EOPNOTSUPP; in ice_ptp_gpio_enable_e810()
1795 * ice_ptp_gettimex64 - Get the time of the clock
1809 struct ice_hw *hw = &pf->hw; in ice_ptp_gettimex64()
1813 return -EBUSY; in ice_ptp_gettimex64()
1823 * ice_ptp_settime64 - Set the time of the clock
1835 struct ice_hw *hw = &pf->hw; in ice_ptp_settime64()
1841 if (pf->ptp.port.link_up) in ice_ptp_settime64()
1842 ice_ptp_port_phy_stop(&pf->ptp.port); in ice_ptp_settime64()
1845 err = -EBUSY; in ice_ptp_settime64()
1861 /* Recalibrate and re-enable timestamp block */ in ice_ptp_settime64()
1862 if (pf->ptp.port.link_up) in ice_ptp_settime64()
1863 ice_ptp_port_phy_restart(&pf->ptp.port); in ice_ptp_settime64()
1874 * ice_ptp_adjtime_nonatomic - Do a non-atomic clock adjustment
1893 * ice_ptp_adjtime - Adjust the time of the clock by the indicated delta
1900 struct ice_hw *hw = &pf->hw; in ice_ptp_adjtime()
1906 /* Hardware only supports atomic adjustments using signed 32-bit in ice_ptp_adjtime()
1908 * a non-atomic get->adjust->set flow. in ice_ptp_adjtime()
1911 dev_dbg(dev, "delta = %lld, adjtime non-atomic\n", delta); in ice_ptp_adjtime()
1917 return -EBUSY; in ice_ptp_adjtime()
1942 * ice_ptp_get_syncdevicetime - Get the cross time stamp info
1956 struct ice_hw *hw = &pf->hw; in ice_ptp_get_syncdevicetime()
1961 hh_lock = rd32(hw, PFHH_SEM + (PFTSYN_SEM_BYTES * hw->pf_id)); in ice_ptp_get_syncdevicetime()
1964 return -EFAULT; in ice_ptp_get_syncdevicetime()
1984 tmr_idx = hw->func_caps.ts_func_info.tmr_index_assoc; in ice_ptp_get_syncdevicetime()
1999 hh_lock = rd32(hw, PFHH_SEM + (PFTSYN_SEM_BYTES * hw->pf_id)); in ice_ptp_get_syncdevicetime()
2001 wr32(hw, PFHH_SEM + (PFTSYN_SEM_BYTES * hw->pf_id), hh_lock); in ice_ptp_get_syncdevicetime()
2004 return -ETIMEDOUT; in ice_ptp_get_syncdevicetime()
2010 * ice_ptp_getcrosststamp_e822 - Capture a device cross timestamp
2036 * ice_ptp_get_ts_config - ioctl interface to read the timestamping config
2046 if (!test_bit(ICE_FLAG_PTP, pf->flags)) in ice_ptp_get_ts_config()
2047 return -EIO; in ice_ptp_get_ts_config()
2049 config = &pf->ptp.tstamp_config; in ice_ptp_get_ts_config()
2051 return copy_to_user(ifr->ifr_data, config, sizeof(*config)) ? in ice_ptp_get_ts_config()
2052 -EFAULT : 0; in ice_ptp_get_ts_config()
2056 * ice_ptp_set_timestamp_mode - Setup driver for requested timestamp mode
2063 switch (config->tx_type) { in ice_ptp_set_timestamp_mode()
2071 return -ERANGE; in ice_ptp_set_timestamp_mode()
2074 switch (config->rx_filter) { in ice_ptp_set_timestamp_mode()
2095 return -ERANGE; in ice_ptp_set_timestamp_mode()
2102 * ice_ptp_set_ts_config - ioctl interface to control the timestamping
2113 if (!test_bit(ICE_FLAG_PTP, pf->flags)) in ice_ptp_set_ts_config()
2114 return -EAGAIN; in ice_ptp_set_ts_config()
2116 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) in ice_ptp_set_ts_config()
2117 return -EFAULT; in ice_ptp_set_ts_config()
2124 config = pf->ptp.tstamp_config; in ice_ptp_set_ts_config()
2126 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? in ice_ptp_set_ts_config()
2127 -EFAULT : 0; in ice_ptp_set_ts_config()
2131 * ice_ptp_rx_hwtstamp - Check for an Rx timestamp
2147 if (!(rx_desc->wb.time_stamp_low & ICE_PTP_TS_VALID)) in ice_ptp_rx_hwtstamp()
2150 cached_time = READ_ONCE(rx_ring->cached_phctime); in ice_ptp_rx_hwtstamp()
2156 /* Use ice_ptp_extend_32b_ts directly, using the ring-specific cached in ice_ptp_rx_hwtstamp()
2162 ts_high = le32_to_cpu(rx_desc->wb.flex_ts.ts_high); in ice_ptp_rx_hwtstamp()
2167 hwtstamps->hwtstamp = ns_to_ktime(ts_ns); in ice_ptp_rx_hwtstamp()
2171 * ice_ptp_disable_sma_pins_e810t - Disable E810-T SMA pins
2176 * indications of pin support when we fail to setup the E810-T SMA control
2184 dev_warn(dev, "Failed to configure E810-T SMA pin control\n"); in ice_ptp_disable_sma_pins_e810t()
2186 info->enable = NULL; in ice_ptp_disable_sma_pins_e810t()
2187 info->verify = NULL; in ice_ptp_disable_sma_pins_e810t()
2188 info->n_pins = 0; in ice_ptp_disable_sma_pins_e810t()
2189 info->n_ext_ts = 0; in ice_ptp_disable_sma_pins_e810t()
2190 info->n_per_out = 0; in ice_ptp_disable_sma_pins_e810t()
2194 * ice_ptp_setup_sma_pins_e810t - Setup the SMA pins
2209 info->pin_config = devm_kcalloc(dev, info->n_pins, in ice_ptp_setup_sma_pins_e810t()
2210 sizeof(*info->pin_config), GFP_KERNEL); in ice_ptp_setup_sma_pins_e810t()
2211 if (!info->pin_config) { in ice_ptp_setup_sma_pins_e810t()
2217 err = ice_get_sma_config_e810t(&pf->hw, info->pin_config); in ice_ptp_setup_sma_pins_e810t()
2223 * ice_ptp_setup_pins_e810 - Setup PTP pins in sysfs
2230 info->n_per_out = N_PER_OUT_E810; in ice_ptp_setup_pins_e810()
2233 info->n_ext_ts = N_EXT_TS_E810; in ice_ptp_setup_pins_e810()
2236 info->n_ext_ts = N_EXT_TS_E810; in ice_ptp_setup_pins_e810()
2237 info->n_pins = NUM_PTP_PINS_E810T; in ice_ptp_setup_pins_e810()
2238 info->verify = ice_verify_pin_e810t; in ice_ptp_setup_pins_e810()
2246 * ice_ptp_set_funcs_e822 - Set specialized functions for E822 support
2261 info->getcrosststamp = ice_ptp_getcrosststamp_e822; in ice_ptp_set_funcs_e822()
2266 * ice_ptp_set_funcs_e810 - Set specialized functions for E810 support
2278 info->enable = ice_ptp_gpio_enable_e810; in ice_ptp_set_funcs_e810()
2283 * ice_ptp_set_caps - Set PTP capabilities
2288 struct ptp_clock_info *info = &pf->ptp.info; in ice_ptp_set_caps()
2291 snprintf(info->name, sizeof(info->name) - 1, "%s-%s-clk", in ice_ptp_set_caps()
2293 info->owner = THIS_MODULE; in ice_ptp_set_caps()
2294 info->max_adj = 999999999; in ice_ptp_set_caps()
2295 info->adjtime = ice_ptp_adjtime; in ice_ptp_set_caps()
2296 info->adjfine = ice_ptp_adjfine; in ice_ptp_set_caps()
2297 info->gettimex64 = ice_ptp_gettimex64; in ice_ptp_set_caps()
2298 info->settime64 = ice_ptp_settime64; in ice_ptp_set_caps()
2300 if (ice_is_e810(&pf->hw)) in ice_ptp_set_caps()
2307 * ice_ptp_create_clock - Create PTP clock device for userspace
2322 if (pf->ptp.clock) in ice_ptp_create_clock()
2327 info = &pf->ptp.info; in ice_ptp_create_clock()
2335 pf->ptp.clock = clock; in ice_ptp_create_clock()
2341 * ice_ptp_request_ts - Request an available Tx timestamp index
2350 if (!tx->init || tx->calibrating) in ice_ptp_request_ts()
2351 return -1; in ice_ptp_request_ts()
2353 spin_lock(&tx->lock); in ice_ptp_request_ts()
2355 idx = find_first_zero_bit(tx->in_use, tx->len); in ice_ptp_request_ts()
2356 if (idx < tx->len) { in ice_ptp_request_ts()
2361 set_bit(idx, tx->in_use); in ice_ptp_request_ts()
2362 tx->tstamps[idx].start = jiffies; in ice_ptp_request_ts()
2363 tx->tstamps[idx].skb = skb_get(skb); in ice_ptp_request_ts()
2364 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; in ice_ptp_request_ts()
2368 spin_unlock(&tx->lock); in ice_ptp_request_ts()
2370 /* return the appropriate PHY timestamp register index, -1 if no in ice_ptp_request_ts()
2373 if (idx >= tx->len) in ice_ptp_request_ts()
2374 return -1; in ice_ptp_request_ts()
2376 return idx + tx->quad_offset; in ice_ptp_request_ts()
2380 * ice_ptp_process_ts - Process the PTP Tx timestamps
2387 return ice_ptp_tx_tstamp(&pf->ptp.port.tx); in ice_ptp_process_ts()
2396 if (!test_bit(ICE_FLAG_PTP, pf->flags)) in ice_ptp_periodic_work()
2401 ice_ptp_tx_tstamp_cleanup(pf, &pf->ptp.port.tx); in ice_ptp_periodic_work()
2404 kthread_queue_delayed_work(ptp->kworker, &ptp->work, in ice_ptp_periodic_work()
2409 * ice_ptp_reset - Initialize PTP hardware clock support after reset
2414 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_reset()
2415 struct ice_hw *hw = &pf->hw; in ice_ptp_reset()
2420 if (test_bit(ICE_PFR_REQ, pf->state)) in ice_ptp_reset()
2423 if (!hw->func_caps.ts_func_info.src_tmr_owned) in ice_ptp_reset()
2432 err = -EBUSY; in ice_ptp_reset()
2447 if (ptp->cached_phc_time) { in ice_ptp_reset()
2448 time_diff = ktime_get_real_ns() - ptp->reset_time; in ice_ptp_reset()
2449 ts = ns_to_timespec64(ptp->cached_phc_time + time_diff); in ice_ptp_reset()
2463 /* Enable quad interrupts */ in ice_ptp_reset()
2475 if (ice_is_e810(&pf->hw)) { in ice_ptp_reset()
2476 err = ice_ptp_init_tx_e810(pf, &ptp->port.tx); in ice_ptp_reset()
2478 kthread_init_delayed_work(&ptp->port.ov_work, in ice_ptp_reset()
2480 err = ice_ptp_init_tx_e822(pf, &ptp->port.tx, in ice_ptp_reset()
2481 ptp->port.port_num); in ice_ptp_reset()
2486 set_bit(ICE_FLAG_PTP, pf->flags); in ice_ptp_reset()
2489 kthread_queue_delayed_work(ptp->kworker, &ptp->work, 0); in ice_ptp_reset()
2499 * ice_ptp_prepare_for_reset - Prepare PTP for reset
2504 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_prepare_for_reset()
2507 clear_bit(ICE_FLAG_PTP, pf->flags); in ice_ptp_prepare_for_reset()
2512 kthread_cancel_delayed_work_sync(&ptp->work); in ice_ptp_prepare_for_reset()
2513 kthread_cancel_work_sync(&ptp->extts_work); in ice_ptp_prepare_for_reset()
2515 if (test_bit(ICE_PFR_REQ, pf->state)) in ice_ptp_prepare_for_reset()
2518 ice_ptp_release_tx_tracker(pf, &pf->ptp.port.tx); in ice_ptp_prepare_for_reset()
2523 src_tmr = ice_get_ptp_src_clock_index(&pf->hw); in ice_ptp_prepare_for_reset()
2526 wr32(&pf->hw, GLTSYN_ENA(src_tmr), (u32)~GLTSYN_ENA_TSYN_ENA_M); in ice_ptp_prepare_for_reset()
2529 ptp->reset_time = ktime_get_real_ns(); in ice_ptp_prepare_for_reset()
2533 * ice_ptp_init_owner - Initialize PTP_1588_CLOCK device
2542 struct ice_hw *hw = &pf->hw; in ice_ptp_init_owner()
2555 err = -EBUSY; in ice_ptp_init_owner()
2578 /* Enable quad interrupts */ in ice_ptp_init_owner()
2595 pf->ptp.clock = NULL; in ice_ptp_init_owner()
2601 * ice_ptp_init_work - Initialize PTP work threads
2610 kthread_init_delayed_work(&ptp->work, ice_ptp_periodic_work); in ice_ptp_init_work()
2611 kthread_init_work(&ptp->extts_work, ice_ptp_extts_work); in ice_ptp_init_work()
2616 kworker = kthread_create_worker(0, "ice-ptp-%s", in ice_ptp_init_work()
2621 ptp->kworker = kworker; in ice_ptp_init_work()
2624 kthread_queue_delayed_work(ptp->kworker, &ptp->work, 0); in ice_ptp_init_work()
2630 * ice_ptp_init_port - Initialize PTP port structure
2636 mutex_init(&ptp_port->ps_lock); in ice_ptp_init_port()
2638 if (ice_is_e810(&pf->hw)) in ice_ptp_init_port()
2639 return ice_ptp_init_tx_e810(pf, &ptp_port->tx); in ice_ptp_init_port()
2641 kthread_init_delayed_work(&ptp_port->ov_work, in ice_ptp_init_port()
2643 return ice_ptp_init_tx_e822(pf, &ptp_port->tx, ptp_port->port_num); in ice_ptp_init_port()
2647 * ice_ptp_init - Initialize PTP hardware clock support
2660 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_init()
2661 struct ice_hw *hw = &pf->hw; in ice_ptp_init()
2667 if (hw->func_caps.ts_func_info.src_tmr_owned) { in ice_ptp_init()
2673 ptp->port.port_num = hw->pf_id; in ice_ptp_init()
2674 err = ice_ptp_init_port(pf, &ptp->port); in ice_ptp_init()
2681 set_bit(ICE_FLAG_PTP, pf->flags); in ice_ptp_init()
2691 if (pf->ptp.clock) { in ice_ptp_init()
2692 ptp_clock_unregister(ptp->clock); in ice_ptp_init()
2693 pf->ptp.clock = NULL; in ice_ptp_init()
2695 clear_bit(ICE_FLAG_PTP, pf->flags); in ice_ptp_init()
2700 * ice_ptp_release - Disable the driver/HW support and unregister the clock
2708 if (!test_bit(ICE_FLAG_PTP, pf->flags)) in ice_ptp_release()
2714 ice_ptp_release_tx_tracker(pf, &pf->ptp.port.tx); in ice_ptp_release()
2716 clear_bit(ICE_FLAG_PTP, pf->flags); in ice_ptp_release()
2718 kthread_cancel_delayed_work_sync(&pf->ptp.work); in ice_ptp_release()
2720 ice_ptp_port_phy_stop(&pf->ptp.port); in ice_ptp_release()
2721 mutex_destroy(&pf->ptp.port.ps_lock); in ice_ptp_release()
2722 if (pf->ptp.kworker) { in ice_ptp_release()
2723 kthread_destroy_worker(pf->ptp.kworker); in ice_ptp_release()
2724 pf->ptp.kworker = NULL; in ice_ptp_release()
2727 if (!pf->ptp.clock) in ice_ptp_release()
2734 ptp_clock_unregister(pf->ptp.clock); in ice_ptp_release()
2735 pf->ptp.clock = NULL; in ice_ptp_release()