]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/wireless/p54/p54common.c
Merge branches 'topic/fixes', 'topic/cleanups' and 'topic/documentation' into for...
[linux-2.6-omap-h63xx.git] / drivers / net / wireless / p54 / p54common.c
index ddb858608a50ebbfb26e92798d31035080e76268..82354b974a04773e752307f45f393bed8a89763c 100644 (file)
@@ -335,6 +335,36 @@ static const char *p54_rf_chips[] = { "NULL", "Duette3", "Duette2",
                               "Frisbee", "Xbow", "Longbow", "NULL", "NULL" };
 static int p54_init_xbow_synth(struct ieee80211_hw *dev);
 
+static void p54_parse_rssical(struct ieee80211_hw *dev, void *data, int len,
+                            u16 type)
+{
+       struct p54_common *priv = dev->priv;
+       int offset = (type == PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED) ? 2 : 0;
+       int entry_size = sizeof(struct pda_rssi_cal_entry) + offset;
+       int num_entries = (type == PDR_RSSI_LINEAR_APPROXIMATION) ? 1 : 2;
+       int i;
+
+       if (len != (entry_size * num_entries)) {
+               printk(KERN_ERR "%s: unknown rssi calibration data packing "
+                                " type:(%x) len:%d.\n",
+                      wiphy_name(dev->wiphy), type, len);
+
+               print_hex_dump_bytes("rssical:", DUMP_PREFIX_NONE,
+                                    data, len);
+
+               printk(KERN_ERR "%s: please report this issue.\n",
+                       wiphy_name(dev->wiphy));
+               return;
+       }
+
+       for (i = 0; i < num_entries; i++) {
+               struct pda_rssi_cal_entry *cal = data +
+                                                (offset + i * entry_size);
+               priv->rssical_db[i].mul = (s16) le16_to_cpu(cal->mul);
+               priv->rssical_db[i].add = (s16) le16_to_cpu(cal->add);
+       }
+}
+
 static int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
 {
        struct p54_common *priv = dev->priv;
@@ -434,6 +464,12 @@ static int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
                case PDR_HARDWARE_PLATFORM_COMPONENT_ID:
                        priv->version = *(u8 *)(entry->data + 1);
                        break;
+               case PDR_RSSI_LINEAR_APPROXIMATION:
+               case PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND:
+               case PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED:
+                       p54_parse_rssical(dev, entry->data, data_len,
+                                         le16_to_cpu(entry->code));
+                       break;
                case PDR_END:
                        /* make it overrun */
                        entry_len = len;
@@ -453,10 +489,7 @@ static int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
                case PDR_DEFAULT_COUNTRY:
                case PDR_ANTENNA_GAIN:
                case PDR_PRISM_INDIGO_PA_CALIBRATION_DATA:
-               case PDR_RSSI_LINEAR_APPROXIMATION:
-               case PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND:
                case PDR_REGULATORY_POWER_LIMITS:
-               case PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED:
                case PDR_RADIATED_TRANSMISSION_CORRECTION:
                case PDR_PRISM_TX_IQ_CALIBRATION:
                case PDR_BASEBAND_REGISTERS:
@@ -527,8 +560,11 @@ static int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
 
 static int p54_rssi_to_dbm(struct ieee80211_hw *dev, int rssi)
 {
-       /* TODO: get the rssi_add & rssi_mul data from the eeprom */
-       return ((rssi * 0x83) / 64 - 400) / 4;
+       struct p54_common *priv = dev->priv;
+       int band = dev->conf.channel->band;
+
+       return ((rssi * priv->rssical_db[band].mul) / 64 +
+                        priv->rssical_db[band].add) / 4;
 }
 
 static int p54_rx_data(struct ieee80211_hw *dev, struct sk_buff *skb)
@@ -647,7 +683,7 @@ void p54_free_skb(struct ieee80211_hw *dev, struct sk_buff *skb)
                freed = priv->rx_end - last_addr;
        __skb_unlink(skb, &priv->tx_queue);
        spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
-       kfree_skb(skb);
+       dev_kfree_skb_any(skb);
 
        if (freed >= priv->headroom + sizeof(struct p54_hdr) + 48 +
                     IEEE80211_MAX_RTS_THRESHOLD + priv->tailroom)
@@ -1052,7 +1088,7 @@ int p54_read_eeprom(struct ieee80211_hw *dev)
                        eeprom_hdr->v2.magic2 = 0xf;
                        memcpy(eeprom_hdr->v2.magic, (const char *)"LOCK", 4);
                }
