OSDN Git Service

iwlwifi: pcie: refactor dev_info lookup
authorJohannes Berg <johannes.berg@intel.com>
Sun, 24 Oct 2021 13:54:59 +0000 (16:54 +0300)
committerLuca Coelho <luciano.coelho@intel.com>
Thu, 28 Oct 2021 09:04:09 +0000 (12:04 +0300)
The large condition here is not very clear, refactor the code to
a separate function where we can more easily just check each of
the pieces separately.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
Link: https://lore.kernel.org/r/iwlwifi.20211024165252.ef06ed58a26e.Ie9664a94b157c5781c481118d900ae428c26fdb3@changeid
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
drivers/net/wireless/intel/iwlwifi/pcie/drv.c

index fec1620..adb3ad2 100644 (file)
@@ -519,7 +519,7 @@ MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
 #define IWL_DEV_INFO(_device, _subdevice, _cfg, _name) \
        _IWL_DEV_INFO(_device, _subdevice, IWL_CFG_ANY, IWL_CFG_ANY,       \
                      IWL_CFG_ANY, IWL_CFG_ANY, IWL_CFG_ANY, IWL_CFG_ANY,  \
-                     IWL_CFG_NO_CDB, _cfg, _name)
+                     IWL_CFG_ANY, _cfg, _name)
 
 static const struct iwl_dev_info iwl_dev_info_table[] = {
 #if IS_ENABLED(CONFIG_IWLMVM)
@@ -1312,13 +1312,67 @@ out:
 /* PCI registers */
 #define PCI_CFG_RETRY_TIMEOUT  0x041
 
+static const struct iwl_dev_info *
+iwl_pci_find_dev_info(u16 device, u16 subsystem_device,
+                     u16 mac_type, u8 mac_step,
+                     u16 rf_type, u8 cdb, u8 rf_id, u8 no_160, u8 cores)
+{
+       const struct iwl_dev_info *ret = NULL;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(iwl_dev_info_table); i++) {
+               const struct iwl_dev_info *dev_info = &iwl_dev_info_table[i];
+
+               if (dev_info->device != (u16)IWL_CFG_ANY &&
+                   dev_info->device != device)
+                       continue;
+
+               if (dev_info->subdevice != (u16)IWL_CFG_ANY &&
+                   dev_info->subdevice != subsystem_device)
+                       continue;
+
+               if (dev_info->mac_type != (u16)IWL_CFG_ANY &&
+                   dev_info->mac_type != mac_type)
+                       continue;
+
+               if (dev_info->mac_step != (u8)IWL_CFG_ANY &&
+                   dev_info->mac_step != mac_step)
+                       continue;
+
+               if (dev_info->rf_type != (u16)IWL_CFG_ANY &&
+                   dev_info->rf_type != rf_type)
+                       continue;
+
+               if (dev_info->cdb != (u8)IWL_CFG_ANY &&
+                   dev_info->cdb != cdb)
+                       continue;
+
+               if (dev_info->rf_id != (u8)IWL_CFG_ANY &&
+                   dev_info->rf_id != rf_id)
+                       continue;
+
+               if (dev_info->no_160 != (u8)IWL_CFG_ANY &&
+                   dev_info->no_160 != no_160)
+                       continue;
+
+               if (dev_info->cores != (u8)IWL_CFG_ANY &&
+                   dev_info->cores != cores)
+                       continue;
+
+               ret = dev_info;
+       }
+
+       return ret;
+}
+
 static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
        const struct iwl_cfg_trans_params *trans;
        const struct iwl_cfg *cfg_7265d __maybe_unused = NULL;
+       const struct iwl_dev_info *dev_info;
        struct iwl_trans *iwl_trans;
        struct iwl_trans_pcie *trans_pcie;
-       int i, ret;
+       int ret;
        const struct iwl_cfg *cfg;
 
        trans = (void *)(ent->driver_data & ~TRANS_CFG_MARKER);
@@ -1370,35 +1424,18 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
            !CSR_HW_RFID_TYPE(iwl_trans->hw_rf_id) && get_crf_id(iwl_trans))
                goto out_free_trans;
 
-       for (i = 0; i < ARRAY_SIZE(iwl_dev_info_table); i++) {
-               const struct iwl_dev_info *dev_info = &iwl_dev_info_table[i];
-               if ((dev_info->device == (u16)IWL_CFG_ANY ||
-                    dev_info->device == pdev->device) &&
-                   (dev_info->subdevice == (u16)IWL_CFG_ANY ||
-                    dev_info->subdevice == pdev->subsystem_device) &&
-                   (dev_info->mac_type == (u16)IWL_CFG_ANY ||
-                    dev_info->mac_type ==
-                    CSR_HW_REV_TYPE(iwl_trans->hw_rev)) &&
-                   (dev_info->mac_step == (u8)IWL_CFG_ANY ||
-                    dev_info->mac_step ==
-                    CSR_HW_REV_STEP(iwl_trans->hw_rev)) &&
-                   (dev_info->rf_type == (u16)IWL_CFG_ANY ||
-                    dev_info->rf_type ==
-                    CSR_HW_RFID_TYPE(iwl_trans->hw_rf_id)) &&
-                   (dev_info->cdb == IWL_CFG_NO_CDB ||
-                    CSR_HW_RFID_IS_CDB(iwl_trans->hw_rf_id)) &&
-                   (dev_info->rf_id == (u8)IWL_CFG_ANY ||
-                    dev_info->rf_id ==
-                    IWL_SUBDEVICE_RF_ID(pdev->subsystem_device)) &&
-                   (dev_info->no_160 == (u8)IWL_CFG_ANY ||
-                    dev_info->no_160 ==
-                    IWL_SUBDEVICE_NO_160(pdev->subsystem_device)) &&
-                   (dev_info->cores == (u8)IWL_CFG_ANY ||
-                    dev_info->cores ==
-                    IWL_SUBDEVICE_CORES(pdev->subsystem_device))) {
-                       iwl_trans->cfg = dev_info->cfg;
-                       iwl_trans->name = dev_info->name;
-               }
+       dev_info = iwl_pci_find_dev_info(pdev->device, pdev->subsystem_device,
+                                        CSR_HW_REV_TYPE(iwl_trans->hw_rev),
+                                        CSR_HW_REV_STEP(iwl_trans->hw_rev),
+                                        CSR_HW_RFID_TYPE(iwl_trans->hw_rf_id),
+                                        CSR_HW_RFID_IS_CDB(iwl_trans->hw_rf_id),
+                                        IWL_SUBDEVICE_RF_ID(pdev->subsystem_device),
+                                        IWL_SUBDEVICE_NO_160(pdev->subsystem_device),
+                                        IWL_SUBDEVICE_CORES(pdev->subsystem_device));
+
+       if (dev_info) {
+               iwl_trans->cfg = dev_info->cfg;
+               iwl_trans->name = dev_info->name;
        }
 
 #if IS_ENABLED(CONFIG_IWLMVM)