3 Broadcom BCM43xx wireless driver
7 Copyright (c) 2006 Michael Buesch <mbuesch@freenet.de>
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.
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.
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.
26 #include "bcm43xx_sysfs.h"
28 #include "bcm43xx_main.h"
29 #include "bcm43xx_radio.h"
31 #include <linux/capability.h>
34 #define GENERIC_FILESIZE 64
37 static int get_integer(const char *buf, size_t count)
39 char tmp[10 + 1] = { 0 };
44 count = min(count, (size_t)10);
45 memcpy(tmp, buf, count);
46 ret = simple_strtol(tmp, NULL, 10);
51 static int get_boolean(const char *buf, size_t count)
58 if (count >= 4 && memcmp(buf, "true", 4) == 0)
60 if (count >= 5 && memcmp(buf, "false", 5) == 0)
62 if (count >= 3 && memcmp(buf, "yes", 3) == 0)
64 if (count >= 2 && memcmp(buf, "no", 2) == 0)
66 if (count >= 2 && memcmp(buf, "on", 2) == 0)
68 if (count >= 3 && memcmp(buf, "off", 3) == 0)
74 static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len)
78 for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
79 pos += snprintf(buf + pos, buf_len - pos - 1,
80 "%04X", swab16(sprom[i]) & 0xFFFF);
82 pos += snprintf(buf + pos, buf_len - pos - 1, "\n");
87 static int hex2sprom(u16 *sprom, const char *dump, size_t len)
93 if (len < BCM43xx_SPROM_SIZE * sizeof(u16) * 2)
96 while (cnt < BCM43xx_SPROM_SIZE) {
99 parsed = simple_strtoul(tmp, NULL, 16);
100 sprom[cnt++] = swab16((u16)parsed);
106 static ssize_t bcm43xx_attr_sprom_show(struct device *dev,
107 struct device_attribute *attr,
110 struct bcm43xx_private *bcm = dev_to_bcm(dev);
115 if (!capable(CAP_NET_ADMIN))
118 assert(BCM43xx_SPROM_SIZE * sizeof(u16) <= PAGE_SIZE);
119 sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
123 mutex_lock(&bcm->mutex);
124 spin_lock_irqsave(&bcm->irq_lock, flags);
125 err = bcm43xx_sprom_read(bcm, sprom);
127 err = sprom2hex(sprom, buf, PAGE_SIZE);
129 spin_unlock_irqrestore(&bcm->irq_lock, flags);
130 mutex_unlock(&bcm->mutex);
136 static ssize_t bcm43xx_attr_sprom_store(struct device *dev,
137 struct device_attribute *attr,
138 const char *buf, size_t count)
140 struct bcm43xx_private *bcm = dev_to_bcm(dev);
145 if (!capable(CAP_NET_ADMIN))
148 sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
152 err = hex2sprom(sprom, buf, count);
155 mutex_lock(&bcm->mutex);
156 spin_lock_irqsave(&bcm->irq_lock, flags);
157 spin_lock(&bcm->leds_lock);
158 err = bcm43xx_sprom_write(bcm, sprom);
160 spin_unlock(&bcm->leds_lock);
161 spin_unlock_irqrestore(&bcm->irq_lock, flags);
162 mutex_unlock(&bcm->mutex);
166 return err ? err : count;
170 static DEVICE_ATTR(sprom, 0600,
171 bcm43xx_attr_sprom_show,
172 bcm43xx_attr_sprom_store);
174 static ssize_t bcm43xx_attr_interfmode_show(struct device *dev,
175 struct device_attribute *attr,
178 struct bcm43xx_private *bcm = dev_to_bcm(dev);
181 if (!capable(CAP_NET_ADMIN))
184 mutex_lock(&bcm->mutex);
186 switch (bcm43xx_current_radio(bcm)->interfmode) {
187 case BCM43xx_RADIO_INTERFMODE_NONE:
188 count = snprintf(buf, PAGE_SIZE, "0 (No Interference Mitigation)\n");
190 case BCM43xx_RADIO_INTERFMODE_NONWLAN:
191 count = snprintf(buf, PAGE_SIZE, "1 (Non-WLAN Interference Mitigation)\n");
193 case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
194 count = snprintf(buf, PAGE_SIZE, "2 (WLAN Interference Mitigation)\n");
200 mutex_unlock(&bcm->mutex);
206 static ssize_t bcm43xx_attr_interfmode_store(struct device *dev,
207 struct device_attribute *attr,
208 const char *buf, size_t count)
210 struct bcm43xx_private *bcm = dev_to_bcm(dev);
215 if (!capable(CAP_NET_ADMIN))
218 mode = get_integer(buf, count);
221 mode = BCM43xx_RADIO_INTERFMODE_NONE;
224 mode = BCM43xx_RADIO_INTERFMODE_NONWLAN;
227 mode = BCM43xx_RADIO_INTERFMODE_MANUALWLAN;
230 mode = BCM43xx_RADIO_INTERFMODE_AUTOWLAN;
236 mutex_lock(&bcm->mutex);
237 spin_lock_irqsave(&bcm->irq_lock, flags);
239 err = bcm43xx_radio_set_interference_mitigation(bcm, mode);
241 printk(KERN_ERR PFX "Interference Mitigation not "
242 "supported by device\n");
245 spin_unlock_irqrestore(&bcm->irq_lock, flags);
246 mutex_unlock(&bcm->mutex);
248 return err ? err : count;
251 static DEVICE_ATTR(interference, 0644,
252 bcm43xx_attr_interfmode_show,
253 bcm43xx_attr_interfmode_store);
255 static ssize_t bcm43xx_attr_preamble_show(struct device *dev,
256 struct device_attribute *attr,
259 struct bcm43xx_private *bcm = dev_to_bcm(dev);
262 if (!capable(CAP_NET_ADMIN))
265 mutex_lock(&bcm->mutex);
267 if (bcm->short_preamble)
268 count = snprintf(buf, PAGE_SIZE, "1 (Short Preamble enabled)\n");
270 count = snprintf(buf, PAGE_SIZE, "0 (Short Preamble disabled)\n");
272 mutex_unlock(&bcm->mutex);
277 static ssize_t bcm43xx_attr_preamble_store(struct device *dev,
278 struct device_attribute *attr,
279 const char *buf, size_t count)
281 struct bcm43xx_private *bcm = dev_to_bcm(dev);
285 if (!capable(CAP_NET_ADMIN))
288 value = get_boolean(buf, count);
291 mutex_lock(&bcm->mutex);
292 spin_lock_irqsave(&bcm->irq_lock, flags);
294 bcm->short_preamble = !!value;
296 spin_unlock_irqrestore(&bcm->irq_lock, flags);
297 mutex_unlock(&bcm->mutex);
302 static DEVICE_ATTR(shortpreamble, 0644,
303 bcm43xx_attr_preamble_show,
304 bcm43xx_attr_preamble_store);
306 static ssize_t bcm43xx_attr_phymode_store(struct device *dev,
307 struct device_attribute *attr,
308 const char *buf, size_t count)
310 struct bcm43xx_private *bcm = dev_to_bcm(dev);
318 phytype = BCM43xx_PHYTYPE_A;
321 phytype = BCM43xx_PHYTYPE_B;
324 phytype = BCM43xx_PHYTYPE_G;
330 bcm43xx_periodic_tasks_delete(bcm);
331 mutex_lock(&(bcm)->mutex);
332 err = bcm43xx_select_wireless_core(bcm, phytype);
334 bcm43xx_periodic_tasks_setup(bcm);
335 mutex_unlock(&(bcm)->mutex);
340 return err ? err : count;
343 static ssize_t bcm43xx_attr_phymode_show(struct device *dev,
344 struct device_attribute *attr,
347 struct bcm43xx_private *bcm = dev_to_bcm(dev);
350 mutex_lock(&(bcm)->mutex);
351 switch (bcm43xx_current_phy(bcm)->type) {
352 case BCM43xx_PHYTYPE_A:
353 snprintf(buf, PAGE_SIZE, "A");
355 case BCM43xx_PHYTYPE_B:
356 snprintf(buf, PAGE_SIZE, "B");
358 case BCM43xx_PHYTYPE_G:
359 snprintf(buf, PAGE_SIZE, "G");
364 mutex_unlock(&(bcm)->mutex);
369 static DEVICE_ATTR(phymode, 0644,
370 bcm43xx_attr_phymode_show,
371 bcm43xx_attr_phymode_store);
373 static ssize_t bcm43xx_attr_microcode_show(struct device *dev,
374 struct device_attribute *attr,
378 struct bcm43xx_private *bcm = dev_to_bcm(dev);
382 if (!capable(CAP_NET_ADMIN))
385 mutex_lock(&(bcm)->mutex);
386 spin_lock_irqsave(&bcm->irq_lock, flags);
387 status = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
388 BCM43xx_UCODE_STATUS);
390 spin_unlock_irqrestore(&bcm->irq_lock, flags);
391 mutex_unlock(&(bcm)->mutex);
394 count = snprintf(buf, PAGE_SIZE, "0x%.4x (invalid)\n",
398 count = snprintf(buf, PAGE_SIZE, "0x%.4x (init)\n",
402 count = snprintf(buf, PAGE_SIZE, "0x%.4x (active)\n",
406 count = snprintf(buf, PAGE_SIZE, "0x%.4x (suspended)\n",
410 count = snprintf(buf, PAGE_SIZE, "0x%.4x (asleep)\n",
414 count = snprintf(buf, PAGE_SIZE, "0x%.4x (unknown)\n",
422 static DEVICE_ATTR(microcodestatus, 0444,
423 bcm43xx_attr_microcode_show,
426 int bcm43xx_sysfs_register(struct bcm43xx_private *bcm)
428 struct device *dev = &bcm->pci_dev->dev;
431 assert(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED);
433 err = device_create_file(dev, &dev_attr_sprom);
436 err = device_create_file(dev, &dev_attr_interference);
438 goto err_remove_sprom;
439 err = device_create_file(dev, &dev_attr_shortpreamble);
441 goto err_remove_interfmode;
442 err = device_create_file(dev, &dev_attr_phymode);
444 goto err_remove_shortpreamble;
445 err = device_create_file(dev, &dev_attr_microcodestatus);
447 goto err_remove_phymode;
452 device_remove_file(dev, &dev_attr_phymode);
453 err_remove_shortpreamble:
454 device_remove_file(dev, &dev_attr_shortpreamble);
455 err_remove_interfmode:
456 device_remove_file(dev, &dev_attr_interference);
458 device_remove_file(dev, &dev_attr_sprom);
462 void bcm43xx_sysfs_unregister(struct bcm43xx_private *bcm)
464 struct device *dev = &bcm->pci_dev->dev;
466 device_remove_file(dev, &dev_attr_microcodestatus);
467 device_remove_file(dev, &dev_attr_phymode);
468 device_remove_file(dev, &dev_attr_shortpreamble);
469 device_remove_file(dev, &dev_attr_interference);
470 device_remove_file(dev, &dev_attr_sprom);