1ae06c70bSJeff Kirsher // SPDX-License-Identifier: GPL-2.0
251dce24bSJeff Kirsher /* Copyright(c) 1999 - 2018 Intel Corporation. */
3d89777bfSBruce Allan 
4d89777bfSBruce Allan /* PTP 1588 Hardware Clock (PHC)
5d89777bfSBruce Allan  * Derived from PTP Hardware Clock driver for Intel 82576 and 82580 (igb)
6d89777bfSBruce Allan  * Copyright (C) 2011 Richard Cochran <richardcochran@gmail.com>
7d89777bfSBruce Allan  */
8d89777bfSBruce Allan 
9d89777bfSBruce Allan #include "e1000.h"
10d89777bfSBruce Allan 
1101d7ada5SChristopher S. Hall #ifdef CONFIG_E1000E_HWTS
1201d7ada5SChristopher S. Hall #include <linux/clocksource.h>
1301d7ada5SChristopher S. Hall #include <linux/ktime.h>
1401d7ada5SChristopher S. Hall #include <asm/tsc.h>
1501d7ada5SChristopher S. Hall #endif
1601d7ada5SChristopher S. Hall 
17d89777bfSBruce Allan /**
18abab010fSJacob Keller  * e1000e_phc_adjfine - adjust the frequency of the hardware clock
19d89777bfSBruce Allan  * @ptp: ptp clock structure
20abab010fSJacob Keller  * @delta: Desired frequency chance in scaled parts per million
21d89777bfSBruce Allan  *
22d89777bfSBruce Allan  * Adjust the frequency of the PHC cycle counter by the indicated delta from
23d89777bfSBruce Allan  * the base frequency.
24abab010fSJacob Keller  *
25abab010fSJacob Keller  * Scaled parts per million is ppm but with a 16 bit binary fractional field.
26d89777bfSBruce Allan  **/
e1000e_phc_adjfine(struct ptp_clock_info * ptp,long delta)27abab010fSJacob Keller static int e1000e_phc_adjfine(struct ptp_clock_info *ptp, long delta)
28d89777bfSBruce Allan {
29d89777bfSBruce Allan 	struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter,
30d89777bfSBruce Allan 						     ptp_clock_info);
31d89777bfSBruce Allan 	struct e1000_hw *hw = &adapter->hw;
326c2ed39cSTodd Fujinaka 	unsigned long flags;
331060707eSJacob Keller 	u64 incvalue;
341060707eSJacob Keller 	u32 timinca;
35d89777bfSBruce Allan 	s32 ret_val;
36d89777bfSBruce Allan 
37d89777bfSBruce Allan 	/* Get the System Time Register SYSTIM base frequency */
38d89777bfSBruce Allan 	ret_val = e1000e_get_base_timinca(adapter, &timinca);
39d89777bfSBruce Allan 	if (ret_val)
40d89777bfSBruce Allan 		return ret_val;
41d89777bfSBruce Allan 
426c2ed39cSTodd Fujinaka 	spin_lock_irqsave(&adapter->systim_lock, flags);
436c2ed39cSTodd Fujinaka 
44d89777bfSBruce Allan 	incvalue = timinca & E1000_TIMINCA_INCVALUE_MASK;
451060707eSJacob Keller 	incvalue = adjust_by_scaled_ppm(incvalue, delta);
46d89777bfSBruce Allan 
47d89777bfSBruce Allan 	timinca &= ~E1000_TIMINCA_INCVALUE_MASK;
48d89777bfSBruce Allan 	timinca |= incvalue;
49d89777bfSBruce Allan 
50d89777bfSBruce Allan 	ew32(TIMINCA, timinca);
51d89777bfSBruce Allan 
52aa524b66SJacob Keller 	adapter->ptp_delta = delta;
53aa524b66SJacob Keller 
546c2ed39cSTodd Fujinaka 	spin_unlock_irqrestore(&adapter->systim_lock, flags);
556c2ed39cSTodd Fujinaka 
56d89777bfSBruce Allan 	return 0;
57d89777bfSBruce Allan }
58d89777bfSBruce Allan 
59d89777bfSBruce Allan /**
60d89777bfSBruce Allan  * e1000e_phc_adjtime - Shift the time of the hardware clock
61d89777bfSBruce Allan  * @ptp: ptp clock structure
62d89777bfSBruce Allan  * @delta: Desired change in nanoseconds
63d89777bfSBruce Allan  *
64d89777bfSBruce Allan  * Adjust the timer by resetting the timecounter structure.
65d89777bfSBruce Allan  **/
e1000e_phc_adjtime(struct ptp_clock_info * ptp,s64 delta)66d89777bfSBruce Allan static int e1000e_phc_adjtime(struct ptp_clock_info *ptp, s64 delta)
67d89777bfSBruce Allan {
68d89777bfSBruce Allan 	struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter,
69d89777bfSBruce Allan 						     ptp_clock_info);
70d89777bfSBruce Allan 	unsigned long flags;
71d89777bfSBruce Allan 
72d89777bfSBruce Allan 	spin_lock_irqsave(&adapter->systim_lock, flags);
73f4de2b95SRichard Cochran 	timecounter_adjtime(&adapter->tc, delta);
74d89777bfSBruce Allan 	spin_unlock_irqrestore(&adapter->systim_lock, flags);
75d89777bfSBruce Allan 
76d89777bfSBruce Allan 	return 0;
77d89777bfSBruce Allan }
78d89777bfSBruce Allan 
7901d7ada5SChristopher S. Hall #ifdef CONFIG_E1000E_HWTS
8001d7ada5SChristopher S. Hall #define MAX_HW_WAIT_COUNT (3)
8101d7ada5SChristopher S. Hall 
8201d7ada5SChristopher S. Hall /**
8301d7ada5SChristopher S. Hall  * e1000e_phc_get_syncdevicetime - Callback given to timekeeping code reads system/device registers
8401d7ada5SChristopher S. Hall  * @device: current device time
8501d7ada5SChristopher S. Hall  * @system: system counter value read synchronously with device time
8601d7ada5SChristopher S. Hall  * @ctx: context provided by timekeeping code
8701d7ada5SChristopher S. Hall  *
8801d7ada5SChristopher S. Hall  * Read device and system (ART) clock simultaneously and return the corrected
8901d7ada5SChristopher S. Hall  * clock values in ns.
9001d7ada5SChristopher S. Hall  **/
e1000e_phc_get_syncdevicetime(ktime_t * device,struct system_counterval_t * system,void * ctx)9101d7ada5SChristopher S. Hall static int e1000e_phc_get_syncdevicetime(ktime_t *device,
9201d7ada5SChristopher S. Hall 					 struct system_counterval_t *system,
9301d7ada5SChristopher S. Hall 					 void *ctx)
9401d7ada5SChristopher S. Hall {
9501d7ada5SChristopher S. Hall 	struct e1000_adapter *adapter = (struct e1000_adapter *)ctx;
9601d7ada5SChristopher S. Hall 	struct e1000_hw *hw = &adapter->hw;
9701d7ada5SChristopher S. Hall 	unsigned long flags;
9801d7ada5SChristopher S. Hall 	int i;
9901d7ada5SChristopher S. Hall 	u32 tsync_ctrl;
100a5a1d1c2SThomas Gleixner 	u64 dev_cycles;
101a5a1d1c2SThomas Gleixner 	u64 sys_cycles;
10201d7ada5SChristopher S. Hall 
10301d7ada5SChristopher S. Hall 	tsync_ctrl = er32(TSYNCTXCTL);
10401d7ada5SChristopher S. Hall 	tsync_ctrl |= E1000_TSYNCTXCTL_START_SYNC |
10501d7ada5SChristopher S. Hall 		E1000_TSYNCTXCTL_MAX_ALLOWED_DLY_MASK;
10601d7ada5SChristopher S. Hall 	ew32(TSYNCTXCTL, tsync_ctrl);
10701d7ada5SChristopher S. Hall 	for (i = 0; i < MAX_HW_WAIT_COUNT; ++i) {
10801d7ada5SChristopher S. Hall 		udelay(1);
10901d7ada5SChristopher S. Hall 		tsync_ctrl = er32(TSYNCTXCTL);
11001d7ada5SChristopher S. Hall 		if (tsync_ctrl & E1000_TSYNCTXCTL_SYNC_COMP)
11101d7ada5SChristopher S. Hall 			break;
11201d7ada5SChristopher S. Hall 	}
11301d7ada5SChristopher S. Hall 
11401d7ada5SChristopher S. Hall 	if (i == MAX_HW_WAIT_COUNT)
11501d7ada5SChristopher S. Hall 		return -ETIMEDOUT;
11601d7ada5SChristopher S. Hall 
11701d7ada5SChristopher S. Hall 	dev_cycles = er32(SYSSTMPH);
11801d7ada5SChristopher S. Hall 	dev_cycles <<= 32;
11901d7ada5SChristopher S. Hall 	dev_cycles |= er32(SYSSTMPL);
12001d7ada5SChristopher S. Hall 	spin_lock_irqsave(&adapter->systim_lock, flags);
12101d7ada5SChristopher S. Hall 	*device = ns_to_ktime(timecounter_cyc2time(&adapter->tc, dev_cycles));
12201d7ada5SChristopher S. Hall 	spin_unlock_irqrestore(&adapter->systim_lock, flags);
12301d7ada5SChristopher S. Hall 
12401d7ada5SChristopher S. Hall 	sys_cycles = er32(PLTSTMPH);
12501d7ada5SChristopher S. Hall 	sys_cycles <<= 32;
12601d7ada5SChristopher S. Hall 	sys_cycles |= er32(PLTSTMPL);
12701d7ada5SChristopher S. Hall 	*system = convert_art_to_tsc(sys_cycles);
12801d7ada5SChristopher S. Hall 
12901d7ada5SChristopher S. Hall 	return 0;
13001d7ada5SChristopher S. Hall }
13101d7ada5SChristopher S. Hall 
13201d7ada5SChristopher S. Hall /**
13339da2cacSSasha Neftin  * e1000e_phc_getcrosststamp - Reads the current system/device cross timestamp
13401d7ada5SChristopher S. Hall  * @ptp: ptp clock structure
135b50f7bcaSJesse Brandeburg  * @xtstamp: structure containing timestamp
13601d7ada5SChristopher S. Hall  *
13701d7ada5SChristopher S. Hall  * Read device and system (ART) clock simultaneously and return the scaled
13801d7ada5SChristopher S. Hall  * clock values in ns.
13901d7ada5SChristopher S. Hall  **/
e1000e_phc_getcrosststamp(struct ptp_clock_info * ptp,struct system_device_crosststamp * xtstamp)14001d7ada5SChristopher S. Hall static int e1000e_phc_getcrosststamp(struct ptp_clock_info *ptp,
14101d7ada5SChristopher S. Hall 				     struct system_device_crosststamp *xtstamp)
14201d7ada5SChristopher S. Hall {
14301d7ada5SChristopher S. Hall 	struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter,
14401d7ada5SChristopher S. Hall 						     ptp_clock_info);
14501d7ada5SChristopher S. Hall 
14601d7ada5SChristopher S. Hall 	return get_device_system_crosststamp(e1000e_phc_get_syncdevicetime,
14701d7ada5SChristopher S. Hall 						adapter, NULL, xtstamp);
14801d7ada5SChristopher S. Hall }
14901d7ada5SChristopher S. Hall #endif/*CONFIG_E1000E_HWTS*/
15001d7ada5SChristopher S. Hall 
151d89777bfSBruce Allan /**
15298942d70SMiroslav Lichvar  * e1000e_phc_gettimex - Reads the current time from the hardware clock and
15398942d70SMiroslav Lichvar  *                       system clock
154d89777bfSBruce Allan  * @ptp: ptp clock structure
15598942d70SMiroslav Lichvar  * @ts: timespec structure to hold the current PHC time
15698942d70SMiroslav Lichvar  * @sts: structure to hold the current system time
157d89777bfSBruce Allan  *
158d89777bfSBruce Allan  * Read the timecounter and return the correct value in ns after converting
159d89777bfSBruce Allan  * it into a struct timespec.
160d89777bfSBruce Allan  **/
e1000e_phc_gettimex(struct ptp_clock_info * ptp,struct timespec64 * ts,struct ptp_system_timestamp * sts)16198942d70SMiroslav Lichvar static int e1000e_phc_gettimex(struct ptp_clock_info *ptp,
16298942d70SMiroslav Lichvar 			       struct timespec64 *ts,
16398942d70SMiroslav Lichvar 			       struct ptp_system_timestamp *sts)
164d89777bfSBruce Allan {
165d89777bfSBruce Allan 	struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter,
166d89777bfSBruce Allan 						     ptp_clock_info);
167d89777bfSBruce Allan 	unsigned long flags;
168e1f65b0dSMiroslav Lichvar 	u64 cycles, ns;
169d89777bfSBruce Allan 
170d89777bfSBruce Allan 	spin_lock_irqsave(&adapter->systim_lock, flags);
171e1f65b0dSMiroslav Lichvar 
17298942d70SMiroslav Lichvar 	/* NOTE: Non-monotonic SYSTIM readings may be returned */
17398942d70SMiroslav Lichvar 	cycles = e1000e_read_systim(adapter, sts);
174e1f65b0dSMiroslav Lichvar 	ns = timecounter_cyc2time(&adapter->tc, cycles);
175e1f65b0dSMiroslav Lichvar 
176d89777bfSBruce Allan 	spin_unlock_irqrestore(&adapter->systim_lock, flags);
177d89777bfSBruce Allan 
178bdf36d94SRichard Cochran 	*ts = ns_to_timespec64(ns);
179d89777bfSBruce Allan 
180d89777bfSBruce Allan 	return 0;
181d89777bfSBruce Allan }
182d89777bfSBruce Allan 
183d89777bfSBruce Allan /**
184d89777bfSBruce Allan  * e1000e_phc_settime - Set the current time on the hardware clock
185d89777bfSBruce Allan  * @ptp: ptp clock structure
186d89777bfSBruce Allan  * @ts: timespec containing the new time for the cycle counter
187d89777bfSBruce Allan  *
188d89777bfSBruce Allan  * Reset the timecounter to use a new base value instead of the kernel
189d89777bfSBruce Allan  * wall timer value.
190d89777bfSBruce Allan  **/
e1000e_phc_settime(struct ptp_clock_info * ptp,const struct timespec64 * ts)191d89777bfSBruce Allan static int e1000e_phc_settime(struct ptp_clock_info *ptp,
19207c74eb7SRichard Cochran 			      const struct timespec64 *ts)
193d89777bfSBruce Allan {
194d89777bfSBruce Allan 	struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter,
195d89777bfSBruce Allan 						     ptp_clock_info);
196d89777bfSBruce Allan 	unsigned long flags;
197d89777bfSBruce Allan 	u64 ns;
198d89777bfSBruce Allan 
19907c74eb7SRichard Cochran 	ns = timespec64_to_ns(ts);
200d89777bfSBruce Allan 
201d89777bfSBruce Allan 	/* reset the timecounter */
202d89777bfSBruce Allan 	spin_lock_irqsave(&adapter->systim_lock, flags);
203d89777bfSBruce Allan 	timecounter_init(&adapter->tc, &adapter->cc, ns);
204d89777bfSBruce Allan 	spin_unlock_irqrestore(&adapter->systim_lock, flags);
205d89777bfSBruce Allan 
206d89777bfSBruce Allan 	return 0;
207d89777bfSBruce Allan }
208d89777bfSBruce Allan 
209d89777bfSBruce Allan /**
210d89777bfSBruce Allan  * e1000e_phc_enable - enable or disable an ancillary feature
211d89777bfSBruce Allan  * @ptp: ptp clock structure
212d89777bfSBruce Allan  * @request: Desired resource to enable or disable
213d89777bfSBruce Allan  * @on: Caller passes one to enable or zero to disable
214d89777bfSBruce Allan  *
215d89777bfSBruce Allan  * Enable (or disable) ancillary features of the PHC subsystem.
216d89777bfSBruce Allan  * Currently, no ancillary features are supported.
217d89777bfSBruce Allan  **/
e1000e_phc_enable(struct ptp_clock_info __always_unused * ptp,struct ptp_clock_request __always_unused * request,int __always_unused on)2188bb62869SBruce Allan static int e1000e_phc_enable(struct ptp_clock_info __always_unused *ptp,
2198bb62869SBruce Allan 			     struct ptp_clock_request __always_unused *request,
2208bb62869SBruce Allan 			     int __always_unused on)
221d89777bfSBruce Allan {
222d89777bfSBruce Allan 	return -EOPNOTSUPP;
223d89777bfSBruce Allan }
224d89777bfSBruce Allan 
e1000e_systim_overflow_work(struct work_struct * work)225d89777bfSBruce Allan static void e1000e_systim_overflow_work(struct work_struct *work)
226d89777bfSBruce Allan {
227d89777bfSBruce Allan 	struct e1000_adapter *adapter = container_of(work, struct e1000_adapter,
228d89777bfSBruce Allan 						     systim_overflow_work.work);
229d89777bfSBruce Allan 	struct e1000_hw *hw = &adapter->hw;
23007c74eb7SRichard Cochran 	struct timespec64 ts;
231e1f65b0dSMiroslav Lichvar 	u64 ns;
232d89777bfSBruce Allan 
233e1f65b0dSMiroslav Lichvar 	/* Update the timecounter */
234e1f65b0dSMiroslav Lichvar 	ns = timecounter_read(&adapter->tc);
235d89777bfSBruce Allan 
236e1f65b0dSMiroslav Lichvar 	ts = ns_to_timespec64(ns);
23732eaf120SDavid S. Miller 	e_dbg("SYSTIM overflow check at %lld.%09lu\n",
23832eaf120SDavid S. Miller 	      (long long) ts.tv_sec, ts.tv_nsec);
239d89777bfSBruce Allan 
240d89777bfSBruce Allan 	schedule_delayed_work(&adapter->systim_overflow_work,
241d89777bfSBruce Allan 			      E1000_SYSTIM_OVERFLOW_PERIOD);
242d89777bfSBruce Allan }
243d89777bfSBruce Allan 
244d89777bfSBruce Allan static const struct ptp_clock_info e1000e_ptp_clock_info = {
245d89777bfSBruce Allan 	.owner		= THIS_MODULE,
246d89777bfSBruce Allan 	.n_alarm	= 0,
247d89777bfSBruce Allan 	.n_ext_ts	= 0,
248d89777bfSBruce Allan 	.n_per_out	= 0,
2494986b4f0SRichard Cochran 	.n_pins		= 0,
250d89777bfSBruce Allan 	.pps		= 0,
251abab010fSJacob Keller 	.adjfine	= e1000e_phc_adjfine,
252d89777bfSBruce Allan 	.adjtime	= e1000e_phc_adjtime,
25398942d70SMiroslav Lichvar 	.gettimex64	= e1000e_phc_gettimex,
25407c74eb7SRichard Cochran 	.settime64	= e1000e_phc_settime,
255d89777bfSBruce Allan 	.enable		= e1000e_phc_enable,
256d89777bfSBruce Allan };
257d89777bfSBruce Allan 
258d89777bfSBruce Allan /**
259d89777bfSBruce Allan  * e1000e_ptp_init - initialize PTP for devices which support it
260d89777bfSBruce Allan  * @adapter: board private structure
261d89777bfSBruce Allan  *
262d89777bfSBruce Allan  * This function performs the required steps for enabling PTP support.
263d89777bfSBruce Allan  * If PTP support has already been loaded it simply calls the cyclecounter
264d89777bfSBruce Allan  * init routine and exits.
265d89777bfSBruce Allan  **/
e1000e_ptp_init(struct e1000_adapter * adapter)266d89777bfSBruce Allan void e1000e_ptp_init(struct e1000_adapter *adapter)
267d89777bfSBruce Allan {
268d89777bfSBruce Allan 	struct e1000_hw *hw = &adapter->hw;
269d89777bfSBruce Allan 
270d89777bfSBruce Allan 	adapter->ptp_clock = NULL;
271d89777bfSBruce Allan 
272d89777bfSBruce Allan 	if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
273d89777bfSBruce Allan 		return;
274d89777bfSBruce Allan 
275d89777bfSBruce Allan 	adapter->ptp_clock_info = e1000e_ptp_clock_info;
276d89777bfSBruce Allan 
277d89777bfSBruce Allan 	snprintf(adapter->ptp_clock_info.name,
278d89777bfSBruce Allan 		 sizeof(adapter->ptp_clock_info.name), "%pm",
279d89777bfSBruce Allan 		 adapter->netdev->perm_addr);
280d89777bfSBruce Allan 
281d89777bfSBruce Allan 	switch (hw->mac.type) {
282d89777bfSBruce Allan 	case e1000_pch2lan:
283*e9ad7a80SJacob Keller 		adapter->ptp_clock_info.max_adj = MAX_PPB_96MHZ;
284*e9ad7a80SJacob Keller 		break;
285d89777bfSBruce Allan 	case e1000_pch_lpt:
286*e9ad7a80SJacob Keller 		if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)
287*e9ad7a80SJacob Keller 			adapter->ptp_clock_info.max_adj = MAX_PPB_96MHZ;
288*e9ad7a80SJacob Keller 		else
289*e9ad7a80SJacob Keller 			adapter->ptp_clock_info.max_adj = MAX_PPB_25MHZ;
290*e9ad7a80SJacob Keller 		break;
29179849ebcSDavid Ertman 	case e1000_pch_spt:
292*e9ad7a80SJacob Keller 		adapter->ptp_clock_info.max_adj = MAX_PPB_24MHZ;
293*e9ad7a80SJacob Keller 		break;
294c8744f44SSasha Neftin 	case e1000_pch_cnp:
295fb776f5dSSasha Neftin 	case e1000_pch_tgp:
29659e46688SSasha Neftin 	case e1000_pch_adp:
297cc23f4f0SSasha Neftin 	case e1000_pch_mtp:
298820b8ff6SSasha Neftin 	case e1000_pch_lnp:
2990c9183ceSSasha Neftin 	case e1000_pch_ptp:
3001fe4f45eSSasha Neftin 	case e1000_pch_nvp:
301*e9ad7a80SJacob Keller 		if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI)
302*e9ad7a80SJacob Keller 			adapter->ptp_clock_info.max_adj = MAX_PPB_24MHZ;
303*e9ad7a80SJacob Keller 		else
304*e9ad7a80SJacob Keller 			adapter->ptp_clock_info.max_adj = MAX_PPB_38400KHZ;
305d89777bfSBruce Allan 		break;
306d89777bfSBruce Allan 	case e1000_82574:
307d89777bfSBruce Allan 	case e1000_82583:
308*e9ad7a80SJacob Keller 		adapter->ptp_clock_info.max_adj = MAX_PPB_25MHZ;
309d89777bfSBruce Allan 		break;
310d89777bfSBruce Allan 	default:
311d89777bfSBruce Allan 		break;
312d89777bfSBruce Allan 	}
313d89777bfSBruce Allan 
31401d7ada5SChristopher S. Hall #ifdef CONFIG_E1000E_HWTS
31501d7ada5SChristopher S. Hall 	/* CPU must have ART and GBe must be from Sunrise Point or greater */
31601d7ada5SChristopher S. Hall 	if (hw->mac.type >= e1000_pch_spt && boot_cpu_has(X86_FEATURE_ART))
31701d7ada5SChristopher S. Hall 		adapter->ptp_clock_info.getcrosststamp =
31801d7ada5SChristopher S. Hall 			e1000e_phc_getcrosststamp;
31901d7ada5SChristopher S. Hall #endif/*CONFIG_E1000E_HWTS*/
32001d7ada5SChristopher S. Hall 
321d89777bfSBruce Allan 	INIT_DELAYED_WORK(&adapter->systim_overflow_work,
322d89777bfSBruce Allan 			  e1000e_systim_overflow_work);
323d89777bfSBruce Allan 
324d89777bfSBruce Allan 	schedule_delayed_work(&adapter->systim_overflow_work,
325d89777bfSBruce Allan 			      E1000_SYSTIM_OVERFLOW_PERIOD);
326d89777bfSBruce Allan 
327d89777bfSBruce Allan 	adapter->ptp_clock = ptp_clock_register(&adapter->ptp_clock_info,
328d89777bfSBruce Allan 						&adapter->pdev->dev);
329d89777bfSBruce Allan 	if (IS_ERR(adapter->ptp_clock)) {
330d89777bfSBruce Allan 		adapter->ptp_clock = NULL;
331d89777bfSBruce Allan 		e_err("ptp_clock_register failed\n");
332efee95f4SNicolas Pitre 	} else if (adapter->ptp_clock) {
333d89777bfSBruce Allan 		e_info("registered PHC clock\n");
334d89777bfSBruce Allan 	}
335d89777bfSBruce Allan }
336d89777bfSBruce Allan 
337d89777bfSBruce Allan /**
338d89777bfSBruce Allan  * e1000e_ptp_remove - disable PTP device and stop the overflow check
339d89777bfSBruce Allan  * @adapter: board private structure
340d89777bfSBruce Allan  *
341d89777bfSBruce Allan  * Stop the PTP support, and cancel the delayed work.
342d89777bfSBruce Allan  **/
e1000e_ptp_remove(struct e1000_adapter * adapter)343d89777bfSBruce Allan void e1000e_ptp_remove(struct e1000_adapter *adapter)
344d89777bfSBruce Allan {
345d89777bfSBruce Allan 	if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
346d89777bfSBruce Allan 		return;
347d89777bfSBruce Allan 
348d89777bfSBruce Allan 	cancel_delayed_work_sync(&adapter->systim_overflow_work);
349d89777bfSBruce Allan 
350d89777bfSBruce Allan 	if (adapter->ptp_clock) {
351d89777bfSBruce Allan 		ptp_clock_unregister(adapter->ptp_clock);
352d89777bfSBruce Allan 		adapter->ptp_clock = NULL;
353d89777bfSBruce Allan 		e_info("removed PHC\n");
354d89777bfSBruce Allan 	}
355d89777bfSBruce Allan }
356