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