1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2019 Intel Corporation */
3
4 #include "igc.h"
5
6 #include <linux/module.h>
7 #include <linux/device.h>
8 #include <linux/pci.h>
9 #include <linux/ptp_classify.h>
10 #include <linux/clocksource.h>
11 #include <linux/ktime.h>
12 #include <linux/delay.h>
13 #include <linux/iopoll.h>
14
15 #define INCVALUE_MASK 0x7fffffff
16 #define ISGN 0x80000000
17
18 #define IGC_SYSTIM_OVERFLOW_PERIOD (HZ * 60 * 9)
19 #define IGC_PTP_TX_TIMEOUT (HZ * 15)
20
21 #define IGC_PTM_STAT_SLEEP 2
22 #define IGC_PTM_STAT_TIMEOUT 100
23
24 /* SYSTIM read access for I225 */
igc_ptp_read(struct igc_adapter * adapter,struct timespec64 * ts)25 void igc_ptp_read(struct igc_adapter *adapter, struct timespec64 *ts)
26 {
27 struct igc_hw *hw = &adapter->hw;
28 u32 sec, nsec;
29
30 /* The timestamp is latched when SYSTIML is read. */
31 nsec = rd32(IGC_SYSTIML);
32 sec = rd32(IGC_SYSTIMH);
33
34 ts->tv_sec = sec;
35 ts->tv_nsec = nsec;
36 }
37
igc_ptp_write_i225(struct igc_adapter * adapter,const struct timespec64 * ts)38 static void igc_ptp_write_i225(struct igc_adapter *adapter,
39 const struct timespec64 *ts)
40 {
41 struct igc_hw *hw = &adapter->hw;
42
43 wr32(IGC_SYSTIML, ts->tv_nsec);
44 wr32(IGC_SYSTIMH, ts->tv_sec);
45 }
46
igc_ptp_adjfine_i225(struct ptp_clock_info * ptp,long scaled_ppm)47 static int igc_ptp_adjfine_i225(struct ptp_clock_info *ptp, long scaled_ppm)
48 {
49 struct igc_adapter *igc = container_of(ptp, struct igc_adapter,
50 ptp_caps);
51 struct igc_hw *hw = &igc->hw;
52 int neg_adj = 0;
53 u64 rate;
54 u32 inca;
55
56 if (scaled_ppm < 0) {
57 neg_adj = 1;
58 scaled_ppm = -scaled_ppm;
59 }
60 rate = scaled_ppm;
61 rate <<= 14;
62 rate = div_u64(rate, 78125);
63
64 inca = rate & INCVALUE_MASK;
65 if (neg_adj)
66 inca |= ISGN;
67
68 wr32(IGC_TIMINCA, inca);
69
70 return 0;
71 }
72
igc_ptp_adjtime_i225(struct ptp_clock_info * ptp,s64 delta)73 static int igc_ptp_adjtime_i225(struct ptp_clock_info *ptp, s64 delta)
74 {
75 struct igc_adapter *igc = container_of(ptp, struct igc_adapter,
76 ptp_caps);
77 struct timespec64 now, then = ns_to_timespec64(delta);
78 unsigned long flags;
79
80 spin_lock_irqsave(&igc->tmreg_lock, flags);
81
82 igc_ptp_read(igc, &now);
83 now = timespec64_add(now, then);
84 igc_ptp_write_i225(igc, (const struct timespec64 *)&now);
85
86 spin_unlock_irqrestore(&igc->tmreg_lock, flags);
87
88 return 0;
89 }
90
igc_ptp_gettimex64_i225(struct ptp_clock_info * ptp,struct timespec64 * ts,struct ptp_system_timestamp * sts)91 static int igc_ptp_gettimex64_i225(struct ptp_clock_info *ptp,
92 struct timespec64 *ts,
93 struct ptp_system_timestamp *sts)
94 {
95 struct igc_adapter *igc = container_of(ptp, struct igc_adapter,
96 ptp_caps);
97 struct igc_hw *hw = &igc->hw;
98 unsigned long flags;
99
100 spin_lock_irqsave(&igc->tmreg_lock, flags);
101
102 ptp_read_system_prets(sts);
103 ts->tv_nsec = rd32(IGC_SYSTIML);
104 ts->tv_sec = rd32(IGC_SYSTIMH);
105 ptp_read_system_postts(sts);
106
107 spin_unlock_irqrestore(&igc->tmreg_lock, flags);
108
109 return 0;
110 }
111
igc_ptp_settime_i225(struct ptp_clock_info * ptp,const struct timespec64 * ts)112 static int igc_ptp_settime_i225(struct ptp_clock_info *ptp,
113 const struct timespec64 *ts)
114 {
115 struct igc_adapter *igc = container_of(ptp, struct igc_adapter,
116 ptp_caps);
117 unsigned long flags;
118
119 spin_lock_irqsave(&igc->tmreg_lock, flags);
120
121 igc_ptp_write_i225(igc, ts);
122
123 spin_unlock_irqrestore(&igc->tmreg_lock, flags);
124
125 return 0;
126 }
127
igc_pin_direction(int pin,int input,u32 * ctrl,u32 * ctrl_ext)128 static void igc_pin_direction(int pin, int input, u32 *ctrl, u32 *ctrl_ext)
129 {
130 u32 *ptr = pin < 2 ? ctrl : ctrl_ext;
131 static const u32 mask[IGC_N_SDP] = {
132 IGC_CTRL_SDP0_DIR,
133 IGC_CTRL_SDP1_DIR,
134 IGC_CTRL_EXT_SDP2_DIR,
135 IGC_CTRL_EXT_SDP3_DIR,
136 };
137
138 if (input)
139 *ptr &= ~mask[pin];
140 else
141 *ptr |= mask[pin];
142 }
143
igc_pin_perout(struct igc_adapter * igc,int chan,int pin,int freq)144 static void igc_pin_perout(struct igc_adapter *igc, int chan, int pin, int freq)
145 {
146 static const u32 igc_aux0_sel_sdp[IGC_N_SDP] = {
147 IGC_AUX0_SEL_SDP0, IGC_AUX0_SEL_SDP1, IGC_AUX0_SEL_SDP2, IGC_AUX0_SEL_SDP3,
148 };
149 static const u32 igc_aux1_sel_sdp[IGC_N_SDP] = {
150 IGC_AUX1_SEL_SDP0, IGC_AUX1_SEL_SDP1, IGC_AUX1_SEL_SDP2, IGC_AUX1_SEL_SDP3,
151 };
152 static const u32 igc_ts_sdp_en[IGC_N_SDP] = {
153 IGC_TS_SDP0_EN, IGC_TS_SDP1_EN, IGC_TS_SDP2_EN, IGC_TS_SDP3_EN,
154 };
155 static const u32 igc_ts_sdp_sel_tt0[IGC_N_SDP] = {
156 IGC_TS_SDP0_SEL_TT0, IGC_TS_SDP1_SEL_TT0,
157 IGC_TS_SDP2_SEL_TT0, IGC_TS_SDP3_SEL_TT0,
158 };
159 static const u32 igc_ts_sdp_sel_tt1[IGC_N_SDP] = {
160 IGC_TS_SDP0_SEL_TT1, IGC_TS_SDP1_SEL_TT1,
161 IGC_TS_SDP2_SEL_TT1, IGC_TS_SDP3_SEL_TT1,
162 };
163 static const u32 igc_ts_sdp_sel_fc0[IGC_N_SDP] = {
164 IGC_TS_SDP0_SEL_FC0, IGC_TS_SDP1_SEL_FC0,
165 IGC_TS_SDP2_SEL_FC0, IGC_TS_SDP3_SEL_FC0,
166 };
167 static const u32 igc_ts_sdp_sel_fc1[IGC_N_SDP] = {
168 IGC_TS_SDP0_SEL_FC1, IGC_TS_SDP1_SEL_FC1,
169 IGC_TS_SDP2_SEL_FC1, IGC_TS_SDP3_SEL_FC1,
170 };
171 static const u32 igc_ts_sdp_sel_clr[IGC_N_SDP] = {
172 IGC_TS_SDP0_SEL_FC1, IGC_TS_SDP1_SEL_FC1,
173 IGC_TS_SDP2_SEL_FC1, IGC_TS_SDP3_SEL_FC1,
174 };
175 struct igc_hw *hw = &igc->hw;
176 u32 ctrl, ctrl_ext, tssdp = 0;
177
178 ctrl = rd32(IGC_CTRL);
179 ctrl_ext = rd32(IGC_CTRL_EXT);
180 tssdp = rd32(IGC_TSSDP);
181
182 igc_pin_direction(pin, 0, &ctrl, &ctrl_ext);
183
184 /* Make sure this pin is not enabled as an input. */
185 if ((tssdp & IGC_AUX0_SEL_SDP3) == igc_aux0_sel_sdp[pin])
186 tssdp &= ~IGC_AUX0_TS_SDP_EN;
187
188 if ((tssdp & IGC_AUX1_SEL_SDP3) == igc_aux1_sel_sdp[pin])
189 tssdp &= ~IGC_AUX1_TS_SDP_EN;
190
191 tssdp &= ~igc_ts_sdp_sel_clr[pin];
192 if (freq) {
193 if (chan == 1)
194 tssdp |= igc_ts_sdp_sel_fc1[pin];
195 else
196 tssdp |= igc_ts_sdp_sel_fc0[pin];
197 } else {
198 if (chan == 1)
199 tssdp |= igc_ts_sdp_sel_tt1[pin];
200 else
201 tssdp |= igc_ts_sdp_sel_tt0[pin];
202 }
203 tssdp |= igc_ts_sdp_en[pin];
204
205 wr32(IGC_TSSDP, tssdp);
206 wr32(IGC_CTRL, ctrl);
207 wr32(IGC_CTRL_EXT, ctrl_ext);
208 }
209
igc_pin_extts(struct igc_adapter * igc,int chan,int pin)210 static void igc_pin_extts(struct igc_adapter *igc, int chan, int pin)
211 {
212 static const u32 igc_aux0_sel_sdp[IGC_N_SDP] = {
213 IGC_AUX0_SEL_SDP0, IGC_AUX0_SEL_SDP1, IGC_AUX0_SEL_SDP2, IGC_AUX0_SEL_SDP3,
214 };
215 static const u32 igc_aux1_sel_sdp[IGC_N_SDP] = {
216 IGC_AUX1_SEL_SDP0, IGC_AUX1_SEL_SDP1, IGC_AUX1_SEL_SDP2, IGC_AUX1_SEL_SDP3,
217 };
218 static const u32 igc_ts_sdp_en[IGC_N_SDP] = {
219 IGC_TS_SDP0_EN, IGC_TS_SDP1_EN, IGC_TS_SDP2_EN, IGC_TS_SDP3_EN,
220 };
221 struct igc_hw *hw = &igc->hw;
222 u32 ctrl, ctrl_ext, tssdp = 0;
223
224 ctrl = rd32(IGC_CTRL);
225 ctrl_ext = rd32(IGC_CTRL_EXT);
226 tssdp = rd32(IGC_TSSDP);
227
228 igc_pin_direction(pin, 1, &ctrl, &ctrl_ext);
229
230 /* Make sure this pin is not enabled as an output. */
231 tssdp &= ~igc_ts_sdp_en[pin];
232
233 if (chan == 1) {
234 tssdp &= ~IGC_AUX1_SEL_SDP3;
235 tssdp |= igc_aux1_sel_sdp[pin] | IGC_AUX1_TS_SDP_EN;
236 } else {
237 tssdp &= ~IGC_AUX0_SEL_SDP3;
238 tssdp |= igc_aux0_sel_sdp[pin] | IGC_AUX0_TS_SDP_EN;
239 }
240
241 wr32(IGC_TSSDP, tssdp);
242 wr32(IGC_CTRL, ctrl);
243 wr32(IGC_CTRL_EXT, ctrl_ext);
244 }
245
igc_ptp_feature_enable_i225(struct ptp_clock_info * ptp,struct ptp_clock_request * rq,int on)246 static int igc_ptp_feature_enable_i225(struct ptp_clock_info *ptp,
247 struct ptp_clock_request *rq, int on)
248 {
249 struct igc_adapter *igc =
250 container_of(ptp, struct igc_adapter, ptp_caps);
251 struct igc_hw *hw = &igc->hw;
252 unsigned long flags;
253 struct timespec64 ts;
254 int use_freq = 0, pin = -1;
255 u32 tsim, tsauxc, tsauxc_mask, tsim_mask, trgttiml, trgttimh, freqout;
256 s64 ns;
257
258 switch (rq->type) {
259 case PTP_CLK_REQ_EXTTS:
260 /* Reject requests with unsupported flags */
261 if (rq->extts.flags & ~(PTP_ENABLE_FEATURE |
262 PTP_RISING_EDGE |
263 PTP_FALLING_EDGE |
264 PTP_STRICT_FLAGS))
265 return -EOPNOTSUPP;
266
267 /* Reject requests failing to enable both edges. */
268 if ((rq->extts.flags & PTP_STRICT_FLAGS) &&
269 (rq->extts.flags & PTP_ENABLE_FEATURE) &&
270 (rq->extts.flags & PTP_EXTTS_EDGES) != PTP_EXTTS_EDGES)
271 return -EOPNOTSUPP;
272
273 if (on) {
274 pin = ptp_find_pin(igc->ptp_clock, PTP_PF_EXTTS,
275 rq->extts.index);
276 if (pin < 0)
277 return -EBUSY;
278 }
279 if (rq->extts.index == 1) {
280 tsauxc_mask = IGC_TSAUXC_EN_TS1;
281 tsim_mask = IGC_TSICR_AUTT1;
282 } else {
283 tsauxc_mask = IGC_TSAUXC_EN_TS0;
284 tsim_mask = IGC_TSICR_AUTT0;
285 }
286 spin_lock_irqsave(&igc->tmreg_lock, flags);
287 tsauxc = rd32(IGC_TSAUXC);
288 tsim = rd32(IGC_TSIM);
289 if (on) {
290 igc_pin_extts(igc, rq->extts.index, pin);
291 tsauxc |= tsauxc_mask;
292 tsim |= tsim_mask;
293 } else {
294 tsauxc &= ~tsauxc_mask;
295 tsim &= ~tsim_mask;
296 }
297 wr32(IGC_TSAUXC, tsauxc);
298 wr32(IGC_TSIM, tsim);
299 spin_unlock_irqrestore(&igc->tmreg_lock, flags);
300 return 0;
301
302 case PTP_CLK_REQ_PEROUT:
303 /* Reject requests with unsupported flags */
304 if (rq->perout.flags)
305 return -EOPNOTSUPP;
306
307 if (on) {
308 pin = ptp_find_pin(igc->ptp_clock, PTP_PF_PEROUT,
309 rq->perout.index);
310 if (pin < 0)
311 return -EBUSY;
312 }
313 ts.tv_sec = rq->perout.period.sec;
314 ts.tv_nsec = rq->perout.period.nsec;
315 ns = timespec64_to_ns(&ts);
316 ns = ns >> 1;
317 if (on && (ns <= 70000000LL || ns == 125000000LL ||
318 ns == 250000000LL || ns == 500000000LL)) {
319 if (ns < 8LL)
320 return -EINVAL;
321 use_freq = 1;
322 }
323 ts = ns_to_timespec64(ns);
324 if (rq->perout.index == 1) {
325 if (use_freq) {
326 tsauxc_mask = IGC_TSAUXC_EN_CLK1 | IGC_TSAUXC_ST1;
327 tsim_mask = 0;
328 } else {
329 tsauxc_mask = IGC_TSAUXC_EN_TT1;
330 tsim_mask = IGC_TSICR_TT1;
331 }
332 trgttiml = IGC_TRGTTIML1;
333 trgttimh = IGC_TRGTTIMH1;
334 freqout = IGC_FREQOUT1;
335 } else {
336 if (use_freq) {
337 tsauxc_mask = IGC_TSAUXC_EN_CLK0 | IGC_TSAUXC_ST0;
338 tsim_mask = 0;
339 } else {
340 tsauxc_mask = IGC_TSAUXC_EN_TT0;
341 tsim_mask = IGC_TSICR_TT0;
342 }
343 trgttiml = IGC_TRGTTIML0;
344 trgttimh = IGC_TRGTTIMH0;
345 freqout = IGC_FREQOUT0;
346 }
347 spin_lock_irqsave(&igc->tmreg_lock, flags);
348 tsauxc = rd32(IGC_TSAUXC);
349 tsim = rd32(IGC_TSIM);
350 if (rq->perout.index == 1) {
351 tsauxc &= ~(IGC_TSAUXC_EN_TT1 | IGC_TSAUXC_EN_CLK1 |
352 IGC_TSAUXC_ST1);
353 tsim &= ~IGC_TSICR_TT1;
354 } else {
355 tsauxc &= ~(IGC_TSAUXC_EN_TT0 | IGC_TSAUXC_EN_CLK0 |
356 IGC_TSAUXC_ST0);
357 tsim &= ~IGC_TSICR_TT0;
358 }
359 if (on) {
360 struct timespec64 safe_start;
361 int i = rq->perout.index;
362
363 igc_pin_perout(igc, i, pin, use_freq);
364 igc_ptp_read(igc, &safe_start);
365
366 /* PPS output start time is triggered by Target time(TT)
367 * register. Programming any past time value into TT
368 * register will cause PPS to never start. Need to make
369 * sure we program the TT register a time ahead in
370 * future. There isn't a stringent need to fire PPS out
371 * right away. Adding +2 seconds should take care of
372 * corner cases. Let's say if the SYSTIML is close to
373 * wrap up and the timer keeps ticking as we program the
374 * register, adding +2seconds is safe bet.
375 */
376 safe_start.tv_sec += 2;
377
378 if (rq->perout.start.sec < safe_start.tv_sec)
379 igc->perout[i].start.tv_sec = safe_start.tv_sec;
380 else
381 igc->perout[i].start.tv_sec = rq->perout.start.sec;
382 igc->perout[i].start.tv_nsec = rq->perout.start.nsec;
383 igc->perout[i].period.tv_sec = ts.tv_sec;
384 igc->perout[i].period.tv_nsec = ts.tv_nsec;
385 wr32(trgttimh, (u32)igc->perout[i].start.tv_sec);
386 /* For now, always select timer 0 as source. */
387 wr32(trgttiml, (u32)(igc->perout[i].start.tv_nsec |
388 IGC_TT_IO_TIMER_SEL_SYSTIM0));
389 if (use_freq)
390 wr32(freqout, ns);
391 tsauxc |= tsauxc_mask;
392 tsim |= tsim_mask;
393 }
394 wr32(IGC_TSAUXC, tsauxc);
395 wr32(IGC_TSIM, tsim);
396 spin_unlock_irqrestore(&igc->tmreg_lock, flags);
397 return 0;
398
399 case PTP_CLK_REQ_PPS:
400 spin_lock_irqsave(&igc->tmreg_lock, flags);
401 tsim = rd32(IGC_TSIM);
402 if (on)
403 tsim |= IGC_TSICR_SYS_WRAP;
404 else
405 tsim &= ~IGC_TSICR_SYS_WRAP;
406 igc->pps_sys_wrap_on = on;
407 wr32(IGC_TSIM, tsim);
408 spin_unlock_irqrestore(&igc->tmreg_lock, flags);
409 return 0;
410
411 default:
412 break;
413 }
414
415 return -EOPNOTSUPP;
416 }
417
igc_ptp_verify_pin(struct ptp_clock_info * ptp,unsigned int pin,enum ptp_pin_function func,unsigned int chan)418 static int igc_ptp_verify_pin(struct ptp_clock_info *ptp, unsigned int pin,
419 enum ptp_pin_function func, unsigned int chan)
420 {
421 switch (func) {
422 case PTP_PF_NONE:
423 case PTP_PF_EXTTS:
424 case PTP_PF_PEROUT:
425 break;
426 case PTP_PF_PHYSYNC:
427 return -1;
428 }
429 return 0;
430 }
431
432 /**
433 * igc_ptp_systim_to_hwtstamp - convert system time value to HW timestamp
434 * @adapter: board private structure
435 * @hwtstamps: timestamp structure to update
436 * @systim: unsigned 64bit system time value
437 *
438 * We need to convert the system time value stored in the RX/TXSTMP registers
439 * into a hwtstamp which can be used by the upper level timestamping functions.
440 *
441 * Returns 0 on success.
442 **/
igc_ptp_systim_to_hwtstamp(struct igc_adapter * adapter,struct skb_shared_hwtstamps * hwtstamps,u64 systim)443 static int igc_ptp_systim_to_hwtstamp(struct igc_adapter *adapter,
444 struct skb_shared_hwtstamps *hwtstamps,
445 u64 systim)
446 {
447 switch (adapter->hw.mac.type) {
448 case igc_i225:
449 memset(hwtstamps, 0, sizeof(*hwtstamps));
450 /* Upper 32 bits contain s, lower 32 bits contain ns. */
451 hwtstamps->hwtstamp = ktime_set(systim >> 32,
452 systim & 0xFFFFFFFF);
453 break;
454 default:
455 return -EINVAL;
456 }
457 return 0;
458 }
459
460 /**
461 * igc_ptp_rx_pktstamp - Retrieve timestamp from Rx packet buffer
462 * @adapter: Pointer to adapter the packet buffer belongs to
463 * @buf: Pointer to packet buffer
464 *
465 * This function retrieves the timestamp saved in the beginning of packet
466 * buffer. While two timestamps are available, one in timer0 reference and the
467 * other in timer1 reference, this function considers only the timestamp in
468 * timer0 reference.
469 *
470 * Returns timestamp value.
471 */
igc_ptp_rx_pktstamp(struct igc_adapter * adapter,__le32 * buf)472 ktime_t igc_ptp_rx_pktstamp(struct igc_adapter *adapter, __le32 *buf)
473 {
474 ktime_t timestamp;
475 u32 secs, nsecs;
476 int adjust;
477
478 /* Timestamps are saved in little endian at the beginning of the packet
479 * buffer following the layout:
480 *
481 * DWORD: | 0 | 1 | 2 | 3 |
482 * Field: | Timer1 SYSTIML | Timer1 SYSTIMH | Timer0 SYSTIML | Timer0 SYSTIMH |
483 *
484 * SYSTIML holds the nanoseconds part while SYSTIMH holds the seconds
485 * part of the timestamp.
486 */
487 nsecs = le32_to_cpu(buf[2]);
488 secs = le32_to_cpu(buf[3]);
489
490 timestamp = ktime_set(secs, nsecs);
491
492 /* Adjust timestamp for the RX latency based on link speed */
493 switch (adapter->link_speed) {
494 case SPEED_10:
495 adjust = IGC_I225_RX_LATENCY_10;
496 break;
497 case SPEED_100:
498 adjust = IGC_I225_RX_LATENCY_100;
499 break;
500 case SPEED_1000:
501 adjust = IGC_I225_RX_LATENCY_1000;
502 break;
503 case SPEED_2500:
504 adjust = IGC_I225_RX_LATENCY_2500;
505 break;
506 default:
507 adjust = 0;
508 netdev_warn_once(adapter->netdev, "Imprecise timestamp\n");
509 break;
510 }
511
512 return ktime_sub_ns(timestamp, adjust);
513 }
514
igc_ptp_disable_rx_timestamp(struct igc_adapter * adapter)515 static void igc_ptp_disable_rx_timestamp(struct igc_adapter *adapter)
516 {
517 struct igc_hw *hw = &adapter->hw;
518 u32 val;
519 int i;
520
521 wr32(IGC_TSYNCRXCTL, 0);
522
523 for (i = 0; i < adapter->num_rx_queues; i++) {
524 val = rd32(IGC_SRRCTL(i));
525 val &= ~IGC_SRRCTL_TIMESTAMP;
526 wr32(IGC_SRRCTL(i), val);
527 }
528
529 val = rd32(IGC_RXPBS);
530 val &= ~IGC_RXPBS_CFG_TS_EN;
531 wr32(IGC_RXPBS, val);
532 }
533
igc_ptp_enable_rx_timestamp(struct igc_adapter * adapter)534 static void igc_ptp_enable_rx_timestamp(struct igc_adapter *adapter)
535 {
536 struct igc_hw *hw = &adapter->hw;
537 u32 val;
538 int i;
539
540 val = rd32(IGC_RXPBS);
541 val |= IGC_RXPBS_CFG_TS_EN;
542 wr32(IGC_RXPBS, val);
543
544 for (i = 0; i < adapter->num_rx_queues; i++) {
545 val = rd32(IGC_SRRCTL(i));
546 /* FIXME: For now, only support retrieving RX timestamps from
547 * timer 0.
548 */
549 val |= IGC_SRRCTL_TIMER1SEL(0) | IGC_SRRCTL_TIMER0SEL(0) |
550 IGC_SRRCTL_TIMESTAMP;
551 wr32(IGC_SRRCTL(i), val);
552 }
553
554 val = IGC_TSYNCRXCTL_ENABLED | IGC_TSYNCRXCTL_TYPE_ALL |
555 IGC_TSYNCRXCTL_RXSYNSIG;
556 wr32(IGC_TSYNCRXCTL, val);
557 }
558
igc_ptp_disable_tx_timestamp(struct igc_adapter * adapter)559 static void igc_ptp_disable_tx_timestamp(struct igc_adapter *adapter)
560 {
561 struct igc_hw *hw = &adapter->hw;
562
563 wr32(IGC_TSYNCTXCTL, 0);
564 }
565
igc_ptp_enable_tx_timestamp(struct igc_adapter * adapter)566 static void igc_ptp_enable_tx_timestamp(struct igc_adapter *adapter)
567 {
568 struct igc_hw *hw = &adapter->hw;
569
570 wr32(IGC_TSYNCTXCTL, IGC_TSYNCTXCTL_ENABLED | IGC_TSYNCTXCTL_TXSYNSIG);
571
572 /* Read TXSTMP registers to discard any timestamp previously stored. */
573 rd32(IGC_TXSTMPL);
574 rd32(IGC_TXSTMPH);
575 }
576
577 /**
578 * igc_ptp_set_timestamp_mode - setup hardware for timestamping
579 * @adapter: networking device structure
580 * @config: hwtstamp configuration
581 *
582 * Return: 0 in case of success, negative errno code otherwise.
583 */
igc_ptp_set_timestamp_mode(struct igc_adapter * adapter,struct hwtstamp_config * config)584 static int igc_ptp_set_timestamp_mode(struct igc_adapter *adapter,
585 struct hwtstamp_config *config)
586 {
587 /* reserved for future extensions */
588 if (config->flags)
589 return -EINVAL;
590
591 switch (config->tx_type) {
592 case HWTSTAMP_TX_OFF:
593 igc_ptp_disable_tx_timestamp(adapter);
594 break;
595 case HWTSTAMP_TX_ON:
596 igc_ptp_enable_tx_timestamp(adapter);
597 break;
598 default:
599 return -ERANGE;
600 }
601
602 switch (config->rx_filter) {
603 case HWTSTAMP_FILTER_NONE:
604 igc_ptp_disable_rx_timestamp(adapter);
605 break;
606 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
607 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
608 case HWTSTAMP_FILTER_PTP_V2_EVENT:
609 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
610 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
611 case HWTSTAMP_FILTER_PTP_V2_SYNC:
612 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
613 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
614 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
615 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
616 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
617 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
618 case HWTSTAMP_FILTER_NTP_ALL:
619 case HWTSTAMP_FILTER_ALL:
620 igc_ptp_enable_rx_timestamp(adapter);
621 config->rx_filter = HWTSTAMP_FILTER_ALL;
622 break;
623 default:
624 return -ERANGE;
625 }
626
627 return 0;
628 }
629
630 /* Requires adapter->ptp_tx_lock held by caller. */
igc_ptp_tx_timeout(struct igc_adapter * adapter)631 static void igc_ptp_tx_timeout(struct igc_adapter *adapter)
632 {
633 struct igc_hw *hw = &adapter->hw;
634
635 dev_kfree_skb_any(adapter->ptp_tx_skb);
636 adapter->ptp_tx_skb = NULL;
637 adapter->tx_hwtstamp_timeouts++;
638 /* Clear the tx valid bit in TSYNCTXCTL register to enable interrupt. */
639 rd32(IGC_TXSTMPH);
640 netdev_warn(adapter->netdev, "Tx timestamp timeout\n");
641 }
642
igc_ptp_tx_hang(struct igc_adapter * adapter)643 void igc_ptp_tx_hang(struct igc_adapter *adapter)
644 {
645 unsigned long flags;
646
647 spin_lock_irqsave(&adapter->ptp_tx_lock, flags);
648
649 if (!adapter->ptp_tx_skb)
650 goto unlock;
651
652 if (time_is_after_jiffies(adapter->ptp_tx_start + IGC_PTP_TX_TIMEOUT))
653 goto unlock;
654
655 igc_ptp_tx_timeout(adapter);
656
657 unlock:
658 spin_unlock_irqrestore(&adapter->ptp_tx_lock, flags);
659 }
660
661 /**
662 * igc_ptp_tx_hwtstamp - utility function which checks for TX time stamp
663 * @adapter: Board private structure
664 *
665 * If we were asked to do hardware stamping and such a time stamp is
666 * available, then it must have been for this skb here because we only
667 * allow only one such packet into the queue.
668 *
669 * Context: Expects adapter->ptp_tx_lock to be held by caller.
670 */
igc_ptp_tx_hwtstamp(struct igc_adapter * adapter)671 static void igc_ptp_tx_hwtstamp(struct igc_adapter *adapter)
672 {
673 struct sk_buff *skb = adapter->ptp_tx_skb;
674 struct skb_shared_hwtstamps shhwtstamps;
675 struct igc_hw *hw = &adapter->hw;
676 int adjust = 0;
677 u64 regval;
678
679 if (WARN_ON_ONCE(!skb))
680 return;
681
682 regval = rd32(IGC_TXSTMPL);
683 regval |= (u64)rd32(IGC_TXSTMPH) << 32;
684 if (igc_ptp_systim_to_hwtstamp(adapter, &shhwtstamps, regval))
685 return;
686
687 switch (adapter->link_speed) {
688 case SPEED_10:
689 adjust = IGC_I225_TX_LATENCY_10;
690 break;
691 case SPEED_100:
692 adjust = IGC_I225_TX_LATENCY_100;
693 break;
694 case SPEED_1000:
695 adjust = IGC_I225_TX_LATENCY_1000;
696 break;
697 case SPEED_2500:
698 adjust = IGC_I225_TX_LATENCY_2500;
699 break;
700 }
701
702 shhwtstamps.hwtstamp =
703 ktime_add_ns(shhwtstamps.hwtstamp, adjust);
704
705 adapter->ptp_tx_skb = NULL;
706
707 /* Notify the stack and free the skb after we've unlocked */
708 skb_tstamp_tx(skb, &shhwtstamps);
709 dev_kfree_skb_any(skb);
710 }
711
712 /**
713 * igc_ptp_tx_work
714 * @work: pointer to work struct
715 *
716 * This work function checks the TSYNCTXCTL valid bit to determine when
717 * a timestamp has been taken for the current stored skb.
718 */
igc_ptp_tx_work(struct work_struct * work)719 static void igc_ptp_tx_work(struct work_struct *work)
720 {
721 struct igc_adapter *adapter = container_of(work, struct igc_adapter,
722 ptp_tx_work);
723 struct igc_hw *hw = &adapter->hw;
724 unsigned long flags;
725 u32 tsynctxctl;
726
727 spin_lock_irqsave(&adapter->ptp_tx_lock, flags);
728
729 if (!adapter->ptp_tx_skb)
730 goto unlock;
731
732 tsynctxctl = rd32(IGC_TSYNCTXCTL);
733 tsynctxctl &= IGC_TSYNCTXCTL_TXTT_0;
734 if (!tsynctxctl) {
735 WARN_ONCE(1, "Received a TSTAMP interrupt but no TSTAMP is ready.\n");
736 goto unlock;
737 }
738
739 igc_ptp_tx_hwtstamp(adapter);
740
741 unlock:
742 spin_unlock_irqrestore(&adapter->ptp_tx_lock, flags);
743 }
744
745 /**
746 * igc_ptp_set_ts_config - set hardware time stamping config
747 * @netdev: network interface device structure
748 * @ifr: interface request data
749 *
750 **/
igc_ptp_set_ts_config(struct net_device * netdev,struct ifreq * ifr)751 int igc_ptp_set_ts_config(struct net_device *netdev, struct ifreq *ifr)
752 {
753 struct igc_adapter *adapter = netdev_priv(netdev);
754 struct hwtstamp_config config;
755 int err;
756
757 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
758 return -EFAULT;
759
760 err = igc_ptp_set_timestamp_mode(adapter, &config);
761 if (err)
762 return err;
763
764 /* save these settings for future reference */
765 memcpy(&adapter->tstamp_config, &config,
766 sizeof(adapter->tstamp_config));
767
768 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
769 -EFAULT : 0;
770 }
771
772 /**
773 * igc_ptp_get_ts_config - get hardware time stamping config
774 * @netdev: network interface device structure
775 * @ifr: interface request data
776 *
777 * Get the hwtstamp_config settings to return to the user. Rather than attempt
778 * to deconstruct the settings from the registers, just return a shadow copy
779 * of the last known settings.
780 **/
igc_ptp_get_ts_config(struct net_device * netdev,struct ifreq * ifr)781 int igc_ptp_get_ts_config(struct net_device *netdev, struct ifreq *ifr)
782 {
783 struct igc_adapter *adapter = netdev_priv(netdev);
784 struct hwtstamp_config *config = &adapter->tstamp_config;
785
786 return copy_to_user(ifr->ifr_data, config, sizeof(*config)) ?
787 -EFAULT : 0;
788 }
789
790 /* The two conditions below must be met for cross timestamping via
791 * PCIe PTM:
792 *
793 * 1. We have an way to convert the timestamps in the PTM messages
794 * to something related to the system clocks (right now, only
795 * X86 systems with support for the Always Running Timer allow that);
796 *
797 * 2. We have PTM enabled in the path from the device to the PCIe root port.
798 */
igc_is_crosststamp_supported(struct igc_adapter * adapter)799 static bool igc_is_crosststamp_supported(struct igc_adapter *adapter)
800 {
801 if (!IS_ENABLED(CONFIG_X86_TSC))
802 return false;
803
804 /* FIXME: it was noticed that enabling support for PCIe PTM in
805 * some i225-V models could cause lockups when bringing the
806 * interface up/down. There should be no downsides to
807 * disabling crosstimestamping support for i225-V, as it
808 * doesn't have any PTP support. That way we gain some time
809 * while root causing the issue.
810 */
811 if (adapter->pdev->device == IGC_DEV_ID_I225_V)
812 return false;
813
814 return pcie_ptm_enabled(adapter->pdev);
815 }
816
igc_device_tstamp_to_system(u64 tstamp)817 static struct system_counterval_t igc_device_tstamp_to_system(u64 tstamp)
818 {
819 #if IS_ENABLED(CONFIG_X86_TSC) && !defined(CONFIG_UML)
820 return convert_art_ns_to_tsc(tstamp);
821 #else
822 return (struct system_counterval_t) { };
823 #endif
824 }
825
igc_ptm_log_error(struct igc_adapter * adapter,u32 ptm_stat)826 static void igc_ptm_log_error(struct igc_adapter *adapter, u32 ptm_stat)
827 {
828 struct net_device *netdev = adapter->netdev;
829
830 switch (ptm_stat) {
831 case IGC_PTM_STAT_RET_ERR:
832 netdev_err(netdev, "PTM Error: Root port timeout\n");
833 break;
834 case IGC_PTM_STAT_BAD_PTM_RES:
835 netdev_err(netdev, "PTM Error: Bad response, PTM Response Data expected\n");
836 break;
837 case IGC_PTM_STAT_T4M1_OVFL:
838 netdev_err(netdev, "PTM Error: T4 minus T1 overflow\n");
839 break;
840 case IGC_PTM_STAT_ADJUST_1ST:
841 netdev_err(netdev, "PTM Error: 1588 timer adjusted during first PTM cycle\n");
842 break;
843 case IGC_PTM_STAT_ADJUST_CYC:
844 netdev_err(netdev, "PTM Error: 1588 timer adjusted during non-first PTM cycle\n");
845 break;
846 default:
847 netdev_err(netdev, "PTM Error: Unknown error (%#x)\n", ptm_stat);
848 break;
849 }
850 }
851
igc_phc_get_syncdevicetime(ktime_t * device,struct system_counterval_t * system,void * ctx)852 static int igc_phc_get_syncdevicetime(ktime_t *device,
853 struct system_counterval_t *system,
854 void *ctx)
855 {
856 u32 stat, t2_curr_h, t2_curr_l, ctrl;
857 struct igc_adapter *adapter = ctx;
858 struct igc_hw *hw = &adapter->hw;
859 int err, count = 100;
860 ktime_t t1, t2_curr;
861
862 /* Get a snapshot of system clocks to use as historic value. */
863 ktime_get_snapshot(&adapter->snapshot);
864
865 do {
866 /* Doing this in a loop because in the event of a
867 * badly timed (ha!) system clock adjustment, we may
868 * get PTM errors from the PCI root, but these errors
869 * are transitory. Repeating the process returns valid
870 * data eventually.
871 */
872
873 /* To "manually" start the PTM cycle we need to clear and
874 * then set again the TRIG bit.
875 */
876 ctrl = rd32(IGC_PTM_CTRL);
877 ctrl &= ~IGC_PTM_CTRL_TRIG;
878 wr32(IGC_PTM_CTRL, ctrl);
879 ctrl |= IGC_PTM_CTRL_TRIG;
880 wr32(IGC_PTM_CTRL, ctrl);
881
882 /* The cycle only starts "for real" when software notifies
883 * that it has read the registers, this is done by setting
884 * VALID bit.
885 */
886 wr32(IGC_PTM_STAT, IGC_PTM_STAT_VALID);
887
888 err = readx_poll_timeout(rd32, IGC_PTM_STAT, stat,
889 stat, IGC_PTM_STAT_SLEEP,
890 IGC_PTM_STAT_TIMEOUT);
891 if (err < 0) {
892 netdev_err(adapter->netdev, "Timeout reading IGC_PTM_STAT register\n");
893 return err;
894 }
895
896 if ((stat & IGC_PTM_STAT_VALID) == IGC_PTM_STAT_VALID)
897 break;
898
899 if (stat & ~IGC_PTM_STAT_VALID) {
900 /* An error occurred, log it. */
901 igc_ptm_log_error(adapter, stat);
902 /* The STAT register is write-1-to-clear (W1C),
903 * so write the previous error status to clear it.
904 */
905 wr32(IGC_PTM_STAT, stat);
906 continue;
907 }
908 } while (--count);
909
910 if (!count) {
911 netdev_err(adapter->netdev, "Exceeded number of tries for PTM cycle\n");
912 return -ETIMEDOUT;
913 }
914
915 t1 = ktime_set(rd32(IGC_PTM_T1_TIM0_H), rd32(IGC_PTM_T1_TIM0_L));
916
917 t2_curr_l = rd32(IGC_PTM_CURR_T2_L);
918 t2_curr_h = rd32(IGC_PTM_CURR_T2_H);
919
920 /* FIXME: When the register that tells the endianness of the
921 * PTM registers are implemented, check them here and add the
922 * appropriate conversion.
923 */
924 t2_curr_h = swab32(t2_curr_h);
925
926 t2_curr = ((s64)t2_curr_h << 32 | t2_curr_l);
927
928 *device = t1;
929 *system = igc_device_tstamp_to_system(t2_curr);
930
931 return 0;
932 }
933
igc_ptp_getcrosststamp(struct ptp_clock_info * ptp,struct system_device_crosststamp * cts)934 static int igc_ptp_getcrosststamp(struct ptp_clock_info *ptp,
935 struct system_device_crosststamp *cts)
936 {
937 struct igc_adapter *adapter = container_of(ptp, struct igc_adapter,
938 ptp_caps);
939
940 return get_device_system_crosststamp(igc_phc_get_syncdevicetime,
941 adapter, &adapter->snapshot, cts);
942 }
943
944 /**
945 * igc_ptp_init - Initialize PTP functionality
946 * @adapter: Board private structure
947 *
948 * This function is called at device probe to initialize the PTP
949 * functionality.
950 */
igc_ptp_init(struct igc_adapter * adapter)951 void igc_ptp_init(struct igc_adapter *adapter)
952 {
953 struct net_device *netdev = adapter->netdev;
954 struct igc_hw *hw = &adapter->hw;
955 int i;
956
957 switch (hw->mac.type) {
958 case igc_i225:
959 for (i = 0; i < IGC_N_SDP; i++) {
960 struct ptp_pin_desc *ppd = &adapter->sdp_config[i];
961
962 snprintf(ppd->name, sizeof(ppd->name), "SDP%d", i);
963 ppd->index = i;
964 ppd->func = PTP_PF_NONE;
965 }
966 snprintf(adapter->ptp_caps.name, 16, "%pm", netdev->dev_addr);
967 adapter->ptp_caps.owner = THIS_MODULE;
968 adapter->ptp_caps.max_adj = 62499999;
969 adapter->ptp_caps.adjfine = igc_ptp_adjfine_i225;
970 adapter->ptp_caps.adjtime = igc_ptp_adjtime_i225;
971 adapter->ptp_caps.gettimex64 = igc_ptp_gettimex64_i225;
972 adapter->ptp_caps.settime64 = igc_ptp_settime_i225;
973 adapter->ptp_caps.enable = igc_ptp_feature_enable_i225;
974 adapter->ptp_caps.pps = 1;
975 adapter->ptp_caps.pin_config = adapter->sdp_config;
976 adapter->ptp_caps.n_ext_ts = IGC_N_EXTTS;
977 adapter->ptp_caps.n_per_out = IGC_N_PEROUT;
978 adapter->ptp_caps.n_pins = IGC_N_SDP;
979 adapter->ptp_caps.verify = igc_ptp_verify_pin;
980
981 if (!igc_is_crosststamp_supported(adapter))
982 break;
983
984 adapter->ptp_caps.getcrosststamp = igc_ptp_getcrosststamp;
985 break;
986 default:
987 adapter->ptp_clock = NULL;
988 return;
989 }
990
991 spin_lock_init(&adapter->ptp_tx_lock);
992 spin_lock_init(&adapter->tmreg_lock);
993 INIT_WORK(&adapter->ptp_tx_work, igc_ptp_tx_work);
994
995 adapter->tstamp_config.rx_filter = HWTSTAMP_FILTER_NONE;
996 adapter->tstamp_config.tx_type = HWTSTAMP_TX_OFF;
997
998 adapter->prev_ptp_time = ktime_to_timespec64(ktime_get_real());
999 adapter->ptp_reset_start = ktime_get();
1000
1001 adapter->ptp_clock = ptp_clock_register(&adapter->ptp_caps,
1002 &adapter->pdev->dev);
1003 if (IS_ERR(adapter->ptp_clock)) {
1004 adapter->ptp_clock = NULL;
1005 netdev_err(netdev, "ptp_clock_register failed\n");
1006 } else if (adapter->ptp_clock) {
1007 netdev_info(netdev, "PHC added\n");
1008 adapter->ptp_flags |= IGC_PTP_ENABLED;
1009 }
1010 }
1011
igc_ptp_time_save(struct igc_adapter * adapter)1012 static void igc_ptp_time_save(struct igc_adapter *adapter)
1013 {
1014 igc_ptp_read(adapter, &adapter->prev_ptp_time);
1015 adapter->ptp_reset_start = ktime_get();
1016 }
1017
igc_ptp_time_restore(struct igc_adapter * adapter)1018 static void igc_ptp_time_restore(struct igc_adapter *adapter)
1019 {
1020 struct timespec64 ts = adapter->prev_ptp_time;
1021 ktime_t delta;
1022
1023 delta = ktime_sub(ktime_get(), adapter->ptp_reset_start);
1024
1025 timespec64_add_ns(&ts, ktime_to_ns(delta));
1026
1027 igc_ptp_write_i225(adapter, &ts);
1028 }
1029
igc_ptm_stop(struct igc_adapter * adapter)1030 static void igc_ptm_stop(struct igc_adapter *adapter)
1031 {
1032 struct igc_hw *hw = &adapter->hw;
1033 u32 ctrl;
1034
1035 ctrl = rd32(IGC_PTM_CTRL);
1036 ctrl &= ~IGC_PTM_CTRL_EN;
1037
1038 wr32(IGC_PTM_CTRL, ctrl);
1039 }
1040
1041 /**
1042 * igc_ptp_suspend - Disable PTP work items and prepare for suspend
1043 * @adapter: Board private structure
1044 *
1045 * This function stops the overflow check work and PTP Tx timestamp work, and
1046 * will prepare the device for OS suspend.
1047 */
igc_ptp_suspend(struct igc_adapter * adapter)1048 void igc_ptp_suspend(struct igc_adapter *adapter)
1049 {
1050 if (!(adapter->ptp_flags & IGC_PTP_ENABLED))
1051 return;
1052
1053 cancel_work_sync(&adapter->ptp_tx_work);
1054 dev_kfree_skb_any(adapter->ptp_tx_skb);
1055 adapter->ptp_tx_skb = NULL;
1056
1057 if (pci_device_is_present(adapter->pdev)) {
1058 igc_ptp_time_save(adapter);
1059 igc_ptm_stop(adapter);
1060 }
1061 }
1062
1063 /**
1064 * igc_ptp_stop - Disable PTP device and stop the overflow check.
1065 * @adapter: Board private structure.
1066 *
1067 * This function stops the PTP support and cancels the delayed work.
1068 **/
igc_ptp_stop(struct igc_adapter * adapter)1069 void igc_ptp_stop(struct igc_adapter *adapter)
1070 {
1071 igc_ptp_suspend(adapter);
1072
1073 if (adapter->ptp_clock) {
1074 ptp_clock_unregister(adapter->ptp_clock);
1075 netdev_info(adapter->netdev, "PHC removed\n");
1076 adapter->ptp_flags &= ~IGC_PTP_ENABLED;
1077 }
1078 }
1079
1080 /**
1081 * igc_ptp_reset - Re-enable the adapter for PTP following a reset.
1082 * @adapter: Board private structure.
1083 *
1084 * This function handles the reset work required to re-enable the PTP device.
1085 **/
igc_ptp_reset(struct igc_adapter * adapter)1086 void igc_ptp_reset(struct igc_adapter *adapter)
1087 {
1088 struct igc_hw *hw = &adapter->hw;
1089 u32 cycle_ctrl, ctrl;
1090 unsigned long flags;
1091 u32 timadj;
1092
1093 /* reset the tstamp_config */
1094 igc_ptp_set_timestamp_mode(adapter, &adapter->tstamp_config);
1095
1096 spin_lock_irqsave(&adapter->tmreg_lock, flags);
1097
1098 switch (adapter->hw.mac.type) {
1099 case igc_i225:
1100 timadj = rd32(IGC_TIMADJ);
1101 timadj |= IGC_TIMADJ_ADJUST_METH;
1102 wr32(IGC_TIMADJ, timadj);
1103
1104 wr32(IGC_TSAUXC, 0x0);
1105 wr32(IGC_TSSDP, 0x0);
1106 wr32(IGC_TSIM,
1107 IGC_TSICR_INTERRUPTS |
1108 (adapter->pps_sys_wrap_on ? IGC_TSICR_SYS_WRAP : 0));
1109 wr32(IGC_IMS, IGC_IMS_TS);
1110
1111 if (!igc_is_crosststamp_supported(adapter))
1112 break;
1113
1114 wr32(IGC_PCIE_DIG_DELAY, IGC_PCIE_DIG_DELAY_DEFAULT);
1115 wr32(IGC_PCIE_PHY_DELAY, IGC_PCIE_PHY_DELAY_DEFAULT);
1116
1117 cycle_ctrl = IGC_PTM_CYCLE_CTRL_CYC_TIME(IGC_PTM_CYC_TIME_DEFAULT);
1118
1119 wr32(IGC_PTM_CYCLE_CTRL, cycle_ctrl);
1120
1121 ctrl = IGC_PTM_CTRL_EN |
1122 IGC_PTM_CTRL_START_NOW |
1123 IGC_PTM_CTRL_SHRT_CYC(IGC_PTM_SHORT_CYC_DEFAULT) |
1124 IGC_PTM_CTRL_PTM_TO(IGC_PTM_TIMEOUT_DEFAULT) |
1125 IGC_PTM_CTRL_TRIG;
1126
1127 wr32(IGC_PTM_CTRL, ctrl);
1128
1129 /* Force the first cycle to run. */
1130 wr32(IGC_PTM_STAT, IGC_PTM_STAT_VALID);
1131
1132 break;
1133 default:
1134 /* No work to do. */
1135 goto out;
1136 }
1137
1138 /* Re-initialize the timer. */
1139 if (hw->mac.type == igc_i225) {
1140 igc_ptp_time_restore(adapter);
1141 } else {
1142 timecounter_init(&adapter->tc, &adapter->cc,
1143 ktime_to_ns(ktime_get_real()));
1144 }
1145 out:
1146 spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
1147
1148 wrfl();
1149 }
1150