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()
133 * e1000e_phc_getcrosststamp - Reads the current system/device cross timestamp
134 * @ptp: ptp clock structure
140 static int e1000e_phc_getcrosststamp(struct ptp_clock_info *ptp, in e1000e_phc_getcrosststamp() argument
143 struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter, in e1000e_phc_getcrosststamp()
152 * e1000e_phc_gettimex - Reads the current time from the hardware clock and
154 * @ptp: ptp clock structure
161 static int e1000e_phc_gettimex(struct ptp_clock_info *ptp, in e1000e_phc_gettimex() argument
165 struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter, in e1000e_phc_gettimex()
170 spin_lock_irqsave(&adapter->systim_lock, flags); in e1000e_phc_gettimex()
172 /* NOTE: Non-monotonic SYSTIM readings may be returned */ in e1000e_phc_gettimex()
174 ns = timecounter_cyc2time(&adapter->tc, cycles); in e1000e_phc_gettimex()
176 spin_unlock_irqrestore(&adapter->systim_lock, flags); in e1000e_phc_gettimex()
184 * e1000e_phc_settime - Set the current time on the hardware clock
185 * @ptp: ptp clock structure
189 * wall timer value.
191 static int e1000e_phc_settime(struct ptp_clock_info *ptp, in e1000e_phc_settime() argument
194 struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter, in e1000e_phc_settime()
202 spin_lock_irqsave(&adapter->systim_lock, flags); in e1000e_phc_settime()
203 timecounter_init(&adapter->tc, &adapter->cc, ns); in e1000e_phc_settime()
204 spin_unlock_irqrestore(&adapter->systim_lock, flags); in e1000e_phc_settime()
210 * e1000e_phc_enable - enable or disable an ancillary feature
211 * @ptp: ptp clock structure
218 static int e1000e_phc_enable(struct ptp_clock_info __always_unused *ptp, in e1000e_phc_enable() argument
222 return -EOPNOTSUPP; in e1000e_phc_enable()
229 struct e1000_hw *hw = &adapter->hw; in e1000e_systim_overflow_work()
234 ns = timecounter_read(&adapter->tc); in e1000e_systim_overflow_work()
240 schedule_delayed_work(&adapter->systim_overflow_work, in e1000e_systim_overflow_work()
259 * e1000e_ptp_init - initialize PTP for devices which support it
262 * This function performs the required steps for enabling PTP support.
263 * If PTP support has already been loaded it simply calls the cyclecounter
268 struct e1000_hw *hw = &adapter->hw; in e1000e_ptp_init()
270 adapter->ptp_clock = NULL; in e1000e_ptp_init()
272 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) in e1000e_ptp_init()
275 adapter->ptp_clock_info = e1000e_ptp_clock_info; in e1000e_ptp_init()
277 snprintf(adapter->ptp_clock_info.name, in e1000e_ptp_init()
278 sizeof(adapter->ptp_clock_info.name), "%pm", in e1000e_ptp_init()
279 adapter->netdev->perm_addr); in e1000e_ptp_init()
281 switch (hw->mac.type) { in e1000e_ptp_init()
283 adapter->ptp_clock_info.max_adj = MAX_PPB_96MHZ; in e1000e_ptp_init()
287 adapter->ptp_clock_info.max_adj = MAX_PPB_96MHZ; in e1000e_ptp_init()
289 adapter->ptp_clock_info.max_adj = MAX_PPB_25MHZ; in e1000e_ptp_init()
292 adapter->ptp_clock_info.max_adj = MAX_PPB_24MHZ; in e1000e_ptp_init()
302 adapter->ptp_clock_info.max_adj = MAX_PPB_24MHZ; in e1000e_ptp_init()
304 adapter->ptp_clock_info.max_adj = MAX_PPB_38400KHZ; in e1000e_ptp_init()
308 adapter->ptp_clock_info.max_adj = MAX_PPB_25MHZ; in e1000e_ptp_init()
316 if (hw->mac.type >= e1000_pch_spt && boot_cpu_has(X86_FEATURE_ART)) in e1000e_ptp_init()
317 adapter->ptp_clock_info.getcrosststamp = in e1000e_ptp_init()
321 INIT_DELAYED_WORK(&adapter->systim_overflow_work, in e1000e_ptp_init()
324 schedule_delayed_work(&adapter->systim_overflow_work, in e1000e_ptp_init()
327 adapter->ptp_clock = ptp_clock_register(&adapter->ptp_clock_info, in e1000e_ptp_init()
328 &adapter->pdev->dev); in e1000e_ptp_init()
329 if (IS_ERR(adapter->ptp_clock)) { in e1000e_ptp_init()
330 adapter->ptp_clock = NULL; in e1000e_ptp_init()
332 } else if (adapter->ptp_clock) { in e1000e_ptp_init()
338 * e1000e_ptp_remove - disable PTP device and stop the overflow check
341 * Stop the PTP support, and cancel the delayed work.
345 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) in e1000e_ptp_remove()
348 cancel_delayed_work_sync(&adapter->systim_overflow_work); in e1000e_ptp_remove()
350 if (adapter->ptp_clock) { in e1000e_ptp_remove()
351 ptp_clock_unregister(adapter->ptp_clock); in e1000e_ptp_remove()
352 adapter->ptp_clock = NULL; in e1000e_ptp_remove()