net: convert print_mac to %pM
[safe/jmp/linux-2.6] / drivers / net / wireless / b43 / main.c
index 63bafc2..6e77301 100644 (file)
@@ -46,7 +46,7 @@
 #include "debugfs.h"
 #include "phy_common.h"
 #include "phy_g.h"
-#include "nphy.h"
+#include "phy_n.h"
 #include "dma.h"
 #include "pio.h"
 #include "sysfs.h"
@@ -815,7 +815,7 @@ void b43_dummy_transmission(struct b43_wldev *dev)
                        break;
                udelay(10);
        }
-       for (i = 0x00; i < 0x0A; i++) {
+       for (i = 0x00; i < 0x19; i++) {
                value = b43_read16(dev, 0x0690);
                if (!(value & 0x0100))
                        break;
@@ -1052,23 +1052,6 @@ void b43_power_saving_ctl_bits(struct b43_wldev *dev, unsigned int ps_flags)
        }
 }
 
-/* Turn the Analog ON/OFF */
-static void b43_switch_analog(struct b43_wldev *dev, int on)
-{
-       switch (dev->phy.type) {
-       case B43_PHYTYPE_A:
-       case B43_PHYTYPE_G:
-               b43_write16(dev, B43_MMIO_PHY0, on ? 0 : 0xF4);
-               break;
-       case B43_PHYTYPE_N:
-               b43_phy_write(dev, B43_NPHY_AFECTL_OVER,
-                             on ? 0 : 0x7FFF);
-               break;
-       default:
-               B43_WARN_ON(1);
-       }
-}
-
 void b43_wireless_core_reset(struct b43_wldev *dev, u32 flags)
 {
        u32 tmslow;
@@ -1091,8 +1074,12 @@ void b43_wireless_core_reset(struct b43_wldev *dev, u32 flags)
        ssb_read32(dev->dev, SSB_TMSLOW);       /* flush */
        msleep(1);
 
-       /* Turn Analog ON */
-       b43_switch_analog(dev, 1);
+       /* Turn Analog ON, but only if we already know the PHY-type.
+        * This protects against very early setup where we don't know the
+        * PHY-type, yet. wireless_core_reset will be called once again later,
+        * when we know the PHY-type. */
+       if (dev->phy.ops)
+               dev->phy.ops->switch_analog(dev, 1);
 
        macctl = b43_read32(dev, B43_MMIO_MACCTL);
        macctl &= ~B43_MACCTL_GMODE;
@@ -1257,13 +1244,13 @@ generate_new:
 
 static void handle_irq_tbtt_indication(struct b43_wldev *dev)
 {
-       if (b43_is_mode(dev->wl, IEEE80211_IF_TYPE_AP)) {
+       if (b43_is_mode(dev->wl, NL80211_IFTYPE_AP)) {
                ///TODO: PS TBTT
        } else {
                if (1 /*FIXME: the last PSpoll frame was sent successfully */ )
                        b43_power_saving_ctl_bits(dev, 0);
        }
-       if (b43_is_mode(dev->wl, IEEE80211_IF_TYPE_IBSS))
+       if (b43_is_mode(dev->wl, NL80211_IFTYPE_ADHOC))
                dev->dfq_valid = 1;
 }
 
@@ -1612,8 +1599,8 @@ static void handle_irq_beacon(struct b43_wldev *dev)
        struct b43_wl *wl = dev->wl;
        u32 cmd, beacon0_valid, beacon1_valid;
 
-       if (!b43_is_mode(wl, IEEE80211_IF_TYPE_AP) &&
-           !b43_is_mode(wl, IEEE80211_IF_TYPE_MESH_POINT))
+       if (!b43_is_mode(wl, NL80211_IFTYPE_AP) &&
+           !b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT))
                return;
 
        /* This is the bottom half of the asynchronous beacon update. */
@@ -2581,10 +2568,10 @@ static void b43_adjust_opmode(struct b43_wldev *dev)
        ctl &= ~B43_MACCTL_BEACPROMISC;
        ctl |= B43_MACCTL_INFRA;
 
-       if (b43_is_mode(wl, IEEE80211_IF_TYPE_AP) ||
-           b43_is_mode(wl, IEEE80211_IF_TYPE_MESH_POINT))
+       if (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
+           b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT))
                ctl |= B43_MACCTL_AP;
