]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/net/wireless/p54/eeprom.c
drivers/net/wireless: Restore upper case words in wiphy_<level> messages
[net-next-2.6.git] / drivers / net / wireless / p54 / eeprom.c
CommitLineData
4c8a32f5
CL
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>
1a9b6679 22#include <linux/sort.h>
5a0e3ad6 23#include <linux/slab.h>
4c8a32f5
CL
24
25#include <net/mac80211.h>
26
27#include "p54.h"
28#include "eeprom.h"
29#include "lmac.h"
30
31static struct ieee80211_rate p54_bgrates[] = {
32 { .bitrate = 10, .hw_value = 0, },
33 { .bitrate = 20, .hw_value = 1, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
34 { .bitrate = 55, .hw_value = 2, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
35 { .bitrate = 110, .hw_value = 3, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
36 { .bitrate = 60, .hw_value = 4, },
37 { .bitrate = 90, .hw_value = 5, },
38 { .bitrate = 120, .hw_value = 6, },
39 { .bitrate = 180, .hw_value = 7, },
40 { .bitrate = 240, .hw_value = 8, },
41 { .bitrate = 360, .hw_value = 9, },
42 { .bitrate = 480, .hw_value = 10, },
43 { .bitrate = 540, .hw_value = 11, },
44};
45
4c8a32f5
CL
46static struct ieee80211_rate p54_arates[] = {
47 { .bitrate = 60, .hw_value = 4, },
48 { .bitrate = 90, .hw_value = 5, },
49 { .bitrate = 120, .hw_value = 6, },
50 { .bitrate = 180, .hw_value = 7, },
51 { .bitrate = 240, .hw_value = 8, },
52 { .bitrate = 360, .hw_value = 9, },
53 { .bitrate = 480, .hw_value = 10, },
54 { .bitrate = 540, .hw_value = 11, },
55};
56
1a9b6679
CL
57#define CHAN_HAS_CAL BIT(0)
58#define CHAN_HAS_LIMIT BIT(1)
59#define CHAN_HAS_CURVE BIT(2)
60#define CHAN_HAS_ALL (CHAN_HAS_CAL | CHAN_HAS_LIMIT | CHAN_HAS_CURVE)
61
62struct p54_channel_entry {
63 u16 freq;
64 u16 data;
65 int index;
66 enum ieee80211_band band;
4c8a32f5
CL
67};
68
1a9b6679
CL
69struct p54_channel_list {
70 struct p54_channel_entry *channels;
71 size_t entries;
72 size_t max_entries;
73 size_t band_channel_num[IEEE80211_NUM_BANDS];
4c8a32f5
CL
74};
75
1a9b6679
CL
76static int p54_get_band_from_freq(u16 freq)
77{
78 /* FIXME: sync these values with the 802.11 spec */
79
80 if ((freq >= 2412) && (freq <= 2484))
81 return IEEE80211_BAND_2GHZ;
82
83 if ((freq >= 4920) && (freq <= 5825))
84 return IEEE80211_BAND_5GHZ;
85
86 return -1;
87}
88
89static int p54_compare_channels(const void *_a,
90 const void *_b)
91{
92 const struct p54_channel_entry *a = _a;
93 const struct p54_channel_entry *b = _b;
94
95 return a->index - b->index;
96}
97
98static int p54_fill_band_bitrates(struct ieee80211_hw *dev,
99 struct ieee80211_supported_band *band_entry,
100 enum ieee80211_band band)
101{
102 /* TODO: generate rate array dynamically */
103
104 switch (band) {
105 case IEEE80211_BAND_2GHZ:
106 band_entry->bitrates = p54_bgrates;
107 band_entry->n_bitrates = ARRAY_SIZE(p54_bgrates);
108 break;
109 case IEEE80211_BAND_5GHZ:
110 band_entry->bitrates = p54_arates;
111 band_entry->n_bitrates = ARRAY_SIZE(p54_arates);
112 break;
113 default:
114 return -EINVAL;
115 }
116
117 return 0;
118}
119
120static int p54_generate_band(struct ieee80211_hw *dev,
121 struct p54_channel_list *list,
122 enum ieee80211_band band)
123{
124 struct p54_common *priv = dev->priv;
125 struct ieee80211_supported_band *tmp, *old;
126 unsigned int i, j;
127 int ret = -ENOMEM;
128
129 if ((!list->entries) || (!list->band_channel_num[band]))
93a59d75 130 return -EINVAL;
1a9b6679
CL
131
132 tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
133 if (!tmp)
134 goto err_out;
135
136 tmp->channels = kzalloc(sizeof(struct ieee80211_channel) *
137 list->band_channel_num[band], GFP_KERNEL);
138 if (!tmp->channels)
139 goto err_out;
140
141 ret = p54_fill_band_bitrates(dev, tmp, band);
142 if (ret)
143 goto err_out;
144
145 for (i = 0, j = 0; (j < list->band_channel_num[band]) &&
146 (i < list->entries); i++) {
147
148 if (list->channels[i].band != band)
149 continue;
150
151 if (list->channels[i].data != CHAN_HAS_ALL) {
c96c31e4
JP
152 wiphy_err(dev->wiphy,
153 "%s%s%s is/are missing for channel:%d [%d MHz].\n",
154 (list->channels[i].data & CHAN_HAS_CAL ? "" :
155 " [iqauto calibration data]"),
156 (list->channels[i].data & CHAN_HAS_LIMIT ? "" :
157 " [output power limits]"),
158 (list->channels[i].data & CHAN_HAS_CURVE ? "" :
159 " [curve data]"),
160 list->channels[i].index, list->channels[i].freq);
93a59d75 161 continue;
1a9b6679
CL
162 }
163
164 tmp->channels[j].band = list->channels[i].band;
165 tmp->channels[j].center_freq = list->channels[i].freq;
166 j++;
167 }
168
93a59d75 169 if (j == 0) {
5db55844 170 wiphy_err(dev->wiphy, "Disabling totally damaged %d GHz band\n",
c96c31e4 171 (band == IEEE80211_BAND_2GHZ) ? 2 : 5);
93a59d75
CL
172
173 ret = -ENODATA;
174 goto err_out;
175 }
176
177 tmp->n_channels = j;
1a9b6679
CL
178 old = priv->band_table[band];
179 priv->band_table[band] = tmp;
180 if (old) {
181 kfree(old->channels);
182 kfree(old);
183 }
184
185 return 0;
186
187err_out:
188 if (tmp) {
189 kfree(tmp->channels);
190 kfree(tmp);
191 }
192
193 return ret;
194}
195
196static void p54_update_channel_param(struct p54_channel_list *list,
197 u16 freq, u16 data)
198{
199 int band, i;
200
201 /*
202 * usually all lists in the eeprom are mostly sorted.
203 * so it's very likely that the entry we are looking for
204 * is right at the end of the list
205 */
206 for (i = list->entries; i >= 0; i--) {
207 if (freq == list->channels[i].freq) {
208 list->channels[i].data |= data;
209 break;
210 }
211 }
212
213 if ((i < 0) && (list->entries < list->max_entries)) {
214 /* entry does not exist yet. Initialize a new one. */
215 band = p54_get_band_from_freq(freq);
216
217 /*
218 * filter out frequencies which don't belong into
219 * any supported band.
220 */
221 if (band < 0)
222 return ;
223
224 i = list->entries++;
225 list->band_channel_num[band]++;
226
227 list->channels[i].freq = freq;
228 list->channels[i].data = data;
229 list->channels[i].band = band;
230 list->channels[i].index = ieee80211_frequency_to_channel(freq);
231 /* TODO: parse output_limit and fill max_power */
232 }
233}
234
235static int p54_generate_channel_lists(struct ieee80211_hw *dev)
236{
237 struct p54_common *priv = dev->priv;
238 struct p54_channel_list *list;
239 unsigned int i, j, max_channel_num;
93a59d75 240 int ret = 0;
1a9b6679
CL
241 u16 freq;
242
243 if ((priv->iq_autocal_len != priv->curve_data->entries) ||
244 (priv->iq_autocal_len != priv->output_limit->entries))
c96c31e4
JP
245 wiphy_err(dev->wiphy,
246 "Unsupported or damaged EEPROM detected. "
247 "You may not be able to use all channels.\n");
1a9b6679
CL
248
249 max_channel_num = max_t(unsigned int, priv->output_limit->entries,
250 priv->iq_autocal_len);
251 max_channel_num = max_t(unsigned int, max_channel_num,
252 priv->curve_data->entries);
253
254 list = kzalloc(sizeof(*list), GFP_KERNEL);
93a59d75
CL
255 if (!list) {
256 ret = -ENOMEM;
1a9b6679 257 goto free;
93a59d75 258 }
1a9b6679
CL
259
260 list->max_entries = max_channel_num;
261 list->channels = kzalloc(sizeof(struct p54_channel_entry) *
262 max_channel_num, GFP_KERNEL);
263 if (!list->channels)
264 goto free;
265
266 for (i = 0; i < max_channel_num; i++) {
267 if (i < priv->iq_autocal_len) {
268 freq = le16_to_cpu(priv->iq_autocal[i].freq);
269 p54_update_channel_param(list, freq, CHAN_HAS_CAL);
270 }
271
272 if (i < priv->output_limit->entries) {
273 freq = le16_to_cpup((__le16 *) (i *
274 priv->output_limit->entry_size +
275 priv->output_limit->offset +
276 priv->output_limit->data));
277
278 p54_update_channel_param(list, freq, CHAN_HAS_LIMIT);
279 }
280
281 if (i < priv->curve_data->entries) {
282 freq = le16_to_cpup((__le16 *) (i *
283 priv->curve_data->entry_size +
284 priv->curve_data->offset +
285 priv->curve_data->data));
286
287 p54_update_channel_param(list, freq, CHAN_HAS_CURVE);
288 }
289 }
290
291 /* sort the list by the channel index */
292 sort(list->channels, list->entries, sizeof(struct p54_channel_entry),
293 p54_compare_channels, NULL);
294
295 for (i = 0, j = 0; i < IEEE80211_NUM_BANDS; i++) {
93a59d75 296 if (p54_generate_band(dev, list, i) == 0)
1a9b6679 297 j++;
1a9b6679
CL
298 }
299 if (j == 0) {
300 /* no useable band available. */
301 ret = -EINVAL;
302 }
303
304free:
305 if (list) {
306 kfree(list->channels);
307 kfree(list);
308 }
309
310 return ret;
311}
312
4c8a32f5
CL
313static int p54_convert_rev0(struct ieee80211_hw *dev,
314 struct pda_pa_curve_data *curve_data)
315{
316 struct p54_common *priv = dev->priv;
317 struct p54_pa_curve_data_sample *dst;
318 struct pda_pa_curve_data_sample_rev0 *src;
319 size_t cd_len = sizeof(*curve_data) +
320 (curve_data->points_per_channel*sizeof(*dst) + 2) *
321 curve_data->channels;
322 unsigned int i, j;
323 void *source, *target;
324
325 priv->curve_data = kmalloc(sizeof(*priv->curve_data) + cd_len,
326 GFP_KERNEL);
327 if (!priv->curve_data)
328 return -ENOMEM;
329
330 priv->curve_data->entries = curve_data->channels;
331 priv->curve_data->entry_size = sizeof(__le16) +
332 sizeof(*dst) * curve_data->points_per_channel;
333 priv->curve_data->offset = offsetof(struct pda_pa_curve_data, data);
334 priv->curve_data->len = cd_len;
335 memcpy(priv->curve_data->data, curve_data, sizeof(*curve_data));
336 source = curve_data->data;
337 target = ((struct pda_pa_curve_data *) priv->curve_data->data)->data;
338 for (i = 0; i < curve_data->channels; i++) {
339 __le16 *freq = source;
340 source += sizeof(__le16);
341 *((__le16 *)target) = *freq;
342 target += sizeof(__le16);
343 for (j = 0; j < curve_data->points_per_channel; j++) {
344 dst = target;
345 src = source;
346
347 dst->rf_power = src->rf_power;
348 dst->pa_detector = src->pa_detector;
349 dst->data_64qam = src->pcv;
350 /* "invent" the points for the other modulations */
351#define SUB(x, y) (u8)(((x) - (y)) > (x) ? 0 : (x) - (y))
352 dst->data_16qam = SUB(src->pcv, 12);
353 dst->data_qpsk = SUB(dst->data_16qam, 12);
354 dst->data_bpsk = SUB(dst->data_qpsk, 12);
355 dst->data_barker = SUB(dst->data_bpsk, 14);
356#undef SUB
357 target += sizeof(*dst);
358 source += sizeof(*src);
359 }
360 }
361
362 return 0;
363}
364
365static int p54_convert_rev1(struct ieee80211_hw *dev,
366 struct pda_pa_curve_data *curve_data)
367{
368 struct p54_common *priv = dev->priv;
369 struct p54_pa_curve_data_sample *dst;
370 struct pda_pa_curve_data_sample_rev1 *src;
371 size_t cd_len = sizeof(*curve_data) +
372 (curve_data->points_per_channel*sizeof(*dst) + 2) *
373 curve_data->channels;
374 unsigned int i, j;
375 void *source, *target;
376
377 priv->curve_data = kzalloc(cd_len + sizeof(*priv->curve_data),
378 GFP_KERNEL);
379 if (!priv->curve_data)
380 return -ENOMEM;
381
382 priv->curve_data->entries = curve_data->channels;
383 priv->curve_data->entry_size = sizeof(__le16) +
384 sizeof(*dst) * curve_data->points_per_channel;
385 priv->curve_data->offset = offsetof(struct pda_pa_curve_data, data);
386 priv->curve_data->len = cd_len;
387 memcpy(priv->curve_data->data, curve_data, sizeof(*curve_data));
388 source = curve_data->data;
389 target = ((struct pda_pa_curve_data *) priv->curve_data->data)->data;
390 for (i = 0; i < curve_data->channels; i++) {
391 __le16 *freq = source;
392 source += sizeof(__le16);
393 *((__le16 *)target) = *freq;
394 target += sizeof(__le16);
395 for (j = 0; j < curve_data->points_per_channel; j++) {
396 memcpy(target, source, sizeof(*src));
397
398 target += sizeof(*dst);
399 source += sizeof(*src);
400 }
401 source++;
402 }
403
404 return 0;
405}
406
407static const char *p54_rf_chips[] = { "INVALID-0", "Duette3", "Duette2",
408 "Frisbee", "Xbow", "Longbow", "INVALID-6", "INVALID-7" };
409
410static void p54_parse_rssical(struct ieee80211_hw *dev, void *data, int len,
411 u16 type)
412{
413 struct p54_common *priv = dev->priv;
414 int offset = (type == PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED) ? 2 : 0;
415 int entry_size = sizeof(struct pda_rssi_cal_entry) + offset;
416 int num_entries = (type == PDR_RSSI_LINEAR_APPROXIMATION) ? 1 : 2;
417 int i;
418
419 if (len != (entry_size * num_entries)) {
c96c31e4
JP
420 wiphy_err(dev->wiphy,
421 "unknown rssi calibration data packing type:(%x) len:%d.\n",
422 type, len);
4c8a32f5
CL
423
424 print_hex_dump_bytes("rssical:", DUMP_PREFIX_NONE,
425 data, len);
426
c96c31e4 427 wiphy_err(dev->wiphy, "please report this issue.\n");
4c8a32f5
CL
428 return;
429 }
430
431 for (i = 0; i < num_entries; i++) {
432 struct pda_rssi_cal_entry *cal = data +
433 (offset + i * entry_size);
434 priv->rssical_db[i].mul = (s16) le16_to_cpu(cal->mul);
435 priv->rssical_db[i].add = (s16) le16_to_cpu(cal->add);
436 }
437}
438
439static void p54_parse_default_country(struct ieee80211_hw *dev,
440 void *data, int len)
441{
442 struct pda_country *country;
443
444 if (len != sizeof(*country)) {
c96c31e4
JP
445 wiphy_err(dev->wiphy,
446 "found possible invalid default country eeprom entry. (entry size: %d)\n",
447 len);
4c8a32f5
CL
448
449 print_hex_dump_bytes("country:", DUMP_PREFIX_NONE,
450 data, len);
451
c96c31e4 452 wiphy_err(dev->wiphy, "please report this issue.\n");
4c8a32f5
CL
453 return;
454 }
455
456 country = (struct pda_country *) data;
457 if (country->flags == PDR_COUNTRY_CERT_CODE_PSEUDO)
458 regulatory_hint(dev->wiphy, country->alpha2);
459 else {
460 /* TODO:
461 * write a shared/common function that converts
462 * "Regulatory domain codes" (802.11-2007 14.8.2.2)
463 * into ISO/IEC 3166-1 alpha2 for regulatory_hint.
464 */
465 }
466}
467
468static int p54_convert_output_limits(struct ieee80211_hw *dev,
469 u8 *data, size_t len)
470{
471 struct p54_common *priv = dev->priv;
472
473 if (len < 2)
474 return -EINVAL;
475
476 if (data[0] != 0) {
c96c31e4
JP
477 wiphy_err(dev->wiphy, "unknown output power db revision:%x\n",
478 data[0]);
4c8a32f5
CL
479 return -EINVAL;
480 }
481
482 if (2 + data[1] * sizeof(struct pda_channel_output_limit) > len)
483 return -EINVAL;
484
485 priv->output_limit = kmalloc(data[1] *
486 sizeof(struct pda_channel_output_limit) +
487 sizeof(*priv->output_limit), GFP_KERNEL);
488
489 if (!priv->output_limit)
490 return -ENOMEM;
491
492 priv->output_limit->offset = 0;
493 priv->output_limit->entries = data[1];
494 priv->output_limit->entry_size =
495 sizeof(struct pda_channel_output_limit);
496 priv->output_limit->len = priv->output_limit->entry_size *
497 priv->output_limit->entries +
498 priv->output_limit->offset;
499
500 memcpy(priv->output_limit->data, &data[2],
501 data[1] * sizeof(struct pda_channel_output_limit));
502
503 return 0;
504}
505
506static struct p54_cal_database *p54_convert_db(struct pda_custom_wrapper *src,
507 size_t total_len)
508{
509 struct p54_cal_database *dst;
510 size_t payload_len, entries, entry_size, offset;
511
512 payload_len = le16_to_cpu(src->len);
513 entries = le16_to_cpu(src->entries);
514 entry_size = le16_to_cpu(src->entry_size);
515 offset = le16_to_cpu(src->offset);
516 if (((entries * entry_size + offset) != payload_len) ||
517 (payload_len + sizeof(*src) != total_len))
518 return NULL;
519
520 dst = kmalloc(sizeof(*dst) + payload_len, GFP_KERNEL);
521 if (!dst)
522 return NULL;
523
524 dst->entries = entries;
525 dst->entry_size = entry_size;
526 dst->offset = offset;
527 dst->len = payload_len;
528
529 memcpy(dst->data, src->data, payload_len);
530 return dst;
531}
532
533int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
534{
535 struct p54_common *priv = dev->priv;
e6a3f551 536 struct eeprom_pda_wrap *wrap;
4c8a32f5
CL
537 struct pda_entry *entry;
538 unsigned int data_len, entry_len;
539 void *tmp;
540 int err;
541 u8 *end = (u8 *)eeprom + len;
542 u16 synth = 0;
543
544 wrap = (struct eeprom_pda_wrap *) eeprom;
545 entry = (void *)wrap->data + le16_to_cpu(wrap->len);
546
547 /* verify that at least the entry length/code fits */
548 while ((u8 *)entry <= end - sizeof(*entry)) {
549 entry_len = le16_to_cpu(entry->len);
550 data_len = ((entry_len - 1) << 1);
551
552 /* abort if entry exceeds whole structure */
553 if ((u8 *)entry + sizeof(*entry) + data_len > end)
554 break;
555
556 switch (le16_to_cpu(entry->code)) {
557 case PDR_MAC_ADDRESS:
558 if (data_len != ETH_ALEN)
559 break;
560 SET_IEEE80211_PERM_ADDR(dev, entry->data);
561 break;
562 case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS:
563 if (priv->output_limit)
564 break;
565 err = p54_convert_output_limits(dev, entry->data,
566 data_len);
567 if (err)
568 goto err;
569 break;
570 case PDR_PRISM_PA_CAL_CURVE_DATA: {
571 struct pda_pa_curve_data *curve_data =
572 (struct pda_pa_curve_data *)entry->data;
573 if (data_len < sizeof(*curve_data)) {
574 err = -EINVAL;
575 goto err;
576 }
577
578 switch (curve_data->cal_method_rev) {
579 case 0:
580 err = p54_convert_rev0(dev, curve_data);
581 break;
582 case 1:
583 err = p54_convert_rev1(dev, curve_data);
584 break;
585 default:
c96c31e4
JP
586 wiphy_err(dev->wiphy,
587 "unknown curve data revision %d\n",
588 curve_data->cal_method_rev);
4c8a32f5
CL
589 err = -ENODEV;
590 break;
591 }
592 if (err)
593 goto err;
594 }
595 break;
596 case PDR_PRISM_ZIF_TX_IQ_CALIBRATION:
27b81bbe
JL
597 priv->iq_autocal = kmemdup(entry->data, data_len,
598 GFP_KERNEL);
4c8a32f5
CL
599 if (!priv->iq_autocal) {
600 err = -ENOMEM;
601 goto err;
602 }
603
4c8a32f5
CL
604 priv->iq_autocal_len = data_len / sizeof(struct pda_iq_autocal_entry);
605 break;
606 case PDR_DEFAULT_COUNTRY:
607 p54_parse_default_country(dev, entry->data, data_len);
608 break;
609 case PDR_INTERFACE_LIST:
610 tmp = entry->data;
611 while ((u8 *)tmp < entry->data + data_len) {
612 struct exp_if *exp_if = tmp;
613 if (exp_if->if_id == cpu_to_le16(IF_ID_ISL39000))
614 synth = le16_to_cpu(exp_if->variant);
615 tmp += sizeof(*exp_if);
616 }
617 break;
618 case PDR_HARDWARE_PLATFORM_COMPONENT_ID:
619 if (data_len < 2)
620 break;
621 priv->version = *(u8 *)(entry->data + 1);
622 break;
623 case PDR_RSSI_LINEAR_APPROXIMATION:
624 case PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND:
625 case PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED:
626 p54_parse_rssical(dev, entry->data, data_len,
627 le16_to_cpu(entry->code));
628 break;
629 case PDR_RSSI_LINEAR_APPROXIMATION_CUSTOM: {
630 __le16 *src = (void *) entry->data;
631 s16 *dst = (void *) &priv->rssical_db;
632 int i;
633
634 if (data_len != sizeof(priv->rssical_db)) {
635 err = -EINVAL;
636 goto err;
637 }
638 for (i = 0; i < sizeof(priv->rssical_db) /
639 sizeof(*src); i++)
640 *(dst++) = (s16) le16_to_cpu(*(src++));
641 }
642 break;
643 case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS_CUSTOM: {
644 struct pda_custom_wrapper *pda = (void *) entry->data;
645 if (priv->output_limit || data_len < sizeof(*pda))
646 break;
647 priv->output_limit = p54_convert_db(pda, data_len);
648 }
649 break;
650 case PDR_PRISM_PA_CAL_CURVE_DATA_CUSTOM: {
651 struct pda_custom_wrapper *pda = (void *) entry->data;
652 if (priv->curve_data || data_len < sizeof(*pda))
653 break;
654 priv->curve_data = p54_convert_db(pda, data_len);
655 }
656 break;
657 case PDR_END:
658 /* make it overrun */
659 entry_len = len;
660 break;
661 default:
662 break;
663 }
664
665 entry = (void *)entry + (entry_len + 1)*2;
666 }
667
668 if (!synth || !priv->iq_autocal || !priv->output_limit ||
669 !priv->curve_data) {
c96c31e4
JP
670 wiphy_err(dev->wiphy,
671 "not all required entries found in eeprom!\n");
4c8a32f5
CL
672 err = -EINVAL;
673 goto err;
674 }
675
1a9b6679
CL
676 err = p54_generate_channel_lists(dev);
677 if (err)
678 goto err;
679
4c8a32f5
CL
680 priv->rxhw = synth & PDR_SYNTH_FRONTEND_MASK;
681 if (priv->rxhw == PDR_SYNTH_FRONTEND_XBOW)
682 p54_init_xbow_synth(priv);
683 if (!(synth & PDR_SYNTH_24_GHZ_DISABLED))
1a9b6679
CL
684 dev->wiphy->bands[IEEE80211_BAND_2GHZ] =
685 priv->band_table[IEEE80211_BAND_2GHZ];
4c8a32f5 686 if (!(synth & PDR_SYNTH_5_GHZ_DISABLED))
1a9b6679
CL
687 dev->wiphy->bands[IEEE80211_BAND_5GHZ] =
688 priv->band_table[IEEE80211_BAND_5GHZ];
4c8a32f5
CL
689 if ((synth & PDR_SYNTH_RX_DIV_MASK) == PDR_SYNTH_RX_DIV_SUPPORTED)
690 priv->rx_diversity_mask = 3;
691 if ((synth & PDR_SYNTH_TX_DIV_MASK) == PDR_SYNTH_TX_DIV_SUPPORTED)
692 priv->tx_diversity_mask = 3;
693
694 if (!is_valid_ether_addr(dev->wiphy->perm_addr)) {
695 u8 perm_addr[ETH_ALEN];
696
c96c31e4 697 wiphy_warn(dev->wiphy,
5db55844 698 "Invalid hwaddr! Using randomly generated MAC addr\n");
4c8a32f5
CL
699 random_ether_addr(perm_addr);
700 SET_IEEE80211_PERM_ADDR(dev, perm_addr);
701 }
702
5db55844 703 wiphy_info(dev->wiphy, "hwaddr %pM, MAC:isl38%02x RF:%s\n",
c96c31e4
JP
704 dev->wiphy->perm_addr, priv->version,
705 p54_rf_chips[priv->rxhw]);
4c8a32f5
CL
706
707 return 0;
708
709err:
710 kfree(priv->iq_autocal);
711 kfree(priv->output_limit);
712 kfree(priv->curve_data);
713 priv->iq_autocal = NULL;
714 priv->output_limit = NULL;
715 priv->curve_data = NULL;
716
c96c31e4 717 wiphy_err(dev->wiphy, "eeprom parse failed!\n");
4c8a32f5
CL
718 return err;
719}
720EXPORT_SYMBOL_GPL(p54_parse_eeprom);
721
722int p54_read_eeprom(struct ieee80211_hw *dev)
723{
724 struct p54_common *priv = dev->priv;
725 size_t eeprom_size = 0x2020, offset = 0, blocksize, maxblocksize;
726 int ret = -ENOMEM;
e6a3f551 727 void *eeprom;
4c8a32f5
CL
728
729 maxblocksize = EEPROM_READBACK_LEN;
730 if (priv->fw_var >= 0x509)
731 maxblocksize -= 0xc;
732 else
733 maxblocksize -= 0x4;
734
735 eeprom = kzalloc(eeprom_size, GFP_KERNEL);
736 if (unlikely(!eeprom))
737 goto free;
738
739 while (eeprom_size) {
740 blocksize = min(eeprom_size, maxblocksize);
741 ret = p54_download_eeprom(priv, (void *) (eeprom + offset),
742 offset, blocksize);
743 if (unlikely(ret))
744 goto free;
745
746 offset += blocksize;
747 eeprom_size -= blocksize;
748 }
749
750 ret = p54_parse_eeprom(dev, eeprom, offset);
751free:
752 kfree(eeprom);
753 return ret;
754}
755EXPORT_SYMBOL_GPL(p54_read_eeprom);