qla_sup.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724
  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. 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. 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. 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. 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. fdata = (faddr & sec_mask) << 2;
  525. ret = qla24xx_write_flash_dword(ha, conf_addr,
  526. (fdata & 0xff00) |((fdata << 16) &
  527. 0xff0000) | ((fdata >> 16) & 0xff));
  528. if (ret != QLA_SUCCESS) {
  529. DEBUG9(printk("%s(%ld) Unable to flash "
  530. "sector: address=%x.\n", __func__,
  531. ha->host_no, faddr));
  532. break;
  533. }
  534. }
  535. ret = qla24xx_write_flash_dword(ha,
  536. flash_data_to_access_addr(faddr),
  537. cpu_to_le32(*dwptr));
  538. if (ret != QLA_SUCCESS) {
  539. DEBUG9(printk("%s(%ld) Unable to program flash "
  540. "address=%x data=%x.\n", __func__,
  541. ha->host_no, faddr, *dwptr));
  542. break;
  543. }
  544. /* Do sector protect at 4K boundry for Atmel part. */
  545. if (man_id == 0x1f &&
  546. ((faddr & sec_end_mask) == 0x3ff))
  547. qla24xx_write_flash_dword(ha,
  548. flash_conf_to_access_addr(0x0336),
  549. (fdata & 0xff00) | ((fdata << 16) &
  550. 0xff0000) | ((fdata >> 16) & 0xff));
  551. }
  552. } while (0);
  553. /* Enable flash write-protection. */
  554. qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0x9c);
  555. /* Disable flash write. */
  556. WRT_REG_DWORD(&reg->ctrl_status,
  557. RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
  558. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  559. return ret;
  560. }
  561. uint8_t *
  562. qla2x00_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  563. uint32_t bytes)
  564. {
  565. uint32_t i;
  566. uint16_t *wptr;
  567. /* Word reads to NVRAM via registers. */
  568. wptr = (uint16_t *)buf;
  569. qla2x00_lock_nvram_access(ha);
  570. for (i = 0; i < bytes >> 1; i++, naddr++)
  571. wptr[i] = cpu_to_le16(qla2x00_get_nvram_word(ha,
  572. naddr));
  573. qla2x00_unlock_nvram_access(ha);
  574. return buf;
  575. }
  576. uint8_t *
  577. qla24xx_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  578. uint32_t bytes)
  579. {
  580. uint32_t i;
  581. uint32_t *dwptr;
  582. /* Dword reads to flash. */
  583. dwptr = (uint32_t *)buf;
  584. for (i = 0; i < bytes >> 2; i++, naddr++)
  585. dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
  586. nvram_data_to_access_addr(naddr)));
  587. return buf;
  588. }
  589. int
  590. qla2x00_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  591. uint32_t bytes)
  592. {
  593. int ret, stat;
  594. uint32_t i;
  595. uint16_t *wptr;
  596. ret = QLA_SUCCESS;
  597. qla2x00_lock_nvram_access(ha);
  598. /* Disable NVRAM write-protection. */
  599. stat = qla2x00_clear_nvram_protection(ha);
  600. wptr = (uint16_t *)buf;
  601. for (i = 0; i < bytes >> 1; i++, naddr++) {
  602. qla2x00_write_nvram_word(ha, naddr,
  603. cpu_to_le16(*wptr));
  604. wptr++;
  605. }
  606. /* Enable NVRAM write-protection. */
  607. qla2x00_set_nvram_protection(ha, stat);
  608. qla2x00_unlock_nvram_access(ha);
  609. return ret;
  610. }
  611. int
  612. qla24xx_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  613. uint32_t bytes)
  614. {
  615. int ret;
  616. uint32_t i;
  617. uint32_t *dwptr;
  618. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  619. ret = QLA_SUCCESS;
  620. /* Enable flash write. */
  621. WRT_REG_DWORD(&reg->ctrl_status,
  622. RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
  623. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  624. /* Disable NVRAM write-protection. */
  625. qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
  626. 0);
  627. qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
  628. 0);
  629. /* Dword writes to flash. */
  630. dwptr = (uint32_t *)buf;
  631. for (i = 0; i < bytes >> 2; i++, naddr++, dwptr++) {
  632. ret = qla24xx_write_flash_dword(ha,
  633. nvram_data_to_access_addr(naddr),
  634. cpu_to_le32(*dwptr));
  635. if (ret != QLA_SUCCESS) {
  636. DEBUG9(printk("%s(%ld) Unable to program "
  637. "nvram address=%x data=%x.\n", __func__,
  638. ha->host_no, naddr, *dwptr));
  639. break;
  640. }
  641. }
  642. /* Enable NVRAM write-protection. */
  643. qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
  644. 0x8c);
  645. /* Disable flash write. */
  646. WRT_REG_DWORD(&reg->ctrl_status,
  647. RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
  648. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  649. return ret;
  650. }
  651. static inline void
  652. qla2x00_flip_colors(scsi_qla_host_t *ha, uint16_t *pflags)
  653. {
  654. if (IS_QLA2322(ha)) {
  655. /* Flip all colors. */
  656. if (ha->beacon_color_state == QLA_LED_ALL_ON) {
  657. /* Turn off. */
  658. ha->beacon_color_state = 0;
  659. *pflags = GPIO_LED_ALL_OFF;
  660. } else {
  661. /* Turn on. */
  662. ha->beacon_color_state = QLA_LED_ALL_ON;
  663. *pflags = GPIO_LED_RGA_ON;
  664. }
  665. } else {
  666. /* Flip green led only. */
  667. if (ha->beacon_color_state == QLA_LED_GRN_ON) {
  668. /* Turn off. */
  669. ha->beacon_color_state = 0;
  670. *pflags = GPIO_LED_GREEN_OFF_AMBER_OFF;
  671. } else {
  672. /* Turn on. */
  673. ha->beacon_color_state = QLA_LED_GRN_ON;
  674. *pflags = GPIO_LED_GREEN_ON_AMBER_OFF;
  675. }
  676. }
  677. }
  678. void
  679. qla2x00_beacon_blink(struct scsi_qla_host *ha)
  680. {
  681. uint16_t gpio_enable;
  682. uint16_t gpio_data;
  683. uint16_t led_color = 0;
  684. unsigned long flags;
  685. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  686. if (ha->pio_address)
  687. reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
  688. spin_lock_irqsave(&ha->hardware_lock, flags);
  689. /* Save the Original GPIOE. */
  690. if (ha->pio_address) {
  691. gpio_enable = RD_REG_WORD_PIO(&reg->gpioe);
  692. gpio_data = RD_REG_WORD_PIO(&reg->gpiod);
  693. } else {
  694. gpio_enable = RD_REG_WORD(&reg->gpioe);
  695. gpio_data = RD_REG_WORD(&reg->gpiod);
  696. }
  697. /* Set the modified gpio_enable values */
  698. gpio_enable |= GPIO_LED_MASK;
  699. if (ha->pio_address) {
  700. WRT_REG_WORD_PIO(&reg->gpioe, gpio_enable);
  701. } else {
  702. WRT_REG_WORD(&reg->gpioe, gpio_enable);
  703. RD_REG_WORD(&reg->gpioe);
  704. }
  705. qla2x00_flip_colors(ha, &led_color);
  706. /* Clear out any previously set LED color. */
  707. gpio_data &= ~GPIO_LED_MASK;
  708. /* Set the new input LED color to GPIOD. */
  709. gpio_data |= led_color;
  710. /* Set the modified gpio_data values */
  711. if (ha->pio_address) {
  712. WRT_REG_WORD_PIO(&reg->gpiod, gpio_data);
  713. } else {
  714. WRT_REG_WORD(&reg->gpiod, gpio_data);
  715. RD_REG_WORD(&reg->gpiod);
  716. }
  717. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  718. }
  719. int
  720. qla2x00_beacon_on(struct scsi_qla_host *ha)
  721. {
  722. uint16_t gpio_enable;
  723. uint16_t gpio_data;
  724. unsigned long flags;
  725. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  726. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  727. ha->fw_options[1] |= FO1_DISABLE_GPIO6_7;
  728. if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
  729. qla_printk(KERN_WARNING, ha,
  730. "Unable to update fw options (beacon on).\n");
  731. return QLA_FUNCTION_FAILED;
  732. }
  733. if (ha->pio_address)
  734. reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
  735. /* Turn off LEDs. */
  736. spin_lock_irqsave(&ha->hardware_lock, flags);
  737. if (ha->pio_address) {
  738. gpio_enable = RD_REG_WORD_PIO(&reg->gpioe);
  739. gpio_data = RD_REG_WORD_PIO(&reg->gpiod);
  740. } else {
  741. gpio_enable = RD_REG_WORD(&reg->gpioe);
  742. gpio_data = RD_REG_WORD(&reg->gpiod);
  743. }
  744. gpio_enable |= GPIO_LED_MASK;
  745. /* Set the modified gpio_enable values. */
  746. if (ha->pio_address) {
  747. WRT_REG_WORD_PIO(&reg->gpioe, gpio_enable);
  748. } else {
  749. WRT_REG_WORD(&reg->gpioe, gpio_enable);
  750. RD_REG_WORD(&reg->gpioe);
  751. }
  752. /* Clear out previously set LED colour. */
  753. gpio_data &= ~GPIO_LED_MASK;
  754. if (ha->pio_address) {
  755. WRT_REG_WORD_PIO(&reg->gpiod, gpio_data);
  756. } else {
  757. WRT_REG_WORD(&reg->gpiod, gpio_data);
  758. RD_REG_WORD(&reg->gpiod);
  759. }
  760. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  761. /*
  762. * Let the per HBA timer kick off the blinking process based on
  763. * the following flags. No need to do anything else now.
  764. */
  765. ha->beacon_blink_led = 1;
  766. ha->beacon_color_state = 0;
  767. return QLA_SUCCESS;
  768. }
  769. int
  770. qla2x00_beacon_off(struct scsi_qla_host *ha)
  771. {
  772. int rval = QLA_SUCCESS;
  773. ha->beacon_blink_led = 0;
  774. /* Set the on flag so when it gets flipped it will be off. */
  775. if (IS_QLA2322(ha))
  776. ha->beacon_color_state = QLA_LED_ALL_ON;
  777. else
  778. ha->beacon_color_state = QLA_LED_GRN_ON;
  779. ha->isp_ops.beacon_blink(ha); /* This turns green LED off */
  780. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  781. ha->fw_options[1] &= ~FO1_DISABLE_GPIO6_7;
  782. rval = qla2x00_set_fw_options(ha, ha->fw_options);
  783. if (rval != QLA_SUCCESS)
  784. qla_printk(KERN_WARNING, ha,
  785. "Unable to update fw options (beacon off).\n");
  786. return rval;
  787. }
  788. static inline void
  789. qla24xx_flip_colors(scsi_qla_host_t *ha, uint16_t *pflags)
  790. {
  791. /* Flip all colors. */
  792. if (ha->beacon_color_state == QLA_LED_ALL_ON) {
  793. /* Turn off. */
  794. ha->beacon_color_state = 0;
  795. *pflags = 0;
  796. } else {
  797. /* Turn on. */
  798. ha->beacon_color_state = QLA_LED_ALL_ON;
  799. *pflags = GPDX_LED_YELLOW_ON | GPDX_LED_AMBER_ON;
  800. }
  801. }
  802. void
  803. qla24xx_beacon_blink(struct scsi_qla_host *ha)
  804. {
  805. uint16_t led_color = 0;
  806. uint32_t gpio_data;
  807. unsigned long flags;
  808. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  809. /* Save the Original GPIOD. */
  810. spin_lock_irqsave(&ha->hardware_lock, flags);
  811. gpio_data = RD_REG_DWORD(&reg->gpiod);
  812. /* Enable the gpio_data reg for update. */
  813. gpio_data |= GPDX_LED_UPDATE_MASK;
  814. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  815. gpio_data = RD_REG_DWORD(&reg->gpiod);
  816. /* Set the color bits. */
  817. qla24xx_flip_colors(ha, &led_color);
  818. /* Clear out any previously set LED color. */
  819. gpio_data &= ~GPDX_LED_COLOR_MASK;
  820. /* Set the new input LED color to GPIOD. */
  821. gpio_data |= led_color;
  822. /* Set the modified gpio_data values. */
  823. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  824. gpio_data = RD_REG_DWORD(&reg->gpiod);
  825. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  826. }
  827. int
  828. qla24xx_beacon_on(struct scsi_qla_host *ha)
  829. {
  830. uint32_t gpio_data;
  831. unsigned long flags;
  832. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  833. if (ha->beacon_blink_led == 0) {
  834. /* Enable firmware for update */
  835. ha->fw_options[1] |= ADD_FO1_DISABLE_GPIO_LED_CTRL;
  836. if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS)
  837. return QLA_FUNCTION_FAILED;
  838. if (qla2x00_get_fw_options(ha, ha->fw_options) !=
  839. QLA_SUCCESS) {
  840. qla_printk(KERN_WARNING, ha,
  841. "Unable to update fw options (beacon on).\n");
  842. return QLA_FUNCTION_FAILED;
  843. }
  844. spin_lock_irqsave(&ha->hardware_lock, flags);
  845. gpio_data = RD_REG_DWORD(&reg->gpiod);
  846. /* Enable the gpio_data reg for update. */
  847. gpio_data |= GPDX_LED_UPDATE_MASK;
  848. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  849. RD_REG_DWORD(&reg->gpiod);
  850. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  851. }
  852. /* So all colors blink together. */
  853. ha->beacon_color_state = 0;
  854. /* Let the per HBA timer kick off the blinking process. */
  855. ha->beacon_blink_led = 1;
  856. return QLA_SUCCESS;
  857. }
  858. int
  859. qla24xx_beacon_off(struct scsi_qla_host *ha)
  860. {
  861. uint32_t gpio_data;
  862. unsigned long flags;
  863. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  864. ha->beacon_blink_led = 0;
  865. ha->beacon_color_state = QLA_LED_ALL_ON;
  866. ha->isp_ops.beacon_blink(ha); /* Will flip to all off. */
  867. /* Give control back to firmware. */
  868. spin_lock_irqsave(&ha->hardware_lock, flags);
  869. gpio_data = RD_REG_DWORD(&reg->gpiod);
  870. /* Disable the gpio_data reg for update. */
  871. gpio_data &= ~GPDX_LED_UPDATE_MASK;
  872. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  873. RD_REG_DWORD(&reg->gpiod);
  874. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  875. ha->fw_options[1] &= ~ADD_FO1_DISABLE_GPIO_LED_CTRL;
  876. if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
  877. qla_printk(KERN_WARNING, ha,
  878. "Unable to update fw options (beacon off).\n");
  879. return QLA_FUNCTION_FAILED;
  880. }
  881. if (qla2x00_get_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
  882. qla_printk(KERN_WARNING, ha,
  883. "Unable to get fw options (beacon off).\n");
  884. return QLA_FUNCTION_FAILED;
  885. }
  886. return QLA_SUCCESS;
  887. }
  888. /*
  889. * Flash support routines
  890. */
  891. /**
  892. * qla2x00_flash_enable() - Setup flash for reading and writing.
  893. * @ha: HA context
  894. */
  895. static void
  896. qla2x00_flash_enable(scsi_qla_host_t *ha)
  897. {
  898. uint16_t data;
  899. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  900. data = RD_REG_WORD(&reg->ctrl_status);
  901. data |= CSR_FLASH_ENABLE;
  902. WRT_REG_WORD(&reg->ctrl_status, data);
  903. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  904. }
  905. /**
  906. * qla2x00_flash_disable() - Disable flash and allow RISC to run.
  907. * @ha: HA context
  908. */
  909. static void
  910. qla2x00_flash_disable(scsi_qla_host_t *ha)
  911. {
  912. uint16_t data;
  913. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  914. data = RD_REG_WORD(&reg->ctrl_status);
  915. data &= ~(CSR_FLASH_ENABLE);
  916. WRT_REG_WORD(&reg->ctrl_status, data);
  917. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  918. }
  919. /**
  920. * qla2x00_read_flash_byte() - Reads a byte from flash
  921. * @ha: HA context
  922. * @addr: Address in flash to read
  923. *
  924. * A word is read from the chip, but, only the lower byte is valid.
  925. *
  926. * Returns the byte read from flash @addr.
  927. */
  928. static uint8_t
  929. qla2x00_read_flash_byte(scsi_qla_host_t *ha, uint32_t addr)
  930. {
  931. uint16_t data;
  932. uint16_t bank_select;
  933. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  934. bank_select = RD_REG_WORD(&reg->ctrl_status);
  935. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  936. /* Specify 64K address range: */
  937. /* clear out Module Select and Flash Address bits [19:16]. */
  938. bank_select &= ~0xf8;
  939. bank_select |= addr >> 12 & 0xf0;
  940. bank_select |= CSR_FLASH_64K_BANK;
  941. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  942. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  943. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  944. data = RD_REG_WORD(&reg->flash_data);
  945. return (uint8_t)data;
  946. }
  947. /* Setup bit 16 of flash address. */
  948. if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
  949. bank_select |= CSR_FLASH_64K_BANK;
  950. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  951. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  952. } else if (((addr & BIT_16) == 0) &&
  953. (bank_select & CSR_FLASH_64K_BANK)) {
  954. bank_select &= ~(CSR_FLASH_64K_BANK);
  955. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  956. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  957. }
  958. /* Always perform IO mapped accesses to the FLASH registers. */
  959. if (ha->pio_address) {
  960. uint16_t data2;
  961. reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
  962. WRT_REG_WORD_PIO(&reg->flash_address, (uint16_t)addr);
  963. do {
  964. data = RD_REG_WORD_PIO(&reg->flash_data);
  965. barrier();
  966. cpu_relax();
  967. data2 = RD_REG_WORD_PIO(&reg->flash_data);
  968. } while (data != data2);
  969. } else {
  970. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  971. data = qla2x00_debounce_register(&reg->flash_data);
  972. }
  973. return (uint8_t)data;
  974. }
  975. /**
  976. * qla2x00_write_flash_byte() - Write a byte to flash
  977. * @ha: HA context
  978. * @addr: Address in flash to write
  979. * @data: Data to write
  980. */
  981. static void
  982. qla2x00_write_flash_byte(scsi_qla_host_t *ha, uint32_t addr, uint8_t data)
  983. {
  984. uint16_t bank_select;
  985. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  986. bank_select = RD_REG_WORD(&reg->ctrl_status);
  987. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  988. /* Specify 64K address range: */
  989. /* clear out Module Select and Flash Address bits [19:16]. */
  990. bank_select &= ~0xf8;
  991. bank_select |= addr >> 12 & 0xf0;
  992. bank_select |= CSR_FLASH_64K_BANK;
  993. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  994. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  995. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  996. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  997. WRT_REG_WORD(&reg->flash_data, (uint16_t)data);
  998. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  999. return;
  1000. }
  1001. /* Setup bit 16 of flash address. */
  1002. if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
  1003. bank_select |= CSR_FLASH_64K_BANK;
  1004. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1005. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1006. } else if (((addr & BIT_16) == 0) &&
  1007. (bank_select & CSR_FLASH_64K_BANK)) {
  1008. bank_select &= ~(CSR_FLASH_64K_BANK);
  1009. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1010. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1011. }
  1012. /* Always perform IO mapped accesses to the FLASH registers. */
  1013. if (ha->pio_address) {
  1014. reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
  1015. WRT_REG_WORD_PIO(&reg->flash_address, (uint16_t)addr);
  1016. WRT_REG_WORD_PIO(&reg->flash_data, (uint16_t)data);
  1017. } else {
  1018. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  1019. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1020. WRT_REG_WORD(&reg->flash_data, (uint16_t)data);
  1021. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1022. }
  1023. }
  1024. /**
  1025. * qla2x00_poll_flash() - Polls flash for completion.
  1026. * @ha: HA context
  1027. * @addr: Address in flash to poll
  1028. * @poll_data: Data to be polled
  1029. * @man_id: Flash manufacturer ID
  1030. * @flash_id: Flash ID
  1031. *
  1032. * This function polls the device until bit 7 of what is read matches data
  1033. * bit 7 or until data bit 5 becomes a 1. If that hapens, the flash ROM timed
  1034. * out (a fatal error). The flash book recommeds reading bit 7 again after
  1035. * reading bit 5 as a 1.
  1036. *
  1037. * Returns 0 on success, else non-zero.
  1038. */
  1039. static int
  1040. qla2x00_poll_flash(scsi_qla_host_t *ha, uint32_t addr, uint8_t poll_data,
  1041. uint8_t man_id, uint8_t flash_id)
  1042. {
  1043. int status;
  1044. uint8_t flash_data;
  1045. uint32_t cnt;
  1046. status = 1;
  1047. /* Wait for 30 seconds for command to finish. */
  1048. poll_data &= BIT_7;
  1049. for (cnt = 3000000; cnt; cnt--) {
  1050. flash_data = qla2x00_read_flash_byte(ha, addr);
  1051. if ((flash_data & BIT_7) == poll_data) {
  1052. status = 0;
  1053. break;
  1054. }
  1055. if (man_id != 0x40 && man_id != 0xda) {
  1056. if ((flash_data & BIT_5) && cnt > 2)
  1057. cnt = 2;
  1058. }
  1059. udelay(10);
  1060. barrier();
  1061. }
  1062. return status;
  1063. }
  1064. /**
  1065. * qla2x00_program_flash_address() - Programs a flash address
  1066. * @ha: HA context
  1067. * @addr: Address in flash to program
  1068. * @data: Data to be written in flash
  1069. * @man_id: Flash manufacturer ID
  1070. * @flash_id: Flash ID
  1071. *
  1072. * Returns 0 on success, else non-zero.
  1073. */
  1074. static int
  1075. qla2x00_program_flash_address(scsi_qla_host_t *ha, uint32_t addr, uint8_t data,
  1076. uint8_t man_id, uint8_t flash_id)
  1077. {
  1078. /* Write Program Command Sequence. */
  1079. if (IS_OEM_001(ha)) {
  1080. qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
  1081. qla2x00_write_flash_byte(ha, 0x555, 0x55);
  1082. qla2x00_write_flash_byte(ha, 0xaaa, 0xa0);
  1083. qla2x00_write_flash_byte(ha, addr, data);
  1084. } else {
  1085. if (man_id == 0xda && flash_id == 0xc1) {
  1086. qla2x00_write_flash_byte(ha, addr, data);
  1087. if (addr & 0x7e)
  1088. return 0;
  1089. } else {
  1090. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1091. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1092. qla2x00_write_flash_byte(ha, 0x5555, 0xa0);
  1093. qla2x00_write_flash_byte(ha, addr, data);
  1094. }
  1095. }
  1096. udelay(150);
  1097. /* Wait for write to complete. */
  1098. return qla2x00_poll_flash(ha, addr, data, man_id, flash_id);
  1099. }
  1100. /**
  1101. * qla2x00_erase_flash() - Erase the flash.
  1102. * @ha: HA context
  1103. * @man_id: Flash manufacturer ID
  1104. * @flash_id: Flash ID
  1105. *
  1106. * Returns 0 on success, else non-zero.
  1107. */
  1108. static int
  1109. qla2x00_erase_flash(scsi_qla_host_t *ha, uint8_t man_id, uint8_t flash_id)
  1110. {
  1111. /* Individual Sector Erase Command Sequence */
  1112. if (IS_OEM_001(ha)) {
  1113. qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
  1114. qla2x00_write_flash_byte(ha, 0x555, 0x55);
  1115. qla2x00_write_flash_byte(ha, 0xaaa, 0x80);
  1116. qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
  1117. qla2x00_write_flash_byte(ha, 0x555, 0x55);
  1118. qla2x00_write_flash_byte(ha, 0xaaa, 0x10);
  1119. } else {
  1120. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1121. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1122. qla2x00_write_flash_byte(ha, 0x5555, 0x80);
  1123. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1124. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1125. qla2x00_write_flash_byte(ha, 0x5555, 0x10);
  1126. }
  1127. udelay(150);
  1128. /* Wait for erase to complete. */
  1129. return qla2x00_poll_flash(ha, 0x00, 0x80, man_id, flash_id);
  1130. }
  1131. /**
  1132. * qla2x00_erase_flash_sector() - Erase a flash sector.
  1133. * @ha: HA context
  1134. * @addr: Flash sector to erase
  1135. * @sec_mask: Sector address mask
  1136. * @man_id: Flash manufacturer ID
  1137. * @flash_id: Flash ID
  1138. *
  1139. * Returns 0 on success, else non-zero.
  1140. */
  1141. static int
  1142. qla2x00_erase_flash_sector(scsi_qla_host_t *ha, uint32_t addr,
  1143. uint32_t sec_mask, uint8_t man_id, uint8_t flash_id)
  1144. {
  1145. /* Individual Sector Erase Command Sequence */
  1146. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1147. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1148. qla2x00_write_flash_byte(ha, 0x5555, 0x80);
  1149. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1150. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1151. if (man_id == 0x1f && flash_id == 0x13)
  1152. qla2x00_write_flash_byte(ha, addr & sec_mask, 0x10);
  1153. else
  1154. qla2x00_write_flash_byte(ha, addr & sec_mask, 0x30);
  1155. udelay(150);
  1156. /* Wait for erase to complete. */
  1157. return qla2x00_poll_flash(ha, addr, 0x80, man_id, flash_id);
  1158. }
  1159. /**
  1160. * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip.
  1161. * @man_id: Flash manufacturer ID
  1162. * @flash_id: Flash ID
  1163. */
  1164. static void
  1165. qla2x00_get_flash_manufacturer(scsi_qla_host_t *ha, uint8_t *man_id,
  1166. uint8_t *flash_id)
  1167. {
  1168. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1169. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1170. qla2x00_write_flash_byte(ha, 0x5555, 0x90);
  1171. *man_id = qla2x00_read_flash_byte(ha, 0x0000);
  1172. *flash_id = qla2x00_read_flash_byte(ha, 0x0001);
  1173. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1174. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1175. qla2x00_write_flash_byte(ha, 0x5555, 0xf0);
  1176. }
  1177. static inline void
  1178. qla2x00_suspend_hba(struct scsi_qla_host *ha)
  1179. {
  1180. int cnt;
  1181. unsigned long flags;
  1182. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1183. /* Suspend HBA. */
  1184. scsi_block_requests(ha->host);
  1185. ha->isp_ops.disable_intrs(ha);
  1186. set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1187. /* Pause RISC. */
  1188. spin_lock_irqsave(&ha->hardware_lock, flags);
  1189. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  1190. RD_REG_WORD(&reg->hccr);
  1191. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  1192. for (cnt = 0; cnt < 30000; cnt++) {
  1193. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
  1194. break;
  1195. udelay(100);
  1196. }
  1197. } else {
  1198. udelay(10);
  1199. }
  1200. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1201. }
  1202. static inline void
  1203. qla2x00_resume_hba(struct scsi_qla_host *ha)
  1204. {
  1205. /* Resume HBA. */
  1206. clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1207. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  1208. qla2xxx_wake_dpc(ha);
  1209. qla2x00_wait_for_hba_online(ha);
  1210. scsi_unblock_requests(ha->host);
  1211. }
  1212. uint8_t *
  1213. qla2x00_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1214. uint32_t offset, uint32_t length)
  1215. {
  1216. unsigned long flags;
  1217. uint32_t addr, midpoint;
  1218. uint8_t *data;
  1219. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1220. /* Suspend HBA. */
  1221. qla2x00_suspend_hba(ha);
  1222. /* Go with read. */
  1223. spin_lock_irqsave(&ha->hardware_lock, flags);
  1224. midpoint = ha->optrom_size / 2;
  1225. qla2x00_flash_enable(ha);
  1226. WRT_REG_WORD(&reg->nvram, 0);
  1227. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  1228. for (addr = offset, data = buf; addr < length; addr++, data++) {
  1229. if (addr == midpoint) {
  1230. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  1231. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  1232. }
  1233. *data = qla2x00_read_flash_byte(ha, addr);
  1234. }
  1235. qla2x00_flash_disable(ha);
  1236. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1237. /* Resume HBA. */
  1238. qla2x00_resume_hba(ha);
  1239. return buf;
  1240. }
  1241. int
  1242. qla2x00_write_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1243. uint32_t offset, uint32_t length)
  1244. {
  1245. int rval;
  1246. unsigned long flags;
  1247. uint8_t man_id, flash_id, sec_number, data;
  1248. uint16_t wd;
  1249. uint32_t addr, liter, sec_mask, rest_addr;
  1250. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1251. /* Suspend HBA. */
  1252. qla2x00_suspend_hba(ha);
  1253. rval = QLA_SUCCESS;
  1254. sec_number = 0;
  1255. /* Reset ISP chip. */
  1256. spin_lock_irqsave(&ha->hardware_lock, flags);
  1257. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  1258. pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
  1259. /* Go with write. */
  1260. qla2x00_flash_enable(ha);
  1261. do { /* Loop once to provide quick error exit */
  1262. /* Structure of flash memory based on manufacturer */
  1263. if (IS_OEM_001(ha)) {
  1264. /* OEM variant with special flash part. */
  1265. man_id = flash_id = 0;
  1266. rest_addr = 0xffff;
  1267. sec_mask = 0x10000;
  1268. goto update_flash;
  1269. }
  1270. qla2x00_get_flash_manufacturer(ha, &man_id, &flash_id);
  1271. switch (man_id) {
  1272. case 0x20: /* ST flash. */
  1273. if (flash_id == 0xd2 || flash_id == 0xe3) {
  1274. /*
  1275. * ST m29w008at part - 64kb sector size with
  1276. * 32kb,8kb,8kb,16kb sectors at memory address
  1277. * 0xf0000.
  1278. */
  1279. rest_addr = 0xffff;
  1280. sec_mask = 0x10000;
  1281. break;
  1282. }
  1283. /*
  1284. * ST m29w010b part - 16kb sector size
  1285. * Default to 16kb sectors
  1286. */
  1287. rest_addr = 0x3fff;
  1288. sec_mask = 0x1c000;
  1289. break;
  1290. case 0x40: /* Mostel flash. */
  1291. /* Mostel v29c51001 part - 512 byte sector size. */
  1292. rest_addr = 0x1ff;
  1293. sec_mask = 0x1fe00;
  1294. break;
  1295. case 0xbf: /* SST flash. */
  1296. /* SST39sf10 part - 4kb sector size. */
  1297. rest_addr = 0xfff;
  1298. sec_mask = 0x1f000;
  1299. break;
  1300. case 0xda: /* Winbond flash. */
  1301. /* Winbond W29EE011 part - 256 byte sector size. */
  1302. rest_addr = 0x7f;
  1303. sec_mask = 0x1ff80;
  1304. break;
  1305. case 0xc2: /* Macronix flash. */
  1306. /* 64k sector size. */
  1307. if (flash_id == 0x38 || flash_id == 0x4f) {
  1308. rest_addr = 0xffff;
  1309. sec_mask = 0x10000;
  1310. break;
  1311. }
  1312. /* Fall through... */
  1313. case 0x1f: /* Atmel flash. */
  1314. /* 512k sector size. */
  1315. if (flash_id == 0x13) {
  1316. rest_addr = 0x7fffffff;
  1317. sec_mask = 0x80000000;
  1318. break;
  1319. }
  1320. /* Fall through... */
  1321. case 0x01: /* AMD flash. */
  1322. if (flash_id == 0x38 || flash_id == 0x40 ||
  1323. flash_id == 0x4f) {
  1324. /* Am29LV081 part - 64kb sector size. */
  1325. /* Am29LV002BT part - 64kb sector size. */
  1326. rest_addr = 0xffff;
  1327. sec_mask = 0x10000;
  1328. break;
  1329. } else if (flash_id == 0x3e) {
  1330. /*
  1331. * Am29LV008b part - 64kb sector size with
  1332. * 32kb,8kb,8kb,16kb sector at memory address
  1333. * h0xf0000.
  1334. */
  1335. rest_addr = 0xffff;
  1336. sec_mask = 0x10000;
  1337. break;
  1338. } else if (flash_id == 0x20 || flash_id == 0x6e) {
  1339. /*
  1340. * Am29LV010 part or AM29f010 - 16kb sector
  1341. * size.
  1342. */
  1343. rest_addr = 0x3fff;
  1344. sec_mask = 0x1c000;
  1345. break;
  1346. } else if (flash_id == 0x6d) {
  1347. /* Am29LV001 part - 8kb sector size. */
  1348. rest_addr = 0x1fff;
  1349. sec_mask = 0x1e000;
  1350. break;
  1351. }
  1352. default:
  1353. /* Default to 16 kb sector size. */
  1354. rest_addr = 0x3fff;
  1355. sec_mask = 0x1c000;
  1356. break;
  1357. }
  1358. update_flash:
  1359. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  1360. if (qla2x00_erase_flash(ha, man_id, flash_id)) {
  1361. rval = QLA_FUNCTION_FAILED;
  1362. break;
  1363. }
  1364. }
  1365. for (addr = offset, liter = 0; liter < length; liter++,
  1366. addr++) {
  1367. data = buf[liter];
  1368. /* Are we at the beginning of a sector? */
  1369. if ((addr & rest_addr) == 0) {
  1370. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  1371. if (addr >= 0x10000UL) {
  1372. if (((addr >> 12) & 0xf0) &&
  1373. ((man_id == 0x01 &&
  1374. flash_id == 0x3e) ||
  1375. (man_id == 0x20 &&
  1376. flash_id == 0xd2))) {
  1377. sec_number++;
  1378. if (sec_number == 1) {
  1379. rest_addr =
  1380. 0x7fff;
  1381. sec_mask =
  1382. 0x18000;
  1383. } else if (
  1384. sec_number == 2 ||
  1385. sec_number == 3) {
  1386. rest_addr =
  1387. 0x1fff;
  1388. sec_mask =
  1389. 0x1e000;
  1390. } else if (
  1391. sec_number == 4) {
  1392. rest_addr =
  1393. 0x3fff;
  1394. sec_mask =
  1395. 0x1c000;
  1396. }
  1397. }
  1398. }
  1399. } else if (addr == ha->optrom_size / 2) {
  1400. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  1401. RD_REG_WORD(&reg->nvram);
  1402. }
  1403. if (flash_id == 0xda && man_id == 0xc1) {
  1404. qla2x00_write_flash_byte(ha, 0x5555,
  1405. 0xaa);
  1406. qla2x00_write_flash_byte(ha, 0x2aaa,
  1407. 0x55);
  1408. qla2x00_write_flash_byte(ha, 0x5555,
  1409. 0xa0);
  1410. } else if (!IS_QLA2322(ha) && !IS_QLA6322(ha)) {
  1411. /* Then erase it */
  1412. if (qla2x00_erase_flash_sector(ha,
  1413. addr, sec_mask, man_id,
  1414. flash_id)) {
  1415. rval = QLA_FUNCTION_FAILED;
  1416. break;
  1417. }
  1418. if (man_id == 0x01 && flash_id == 0x6d)
  1419. sec_number++;
  1420. }
  1421. }
  1422. if (man_id == 0x01 && flash_id == 0x6d) {
  1423. if (sec_number == 1 &&
  1424. addr == (rest_addr - 1)) {
  1425. rest_addr = 0x0fff;
  1426. sec_mask = 0x1f000;
  1427. } else if (sec_number == 3 && (addr & 0x7ffe)) {
  1428. rest_addr = 0x3fff;
  1429. sec_mask = 0x1c000;
  1430. }
  1431. }
  1432. if (qla2x00_program_flash_address(ha, addr, data,
  1433. man_id, flash_id)) {
  1434. rval = QLA_FUNCTION_FAILED;
  1435. break;
  1436. }
  1437. }
  1438. } while (0);
  1439. qla2x00_flash_disable(ha);
  1440. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1441. /* Resume HBA. */
  1442. qla2x00_resume_hba(ha);
  1443. return rval;
  1444. }
  1445. uint8_t *
  1446. qla24xx_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1447. uint32_t offset, uint32_t length)
  1448. {
  1449. /* Suspend HBA. */
  1450. scsi_block_requests(ha->host);
  1451. ha->isp_ops.disable_intrs(ha);
  1452. set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1453. /* Go with read. */
  1454. qla24xx_read_flash_data(ha, (uint32_t *)buf, offset >> 2, length >> 2);
  1455. /* Resume HBA. */
  1456. clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1457. ha->isp_ops.enable_intrs(ha);
  1458. scsi_unblock_requests(ha->host);
  1459. return buf;
  1460. }
  1461. int
  1462. qla24xx_write_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1463. uint32_t offset, uint32_t length)
  1464. {
  1465. int rval;
  1466. /* Suspend HBA. */
  1467. scsi_block_requests(ha->host);
  1468. ha->isp_ops.disable_intrs(ha);
  1469. set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1470. /* Go with write. */
  1471. rval = qla24xx_write_flash_data(ha, (uint32_t *)buf, offset >> 2,
  1472. length >> 2);
  1473. /* Resume HBA -- RISC reset needed. */
  1474. clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1475. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  1476. qla2xxx_wake_dpc(ha);
  1477. qla2x00_wait_for_hba_online(ha);
  1478. scsi_unblock_requests(ha->host);
  1479. return rval;
  1480. }