rtw88: support SAR via kernel common API
Ping-Ke Shih
maintainerPATCH 1/1 rtw88: support SAR via kernel common API
From: Zong-Zhe Yang <[email protected]>
Register cfg80211_sar_capa with type NL80211_SAR_TYPE_POWER and four frequency ranges for configurations in unit of 0.25 dBm. And handle callback set_sar_specs.
Originally, TX power has three main parameters, i.e. power base, power by rate, and power limit. The formula can be simply considered as TX power = power base + min(power by rate, power limit). With the support of SAR which can be treated as another power limit, there is one more parameter for TX power. And the formula will evolve into TX power = power base + min(power by rate, power limit, power sar).
Besides, debugfs tx_pwr_tbl is also refined to show SAR information. The following is an example for the difference.
Before supporting SAR,
-----------------------------------
...
path rate pwr base (byr lmt ) rem
A CCK_1M 66(0x42) 78 -12 ( 12 -12) 0 A CCK_2M 66(0x42) 78 -12 ( 8 -12) 0
...
-----------------------------------
After supporting SAR and making some configurations,
-----------------------------------
...
path rate pwr base (byr lmt sar ) rem
A CCK_1M 62(0x3e) 78 -16 ( 12 -12 -16) 0 A CCK_2M 62(0x3e) 78 -16 ( 8 -12 -16) 0
...
-----------------------------------
---
Note: This patch dpends on another sent patch "rtw88: 8822c: add ieee80211_ops::hw_scan"
--- drivers/net/wireless/realtek/rtw88/Makefile | 1 + drivers/net/wireless/realtek/rtw88/debug.c | 12 +- drivers/net/wireless/realtek/rtw88/mac80211.c | 12 ++ drivers/net/wireless/realtek/rtw88/main.c | 22 ++++ drivers/net/wireless/realtek/rtw88/main.h | 30 +++++ drivers/net/wireless/realtek/rtw88/phy.c | 63 +++++++--- drivers/net/wireless/realtek/rtw88/phy.h | 1 + drivers/net/wireless/realtek/rtw88/sar.c | 114 ++++++++++++++++++ drivers/net/wireless/realtek/rtw88/sar.h | 22 ++++ 9 files changed, 257 insertions(+), 20 deletions(-) create mode 100644 drivers/net/wireless/realtek/rtw88/sar.c create mode 100644 drivers/net/wireless/realtek/rtw88/sar.h
drivers/net/wireless/realtek/rtw88/Makefile +1 -0
@@ -15,6 +15,7 @@ rtw88_core-y += main.o \ ps.o \ sec.o \ bf.o \ + sar.o \ regd.o rtw88_core-$(CONFIG_PM) += wow.o
drivers/net/wireless/realtek/rtw88/debug.c +7 -5
@@ -634,8 +634,8 @@ static int rtw_debugfs_get_tx_pwr_tbl(struct seq_file *m, void *v)seq_printf (m,"channel: %u\n" , ch);seq_printf (m,"bandwidth: %u\n" , bw);seq_printf (m,"regulatory: %s\n" ,rtw_get_regd_string (regd)); -seq_printf (m,"%-4s %-10s %-3s%6s %-4s %4s (%-4s %-4s) %-4s\n" , -"path" ,"rate" ,"pwr" ,"" ,"base" ,"" ,"byr" ,"lmt" ,"rem" ); +seq_printf (m,"%-4s %-10s %-9s %-9s (%-4s %-4s %-4s) %-4s\n" , +"path" ,"rate" ,"pwr" ,"base" ,"byr" ,"lmt" ,"sar" ,"rem" );mutex_lock (&hal->tx_power_mutex);for (path =RF_PATH_A ; path <=RF_PATH_B ; path++) {
@@ -657,13 +657,15 @@ static int rtw_debugfs_get_tx_pwr_tbl(struct seq_file *m, void *v)seq_printf (m,"%4c " , path +'A' );rtw_print_rate (m, rate); -seq_printf (m," %3u(0x%02x) %4u %4d (%4d %4d) %4d\n" , +seq_printf (m," %3u(0x%02x) %4u %4d (%4d %4d %4d) %4d\n" , hal->tx_pwr_tbl[path][rate], hal->tx_pwr_tbl[path][rate], pwr_param.pwr_base, -min_t (s8, pwr_param.pwr_offset, - pwr_param.pwr_limit), +min3 (pwr_param.pwr_offset, + pwr_param.pwr_limit, + pwr_param.pwr_sar), pwr_param.pwr_offset, pwr_param.pwr_limit, + pwr_param.pwr_sar, pwr_param.pwr_remnant); } }
drivers/net/wireless/realtek/rtw88/mac80211.c +12 -0
@@ -13,6 +13,7 @@#include "bf.h" #include "debug.h" #include "wow.h" +#include "sar.h" static void rtw_ops_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
@@ -835,6 +836,16 @@ static void rtw_ops_cancel_hw_scan(struct ieee80211_hw *hw,mutex_unlock (&rtwdev->mutex); } +static int rtw_ops_set_sar_specs (struct ieee80211_hw *hw, +const struct cfg80211_sar_specs *sar) +{ +struct rtw_dev *rtwdev = hw->priv; + +rtw_set_sar_specs (rtwdev, sar); + +return 0 ; +} +const struct ieee80211_ops rtw_ops = { .tx = rtw_ops_tx, .wake_tx_queue = rtw_ops_wake_tx_queue,
@@ -864,6 +875,7 @@ const struct ieee80211_ops rtw_ops = { .reconfig_complete = rtw_reconfig_complete, .hw_scan = rtw_ops_hw_scan, .cancel_hw_scan = rtw_ops_cancel_hw_scan, + .set_sar_specs = rtw_ops_set_sar_specs, #ifdef CONFIG_PM .suspend = rtw_ops_suspend, .resume = rtw_ops_resume,
drivers/net/wireless/realtek/rtw88/main.c +22 -0
@@ -17,6 +17,7 @@#include "tx.h" #include "debug.h" #include "bf.h" +#include "sar.h" bool rtw_disable_lps_deep_mode;EXPORT_SYMBOL (rtw_disable_lps_deep_mode);
@@ -751,6 +752,25 @@ void rtw_set_channel(struct rtw_dev *rtwdev) hal->current_primary_channel_index = primary_chan_idx; hal->current_band_type = center_chan >14 ?RTW_BAND_5G :RTW_BAND_2G ; +switch (center_chan) { + case 1 ... 14: + hal->sar_band =RTW_SAR_BAND_0 ; +break ; + case 36 ... 64: + hal->sar_band =RTW_SAR_BAND_1 ; +break ; + case 100 ... 144: + hal->sar_band =RTW_SAR_BAND_3 ; +break ; + case 149 ... 177: + hal->sar_band =RTW_SAR_BAND_4 ; +break ; +default : +WARN (1 ,"unknown ch(%u) to SAR band\n" , center_chan); + hal->sar_band =RTW_SAR_BAND_0 ; +break ; + } +for (i =RTW_CHANNEL_WIDTH_20 ; i <=RTW_MAX_CHANNEL_WIDTH ; i++) hal->cch_by_bw[i] = ch_param.cch_by_bw[i];
@@ -2036,6 +2056,8 @@ int rtw_register_hw(struct rtw_dev *rtwdev, struct ieee80211_hw *hw)rtw_set_supported_band (hw, rtwdev->chip);SET_IEEE80211_PERM_ADDR (hw, rtwdev->efuse.addr); + hw->wiphy->sar_capa = &rtw_sar_capa; + ret =rtw_regd_init (rtwdev);if (ret) {rtw_err (rtwdev,"failed to init regd\n" );
drivers/net/wireless/realtek/rtw88/main.h +30 -0
@@ -1813,6 +1813,33 @@ struct rtw_fw_state {u32 feature; }; +enum rtw_sar_sources { +RTW_SAR_SOURCE_NONE , +RTW_SAR_SOURCE_COMMON , +}; + +enum rtw_sar_bands { +RTW_SAR_BAND_0 , +RTW_SAR_BAND_1 , +/* RTW_SAR_BAND_2, not used now */ +RTW_SAR_BAND_3 , +RTW_SAR_BAND_4 , + +RTW_SAR_BAND_NR , +}; + +/* the union is reserved for other knids of SAR sources +* which might not re-use same format with array common. +*/ +union rtw_sar_cfg { +s8 common[RTW_SAR_BAND_NR ]; +}; + +struct rtw_sar { +enum rtw_sar_sources src; +union rtw_sar_cfg cfg[RTW_RF_PATH_MAX ][RTW_RATE_SECTION_MAX ]; +}; +struct rtw_hal {u32 rcr;
@@ -1861,6 +1888,9 @@ struct rtw_hal { [RTW_MAX_CHANNEL_NUM_5G ];s8 tx_pwr_tbl[RTW_RF_PATH_MAX ] [DESC_RATE_MAX ]; + +enum rtw_sar_bands sar_band; +struct rtw_sar sar; };struct rtw_path_div {
drivers/net/wireless/realtek/rtw88/phy.c +48 -15
111 lines not on this page · raw message
drivers/net/wireless/realtek/rtw88/phy.h +1 -0
@@ -148,6 +148,7 @@ struct rtw_power_params {s8 pwr_offset;s8 pwr_limit;s8 pwr_remnant; +s8 pwr_sar; };void
drivers/net/wireless/realtek/rtw88/sar.c new file +114 -0
114 lines not on this page · raw message
drivers/net/wireless/realtek/rtw88/sar.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ +/* Copyright(c) 2018-2021 Realtek Corporation +*/ + +#include "main.h" + +/* NL80211_SAR_TYPE_POWER means unit is in 0.25 dBm, +* where 0.25 = 1/4 = 2^(-2), so make factor 2. +*/ +#define RTW_COMMON_SAR_FCT 2 + +struct rtw_sar_arg { +u8 sar_band; +u8 path; +u8 rs; +}; + +extern const struct cfg80211_sar_capa rtw_sar_capa; + +s8 rtw_query_sar (struct rtw_dev *rtwdev,const struct rtw_sar_arg *arg); +int rtw_set_sar_specs (struct rtw_dev *rtwdev, +const struct cfg80211_sar_specs *sar);
Signature · 1 line
2.25.1
Quoted 27 lines · Ping-Ke Shih
From: Zong-Zhe Yang <[email protected]>
Register
cfg80211_sar_capawith typeNL80211_SAR_TYPE_POWERand four frequency ranges for configurations in unit of 0.25 dBm. And handle callbackset_sar_specs.Originally, TX power has three main parameters, i.e. power base, power by rate, and power limit. The formula can be simply considered as TX power = power base +
min(power by rate, power limit). With the support of SAR which can be treated as another power limit, there is one more parameter for TX power. And the formula will evolve into TX power = power base +min(power by rate, power limit, power sar).Besides, debugfs
tx_pwr_tblis also refined to show SAR information. The following is an example for the difference.
Before supporting SAR,
-----------------------------------
...
path rate pwr base (byr lmt ) remA CCK_1M 66(0x42) 78 -12 ( 12 -12) 0 A CCK_2M 66(0x42) 78 -12 ( 8 -12) 0...
-----------------------------------
After supporting SAR and making some configurations,
-----------------------------------
...
path rate pwr base (byr lmt sar ) rem
Quoted 7 lines
A CCK_1M 62(0x3e) 78 -16 ( 12 -12 -16) 0 A CCK_2M 62(0x3e) 78 -16 ( 8 -12 -16) 0...
-----------------------------------Signed-off-by Zong-Zhe Yang <[email protected]>Signed-off-by Ping-Ke Shih <[email protected]>
I switched my email to [email protected] and my codeaurora.org address will stop working soon, please update your address book and scripts.
No need to resend because of this.
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Quoted 27 lines · Ping-Ke Shih
From: Zong-Zhe Yang <[email protected]>
Register
cfg80211_sar_capawith typeNL80211_SAR_TYPE_POWERand four frequency ranges for configurations in unit of 0.25 dBm. And handle callbackset_sar_specs.Originally, TX power has three main parameters, i.e. power base, power by rate, and power limit. The formula can be simply considered as TX power = power base +
min(power by rate, power limit). With the support of SAR which can be treated as another power limit, there is one more parameter for TX power. And the formula will evolve into TX power = power base +min(power by rate, power limit, power sar).Besides, debugfs
tx_pwr_tblis also refined to show SAR information. The following is an example for the difference.
Before supporting SAR,
-----------------------------------
...
path rate pwr base (byr lmt ) remA CCK_1M 66(0x42) 78 -12 ( 12 -12) 0 A CCK_2M 66(0x42) 78 -12 ( 8 -12) 0...
-----------------------------------
After supporting SAR and making some configurations,
-----------------------------------
...
path rate pwr base (byr lmt sar ) rem
Quoted 7 lines
A CCK_1M 62(0x3e) 78 -16 ( 12 -12 -16) 0 A CCK_2M 62(0x3e) 78 -16 ( 8 -12 -16) 0...
-----------------------------------Signed-off-by Zong-Zhe Yang <[email protected]>Signed-off-by Ping-Ke Shih <[email protected]>
Patch applied to wireless-drivers-next.git, thanks.
8704d0befb59 rtw88: support SAR via kernel common API
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches