BACKPORT: FROMLIST: iwlwifi: pcie: limit memory read spin time

When we read device memory, we lock a spinlock, write the address we
want to read from the device and then spin in a loop reading the data
in 32-bit quantities from another register.

As the description makes clear, this is rather inefficient, incurring
a PCIe bus transaction for every read. In a typical device today, we
want to read 786k SMEM if it crashes, leading to 192k register reads.
Occasionally, we've seen the whole loop take over 20 seconds and then
triggering the soft lockup detector.

Clearly, it is unreasonable to spin here for such extended periods of
time.

To fix this, break the loop down into an outer and an inner loop, and
break out of the inner loop if more than half a second elapsed. To
avoid too much overhead, check for that only every 128 reads, though
there's no particular reason for that number. Then, unlock and relock
to obtain NIC access again, reprogram the start address and continue.

This will keep (interrupt) latencies on the CPU down to a reasonable
time.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Mordechay Goodstein <mordechay.goodstein@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>

(am from https://patchwork.kernel.org/patch/11851469)

BUG=b:168087631
TEST=suspend_stress_test -c 2500 on morphius

Backport:
- change the paths from iwlwifi to iwl7000

Change-Id: If96d4552baefa35b4fce056f52969f03cca5ffbb
Signed-off-by: Nicolas Norvez <norvez@chromium.org>
Signed-off-by: Bhanu Prakash Maiya <bhanumaiya@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2504583
Reviewed-by: Brian Norris <briannorris@chromium.org>
(cherry picked from commit e65d748dc85640a305a1b41413cb621252278435)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2522093
(cherry picked from commit 19f2feee624cac56b817164d370621c224b07dc9)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2571741
Commit-Queue: Rob Barnes <robbarnes@google.com>
Reviewed-by: Rob Barnes <robbarnes@google.com>
1 file changed