PCI/ASPM: Correct LTR_L1.2_THRESHOLD computation
authorBjorn Helgaas <bhelgaas@google.com>
Wed, 5 Oct 2022 02:58:09 +0000 (21:58 -0500)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 5 Oct 2022 17:12:02 +0000 (12:12 -0500)
commit7afeb84d14eaaebb71f5c558ed57ca858e4304e7
treea07e7501865c1f402b567fe36419e05899e2d2cf
parentcfc0028627cadfa271fab0290f18731193d63d87
PCI/ASPM: Correct LTR_L1.2_THRESHOLD computation

80d7d7a904fa ("PCI/ASPM: Calculate LTR_L1.2_THRESHOLD from device
characteristics") replaced a fixed value (163840ns) with one computed from
T_POWER_OFF, Common_Mode_Restore_Time, etc., but it encoded the
LTR_L1.2_THRESHOLD value incorrectly.

This is especially a problem for small thresholds, e.g., 63ns fell into the
"threshold_ns < 1024" case and was encoded as 32ns:

  LTR_L1.2_THRESHOLD_Scale = 1 (multiplier is 32ns)
  LTR_L1.2_THRESHOLD_Value = 63 >> 5 = 1
  LTR_L1.2_THRESHOLD       = multiplier * value = 32ns * 1 = 32ns

Correct the algorithm to encode all times of 1023ns (0x3ff) or smaller
exactly and larger times conservatively (the encoded threshold is never
smaller than was requested).  This reduces the chance of entering L1.2
when the device can't tolerate the exit latency.

Fixes: 80d7d7a904fa ("PCI/ASPM: Calculate LTR_L1.2_THRESHOLD from device characteristics")
Link: https://lore.kernel.org/r/20221005025809.2247547-4-helgaas@kernel.org
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
drivers/pci/pcie/aspm.c