Lines Matching +full:rx +full:- +full:pins
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
6 #include <linux/posix-clock.h>
38 CANT_DO_PINS = -1,
51 end = -2,
65 led_end = -2,
141 struct i40e_ptp_pins_settings *pins);
144 * i40e_ptp_extts0_work - workqueue task function
153 struct i40e_hw *hw = &pf->hw; in i40e_ptp_extts0_work()
168 event.index = hw->pf_id; in i40e_ptp_extts0_work()
171 ptp_clock_event(pf->ptp_clock, &event); in i40e_ptp_extts0_work()
175 * i40e_is_ptp_pin_dev - check if device supports PTP pins
178 * Return true if device supports PTP pins, false otherwise.
182 return hw->device_id == I40E_DEV_ID_25G_SFP28 && in i40e_is_ptp_pin_dev()
183 hw->subsystem_device_id == I40E_SUBDEV_ID_25G_PTP_PIN; in i40e_is_ptp_pin_dev()
187 * i40e_can_set_pins - check possibility of manipulating the pins
190 * Check if all conditions are satisfied to manipulate PTP pins.
191 * Return CAN_SET_PINS if pins can be set on a specific PF or
192 * return CAN_DO_PINS if pins can be manipulated within a NIC or
197 if (!i40e_is_ptp_pin_dev(&pf->hw)) { in i40e_can_set_pins()
198 dev_warn(&pf->pdev->dev, in i40e_can_set_pins()
203 if (!pf->ptp_pins) { in i40e_can_set_pins()
204 dev_warn(&pf->pdev->dev, in i40e_can_set_pins()
209 if (pf->hw.pf_id) { in i40e_can_set_pins()
210 dev_warn(&pf->pdev->dev, in i40e_can_set_pins()
211 "PTP PINs should be accessed via PF0.\n"); in i40e_can_set_pins()
219 * i40_ptp_reset_timing_events - Reset PTP timing events
228 spin_lock_bh(&pf->ptp_rx_lock); in i40_ptp_reset_timing_events()
231 rd32(&pf->hw, I40E_PRTTSYN_RXTIME_L(i)); in i40_ptp_reset_timing_events()
232 rd32(&pf->hw, I40E_PRTTSYN_RXTIME_H(i)); in i40_ptp_reset_timing_events()
233 pf->latch_events[i] = 0; in i40_ptp_reset_timing_events()
236 rd32(&pf->hw, I40E_PRTTSYN_TXTIME_L); in i40_ptp_reset_timing_events()
237 rd32(&pf->hw, I40E_PRTTSYN_TXTIME_H); in i40_ptp_reset_timing_events()
239 pf->tx_hwtstamp_timeouts = 0; in i40_ptp_reset_timing_events()
240 pf->tx_hwtstamp_skipped = 0; in i40_ptp_reset_timing_events()
241 pf->rx_hwtstamp_cleared = 0; in i40_ptp_reset_timing_events()
242 pf->latch_event_flags = 0; in i40_ptp_reset_timing_events()
243 spin_unlock_bh(&pf->ptp_rx_lock); in i40_ptp_reset_timing_events()
247 * i40e_ptp_verify - check pins
253 * Check pins consistency.
265 return -EOPNOTSUPP; in i40e_ptp_verify()
271 * i40e_ptp_read - Read the PHC time from the device
283 struct i40e_hw *hw = &pf->hw; in i40e_ptp_read()
299 * i40e_ptp_write - Write the PHC time to the device
309 struct i40e_hw *hw = &pf->hw; in i40e_ptp_write()
320 * i40e_ptp_convert_to_hwtstamp - Convert device clock to system time
325 * the upper level timestamping functions. Since the timestamp is simply a 64-
333 hwtstamps->hwtstamp = ns_to_ktime(timestamp); in i40e_ptp_convert_to_hwtstamp()
337 * i40e_ptp_adjfine - Adjust the PHC frequency
349 struct i40e_hw *hw = &pf->hw; in i40e_ptp_adjfine()
355 scaled_ppm = -scaled_ppm; in i40e_ptp_adjfine()
359 freq = I40E_PTP_40GB_INCVAL * READ_ONCE(pf->ptp_adj_mult); in i40e_ptp_adjfine()
364 adj = I40E_PTP_40GB_INCVAL - diff; in i40e_ptp_adjfine()
375 * i40e_ptp_set_1pps_signal_hw - configure 1PPS PTP signal for pins
378 * Configure 1PPS signal used for PTP pins
382 struct i40e_hw *hw = &pf->hw; in i40e_ptp_set_1pps_signal_hw()
406 * i40e_ptp_adjtime - Adjust the PHC time
415 struct i40e_hw *hw = &pf->hw; in i40e_ptp_adjtime()
417 mutex_lock(&pf->tmreg_lock); in i40e_ptp_adjtime()
419 if (delta > -999999900LL && delta < 999999900LL) { in i40e_ptp_adjtime()
426 tohw = -delta; in i40e_ptp_adjtime()
445 mutex_unlock(&pf->tmreg_lock); in i40e_ptp_adjtime()
451 * i40e_ptp_gettimex - Get the time of the PHC
464 mutex_lock(&pf->tmreg_lock); in i40e_ptp_gettimex()
466 mutex_unlock(&pf->tmreg_lock); in i40e_ptp_gettimex()
472 * i40e_ptp_settime - Set the time of the PHC
484 mutex_lock(&pf->tmreg_lock); in i40e_ptp_settime()
486 mutex_unlock(&pf->tmreg_lock); in i40e_ptp_settime()
492 * i40e_pps_configure - configure PPS events
513 * i40e_pin_state - determine PIN state
537 * i40e_ptp_enable_pin - enable PINs.
543 * Enable PTP pins for external clock source.
550 struct i40e_ptp_pins_settings pins; in i40e_ptp_enable_pin() local
553 /* Use PF0 to set pins. Return success for user space tools */ in i40e_ptp_enable_pin()
554 if (pf->hw.pf_id) in i40e_ptp_enable_pin()
557 /* Preserve previous state of pins that we don't touch */ in i40e_ptp_enable_pin()
558 pins.sdp3_2 = pf->ptp_pins->sdp3_2; in i40e_ptp_enable_pin()
559 pins.sdp3_3 = pf->ptp_pins->sdp3_3; in i40e_ptp_enable_pin()
560 pins.gpio_4 = pf->ptp_pins->gpio_4; in i40e_ptp_enable_pin()
562 /* To turn on the pin - find the corresponding one based on in i40e_ptp_enable_pin()
563 * the given index. To to turn the function off - find in i40e_ptp_enable_pin()
569 pin_index = ptp_find_pin(pf->ptp_clock, func, chan); in i40e_ptp_enable_pin()
571 return -EBUSY; in i40e_ptp_enable_pin()
575 pin = &pins.sdp3_2; in i40e_ptp_enable_pin()
578 pin = &pins.sdp3_3; in i40e_ptp_enable_pin()
581 pin = &pins.gpio_4; in i40e_ptp_enable_pin()
584 return -EINVAL; in i40e_ptp_enable_pin()
589 pins.sdp3_2 = off; in i40e_ptp_enable_pin()
590 pins.sdp3_3 = off; in i40e_ptp_enable_pin()
591 pins.gpio_4 = off; in i40e_ptp_enable_pin()
594 return i40e_ptp_set_pins(pf, &pins) ? -EINVAL : 0; in i40e_ptp_enable_pin()
598 * i40e_ptp_feature_enable - Enable external clock pins
615 switch (rq->type) { in i40e_ptp_feature_enable()
618 chan = rq->extts.index; in i40e_ptp_feature_enable()
622 chan = rq->perout.index; in i40e_ptp_feature_enable()
627 return -EOPNOTSUPP; in i40e_ptp_feature_enable()
634 * i40e_ptp_get_rx_events - Read I40E_PRTTSYN_STAT_1 and latch events
639 * time a latch event was noticed which will be used to help clear out Rx
647 struct i40e_hw *hw = &pf->hw; in i40e_ptp_get_rx_events()
652 new_latch_events = prttsyn_stat & ~pf->latch_event_flags; in i40e_ptp_get_rx_events()
665 pf->latch_events[i] = jiffies; in i40e_ptp_get_rx_events()
668 /* Finally, we store the current status of the Rx timestamp latches */ in i40e_ptp_get_rx_events()
669 pf->latch_event_flags = prttsyn_stat; in i40e_ptp_get_rx_events()
675 * i40e_ptp_rx_hang - Detect error case when Rx timestamp registers are hung
679 * dropped an Rx packet that was timestamped when the ring is full. The
685 struct i40e_hw *hw = &pf->hw; in i40e_ptp_rx_hang()
688 /* Since we cannot turn off the Rx timestamp logic if the device is in i40e_ptp_rx_hang()
689 * configured for Tx timestamping, we check if Rx timestamping is in i40e_ptp_rx_hang()
690 * configured. We don't want to spuriously warn about Rx timestamp in i40e_ptp_rx_hang()
693 if (!(pf->flags & I40E_FLAG_PTP) || !pf->ptp_rx) in i40e_ptp_rx_hang()
696 spin_lock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hang()
698 /* Update current latch times for Rx events */ in i40e_ptp_rx_hang()
701 /* Check all the currently latched Rx events and see whether they have in i40e_ptp_rx_hang()
708 if ((pf->latch_event_flags & BIT(i)) && in i40e_ptp_rx_hang()
709 time_is_before_jiffies(pf->latch_events[i] + HZ)) { in i40e_ptp_rx_hang()
711 pf->latch_event_flags &= ~BIT(i); in i40e_ptp_rx_hang()
716 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hang()
725 dev_dbg(&pf->pdev->dev, in i40e_ptp_rx_hang()
730 pf->rx_hwtstamp_cleared += cleared; in i40e_ptp_rx_hang()
734 * i40e_ptp_tx_hang - Detect error case when Tx timestamp register is hung
746 if (!(pf->flags & I40E_FLAG_PTP) || !pf->ptp_tx) in i40e_ptp_tx_hang()
750 if (!test_bit(__I40E_PTP_TX_IN_PROGRESS, pf->state)) in i40e_ptp_tx_hang()
757 if (time_is_before_jiffies(pf->ptp_tx_start + HZ)) { in i40e_ptp_tx_hang()
758 skb = pf->ptp_tx_skb; in i40e_ptp_tx_hang()
759 pf->ptp_tx_skb = NULL; in i40e_ptp_tx_hang()
760 clear_bit_unlock(__I40E_PTP_TX_IN_PROGRESS, pf->state); in i40e_ptp_tx_hang()
764 pf->tx_hwtstamp_timeouts++; in i40e_ptp_tx_hang()
769 * i40e_ptp_tx_hwtstamp - Utility function which returns the Tx timestamp
779 struct sk_buff *skb = pf->ptp_tx_skb; in i40e_ptp_tx_hwtstamp()
780 struct i40e_hw *hw = &pf->hw; in i40e_ptp_tx_hwtstamp()
784 if (!(pf->flags & I40E_FLAG_PTP) || !pf->ptp_tx) in i40e_ptp_tx_hwtstamp()
788 if (!pf->ptp_tx_skb) in i40e_ptp_tx_hwtstamp()
802 pf->ptp_tx_skb = NULL; in i40e_ptp_tx_hwtstamp()
803 clear_bit_unlock(__I40E_PTP_TX_IN_PROGRESS, pf->state); in i40e_ptp_tx_hwtstamp()
811 * i40e_ptp_rx_hwtstamp - Utility function which checks for an Rx timestamp
828 /* Since we cannot turn off the Rx timestamp logic if the device is in i40e_ptp_rx_hwtstamp()
829 * doing Tx timestamping, check if Rx timestamping is configured. in i40e_ptp_rx_hwtstamp()
831 if (!(pf->flags & I40E_FLAG_PTP) || !pf->ptp_rx) in i40e_ptp_rx_hwtstamp()
834 hw = &pf->hw; in i40e_ptp_rx_hwtstamp()
836 spin_lock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hwtstamp()
838 /* Get current Rx events and update latch times */ in i40e_ptp_rx_hwtstamp()
841 /* TODO: Should we warn about missing Rx timestamp event? */ in i40e_ptp_rx_hwtstamp()
843 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hwtstamp()
848 pf->latch_event_flags &= ~BIT(index); in i40e_ptp_rx_hwtstamp()
853 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hwtstamp()
861 * i40e_ptp_set_increment - Utility function to update clock increment rate
871 struct i40e_hw *hw = &pf->hw; in i40e_ptp_set_increment()
875 hw_link_info = &hw->phy.link_info; in i40e_ptp_set_increment()
877 i40e_aq_get_link_info(&pf->hw, true, NULL, NULL); in i40e_ptp_set_increment()
879 switch (hw_link_info->link_speed) { in i40e_ptp_set_increment()
894 dev_warn(&pf->pdev->dev, in i40e_ptp_set_increment()
920 WRITE_ONCE(pf->ptp_adj_mult, mult); in i40e_ptp_set_increment()
925 * i40e_ptp_get_ts_config - ioctl interface to read the HW timestamping
935 struct hwtstamp_config *config = &pf->tstamp_config; in i40e_ptp_get_ts_config()
937 if (!(pf->flags & I40E_FLAG_PTP)) in i40e_ptp_get_ts_config()
938 return -EOPNOTSUPP; in i40e_ptp_get_ts_config()
940 return copy_to_user(ifr->ifr_data, config, sizeof(*config)) ? in i40e_ptp_get_ts_config()
941 -EFAULT : 0; in i40e_ptp_get_ts_config()
945 * i40e_ptp_free_pins - free memory used by PTP pins
948 * Release memory allocated for PTP pins.
952 if (i40e_is_ptp_pin_dev(&pf->hw)) { in i40e_ptp_free_pins()
953 kfree(pf->ptp_pins); in i40e_ptp_free_pins()
954 kfree(pf->ptp_caps.pin_config); in i40e_ptp_free_pins()
955 pf->ptp_pins = NULL; in i40e_ptp_free_pins()
960 * i40e_ptp_set_pin_hw - Set HW GPIO pin
997 * i40e_ptp_set_led_hw - Set HW GPIO led
1024 * i40e_ptp_init_leds_hw - init LEDs
1042 * i40e_ptp_set_pins_hw - Set HW GPIO pins
1045 * This function sets GPIO pins for PTP
1049 const struct i40e_ptp_pins_settings *pins = pf->ptp_pins; in i40e_ptp_set_pins_hw() local
1050 struct i40e_hw *hw = &pf->hw; in i40e_ptp_set_pins_hw()
1057 i40e_ptp_set_pin_hw(hw, I40E_SDP3_2, pins->sdp3_2); in i40e_ptp_set_pins_hw()
1058 i40e_ptp_set_pin_hw(hw, I40E_SDP3_3, pins->sdp3_3); in i40e_ptp_set_pins_hw()
1059 i40e_ptp_set_pin_hw(hw, I40E_GPIO_4, pins->gpio_4); in i40e_ptp_set_pins_hw()
1061 i40e_ptp_set_led_hw(hw, I40E_LED2_0, pins->led2_0); in i40e_ptp_set_pins_hw()
1062 i40e_ptp_set_led_hw(hw, I40E_LED2_1, pins->led2_1); in i40e_ptp_set_pins_hw()
1063 i40e_ptp_set_led_hw(hw, I40E_LED3_0, pins->led3_0); in i40e_ptp_set_pins_hw()
1064 i40e_ptp_set_led_hw(hw, I40E_LED3_1, pins->led3_1); in i40e_ptp_set_pins_hw()
1066 dev_info(&pf->pdev->dev, in i40e_ptp_set_pins_hw()
1068 i40e_ptp_gpio_pin_state2str[pins->sdp3_2], in i40e_ptp_set_pins_hw()
1069 i40e_ptp_gpio_pin_state2str[pins->sdp3_3], in i40e_ptp_set_pins_hw()
1070 i40e_ptp_gpio_pin_state2str[pins->gpio_4]); in i40e_ptp_set_pins_hw()
1074 * i40e_ptp_set_pins - set PTP pins in HW
1076 * @pins: PTP pins to be applied
1078 * Validate and set PTP pins in HW for specific PF.
1082 struct i40e_ptp_pins_settings *pins) in i40e_ptp_set_pins() argument
1088 return -EOPNOTSUPP; in i40e_ptp_set_pins()
1092 if (pins->sdp3_2 == invalid) in i40e_ptp_set_pins()
1093 pins->sdp3_2 = pf->ptp_pins->sdp3_2; in i40e_ptp_set_pins()
1094 if (pins->sdp3_3 == invalid) in i40e_ptp_set_pins()
1095 pins->sdp3_3 = pf->ptp_pins->sdp3_3; in i40e_ptp_set_pins()
1096 if (pins->gpio_4 == invalid) in i40e_ptp_set_pins()
1097 pins->gpio_4 = pf->ptp_pins->gpio_4; in i40e_ptp_set_pins()
1099 if (pins->sdp3_2 == i40e_ptp_pin_led_allowed_states[i].sdp3_2 && in i40e_ptp_set_pins()
1100 pins->sdp3_3 == i40e_ptp_pin_led_allowed_states[i].sdp3_3 && in i40e_ptp_set_pins()
1101 pins->gpio_4 == i40e_ptp_pin_led_allowed_states[i].gpio_4) { in i40e_ptp_set_pins()
1102 pins->led2_0 = in i40e_ptp_set_pins()
1104 pins->led2_1 = in i40e_ptp_set_pins()
1106 pins->led3_0 = in i40e_ptp_set_pins()
1108 pins->led3_1 = in i40e_ptp_set_pins()
1115 dev_warn(&pf->pdev->dev, in i40e_ptp_set_pins()
1117 i40e_ptp_gpio_pin_state2str[pins->sdp3_2], in i40e_ptp_set_pins()
1118 i40e_ptp_gpio_pin_state2str[pins->sdp3_3], in i40e_ptp_set_pins()
1119 i40e_ptp_gpio_pin_state2str[pins->gpio_4]); in i40e_ptp_set_pins()
1121 return -EPERM; in i40e_ptp_set_pins()
1123 memcpy(pf->ptp_pins, pins, sizeof(*pins)); in i40e_ptp_set_pins()
1131 * i40e_ptp_alloc_pins - allocate PTP pins structure
1134 * allocate PTP pins structure
1138 if (!i40e_is_ptp_pin_dev(&pf->hw)) in i40e_ptp_alloc_pins()
1141 pf->ptp_pins = in i40e_ptp_alloc_pins()
1144 if (!pf->ptp_pins) { in i40e_ptp_alloc_pins()
1145 dev_warn(&pf->pdev->dev, "Cannot allocate memory for PTP pins structure.\n"); in i40e_ptp_alloc_pins()
1146 return -I40E_ERR_NO_MEMORY; in i40e_ptp_alloc_pins()
1149 pf->ptp_pins->sdp3_2 = off; in i40e_ptp_alloc_pins()
1150 pf->ptp_pins->sdp3_3 = off; in i40e_ptp_alloc_pins()
1151 pf->ptp_pins->gpio_4 = off; in i40e_ptp_alloc_pins()
1152 pf->ptp_pins->led2_0 = high; in i40e_ptp_alloc_pins()
1153 pf->ptp_pins->led2_1 = high; in i40e_ptp_alloc_pins()
1154 pf->ptp_pins->led3_0 = high; in i40e_ptp_alloc_pins()
1155 pf->ptp_pins->led3_1 = high; in i40e_ptp_alloc_pins()
1157 /* Use PF0 to set pins in HW. Return success for user space tools */ in i40e_ptp_alloc_pins()
1158 if (pf->hw.pf_id) in i40e_ptp_alloc_pins()
1161 i40e_ptp_init_leds_hw(&pf->hw); in i40e_ptp_alloc_pins()
1168 * i40e_ptp_set_timestamp_mode - setup hardware for requested timestamp mode
1182 struct i40e_hw *hw = &pf->hw; in i40e_ptp_set_timestamp_mode()
1198 INIT_WORK(&pf->ptp_extts0_work, i40e_ptp_extts0_work); in i40e_ptp_set_timestamp_mode()
1200 switch (config->tx_type) { in i40e_ptp_set_timestamp_mode()
1202 pf->ptp_tx = false; in i40e_ptp_set_timestamp_mode()
1205 pf->ptp_tx = true; in i40e_ptp_set_timestamp_mode()
1208 return -ERANGE; in i40e_ptp_set_timestamp_mode()
1211 switch (config->rx_filter) { in i40e_ptp_set_timestamp_mode()
1213 pf->ptp_rx = false; in i40e_ptp_set_timestamp_mode()
1216 * disabling PTP Rx timestamps as possible since V1 packets in i40e_ptp_set_timestamp_mode()
1224 if (!(pf->hw_features & I40E_HW_PTP_L4_CAPABLE)) in i40e_ptp_set_timestamp_mode()
1225 return -ERANGE; in i40e_ptp_set_timestamp_mode()
1226 pf->ptp_rx = true; in i40e_ptp_set_timestamp_mode()
1230 config->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; in i40e_ptp_set_timestamp_mode()
1238 if (!(pf->hw_features & I40E_HW_PTP_L4_CAPABLE)) in i40e_ptp_set_timestamp_mode()
1239 return -ERANGE; in i40e_ptp_set_timestamp_mode()
1244 pf->ptp_rx = true; in i40e_ptp_set_timestamp_mode()
1247 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE) { in i40e_ptp_set_timestamp_mode()
1249 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; in i40e_ptp_set_timestamp_mode()
1251 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; in i40e_ptp_set_timestamp_mode()
1257 return -ERANGE; in i40e_ptp_set_timestamp_mode()
1260 /* Clear out all 1588-related registers to clear and unlatch them. */ in i40e_ptp_set_timestamp_mode()
1261 spin_lock_bh(&pf->ptp_rx_lock); in i40e_ptp_set_timestamp_mode()
1268 pf->latch_event_flags = 0; in i40e_ptp_set_timestamp_mode()
1269 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_set_timestamp_mode()
1273 if (pf->ptp_tx) in i40e_ptp_set_timestamp_mode()
1280 if (pf->ptp_tx) in i40e_ptp_set_timestamp_mode()
1286 /* Although there is no simple on/off switch for Rx, we "disable" Rx in i40e_ptp_set_timestamp_mode()
1288 * recognition. This ought to disable all PTP Rx timestamps as V1 in i40e_ptp_set_timestamp_mode()
1290 * ignore Rx timestamps via the pf->ptp_rx flag. in i40e_ptp_set_timestamp_mode()
1295 /* now enable bits for desired Rx timestamps */ in i40e_ptp_set_timestamp_mode()
1303 * i40e_ptp_set_ts_config - ioctl interface to control the HW timestamping
1308 * changes here. The XL710 cannot support splitting of the Tx/Rx timestamping
1321 if (!(pf->flags & I40E_FLAG_PTP)) in i40e_ptp_set_ts_config()
1322 return -EOPNOTSUPP; in i40e_ptp_set_ts_config()
1324 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) in i40e_ptp_set_ts_config()
1325 return -EFAULT; in i40e_ptp_set_ts_config()
1332 pf->tstamp_config = config; in i40e_ptp_set_ts_config()
1334 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? in i40e_ptp_set_ts_config()
1335 -EFAULT : 0; in i40e_ptp_set_ts_config()
1339 * i40e_init_pin_config - initialize pins.
1342 * Initialize pins for external clock source.
1349 pf->ptp_caps.n_pins = 3; in i40e_init_pin_config()
1350 pf->ptp_caps.n_ext_ts = 2; in i40e_init_pin_config()
1351 pf->ptp_caps.pps = 1; in i40e_init_pin_config()
1352 pf->ptp_caps.n_per_out = 2; in i40e_init_pin_config()
1354 pf->ptp_caps.pin_config = kcalloc(pf->ptp_caps.n_pins, in i40e_init_pin_config()
1355 sizeof(*pf->ptp_caps.pin_config), in i40e_init_pin_config()
1357 if (!pf->ptp_caps.pin_config) in i40e_init_pin_config()
1358 return -ENOMEM; in i40e_init_pin_config()
1360 for (i = 0; i < pf->ptp_caps.n_pins; i++) { in i40e_init_pin_config()
1361 snprintf(pf->ptp_caps.pin_config[i].name, in i40e_init_pin_config()
1362 sizeof(pf->ptp_caps.pin_config[i].name), in i40e_init_pin_config()
1364 pf->ptp_caps.pin_config[i].index = sdp_desc[i].index; in i40e_init_pin_config()
1365 pf->ptp_caps.pin_config[i].func = PTP_PF_NONE; in i40e_init_pin_config()
1366 pf->ptp_caps.pin_config[i].chan = sdp_desc[i].chan; in i40e_init_pin_config()
1369 pf->ptp_caps.verify = i40e_ptp_verify; in i40e_init_pin_config()
1370 pf->ptp_caps.enable = i40e_ptp_feature_enable; in i40e_init_pin_config()
1372 pf->ptp_caps.pps = 1; in i40e_init_pin_config()
1378 * i40e_ptp_create_clock - Create PTP clock device for userspace
1390 if (!IS_ERR_OR_NULL(pf->ptp_clock)) in i40e_ptp_create_clock()
1393 strscpy(pf->ptp_caps.name, i40e_driver_name, in i40e_ptp_create_clock()
1394 sizeof(pf->ptp_caps.name) - 1); in i40e_ptp_create_clock()
1395 pf->ptp_caps.owner = THIS_MODULE; in i40e_ptp_create_clock()
1396 pf->ptp_caps.max_adj = 999999999; in i40e_ptp_create_clock()
1397 pf->ptp_caps.adjfine = i40e_ptp_adjfine; in i40e_ptp_create_clock()
1398 pf->ptp_caps.adjtime = i40e_ptp_adjtime; in i40e_ptp_create_clock()
1399 pf->ptp_caps.gettimex64 = i40e_ptp_gettimex; in i40e_ptp_create_clock()
1400 pf->ptp_caps.settime64 = i40e_ptp_settime; in i40e_ptp_create_clock()
1401 if (i40e_is_ptp_pin_dev(&pf->hw)) { in i40e_ptp_create_clock()
1409 pf->ptp_clock = ptp_clock_register(&pf->ptp_caps, &pf->pdev->dev); in i40e_ptp_create_clock()
1410 if (IS_ERR(pf->ptp_clock)) in i40e_ptp_create_clock()
1411 return PTR_ERR(pf->ptp_clock); in i40e_ptp_create_clock()
1417 pf->tstamp_config.rx_filter = HWTSTAMP_FILTER_NONE; in i40e_ptp_create_clock()
1418 pf->tstamp_config.tx_type = HWTSTAMP_TX_OFF; in i40e_ptp_create_clock()
1421 ktime_get_real_ts64(&pf->ptp_prev_hw_time); in i40e_ptp_create_clock()
1422 pf->ptp_reset_start = ktime_get(); in i40e_ptp_create_clock()
1428 * i40e_ptp_save_hw_time - Save the current PTP time as ptp_prev_hw_time
1431 * Read the current PTP time and save it into pf->ptp_prev_hw_time. This should
1439 if (!(pf->flags & I40E_FLAG_PTP)) in i40e_ptp_save_hw_time()
1442 i40e_ptp_gettimex(&pf->ptp_caps, &pf->ptp_prev_hw_time, NULL); in i40e_ptp_save_hw_time()
1444 pf->ptp_reset_start = ktime_get(); in i40e_ptp_save_hw_time()
1448 * i40e_ptp_restore_hw_time - Restore the ptp_prev_hw_time + delta to PTP regs
1452 * hardware time as pf->ptp_prev_hw_time. To be as accurate as possible,
1461 ktime_t delta = ktime_sub(ktime_get(), pf->ptp_reset_start); in i40e_ptp_restore_hw_time()
1464 timespec64_add_ns(&pf->ptp_prev_hw_time, ktime_to_ns(delta)); in i40e_ptp_restore_hw_time()
1467 i40e_ptp_settime(&pf->ptp_caps, &pf->ptp_prev_hw_time); in i40e_ptp_restore_hw_time()
1471 * i40e_ptp_init - Initialize the 1588 support after device probe or reset
1479 * pf->ptp_prev_hw_time to the current system time. During resets, it is
1485 struct net_device *netdev = pf->vsi[pf->lan_vsi]->netdev; in i40e_ptp_init()
1486 struct i40e_hw *hw = &pf->hw; in i40e_ptp_init()
1495 if (hw->pf_id != pf_id) { in i40e_ptp_init()
1496 pf->flags &= ~I40E_FLAG_PTP; in i40e_ptp_init()
1497 dev_info(&pf->pdev->dev, "%s: PTP not supported on %s\n", in i40e_ptp_init()
1499 netdev->name); in i40e_ptp_init()
1503 mutex_init(&pf->tmreg_lock); in i40e_ptp_init()
1504 spin_lock_init(&pf->ptp_rx_lock); in i40e_ptp_init()
1509 pf->ptp_clock = NULL; in i40e_ptp_init()
1510 dev_err(&pf->pdev->dev, "%s: ptp_clock_register failed\n", in i40e_ptp_init()
1512 } else if (pf->ptp_clock) { in i40e_ptp_init()
1515 if (pf->hw.debug_mask & I40E_DEBUG_LAN) in i40e_ptp_init()
1516 dev_info(&pf->pdev->dev, "PHC enabled\n"); in i40e_ptp_init()
1517 pf->flags |= I40E_FLAG_PTP; in i40e_ptp_init()
1531 i40e_ptp_set_timestamp_mode(pf, &pf->tstamp_config); in i40e_ptp_init()
1541 * i40e_ptp_stop - Disable the driver/hardware support and unregister the PHC
1549 struct i40e_hw *hw = &pf->hw; in i40e_ptp_stop()
1552 pf->flags &= ~I40E_FLAG_PTP; in i40e_ptp_stop()
1553 pf->ptp_tx = false; in i40e_ptp_stop()
1554 pf->ptp_rx = false; in i40e_ptp_stop()
1556 if (pf->ptp_tx_skb) { in i40e_ptp_stop()
1557 struct sk_buff *skb = pf->ptp_tx_skb; in i40e_ptp_stop()
1559 pf->ptp_tx_skb = NULL; in i40e_ptp_stop()
1560 clear_bit_unlock(__I40E_PTP_TX_IN_PROGRESS, pf->state); in i40e_ptp_stop()
1564 if (pf->ptp_clock) { in i40e_ptp_stop()
1565 ptp_clock_unregister(pf->ptp_clock); in i40e_ptp_stop()
1566 pf->ptp_clock = NULL; in i40e_ptp_stop()
1567 dev_info(&pf->pdev->dev, "%s: removed PHC on %s\n", __func__, in i40e_ptp_stop()
1568 pf->vsi[pf->lan_vsi]->netdev->name); in i40e_ptp_stop()
1571 if (i40e_is_ptp_pin_dev(&pf->hw)) { in i40e_ptp_stop()