b43: HT-PHY: init: init BPHY and upload 0x1a table
[deliverable/linux.git] / drivers / net / wireless / b43 / main.c
index 092dd93188696af4e3f2db485c285fa93899dffb..b5e83057dab3719f38afc558dafc04811ce37e9e 100644 (file)
@@ -4,7 +4,7 @@
 
   Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>
   Copyright (c) 2005 Stefano Brivio <stefano.brivio@polimi.it>
-  Copyright (c) 2005-2009 Michael Buesch <mb@bu3sch.de>
+  Copyright (c) 2005-2009 Michael Buesch <m@bues.ch>
   Copyright (c) 2005 Danny van Dyk <kugelfang@gentoo.org>
   Copyright (c) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
 
@@ -37,7 +37,6 @@
 #include <linux/if_arp.h>
 #include <linux/etherdevice.h>
 #include <linux/firmware.h>
-#include <linux/wireless.h>
 #include <linux/workqueue.h>
 #include <linux/skbuff.h>
 #include <linux/io.h>
@@ -115,6 +114,7 @@ MODULE_PARM_DESC(pio, "Use PIO accesses by default: 0=DMA, 1=PIO");
 
 #ifdef CONFIG_B43_BCMA
 static const struct bcma_device_id b43_bcma_tbl[] = {
+       BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 0x11, BCMA_ANY_CLASS),
        BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 0x17, BCMA_ANY_CLASS),
        BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 0x18, BCMA_ANY_CLASS),
        BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 0x1D, BCMA_ANY_CLASS),
@@ -320,6 +320,10 @@ static void b43_wireless_core_exit(struct b43_wldev *dev);
 static int b43_wireless_core_init(struct b43_wldev *dev);
 static struct b43_wldev * b43_wireless_core_stop(struct b43_wldev *dev);
 static int b43_wireless_core_start(struct b43_wldev *dev);
+static void b43_op_bss_info_changed(struct ieee80211_hw *hw,
+                                   struct ieee80211_vif *vif,
+                                   struct ieee80211_bss_conf *conf,
+                                   u32 changed);
 
 static int b43_ratelimit(struct b43_wl *wl)
 {
@@ -1156,17 +1160,37 @@ void b43_power_saving_ctl_bits(struct b43_wldev *dev, unsigned int ps_flags)
 }
 
 #ifdef CONFIG_B43_BCMA
-static void b43_bcma_wireless_core_reset(struct b43_wldev *dev, bool gmode)
+static void b43_bcma_phy_reset(struct b43_wldev *dev)
 {
-       u32 flags = 0;
+       u32 flags;
 
-       if (gmode)
-               flags = B43_BCMA_IOCTL_GMODE;
-       flags |= B43_BCMA_IOCTL_PHY_CLKEN;
+       /* Put PHY into reset */
+       flags = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
+       flags |= B43_BCMA_IOCTL_PHY_RESET;
        flags |= B43_BCMA_IOCTL_PHY_BW_20MHZ; /* Make 20 MHz def */
-       b43_device_enable(dev, flags);
+       bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, flags);
+       udelay(2);
+
+       /* Take PHY out of reset */
+       flags = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
+       flags &= ~B43_BCMA_IOCTL_PHY_RESET;
+       flags |= BCMA_IOCTL_FGC;
+       bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, flags);
+       udelay(1);
 
-       /* TODO: reset PHY */
+       /* Do not force clock anymore */
+       flags = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
+       flags &= ~BCMA_IOCTL_FGC;
+       bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, flags);
+       udelay(1);
+}
+
+static void b43_bcma_wireless_core_reset(struct b43_wldev *dev, bool gmode)
+{
+       b43_device_enable(dev, B43_BCMA_IOCTL_PHY_CLKEN);
+       bcma_core_set_clockmode(dev->dev->bdev, BCMA_CLKMODE_FAST);
+       b43_bcma_phy_reset(dev);
+       bcma_core_pll_ctl(dev->dev->bdev, 0x300, 0x3000000, true);
 }
 #endif
 
