rfkill: rewrite
Subsystems (16)
Johannes Berg
maintainerRFC 1/1 rfkill: rewrite
This patch completely rewrites the rfkill core to address the following deficiencies:
* all rfkill drivers need to implement polling where necessary rather than having one central implementation
* updating the rfkill state cannot be done from any context, forcing drivers to use schedule_work and requiring lots of code
* rfkill drivers need to keep track of soft/hard blocked internally -- the core should do this
* the rfkill API has many unexpected quirks, for example being asymmetric wrt. alloc/free and register/unregister
* rfkill can call back into a driver from within a function the driver called -- this is prone to deadlocks and generally should be avoided
* rfkill-input pointlessly is a separate module
* drivers need to #ifdef rfkill functions (unless they want to depend on or select RFKILL) -- rfkill should provide inlines that do nothing if it isn't compiled in
* the rfkill structure, despite containing almost only internal variables, is not opaque -- and drivers need to initialise it correctly (lots of sanity checking code required) -- instead force drivers to pass the right variables to rfkill_alloc()
* the documentation is hard to read because it always assumes the reader is completely clueless and contains way to many CAPS
* the rfkill code needlessly uses a lot of locks and atomic operations in locked sections
---
RFC only because I haven't fixed all drivers yet, still missing are toshiba, thinkpad, wimax and tosa.
Let the flames begin! (or if you like it feel free to chime in too)
Documentation/rfkill.txt | 637 +++------------------- MAINTAINERS | 4 drivers/net/wireless/ath9k/ath9k.h | 7 drivers/net/wireless/ath9k/main.c | 115 ---- drivers/net/wireless/ath9k/pci.c | 15 drivers/net/wireless/b43/Kconfig | 2 drivers/net/wireless/b43/leds.c | 2 drivers/net/wireless/b43/main.c | 4 drivers/net/wireless/b43/phy_a.c | 4 drivers/net/wireless/b43/phy_common.c | 17 drivers/net/wireless/b43/phy_common.h | 4 drivers/net/wireless/b43/phy_g.c | 4 drivers/net/wireless/b43/phy_lp.c | 2 drivers/net/wireless/b43/phy_n.c | 2 drivers/net/wireless/b43/rfkill.c | 60 -- drivers/net/wireless/b43/rfkill.h | 2 drivers/net/wireless/b43legacy/Kconfig | 2 drivers/net/wireless/b43legacy/leds.c | 3 drivers/net/wireless/b43legacy/rfkill.c | 55 - drivers/net/wireless/b43legacy/rfkill.h | 2 drivers/net/wireless/iwlwifi/Kconfig | 5 drivers/net/wireless/iwlwifi/iwl-rfkill.c | 70 -- drivers/platform/x86/Kconfig | 6 drivers/platform/x86/acer-wmi.c | 53 - drivers/platform/x86/dell-laptop.c | 103 +-- drivers/platform/x86/eeepc-laptop.c | 91 --- drivers/platform/x86/hp-wmi.c | 104 +-- drivers/platform/x86/toshiba_acpi.c | 28 include/linux/Kbuild | 1 include/linux/rfkill.h | 290 +++++++--- net/rfkill/Kconfig | 6 net/rfkill/Makefile | 6 net/rfkill/core.c | 754 ++++++++++++++++++++++++++ net/rfkill/input.c | 384 +++++++++++++ net/rfkill/rfkill-input.c | 392 ------------- net/rfkill/rfkill-input.h | 21 net/rfkill/rfkill.c | 843 ------------------------------ net/rfkill/rfkill.h | 27 38 files changed, 1763 insertions(+), 2364 deletions(-)
include/linux/rfkill.h +220 -70
@@ -4,6 +4,7 @@/* * Copyright (C) 2006 - 2007 Ivo van Doorn * Copyright (C) 2007 Dmitry Torokhov +* Copyright 2009 Johannes Berg <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -21,6 +22,24 @@* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* define userspace visible states */ +#define RFKILL_STATE_SOFT_BLOCKED 0 +#define RFKILL_STATE_UNBLOCKED 1 +#define RFKILL_STATE_HARD_BLOCKED 2 + +/* and that's all userspace gets */ +#ifdef __KERNEL__ +/* don't allow anyone to use these in the kernel */ +enum rfkill_user_states { +RFKILL_USER_STATE_SOFT_BLOCKED =RFKILL_STATE_SOFT_BLOCKED , +RFKILL_USER_STATE_UNBLOCKED =RFKILL_STATE_UNBLOCKED , +RFKILL_USER_STATE_HARD_BLOCKED =RFKILL_STATE_HARD_BLOCKED , +}; +#undef RFKILL_STATE_SOFT_BLOCKED +#undef RFKILL_STATE_UNBLOCKED +#undef RFKILL_STATE_HARD_BLOCKED +#include <linux/types.h> #include <linux/kernel.h> #include <linux/list.h>
@@ -30,11 +49,13 @@/** * enum rfkill_type - type of rfkill switch. -* RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. -* RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. -* RFKILL_TYPE_UWB: switch is on a ultra wideband device. -* RFKILL_TYPE_WIMAX: switch is on a WiMAX device. -* RFKILL_TYPE_WWAN: switch is on a wireless WAN device. +* +* @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. +* @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. +* @RFKILL_TYPE_UWB: switch is on a ultra wideband device. +* @RFKILL_TYPE_WIMAX: switch is on a WiMAX device. +* @RFKILL_TYPE_WWAN: switch is on a wireless WAN device. +* @NUM_RFKILL_TYPES: number of defined rfkill types */ enum rfkill_type {RFKILL_TYPE_WLAN ,
@@ -42,97 +63,226 @@ enum rfkill_type {RFKILL_TYPE_UWB ,RFKILL_TYPE_WIMAX ,RFKILL_TYPE_WWAN , - RFKILL_TYPE_MAX, + NUM_RFKILL_TYPES, }; -enum rfkill_state { -RFKILL_STATE_SOFT_BLOCKED =0 ,/* Radio output blocked */ -RFKILL_STATE_UNBLOCKED =1 ,/* Radio output allowed */ -RFKILL_STATE_HARD_BLOCKED =2 ,/* Output blocked, non-overrideable */ -RFKILL_STATE_MAX ,/* marker for last valid state */ -}; +#define RFKILL_BLOCK_HW_BIT 0 +#define RFKILL_BLOCK_SW_BIT 1/** -* struct rfkill - rfkill control structure. -* @name: Name of the switch. -* @type: Radio type which the button controls, the value stored -* here should be a value from enum rfkill_type. -* @state: State of the switch, "UNBLOCKED" means radio can operate. -* @mutex: Guards switch state transitions. It serializes callbacks -* and also protects the state. -* @data: Pointer to the RF button drivers private data which will be -* passed along when toggling radio state. -* @toggle_radio(): Mandatory handler to control state of the radio. -* only RFKILL_STATE_SOFT_BLOCKED and RFKILL_STATE_UNBLOCKED are -* valid parameters. -* @get_state(): handler to read current radio state from hardware, -* may be called from atomic context, should return 0 on success. -* Either this handler OR judicious use of rfkill_force_state() is -* MANDATORY for any driver capable of RFKILL_STATE_HARD_BLOCKED. -* @led_trigger: A LED trigger for this button's LED. -* @dev: Device structure integrating the switch into device tree. -* @node: Used to place switch into list of all switches known to the -* the system. -* -* This structure represents a RF switch located on a network device. -*/ -struct rfkill { -const char *name; -enum rfkill_type type; - -/* the mutex serializes callbacks and also protects -* the state */ -struct mutex mutex; -enum rfkill_state state; -void *data; -int (*toggle_radio)(void *data,enum rfkill_state state); -int (*get_state)(void *data,enum rfkill_state *state); - -#ifdef CONFIG_RFKILL_LEDS -struct led_trigger led_trigger; +* struct rfkill_ops - rfkill driver methods +* +* @poll_hw_block: poll the rfkill hardware block state (return true +* for blocked) -- only assign this method when you cannot +* do without polling +* @query_state: query the rfkill hardware block state (return true +* for blocked) -- assign this method if software events might +* cause hardware state changes +* @set_block: turn the transmitter on (blocked == false) or off +* (blocked == true) -- this is called only while the transmitter +* is not hard-blocked. This must be assigned. +*/ +struct rfkill_ops { +#if defined(CONFIG_RFKILL ) || defined(CONFIG_RFKILL_MODULE ) +bool (*poll_hw_block)(void *data); +bool (*query_state)(void *data); +void (*set_block)(void *data,bool blocked);#endif - -struct device dev; -struct list_head node; -enum rfkill_state state_for_resume; }; -#define to_rfkill (d) container_of(d, struct rfkill, dev) -struct rfkill *__must_check rfkill_allocate (struct device *parent, -enum rfkill_type type); -void rfkill_free (struct rfkill *rfkill); +/* this is opaque */ +struct rfkill ; + +#if defined(CONFIG_RFKILL ) || defined(CONFIG_RFKILL_MODULE ) +/** +* rfkill_alloc - allocate rfkill structure +* @name: name of the struct -- the string is not copied internally +* @parent: device that has rf switch on it +* @type: type of the switch (RFKILL_TYPE_*) +* @ops: rfkill methods +* @ops_data: data passed to each method +* +* This function should be called by the transmitter driver to allocate an +* rfkill structure. +*/ +struct rfkill *__must_check rfkill_alloc (const char *name, +struct device *parent, +const enum rfkill_type type, +const struct rfkill_ops *ops, +void *ops_data); + +/** +* rfkill_register - Register a rfkill structure. +* @rfkill: rfkill structure to be registered +* +* This function should be called by the network driver when the rfkill +* structure needs to be registered. Before calling this function the +* driver needs to be ready to service method calls from rfkill. +*/ int __must_check rfkill_register (struct rfkill *rfkill); + +/** +* rfkill_pause_polling(struct rfkill *rfkill) +* +* Pause polling -- say transmitter is off for other reasons. +* NOTE: not necessary for suspend/resume -- in that case the +* core stops polling anyway +*/ +void rfkill_pause_polling (struct rfkill *rfkill); + +/** +* rfkill_resume_polling(struct rfkill *rfkill) +* +* Pause polling -- say transmitter is off for other reasons. +* NOTE: not necessary for suspend/resume -- in that case the +* core stops polling anyway +*/ +void rfkill_resume_polling (struct rfkill *rfkill); + + +/** +* rfkill_unregister - Unregister a rfkill structure. +* @rfkill: rfkill structure to be unregistered +* +* This function should be called by the network driver during device +* teardown to destroy rfkill structure. Until it returns, the driver +* needs to be able to service method calls. +*/ void rfkill_unregister (struct rfkill *rfkill); -int rfkill_force_state (struct rfkill *rfkill,enum rfkill_state state); -int rfkill_set_default (enum rfkill_type type,enum rfkill_state state); +/** +* rfkill_destroy - free rfkill structure +* @rfkill: rfkill structure to be destroyed +* +* Destroys the rfkill structure. +*/ +void rfkill_destroy (struct rfkill *rfkill);/** -* rfkill_state_complement - return complementar state -* @state: state to return the complement of +* rfkill_set_hw_state - Set the internal rfkill hardware block state +* @rfkill: pointer to the rfkill class to modify. +* @state: the current hardware block state to set +* +* rfkill drivers that get events when the hard-blocked state changes +* use this function to notify the rfkill core (and through that also +* userspace) of the current state -- they should also use this after +* resume if the state could have changed. * -* Returns RFKILL_STATE_SOFT_BLOCKED if @state is RFKILL_STATE_UNBLOCKED, -* returns RFKILL_STATE_UNBLOCKED otherwise. +* You need not (but may) call this function if poll_state is assigned. +* +* This function can be called in any context. +* +* The function returns the combined block state (true if transmitter +* should be blocked) so that drivers need not keep track of the soft +* block state -- which they cannot anyway because while hard-blocked +* they do not receive soft-block events. */ -static inline enum rfkill_state rfkill_state_complement (enum rfkill_state state) +bool rfkill_set_hw_state (struct rfkill *rfkill,bool blocked); + +/** +* rfkill_set_sw_state - Set the internal rfkill software block state +* @rfkill: pointer to the rfkill class to modify. +* @state: the current software block state to set +* +* rfkill drivers that get events when the soft-blocked state changes +* (yes, some platforms directly act on input but allow changing again) +* use this function to notify the rfkill core (and through that also +* userspace) of the current state -- they should also use this after +* resume if the state could have changed. +* +* This function can be called in any context. +* +* The function returns the combined block state (true if transmitter +* should be blocked). +*/ +bool rfkill_set_sw_state (struct rfkill *rfkill,bool blocked); + +/** +* rfkill_set_sw_default - set initial value for a switch type +* @type - the type of switch to set the default state of +* @blocked - the new default state for that group of switches +* +* Sets the initial state rfkill should use for a given type. +* +* This function is meant to be used by platform drivers for platforms +* that can save switch state across power down/reboot. +* +* The default state for each switch type can be changed exactly once. +* After a switch of that type is registered, the default state cannot +* be changed anymore. This guards against multiple drivers it the +* same platform trying to set the initial switch default state, which +* is not allowed. +* +* Returns -EPERM if the state has already been set once or is in use, +* so drivers likely want to either ignore or at most printk(KERN_NOTICE) +* if this function returns -EPERM. +* +* Returns 0 if the new default state was set, or an error if it +* could not be set. +*/ +int rfkill_set_sw_default (enum rfkill_type type,bool blocked); +#else /* !RFKILL */ +static inline struct rfkill *__must_check +rfkill_alloc (const char *name, +struct device *parent, +const enum rfkill_type type, +const struct rfkill_ops *ops, +void *ops_data) +{ +return ERR_PTR (-ENODEV ); +} + +static inline int __must_check rfkill_register (struct rfkill *rfkill) +{ +if (rfkill ==ERR_PTR (-ENODEV )) +return 0 ; +return -EINVAL ; +} + +static inline void rfkill_pause_polling (struct rfkill *rfkill) +{ +} + +static inline void rfkill_resume_polling (struct rfkill *rfkill) { -return (state ==RFKILL_STATE_UNBLOCKED ) ? -RFKILL_STATE_SOFT_BLOCKED :RFKILL_STATE_UNBLOCKED ; } +static inline void rfkill_unregister (struct rfkill *rfkill) +{ +} + +static inline void rfkill_destroy (struct rfkill *rfkill) +{ +} + +static inline bool rfkill_set_hw_state (struct rfkill *rfkill,bool blocked) +{ +return blocked; +} + +static inline bool rfkill_set_sw_state (struct rfkill *rfkill,bool blocked) +{ +return blocked; +} +#endif /* RFKILL || RFKILL_MODULE */ + + +/** * rfkill_get_led_name - Get the LED trigger name for the button's LED. * This function might return a NULL pointer if registering of the * LED trigger failed. * Use this as "default_trigger" for the LED. */ -static inline char *rfkill_get_led_name (struct rfkill *rfkill) -{#ifdef CONFIG_RFKILL_LEDS -return (char *)(rfkill->led_trigger.name); +const char *rfkill_get_led_name (struct rfkill *rfkill);#else +static inline const char *rfkill_get_led_name (struct rfkill *rfkill) +{return NULL ; -#endif } +#endif + +#endif /* __KERNEL__ */ #endif /* RFKILL_H */
drivers/net/wireless/ath9k/main.c +28 -87
168 lines not on this page · raw message
drivers/platform/x86/eeepc-laptop.c +22 -69
128 lines not on this page · raw message
net/rfkill/rfkill.c deleted +0 -843
843 lines not on this page · raw message
net/rfkill/rfkill-input.h deleted +0 -21
@@ -1,21 +0,0 @@ -/* -* Copyright (C) 2007 Ivo van Doorn -*/ - -/* -* This program is free software; you can redistribute it and/or modify it -* under the terms of the GNU General Public License version 2 as published -* by the Free Software Foundation. -*/ - -#ifndef __RFKILL_INPUT_H -#define __RFKILL_INPUT_H - -void rfkill_switch_all (enum rfkill_type type,enum rfkill_state state); -void rfkill_epo (void ); -void rfkill_restore_states (void ); -void rfkill_remove_epo_lock (void ); -bool rfkill_is_epo_lock_active (void ); -enum rfkill_state rfkill_get_global_state (const enum rfkill_type type); - -#endif /* __RFKILL_INPUT_H */
net/rfkill/rfkill-input.c deleted +0 -392
392 lines not on this page · raw message
drivers/net/wireless/b43/main.c +2 -2
@@ -3492,7 +3492,7 @@ static int b43_op_config(struct ieee8021if (!!conf->radio_enabled != phy->radio_on) {if (conf->radio_enabled) { -b43_software_rfkill (dev,RFKILL_STATE_UNBLOCKED ); +b43_software_rfkill (dev, false);b43info (dev->wl,"Radio turned on by software\n" );if (!dev->radio_hw_enable) { b43info(dev->wl, "The hardware RF-kill button "
@@ -3500,7 +3500,7 @@ static int b43_op_config(struct ieee8021 "Press the button to turn it on.\n"); } }else { -b43_software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); +b43_software_rfkill (dev, true);b43info (dev->wl,"Radio turned off by software\n" ); } }
drivers/net/wireless/b43/phy_a.c +2 -2
@@ -480,11 +480,11 @@ static bool b43_aphy_op_supports_hwpctl( }static void b43_aphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {struct b43_phy *phy = &dev->phy; -if (state ==RFKILL_STATE_UNBLOCKED ) { +if (!blocked) {if (phy->radio_on)return ;b43_radio_write16 (dev,0x0004 ,0x00C0 );
drivers/net/wireless/b43/phy_common.c +6 -11
@@ -84,7 +84,7 @@ int b43_phy_init(struct b43_wldev *dev) phy->channel = ops->get_default_chan (dev); - ops->software_rfkill (dev,RFKILL_STATE_UNBLOCKED ); + ops->software_rfkill (dev, false); err = ops->init (dev);if (err) {b43err (dev->wl,"PHY init failed\n" );
@@ -104,7 +104,7 @@ err_phy_exit:if (ops->exit) ops->exit (dev); err_block_rf: - ops->software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); + ops->software_rfkill (dev, true);return err; }
@@ -113,7 +113,7 @@ void b43_phy_exit(struct b43_wldev *dev) {const struct b43_phy_operations *ops = dev->phy.ops; - ops->software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); + ops->software_rfkill (dev, true);if (ops->exit) ops->exit (dev); }
@@ -287,18 +287,13 @@ err_restore_cookie:return err; } -void b43_software_rfkill (struct b43_wldev *dev,enum rfkill_state state) +void b43_software_rfkill (struct b43_wldev *dev,bool blocked) {struct b43_phy *phy = &dev->phy; -if (state ==RFKILL_STATE_HARD_BLOCKED ) { -/* We cannot hardware-block the device */ - state =RFKILL_STATE_SOFT_BLOCKED ; - } -b43_mac_suspend (dev); - phy->ops->software_rfkill (dev, state); - phy->radio_on = (state ==RFKILL_STATE_UNBLOCKED ); + phy->ops->software_rfkill (dev, blocked); + phy->radio_on = !blocked;b43_mac_enable (dev); }
drivers/net/wireless/b43/phy_common.h +2 -2
@@ -159,7 +159,7 @@ struct b43_phy_operations {/* Radio */ bool (*supports_hwpctl)(struct b43_wldev *dev); -void (*software_rfkill)(struct b43_wldev *dev,enum rfkill_state state); +void (*software_rfkill)(struct b43_wldev *dev,bool blocked);void (*switch_analog)(struct b43_wldev *dev,bool on);int (*switch_channel)(struct b43_wldev *dev,unsigned int new_channel);unsigned int (*get_default_chan)(struct b43_wldev *dev);
@@ -362,7 +362,7 @@ int b43_switch_channel(struct b43_wldev/** * b43_software_rfkill - Turn the radio ON or OFF in software. */ -void b43_software_rfkill (struct b43_wldev *dev,enum rfkill_state state); +void b43_software_rfkill (struct b43_wldev *dev,bool blocked);/** * b43_phy_txpower_check - Check TX power output.
drivers/net/wireless/b43/phy_g.c +2 -2
@@ -2592,7 +2592,7 @@ static bool b43_gphy_op_supports_hwpctl( }static void b43_gphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {struct b43_phy *phy = &dev->phy;struct b43_phy_g *gphy = phy->g;
@@ -2600,7 +2600,7 @@ static void b43_gphy_op_software_rfkill(might_sleep (); -if (state ==RFKILL_STATE_UNBLOCKED ) { +if (!blocked) {/* Turn radio ON */ if (phy->radio_on)return ;
drivers/net/wireless/b43/phy_n.c +1 -1
@@ -579,7 +579,7 @@ static void b43_nphy_op_radio_write(stru }static void b43_nphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {//TODO }
drivers/net/wireless/b43/rfkill.c +25 -35
107 lines not on this page · raw message
drivers/net/wireless/b43legacy/rfkill.c +23 -32
107 lines not on this page · raw message
drivers/net/wireless/iwlwifi/iwl-rfkill.c +28 -42
124 lines not on this page · raw message
Documentation/rfkill.txt +98 -539
656 lines not on this page · raw message
net/rfkill/Kconfig +2 -4
Lines of this file are not shown. View the raw message.
net/rfkill/Makefile +4 -2
Lines of this file are not shown. View the raw message.
net/rfkill/core.c new file +754 -0
754 lines not on this page · raw message
net/rfkill/input.c new file +384 -0
384 lines not on this page · raw message
net/rfkill/rfkill.h new file +27 -0
Lines of this file are not shown. View the raw message.
MAINTAINERS +2 -2
Lines of this file are not shown. View the raw message.
include/linux/Kbuild +1 -0
Lines of this file are not shown. View the raw message.
drivers/net/wireless/ath9k/ath9k.h +1 -6
Lines of this file are not shown. View the raw message.
drivers/net/wireless/ath9k/pci.c +0 -15
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/Kconfig +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/rfkill.h +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/Kconfig +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/leds.c +2 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/rfkill.h +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/leds.c +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/iwlwifi/Kconfig +2 -3
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/phy_lp.c +1 -1
Lines of this file are not shown. View the raw message.
drivers/platform/x86/Kconfig +0 -6
Lines of this file are not shown. View the raw message.
drivers/platform/x86/acer-wmi.c +23 -30
53 lines not on this page · raw message
drivers/platform/x86/dell-laptop.c +33 -70
103 lines not on this page · raw message
drivers/platform/x86/hp-wmi.c +53 -51
104 lines not on this page · raw message
drivers/platform/x86/toshiba_acpi.c +10 -18
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Quoted 37 lines · Johannes Berg
This patch completely rewrites the rfkill core to address the following deficiencies:
* all rfkill drivers need to implement polling where necessary rather than having one central implementation
* updating the rfkill state cannot be done from any context, forcing drivers to use
schedule_workand requiring lots of code* rfkill drivers need to keep track of soft/hard blocked internally -- the core should do this
* the rfkill API has many unexpected quirks, for example being asymmetric wrt. alloc/free and register/unregister
* rfkill can call back into a driver from within a function the driver called -- this is prone to deadlocks and generally should be avoided
* rfkill-input pointlessly is a separate module
* drivers need to #ifdef rfkill functions (unless they want to depend on or select RFKILL) -- rfkill should provide inlines that do nothing if it isn't compiled in
* the rfkill structure, despite containing almost only internal variables, is not opaque -- and drivers need to initialise it correctly (lots of sanity checking code required) -- instead force drivers to pass the right variables to
rfkill_alloc()* the documentation is hard to read because it always assumes the reader is completely clueless and contains way to many CAPS
* the rfkill code needlessly uses a lot of locks and atomic operations in locked sections
Quoted 6 lines
Signed-off-by Johannes Berg <[email protected]>---
RFC only because I haven't fixed all drivers yet, still missing are toshiba, thinkpad, wimax and tosa.Let the flames begin! (or if you like it feel free to chime in too)
Just for the record, as long as you (or somebody else) takes over maintainership over rfkill after these changes, I have no objections against the changes. Luckily you already updated the Maintainers entry, so I'm happy. :)
I know rfkill was poorly designed and I simply lacked the time (and perhaps some interest as well) to continue with it. The changes you propose sound reasonable so I hope it will turn rfkill really into something which it was supposed to be from the start.
Ivo
Johannes Berg
maintainerQuoted 5 lines · Johannes Berg
This patch completely rewrites the rfkill core to address the following deficiencies:
* all rfkill drivers need to implement polling where necessary rather than having one central implementation
One thing I was wondering about -- should we just implement polling via a single work struct that iterates all those rfkill drivers that need polling? I've given them each an own right now, but that seems unnecessary.
johannes
Johannes Berg
maintainerTODO:
* toshiba_acpi.c
-> need help, seems to abuse input polldev and report it as both
input and rfkill block state? at very least need info about what hw actually does
* thinkpad_acpi.c
-> need help, convoluted code I don't understand at all, looks like
another candidate for rewriting
* wimax
-> need help, seems to report rfkill states to input device?
don't understand
* b43/b43legacy
-> compiles now, but should remove input polldev and use hw block
polling -- later
* tosa - done now in new patch, but not even compile-tested
(http://johannes.sipsolutions.net/patches/kernel/all/LATEST/NNN-rfkill-rewrite.patch)
* test
-> need help, I don't have any hardware with rfkill buttons, will see
if I can come up with a uinput rfkill "button"
johannes
Quoted 11 lines · On Monday 30 March 2009 11:06:27 Johannes Berg wrote:
Quoted 5 lines · Johannes Berg
This patch completely rewrites the rfkill core to address the following deficiencies:
* all rfkill drivers need to implement polling where necessary rather than having one central implementation
One thing I was wondering about -- should we just implement polling via a single work struct that iterates all those rfkill drivers that need polling? I've given them each an own right now, but that seems unnecessary.
If it doesn't add new locking problems (global locks, etc...) that'd be OK.
Signature · 1 line
Greetings, Michael.
Johannes Berg
maintainerQuoted 8 lines · Michael Buesch
Quoted 7 lines · On Monday 30 March 2009 11:06:27 Johannes Berg wrote:
Quoted 5 lines · Johannes Berg
This patch completely rewrites the rfkill core to address the following deficiencies:
* all rfkill drivers need to implement polling where necessary rather than having one central implementation
Quoted 6 lines
Quoted 4 lines
One thing I was wondering about -- should we just implement polling via a single work struct that iterates all those rfkill drivers that need polling? I've given them each an own right now, but that seems unnecessary.
If it doesn't add new locking problems (global locks, etc...) that'd be OK.
Hm, indeed, it probably would -- rfkill_register needs a global lock while being called from the driver, and the polling would need the same lock while calling into the driver.
johannes
Quoted 6 lines · Johannes Berg
TODO:
*
toshiba_acpi.c
-> need help, seems to abuse input polldev and report it as both
input and rfkill block state? at very least need info about what hw actually does
I'm looking at reworking some of this today.
Signature · 1 line
Matthew Garrett | [email protected]
Johannes Berg
maintainerQuoted 10 lines · Johannes Berg
Quoted 6 lines
Quoted 4 lines
One thing I was wondering about -- should we just implement polling via a single work struct that iterates all those rfkill drivers that need polling? I've given them each an own right now, but that seems unnecessary.
If it doesn't add new locking problems (global locks, etc...) that'd be OK.
Hm, indeed, it probably would --
rfkill_registerneeds a global lock while being called from the driver, and the polling would need the same lock while calling into the driver.
We can work around that by cancelling the work whenever we want to modify the list -- that way the work doesn't need to take any locks. Not sure it's worth it though, that makes the code harder to follow.
johannes
Quoted 8 lines · Ivo van Doorn
Just for the record, as long as you (or somebody else) takes over maintainership over rfkill after these changes, I have no objections against the changes. Luckily you already updated the Maintainers entry, so I'm happy. :)
I know rfkill was poorly designed and I simply lacked the time (and perhaps some interest as well) to continue with it. The changes you propose sound reasonable so I hope it will turn rfkill really into something which it was supposed to be from the start.
Agreed. I never wanted to do so much work on rfkill, either... I just wanted something I could use in thinkpad-acpi, but that proved to be a lot of work, as once you start, you want to finish it.
I will go over the new proposed rfkill to check if it is in a state that is comfortable for drivers like thinkpad-acpi to use, and offer comments about it.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 3 lines · Johannes Berg
*
thinkpad_acpi.c
-> need help, convoluted code I don't understand at all, looks like
another candidate for rewriting
Heh. I will take care of it, obviously. As for rewriting, well, a cleanup
is in the queue.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Johannes Berg
maintainerQuoted 7 lines · Henrique de Moraes Holschuh
Quoted 3 lines · Johannes Berg
*
thinkpad_acpi.c
-> need help, convoluted code I don't understand at all, looks like
another candidate for rewritingHeh. I will take care of it, obviously. As for rewriting, well, a cleanup
is in the queue.
Heh, thanks. I appreciate any help even if the golden rule still is that those who change the API get to fix users :)
Thinkpad in particular confuses me due to the way it uses force_state and input. Is it like Dell in that the button press causes a soft block?
johannes
Hi Johannes!
Quoted 6 lines · Johannes Berg
Quoted 5 lines · Henrique de Moraes Holschuh
Quoted 3 lines · Johannes Berg
*
thinkpad_acpi.c
-> need help, convoluted code I don't understand at all, looks like
another candidate for rewriting
Quoted 8 lines
Quoted 2 lines
Heh. I will take care of it, obviously. As for rewriting, well, a cleanup
is in the queue.Heh, thanks. I appreciate any help even if the golden rule still is that those who change the API get to fix users :)
Thinkpad in particular confuses me due to the way it uses
force_stateand input. Is it like Dell in that the button press causes a soft block?
There are three independent rfkill controllers in a thinkpad: UWB, WWAN, bluetooth. They're hierarchically slaved to the master radio-kill switch in the standard EPO way: if the master switch is active, all rfkill controllers are forced active (all radios are killed). If the master switch is not active, each rfkill controller can be independently set to kill or not their respective radio.
When the user moves the phisical radio-kill switch, the thinkpad embedded controller hard-kills every USB-attached radio (as in: cut power and kick off-bus), raises the hardware rfkill line on the mini-PCI/mini-PCIe slots (which will hard-block Intel wireless devices. I think the Atheros ones
ignore it). And sends us an event over ACPI (HKEY event 7000).
That event is used by the driver as a hint to check the state of all rfkill controllers, and sync the core (thus, it causes calls to rfkill_force_state()). It is also sent to userspace as an input event (so that rfkill-input can go and block other radios, such as USB dongles, etc).
It is also possible to request that hard-kill in the BIOS: the thinkpad boots with all radios rfkilled (the BIOS tells the EC to radio-kill everything and to keep them killed), and there is absolutely _nothing_ one can do to unblock them, until a reboot and BIOS reconfig is done.
Anyway, thinkpad-acpi is a _hybrid_ driver as far as rfkill is concerned. It has rfkill controllers, but it has an input device side too.
There is some highly paranoid logic in thinkpad-acpi that basically enforces the radio-kill switch even if the firmware goes rogue on us and decides not to do it. This is just to guarantee that all thinkpads will behave the same way, if there is one or two models out there with a weird firmware. You can ignore it when trying to understand the information flow in the driver, if I ripped it out, most (all?) thinkpads would behave just the same.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 4 lines · Johannes Berg
* wimax
-> need help, seems to report rfkill states to input device?
don't understand
Not really.
What it does is if the device exposes a hw rfkill key, export that key as an input device, as well as using it to report the state change.
So there are three main entry points:
wimax_report_rfkill_hw() -- device driver report to stack
device reports a change in the hw rfkill key; switch the radio to whichever state AND report a key event through the input layer
wimax_report_rfkill_sw() -- device driver report to stack
device reports a change in the sw rfkill state; this is needed for cases where the radio is shared amongst different technologies (wifi and wimax, for example, in the case of the 5150). When you turn on Wifi, WiMAX switches off (and vice versa).
As well, if from SW you flip it off, this gets called back but does nothing as the state is updated already.
wimax_rfkill / wimax_rfkill_toggle_radio -- user interface
The user wants to flip the SW switch on/off
Signature · 1 line
Inaky
Johannes Berg
maintainer[remove memebeam.org from CC, it doesn't have an MX]
Hi Henrique,
Quoted 6 lines
There are three independent rfkill controllers in a thinkpad: UWB, WWAN, bluetooth. They're hierarchically slaved to the master radio-kill switch in the standard EPO way: if the master switch is active, all rfkill controllers are forced active (all radios are killed). If the master switch is not active, each rfkill controller can be independently set to kill or not their respective radio.
[snip]
Thanks for the explanation. I guess that kinda makes sense. One thing I'm entirely sure about -- I had removed the sw default state setter -- I guess this code still requires then? I was thinking the sw default state should be set for the devices it applies to, but it seems that if the master rfkill switch is set to "transmitter off" then one needs to set the default state (for all USB transmitters etc) to off, correct?
johannes
Johannes Berg
maintainerQuoted 12 lines · Inaky Perez-Gonzalez
Quoted 4 lines · Johannes Berg
* wimax
-> need help, seems to report rfkill states to input device?
don't understandNot really.
What it does is if the device exposes a hw rfkill key, export that key as an input device, as well as using it to report the state change.
Quoted 6 lines
So there are three main entry points:
wimax_report_rfkill_hw()-- device driver report to stackdevice reports a change in the hw rfkill key; switch the radio to whichever state AND report a key event through the input layer
But reporting the key through the input layer is wrong, afaict.
Quoted 9 lines
wimax_report_rfkill_sw()-- device driver report to stackdevice reports a change in the sw rfkill state; this is needed for cases where the radio is shared amongst different technologies (wifi and wimax, for example, in the case of the 5150). When you turn on Wifi, WiMAX switches off (and vice versa).
As well, if from SW you flip it off, this gets called back but does nothing as the state is updated already.
Shouldn't that be a hard block then? Or can the software turn it back on (and consequently turn off wifi)?
Quoted 3 lines
wimax_rfkill/wimax_rfkill_toggle_radio-- user interfaceThe user wants to flip the SW switch on/off
Right.
So let's go back to my first assertion:
"seems to report rfkill states to input device"
wimax_report_rfkill_hw:
enum rfkill_state rfkill_state;
...
input_report_key(wimax_dev->rfkill_input, KEY_WIMAX,
rfkill_state);??
I don't see why it should have an input device at all, to be honest.
johannes
Quoted 13 lines · Johannes Berg
Quoted 12 lines · Inaky Perez-Gonzalez
Quoted 4 lines · Johannes Berg
* wimax
-> need help, seems to report rfkill states to input device?
don't understandNot really.
What it does is if the device exposes a hw rfkill key, export that key as an input device, as well as using it to report the state change.
Quoted 8 lines
Quoted 6 lines
So there are three main entry points:
wimax_report_rfkill_hw()-- device driver report to stackdevice reports a change in the hw rfkill key; switch the radio to whichever state AND report a key event through the input layer
But reporting the key through the input layer is wrong, afaict.
Why because it combines it with switching the radio?
In rt2x00 all key events are going through the input layer as well, because it has no influence on the radio state of the device. (In other words, you can still happily send and receive all the data you want regardless of the key state).
Ivo
Johannes Berg
maintainerQuoted 5 lines · Ivo van Doorn
Quoted 5 lines
Quoted 4 lines
wimax_report_rfkill_hw()-- device driver report to stackdevice reports a change in the hw rfkill key; switch the radio to whichever state AND report a key event through the input layer
Quoted 7 lines
Quoted 1 line
But reporting the key through the input layer is wrong, afaict.
Why because it combines it with switching the radio?
In rt2x00 all key events are going through the input layer as well, because it has no influence on the radio state of the device. (In other words, you can still happily send and receive all the data you want regardless of the key state).
Yes, but my understanding is (and I've just rewritten the code, heh) that if the button switches the hardware kill directly then we don't report an input event.
Except in very limited circumstances (like the thinkpad-acpi platform driver Henrique explained) I think doing _both_ rfkill_force_state(hard-blocked) [in new API terms:rfkill_set_hw_block(true)] _and_ input_report() is incorrect.
johannes
Johannes Berg
maintainerQuoted 3 lines · Johannes Berg
* b43/b43legacy
-> compiles now, but should remove input polldev and use hw block
polling -- later
done
Quoted 2 lines
* tosa - done now in new patch, but not even compile-tested
(http://johannes.sipsolutions.net/patches/kernel/all/LATEST/NNN-rfkill-rewrite.patch)
need to take care of LED default trigger thing here
johannes
Quoted 14 lines · Johannes Berg
Quoted 5 lines · Ivo van Doorn
Quoted 5 lines
Quoted 4 lines
wimax_report_rfkill_hw()-- device driver report to stackdevice reports a change in the hw rfkill key; switch the radio to whichever state AND report a key event through the input layer
Quoted 7 lines
Quoted 1 line
But reporting the key through the input layer is wrong, afaict.
Why because it combines it with switching the radio?
In rt2x00 all key events are going through the input layer as well, because it has no influence on the radio state of the device. (In other words, you can still happily send and receive all the data you want regardless of the key state).
Quoted 8 lines
Yes, but my understanding is (and I've just rewritten the code, heh) that if the button switches the hardware kill directly then we don't report an input event.
Except in very limited circumstances (like the thinkpad-acpi platform driver Henrique explained) I think doing _both_
rfkill_force_state(hard-blocked)[in new API terms:rfkill_set_hw_block(true)] _and_input_report()is incorrect.
I guess there is both history to both; Johannes, you are right, in this case the hw rfkill kills the radio in HW and *we* send the input event.
Reason it sends the input event is because I used the rt2x00 code as reference...
So, if you guys all agree that passing this to the input layer is not needed,feel free to yank it.
Signature · 1 line
Inaky
Johannes Berg
maintainerQuoted 2 lines · Inaky Perez-Gonzalez
I guess there is both history to both; Johannes, you are right, in this case the hw rfkill kills the radio in HW and *we* send the input event.
Ok.
Quoted 2 lines
Reason it sends the input event is because I used the rt2x00 code as reference...
Right, but rt2x00 doesn't kill the radio in HW.
Quoted 2 lines
So, if you guys all agree that passing this to the input layer is not needed,feel free to yank it.
Ok. Except I don't know how to handle wimax_report_rfkill_sw() yet.
johannes
Quoted 3 lines · Johannes Berg
Thanks for the explanation. I guess that kinda makes sense. One thing I'm entirely sure about -- I had removed the sw default state setter -- I guess this code still requires then? I was thinking the sw default
Yes, thinkpad-acpi wants it. It uses that to make sure the bluethooth and wwan rfkill _global_ state is kept across machine shutdown and reboots (I can't do that for UWB because Lenovo didn't add persistence for UWB for some reason).
Here's how it works:
0. Platform boots with the radio states that were in NVRAM
1. thinkpad-acpi loads
1a. reads radio states from firmware, and stores to rfkill core
default state for the specific radio type
1b. registers the rfkill switch. The core will cause the just
registered rfkill switch state to be changed to match the current global state for that switch type... which probably is what thinkpad-acpi tried to set in 1a.
(normal system lifecycle)
2. thinkpad-acpi unload (or machine shutdown via platform bus shutdown)
2a. commands firmware to store current radio state to NVRAM
So, if thinkpad-acpi is the first rfkill driver of a certain radio type to load, it will cause the state for that radio type to be
persistent. If it is not the first driver to load, well, there is
nothing we can do, and the radio state will be whatever is the current global state for that radio.
The rfkill core tries to keep global states, that are per type. That's why the default is per type (and not per rfkill controller).
Without it, all rfkill types will initally be either blocked or unblocked, depending on a module parameter for the rfkill core.
Quoted 3 lines
state should be set for the devices it applies to, but it seems that if the master rfkill switch is set to "transmitter off" then one needs to set the default state (for all USB transmitters etc) to off, correct?
Well, the default is applied to a _type_, so it is valid for all switches of that type.
It is probably a good idea to have the rfkill core sanitize the attempt to set the default state, and force it to "block" if EPO is active (I don't recall if I checked for this failure mode in the old code).
On a _thinkpad_, the state stored in NVRAM will be overriden by the master switch, because the driver gets that information very indirectly (the firmware sets the initial rfkill controller state from NVRAM, and the driver just reads the rfkill controlled state at startup -- and if the master switch is active, the driver will read
all rfkill controllers as blocked). A driver that could get the
persistent state directly from NVRAM might not be so limited.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 13 lines · Johannes Berg
Quoted 12 lines · Inaky Perez-Gonzalez
Quoted 4 lines · Johannes Berg
* wimax
-> need help, seems to report rfkill states to input device?
don't understandNot really.
What it does is if the device exposes a hw rfkill key, export that key as an input device, as well as using it to report the state change.
Quoted 8 lines
Quoted 6 lines
So there are three main entry points:
wimax_report_rfkill_hw()-- device driver report to stackdevice reports a change in the hw rfkill key; switch the radio to whichever state AND report a key event through the input layer
But reporting the key through the input layer is wrong, afaict.
Reporting the key through the input layer is correct if, and _only_ if, it is REALLY a button/key, AND nothing else is doing it.
It is NOT to be done in anything that could be, for example, an input pin that is tied to a GPIO output in the embedded controller of a laptop that will be driven by a platform driver.
And if it could be both and you can't be certain, you need dmi whitelisting or a module parameter to know which one. And default to NOT issuing input events.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Johannes Berg
maintainerQuoted 4 lines · Henrique de Moraes Holschuh
Yes, thinkpad-acpi wants it. It uses that to make sure the bluethooth and wwan rfkill _global_ state is kept across machine shutdown and reboots (I can't do that for UWB because Lenovo didn't add persistence for UWB for some reason).
Yeah, I've added it back already :)
Quoted 7 lines
1. thinkpad-acpi loads
1a. reads radio states from firmware, and stores to rfkill core
default state for the specific radio type
1b. registers the rfkill switch. The core will cause the just
registered rfkill switch state to be changed to match the current global state for that switch type... which probably is what thinkpad-acpi tried to set in 1a.
Yeah -- I need to add back 1b; I removed it for now because it goes like this:
driver - rfkill_register
rfkill - rfkill_register
rfkill - set radio
driver - set radio <--- deadlock if this needs lock
This I need to schedule that away.
Quoted 6 lines
Quoted 3 lines
state should be set for the devices it applies to, but it seems that if the master rfkill switch is set to "transmitter off" then one needs to set the default state (for all USB transmitters etc) to off, correct?
Well, the default is applied to a _type_, so it is valid for all switches of that type.
Right.
Quoted 4 lines
It is probably a good idea to have the rfkill core sanitize the attempt to set the default state, and force it to "block" if EPO is active (I don't recall if I checked for this failure mode in the old code).
No, but it rejects any calls to set the default state when any rfkill struct has been registered already. So this isn't a concern.
johannes
Hi Johannes!
Quoted 36 lines · Johannes Berg
Quoted 4 lines · Henrique de Moraes Holschuh
Yes, thinkpad-acpi wants it. It uses that to make sure the bluethooth and wwan rfkill _global_ state is kept across machine shutdown and reboots (I can't do that for UWB because Lenovo didn't add persistence for UWB for some reason).
Yeah, I've added it back already :)
Quoted 7 lines
1. thinkpad-acpi loads
1a. reads radio states from firmware, and stores to rfkill core
default state for the specific radio type
1b. registers the rfkill switch. The core will cause the just
registered rfkill switch state to be changed to match the current global state for that switch type... which probably is what thinkpad-acpi tried to set in 1a.Yeah -- I need to add back 1b; I removed it for now because it goes like this:
driver -
rfkill_register
rfkill -rfkill_register
rfkill - set radio
driver - set radio <--- deadlock if this needs lockThis I need to schedule that away.
Quoted 6 lines
Quoted 3 lines
state should be set for the devices it applies to, but it seems that if the master rfkill switch is set to "transmitter off" then one needs to set the default state (for all USB transmitters etc) to off, correct?
Well, the default is applied to a _type_, so it is valid for all switches of that type.
Right.
Quoted 7 lines
Quoted 4 lines
It is probably a good idea to have the rfkill core sanitize the attempt to set the default state, and force it to "block" if EPO is active (I don't recall if I checked for this failure mode in the old code).
No, but it rejects any calls to set the default state when any rfkill struct has been registered already. So this isn't a concern.
Suppose something entirely different (an input device) issued SW_RFKILL_ALL, and EPO is in effect. It happened right at boot because the user turned the laptop on with the rfkill switch active, and that driver loaded first.
Now another driver is loading, and is registering the first rfkill struct of type foo (say, for an USB 'foo' dongle that has no idea whatsoever of any platform rfkill switches), and that USB 'foo' dongle is a really well-made device that even has NVRAM with lots of state pertaining to 'foo', including a bit used to keep persistent on/off state.
It will try to set the default state for type 'foo' (which might well be unblock) while EPO is active. This attempt to set the default for 'foo' to ubblock can succeed or not (whatever is easier on the rfkill core code), but either way it must _not_ cause any switches to be unblocked, and that includes any subsequent rfkill_register (because EPO _is_ active)...
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
So, far, it looks quite good. A few initial comments that I want to get out ASAP (I am bound to have many more after I take a first try at convert thinkpad-acpi to the new API).
Quoted 12 lines · Johannes Berg
+ * struct
rfkill_ops- rfkill driver methods
+ *
+ * @poll_hw_block: poll the rfkill hardware block state (return true
+ * for blocked) -- only assign this method when you cannot
+ * do without polling
+ * @query_state: query the rfkill hardware block state (return true
+ * for blocked) -- assign this method if software events might
+ * cause hardware state changes
+ * @set_block: turn the transmitter on (blocked == false) or off
+ * (blocked == true) -- this is called only while the transmitter
+ * is not hard-blocked. This must be assigned.
+ */
include/linux/rfkill.h enum rfkill_type { · line 90
Quoted 6 lines
include/linux/rfkill.h +5
-0+struct rfkill_ops { +#if defined(CONFIG_RFKILL ) || defined(CONFIG_RFKILL_MODULE ) +bool (*poll_hw_block)(void *data); +bool (*query_state)(void *data); +void (*set_block)(void *data,bool blocked);#endif
Missing error handling on set_block... could you change that to:
int (*set_block)(void *data, bool blocked)
with the usual kernel error semathics (0 = no error, < 0 = specific
error)? And of course, do the error handling on the core?
I don't know about wireless network drivers, but platform drivers want to be able to return errors, they _do_ happen when you are doing ACPI
dances: EBUSY, EIO, ENOMEM...
If something in userspace wants to block a transmitter, it better get an error back if the transmitter could not be blocked. The opposite (unblock) is less critical in the safety sense, but no less critical in the usability sense, so it wants proper error feedback as well.
Quoted 5 lines
+/**
+ *rfkill_register- Register a rfkill structure.
+ * @rfkill: rfkill structure to be registered
+ *
+ * This function should be called by the network driver when the rfkill
minor nit: s/network/rfkill controller/
Quoted 27 lines
Documentation/rfkill.txt +0
-27-Important terms for the rfkill subsystem: - -In order to avoid confusion, we avoid the term "switch" in rfkill when it is -referring to an electronic control circuit that enables or disables a -transmitter. We reserve it for the physical device a human manipulates -(which is an input device, by the way): - -rfkill switch: - - A physical device a human manipulates. Its state can be perceived by - the kernel either directly (through a GPIO pin, ACPI GPE) or by its - effect on a rfkill line of a wireless device. - -rfkill controller: - - A hardware circuit that controls the state of a rfkill line, which a - kernel driver can interact with *to modify* that state (i.e. it has - either write-only or read/write access). - -rfkill line: - - An input channel (hardware or software) of a wireless device, which - causes a wireless transmitter to stop emitting energy (BLOCK) when it - is active. Point of view is extremely important here: rfkill lines are - always seen from the PoV of a wireless device (and its driver). - -soft rfkill line/software rfkill line:
Documentation/rfkill.txt line 108
Quoted 10 lines
Documentation/rfkill.txt +0
-10- - A rfkill line the wireless device driver can directly change the state - of. Related to rfkill_state RFKILL_STATE_SOFT_BLOCKED. - -hard rfkill line/hardware rfkill line: - - A rfkill line that works fully in hardware or firmware, and that cannot - be overridden by the kernel driver. The hardware device or the - firmware just exports its status to the driver, but it is read-only. - Related to rfkill_state RFKILL_STATE_HARD_BLOCKED.
Are you sure you want to do away with the above definitions?
The use of 'rfkill switch' for fundamentally different things caused a lot of confusion in the past. That's why I had to come up with
'rfkill controller', and 'rfkill line'. Maybe you can do away with
the 'rfkill line' now, but controller/switch is something that is helpful to avoid getting input devices and non input devices mixed up.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Johannes Berg
maintainerQuoted 18 lines · Henrique de Moraes Holschuh
Quoted 7 lines
Quoted 4 lines
It is probably a good idea to have the rfkill core sanitize the attempt to set the default state, and force it to "block" if EPO is active (I don't recall if I checked for this failure mode in the old code).
No, but it rejects any calls to set the default state when any rfkill struct has been registered already. So this isn't a concern.
Suppose something entirely different (an input device) issued
SW_RFKILL_ALL, and EPO is in effect. It happened right at boot because the user turned the laptop on with the rfkill switch active, and that driver loaded first.Now another driver is loading, and is registering the first rfkill struct of type foo (say, for an USB 'foo' dongle that has no idea whatsoever of any platform rfkill switches), and that USB 'foo' dongle is a really well-made device that even has NVRAM with lots of state pertaining to 'foo', including a bit used to keep persistent on/off state.
Quoted 5 lines
It will try to set the default state for type 'foo' (which might well be unblock) while EPO is active. This attempt to set the default for 'foo' to ubblock can succeed or not (whatever is easier on the rfkill core code), but either way it must _not_ cause any switches to be unblocked, and that includes any subsequent
rfkill_register(because EPO _is_ active)...
Interesting scenario -- I'll have to think about that, but you're probably right and it needs some stuff to check for epo when setting default.
johannes
Johannes Berg
maintainerQuoted 14 lines · Henrique de Moraes Holschuh
include/linux/rfkill.h enum rfkill_type { · line 90
Quoted 6 lines
include/linux/rfkill.h +5
-0+struct rfkill_ops { +#if defined(CONFIG_RFKILL ) || defined(CONFIG_RFKILL_MODULE ) +bool (*poll_hw_block)(void *data); +bool (*query_state)(void *data); +void (*set_block)(void *data,bool blocked);#endif Missing error handling on
set_block... could you change that to:int (*set_block)(void *data, bool blocked)
with the usual kernel error semathics (0 = no error, < 0 = specific
error)? And of course, do the error handling on the core?
Quoted 8 lines
I don't know about wireless network drivers, but platform drivers want to be able to return errors, they _do_ happen when you are doing ACPI
dances: EBUSY, EIO, ENOMEM...If something in userspace wants to block a transmitter, it better get an error back if the transmitter could not be blocked. The opposite (unblock) is less critical in the safety sense, but no less critical in the usability sense, so it wants proper error feedback as well.
I was considering that, but the current users of the API have no chance to act on the error. It _might_ make sense to put it back when we add the userspace API back, but what should userspace do in that case?
OTOH if it does return an error the sw block bit probably shouldn't be set, so I guess I'll change that.
Quoted 7 lines
Quoted 5 lines
+/**
+ *rfkill_register- Register a rfkill structure.
+ * @rfkill: rfkill structure to be registered
+ *
+ * This function should be called by the network driver when the rfkillminor nit: s/network/rfkill controller/
something like that maybe.
Quoted 40 lines
Quoted 27 lines
Documentation/rfkill.txt +0
-27-Important terms for the rfkill subsystem: - -In order to avoid confusion, we avoid the term "switch" in rfkill when it is -referring to an electronic control circuit that enables or disables a -transmitter. We reserve it for the physical device a human manipulates -(which is an input device, by the way): - -rfkill switch: - - A physical device a human manipulates. Its state can be perceived by - the kernel either directly (through a GPIO pin, ACPI GPE) or by its - effect on a rfkill line of a wireless device. - -rfkill controller: - - A hardware circuit that controls the state of a rfkill line, which a - kernel driver can interact with *to modify* that state (i.e. it has - either write-only or read/write access). - -rfkill line: - - An input channel (hardware or software) of a wireless device, which - causes a wireless transmitter to stop emitting energy (BLOCK) when it - is active. Point of view is extremely important here: rfkill lines are - always seen from the PoV of a wireless device (and its driver). - -soft rfkill line/software rfkill line:Documentation/rfkill.txt line 108
Quoted 10 lines
Documentation/rfkill.txt +0
-10- - A rfkill line the wireless device driver can directly change the state - of. Related to rfkill_state RFKILL_STATE_SOFT_BLOCKED. - -hard rfkill line/hardware rfkill line: - - A rfkill line that works fully in hardware or firmware, and that cannot - be overridden by the kernel driver. The hardware device or the - firmware just exports its status to the driver, but it is read-only. - Related to rfkill_state RFKILL_STATE_HARD_BLOCKED.Are you sure you want to do away with the above definitions?
Quoted 5 lines
The use of 'rfkill switch' for fundamentally different things caused a lot of confusion in the past. That's why I had to come up with
'rfkill controller', and 'rfkill line'. Maybe you can do away with
the 'rfkill line' now, but controller/switch is something that is helpful to avoid getting input devices and non input devices mixed up.
This isn't actually helpful since the terms aren't very clearly used...
I think describing it as a "transmitter driver" is much better anyway. And we don't need any sort of terms whether it's an rfkill line, or whatever, it just doesn't matter -- all we need to know it's hardware-off.
johannes
Johannes Berg
maintainerQuoted 3 lines · Henrique de Moraes Holschuh
So, far, it looks quite good. A few initial comments that I want to get out ASAP (I am bound to have many more after I take a first try at convert thinkpad-acpi to the new API).
Eh, btw, I've been working on it -- look at
http://johannes.sipsolutions.net/patches/kernel/all/LATEST/NNN-rfkill-rewrite.patch (updated frequently)
johannes
Johannes Berg
maintainerQuoted 5 lines · Johannes Berg
TODO:
* wimax
-> need help, seems to report rfkill states to input device?
don't understand
Ok, done.
johannes
Johannes Berg
maintainerQuoted 2 lines · Johannes Berg
* tosa - done now in new patch, but not even compile-tested
(http://johannes.sipsolutions.net/patches/kernel/all/LATEST/NNN-rfkill-rewrite.patch)
One problem here remains -- the LED trigger name was forced to be "tosa-bt" in that code -- that is no longer possible now that struct rfkill is opaque. I think we should simply standardise the name to something like
"<rfkill-name>-radio"
Thoughts? I don't want to call it <..>-rfkill or rfkill-<..> because that would seem to imply inverted polarity.
johannes
Johannes Berg
maintainerPATCH v2 1/1 rfkill: rewrite
In reply to Johannes BergThis patch completely rewrites the rfkill core to address the following deficiencies:
* all rfkill drivers need to implement polling where necessary rather than having one central implementation
* updating the rfkill state cannot be done from arbitrary contexts, forcing drivers to use schedule_work and requiring lots of code
* rfkill drivers need to keep track of soft/hard blocked internally -- the core should do this
* the rfkill API has many unexpected quirks, for example being asymmetric wrt. alloc/free and register/unregister
* rfkill can call back into a driver from within a function the driver called -- this is prone to deadlocks and generally should be avoided
* rfkill-input pointlessly is a separate module
* drivers need to #ifdef rfkill functions (unless they want to depend on or select RFKILL) -- rfkill should provide inlines that do nothing if it isn't compiled in
* the rfkill structure is not opaque -- drivers need to initialise it correctly (lots of sanity checking code required) -- instead force drivers to pass the right variables to rfkill_alloc()
* the documentation is hard to read because it always assumes the reader is completely clueless and contains way TOO MANY CAPS
* the rfkill code needlessly uses a lot of locks and atomic operations in locked sections
---
TODO
* convert toshiba, thinkpad
* compile-test tosa conversion
* figure out tosa-default LED trigger thing
* apply default state to devices after being registered
* test
Requires the other rfkill patches -- which you can also get at
http://johannes.sipsolutions.net/patches/kernel/all/LATEST/
Documentation/rfkill.txt | 637 +++------------------- MAINTAINERS | 6 arch/arm/mach-pxa/tosa-bt.c | 30 - arch/arm/mach-pxa/tosa.c | 1 drivers/net/wireless/ath9k/ath9k.h | 7 drivers/net/wireless/ath9k/main.c | 115 +--- drivers/net/wireless/ath9k/pci.c | 15 drivers/net/wireless/b43/Kconfig | 2 drivers/net/wireless/b43/leds.c | 2 drivers/net/wireless/b43/main.c | 4 drivers/net/wireless/b43/phy_a.c | 4 drivers/net/wireless/b43/phy_common.c | 17 drivers/net/wireless/b43/phy_common.h | 4 drivers/net/wireless/b43/phy_g.c | 4 drivers/net/wireless/b43/phy_lp.c | 2 drivers/net/wireless/b43/phy_n.c | 2 drivers/net/wireless/b43/rfkill.c | 120 +--- drivers/net/wireless/b43/rfkill.h | 5 drivers/net/wireless/b43legacy/Kconfig | 2 drivers/net/wireless/b43legacy/leds.c | 3 drivers/net/wireless/b43legacy/rfkill.c | 116 +--- drivers/net/wireless/b43legacy/rfkill.h | 6 drivers/net/wireless/iwlwifi/Kconfig | 5 drivers/net/wireless/iwlwifi/iwl-rfkill.c | 69 -- drivers/platform/x86/Kconfig | 6 drivers/platform/x86/acer-wmi.c | 50 - drivers/platform/x86/dell-laptop.c | 101 +-- drivers/platform/x86/eeepc-laptop.c | 91 --- drivers/platform/x86/hp-wmi.c | 103 +-- drivers/platform/x86/toshiba_acpi.c | 23 include/linux/Kbuild | 1 include/linux/rfkill.h | 281 +++++++--- include/net/wimax.h | 8 net/rfkill/Kconfig | 14 net/rfkill/Makefile | 4 net/rfkill/core.c | 752 ++++++++++++++++++++++++++ net/rfkill/input.c | 337 +++++++++++ net/rfkill/rfkill-input.c | 392 ------------- net/rfkill/rfkill-input.h | 21 net/rfkill/rfkill.c | 843 ------------------------------ net/rfkill/rfkill.h | 27 net/wimax/op-rfkill.c | 82 -- 42 files changed, 1753 insertions(+), 2561 deletions(-)
include/linux/rfkill.h +211 -70
@@ -4,6 +4,7 @@/* * Copyright (C) 2006 - 2007 Ivo van Doorn * Copyright (C) 2007 Dmitry Torokhov +* Copyright 2009 Johannes Berg <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -21,6 +22,24 @@* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* define userspace visible states */ +#define RFKILL_STATE_SOFT_BLOCKED 0 +#define RFKILL_STATE_UNBLOCKED 1 +#define RFKILL_STATE_HARD_BLOCKED 2 + +/* and that's all userspace gets */ +#ifdef __KERNEL__ +/* don't allow anyone to use these in the kernel */ +enum rfkill_user_states { +RFKILL_USER_STATE_SOFT_BLOCKED =RFKILL_STATE_SOFT_BLOCKED , +RFKILL_USER_STATE_UNBLOCKED =RFKILL_STATE_UNBLOCKED , +RFKILL_USER_STATE_HARD_BLOCKED =RFKILL_STATE_HARD_BLOCKED , +}; +#undef RFKILL_STATE_SOFT_BLOCKED +#undef RFKILL_STATE_UNBLOCKED +#undef RFKILL_STATE_HARD_BLOCKED +#include <linux/types.h> #include <linux/kernel.h> #include <linux/list.h>
@@ -30,11 +49,13 @@/** * enum rfkill_type - type of rfkill switch. -* RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. -* RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. -* RFKILL_TYPE_UWB: switch is on a ultra wideband device. -* RFKILL_TYPE_WIMAX: switch is on a WiMAX device. -* RFKILL_TYPE_WWAN: switch is on a wireless WAN device. +* +* @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. +* @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. +* @RFKILL_TYPE_UWB: switch is on a ultra wideband device. +* @RFKILL_TYPE_WIMAX: switch is on a WiMAX device. +* @RFKILL_TYPE_WWAN: switch is on a wireless WAN device. +* @NUM_RFKILL_TYPES: number of defined rfkill types */ enum rfkill_type {RFKILL_TYPE_WLAN ,
@@ -42,97 +63,217 @@ enum rfkill_type {RFKILL_TYPE_UWB ,RFKILL_TYPE_WIMAX ,RFKILL_TYPE_WWAN , - RFKILL_TYPE_MAX, + NUM_RFKILL_TYPES, }; -enum rfkill_state { -RFKILL_STATE_SOFT_BLOCKED =0 ,/* Radio output blocked */ -RFKILL_STATE_UNBLOCKED =1 ,/* Radio output allowed */ -RFKILL_STATE_HARD_BLOCKED =2 ,/* Output blocked, non-overrideable */ -RFKILL_STATE_MAX ,/* marker for last valid state */ -}; +#define RFKILL_BLOCK_HW_BIT 0 +#define RFKILL_BLOCK_SW_BIT 1/** -* struct rfkill - rfkill control structure. -* @name: Name of the switch. -* @type: Radio type which the button controls, the value stored -* here should be a value from enum rfkill_type. -* @state: State of the switch, "UNBLOCKED" means radio can operate. -* @mutex: Guards switch state transitions. It serializes callbacks -* and also protects the state. -* @data: Pointer to the RF button drivers private data which will be -* passed along when toggling radio state. -* @toggle_radio(): Mandatory handler to control state of the radio. -* only RFKILL_STATE_SOFT_BLOCKED and RFKILL_STATE_UNBLOCKED are -* valid parameters. -* @get_state(): handler to read current radio state from hardware, -* may be called from atomic context, should return 0 on success. -* Either this handler OR judicious use of rfkill_force_state() is -* MANDATORY for any driver capable of RFKILL_STATE_HARD_BLOCKED. -* @led_trigger: A LED trigger for this button's LED. -* @dev: Device structure integrating the switch into device tree. -* @node: Used to place switch into list of all switches known to the -* the system. -* -* This structure represents a RF switch located on a network device. -*/ -struct rfkill { -const char *name; -enum rfkill_type type; - -/* the mutex serializes callbacks and also protects -* the state */ -struct mutex mutex; -enum rfkill_state state; -void *data; -int (*toggle_radio)(void *data,enum rfkill_state state); -int (*get_state)(void *data,enum rfkill_state *state); +* struct rfkill_ops - rfkill driver methods +* +* @poll_hw_block: poll the rfkill hardware block state (return true +* for blocked) -- only assign this method when you cannot +* do without polling +* @query_state: query the rfkill hardware block state (return true +* for blocked) -- assign this method if software events might +* cause hardware state changes +* @set_block: turn the transmitter on (blocked == false) or off +* (blocked == true) -- this is called only while the transmitter +* is not hard-blocked. This must be assigned. +*/ +struct rfkill_ops { +bool (*poll_hw_block)(void *data); +bool (*query_state)(void *data); +int (*set_block)(void *data,bool blocked); +}; -#ifdef CONFIG_RFKILL_LEDS -struct led_trigger led_trigger; -#endif +/* this is opaque */ +struct rfkill ; -struct device dev; -struct list_head node; -enum rfkill_state state_for_resume; -}; -#define to_rfkill (d) container_of(d, struct rfkill, dev) +#if defined(CONFIG_RFKILL ) || defined(CONFIG_RFKILL_MODULE ) +/** +* rfkill_alloc - allocate rfkill structure +* @name: name of the struct -- the string is not copied internally +* @parent: device that has rf switch on it +* @type: type of the switch (RFKILL_TYPE_*) +* @ops: rfkill methods +* @ops_data: data passed to each method +* +* This function should be called by the transmitter driver to allocate an +* rfkill structure. +*/ +struct rfkill *__must_check rfkill_alloc (const char *name, +struct device *parent, +const enum rfkill_type type, +const struct rfkill_ops *ops, +void *ops_data); -struct rfkill *__must_check rfkill_allocate (struct device *parent, -enum rfkill_type type); -void rfkill_free (struct rfkill *rfkill); +/** +* rfkill_register - Register a rfkill structure. +* @rfkill: rfkill structure to be registered +* +* This function should be called by the transmitter driver to register +* the rfkill structure needs to be registered. Before calling this function +* the driver needs to be ready to service method calls from rfkill. +*/ int __must_check rfkill_register (struct rfkill *rfkill); + +/** +* rfkill_pause_polling(struct rfkill *rfkill) +* +* Pause polling -- say transmitter is off for other reasons. +* NOTE: not necessary for suspend/resume -- in that case the +* core stops polling anyway +*/ +void rfkill_pause_polling (struct rfkill *rfkill); + +/** +* rfkill_resume_polling(struct rfkill *rfkill) +* +* Pause polling -- say transmitter is off for other reasons. +* NOTE: not necessary for suspend/resume -- in that case the +* core stops polling anyway +*/ +void rfkill_resume_polling (struct rfkill *rfkill); + + +/** +* rfkill_unregister - Unregister a rfkill structure. +* @rfkill: rfkill structure to be unregistered +* +* This function should be called by the network driver during device +* teardown to destroy rfkill structure. Until it returns, the driver +* needs to be able to service method calls. +*/ void rfkill_unregister (struct rfkill *rfkill); -int rfkill_force_state (struct rfkill *rfkill,enum rfkill_state state); -int rfkill_set_default (enum rfkill_type type,enum rfkill_state state); +/** +* rfkill_destroy - free rfkill structure +* @rfkill: rfkill structure to be destroyed +* +* Destroys the rfkill structure. +*/ +void rfkill_destroy (struct rfkill *rfkill); + +/** +* rfkill_set_hw_state - Set the internal rfkill hardware block state +* @rfkill: pointer to the rfkill class to modify. +* @state: the current hardware block state to set +* +* rfkill drivers that get events when the hard-blocked state changes +* use this function to notify the rfkill core (and through that also +* userspace) of the current state -- they should also use this after +* resume if the state could have changed. +* +* You need not (but may) call this function if poll_state is assigned. +* +* This function can be called in any context. +* +* The function returns the combined block state (true if transmitter +* should be blocked) so that drivers need not keep track of the soft +* block state -- which they cannot anyway because while hard-blocked +* they do not receive soft-block events. +*/ +bool rfkill_set_hw_state (struct rfkill *rfkill,bool blocked); + +/** +* rfkill_set_sw_state - Set the internal rfkill software block state +* @rfkill: pointer to the rfkill class to modify. +* @state: the current software block state to set +* +* rfkill drivers that get events when the soft-blocked state changes +* (yes, some platforms directly act on input but allow changing again) +* use this function to notify the rfkill core (and through that also +* userspace) of the current state -- they should also use this after +* resume if the state could have changed. +* +* This function can be called in any context. +* +* The function returns the combined block state (true if transmitter +* should be blocked). +*/ +bool rfkill_set_sw_state (struct rfkill *rfkill,bool blocked);/** -* rfkill_state_complement - return complementar state -* @state: state to return the complement of +* rfkill_set_global_sw_state - set global sw block default +* @type: rfkill type to set default for +* @blocked: default to set +* +* This function sets the global default -- use at boot if your platform has +* an rfkill switch. If not early enough this call may be ignored. * -* Returns RFKILL_STATE_SOFT_BLOCKED if @state is RFKILL_STATE_UNBLOCKED, -* returns RFKILL_STATE_UNBLOCKED otherwise. +* XXX: instead of ignoring -- how about just updating all currently +* registered drivers? */ -static inline enum rfkill_state rfkill_state_complement (enum rfkill_state state) +void rfkill_set_global_sw_state (const enum rfkill_type type,bool blocked); +#else /* !RFKILL */ +static inline struct rfkill *__must_check +rfkill_alloc (const char *name, +struct device *parent, +const enum rfkill_type type, +const struct rfkill_ops *ops, +void *ops_data) +{ +return ERR_PTR (-ENODEV ); +} + +static inline int __must_check rfkill_register (struct rfkill *rfkill) +{ +if (rfkill ==ERR_PTR (-ENODEV )) +return 0 ; +return -EINVAL ; +} + +static inline void rfkill_pause_polling (struct rfkill *rfkill) +{ +} + +static inline void rfkill_resume_polling (struct rfkill *rfkill) +{ +} + +static inline void rfkill_unregister (struct rfkill *rfkill) { -return (state ==RFKILL_STATE_UNBLOCKED ) ? -RFKILL_STATE_SOFT_BLOCKED :RFKILL_STATE_UNBLOCKED ; } +static inline void rfkill_destroy (struct rfkill *rfkill) +{ +} + +static inline bool rfkill_set_hw_state (struct rfkill *rfkill,bool blocked) +{ +return blocked; +} + +static inline bool rfkill_set_sw_state (struct rfkill *rfkill,bool blocked) +{ +return blocked; +} + +static inline void rfkill_set_global_sw_state (const enum rfkill_type type, +bool blocked) +{ +} +#endif /* RFKILL || RFKILL_MODULE */ + + +/** * rfkill_get_led_name - Get the LED trigger name for the button's LED. * This function might return a NULL pointer if registering of the * LED trigger failed. * Use this as "default_trigger" for the LED. */ -static inline char *rfkill_get_led_name (struct rfkill *rfkill) -{#ifdef CONFIG_RFKILL_LEDS -return (char *)(rfkill->led_trigger.name); +const char *rfkill_get_led_name (struct rfkill *rfkill);#else +static inline const char *rfkill_get_led_name (struct rfkill *rfkill) +{return NULL ; -#endif } +#endif + +#endif /* __KERNEL__ */ #endif /* RFKILL_H */
drivers/net/wireless/ath9k/main.c +29 -86
169 lines not on this page · raw message
drivers/platform/x86/eeepc-laptop.c +22 -69
128 lines not on this page · raw message
net/rfkill/rfkill.c deleted +0 -843
843 lines not on this page · raw message
net/rfkill/rfkill-input.h deleted +0 -21
@@ -1,21 +0,0 @@ -/* -* Copyright (C) 2007 Ivo van Doorn -*/ - -/* -* This program is free software; you can redistribute it and/or modify it -* under the terms of the GNU General Public License version 2 as published -* by the Free Software Foundation. -*/ - -#ifndef __RFKILL_INPUT_H -#define __RFKILL_INPUT_H - -void rfkill_switch_all (enum rfkill_type type,enum rfkill_state state); -void rfkill_epo (void ); -void rfkill_restore_states (void ); -void rfkill_remove_epo_lock (void ); -bool rfkill_is_epo_lock_active (void ); -enum rfkill_state rfkill_get_global_state (const enum rfkill_type type); - -#endif /* __RFKILL_INPUT_H */
net/rfkill/rfkill-input.c deleted +0 -392
392 lines not on this page · raw message
drivers/net/wireless/b43/main.c +2 -2
@@ -3492,7 +3492,7 @@ static int b43_op_config(struct ieee8021if (!!conf->radio_enabled != phy->radio_on) {if (conf->radio_enabled) { -b43_software_rfkill (dev,RFKILL_STATE_UNBLOCKED ); +b43_software_rfkill (dev, false);b43info (dev->wl,"Radio turned on by software\n" );if (!dev->radio_hw_enable) { b43info(dev->wl, "The hardware RF-kill button "
@@ -3500,7 +3500,7 @@ static int b43_op_config(struct ieee8021 "Press the button to turn it on.\n"); } }else { -b43_software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); +b43_software_rfkill (dev, true);b43info (dev->wl,"Radio turned off by software\n" ); } }
drivers/net/wireless/b43/phy_a.c +2 -2
@@ -480,11 +480,11 @@ static bool b43_aphy_op_supports_hwpctl( }static void b43_aphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {struct b43_phy *phy = &dev->phy; -if (state ==RFKILL_STATE_UNBLOCKED ) { +if (!blocked) {if (phy->radio_on)return ;b43_radio_write16 (dev,0x0004 ,0x00C0 );
drivers/net/wireless/b43/phy_common.c +6 -11
@@ -84,7 +84,7 @@ int b43_phy_init(struct b43_wldev *dev) phy->channel = ops->get_default_chan (dev); - ops->software_rfkill (dev,RFKILL_STATE_UNBLOCKED ); + ops->software_rfkill (dev, false); err = ops->init (dev);if (err) {b43err (dev->wl,"PHY init failed\n" );
@@ -104,7 +104,7 @@ err_phy_exit:if (ops->exit) ops->exit (dev); err_block_rf: - ops->software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); + ops->software_rfkill (dev, true);return err; }
@@ -113,7 +113,7 @@ void b43_phy_exit(struct b43_wldev *dev) {const struct b43_phy_operations *ops = dev->phy.ops; - ops->software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); + ops->software_rfkill (dev, true);if (ops->exit) ops->exit (dev); }
@@ -287,18 +287,13 @@ err_restore_cookie:return err; } -void b43_software_rfkill (struct b43_wldev *dev,enum rfkill_state state) +void b43_software_rfkill (struct b43_wldev *dev,bool blocked) {struct b43_phy *phy = &dev->phy; -if (state ==RFKILL_STATE_HARD_BLOCKED ) { -/* We cannot hardware-block the device */ - state =RFKILL_STATE_SOFT_BLOCKED ; - } -b43_mac_suspend (dev); - phy->ops->software_rfkill (dev, state); - phy->radio_on = (state ==RFKILL_STATE_UNBLOCKED ); + phy->ops->software_rfkill (dev, blocked); + phy->radio_on = !blocked;b43_mac_enable (dev); }
drivers/net/wireless/b43/phy_common.h +2 -2
@@ -159,7 +159,7 @@ struct b43_phy_operations {/* Radio */ bool (*supports_hwpctl)(struct b43_wldev *dev); -void (*software_rfkill)(struct b43_wldev *dev,enum rfkill_state state); +void (*software_rfkill)(struct b43_wldev *dev,bool blocked);void (*switch_analog)(struct b43_wldev *dev,bool on);int (*switch_channel)(struct b43_wldev *dev,unsigned int new_channel);unsigned int (*get_default_chan)(struct b43_wldev *dev);
@@ -362,7 +362,7 @@ int b43_switch_channel(struct b43_wldev/** * b43_software_rfkill - Turn the radio ON or OFF in software. */ -void b43_software_rfkill (struct b43_wldev *dev,enum rfkill_state state); +void b43_software_rfkill (struct b43_wldev *dev,bool blocked);/** * b43_phy_txpower_check - Check TX power output.
drivers/net/wireless/b43/phy_g.c +2 -2
@@ -2592,7 +2592,7 @@ static bool b43_gphy_op_supports_hwpctl( }static void b43_gphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {struct b43_phy *phy = &dev->phy;struct b43_phy_g *gphy = phy->g;
@@ -2600,7 +2600,7 @@ static void b43_gphy_op_software_rfkill(might_sleep (); -if (state ==RFKILL_STATE_UNBLOCKED ) { +if (!blocked) {/* Turn radio ON */ if (phy->radio_on)return ;
drivers/net/wireless/b43/phy_n.c +1 -1
@@ -579,7 +579,7 @@ static void b43_nphy_op_radio_write(stru }static void b43_nphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {//TODO }
drivers/net/wireless/b43/rfkill.c +32 -88
187 lines not on this page · raw message
drivers/net/wireless/b43legacy/rfkill.c +33 -83
187 lines not on this page · raw message
drivers/net/wireless/iwlwifi/iwl-rfkill.c +28 -41
124 lines not on this page · raw message
Documentation/rfkill.txt +98 -539
504 lines not on this page · raw message
net/rfkill/Kconfig +0 -14
Lines of this file are not shown. View the raw message.
net/rfkill/Makefile +2 -2
Lines of this file are not shown. View the raw message.
net/rfkill/core.c new file +752 -0
752 lines not on this page · raw message
net/rfkill/input.c new file +337 -0
337 lines not on this page · raw message
net/rfkill/rfkill.h new file +27 -0
Lines of this file are not shown. View the raw message.
MAINTAINERS +3 -3
Lines of this file are not shown. View the raw message.
include/linux/Kbuild +1 -0
Lines of this file are not shown. View the raw message.
drivers/net/wireless/ath9k/ath9k.h +1 -6
Lines of this file are not shown. View the raw message.
drivers/net/wireless/ath9k/pci.c +0 -15
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/Kconfig +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/rfkill.h +1 -4
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/Kconfig +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/leds.c +2 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/rfkill.h +1 -5
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/leds.c +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/iwlwifi/Kconfig +2 -3
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/phy_lp.c +1 -1
Lines of this file are not shown. View the raw message.
drivers/platform/x86/Kconfig +0 -6
Lines of this file are not shown. View the raw message.
drivers/platform/x86/acer-wmi.c +22 -28
50 lines not on this page · raw message
drivers/platform/x86/dell-laptop.c +33 -68
101 lines not on this page · raw message
drivers/platform/x86/hp-wmi.c +52 -51
103 lines not on this page · raw message
drivers/platform/x86/toshiba_acpi.c +7 -16
Lines of this file are not shown. View the raw message.
arch/arm/mach-pxa/tosa-bt.c +14 -16
Lines of this file are not shown. View the raw message.
arch/arm/mach-pxa/tosa.c +0 -1
Lines of this file are not shown. View the raw message.
include/net/wimax.h +2 -6
Lines of this file are not shown. View the raw message.
net/wimax/op-rfkill.c +22 -60
82 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Quoted 45 lines · Johannes Berg
This patch completely rewrites the rfkill core to address the following deficiencies:
* all rfkill drivers need to implement polling where necessary rather than having one central implementation
* updating the rfkill state cannot be done from arbitrary contexts, forcing drivers to use
schedule_workand requiring lots of code* rfkill drivers need to keep track of soft/hard blocked internally -- the core should do this
* the rfkill API has many unexpected quirks, for example being asymmetric wrt. alloc/free and register/unregister
* rfkill can call back into a driver from within a function the driver called -- this is prone to deadlocks and generally should be avoided
* rfkill-input pointlessly is a separate module
* drivers need to #ifdef rfkill functions (unless they want to depend on or select RFKILL) -- rfkill should provide inlines that do nothing if it isn't compiled in
* the rfkill structure is not opaque -- drivers need to initialise it correctly (lots of sanity checking code required) -- instead force drivers to pass the right variables to
rfkill_alloc()* the documentation is hard to read because it always assumes the reader is completely clueless and contains way TOO MANY CAPS
* the rfkill code needlessly uses a lot of locks and atomic operations in locked sections
Signed-off-by Johannes Berg <[email protected]>---
TODO
* convert toshiba, thinkpad
* compile-test tosa conversion
* figure out tosa-default LED trigger thing
* apply default state to devices after being registered
* test
Quoted 2 lines
Requires the other rfkill patches -- which you can also get at
http://johannes.sipsolutions.net/patches/kernel/all/LATEST/
Initial testing shows at least two problems with b43legacy (and probably b43 as well):
(1) On bootup with my radio switch OFF, the driver ignored that switch and associated with my AP. Only when the switch was turned on and off again did the driver log the expected "switch off" message".
(2) The radio LED is on no matter the state of the switch.
Larry
Johannes Berg
maintainerQuoted 2 lines · Larry Finger
Initial testing shows at least two problems with b43legacy (and probably b43 as well):
Thanks for testing!
Quoted 3 lines
(1) On bootup with my radio switch OFF, the driver ignored that switch and associated with my AP. Only when the switch was turned on and off again did the driver log the expected "switch off" message".
I think that's expected because I'm missing some code to set the default state when a driver registers.
Quoted 1 line
(2) The radio LED is on no matter the state of the switch.
That's strange. I'll take a look.
johannes
Johannes Berg
maintainer[dropping CCs, this is relevant to b43legacy only]
Quoted 3 lines · Johannes Berg
Quoted 1 line
(2) The radio LED is on no matter the state of the switch.
That's strange. I'll take a look.
Hmm, has that really worked before? I'd be surprised if it has -- the radio LED seems to be tied to mac80211's radio LED trigger, not the rfkill LED trigger, and mac80211 knows nothing about rfkill at this point (which I'll fix too, eventually).
johannes
Johannes Berg
maintainerQuoted 2 lines · Johannes Berg
This patch completely rewrites the rfkill core to address the following deficiencies:
[snip]
This one has a few stupid locking bugs, will send an updated version later today, for now at the well-known URL.
johannes
Quoted 2 lines · Johannes Berg
This patch completely rewrites the rfkill core to address the following deficiencies:
-- snip --
net/rfkill/core.c line 1
Quoted 4 lines
net/rfkill/core.c new file +1
-0@@ -0,0 +1,752 @@ +/*
-- snip --
Quoted 40 lines
net/rfkill/core.c new file +40
-0+int __must_check rfkill_register (struct rfkill *rfkill) +{ +static unsigned long rfkill_no =0 ; +struct device *dev = &rfkill->dev; +int error; + +BUG_ON (!rfkill); + +mutex_lock (&rfkill_global_mutex); + +if (rfkill->registered) { + error = -EALREADY ; + goto unlock; + } + +dev_set_name (dev,"rfkill%lu" , rfkill_no); + rfkill_no++; + +if (!(rfkill_states_default_locked &BIT (rfkill->type))) { +/* first of its kind */ +BUILD_BUG_ON (NUM_RFKILL_TYPES > +sizeof (rfkill_states_default_locked) *8 ); + rfkill_states_default_locked |=BIT (rfkill->type); + rfkill_global_states[rfkill->type].cur = + rfkill_global_states[rfkill->type].def; + } + +/* XXX: schedule work to set default state */ + +list_add_tail (&rfkill->node, &rfkill_list); + + error =device_add (dev); +if (error) + goto remove; + + error =rfkill_led_trigger_register (rfkill); +if (error) + goto devdel; + + rfkill->registered = true;
net/rfkill/core.c line 51
Quoted 10 lines
net/rfkill/core.c new file +10
-0+ +if (rfkill->ops->poll_hw_block) { +INIT_DELAYED_WORK (&rfkill->poll_work, rfkill_poll); +schedule_delayed_work (&rfkill->poll_work, +round_jiffies_relative (POLL_INTERVAL )); + } + +INIT_WORK (&rfkill->uevent_work, rfkill_uevent_work); + +return 0 ;
The locking looks funny here. The normal return leaves the rfkill_global_mutex locked. Did you mean "goto unlock" instead of "return 0"?
net/rfkill/core.c line 60
Quoted 9 lines
net/rfkill/core.c new file +9
-0+ + devdel: +device_del (&rfkill->dev); + remove: +list_del_init (&rfkill->node); + unlock: +mutex_unlock (&rfkill_global_mutex); +return error; +}
I was alerted to this problem when I was unable to shut down or reboot normally. Those problems are fixed with the patch
net/rfkill/core.c +1 -1
@@ -676,7 +676,7 @@ int __must_check rfkill_register(structINIT_WORK (&rfkill->uevent_work, rfkill_uevent_work); -return 0 ; + goto unlock; devdel:device_del (&rfkill->dev);
Larry
Johannes Berg
maintainerQuoted 2 lines · Larry Finger
I was alerted to this problem when I was unable to shut down or reboot normally. Those problems are fixed with the patch
Indeed, thanks. There's another, similar, bug in another function -- I've updated the patch on my website. I'm going to implement the "initial state" thing now and then resend.
johannes
Johannes Berg
maintainerRFC v3 1/1 rfkill: rewrite
In reply to Johannes BergThis patch completely rewrites the rfkill core to address the following deficiencies:
* all rfkill drivers need to implement polling where necessary rather than having one central implementation
* updating the rfkill state cannot be done from arbitrary contexts, forcing drivers to use schedule_work and requiring lots of code
* rfkill drivers need to keep track of soft/hard blocked internally -- the core should do this
* the rfkill API has many unexpected quirks, for example being asymmetric wrt. alloc/free and register/unregister
* rfkill-input pointlessly is a separate module
* drivers need to #ifdef rfkill functions (unless they want to depend on or select RFKILL) -- rfkill should provide inlines that do nothing if it isn't compiled in
* the rfkill structure is not opaque -- drivers need to initialise it correctly (lots of sanity checking code required) -- instead force drivers to pass the right variables to rfkill_alloc()
* the documentation is hard to read because it always assumes the reader is completely clueless and contains way TOO MANY CAPS
* the rfkill code needlessly uses a lot of locks and atomic operations in locked sections
---
v3: * fix locking bugs
* fix bug in input.c that made it ignore things
* allow setting LED trigger name
* apply default state while registering
* convert HSO
TODO
* convert toshiba, thinkpad
* (compile) test tosa conversion
* test
Documentation/rfkill.txt | 639 +++------------------- MAINTAINERS | 6 arch/arm/mach-pxa/tosa-bt.c | 30 - arch/arm/mach-pxa/tosa.c | 1 drivers/net/usb/hso.c | 42 - drivers/net/wireless/ath9k/ath9k.h | 7 drivers/net/wireless/ath9k/main.c | 115 +--- drivers/net/wireless/ath9k/pci.c | 15 drivers/net/wireless/b43/Kconfig | 2 drivers/net/wireless/b43/leds.c | 2 drivers/net/wireless/b43/main.c | 4 drivers/net/wireless/b43/phy_a.c | 4 drivers/net/wireless/b43/phy_common.c | 17 drivers/net/wireless/b43/phy_common.h | 4 drivers/net/wireless/b43/phy_g.c | 4 drivers/net/wireless/b43/phy_lp.c | 2 drivers/net/wireless/b43/phy_n.c | 2 drivers/net/wireless/b43/rfkill.c | 122 +--- drivers/net/wireless/b43/rfkill.h | 5 drivers/net/wireless/b43legacy/Kconfig | 2 drivers/net/wireless/b43legacy/leds.c | 3 drivers/net/wireless/b43legacy/rfkill.c | 118 +--- drivers/net/wireless/b43legacy/rfkill.h | 6 drivers/net/wireless/iwlwifi/Kconfig | 5 drivers/net/wireless/iwlwifi/iwl-rfkill.c | 69 -- drivers/platform/x86/Kconfig | 6 drivers/platform/x86/acer-wmi.c | 50 - drivers/platform/x86/dell-laptop.c | 101 +-- drivers/platform/x86/eeepc-laptop.c | 91 --- drivers/platform/x86/hp-wmi.c | 103 +-- drivers/platform/x86/toshiba_acpi.c | 23 include/linux/Kbuild | 1 include/linux/rfkill.h | 330 +++++++++-- include/net/wimax.h | 8 net/rfkill/Kconfig | 14 net/rfkill/Makefile | 4 net/rfkill/core.c | 780 +++++++++++++++++++++++++++ net/rfkill/input.c | 342 ++++++++++++ net/rfkill/rfkill-input.c | 392 ------------- net/rfkill/rfkill-input.h | 21 net/rfkill/rfkill.c | 843 ------------------------------ net/rfkill/rfkill.h | 27 net/wimax/Kconfig | 14 net/wimax/op-rfkill.c | 125 ---- 44 files changed, 1865 insertions(+), 2636 deletions(-)
include/linux/rfkill.h +257 -73
@@ -4,6 +4,7 @@/* * Copyright (C) 2006 - 2007 Ivo van Doorn * Copyright (C) 2007 Dmitry Torokhov +* Copyright 2009 Johannes Berg <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -21,6 +22,24 @@* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* define userspace visible states */ +#define RFKILL_STATE_SOFT_BLOCKED 0 +#define RFKILL_STATE_UNBLOCKED 1 +#define RFKILL_STATE_HARD_BLOCKED 2 + +/* and that's all userspace gets */ +#ifdef __KERNEL__ +/* don't allow anyone to use these in the kernel */ +enum rfkill_user_states { +RFKILL_USER_STATE_SOFT_BLOCKED =RFKILL_STATE_SOFT_BLOCKED , +RFKILL_USER_STATE_UNBLOCKED =RFKILL_STATE_UNBLOCKED , +RFKILL_USER_STATE_HARD_BLOCKED =RFKILL_STATE_HARD_BLOCKED , +}; +#undef RFKILL_STATE_SOFT_BLOCKED +#undef RFKILL_STATE_UNBLOCKED +#undef RFKILL_STATE_HARD_BLOCKED +#include <linux/types.h> #include <linux/kernel.h> #include <linux/list.h>
@@ -30,11 +49,13 @@/** * enum rfkill_type - type of rfkill switch. -* RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. -* RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. -* RFKILL_TYPE_UWB: switch is on a ultra wideband device. -* RFKILL_TYPE_WIMAX: switch is on a WiMAX device. -* RFKILL_TYPE_WWAN: switch is on a wireless WAN device. +* +* @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. +* @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. +* @RFKILL_TYPE_UWB: switch is on a ultra wideband device. +* @RFKILL_TYPE_WIMAX: switch is on a WiMAX device. +* @RFKILL_TYPE_WWAN: switch is on a wireless WAN device. +* @NUM_RFKILL_TYPES: number of defined rfkill types */ enum rfkill_type {RFKILL_TYPE_WLAN ,
@@ -42,97 +63,260 @@ enum rfkill_type {RFKILL_TYPE_UWB ,RFKILL_TYPE_WIMAX ,RFKILL_TYPE_WWAN , - RFKILL_TYPE_MAX, + NUM_RFKILL_TYPES, }; -enum rfkill_state { -RFKILL_STATE_SOFT_BLOCKED =0 ,/* Radio output blocked */ -RFKILL_STATE_UNBLOCKED =1 ,/* Radio output allowed */ -RFKILL_STATE_HARD_BLOCKED =2 ,/* Output blocked, non-overrideable */ -RFKILL_STATE_MAX ,/* marker for last valid state */ +#define RFKILL_BLOCK_HW_BIT 0 +#define RFKILL_BLOCK_SW_BIT 1 + +/** +* struct rfkill_ops - rfkill driver methods +* +* @poll_hw_block: poll the rfkill hardware block state (return true +* for blocked) -- only assign this method when you cannot +* do without polling +* @query_hw_block: query the rfkill hardware block state (return true +* for blocked) -- assign this method if input events can cause +* hardware state changes +* @set_block: turn the transmitter on (blocked == false) or off +* (blocked == true) -- this is called only while the transmitter +* is not hard-blocked. This must be assigned. +*/ +struct rfkill_ops { +bool (*poll_hw_block)(void *data); +bool (*query_hw_block)(void *data); +int (*set_block)(void *data,bool blocked); }; +/* this is opaque */ +struct rfkill ; + +#if defined(CONFIG_RFKILL ) || defined(CONFIG_RFKILL_MODULE )/** -* struct rfkill - rfkill control structure. -* @name: Name of the switch. -* @type: Radio type which the button controls, the value stored -* here should be a value from enum rfkill_type. -* @state: State of the switch, "UNBLOCKED" means radio can operate. -* @mutex: Guards switch state transitions. It serializes callbacks -* and also protects the state. -* @data: Pointer to the RF button drivers private data which will be -* passed along when toggling radio state. -* @toggle_radio(): Mandatory handler to control state of the radio. -* only RFKILL_STATE_SOFT_BLOCKED and RFKILL_STATE_UNBLOCKED are -* valid parameters. -* @get_state(): handler to read current radio state from hardware, -* may be called from atomic context, should return 0 on success. -* Either this handler OR judicious use of rfkill_force_state() is -* MANDATORY for any driver capable of RFKILL_STATE_HARD_BLOCKED. -* @led_trigger: A LED trigger for this button's LED. -* @dev: Device structure integrating the switch into device tree. -* @node: Used to place switch into list of all switches known to the -* the system. -* -* This structure represents a RF switch located on a network device. -*/ -struct rfkill { -const char *name; -enum rfkill_type type; - -/* the mutex serializes callbacks and also protects -* the state */ -struct mutex mutex; -enum rfkill_state state; -void *data; -int (*toggle_radio)(void *data,enum rfkill_state state); -int (*get_state)(void *data,enum rfkill_state *state); +* rfkill_alloc - allocate rfkill structure +* @name: name of the struct -- the string is not copied internally +* @parent: device that has rf switch on it +* @type: type of the switch (RFKILL_TYPE_*) +* @ops: rfkill methods +* @ops_data: data passed to each method +* +* This function should be called by the transmitter driver to allocate an +* rfkill structure. +*/ +struct rfkill *__must_check rfkill_alloc (const char *name, +struct device *parent, +const enum rfkill_type type, +const struct rfkill_ops *ops, +void *ops_data); -#ifdef CONFIG_RFKILL_LEDS -struct led_trigger led_trigger; -#endif +/** +* rfkill_has_sw_block_memory -- turn on calling set_block unconditionally +* @rfkill: rfkill struct +* +* This function tells the rfkill core that the device is capable of +* remembering soft blocks (which it is notified of via the set_block +* method) -- this means that the driver may ignore the return value +* from rfkill_set_hw_state(). +* +* This function must be called before rfkill_register(). +*/ +void rfkill_has_sw_block_memory (struct rfkill *rfkill); -struct device dev; -struct list_head node; -enum rfkill_state state_for_resume; -}; -#define to_rfkill (d) container_of(d, struct rfkill, dev) +/** +* rfkill_set_led_trigger_name -- set the LED trigger name +* @rfkill: rfkill struct +* @name: LED trigger name +* +* This function sets the LED trigger name of the radio LED +* trigger that rfkill creates. It is optional, but if called +* must be called before rfkill_register() to be effective. +*/ +void rfkill_set_led_trigger_name (struct rfkill *rfkill,const char *name); -struct rfkill *__must_check rfkill_allocate (struct device *parent, -enum rfkill_type type); -void rfkill_free (struct rfkill *rfkill); +/** +* rfkill_register - Register a rfkill structure. +* @rfkill: rfkill structure to be registered +* +* This function should be called by the transmitter driver to register +* the rfkill structure needs to be registered. Before calling this function +* the driver needs to be ready to service method calls from rfkill. +*/ int __must_check rfkill_register (struct rfkill *rfkill); + +/** +* rfkill_pause_polling(struct rfkill *rfkill) +* +* Pause polling -- say transmitter is off for other reasons. +* NOTE: not necessary for suspend/resume -- in that case the +* core stops polling anyway +*/ +void rfkill_pause_polling (struct rfkill *rfkill); + +/** +* rfkill_resume_polling(struct rfkill *rfkill) +* +* Pause polling -- say transmitter is off for other reasons. +* NOTE: not necessary for suspend/resume -- in that case the +* core stops polling anyway +*/ +void rfkill_resume_polling (struct rfkill *rfkill); + + +/** +* rfkill_unregister - Unregister a rfkill structure. +* @rfkill: rfkill structure to be unregistered +* +* This function should be called by the network driver during device +* teardown to destroy rfkill structure. Until it returns, the driver +* needs to be able to service method calls. +*/ void rfkill_unregister (struct rfkill *rfkill); -int rfkill_force_state (struct rfkill *rfkill,enum rfkill_state state); -int rfkill_set_default (enum rfkill_type type,enum rfkill_state state); +/** +* rfkill_destroy - free rfkill structure +* @rfkill: rfkill structure to be destroyed +* +* Destroys the rfkill structure. +*/ +void rfkill_destroy (struct rfkill *rfkill);/** -* rfkill_state_complement - return complementar state -* @state: state to return the complement of +* rfkill_set_hw_state - Set the internal rfkill hardware block state +* @rfkill: pointer to the rfkill class to modify. +* @state: the current hardware block state to set +* +* rfkill drivers that get events when the hard-blocked state changes +* use this function to notify the rfkill core (and through that also +* userspace) of the current state -- they should also use this after +* resume if the state could have changed. +* +* You need not (but may) call this function if poll_state is assigned. +* +* This function can be called in any context. * -* Returns RFKILL_STATE_SOFT_BLOCKED if @state is RFKILL_STATE_UNBLOCKED, -* returns RFKILL_STATE_UNBLOCKED otherwise. +* The function returns the combined block state (true if transmitter +* should be blocked) so that drivers need not keep track of the soft +* block state -- which they might not be able to. +* +* If the device is able to, call rfkill_has_sw_block_memory() and +* ignore the return value of this function. */ -static inline enum rfkill_state rfkill_state_complement (enum rfkill_state state) +bool rfkill_set_hw_state (struct rfkill *rfkill,bool blocked); + +/** +* rfkill_set_sw_state - Set the internal rfkill software block state +* @rfkill: pointer to the rfkill class to modify. +* @state: the current software block state to set +* +* rfkill drivers that get events when the soft-blocked state changes +* (yes, some platforms directly act on input but allow changing again) +* use this function to notify the rfkill core (and through that also +* userspace) of the current state -- they should also use this after +* resume if the state could have changed. +* +* This function can be called in any context. +* +* The function returns the combined block state (true if transmitter +* should be blocked). +*/ +bool rfkill_set_sw_state (struct rfkill *rfkill,bool blocked); + +/** +* rfkill_set_global_sw_state - set global sw block default +* @type: rfkill type to set default for +* @blocked: default to set +* +* This function sets the global default -- use at boot if your platform has +* an rfkill switch. If not early enough this call may be ignored. +* +* XXX: instead of ignoring -- how about just updating all currently +* registered drivers? +*/ +void rfkill_set_global_sw_state (const enum rfkill_type type,bool blocked); +#else /* !RFKILL */ +static inline struct rfkill *__must_check +rfkill_alloc (const char *name, +struct device *parent, +const enum rfkill_type type, +const struct rfkill_ops *ops, +void *ops_data) +{ +return ERR_PTR (-ENODEV ); +} + +static inline void rfkill_has_sw_block_memory (struct rfkill *rfkill) +{ +} + +static inline int __must_check rfkill_register (struct rfkill *rfkill) +{ +if (rfkill ==ERR_PTR (-ENODEV )) +return 0 ; +return -EINVAL ; +} + +static inline void rfkill_pause_polling (struct rfkill *rfkill) +{ +} + +static inline void rfkill_resume_polling (struct rfkill *rfkill) +{ +} + +static inline void rfkill_unregister (struct rfkill *rfkill) +{ +} + +static inline void rfkill_destroy (struct rfkill *rfkill) { -return (state ==RFKILL_STATE_UNBLOCKED ) ? -RFKILL_STATE_SOFT_BLOCKED :RFKILL_STATE_UNBLOCKED ; } +static inline bool rfkill_set_hw_state (struct rfkill *rfkill,bool blocked) +{ +return blocked; +} + +static inline bool rfkill_set_sw_state (struct rfkill *rfkill,bool blocked) +{ +return blocked; +} + +static inline void rfkill_set_global_sw_state (const enum rfkill_type type, +bool blocked) +{ +} +#endif /* RFKILL || RFKILL_MODULE */ + + +#ifdef CONFIG_RFKILL_LEDS /** -* rfkill_get_led_name - Get the LED trigger name for the button's LED. +* rfkill_get_led_trigger_name - Get the LED trigger name for the button's LED. * This function might return a NULL pointer if registering of the -* LED trigger failed. -* Use this as "default_trigger" for the LED. +* LED trigger failed. Use this as "default_trigger" for the LED. */ -static inline char *rfkill_get_led_name (struct rfkill *rfkill) -{ -#ifdef CONFIG_RFKILL_LEDS -return (char *)(rfkill->led_trigger.name); +const char *rfkill_get_led_trigger_name (struct rfkill *rfkill); + +/** +* rfkill_set_led_trigger_name -- set the LED trigger name +* @rfkill: rfkill struct +* @name: LED trigger name +* +* This function sets the LED trigger name of the radio LED +* trigger that rfkill creates. It is optional, but if called +* must be called before rfkill_register() to be effective. +*/ +void rfkill_set_led_trigger_name (struct rfkill *rfkill,const char *name);#else +static inline const char *rfkill_get_led_trigger_name (struct rfkill *rfkill) +{return NULL ; -#endif } +void rfkill_set_led_trigger_name (struct rfkill *rfkill,const char *name) +{ +} +#endif + +#endif /* __KERNEL__ */ +#endif /* RFKILL_H */
drivers/net/wireless/ath9k/main.c +29 -86
169 lines not on this page · raw message
drivers/platform/x86/eeepc-laptop.c +22 -69
128 lines not on this page · raw message
net/rfkill/rfkill.c deleted +0 -843
843 lines not on this page · raw message
net/rfkill/rfkill-input.h deleted +0 -21
@@ -1,21 +0,0 @@ -/* -* Copyright (C) 2007 Ivo van Doorn -*/ - -/* -* This program is free software; you can redistribute it and/or modify it -* under the terms of the GNU General Public License version 2 as published -* by the Free Software Foundation. -*/ - -#ifndef __RFKILL_INPUT_H -#define __RFKILL_INPUT_H - -void rfkill_switch_all (enum rfkill_type type,enum rfkill_state state); -void rfkill_epo (void ); -void rfkill_restore_states (void ); -void rfkill_remove_epo_lock (void ); -bool rfkill_is_epo_lock_active (void ); -enum rfkill_state rfkill_get_global_state (const enum rfkill_type type); - -#endif /* __RFKILL_INPUT_H */
net/rfkill/rfkill-input.c deleted +0 -392
392 lines not on this page · raw message
drivers/net/wireless/b43/main.c +2 -2
@@ -3492,7 +3492,7 @@ static int b43_op_config(struct ieee8021if (!!conf->radio_enabled != phy->radio_on) {if (conf->radio_enabled) { -b43_software_rfkill (dev,RFKILL_STATE_UNBLOCKED ); +b43_software_rfkill (dev, false);b43info (dev->wl,"Radio turned on by software\n" );if (!dev->radio_hw_enable) { b43info(dev->wl, "The hardware RF-kill button "
@@ -3500,7 +3500,7 @@ static int b43_op_config(struct ieee8021 "Press the button to turn it on.\n"); } }else { -b43_software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); +b43_software_rfkill (dev, true);b43info (dev->wl,"Radio turned off by software\n" ); } }
drivers/net/wireless/b43/phy_a.c +2 -2
@@ -480,11 +480,11 @@ static bool b43_aphy_op_supports_hwpctl( }static void b43_aphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {struct b43_phy *phy = &dev->phy; -if (state ==RFKILL_STATE_UNBLOCKED ) { +if (!blocked) {if (phy->radio_on)return ;b43_radio_write16 (dev,0x0004 ,0x00C0 );
drivers/net/wireless/b43/phy_common.c +6 -11
@@ -84,7 +84,7 @@ int b43_phy_init(struct b43_wldev *dev) phy->channel = ops->get_default_chan (dev); - ops->software_rfkill (dev,RFKILL_STATE_UNBLOCKED ); + ops->software_rfkill (dev, false); err = ops->init (dev);if (err) {b43err (dev->wl,"PHY init failed\n" );
@@ -104,7 +104,7 @@ err_phy_exit:if (ops->exit) ops->exit (dev); err_block_rf: - ops->software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); + ops->software_rfkill (dev, true);return err; }
@@ -113,7 +113,7 @@ void b43_phy_exit(struct b43_wldev *dev) {const struct b43_phy_operations *ops = dev->phy.ops; - ops->software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); + ops->software_rfkill (dev, true);if (ops->exit) ops->exit (dev); }
@@ -287,18 +287,13 @@ err_restore_cookie:return err; } -void b43_software_rfkill (struct b43_wldev *dev,enum rfkill_state state) +void b43_software_rfkill (struct b43_wldev *dev,bool blocked) {struct b43_phy *phy = &dev->phy; -if (state ==RFKILL_STATE_HARD_BLOCKED ) { -/* We cannot hardware-block the device */ - state =RFKILL_STATE_SOFT_BLOCKED ; - } -b43_mac_suspend (dev); - phy->ops->software_rfkill (dev, state); - phy->radio_on = (state ==RFKILL_STATE_UNBLOCKED ); + phy->ops->software_rfkill (dev, blocked); + phy->radio_on = !blocked;b43_mac_enable (dev); }
drivers/net/wireless/b43/phy_common.h +2 -2
@@ -159,7 +159,7 @@ struct b43_phy_operations {/* Radio */ bool (*supports_hwpctl)(struct b43_wldev *dev); -void (*software_rfkill)(struct b43_wldev *dev,enum rfkill_state state); +void (*software_rfkill)(struct b43_wldev *dev,bool blocked);void (*switch_analog)(struct b43_wldev *dev,bool on);int (*switch_channel)(struct b43_wldev *dev,unsigned int new_channel);unsigned int (*get_default_chan)(struct b43_wldev *dev);
@@ -362,7 +362,7 @@ int b43_switch_channel(struct b43_wldev/** * b43_software_rfkill - Turn the radio ON or OFF in software. */ -void b43_software_rfkill (struct b43_wldev *dev,enum rfkill_state state); +void b43_software_rfkill (struct b43_wldev *dev,bool blocked);/** * b43_phy_txpower_check - Check TX power output.
drivers/net/wireless/b43/phy_g.c +2 -2
@@ -2592,7 +2592,7 @@ static bool b43_gphy_op_supports_hwpctl( }static void b43_gphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {struct b43_phy *phy = &dev->phy;struct b43_phy_g *gphy = phy->g;
@@ -2600,7 +2600,7 @@ static void b43_gphy_op_software_rfkill(might_sleep (); -if (state ==RFKILL_STATE_UNBLOCKED ) { +if (!blocked) {/* Turn radio ON */ if (phy->radio_on)return ;
drivers/net/wireless/b43/phy_n.c +1 -1
@@ -579,7 +579,7 @@ static void b43_nphy_op_radio_write(stru }static void b43_nphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {//TODO }
drivers/net/wireless/b43/rfkill.c +33 -89
190 lines not on this page · raw message
drivers/net/wireless/b43legacy/rfkill.c +34 -84
190 lines not on this page · raw message
drivers/net/wireless/iwlwifi/iwl-rfkill.c +28 -41
124 lines not on this page · raw message
Documentation/rfkill.txt +100 -539
452 lines not on this page · raw message
net/rfkill/Kconfig +0 -14
Lines of this file are not shown. View the raw message.
net/rfkill/Makefile +2 -2
Lines of this file are not shown. View the raw message.
net/rfkill/core.c new file +780 -0
780 lines not on this page · raw message
net/rfkill/input.c new file +342 -0
342 lines not on this page · raw message
net/rfkill/rfkill.h new file +27 -0
Lines of this file are not shown. View the raw message.
MAINTAINERS +3 -3
Lines of this file are not shown. View the raw message.
include/linux/Kbuild +1 -0
Lines of this file are not shown. View the raw message.
drivers/net/wireless/ath9k/ath9k.h +1 -6
Lines of this file are not shown. View the raw message.
drivers/net/wireless/ath9k/pci.c +0 -15
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/Kconfig +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/rfkill.h +1 -4
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/Kconfig +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/leds.c +2 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/rfkill.h +1 -5
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/leds.c +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/iwlwifi/Kconfig +2 -3
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/phy_lp.c +1 -1
Lines of this file are not shown. View the raw message.
drivers/platform/x86/Kconfig +0 -6
Lines of this file are not shown. View the raw message.
drivers/platform/x86/acer-wmi.c +22 -28
50 lines not on this page · raw message
drivers/platform/x86/dell-laptop.c +33 -68
101 lines not on this page · raw message
drivers/platform/x86/hp-wmi.c +52 -51
103 lines not on this page · raw message
drivers/platform/x86/toshiba_acpi.c +7 -16
Lines of this file are not shown. View the raw message.
arch/arm/mach-pxa/tosa-bt.c +15 -15
Lines of this file are not shown. View the raw message.
arch/arm/mach-pxa/tosa.c +0 -1
Lines of this file are not shown. View the raw message.
include/net/wimax.h +2 -6
Lines of this file are not shown. View the raw message.
net/wimax/op-rfkill.c +28 -97
125 lines not on this page · raw message
net/wimax/Kconfig +0 -14
Lines of this file are not shown. View the raw message.
drivers/net/usb/hso.c +22 -20
42 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Quoted 3 lines · Henrique de Moraes Holschuh
So, far, it looks quite good. A few initial comments that I want to get out ASAP (I am bound to have many more after I take a first try at convert thinkpad-acpi to the new API).
And it would have been better if I had looked at it for an extra five minutes :-(
Quoted 10 lines
Quoted 10 lines
+ * @poll_hw_block: poll the rfkill hardware block state (return true
+ * for blocked) -- only assign this method when you cannot
+ * do without polling
+ * @query_state: query the rfkill hardware block state (return true
+ * for blocked) -- assign this method if software events might
+ * cause hardware state changes
+ * @set_block: turn the transmitter on (blocked == false) or off
+ * (blocked == true) -- this is called only while the transmitter
+ * is not hard-blocked. This must be assigned.
+ */
Quoted 8 lines
include/linux/rfkill.h enum rfkill_type { · line 90
Quoted 6 lines
include/linux/rfkill.h +5
-0+struct rfkill_ops { +#if defined(CONFIG_RFKILL ) || defined(CONFIG_RFKILL_MODULE ) +bool (*poll_hw_block)(void *data); +bool (*query_state)(void *data); +void (*set_block)(void *data,bool blocked);#endif Missing error handling on
set_block... could you change that to:
And also on the rest of the hooks. I should have noticed it sooner!
As I said, ACPI platform drivers _do_ get errors when calling the ACPI functions, or trying to do an EC transaction. That applies to reads just as well as it applies to writes.
I.e. I can get AE_BUSY or something else while querying the thinkpad firmware, and then, what should I do to return the data on the query_state (and, for that matter, poll_hw_block) hooks?
Since there can be a clear error path from userspace to the rfkill driver for reads and writes in many situations (e.g. on all sysfs accesses to that driver's rfkill struct), this would be a good reason to change the hooks to allow for that error path.
There is a second reason as well to change it: the policy on what to do when the driver cannot query the up-to-date state of the rfkill controller should not be defined by the driver itself, it is best defined by the rfkill core so that all drivers behave the same.
Without that, I'd have, for example, to return false (unblocked) on any errors from thinkpad-acpi, for safety reasons (a blocked radio is never a hazard, but an unblocked one can be). This is the kind of stuff that a driver shouldn't need to decide by itself...
On a related note, it was not clear to me from looking only at rfkill.txt and the linux/rfkill.h headers, how am I supposed to deal with the software controlled component of the rfkill controller (the hardware rfkill line is quite obvious, though). I know there is a way, but I haven't finished reading the core code to know which one, and the docs didn't help, so they need an extra paragraph somewhere...
Anyway, I suggest changing the hook protypes to this (which does _NOT_ change the fact that you now track hw and sw separately in the core, but lets the rfkill driver deliver both in a single call if it needs to):
int (*poll_block_state)(void *data,
bool *is_sw_block_active, bool *is_hw_block_active); int (*query_block_state)(void *data, bool *is_sw_block_active, bool *is_hw_block_active);
int (*set_block_state)(void *data, bool do_sw_block);
With the following semanthics:
function return status: 0 if OK, <0 in case of error (i.e. standard error semanthics).
is_sw_block_active: leave untouched if there is no sw blocking support, otherwise change it to the up-to-date state of the sw blocking flag (true=blocked)
is_hw_block_active: leave untouched if there is no hw blocking, otherwise change it to the up-to-date state of the hw blocking flag (true=blocked)
The core should ignore the is_* stuff if an error status is returned, as a defensive approach against driver bugs: doing it that way is less programmer-error-prone than telling people to not touch is_* in case of an error.
do_sw_block: true if the driver should software block, false if it should attempt to software unblock.
BTW: it is probably a good idea to document what the driver should do if the core tries this on a radio that is hardware blocked, or if the driver discovers the radio is hardware blocked the instant it tries to software unblock it...
It would be nice to have the core export a way to "force" both sw and hw states at once, as well. This lets the core optimize the issuing of events and other internal changes and avoids bad mojo if the driver does sw/hw force calls in the wrong order (which might cause a unblock-block fast sequence, etc).
This would let drivers that have the worst case software blocking (it exists, hw blocking also exists and is separate, and both sw and hw blocking state could change behind the driver's back) work well, without causing any extra complexity to the other drivers.
IF you don't want the hooks to return both sw and hw states, you can just change the return type from bool to int, and explicitly document tha the return status is:
status < 0: error
status = 0: false, implies no error
status > 0: true, implies no error
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Johannes Berg
maintainerHi!
Quoted 9 lines
Quoted 8 lines
include/linux/rfkill.h enum rfkill_type { · line 90
Quoted 6 lines
include/linux/rfkill.h +5
-0+struct rfkill_ops { +#if defined(CONFIG_RFKILL ) || defined(CONFIG_RFKILL_MODULE ) +bool (*poll_hw_block)(void *data); +bool (*query_state)(void *data); +void (*set_block)(void *data,bool blocked);#endif Missing error handling on
set_block... could you change that to:
Quoted 5 lines
And also on the rest of the hooks. I should have noticed it sooner!
As I said, ACPI platform drivers _do_ get errors when calling the ACPI functions, or trying to do an EC transaction. That applies to reads just as well as it applies to writes.
And it also doesn't really matter. Yes, the current poll API isn't prepared to treat errors, but see below for a suggestion.
Quoted 8 lines
I.e. I can get
AE_BUSYor something else while querying the thinkpad firmware, and then, what should I do to return the data on thequery_state(and, for that matter,poll_hw_block) hooks?Since there can be a clear error path from userspace to the rfkill driver for reads and writes in many situations (e.g. on all sysfs accesses to that driver's rfkill struct), this would be a good reason to change the hooks to allow for that error path.
Totally bogus argument -- 99.9% of users will be using rfkill's input handler which has no way of reacting to errors, and neither does userspace. And it's wrong too -- the sysfs files don't actually call into rfkill, they just report the current status.
Quoted 4 lines
Without that, I'd have, for example, to return false (unblocked) on any errors from thinkpad-acpi, for safety reasons (a blocked radio is never a hazard, but an unblocked one can be). This is the kind of stuff that a driver shouldn't need to decide by itself...
Eh? Your first half sentence is correct (up to "on any errors"), the rest is garbage. Yes, you'd have to return false so that the core assumes it can do something, but no, it has nothing to do with hazards.
Quoted 6 lines
On a related note, it was not clear to me from looking only at rfkill.txt and the
linux/rfkill.hheaders, how am I supposed to deal with the software controlled component of the rfkill controller (the hardware rfkill line is quite obvious, though). I know there is a way, but I haven't finished reading the core code to know which one, and the docs didn't help, so they need an extra paragraph somewhere...
There's a function for that -- but no poll yet.
Quoted 11 lines
Anyway, I suggest changing the hook protypes to this (which does _NOT_ change the fact that you now track hw and sw separately in the core, but lets the rfkill driver deliver both in a single call if it needs to):
int (*poll_block_state)(void *data,
bool *is_sw_block_active, bool *is_hw_block_active); int (*query_block_state)(void *data, bool *is_sw_block_active, bool *is_hw_block_active);int (*set_block_state)(void *data, bool
do_sw_block);
No way.
I can be convinced to change the prototype of poll_hw_block to
void (*poll_hw_block)(void *data, bool *blocked);
so that drivers can say
"*shrug*, I dunno right now, keep whatever I told you last".
Returning an error, however, is completely pointless.
Quoted 4 lines
The core should ignore the is_* stuff if an error status is returned, as a defensive approach against driver bugs: doing it that way is less programmer-error-prone than telling people to not touch is_* in case of an error.
Bugs happen, and can be fixed; your defensive programming mantra just makes for messy code that has multiple ways of working "correctly". I quite obviously disagree -- if you can't read the status don't touch the variables.
Quoted 4 lines
BTW: it is probably a good idea to document what the driver should do if the core tries this on a radio that is hardware blocked, or if the driver discovers the radio is hardware blocked the instant it tries to software unblock it...
The first case doesn't happen... And it says so in the header file:
* @set_block: turn the transmitter on (blocked == false) or off
* (blocked == true) -- this is called only while the transmitter
* is not hard-blocked. This must be assigned.
The second case _shouldn't_ happen (but can, due to race conditions); Then you just call set_hw_state before returning.
The third case, which you forgot, works the same as the second and needs no extra code either.
Quoted 10 lines
It would be nice to have the core export a way to "force" both sw and hw states at once, as well. This lets the core optimize the issuing of events and other internal changes and avoids bad mojo if the driver does sw/hw force calls in the wrong order (which might cause a unblock-block fast sequence, etc).
This would let drivers that have the worst case software blocking (it exists, hw blocking also exists and is separate, and both sw and hw blocking state could change behind the driver's back) work well, without causing any extra complexity to the other drivers.
There may be some value in that, do you need polling for both though? Otherwise you'd need
if (hw_blocked)
set_hw_state(hw_blocked) set_sw_state(sw_blocked)
else
set_sw_state(sw_blocked) set_hw_state(hw_blocked)
in the driver which I agree isn't nice and would be better with a combined function.
Quoted 7 lines
IF you don't want the hooks to return both sw and hw states, you can just change the return type from bool to int, and explicitly document tha the return status is:
status < 0: error
status = 0: false, implies no error
status > 0: true, implies no error
Ick.
If you really do need polling for the sw state as well as the hw state, I can be convinced to change poll_hw_block to
void (*poll_block)(void *data, bool *hw_blocked, bool *sw_blocked);
You need much better reasons, however, to convince me to add any error return, I see absolutely no value in that. Neither rfkill's input handler nor the polling nor userspace has any means to react to errors.
johannes
Quoted 6 lines · Johannes Berg
Quoted 3 lines
As I said, ACPI platform drivers _do_ get errors when calling the ACPI functions, or trying to do an EC transaction. That applies to reads just as well as it applies to writes.
And it also doesn't really matter. Yes, the current poll API isn't prepared to treat errors, but see below for a suggestion.
Ok. The older one allowed for it, so that's where the divergence lies.
Quoted 11 lines
Quoted 8 lines
I.e. I can get
AE_BUSYor something else while querying the thinkpad firmware, and then, what should I do to return the data on thequery_state(and, for that matter,poll_hw_block) hooks?Since there can be a clear error path from userspace to the rfkill driver for reads and writes in many situations (e.g. on all sysfs accesses to that driver's rfkill struct), this would be a good reason to change the hooks to allow for that error path.
Totally bogus argument -- 99.9% of users will be using rfkill's input handler which has no way of reacting to errors, and neither does
Well, network manager would be using sysfs, and that's something that can report errors properly to the user, if it gets them from the kernel. While I am happy with rfkill-input, I can easily imagine someone wanting to have all rfkill-related input events to go to network manager to get some unified GUI treatment there, and a proper error path would be nice to have in that case.
Quoted 2 lines
userspace. And it's wrong too -- the sysfs files don't actually call into rfkill, they just report the current status.
Indeed, I just looked at the code. I don't know why I had this wrong recollection that I had added a proper error path there.
Well, I'd still prefer the API to have the error return, and if the core doesn't have much use for it, it can consume it. Fixing the core later to propagate errors back to userspace if needed would be much easier than fixing all users of the API.
Quoted 8 lines
Quoted 4 lines
Without that, I'd have, for example, to return false (unblocked) on any errors from thinkpad-acpi, for safety reasons (a blocked radio is never a hazard, but an unblocked one can be). This is the kind of stuff that a driver shouldn't need to decide by itself...
Eh? Your first half sentence is correct (up to "on any errors"), the rest is garbage. Yes, you'd have to return false so that the core assumes it can do something, but no, it has nothing to do with hazards.
Hmm? Yes, it does. The choice to return false (transmiter is not blocked) when you don't know jack about its state is rooted to the fact that you cannot tell the user (or the system) that a transmitter is 'secured' (i.e. blocked) when it is not, while the opposite is not that bad.
The reason is the same reason why one _cannot_ implement the rfkill class in hardware that doesn't give guarantees that the transmission will be blocked from emmiting energy.
And all of this happens because a transmitter emitting energy at the wrong place and time can cause problems. Immediate examples are: undue interference to sensitive equipment and sensor arrays, safety hazards (unblock a laser while someone is cleaning the lens, unblock a microwave radio when someone is in direct contact with the antenna), lightning, fire and explosion hazard (emitting microwaves in highly explosive atmosphere or in a highly 'charged' environment is not very safe), etc. Yes, it _is_ far-fetched, but that's what is behind the regulations that brought rfkill to life.
I know (now) that the old core was consuming the error status instead of passing it through -- I wasn't aware of it anymore or I'd have tried to fix it (and it _is_ probable that I was the one that wrecked it to begin with).
If the 'return it is unblocked in case of doubt' also happens to be a better choice for other reasons, that's good.
Anyway, please document that in case of errors one is to return "false" in the kerneldoc if you won't add the error status to the API.
Quoted 8 lines
Quoted 6 lines
On a related note, it was not clear to me from looking only at rfkill.txt and the
linux/rfkill.hheaders, how am I supposed to deal with the software controlled component of the rfkill controller (the hardware rfkill line is quite obvious, though). I know there is a way, but I haven't finished reading the core code to know which one, and the docs didn't help, so they need an extra paragraph somewhere...There's a function for that -- but no poll yet.
I don't really need a poll function for thinkpad-acpi (I get events), but see below.
Quoted 7 lines
I can be convinced to change the prototype of
poll_hw_blocktovoid (*poll_hw_block)(void *data, bool *blocked);so that drivers can say
"*shrug*, I dunno right now, keep whatever I told you last".
Returning an error, however, is completely pointless.
See my arguments above about why I like the error status in the hook API. I think we will just have to agree to disagree on that.
And I don't personally care much about the constant poll hook (poll_*), just about the opportunistic poll hook (get_status), and the hook to set radio state.
Quoted 4 lines
Bugs happen, and can be fixed; your defensive programming mantra just makes for messy code that has multiple ways of working "correctly". I quite obviously disagree -- if you can't read the status don't touch the variables.
I am fine with that, I know *I* do read the kerneldoc entries for everything I use, and often I look at the code too, since one cannot trust kerneldoc entries too much.
Still, I just ask that you document these requirements explicitly in the kerneldoc entry for the hooks, as well as the expected behaviour the hooks should take on error conditions ("return false", "don't touch the state", whatever).
Quoted 5 lines
Quoted 4 lines
BTW: it is probably a good idea to document what the driver should do if the core tries this on a radio that is hardware blocked, or if the driver discovers the radio is hardware blocked the instant it tries to software unblock it...
Quoted 8 lines
The first case doesn't happen... And it says so in the header file:
* @set_block: turn the transmitter on (blocked == false) or off
* (blocked == true) -- this is called only while the transmitter
* is not hard-blocked. This must be assigned.The second case _shouldn't_ happen (but can, due to race conditions); Then you just call
set_hw_statebefore returning.
That is the sort of stuff that belongs in a doc somewhere for sure, although one could infer it since the set_hw_state function makes it clear that it can be called from anywhere, anytime... but it is not obvious.
Quoted 2 lines
The third case, which you forgot, works the same as the second and needs no extra code either.
Ok.
Quoted 11 lines
Quoted 10 lines
It would be nice to have the core export a way to "force" both sw and hw states at once, as well. This lets the core optimize the issuing of events and other internal changes and avoids bad mojo if the driver does sw/hw force calls in the wrong order (which might cause a unblock-block fast sequence, etc).
This would let drivers that have the worst case software blocking (it exists, hw blocking also exists and is separate, and both sw and hw blocking state could change behind the driver's back) work well, without causing any extra complexity to the other drivers.
Quoted 8 lines
There may be some value in that, do you need polling for both though? Otherwise you'd need
if (hw_blocked)
set_hw_state(hw_blocked)set_sw_state(sw_blocked)
else
set_sw_state(sw_blocked)set_hw_state(hw_blocked)
Well, *I* have full events, so I can disable polling altoghether, and do the above.
However, I liked the old rfkill core 'opportunistic polling' through the get_state hook, which the new core could also do, because it GREATLY reduced the time window where a state could be wrong because of some sort of misdelivery of events (you can NEVER trust ACPI-based crap too much).
And to use the opportunistic pooling, I'd need to be able to return both states, so I'd need the query_state hook to let me return both states at once.
So, I'd really appreciate a "void get_state(void *data, bool *sw, bool *hw)" hook (since you won't give me error status).
Or maybe even change the get_state and poll_hw hooks to a "void (hook)(void *data)" thing, where the driver is expected to use set_hw_state and friends to do the update instead of returning values.
As for the small code snippet above, I ask that you add a set_hw_sw_state() function. It would make my life as a driver writer easier, it would be simpler to understand, and it would give the rfkill core better optimization oportunities to avoid transient spurious blocks/unblocks.
Quoted 4 lines
If you really do need polling for the sw state as well as the hw state, I can be convinced to change
poll_hw_blocktovoid (*poll_block)(void *data, bool *hw_blocked, bool *sw_blocked);
Do that to get_state() as well, and give me set_hw_sw_state(bool sw, bool hw), and we have a deal.
Or change the poll and get_state hooks to void (*hook)(void *data), and give us set_hw_state, set_sw_state and set_hw_sw_state functions to call. I find this to be easier to use, but either choice would make me happy.
Quoted 3 lines
You need much better reasons, however, to convince me to add any error return, I see absolutely no value in that. Neither rfkill's input handler nor the polling nor userspace has any means to react to errors.
Userspace can react to errors, by notifying the user. rfkill-input can't do anything right now, but we COULD (if the userspace people wanted) issue uevents to get notifications sent to the user. My point is that we can certainly propagate the errors to someone who could do something about it if we wanted, as long as we have the errors to propagate.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Johannes Berg
maintainerHi,
Alright, finally got some spare cycles.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
I.e. I can get
AE_BUSYor something else while querying the thinkpad firmware, and then, what should I do to return the data on thequery_state(and, for that matter,poll_hw_block) hooks?Since there can be a clear error path from userspace to the rfkill driver for reads and writes in many situations (e.g. on all sysfs accesses to that driver's rfkill struct), this would be a good reason to change the hooks to allow for that error path.
Quoted 5 lines
Quoted 2 lines
Totally bogus argument -- 99.9% of users will be using rfkill's input handler which has no way of reacting to errors, and neither does
Well, network manager would be using sysfs, and that's something that can report errors properly to the user, if it gets them from the kernel.
Actually, no. I removed actually polling the rfkill driver on sysfs accesses -- and that was intentional. If we keep that we get into strange situations like a sysfs read can causing a uevent, or having some userspace app poll the sysfs file because the kernel polling isn't working properly or ...
Quoted 5 lines
Quoted 2 lines
userspace. And it's wrong too -- the sysfs files don't actually call into rfkill, they just report the current status.
Indeed, I just looked at the code. I don't know why I had this wrong recollection that I had added a proper error path there.
You might have had that and I removed it? Anyway, I think it's bad, see above.
Quoted 4 lines
[snip]
Yes, it _is_
far-fetched, but that's what is behind the regulations that brought rfkill to life.
Alright, I see where you're coming from -- I still think we shouldn't treat rfkill as a "nuclear power plant" control but rather as a "don't want wireless" control -- your opinion clearly differs.
Quoted 2 lines
Anyway, please document that in case of errors one is to return "false" in the kerneldoc if you won't add the error status to the API.
I'm now convinced we should just treat errors as transient and allow poll to say "no state change". If there is a possibility that there are errors that don't go away (are not transient) then the driver should probably just unregister the rfkill.
Quoted 8 lines
Quoted 7 lines
I can be convinced to change the prototype of
poll_hw_blocktovoid (*poll_hw_block)(void *data, bool *blocked);so that drivers can say
"*shrug*, I dunno right now, keep whatever I told you last".
Returning an error, however, is completely pointless.
Quoted 6 lines
See my arguments above about why I like the error status in the hook API. I think we will just have to agree to disagree on that.
And I don't personally care much about the constant poll hook (poll_*), just about the opportunistic poll hook (
get_status), and the hook to set radio state.
Mind you, the get_status() hook changed semantics and was renamed to query_hw_block(); you used to call it in sysfs and some other places I think, I now only call it for the weird case where an input button can cause an rfkill status update... Only Dell does that weird thing afaict.
Quoted 4 lines
Still, I just ask that you document these requirements explicitly in the kerneldoc entry for the hooks, as well as the expected behaviour the hooks should take on error conditions ("return false", "don't touch the state", whatever).
Will do.
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
BTW: it is probably a good idea to document what the driver should do if the core tries this on a radio that is hardware blocked, or if the driver discovers the radio is hardware blocked the instant it tries to software unblock it...
The first case doesn't happen... And it says so in the header file:
* @set_block: turn the transmitter on (blocked == false) or off
* (blocked == true) -- this is called only while the transmitter
* is not hard-blocked. This must be assigned.
Quoted 6 lines
Quoted 2 lines
The second case _shouldn't_ happen (but can, due to race conditions); Then you just call
set_hw_statebefore returning.That is the sort of stuff that belongs in a doc somewhere for sure, although one could infer it since the
set_hw_statefunction makes it clear that it can be called from anywhere, anytime... but it is not obvious.
I'll add a note.
Quoted 20 lines
Quoted 11 lines
Quoted 10 lines
It would be nice to have the core export a way to "force" both sw and hw states at once, as well. This lets the core optimize the issuing of events and other internal changes and avoids bad mojo if the driver does sw/hw force calls in the wrong order (which might cause a unblock-block fast sequence, etc).
This would let drivers that have the worst case software blocking (it exists, hw blocking also exists and is separate, and both sw and hw blocking state could change behind the driver's back) work well, without causing any extra complexity to the other drivers.
Quoted 8 lines
There may be some value in that, do you need polling for both though? Otherwise you'd need
if (hw_blocked)
set_hw_state(hw_blocked)set_sw_state(sw_blocked)
else
set_sw_state(sw_blocked)set_hw_state(hw_blocked)
Quoted 2 lines
Well, *I* have full events, so I can disable polling altoghether, and do the above.
I'll allow you to merge it into set_state(hw, sw) though, I think.
Quoted 9 lines
However, I liked the old rfkill core 'opportunistic polling' through the
get_statehook, which the new core could also do, because it GREATLY reduced the time window where a state could be wrong because of some sort of misdelivery of events (you can NEVER trust ACPI-based crap too much).And to use the opportunistic pooling, I'd need to be able to return both states, so I'd need the
query_statehook to let me return both states at once.
Quoted 6 lines
So, I'd really appreciate a "void
get_state(void *data, bool *sw, bool *hw)" hook (since you won't give me error status).Or maybe even change the
get_stateandpoll_hwhooks to a "void (hook)(void *data)" thing, where the driver is expected to useset_hw_stateand friends to do the update instead of returning values.
Indeed, that would work as well and would simplify the API.
Can you explain how such a query method can reduce the time window of a wrong state though? I honestly don't understand that.
Quoted 5 lines
As for the small code snippet above, I ask that you add a
set_hw_sw_state()function. It would make my life as a driver writer easier, it would be simpler to understand, and it would give the rfkill core better optimization oportunities to avoid transient spurious blocks/unblocks.
Yeah, will do.
Quoted 11 lines
Quoted 4 lines
If you really do need polling for the sw state as well as the hw state, I can be convinced to change
poll_hw_blocktovoid (*poll_block)(void *data, bool *hw_blocked, bool *sw_blocked);Do that to
get_state()as well, and give meset_hw_sw_state(bool sw, bool hw), and we have a deal.Or change the poll and
get_statehooks to void (*hook)(void *data), and give usset_hw_state,set_sw_stateandset_hw_sw_statefunctions to call. I find this to be easier to use, but either choice would make me happy.
I agree, removing the arguments seems simpler.
Quoted 9 lines
Quoted 3 lines
You need much better reasons, however, to convince me to add any error return, I see absolutely no value in that. Neither rfkill's input handler nor the polling nor userspace has any means to react to errors.
Userspace can react to errors, by notifying the user. rfkill-input can't do anything right now, but we COULD (if the userspace people wanted) issue uevents to get notifications sent to the user. My point is that we can certainly propagate the errors to someone who could do something about it if we wanted, as long as we have the errors to propagate.
Sure, and then when the user was notified how can the user react? Either the error is transient, in which case the user can only try again (but why don't we program it to do that then?), or the error is permanent in which case the user cannot do anything either. So what gives?
johannes
Johannes Berg
maintainerRFC v5 1/1 rfkill: rewrite
In reply to Johannes BergThis patch completely rewrites the rfkill core to address the following deficiencies:
* all rfkill drivers need to implement polling where necessary rather than having one central implementation
* updating the rfkill state cannot be done from arbitrary contexts, forcing drivers to use schedule_work and requiring lots of code
* rfkill drivers need to keep track of soft/hard blocked internally -- the core should do this
* the rfkill API has many unexpected quirks, for example being asymmetric wrt. alloc/free and register/unregister
* rfkill can call back into a driver from within a function the driver called -- this is prone to deadlocks and generally should be avoided
* rfkill-input pointlessly is a separate module
* drivers need to #ifdef rfkill functions (unless they want to depend on or select RFKILL) -- rfkill should provide inlines that do nothing if it isn't compiled in
* the rfkill structure is not opaque -- drivers need to initialise it correctly (lots of sanity checking code required) -- instead force drivers to pass the right variables to rfkill_alloc()
* the documentation is hard to read because it always assumes the reader is completely clueless and contains way TOO MANY CAPS
* the rfkill code needlessly uses a lot of locks and atomic operations in locked sections
* fix LED trigger to actually change the LED when the radio state changes -- this wasn't done before
---
v3: * fix locking bugs
* fix bug in input.c that made it ignore things
* allow setting LED trigger name
* apply default state while registering
* convert HSO
v4: * LED triggering
v5: * convert sony
* introduce rfkill_set_states function
* change query/poll methods to require calls to rfkill_set{_sw,_hw}_state/rfkill_set_states
* do not call driver from registration
* remove tested-by since it changed a lot...
TODO
* convert toshiba, thinkpad
Documentation/rfkill.txt | 639 +++------------------- MAINTAINERS | 6 arch/arm/mach-pxa/tosa-bt.c | 30 - arch/arm/mach-pxa/tosa.c | 1 drivers/net/usb/hso.c | 42 - drivers/net/wireless/ath/ath9k/ath9k.h | 7 drivers/net/wireless/ath/ath9k/main.c | 115 +--- drivers/net/wireless/ath/ath9k/pci.c | 15 drivers/net/wireless/b43/Kconfig | 2 drivers/net/wireless/b43/leds.c | 2 drivers/net/wireless/b43/main.c | 4 drivers/net/wireless/b43/phy_a.c | 4 drivers/net/wireless/b43/phy_common.c | 17 drivers/net/wireless/b43/phy_common.h | 4 drivers/net/wireless/b43/phy_g.c | 4 drivers/net/wireless/b43/phy_lp.c | 2 drivers/net/wireless/b43/phy_n.c | 2 drivers/net/wireless/b43/rfkill.c | 123 +--- drivers/net/wireless/b43/rfkill.h | 5 drivers/net/wireless/b43legacy/Kconfig | 2 drivers/net/wireless/b43legacy/leds.c | 3 drivers/net/wireless/b43legacy/rfkill.c | 123 +--- drivers/net/wireless/b43legacy/rfkill.h | 6 drivers/net/wireless/iwlwifi/Kconfig | 5 drivers/net/wireless/iwlwifi/iwl-rfkill.c | 69 -- drivers/platform/x86/Kconfig | 6 drivers/platform/x86/acer-wmi.c | 50 - drivers/platform/x86/dell-laptop.c | 101 +-- drivers/platform/x86/eeepc-laptop.c | 91 --- drivers/platform/x86/hp-wmi.c | 103 +-- drivers/platform/x86/sony-laptop.c | 115 ++-- drivers/platform/x86/toshiba_acpi.c | 23 include/linux/Kbuild | 1 include/linux/rfkill.h | 344 +++++++++--- include/net/wimax.h | 8 net/rfkill/Kconfig | 14 net/rfkill/Makefile | 4 net/rfkill/core.c | 837 +++++++++++++++++++++++++++++ net/rfkill/input.c | 342 ++++++++++++ net/rfkill/rfkill-input.c | 390 ------------- net/rfkill/rfkill-input.h | 21 net/rfkill/rfkill.c | 843 ------------------------------ net/rfkill/rfkill.h | 27 net/wimax/Kconfig | 14 net/wimax/op-rfkill.c | 125 ---- 45 files changed, 1999 insertions(+), 2692 deletions(-)
include/linux/rfkill.h +271 -73
@@ -4,6 +4,7 @@/* * Copyright (C) 2006 - 2007 Ivo van Doorn * Copyright (C) 2007 Dmitry Torokhov +* Copyright 2009 Johannes Berg <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -21,6 +22,24 @@* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* define userspace visible states */ +#define RFKILL_STATE_SOFT_BLOCKED 0 +#define RFKILL_STATE_UNBLOCKED 1 +#define RFKILL_STATE_HARD_BLOCKED 2 + +/* and that's all userspace gets */ +#ifdef __KERNEL__ +/* don't allow anyone to use these in the kernel */ +enum rfkill_user_states { +RFKILL_USER_STATE_SOFT_BLOCKED =RFKILL_STATE_SOFT_BLOCKED , +RFKILL_USER_STATE_UNBLOCKED =RFKILL_STATE_UNBLOCKED , +RFKILL_USER_STATE_HARD_BLOCKED =RFKILL_STATE_HARD_BLOCKED , +}; +#undef RFKILL_STATE_SOFT_BLOCKED +#undef RFKILL_STATE_UNBLOCKED +#undef RFKILL_STATE_HARD_BLOCKED +#include <linux/types.h> #include <linux/kernel.h> #include <linux/list.h>
@@ -30,11 +49,13 @@/** * enum rfkill_type - type of rfkill switch. -* RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. -* RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. -* RFKILL_TYPE_UWB: switch is on a ultra wideband device. -* RFKILL_TYPE_WIMAX: switch is on a WiMAX device. -* RFKILL_TYPE_WWAN: switch is on a wireless WAN device. +* +* @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. +* @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. +* @RFKILL_TYPE_UWB: switch is on a ultra wideband device. +* @RFKILL_TYPE_WIMAX: switch is on a WiMAX device. +* @RFKILL_TYPE_WWAN: switch is on a wireless WAN device. +* @NUM_RFKILL_TYPES: number of defined rfkill types */ enum rfkill_type {RFKILL_TYPE_WLAN ,
@@ -42,97 +63,274 @@ enum rfkill_type {RFKILL_TYPE_UWB ,RFKILL_TYPE_WIMAX ,RFKILL_TYPE_WWAN , - RFKILL_TYPE_MAX, + NUM_RFKILL_TYPES, }; -enum rfkill_state { -RFKILL_STATE_SOFT_BLOCKED =0 ,/* Radio output blocked */ -RFKILL_STATE_UNBLOCKED =1 ,/* Radio output allowed */ -RFKILL_STATE_HARD_BLOCKED =2 ,/* Output blocked, non-overrideable */ -RFKILL_STATE_MAX ,/* marker for last valid state */ +/* this is opaque */ +struct rfkill ; + +/** +* struct rfkill_ops - rfkill driver methods +* +* @poll: poll the rfkill block state(s) -- only assign this method +* when you need polling. When called, simply call one of the +* rfkill_set{,_hw,_sw}_state family of functions. If the hw +* is getting unblocked you need to take into account the return +* value of those functions to make sure the software block is +* properly used. +* @query: query the rfkill hardware block state (return true +* for blocked) -- assign this method if input events can cause +* hardware state changes to make the rfkill core query your +* driver before setting a requested block +* @set_block: turn the transmitter on (blocked == false) or off +* (blocked == true) -- this is called only while the transmitter +* is not hard-blocked. This must be assigned. +*/ +struct rfkill_ops { +void (*poll)(struct rfkill *rfkill,void *data); +void (*query)(struct rfkill *rfkill,void *data); +int (*set_block)(void *data,bool blocked); }; +#if defined(CONFIG_RFKILL ) || defined(CONFIG_RFKILL_MODULE )/** -* struct rfkill - rfkill control structure. -* @name: Name of the switch. -* @type: Radio type which the button controls, the value stored -* here should be a value from enum rfkill_type. -* @state: State of the switch, "UNBLOCKED" means radio can operate. -* @mutex: Guards switch state transitions. It serializes callbacks -* and also protects the state. -* @data: Pointer to the RF button drivers private data which will be -* passed along when toggling radio state. -* @toggle_radio(): Mandatory handler to control state of the radio. -* only RFKILL_STATE_SOFT_BLOCKED and RFKILL_STATE_UNBLOCKED are -* valid parameters. -* @get_state(): handler to read current radio state from hardware, -* may be called from atomic context, should return 0 on success. -* Either this handler OR judicious use of rfkill_force_state() is -* MANDATORY for any driver capable of RFKILL_STATE_HARD_BLOCKED. -* @led_trigger: A LED trigger for this button's LED. -* @dev: Device structure integrating the switch into device tree. -* @node: Used to place switch into list of all switches known to the -* the system. -* -* This structure represents a RF switch located on a network device. -*/ -struct rfkill { -const char *name; -enum rfkill_type type; - -/* the mutex serializes callbacks and also protects -* the state */ -struct mutex mutex; -enum rfkill_state state; -void *data; -int (*toggle_radio)(void *data,enum rfkill_state state); -int (*get_state)(void *data,enum rfkill_state *state); +* rfkill_alloc - allocate rfkill structure +* @name: name of the struct -- the string is not copied internally +* @parent: device that has rf switch on it +* @type: type of the switch (RFKILL_TYPE_*) +* @ops: rfkill methods +* @ops_data: data passed to each method +* +* This function should be called by the transmitter driver to allocate an +* rfkill structure. +*/ +struct rfkill *__must_check rfkill_alloc (const char *name, +struct device *parent, +const enum rfkill_type type, +const struct rfkill_ops *ops, +void *ops_data); -#ifdef CONFIG_RFKILL_LEDS -struct led_trigger led_trigger; -#endif +/** +* rfkill_has_sw_block_memory -- turn on calling set_block unconditionally +* @rfkill: rfkill struct +* +* This function tells the rfkill core that the device is capable of +* remembering soft blocks (which it is notified of via the set_block +* method) -- this means that the driver may ignore the return value +* from rfkill_set_hw_state(). +* +* This function must be called before rfkill_register(). +*/ +void rfkill_has_sw_block_memory (struct rfkill *rfkill); -struct device dev; -struct list_head node; -enum rfkill_state state_for_resume; -}; -#define to_rfkill (d) container_of(d, struct rfkill, dev) +/** +* rfkill_set_led_trigger_name -- set the LED trigger name +* @rfkill: rfkill struct +* @name: LED trigger name +* +* This function sets the LED trigger name of the radio LED +* trigger that rfkill creates. It is optional, but if called +* must be called before rfkill_register() to be effective. +*/ +void rfkill_set_led_trigger_name (struct rfkill *rfkill,const char *name); -struct rfkill *__must_check rfkill_allocate (struct device *parent, -enum rfkill_type type); -void rfkill_free (struct rfkill *rfkill); +/** +* rfkill_register - Register a rfkill structure. +* @rfkill: rfkill structure to be registered +* +* This function should be called by the transmitter driver to register +* the rfkill structure needs to be registered. Before calling this function +* the driver needs to be ready to service method calls from rfkill. +*/ int __must_check rfkill_register (struct rfkill *rfkill); + +/** +* rfkill_pause_polling(struct rfkill *rfkill) +* +* Pause polling -- say transmitter is off for other reasons. +* NOTE: not necessary for suspend/resume -- in that case the +* core stops polling anyway +*/ +void rfkill_pause_polling (struct rfkill *rfkill); + +/** +* rfkill_resume_polling(struct rfkill *rfkill) +* +* Pause polling -- say transmitter is off for other reasons. +* NOTE: not necessary for suspend/resume -- in that case the +* core stops polling anyway +*/ +void rfkill_resume_polling (struct rfkill *rfkill); + + +/** +* rfkill_unregister - Unregister a rfkill structure. +* @rfkill: rfkill structure to be unregistered +* +* This function should be called by the network driver during device +* teardown to destroy rfkill structure. Until it returns, the driver +* needs to be able to service method calls. +*/ void rfkill_unregister (struct rfkill *rfkill); -int rfkill_force_state (struct rfkill *rfkill,enum rfkill_state state); -int rfkill_set_default (enum rfkill_type type,enum rfkill_state state); +/** +* rfkill_destroy - free rfkill structure +* @rfkill: rfkill structure to be destroyed +* +* Destroys the rfkill structure. +*/ +void rfkill_destroy (struct rfkill *rfkill); + +/** +* rfkill_set_hw_state - Set the internal rfkill hardware block state +* @rfkill: pointer to the rfkill class to modify. +* @state: the current hardware block state to set +* +* rfkill drivers that get events when the hard-blocked state changes +* use this function to notify the rfkill core (and through that also +* userspace) of the current state -- they should also use this after +* resume if the state could have changed. +* +* You need not (but may) call this function if poll_state is assigned. +* +* This function can be called in any context, even from within rfkill +* callbacks. +* +* The function returns the combined block state (true if transmitter +* should be blocked) so that drivers need not keep track of the soft +* block state -- which they might not be able to. +* +* If the device is able to, call rfkill_has_sw_block_memory() and +* ignore the return value of this function. +*/ +bool __must_check rfkill_set_hw_state (struct rfkill *rfkill,bool blocked); + +/** +* rfkill_set_sw_state - Set the internal rfkill software block state +* @rfkill: pointer to the rfkill class to modify. +* @state: the current software block state to set +* +* rfkill drivers that get events when the soft-blocked state changes +* (yes, some platforms directly act on input but allow changing again) +* use this function to notify the rfkill core (and through that also +* userspace) of the current state -- they should also use this after +* resume if the state could have changed. +* +* This function can be called in any context, even from within rfkill +* callbacks. +* +* The function returns the combined block state (true if transmitter +* should be blocked). +*/ +bool __must_check rfkill_set_sw_state (struct rfkill *rfkill,bool blocked); + +/** +* rfkill_set_states - Set the internal rfkill block states +* @rfkill: pointer to the rfkill class to modify. +* @sw: the current software block state to set +* @hw: the current hardware block state to set +* +* This function can be called in any context, even from within rfkill +* callbacks. +*/ +void rfkill_set_states (struct rfkill *rfkill,bool sw,bool hw);/** -* rfkill_state_complement - return complementar state -* @state: state to return the complement of +* rfkill_set_global_sw_state - set global sw block default +* @type: rfkill type to set default for +* @blocked: default to set * -* Returns RFKILL_STATE_SOFT_BLOCKED if @state is RFKILL_STATE_UNBLOCKED, -* returns RFKILL_STATE_UNBLOCKED otherwise. +* This function sets the global default -- use at boot if your platform has +* an rfkill switch. If not early enough this call may be ignored. +* +* XXX: instead of ignoring -- how about just updating all currently +* registered drivers? */ -static inline enum rfkill_state rfkill_state_complement (enum rfkill_state state) +void rfkill_set_global_sw_state (const enum rfkill_type type,bool blocked); +#else /* !RFKILL */ +static inline struct rfkill *__must_check +rfkill_alloc (const char *name, +struct device *parent, +const enum rfkill_type type, +const struct rfkill_ops *ops, +void *ops_data) +{ +return ERR_PTR (-ENODEV ); +} + +static inline void rfkill_has_sw_block_memory (struct rfkill *rfkill) +{ +} + +static inline int __must_check rfkill_register (struct rfkill *rfkill) +{ +if (rfkill ==ERR_PTR (-ENODEV )) +return 0 ; +return -EINVAL ; +} + +static inline void rfkill_pause_polling (struct rfkill *rfkill) +{ +} + +static inline void rfkill_resume_polling (struct rfkill *rfkill) +{ +} + +static inline void rfkill_unregister (struct rfkill *rfkill) +{ +} + +static inline void rfkill_destroy (struct rfkill *rfkill) +{ +} + +static inline bool rfkill_set_hw_state (struct rfkill *rfkill,bool blocked) +{ +return blocked; +} + +static inline bool rfkill_set_sw_state (struct rfkill *rfkill,bool blocked) { -return (state ==RFKILL_STATE_UNBLOCKED ) ? -RFKILL_STATE_SOFT_BLOCKED :RFKILL_STATE_UNBLOCKED ; +return blocked; } +static inline void rfkill_set_global_sw_state (const enum rfkill_type type, +bool blocked) +{ +} +#endif /* RFKILL || RFKILL_MODULE */ + + +#ifdef CONFIG_RFKILL_LEDS /** -* rfkill_get_led_name - Get the LED trigger name for the button's LED. +* rfkill_get_led_trigger_name - Get the LED trigger name for the button's LED. * This function might return a NULL pointer if registering of the -* LED trigger failed. -* Use this as "default_trigger" for the LED. +* LED trigger failed. Use this as "default_trigger" for the LED. */ -static inline char *rfkill_get_led_name (struct rfkill *rfkill) -{ -#ifdef CONFIG_RFKILL_LEDS -return (char *)(rfkill->led_trigger.name); +const char *rfkill_get_led_trigger_name (struct rfkill *rfkill); + +/** +* rfkill_set_led_trigger_name -- set the LED trigger name +* @rfkill: rfkill struct +* @name: LED trigger name +* +* This function sets the LED trigger name of the radio LED +* trigger that rfkill creates. It is optional, but if called +* must be called before rfkill_register() to be effective. +*/ +void rfkill_set_led_trigger_name (struct rfkill *rfkill,const char *name);#else +static inline const char *rfkill_get_led_trigger_name (struct rfkill *rfkill) +{return NULL ; -#endif } +void rfkill_set_led_trigger_name (struct rfkill *rfkill,const char *name) +{ +} +#endif + +#endif /* __KERNEL__ */ +#endif /* RFKILL_H */
drivers/net/wireless/ath/ath9k/main.c +29 -86
169 lines not on this page · raw message
drivers/platform/x86/eeepc-laptop.c +22 -69
128 lines not on this page · raw message
net/rfkill/rfkill.c deleted +0 -843
843 lines not on this page · raw message
net/rfkill/rfkill-input.h deleted +0 -21
@@ -1,21 +0,0 @@ -/* -* Copyright (C) 2007 Ivo van Doorn -*/ - -/* -* This program is free software; you can redistribute it and/or modify it -* under the terms of the GNU General Public License version 2 as published -* by the Free Software Foundation. -*/ - -#ifndef __RFKILL_INPUT_H -#define __RFKILL_INPUT_H - -void rfkill_switch_all (enum rfkill_type type,enum rfkill_state state); -void rfkill_epo (void ); -void rfkill_restore_states (void ); -void rfkill_remove_epo_lock (void ); -bool rfkill_is_epo_lock_active (void ); -enum rfkill_state rfkill_get_global_state (const enum rfkill_type type); - -#endif /* __RFKILL_INPUT_H */
net/rfkill/rfkill-input.c deleted +0 -390
390 lines not on this page · raw message
drivers/net/wireless/b43/main.c +2 -2
@@ -3498,7 +3498,7 @@ static int b43_op_config(struct ieee8021if (!!conf->radio_enabled != phy->radio_on) {if (conf->radio_enabled) { -b43_software_rfkill (dev,RFKILL_STATE_UNBLOCKED ); +b43_software_rfkill (dev, false);b43info (dev->wl,"Radio turned on by software\n" );if (!dev->radio_hw_enable) { b43info(dev->wl, "The hardware RF-kill button "
@@ -3506,7 +3506,7 @@ static int b43_op_config(struct ieee8021 "Press the button to turn it on.\n"); } }else { -b43_software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); +b43_software_rfkill (dev, true);b43info (dev->wl,"Radio turned off by software\n" ); } }
drivers/net/wireless/b43/phy_a.c +2 -2
@@ -480,11 +480,11 @@ static bool b43_aphy_op_supports_hwpctl( }static void b43_aphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {struct b43_phy *phy = &dev->phy; -if (state ==RFKILL_STATE_UNBLOCKED ) { +if (!blocked) {if (phy->radio_on)return ;b43_radio_write16 (dev,0x0004 ,0x00C0 );
drivers/net/wireless/b43/phy_common.c +6 -11
@@ -84,7 +84,7 @@ int b43_phy_init(struct b43_wldev *dev) phy->channel = ops->get_default_chan (dev); - ops->software_rfkill (dev,RFKILL_STATE_UNBLOCKED ); + ops->software_rfkill (dev, false); err = ops->init (dev);if (err) {b43err (dev->wl,"PHY init failed\n" );
@@ -104,7 +104,7 @@ err_phy_exit:if (ops->exit) ops->exit (dev); err_block_rf: - ops->software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); + ops->software_rfkill (dev, true);return err; }
@@ -113,7 +113,7 @@ void b43_phy_exit(struct b43_wldev *dev) {const struct b43_phy_operations *ops = dev->phy.ops; - ops->software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); + ops->software_rfkill (dev, true);if (ops->exit) ops->exit (dev); }
@@ -287,18 +287,13 @@ err_restore_cookie:return err; } -void b43_software_rfkill (struct b43_wldev *dev,enum rfkill_state state) +void b43_software_rfkill (struct b43_wldev *dev,bool blocked) {struct b43_phy *phy = &dev->phy; -if (state ==RFKILL_STATE_HARD_BLOCKED ) { -/* We cannot hardware-block the device */ - state =RFKILL_STATE_SOFT_BLOCKED ; - } -b43_mac_suspend (dev); - phy->ops->software_rfkill (dev, state); - phy->radio_on = (state ==RFKILL_STATE_UNBLOCKED ); + phy->ops->software_rfkill (dev, blocked); + phy->radio_on = !blocked;b43_mac_enable (dev); }
drivers/net/wireless/b43/phy_common.h +2 -2
@@ -159,7 +159,7 @@ struct b43_phy_operations {/* Radio */ bool (*supports_hwpctl)(struct b43_wldev *dev); -void (*software_rfkill)(struct b43_wldev *dev,enum rfkill_state state); +void (*software_rfkill)(struct b43_wldev *dev,bool blocked);void (*switch_analog)(struct b43_wldev *dev,bool on);int (*switch_channel)(struct b43_wldev *dev,unsigned int new_channel);unsigned int (*get_default_chan)(struct b43_wldev *dev);
@@ -362,7 +362,7 @@ int b43_switch_channel(struct b43_wldev/** * b43_software_rfkill - Turn the radio ON or OFF in software. */ -void b43_software_rfkill (struct b43_wldev *dev,enum rfkill_state state); +void b43_software_rfkill (struct b43_wldev *dev,bool blocked);/** * b43_phy_txpower_check - Check TX power output.
drivers/net/wireless/b43/phy_g.c +2 -2
@@ -2592,7 +2592,7 @@ static bool b43_gphy_op_supports_hwpctl( }static void b43_gphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {struct b43_phy *phy = &dev->phy;struct b43_phy_g *gphy = phy->g;
@@ -2600,7 +2600,7 @@ static void b43_gphy_op_software_rfkill(might_sleep (); -if (state ==RFKILL_STATE_UNBLOCKED ) { +if (!blocked) {/* Turn radio ON */ if (phy->radio_on)return ;
drivers/net/wireless/b43/phy_n.c +1 -1
@@ -579,7 +579,7 @@ static void b43_nphy_op_radio_write(stru }static void b43_nphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {//TODO }
drivers/net/wireless/b43/rfkill.c +34 -89
188 lines not on this page · raw message
drivers/net/wireless/b43legacy/rfkill.c +39 -84
192 lines not on this page · raw message
drivers/net/wireless/iwlwifi/iwl-rfkill.c +28 -41
124 lines not on this page · raw message
Documentation/rfkill.txt +100 -539
440 lines not on this page · raw message
net/rfkill/Kconfig +0 -14
Lines of this file are not shown. View the raw message.
net/rfkill/Makefile +2 -2
Lines of this file are not shown. View the raw message.
net/rfkill/core.c new file +837 -0
837 lines not on this page · raw message
net/rfkill/input.c new file +342 -0
342 lines not on this page · raw message
net/rfkill/rfkill.h new file +27 -0
Lines of this file are not shown. View the raw message.
MAINTAINERS +3 -3
Lines of this file are not shown. View the raw message.
include/linux/Kbuild +1 -0
Lines of this file are not shown. View the raw message.
drivers/net/wireless/ath/ath9k/ath9k.h +1 -6
Lines of this file are not shown. View the raw message.
drivers/net/wireless/ath/ath9k/pci.c +0 -15
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/Kconfig +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/rfkill.h +1 -4
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/Kconfig +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/leds.c +2 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/rfkill.h +1 -5
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/leds.c +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/iwlwifi/Kconfig +2 -3
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/phy_lp.c +1 -1
Lines of this file are not shown. View the raw message.
drivers/platform/x86/Kconfig +0 -6
Lines of this file are not shown. View the raw message.
drivers/platform/x86/acer-wmi.c +22 -28
50 lines not on this page · raw message
drivers/platform/x86/dell-laptop.c +32 -69
101 lines not on this page · raw message
drivers/platform/x86/hp-wmi.c +52 -51
103 lines not on this page · raw message
drivers/platform/x86/toshiba_acpi.c +7 -16
Lines of this file are not shown. View the raw message.
arch/arm/mach-pxa/tosa-bt.c +15 -15
Lines of this file are not shown. View the raw message.
arch/arm/mach-pxa/tosa.c +0 -1
Lines of this file are not shown. View the raw message.
include/net/wimax.h +2 -6
Lines of this file are not shown. View the raw message.
net/wimax/op-rfkill.c +28 -97
125 lines not on this page · raw message
net/wimax/Kconfig +0 -14
Lines of this file are not shown. View the raw message.
drivers/net/usb/hso.c +22 -20
42 lines not on this page · raw message
drivers/platform/x86/sony-laptop.c +58 -57
115 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Johannes Berg
maintainerRFC v6 1/1 rfkill: rewrite
This patch completely rewrites the rfkill core to address the following deficiencies:
* all rfkill drivers need to implement polling where necessary rather than having one central implementation
* updating the rfkill state cannot be done from arbitrary contexts, forcing drivers to use schedule_work and requiring lots of code
* rfkill drivers need to keep track of soft/hard blocked internally -- the core should do this
* the rfkill API has many unexpected quirks, for example being asymmetric wrt. alloc/free and register/unregister
* rfkill can call back into a driver from within a function the driver called -- this is prone to deadlocks and generally should be avoided
* rfkill-input pointlessly is a separate module
* drivers need to #ifdef rfkill functions (unless they want to depend on or select RFKILL) -- rfkill should provide inlines that do nothing if it isn't compiled in
* the rfkill structure is not opaque -- drivers need to initialise it correctly (lots of sanity checking code required) -- instead force drivers to pass the right variables to rfkill_alloc()
* the documentation is hard to read because it always assumes the reader is completely clueless and contains way TOO MANY CAPS
* the rfkill code needlessly uses a lot of locks and atomic operations in locked sections
* fix LED trigger to actually change the LED when the radio state changes -- this wasn't done before
---
v3: * fix locking bugs
* fix bug in input.c that made it ignore things
* allow setting LED trigger name
* apply default state while registering
* convert HSO
v4: * LED triggering
v5: * convert sony
* introduce rfkill_set_states function
* change query/poll methods to require calls to rfkill_set{_sw,_hw}_state/rfkill_set_states
* do not call driver from registration
* remove tested-by since it changed a lot
v6: * fix stupid sync work bugs
TODO
* convert toshiba, thinkpad
Documentation/rfkill.txt | 639 +++------------------- MAINTAINERS | 6 arch/arm/mach-pxa/tosa-bt.c | 30 - arch/arm/mach-pxa/tosa.c | 1 drivers/net/usb/hso.c | 42 - drivers/net/wireless/ath/ath9k/ath9k.h | 7 drivers/net/wireless/ath/ath9k/main.c | 115 +--- drivers/net/wireless/ath/ath9k/pci.c | 15 drivers/net/wireless/b43/Kconfig | 2 drivers/net/wireless/b43/leds.c | 2 drivers/net/wireless/b43/main.c | 4 drivers/net/wireless/b43/phy_a.c | 4 drivers/net/wireless/b43/phy_common.c | 17 drivers/net/wireless/b43/phy_common.h | 4 drivers/net/wireless/b43/phy_g.c | 4 drivers/net/wireless/b43/phy_lp.c | 2 drivers/net/wireless/b43/phy_n.c | 2 drivers/net/wireless/b43/rfkill.c | 123 +--- drivers/net/wireless/b43/rfkill.h | 5 drivers/net/wireless/b43legacy/Kconfig | 2 drivers/net/wireless/b43legacy/leds.c | 3 drivers/net/wireless/b43legacy/rfkill.c | 123 +--- drivers/net/wireless/b43legacy/rfkill.h | 6 drivers/net/wireless/iwlwifi/Kconfig | 5 drivers/net/wireless/iwlwifi/iwl-rfkill.c | 69 -- drivers/platform/x86/Kconfig | 6 drivers/platform/x86/acer-wmi.c | 50 - drivers/platform/x86/dell-laptop.c | 101 +-- drivers/platform/x86/eeepc-laptop.c | 91 --- drivers/platform/x86/hp-wmi.c | 103 +-- drivers/platform/x86/sony-laptop.c | 115 ++-- drivers/platform/x86/toshiba_acpi.c | 23 include/linux/Kbuild | 1 include/linux/rfkill.h | 344 +++++++++--- include/net/wimax.h | 8 net/rfkill/Kconfig | 14 net/rfkill/Makefile | 4 net/rfkill/core.c | 838 +++++++++++++++++++++++++++++ net/rfkill/input.c | 342 ++++++++++++ net/rfkill/rfkill-input.c | 390 ------------- net/rfkill/rfkill-input.h | 21 net/rfkill/rfkill.c | 843 ------------------------------ net/rfkill/rfkill.h | 27 net/wimax/Kconfig | 14 net/wimax/op-rfkill.c | 125 ---- 45 files changed, 2000 insertions(+), 2692 deletions(-)
include/linux/rfkill.h +271 -73
@@ -4,6 +4,7 @@/* * Copyright (C) 2006 - 2007 Ivo van Doorn * Copyright (C) 2007 Dmitry Torokhov +* Copyright 2009 Johannes Berg <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -21,6 +22,24 @@* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* define userspace visible states */ +#define RFKILL_STATE_SOFT_BLOCKED 0 +#define RFKILL_STATE_UNBLOCKED 1 +#define RFKILL_STATE_HARD_BLOCKED 2 + +/* and that's all userspace gets */ +#ifdef __KERNEL__ +/* don't allow anyone to use these in the kernel */ +enum rfkill_user_states { +RFKILL_USER_STATE_SOFT_BLOCKED =RFKILL_STATE_SOFT_BLOCKED , +RFKILL_USER_STATE_UNBLOCKED =RFKILL_STATE_UNBLOCKED , +RFKILL_USER_STATE_HARD_BLOCKED =RFKILL_STATE_HARD_BLOCKED , +}; +#undef RFKILL_STATE_SOFT_BLOCKED +#undef RFKILL_STATE_UNBLOCKED +#undef RFKILL_STATE_HARD_BLOCKED +#include <linux/types.h> #include <linux/kernel.h> #include <linux/list.h>
@@ -30,11 +49,13 @@/** * enum rfkill_type - type of rfkill switch. -* RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. -* RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. -* RFKILL_TYPE_UWB: switch is on a ultra wideband device. -* RFKILL_TYPE_WIMAX: switch is on a WiMAX device. -* RFKILL_TYPE_WWAN: switch is on a wireless WAN device. +* +* @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. +* @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. +* @RFKILL_TYPE_UWB: switch is on a ultra wideband device. +* @RFKILL_TYPE_WIMAX: switch is on a WiMAX device. +* @RFKILL_TYPE_WWAN: switch is on a wireless WAN device. +* @NUM_RFKILL_TYPES: number of defined rfkill types */ enum rfkill_type {RFKILL_TYPE_WLAN ,
@@ -42,97 +63,274 @@ enum rfkill_type {RFKILL_TYPE_UWB ,RFKILL_TYPE_WIMAX ,RFKILL_TYPE_WWAN , - RFKILL_TYPE_MAX, + NUM_RFKILL_TYPES, }; -enum rfkill_state { -RFKILL_STATE_SOFT_BLOCKED =0 ,/* Radio output blocked */ -RFKILL_STATE_UNBLOCKED =1 ,/* Radio output allowed */ -RFKILL_STATE_HARD_BLOCKED =2 ,/* Output blocked, non-overrideable */ -RFKILL_STATE_MAX ,/* marker for last valid state */ +/* this is opaque */ +struct rfkill ; + +/** +* struct rfkill_ops - rfkill driver methods +* +* @poll: poll the rfkill block state(s) -- only assign this method +* when you need polling. When called, simply call one of the +* rfkill_set{,_hw,_sw}_state family of functions. If the hw +* is getting unblocked you need to take into account the return +* value of those functions to make sure the software block is +* properly used. +* @query: query the rfkill hardware block state (return true +* for blocked) -- assign this method if input events can cause +* hardware state changes to make the rfkill core query your +* driver before setting a requested block +* @set_block: turn the transmitter on (blocked == false) or off +* (blocked == true) -- this is called only while the transmitter +* is not hard-blocked. This must be assigned. +*/ +struct rfkill_ops { +void (*poll)(struct rfkill *rfkill,void *data); +void (*query)(struct rfkill *rfkill,void *data); +int (*set_block)(void *data,bool blocked); }; +#if defined(CONFIG_RFKILL ) || defined(CONFIG_RFKILL_MODULE )/** -* struct rfkill - rfkill control structure. -* @name: Name of the switch. -* @type: Radio type which the button controls, the value stored -* here should be a value from enum rfkill_type. -* @state: State of the switch, "UNBLOCKED" means radio can operate. -* @mutex: Guards switch state transitions. It serializes callbacks -* and also protects the state. -* @data: Pointer to the RF button drivers private data which will be -* passed along when toggling radio state. -* @toggle_radio(): Mandatory handler to control state of the radio. -* only RFKILL_STATE_SOFT_BLOCKED and RFKILL_STATE_UNBLOCKED are -* valid parameters. -* @get_state(): handler to read current radio state from hardware, -* may be called from atomic context, should return 0 on success. -* Either this handler OR judicious use of rfkill_force_state() is -* MANDATORY for any driver capable of RFKILL_STATE_HARD_BLOCKED. -* @led_trigger: A LED trigger for this button's LED. -* @dev: Device structure integrating the switch into device tree. -* @node: Used to place switch into list of all switches known to the -* the system. -* -* This structure represents a RF switch located on a network device. -*/ -struct rfkill { -const char *name; -enum rfkill_type type; - -/* the mutex serializes callbacks and also protects -* the state */ -struct mutex mutex; -enum rfkill_state state; -void *data; -int (*toggle_radio)(void *data,enum rfkill_state state); -int (*get_state)(void *data,enum rfkill_state *state); +* rfkill_alloc - allocate rfkill structure +* @name: name of the struct -- the string is not copied internally +* @parent: device that has rf switch on it +* @type: type of the switch (RFKILL_TYPE_*) +* @ops: rfkill methods +* @ops_data: data passed to each method +* +* This function should be called by the transmitter driver to allocate an +* rfkill structure. +*/ +struct rfkill *__must_check rfkill_alloc (const char *name, +struct device *parent, +const enum rfkill_type type, +const struct rfkill_ops *ops, +void *ops_data); -#ifdef CONFIG_RFKILL_LEDS -struct led_trigger led_trigger; -#endif +/** +* rfkill_has_sw_block_memory -- turn on calling set_block unconditionally +* @rfkill: rfkill struct +* +* This function tells the rfkill core that the device is capable of +* remembering soft blocks (which it is notified of via the set_block +* method) -- this means that the driver may ignore the return value +* from rfkill_set_hw_state(). +* +* This function must be called before rfkill_register(). +*/ +void rfkill_has_sw_block_memory (struct rfkill *rfkill); -struct device dev; -struct list_head node; -enum rfkill_state state_for_resume; -}; -#define to_rfkill (d) container_of(d, struct rfkill, dev) +/** +* rfkill_set_led_trigger_name -- set the LED trigger name +* @rfkill: rfkill struct +* @name: LED trigger name +* +* This function sets the LED trigger name of the radio LED +* trigger that rfkill creates. It is optional, but if called +* must be called before rfkill_register() to be effective. +*/ +void rfkill_set_led_trigger_name (struct rfkill *rfkill,const char *name); -struct rfkill *__must_check rfkill_allocate (struct device *parent, -enum rfkill_type type); -void rfkill_free (struct rfkill *rfkill); +/** +* rfkill_register - Register a rfkill structure. +* @rfkill: rfkill structure to be registered +* +* This function should be called by the transmitter driver to register +* the rfkill structure needs to be registered. Before calling this function +* the driver needs to be ready to service method calls from rfkill. +*/ int __must_check rfkill_register (struct rfkill *rfkill); + +/** +* rfkill_pause_polling(struct rfkill *rfkill) +* +* Pause polling -- say transmitter is off for other reasons. +* NOTE: not necessary for suspend/resume -- in that case the +* core stops polling anyway +*/ +void rfkill_pause_polling (struct rfkill *rfkill); + +/** +* rfkill_resume_polling(struct rfkill *rfkill) +* +* Pause polling -- say transmitter is off for other reasons. +* NOTE: not necessary for suspend/resume -- in that case the +* core stops polling anyway +*/ +void rfkill_resume_polling (struct rfkill *rfkill); + + +/** +* rfkill_unregister - Unregister a rfkill structure. +* @rfkill: rfkill structure to be unregistered +* +* This function should be called by the network driver during device +* teardown to destroy rfkill structure. Until it returns, the driver +* needs to be able to service method calls. +*/ void rfkill_unregister (struct rfkill *rfkill); -int rfkill_force_state (struct rfkill *rfkill,enum rfkill_state state); -int rfkill_set_default (enum rfkill_type type,enum rfkill_state state); +/** +* rfkill_destroy - free rfkill structure +* @rfkill: rfkill structure to be destroyed +* +* Destroys the rfkill structure. +*/ +void rfkill_destroy (struct rfkill *rfkill); + +/** +* rfkill_set_hw_state - Set the internal rfkill hardware block state +* @rfkill: pointer to the rfkill class to modify. +* @state: the current hardware block state to set +* +* rfkill drivers that get events when the hard-blocked state changes +* use this function to notify the rfkill core (and through that also +* userspace) of the current state -- they should also use this after +* resume if the state could have changed. +* +* You need not (but may) call this function if poll_state is assigned. +* +* This function can be called in any context, even from within rfkill +* callbacks. +* +* The function returns the combined block state (true if transmitter +* should be blocked) so that drivers need not keep track of the soft +* block state -- which they might not be able to. +* +* If the device is able to, call rfkill_has_sw_block_memory() and +* ignore the return value of this function. +*/ +bool __must_check rfkill_set_hw_state (struct rfkill *rfkill,bool blocked); + +/** +* rfkill_set_sw_state - Set the internal rfkill software block state +* @rfkill: pointer to the rfkill class to modify. +* @state: the current software block state to set +* +* rfkill drivers that get events when the soft-blocked state changes +* (yes, some platforms directly act on input but allow changing again) +* use this function to notify the rfkill core (and through that also +* userspace) of the current state -- they should also use this after +* resume if the state could have changed. +* +* This function can be called in any context, even from within rfkill +* callbacks. +* +* The function returns the combined block state (true if transmitter +* should be blocked). +*/ +bool __must_check rfkill_set_sw_state (struct rfkill *rfkill,bool blocked); + +/** +* rfkill_set_states - Set the internal rfkill block states +* @rfkill: pointer to the rfkill class to modify. +* @sw: the current software block state to set +* @hw: the current hardware block state to set +* +* This function can be called in any context, even from within rfkill +* callbacks. +*/ +void rfkill_set_states (struct rfkill *rfkill,bool sw,bool hw);/** -* rfkill_state_complement - return complementar state -* @state: state to return the complement of +* rfkill_set_global_sw_state - set global sw block default +* @type: rfkill type to set default for +* @blocked: default to set * -* Returns RFKILL_STATE_SOFT_BLOCKED if @state is RFKILL_STATE_UNBLOCKED, -* returns RFKILL_STATE_UNBLOCKED otherwise. +* This function sets the global default -- use at boot if your platform has +* an rfkill switch. If not early enough this call may be ignored. +* +* XXX: instead of ignoring -- how about just updating all currently +* registered drivers? */ -static inline enum rfkill_state rfkill_state_complement (enum rfkill_state state) +void rfkill_set_global_sw_state (const enum rfkill_type type,bool blocked); +#else /* !RFKILL */ +static inline struct rfkill *__must_check +rfkill_alloc (const char *name, +struct device *parent, +const enum rfkill_type type, +const struct rfkill_ops *ops, +void *ops_data) +{ +return ERR_PTR (-ENODEV ); +} + +static inline void rfkill_has_sw_block_memory (struct rfkill *rfkill) +{ +} + +static inline int __must_check rfkill_register (struct rfkill *rfkill) +{ +if (rfkill ==ERR_PTR (-ENODEV )) +return 0 ; +return -EINVAL ; +} + +static inline void rfkill_pause_polling (struct rfkill *rfkill) +{ +} + +static inline void rfkill_resume_polling (struct rfkill *rfkill) +{ +} + +static inline void rfkill_unregister (struct rfkill *rfkill) +{ +} + +static inline void rfkill_destroy (struct rfkill *rfkill) +{ +} + +static inline bool rfkill_set_hw_state (struct rfkill *rfkill,bool blocked) +{ +return blocked; +} + +static inline bool rfkill_set_sw_state (struct rfkill *rfkill,bool blocked) { -return (state ==RFKILL_STATE_UNBLOCKED ) ? -RFKILL_STATE_SOFT_BLOCKED :RFKILL_STATE_UNBLOCKED ; +return blocked; } +static inline void rfkill_set_global_sw_state (const enum rfkill_type type, +bool blocked) +{ +} +#endif /* RFKILL || RFKILL_MODULE */ + + +#ifdef CONFIG_RFKILL_LEDS /** -* rfkill_get_led_name - Get the LED trigger name for the button's LED. +* rfkill_get_led_trigger_name - Get the LED trigger name for the button's LED. * This function might return a NULL pointer if registering of the -* LED trigger failed. -* Use this as "default_trigger" for the LED. +* LED trigger failed. Use this as "default_trigger" for the LED. */ -static inline char *rfkill_get_led_name (struct rfkill *rfkill) -{ -#ifdef CONFIG_RFKILL_LEDS -return (char *)(rfkill->led_trigger.name); +const char *rfkill_get_led_trigger_name (struct rfkill *rfkill); + +/** +* rfkill_set_led_trigger_name -- set the LED trigger name +* @rfkill: rfkill struct +* @name: LED trigger name +* +* This function sets the LED trigger name of the radio LED +* trigger that rfkill creates. It is optional, but if called +* must be called before rfkill_register() to be effective. +*/ +void rfkill_set_led_trigger_name (struct rfkill *rfkill,const char *name);#else +static inline const char *rfkill_get_led_trigger_name (struct rfkill *rfkill) +{return NULL ; -#endif } +void rfkill_set_led_trigger_name (struct rfkill *rfkill,const char *name) +{ +} +#endif + +#endif /* __KERNEL__ */ +#endif /* RFKILL_H */
drivers/net/wireless/ath/ath9k/main.c +29 -86
169 lines not on this page · raw message
drivers/platform/x86/eeepc-laptop.c +22 -69
128 lines not on this page · raw message
net/rfkill/rfkill.c deleted +0 -843
843 lines not on this page · raw message
net/rfkill/rfkill-input.h deleted +0 -21
@@ -1,21 +0,0 @@ -/* -* Copyright (C) 2007 Ivo van Doorn -*/ - -/* -* This program is free software; you can redistribute it and/or modify it -* under the terms of the GNU General Public License version 2 as published -* by the Free Software Foundation. -*/ - -#ifndef __RFKILL_INPUT_H -#define __RFKILL_INPUT_H - -void rfkill_switch_all (enum rfkill_type type,enum rfkill_state state); -void rfkill_epo (void ); -void rfkill_restore_states (void ); -void rfkill_remove_epo_lock (void ); -bool rfkill_is_epo_lock_active (void ); -enum rfkill_state rfkill_get_global_state (const enum rfkill_type type); - -#endif /* __RFKILL_INPUT_H */
net/rfkill/rfkill-input.c deleted +0 -390
390 lines not on this page · raw message
drivers/net/wireless/b43/main.c +2 -2
@@ -3498,7 +3498,7 @@ static int b43_op_config(struct ieee8021if (!!conf->radio_enabled != phy->radio_on) {if (conf->radio_enabled) { -b43_software_rfkill (dev,RFKILL_STATE_UNBLOCKED ); +b43_software_rfkill (dev, false);b43info (dev->wl,"Radio turned on by software\n" );if (!dev->radio_hw_enable) { b43info(dev->wl, "The hardware RF-kill button "
@@ -3506,7 +3506,7 @@ static int b43_op_config(struct ieee8021 "Press the button to turn it on.\n"); } }else { -b43_software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); +b43_software_rfkill (dev, true);b43info (dev->wl,"Radio turned off by software\n" ); } }
drivers/net/wireless/b43/phy_a.c +2 -2
@@ -480,11 +480,11 @@ static bool b43_aphy_op_supports_hwpctl( }static void b43_aphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {struct b43_phy *phy = &dev->phy; -if (state ==RFKILL_STATE_UNBLOCKED ) { +if (!blocked) {if (phy->radio_on)return ;b43_radio_write16 (dev,0x0004 ,0x00C0 );
drivers/net/wireless/b43/phy_common.c +6 -11
@@ -84,7 +84,7 @@ int b43_phy_init(struct b43_wldev *dev) phy->channel = ops->get_default_chan (dev); - ops->software_rfkill (dev,RFKILL_STATE_UNBLOCKED ); + ops->software_rfkill (dev, false); err = ops->init (dev);if (err) {b43err (dev->wl,"PHY init failed\n" );
@@ -104,7 +104,7 @@ err_phy_exit:if (ops->exit) ops->exit (dev); err_block_rf: - ops->software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); + ops->software_rfkill (dev, true);return err; }
@@ -113,7 +113,7 @@ void b43_phy_exit(struct b43_wldev *dev) {const struct b43_phy_operations *ops = dev->phy.ops; - ops->software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); + ops->software_rfkill (dev, true);if (ops->exit) ops->exit (dev); }
@@ -287,18 +287,13 @@ err_restore_cookie:return err; } -void b43_software_rfkill (struct b43_wldev *dev,enum rfkill_state state) +void b43_software_rfkill (struct b43_wldev *dev,bool blocked) {struct b43_phy *phy = &dev->phy; -if (state ==RFKILL_STATE_HARD_BLOCKED ) { -/* We cannot hardware-block the device */ - state =RFKILL_STATE_SOFT_BLOCKED ; - } -b43_mac_suspend (dev); - phy->ops->software_rfkill (dev, state); - phy->radio_on = (state ==RFKILL_STATE_UNBLOCKED ); + phy->ops->software_rfkill (dev, blocked); + phy->radio_on = !blocked;b43_mac_enable (dev); }
drivers/net/wireless/b43/phy_common.h +2 -2
@@ -159,7 +159,7 @@ struct b43_phy_operations {/* Radio */ bool (*supports_hwpctl)(struct b43_wldev *dev); -void (*software_rfkill)(struct b43_wldev *dev,enum rfkill_state state); +void (*software_rfkill)(struct b43_wldev *dev,bool blocked);void (*switch_analog)(struct b43_wldev *dev,bool on);int (*switch_channel)(struct b43_wldev *dev,unsigned int new_channel);unsigned int (*get_default_chan)(struct b43_wldev *dev);
@@ -362,7 +362,7 @@ int b43_switch_channel(struct b43_wldev/** * b43_software_rfkill - Turn the radio ON or OFF in software. */ -void b43_software_rfkill (struct b43_wldev *dev,enum rfkill_state state); +void b43_software_rfkill (struct b43_wldev *dev,bool blocked);/** * b43_phy_txpower_check - Check TX power output.
drivers/net/wireless/b43/phy_g.c +2 -2
@@ -2592,7 +2592,7 @@ static bool b43_gphy_op_supports_hwpctl( }static void b43_gphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {struct b43_phy *phy = &dev->phy;struct b43_phy_g *gphy = phy->g;
@@ -2600,7 +2600,7 @@ static void b43_gphy_op_software_rfkill(might_sleep (); -if (state ==RFKILL_STATE_UNBLOCKED ) { +if (!blocked) {/* Turn radio ON */ if (phy->radio_on)return ;
drivers/net/wireless/b43/phy_n.c +1 -1
@@ -579,7 +579,7 @@ static void b43_nphy_op_radio_write(stru }static void b43_nphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {//TODO }
drivers/net/wireless/b43/rfkill.c +34 -89
188 lines not on this page · raw message
drivers/net/wireless/b43legacy/rfkill.c +39 -84
192 lines not on this page · raw message
drivers/net/wireless/iwlwifi/iwl-rfkill.c +28 -41
124 lines not on this page · raw message
Documentation/rfkill.txt +100 -539
440 lines not on this page · raw message
net/rfkill/Kconfig +0 -14
Lines of this file are not shown. View the raw message.
net/rfkill/Makefile +2 -2
Lines of this file are not shown. View the raw message.
net/rfkill/core.c new file +838 -0
838 lines not on this page · raw message
net/rfkill/input.c new file +342 -0
342 lines not on this page · raw message
net/rfkill/rfkill.h new file +27 -0
Lines of this file are not shown. View the raw message.
MAINTAINERS +3 -3
Lines of this file are not shown. View the raw message.
include/linux/Kbuild +1 -0
Lines of this file are not shown. View the raw message.
drivers/net/wireless/ath/ath9k/ath9k.h +1 -6
Lines of this file are not shown. View the raw message.
drivers/net/wireless/ath/ath9k/pci.c +0 -15
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/Kconfig +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/rfkill.h +1 -4
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/Kconfig +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/leds.c +2 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/rfkill.h +1 -5
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/leds.c +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/iwlwifi/Kconfig +2 -3
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/phy_lp.c +1 -1
Lines of this file are not shown. View the raw message.
drivers/platform/x86/Kconfig +0 -6
Lines of this file are not shown. View the raw message.
drivers/platform/x86/acer-wmi.c +22 -28
50 lines not on this page · raw message
drivers/platform/x86/dell-laptop.c +32 -69
101 lines not on this page · raw message
drivers/platform/x86/hp-wmi.c +52 -51
103 lines not on this page · raw message
drivers/platform/x86/toshiba_acpi.c +7 -16
Lines of this file are not shown. View the raw message.
arch/arm/mach-pxa/tosa-bt.c +15 -15
Lines of this file are not shown. View the raw message.
arch/arm/mach-pxa/tosa.c +0 -1
Lines of this file are not shown. View the raw message.
include/net/wimax.h +2 -6
Lines of this file are not shown. View the raw message.
net/wimax/op-rfkill.c +28 -97
125 lines not on this page · raw message
net/wimax/Kconfig +0 -14
Lines of this file are not shown. View the raw message.
drivers/net/usb/hso.c +22 -20
42 lines not on this page · raw message
drivers/platform/x86/sony-laptop.c +58 -57
115 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Quoted 4 lines · Johannes Berg
This patch completely rewrites the rfkill core to address the following deficiencies:
Signed-off-by Johannes Berg <[email protected]>
Quoted 14 lines
---
v3: * fix locking bugs
* fix bug ininput.cthat made it ignore things
* allow setting LED trigger name
* apply default state while registering
* convert HSO
v4: * LED triggering
v5: * convert sony
* introducerfkill_set_statesfunction
* change query/poll methods to require calls to rfkill_set{_sw,_hw}_state/rfkill_set_states
* do not call driver from registration
* remove tested-by since it changed a lot
v6: * fix stupid sync work bugs
V6 works with b43legacy.
I am halfway on the thinkpad-acpi conversion. It is going slow because I have to cleanup the entire thing to have the code look even remotely sane now that HW and SW states are to be tracked separately by the backend driver, and I lost the RFKILL_STATE_* stuff.
Anyway, in the process (using v7 of the patch, taken from the URL you posted sometime ago), I noticed this:
The return values for rfkill_alloc() are not the same on the stub and real functions. The stub function uses ERR_PTR, while the real
function uses NULL for any errors. Please make them do the same
thing, and it is probably a damn good idea to document in the kerneldoc what kind of return values one should expect when you return a pointer and the function can fail (i.e. NULL or ERR_PTR).
Also, I have a question: are hooks ever called in atomic/interrupt context? Just about every ACPI and I2C driver needs to sleep to do their magic, so I sure hope the answer is "no", otherwise life suddenly got a whole lot more complicated for thinkpad-acpi..
Also, due to races, it is _impossible_ to assure the backend driver that the set_block hook will never be called when the radio is hard-blocked. Best to change the description of that hook to make it clear that it could happen, but that the rfkill core will try to optimize away such changes. Here's the race:
A Brfkill_set_block
saves state in "prev"
... rfkill_set_hw_state(true)
call set_block hook
but radio IS hard-blocked
and the core WAS informed
of this
Also, it looks like the SW state rollback done by rfkill_set_block can sw-unblock a radio when it shouldn't on races very similar as the one above, but involving sw-blocking.
I don't see a way to do safe state rollback in a lockless rfkill core if set_sw_state can happen at any time. Please enlighten me if I am wrong (and I hope I am) :-(
If I am not wrong, one could change rfkill_set_sw_state and rfkill_set_states to return an error if rfkill_set_block is on the way (that can be done lockless). For rfkill_set_states, document that the hw state WILL be updated regardless, but that the sw state might not be.
Or one could kick the problem to the backend driver (which will have any required locking anyway), by giving the set_block hook the duty of calling set_sw_state when it succeeds. The return status might be kept should we ever start passing it down to other layers like userspace, or you can remove it.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Johannes Berg
maintainerHi,
Quoted 4 lines · Henrique de Moraes Holschuh
I am halfway on the thinkpad-acpi conversion. It is going slow because I have to cleanup the entire thing to have the code look even remotely sane now that HW and SW states are to be tracked separately by the backend driver, and I lost the RFKILL_STATE_* stuff.
Hmm. I didn't think it was that much of a problem for the other drivers at least.
Quoted 9 lines
Anyway, in the process (using v7 of the patch, taken from the URL you posted sometime ago), I noticed this:
The return values for
rfkill_alloc()are not the same on the stub and real functions. The stub function usesERR_PTR, while the real
function uses NULL for any errors. Please make them do the same
thing, and it is probably a damn good idea to document in the kerneldoc what kind of return values one should expect when you return a pointer and the function can fail (i.e. NULL orERR_PTR).
Oops, yes, will fix that. I think I intended to use ERR_PTR but then thought it was too much of an API change. Don't really remember though.
Quoted 4 lines
Also, I have a question: are hooks ever called in atomic/interrupt context? Just about every ACPI and I2C driver needs to sleep to do their magic, so I sure hope the answer is "no", otherwise life suddenly got a whole lot more complicated for thinkpad-acpi..
The answer is "no" unless there's a bug, this didn't really change, they're called only from the input handler.
Quoted 6 lines
Also, due to races, it is _impossible_ to assure the backend driver that the
set_blockhook will never be called when the radio is hard-blocked. Best to change the description of that hook to make it clear that it could happen, but that the rfkill core will try to optimize away such changes. Here's the race:
Quoted 8 lines
A B
rfkill_set_block
saves state in "prev"
...rfkill_set_hw_state(true)
callset_blockhook
but radio IS hard-blocked
and the core WAS informed
of this
Good point. I wonder what's more important -- it would be almost trivial to change this by using a spinlock instead of atomic bit operations.
Quoted 14 lines
Also, it looks like the SW state rollback done by
rfkill_set_blockcan sw-unblock a radio when it shouldn't on races very similar as the one above, but involving sw-blocking.I don't see a way to do safe state rollback in a lockless rfkill core if
set_sw_statecan happen at any time. Please enlighten me if I am wrong (and I hope I am) :-(If I am not wrong, one could change
rfkill_set_sw_stateandrfkill_set_statesto return an error ifrfkill_set_blockis on the way (that can be done lockless). Forrfkill_set_states, document that the hw state WILL be updated regardless, but that the sw state might not be.
Quoted 5 lines
Or one could kick the problem to the backend driver (which will have any required locking anyway), by giving the
set_blockhook the duty of callingset_sw_statewhen it succeeds. The return status might be kept should we ever start passing it down to other layers like userspace, or you can remove it.
Thanks for your analysis. It does seem like a problem, and even locking in rfkill can't really avoid the problem [1]. However, why would we require the driver to postpone that? Your idea is sound, but I think we can do it in the core. It might require a spinlock there, but that's acceptable, I didn't use atomic operations to make it faster but to make it simpler.
* rfkill_set_block can set a flag "I'm in an update"
* a concurrent rfkill_set_sw_state will check that flag, and update the "prev" variable instead of the real variable
* on errors, rfkill_set_block will then revert to whatever the last set_sw_state said
That way, if the driver returns an error from ops->set_block, we will really revert to what the driver last told us with set_sw_state. It would seem to get this prev/in-update handling correct we need to add a spinlock, but concurrent rfkill_set_block()s are already prevented by the mutex so no additional locking would be needed there.
Does that sound correct/acceptable?
johannes
[1] unless we want to use a mutex or require ops->set_block to be atomic but then we can't really do either
Quoted 8 lines · Johannes Berg
Quoted 4 lines · Henrique de Moraes Holschuh
I am halfway on the thinkpad-acpi conversion. It is going slow because I have to cleanup the entire thing to have the code look even remotely sane now that HW and SW states are to be tracked separately by the backend driver, and I lost the RFKILL_STATE_* stuff.
Hmm. I didn't think it was that much of a problem for the other drivers at least.
I will cope, it just slows things down. What is really annoying me is that I have to find a way to get the new rfkill running on 2.6.28 to be able to test the code properly. Fortunately, that just means net/rfkill, as the only module I need that connects to rfkill is thinkpad-acpi itself.
Quoted 15 lines
Quoted 6 lines
Also, due to races, it is _impossible_ to assure the backend driver that the
set_blockhook will never be called when the radio is hard-blocked. Best to change the description of that hook to make it clear that it could happen, but that the rfkill core will try to optimize away such changes. Here's the race:Quoted 8 lines
A B
rfkill_set_block
saves state in "prev"
...rfkill_set_hw_state(true)
callset_blockhook
but radio IS hard-blocked
and the core WAS informed
of this
Quoted 2 lines
Good point. I wonder what's more important -- it would be almost trivial to change this by using a spinlock instead of atomic bit operations.
Yeah, as long as it is a spinlock variant that can be used safely in any context, it should work fine, as contention would be quite rare (unless there is a pathological case in one driver that makes it always call some set_foo just when the core is going to call it back...)
Quoted 12 lines
Quoted 11 lines
If I am not wrong, one could change
rfkill_set_sw_stateandrfkill_set_statesto return an error ifrfkill_set_blockis on the way (that can be done lockless). Forrfkill_set_states, document that the hw state WILL be updated regardless, but that the sw state might not be.Or one could kick the problem to the backend driver (which will have any required locking anyway), by giving the
set_blockhook the duty of callingset_sw_statewhen it succeeds. The return status might be kept should we ever start passing it down to other layers like userspace, or you can remove it.
Quoted 6 lines
Thanks for your analysis. It does seem like a problem, and even locking in rfkill can't really avoid the problem [1]. However, why would we require the driver to postpone that? Your idea is sound, but I think we can do it in the core. It might require a spinlock there, but that's acceptable, I didn't use atomic operations to make it faster but to make it simpler.
Well, as long as the race is closed, and the kernel doesn't stay around spinning with interrupts disabled for long periods, I'm fine :-)
Quoted 5 lines
*
rfkill_set_blockcan set a flag "I'm in an update"
* a concurrentrfkill_set_sw_statewill check that flag, and update the "prev" variable instead of the real variable
* on errors,rfkill_set_blockwill then revert to whatever the lastset_sw_statesaid
That could work. It is still required to make it clear that the set_block hook can be called with a hardware block active, even if it normally won't be, so that backend drivers are aware of the possibility.
Quoted 7 lines
That way, if the driver returns an error from
ops->set_block, we will really revert to what the driver last told us withset_sw_state. It would seem to get this prev/in-update handling correct we need to add a spinlock, but concurrent rfkill_set_block()s are already prevented by the mutex so no additional locking would be needed there.Does that sound correct/acceptable?
I think so, but I'd need to look at the finished patch to be even remotely sure. I am not very good at Linux locking yet, in particular I am quite weak at the more esotheric (but really useful) readers/writers locks, RCU, and other such stuff.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Johannes Berg
maintainerQuoted 15 lines · Henrique de Moraes Holschuh
Quoted 15 lines
Quoted 14 lines
Also, due to races, it is _impossible_ to assure the backend driver that the
set_blockhook will never be called when the radio is hard-blocked. Best to change the description of that hook to make it clear that it could happen, but that the rfkill core will try to optimize away such changes. Here's the race:A B
rfkill_set_block
saves state in "prev"
...rfkill_set_hw_state(true)
callset_blockhook
but radio IS hard-blocked
and the core WAS informed
of this
Quoted 7 lines
Quoted 2 lines
Good point. I wonder what's more important -- it would be almost trivial to change this by using a spinlock instead of atomic bit operations.
Yeah, as long as it is a spinlock variant that can be used safely in any context, it should work fine, as contention would be quite rare (unless there is a pathological case in one driver that makes it always call some
set_foojust when the core is going to call it back...)
Heh, that would be strange.
Quoted 9 lines
Quoted 5 lines
*
rfkill_set_blockcan set a flag "I'm in an update"
* a concurrentrfkill_set_sw_statewill check that flag, and update the "prev" variable instead of the real variable
* on errors,rfkill_set_blockwill then revert to whatever the lastset_sw_statesaidThat could work. It is still required to make it clear that the
set_blockhook can be called with a hardware block active, even if it normally won't be, so that backend drivers are aware of the possibility.
Right, it could still happen, if the driver has just called set_hw_state when something decided to change the sw state. Should be relatively rare though. The other race can also happen, but the driver needs to take care of the return value of set_hw_state() so it doesn't matter.
I'll see if I can implement this.
johannes
Johannes Berg
maintainerQuoted 6 lines · Henrique de Moraes Holschuh
The return values for
rfkill_alloc()are not the same on the stub and real functions. The stub function usesERR_PTR, while the real
function uses NULL for any errors. Please make them do the same
thing, and it is probably a damn good idea to document in the kerneldoc what kind of return values one should expect when you return a pointer and the function can fail (i.e. NULL orERR_PTR).
Actually, I was going to clean this up, and then I noticed you're wrong. :) Returning ERR_PTR(-ENODEV) is intentional, in the non-RFKILL case. Imagine a driver like this:
ASDF
rf = rfkill_alloc(...)
if (!rf)
return -ENOMEM;
err = rfkill_register(rf);
if (err) {
rfkill_destroy(rf);
return err;
}
GHJKNow, in the non-RFKILL case, this boils down to:
rf = ERR_PTR(-ENODEV); ...
and given compiler optimisations will end up like this:
ASDF
GHJK
Which is good :)
johannes
Johannes Berg
maintainerRFC v8 1/1 rfkill: rewrite
In reply to Henrique de Moraes HolschuhOk, here's a new version.
I wonder if we should remove the optimisation of "don't call set_block if hw-blocked since due to the race drivers must be able to handle that anyway, if only by making it a no-op... Then we could get rid of rfkill_has_sw_block_memory again which always seemed like a hack. I think I'll do that for v9 after I review the drivers.
johannes
----
This patch completely rewrites the rfkill core to address the following deficiencies:
* all rfkill drivers need to implement polling where necessary rather than having one central implementation
* updating the rfkill state cannot be done from arbitrary contexts, forcing drivers to use schedule_work and requiring lots of code
* rfkill drivers need to keep track of soft/hard blocked internally -- the core should do this
* the rfkill API has many unexpected quirks, for example being asymmetric wrt. alloc/free and register/unregister
* rfkill can call back into a driver from within a function the driver called -- this is prone to deadlocks and generally should be avoided
* rfkill-input pointlessly is a separate module
* drivers need to #ifdef rfkill functions (unless they want to depend on or select RFKILL) -- rfkill should provide inlines that do nothing if it isn't compiled in
* the rfkill structure is not opaque -- drivers need to initialise it correctly (lots of sanity checking code required) -- instead force drivers to pass the right variables to rfkill_alloc()
* the documentation is hard to read because it always assumes the reader is completely clueless and contains way TOO MANY CAPS
* the rfkill code needlessly uses a lot of locks and atomic operations in locked sections
* fix LED trigger to actually change the LED when the radio state changes -- this wasn't done before
---
v3: * fix locking bugs
* fix bug in input.c that made it ignore things
* allow setting LED trigger name
* apply default state while registering
* convert HSO
v4: * LED triggering
v5: * convert sony
* introduce rfkill_set_states function
* change query/poll methods to require calls to rfkill_set{_sw,_hw}_state/rfkill_set_states
* do not call driver from registration
* remove tested-by since it changed a lot
v6: * fix stupid sync work bugs
v7: * fix setting states before registration
* make EEEPC resume properly [Alan Jenkins]
v8: * move one rfkill_set_state call under the mutex
* protect things with spinlock and take care to close the race Henrique pointed out
* add note about set_block race
* remove tested-by again, the spinlock change is a little too invasive to claim testing
TODO
* convert toshiba, thinkpad
Documentation/rfkill.txt | 639 +++------------------ MAINTAINERS | 6 arch/arm/mach-pxa/tosa-bt.c | 30 - arch/arm/mach-pxa/tosa.c | 1 drivers/net/usb/hso.c | 42 - drivers/net/wireless/ath/ath9k/ath9k.h | 7 drivers/net/wireless/ath/ath9k/main.c | 115 --- drivers/net/wireless/ath/ath9k/pci.c | 15 drivers/net/wireless/b43/Kconfig | 2 drivers/net/wireless/b43/leds.c | 2 drivers/net/wireless/b43/main.c | 4 drivers/net/wireless/b43/phy_a.c | 4 drivers/net/wireless/b43/phy_common.c | 17 drivers/net/wireless/b43/phy_common.h | 4 drivers/net/wireless/b43/phy_g.c | 4 drivers/net/wireless/b43/phy_lp.c | 2 drivers/net/wireless/b43/phy_n.c | 2 drivers/net/wireless/b43/rfkill.c | 123 +--- drivers/net/wireless/b43/rfkill.h | 5 drivers/net/wireless/b43legacy/Kconfig | 2 drivers/net/wireless/b43legacy/leds.c | 3 drivers/net/wireless/b43legacy/rfkill.c | 123 +--- drivers/net/wireless/b43legacy/rfkill.h | 6 drivers/net/wireless/iwlwifi/Kconfig | 5 drivers/net/wireless/iwlwifi/iwl-rfkill.c | 69 -- drivers/platform/x86/Kconfig | 6 drivers/platform/x86/acer-wmi.c | 50 - drivers/platform/x86/dell-laptop.c | 101 +-- drivers/platform/x86/eeepc-laptop.c | 122 +--- drivers/platform/x86/hp-wmi.c | 103 +-- drivers/platform/x86/sony-laptop.c | 115 +-- drivers/platform/x86/toshiba_acpi.c | 23 include/linux/Kbuild | 1 include/linux/rfkill.h | 348 +++++++++-- include/net/wimax.h | 8 net/rfkill/Kconfig | 14 net/rfkill/Makefile | 4 net/rfkill/core.c | 895 ++++++++++++++++++++++++++++++ net/rfkill/input.c | 342 +++++++++++ net/rfkill/rfkill-input.c | 390 ------------- net/rfkill/rfkill-input.h | 21 net/rfkill/rfkill.c | 855 ---------------------------- net/rfkill/rfkill.h | 27 net/wimax/Kconfig | 14 net/wimax/op-rfkill.c | 125 ---- 45 files changed, 2088 insertions(+), 2708 deletions(-)
include/linux/rfkill.h +275 -73
@@ -4,6 +4,7 @@/* * Copyright (C) 2006 - 2007 Ivo van Doorn * Copyright (C) 2007 Dmitry Torokhov +* Copyright 2009 Johannes Berg <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -21,6 +22,24 @@* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* define userspace visible states */ +#define RFKILL_STATE_SOFT_BLOCKED 0 +#define RFKILL_STATE_UNBLOCKED 1 +#define RFKILL_STATE_HARD_BLOCKED 2 + +/* and that's all userspace gets */ +#ifdef __KERNEL__ +/* don't allow anyone to use these in the kernel */ +enum rfkill_user_states { +RFKILL_USER_STATE_SOFT_BLOCKED =RFKILL_STATE_SOFT_BLOCKED , +RFKILL_USER_STATE_UNBLOCKED =RFKILL_STATE_UNBLOCKED , +RFKILL_USER_STATE_HARD_BLOCKED =RFKILL_STATE_HARD_BLOCKED , +}; +#undef RFKILL_STATE_SOFT_BLOCKED +#undef RFKILL_STATE_UNBLOCKED +#undef RFKILL_STATE_HARD_BLOCKED +#include <linux/types.h> #include <linux/kernel.h> #include <linux/list.h>
@@ -30,11 +49,13 @@/** * enum rfkill_type - type of rfkill switch. -* RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. -* RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. -* RFKILL_TYPE_UWB: switch is on a ultra wideband device. -* RFKILL_TYPE_WIMAX: switch is on a WiMAX device. -* RFKILL_TYPE_WWAN: switch is on a wireless WAN device. +* +* @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. +* @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. +* @RFKILL_TYPE_UWB: switch is on a ultra wideband device. +* @RFKILL_TYPE_WIMAX: switch is on a WiMAX device. +* @RFKILL_TYPE_WWAN: switch is on a wireless WAN device. +* @NUM_RFKILL_TYPES: number of defined rfkill types */ enum rfkill_type {RFKILL_TYPE_WLAN ,
@@ -42,97 +63,278 @@ enum rfkill_type {RFKILL_TYPE_UWB ,RFKILL_TYPE_WIMAX ,RFKILL_TYPE_WWAN , - RFKILL_TYPE_MAX, + NUM_RFKILL_TYPES, }; -enum rfkill_state { -RFKILL_STATE_SOFT_BLOCKED =0 ,/* Radio output blocked */ -RFKILL_STATE_UNBLOCKED =1 ,/* Radio output allowed */ -RFKILL_STATE_HARD_BLOCKED =2 ,/* Output blocked, non-overrideable */ -RFKILL_STATE_MAX ,/* marker for last valid state */ +/* this is opaque */ +struct rfkill ; + +/** +* struct rfkill_ops - rfkill driver methods +* +* @poll: poll the rfkill block state(s) -- only assign this method +* when you need polling. When called, simply call one of the +* rfkill_set{,_hw,_sw}_state family of functions. If the hw +* is getting unblocked you need to take into account the return +* value of those functions to make sure the software block is +* properly used. +* @query: query the rfkill hardware block state (return true +* for blocked) -- assign this method if input events can cause +* hardware state changes to make the rfkill core query your +* driver before setting a requested block +* @set_block: turn the transmitter on (blocked == false) or off +* (blocked == true) -- this is called only while the transmitter +* is not hard-blocked, but note that the core's view of whether +* the transmitter is hard-blocked might differ from your driver's +* view due to race conditions, so it is possible that it is still +* called at the same time as you are calling rfkill_set_hw_state(). +* This callback must be assigned. +*/ +struct rfkill_ops { +void (*poll)(struct rfkill *rfkill,void *data); +void (*query)(struct rfkill *rfkill,void *data); +int (*set_block)(void *data,bool blocked); }; +#if defined(CONFIG_RFKILL ) || defined(CONFIG_RFKILL_MODULE )/** -* struct rfkill - rfkill control structure. -* @name: Name of the switch. -* @type: Radio type which the button controls, the value stored -* here should be a value from enum rfkill_type. -* @state: State of the switch, "UNBLOCKED" means radio can operate. -* @mutex: Guards switch state transitions. It serializes callbacks -* and also protects the state. -* @data: Pointer to the RF button drivers private data which will be -* passed along when toggling radio state. -* @toggle_radio(): Mandatory handler to control state of the radio. -* only RFKILL_STATE_SOFT_BLOCKED and RFKILL_STATE_UNBLOCKED are -* valid parameters. -* @get_state(): handler to read current radio state from hardware, -* may be called from atomic context, should return 0 on success. -* Either this handler OR judicious use of rfkill_force_state() is -* MANDATORY for any driver capable of RFKILL_STATE_HARD_BLOCKED. -* @led_trigger: A LED trigger for this button's LED. -* @dev: Device structure integrating the switch into device tree. -* @node: Used to place switch into list of all switches known to the -* the system. -* -* This structure represents a RF switch located on a network device. -*/ -struct rfkill { -const char *name; -enum rfkill_type type; - -/* the mutex serializes callbacks and also protects -* the state */ -struct mutex mutex; -enum rfkill_state state; -void *data; -int (*toggle_radio)(void *data,enum rfkill_state state); -int (*get_state)(void *data,enum rfkill_state *state); +* rfkill_alloc - allocate rfkill structure +* @name: name of the struct -- the string is not copied internally +* @parent: device that has rf switch on it +* @type: type of the switch (RFKILL_TYPE_*) +* @ops: rfkill methods +* @ops_data: data passed to each method +* +* This function should be called by the transmitter driver to allocate an +* rfkill structure. Returns %NULL on failure. +*/ +struct rfkill *__must_check rfkill_alloc (const char *name, +struct device *parent, +const enum rfkill_type type, +const struct rfkill_ops *ops, +void *ops_data); -#ifdef CONFIG_RFKILL_LEDS -struct led_trigger led_trigger; -#endif +/** +* rfkill_has_sw_block_memory -- turn on calling set_block unconditionally +* @rfkill: rfkill struct +* +* This function tells the rfkill core that the device is capable of +* remembering soft blocks (which it is notified of via the set_block +* method) -- this means that the driver may ignore the return value +* from rfkill_set_hw_state(). +* +* This function must be called before rfkill_register(). +*/ +void rfkill_has_sw_block_memory (struct rfkill *rfkill); -struct device dev; -struct list_head node; -enum rfkill_state state_for_resume; -}; -#define to_rfkill (d) container_of(d, struct rfkill, dev) +/** +* rfkill_set_led_trigger_name -- set the LED trigger name +* @rfkill: rfkill struct +* @name: LED trigger name +* +* This function sets the LED trigger name of the radio LED +* trigger that rfkill creates. It is optional, but if called +* must be called before rfkill_register() to be effective. +*/ +void rfkill_set_led_trigger_name (struct rfkill *rfkill,const char *name); -struct rfkill *__must_check rfkill_allocate (struct device *parent, -enum rfkill_type type); -void rfkill_free (struct rfkill *rfkill); +/** +* rfkill_register - Register a rfkill structure. +* @rfkill: rfkill structure to be registered +* +* This function should be called by the transmitter driver to register +* the rfkill structure needs to be registered. Before calling this function +* the driver needs to be ready to service method calls from rfkill. +*/ int __must_check rfkill_register (struct rfkill *rfkill); + +/** +* rfkill_pause_polling(struct rfkill *rfkill) +* +* Pause polling -- say transmitter is off for other reasons. +* NOTE: not necessary for suspend/resume -- in that case the +* core stops polling anyway +*/ +void rfkill_pause_polling (struct rfkill *rfkill); + +/** +* rfkill_resume_polling(struct rfkill *rfkill) +* +* Pause polling -- say transmitter is off for other reasons. +* NOTE: not necessary for suspend/resume -- in that case the +* core stops polling anyway +*/ +void rfkill_resume_polling (struct rfkill *rfkill); + + +/** +* rfkill_unregister - Unregister a rfkill structure. +* @rfkill: rfkill structure to be unregistered +* +* This function should be called by the network driver during device +* teardown to destroy rfkill structure. Until it returns, the driver +* needs to be able to service method calls. +*/ void rfkill_unregister (struct rfkill *rfkill); -int rfkill_force_state (struct rfkill *rfkill,enum rfkill_state state); -int rfkill_set_default (enum rfkill_type type,enum rfkill_state state); +/** +* rfkill_destroy - free rfkill structure +* @rfkill: rfkill structure to be destroyed +* +* Destroys the rfkill structure. +*/ +void rfkill_destroy (struct rfkill *rfkill); + +/** +* rfkill_set_hw_state - Set the internal rfkill hardware block state +* @rfkill: pointer to the rfkill class to modify. +* @state: the current hardware block state to set +* +* rfkill drivers that get events when the hard-blocked state changes +* use this function to notify the rfkill core (and through that also +* userspace) of the current state -- they should also use this after +* resume if the state could have changed. +* +* You need not (but may) call this function if poll_state is assigned. +* +* This function can be called in any context, even from within rfkill +* callbacks. +* +* The function returns the combined block state (true if transmitter +* should be blocked) so that drivers need not keep track of the soft +* block state -- which they might not be able to. +* +* If the device is able to, call rfkill_has_sw_block_memory() and +* ignore the return value of this function. +*/ +bool __must_check rfkill_set_hw_state (struct rfkill *rfkill,bool blocked); + +/** +* rfkill_set_sw_state - Set the internal rfkill software block state +* @rfkill: pointer to the rfkill class to modify. +* @state: the current software block state to set +* +* rfkill drivers that get events when the soft-blocked state changes +* (yes, some platforms directly act on input but allow changing again) +* use this function to notify the rfkill core (and through that also +* userspace) of the current state -- they should also use this after +* resume if the state could have changed. +* +* This function can be called in any context, even from within rfkill +* callbacks. +* +* The function returns the combined block state (true if transmitter +* should be blocked). +*/ +bool rfkill_set_sw_state (struct rfkill *rfkill,bool blocked); + +/** +* rfkill_set_states - Set the internal rfkill block states +* @rfkill: pointer to the rfkill class to modify. +* @sw: the current software block state to set +* @hw: the current hardware block state to set +* +* This function can be called in any context, even from within rfkill +* callbacks. +*/ +void rfkill_set_states (struct rfkill *rfkill,bool sw,bool hw);/** -* rfkill_state_complement - return complementar state -* @state: state to return the complement of +* rfkill_set_global_sw_state - set global sw block default +* @type: rfkill type to set default for +* @blocked: default to set * -* Returns RFKILL_STATE_SOFT_BLOCKED if @state is RFKILL_STATE_UNBLOCKED, -* returns RFKILL_STATE_UNBLOCKED otherwise. +* This function sets the global default -- use at boot if your platform has +* an rfkill switch. If not early enough this call may be ignored. +* +* XXX: instead of ignoring -- how about just updating all currently +* registered drivers? */ -static inline enum rfkill_state rfkill_state_complement (enum rfkill_state state) +void rfkill_set_global_sw_state (const enum rfkill_type type,bool blocked); +#else /* !RFKILL */ +static inline struct rfkill *__must_check +rfkill_alloc (const char *name, +struct device *parent, +const enum rfkill_type type, +const struct rfkill_ops *ops, +void *ops_data) +{ +return ERR_PTR (-ENODEV ); +} + +static inline void rfkill_has_sw_block_memory (struct rfkill *rfkill) +{ +} + +static inline int __must_check rfkill_register (struct rfkill *rfkill) +{ +if (rfkill ==ERR_PTR (-ENODEV )) +return 0 ; +return -EINVAL ; +} + +static inline void rfkill_pause_polling (struct rfkill *rfkill) +{ +} + +static inline void rfkill_resume_polling (struct rfkill *rfkill) +{ +} + +static inline void rfkill_unregister (struct rfkill *rfkill) +{ +} + +static inline void rfkill_destroy (struct rfkill *rfkill) +{ +} + +static inline bool rfkill_set_hw_state (struct rfkill *rfkill,bool blocked) +{ +return blocked; +} + +static inline bool rfkill_set_sw_state (struct rfkill *rfkill,bool blocked) { -return (state ==RFKILL_STATE_UNBLOCKED ) ? -RFKILL_STATE_SOFT_BLOCKED :RFKILL_STATE_UNBLOCKED ; +return blocked; } +static inline void rfkill_set_global_sw_state (const enum rfkill_type type, +bool blocked) +{ +} +#endif /* RFKILL || RFKILL_MODULE */ + + +#ifdef CONFIG_RFKILL_LEDS /** -* rfkill_get_led_name - Get the LED trigger name for the button's LED. +* rfkill_get_led_trigger_name - Get the LED trigger name for the button's LED. * This function might return a NULL pointer if registering of the -* LED trigger failed. -* Use this as "default_trigger" for the LED. +* LED trigger failed. Use this as "default_trigger" for the LED. */ -static inline char *rfkill_get_led_name (struct rfkill *rfkill) -{ -#ifdef CONFIG_RFKILL_LEDS -return (char *)(rfkill->led_trigger.name); +const char *rfkill_get_led_trigger_name (struct rfkill *rfkill); + +/** +* rfkill_set_led_trigger_name -- set the LED trigger name +* @rfkill: rfkill struct +* @name: LED trigger name +* +* This function sets the LED trigger name of the radio LED +* trigger that rfkill creates. It is optional, but if called +* must be called before rfkill_register() to be effective. +*/ +void rfkill_set_led_trigger_name (struct rfkill *rfkill,const char *name);#else +static inline const char *rfkill_get_led_trigger_name (struct rfkill *rfkill) +{return NULL ; -#endif } +void rfkill_set_led_trigger_name (struct rfkill *rfkill,const char *name) +{ +} +#endif + +#endif /* __KERNEL__ */ +#endif /* RFKILL_H */
drivers/net/wireless/ath/ath9k/main.c +29 -86
169 lines not on this page · raw message
drivers/platform/x86/eeepc-laptop.c +49 -73
193 lines not on this page · raw message
net/rfkill/rfkill.c deleted +0 -855
855 lines not on this page · raw message
net/rfkill/rfkill-input.h deleted +0 -21
@@ -1,21 +0,0 @@ -/* -* Copyright (C) 2007 Ivo van Doorn -*/ - -/* -* This program is free software; you can redistribute it and/or modify it -* under the terms of the GNU General Public License version 2 as published -* by the Free Software Foundation. -*/ - -#ifndef __RFKILL_INPUT_H -#define __RFKILL_INPUT_H - -void rfkill_switch_all (enum rfkill_type type,enum rfkill_state state); -void rfkill_epo (void ); -void rfkill_restore_states (void ); -void rfkill_remove_epo_lock (void ); -bool rfkill_is_epo_lock_active (void ); -enum rfkill_state rfkill_get_global_state (const enum rfkill_type type); - -#endif /* __RFKILL_INPUT_H */
net/rfkill/rfkill-input.c deleted +0 -390
390 lines not on this page · raw message
drivers/net/wireless/b43/main.c +2 -2
@@ -3470,7 +3470,7 @@ static int b43_op_config(struct ieee8021if (!!conf->radio_enabled != phy->radio_on) {if (conf->radio_enabled) { -b43_software_rfkill (dev,RFKILL_STATE_UNBLOCKED ); +b43_software_rfkill (dev, false);b43info (dev->wl,"Radio turned on by software\n" );if (!dev->radio_hw_enable) { b43info(dev->wl, "The hardware RF-kill button "
@@ -3478,7 +3478,7 @@ static int b43_op_config(struct ieee8021 "Press the button to turn it on.\n"); } }else { -b43_software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); +b43_software_rfkill (dev, true);b43info (dev->wl,"Radio turned off by software\n" ); } }
drivers/net/wireless/b43/phy_a.c +2 -2
@@ -480,11 +480,11 @@ static bool b43_aphy_op_supports_hwpctl( }static void b43_aphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {struct b43_phy *phy = &dev->phy; -if (state ==RFKILL_STATE_UNBLOCKED ) { +if (!blocked) {if (phy->radio_on)return ;b43_radio_write16 (dev,0x0004 ,0x00C0 );
drivers/net/wireless/b43/phy_common.c +6 -11
@@ -84,7 +84,7 @@ int b43_phy_init(struct b43_wldev *dev) phy->channel = ops->get_default_chan (dev); - ops->software_rfkill (dev,RFKILL_STATE_UNBLOCKED ); + ops->software_rfkill (dev, false); err = ops->init (dev);if (err) {b43err (dev->wl,"PHY init failed\n" );
@@ -104,7 +104,7 @@ err_phy_exit:if (ops->exit) ops->exit (dev); err_block_rf: - ops->software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); + ops->software_rfkill (dev, true);return err; }
@@ -113,7 +113,7 @@ void b43_phy_exit(struct b43_wldev *dev) {const struct b43_phy_operations *ops = dev->phy.ops; - ops->software_rfkill (dev,RFKILL_STATE_SOFT_BLOCKED ); + ops->software_rfkill (dev, true);if (ops->exit) ops->exit (dev); }
@@ -295,18 +295,13 @@ err_restore_cookie:return err; } -void b43_software_rfkill (struct b43_wldev *dev,enum rfkill_state state) +void b43_software_rfkill (struct b43_wldev *dev,bool blocked) {struct b43_phy *phy = &dev->phy; -if (state ==RFKILL_STATE_HARD_BLOCKED ) { -/* We cannot hardware-block the device */ - state =RFKILL_STATE_SOFT_BLOCKED ; - } -b43_mac_suspend (dev); - phy->ops->software_rfkill (dev, state); - phy->radio_on = (state ==RFKILL_STATE_UNBLOCKED ); + phy->ops->software_rfkill (dev, blocked); + phy->radio_on = !blocked;b43_mac_enable (dev); }
drivers/net/wireless/b43/phy_common.h +2 -2
@@ -159,7 +159,7 @@ struct b43_phy_operations {/* Radio */ bool (*supports_hwpctl)(struct b43_wldev *dev); -void (*software_rfkill)(struct b43_wldev *dev,enum rfkill_state state); +void (*software_rfkill)(struct b43_wldev *dev,bool blocked);void (*switch_analog)(struct b43_wldev *dev,bool on);int (*switch_channel)(struct b43_wldev *dev,unsigned int new_channel);unsigned int (*get_default_chan)(struct b43_wldev *dev);
@@ -364,7 +364,7 @@ int b43_switch_channel(struct b43_wldev/** * b43_software_rfkill - Turn the radio ON or OFF in software. */ -void b43_software_rfkill (struct b43_wldev *dev,enum rfkill_state state); +void b43_software_rfkill (struct b43_wldev *dev,bool blocked);/** * b43_phy_txpower_check - Check TX power output.
drivers/net/wireless/b43/phy_g.c +2 -2
@@ -2592,7 +2592,7 @@ static bool b43_gphy_op_supports_hwpctl( }static void b43_gphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {struct b43_phy *phy = &dev->phy;struct b43_phy_g *gphy = phy->g;
@@ -2600,7 +2600,7 @@ static void b43_gphy_op_software_rfkill(might_sleep (); -if (state ==RFKILL_STATE_UNBLOCKED ) { +if (!blocked) {/* Turn radio ON */ if (phy->radio_on)return ;
drivers/net/wireless/b43/phy_n.c +1 -1
@@ -579,7 +579,7 @@ static void b43_nphy_op_radio_write(stru }static void b43_nphy_op_software_rfkill (struct b43_wldev *dev, -enum rfkill_state state) +bool blocked) {//TODO }
drivers/net/wireless/b43/rfkill.c +34 -89
188 lines not on this page · raw message
drivers/net/wireless/b43legacy/rfkill.c +39 -84
192 lines not on this page · raw message
drivers/net/wireless/iwlwifi/iwl-rfkill.c +28 -41
124 lines not on this page · raw message
Documentation/rfkill.txt +100 -539
359 lines not on this page · raw message
net/rfkill/Kconfig +0 -14
Lines of this file are not shown. View the raw message.
net/rfkill/Makefile +2 -2
Lines of this file are not shown. View the raw message.
net/rfkill/core.c new file +895 -0
895 lines not on this page · raw message
net/rfkill/input.c new file +342 -0
342 lines not on this page · raw message
net/rfkill/rfkill.h new file +27 -0
Lines of this file are not shown. View the raw message.
MAINTAINERS +3 -3
Lines of this file are not shown. View the raw message.
include/linux/Kbuild +1 -0
Lines of this file are not shown. View the raw message.
drivers/net/wireless/ath/ath9k/ath9k.h +1 -6
Lines of this file are not shown. View the raw message.
drivers/net/wireless/ath/ath9k/pci.c +0 -15
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/Kconfig +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/rfkill.h +1 -4
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/Kconfig +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/leds.c +2 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43legacy/rfkill.h +1 -5
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/leds.c +1 -1
Lines of this file are not shown. View the raw message.
drivers/net/wireless/iwlwifi/Kconfig +2 -3
Lines of this file are not shown. View the raw message.
drivers/net/wireless/b43/phy_lp.c +1 -1
Lines of this file are not shown. View the raw message.
drivers/platform/x86/Kconfig +0 -6
Lines of this file are not shown. View the raw message.
drivers/platform/x86/acer-wmi.c +22 -28
50 lines not on this page · raw message
drivers/platform/x86/dell-laptop.c +32 -69
101 lines not on this page · raw message
drivers/platform/x86/hp-wmi.c +52 -51
103 lines not on this page · raw message
drivers/platform/x86/toshiba_acpi.c +7 -16
Lines of this file are not shown. View the raw message.
arch/arm/mach-pxa/tosa-bt.c +15 -15
Lines of this file are not shown. View the raw message.
arch/arm/mach-pxa/tosa.c +0 -1
Lines of this file are not shown. View the raw message.
include/net/wimax.h +2 -6
Lines of this file are not shown. View the raw message.
net/wimax/op-rfkill.c +28 -97
125 lines not on this page · raw message
net/wimax/Kconfig +0 -14
Lines of this file are not shown. View the raw message.
drivers/net/usb/hso.c +22 -20
42 lines not on this page · raw message
drivers/platform/x86/sony-laptop.c +58 -57
115 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Quoted 10 lines · Johannes Berg
Quoted 6 lines
The return values for
rfkill_alloc()are not the same on the stub and real functions. The stub function usesERR_PTR, while the real
function uses NULL for any errors. Please make them do the same
thing, and it is probably a damn good idea to document in the kerneldoc what kind of return values one should expect when you return a pointer and the function can fail (i.e. NULL orERR_PTR).Actually, I was going to clean this up, and then I noticed you're wrong. :) Returning
ERR_PTR(-ENODEV)is intentional, in the non-RFKILL case. Imagine a driver like this:
Well, that's confusing as all heck... document it, please? I still think in that case, we'd be better off if rfkill_alloc always uses the ERR_PTR convention.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Johannes Berg
maintainerQuoted 5 lines · Henrique de Moraes Holschuh
Quoted 3 lines
Actually, I was going to clean this up, and then I noticed you're wrong. :) Returning
ERR_PTR(-ENODEV)is intentional, in the non-RFKILL case. Imagine a driver like this:Well, that's confusing as all heck... document it, please?
Well, ok. I don't really think it's all that confusing since you don't need to think about the non-RFKILL code, you can just write the code as though rfkill was always enabled.
Quoted 3 lines
I still think in
that case, we'd be better off ifrfkill_allocalways uses theERR_PTRconvention.
Umm, no, think again. If we do that, the driver won't do
if (!rf) but if (IS_ERR(rf))
and the advantage is lost.
This is exactly what debugfs does too.
johannes