Commit ee92656e authored by Johannes Berg's avatar Johannes Berg Committed by Miri Korenblit
Browse files

wifi: iwlwifi: cfg: reduce configuration struct size



We don't need the CORES() match nor jacket (which really doesn't
even make sense to match to the RF anyway), and since the subdevice
masks we care about are contiguous, we can encode them as highest
and lowest bit set (automatically.) By encoding whether to match or
not as separate flags and taking advantage of the limited range of
the RF type, step and ID we can reduce the amount of memory needed
for the table, while also making the logic (apart perhaps from the
subdevice mask) easier to understand.

This reduces the size of the module by about 1.5KiB on x86-64.

Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
Signed-off-by: default avatarMiri Korenblit <miriam.rachel.korenblit@intel.com>
Link: https://patch.msgid.link/20250511195137.38a805a7c96f.Ieece00476cea6054b0827cd075eb8ba5943373df@changeid
parent 25384061
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -478,18 +478,22 @@ struct iwl_rf_cfg {
#define IWL_SUBDEVICE_CORES(subdevice)	((u16)((subdevice) & 0x1C00) >> 10)

struct iwl_dev_info {
	u16 device;
	u16 subdevice;
	u16 subdevice_mask;
	u16 rf_type;
	u8 bw_limit;
	u8 rf_step;
	u8 rf_id;
	u8 cores;
	u8 cdb;
	u8 jacket;
	const struct iwl_rf_cfg *cfg;
	const char *name;
	u16 device;
	u16 subdevice;
	u32 subdevice_m_l:4,
	    subdevice_m_h:4,
	    match_rf_type:1,
	    rf_type:9,
	    match_bw_limit:1,
	    bw_limit:1,
	    match_rf_step:1,
	    rf_step:4,
	    match_rf_id:1,
	    rf_id:4,
	    match_cdb:1,
	    cdb:1;
};

#if IS_ENABLED(CONFIG_IWLWIFI_KUNIT_TESTS)
@@ -497,7 +501,7 @@ extern const struct iwl_dev_info iwl_dev_info_table[];
extern const unsigned int iwl_dev_info_table_size;
const struct iwl_dev_info *
iwl_pci_find_dev_info(u16 device, u16 subsystem_device, u16 rf_type, u8 cdb,
		      u8 jacket, u8 rf_id, u8 bw_limit, u8 cores, u8 rf_step);
		      u8 rf_id, u8 bw_limit, u8 rf_step);
extern const struct pci_device_id iwl_hw_card_ids[];
#endif

+33 −43
Original line number Diff line number Diff line
@@ -557,14 +557,7 @@ EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_hw_card_ids);
	.name = _name,				\
	.device = IWL_CFG_ANY,			\
	.subdevice = IWL_CFG_ANY,		\
	.subdevice_mask = ~0,			\
	.rf_type = IWL_CFG_ANY,			\
	.rf_step = IWL_CFG_ANY,			\
	.bw_limit = IWL_CFG_ANY,		\
	.jacket = IWL_CFG_ANY,			\
	.cores = IWL_CFG_ANY,			\
	.rf_id = IWL_CFG_ANY,			\
	.cdb = IWL_CFG_ANY,			\
	.subdevice_m_h = 15,			\
	__VA_ARGS__				\
}
#define IWL_DEV_INFO(_cfg, _name, ...)		\
@@ -572,17 +565,25 @@ EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_hw_card_ids);

#define DEVICE(n)		.device = (n)
#define SUBDEV(n)		.subdevice = (n)
#define SUBDEV_MASKED(v, m)			\
			.subdevice = (v),	\
			.subdevice_mask = (m)
#define RF_TYPE(n)	.rf_type = IWL_CFG_RF_TYPE_##n
#define RF_STEP(n)	.rf_step = SILICON_##n##_STEP
#define CORES(n)	.cores = IWL_CFG_CORES_##n
#define RF_ID(n)	.rf_id = IWL_CFG_RF_ID_##n
#define NO_CDB		.cdb = IWL_CFG_NO_CDB
#define CDB		.cdb = IWL_CFG_CDB
#define BW_NOT_LIMITED	.bw_limit = 0
#define BW_LIMITED	.bw_limit = 1
#define _LOWEST_BIT(n)		(__builtin_ffs(n) - 1)
#define _BIT_ABOVE_MASK(n)	((n) + (1 << _LOWEST_BIT(n)))
#define _HIGHEST_BIT(n)		(__builtin_ffs(_BIT_ABOVE_MASK(n)) - 2)
#define _IS_POW2(n)		(((n) & ((n) - 1)) == 0)
#define _IS_CONTIG(n)		_IS_POW2(_BIT_ABOVE_MASK(n))
#define _CHECK_MASK(m)		BUILD_BUG_ON_ZERO(!_IS_CONTIG(m))
#define SUBDEV_MASKED(v, m)	.subdevice = (v) + _CHECK_MASK(m),	\
				.subdevice_m_l = _LOWEST_BIT(m),	\
				.subdevice_m_h = _HIGHEST_BIT(m)
