Lines Matching +full:quad +full:- +full:phase
1 // SPDX-License-Identifier: GPL-2.0
114 return -EINVAL; in ice_ptp_set_sma_config_e810t()
119 return -EINVAL; in ice_ptp_set_sma_config_e810t()
191 struct ice_hw *hw = &pf->hw; in ice_ptp_set_sma_e810t()
195 return -EOPNOTSUPP; in ice_ptp_set_sma_e810t()
235 return -EOPNOTSUPP; in ice_verify_pin_e810t()
243 return -EOPNOTSUPP; in ice_verify_pin_e810t()
247 return -EOPNOTSUPP; in ice_verify_pin_e810t()
250 return -EOPNOTSUPP; in ice_verify_pin_e810t()
257 * ice_ptp_cfg_tx_interrupt - Configure Tx timestamp interrupt for the device
265 struct ice_hw *hw = &pf->hw; in ice_ptp_cfg_tx_interrupt()
269 switch (pf->ptp.tx_interrupt_mode) { in ice_ptp_cfg_tx_interrupt()
272 wr32(hw, PFINT_TSYN_MSK + (0x4 * hw->pf_id), (u32)0x1f); in ice_ptp_cfg_tx_interrupt()
276 /* Do not react to interrupts on any quad. */ in ice_ptp_cfg_tx_interrupt()
277 wr32(hw, PFINT_TSYN_MSK + (0x4 * hw->pf_id), (u32)0x0); in ice_ptp_cfg_tx_interrupt()
282 enable = pf->ptp.tstamp_config.tx_type == HWTSTAMP_TX_ON; in ice_ptp_cfg_tx_interrupt()
296 * ice_set_rx_tstamp - Enable or disable Rx timestamping
306 if (!vsi || !vsi->rx_rings) in ice_set_rx_tstamp()
311 if (!vsi->rx_rings[i]) in ice_set_rx_tstamp()
313 vsi->rx_rings[i]->ptp_rx = on; in ice_set_rx_tstamp()
318 * ice_ptp_disable_timestamp_mode - Disable current timestamp mode
327 struct ice_hw *hw = &pf->hw; in ice_ptp_disable_timestamp_mode()
338 * ice_ptp_restore_timestamp_mode - Restore timestamp configuration
346 struct ice_hw *hw = &pf->hw; in ice_ptp_restore_timestamp_mode()
351 enable_rx = pf->ptp.tstamp_config.rx_filter == HWTSTAMP_FILTER_ALL; in ice_ptp_restore_timestamp_mode()
362 * ice_ptp_read_src_clk_reg - Read the source clock register
370 struct ice_hw *hw = &pf->hw; in ice_ptp_read_src_clk_reg()
375 guard(spinlock)(&pf->adapter->ptp_gltsyn_time_lock); in ice_ptp_read_src_clk_reg()
401 * ice_ptp_extend_32b_ts - Convert a 32b nanoseconds timestamp to 64b
408 * 8 bits are sub-nanoseconds and generally discarded.
449 delta = (in_tstamp - phc_time_lo); in ice_ptp_extend_32b_ts()
458 delta = (phc_time_lo - in_tstamp); in ice_ptp_extend_32b_ts()
459 ns = cached_phc_time - delta; in ice_ptp_extend_32b_ts()
468 * ice_ptp_extend_40b_ts - Convert a 40b timestamp to 64b nanoseconds
473 * nanoseconds, 7 bits of sub-nanoseconds, and a valid bit.
475 * *--------------------------------------------------------------*
477 * *--------------------------------------------------------------*
480 * 7 bits are a capture of the upper 7 bits of the sub-nanosecond underflow,
499 discard_time = pf->ptp.cached_phc_jiffies + msecs_to_jiffies(2000); in ice_ptp_extend_40b_ts()
501 pf->ptp.tx_hwtstamp_discarded++; in ice_ptp_extend_40b_ts()
505 return ice_ptp_extend_32b_ts(pf->ptp.cached_phc_time, in ice_ptp_extend_40b_ts()
510 * ice_ptp_is_tx_tracker_up - Check if Tx tracker is ready for new timestamps
516 * Assumes the tx->lock spinlock is already held.
521 lockdep_assert_held(&tx->lock); in ice_ptp_is_tx_tracker_up()
523 return tx->init && !tx->calibrating; in ice_ptp_is_tx_tracker_up()
527 * ice_ptp_req_tx_single_tstamp - Request Tx timestamp for a port from FW
537 if (!tx->init) in ice_ptp_req_tx_single_tstamp()
544 if (time_is_before_jiffies(tx->tstamps[idx].start + 2 * HZ)) { in ice_ptp_req_tx_single_tstamp()
546 pf->ptp.tx_hwtstamp_timeouts++; in ice_ptp_req_tx_single_tstamp()
548 skb = tx->tstamps[idx].skb; in ice_ptp_req_tx_single_tstamp()
549 tx->tstamps[idx].skb = NULL; in ice_ptp_req_tx_single_tstamp()
550 clear_bit(idx, tx->in_use); in ice_ptp_req_tx_single_tstamp()
556 ice_trace(tx_tstamp_fw_req, tx->tstamps[idx].skb, idx); in ice_ptp_req_tx_single_tstamp()
559 wr32(&pf->hw, PF_SB_ATQBAL, in ice_ptp_req_tx_single_tstamp()
562 tx->last_ll_ts_idx_read = idx; in ice_ptp_req_tx_single_tstamp()
566 * ice_ptp_complete_tx_single_tstamp - Complete Tx timestamp for a port
572 u8 idx = tx->last_ll_ts_idx_read; in ice_ptp_complete_tx_single_tstamp()
580 if (!tx->init || tx->last_ll_ts_idx_read < 0) in ice_ptp_complete_tx_single_tstamp()
586 ice_trace(tx_tstamp_fw_done, tx->tstamps[idx].skb, idx); in ice_ptp_complete_tx_single_tstamp()
588 val = rd32(&pf->hw, PF_SB_ATQBAL); in ice_ptp_complete_tx_single_tstamp()
592 dev_err(ice_pf_to_dev(pf), "Failed to get the Tx tstamp - FW not ready"); in ice_ptp_complete_tx_single_tstamp()
601 raw_tstamp |= (u64)rd32(&pf->hw, PF_SB_ATQBAH); in ice_ptp_complete_tx_single_tstamp()
606 if (raw_tstamp == tx->tstamps[idx].cached_tstamp) in ice_ptp_complete_tx_single_tstamp()
609 tx->tstamps[idx].cached_tstamp = raw_tstamp; in ice_ptp_complete_tx_single_tstamp()
610 clear_bit(idx, tx->in_use); in ice_ptp_complete_tx_single_tstamp()
611 skb = tx->tstamps[idx].skb; in ice_ptp_complete_tx_single_tstamp()
612 tx->tstamps[idx].skb = NULL; in ice_ptp_complete_tx_single_tstamp()
613 if (test_and_clear_bit(idx, tx->stale)) in ice_ptp_complete_tx_single_tstamp()
636 * ice_ptp_process_tx_tstamp - Process Tx timestamps for a port
660 * removed. A timestamp index will never be re-used until the in_use bit for
664 * right away but we will notice it at the end when we re-queue the task.
667 * interrupt for that timestamp should re-trigger this function once
696 hw = &pf->hw; in ice_ptp_process_tx_tstamp()
699 if (tx->has_ready_bitmap) { in ice_ptp_process_tx_tstamp()
700 err = ice_get_phy_tx_tstamp_ready(hw, tx->block, &tstamp_ready); in ice_ptp_process_tx_tstamp()
706 link_up = ptp_port->link_up; in ice_ptp_process_tx_tstamp()
708 for_each_set_bit(idx, tx->in_use, tx->len) { in ice_ptp_process_tx_tstamp()
710 u8 phy_idx = idx + tx->offset; in ice_ptp_process_tx_tstamp()
716 if (time_is_before_jiffies(tx->tstamps[idx].start + 2 * HZ)) { in ice_ptp_process_tx_tstamp()
720 pf->ptp.tx_hwtstamp_timeouts++; in ice_ptp_process_tx_tstamp()
731 if (tx->has_ready_bitmap && in ice_ptp_process_tx_tstamp()
739 ice_trace(tx_tstamp_fw_req, tx->tstamps[idx].skb, idx); in ice_ptp_process_tx_tstamp()
741 err = ice_read_phy_tstamp(hw, tx->block, phy_idx, &raw_tstamp); in ice_ptp_process_tx_tstamp()
745 ice_trace(tx_tstamp_fw_done, tx->tstamps[idx].skb, idx); in ice_ptp_process_tx_tstamp()
752 if (!drop_ts && !tx->has_ready_bitmap && in ice_ptp_process_tx_tstamp()
753 raw_tstamp == tx->tstamps[idx].cached_tstamp) in ice_ptp_process_tx_tstamp()
761 spin_lock_irqsave(&tx->lock, flags); in ice_ptp_process_tx_tstamp()
762 if (!tx->has_ready_bitmap && raw_tstamp) in ice_ptp_process_tx_tstamp()
763 tx->tstamps[idx].cached_tstamp = raw_tstamp; in ice_ptp_process_tx_tstamp()
764 clear_bit(idx, tx->in_use); in ice_ptp_process_tx_tstamp()
765 skb = tx->tstamps[idx].skb; in ice_ptp_process_tx_tstamp()
766 tx->tstamps[idx].skb = NULL; in ice_ptp_process_tx_tstamp()
767 if (test_and_clear_bit(idx, tx->stale)) in ice_ptp_process_tx_tstamp()
769 spin_unlock_irqrestore(&tx->lock, flags); in ice_ptp_process_tx_tstamp()
795 * ice_ptp_tx_tstamp_owner - Process Tx timestamps for all ports on the device
803 mutex_lock(&pf->ptp.ports_owner.lock); in ice_ptp_tx_tstamp_owner()
804 list_for_each_entry(port, &pf->ptp.ports_owner.ports, list_member) { in ice_ptp_tx_tstamp_owner()
805 struct ice_ptp_tx *tx = &port->tx; in ice_ptp_tx_tstamp_owner()
807 if (!tx || !tx->init) in ice_ptp_tx_tstamp_owner()
812 mutex_unlock(&pf->ptp.ports_owner.lock); in ice_ptp_tx_tstamp_owner()
814 for (i = 0; i < ICE_GET_QUAD_NUM(pf->hw.ptp.num_lports); i++) { in ice_ptp_tx_tstamp_owner()
819 err = ice_get_phy_tx_tstamp_ready(&pf->hw, i, &tstamp_ready); in ice_ptp_tx_tstamp_owner()
830 * ice_ptp_tx_tstamp - Process Tx timestamps for this function.
841 if (!tx->init) in ice_ptp_tx_tstamp()
848 spin_lock_irqsave(&tx->lock, flags); in ice_ptp_tx_tstamp()
849 more_timestamps = tx->init && !bitmap_empty(tx->in_use, tx->len); in ice_ptp_tx_tstamp()
850 spin_unlock_irqrestore(&tx->lock, flags); in ice_ptp_tx_tstamp()
859 * ice_ptp_alloc_tx_tracker - Initialize tracking for Tx timestamps
871 tstamps = kcalloc(tx->len, sizeof(*tstamps), GFP_KERNEL); in ice_ptp_alloc_tx_tracker()
872 in_use = bitmap_zalloc(tx->len, GFP_KERNEL); in ice_ptp_alloc_tx_tracker()
873 stale = bitmap_zalloc(tx->len, GFP_KERNEL); in ice_ptp_alloc_tx_tracker()
880 return -ENOMEM; in ice_ptp_alloc_tx_tracker()
883 tx->tstamps = tstamps; in ice_ptp_alloc_tx_tracker()
884 tx->in_use = in_use; in ice_ptp_alloc_tx_tracker()
885 tx->stale = stale; in ice_ptp_alloc_tx_tracker()
886 tx->init = 1; in ice_ptp_alloc_tx_tracker()
887 tx->last_ll_ts_idx_read = -1; in ice_ptp_alloc_tx_tracker()
889 spin_lock_init(&tx->lock); in ice_ptp_alloc_tx_tracker()
895 * ice_ptp_flush_tx_tracker - Flush any remaining timestamps from the tracker
904 struct ice_hw *hw = &pf->hw; in ice_ptp_flush_tx_tracker()
910 err = ice_get_phy_tx_tstamp_ready(hw, tx->block, &tstamp_ready); in ice_ptp_flush_tx_tracker()
913 tx->block, err); in ice_ptp_flush_tx_tracker()
921 for_each_set_bit(idx, tx->in_use, tx->len) { in ice_ptp_flush_tx_tracker()
922 u8 phy_idx = idx + tx->offset; in ice_ptp_flush_tx_tracker()
926 if (!hw->reset_ongoing && (tstamp_ready & BIT_ULL(phy_idx))) in ice_ptp_flush_tx_tracker()
927 ice_clear_phy_tstamp(hw, tx->block, phy_idx); in ice_ptp_flush_tx_tracker()
929 spin_lock_irqsave(&tx->lock, flags); in ice_ptp_flush_tx_tracker()
930 skb = tx->tstamps[idx].skb; in ice_ptp_flush_tx_tracker()
931 tx->tstamps[idx].skb = NULL; in ice_ptp_flush_tx_tracker()
932 clear_bit(idx, tx->in_use); in ice_ptp_flush_tx_tracker()
933 clear_bit(idx, tx->stale); in ice_ptp_flush_tx_tracker()
934 spin_unlock_irqrestore(&tx->lock, flags); in ice_ptp_flush_tx_tracker()
937 pf->ptp.tx_hwtstamp_flushed++; in ice_ptp_flush_tx_tracker()
945 * ice_ptp_mark_tx_tracker_stale - Mark unfinished timestamps as stale
960 spin_lock_irqsave(&tx->lock, flags); in ice_ptp_mark_tx_tracker_stale()
961 bitmap_or(tx->stale, tx->stale, tx->in_use, tx->len); in ice_ptp_mark_tx_tracker_stale()
962 spin_unlock_irqrestore(&tx->lock, flags); in ice_ptp_mark_tx_tracker_stale()
966 * ice_ptp_flush_all_tx_tracker - Flush all timestamp trackers on this clock
977 list_for_each_entry(port, &pf->ptp.ports_owner.ports, list_member) in ice_ptp_flush_all_tx_tracker()
978 ice_ptp_flush_tx_tracker(ptp_port_to_pf(port), &port->tx); in ice_ptp_flush_all_tx_tracker()
982 * ice_ptp_release_tx_tracker - Release allocated memory for Tx tracker
993 spin_lock_irqsave(&tx->lock, flags); in ice_ptp_release_tx_tracker()
994 tx->init = 0; in ice_ptp_release_tx_tracker()
995 spin_unlock_irqrestore(&tx->lock, flags); in ice_ptp_release_tx_tracker()
998 synchronize_irq(pf->oicr_irq.virq); in ice_ptp_release_tx_tracker()
1002 kfree(tx->tstamps); in ice_ptp_release_tx_tracker()
1003 tx->tstamps = NULL; in ice_ptp_release_tx_tracker()
1005 bitmap_free(tx->in_use); in ice_ptp_release_tx_tracker()
1006 tx->in_use = NULL; in ice_ptp_release_tx_tracker()
1008 bitmap_free(tx->stale); in ice_ptp_release_tx_tracker()
1009 tx->stale = NULL; in ice_ptp_release_tx_tracker()
1011 tx->len = 0; in ice_ptp_release_tx_tracker()
1015 * ice_ptp_init_tx_eth56g - Initialize tracking for Tx timestamps
1023 * Return: 0 for success, -ENOMEM when failed to allocate Tx tracker
1028 tx->block = port; in ice_ptp_init_tx_eth56g()
1029 tx->offset = 0; in ice_ptp_init_tx_eth56g()
1030 tx->len = INDEX_PER_PORT_ETH56G; in ice_ptp_init_tx_eth56g()
1031 tx->has_ready_bitmap = 1; in ice_ptp_init_tx_eth56g()
1037 * ice_ptp_init_tx_e82x - Initialize tracking for Tx timestamps
1043 * the timestamp block is shared for all ports in the same quad. To avoid
1050 tx->block = ICE_GET_QUAD_NUM(port); in ice_ptp_init_tx_e82x()
1051 tx->offset = (port % ICE_PORTS_PER_QUAD) * INDEX_PER_PORT_E82X; in ice_ptp_init_tx_e82x()
1052 tx->len = INDEX_PER_PORT_E82X; in ice_ptp_init_tx_e82x()
1053 tx->has_ready_bitmap = 1; in ice_ptp_init_tx_e82x()
1059 * ice_ptp_init_tx_e810 - Initialize tracking for Tx timestamps
1069 tx->block = pf->hw.port_info->lport; in ice_ptp_init_tx_e810()
1070 tx->offset = 0; in ice_ptp_init_tx_e810()
1071 tx->len = INDEX_PER_PORT_E810; in ice_ptp_init_tx_e810()
1076 tx->has_ready_bitmap = 0; in ice_ptp_init_tx_e810()
1082 * ice_ptp_update_cached_phctime - Update the cached PHC time values
1095 * * 0 - OK, successfully updated
1096 * * -EAGAIN - PF was busy, need to reschedule the update
1105 update_before = pf->ptp.cached_phc_jiffies + msecs_to_jiffies(2000); in ice_ptp_update_cached_phctime()
1106 if (pf->ptp.cached_phc_time && in ice_ptp_update_cached_phctime()
1108 unsigned long time_taken = jiffies - pf->ptp.cached_phc_jiffies; in ice_ptp_update_cached_phctime()
1112 pf->ptp.late_cached_phc_updates++; in ice_ptp_update_cached_phctime()
1119 WRITE_ONCE(pf->ptp.cached_phc_time, systime); in ice_ptp_update_cached_phctime()
1120 WRITE_ONCE(pf->ptp.cached_phc_jiffies, jiffies); in ice_ptp_update_cached_phctime()
1122 if (test_and_set_bit(ICE_CFG_BUSY, pf->state)) in ice_ptp_update_cached_phctime()
1123 return -EAGAIN; in ice_ptp_update_cached_phctime()
1126 struct ice_vsi *vsi = pf->vsi[i]; in ice_ptp_update_cached_phctime()
1132 if (vsi->type != ICE_VSI_PF) in ice_ptp_update_cached_phctime()
1136 if (!vsi->rx_rings[j]) in ice_ptp_update_cached_phctime()
1138 WRITE_ONCE(vsi->rx_rings[j]->cached_phctime, systime); in ice_ptp_update_cached_phctime()
1141 clear_bit(ICE_CFG_BUSY, pf->state); in ice_ptp_update_cached_phctime()
1147 * ice_ptp_reset_cached_phctime - Reset cached PHC time after an update
1177 kthread_queue_delayed_work(pf->ptp.kworker, &pf->ptp.work, in ice_ptp_reset_cached_phctime()
1186 ice_ptp_mark_tx_tracker_stale(&pf->ptp.port.tx); in ice_ptp_reset_cached_phctime()
1190 * ice_ptp_write_init - Set PHC time to provided value
1199 struct ice_hw *hw = &pf->hw; in ice_ptp_write_init()
1205 * ice_ptp_write_adj - Adjust PHC clock time atomically
1214 struct ice_hw *hw = &pf->hw; in ice_ptp_write_adj()
1220 * ice_base_incval - Get base timer increment value
1230 struct ice_hw *hw = &pf->hw; in ice_base_incval()
1242 * ice_ptp_check_tx_fifo - Check whether Tx FIFO is in an OK state
1247 int offs = port->port_num % ICE_PORTS_PER_QUAD; in ice_ptp_check_tx_fifo()
1248 int quad = ICE_GET_QUAD_NUM(port->port_num); in ice_ptp_check_tx_fifo() local
1255 hw = &pf->hw; in ice_ptp_check_tx_fifo()
1257 if (port->tx_fifo_busy_cnt == FIFO_OK) in ice_ptp_check_tx_fifo()
1262 err = ice_read_quad_reg_e82x(hw, quad, Q_REG_FIFO01_STATUS, in ice_ptp_check_tx_fifo()
1265 err = ice_read_quad_reg_e82x(hw, quad, Q_REG_FIFO23_STATUS, in ice_ptp_check_tx_fifo()
1270 port->port_num, err); in ice_ptp_check_tx_fifo()
1280 port->tx_fifo_busy_cnt = FIFO_OK; in ice_ptp_check_tx_fifo()
1284 port->tx_fifo_busy_cnt++; in ice_ptp_check_tx_fifo()
1287 port->tx_fifo_busy_cnt, port->port_num); in ice_ptp_check_tx_fifo()
1289 if (port->tx_fifo_busy_cnt == ICE_PTP_FIFO_NUM_CHECKS) { in ice_ptp_check_tx_fifo()
1291 "Port %d Tx FIFO still not empty; resetting quad %d\n", in ice_ptp_check_tx_fifo()
1292 port->port_num, quad); in ice_ptp_check_tx_fifo()
1293 ice_ptp_reset_ts_memory_quad_e82x(hw, quad); in ice_ptp_check_tx_fifo()
1294 port->tx_fifo_busy_cnt = FIFO_OK; in ice_ptp_check_tx_fifo()
1298 return -EAGAIN; in ice_ptp_check_tx_fifo()
1302 * ice_ptp_wait_for_offsets - Check for valid Tx and Rx offsets
1326 hw = &pf->hw; in ice_ptp_wait_for_offsets()
1328 if (ice_is_reset_in_progress(pf->state)) { in ice_ptp_wait_for_offsets()
1330 kthread_queue_delayed_work(pf->ptp.kworker, in ice_ptp_wait_for_offsets()
1331 &port->ov_work, in ice_ptp_wait_for_offsets()
1338 tx_err = ice_phy_cfg_tx_offset_e82x(hw, port->port_num); in ice_ptp_wait_for_offsets()
1339 rx_err = ice_phy_cfg_rx_offset_e82x(hw, port->port_num); in ice_ptp_wait_for_offsets()
1342 kthread_queue_delayed_work(pf->ptp.kworker, in ice_ptp_wait_for_offsets()
1343 &port->ov_work, in ice_ptp_wait_for_offsets()
1350 * ice_ptp_port_phy_stop - Stop timestamping for a PHY port
1357 u8 port = ptp_port->port_num; in ice_ptp_port_phy_stop()
1358 struct ice_hw *hw = &pf->hw; in ice_ptp_port_phy_stop()
1364 mutex_lock(&ptp_port->ps_lock); in ice_ptp_port_phy_stop()
1366 switch (hw->ptp.phy_model) { in ice_ptp_port_phy_stop()
1371 kthread_cancel_delayed_work_sync(&ptp_port->ov_work); in ice_ptp_port_phy_stop()
1376 err = -ENODEV; in ice_ptp_port_phy_stop()
1378 if (err && err != -EBUSY) in ice_ptp_port_phy_stop()
1382 mutex_unlock(&ptp_port->ps_lock); in ice_ptp_port_phy_stop()
1388 * ice_ptp_port_phy_restart - (Re)start and calibrate PHY timestamping
1399 u8 port = ptp_port->port_num; in ice_ptp_port_phy_restart()
1400 struct ice_hw *hw = &pf->hw; in ice_ptp_port_phy_restart()
1407 if (!ptp_port->link_up) in ice_ptp_port_phy_restart()
1410 mutex_lock(&ptp_port->ps_lock); in ice_ptp_port_phy_restart()
1412 switch (hw->ptp.phy_model) { in ice_ptp_port_phy_restart()
1418 kthread_cancel_delayed_work_sync(&ptp_port->ov_work); in ice_ptp_port_phy_restart()
1423 spin_lock_irqsave(&ptp_port->tx.lock, flags); in ice_ptp_port_phy_restart()
1424 ptp_port->tx.calibrating = true; in ice_ptp_port_phy_restart()
1425 spin_unlock_irqrestore(&ptp_port->tx.lock, flags); in ice_ptp_port_phy_restart()
1426 ptp_port->tx_fifo_busy_cnt = 0; in ice_ptp_port_phy_restart()
1434 spin_lock_irqsave(&ptp_port->tx.lock, flags); in ice_ptp_port_phy_restart()
1435 ptp_port->tx.calibrating = false; in ice_ptp_port_phy_restart()
1436 spin_unlock_irqrestore(&ptp_port->tx.lock, flags); in ice_ptp_port_phy_restart()
1438 kthread_queue_delayed_work(pf->ptp.kworker, &ptp_port->ov_work, in ice_ptp_port_phy_restart()
1442 err = -ENODEV; in ice_ptp_port_phy_restart()
1449 mutex_unlock(&ptp_port->ps_lock); in ice_ptp_port_phy_restart()
1455 * ice_ptp_link_change - Reconfigure PTP after link status change
1463 struct ice_hw *hw = &pf->hw; in ice_ptp_link_change()
1465 if (pf->ptp.state != ICE_PTP_READY) in ice_ptp_link_change()
1468 if (WARN_ON_ONCE(port >= hw->ptp.num_lports)) in ice_ptp_link_change()
1471 ptp_port = &pf->ptp.port; in ice_ptp_link_change()
1472 if (ice_is_e825c(hw) && hw->ptp.is_2x50g_muxed_topo) in ice_ptp_link_change()
1474 if (WARN_ON_ONCE(ptp_port->port_num != port)) in ice_ptp_link_change()
1478 ptp_port->link_up = linkup; in ice_ptp_link_change()
1481 if (pf->hw.reset_ongoing) in ice_ptp_link_change()
1484 switch (hw->ptp.phy_model) { in ice_ptp_link_change()
1498 * ice_ptp_cfg_phy_interrupt - Configure PHY interrupt settings
1507 * Return: 0 on success, -EOPNOTSUPP when PHY model incorrect, other error codes
1513 struct ice_hw *hw = &pf->hw; in ice_ptp_cfg_phy_interrupt()
1517 switch (hw->ptp.phy_model) { in ice_ptp_cfg_phy_interrupt()
1521 for (port = 0; port < hw->ptp.num_lports; port++) { in ice_ptp_cfg_phy_interrupt()
1535 int quad; in ice_ptp_cfg_phy_interrupt() local
1537 for (quad = 0; quad < ICE_GET_QUAD_NUM(hw->ptp.num_lports); in ice_ptp_cfg_phy_interrupt()
1538 quad++) { in ice_ptp_cfg_phy_interrupt()
1541 err = ice_phy_cfg_intr_e82x(hw, quad, ena, threshold); in ice_ptp_cfg_phy_interrupt()
1543 dev_err(dev, "Failed to configure PHY interrupt for quad %d, err %d\n", in ice_ptp_cfg_phy_interrupt()
1544 quad, err); in ice_ptp_cfg_phy_interrupt()
1556 hw->ptp.phy_model); in ice_ptp_cfg_phy_interrupt()
1557 return -EOPNOTSUPP; in ice_ptp_cfg_phy_interrupt()
1562 * ice_ptp_reset_phy_timestamping - Reset PHY timestamping block
1567 ice_ptp_port_phy_restart(&pf->ptp.port); in ice_ptp_reset_phy_timestamping()
1571 * ice_ptp_restart_all_phy - Restart all PHYs to recalibrate timestamping
1578 list_for_each(entry, &pf->ptp.ports_owner.ports) { in ice_ptp_restart_all_phy()
1583 if (port->link_up) in ice_ptp_restart_all_phy()
1589 * ice_ptp_adjfine - Adjust clock increment rate
1591 * @scaled_ppm: Parts per million with 16-bit fractional field
1599 struct ice_hw *hw = &pf->hw; in ice_ptp_adjfine()
1608 return -EIO; in ice_ptp_adjfine()
1615 * ice_ptp_extts_event - Process PTP external clock event
1621 struct ice_hw *hw = &pf->hw; in ice_ptp_extts_event()
1626 if (pf->ptp.state != ICE_PTP_READY) in ice_ptp_extts_event()
1629 tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned; in ice_ptp_extts_event()
1637 if (pf->ptp.ext_ts_irq & (1 << chan)) { in ice_ptp_extts_event()
1645 ptp_clock_event(pf->ptp.clock, &event); in ice_ptp_extts_event()
1646 pf->ptp.ext_ts_irq &= ~(1 << chan); in ice_ptp_extts_event()
1652 * ice_ptp_cfg_extts - Configure EXTTS pin and channel
1654 * @chan: GPIO channel (0-3)
1660 * Return: 0 on success, -EOPNOTUSPP on unsupported flags
1666 struct ice_hw *hw = &pf->hw; in ice_ptp_cfg_extts()
1670 if (config->flags & ~(PTP_ENABLE_FEATURE | in ice_ptp_cfg_extts()
1674 return -EOPNOTSUPP; in ice_ptp_cfg_extts()
1676 tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned; in ice_ptp_cfg_extts()
1680 if (config->ena) { in ice_ptp_cfg_extts()
1689 if (config->flags & PTP_FALLING_EDGE) in ice_ptp_cfg_extts()
1691 if (config->flags & PTP_RISING_EDGE) in ice_ptp_cfg_extts()
1700 pf->ptp.ext_ts_chan |= (1 << chan); in ice_ptp_cfg_extts()
1705 pf->ptp.ext_ts_chan &= ~(1 << chan); in ice_ptp_cfg_extts()
1706 if (!pf->ptp.ext_ts_chan) in ice_ptp_cfg_extts()
1712 wr32(hw, GLGEN_GPIO_CTL(config->gpio_pin), gpio_reg); in ice_ptp_cfg_extts()
1715 memcpy(&pf->ptp.extts_channels[chan], config, sizeof(*config)); in ice_ptp_cfg_extts()
1721 * ice_ptp_disable_all_extts - Disable all EXTTS channels
1729 for (i = 0; i < pf->ptp.info.n_ext_ts; i++) { in ice_ptp_disable_all_extts()
1730 if (pf->ptp.extts_channels[i].ena) { in ice_ptp_disable_all_extts()
1731 extts_cfg.gpio_pin = pf->ptp.extts_channels[i].gpio_pin; in ice_ptp_disable_all_extts()
1737 synchronize_irq(pf->oicr_irq.virq); in ice_ptp_disable_all_extts()
1741 * ice_ptp_enable_all_extts - Enable all EXTTS channels
1750 for (i = 0; i < pf->ptp.info.n_ext_ts; i++) { in ice_ptp_enable_all_extts()
1751 if (pf->ptp.extts_channels[i].ena) in ice_ptp_enable_all_extts()
1752 ice_ptp_cfg_extts(pf, i, &pf->ptp.extts_channels[i], in ice_ptp_enable_all_extts()
1758 * ice_ptp_cfg_clkout - Configure clock to generate periodic wave
1760 * @chan: GPIO channel (0-3)
1770 u64 current_time, period, start_time, phase; in ice_ptp_cfg_clkout() local
1771 struct ice_hw *hw = &pf->hw; in ice_ptp_cfg_clkout()
1775 if (config && config->flags & ~PTP_PEROUT_PHASE) in ice_ptp_cfg_clkout()
1776 return -EOPNOTSUPP; in ice_ptp_cfg_clkout()
1778 tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned; in ice_ptp_cfg_clkout()
1786 if (!config || !config->ena) { in ice_ptp_cfg_clkout()
1792 gpio_pin = pf->ptp.perout_channels[chan].gpio_pin; in ice_ptp_cfg_clkout()
1797 memset(&pf->ptp.perout_channels[chan], 0, in ice_ptp_cfg_clkout()
1802 period = config->period; in ice_ptp_cfg_clkout()
1803 start_time = config->start_time; in ice_ptp_cfg_clkout()
1804 div64_u64_rem(start_time, period, &phase); in ice_ptp_cfg_clkout()
1805 gpio_pin = config->gpio_pin; in ice_ptp_cfg_clkout()
1830 * maintaining phase in ice_ptp_cfg_clkout()
1833 start_time = roundup_u64(current_time, NSEC_PER_SEC) + phase; in ice_ptp_cfg_clkout()
1836 start_time -= E810_OUT_PROP_DELAY_NS; in ice_ptp_cfg_clkout()
1838 start_time -= ice_e82x_pps_delay(ice_e82x_time_ref(hw)); in ice_ptp_cfg_clkout()
1856 memcpy(&pf->ptp.perout_channels[chan], config, in ice_ptp_cfg_clkout()
1858 pf->ptp.perout_channels[chan].start_time = phase; in ice_ptp_cfg_clkout()
1864 return -EFAULT; in ice_ptp_cfg_clkout()
1868 * ice_ptp_disable_all_clkout - Disable all currently configured outputs
1873 * re-enable the clocks again.
1879 for (i = 0; i < pf->ptp.info.n_per_out; i++) in ice_ptp_disable_all_clkout()
1880 if (pf->ptp.perout_channels[i].ena) in ice_ptp_disable_all_clkout()
1885 * ice_ptp_enable_all_clkout - Enable all configured periodic clock outputs
1896 for (i = 0; i < pf->ptp.info.n_per_out; i++) in ice_ptp_enable_all_clkout()
1897 if (pf->ptp.perout_channels[i].ena) in ice_ptp_enable_all_clkout()
1898 ice_ptp_cfg_clkout(pf, i, &pf->ptp.perout_channels[i], in ice_ptp_enable_all_clkout()
1903 * ice_ptp_gpio_enable_e810 - Enable/disable ancillary features of PHC
1920 switch (rq->type) { in ice_ptp_gpio_enable_e810()
1925 chan = rq->perout.index; in ice_ptp_gpio_enable_e810()
1932 return -1; in ice_ptp_gpio_enable_e810()
1933 } else if (ice_is_e810t(&pf->hw)) { in ice_ptp_gpio_enable_e810()
1944 clk_cfg.flags = rq->perout.flags; in ice_ptp_gpio_enable_e810()
1945 clk_cfg.period = ((rq->perout.period.sec * NSEC_PER_SEC) + in ice_ptp_gpio_enable_e810()
1946 rq->perout.period.nsec); in ice_ptp_gpio_enable_e810()
1947 clk_cfg.start_time = ((rq->perout.start.sec * NSEC_PER_SEC) + in ice_ptp_gpio_enable_e810()
1948 rq->perout.start.nsec); in ice_ptp_gpio_enable_e810()
1957 chan = rq->extts.index; in ice_ptp_gpio_enable_e810()
1963 } else if (ice_is_e810t(&pf->hw)) { in ice_ptp_gpio_enable_e810()
1972 extts_cfg.flags = rq->extts.flags; in ice_ptp_gpio_enable_e810()
1979 return -EOPNOTSUPP; in ice_ptp_gpio_enable_e810()
1984 * ice_ptp_gpio_enable_e823 - Enable/disable ancillary features of PHC
1994 switch (rq->type) { in ice_ptp_gpio_enable_e823()
1999 clk_cfg.flags = rq->perout.flags; in ice_ptp_gpio_enable_e823()
2010 extts_cfg.flags = rq->extts.flags; in ice_ptp_gpio_enable_e823()
2014 return ice_ptp_cfg_extts(pf, rq->extts.index, &extts_cfg, true); in ice_ptp_gpio_enable_e823()
2017 return -EOPNOTSUPP; in ice_ptp_gpio_enable_e823()
2022 * ice_ptp_gettimex64 - Get the time of the clock
2044 * ice_ptp_settime64 - Set the time of the clock
2056 struct ice_hw *hw = &pf->hw; in ice_ptp_settime64()
2062 if (hw->ptp.phy_model == ICE_PHY_E82X) { in ice_ptp_settime64()
2069 err = -EBUSY; in ice_ptp_settime64()
2085 /* Recalibrate and re-enable timestamp blocks for E822/E823 */ in ice_ptp_settime64()
2086 if (hw->ptp.phy_model == ICE_PHY_E82X) in ice_ptp_settime64()
2098 * ice_ptp_adjtime_nonatomic - Do a non-atomic clock adjustment
2117 * ice_ptp_adjtime - Adjust the time of the clock by the indicated delta
2124 struct ice_hw *hw = &pf->hw; in ice_ptp_adjtime()
2130 /* Hardware only supports atomic adjustments using signed 32-bit in ice_ptp_adjtime()
2132 * a non-atomic get->adjust->set flow. in ice_ptp_adjtime()
2135 dev_dbg(dev, "delta = %lld, adjtime non-atomic\n", delta); in ice_ptp_adjtime()
2141 return -EBUSY; in ice_ptp_adjtime()
2166 * ice_ptp_get_syncdevicetime - Get the cross time stamp info
2180 struct ice_hw *hw = &pf->hw; in ice_ptp_get_syncdevicetime()
2189 hh_lock = rd32(hw, PFHH_SEM + (PFTSYN_SEM_BYTES * hw->pf_id)); in ice_ptp_get_syncdevicetime()
2198 return -EBUSY; in ice_ptp_get_syncdevicetime()
2219 tmr_idx = hw->func_caps.ts_func_info.tmr_index_assoc; in ice_ptp_get_syncdevicetime()
2224 system->cycles = hh_ts; in ice_ptp_get_syncdevicetime()
2225 system->cs_id = CSID_X86_ART; in ice_ptp_get_syncdevicetime()
2239 hh_lock = rd32(hw, PFHH_SEM + (PFTSYN_SEM_BYTES * hw->pf_id)); in ice_ptp_get_syncdevicetime()
2241 wr32(hw, PFHH_SEM + (PFTSYN_SEM_BYTES * hw->pf_id), hh_lock); in ice_ptp_get_syncdevicetime()
2244 return -ETIMEDOUT; in ice_ptp_get_syncdevicetime()
2250 * ice_ptp_getcrosststamp_e82x - Capture a device cross timestamp
2276 * ice_ptp_get_ts_config - ioctl interface to read the timestamping config
2286 if (pf->ptp.state != ICE_PTP_READY) in ice_ptp_get_ts_config()
2287 return -EIO; in ice_ptp_get_ts_config()
2289 config = &pf->ptp.tstamp_config; in ice_ptp_get_ts_config()
2291 return copy_to_user(ifr->ifr_data, config, sizeof(*config)) ? in ice_ptp_get_ts_config()
2292 -EFAULT : 0; in ice_ptp_get_ts_config()
2296 * ice_ptp_set_timestamp_mode - Setup driver for requested timestamp mode
2303 switch (config->tx_type) { in ice_ptp_set_timestamp_mode()
2305 pf->ptp.tstamp_config.tx_type = HWTSTAMP_TX_OFF; in ice_ptp_set_timestamp_mode()
2308 pf->ptp.tstamp_config.tx_type = HWTSTAMP_TX_ON; in ice_ptp_set_timestamp_mode()
2311 return -ERANGE; in ice_ptp_set_timestamp_mode()
2314 switch (config->rx_filter) { in ice_ptp_set_timestamp_mode()
2316 pf->ptp.tstamp_config.rx_filter = HWTSTAMP_FILTER_NONE; in ice_ptp_set_timestamp_mode()
2332 pf->ptp.tstamp_config.rx_filter = HWTSTAMP_FILTER_ALL; in ice_ptp_set_timestamp_mode()
2335 return -ERANGE; in ice_ptp_set_timestamp_mode()
2345 * ice_ptp_set_ts_config - ioctl interface to control the timestamping
2356 if (pf->ptp.state != ICE_PTP_READY) in ice_ptp_set_ts_config()
2357 return -EAGAIN; in ice_ptp_set_ts_config()
2359 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) in ice_ptp_set_ts_config()
2360 return -EFAULT; in ice_ptp_set_ts_config()
2367 config = pf->ptp.tstamp_config; in ice_ptp_set_ts_config()
2369 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? in ice_ptp_set_ts_config()
2370 -EFAULT : 0; in ice_ptp_set_ts_config()
2374 * ice_ptp_get_rx_hwts - Get packet Rx timestamp in ns
2386 if (!(rx_desc->wb.time_stamp_low & ICE_PTP_TS_VALID)) in ice_ptp_get_rx_hwts()
2389 cached_time = READ_ONCE(pkt_ctx->cached_phctime); in ice_ptp_get_rx_hwts()
2395 /* Use ice_ptp_extend_32b_ts directly, using the ring-specific cached in ice_ptp_get_rx_hwts()
2401 ts_high = le32_to_cpu(rx_desc->wb.flex_ts.ts_high); in ice_ptp_get_rx_hwts()
2408 * ice_ptp_disable_sma_pins_e810t - Disable E810-T SMA pins
2413 * indications of pin support when we fail to setup the E810-T SMA control
2421 dev_warn(dev, "Failed to configure E810-T SMA pin control\n"); in ice_ptp_disable_sma_pins_e810t()
2423 info->enable = NULL; in ice_ptp_disable_sma_pins_e810t()
2424 info->verify = NULL; in ice_ptp_disable_sma_pins_e810t()
2425 info->n_pins = 0; in ice_ptp_disable_sma_pins_e810t()
2426 info->n_ext_ts = 0; in ice_ptp_disable_sma_pins_e810t()
2427 info->n_per_out = 0; in ice_ptp_disable_sma_pins_e810t()
2431 * ice_ptp_setup_sma_pins_e810t - Setup the SMA pins
2446 info->pin_config = devm_kcalloc(dev, info->n_pins, in ice_ptp_setup_sma_pins_e810t()
2447 sizeof(*info->pin_config), GFP_KERNEL); in ice_ptp_setup_sma_pins_e810t()
2448 if (!info->pin_config) { in ice_ptp_setup_sma_pins_e810t()
2454 err = ice_get_sma_config_e810t(&pf->hw, info->pin_config); in ice_ptp_setup_sma_pins_e810t()
2460 * ice_ptp_setup_pins_e810 - Setup PTP pins in sysfs
2468 info->n_ext_ts = N_EXT_TS_E810; in ice_ptp_setup_pins_e810()
2469 info->n_per_out = N_PER_OUT_E810T; in ice_ptp_setup_pins_e810()
2470 info->n_pins = NUM_PTP_PINS_E810T; in ice_ptp_setup_pins_e810()
2471 info->verify = ice_verify_pin_e810t; in ice_ptp_setup_pins_e810()
2475 } else if (ice_is_e810t(&pf->hw)) { in ice_ptp_setup_pins_e810()
2476 info->n_ext_ts = N_EXT_TS_NO_SMA_E810T; in ice_ptp_setup_pins_e810()
2477 info->n_per_out = N_PER_OUT_NO_SMA_E810T; in ice_ptp_setup_pins_e810()
2479 info->n_per_out = N_PER_OUT_E810; in ice_ptp_setup_pins_e810()
2480 info->n_ext_ts = N_EXT_TS_E810; in ice_ptp_setup_pins_e810()
2485 * ice_ptp_setup_pins_e823 - Setup PTP pins in sysfs
2492 info->pps = 1; in ice_ptp_setup_pins_e823()
2493 info->n_per_out = 0; in ice_ptp_setup_pins_e823()
2494 info->n_ext_ts = 1; in ice_ptp_setup_pins_e823()
2498 * ice_ptp_set_funcs_e82x - Set specialized functions for E82x support
2513 info->getcrosststamp = ice_ptp_getcrosststamp_e82x; in ice_ptp_set_funcs_e82x()
2518 * ice_ptp_set_funcs_e810 - Set specialized functions for E810 support
2530 info->enable = ice_ptp_gpio_enable_e810; in ice_ptp_set_funcs_e810()
2535 * ice_ptp_set_funcs_e823 - Set specialized functions for E823 support
2549 info->enable = ice_ptp_gpio_enable_e823; in ice_ptp_set_funcs_e823()
2554 * ice_ptp_set_caps - Set PTP capabilities
2559 struct ptp_clock_info *info = &pf->ptp.info; in ice_ptp_set_caps()
2562 snprintf(info->name, sizeof(info->name) - 1, "%s-%s-clk", in ice_ptp_set_caps()
2564 info->owner = THIS_MODULE; in ice_ptp_set_caps()
2565 info->max_adj = 100000000; in ice_ptp_set_caps()
2566 info->adjtime = ice_ptp_adjtime; in ice_ptp_set_caps()
2567 info->adjfine = ice_ptp_adjfine; in ice_ptp_set_caps()
2568 info->gettimex64 = ice_ptp_gettimex64; in ice_ptp_set_caps()
2569 info->settime64 = ice_ptp_settime64; in ice_ptp_set_caps()
2571 if (ice_is_e810(&pf->hw)) in ice_ptp_set_caps()
2573 else if (ice_is_e823(&pf->hw)) in ice_ptp_set_caps()
2580 * ice_ptp_create_clock - Create PTP clock device for userspace
2594 if (pf->ptp.clock) in ice_ptp_create_clock()
2599 info = &pf->ptp.info; in ice_ptp_create_clock()
2603 pf->ptp.clock = ptp_clock_register(info, dev); in ice_ptp_create_clock()
2604 if (IS_ERR(pf->ptp.clock)) { in ice_ptp_create_clock()
2606 return PTR_ERR(pf->ptp.clock); in ice_ptp_create_clock()
2613 * ice_ptp_request_ts - Request an available Tx timestamp index
2622 spin_lock_irqsave(&tx->lock, flags); in ice_ptp_request_ts()
2626 spin_unlock_irqrestore(&tx->lock, flags); in ice_ptp_request_ts()
2627 return -1; in ice_ptp_request_ts()
2631 idx = find_next_zero_bit(tx->in_use, tx->len, in ice_ptp_request_ts()
2632 tx->last_ll_ts_idx_read + 1); in ice_ptp_request_ts()
2633 if (idx == tx->len) in ice_ptp_request_ts()
2634 idx = find_first_zero_bit(tx->in_use, tx->len); in ice_ptp_request_ts()
2636 if (idx < tx->len) { in ice_ptp_request_ts()
2641 set_bit(idx, tx->in_use); in ice_ptp_request_ts()
2642 clear_bit(idx, tx->stale); in ice_ptp_request_ts()
2643 tx->tstamps[idx].start = jiffies; in ice_ptp_request_ts()
2644 tx->tstamps[idx].skb = skb_get(skb); in ice_ptp_request_ts()
2645 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; in ice_ptp_request_ts()
2649 spin_unlock_irqrestore(&tx->lock, flags); in ice_ptp_request_ts()
2651 /* return the appropriate PHY timestamp register index, -1 if no in ice_ptp_request_ts()
2654 if (idx >= tx->len) in ice_ptp_request_ts()
2655 return -1; in ice_ptp_request_ts()
2657 return idx + tx->offset; in ice_ptp_request_ts()
2661 * ice_ptp_process_ts - Process the PTP Tx timestamps
2669 switch (pf->ptp.tx_interrupt_mode) { in ice_ptp_process_ts()
2675 return ice_ptp_tx_tstamp(&pf->ptp.port.tx); in ice_ptp_process_ts()
2681 pf->ptp.tx_interrupt_mode); in ice_ptp_process_ts()
2687 * ice_ptp_maybe_trigger_tx_interrupt - Trigger Tx timstamp interrupt
2702 struct ice_hw *hw = &pf->hw; in ice_ptp_maybe_trigger_tx_interrupt()
2712 for (i = 0; i < ICE_GET_QUAD_NUM(hw->ptp.num_lports); i++) { in ice_ptp_maybe_trigger_tx_interrupt()
2716 err = ice_get_phy_tx_tstamp_ready(&pf->hw, i, &tstamp_ready); in ice_ptp_maybe_trigger_tx_interrupt()
2740 if (pf->ptp.state != ICE_PTP_READY) in ice_ptp_periodic_work()
2748 kthread_queue_delayed_work(ptp->kworker, &ptp->work, in ice_ptp_periodic_work()
2753 * ice_ptp_prepare_for_reset - Prepare PTP for reset
2759 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_prepare_for_reset()
2762 if (ptp->state != ICE_PTP_READY) in ice_ptp_prepare_for_reset()
2765 ptp->state = ICE_PTP_RESETTING; in ice_ptp_prepare_for_reset()
2770 kthread_cancel_delayed_work_sync(&ptp->work); in ice_ptp_prepare_for_reset()
2775 ice_ptp_release_tx_tracker(pf, &pf->ptp.port.tx); in ice_ptp_prepare_for_reset()
2780 src_tmr = ice_get_ptp_src_clock_index(&pf->hw); in ice_ptp_prepare_for_reset()
2783 wr32(&pf->hw, GLTSYN_ENA(src_tmr), (u32)~GLTSYN_ENA_TSYN_ENA_M); in ice_ptp_prepare_for_reset()
2786 ptp->reset_time = ktime_get_real_ns(); in ice_ptp_prepare_for_reset()
2790 * ice_ptp_rebuild_owner - Initialize PTP clock owner after reset
2798 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_rebuild_owner()
2799 struct ice_hw *hw = &pf->hw; in ice_ptp_rebuild_owner()
2810 err = -EBUSY; in ice_ptp_rebuild_owner()
2825 if (ptp->cached_phc_time) { in ice_ptp_rebuild_owner()
2826 time_diff = ktime_get_real_ns() - ptp->reset_time; in ice_ptp_rebuild_owner()
2827 ts = ns_to_timespec64(ptp->cached_phc_time + time_diff); in ice_ptp_rebuild_owner()
2846 /* Enable quad interrupts */ in ice_ptp_rebuild_owner()
2854 /* Re-enable all periodic outputs and external timestamp events */ in ice_ptp_rebuild_owner()
2862 * ice_ptp_rebuild - Initialize PTP hardware clock support after reset
2868 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_rebuild()
2871 if (ptp->state == ICE_PTP_READY) { in ice_ptp_rebuild()
2873 } else if (ptp->state != ICE_PTP_RESETTING) { in ice_ptp_rebuild()
2874 err = -EINVAL; in ice_ptp_rebuild()
2885 ptp->state = ICE_PTP_READY; in ice_ptp_rebuild()
2888 kthread_queue_delayed_work(ptp->kworker, &ptp->work, 0); in ice_ptp_rebuild()
2894 ptp->state = ICE_PTP_ERROR; in ice_ptp_rebuild()
2899 * ice_ptp_aux_dev_to_aux_pf - Get auxiliary PF handle for the auxiliary device
2915 * ice_ptp_aux_dev_to_owner_pf - Get PF handle for the auxiliary device
2925 if (!aux_dev->dev.driver) in ice_ptp_aux_dev_to_owner_pf()
2928 aux_drv = to_auxiliary_drv(aux_dev->dev.driver); in ice_ptp_aux_dev_to_owner_pf()
2936 * ice_ptp_auxbus_probe - Probe auxiliary devices
2947 return -ENODEV; in ice_ptp_auxbus_probe()
2949 INIT_LIST_HEAD(&aux_pf->ptp.port.list_member); in ice_ptp_auxbus_probe()
2950 mutex_lock(&owner_pf->ptp.ports_owner.lock); in ice_ptp_auxbus_probe()
2951 list_add(&aux_pf->ptp.port.list_member, in ice_ptp_auxbus_probe()
2952 &owner_pf->ptp.ports_owner.ports); in ice_ptp_auxbus_probe()
2953 mutex_unlock(&owner_pf->ptp.ports_owner.lock); in ice_ptp_auxbus_probe()
2959 * ice_ptp_auxbus_remove - Remove auxiliary devices from the bus
2967 mutex_lock(&owner_pf->ptp.ports_owner.lock); in ice_ptp_auxbus_remove()
2968 list_del(&aux_pf->ptp.port.list_member); in ice_ptp_auxbus_remove()
2969 mutex_unlock(&owner_pf->ptp.ports_owner.lock); in ice_ptp_auxbus_remove()
3004 * ice_ptp_auxbus_create_id_table - Create auxiliary device ID table
3025 * ice_ptp_register_auxbus_driver - Register PTP auxiliary bus driver
3036 ptp = &pf->ptp; in ice_ptp_register_auxbus_driver()
3038 aux_driver = &ptp->ports_owner.aux_driver; in ice_ptp_register_auxbus_driver()
3039 INIT_LIST_HEAD(&ptp->ports_owner.ports); in ice_ptp_register_auxbus_driver()
3040 mutex_init(&ptp->ports_owner.lock); in ice_ptp_register_auxbus_driver()
3042 pf->pdev->bus->number, PCI_SLOT(pf->pdev->devfn), in ice_ptp_register_auxbus_driver()
3043 ice_get_ptp_src_clock_index(&pf->hw)); in ice_ptp_register_auxbus_driver()
3045 return -ENOMEM; in ice_ptp_register_auxbus_driver()
3047 aux_driver->name = name; in ice_ptp_register_auxbus_driver()
3048 aux_driver->shutdown = ice_ptp_auxbus_shutdown; in ice_ptp_register_auxbus_driver()
3049 aux_driver->suspend = ice_ptp_auxbus_suspend; in ice_ptp_register_auxbus_driver()
3050 aux_driver->remove = ice_ptp_auxbus_remove; in ice_ptp_register_auxbus_driver()
3051 aux_driver->resume = ice_ptp_auxbus_resume; in ice_ptp_register_auxbus_driver()
3052 aux_driver->probe = ice_ptp_auxbus_probe; in ice_ptp_register_auxbus_driver()
3053 aux_driver->id_table = ice_ptp_auxbus_create_id_table(pf, name); in ice_ptp_register_auxbus_driver()
3054 if (!aux_driver->id_table) in ice_ptp_register_auxbus_driver()
3055 return -ENOMEM; in ice_ptp_register_auxbus_driver()
3059 devm_kfree(dev, aux_driver->id_table); in ice_ptp_register_auxbus_driver()
3068 * ice_ptp_unregister_auxbus_driver - Unregister PTP auxiliary bus driver
3073 struct auxiliary_driver *aux_driver = &pf->ptp.ports_owner.aux_driver; in ice_ptp_unregister_auxbus_driver()
3076 devm_kfree(ice_pf_to_dev(pf), aux_driver->id_table); in ice_ptp_unregister_auxbus_driver()
3078 mutex_destroy(&pf->ptp.ports_owner.lock); in ice_ptp_unregister_auxbus_driver()
3082 * ice_ptp_clock_index - Get the PTP clock index for this device
3085 * Returns: the PTP clock index associated with this PF, or -1 if no PTP clock
3094 aux_dev = &pf->ptp.port.aux_dev; in ice_ptp_clock_index()
3097 return -1; in ice_ptp_clock_index()
3098 clock = owner_pf->ptp.clock; in ice_ptp_clock_index()
3100 return clock ? ptp_clock_index(clock) : -1; in ice_ptp_clock_index()
3104 * ice_ptp_init_owner - Initialize PTP_1588_CLOCK device
3113 struct ice_hw *hw = &pf->hw; in ice_ptp_init_owner()
3126 err = -EBUSY; in ice_ptp_init_owner()
3166 ptp_clock_unregister(pf->ptp.clock); in ice_ptp_init_owner()
3168 pf->ptp.clock = NULL; in ice_ptp_init_owner()
3174 * ice_ptp_init_work - Initialize PTP work threads
3183 kthread_init_delayed_work(&ptp->work, ice_ptp_periodic_work); in ice_ptp_init_work()
3188 kworker = kthread_create_worker(0, "ice-ptp-%s", in ice_ptp_init_work()
3193 ptp->kworker = kworker; in ice_ptp_init_work()
3196 kthread_queue_delayed_work(ptp->kworker, &ptp->work, 0); in ice_ptp_init_work()
3202 * ice_ptp_init_port - Initialize PTP port structure
3208 struct ice_hw *hw = &pf->hw; in ice_ptp_init_port()
3210 mutex_init(&ptp_port->ps_lock); in ice_ptp_init_port()
3212 switch (hw->ptp.phy_model) { in ice_ptp_init_port()
3214 return ice_ptp_init_tx_eth56g(pf, &ptp_port->tx, in ice_ptp_init_port()
3215 ptp_port->port_num); in ice_ptp_init_port()
3217 return ice_ptp_init_tx_e810(pf, &ptp_port->tx); in ice_ptp_init_port()
3219 kthread_init_delayed_work(&ptp_port->ov_work, in ice_ptp_init_port()
3222 return ice_ptp_init_tx_e82x(pf, &ptp_port->tx, in ice_ptp_init_port()
3223 ptp_port->port_num); in ice_ptp_init_port()
3225 return -ENODEV; in ice_ptp_init_port()
3239 * ice_ptp_create_auxbus_device - Create PTP auxiliary bus device
3251 ptp = &pf->ptp; in ice_ptp_create_auxbus_device()
3252 id = ptp->port.port_num; in ice_ptp_create_auxbus_device()
3255 aux_dev = &ptp->port.aux_dev; in ice_ptp_create_auxbus_device()
3258 pf->pdev->bus->number, PCI_SLOT(pf->pdev->devfn), in ice_ptp_create_auxbus_device()
3259 ice_get_ptp_src_clock_index(&pf->hw)); in ice_ptp_create_auxbus_device()
3261 return -ENOMEM; in ice_ptp_create_auxbus_device()
3263 aux_dev->name = name; in ice_ptp_create_auxbus_device()
3264 aux_dev->id = id; in ice_ptp_create_auxbus_device()
3265 aux_dev->dev.release = ice_ptp_release_auxbus_device; in ice_ptp_create_auxbus_device()
3266 aux_dev->dev.parent = dev; in ice_ptp_create_auxbus_device()
3286 * ice_ptp_remove_auxbus_device - Remove PTP auxiliary bus device
3291 struct auxiliary_device *aux_dev = &pf->ptp.port.aux_dev; in ice_ptp_remove_auxbus_device()
3300 * ice_ptp_init_tx_interrupt_mode - Initialize device Tx interrupt mode
3305 * E822-based devices, only the clock owner processes the timestamps. Other
3310 switch (pf->hw.ptp.phy_model) { in ice_ptp_init_tx_interrupt_mode()
3316 pf->ptp.tx_interrupt_mode = ICE_PTP_TX_INTERRUPT_ALL; in ice_ptp_init_tx_interrupt_mode()
3318 pf->ptp.tx_interrupt_mode = ICE_PTP_TX_INTERRUPT_NONE; in ice_ptp_init_tx_interrupt_mode()
3322 pf->ptp.tx_interrupt_mode = ICE_PTP_TX_INTERRUPT_SELF; in ice_ptp_init_tx_interrupt_mode()
3327 * ice_ptp_init - Initialize PTP hardware clock support
3340 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_init()
3341 struct ice_hw *hw = &pf->hw; in ice_ptp_init()
3344 ptp->state = ICE_PTP_INITIALIZING; in ice_ptp_init()
3359 ptp->port.port_num = hw->pf_id; in ice_ptp_init()
3360 if (ice_is_e825c(hw) && hw->ptp.is_2x50g_muxed_topo) in ice_ptp_init()
3361 ptp->port.port_num = hw->pf_id * 2; in ice_ptp_init()
3363 err = ice_ptp_init_port(pf, &ptp->port); in ice_ptp_init()
3377 ptp->state = ICE_PTP_READY; in ice_ptp_init()
3388 if (pf->ptp.clock) { in ice_ptp_init()
3389 ptp_clock_unregister(ptp->clock); in ice_ptp_init()
3390 pf->ptp.clock = NULL; in ice_ptp_init()
3392 ptp->state = ICE_PTP_ERROR; in ice_ptp_init()
3397 * ice_ptp_release - Disable the driver/HW support and unregister the clock
3405 if (pf->ptp.state != ICE_PTP_READY) in ice_ptp_release()
3408 pf->ptp.state = ICE_PTP_UNINIT; in ice_ptp_release()
3415 ice_ptp_release_tx_tracker(pf, &pf->ptp.port.tx); in ice_ptp_release()
3419 kthread_cancel_delayed_work_sync(&pf->ptp.work); in ice_ptp_release()
3421 ice_ptp_port_phy_stop(&pf->ptp.port); in ice_ptp_release()
3422 mutex_destroy(&pf->ptp.port.ps_lock); in ice_ptp_release()
3423 if (pf->ptp.kworker) { in ice_ptp_release()
3424 kthread_destroy_worker(pf->ptp.kworker); in ice_ptp_release()
3425 pf->ptp.kworker = NULL; in ice_ptp_release()
3431 if (!pf->ptp.clock) in ice_ptp_release()
3437 ptp_clock_unregister(pf->ptp.clock); in ice_ptp_release()
3438 pf->ptp.clock = NULL; in ice_ptp_release()