1 // SPDX-License-Identifier: GPL-2.0-only
3 * EEPROM parser code for mac80211 Prism54 drivers
5 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
6 * Copyright (c) 2007-2009, Christian Lamparter <chunkeey@web.de>
7 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
10 * - the islsm (softmac prism54) driver, which is:
11 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
13 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
16 #include <linux/firmware.h>
17 #include <linux/etherdevice.h>
18 #include <linux/sort.h>
19 #include <linux/slab.h>
21 #include <net/mac80211.h>
22 #include <linux/crc-ccitt.h>
23 #include <linux/export.h>
29 static struct ieee80211_rate p54_bgrates
[] = {
30 { .bitrate
= 10, .hw_value
= 0, },
31 { .bitrate
= 20, .hw_value
= 1, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
32 { .bitrate
= 55, .hw_value
= 2, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
33 { .bitrate
= 110, .hw_value
= 3, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
34 { .bitrate
= 60, .hw_value
= 4, },
35 { .bitrate
= 90, .hw_value
= 5, },
36 { .bitrate
= 120, .hw_value
= 6, },
37 { .bitrate
= 180, .hw_value
= 7, },
38 { .bitrate
= 240, .hw_value
= 8, },
39 { .bitrate
= 360, .hw_value
= 9, },
40 { .bitrate
= 480, .hw_value
= 10, },
41 { .bitrate
= 540, .hw_value
= 11, },
44 static struct ieee80211_rate p54_arates
[] = {
45 { .bitrate
= 60, .hw_value
= 4, },
46 { .bitrate
= 90, .hw_value
= 5, },
47 { .bitrate
= 120, .hw_value
= 6, },
48 { .bitrate
= 180, .hw_value
= 7, },
49 { .bitrate
= 240, .hw_value
= 8, },
50 { .bitrate
= 360, .hw_value
= 9, },
51 { .bitrate
= 480, .hw_value
= 10, },
52 { .bitrate
= 540, .hw_value
= 11, },
55 static struct p54_rssi_db_entry p54_rssi_default
= {
57 * The defaults are taken from usb-logs of the
58 * vendor driver. So, they should be safe to
59 * use in case we can't get a match from the
60 * rssi <-> dBm conversion database.
66 #define CHAN_HAS_CAL BIT(0)
67 #define CHAN_HAS_LIMIT BIT(1)
68 #define CHAN_HAS_CURVE BIT(2)
69 #define CHAN_HAS_ALL (CHAN_HAS_CAL | CHAN_HAS_LIMIT | CHAN_HAS_CURVE)
71 struct p54_channel_entry
{
76 enum nl80211_band band
;
79 struct p54_channel_list
{
80 struct p54_channel_entry
*channels
;
83 size_t band_channel_num
[NUM_NL80211_BANDS
];
86 static int p54_get_band_from_freq(u16 freq
)
88 /* FIXME: sync these values with the 802.11 spec */
90 if ((freq
>= 2412) && (freq
<= 2484))
91 return NL80211_BAND_2GHZ
;
93 if ((freq
>= 4920) && (freq
<= 5825))
94 return NL80211_BAND_5GHZ
;
99 static int same_band(u16 freq
, u16 freq2
)
101 return p54_get_band_from_freq(freq
) == p54_get_band_from_freq(freq2
);
104 static int p54_compare_channels(const void *_a
,
107 const struct p54_channel_entry
*a
= _a
;
108 const struct p54_channel_entry
*b
= _b
;
110 return a
->freq
- b
->freq
;
113 static int p54_compare_rssichan(const void *_a
,
116 const struct p54_rssi_db_entry
*a
= _a
;
117 const struct p54_rssi_db_entry
*b
= _b
;
119 return a
->freq
- b
->freq
;
122 static int p54_fill_band_bitrates(struct ieee80211_hw
*dev
,
123 struct ieee80211_supported_band
*band_entry
,
124 enum nl80211_band band
)
126 /* TODO: generate rate array dynamically */
129 case NL80211_BAND_2GHZ
:
130 band_entry
->bitrates
= p54_bgrates
;
131 band_entry
->n_bitrates
= ARRAY_SIZE(p54_bgrates
);
133 case NL80211_BAND_5GHZ
:
134 band_entry
->bitrates
= p54_arates
;
135 band_entry
->n_bitrates
= ARRAY_SIZE(p54_arates
);
144 static int p54_generate_band(struct ieee80211_hw
*dev
,
145 struct p54_channel_list
*list
,
146 unsigned int *chan_num
,
147 enum nl80211_band band
)
149 struct p54_common
*priv
= dev
->priv
;
150 struct ieee80211_supported_band
*tmp
, *old
;
154 if ((!list
->entries
) || (!list
->band_channel_num
[band
]))
157 tmp
= kzalloc(sizeof(*tmp
), GFP_KERNEL
);
161 tmp
->channels
= kcalloc(list
->band_channel_num
[band
],
162 sizeof(struct ieee80211_channel
),
167 ret
= p54_fill_band_bitrates(dev
, tmp
, band
);
171 for (i
= 0, j
= 0; (j
< list
->band_channel_num
[band
]) &&
172 (i
< list
->entries
); i
++) {
173 struct p54_channel_entry
*chan
= &list
->channels
[i
];
174 struct ieee80211_channel
*dest
= &tmp
->channels
[j
];
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 dest
->band
= chan
->band
;
193 dest
->center_freq
= chan
->freq
;
194 dest
->max_power
= chan
->max_power
;
195 priv
->survey
[*chan_num
].channel
= &tmp
->channels
[j
];
196 priv
->survey
[*chan_num
].filled
= SURVEY_INFO_NOISE_DBM
|
198 SURVEY_INFO_TIME_BUSY
|
200 dest
->hw_value
= (*chan_num
);
206 wiphy_err(dev
->wiphy
, "Disabling totally damaged %d GHz band\n",
207 (band
== NL80211_BAND_2GHZ
) ? 2 : 5);
214 old
= priv
->band_table
[band
];
215 priv
->band_table
[band
] = tmp
;
217 kfree(old
->channels
);
225 kfree(tmp
->channels
);
232 static struct p54_channel_entry
*p54_update_channel_param(struct p54_channel_list
*list
,
236 struct p54_channel_entry
*entry
= NULL
;
239 * usually all lists in the eeprom are mostly sorted.
240 * so it's very likely that the entry we are looking for
241 * is right at the end of the list
243 for (i
= list
->entries
; i
>= 0; i
--) {
244 if (freq
== list
->channels
[i
].freq
) {
245 entry
= &list
->channels
[i
];
250 if ((i
< 0) && (list
->entries
< list
->max_entries
)) {
251 /* entry does not exist yet. Initialize a new one. */
252 int band
= p54_get_band_from_freq(freq
);
255 * filter out frequencies which don't belong into
256 * any supported band.
260 list
->band_channel_num
[band
]++;
262 entry
= &list
->channels
[i
];
265 entry
->index
= ieee80211_frequency_to_channel(freq
);
266 entry
->max_power
= 0;
277 static int p54_get_maxpower(struct p54_common
*priv
, void *data
)
279 switch (priv
->rxhw
& PDR_SYNTH_FRONTEND_MASK
) {
280 case PDR_SYNTH_FRONTEND_LONGBOW
: {
281 struct pda_channel_output_limit_longbow
*pda
= data
;
285 for (j
= 0; j
< ARRAY_SIZE(pda
->point
); j
++) {
286 struct pda_channel_output_limit_point_longbow
*point
=
288 rawpower
= max_t(u16
,
289 rawpower
, le16_to_cpu(point
->val_qpsk
));
290 rawpower
= max_t(u16
,
291 rawpower
, le16_to_cpu(point
->val_bpsk
));
292 rawpower
= max_t(u16
,
293 rawpower
, le16_to_cpu(point
->val_16qam
));
294 rawpower
= max_t(u16
,
295 rawpower
, le16_to_cpu(point
->val_64qam
));
297 /* longbow seems to use 1/16 dBm units */
298 return rawpower
/ 16;
301 case PDR_SYNTH_FRONTEND_DUETTE3
:
302 case PDR_SYNTH_FRONTEND_DUETTE2
:
303 case PDR_SYNTH_FRONTEND_FRISBEE
:
304 case PDR_SYNTH_FRONTEND_XBOW
: {
305 struct pda_channel_output_limit
*pda
= data
;
307 rawpower
= max(rawpower
, pda
->val_qpsk
);
308 rawpower
= max(rawpower
, pda
->val_bpsk
);
309 rawpower
= max(rawpower
, pda
->val_16qam
);
310 rawpower
= max(rawpower
, pda
->val_64qam
);
311 /* raw values are in 1/4 dBm units */
320 static int p54_generate_channel_lists(struct ieee80211_hw
*dev
)
322 struct p54_common
*priv
= dev
->priv
;
323 struct p54_channel_list
*list
;
324 unsigned int i
, j
, k
, max_channel_num
;
328 if ((priv
->iq_autocal_len
!= priv
->curve_data
->entries
) ||
329 (priv
->iq_autocal_len
!= priv
->output_limit
->entries
))
330 wiphy_err(dev
->wiphy
,
331 "Unsupported or damaged EEPROM detected. "
332 "You may not be able to use all channels.\n");
334 max_channel_num
= max_t(unsigned int, priv
->output_limit
->entries
,
335 priv
->iq_autocal_len
);
336 max_channel_num
= max_t(unsigned int, max_channel_num
,
337 priv
->curve_data
->entries
);
339 list
= kzalloc(sizeof(*list
), GFP_KERNEL
);
344 priv
->chan_num
= max_channel_num
;
345 priv
->survey
= kcalloc(max_channel_num
, sizeof(struct survey_info
),
352 list
->max_entries
= max_channel_num
;
353 list
->channels
= kcalloc(max_channel_num
,
354 sizeof(struct p54_channel_entry
),
356 if (!list
->channels
) {
361 for (i
= 0; i
< max_channel_num
; i
++) {
362 if (i
< priv
->iq_autocal_len
) {
363 freq
= le16_to_cpu(priv
->iq_autocal
[i
].freq
);
364 p54_update_channel_param(list
, freq
, CHAN_HAS_CAL
);
367 if (i
< priv
->output_limit
->entries
) {
368 struct p54_channel_entry
*tmp
;
370 void *data
= (void *) ((unsigned long) i
*
371 priv
->output_limit
->entry_size
+
372 priv
->output_limit
->offset
+
373 priv
->output_limit
->data
);
375 freq
= le16_to_cpup((__le16
*) data
);
376 tmp
= p54_update_channel_param(list
, freq
,
379 tmp
->max_power
= p54_get_maxpower(priv
, data
);
383 if (i
< priv
->curve_data
->entries
) {
384 freq
= le16_to_cpup((__le16
*) (i
*
385 priv
->curve_data
->entry_size
+
386 priv
->curve_data
->offset
+
387 priv
->curve_data
->data
));
389 p54_update_channel_param(list
, freq
, CHAN_HAS_CURVE
);
393 /* sort the channel list by frequency */
394 sort(list
->channels
, list
->entries
, sizeof(struct p54_channel_entry
),
395 p54_compare_channels
, NULL
);
398 for (i
= 0, j
= 0; i
< NUM_NL80211_BANDS
; i
++) {
399 if (p54_generate_band(dev
, list
, &k
, i
) == 0)
403 /* no useable band available. */
409 kfree(list
->channels
);
420 static int p54_convert_rev0(struct ieee80211_hw
*dev
,
421 struct pda_pa_curve_data
*curve_data
)
423 struct p54_common
*priv
= dev
->priv
;
424 struct p54_pa_curve_data_sample
*dst
;
425 struct pda_pa_curve_data_sample_rev0
*src
;
426 size_t cd_len
= sizeof(*curve_data
) +
427 (curve_data
->points_per_channel
*sizeof(*dst
) + 2) *
428 curve_data
->channels
;
430 void *source
, *target
;
432 priv
->curve_data
= kmalloc(sizeof(*priv
->curve_data
) + cd_len
,
434 if (!priv
->curve_data
)
437 priv
->curve_data
->entries
= curve_data
->channels
;
438 priv
->curve_data
->entry_size
= sizeof(__le16
) +
439 sizeof(*dst
) * curve_data
->points_per_channel
;
440 priv
->curve_data
->offset
= offsetof(struct pda_pa_curve_data
, data
);
441 priv
->curve_data
->len
= cd_len
;
442 memcpy(priv
->curve_data
->data
, curve_data
, sizeof(*curve_data
));
443 source
= curve_data
->data
;
444 target
= ((struct pda_pa_curve_data
*) priv
->curve_data
->data
)->data
;
445 for (i
= 0; i
< curve_data
->channels
; i
++) {
446 __le16
*freq
= source
;
447 source
+= sizeof(__le16
);
448 *((__le16
*)target
) = *freq
;
449 target
+= sizeof(__le16
);
450 for (j
= 0; j
< curve_data
->points_per_channel
; j
++) {
454 dst
->rf_power
= src
->rf_power
;
455 dst
->pa_detector
= src
->pa_detector
;
456 dst
->data_64qam
= src
->pcv
;
457 /* "invent" the points for the other modulations */
458 #define SUB(x, y) (u8)(((x) - (y)) > (x) ? 0 : (x) - (y))
459 dst
->data_16qam
= SUB(src
->pcv
, 12);
460 dst
->data_qpsk
= SUB(dst
->data_16qam
, 12);
461 dst
->data_bpsk
= SUB(dst
->data_qpsk
, 12);
462 dst
->data_barker
= SUB(dst
->data_bpsk
, 14);
464 target
+= sizeof(*dst
);
465 source
+= sizeof(*src
);
472 static int p54_convert_rev1(struct ieee80211_hw
*dev
,
473 struct pda_pa_curve_data
*curve_data
)
475 struct p54_common
*priv
= dev
->priv
;
476 struct p54_pa_curve_data_sample
*dst
;
477 struct pda_pa_curve_data_sample_rev1
*src
;
478 size_t cd_len
= sizeof(*curve_data
) +
479 (curve_data
->points_per_channel
*sizeof(*dst
) + 2) *
480 curve_data
->channels
;
482 void *source
, *target
;
484 priv
->curve_data
= kzalloc(cd_len
+ sizeof(*priv
->curve_data
),
486 if (!priv
->curve_data
)
489 priv
->curve_data
->entries
= curve_data
->channels
;
490 priv
->curve_data
->entry_size
= sizeof(__le16
) +
491 sizeof(*dst
) * curve_data
->points_per_channel
;
492 priv
->curve_data
->offset
= offsetof(struct pda_pa_curve_data
, data
);
493 priv
->curve_data
->len
= cd_len
;
494 memcpy(priv
->curve_data
->data
, curve_data
, sizeof(*curve_data
));
495 source
= curve_data
->data
;
496 target
= ((struct pda_pa_curve_data
*) priv
->curve_data
->data
)->data
;
497 for (i
= 0; i
< curve_data
->channels
; i
++) {
498 __le16
*freq
= source
;
499 source
+= sizeof(__le16
);
500 *((__le16
*)target
) = *freq
;
501 target
+= sizeof(__le16
);
502 for (j
= 0; j
< curve_data
->points_per_channel
; j
++) {
503 memcpy(target
, source
, sizeof(*src
));
505 target
+= sizeof(*dst
);
506 source
+= sizeof(*src
);
514 static const char *p54_rf_chips
[] = { "INVALID-0", "Duette3", "Duette2",
515 "Frisbee", "Xbow", "Longbow", "INVALID-6", "INVALID-7" };
517 static int p54_parse_rssical(struct ieee80211_hw
*dev
,
518 u8
*data
, int len
, u16 type
)
520 struct p54_common
*priv
= dev
->priv
;
521 struct p54_rssi_db_entry
*entry
;
522 size_t db_len
, entries
;
525 if (type
!= PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED
) {
526 entries
= (type
== PDR_RSSI_LINEAR_APPROXIMATION
) ? 1 : 2;
527 if (len
!= sizeof(struct pda_rssi_cal_entry
) * entries
) {
528 wiphy_err(dev
->wiphy
, "rssical size mismatch.\n");
533 * Some devices (Dell 1450 USB, Xbow 5GHz card, etc...)
534 * have an empty two byte header.
536 if (*((__le16
*)&data
[offset
]) == cpu_to_le16(0))
539 entries
= (len
- offset
) /
540 sizeof(struct pda_rssi_cal_ext_entry
);
543 (len
- offset
) % sizeof(struct pda_rssi_cal_ext_entry
) ||
545 wiphy_err(dev
->wiphy
, "invalid rssi database.\n");
550 db_len
= sizeof(*entry
) * entries
;
551 priv
->rssi_db
= kzalloc(db_len
+ sizeof(*priv
->rssi_db
), GFP_KERNEL
);
555 priv
->rssi_db
->offset
= 0;
556 priv
->rssi_db
->entries
= entries
;
557 priv
->rssi_db
->entry_size
= sizeof(*entry
);
558 priv
->rssi_db
->len
= db_len
;
560 entry
= (void *)((unsigned long)priv
->rssi_db
->data
+ priv
->rssi_db
->offset
);
561 if (type
== PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED
) {
562 struct pda_rssi_cal_ext_entry
*cal
= (void *) &data
[offset
];
564 for (i
= 0; i
< entries
; i
++) {
565 entry
[i
].freq
= le16_to_cpu(cal
[i
].freq
);
566 entry
[i
].mul
= (s16
) le16_to_cpu(cal
[i
].mul
);
567 entry
[i
].add
= (s16
) le16_to_cpu(cal
[i
].add
);
570 struct pda_rssi_cal_entry
*cal
= (void *) &data
[offset
];
572 for (i
= 0; i
< entries
; i
++) {
575 case NL80211_BAND_2GHZ
:
578 case NL80211_BAND_5GHZ
:
583 entry
[i
].freq
= freq
;
584 entry
[i
].mul
= (s16
) le16_to_cpu(cal
[i
].mul
);
585 entry
[i
].add
= (s16
) le16_to_cpu(cal
[i
].add
);
589 /* sort the list by channel frequency */
590 sort(entry
, entries
, sizeof(*entry
), p54_compare_rssichan
, NULL
);
594 wiphy_err(dev
->wiphy
,
595 "rssi calibration data packing type:(%x) len:%d.\n",
598 print_hex_dump_bytes("rssical:", DUMP_PREFIX_NONE
, data
, len
);
600 wiphy_err(dev
->wiphy
, "please report this issue.\n");
604 struct p54_rssi_db_entry
*p54_rssi_find(struct p54_common
*priv
, const u16 freq
)
606 struct p54_rssi_db_entry
*entry
;
610 return &p54_rssi_default
;
612 entry
= (void *)(priv
->rssi_db
->data
+ priv
->rssi_db
->offset
);
613 for (i
= 0; i
< priv
->rssi_db
->entries
; i
++) {
614 if (!same_band(freq
, entry
[i
].freq
))
623 if (abs(freq
- entry
[i
].freq
) <
624 abs(freq
- entry
[found
].freq
)) {
632 return found
< 0 ? &p54_rssi_default
: &entry
[found
];
635 static void p54_parse_default_country(struct ieee80211_hw
*dev
,
638 struct pda_country
*country
;
640 if (len
!= sizeof(*country
)) {
641 wiphy_err(dev
->wiphy
,
642 "found possible invalid default country eeprom entry. (entry size: %d)\n",
645 print_hex_dump_bytes("country:", DUMP_PREFIX_NONE
,
648 wiphy_err(dev
->wiphy
, "please report this issue.\n");
652 country
= (struct pda_country
*) data
;
653 if (country
->flags
== PDR_COUNTRY_CERT_CODE_PSEUDO
)
654 regulatory_hint(dev
->wiphy
, country
->alpha2
);
657 * write a shared/common function that converts
658 * "Regulatory domain codes" (802.11-2007 14.8.2.2)
659 * into ISO/IEC 3166-1 alpha2 for regulatory_hint.
664 static int p54_convert_output_limits(struct ieee80211_hw
*dev
,
665 u8
*data
, size_t len
)
667 struct p54_common
*priv
= dev
->priv
;
673 wiphy_err(dev
->wiphy
, "unknown output power db revision:%x\n",
678 if (2 + data
[1] * sizeof(struct pda_channel_output_limit
) > len
)
681 priv
->output_limit
= kmalloc(data
[1] *
682 sizeof(struct pda_channel_output_limit
) +
683 sizeof(*priv
->output_limit
), GFP_KERNEL
);
685 if (!priv
->output_limit
)
688 priv
->output_limit
->offset
= 0;
689 priv
->output_limit
->entries
= data
[1];
690 priv
->output_limit
->entry_size
=
691 sizeof(struct pda_channel_output_limit
);
692 priv
->output_limit
->len
= priv
->output_limit
->entry_size
*
693 priv
->output_limit
->entries
+
694 priv
->output_limit
->offset
;
696 memcpy(priv
->output_limit
->data
, &data
[2],
697 data
[1] * sizeof(struct pda_channel_output_limit
));
702 static struct p54_cal_database
*p54_convert_db(struct pda_custom_wrapper
*src
,
705 struct p54_cal_database
*dst
;
706 size_t payload_len
, entries
, entry_size
, offset
;
708 payload_len
= le16_to_cpu(src
->len
);
709 entries
= le16_to_cpu(src
->entries
);
710 entry_size
= le16_to_cpu(src
->entry_size
);
711 offset
= le16_to_cpu(src
->offset
);
712 if (((entries
* entry_size
+ offset
) != payload_len
) ||
713 (payload_len
+ sizeof(*src
) != total_len
))
716 dst
= kmalloc(sizeof(*dst
) + payload_len
, GFP_KERNEL
);
720 dst
->entries
= entries
;
721 dst
->entry_size
= entry_size
;
722 dst
->offset
= offset
;
723 dst
->len
= payload_len
;
725 memcpy(dst
->data
, src
->data
, payload_len
);
729 int p54_parse_eeprom(struct ieee80211_hw
*dev
, void *eeprom
, int len
)
731 struct p54_common
*priv
= dev
->priv
;
732 struct eeprom_pda_wrap
*wrap
;
733 struct pda_entry
*entry
;
734 unsigned int data_len
, entry_len
;
737 u8
*end
= (u8
*)eeprom
+ len
;
741 wrap
= (struct eeprom_pda_wrap
*) eeprom
;
742 entry
= (void *)wrap
->data
+ le16_to_cpu(wrap
->len
);
744 /* verify that at least the entry length/code fits */
745 while ((u8
*)entry
<= end
- sizeof(*entry
)) {
746 entry_len
= le16_to_cpu(entry
->len
);
747 data_len
= ((entry_len
- 1) << 1);
749 /* abort if entry exceeds whole structure */
750 if ((u8
*)entry
+ sizeof(*entry
) + data_len
> end
)
753 switch (le16_to_cpu(entry
->code
)) {
754 case PDR_MAC_ADDRESS
:
755 if (data_len
!= ETH_ALEN
)
757 SET_IEEE80211_PERM_ADDR(dev
, entry
->data
);
759 case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS
:
760 if (priv
->output_limit
)
762 err
= p54_convert_output_limits(dev
, entry
->data
,
767 case PDR_PRISM_PA_CAL_CURVE_DATA
: {
768 struct pda_pa_curve_data
*curve_data
=
769 (struct pda_pa_curve_data
*)entry
->data
;
770 if (data_len
< sizeof(*curve_data
)) {
775 switch (curve_data
->cal_method_rev
) {
777 err
= p54_convert_rev0(dev
, curve_data
);
780 err
= p54_convert_rev1(dev
, curve_data
);
783 wiphy_err(dev
->wiphy
,
784 "unknown curve data revision %d\n",
785 curve_data
->cal_method_rev
);
793 case PDR_PRISM_ZIF_TX_IQ_CALIBRATION
:
794 priv
->iq_autocal
= kmemdup(entry
->data
, data_len
,
796 if (!priv
->iq_autocal
) {
801 priv
->iq_autocal_len
= data_len
/ sizeof(struct pda_iq_autocal_entry
);
803 case PDR_DEFAULT_COUNTRY
:
804 p54_parse_default_country(dev
, entry
->data
, data_len
);
806 case PDR_INTERFACE_LIST
:
808 while ((u8
*)tmp
< entry
->data
+ data_len
) {
809 struct exp_if
*exp_if
= tmp
;
810 if (exp_if
->if_id
== cpu_to_le16(IF_ID_ISL39000
))
811 synth
= le16_to_cpu(exp_if
->variant
);
812 tmp
+= sizeof(*exp_if
);
815 case PDR_HARDWARE_PLATFORM_COMPONENT_ID
:
818 priv
->version
= *(u8
*)(entry
->data
+ 1);
820 case PDR_RSSI_LINEAR_APPROXIMATION
:
821 case PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND
:
822 case PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED
:
823 err
= p54_parse_rssical(dev
, entry
->data
, data_len
,
824 le16_to_cpu(entry
->code
));
828 case PDR_RSSI_LINEAR_APPROXIMATION_CUSTOMV2
: {
829 struct pda_custom_wrapper
*pda
= (void *) entry
->data
;
834 if (priv
->rssi_db
|| data_len
< sizeof(*pda
))
837 priv
->rssi_db
= p54_convert_db(pda
, data_len
);
841 src
= (void *) priv
->rssi_db
->data
;
842 dst
= (void *) priv
->rssi_db
->data
;
844 for (i
= 0; i
< priv
->rssi_db
->entries
; i
++)
845 *(dst
++) = (s16
) le16_to_cpu(*(src
++));
849 case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS_CUSTOM
: {
850 struct pda_custom_wrapper
*pda
= (void *) entry
->data
;
851 if (priv
->output_limit
|| data_len
< sizeof(*pda
))
853 priv
->output_limit
= p54_convert_db(pda
, data_len
);
856 case PDR_PRISM_PA_CAL_CURVE_DATA_CUSTOM
: {
857 struct pda_custom_wrapper
*pda
= (void *) entry
->data
;
858 if (priv
->curve_data
|| data_len
< sizeof(*pda
))
860 priv
->curve_data
= p54_convert_db(pda
, data_len
);
864 crc16
= ~crc_ccitt(crc16
, (u8
*) entry
, sizeof(*entry
));
865 if (crc16
!= le16_to_cpup((__le16
*)entry
->data
)) {
866 wiphy_err(dev
->wiphy
, "eeprom failed checksum "
878 crc16
= crc_ccitt(crc16
, (u8
*)entry
, (entry_len
+ 1) * 2);
879 entry
= (void *)entry
+ (entry_len
+ 1) * 2;
882 wiphy_err(dev
->wiphy
, "unexpected end of eeprom data.\n");
887 if (!synth
|| !priv
->iq_autocal
|| !priv
->output_limit
||
889 wiphy_err(dev
->wiphy
,
890 "not all required entries found in eeprom!\n");
895 priv
->rxhw
= synth
& PDR_SYNTH_FRONTEND_MASK
;
897 err
= p54_generate_channel_lists(dev
);
901 if (priv
->rxhw
== PDR_SYNTH_FRONTEND_XBOW
)
902 p54_init_xbow_synth(priv
);
903 if (!(synth
& PDR_SYNTH_24_GHZ_DISABLED
))
904 dev
->wiphy
->bands
[NL80211_BAND_2GHZ
] =
905 priv
->band_table
[NL80211_BAND_2GHZ
];
906 if (!(synth
& PDR_SYNTH_5_GHZ_DISABLED
))
907 dev
->wiphy
->bands
[NL80211_BAND_5GHZ
] =
908 priv
->band_table
[NL80211_BAND_5GHZ
];
909 if ((synth
& PDR_SYNTH_RX_DIV_MASK
) == PDR_SYNTH_RX_DIV_SUPPORTED
)
910 priv
->rx_diversity_mask
= 3;
911 if ((synth
& PDR_SYNTH_TX_DIV_MASK
) == PDR_SYNTH_TX_DIV_SUPPORTED
)
912 priv
->tx_diversity_mask
= 3;
914 if (!is_valid_ether_addr(dev
->wiphy
->perm_addr
)) {
915 u8 perm_addr
[ETH_ALEN
];
917 wiphy_warn(dev
->wiphy
,
918 "Invalid hwaddr! Using randomly generated MAC addr\n");
919 eth_random_addr(perm_addr
);
920 SET_IEEE80211_PERM_ADDR(dev
, perm_addr
);
923 priv
->cur_rssi
= &p54_rssi_default
;
925 wiphy_info(dev
->wiphy
, "hwaddr %pM, MAC:isl38%02x RF:%s\n",
926 dev
->wiphy
->perm_addr
, priv
->version
,
927 p54_rf_chips
[priv
->rxhw
]);
932 kfree(priv
->iq_autocal
);
933 kfree(priv
->output_limit
);
934 kfree(priv
->curve_data
);
935 kfree(priv
->rssi_db
);
937 priv
->iq_autocal
= NULL
;
938 priv
->output_limit
= NULL
;
939 priv
->curve_data
= NULL
;
940 priv
->rssi_db
= NULL
;
943 wiphy_err(dev
->wiphy
, "eeprom parse failed!\n");
946 EXPORT_SYMBOL_GPL(p54_parse_eeprom
);
948 int p54_read_eeprom(struct ieee80211_hw
*dev
)
950 struct p54_common
*priv
= dev
->priv
;
951 size_t eeprom_size
= 0x2020, offset
= 0, blocksize
, maxblocksize
;
955 maxblocksize
= EEPROM_READBACK_LEN
;
956 if (priv
->fw_var
>= 0x509)
961 eeprom
= kzalloc(eeprom_size
, GFP_KERNEL
);
962 if (unlikely(!eeprom
))
965 while (eeprom_size
) {
966 blocksize
= min(eeprom_size
, maxblocksize
);
967 ret
= p54_download_eeprom(priv
, eeprom
+ offset
,
973 eeprom_size
-= blocksize
;
976 ret
= p54_parse_eeprom(dev
, eeprom
, offset
);
981 EXPORT_SYMBOL_GPL(p54_read_eeprom
);