qla_sup.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /******************************************************************************
  2. * QLOGIC LINUX SOFTWARE
  3. *
  4. * QLogic ISP2x00 device driver for Linux 2.6.x
  5. * Copyright (C) 2003-2005 QLogic Corporation
  6. * (www.qlogic.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2, or (at your option) any
  11. * later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. ******************************************************************************/
  19. #include "qla_def.h"
  20. #include <linux/delay.h>
  21. #include <asm/uaccess.h>
  22. static uint16_t qla2x00_nvram_request(scsi_qla_host_t *, uint32_t);
  23. static void qla2x00_nv_deselect(scsi_qla_host_t *);
  24. static void qla2x00_nv_write(scsi_qla_host_t *, uint16_t);
  25. /*
  26. * NVRAM support routines
  27. */
  28. /**
  29. * qla2x00_lock_nvram_access() -
  30. * @ha: HA context
  31. */
  32. void
  33. qla2x00_lock_nvram_access(scsi_qla_host_t *ha)
  34. {
  35. uint16_t data;
  36. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  37. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) {
  38. data = RD_REG_WORD(&reg->nvram);
  39. while (data & NVR_BUSY) {
  40. udelay(100);
  41. data = RD_REG_WORD(&reg->nvram);
  42. }
  43. /* Lock resource */
  44. WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0x1);
  45. RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  46. udelay(5);
  47. data = RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  48. while ((data & BIT_0) == 0) {
  49. /* Lock failed */
  50. udelay(100);
  51. WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0x1);
  52. RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  53. udelay(5);
  54. data = RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  55. }
  56. }
  57. }
  58. /**
  59. * qla2x00_unlock_nvram_access() -
  60. * @ha: HA context
  61. */
  62. void
  63. qla2x00_unlock_nvram_access(scsi_qla_host_t *ha)
  64. {
  65. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  66. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) {
  67. WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0);
  68. RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  69. }
  70. }
  71. /**
  72. * qla2x00_get_nvram_word() - Calculates word position in NVRAM and calls the
  73. * request routine to get the word from NVRAM.
  74. * @ha: HA context
  75. * @addr: Address in NVRAM to read
  76. *
  77. * Returns the word read from nvram @addr.
  78. */
  79. uint16_t
  80. qla2x00_get_nvram_word(scsi_qla_host_t *ha, uint32_t addr)
  81. {
  82. uint16_t data;
  83. uint32_t nv_cmd;
  84. nv_cmd = addr << 16;
  85. nv_cmd |= NV_READ_OP;
  86. data = qla2x00_nvram_request(ha, nv_cmd);
  87. return (data);
  88. }
  89. /**
  90. * qla2x00_write_nvram_word() - Write NVRAM data.
  91. * @ha: HA context
  92. * @addr: Address in NVRAM to write
  93. * @data: word to program
  94. */
  95. void
  96. qla2x00_write_nvram_word(scsi_qla_host_t *ha, uint32_t addr, uint16_t data)
  97. {
  98. int count;
  99. uint16_t word;
  100. uint32_t nv_cmd;
  101. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  102. qla2x00_nv_write(ha, NVR_DATA_OUT);
  103. qla2x00_nv_write(ha, 0);
  104. qla2x00_nv_write(ha, 0);
  105. for (word = 0; word < 8; word++)
  106. qla2x00_nv_write(ha, NVR_DATA_OUT);
  107. qla2x00_nv_deselect(ha);
  108. /* Write data */
  109. nv_cmd = (addr << 16) | NV_WRITE_OP;
  110. nv_cmd |= data;
  111. nv_cmd <<= 5;
  112. for (count = 0; count < 27; count++) {
  113. if (nv_cmd & BIT_31)
  114. qla2x00_nv_write(ha, NVR_DATA_OUT);
  115. else
  116. qla2x00_nv_write(ha, 0);
  117. nv_cmd <<= 1;
  118. }
  119. qla2x00_nv_deselect(ha);
  120. /* Wait for NVRAM to become ready */
  121. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  122. do {
  123. NVRAM_DELAY();
  124. word = RD_REG_WORD(&reg->nvram);
  125. } while ((word & NVR_DATA_IN) == 0);
  126. qla2x00_nv_deselect(ha);
  127. /* Disable writes */
  128. qla2x00_nv_write(ha, NVR_DATA_OUT);
  129. for (count = 0; count < 10; count++)
  130. qla2x00_nv_write(ha, 0);
  131. qla2x00_nv_deselect(ha);
  132. }
  133. static int
  134. qla2x00_write_nvram_word_tmo(scsi_qla_host_t *ha, uint32_t addr, uint16_t data,
  135. uint32_t tmo)
  136. {
  137. int ret, count;
  138. uint16_t word;
  139. uint32_t nv_cmd;
  140. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  141. ret = QLA_SUCCESS;
  142. qla2x00_nv_write(ha, NVR_DATA_OUT);
  143. qla2x00_nv_write(ha, 0);
  144. qla2x00_nv_write(ha, 0);
  145. for (word = 0; word < 8; word++)
  146. qla2x00_nv_write(ha, NVR_DATA_OUT);
  147. qla2x00_nv_deselect(ha);
  148. /* Write data */
  149. nv_cmd = (addr << 16) | NV_WRITE_OP;
  150. nv_cmd |= data;
  151. nv_cmd <<= 5;
  152. for (count = 0; count < 27; count++) {
  153. if (nv_cmd & BIT_31)
  154. qla2x00_nv_write(ha, NVR_DATA_OUT);
  155. else
  156. qla2x00_nv_write(ha, 0);
  157. nv_cmd <<= 1;
  158. }
  159. qla2x00_nv_deselect(ha);
  160. /* Wait for NVRAM to become ready */
  161. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  162. do {
  163. NVRAM_DELAY();
  164. word = RD_REG_WORD(&reg->nvram);
  165. if (!--tmo) {
  166. ret = QLA_FUNCTION_FAILED;
  167. break;
  168. }
  169. } while ((word & NVR_DATA_IN) == 0);
  170. qla2x00_nv_deselect(ha);
  171. /* Disable writes */
  172. qla2x00_nv_write(ha, NVR_DATA_OUT);
  173. for (count = 0; count < 10; count++)
  174. qla2x00_nv_write(ha, 0);
  175. qla2x00_nv_deselect(ha);
  176. return ret;
  177. }
  178. /**
  179. * qla2x00_nvram_request() - Sends read command to NVRAM and gets data from
  180. * NVRAM.
  181. * @ha: HA context
  182. * @nv_cmd: NVRAM command
  183. *
  184. * Bit definitions for NVRAM command:
  185. *
  186. * Bit 26 = start bit
  187. * Bit 25, 24 = opcode
  188. * Bit 23-16 = address
  189. * Bit 15-0 = write data
  190. *
  191. * Returns the word read from nvram @addr.
  192. */
  193. static uint16_t
  194. qla2x00_nvram_request(scsi_qla_host_t *ha, uint32_t nv_cmd)
  195. {
  196. uint8_t cnt;
  197. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  198. uint16_t data = 0;
  199. uint16_t reg_data;
  200. /* Send command to NVRAM. */
  201. nv_cmd <<= 5;
  202. for (cnt = 0; cnt < 11; cnt++) {
  203. if (nv_cmd & BIT_31)
  204. qla2x00_nv_write(ha, NVR_DATA_OUT);
  205. else
  206. qla2x00_nv_write(ha, 0);
  207. nv_cmd <<= 1;
  208. }
  209. /* Read data from NVRAM. */
  210. for (cnt = 0; cnt < 16; cnt++) {
  211. WRT_REG_WORD(&reg->nvram, NVR_SELECT | NVR_CLOCK);
  212. NVRAM_DELAY();
  213. data <<= 1;
  214. reg_data = RD_REG_WORD(&reg->nvram);
  215. if (reg_data & NVR_DATA_IN)
  216. data |= BIT_0;
  217. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  218. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  219. NVRAM_DELAY();
  220. }
  221. /* Deselect chip. */
  222. WRT_REG_WORD(&reg->nvram, NVR_DESELECT);
  223. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  224. NVRAM_DELAY();
  225. return (data);
  226. }
  227. /**
  228. * qla2x00_nv_write() - Clean NVRAM operations.
  229. * @ha: HA context
  230. */
  231. static void
  232. qla2x00_nv_deselect(scsi_qla_host_t *ha)
  233. {
  234. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  235. WRT_REG_WORD(&reg->nvram, NVR_DESELECT);
  236. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  237. NVRAM_DELAY();
  238. }
  239. /**
  240. * qla2x00_nv_write() - Prepare for NVRAM read/write operation.
  241. * @ha: HA context
  242. * @data: Serial interface selector
  243. */
  244. static void
  245. qla2x00_nv_write(scsi_qla_host_t *ha, uint16_t data)
  246. {
  247. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  248. WRT_REG_WORD(&reg->nvram, data | NVR_SELECT | NVR_WRT_ENABLE);
  249. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  250. NVRAM_DELAY();
  251. WRT_REG_WORD(&reg->nvram, data | NVR_SELECT| NVR_CLOCK |
  252. NVR_WRT_ENABLE);
  253. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  254. NVRAM_DELAY();
  255. WRT_REG_WORD(&reg->nvram, data | NVR_SELECT | NVR_WRT_ENABLE);
  256. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  257. NVRAM_DELAY();
  258. }
  259. /**
  260. * qla2x00_clear_nvram_protection() -
  261. * @ha: HA context
  262. */
  263. static int
  264. qla2x00_clear_nvram_protection(scsi_qla_host_t *ha)
  265. {
  266. int ret, stat;
  267. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  268. uint32_t word;
  269. uint16_t wprot, wprot_old;
  270. /* Clear NVRAM write protection. */
  271. ret = QLA_FUNCTION_FAILED;
  272. wprot_old = cpu_to_le16(qla2x00_get_nvram_word(ha, 0));
  273. stat = qla2x00_write_nvram_word_tmo(ha, 0,
  274. __constant_cpu_to_le16(0x1234), 100000);
  275. wprot = cpu_to_le16(qla2x00_get_nvram_word(ha, 0));
  276. if (stat != QLA_SUCCESS || wprot != __constant_cpu_to_le16(0x1234)) {
  277. /* Write enable. */
  278. qla2x00_nv_write(ha, NVR_DATA_OUT);
  279. qla2x00_nv_write(ha, 0);
  280. qla2x00_nv_write(ha, 0);
  281. for (word = 0; word < 8; word++)
  282. qla2x00_nv_write(ha, NVR_DATA_OUT);
  283. qla2x00_nv_deselect(ha);
  284. /* Enable protection register. */
  285. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  286. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  287. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  288. for (word = 0; word < 8; word++)
  289. qla2x00_nv_write(ha, NVR_DATA_OUT | NVR_PR_ENABLE);
  290. qla2x00_nv_deselect(ha);
  291. /* Clear protection register (ffff is cleared). */
  292. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  293. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  294. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  295. for (word = 0; word < 8; word++)
  296. qla2x00_nv_write(ha, NVR_DATA_OUT | NVR_PR_ENABLE);
  297. qla2x00_nv_deselect(ha);
  298. /* Wait for NVRAM to become ready. */
  299. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  300. do {
  301. NVRAM_DELAY();
  302. word = RD_REG_WORD(&reg->nvram);
  303. } while ((word & NVR_DATA_IN) == 0);
  304. ret = QLA_SUCCESS;
  305. } else
  306. qla2x00_write_nvram_word(ha, 0, wprot_old);
  307. return ret;
  308. }
  309. static void
  310. qla2x00_set_nvram_protection(scsi_qla_host_t *ha, int stat)
  311. {
  312. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  313. uint32_t word;
  314. if (stat != QLA_SUCCESS)
  315. return;
  316. /* Set NVRAM write protection. */
  317. /* Write enable. */
  318. qla2x00_nv_write(ha, NVR_DATA_OUT);
  319. qla2x00_nv_write(ha, 0);
  320. qla2x00_nv_write(ha, 0);
  321. for (word = 0; word < 8; word++)
  322. qla2x00_nv_write(ha, NVR_DATA_OUT);
  323. qla2x00_nv_deselect(ha);
  324. /* Enable protection register. */
  325. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  326. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  327. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  328. for (word = 0; word < 8; word++)
  329. qla2x00_nv_write(ha, NVR_DATA_OUT | NVR_PR_ENABLE);
  330. qla2x00_nv_deselect(ha);
  331. /* Enable protection register. */
  332. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  333. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  334. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  335. for (word = 0; word < 8; word++)
  336. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  337. qla2x00_nv_deselect(ha);
  338. /* Wait for NVRAM to become ready. */
  339. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  340. do {
  341. NVRAM_DELAY();
  342. word = RD_REG_WORD(&reg->nvram);
  343. } while ((word & NVR_DATA_IN) == 0);
  344. }
  345. /*****************************************************************************/
  346. /* Flash Manipulation Routines */
  347. /*****************************************************************************/
  348. static inline uint32_t
  349. flash_conf_to_access_addr(uint32_t faddr)
  350. {
  351. return FARX_ACCESS_FLASH_CONF | faddr;
  352. }
  353. static inline uint32_t
  354. flash_data_to_access_addr(uint32_t faddr)
  355. {
  356. return FARX_ACCESS_FLASH_DATA | faddr;
  357. }
  358. static inline uint32_t
  359. nvram_conf_to_access_addr(uint32_t naddr)
  360. {
  361. return FARX_ACCESS_NVRAM_CONF | naddr;
  362. }
  363. static inline uint32_t
  364. nvram_data_to_access_addr(uint32_t naddr)
  365. {
  366. return FARX_ACCESS_NVRAM_DATA | naddr;
  367. }
  368. uint32_t
  369. qla24xx_read_flash_dword(scsi_qla_host_t *ha, uint32_t addr)
  370. {
  371. int rval;
  372. uint32_t cnt, data;
  373. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  374. WRT_REG_DWORD(&reg->flash_addr, addr & ~FARX_DATA_FLAG);
  375. /* Wait for READ cycle to complete. */
  376. rval = QLA_SUCCESS;
  377. for (cnt = 3000;
  378. (RD_REG_DWORD(&reg->flash_addr) & FARX_DATA_FLAG) == 0 &&
  379. rval == QLA_SUCCESS; cnt--) {
  380. if (cnt)
  381. udelay(10);
  382. else
  383. rval = QLA_FUNCTION_TIMEOUT;
  384. }
  385. /* TODO: What happens if we time out? */
  386. data = 0xDEADDEAD;
  387. if (rval == QLA_SUCCESS)
  388. data = RD_REG_DWORD(&reg->flash_data);
  389. return data;
  390. }
  391. uint32_t *
  392. qla24xx_read_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
  393. uint32_t dwords)
  394. {
  395. uint32_t i;
  396. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  397. /* Pause RISC. */
  398. WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_PAUSE);
  399. RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
  400. /* Dword reads to flash. */
  401. for (i = 0; i < dwords; i++, faddr++)
  402. dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
  403. flash_data_to_access_addr(faddr)));
  404. /* Release RISC pause. */
  405. WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  406. RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
  407. return dwptr;
  408. }
  409. int
  410. qla24xx_write_flash_dword(scsi_qla_host_t *ha, uint32_t addr, uint32_t data)
  411. {
  412. int rval;
  413. uint32_t cnt;
  414. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  415. WRT_REG_DWORD(&reg->flash_data, data);
  416. RD_REG_DWORD(&reg->flash_data); /* PCI Posting. */
  417. WRT_REG_DWORD(&reg->flash_addr, addr | FARX_DATA_FLAG);
  418. /* Wait for Write cycle to complete. */
  419. rval = QLA_SUCCESS;
  420. for (cnt = 500000; (RD_REG_DWORD(&reg->flash_addr) & FARX_DATA_FLAG) &&
  421. rval == QLA_SUCCESS; cnt--) {
  422. if (cnt)
  423. udelay(10);
  424. else
  425. rval = QLA_FUNCTION_TIMEOUT;
  426. }
  427. return rval;
  428. }
  429. void
  430. qla24xx_get_flash_manufacturer(scsi_qla_host_t *ha, uint8_t *man_id,
  431. uint8_t *flash_id)
  432. {
  433. uint32_t ids;
  434. ids = qla24xx_read_flash_dword(ha, flash_data_to_access_addr(0xd03ab));
  435. *man_id = LSB(ids);
  436. *flash_id = MSB(ids);
  437. }
  438. int
  439. qla24xx_write_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
  440. uint32_t dwords)
  441. {
  442. int ret;
  443. uint32_t liter;
  444. uint32_t sec_mask, rest_addr, conf_addr;
  445. uint32_t fdata;
  446. uint8_t man_id, flash_id;
  447. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  448. ret = QLA_SUCCESS;
  449. /* Pause RISC. */
  450. WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_PAUSE);
  451. RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
  452. qla24xx_get_flash_manufacturer(ha, &man_id, &flash_id);
  453. DEBUG9(printk("%s(%ld): Flash man_id=%d flash_id=%d\n", __func__,
  454. ha->host_no, man_id, flash_id));
  455. conf_addr = flash_conf_to_access_addr(0x03d8);
  456. switch (man_id) {
  457. case 0xbf: /* STT flash. */
  458. rest_addr = 0x1fff;
  459. sec_mask = 0x3e000;
  460. if (flash_id == 0x80)
  461. conf_addr = flash_conf_to_access_addr(0x0352);
  462. break;
  463. case 0x13: /* ST M25P80. */
  464. rest_addr = 0x3fff;
  465. sec_mask = 0x3c000;
  466. break;
  467. default:
  468. /* Default to 64 kb sector size. */
  469. rest_addr = 0x3fff;
  470. sec_mask = 0x3c000;
  471. break;
  472. }
  473. /* Enable flash write. */
  474. WRT_REG_DWORD(&reg->ctrl_status,
  475. RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
  476. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  477. /* Disable flash write-protection. */
  478. qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0);
  479. do { /* Loop once to provide quick error exit. */
  480. for (liter = 0; liter < dwords; liter++, faddr++, dwptr++) {
  481. /* Are we at the beginning of a sector? */
  482. if ((faddr & rest_addr) == 0) {
  483. fdata = (faddr & sec_mask) << 2;
  484. ret = qla24xx_write_flash_dword(ha, conf_addr,
  485. (fdata & 0xff00) |((fdata << 16) &
  486. 0xff0000) | ((fdata >> 16) & 0xff));
  487. if (ret != QLA_SUCCESS) {
  488. DEBUG9(printk("%s(%ld) Unable to flash "
  489. "sector: address=%x.\n", __func__,
  490. ha->host_no, faddr));
  491. break;
  492. }
  493. }
  494. ret = qla24xx_write_flash_dword(ha,
  495. flash_data_to_access_addr(faddr),
  496. cpu_to_le32(*dwptr));
  497. if (ret != QLA_SUCCESS) {
  498. DEBUG9(printk("%s(%ld) Unable to program flash "
  499. "address=%x data=%x.\n", __func__,
  500. ha->host_no, faddr, *dwptr));
  501. break;
  502. }
  503. }
  504. } while (0);
  505. /* Disable flash write. */
  506. WRT_REG_DWORD(&reg->ctrl_status,
  507. RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
  508. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  509. /* Release RISC pause. */
  510. WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  511. RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
  512. return ret;
  513. }
  514. uint8_t *
  515. qla2x00_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  516. uint32_t bytes)
  517. {
  518. uint32_t i;
  519. uint16_t *wptr;
  520. /* Word reads to NVRAM via registers. */
  521. wptr = (uint16_t *)buf;
  522. qla2x00_lock_nvram_access(ha);
  523. for (i = 0; i < bytes >> 1; i++, naddr++)
  524. wptr[i] = cpu_to_le16(qla2x00_get_nvram_word(ha,
  525. naddr));
  526. qla2x00_unlock_nvram_access(ha);
  527. return buf;
  528. }
  529. uint8_t *
  530. qla24xx_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  531. uint32_t bytes)
  532. {
  533. uint32_t i;
  534. uint32_t *dwptr;
  535. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  536. /* Pause RISC. */
  537. WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_PAUSE);
  538. RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
  539. /* Dword reads to flash. */
  540. dwptr = (uint32_t *)buf;
  541. for (i = 0; i < bytes >> 2; i++, naddr++)
  542. dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
  543. nvram_data_to_access_addr(naddr)));
  544. /* Release RISC pause. */
  545. WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  546. RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
  547. return buf;
  548. }
  549. int
  550. qla2x00_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  551. uint32_t bytes)
  552. {
  553. int ret, stat;
  554. uint32_t i;
  555. uint16_t *wptr;
  556. ret = QLA_SUCCESS;
  557. qla2x00_lock_nvram_access(ha);
  558. /* Disable NVRAM write-protection. */
  559. stat = qla2x00_clear_nvram_protection(ha);
  560. wptr = (uint16_t *)buf;
  561. for (i = 0; i < bytes >> 1; i++, naddr++) {
  562. qla2x00_write_nvram_word(ha, naddr,
  563. cpu_to_le16(*wptr));
  564. wptr++;
  565. }
  566. /* Enable NVRAM write-protection. */
  567. qla2x00_set_nvram_protection(ha, stat);
  568. qla2x00_unlock_nvram_access(ha);
  569. return ret;
  570. }
  571. int
  572. qla24xx_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  573. uint32_t bytes)
  574. {
  575. int ret;
  576. uint32_t i;
  577. uint32_t *dwptr;
  578. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  579. ret = QLA_SUCCESS;
  580. /* Pause RISC. */
  581. WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_PAUSE);
  582. RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
  583. /* Enable flash write. */
  584. WRT_REG_DWORD(&reg->ctrl_status,
  585. RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
  586. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  587. /* Disable NVRAM write-protection. */
  588. qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
  589. 0);
  590. qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
  591. 0);
  592. /* Dword writes to flash. */
  593. dwptr = (uint32_t *)buf;
  594. for (i = 0; i < bytes >> 2; i++, naddr++, dwptr++) {
  595. ret = qla24xx_write_flash_dword(ha,
  596. nvram_data_to_access_addr(naddr),
  597. cpu_to_le32(*dwptr));
  598. if (ret != QLA_SUCCESS) {
  599. DEBUG9(printk("%s(%ld) Unable to program "
  600. "nvram address=%x data=%x.\n", __func__,
  601. ha->host_no, naddr, *dwptr));
  602. break;
  603. }
  604. }
  605. /* Enable NVRAM write-protection. */
  606. qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
  607. 0x8c);
  608. /* Disable flash write. */
  609. WRT_REG_DWORD(&reg->ctrl_status,
  610. RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
  611. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  612. /* Release RISC pause. */
  613. WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  614. RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
  615. return ret;
  616. }