eeprom.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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. #include <linux/init.h>
  19. #include <linux/firmware.h>
  20. #include <linux/etherdevice.h>
  21. #include <linux/sort.h>
  22. #include <net/mac80211.h>
  23. #include "p54.h"
  24. #include "eeprom.h"
  25. #include "lmac.h"
  26. static struct ieee80211_rate p54_bgrates[] = {
  27. { .bitrate = 10, .hw_value = 0, },
  28. { .bitrate = 20, .hw_value = 1, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  29. { .bitrate = 55, .hw_value = 2, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  30. { .bitrate = 110, .hw_value = 3, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  31. { .bitrate = 60, .hw_value = 4, },
  32. { .bitrate = 90, .hw_value = 5, },
  33. { .bitrate = 120, .hw_value = 6, },
  34. { .bitrate = 180, .hw_value = 7, },
  35. { .bitrate = 240, .hw_value = 8, },
  36. { .bitrate = 360, .hw_value = 9, },
  37. { .bitrate = 480, .hw_value = 10, },
  38. { .bitrate = 540, .hw_value = 11, },
  39. };
  40. static struct ieee80211_rate p54_arates[] = {
  41. { .bitrate = 60, .hw_value = 4, },
  42. { .bitrate = 90, .hw_value = 5, },
  43. { .bitrate = 120, .hw_value = 6, },
  44. { .bitrate = 180, .hw_value = 7, },
  45. { .bitrate = 240, .hw_value = 8, },
  46. { .bitrate = 360, .hw_value = 9, },
  47. { .bitrate = 480, .hw_value = 10, },
  48. { .bitrate = 540, .hw_value = 11, },
  49. };
  50. #define CHAN_HAS_CAL BIT(0)
  51. #define CHAN_HAS_LIMIT BIT(1)
  52. #define CHAN_HAS_CURVE BIT(2)
  53. #define CHAN_HAS_ALL (CHAN_HAS_CAL | CHAN_HAS_LIMIT | CHAN_HAS_CURVE)
  54. struct p54_channel_entry {
  55. u16 freq;
  56. u16 data;
  57. int index;
  58. enum ieee80211_band band;
  59. };
  60. struct p54_channel_list {
  61. struct p54_channel_entry *channels;
  62. size_t entries;
  63. size_t max_entries;
  64. size_t band_channel_num[IEEE80211_NUM_BANDS];
  65. };
  66. static int p54_get_band_from_freq(u16 freq)
  67. {
  68. /* FIXME: sync these values with the 802.11 spec */
  69. if ((freq >= 2412) && (freq <= 2484))
  70. return IEEE80211_BAND_2GHZ;
  71. if ((freq >= 4920) && (freq <= 5825))
  72. return IEEE80211_BAND_5GHZ;
  73. return -1;
  74. }
  75. static int p54_compare_channels(const void *_a,
  76. const void *_b)
  77. {
  78. const struct p54_channel_entry *a = _a;
  79. const struct p54_channel_entry *b = _b;
  80. return a->index - b->index;
  81. }
  82. static int p54_fill_band_bitrates(struct ieee80211_hw *dev,
  83. struct ieee80211_supported_band *band_entry,
  84. enum ieee80211_band band)
  85. {
  86. /* TODO: generate rate array dynamically */
  87. switch (band) {
  88. case IEEE80211_BAND_2GHZ:
  89. band_entry->bitrates = p54_bgrates;
  90. band_entry->n_bitrates = ARRAY_SIZE(p54_bgrates);
  91. break;
  92. case IEEE80211_BAND_5GHZ:
  93. band_entry->bitrates = p54_arates;
  94. band_entry->n_bitrates = ARRAY_SIZE(p54_arates);
  95. break;
  96. default:
  97. return -EINVAL;
  98. }
  99. return 0;
  100. }
  101. static int p54_generate_band(struct ieee80211_hw *dev,
  102. struct p54_channel_list *list,
  103. enum ieee80211_band band)
  104. {
  105. struct p54_common *priv = dev->priv;
  106. struct ieee80211_supported_band *tmp, *old;
  107. unsigned int i, j;
  108. int ret = -ENOMEM;
  109. if ((!list->entries) || (!list->band_channel_num[band]))
  110. return 0;
  111. tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
  112. if (!tmp)
  113. goto err_out;
  114. tmp->channels = kzalloc(sizeof(struct ieee80211_channel) *
  115. list->band_channel_num[band], GFP_KERNEL);
  116. if (!tmp->channels)
  117. goto err_out;
  118. ret = p54_fill_band_bitrates(dev, tmp, band);
  119. if (ret)
  120. goto err_out;
  121. for (i = 0, j = 0; (j < list->band_channel_num[band]) &&
  122. (i < list->entries); i++) {
  123. if (list->channels[i].band != band)
  124. continue;
  125. if (list->channels[i].data != CHAN_HAS_ALL) {
  126. printk(KERN_ERR "%s:%s%s%s is/are missing for "
  127. "channel:%d [%d MHz].\n",
  128. wiphy_name(dev->wiphy),
  129. (list->channels[i].data & CHAN_HAS_CAL ? "" :
  130. " [iqauto calibration data]"),
  131. (list->channels[i].data & CHAN_HAS_LIMIT ? "" :
  132. " [output power limits]"),
  133. (list->channels[i].data & CHAN_HAS_CURVE ? "" :
  134. " [curve data]"),
  135. list->channels[i].index, list->channels[i].freq);
  136. }
  137. tmp->channels[j].band = list->channels[i].band;
  138. tmp->channels[j].center_freq = list->channels[i].freq;
  139. j++;
  140. }
  141. tmp->n_channels = list->band_channel_num[band];
  142. old = priv->band_table[band];
  143. priv->band_table[band] = tmp;
  144. if (old) {
  145. kfree(old->channels);
  146. kfree(old);
  147. }
  148. return 0;
  149. err_out:
  150. if (tmp) {
  151. kfree(tmp->channels);
  152. kfree(tmp);
  153. }
  154. return ret;
  155. }
  156. static void p54_update_channel_param(struct p54_channel_list *list,
  157. u16 freq, u16 data)
  158. {
  159. int band, i;
  160. /*
  161. * usually all lists in the eeprom are mostly sorted.
  162. * so it's very likely that the entry we are looking for
  163. * is right at the end of the list
  164. */
  165. for (i = list->entries; i >= 0; i--) {
  166. if (freq == list->channels[i].freq) {
  167. list->channels[i].data |= data;
  168. break;
  169. }
  170. }
  171. if ((i < 0) && (list->entries < list->max_entries)) {
  172. /* entry does not exist yet. Initialize a new one. */
  173. band = p54_get_band_from_freq(freq);
  174. /*
  175. * filter out frequencies which don't belong into
  176. * any supported band.
  177. */
  178. if (band < 0)
  179. return ;
  180. i = list->entries++;
  181. list->band_channel_num[band]++;
  182. list->channels[i].freq = freq;
  183. list->channels[i].data = data;
  184. list->channels[i].band = band;
  185. list->channels[i].index = ieee80211_frequency_to_channel(freq);
  186. /* TODO: parse output_limit and fill max_power */
  187. }
  188. }
  189. static int p54_generate_channel_lists(struct ieee80211_hw *dev)
  190. {
  191. struct p54_common *priv = dev->priv;
  192. struct p54_channel_list *list;
  193. unsigned int i, j, max_channel_num;
  194. int ret = -ENOMEM;
  195. u16 freq;
  196. if ((priv->iq_autocal_len != priv->curve_data->entries) ||
  197. (priv->iq_autocal_len != priv->output_limit->entries))
  198. printk(KERN_ERR "%s: EEPROM is damaged... you may not be able"
  199. "to use all channels with this device.\n",
  200. wiphy_name(dev->wiphy));
  201. max_channel_num = max_t(unsigned int, priv->output_limit->entries,
  202. priv->iq_autocal_len);
  203. max_channel_num = max_t(unsigned int, max_channel_num,
  204. priv->curve_data->entries);
  205. list = kzalloc(sizeof(*list), GFP_KERNEL);
  206. if (!list)
  207. goto free;
  208. list->max_entries = max_channel_num;
  209. list->channels = kzalloc(sizeof(struct p54_channel_entry) *
  210. max_channel_num, GFP_KERNEL);
  211. if (!list->channels)
  212. goto free;
  213. for (i = 0; i < max_channel_num; i++) {
  214. if (i < priv->iq_autocal_len) {
  215. freq = le16_to_cpu(priv->iq_autocal[i].freq);
  216. p54_update_channel_param(list, freq, CHAN_HAS_CAL);
  217. }
  218. if (i < priv->output_limit->entries) {
  219. freq = le16_to_cpup((__le16 *) (i *
  220. priv->output_limit->entry_size +
  221. priv->output_limit->offset +
  222. priv->output_limit->data));
  223. p54_update_channel_param(list, freq, CHAN_HAS_LIMIT);
  224. }
  225. if (i < priv->curve_data->entries) {
  226. freq = le16_to_cpup((__le16 *) (i *
  227. priv->curve_data->entry_size +
  228. priv->curve_data->offset +
  229. priv->curve_data->data));
  230. p54_update_channel_param(list, freq, CHAN_HAS_CURVE);
  231. }
  232. }
  233. /* sort the list by the channel index */
  234. sort(list->channels, list->entries, sizeof(struct p54_channel_entry),
  235. p54_compare_channels, NULL);
  236. for (i = 0, j = 0; i < IEEE80211_NUM_BANDS; i++) {
  237. if (list->band_channel_num[i]) {
  238. ret = p54_generate_band(dev, list, i);
  239. if (ret)
  240. goto free;
  241. j++;
  242. }
  243. }
  244. if (j == 0) {
  245. /* no useable band available. */
  246. ret = -EINVAL;
  247. }
  248. free:
  249. if (list) {
  250. kfree(list->channels);
  251. kfree(list);
  252. }
  253. return ret;
  254. }
  255. static int p54_convert_rev0(struct ieee80211_hw *dev,
  256. struct pda_pa_curve_data *curve_data)
  257. {
  258. struct p54_common *priv = dev->priv;
  259. struct p54_pa_curve_data_sample *dst;
  260. struct pda_pa_curve_data_sample_rev0 *src;
  261. size_t cd_len = sizeof(*curve_data) +
  262. (curve_data->points_per_channel*sizeof(*dst) + 2) *
  263. curve_data->channels;
  264. unsigned int i, j;
  265. void *source, *target;
  266. priv->curve_data = kmalloc(sizeof(*priv->curve_data) + cd_len,
  267. GFP_KERNEL);
  268. if (!priv->curve_data)
  269. return -ENOMEM;
  270. priv->curve_data->entries = curve_data->channels;
  271. priv->curve_data->entry_size = sizeof(__le16) +
  272. sizeof(*dst) * curve_data->points_per_channel;
  273. priv->curve_data->offset = offsetof(struct pda_pa_curve_data, data);
  274. priv->curve_data->len = cd_len;
  275. memcpy(priv->curve_data->data, curve_data, sizeof(*curve_data));
  276. source = curve_data->data;
  277. target = ((struct pda_pa_curve_data *) priv->curve_data->data)->data;
  278. for (i = 0; i < curve_data->channels; i++) {
  279. __le16 *freq = source;
  280. source += sizeof(__le16);
  281. *((__le16 *)target) = *freq;
  282. target += sizeof(__le16);
  283. for (j = 0; j < curve_data->points_per_channel; j++) {
  284. dst = target;
  285. src = source;
  286. dst->rf_power = src->rf_power;
  287. dst->pa_detector = src->pa_detector;
  288. dst->data_64qam = src->pcv;
  289. /* "invent" the points for the other modulations */
  290. #define SUB(x, y) (u8)(((x) - (y)) > (x) ? 0 : (x) - (y))
  291. dst->data_16qam = SUB(src->pcv, 12);
  292. dst->data_qpsk = SUB(dst->data_16qam, 12);
  293. dst->data_bpsk = SUB(dst->data_qpsk, 12);
  294. dst->data_barker = SUB(dst->data_bpsk, 14);
  295. #undef SUB
  296. target += sizeof(*dst);
  297. source += sizeof(*src);
  298. }
  299. }
  300. return 0;
  301. }
  302. static int p54_convert_rev1(struct ieee80211_hw *dev,
  303. struct pda_pa_curve_data *curve_data)
  304. {
  305. struct p54_common *priv = dev->priv;
  306. struct p54_pa_curve_data_sample *dst;
  307. struct pda_pa_curve_data_sample_rev1 *src;
  308. size_t cd_len = sizeof(*curve_data) +
  309. (curve_data->points_per_channel*sizeof(*dst) + 2) *
  310. curve_data->channels;
  311. unsigned int i, j;
  312. void *source, *target;
  313. priv->curve_data = kzalloc(cd_len + sizeof(*priv->curve_data),
  314. GFP_KERNEL);
  315. if (!priv->curve_data)
  316. return -ENOMEM;
  317. priv->curve_data->entries = curve_data->channels;
  318. priv->curve_data->entry_size = sizeof(__le16) +
  319. sizeof(*dst) * curve_data->points_per_channel;
  320. priv->curve_data->offset = offsetof(struct pda_pa_curve_data, data);
  321. priv->curve_data->len = cd_len;
  322. memcpy(priv->curve_data->data, curve_data, sizeof(*curve_data));
  323. source = curve_data->data;
  324. target = ((struct pda_pa_curve_data *) priv->curve_data->data)->data;
  325. for (i = 0; i < curve_data->channels; i++) {
  326. __le16 *freq = source;
  327. source += sizeof(__le16);
  328. *((__le16 *)target) = *freq;
  329. target += sizeof(__le16);
  330. for (j = 0; j < curve_data->points_per_channel; j++) {
  331. memcpy(target, source, sizeof(*src));
  332. target += sizeof(*dst);
  333. source += sizeof(*src);
  334. }
  335. source++;
  336. }
  337. return 0;
  338. }
  339. static const char *p54_rf_chips[] = { "INVALID-0", "Duette3", "Duette2",
  340. "Frisbee", "Xbow", "Longbow", "INVALID-6", "INVALID-7" };
  341. static void p54_parse_rssical(struct ieee80211_hw *dev, void *data, int len,
  342. u16 type)
  343. {
  344. struct p54_common *priv = dev->priv;
  345. int offset = (type == PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED) ? 2 : 0;
  346. int entry_size = sizeof(struct pda_rssi_cal_entry) + offset;
  347. int num_entries = (type == PDR_RSSI_LINEAR_APPROXIMATION) ? 1 : 2;
  348. int i;
  349. if (len != (entry_size * num_entries)) {
  350. printk(KERN_ERR "%s: unknown rssi calibration data packing "
  351. " type:(%x) len:%d.\n",
  352. wiphy_name(dev->wiphy), type, len);
  353. print_hex_dump_bytes("rssical:", DUMP_PREFIX_NONE,
  354. data, len);
  355. printk(KERN_ERR "%s: please report this issue.\n",
  356. wiphy_name(dev->wiphy));
  357. return;
  358. }
  359. for (i = 0; i < num_entries; i++) {
  360. struct pda_rssi_cal_entry *cal = data +
  361. (offset + i * entry_size);
  362. priv->rssical_db[i].mul = (s16) le16_to_cpu(cal->mul);
  363. priv->rssical_db[i].add = (s16) le16_to_cpu(cal->add);
  364. }
  365. }
  366. static void p54_parse_default_country(struct ieee80211_hw *dev,
  367. void *data, int len)
  368. {
  369. struct pda_country *country;
  370. if (len != sizeof(*country)) {
  371. printk(KERN_ERR "%s: found possible invalid default country "
  372. "eeprom entry. (entry size: %d)\n",
  373. wiphy_name(dev->wiphy), len);
  374. print_hex_dump_bytes("country:", DUMP_PREFIX_NONE,
  375. data, len);
  376. printk(KERN_ERR "%s: please report this issue.\n",
  377. wiphy_name(dev->wiphy));
  378. return;
  379. }
  380. country = (struct pda_country *) data;
  381. if (country->flags == PDR_COUNTRY_CERT_CODE_PSEUDO)
  382. regulatory_hint(dev->wiphy, country->alpha2);
  383. else {
  384. /* TODO:
  385. * write a shared/common function that converts
  386. * "Regulatory domain codes" (802.11-2007 14.8.2.2)
  387. * into ISO/IEC 3166-1 alpha2 for regulatory_hint.
  388. */
  389. }
  390. }
  391. static int p54_convert_output_limits(struct ieee80211_hw *dev,
  392. u8 *data, size_t len)
  393. {
  394. struct p54_common *priv = dev->priv;
  395. if (len < 2)
  396. return -EINVAL;
  397. if (data[0] != 0) {
  398. printk(KERN_ERR "%s: unknown output power db revision:%x\n",
  399. wiphy_name(dev->wiphy), data[0]);
  400. return -EINVAL;
  401. }
  402. if (2 + data[1] * sizeof(struct pda_channel_output_limit) > len)
  403. return -EINVAL;
  404. priv->output_limit = kmalloc(data[1] *
  405. sizeof(struct pda_channel_output_limit) +
  406. sizeof(*priv->output_limit), GFP_KERNEL);
  407. if (!priv->output_limit)
  408. return -ENOMEM;
  409. priv->output_limit->offset = 0;
  410. priv->output_limit->entries = data[1];
  411. priv->output_limit->entry_size =
  412. sizeof(struct pda_channel_output_limit);
  413. priv->output_limit->len = priv->output_limit->entry_size *
  414. priv->output_limit->entries +
  415. priv->output_limit->offset;
  416. memcpy(priv->output_limit->data, &data[2],
  417. data[1] * sizeof(struct pda_channel_output_limit));
  418. return 0;
  419. }
  420. static struct p54_cal_database *p54_convert_db(struct pda_custom_wrapper *src,
  421. size_t total_len)
  422. {
  423. struct p54_cal_database *dst;
  424. size_t payload_len, entries, entry_size, offset;
  425. payload_len = le16_to_cpu(src->len);
  426. entries = le16_to_cpu(src->entries);
  427. entry_size = le16_to_cpu(src->entry_size);
  428. offset = le16_to_cpu(src->offset);
  429. if (((entries * entry_size + offset) != payload_len) ||
  430. (payload_len + sizeof(*src) != total_len))
  431. return NULL;
  432. dst = kmalloc(sizeof(*dst) + payload_len, GFP_KERNEL);
  433. if (!dst)
  434. return NULL;
  435. dst->entries = entries;
  436. dst->entry_size = entry_size;
  437. dst->offset = offset;
  438. dst->len = payload_len;
  439. memcpy(dst->data, src->data, payload_len);
  440. return dst;
  441. }
  442. int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
  443. {
  444. struct p54_common *priv = dev->priv;
  445. struct eeprom_pda_wrap *wrap;
  446. struct pda_entry *entry;
  447. unsigned int data_len, entry_len;
  448. void *tmp;
  449. int err;
  450. u8 *end = (u8 *)eeprom + len;
  451. u16 synth = 0;
  452. wrap = (struct eeprom_pda_wrap *) eeprom;
  453. entry = (void *)wrap->data + le16_to_cpu(wrap->len);
  454. /* verify that at least the entry length/code fits */
  455. while ((u8 *)entry <= end - sizeof(*entry)) {
  456. entry_len = le16_to_cpu(entry->len);
  457. data_len = ((entry_len - 1) << 1);
  458. /* abort if entry exceeds whole structure */
  459. if ((u8 *)entry + sizeof(*entry) + data_len > end)
  460. break;
  461. switch (le16_to_cpu(entry->code)) {
  462. case PDR_MAC_ADDRESS:
  463. if (data_len != ETH_ALEN)
  464. break;
  465. SET_IEEE80211_PERM_ADDR(dev, entry->data);
  466. break;
  467. case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS:
  468. if (priv->output_limit)
  469. break;
  470. err = p54_convert_output_limits(dev, entry->data,
  471. data_len);
  472. if (err)
  473. goto err;
  474. break;
  475. case PDR_PRISM_PA_CAL_CURVE_DATA: {
  476. struct pda_pa_curve_data *curve_data =
  477. (struct pda_pa_curve_data *)entry->data;
  478. if (data_len < sizeof(*curve_data)) {
  479. err = -EINVAL;
  480. goto err;
  481. }
  482. switch (curve_data->cal_method_rev) {
  483. case 0:
  484. err = p54_convert_rev0(dev, curve_data);
  485. break;
  486. case 1:
  487. err = p54_convert_rev1(dev, curve_data);
  488. break;
  489. default:
  490. printk(KERN_ERR "%s: unknown curve data "
  491. "revision %d\n",
  492. wiphy_name(dev->wiphy),
  493. curve_data->cal_method_rev);
  494. err = -ENODEV;
  495. break;
  496. }
  497. if (err)
  498. goto err;
  499. }
  500. break;
  501. case PDR_PRISM_ZIF_TX_IQ_CALIBRATION:
  502. priv->iq_autocal = kmalloc(data_len, GFP_KERNEL);
  503. if (!priv->iq_autocal) {
  504. err = -ENOMEM;
  505. goto err;
  506. }
  507. memcpy(priv->iq_autocal, entry->data, data_len);
  508. priv->iq_autocal_len = data_len / sizeof(struct pda_iq_autocal_entry);
  509. break;
  510. case PDR_DEFAULT_COUNTRY:
  511. p54_parse_default_country(dev, entry->data, data_len);
  512. break;
  513. case PDR_INTERFACE_LIST:
  514. tmp = entry->data;
  515. while ((u8 *)tmp < entry->data + data_len) {
  516. struct exp_if *exp_if = tmp;
  517. if (exp_if->if_id == cpu_to_le16(IF_ID_ISL39000))
  518. synth = le16_to_cpu(exp_if->variant);
  519. tmp += sizeof(*exp_if);
  520. }
  521. break;
  522. case PDR_HARDWARE_PLATFORM_COMPONENT_ID:
  523. if (data_len < 2)
  524. break;
  525. priv->version = *(u8 *)(entry->data + 1);
  526. break;
  527. case PDR_RSSI_LINEAR_APPROXIMATION:
  528. case PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND:
  529. case PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED:
  530. p54_parse_rssical(dev, entry->data, data_len,
  531. le16_to_cpu(entry->code));
  532. break;
  533. case PDR_RSSI_LINEAR_APPROXIMATION_CUSTOM: {
  534. __le16 *src = (void *) entry->data;
  535. s16 *dst = (void *) &priv->rssical_db;
  536. int i;
  537. if (data_len != sizeof(priv->rssical_db)) {
  538. err = -EINVAL;
  539. goto err;
  540. }
  541. for (i = 0; i < sizeof(priv->rssical_db) /
  542. sizeof(*src); i++)
  543. *(dst++) = (s16) le16_to_cpu(*(src++));
  544. }
  545. break;
  546. case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS_CUSTOM: {
  547. struct pda_custom_wrapper *pda = (void *) entry->data;
  548. if (priv->output_limit || data_len < sizeof(*pda))
  549. break;
  550. priv->output_limit = p54_convert_db(pda, data_len);
  551. }
  552. break;
  553. case PDR_PRISM_PA_CAL_CURVE_DATA_CUSTOM: {
  554. struct pda_custom_wrapper *pda = (void *) entry->data;
  555. if (priv->curve_data || data_len < sizeof(*pda))
  556. break;
  557. priv->curve_data = p54_convert_db(pda, data_len);
  558. }
  559. break;
  560. case PDR_END:
  561. /* make it overrun */
  562. entry_len = len;
  563. break;
  564. default:
  565. break;
  566. }
  567. entry = (void *)entry + (entry_len + 1)*2;
  568. }
  569. if (!synth || !priv->iq_autocal || !priv->output_limit ||
  570. !priv->curve_data) {
  571. printk(KERN_ERR "%s: not all required entries found in eeprom!\n",
  572. wiphy_name(dev->wiphy));
  573. err = -EINVAL;
  574. goto err;
  575. }
  576. err = p54_generate_channel_lists(dev);
  577. if (err)
  578. goto err;
  579. priv->rxhw = synth & PDR_SYNTH_FRONTEND_MASK;
  580. if (priv->rxhw == PDR_SYNTH_FRONTEND_XBOW)
  581. p54_init_xbow_synth(priv);
  582. if (!(synth & PDR_SYNTH_24_GHZ_DISABLED))
  583. dev->wiphy->bands[IEEE80211_BAND_2GHZ] =
  584. priv->band_table[IEEE80211_BAND_2GHZ];
  585. if (!(synth & PDR_SYNTH_5_GHZ_DISABLED))
  586. dev->wiphy->bands[IEEE80211_BAND_5GHZ] =
  587. priv->band_table[IEEE80211_BAND_5GHZ];
  588. if ((synth & PDR_SYNTH_RX_DIV_MASK) == PDR_SYNTH_RX_DIV_SUPPORTED)
  589. priv->rx_diversity_mask = 3;
  590. if ((synth & PDR_SYNTH_TX_DIV_MASK) == PDR_SYNTH_TX_DIV_SUPPORTED)
  591. priv->tx_diversity_mask = 3;
  592. if (!is_valid_ether_addr(dev->wiphy->perm_addr)) {
  593. u8 perm_addr[ETH_ALEN];
  594. printk(KERN_WARNING "%s: Invalid hwaddr! Using randomly generated MAC addr\n",
  595. wiphy_name(dev->wiphy));
  596. random_ether_addr(perm_addr);
  597. SET_IEEE80211_PERM_ADDR(dev, perm_addr);
  598. }
  599. printk(KERN_INFO "%s: hwaddr %pM, MAC:isl38%02x RF:%s\n",
  600. wiphy_name(dev->wiphy), dev->wiphy->perm_addr, priv->version,
  601. p54_rf_chips[priv->rxhw]);
  602. return 0;
  603. err:
  604. kfree(priv->iq_autocal);
  605. kfree(priv->output_limit);
  606. kfree(priv->curve_data);
  607. priv->iq_autocal = NULL;
  608. priv->output_limit = NULL;
  609. priv->curve_data = NULL;
  610. printk(KERN_ERR "%s: eeprom parse failed!\n",
  611. wiphy_name(dev->wiphy));
  612. return err;
  613. }
  614. EXPORT_SYMBOL_GPL(p54_parse_eeprom);
  615. int p54_read_eeprom(struct ieee80211_hw *dev)
  616. {
  617. struct p54_common *priv = dev->priv;
  618. size_t eeprom_size = 0x2020, offset = 0, blocksize, maxblocksize;
  619. int ret = -ENOMEM;
  620. void *eeprom;
  621. maxblocksize = EEPROM_READBACK_LEN;
  622. if (priv->fw_var >= 0x509)
  623. maxblocksize -= 0xc;
  624. else
  625. maxblocksize -= 0x4;
  626. eeprom = kzalloc(eeprom_size, GFP_KERNEL);
  627. if (unlikely(!eeprom))
  628. goto free;
  629. while (eeprom_size) {
  630. blocksize = min(eeprom_size, maxblocksize);
  631. ret = p54_download_eeprom(priv, (void *) (eeprom + offset),
  632. offset, blocksize);
  633. if (unlikely(ret))
  634. goto free;
  635. offset += blocksize;
  636. eeprom_size -= blocksize;
  637. }
  638. ret = p54_parse_eeprom(dev, eeprom, offset);
  639. free:
  640. kfree(eeprom);
  641. return ret;
  642. }
  643. EXPORT_SYMBOL_GPL(p54_read_eeprom);