1. 09 12月, 2022 14 次提交
    • J
      ice: reschedule ice_ptp_wait_for_offset_valid during reset · 95af1f1c
      Jacob Keller 提交于
      If the ice_ptp_wait_for_offest_valid function is scheduled to run while the
      driver is resetting, it will exit without completing calibration. The work
      function gets scheduled by ice_ptp_port_phy_restart which will be called as
      part of the reset recovery process.
      
      It is possible for the first execution to occur before the driver has
      completely cleared its resetting flags. Ensure calibration completes by
      rescheduling the task until reset is fully completed.
      Reported-by: NSiddaraju DH <siddaraju.dh@intel.com>
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      95af1f1c
    • S
      ice: make Tx and Rx vernier offset calibration independent · f029a343
      Siddaraju DH 提交于
      The Tx and Rx calibration and timestamp generation blocks are independent.
      However, the ice driver waits until both blocks are ready before
      configuring either block.
      
      This can result in delay of configuring one block because we have not yet
      received a packet in the other block.
      
      There is no reason to wait to finish programming Tx just because we haven't
      received a packet. Similarly there is no reason to wait to program Rx just
      because we haven't transmitted a packet.
      
      Instead of checking both offset status before programming either block,
      refactor the ice_phy_cfg_tx_offset_e822 and ice_phy_cfg_rx_offset_e822
      functions so that they perform their own offset status checks.
      Additionally, make them also check the offset ready bit to determine if
      the offset values have already been programmed.
      
      Call the individual configure functions directly in
      ice_ptp_wait_for_offset_valid. The functions will now correctly check
      status, and program the offsets if ready. Once the offset is programmed,
      the functions will exit quickly after just checking the offset ready
      register.
      
      Remove the ice_phy_calc_vernier_e822 in ice_ptp_hw.c, as well as the offset
      valid check functions in ice_ptp.c entirely as they are no longer
      necessary.
      
      With this change, the Tx and Rx blocks will each be enabled as soon as
      possible without waiting for the other block to complete calibration. This
      can enable timestamps faster in setups which have a low rate of transmitted
      or received packets. In particular, it can stop a situation where one port
      never receives traffic, and thus never finishes calibration of the Tx
      block, resulting in continuous faults reported by the ptp4l daemon
      application.
      Signed-off-by: NSiddaraju DH <siddaraju.dh@intel.com>
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      f029a343
    • J
      ice: only check set bits in ice_ptp_flush_tx_tracker · e3ba5248
      Jacob Keller 提交于
      The ice_ptp_flush_tx_tracker function is called to clear all outstanding Tx
      timestamp requests when the port is being brought down. This function
      iterates over the entire list, but this is unnecessary. We only need to
      check the bits which are actually set in the ready bitmap.
      
      Replace this logic with for_each_set_bit, and follow a similar flow as in
      ice_ptp_tx_tstamp_cleanup. Note that it is safe to call dev_kfree_skb_any
      on a NULL pointer as it will perform a no-op so we do not need to verify
      that the skb is actually NULL.
      
      The new implementation also avoids clearing (and thus reading!) the PHY
      timestamp unless the index is marked as having a valid timestamp in the
      timestamp status bitmap. This ensures that we properly clear the status
      registers as appropriate.
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      e3ba5248
    • J
      ice: handle flushing stale Tx timestamps in ice_ptp_tx_tstamp · d40fd600
      Jacob Keller 提交于
      In the event of a PTP clock time change due to .adjtime or .settime, the
      ice driver needs to update the cached copy of the PHC time and also discard
      any outstanding Tx timestamps.
      
      This is required because otherwise the wrong copy of the PHC time will be
      used when extending the Tx timestamp. This could result in reporting
      incorrect timestamps to the stack.
      
      The current approach taken to handle this is to call
      ice_ptp_flush_tx_tracker, which will discard any timestamps which are not
      yet complete.
      
      This is problematic for two reasons:
      
      1) it could lead to a potential race condition where the wrong timestamp is
         associated with a future packet.
      
         This can occur with the following flow:
      
         1. Thread A gets request to transmit a timestamped packet, and picks an
            index and transmits the packet
      
         2. Thread B calls ice_ptp_flush_tx_tracker and sees the index in use,
            marking is as disarded. No timestamp read occurs because the status
            bit is not set, but the index is released for re-use
      
         3. Thread A gets a new request to transmit another timestamped packet,
            picks the same (now unused) index and transmits that packet.
      
         4. The PHY transmits the first packet and updates the timestamp slot and
            generates an interrupt.
      
         5. The ice_ptp_tx_tstamp thread executes and sees the interrupt and a
            valid timestamp but associates it with the new Tx SKB and not the one
            that actual timestamp for the packet as expected.
      
         This could result in the previous timestamp being assigned to a new
         packet producing incorrect timestamps and leading to incorrect behavior
         in PTP applications.
      
         This is most likely to occur when the packet rate for Tx timestamp
         requests is very high.
      
      2) on E822 hardware, we must avoid reading a timestamp index more than once
         each time its status bit is set and an interrupt is generated by
         hardware.
      
         We do have some extensive checks for the unread flag to ensure that only
         one of either the ice_ptp_flush_tx_tracker or ice_ptp_tx_tstamp threads
         read the timestamp. However, even with this we can still have cases
         where we "flush" a timestamp that was actually completed in hardware.
         This can lead to cases where we don't read the timestamp index as
         appropriate.
      
      To fix both of these issues, we must avoid calling ice_ptp_flush_tx_tracker
      outside of the teardown path.
      
      Rather than using ice_ptp_flush_tx_tracker, introduce a new state bitmap,
      the stale bitmap. Start this as cleared when we begin a new timestamp
      request. When we're about to extend a timestamp and send it up to the
      stack, first check to see if that stale bit was set. If so, drop the
      timestamp without sending it to the stack.
      
      When we need to update the cached PHC timestamp out of band, just mark all
      currently outstanding timestamps as stale. This will ensure that once
      hardware completes the timestamp we'll ignore it correctly and avoid
      reporting bogus timestamps to userspace.
      
      With this change, we fix potential issues caused  by calling
      ice_ptp_flush_tx_tracker during normal operation.
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      d40fd600
    • J
      ice: cleanup allocations in ice_ptp_alloc_tx_tracker · c1f3414d
      Jacob Keller 提交于
      The ice_ptp_alloc_tx_tracker function must allocate the timestamp array and
      the bitmap for tracking the currently in use indexes. A future change is
      going to add yet another allocation to this function.
      
      If these allocations fail we need to ensure that we properly cleanup and
      ensure that the pointers in the ice_ptp_tx structure are NULL.
      
      Simplify this logic by allocating to local variables first. If any
      allocation fails, then free everything and exit. Only update the ice_ptp_tx
      structure if all allocations succeed.
      
      This ensures that we have no side effects on the Tx structure unless all
      allocations have succeeded. Thus, no code will see an invalid pointer and
      we don't need to re-assign NULL on cleanup.
      
      This is safe because kernel "free" functions are designed to be NULL safe
      and perform no action if passed a NULL pointer. Thus its safe to simply
      always call kfree or bitmap_free even if one of those pointers was NULL.
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      c1f3414d
    • J
      ice: protect init and calibrating check in ice_ptp_request_ts · 3ad5c10b
      Jacob Keller 提交于
      When requesting a new timestamp, the ice_ptp_request_ts function does not
      hold the Tx tracker lock while checking init and calibrating. This means
      that we might issue a new timestamp request just after the Tx timestamp
      tracker starts being deinitialized. This could lead to incorrect access of
      the timestamp structures. Correct this by moving the init and calibrating
      checks under the lock, and updating the flows which modify these fields to
      use the lock.
      
      Note that we do not need to hold the lock while checking for tx->init in
      ice_ptp_tx_tstamp. This is because the teardown function will use
      synchronize_irq after clearing the flag to ensure that the threaded
      interrupt completes. Either a) the tx->init flag will be cleared before the
      ice_ptp_tx_tstamp function starts, thus it will exit immediately, or b) the
      threaded interrupt will be executing and the synchronize_irq will wait
      until the threaded interrupt has completed at which point we know the init
      field has definitely been set and new interrupts will not execute the Tx
      timestamp thread function.
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      3ad5c10b
    • J
      ice: synchronize the misc IRQ when tearing down Tx tracker · f0ae1240
      Jacob Keller 提交于
      Since commit 1229b339 ("ice: Add low latency Tx timestamp read") the
      ice driver has used a threaded IRQ for handling Tx timestamps. This change
      did not add a call to synchronize_irq during ice_ptp_release_tx_tracker.
      Thus it is possible that an interrupt could occur just as the tracker is
      being removed. This could lead to a use-after-free of the Tx tracker
      structure data.
      
      Fix this by calling sychronize_irq in ice_ptp_release_tx_tracker after
      we've cleared the init flag. In addition, make sure that we re-check the
      init flag at the end of ice_ptp_tx_tstamp before we exit ensuring that we
      will stop polling for new timestamps once the tracker de-initialization has
      begun.
      
      Refactor the ts_handled variable into "more_timestamps" so that we can
      simply directly assign this boolean instead of relying on an initialized
      value of true. This makes the new combined check easier to read.
      
      With this change, the ice_ptp_release_tx_tracker function will now wait for
      the threaded interrupt to complete if it was executing while the init flag
      was cleared.
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      f0ae1240
    • J
      ice: check Tx timestamp memory register for ready timestamps · 10e4b4a3
      Jacob Keller 提交于
      The PHY for E822 based hardware has a register which indicates which
      timestamps are valid in the PHY timestamp memory block. Each bit in the
      register indicates whether the associated index in the timestamp memory is
      valid.
      
      Hardware sets this bit when the timestamp is captured, and clears the bit
      when the timestamp is read. Use of this register is important as reading
      timestamp registers can impact the way that hardware generates timestamp
      interrupts.
      
      This occurs because the PHY has an internal value which is incremented
      when hardware captures a timestamp and decremented when software reads a
      timestamp. Reading timestamps which are not marked as valid still decrement
      the internal value and can result in the Tx timestamp interrupt not
      triggering in the future.
      
      To prevent this, use the timestamp memory value to determine which
      timestamps are ready to be read. The ice_get_phy_tx_tstamp_ready function
      reads this value. For E810 devices, this just always returns with all bits
      set.
      
      Skip any timestamp which is not set in this bitmap, avoiding reading extra
      timestamps on E822 devices.
      
      The stale check against a cached timestamp value is no longer necessary for
      PHYs which support the timestamp ready bitmap properly. E810 devices still
      need this. Introduce a new verify_cached flag to the ice_ptp_tx structure.
      Use this to determine if we need to perform the verification against the
      cached timestamp value. Set this to 1 for the E810 Tx tracker init
      function. Notice that many of the fields in ice_ptp_tx are simple 1 bit
      flags. Save some structure space by using bitfields of length 1 for these
      values.
      
      Modify the ICE_PTP_TS_VALID check to simply drop the timestamp immediately
      so that in an event of getting such an invalid timestamp the driver does
      not attempt to re-read the timestamp again in a future poll of the
      register.
      
      With these changes, the driver now reads each timestamp register exactly
      once, and does not attempt any re-reads. This ensures the interrupt
      tracking logic in the PHY will not get stuck.
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      10e4b4a3
    • J
      ice: handle discarding old Tx requests in ice_ptp_tx_tstamp · 0dd92862
      Jacob Keller 提交于
      Currently the driver uses the PTP kthread to process handling and
      discarding of stale Tx timestamp requests. The function
      ice_ptp_tx_tstamp_cleanup is used for this.
      
      A separate thread creates complications for the driver as we now have both
      the main Tx timestamp processing IRQ checking timestamps as well as the
      kthread.
      
      Rather than using the kthread to handle this, simply check for stale
      timestamps within the ice_ptp_tx_tstamp function. This function must
      already process the timestamps anyways.
      
      If a Tx timestamp has been waiting for 2 seconds we simply clear the bit
      and discard the SKB. This avoids the complication of having separate
      threads polling, reducing overall CPU work.
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      0dd92862
    • J
      ice: always call ice_ptp_link_change and make it void · 6b1ff5d3
      Jacob Keller 提交于
      The ice_ptp_link_change function is currently only called for E822 based
      hardware. Future changes are going to extend this function to perform
      additional tasks on link change.
      
      Always call this function, moving the E810 check from the callers down to
      just before we call the E822-specific function required to restart the PHY.
      
      This function also returns an error value, but none of the callers actually
      check it. In general, the errors it produces are more likely systemic
      problems such as invalid or corrupt port numbers. No caller checks these,
      and so no warning is logged.
      
      Re-order the flag checks so that ICE_FLAG_PTP is checked first. Drop the
      unnecessary check for ICE_FLAG_PTP_SUPPORTED, as ICE_FLAG_PTP will not be
      set except when ICE_FLAG_PTP_SUPPORTED is set.
      
      Convert the port checks to WARN_ON_ONCE, in order to generate a kernel
      stack trace when they are hit.
      
      Convert the function to void since no caller actually checks these return
      values.
      Co-developed-by: NDave Ertman <david.m.ertman@intel.com>
      Signed-off-by: NDave Ertman <david.m.ertman@intel.com>
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      6b1ff5d3
    • J
      ice: fix misuse of "link err" with "link status" · 11722c39
      Jacob Keller 提交于
      The ice_ptp_link_change function has a comment which mentions "link
      err" when referring to the current link status. We are storing the status
      of whether link is up or down, which is not an error.
      
      It is appears that this use of err accidentally got included due to an
      overzealous search and replace when removing the ice_status enum and local
      status variable.
      
      Fix the wording to use the correct term.
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      11722c39
    • K
      ice: Reset TS memory for all quads · 407b66c0
      Karol Kolacinski 提交于
      In E822 products, the owner PF should reset memory for all quads, not
      only for the one where assigned lport is.
      Signed-off-by: NKarol Kolacinski <karol.kolacinski@intel.com>
      Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      407b66c0
    • M
      ice: Remove the E822 vernier "bypass" logic · 0357d5ca
      Milena Olech 提交于
      The E822 devices support an extended "vernier" calibration which enables
      higher precision timestamps by accounting for delays in the PHY, and
      compensating for them. These delays are measured by hardware as part of its
      vernier calibration logic.
      
      The driver currently starts the PHY in "bypass" mode which skips
      the compensation. Then it later attempts to switch from bypass to vernier.
      This unfortunately does not work as expected. Instead of properly
      compensating for the delays, the hardware continues operating in bypass
      without the improved precision expected.
      
      Because we cannot dynamically switch between bypass and vernier mode,
      refactor the driver to always operate in vernier mode. This has a slight
      downside: Tx timestamp and Rx timestamp requests that occur as the very
      first packet set after link up will not complete properly and may be
      reported to applications as missing timestamps.
      
      This occurs frequently in test environments where traffic is light or
      targeted specifically at testing PTP. However, in practice most
      environments will have transmitted or received some data over the network
      before such initial requests are made.
      Signed-off-by: NMilena Olech <milena.olech@intel.com>
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      0357d5ca
    • S
      ice: Use more generic names for ice_ptp_tx fields · 6b5cbc8c
      Sergey Temerkhanov 提交于
      Some supported devices have per-port timestamp memory blocks while
      others have shared ones within quads. Rename the struct ice_ptp_tx
      fields to reflect the block entities it works with
      Signed-off-by: NSergey Temerkhanov <sergey.temerkhanov@intel.com>
      Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      6b5cbc8c
  2. 22 11月, 2022 1 次提交
    • J
      ice: fix handling of burst Tx timestamps · 30f15874
      Jacob Keller 提交于
      Commit 1229b339 ("ice: Add low latency Tx timestamp read") refactored
      PTP timestamping logic to use a threaded IRQ instead of a separate kthread.
      
      This implementation introduced ice_misc_intr_thread_fn and redefined the
      ice_ptp_process_ts function interface to return a value of whether or not
      the timestamp processing was complete.
      
      ice_misc_intr_thread_fn would take the return value from ice_ptp_process_ts
      and convert it into either IRQ_HANDLED if there were no more timestamps to
      be processed, or IRQ_WAKE_THREAD if the thread should continue processing.
      
      This is not correct, as the kernel does not re-schedule threaded IRQ
      functions automatically. IRQ_WAKE_THREAD can only be used by the main IRQ
      function.
      
      This results in the ice_ptp_process_ts function (and in turn the
      ice_ptp_tx_tstamp function) from only being called exactly once per
      interrupt.
      
      If an application sends a burst of Tx timestamps without waiting for a
      response, the interrupt will trigger for the first timestamp. However,
      later timestamps may not have arrived yet. This can result in dropped or
      discarded timestamps. Worse, on E822 hardware this results in the interrupt
      logic getting stuck such that no future interrupts will be triggered. The
      result is complete loss of Tx timestamp functionality.
      
      Fix this by modifying the ice_misc_intr_thread_fn to perform its own
      polling of the ice_ptp_process_ts function. We sleep for a few microseconds
      between attempts to avoid wasting significant CPU time. The value was
      chosen to allow time for the Tx timestamps to complete without wasting so
      much time that we overrun application wait budgets in the worst case.
      
      The ice_ptp_process_ts function also currently returns false in the event
      that the Tx tracker is not initialized. This would result in the threaded
      IRQ handler never exiting if it gets started while the tracker is not
      initialized.
      
      Fix the function to appropriately return true when the tracker is not
      initialized.
      
      Note that this will not reproduce with default ptp4l behavior, as the
      program always synchronously waits for a timestamp response before sending
      another timestamp request.
      Reported-by: NSiddaraju DH <siddaraju.dh@intel.com>
      Fixes: 1229b339 ("ice: Add low latency Tx timestamp read")
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      Link: https://lore.kernel.org/r/20221118222729.1565317-1-anthony.l.nguyen@intel.comSigned-off-by: NJakub Kicinski <kuba@kernel.org>
      30f15874
  3. 31 10月, 2022 1 次提交
    • J
      ptp: introduce helpers to adjust by scaled parts per million · 1060707e
      Jacob Keller 提交于
      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: NJacob Keller <jacob.e.keller@intel.com>
      Acked-by: NRichard Cochran <richardcochran@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      1060707e
  4. 29 9月, 2022 1 次提交
  5. 21 9月, 2022 1 次提交
  6. 07 9月, 2022 1 次提交
  7. 17 8月, 2022 4 次提交
    • J
      ice: introduce ice_ptp_reset_cached_phctime function · b1a582e6
      Jacob Keller 提交于
      If the PTP hardware clock is adjusted, the ice driver must update the
      cached PHC timestamp. This is required in order to perform timestamp
      extension on the shorter timestamps captured by the PHY.
      
      Currently, we simply call ice_ptp_update_cached_phctime in the settime and
      adjtime callbacks. This has a few issues:
      
      1) if ICE_CFG_BUSY is set because another thread is updating the Rx rings,
         we will exit with an error. This is not checked, and the functions do
         not re-schedule the update. This could leave the cached timestamp
         incorrect until the next scheduled work item execution.
      
      2) even if we did handle an update, any currently outstanding Tx timestamp
         would be extended using the wrong cached PHC time. This would produce
         incorrect results.
      
      To fix these issues, introduce a new ice_ptp_reset_cached_phctime function.
      This function calls the ice_ptp_update_cached_phctime, and discards
      outstanding Tx timestamps.
      
      If the ice_ptp_update_cached_phctime function fails because ICE_CFG_BUSY is
      set, we log a warning and schedule the thread to execute soon. The update
      function is modified so that it always updates the cached copy in the PF
      regardless. This ensures we have the most up to date values possible and
      minimizes the risk of a packet timestamp being extended with the wrong
      value.
      
      It would be nice if we could skip reporting Rx timestamps until the cached
      values are up to date. However, we can't access the Rx rings while
      ICE_CFG_BUSY is set because they are actively being updated by another
      thread.
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      b1a582e6
    • J
      ice: re-arrange some static functions in ice_ptp.c · 4b1251bd
      Jacob Keller 提交于
      A following change is going to want to make use of ice_ptp_flush_tx_tracker
      earlier in the ice_ptp.c file. To make this work, move the Tx timestamp
      tracking functions higher up in the file, and pull the
      ice_ptp_update_cached_timestamp function below them. This should have no
      functional change.
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      4b1251bd
    • J
      ice: track and warn when PHC update is late · cd25507a
      Jacob Keller 提交于
      The ice driver requires a cached copy of the PHC time in order to perform
      timestamp extension on Tx and Rx hardware timestamp values. This cached PHC
      time must always be updated at least once every 2 seconds. Otherwise, the
      math used to perform the extension would produce invalid results.
      
      The updates are supposed to occur periodically in the PTP kthread work
      item, which is scheduled to run every half second. Thus, we do not expect
      an update to be delayed for so long. However, there are error conditions
      which can cause the update to be delayed.
      
      Track this situation by using jiffies to determine approximately how long
      ago the last update occurred. Add a new statistic and a dev_warn when we
      have failed to update the cached PHC time. This makes the error case more
      obvious.
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      cd25507a
    • J
      ice: track Tx timestamp stats similar to other Intel drivers · f020481b
      Jacob Keller 提交于
      Several Intel networking drivers which support PTP track when Tx timestamps
      are skipped or when they timeout without a timestamp from hardware. The
      conditions which could cause these events are rare, but it can be useful to
      know when and how often they occur.
      
      Implement similar statistics for the ice driver, tx_hwtstamp_skipped,
      tx_hwtstamp_timeouts, and tx_hwtstamp_flushed.
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      f020481b
  8. 29 7月, 2022 1 次提交
    • J
      ice: implement adjfine with mul_u64_u64_div_u64 · 4488df14
      Jacob Keller 提交于
      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: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      4488df14
  9. 16 7月, 2022 1 次提交
  10. 15 6月, 2022 1 次提交
    • M
      ice: Fix PTP TX timestamp offset calculation · 71a579f0
      Michal Michalik 提交于
      The offset was being incorrectly calculated for E822 - that led to
      collisions in choosing TX timestamp register location when more than
      one port was trying to use timestamping mechanism.
      
      In E822 one quad is being logically split between ports, so quad 0 is
      having trackers for ports 0-3, quad 1 ports 4-7 etc. Each port should
      have separate memory location for tracking timestamps. Due to error for
      example ports 1 and 2 had been assigned to quad 0 with same offset (0),
      while port 1 should have offset 0 and 1 offset 16.
      
      Fix it by correctly calculating quad offset.
      
      Fixes: 3a749623 ("ice: implement basic E822 PTP support")
      Signed-off-by: NMichal Michalik <michal.michalik@intel.com>
      Tested-by: Gurucharan <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      71a579f0
  11. 18 5月, 2022 1 次提交
    • A
      ice: fix crash when writing timestamp on RX rings · 4503cc7f
      Arkadiusz Kubalewski 提交于
      Do not allow to write timestamps on RX rings if PF is being configured.
      When PF is being configured RX rings can be freed or rebuilt. If at the
      same time timestamps are updated, the kernel will crash by dereferencing
      null RX ring pointer.
      
      PID: 1449   TASK: ff187d28ed658040  CPU: 34  COMMAND: "ice-ptp-0000:51"
       #0 [ff1966a94a713bb0] machine_kexec at ffffffff9d05a0be
       #1 [ff1966a94a713c08] __crash_kexec at ffffffff9d192e9d
       #2 [ff1966a94a713cd0] crash_kexec at ffffffff9d1941bd
       #3 [ff1966a94a713ce8] oops_end at ffffffff9d01bd54
       #4 [ff1966a94a713d08] no_context at ffffffff9d06bda4
       #5 [ff1966a94a713d60] __bad_area_nosemaphore at ffffffff9d06c10c
       #6 [ff1966a94a713da8] do_page_fault at ffffffff9d06cae4
       #7 [ff1966a94a713de0] page_fault at ffffffff9da0107e
          [exception RIP: ice_ptp_update_cached_phctime+91]
          RIP: ffffffffc076db8b  RSP: ff1966a94a713e98  RFLAGS: 00010246
          RAX: 16e3db9c6b7ccae4  RBX: ff187d269dd3c180  RCX: ff187d269cd4d018
          RDX: 0000000000000000  RSI: 0000000000000000  RDI: 0000000000000000
          RBP: ff187d269cfcc644   R8: ff187d339b9641b0   R9: 0000000000000000
          R10: 0000000000000002  R11: 0000000000000000  R12: ff187d269cfcc648
          R13: ffffffff9f128784  R14: ffffffff9d101b70  R15: ff187d269cfcc640
          ORIG_RAX: ffffffffffffffff  CS: 0010  SS: 0018
       #8 [ff1966a94a713ea0] ice_ptp_periodic_work at ffffffffc076dbef [ice]
       #9 [ff1966a94a713ee0] kthread_worker_fn at ffffffff9d101c1b
       #10 [ff1966a94a713f10] kthread at ffffffff9d101b4d
       #11 [ff1966a94a713f50] ret_from_fork at ffffffff9da0023f
      
      Fixes: 77a78115 ("ice: enable receive hardware timestamping")
      Signed-off-by: NArkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
      Reviewed-by: NMichal Schmidt <mschmidt@redhat.com>
      Tested-by: NDave Cain <dcain@redhat.com>
      Tested-by: Gurucharan <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      4503cc7f
  12. 07 5月, 2022 1 次提交
  13. 17 3月, 2022 1 次提交
    • J
      ice: add trace events for tx timestamps · 4c120218
      Jacob Keller 提交于
      We've previously run into many issues related to the latency of a Tx
      timestamp completion with the ice hardware. It can be difficult to
      determine the root cause of a slow Tx timestamp. To aid in this,
      introduce new trace events which capture timing data about when the
      driver reaches certain points while processing a transmit timestamp
      
       * ice_tx_tstamp_request: Trace when the stack initiates a new timestamp
         request.
      
       * ice_tx_tstamp_fw_req: Trace when the driver begins a read of the
         timestamp register in the work thread.
      
       * ice_tx_tstamp_fw_done: Trace when the driver finishes reading a
         timestamp register in the work thread.
      
       * ice_tx_tstamp_complete: Trace when the driver submits the skb back to
         the stack with a completed Tx timestamp.
      
      These trace events can be enabled using the standard trace event
      subsystem exposed by the ice driver. If they are disabled, they become
      no-ops with no run time cost.
      
      The following is a simple GNU AWK script which can highlight one
      potential way to use the trace events to capture latency data from the
      trace buffer about how long the driver takes to process a timestamp:
      
      -----
        BEGIN {
            PREC=256
        }
      
        # Detect requests
        /tx_tstamp_request/ {
            time=strtonum($4)
            skb=$7
      
            # Store the time of request for this skb
            requests[skb] = time
            printf("skb %s: idx %d at %.6f\n", skb, idx, time)
        }
      
        # Detect completions
        /tx_tstamp_complete/ {
            time=strtonum($4)
            skb=$7
            idx=$9
      
            if (skb in requests) {
                latency = (time - requests[skb]) * 1000
                printf("skb %s: %.3f to complete\n", skb, latency)
                if (latency > 4) {
                    printf(">>> HIGH LATENCY <<<\n")
                }
                printf("\n")
            } else {
                printf("!!! skb %s (idx %d) at %.6f\n", skb, idx, time)
            }
        }
      -----
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Tested-by: Gurucharan <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      4c120218
  14. 19 2月, 2022 1 次提交
    • T
      ice: check the return of ice_ptp_gettimex64 · ed22d9c8
      Tom Rix 提交于
      Clang static analysis reports this issue
      time64.h:69:50: warning: The left operand of '+'
        is a garbage value
        set_normalized_timespec64(&ts_delta, lhs.tv_sec + rhs.tv_sec,
                                             ~~~~~~~~~~ ^
      In ice_ptp_adjtime_nonatomic(), the timespec64 variable 'now'
      is set by ice_ptp_gettimex64().  This function can fail
      with -EBUSY, so 'now' can have a gargbage value.
      So check the return.
      
      Fixes: 06c16d89 ("ice: register 1588 PTP clock device object for E810 devices")
      Signed-off-by: NTom Rix <trix@redhat.com>
      Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
      Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
      ed22d9c8
  15. 07 1月, 2022 1 次提交
  16. 22 12月, 2021 7 次提交
  17. 15 12月, 2021 2 次提交