Skip to content

Commit 08e77d5

Browse files
jmberg-intelMiriam-Rachel
authored andcommitted
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: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com> Link: https://patch.msgid.link/20250504132447.e2a2535ecfd0.I21653103ff02afc5a4d97a41b68021f053985e37@changeid
1 parent d586137 commit 08e77d5

File tree

15 files changed

+169
-223
lines changed

15 files changed

+169
-223
lines changed

drivers/net/wireless/intel/iwlwifi/dvm/main.c

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,6 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
12331233
struct iwl_op_mode *op_mode;
12341234
u16 num_mac;
12351235
u32 ucode_flags;
1236-
struct iwl_trans_config trans_cfg = {};
12371236
static const u8 no_reclaim_cmds[] = {
12381237
REPLY_RX_PHY_CMD,
12391238
REPLY_RX_MPDU_CMD,
@@ -1310,31 +1309,32 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
13101309
* Populate the state variables that the transport layer needs
13111310
* to know about.
13121311
*/
1313-
trans_cfg.op_mode = op_mode;
1314-
trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
1315-
trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
1312+
BUILD_BUG_ON(sizeof(no_reclaim_cmds) >
1313+
sizeof(trans->conf.no_reclaim_cmds));
1314+
memcpy(trans->conf.no_reclaim_cmds, no_reclaim_cmds,
1315+
sizeof(no_reclaim_cmds));
13161316

13171317
switch (iwlwifi_mod_params.amsdu_size) {
13181318
case IWL_AMSDU_DEF:
13191319
case IWL_AMSDU_4K:
1320-
trans_cfg.rx_buf_size = IWL_AMSDU_4K;
1320+
trans->conf.rx_buf_size = IWL_AMSDU_4K;
13211321
break;
13221322
case IWL_AMSDU_8K:
1323-
trans_cfg.rx_buf_size = IWL_AMSDU_8K;
1323+
trans->conf.rx_buf_size = IWL_AMSDU_8K;
13241324
break;
13251325
case IWL_AMSDU_12K:
13261326
default:
1327-
trans_cfg.rx_buf_size = IWL_AMSDU_4K;
1327+
trans->conf.rx_buf_size = IWL_AMSDU_4K;
13281328
pr_err("Unsupported amsdu_size: %d\n",
13291329
iwlwifi_mod_params.amsdu_size);
13301330
}
13311331

1332-
trans_cfg.command_groups = iwl_dvm_groups;
1333-
trans_cfg.command_groups_size = ARRAY_SIZE(iwl_dvm_groups);
1332+
trans->conf.command_groups = iwl_dvm_groups;
1333+
trans->conf.command_groups_size = ARRAY_SIZE(iwl_dvm_groups);
13341334

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

13391339
WARN_ON(sizeof(priv->transport_queue_stop) * BITS_PER_BYTE <
13401340
priv->trans->trans_cfg->base_params->num_of_queues);
@@ -1343,19 +1343,16 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
13431343

13441344
if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
13451345
priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
1346-
trans_cfg.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
1346+
trans->conf.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
13471347
} else {
13481348
priv->sta_key_max_num = STA_KEY_MAX_NUM;
1349-
trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
1349+
trans->conf.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
13501350
}
13511351

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

1355-
trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
1356-
trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
1357-
trans->command_groups = trans_cfg.command_groups;
1358-
trans->command_groups_size = trans_cfg.command_groups_size;
1355+
iwl_trans_op_mode_enter(priv->trans, op_mode);
13591356

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

@@ -1438,10 +1435,7 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
14381435
* packaging bug or due to the eeprom check above
14391436
*/
14401437
priv->sta_key_max_num = STA_KEY_MAX_NUM;
1441-
trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
1442-
1443-
/* Configure transport layer again*/
1444-
iwl_trans_configure(priv->trans, &trans_cfg);
1438+
trans->conf.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
14451439
}
14461440

14471441
/*******************

drivers/net/wireless/intel/iwlwifi/iwl-devtrace.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright(c) 2009 - 2014 Intel Corporation. All rights reserved.
55
* Copyright(C) 2016 Intel Deutschland GmbH
6-
* Copyright(c) 2018, 2023 Intel Corporation
6+
* Copyright(c) 2018, 2023, 2025 Intel Corporation
77
*****************************************************************************/
88

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

57-
if (cmd->cmd != trans->rx_mpdu_cmd)
57+
if (cmd->cmd != trans->conf.rx_mpdu_cmd)
5858
return len;
5959

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

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

drivers/net/wireless/intel/iwlwifi/iwl-trans.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ int iwl_trans_send_cmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
343343
if (!(cmd->flags & CMD_ASYNC))
344344
lock_map_acquire_read(&trans->sync_cmd_lockdep_map);
345345

