eeprom.c 20 KB

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