2024-04-15 20:59:15

by Bitterblue Smith

[permalink] [raw]
Subject: [PATCH v2] 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.

Cc: [email protected]
Signed-off-by: Bitterblue Smith <[email protected]>
---
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(-)

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);
}
}
--
2.44.0



2024-04-16 06:32:21

by Ping-Ke Shih

[permalink] [raw]
Subject: RE: [PATCH v2] wifi: rtl8xxxu: Fix the TX power of RTL8192CU, RTL8723AU

Bitterblue Smith <[email protected]> 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: [email protected]
> Signed-off-by: Bitterblue Smith <[email protected]>

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

Reviewed-by: Ping-Ke Shih <[email protected]>


2024-04-19 01:44:06

by Ping-Ke Shih

[permalink] [raw]
Subject: Re: [PATCH v2] wifi: rtl8xxxu: Fix the TX power of RTL8192CU, RTL8723AU

Bitterblue Smith <[email protected]> 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: [email protected]
> Signed-off-by: Bitterblue Smith <[email protected]>
> Reviewed-by: Ping-Ke Shih <[email protected]>

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