2009-09-24 13:43:20

by Norbert Preining

[permalink] [raw]
Subject: rfkill hard state after booting

Hi all,

(please cc)

I recently (on a flight) I found out that when I boot with the hard-switch
activated, so turning off all wireless activity on my laptop, the state
is not correctly announced in /dev/rfkill (reading it with rfkill command,
or my own gnome applet). All the devices seem to be in normal state but
one.

Here some outputs:
$ cd /sys/class/rfkill
$ ls
rfkill0@ rfkill1@ rfkill2@ rfkill3@ rfkill4@ rfkill5@
$ cat rfkill?/name
sony-wifi
sony-bluetooth
sony-wwan
hso-0
hci0
phy0
$

and the three sony-* are the ones for actually turning on/off the devices,
but they showed all soft 0 hard 0 at initial startup. Only phy0 (AFAIR)
had hard 1.

After turning off and on again the hard-switch the events were right.

That is all with 2.6.31.
driver iwlagn, Detected Intel Wireless WiFi Link 5100AGN REV=0x54

Best wishes

Norbert

-------------------------------------------------------------------------------
Dr. Norbert Preining <[email protected]> Vienna University of Technology
Debian Developer <[email protected]> Debian TeX Group
gpg DSA: 0x09C5B094 fp: 14DF 2E6C 0307 BE6D AD76 A9C0 D2BF 4AA3 09C5 B094
-------------------------------------------------------------------------------
LIMERIGG (vb.)
To jar one's leg as the result of the disappearance of a stair which
isn't there in the darkness.
--- Douglas Adams, The Meaning of Liff


2009-09-24 22:49:29

by Mattia Dongili

[permalink] [raw]
Subject: Re: [PATCH] sony-laptop: check for rfkill hard block at load time

On Thu, Sep 24, 2009 at 08:15:24PM +0100, Alan Jenkins wrote:
> "I recently (on a flight) I found out that when I boot with the hard-switch
> activated, so turning off all wireless activity on my laptop, the state
> is not correctly announced in /dev/rfkill (reading it with rfkill command,
> or my own gnome applet)...
>
> After turning off and on again the hard-switch the events were right."
>
> We can fix this by querying the firmware at load time and calling
> rfkill_set_hw_state().

Is it worth trying to get this into a stable release?

> Signed-off-by: Alan Jenkins <[email protected]>
> Tested-by: Norbert Preining <[email protected]>

Acked-by: Mattia Dongili <[email protected]>

