aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2006-04-12 20:32:58 -0400
committerJohn W. Linville <linville@tuxdriver.com>2006-04-19 17:25:41 -0400
commitb35d649cb2110b4e782a8a7e9b625432c863cade (patch)
tree44a22b588be3af2182a435277cecef078bcb6210 /drivers
parent8829d55e6b4957770de3f716bafab65ca3680110 (diff)
[PATCH] bcm43xx: sysfs code cleanup
This cleans up the bcm43xx sysfs code and makes it compliant with the unwritten sysfs rules (at least I hope so). Signed-off-by: Michael Buesch <mb@bu3sch.de> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx.h17
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_main.c1
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c115
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_sysfs.h16
4 files changed, 82 insertions, 67 deletions
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx.h b/drivers/net/wireless/bcm43xx/bcm43xx.h
index dcadd295de4f..2e83083935e1 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx.h
+++ b/drivers/net/wireless/bcm43xx/bcm43xx.h
@@ -15,7 +15,6 @@
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"
19 18
20 19
21#define PFX KBUILD_MODNAME ": " 20#define PFX KBUILD_MODNAME ": "
@@ -638,8 +637,6 @@ struct bcm43xx_key {
638}; 637};
639 638
640struct bcm43xx_private { 639struct bcm43xx_private {
641 struct bcm43xx_sysfs sysfs;
642
643 struct ieee80211_device *ieee; 640 struct ieee80211_device *ieee;
644 struct ieee80211softmac_device *softmac; 641 struct ieee80211softmac_device *softmac;
645 642
@@ -772,6 +769,20 @@ struct bcm43xx_private * bcm43xx_priv(struct net_device *dev)
772 return ieee80211softmac_priv(dev); 769 return ieee80211softmac_priv(dev);
773} 770}
774 771
772struct device;
773
774static inline
775struct bcm43xx_private * dev_to_bcm(struct device *dev)
776{
777 struct net_device *net_dev;
778 struct bcm43xx_private *bcm;
779
780 net_dev = dev_get_drvdata(dev);
781 bcm = bcm43xx_priv(net_dev);
782
783 return bcm;
784}
785
775 786
776/* Helper function, which returns a boolean. 787/* Helper function, which returns a boolean.
777 * TRUE, if PIO is used; FALSE, if DMA is used. 788 * TRUE, if PIO is used; FALSE, if DMA is used.
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_main.c b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
index 23ad77293d64..9a06e61df0a2 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_main.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
@@ -52,6 +52,7 @@
52#include "bcm43xx_wx.h" 52#include "bcm43xx_wx.h"
53#include "bcm43xx_ethtool.h" 53#include "bcm43xx_ethtool.h"
54#include "bcm43xx_xmit.h" 54#include "bcm43xx_xmit.h"
55#include "bcm43xx_sysfs.h"
55 56
56 57
57MODULE_DESCRIPTION("Broadcom BCM43xx wireless driver"); 58MODULE_DESCRIPTION("Broadcom BCM43xx wireless driver");
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c b/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c
index c44d890b949b..b438f48e891d 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c
@@ -71,14 +71,46 @@ static int get_boolean(const char *buf, size_t count)
71 return -EINVAL; 71 return -EINVAL;
72} 72}
73 73
74static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len)
75{
76 int i, pos = 0;
77
78 for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
79 pos += snprintf(buf + pos, buf_len - pos - 1,
80 "%04X", swab16(sprom[i]) & 0xFFFF);
81 }
82 pos += snprintf(buf + pos, buf_len - pos - 1, "\n");
83
84 return pos + 1;
85}
86
87static int hex2sprom(u16 *sprom, const char *dump, size_t len)
88{
89 char tmp[5] = { 0 };
90 int cnt = 0;
91 unsigned long parsed;
92
93 if (len < BCM43xx_SPROM_SIZE * sizeof(u16) * 2)
94 return -EINVAL;
95
96 while (cnt < BCM43xx_SPROM_SIZE) {
97 memcpy(tmp, dump, 4);
98 dump += 4;
99 parsed = simple_strtoul(tmp, NULL, 16);
100 sprom[cnt++] = swab16((u16)parsed);
101 }
102
103 return 0;
104}
105
74static ssize_t bcm43xx_attr_sprom_show(struct device *dev, 106static ssize_t bcm43xx_attr_sprom_show(struct device *dev,
75 struct device_attribute *attr, 107 struct device_attribute *attr,
76 char *buf) 108 char *buf)
77{ 109{
78 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_sprom); 110 struct bcm43xx_private *bcm = dev_to_bcm(dev);
79 u16 *sprom; 111 u16 *sprom;
80 unsigned long flags; 112 unsigned long flags;
81 int i, err; 113 int err;
82 114
83 if (!capable(CAP_NET_ADMIN)) 115 if (!capable(CAP_NET_ADMIN))
84 return -EPERM; 116 return -EPERM;
@@ -91,55 +123,53 @@ static ssize_t bcm43xx_attr_sprom_show(struct device *dev,
91 bcm43xx_lock_mmio(bcm, flags); 123 bcm43xx_lock_mmio(bcm, flags);
92 assert(bcm->initialized); 124 assert(bcm->initialized);
93 err = bcm43xx_sprom_read(bcm, sprom); 125 err = bcm43xx_sprom_read(bcm, sprom);
94 if (!err) { 126 if (!err)
95 for (i = 0; i < BCM43xx_SPROM_SIZE; i++) { 127 err = sprom2hex(sprom, buf, PAGE_SIZE);
96 buf[i * 2] = sprom[i] & 0x00FF;
97 buf[i * 2 + 1] = (sprom[i] & 0xFF00) >> 8;
98 }
99 }
100 bcm43xx_unlock_mmio(bcm, flags); 128 bcm43xx_unlock_mmio(bcm, flags);
101 kfree(sprom); 129 kfree(sprom);
102 130
103 return err ? err : BCM43xx_SPROM_SIZE * sizeof(u16); 131 return err;
104} 132}
105 133
106static ssize_t bcm43xx_attr_sprom_store(struct device *dev, 134static ssize_t bcm43xx_attr_sprom_store(struct device *dev,
107 struct device_attribute *attr, 135 struct device_attribute *attr,
108 const char *buf, size_t count) 136 const char *buf, size_t count)
109{ 137{
110 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_sprom); 138 struct bcm43xx_private *bcm = dev_to_bcm(dev);
111 u16 *sprom; 139 u16 *sprom;
112 unsigned long flags; 140 unsigned long flags;
113 int i, err; 141 int err;
114 142
115 if (!capable(CAP_NET_ADMIN)) 143 if (!capable(CAP_NET_ADMIN))
116 return -EPERM; 144 return -EPERM;
117 145
118 if (count != BCM43xx_SPROM_SIZE * sizeof(u16))
119 return -EINVAL;
120 sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom), 146 sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
121 GFP_KERNEL); 147 GFP_KERNEL);
122 if (!sprom) 148 if (!sprom)
123 return -ENOMEM; 149 return -ENOMEM;
124 for (i = 0; i < BCM43xx_SPROM_SIZE; i++) { 150 err = hex2sprom(sprom, buf, count);
125 sprom[i] = buf[i * 2] & 0xFF; 151 if (err)
126 sprom[i] |= ((u16)(buf[i * 2 + 1] & 0xFF)) << 8; 152 goto out_kfree;
127 }
128 bcm43xx_lock_mmio(bcm, flags); 153 bcm43xx_lock_mmio(bcm, flags);
129 assert(bcm->initialized); 154 assert(bcm->initialized);
130 err = bcm43xx_sprom_write(bcm, sprom); 155 err = bcm43xx_sprom_write(bcm, sprom);
131 bcm43xx_unlock_mmio(bcm, flags); 156 bcm43xx_unlock_mmio(bcm, flags);
157out_kfree:
132 kfree(sprom); 158 kfree(sprom);
133 159
134 return err ? err : count; 160 return err ? err : count;
135 161
136} 162}
137 163
164static DEVICE_ATTR(sprom, 0600,
165 bcm43xx_attr_sprom_show,
166 bcm43xx_attr_sprom_store);
167
138static ssize_t bcm43xx_attr_interfmode_show(struct device *dev, 168static ssize_t bcm43xx_attr_interfmode_show(struct device *dev,
139 struct device_attribute *attr, 169 struct device_attribute *attr,
140 char *buf) 170 char *buf)
141{ 171{
142 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_interfmode); 172 struct bcm43xx_private *bcm = dev_to_bcm(dev);
143 unsigned long flags; 173 unsigned long flags;
144 int err; 174 int err;
145 ssize_t count = 0; 175 ssize_t count = 0;
@@ -175,7 +205,7 @@ static ssize_t bcm43xx_attr_interfmode_store(struct device *dev,
175 struct device_attribute *attr, 205 struct device_attribute *attr,
176 const char *buf, size_t count) 206 const char *buf, size_t count)
177{ 207{
178 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_interfmode); 208 struct bcm43xx_private *bcm = dev_to_bcm(dev);
179 unsigned long flags; 209 unsigned long flags;
180 int err; 210 int err;
181 int mode; 211 int mode;
@@ -215,11 +245,15 @@ static ssize_t bcm43xx_attr_interfmode_store(struct device *dev,
215 return err ? err : count; 245 return err ? err : count;
216} 246}
217 247
248static DEVICE_ATTR(interference, 0644,
249 bcm43xx_attr_interfmode_show,
250 bcm43xx_attr_interfmode_store);
251
218static ssize_t bcm43xx_attr_preamble_show(struct device *dev, 252static ssize_t bcm43xx_attr_preamble_show(struct device *dev,
219 struct device_attribute *attr, 253 struct device_attribute *attr,
220 char *buf) 254 char *buf)
221{ 255{
222 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_preamble); 256 struct bcm43xx_private *bcm = dev_to_bcm(dev);
223 unsigned long flags; 257 unsigned long flags;
224 int err; 258 int err;
225 ssize_t count; 259 ssize_t count;
@@ -245,7 +279,7 @@ static ssize_t bcm43xx_attr_preamble_store(struct device *dev,
245 struct device_attribute *attr, 279 struct device_attribute *attr,
246 const char *buf, size_t count) 280 const char *buf, size_t count)
247{ 281{
248 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_preamble); 282 struct bcm43xx_private *bcm = dev_to_bcm(dev);
249 unsigned long flags; 283 unsigned long flags;
250 int err; 284 int err;
251 int value; 285 int value;
@@ -267,56 +301,41 @@ static ssize_t bcm43xx_attr_preamble_store(struct device *dev,
267 return err ? err : count; 301 return err ? err : count;
268} 302}
269 303
304static DEVICE_ATTR(shortpreamble, 0644,
305 bcm43xx_attr_preamble_show,
306 bcm43xx_attr_preamble_store);
307
270int bcm43xx_sysfs_register(struct bcm43xx_private *bcm) 308int bcm43xx_sysfs_register(struct bcm43xx_private *bcm)
271{ 309{
272 struct device *dev = &bcm->pci_dev->dev; 310 struct device *dev = &bcm->pci_dev->dev;
273 struct bcm43xx_sysfs *sysfs = &bcm->sysfs;
274 int err; 311 int err;
275 312
276 assert(bcm->initialized); 313 assert(bcm->initialized);
277 314
278 sysfs->attr_sprom.attr.name = "sprom"; 315 err = device_create_file(dev, &dev_attr_sprom);
279 sysfs->attr_sprom.attr.owner = THIS_MODULE;
280 sysfs->attr_sprom.attr.mode = 0600;
281 sysfs->attr_sprom.show = bcm43xx_attr_sprom_show;
282 sysfs->attr_sprom.store = bcm43xx_attr_sprom_store;
283 err = device_create_file(dev, &sysfs->attr_sprom);
284 if (err) 316 if (err)
285 goto out; 317 goto out;
286 318 err = device_create_file(dev, &dev_attr_interference);
287 sysfs->attr_interfmode.attr.name = "interference";
288 sysfs->attr_interfmode.attr.owner = THIS_MODULE;
289 sysfs->attr_interfmode.attr.mode = 0600;
290 sysfs->attr_interfmode.show = bcm43xx_attr_interfmode_show;
291 sysfs->attr_interfmode.store = bcm43xx_attr_interfmode_store;
292 err = device_create_file(dev, &sysfs->attr_interfmode);
293 if (err) 319 if (err)
294 goto err_remove_sprom; 320 goto err_remove_sprom;
295 321 err = device_create_file(dev, &dev_attr_shortpreamble);
296 sysfs->attr_preamble.attr.name = "shortpreamble";
297 sysfs->attr_preamble.attr.owner = THIS_MODULE;
298 sysfs->attr_preamble.attr.mode = 0600;
299 sysfs->attr_preamble.show = bcm43xx_attr_preamble_show;
300 sysfs->attr_preamble.store = bcm43xx_attr_preamble_store;
301 err = device_create_file(dev, &sysfs->attr_preamble);
302 if (err) 322 if (err)
303 goto err_remove_interfmode; 323 goto err_remove_interfmode;
304 324
305out: 325out:
306 return err; 326 return err;
307err_remove_interfmode: 327err_remove_interfmode:
308 device_remove_file(dev, &sysfs->attr_interfmode); 328 device_remove_file(dev, &dev_attr_interference);
309err_remove_sprom: 329err_remove_sprom:
310 device_remove_file(dev, &sysfs->attr_sprom); 330 device_remove_file(dev, &dev_attr_sprom);
311 goto out; 331 goto out;
312} 332}
313 333
314void bcm43xx_sysfs_unregister(struct bcm43xx_private *bcm) 334void bcm43xx_sysfs_unregister(struct bcm43xx_private *bcm)
315{ 335{
316 struct device *dev = &bcm->pci_dev->dev; 336 struct device *dev = &bcm->pci_dev->dev;
317 struct bcm43xx_sysfs *sysfs = &bcm->sysfs;
318 337
319 device_remove_file(dev, &sysfs->attr_preamble); 338 device_remove_file(dev, &dev_attr_shortpreamble);
320 device_remove_file(dev, &sysfs->attr_interfmode); 339 device_remove_file(dev, &dev_attr_interference);
321 device_remove_file(dev, &sysfs->attr_sprom); 340 device_remove_file(dev, &dev_attr_sprom);
322} 341}
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.h b/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.h
index 57f14514e3e0..cc701df71e2a 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.h
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.h
@@ -1,22 +1,6 @@
1#ifndef BCM43xx_SYSFS_H_ 1#ifndef BCM43xx_SYSFS_H_
2#define BCM43xx_SYSFS_H_ 2#define BCM43xx_SYSFS_H_
3 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; 4struct bcm43xx_private;
21 5
22int bcm43xx_sysfs_register(struct bcm43xx_private *bcm); 6int bcm43xx_sysfs_register(struct bcm43xx_private *bcm);