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>
9 * - the islsm (softmac prism54) driver, which is:
10 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
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>
23 #include <linux/slab.h>
25 #include <net/mac80211.h>
26 #include <linux/crc-ccitt.h>
32 static struct ieee80211_rate p54_bgrates
[] = {
33 { .bitrate
= 10, .hw_value
= 0, },
34 { .bitrate
= 20, .hw_value
= 1, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
35 { .bitrate
= 55, .hw_value
= 2, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
36 { .bitrate
= 110, .hw_value
= 3, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
37 { .bitrate
= 60, .hw_value
= 4, },
38 { .bitrate
= 90, .hw_value
= 5, },
39 { .bitrate
= 120, .hw_value
= 6, },
40 { .bitrate
= 180, .hw_value
= 7, },
41 { .bitrate
= 240, .hw_value
= 8, },
42 { .bitrate
= 360, .hw_value
= 9, },
43 { .bitrate
= 480, .hw_value
= 10, },
44 { .bitrate
= 540, .hw_value
= 11, },
47 static struct ieee80211_rate p54_arates
[] = {
48 { .bitrate
= 60, .hw_value
= 4, },
49 { .bitrate
= 90, .hw_value
= 5, },
50 { .bitrate
= 120, .hw_value
= 6, },
51 { .bitrate
= 180, .hw_value
= 7, },
52 { .bitrate
= 240, .hw_value
= 8, },
53 { .bitrate
= 360, .hw_value
= 9, },
54 { .bitrate
= 480, .hw_value
= 10, },
55 { .bitrate
= 540, .hw_value
= 11, },
58 static struct p54_rssi_db_entry p54_rssi_default
= {
60 * The defaults are taken from usb-logs of the
61 * vendor driver. So, they should be safe to
62 * use in case we can't get a match from the
63 * rssi <-> dBm conversion database.
69 #define CHAN_HAS_CAL BIT(0)
70 #define CHAN_HAS_LIMIT BIT(1)
71 #define CHAN_HAS_CURVE BIT(2)
72 #define CHAN_HAS_ALL (CHAN_HAS_CAL | CHAN_HAS_LIMIT | CHAN_HAS_CURVE)
74 struct p54_channel_entry
{
78 enum ieee80211_band band
;
81 struct p54_channel_list
{
82 struct p54_channel_entry
*channels
;
85 size_t band_channel_num
[IEEE80211_NUM_BANDS
];
88 static int p54_get_band_from_freq(u16 freq
)
90 /* FIXME: sync these values with the 802.11 spec */
92 if ((freq
>= 2412) && (freq
<= 2484))
93 return IEEE80211_BAND_2GHZ
;
95 if ((freq
>= 4920) && (freq
<= 5825))
96 return IEEE80211_BAND_5GHZ
;
101 static int same_band(u16 freq
, u16 freq2
)
103 return p54_get_band_from_freq(freq
) == p54_get_band_from_freq(freq2
);
106 static int p54_compare_channels(const void *_a
,
109 const struct p54_channel_entry
*a
= _a
;
110 const struct p54_channel_entry
*b
= _b
;
112 return a
->freq
- b
->freq
;
115 static int p54_compare_rssichan(const void *_a
,
118 const struct p54_rssi_db_entry
*a
= _a
;
119 const struct p54_rssi_db_entry
*b
= _b
;
121 return a
->freq
- b
->freq
;
124 static int p54_fill_band_bitrates(struct ieee80211_hw
*dev
,
125 struct ieee80211_supported_band
*band_entry
,
126 enum ieee80211_band band
)
128 /* TODO: generate rate array dynamically */
131 case IEEE80211_BAND_2GHZ
:
132 band_entry
->bitrates
= p54_bgrates
;
133 band_entry
->n_bitrates
= ARRAY_SIZE(p54_bgrates
);
135 case IEEE80211_BAND_5GHZ
:
136 band_entry
->bitrates
= p54_arates
;
137 band_entry
->n_bitrates
= ARRAY_SIZE(p54_arates
);
146 static int p54_generate_band(struct ieee80211_hw
*dev
,
147 struct p54_channel_list
*list
,
148 unsigned int *chan_num
,
149 enum ieee80211_band band
)
151 struct p54_common
*priv
= dev
->priv
;
152 struct ieee80211_supported_band
*tmp
, *old
;
156 if ((!list
->entries
) || (!list
->band_channel_num
[band
]))
159 tmp
= kzalloc(sizeof(*tmp
), GFP_KERNEL
);
163 tmp
->channels
= kzalloc(sizeof(struct ieee80211_channel
) *
164 list
->band_channel_num
[band
], GFP_KERNEL
);
168 ret
= p54_fill_band_bitrates(dev
, tmp
, band
);
172 for (i
= 0, j
= 0; (j
< list
->band_channel_num
[band
]) &&
173 (i
< list
->entries
); i
++) {
174 struct p54_channel_entry
*chan
= &list
->channels
[i
];
176 if (chan
->band
!= band
)
179 if (chan
->data
!= CHAN_HAS_ALL
) {
180 wiphy_err(dev
->wiphy
, "%s%s%s is/are missing for "
181 "channel:%d [%d MHz].\n",
182 (chan
->data
& CHAN_HAS_CAL
? "" :
183 " [iqauto calibration data]"),
184 (chan
->data
& CHAN_HAS_LIMIT
? "" :
185 " [output power limits]"),
186 (chan
->data
& CHAN_HAS_CURVE
? "" :
188 chan
->index
, chan
->freq
);
192 tmp
->channels
[j
].band
= chan
->band
;
193 tmp
->channels
[j
].center_freq
= chan
->freq
;
194 priv
->survey
[*chan_num
].channel
= &tmp
->channels
[j
];
195 priv
->survey
[*chan_num
].filled
= SURVEY_INFO_NOISE_DBM
|
196 SURVEY_INFO_CHANNEL_TIME
|
197 SURVEY_INFO_CHANNEL_TIME_BUSY
|
198 SURVEY_INFO_CHANNEL_TIME_TX
;
199 tmp
->channels
[j
].hw_value
= (*chan_num
);
205 wiphy_err(dev
->wiphy
, "Disabling totally damaged %d GHz band\n",
206 (band
== IEEE80211_BAND_2GHZ
) ? 2 : 5);
213 old
= priv
->band_table
[band
];
214 priv
->band_table
[band
] = tmp
;
216 kfree(old
->channels
);
224 kfree(tmp
->channels
);
231 static void p54_update_channel_param(struct p54_channel_list
*list
,
237 * usually all lists in the eeprom are mostly sorted.
238 * so it's very likely that the entry we are looking for
239 * is right at the end of the list
241 for (i
= list
->entries
; i
>= 0; i
--) {
242 if (freq
== list
->channels
[i
].freq
) {
243 list
->channels
[i
].data
|= data
;
248 if ((i
< 0) && (list
->entries
< list
->max_entries
)) {
249 /* entry does not exist yet. Initialize a new one. */
250 band
= p54_get_band_from_freq(freq
);
253 * filter out frequencies which don't belong into
254 * any supported band.
260 list
->band_channel_num
[band
]++;
262 list
->channels
[i
].freq
= freq
;
263 list
->channels
[i
].data
= data
;
264 list
->channels
[i
].band
= band
;
265 list
->channels
[i
].index
= ieee80211_frequency_to_channel(freq
);
266 /* TODO: parse output_limit and fill max_power */
270 static int p54_generate_channel_lists(struct ieee80211_hw
*dev
)
272 struct p54_common
*priv
= dev
->priv
;
273 struct p54_channel_list
*list
;
274 unsigned int i
, j
, k
, max_channel_num
;
278 if ((priv
->iq_autocal_len
!= priv
->curve_data
->entries
) ||
279 (priv
->iq_autocal_len
!= priv
->output_limit
->entries
))
280 wiphy_err(dev
->wiphy
,
281 "Unsupported or damaged EEPROM detected. "
282 "You may not be able to use all channels.\n");
284 max_channel_num
= max_t(unsigned int, priv
->output_limit
->entries
,
285 priv
->iq_autocal_len
);
286 max_channel_num
= max_t(unsigned int, max_channel_num
,
287 priv
->curve_data
->entries
);
289 list
= kzalloc(sizeof(*list
), GFP_KERNEL
);
294 priv
->chan_num
= max_channel_num
;
295 priv
->survey
= kzalloc(sizeof(struct survey_info
) * max_channel_num
,
302 list
->max_entries
= max_channel_num
;
303 list
->channels
= kzalloc(sizeof(struct p54_channel_entry
) *
304 max_channel_num
, GFP_KERNEL
);
305 if (!list
->channels
) {
310 for (i
= 0; i
< max_channel_num
; i
++) {
311 if (i
< priv
->iq_autocal_len
) {
312 freq
= le16_to_cpu(priv
->iq_autocal
[i
].freq
);
313 p54_update_channel_param(list
, freq
, CHAN_HAS_CAL
);
316 if (i
< priv
->output_limit
->entries
) {
317 freq
= le16_to_cpup((__le16
*) (i
*
318 priv
->output_limit
->entry_size
+
319 priv
->output_limit
->offset
+
320 priv
->output_limit
->data
));
322 p54_update_channel_param(list
, freq
, CHAN_HAS_LIMIT
);
325 if (i
< priv
->curve_data
->entries
) {
326 freq
= le16_to_cpup((__le16
*) (i
*
327 priv
->curve_data
->entry_size
+
328 priv
->curve_data
->offset
+
329 priv
->curve_data
->data
));
331 p54_update_channel_param(list
, freq
, CHAN_HAS_CURVE
);
335 /* sort the channel list by frequency */
336 sort(list
->channels
, list
->entries
, sizeof(struct p54_channel_entry
),
337 p54_compare_channels
, NULL
);
340 for (i
= 0, j
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
341 if (p54_generate_band(dev
, list
, &k
, i
) == 0)
345 /* no useable band available. */
351 kfree(list
->channels
);
362 static int p54_convert_rev0(struct ieee80211_hw
*dev
,
363 struct pda_pa_curve_data
*curve_data
)
365 struct p54_common
*priv
= dev
->priv
;
366 struct p54_pa_curve_data_sample
*dst
;
367 struct pda_pa_curve_data_sample_rev0
*src
;
368 size_t cd_len
= sizeof(*curve_data
) +
369 (curve_data
->points_per_channel
*sizeof(*dst
) + 2) *
370 curve_data
->channels
;
372 void *source
, *target
;
374 priv
->curve_data
= kmalloc(sizeof(*priv
->curve_data
) + cd_len
,
376 if (!priv
->curve_data
)
379 priv
->curve_data
->entries
= curve_data
->channels
;
380 priv
->curve_data
->entry_size
= sizeof(__le16
) +
381 sizeof(*dst
) * curve_data
->points_per_channel
;
382 priv
->curve_data
->offset
= offsetof(struct pda_pa_curve_data
, data
);
383 priv
->curve_data
->len
= cd_len
;
384 memcpy(priv
->curve_data
->data
, curve_data
, sizeof(*curve_data
));
385 source
= curve_data
->data
;
386 target
= ((struct pda_pa_curve_data
*) priv
->curve_data
->data
)->data
;
387 for (i
= 0; i
< curve_data
->channels
; i
++) {
388 __le16
*freq
= source
;
389 source
+= sizeof(__le16
);
390 *((__le16
*)target
) = *freq
;
391 target
+= sizeof(__le16
);
392 for (j
= 0; j
< curve_data
->points_per_channel
; j
++) {
396 dst
->rf_power
= src
->rf_power
;
397 dst
->pa_detector
= src
->pa_detector
;
398 dst
->data_64qam
= src
->pcv
;
399 /* "invent" the points for the other modulations */
400 #define SUB(x, y) (u8)(((x) - (y)) > (x) ? 0 : (x) - (y))
401 dst
->data_16qam
= SUB(src
->pcv
, 12);
402 dst
->data_qpsk
= SUB(dst
->data_16qam
, 12);
403 dst
->data_bpsk
= SUB(dst
->data_qpsk
, 12);
404 dst
->data_barker
= SUB(dst
->data_bpsk
, 14);
406 target
+= sizeof(*dst
);
407 source
+= sizeof(*src
);
414 static int p54_convert_rev1(struct ieee80211_hw
*dev
,
415 struct pda_pa_curve_data
*curve_data
)
417 struct p54_common
*priv
= dev
->priv
;
418 struct p54_pa_curve_data_sample
*dst
;
419 struct pda_pa_curve_data_sample_rev1
*src
;
420 size_t cd_len
= sizeof(*curve_data
) +
421 (curve_data
->points_per_channel
*sizeof(*dst
) + 2) *
422 curve_data
->channels
;
424 void *source
, *target
;
426 priv
->curve_data
= kzalloc(cd_len
+ sizeof(*priv
->curve_data
),
428 if (!priv
->curve_data
)
431 priv
->curve_data
->entries
= curve_data
->channels
;
432 priv
->curve_data
->entry_size
= sizeof(__le16
) +
433 sizeof(*dst
) * curve_data
->points_per_channel
;
434 priv
->curve_data
->offset
= offsetof(struct pda_pa_curve_data
, data
);
435 priv
->curve_data
->len
= cd_len
;
436 memcpy(priv
->curve_data
->data
, curve_data
, sizeof(*curve_data
));
437 source
= curve_data
->data
;
438 target
= ((struct pda_pa_curve_data
*) priv
->curve_data
->data
)->data
;
439 for (i
= 0; i
< curve_data
->channels
; i
++) {
440 __le16
*freq
= source
;
441 source
+= sizeof(__le16
);
442 *((__le16
*)target
) = *freq
;
443 target
+= sizeof(__le16
);
444 for (j
= 0; j
< curve_data
->points_per_channel
; j
++) {
445 memcpy(target
, source
, sizeof(*src
));
447 target
+= sizeof(*dst
);
448 source
+= sizeof(*src
);
456 static const char *p54_rf_chips
[] = { "INVALID-0", "Duette3", "Duette2",
457 "Frisbee", "Xbow", "Longbow", "INVALID-6", "INVALID-7" };
459 static int p54_parse_rssical(struct ieee80211_hw
*dev
,
460 u8
*data
, int len
, u16 type
)
462 struct p54_common
*priv
= dev
->priv
;
463 struct p54_rssi_db_entry
*entry
;
464 size_t db_len
, entries
;
467 if (type
!= PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED
) {
468 entries
= (type
== PDR_RSSI_LINEAR_APPROXIMATION
) ? 1 : 2;
469 if (len
!= sizeof(struct pda_rssi_cal_entry
) * entries
) {
470 wiphy_err(dev
->wiphy
, "rssical size mismatch.\n");
475 * Some devices (Dell 1450 USB, Xbow 5GHz card, etc...)
476 * have an empty two byte header.
478 if (*((__le16
*)&data
[offset
]) == cpu_to_le16(0))
481 entries
= (len
- offset
) /
482 sizeof(struct pda_rssi_cal_ext_entry
);
484 if ((len
- offset
) % sizeof(struct pda_rssi_cal_ext_entry
) ||
486 wiphy_err(dev
->wiphy
, "invalid rssi database.\n");
491 db_len
= sizeof(*entry
) * entries
;
492 priv
->rssi_db
= kzalloc(db_len
+ sizeof(*priv
->rssi_db
), GFP_KERNEL
);
496 priv
->rssi_db
->offset
= 0;
497 priv
->rssi_db
->entries
= entries
;
498 priv
->rssi_db
->entry_size
= sizeof(*entry
);
499 priv
->rssi_db
->len
= db_len
;
501 entry
= (void *)((unsigned long)priv
->rssi_db
->data
+ priv
->rssi_db
->offset
);
502 if (type
== PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED
) {
503 struct pda_rssi_cal_ext_entry
*cal
= (void *) &data
[offset
];
505 for (i
= 0; i
< entries
; i
++) {
506 entry
[i
].freq
= le16_to_cpu(cal
[i
].freq
);
507 entry
[i
].mul
= (s16
) le16_to_cpu(cal
[i
].mul
);
508 entry
[i
].add
= (s16
) le16_to_cpu(cal
[i
].add
);
511 struct pda_rssi_cal_entry
*cal
= (void *) &data
[offset
];
513 for (i
= 0; i
< entries
; i
++) {
516 case IEEE80211_BAND_2GHZ
:
519 case IEEE80211_BAND_5GHZ
:
524 entry
[i
].freq
= freq
;
525 entry
[i
].mul
= (s16
) le16_to_cpu(cal
[i
].mul
);
526 entry
[i
].add
= (s16
) le16_to_cpu(cal
[i
].add
);
530 /* sort the list by channel frequency */
531 sort(entry
, entries
, sizeof(*entry
), p54_compare_rssichan
, NULL
);
535 wiphy_err(dev
->wiphy
,
536 "rssi calibration data packing type:(%x) len:%d.\n",
539 print_hex_dump_bytes("rssical:", DUMP_PREFIX_NONE
, data
, len
);
541 wiphy_err(dev
->wiphy
, "please report this issue.\n");
545 struct p54_rssi_db_entry
*p54_rssi_find(struct p54_common
*priv
, const u16 freq
)
547 struct p54_rssi_db_entry
*entry
;
551 return &p54_rssi_default
;
553 entry
= (void *)(priv
->rssi_db
->data
+ priv
->rssi_db
->offset
);
554 for (i
= 0; i
< priv
->rssi_db
->entries
; i
++) {
555 if (!same_band(freq
, entry
[i
].freq
))
564 if (abs(freq
- entry
[i
].freq
) <
565 abs(freq
- entry
[found
].freq
)) {
573 return found
< 0 ? &p54_rssi_default
: &entry
[found
];
576 static void p54_parse_default_country(struct ieee80211_hw
*dev
,
579 struct pda_country
*country
;
581 if (len
!= sizeof(*country
)) {
582 wiphy_err(dev
->wiphy
,
583 "found possible invalid default country eeprom entry. (entry size: %d)\n",
586 print_hex_dump_bytes("country:", DUMP_PREFIX_NONE
,
589 wiphy_err(dev
->wiphy
, "please report this issue.\n");
593 country
= (struct pda_country
*) data
;
594 if (country
->flags
== PDR_COUNTRY_CERT_CODE_PSEUDO
)
595 regulatory_hint(dev
->wiphy
, country
->alpha2
);
598 * write a shared/common function that converts
599 * "Regulatory domain codes" (802.11-2007 14.8.2.2)
600 * into ISO/IEC 3166-1 alpha2 for regulatory_hint.
605 static int p54_convert_output_limits(struct ieee80211_hw
*dev
,
606 u8
*data
, size_t len
)
608 struct p54_common
*priv
= dev
->priv
;
614 wiphy_err(dev
->wiphy
, "unknown output power db revision:%x\n",
619 if (2 + data
[1] * sizeof(struct pda_channel_output_limit
) > len
)
622 priv
->output_limit
= kmalloc(data
[1] *
623 sizeof(struct pda_channel_output_limit
) +
624 sizeof(*priv
->output_limit
), GFP_KERNEL
);
626 if (!priv
->output_limit
)
629 priv
->output_limit
->offset
= 0;
630 priv
->output_limit
->entries
= data
[1];
631 priv
->output_limit
->entry_size
=
632 sizeof(struct pda_channel_output_limit
);
633 priv
->output_limit
->len
= priv
->output_limit
->entry_size
*
634 priv
->output_limit
->entries
+
635 priv
->output_limit
->offset
;
637 memcpy(priv
->output_limit
->data
, &data
[2],
638 data
[1] * sizeof(struct pda_channel_output_limit
));
643 static struct p54_cal_database
*p54_convert_db(struct pda_custom_wrapper
*src
,
646 struct p54_cal_database
*dst
;
647 size_t payload_len
, entries
, entry_size
, offset
;
649 payload_len
= le16_to_cpu(src
->len
);
650 entries
= le16_to_cpu(src
->entries
);
651 entry_size
= le16_to_cpu(src
->entry_size
);
652 offset
= le16_to_cpu(src
->offset
);
653 if (((entries
* entry_size
+ offset
) != payload_len
) ||
654 (payload_len
+ sizeof(*src
) != total_len
))
657 dst
= kmalloc(sizeof(*dst
) + payload_len
, GFP_KERNEL
);
661 dst
->entries
= entries
;
662 dst
->entry_size
= entry_size
;
663 dst
->offset
= offset
;
664 dst
->len
= payload_len
;
666 memcpy(dst
->data
, src
->data
, payload_len
);
670 int p54_parse_eeprom(struct ieee80211_hw
*dev
, void *eeprom
, int len
)
672 struct p54_common
*priv
= dev
->priv
;
673 struct eeprom_pda_wrap
*wrap
;
674 struct pda_entry
*entry
;
675 unsigned int data_len
, entry_len
;
678 u8
*end
= (u8
*)eeprom
+ len
;
682 wrap
= (struct eeprom_pda_wrap
*) eeprom
;
683 entry
= (void *)wrap
->data
+ le16_to_cpu(wrap
->len
);
685 /* verify that at least the entry length/code fits */
686 while ((u8
*)entry
<= end
- sizeof(*entry
)) {
687 entry_len
= le16_to_cpu(entry
->len
);
688 data_len
= ((entry_len
- 1) << 1);
690 /* abort if entry exceeds whole structure */
691 if ((u8
*)entry
+ sizeof(*entry
) + data_len
> end
)
694 switch (le16_to_cpu(entry
->code
)) {
695 case PDR_MAC_ADDRESS
:
696 if (data_len
!= ETH_ALEN
)
698 SET_IEEE80211_PERM_ADDR(dev
, entry
->data
);
700 case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS
:
701 if (priv
->output_limit
)
703 err
= p54_convert_output_limits(dev
, entry
->data
,
708 case PDR_PRISM_PA_CAL_CURVE_DATA
: {
709 struct pda_pa_curve_data
*curve_data
=
710 (struct pda_pa_curve_data
*)entry
->data
;
711 if (data_len
< sizeof(*curve_data
)) {
716 switch (curve_data
->cal_method_rev
) {
718 err
= p54_convert_rev0(dev
, curve_data
);
721 err
= p54_convert_rev1(dev
, curve_data
);
724 wiphy_err(dev
->wiphy
,
725 "unknown curve data revision %d\n",
726 curve_data
->cal_method_rev
);
734 case PDR_PRISM_ZIF_TX_IQ_CALIBRATION
:
735 priv
->iq_autocal
= kmemdup(entry
->data
, data_len
,
737 if (!priv
->iq_autocal
) {
742 priv
->iq_autocal_len
= data_len
/ sizeof(struct pda_iq_autocal_entry
);
744 case PDR_DEFAULT_COUNTRY
:
745 p54_parse_default_country(dev
, entry
->data
, data_len
);
747 case PDR_INTERFACE_LIST
:
749 while ((u8
*)tmp
< entry
->data
+ data_len
) {
750 struct exp_if
*exp_if
= tmp
;
751 if (exp_if
->if_id
== cpu_to_le16(IF_ID_ISL39000
))
752 synth
= le16_to_cpu(exp_if
->variant
);
753 tmp
+= sizeof(*exp_if
);
756 case PDR_HARDWARE_PLATFORM_COMPONENT_ID
:
759 priv
->version
= *(u8
*)(entry
->data
+ 1);
761 case PDR_RSSI_LINEAR_APPROXIMATION
:
762 case PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND
:
763 case PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED
:
764 err
= p54_parse_rssical(dev
, entry
->data
, data_len
,
765 le16_to_cpu(entry
->code
));
769 case PDR_RSSI_LINEAR_APPROXIMATION_CUSTOMV2
: {
770 struct pda_custom_wrapper
*pda
= (void *) entry
->data
;
775 if (priv
->rssi_db
|| data_len
< sizeof(*pda
))
778 priv
->rssi_db
= p54_convert_db(pda
, data_len
);
782 src
= (void *) priv
->rssi_db
->data
;
783 dst
= (void *) priv
->rssi_db
->data
;
785 for (i
= 0; i
< priv
->rssi_db
->entries
; i
++)
786 *(dst
++) = (s16
) le16_to_cpu(*(src
++));
790 case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS_CUSTOM
: {
791 struct pda_custom_wrapper
*pda
= (void *) entry
->data
;
792 if (priv
->output_limit
|| data_len
< sizeof(*pda
))
794 priv
->output_limit
= p54_convert_db(pda
, data_len
);
797 case PDR_PRISM_PA_CAL_CURVE_DATA_CUSTOM
: {
798 struct pda_custom_wrapper
*pda
= (void *) entry
->data
;
799 if (priv
->curve_data
|| data_len
< sizeof(*pda
))
801 priv
->curve_data
= p54_convert_db(pda
, data_len
);
805 crc16
= ~crc_ccitt(crc16
, (u8
*) entry
, sizeof(*entry
));
806 if (crc16
!= le16_to_cpup((__le16
*)entry
->data
)) {
807 wiphy_err(dev
->wiphy
, "eeprom failed checksum "
819 crc16
= crc_ccitt(crc16
, (u8
*)entry
, (entry_len
+ 1) * 2);
820 entry
= (void *)entry
+ (entry_len
+ 1) * 2;
823 wiphy_err(dev
->wiphy
, "unexpected end of eeprom data.\n");
828 if (!synth
|| !priv
->iq_autocal
|| !priv
->output_limit
||
830 wiphy_err(dev
->wiphy
,
831 "not all required entries found in eeprom!\n");
836 err
= p54_generate_channel_lists(dev
);
840 priv
->rxhw
= synth
& PDR_SYNTH_FRONTEND_MASK
;
841 if (priv
->rxhw
== PDR_SYNTH_FRONTEND_XBOW
)
842 p54_init_xbow_synth(priv
);
843 if (!(synth
& PDR_SYNTH_24_GHZ_DISABLED
))
844 dev
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
845 priv
->band_table
[IEEE80211_BAND_2GHZ
];
846 if (!(synth
& PDR_SYNTH_5_GHZ_DISABLED
))
847 dev
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
848 priv
->band_table
[IEEE80211_BAND_5GHZ
];
849 if ((synth
& PDR_SYNTH_RX_DIV_MASK
) == PDR_SYNTH_RX_DIV_SUPPORTED
)
850 priv
->rx_diversity_mask
= 3;
851 if ((synth
& PDR_SYNTH_TX_DIV_MASK
) == PDR_SYNTH_TX_DIV_SUPPORTED
)
852 priv
->tx_diversity_mask
= 3;
854 if (!is_valid_ether_addr(dev
->wiphy
->perm_addr
)) {
855 u8 perm_addr
[ETH_ALEN
];
857 wiphy_warn(dev
->wiphy
,
858 "Invalid hwaddr! Using randomly generated MAC addr\n");
859 random_ether_addr(perm_addr
);
860 SET_IEEE80211_PERM_ADDR(dev
, perm_addr
);
863 priv
->cur_rssi
= &p54_rssi_default
;
865 wiphy_info(dev
->wiphy
, "hwaddr %pM, MAC:isl38%02x RF:%s\n",
866 dev
->wiphy
->perm_addr
, priv
->version
,
867 p54_rf_chips
[priv
->rxhw
]);
872 kfree(priv
->iq_autocal
);
873 kfree(priv
->output_limit
);
874 kfree(priv
->curve_data
);
875 kfree(priv
->rssi_db
);
877 priv
->iq_autocal
= NULL
;
878 priv
->output_limit
= NULL
;
879 priv
->curve_data
= NULL
;
880 priv
->rssi_db
= NULL
;
883 wiphy_err(dev
->wiphy
, "eeprom parse failed!\n");
886 EXPORT_SYMBOL_GPL(p54_parse_eeprom
);
888 int p54_read_eeprom(struct ieee80211_hw
*dev
)
890 struct p54_common
*priv
= dev
->priv
;
891 size_t eeprom_size
= 0x2020, offset
= 0, blocksize
, maxblocksize
;
895 maxblocksize
= EEPROM_READBACK_LEN
;
896 if (priv
->fw_var
>= 0x509)
901 eeprom
= kzalloc(eeprom_size
, GFP_KERNEL
);
902 if (unlikely(!eeprom
))
905 while (eeprom_size
) {
906 blocksize
= min(eeprom_size
, maxblocksize
);
907 ret
= p54_download_eeprom(priv
, (void *) (eeprom
+ offset
),
913 eeprom_size
-= blocksize
;
916 ret
= p54_parse_eeprom(dev
, eeprom
, offset
);
921 EXPORT_SYMBOL_GPL(p54_read_eeprom
);