Skip to content

Commit

Permalink
b43/legacy: port to cfg80211 rfkill
Browse files Browse the repository at this point in the history
This ports the b43/legacy rfkill code to the new API offered
by cfg80211 and thus removes a lot of useless stuff.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Cc: Michael Buesch <mb@bu3sch.de>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Johannes Berg authored and John W. Linville committed Jun 10, 2009
1 parent e6a3b61 commit f41f3f3
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 341 deletions.
7 changes: 0 additions & 7 deletions drivers/net/wireless/b43/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,6 @@ config B43_LEDS
depends on B43 && MAC80211_LEDS && (LEDS_CLASS = y || LEDS_CLASS = B43)
default y

# This config option automatically enables b43 RFKILL support,
# if it's possible.
config B43_RFKILL
bool
depends on B43 && (RFKILL = y || RFKILL = B43)
default y

# This config option automatically enables b43 HW-RNG support,
# if the HW-RNG core is enabled.
config B43_HWRNG
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/b43/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ b43-y += lo.o
b43-y += wa.o
b43-y += dma.o
b43-$(CONFIG_B43_PIO) += pio.o
b43-$(CONFIG_B43_RFKILL) += rfkill.o
b43-y += rfkill.o
b43-$(CONFIG_B43_LEDS) += leds.o
b43-$(CONFIG_B43_PCMCIA) += pcmcia.o
b43-$(CONFIG_B43_DEBUG) += debugfs.o
Expand Down
3 changes: 0 additions & 3 deletions drivers/net/wireless/b43/b43.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,6 @@ struct b43_wl {
char rng_name[30 + 1];
#endif /* CONFIG_B43_HWRNG */

/* The RF-kill button */
struct b43_rfkill rfkill;

/* List of all wireless devices on this chip */
struct list_head devlist;
u8 nr_devs;
Expand Down
7 changes: 4 additions & 3 deletions drivers/net/wireless/b43/leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "b43.h"
#include "leds.h"
#include "rfkill.h"


static void b43_led_turn_on(struct b43_wldev *dev, u8 led_index,
Expand Down Expand Up @@ -164,10 +165,10 @@ static void b43_map_led(struct b43_wldev *dev,
snprintf(name, sizeof(name),
"b43-%s::radio", wiphy_name(hw->wiphy));
b43_register_led(dev, &dev->led_radio, name,
b43_rfkill_led_name(dev),
ieee80211_get_radio_led_name(hw),
led_index, activelow);
/* Sync the RF-kill LED state with the switch state. */
if (dev->radio_hw_enable)
/* Sync the RF-kill LED state with radio and switch states. */
if (dev->phy.radio_on && b43_is_hw_radio_enabled(dev))
b43_led_turn_on(dev, led_index, activelow);
break;
case B43_LED_WEIRD:
Expand Down
27 changes: 8 additions & 19 deletions drivers/net/wireless/b43/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4298,7 +4298,6 @@ static int b43_op_start(struct ieee80211_hw *hw)
struct b43_wldev *dev = wl->current_dev;
int did_init = 0;
int err = 0;
bool do_rfkill_exit = 0;

/* Kill all old instance specific information to make sure
* the card won't use it in the short timeframe between start
Expand All @@ -4312,18 +4311,12 @@ static int b43_op_start(struct ieee80211_hw *hw)
wl->beacon1_uploaded = 0;
wl->beacon_templates_virgin = 1;

/* First register RFkill.
* LEDs that are registered later depend on it. */
b43_rfkill_init(dev);

mutex_lock(&wl->mutex);

if (b43_status(dev) < B43_STAT_INITIALIZED) {
err = b43_wireless_core_init(dev);
if (err) {
do_rfkill_exit = 1;
if (err)
goto out_mutex_unlock;
}
did_init = 1;
}

Expand All @@ -4332,17 +4325,16 @@ static int b43_op_start(struct ieee80211_hw *hw)
if (err) {
if (did_init)
b43_wireless_core_exit(dev);
do_rfkill_exit = 1;
goto out_mutex_unlock;
}
}

/* XXX: only do if device doesn't support rfkill irq */
wiphy_rfkill_start_polling(hw->wiphy);

out_mutex_unlock:
mutex_unlock(&wl->mutex);

if (do_rfkill_exit)
b43_rfkill_exit(dev);

return err;
}

Expand All @@ -4351,7 +4343,6 @@ static void b43_op_stop(struct ieee80211_hw *hw)
struct b43_wl *wl = hw_to_b43_wl(hw);
struct b43_wldev *dev = wl->current_dev;

b43_rfkill_exit(dev);
cancel_work_sync(&(wl->beacon_update_trigger));

mutex_lock(&wl->mutex);
Expand Down Expand Up @@ -4433,6 +4424,7 @@ static const struct ieee80211_ops b43_hw_ops = {
.sta_notify = b43_op_sta_notify,
.sw_scan_start = b43_op_sw_scan_start_notifier,
.sw_scan_complete = b43_op_sw_scan_complete_notifier,
.rfkill_poll = b43_rfkill_poll,
};

/* Hard-reset the chip. Do not call this directly.
Expand Down Expand Up @@ -4920,7 +4912,7 @@ static struct ssb_driver b43_ssb_driver = {
static void b43_print_driverinfo(void)
{
const char *feat_pci = "", *feat_pcmcia = "", *feat_nphy = "",
*feat_leds = "", *feat_rfkill = "";
*feat_leds = "";

#ifdef CONFIG_B43_PCI_AUTOSELECT
feat_pci = "P";
Expand All @@ -4933,15 +4925,12 @@ static void b43_print_driverinfo(void)
#endif
#ifdef CONFIG_B43_LEDS
feat_leds = "L";
#endif
#ifdef CONFIG_B43_RFKILL
feat_rfkill = "R";
#endif
printk(KERN_INFO "Broadcom 43xx driver loaded "
"[ Features: %s%s%s%s%s, Firmware-ID: "
"[ Features: %s%s%s%s, Firmware-ID: "
B43_SUPPORTED_FIRMWARE_ID " ]\n",
feat_pci, feat_pcmcia, feat_nphy,
feat_leds, feat_rfkill);
feat_leds);
}

static int __init b43_init(void)
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/b43/phy_common.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef LINUX_B43_PHY_COMMON_H_
#define LINUX_B43_PHY_COMMON_H_

#include <linux/rfkill.h>
#include <linux/types.h>

struct b43_wldev;

Expand Down
113 changes: 19 additions & 94 deletions drivers/net/wireless/b43/rfkill.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@
*/

#include "rfkill.h"
#include "b43.h"
#include "phy_common.h"

#include <linux/kmod.h>


/* Returns TRUE, if the radio is enabled in hardware. */
static bool b43_is_hw_radio_enabled(struct b43_wldev *dev)
bool b43_is_hw_radio_enabled(struct b43_wldev *dev)
{
if (dev->phy.rev >= 3) {
if (!(b43_read32(dev, B43_MMIO_RADIO_HWENABLED_HI)
Expand All @@ -45,110 +41,39 @@ static bool b43_is_hw_radio_enabled(struct b43_wldev *dev)
}

/* The poll callback for the hardware button. */
static void b43_rfkill_poll(struct rfkill *rfkill, void *data)
void b43_rfkill_poll(struct ieee80211_hw *hw)
{
struct b43_wldev *dev = data;
struct b43_wl *wl = dev->wl;
struct b43_wl *wl = hw_to_b43_wl(hw);
struct b43_wldev *dev = wl->current_dev;
struct ssb_bus *bus = dev->dev->bus;
bool enabled;
bool brought_up = false;

mutex_lock(&wl->mutex);
if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) {
mutex_unlock(&wl->mutex);
return;
if (ssb_bus_powerup(bus, 0)) {
mutex_unlock(&wl->mutex);
return;
}
ssb_device_enable(dev->dev, 0);
brought_up = true;
}

enabled = b43_is_hw_radio_enabled(dev);

if (unlikely(enabled != dev->radio_hw_enable)) {
dev->radio_hw_enable = enabled;
b43info(wl, "Radio hardware status changed to %s\n",
enabled ? "ENABLED" : "DISABLED");
enabled = !rfkill_set_hw_state(rfkill, !enabled);
wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
if (enabled != dev->phy.radio_on)
b43_software_rfkill(dev, !enabled);
}
mutex_unlock(&wl->mutex);
}

/* Called when the RFKILL toggled in software. */
static int b43_rfkill_soft_set(void *data, bool blocked)
{
struct b43_wldev *dev = data;
struct b43_wl *wl = dev->wl;
int err = -EINVAL;

if (WARN_ON(!wl->rfkill.registered))
return -EINVAL;

mutex_lock(&wl->mutex);

if (b43_status(dev) < B43_STAT_INITIALIZED)
goto out_unlock;

if (!dev->radio_hw_enable)
goto out_unlock;
if (brought_up) {
ssb_device_disable(dev->dev, 0);
ssb_bus_may_powerdown(bus);
}

if (!blocked != dev->phy.radio_on)
b43_software_rfkill(dev, blocked);
err = 0;
out_unlock:
mutex_unlock(&wl->mutex);
return err;
}

const char *b43_rfkill_led_name(struct b43_wldev *dev)
{
struct b43_rfkill *rfk = &(dev->wl->rfkill);

if (!rfk->registered)
return NULL;
return rfkill_get_led_trigger_name(rfk->rfkill);
}

static const struct rfkill_ops b43_rfkill_ops = {
.set_block = b43_rfkill_soft_set,
.poll = b43_rfkill_poll,
};

void b43_rfkill_init(struct b43_wldev *dev)
{
struct b43_wl *wl = dev->wl;
struct b43_rfkill *rfk = &(wl->rfkill);
int err;

rfk->registered = 0;

snprintf(rfk->name, sizeof(rfk->name),
"b43-%s", wiphy_name(wl->hw->wiphy));

rfk->rfkill = rfkill_alloc(rfk->name,
dev->dev->dev,
RFKILL_TYPE_WLAN,
&b43_rfkill_ops, dev);
if (!rfk->rfkill)
goto out_error;

err = rfkill_register(rfk->rfkill);
if (err)
goto err_free;

rfk->registered = 1;

return;
err_free:
rfkill_destroy(rfk->rfkill);
out_error:
rfk->registered = 0;
b43warn(wl, "RF-kill button init failed\n");
}

void b43_rfkill_exit(struct b43_wldev *dev)
{
struct b43_rfkill *rfk = &(dev->wl->rfkill);

if (!rfk->registered)
return;
rfk->registered = 0;

rfkill_unregister(rfk->rfkill);
rfkill_destroy(rfk->rfkill);
rfk->rfkill = NULL;
}
44 changes: 3 additions & 41 deletions drivers/net/wireless/b43/rfkill.h
Original file line number Diff line number Diff line change
@@ -1,49 +1,11 @@
#ifndef B43_RFKILL_H_
#define B43_RFKILL_H_

struct ieee80211_hw;
struct b43_wldev;

void b43_rfkill_poll(struct ieee80211_hw *hw);

#ifdef CONFIG_B43_RFKILL

#include <linux/rfkill.h>


struct b43_rfkill {
/* The RFKILL subsystem data structure */
struct rfkill *rfkill;
/* Did initialization succeed? Used for freeing. */
bool registered;
/* The unique name of this rfkill switch */
char name[sizeof("b43-phy4294967295")];
};

/* The init function returns void, because we are not interested
* in failing the b43 init process when rfkill init failed. */
void b43_rfkill_init(struct b43_wldev *dev);
void b43_rfkill_exit(struct b43_wldev *dev);

const char *b43_rfkill_led_name(struct b43_wldev *dev);


#else /* CONFIG_B43_RFKILL */
/* No RFKILL support. */

struct b43_rfkill {
/* empty */
};

static inline void b43_rfkill_init(struct b43_wldev *dev)
{
}
static inline void b43_rfkill_exit(struct b43_wldev *dev)
{
}
static inline char * b43_rfkill_led_name(struct b43_wldev *dev)
{
return NULL;
}

#endif /* CONFIG_B43_RFKILL */
bool b43_is_hw_radio_enabled(struct b43_wldev *dev);

#endif /* B43_RFKILL_H_ */
8 changes: 0 additions & 8 deletions drivers/net/wireless/b43legacy/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ config B43LEGACY_LEDS
depends on B43LEGACY && MAC80211_LEDS && (LEDS_CLASS = y || LEDS_CLASS = B43LEGACY)
default y

# RFKILL support
# This config option automatically enables b43legacy RFKILL support,
# if it's possible.
config B43LEGACY_RFKILL
bool
depends on B43LEGACY && (RFKILL = y || RFKILL = B43LEGACY)
default y

# This config option automatically enables b43 HW-RNG support,
# if the HW-RNG core is enabled.
config B43LEGACY_HWRNG
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/b43legacy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ b43legacy-y += radio.o
b43legacy-y += sysfs.o
b43legacy-y += xmit.o
# b43 RFKILL button support
b43legacy-$(CONFIG_B43LEGACY_RFKILL) += rfkill.o
b43legacy-y += rfkill.o
# b43legacy LED support
b43legacy-$(CONFIG_B43LEGACY_LEDS) += leds.o
# b43legacy debugging
Expand Down
3 changes: 0 additions & 3 deletions drivers/net/wireless/b43legacy/b43legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,6 @@ struct b43legacy_wl {
char rng_name[30 + 1];
#endif

/* The RF-kill button */
struct b43legacy_rfkill rfkill;

/* List of all wireless devices on this chip */
struct list_head devlist;
u8 nr_devs;
Expand Down
Loading

0 comments on commit f41f3f3

Please sign in to comment.