hermes_dld.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /*
  2. * Hermes download helper.
  3. *
  4. * This helper:
  5. * - is capable of writing to the volatile area of the hermes device
  6. * - is currently not capable of writing to non-volatile areas
  7. * - provide helpers to identify and update plugin data
  8. * - is not capable of interpreting a fw image directly. That is up to
  9. * the main card driver.
  10. * - deals with Hermes I devices. It can probably be modified to deal
  11. * with Hermes II devices
  12. *
  13. * Copyright (C) 2007, David Kilroy
  14. *
  15. * Plug data code slightly modified from spectrum_cs driver
  16. * Copyright (C) 2002-2005 Pavel Roskin <proski@gnu.org>
  17. * Portions based on information in wl_lkm_718 Agere driver
  18. * COPYRIGHT (C) 2001-2004 by Agere Systems Inc. All Rights Reserved
  19. *
  20. * The contents of this file are subject to the Mozilla Public License
  21. * Version 1.1 (the "License"); you may not use this file except in
  22. * compliance with the License. You may obtain a copy of the License
  23. * at http://www.mozilla.org/MPL/
  24. *
  25. * Software distributed under the License is distributed on an "AS IS"
  26. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  27. * the License for the specific language governing rights and
  28. * limitations under the License.
  29. *
  30. * Alternatively, the contents of this file may be used under the
  31. * terms of the GNU General Public License version 2 (the "GPL"), in
  32. * which case the provisions of the GPL are applicable instead of the
  33. * above. If you wish to allow the use of your version of this file
  34. * only under the terms of the GPL and not to allow others to use your
  35. * version of this file under the MPL, indicate your decision by
  36. * deleting the provisions above and replace them with the notice and
  37. * other provisions required by the GPL. If you do not delete the
  38. * provisions above, a recipient may use your version of this file
  39. * under either the MPL or the GPL.
  40. */
  41. #include <linux/module.h>
  42. #include <linux/delay.h>
  43. #include "hermes.h"
  44. #include "hermes_dld.h"
  45. #define PFX "hermes_dld: "
  46. /*
  47. * AUX port access. To unlock the AUX port write the access keys to the
  48. * PARAM0-2 registers, then write HERMES_AUX_ENABLE to the HERMES_CONTROL
  49. * register. Then read it and make sure it's HERMES_AUX_ENABLED.
  50. */
  51. #define HERMES_AUX_ENABLE 0x8000 /* Enable auxiliary port access */
  52. #define HERMES_AUX_DISABLE 0x4000 /* Disable to auxiliary port access */
  53. #define HERMES_AUX_ENABLED 0xC000 /* Auxiliary port is open */
  54. #define HERMES_AUX_DISABLED 0x0000 /* Auxiliary port is closed */
  55. #define HERMES_AUX_PW0 0xFE01
  56. #define HERMES_AUX_PW1 0xDC23
  57. #define HERMES_AUX_PW2 0xBA45
  58. /* HERMES_CMD_DOWNLD */
  59. #define HERMES_PROGRAM_DISABLE (0x0000 | HERMES_CMD_DOWNLD)
  60. #define HERMES_PROGRAM_ENABLE_VOLATILE (0x0100 | HERMES_CMD_DOWNLD)
  61. #define HERMES_PROGRAM_ENABLE_NON_VOLATILE (0x0200 | HERMES_CMD_DOWNLD)
  62. #define HERMES_PROGRAM_NON_VOLATILE (0x0300 | HERMES_CMD_DOWNLD)
  63. /* End markers used in dblocks */
  64. #define PDI_END 0x00000000 /* End of PDA */
  65. #define BLOCK_END 0xFFFFFFFF /* Last image block */
  66. #define TEXT_END 0x1A /* End of text header */
  67. /* Limit the amout we try to download in a single shot.
  68. * Size is in bytes.
  69. */
  70. #define MAX_DL_SIZE 1024
  71. #define LIMIT_PROGRAM_SIZE 0
  72. /*
  73. * The following structures have little-endian fields denoted by
  74. * the leading underscore. Don't access them directly - use inline
  75. * functions defined below.
  76. */
  77. /*
  78. * The binary image to be downloaded consists of series of data blocks.
  79. * Each block has the following structure.
  80. */
  81. struct dblock {
  82. __le32 addr; /* adapter address where to write the block */
  83. __le16 len; /* length of the data only, in bytes */
  84. char data[0]; /* data to be written */
  85. } __attribute__ ((packed));
  86. /*
  87. * Plug Data References are located in in the image after the last data
  88. * block. They refer to areas in the adapter memory where the plug data
  89. * items with matching ID should be written.
  90. */
  91. struct pdr {
  92. __le32 id; /* record ID */
  93. __le32 addr; /* adapter address where to write the data */
  94. __le32 len; /* expected length of the data, in bytes */
  95. char next[0]; /* next PDR starts here */
  96. } __attribute__ ((packed));
  97. /*
  98. * Plug Data Items are located in the EEPROM read from the adapter by
  99. * primary firmware. They refer to the device-specific data that should
  100. * be plugged into the secondary firmware.
  101. */
  102. struct pdi {
  103. __le16 len; /* length of ID and data, in words */
  104. __le16 id; /* record ID */
  105. char data[0]; /* plug data */
  106. } __attribute__ ((packed));
  107. /*** FW data block access functions ***/
  108. static inline u32
  109. dblock_addr(const struct dblock *blk)
  110. {
  111. return le32_to_cpu(blk->addr);
  112. }
  113. static inline u32
  114. dblock_len(const struct dblock *blk)
  115. {
  116. return le16_to_cpu(blk->len);
  117. }
  118. /*** PDR Access functions ***/
  119. static inline u32
  120. pdr_id(const struct pdr *pdr)
  121. {
  122. return le32_to_cpu(pdr->id);
  123. }
  124. static inline u32
  125. pdr_addr(const struct pdr *pdr)
  126. {
  127. return le32_to_cpu(pdr->addr);
  128. }
  129. static inline u32
  130. pdr_len(const struct pdr *pdr)
  131. {
  132. return le32_to_cpu(pdr->len);
  133. }
  134. /*** PDI Access functions ***/
  135. static inline u32
  136. pdi_id(const struct pdi *pdi)
  137. {
  138. return le16_to_cpu(pdi->id);
  139. }
  140. /* Return length of the data only, in bytes */
  141. static inline u32
  142. pdi_len(const struct pdi *pdi)
  143. {
  144. return 2 * (le16_to_cpu(pdi->len) - 1);
  145. }
  146. /*** Hermes AUX control ***/
  147. static inline void
  148. hermes_aux_setaddr(hermes_t *hw, u32 addr)
  149. {
  150. hermes_write_reg(hw, HERMES_AUXPAGE, (u16) (addr >> 7));
  151. hermes_write_reg(hw, HERMES_AUXOFFSET, (u16) (addr & 0x7F));
  152. }
  153. static inline int
  154. hermes_aux_control(hermes_t *hw, int enabled)
  155. {
  156. int desired_state = enabled ? HERMES_AUX_ENABLED : HERMES_AUX_DISABLED;
  157. int action = enabled ? HERMES_AUX_ENABLE : HERMES_AUX_DISABLE;
  158. int i;
  159. /* Already open? */
  160. if (hermes_read_reg(hw, HERMES_CONTROL) == desired_state)
  161. return 0;
  162. hermes_write_reg(hw, HERMES_PARAM0, HERMES_AUX_PW0);
  163. hermes_write_reg(hw, HERMES_PARAM1, HERMES_AUX_PW1);
  164. hermes_write_reg(hw, HERMES_PARAM2, HERMES_AUX_PW2);
  165. hermes_write_reg(hw, HERMES_CONTROL, action);
  166. for (i = 0; i < 20; i++) {
  167. udelay(10);
  168. if (hermes_read_reg(hw, HERMES_CONTROL) ==
  169. desired_state)
  170. return 0;
  171. }
  172. return -EBUSY;
  173. }
  174. /*** Plug Data Functions ***/
  175. /*
  176. * Scan PDR for the record with the specified RECORD_ID.
  177. * If it's not found, return NULL.
  178. */
  179. static const struct pdr *
  180. hermes_find_pdr(const struct pdr *first_pdr, u32 record_id, const void *end)
  181. {
  182. const struct pdr *pdr = first_pdr;
  183. end -= sizeof(struct pdr);
  184. while (((void *) pdr <= end) &&
  185. (pdr_id(pdr) != PDI_END)) {
  186. /*
  187. * PDR area is currently not terminated by PDI_END.
  188. * It's followed by CRC records, which have the type
  189. * field where PDR has length. The type can be 0 or 1.
  190. */
  191. if (pdr_len(pdr) < 2)
  192. return NULL;
  193. /* If the record ID matches, we are done */
  194. if (pdr_id(pdr) == record_id)
  195. return pdr;
  196. pdr = (struct pdr *) pdr->next;
  197. }
  198. return NULL;
  199. }
  200. /* Scan production data items for a particular entry */
  201. static const struct pdi *
  202. hermes_find_pdi(const struct pdi *first_pdi, u32 record_id, const void *end)
  203. {
  204. const struct pdi *pdi = first_pdi;
  205. end -= sizeof(struct pdi);
  206. while (((void *) pdi <= end) &&
  207. (pdi_id(pdi) != PDI_END)) {
  208. /* If the record ID matches, we are done */
  209. if (pdi_id(pdi) == record_id)
  210. return pdi;
  211. pdi = (struct pdi *) &pdi->data[pdi_len(pdi)];
  212. }
  213. return NULL;
  214. }
  215. /* Process one Plug Data Item - find corresponding PDR and plug it */
  216. static int
  217. hermes_plug_pdi(hermes_t *hw, const struct pdr *first_pdr,
  218. const struct pdi *pdi, const void *pdr_end)
  219. {
  220. const struct pdr *pdr;
  221. /* Find the PDR corresponding to this PDI */
  222. pdr = hermes_find_pdr(first_pdr, pdi_id(pdi), pdr_end);
  223. /* No match is found, safe to ignore */
  224. if (!pdr)
  225. return 0;
  226. /* Lengths of the data in PDI and PDR must match */
  227. if (pdi_len(pdi) != pdr_len(pdr))
  228. return -EINVAL;
  229. /* do the actual plugging */
  230. hermes_aux_setaddr(hw, pdr_addr(pdr));
  231. hermes_write_bytes(hw, HERMES_AUXDATA, pdi->data, pdi_len(pdi));
  232. return 0;
  233. }
  234. /* Read PDA from the adapter */
  235. int hermes_read_pda(hermes_t *hw,
  236. __le16 *pda,
  237. u32 pda_addr,
  238. u16 pda_len,
  239. int use_eeprom) /* can we get this into hw? */
  240. {
  241. int ret;
  242. u16 pda_size;
  243. u16 data_len = pda_len;
  244. __le16 *data = pda;
  245. if (use_eeprom) {
  246. /* PDA of spectrum symbol is in eeprom */
  247. /* Issue command to read EEPROM */
  248. ret = hermes_docmd_wait(hw, HERMES_CMD_READMIF, 0, NULL);
  249. if (ret)
  250. return ret;
  251. } else {
  252. /* wl_lkm does not include PDA size in the PDA area.
  253. * We will pad the information into pda, so other routines
  254. * don't have to be modified */
  255. pda[0] = cpu_to_le16(pda_len - 2);
  256. /* Includes CFG_PROD_DATA but not itself */
  257. pda[1] = cpu_to_le16(0x0800); /* CFG_PROD_DATA */
  258. data_len = pda_len - 4;
  259. data = pda + 2;
  260. }
  261. /* Open auxiliary port */
  262. ret = hermes_aux_control(hw, 1);
  263. pr_debug(PFX "AUX enable returned %d\n", ret);
  264. if (ret)
  265. return ret;
  266. /* read PDA from EEPROM */
  267. hermes_aux_setaddr(hw, pda_addr);
  268. hermes_read_words(hw, HERMES_AUXDATA, data, data_len / 2);
  269. /* Close aux port */
  270. ret = hermes_aux_control(hw, 0);
  271. pr_debug(PFX "AUX disable returned %d\n", ret);
  272. /* Check PDA length */
  273. pda_size = le16_to_cpu(pda[0]);
  274. pr_debug(PFX "Actual PDA length %d, Max allowed %d\n",
  275. pda_size, pda_len);
  276. if (pda_size > pda_len)
  277. return -EINVAL;
  278. return 0;
  279. }
  280. /* Parse PDA and write the records into the adapter
  281. *
  282. * Attempt to write every records that is in the specified pda
  283. * which also has a valid production data record for the firmware.
  284. */
  285. int hermes_apply_pda(hermes_t *hw,
  286. const char *first_pdr,
  287. const void *pdr_end,
  288. const __le16 *pda,
  289. const void *pda_end)
  290. {
  291. int ret;
  292. const struct pdi *pdi;
  293. const struct pdr *pdr;
  294. pdr = (const struct pdr *) first_pdr;
  295. pda_end -= sizeof(struct pdi);
  296. /* Go through every PDI and plug them into the adapter */
  297. pdi = (const struct pdi *) (pda + 2);
  298. while (((void *) pdi <= pda_end) &&
  299. (pdi_id(pdi) != PDI_END)) {
  300. ret = hermes_plug_pdi(hw, pdr, pdi, pdr_end);
  301. if (ret)
  302. return ret;
  303. /* Increment to the next PDI */
  304. pdi = (const struct pdi *) &pdi->data[pdi_len(pdi)];
  305. }
  306. return 0;
  307. }
  308. /* Identify the total number of bytes in all blocks
  309. * including the header data.
  310. */
  311. size_t
  312. hermes_blocks_length(const char *first_block, const void *end)
  313. {
  314. const struct dblock *blk = (const struct dblock *) first_block;
  315. int total_len = 0;
  316. int len;
  317. end -= sizeof(*blk);
  318. /* Skip all blocks to locate Plug Data References
  319. * (Spectrum CS) */
  320. while (((void *) blk <= end) &&
  321. (dblock_addr(blk) != BLOCK_END)) {
  322. len = dblock_len(blk);
  323. total_len += sizeof(*blk) + len;
  324. blk = (struct dblock *) &blk->data[len];
  325. }
  326. return total_len;
  327. }
  328. /*** Hermes programming ***/
  329. /* About to start programming data (Hermes I)
  330. * offset is the entry point
  331. *
  332. * Spectrum_cs' Symbol fw does not require this
  333. * wl_lkm Agere fw does
  334. * Don't know about intersil
  335. */
  336. int hermesi_program_init(hermes_t *hw, u32 offset)
  337. {
  338. int err;
  339. /* Disable interrupts?*/
  340. /*hw->inten = 0x0;*/
  341. /*hermes_write_regn(hw, INTEN, 0);*/
  342. /*hermes_set_irqmask(hw, 0);*/
  343. /* Acknowledge any outstanding command */
  344. hermes_write_regn(hw, EVACK, 0xFFFF);
  345. /* Using doicmd_wait rather than docmd_wait */
  346. err = hermes_doicmd_wait(hw,
  347. 0x0100 | HERMES_CMD_INIT,
  348. 0, 0, 0, NULL);
  349. if (err)
  350. return err;
  351. err = hermes_doicmd_wait(hw,
  352. 0x0000 | HERMES_CMD_INIT,
  353. 0, 0, 0, NULL);
  354. if (err)
  355. return err;
  356. err = hermes_aux_control(hw, 1);
  357. pr_debug(PFX "AUX enable returned %d\n", err);
  358. if (err)
  359. return err;
  360. pr_debug(KERN_DEBUG PFX "Enabling volatile, EP 0x%08x\n", offset);
  361. err = hermes_doicmd_wait(hw,
  362. HERMES_PROGRAM_ENABLE_VOLATILE,
  363. offset & 0xFFFFu,
  364. offset >> 16,
  365. 0,
  366. NULL);
  367. pr_debug(PFX "PROGRAM_ENABLE returned %d\n", err);
  368. return err;
  369. }
  370. /* Done programming data (Hermes I)
  371. *
  372. * Spectrum_cs' Symbol fw does not require this
  373. * wl_lkm Agere fw does
  374. * Don't know about intersil
  375. */
  376. int hermesi_program_end(hermes_t *hw)
  377. {
  378. struct hermes_response resp;
  379. int rc = 0;
  380. int err;
  381. rc = hermes_docmd_wait(hw, HERMES_PROGRAM_DISABLE, 0, &resp);
  382. pr_debug(PFX "PROGRAM_DISABLE returned %d, "
  383. "r0 0x%04x, r1 0x%04x, r2 0x%04x\n",
  384. rc, resp.resp0, resp.resp1, resp.resp2);
  385. if ((rc == 0) &&
  386. ((resp.status & HERMES_STATUS_CMDCODE) != HERMES_CMD_DOWNLD))
  387. rc = -EIO;
  388. err = hermes_aux_control(hw, 0);
  389. pr_debug(PFX "AUX disable returned %d\n", err);
  390. /* Acknowledge any outstanding command */
  391. hermes_write_regn(hw, EVACK, 0xFFFF);
  392. /* Reinitialise, ignoring return */
  393. (void) hermes_doicmd_wait(hw, 0x0000 | HERMES_CMD_INIT,
  394. 0, 0, 0, NULL);
  395. return rc ? rc : err;
  396. }
  397. /* Program the data blocks */
  398. int hermes_program(hermes_t *hw, const char *first_block, const void *end)
  399. {
  400. const struct dblock *blk;
  401. u32 blkaddr;
  402. u32 blklen;
  403. #if LIMIT_PROGRAM_SIZE
  404. u32 addr;
  405. u32 len;
  406. #endif
  407. blk = (const struct dblock *) first_block;
  408. if ((void *) blk > (end - sizeof(*blk)))
  409. return -EIO;
  410. blkaddr = dblock_addr(blk);
  411. blklen = dblock_len(blk);
  412. while ((blkaddr != BLOCK_END) &&
  413. (((void *) blk + blklen) <= end)) {
  414. pr_debug(PFX "Programming block of length %d "
  415. "to address 0x%08x\n", blklen, blkaddr);
  416. #if !LIMIT_PROGRAM_SIZE
  417. /* wl_lkm driver splits this into writes of 2000 bytes */
  418. hermes_aux_setaddr(hw, blkaddr);
  419. hermes_write_bytes(hw, HERMES_AUXDATA, blk->data,
  420. blklen);
  421. #else
  422. len = (blklen < MAX_DL_SIZE) ? blklen : MAX_DL_SIZE;
  423. addr = blkaddr;
  424. while (addr < (blkaddr + blklen)) {
  425. pr_debug(PFX "Programming subblock of length %d "
  426. "to address 0x%08x. Data @ %p\n",
  427. len, addr, &blk->data[addr - blkaddr]);
  428. hermes_aux_setaddr(hw, addr);
  429. hermes_write_bytes(hw, HERMES_AUXDATA,
  430. &blk->data[addr - blkaddr],
  431. len);
  432. addr += len;
  433. len = ((blkaddr + blklen - addr) < MAX_DL_SIZE) ?
  434. (blkaddr + blklen - addr) : MAX_DL_SIZE;
  435. }
  436. #endif
  437. blk = (const struct dblock *) &blk->data[blklen];
  438. if ((void *) blk > (end - sizeof(*blk)))
  439. return -EIO;
  440. blkaddr = dblock_addr(blk);
  441. blklen = dblock_len(blk);
  442. }
  443. return 0;
  444. }
  445. /*** Default plugging data for Hermes I ***/
  446. /* Values from wl_lkm_718/hcf/dhf.c */
  447. #define DEFINE_DEFAULT_PDR(pid, length, data) \
  448. static const struct { \
  449. __le16 len; \
  450. __le16 id; \
  451. u8 val[length]; \
  452. } __attribute__ ((packed)) default_pdr_data_##pid = { \
  453. cpu_to_le16((sizeof(default_pdr_data_##pid)/ \
  454. sizeof(__le16)) - 1), \
  455. cpu_to_le16(pid), \
  456. data \
  457. }
  458. #define DEFAULT_PDR(pid) default_pdr_data_##pid
  459. /* HWIF Compatiblity */
  460. DEFINE_DEFAULT_PDR(0x0005, 10, "\x00\x00\x06\x00\x01\x00\x01\x00\x01\x00");
  461. /* PPPPSign */
  462. DEFINE_DEFAULT_PDR(0x0108, 4, "\x00\x00\x00\x00");
  463. /* PPPPProf */
  464. DEFINE_DEFAULT_PDR(0x0109, 10, "\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00");
  465. /* Antenna diversity */
  466. DEFINE_DEFAULT_PDR(0x0150, 2, "\x00\x3F");
  467. /* Modem VCO band Set-up */
  468. DEFINE_DEFAULT_PDR(0x0160, 28,
  469. "\x00\x00\x00\x00\x00\x00\x00\x00"
  470. "\x00\x00\x00\x00\x00\x00\x00\x00"
  471. "\x00\x00\x00\x00\x00\x00\x00\x00"
  472. "\x00\x00\x00\x00");
  473. /* Modem Rx Gain Table Values */
  474. DEFINE_DEFAULT_PDR(0x0161, 256,
  475. "\x3F\x01\x3F\01\x3F\x01\x3F\x01"
  476. "\x3F\x01\x3F\01\x3F\x01\x3F\x01"
  477. "\x3F\x01\x3F\01\x3F\x01\x3F\x01"
  478. "\x3F\x01\x3F\01\x3F\x01\x3F\x01"
  479. "\x3F\x01\x3E\01\x3E\x01\x3D\x01"
  480. "\x3D\x01\x3C\01\x3C\x01\x3B\x01"
  481. "\x3B\x01\x3A\01\x3A\x01\x39\x01"
  482. "\x39\x01\x38\01\x38\x01\x37\x01"
  483. "\x37\x01\x36\01\x36\x01\x35\x01"
  484. "\x35\x01\x34\01\x34\x01\x33\x01"
  485. "\x33\x01\x32\x01\x32\x01\x31\x01"
  486. "\x31\x01\x30\x01\x30\x01\x7B\x01"
  487. "\x7B\x01\x7A\x01\x7A\x01\x79\x01"
  488. "\x79\x01\x78\x01\x78\x01\x77\x01"
  489. "\x77\x01\x76\x01\x76\x01\x75\x01"
  490. "\x75\x01\x74\x01\x74\x01\x73\x01"
  491. "\x73\x01\x72\x01\x72\x01\x71\x01"
  492. "\x71\x01\x70\x01\x70\x01\x68\x01"
  493. "\x68\x01\x67\x01\x67\x01\x66\x01"
  494. "\x66\x01\x65\x01\x65\x01\x57\x01"
  495. "\x57\x01\x56\x01\x56\x01\x55\x01"
  496. "\x55\x01\x54\x01\x54\x01\x53\x01"
  497. "\x53\x01\x52\x01\x52\x01\x51\x01"
  498. "\x51\x01\x50\x01\x50\x01\x48\x01"
  499. "\x48\x01\x47\x01\x47\x01\x46\x01"
  500. "\x46\x01\x45\x01\x45\x01\x44\x01"
  501. "\x44\x01\x43\x01\x43\x01\x42\x01"
  502. "\x42\x01\x41\x01\x41\x01\x40\x01"
  503. "\x40\x01\x40\x01\x40\x01\x40\x01"
  504. "\x40\x01\x40\x01\x40\x01\x40\x01"
  505. "\x40\x01\x40\x01\x40\x01\x40\x01"
  506. "\x40\x01\x40\x01\x40\x01\x40\x01");
  507. /* Write PDA according to certain rules.
  508. *
  509. * For every production data record, look for a previous setting in
  510. * the pda, and use that.
  511. *
  512. * For certain records, use defaults if they are not found in pda.
  513. */
  514. int hermes_apply_pda_with_defaults(hermes_t *hw,
  515. const char *first_pdr,
  516. const void *pdr_end,
  517. const __le16 *pda,
  518. const void *pda_end)
  519. {
  520. const struct pdr *pdr = (const struct pdr *) first_pdr;
  521. const struct pdi *first_pdi = (const struct pdi *) &pda[2];
  522. const struct pdi *pdi;
  523. const struct pdi *default_pdi = NULL;
  524. const struct pdi *outdoor_pdi;
  525. int record_id;
  526. pdr_end -= sizeof(struct pdr);
  527. while (((void *) pdr <= pdr_end) &&
  528. (pdr_id(pdr) != PDI_END)) {
  529. /*
  530. * For spectrum_cs firmwares,
  531. * PDR area is currently not terminated by PDI_END.
  532. * It's followed by CRC records, which have the type
  533. * field where PDR has length. The type can be 0 or 1.
  534. */
  535. if (pdr_len(pdr) < 2)
  536. break;
  537. record_id = pdr_id(pdr);
  538. pdi = hermes_find_pdi(first_pdi, record_id, pda_end);
  539. if (pdi)
  540. pr_debug(PFX "Found record 0x%04x at %p\n",
  541. record_id, pdi);
  542. switch (record_id) {
  543. case 0x110: /* Modem REFDAC values */
  544. case 0x120: /* Modem VGDAC values */
  545. outdoor_pdi = hermes_find_pdi(first_pdi, record_id + 1,
  546. pda_end);
  547. default_pdi = NULL;
  548. if (outdoor_pdi) {
  549. pdi = outdoor_pdi;
  550. pr_debug(PFX
  551. "Using outdoor record 0x%04x at %p\n",
  552. record_id + 1, pdi);
  553. }
  554. break;
  555. case 0x5: /* HWIF Compatiblity */
  556. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0005);
  557. break;
  558. case 0x108: /* PPPPSign */
  559. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0108);
  560. break;
  561. case 0x109: /* PPPPProf */
  562. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0109);
  563. break;
  564. case 0x150: /* Antenna diversity */
  565. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0150);
  566. break;
  567. case 0x160: /* Modem VCO band Set-up */
  568. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0160);
  569. break;
  570. case 0x161: /* Modem Rx Gain Table Values */
  571. default_pdi = (struct pdi *) &DEFAULT_PDR(0x0161);
  572. break;
  573. default:
  574. default_pdi = NULL;
  575. break;
  576. }
  577. if (!pdi && default_pdi) {
  578. /* Use default */
  579. pdi = default_pdi;
  580. pr_debug(PFX "Using default record 0x%04x at %p\n",
  581. record_id, pdi);
  582. }
  583. if (pdi) {
  584. /* Lengths of the data in PDI and PDR must match */
  585. if ((pdi_len(pdi) == pdr_len(pdr)) &&
  586. ((void *) pdi->data + pdi_len(pdi) < pda_end)) {
  587. /* do the actual plugging */
  588. hermes_aux_setaddr(hw, pdr_addr(pdr));
  589. hermes_write_bytes(hw, HERMES_AUXDATA,
  590. pdi->data, pdi_len(pdi));
  591. }
  592. }
  593. pdr++;
  594. }
  595. return 0;
  596. }