Skip to contentSkip to conversation

platform/x86: asus-wmi: Fix wlan_ctrl_by_user detection

PATCH In review Hans de Goede 3 participants 5 messages May 1, 2025 – May 7, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover platform/x86: asus-wmi: Fix wlan_ctrl_by_user detection

Hi All,

Here is a patch which fixes:
https://bugzilla.kernel.org/show_bug.cgi?id=219786

The patch itself is trivial enough and seems obviously correct to me, but the code it fixes was first introduced in 2012 and we've been doing the wrong thing when setting rfkill state on some Asus laptops ever since.

rfkill has always been a bit finicky on Asus laptops, so I must admit that I'm worried about this causing regressions (or maybe the fixed issue was the root cause of some of our issues?

So I think we should try to get this into 6.15, but not backport it for a while to see if this does not cause regressions.

Regards,

Hans

Hans de Goede (1):
platform/x86: asus-wmi: Fix wlan_ctrl_by_user detection

 drivers/platform/x86/asus-wmi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.49.0
#1 lore raw

PATCH 1/1 platform/x86: asus-wmi: Fix wlan_ctrl_by_user detection

The wlan_ctrl_by_user detection was introduced by commit a50bd128f28c ("asus-wmi: record wlan status while controlled by userapp").

Quoting from that commit's commit message:

"""
When you call WMIMethod(DSTS, 0x00010011) to get WLAN status, it may return

(1) 0x00050001 (On)
(2) 0x00050000 (Off)
(3) 0x00030001 (On)
(4) 0x00030000 (Off)
(5) 0x00000002 (Unknown)

(1), (2) means that the model has hardware GPIO for WLAN, you can call WMIMethod(DEVS, 0x00010011, 1 or 0) to turn WLAN on/off.
(3), (4) means that the model doesn’t have hardware GPIO, you need to use API or driver library to turn WLAN on/off, and call WMIMethod(DEVS, 0x00010012, 1 or 0) to set WLAN LED status. After you set WLAN LED status, you can see the WLAN status is changed with WMIMethod(DSTS, 0x00010011). Because the status is recorded lastly (ex: Windows), you can use it for synchronization.
(5) means that the model doesn’t have WLAN device.

WLAN is the ONLY special case with upper rule.
"""

The wlan_ctrl_by_user flag should be set on 0x0003000? ((3), (4) above) return values, but the flag mistakenly also gets set on laptops with 0x0005000? ((1), (2)) return values. This is causing rfkill problems on laptops where 0x0005000? is returned.

Fix the check to only set the wlan_ctrl_by_user flag for 0x0003000? return values.

Fixes a50bd128f28c ("asus-wmi: record wlan status while controlled by userapp")
---
 drivers/platform/x86/asus-wmi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/x86/asus-wmi.c +2 -1
index 38ef778e8c19..f66d152e265d 100644
@@ -4777,7 +4777,8 @@ static int asus_wmi_add(struct platform_device *pdev)
 		goto fail_leds;
 
 	asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WLAN, &result);
