ia64/kvm: compilation fix. export account_system_vtime.
[pv_ops_mirror.git] / drivers / net / wireless / b43 / sysfs.c
blob275095b8cbe743c85b5fcd0ef7499e336545d3bf
1 /*
3 Broadcom B43 wireless driver
5 SYSFS support routines
7 Copyright (c) 2006 Michael Buesch <mb@bu3sch.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 <linux/capability.h>
27 #include <linux/io.h>
29 #include "b43.h"
30 #include "sysfs.h"
31 #include "main.h"
32 #include "phy.h"
34 #define GENERIC_FILESIZE 64
36 static int get_integer(const char *buf, size_t count)
38 char tmp[10 + 1] = { 0 };
39 int ret = -EINVAL;
41 if (count == 0)
42 goto out;
43 count = min(count, (size_t) 10);
44 memcpy(tmp, buf, count);
45 ret = simple_strtol(tmp, NULL, 10);
46 out:
47 return ret;
50 static ssize_t b43_attr_interfmode_show(struct device *dev,
51 struct device_attribute *attr,
52 char *buf)
54 struct b43_wldev *wldev = dev_to_b43_wldev(dev);
55 ssize_t count = 0;
57 if (!capable(CAP_NET_ADMIN))
58 return -EPERM;
60 mutex_lock(&wldev->wl->mutex);
62 switch (wldev->phy.interfmode) {
63 case B43_INTERFMODE_NONE:
64 count =
65 snprintf(buf, PAGE_SIZE,
66 "0 (No Interference Mitigation)\n");
67 break;
68 case B43_INTERFMODE_NONWLAN:
69 count =
70 snprintf(buf, PAGE_SIZE,
71 "1 (Non-WLAN Interference Mitigation)\n");
72 break;
73 case B43_INTERFMODE_MANUALWLAN:
74 count =
75 snprintf(buf, PAGE_SIZE,
76 "2 (WLAN Interference Mitigation)\n");
77 break;
78 default:
79 B43_WARN_ON(1);
82 mutex_unlock(&wldev->wl->mutex);
84 return count;
87 static ssize_t b43_attr_interfmode_store(struct device *dev,
88 struct device_attribute *attr,
89 const char *buf, size_t count)
91 struct b43_wldev *wldev = dev_to_b43_wldev(dev);
92 unsigned long flags;
93 int err;
94 int mode;
96 if (!capable(CAP_NET_ADMIN))
97 return -EPERM;
99 mode = get_integer(buf, count);
100 switch (mode) {
101 case 0:
102 mode = B43_INTERFMODE_NONE;
103 break;
104 case 1:
105 mode = B43_INTERFMODE_NONWLAN;
106 break;
107 case 2:
108 mode = B43_INTERFMODE_MANUALWLAN;
109 break;
110 case 3:
111 mode = B43_INTERFMODE_AUTOWLAN;
112 break;
113 default:
114 return -EINVAL;
117 mutex_lock(&wldev->wl->mutex);
118 spin_lock_irqsave(&wldev->wl->irq_lock, flags);
120 err = b43_radio_set_interference_mitigation(wldev, mode);
121 if (err) {
122 b43err(wldev->wl, "Interference Mitigation not "
123 "supported by device\n");
125 mmiowb();
126 spin_unlock_irqrestore(&wldev->wl->irq_lock, flags);
127 mutex_unlock(&wldev->wl->mutex);
129 return err ? err : count;
132 static DEVICE_ATTR(interference, 0644,
133 b43_attr_interfmode_show, b43_attr_interfmode_store);
135 int b43_sysfs_register(struct b43_wldev *wldev)
137 struct device *dev = wldev->dev->dev;
139 B43_WARN_ON(b43_status(wldev) != B43_STAT_INITIALIZED);
141 return device_create_file(dev, &dev_attr_interference);
144 void b43_sysfs_unregister(struct b43_wldev *wldev)
146 struct device *dev = wldev->dev->dev;
148 device_remove_file(dev, &dev_attr_interference);