Commit b363614c authored by Baochen Qiang's avatar Baochen Qiang Committed by Kalle Valo

wifi: ath11k: refactor setting country code logic

ath11k_wmi_send_set_current_country_cmd() is called in several places
and all of them are just simply repeating the same logic.

Refactor to make code clean.

Compile tested only.
Signed-off-by: default avatarBaochen Qiang <quic_bqiang@quicinc.com>
Signed-off-by: default avatarKalle Valo <quic_kvalo@quicinc.com>
Link: https://msgid.link/20240520024148.5472-2-quic_bqiang@quicinc.com
parent 35864b62
...@@ -1978,23 +1978,20 @@ static void ath11k_update_11d(struct work_struct *work) ...@@ -1978,23 +1978,20 @@ static void ath11k_update_11d(struct work_struct *work)
struct ath11k_base *ab = container_of(work, struct ath11k_base, update_11d_work); struct ath11k_base *ab = container_of(work, struct ath11k_base, update_11d_work);
struct ath11k *ar; struct ath11k *ar;
struct ath11k_pdev *pdev; struct ath11k_pdev *pdev;
struct wmi_set_current_country_params set_current_param = {};
int ret, i; int ret, i;
spin_lock_bh(&ab->base_lock);
memcpy(&set_current_param.alpha2, &ab->new_alpha2, 2);
spin_unlock_bh(&ab->base_lock);
ath11k_dbg(ab, ATH11K_DBG_WMI, "update 11d new cc %c%c\n",
set_current_param.alpha2[0],
set_current_param.alpha2[1]);
for (i = 0; i < ab->num_radios; i++) { for (i = 0; i < ab->num_radios; i++) {
pdev = &ab->pdevs[i]; pdev = &ab->pdevs[i];
ar = pdev->ar; ar = pdev->ar;
memcpy(&ar->alpha2, &set_current_param.alpha2, 2); spin_lock_bh(&ab->base_lock);
ret = ath11k_wmi_send_set_current_country_cmd(ar, &set_current_param); memcpy(&ar->alpha2, &ab->new_alpha2, 2);
spin_unlock_bh(&ab->base_lock);
ath11k_dbg(ab, ATH11K_DBG_WMI, "update 11d new cc %c%c for pdev %d\n",
ar->alpha2[0], ar->alpha2[1], i);
ret = ath11k_reg_set_cc(ar);
if (ret) if (ret)
ath11k_warn(ar->ab, ath11k_warn(ar->ab,
"pdev id %d failed set current country code: %d\n", "pdev id %d failed set current country code: %d\n",
......
...@@ -8864,12 +8864,8 @@ ath11k_mac_op_reconfig_complete(struct ieee80211_hw *hw, ...@@ -8864,12 +8864,8 @@ ath11k_mac_op_reconfig_complete(struct ieee80211_hw *hw,
ieee80211_wake_queues(ar->hw); ieee80211_wake_queues(ar->hw);
if (ar->ab->hw_params.current_cc_support && if (ar->ab->hw_params.current_cc_support &&
ar->alpha2[0] != 0 && ar->alpha2[1] != 0) { ar->alpha2[0] != 0 && ar->alpha2[1] != 0)
struct wmi_set_current_country_params set_current_param = {}; ath11k_reg_set_cc(ar);
memcpy(&set_current_param.alpha2, ar->alpha2, 2);
ath11k_wmi_send_set_current_country_cmd(ar, &set_current_param);
}
if (ab->is_reset) { if (ab->is_reset) {
recovery_count = atomic_inc_return(&ab->recovery_count); recovery_count = atomic_inc_return(&ab->recovery_count);
...@@ -10311,11 +10307,8 @@ static int __ath11k_mac_register(struct ath11k *ar) ...@@ -10311,11 +10307,8 @@ static int __ath11k_mac_register(struct ath11k *ar)
} }
if (ab->hw_params.current_cc_support && ab->new_alpha2[0]) { if (ab->hw_params.current_cc_support && ab->new_alpha2[0]) {
struct wmi_set_current_country_params set_current_param = {};
memcpy(&set_current_param.alpha2, ab->new_alpha2, 2);
memcpy(&ar->alpha2, ab->new_alpha2, 2); memcpy(&ar->alpha2, ab->new_alpha2, 2);
ret = ath11k_wmi_send_set_current_country_cmd(ar, &set_current_param); ret = ath11k_reg_set_cc(ar);
if (ret) if (ret)
ath11k_warn(ar->ab, ath11k_warn(ar->ab,
"failed set cc code for mac register: %d\n", ret); "failed set cc code for mac register: %d\n", ret);
......
...@@ -49,7 +49,6 @@ ath11k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request) ...@@ -49,7 +49,6 @@ ath11k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request)
{ {
struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
struct wmi_init_country_params init_country_param; struct wmi_init_country_params init_country_param;
struct wmi_set_current_country_params set_current_param = {};
struct ath11k *ar = hw->priv; struct ath11k *ar = hw->priv;
int ret; int ret;
...@@ -83,9 +82,8 @@ ath11k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request) ...@@ -83,9 +82,8 @@ ath11k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request)
* reg info * reg info
*/ */
if (ar->ab->hw_params.current_cc_support) { if (ar->ab->hw_params.current_cc_support) {
memcpy(&set_current_param.alpha2, request->alpha2, 2); memcpy(&ar->alpha2, request->alpha2, 2);
memcpy(&ar->alpha2, &set_current_param.alpha2, 2); ret = ath11k_reg_set_cc(ar);
ret = ath11k_wmi_send_set_current_country_cmd(ar, &set_current_param);
if (ret) if (ret)
ath11k_warn(ar->ab, ath11k_warn(ar->ab,
"failed set current country code: %d\n", ret); "failed set current country code: %d\n", ret);
...@@ -1017,3 +1015,11 @@ void ath11k_reg_free(struct ath11k_base *ab) ...@@ -1017,3 +1015,11 @@ void ath11k_reg_free(struct ath11k_base *ab)
kfree(ab->new_regd[i]); kfree(ab->new_regd[i]);
} }
} }
int ath11k_reg_set_cc(struct ath11k *ar)
{
struct wmi_set_current_country_params set_current_param = {};
memcpy(&set_current_param.alpha2, ar->alpha2, 2);
return ath11k_wmi_send_set_current_country_cmd(ar, &set_current_param);
}
/* SPDX-License-Identifier: BSD-3-Clause-Clear */ /* SPDX-License-Identifier: BSD-3-Clause-Clear */
/* /*
* Copyright (c) 2019 The Linux Foundation. All rights reserved. * Copyright (c) 2019 The Linux Foundation. All rights reserved.
* Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved. * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
*/ */
#ifndef ATH11K_REG_H #ifndef ATH11K_REG_H
...@@ -45,5 +45,5 @@ ath11k_reg_ap_pwr_convert(enum ieee80211_ap_reg_power power_type); ...@@ -45,5 +45,5 @@ ath11k_reg_ap_pwr_convert(enum ieee80211_ap_reg_power power_type);
int ath11k_reg_handle_chan_list(struct ath11k_base *ab, int ath11k_reg_handle_chan_list(struct ath11k_base *ab,
struct cur_regulatory_info *reg_info, struct cur_regulatory_info *reg_info,
enum ieee80211_ap_reg_power power_type); enum ieee80211_ap_reg_power power_type);
int ath11k_reg_set_cc(struct ath11k *ar);
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment