aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2009-06-02 07:01:37 -0400
committerJohn W. Linville <linville@tuxdriver.com>2009-06-03 14:06:13 -0400
commit19d337dff95cbf76edd3ad95c0cee2732c3e1ec5 (patch)
tree33326eeb09cb9664cc8427a5dc7cd2b08b5a57c3 /include/linux
parent0f6399c4c525b518644a9b09f8d6fb125a418c4d (diff)
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 Tested-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk> Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br> [thinkpad] Signed-off-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/Kbuild1
-rw-r--r--include/linux/rfkill.h325
2 files changed, 252 insertions, 74 deletions
diff --git a/include/linux/Kbuild b/include/linux/Kbuild
index 3f0eaa397ef..7e09c5c1ed0 100644
--- a/include/linux/Kbuild
+++ b/include/linux/Kbuild
@@ -311,6 +311,7 @@ unifdef-y += ptrace.h
311unifdef-y += qnx4_fs.h 311unifdef-y += qnx4_fs.h
312unifdef-y += quota.h 312unifdef-y += quota.h
313unifdef-y += random.h 313unifdef-y += random.h
314unifdef-y += rfkill.h
314unifdef-y += irqnr.h 315unifdef-y += irqnr.h
315unifdef-y += reboot.h 316unifdef-y += reboot.h
316unifdef-y += reiserfs_fs.h 317unifdef-y += reiserfs_fs.h
diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
index de18ef227e0..090852c8de7 100644
--- a/include/linux/rfkill.h
+++ b/include/linux/rfkill.h
@@ -4,6 +4,7 @@
4/* 4/*
5 * Copyright (C) 2006 - 2007 Ivo van Doorn 5 * Copyright (C) 2006 - 2007 Ivo van Doorn
6 * Copyright (C) 2007 Dmitry Torokhov 6 * Copyright (C) 2007 Dmitry Torokhov
7 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
@@ -21,6 +22,24 @@
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */ 23 */
23 24
25
26/* define userspace visible states */
27#define RFKILL_STATE_SOFT_BLOCKED 0
28#define RFKILL_STATE_UNBLOCKED 1
29#define RFKILL_STATE_HARD_BLOCKED 2
30
31/* and that's all userspace gets */
32#ifdef __KERNEL__
33/* don't allow anyone to use these in the kernel */
34enum rfkill_user_states {
35 RFKILL_USER_STATE_SOFT_BLOCKED = RFKILL_STATE_SOFT_BLOCKED,
36 RFKILL_USER_STATE_UNBLOCKED = RFKILL_STATE_UNBLOCKED,
37 RFKILL_USER_STATE_HARD_BLOCKED = RFKILL_STATE_HARD_BLOCKED,
38};
39#undef RFKILL_STATE_SOFT_BLOCKED
40#undef RFKILL_STATE_UNBLOCKED
41#undef RFKILL_STATE_HARD_BLOCKED
42
24#include <linux/types.h> 43#include <linux/types.h>
25#include <linux/kernel.h> 44#include <linux/kernel.h>
26#include <linux/list.h> 45#include <linux/list.h>
@@ -30,109 +49,267 @@
30 49
31/** 50/**
32 * enum rfkill_type - type of rfkill switch. 51 * enum rfkill_type - type of rfkill switch.
33 * RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. 52 *
34 * RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. 53 * @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device.
35 * RFKILL_TYPE_UWB: switch is on a ultra wideband device. 54 * @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device.
36 * RFKILL_TYPE_WIMAX: switch is on a WiMAX device. 55 * @RFKILL_TYPE_UWB: switch is on a ultra wideband device.
37 * RFKILL_TYPE_WWAN: switch is on a wireless WAN device. 56 * @RFKILL_TYPE_WIMAX: switch is on a WiMAX device.
57 * @RFKILL_TYPE_WWAN: switch is on a wireless WAN device.
58 * @NUM_RFKILL_TYPES: number of defined rfkill types
38 */ 59 */
39enum rfkill_type { 60enum rfkill_type {
40 RFKILL_TYPE_WLAN , 61 RFKILL_TYPE_WLAN,
41 RFKILL_TYPE_BLUETOOTH, 62 RFKILL_TYPE_BLUETOOTH,
42 RFKILL_TYPE_UWB, 63 RFKILL_TYPE_UWB,
43 RFKILL_TYPE_WIMAX, 64 RFKILL_TYPE_WIMAX,
44 RFKILL_TYPE_WWAN, 65 RFKILL_TYPE_WWAN,
45 RFKILL_TYPE_MAX, 66 NUM_RFKILL_TYPES,
46}; 67};
47 68
48enum rfkill_state { 69/* this is opaque */
49 RFKILL_STATE_SOFT_BLOCKED = 0, /* Radio output blocked */ 70struct rfkill;
50 RFKILL_STATE_UNBLOCKED = 1, /* Radio output allowed */ 71
51 RFKILL_STATE_HARD_BLOCKED = 2, /* Output blocked, non-overrideable */ 72/**
52 RFKILL_STATE_MAX, /* marker for last valid state */ 73 * struct rfkill_ops - rfkill driver methods
74 *
75 * @poll: poll the rfkill block state(s) -- only assign this method
76 * when you need polling. When called, simply call one of the
77 * rfkill_set{,_hw,_sw}_state family of functions. If the hw
78 * is getting unblocked you need to take into account the return
79 * value of those functions to make sure the software block is
80 * properly used.
81 * @query: query the rfkill block state(s) and call exactly one of the
82 * rfkill_set{,_hw,_sw}_state family of functions. Assign this
83 * method if input events can cause hardware state changes to make
84 * the rfkill core query your driver before setting a requested
85 * block.
86 * @set_block: turn the transmitter on (blocked == false) or off
87 * (blocked == true) -- this is called only while the transmitter
88 * is not hard-blocked, but note that the core's view of whether
89 * the transmitter is hard-blocked might differ from your driver's
90 * view due to race conditions, so it is possible that it is still
91 * called at the same time as you are calling rfkill_set_hw_state().
92 * This callback must be assigned.
93 */
94struct rfkill_ops {
95 void (*poll)(struct rfkill *rfkill, void *data);
96 void (*query)(struct rfkill *rfkill, void *data);
97 int (*set_block)(void *data, bool blocked);
53}; 98};
54 99
100#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
55/** 101/**
56 * struct rfkill - rfkill control structure. 102 * rfkill_alloc - allocate rfkill structure
57 * @name: Name of the switch. 103 * @name: name of the struct -- the string is not copied internally
58 * @type: Radio type which the button controls, the value stored 104 * @parent: device that has rf switch on it
59 * here should be a value from enum rfkill_type. 105 * @type: type of the switch (RFKILL_TYPE_*)
60 * @state: State of the switch, "UNBLOCKED" means radio can operate. 106 * @ops: rfkill methods
61 * @mutex: Guards switch state transitions. It serializes callbacks 107 * @ops_data: data passed to each method
62 * and also protects the state. 108 *
63 * @data: Pointer to the RF button drivers private data which will be 109 * This function should be called by the transmitter driver to allocate an
64 * passed along when toggling radio state. 110 * rfkill structure. Returns %NULL on failure.
65 * @toggle_radio(): Mandatory handler to control state of the radio.
66 * only RFKILL_STATE_SOFT_BLOCKED and RFKILL_STATE_UNBLOCKED are
67 * valid parameters.
68 * @get_state(): handler to read current radio state from hardware,
69 * may be called from atomic context, should return 0 on success.
70 * Either this handler OR judicious use of rfkill_force_state() is
71 * MANDATORY for any driver capable of RFKILL_STATE_HARD_BLOCKED.
72 * @led_trigger: A LED trigger for this button's LED.
73 * @dev: Device structure integrating the switch into device tree.
74 * @node: Used to place switch into list of all switches known to the
75 * the system.
76 *
77 * This structure represents a RF switch located on a network device.
78 */ 111 */
79struct rfkill { 112struct rfkill * __must_check rfkill_alloc(const char *name,
80 const char *name; 113 struct device *parent,
81 enum rfkill_type type; 114 const enum rfkill_type type,
82 115 const struct rfkill_ops *ops,
83 /* the mutex serializes callbacks and also protects 116 void *ops_data);
84 * the state */
85 struct mutex mutex;
86 enum rfkill_state state;
87 void *data;
88 int (*toggle_radio)(void *data, enum rfkill_state state);
89 int (*get_state)(void *data, enum rfkill_state *state);
90 117
91#ifdef CONFIG_RFKILL_LEDS 118/**
92 struct led_trigger led_trigger; 119 * rfkill_register - Register a rfkill structure.
93#endif 120 * @rfkill: rfkill structure to be registered
121 *
122 * This function should be called by the transmitter driver to register
123 * the rfkill structure needs to be registered. Before calling this function
124 * the driver needs to be ready to service method calls from rfkill.
125 */
126int __must_check rfkill_register(struct rfkill *rfkill);
94 127
95 struct device dev; 128/**
96 struct list_head node; 129 * rfkill_pause_polling(struct rfkill *rfkill)
97 enum rfkill_state state_for_resume; 130 *
98}; 131 * Pause polling -- say transmitter is off for other reasons.
99#define to_rfkill(d) container_of(d, struct rfkill, dev) 132 * NOTE: not necessary for suspend/resume -- in that case the
133 * core stops polling anyway
134 */
135void rfkill_pause_polling(struct rfkill *rfkill);
100 136
101struct rfkill * __must_check rfkill_allocate(struct device *parent, 137/**
102 enum rfkill_type type); 138 * rfkill_resume_polling(struct rfkill *rfkill)
103void rfkill_free(struct rfkill *rfkill); 139 *
104int __must_check rfkill_register(struct rfkill *rfkill); 140 * Pause polling -- say transmitter is off for other reasons.
141 * NOTE: not necessary for suspend/resume -- in that case the
142 * core stops polling anyway
143 */