1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/module.h>
20#include <linux/device.h>
21#include <linux/pci.h>
22#include <linux/ptp_classify.h>
23
24#include "igb.h"
25
26#define INCVALUE_MASK 0x7fffffff
27#define ISGN 0x80000000
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71#define IGB_SYSTIM_OVERFLOW_PERIOD (HZ * 60 * 9)
72#define IGB_PTP_TX_TIMEOUT (HZ * 15)
73#define INCPERIOD_82576 (1 << E1000_TIMINCA_16NS_SHIFT)
74#define INCVALUE_82576_MASK ((1 << E1000_TIMINCA_16NS_SHIFT) - 1)
75#define INCVALUE_82576 (16 << IGB_82576_TSYNC_SHIFT)
76#define IGB_NBITS_82580 40
77
78
79static cycle_t igb_ptp_read_82576(const struct cyclecounter *cc)
80{
81 struct igb_adapter *igb = container_of(cc, struct igb_adapter, cc);
82 struct e1000_hw *hw = &igb->hw;
83 u64 val;
84 u32 lo, hi;
85
86 lo = rd32(E1000_SYSTIML);
87 hi = rd32(E1000_SYSTIMH);
88
89 val = ((u64) hi) << 32;
90 val |= lo;
91
92 return val;
93}
94
95
96static cycle_t igb_ptp_read_82580(const struct cyclecounter *cc)
97{
98 struct igb_adapter *igb = container_of(cc, struct igb_adapter, cc);
99 struct e1000_hw *hw = &igb->hw;
100 u32 lo, hi;
101 u64 val;
102
103
104
105
106
107 rd32(E1000_SYSTIMR);
108 lo = rd32(E1000_SYSTIML);
109 hi = rd32(E1000_SYSTIMH);
110
111 val = ((u64) hi) << 32;
112 val |= lo;
113
114 return val;
115}
116
117
118static void igb_ptp_read_i210(struct igb_adapter *adapter, struct timespec *ts)
119{
120 struct e1000_hw *hw = &adapter->hw;
121 u32 sec, nsec;
122
123
124
125
126
127 rd32(E1000_SYSTIMR);
128 nsec = rd32(E1000_SYSTIML);
129 sec = rd32(E1000_SYSTIMH);
130
131 ts->tv_sec = sec;
132 ts->tv_nsec = nsec;
133}
134
135static void igb_ptp_write_i210(struct igb_adapter *adapter,
136 const struct timespec *ts)
137{
138 struct e1000_hw *hw = &adapter->hw;
139
140
141
142
143 wr32(E1000_SYSTIML, ts->tv_nsec);
144 wr32(E1000_SYSTIMH, ts->tv_sec);
145}
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164static void igb_ptp_systim_to_hwtstamp(struct igb_adapter *adapter,
165 struct skb_shared_hwtstamps *hwtstamps,
166 u64 systim)
167{
168 unsigned long flags;
169 u64 ns;
170
171 switch (adapter->hw.mac.type) {
172 case e1000_82576:
173 case e1000_82580:
174 case e1000_i354:
175 case e1000_i350:
176 spin_lock_irqsave(&adapter->tmreg_lock, flags);
177
178 ns = timecounter_cyc2time(&adapter->tc, systim);
179
180 spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
181
182 memset(hwtstamps, 0, sizeof(*hwtstamps));
183 hwtstamps->hwtstamp = ns_to_ktime(ns);
184 break;
185 case e1000_i210:
186 case e1000_i211:
187 memset(hwtstamps, 0, sizeof(*hwtstamps));
188
189 hwtstamps->hwtstamp = ktime_set(systim >> 32,
190 systim & 0xFFFFFFFF);
191 break;
192 default:
193 break;
194 }
195}
196
197
198static int igb_ptp_adjfreq_82576(struct ptp_clock_info *ptp, s32 ppb)
199{
200 struct igb_adapter *igb = container_of(ptp, struct igb_adapter,
201 ptp_caps);
202 struct e1000_hw *hw = &igb->hw;
203 int neg_adj = 0;
204 u64 rate;
205 u32 incvalue;
206
207 if (ppb < 0) {
208 neg_adj = 1;
209 ppb = -ppb;
210 }
211 rate = ppb;
212 rate <<= 14;
213 rate = div_u64(rate, 1953125);
214
215 incvalue = 16 << IGB_82576_TSYNC_SHIFT;
216
217 if (neg_adj)
218 incvalue -= rate;
219 else
220 incvalue += rate;
221
222 wr32(E1000_TIMINCA, INCPERIOD_82576 | (incvalue & INCVALUE_82576_MASK));
223
224 return 0;
225}
226
227static int igb_ptp_adjfreq_82580(struct ptp_clock_info *ptp, s32 ppb)
228{
229 struct igb_adapter *igb = container_of(ptp, struct igb_adapter,
230 ptp_caps);
231 struct e1000_hw *hw = &igb->hw;
232 int neg_adj = 0;
233 u64 rate;
234 u32 inca;
235
236 if (ppb < 0) {
237 neg_adj = 1;
238 ppb = -ppb;
239 }
240 rate = ppb;
241 rate <<= 26;
242 rate = div_u64(rate, 1953125);
243
244 inca = rate & INCVALUE_MASK;
245 if (neg_adj)
246 inca |= ISGN;
247
248 wr32(E1000_TIMINCA, inca);
249
250 return 0;
251}
252
253static int igb_ptp_adjtime_82576(struct ptp_clock_info *ptp, s64 delta)
254{
255 struct igb_adapter *igb = container_of(ptp, struct igb_adapter,
256 ptp_caps);
257 unsigned long flags;
258 s64 now;
259
260 spin_lock_irqsave(&igb->tmreg_lock, flags);
261
262 now = timecounter_read(&igb->tc);
263 now += delta;
264 timecounter_init(&igb->tc, &igb->cc, now);
265
266 spin_unlock_irqrestore(&igb->tmreg_lock, flags);
267
268 return 0;
269}
270
271static int igb_ptp_adjtime_i210(struct ptp_clock_info *ptp, s64 delta)
272{
273 struct igb_adapter *igb = container_of(ptp, struct igb_adapter,
274 ptp_caps);
275 unsigned long flags;
276 struct timespec now, then = ns_to_timespec(delta);
277
278 spin_lock_irqsave(&igb->tmreg_lock, flags);
279
280 igb_ptp_read_i210(igb, &now);
281 now = timespec_add(now, then);
282 igb_ptp_write_i210(igb, (const struct timespec *)&now);
283
284 spin_unlock_irqrestore(&igb->tmreg_lock, flags);
285
286 return 0;
287}
288
289static int igb_ptp_gettime_82576(struct ptp_clock_info *ptp,
290 struct timespec *ts)
291{
292 struct igb_adapter *igb = container_of(ptp, struct igb_adapter,
293 ptp_caps);
294 unsigned long flags;
295 u64 ns;
296 u32 remainder;
297
298 spin_lock_irqsave(&igb->tmreg_lock, flags);
299
300 ns = timecounter_read(&igb->tc);
301
302 spin_unlock_irqrestore(&igb->tmreg_lock, flags);
303
304 ts->tv_sec = div_u64_rem(ns, 1000000000, &remainder);
305 ts->tv_nsec = remainder;
306
307 return 0;
308}
309
310static int igb_ptp_gettime_i210(struct ptp_clock_info *ptp,
311 struct timespec *ts)
312{
313 struct igb_adapter *igb = container_of(ptp, struct igb_adapter,
314 ptp_caps);
315 unsigned long flags;
316
317 spin_lock_irqsave(&igb->tmreg_lock, flags);
318
319 igb_ptp_read_i210(igb, ts);
320
321 spin_unlock_irqrestore(&igb->tmreg_lock, flags);
322
323 return 0;
324}
325
326static int igb_ptp_settime_82576(struct ptp_clock_info *ptp,
327 const struct timespec *ts)
328{
329 struct igb_adapter *igb = container_of(ptp, struct igb_adapter,
330 ptp_caps);
331 unsigned long flags;
332 u64 ns;
333
334 ns = ts->tv_sec * 1000000000ULL;
335 ns += ts->tv_nsec;
336
337 spin_lock_irqsave(&igb->tmreg_lock, flags);
338
339 timecounter_init(&igb->tc, &igb->cc, ns);
340
341 spin_unlock_irqrestore(&igb->tmreg_lock, flags);
342
343 return 0;
344}
345
346static int igb_ptp_settime_i210(struct ptp_clock_info *ptp,
347 const struct timespec *ts)
348{
349 struct igb_adapter *igb = container_of(ptp, struct igb_adapter,
350 ptp_caps);
351 unsigned long flags;
352
353 spin_lock_irqsave(&igb->tmreg_lock, flags);
354
355 igb_ptp_write_i210(igb, ts);
356
357 spin_unlock_irqrestore(&igb->tmreg_lock, flags);
358
359 return 0;
360}
361
362static int igb_ptp_enable(struct ptp_clock_info *ptp,
363 struct ptp_clock_request *rq, int on)
364{
365 return -EOPNOTSUPP;
366}
367
368
369
370
371
372
373
374
375void igb_ptp_tx_work(struct work_struct *work)
376{
377 struct igb_adapter *adapter = container_of(work, struct igb_adapter,
378 ptp_tx_work);
379 struct e1000_hw *hw = &adapter->hw;
380 u32 tsynctxctl;
381
382 if (!adapter->ptp_tx_skb)
383 return;
384
385 if (time_is_before_jiffies(adapter->ptp_tx_start +
386 IGB_PTP_TX_TIMEOUT)) {
387 dev_kfree_skb_any(adapter->ptp_tx_skb);
388 adapter->ptp_tx_skb = NULL;
389 adapter->tx_hwtstamp_timeouts++;
390 dev_warn(&adapter->pdev->dev, "clearing Tx timestamp hang");
391 return;
392 }
393
394 tsynctxctl = rd32(E1000_TSYNCTXCTL);
395 if (tsynctxctl & E1000_TSYNCTXCTL_VALID)
396 igb_ptp_tx_hwtstamp(adapter);
397 else
398
399 schedule_work(&adapter->ptp_tx_work);
400}
401
402static void igb_ptp_overflow_check(struct work_struct *work)
403{
404 struct igb_adapter *igb =
405 container_of(work, struct igb_adapter, ptp_overflow_work.work);
406 struct timespec ts;
407
408 igb->ptp_caps.gettime(&igb->ptp_caps, &ts);
409
410 pr_debug("igb overflow check at %ld.%09lu\n", ts.tv_sec, ts.tv_nsec);
411
412 schedule_delayed_work(&igb->ptp_overflow_work,
413 IGB_SYSTIM_OVERFLOW_PERIOD);
414}
415
416
417
418
419
420
421
422
423
424
425void igb_ptp_rx_hang(struct igb_adapter *adapter)
426{
427 struct e1000_hw *hw = &adapter->hw;
428 struct igb_ring *rx_ring;
429 u32 tsyncrxctl = rd32(E1000_TSYNCRXCTL);
430 unsigned long rx_event;
431 int n;
432
433 if (hw->mac.type != e1000_82576)
434 return;
435
436
437
438
439 if (!(tsyncrxctl & E1000_TSYNCRXCTL_VALID)) {
440 adapter->last_rx_ptp_check = jiffies;
441 return;
442 }
443
444
445 rx_event = adapter->last_rx_ptp_check;
446 for (n = 0; n < adapter->num_rx_queues; n++) {
447 rx_ring = adapter->rx_ring[n];
448 if (time_after(rx_ring->last_rx_timestamp, rx_event))
449 rx_event = rx_ring->last_rx_timestamp;
450 }
451
452
453 if (time_is_before_jiffies(rx_event + 5 * HZ)) {
454 rd32(E1000_RXSTMPH);
455 adapter->last_rx_ptp_check = jiffies;
456 adapter->rx_hwtstamp_cleared++;
457 dev_warn(&adapter->pdev->dev, "clearing Rx timestamp hang");
458 }
459}
460
461
462
463
464
465
466
467
468
469void igb_ptp_tx_hwtstamp(struct igb_adapter *adapter)
470{
471 struct e1000_hw *hw = &adapter->hw;
472 struct skb_shared_hwtstamps shhwtstamps;
473 u64 regval;
474
475 regval = rd32(E1000_TXSTMPL);
476 regval |= (u64)rd32(E1000_TXSTMPH) << 32;
477
478 igb_ptp_systim_to_hwtstamp(adapter, &shhwtstamps, regval);
479 skb_tstamp_tx(adapter->ptp_tx_skb, &shhwtstamps);
480 dev_kfree_skb_any(adapter->ptp_tx_skb);
481 adapter->ptp_tx_skb = NULL;
482}
483
484
485
486
487
488
489
490
491
492
493
494void igb_ptp_rx_pktstamp(struct igb_q_vector *q_vector,
495 unsigned char *va,
496 struct sk_buff *skb)
497{
498 __le64 *regval = (__le64 *)va;
499
500
501
502
503
504 igb_ptp_systim_to_hwtstamp(q_vector->adapter, skb_hwtstamps(skb),
505 le64_to_cpu(regval[1]));
506}
507
508
509
510
511
512
513
514
515
516void igb_ptp_rx_rgtstamp(struct igb_q_vector *q_vector,
517 struct sk_buff *skb)
518{
519 struct igb_adapter *adapter = q_vector->adapter;
520 struct e1000_hw *hw = &adapter->hw;
521 u64 regval;
522
523
524
525
526
527
528
529
530
531
532
533 if (!(rd32(E1000_TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
534 return;
535
536 regval = rd32(E1000_RXSTMPL);
537 regval |= (u64)rd32(E1000_RXSTMPH) << 32;
538
539 igb_ptp_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), regval);
540}
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560int igb_ptp_hwtstamp_ioctl(struct net_device *netdev,
561 struct ifreq *ifr, int cmd)
562{
563 struct igb_adapter *adapter = netdev_priv(netdev);
564 struct e1000_hw *hw = &adapter->hw;
565 struct hwtstamp_config config;
566 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
567 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
568 u32 tsync_rx_cfg = 0;
569 bool is_l4 = false;
570 bool is_l2 = false;
571 u32 regval;
572
573 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
574 return -EFAULT;
575
576
577 if (config.flags)
578 return -EINVAL;
579
580 switch (config.tx_type) {
581 case HWTSTAMP_TX_OFF:
582 tsync_tx_ctl = 0;
583 case HWTSTAMP_TX_ON:
584 break;
585 default:
586 return -ERANGE;
587 }
588
589 switch (config.rx_filter) {
590 case HWTSTAMP_FILTER_NONE:
591 tsync_rx_ctl = 0;
592 break;
593 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
594 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
595 tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE;
596 is_l4 = true;
597 break;
598 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
599 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
600 tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE;
601 is_l4 = true;
602 break;
603 case HWTSTAMP_FILTER_PTP_V2_EVENT:
604 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
605 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
606 case HWTSTAMP_FILTER_PTP_V2_SYNC:
607 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
608 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
609 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
610 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
611 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
612 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
613 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
614 is_l2 = true;
615 is_l4 = true;
616 break;
617 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
618 case HWTSTAMP_FILTER_ALL:
619
620
621
622 if (hw->mac.type != e1000_82576) {
623 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
624 config.rx_filter = HWTSTAMP_FILTER_ALL;
625 break;
626 }
627
628 default:
629 config.rx_filter = HWTSTAMP_FILTER_NONE;
630 return -ERANGE;
631 }
632
633 if (hw->mac.type == e1000_82575) {
634 if (tsync_rx_ctl | tsync_tx_ctl)
635 return -EINVAL;
636 return 0;
637 }
638
639
640
641
642
643 if ((hw->mac.type >= e1000_82580) && tsync_rx_ctl) {
644 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
645 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
646 config.rx_filter = HWTSTAMP_FILTER_ALL;
647 is_l2 = true;
648 is_l4 = true;
649
650 if ((hw->mac.type == e1000_i210) ||
651 (hw->mac.type == e1000_i211)) {
652 regval = rd32(E1000_RXPBS);
653 regval |= E1000_RXPBS_CFG_TS_EN;
654 wr32(E1000_RXPBS, regval);
655 }
656 }
657
658
659 regval = rd32(E1000_TSYNCTXCTL);
660 regval &= ~E1000_TSYNCTXCTL_ENABLED;
661 regval |= tsync_tx_ctl;
662 wr32(E1000_TSYNCTXCTL, regval);
663
664
665 regval = rd32(E1000_TSYNCRXCTL);
666 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
667 regval |= tsync_rx_ctl;
668 wr32(E1000_TSYNCRXCTL, regval);
669
670
671 wr32(E1000_TSYNCRXCFG, tsync_rx_cfg);
672
673
674 if (is_l2)
675 wr32(E1000_ETQF(3),
676 (E1000_ETQF_FILTER_ENABLE |
677 E1000_ETQF_1588 |
678 ETH_P_1588));
679 else
680 wr32(E1000_ETQF(3), 0);
681
682
683 if (is_l4) {
684 u32 ftqf = (IPPROTO_UDP
685 | E1000_FTQF_VF_BP
686 | E1000_FTQF_1588_TIME_STAMP
687 | E1000_FTQF_MASK);
688 ftqf &= ~E1000_FTQF_MASK_PROTO_BP;
689
690 wr32(E1000_IMIR(3), htons(PTP_EV_PORT));
691 wr32(E1000_IMIREXT(3),
692 (E1000_IMIREXT_SIZE_BP | E1000_IMIREXT_CTRL_BP));
693 if (hw->mac.type == e1000_82576) {
694
695 wr32(E1000_SPQF(3), htons(PTP_EV_PORT));
696 ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP;
697 }
698 wr32(E1000_FTQF(3), ftqf);
699 } else {
700 wr32(E1000_FTQF(3), E1000_FTQF_MASK);
701 }
702 wrfl();
703
704
705 regval = rd32(E1000_TXSTMPL);
706 regval = rd32(E1000_TXSTMPH);
707 regval = rd32(E1000_RXSTMPL);
708 regval = rd32(E1000_RXSTMPH);
709
710 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
711 -EFAULT : 0;
712}
713
714void igb_ptp_init(struct igb_adapter *adapter)
715{
716 struct e1000_hw *hw = &adapter->hw;
717 struct net_device *netdev = adapter->netdev;
718
719 switch (hw->mac.type) {
720 case e1000_82576:
721 snprintf(adapter->ptp_caps.name, 16, "%pm", netdev->dev_addr);
722 adapter->ptp_caps.owner = THIS_MODULE;
723 adapter->ptp_caps.max_adj = 999999881;
724 adapter->ptp_caps.n_ext_ts = 0;
725 adapter->ptp_caps.pps = 0;
726 adapter->ptp_caps.adjfreq = igb_ptp_adjfreq_82576;
727 adapter->ptp_caps.adjtime = igb_ptp_adjtime_82576;
728 adapter->ptp_caps.gettime = igb_ptp_gettime_82576;
729 adapter->ptp_caps.settime = igb_ptp_settime_82576;
730 adapter->ptp_caps.enable = igb_ptp_enable;
731 adapter->cc.read = igb_ptp_read_82576;
732 adapter->cc.mask = CLOCKSOURCE_MASK(64);
733 adapter->cc.mult = 1;
734 adapter->cc.shift = IGB_82576_TSYNC_SHIFT;
735
736 wr32(E1000_TIMINCA, INCPERIOD_82576 | INCVALUE_82576);
737 break;
738 case e1000_82580:
739 case e1000_i354:
740 case e1000_i350:
741 snprintf(adapter->ptp_caps.name, 16, "%pm", netdev->dev_addr);
742 adapter->ptp_caps.owner = THIS_MODULE;
743 adapter->ptp_caps.max_adj = 62499999;
744 adapter->ptp_caps.n_ext_ts = 0;
745 adapter->ptp_caps.pps = 0;
746 adapter->ptp_caps.adjfreq = igb_ptp_adjfreq_82580;
747 adapter->ptp_caps.adjtime = igb_ptp_adjtime_82576;
748 adapter->ptp_caps.gettime = igb_ptp_gettime_82576;
749 adapter->ptp_caps.settime = igb_ptp_settime_82576;
750 adapter->ptp_caps.enable = igb_ptp_enable;
751 adapter->cc.read = igb_ptp_read_82580;
752 adapter->cc.mask = CLOCKSOURCE_MASK(IGB_NBITS_82580);
753 adapter->cc.mult = 1;
754 adapter->cc.shift = 0;
755
756 wr32(E1000_TSAUXC, 0x0);
757 break;
758 case e1000_i210:
759 case e1000_i211:
760 snprintf(adapter->ptp_caps.name, 16, "%pm", netdev->dev_addr);
761 adapter->ptp_caps.owner = THIS_MODULE;
762 adapter->ptp_caps.max_adj = 62499999;
763 adapter->ptp_caps.n_ext_ts = 0;
764 adapter->ptp_caps.pps = 0;
765 adapter->ptp_caps.adjfreq = igb_ptp_adjfreq_82580;
766 adapter->ptp_caps.adjtime = igb_ptp_adjtime_i210;
767 adapter->ptp_caps.gettime = igb_ptp_gettime_i210;
768 adapter->ptp_caps.settime = igb_ptp_settime_i210;
769 adapter->ptp_caps.enable = igb_ptp_enable;
770
771 wr32(E1000_TSAUXC, 0x0);
772 break;
773 default:
774 adapter->ptp_clock = NULL;
775 return;
776 }
777
778 wrfl();
779
780 spin_lock_init(&adapter->tmreg_lock);
781 INIT_WORK(&adapter->ptp_tx_work, igb_ptp_tx_work);
782
783
784 if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211)) {
785 struct timespec ts = ktime_to_timespec(ktime_get_real());
786
787 igb_ptp_settime_i210(&adapter->ptp_caps, &ts);
788 } else {
789 timecounter_init(&adapter->tc, &adapter->cc,
790 ktime_to_ns(ktime_get_real()));
791
792 INIT_DELAYED_WORK(&adapter->ptp_overflow_work,
793 igb_ptp_overflow_check);
794
795 schedule_delayed_work(&adapter->ptp_overflow_work,
796 IGB_SYSTIM_OVERFLOW_PERIOD);
797 }
798
799
800 if (hw->mac.type >= e1000_82580) {
801 wr32(E1000_TSIM, E1000_TSIM_TXTS);
802 wr32(E1000_IMS, E1000_IMS_TS);
803 }
804
805 adapter->ptp_clock = ptp_clock_register(&adapter->ptp_caps,
806 &adapter->pdev->dev);
807 if (IS_ERR(adapter->ptp_clock)) {
808 adapter->ptp_clock = NULL;
809 dev_err(&adapter->pdev->dev, "ptp_clock_register failed\n");
810 } else {
811 dev_info(&adapter->pdev->dev, "added PHC on %s\n",
812 adapter->netdev->name);
813 adapter->flags |= IGB_FLAG_PTP;
814 }
815}
816
817
818
819
820
821
822
823void igb_ptp_stop(struct igb_adapter *adapter)
824{
825 switch (adapter->hw.mac.type) {
826 case e1000_82576:
827 case e1000_82580:
828 case e1000_i354:
829 case e1000_i350:
830 cancel_delayed_work_sync(&adapter->ptp_overflow_work);
831 break;
832 case e1000_i210:
833 case e1000_i211:
834
835 break;
836 default:
837 return;
838 }
839
840 cancel_work_sync(&adapter->ptp_tx_work);
841 if (adapter->ptp_tx_skb) {
842 dev_kfree_skb_any(adapter->ptp_tx_skb);
843 adapter->ptp_tx_skb = NULL;
844 }
845
846 if (adapter->ptp_clock) {
847 ptp_clock_unregister(adapter->ptp_clock);
848 dev_info(&adapter->pdev->dev, "removed PHC on %s\n",
849 adapter->netdev->name);
850 adapter->flags &= ~IGB_FLAG_PTP;
851 }
852}
853
854
855
856
857
858
859
860void igb_ptp_reset(struct igb_adapter *adapter)
861{
862 struct e1000_hw *hw = &adapter->hw;
863
864 if (!(adapter->flags & IGB_FLAG_PTP))
865 return;
866
867 switch (adapter->hw.mac.type) {
868 case e1000_82576:
869
870 wr32(E1000_TIMINCA, INCPERIOD_82576 | INCVALUE_82576);
871 break;
872 case e1000_82580:
873 case e1000_i354:
874 case e1000_i350:
875 case e1000_i210:
876 case e1000_i211:
877
878 wr32(E1000_TSAUXC, 0x0);
879 wr32(E1000_TSIM, E1000_TSIM_TXTS);
880 wr32(E1000_IMS, E1000_IMS_TS);
881 break;
882 default:
883
884 return;
885 }
886
887
888 if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211)) {
889 struct timespec ts = ktime_to_timespec(ktime_get_real());
890
891 igb_ptp_settime_i210(&adapter->ptp_caps, &ts);
892 } else {
893 timecounter_init(&adapter->tc, &adapter->cc,
894 ktime_to_ns(ktime_get_real()));
895 }
896}
897