-               priv->tx(dev, skb, 0);
+               priv->tx(dev, skb);
 
                if (!wait_for_completion_interruptible_timeout(&priv->eeprom_comp, HZ)) {
                        printk(KERN_ERR "%s: device does not respond!\n",
@@ -1093,7 +1129,7 @@ static int p54_set_tim(struct ieee80211_hw *dev, struct ieee80211_sta *sta,
        tim = (struct p54_tim *) skb_put(skb, sizeof(*tim));
        tim->count = 1;
        tim->entry[0] = cpu_to_le16(set ? (sta->aid | 0x8000) : sta->aid);
-       priv->tx(dev, skb, 1);
+       priv->tx(dev, skb);
        return 0;
 }
 
@@ -1111,7 +1147,7 @@ static int p54_sta_unlock(struct ieee80211_hw *dev, u8 *addr)
 
        sta = (struct p54_sta_unlock *)skb_put(skb, sizeof(*sta));
        memcpy(sta->addr, addr, ETH_ALEN);
-       priv->tx(dev, skb, 1);
+       priv->tx(dev, skb);
        return 0;
 }
 
@@ -1154,7 +1190,7 @@ static int p54_tx_cancel(struct ieee80211_hw *dev, struct sk_buff *entry)
        hdr = (void *)entry->data;
        cancel = (struct p54_txcancel *)skb_put(skb, sizeof(*cancel));
        cancel->req_id = hdr->req_id;
-       priv->tx(dev, skb, 1);
+       priv->tx(dev, skb);
        return 0;
 }
 
@@ -1383,7 +1419,7 @@ static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
        /* modifies skb->cb and with it info, so must be last! */
        if (unlikely(p54_assign_address(dev, skb, hdr, skb->len + tim_len)))
                goto err;
-       priv->tx(dev, skb, 0);
+       priv->tx(dev, skb);
 
        queue_delayed_work(dev->workqueue, &priv->work,
                           msecs_to_jiffies(P54_TX_FRAME_LIFETIME));
@@ -1462,19 +1498,19 @@ static int p54_setup_mac(struct ieee80211_hw *dev)
                setup->v2.lpf_bandwidth = cpu_to_le16(65535);
                setup->v2.osc_start_delay = cpu_to_le16(65535);
        }
-       priv->tx(dev, skb, 1);
+       priv->tx(dev, skb);
        return 0;
 }
 
-static int p54_scan(struct ieee80211_hw *dev, u16 mode, u16 dwell,
-                   u16 frequency)
+static int p54_scan(struct ieee80211_hw *dev, u16 mode, u16 dwell)
 {
        struct p54_common *priv = dev->priv;
        struct sk_buff *skb;
        struct p54_scan *chan;
        unsigned int i;
        void *entry;
-       __le16 freq = cpu_to_le16(frequency);
+       __le16 freq = cpu_to_le16(dev->conf.channel->center_freq);
+       int band = dev->conf.channel->band;
 
        skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*chan) +
                            sizeof(struct p54_hdr), P54_CONTROL_TYPE_SCAN,
