Lines Matching +full:low +full:- +full:to +full:- +full:high
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
5 #include <linux/posix-clock.h>
9 /* The XL710 timesync is very much like Intel's 82599 design when it comes to
39 CANT_DO_PINS = -1,
52 end = -2,
66 led_end = -2,
67 low = 0, enumerator
68 high, enumerator
83 {off, off, off, high, high, high, high},
84 {off, in_A, off, high, high, high, low},
85 {off, out_A, off, high, low, high, high},
86 {off, in_B, off, high, high, high, low},
87 {off, out_B, off, high, low, high, high},
88 {in_A, off, off, high, high, high, low},
89 {in_A, in_B, off, high, high, high, low},
90 {in_A, out_B, off, high, low, high, high},
91 {out_A, off, off, high, low, high, high},
92 {out_A, in_B, off, high, low, high, high},
93 {in_B, off, off, high, high, high, low},
94 {in_B, in_A, off, high, high, high, low},
95 {in_B, out_A, off, high, low, high, high},
96 {out_B, off, off, high, low, high, high},
97 {out_B, in_A, off, high, low, high, high},
98 {off, off, in_A, high, high, low, high},
99 {off, out_A, in_A, high, low, low, high},
100 {off, in_B, in_A, high, high, low, low},
101 {off, out_B, in_A, high, low, low, high},
102 {out_A, off, in_A, high, low, low, high},
103 {out_A, in_B, in_A, high, low, low, high},
104 {in_B, off, in_A, high, high, low, low},
105 {in_B, out_A, in_A, high, low, low, high},
106 {out_B, off, in_A, high, low, low, high},
107 {off, off, out_A, low, high, high, high},
108 {off, in_A, out_A, low, high, high, low},
109 {off, in_B, out_A, low, high, high, low},
110 {off, out_B, out_A, low, low, high, high},
111 {in_A, off, out_A, low, high, high, low},
112 {in_A, in_B, out_A, low, high, high, low},
113 {in_A, out_B, out_A, low, low, high, high},
114 {in_B, off, out_A, low, high, high, low},
115 {in_B, in_A, out_A, low, high, high, low},
116 {out_B, off, out_A, low, low, high, high},
117 {out_B, in_A, out_A, low, low, high, high},
118 {off, off, in_B, high, high, low, high},
119 {off, in_A, in_B, high, high, low, low},
120 {off, out_A, in_B, high, low, low, high},
121 {off, out_B, in_B, high, low, low, high},
122 {in_A, off, in_B, high, high, low, low},
123 {in_A, out_B, in_B, high, low, low, high},
124 {out_A, off, in_B, high, low, low, high},
125 {out_B, off, in_B, high, low, low, high},
126 {out_B, in_A, in_B, high, low, low, high},
127 {off, off, out_B, low, high, high, high},
128 {off, in_A, out_B, low, high, high, low},
129 {off, out_A, out_B, low, low, high, high},
130 {off, in_B, out_B, low, high, high, low},
131 {in_A, off, out_B, low, high, high, low},
132 {in_A, in_B, out_B, low, high, high, low},
133 {out_A, off, out_B, low, low, high, high},
134 {out_A, in_B, out_B, low, low, high, high},
135 {in_B, off, out_B, low, high, high, low},
136 {in_B, in_A, out_B, low, high, high, low},
137 {in_B, out_A, out_B, low, low, high, high},
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
177 * @hw: pointer to the hardware structure
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.
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()
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
266 return -EOPNOTSUPP; in i40e_ptp_verify()
272 * i40e_ptp_read - Read the PHC time from the device
274 * @ts: timespec structure to hold the current time value
275 * @sts: structure to hold the system time before and after reading the PHC
279 * convert the result to a timespec before we can return.
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()
313 /* The timer will not update until the high register is written, so in i40e_ptp_write()
314 * write the low register first. in i40e_ptp_write()
321 * i40e_ptp_convert_to_hwtstamp - Convert device clock to system time
322 * @hwtstamps: Timestamp structure to update
325 * We need to convert the NIC clock value into a hwtstamp which can be used by
326 * the upper level timestamping functions. Since the timestamp is simply a 64-
327 * bit nanosecond value, we can call ns_to_ktime directly to handle this.
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
372 struct i40e_hw *hw = &pf->hw; in i40e_ptp_set_1pps_signal_hw()
396 * i40e_ptp_adjtime - Adjust the PHC time
398 * @delta: Offset in nanoseconds to adjust the PHC time by
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
443 * @ts: timespec structure to hold the current time value
444 * @sts: structure to hold the system time before and after reading 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
466 * Set the device clock to the user input value. The conversion from timespec
467 * to ns happens in the write function.
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
505 * @func: function assigned to PIN
527 * i40e_ptp_enable_pin - enable PINs.
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()
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()
555 * because it tries to lock the pincfg_mux which is locked by 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()
574 return -EINVAL; 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
591 * @on: To turn feature on/off
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
628 * for noticed latch events. This allows the driver to keep track of the first
629 * time a latch event was noticed which will be used to help clear out Rx
633 * expected to be called only while under the ptp_rx_lock.
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()
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
668 * This watchdog task is scheduled to detect error case where hardware has
670 * particular error is rare but leaves the device in a state unable to timestamp
675 struct i40e_hw *hw = &pf->hw; 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()
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()
709 * check. We don't want to warn about all drops because it can occur in i40e_ptp_rx_hang()
711 * aren't listening to. However, administrator should know if this is 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
727 * This watchdog task is run periodically to make sure that we clear the Tx
736 if (!test_bit(I40E_FLAG_PTP_ENA, pf->flags) || !pf->ptp_tx) in i40e_ptp_tx_hang()
739 /* Nothing to do if we're not already waiting for a timestamp */ in i40e_ptp_tx_hang()
740 if (!test_bit(__I40E_PTP_TX_IN_PROGRESS, pf->state)) in i40e_ptp_tx_hang()
745 * within a second it is reasonable to assume that we never will. 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()
777 /* don't attempt to timestamp if we don't have an skb */ in i40e_ptp_tx_hwtstamp()
778 if (!pf->ptp_tx_skb) in i40e_ptp_tx_hwtstamp()
788 * and prior to notifying the stack via skb_tstamp_tx(). Otherwise in i40e_ptp_tx_hwtstamp()
789 * applications might wake up and attempt to request another transmit in i40e_ptp_tx_hwtstamp()
790 * timestamp prior to the bit lock being cleared. 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
803 * @skb: Particular skb to send timestamp with
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()
833 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hwtstamp()
837 /* Clear the latched event since we're about to read its register */ 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
855 * change. In order to keep the PRTTSYN_TIME registers in units of nanoseconds,
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
919 * Obtain the current hardware timestamping settigs as requested. To do this,
920 * keep a shadow copy of the timestamp settings rather than attempting to
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
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
951 * @hw: pointer to the hardware structure
987 * i40e_ptp_set_led_hw - Set HW GPIO led
988 * @hw: pointer to the hardware structure
999 case low: in i40e_ptp_set_led_hw()
1003 case high: in i40e_ptp_set_led_hw()
1014 * i40e_ptp_init_leds_hw - init LEDs
1015 * @hw: pointer to a hardware structure
1032 * i40e_ptp_set_pins_hw - Set HW GPIO pins
1039 const struct i40e_ptp_pins_settings *pins = pf->ptp_pins; in i40e_ptp_set_pins_hw()
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()
1057 "PTP configuration set to: SDP3_2: %s, SDP3_3: %s, GPIO_4: %s.\n", 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
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
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
1162 * Control hardware registers to enter the specific mode requested by the
1163 * user. Also used during reset path to ensure that timestamp settings are
1166 * Note: modifies config in place, and may update the requested mode to be
1172 struct i40e_hw *hw = &pf->hw; in i40e_ptp_set_timestamp_mode()
1175 /* Selects external trigger to cause event */ 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()
1204 /* We set the type to V1, but do not enable UDP packet in i40e_ptp_set_timestamp_mode()
1205 * recognition. In this way, we should be as close to 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()
1277 * timestamps by setting to V1 only mode and clear the UDP in i40e_ptp_set_timestamp_mode()
1278 * recognition. This ought to disable all PTP Rx timestamps as V1 in i40e_ptp_set_timestamp_mode()
1279 * packets are always over UDP. Note that software is configured to in i40e_ptp_set_timestamp_mode()
1280 * ignore Rx timestamps via the pf->ptp_rx flag. in i40e_ptp_set_timestamp_mode()
1293 * i40e_ptp_set_ts_config - ioctl interface to control the HW timestamping
1297 * Respond to the user filter requests and make the appropriate hardware
1299 * logic, so keep track in software of whether to indicate these timestamps
1302 * It is permissible to "upgrade" the user request to a broader filter, as long
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.
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
1372 * don't already have one, so it is safe to call. Will return error if it
1374 * by i40e_ptp_init to create clock initially, and prevent global resets from
1379 /* no need to create a clock device if we already have one */ in i40e_ptp_create_clock()
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()
1398 /* Attempt to register the clock before enabling the hardware. */ 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()
1410 /* Set the previous "reset" time to the current Kernel clock time */ 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
1422 * be called at the end of preparing to reset, just before hardware reset
1423 * occurs, in order to preserve the PTP time as close as possible across
1428 /* don't try to access the PTP clock if it's not enabled */ in i40e_ptp_save_hw_time()
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,
1444 * CLOCK_MONOTONIC (via ktime_get()) to calculate the time difference.
1446 * This ensures that the hardware clock is restored to nearly what it should
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
1470 * expected that this timespec will be set to the last known PTP clock time,
1471 * in order to preserve the clock time as close as possible across a reset.
1476 struct net_device *netdev = vsi->netdev; in i40e_ptp_init()
1477 struct i40e_hw *hw = &pf->hw; in i40e_ptp_init()
1481 /* Only one PF is assigned to control 1588 logic per port. Do not 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()