1 // SPDX-License-Identifier: GPL-2.0-or-later
4 Broadcom B43 wireless driver
13 #include <linux/capability.h>
19 #include "phy_common.h"
21 #define GENERIC_FILESIZE 64
23 static int get_integer(const char *buf, size_t count)
25 char tmp[10 + 1] = { 0 };
30 count = min_t(size_t, count, 10);
31 memcpy(tmp, buf, count);
32 ret = simple_strtol(tmp, NULL, 10);
37 static ssize_t b43_attr_interfmode_show(struct device *dev,
38 struct device_attribute *attr,
41 struct b43_wldev *wldev = dev_to_b43_wldev(dev);
44 if (!capable(CAP_NET_ADMIN))
47 mutex_lock(&wldev->wl->mutex);
49 if (wldev->phy.type != B43_PHYTYPE_G) {
50 mutex_unlock(&wldev->wl->mutex);
54 switch (wldev->phy.g->interfmode) {
55 case B43_INTERFMODE_NONE:
56 count = sysfs_emit(buf, "0 (No Interference Mitigation)\n");
58 case B43_INTERFMODE_NONWLAN:
59 count = sysfs_emit(buf,
60 "1 (Non-WLAN Interference Mitigation)\n");
62 case B43_INTERFMODE_MANUALWLAN:
63 count = sysfs_emit(buf, "2 (WLAN Interference Mitigation)\n");
69 mutex_unlock(&wldev->wl->mutex);
74 static ssize_t b43_attr_interfmode_store(struct device *dev,
75 struct device_attribute *attr,
76 const char *buf, size_t count)
78 struct b43_wldev *wldev = dev_to_b43_wldev(dev);
82 if (!capable(CAP_NET_ADMIN))
85 mode = get_integer(buf, count);
88 mode = B43_INTERFMODE_NONE;
91 mode = B43_INTERFMODE_NONWLAN;
94 mode = B43_INTERFMODE_MANUALWLAN;
97 mode = B43_INTERFMODE_AUTOWLAN;
103 mutex_lock(&wldev->wl->mutex);
105 if (wldev->phy.ops->interf_mitigation) {
106 err = wldev->phy.ops->interf_mitigation(wldev, mode);
108 b43err(wldev->wl, "Interference Mitigation not "
109 "supported by device\n");
114 mutex_unlock(&wldev->wl->mutex);
116 return err ? err : count;
119 static DEVICE_ATTR(interference, 0644,
120 b43_attr_interfmode_show, b43_attr_interfmode_store);
122 int b43_sysfs_register(struct b43_wldev *wldev)
124 struct device *dev = wldev->dev->dev;
126 B43_WARN_ON(b43_status(wldev) != B43_STAT_INITIALIZED);
128 return device_create_file(dev, &dev_attr_interference);
131 void b43_sysfs_unregister(struct b43_wldev *wldev)
133 struct device *dev = wldev->dev->dev;
135 device_remove_file(dev, &dev_attr_interference);