hermes.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. /* hermes.c
  2. *
  3. * Driver core for the "Hermes" wireless MAC controller, as used in
  4. * the Lucent Orinoco and Cabletron RoamAbout cards. It should also
  5. * work on the hfa3841 and hfa3842 MAC controller chips used in the
  6. * Prism II chipsets.
  7. *
  8. * This is not a complete driver, just low-level access routines for
  9. * the MAC controller itself.
  10. *
  11. * Based on the prism2 driver from Absolute Value Systems' linux-wlan
  12. * project, the Linux wvlan_cs driver, Lucent's HCF-Light
  13. * (wvlan_hcf.c) library, and the NetBSD wireless driver (in no
  14. * particular order).
  15. *
  16. * Copyright (C) 2000, David Gibson, Linuxcare Australia.
  17. * (C) Copyright David Gibson, IBM Corp. 2001-2003.
  18. *
  19. * The contents of this file are subject to the Mozilla Public License
  20. * Version 1.1 (the "License"); you may not use this file except in
  21. * compliance with the License. You may obtain a copy of the License
  22. * at http://www.mozilla.org/MPL/
  23. *
  24. * Software distributed under the License is distributed on an "AS IS"
  25. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  26. * the License for the specific language governing rights and
  27. * limitations under the License.
  28. *
  29. * Alternatively, the contents of this file may be used under the
  30. * terms of the GNU General Public License version 2 (the "GPL"), in
  31. * which case the provisions of the GPL are applicable instead of the
  32. * above. If you wish to allow the use of your version of this file
  33. * only under the terms of the GPL and not to allow others to use your
  34. * version of this file under the MPL, indicate your decision by
  35. * deleting the provisions above and replace them with the notice and
  36. * other provisions required by the GPL. If you do not delete the
  37. * provisions above, a recipient may use your version of this file
  38. * under either the MPL or the GPL.
  39. */
  40. #include <linux/module.h>
  41. #include <linux/kernel.h>
  42. #include <linux/delay.h>
  43. #include "hermes.h"
  44. /* These are maximum timeouts. Most often, card wil react much faster */
  45. #define CMD_BUSY_TIMEOUT (100) /* In iterations of ~1us */
  46. #define CMD_INIT_TIMEOUT (50000) /* in iterations of ~10us */
  47. #define CMD_COMPL_TIMEOUT (20000) /* in iterations of ~10us */
  48. #define ALLOC_COMPL_TIMEOUT (1000) /* in iterations of ~10us */
  49. /*
  50. * AUX port access. To unlock the AUX port write the access keys to the
  51. * PARAM0-2 registers, then write HERMES_AUX_ENABLE to the HERMES_CONTROL
  52. * register. Then read it and make sure it's HERMES_AUX_ENABLED.
  53. */
  54. #define HERMES_AUX_ENABLE 0x8000 /* Enable auxiliary port access */
  55. #define HERMES_AUX_DISABLE 0x4000 /* Disable to auxiliary port access */
  56. #define HERMES_AUX_ENABLED 0xC000 /* Auxiliary port is open */
  57. #define HERMES_AUX_DISABLED 0x0000 /* Auxiliary port is closed */
  58. #define HERMES_AUX_PW0 0xFE01
  59. #define HERMES_AUX_PW1 0xDC23
  60. #define HERMES_AUX_PW2 0xBA45
  61. /* HERMES_CMD_DOWNLD */
  62. #define HERMES_PROGRAM_DISABLE (0x0000 | HERMES_CMD_DOWNLD)
  63. #define HERMES_PROGRAM_ENABLE_VOLATILE (0x0100 | HERMES_CMD_DOWNLD)
  64. #define HERMES_PROGRAM_ENABLE_NON_VOLATILE (0x0200 | HERMES_CMD_DOWNLD)
  65. #define HERMES_PROGRAM_NON_VOLATILE (0x0300 | HERMES_CMD_DOWNLD)
  66. /*
  67. * Debugging helpers
  68. */
  69. #define DMSG(stuff...) do {printk(KERN_DEBUG "hermes @ %p: " , hw->iobase); \
  70. printk(stuff); } while (0)
  71. #undef HERMES_DEBUG
  72. #ifdef HERMES_DEBUG
  73. #include <stdarg.h>
  74. #define DEBUG(lvl, stuff...) if ((lvl) <= HERMES_DEBUG) DMSG(stuff)
  75. #else /* ! HERMES_DEBUG */
  76. #define DEBUG(lvl, stuff...) do { } while (0)
  77. #endif /* ! HERMES_DEBUG */
  78. static const struct hermes_ops hermes_ops_local;
  79. /*
  80. * Internal functions
  81. */
  82. /* Issue a command to the chip. Waiting for it to complete is the caller's
  83. problem.
  84. Returns -EBUSY if the command register is busy, 0 on success.
  85. Callable from any context.
  86. */
  87. static int hermes_issue_cmd(struct hermes *hw, u16 cmd, u16 param0,
  88. u16 param1, u16 param2)
  89. {
  90. int k = CMD_BUSY_TIMEOUT;
  91. u16 reg;
  92. /* First wait for the command register to unbusy */
  93. reg = hermes_read_regn(hw, CMD);
  94. while ((reg & HERMES_CMD_BUSY) && k) {
  95. k--;
  96. udelay(1);
  97. reg = hermes_read_regn(hw, CMD);
  98. }
  99. if (reg & HERMES_CMD_BUSY)
  100. return -EBUSY;
  101. hermes_write_regn(hw, PARAM2, param2);
  102. hermes_write_regn(hw, PARAM1, param1);
  103. hermes_write_regn(hw, PARAM0, param0);
  104. hermes_write_regn(hw, CMD, cmd);
  105. return 0;
  106. }
  107. /*
  108. * Function definitions
  109. */
  110. /* For doing cmds that wipe the magic constant in SWSUPPORT0 */
  111. static int hermes_doicmd_wait(struct hermes *hw, u16 cmd,
  112. u16 parm0, u16 parm1, u16 parm2,
  113. struct hermes_response *resp)
  114. {
  115. int err = 0;
  116. int k;
  117. u16 status, reg;
  118. err = hermes_issue_cmd(hw, cmd, parm0, parm1, parm2);
  119. if (err)
  120. return err;
  121. reg = hermes_read_regn(hw, EVSTAT);
  122. k = CMD_INIT_TIMEOUT;
  123. while ((!(reg & HERMES_EV_CMD)) && k) {
  124. k--;
  125. udelay(10);
  126. reg = hermes_read_regn(hw, EVSTAT);
  127. }
  128. hermes_write_regn(hw, SWSUPPORT0, HERMES_MAGIC);
  129. if (!hermes_present(hw)) {
  130. DEBUG(0, "hermes @ 0x%x: Card removed during reset.\n",
  131. hw->iobase);
  132. err = -ENODEV;
  133. goto out;
  134. }
  135. if (!(reg & HERMES_EV_CMD)) {
  136. printk(KERN_ERR "hermes @ %p: "
  137. "Timeout waiting for card to reset (reg=0x%04x)!\n",
  138. hw->iobase, reg);
  139. err = -ETIMEDOUT;
  140. goto out;
  141. }
  142. status = hermes_read_regn(hw, STATUS);
  143. if (resp) {
  144. resp->status = status;
  145. resp->resp0 = hermes_read_regn(hw, RESP0);
  146. resp->resp1 = hermes_read_regn(hw, RESP1);
  147. resp->resp2 = hermes_read_regn(hw, RESP2);
  148. }
  149. hermes_write_regn(hw, EVACK, HERMES_EV_CMD);
  150. if (status & HERMES_STATUS_RESULT)
  151. err = -EIO;
  152. out:
  153. return err;
  154. }
  155. void hermes_struct_init(struct hermes *hw, void __iomem *address,
  156. int reg_spacing)
  157. {
  158. hw->iobase = address;
  159. hw->reg_spacing = reg_spacing;
  160. hw->inten = 0x0;
  161. hw->eeprom_pda = false;
  162. hw->ops = &hermes_ops_local;
  163. }
  164. EXPORT_SYMBOL(hermes_struct_init);
  165. static int hermes_init(struct hermes *hw)
  166. {
  167. u16 reg;
  168. int err = 0;
  169. int k;
  170. /* We don't want to be interrupted while resetting the chipset */
  171. hw->inten = 0x0;
  172. hermes_write_regn(hw, INTEN, 0);
  173. hermes_write_regn(hw, EVACK, 0xffff);
  174. /* Normally it's a "can't happen" for the command register to
  175. be busy when we go to issue a command because we are
  176. serializing all commands. However we want to have some
  177. chance of resetting the card even if it gets into a stupid
  178. state, so we actually wait to see if the command register
  179. will unbusy itself here. */
  180. k = CMD_BUSY_TIMEOUT;
  181. reg = hermes_read_regn(hw, CMD);
  182. while (k && (reg & HERMES_CMD_BUSY)) {
  183. if (reg == 0xffff) /* Special case - the card has probably been
  184. removed, so don't wait for the timeout */
  185. return -ENODEV;
  186. k--;
  187. udelay(1);
  188. reg = hermes_read_regn(hw, CMD);
  189. }
  190. /* No need to explicitly handle the timeout - if we've timed
  191. out hermes_issue_cmd() will probably return -EBUSY below */
  192. /* According to the documentation, EVSTAT may contain
  193. obsolete event occurrence information. We have to acknowledge
  194. it by writing EVACK. */
  195. reg = hermes_read_regn(hw, EVSTAT);
  196. hermes_write_regn(hw, EVACK, reg);
  197. /* We don't use hermes_docmd_wait here, because the reset wipes
  198. the magic constant in SWSUPPORT0 away, and it gets confused */
  199. err = hermes_doicmd_wait(hw, HERMES_CMD_INIT, 0, 0, 0, NULL);
  200. return err;
  201. }
  202. /* Issue a command to the chip, and (busy!) wait for it to
  203. * complete.
  204. *
  205. * Returns:
  206. * < 0 on internal error
  207. * 0 on success
  208. * > 0 on error returned by the firmware
  209. *
  210. * Callable from any context, but locking is your problem. */
  211. static int hermes_docmd_wait(struct hermes *hw, u16 cmd, u16 parm0,
  212. struct hermes_response *resp)
  213. {
  214. int err;
  215. int k;
  216. u16 reg;
  217. u16 status;
  218. err = hermes_issue_cmd(hw, cmd, parm0, 0, 0);
  219. if (err) {
  220. if (!hermes_present(hw)) {
  221. if (net_ratelimit())
  222. printk(KERN_WARNING "hermes @ %p: "
  223. "Card removed while issuing command "
  224. "0x%04x.\n", hw->iobase, cmd);
  225. err = -ENODEV;
  226. } else
  227. if (net_ratelimit())
  228. printk(KERN_ERR "hermes @ %p: "
  229. "Error %d issuing command 0x%04x.\n",
  230. hw->iobase, err, cmd);
  231. goto out;
  232. }
  233. reg = hermes_read_regn(hw, EVSTAT);
  234. k = CMD_COMPL_TIMEOUT;
  235. while ((!(reg & HERMES_EV_CMD)) && k) {
  236. k--;
  237. udelay(10);
  238. reg = hermes_read_regn(hw, EVSTAT);
  239. }
  240. if (!hermes_present(hw)) {
  241. printk(KERN_WARNING "hermes @ %p: Card removed "
  242. "while waiting for command 0x%04x completion.\n",
  243. hw->iobase, cmd);
  244. err = -ENODEV;
  245. goto out;
  246. }
  247. if (!(reg & HERMES_EV_CMD)) {
  248. printk(KERN_ERR "hermes @ %p: Timeout waiting for "
  249. "command 0x%04x completion.\n", hw->iobase, cmd);
  250. err = -ETIMEDOUT;
  251. goto out;
  252. }
  253. status = hermes_read_regn(hw, STATUS);
  254. if (resp) {
  255. resp->status = status;
  256. resp->resp0 = hermes_read_regn(hw, RESP0);
  257. resp->resp1 = hermes_read_regn(hw, RESP1);
  258. resp->resp2 = hermes_read_regn(hw, RESP2);
  259. }
  260. hermes_write_regn(hw, EVACK, HERMES_EV_CMD);
  261. if (status & HERMES_STATUS_RESULT)
  262. err = -EIO;
  263. out:
  264. return err;
  265. }
  266. static int hermes_allocate(struct hermes *hw, u16 size, u16 *fid)
  267. {
  268. int err = 0;
  269. int k;
  270. u16 reg;
  271. if ((size < HERMES_ALLOC_LEN_MIN) || (size > HERMES_ALLOC_LEN_MAX))
  272. return -EINVAL;
  273. err = hermes_docmd_wait(hw, HERMES_CMD_ALLOC, size, NULL);
  274. if (err)
  275. return err;
  276. reg = hermes_read_regn(hw, EVSTAT);
  277. k = ALLOC_COMPL_TIMEOUT;
  278. while ((!(reg & HERMES_EV_ALLOC)) && k) {
  279. k--;
  280. udelay(10);
  281. reg = hermes_read_regn(hw, EVSTAT);
  282. }
  283. if (!hermes_present(hw)) {
  284. printk(KERN_WARNING "hermes @ %p: "
  285. "Card removed waiting for frame allocation.\n",
  286. hw->iobase);
  287. return -ENODEV;
  288. }
  289. if (!(reg & HERMES_EV_ALLOC)) {
  290. printk(KERN_ERR "hermes @ %p: "
  291. "Timeout waiting for frame allocation\n",
  292. hw->iobase);
  293. return -ETIMEDOUT;
  294. }
  295. *fid = hermes_read_regn(hw, ALLOCFID);
  296. hermes_write_regn(hw, EVACK, HERMES_EV_ALLOC);
  297. return 0;
  298. }
  299. /* Set up a BAP to read a particular chunk of data from card's internal buffer.
  300. *
  301. * Returns:
  302. * < 0 on internal failure (errno)
  303. * 0 on success
  304. * > 0 on error
  305. * from firmware
  306. *
  307. * Callable from any context */
  308. static int hermes_bap_seek(struct hermes *hw, int bap, u16 id, u16 offset)
  309. {
  310. int sreg = bap ? HERMES_SELECT1 : HERMES_SELECT0;
  311. int oreg = bap ? HERMES_OFFSET1 : HERMES_OFFSET0;
  312. int k;
  313. u16 reg;
  314. /* Paranoia.. */
  315. if ((offset > HERMES_BAP_OFFSET_MAX) || (offset % 2))
  316. return -EINVAL;
  317. k = HERMES_BAP_BUSY_TIMEOUT;
  318. reg = hermes_read_reg(hw, oreg);
  319. while ((reg & HERMES_OFFSET_BUSY) && k) {
  320. k--;
  321. udelay(1);
  322. reg = hermes_read_reg(hw, oreg);
  323. }
  324. if (reg & HERMES_OFFSET_BUSY)
  325. return -ETIMEDOUT;
  326. /* Now we actually set up the transfer */
  327. hermes_write_reg(hw, sreg, id);
  328. hermes_write_reg(hw, oreg, offset);
  329. /* Wait for the BAP to be ready */
  330. k = HERMES_BAP_BUSY_TIMEOUT;
  331. reg = hermes_read_reg(hw, oreg);
  332. while ((reg & (HERMES_OFFSET_BUSY | HERMES_OFFSET_ERR)) && k) {
  333. k--;
  334. udelay(1);
  335. reg = hermes_read_reg(hw, oreg);
  336. }
  337. if (reg != offset) {
  338. printk(KERN_ERR "hermes @ %p: BAP%d offset %s: "
  339. "reg=0x%x id=0x%x offset=0x%x\n", hw->iobase, bap,
  340. (reg & HERMES_OFFSET_BUSY) ? "timeout" : "error",
  341. reg, id, offset);
  342. if (reg & HERMES_OFFSET_BUSY)
  343. return -ETIMEDOUT;
  344. return -EIO; /* error or wrong offset */
  345. }
  346. return 0;
  347. }
  348. /* Read a block of data from the chip's buffer, via the
  349. * BAP. Synchronization/serialization is the caller's problem. len
  350. * must be even.
  351. *
  352. * Returns:
  353. * < 0 on internal failure (errno)
  354. * 0 on success
  355. * > 0 on error from firmware
  356. */
  357. static int hermes_bap_pread(struct hermes *hw, int bap, void *buf, int len,
  358. u16 id, u16 offset)
  359. {
  360. int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
  361. int err = 0;
  362. if ((len < 0) || (len % 2))
  363. return -EINVAL;
  364. err = hermes_bap_seek(hw, bap, id, offset);
  365. if (err)
  366. goto out;
  367. /* Actually do the transfer */
  368. hermes_read_words(hw, dreg, buf, len / 2);
  369. out:
  370. return err;
  371. }
  372. /* Write a block of data to the chip's buffer, via the
  373. * BAP. Synchronization/serialization is the caller's problem.
  374. *
  375. * Returns:
  376. * < 0 on internal failure (errno)
  377. * 0 on success
  378. * > 0 on error from firmware
  379. */
  380. static int hermes_bap_pwrite(struct hermes *hw, int bap, const void *buf,
  381. int len, u16 id, u16 offset)
  382. {
  383. int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
  384. int err = 0;
  385. if (len < 0)
  386. return -EINVAL;
  387. err = hermes_bap_seek(hw, bap, id, offset);
  388. if (err)
  389. goto out;
  390. /* Actually do the transfer */
  391. hermes_write_bytes(hw, dreg, buf, len);
  392. out:
  393. return err;
  394. }
  395. /* Read a Length-Type-Value record from the card.
  396. *
  397. * If length is NULL, we ignore the length read from the card, and
  398. * read the entire buffer regardless. This is useful because some of
  399. * the configuration records appear to have incorrect lengths in
  400. * practice.
  401. *
  402. * Callable from user or bh context. */
  403. static int hermes_read_ltv(struct hermes *hw, int bap, u16 rid,
  404. unsigned bufsize, u16 *length, void *buf)
  405. {
  406. int err = 0;
  407. int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
  408. u16 rlength, rtype;
  409. unsigned nwords;
  410. if (bufsize % 2)
  411. return -EINVAL;
  412. err = hermes_docmd_wait(hw, HERMES_CMD_ACCESS, rid, NULL);
  413. if (err)
  414. return err;
  415. err = hermes_bap_seek(hw, bap, rid, 0);
  416. if (err)
  417. return err;
  418. rlength = hermes_read_reg(hw, dreg);
  419. if (!rlength)
  420. return -ENODATA;
  421. rtype = hermes_read_reg(hw, dreg);
  422. if (length)
  423. *length = rlength;
  424. if (rtype != rid)
  425. printk(KERN_WARNING "hermes @ %p: %s(): "
  426. "rid (0x%04x) does not match type (0x%04x)\n",
  427. hw->iobase, __func__, rid, rtype);
  428. if (HERMES_RECLEN_TO_BYTES(rlength) > bufsize)
  429. printk(KERN_WARNING "hermes @ %p: "
  430. "Truncating LTV record from %d to %d bytes. "
  431. "(rid=0x%04x, len=0x%04x)\n", hw->iobase,
  432. HERMES_RECLEN_TO_BYTES(rlength), bufsize, rid, rlength);
  433. nwords = min((unsigned)rlength - 1, bufsize / 2);
  434. hermes_read_words(hw, dreg, buf, nwords);
  435. return 0;
  436. }
  437. static int hermes_write_ltv(struct hermes *hw, int bap, u16 rid,
  438. u16 length, const void *value)
  439. {
  440. int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
  441. int err = 0;
  442. unsigned count;
  443. if (length == 0)
  444. return -EINVAL;
  445. err = hermes_bap_seek(hw, bap, rid, 0);
  446. if (err)
  447. return err;
  448. hermes_write_reg(hw, dreg, length);
  449. hermes_write_reg(hw, dreg, rid);
  450. count = length - 1;
  451. hermes_write_bytes(hw, dreg, value, count << 1);
  452. err = hermes_docmd_wait(hw, HERMES_CMD_ACCESS | HERMES_CMD_WRITE,
  453. rid, NULL);
  454. return err;
  455. }
  456. /*** Hermes AUX control ***/
  457. static inline void
  458. hermes_aux_setaddr(struct hermes *hw, u32 addr)
  459. {
  460. hermes_write_reg(hw, HERMES_AUXPAGE, (u16) (addr >> 7));
  461. hermes_write_reg(hw, HERMES_AUXOFFSET, (u16) (addr & 0x7F));
  462. }
  463. static inline int
  464. hermes_aux_control(struct hermes *hw, int enabled)
  465. {
  466. int desired_state = enabled ? HERMES_AUX_ENABLED : HERMES_AUX_DISABLED;
  467. int action = enabled ? HERMES_AUX_ENABLE : HERMES_AUX_DISABLE;
  468. int i;
  469. /* Already open? */
  470. if (hermes_read_reg(hw, HERMES_CONTROL) == desired_state)
  471. return 0;
  472. hermes_write_reg(hw, HERMES_PARAM0, HERMES_AUX_PW0);
  473. hermes_write_reg(hw, HERMES_PARAM1, HERMES_AUX_PW1);
  474. hermes_write_reg(hw, HERMES_PARAM2, HERMES_AUX_PW2);
  475. hermes_write_reg(hw, HERMES_CONTROL, action);
  476. for (i = 0; i < 20; i++) {
  477. udelay(10);
  478. if (hermes_read_reg(hw, HERMES_CONTROL) ==
  479. desired_state)
  480. return 0;
  481. }
  482. return -EBUSY;
  483. }
  484. /*** Hermes programming ***/
  485. /* About to start programming data (Hermes I)
  486. * offset is the entry point
  487. *
  488. * Spectrum_cs' Symbol fw does not require this
  489. * wl_lkm Agere fw does
  490. * Don't know about intersil
  491. */
  492. static int hermesi_program_init(struct hermes *hw, u32 offset)
  493. {
  494. int err;
  495. /* Disable interrupts?*/
  496. /*hw->inten = 0x0;*/
  497. /*hermes_write_regn(hw, INTEN, 0);*/
  498. /*hermes_set_irqmask(hw, 0);*/
  499. /* Acknowledge any outstanding command */
  500. hermes_write_regn(hw, EVACK, 0xFFFF);
  501. /* Using init_cmd_wait rather than cmd_wait */
  502. err = hw->ops->init_cmd_wait(hw,
  503. 0x0100 | HERMES_CMD_INIT,
  504. 0, 0, 0, NULL);
  505. if (err)
  506. return err;
  507. err = hw->ops->init_cmd_wait(hw,
  508. 0x0000 | HERMES_CMD_INIT,
  509. 0, 0, 0, NULL);
  510. if (err)
  511. return err;
  512. err = hermes_aux_control(hw, 1);
  513. pr_debug("AUX enable returned %d\n", err);
  514. if (err)
  515. return err;
  516. pr_debug("Enabling volatile, EP 0x%08x\n", offset);
  517. err = hw->ops->init_cmd_wait(hw,
  518. HERMES_PROGRAM_ENABLE_VOLATILE,
  519. offset & 0xFFFFu,
  520. offset >> 16,
  521. 0,
  522. NULL);
  523. pr_debug("PROGRAM_ENABLE returned %d\n", err);
  524. return err;
  525. }
  526. /* Done programming data (Hermes I)
  527. *
  528. * Spectrum_cs' Symbol fw does not require this
  529. * wl_lkm Agere fw does
  530. * Don't know about intersil
  531. */
  532. static int hermesi_program_end(struct hermes *hw)
  533. {
  534. struct hermes_response resp;
  535. int rc = 0;
  536. int err;
  537. rc = hw->ops->cmd_wait(hw, HERMES_PROGRAM_DISABLE, 0, &resp);
  538. pr_debug("PROGRAM_DISABLE returned %d, "
  539. "r0 0x%04x, r1 0x%04x, r2 0x%04x\n",
  540. rc, resp.resp0, resp.resp1, resp.resp2);
  541. if ((rc == 0) &&
  542. ((resp.status & HERMES_STATUS_CMDCODE) != HERMES_CMD_DOWNLD))
  543. rc = -EIO;
  544. err = hermes_aux_control(hw, 0);
  545. pr_debug("AUX disable returned %d\n", err);
  546. /* Acknowledge any outstanding command */
  547. hermes_write_regn(hw, EVACK, 0xFFFF);
  548. /* Reinitialise, ignoring return */
  549. (void) hw->ops->init_cmd_wait(hw, 0x0000 | HERMES_CMD_INIT,
  550. 0, 0, 0, NULL);
  551. return rc ? rc : err;
  552. }
  553. static int hermes_program_bytes(struct hermes *hw, const char *data,
  554. u32 addr, u32 len)
  555. {
  556. /* wl lkm splits the programming into chunks of 2000 bytes.
  557. * This restriction appears to come from USB. The PCMCIA
  558. * adapters can program the whole lot in one go */
  559. hermes_aux_setaddr(hw, addr);
  560. hermes_write_bytes(hw, HERMES_AUXDATA, data, len);
  561. return 0;
  562. }
  563. /* Read PDA from the adapter */
  564. static int hermes_read_pda(struct hermes *hw, __le16 *pda, u32 pda_addr,
  565. u16 pda_len)
  566. {
  567. int ret;
  568. u16 pda_size;
  569. u16 data_len = pda_len;
  570. __le16 *data = pda;
  571. if (hw->eeprom_pda) {
  572. /* PDA of spectrum symbol is in eeprom */
  573. /* Issue command to read EEPROM */
  574. ret = hw->ops->cmd_wait(hw, HERMES_CMD_READMIF, 0, NULL);
  575. if (ret)
  576. return ret;
  577. } else {
  578. /* wl_lkm does not include PDA size in the PDA area.
  579. * We will pad the information into pda, so other routines
  580. * don't have to be modified */
  581. pda[0] = cpu_to_le16(pda_len - 2);
  582. /* Includes CFG_PROD_DATA but not itself */
  583. pda[1] = cpu_to_le16(0x0800); /* CFG_PROD_DATA */
  584. data_len = pda_len - 4;
  585. data = pda + 2;
  586. }
  587. /* Open auxiliary port */
  588. ret = hermes_aux_control(hw, 1);
  589. pr_debug("AUX enable returned %d\n", ret);
  590. if (ret)
  591. return ret;
  592. /* Read PDA */
  593. hermes_aux_setaddr(hw, pda_addr);
  594. hermes_read_words(hw, HERMES_AUXDATA, data, data_len / 2);
  595. /* Close aux port */
  596. ret = hermes_aux_control(hw, 0);
  597. pr_debug("AUX disable returned %d\n", ret);
  598. /* Check PDA length */
  599. pda_size = le16_to_cpu(pda[0]);
  600. pr_debug("Actual PDA length %d, Max allowed %d\n",
  601. pda_size, pda_len);
  602. if (pda_size > pda_len)
  603. return -EINVAL;
  604. return 0;
  605. }
  606. static void hermes_lock_irqsave(spinlock_t *lock,
  607. unsigned long *flags) __acquires(lock)
  608. {
  609. spin_lock_irqsave(lock, *flags);
  610. }
  611. static void hermes_unlock_irqrestore(spinlock_t *lock,
  612. unsigned long *flags) __releases(lock)
  613. {
  614. spin_unlock_irqrestore(lock, *flags);
  615. }
  616. static void hermes_lock_irq(spinlock_t *lock) __acquires(lock)
  617. {
  618. spin_lock_irq(lock);
  619. }
  620. static void hermes_unlock_irq(spinlock_t *lock) __releases(lock)
  621. {
  622. spin_unlock_irq(lock);
  623. }
  624. /* Hermes operations for local buses */
  625. static const struct hermes_ops hermes_ops_local = {
  626. .init = hermes_init,
  627. .cmd_wait = hermes_docmd_wait,
  628. .init_cmd_wait = hermes_doicmd_wait,
  629. .allocate = hermes_allocate,
  630. .read_ltv = hermes_read_ltv,
  631. .write_ltv = hermes_write_ltv,
  632. .bap_pread = hermes_bap_pread,
  633. .bap_pwrite = hermes_bap_pwrite,
  634. .read_pda = hermes_read_pda,
  635. .program_init = hermesi_program_init,
  636. .program_end = hermesi_program_end,
  637. .program = hermes_program_bytes,
  638. .lock_irqsave = hermes_lock_irqsave,
  639. .unlock_irqrestore = hermes_unlock_irqrestore,
  640. .lock_irq = hermes_lock_irq,
  641. .unlock_irq = hermes_unlock_irq,
  642. };