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

wifi: iwlwifi: rework transport configuration



Instead of having a trans_configure method that copies all
the data, just have the users set up the configuration in
the transport directly. This simplifies the code on both
sides. While doing so also move some value from the trans
struct into the conf struct because they are configuration.

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/20250504132447.e2a2535ecfd0.I21653103ff02afc5a4d97a41b68021f053985e37@changeid
parent d5861378
Loading
Loading
Loading
Loading
+18 −24
Original line number Diff line number Diff line
@@ -1233,7 +1233,6 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
	struct iwl_op_mode *op_mode;
	u16 num_mac;
	u32 ucode_flags;
	struct iwl_trans_config trans_cfg = {};
	static const u8 no_reclaim_cmds[] = {
		REPLY_RX_PHY_CMD,
		REPLY_RX_MPDU_CMD,
@@ -1310,30 +1309,31 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
	 * Populate the state variables that the transport layer needs
	 * to know about.
	 */
	trans_cfg.op_mode = op_mode;
	trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
	trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
	BUILD_BUG_ON(sizeof(no_reclaim_cmds) >
		     sizeof(trans->conf.no_reclaim_cmds));
	memcpy(trans->conf.no_reclaim_cmds, no_reclaim_cmds,
	       sizeof(no_reclaim_cmds));

	switch (iwlwifi_mod_params.amsdu_size) {
	case IWL_AMSDU_DEF:
	case IWL_AMSDU_4K:
		trans_cfg.rx_buf_size = IWL_AMSDU_4K;
		trans->conf.rx_buf_size = IWL_AMSDU_4K;
		break;
	case IWL_AMSDU_8K:
		trans_cfg.rx_buf_size = IWL_AMSDU_8K;
		trans->conf.rx_buf_size = IWL_AMSDU_8K;
		break;
	case IWL_AMSDU_12K:
	default:
		trans_cfg.rx_buf_size = IWL_AMSDU_4K;
		trans->conf.rx_buf_size = IWL_AMSDU_4K;
		pr_err("Unsupported amsdu_size: %d\n",
		       iwlwifi_mod_params.amsdu_size);
	}

	trans_cfg.command_groups = iwl_dvm_groups;
	trans_cfg.command_groups_size = ARRAY_SIZE(iwl_dvm_groups);
	trans->conf.command_groups = iwl_dvm_groups;
	trans->conf.command_groups_size = ARRAY_SIZE(iwl_dvm_groups);

	trans_cfg.cmd_fifo = IWLAGN_CMD_FIFO_NUM;
	trans_cfg.cb_data_offs = offsetof(struct ieee80211_tx_info,
	trans->conf.cmd_fifo = IWLAGN_CMD_FIFO_NUM;
	trans->conf.cb_data_offs = offsetof(struct ieee80211_tx_info,
					    driver_data[2]);

	WARN_ON(sizeof(priv->transport_queue_stop) * BITS_PER_BYTE <
@@ -1343,19 +1343,16 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,

	if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
		priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
		trans_cfg.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
		trans->conf.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
	} else {
		priv->sta_key_max_num = STA_KEY_MAX_NUM;
		trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
		trans->conf.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
	}

	/* Configure transport layer */
	iwl_trans_configure(priv->trans, &trans_cfg);
	trans->conf.rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
	trans->conf.rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);

	trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
	trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
	trans->command_groups = trans_cfg.command_groups;
	trans->command_groups_size = trans_cfg.command_groups_size;
	iwl_trans_op_mode_enter(priv->trans, op_mode);

	/* At this point both hw and priv are allocated. */

@@ -1438,10 +1435,7 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
		 * packaging bug or due to the eeprom check above
		 */
		priv->sta_key_max_num = STA_KEY_MAX_NUM;
		trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;

		/* Configure transport layer again*/
		iwl_trans_configure(priv->trans, &trans_cfg);
		trans->conf.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
	}

	/*******************
+5 −4
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
 *
 * Copyright(c) 2009 - 2014 Intel Corporation. All rights reserved.
 * Copyright(C) 2016        Intel Deutschland GmbH
 * Copyright(c) 2018, 2023  Intel Corporation
 * Copyright(c) 2018, 2023, 2025 Intel Corporation
 *****************************************************************************/

