• Jacob Keller's avatar
    ptp: introduce helpers to adjust by scaled parts per million · 1060707e
    Jacob Keller authored
    Many drivers implement the .adjfreq or .adjfine PTP op function with the
    same basic logic:
    
      1. Determine a base frequency value
      2. Multiply this by the abs() of the requested adjustment, then divide by
         the appropriate divisor (1 billion, or 65,536 billion).
      3. Add or subtract this difference from the base frequency to calculate a
         new adjustment.
    
    A few drivers need the difference and direction rather than the combined
    new increment value.
    
    I recently converted the Intel drivers to .adjfine and the scaled parts per
    million (65.536 parts per billion) logic. To avoid overflow with minimal
    loss of precision, mul_u64_u64_div_u64 was used.
    
    The basic logic used by all of these drivers is very similar, and leads to
    a lot of duplicate code to perform the same task.
    
    Rather than keep this duplicate code, introduce diff_by_scaled_ppm and
    adjust_by_scaled_ppm. These helper functions calculate the difference or
    adjustment necessary based on the scaled parts per million input.
    
    The diff_by_scaled_ppm function returns true if the difference should be
    subtracted, and false otherwise.
    
    Update the Intel drivers to use the new helper functions. Other vendor
    drivers will be converted to .adjfine and this helper function in the
    following changes.
    Signed-off-by: default avatarJacob Keller <jacob.e.keller@intel.com>
    Acked-by: default avatarRichard Cochran <richardcochran@gmail.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    1060707e
igb_ptp.c 42.1 KB