drivers/net/wireless/p54/eeprom.c: Return -ENOMEM on memory allocation failure
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / wireless / p54 / eeprom.c
blob2c31eb4c21a2e4850732184330cf6959d18f0a85
1 /*
2 * EEPROM parser code for mac80211 Prism54 drivers
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>
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).
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.
19 #include <linux/init.h>
20 #include <linux/firmware.h>
21 #include <linux/etherdevice.h>
22 #include <linux/sort.h>
24 #include <net/mac80211.h>
26 #include "p54.h"
27 #include "eeprom.h"
28 #include "lmac.h"
30 static struct ieee80211_rate p54_bgrates[] = {
31 { .bitrate = 10, .hw_value = 0, },
32 { .bitrate = 20, .hw_value = 1, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
33 { .bitrate = 55, .hw_value = 2, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
34 { .bitrate = 110, .hw_value = 3, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
35 { .bitrate = 60, .hw_value = 4, },
36 { .bitrate = 90, .hw_value = 5, },
37 { .bitrate = 120, .hw_value = 6, },
38 { .bitrate = 180, .hw_value = 7, },
39 { .bitrate = 240, .hw_value = 8, },
40 { .bitrate = 360, .hw_value = 9, },
41 { .bitrate = 480, .hw_value = 10, },
42 { .bitrate = 540, .hw_value = 11, },
45 static struct ieee80211_rate p54_arates[] = {
46 { .bitrate = 60, .hw_value = 4, },
47 { .bitrate = 90, .hw_value = 5, },
48 { .bitrate = 120, .hw_value = 6, },
49 { .bitrate = 180, .hw_value = 7, },
50 { .bitrate = 240, .hw_value = 8, },
51 { .bitrate = 360, .hw_value = 9, },
52 { .bitrate = 480, .hw_value = 10, },
53 { .bitrate = 540, .hw_value = 11, },
56 #define CHAN_HAS_CAL BIT(0)
57 #define CHAN_HAS_LIMIT BIT(1)
58 #define CHAN_HAS_CURVE BIT(2)
59 #define CHAN_HAS_ALL (CHAN_HAS_CAL | CHAN_HAS_LIMIT | CHAN_HAS_CURVE)
61 struct p54_channel_entry {
62 u16 freq;
63 u16 data;
64 int index;
65 enum ieee80211_band band;
68 struct p54_channel_list {
69 struct p54_channel_entry *channels;
70 size_t entries;
71 size_t max_entries;
72 size_t band_channel_num[IEEE80211_NUM_BANDS];
75 static int p54_get_band_from_freq(u16 freq)
77 /* FIXME: sync these values with the 802.11 spec */
79 if ((freq >= 2412) && (freq <= 2484))
80 return IEEE80211_BAND_2GHZ;
82 if ((freq >= 4920) && (freq <= 5825))
83 return IEEE80211_BAND_5GHZ;
85 return -1;
88 static int p54_compare_channels(const void *_a,
89 const void *_b)
91 const struct p54_channel_entry *a = _a;
92 const struct p54_channel_entry *b = _b;
94 return a->index - b->index;
97 static int p54_fill_band_bitrates(struct ieee80211_hw *dev,
98 struct ieee80211_supported_band *band_entry,
99 enum ieee80211_band band)
101 /* TODO: generate rate array dynamically */
103 switch (band) {
104 case IEEE80211_BAND_2GHZ:
105 band_entry->bitrates = p54_bgrates;
106 band_entry->n_bitrates = ARRAY_SIZE(p54_bgrates);
107 break;
108 case IEEE80211_BAND_5GHZ:
109 band_entry->bitrates = p54_arates;
110 band_entry->n_bitrates = ARRAY_SIZE(p54_arates);
111 break;
112 default:
113 return -EINVAL;
116 return 0;
119 static int p54_generate_band(struct ieee80211_hw *dev,
120 struct p54_channel_list *list,
121 enum ieee80211_band band)
123 struct p54_common *priv = dev->priv;
124 struct ieee80211_supported_band *tmp, *old;
125 unsigned int i, j;
126 int ret = -ENOMEM;
128 if ((!list->entries) || (!list->band_channel_num[band]))
129 return -EINVAL;
131 tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
132 if (!tmp)
133 goto err_out;
135 tmp->channels = kzalloc(sizeof(struct ieee80211_channel) *
136 list->band_channel_num[band], GFP_KERNEL);
137 if (!tmp->channels)
138 goto err_out;
140 ret = p54_fill_band_bitrates(dev, tmp, band);
141 if (ret)
142 goto err_out;
144 for (i = 0, j = 0; (j < list->band_channel_num[band]) &&
145 (i < list->entries); i++) {
147 if (list->channels[i].band != band)
148 continue;
150 if (list->channels[i].data != CHAN_HAS_ALL) {
151 printk(KERN_ERR "%s:%s%s%s is/are missing for "
152 "channel:%d [%d MHz].\n",
153 wiphy_name(dev->wiphy),
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);
161 continue;
164 tmp->channels[j].band = list->channels[i].band;
165 tmp->channels[j].center_freq = list->channels[i].freq;
166 j++;
169 if (j == 0) {
170 printk(KERN_ERR "%s: Disabling totally damaged %s band.\n",
171 wiphy_name(dev->wiphy), (band == IEEE80211_BAND_2GHZ) ?
172 "2 GHz" : "5 GHz");
174 ret = -ENODATA;
175 goto err_out;
178 tmp->n_channels = j;
179 old = priv->band_table[band];
180 priv->band_table[band] = tmp;
181 if (old) {
182 kfree(old->channels);
183 kfree(old);
186 return 0;
188 err_out:
189 if (tmp) {
190 kfree(tmp->channels);
191 kfree(tmp);
194 return ret;
197 static void p54_update_channel_param(struct p54_channel_list *list,
198 u16 freq, u16 data)
200 int band, i;
203 * usually all lists in the eeprom are mostly sorted.
204 * so it's very likely that the entry we are looking for
205 * is right at the end of the list
207 for (i = list->entries; i >= 0; i--) {
208 if (freq == list->channels[i].freq) {
209 list->channels[i].data |= data;
210 break;
214 if ((i < 0) && (list->entries < list->max_entries)) {
215 /* entry does not exist yet. Initialize a new one. */
216 band = p54_get_band_from_freq(freq);
219 * filter out frequencies which don't belong into
220 * any supported band.
222 if (band < 0)
223 return ;
225 i = list->entries++;
226 list->band_channel_num[band]++;
228 list->channels[i].freq = freq;
229 list->channels[i].data = data;
230 list->channels[i].band = band;
231 list->channels[i].index = ieee80211_frequency_to_channel(freq);
232 /* TODO: parse output_limit and fill max_power */
236 static int p54_generate_channel_lists(struct ieee80211_hw *dev)
238 struct p54_common *priv = dev->priv;
239 struct p54_channel_list *list;
240 unsigned int i, j, max_channel_num;
241 int ret = 0;
242 u16 freq;
244 if ((priv->iq_autocal_len != priv->curve_data->entries) ||
245 (priv->iq_autocal_len != priv->output_limit->entries))
246 printk(KERN_ERR "%s: Unsupported or damaged EEPROM detected. "
247 "You may not be able to use all channels.\n",
248 wiphy_name(dev->wiphy));
250 max_channel_num = max_t(unsigned int, priv->output_limit->entries,
251 priv->iq_autocal_len);
252 max_channel_num = max_t(unsigned int, max_channel_num,
253 priv->curve_data->entries);
255 list = kzalloc(sizeof(*list), GFP_KERNEL);
256 if (!list) {
257 ret = -ENOMEM;
258 goto free;
261 list->max_entries = max_channel_num;
262 list->channels = kzalloc(sizeof(struct p54_channel_entry) *
263 max_channel_num, GFP_KERNEL);
264 if (!list->channels) {
265 ret = -ENOMEM;
266 goto free;
269 for (i = 0; i < max_channel_num; i++) {
270 if (i < priv->iq_autocal_len) {
271 freq = le16_to_cpu(priv->iq_autocal[i].freq);
272 p54_update_channel_param(list, freq, CHAN_HAS_CAL);
275 if (i < priv->output_limit->entries) {
276 freq = le16_to_cpup((__le16 *) (i *
277 priv->output_limit->entry_size +
278 priv->output_limit->offset +
279 priv->output_limit->data));
281 p54_update_channel_param(list, freq, CHAN_HAS_LIMIT);
284 if (i < priv->curve_data->entries) {
285 freq = le16_to_cpup((__le16 *) (i *
286 priv->curve_data->entry_size +
287 priv->curve_data->offset +
288 priv->curve_data->data));
290 p54_update_channel_param(list, freq, CHAN_HAS_CURVE);
294 /* sort the list by the channel index */
295 sort(list->channels, list->entries, sizeof(struct p54_channel_entry),
296 p54_compare_channels, NULL);
298 for (i = 0, j = 0; i < IEEE80211_NUM_BANDS; i++) {
299 if (p54_generate_band(dev, list, i) == 0)
300 j++;
302 if (j == 0) {
303 /* no useable band available. */
304 ret = -EINVAL;
307 free:
308 if (list) {
309 kfree(list->channels);
310 kfree(list);
313 return ret;
316 static int p54_convert_rev0(struct ieee80211_hw *dev,
317 struct pda_pa_curve_data *curve_data)
319 struct p54_common *priv = dev->priv;
320 struct p54_pa_curve_data_sample *dst;
321 struct pda_pa_curve_data_sample_rev0 *src;
322 size_t cd_len = sizeof(*curve_data) +
323 (curve_data->points_per_channel*sizeof(*dst) + 2) *
324 curve_data->channels;
325 unsigned int i, j;
326 void *source, *target;
328 priv->curve_data = kmalloc(sizeof(*priv->curve_data) + cd_len,
329 GFP_KERNEL);
330 if (!priv->curve_data)
331 return -ENOMEM;
333 priv->curve_data->entries = curve_data->channels;
334 priv->curve_data->entry_size = sizeof(__le16) +
335 sizeof(*dst) * curve_data->points_per_channel;
336 priv->curve_data->offset = offsetof(struct pda_pa_curve_data, data);
337 priv->curve_data->len = cd_len;
338 memcpy(priv->curve_data->data, curve_data, sizeof(*curve_data));
339 source = curve_data->data;
340 target = ((struct pda_pa_curve_data *) priv->curve_data->data)->data;
341 for (i = 0; i < curve_data->channels; i++) {
342 __le16 *freq = source;
343 source += sizeof(__le16);
344 *((__le16 *)target) = *freq;
345 target += sizeof(__le16);
346 for (j = 0; j < curve_data->points_per_channel; j++) {
347 dst = target;
348 src = source;
350 dst->rf_power = src->rf_power;
351 dst->pa_detector = src->pa_detector;
352 dst->data_64qam = src->pcv;
353 /* "invent" the points for the other modulations */
354 #define SUB(x, y) (u8)(((x) - (y)) > (x) ? 0 : (x) - (y))
355 dst->data_16qam = SUB(src->pcv, 12);
356 dst->data_qpsk = SUB(dst->data_16qam, 12);
357 dst->data_bpsk = SUB(dst->data_qpsk, 12);
358 dst->data_barker = SUB(dst->data_bpsk, 14);
359 #undef SUB
360 target += sizeof(*dst);
361 source += sizeof(*src);
365 return 0;
368 static int p54_convert_rev1(struct ieee80211_hw *dev,
369 struct pda_pa_curve_data *curve_data)
371 struct p54_common *priv = dev->priv;
372 struct p54_pa_curve_data_sample *dst;
373 struct pda_pa_curve_data_sample_rev1 *src;
374 size_t cd_len = sizeof(*curve_data) +
375 (curve_data->points_per_channel*sizeof(*dst) + 2) *
376 curve_data->channels;
377 unsigned int i, j;
378 void *source, *target;
380 priv->curve_data = kzalloc(cd_len + sizeof(*priv->curve_data),
381 GFP_KERNEL);
382 if (!priv->curve_data)
383 return -ENOMEM;
385 priv->curve_data->entries = curve_data->channels;
386 priv->curve_data->entry_size = sizeof(__le16) +
387 sizeof(*dst) * curve_data->points_per_channel;
388 priv->curve_data->offset = offsetof(struct pda_pa_curve_data, data);
389 priv->curve_data->len = cd_len;
390 memcpy(priv->curve_data->data, curve_data, sizeof(*curve_data));
391 source = curve_data->data;
392 target = ((struct pda_pa_curve_data *) priv->curve_data->data)->data;
393 for (i = 0; i < curve_data->channels; i++) {
394 __le16 *freq = source;
395 source += sizeof(__le16);
396 *((__le16 *)target) = *freq;
397 target += sizeof(__le16);
398 for (j = 0; j < curve_data->points_per_channel; j++) {
399 memcpy(target, source, sizeof(*src));
401 target += sizeof(*dst);
402 source += sizeof(*src);
404 source++;
407 return 0;
410 static const char *p54_rf_chips[] = { "INVALID-0", "Duette3", "Duette2",
411 "Frisbee", "Xbow", "Longbow", "INVALID-6", "INVALID-7" };
413 static void p54_parse_rssical(struct ieee80211_hw *dev, void *data, int len,
414 u16 type)
416 struct p54_common *priv = dev->priv;
417 int offset = (type == PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED) ? 2 : 0;
418 int entry_size = sizeof(struct pda_rssi_cal_entry) + offset;
419 int num_entries = (type == PDR_RSSI_LINEAR_APPROXIMATION) ? 1 : 2;
420 int i;
422 if (len != (entry_size * num_entries)) {
423 printk(KERN_ERR "%s: unknown rssi calibration data packing "
424 " type:(%x) len:%d.\n",
425 wiphy_name(dev->wiphy), type, len);
427 print_hex_dump_bytes("rssical:", DUMP_PREFIX_NONE,
428 data, len);
430 printk(KERN_ERR "%s: please report this issue.\n",
431 wiphy_name(dev->wiphy));
432 return;
435 for (i = 0; i < num_entries; i++) {
436 struct pda_rssi_cal_entry *cal = data +
437 (offset + i * entry_size);
438 priv->rssical_db[i].mul = (s16) le16_to_cpu(cal->mul);
439 priv->rssical_db[i].add = (s16) le16_to_cpu(cal->add);
443 static void p54_parse_default_country(struct ieee80211_hw *dev,
444 void *data, int len)
446 struct pda_country *country;
448 if (len != sizeof(*country)) {
449 printk(KERN_ERR "%s: found possible invalid default country "
450 "eeprom entry. (entry size: %d)\n",
451 wiphy_name(dev->wiphy), len);
453 print_hex_dump_bytes("country:", DUMP_PREFIX_NONE,
454 data, len);
456 printk(KERN_ERR "%s: please report this issue.\n",
457 wiphy_name(dev->wiphy));
458 return;
461 country = (struct pda_country *) data;
462 if (country->flags == PDR_COUNTRY_CERT_CODE_PSEUDO)
463 regulatory_hint(dev->wiphy, country->alpha2);
464 else {
465 /* TODO:
466 * write a shared/common function that converts
467 * "Regulatory domain codes" (802.11-2007 14.8.2.2)
468 * into ISO/IEC 3166-1 alpha2 for regulatory_hint.
473 static int p54_convert_output_limits(struct ieee80211_hw *dev,
474 u8 *data, size_t len)
476 struct p54_common *priv = dev->priv;
478 if (len < 2)
479 return -EINVAL;
481 if (data[0] != 0) {
482 printk(KERN_ERR "%s: unknown output power db revision:%x\n",
483 wiphy_name(dev->wiphy), data[0]);
484 return -EINVAL;
487 if (2 + data[1] * sizeof(struct pda_channel_output_limit) > len)
488 return -EINVAL;
490 priv->output_limit = kmalloc(data[1] *
491 sizeof(struct pda_channel_output_limit) +
492 sizeof(*priv->output_limit), GFP_KERNEL);
494 if (!priv->output_limit)
495 return -ENOMEM;
497 priv->output_limit->offset = 0;
498 priv->output_limit->entries = data[1];
499 priv->output_limit->entry_size =
500 sizeof(struct pda_channel_output_limit);
501 priv->output_limit->len = priv->output_limit->entry_size *
502 priv->output_limit->entries +
503 priv->output_limit->offset;
505 memcpy(priv->output_limit->data, &data[2],
506 data[1] * sizeof(struct pda_channel_output_limit));
508 return 0;
511 static struct p54_cal_database *p54_convert_db(struct pda_custom_wrapper *src,
512 size_t total_len)
514 struct p54_cal_database *dst;
515 size_t payload_len, entries, entry_size, offset;
517 payload_len = le16_to_cpu(src->len);
518 entries = le16_to_cpu(src->entries);
519 entry_size = le16_to_cpu(src->entry_size);
520 offset = le16_to_cpu(src->offset);
521 if (((entries * entry_size + offset) != payload_len) ||
522 (payload_len + sizeof(*src) != total_len))
523 return NULL;
525 dst = kmalloc(sizeof(*dst) + payload_len, GFP_KERNEL);
526 if (!dst)
527 return NULL;
529 dst->entries = entries;
530 dst->entry_size = entry_size;
531 dst->offset = offset;
532 dst->len = payload_len;
534 memcpy(dst->data, src->data, payload_len);
535 return dst;
538 int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
540 struct p54_common *priv = dev->priv;
541 struct eeprom_pda_wrap *wrap;
542 struct pda_entry *entry;
543 unsigned int data_len, entry_len;
544 void *tmp;
545 int err;
546 u8 *end = (u8 *)eeprom + len;
547 u16 synth = 0;
549 wrap = (struct eeprom_pda_wrap *) eeprom;
550 entry = (void *)wrap->data + le16_to_cpu(wrap->len);
552 /* verify that at least the entry length/code fits */
553 while ((u8 *)entry <= end - sizeof(*entry)) {
554 entry_len = le16_to_cpu(entry->len);
555 data_len = ((entry_len - 1) << 1);
557 /* abort if entry exceeds whole structure */
558 if ((u8 *)entry + sizeof(*entry) + data_len > end)
559 break;
561 switch (le16_to_cpu(entry->code)) {
562 case PDR_MAC_ADDRESS:
563 if (data_len != ETH_ALEN)
564 break;
565 SET_IEEE80211_PERM_ADDR(dev, entry->data);
566 break;
567 case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS:
568 if (priv->output_limit)
569 break;
570 err = p54_convert_output_limits(dev, entry->data,
571 data_len);
572 if (err)
573 goto err;
574 break;
575 case PDR_PRISM_PA_CAL_CURVE_DATA: {
576 struct pda_pa_curve_data *curve_data =
577 (struct pda_pa_curve_data *)entry->data;
578 if (data_len < sizeof(*curve_data)) {
579 err = -EINVAL;
580 goto err;
583 switch (curve_data->cal_method_rev) {
584 case 0:
585 err = p54_convert_rev0(dev, curve_data);
586 break;
587 case 1:
588 err = p54_convert_rev1(dev, curve_data);
589 break;
590 default:
591 printk(KERN_ERR "%s: unknown curve data "
592 "revision %d\n",
593 wiphy_name(dev->wiphy),
594 curve_data->cal_method_rev);
595 err = -ENODEV;
596 break;
598 if (err)
599 goto err;
601 break;
602 case PDR_PRISM_ZIF_TX_IQ_CALIBRATION:
603 priv->iq_autocal = kmalloc(data_len, GFP_KERNEL);
604 if (!priv->iq_autocal) {
605 err = -ENOMEM;
606 goto err;
609 memcpy(priv->iq_autocal, entry->data, data_len);
610 priv->iq_autocal_len = data_len / sizeof(struct pda_iq_autocal_entry);
611 break;
612 case PDR_DEFAULT_COUNTRY:
613 p54_parse_default_country(dev, entry->data, data_len);
614 break;
615 case PDR_INTERFACE_LIST:
616 tmp = entry->data;
617 while ((u8 *)tmp < entry->data + data_len) {
618 struct exp_if *exp_if = tmp;
619 if (exp_if->if_id == cpu_to_le16(IF_ID_ISL39000))
620 synth = le16_to_cpu(exp_if->variant);
621 tmp += sizeof(*exp_if);
623 break;
624 case PDR_HARDWARE_PLATFORM_COMPONENT_ID:
625 if (data_len < 2)
626 break;
627 priv->version = *(u8 *)(entry->data + 1);
628 break;
629 case PDR_RSSI_LINEAR_APPROXIMATION:
630 case PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND:
631 case PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED:
632 p54_parse_rssical(dev, entry->data, data_len,
633 le16_to_cpu(entry->code));
634 break;
635 case PDR_RSSI_LINEAR_APPROXIMATION_CUSTOM: {
636 __le16 *src = (void *) entry->data;
637 s16 *dst = (void *) &priv->rssical_db;
638 int i;
640 if (data_len != sizeof(priv->rssical_db)) {
641 err = -EINVAL;
642 goto err;
644 for (i = 0; i < sizeof(priv->rssical_db) /
645 sizeof(*src); i++)
646 *(dst++) = (s16) le16_to_cpu(*(src++));
648 break;
649 case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS_CUSTOM: {
650 struct pda_custom_wrapper *pda = (void *) entry->data;
651 if (priv->output_limit || data_len < sizeof(*pda))
652 break;
653 priv->output_limit = p54_convert_db(pda, data_len);
655 break;
656 case PDR_PRISM_PA_CAL_CURVE_DATA_CUSTOM: {
657 struct pda_custom_wrapper *pda = (void *) entry->data;
658 if (priv->curve_data || data_len < sizeof(*pda))
659 break;
660 priv->curve_data = p54_convert_db(pda, data_len);
662 break;
663 case PDR_END:
664 /* make it overrun */
665 entry_len = len;
666 break;
667 default:
668 break;
671 entry = (void *)entry + (entry_len + 1)*2;
674 if (!synth || !priv->iq_autocal || !priv->output_limit ||
675 !priv->curve_data) {
676 printk(KERN_ERR "%s: not all required entries found in eeprom!\n",
677 wiphy_name(dev->wiphy));
678 err = -EINVAL;
679 goto err;
682 err = p54_generate_channel_lists(dev);
683 if (err)
684 goto err;
686 priv->rxhw = synth & PDR_SYNTH_FRONTEND_MASK;
687 if (priv->rxhw == PDR_SYNTH_FRONTEND_XBOW)
688 p54_init_xbow_synth(priv);
689 if (!(synth & PDR_SYNTH_24_GHZ_DISABLED))
690 dev->wiphy->bands[IEEE80211_BAND_2GHZ] =
691 priv->band_table[IEEE80211_BAND_2GHZ];
692 if (!(synth & PDR_SYNTH_5_GHZ_DISABLED))
693 dev->wiphy->bands[IEEE80211_BAND_5GHZ] =
694 priv->band_table[IEEE80211_BAND_5GHZ];
695 if ((synth & PDR_SYNTH_RX_DIV_MASK) == PDR_SYNTH_RX_DIV_SUPPORTED)
696 priv->rx_diversity_mask = 3;
697 if ((synth & PDR_SYNTH_TX_DIV_MASK) == PDR_SYNTH_TX_DIV_SUPPORTED)
698 priv->tx_diversity_mask = 3;
700 if (!is_valid_ether_addr(dev->wiphy->perm_addr)) {
701 u8 perm_addr[ETH_ALEN];
703 printk(KERN_WARNING "%s: Invalid hwaddr! Using randomly generated MAC addr\n",
704 wiphy_name(dev->wiphy));
705 random_ether_addr(perm_addr);
706 SET_IEEE80211_PERM_ADDR(dev, perm_addr);
709 printk(KERN_INFO "%s: hwaddr %pM, MAC:isl38%02x RF:%s\n",
710 wiphy_name(dev->wiphy), dev->wiphy->perm_addr, priv->version,
711 p54_rf_chips[priv->rxhw]);
713 return 0;
715 err:
716 kfree(priv->iq_autocal);
717 kfree(priv->output_limit);
718 kfree(priv->curve_data);
719 priv->iq_autocal = NULL;
720 priv->output_limit = NULL;
721 priv->curve_data = NULL;
723 printk(KERN_ERR "%s: eeprom parse failed!\n",
724 wiphy_name(dev->wiphy));
725 return err;
727 EXPORT_SYMBOL_GPL(p54_parse_eeprom);
729 int p54_read_eeprom(struct ieee80211_hw *dev)
731 struct p54_common *priv = dev->priv;
732 size_t eeprom_size = 0x2020, offset = 0, blocksize, maxblocksize;
733 int ret = -ENOMEM;
734 void *eeprom;
736 maxblocksize = EEPROM_READBACK_LEN;
737 if (priv->fw_var >= 0x509)
738 maxblocksize -= 0xc;
739 else
740 maxblocksize -= 0x4;
742 eeprom = kzalloc(eeprom_size, GFP_KERNEL);
743 if (unlikely(!eeprom))
744 goto free;
746 while (eeprom_size) {
747 blocksize = min(eeprom_size, maxblocksize);
748 ret = p54_download_eeprom(priv, (void *) (eeprom + offset),
749 offset, blocksize);
750 if (unlikely(ret))
751 goto free;
753 offset += blocksize;
754 eeprom_size -= blocksize;
757 ret = p54_parse_eeprom(dev, eeprom, offset);
758 free:
759 kfree(eeprom);
760 return ret;
762 EXPORT_SYMBOL_GPL(p54_read_eeprom);