Lines Matching full:pf

57 static struct ice_pf *ice_get_ctrl_pf(struct ice_pf *pf)  in ice_get_ctrl_pf()  argument
59 return !pf->adapter ? NULL : pf->adapter->ctrl_pf; in ice_get_ctrl_pf()
62 static struct ice_ptp *ice_get_ctrl_ptp(struct ice_pf *pf) in ice_get_ctrl_ptp() argument
64 struct ice_pf *ctrl_pf = ice_get_ctrl_pf(pf); in ice_get_ctrl_ptp()
71 * @pf: Board private structure
77 static int ice_ptp_find_pin_idx(struct ice_pf *pf, enum ptp_pin_function func, in ice_ptp_find_pin_idx() argument
80 const struct ptp_clock_info *info = &pf->ptp.info; in ice_ptp_find_pin_idx()
94 * @pf: Board private structure
99 static void ice_ptp_cfg_tx_interrupt(struct ice_pf *pf) in ice_ptp_cfg_tx_interrupt() argument
101 struct ice_hw *hw = &pf->hw; in ice_ptp_cfg_tx_interrupt()
105 switch (pf->ptp.tx_interrupt_mode) { in ice_ptp_cfg_tx_interrupt()
118 enable = pf->ptp.tstamp_config.tx_type == HWTSTAMP_TX_ON; in ice_ptp_cfg_tx_interrupt()
133 * @pf: The PF pointer to search in
136 static void ice_set_rx_tstamp(struct ice_pf *pf, bool on) in ice_set_rx_tstamp() argument
141 vsi = ice_get_main_vsi(pf); in ice_set_rx_tstamp()
155 * @pf: Board private structure
161 static void ice_ptp_disable_timestamp_mode(struct ice_pf *pf) in ice_ptp_disable_timestamp_mode() argument
163 struct ice_hw *hw = &pf->hw; in ice_ptp_disable_timestamp_mode()
170 ice_set_rx_tstamp(pf, false); in ice_ptp_disable_timestamp_mode()
175 * @pf: Board private structure
180 void ice_ptp_restore_timestamp_mode(struct ice_pf *pf) in ice_ptp_restore_timestamp_mode() argument
182 struct ice_hw *hw = &pf->hw; in ice_ptp_restore_timestamp_mode()
185 ice_ptp_cfg_tx_interrupt(pf); in ice_ptp_restore_timestamp_mode()
187 enable_rx = pf->ptp.tstamp_config.rx_filter == HWTSTAMP_FILTER_ALL; in ice_ptp_restore_timestamp_mode()
188 ice_set_rx_tstamp(pf, enable_rx); in ice_ptp_restore_timestamp_mode()
199 * @pf: Board private structure
203 u64 ice_ptp_read_src_clk_reg(struct ice_pf *pf, in ice_ptp_read_src_clk_reg() argument
206 struct ice_hw *hw = &pf->hw; in ice_ptp_read_src_clk_reg()
211 hw = ice_get_primary_hw(pf); in ice_ptp_read_src_clk_reg()
214 guard(spinlock)(&pf->adapter->ptp_gltsyn_time_lock); in ice_ptp_read_src_clk_reg()
317 * @pf: Board private structure
341 static u64 ice_ptp_extend_40b_ts(struct ice_pf *pf, u64 in_tstamp) in ice_ptp_extend_40b_ts() argument
347 discard_time = pf->ptp.cached_phc_jiffies + msecs_to_jiffies(2000); in ice_ptp_extend_40b_ts()
349 pf->ptp.tx_hwtstamp_discarded++; in ice_ptp_extend_40b_ts()
353 return ice_ptp_extend_32b_ts(pf->ptp.cached_phc_time, in ice_ptp_extend_40b_ts()
385 struct ice_pf *pf; in ice_ptp_req_tx_single_tstamp() local
391 pf = ptp_port_to_pf(ptp_port); in ice_ptp_req_tx_single_tstamp()
392 params = &pf->hw.ptp.phy.e810; in ice_ptp_req_tx_single_tstamp()
397 pf->ptp.tx_hwtstamp_timeouts++; in ice_ptp_req_tx_single_tstamp()
413 /* Write TS index to read to the PF register so the FW can read it */ in ice_ptp_req_tx_single_tstamp()
414 wr32(&pf->hw, REG_LL_PROXY_H, in ice_ptp_req_tx_single_tstamp()
437 struct ice_pf *pf; in ice_ptp_complete_tx_single_tstamp() local
444 pf = ptp_port_to_pf(ptp_port); in ice_ptp_complete_tx_single_tstamp()
445 dev = ice_pf_to_dev(pf); in ice_ptp_complete_tx_single_tstamp()
446 params = &pf->hw.ptp.phy.e810; in ice_ptp_complete_tx_single_tstamp()
457 raw_tstamp = rd32(&pf->hw, REG_LL_PROXY_L); in ice_ptp_complete_tx_single_tstamp()
459 reg_ll_high = rd32(&pf->hw, REG_LL_PROXY_H); in ice_ptp_complete_tx_single_tstamp()
470 dev_err(ice_pf_to_dev(pf), "Failed to get the Tx tstamp - FW not ready"); in ice_ptp_complete_tx_single_tstamp()
499 tstamp = ice_ptp_extend_40b_ts(pf, raw_tstamp); in ice_ptp_complete_tx_single_tstamp()
561 struct ice_pf *pf; in ice_ptp_process_tx_tstamp() local
569 pf = ptp_port_to_pf(ptp_port); in ice_ptp_process_tx_tstamp()
570 hw = &pf->hw; in ice_ptp_process_tx_tstamp()
594 pf->ptp.tx_hwtstamp_timeouts++; in ice_ptp_process_tx_tstamp()
657 tstamp = ice_ptp_extend_40b_ts(pf, raw_tstamp); in ice_ptp_process_tx_tstamp()
670 * @pf: Board private structure
672 static enum ice_tx_tstamp_work ice_ptp_tx_tstamp_owner(struct ice_pf *pf) in ice_ptp_tx_tstamp_owner() argument
677 mutex_lock(&pf->adapter->ports.lock); in ice_ptp_tx_tstamp_owner()
678 list_for_each_entry(port, &pf->adapter->ports.ports, list_node) { in ice_ptp_tx_tstamp_owner()
686 mutex_unlock(&pf->adapter->ports.lock); in ice_ptp_tx_tstamp_owner()
688 for (i = 0; i < ICE_GET_QUAD_NUM(pf->hw.ptp.num_lports); i++) { in ice_ptp_tx_tstamp_owner()
693 err = ice_get_phy_tx_tstamp_ready(&pf->hw, i, &tstamp_ready); in ice_ptp_tx_tstamp_owner()
770 * @pf: Board private structure
776 ice_ptp_flush_tx_tracker(struct ice_pf *pf, struct ice_ptp_tx *tx) in ice_ptp_flush_tx_tracker() argument
778 struct ice_hw *hw = &pf->hw; in ice_ptp_flush_tx_tracker()
786 dev_dbg(ice_pf_to_dev(pf), "Failed to get the Tx tstamp ready bitmap for block %u, err %d\n", in ice_ptp_flush_tx_tracker()
811 pf->ptp.tx_hwtstamp_flushed++; in ice_ptp_flush_tx_tracker()
841 * @pf: Board private structure
847 ice_ptp_flush_all_tx_tracker(struct ice_pf *pf) in ice_ptp_flush_all_tx_tracker() argument
851 list_for_each_entry(port, &pf->adapter->ports.ports, list_node) in ice_ptp_flush_all_tx_tracker()
857 * @pf: Board private structure
863 ice_ptp_release_tx_tracker(struct ice_pf *pf, struct ice_ptp_tx *tx) in ice_ptp_release_tx_tracker() argument
872 synchronize_irq(pf->oicr_irq.virq); in ice_ptp_release_tx_tracker()
874 ice_ptp_flush_tx_tracker(pf, tx); in ice_ptp_release_tx_tracker()
890 * @pf: Board private structure
901 static int ice_ptp_init_tx_e82x(struct ice_pf *pf, struct ice_ptp_tx *tx, in ice_ptp_init_tx_e82x() argument
914 * @pf: Board private structure
918 * Initialize the Tx timestamp tracker for this PF. For all PHYs except E82X,
923 static int ice_ptp_init_tx(struct ice_pf *pf, struct ice_ptp_tx *tx, u8 port) in ice_ptp_init_tx() argument
933 tx->has_ready_bitmap = pf->hw.mac_type != ICE_MAC_E810; in ice_ptp_init_tx()
940 * @pf: Board specific private structure
942 * This function updates the system time values which are cached in the PF
948 * Note that the cached copy in the PF PTP structure is always updated, even
953 * * -EAGAIN - PF was busy, need to reschedule the update
955 static int ice_ptp_update_cached_phctime(struct ice_pf *pf) in ice_ptp_update_cached_phctime() argument
957 struct device *dev = ice_pf_to_dev(pf); in ice_ptp_update_cached_phctime()
962 update_before = pf->ptp.cached_phc_jiffies + msecs_to_jiffies(2000); in ice_ptp_update_cached_phctime()
963 if (pf->ptp.cached_phc_time && in ice_ptp_update_cached_phctime()
965 unsigned long time_taken = jiffies - pf->ptp.cached_phc_jiffies; in ice_ptp_update_cached_phctime()
969 pf->ptp.late_cached_phc_updates++; in ice_ptp_update_cached_phctime()
973 systime = ice_ptp_read_src_clk_reg(pf, NULL); in ice_ptp_update_cached_phctime()
975 /* Update the cached PHC time stored in the PF structure */ in ice_ptp_update_cached_phctime()
976 WRITE_ONCE(pf->ptp.cached_phc_time, systime); in ice_ptp_update_cached_phctime()
977 WRITE_ONCE(pf->ptp.cached_phc_jiffies, jiffies); in ice_ptp_update_cached_phctime()
979 if (test_and_set_bit(ICE_CFG_BUSY, pf->state)) in ice_ptp_update_cached_phctime()
982 ice_for_each_vsi(pf, i) { in ice_ptp_update_cached_phctime()
983 struct ice_vsi *vsi = pf->vsi[i]; in ice_ptp_update_cached_phctime()
998 clear_bit(ICE_CFG_BUSY, pf->state); in ice_ptp_update_cached_phctime()
1005 * @pf: Board specific private structure
1009 * timestamps as stale and updates the cached PHC time for both the PF and Rx
1016 static void ice_ptp_reset_cached_phctime(struct ice_pf *pf) in ice_ptp_reset_cached_phctime() argument
1018 struct device *dev = ice_pf_to_dev(pf); in ice_ptp_reset_cached_phctime()
1024 err = ice_ptp_update_cached_phctime(pf); in ice_ptp_reset_cached_phctime()
1034 kthread_queue_delayed_work(pf->ptp.kworker, &pf->ptp.work, in ice_ptp_reset_cached_phctime()
1043 ice_ptp_mark_tx_tracker_stale(&pf->ptp.port.tx); in ice_ptp_reset_cached_phctime()
1048 * @pf: Board private structure
1053 static int ice_ptp_write_init(struct ice_pf *pf, struct timespec64 *ts) in ice_ptp_write_init() argument
1056 struct ice_hw *hw = &pf->hw; in ice_ptp_write_init()
1063 * @pf: Board private structure
1069 static int ice_ptp_write_adj(struct ice_pf *pf, s32 adj) in ice_ptp_write_adj() argument
1071 struct ice_hw *hw = &pf->hw; in ice_ptp_write_adj()
1078 * @pf: Board private structure
1085 static u64 ice_base_incval(struct ice_pf *pf) in ice_base_incval() argument
1087 struct ice_hw *hw = &pf->hw; in ice_base_incval()
1092 dev_dbg(ice_pf_to_dev(pf), "PTP: using base increment value of 0x%016llx\n", in ice_base_incval()
1106 struct ice_pf *pf; in ice_ptp_check_tx_fifo() local
1111 pf = ptp_port_to_pf(port); in ice_ptp_check_tx_fifo()
1112 hw = &pf->hw; in ice_ptp_check_tx_fifo()
1126 dev_err(ice_pf_to_dev(pf), "PTP failed to check port %d Tx FIFO, err %d\n", in ice_ptp_check_tx_fifo()
1143 dev_dbg(ice_pf_to_dev(pf), "Try %d, port %d FIFO not empty\n", in ice_ptp_check_tx_fifo()
1147 dev_dbg(ice_pf_to_dev(pf), in ice_ptp_check_tx_fifo()
1176 struct ice_pf *pf; in ice_ptp_wait_for_offsets() local
1182 pf = ptp_port_to_pf(port); in ice_ptp_wait_for_offsets()
1183 hw = &pf->hw; in ice_ptp_wait_for_offsets()
1185 if (ice_is_reset_in_progress(pf->state)) { in ice_ptp_wait_for_offsets()
1187 kthread_queue_delayed_work(pf->ptp.kworker, in ice_ptp_wait_for_offsets()
1199 kthread_queue_delayed_work(pf->ptp.kworker, in ice_ptp_wait_for_offsets()
1213 struct ice_pf *pf = ptp_port_to_pf(ptp_port); in ice_ptp_port_phy_stop() local
1215 struct ice_hw *hw = &pf->hw; in ice_ptp_port_phy_stop()
1237 dev_err(ice_pf_to_dev(pf), "PTP failed to set PHY port %d down, err %d\n", in ice_ptp_port_phy_stop()
1256 struct ice_pf *pf = ptp_port_to_pf(ptp_port); in ice_ptp_port_phy_restart() local
1258 struct ice_hw *hw = &pf->hw; in ice_ptp_port_phy_restart()
1294 kthread_queue_delayed_work(pf->ptp.kworker, &ptp_port->ov_work, in ice_ptp_port_phy_restart()
1305 dev_err(ice_pf_to_dev(pf), "PTP failed to set PHY port %d up, err %d\n", in ice_ptp_port_phy_restart()
1315 * @pf: Board private structure
1318 void ice_ptp_link_change(struct ice_pf *pf, bool linkup) in ice_ptp_link_change() argument
1321 struct ice_hw *hw = &pf->hw; in ice_ptp_link_change()
1323 if (pf->ptp.state != ICE_PTP_READY) in ice_ptp_link_change()
1326 ptp_port = &pf->ptp.port; in ice_ptp_link_change()
1332 if (pf->hw.reset_ongoing) in ice_ptp_link_change()
1345 dev_warn(ice_pf_to_dev(pf), "%s: Unknown PHY type\n", __func__); in ice_ptp_link_change()
1351 * @pf: PF private structure
1362 static int ice_ptp_cfg_phy_interrupt(struct ice_pf *pf, bool ena, u32 threshold) in ice_ptp_cfg_phy_interrupt() argument
1364 struct device *dev = ice_pf_to_dev(pf); in ice_ptp_cfg_phy_interrupt()
1365 struct ice_hw *hw = &pf->hw; in ice_ptp_cfg_phy_interrupt()
1414 * @pf: Board private structure
1416 static void ice_ptp_reset_phy_timestamping(struct ice_pf *pf) in ice_ptp_reset_phy_timestamping() argument
1418 ice_ptp_port_phy_restart(&pf->ptp.port); in ice_ptp_reset_phy_timestamping()
1423 * @pf: Board private structure
1425 static void ice_ptp_restart_all_phy(struct ice_pf *pf) in ice_ptp_restart_all_phy() argument
1429 list_for_each(entry, &pf->adapter->ports.ports) { in ice_ptp_restart_all_phy()
1449 struct ice_pf *pf = ptp_info_to_pf(info); in ice_ptp_adjfine() local
1450 struct ice_hw *hw = &pf->hw; in ice_ptp_adjfine()
1454 incval = adjust_by_scaled_ppm(ice_base_incval(pf), scaled_ppm); in ice_ptp_adjfine()
1457 dev_err(ice_pf_to_dev(pf), "PTP failed to set incval, err %d\n", in ice_ptp_adjfine()
1467 * @pf: Board private structure
1469 void ice_ptp_extts_event(struct ice_pf *pf) in ice_ptp_extts_event() argument
1472 struct ice_hw *hw = &pf->hw; in ice_ptp_extts_event()
1477 if (pf->ptp.state != ICE_PTP_READY) in ice_ptp_extts_event()
1490 if (!(pf->ptp.ext_ts_irq & (1 << chan))) in ice_ptp_extts_event()
1498 pin_desc_idx = ice_ptp_find_pin_idx(pf, PTP_PF_EXTTS, chan); in ice_ptp_extts_event()
1502 desc = &pf->ptp.ice_pin_desc[pin_desc_idx]; in ice_ptp_extts_event()
1508 pf->ptp.ext_ts_irq &= ~(1 << chan); in ice_ptp_extts_event()
1509 ptp_clock_event(pf->ptp.clock, &event); in ice_ptp_extts_event()
1515 * @pf: Board private structure
1523 static int ice_ptp_cfg_extts(struct ice_pf *pf, struct ptp_extts_request *rq, in ice_ptp_cfg_extts() argument
1527 struct ice_hw *hw = &pf->hw; in ice_ptp_cfg_extts()
1535 pin_desc_idx = ice_ptp_find_pin_idx(pf, PTP_PF_EXTTS, chan); in ice_ptp_cfg_extts()
1539 gpio_pin = pf->ptp.ice_pin_desc[pin_desc_idx].gpio[0]; in ice_ptp_cfg_extts()
1569 for (unsigned int i = 0; i < pf->ptp.info.n_ext_ts; i++) in ice_ptp_cfg_extts()
1570 if ((pf->ptp.extts_rqs[i].flags & in ice_ptp_cfg_extts()
1589 * @pf: Board private structure
1591 static void ice_ptp_disable_all_extts(struct ice_pf *pf) in ice_ptp_disable_all_extts() argument
1593 for (unsigned int i = 0; i < pf->ptp.info.n_ext_ts ; i++) in ice_ptp_disable_all_extts()
1594 if (pf->ptp.extts_rqs[i].flags & PTP_ENABLE_FEATURE) in ice_ptp_disable_all_extts()
1595 ice_ptp_cfg_extts(pf, &pf->ptp.extts_rqs[i], in ice_ptp_disable_all_extts()
1598 synchronize_irq(pf->oicr_irq.virq); in ice_ptp_disable_all_extts()
1603 * @pf: Board private structure
1607 static void ice_ptp_enable_all_extts(struct ice_pf *pf) in ice_ptp_enable_all_extts() argument
1609 for (unsigned int i = 0; i < pf->ptp.info.n_ext_ts ; i++) in ice_ptp_enable_all_extts()
1610 if (pf->ptp.extts_rqs[i].flags & PTP_ENABLE_FEATURE) in ice_ptp_enable_all_extts()
1611 ice_ptp_cfg_extts(pf, &pf->ptp.extts_rqs[i], in ice_ptp_enable_all_extts()
1685 * @pf: Board private structure
1694 static int ice_ptp_cfg_perout(struct ice_pf *pf, struct ptp_perout_request *rq, in ice_ptp_cfg_perout() argument
1699 struct ice_hw *hw = &pf->hw; in ice_ptp_cfg_perout()
1702 pin_desc_idx = ice_ptp_find_pin_idx(pf, PTP_PF_PEROUT, rq->index); in ice_ptp_cfg_perout()
1706 gpio_pin = pf->ptp.ice_pin_desc[pin_desc_idx].gpio[1]; in ice_ptp_cfg_perout()
1707 prop_delay_ns = pf->ptp.ice_pin_desc[pin_desc_idx].delay[1]; in ice_ptp_cfg_perout()
1716 if (strncmp(pf->ptp.pin_desc[pin_desc_idx].name, "1PPS", 64) == 0 && in ice_ptp_cfg_perout()
1718 dev_err(ice_pf_to_dev(pf), "1PPS pin supports only 1 s period\n"); in ice_ptp_cfg_perout()
1723 dev_err(ice_pf_to_dev(pf), "CLK Period must be an even value\n"); in ice_ptp_cfg_perout()
1739 clk = ice_ptp_read_src_clk_reg(pf, NULL) + NSEC_PER_MSEC * 500; in ice_ptp_cfg_perout()
1751 * @pf: Board private structure
1757 static void ice_ptp_disable_all_perout(struct ice_pf *pf) in ice_ptp_disable_all_perout() argument
1759 for (unsigned int i = 0; i < pf->ptp.info.n_per_out; i++) in ice_ptp_disable_all_perout()
1760 if (pf->ptp.perout_rqs[i].period.sec || in ice_ptp_disable_all_perout()
1761 pf->ptp.perout_rqs[i].period.nsec) in ice_ptp_disable_all_perout()
1762 ice_ptp_cfg_perout(pf, &pf->ptp.perout_rqs[i], in ice_ptp_disable_all_perout()
1768 * @pf: Board private structure
1774 static void ice_ptp_enable_all_perout(struct ice_pf *pf) in ice_ptp_enable_all_perout() argument
1776 for (unsigned int i = 0; i < pf->ptp.info.n_per_out; i++) in ice_ptp_enable_all_perout()
1777 if (pf->ptp.perout_rqs[i].period.sec || in ice_ptp_enable_all_perout()
1778 pf->ptp.perout_rqs[i].period.nsec) in ice_ptp_enable_all_perout()
1779 ice_ptp_cfg_perout(pf, &pf->ptp.perout_rqs[i], in ice_ptp_enable_all_perout()
1795 struct ice_pf *pf = ptp_info_to_pf(info); in ice_verify_pin() local
1798 pin_desc = &pf->ptp.ice_pin_desc[pin]; in ice_verify_pin()
1831 struct ice_pf *pf = ptp_info_to_pf(info); in ice_ptp_gpio_enable() local
1838 &pf->ptp.perout_rqs[rq->perout.index]; in ice_ptp_gpio_enable()
1840 err = ice_ptp_cfg_perout(pf, &rq->perout, on); in ice_ptp_gpio_enable()
1852 &pf->ptp.extts_rqs[rq->extts.index]; in ice_ptp_gpio_enable()
1854 err = ice_ptp_cfg_extts(pf, &rq->extts, on); in ice_ptp_gpio_enable()
1880 struct ice_pf *pf = ptp_info_to_pf(info); in ice_ptp_gettimex64() local
1883 time_ns = ice_ptp_read_src_clk_reg(pf, sts); in ice_ptp_gettimex64()
1899 struct ice_pf *pf = ptp_info_to_pf(info); in ice_ptp_settime64() local
1901 struct ice_hw *hw = &pf->hw; in ice_ptp_settime64()
1910 dev_warn(ice_pf_to_dev(pf), "Failed to mark timestamps as invalid before settime\n"); in ice_ptp_settime64()
1919 ice_ptp_disable_all_perout(pf); in ice_ptp_settime64()
1921 err = ice_ptp_write_init(pf, &ts64); in ice_ptp_settime64()
1925 ice_ptp_reset_cached_phctime(pf); in ice_ptp_settime64()
1928 ice_ptp_enable_all_perout(pf); in ice_ptp_settime64()
1932 ice_ptp_restart_all_phy(pf); in ice_ptp_settime64()
1935 dev_err(ice_pf_to_dev(pf), "PTP failed to set time %d\n", err); in ice_ptp_settime64()
1968 struct ice_pf *pf = ptp_info_to_pf(info); in ice_ptp_adjtime() local
1969 struct ice_hw *hw = &pf->hw; in ice_ptp_adjtime()
1973 dev = ice_pf_to_dev(pf); in ice_ptp_adjtime()
1990 ice_ptp_disable_all_perout(pf); in ice_ptp_adjtime()
1992 err = ice_ptp_write_adj(pf, delta); in ice_ptp_adjtime()
1995 ice_ptp_enable_all_perout(pf); in ice_ptp_adjtime()
2004 ice_ptp_reset_cached_phctime(pf); in ice_ptp_adjtime()
2067 * @pf: pointer to the PF private structure
2072 struct ice_pf *pf; member
2094 struct ice_pf *pf; in ice_capture_crosststamp() local
2100 pf = ctx->pf; in ice_capture_crosststamp()
2101 hw = &pf->hw; in ice_capture_crosststamp()
2112 dev_err(ice_pf_to_dev(pf), "PTP failed to get cross timestamp lock\n"); in ice_capture_crosststamp()
2176 struct ice_pf *pf = ptp_info_to_pf(info); in ice_ptp_getcrosststamp() local
2178 .pf = pf, in ice_ptp_getcrosststamp()
2181 switch (pf->hw.mac_type) { in ice_ptp_getcrosststamp()
2210 struct ice_pf *pf = np->vsi->back; in ice_ptp_hwtstamp_get() local
2212 if (pf->ptp.state != ICE_PTP_READY) in ice_ptp_hwtstamp_get()
2215 *config = pf->ptp.tstamp_config; in ice_ptp_hwtstamp_get()
2222 * @pf: Board private structure
2225 static int ice_ptp_set_timestamp_mode(struct ice_pf *pf, in ice_ptp_set_timestamp_mode() argument
2230 pf->ptp.tstamp_config.tx_type = HWTSTAMP_TX_OFF; in ice_ptp_set_timestamp_mode()
2233 pf->ptp.tstamp_config.tx_type = HWTSTAMP_TX_ON; in ice_ptp_set_timestamp_mode()
2241 pf->ptp.tstamp_config.rx_filter = HWTSTAMP_FILTER_NONE; in ice_ptp_set_timestamp_mode()
2257 pf->ptp.tstamp_config.rx_filter = HWTSTAMP_FILTER_ALL; in ice_ptp_set_timestamp_mode()
2264 ice_ptp_restore_timestamp_mode(pf); in ice_ptp_set_timestamp_mode()
2282 struct ice_pf *pf = np->vsi->back; in ice_ptp_hwtstamp_set() local
2285 if (pf->ptp.state != ICE_PTP_READY) in ice_ptp_hwtstamp_set()
2288 err = ice_ptp_set_timestamp_mode(pf, config); in ice_ptp_hwtstamp_set()
2293 *config = pf->ptp.tstamp_config; in ice_ptp_hwtstamp_set()
2321 * PHC value, rather than accessing the PF. This also allows us to in ice_ptp_get_rx_hwts()
2334 * @pf: Board private structure
2336 static void ice_ptp_setup_pin_cfg(struct ice_pf *pf) in ice_ptp_setup_pin_cfg() argument
2338 for (unsigned int i = 0; i < pf->ptp.info.n_pins; i++) { in ice_ptp_setup_pin_cfg()
2339 const struct ice_ptp_pin_desc *desc = &pf->ptp.ice_pin_desc[i]; in ice_ptp_setup_pin_cfg()
2340 struct ptp_pin_desc *pin = &pf->ptp.pin_desc[i]; in ice_ptp_setup_pin_cfg()
2343 if (!ice_is_feature_supported(pf, ICE_F_SMA_CTRL)) in ice_ptp_setup_pin_cfg()
2353 pf->ptp.info.pin_config = pf->ptp.pin_desc; in ice_ptp_setup_pin_cfg()
2358 * @pf: pointer to the PF structure
2363 static void ice_ptp_disable_pins(struct ice_pf *pf) in ice_ptp_disable_pins() argument
2365 struct ptp_clock_info *info = &pf->ptp.info; in ice_ptp_disable_pins()
2367 dev_warn(ice_pf_to_dev(pf), "Failed to configure PTP pin control\n"); in ice_ptp_disable_pins()
2378 * @pf: pointer to the PF structure
2385 static int ice_ptp_parse_sdp_entries(struct ice_pf *pf, __le16 *entries, in ice_ptp_parse_sdp_entries() argument
2429 dev_dbg(ice_pf_to_dev(pf), in ice_ptp_parse_sdp_entries()
2434 pf->ptp.info.n_pins = n_pins; in ice_ptp_parse_sdp_entries()
2440 * @pf: Board private structure
2447 static void ice_ptp_set_funcs_e82x(struct ice_pf *pf) in ice_ptp_set_funcs_e82x() argument
2449 pf->ptp.info.getcrosststamp = ice_ptp_getcrosststamp; in ice_ptp_set_funcs_e82x()
2451 if (pf->hw.mac_type == ICE_MAC_GENERIC_3K_E825) { in ice_ptp_set_funcs_e82x()
2452 pf->ptp.ice_pin_desc = ice_pin_desc_e825c; in ice_ptp_set_funcs_e82x()
2453 pf->ptp.info.n_pins = ARRAY_SIZE(ice_pin_desc_e825c); in ice_ptp_set_funcs_e82x()
2455 pf->ptp.ice_pin_desc = ice_pin_desc_e82x; in ice_ptp_set_funcs_e82x()
2456 pf->ptp.info.n_pins = ARRAY_SIZE(ice_pin_desc_e82x); in ice_ptp_set_funcs_e82x()
2458 ice_ptp_setup_pin_cfg(pf); in ice_ptp_set_funcs_e82x()
2463 * @pf: Board private structure
2470 static void ice_ptp_set_funcs_e810(struct ice_pf *pf) in ice_ptp_set_funcs_e810() argument
2474 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_set_funcs_e810()
2478 err = ice_ptp_read_sdp_ac(&pf->hw, entries, &num_entries); in ice_ptp_set_funcs_e810()
2481 if (ice_is_feature_supported(pf, ICE_F_SMA_CTRL)) { in ice_ptp_set_funcs_e810()
2485 pf->ptp.ice_pin_desc = ice_pin_desc_e810; in ice_ptp_set_funcs_e810()
2486 pf->ptp.info.n_pins = ARRAY_SIZE(ice_pin_desc_e810); in ice_ptp_set_funcs_e810()
2490 desc = devm_kcalloc(ice_pf_to_dev(pf), ICE_N_PINS_MAX, in ice_ptp_set_funcs_e810()
2496 err = ice_ptp_parse_sdp_entries(pf, entries, num_entries, desc); in ice_ptp_set_funcs_e810()
2504 ice_ptp_setup_pin_cfg(pf); in ice_ptp_set_funcs_e810()
2508 devm_kfree(ice_pf_to_dev(pf), desc); in ice_ptp_set_funcs_e810()
2509 ice_ptp_disable_pins(pf); in ice_ptp_set_funcs_e810()
2515 * @pf: Board private structure
2522 static void ice_ptp_set_funcs_e830(struct ice_pf *pf) in ice_ptp_set_funcs_e830() argument
2525 if (pcie_ptm_enabled(pf->pdev) && boot_cpu_has(X86_FEATURE_ART)) in ice_ptp_set_funcs_e830()
2526 pf->ptp.info.getcrosststamp = ice_ptp_getcrosststamp; in ice_ptp_set_funcs_e830()
2530 pf->ptp.ice_pin_desc = ice_pin_desc_e810; in ice_ptp_set_funcs_e830()
2531 pf->ptp.info.n_pins = ARRAY_SIZE(ice_pin_desc_e810); in ice_ptp_set_funcs_e830()
2532 ice_ptp_setup_pin_cfg(pf); in ice_ptp_set_funcs_e830()
2537 * @pf: Board private structure
2539 static void ice_ptp_set_caps(struct ice_pf *pf) in ice_ptp_set_caps() argument
2541 struct ptp_clock_info *info = &pf->ptp.info; in ice_ptp_set_caps()
2542 struct device *dev = ice_pf_to_dev(pf); in ice_ptp_set_caps()
2562 switch (pf->hw.mac_type) { in ice_ptp_set_caps()
2564 ice_ptp_set_funcs_e810(pf); in ice_ptp_set_caps()
2567 ice_ptp_set_funcs_e830(pf); in ice_ptp_set_caps()
2571 ice_ptp_set_funcs_e82x(pf); in ice_ptp_set_caps()
2580 * @pf: Board private structure
2587 static long ice_ptp_create_clock(struct ice_pf *pf) in ice_ptp_create_clock() argument
2593 if (pf->ptp.clock) in ice_ptp_create_clock()
2596 ice_ptp_set_caps(pf); in ice_ptp_create_clock()
2598 info = &pf->ptp.info; in ice_ptp_create_clock()
2599 dev = ice_pf_to_dev(pf); in ice_ptp_create_clock()
2602 pf->ptp.clock = ptp_clock_register(info, dev); in ice_ptp_create_clock()
2603 if (IS_ERR(pf->ptp.clock)) { in ice_ptp_create_clock()
2604 dev_err(ice_pf_to_dev(pf), "Failed to register PTP clock device"); in ice_ptp_create_clock()
2605 return PTR_ERR(pf->ptp.clock); in ice_ptp_create_clock()
2661 * @pf: Board private structure
2666 enum ice_tx_tstamp_work ice_ptp_process_ts(struct ice_pf *pf) in ice_ptp_process_ts() argument
2668 switch (pf->ptp.tx_interrupt_mode) { in ice_ptp_process_ts()
2674 return ice_ptp_tx_tstamp(&pf->ptp.port.tx); in ice_ptp_process_ts()
2677 return ice_ptp_tx_tstamp_owner(pf); in ice_ptp_process_ts()
2680 pf->ptp.tx_interrupt_mode); in ice_ptp_process_ts()
2687 * @pf: Board private structure
2692 irqreturn_t ice_ptp_ts_irq(struct ice_pf *pf) in ice_ptp_ts_irq() argument
2694 struct ice_hw *hw = &pf->hw; in ice_ptp_ts_irq()
2703 struct ice_ptp_tx *tx = &pf->ptp.port.tx; in ice_ptp_ts_irq()
2706 if (!ice_pf_state_is_nominal(pf)) in ice_ptp_ts_irq()
2727 if (!ice_ptp_pf_handles_tx_interrupt(pf)) in ice_ptp_ts_irq()
2730 set_bit(ICE_MISC_THREAD_TX_TSTAMP, pf->misc_thread); in ice_ptp_ts_irq()
2734 if (ice_ptp_process_ts(pf) == ICE_TX_TSTAMP_WORK_PENDING) { in ice_ptp_ts_irq()
2749 * @pf: Board private structure
2760 static void ice_ptp_maybe_trigger_tx_interrupt(struct ice_pf *pf) in ice_ptp_maybe_trigger_tx_interrupt() argument
2762 struct device *dev = ice_pf_to_dev(pf); in ice_ptp_maybe_trigger_tx_interrupt()
2763 struct ice_hw *hw = &pf->hw; in ice_ptp_maybe_trigger_tx_interrupt()
2767 if (!pf->ptp.port.tx.has_ready_bitmap) in ice_ptp_maybe_trigger_tx_interrupt()
2770 if (!ice_pf_src_tmr_owned(pf)) in ice_ptp_maybe_trigger_tx_interrupt()
2777 err = ice_get_phy_tx_tstamp_ready(&pf->hw, i, &tstamp_ready); in ice_ptp_maybe_trigger_tx_interrupt()
2798 struct ice_pf *pf = container_of(ptp, struct ice_pf, ptp); in ice_ptp_periodic_work() local
2801 if (pf->ptp.state != ICE_PTP_READY) in ice_ptp_periodic_work()
2804 err = ice_ptp_update_cached_phctime(pf); in ice_ptp_periodic_work()
2806 ice_ptp_maybe_trigger_tx_interrupt(pf); in ice_ptp_periodic_work()
2815 * @pf: Board private structure
2819 static void ice_ptp_prepare_rebuild_sec(struct ice_pf *pf, bool rebuild, in ice_ptp_prepare_rebuild_sec() argument
2824 list_for_each(entry, &pf->adapter->ports.ports) { in ice_ptp_prepare_rebuild_sec()
2841 * @pf: Board private structure
2844 void ice_ptp_prepare_for_reset(struct ice_pf *pf, enum ice_reset_req reset_type) in ice_ptp_prepare_for_reset() argument
2846 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_prepare_for_reset()
2847 struct ice_hw *hw = &pf->hw; in ice_ptp_prepare_for_reset()
2856 ice_ptp_disable_timestamp_mode(pf); in ice_ptp_prepare_for_reset()
2863 if (ice_pf_src_tmr_owned(pf) && hw->mac_type == ICE_MAC_GENERIC_3K_E825) in ice_ptp_prepare_for_reset()
2864 ice_ptp_prepare_rebuild_sec(pf, false, reset_type); in ice_ptp_prepare_for_reset()
2866 ice_ptp_release_tx_tracker(pf, &pf->ptp.port.tx); in ice_ptp_prepare_for_reset()
2869 ice_ptp_disable_all_perout(pf); in ice_ptp_prepare_for_reset()
2871 src_tmr = ice_get_ptp_src_clock_index(&pf->hw); in ice_ptp_prepare_for_reset()
2874 wr32(&pf->hw, GLTSYN_ENA(src_tmr), (u32)~GLTSYN_ENA_TSYN_ENA_M); in ice_ptp_prepare_for_reset()
2882 * @pf: Board private structure
2887 static int ice_ptp_rebuild_owner(struct ice_pf *pf) in ice_ptp_rebuild_owner() argument
2889 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_rebuild_owner()
2890 struct ice_hw *hw = &pf->hw; in ice_ptp_rebuild_owner()
2910 err = ice_ptp_write_incval(hw, ice_base_incval(pf)); in ice_ptp_rebuild_owner()
2924 err = ice_ptp_write_init(pf, &ts); in ice_ptp_rebuild_owner()
2934 ice_ptp_flush_all_tx_tracker(pf); in ice_ptp_rebuild_owner()
2937 err = ice_ptp_cfg_phy_interrupt(pf, true, 1); in ice_ptp_rebuild_owner()
2941 ice_ptp_restart_all_phy(pf); in ice_ptp_rebuild_owner()
2944 ice_ptp_enable_all_perout(pf); in ice_ptp_rebuild_owner()
2945 ice_ptp_enable_all_extts(pf); in ice_ptp_rebuild_owner()
2956 * @pf: Board private structure
2959 void ice_ptp_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type) in ice_ptp_rebuild() argument
2961 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_rebuild()
2965 ice_ptp_prepare_for_reset(pf, reset_type); in ice_ptp_rebuild()
2968 dev_err(ice_pf_to_dev(pf), "PTP was not initialized\n"); in ice_ptp_rebuild()
2972 if (ice_pf_src_tmr_owned(pf) && reset_type != ICE_RESET_PFR) { in ice_ptp_rebuild()
2973 err = ice_ptp_rebuild_owner(pf); in ice_ptp_rebuild()
2983 dev_info(ice_pf_to_dev(pf), "PTP reset successful\n"); in ice_ptp_rebuild()
2988 dev_err(ice_pf_to_dev(pf), "PTP reset failed %d\n", err); in ice_ptp_rebuild()
2991 static int ice_ptp_setup_adapter(struct ice_pf *pf) in ice_ptp_setup_adapter() argument
2993 if (!ice_pf_src_tmr_owned(pf) || !ice_is_primary(&pf->hw)) in ice_ptp_setup_adapter()
2996 pf->adapter->ctrl_pf = pf; in ice_ptp_setup_adapter()
3001 static int ice_ptp_setup_pf(struct ice_pf *pf) in ice_ptp_setup_pf() argument
3003 struct ice_ptp *ctrl_ptp = ice_get_ctrl_ptp(pf); in ice_ptp_setup_pf()
3004 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_setup_pf()
3006 if (WARN_ON(!ctrl_ptp) || pf->hw.mac_type == ICE_MAC_UNKNOWN) in ice_ptp_setup_pf()
3010 mutex_lock(&pf->adapter->ports.lock); in ice_ptp_setup_pf()
3013 &pf->adapter->ports.ports); in ice_ptp_setup_pf()
3014 mutex_unlock(&pf->adapter->ports.lock); in ice_ptp_setup_pf()
3019 static void ice_ptp_cleanup_pf(struct ice_pf *pf) in ice_ptp_cleanup_pf() argument
3021 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_cleanup_pf()
3023 if (pf->hw.mac_type != ICE_MAC_UNKNOWN) { in ice_ptp_cleanup_pf()
3024 mutex_lock(&pf->adapter->ports.lock); in ice_ptp_cleanup_pf()
3026 mutex_unlock(&pf->adapter->ports.lock); in ice_ptp_cleanup_pf()
3032 * @pf: Board private structure
3034 * Returns: the PTP clock index associated with this PF, or -1 if no PTP clock
3037 int ice_ptp_clock_index(struct ice_pf *pf) in ice_ptp_clock_index() argument
3039 struct ice_ptp *ctrl_ptp = ice_get_ctrl_ptp(pf); in ice_ptp_clock_index()
3051 * @pf: Board private structure
3057 static int ice_ptp_init_owner(struct ice_pf *pf) in ice_ptp_init_owner() argument
3059 struct ice_hw *hw = &pf->hw; in ice_ptp_init_owner()
3065 dev_err(ice_pf_to_dev(pf), "Failed to initialize PHC, err %d\n", in ice_ptp_init_owner()
3072 dev_err(ice_pf_to_dev(pf), "Failed to initialize CGU, status %d\n", in ice_ptp_init_owner()
3084 err = ice_ptp_write_incval(hw, ice_base_incval(pf)); in ice_ptp_init_owner()
3090 err = ice_ptp_write_init(pf, &ts); in ice_ptp_init_owner()
3098 err = ice_ptp_cfg_phy_interrupt(pf, true, 1); in ice_ptp_init_owner()
3103 err = ice_ptp_create_clock(pf); in ice_ptp_init_owner()
3109 pf->ptp.clock = NULL; in ice_ptp_init_owner()
3120 * @pf: Board private structure
3121 * @ptp: PF PTP structure
3123 static int ice_ptp_init_work(struct ice_pf *pf, struct ice_ptp *ptp) in ice_ptp_init_work() argument
3134 dev_name(ice_pf_to_dev(pf))); in ice_ptp_init_work()
3148 * @pf: Board private structure
3153 static int ice_ptp_init_port(struct ice_pf *pf, struct ice_ptp_port *ptp_port) in ice_ptp_init_port() argument
3155 struct ice_hw *hw = &pf->hw; in ice_ptp_init_port()
3163 return ice_ptp_init_tx(pf, &ptp_port->tx, ptp_port->port_num); in ice_ptp_init_port()
3167 return ice_ptp_init_tx_e82x(pf, &ptp_port->tx, in ice_ptp_init_port()
3176 * @pf: Board private structure
3179 * types, each PF processes the interrupt and manages its own timestamps. For
3183 static void ice_ptp_init_tx_interrupt_mode(struct ice_pf *pf) in ice_ptp_init_tx_interrupt_mode() argument
3185 switch (pf->hw.mac_type) { in ice_ptp_init_tx_interrupt_mode()
3190 if (ice_pf_src_tmr_owned(pf)) in ice_ptp_init_tx_interrupt_mode()
3191 pf->ptp.tx_interrupt_mode = ICE_PTP_TX_INTERRUPT_ALL; in ice_ptp_init_tx_interrupt_mode()
3193 pf->ptp.tx_interrupt_mode = ICE_PTP_TX_INTERRUPT_NONE; in ice_ptp_init_tx_interrupt_mode()
3197 pf->ptp.tx_interrupt_mode = ICE_PTP_TX_INTERRUPT_SELF; in ice_ptp_init_tx_interrupt_mode()
3203 * @pf: Board private structure
3213 void ice_ptp_init(struct ice_pf *pf) in ice_ptp_init() argument
3215 struct ice_ptp *ptp = &pf->ptp; in ice_ptp_init()
3216 struct ice_hw *hw = &pf->hw; in ice_ptp_init()
3229 ice_ptp_init_tx_interrupt_mode(pf); in ice_ptp_init()
3234 if (ice_pf_src_tmr_owned(pf) && ice_is_primary(hw)) { in ice_ptp_init()
3235 err = ice_ptp_setup_adapter(pf); in ice_ptp_init()
3238 err = ice_ptp_init_owner(pf); in ice_ptp_init()
3243 err = ice_ptp_setup_pf(pf); in ice_ptp_init()
3247 err = ice_ptp_init_port(pf, &ptp->port); in ice_ptp_init()
3252 ice_ptp_reset_phy_timestamping(pf); in ice_ptp_init()
3255 ice_ptp_cfg_tx_interrupt(pf); in ice_ptp_init()
3259 err = ice_ptp_init_work(pf, ptp); in ice_ptp_init()
3263 dev_info(ice_pf_to_dev(pf), "PTP init successful\n"); in ice_ptp_init()
3268 if (pf->ptp.clock) { in ice_ptp_init()
3270 pf->ptp.clock = NULL; in ice_ptp_init()
3273 dev_err(ice_pf_to_dev(pf), "PTP failed %d\n", err); in ice_ptp_init()
3278 * @pf: Board private structure
3283 void ice_ptp_release(struct ice_pf *pf) in ice_ptp_release() argument
3285 if (pf->ptp.state != ICE_PTP_READY) in ice_ptp_release()
3288 pf->ptp.state = ICE_PTP_UNINIT; in ice_ptp_release()
3291 ice_ptp_disable_timestamp_mode(pf); in ice_ptp_release()
3293 ice_ptp_cleanup_pf(pf); in ice_ptp_release()
3295 ice_ptp_release_tx_tracker(pf, &pf->ptp.port.tx); in ice_ptp_release()
3297 ice_ptp_disable_all_extts(pf); in ice_ptp_release()
3299 kthread_cancel_delayed_work_sync(&pf->ptp.work); in ice_ptp_release()
3301 ice_ptp_port_phy_stop(&pf->ptp.port); in ice_ptp_release()
3302 mutex_destroy(&pf->ptp.port.ps_lock); in ice_ptp_release()
3303 if (pf->ptp.kworker) { in ice_ptp_release()
3304 kthread_destroy_worker(pf->ptp.kworker); in ice_ptp_release()
3305 pf->ptp.kworker = NULL; in ice_ptp_release()
3308 if (!pf->ptp.clock) in ice_ptp_release()
3312 ice_ptp_disable_all_perout(pf); in ice_ptp_release()
3314 ptp_clock_unregister(pf->ptp.clock); in ice_ptp_release()
3315 pf->ptp.clock = NULL; in ice_ptp_release()
3317 dev_info(ice_pf_to_dev(pf), "Removed PTP clock\n"); in ice_ptp_release()