1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2 /* 3 * KUnit tests for the iwlwifi device info table 4 * 5 * Copyright (C) 2023-2025 Intel Corporation 6 */ 7 #include <kunit/test.h> 8 #include <linux/pci.h> 9 #include "iwl-drv.h" 10 #include "iwl-config.h" 11 12 MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING"); 13 14 static void iwl_pci_print_dev_info(const char *pfx, const struct iwl_dev_info *di) 15 { 16 printk(KERN_DEBUG "%sdev=%.4x,subdev=%.4x,mac_type=%.4x,mac_step=%.4x,rf_type=%.4x,cdb=%d,jacket=%d,rf_id=%.2x,bw_limit=%d,cores=%.2x\n", 17 pfx, di->device, di->subdevice, di->mac_type, di->mac_step, 18 di->rf_type, di->cdb, di->jacket, di->rf_id, di->bw_limit, 19 di->cores); 20 } 21 22 static void devinfo_table_order(struct kunit *test) 23 { 24 int idx; 25 26 for (idx = 0; idx < iwl_dev_info_table_size; idx++) { 27 const struct iwl_dev_info *di = &iwl_dev_info_table[idx]; 28 const struct iwl_dev_info *ret; 29 30 ret = iwl_pci_find_dev_info(di->device, di->subdevice, 31 di->mac_type, di->mac_step, 32 di->rf_type, di->cdb, 33 di->jacket, di->rf_id, 34 di->bw_limit != IWL_CFG_BW_NO_LIM, 35 di->cores, di->rf_step); 36 if (!ret) { 37 iwl_pci_print_dev_info("No entry found for: ", di); 38 KUNIT_FAIL(test, 39 "No entry found for entry at index %d\n", idx); 40 } else if (ret != di) { 41 iwl_pci_print_dev_info("searched: ", di); 42 iwl_pci_print_dev_info("found: ", ret); 43 KUNIT_FAIL(test, 44 "unusable entry at index %d (found index %d instead)\n", 45 idx, (int)(ret - iwl_dev_info_table)); 46 } 47 } 48 } 49 50 static void devinfo_pci_ids(struct kunit *test) 51 { 52 struct pci_dev *dev; 53 54 dev = kunit_kmalloc(test, sizeof(*dev), GFP_KERNEL); 55 KUNIT_ASSERT_NOT_NULL(test, dev); 56 57 for (int i = 0; iwl_hw_card_ids[i].vendor; i++) { 58 const struct pci_device_id *s, *t; 59 60 s = &iwl_hw_card_ids[i]; 61 dev->vendor = s->vendor; 62 dev->device = s->device; 63 dev->subsystem_vendor = s->subvendor; 64 dev->subsystem_device = s->subdevice; 65 dev->class = s->class; 66 67 t = pci_match_id(iwl_hw_card_ids, dev); 68 KUNIT_EXPECT_PTR_EQ(test, t, s); 69 } 70 } 71 72 static struct kunit_case devinfo_test_cases[] = { 73 KUNIT_CASE(devinfo_table_order), 74 KUNIT_CASE(devinfo_pci_ids), 75 {} 76 }; 77 78 static struct kunit_suite iwlwifi_devinfo = { 79 .name = "iwlwifi-devinfo", 80 .test_cases = devinfo_test_cases, 81 }; 82 83 kunit_test_suite(iwlwifi_devinfo); 84