#ifndef __IWLWIFI_DEVICE_TRACE
@@ -54,11 +54,11 @@ static inline size_t iwl_rx_trace_len(const struct iwl_trans *trans,
	struct ieee80211_hdr *hdr = NULL;
	size_t hdr_offset;

	if (cmd->cmd != trans->rx_mpdu_cmd)
	if (cmd->cmd != trans->conf.rx_mpdu_cmd)
		return len;

	hdr_offset = sizeof(struct iwl_cmd_header) +
		     trans->rx_mpdu_cmd_hdr_size;
		     trans->conf.rx_mpdu_cmd_hdr_size;

	if (out_hdr_offset)
		*out_hdr_offset = hdr_offset;
@@ -67,7 +67,8 @@ static inline size_t iwl_rx_trace_len(const struct iwl_trans *trans,
	if (!ieee80211_is_data(hdr->frame_control))
		return len;
	/* maybe try to identify EAPOL frames? */
	return sizeof(__le32) + sizeof(*cmd) + trans->rx_mpdu_cmd_hdr_size +
	return sizeof(__le32) + sizeof(*cmd) +
		trans->conf.rx_mpdu_cmd_hdr_size +
		ieee80211_hdrlen(hdr->frame_control);
}

+17 −11
Original line number Diff line number Diff line
@@ -343,7 +343,7 @@ int iwl_trans_send_cmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
	if (!(cmd->flags & CMD_ASYNC))
		lock_map_acquire_read(&trans->sync_cmd_lockdep_map);

	if (trans->wide_cmd_header && !iwl_cmd_groupid(cmd->id)) {
	if (trans->conf.wide_cmd_header && !iwl_cmd_groupid(cmd->id)) {
		if (cmd->id != REPLY_ERROR)
			cmd->id = DEF_ID(cmd->id);
	}
@@ -387,11 +387,12 @@ const char *iwl_get_cmd_string(struct iwl_trans *trans, u32 id)
	grp = iwl_cmd_groupid(id);
	cmd = iwl_cmd_opcode(id);

	if (!trans->command_groups || grp >= trans->command_groups_size ||
	    !trans->command_groups[grp].arr)
	if (!trans->conf.command_groups ||
	    grp >= trans->conf.command_groups_size ||
	    !trans->conf.command_groups[grp].arr)
		return "UNKNOWN";

	arr = &trans->command_groups[grp];
	arr = &trans->conf.command_groups[grp];
	ret = bsearch(&cmd, arr->arr, arr->size, size, iwl_hcmd_names_cmp);
	if (!ret)
		return "UNKNOWN";
@@ -399,14 +400,20 @@ const char *iwl_get_cmd_string(struct iwl_trans *trans, u32 id)
}
IWL_EXPORT_SYMBOL(iwl_get_cmd_string);

void iwl_trans_configure(struct iwl_trans *trans,
			 const struct iwl_trans_config *trans_cfg)
void iwl_trans_op_mode_enter(struct iwl_trans *trans,
			     struct iwl_op_mode *op_mode)
{
	trans->op_mode = trans_cfg->op_mode;
	trans->op_mode = op_mode;

	iwl_trans_pcie_configure(trans, trans_cfg);
	if (WARN_ON(trans->conf.n_no_reclaim_cmds > MAX_NO_RECLAIM_CMDS))
		trans->conf.n_no_reclaim_cmds =
			ARRAY_SIZE(trans->conf.no_reclaim_cmds);

	WARN_ON_ONCE(!trans->conf.rx_mpdu_cmd);

	iwl_trans_pcie_op_mode_enter(trans);
}
IWL_EXPORT_SYMBOL(iwl_trans_configure);
IWL_EXPORT_SYMBOL(iwl_trans_op_mode_enter);

int iwl_trans_start_hw(struct iwl_trans *trans)
{
@@ -429,6 +436,7 @@ void iwl_trans_op_mode_leave(struct iwl_trans *trans)
	cancel_work_sync(&trans->restart.wk);

	trans->op_mode = NULL;
	memset(&trans->conf, 0, sizeof(trans->conf));

	trans->state = IWL_TRANS_NO_FW;
}
@@ -601,8 +609,6 @@ int iwl_trans_start_fw(struct iwl_trans *trans, const struct iwl_fw *fw,

	might_sleep();

	WARN_ON_ONCE(!trans->rx_mpdu_cmd);

	img = iwl_get_ucode_image(fw, ucode_type);
	if (!img)
		return -EINVAL;
+16 −20
Original line number Diff line number Diff line
@@ -390,7 +390,8 @@ struct iwl_dump_sanitize_ops {
/**
 * struct iwl_trans_config - transport configuration
 *
 * @op_mode: pointer to the upper layer.
 * These values should be set before iwl_trans_op_mode_enter().
 *
 * @cmd_queue: the index of the command queue.
 *	Must be set before start_fw.
 * @cmd_fifo: the fifo for host commands
@@ -411,14 +412,17 @@ struct iwl_dump_sanitize_ops {
 * @queue_alloc_cmd_ver: queue allocation command version, set to 0
 *	for using the older SCD_QUEUE_CFG, set to the version of
 *	SCD_QUEUE_CONFIG_CMD otherwise.
 * @wide_cmd_header: true when ucode supports wide command header format
 * @rx_mpdu_cmd: MPDU RX command ID, must be assigned by opmode before
 *	starting the firmware, used for tracing
 * @rx_mpdu_cmd_hdr_size: used for tracing, amount of data before the
 *	start of the 802.11 header in the @rx_mpdu_cmd
 */
struct iwl_trans_config {
	struct iwl_op_mode *op_mode;

	u8 cmd_queue;
	u8 cmd_fifo;
	const u8 *no_reclaim_cmds;
	unsigned int n_no_reclaim_cmds;
	u8 n_no_reclaim_cmds;
	u8 no_reclaim_cmds[MAX_NO_RECLAIM_CMDS];

	enum iwl_amsdu_size rx_buf_size;
	bool scd_set_active;
@@ -428,6 +432,9 @@ struct iwl_trans_config {
	u8 cb_data_offs;
	bool fw_reset_handshake;
	u8 queue_alloc_cmd_ver;

	bool wide_cmd_header;
	u8 rx_mpdu_cmd, rx_mpdu_cmd_hdr_size;
};

struct iwl_trans_dump_data {
@@ -839,6 +846,7 @@ struct iwl_trans_info {
 * @trans_cfg: the trans-specific configuration part
 * @cfg: pointer to the configuration
 * @drv: pointer to iwl_drv
 * @conf: configuration set by the opmode before enter
 * @state: current device state
 * @status: a bit-mask of transport status flags
 * @dev: pointer to struct device * that represents the device
@@ -850,18 +858,11 @@ struct iwl_trans_info {
 * @fail_to_parse_pnvm_image: set to true if pnvm parsing failed
 * @reduce_power_loaded: indicates reduced power section was loaded
 * @failed_to_load_reduce_power_image: set to true if pnvm loading failed
 * @command_groups: pointer to command group name list array
 * @command_groups_size: array size of @command_groups
 * @wide_cmd_header: true when ucode supports wide command header format
 * @dev_cmd_pool: pool for Tx cmd allocation - for internal use only.
 *	The user should use iwl_trans_{alloc,free}_tx_cmd.
 * @dev_cmd_pool_name: name for the TX command allocation pool
 * @dbgfs_dir: iwlwifi debugfs base dir for this device
 * @sync_cmd_lockdep_map: lockdep map for checking sync commands
 * @rx_mpdu_cmd: MPDU RX command ID, must be assigned by opmode before
 *	starting the firmware, used for tracing
 * @rx_mpdu_cmd_hdr_size: used for tracing, amount of data before the
 *	start of the 802.11 header in the @rx_mpdu_cmd
 * @dbg: additional debug data, see &struct iwl_trans_debug
 * @init_dram: FW initialization DMA data
 * @mbx_addr_0_step: step address data 0
@@ -887,6 +888,7 @@ struct iwl_trans {
	const struct iwl_cfg_trans_params *trans_cfg;
	const struct iwl_cfg *cfg;
	struct iwl_drv *drv;
	struct iwl_trans_config conf;
	enum iwl_trans_state state;
	unsigned long status;

@@ -902,8 +904,6 @@ struct iwl_trans {

	bool ext_32khz_clock_valid;

	u8 rx_mpdu_cmd, rx_mpdu_cmd_hdr_size;

	bool pm_support;
	bool ltr_enabled;
	u8 pnvm_loaded:1;
@@ -911,10 +911,6 @@ struct iwl_trans {
	u8 reduce_power_loaded:1;
	u8 failed_to_load_reduce_power_image:1;

	const struct iwl_hcmd_arr *command_groups;
	int command_groups_size;
	bool wide_cmd_header;

	/* The following fields are internal only */
	struct kmem_cache *dev_cmd_pool;
	char dev_cmd_pool_name[50];
@@ -947,8 +943,8 @@ struct iwl_trans {

const char *iwl_get_cmd_string(struct iwl_trans *trans, u32 id);

void iwl_trans_configure(struct iwl_trans *trans,
			 const struct iwl_trans_config *trans_cfg);
void iwl_trans_op_mode_enter(struct iwl_trans *trans,
			     struct iwl_op_mode *op_mode);

int iwl_trans_start_hw(struct iwl_trans *trans);

+21 −22
Original line number Diff line number Diff line
@@ -327,30 +327,29 @@ iwl_mld_configure_trans(struct iwl_op_mode *op_mode)
{
	const struct iwl_mld *mld = IWL_OP_MODE_GET_MLD(op_mode);
	static const u8 no_reclaim_cmds[] = {TX_CMD};
	struct iwl_trans_config trans_cfg = {
		.op_mode = op_mode,
		/* Rx is not supported yet, but add it to avoid warnings */
		.rx_buf_size = iwl_amsdu_size_to_rxb_size(),
		.command_groups = iwl_mld_groups,
		.command_groups_size = ARRAY_SIZE(iwl_mld_groups),
		.fw_reset_handshake = true,
		.queue_alloc_cmd_ver =
			iwl_fw_lookup_cmd_ver(mld->fw,
					      WIDE_ID(DATA_PATH_GROUP,
						      SCD_QUEUE_CONFIG_CMD),
					      0),
		.no_reclaim_cmds = no_reclaim_cmds,
		.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds),
		.cb_data_offs = offsetof(struct ieee80211_tx_info,
					 driver_data[2]),
	};
	struct iwl_trans *trans = mld->trans;

	trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
	trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
	trans->wide_cmd_header = true;

	iwl_trans_configure(trans, &trans_cfg);
	trans->conf.rx_buf_size = iwl_amsdu_size_to_rxb_size();
	trans->conf.command_groups = iwl_mld_groups;
	trans->conf.command_groups_size = ARRAY_SIZE(iwl_mld_groups);
	trans->conf.fw_reset_handshake = true;
	trans->conf.queue_alloc_cmd_ver =
		iwl_fw_lookup_cmd_ver(mld->fw, WIDE_ID(DATA_PATH_GROUP,
						       SCD_QUEUE_CONFIG_CMD),
				      0);
	trans->conf.cb_data_offs = offsetof(struct ieee80211_tx_info,
					    driver_data[2]);
	BUILD_BUG_ON(sizeof(no_reclaim_cmds) >
		     sizeof(trans->conf.no_reclaim_cmds));
	memcpy(trans->conf.no_reclaim_cmds, no_reclaim_cmds,
	       sizeof(no_reclaim_cmds));
	trans->conf.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);

	trans->conf.rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
	trans->conf.rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
	trans->conf.wide_cmd_header = true;

	iwl_trans_op_mode_enter(trans, op_mode);
}

/*
Loading