aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c
diff options
context:
space:
mode:
authorMichael Buesch <mbuesch@freenet.de>2006-02-28 09:32:19 -0500
committerJohn W. Linville <linville@tuxdriver.com>2006-03-27 11:18:40 -0500
commit367f899ac3b52cf4611cd291ec2bfbf774b15bc7 (patch)
tree99763a1b2c27e3371c575beab326147bdb675410 /drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c
parentf398f02d12cdc372e16c5e86246b10acf7211abc (diff)
[PATCH] bcm43xx: Add sysfs attributes for device specific tunables.
Signed-off-by: Michael Buesch <mbuesch@freenet.de> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c')
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c323
1 files changed, 323 insertions, 0 deletions
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c b/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c
new file mode 100644
index 000000000000..2d31737372fd
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c
@@ -0,0 +1,323 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 SYSFS support routines
6
7 Copyright (c) 2006 Michael Buesch <mbuesch@freenet.de>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; see the file COPYING. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
22 Boston, MA 02110-1301, USA.
23
24*/
25
26#include "bcm43xx_sysfs.h"
27#include "bcm43xx.h"
28#include "bcm43xx_main.h"
29#include "bcm43xx_radio.h"
30
31#include <linux/capability.h>
32
33
34#define GENERIC_FILESIZE 64
35
36
37static int get_integer(const char *buf, size_t count)
38{
39 char tmp[10 + 1] = { 0 };
40 int ret = -EINVAL;
41
42 if (count == 0)
43 goto out;
44 count = min(count, (size_t)10);
45 memcpy(tmp, buf, count);
46 ret = simple_strtol(tmp, NULL, 10);
47out:
48 return ret;
49}
50
51static int get_boolean(const char *buf, size_t count)
52{
53 if (count != 0) {
54 if (buf[0] == '1')
55 return 1;
56 if (buf[0] == '0')
57 return 0;
58 if (count >= 4 && memcmp(buf, "true", 4) == 0)
59 return 1;
60 if (count >= 5 && memcmp(buf, "false", 5) == 0)
61 return 0;
62 if (count >= 3 && memcmp(buf, "yes", 3) == 0)
63 return 1;
64 if (count >= 2 && memcmp(buf, "no", 2) == 0)
65 return 0;
66 if (count >= 2 && memcmp(buf, "on", 2) == 0)
67 return 1;
68 if (count >= 3 && memcmp(buf, "off", 3) == 0)
69 return 0;
70 }
71 return -EINVAL;
72}
73
74static ssize_t bcm43xx_attr_sprom_show(struct device *dev,
75 struct device_attribute *attr,
76 char *buf)
77{
78 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_sprom);
79 u16 *sprom;
80 unsigned long flags;
81 int i, err;
82
83 if (!capable(CAP_NET_ADMIN))
84 return -EPERM;
85
86 assert(BCM43xx_SPROM_SIZE * sizeof(u16) <= PAGE_SIZE);
87 sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
88 GFP_KERNEL);
89 if (!sprom)
90 return -ENOMEM;
91 spin_lock_irqsave(&bcm->lock, flags);
92 assert(bcm->initialized);
93 err = bcm43xx_sprom_read(bcm, sprom);
94 if (!err) {
95 for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
96 buf[i * 2] = sprom[i] & 0x00FF;
97 buf[i * 2 + 1] = (sprom[i] & 0xFF00) >> 8;
98 }
99 }
100 spin_unlock_irqrestore(&bcm->lock, flags);
101 kfree(sprom);
102
103 return err ? err : BCM43xx_SPROM_SIZE * sizeof(u16);
104}
105
106static ssize_t bcm43xx_attr_sprom_store(struct device *dev,
107 struct device_attribute *attr,
108 const char *buf, size_t count)
109{
110 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_sprom);
111 u16 *sprom;
112 unsigned long flags;
113 int i, err;
114
115 if (!capable(CAP_NET_ADMIN))
116 return -EPERM;
117
118 if (count != BCM43xx_SPROM_SIZE * sizeof(u16))
119 return -EINVAL;
120 sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
121 GFP_KERNEL);
122 if (!sprom)
123 return -ENOMEM;
124 for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
125 sprom[i] = buf[i * 2] & 0xFF;
126 sprom[i] |= ((u16)(buf[i * 2 + 1] & 0xFF)) << 8;
127 }
128 spin_lock_irqsave(&bcm->lock, flags);
129 assert(bcm->initialized);
130 err = bcm43xx_sprom_write(bcm, sprom);
131 spin_unlock_irqrestore(&bcm->lock, flags);
132 kfree(sprom);
133
134 return err ? err : count;
135
136}
137
138static ssize_t bcm43xx_attr_interfmode_show(struct device *dev,
139 struct device_attribute *attr,
140 char *buf)
141{
142 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_interfmode);
143 unsigned long flags;
144 int err;
145 ssize_t count = 0;
146
147 if (!capable(CAP_NET_ADMIN))
148 return -EPERM;
149
150 spin_lock_irqsave(&bcm->lock, flags);
151 assert(bcm->initialized);
152
153 switch (bcm->current_core->radio->interfmode) {
154 case BCM43xx_RADIO_INTERFMODE_NONE:
155 count = snprintf(buf, PAGE_SIZE, "0 (No Interference Mitigation)\n");
156 break;
157 case BCM43xx_RADIO_INTERFMODE_NONWLAN:
158 count = snprintf(buf, PAGE_SIZE, "1 (Non-WLAN Interference Mitigation)\n");
159 break;
160 case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
161 count = snprintf(buf, PAGE_SIZE, "2 (WLAN Interference Mitigation)\n");
162 break;
163 default:
164 assert(0);
165 }
166 err = 0;
167
168 spin_unlock_irqrestore(&bcm->lock, flags);
169 return err ? err : count;
170
171}
172
173static ssize_t bcm43xx_attr_interfmode_store(struct device *dev,
174 struct device_attribute *attr,
175 const char *buf, size_t count)
176{
177 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_interfmode);
178 unsigned long flags;
179 int err;
180 int mode;
181
182 if (!capable(CAP_NET_ADMIN))
183 return -EPERM;
184
185 mode = get_integer(buf, count);
186 switch (mode) {
187 case 0:
188 mode = BCM43xx_RADIO_INTERFMODE_NONE;
189 break;
190 case 1:
191 mode = BCM43xx_RADIO_INTERFMODE_NONWLAN;
192 break;
193 case 2:
194 mode = BCM43xx_RADIO_INTERFMODE_MANUALWLAN;
195 break;
196 case 3:
197 mode = BCM43xx_RADIO_INTERFMODE_AUTOWLAN;
198 break;
199 default:
200 return -EINVAL;
201 }
202
203 spin_lock_irqsave(&bcm->lock, flags);
204 assert(bcm->initialized);
205
206 err = bcm43xx_radio_set_interference_mitigation(bcm, mode);
207 if (err) {
208 printk(KERN_ERR PFX "Interference Mitigation not "
209 "supported by device\n");
210 }
211
212 spin_unlock_irqrestore(&bcm->lock, flags);
213
214 return err ? err : count;
215}
216
217static ssize_t bcm43xx_attr_preamble_show(struct device *dev,
218 struct device_attribute *attr,
219 char *buf)
220{
221 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_preamble);
222 unsigned long flags;
223 int err;
224 ssize_t count;
225
226 if (!capable(CAP_NET_ADMIN))
227 return -EPERM;
228
229 spin_lock_irqsave(&bcm->lock, flags);
230 assert(bcm->initialized);
231
232 if (bcm->short_preamble)
233 count = snprintf(buf, PAGE_SIZE, "1 (Short Preamble enabled)\n");
234 else
235 count = snprintf(buf, PAGE_SIZE, "0 (Short Preamble disabled)\n");
236
237 err = 0;
238 spin_unlock_irqrestore(&bcm->lock, flags);
239
240 return err ? err : count;
241}
242
243static ssize_t bcm43xx_attr_preamble_store(struct device *dev,
244 struct device_attribute *attr,
245 const char *buf, size_t count)
246{
247 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_preamble);
248 unsigned long flags;
249 int err;
250 int value;
251
252 if (!capable(CAP_NET_ADMIN))
253 return -EPERM;
254
255 value = get_boolean(buf, count);
256 if (value < 0)
257 return value;
258 spin_lock_irqsave(&bcm->lock, flags);
259 assert(bcm->initialized);
260
261 bcm->short_preamble = !!value;
262
263 err = 0;
264 spin_unlock_irqrestore(&bcm->lock, flags);
265
266 return err ? err : count;
267}
268
269int bcm43xx_sysfs_register(struct bcm43xx_private *bcm)
270{
271 struct device *dev = &bcm->pci_dev->dev;
272 struct bcm43xx_sysfs *sysfs = &bcm->sysfs;
273 int err;
274
275 assert(bcm->initialized);
276
277 sysfs->attr_sprom.attr.name = "sprom";
278 sysfs->attr_sprom.attr.owner = THIS_MODULE;
279 sysfs->attr_sprom.attr.mode = 0600;
280 sysfs->attr_sprom.show = bcm43xx_attr_sprom_show;
281 sysfs->attr_sprom.store = bcm43xx_attr_sprom_store;
282 err = device_create_file(dev, &sysfs->attr_sprom);
283 if (err)
284 goto out;
285
286 sysfs->attr_interfmode.attr.name = "interference";
287 sysfs->attr_interfmode.attr.owner = THIS_MODULE;
288 sysfs->attr_interfmode.attr.mode = 0600;
289 sysfs->attr_interfmode.show = bcm43xx_attr_interfmode_show;
290 sysfs->attr_interfmode.store = bcm43xx_attr_interfmode_store;
291 err = device_create_file(dev, &sysfs->attr_interfmode);
292 if (err)
293 goto err_remove_sprom;
294
295 sysfs->attr_preamble.attr.name = "shortpreamble";
296 sysfs->attr_preamble.attr.owner = THIS_MODULE;
297 sysfs->attr_preamble.attr.mode = 0600;
298 sysfs->attr_preamble.show = bcm43xx_attr_preamble_show;
299 sysfs->attr_preamble.store = bcm43xx_attr_preamble_store;
300 err = device_create_file(dev, &sysfs->attr_preamble);
301 if (err)
302 goto err_remove_interfmode;
303
304out:
305 return err;
306err_remove_interfmode:
307 device_remove_file(dev, &sysfs->attr_interfmode);
308err_remove_sprom:
309 device_remove_file(dev, &sysfs->attr_sprom);
310 goto out;
311}
312
313void bcm43xx_sysfs_unregister(struct bcm43xx_private *bcm)
314{
315 struct device *dev = &bcm->pci_dev->dev;
316 struct bcm43xx_sysfs *sysfs = &bcm->sysfs;
317
318 device_remove_file(dev, &sysfs->attr_preamble);
319 device_remove_file(dev, &sysfs->attr_interfmode);
320 device_remove_file(dev, &sysfs->attr_sprom);
321}
322
323/* vim: set ts=8 sw=8 sts=8: */