]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/wireless/p54/p54common.c
p54: implement MRR
[linux-2.6-omap-h63xx.git] / drivers / net / wireless / p54 / p54common.c
index 2d022f83774c6be9fc77d2485c6bd564e2203271..237090140243ccb54b778867107af6bbbbd16588 100644 (file)
@@ -1,9 +1,9 @@
-
 /*
  * Common code for mac80211 Prism54 drivers
  *
  * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
  * Copyright (c) 2007, Christian Lamparter <chunkeey@web.de>
+ * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
  *
  * Based on the islsm (softmac prism54) driver, which is:
  * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
@@ -183,7 +183,7 @@ int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw)
                        priv->headroom = desc->headroom;
                        priv->tailroom = desc->tailroom;
                        if (le32_to_cpu(bootrec->len) == 11)
-                               priv->rx_mtu = le16_to_cpu(bootrec->rx_mtu);
+                               priv->rx_mtu = le16_to_cpu(desc->rx_mtu);
                        else
                                priv->rx_mtu = (size_t)
                                        0x620 - priv->tx_hdr_len;
@@ -319,8 +319,7 @@ static int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
        void *tmp;
        int err;
        u8 *end = (u8 *)eeprom + len;
-       u16 synth;
-       DECLARE_MAC_BUF(mac);
+       u16 synth = 0;
 
        wrap = (struct eeprom_pda_wrap *) eeprom;
        entry = (void *)wrap->data + le16_to_cpu(wrap->len);
@@ -422,7 +421,8 @@ static int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
                entry = (void *)entry + (entry_len + 1)*2;
        }
 
-       if (!priv->iq_autocal || !priv->output_limit || !priv->curve_data) {
+       if (!synth || !priv->iq_autocal || !priv->output_limit ||
+           !priv->curve_data) {
                printk(KERN_ERR "p54: not all required entries found in eeprom!\n");
                err = -EINVAL;
                goto err;
@@ -445,9 +445,9 @@ static int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
                SET_IEEE80211_PERM_ADDR(dev, perm_addr);
        }
 
-       printk(KERN_INFO "%s: hwaddr %s, MAC:isl38%02x RF:%s\n",
+       printk(KERN_INFO "%s: hwaddr %pM, MAC:isl38%02x RF:%s\n",
                wiphy_name(dev->wiphy),
-               print_mac(mac, dev->wiphy->perm_addr),
+               dev->wiphy->perm_addr,
                priv->version, p54_rf_chips[priv->rxhw]);
 
        return 0;
@@ -544,11 +544,12 @@ static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb)
        u32 freed = 0;
        u32 last_addr = priv->rx_start;
        unsigned long flags;
+       int count, idx;
 
        spin_lock_irqsave(&priv->tx_queue.lock, flags);
        while (entry != (struct sk_buff *)&priv->tx_queue) {
                struct ieee80211_tx_info *info = IEEE80211_SKB_CB(entry);
-               range = (void *)info->driver_data;
+               range = (void *)info->rate_driver_data;
                if (range->start_addr == addr) {
                        struct p54_control_hdr *entry_hdr;
                        struct p54_tx_control_allocdata *entry_data;
@@ -559,7 +560,7 @@ static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb)
                                struct memrecord *mr;
 
                                ni = IEEE80211_SKB_CB(entry->next);
-                               mr = (struct memrecord *)ni->driver_data;
+                               mr = (struct memrecord *)ni->rate_driver_data;
                                freed = mr->start_addr - last_addr;
                        } else
                                freed = priv->rx_end - last_addr;
@@ -568,20 +569,39 @@ static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb)
                        __skb_unlink(entry, &priv->tx_queue);
                        spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
 
-                       memset(&info->status, 0, sizeof(info->status));
+                       /*
+                        * Clear manually, ieee80211_tx_info_clear_status would
+                        * clear the counts too and we need them.
+                        */
+                       memset(&info->status.ampdu_ack_len, 0,
+                              sizeof(struct ieee80211_tx_info) -
+                              offsetof(struct ieee80211_tx_info, status.ampdu_ack_len));
+                       BUILD_BUG_ON(offsetof(struct ieee80211_tx_info,
+                                             status.ampdu_ack_len) != 23);
+
                        entry_hdr = (struct p54_control_hdr *) entry->data;
                        entry_data = (struct p54_tx_control_allocdata *) entry_hdr->data;
                        if ((entry_hdr->magic1 & cpu_to_le16(0x4000)) != 0)
                                pad = entry_data->align[0];
 
