Lines Matching +full:rx +full:- +full:pins

1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
5 #include <linux/posix-clock.h>
39 CANT_DO_PINS = -1,
52 end = -2,
66 led_end = -2,
142 struct i40e_ptp_pins_settings *pins);
145 * i40e_ptp_extts0_work - workqueue task function
154 struct i40e_hw *hw = &pf->hw; in i40e_ptp_extts0_work()
169 event.index = hw->pf_id; in i40e_ptp_extts0_work()
172 ptp_clock_event(pf->ptp_clock, &event); in i40e_ptp_extts0_work()
176 * i40e_is_ptp_pin_dev - check if device supports PTP pins
179 * Return true if device supports PTP pins, false otherwise.
183 return hw->device_id == I40E_DEV_ID_25G_SFP28 && in i40e_is_ptp_pin_dev()
184 hw->subsystem_device_id == I40E_SUBDEV_ID_25G_PTP_PIN; in i40e_is_ptp_pin_dev()
188 * i40e_can_set_pins - check possibility of manipulating the pins
191 * Check if all conditions are satisfied to manipulate PTP pins.
192 * Return CAN_SET_PINS if pins can be set on a specific PF or
193 * return CAN_DO_PINS if pins can be manipulated within a NIC or
198 if (!i40e_is_ptp_pin_dev(&pf->hw)) { in i40e_can_set_pins()
199 dev_warn(&pf->pdev->dev, in i40e_can_set_pins()
204 if (!pf->ptp_pins) { in i40e_can_set_pins()
205 dev_warn(&pf->pdev->dev, in i40e_can_set_pins()
210 if (pf->hw.pf_id) { in i40e_can_set_pins()
211 dev_warn(&pf->pdev->dev, in i40e_can_set_pins()
212 "PTP PINs should be accessed via PF0.\n"); in i40e_can_set_pins()
220 * i40_ptp_reset_timing_events - Reset PTP timing events
229 spin_lock_bh(&pf->ptp_rx_lock); in i40_ptp_reset_timing_events()
232 rd32(&pf->hw, I40E_PRTTSYN_RXTIME_L(i)); in i40_ptp_reset_timing_events()
233 rd32(&pf->hw, I40E_PRTTSYN_RXTIME_H(i)); in i40_ptp_reset_timing_events()
234 pf->latch_events[i] = 0; in i40_ptp_reset_timing_events()
237 rd32(&pf->hw, I40E_PRTTSYN_TXTIME_L); in i40_ptp_reset_timing_events()
238 rd32(&pf->hw, I40E_PRTTSYN_TXTIME_H); in i40_ptp_reset_timing_events()
240 pf->tx_hwtstamp_timeouts = 0; in i40_ptp_reset_timing_events()
241 pf->tx_hwtstamp_skipped = 0; in i40_ptp_reset_timing_events()
242 pf->rx_hwtstamp_cleared = 0; in i40_ptp_reset_timing_events()
243 pf->latch_event_flags = 0; in i40_ptp_reset_timing_events()
244 spin_unlock_bh(&pf->ptp_rx_lock); in i40_ptp_reset_timing_events()
248 * i40e_ptp_verify - check pins
254 * Check pins consistency.
266 return -EOPNOTSUPP; in i40e_ptp_verify()
272 * i40e_ptp_read - Read the PHC time from the device
284 struct i40e_hw *hw = &pf->hw; in i40e_ptp_read()
300 * i40e_ptp_write - Write the PHC time to the device
310 struct i40e_hw *hw = &pf->hw; in i40e_ptp_write()
321 * i40e_ptp_convert_to_hwtstamp - Convert device clock to system time
326 * the upper level timestamping functions. Since the timestamp is simply a 64-
334 hwtstamps->hwtstamp = ns_to_ktime(timestamp); in i40e_ptp_convert_to_hwtstamp()
338 * i40e_ptp_adjfine - Adjust the PHC frequency
350 struct i40e_hw *hw = &pf->hw; in i40e_ptp_adjfine()
354 base_adj = I40E_PTP_40GB_INCVAL * READ_ONCE(pf->ptp_adj_mult); in i40e_ptp_adjfine()
365 * i40e_ptp_set_1pps_signal_hw - configure 1PPS PTP signal for pins
368 * Configure 1PPS signal used for PTP pins
372 struct i40e_hw *hw = &pf->hw; in i40e_ptp_set_1pps_signal_hw()
396 * i40e_ptp_adjtime - Adjust the PHC time
405 struct i40e_hw *hw = &pf->hw; in i40e_ptp_adjtime()
407 mutex_lock(&pf->tmreg_lock); in i40e_ptp_adjtime()
409 if (delta > -999999900LL && delta < 999999900LL) { in i40e_ptp_adjtime()
416 tohw = -delta; in i40e_ptp_adjtime()
435 mutex_unlock(&pf->tmreg_lock); in i40e_ptp_adjtime()
441 * i40e_ptp_gettimex - Get the time of the PHC
454 mutex_lock(&pf->tmreg_lock); in i40e_ptp_gettimex()
456 mutex_unlock(&pf->tmreg_lock); in i40e_ptp_gettimex()
462 * i40e_ptp_settime - Set the time of the PHC
474 mutex_lock(&pf->tmreg_lock); in i40e_ptp_settime()
476 mutex_unlock(&pf->tmreg_lock); in i40e_ptp_settime()
482 * i40e_pps_configure - configure PPS events
503 * i40e_pin_state - determine PIN state
527 * i40e_ptp_enable_pin - enable PINs.
533 * Enable PTP pins for external clock source.
540 struct i40e_ptp_pins_settings pins; in i40e_ptp_enable_pin() local
543 /* Use PF0 to set pins. Return success for user space tools */ in i40e_ptp_enable_pin()
544 if (pf->hw.pf_id) in i40e_ptp_enable_pin()
547 /* Preserve previous state of pins that we don't touch */ in i40e_ptp_enable_pin()
548 pins.sdp3_2 = pf->ptp_pins->sdp3_2; in i40e_ptp_enable_pin()
549 pins.sdp3_3 = pf->ptp_pins->sdp3_3; in i40e_ptp_enable_pin()
550 pins.gpio_4 = pf->ptp_pins->gpio_4; in i40e_ptp_enable_pin()
552 /* To turn on the pin - find the corresponding one based on in i40e_ptp_enable_pin()
553 * the given index. To to turn the function off - find in i40e_ptp_enable_pin()
559 pin_index = ptp_find_pin(pf->ptp_clock, func, chan); in i40e_ptp_enable_pin()
561 return -EBUSY; in i40e_ptp_enable_pin()
565 pin = &pins.sdp3_2; in i40e_ptp_enable_pin()
568 pin = &pins.sdp3_3; in i40e_ptp_enable_pin()
571 pin = &pins.gpio_4; in i40e_ptp_enable_pin()
574 return -EINVAL; in i40e_ptp_enable_pin()
579 pins.sdp3_2 = off; in i40e_ptp_enable_pin()
580 pins.sdp3_3 = off; in i40e_ptp_enable_pin()
581 pins.gpio_4 = off; in i40e_ptp_enable_pin()
584 return i40e_ptp_set_pins(pf, &pins) ? -EINVAL : 0; in i40e_ptp_enable_pin()
588 * i40e_ptp_feature_enable - Enable external clock pins
605 switch (rq->type) { in i40e_ptp_feature_enable()
608 chan = rq->extts.index; in i40e_ptp_feature_enable()
612 chan = rq->perout.index; in i40e_ptp_feature_enable()
617 return -EOPNOTSUPP; in i40e_ptp_feature_enable()
624 * i40e_ptp_get_rx_events - Read I40E_PRTTSYN_STAT_1 and latch events
629 * time a latch event was noticed which will be used to help clear out Rx
637 struct i40e_hw *hw = &pf->hw; in i40e_ptp_get_rx_events()
642 new_latch_events = prttsyn_stat & ~pf->latch_event_flags; in i40e_ptp_get_rx_events()
655 pf->latch_events[i] = jiffies; in i40e_ptp_get_rx_events()
658 /* Finally, we store the current status of the Rx timestamp latches */ in i40e_ptp_get_rx_events()
659 pf->latch_event_flags = prttsyn_stat; in i40e_ptp_get_rx_events()
665 * i40e_ptp_rx_hang - Detect error case when Rx timestamp registers are hung
669 * dropped an Rx packet that was timestamped when the ring is full. The
675 struct i40e_hw *hw = &pf->hw; in i40e_ptp_rx_hang()
678 /* Since we cannot turn off the Rx timestamp logic if the device is in i40e_ptp_rx_hang()
679 * configured for Tx timestamping, we check if Rx timestamping is in i40e_ptp_rx_hang()
680 * configured. We don't want to spuriously warn about Rx timestamp in i40e_ptp_rx_hang()
683 if (!test_bit(I40E_FLAG_PTP_ENA, pf->flags) || !pf->ptp_rx) in i40e_ptp_rx_hang()
686 spin_lock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hang()
688 /* Update current latch times for Rx events */ in i40e_ptp_rx_hang()
691 /* Check all the currently latched Rx events and see whether they have in i40e_ptp_rx_hang()
698 if ((pf->latch_event_flags & BIT(i)) && in i40e_ptp_rx_hang()
699 time_is_before_jiffies(pf->latch_events[i] + HZ)) { in i40e_ptp_rx_hang()
701 pf->latch_event_flags &= ~BIT(i); in i40e_ptp_rx_hang()
706 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hang()
715 dev_dbg(&pf->pdev->dev, in i40e_ptp_rx_hang()
720 pf->rx_hwtstamp_cleared += cleared; in i40e_ptp_rx_hang()
724 * i40e_ptp_tx_hang - Detect error case when Tx timestamp register is hung
736 if (!test_bit(I40E_FLAG_PTP_ENA, pf->flags) || !pf->ptp_tx) in i40e_ptp_tx_hang()
740 if (!test_bit(__I40E_PTP_TX_IN_PROGRESS, pf->state)) in i40e_ptp_tx_hang()
747 if (time_is_before_jiffies(pf->ptp_tx_start + HZ)) { in i40e_ptp_tx_hang()
748 skb = pf->ptp_tx_skb; in i40e_ptp_tx_hang()
749 pf->ptp_tx_skb = NULL; in i40e_ptp_tx_hang()
750 clear_bit_unlock(__I40E_PTP_TX_IN_PROGRESS, pf->state); in i40e_ptp_tx_hang()
754 pf->tx_hwtstamp_timeouts++; in i40e_ptp_tx_hang()
759 * i40e_ptp_tx_hwtstamp - Utility function which returns the Tx timestamp
769 struct sk_buff *skb = pf->ptp_tx_skb; in i40e_ptp_tx_hwtstamp()
770 struct i40e_hw *hw = &pf->hw; in i40e_ptp_tx_hwtstamp()
774 if (!test_bit(I40E_FLAG_PTP_ENA, pf->flags) || !pf->ptp_tx) in i40e_ptp_tx_hwtstamp()
778 if (!pf->ptp_tx_skb) in i40e_ptp_tx_hwtstamp()
792 pf->ptp_tx_skb = NULL; in i40e_ptp_tx_hwtstamp()
793 clear_bit_unlock(__I40E_PTP_TX_IN_PROGRESS, pf->state); in i40e_ptp_tx_hwtstamp()
801 * i40e_ptp_rx_hwtstamp - Utility function which checks for an Rx timestamp
818 /* Since we cannot turn off the Rx timestamp logic if the device is in i40e_ptp_rx_hwtstamp()
819 * doing Tx timestamping, check if Rx timestamping is configured. in i40e_ptp_rx_hwtstamp()
821 if (!test_bit(I40E_FLAG_PTP_ENA, pf->flags) || !pf->ptp_rx) in i40e_ptp_rx_hwtstamp()
824 hw = &pf->hw; in i40e_ptp_rx_hwtstamp()
826 spin_lock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hwtstamp()
828 /* Get current Rx events and update latch times */ in i40e_ptp_rx_hwtstamp()
831 /* TODO: Should we warn about missing Rx timestamp event? */ in i40e_ptp_rx_hwtstamp()
833 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hwtstamp()
838 pf->latch_event_flags &= ~BIT(index); in i40e_ptp_rx_hwtstamp()
843 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hwtstamp()
851 * i40e_ptp_set_increment - Utility function to update clock increment rate
861 struct i40e_hw *hw = &pf->hw; in i40e_ptp_set_increment()
865 hw_link_info = &hw->phy.link_info; in i40e_ptp_set_increment()
867 i40e_aq_get_link_info(&pf->hw, true, NULL, NULL); in i40e_ptp_set_increment()
869 switch (hw_link_info->link_speed) { in i40e_ptp_set_increment()
884 dev_warn(&pf->pdev->dev, in i40e_ptp_set_increment()
910 WRITE_ONCE(pf->ptp_adj_mult, mult); in i40e_ptp_set_increment()
915 * i40e_ptp_get_ts_config - ioctl interface to read the HW timestamping
925 struct hwtstamp_config *config = &pf->tstamp_config; in i40e_ptp_get_ts_config()
927 if (!test_bit(I40E_FLAG_PTP_ENA, pf->flags)) in i40e_ptp_get_ts_config()
928 return -EOPNOTSUPP; in i40e_ptp_get_ts_config()
930 return copy_to_user(ifr->ifr_data, config, sizeof(*config)) ? in i40e_ptp_get_ts_config()
931 -EFAULT : 0; in i40e_ptp_get_ts_config()
935 * i40e_ptp_free_pins - free memory used by PTP pins
938 * Release memory allocated for PTP pins.
942 if (i40e_is_ptp_pin_dev(&pf->hw)) { in i40e_ptp_free_pins()
943 kfree(pf->ptp_pins); in i40e_ptp_free_pins()
944 kfree(pf->ptp_caps.pin_config); in i40e_ptp_free_pins()
945 pf->ptp_pins = NULL; in i40e_ptp_free_pins()
950 * i40e_ptp_set_pin_hw - Set HW GPIO pin
987 * i40e_ptp_set_led_hw - Set HW GPIO led
1014 * i40e_ptp_init_leds_hw - init LEDs
1032 * i40e_ptp_set_pins_hw - Set HW GPIO pins
1035 * This function sets GPIO pins for PTP
1039 const struct i40e_ptp_pins_settings *pins = pf->ptp_pins; in i40e_ptp_set_pins_hw() local
1040 struct i40e_hw *hw = &pf->hw; in i40e_ptp_set_pins_hw()
1047 i40e_ptp_set_pin_hw(hw, I40E_SDP3_2, pins->sdp3_2); in i40e_ptp_set_pins_hw()
1048 i40e_ptp_set_pin_hw(hw, I40E_SDP3_3, pins->sdp3_3); in i40e_ptp_set_pins_hw()
1049 i40e_ptp_set_pin_hw(hw, I40E_GPIO_4, pins->gpio_4); in i40e_ptp_set_pins_hw()
1051 i40e_ptp_set_led_hw(hw, I40E_LED2_0, pins->led2_0); in i40e_ptp_set_pins_hw()
1052 i40e_ptp_set_led_hw(hw, I40E_LED2_1, pins->led2_1); in i40e_ptp_set_pins_hw()
1053 i40e_ptp_set_led_hw(hw, I40E_LED3_0, pins->led3_0); in i40e_ptp_set_pins_hw()
1054 i40e_ptp_set_led_hw(hw, I40E_LED3_1, pins->led3_1); in i40e_ptp_set_pins_hw()
1056 dev_info(&pf->pdev->dev, in i40e_ptp_set_pins_hw()
1058 i40e_ptp_gpio_pin_state2str[pins->sdp3_2], in i40e_ptp_set_pins_hw()
1059 i40e_ptp_gpio_pin_state2str[pins->sdp3_3], in i40e_ptp_set_pins_hw()
1060 i40e_ptp_gpio_pin_state2str[pins->gpio_4]); in i40e_ptp_set_pins_hw()
1064 * i40e_ptp_set_pins - set PTP pins in HW
1066 * @pins: PTP pins to be applied
1068 * Validate and set PTP pins in HW for specific PF.
1072 struct i40e_ptp_pins_settings *pins) in i40e_ptp_set_pins() argument
1078 return -EOPNOTSUPP; in i40e_ptp_set_pins()
1082 if (pins->sdp3_2 == invalid) in i40e_ptp_set_pins()
1083 pins->sdp3_2 = pf->ptp_pins->sdp3_2; in i40e_ptp_set_pins()
1084 if (pins->sdp3_3 == invalid) in i40e_ptp_set_pins()
1085 pins->sdp3_3 = pf->ptp_pins->sdp3_3; in i40e_ptp_set_pins()
1086 if (pins->gpio_4 == invalid) in i40e_ptp_set_pins()
1087 pins->gpio_4 = pf->ptp_pins->gpio_4; in i40e_ptp_set_pins()
1089 if (pins->sdp3_2 == i40e_ptp_pin_led_allowed_states[i].sdp3_2 && in i40e_ptp_set_pins()
1090 pins->sdp3_3 == i40e_ptp_pin_led_allowed_states[i].sdp3_3 && in i40e_ptp_set_pins()
1091 pins->gpio_4 == i40e_ptp_pin_led_allowed_states[i].gpio_4) { in i40e_ptp_set_pins()
1092 pins->led2_0 = in i40e_ptp_set_pins()
1094 pins->led2_1 = in i40e_ptp_set_pins()
1096 pins->led3_0 = in i40e_ptp_set_pins()
1098 pins->led3_1 = in i40e_ptp_set_pins()
1105 dev_warn(&pf->pdev->dev, in i40e_ptp_set_pins()
1107 i40e_ptp_gpio_pin_state2str[pins->sdp3_2], in i40e_ptp_set_pins()
1108 i40e_ptp_gpio_pin_state2str[pins->sdp3_3], in i40e_ptp_set_pins()
1109 i40e_ptp_gpio_pin_state2str[pins->gpio_4]); in i40e_ptp_set_pins()
1111 return -EPERM; in i40e_ptp_set_pins()
1113 memcpy(pf->ptp_pins, pins, sizeof(*pins)); in i40e_ptp_set_pins()
1121 * i40e_ptp_alloc_pins - allocate PTP pins structure
1124 * allocate PTP pins structure
1128 if (!i40e_is_ptp_pin_dev(&pf->hw)) in i40e_ptp_alloc_pins()
1131 pf->ptp_pins = in i40e_ptp_alloc_pins()
1134 if (!pf->ptp_pins) { in i40e_ptp_alloc_pins()
1135 dev_warn(&pf->pdev->dev, "Cannot allocate memory for PTP pins structure.\n"); in i40e_ptp_alloc_pins()
1136 return -ENOMEM; in i40e_ptp_alloc_pins()
1139 pf->ptp_pins->sdp3_2 = off; in i40e_ptp_alloc_pins()
1140 pf->ptp_pins->sdp3_3 = off; in i40e_ptp_alloc_pins()
1141 pf->ptp_pins->gpio_4 = off; in i40e_ptp_alloc_pins()
1142 pf->ptp_pins->led2_0 = high; in i40e_ptp_alloc_pins()
1143 pf->ptp_pins->led2_1 = high; in i40e_ptp_alloc_pins()
1144 pf->ptp_pins->led3_0 = high; in i40e_ptp_alloc_pins()
1145 pf->ptp_pins->led3_1 = high; in i40e_ptp_alloc_pins()
1147 /* Use PF0 to set pins in HW. Return success for user space tools */ in i40e_ptp_alloc_pins()
1148 if (pf->hw.pf_id) in i40e_ptp_alloc_pins()
1151 i40e_ptp_init_leds_hw(&pf->hw); in i40e_ptp_alloc_pins()
1158 * i40e_ptp_set_timestamp_mode - setup hardware for requested timestamp mode
1172 struct i40e_hw *hw = &pf->hw; in i40e_ptp_set_timestamp_mode()
1188 INIT_WORK(&pf->ptp_extts0_work, i40e_ptp_extts0_work); in i40e_ptp_set_timestamp_mode()
1190 switch (config->tx_type) { in i40e_ptp_set_timestamp_mode()
1192 pf->ptp_tx = false; in i40e_ptp_set_timestamp_mode()
1195 pf->ptp_tx = true; in i40e_ptp_set_timestamp_mode()
1198 return -ERANGE; in i40e_ptp_set_timestamp_mode()
1201 switch (config->rx_filter) { in i40e_ptp_set_timestamp_mode()
1203 pf->ptp_rx = false; in i40e_ptp_set_timestamp_mode()
1206 * disabling PTP Rx timestamps as possible since V1 packets in i40e_ptp_set_timestamp_mode()
1214 if (!test_bit(I40E_HW_CAP_PTP_L4, pf->hw.caps)) in i40e_ptp_set_timestamp_mode()
1215 return -ERANGE; in i40e_ptp_set_timestamp_mode()
1216 pf->ptp_rx = true; in i40e_ptp_set_timestamp_mode()
1220 config->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; in i40e_ptp_set_timestamp_mode()
1228 if (!test_bit(I40E_HW_CAP_PTP_L4, pf->hw.caps)) in i40e_ptp_set_timestamp_mode()
1229 return -ERANGE; in i40e_ptp_set_timestamp_mode()
1234 pf->ptp_rx = true; in i40e_ptp_set_timestamp_mode()
1237 if (test_bit(I40E_HW_CAP_PTP_L4, pf->hw.caps)) { in i40e_ptp_set_timestamp_mode()
1239 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; in i40e_ptp_set_timestamp_mode()
1241 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; in i40e_ptp_set_timestamp_mode()
1247 return -ERANGE; in i40e_ptp_set_timestamp_mode()
1250 /* Clear out all 1588-related registers to clear and unlatch them. */ in i40e_ptp_set_timestamp_mode()
1251 spin_lock_bh(&pf->ptp_rx_lock); in i40e_ptp_set_timestamp_mode()
1258 pf->latch_event_flags = 0; in i40e_ptp_set_timestamp_mode()
1259 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_set_timestamp_mode()
1263 if (pf->ptp_tx) in i40e_ptp_set_timestamp_mode()
1270 if (pf->ptp_tx) in i40e_ptp_set_timestamp_mode()
1276 /* Although there is no simple on/off switch for Rx, we "disable" Rx in i40e_ptp_set_timestamp_mode()
1278 * recognition. This ought to disable all PTP Rx timestamps as V1 in i40e_ptp_set_timestamp_mode()
1280 * ignore Rx timestamps via the pf->ptp_rx flag. in i40e_ptp_set_timestamp_mode()
1285 /* now enable bits for desired Rx timestamps */ in i40e_ptp_set_timestamp_mode()
1293 * i40e_ptp_set_ts_config - ioctl interface to control the HW timestamping
1298 * changes here. The XL710 cannot support splitting of the Tx/Rx timestamping
1311 if (!test_bit(I40E_FLAG_PTP_ENA, pf->flags)) in i40e_ptp_set_ts_config()
1312 return -EOPNOTSUPP; in i40e_ptp_set_ts_config()
1314 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) in i40e_ptp_set_ts_config()
1315 return -EFAULT; in i40e_ptp_set_ts_config()
1322 pf->tstamp_config = config; in i40e_ptp_set_ts_config()
1324 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? in i40e_ptp_set_ts_config()
1325 -EFAULT : 0; in i40e_ptp_set_ts_config()
1329 * i40e_init_pin_config - initialize pins.
1332 * Initialize pins for external clock source.
1339 pf->ptp_caps.n_pins = 3; in i40e_init_pin_config()
1340 pf->ptp_caps.n_ext_ts = 2; in i40e_init_pin_config()
1341 pf->ptp_caps.pps = 1; in i40e_init_pin_config()
1342 pf->ptp_caps.n_per_out = 2; in i40e_init_pin_config()
1344 pf->ptp_caps.pin_config = kcalloc(pf->ptp_caps.n_pins, in i40e_init_pin_config()
1345 sizeof(*pf->ptp_caps.pin_config), in i40e_init_pin_config()
1347 if (!pf->ptp_caps.pin_config) in i40e_init_pin_config()
1348 return -ENOMEM; in i40e_init_pin_config()
1350 for (i = 0; i < pf->ptp_caps.n_pins; i++) { in i40e_init_pin_config()
1351 snprintf(pf->ptp_caps.pin_config[i].name, in i40e_init_pin_config()
1352 sizeof(pf->ptp_caps.pin_config[i].name), in i40e_init_pin_config()
1354 pf->ptp_caps.pin_config[i].index = sdp_desc[i].index; in i40e_init_pin_config()
1355 pf->ptp_caps.pin_config[i].func = PTP_PF_NONE; in i40e_init_pin_config()
1356 pf->ptp_caps.pin_config[i].chan = sdp_desc[i].chan; in i40e_init_pin_config()
1359 pf->ptp_caps.verify = i40e_ptp_verify; in i40e_init_pin_config()
1360 pf->ptp_caps.enable = i40e_ptp_feature_enable; in i40e_init_pin_config()
1362 pf->ptp_caps.pps = 1; in i40e_init_pin_config()
1368 * i40e_ptp_create_clock - Create PTP clock device for userspace
1380 if (!IS_ERR_OR_NULL(pf->ptp_clock)) in i40e_ptp_create_clock()
1383 strscpy(pf->ptp_caps.name, i40e_driver_name, in i40e_ptp_create_clock()
1384 sizeof(pf->ptp_caps.name) - 1); in i40e_ptp_create_clock()
1385 pf->ptp_caps.owner = THIS_MODULE; in i40e_ptp_create_clock()
1386 pf->ptp_caps.max_adj = 999999999; in i40e_ptp_create_clock()
1387 pf->ptp_caps.adjfine = i40e_ptp_adjfine; in i40e_ptp_create_clock()
1388 pf->ptp_caps.adjtime = i40e_ptp_adjtime; in i40e_ptp_create_clock()
1389 pf->ptp_caps.gettimex64 = i40e_ptp_gettimex; in i40e_ptp_create_clock()
1390 pf->ptp_caps.settime64 = i40e_ptp_settime; in i40e_ptp_create_clock()
1391 if (i40e_is_ptp_pin_dev(&pf->hw)) { in i40e_ptp_create_clock()
1399 pf->ptp_clock = ptp_clock_register(&pf->ptp_caps, &pf->pdev->dev); in i40e_ptp_create_clock()
1400 if (IS_ERR(pf->ptp_clock)) in i40e_ptp_create_clock()
1401 return PTR_ERR(pf->ptp_clock); in i40e_ptp_create_clock()
1407 pf->tstamp_config.rx_filter = HWTSTAMP_FILTER_NONE; in i40e_ptp_create_clock()
1408 pf->tstamp_config.tx_type = HWTSTAMP_TX_OFF; in i40e_ptp_create_clock()
1411 ktime_get_real_ts64(&pf->ptp_prev_hw_time); in i40e_ptp_create_clock()
1412 pf->ptp_reset_start = ktime_get(); in i40e_ptp_create_clock()
1418 * i40e_ptp_save_hw_time - Save the current PTP time as ptp_prev_hw_time
1421 * Read the current PTP time and save it into pf->ptp_prev_hw_time. This should
1429 if (!test_bit(I40E_FLAG_PTP_ENA, pf->flags)) in i40e_ptp_save_hw_time()
1432 i40e_ptp_gettimex(&pf->ptp_caps, &pf->ptp_prev_hw_time, NULL); in i40e_ptp_save_hw_time()
1434 pf->ptp_reset_start = ktime_get(); in i40e_ptp_save_hw_time()
1438 * i40e_ptp_restore_hw_time - Restore the ptp_prev_hw_time + delta to PTP regs
1442 * hardware time as pf->ptp_prev_hw_time. To be as accurate as possible,
1451 ktime_t delta = ktime_sub(ktime_get(), pf->ptp_reset_start); in i40e_ptp_restore_hw_time()
1454 timespec64_add_ns(&pf->ptp_prev_hw_time, ktime_to_ns(delta)); in i40e_ptp_restore_hw_time()
1457 i40e_ptp_settime(&pf->ptp_caps, &pf->ptp_prev_hw_time); in i40e_ptp_restore_hw_time()
1461 * i40e_ptp_init - Initialize the 1588 support after device probe or reset
1469 * pf->ptp_prev_hw_time to the current system time. During resets, it is
1476 struct net_device *netdev = vsi->netdev; in i40e_ptp_init()
1477 struct i40e_hw *hw = &pf->hw; in i40e_ptp_init()
1486 if (hw->pf_id != pf_id) { in i40e_ptp_init()
1487 clear_bit(I40E_FLAG_PTP_ENA, pf->flags); in i40e_ptp_init()
1488 dev_info(&pf->pdev->dev, "%s: PTP not supported on %s\n", in i40e_ptp_init()
1490 netdev->name); in i40e_ptp_init()
1494 mutex_init(&pf->tmreg_lock); in i40e_ptp_init()
1495 spin_lock_init(&pf->ptp_rx_lock); in i40e_ptp_init()
1500 pf->ptp_clock = NULL; in i40e_ptp_init()
1501 dev_err(&pf->pdev->dev, "%s: ptp_clock_register failed\n", in i40e_ptp_init()
1503 } else if (pf->ptp_clock) { in i40e_ptp_init()
1506 if (pf->hw.debug_mask & I40E_DEBUG_LAN) in i40e_ptp_init()
1507 dev_info(&pf->pdev->dev, "PHC enabled\n"); in i40e_ptp_init()
1508 set_bit(I40E_FLAG_PTP_ENA, pf->flags); in i40e_ptp_init()
1522 i40e_ptp_set_timestamp_mode(pf, &pf->tstamp_config); in i40e_ptp_init()
1532 * i40e_ptp_stop - Disable the driver/hardware support and unregister the PHC
1541 struct i40e_hw *hw = &pf->hw; in i40e_ptp_stop()
1544 clear_bit(I40E_FLAG_PTP_ENA, pf->flags); in i40e_ptp_stop()
1545 pf->ptp_tx = false; in i40e_ptp_stop()
1546 pf->ptp_rx = false; in i40e_ptp_stop()
1548 if (pf->ptp_tx_skb) { in i40e_ptp_stop()
1549 struct sk_buff *skb = pf->ptp_tx_skb; in i40e_ptp_stop()
1551 pf->ptp_tx_skb = NULL; in i40e_ptp_stop()
1552 clear_bit_unlock(__I40E_PTP_TX_IN_PROGRESS, pf->state); in i40e_ptp_stop()
1556 if (pf->ptp_clock) { in i40e_ptp_stop()
1557 ptp_clock_unregister(pf->ptp_clock); in i40e_ptp_stop()
1558 pf->ptp_clock = NULL; in i40e_ptp_stop()
1559 dev_info(&pf->pdev->dev, "%s: removed PHC on %s\n", __func__, in i40e_ptp_stop()
1560 main_vsi->netdev->name); in i40e_ptp_stop()
1563 if (i40e_is_ptp_pin_dev(&pf->hw)) { in i40e_ptp_stop()