@@ -2490,6 +2514,12 @@ static int b43_upload_microcode(struct b43_wldev *dev)
        }
        dev->fw.rev = fwrev;
        dev->fw.patch = fwpatch;
+       if (dev->fw.rev >= 598)
+               dev->fw.hdr_format = B43_FW_HDR_598;
+       else if (dev->fw.rev >= 410)
+               dev->fw.hdr_format = B43_FW_HDR_410;
+       else
+               dev->fw.hdr_format = B43_FW_HDR_351;
        dev->fw.opensource = (fwdate == 0xFFFF);
 
        /* Default to use-all-queues. */
@@ -2537,7 +2567,7 @@ static int b43_upload_microcode(struct b43_wldev *dev)
                        dev->fw.rev, dev->fw.patch);
        wiphy->hw_version = dev->dev->core_id;
 
-       if (b43_is_old_txhdr_format(dev)) {
+       if (dev->fw.hdr_format == B43_FW_HDR_351) {
                /* We're over the deadline, but we keep support for old fw
                 * until it turns out to be in major conflict with something new. */
                b43warn(dev->wl, "You are using an old firmware image. "
@@ -2814,12 +2844,12 @@ void b43_mac_phy_clock_set(struct b43_wldev *dev, bool on)
        switch (dev->dev->bus_type) {
 #ifdef CONFIG_B43_BCMA
        case B43_BUS_BCMA:
-               tmp = bcma_read32(dev->dev->bdev, BCMA_IOCTL);
+               tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
                if (on)
                        tmp |= B43_BCMA_IOCTL_MACPHYCLKEN;
                else
                        tmp &= ~B43_BCMA_IOCTL_MACPHYCLKEN;
-               bcma_write32(dev->dev->bdev, BCMA_IOCTL, tmp);
+               bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
                break;
 #endif
 #ifdef CONFIG_B43_SSB
@@ -2923,6 +2953,7 @@ static void b43_rate_memory_init(struct b43_wldev *dev)
        case B43_PHYTYPE_G:
        case B43_PHYTYPE_N:
        case B43_PHYTYPE_LP:
+       case B43_PHYTYPE_HT:
                b43_rate_memory_write(dev, B43_OFDM_RATE_6MB, 1);
                b43_rate_memory_write(dev, B43_OFDM_RATE_12MB, 1);
                b43_rate_memory_write(dev, B43_OFDM_RATE_18MB, 1);
@@ -3758,14 +3789,24 @@ static int b43_op_config(struct ieee80211_hw *hw, u32 changed)
        struct ieee80211_conf *conf = &hw->conf;
        int antenna;
        int err = 0;
+       bool reload_bss = false;
 
        mutex_lock(&wl->mutex);
 
+       dev = wl->current_dev;
+
        /* Switch the band (if necessary). This might change the active core. */
        err = b43_switch_band(wl, conf->channel);
        if (err)
                goto out_unlock_mutex;
-       dev = wl->current_dev;
+
+       /* Need to reload all settings if the core changed */
+       if (dev != wl->current_dev) {
+               dev = wl->current_dev;
+               changed = ~0;
+               reload_bss = true;
+       }
+
        phy = &dev->phy;
 
        if (conf_is_ht(conf))
@@ -3826,6 +3867,9 @@ out_mac_enable:
 out_unlock_mutex:
        mutex_unlock(&wl->mutex);
 
+       if (wl->vif && reload_bss)
+               b43_op_bss_info_changed(hw, wl->vif, &wl->vif->bss_conf, ~0);
+
        return err;
 }
 
@@ -3914,7 +3958,8 @@ static void b43_op_bss_info_changed(struct ieee80211_hw *hw,
        if (changed & BSS_CHANGED_BEACON_INT &&
            (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
             b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT) ||
-            b43_is_mode(wl, NL80211_IFTYPE_ADHOC)))
+            b43_is_mode(wl, NL80211_IFTYPE_ADHOC)) &&
+           conf->beacon_int)
                b43_set_beacon_int(dev, conf->beacon_int);
 
        if (changed & BSS_CHANGED_BASIC_RATES)
@@ -4682,6 +4727,9 @@ static int b43_op_add_interface(struct ieee80211_hw *hw,
  out_mutex_unlock:
        mutex_unlock(&wl->mutex);
 
+       if (err == 0)
+               b43_op_bss_info_changed(hw, vif, &vif->bss_conf, ~0);
+
        return err;
 }
 
@@ -4752,6 +4800,9 @@ static int b43_op_start(struct ieee80211_hw *hw)
  out_mutex_unlock:
        mutex_unlock(&wl->mutex);
 
+       /* reload configuration */
+       b43_op_config(hw, ~0);
+
        return err;
 }
 
