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

rtw88: upgrade rtw_regulatory mechanism and mapping

Mapping table from country code to rtw_regulatory, which manages tx power
limit according to countries, is updated. And mapping architecture is also
upgraded. For more precise control on tx power limit, it allows different
rtw_regulatory for different bands logically. Besides, a helper function
to query rtw_regulatory for current band under current country is provided.

For older chips, some newly added rtw_regulatory may not be configured.
To avoid that those chips have no limit on some countries mapping to a
newer rtw_regulatory after table update, a backward selection mechanism
of rtw_regulatory is introduced. It can help chips use a rtw_regulatory
which has been configured as an alternative of a newer one which is not
configured.

In addition, rtw88 actually doesn't manage channel plans by itself.
Instead, it follows them from stack. So, correct some naming about
chplan with regd, and remove the unnecessary channel control for now.
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@codeaurora.org>
Link: https://lore.kernel.org/r/20210830072014.12250-2-pkshih@realtek.com
parent beca6bd9
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "phy.h" #include "phy.h"
#include "reg.h" #include "reg.h"
#include "ps.h" #include "ps.h"
#include "regd.h"
#ifdef CONFIG_RTW88_DEBUGFS #ifdef CONFIG_RTW88_DEBUGFS
...@@ -587,7 +588,7 @@ static int rtw_debugfs_get_tx_pwr_tbl(struct seq_file *m, void *v) ...@@ -587,7 +588,7 @@ static int rtw_debugfs_get_tx_pwr_tbl(struct seq_file *m, void *v)
struct rtw_power_params pwr_param = {0}; struct rtw_power_params pwr_param = {0};
u8 bw = hal->current_band_width; u8 bw = hal->current_band_width;
u8 ch = hal->current_channel; u8 ch = hal->current_channel;
u8 regd = rtwdev->regd.txpwr_regd; u8 regd = rtw_regd_get(rtwdev);
seq_printf(m, "regulatory: %s\n", rtw_get_regd_string(regd)); seq_printf(m, "regulatory: %s\n", rtw_get_regd_string(regd));
seq_printf(m, "%-4s %-10s %-3s%6s %-4s %4s (%-4s %-4s) %-4s\n", seq_printf(m, "%-4s %-10s %-3s%6s %-4s %4s (%-4s %-4s) %-4s\n",
......
...@@ -800,8 +800,8 @@ struct rtw_vif { ...@@ -800,8 +800,8 @@ struct rtw_vif {
struct rtw_regulatory { struct rtw_regulatory {
char alpha2[2]; char alpha2[2];
u8 chplan; u8 txpwr_regd_2g;
u8 txpwr_regd; u8 txpwr_regd_5g;
}; };
struct rtw_chip_ops { struct rtw_chip_ops {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "fw.h" #include "fw.h"
#include "phy.h" #include "phy.h"
#include "debug.h" #include "debug.h"
#include "regd.h"
struct phy_cfg_pair { struct phy_cfg_pair {
u32 addr; u32 addr;
...@@ -1564,17 +1565,70 @@ static void rtw_xref_txpwr_lmt(struct rtw_dev *rtwdev) ...@@ -1564,17 +1565,70 @@ static void rtw_xref_txpwr_lmt(struct rtw_dev *rtwdev)
rtw_xref_txpwr_lmt_by_bw(rtwdev, regd); rtw_xref_txpwr_lmt_by_bw(rtwdev, regd);
} }
static void
__cfg_txpwr_lmt_by_alt(struct rtw_hal *hal, u8 regd, u8 regd_alt, u8 bw, u8 rs)
{
u8 ch;
for (ch = 0; ch < RTW_MAX_CHANNEL_NUM_2G; ch++)
hal->tx_pwr_limit_2g[regd][bw][rs][ch] =
hal->tx_pwr_limit_2g[regd_alt][bw][rs][ch];
for (ch = 0; ch < RTW_MAX_CHANNEL_NUM_5G; ch++)
hal->tx_pwr_limit_5g[regd][bw][rs][ch] =
hal->tx_pwr_limit_5g[regd_alt][bw][rs][ch];
}
static void
rtw_cfg_txpwr_lmt_by_alt(struct rtw_dev *rtwdev, u8 regd, u8 regd_alt)
{
u8 bw, rs;
for (bw = 0; bw < RTW_CHANNEL_WIDTH_MAX; bw++)
for (rs = 0; rs < RTW_RATE_SECTION_MAX; rs++)
__cfg_txpwr_lmt_by_alt(&rtwdev->hal, regd, regd_alt,
bw, rs);
}
void rtw_parse_tbl_txpwr_lmt(struct rtw_dev *rtwdev, void rtw_parse_tbl_txpwr_lmt(struct rtw_dev *rtwdev,
const struct rtw_table *tbl) const struct rtw_table *tbl)
{ {
const struct rtw_txpwr_lmt_cfg_pair *p = tbl->data; const struct rtw_txpwr_lmt_cfg_pair *p = tbl->data;
const struct rtw_txpwr_lmt_cfg_pair *end = p + tbl->size; const struct rtw_txpwr_lmt_cfg_pair *end = p + tbl->size;
u32 regd_cfg_flag = 0;
u8 regd_alt;
u8 i;
for (; p < end; p++) { for (; p < end; p++) {
regd_cfg_flag |= BIT(p->regd);
rtw_phy_set_tx_power_limit(rtwdev, p->regd, p->band, rtw_phy_set_tx_power_limit(rtwdev, p->regd, p->band,
p->bw, p->rs, p->ch, p->txpwr_lmt); p->bw, p->rs, p->ch, p->txpwr_lmt);
} }
for (i = 0; i < RTW_REGD_MAX; i++) {
if (i == RTW_REGD_WW)
continue;
if (regd_cfg_flag & BIT(i))
continue;
rtw_dbg(rtwdev, RTW_DBG_REGD,
"txpwr regd %d does not be configured\n", i);
if (rtw_regd_has_alt(i, &regd_alt) &&
regd_cfg_flag & BIT(regd_alt)) {
rtw_dbg(rtwdev, RTW_DBG_REGD,
"cfg txpwr regd %d by regd %d as alternative\n",
i, regd_alt);
rtw_cfg_txpwr_lmt_by_alt(rtwdev, i, regd_alt);
continue;
}
rtw_dbg(rtwdev, RTW_DBG_REGD, "cfg txpwr regd %d by WW\n", i);
rtw_cfg_txpwr_lmt_by_alt(rtwdev, i, RTW_REGD_WW);
}
rtw_xref_txpwr_lmt(rtwdev); rtw_xref_txpwr_lmt(rtwdev);
} }
EXPORT_SYMBOL(rtw_parse_tbl_txpwr_lmt); EXPORT_SYMBOL(rtw_parse_tbl_txpwr_lmt);
...@@ -2014,7 +2068,7 @@ static void rtw_phy_set_tx_power_index_by_rs(struct rtw_dev *rtwdev, ...@@ -2014,7 +2068,7 @@ static void rtw_phy_set_tx_power_index_by_rs(struct rtw_dev *rtwdev,
u8 ch, u8 path, u8 rs) u8 ch, u8 path, u8 rs)
{ {
struct rtw_hal *hal = &rtwdev->hal; struct rtw_hal *hal = &rtwdev->hal;
u8 regd = rtwdev->regd.txpwr_regd; u8 regd = rtw_regd_get(rtwdev);
u8 *rates; u8 *rates;
u8 size; u8 size;
u8 rate; u8 rate;
......
This diff is collapsed.
...@@ -68,4 +68,6 @@ int rtw_regd_init(struct rtw_dev *rtwdev, ...@@ -68,4 +68,6 @@ int rtw_regd_init(struct rtw_dev *rtwdev,
void (*reg_notifier)(struct wiphy *wiphy, void (*reg_notifier)(struct wiphy *wiphy,
struct regulatory_request *request)); struct regulatory_request *request));
void rtw_regd_notifier(struct wiphy *wiphy, struct regulatory_request *request); void rtw_regd_notifier(struct wiphy *wiphy, struct regulatory_request *request);
u8 rtw_regd_get(struct rtw_dev *rtwdev);
bool rtw_regd_has_alt(u8 regd, u8 *regd_alt);
#endif #endif
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "reg.h" #include "reg.h"
#include "debug.h" #include "debug.h"
#include "bf.h" #include "bf.h"
#include "regd.h"
static const s8 lna_gain_table_0[8] = {22, 8, -6, -22, -31, -40, -46, -52}; static const s8 lna_gain_table_0[8] = {22, 8, -6, -22, -31, -40, -46, -52};
static const s8 lna_gain_table_1[16] = {10, 6, 2, -2, -6, -10, -14, -17, static const s8 lna_gain_table_1[16] = {10, 6, 2, -2, -6, -10, -14, -17,
...@@ -993,7 +994,7 @@ static void rtw8821c_pwrtrack_set(struct rtw_dev *rtwdev) ...@@ -993,7 +994,7 @@ static void rtw8821c_pwrtrack_set(struct rtw_dev *rtwdev)
s8 pwr_idx_offset_lower; s8 pwr_idx_offset_lower;
u8 channel = rtwdev->hal.current_channel; u8 channel = rtwdev->hal.current_channel;
u8 band_width = rtwdev->hal.current_band_width; u8 band_width = rtwdev->hal.current_band_width;
u8 regd = rtwdev->regd.txpwr_regd; u8 regd = rtw_regd_get(rtwdev);
u8 tx_rate = dm_info->tx_rate; u8 tx_rate = dm_info->tx_rate;
u8 max_pwr_idx = rtwdev->chip->max_power_index; u8 max_pwr_idx = rtwdev->chip->max_power_index;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "reg.h" #include "reg.h"
#include "debug.h" #include "debug.h"
#include "bf.h" #include "bf.h"
#include "regd.h"
static void rtw8822b_config_trx_mode(struct rtw_dev *rtwdev, u8 tx_path, static void rtw8822b_config_trx_mode(struct rtw_dev *rtwdev, u8 tx_path,
u8 rx_path, bool is_tx2_path); u8 rx_path, bool is_tx2_path);
...@@ -1436,7 +1437,7 @@ static void rtw8822b_pwrtrack_set(struct rtw_dev *rtwdev, u8 path) ...@@ -1436,7 +1437,7 @@ static void rtw8822b_pwrtrack_set(struct rtw_dev *rtwdev, u8 path)
u8 pwr_idx_offset, tx_pwr_idx; u8 pwr_idx_offset, tx_pwr_idx;
u8 channel = rtwdev->hal.current_channel; u8 channel = rtwdev->hal.current_channel;
u8 band_width = rtwdev->hal.current_band_width; u8 band_width = rtwdev->hal.current_band_width;
u8 regd = rtwdev->regd.txpwr_regd; u8 regd = rtw_regd_get(rtwdev);
u8 tx_rate = dm_info->tx_rate; u8 tx_rate = dm_info->tx_rate;
u8 max_pwr_idx = rtwdev->chip->max_power_index; u8 max_pwr_idx = rtwdev->chip->max_power_index;
......
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