20 #include <linux/module.h>
21 #include <linux/device.h>
22 #include <linux/pci.h>
26 #define INCVALUE_MASK 0x7fffffff
27 #define ISGN 0x80000000
72 #define IGB_SYSTIM_OVERFLOW_PERIOD (HZ * 60 * 9)
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
92 val = ((
u64) hi) << 32;
118 val = ((
u64) hi) << 32;
183 switch (adapter->
hw.mac.type) {
191 spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
193 memset(hwtstamps, 0,
sizeof(*hwtstamps));
194 hwtstamps->
hwtstamp = ns_to_ktime(ns);
198 memset(hwtstamps, 0,
sizeof(*hwtstamps));
200 hwtstamps->
hwtstamp = ktime_set(systim >> 32,
201 systim & 0xFFFFFFFF);
227 rate = div_u64(rate, 1953125);
256 rate = div_u64(rate, 1953125);
280 spin_unlock_irqrestore(&igb->tmreg_lock, flags);
294 igb_ptp_read_i210(igb, &now);
295 now = timespec_add(now, then);
296 igb_ptp_write_i210(igb, (
const struct timespec *)&now);
298 spin_unlock_irqrestore(&igb->tmreg_lock, flags);
316 spin_unlock_irqrestore(&igb->tmreg_lock, flags);
318 ts->
tv_sec = div_u64_rem(ns, 1000000000, &remainder);
333 igb_ptp_read_i210(igb, ts);
335 spin_unlock_irqrestore(&igb->tmreg_lock, flags);
348 ns = ts->
tv_sec * 1000000000ULL;
355 spin_unlock_irqrestore(&igb->tmreg_lock, flags);
369 igb_ptp_write_i210(igb, ts);
371 spin_unlock_irqrestore(&igb->tmreg_lock, flags);
396 if (!adapter->ptp_tx_skb)
413 igb->ptp_caps.gettime(&igb->ptp_caps, &
ts);
415 pr_debug(
"igb overflow check at %ld.%09lu\n",
ts.tv_sec,
ts.tv_nsec);
438 igb_ptp_systim_to_hwtstamp(adapter, &shhwtstamps, regval);
441 adapter->ptp_tx_skb =
NULL;
480 igb_ptp_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), regval);
510 u32 tsync_rx_cfg = 0;
586 if (tsync_rx_ctl | tsync_tx_ctl)
611 regval |= tsync_tx_ctl;
617 regval |= tsync_rx_ctl;
661 return copy_to_user(ifr->ifr_data, &config,
sizeof(config)) ?
670 switch (hw->
mac.type) {
674 adapter->ptp_caps.max_adj = 1000000000;
675 adapter->ptp_caps.n_ext_ts = 0;
676 adapter->ptp_caps.pps = 0;
677 adapter->ptp_caps.adjfreq = igb_ptp_adjfreq_82576;
678 adapter->ptp_caps.adjtime = igb_ptp_adjtime_82576;
679 adapter->ptp_caps.gettime = igb_ptp_gettime_82576;
680 adapter->ptp_caps.settime = igb_ptp_settime_82576;
681 adapter->ptp_caps.enable = igb_ptp_enable;
682 adapter->cc.read = igb_ptp_read_82576;
684 adapter->cc.mult = 1;
693 adapter->ptp_caps.max_adj = 62499999;
694 adapter->ptp_caps.n_ext_ts = 0;
695 adapter->ptp_caps.pps = 0;
696 adapter->ptp_caps.adjfreq = igb_ptp_adjfreq_82580;
697 adapter->ptp_caps.adjtime = igb_ptp_adjtime_82576;
698 adapter->ptp_caps.gettime = igb_ptp_gettime_82576;
699 adapter->ptp_caps.settime = igb_ptp_settime_82576;
700 adapter->ptp_caps.enable = igb_ptp_enable;
701 adapter->cc.read = igb_ptp_read_82580;
703 adapter->cc.mult = 1;
704 adapter->cc.shift = 0;
712 adapter->ptp_caps.max_adj = 62499999;
713 adapter->ptp_caps.n_ext_ts = 0;
714 adapter->ptp_caps.pps = 0;
715 adapter->ptp_caps.adjfreq = igb_ptp_adjfreq_82580;
716 adapter->ptp_caps.adjtime = igb_ptp_adjtime_i210;
717 adapter->ptp_caps.gettime = igb_ptp_gettime_i210;
718 adapter->ptp_caps.settime = igb_ptp_settime_i210;
719 adapter->ptp_caps.enable = igb_ptp_enable;
724 adapter->ptp_clock =
NULL;
737 igb_ptp_settime_i210(&adapter->ptp_caps, &ts);
743 igb_ptp_overflow_check);
756 &adapter->
pdev->dev);
757 if (IS_ERR(adapter->ptp_clock)) {
758 adapter->ptp_clock =
NULL;
759 dev_err(&adapter->
pdev->dev,
"ptp_clock_register failed\n");
775 switch (adapter->
hw.mac.type) {
791 if (adapter->ptp_clock) {
812 switch (adapter->
hw.mac.type) {
835 igb_ptp_settime_i210(&adapter->ptp_caps, &ts);