> ---
> drivers/platform/x86/sony-laptop.c | 6 ++++++
> 1 files changed, 6 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
> index dafaa4a..a234a9d 100644
> --- a/drivers/platform/x86/sony-laptop.c
> +++ b/drivers/platform/x86/sony-laptop.c
> @@ -1081,6 +1081,8 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
> struct rfkill *rfk;
> enum rfkill_type type;
> const char *name;
> + int result;
> + bool hwblock;
>
> switch (nc_type) {
> case SONY_WIFI:
> @@ -1108,6 +1110,10 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
> if (!rfk)
> return -ENOMEM;
>
> + sony_call_snc_handle(0x124, 0x200, &result);
> + hwblock = !(result & 0x1);
> + rfkill_set_hw_state(rfk, hwblock);
> +
> err = rfkill_register(rfk);
> if (err) {
> rfkill_destroy(rfk);
> --
> 1.6.3.2
>
>
>
--
mattia
:wq!

2009-09-24 17:29:29

by Johannes Berg

[permalink] [raw]
Subject: Re: rfkill hard state after booting

On Thu, 2009-09-24 at 16:12 +0100, Alan Jenkins wrote:

> > Although maybe it should just call sony_nc_rfkill_update() after
> > registering all of them?

> That means the initial "add" uevents etc. will contain wrong values (and
> then be updated immediately after). Do we care about that? It's
> unlikely to matter in practice for platform devices which only get
> loaded at boot-time, but perhaps it would set a bad example.

Ah, good point. I was just a little concerned about the logic
difference, but I don't really understand the _update() logic.

johannes


Attachments:
signature.asc (801.00 B)
This is a digitally signed message part

2009-09-24 15:12:30

by Alan Jenkins

[permalink] [raw]
Subject: Re: rfkill hard state after booting

Johannes Berg wrote:
> On Thu, 2009-09-24 at 16:01 +0100, Alan Jenkins wrote:
>
>
>> I think it's pretty clear it's in the sony code. It doesn't call
>> set_hw_state() during init. I.e. (completely untested):
>>
>
> Agree, looking at the code this seems reasonable.
>
> Although maybe it should just call sony_nc_rfkill_update() after
> registering all of them?
>
> johannes
>

That means the initial "add" uevents etc. will contain wrong values (and
then be updated immediately after). Do we care about that? It's
unlikely to matter in practice for platform devices which only get
loaded at boot-time, but perhaps it would set a bad example.

Regards
Alan

2009-09-24 19:24:43

by Gábor Stefanik

[permalink] [raw]
Subject: Re: [PATCH] sony-laptop: check for rfkill hard block at load time

On Thu, Sep 24, 2009 at 9:15 PM, Alan Jenkins
<[email protected]> wrote:
> "I recently (on a flight) I found out that when I boot with the hard-switch
> activated, so turning off all wireless activity on my laptop, the state
> is not correctly announced in /dev/rfkill (reading it with rfkill command,
> or my own gnome applet)...
>
> After turning off and on again the hard-switch the events were right."
>
> We can fix this by querying the firmware at load time and calling
> rfkill_set_hw_state().
>
> Signed-off-by: Alan Jenkins <[email protected]>
> Tested-by: Norbert Preining <[email protected]>
> ---
> ?drivers/platform/x86/sony-laptop.c | ? ?6 ++++++
> ?1 files changed, 6 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
> index dafaa4a..a234a9d 100644
> --- a/drivers/platform/x86/sony-laptop.c
> +++ b/drivers/platform/x86/sony-laptop.c
> @@ -1081,6 +1081,8 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
> ? ? ? ?struct rfkill *rfk;
> ? ? ? ?enum rfkill_type type;
> ? ? ? ?const char *name;
> + ? ? ? int result;
> + ? ? ? bool hwblock;
>
> ? ? ? ?switch (nc_type) {
> ? ? ? ?case SONY_WIFI:
> @@ -1108,6 +1110,10 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
> ? ? ? ?if (!rfk)
> ? ? ? ? ? ? ? ?return -ENOMEM;
>
> + ? ? ? sony_call_snc_handle(0x124, 0x200, &result);

Please define these somewhere, don't use magic numbers.

> + ? ? ? hwblock = !(result & 0x1);
> + ? ? ? rfkill_set_hw_state(rfk, hwblock);
> +
> ? ? ? ?err = rfkill_register(rfk);
> ? ? ? ?if (err) {
> ? ? ? ? ? ? ? ?rfkill_destroy(rfk);
> --
> 1.6.3.2
>
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
> the body of a message to [email protected]
> More majordomo info at ?http://vger.kernel.org/majordomo-info.html
>



--
Vista: [V]iruses, [I]ntruders, [S]pyware, [T]rojans and [A]dware. :-)

2009-09-24 16:19:59

by Norbert Preining

[permalink] [raw]
Subject: Re: rfkill hard state after booting

On Do, 24 Sep 2009, Alan Jenkins wrote:
> + sony_call_snc_handle(0x124, 0x200, &result);
> + hwblock = !(result & 0x1);
> + rfkill_set_hw_state(rfk, hwblock);
> +

I confirm that the (full) patch fixed that problem. Thanks!

Best wishes

Norbert

-------------------------------------------------------------------------------
Dr. Norbert Preining <[email protected]> Vienna University of Technology
Debian Developer <[email protected]> Debian TeX Group
gpg DSA: 0x09C5B094 fp: 14DF 2E6C 0307 BE6D AD76 A9C0 D2BF 4AA3 09C5 B094
-------------------------------------------------------------------------------
GOLANT (adj.)
Blank, sly and faintly embarrassed. Pertaining to the expression seen
on the face of someone who has clearly forgotten your name.
--- Douglas Adams, The Meaning of Liff

2009-09-24 15:06:52

by Alan Jenkins

[permalink] [raw]
Subject: Re: rfkill hard state after booting

Johannes Berg wrote:
> On Thu, 2009-09-24 at 15:02 +0200, Norbert Preining wrote:
>
>
>> I recently (on a flight) I found out that when I boot with the hard-switch
>> activated, so turning off all wireless activity on my laptop, the state
>> is not correctly announced in /dev/rfkill (reading it with rfkill command,
>> or my own gnome applet). All the devices seem to be in normal state but
>> one.
>>
>
> Very strange.
>
>
>> Here some outputs:
>> $ cd /sys/class/rfkill
>> $ ls
>> rfkill0@ rfkill1@ rfkill2@ rfkill3@ rfkill4@ rfkill5@
>> $ cat rfkill?/name
>> sony-wifi
>> sony-bluetooth
>> sony-wwan
>> hso-0
>> hci0
>> phy0
>> $
>>
>> and the three sony-* are the ones for actually turning on/off the devices,
>> but they showed all soft 0 hard 0 at initial startup. Only phy0 (AFAIR)
>> had hard 1.
>>
>
> Makes sense. I mean, that phy0 was hard blocked.
>
>
>> After turning off and on again the hard-switch the events were right.
>>
>
> I can't decide where this bug is. I suspect it's in the sony code.
> Anyone feel responsible for that code?
>
> johannes
>

I think it's pretty clear it's in the sony code. It doesn't call
set_hw_state() during init. I.e. (completely untested):

diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
index dafaa4a..a234a9d 100644
--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -1081,6 +1081,8 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
struct rfkill *rfk;
enum rfkill_type type;
const char *name;
+ int result;
+ bool hwblock;

switch (nc_type) {
case SONY_WIFI:
@@ -1108,6 +1110,10 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
if (!rfk)
return -ENOMEM;

+ sony_call_snc_handle(0x124, 0x200, &result);
+ hwblock = !(result & 0x1);
+ rfkill_set_hw_state(rfk, hwblock);
+
err = rfkill_register(rfk);
if (err) {
rfkill_destroy(rfk);


2009-09-24 20:11:37

by Alan Jenkins

[permalink] [raw]
Subject: Re: [PATCH] sony-laptop: check for rfkill hard block at load time

G?bor Stefanik wrote:
> On Thu, Sep 24, 2009 at 9:15 PM, Alan Jenkins
> <[email protected]> wrote:
>
>> "I recently (on a flight) I found out that when I boot with the hard-switch
>> activated, so turning off all wireless activity on my laptop, the state
>> is not correctly announced in /dev/rfkill (reading it with rfkill command,
>> or my own gnome applet)...
>>
>> After turning off and on again the hard-switch the events were right."
>>
>> We can fix this by querying the firmware at load time and calling
>> rfkill_set_hw_state().
>>
>> Signed-off-by: Alan Jenkins <[email protected]>
>> Tested-by: Norbert Preining <[email protected]>
>> ---
>> drivers/platform/x86/sony-laptop.c | 6 ++++++
>> 1 files changed, 6 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
>> index dafaa4a..a234a9d 100644
>> --- a/drivers/platform/x86/sony-laptop.c
>> +++ b/drivers/platform/x86/sony-laptop.c
>> @@ -1081,6 +1081,8 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
>> struct rfkill *rfk;
>> enum rfkill_type type;
>> const char *name;
>> + int result;
>> + bool hwblock;
>>
>> switch (nc_type) {
>> case SONY_WIFI:
>> @@ -1108,6 +1110,10 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
>> if (!rfk)
>> return -ENOMEM;
>>
>> + sony_call_snc_handle(0x124, 0x200, &result);
>>
>
> Please define these somewhere, don't use magic numbers.
>

The rfkill functions are all together in the file, it's not that bad.
But ok.

There's another bug / missing feature - it doesn't re-read the hard
states on resume from suspend.

I'll submit two more patches then. I won't convert all of the magic
numbers though. This isn't hardware I know anything about, and "magic
numbers" is a good description of some of them -

/* Setup hotkeys */
sony_call_snc_handle(0x0100, 0, &result);
sony_call_snc_handle(0x0101, 0, &result);
sony_call_snc_handle(0x0102, 0x100, &result);
sony_call_snc_handle(0x0127, 0, &result);

Others are already sufficiently obvious, and the extra indirection would
only serve to obscure

/* Enable all events */
acpi_callsetfunc(sony_nc_acpi_handle, "SN02", 0xffff, &result);

2009-09-24 19:27:13

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH] sony-laptop: check for rfkill hard block at load time

On Thu, 2009-09-24 at 20:15 +0100, Alan Jenkins wrote:
> "I recently (on a flight) I found out that when I boot with the hard-switch
> activated, so turning off all wireless activity on my laptop, the state
> is not correctly announced in /dev/rfkill (reading it with rfkill command,
> or my own gnome applet)...
>
> After turning off and on again the hard-switch the events were right."
>
> We can fix this by querying the firmware at load time and calling
> rfkill_set_hw_state().
>
> Signed-off-by: Alan Jenkins <[email protected]>
> Tested-by: Norbert Preining <[email protected]>

Looks good, thanks Alan.

Acked-by: Johannes Berg <[email protected]>

> ---
> drivers/platform/x86/sony-laptop.c | 6 ++++++
> 1 files changed, 6 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
> index dafaa4a..a234a9d 100644
> --- a/drivers/platform/x86/sony-laptop.c
> +++ b/drivers/platform/x86/sony-laptop.c
> @@ -1081,6 +1081,8 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
> struct rfkill *rfk;
> enum rfkill_type type;
> const char *name;
> + int result;
> + bool hwblock;
>
> switch (nc_type) {
> case SONY_WIFI:
> @@ -1108,6 +1110,10 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
> if (!rfk)
> return -ENOMEM;
>
> + sony_call_snc_handle(0x124, 0x200, &result);
> + hwblock = !(result & 0x1);
> + rfkill_set_hw_state(rfk, hwblock);
> +
> err = rfkill_register(rfk);
> if (err) {
> rfkill_destroy(rfk);


Attachments:
signature.asc (801.00 B)
This is a digitally signed message part

2009-09-24 15:05:11

by Johannes Berg

[permalink] [raw]
Subject: Re: rfkill hard state after booting

On Thu, 2009-09-24 at 16:01 +0100, Alan Jenkins wrote:

> I think it's pretty clear it's in the sony code. It doesn't call
> set_hw_state() during init. I.e. (completely untested):

Agree, looking at the code this seems reasonable.

Although maybe it should just call sony_nc_rfkill_update() after
registering all of them?

johannes


Attachments:
signature.asc (801.00 B)
This is a digitally signed message part

2009-09-24 19:15:27

by Alan Jenkins

[permalink] [raw]
Subject: [PATCH] sony-laptop: check for rfkill hard block at load time

"I recently (on a flight) I found out that when I boot with the hard-switch
activated, so turning off all wireless activity on my laptop, the state
is not correctly announced in /dev/rfkill (reading it with rfkill command,
or my own gnome applet)...

After turning off and on again the hard-switch the events were right."

We can fix this by querying the firmware at load time and calling
rfkill_set_hw_state().

Signed-off-by: Alan Jenkins <[email protected]>
Tested-by: Norbert Preining <[email protected]>
---
drivers/platform/x86/sony-laptop.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
index dafaa4a..a234a9d 100644
--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -1081,6 +1081,8 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
struct rfkill *rfk;
enum rfkill_type type;
const char *name;
+ int result;
+ bool hwblock;

switch (nc_type) {
case SONY_WIFI:
@@ -1108,6 +1110,10 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
if (!rfk)
return -ENOMEM;

+ sony_call_snc_handle(0x124, 0x200, &result);
+ hwblock = !(result & 0x1);
+ rfkill_set_hw_state(rfk, hwblock);
+
err = rfkill_register(rfk);
if (err) {
rfkill_destroy(rfk);
--
1.6.3.2




2009-09-24 23:04:16

by Mattia Dongili

[permalink] [raw]
Subject: Re: [PATCH] sony-laptop: check for rfkill hard block at load time

On Thu, Sep 24, 2009 at 09:11:36PM +0100, Alan Jenkins wrote:
> G?bor Stefanik wrote:
> > On Thu, Sep 24, 2009 at 9:15 PM, Alan Jenkins
> > <[email protected]> wrote:
> >
...
> >> @@ -1108,6 +1110,10 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
> >> if (!rfk)
> >> return -ENOMEM;
> >>
> >> + sony_call_snc_handle(0x124, 0x200, &result);
> >>
> >
> > Please define these somewhere, don't use magic numbers.
> >
>
> The rfkill functions are all together in the file, it's not that bad.
> But ok.
>
> There's another bug / missing feature - it doesn't re-read the hard
> states on resume from suspend.
>
> I'll submit two more patches then. I won't convert all of the magic
> numbers though. This isn't hardware I know anything about, and "magic
> numbers" is a good description of some of them -

right and the whole purpose of them is to hit specific code paths
in the DSDT tables. Not sure we would benefit that much from having
names for them.

--
mattia
:wq!

2009-09-25 09:13:46

by Alan Jenkins

[permalink] [raw]
Subject: Re: [PATCH] sony-laptop: check for rfkill hard block at load time

Mattia Dongili wrote:
> On Thu, Sep 24, 2009 at 08:15:24PM +0100, Alan Jenkins wrote:
>
>> "I recently (on a flight) I found out that when I boot with the hard-switch
>> activated, so turning off all wireless activity on my laptop, the state
>> is not correctly announced in /dev/rfkill (reading it with rfkill command,
>> or my own gnome applet)...
>>
>> After turning off and on again the hard-switch the events were right."
>>
>> We can fix this by querying the firmware at load time and calling
>> rfkill_set_hw_state().
>>
>
> Is it worth trying to get this into a stable release?
>

Sure. It seems to fit, and all we have to do is add a CC to the patch

>> Signed-off-by: Alan Jenkins <[email protected]>
>> Tested-by: Norbert Preining <[email protected]>
>>
>
> Acked-by: Mattia Dongili <[email protected]>
>

CC: [email protected]

>
>> ---
>> drivers/platform/x86/sony-laptop.c | 6 ++++++
>> 1 files changed, 6 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
>> index dafaa4a..a234a9d 100644
>> --- a/drivers/platform/x86/sony-laptop.c
>> +++ b/drivers/platform/x86/sony-laptop.c
>> @@ -1081,6 +1081,8 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
>> struct rfkill *rfk;
>> enum rfkill_type type;
>> const char *name;
>> + int result;
>> + bool hwblock;
>>
>> switch (nc_type) {
>> case SONY_WIFI:
>> @@ -1108,6 +1110,10 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
>> if (!rfk)
>> return -ENOMEM;
>>
>> + sony_call_snc_handle(0x124, 0x200, &result);
>> + hwblock = !(result & 0x1);
>> + rfkill_set_hw_state(rfk, hwblock);
>> +
>> err = rfkill_register(rfk);
>> if (err) {
>> rfkill_destroy(rfk);
>> --
>> 1.6.3.2
>>
>>
>>
>>


2009-09-24 14:07:33

by Johannes Berg

[permalink] [raw]
Subject: Re: rfkill hard state after booting

On Thu, 2009-09-24 at 15:02 +0200, Norbert Preining wrote:

> I recently (on a flight) I found out that when I boot with the hard-switch
> activated, so turning off all wireless activity on my laptop, the state
> is not correctly announced in /dev/rfkill (reading it with rfkill command,
> or my own gnome applet). All the devices seem to be in normal state but
> one.

Very strange.

> Here some outputs:
> $ cd /sys/class/rfkill
> $ ls
> rfkill0@ rfkill1@ rfkill2@ rfkill3@ rfkill4@ rfkill5@
> $ cat rfkill?/name
> sony-wifi
> sony-bluetooth
> sony-wwan
> hso-0
> hci0
> phy0
> $
>
> and the three sony-* are the ones for actually turning on/off the devices,
> but they showed all soft 0 hard 0 at initial startup. Only phy0 (AFAIR)
> had hard 1.

Makes sense. I mean, that phy0 was hard blocked.

> After turning off and on again the hard-switch the events were right.

I can't decide where this bug is. I suspect it's in the sony code.
Anyone feel responsible for that code?

johannes


Attachments:
signature.asc (801.00 B)
This is a digitally signed message part