@@ -1535,15 +1571,15 @@ static int p54_scan(struct ieee80211_hw *dev, u16 mode, u16 dwell,
        }
 
        if (priv->fw_var < 0x500) {
-               chan->v1.rssical_mul = cpu_to_le16(130);
-               chan->v1.rssical_add = cpu_to_le16(0xfe70);
+               chan->v1_rssi.mul = cpu_to_le16(priv->rssical_db[band].mul);
+               chan->v1_rssi.add = cpu_to_le16(priv->rssical_db[band].add);
        } else {
-               chan->v2.rssical_mul = cpu_to_le16(130);
-               chan->v2.rssical_add = cpu_to_le16(0xfe70);
+               chan->v2.rssi.mul = cpu_to_le16(priv->rssical_db[band].mul);
+               chan->v2.rssi.add = cpu_to_le16(priv->rssical_db[band].add);
                chan->v2.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
                memset(chan->v2.rts_rates, 0, 8);
        }
-       priv->tx(dev, skb, 1);
+       priv->tx(dev, skb);
        return 0;
 
  err:
@@ -1569,7 +1605,7 @@ static int p54_set_leds(struct ieee80211_hw *dev, int mode, int link, int act)
        led->led_permanent = cpu_to_le16(link);
        led->led_temporary = cpu_to_le16(act);
        led->duration = cpu_to_le16(1000);
-       priv->tx(dev, skb, 1);
+       priv->tx(dev, skb);
        return 0;
 }
 
@@ -1609,7 +1645,7 @@ static int p54_set_edcf(struct ieee80211_hw *dev)
        edcf->flags = 0;
        memset(edcf->mapping, 0, sizeof(edcf->mapping));
        memcpy(edcf->queue, priv->qos_params, sizeof(edcf->queue));
-       priv->tx(dev, skb, 1);
+       priv->tx(dev, skb);
        return 0;
 }
 
@@ -1801,8 +1837,7 @@ static int p54_config(struct ieee80211_hw *dev, u32 changed)
                        goto out;
        }
        if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
-               ret = p54_scan(dev, P54_SCAN_EXIT, 0,
-                              conf->channel->center_freq);
+               ret = p54_scan(dev, P54_SCAN_EXIT, 0);
                if (ret)
                        goto out;
        }
@@ -1828,8 +1863,7 @@ static int p54_config_interface(struct ieee80211_hw *dev,
        }
 
        if (conf->changed & IEEE80211_IFCC_BEACON) {
-               ret = p54_scan(dev, P54_SCAN_EXIT, 0,
-                              dev->conf.channel->center_freq);
+               ret = p54_scan(dev, P54_SCAN_EXIT, 0);
                if (ret)
                        goto out;
                ret = p54_setup_mac(dev);
@@ -1902,7 +1936,7 @@ static int p54_init_xbow_synth(struct ieee80211_hw *dev)
        xbow->magic2 = cpu_to_le16(0x2);
        xbow->freq = cpu_to_le16(5390);
        memset(xbow->padding, 0, sizeof(xbow->padding));
-       priv->tx(dev, skb, 1);
+       priv->tx(dev, skb);
        return 0;
 }
 
@@ -1928,7 +1962,7 @@ static void p54_work(struct work_struct *work)
        if (!skb)
                return ;
 
-       priv->tx(dev, skb, 0);
+       priv->tx(dev, skb);
 }
 
 static int p54_get_stats(struct ieee80211_hw *dev,
@@ -1968,8 +2002,7 @@ static void p54_bss_info_changed(struct ieee80211_hw *dev,
                        priv->basic_rate_mask = info->basic_rates;
                p54_setup_mac(dev);
                if (priv->fw_var >= 0x500)
-                       p54_scan(dev, P54_SCAN_EXIT, 0,
-                                dev->conf.channel->center_freq);
+                       p54_scan(dev, P54_SCAN_EXIT, 0);
        }
        if (changed & BSS_CHANGED_ASSOC) {
                if (info->assoc) {
@@ -2061,7 +2094,7 @@ static int p54_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd,
                        [NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY]), 8);
        }
 
-       priv->tx(dev, skb, 1);
+       priv->tx(dev, skb);
        mutex_unlock(&priv->conf_mutex);
        return 0;
 }