346-
if (trans->wide_cmd_header && !iwl_cmd_groupid(cmd->id)) {
346+
if (trans->conf.wide_cmd_header && !iwl_cmd_groupid(cmd->id)) {
347347
if (cmd->id != REPLY_ERROR)
348348
cmd->id = DEF_ID(cmd->id);
349349
}
@@ -387,26 +387,33 @@ const char *iwl_get_cmd_string(struct iwl_trans *trans, u32 id)
387387
grp = iwl_cmd_groupid(id);
388388
cmd = iwl_cmd_opcode(id);
389389

390-
if (!trans->command_groups || grp >= trans->command_groups_size ||
391-
!trans->command_groups[grp].arr)
390+
if (!trans->conf.command_groups ||
391+
grp >= trans->conf.command_groups_size ||
392+
!trans->conf.command_groups[grp].arr)
392393
return "UNKNOWN";
393394

394-
arr = &trans->command_groups[grp];
395+
arr = &trans->conf.command_groups[grp];
395396
ret = bsearch(&cmd, arr->arr, arr->size, size, iwl_hcmd_names_cmp);
396397
if (!ret)
397398
return "UNKNOWN";
398399
return ret->cmd_name;
399400
}
400401
IWL_EXPORT_SYMBOL(iwl_get_cmd_string);
401402

402-
void iwl_trans_configure(struct iwl_trans *trans,
403-
const struct iwl_trans_config *trans_cfg)
403+
void iwl_trans_op_mode_enter(struct iwl_trans *trans,
404+
struct iwl_op_mode *op_mode)
404405
{
405-
trans->op_mode = trans_cfg->op_mode;
406+
trans->op_mode = op_mode;
406407

407-
iwl_trans_pcie_configure(trans, trans_cfg);
408+
if (WARN_ON(trans->conf.n_no_reclaim_cmds > MAX_NO_RECLAIM_CMDS))
409+
trans->conf.n_no_reclaim_cmds =
410+
ARRAY_SIZE(trans->conf.no_reclaim_cmds);
411+
412+
WARN_ON_ONCE(!trans->conf.rx_mpdu_cmd);
413+
414+
iwl_trans_pcie_op_mode_enter(trans);
408415
}
409-
IWL_EXPORT_SYMBOL(iwl_trans_configure);
416+
IWL_EXPORT_SYMBOL(iwl_trans_op_mode_enter);
410417

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

431438
trans->op_mode = NULL;
439+
memset(&trans->conf, 0, sizeof(trans->conf));
432440

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

602610
might_sleep();
603611

604-
WARN_ON_ONCE(!trans->rx_mpdu_cmd);
605-
606612
img = iwl_get_ucode_image(fw, ucode_type);
607613
if (!img)
608614
return -EINVAL;

