aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless
diff options
context:
space:
mode:
authorIvo van Doorn <ivdoorn@gmail.com>2008-03-13 10:38:03 -0400
committerJohn W. Linville <linville@tuxdriver.com>2008-03-13 15:57:26 -0400
commit1682fe6de206bd1e937529cbb393915e5ea40b2c (patch)
tree4890282b3ea30708d27667015664d6b742261277 /drivers/net/wireless
parentf50e4a8494a74bdbc0f86f1430a4cca2a4f28799 (diff)
rt2x00: Add suspend/resume handlers to rt2x00rfkill
Add suspend/resume handlers to rt2x00rfkill to have it stop the input-polldev and prevent it from calling rt2x00 during suspend period. This could lead to a NULL pointer fault when rt2x00 suspended, but polldev send a request, because the csr_addr is NULL. Also don't let the rfkill allocation/registration block the initialization of the entire device. Just print a warning and continue as if nothing happened. Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless')
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00.h3
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c35
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00lib.h20
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00rfkill.c116
4 files changed, 106 insertions, 68 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
index 05927b908f80..6c725422af5a 100644
--- a/drivers/net/wireless/rt2x00/rt2x00.h
+++ b/drivers/net/wireless/rt2x00/rt2x00.h
@@ -620,6 +620,9 @@ struct rt2x00_dev {
620 * This will only be compiled in when required. 620 * This will only be compiled in when required.
621 */ 621 */
622#ifdef CONFIG_RT2X00_LIB_RFKILL 622#ifdef CONFIG_RT2X00_LIB_RFKILL
623unsigned long rfkill_state;
624#define RFKILL_STATE_ALLOCATED 1
625#define RFKILL_STATE_REGISTERED 2
623 struct rfkill *rfkill; 626 struct rfkill *rfkill;
624 struct input_polled_dev *poll_dev; 627 struct input_polled_dev *poll_dev;
625#endif /* CONFIG_RT2X00_LIB_RFKILL */ 628#endif /* CONFIG_RT2X00_LIB_RFKILL */
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index 0d51f478bcdf..bc846ba12f63 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -1098,7 +1098,7 @@ static void rt2x00lib_uninitialize(struct rt2x00_dev *rt2x00dev)
1098 return; 1098 return;
1099 1099
1100 /* 1100 /*
1101 * Unregister rfkill. 1101 * Unregister extra components.
1102 */ 1102 */
1103 rt2x00rfkill_unregister(rt2x00dev); 1103 rt2x00rfkill_unregister(rt2x00dev);
1104 1104
@@ -1139,11 +1139,9 @@ static int rt2x00lib_initialize(struct rt2x00_dev *rt2x00dev)
1139 __set_bit(DEVICE_INITIALIZED, &rt2x00dev->flags); 1139 __set_bit(DEVICE_INITIALIZED, &rt2x00dev->flags);
1140 1140
1141 /* 1141 /*
1142 * Register the rfkill handler. 1142 * Register the extra components.
1143 */ 1143 */
1144 status = rt2x00rfkill_register(rt2x00dev); 1144 rt2x00rfkill_register(rt2x00dev);
1145 if (status)
1146 goto exit_unitialize;
1147 1145
1148 return 0; 1146 return 0;
1149 1147
@@ -1313,15 +1311,9 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
1313 } 1311 }
1314 1312
1315 /* 1313 /*
1316 * Allocatie rfkill. 1314 * Register extra components.
1317 */
1318 retval = rt2x00rfkill_allocate(rt2x00dev);
1319 if (retval)
1320 goto exit;
1321
1322 /*
1323 * Open the debugfs entry.
1324 */ 1315 */
1316 rt2x00rfkill_allocate(rt2x00dev);
1325 rt2x00debug_register(rt2x00dev); 1317 rt2x00debug_register(rt2x00dev);
1326 1318
1327 __set_bit(DEVICE_PRESENT, &rt2x00dev->flags); 1319 __set_bit(DEVICE_PRESENT, &rt2x00dev->flags);
@@ -1350,13 +1342,9 @@ void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
1350 rt2x00lib_uninitialize(rt2x00dev); 1342 rt2x00lib_uninitialize(rt2x00dev);
1351 1343
1352 /* 1344 /*
1353 * Close debugfs entry. 1345 * Free extra components
1354 */ 1346 */
1355 rt2x00debug_deregister(rt2x00dev); 1347 rt2x00debug_deregister(rt2x00dev);
1356
1357 /*
1358 * Free rfkill
1359 */
1360 rt2x00rfkill_free(rt2x00dev); 1348 rt2x00rfkill_free(rt2x00dev);
1361 1349
1362 /* 1350 /*
@@ -1395,11 +1383,15 @@ int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state)
1395 __set_bit(DEVICE_STARTED_SUSPEND, &rt2x00dev->flags); 1383 __set_bit(DEVICE_STARTED_SUSPEND, &rt2x00dev->flags);
1396 1384
1397 /* 1385 /*
1398 * Disable radio and unitialize all items 1386 * Disable radio.
1399 * that must be recreated on resume.
1400 */ 1387 */
1401 rt2x00lib_stop(rt2x00dev); 1388 rt2x00lib_stop(rt2x00dev);
1402 rt2x00lib_uninitialize(rt2x00dev); 1389 rt2x00lib_uninitialize(rt2x00dev);
1390
1391 /*
1392 * Suspend/disable extra components.
1393 */
1394 rt2x00rfkill_suspend(rt2x00dev);
1403 rt2x00debug_deregister(rt2x00dev); 1395 rt2x00debug_deregister(rt2x00dev);
1404 1396
1405exit: 1397exit:
@@ -1422,9 +1414,10 @@ int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev)
1422 NOTICE(rt2x00dev, "Waking up.\n"); 1414 NOTICE(rt2x00dev, "Waking up.\n");
1423 1415
1424 /* 1416 /*
1425 * Open the debugfs entry. 1417 * Restore/enable extra components.
1426 */ 1418 */
1427 rt2x00debug_register(rt2x00dev); 1419 rt2x00debug_register(rt2x00dev);
1420 rt2x00rfkill_resume(rt2x00dev);
1428 1421
1429 /* 1422 /*
1430 * Only continue if mac80211 had open interfaces. 1423 * Only continue if mac80211 had open interfaces.
diff --git a/drivers/net/wireless/rt2x00/rt2x00lib.h b/drivers/net/wireless/rt2x00/rt2x00lib.h
index 1adbd28e0973..ce58c654ade1 100644
--- a/drivers/net/wireless/rt2x00/rt2x00lib.h
+++ b/drivers/net/wireless/rt2x00/rt2x00lib.h
@@ -100,28 +100,36 @@ static inline void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
100 * RFkill handlers. 100 * RFkill handlers.
101 */ 101 */
102#ifdef CONFIG_RT2X00_LIB_RFKILL 102#ifdef CONFIG_RT2X00_LIB_RFKILL
103int rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev); 103void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev);
104void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev); 104void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev);
105int rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev); 105void rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev);
106void rt2x00rfkill_free(struct rt2x00_dev *rt2x00dev); 106void rt2x00rfkill_free(struct rt2x00_dev *rt2x00dev);
107void rt2x00rfkill_suspend(struct rt2x00_dev *rt2x00dev);
108void rt2x00rfkill_resume(struct rt2x00_dev *rt2x00dev);
107#else 109#else
108static inline int rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev) 110static inline void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev)
109{ 111{
110 return 0;
111} 112}
112 113
113static inline void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev) 114static inline void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev)
114{ 115{
115} 116}
116 117
117static inline int rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev) 118static inline void rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev)
118{ 119{
119 return 0;
120} 120}
121 121
122static inline void rt2x00rfkill_free(struct rt2x00_dev *rt2x00dev) 122static inline void rt2x00rfkill_free(struct rt2x00_dev *rt2x00dev)
123{ 123{
124} 124}
125
126static inline void rt2x00rfkill_suspend(struct rt2x00_dev *rt2x00dev)
127{
128}
129
130static inline void rt2x00rfkill_resume(struct rt2x00_dev *rt2x00dev)
131{
132}
125#endif /* CONFIG_RT2X00_LIB_RFKILL */ 133#endif /* CONFIG_RT2X00_LIB_RFKILL */
126 134
127#endif /* RT2X00LIB_H */ 135#endif /* RT2X00LIB_H */
diff --git a/drivers/net/wireless/rt2x00/rt2x00rfkill.c b/drivers/net/wireless/rt2x00/rt2x00rfkill.c
index 34a96d44e306..f95577596206 100644
--- a/drivers/net/wireless/rt2x00/rt2x00rfkill.c
+++ b/drivers/net/wireless/rt2x00/rt2x00rfkill.c
@@ -69,56 +69,81 @@ static void rt2x00rfkill_poll(struct input_polled_dev *poll_dev)
69 } 69 }
70} 70}
71 71
72int rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev) 72void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev)
73{ 73{
74 int retval; 74 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags) ||
75 75 !test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state))
76 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags)) 76 return;
77 return 0;
78 77
79 retval = rfkill_register(rt2x00dev->rfkill); 78 if (rfkill_register(rt2x00dev->rfkill)) {
80 if (retval) {
81 ERROR(rt2x00dev, "Failed to register rfkill handler.\n"); 79 ERROR(rt2x00dev, "Failed to register rfkill handler.\n");
82 return retval; 80 return;
83 } 81 }
84 82
85 retval = input_register_polled_device(rt2x00dev->poll_dev); 83 if (input_register_polled_device(rt2x00dev->poll_dev)) {
86 if (retval) {
87 ERROR(rt2x00dev, "Failed to register polled device.\n"); 84 ERROR(rt2x00dev, "Failed to register polled device.\n");
88 rfkill_unregister(rt2x00dev->rfkill); 85 rfkill_unregister(rt2x00dev->rfkill);
89 return retval; 86 return;
90 } 87 }
91 88
89 __set_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state);
90
92 /* 91 /*
93 * Force initial poll which will detect the initial device state, 92 * Force initial poll which will detect the initial device state,
94 * and correctly sends the signal to the rfkill layer about this 93 * and correctly sends the signal to the rfkill layer about this
95 * state. 94 * state.
96 */ 95 */
97 rt2x00rfkill_poll(rt2x00dev->poll_dev); 96 rt2x00rfkill_poll(rt2x00dev->poll_dev);
98
99 return 0;
100} 97}
101 98
102void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev) 99void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev)
103{ 100{
104 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags)) 101 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags) ||
102 !test_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state))
105 return; 103 return;
106 104
107 input_unregister_polled_device(rt2x00dev->poll_dev); 105 input_unregister_polled_device(rt2x00dev->poll_dev);
108 rfkill_unregister(rt2x00dev->rfkill); 106 rfkill_unregister(rt2x00dev->rfkill);
107
108 __clear_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state);
109} 109}
110 110
111int rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev) 111static struct input_polled_dev *
112rt2x00rfkill_allocate_polldev(struct rt2x00_dev *rt2x00dev)
112{ 113{
113 struct device *device = wiphy_dev(rt2x00dev->hw->wiphy); 114 struct input_polled_dev *poll_dev;
115
116 poll_dev = input_allocate_polled_device();
117 if (!poll_dev)
118 return NULL;
119
120 poll_dev->private = rt2x00dev;
121 poll_dev->poll = rt2x00rfkill_poll;
122 poll_dev->poll_interval = RFKILL_POLL_INTERVAL;
123
124 poll_dev->input->name = rt2x00dev->ops->name;
125 poll_dev->input->phys = wiphy_name(rt2x00dev->hw->wiphy);
126 poll_dev->input->id.bustype = BUS_HOST;
127 poll_dev->input->id.vendor = 0x1814;
128 poll_dev->input->id.product = rt2x00dev->chip.rt;
129 poll_dev->input->id.version = rt2x00dev->chip.rev;
130 poll_dev->input->dev.parent = wiphy_dev(rt2x00dev->hw->wiphy);
131 poll_dev->input->evbit[0] = BIT(EV_KEY);
132 set_bit(KEY_WLAN, poll_dev->input->keybit);
133
134 return poll_dev;
135}
114 136
137void rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev)
138{
115 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags)) 139 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags))
116 return 0; 140 return;
117 141
118 rt2x00dev->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN); 142 rt2x00dev->rfkill =
143 rfkill_allocate(wiphy_dev(rt2x00dev->hw->wiphy), RFKILL_TYPE_WLAN);
119 if (!rt2x00dev->rfkill) { 144 if (!rt2x00dev->rfkill) {
120 ERROR(rt2x00dev, "Failed to allocate rfkill handler.\n"); 145 ERROR(rt2x00dev, "Failed to allocate rfkill handler.\n");
121 goto exit; 146 return;
122 } 147 }
123 148
124 rt2x00dev->rfkill->name = rt2x00dev->ops->name; 149 rt2x00dev->rfkill->name = rt2x00dev->ops->name;
@@ -126,40 +151,49 @@ int rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev)
126 rt2x00dev->rfkill->state = -1; 151 rt2x00dev->rfkill->state = -1;
127 rt2x00dev->rfkill->toggle_radio = rt2x00rfkill_toggle_radio; 152 rt2x00dev->rfkill->toggle_radio = rt2x00rfkill_toggle_radio;
128 153
129 rt2x00dev->poll_dev = input_allocate_polled_device(); 154 rt2x00dev->poll_dev = rt2x00rfkill_allocate_polldev(rt2x00dev);
130 if (!rt2x00dev->poll_dev) { 155 if (!rt2x00dev->poll_dev) {
131 ERROR(rt2x00dev, "Failed to allocate polled device.\n"); 156 ERROR(rt2x00dev, "Failed to allocate polled device.\n");
132 goto exit_free_rfkill; 157 rfkill_free(rt2x00dev->rfkill);
158 rt2x00dev->rfkill = NULL;
159 return;
133 } 160 }
134 161
135 rt2x00dev->poll_dev->private = rt2x00dev; 162 return;
136 rt2x00dev->poll_dev->poll = rt2x00rfkill_poll; 163}
137 rt2x00dev->poll_dev->poll_interval = RFKILL_POLL_INTERVAL;
138 164
139 rt2x00dev->poll_dev->input->name = rt2x00dev->ops->name; 165void rt2x00rfkill_free(struct rt2x00_dev *rt2x00dev)
140 rt2x00dev->poll_dev->input->phys = wiphy_name(rt2x00dev->hw->wiphy); 166{
141 rt2x00dev->poll_dev->input->id.bustype = BUS_HOST; 167 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags) ||
142 rt2x00dev->poll_dev->input->id.vendor = 0x1814; 168 !test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state))
143 rt2x00dev->poll_dev->input->id.product = rt2x00dev->chip.rt; 169 return;
144 rt2x00dev->poll_dev->input->id.version = rt2x00dev->chip.rev;
145 rt2x00dev->poll_dev->input->dev.parent = device;
146 rt2x00dev->poll_dev->input->evbit[0] = BIT(EV_KEY);
147 set_bit(KEY_WLAN, rt2x00dev->poll_dev->input->keybit);
148 170
149 return 0; 171 input_free_polled_device(rt2x00dev->poll_dev);
172 rt2x00dev->poll_dev = NULL;
150 173
151exit_free_rfkill:
152 rfkill_free(rt2x00dev->rfkill); 174 rfkill_free(rt2x00dev->rfkill);
153 175 rt2x00dev->rfkill = NULL;
154exit:
155 return -ENOMEM;
156} 176}
157 177
158void rt2x00rfkill_free(struct rt2x00_dev *rt2x00dev) 178void rt2x00rfkill_suspend(struct rt2x00_dev *rt2x00dev)
159{ 179{
160 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags)) 180 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags) ||
181 !test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state))
161 return; 182 return;
162 183
163 input_free_polled_device(rt2x00dev->poll_dev); 184 input_free_polled_device(rt2x00dev->poll_dev);
164 rfkill_free(rt2x00dev->rfkill); 185 rt2x00dev->poll_dev = NULL;
186}
187
188void rt2x00rfkill_resume(struct rt2x00_dev *rt2x00dev)
189{
190 if (!test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags) ||
191 !test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state))
192 return;
193
194 rt2x00dev->poll_dev = rt2x00rfkill_allocate_polldev(rt2x00dev);
195 if (!rt2x00dev->poll_dev) {
196 ERROR(rt2x00dev, "Failed to allocate polled device.\n");
197 return;
198 }
165} 199}