#define RF_TYPE(n)		.match_rf_type = 1,			\
				.rf_type = IWL_CFG_RF_TYPE_##n
#define RF_STEP(n)		.match_rf_step = 1,			\
				.rf_step = SILICON_##n##_STEP
#define RF_ID(n)		.match_rf_id = 1,			\
				.rf_id = IWL_CFG_RF_ID_##n
#define NO_CDB			.match_cdb = 1, .cdb = 0
#define CDB			.match_cdb = 1, .cdb = 1
#define BW_NOT_LIMITED		.match_bw_limit = 1, .bw_limit = 0
#define BW_LIMITED		.match_bw_limit = 1, .bw_limit = 1

VISIBLE_IF_IWLWIFI_KUNIT const struct iwl_dev_info iwl_dev_info_table[] = {
#if IS_ENABLED(CONFIG_IWLDVM)
@@ -1214,7 +1215,7 @@ static int map_crf_id(struct iwl_trans *iwl_trans,

VISIBLE_IF_IWLWIFI_KUNIT const struct iwl_dev_info *
iwl_pci_find_dev_info(u16 device, u16 subsystem_device, u16 rf_type, u8 cdb,
		      u8 jacket, u8 rf_id, u8 bw_limit, u8 cores, u8 rf_step)
		      u8 rf_id, u8 bw_limit, u8 rf_step)
{
	int num_devices = ARRAY_SIZE(iwl_dev_info_table);
	int i;
@@ -1224,41 +1225,32 @@ iwl_pci_find_dev_info(u16 device, u16 subsystem_device, u16 rf_type, u8 cdb,

	for (i = num_devices - 1; i >= 0; i--) {
		const struct iwl_dev_info *dev_info = &iwl_dev_info_table[i];
		u16 subdevice_mask;

		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 & dev_info->subdevice_mask))
			continue;
		subdevice_mask = GENMASK(dev_info->subdevice_m_h,
					 dev_info->subdevice_m_l);

		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)
		if (dev_info->subdevice != (u16)IWL_CFG_ANY &&
		    dev_info->subdevice != (subsystem_device & subdevice_mask))
			continue;

		if (dev_info->jacket != (u8)IWL_CFG_ANY &&
		    dev_info->jacket != jacket)
		if (dev_info->match_rf_type && dev_info->rf_type != rf_type)
			continue;

		if (dev_info->rf_id != (u8)IWL_CFG_ANY &&
		    dev_info->rf_id != rf_id)
		if (dev_info->match_cdb && dev_info->cdb != cdb)
			continue;

		if (dev_info->bw_limit != (u8)IWL_CFG_ANY &&
		    dev_info->bw_limit != bw_limit)
		if (dev_info->match_rf_id && dev_info->rf_id != rf_id)
			continue;

		if (dev_info->cores != (u8)IWL_CFG_ANY &&
		    dev_info->cores != cores)
		if (dev_info->match_bw_limit && dev_info->bw_limit != bw_limit)
			continue;

		if (dev_info->rf_step != (u8)IWL_CFG_ANY &&
		    dev_info->rf_step != rf_step)
		if (dev_info->match_rf_step && dev_info->rf_step != rf_step)
			continue;

		return dev_info;
@@ -1378,10 +1370,8 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
	dev_info = iwl_pci_find_dev_info(pdev->device, pdev->subsystem_device,
					 CSR_HW_RFID_TYPE(info.hw_rf_id),
					 CSR_HW_RFID_IS_CDB(info.hw_rf_id),
					 CSR_HW_RFID_IS_JACKET(info.hw_rf_id),
					 IWL_SUBDEVICE_RF_ID(pdev->subsystem_device),
					 IWL_SUBDEVICE_BW_LIM(pdev->subsystem_device),
					 IWL_SUBDEVICE_CORES(pdev->subsystem_device),
					 CSR_HW_RFID_STEP(info.hw_rf_id));
	if (dev_info) {
		iwl_trans->cfg = dev_info->cfg;
+54 −15
Original line number Diff line number Diff line
@@ -13,10 +13,50 @@ MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");

static void iwl_pci_print_dev_info(const char *pfx, const struct iwl_dev_info *di)
{
	printk(KERN_DEBUG "%sdev=%.4x subdev=%.4x rf_type=%.4x cdb=%d jacket=%d rf_id=%.2x bw_limit=%d cores=%.2x\n",
	       pfx, di->device, di->subdevice,
	       di->rf_type, di->cdb, di->jacket, di->rf_id, di->bw_limit,
	       di->cores);
	u16 subdevice_mask = GENMASK(di->subdevice_m_h, di->subdevice_m_l);
	char buf[100] = {};
	int pos = 0;

	if (di->match_rf_type)
		pos += scnprintf(buf + pos, sizeof(buf) - pos,
				 " rf_type=%03x", di->rf_type);
	else
		pos += scnprintf(buf + pos, sizeof(buf) - pos,
				 " rf_type=*");

	if (di->match_bw_limit)
		pos += scnprintf(buf + pos, sizeof(buf) - pos,
				 " bw_limit=%d", di->bw_limit);
	else
		pos += scnprintf(buf + pos, sizeof(buf) - pos,
				 " bw_limit=*");

	if (di->match_rf_step)
		pos += scnprintf(buf + pos, sizeof(buf) - pos,
				 " rf_step=%c",
				 di->rf_step == SILICON_Z_STEP ? 'Z' :
				 	'A' + di->rf_step);
	else
		pos += scnprintf(buf + pos, sizeof(buf) - pos,
				 " rf_step=*");

	if (di->match_rf_id)
		pos += scnprintf(buf + pos, sizeof(buf) - pos,
				 " rf_id=0x%x", di->rf_id);
	else
		pos += scnprintf(buf + pos, sizeof(buf) - pos,
				 " rf_id=*");

	if (di->match_cdb)
		pos += scnprintf(buf + pos, sizeof(buf) - pos,
				 " cdb=%d", di->cdb);
	else
		pos += scnprintf(buf + pos, sizeof(buf) - pos,
				 " cdb=*");


	printk(KERN_DEBUG "%sdev=%04x subdev=%04x/%04x%s\n",
	       pfx, di->device, di->subdevice, subdevice_mask, buf);
}

static void devinfo_table_order(struct kunit *test)
@@ -29,9 +69,8 @@ static void devinfo_table_order(struct kunit *test)

		ret = iwl_pci_find_dev_info(di->device, di->subdevice,
					    di->rf_type, di->cdb,
					    di->jacket, di->rf_id,
					    di->bw_limit,
					    di->cores, di->rf_step);
					    di->rf_id, di->bw_limit,
					    di->rf_step);
		if (!ret) {
			iwl_pci_print_dev_info("No entry found for: ", di);
			KUNIT_FAIL(test,
@@ -98,25 +137,25 @@ static void devinfo_check_subdev_match(struct kunit *test)
{
	for (int i = 0; i < iwl_dev_info_table_size; i++) {
		const struct iwl_dev_info *di = &iwl_dev_info_table[i];
		u16 subdevice_mask = GENMASK(di->subdevice_m_h,
					     di->subdevice_m_l);

		/* if BW limit bit is matched then must have a limit */
		if (di->bw_limit == 1)
		if (di->match_bw_limit == 1 && di->bw_limit == 1)
			KUNIT_EXPECT_NE(test, di->cfg->bw_limit, 0);

		/* if subdevice is ANY we can have RF ID/BW limit/cores */
		/* if subdevice is ANY we can have RF ID/BW limit */
		if (di->subdevice == (u16)IWL_CFG_ANY)
			continue;

		/* same if the subdevice mask doesn't overlap them */
		if (IWL_SUBDEVICE_RF_ID(di->subdevice_mask) == 0 &&
		    IWL_SUBDEVICE_BW_LIM(di->subdevice_mask) == 0 &&
		    IWL_SUBDEVICE_CORES(di->subdevice_mask) == 0)
		if (IWL_SUBDEVICE_RF_ID(subdevice_mask) == 0 &&
		    IWL_SUBDEVICE_BW_LIM(subdevice_mask) == 0)
			continue;

		/* but otherwise they shouldn't be used */
		KUNIT_EXPECT_EQ(test, di->rf_id, (u8)IWL_CFG_ANY);
		KUNIT_EXPECT_EQ(test, di->bw_limit, (u8)IWL_CFG_ANY);
		KUNIT_EXPECT_EQ(test, di->cores, (u8)IWL_CFG_ANY);
		KUNIT_EXPECT_EQ(test, (int)di->match_rf_id, 0);
		KUNIT_EXPECT_EQ(test, (int)di->match_bw_limit, 0);
	}
}