diff mbox series

[v2] wifi: rtl8xxxu: Fix the TX power of RTL8192CU, RTL8723AU

Message ID 6ae5945b-644e-45e4-a78f-4c7d9c987910@gmail.com (mailing list archive)
State Accepted
Delegated to: Ping-Ke Shih
Headers show
Series [v2] wifi: rtl8xxxu: Fix the TX power of RTL8192CU, RTL8723AU | expand

Commit Message

Bitterblue Smith April 15, 2024, 8:59 p.m. UTC
Don't subtract 1 from the power index. This was added in commit
2fc0b8e5a17d ("rtl8xxxu: Add TX power base values for gen1 parts")
for unknown reasons. The vendor drivers don't do this.

Also correct the calculations of values written to
REG_OFDM0_X{C,D}_TX_IQ_IMBALANCE. According to the vendor driver,
these are used for TX power training.

With these changes rtl8xxxu sets the TX power of RTL8192CU the same
as the vendor driver.

None of this appears to have any effect on my RTL8192CU device.

Cc: stable@vger.kernel.org
Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
---
v1 was a long time ago:
https://lore.kernel.org/linux-wireless/52c28b65-6f28-2cc0-7281-179bb1087c2a@gmail.com/

v2:
 - Use ternary operator and max_t in the for loops.
---
 .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 25 ++++++++-----------
 1 file changed, 10 insertions(+), 15 deletions(-)

Comments

Ping-Ke Shih April 16, 2024, 6:31 a.m. UTC | #1
Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
> 
> Don't subtract 1 from the power index. This was added in commit
> 2fc0b8e5a17d ("rtl8xxxu: Add TX power base values for gen1 parts")
> for unknown reasons. The vendor drivers don't do this.
> 
> Also correct the calculations of values written to
> REG_OFDM0_X{C,D}_TX_IQ_IMBALANCE. According to the vendor driver,
> these are used for TX power training.
> 
> With these changes rtl8xxxu sets the TX power of RTL8192CU the same
> as the vendor driver.
> 
> None of this appears to have any effect on my RTL8192CU device.

IIRC TX power is in unit of 0.5 dBm, so that would not be significant to
throughput. 

> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>

I checked logic of changes is the same as vendor driver now. 

Reviewed-by: Ping-Ke Shih <pkshih@realtek.com>
Ping-Ke Shih April 19, 2024, 1:43 a.m. UTC | #2
Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:

> Don't subtract 1 from the power index. This was added in commit
> 2fc0b8e5a17d ("rtl8xxxu: Add TX power base values for gen1 parts")
> for unknown reasons. The vendor drivers don't do this.
> 
> Also correct the calculations of values written to
> REG_OFDM0_X{C,D}_TX_IQ_IMBALANCE. According to the vendor driver,
> these are used for TX power training.
> 
> With these changes rtl8xxxu sets the TX power of RTL8192CU the same
> as the vendor driver.
> 
> None of this appears to have any effect on my RTL8192CU device.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
> Reviewed-by: Ping-Ke Shih <pkshih@realtek.com>

1 patch(es) applied to rtw-next branch of rtw.git, thanks.

08b5d052d17a wifi: rtl8xxxu: Fix the TX power of RTL8192CU, RTL8723AU

---
https://github.com/pkshih/rtw.git
diff mbox series

Patch

diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
index 7bf0bbbd52c1..af58e5b2c846 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
@@ -1480,13 +1480,13 @@  rtl8xxxu_gen1_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40)
 	u8 cck[RTL8723A_MAX_RF_PATHS], ofdm[RTL8723A_MAX_RF_PATHS];
 	u8 ofdmbase[RTL8723A_MAX_RF_PATHS], mcsbase[RTL8723A_MAX_RF_PATHS];
 	u32 val32, ofdm_a, ofdm_b, mcs_a, mcs_b;
-	u8 val8;
+	u8 val8, base;
 	int group, i;
 
 	group = rtl8xxxu_gen1_channel_to_group(channel);
 
-	cck[0] = priv->cck_tx_power_index_A[group] - 1;
-	cck[1] = priv->cck_tx_power_index_B[group] - 1;
+	cck[0] = priv->cck_tx_power_index_A[group];
+	cck[1] = priv->cck_tx_power_index_B[group];
 
 	if (priv->hi_pa) {
 		if (cck[0] > 0x20)
@@ -1497,10 +1497,6 @@  rtl8xxxu_gen1_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40)
 
 	ofdm[0] = priv->ht40_1s_tx_power_index_A[group];
 	ofdm[1] = priv->ht40_1s_tx_power_index_B[group];
-	if (ofdm[0])
-		ofdm[0] -= 1;
-	if (ofdm[1])
-		ofdm[1] -= 1;
 
 	ofdmbase[0] = ofdm[0] +	priv->ofdm_tx_power_index_diff[group].a;
 	ofdmbase[1] = ofdm[1] +	priv->ofdm_tx_power_index_diff[group].b;
@@ -1589,20 +1585,19 @@  rtl8xxxu_gen1_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40)
 
 	rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS15_MCS12,
 			 mcs_a + power_base->reg_0e1c);
+	val8 = u32_get_bits(mcs_a + power_base->reg_0e1c, 0xff000000);
 	for (i = 0; i < 3; i++) {
-		if (i != 2)
-			val8 = (mcsbase[0] > 8) ? (mcsbase[0] - 8) : 0;
-		else
-			val8 = (mcsbase[0] > 6) ? (mcsbase[0] - 6) : 0;
+		base = i != 2 ? 8 : 6;
+		val8 = max_t(int, val8 - base, 0);
 		rtl8xxxu_write8(priv, REG_OFDM0_XC_TX_IQ_IMBALANCE + i, val8);
 	}
+
 	rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS15_MCS12,
 			 mcs_b + power_base->reg_0868);
+	val8 = u32_get_bits(mcs_b + power_base->reg_0868, 0xff000000);
 	for (i = 0; i < 3; i++) {
-		if (i != 2)
-			val8 = (mcsbase[1] > 8) ? (mcsbase[1] - 8) : 0;
-		else
-			val8 = (mcsbase[1] > 6) ? (mcsbase[1] - 6) : 0;
+		base = i != 2 ? 8 : 6;
+		val8 = max_t(int, val8 - base, 0);
 		rtl8xxxu_write8(priv, REG_OFDM0_XD_TX_IQ_IMBALANCE + i, val8);
 	}
 }