b43: Suspend MAC while killing the radio
[safe/jmp/linux-2.6] / drivers / net / wireless / b43 / xmit.c
index b2a3123..eae9b80 100644 (file)
@@ -28,7 +28,7 @@
 */
 
 #include "xmit.h"
-#include "phy.h"
+#include "phy_common.h"
 #include "dma.h"
 #include "pio.h"
 
@@ -46,7 +46,6 @@ static int b43_plcp_get_bitrate_idx_cck(struct b43_plcp_hdr6 *plcp)
        case 0x6E:
                return 3;
        }
-       B43_WARN_ON(1);
        return -1;
 }
 
@@ -73,7 +72,6 @@ static u8 b43_plcp_get_bitrate_idx_ofdm(struct b43_plcp_hdr6 *plcp, bool aphy)
        case 0xC:
                return base + 7;
        }
-       B43_WARN_ON(1);
        return -1;
 }
 
@@ -185,15 +183,15 @@ int b43_generate_txhdr(struct b43_wldev *dev,
                       u8 *_txhdr,
                       const unsigned char *fragment_data,
                       unsigned int fragment_len,
-                      const struct ieee80211_tx_control *txctl,
+                      struct ieee80211_tx_info *info,
                       u16 cookie)
 {
        struct b43_txhdr *txhdr = (struct b43_txhdr *)_txhdr;
        const struct b43_phy *phy = &dev->phy;
        const struct ieee80211_hdr *wlhdr =
            (const struct ieee80211_hdr *)fragment_data;
-       int use_encryption = (!(txctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT));
-       u16 fctl = le16_to_cpu(wlhdr->frame_control);
+       int use_encryption = !!info->control.hw_key;
+       __le16 fctl = wlhdr->frame_control;
        struct ieee80211_rate *fbrate;
        u8 rate, rate_fb;
        int rate_ofdm, rate_fb_ofdm;
@@ -201,13 +199,15 @@ int b43_generate_txhdr(struct b43_wldev *dev,
        u32 mac_ctl = 0;
        u16 phy_ctl = 0;
        u8 extra_ft = 0;
+       struct ieee80211_rate *txrate;
+       struct ieee80211_tx_rate *rates;
 
        memset(txhdr, 0, sizeof(*txhdr));
 
-       WARN_ON(!txctl->tx_rate);
-       rate = txctl->tx_rate ? txctl->tx_rate->hw_value : B43_CCK_RATE_1MB;
+       txrate = ieee80211_get_tx_rate(dev->wl->hw, info);
+       rate = txrate ? txrate->hw_value : B43_CCK_RATE_1MB;
        rate_ofdm = b43_is_ofdm_rate(rate);
-       fbrate = txctl->alt_retry_rate ? : txctl->tx_rate;
+       fbrate = ieee80211_get_alt_retry_rate(dev->wl->hw, info, 0) ? : txrate;
        rate_fb = fbrate->hw_value;
        rate_fb_ofdm = b43_is_ofdm_rate(rate_fb);
 
@@ -227,15 +227,13 @@ int b43_generate_txhdr(struct b43_wldev *dev,
                 * use the original dur_id field. */
                txhdr->dur_fb = wlhdr->duration_id;
        } else {
-               txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw,
-                                                                txctl->vif,
-                                                                fragment_len,
-                                                                fbrate);
+               txhdr->dur_fb = ieee80211_generic_frame_duration(
+                       dev->wl->hw, info->control.vif, fragment_len, fbrate);
        }
 
        plcp_fragment_len = fragment_len + FCS_LEN;
        if (use_encryption) {
-               u8 key_idx = (u16) (txctl->key_idx);
+               u8 key_idx = info->control.hw_key->hw_key_idx;
                struct b43_key *key;
                int wlhdr_len;
                size_t iv_len;
@@ -253,15 +251,15 @@ int b43_generate_txhdr(struct b43_wldev *dev,
                }
 
                /* Hardware appends ICV. */
-               plcp_fragment_len += txctl->icv_len;
+               plcp_fragment_len += info->control.hw_key->icv_len;
 
                key_idx = b43_kidx_to_fw(dev, key_idx);
                mac_ctl |= (key_idx << B43_TXH_MAC_KEYIDX_SHIFT) &
                           B43_TXH_MAC_KEYIDX;
                mac_ctl |= (key->algorithm << B43_TXH_MAC_KEYALG_SHIFT) &
                           B43_TXH_MAC_KEYALG;
-               wlhdr_len = ieee80211_get_hdrlen(fctl);
-               iv_len = min((size_t) txctl->iv_len,
+               wlhdr_len = ieee80211_hdrlen(fctl);
+               iv_len = min((size_t) info->control.hw_key->iv_len,
                             ARRAY_SIZE(txhdr->iv));
                memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len);
        }
@@ -292,10 +290,10 @@ int b43_generate_txhdr(struct b43_wldev *dev,
                phy_ctl |= B43_TXH_PHY_ENC_OFDM;
        else
                phy_ctl |= B43_TXH_PHY_ENC_CCK;
-       if (txctl->flags & IEEE80211_TXCTL_SHORT_PREAMBLE)
+       if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
                phy_ctl |= B43_TXH_PHY_SHORTPRMBL;
 
-       switch (b43_ieee80211_antenna_sanitize(dev, txctl->antenna_sel_tx)) {
+       switch (b43_ieee80211_antenna_sanitize(dev, info->antenna_sel_tx)) {
        case 0: /* Default */
                phy_ctl |= B43_TXH_PHY_ANT01AUTO;
                break;
@@ -315,35 +313,48 @@ int b43_generate_txhdr(struct b43_wldev *dev,
                B43_WARN_ON(1);
        }
 
+       rates = info->control.rates;
        /* MAC control */
-       if (!(txctl->flags & IEEE80211_TXCTL_NO_ACK))
+       if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
                mac_ctl |= B43_TXH_MAC_ACK;
-       if (!(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
-             ((fctl & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)))
+       /* use hardware sequence counter as the non-TID counter */
+       if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
                mac_ctl |= B43_TXH_MAC_HWSEQ;
-       if (txctl->flags & IEEE80211_TXCTL_FIRST_FRAGMENT)
+       if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
                mac_ctl |= B43_TXH_MAC_STMSDU;
        if (phy->type == B43_PHYTYPE_A)
                mac_ctl |= B43_TXH_MAC_5GHZ;
-       if (txctl->flags & IEEE80211_TXCTL_LONG_RETRY_LIMIT)
+
+       /* Overwrite rates[0].count to make the retry calculation
+        * in the tx status easier. need the actual retry limit to
+        * detect whether the fallback rate was used.
+        */
+       if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
+           (rates[0].count <= dev->wl->hw->conf.long_frame_max_tx_count)) {
+               rates[0].count = dev->wl->hw->conf.long_frame_max_tx_count;
                mac_ctl |= B43_TXH_MAC_LONGFRAME;
+       } else {
+               rates[0].count = dev->wl->hw->conf.short_frame_max_tx_count;
+       }
 
        /* Generate the RTS or CTS-to-self frame */
-       if ((txctl->flags & IEEE80211_TXCTL_USE_RTS_CTS) ||
-           (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) {
+       if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
+           (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)) {
                unsigned int len;
                struct ieee80211_hdr *hdr;
                int rts_rate, rts_rate_fb;
                int rts_rate_ofdm, rts_rate_fb_ofdm;
                struct b43_plcp_hdr6 *plcp;
+               struct ieee80211_rate *rts_cts_rate;
+
+               rts_cts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info);
 
-               WARN_ON(!txctl->rts_cts_rate);
-               rts_rate = txctl->rts_cts_rate ? txctl->rts_cts_rate->hw_value : B43_CCK_RATE_1MB;
+               rts_rate = rts_cts_rate ? rts_cts_rate->hw_value : B43_CCK_RATE_1MB;
                rts_rate_ofdm = b43_is_ofdm_rate(rts_rate);
                rts_rate_fb = b43_calc_fallback_rate(rts_rate);
                rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb);
 
-               if (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
+               if (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
                        struct ieee80211_cts *cts;
 
                        if (b43_is_old_txhdr_format(dev)) {
@@ -353,9 +364,9 @@ int b43_generate_txhdr(struct b43_wldev *dev,
                                cts = (struct ieee80211_cts *)
                                        (txhdr->new_format.rts_frame);
                        }
-                       ieee80211_ctstoself_get(dev->wl->hw, txctl->vif,
+                       ieee80211_ctstoself_get(dev->wl->hw, info->control.vif,
                                                fragment_data, fragment_len,
-                                               txctl, cts);
+                                               info, cts);
                        mac_ctl |= B43_TXH_MAC_SENDCTS;
                        len = sizeof(struct ieee80211_cts);
                } else {
@@ -368,9 +379,9 @@ int b43_generate_txhdr(struct b43_wldev *dev,
                                rts = (struct ieee80211_rts *)
                                        (txhdr->new_format.rts_frame);
                        }
-                       ieee80211_rts_get(dev->wl->hw, txctl->vif,
+                       ieee80211_rts_get(dev->wl->hw, info->control.vif,
                                          fragment_data, fragment_len,
-                                         txctl, rts);
+                                         info, rts);
                        mac_ctl |= B43_TXH_MAC_SENDRTS;
                        len = sizeof(struct ieee80211_rts);
                }
@@ -430,6 +441,7 @@ static s8 b43_rssi_postprocess(struct b43_wldev *dev,
                               int adjust_2053, int adjust_2050)
 {
        struct b43_phy *phy = &dev->phy;
+       struct b43_phy_g *gphy = phy->g;
        s32 tmp;
 
        switch (phy->radio_ver) {
@@ -449,7 +461,8 @@ static s8 b43_rssi_postprocess(struct b43_wldev *dev,
                            boardflags_lo & B43_BFL_RSSI) {
                                if (in_rssi > 63)
                                        in_rssi = 63;
-                               tmp = phy->nrssi_lt[in_rssi];
+                               B43_WARN_ON(phy->type != B43_PHYTYPE_G);
+                               tmp = gphy->nrssi_lt[in_rssi];
                                tmp = 31 - tmp;
                                tmp *= -131;
                                tmp /= 128;
@@ -508,12 +521,11 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
        struct b43_plcp_hdr6 *plcp;
        struct ieee80211_hdr *wlhdr;
        const struct b43_rxhdr_fw4 *rxhdr = _rxhdr;
-       u16 fctl;
+       __le16 fctl;
        u16 phystat0, phystat3, chanstat, mactime;
        u32 macstat;
        u16 chanid;
        u16 phytype;
-       u8 jssi;
        int padding;
 
        memset(&status, 0, sizeof(status));
@@ -521,7 +533,6 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
        /* Get metadata about the frame from the header. */
        phystat0 = le16_to_cpu(rxhdr->phy_status0);
        phystat3 = le16_to_cpu(rxhdr->phy_status3);
-       jssi = rxhdr->jssi;
        macstat = le32_to_cpu(rxhdr->mac_status);
        mactime = le16_to_cpu(rxhdr->mac_time);
        chanstat = le16_to_cpu(rxhdr->channel);
@@ -550,7 +561,7 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
                goto drop;
        }
        wlhdr = (struct ieee80211_hdr *)(skb->data);
-       fctl = le16_to_cpu(wlhdr->frame_control);
+       fctl = wlhdr->frame_control;
 
        if (macstat & B43_RX_MAC_DEC) {
                unsigned int keyidx;
@@ -565,7 +576,7 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
                B43_WARN_ON(keyidx >= dev->max_nr_keys);
 
                if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) {
-                       wlhdr_len = ieee80211_get_hdrlen(fctl);
+                       wlhdr_len = ieee80211_hdrlen(fctl);
                        if (unlikely(skb->len < (wlhdr_len + 3))) {
                                b43dbg(dev->wl,
                                       "RX: Packet size underrun (3)\n");
@@ -575,18 +586,28 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
                }
        }
 
-       status.ssi = b43_rssi_postprocess(dev, jssi,
-                                         (phystat0 & B43_RX_PHYST0_OFDM),
-                                         (phystat0 & B43_RX_PHYST0_GAINCTL),
-                                         (phystat3 & B43_RX_PHYST3_TRSTATE));
+       /* Link quality statistics */
        status.noise = dev->stats.link_noise;
-       /* the next line looks wrong, but is what mac80211 wants */
-       status.signal = (jssi * 100) / B43_RX_MAX_SSI;
+       if ((chanstat & B43_RX_CHAN_PHYTYPE) == B43_PHYTYPE_N) {
+//             s8 rssi = max(rxhdr->power0, rxhdr->power1);
+               //TODO: Find out what the rssi value is (dBm or percentage?)
+               //      and also find out what the maximum possible value is.
+               //      Fill status.ssi and status.signal fields.
+       } else {
+               status.signal = b43_rssi_postprocess(dev, rxhdr->jssi,
+                                                 (phystat0 & B43_RX_PHYST0_OFDM),
+                                                 (phystat0 & B43_RX_PHYST0_GAINCTL),
+                                                 (phystat3 & B43_RX_PHYST3_TRSTATE));
+               status.qual = (rxhdr->jssi * 100) / B43_RX_MAX_SSI;
+       }
+
        if (phystat0 & B43_RX_PHYST0_OFDM)
                status.rate_idx = b43_plcp_get_bitrate_idx_ofdm(plcp,
                                                phytype == B43_PHYTYPE_A);
        else
                status.rate_idx = b43_plcp_get_bitrate_idx_cck(plcp);
+       if (unlikely(status.rate_idx == -1))
+               goto drop;
        status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT);
 
        /*
@@ -597,9 +618,7 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
         * of timestamp, i.e. about 65 milliseconds after the PHY received
         * the first symbol.
         */
-       if (((fctl & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE))
-           == (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON)) ||
-           dev->wl->radiotap_enabled) {
+       if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) {
                u16 low_mactime_now;
 
                b43_tsf_read(dev, &status.mactime);
@@ -673,32 +692,60 @@ void b43_handle_txstatus(struct b43_wldev *dev,
                b43_pio_handle_txstatus(dev, status);
        else
                b43_dma_handle_txstatus(dev, status);
+
+       b43_phy_txpower_check(dev, 0);
 }
 
 /* Fill out the mac80211 TXstatus report based on the b43-specific
  * txstatus report data. This returns a boolean whether the frame was
  * successfully transmitted. */
-bool b43_fill_txstatus_report(struct ieee80211_tx_status *report,
+bool b43_fill_txstatus_report(struct b43_wldev *dev,
+                             struct ieee80211_tx_info *report,
                              const struct b43_txstatus *status)
 {
        bool frame_success = 1;
+       int retry_limit;
+
+       /* preserve the confiured retry limit before clearing the status
+        * The xmit function has overwritten the rc's value with the actual
+        * retry limit done by the hardware */
+       retry_limit = report->status.rates[0].count;
+       ieee80211_tx_info_clear_status(report);
 
        if (status->acked) {
                /* The frame was ACKed. */
-               report->flags |= IEEE80211_TX_STATUS_ACK;
+               report->flags |= IEEE80211_TX_STAT_ACK;
        } else {
                /* The frame was not ACKed... */
-               if (!(report->control.flags & IEEE80211_TXCTL_NO_ACK)) {
+               if (!(report->flags & IEEE80211_TX_CTL_NO_ACK)) {
                        /* ...but we expected an ACK. */
                        frame_success = 0;
-                       report->excessive_retries = 1;
                }
        }
        if (status->frame_count == 0) {
                /* The frame was not transmitted at all. */
-               report->retry_count = 0;
-       } else
-               report->retry_count = status->frame_count - 1;
+               report->status.rates[0].count = 0;
+       } else if (status->rts_count > dev->wl->hw->conf.short_frame_max_tx_count) {
+               /*
+                * If the short retries (RTS, not data frame) have exceeded
+                * the limit, the hw will not have tried the selected rate,
+                * but will have used the fallback rate instead.
+                * Don't let the rate control count attempts for the selected
+                * rate in this case, otherwise the statistics will be off.
+                */
+               report->status.rates[0].count = 0;
+               report->status.rates[1].count = status->frame_count;
+       } else {
+               if (status->frame_count > retry_limit) {
+                       report->status.rates[0].count = retry_limit;
+                       report->status.rates[1].count = status->frame_count -
+                                       retry_limit;
+
+               } else {
+                       report->status.rates[0].count = status->frame_count;
+                       report->status.rates[1].idx = -1;
+               }
+       }
 
        return frame_success;
 }