Commit bfbadacf authored by Zong-Zhe Yang's avatar Zong-Zhe Yang Committed by Kalle Valo

wifi: rtw89: sar: let caller decide the center frequency to query

If multiple channels, SAR will be hard to determine the center frequency
to query. Therefore, we move this decision out of SAR.
Signed-off-by: default avatarZong-Zhe Yang <kevin_yang@realtek.com>
Signed-off-by: default avatarPing-Ke Shih <pkshih@realtek.com>
Signed-off-by: default avatarKalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/20230816082133.57474-4-pkshih@realtek.com
parent b05fdc46
...@@ -572,9 +572,9 @@ static int __print_txpwr_map(struct seq_file *m, struct rtw89_dev *rtwdev, ...@@ -572,9 +572,9 @@ static int __print_txpwr_map(struct seq_file *m, struct rtw89_dev *rtwdev,
seq_puts(m, #_regd "\n"); \ seq_puts(m, #_regd "\n"); \
break break
static void __print_regd(struct seq_file *m, struct rtw89_dev *rtwdev) static void __print_regd(struct seq_file *m, struct rtw89_dev *rtwdev,
const struct rtw89_chan *chan)
{ {
const struct rtw89_chan *chan = rtw89_chan_get(rtwdev, RTW89_SUB_ENTITY_0);
u8 band = chan->band_type; u8 band = chan->band_type;
u8 regd = rtw89_regd_get(rtwdev, band); u8 regd = rtw89_regd_get(rtwdev, band);
...@@ -604,16 +604,18 @@ static int rtw89_debug_priv_txpwr_table_get(struct seq_file *m, void *v) ...@@ -604,16 +604,18 @@ static int rtw89_debug_priv_txpwr_table_get(struct seq_file *m, void *v)
{ {
struct rtw89_debugfs_priv *debugfs_priv = m->private; struct rtw89_debugfs_priv *debugfs_priv = m->private;
struct rtw89_dev *rtwdev = debugfs_priv->rtwdev; struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
const struct rtw89_chan *chan;
int ret = 0; int ret = 0;
mutex_lock(&rtwdev->mutex); mutex_lock(&rtwdev->mutex);
rtw89_leave_ps_mode(rtwdev); rtw89_leave_ps_mode(rtwdev);
chan = rtw89_chan_get(rtwdev, RTW89_SUB_ENTITY_0);
seq_puts(m, "[Regulatory] "); seq_puts(m, "[Regulatory] ");
__print_regd(m, rtwdev); __print_regd(m, rtwdev, chan);
seq_puts(m, "[SAR]\n"); seq_puts(m, "[SAR]\n");
rtw89_print_sar(m, rtwdev); rtw89_print_sar(m, rtwdev, chan->freq);
seq_puts(m, "[TAS]\n"); seq_puts(m, "[TAS]\n");
rtw89_print_tas(m, rtwdev); rtw89_print_tas(m, rtwdev);
......
...@@ -1647,6 +1647,8 @@ s8 rtw89_phy_read_txpwr_limit(struct rtw89_dev *rtwdev, u8 band, ...@@ -1647,6 +1647,8 @@ s8 rtw89_phy_read_txpwr_limit(struct rtw89_dev *rtwdev, u8 band,
const struct rtw89_txpwr_rule_5ghz *rule_5ghz = &rfe_parms->rule_5ghz; const struct rtw89_txpwr_rule_5ghz *rule_5ghz = &rfe_parms->rule_5ghz;
const struct rtw89_txpwr_rule_6ghz *rule_6ghz = &rfe_parms->rule_6ghz; const struct rtw89_txpwr_rule_6ghz *rule_6ghz = &rfe_parms->rule_6ghz;
struct rtw89_regulatory_info *regulatory = &rtwdev->regulatory; struct rtw89_regulatory_info *regulatory = &rtwdev->regulatory;
enum nl80211_band nl_band = rtw89_hw_to_nl80211_band(band);
u32 freq = ieee80211_channel_to_frequency(ch, nl_band);
u8 ch_idx = rtw89_channel_to_idx(rtwdev, band, ch); u8 ch_idx = rtw89_channel_to_idx(rtwdev, band, ch);
u8 regd = rtw89_regd_get(rtwdev, band); u8 regd = rtw89_regd_get(rtwdev, band);
u8 reg6 = regulatory->reg_6ghz_power; u8 reg6 = regulatory->reg_6ghz_power;
...@@ -1682,7 +1684,7 @@ s8 rtw89_phy_read_txpwr_limit(struct rtw89_dev *rtwdev, u8 band, ...@@ -1682,7 +1684,7 @@ s8 rtw89_phy_read_txpwr_limit(struct rtw89_dev *rtwdev, u8 band,
} }
lmt = _phy_txpwr_rf_to_mac(rtwdev, lmt); lmt = _phy_txpwr_rf_to_mac(rtwdev, lmt);
sar = rtw89_query_sar(rtwdev); sar = rtw89_query_sar(rtwdev, freq);
return min(lmt, sar); return min(lmt, sar);
} }
...@@ -1902,6 +1904,8 @@ static s8 rtw89_phy_read_txpwr_limit_ru(struct rtw89_dev *rtwdev, u8 band, ...@@ -1902,6 +1904,8 @@ static s8 rtw89_phy_read_txpwr_limit_ru(struct rtw89_dev *rtwdev, u8 band,
const struct rtw89_txpwr_rule_5ghz *rule_5ghz = &rfe_parms->rule_5ghz; const struct rtw89_txpwr_rule_5ghz *rule_5ghz = &rfe_parms->rule_5ghz;
const struct rtw89_txpwr_rule_6ghz *rule_6ghz = &rfe_parms->rule_6ghz; const struct rtw89_txpwr_rule_6ghz *rule_6ghz = &rfe_parms->rule_6ghz;
struct rtw89_regulatory_info *regulatory = &rtwdev->regulatory; struct rtw89_regulatory_info *regulatory = &rtwdev->regulatory;
enum nl80211_band nl_band = rtw89_hw_to_nl80211_band(band);
u32 freq = ieee80211_channel_to_frequency(ch, nl_band);
u8 ch_idx = rtw89_channel_to_idx(rtwdev, band, ch); u8 ch_idx = rtw89_channel_to_idx(rtwdev, band, ch);
u8 regd = rtw89_regd_get(rtwdev, band); u8 regd = rtw89_regd_get(rtwdev, band);
u8 reg6 = regulatory->reg_6ghz_power; u8 reg6 = regulatory->reg_6ghz_power;
...@@ -1937,7 +1941,7 @@ static s8 rtw89_phy_read_txpwr_limit_ru(struct rtw89_dev *rtwdev, u8 band, ...@@ -1937,7 +1941,7 @@ static s8 rtw89_phy_read_txpwr_limit_ru(struct rtw89_dev *rtwdev, u8 band,
} }
lmt_ru = _phy_txpwr_rf_to_mac(rtwdev, lmt_ru); lmt_ru = _phy_txpwr_rf_to_mac(rtwdev, lmt_ru);
sar = rtw89_query_sar(rtwdev); sar = rtw89_query_sar(rtwdev, freq);
return min(lmt_ru, sar); return min(lmt_ru, sar);
} }
......
...@@ -85,17 +85,15 @@ static const struct rtw89_sar_span rtw89_sar_overlapping_6ghz[] = { ...@@ -85,17 +85,15 @@ static const struct rtw89_sar_span rtw89_sar_overlapping_6ghz[] = {
RTW89_DECL_SAR_6GHZ_SPAN(6885, SUBBAND_7_H, SUBBAND_8), RTW89_DECL_SAR_6GHZ_SPAN(6885, SUBBAND_7_H, SUBBAND_8),
}; };
static int rtw89_query_sar_config_common(struct rtw89_dev *rtwdev, s32 *cfg) static int rtw89_query_sar_config_common(struct rtw89_dev *rtwdev,
u32 center_freq, s32 *cfg)
{ {
struct rtw89_sar_cfg_common *rtwsar = &rtwdev->sar.cfg_common; struct rtw89_sar_cfg_common *rtwsar = &rtwdev->sar.cfg_common;
const struct rtw89_chan *chan = rtw89_chan_get(rtwdev, RTW89_SUB_ENTITY_0);
enum rtw89_band band = chan->band_type;
u32 center_freq = chan->freq;
const struct rtw89_sar_span *span = NULL; const struct rtw89_sar_span *span = NULL;
enum rtw89_sar_subband subband_l, subband_h; enum rtw89_sar_subband subband_l, subband_h;
int idx; int idx;
if (band == RTW89_BAND_6G) { if (center_freq >= RTW89_SAR_6GHZ_SPAN_HEAD) {
idx = RTW89_SAR_6GHZ_SPAN_IDX(center_freq); idx = RTW89_SAR_6GHZ_SPAN_IDX(center_freq);
/* To decrease size of rtw89_sar_overlapping_6ghz[], /* To decrease size of rtw89_sar_overlapping_6ghz[],
* RTW89_SAR_6GHZ_SPAN_IDX() truncates the leading NULLs * RTW89_SAR_6GHZ_SPAN_IDX() truncates the leading NULLs
...@@ -115,8 +113,8 @@ static int rtw89_query_sar_config_common(struct rtw89_dev *rtwdev, s32 *cfg) ...@@ -115,8 +113,8 @@ static int rtw89_query_sar_config_common(struct rtw89_dev *rtwdev, s32 *cfg)
} }
rtw89_debug(rtwdev, RTW89_DBG_SAR, rtw89_debug(rtwdev, RTW89_DBG_SAR,
"for {band %u, center_freq %u}, SAR subband: {%u, %u}\n", "center_freq %u: SAR subband {%u, %u}\n",
band, center_freq, subband_l, subband_h); center_freq, subband_l, subband_h);
if (!rtwsar->set[subband_l] && !rtwsar->set[subband_h]) if (!rtwsar->set[subband_l] && !rtwsar->set[subband_h])
return -ENODATA; return -ENODATA;
...@@ -186,7 +184,7 @@ static s8 rtw89_txpwr_sar_to_tas(const struct rtw89_sar_handler *sar_hdl, ...@@ -186,7 +184,7 @@ static s8 rtw89_txpwr_sar_to_tas(const struct rtw89_sar_handler *sar_hdl,
return cfg << (RTW89_TAS_FACTOR - fct); return cfg << (RTW89_TAS_FACTOR - fct);
} }
s8 rtw89_query_sar(struct rtw89_dev *rtwdev) s8 rtw89_query_sar(struct rtw89_dev *rtwdev, u32 center_freq)
{ {
const enum rtw89_sar_sources src = rtwdev->sar.src; const enum rtw89_sar_sources src = rtwdev->sar.src;
/* its members are protected by rtw89_sar_set_src() */ /* its members are protected by rtw89_sar_set_src() */
...@@ -202,7 +200,7 @@ s8 rtw89_query_sar(struct rtw89_dev *rtwdev) ...@@ -202,7 +200,7 @@ s8 rtw89_query_sar(struct rtw89_dev *rtwdev)
if (src == RTW89_SAR_SOURCE_NONE) if (src == RTW89_SAR_SOURCE_NONE)
return RTW89_SAR_TXPWR_MAC_MAX; return RTW89_SAR_TXPWR_MAC_MAX;
ret = sar_hdl->query_sar_config(rtwdev, &cfg); ret = sar_hdl->query_sar_config(rtwdev, center_freq, &cfg);
if (ret) if (ret)
return RTW89_SAR_TXPWR_MAC_MAX; return RTW89_SAR_TXPWR_MAC_MAX;
...@@ -224,7 +222,7 @@ s8 rtw89_query_sar(struct rtw89_dev *rtwdev) ...@@ -224,7 +222,7 @@ s8 rtw89_query_sar(struct rtw89_dev *rtwdev)
return rtw89_txpwr_sar_to_mac(rtwdev, fct, cfg); return rtw89_txpwr_sar_to_mac(rtwdev, fct, cfg);
} }
void rtw89_print_sar(struct seq_file *m, struct rtw89_dev *rtwdev) void rtw89_print_sar(struct seq_file *m, struct rtw89_dev *rtwdev, u32 center_freq)
{ {
const enum rtw89_sar_sources src = rtwdev->sar.src; const enum rtw89_sar_sources src = rtwdev->sar.src;
/* its members are protected by rtw89_sar_set_src() */ /* its members are protected by rtw89_sar_set_src() */
...@@ -243,7 +241,7 @@ void rtw89_print_sar(struct seq_file *m, struct rtw89_dev *rtwdev) ...@@ -243,7 +241,7 @@ void rtw89_print_sar(struct seq_file *m, struct rtw89_dev *rtwdev)
seq_printf(m, "source: %d (%s)\n", src, sar_hdl->descr_sar_source); seq_printf(m, "source: %d (%s)\n", src, sar_hdl->descr_sar_source);
ret = sar_hdl->query_sar_config(rtwdev, &cfg); ret = sar_hdl->query_sar_config(rtwdev, center_freq, &cfg);
if (ret) { if (ret) {
seq_printf(m, "config: return code: %d\n", ret); seq_printf(m, "config: return code: %d\n", ret);
seq_printf(m, "assign: max setting: %d (unit: 1/%lu dBm)\n", seq_printf(m, "assign: max setting: %d (unit: 1/%lu dBm)\n",
...@@ -359,6 +357,7 @@ static void rtw89_tas_state_update(struct rtw89_dev *rtwdev) ...@@ -359,6 +357,7 @@ static void rtw89_tas_state_update(struct rtw89_dev *rtwdev)
s32 txpwr_avg = tas->total_txpwr / RTW89_TAS_MAX_WINDOW / PERCENT; s32 txpwr_avg = tas->total_txpwr / RTW89_TAS_MAX_WINDOW / PERCENT;
s32 dpr_on_threshold, dpr_off_threshold, cfg; s32 dpr_on_threshold, dpr_off_threshold, cfg;
enum rtw89_tas_state state = tas->state; enum rtw89_tas_state state = tas->state;
const struct rtw89_chan *chan;
int ret; int ret;
lockdep_assert_held(&rtwdev->mutex); lockdep_assert_held(&rtwdev->mutex);
...@@ -366,7 +365,8 @@ static void rtw89_tas_state_update(struct rtw89_dev *rtwdev) ...@@ -366,7 +365,8 @@ static void rtw89_tas_state_update(struct rtw89_dev *rtwdev)
if (src == RTW89_SAR_SOURCE_NONE) if (src == RTW89_SAR_SOURCE_NONE)
return; return;
ret = sar_hdl->query_sar_config(rtwdev, &cfg); chan = rtw89_chan_get(rtwdev, RTW89_SUB_ENTITY_0);
ret = sar_hdl->query_sar_config(rtwdev, chan->freq, &cfg);
if (ret) if (ret)
return; return;
......
...@@ -13,13 +13,13 @@ ...@@ -13,13 +13,13 @@
struct rtw89_sar_handler { struct rtw89_sar_handler {
const char *descr_sar_source; const char *descr_sar_source;
u8 txpwr_factor_sar; u8 txpwr_factor_sar;
int (*query_sar_config)(struct rtw89_dev *rtwdev, s32 *cfg); int (*query_sar_config)(struct rtw89_dev *rtwdev, u32 center_freq, s32 *cfg);
}; };
extern const struct cfg80211_sar_capa rtw89_sar_capa; extern const struct cfg80211_sar_capa rtw89_sar_capa;
s8 rtw89_query_sar(struct rtw89_dev *rtwdev); s8 rtw89_query_sar(struct rtw89_dev *rtwdev, u32 center_freq);
void rtw89_print_sar(struct seq_file *m, struct rtw89_dev *rtwdev); void rtw89_print_sar(struct seq_file *m, struct rtw89_dev *rtwdev, u32 center_freq);
void rtw89_print_tas(struct seq_file *m, struct rtw89_dev *rtwdev); void rtw89_print_tas(struct seq_file *m, struct rtw89_dev *rtwdev);
int rtw89_ops_set_sar_specs(struct ieee80211_hw *hw, int rtw89_ops_set_sar_specs(struct ieee80211_hw *hw,
const struct cfg80211_sar_specs *sar); const struct cfg80211_sar_specs *sar);
......
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