1. Jul 29, 2022
    • Jacob Keller's avatar
      i40e: convert .adjfreq to .adjfine · ccd3bf98
      Jacob Keller authored
      
      
      The i40e driver currently implements the .adjfreq handler for frequency
      adjustments. This takes the adjustment parameter in parts per billion. The
      PTP core supports .adjfine which provides an adjustment in scaled parts per
      million. This has a higher resolution and can result in more precise
      adjustments for small corrections.
      
      Convert the existing .adjfreq implementation to the newer .adjfine
      implementation. This is trivial since it just requires changing the divisor
      from 1000000000ULL to (1000000ULL << 16) in the mul_u64_u64_div_u64 call.
      
      This improves the precision of the adjustments and gets us one driver
      closer to removing the old .adjfreq support from the kernel.
      
      Signed-off-by: default avatarJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      ccd3bf98
    • Jacob Keller's avatar
      i40e: use mul_u64_u64_div_u64 for PTP frequency calculation · 3626a690
      Jacob Keller authored
      
      
      The i40e device has a different clock rate depending on the current link
      speed. This requires using a different increment rate for the PTP clock
      registers. For slower link speeds, the base increment value is larger.
      Directly multiplying the larger increment value by the parts per billion
      adjustment might overflow.
      
      To avoid this, the i40e implementation defaults to using the lower
      increment value and then multiplying the adjustment afterwards. This causes
      a loss of precision for lower link speeds.
      
      We can fix this by using mul_u64_u64_div_u64 instead of performing the
      multiplications using standard C operations. On X86, this will use special
      instructions that perform the multiplication and division with 128bit
      intermediate values. For other architectures, the fallback implementation
      will limit the loss of precision for large values. Small adjustments don't
      overflow anyways and won't lose precision at all.
      
      This allows first multiplying the base increment value and then performing
      the adjustment calculation, since we no longer fear overflowing. It also
      makes it easier to convert to the even more precise .adjfine implementation
      in a following change.
      
      Signed-off-by: default avatarJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      3626a690
    • Jacob Keller's avatar
      e1000e: convert .adjfreq to .adjfine · abab010f
      Jacob Keller authored
      
      
      The PTP implementation for the e1000e driver uses the older .adjfreq
      method. This method takes an adjustment in parts per billion. The newer
      .adjfine implementation uses scaled_ppm. The use of scaled_ppm allows for
      finer grained adjustments and is preferred over using the older
      implementation.
      
      Make use of mul_u64_u64_div_u64 in order to handle possible overflow of the
      multiplication used to calculate the desired adjustment to the hardware
      increment value.
      
      Signed-off-by: default avatarJacob Keller <jacob.e.keller@intel.com>
      Tested-by: default avatarNaama Meir <naamax.meir@linux.intel.com>
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      abab010f
    • Jacob Keller's avatar
      e1000e: remove unnecessary range check in e1000e_phc_adjfreq · ab8e8db2
      Jacob Keller authored
      
      
      The e1000e_phc_adjfreq function validates that the input delta is within
      the maximum range. This is already handled by the core PTP code and this is
      a duplicate and thus unnecessary check. It also complicates refactoring to
      use the newer .adjfine implementation, where the input is no longer
      specified in parts per billion. Remove the range validation check.
      
      Signed-off-by: default avatarJacob Keller <jacob.e.keller@intel.com>
      Tested-by: default avatarNaama Meir <naamax.meir@linux.intel.com>
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      ab8e8db2
    • Jacob Keller's avatar
      ice: implement adjfine with mul_u64_u64_div_u64 · 4488df14
      Jacob Keller authored
      
      
      The PTP frequency adjustment code needs to determine an appropriate
      adjustment given an input scaled_ppm adjustment.
      
      We calculate the adjustment to the register by multiplying the base
      (nominal) increment value by the scaled_ppm and then dividing by the
      scaled one million value.
      
      For very large adjustments, this might overflow. To avoid this, both the
      scaled_ppm and divisor values are downshifted.
      
      We can avoid that on X86 architectures by using mul_u64_u64_div_u64. This
      helper function will perform the multiplication and division with 128bit
      intermediate values. We know that scaled_ppm is never larger than the
      divisor so this operation will never result in an overflow.
      
      This improves the accuracy of the calculations for large adjustment values
      on X86. It is likely an improvement on other architectures as well because
      the default implementation of mul_u64_u64_div_u64 is smarter than the
      original approach taken in the ice code.
      
      Additionally, this implementation is easier to read, using fewer local
      variables and lines of code to implement.
      
      Signed-off-by: default avatarJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      4488df14
  2. Jul 28, 2022
  3. Jul 27, 2022