-       else if (b43_is_mode(wl, IEEE80211_IF_TYPE_IBSS))
+       else if (b43_is_mode(wl, NL80211_IFTYPE_ADHOC))
                ctl &= ~B43_MACCTL_INFRA;
 
        if (wl->filter_flags & FIF_CONTROL)
@@ -2694,6 +2681,7 @@ static void b43_mgmtframe_txantenna(struct b43_wldev *dev, int antenna)
 /* This is the opposite of b43_chip_init() */
 static void b43_chip_exit(struct b43_wldev *dev)
 {
+       b43_phy_exit(dev);
        b43_gpio_cleanup(dev);
        /* firmware is released later */
 }
@@ -2730,7 +2718,8 @@ static int b43_chip_init(struct b43_wldev *dev)
        if (err)
                goto err_gpio_clean;
 
-       b43_write16(dev, 0x03E6, 0x0000);
+       /* Turn the Analog on and initialize the PHY. */
+       phy->ops->switch_analog(dev, 1);
        err = b43_phy_init(dev);
        if (err)
                goto err_gpio_clean;
@@ -3070,36 +3059,31 @@ static void b43_qos_params_upload(struct b43_wldev *dev,
        }
 }
 
-/* Update the QOS parameters in hardware. */
-static void b43_qos_update(struct b43_wldev *dev)
+/* Mapping of mac80211 queue numbers to b43 QoS SHM offsets. */
+static const u16 b43_qos_shm_offsets[] = {
+       /* [mac80211-queue-nr] = SHM_OFFSET, */
+       [0] = B43_QOS_VOICE,
+       [1] = B43_QOS_VIDEO,
+       [2] = B43_QOS_BESTEFFORT,
+       [3] = B43_QOS_BACKGROUND,
+};
+
+/* Update all QOS parameters in hardware. */
+static void b43_qos_upload_all(struct b43_wldev *dev)
 {
        struct b43_wl *wl = dev->wl;
        struct b43_qos_params *params;
-       unsigned long flags;
        unsigned int i;
 
-       /* Mapping of mac80211 queues to b43 SHM offsets. */
-       static const u16 qos_shm_offsets[] = {
-               [0] = B43_QOS_VOICE,
-               [1] = B43_QOS_VIDEO,
-               [2] = B43_QOS_BESTEFFORT,
-               [3] = B43_QOS_BACKGROUND,
-       };
-       BUILD_BUG_ON(ARRAY_SIZE(qos_shm_offsets) != ARRAY_SIZE(wl->qos_params));
+       BUILD_BUG_ON(ARRAY_SIZE(b43_qos_shm_offsets) !=
+                    ARRAY_SIZE(wl->qos_params));
 
        b43_mac_suspend(dev);
-       spin_lock_irqsave(&wl->irq_lock, flags);
-
        for (i = 0; i < ARRAY_SIZE(wl->qos_params); i++) {
                params = &(wl->qos_params[i]);
-               if (params->need_hw_update) {
-                       b43_qos_params_upload(dev, &(params->p),
-                                             qos_shm_offsets[i]);
-                       params->need_hw_update = 0;
-               }
+               b43_qos_params_upload(dev, &(params->p),
+                                     b43_qos_shm_offsets[i]);
        }
-
-       spin_unlock_irqrestore(&wl->irq_lock, flags);
        b43_mac_enable(dev);
 }
 
@@ -3108,25 +3092,50 @@ static void b43_qos_clear(struct b43_wl *wl)
        struct b43_qos_params *params;
        unsigned int i;
 