@@ -4908,10 +4959,18 @@ out:
        if (err)
                wl->current_dev = NULL; /* Failed to init the dev. */
        mutex_unlock(&wl->mutex);
-       if (err)
+
+       if (err) {
                b43err(wl, "Controller restart FAILED\n");
-       else
-               b43info(wl, "Controller restarted\n");
+               return;
+       }
+
+       /* reload configuration */
+       b43_op_config(wl->hw, ~0);
+       if (wl->vif)
+               b43_op_bss_info_changed(wl->hw, wl->vif, &wl->vif->bss_conf, ~0);
+
+       b43info(wl, "Controller restarted\n");
 }
 
 static int b43_setup_bands(struct b43_wldev *dev,
@@ -4948,6 +5007,7 @@ static int b43_wireless_core_attach(struct b43_wldev *dev)
        struct b43_wl *wl = dev->wl;
        struct pci_dev *pdev = NULL;
        int err;
+       u32 tmp;
        bool have_2ghz_phy = 0, have_5ghz_phy = 0;
 
        /* Do NOT do any device initialization here.
@@ -4973,17 +5033,17 @@ static int b43_wireless_core_attach(struct b43_wldev *dev)
        switch (dev->dev->bus_type) {
 #ifdef CONFIG_B43_BCMA
        case B43_BUS_BCMA:
-               /* FIXME */
-               have_2ghz_phy = 1;
-               have_5ghz_phy = 0;
+               tmp = bcma_aread32(dev->dev->bdev, BCMA_IOST);
+               have_2ghz_phy = !!(tmp & B43_BCMA_IOST_2G_PHY);
+               have_5ghz_phy = !!(tmp & B43_BCMA_IOST_5G_PHY);
                break;
 #endif
 #ifdef CONFIG_B43_SSB
        case B43_BUS_SSB:
                if (dev->dev->core_rev >= 5) {
-                       u32 tmshigh = ssb_read32(dev->dev->sdev, SSB_TMSHIGH);
-                       have_2ghz_phy = !!(tmshigh & B43_TMSHIGH_HAVE_2GHZ_PHY);
-                       have_5ghz_phy = !!(tmshigh & B43_TMSHIGH_HAVE_5GHZ_PHY);
+                       tmp = ssb_read32(dev->dev->sdev, SSB_TMSHIGH);
+                       have_2ghz_phy = !!(tmp & B43_TMSHIGH_HAVE_2GHZ_PHY);
+                       have_5ghz_phy = !!(tmp & B43_TMSHIGH_HAVE_5GHZ_PHY);
                } else
                        B43_WARN_ON(1);
                break;
@@ -5164,6 +5224,7 @@ static struct b43_wl *b43_wireless_init(struct b43_bus_dev *dev)
        struct ssb_sprom *sprom = dev->bus_sprom;
        struct ieee80211_hw *hw;
        struct b43_wl *wl;
+       char chip_name[6];
 
        hw = ieee80211_alloc_hw(sizeof(*wl), &b43_hw_ops);
        if (!hw) {
@@ -5202,8 +5263,10 @@ static struct b43_wl *b43_wireless_init(struct b43_bus_dev *dev)
        INIT_WORK(&wl->tx_work, b43_tx_work);
        skb_queue_head_init(&wl->tx_queue);
 
-       b43info(wl, "Broadcom %04X WLAN found (core revision %u)\n",
-               dev->chip_id, dev->core_rev);
+       snprintf(chip_name, ARRAY_SIZE(chip_name),
+                (dev->chip_id > 0x9999) ? "%d" : "%04X", dev->chip_id);
+       b43info(wl, "Broadcom %s WLAN found (core revision %u)\n", chip_name,
+               dev->core_rev);
        return wl;
 }
 
@@ -5211,19 +5274,59 @@ static struct b43_wl *b43_wireless_init(struct b43_bus_dev *dev)
 static int b43_bcma_probe(struct bcma_device *core)
 {
        struct b43_bus_dev *dev;
+       struct b43_wl *wl;
+       int err;
 
        dev = b43_bus_dev_bcma_init(core);
        if (!dev)
                return -ENODEV;
 
-       b43err(NULL, "BCMA is not supported yet!");
-       kfree(dev);
-       return -EOPNOTSUPP;
+       wl = b43_wireless_init(dev);
+       if (IS_ERR(wl)) {
+               err = PTR_ERR(wl);
+               goto bcma_out;
+       }
+
+       err = b43_one_core_attach(dev, wl);
+       if (err)
+               goto bcma_err_wireless_exit;
+
+       err = ieee80211_register_hw(wl->hw);
+       if (err)
+               goto bcma_err_one_core_detach;
+       b43_leds_register(wl->current_dev);
+
+bcma_out:
+       return err;
+
+bcma_err_one_core_detach:
+       b43_one_core_detach(dev);
+bcma_err_wireless_exit:
+       ieee80211_free_hw(wl->hw);
+       return err;
 }
 
 static void b43_bcma_remove(struct bcma_device *core)
 {
-       /* TODO */
+       struct b43_wldev *wldev = bcma_get_drvdata(core);
+       struct b43_wl *wl = wldev->wl;
+
+       /* We must cancel any work here before unregistering from ieee80211,
+        * as the ieee80211 unreg will destroy the workqueue. */
+       cancel_work_sync(&wldev->restart_work);
+
+       /* Restore the queues count before unregistering, because firmware detect
+        * might have modified it. Restoring is important, so the networking
+        * stack can properly free resources. */
+       wl->hw->queues = wl->mac80211_initially_registered_queues;
+       b43_leds_stop(wldev);
+       ieee80211_unregister_hw(wl->hw);
+
+       b43_one_core_detach(wldev->dev);
+
+       b43_leds_unregister(wl);
+
+       ieee80211_free_hw(wl->hw);
 }
 
 static struct bcma_driver b43_bcma_driver = {
@@ -5286,6 +5389,7 @@ static void b43_ssb_remove(struct ssb_device *sdev)
 {
        struct b43_wl *wl = ssb_get_devtypedata(sdev);
        struct b43_wldev *wldev = ssb_get_drvdata(sdev);
+       struct b43_bus_dev *dev = wldev->dev;
 
        /* We must cancel any work here before unregistering from ieee80211,
         * as the ieee80211 unreg will destroy the workqueue. */
@@ -5301,14 +5405,14 @@ static void b43_ssb_remove(struct ssb_device *sdev)
                ieee80211_unregister_hw(wl->hw);
        }
 
-       b43_one_core_detach(wldev->dev);
+       b43_one_core_detach(dev);
 
        if (list_empty(&wl->devlist)) {
                b43_leds_unregister(wl);
                /* Last core on the chip unregistered.
                 * We can destroy common struct b43_wl.
                 */
-               b43_wireless_exit(wldev->dev, wl);
+               b43_wireless_exit(dev, wl);
        }
 }
 
This page took 0.040141 seconds and 5 git commands to generate.