eeprom.c 20 KB

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