Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 1 | /* |
| 2 | * EEPROM parser code for mac80211 Prism54 drivers |
| 3 | * |
| 4 | * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net> |
| 5 | * Copyright (c) 2007-2009, Christian Lamparter <chunkeey@web.de> |
| 6 | * Copyright 2008, Johannes Berg <johannes@sipsolutions.net> |
| 7 | * |
| 8 | * Based on: |
| 9 | * - the islsm (softmac prism54) driver, which is: |
| 10 | * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al. |
| 11 | * - stlc45xx driver |
| 12 | * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License version 2 as |
| 16 | * published by the Free Software Foundation. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/firmware.h> |
| 21 | #include <linux/etherdevice.h> |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 22 | #include <linux/sort.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 24 | |
| 25 | #include <net/mac80211.h> |
Christian Lamparter | d7eb50c | 2010-08-17 01:16:58 +0200 | [diff] [blame] | 26 | #include <linux/crc-ccitt.h> |
Paul Gortmaker | ee40fa0 | 2011-05-27 16:14:23 -0400 | [diff] [blame] | 27 | #include <linux/export.h> |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 28 | |
| 29 | #include "p54.h" |
| 30 | #include "eeprom.h" |
| 31 | #include "lmac.h" |
| 32 | |
| 33 | static struct ieee80211_rate p54_bgrates[] = { |
| 34 | { .bitrate = 10, .hw_value = 0, }, |
| 35 | { .bitrate = 20, .hw_value = 1, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 36 | { .bitrate = 55, .hw_value = 2, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 37 | { .bitrate = 110, .hw_value = 3, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 38 | { .bitrate = 60, .hw_value = 4, }, |
| 39 | { .bitrate = 90, .hw_value = 5, }, |
| 40 | { .bitrate = 120, .hw_value = 6, }, |
| 41 | { .bitrate = 180, .hw_value = 7, }, |
| 42 | { .bitrate = 240, .hw_value = 8, }, |
| 43 | { .bitrate = 360, .hw_value = 9, }, |
| 44 | { .bitrate = 480, .hw_value = 10, }, |
| 45 | { .bitrate = 540, .hw_value = 11, }, |
| 46 | }; |
| 47 | |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 48 | static struct ieee80211_rate p54_arates[] = { |
| 49 | { .bitrate = 60, .hw_value = 4, }, |
| 50 | { .bitrate = 90, .hw_value = 5, }, |
| 51 | { .bitrate = 120, .hw_value = 6, }, |
| 52 | { .bitrate = 180, .hw_value = 7, }, |
| 53 | { .bitrate = 240, .hw_value = 8, }, |
| 54 | { .bitrate = 360, .hw_value = 9, }, |
| 55 | { .bitrate = 480, .hw_value = 10, }, |
| 56 | { .bitrate = 540, .hw_value = 11, }, |
| 57 | }; |
| 58 | |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 59 | static struct p54_rssi_db_entry p54_rssi_default = { |
| 60 | /* |
| 61 | * The defaults are taken from usb-logs of the |
| 62 | * vendor driver. So, they should be safe to |
| 63 | * use in case we can't get a match from the |
| 64 | * rssi <-> dBm conversion database. |
| 65 | */ |
| 66 | .mul = 130, |
| 67 | .add = -398, |
| 68 | }; |
| 69 | |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 70 | #define CHAN_HAS_CAL BIT(0) |
| 71 | #define CHAN_HAS_LIMIT BIT(1) |
| 72 | #define CHAN_HAS_CURVE BIT(2) |
| 73 | #define CHAN_HAS_ALL (CHAN_HAS_CAL | CHAN_HAS_LIMIT | CHAN_HAS_CURVE) |
| 74 | |
| 75 | struct p54_channel_entry { |
| 76 | u16 freq; |
| 77 | u16 data; |
| 78 | int index; |
Christian Lamparter | 9bc6381 | 2012-07-28 02:57:51 +0200 | [diff] [blame^] | 79 | int max_power; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 80 | enum ieee80211_band band; |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 81 | }; |
| 82 | |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 83 | struct p54_channel_list { |
| 84 | struct p54_channel_entry *channels; |
| 85 | size_t entries; |
| 86 | size_t max_entries; |
| 87 | size_t band_channel_num[IEEE80211_NUM_BANDS]; |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 88 | }; |
| 89 | |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 90 | static int p54_get_band_from_freq(u16 freq) |
| 91 | { |
| 92 | /* FIXME: sync these values with the 802.11 spec */ |
| 93 | |
| 94 | if ((freq >= 2412) && (freq <= 2484)) |
| 95 | return IEEE80211_BAND_2GHZ; |
| 96 | |
| 97 | if ((freq >= 4920) && (freq <= 5825)) |
| 98 | return IEEE80211_BAND_5GHZ; |
| 99 | |
| 100 | return -1; |
| 101 | } |
| 102 | |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 103 | static int same_band(u16 freq, u16 freq2) |
| 104 | { |
| 105 | return p54_get_band_from_freq(freq) == p54_get_band_from_freq(freq2); |
| 106 | } |
| 107 | |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 108 | static int p54_compare_channels(const void *_a, |
| 109 | const void *_b) |
| 110 | { |
| 111 | const struct p54_channel_entry *a = _a; |
| 112 | const struct p54_channel_entry *b = _b; |
| 113 | |
Christian Lamparter | 192abec | 2011-02-12 21:49:38 +0100 | [diff] [blame] | 114 | return a->freq - b->freq; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 115 | } |
| 116 | |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 117 | static int p54_compare_rssichan(const void *_a, |
| 118 | const void *_b) |
| 119 | { |
| 120 | const struct p54_rssi_db_entry *a = _a; |
| 121 | const struct p54_rssi_db_entry *b = _b; |
| 122 | |
| 123 | return a->freq - b->freq; |
| 124 | } |
| 125 | |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 126 | static int p54_fill_band_bitrates(struct ieee80211_hw *dev, |
| 127 | struct ieee80211_supported_band *band_entry, |
| 128 | enum ieee80211_band band) |
| 129 | { |
| 130 | /* TODO: generate rate array dynamically */ |
| 131 | |
| 132 | switch (band) { |
| 133 | case IEEE80211_BAND_2GHZ: |
| 134 | band_entry->bitrates = p54_bgrates; |
| 135 | band_entry->n_bitrates = ARRAY_SIZE(p54_bgrates); |
| 136 | break; |
| 137 | case IEEE80211_BAND_5GHZ: |
| 138 | band_entry->bitrates = p54_arates; |
| 139 | band_entry->n_bitrates = ARRAY_SIZE(p54_arates); |
| 140 | break; |
| 141 | default: |
| 142 | return -EINVAL; |
| 143 | } |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | static int p54_generate_band(struct ieee80211_hw *dev, |
| 149 | struct p54_channel_list *list, |
Christian Lamparter | 0d78156 | 2011-08-20 01:53:59 +0200 | [diff] [blame] | 150 | unsigned int *chan_num, |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 151 | enum ieee80211_band band) |
| 152 | { |
| 153 | struct p54_common *priv = dev->priv; |
| 154 | struct ieee80211_supported_band *tmp, *old; |
| 155 | unsigned int i, j; |
| 156 | int ret = -ENOMEM; |
| 157 | |
| 158 | if ((!list->entries) || (!list->band_channel_num[band])) |
Christian Lamparter | 93a59d7 | 2009-10-31 22:59:27 +0100 | [diff] [blame] | 159 | return -EINVAL; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 160 | |
| 161 | tmp = kzalloc(sizeof(*tmp), GFP_KERNEL); |
| 162 | if (!tmp) |
| 163 | goto err_out; |
| 164 | |
| 165 | tmp->channels = kzalloc(sizeof(struct ieee80211_channel) * |
| 166 | list->band_channel_num[band], GFP_KERNEL); |
| 167 | if (!tmp->channels) |
| 168 | goto err_out; |
| 169 | |
| 170 | ret = p54_fill_band_bitrates(dev, tmp, band); |
| 171 | if (ret) |
| 172 | goto err_out; |
| 173 | |
| 174 | for (i = 0, j = 0; (j < list->band_channel_num[band]) && |
| 175 | (i < list->entries); i++) { |
Christian Lamparter | a3162ee | 2011-02-12 22:14:38 +0100 | [diff] [blame] | 176 | struct p54_channel_entry *chan = &list->channels[i]; |
Christian Lamparter | 9bc6381 | 2012-07-28 02:57:51 +0200 | [diff] [blame^] | 177 | struct ieee80211_channel *dest = &tmp->channels[j]; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 178 | |
Christian Lamparter | a3162ee | 2011-02-12 22:14:38 +0100 | [diff] [blame] | 179 | if (chan->band != band) |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 180 | continue; |
| 181 | |
Christian Lamparter | a3162ee | 2011-02-12 22:14:38 +0100 | [diff] [blame] | 182 | if (chan->data != CHAN_HAS_ALL) { |
| 183 | wiphy_err(dev->wiphy, "%s%s%s is/are missing for " |
| 184 | "channel:%d [%d MHz].\n", |
| 185 | (chan->data & CHAN_HAS_CAL ? "" : |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 186 | " [iqauto calibration data]"), |
Christian Lamparter | a3162ee | 2011-02-12 22:14:38 +0100 | [diff] [blame] | 187 | (chan->data & CHAN_HAS_LIMIT ? "" : |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 188 | " [output power limits]"), |
Christian Lamparter | a3162ee | 2011-02-12 22:14:38 +0100 | [diff] [blame] | 189 | (chan->data & CHAN_HAS_CURVE ? "" : |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 190 | " [curve data]"), |
Christian Lamparter | a3162ee | 2011-02-12 22:14:38 +0100 | [diff] [blame] | 191 | chan->index, chan->freq); |
Christian Lamparter | 93a59d7 | 2009-10-31 22:59:27 +0100 | [diff] [blame] | 192 | continue; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 193 | } |
| 194 | |
Christian Lamparter | 9bc6381 | 2012-07-28 02:57:51 +0200 | [diff] [blame^] | 195 | dest->band = chan->band; |
| 196 | dest->center_freq = chan->freq; |
| 197 | dest->max_power = chan->max_power; |
Christian Lamparter | 0d78156 | 2011-08-20 01:53:59 +0200 | [diff] [blame] | 198 | priv->survey[*chan_num].channel = &tmp->channels[j]; |
| 199 | priv->survey[*chan_num].filled = SURVEY_INFO_NOISE_DBM | |
| 200 | SURVEY_INFO_CHANNEL_TIME | |
| 201 | SURVEY_INFO_CHANNEL_TIME_BUSY | |
| 202 | SURVEY_INFO_CHANNEL_TIME_TX; |
Christian Lamparter | 9bc6381 | 2012-07-28 02:57:51 +0200 | [diff] [blame^] | 203 | dest->hw_value = (*chan_num); |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 204 | j++; |
Christian Lamparter | 0d78156 | 2011-08-20 01:53:59 +0200 | [diff] [blame] | 205 | (*chan_num)++; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 206 | } |
| 207 | |
Christian Lamparter | 93a59d7 | 2009-10-31 22:59:27 +0100 | [diff] [blame] | 208 | if (j == 0) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 209 | wiphy_err(dev->wiphy, "Disabling totally damaged %d GHz band\n", |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 210 | (band == IEEE80211_BAND_2GHZ) ? 2 : 5); |
Christian Lamparter | 93a59d7 | 2009-10-31 22:59:27 +0100 | [diff] [blame] | 211 | |
| 212 | ret = -ENODATA; |
| 213 | goto err_out; |
| 214 | } |
| 215 | |
| 216 | tmp->n_channels = j; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 217 | old = priv->band_table[band]; |
| 218 | priv->band_table[band] = tmp; |
| 219 | if (old) { |
| 220 | kfree(old->channels); |
| 221 | kfree(old); |
| 222 | } |
| 223 | |
| 224 | return 0; |
| 225 | |
| 226 | err_out: |
| 227 | if (tmp) { |
| 228 | kfree(tmp->channels); |
| 229 | kfree(tmp); |
| 230 | } |
| 231 | |
| 232 | return ret; |
| 233 | } |
| 234 | |
Christian Lamparter | 9bc6381 | 2012-07-28 02:57:51 +0200 | [diff] [blame^] | 235 | static struct p54_channel_entry *p54_update_channel_param(struct p54_channel_list *list, |
| 236 | u16 freq, u16 data) |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 237 | { |
Christian Lamparter | 9bc6381 | 2012-07-28 02:57:51 +0200 | [diff] [blame^] | 238 | int i; |
| 239 | struct p54_channel_entry *entry = NULL; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 240 | |
| 241 | /* |
| 242 | * usually all lists in the eeprom are mostly sorted. |
| 243 | * so it's very likely that the entry we are looking for |
| 244 | * is right at the end of the list |
| 245 | */ |
| 246 | for (i = list->entries; i >= 0; i--) { |
| 247 | if (freq == list->channels[i].freq) { |
Christian Lamparter | 9bc6381 | 2012-07-28 02:57:51 +0200 | [diff] [blame^] | 248 | entry = &list->channels[i]; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 249 | break; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | if ((i < 0) && (list->entries < list->max_entries)) { |
| 254 | /* entry does not exist yet. Initialize a new one. */ |
Christian Lamparter | 9bc6381 | 2012-07-28 02:57:51 +0200 | [diff] [blame^] | 255 | int band = p54_get_band_from_freq(freq); |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 256 | |
| 257 | /* |
| 258 | * filter out frequencies which don't belong into |
| 259 | * any supported band. |
| 260 | */ |
Christian Lamparter | 9bc6381 | 2012-07-28 02:57:51 +0200 | [diff] [blame^] | 261 | if (band >= 0) { |
| 262 | i = list->entries++; |
| 263 | list->band_channel_num[band]++; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 264 | |
Christian Lamparter | 9bc6381 | 2012-07-28 02:57:51 +0200 | [diff] [blame^] | 265 | entry = &list->channels[i]; |
| 266 | entry->freq = freq; |
| 267 | entry->band = band; |
| 268 | entry->index = ieee80211_frequency_to_channel(freq); |
| 269 | entry->max_power = 0; |
| 270 | entry->data = 0; |
| 271 | } |
| 272 | } |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 273 | |
Christian Lamparter | 9bc6381 | 2012-07-28 02:57:51 +0200 | [diff] [blame^] | 274 | if (entry) |
| 275 | entry->data |= data; |
| 276 | |
| 277 | return entry; |
| 278 | } |
| 279 | |
| 280 | static int p54_get_maxpower(struct p54_common *priv, void *data) |
| 281 | { |
| 282 | switch (priv->rxhw & PDR_SYNTH_FRONTEND_MASK) { |
| 283 | case PDR_SYNTH_FRONTEND_LONGBOW: { |
| 284 | struct pda_channel_output_limit_longbow *pda = data; |
| 285 | int j; |
| 286 | u16 rawpower = 0; |
| 287 | pda = data; |
| 288 | for (j = 0; j < ARRAY_SIZE(pda->point); j++) { |
| 289 | struct pda_channel_output_limit_point_longbow *point = |
| 290 | &pda->point[j]; |
| 291 | rawpower = max(rawpower, le16_to_cpu(point->val_qpsk)); |
| 292 | rawpower = max(rawpower, le16_to_cpu(point->val_bpsk)); |
| 293 | rawpower = max(rawpower, le16_to_cpu(point->val_16qam)); |
| 294 | rawpower = max(rawpower, le16_to_cpu(point->val_64qam)); |
| 295 | } |
| 296 | /* longbow seems to use 1/16 dBm units */ |
| 297 | return rawpower / 16; |
| 298 | } |
| 299 | |
| 300 | case PDR_SYNTH_FRONTEND_DUETTE3: |
| 301 | case PDR_SYNTH_FRONTEND_DUETTE2: |
| 302 | case PDR_SYNTH_FRONTEND_FRISBEE: |
| 303 | case PDR_SYNTH_FRONTEND_XBOW: { |
| 304 | struct pda_channel_output_limit *pda = data; |
| 305 | u8 rawpower = 0; |
| 306 | rawpower = max(rawpower, pda->val_qpsk); |
| 307 | rawpower = max(rawpower, pda->val_bpsk); |
| 308 | rawpower = max(rawpower, pda->val_16qam); |
| 309 | rawpower = max(rawpower, pda->val_64qam); |
| 310 | /* raw values are in 1/4 dBm units */ |
| 311 | return rawpower / 4; |
| 312 | } |
| 313 | |
| 314 | default: |
| 315 | return 20; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | |
| 319 | static int p54_generate_channel_lists(struct ieee80211_hw *dev) |
| 320 | { |
| 321 | struct p54_common *priv = dev->priv; |
| 322 | struct p54_channel_list *list; |
Christian Lamparter | 0d78156 | 2011-08-20 01:53:59 +0200 | [diff] [blame] | 323 | unsigned int i, j, k, max_channel_num; |
Christian Lamparter | 93a59d7 | 2009-10-31 22:59:27 +0100 | [diff] [blame] | 324 | int ret = 0; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 325 | u16 freq; |
| 326 | |
| 327 | if ((priv->iq_autocal_len != priv->curve_data->entries) || |
| 328 | (priv->iq_autocal_len != priv->output_limit->entries)) |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 329 | wiphy_err(dev->wiphy, |
| 330 | "Unsupported or damaged EEPROM detected. " |
| 331 | "You may not be able to use all channels.\n"); |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 332 | |
| 333 | max_channel_num = max_t(unsigned int, priv->output_limit->entries, |
| 334 | priv->iq_autocal_len); |
| 335 | max_channel_num = max_t(unsigned int, max_channel_num, |
| 336 | priv->curve_data->entries); |
| 337 | |
| 338 | list = kzalloc(sizeof(*list), GFP_KERNEL); |
Christian Lamparter | 93a59d7 | 2009-10-31 22:59:27 +0100 | [diff] [blame] | 339 | if (!list) { |
| 340 | ret = -ENOMEM; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 341 | goto free; |
Christian Lamparter | 93a59d7 | 2009-10-31 22:59:27 +0100 | [diff] [blame] | 342 | } |
Christian Lamparter | 0d78156 | 2011-08-20 01:53:59 +0200 | [diff] [blame] | 343 | priv->chan_num = max_channel_num; |
| 344 | priv->survey = kzalloc(sizeof(struct survey_info) * max_channel_num, |
| 345 | GFP_KERNEL); |
| 346 | if (!priv->survey) { |
| 347 | ret = -ENOMEM; |
| 348 | goto free; |
| 349 | } |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 350 | |
| 351 | list->max_entries = max_channel_num; |
| 352 | list->channels = kzalloc(sizeof(struct p54_channel_entry) * |
| 353 | max_channel_num, GFP_KERNEL); |
Julia Lawall | 0d91f22 | 2010-10-15 15:00:06 +0200 | [diff] [blame] | 354 | if (!list->channels) { |
| 355 | ret = -ENOMEM; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 356 | goto free; |
Julia Lawall | 0d91f22 | 2010-10-15 15:00:06 +0200 | [diff] [blame] | 357 | } |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 358 | |
| 359 | for (i = 0; i < max_channel_num; i++) { |
| 360 | if (i < priv->iq_autocal_len) { |
| 361 | freq = le16_to_cpu(priv->iq_autocal[i].freq); |
| 362 | p54_update_channel_param(list, freq, CHAN_HAS_CAL); |
| 363 | } |
| 364 | |
| 365 | if (i < priv->output_limit->entries) { |
Christian Lamparter | 9bc6381 | 2012-07-28 02:57:51 +0200 | [diff] [blame^] | 366 | struct p54_channel_entry *tmp; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 367 | |
Christian Lamparter | 9bc6381 | 2012-07-28 02:57:51 +0200 | [diff] [blame^] | 368 | void *data = (void *) ((unsigned long) i * |
| 369 | priv->output_limit->entry_size + |
| 370 | priv->output_limit->offset + |
| 371 | priv->output_limit->data); |
| 372 | |
| 373 | freq = le16_to_cpup((__le16 *) data); |
| 374 | tmp = p54_update_channel_param(list, freq, |
| 375 | CHAN_HAS_LIMIT); |
| 376 | if (tmp) { |
| 377 | tmp->max_power = p54_get_maxpower(priv, data); |
| 378 | } |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | if (i < priv->curve_data->entries) { |
| 382 | freq = le16_to_cpup((__le16 *) (i * |
| 383 | priv->curve_data->entry_size + |
| 384 | priv->curve_data->offset + |
| 385 | priv->curve_data->data)); |
| 386 | |
| 387 | p54_update_channel_param(list, freq, CHAN_HAS_CURVE); |
| 388 | } |
| 389 | } |
| 390 | |
Christian Lamparter | 192abec | 2011-02-12 21:49:38 +0100 | [diff] [blame] | 391 | /* sort the channel list by frequency */ |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 392 | sort(list->channels, list->entries, sizeof(struct p54_channel_entry), |
| 393 | p54_compare_channels, NULL); |
| 394 | |
Christian Lamparter | 0d78156 | 2011-08-20 01:53:59 +0200 | [diff] [blame] | 395 | k = 0; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 396 | for (i = 0, j = 0; i < IEEE80211_NUM_BANDS; i++) { |
Christian Lamparter | 0d78156 | 2011-08-20 01:53:59 +0200 | [diff] [blame] | 397 | if (p54_generate_band(dev, list, &k, i) == 0) |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 398 | j++; |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 399 | } |
| 400 | if (j == 0) { |
| 401 | /* no useable band available. */ |
| 402 | ret = -EINVAL; |
| 403 | } |
| 404 | |
| 405 | free: |
| 406 | if (list) { |
| 407 | kfree(list->channels); |
| 408 | kfree(list); |
| 409 | } |
Christian Lamparter | 0d78156 | 2011-08-20 01:53:59 +0200 | [diff] [blame] | 410 | if (ret) { |
| 411 | kfree(priv->survey); |
| 412 | priv->survey = NULL; |
| 413 | } |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 414 | |
| 415 | return ret; |
| 416 | } |
| 417 | |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 418 | static int p54_convert_rev0(struct ieee80211_hw *dev, |
| 419 | struct pda_pa_curve_data *curve_data) |
| 420 | { |
| 421 | struct p54_common *priv = dev->priv; |
| 422 | struct p54_pa_curve_data_sample *dst; |
| 423 | struct pda_pa_curve_data_sample_rev0 *src; |
| 424 | size_t cd_len = sizeof(*curve_data) + |
| 425 | (curve_data->points_per_channel*sizeof(*dst) + 2) * |
| 426 | curve_data->channels; |
| 427 | unsigned int i, j; |
| 428 | void *source, *target; |
| 429 | |
| 430 | priv->curve_data = kmalloc(sizeof(*priv->curve_data) + cd_len, |
| 431 | GFP_KERNEL); |
| 432 | if (!priv->curve_data) |
| 433 | return -ENOMEM; |
| 434 | |
| 435 | priv->curve_data->entries = curve_data->channels; |
| 436 | priv->curve_data->entry_size = sizeof(__le16) + |
| 437 | sizeof(*dst) * curve_data->points_per_channel; |
| 438 | priv->curve_data->offset = offsetof(struct pda_pa_curve_data, data); |
| 439 | priv->curve_data->len = cd_len; |
| 440 | memcpy(priv->curve_data->data, curve_data, sizeof(*curve_data)); |
| 441 | source = curve_data->data; |
| 442 | target = ((struct pda_pa_curve_data *) priv->curve_data->data)->data; |
| 443 | for (i = 0; i < curve_data->channels; i++) { |
| 444 | __le16 *freq = source; |
| 445 | source += sizeof(__le16); |
| 446 | *((__le16 *)target) = *freq; |
| 447 | target += sizeof(__le16); |
| 448 | for (j = 0; j < curve_data->points_per_channel; j++) { |
| 449 | dst = target; |
| 450 | src = source; |
| 451 | |
| 452 | dst->rf_power = src->rf_power; |
| 453 | dst->pa_detector = src->pa_detector; |
| 454 | dst->data_64qam = src->pcv; |
| 455 | /* "invent" the points for the other modulations */ |
| 456 | #define SUB(x, y) (u8)(((x) - (y)) > (x) ? 0 : (x) - (y)) |
| 457 | dst->data_16qam = SUB(src->pcv, 12); |
| 458 | dst->data_qpsk = SUB(dst->data_16qam, 12); |
| 459 | dst->data_bpsk = SUB(dst->data_qpsk, 12); |
| 460 | dst->data_barker = SUB(dst->data_bpsk, 14); |
| 461 | #undef SUB |
| 462 | target += sizeof(*dst); |
| 463 | source += sizeof(*src); |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | static int p54_convert_rev1(struct ieee80211_hw *dev, |
| 471 | struct pda_pa_curve_data *curve_data) |
| 472 | { |
| 473 | struct p54_common *priv = dev->priv; |
| 474 | struct p54_pa_curve_data_sample *dst; |
| 475 | struct pda_pa_curve_data_sample_rev1 *src; |
| 476 | size_t cd_len = sizeof(*curve_data) + |
| 477 | (curve_data->points_per_channel*sizeof(*dst) + 2) * |
| 478 | curve_data->channels; |
| 479 | unsigned int i, j; |
| 480 | void *source, *target; |
| 481 | |
| 482 | priv->curve_data = kzalloc(cd_len + sizeof(*priv->curve_data), |
| 483 | GFP_KERNEL); |
| 484 | if (!priv->curve_data) |
| 485 | return -ENOMEM; |
| 486 | |
| 487 | priv->curve_data->entries = curve_data->channels; |
| 488 | priv->curve_data->entry_size = sizeof(__le16) + |
| 489 | sizeof(*dst) * curve_data->points_per_channel; |
| 490 | priv->curve_data->offset = offsetof(struct pda_pa_curve_data, data); |
| 491 | priv->curve_data->len = cd_len; |
| 492 | memcpy(priv->curve_data->data, curve_data, sizeof(*curve_data)); |
| 493 | source = curve_data->data; |
| 494 | target = ((struct pda_pa_curve_data *) priv->curve_data->data)->data; |
| 495 | for (i = 0; i < curve_data->channels; i++) { |
| 496 | __le16 *freq = source; |
| 497 | source += sizeof(__le16); |
| 498 | *((__le16 *)target) = *freq; |
| 499 | target += sizeof(__le16); |
| 500 | for (j = 0; j < curve_data->points_per_channel; j++) { |
| 501 | memcpy(target, source, sizeof(*src)); |
| 502 | |
| 503 | target += sizeof(*dst); |
| 504 | source += sizeof(*src); |
| 505 | } |
| 506 | source++; |
| 507 | } |
| 508 | |
| 509 | return 0; |
| 510 | } |
| 511 | |
| 512 | static const char *p54_rf_chips[] = { "INVALID-0", "Duette3", "Duette2", |
| 513 | "Frisbee", "Xbow", "Longbow", "INVALID-6", "INVALID-7" }; |
| 514 | |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 515 | static int p54_parse_rssical(struct ieee80211_hw *dev, |
| 516 | u8 *data, int len, u16 type) |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 517 | { |
| 518 | struct p54_common *priv = dev->priv; |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 519 | struct p54_rssi_db_entry *entry; |
| 520 | size_t db_len, entries; |
| 521 | int offset = 0, i; |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 522 | |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 523 | if (type != PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED) { |
| 524 | entries = (type == PDR_RSSI_LINEAR_APPROXIMATION) ? 1 : 2; |
| 525 | if (len != sizeof(struct pda_rssi_cal_entry) * entries) { |
| 526 | wiphy_err(dev->wiphy, "rssical size mismatch.\n"); |
| 527 | goto err_data; |
| 528 | } |
| 529 | } else { |
| 530 | /* |
| 531 | * Some devices (Dell 1450 USB, Xbow 5GHz card, etc...) |
| 532 | * have an empty two byte header. |
| 533 | */ |
| 534 | if (*((__le16 *)&data[offset]) == cpu_to_le16(0)) |
| 535 | offset += 2; |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 536 | |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 537 | entries = (len - offset) / |
| 538 | sizeof(struct pda_rssi_cal_ext_entry); |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 539 | |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 540 | if ((len - offset) % sizeof(struct pda_rssi_cal_ext_entry) || |
| 541 | entries <= 0) { |
| 542 | wiphy_err(dev->wiphy, "invalid rssi database.\n"); |
| 543 | goto err_data; |
| 544 | } |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 545 | } |
| 546 | |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 547 | db_len = sizeof(*entry) * entries; |
| 548 | priv->rssi_db = kzalloc(db_len + sizeof(*priv->rssi_db), GFP_KERNEL); |
| 549 | if (!priv->rssi_db) |
| 550 | return -ENOMEM; |
| 551 | |
| 552 | priv->rssi_db->offset = 0; |
| 553 | priv->rssi_db->entries = entries; |
| 554 | priv->rssi_db->entry_size = sizeof(*entry); |
| 555 | priv->rssi_db->len = db_len; |
| 556 | |
| 557 | entry = (void *)((unsigned long)priv->rssi_db->data + priv->rssi_db->offset); |
| 558 | if (type == PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED) { |
| 559 | struct pda_rssi_cal_ext_entry *cal = (void *) &data[offset]; |
| 560 | |
| 561 | for (i = 0; i < entries; i++) { |
| 562 | entry[i].freq = le16_to_cpu(cal[i].freq); |
| 563 | entry[i].mul = (s16) le16_to_cpu(cal[i].mul); |
| 564 | entry[i].add = (s16) le16_to_cpu(cal[i].add); |
| 565 | } |
| 566 | } else { |
| 567 | struct pda_rssi_cal_entry *cal = (void *) &data[offset]; |
| 568 | |
| 569 | for (i = 0; i < entries; i++) { |
John W. Linville | ce6cac8 | 2011-04-29 15:09:39 -0400 | [diff] [blame] | 570 | u16 freq = 0; |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 571 | switch (i) { |
| 572 | case IEEE80211_BAND_2GHZ: |
| 573 | freq = 2437; |
| 574 | break; |
| 575 | case IEEE80211_BAND_5GHZ: |
| 576 | freq = 5240; |
| 577 | break; |
| 578 | } |
| 579 | |
| 580 | entry[i].freq = freq; |
| 581 | entry[i].mul = (s16) le16_to_cpu(cal[i].mul); |
| 582 | entry[i].add = (s16) le16_to_cpu(cal[i].add); |
| 583 | } |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 584 | } |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 585 | |
| 586 | /* sort the list by channel frequency */ |
| 587 | sort(entry, entries, sizeof(*entry), p54_compare_rssichan, NULL); |
| 588 | return 0; |
| 589 | |
| 590 | err_data: |
| 591 | wiphy_err(dev->wiphy, |
| 592 | "rssi calibration data packing type:(%x) len:%d.\n", |
| 593 | type, len); |
| 594 | |
| 595 | print_hex_dump_bytes("rssical:", DUMP_PREFIX_NONE, data, len); |
| 596 | |
| 597 | wiphy_err(dev->wiphy, "please report this issue.\n"); |
| 598 | return -EINVAL; |
| 599 | } |
| 600 | |
| 601 | struct p54_rssi_db_entry *p54_rssi_find(struct p54_common *priv, const u16 freq) |
| 602 | { |
Felix Fietkau | a5a7103 | 2011-02-27 22:19:22 +0100 | [diff] [blame] | 603 | struct p54_rssi_db_entry *entry; |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 604 | int i, found = -1; |
| 605 | |
Felix Fietkau | a5a7103 | 2011-02-27 22:19:22 +0100 | [diff] [blame] | 606 | if (!priv->rssi_db) |
| 607 | return &p54_rssi_default; |
| 608 | |
| 609 | entry = (void *)(priv->rssi_db->data + priv->rssi_db->offset); |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 610 | for (i = 0; i < priv->rssi_db->entries; i++) { |
| 611 | if (!same_band(freq, entry[i].freq)) |
| 612 | continue; |
| 613 | |
| 614 | if (found == -1) { |
| 615 | found = i; |
| 616 | continue; |
| 617 | } |
| 618 | |
| 619 | /* nearest match */ |
| 620 | if (abs(freq - entry[i].freq) < |
| 621 | abs(freq - entry[found].freq)) { |
| 622 | found = i; |
| 623 | continue; |
| 624 | } else { |
| 625 | break; |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | return found < 0 ? &p54_rssi_default : &entry[found]; |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | static void p54_parse_default_country(struct ieee80211_hw *dev, |
| 633 | void *data, int len) |
| 634 | { |
| 635 | struct pda_country *country; |
| 636 | |
| 637 | if (len != sizeof(*country)) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 638 | wiphy_err(dev->wiphy, |
| 639 | "found possible invalid default country eeprom entry. (entry size: %d)\n", |
| 640 | len); |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 641 | |
| 642 | print_hex_dump_bytes("country:", DUMP_PREFIX_NONE, |
| 643 | data, len); |
| 644 | |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 645 | wiphy_err(dev->wiphy, "please report this issue.\n"); |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 646 | return; |
| 647 | } |
| 648 | |
| 649 | country = (struct pda_country *) data; |
| 650 | if (country->flags == PDR_COUNTRY_CERT_CODE_PSEUDO) |
| 651 | regulatory_hint(dev->wiphy, country->alpha2); |
| 652 | else { |
| 653 | /* TODO: |
| 654 | * write a shared/common function that converts |
| 655 | * "Regulatory domain codes" (802.11-2007 14.8.2.2) |
| 656 | * into ISO/IEC 3166-1 alpha2 for regulatory_hint. |
| 657 | */ |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | static int p54_convert_output_limits(struct ieee80211_hw *dev, |
| 662 | u8 *data, size_t len) |
| 663 | { |
| 664 | struct p54_common *priv = dev->priv; |
| 665 | |
| 666 | if (len < 2) |
| 667 | return -EINVAL; |
| 668 | |
| 669 | if (data[0] != 0) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 670 | wiphy_err(dev->wiphy, "unknown output power db revision:%x\n", |
| 671 | data[0]); |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 672 | return -EINVAL; |
| 673 | } |
| 674 | |
| 675 | if (2 + data[1] * sizeof(struct pda_channel_output_limit) > len) |
| 676 | return -EINVAL; |
| 677 | |
| 678 | priv->output_limit = kmalloc(data[1] * |
| 679 | sizeof(struct pda_channel_output_limit) + |
| 680 | sizeof(*priv->output_limit), GFP_KERNEL); |
| 681 | |
| 682 | if (!priv->output_limit) |
| 683 | return -ENOMEM; |
| 684 | |
| 685 | priv->output_limit->offset = 0; |
| 686 | priv->output_limit->entries = data[1]; |
| 687 | priv->output_limit->entry_size = |
| 688 | sizeof(struct pda_channel_output_limit); |
| 689 | priv->output_limit->len = priv->output_limit->entry_size * |
| 690 | priv->output_limit->entries + |
| 691 | priv->output_limit->offset; |
| 692 | |
| 693 | memcpy(priv->output_limit->data, &data[2], |
| 694 | data[1] * sizeof(struct pda_channel_output_limit)); |
| 695 | |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | static struct p54_cal_database *p54_convert_db(struct pda_custom_wrapper *src, |
| 700 | size_t total_len) |
| 701 | { |
| 702 | struct p54_cal_database *dst; |
| 703 | size_t payload_len, entries, entry_size, offset; |
| 704 | |
| 705 | payload_len = le16_to_cpu(src->len); |
| 706 | entries = le16_to_cpu(src->entries); |
| 707 | entry_size = le16_to_cpu(src->entry_size); |
| 708 | offset = le16_to_cpu(src->offset); |
| 709 | if (((entries * entry_size + offset) != payload_len) || |
| 710 | (payload_len + sizeof(*src) != total_len)) |
| 711 | return NULL; |
| 712 | |
| 713 | dst = kmalloc(sizeof(*dst) + payload_len, GFP_KERNEL); |
| 714 | if (!dst) |
| 715 | return NULL; |
| 716 | |
| 717 | dst->entries = entries; |
| 718 | dst->entry_size = entry_size; |
| 719 | dst->offset = offset; |
| 720 | dst->len = payload_len; |
| 721 | |
| 722 | memcpy(dst->data, src->data, payload_len); |
| 723 | return dst; |
| 724 | } |
| 725 | |
| 726 | int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len) |
| 727 | { |
| 728 | struct p54_common *priv = dev->priv; |
Larry Finger | e6a3f55 | 2009-07-19 21:53:14 -0500 | [diff] [blame] | 729 | struct eeprom_pda_wrap *wrap; |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 730 | struct pda_entry *entry; |
| 731 | unsigned int data_len, entry_len; |
| 732 | void *tmp; |
| 733 | int err; |
| 734 | u8 *end = (u8 *)eeprom + len; |
| 735 | u16 synth = 0; |
Christian Lamparter | d7eb50c | 2010-08-17 01:16:58 +0200 | [diff] [blame] | 736 | u16 crc16 = ~0; |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 737 | |
| 738 | wrap = (struct eeprom_pda_wrap *) eeprom; |
| 739 | entry = (void *)wrap->data + le16_to_cpu(wrap->len); |
| 740 | |
| 741 | /* verify that at least the entry length/code fits */ |
| 742 | while ((u8 *)entry <= end - sizeof(*entry)) { |
| 743 | entry_len = le16_to_cpu(entry->len); |
| 744 | data_len = ((entry_len - 1) << 1); |
| 745 | |
| 746 | /* abort if entry exceeds whole structure */ |
| 747 | if ((u8 *)entry + sizeof(*entry) + data_len > end) |
| 748 | break; |
| 749 | |
| 750 | switch (le16_to_cpu(entry->code)) { |
| 751 | case PDR_MAC_ADDRESS: |
| 752 | if (data_len != ETH_ALEN) |
| 753 | break; |
| 754 | SET_IEEE80211_PERM_ADDR(dev, entry->data); |
| 755 | break; |
| 756 | case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS: |
| 757 | if (priv->output_limit) |
| 758 | break; |
| 759 | err = p54_convert_output_limits(dev, entry->data, |
| 760 | data_len); |
| 761 | if (err) |
| 762 | goto err; |
| 763 | break; |
| 764 | case PDR_PRISM_PA_CAL_CURVE_DATA: { |
| 765 | struct pda_pa_curve_data *curve_data = |
| 766 | (struct pda_pa_curve_data *)entry->data; |
| 767 | if (data_len < sizeof(*curve_data)) { |
| 768 | err = -EINVAL; |
| 769 | goto err; |
| 770 | } |
| 771 | |
| 772 | switch (curve_data->cal_method_rev) { |
| 773 | case 0: |
| 774 | err = p54_convert_rev0(dev, curve_data); |
| 775 | break; |
| 776 | case 1: |
| 777 | err = p54_convert_rev1(dev, curve_data); |
| 778 | break; |
| 779 | default: |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 780 | wiphy_err(dev->wiphy, |
| 781 | "unknown curve data revision %d\n", |
| 782 | curve_data->cal_method_rev); |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 783 | err = -ENODEV; |
| 784 | break; |
| 785 | } |
| 786 | if (err) |
| 787 | goto err; |
| 788 | } |
| 789 | break; |
| 790 | case PDR_PRISM_ZIF_TX_IQ_CALIBRATION: |
Julia Lawall | 27b81bb | 2010-05-15 23:22:55 +0200 | [diff] [blame] | 791 | priv->iq_autocal = kmemdup(entry->data, data_len, |
| 792 | GFP_KERNEL); |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 793 | if (!priv->iq_autocal) { |
| 794 | err = -ENOMEM; |
| 795 | goto err; |
| 796 | } |
| 797 | |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 798 | priv->iq_autocal_len = data_len / sizeof(struct pda_iq_autocal_entry); |
| 799 | break; |
| 800 | case PDR_DEFAULT_COUNTRY: |
| 801 | p54_parse_default_country(dev, entry->data, data_len); |
| 802 | break; |
| 803 | case PDR_INTERFACE_LIST: |
| 804 | tmp = entry->data; |
| 805 | while ((u8 *)tmp < entry->data + data_len) { |
| 806 | struct exp_if *exp_if = tmp; |
| 807 | if (exp_if->if_id == cpu_to_le16(IF_ID_ISL39000)) |
| 808 | synth = le16_to_cpu(exp_if->variant); |
| 809 | tmp += sizeof(*exp_if); |
| 810 | } |
| 811 | break; |
| 812 | case PDR_HARDWARE_PLATFORM_COMPONENT_ID: |
| 813 | if (data_len < 2) |
| 814 | break; |
| 815 | priv->version = *(u8 *)(entry->data + 1); |
| 816 | break; |
| 817 | case PDR_RSSI_LINEAR_APPROXIMATION: |
| 818 | case PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND: |
| 819 | case PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED: |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 820 | err = p54_parse_rssical(dev, entry->data, data_len, |
| 821 | le16_to_cpu(entry->code)); |
| 822 | if (err) |
| 823 | goto err; |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 824 | break; |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 825 | case PDR_RSSI_LINEAR_APPROXIMATION_CUSTOMV2: { |
| 826 | struct pda_custom_wrapper *pda = (void *) entry->data; |
| 827 | __le16 *src; |
| 828 | u16 *dst; |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 829 | int i; |
| 830 | |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 831 | if (priv->rssi_db || data_len < sizeof(*pda)) |
| 832 | break; |
| 833 | |
| 834 | priv->rssi_db = p54_convert_db(pda, data_len); |
| 835 | if (!priv->rssi_db) |
| 836 | break; |
| 837 | |
| 838 | src = (void *) priv->rssi_db->data; |
| 839 | dst = (void *) priv->rssi_db->data; |
| 840 | |
| 841 | for (i = 0; i < priv->rssi_db->entries; i++) |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 842 | *(dst++) = (s16) le16_to_cpu(*(src++)); |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 843 | |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 844 | } |
| 845 | break; |
| 846 | case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS_CUSTOM: { |
| 847 | struct pda_custom_wrapper *pda = (void *) entry->data; |
| 848 | if (priv->output_limit || data_len < sizeof(*pda)) |
| 849 | break; |
| 850 | priv->output_limit = p54_convert_db(pda, data_len); |
| 851 | } |
| 852 | break; |
| 853 | case PDR_PRISM_PA_CAL_CURVE_DATA_CUSTOM: { |
| 854 | struct pda_custom_wrapper *pda = (void *) entry->data; |
| 855 | if (priv->curve_data || data_len < sizeof(*pda)) |
| 856 | break; |
| 857 | priv->curve_data = p54_convert_db(pda, data_len); |
| 858 | } |
| 859 | break; |
| 860 | case PDR_END: |
Christian Lamparter | d7eb50c | 2010-08-17 01:16:58 +0200 | [diff] [blame] | 861 | crc16 = ~crc_ccitt(crc16, (u8 *) entry, sizeof(*entry)); |
| 862 | if (crc16 != le16_to_cpup((__le16 *)entry->data)) { |
| 863 | wiphy_err(dev->wiphy, "eeprom failed checksum " |
| 864 | "test!\n"); |
| 865 | err = -ENOMSG; |
| 866 | goto err; |
| 867 | } else { |
| 868 | goto good_eeprom; |
| 869 | } |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 870 | break; |
| 871 | default: |
| 872 | break; |
| 873 | } |
| 874 | |
Christian Lamparter | d7eb50c | 2010-08-17 01:16:58 +0200 | [diff] [blame] | 875 | crc16 = crc_ccitt(crc16, (u8 *)entry, (entry_len + 1) * 2); |
| 876 | entry = (void *)entry + (entry_len + 1) * 2; |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 877 | } |
| 878 | |
Christian Lamparter | d7eb50c | 2010-08-17 01:16:58 +0200 | [diff] [blame] | 879 | wiphy_err(dev->wiphy, "unexpected end of eeprom data.\n"); |
| 880 | err = -ENODATA; |
| 881 | goto err; |
| 882 | |
| 883 | good_eeprom: |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 884 | if (!synth || !priv->iq_autocal || !priv->output_limit || |
| 885 | !priv->curve_data) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 886 | wiphy_err(dev->wiphy, |
| 887 | "not all required entries found in eeprom!\n"); |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 888 | err = -EINVAL; |
| 889 | goto err; |
| 890 | } |
| 891 | |
Christian Lamparter | 9bc6381 | 2012-07-28 02:57:51 +0200 | [diff] [blame^] | 892 | priv->rxhw = synth & PDR_SYNTH_FRONTEND_MASK; |
| 893 | |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 894 | err = p54_generate_channel_lists(dev); |
| 895 | if (err) |
| 896 | goto err; |
| 897 | |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 898 | if (priv->rxhw == PDR_SYNTH_FRONTEND_XBOW) |
| 899 | p54_init_xbow_synth(priv); |
| 900 | if (!(synth & PDR_SYNTH_24_GHZ_DISABLED)) |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 901 | dev->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 902 | priv->band_table[IEEE80211_BAND_2GHZ]; |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 903 | if (!(synth & PDR_SYNTH_5_GHZ_DISABLED)) |
Christian Lamparter | 1a9b667 | 2009-07-11 01:22:26 +0200 | [diff] [blame] | 904 | dev->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 905 | priv->band_table[IEEE80211_BAND_5GHZ]; |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 906 | if ((synth & PDR_SYNTH_RX_DIV_MASK) == PDR_SYNTH_RX_DIV_SUPPORTED) |
| 907 | priv->rx_diversity_mask = 3; |
| 908 | if ((synth & PDR_SYNTH_TX_DIV_MASK) == PDR_SYNTH_TX_DIV_SUPPORTED) |
| 909 | priv->tx_diversity_mask = 3; |
| 910 | |
| 911 | if (!is_valid_ether_addr(dev->wiphy->perm_addr)) { |
| 912 | u8 perm_addr[ETH_ALEN]; |
| 913 | |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 914 | wiphy_warn(dev->wiphy, |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 915 | "Invalid hwaddr! Using randomly generated MAC addr\n"); |
Joe Perches | f4f7f414 | 2012-07-12 19:33:08 +0000 | [diff] [blame] | 916 | eth_random_addr(perm_addr); |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 917 | SET_IEEE80211_PERM_ADDR(dev, perm_addr); |
| 918 | } |
| 919 | |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 920 | priv->cur_rssi = &p54_rssi_default; |
| 921 | |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 922 | wiphy_info(dev->wiphy, "hwaddr %pM, MAC:isl38%02x RF:%s\n", |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 923 | dev->wiphy->perm_addr, priv->version, |
| 924 | p54_rf_chips[priv->rxhw]); |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 925 | |
| 926 | return 0; |
| 927 | |
| 928 | err: |
| 929 | kfree(priv->iq_autocal); |
| 930 | kfree(priv->output_limit); |
| 931 | kfree(priv->curve_data); |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 932 | kfree(priv->rssi_db); |
Christian Lamparter | 0d78156 | 2011-08-20 01:53:59 +0200 | [diff] [blame] | 933 | kfree(priv->survey); |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 934 | priv->iq_autocal = NULL; |
| 935 | priv->output_limit = NULL; |
| 936 | priv->curve_data = NULL; |
Christian Lamparter | 7a047f4 | 2011-02-12 22:32:49 +0100 | [diff] [blame] | 937 | priv->rssi_db = NULL; |
Christian Lamparter | 0d78156 | 2011-08-20 01:53:59 +0200 | [diff] [blame] | 938 | priv->survey = NULL; |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 939 | |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 940 | wiphy_err(dev->wiphy, "eeprom parse failed!\n"); |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 941 | return err; |
| 942 | } |
| 943 | EXPORT_SYMBOL_GPL(p54_parse_eeprom); |
| 944 | |
| 945 | int p54_read_eeprom(struct ieee80211_hw *dev) |
| 946 | { |
| 947 | struct p54_common *priv = dev->priv; |
| 948 | size_t eeprom_size = 0x2020, offset = 0, blocksize, maxblocksize; |
| 949 | int ret = -ENOMEM; |
Larry Finger | e6a3f55 | 2009-07-19 21:53:14 -0500 | [diff] [blame] | 950 | void *eeprom; |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 951 | |
| 952 | maxblocksize = EEPROM_READBACK_LEN; |
| 953 | if (priv->fw_var >= 0x509) |
| 954 | maxblocksize -= 0xc; |
| 955 | else |
| 956 | maxblocksize -= 0x4; |
| 957 | |
| 958 | eeprom = kzalloc(eeprom_size, GFP_KERNEL); |
| 959 | if (unlikely(!eeprom)) |
| 960 | goto free; |
| 961 | |
| 962 | while (eeprom_size) { |
| 963 | blocksize = min(eeprom_size, maxblocksize); |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 964 | ret = p54_download_eeprom(priv, eeprom + offset, |
Christian Lamparter | 4c8a32f | 2009-06-23 10:36:26 -0500 | [diff] [blame] | 965 | offset, blocksize); |
| 966 | if (unlikely(ret)) |
| 967 | goto free; |
| 968 | |
| 969 | offset += blocksize; |
| 970 | eeprom_size -= blocksize; |
| 971 | } |
| 972 | |
| 973 | ret = p54_parse_eeprom(dev, eeprom, offset); |
| 974 | free: |
| 975 | kfree(eeprom); |
| 976 | return ret; |
| 977 | } |
| 978 | EXPORT_SYMBOL_GPL(p54_read_eeprom); |