From: Johannes Berg This is all fairly manual, with the shifts etc., and the documentation has to call out the specific bits (which also isn't usable for our tracing data). Add an enum that directly declares the bit masks for it and then use the more modern u8_encode_bits(). Signed-off-by: Johannes Berg Signed-off-by: Miri Korenblit --- .../wireless/intel/iwlwifi/fw/api/location.h | 100 +++++++++--------- .../intel/iwlwifi/mld/ftm-initiator.c | 30 ++++-- .../intel/iwlwifi/mvm/ftm-initiator.c | 30 ++++-- .../intel/iwlwifi/mvm/ftm-responder.c | 32 ++++-- 4 files changed, 111 insertions(+), 81 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/location.h b/drivers/net/wireless/intel/iwlwifi/fw/api/location.h index d3f774ffacde..421ea94ace01 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/location.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/location.h @@ -88,6 +88,46 @@ enum iwl_location_subcmd_ids { TOF_RANGE_RESPONSE_NOTIF = 0xFF, }; +/** + * enum iwl_location_frame_format - location frame formats + * @IWL_LOCATION_FRAME_FORMAT_LEGACY: legacy + * @IWL_LOCATION_FRAME_FORMAT_HT: HT + * @IWL_LOCATION_FRAME_FORMAT_VHT: VHT + * @IWL_LOCATION_FRAME_FORMAT_HE: HE + */ +enum iwl_location_frame_format { + IWL_LOCATION_FRAME_FORMAT_LEGACY, + IWL_LOCATION_FRAME_FORMAT_HT, + IWL_LOCATION_FRAME_FORMAT_VHT, + IWL_LOCATION_FRAME_FORMAT_HE, +}; + +/** + * enum iwl_location_bw - location bandwidth selection + * @IWL_LOCATION_BW_20MHZ: 20 MHz + * @IWL_LOCATION_BW_40MHZ: 40 MHz + * @IWL_LOCATION_BW_80MHZ: 80 MHz + * @IWL_LOCATION_BW_160MHZ: 160 MHz + * @IWL_LOCATION_BW_320MHZ: 320 MHz + */ +enum iwl_location_bw { + IWL_LOCATION_BW_20MHZ, + IWL_LOCATION_BW_40MHZ, + IWL_LOCATION_BW_80MHZ, + IWL_LOCATION_BW_160MHZ, + IWL_LOCATION_BW_320MHZ, +}; + +/** + * enum iwl_location_format_bw - format/BW encoding + * @IWL_LOCATION_FMT_BW_FORMAT: &enum iwl_location_frame_format + * @IWL_LOCATION_FMT_BW_BANDWIDTH: &enum iwl_location_bw + */ +enum iwl_location_format_bw { + IWL_LOCATION_FMT_BW_FORMAT = 0x0f, + IWL_LOCATION_FMT_BW_BANDWIDTH = 0xf0, +}; + /** * struct iwl_tof_config_cmd - ToF configuration * @tof_disabled: indicates if ToF is disabled (or not) @@ -264,8 +304,7 @@ struct iwl_tof_responder_config_cmd_v6 { * struct iwl_tof_responder_config_cmd_v7 - ToF AP mode (for debug) * @cmd_valid_fields: &iwl_tof_responder_cmd_valid_field * @responder_cfg_flags: &iwl_tof_responder_cfg_flags - * @format_bw: bits 0 - 3: &enum iwl_location_frame_format. - * bits 4 - 7: &enum iwl_location_bw. + * @format_bw: &enum iwl_location_format_bw * @rate: current AP rate * @channel_num: current AP Channel * @ctrl_ch_position: coding of the control channel position relative to @@ -303,8 +342,7 @@ struct iwl_tof_responder_config_cmd_v7 { * struct iwl_tof_responder_config_cmd_v8 - ToF AP mode (for debug) * @cmd_valid_fields: &iwl_tof_responder_cmd_valid_field * @responder_cfg_flags: &iwl_tof_responder_cfg_flags - * @format_bw: bits 0 - 3: &enum iwl_location_frame_format. - * bits 4 - 7: &enum iwl_location_bw. + * @format_bw: &enum iwl_location_format_bw * @rate: current AP rate * @channel_num: current AP Channel * @ctrl_ch_position: coding of the control channel position relative to @@ -349,8 +387,7 @@ struct iwl_tof_responder_config_cmd_v8 { * struct iwl_tof_responder_config_cmd_v9 - ToF AP mode (for debug) * @cmd_valid_fields: &iwl_tof_responder_cmd_valid_field * @responder_cfg_flags: &iwl_tof_responder_cfg_flags - * @format_bw: bits 0 - 3: &enum iwl_location_frame_format. - * bits 4 - 7: &enum iwl_location_bw. + * @format_bw: &enum iwl_location_format_bw * @bss_color: current AP bss_color * @channel_num: current AP Channel * @ctrl_ch_position: coding of the control channel position relative to @@ -401,8 +438,7 @@ struct iwl_tof_responder_config_cmd_v9 { * struct iwl_tof_responder_config_cmd - ToF AP mode * @cmd_valid_fields: &iwl_tof_responder_cmd_valid_field * @responder_cfg_flags: &iwl_tof_responder_cfg_flags - * @format_bw: bits 0 - 3: &enum iwl_location_frame_format. - * bits 4 - 7: &enum iwl_location_bw. + * @format_bw: &enum iwl_location_format_bw * @bss_color: current AP bss_color * @channel_num: current AP Channel * @ctrl_ch_position: coding of the control channel position relative to @@ -677,44 +713,13 @@ struct iwl_tof_range_req_ap_entry_v3 { __le32 tsf_delta; } __packed; /* LOCATION_RANGE_REQ_AP_ENTRY_CMD_API_S_VER_3 */ -/** - * enum iwl_location_frame_format - location frame formats - * @IWL_LOCATION_FRAME_FORMAT_LEGACY: legacy - * @IWL_LOCATION_FRAME_FORMAT_HT: HT - * @IWL_LOCATION_FRAME_FORMAT_VHT: VHT - * @IWL_LOCATION_FRAME_FORMAT_HE: HE - */ -enum iwl_location_frame_format { - IWL_LOCATION_FRAME_FORMAT_LEGACY, - IWL_LOCATION_FRAME_FORMAT_HT, - IWL_LOCATION_FRAME_FORMAT_VHT, - IWL_LOCATION_FRAME_FORMAT_HE, -}; - -/** - * enum iwl_location_bw - location bandwidth selection - * @IWL_LOCATION_BW_20MHZ: 20MHz - * @IWL_LOCATION_BW_40MHZ: 40MHz - * @IWL_LOCATION_BW_80MHZ: 80MHz - * @IWL_LOCATION_BW_160MHZ: 160MHz - */ -enum iwl_location_bw { - IWL_LOCATION_BW_20MHZ, - IWL_LOCATION_BW_40MHZ, - IWL_LOCATION_BW_80MHZ, - IWL_LOCATION_BW_160MHZ, -}; - #define TK_11AZ_LEN 32 -#define LOCATION_BW_POS 4 - /** * struct iwl_tof_range_req_ap_entry_v4 - AP configuration parameters * @initiator_ap_flags: see &enum iwl_initiator_ap_flags. * @channel_num: AP Channel number - * @format_bw: bits 0 - 3: &enum iwl_location_frame_format. - * bits 4 - 7: &enum iwl_location_bw. + * @format_bw: &enum iwl_location_format_bw * @ctrl_ch_position: Coding of the control channel position relative to the * center frequency, see iwl_mvm_get_ctrl_pos(). * @ftmr_max_retries: Max number of retries to send the FTMR in case of no @@ -764,8 +769,7 @@ enum iwl_location_cipher { * struct iwl_tof_range_req_ap_entry_v6 - AP configuration parameters * @initiator_ap_flags: see &enum iwl_initiator_ap_flags. * @channel_num: AP Channel number - * @format_bw: bits 0 - 3: &enum iwl_location_frame_format. - * bits 4 - 7: &enum iwl_location_bw. + * @format_bw: &enum iwl_location_format_bw * @ctrl_ch_position: Coding of the control channel position relative to the * center frequency, see iwl_mvm_get_ctrl_pos(). * @ftmr_max_retries: Max number of retries to send the FTMR in case of no @@ -811,8 +815,7 @@ struct iwl_tof_range_req_ap_entry_v6 { * struct iwl_tof_range_req_ap_entry_v7 - AP configuration parameters * @initiator_ap_flags: see &enum iwl_initiator_ap_flags. * @channel_num: AP Channel number - * @format_bw: bits 0 - 3: &enum iwl_location_frame_format. - * bits 4 - 7: &enum iwl_location_bw. + * @format_bw: &enum iwl_location_format_bw * @ctrl_ch_position: Coding of the control channel position relative to the * center frequency, see iwl_mvm_get_ctrl_pos(). * @ftmr_max_retries: Max number of retries to send the FTMR in case of no @@ -869,8 +872,7 @@ struct iwl_tof_range_req_ap_entry_v7 { * struct iwl_tof_range_req_ap_entry_v8 - AP configuration parameters * @initiator_ap_flags: see &enum iwl_initiator_ap_flags. * @channel_num: AP Channel number - * @format_bw: bits 0 - 3: &enum iwl_location_frame_format. - * bits 4 - 7: &enum iwl_location_bw. + * @format_bw: &enum iwl_location_format_bw * @ctrl_ch_position: Coding of the control channel position relative to the * center frequency, see iwl_mvm_get_ctrl_pos(). * @ftmr_max_retries: Max number of retries to send the FTMR in case of no @@ -940,8 +942,7 @@ struct iwl_tof_range_req_ap_entry_v8 { * struct iwl_tof_range_req_ap_entry_v9 - AP configuration parameters * @initiator_ap_flags: see &enum iwl_initiator_ap_flags. * @channel_num: AP Channel number - * @format_bw: bits 0 - 3: &enum iwl_location_frame_format. - * bits 4 - 7: &enum iwl_location_bw. + * @format_bw: &enum iwl_location_format_bw * @ctrl_ch_position: Coding of the control channel position relative to the * center frequency, see iwl_mvm_get_ctrl_pos(). * @ftmr_max_retries: Max number of retries to send the FTMR in case of no @@ -1025,8 +1026,7 @@ struct iwl_tof_range_req_ap_entry_v9 { * @initiator_ap_flags: see &enum iwl_initiator_ap_flags. * @band: 0 for 5.2 GHz, 1 for 2.4 GHz, 2 for 6GHz * @channel_num: AP Channel number - * @format_bw: bits 0 - 3: &enum iwl_location_frame_format. - * bits 4 - 7: &enum iwl_location_bw. + * @format_bw: &enum iwl_location_format_bw * @ctrl_ch_position: Coding of the control channel position relative to the * center frequency, see iwl_mvm_get_ctrl_pos(). * @bssid: AP's BSSID diff --git a/drivers/net/wireless/intel/iwlwifi/mld/ftm-initiator.c b/drivers/net/wireless/intel/iwlwifi/mld/ftm-initiator.c index 3464b3268712..81df3fdfcbf5 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/ftm-initiator.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/ftm-initiator.c @@ -71,24 +71,34 @@ iwl_mld_ftm_set_target_chandef(struct iwl_mld *mld, switch (peer->chandef.width) { case NL80211_CHAN_WIDTH_20_NOHT: - target->format_bw = IWL_LOCATION_FRAME_FORMAT_LEGACY; - target->format_bw |= IWL_LOCATION_BW_20MHZ << LOCATION_BW_POS; + target->format_bw = u8_encode_bits(IWL_LOCATION_FRAME_FORMAT_LEGACY, + IWL_LOCATION_FMT_BW_FORMAT); + target->format_bw |= u8_encode_bits(IWL_LOCATION_BW_20MHZ, + IWL_LOCATION_FMT_BW_BANDWIDTH); break; case NL80211_CHAN_WIDTH_20: - target->format_bw = IWL_LOCATION_FRAME_FORMAT_HT; - target->format_bw |= IWL_LOCATION_BW_20MHZ << LOCATION_BW_POS; + target->format_bw = u8_encode_bits(IWL_LOCATION_FRAME_FORMAT_HT, + IWL_LOCATION_FMT_BW_FORMAT); + target->format_bw |= u8_encode_bits(IWL_LOCATION_BW_20MHZ, + IWL_LOCATION_FMT_BW_BANDWIDTH); break; case NL80211_CHAN_WIDTH_40: - target->format_bw = IWL_LOCATION_FRAME_FORMAT_HT; - target->format_bw |= IWL_LOCATION_BW_40MHZ << LOCATION_BW_POS; + target->format_bw = u8_encode_bits(IWL_LOCATION_FRAME_FORMAT_HT, + IWL_LOCATION_FMT_BW_FORMAT); + target->format_bw |= u8_encode_bits(IWL_LOCATION_BW_40MHZ, + IWL_LOCATION_FMT_BW_BANDWIDTH); break; case NL80211_CHAN_WIDTH_80: - target->format_bw = IWL_LOCATION_FRAME_FORMAT_VHT; - target->format_bw |= IWL_LOCATION_BW_80MHZ << LOCATION_BW_POS; + target->format_bw = u8_encode_bits(IWL_LOCATION_FRAME_FORMAT_VHT, + IWL_LOCATION_FMT_BW_FORMAT); + target->format_bw |= u8_encode_bits(IWL_LOCATION_BW_80MHZ, + IWL_LOCATION_FMT_BW_BANDWIDTH); break; case NL80211_CHAN_WIDTH_160: - target->format_bw = IWL_LOCATION_FRAME_FORMAT_HE; - target->format_bw |= IWL_LOCATION_BW_160MHZ << LOCATION_BW_POS; + target->format_bw = u8_encode_bits(IWL_LOCATION_FRAME_FORMAT_HE, + IWL_LOCATION_FMT_BW_FORMAT); + target->format_bw |= u8_encode_bits(IWL_LOCATION_BW_160MHZ, + IWL_LOCATION_FMT_BW_BANDWIDTH); break; default: IWL_ERR(mld, "Unsupported BW in FTM request (%d)\n", diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c b/drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c index 1b67836b1fac..3a14ca5e512a 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c @@ -261,20 +261,28 @@ iwl_mvm_ftm_target_chandef_v2(struct iwl_mvm *mvm, switch (peer->chandef.width) { case NL80211_CHAN_WIDTH_20_NOHT: - *format_bw = IWL_LOCATION_FRAME_FORMAT_LEGACY; - *format_bw |= IWL_LOCATION_BW_20MHZ << LOCATION_BW_POS; + *format_bw = u8_encode_bits(IWL_LOCATION_FRAME_FORMAT_LEGACY, + IWL_LOCATION_FMT_BW_FORMAT); + *format_bw |= u8_encode_bits(IWL_LOCATION_BW_20MHZ, + IWL_LOCATION_FMT_BW_BANDWIDTH); break; case NL80211_CHAN_WIDTH_20: - *format_bw = IWL_LOCATION_FRAME_FORMAT_HT; - *format_bw |= IWL_LOCATION_BW_20MHZ << LOCATION_BW_POS; + *format_bw = u8_encode_bits(IWL_LOCATION_FRAME_FORMAT_HT, + IWL_LOCATION_FMT_BW_FORMAT); + *format_bw |= u8_encode_bits(IWL_LOCATION_BW_20MHZ, + IWL_LOCATION_FMT_BW_BANDWIDTH); break; case NL80211_CHAN_WIDTH_40: - *format_bw = IWL_LOCATION_FRAME_FORMAT_HT; - *format_bw |= IWL_LOCATION_BW_40MHZ << LOCATION_BW_POS; + *format_bw = u8_encode_bits(IWL_LOCATION_FRAME_FORMAT_HT, + IWL_LOCATION_FMT_BW_FORMAT); + *format_bw |= u8_encode_bits(IWL_LOCATION_BW_40MHZ, + IWL_LOCATION_FMT_BW_BANDWIDTH); break; case NL80211_CHAN_WIDTH_80: - *format_bw = IWL_LOCATION_FRAME_FORMAT_VHT; - *format_bw |= IWL_LOCATION_BW_80MHZ << LOCATION_BW_POS; + *format_bw = u8_encode_bits(IWL_LOCATION_FRAME_FORMAT_VHT, + IWL_LOCATION_FMT_BW_FORMAT); + *format_bw |= u8_encode_bits(IWL_LOCATION_BW_80MHZ, + IWL_LOCATION_FMT_BW_BANDWIDTH); break; case NL80211_CHAN_WIDTH_160: cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, @@ -282,8 +290,10 @@ iwl_mvm_ftm_target_chandef_v2(struct iwl_mvm *mvm, IWL_FW_CMD_VER_UNKNOWN); if (cmd_ver >= 13) { - *format_bw = IWL_LOCATION_FRAME_FORMAT_HE; - *format_bw |= IWL_LOCATION_BW_160MHZ << LOCATION_BW_POS; + *format_bw = u8_encode_bits(IWL_LOCATION_FRAME_FORMAT_HE, + IWL_LOCATION_FMT_BW_FORMAT); + *format_bw |= u8_encode_bits(IWL_LOCATION_BW_160MHZ, + IWL_LOCATION_FMT_BW_BANDWIDTH); break; } fallthrough; diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/ftm-responder.c b/drivers/net/wireless/intel/iwlwifi/mvm/ftm-responder.c index 83f6e508a094..ae7a163c81c9 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/ftm-responder.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/ftm-responder.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* * Copyright (C) 2015-2017 Intel Deutschland GmbH - * Copyright (C) 2018-2024 Intel Corporation + * Copyright (C) 2018-2024, 2026 Intel Corporation */ #include #include @@ -54,27 +54,37 @@ static int iwl_mvm_ftm_responder_set_bw_v2(struct cfg80211_chan_def *chandef, { switch (chandef->width) { case NL80211_CHAN_WIDTH_20_NOHT: - *format_bw = IWL_LOCATION_FRAME_FORMAT_LEGACY; - *format_bw |= IWL_LOCATION_BW_20MHZ << LOCATION_BW_POS; + *format_bw = u8_encode_bits(IWL_LOCATION_FRAME_FORMAT_LEGACY, + IWL_LOCATION_FMT_BW_FORMAT); + *format_bw |= u8_encode_bits(IWL_LOCATION_BW_20MHZ, + IWL_LOCATION_FMT_BW_BANDWIDTH); break; case NL80211_CHAN_WIDTH_20: - *format_bw = IWL_LOCATION_FRAME_FORMAT_HT; - *format_bw |= IWL_LOCATION_BW_20MHZ << LOCATION_BW_POS; + *format_bw = u8_encode_bits(IWL_LOCATION_FRAME_FORMAT_HT, + IWL_LOCATION_FMT_BW_FORMAT); + *format_bw |= u8_encode_bits(IWL_LOCATION_BW_20MHZ, + IWL_LOCATION_FMT_BW_BANDWIDTH); break; case NL80211_CHAN_WIDTH_40: - *format_bw = IWL_LOCATION_FRAME_FORMAT_HT; - *format_bw |= IWL_LOCATION_BW_40MHZ << LOCATION_BW_POS; + *format_bw = u8_encode_bits(IWL_LOCATION_FRAME_FORMAT_HT, + IWL_LOCATION_FMT_BW_FORMAT); + *format_bw |= u8_encode_bits(IWL_LOCATION_BW_40MHZ, + IWL_LOCATION_FMT_BW_BANDWIDTH); *ctrl_ch_position = iwl_mvm_get_ctrl_pos(chandef); break; case NL80211_CHAN_WIDTH_80: - *format_bw = IWL_LOCATION_FRAME_FORMAT_VHT; - *format_bw |= IWL_LOCATION_BW_80MHZ << LOCATION_BW_POS; + *format_bw = u8_encode_bits(IWL_LOCATION_FRAME_FORMAT_VHT, + IWL_LOCATION_FMT_BW_FORMAT); + *format_bw |= u8_encode_bits(IWL_LOCATION_BW_80MHZ, + IWL_LOCATION_FMT_BW_BANDWIDTH); *ctrl_ch_position = iwl_mvm_get_ctrl_pos(chandef); break; case NL80211_CHAN_WIDTH_160: if (cmd_ver >= 9) { - *format_bw = IWL_LOCATION_FRAME_FORMAT_HE; - *format_bw |= IWL_LOCATION_BW_160MHZ << LOCATION_BW_POS; + *format_bw = u8_encode_bits(IWL_LOCATION_FRAME_FORMAT_HE, + IWL_LOCATION_FMT_BW_FORMAT); + *format_bw |= u8_encode_bits(IWL_LOCATION_BW_160MHZ, + IWL_LOCATION_FMT_BW_BANDWIDTH); *ctrl_ch_position = iwl_mvm_get_ctrl_pos(chandef); break; } -- 2.34.1