Bug 216452 - iwlwifi: Error while preparing HW: -110 when Intel AMT via WiFi is configured.
Summary: iwlwifi: Error while preparing HW: -110 when Intel AMT via WiFi is configured.
Status: CLOSED CODE_FIX
Alias: None
Product: Drivers
Classification: Unclassified
Component: network-wireless-intel (show other bugs)
Hardware: Intel Linux
: P1 normal
Assignee: Default virtual assignee for network-wireless-intel
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-09-05 22:24 UTC by Lorenzo Zolfanelli
Modified: 2022-09-17 17:56 UTC (History)
3 users (show)

See Also:
Kernel Version: 5.15.65
Subsystem:
Regression: No
Bisected commit-id:


Attachments
iwlwifi kernel log, options debug=1, card preparation failed after cold boot (212.96 KB, text/plain)
2022-09-05 22:24 UTC, Lorenzo Zolfanelli
Details
iwlwifi kernel log, options debug=1, card preparation succeded after module reload (210.29 KB, text/plain)
2022-09-05 22:25 UTC, Lorenzo Zolfanelli
Details
iwlwifi kernel log, options debug=1, proposed patch applied, card preparation succeded after reboot (678.14 KB, text/plain)
2022-09-07 00:01 UTC, Lorenzo Zolfanelli
Details

Description Lorenzo Zolfanelli 2022-09-05 22:24:22 UTC
Created attachment 301750 [details]
iwlwifi kernel log, options debug=1, card preparation failed after cold boot

This issue exists at least since 2013-05-22 12:32, as has been reported downstream by a RedHat user: https://bugzilla.redhat.com/show_bug.cgi?id=966080.

I have replicated it for the last 3-4 years on a Dell Latitude 7480, using many kernel versions, 4.x and 5.x. The problem is consistent across distribution and kernel flavors.

Configuring the Intel AMT out-of-band management platform to use WiFi seems sufficient to cause a race-condition for the control of the PCIe WiFi network card, causing the WiFi card to not be initialized at boot.

The problems occurs randomly (approximately 8 times over 10) when starting the computer from cold power-off or resuming for suspension.
It only occurs if the computer has been suspended/powered-off for a sufficient amount of time (>15-20 seconds), probably the time needed for the Intel AMT system to rise its network stack and take control of the WiFi card.

To get the card recognized and working again it's necessary to unload and reload the `iwlwifi` module several times.

The part of the module `iwlwifi` involved seems to reside in the file `linux/drivers/net/wireless/intel/iwlwifi/pcie/trans.c`. In particular the functions `iwl_pcie_prepare_card_hw` and `iwl_pcie_set_hw_ready` are the ones called when the attempts to prepare the card fail.

Apparently an attempt to fix this issue (or a similar one) has been made in commit https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=501fd9895c1d7d8161ed56698ae2fccb10ef14f5 (iwlwifi: pcie: try to get ownership several times, 2014-05-11, Reviewed-by: Johannes Berg <johannes.berg@intel.com>, Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>).
Comment 1 Lorenzo Zolfanelli 2022-09-05 22:25:59 UTC
Created attachment 301751 [details]
iwlwifi kernel log, options debug=1, card preparation succeded after module reload
Comment 2 Emmanuel Grumbach 2022-09-06 05:43:16 UTC
Hi,

can you try this:
diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c
index ce62929c36..e4868aa2f9 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c
@@ -603,7 +603,6 @@ static int iwl_pcie_set_hw_ready(struct iwl_trans *trans)
 int iwl_pcie_prepare_card_hw(struct iwl_trans *trans)
 {
        int ret;
-       int t = 0;
        int iter;

        IWL_DEBUG_INFO(trans, "iwl_trans_prepare_card_hw enter\n");
@@ -620,6 +619,8 @@ int iwl_pcie_prepare_card_hw(struct iwl_trans *trans)
        usleep_range(1000, 2000);

        for (iter = 0; iter < 10; iter++) {
+               int t = 0;
+
                /* If HW is not ready, prepare the conditions to check again */
                iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
                            CSR_HW_IF_CONFIG_REG_PREPARE);
Comment 3 Lorenzo Zolfanelli 2022-09-06 23:59:31 UTC
Hi Emmanuel,

I am currently using v5.15.60 and the patch seems indeed to make things better. I will need some more time to test extensively.

In my first cold boot after patching the device got ready (automatically) in 12 seconds after the first attempt, at the iteration 7 over 10 (I modified the patch to print the iteration number in the debug kernel messages).
Comment 4 Lorenzo Zolfanelli 2022-09-07 00:01:36 UTC
Created attachment 301758 [details]
iwlwifi kernel log, options debug=1, proposed patch applied, card preparation succeded after reboot
Comment 5 Lorenzo Zolfanelli 2022-09-17 15:07:24 UTC
After days of routinely using my laptop with the patched module, I can confirm that the proposed patch works and is stable.

I monitored the iterations used at each start, and they reached a maximum of 8 (over 10 maximum allowed).

Thanks to Emmanuel Grumbach for the rapid solution!
Comment 6 Emmanuel Grumbach 2022-09-17 17:56:00 UTC
Great.

Patch will be upstreamed throught the usual process.
It may take time since we have a big backlog.

Note You need to log in before you can comment on or make changes to this bug.