aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c')
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c164
1 files changed, 65 insertions, 99 deletions
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
index d9291316ee9f..1a751c9d09c4 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
@@ -387,6 +387,15 @@ void ixgbe_ptp_check_pps_event(struct ixgbe_adapter *adapter, u32 eicr)
387 struct ixgbe_hw *hw = &adapter->hw; 387 struct ixgbe_hw *hw = &adapter->hw;
388 struct ptp_clock_event event; 388 struct ptp_clock_event event;
389 389
390 event.type = PTP_CLOCK_PPS;
391
392 /* this check is necessary in case the interrupt was enabled via some
393 * alternative means (ex. debug_fs). Better to check here than
394 * everywhere that calls this function.
395 */
396 if (!adapter->ptp_clock)
397 return;
398
390 switch (hw->mac.type) { 399 switch (hw->mac.type) {
391 case ixgbe_mac_X540: 400 case ixgbe_mac_X540:
392 ptp_clock_event(adapter->ptp_clock, &event); 401 ptp_clock_event(adapter->ptp_clock, &event);
@@ -411,7 +420,7 @@ void ixgbe_ptp_overflow_check(struct ixgbe_adapter *adapter)
411 unsigned long elapsed_jiffies = adapter->last_overflow_check - jiffies; 420 unsigned long elapsed_jiffies = adapter->last_overflow_check - jiffies;
412 struct timespec ts; 421 struct timespec ts;
413 422
414 if ((adapter->flags2 & IXGBE_FLAG2_OVERFLOW_CHECK_ENABLED) && 423 if ((adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED) &&
415 (elapsed_jiffies >= IXGBE_OVERFLOW_PERIOD)) { 424 (elapsed_jiffies >= IXGBE_OVERFLOW_PERIOD)) {
416 ixgbe_ptp_gettime(&adapter->ptp_caps, &ts); 425 ixgbe_ptp_gettime(&adapter->ptp_caps, &ts);
417 adapter->last_overflow_check = jiffies; 426 adapter->last_overflow_check = jiffies;
@@ -554,12 +563,14 @@ void ixgbe_ptp_rx_hwtstamp(struct ixgbe_q_vector *q_vector,
554 adapter = q_vector->adapter; 563 adapter = q_vector->adapter;
555 hw = &adapter->hw; 564 hw = &adapter->hw;
556 565
566 if (likely(!ixgbe_ptp_match(skb, adapter->rx_hwtstamp_filter)))
567 return;
568
557 tsyncrxctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL); 569 tsyncrxctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
558 570
559 /* Check if we have a valid timestamp and make sure the skb should 571 /* Check if we have a valid timestamp and make sure the skb should
560 * have been timestamped */ 572 * have been timestamped */
561 if (likely(!(tsyncrxctl & IXGBE_TSYNCRXCTL_VALID) || 573 if (!(tsyncrxctl & IXGBE_TSYNCRXCTL_VALID))
562 !ixgbe_ptp_match(skb, adapter->rx_hwtstamp_filter)))
563 return; 574 return;
564 575
565 /* 576 /*
@@ -622,8 +633,7 @@ int ixgbe_ptp_hwtstamp_ioctl(struct ixgbe_adapter *adapter,
622 struct hwtstamp_config config; 633 struct hwtstamp_config config;
623 u32 tsync_tx_ctl = IXGBE_TSYNCTXCTL_ENABLED; 634 u32 tsync_tx_ctl = IXGBE_TSYNCTXCTL_ENABLED;
624 u32 tsync_rx_ctl = IXGBE_TSYNCRXCTL_ENABLED; 635 u32 tsync_rx_ctl = IXGBE_TSYNCRXCTL_ENABLED;
625 u32 tsync_rx_mtrl = 0; 636 u32 tsync_rx_mtrl = PTP_EV_PORT << 16;
626 bool is_l4 = false;
627 bool is_l2 = false; 637 bool is_l2 = false;
628 u32 regval; 638 u32 regval;
629 639
@@ -646,16 +656,15 @@ int ixgbe_ptp_hwtstamp_ioctl(struct ixgbe_adapter *adapter,
646 switch (config.rx_filter) { 656 switch (config.rx_filter) {
647 case HWTSTAMP_FILTER_NONE: 657 case HWTSTAMP_FILTER_NONE:
648 tsync_rx_ctl = 0; 658 tsync_rx_ctl = 0;
659 tsync_rx_mtrl = 0;
649 break; 660 break;
650 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: 661 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
651 tsync_rx_ctl |= IXGBE_TSYNCRXCTL_TYPE_L4_V1; 662 tsync_rx_ctl |= IXGBE_TSYNCRXCTL_TYPE_L4_V1;
652 tsync_rx_mtrl = IXGBE_RXMTRL_V1_SYNC_MSG; 663 tsync_rx_mtrl = IXGBE_RXMTRL_V1_SYNC_MSG;
653 is_l4 = true;
654 break; 664 break;
655 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: 665 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
656 tsync_rx_ctl |= IXGBE_TSYNCRXCTL_TYPE_L4_V1; 666 tsync_rx_ctl |= IXGBE_TSYNCRXCTL_TYPE_L4_V1;
657 tsync_rx_mtrl = IXGBE_RXMTRL_V1_DELAY_REQ_MSG; 667 tsync_rx_mtrl = IXGBE_RXMTRL_V1_DELAY_REQ_MSG;
658 is_l4 = true;
659 break; 668 break;
660 case HWTSTAMP_FILTER_PTP_V2_EVENT: 669 case HWTSTAMP_FILTER_PTP_V2_EVENT:
661 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: 670 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
@@ -668,7 +677,6 @@ int ixgbe_ptp_hwtstamp_ioctl(struct ixgbe_adapter *adapter,
668 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: 677 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
669 tsync_rx_ctl |= IXGBE_TSYNCRXCTL_TYPE_EVENT_V2; 678 tsync_rx_ctl |= IXGBE_TSYNCRXCTL_TYPE_EVENT_V2;
670 is_l2 = true; 679 is_l2 = true;
671 is_l4 = true;
672 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; 680 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
673 break; 681 break;
674 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: 682 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
@@ -693,42 +701,15 @@ int ixgbe_ptp_hwtstamp_ioctl(struct ixgbe_adapter *adapter,
693 /* Store filter value for later use */ 701 /* Store filter value for later use */
694 adapter->rx_hwtstamp_filter = config.rx_filter; 702 adapter->rx_hwtstamp_filter = config.rx_filter;
695 703
696 /* define ethertype filter for timestamped packets */ 704 /* define ethertype filter for timestamping L2 packets */
697 if (is_l2) 705 if (is_l2)
698 IXGBE_WRITE_REG(hw, IXGBE_ETQF(3), 706 IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588),
699 (IXGBE_ETQF_FILTER_EN | /* enable filter */ 707 (IXGBE_ETQF_FILTER_EN | /* enable filter */
700 IXGBE_ETQF_1588 | /* enable timestamping */ 708 IXGBE_ETQF_1588 | /* enable timestamping */
701 ETH_P_1588)); /* 1588 eth protocol type */ 709 ETH_P_1588)); /* 1588 eth protocol type */
702 else 710 else
703 IXGBE_WRITE_REG(hw, IXGBE_ETQF(3), 0); 711 IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588), 0);
704
705#define PTP_PORT 319
706 /* L4 Queue Filter[3]: filter by destination port and protocol */
707 if (is_l4) {
708 u32 ftqf = (IXGBE_FTQF_PROTOCOL_UDP /* UDP */
709 | IXGBE_FTQF_POOL_MASK_EN /* Pool not compared */
710 | IXGBE_FTQF_QUEUE_ENABLE);
711
712 ftqf |= ((IXGBE_FTQF_PROTOCOL_COMP_MASK /* protocol check */
713 & IXGBE_FTQF_DEST_PORT_MASK /* dest check */
714 & IXGBE_FTQF_SOURCE_PORT_MASK) /* source check */
715 << IXGBE_FTQF_5TUPLE_MASK_SHIFT);
716 712
717 IXGBE_WRITE_REG(hw, IXGBE_L34T_IMIR(3),
718 (3 << IXGBE_IMIR_RX_QUEUE_SHIFT_82599 |
719 IXGBE_IMIR_SIZE_BP_82599));
720
721 /* enable port check */
722 IXGBE_WRITE_REG(hw, IXGBE_SDPQF(3),
723 (htons(PTP_PORT) |
724 htons(PTP_PORT) << 16));
725
726 IXGBE_WRITE_REG(hw, IXGBE_FTQF(3), ftqf);
727
728 tsync_rx_mtrl |= PTP_PORT << 16;
729 } else {
730 IXGBE_WRITE_REG(hw, IXGBE_FTQF(3), 0);
731 }
732 713
733 /* enable/disable TX */ 714 /* enable/disable TX */
734 regval = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL); 715 regval = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
@@ -759,58 +740,20 @@ int ixgbe_ptp_hwtstamp_ioctl(struct ixgbe_adapter *adapter,
759 * ixgbe_ptp_start_cyclecounter - create the cycle counter from hw 740 * ixgbe_ptp_start_cyclecounter - create the cycle counter from hw
760 * @adapter: pointer to the adapter structure 741 * @adapter: pointer to the adapter structure
761 * 742 *
762 * this function initializes the timecounter and cyclecounter 743 * This function should be called to set the proper values for the TIMINCA
763 * structures for use in generated a ns counter from the arbitrary 744 * register and tell the cyclecounter structure what the tick rate of SYSTIME
764 * fixed point cycles registers in the hardware. 745 * is. It does not directly modify SYSTIME registers or the timecounter
765 * 746 * structure. It should be called whenever a new TIMINCA value is necessary,
766 * A change in link speed impacts the frequency of the DMA clock on 747 * such as during initialization or when the link speed changes.
767 * the device, which is used to generate the cycle counter
768 * registers. Therefor this function is called whenever the link speed
769 * changes.
770 *
771 * This function also turns on the SDP pin for clock out feature (X540
772 * only), because this is where the shift is first calculated.
773 */ 748 */
774void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter) 749void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
775{ 750{
776 struct ixgbe_hw *hw = &adapter->hw; 751 struct ixgbe_hw *hw = &adapter->hw;
777 u32 incval = 0; 752 u32 incval = 0;
778 u32 timinca = 0;
779 u32 shift = 0; 753 u32 shift = 0;
780 u32 cycle_speed;
781 unsigned long flags; 754 unsigned long flags;
782 755
783 /** 756 /**
784 * Determine what speed we need to set the cyclecounter
785 * for. It should be different for 100Mb, 1Gb, and 10Gb. Treat
786 * unknown speeds as 10Gb. (Hence why we can't just copy the
787 * link_speed.
788 */
789 switch (adapter->link_speed) {
790 case IXGBE_LINK_SPEED_100_FULL:
791 case IXGBE_LINK_SPEED_1GB_FULL:
792 case IXGBE_LINK_SPEED_10GB_FULL:
793 cycle_speed = adapter->link_speed;
794 break;
795 default:
796 /* cycle speed should be 10Gb when there is no link */
797 cycle_speed = IXGBE_LINK_SPEED_10GB_FULL;
798 break;
799 }
800
801 /*
802 * grab the current TIMINCA value from the register so that it can be
803 * double checked. If the register value has been cleared, it must be
804 * reset to the correct value for generating a cyclecounter. If
805 * TIMINCA is zero, the SYSTIME registers do not increment at all.
806 */
807 timinca = IXGBE_READ_REG(hw, IXGBE_TIMINCA);
808
809 /* Bail if the cycle speed didn't change and TIMINCA is non-zero */
810 if (adapter->cycle_speed == cycle_speed && timinca)
811 return;
812
813 /**
814 * Scale the NIC cycle counter by a large factor so that 757 * Scale the NIC cycle counter by a large factor so that
815 * relatively small corrections to the frequency can be added 758 * relatively small corrections to the frequency can be added
816 * or subtracted. The drawbacks of a large factor include 759 * or subtracted. The drawbacks of a large factor include
@@ -819,8 +762,12 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
819 * to nanoseconds using only a multiplier and a right-shift, 762 * to nanoseconds using only a multiplier and a right-shift,
820 * and (c) the value must fit within the timinca register space 763 * and (c) the value must fit within the timinca register space
821 * => math based on internal DMA clock rate and available bits 764 * => math based on internal DMA clock rate and available bits
765 *
766 * Note that when there is no link, internal DMA clock is same as when
767 * link speed is 10Gb. Set the registers correctly even when link is
768 * down to preserve the clock setting
822 */ 769 */
823 switch (cycle_speed) { 770 switch (adapter->link_speed) {
824 case IXGBE_LINK_SPEED_100_FULL: 771 case IXGBE_LINK_SPEED_100_FULL:
825 incval = IXGBE_INCVAL_100; 772 incval = IXGBE_INCVAL_100;
826 shift = IXGBE_INCVAL_SHIFT_100; 773 shift = IXGBE_INCVAL_SHIFT_100;
@@ -830,6 +777,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
830 shift = IXGBE_INCVAL_SHIFT_1GB; 777 shift = IXGBE_INCVAL_SHIFT_1GB;
831 break; 778 break;
832 case IXGBE_LINK_SPEED_10GB_FULL: 779 case IXGBE_LINK_SPEED_10GB_FULL:
780 default:
833 incval = IXGBE_INCVAL_10GB; 781 incval = IXGBE_INCVAL_10GB;
834 shift = IXGBE_INCVAL_SHIFT_10GB; 782 shift = IXGBE_INCVAL_SHIFT_10GB;
835 break; 783 break;
@@ -857,18 +805,11 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
857 return; 805 return;
858 } 806 }
859 807
860 /* reset the system time registers */ 808 /* update the base incval used to calculate frequency adjustment */
861 IXGBE_WRITE_REG(hw, IXGBE_SYSTIML, 0x00000000);
862 IXGBE_WRITE_REG(hw, IXGBE_SYSTIMH, 0x00000000);
863 IXGBE_WRITE_FLUSH(hw);
864
865 /* store the new cycle speed */
866 adapter->cycle_speed = cycle_speed;
867
868 ACCESS_ONCE(adapter->base_incval) = incval; 809 ACCESS_ONCE(adapter->base_incval) = incval;
869 smp_mb(); 810 smp_mb();
870 811
871 /* grab the ptp lock */ 812 /* need lock to prevent incorrect read while modifying cyclecounter */
872 spin_lock_irqsave(&adapter->tmreg_lock, flags); 813 spin_lock_irqsave(&adapter->tmreg_lock, flags);
873 814
874 memset(&adapter->cc, 0, sizeof(adapter->cc)); 815 memset(&adapter->cc, 0, sizeof(adapter->cc));
@@ -877,6 +818,31 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
877 adapter->cc.shift = shift; 818 adapter->cc.shift = shift;
878 adapter->cc.mult = 1; 819 adapter->cc.mult = 1;
879 820
821 spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
822}
823
824/**
825 * ixgbe_ptp_reset
826 * @adapter: the ixgbe private board structure
827 *
828 * When the MAC resets, all timesync features are reset. This function should be
829 * called to re-enable the PTP clock structure. It will re-init the timecounter
830 * structure based on the kernel time as well as setup the cycle counter data.
831 */
832void ixgbe_ptp_reset(struct ixgbe_adapter *adapter)
833{
834 struct ixgbe_hw *hw = &adapter->hw;
835 unsigned long flags;
836
837 /* set SYSTIME registers to 0 just in case */
838 IXGBE_WRITE_REG(hw, IXGBE_SYSTIML, 0x00000000);
839 IXGBE_WRITE_REG(hw, IXGBE_SYSTIMH, 0x00000000);
840 IXGBE_WRITE_FLUSH(hw);
841
842 ixgbe_ptp_start_cyclecounter(adapter);
843
844 spin_lock_irqsave(&adapter->tmreg_lock, flags);
845
880 /* reset the ns time counter */ 846 /* reset the ns time counter */
881 timecounter_init(&adapter->tc, &adapter->cc, 847 timecounter_init(&adapter->tc, &adapter->cc,
882 ktime_to_ns(ktime_get_real())); 848 ktime_to_ns(ktime_get_real()));
@@ -904,7 +870,7 @@ void ixgbe_ptp_init(struct ixgbe_adapter *adapter)
904 870
905 switch (adapter->hw.mac.type) { 871 switch (adapter->hw.mac.type) {
906 case ixgbe_mac_X540: 872 case ixgbe_mac_X540:
907 snprintf(adapter->ptp_caps.name, 16, "%pm", netdev->dev_addr); 873 snprintf(adapter->ptp_caps.name, 16, "%s", netdev->name);
908 adapter->ptp_caps.owner = THIS_MODULE; 874 adapter->ptp_caps.owner = THIS_MODULE;
909 adapter->ptp_caps.max_adj = 250000000; 875 adapter->ptp_caps.max_adj = 250000000;
910 adapter->ptp_caps.n_alarm = 0; 876 adapter->ptp_caps.n_alarm = 0;
@@ -918,7 +884,7 @@ void ixgbe_ptp_init(struct ixgbe_adapter *adapter)
918 adapter->ptp_caps.enable = ixgbe_ptp_enable; 884 adapter->ptp_caps.enable = ixgbe_ptp_enable;
919 break; 885 break;
920 case ixgbe_mac_82599EB: 886 case ixgbe_mac_82599EB:
921 snprintf(adapter->ptp_caps.name, 16, "%pm", netdev->dev_addr); 887 snprintf(adapter->ptp_caps.name, 16, "%s", netdev->name);
922 adapter->ptp_caps.owner = THIS_MODULE; 888 adapter->ptp_caps.owner = THIS_MODULE;
923 adapter->ptp_caps.max_adj = 250000000; 889 adapter->ptp_caps.max_adj = 250000000;
924 adapter->ptp_caps.n_alarm = 0; 890 adapter->ptp_caps.n_alarm = 0;
@@ -942,11 +908,6 @@ void ixgbe_ptp_init(struct ixgbe_adapter *adapter)
942 908
943 spin_lock_init(&adapter->tmreg_lock); 909 spin_lock_init(&adapter->tmreg_lock);
944 910
945 ixgbe_ptp_start_cyclecounter(adapter);
946
947 /* (Re)start the overflow check */
948 adapter->flags2 |= IXGBE_FLAG2_OVERFLOW_CHECK_ENABLED;
949
950 adapter->ptp_clock = ptp_clock_register(&adapter->ptp_caps, 911 adapter->ptp_clock = ptp_clock_register(&adapter->ptp_caps,
951 &adapter->pdev->dev); 912 &adapter->pdev->dev);
952 if (IS_ERR(adapter->ptp_clock)) { 913 if (IS_ERR(adapter->ptp_clock)) {
@@ -955,6 +916,11 @@ void ixgbe_ptp_init(struct ixgbe_adapter *adapter)
955 } else 916 } else
956 e_dev_info("registered PHC device on %s\n", netdev->name); 917 e_dev_info("registered PHC device on %s\n", netdev->name);
957 918
919 ixgbe_ptp_reset(adapter);
920
921 /* set the flag that PTP has been enabled */
922 adapter->flags2 |= IXGBE_FLAG2_PTP_ENABLED;
923
958 return; 924 return;
959} 925}
960 926
@@ -967,7 +933,7 @@ void ixgbe_ptp_init(struct ixgbe_adapter *adapter)
967void ixgbe_ptp_stop(struct ixgbe_adapter *adapter) 933void ixgbe_ptp_stop(struct ixgbe_adapter *adapter)
968{ 934{
969 /* stop the overflow check task */ 935 /* stop the overflow check task */
970 adapter->flags2 &= ~(IXGBE_FLAG2_OVERFLOW_CHECK_ENABLED | 936 adapter->flags2 &= ~(IXGBE_FLAG2_PTP_ENABLED |
971 IXGBE_FLAG2_PTP_PPS_ENABLED); 937 IXGBE_FLAG2_PTP_PPS_ENABLED);
972 938
973 ixgbe_ptp_setup_sdp(adapter); 939 ixgbe_ptp_setup_sdp(adapter);