-	if (result & (ASUS_WMI_DSTS_PRESENCE_BIT | ASUS_WMI_DSTS_USER_BIT))
+	if ((result & (ASUS_WMI_DSTS_PRESENCE_BIT | ASUS_WMI_DSTS_USER_BIT)) ==
+	    (ASUS_WMI_DSTS_PRESENCE_BIT | ASUS_WMI_DSTS_USER_BIT))
 		asus->driver->wlan_ctrl_by_user = 1;
 
 	if (!(asus->driver->wlan_ctrl_by_user && ashs_present())) {
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#2 lore raw

Am 01.05.25 um 15:17 schrieb Hans de Goede:

Quoted 47 lines

The wlan_ctrl_by_user detection was introduced by commit a50bd128f28c ("asus-wmi: record wlan status while controlled by userapp").

Quoting from that commit's commit message:

"""
When you call WMIMethod(DSTS, 0x00010011) to get WLAN status, it may return

(1) 0x00050001 (On)
(2) 0x00050000 (Off)
(3) 0x00030001 (On)
(4) 0x00030000 (Off)
(5) 0x00000002 (Unknown)

(1), (2) means that the model has hardware GPIO for WLAN, you can call WMIMethod(DEVS, 0x00010011, 1 or 0) to turn WLAN on/off.
(3), (4) means that the model doesn’t have hardware GPIO, you need to use API or driver library to turn WLAN on/off, and call WMIMethod(DEVS, 0x00010012, 1 or 0) to set WLAN LED status. After you set WLAN LED status, you can see the WLAN status is changed with WMIMethod(DSTS, 0x00010011). Because the status is recorded lastly (ex: Windows), you can use it for synchronization.
(5) means that the model doesn’t have WLAN device.

WLAN is the ONLY special case with upper rule.
"""

The wlan_ctrl_by_user flag should be set on 0x0003000? ((3), (4) above) return values, but the flag mistakenly also gets set on laptops with 0x0005000? ((1), (2)) return values. This is causing rfkill problems on laptops where 0x0005000? is returned.

Fix the check to only set the wlan_ctrl_by_user flag for 0x0003000? return values.

Fixes a50bd128f28c ("asus-wmi: record wlan status while controlled by userapp")
---
  drivers/platform/x86/asus-wmi.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/x86/asus-wmi.c +0 -0
index 38ef778e8c19..f66d152e265d 100644

drivers/platform/x86/asus-wmi.c static int asus_wmi_add(struct platform_device *pdev) · line 4781

Quoted 6 lines
drivers/platform/x86/asus-wmi.c +2 -1
@@ -4777,7 +4777,8 @@ static int asus_wmi_add(struct platform_device *pdev)
  		goto fail_leds;
 
  	asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WLAN, &result);
-	if (result & (ASUS_WMI_DSTS_PRESENCE_BIT | ASUS_WMI_DSTS_USER_BIT))
+	if ((result & (ASUS_WMI_DSTS_PRESENCE_BIT | ASUS_WMI_DSTS_USER_BIT)) ==
+	    (ASUS_WMI_DSTS_PRESENCE_BIT | ASUS_WMI_DSTS_USER_BIT))

Good catch, seems that the original commit forgot about the presence bit.

Quoted 3 lines
drivers/platform/x86/asus-wmi.c +0 -0
  		asus->driver->wlan_ctrl_by_user = 1;
 
  	if (!(asus->driver->wlan_ctrl_by_user && ashs_present())) {
#3 lore raw
In reply to Hans de Goede

Am 01.05.25 um 15:17 schrieb Hans de Goede:

Quoted 13 lines

Hi All,

Here is a patch which fixes:
https://bugzilla.kernel.org/show_bug.cgi?id=219786

The patch itself is trivial enough and seems obviously correct to me, but the code it fixes was first introduced in 2012 and we've been doing the wrong thing when setting rfkill state on some Asus laptops ever since.

rfkill has always been a bit finicky on Asus laptops, so I must admit that I'm worried about this causing regressions (or maybe the fixed issue was the root cause of some of our issues?

Quoted 6 lines

So I think we should try to get this into 6.15, but not backport it for a while to see if this does not cause regressions.

Regards,

Hans

I agree, this issue could potentially be the root cause for all the rfkill problems on Asus devices. Since this patch has been tested on real hardware, i think that we can safely add it to the 6.15 kernel.

Thanks,
Armin Wolf

Quoted 8 lines

Hans de Goede (1):
platform/x86: asus-wmi: Fix wlan_ctrl_by_user detection

  drivers/platform/x86/asus-wmi.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
maintainer
#4 lore raw
In reply to Hans de Goede
Quoted 8 lines · Hans de Goede

Here is a patch which fixes:
https://bugzilla.kernel.org/show_bug.cgi?id=219786

The patch itself is trivial enough and seems obviously correct to me, but the code it fixes was first introduced in 2012 and we've been doing the wrong thing when setting rfkill state on some Asus laptops ever since.

[...]

Thank you for your contribution, it has been applied to my local review-ilpo-fixes branch. Note it will show up in the public platform-drivers-x86/review-ilpo-fixes branch only once I've pushed my local branch there, which might take a while.

The list of commits applied:
[1/1] platform/x86: asus-wmi: Fix wlan_ctrl_by_user detection

      commit: bfcfe6d335a967f8ea0c1980960e6f0205b5de6e

--
i.