+       /* Initialize QoS parameters to sane defaults. */
+
+       BUILD_BUG_ON(ARRAY_SIZE(b43_qos_shm_offsets) !=
+                    ARRAY_SIZE(wl->qos_params));
+
        for (i = 0; i < ARRAY_SIZE(wl->qos_params); i++) {
                params = &(wl->qos_params[i]);
 
-               memset(&(params->p), 0, sizeof(params->p));
-               params->p.aifs = -1;
-               params->need_hw_update = 1;
+               switch (b43_qos_shm_offsets[i]) {
+               case B43_QOS_VOICE:
+                       params->p.txop = 0;
+                       params->p.aifs = 2;
+                       params->p.cw_min = 0x0001;
+                       params->p.cw_max = 0x0001;
+                       break;
+               case B43_QOS_VIDEO:
+                       params->p.txop = 0;
+                       params->p.aifs = 2;
+                       params->p.cw_min = 0x0001;
+                       params->p.cw_max = 0x0001;
+                       break;
+               case B43_QOS_BESTEFFORT:
+                       params->p.txop = 0;
+                       params->p.aifs = 3;
+                       params->p.cw_min = 0x0001;
+                       params->p.cw_max = 0x03FF;
+                       break;
+               case B43_QOS_BACKGROUND:
+                       params->p.txop = 0;
+                       params->p.aifs = 7;
+                       params->p.cw_min = 0x0001;
+                       params->p.cw_max = 0x03FF;
+                       break;
+               default:
+                       B43_WARN_ON(1);
+               }
        }
 }
 
 /* Initialize the core's QOS capabilities */
 static void b43_qos_init(struct b43_wldev *dev)
 {
-       struct b43_wl *wl = dev->wl;
-       unsigned int i;
-
        /* Upload the current QOS parameters. */
-       for (i = 0; i < ARRAY_SIZE(wl->qos_params); i++)
-               wl->qos_params[i].need_hw_update = 1;
-       b43_qos_update(dev);
+       b43_qos_upload_all(dev);
 
        /* Enable QOS support. */
        b43_hf_write(dev, b43_hf_read(dev) | B43_HF_EDCF);
@@ -3135,25 +3144,13 @@ static void b43_qos_init(struct b43_wldev *dev)
                    | B43_MMIO_IFSCTL_USE_EDCF);
 }
 
-static void b43_qos_update_work(struct work_struct *work)
-{
-       struct b43_wl *wl = container_of(work, struct b43_wl, qos_update_work);
-       struct b43_wldev *dev;
-
-       mutex_lock(&wl->mutex);
-       dev = wl->current_dev;
-       if (likely(dev && (b43_status(dev) >= B43_STAT_INITIALIZED)))
-               b43_qos_update(dev);
-       mutex_unlock(&wl->mutex);
-}
-
 static int b43_op_conf_tx(struct ieee80211_hw *hw, u16 _queue,
                          const struct ieee80211_tx_queue_params *params)
 {
        struct b43_wl *wl = hw_to_b43_wl(hw);
-       unsigned long flags;
+       struct b43_wldev *dev;
        unsigned int queue = (unsigned int)_queue;
-       struct b43_qos_params *p;
+       int err = -ENODEV;
 
        if (queue >= ARRAY_SIZE(wl->qos_params)) {
                /* Queue not available or don't support setting
@@ -3161,16 +3158,25 @@ static int b43_op_conf_tx(struct ieee80211_hw *hw, u16 _queue,
                 * confuse mac80211. */
                return 0;
        }
+       BUILD_BUG_ON(ARRAY_SIZE(b43_qos_shm_offsets) !=
+                    ARRAY_SIZE(wl->qos_params));
 
-       spin_lock_irqsave(&wl->irq_lock, flags);
-       p = &(wl->qos_params[queue]);
-       memcpy(&(p->p), params, sizeof(p->p));
-       p->need_hw_update = 1;
-       spin_unlock_irqrestore(&wl->irq_lock, flags);
+       mutex_lock(&wl->mutex);
+       dev = wl->current_dev;
+       if (unlikely(!dev || (b43_status(dev) < B43_STAT_INITIALIZED)))
+               goto out_unlock;
 
-       queue_work(hw->workqueue, &wl->qos_update_work);
+       memcpy(&(wl->qos_params[queue].p), params, sizeof(*params));
+       b43_mac_suspend(dev);
+       b43_qos_params_upload(dev, &(wl->qos_params[queue].p),
+                             b43_qos_shm_offsets[queue]);
+       b43_mac_enable(dev);
+       err = 0;
 
-       return 0;
+out_unlock:
+       mutex_unlock(&wl->mutex);
+
+       return err;
 }
 
 static int b43_op_get_tx_stats(struct ieee80211_hw *hw,
@@ -3400,8 +3406,8 @@ static int b43_op_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
                phy->ops->set_rx_antenna(dev, antenna);
 
        /* Update templates for AP/mesh mode. */
-       if (b43_is_mode(wl, IEEE80211_IF_TYPE_AP) ||
-           b43_is_mode(wl, IEEE80211_IF_TYPE_MESH_POINT))
+       if (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
+           b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT))
                b43_set_beacon_int(dev, conf->beacon_int);
 
        if (!!conf->radio_enabled != phy->radio_on) {
@@ -3439,7 +3445,6 @@ static int b43_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
        u8 algorithm;
        u8 index;
        int err;
-       DECLARE_MAC_BUF(mac);
 
        if (modparam_nohwcrypt)
                return -ENOSPC; /* User disabled HW-crypto */
@@ -3527,9 +3532,9 @@ out_unlock:
        mutex_unlock(&wl->mutex);
        if (!err) {
                b43dbg(wl, "%s hardware based encryption for keyidx: %d, "
-                      "mac: %s\n",
+                      "mac: %pM\n",
                       cmd == SET_KEY ? "Using" : "Disabling", key->keyidx,
-                      print_mac(mac, addr));
+                      addr);
        }
        return err;
 }
