aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet
diff options
context:
space:
mode:
authorJacob Keller <jacob.e.keller@intel.com>2012-08-24 23:54:19 -0400
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>2012-10-23 00:16:13 -0400
commit1a71ab24914b45a9624335866ba00885a33f2108 (patch)
treedb77f04b24a9783f077a5dd6a41882912276ab63 /drivers/net/ethernet
parentf8a06c2ceb6b7158c2a68a407fd6b0b926b47f39 (diff)
ixgbe: (PTP) refactor init, cyclecounter and reset
This patch modifies when and where PTP registers and data are set. Previously a work-around was used inside cyclecounter_start in order to reset some of the time registers. This patch creates a new ixgbe_ptp_reset specifically for this purpose. The cyclecounter configuration has trimmed down to only modify what is necessary. Due to hardware conditions after probe and before open, PTP init has now moved into the ixgbe_open call. This allows the ptp device name in the sysfs to be the ethernet device name instead of the MAC address. The cyclecounter check flag is renamed to PTP_ENABLED and is used to prevent PTP init from happening when PTP has not been enabled. CC: Richard Cochran <richardcochran@gmail.com> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com> Tested-by: Phil Schmitt <phillip.j.schmitt@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Diffstat (limited to 'drivers/net/ethernet')
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe.h4
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_main.c26
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c109
3 files changed, 66 insertions, 73 deletions
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe.h b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
index 101e525e7fe3..c64a777b2c0b 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe.h
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
@@ -483,7 +483,7 @@ struct ixgbe_adapter {
483#define IXGBE_FLAG2_FDIR_REQUIRES_REINIT (u32)(1 << 7) 483#define IXGBE_FLAG2_FDIR_REQUIRES_REINIT (u32)(1 << 7)
484#define IXGBE_FLAG2_RSS_FIELD_IPV4_UDP (u32)(1 << 8) 484#define IXGBE_FLAG2_RSS_FIELD_IPV4_UDP (u32)(1 << 8)
485#define IXGBE_FLAG2_RSS_FIELD_IPV6_UDP (u32)(1 << 9) 485#define IXGBE_FLAG2_RSS_FIELD_IPV6_UDP (u32)(1 << 9)
486#define IXGBE_FLAG2_OVERFLOW_CHECK_ENABLED (u32)(1 << 10) 486#define IXGBE_FLAG2_PTP_ENABLED (u32)(1 << 10)
487#define IXGBE_FLAG2_PTP_PPS_ENABLED (u32)(1 << 11) 487#define IXGBE_FLAG2_PTP_PPS_ENABLED (u32)(1 << 11)
488 488
489 /* Tx fast path data */ 489 /* Tx fast path data */
@@ -581,7 +581,6 @@ struct ixgbe_adapter {
581 struct timecounter tc; 581 struct timecounter tc;
582 int rx_hwtstamp_filter; 582 int rx_hwtstamp_filter;
583 u32 base_incval; 583 u32 base_incval;
584 u32 cycle_speed;
585#endif /* CONFIG_IXGBE_PTP */ 584#endif /* CONFIG_IXGBE_PTP */
586 585
587 /* SR-IOV */ 586 /* SR-IOV */
@@ -754,6 +753,7 @@ extern void ixgbe_ptp_rx_hwtstamp(struct ixgbe_q_vector *q_vector,
754extern int ixgbe_ptp_hwtstamp_ioctl(struct ixgbe_adapter *adapter, 753extern int ixgbe_ptp_hwtstamp_ioctl(struct ixgbe_adapter *adapter,
755 struct ifreq *ifr, int cmd); 754 struct ifreq *ifr, int cmd);
756extern void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter); 755extern void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter);
756extern void ixgbe_ptp_reset(struct ixgbe_adapter *adapter);
757extern void ixgbe_ptp_check_pps_event(struct ixgbe_adapter *adapter, u32 eicr); 757extern void ixgbe_ptp_check_pps_event(struct ixgbe_adapter *adapter, u32 eicr);
758#endif /* CONFIG_IXGBE_PTP */ 758#endif /* CONFIG_IXGBE_PTP */
759 759
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index e417394a2a4e..46bf0fde1a69 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -4210,6 +4210,11 @@ void ixgbe_reset(struct ixgbe_adapter *adapter)
4210 /* update SAN MAC vmdq pool selection */ 4210 /* update SAN MAC vmdq pool selection */
4211 if (hw->mac.san_mac_rar_index) 4211 if (hw->mac.san_mac_rar_index)
4212 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); 4212 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
4213
4214#ifdef CONFIG_IXGBE_PTP
4215 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
4216 ixgbe_ptp_reset(adapter);
4217#endif
4213} 4218}
4214 4219
4215/** 4220/**
@@ -4919,6 +4924,10 @@ static int ixgbe_open(struct net_device *netdev)
4919 if (err) 4924 if (err)
4920 goto err_set_queues; 4925 goto err_set_queues;
4921 4926
4927#ifdef CONFIG_IXGBE_PTP
4928 ixgbe_ptp_init(adapter);
4929#endif /* CONFIG_IXGBE_PTP*/
4930
4922 ixgbe_up_complete(adapter); 4931 ixgbe_up_complete(adapter);
4923 4932
4924 return 0; 4933 return 0;
@@ -4950,6 +4959,10 @@ static int ixgbe_close(struct net_device *netdev)
4950{ 4959{
4951 struct ixgbe_adapter *adapter = netdev_priv(netdev); 4960 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4952 4961
4962#ifdef CONFIG_IXGBE_PTP
4963 ixgbe_ptp_stop(adapter);
4964#endif
4965
4953 ixgbe_down(adapter); 4966 ixgbe_down(adapter);
4954 ixgbe_free_irq(adapter); 4967 ixgbe_free_irq(adapter);
4955 4968
@@ -5518,7 +5531,8 @@ static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5518 } 5531 }
5519 5532
5520#ifdef CONFIG_IXGBE_PTP 5533#ifdef CONFIG_IXGBE_PTP
5521 ixgbe_ptp_start_cyclecounter(adapter); 5534 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5535 ixgbe_ptp_start_cyclecounter(adapter);
5522#endif 5536#endif
5523 5537
5524 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", 5538 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
@@ -5565,7 +5579,8 @@ static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
5565 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; 5579 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5566 5580
5567#ifdef CONFIG_IXGBE_PTP 5581#ifdef CONFIG_IXGBE_PTP
5568 ixgbe_ptp_start_cyclecounter(adapter); 5582 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5583 ixgbe_ptp_start_cyclecounter(adapter);
5569#endif 5584#endif
5570 5585
5571 e_info(drv, "NIC Link is Down\n"); 5586 e_info(drv, "NIC Link is Down\n");
@@ -7403,10 +7418,6 @@ static int __devinit ixgbe_probe(struct pci_dev *pdev,
7403 7418
7404 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); 7419 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7405 7420
7406#ifdef CONFIG_IXGBE_PTP
7407 ixgbe_ptp_init(adapter);
7408#endif /* CONFIG_IXGBE_PTP*/
7409
7410 /* save off EEPROM version number */ 7421 /* save off EEPROM version number */
7411 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh); 7422 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7412 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl); 7423 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
@@ -7544,9 +7555,6 @@ static void __devexit ixgbe_remove(struct pci_dev *pdev)
7544 set_bit(__IXGBE_DOWN, &adapter->state); 7555 set_bit(__IXGBE_DOWN, &adapter->state);
7545 cancel_work_sync(&adapter->service_task); 7556 cancel_work_sync(&adapter->service_task);
7546 7557
7547#ifdef CONFIG_IXGBE_PTP
7548 ixgbe_ptp_stop(adapter);
7549#endif
7550 7558
7551#ifdef CONFIG_IXGBE_DCA 7559#ifdef CONFIG_IXGBE_DCA
7552 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { 7560 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
index d9291316ee9f..5e71ddbb3414 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
@@ -411,7 +411,7 @@ void ixgbe_ptp_overflow_check(struct ixgbe_adapter *adapter)
411 unsigned long elapsed_jiffies = adapter->last_overflow_check - jiffies; 411 unsigned long elapsed_jiffies = adapter->last_overflow_check - jiffies;
412 struct timespec ts; 412 struct timespec ts;
413 413
414 if ((adapter->flags2 & IXGBE_FLAG2_OVERFLOW_CHECK_ENABLED) && 414 if ((adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED) &&
415 (elapsed_jiffies >= IXGBE_OVERFLOW_PERIOD)) { 415 (elapsed_jiffies >= IXGBE_OVERFLOW_PERIOD)) {
416 ixgbe_ptp_gettime(&adapter->ptp_caps, &ts); 416 ixgbe_ptp_gettime(&adapter->ptp_caps, &ts);
417 adapter->last_overflow_check = jiffies; 417 adapter->last_overflow_check = jiffies;
@@ -759,58 +759,20 @@ int ixgbe_ptp_hwtstamp_ioctl(struct ixgbe_adapter *adapter,
759 * ixgbe_ptp_start_cyclecounter - create the cycle counter from hw 759 * ixgbe_ptp_start_cyclecounter - create the cycle counter from hw
760 * @adapter: pointer to the adapter structure 760 * @adapter: pointer to the adapter structure
761 * 761 *
762 * this function initializes the timecounter and cyclecounter 762 * 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 763 * register and tell the cyclecounter structure what the tick rate of SYSTIME
764 * fixed point cycles registers in the hardware. 764 * is. It does not directly modify SYSTIME registers or the timecounter
765 * 765 * 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 766 * 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 */ 767 */
774void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter) 768void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
775{ 769{
776 struct ixgbe_hw *hw = &adapter->hw; 770 struct ixgbe_hw *hw = &adapter->hw;
777 u32 incval = 0; 771 u32 incval = 0;
778 u32 timinca = 0;
779 u32 shift = 0; 772 u32 shift = 0;
780 u32 cycle_speed;
781 unsigned long flags; 773 unsigned long flags;
782 774
783 /** 775 /**
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 776 * Scale the NIC cycle counter by a large factor so that
815 * relatively small corrections to the frequency can be added 777 * relatively small corrections to the frequency can be added
816 * or subtracted. The drawbacks of a large factor include 778 * or subtracted. The drawbacks of a large factor include
@@ -819,8 +781,12 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
819 * to nanoseconds using only a multiplier and a right-shift, 781 * to nanoseconds using only a multiplier and a right-shift,
820 * and (c) the value must fit within the timinca register space 782 * and (c) the value must fit within the timinca register space
821 * => math based on internal DMA clock rate and available bits 783 * => math based on internal DMA clock rate and available bits
784 *
785 * Note that when there is no link, internal DMA clock is same as when
786 * link speed is 10Gb. Set the registers correctly even when link is
787 * down to preserve the clock setting
822 */ 788 */
823 switch (cycle_speed) { 789 switch (adapter->link_speed) {
824 case IXGBE_LINK_SPEED_100_FULL: 790 case IXGBE_LINK_SPEED_100_FULL:
825 incval = IXGBE_INCVAL_100; 791 incval = IXGBE_INCVAL_100;
826 shift = IXGBE_INCVAL_SHIFT_100; 792 shift = IXGBE_INCVAL_SHIFT_100;
@@ -830,6 +796,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
830 shift = IXGBE_INCVAL_SHIFT_1GB; 796 shift = IXGBE_INCVAL_SHIFT_1GB;
831 break; 797 break;
832 case IXGBE_LINK_SPEED_10GB_FULL: 798 case IXGBE_LINK_SPEED_10GB_FULL:
799 default:
833 incval = IXGBE_INCVAL_10GB; 800 incval = IXGBE_INCVAL_10GB;
834 shift = IXGBE_INCVAL_SHIFT_10GB; 801 shift = IXGBE_INCVAL_SHIFT_10GB;
835 break; 802 break;
@@ -857,18 +824,11 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
857 return; 824 return;
858 } 825 }
859 826
860 /* reset the system time registers */ 827 /* 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; 828 ACCESS_ONCE(adapter->base_incval) = incval;
869 smp_mb(); 829 smp_mb();
870 830
871 /* grab the ptp lock */ 831 /* need lock to prevent incorrect read while modifying cyclecounter */
872 spin_lock_irqsave(&adapter->tmreg_lock, flags); 832 spin_lock_irqsave(&adapter->tmreg_lock, flags);
873 833
874 memset(&adapter->cc, 0, sizeof(adapter->cc)); 834 memset(&adapter->cc, 0, sizeof(adapter->cc));
@@ -877,6 +837,31 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
877 adapter->cc.shift = shift; 837 adapter->cc.shift = shift;
878 adapter->cc.mult = 1; 838 adapter->cc.mult = 1;
879 839
840 spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
841}
842
843/**
844 * ixgbe_ptp_reset
845 * @adapter: the ixgbe private board structure
846 *
847 * When the MAC resets, all timesync features are reset. This function should be
848 * called to re-enable the PTP clock structure. It will re-init the timecounter
849 * structure based on the kernel time as well as setup the cycle counter data.
850 */
851void ixgbe_ptp_reset(struct ixgbe_adapter *adapter)
852{
853 struct ixgbe_hw *hw = &adapter->hw;
854 unsigned long flags;
855
856 /* set SYSTIME registers to 0 just in case */
857 IXGBE_WRITE_REG(hw, IXGBE_SYSTIML, 0x00000000);
858 IXGBE_WRITE_REG(hw, IXGBE_SYSTIMH, 0x00000000);
859 IXGBE_WRITE_FLUSH(hw);
860
861 ixgbe_ptp_start_cyclecounter(adapter);
862
863 spin_lock_irqsave(&adapter->tmreg_lock, flags);
864
880 /* reset the ns time counter */ 865 /* reset the ns time counter */
881 timecounter_init(&adapter->tc, &adapter->cc, 866 timecounter_init(&adapter->tc, &adapter->cc,
882 ktime_to_ns(ktime_get_real())); 867 ktime_to_ns(ktime_get_real()));
@@ -904,7 +889,7 @@ void ixgbe_ptp_init(struct ixgbe_adapter *adapter)
904 889
905 switch (adapter->hw.mac.type) { 890 switch (adapter->hw.mac.type) {
906 case ixgbe_mac_X540: 891 case ixgbe_mac_X540:
907 snprintf(adapter->ptp_caps.name, 16, "%pm", netdev->dev_addr); 892 snprintf(adapter->ptp_caps.name, 16, "%s", netdev->name);
908 adapter->ptp_caps.owner = THIS_MODULE; 893 adapter->ptp_caps.owner = THIS_MODULE;
909 adapter->ptp_caps.max_adj = 250000000; 894 adapter->ptp_caps.max_adj = 250000000;
910 adapter->ptp_caps.n_alarm = 0; 895 adapter->ptp_caps.n_alarm = 0;
@@ -918,7 +903,7 @@ void ixgbe_ptp_init(struct ixgbe_adapter *adapter)
918 adapter->ptp_caps.enable = ixgbe_ptp_enable; 903 adapter->ptp_caps.enable = ixgbe_ptp_enable;
919 break; 904 break;
920 case ixgbe_mac_82599EB: 905 case ixgbe_mac_82599EB:
921 snprintf(adapter->ptp_caps.name, 16, "%pm", netdev->dev_addr); 906 snprintf(adapter->ptp_caps.name, 16, "%s", netdev->name);
922 adapter->ptp_caps.owner = THIS_MODULE; 907 adapter->ptp_caps.owner = THIS_MODULE;
923 adapter->ptp_caps.max_adj = 250000000; 908 adapter->ptp_caps.max_adj = 250000000;
924 adapter->ptp_caps.n_alarm = 0; 909 adapter->ptp_caps.n_alarm = 0;
@@ -942,11 +927,6 @@ void ixgbe_ptp_init(struct ixgbe_adapter *adapter)
942 927
943 spin_lock_init(&adapter->tmreg_lock); 928 spin_lock_init(&adapter->tmreg_lock);
944 929
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, 930 adapter->ptp_clock = ptp_clock_register(&adapter->ptp_caps,
951 &adapter->pdev->dev); 931 &adapter->pdev->dev);
952 if (IS_ERR(adapter->ptp_clock)) { 932 if (IS_ERR(adapter->ptp_clock)) {
@@ -955,6 +935,11 @@ void ixgbe_ptp_init(struct ixgbe_adapter *adapter)
955 } else 935 } else
956 e_dev_info("registered PHC device on %s\n", netdev->name); 936 e_dev_info("registered PHC device on %s\n", netdev->name);
957 937
938 ixgbe_ptp_reset(adapter);
939
940 /* set the flag that PTP has been enabled */
941 adapter->flags2 |= IXGBE_FLAG2_PTP_ENABLED;
942
958 return; 943 return;
959} 944}
960 945
@@ -967,7 +952,7 @@ void ixgbe_ptp_init(struct ixgbe_adapter *adapter)
967void ixgbe_ptp_stop(struct ixgbe_adapter *adapter) 952void ixgbe_ptp_stop(struct ixgbe_adapter *adapter)
968{ 953{
969 /* stop the overflow check task */ 954 /* stop the overflow check task */
970 adapter->flags2 &= ~(IXGBE_FLAG2_OVERFLOW_CHECK_ENABLED | 955 adapter->flags2 &= ~(IXGBE_FLAG2_PTP_ENABLED |
971 IXGBE_FLAG2_PTP_PPS_ENABLED); 956 IXGBE_FLAG2_PTP_PPS_ENABLED);
972 957
973 ixgbe_ptp_setup_sdp(adapter); 958 ixgbe_ptp_setup_sdp(adapter);