wl1251: fix ELP_CTRL register accesses when using SDIO
[safe/jmp/linux-2.6] / drivers / net / wireless / wl12xx / wl1251_main.c
index 1db9722..0155653 100644 (file)
@@ -146,8 +146,8 @@ static void wl1251_fw_wakeup(struct wl1251 *wl)
        u32 elp_reg;
 
        elp_reg = ELPCTRL_WAKE_UP;
-       wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
-       elp_reg = wl1251_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
+       wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
+       elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
 
        if (!(elp_reg & ELPCTRL_WLAN_READY))
                wl1251_warning("WLAN not ready");
@@ -563,6 +563,27 @@ static void wl1251_op_remove_interface(struct ieee80211_hw *hw,
        mutex_unlock(&wl->mutex);
 }
 
+static int wl1251_build_qos_null_data(struct wl1251 *wl)
+{
+       struct ieee80211_qos_hdr template;
+
+       memset(&template, 0, sizeof(template));
+
+       memcpy(template.addr1, wl->bssid, ETH_ALEN);
+       memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
+       memcpy(template.addr3, wl->bssid, ETH_ALEN);
+
+       template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
+                                            IEEE80211_STYPE_QOS_NULLFUNC |
+                                            IEEE80211_FCTL_TODS);
+
+       /* FIXME: not sure what priority to use here */
+       template.qos_ctrl = cpu_to_le16(0);
+
+       return wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, &template,
+                                      sizeof(template));
+}
+
 static int wl1251_op_config(struct ieee80211_hw *hw, u32 changed)
 {
        struct wl1251 *wl = hw->priv;
@@ -596,10 +617,13 @@ static int wl1251_op_config(struct ieee80211_hw *hw, u32 changed)
 
                wl->psm_requested = true;
 
+               wl->dtim_period = conf->ps_dtim_period;
+
+               ret = wl1251_acx_wr_tbtt_and_dtim(wl, wl->beacon_int,
+                                                 wl->dtim_period);
+
                /*
-                * We enter PSM only if we're already associated.
-                * If we're not, we'll enter it when joining an SSID,
-                * through the bss_info_changed() hook.
+                * mac80211 enables PSM only if we're already associated.
                 */
                ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
                if (ret < 0)
@@ -878,7 +902,8 @@ static int wl1251_op_hw_scan(struct ieee80211_hw *hw,
 
        wl->scanning = true;
 
-       ret = wl1251_cmd_scan(wl, ssid, ssid_len, 13, 3);
+       ret = wl1251_cmd_scan(wl, ssid, ssid_len, req->channels,
+                             req->n_channels, WL1251_SCAN_NUM_PROBES);
        if (ret < 0) {
                wl->scanning = false;
                goto out_sleep;
@@ -921,7 +946,6 @@ static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
                                       struct ieee80211_bss_conf *bss_conf,
                                       u32 changed)
 {
-       enum wl1251_cmd_ps_mode mode;
        struct wl1251 *wl = hw->priv;
        struct sk_buff *beacon, *skb;
        int ret;
@@ -945,6 +969,10 @@ static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
                                              skb->data, skb->len);
                dev_kfree_skb(skb);
                if (ret < 0)
+                       goto out_sleep;
+
+               ret = wl1251_build_qos_null_data(wl);
+               if (ret < 0)
                        goto out;
 
                if (wl->bss_type != BSS_TYPE_IBSS) {
@@ -958,11 +986,6 @@ static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
        if (changed & BSS_CHANGED_ASSOC) {
                if (bss_conf->assoc) {
                        wl->beacon_int = bss_conf->beacon_int;
-                       wl->dtim_period = bss_conf->dtim_period;
-
-                       ret = wl1251_acx_wr_tbtt_and_dtim(wl, wl->beacon_int,
-                                                         wl->dtim_period);
-                       wl->aid = bss_conf->aid;
 
                        skb = ieee80211_pspoll_get(wl->hw, wl->vif);
                        if (!skb)
@@ -975,17 +998,9 @@ static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
                        if (ret < 0)
                                goto out_sleep;
 
-                       ret = wl1251_acx_aid(wl, wl->aid);
+                       ret = wl1251_acx_aid(wl, bss_conf->aid);
                        if (ret < 0)
                                goto out_sleep;
-
-                       /* If we want to go in PSM but we're not there yet */
-                       if (wl->psm_requested && !wl->psm) {
-                               mode = STATION_POWER_SAVE_MODE;
-                               ret = wl1251_ps_set_mode(wl, mode);
-                               if (ret < 0)
-                                       goto out_sleep;
-                       }
                } else {
                        /* use defaults when not associated */
                        wl->beacon_int = WL1251_DEFAULT_BEACON_INT;
@@ -1017,7 +1032,7 @@ static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
                        ret = wl1251_acx_cts_protect(wl, CTSPROTECT_DISABLE);
                if (ret < 0) {
                        wl1251_warning("Set ctsprotect failed %d", ret);
-                       goto out;
+                       goto out_sleep;
                }
        }
 
@@ -1028,7 +1043,7 @@ static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
 
                if (ret < 0) {
                        dev_kfree_skb(beacon);
-                       goto out;
+                       goto out_sleep;
                }
 
                ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data,
@@ -1037,13 +1052,13 @@ static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
                dev_kfree_skb(beacon);
 
                if (ret < 0)
-                       goto out;
+                       goto out_sleep;
 
                ret = wl1251_join(wl, wl->bss_type, wl->beacon_int,
                                  wl->channel, wl->dtim_period);
 
                if (ret < 0)
-                       goto out;
+                       goto out_sleep;
        }
 
 out_sleep:
@@ -1117,6 +1132,7 @@ static struct ieee80211_channel wl1251_channels[] = {
 static int wl1251_op_conf_tx(struct ieee80211_hw *hw, u16 queue,
                             const struct ieee80211_tx_queue_params *params)
 {
+       enum wl1251_acx_ps_scheme ps_scheme;
        struct wl1251 *wl = hw->priv;
        int ret;
 
@@ -1128,16 +1144,21 @@ static int wl1251_op_conf_tx(struct ieee80211_hw *hw, u16 queue,
        if (ret < 0)
                goto out;
 
+       /* mac80211 uses units of 32 usec */
        ret = wl1251_acx_ac_cfg(wl, wl1251_tx_get_queue(queue),
                                params->cw_min, params->cw_max,
-                               params->aifs, params->txop);
+                               params->aifs, params->txop * 32);
        if (ret < 0)
                goto out_sleep;
 
+       if (params->uapsd)
+               ps_scheme = WL1251_ACX_PS_SCHEME_UPSD_TRIGGER;
+       else
+               ps_scheme = WL1251_ACX_PS_SCHEME_LEGACY;
+
        ret = wl1251_acx_tid_cfg(wl, wl1251_tx_get_queue(queue),
                                 CHANNEL_TYPE_EDCF,
-                                wl1251_tx_get_queue(queue),
-                                WL1251_ACX_PS_SCHEME_LEGACY,
+                                wl1251_tx_get_queue(queue), ps_scheme,
                                 WL1251_ACX_ACK_POLICY_LEGACY);
        if (ret < 0)
                goto out_sleep;
@@ -1211,7 +1232,8 @@ int wl1251_init_ieee80211(struct wl1251 *wl)
        wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
                IEEE80211_HW_NOISE_DBM |
                IEEE80211_HW_SUPPORTS_PS |
-               IEEE80211_HW_BEACON_FILTER;
+               IEEE80211_HW_BEACON_FILTER |
+               IEEE80211_HW_SUPPORTS_UAPSD;
 
        wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
        wl->hw->wiphy->max_scan_ssids = 1;