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/firmware.h>
20 #include <linux/etherdevice.h>
21 #include <linux/sort.h>
22 #include <linux/slab.h>
24 #include <net/mac80211.h>
25 #include <linux/crc-ccitt.h>
26 #include <linux/export.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
{
79 enum nl80211_band band
;
82 struct p54_channel_list
{
83 struct p54_channel_entry
*channels
;
86 size_t band_channel_num
[NUM_NL80211_BANDS
];
89 static int p54_get_band_from_freq(u16 freq
)
91 /* FIXME: sync these values with the 802.11 spec */
93 if ((freq
>= 2412) && (freq
<= 2484))
94 return NL80211_BAND_2GHZ
;
96 if ((freq
>= 4920) && (freq
<= 5825))
97 return NL80211_BAND_5GHZ
;
102 static int same_band(u16 freq
, u16 freq2
)
104 return p54_get_band_from_freq(freq
) == p54_get_band_from_freq(freq2
);
107 static int p54_compare_channels(const void *_a
,
110 const struct p54_channel_entry
*a
= _a
;
111 const struct p54_channel_entry
*b
= _b
;
113 return a
->freq
- b
->freq
;
116 static int p54_compare_rssichan(const void *_a
,
119 const struct p54_rssi_db_entry
*a
= _a
;
120 const struct p54_rssi_db_entry
*b
= _b
;
122 return a
->freq
- b
->freq
;
125 static int p54_fill_band_bitrates(struct ieee80211_hw
*dev
,
126 struct ieee80211_supported_band
*band_entry
,
127 enum nl80211_band band
)
129 /* TODO: generate rate array dynamically */
132 case NL80211_BAND_2GHZ
:
133 band_entry
->bitrates
= p54_bgrates
;
134 band_entry
->n_bitrates
= ARRAY_SIZE(p54_bgrates
);
136 case NL80211_BAND_5GHZ
:
137 band_entry
->bitrates
= p54_arates
;
138 band_entry
->n_bitrates
= ARRAY_SIZE(p54_arates
);
147 static int p54_generate_band(struct ieee80211_hw
*dev
,
148 struct p54_channel_list
*list
,
149 unsigned int *chan_num
,
150 enum nl80211_band band
)
152 struct p54_common
*priv
= dev
->priv
;
153 struct ieee80211_supported_band
*tmp
, *old
;
157 if ((!list
->entries
) || (!list
->band_channel_num
[band
]))
160 tmp
= kzalloc(sizeof(*tmp
), GFP_KERNEL
);
164 tmp
->channels
= kcalloc(list
->band_channel_num
[band
],
165 sizeof(struct ieee80211_channel
),
170 ret
= p54_fill_band_bitrates(dev
, tmp
, band
);
174 for (i
= 0, j
= 0; (j
< list
->band_channel_num
[band
]) &&
175 (i
< list
->entries
); i
++) {
176 struct p54_channel_entry
*chan
= &list
->channels
[i
];
177 struct ieee80211_channel
*dest
= &tmp
->channels
[j
];
179 if (chan
->band
!= band
)
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
? "" :
186 " [iqauto calibration data]"),
187 (chan
->data
& CHAN_HAS_LIMIT
? "" :
188 " [output power limits]"),
189 (chan
->data
& CHAN_HAS_CURVE
? "" :
191 chan
->index
, chan
->freq
);
195 dest
->band
= chan
->band
;
196 dest
->center_freq
= chan
->freq
;
197 dest
->max_power
= chan
->max_power
;
198 priv
->survey
[*chan_num
].channel
= &tmp
->channels
[j
];
199 priv
->survey
[*chan_num
].filled
= SURVEY_INFO_NOISE_DBM
|
201 SURVEY_INFO_TIME_BUSY
|
203 dest
->hw_value
= (*chan_num
);
209 wiphy_err(dev
->wiphy
, "Disabling totally damaged %d GHz band\n",
210 (band
== NL80211_BAND_2GHZ
) ? 2 : 5);
217 old
= priv
->band_table
[band
];
218 priv
->band_table
[band
] = tmp
;
220 kfree(old
->channels
);
228 kfree(tmp
->channels
);
235 static struct p54_channel_entry
*p54_update_channel_param(struct p54_channel_list
*list
,
239 struct p54_channel_entry
*entry
= NULL
;
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
246 for (i
= list
->entries
; i
>= 0; i
--) {
247 if (freq
== list
->channels
[i
].freq
) {
248 entry
= &list
->channels
[i
];
253 if ((i
< 0) && (list
->entries
< list
->max_entries
)) {
254 /* entry does not exist yet. Initialize a new one. */
255 int band
= p54_get_band_from_freq(freq
);
258 * filter out frequencies which don't belong into
259 * any supported band.
263 list
->band_channel_num
[band
]++;
265 entry
= &list
->channels
[i
];
268 entry
->index
= ieee80211_frequency_to_channel(freq
);
269 entry
->max_power
= 0;
280 static int p54_get_maxpower(struct p54_common
*priv
, void *data
)
282 switch (priv
->rxhw
& PDR_SYNTH_FRONTEND_MASK
) {
283 case PDR_SYNTH_FRONTEND_LONGBOW
: {
284 struct pda_channel_output_limit_longbow
*pda
= data
;
288 for (j
= 0; j
< ARRAY_SIZE(pda
->point
); j
++) {
289 struct pda_channel_output_limit_point_longbow
*point
=
291 rawpower
= max_t(u16
,
292 rawpower
, le16_to_cpu(point
->val_qpsk
));
293 rawpower
= max_t(u16
,
294 rawpower
, le16_to_cpu(point
->val_bpsk
));
295 rawpower
= max_t(u16
,
296 rawpower
, le16_to_cpu(point
->val_16qam
));
297 rawpower
= max_t(u16
,
298 rawpower
, le16_to_cpu(point
->val_64qam
));
300 /* longbow seems to use 1/16 dBm units */
301 return rawpower
/ 16;
304 case PDR_SYNTH_FRONTEND_DUETTE3
:
305 case PDR_SYNTH_FRONTEND_DUETTE2
:
306 case PDR_SYNTH_FRONTEND_FRISBEE
:
307 case PDR_SYNTH_FRONTEND_XBOW
: {
308 struct pda_channel_output_limit
*pda
= data
;
310 rawpower
= max(rawpower
, pda
->val_qpsk
);
311 rawpower
= max(rawpower
, pda
->val_bpsk
);
312 rawpower
= max(rawpower
, pda
->val_16qam
);
313 rawpower
= max(rawpower
, pda
->val_64qam
);
314 /* raw values are in 1/4 dBm units */
323 static int p54_generate_channel_lists(struct ieee80211_hw
*dev
)
325 struct p54_common
*priv
= dev
->priv
;
326 struct p54_channel_list
*list
;
327 unsigned int i
, j
, k
, max_channel_num
;
331 if ((priv
->iq_autocal_len
!= priv
->curve_data
->entries
) ||
332 (priv
->iq_autocal_len
!= priv
->output_limit
->entries
))
333 wiphy_err(dev
->wiphy
,
334 "Unsupported or damaged EEPROM detected. "
335 "You may not be able to use all channels.\n");
337 max_channel_num
= max_t(unsigned int, priv
->output_limit
->entries
,
338 priv
->iq_autocal_len
);
339 max_channel_num
= max_t(unsigned int, max_channel_num
,
340 priv
->curve_data
->entries
);
342 list
= kzalloc(sizeof(*list
), GFP_KERNEL
);
347 priv
->chan_num
= max_channel_num
;
348 priv
->survey
= kcalloc(max_channel_num
, sizeof(struct survey_info
),
355 list
->max_entries
= max_channel_num
;
356 list
->channels
= kcalloc(max_channel_num
,
357 sizeof(struct p54_channel_entry
),
359 if (!list
->channels
) {
364 for (i
= 0; i
< max_channel_num
; i
++) {
365 if (i
< priv
->iq_autocal_len
) {
366 freq
= le16_to_cpu(priv
->iq_autocal
[i
].freq
);
367 p54_update_channel_param(list
, freq
, CHAN_HAS_CAL
);
370 if (i
< priv
->output_limit
->entries
) {
371 struct p54_channel_entry
*tmp
;
373 void *data
= (void *) ((unsigned long) i
*
374 priv
->output_limit
->entry_size
+
375 priv
->output_limit
->offset
+
376 priv
->output_limit
->data
);
378 freq
= le16_to_cpup((__le16
*) data
);
379 tmp
= p54_update_channel_param(list
, freq
,
382 tmp
->max_power
= p54_get_maxpower(priv
, data
);
386 if (i
< priv
->curve_data
->entries
) {
387 freq
= le16_to_cpup((__le16
*) (i
*
388 priv
->curve_data
->entry_size
+
389 priv
->curve_data
->offset
+
390 priv
->curve_data
->data
));
392 p54_update_channel_param(list
, freq
, CHAN_HAS_CURVE
);
396 /* sort the channel list by frequency */
397 sort(list
->channels
, list
->entries
, sizeof(struct p54_channel_entry
),
398 p54_compare_channels
, NULL
);
401 for (i
= 0, j
= 0; i
< NUM_NL80211_BANDS
; i
++) {
402 if (p54_generate_band(dev
, list
, &k
, i
) == 0)
406 /* no useable band available. */
412 kfree(list
->channels
);
423 static int p54_convert_rev0(struct ieee80211_hw
*dev
,
424 struct pda_pa_curve_data
*curve_data
)
426 struct p54_common
*priv
= dev
->priv
;
427 struct p54_pa_curve_data_sample
*dst
;
428 struct pda_pa_curve_data_sample_rev0
*src
;
429 size_t cd_len
= sizeof(*curve_data
) +
430 (curve_data
->points_per_channel
*sizeof(*dst
) + 2) *
431 curve_data
->channels
;
433 void *source
, *target
;
435 priv
->curve_data
= kmalloc(sizeof(*priv
->curve_data
) + cd_len
,
437 if (!priv
->curve_data
)
440 priv
->curve_data
->entries
= curve_data
->channels
;
441 priv
->curve_data
->entry_size
= sizeof(__le16
) +
442 sizeof(*dst
) * curve_data
->points_per_channel
;
443 priv
->curve_data
->offset
= offsetof(struct pda_pa_curve_data
, data
);
444 priv
->curve_data
->len
= cd_len
;
445 memcpy(priv
->curve_data
->data
, curve_data
, sizeof(*curve_data
));
446 source
= curve_data
->data
;
447 target
= ((struct pda_pa_curve_data
*) priv
->curve_data
->data
)->data
;
448 for (i
= 0; i
< curve_data
->channels
; i
++) {
449 __le16
*freq
= source
;
450 source
+= sizeof(__le16
);
451 *((__le16
*)target
) = *freq
;
452 target
+= sizeof(__le16
);
453 for (j
= 0; j
< curve_data
->points_per_channel
; j
++) {
457 dst
->rf_power
= src
->rf_power
;
458 dst
->pa_detector
= src
->pa_detector
;
459 dst
->data_64qam
= src
->pcv
;
460 /* "invent" the points for the other modulations */
461 #define SUB(x, y) (u8)(((x) - (y)) > (x) ? 0 : (x) - (y))
462 dst
->data_16qam
= SUB(src
->pcv
, 12);
463 dst
->data_qpsk
= SUB(dst
->data_16qam
, 12);
464 dst
->data_bpsk
= SUB(dst
->data_qpsk
, 12);
465 dst
->data_barker
= SUB(dst
->data_bpsk
, 14);
467 target
+= sizeof(*dst
);
468 source
+= sizeof(*src
);
475 static int p54_convert_rev1(struct ieee80211_hw
*dev
,
476 struct pda_pa_curve_data
*curve_data
)
478 struct p54_common
*priv
= dev
->priv
;
479 struct p54_pa_curve_data_sample
*dst
;
480 struct pda_pa_curve_data_sample_rev1
*src
;
481 size_t cd_len
= sizeof(*curve_data
) +
482 (curve_data
->points_per_channel
*sizeof(*dst
) + 2) *
483 curve_data
->channels
;
485 void *source
, *target
;
487 priv
->curve_data
= kzalloc(cd_len
+ sizeof(*priv
->curve_data
),
489 if (!priv
->curve_data
)
492 priv
->curve_data
->entries
= curve_data
->channels
;
493 priv
->curve_data
->entry_size
= sizeof(__le16
) +
494 sizeof(*dst
) * curve_data
->points_per_channel
;
495 priv
->curve_data
->offset
= offsetof(struct pda_pa_curve_data
, data
);
496 priv
->curve_data
->len
= cd_len
;
497 memcpy(priv
->curve_data
->data
, curve_data
, sizeof(*curve_data
));
498 source
= curve_data
->data
;
499 target
= ((struct pda_pa_curve_data
*) priv
->curve_data
->data
)->data
;
500 for (i
= 0; i
< curve_data
->channels
; i
++) {
501 __le16
*freq
= source
;
502 source
+= sizeof(__le16
);
503 *((__le16
*)target
) = *freq
;
504 target
+= sizeof(__le16
);
505 for (j
= 0; j
< curve_data
->points_per_channel
; j
++) {
506 memcpy(target
, source
, sizeof(*src
));
508 target
+= sizeof(*dst
);
509 source
+= sizeof(*src
);
517 static const char *p54_rf_chips
[] = { "INVALID-0", "Duette3", "Duette2",
518 "Frisbee", "Xbow", "Longbow", "INVALID-6", "INVALID-7" };
520 static int p54_parse_rssical(struct ieee80211_hw
*dev
,
521 u8
*data
, int len
, u16 type
)
523 struct p54_common
*priv
= dev
->priv
;
524 struct p54_rssi_db_entry
*entry
;
525 size_t db_len
, entries
;
528 if (type
!= PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED
) {
529 entries
= (type
== PDR_RSSI_LINEAR_APPROXIMATION
) ? 1 : 2;
530 if (len
!= sizeof(struct pda_rssi_cal_entry
) * entries
) {
531 wiphy_err(dev
->wiphy
, "rssical size mismatch.\n");
536 * Some devices (Dell 1450 USB, Xbow 5GHz card, etc...)
537 * have an empty two byte header.
539 if (*((__le16
*)&data
[offset
]) == cpu_to_le16(0))
542 entries
= (len
- offset
) /
543 sizeof(struct pda_rssi_cal_ext_entry
);
546 (len
- offset
) % sizeof(struct pda_rssi_cal_ext_entry
) ||
548 wiphy_err(dev
->wiphy
, "invalid rssi database.\n");
553 db_len
= sizeof(*entry
) * entries
;
554 priv
->rssi_db
= kzalloc(db_len
+ sizeof(*priv
->rssi_db
), GFP_KERNEL
);
558 priv
->rssi_db
->offset
= 0;
559 priv
->rssi_db
->entries
= entries
;
560 priv
->rssi_db
->entry_size
= sizeof(*entry
);
561 priv
->rssi_db
->len
= db_len
;
563 entry
= (void *)((unsigned long)priv
->rssi_db
->data
+ priv
->rssi_db
->offset
);
564 if (type
== PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED
) {
565 struct pda_rssi_cal_ext_entry
*cal
= (void *) &data
[offset
];
567 for (i
= 0; i
< entries
; i
++) {
568 entry
[i
].freq
= le16_to_cpu(cal
[i
].freq
);
569 entry
[i
].mul
= (s16
) le16_to_cpu(cal
[i
].mul
);
570 entry
[i
].add
= (s16
) le16_to_cpu(cal
[i
].add
);
573 struct pda_rssi_cal_entry
*cal
= (void *) &data
[offset
];
575 for (i
= 0; i
< entries
; i
++) {
578 case NL80211_BAND_2GHZ
:
581 case NL80211_BAND_5GHZ
:
586 entry
[i
].freq
= freq
;
587 entry
[i
].mul
= (s16
) le16_to_cpu(cal
[i
].mul
);
588 entry
[i
].add
= (s16
) le16_to_cpu(cal
[i
].add
);
592 /* sort the list by channel frequency */
593 sort(entry
, entries
, sizeof(*entry
), p54_compare_rssichan
, NULL
);
597 wiphy_err(dev
->wiphy
,
598 "rssi calibration data packing type:(%x) len:%d.\n",
601 print_hex_dump_bytes("rssical:", DUMP_PREFIX_NONE
, data
, len
);
603 wiphy_err(dev
->wiphy
, "please report this issue.\n");
607 struct p54_rssi_db_entry
*p54_rssi_find(struct p54_common
*priv
, const u16 freq
)
609 struct p54_rssi_db_entry
*entry
;
613 return &p54_rssi_default
;
615 entry
= (void *)(priv
->rssi_db
->data
+ priv
->rssi_db
->offset
);
616 for (i
= 0; i
< priv
->rssi_db
->entries
; i
++) {
617 if (!same_band(freq
, entry
[i
].freq
))
626 if (abs(freq
- entry
[i
].freq
) <
627 abs(freq
- entry
[found
].freq
)) {
635 return found
< 0 ? &p54_rssi_default
: &entry
[found
];
638 static void p54_parse_default_country(struct ieee80211_hw
*dev
,
641 struct pda_country
*country
;
643 if (len
!= sizeof(*country
)) {
644 wiphy_err(dev
->wiphy
,
645 "found possible invalid default country eeprom entry. (entry size: %d)\n",
648 print_hex_dump_bytes("country:", DUMP_PREFIX_NONE
,
651 wiphy_err(dev
->wiphy
, "please report this issue.\n");
655 country
= (struct pda_country
*) data
;
656 if (country
->flags
== PDR_COUNTRY_CERT_CODE_PSEUDO
)
657 regulatory_hint(dev
->wiphy
, country
->alpha2
);
660 * write a shared/common function that converts
661 * "Regulatory domain codes" (802.11-2007 14.8.2.2)
662 * into ISO/IEC 3166-1 alpha2 for regulatory_hint.
667 static int p54_convert_output_limits(struct ieee80211_hw
*dev
,
668 u8
*data
, size_t len
)
670 struct p54_common
*priv
= dev
->priv
;
676 wiphy_err(dev
->wiphy
, "unknown output power db revision:%x\n",
681 if (2 + data
[1] * sizeof(struct pda_channel_output_limit
) > len
)
684 priv
->output_limit
= kmalloc(data
[1] *
685 sizeof(struct pda_channel_output_limit
) +
686 sizeof(*priv
->output_limit
), GFP_KERNEL
);
688 if (!priv
->output_limit
)
691 priv
->output_limit
->offset
= 0;
692 priv
->output_limit
->entries
= data
[1];
693 priv
->output_limit
->entry_size
=
694 sizeof(struct pda_channel_output_limit
);
695 priv
->output_limit
->len
= priv
->output_limit
->entry_size
*
696 priv
->output_limit
->entries
+
697 priv
->output_limit
->offset
;
699 memcpy(priv
->output_limit
->data
, &data
[2],
700 data
[1] * sizeof(struct pda_channel_output_limit
));
705 static struct p54_cal_database
*p54_convert_db(struct pda_custom_wrapper
*src
,
708 struct p54_cal_database
*dst
;
709 size_t payload_len
, entries
, entry_size
, offset
;
711 payload_len
= le16_to_cpu(src
->len
);
712 entries
= le16_to_cpu(src
->entries
);
713 entry_size
= le16_to_cpu(src
->entry_size
);
714 offset
= le16_to_cpu(src
->offset
);
715 if (((entries
* entry_size
+ offset
) != payload_len
) ||
716 (payload_len
+ sizeof(*src
) != total_len
))
719 dst
= kmalloc(sizeof(*dst
) + payload_len
, GFP_KERNEL
);
723 dst
->entries
= entries
;
724 dst
->entry_size
= entry_size
;
725 dst
->offset
= offset
;
726 dst
->len
= payload_len
;
728 memcpy(dst
->data
, src
->data
, payload_len
);
732 int p54_parse_eeprom(struct ieee80211_hw
*dev
, void *eeprom
, int len
)
734 struct p54_common
*priv
= dev
->priv
;
735 struct eeprom_pda_wrap
*wrap
;
736 struct pda_entry
*entry
;
737 unsigned int data_len
, entry_len
;
740 u8
*end
= (u8
*)eeprom
+ len
;
744 wrap
= (struct eeprom_pda_wrap
*) eeprom
;
745 entry
= (void *)wrap
->data
+ le16_to_cpu(wrap
->len
);
747 /* verify that at least the entry length/code fits */
748 while ((u8
*)entry
<= end
- sizeof(*entry
)) {
749 entry_len
= le16_to_cpu(entry
->len
);
750 data_len
= ((entry_len
- 1) << 1);
752 /* abort if entry exceeds whole structure */
753 if ((u8
*)entry
+ sizeof(*entry
) + data_len
> end
)
756 switch (le16_to_cpu(entry
->code
)) {
757 case PDR_MAC_ADDRESS
:
758 if (data_len
!= ETH_ALEN
)
760 SET_IEEE80211_PERM_ADDR(dev
, entry
->data
);
762 case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS
:
763 if (priv
->output_limit
)
765 err
= p54_convert_output_limits(dev
, entry
->data
,
770 case PDR_PRISM_PA_CAL_CURVE_DATA
: {
771 struct pda_pa_curve_data
*curve_data
=
772 (struct pda_pa_curve_data
*)entry
->data
;
773 if (data_len
< sizeof(*curve_data
)) {
778 switch (curve_data
->cal_method_rev
) {
780 err
= p54_convert_rev0(dev
, curve_data
);
783 err
= p54_convert_rev1(dev
, curve_data
);
786 wiphy_err(dev
->wiphy
,
787 "unknown curve data revision %d\n",
788 curve_data
->cal_method_rev
);
796 case PDR_PRISM_ZIF_TX_IQ_CALIBRATION
:
797 priv
->iq_autocal
= kmemdup(entry
->data
, data_len
,
799 if (!priv
->iq_autocal
) {
804 priv
->iq_autocal_len
= data_len
/ sizeof(struct pda_iq_autocal_entry
);
806 case PDR_DEFAULT_COUNTRY
:
807 p54_parse_default_country(dev
, entry
->data
, data_len
);
809 case PDR_INTERFACE_LIST
:
811 while ((u8
*)tmp
< entry
->data
+ data_len
) {
812 struct exp_if
*exp_if
= tmp
;
813 if (exp_if
->if_id
== cpu_to_le16(IF_ID_ISL39000
))
814 synth
= le16_to_cpu(exp_if
->variant
);
815 tmp
+= sizeof(*exp_if
);
818 case PDR_HARDWARE_PLATFORM_COMPONENT_ID
:
821 priv
->version
= *(u8
*)(entry
->data
+ 1);
823 case PDR_RSSI_LINEAR_APPROXIMATION
:
824 case PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND
:
825 case PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED
:
826 err
= p54_parse_rssical(dev
, entry
->data
, data_len
,
827 le16_to_cpu(entry
->code
));
831 case PDR_RSSI_LINEAR_APPROXIMATION_CUSTOMV2
: {
832 struct pda_custom_wrapper
*pda
= (void *) entry
->data
;
837 if (priv
->rssi_db
|| data_len
< sizeof(*pda
))
840 priv
->rssi_db
= p54_convert_db(pda
, data_len
);
844 src
= (void *) priv
->rssi_db
->data
;
845 dst
= (void *) priv
->rssi_db
->data
;
847 for (i
= 0; i
< priv
->rssi_db
->entries
; i
++)
848 *(dst
++) = (s16
) le16_to_cpu(*(src
++));
852 case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS_CUSTOM
: {
853 struct pda_custom_wrapper
*pda
= (void *) entry
->data
;
854 if (priv
->output_limit
|| data_len
< sizeof(*pda
))
856 priv
->output_limit
= p54_convert_db(pda
, data_len
);
859 case PDR_PRISM_PA_CAL_CURVE_DATA_CUSTOM
: {
860 struct pda_custom_wrapper
*pda
= (void *) entry
->data
;
861 if (priv
->curve_data
|| data_len
< sizeof(*pda
))
863 priv
->curve_data
= p54_convert_db(pda
, data_len
);
867 crc16
= ~crc_ccitt(crc16
, (u8
*) entry
, sizeof(*entry
));
868 if (crc16
!= le16_to_cpup((__le16
*)entry
->data
)) {
869 wiphy_err(dev
->wiphy
, "eeprom failed checksum "
881 crc16
= crc_ccitt(crc16
, (u8
*)entry
, (entry_len
+ 1) * 2);
882 entry
= (void *)entry
+ (entry_len
+ 1) * 2;
885 wiphy_err(dev
->wiphy
, "unexpected end of eeprom data.\n");
890 if (!synth
|| !priv
->iq_autocal
|| !priv
->output_limit
||
892 wiphy_err(dev
->wiphy
,
893 "not all required entries found in eeprom!\n");
898 priv
->rxhw
= synth
& PDR_SYNTH_FRONTEND_MASK
;
900 err
= p54_generate_channel_lists(dev
);
904 if (priv
->rxhw
== PDR_SYNTH_FRONTEND_XBOW
)
905 p54_init_xbow_synth(priv
);
906 if (!(synth
& PDR_SYNTH_24_GHZ_DISABLED
))
907 dev
->wiphy
->bands
[NL80211_BAND_2GHZ
] =
908 priv
->band_table
[NL80211_BAND_2GHZ
];
909 if (!(synth
& PDR_SYNTH_5_GHZ_DISABLED
))
910 dev
->wiphy
->bands
[NL80211_BAND_5GHZ
] =
911 priv
->band_table
[NL80211_BAND_5GHZ
];
912 if ((synth
& PDR_SYNTH_RX_DIV_MASK
) == PDR_SYNTH_RX_DIV_SUPPORTED
)
913 priv
->rx_diversity_mask
= 3;
914 if ((synth
& PDR_SYNTH_TX_DIV_MASK
) == PDR_SYNTH_TX_DIV_SUPPORTED
)
915 priv
->tx_diversity_mask
= 3;
917 if (!is_valid_ether_addr(dev
->wiphy
->perm_addr
)) {
918 u8 perm_addr
[ETH_ALEN
];
920 wiphy_warn(dev
->wiphy
,
921 "Invalid hwaddr! Using randomly generated MAC addr\n");
922 eth_random_addr(perm_addr
);
923 SET_IEEE80211_PERM_ADDR(dev
, perm_addr
);
926 priv
->cur_rssi
= &p54_rssi_default
;
928 wiphy_info(dev
->wiphy
, "hwaddr %pM, MAC:isl38%02x RF:%s\n",
929 dev
->wiphy
->perm_addr
, priv
->version
,
930 p54_rf_chips
[priv
->rxhw
]);
935 kfree(priv
->iq_autocal
);
936 kfree(priv
->output_limit
);
937 kfree(priv
->curve_data
);
938 kfree(priv
->rssi_db
);
940 priv
->iq_autocal
= NULL
;
941 priv
->output_limit
= NULL
;
942 priv
->curve_data
= NULL
;
943 priv
->rssi_db
= NULL
;
946 wiphy_err(dev
->wiphy
, "eeprom parse failed!\n");
949 EXPORT_SYMBOL_GPL(p54_parse_eeprom
);
951 int p54_read_eeprom(struct ieee80211_hw
*dev
)
953 struct p54_common
*priv
= dev
->priv
;
954 size_t eeprom_size
= 0x2020, offset
= 0, blocksize
, maxblocksize
;
958 maxblocksize
= EEPROM_READBACK_LEN
;
959 if (priv
->fw_var
>= 0x509)
964 eeprom
= kzalloc(eeprom_size
, GFP_KERNEL
);
965 if (unlikely(!eeprom
))
968 while (eeprom_size
) {
969 blocksize
= min(eeprom_size
, maxblocksize
);
970 ret
= p54_download_eeprom(priv
, eeprom
+ offset
,
976 eeprom_size
-= blocksize
;
979 ret
= p54_parse_eeprom(dev
, eeprom
, offset
);
984 EXPORT_SYMBOL_GPL(p54_read_eeprom
);