Skip to contentSkip to conversation

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

PATCH In review Bitterblue Smith 2 participants 3 messages Apr 15, 2024 – Apr 19, 2024 RTL8XXXU wireless driver (rtl8xxxu)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 wifi: rtl8xxxu: Fix the TX power of RTL8192CU, RTL8723AU

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.

---
v1 was a long time ago:
https://lore.kernel.org/linux-wireless/[email protected]/

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(-)
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +10 -15
index 7bf0bbbd52c1..af58e5b2c846 100644
@@ -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);
 	}
 }
Signature · 1 line
2.44.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Bitterblue Smith

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.

Quoted 8 lines

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.

Quoted 3 lines

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

#2 lore raw
In reply to Bitterblue Smith
Quoted 8 lines · Bitterblue Smith

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.

Quoted 8 lines

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.

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