wifi: iwlwifi: unify checks for HW error values
authorJohannes Berg <johannes.berg@intel.com>
Mon, 12 Jun 2023 15:51:10 +0000 (18:51 +0300)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 14 Jun 2023 10:32:18 +0000 (12:32 +0200)
The hardware, depending on which part fails or times out,
returns 0xA5A5A5A. or 0x5A5A5A5. with the lowest 4 bits
encoding some further reason/status. However, mostly we
don't really need to care about the exact reasons, so
unify the checks for this to avoid hardcoding those magic
values all over the driver.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Gregory Greenman <gregory.greenman@intel.com>
Link: https://lore.kernel.org/r/20230612184434.3e2959741a38.I1c297a53787b87e4e2b8f296c041921338573f4d@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
drivers/net/wireless/intel/iwlwifi/fw/dbg.c
drivers/net/wireless/intel/iwlwifi/fw/dump.c
drivers/net/wireless/intel/iwlwifi/iwl-io.c
drivers/net/wireless/intel/iwlwifi/iwl-trans.h
drivers/net/wireless/intel/iwlwifi/pcie/rx.c
drivers/net/wireless/intel/iwlwifi/pcie/trans.c

index 3c5a43a..3253d89 100644 (file)
@@ -1038,7 +1038,7 @@ iwl_dump_ini_prph_mac_iter(struct iwl_fw_runtime *fwrt,
        range->range_data_size = reg->dev_addr.size;
        for (i = 0; i < le32_to_cpu(reg->dev_addr.size); i += 4) {
                prph_val = iwl_read_prph(fwrt->trans, addr + i);
-               if ((prph_val & ~0xf) == 0xa5a5a5a0)
+               if (iwl_trans_is_hw_error_value(prph_val))
                        return -EBUSY;
                *val++ = cpu_to_le32(prph_val);
        }
@@ -1562,7 +1562,7 @@ iwl_dump_ini_dbgi_sram_iter(struct iwl_fw_runtime *fwrt,
                prph_data = iwl_read_prph_no_grab(fwrt->trans, (i % 2) ?
                                          DBGI_SRAM_TARGET_ACCESS_RDATA_MSB :
                                          DBGI_SRAM_TARGET_ACCESS_RDATA_LSB);
-               if ((prph_data & ~0xf) == 0xa5a5a5a0) {
+               if (iwl_trans_is_hw_error_value(prph_data)) {
                        iwl_trans_release_nic_access(fwrt->trans);
                        return -EBUSY;
                }
index f86f7b4..64e83f3 100644 (file)
@@ -194,7 +194,7 @@ static void iwl_fwrt_dump_lmac_error_log(struct iwl_fw_runtime *fwrt, u8 lmac_nu
 
        /* check if there is a HW error */
        val = iwl_trans_read_mem32(trans, base);
-       if (((val & ~0xf) == 0xa5a5a5a0) || ((val & ~0xf) == 0x5a5a5a50)) {
+       if (iwl_trans_is_hw_error_value(val)) {
                int err;
 
                IWL_ERR(trans, "HW error, resetting before reading\n");
index 396f2c9..c60f946 100644 (file)
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
 /*
- * Copyright (C) 2003-2014, 2018-2021 Intel Corporation
+ * Copyright (C) 2003-2014, 2018-2022 Intel Corporation
  * Copyright (C) 2015-2016 Intel Deutschland GmbH
  */
 #include <linux/delay.h>
@@ -72,6 +72,7 @@ u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg)
                return value;
        }
 
+       /* return as if we have a HW timeout/failure */
        return 0x5a5a5a5a;
 }
 IWL_EXPORT_SYMBOL(iwl_read_direct32);
@@ -143,6 +144,7 @@ u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs)
                return val;
        }
 
+       /* return as if we have a HW timeout/failure */
        return 0x5a5a5a5a;
 }
 IWL_EXPORT_SYMBOL(iwl_read_prph);
index d9e465d..1fa035d 100644 (file)
@@ -1613,6 +1613,11 @@ struct iwl_trans *iwl_trans_alloc(unsigned int priv_size,
 int iwl_trans_init(struct iwl_trans *trans);
 void iwl_trans_free(struct iwl_trans *trans);
 
+static inline bool iwl_trans_is_hw_error_value(u32 val)
+{
+       return ((val & ~0xf) == 0xa5a5a5a0) || ((val & ~0xf) == 0x5a5a5a50);
+}
+
 /*****************************************************
 * driver (transport) register/unregister functions
 ******************************************************/
index 0d7890f..4ee4886 100644 (file)
@@ -1873,7 +1873,7 @@ irqreturn_t iwl_pcie_irq_handler(int irq, void *dev_id)
                return IRQ_NONE;
        }
 
-       if (unlikely(inta == 0xFFFFFFFF || (inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
+       if (unlikely(inta == 0xFFFFFFFF || iwl_trans_is_hw_error_value(inta))) {
                /*
                 * Hardware disappeared. It might have
                 * already raised an interrupt.
index 1541939..7240bec 100644 (file)
@@ -1788,7 +1788,7 @@ static int iwl_trans_pcie_clear_persistence_bit(struct iwl_trans *trans)
        }
 
        hpm = iwl_read_umac_prph_no_grab(trans, HPM_DEBUG);
-       if (hpm != 0xa5a5a5a0 && (hpm & PERSISTENCE_BIT)) {
+       if (!iwl_trans_is_hw_error_value(hpm) && (hpm & PERSISTENCE_BIT)) {
                u32 wprot_val = iwl_read_umac_prph_no_grab(trans, wprot);
 
                if (wprot_val & PREG_WFPM_ACCESS) {