@@ -3589,14 +3594,14 @@ static int b43_op_config_interface(struct ieee80211_hw *hw,
        else
                memset(wl->bssid, 0, ETH_ALEN);
        if (b43_status(dev) >= B43_STAT_INITIALIZED) {
-               if (b43_is_mode(wl, IEEE80211_IF_TYPE_AP) ||
-                   b43_is_mode(wl, IEEE80211_IF_TYPE_MESH_POINT)) {
+               if (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
+                   b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT)) {
                        B43_WARN_ON(vif->type != wl->if_type);
                        if (conf->changed & IEEE80211_IFCC_SSID)
                                b43_set_ssid(dev, conf->ssid, conf->ssid_len);
                        if (conf->changed & IEEE80211_IFCC_BEACON)
                                b43_update_templates(wl);
-               } else if (b43_is_mode(wl, IEEE80211_IF_TYPE_IBSS)) {
+               } else if (b43_is_mode(wl, NL80211_IFTYPE_ADHOC)) {
                        if (conf->changed & IEEE80211_IFCC_BEACON)
                                b43_update_templates(wl);
                }
@@ -3897,7 +3902,7 @@ static void b43_set_synth_pu_delay(struct b43_wldev *dev, bool idle)
                pu_delay = 3700;
        else
                pu_delay = 1050;
-       if (b43_is_mode(dev->wl, IEEE80211_IF_TYPE_IBSS) || idle)
+       if (b43_is_mode(dev->wl, NL80211_IFTYPE_ADHOC) || idle)
                pu_delay = 500;
        if ((dev->phy.radio_ver == 0x2050) && (dev->phy.radio_rev == 8))
                pu_delay = max(pu_delay, (u16)2400);
@@ -3911,7 +3916,7 @@ static void b43_set_pretbtt(struct b43_wldev *dev)
        u16 pretbtt;
 
        /* The time value is in microseconds. */
-       if (b43_is_mode(dev->wl, IEEE80211_IF_TYPE_IBSS)) {
+       if (b43_is_mode(dev->wl, NL80211_IFTYPE_ADHOC)) {
                pretbtt = 2;
        } else {
                if (dev->phy.type == B43_PHYTYPE_A)
@@ -3947,12 +3952,11 @@ static void b43_wireless_core_exit(struct b43_wldev *dev)
        b43_dma_free(dev);
        b43_pio_free(dev);
        b43_chip_exit(dev);
-       b43_switch_analog(dev, 0);
+       dev->phy.ops->switch_analog(dev, 0);
        if (dev->wl->current_beacon) {
                dev_kfree_skb_any(dev->wl->current_beacon);
                dev->wl->current_beacon = NULL;
        }
-       b43_phy_exit(dev);
 
        ssb_device_disable(dev->dev, 0);
        ssb_bus_may_powerdown(dev->dev->bus);
@@ -3979,24 +3983,23 @@ static int b43_wireless_core_init(struct b43_wldev *dev)
                b43_wireless_core_reset(dev, tmp);
        }
 
+       /* Reset all data structures. */
        setup_struct_wldev_for_init(dev);
-       err = b43_phy_operations_setup(dev);
-       if (err)
-               goto err_busdown;
+       phy->ops->prepare_structs(dev);
 
        /* Enable IRQ routing to this device. */
        ssb_pcicore_dev_irqvecs_enable(&bus->pcicore, dev->dev);
 
        b43_imcfglo_timeouts_workaround(dev);
        b43_bluetooth_coext_disable(dev);
-       if (phy->ops->prepare) {
-               err = phy->ops->prepare(dev);
+       if (phy->ops->prepare_hardware) {
+               err = phy->ops->prepare_hardware(dev);
                if (err)
-                       goto err_phy_exit;
+                       goto err_busdown;
        }
        err = b43_chip_init(dev);
        if (err)
-               goto err_phy_exit;
+               goto err_busdown;
        b43_shm_write16(dev, B43_SHM_SHARED,
                        B43_SHM_SH_WLCOREREV, dev->dev->id.revision);
        hf = b43_hf_read(dev);
@@ -4064,8 +4067,6 @@ out:
 
 err_chip_exit:
        b43_chip_exit(dev);
-err_phy_exit:
-       b43_phy_exit(dev);
 err_busdown:
        ssb_bus_may_powerdown(bus);
        B43_WARN_ON(b43_status(dev) != B43_STAT_UNINIT);
@@ -4082,11 +4083,11 @@ static int b43_op_add_interface(struct ieee80211_hw *hw,
 
        /* TODO: allow WDS/AP devices to coexist */
 
-       if (conf->type != IEEE80211_IF_TYPE_AP &&
-           conf->type != IEEE80211_IF_TYPE_MESH_POINT &&
-           conf->type != IEEE80211_IF_TYPE_STA &&
-           conf->type != IEEE80211_IF_TYPE_WDS &&
-           conf->type != IEEE80211_IF_TYPE_IBSS)
+       if (conf->type != NL80211_IFTYPE_AP &&
+           conf->type != NL80211_IFTYPE_MESH_POINT &&
+           conf->type != NL80211_IFTYPE_STATION &&
+           conf->type != NL80211_IFTYPE_WDS &&
+           conf->type != NL80211_IFTYPE_ADHOC)
                return -EOPNOTSUPP;
 
        mutex_lock(&wl->mutex);
@@ -4201,7 +4202,6 @@ static void b43_op_stop(struct ieee80211_hw *hw)
        struct b43_wldev *dev = wl->current_dev;
 
        b43_rfkill_exit(dev);
-       cancel_work_sync(&(wl->qos_update_work));
        cancel_work_sync(&(wl->beacon_update_trigger));
 
        mutex_lock(&wl->mutex);
@@ -4233,7 +4233,8 @@ out_unlock:
        return err;
 }
 
-static int b43_op_beacon_set_tim(struct ieee80211_hw *hw, int aid, int set)
+static int b43_op_beacon_set_tim(struct ieee80211_hw *hw,
+                                struct ieee80211_sta *sta, bool set)
 {
        struct b43_wl *wl = hw_to_b43_wl(hw);
        unsigned long flags;
@@ -4248,7 +4249,7 @@ static int b43_op_beacon_set_tim(struct ieee80211_hw *hw, int aid, int set)
 static void b43_op_sta_notify(struct ieee80211_hw *hw,
                              struct ieee80211_vif *vif,
                              enum sta_notify_cmd notify_cmd,
-                             const u8 *addr)
+                             struct ieee80211_sta *sta)
 {
        struct b43_wl *wl = hw_to_b43_wl(hw);
 
@@ -4342,6 +4343,7 @@ static void b43_wireless_core_detach(struct b43_wldev *dev)
        /* We release firmware that late to not be required to re-request
         * is all the time when we reinit the core. */
        b43_release_firmware(dev);
+       b43_phy_free(dev);
 }
 
 static int b43_wireless_core_attach(struct b43_wldev *dev)
@@ -4415,29 +4417,35 @@ static int b43_wireless_core_attach(struct b43_wldev *dev)
                }
        }
 
+       err = b43_phy_allocate(dev);
+       if (err)
+               goto err_powerdown;
+
        dev->phy.gmode = have_2ghz_phy;
        tmp = dev->phy.gmode ? B43_TMSLOW_GMODE : 0;
        b43_wireless_core_reset(dev, tmp);
 
        err = b43_validate_chipaccess(dev);
        if (err)
-               goto err_powerdown;
+               goto err_phy_free;
        err = b43_setup_bands(dev, have_2ghz_phy, have_5ghz_phy);
        if (err)
-               goto err_powerdown;
+               goto err_phy_free;
 
        /* Now set some default "current_dev" */
        if (!wl->current_dev)
                wl->current_dev = dev;
        INIT_WORK(&dev->restart_work, b43_chip_reset);
 
-       b43_switch_analog(dev, 0);
+       dev->phy.ops->switch_analog(dev, 0);
        ssb_device_disable(dev->dev, 0);
        ssb_bus_may_powerdown(bus);
 
 out:
        return err;
 
+err_phy_free:
+       b43_phy_free(dev);
 err_powerdown:
        ssb_bus_may_powerdown(bus);
        return err;
@@ -4534,9 +4542,11 @@ static void b43_sprom_fixup(struct ssb_bus *bus)
                pdev = bus->host_pci;
                if (IS_PDEV(pdev, BROADCOM, 0x4318, ASUSTEK, 0x100F) ||
                    IS_PDEV(pdev, BROADCOM, 0x4320,    DELL, 0x0003) ||
+                   IS_PDEV(pdev, BROADCOM, 0x4320,      HP, 0x12f8) ||
                    IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0015) ||
                    IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0014) ||
-                   IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0013))
+                   IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0013) ||
+                   IS_PDEV(pdev, BROADCOM, 0x4320, MOTOROLA, 0x7010))
                        bus->sprom.boardflags_lo &= ~B43_BFL_BTCOEXIST;
        }
 }
