From ce6ad123e76311d2a882054b4ea532d1bfb643c8 Mon Sep 17 00:00:00 2001 From: Shiji Yang Date: Tue, 22 Aug 2023 19:16:22 +0100 Subject: [PATCH] mac80211: fix MT7620 Wi-Fi channel scanning function During the channel scanning process, the driver will continuously switch channels. It seems that the full RF calibration step in rt2800_config_channel() caused the channel scanning function to timeout. To fix it, move the RF calibration to rt2800_enable_radio() so that it is only executed once. This commit also includes some coding format adjustments to follow the Linux recommended style. Fixes: 2824fa6963cf ("mac80211: rework MT7620 PA/LNA RF calibration") Signed-off-by: Shiji Yang --- ...-rework-MT7620-PA-LNA-RF-calibration.patch | 93 +++++++------------ 1 file changed, 36 insertions(+), 57 deletions(-) diff --git a/package/kernel/mac80211/patches/rt2x00/998-wifi-rt2x00-rework-MT7620-PA-LNA-RF-calibration.patch b/package/kernel/mac80211/patches/rt2x00/998-wifi-rt2x00-rework-MT7620-PA-LNA-RF-calibration.patch index 7fdad6397660..5f6f5140d9e9 100644 --- a/package/kernel/mac80211/patches/rt2x00/998-wifi-rt2x00-rework-MT7620-PA-LNA-RF-calibration.patch +++ b/package/kernel/mac80211/patches/rt2x00/998-wifi-rt2x00-rework-MT7620-PA-LNA-RF-calibration.patch @@ -3,8 +3,6 @@ Date: Tue, 25 Jul 2023 20:05:06 +0800 Subject: [PATCH] wifi: rt2x00: rework MT7620 PA/LNA RF calibration 1. Move MT7620 PA/LNA calibration code to dedicated functions. - Calibration stage 1 is executed before configuring channels and - stage 2 is executed after configuring channels. 2. For external PA/LNA devices, restore RF and BBP registers before R-Calibration. 3. Do Rx DCOC calibration again before RXIQ calibration. @@ -21,23 +19,13 @@ Subject: [PATCH] wifi: rt2x00: rework MT7620 PA/LNA RF calibration Signed-off-by: Shiji Yang --- - .../net/wireless/ralink/rt2x00/rt2800lib.c | 318 +++++++++++------- + .../net/wireless/ralink/rt2x00/rt2800lib.c | 306 ++++++++++-------- drivers/net/wireless/ralink/rt2x00/rt2x00.h | 6 + - 2 files changed, 194 insertions(+), 130 deletions(-) + 2 files changed, 182 insertions(+), 130 deletions(-) --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c -@@ -62,6 +62,9 @@ MODULE_PARM_DESC(watchdog, "Enable watch - rt2800_regbusy_read((__dev), H2M_MAILBOX_CSR, \ - H2M_MAILBOX_CSR_OWNER, (__reg)) - -+static void rt6352_init_palna_stage1(struct rt2x00_dev *rt2x00dev); -+static void rt6352_init_palna_stage2(struct rt2x00_dev *rt2x00dev); -+ - static inline bool rt2800_is_305x_soc(struct rt2x00_dev *rt2x00dev) - { - /* check for rt2872 on SoC */ -@@ -3881,14 +3884,6 @@ static void rt2800_config_channel_rf7620 +@@ -3881,14 +3881,6 @@ static void rt2800_config_channel_rf7620 rfcsr |= tx_agc_fc; rt2800_rfcsr_write_bank(rt2x00dev, 7, 59, rfcsr); } @@ -52,17 +40,7 @@ Signed-off-by: Shiji Yang } static void rt2800_config_alc_rt6352(struct rt2x00_dev *rt2x00dev, -@@ -4151,6 +4146,9 @@ static void rt2800_config_channel(struct - rt2800_txpower_to_dev(rt2x00dev, rf->channel, - info->default_power3); - -+ if (rt2x00_rt(rt2x00dev, RT6352)) -+ rt6352_init_palna_stage1(rt2x00dev); -+ - switch (rt2x00dev->chip.rt) { - case RT3883: - rt3883_bbp_adjust(rt2x00dev, rf); -@@ -4457,89 +4455,65 @@ static void rt2800_config_channel(struct +@@ -4457,89 +4449,63 @@ static void rt2800_config_channel(struct usleep_range(1000, 1500); } @@ -193,12 +171,10 @@ Signed-off-by: Shiji Yang + * Otherwise it's difficult to pass the WHQL. + */ + usleep_range(1000, 1500); -+ -+ rt6352_init_palna_stage2(rt2x00dev); } bbp = rt2800_bbp_read(rt2x00dev, 4); -@@ -5649,43 +5623,6 @@ void rt2800_vco_calibration(struct rt2x0 +@@ -5649,43 +5615,6 @@ void rt2800_vco_calibration(struct rt2x0 } } rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin); @@ -242,7 +218,7 @@ Signed-off-by: Shiji Yang } EXPORT_SYMBOL_GPL(rt2800_vco_calibration); -@@ -8650,7 +8587,7 @@ static void rt2800_r_calibration(struct +@@ -8650,7 +8579,7 @@ static void rt2800_r_calibration(struct rt2x00_warn(rt2x00dev, "Wait MAC Tx Status to MAX !!!\n"); maccfg = rt2800_register_read(rt2x00dev, MAC_SYS_CTRL); @@ -251,7 +227,7 @@ Signed-off-by: Shiji Yang rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, maccfg); if (unlikely(rt2800_wait_bbp_rf_ready(rt2x00dev, MAC_STATUS_CFG_BBP_RF_BUSY_RX))) -@@ -10688,30 +10625,151 @@ static void rt2800_init_rfcsr_6352(struc +@@ -10688,30 +10617,143 @@ static void rt2800_init_rfcsr_6352(struc rt2800_rfcsr_write_dccal(rt2x00dev, 5, 0x00); rt2800_rfcsr_write_dccal(rt2x00dev, 17, 0x7C); } @@ -266,7 +242,7 @@ Signed-off-by: Shiji Yang - rt2800_loft_iq_calibration(rt2x00dev); - rt2800_rxiq_calibration(rt2x00dev); - rt6352_enable_pa_pin(rt2x00dev, 1); -+static void rt6352_init_ext_palna(struct rt2x00_dev *rt2x00dev) ++static void rt2800_init_palna_rt6352(struct rt2x00_dev *rt2x00dev) +{ + u32 reg; + @@ -282,14 +258,14 @@ Signed-off-by: Shiji Yang - if (rt2x00_has_cap_external_lna_bg(rt2x00dev)) { + if (rt2800_hw_get_chippkg(rt2x00dev) == 1 && -+ rt2x00_has_cap_external_lna_bg(rt2x00dev)) { ++ rt2x00_has_cap_external_lna_bg(rt2x00dev)) { rt2800_rfcsr_write_chanreg(rt2x00dev, 14, 0x66); rt2800_rfcsr_write_chanreg(rt2x00dev, 17, 0x20); rt2800_rfcsr_write_chanreg(rt2x00dev, 18, 0x42); + } + + if (rt2800_hw_get_chippkg(rt2x00dev) == 1 && -+ rt2x00_has_cap_external_pa(rt2x00dev)) { ++ rt2x00_has_cap_external_pa(rt2x00dev)) { + rt2800_rfcsr_write_chanreg(rt2x00dev, 43, 0x73); + rt2800_rfcsr_write_chanreg(rt2x00dev, 44, 0x73); + rt2800_rfcsr_write_chanreg(rt2x00dev, 45, 0x73); @@ -308,12 +284,11 @@ Signed-off-by: Shiji Yang + } + + if (rt2800_hw_get_chippkg(rt2x00dev) == 1 && -+ rt2x00_has_cap_external_pa(rt2x00dev)) { ++ rt2x00_has_cap_external_pa(rt2x00dev)) + rt2800_rfcsr_write_dccal(rt2x00dev, 05, 0x00); -+ } + + if (rt2800_hw_get_chippkg(rt2x00dev) == 1 && -+ rt2x00_has_cap_external_lna_bg(rt2x00dev)) { ++ rt2x00_has_cap_external_lna_bg(rt2x00dev)) { rt2800_bbp_write(rt2x00dev, 75, 0x68); rt2800_bbp_write(rt2x00dev, 76, 0x4C); rt2800_bbp_write(rt2x00dev, 79, 0x1C); @@ -326,14 +301,14 @@ Signed-off-by: Shiji Yang + } + + if (rt2800_hw_get_chippkg(rt2x00dev) == 1 && -+ rt2x00_has_cap_external_pa(rt2x00dev)) { ++ rt2x00_has_cap_external_pa(rt2x00dev)) { + rt2800_register_write(rt2x00dev, TX0_RF_GAIN_CORRECT, 0x36303636); + rt2800_register_write(rt2x00dev, TX0_RF_GAIN_ATTEN, 0x6C6C6B6C); + rt2800_register_write(rt2x00dev, TX1_RF_GAIN_ATTEN, 0x6C6C6B6C); + } +} + -+static void rt6352_restore_rf_bbp(struct rt2x00_dev *rt2x00dev) ++static void rt2800_restore_rf_bbp_rt6352(struct rt2x00_dev *rt2x00dev) +{ + if (rt2x00_has_cap_external_pa(rt2x00dev)) { + rt2800_register_write(rt2x00dev, RF_CONTROL3, 0x0); @@ -341,15 +316,14 @@ Signed-off-by: Shiji Yang + } + + if (rt2800_hw_get_chippkg(rt2x00dev) == 1 && -+ rt2x00_has_cap_external_lna_bg(rt2x00dev)) { ++ rt2x00_has_cap_external_lna_bg(rt2x00dev)) { + rt2800_rfcsr_write_chanreg(rt2x00dev, 14, 0x16); + rt2800_rfcsr_write_chanreg(rt2x00dev, 17, 0x23); + rt2800_rfcsr_write_chanreg(rt2x00dev, 18, 0x02); + } + + if (rt2800_hw_get_chippkg(rt2x00dev) == 1 && -+ rt2x00_has_cap_external_pa(rt2x00dev)) -+ { ++ rt2x00_has_cap_external_pa(rt2x00dev)) { + rt2800_rfcsr_write_chanreg(rt2x00dev, 43, 0xD3); + rt2800_rfcsr_write_chanreg(rt2x00dev, 44, 0xB3); + rt2800_rfcsr_write_chanreg(rt2x00dev, 45, 0xD5); @@ -368,7 +342,7 @@ Signed-off-by: Shiji Yang + } + + if (rt2800_hw_get_chippkg(rt2x00dev) == 1 && -+ rt2x00_has_cap_external_lna_bg(rt2x00dev)) { ++ rt2x00_has_cap_external_lna_bg(rt2x00dev)) { + rt2800_bbp_write(rt2x00dev, 75, 0x60); + rt2800_bbp_write(rt2x00dev, 76, 0x44); + rt2800_bbp_write(rt2x00dev, 79, 0x1C); @@ -376,29 +350,23 @@ Signed-off-by: Shiji Yang + rt2800_bbp_write(rt2x00dev, 82, 0xB6); + } + -+ if (rt2800_hw_get_chippkg(rt2x00dev) == 1 -+ && rt2x00_has_cap_external_pa(rt2x00dev)) { ++ if (rt2800_hw_get_chippkg(rt2x00dev) == 1 && ++ rt2x00_has_cap_external_pa(rt2x00dev)) { + rt2800_register_write(rt2x00dev, TX0_RF_GAIN_CORRECT, 0x3630363A); + rt2800_register_write(rt2x00dev, TX0_RF_GAIN_ATTEN, 0x6C6C666C); + rt2800_register_write(rt2x00dev, TX1_RF_GAIN_ATTEN, 0x6C6C666C); + } +} + -+/* MT7620 PA/LNA initialization before switching channels */ -+static void rt6352_init_palna_stage1(struct rt2x00_dev *rt2x00dev) ++static void rt2800_calibration_rt6352(struct rt2x00_dev *rt2x00dev) +{ + if (rt2x00_has_cap_external_pa(rt2x00dev) || -+ rt2x00_has_cap_external_lna_bg(rt2x00dev)) { ++ rt2x00_has_cap_external_lna_bg(rt2x00dev)) { + rt6352_enable_pa_pin(rt2x00dev, 0); -+ rt6352_restore_rf_bbp(rt2x00dev); ++ rt2800_restore_rf_bbp_rt6352(rt2x00dev); + } + + rt2800_r_calibration(rt2x00dev); -+} -+ -+/* MT7620 PA/LNA initialization after switching channels */ -+static void rt6352_init_palna_stage2(struct rt2x00_dev *rt2x00dev) -+{ + rt2800_rf_self_txdc_cal(rt2x00dev); + rt2800_rxdcoc_calibration(rt2x00dev); + rt2800_bw_filter_calibration(rt2x00dev, true); @@ -410,13 +378,24 @@ Signed-off-by: Shiji Yang + rt2800_rxdcoc_calibration(rt2x00dev); + rt2800_rxiq_calibration(rt2x00dev); + -+ if(rt2x00_has_cap_external_pa(rt2x00dev) || -+ rt2x00_has_cap_external_lna_bg(rt2x00dev)) { ++ if (rt2x00_has_cap_external_pa(rt2x00dev) || ++ rt2x00_has_cap_external_lna_bg(rt2x00dev)) { + rt6352_enable_pa_pin(rt2x00dev, 1); -+ rt6352_init_ext_palna(rt2x00dev); ++ rt2800_init_palna_rt6352(rt2x00dev); } } +@@ -10804,6 +10846,10 @@ int rt2800_enable_radio(struct rt2x00_de + rt2800_init_bbp(rt2x00dev); + rt2800_init_rfcsr(rt2x00dev); + ++ /* Do calibration and init PA/LNA for RT6352 */ ++ if (rt2x00_rt(rt2x00dev, RT6352)) ++ rt2800_calibration_rt6352(rt2x00dev); ++ + if (rt2x00_is_usb(rt2x00dev) && + (rt2x00_rt(rt2x00dev, RT3070) || + rt2x00_rt(rt2x00dev, RT3071) || --- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h @@ -1277,6 +1277,12 @@ rt2x00_has_cap_external_lna_bg(struct rt -- 2.30.2