aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless
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
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')
-rw-r--r--drivers/net/wireless/bcm43xx/Makefile2
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx.h3
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_main.c4
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c323
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_sysfs.h25
5 files changed, 356 insertions, 1 deletions
diff --git a/drivers/net/wireless/bcm43xx/Makefile b/drivers/net/wireless/bcm43xx/Makefile
index 2962b5f9e3e7..bb5220c629d2 100644
--- a/drivers/net/wireless/bcm43xx/Makefile
+++ b/drivers/net/wireless/bcm43xx/Makefile
@@ -8,5 +8,5 @@ bcm43xx-objs := bcm43xx_main.o bcm43xx_ilt.o \
8 bcm43xx_radio.o bcm43xx_phy.o \ 8 bcm43xx_radio.o bcm43xx_phy.o \
9 bcm43xx_power.o bcm43xx_wx.o \ 9 bcm43xx_power.o bcm43xx_wx.o \
10 bcm43xx_leds.o bcm43xx_ethtool.o \ 10 bcm43xx_leds.o bcm43xx_ethtool.o \
11 bcm43xx_xmit.o \ 11 bcm43xx_xmit.o bcm43xx_sysfs.o \
12 $(bcm43xx-obj-y) 12 $(bcm43xx-obj-y)
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx.h b/drivers/net/wireless/bcm43xx/bcm43xx.h
index 21c75cae14bf..fd9754b52951 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx.h
+++ b/drivers/net/wireless/bcm43xx/bcm43xx.h
@@ -15,6 +15,7 @@
15 15
16#include "bcm43xx_debugfs.h" 16#include "bcm43xx_debugfs.h"
17#include "bcm43xx_leds.h" 17#include "bcm43xx_leds.h"
18#include "bcm43xx_sysfs.h"
18 19
19 20
20#define PFX KBUILD_MODNAME ": " 21#define PFX KBUILD_MODNAME ": "
@@ -606,6 +607,8 @@ struct bcm43xx_key {
606}; 607};
607 608
608struct bcm43xx_private { 609struct bcm43xx_private {
610 struct bcm43xx_sysfs sysfs;
611
609 struct ieee80211_device *ieee; 612 struct ieee80211_device *ieee;
610 struct ieee80211softmac_device *softmac; 613 struct ieee80211softmac_device *softmac;
611 614
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_main.c b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
index f1ac9940f14c..1fe2fa9856e3 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_main.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
@@ -3160,6 +3160,8 @@ static void bcm43xx_free_board(struct bcm43xx_private *bcm)
3160 int i, err; 3160 int i, err;
3161 unsigned long flags; 3161 unsigned long flags;
3162 3162
3163 bcm43xx_sysfs_unregister(bcm);
3164
3163 bcm43xx_periodic_tasks_delete(bcm); 3165 bcm43xx_periodic_tasks_delete(bcm);
3164 3166
3165 spin_lock_irqsave(&bcm->lock, flags); 3167 spin_lock_irqsave(&bcm->lock, flags);
@@ -3270,6 +3272,8 @@ static int bcm43xx_init_board(struct bcm43xx_private *bcm)
3270 spin_unlock_irqrestore(&bcm->lock, flags); 3272 spin_unlock_irqrestore(&bcm->lock, flags);
3271 3273
3272 bcm43xx_periodic_tasks_setup(bcm); 3274 bcm43xx_periodic_tasks_setup(bcm);
3275 bcm43xx_sysfs_register(bcm);
3276 //FIXME: check for bcm43xx_sysfs_register failure. This function is a bit messy regarding unwinding, though...
3273 3277
3274 assert(err == 0); 3278 assert(err == 0);
3275out: 3279out:
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: */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.h b/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.h
new file mode 100644
index 000000000000..57f14514e3e0
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.h
@@ -0,0 +1,25 @@
1#ifndef BCM43xx_SYSFS_H_
2#define BCM43xx_SYSFS_H_
3
4#include <linux/device.h>
5
6
7struct bcm43xx_sysfs {
8 struct device_attribute attr_sprom;
9 struct device_attribute attr_interfmode;
10 struct device_attribute attr_preamble;
11};
12
13#define devattr_to_bcm(attr, attr_name) ({ \
14 struct bcm43xx_sysfs *__s; struct bcm43xx_private *__p; \
15 __s = container_of((attr), struct bcm43xx_sysfs, attr_name); \
16 __p = container_of(__s, struct bcm43xx_private, sysfs); \
17 __p; \
18 })
19
20struct bcm43xx_private;
21
22int bcm43xx_sysfs_register(struct bcm43xx_private *bcm);
23void bcm43xx_sysfs_unregister(struct bcm43xx_private *bcm);
24
25#endif /* BCM43xx_SYSFS_H_ */