* [PATCH 1/2] wifi: rtlwifi: remove dead code in phy_get_tx_swing_8812A()
@ 2023-11-01 11:35 Dmitry Antipov
2023-11-01 11:35 ` [PATCH 2/2] wifi: rtlwifi: simplify _rtl8812ae_phy_get_txpower_limit() Dmitry Antipov
2023-11-06 3:37 ` [PATCH 1/2] wifi: rtlwifi: remove dead code in phy_get_tx_swing_8812A() Ping-Ke Shih
0 siblings, 2 replies; 4+ messages in thread
From: Dmitry Antipov @ 2023-11-01 11:35 UTC (permalink / raw
To: Ping-Ke Shih; +Cc: Kalle Valo, linux-wireless, lvc-project, Dmitry Antipov
Since 'reg_swing_2g', 'swing_2g', 'reg_swing_5g', and 'swing_5g'
are compile-time constants, mark all of them as such and remove
never executed blocks in 'phy_get_tx_swing_8812A()'. Minor style
adjustments, compile tested only.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
.../wireless/realtek/rtlwifi/rtl8821ae/phy.c | 77 ++++---------------
1 file changed, 16 insertions(+), 61 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
index 5323ead30db0..c262770fea29 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
@@ -437,12 +437,11 @@ u32 phy_get_tx_swing_8812A(struct ieee80211_hw *hw, u8 band,
struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
struct rtl_dm *rtldm = rtl_dm(rtlpriv);
struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
- s8 reg_swing_2g = -1;/* 0xff; */
- s8 reg_swing_5g = -1;/* 0xff; */
- s8 swing_2g = -1 * reg_swing_2g;
- s8 swing_5g = -1 * reg_swing_5g;
- u32 out = 0x200;
- const s8 auto_temp = -1;
+ const s8 reg_swing_2g = -1; /* 0xff; */
+ const s8 reg_swing_5g = -1; /* 0xff; */
+ const s8 swing_2g = -1 * reg_swing_2g;
+ const s8 swing_5g = -1 * reg_swing_5g;
+ u32 out = 0x200;
rtl_dbg(rtlpriv, COMP_SCAN, DBG_LOUD,
"===> PHY_GetTXBBSwing_8812A, bbSwing_2G: %d, bbSwing_5G: %d,autoload_failflag=%d.\n",
@@ -452,36 +451,16 @@ u32 phy_get_tx_swing_8812A(struct ieee80211_hw *hw, u8 band,
if (rtlefuse->autoload_failflag) {
if (band == BAND_ON_2_4G) {
rtldm->swing_diff_2g = swing_2g;
- if (swing_2g == 0) {
- out = 0x200; /* 0 dB */
- } else if (swing_2g == -3) {
- out = 0x16A; /* -3 dB */
- } else if (swing_2g == -6) {
- out = 0x101; /* -6 dB */
- } else if (swing_2g == -9) {
- out = 0x0B6; /* -9 dB */
- } else {
- rtldm->swing_diff_2g = 0;
- out = 0x200;
- }
+ rtldm->swing_diff_2g = 0;
+ out = 0x200;
} else if (band == BAND_ON_5G) {
rtldm->swing_diff_5g = swing_5g;
- if (swing_5g == 0) {
- out = 0x200; /* 0 dB */
- } else if (swing_5g == -3) {
- out = 0x16A; /* -3 dB */
- } else if (swing_5g == -6) {
- out = 0x101; /* -6 dB */
- } else if (swing_5g == -9) {
- out = 0x0B6; /* -9 dB */
+ if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
+ rtldm->swing_diff_5g = -3;
+ out = 0x16A;
} else {
- if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
- rtldm->swing_diff_5g = -3;
- out = 0x16A;
- } else {
- rtldm->swing_diff_5g = 0;
- out = 0x200;
- }
+ rtldm->swing_diff_5g = 0;
+ out = 0x200;
}
} else {
rtldm->swing_diff_2g = -3;
@@ -492,35 +471,11 @@ u32 phy_get_tx_swing_8812A(struct ieee80211_hw *hw, u8 band,
u32 swing = 0, swing_a = 0, swing_b = 0;
if (band == BAND_ON_2_4G) {
- if (reg_swing_2g == auto_temp) {
- efuse_shadow_read(hw, 1, 0xC6, (u32 *)&swing);
- swing = (swing == 0xFF) ? 0x00 : swing;
- } else if (swing_2g == 0) {
- swing = 0x00; /* 0 dB */
- } else if (swing_2g == -3) {
- swing = 0x05; /* -3 dB */
- } else if (swing_2g == -6) {
- swing = 0x0A; /* -6 dB */
- } else if (swing_2g == -9) {
- swing = 0xFF; /* -9 dB */
- } else {
- swing = 0x00;
- }
+ efuse_shadow_read(hw, 1, 0xC6, (u32 *)&swing);
+ swing = (swing == 0xFF) ? 0x00 : swing;
} else {
- if (reg_swing_5g == auto_temp) {
- efuse_shadow_read(hw, 1, 0xC7, (u32 *)&swing);
- swing = (swing == 0xFF) ? 0x00 : swing;
- } else if (swing_5g == 0) {
- swing = 0x00; /* 0 dB */
- } else if (swing_5g == -3) {
- swing = 0x05; /* -3 dB */
- } else if (swing_5g == -6) {
- swing = 0x0A; /* -6 dB */
- } else if (swing_5g == -9) {
- swing = 0xFF; /* -9 dB */
- } else {
- swing = 0x00;
- }
+ efuse_shadow_read(hw, 1, 0xC7, (u32 *)&swing);
+ swing = (swing == 0xFF) ? 0x00 : swing;
}
swing_a = (swing & 0x3) >> 0; /* 0xC6/C7[1:0] */
--
2.41.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] wifi: rtlwifi: simplify _rtl8812ae_phy_get_txpower_limit()
2023-11-01 11:35 [PATCH 1/2] wifi: rtlwifi: remove dead code in phy_get_tx_swing_8812A() Dmitry Antipov
@ 2023-11-01 11:35 ` Dmitry Antipov
2023-11-06 3:44 ` Ping-Ke Shih
2023-11-06 3:37 ` [PATCH 1/2] wifi: rtlwifi: remove dead code in phy_get_tx_swing_8812A() Ping-Ke Shih
1 sibling, 1 reply; 4+ messages in thread
From: Dmitry Antipov @ 2023-11-01 11:35 UTC (permalink / raw
To: Ping-Ke Shih; +Cc: Kalle Valo, linux-wireless, lvc-project, Dmitry Antipov
Since 'regulation' is a compile-time constant equal to
'TXPWR_LMT_WW', mark it as such and simplify few branches
in '_rtl8812ae_phy_get_txpower_limit()'. Compile tested only.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
.../wireless/realtek/rtlwifi/rtl8821ae/phy.c | 24 +++++++------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
index c262770fea29..27e256a82f00 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
@@ -2278,16 +2278,15 @@ static s8 _rtl8812ae_phy_get_txpower_limit(struct ieee80211_hw *hw,
struct rtl_priv *rtlpriv = rtl_priv(hw);
struct rtl_efuse *rtlefuse = rtl_efuse(rtlpriv);
struct rtl_phy *rtlphy = &rtlpriv->phy;
- short band_temp = -1, regulation = -1, bandwidth_temp = -1,
- rate_section = -1, channel_temp = -1;
- u16 regu, bdwidth, sec, chnl;
+ short band_temp = -1, bandwidth_temp = -1,
+ rate_section = -1, channel_temp = -1;
+ u16 bdwidth, sec, chnl;
s8 power_limit = MAX_POWER_INDEX;
+ const short regulation = TXPWR_LMT_WW;
if (rtlefuse->eeprom_regulatory == 2)
return MAX_POWER_INDEX;
- regulation = TXPWR_LMT_WW;
-
if (band == BAND_ON_2_4G)
band_temp = 0;
else if (band == BAND_ON_5G)
@@ -2393,8 +2392,8 @@ static s8 _rtl8812ae_phy_get_txpower_limit(struct ieee80211_hw *hw,
;/* BAND_ON_BOTH don't care temporarily */
}
- if (band_temp == -1 || regulation == -1 || bandwidth_temp == -1 ||
- rate_section == -1 || channel_temp == -1) {
+ if (band_temp == -1 || bandwidth_temp == -1 ||
+ rate_section == -1 || channel_temp == -1) {
rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD,
"Wrong index value to access power limit table [band %d][regulation %d][bandwidth %d][rf_path %d][rate_section %d][chnl %d]\n",
band_temp, regulation, bandwidth_temp, rf_path,
@@ -2402,7 +2401,6 @@ static s8 _rtl8812ae_phy_get_txpower_limit(struct ieee80211_hw *hw,
return MAX_POWER_INDEX;
}
- regu = regulation;
bdwidth = bandwidth_temp;
sec = rate_section;
chnl = channel_temp;
@@ -2415,10 +2413,7 @@ static s8 _rtl8812ae_phy_get_txpower_limit(struct ieee80211_hw *hw,
limits[i] = rtlphy->txpwr_limit_2_4g[i][bdwidth]
[sec][chnl][rf_path];
- power_limit = (regulation == TXPWR_LMT_WW) ?
- _rtl8812ae_phy_get_world_wide_limit(limits) :
- rtlphy->txpwr_limit_2_4g[regu][bdwidth]
- [sec][chnl][rf_path];
+ power_limit = _rtl8812ae_phy_get_world_wide_limit(limits);
} else if (band == BAND_ON_5G) {
s8 limits[10] = {0};
u8 i;
@@ -2427,10 +2422,7 @@ static s8 _rtl8812ae_phy_get_txpower_limit(struct ieee80211_hw *hw,
limits[i] = rtlphy->txpwr_limit_5g[i][bdwidth]
[sec][chnl][rf_path];
- power_limit = (regulation == TXPWR_LMT_WW) ?
- _rtl8812ae_phy_get_world_wide_limit(limits) :
- rtlphy->txpwr_limit_5g[regu][chnl]
- [sec][chnl][rf_path];
+ power_limit = _rtl8812ae_phy_get_world_wide_limit(limits);
} else {
rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD,
"No power limit table of the specified band\n");
--
2.41.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH 1/2] wifi: rtlwifi: remove dead code in phy_get_tx_swing_8812A()
2023-11-01 11:35 [PATCH 1/2] wifi: rtlwifi: remove dead code in phy_get_tx_swing_8812A() Dmitry Antipov
2023-11-01 11:35 ` [PATCH 2/2] wifi: rtlwifi: simplify _rtl8812ae_phy_get_txpower_limit() Dmitry Antipov
@ 2023-11-06 3:37 ` Ping-Ke Shih
1 sibling, 0 replies; 4+ messages in thread
From: Ping-Ke Shih @ 2023-11-06 3:37 UTC (permalink / raw
To: Dmitry Antipov
Cc: Kalle Valo, linux-wireless@vger.kernel.org,
lvc-project@linuxtesting.org
> -----Original Message-----
> From: Dmitry Antipov <dmantipov@yandex.ru>
> Sent: Wednesday, November 1, 2023 7:35 PM
> To: Ping-Ke Shih <pkshih@realtek.com>
> Cc: Kalle Valo <kvalo@kernel.org>; linux-wireless@vger.kernel.org; lvc-project@linuxtesting.org; Dmitry
> Antipov <dmantipov@yandex.ru>
> Subject: [PATCH 1/2] wifi: rtlwifi: remove dead code in phy_get_tx_swing_8812A()
>
> Since 'reg_swing_2g', 'swing_2g', 'reg_swing_5g', and 'swing_5g'
> are compile-time constants, mark all of them as such and remove
> never executed blocks in 'phy_get_tx_swing_8812A()'. Minor style
> adjustments, compile tested only.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
> ---
> .../wireless/realtek/rtlwifi/rtl8821ae/phy.c | 77 ++++---------------
> 1 file changed, 16 insertions(+), 61 deletions(-)
>
> diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
> b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
> index 5323ead30db0..c262770fea29 100644
> --- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
> +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
> @@ -437,12 +437,11 @@ u32 phy_get_tx_swing_8812A(struct ieee80211_hw *hw, u8 band,
> struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
> struct rtl_dm *rtldm = rtl_dm(rtlpriv);
> struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
> - s8 reg_swing_2g = -1;/* 0xff; */
> - s8 reg_swing_5g = -1;/* 0xff; */
> - s8 swing_2g = -1 * reg_swing_2g;
> - s8 swing_5g = -1 * reg_swing_5g;
> - u32 out = 0x200;
> - const s8 auto_temp = -1;
> + const s8 reg_swing_2g = -1; /* 0xff; */
> + const s8 reg_swing_5g = -1; /* 0xff; */
Looks like these two can be removed, but I don't really understand what it
wants originally.
> + const s8 swing_2g = -1 * reg_swing_2g;
> + const s8 swing_5g = -1 * reg_swing_5g;
> + u32 out = 0x200;
>
> rtl_dbg(rtlpriv, COMP_SCAN, DBG_LOUD,
> "===> PHY_GetTXBBSwing_8812A, bbSwing_2G: %d, bbSwing_5G: %d,autoload_failflag=%d.\n",
> @@ -452,36 +451,16 @@ u32 phy_get_tx_swing_8812A(struct ieee80211_hw *hw, u8 band,
> if (rtlefuse->autoload_failflag) {
> if (band == BAND_ON_2_4G) {
> rtldm->swing_diff_2g = swing_2g;
> - if (swing_2g == 0) {
> - out = 0x200; /* 0 dB */
> - } else if (swing_2g == -3) {
> - out = 0x16A; /* -3 dB */
> - } else if (swing_2g == -6) {
> - out = 0x101; /* -6 dB */
> - } else if (swing_2g == -9) {
> - out = 0x0B6; /* -9 dB */
> - } else {
> - rtldm->swing_diff_2g = 0;
> - out = 0x200;
> - }
> + rtldm->swing_diff_2g = 0;
> + out = 0x200;
This branch becomes duplicate assignments of swing_diff_2g.
rtldm->swing_diff_2g = swing_2g;
rtldm->swing_diff_2g = 0;
out = 0x200;
The original branch chunk might be debug purpose, so maybe add a debugfs entry as
the input of 'swing_2g'. Or, that is used by some boards that don't programmed efuse
but read 'swing_2g' from external file.
It is hard to me to decide if we should take this cleanup.
Ping-Ke
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH 2/2] wifi: rtlwifi: simplify _rtl8812ae_phy_get_txpower_limit()
2023-11-01 11:35 ` [PATCH 2/2] wifi: rtlwifi: simplify _rtl8812ae_phy_get_txpower_limit() Dmitry Antipov
@ 2023-11-06 3:44 ` Ping-Ke Shih
0 siblings, 0 replies; 4+ messages in thread
From: Ping-Ke Shih @ 2023-11-06 3:44 UTC (permalink / raw
To: Dmitry Antipov
Cc: Kalle Valo, linux-wireless@vger.kernel.org,
lvc-project@linuxtesting.org
> -----Original Message-----
> From: Dmitry Antipov <dmantipov@yandex.ru>
> Sent: Wednesday, November 1, 2023 7:35 PM
> To: Ping-Ke Shih <pkshih@realtek.com>
> Cc: Kalle Valo <kvalo@kernel.org>; linux-wireless@vger.kernel.org; lvc-project@linuxtesting.org; Dmitry
> Antipov <dmantipov@yandex.ru>
> Subject: [PATCH 2/2] wifi: rtlwifi: simplify _rtl8812ae_phy_get_txpower_limit()
>
> Since 'regulation' is a compile-time constant equal to
> 'TXPWR_LMT_WW', mark it as such and simplify few branches
> in '_rtl8812ae_phy_get_txpower_limit()'. Compile tested only.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
> ---
> .../wireless/realtek/rtlwifi/rtl8821ae/phy.c | 24 +++++++------------
> 1 file changed, 8 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
> b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
> index c262770fea29..27e256a82f00 100644
[...]
> @@ -2415,10 +2413,7 @@ static s8 _rtl8812ae_phy_get_txpower_limit(struct ieee80211_hw *hw,
> limits[i] = rtlphy->txpwr_limit_2_4g[i][bdwidth]
> [sec][chnl][rf_path];
>
> - power_limit = (regulation == TXPWR_LMT_WW) ?
> - _rtl8812ae_phy_get_world_wide_limit(limits) :
> - rtlphy->txpwr_limit_2_4g[regu][bdwidth]
> - [sec][chnl][rf_path];
> + power_limit = _rtl8812ae_phy_get_world_wide_limit(limits);
I think the constantly selection of "WW" is just a workaround, and correct
way is to add regd notifier and handle regulatory request.
Ping-Ke
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-06 3:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-01 11:35 [PATCH 1/2] wifi: rtlwifi: remove dead code in phy_get_tx_swing_8812A() Dmitry Antipov
2023-11-01 11:35 ` [PATCH 2/2] wifi: rtlwifi: simplify _rtl8812ae_phy_get_txpower_limit() Dmitry Antipov
2023-11-06 3:44 ` Ping-Ke Shih
2023-11-06 3:37 ` [PATCH 1/2] wifi: rtlwifi: remove dead code in phy_get_tx_swing_8812A() Ping-Ke Shih
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).