qla_sup.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2005 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/delay.h>
  9. #include <asm/uaccess.h>
  10. static uint16_t qla2x00_nvram_request(scsi_qla_host_t *, uint32_t);
  11. static void qla2x00_nv_deselect(scsi_qla_host_t *);
  12. static void qla2x00_nv_write(scsi_qla_host_t *, uint16_t);
  13. /*
  14. * NVRAM support routines
  15. */
  16. /**
  17. * qla2x00_lock_nvram_access() -
  18. * @ha: HA context
  19. */
  20. void
  21. qla2x00_lock_nvram_access(scsi_qla_host_t *ha)
  22. {
  23. uint16_t data;
  24. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  25. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) {
  26. data = RD_REG_WORD(&reg->nvram);
  27. while (data & NVR_BUSY) {
  28. udelay(100);
  29. data = RD_REG_WORD(&reg->nvram);
  30. }
  31. /* Lock resource */
  32. WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0x1);
  33. RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  34. udelay(5);
  35. data = RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  36. while ((data & BIT_0) == 0) {
  37. /* Lock failed */
  38. udelay(100);
  39. WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0x1);
  40. RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  41. udelay(5);
  42. data = RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  43. }
  44. }
  45. }
  46. /**
  47. * qla2x00_unlock_nvram_access() -
  48. * @ha: HA context
  49. */
  50. void
  51. qla2x00_unlock_nvram_access(scsi_qla_host_t *ha)
  52. {
  53. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  54. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) {
  55. WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0);
  56. RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  57. }
  58. }
  59. /**
  60. * qla2x00_get_nvram_word() - Calculates word position in NVRAM and calls the
  61. * request routine to get the word from NVRAM.
  62. * @ha: HA context
  63. * @addr: Address in NVRAM to read
  64. *
  65. * Returns the word read from nvram @addr.
  66. */
  67. uint16_t
  68. qla2x00_get_nvram_word(scsi_qla_host_t *ha, uint32_t addr)
  69. {
  70. uint16_t data;
  71. uint32_t nv_cmd;
  72. nv_cmd = addr << 16;
  73. nv_cmd |= NV_READ_OP;
  74. data = qla2x00_nvram_request(ha, nv_cmd);
  75. return (data);
  76. }
  77. /**
  78. * qla2x00_write_nvram_word() - Write NVRAM data.
  79. * @ha: HA context
  80. * @addr: Address in NVRAM to write
  81. * @data: word to program
  82. */
  83. void
  84. qla2x00_write_nvram_word(scsi_qla_host_t *ha, uint32_t addr, uint16_t data)
  85. {
  86. int count;
  87. uint16_t word;
  88. uint32_t nv_cmd, wait_cnt;
  89. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  90. qla2x00_nv_write(ha, NVR_DATA_OUT);
  91. qla2x00_nv_write(ha, 0);
  92. qla2x00_nv_write(ha, 0);
  93. for (word = 0; word < 8; word++)
  94. qla2x00_nv_write(ha, NVR_DATA_OUT);
  95. qla2x00_nv_deselect(ha);
  96. /* Write data */
  97. nv_cmd = (addr << 16) | NV_WRITE_OP;
  98. nv_cmd |= data;
  99. nv_cmd <<= 5;
  100. for (count = 0; count < 27; count++) {
  101. if (nv_cmd & BIT_31)
  102. qla2x00_nv_write(ha, NVR_DATA_OUT);
  103. else
  104. qla2x00_nv_write(ha, 0);
  105. nv_cmd <<= 1;
  106. }
  107. qla2x00_nv_deselect(ha);
  108. /* Wait for NVRAM to become ready */
  109. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  110. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  111. wait_cnt = NVR_WAIT_CNT;
  112. do {
  113. if (!--wait_cnt) {
  114. DEBUG9_10(printk("%s(%ld): NVRAM didn't go ready...\n",
  115. __func__, ha->host_no));
  116. break;
  117. }
  118. NVRAM_DELAY();
  119. word = RD_REG_WORD(&reg->nvram);
  120. } while ((word & NVR_DATA_IN) == 0);
  121. qla2x00_nv_deselect(ha);
  122. /* Disable writes */
  123. qla2x00_nv_write(ha, NVR_DATA_OUT);
  124. for (count = 0; count < 10; count++)
  125. qla2x00_nv_write(ha, 0);
  126. qla2x00_nv_deselect(ha);
  127. }
  128. static int
  129. qla2x00_write_nvram_word_tmo(scsi_qla_host_t *ha, uint32_t addr, uint16_t data,
  130. uint32_t tmo)
  131. {
  132. int ret, count;
  133. uint16_t word;
  134. uint32_t nv_cmd;
  135. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  136. ret = QLA_SUCCESS;
  137. qla2x00_nv_write(ha, NVR_DATA_OUT);
  138. qla2x00_nv_write(ha, 0);
  139. qla2x00_nv_write(ha, 0);
  140. for (word = 0; word < 8; word++)
  141. qla2x00_nv_write(ha, NVR_DATA_OUT);
  142. qla2x00_nv_deselect(ha);
  143. /* Write data */
  144. nv_cmd = (addr << 16) | NV_WRITE_OP;
  145. nv_cmd |= data;
  146. nv_cmd <<= 5;
  147. for (count = 0; count < 27; count++) {
  148. if (nv_cmd & BIT_31)
  149. qla2x00_nv_write(ha, NVR_DATA_OUT);
  150. else
  151. qla2x00_nv_write(ha, 0);
  152. nv_cmd <<= 1;
  153. }
  154. qla2x00_nv_deselect(ha);
  155. /* Wait for NVRAM to become ready */
  156. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  157. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  158. do {
  159. NVRAM_DELAY();
  160. word = RD_REG_WORD(&reg->nvram);
  161. if (!--tmo) {
  162. ret = QLA_FUNCTION_FAILED;
  163. break;
  164. }
  165. } while ((word & NVR_DATA_IN) == 0);
  166. qla2x00_nv_deselect(ha);
  167. /* Disable writes */
  168. qla2x00_nv_write(ha, NVR_DATA_OUT);
  169. for (count = 0; count < 10; count++)
  170. qla2x00_nv_write(ha, 0);
  171. qla2x00_nv_deselect(ha);
  172. return ret;
  173. }
  174. /**
  175. * qla2x00_nvram_request() - Sends read command to NVRAM and gets data from
  176. * NVRAM.
  177. * @ha: HA context
  178. * @nv_cmd: NVRAM command
  179. *
  180. * Bit definitions for NVRAM command:
  181. *
  182. * Bit 26 = start bit
  183. * Bit 25, 24 = opcode
  184. * Bit 23-16 = address
  185. * Bit 15-0 = write data
  186. *
  187. * Returns the word read from nvram @addr.
  188. */
  189. static uint16_t
  190. qla2x00_nvram_request(scsi_qla_host_t *ha, uint32_t nv_cmd)
  191. {
  192. uint8_t cnt;
  193. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  194. uint16_t data = 0;
  195. uint16_t reg_data;
  196. /* Send command to NVRAM. */
  197. nv_cmd <<= 5;
  198. for (cnt = 0; cnt < 11; cnt++) {
  199. if (nv_cmd & BIT_31)
  200. qla2x00_nv_write(ha, NVR_DATA_OUT);
  201. else
  202. qla2x00_nv_write(ha, 0);
  203. nv_cmd <<= 1;
  204. }
  205. /* Read data from NVRAM. */
  206. for (cnt = 0; cnt < 16; cnt++) {
  207. WRT_REG_WORD(&reg->nvram, NVR_SELECT | NVR_CLOCK);
  208. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  209. NVRAM_DELAY();
  210. data <<= 1;
  211. reg_data = RD_REG_WORD(&reg->nvram);
  212. if (reg_data & NVR_DATA_IN)
  213. data |= BIT_0;
  214. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  215. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  216. NVRAM_DELAY();
  217. }
  218. /* Deselect chip. */
  219. WRT_REG_WORD(&reg->nvram, NVR_DESELECT);
  220. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  221. NVRAM_DELAY();
  222. return (data);
  223. }
  224. /**
  225. * qla2x00_nv_write() - Clean NVRAM operations.
  226. * @ha: HA context
  227. */
  228. static void
  229. qla2x00_nv_deselect(scsi_qla_host_t *ha)
  230. {
  231. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  232. WRT_REG_WORD(&reg->nvram, NVR_DESELECT);
  233. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  234. NVRAM_DELAY();
  235. }
  236. /**
  237. * qla2x00_nv_write() - Prepare for NVRAM read/write operation.
  238. * @ha: HA context
  239. * @data: Serial interface selector
  240. */
  241. static void
  242. qla2x00_nv_write(scsi_qla_host_t *ha, uint16_t data)
  243. {
  244. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  245. WRT_REG_WORD(&reg->nvram, data | NVR_SELECT | NVR_WRT_ENABLE);
  246. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  247. NVRAM_DELAY();
  248. WRT_REG_WORD(&reg->nvram, data | NVR_SELECT| NVR_CLOCK |
  249. NVR_WRT_ENABLE);
  250. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  251. NVRAM_DELAY();
  252. WRT_REG_WORD(&reg->nvram, data | NVR_SELECT | NVR_WRT_ENABLE);
  253. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  254. NVRAM_DELAY();
  255. }
  256. /**
  257. * qla2x00_clear_nvram_protection() -
  258. * @ha: HA context
  259. */
  260. static int
  261. qla2x00_clear_nvram_protection(scsi_qla_host_t *ha)
  262. {
  263. int ret, stat;
  264. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  265. uint32_t word, wait_cnt;
  266. uint16_t wprot, wprot_old;
  267. /* Clear NVRAM write protection. */
  268. ret = QLA_FUNCTION_FAILED;
  269. wprot_old = cpu_to_le16(qla2x00_get_nvram_word(ha, ha->nvram_base));
  270. stat = qla2x00_write_nvram_word_tmo(ha, ha->nvram_base,
  271. __constant_cpu_to_le16(0x1234), 100000);
  272. wprot = cpu_to_le16(qla2x00_get_nvram_word(ha, ha->nvram_base));
  273. if (stat != QLA_SUCCESS || wprot != 0x1234) {
  274. /* Write enable. */
  275. qla2x00_nv_write(ha, NVR_DATA_OUT);
  276. qla2x00_nv_write(ha, 0);
  277. qla2x00_nv_write(ha, 0);
  278. for (word = 0; word < 8; word++)
  279. qla2x00_nv_write(ha, NVR_DATA_OUT);
  280. qla2x00_nv_deselect(ha);
  281. /* Enable protection register. */
  282. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  283. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  284. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  285. for (word = 0; word < 8; word++)
  286. qla2x00_nv_write(ha, NVR_DATA_OUT | NVR_PR_ENABLE);
  287. qla2x00_nv_deselect(ha);
  288. /* Clear protection register (ffff is cleared). */
  289. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  290. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  291. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  292. for (word = 0; word < 8; word++)
  293. qla2x00_nv_write(ha, NVR_DATA_OUT | NVR_PR_ENABLE);
  294. qla2x00_nv_deselect(ha);
  295. /* Wait for NVRAM to become ready. */
  296. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  297. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  298. wait_cnt = NVR_WAIT_CNT;
  299. do {
  300. if (!--wait_cnt) {
  301. DEBUG9_10(printk("%s(%ld): NVRAM didn't go "
  302. "ready...\n", __func__,
  303. ha->host_no));
  304. break;
  305. }
  306. NVRAM_DELAY();
  307. word = RD_REG_WORD(&reg->nvram);
  308. } while ((word & NVR_DATA_IN) == 0);
  309. if (wait_cnt)
  310. ret = QLA_SUCCESS;
  311. } else
  312. qla2x00_write_nvram_word(ha, ha->nvram_base, wprot_old);
  313. return ret;
  314. }
  315. static void
  316. qla2x00_set_nvram_protection(scsi_qla_host_t *ha, int stat)
  317. {
  318. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  319. uint32_t word, wait_cnt;
  320. if (stat != QLA_SUCCESS)
  321. return;
  322. /* Set NVRAM write protection. */
  323. /* Write enable. */
  324. qla2x00_nv_write(ha, NVR_DATA_OUT);
  325. qla2x00_nv_write(ha, 0);
  326. qla2x00_nv_write(ha, 0);
  327. for (word = 0; word < 8; word++)
  328. qla2x00_nv_write(ha, NVR_DATA_OUT);
  329. qla2x00_nv_deselect(ha);
  330. /* Enable protection register. */
  331. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  332. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  333. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  334. for (word = 0; word < 8; word++)
  335. qla2x00_nv_write(ha, NVR_DATA_OUT | NVR_PR_ENABLE);
  336. qla2x00_nv_deselect(ha);
  337. /* Enable protection register. */
  338. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  339. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  340. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  341. for (word = 0; word < 8; word++)
  342. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  343. qla2x00_nv_deselect(ha);
  344. /* Wait for NVRAM to become ready. */
  345. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  346. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  347. wait_cnt = NVR_WAIT_CNT;
  348. do {
  349. if (!--wait_cnt) {
  350. DEBUG9_10(printk("%s(%ld): NVRAM didn't go ready...\n",
  351. __func__, ha->host_no));
  352. break;
  353. }
  354. NVRAM_DELAY();
  355. word = RD_REG_WORD(&reg->nvram);
  356. } while ((word & NVR_DATA_IN) == 0);
  357. }
  358. /*****************************************************************************/
  359. /* Flash Manipulation Routines */
  360. /*****************************************************************************/
  361. static inline uint32_t
  362. flash_conf_to_access_addr(uint32_t faddr)
  363. {
  364. return FARX_ACCESS_FLASH_CONF | faddr;
  365. }
  366. static inline uint32_t
  367. flash_data_to_access_addr(uint32_t faddr)
  368. {
  369. return FARX_ACCESS_FLASH_DATA | faddr;
  370. }
  371. static inline uint32_t
  372. nvram_conf_to_access_addr(uint32_t naddr)
  373. {
  374. return FARX_ACCESS_NVRAM_CONF | naddr;
  375. }
  376. static inline uint32_t
  377. nvram_data_to_access_addr(uint32_t naddr)
  378. {
  379. return FARX_ACCESS_NVRAM_DATA | naddr;
  380. }
  381. static uint32_t
  382. qla24xx_read_flash_dword(scsi_qla_host_t *ha, uint32_t addr)
  383. {
  384. int rval;
  385. uint32_t cnt, data;
  386. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  387. WRT_REG_DWORD(&reg->flash_addr, addr & ~FARX_DATA_FLAG);
  388. /* Wait for READ cycle to complete. */
  389. rval = QLA_SUCCESS;
  390. for (cnt = 3000;
  391. (RD_REG_DWORD(&reg->flash_addr) & FARX_DATA_FLAG) == 0 &&
  392. rval == QLA_SUCCESS; cnt--) {
  393. if (cnt)
  394. udelay(10);
  395. else
  396. rval = QLA_FUNCTION_TIMEOUT;
  397. }
  398. /* TODO: What happens if we time out? */
  399. data = 0xDEADDEAD;
  400. if (rval == QLA_SUCCESS)
  401. data = RD_REG_DWORD(&reg->flash_data);
  402. return data;
  403. }
  404. uint32_t *
  405. qla24xx_read_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
  406. uint32_t dwords)
  407. {
  408. uint32_t i;
  409. /* Dword reads to flash. */
  410. for (i = 0; i < dwords; i++, faddr++)
  411. dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
  412. flash_data_to_access_addr(faddr)));
  413. return dwptr;
  414. }
  415. static int
  416. qla24xx_write_flash_dword(scsi_qla_host_t *ha, uint32_t addr, uint32_t data)
  417. {
  418. int rval;
  419. uint32_t cnt;
  420. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  421. WRT_REG_DWORD(&reg->flash_data, data);
  422. RD_REG_DWORD(&reg->flash_data); /* PCI Posting. */
  423. WRT_REG_DWORD(&reg->flash_addr, addr | FARX_DATA_FLAG);
  424. /* Wait for Write cycle to complete. */
  425. rval = QLA_SUCCESS;
  426. for (cnt = 500000; (RD_REG_DWORD(&reg->flash_addr) & FARX_DATA_FLAG) &&
  427. rval == QLA_SUCCESS; cnt--) {
  428. if (cnt)
  429. udelay(10);
  430. else
  431. rval = QLA_FUNCTION_TIMEOUT;
  432. }
  433. return rval;
  434. }
  435. static void
  436. qla24xx_get_flash_manufacturer(scsi_qla_host_t *ha, uint8_t *man_id,
  437. uint8_t *flash_id)
  438. {
  439. uint32_t ids;
  440. ids = qla24xx_read_flash_dword(ha, flash_data_to_access_addr(0xd03ab));
  441. *man_id = LSB(ids);
  442. *flash_id = MSB(ids);
  443. /* Check if man_id and flash_id are valid. */
  444. if (ids != 0xDEADDEAD && (*man_id == 0 || *flash_id == 0)) {
  445. /* Read information using 0x9f opcode
  446. * Device ID, Mfg ID would be read in the format:
  447. * <Ext Dev Info><Device ID Part2><Device ID Part 1><Mfg ID>
  448. * Example: ATMEL 0x00 01 45 1F
  449. * Extract MFG and Dev ID from last two bytes.
  450. */
  451. ids = qla24xx_read_flash_dword(ha,
  452. flash_data_to_access_addr(0xd009f));
  453. *man_id = LSB(ids);
  454. *flash_id = MSB(ids);
  455. }
  456. }
  457. static int
  458. qla24xx_write_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
  459. uint32_t dwords)
  460. {
  461. int ret;
  462. uint32_t liter;
  463. uint32_t sec_mask, rest_addr, conf_addr, sec_end_mask;
  464. uint32_t fdata, findex ;
  465. uint8_t man_id, flash_id;
  466. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  467. ret = QLA_SUCCESS;
  468. qla24xx_get_flash_manufacturer(ha, &man_id, &flash_id);
  469. DEBUG9(printk("%s(%ld): Flash man_id=%d flash_id=%d\n", __func__,
  470. ha->host_no, man_id, flash_id));
  471. sec_end_mask = 0;
  472. conf_addr = flash_conf_to_access_addr(0x03d8);
  473. switch (man_id) {
  474. case 0xbf: /* STT flash. */
  475. rest_addr = 0x1fff;
  476. sec_mask = 0x3e000;
  477. if (flash_id == 0x80)
  478. conf_addr = flash_conf_to_access_addr(0x0352);
  479. break;
  480. case 0x13: /* ST M25P80. */
  481. rest_addr = 0x3fff;
  482. sec_mask = 0x3c000;
  483. break;
  484. case 0x1f: // Atmel 26DF081A
  485. rest_addr = 0x0fff;
  486. sec_mask = 0xff000;
  487. sec_end_mask = 0x003ff;
  488. conf_addr = flash_conf_to_access_addr(0x0320);
  489. break;
  490. default:
  491. /* Default to 64 kb sector size. */
  492. rest_addr = 0x3fff;
  493. sec_mask = 0x3c000;
  494. break;
  495. }
  496. /* Enable flash write. */
  497. WRT_REG_DWORD(&reg->ctrl_status,
  498. RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
  499. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  500. /* Disable flash write-protection. */
  501. qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0);
  502. /* Some flash parts need an additional zero-write to clear bits.*/
  503. qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0);
  504. do { /* Loop once to provide quick error exit. */
  505. for (liter = 0; liter < dwords; liter++, faddr++, dwptr++) {
  506. if (man_id == 0x1f) {
  507. findex = faddr << 2;
  508. fdata = findex & sec_mask;
  509. } else {
  510. findex = faddr;
  511. fdata = (findex & sec_mask) << 2;
  512. }
  513. /* Are we at the beginning of a sector? */
  514. if ((findex & rest_addr) == 0) {
  515. /*
  516. * Do sector unprotect at 4K boundry for Atmel
  517. * part.
  518. */
  519. if (man_id == 0x1f)
  520. qla24xx_write_flash_dword(ha,
  521. flash_conf_to_access_addr(0x0339),
  522. (fdata & 0xff00) | ((fdata << 16) &
  523. 0xff0000) | ((fdata >> 16) & 0xff));
  524. ret = qla24xx_write_flash_dword(ha, conf_addr,
  525. (fdata & 0xff00) |((fdata << 16) &
  526. 0xff0000) | ((fdata >> 16) & 0xff));
  527. if (ret != QLA_SUCCESS) {
  528. DEBUG9(printk("%s(%ld) Unable to flash "
  529. "sector: address=%x.\n", __func__,
  530. ha->host_no, faddr));
  531. break;
  532. }
  533. }
  534. ret = qla24xx_write_flash_dword(ha,
  535. flash_data_to_access_addr(faddr),
  536. cpu_to_le32(*dwptr));
  537. if (ret != QLA_SUCCESS) {
  538. DEBUG9(printk("%s(%ld) Unable to program flash "
  539. "address=%x data=%x.\n", __func__,
  540. ha->host_no, faddr, *dwptr));
  541. break;
  542. }
  543. /* Do sector protect at 4K boundry for Atmel part. */
  544. if (man_id == 0x1f &&
  545. ((faddr & sec_end_mask) == 0x3ff))
  546. qla24xx_write_flash_dword(ha,
  547. flash_conf_to_access_addr(0x0336),
  548. (fdata & 0xff00) | ((fdata << 16) &
  549. 0xff0000) | ((fdata >> 16) & 0xff));
  550. }
  551. } while (0);
  552. /* Enable flash write-protection. */
  553. qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0x9c);
  554. /* Disable flash write. */
  555. WRT_REG_DWORD(&reg->ctrl_status,
  556. RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
  557. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  558. return ret;
  559. }
  560. uint8_t *
  561. qla2x00_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  562. uint32_t bytes)
  563. {
  564. uint32_t i;
  565. uint16_t *wptr;
  566. /* Word reads to NVRAM via registers. */
  567. wptr = (uint16_t *)buf;
  568. qla2x00_lock_nvram_access(ha);
  569. for (i = 0; i < bytes >> 1; i++, naddr++)
  570. wptr[i] = cpu_to_le16(qla2x00_get_nvram_word(ha,
  571. naddr));
  572. qla2x00_unlock_nvram_access(ha);
  573. return buf;
  574. }
  575. uint8_t *
  576. qla24xx_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  577. uint32_t bytes)
  578. {
  579. uint32_t i;
  580. uint32_t *dwptr;
  581. /* Dword reads to flash. */
  582. dwptr = (uint32_t *)buf;
  583. for (i = 0; i < bytes >> 2; i++, naddr++)
  584. dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
  585. nvram_data_to_access_addr(naddr)));
  586. return buf;
  587. }
  588. int
  589. qla2x00_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  590. uint32_t bytes)
  591. {
  592. int ret, stat;
  593. uint32_t i;
  594. uint16_t *wptr;
  595. ret = QLA_SUCCESS;
  596. qla2x00_lock_nvram_access(ha);
  597. /* Disable NVRAM write-protection. */
  598. stat = qla2x00_clear_nvram_protection(ha);
  599. wptr = (uint16_t *)buf;
  600. for (i = 0; i < bytes >> 1; i++, naddr++) {
  601. qla2x00_write_nvram_word(ha, naddr,
  602. cpu_to_le16(*wptr));
  603. wptr++;
  604. }
  605. /* Enable NVRAM write-protection. */
  606. qla2x00_set_nvram_protection(ha, stat);
  607. qla2x00_unlock_nvram_access(ha);
  608. return ret;
  609. }
  610. int
  611. qla24xx_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  612. uint32_t bytes)
  613. {
  614. int ret;
  615. uint32_t i;
  616. uint32_t *dwptr;
  617. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  618. ret = QLA_SUCCESS;
  619. /* Enable flash write. */
  620. WRT_REG_DWORD(&reg->ctrl_status,
  621. RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
  622. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  623. /* Disable NVRAM write-protection. */
  624. qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
  625. 0);
  626. qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
  627. 0);
  628. /* Dword writes to flash. */
  629. dwptr = (uint32_t *)buf;
  630. for (i = 0; i < bytes >> 2; i++, naddr++, dwptr++) {
  631. ret = qla24xx_write_flash_dword(ha,
  632. nvram_data_to_access_addr(naddr),
  633. cpu_to_le32(*dwptr));
  634. if (ret != QLA_SUCCESS) {
  635. DEBUG9(printk("%s(%ld) Unable to program "
  636. "nvram address=%x data=%x.\n", __func__,
  637. ha->host_no, naddr, *dwptr));
  638. break;
  639. }
  640. }
  641. /* Enable NVRAM write-protection. */
  642. qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
  643. 0x8c);
  644. /* Disable flash write. */
  645. WRT_REG_DWORD(&reg->ctrl_status,
  646. RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
  647. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  648. return ret;
  649. }
  650. static inline void
  651. qla2x00_flip_colors(scsi_qla_host_t *ha, uint16_t *pflags)
  652. {
  653. if (IS_QLA2322(ha)) {
  654. /* Flip all colors. */
  655. if (ha->beacon_color_state == QLA_LED_ALL_ON) {
  656. /* Turn off. */
  657. ha->beacon_color_state = 0;
  658. *pflags = GPIO_LED_ALL_OFF;
  659. } else {
  660. /* Turn on. */
  661. ha->beacon_color_state = QLA_LED_ALL_ON;
  662. *pflags = GPIO_LED_RGA_ON;
  663. }
  664. } else {
  665. /* Flip green led only. */
  666. if (ha->beacon_color_state == QLA_LED_GRN_ON) {
  667. /* Turn off. */
  668. ha->beacon_color_state = 0;
  669. *pflags = GPIO_LED_GREEN_OFF_AMBER_OFF;
  670. } else {
  671. /* Turn on. */
  672. ha->beacon_color_state = QLA_LED_GRN_ON;
  673. *pflags = GPIO_LED_GREEN_ON_AMBER_OFF;
  674. }
  675. }
  676. }
  677. void
  678. qla2x00_beacon_blink(struct scsi_qla_host *ha)
  679. {
  680. uint16_t gpio_enable;
  681. uint16_t gpio_data;
  682. uint16_t led_color = 0;
  683. unsigned long flags;
  684. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  685. if (ha->pio_address)
  686. reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
  687. spin_lock_irqsave(&ha->hardware_lock, flags);
  688. /* Save the Original GPIOE. */
  689. if (ha->pio_address) {
  690. gpio_enable = RD_REG_WORD_PIO(&reg->gpioe);
  691. gpio_data = RD_REG_WORD_PIO(&reg->gpiod);
  692. } else {
  693. gpio_enable = RD_REG_WORD(&reg->gpioe);
  694. gpio_data = RD_REG_WORD(&reg->gpiod);
  695. }
  696. /* Set the modified gpio_enable values */
  697. gpio_enable |= GPIO_LED_MASK;
  698. if (ha->pio_address) {
  699. WRT_REG_WORD_PIO(&reg->gpioe, gpio_enable);
  700. } else {
  701. WRT_REG_WORD(&reg->gpioe, gpio_enable);
  702. RD_REG_WORD(&reg->gpioe);
  703. }
  704. qla2x00_flip_colors(ha, &led_color);
  705. /* Clear out any previously set LED color. */
  706. gpio_data &= ~GPIO_LED_MASK;
  707. /* Set the new input LED color to GPIOD. */
  708. gpio_data |= led_color;
  709. /* Set the modified gpio_data values */
  710. if (ha->pio_address) {
  711. WRT_REG_WORD_PIO(&reg->gpiod, gpio_data);
  712. } else {
  713. WRT_REG_WORD(&reg->gpiod, gpio_data);
  714. RD_REG_WORD(&reg->gpiod);
  715. }
  716. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  717. }
  718. int
  719. qla2x00_beacon_on(struct scsi_qla_host *ha)
  720. {
  721. uint16_t gpio_enable;
  722. uint16_t gpio_data;
  723. unsigned long flags;
  724. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  725. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  726. ha->fw_options[1] |= FO1_DISABLE_GPIO6_7;
  727. if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
  728. qla_printk(KERN_WARNING, ha,
  729. "Unable to update fw options (beacon on).\n");
  730. return QLA_FUNCTION_FAILED;
  731. }
  732. if (ha->pio_address)
  733. reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
  734. /* Turn off LEDs. */
  735. spin_lock_irqsave(&ha->hardware_lock, flags);
  736. if (ha->pio_address) {
  737. gpio_enable = RD_REG_WORD_PIO(&reg->gpioe);
  738. gpio_data = RD_REG_WORD_PIO(&reg->gpiod);
  739. } else {
  740. gpio_enable = RD_REG_WORD(&reg->gpioe);
  741. gpio_data = RD_REG_WORD(&reg->gpiod);
  742. }
  743. gpio_enable |= GPIO_LED_MASK;
  744. /* Set the modified gpio_enable values. */
  745. if (ha->pio_address) {
  746. WRT_REG_WORD_PIO(&reg->gpioe, gpio_enable);
  747. } else {
  748. WRT_REG_WORD(&reg->gpioe, gpio_enable);
  749. RD_REG_WORD(&reg->gpioe);
  750. }
  751. /* Clear out previously set LED colour. */
  752. gpio_data &= ~GPIO_LED_MASK;
  753. if (ha->pio_address) {
  754. WRT_REG_WORD_PIO(&reg->gpiod, gpio_data);
  755. } else {
  756. WRT_REG_WORD(&reg->gpiod, gpio_data);
  757. RD_REG_WORD(&reg->gpiod);
  758. }
  759. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  760. /*
  761. * Let the per HBA timer kick off the blinking process based on
  762. * the following flags. No need to do anything else now.
  763. */
  764. ha->beacon_blink_led = 1;
  765. ha->beacon_color_state = 0;
  766. return QLA_SUCCESS;
  767. }
  768. int
  769. qla2x00_beacon_off(struct scsi_qla_host *ha)
  770. {
  771. int rval = QLA_SUCCESS;
  772. ha->beacon_blink_led = 0;
  773. /* Set the on flag so when it gets flipped it will be off. */
  774. if (IS_QLA2322(ha))
  775. ha->beacon_color_state = QLA_LED_ALL_ON;
  776. else
  777. ha->beacon_color_state = QLA_LED_GRN_ON;
  778. ha->isp_ops.beacon_blink(ha); /* This turns green LED off */
  779. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  780. ha->fw_options[1] &= ~FO1_DISABLE_GPIO6_7;
  781. rval = qla2x00_set_fw_options(ha, ha->fw_options);
  782. if (rval != QLA_SUCCESS)
  783. qla_printk(KERN_WARNING, ha,
  784. "Unable to update fw options (beacon off).\n");
  785. return rval;
  786. }
  787. static inline void
  788. qla24xx_flip_colors(scsi_qla_host_t *ha, uint16_t *pflags)
  789. {
  790. /* Flip all colors. */
  791. if (ha->beacon_color_state == QLA_LED_ALL_ON) {
  792. /* Turn off. */
  793. ha->beacon_color_state = 0;
  794. *pflags = 0;
  795. } else {
  796. /* Turn on. */
  797. ha->beacon_color_state = QLA_LED_ALL_ON;
  798. *pflags = GPDX_LED_YELLOW_ON | GPDX_LED_AMBER_ON;
  799. }
  800. }
  801. void
  802. qla24xx_beacon_blink(struct scsi_qla_host *ha)
  803. {
  804. uint16_t led_color = 0;
  805. uint32_t gpio_data;
  806. unsigned long flags;
  807. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  808. /* Save the Original GPIOD. */
  809. spin_lock_irqsave(&ha->hardware_lock, flags);
  810. gpio_data = RD_REG_DWORD(&reg->gpiod);
  811. /* Enable the gpio_data reg for update. */
  812. gpio_data |= GPDX_LED_UPDATE_MASK;
  813. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  814. gpio_data = RD_REG_DWORD(&reg->gpiod);
  815. /* Set the color bits. */
  816. qla24xx_flip_colors(ha, &led_color);
  817. /* Clear out any previously set LED color. */
  818. gpio_data &= ~GPDX_LED_COLOR_MASK;
  819. /* Set the new input LED color to GPIOD. */
  820. gpio_data |= led_color;
  821. /* Set the modified gpio_data values. */
  822. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  823. gpio_data = RD_REG_DWORD(&reg->gpiod);
  824. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  825. }
  826. int
  827. qla24xx_beacon_on(struct scsi_qla_host *ha)
  828. {
  829. uint32_t gpio_data;
  830. unsigned long flags;
  831. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  832. if (ha->beacon_blink_led == 0) {
  833. /* Enable firmware for update */
  834. ha->fw_options[1] |= ADD_FO1_DISABLE_GPIO_LED_CTRL;
  835. if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS)
  836. return QLA_FUNCTION_FAILED;
  837. if (qla2x00_get_fw_options(ha, ha->fw_options) !=
  838. QLA_SUCCESS) {
  839. qla_printk(KERN_WARNING, ha,
  840. "Unable to update fw options (beacon on).\n");
  841. return QLA_FUNCTION_FAILED;
  842. }
  843. spin_lock_irqsave(&ha->hardware_lock, flags);
  844. gpio_data = RD_REG_DWORD(&reg->gpiod);
  845. /* Enable the gpio_data reg for update. */
  846. gpio_data |= GPDX_LED_UPDATE_MASK;
  847. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  848. RD_REG_DWORD(&reg->gpiod);
  849. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  850. }
  851. /* So all colors blink together. */
  852. ha->beacon_color_state = 0;
  853. /* Let the per HBA timer kick off the blinking process. */
  854. ha->beacon_blink_led = 1;
  855. return QLA_SUCCESS;
  856. }
  857. int
  858. qla24xx_beacon_off(struct scsi_qla_host *ha)
  859. {
  860. uint32_t gpio_data;
  861. unsigned long flags;
  862. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  863. ha->beacon_blink_led = 0;
  864. ha->beacon_color_state = QLA_LED_ALL_ON;
  865. ha->isp_ops.beacon_blink(ha); /* Will flip to all off. */
  866. /* Give control back to firmware. */
  867. spin_lock_irqsave(&ha->hardware_lock, flags);
  868. gpio_data = RD_REG_DWORD(&reg->gpiod);
  869. /* Disable the gpio_data reg for update. */
  870. gpio_data &= ~GPDX_LED_UPDATE_MASK;
  871. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  872. RD_REG_DWORD(&reg->gpiod);
  873. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  874. ha->fw_options[1] &= ~ADD_FO1_DISABLE_GPIO_LED_CTRL;
  875. if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
  876. qla_printk(KERN_WARNING, ha,
  877. "Unable to update fw options (beacon off).\n");
  878. return QLA_FUNCTION_FAILED;
  879. }
  880. if (qla2x00_get_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
  881. qla_printk(KERN_WARNING, ha,
  882. "Unable to get fw options (beacon off).\n");
  883. return QLA_FUNCTION_FAILED;
  884. }
  885. return QLA_SUCCESS;
  886. }
  887. /*
  888. * Flash support routines
  889. */
  890. /**
  891. * qla2x00_flash_enable() - Setup flash for reading and writing.
  892. * @ha: HA context
  893. */
  894. static void
  895. qla2x00_flash_enable(scsi_qla_host_t *ha)
  896. {
  897. uint16_t data;
  898. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  899. data = RD_REG_WORD(&reg->ctrl_status);
  900. data |= CSR_FLASH_ENABLE;
  901. WRT_REG_WORD(&reg->ctrl_status, data);
  902. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  903. }
  904. /**
  905. * qla2x00_flash_disable() - Disable flash and allow RISC to run.
  906. * @ha: HA context
  907. */
  908. static void
  909. qla2x00_flash_disable(scsi_qla_host_t *ha)
  910. {
  911. uint16_t data;
  912. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  913. data = RD_REG_WORD(&reg->ctrl_status);
  914. data &= ~(CSR_FLASH_ENABLE);
  915. WRT_REG_WORD(&reg->ctrl_status, data);
  916. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  917. }
  918. /**
  919. * qla2x00_read_flash_byte() - Reads a byte from flash
  920. * @ha: HA context
  921. * @addr: Address in flash to read
  922. *
  923. * A word is read from the chip, but, only the lower byte is valid.
  924. *
  925. * Returns the byte read from flash @addr.
  926. */
  927. static uint8_t
  928. qla2x00_read_flash_byte(scsi_qla_host_t *ha, uint32_t addr)
  929. {
  930. uint16_t data;
  931. uint16_t bank_select;
  932. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  933. bank_select = RD_REG_WORD(&reg->ctrl_status);
  934. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  935. /* Specify 64K address range: */
  936. /* clear out Module Select and Flash Address bits [19:16]. */
  937. bank_select &= ~0xf8;
  938. bank_select |= addr >> 12 & 0xf0;
  939. bank_select |= CSR_FLASH_64K_BANK;
  940. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  941. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  942. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  943. data = RD_REG_WORD(&reg->flash_data);
  944. return (uint8_t)data;
  945. }
  946. /* Setup bit 16 of flash address. */
  947. if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
  948. bank_select |= CSR_FLASH_64K_BANK;
  949. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  950. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  951. } else if (((addr & BIT_16) == 0) &&
  952. (bank_select & CSR_FLASH_64K_BANK)) {
  953. bank_select &= ~(CSR_FLASH_64K_BANK);
  954. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  955. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  956. }
  957. /* Always perform IO mapped accesses to the FLASH registers. */
  958. if (ha->pio_address) {
  959. uint16_t data2;
  960. reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
  961. WRT_REG_WORD_PIO(&reg->flash_address, (uint16_t)addr);
  962. do {
  963. data = RD_REG_WORD_PIO(&reg->flash_data);
  964. barrier();
  965. cpu_relax();
  966. data2 = RD_REG_WORD_PIO(&reg->flash_data);
  967. } while (data != data2);
  968. } else {
  969. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  970. data = qla2x00_debounce_register(&reg->flash_data);
  971. }
  972. return (uint8_t)data;
  973. }
  974. /**
  975. * qla2x00_write_flash_byte() - Write a byte to flash
  976. * @ha: HA context
  977. * @addr: Address in flash to write
  978. * @data: Data to write
  979. */
  980. static void
  981. qla2x00_write_flash_byte(scsi_qla_host_t *ha, uint32_t addr, uint8_t data)
  982. {
  983. uint16_t bank_select;
  984. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  985. bank_select = RD_REG_WORD(&reg->ctrl_status);
  986. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  987. /* Specify 64K address range: */
  988. /* clear out Module Select and Flash Address bits [19:16]. */
  989. bank_select &= ~0xf8;
  990. bank_select |= addr >> 12 & 0xf0;
  991. bank_select |= CSR_FLASH_64K_BANK;
  992. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  993. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  994. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  995. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  996. WRT_REG_WORD(&reg->flash_data, (uint16_t)data);
  997. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  998. return;
  999. }
  1000. /* Setup bit 16 of flash address. */
  1001. if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
  1002. bank_select |= CSR_FLASH_64K_BANK;
  1003. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1004. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1005. } else if (((addr & BIT_16) == 0) &&
  1006. (bank_select & CSR_FLASH_64K_BANK)) {
  1007. bank_select &= ~(CSR_FLASH_64K_BANK);
  1008. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1009. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1010. }
  1011. /* Always perform IO mapped accesses to the FLASH registers. */
  1012. if (ha->pio_address) {
  1013. reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
  1014. WRT_REG_WORD_PIO(&reg->flash_address, (uint16_t)addr);
  1015. WRT_REG_WORD_PIO(&reg->flash_data, (uint16_t)data);
  1016. } else {
  1017. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  1018. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1019. WRT_REG_WORD(&reg->flash_data, (uint16_t)data);
  1020. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1021. }
  1022. }
  1023. /**
  1024. * qla2x00_poll_flash() - Polls flash for completion.
  1025. * @ha: HA context
  1026. * @addr: Address in flash to poll
  1027. * @poll_data: Data to be polled
  1028. * @man_id: Flash manufacturer ID
  1029. * @flash_id: Flash ID
  1030. *
  1031. * This function polls the device until bit 7 of what is read matches data
  1032. * bit 7 or until data bit 5 becomes a 1. If that hapens, the flash ROM timed
  1033. * out (a fatal error). The flash book recommeds reading bit 7 again after
  1034. * reading bit 5 as a 1.
  1035. *
  1036. * Returns 0 on success, else non-zero.
  1037. */
  1038. static int
  1039. qla2x00_poll_flash(scsi_qla_host_t *ha, uint32_t addr, uint8_t poll_data,
  1040. uint8_t man_id, uint8_t flash_id)
  1041. {
  1042. int status;
  1043. uint8_t flash_data;
  1044. uint32_t cnt;
  1045. status = 1;
  1046. /* Wait for 30 seconds for command to finish. */
  1047. poll_data &= BIT_7;
  1048. for (cnt = 3000000; cnt; cnt--) {
  1049. flash_data = qla2x00_read_flash_byte(ha, addr);
  1050. if ((flash_data & BIT_7) == poll_data) {
  1051. status = 0;
  1052. break;
  1053. }
  1054. if (man_id != 0x40 && man_id != 0xda) {
  1055. if ((flash_data & BIT_5) && cnt > 2)
  1056. cnt = 2;
  1057. }
  1058. udelay(10);
  1059. barrier();
  1060. }
  1061. return status;
  1062. }
  1063. /**
  1064. * qla2x00_program_flash_address() - Programs a flash address
  1065. * @ha: HA context
  1066. * @addr: Address in flash to program
  1067. * @data: Data to be written in flash
  1068. * @man_id: Flash manufacturer ID
  1069. * @flash_id: Flash ID
  1070. *
  1071. * Returns 0 on success, else non-zero.
  1072. */
  1073. static int
  1074. qla2x00_program_flash_address(scsi_qla_host_t *ha, uint32_t addr, uint8_t data,
  1075. uint8_t man_id, uint8_t flash_id)
  1076. {
  1077. /* Write Program Command Sequence. */
  1078. if (IS_OEM_001(ha)) {
  1079. qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
  1080. qla2x00_write_flash_byte(ha, 0x555, 0x55);
  1081. qla2x00_write_flash_byte(ha, 0xaaa, 0xa0);
  1082. qla2x00_write_flash_byte(ha, addr, data);
  1083. } else {
  1084. if (man_id == 0xda && flash_id == 0xc1) {
  1085. qla2x00_write_flash_byte(ha, addr, data);
  1086. if (addr & 0x7e)
  1087. return 0;
  1088. } else {
  1089. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1090. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1091. qla2x00_write_flash_byte(ha, 0x5555, 0xa0);
  1092. qla2x00_write_flash_byte(ha, addr, data);
  1093. }
  1094. }
  1095. udelay(150);
  1096. /* Wait for write to complete. */
  1097. return qla2x00_poll_flash(ha, addr, data, man_id, flash_id);
  1098. }
  1099. /**
  1100. * qla2x00_erase_flash() - Erase the flash.
  1101. * @ha: HA context
  1102. * @man_id: Flash manufacturer ID
  1103. * @flash_id: Flash ID
  1104. *
  1105. * Returns 0 on success, else non-zero.
  1106. */
  1107. static int
  1108. qla2x00_erase_flash(scsi_qla_host_t *ha, uint8_t man_id, uint8_t flash_id)
  1109. {
  1110. /* Individual Sector Erase Command Sequence */
  1111. if (IS_OEM_001(ha)) {
  1112. qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
  1113. qla2x00_write_flash_byte(ha, 0x555, 0x55);
  1114. qla2x00_write_flash_byte(ha, 0xaaa, 0x80);
  1115. qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
  1116. qla2x00_write_flash_byte(ha, 0x555, 0x55);
  1117. qla2x00_write_flash_byte(ha, 0xaaa, 0x10);
  1118. } else {
  1119. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1120. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1121. qla2x00_write_flash_byte(ha, 0x5555, 0x80);
  1122. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1123. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1124. qla2x00_write_flash_byte(ha, 0x5555, 0x10);
  1125. }
  1126. udelay(150);
  1127. /* Wait for erase to complete. */
  1128. return qla2x00_poll_flash(ha, 0x00, 0x80, man_id, flash_id);
  1129. }
  1130. /**
  1131. * qla2x00_erase_flash_sector() - Erase a flash sector.
  1132. * @ha: HA context
  1133. * @addr: Flash sector to erase
  1134. * @sec_mask: Sector address mask
  1135. * @man_id: Flash manufacturer ID
  1136. * @flash_id: Flash ID
  1137. *
  1138. * Returns 0 on success, else non-zero.
  1139. */
  1140. static int
  1141. qla2x00_erase_flash_sector(scsi_qla_host_t *ha, uint32_t addr,
  1142. uint32_t sec_mask, uint8_t man_id, uint8_t flash_id)
  1143. {
  1144. /* Individual Sector Erase Command Sequence */
  1145. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1146. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1147. qla2x00_write_flash_byte(ha, 0x5555, 0x80);
  1148. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1149. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1150. if (man_id == 0x1f && flash_id == 0x13)
  1151. qla2x00_write_flash_byte(ha, addr & sec_mask, 0x10);
  1152. else
  1153. qla2x00_write_flash_byte(ha, addr & sec_mask, 0x30);
  1154. udelay(150);
  1155. /* Wait for erase to complete. */
  1156. return qla2x00_poll_flash(ha, addr, 0x80, man_id, flash_id);
  1157. }
  1158. /**
  1159. * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip.
  1160. * @man_id: Flash manufacturer ID
  1161. * @flash_id: Flash ID
  1162. */
  1163. static void
  1164. qla2x00_get_flash_manufacturer(scsi_qla_host_t *ha, uint8_t *man_id,
  1165. uint8_t *flash_id)
  1166. {
  1167. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1168. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1169. qla2x00_write_flash_byte(ha, 0x5555, 0x90);
  1170. *man_id = qla2x00_read_flash_byte(ha, 0x0000);
  1171. *flash_id = qla2x00_read_flash_byte(ha, 0x0001);
  1172. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1173. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1174. qla2x00_write_flash_byte(ha, 0x5555, 0xf0);
  1175. }
  1176. static inline void
  1177. qla2x00_suspend_hba(struct scsi_qla_host *ha)
  1178. {
  1179. int cnt;
  1180. unsigned long flags;
  1181. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1182. /* Suspend HBA. */
  1183. scsi_block_requests(ha->host);
  1184. ha->isp_ops.disable_intrs(ha);
  1185. set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1186. /* Pause RISC. */
  1187. spin_lock_irqsave(&ha->hardware_lock, flags);
  1188. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  1189. RD_REG_WORD(&reg->hccr);
  1190. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  1191. for (cnt = 0; cnt < 30000; cnt++) {
  1192. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
  1193. break;
  1194. udelay(100);
  1195. }
  1196. } else {
  1197. udelay(10);
  1198. }
  1199. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1200. }
  1201. static inline void
  1202. qla2x00_resume_hba(struct scsi_qla_host *ha)
  1203. {
  1204. /* Resume HBA. */
  1205. clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1206. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  1207. qla2xxx_wake_dpc(ha);
  1208. qla2x00_wait_for_hba_online(ha);
  1209. scsi_unblock_requests(ha->host);
  1210. }
  1211. uint8_t *
  1212. qla2x00_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1213. uint32_t offset, uint32_t length)
  1214. {
  1215. unsigned long flags;
  1216. uint32_t addr, midpoint;
  1217. uint8_t *data;
  1218. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1219. /* Suspend HBA. */
  1220. qla2x00_suspend_hba(ha);
  1221. /* Go with read. */
  1222. spin_lock_irqsave(&ha->hardware_lock, flags);
  1223. midpoint = ha->optrom_size / 2;
  1224. qla2x00_flash_enable(ha);
  1225. WRT_REG_WORD(&reg->nvram, 0);
  1226. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  1227. for (addr = offset, data = buf; addr < length; addr++, data++) {
  1228. if (addr == midpoint) {
  1229. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  1230. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  1231. }
  1232. *data = qla2x00_read_flash_byte(ha, addr);
  1233. }
  1234. qla2x00_flash_disable(ha);
  1235. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1236. /* Resume HBA. */
  1237. qla2x00_resume_hba(ha);
  1238. return buf;
  1239. }
  1240. int
  1241. qla2x00_write_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1242. uint32_t offset, uint32_t length)
  1243. {
  1244. int rval;
  1245. unsigned long flags;
  1246. uint8_t man_id, flash_id, sec_number, data;
  1247. uint16_t wd;
  1248. uint32_t addr, liter, sec_mask, rest_addr;
  1249. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1250. /* Suspend HBA. */
  1251. qla2x00_suspend_hba(ha);
  1252. rval = QLA_SUCCESS;
  1253. sec_number = 0;
  1254. /* Reset ISP chip. */
  1255. spin_lock_irqsave(&ha->hardware_lock, flags);
  1256. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  1257. pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
  1258. /* Go with write. */
  1259. qla2x00_flash_enable(ha);
  1260. do { /* Loop once to provide quick error exit */
  1261. /* Structure of flash memory based on manufacturer */
  1262. if (IS_OEM_001(ha)) {
  1263. /* OEM variant with special flash part. */
  1264. man_id = flash_id = 0;
  1265. rest_addr = 0xffff;
  1266. sec_mask = 0x10000;
  1267. goto update_flash;
  1268. }
  1269. qla2x00_get_flash_manufacturer(ha, &man_id, &flash_id);
  1270. switch (man_id) {
  1271. case 0x20: /* ST flash. */
  1272. if (flash_id == 0xd2 || flash_id == 0xe3) {
  1273. /*
  1274. * ST m29w008at part - 64kb sector size with
  1275. * 32kb,8kb,8kb,16kb sectors at memory address
  1276. * 0xf0000.
  1277. */
  1278. rest_addr = 0xffff;
  1279. sec_mask = 0x10000;
  1280. break;
  1281. }
  1282. /*
  1283. * ST m29w010b part - 16kb sector size
  1284. * Default to 16kb sectors
  1285. */
  1286. rest_addr = 0x3fff;
  1287. sec_mask = 0x1c000;
  1288. break;
  1289. case 0x40: /* Mostel flash. */
  1290. /* Mostel v29c51001 part - 512 byte sector size. */
  1291. rest_addr = 0x1ff;
  1292. sec_mask = 0x1fe00;
  1293. break;
  1294. case 0xbf: /* SST flash. */
  1295. /* SST39sf10 part - 4kb sector size. */
  1296. rest_addr = 0xfff;
  1297. sec_mask = 0x1f000;
  1298. break;
  1299. case 0xda: /* Winbond flash. */
  1300. /* Winbond W29EE011 part - 256 byte sector size. */
  1301. rest_addr = 0x7f;
  1302. sec_mask = 0x1ff80;
  1303. break;
  1304. case 0xc2: /* Macronix flash. */
  1305. /* 64k sector size. */
  1306. if (flash_id == 0x38 || flash_id == 0x4f) {
  1307. rest_addr = 0xffff;
  1308. sec_mask = 0x10000;
  1309. break;
  1310. }
  1311. /* Fall through... */
  1312. case 0x1f: /* Atmel flash. */
  1313. /* 512k sector size. */
  1314. if (flash_id == 0x13) {
  1315. rest_addr = 0x7fffffff;
  1316. sec_mask = 0x80000000;
  1317. break;
  1318. }
  1319. /* Fall through... */
  1320. case 0x01: /* AMD flash. */
  1321. if (flash_id == 0x38 || flash_id == 0x40 ||
  1322. flash_id == 0x4f) {
  1323. /* Am29LV081 part - 64kb sector size. */
  1324. /* Am29LV002BT part - 64kb sector size. */
  1325. rest_addr = 0xffff;
  1326. sec_mask = 0x10000;
  1327. break;
  1328. } else if (flash_id == 0x3e) {
  1329. /*
  1330. * Am29LV008b part - 64kb sector size with
  1331. * 32kb,8kb,8kb,16kb sector at memory address
  1332. * h0xf0000.
  1333. */
  1334. rest_addr = 0xffff;
  1335. sec_mask = 0x10000;
  1336. break;
  1337. } else if (flash_id == 0x20 || flash_id == 0x6e) {
  1338. /*
  1339. * Am29LV010 part or AM29f010 - 16kb sector
  1340. * size.
  1341. */
  1342. rest_addr = 0x3fff;
  1343. sec_mask = 0x1c000;
  1344. break;
  1345. } else if (flash_id == 0x6d) {
  1346. /* Am29LV001 part - 8kb sector size. */
  1347. rest_addr = 0x1fff;
  1348. sec_mask = 0x1e000;
  1349. break;
  1350. }
  1351. default:
  1352. /* Default to 16 kb sector size. */
  1353. rest_addr = 0x3fff;
  1354. sec_mask = 0x1c000;
  1355. break;
  1356. }
  1357. update_flash:
  1358. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  1359. if (qla2x00_erase_flash(ha, man_id, flash_id)) {
  1360. rval = QLA_FUNCTION_FAILED;
  1361. break;
  1362. }
  1363. }
  1364. for (addr = offset, liter = 0; liter < length; liter++,
  1365. addr++) {
  1366. data = buf[liter];
  1367. /* Are we at the beginning of a sector? */
  1368. if ((addr & rest_addr) == 0) {
  1369. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  1370. if (addr >= 0x10000UL) {
  1371. if (((addr >> 12) & 0xf0) &&
  1372. ((man_id == 0x01 &&
  1373. flash_id == 0x3e) ||
  1374. (man_id == 0x20 &&
  1375. flash_id == 0xd2))) {
  1376. sec_number++;
  1377. if (sec_number == 1) {
  1378. rest_addr =
  1379. 0x7fff;
  1380. sec_mask =
  1381. 0x18000;
  1382. } else if (
  1383. sec_number == 2 ||
  1384. sec_number == 3) {
  1385. rest_addr =
  1386. 0x1fff;
  1387. sec_mask =
  1388. 0x1e000;
  1389. } else if (
  1390. sec_number == 4) {
  1391. rest_addr =
  1392. 0x3fff;
  1393. sec_mask =
  1394. 0x1c000;
  1395. }
  1396. }
  1397. }
  1398. } else if (addr == ha->optrom_size / 2) {
  1399. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  1400. RD_REG_WORD(&reg->nvram);
  1401. }
  1402. if (flash_id == 0xda && man_id == 0xc1) {
  1403. qla2x00_write_flash_byte(ha, 0x5555,
  1404. 0xaa);
  1405. qla2x00_write_flash_byte(ha, 0x2aaa,
  1406. 0x55);
  1407. qla2x00_write_flash_byte(ha, 0x5555,
  1408. 0xa0);
  1409. } else if (!IS_QLA2322(ha) && !IS_QLA6322(ha)) {
  1410. /* Then erase it */
  1411. if (qla2x00_erase_flash_sector(ha,
  1412. addr, sec_mask, man_id,
  1413. flash_id)) {
  1414. rval = QLA_FUNCTION_FAILED;
  1415. break;
  1416. }
  1417. if (man_id == 0x01 && flash_id == 0x6d)
  1418. sec_number++;
  1419. }
  1420. }
  1421. if (man_id == 0x01 && flash_id == 0x6d) {
  1422. if (sec_number == 1 &&
  1423. addr == (rest_addr - 1)) {
  1424. rest_addr = 0x0fff;
  1425. sec_mask = 0x1f000;
  1426. } else if (sec_number == 3 && (addr & 0x7ffe)) {
  1427. rest_addr = 0x3fff;
  1428. sec_mask = 0x1c000;
  1429. }
  1430. }
  1431. if (qla2x00_program_flash_address(ha, addr, data,
  1432. man_id, flash_id)) {
  1433. rval = QLA_FUNCTION_FAILED;
  1434. break;
  1435. }
  1436. }
  1437. } while (0);
  1438. qla2x00_flash_disable(ha);
  1439. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1440. /* Resume HBA. */
  1441. qla2x00_resume_hba(ha);
  1442. return rval;
  1443. }
  1444. uint8_t *
  1445. qla24xx_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1446. uint32_t offset, uint32_t length)
  1447. {
  1448. /* Suspend HBA. */
  1449. scsi_block_requests(ha->host);
  1450. ha->isp_ops.disable_intrs(ha);
  1451. set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1452. /* Go with read. */
  1453. qla24xx_read_flash_data(ha, (uint32_t *)buf, offset >> 2, length >> 2);
  1454. /* Resume HBA. */
  1455. clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1456. ha->isp_ops.enable_intrs(ha);
  1457. scsi_unblock_requests(ha->host);
  1458. return buf;
  1459. }
  1460. int
  1461. qla24xx_write_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1462. uint32_t offset, uint32_t length)
  1463. {
  1464. int rval;
  1465. /* Suspend HBA. */
  1466. scsi_block_requests(ha->host);
  1467. ha->isp_ops.disable_intrs(ha);
  1468. set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1469. /* Go with write. */
  1470. rval = qla24xx_write_flash_data(ha, (uint32_t *)buf, offset >> 2,
  1471. length >> 2);
  1472. /* Resume HBA -- RISC reset needed. */
  1473. clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1474. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  1475. qla2xxx_wake_dpc(ha);
  1476. qla2x00_wait_for_hba_online(ha);
  1477. scsi_unblock_requests(ha->host);
  1478. return rval;
  1479. }