1 // SPDX-License-Identifier: GPL-2.0-or-later
4 Broadcom B43 wireless driver
8 Copyright (c) 2006 Michael Buesch <m@bues.ch>
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:
57 snprintf(buf, PAGE_SIZE,
58 "0 (No Interference Mitigation)\n");
60 case B43_INTERFMODE_NONWLAN:
62 snprintf(buf, PAGE_SIZE,
63 "1 (Non-WLAN Interference Mitigation)\n");
65 case B43_INTERFMODE_MANUALWLAN:
67 snprintf(buf, PAGE_SIZE,
68 "2 (WLAN Interference Mitigation)\n");
74 mutex_unlock(&wldev->wl->mutex);
79 static ssize_t b43_attr_interfmode_store(struct device *dev,
80 struct device_attribute *attr,
81 const char *buf, size_t count)
83 struct b43_wldev *wldev = dev_to_b43_wldev(dev);
87 if (!capable(CAP_NET_ADMIN))
90 mode = get_integer(buf, count);
93 mode = B43_INTERFMODE_NONE;
96 mode = B43_INTERFMODE_NONWLAN;
99 mode = B43_INTERFMODE_MANUALWLAN;
102 mode = B43_INTERFMODE_AUTOWLAN;
108 mutex_lock(&wldev->wl->mutex);
110 if (wldev->phy.ops->interf_mitigation) {
111 err = wldev->phy.ops->interf_mitigation(wldev, mode);
113 b43err(wldev->wl, "Interference Mitigation not "
114 "supported by device\n");
119 mutex_unlock(&wldev->wl->mutex);
121 return err ? err : count;
124 static DEVICE_ATTR(interference, 0644,
125 b43_attr_interfmode_show, b43_attr_interfmode_store);
127 int b43_sysfs_register(struct b43_wldev *wldev)
129 struct device *dev = wldev->dev->dev;
131 B43_WARN_ON(b43_status(wldev) != B43_STAT_INITIALIZED);
133 return device_create_file(dev, &dev_attr_interference);
136 void b43_sysfs_unregister(struct b43_wldev *wldev)
138 struct device *dev = wldev->dev->dev;
140 device_remove_file(dev, &dev_attr_interference);