drivers/net/wireless/intel/iwlwifi/iwl-trans.h

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ struct iwl_dump_sanitize_ops {
390390
/**
391391
* struct iwl_trans_config - transport configuration
392392
*
393-
* @op_mode: pointer to the upper layer.
393+
* These values should be set before iwl_trans_op_mode_enter().
394+
*
394395
* @cmd_queue: the index of the command queue.
395396
* Must be set before start_fw.
396397
* @cmd_fifo: the fifo for host commands
@@ -411,14 +412,17 @@ struct iwl_dump_sanitize_ops {
411412
* @queue_alloc_cmd_ver: queue allocation command version, set to 0
412413
* for using the older SCD_QUEUE_CFG, set to the version of
413414
* SCD_QUEUE_CONFIG_CMD otherwise.
415+
* @wide_cmd_header: true when ucode supports wide command header format
416+
* @rx_mpdu_cmd: MPDU RX command ID, must be assigned by opmode before
417+
* starting the firmware, used for tracing
418+
* @rx_mpdu_cmd_hdr_size: used for tracing, amount of data before the
419+
* start of the 802.11 header in the @rx_mpdu_cmd
414420
*/
415421
struct iwl_trans_config {
416-
struct iwl_op_mode *op_mode;
417-
418422
u8 cmd_queue;
419423
u8 cmd_fifo;
420-
const u8 *no_reclaim_cmds;
421-
unsigned int n_no_reclaim_cmds;
424+
u8 n_no_reclaim_cmds;
425+
u8 no_reclaim_cmds[MAX_NO_RECLAIM_CMDS];
422426

423427
enum iwl_amsdu_size rx_buf_size;
424428
bool scd_set_active;
@@ -428,6 +432,9 @@ struct iwl_trans_config {
428432
u8 cb_data_offs;
429433
bool fw_reset_handshake;
430434
u8 queue_alloc_cmd_ver;
435+
436+
bool wide_cmd_header;
437+
u8 rx_mpdu_cmd, rx_mpdu_cmd_hdr_size;
431438
};
432439

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

@@ -902,19 +904,13 @@ struct iwl_trans {
902904

903905
bool ext_32khz_clock_valid;
904906

905-
u8 rx_mpdu_cmd, rx_mpdu_cmd_hdr_size;
906-
907907
bool pm_support;
908908
bool ltr_enabled;
909909
u8 pnvm_loaded:1;
910910
u8 fail_to_parse_pnvm_image:1;
911911
u8 reduce_power_loaded:1;
912912
u8 failed_to_load_reduce_power_image:1;
913913

914-
const struct iwl_hcmd_arr *command_groups;
915-
int command_groups_size;
916-
bool wide_cmd_header;
917-
918914
/* The following fields are internal only */
919915
struct kmem_cache *dev_cmd_pool;
920916
char dev_cmd_pool_name[50];
@@ -947,8 +943,8 @@ struct iwl_trans {
947943

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

950-
void iwl_trans_configure(struct iwl_trans *trans,
951-
const struct iwl_trans_config *trans_cfg);
946+
void iwl_trans_op_mode_enter(struct iwl_trans *trans,
947+
struct iwl_op_mode *op_mode);
952948

953949
int iwl_trans_start_hw(struct iwl_trans *trans);
954950

drivers/net/wireless/intel/iwlwifi/mld/mld.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -327,30 +327,29 @@ iwl_mld_configure_trans(struct iwl_op_mode *op_mode)
327327
{
328328
const struct iwl_mld *mld = IWL_OP_MODE_GET_MLD(op_mode);
329329
static const u8 no_reclaim_cmds[] = {TX_CMD};
330-
struct iwl_trans_config trans_cfg = {
331-
.op_mode = op_mode,
332-
/* Rx is not supported yet, but add it to avoid warnings */
333-
.rx_buf_size = iwl_amsdu_size_to_rxb_size(),
334-
.command_groups = iwl_mld_groups,
335-
.command_groups_size = ARRAY_SIZE(iwl_mld_groups),
336-
.fw_reset_handshake = true,
337-
.queue_alloc_cmd_ver =
338-
iwl_fw_lookup_cmd_ver(mld->fw,
339-
WIDE_ID(DATA_PATH_GROUP,
340-
SCD_QUEUE_CONFIG_CMD),
341-
0),
342-
.no_reclaim_cmds = no_reclaim_cmds,
343-
.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds),
344-
.cb_data_offs = offsetof(struct ieee80211_tx_info,
345-
driver_data[2]),
346-
};
347330
struct iwl_trans *trans = mld->trans;
348331

349-
trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
350-
trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
351-
trans->wide_cmd_header = true;
352-
353-
iwl_trans_configure(trans, &trans_cfg);
332+
trans->conf.rx_buf_size = iwl_amsdu_size_to_rxb_size();
333+
trans->conf.command_groups = iwl_mld_groups;
334+
trans->conf.command_groups_size = ARRAY_SIZE(iwl_mld_groups);
335+
trans->conf.fw_reset_handshake = true;
336+
trans->conf.queue_alloc_cmd_ver =
337+
iwl_fw_lookup_cmd_ver(mld->fw, WIDE_ID(DATA_PATH_GROUP,
338+
SCD_QUEUE_CONFIG_CMD),
339+
0);
340+
trans->conf.cb_data_offs = offsetof(struct ieee80211_tx_info,
341+
driver_data[2]);
342+
BUILD_BUG_ON(sizeof(no_reclaim_cmds) >
343+
sizeof(trans->conf.no_reclaim_cmds));
344+
memcpy(trans->conf.no_reclaim_cmds, no_reclaim_cmds,
345+
sizeof(no_reclaim_cmds));
346+
trans->conf.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
347+
348+
trans->conf.rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
349+
trans->conf.rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
350+
trans->conf.wide_cmd_header = true;
351+
352+
iwl_trans_op_mode_enter(trans, op_mode);
354353
}
355354

356355
/*

drivers/net/wireless/intel/iwlwifi/mld/tests/hcmd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* KUnit tests for channel helper functions
44
*
5-
* Copyright (C) 2024 Intel Corporation
5+
* Copyright (C) 2024-2025 Intel Corporation
66
*/
77
#include <kunit/test.h>
88

@@ -30,10 +30,10 @@ static void test_hcmd_names_sorted(struct kunit *test)
3030
static void test_hcmd_names_for_rx(struct kunit *test)
3131
{
3232
static struct iwl_trans t = {
33-
.command_groups = iwl_mld_groups,
33+
.conf.command_groups = iwl_mld_groups,
3434
};
3535

36-
t.command_groups_size = global_iwl_mld_goups_size;
36+
t.conf.command_groups_size = global_iwl_mld_goups_size;
3737

3838
for (unsigned int i = 0; i < iwl_mld_rx_handlers_num; i++) {
3939
const struct iwl_rx_handler *rxh;

0 commit comments

Comments
 (0)