@@ -4569,7 +4579,15 @@ static int b43_wireless_init(struct ssb_device *dev)
                    IEEE80211_HW_SIGNAL_DBM |
                    IEEE80211_HW_NOISE_DBM;
 
+       hw->wiphy->interface_modes =
+               BIT(NL80211_IFTYPE_AP) |
+               BIT(NL80211_IFTYPE_MESH_POINT) |
+               BIT(NL80211_IFTYPE_STATION) |
+               BIT(NL80211_IFTYPE_WDS) |
+               BIT(NL80211_IFTYPE_ADHOC);
+
        hw->queues = b43_modparam_qos ? 4 : 1;
+       hw->max_altrates = 1;
        SET_IEEE80211_DEV(hw, dev->dev);
        if (is_valid_ether_addr(sprom->et1mac))
                SET_IEEE80211_PERM_ADDR(hw, sprom->et1mac);
@@ -4586,7 +4604,6 @@ static int b43_wireless_init(struct ssb_device *dev)
        spin_lock_init(&wl->shm_lock);
        mutex_init(&wl->mutex);
        INIT_LIST_HEAD(&wl->devlist);
-       INIT_WORK(&wl->qos_update_work, b43_qos_update_work);
        INIT_WORK(&wl->beacon_update_trigger, b43_beacon_update_trigger_work);
        INIT_WORK(&wl->txpower_adjust_work, b43_phy_txpower_adjust_work);