Lines Matching +full:ptp +full:- +full:timer

1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 1999 - 2018 Intel Corporation. */
4 /* PTP 1588 Hardware Clock (PHC)
5 * Derived from PTP Hardware Clock driver for Intel 82576 and 82580 (igb)
18 * e1000e_phc_adjfine - adjust the frequency of the hardware clock
19 * @ptp: ptp clock structure
27 static int e1000e_phc_adjfine(struct ptp_clock_info *ptp, long delta) in e1000e_phc_adjfine() argument
29 struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter, in e1000e_phc_adjfine()
31 struct e1000_hw *hw = &adapter->hw; in e1000e_phc_adjfine()
42 spin_lock_irqsave(&adapter->systim_lock, flags); in e1000e_phc_adjfine()
52 adapter->ptp_delta = delta; in e1000e_phc_adjfine()
54 spin_unlock_irqrestore(&adapter->systim_lock, flags); in e1000e_phc_adjfine()
60 * e1000e_phc_adjtime - Shift the time of the hardware clock
61 * @ptp: ptp clock structure
64 * Adjust the timer by resetting the timecounter structure.
66 static int e1000e_phc_adjtime(struct ptp_clock_info *ptp, s64 delta) in e1000e_phc_adjtime() argument
68 struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter, in e1000e_phc_adjtime()
72 spin_lock_irqsave(&adapter->systim_lock, flags); in e1000e_phc_adjtime()
73 timecounter_adjtime(&adapter->tc, delta); in e1000e_phc_adjtime()
74 spin_unlock_irqrestore(&adapter->systim_lock, flags); in e1000e_phc_adjtime()
83 * e1000e_phc_get_syncdevicetime - Callback given to timekeeping code reads system/device registers
96 struct e1000_hw *hw = &adapter->hw; in e1000e_phc_get_syncdevicetime()
115 return -ETIMEDOUT; in e1000e_phc_get_syncdevicetime()
120 spin_lock_irqsave(&adapter->systim_lock, flags); in e1000e_phc_get_syncdevicetime()
121 *device = ns_to_ktime(timecounter_cyc2time(&adapter->tc, dev_cycles)); in e1000e_phc_get_syncdevicetime()
122 spin_unlock_irqrestore(&adapter->systim_lock, flags); in e1000e_phc_get_syncdevicetime()
127 system->cycles = sys_cycles; in e1000e_phc_get_syncdevicetime()
128 system->cs_id = CSID_X86_ART; in e1000e_phc_get_syncdevicetime()
134 * e1000e_phc_getcrosststamp - Reads the current system/device cross timestamp
135 * @ptp: ptp clock structure
141 static int e1000e_phc_getcrosststamp(struct ptp_clock_info *ptp, in e1000e_phc_getcrosststamp() argument
144 struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter, in e1000e_phc_getcrosststamp()
153 * e1000e_phc_gettimex - Reads the current time from the hardware clock and
155 * @ptp: ptp clock structure
162 static int e1000e_phc_gettimex(struct ptp_clock_info *ptp, in e1000e_phc_gettimex() argument
166 struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter, in e1000e_phc_gettimex()
171 spin_lock_irqsave(&adapter->systim_lock, flags); in e1000e_phc_gettimex()
173 /* NOTE: Non-monotonic SYSTIM readings may be returned */ in e1000e_phc_gettimex()
175 ns = timecounter_cyc2time(&adapter->tc, cycles); in e1000e_phc_gettimex()
177 spin_unlock_irqrestore(&adapter->systim_lock, flags); in e1000e_phc_gettimex()
185 * e1000e_phc_settime - Set the current time on the hardware clock
186 * @ptp: ptp clock structure
190 * wall timer value.
192 static int e1000e_phc_settime(struct ptp_clock_info *ptp, in e1000e_phc_settime() argument
195 struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter, in e1000e_phc_settime()
203 spin_lock_irqsave(&adapter->systim_lock, flags); in e1000e_phc_settime()
204 timecounter_init(&adapter->tc, &adapter->cc, ns); in e1000e_phc_settime()
205 spin_unlock_irqrestore(&adapter->systim_lock, flags); in e1000e_phc_settime()
211 * e1000e_phc_enable - enable or disable an ancillary feature
212 * @ptp: ptp clock structure
219 static int e1000e_phc_enable(struct ptp_clock_info __always_unused *ptp, in e1000e_phc_enable() argument
223 return -EOPNOTSUPP; in e1000e_phc_enable()
230 struct e1000_hw *hw = &adapter->hw; in e1000e_systim_overflow_work()
235 ns = timecounter_read(&adapter->tc); in e1000e_systim_overflow_work()
241 schedule_delayed_work(&adapter->systim_overflow_work, in e1000e_systim_overflow_work()
260 * e1000e_ptp_init - initialize PTP for devices which support it
263 * This function performs the required steps for enabling PTP support.
264 * If PTP support has already been loaded it simply calls the cyclecounter
269 struct e1000_hw *hw = &adapter->hw; in e1000e_ptp_init()
271 adapter->ptp_clock = NULL; in e1000e_ptp_init()
273 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) in e1000e_ptp_init()
276 adapter->ptp_clock_info = e1000e_ptp_clock_info; in e1000e_ptp_init()
278 snprintf(adapter->ptp_clock_info.name, in e1000e_ptp_init()
279 sizeof(adapter->ptp_clock_info.name), "%pm", in e1000e_ptp_init()
280 adapter->netdev->perm_addr); in e1000e_ptp_init()
282 switch (hw->mac.type) { in e1000e_ptp_init()
284 adapter->ptp_clock_info.max_adj = MAX_PPB_96MHZ; in e1000e_ptp_init()
288 adapter->ptp_clock_info.max_adj = MAX_PPB_96MHZ; in e1000e_ptp_init()
290 adapter->ptp_clock_info.max_adj = MAX_PPB_25MHZ; in e1000e_ptp_init()
293 adapter->ptp_clock_info.max_adj = MAX_PPB_24MHZ; in e1000e_ptp_init()
303 adapter->ptp_clock_info.max_adj = MAX_PPB_24MHZ; in e1000e_ptp_init()
305 adapter->ptp_clock_info.max_adj = MAX_PPB_38400KHZ; in e1000e_ptp_init()
309 adapter->ptp_clock_info.max_adj = MAX_PPB_25MHZ; in e1000e_ptp_init()
317 if (hw->mac.type >= e1000_pch_spt && boot_cpu_has(X86_FEATURE_ART)) in e1000e_ptp_init()
318 adapter->ptp_clock_info.getcrosststamp = in e1000e_ptp_init()
322 INIT_DELAYED_WORK(&adapter->systim_overflow_work, in e1000e_ptp_init()
325 schedule_delayed_work(&adapter->systim_overflow_work, in e1000e_ptp_init()
328 adapter->ptp_clock = ptp_clock_register(&adapter->ptp_clock_info, in e1000e_ptp_init()
329 &adapter->pdev->dev); in e1000e_ptp_init()
330 if (IS_ERR(adapter->ptp_clock)) { in e1000e_ptp_init()
331 adapter->ptp_clock = NULL; in e1000e_ptp_init()
333 } else if (adapter->ptp_clock) { in e1000e_ptp_init()
339 * e1000e_ptp_remove - disable PTP device and stop the overflow check
342 * Stop the PTP support, and cancel the delayed work.
346 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) in e1000e_ptp_remove()
349 cancel_delayed_work_sync(&adapter->systim_overflow_work); in e1000e_ptp_remove()
351 if (adapter->ptp_clock) { in e1000e_ptp_remove()
352 ptp_clock_unregister(adapter->ptp_clock); in e1000e_ptp_remove()
353 adapter->ptp_clock = NULL; in e1000e_ptp_remove()