-                       priv->tx_stats[entry_data->hw_queue].len--;
-                       if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
-                               if (!(payload->status & 0x01))
-                                       info->flags |= IEEE80211_TX_STAT_ACK;
-                               else
-                                       info->status.excessive_retries = 1;
+                       /* walk through the rates array and adjust the counts */
+                       count = payload->retries;
+                       for (idx = 0; idx < 4; idx++) {
+                               if (count >= info->status.rates[idx].count) {
+                                       count -= info->status.rates[idx].count;
+                               } else if (count > 0) {
+                                       info->status.rates[idx].count = count;
+                                       count = 0;
+                               } else {
+                                       info->status.rates[idx].idx = -1;
+                                       info->status.rates[idx].count = 0;
+                               }
                        }
-                       info->status.retry_count = payload->retries - 1;
+
+                       priv->tx_stats[entry_data->hw_queue].len--;
+                       if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) &&
+                           !(payload->status & 0x01))
+                               info->flags |= IEEE80211_TX_STAT_ACK;
                        info->status.ack_signal = p54_rssi_to_dbm(dev,
                                        le16_to_cpu(payload->ack_rssi));
                        skb_pull(entry, sizeof(*hdr) + pad + sizeof(*entry_data));
@@ -699,7 +719,7 @@ static void p54_assign_address(struct ieee80211_hw *dev, struct sk_buff *skb,
        while (left--) {
                u32 hole_size;
                struct ieee80211_tx_info *info = IEEE80211_SKB_CB(entry);
-               struct memrecord *range = (void *)info->driver_data;
+               struct memrecord *range = (void *)info->rate_driver_data;
                hole_size = range->start_addr - last_addr;
                if (!target_skb && hole_size >= len) {
                        target_skb = entry->prev;
@@ -715,7 +735,7 @@ static void p54_assign_address(struct ieee80211_hw *dev, struct sk_buff *skb,
                largest_hole = max(largest_hole, priv->rx_end - last_addr - len);
                if (!skb_queue_empty(&priv->tx_queue)) {
                        struct ieee80211_tx_info *info = IEEE80211_SKB_CB(target_skb);
-                       struct memrecord *range = (void *)info->driver_data;
+                       struct memrecord *range = (void *)info->rate_driver_data;
                        target_addr = range->end_addr;
                }
        } else
@@ -723,7 +743,7 @@ static void p54_assign_address(struct ieee80211_hw *dev, struct sk_buff *skb,
 
        if (skb) {
                struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
-               struct memrecord *range = (void *)info->driver_data;
+               struct memrecord *range = (void *)info->rate_driver_data;
                range->start_addr = target_addr;
                range->end_addr = target_addr + len;
                __skb_queue_after(&priv->tx_queue, target_skb, skb);
@@ -802,11 +822,14 @@ static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
        struct ieee80211_tx_queue_stats *current_queue;
        struct p54_common *priv = dev->priv;
        struct p54_control_hdr *hdr;
-       struct ieee80211_hdr *ieee80211hdr = (struct ieee80211_hdr *)skb->data;
        struct p54_tx_control_allocdata *txhdr;
        size_t padding, len;
+       int i, j, ridx;
        u8 rate;
        u8 cts_rate = 0x20;
+       u8 rc_flags;
+       u8 calculated_tries[4];
+       u8 nrates = 0, nremaining = 8;
 
        current_queue = &priv->tx_stats[skb_get_queue_mapping(skb) + 4];
        if (unlikely(current_queue->len > current_queue->limit))
@@ -829,22 +852,74 @@ static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
                hdr->magic1 = cpu_to_le16(0x0010);
        hdr->len = cpu_to_le16(len);
        hdr->type = (info->flags & IEEE80211_TX_CTL_NO_ACK) ? 0 : cpu_to_le16(1);
-       hdr->retry1 = hdr->retry2 = info->control.retry_limit;
+       hdr->retry1 = info->control.rates[0].count;
 
-       /* TODO: add support for alternate retry TX rates */
-       rate = ieee80211_get_tx_rate(dev, info)->hw_value;
-       if (info->flags & IEEE80211_TX_CTL_SHORT_PREAMBLE) {
-               rate |= 0x10;
-               cts_rate |= 0x10;
+       /*
+        * we register the rates in perfect order, and
+        * RTS/CTS won't happen on 5 GHz
+        */
+       cts_rate = info->control.rts_cts_rate_idx;
+
+       memset(&txhdr->rateset, 0, sizeof(txhdr->rateset));
+
+       /* see how many rates got used */
+       for (i = 0; i < 4; i++) {
+               if (info->control.rates[i].idx < 0)
+                       break;
+               nrates++;
        }
-       if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) {
-               rate |= 0x40;
-               cts_rate |= ieee80211_get_rts_cts_rate(dev, info)->hw_value;
-       } else if (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) {
-               rate |= 0x20;
-               cts_rate |= ieee80211_get_rts_cts_rate(dev, info)->hw_value;
+
+       /* limit tries to 8/nrates per rate */
+       for (i = 0; i < nrates; i++) {
+               /*
+                * The magic expression here is equivalent to 8/nrates for
+                * all values that matter, but avoids division and jumps.
+                * Note that nrates can only take the values 1 through 4.
+                */
+               calculated_tries[i] = min_t(int, ((15 >> nrates) | 1) + 1,
+                                                info->control.rates[i].count);
+               nremaining -= calculated_tries[i];
        }
-       memset(txhdr->rateset, rate, 8);
+
+       /* if there are tries left, distribute from back to front */
+       for (i = nrates - 1; nremaining > 0 && i >= 0; i--) {
+               int tmp = info->control.rates[i].count - calculated_tries[i];
+
+               if (tmp <= 0)
+                       continue;
+               /* RC requested more tries at this rate */
+
+               tmp = min_t(int, tmp, nremaining);
+               calculated_tries[i] += tmp;
+               nremaining -= tmp;
+       }
+
+       ridx = 0;
+       for (i = 0; i < nrates && ridx < 8; i++) {
+               /* we register the rates in perfect order */
+               rate = info->control.rates[i].idx;
+               if (info->band == IEEE80211_BAND_5GHZ)
+                       rate += 4;
+
+               /* store the count we actually calculated for TX status */
+               info->control.rates[i].count = calculated_tries[i];
+
+               rc_flags = info->control.rates[i].flags;
+               if (rc_flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) {
+                       rate |= 0x10;
+                       cts_rate |= 0x10;
+               }
+               if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS)
+                       rate |= 0x40;
+               else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
+                       rate |= 0x20;
+               for (j = 0; j < calculated_tries[i] && ridx < 8; j++) {
+                       txhdr->rateset[ridx] = rate;
+                       ridx++;
+               }
+       }
+       hdr->retry2 = ridx;
+
        txhdr->key_type = 0;
        txhdr->key_len = 0;
        txhdr->hw_queue = skb_get_queue_mapping(skb) + 4;
@@ -856,19 +931,6 @@ static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
        if (padding)
                txhdr->align[0] = padding;
 
-       /* FIXME: The sequence that follows is needed for this driver to
-        * work with mac80211 since "mac80211: fix TX sequence numbers".
-        * As with the temporary code in rt2x00, changes will be needed
-        * to get proper sequence numbers on beacons. In addition, this
-        * patch places the sequence number in the hardware state, which
-        * limits us to a single virtual state.
-        */
-       if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
-               if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
-                       priv->seqno += 0x10;
-               ieee80211hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
-               ieee80211hdr->seq_ctrl |= cpu_to_le16(priv->seqno);
-       }
        /* modifies skb->cb and with it info, so must be last! */
        p54_assign_address(dev, skb, hdr, skb->len);
 
@@ -901,12 +963,10 @@ static int p54_set_filter(struct ieee80211_hw *dev, u16 filter_type,
                memset(filter->bssid, ~0, ETH_ALEN);
        else
                memcpy(filter->bssid, bssid, ETH_ALEN);
-
        filter->rx_antenna = priv->rx_antenna;
-
        if (priv->fw_var < 0x500) {
                data_len = P54_TX_CONTROL_FILTER_V1_LEN;
-               filter->v1.basic_rate_mask = cpu_to_le32(0x15F);
+               filter->v1.basic_rate_mask = cpu_to_le32(0x15f);
                filter->v1.rx_addr = cpu_to_le32(priv->rx_end);
                filter->v1.max_rx = cpu_to_le16(priv->rx_mtu);
                filter->v1.rxhw = cpu_to_le16(priv->rxhw);
@@ -918,7 +978,6 @@ static int p54_set_filter(struct ieee80211_hw *dev, u16 filter_type,
                filter->v2.rxhw = cpu_to_le16(priv->rxhw);
                filter->v2.timer = cpu_to_le16(1000);
        }
-
        hdr->len = cpu_to_le16(data_len);
        p54_assign_address(dev, NULL, hdr, sizeof(*hdr) + data_len);
        priv->tx(dev, hdr, sizeof(*hdr) + data_len, 1);
@@ -1088,7 +1147,7 @@ static void p54_set_vdcf(struct ieee80211_hw *dev)
 
        vdcf = (struct p54_tx_control_vdcf *) hdr->data;
 
-       if (dev->conf.flags & IEEE80211_CONF_SHORT_SLOT_TIME) {
+       if (priv->use_short_slot) {
                vdcf->slottime = 9;
                vdcf->magic1 = 0x10;
                vdcf->magic2 = 0x00;
@@ -1135,7 +1194,6 @@ static int p54_start(struct ieee80211_hw *dev)
                priv->mode = NL80211_IFTYPE_MONITOR;
 
        p54_init_vdcf(dev);
-
        mod_timer(&priv->stats_timer, jiffies + HZ);
        return err;
 }
@@ -1196,14 +1254,14 @@ static void p54_remove_interface(struct ieee80211_hw *dev,
        p54_set_filter(dev, 0, NULL);
 }
 
-static int p54_config(struct ieee80211_hw *dev, struct ieee80211_conf *conf)
+static int p54_config(struct ieee80211_hw *dev, u32 changed)
 {
        int ret;
        struct p54_common *priv = dev->priv;
+       struct ieee80211_conf *conf = &dev->conf;
 
        mutex_lock(&priv->conf_mutex);
-       priv->rx_antenna = (conf->antenna_sel_rx == 0) ?
-               2 : conf->antenna_sel_tx - 1;
+       priv->rx_antenna = 2; /* automatic */
        priv->output_power = conf->power_level << 2;
        ret = p54_set_freq(dev, cpu_to_le16(conf->channel->center_freq));
        p54_set_vdcf(dev);
@@ -1351,6 +1409,19 @@ static int p54_get_tx_stats(struct ieee80211_hw *dev,
        return 0;
 }
 
+static void p54_bss_info_changed(struct ieee80211_hw *dev,
+                                struct ieee80211_vif *vif,
+                                struct ieee80211_bss_conf *info,
+                                u32 changed)
+{
+       struct p54_common *priv = dev->priv;
+
+       if (changed & BSS_CHANGED_ERP_SLOT) {
+               priv->use_short_slot = info->use_short_slot;
+               p54_set_vdcf(dev);
+       }
+}
+
 static const struct ieee80211_ops p54_ops = {
        .tx                     = p54_tx,
        .start                  = p54_start,
@@ -1359,6 +1430,7 @@ static const struct ieee80211_ops p54_ops = {
        .remove_interface       = p54_remove_interface,
        .config                 = p54_config,
        .config_interface       = p54_config_interface,
+       .bss_info_changed       = p54_bss_info_changed,
        .configure_filter       = p54_configure_filter,
        .conf_tx                = p54_conf_tx,
        .get_stats              = p54_get_stats,
@@ -1382,10 +1454,14 @@ struct ieee80211_hw *p54_init_common(size_t priv_data_len)
                     IEEE80211_HW_SIGNAL_DBM |
                     IEEE80211_HW_NOISE_DBM;
 
+       /*
+        * XXX: when this driver gets support for any mode that
+        *      requires beacons (AP, MESH, IBSS) then it must
+        *      implement IEEE80211_TX_CTL_ASSIGN_SEQ.
+        */
        dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
 
        dev->channel_change_time = 1000;        /* TODO: find actual value */
-
        priv->tx_stats[0].limit = 1;
        priv->tx_stats[1].limit = 1;
        priv->tx_stats[2].limit = 1;
@@ -1393,6 +1469,16 @@ struct ieee80211_hw *p54_init_common(size_t priv_data_len)
        priv->tx_stats[4].limit = 5;
        dev->queues = 1;
        priv->noise = -94;
+       /*
+        * We support at most 8 tries no matter which rate they're at,
+        * we cannot support max_rates * max_rate_tries as we set it
+        * here, but setting it correctly to 4/2 or so would limit us
+        * artificially if the RC algorithm wants just two rates, so
+        * let's say 4/7, we'll redistribute it at TX time, see the
+        * comments there.
+        */
+       dev->max_rates = 4;
+       dev->max_rate_tries = 7;
        dev->extra_tx_headroom = sizeof(struct p54_control_hdr) + 4 +
                                 sizeof(struct p54_tx_control_allocdata);