qla_sup.c 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2008 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 <linux/vmalloc.h>
  10. #include <asm/uaccess.h>
  11. static uint16_t qla2x00_nvram_request(scsi_qla_host_t *, uint32_t);
  12. static void qla2x00_nv_deselect(scsi_qla_host_t *);
  13. static void qla2x00_nv_write(scsi_qla_host_t *, uint16_t);
  14. /*
  15. * NVRAM support routines
  16. */
  17. /**
  18. * qla2x00_lock_nvram_access() -
  19. * @ha: HA context
  20. */
  21. static void
  22. qla2x00_lock_nvram_access(scsi_qla_host_t *ha)
  23. {
  24. uint16_t data;
  25. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  26. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) {
  27. data = RD_REG_WORD(&reg->nvram);
  28. while (data & NVR_BUSY) {
  29. udelay(100);
  30. data = RD_REG_WORD(&reg->nvram);
  31. }
  32. /* Lock resource */
  33. WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0x1);
  34. RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  35. udelay(5);
  36. data = RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  37. while ((data & BIT_0) == 0) {
  38. /* Lock failed */
  39. udelay(100);
  40. WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0x1);
  41. RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  42. udelay(5);
  43. data = RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  44. }
  45. }
  46. }
  47. /**
  48. * qla2x00_unlock_nvram_access() -
  49. * @ha: HA context
  50. */
  51. static void
  52. qla2x00_unlock_nvram_access(scsi_qla_host_t *ha)
  53. {
  54. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  55. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) {
  56. WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0);
  57. RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  58. }
  59. }
  60. /**
  61. * qla2x00_get_nvram_word() - Calculates word position in NVRAM and calls the
  62. * request routine to get the word from NVRAM.
  63. * @ha: HA context
  64. * @addr: Address in NVRAM to read
  65. *
  66. * Returns the word read from nvram @addr.
  67. */
  68. static uint16_t
  69. qla2x00_get_nvram_word(scsi_qla_host_t *ha, uint32_t addr)
  70. {
  71. uint16_t data;
  72. uint32_t nv_cmd;
  73. nv_cmd = addr << 16;
  74. nv_cmd |= NV_READ_OP;
  75. data = qla2x00_nvram_request(ha, nv_cmd);
  76. return (data);
  77. }
  78. /**
  79. * qla2x00_write_nvram_word() - Write NVRAM data.
  80. * @ha: HA context
  81. * @addr: Address in NVRAM to write
  82. * @data: word to program
  83. */
  84. static void
  85. qla2x00_write_nvram_word(scsi_qla_host_t *ha, uint32_t addr, uint16_t data)
  86. {
  87. int count;
  88. uint16_t word;
  89. uint32_t nv_cmd, wait_cnt;
  90. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  91. qla2x00_nv_write(ha, NVR_DATA_OUT);
  92. qla2x00_nv_write(ha, 0);
  93. qla2x00_nv_write(ha, 0);
  94. for (word = 0; word < 8; word++)
  95. qla2x00_nv_write(ha, NVR_DATA_OUT);
  96. qla2x00_nv_deselect(ha);
  97. /* Write data */
  98. nv_cmd = (addr << 16) | NV_WRITE_OP;
  99. nv_cmd |= data;
  100. nv_cmd <<= 5;
  101. for (count = 0; count < 27; count++) {
  102. if (nv_cmd & BIT_31)
  103. qla2x00_nv_write(ha, NVR_DATA_OUT);
  104. else
  105. qla2x00_nv_write(ha, 0);
  106. nv_cmd <<= 1;
  107. }
  108. qla2x00_nv_deselect(ha);
  109. /* Wait for NVRAM to become ready */
  110. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  111. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  112. wait_cnt = NVR_WAIT_CNT;
  113. do {
  114. if (!--wait_cnt) {
  115. DEBUG9_10(printk("%s(%ld): NVRAM didn't go ready...\n",
  116. __func__, ha->host_no));
  117. break;
  118. }
  119. NVRAM_DELAY();
  120. word = RD_REG_WORD(&reg->nvram);
  121. } while ((word & NVR_DATA_IN) == 0);
  122. qla2x00_nv_deselect(ha);
  123. /* Disable writes */
  124. qla2x00_nv_write(ha, NVR_DATA_OUT);
  125. for (count = 0; count < 10; count++)
  126. qla2x00_nv_write(ha, 0);
  127. qla2x00_nv_deselect(ha);
  128. }
  129. static int
  130. qla2x00_write_nvram_word_tmo(scsi_qla_host_t *ha, uint32_t addr, uint16_t data,
  131. uint32_t tmo)
  132. {
  133. int ret, count;
  134. uint16_t word;
  135. uint32_t nv_cmd;
  136. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  137. ret = QLA_SUCCESS;
  138. qla2x00_nv_write(ha, NVR_DATA_OUT);
  139. qla2x00_nv_write(ha, 0);
  140. qla2x00_nv_write(ha, 0);
  141. for (word = 0; word < 8; word++)
  142. qla2x00_nv_write(ha, NVR_DATA_OUT);
  143. qla2x00_nv_deselect(ha);
  144. /* Write data */
  145. nv_cmd = (addr << 16) | NV_WRITE_OP;
  146. nv_cmd |= data;
  147. nv_cmd <<= 5;
  148. for (count = 0; count < 27; count++) {
  149. if (nv_cmd & BIT_31)
  150. qla2x00_nv_write(ha, NVR_DATA_OUT);
  151. else
  152. qla2x00_nv_write(ha, 0);
  153. nv_cmd <<= 1;
  154. }
  155. qla2x00_nv_deselect(ha);
  156. /* Wait for NVRAM to become ready */
  157. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  158. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  159. do {
  160. NVRAM_DELAY();
  161. word = RD_REG_WORD(&reg->nvram);
  162. if (!--tmo) {
  163. ret = QLA_FUNCTION_FAILED;
  164. break;
  165. }
  166. } while ((word & NVR_DATA_IN) == 0);
  167. qla2x00_nv_deselect(ha);
  168. /* Disable writes */
  169. qla2x00_nv_write(ha, NVR_DATA_OUT);
  170. for (count = 0; count < 10; count++)
  171. qla2x00_nv_write(ha, 0);
  172. qla2x00_nv_deselect(ha);
  173. return ret;
  174. }
  175. /**
  176. * qla2x00_nvram_request() - Sends read command to NVRAM and gets data from
  177. * NVRAM.
  178. * @ha: HA context
  179. * @nv_cmd: NVRAM command
  180. *
  181. * Bit definitions for NVRAM command:
  182. *
  183. * Bit 26 = start bit
  184. * Bit 25, 24 = opcode
  185. * Bit 23-16 = address
  186. * Bit 15-0 = write data
  187. *
  188. * Returns the word read from nvram @addr.
  189. */
  190. static uint16_t
  191. qla2x00_nvram_request(scsi_qla_host_t *ha, uint32_t nv_cmd)
  192. {
  193. uint8_t cnt;
  194. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  195. uint16_t data = 0;
  196. uint16_t reg_data;
  197. /* Send command to NVRAM. */
  198. nv_cmd <<= 5;
  199. for (cnt = 0; cnt < 11; cnt++) {
  200. if (nv_cmd & BIT_31)
  201. qla2x00_nv_write(ha, NVR_DATA_OUT);
  202. else
  203. qla2x00_nv_write(ha, 0);
  204. nv_cmd <<= 1;
  205. }
  206. /* Read data from NVRAM. */
  207. for (cnt = 0; cnt < 16; cnt++) {
  208. WRT_REG_WORD(&reg->nvram, NVR_SELECT | NVR_CLOCK);
  209. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  210. NVRAM_DELAY();
  211. data <<= 1;
  212. reg_data = RD_REG_WORD(&reg->nvram);
  213. if (reg_data & NVR_DATA_IN)
  214. data |= BIT_0;
  215. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  216. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  217. NVRAM_DELAY();
  218. }
  219. /* Deselect chip. */
  220. WRT_REG_WORD(&reg->nvram, NVR_DESELECT);
  221. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  222. NVRAM_DELAY();
  223. return (data);
  224. }
  225. /**
  226. * qla2x00_nv_write() - Clean NVRAM operations.
  227. * @ha: HA context
  228. */
  229. static void
  230. qla2x00_nv_deselect(scsi_qla_host_t *ha)
  231. {
  232. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  233. WRT_REG_WORD(&reg->nvram, NVR_DESELECT);
  234. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  235. NVRAM_DELAY();
  236. }
  237. /**
  238. * qla2x00_nv_write() - Prepare for NVRAM read/write operation.
  239. * @ha: HA context
  240. * @data: Serial interface selector
  241. */
  242. static void
  243. qla2x00_nv_write(scsi_qla_host_t *ha, uint16_t data)
  244. {
  245. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  246. WRT_REG_WORD(&reg->nvram, data | NVR_SELECT | NVR_WRT_ENABLE);
  247. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  248. NVRAM_DELAY();
  249. WRT_REG_WORD(&reg->nvram, data | NVR_SELECT| NVR_CLOCK |
  250. NVR_WRT_ENABLE);
  251. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  252. NVRAM_DELAY();
  253. WRT_REG_WORD(&reg->nvram, data | NVR_SELECT | NVR_WRT_ENABLE);
  254. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  255. NVRAM_DELAY();
  256. }
  257. /**
  258. * qla2x00_clear_nvram_protection() -
  259. * @ha: HA context
  260. */
  261. static int
  262. qla2x00_clear_nvram_protection(scsi_qla_host_t *ha)
  263. {
  264. int ret, stat;
  265. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  266. uint32_t word, wait_cnt;
  267. uint16_t wprot, wprot_old;
  268. /* Clear NVRAM write protection. */
  269. ret = QLA_FUNCTION_FAILED;
  270. wprot_old = cpu_to_le16(qla2x00_get_nvram_word(ha, ha->nvram_base));
  271. stat = qla2x00_write_nvram_word_tmo(ha, ha->nvram_base,
  272. __constant_cpu_to_le16(0x1234), 100000);
  273. wprot = cpu_to_le16(qla2x00_get_nvram_word(ha, ha->nvram_base));
  274. if (stat != QLA_SUCCESS || wprot != 0x1234) {
  275. /* Write enable. */
  276. qla2x00_nv_write(ha, NVR_DATA_OUT);
  277. qla2x00_nv_write(ha, 0);
  278. qla2x00_nv_write(ha, 0);
  279. for (word = 0; word < 8; word++)
  280. qla2x00_nv_write(ha, NVR_DATA_OUT);
  281. qla2x00_nv_deselect(ha);
  282. /* Enable protection register. */
  283. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  284. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  285. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  286. for (word = 0; word < 8; word++)
  287. qla2x00_nv_write(ha, NVR_DATA_OUT | NVR_PR_ENABLE);
  288. qla2x00_nv_deselect(ha);
  289. /* Clear protection register (ffff is cleared). */
  290. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  291. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  292. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  293. for (word = 0; word < 8; word++)
  294. qla2x00_nv_write(ha, NVR_DATA_OUT | NVR_PR_ENABLE);
  295. qla2x00_nv_deselect(ha);
  296. /* Wait for NVRAM to become ready. */
  297. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  298. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  299. wait_cnt = NVR_WAIT_CNT;
  300. do {
  301. if (!--wait_cnt) {
  302. DEBUG9_10(printk("%s(%ld): NVRAM didn't go "
  303. "ready...\n", __func__,
  304. ha->host_no));
  305. break;
  306. }
  307. NVRAM_DELAY();
  308. word = RD_REG_WORD(&reg->nvram);
  309. } while ((word & NVR_DATA_IN) == 0);
  310. if (wait_cnt)
  311. ret = QLA_SUCCESS;
  312. } else
  313. qla2x00_write_nvram_word(ha, ha->nvram_base, wprot_old);
  314. return ret;
  315. }
  316. static void
  317. qla2x00_set_nvram_protection(scsi_qla_host_t *ha, int stat)
  318. {
  319. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  320. uint32_t word, wait_cnt;
  321. if (stat != QLA_SUCCESS)
  322. return;
  323. /* Set NVRAM write protection. */
  324. /* Write enable. */
  325. qla2x00_nv_write(ha, NVR_DATA_OUT);
  326. qla2x00_nv_write(ha, 0);
  327. qla2x00_nv_write(ha, 0);
  328. for (word = 0; word < 8; word++)
  329. qla2x00_nv_write(ha, NVR_DATA_OUT);
  330. qla2x00_nv_deselect(ha);
  331. /* Enable protection register. */
  332. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  333. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  334. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  335. for (word = 0; word < 8; word++)
  336. qla2x00_nv_write(ha, NVR_DATA_OUT | NVR_PR_ENABLE);
  337. qla2x00_nv_deselect(ha);
  338. /* Enable protection register. */
  339. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  340. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  341. qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
  342. for (word = 0; word < 8; word++)
  343. qla2x00_nv_write(ha, NVR_PR_ENABLE);
  344. qla2x00_nv_deselect(ha);
  345. /* Wait for NVRAM to become ready. */
  346. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  347. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  348. wait_cnt = NVR_WAIT_CNT;
  349. do {
  350. if (!--wait_cnt) {
  351. DEBUG9_10(printk("%s(%ld): NVRAM didn't go ready...\n",
  352. __func__, ha->host_no));
  353. break;
  354. }
  355. NVRAM_DELAY();
  356. word = RD_REG_WORD(&reg->nvram);
  357. } while ((word & NVR_DATA_IN) == 0);
  358. }
  359. /*****************************************************************************/
  360. /* Flash Manipulation Routines */
  361. /*****************************************************************************/
  362. #define OPTROM_BURST_SIZE 0x1000
  363. #define OPTROM_BURST_DWORDS (OPTROM_BURST_SIZE / 4)
  364. static inline uint32_t
  365. flash_conf_to_access_addr(uint32_t faddr)
  366. {
  367. return FARX_ACCESS_FLASH_CONF | faddr;
  368. }
  369. static inline uint32_t
  370. flash_data_to_access_addr(uint32_t faddr)
  371. {
  372. return FARX_ACCESS_FLASH_DATA | faddr;
  373. }
  374. static inline uint32_t
  375. nvram_conf_to_access_addr(uint32_t naddr)
  376. {
  377. return FARX_ACCESS_NVRAM_CONF | naddr;
  378. }
  379. static inline uint32_t
  380. nvram_data_to_access_addr(uint32_t naddr)
  381. {
  382. return FARX_ACCESS_NVRAM_DATA | naddr;
  383. }
  384. static uint32_t
  385. qla24xx_read_flash_dword(scsi_qla_host_t *ha, uint32_t addr)
  386. {
  387. int rval;
  388. uint32_t cnt, data;
  389. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  390. WRT_REG_DWORD(&reg->flash_addr, addr & ~FARX_DATA_FLAG);
  391. /* Wait for READ cycle to complete. */
  392. rval = QLA_SUCCESS;
  393. for (cnt = 3000;
  394. (RD_REG_DWORD(&reg->flash_addr) & FARX_DATA_FLAG) == 0 &&
  395. rval == QLA_SUCCESS; cnt--) {
  396. if (cnt)
  397. udelay(10);
  398. else
  399. rval = QLA_FUNCTION_TIMEOUT;
  400. cond_resched();
  401. }
  402. /* TODO: What happens if we time out? */
  403. data = 0xDEADDEAD;
  404. if (rval == QLA_SUCCESS)
  405. data = RD_REG_DWORD(&reg->flash_data);
  406. return data;
  407. }
  408. uint32_t *
  409. qla24xx_read_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
  410. uint32_t dwords)
  411. {
  412. uint32_t i;
  413. /* Dword reads to flash. */
  414. for (i = 0; i < dwords; i++, faddr++)
  415. dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
  416. flash_data_to_access_addr(faddr)));
  417. return dwptr;
  418. }
  419. static int
  420. qla24xx_write_flash_dword(scsi_qla_host_t *ha, uint32_t addr, uint32_t data)
  421. {
  422. int rval;
  423. uint32_t cnt;
  424. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  425. WRT_REG_DWORD(&reg->flash_data, data);
  426. RD_REG_DWORD(&reg->flash_data); /* PCI Posting. */
  427. WRT_REG_DWORD(&reg->flash_addr, addr | FARX_DATA_FLAG);
  428. /* Wait for Write cycle to complete. */
  429. rval = QLA_SUCCESS;
  430. for (cnt = 500000; (RD_REG_DWORD(&reg->flash_addr) & FARX_DATA_FLAG) &&
  431. rval == QLA_SUCCESS; cnt--) {
  432. if (cnt)
  433. udelay(10);
  434. else
  435. rval = QLA_FUNCTION_TIMEOUT;
  436. cond_resched();
  437. }
  438. return rval;
  439. }
  440. static void
  441. qla24xx_get_flash_manufacturer(scsi_qla_host_t *ha, uint8_t *man_id,
  442. uint8_t *flash_id)
  443. {
  444. uint32_t ids;
  445. ids = qla24xx_read_flash_dword(ha, flash_data_to_access_addr(0xd03ab));
  446. *man_id = LSB(ids);
  447. *flash_id = MSB(ids);
  448. /* Check if man_id and flash_id are valid. */
  449. if (ids != 0xDEADDEAD && (*man_id == 0 || *flash_id == 0)) {
  450. /* Read information using 0x9f opcode
  451. * Device ID, Mfg ID would be read in the format:
  452. * <Ext Dev Info><Device ID Part2><Device ID Part 1><Mfg ID>
  453. * Example: ATMEL 0x00 01 45 1F
  454. * Extract MFG and Dev ID from last two bytes.
  455. */
  456. ids = qla24xx_read_flash_dword(ha,
  457. flash_data_to_access_addr(0xd009f));
  458. *man_id = LSB(ids);
  459. *flash_id = MSB(ids);
  460. }
  461. }
  462. static int
  463. qla2xxx_find_flt_start(scsi_qla_host_t *ha, uint32_t *start)
  464. {
  465. const char *loc, *locations[] = { "DEF", "PCI" };
  466. uint32_t pcihdr, pcids;
  467. uint32_t *dcode;
  468. uint8_t *buf, *bcode, last_image;
  469. uint16_t cnt, chksum, *wptr;
  470. struct qla_flt_location *fltl;
  471. /*
  472. * FLT-location structure resides after the last PCI region.
  473. */
  474. /* Begin with sane defaults. */
  475. loc = locations[0];
  476. *start = IS_QLA24XX_TYPE(ha) ? FA_FLASH_LAYOUT_ADDR_24:
  477. FA_FLASH_LAYOUT_ADDR;
  478. /* Begin with first PCI expansion ROM header. */
  479. buf = (uint8_t *)ha->request_ring;
  480. dcode = (uint32_t *)ha->request_ring;
  481. pcihdr = 0;
  482. last_image = 1;
  483. do {
  484. /* Verify PCI expansion ROM header. */
  485. qla24xx_read_flash_data(ha, dcode, pcihdr >> 2, 0x20);
  486. bcode = buf + (pcihdr % 4);
  487. if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa)
  488. goto end;
  489. /* Locate PCI data structure. */
  490. pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]);
  491. qla24xx_read_flash_data(ha, dcode, pcids >> 2, 0x20);
  492. bcode = buf + (pcihdr % 4);
  493. /* Validate signature of PCI data structure. */
  494. if (bcode[0x0] != 'P' || bcode[0x1] != 'C' ||
  495. bcode[0x2] != 'I' || bcode[0x3] != 'R')
  496. goto end;
  497. last_image = bcode[0x15] & BIT_7;
  498. /* Locate next PCI expansion ROM. */
  499. pcihdr += ((bcode[0x11] << 8) | bcode[0x10]) * 512;
  500. } while (!last_image);
  501. /* Now verify FLT-location structure. */
  502. fltl = (struct qla_flt_location *)ha->request_ring;
  503. qla24xx_read_flash_data(ha, dcode, pcihdr >> 2,
  504. sizeof(struct qla_flt_location) >> 2);
  505. if (fltl->sig[0] != 'Q' || fltl->sig[1] != 'F' ||
  506. fltl->sig[2] != 'L' || fltl->sig[3] != 'T')
  507. goto end;
  508. wptr = (uint16_t *)ha->request_ring;
  509. cnt = sizeof(struct qla_flt_location) >> 1;
  510. for (chksum = 0; cnt; cnt--)
  511. chksum += le16_to_cpu(*wptr++);
  512. if (chksum) {
  513. qla_printk(KERN_ERR, ha,
  514. "Inconsistent FLTL detected: checksum=0x%x.\n", chksum);
  515. qla2x00_dump_buffer(buf, sizeof(struct qla_flt_location));
  516. return QLA_FUNCTION_FAILED;
  517. }
  518. /* Good data. Use specified location. */
  519. loc = locations[1];
  520. *start = le16_to_cpu(fltl->start_hi) << 16 |
  521. le16_to_cpu(fltl->start_lo);
  522. end:
  523. DEBUG2(qla_printk(KERN_DEBUG, ha, "FLTL[%s] = 0x%x.\n", loc, *start));
  524. return QLA_SUCCESS;
  525. }
  526. static void
  527. qla2xxx_get_flt_info(scsi_qla_host_t *ha, uint32_t flt_addr)
  528. {
  529. const char *loc, *locations[] = { "DEF", "FLT" };
  530. uint16_t *wptr;
  531. uint16_t cnt, chksum;
  532. uint32_t start;
  533. struct qla_flt_header *flt;
  534. struct qla_flt_region *region;
  535. ha->flt_region_flt = flt_addr;
  536. wptr = (uint16_t *)ha->request_ring;
  537. flt = (struct qla_flt_header *)ha->request_ring;
  538. region = (struct qla_flt_region *)&flt[1];
  539. ha->isp_ops->read_optrom(ha, (uint8_t *)ha->request_ring,
  540. flt_addr << 2, OPTROM_BURST_SIZE);
  541. if (*wptr == __constant_cpu_to_le16(0xffff))
  542. goto no_flash_data;
  543. if (flt->version != __constant_cpu_to_le16(1)) {
  544. DEBUG2(qla_printk(KERN_INFO, ha, "Unsupported FLT detected: "
  545. "version=0x%x length=0x%x checksum=0x%x.\n",
  546. le16_to_cpu(flt->version), le16_to_cpu(flt->length),
  547. le16_to_cpu(flt->checksum)));
  548. goto no_flash_data;
  549. }
  550. cnt = (sizeof(struct qla_flt_header) + le16_to_cpu(flt->length)) >> 1;
  551. for (chksum = 0; cnt; cnt--)
  552. chksum += le16_to_cpu(*wptr++);
  553. if (chksum) {
  554. DEBUG2(qla_printk(KERN_INFO, ha, "Inconsistent FLT detected: "
  555. "version=0x%x length=0x%x checksum=0x%x.\n",
  556. le16_to_cpu(flt->version), le16_to_cpu(flt->length),
  557. chksum));
  558. goto no_flash_data;
  559. }
  560. loc = locations[1];
  561. cnt = le16_to_cpu(flt->length) / sizeof(struct qla_flt_region);
  562. for ( ; cnt; cnt--, region++) {
  563. /* Store addresses as DWORD offsets. */
  564. start = le32_to_cpu(region->start) >> 2;
  565. DEBUG3(qla_printk(KERN_DEBUG, ha, "FLT[%02x]: start=0x%x "
  566. "end=0x%x size=0x%x.\n", le32_to_cpu(region->code), start,
  567. le32_to_cpu(region->end) >> 2, le32_to_cpu(region->size)));
  568. switch (le32_to_cpu(region->code)) {
  569. case FLT_REG_FW:
  570. ha->flt_region_fw = start;
  571. break;
  572. case FLT_REG_BOOT_CODE:
  573. ha->flt_region_boot = start;
  574. break;
  575. case FLT_REG_VPD_0:
  576. ha->flt_region_vpd_nvram = start;
  577. break;
  578. case FLT_REG_FDT:
  579. ha->flt_region_fdt = start;
  580. break;
  581. case FLT_REG_HW_EVENT_0:
  582. if (!PCI_FUNC(ha->pdev->devfn))
  583. ha->flt_region_hw_event = start;
  584. break;
  585. case FLT_REG_HW_EVENT_1:
  586. if (PCI_FUNC(ha->pdev->devfn))
  587. ha->flt_region_hw_event = start;
  588. break;
  589. case FLT_REG_NPIV_CONF_0:
  590. if (!PCI_FUNC(ha->pdev->devfn))
  591. ha->flt_region_npiv_conf = start;
  592. break;
  593. case FLT_REG_NPIV_CONF_1:
  594. if (PCI_FUNC(ha->pdev->devfn))
  595. ha->flt_region_npiv_conf = start;
  596. break;
  597. }
  598. }
  599. goto done;
  600. no_flash_data:
  601. /* Use hardcoded defaults. */
  602. loc = locations[0];
  603. ha->flt_region_fw = FA_RISC_CODE_ADDR;
  604. ha->flt_region_boot = FA_BOOT_CODE_ADDR;
  605. ha->flt_region_vpd_nvram = FA_VPD_NVRAM_ADDR;
  606. ha->flt_region_fdt = IS_QLA24XX_TYPE(ha) ? FA_FLASH_DESCR_ADDR_24:
  607. FA_FLASH_DESCR_ADDR;
  608. ha->flt_region_hw_event = !PCI_FUNC(ha->pdev->devfn) ?
  609. FA_HW_EVENT0_ADDR: FA_HW_EVENT1_ADDR;
  610. ha->flt_region_npiv_conf = !PCI_FUNC(ha->pdev->devfn) ?
  611. (IS_QLA24XX_TYPE(ha) ? FA_NPIV_CONF0_ADDR_24: FA_NPIV_CONF0_ADDR):
  612. (IS_QLA24XX_TYPE(ha) ? FA_NPIV_CONF1_ADDR_24: FA_NPIV_CONF1_ADDR);
  613. done:
  614. DEBUG2(qla_printk(KERN_DEBUG, ha, "FLT[%s]: boot=0x%x fw=0x%x "
  615. "vpd_nvram=0x%x fdt=0x%x flt=0x%x hwe=0x%x npiv=0x%x.\n", loc,
  616. ha->flt_region_boot, ha->flt_region_fw, ha->flt_region_vpd_nvram,
  617. ha->flt_region_fdt, ha->flt_region_flt, ha->flt_region_hw_event,
  618. ha->flt_region_npiv_conf));
  619. }
  620. static void
  621. qla2xxx_get_fdt_info(scsi_qla_host_t *ha)
  622. {
  623. #define FLASH_BLK_SIZE_4K 0x1000
  624. #define FLASH_BLK_SIZE_32K 0x8000
  625. #define FLASH_BLK_SIZE_64K 0x10000
  626. const char *loc, *locations[] = { "MID", "FDT" };
  627. uint16_t cnt, chksum;
  628. uint16_t *wptr;
  629. struct qla_fdt_layout *fdt;
  630. uint8_t man_id, flash_id;
  631. uint16_t mid, fid;
  632. wptr = (uint16_t *)ha->request_ring;
  633. fdt = (struct qla_fdt_layout *)ha->request_ring;
  634. ha->isp_ops->read_optrom(ha, (uint8_t *)ha->request_ring,
  635. ha->flt_region_fdt << 2, OPTROM_BURST_SIZE);
  636. if (*wptr == __constant_cpu_to_le16(0xffff))
  637. goto no_flash_data;
  638. if (fdt->sig[0] != 'Q' || fdt->sig[1] != 'L' || fdt->sig[2] != 'I' ||
  639. fdt->sig[3] != 'D')
  640. goto no_flash_data;
  641. for (cnt = 0, chksum = 0; cnt < sizeof(struct qla_fdt_layout) >> 1;
  642. cnt++)
  643. chksum += le16_to_cpu(*wptr++);
  644. if (chksum) {
  645. DEBUG2(qla_printk(KERN_INFO, ha, "Inconsistent FDT detected: "
  646. "checksum=0x%x id=%c version=0x%x.\n", chksum, fdt->sig[0],
  647. le16_to_cpu(fdt->version)));
  648. DEBUG9(qla2x00_dump_buffer((uint8_t *)fdt, sizeof(*fdt)));
  649. goto no_flash_data;
  650. }
  651. loc = locations[1];
  652. mid = le16_to_cpu(fdt->man_id);
  653. fid = le16_to_cpu(fdt->id);
  654. ha->fdt_wrt_disable = fdt->wrt_disable_bits;
  655. ha->fdt_erase_cmd = flash_conf_to_access_addr(0x0300 | fdt->erase_cmd);
  656. ha->fdt_block_size = le32_to_cpu(fdt->block_size);
  657. if (fdt->unprotect_sec_cmd) {
  658. ha->fdt_unprotect_sec_cmd = flash_conf_to_access_addr(0x0300 |
  659. fdt->unprotect_sec_cmd);
  660. ha->fdt_protect_sec_cmd = fdt->protect_sec_cmd ?
  661. flash_conf_to_access_addr(0x0300 | fdt->protect_sec_cmd):
  662. flash_conf_to_access_addr(0x0336);
  663. }
  664. goto done;
  665. no_flash_data:
  666. loc = locations[0];
  667. qla24xx_get_flash_manufacturer(ha, &man_id, &flash_id);
  668. mid = man_id;
  669. fid = flash_id;
  670. ha->fdt_wrt_disable = 0x9c;
  671. ha->fdt_erase_cmd = flash_conf_to_access_addr(0x03d8);
  672. switch (man_id) {
  673. case 0xbf: /* STT flash. */
  674. if (flash_id == 0x8e)
  675. ha->fdt_block_size = FLASH_BLK_SIZE_64K;
  676. else
  677. ha->fdt_block_size = FLASH_BLK_SIZE_32K;
  678. if (flash_id == 0x80)
  679. ha->fdt_erase_cmd = flash_conf_to_access_addr(0x0352);
  680. break;
  681. case 0x13: /* ST M25P80. */
  682. ha->fdt_block_size = FLASH_BLK_SIZE_64K;
  683. break;
  684. case 0x1f: /* Atmel 26DF081A. */
  685. ha->fdt_block_size = FLASH_BLK_SIZE_4K;
  686. ha->fdt_erase_cmd = flash_conf_to_access_addr(0x0320);
  687. ha->fdt_unprotect_sec_cmd = flash_conf_to_access_addr(0x0339);
  688. ha->fdt_protect_sec_cmd = flash_conf_to_access_addr(0x0336);
  689. break;
  690. default:
  691. /* Default to 64 kb sector size. */
  692. ha->fdt_block_size = FLASH_BLK_SIZE_64K;
  693. break;
  694. }
  695. done:
  696. DEBUG2(qla_printk(KERN_DEBUG, ha, "FDT[%s]: (0x%x/0x%x) erase=0x%x "
  697. "pro=%x upro=%x wrtd=0x%x blk=0x%x.\n", loc, mid, fid,
  698. ha->fdt_erase_cmd, ha->fdt_protect_sec_cmd,
  699. ha->fdt_unprotect_sec_cmd, ha->fdt_wrt_disable,
  700. ha->fdt_block_size));
  701. }
  702. int
  703. qla2xxx_get_flash_info(scsi_qla_host_t *ha)
  704. {
  705. int ret;
  706. uint32_t flt_addr;
  707. if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
  708. return QLA_SUCCESS;
  709. ret = qla2xxx_find_flt_start(ha, &flt_addr);
  710. if (ret != QLA_SUCCESS)
  711. return ret;
  712. qla2xxx_get_flt_info(ha, flt_addr);
  713. qla2xxx_get_fdt_info(ha);
  714. return QLA_SUCCESS;
  715. }
  716. void
  717. qla2xxx_flash_npiv_conf(scsi_qla_host_t *ha)
  718. {
  719. #define NPIV_CONFIG_SIZE (16*1024)
  720. void *data;
  721. uint16_t *wptr;
  722. uint16_t cnt, chksum;
  723. struct qla_npiv_header hdr;
  724. struct qla_npiv_entry *entry;
  725. if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
  726. return;
  727. ha->isp_ops->read_optrom(ha, (uint8_t *)&hdr,
  728. ha->flt_region_npiv_conf << 2, sizeof(struct qla_npiv_header));
  729. if (hdr.version == __constant_cpu_to_le16(0xffff))
  730. return;
  731. if (hdr.version != __constant_cpu_to_le16(1)) {
  732. DEBUG2(qla_printk(KERN_INFO, ha, "Unsupported NPIV-Config "
  733. "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
  734. le16_to_cpu(hdr.version), le16_to_cpu(hdr.entries),
  735. le16_to_cpu(hdr.checksum)));
  736. return;
  737. }
  738. data = kmalloc(NPIV_CONFIG_SIZE, GFP_KERNEL);
  739. if (!data) {
  740. DEBUG2(qla_printk(KERN_INFO, ha, "NPIV-Config: Unable to "
  741. "allocate memory.\n"));
  742. return;
  743. }
  744. ha->isp_ops->read_optrom(ha, (uint8_t *)data,
  745. ha->flt_region_npiv_conf << 2, NPIV_CONFIG_SIZE);
  746. cnt = (sizeof(struct qla_npiv_header) + le16_to_cpu(hdr.entries) *
  747. sizeof(struct qla_npiv_entry)) >> 1;
  748. for (wptr = data, chksum = 0; cnt; cnt--)
  749. chksum += le16_to_cpu(*wptr++);
  750. if (chksum) {
  751. DEBUG2(qla_printk(KERN_INFO, ha, "Inconsistent NPIV-Config "
  752. "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
  753. le16_to_cpu(hdr.version), le16_to_cpu(hdr.entries),
  754. chksum));
  755. goto done;
  756. }
  757. entry = data + sizeof(struct qla_npiv_header);
  758. cnt = le16_to_cpu(hdr.entries);
  759. for ( ; cnt; cnt--, entry++) {
  760. uint16_t flags;
  761. struct fc_vport_identifiers vid;
  762. struct fc_vport *vport;
  763. flags = le16_to_cpu(entry->flags);
  764. if (flags == 0xffff)
  765. continue;
  766. if ((flags & BIT_0) == 0)
  767. continue;
  768. memset(&vid, 0, sizeof(vid));
  769. vid.roles = FC_PORT_ROLE_FCP_INITIATOR;
  770. vid.vport_type = FC_PORTTYPE_NPIV;
  771. vid.disable = false;
  772. vid.port_name = wwn_to_u64(entry->port_name);
  773. vid.node_name = wwn_to_u64(entry->node_name);
  774. DEBUG2(qla_printk(KERN_DEBUG, ha, "NPIV[%02x]: wwpn=%llx "
  775. "wwnn=%llx vf_id=0x%x qos=0x%x.\n", cnt,
  776. (unsigned long long)vid.port_name,
  777. (unsigned long long)vid.node_name,
  778. le16_to_cpu(entry->vf_id), le16_to_cpu(entry->qos)));
  779. vport = fc_vport_create(ha->host, 0, &vid);
  780. if (!vport)
  781. qla_printk(KERN_INFO, ha, "NPIV-Config: Failed to "
  782. "create vport [%02x]: wwpn=%llx wwnn=%llx.\n", cnt,
  783. (unsigned long long)vid.port_name,
  784. (unsigned long long)vid.node_name);
  785. }
  786. done:
  787. kfree(data);
  788. }
  789. static void
  790. qla24xx_unprotect_flash(scsi_qla_host_t *ha)
  791. {
  792. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  793. /* Enable flash write. */
  794. WRT_REG_DWORD(&reg->ctrl_status,
  795. RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
  796. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  797. if (!ha->fdt_wrt_disable)
  798. return;
  799. /* Disable flash write-protection. */
  800. qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0);
  801. /* Some flash parts need an additional zero-write to clear bits.*/
  802. qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0);
  803. }
  804. static void
  805. qla24xx_protect_flash(scsi_qla_host_t *ha)
  806. {
  807. uint32_t cnt;
  808. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  809. if (!ha->fdt_wrt_disable)
  810. goto skip_wrt_protect;
  811. /* Enable flash write-protection and wait for completion. */
  812. qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101),
  813. ha->fdt_wrt_disable);
  814. for (cnt = 300; cnt &&
  815. qla24xx_read_flash_dword(ha,
  816. flash_conf_to_access_addr(0x005)) & BIT_0;
  817. cnt--) {
  818. udelay(10);
  819. }
  820. skip_wrt_protect:
  821. /* Disable flash write. */
  822. WRT_REG_DWORD(&reg->ctrl_status,
  823. RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
  824. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  825. }
  826. static int
  827. qla24xx_write_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
  828. uint32_t dwords)
  829. {
  830. int ret;
  831. uint32_t liter, miter;
  832. uint32_t sec_mask, rest_addr;
  833. uint32_t fdata, findex;
  834. dma_addr_t optrom_dma;
  835. void *optrom = NULL;
  836. uint32_t *s, *d;
  837. ret = QLA_SUCCESS;
  838. /* Prepare burst-capable write on supported ISPs. */
  839. if (IS_QLA25XX(ha) && !(faddr & 0xfff) &&
  840. dwords > OPTROM_BURST_DWORDS) {
  841. optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
  842. &optrom_dma, GFP_KERNEL);
  843. if (!optrom) {
  844. qla_printk(KERN_DEBUG, ha,
  845. "Unable to allocate memory for optrom burst write "
  846. "(%x KB).\n", OPTROM_BURST_SIZE / 1024);
  847. }
  848. }
  849. rest_addr = (ha->fdt_block_size >> 2) - 1;
  850. sec_mask = 0x80000 - (ha->fdt_block_size >> 2);
  851. qla24xx_unprotect_flash(ha);
  852. for (liter = 0; liter < dwords; liter++, faddr++, dwptr++) {
  853. findex = faddr;
  854. fdata = (findex & sec_mask) << 2;
  855. /* Are we at the beginning of a sector? */
  856. if ((findex & rest_addr) == 0) {
  857. /* Do sector unprotect. */
  858. if (ha->fdt_unprotect_sec_cmd)
  859. qla24xx_write_flash_dword(ha,
  860. ha->fdt_unprotect_sec_cmd,
  861. (fdata & 0xff00) | ((fdata << 16) &
  862. 0xff0000) | ((fdata >> 16) & 0xff));
  863. ret = qla24xx_write_flash_dword(ha, ha->fdt_erase_cmd,
  864. (fdata & 0xff00) |((fdata << 16) &
  865. 0xff0000) | ((fdata >> 16) & 0xff));
  866. if (ret != QLA_SUCCESS) {
  867. DEBUG9(printk("%s(%ld) Unable to flash "
  868. "sector: address=%x.\n", __func__,
  869. ha->host_no, faddr));
  870. break;
  871. }
  872. }
  873. /* Go with burst-write. */
  874. if (optrom && (liter + OPTROM_BURST_DWORDS) <= dwords) {
  875. /* Copy data to DMA'ble buffer. */
  876. for (miter = 0, s = optrom, d = dwptr;
  877. miter < OPTROM_BURST_DWORDS; miter++, s++, d++)
  878. *s = cpu_to_le32(*d);
  879. ret = qla2x00_load_ram(ha, optrom_dma,
  880. flash_data_to_access_addr(faddr),
  881. OPTROM_BURST_DWORDS);
  882. if (ret != QLA_SUCCESS) {
  883. qla_printk(KERN_WARNING, ha,
  884. "Unable to burst-write optrom segment "
  885. "(%x/%x/%llx).\n", ret,
  886. flash_data_to_access_addr(faddr),
  887. (unsigned long long)optrom_dma);
  888. qla_printk(KERN_WARNING, ha,
  889. "Reverting to slow-write.\n");
  890. dma_free_coherent(&ha->pdev->dev,
  891. OPTROM_BURST_SIZE, optrom, optrom_dma);
  892. optrom = NULL;
  893. } else {
  894. liter += OPTROM_BURST_DWORDS - 1;
  895. faddr += OPTROM_BURST_DWORDS - 1;
  896. dwptr += OPTROM_BURST_DWORDS - 1;
  897. continue;
  898. }
  899. }
  900. ret = qla24xx_write_flash_dword(ha,
  901. flash_data_to_access_addr(faddr), cpu_to_le32(*dwptr));
  902. if (ret != QLA_SUCCESS) {
  903. DEBUG9(printk("%s(%ld) Unable to program flash "
  904. "address=%x data=%x.\n", __func__,
  905. ha->host_no, faddr, *dwptr));
  906. break;
  907. }
  908. /* Do sector protect. */
  909. if (ha->fdt_unprotect_sec_cmd &&
  910. ((faddr & rest_addr) == rest_addr))
  911. qla24xx_write_flash_dword(ha,
  912. ha->fdt_protect_sec_cmd,
  913. (fdata & 0xff00) | ((fdata << 16) &
  914. 0xff0000) | ((fdata >> 16) & 0xff));
  915. }
  916. qla24xx_protect_flash(ha);
  917. if (optrom)
  918. dma_free_coherent(&ha->pdev->dev,
  919. OPTROM_BURST_SIZE, optrom, optrom_dma);
  920. return ret;
  921. }
  922. uint8_t *
  923. qla2x00_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  924. uint32_t bytes)
  925. {
  926. uint32_t i;
  927. uint16_t *wptr;
  928. /* Word reads to NVRAM via registers. */
  929. wptr = (uint16_t *)buf;
  930. qla2x00_lock_nvram_access(ha);
  931. for (i = 0; i < bytes >> 1; i++, naddr++)
  932. wptr[i] = cpu_to_le16(qla2x00_get_nvram_word(ha,
  933. naddr));
  934. qla2x00_unlock_nvram_access(ha);
  935. return buf;
  936. }
  937. uint8_t *
  938. qla24xx_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  939. uint32_t bytes)
  940. {
  941. uint32_t i;
  942. uint32_t *dwptr;
  943. /* Dword reads to flash. */
  944. dwptr = (uint32_t *)buf;
  945. for (i = 0; i < bytes >> 2; i++, naddr++)
  946. dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
  947. nvram_data_to_access_addr(naddr)));
  948. return buf;
  949. }
  950. int
  951. qla2x00_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  952. uint32_t bytes)
  953. {
  954. int ret, stat;
  955. uint32_t i;
  956. uint16_t *wptr;
  957. unsigned long flags;
  958. ret = QLA_SUCCESS;
  959. spin_lock_irqsave(&ha->hardware_lock, flags);
  960. qla2x00_lock_nvram_access(ha);
  961. /* Disable NVRAM write-protection. */
  962. stat = qla2x00_clear_nvram_protection(ha);
  963. wptr = (uint16_t *)buf;
  964. for (i = 0; i < bytes >> 1; i++, naddr++) {
  965. qla2x00_write_nvram_word(ha, naddr,
  966. cpu_to_le16(*wptr));
  967. wptr++;
  968. }
  969. /* Enable NVRAM write-protection. */
  970. qla2x00_set_nvram_protection(ha, stat);
  971. qla2x00_unlock_nvram_access(ha);
  972. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  973. return ret;
  974. }
  975. int
  976. qla24xx_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  977. uint32_t bytes)
  978. {
  979. int ret;
  980. uint32_t i;
  981. uint32_t *dwptr;
  982. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  983. ret = QLA_SUCCESS;
  984. /* Enable flash write. */
  985. WRT_REG_DWORD(&reg->ctrl_status,
  986. RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
  987. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  988. /* Disable NVRAM write-protection. */
  989. qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
  990. 0);
  991. qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
  992. 0);
  993. /* Dword writes to flash. */
  994. dwptr = (uint32_t *)buf;
  995. for (i = 0; i < bytes >> 2; i++, naddr++, dwptr++) {
  996. ret = qla24xx_write_flash_dword(ha,
  997. nvram_data_to_access_addr(naddr),
  998. cpu_to_le32(*dwptr));
  999. if (ret != QLA_SUCCESS) {
  1000. DEBUG9(printk("%s(%ld) Unable to program "
  1001. "nvram address=%x data=%x.\n", __func__,
  1002. ha->host_no, naddr, *dwptr));
  1003. break;
  1004. }
  1005. }
  1006. /* Enable NVRAM write-protection. */
  1007. qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
  1008. 0x8c);
  1009. /* Disable flash write. */
  1010. WRT_REG_DWORD(&reg->ctrl_status,
  1011. RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
  1012. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  1013. return ret;
  1014. }
  1015. uint8_t *
  1016. qla25xx_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  1017. uint32_t bytes)
  1018. {
  1019. uint32_t i;
  1020. uint32_t *dwptr;
  1021. /* Dword reads to flash. */
  1022. dwptr = (uint32_t *)buf;
  1023. for (i = 0; i < bytes >> 2; i++, naddr++)
  1024. dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
  1025. flash_data_to_access_addr(ha->flt_region_vpd_nvram |
  1026. naddr)));
  1027. return buf;
  1028. }
  1029. int
  1030. qla25xx_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  1031. uint32_t bytes)
  1032. {
  1033. #define RMW_BUFFER_SIZE (64 * 1024)
  1034. uint8_t *dbuf;
  1035. dbuf = vmalloc(RMW_BUFFER_SIZE);
  1036. if (!dbuf)
  1037. return QLA_MEMORY_ALLOC_FAILED;
  1038. ha->isp_ops->read_optrom(ha, dbuf, ha->flt_region_vpd_nvram << 2,
  1039. RMW_BUFFER_SIZE);
  1040. memcpy(dbuf + (naddr << 2), buf, bytes);
  1041. ha->isp_ops->write_optrom(ha, dbuf, ha->flt_region_vpd_nvram << 2,
  1042. RMW_BUFFER_SIZE);
  1043. vfree(dbuf);
  1044. return QLA_SUCCESS;
  1045. }
  1046. static inline void
  1047. qla2x00_flip_colors(scsi_qla_host_t *ha, uint16_t *pflags)
  1048. {
  1049. if (IS_QLA2322(ha)) {
  1050. /* Flip all colors. */
  1051. if (ha->beacon_color_state == QLA_LED_ALL_ON) {
  1052. /* Turn off. */
  1053. ha->beacon_color_state = 0;
  1054. *pflags = GPIO_LED_ALL_OFF;
  1055. } else {
  1056. /* Turn on. */
  1057. ha->beacon_color_state = QLA_LED_ALL_ON;
  1058. *pflags = GPIO_LED_RGA_ON;
  1059. }
  1060. } else {
  1061. /* Flip green led only. */
  1062. if (ha->beacon_color_state == QLA_LED_GRN_ON) {
  1063. /* Turn off. */
  1064. ha->beacon_color_state = 0;
  1065. *pflags = GPIO_LED_GREEN_OFF_AMBER_OFF;
  1066. } else {
  1067. /* Turn on. */
  1068. ha->beacon_color_state = QLA_LED_GRN_ON;
  1069. *pflags = GPIO_LED_GREEN_ON_AMBER_OFF;
  1070. }
  1071. }
  1072. }
  1073. #define PIO_REG(h, r) ((h)->pio_address + offsetof(struct device_reg_2xxx, r))
  1074. void
  1075. qla2x00_beacon_blink(struct scsi_qla_host *ha)
  1076. {
  1077. uint16_t gpio_enable;
  1078. uint16_t gpio_data;
  1079. uint16_t led_color = 0;
  1080. unsigned long flags;
  1081. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1082. spin_lock_irqsave(&ha->hardware_lock, flags);
  1083. /* Save the Original GPIOE. */
  1084. if (ha->pio_address) {
  1085. gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
  1086. gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
  1087. } else {
  1088. gpio_enable = RD_REG_WORD(&reg->gpioe);
  1089. gpio_data = RD_REG_WORD(&reg->gpiod);
  1090. }
  1091. /* Set the modified gpio_enable values */
  1092. gpio_enable |= GPIO_LED_MASK;
  1093. if (ha->pio_address) {
  1094. WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
  1095. } else {
  1096. WRT_REG_WORD(&reg->gpioe, gpio_enable);
  1097. RD_REG_WORD(&reg->gpioe);
  1098. }
  1099. qla2x00_flip_colors(ha, &led_color);
  1100. /* Clear out any previously set LED color. */
  1101. gpio_data &= ~GPIO_LED_MASK;
  1102. /* Set the new input LED color to GPIOD. */
  1103. gpio_data |= led_color;
  1104. /* Set the modified gpio_data values */
  1105. if (ha->pio_address) {
  1106. WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
  1107. } else {
  1108. WRT_REG_WORD(&reg->gpiod, gpio_data);
  1109. RD_REG_WORD(&reg->gpiod);
  1110. }
  1111. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1112. }
  1113. int
  1114. qla2x00_beacon_on(struct scsi_qla_host *ha)
  1115. {
  1116. uint16_t gpio_enable;
  1117. uint16_t gpio_data;
  1118. unsigned long flags;
  1119. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1120. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  1121. ha->fw_options[1] |= FO1_DISABLE_GPIO6_7;
  1122. if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
  1123. qla_printk(KERN_WARNING, ha,
  1124. "Unable to update fw options (beacon on).\n");
  1125. return QLA_FUNCTION_FAILED;
  1126. }
  1127. /* Turn off LEDs. */
  1128. spin_lock_irqsave(&ha->hardware_lock, flags);
  1129. if (ha->pio_address) {
  1130. gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
  1131. gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
  1132. } else {
  1133. gpio_enable = RD_REG_WORD(&reg->gpioe);
  1134. gpio_data = RD_REG_WORD(&reg->gpiod);
  1135. }
  1136. gpio_enable |= GPIO_LED_MASK;
  1137. /* Set the modified gpio_enable values. */
  1138. if (ha->pio_address) {
  1139. WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
  1140. } else {
  1141. WRT_REG_WORD(&reg->gpioe, gpio_enable);
  1142. RD_REG_WORD(&reg->gpioe);
  1143. }
  1144. /* Clear out previously set LED colour. */
  1145. gpio_data &= ~GPIO_LED_MASK;
  1146. if (ha->pio_address) {
  1147. WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
  1148. } else {
  1149. WRT_REG_WORD(&reg->gpiod, gpio_data);
  1150. RD_REG_WORD(&reg->gpiod);
  1151. }
  1152. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1153. /*
  1154. * Let the per HBA timer kick off the blinking process based on
  1155. * the following flags. No need to do anything else now.
  1156. */
  1157. ha->beacon_blink_led = 1;
  1158. ha->beacon_color_state = 0;
  1159. return QLA_SUCCESS;
  1160. }
  1161. int
  1162. qla2x00_beacon_off(struct scsi_qla_host *ha)
  1163. {
  1164. int rval = QLA_SUCCESS;
  1165. ha->beacon_blink_led = 0;
  1166. /* Set the on flag so when it gets flipped it will be off. */
  1167. if (IS_QLA2322(ha))
  1168. ha->beacon_color_state = QLA_LED_ALL_ON;
  1169. else
  1170. ha->beacon_color_state = QLA_LED_GRN_ON;
  1171. ha->isp_ops->beacon_blink(ha); /* This turns green LED off */
  1172. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  1173. ha->fw_options[1] &= ~FO1_DISABLE_GPIO6_7;
  1174. rval = qla2x00_set_fw_options(ha, ha->fw_options);
  1175. if (rval != QLA_SUCCESS)
  1176. qla_printk(KERN_WARNING, ha,
  1177. "Unable to update fw options (beacon off).\n");
  1178. return rval;
  1179. }
  1180. static inline void
  1181. qla24xx_flip_colors(scsi_qla_host_t *ha, uint16_t *pflags)
  1182. {
  1183. /* Flip all colors. */
  1184. if (ha->beacon_color_state == QLA_LED_ALL_ON) {
  1185. /* Turn off. */
  1186. ha->beacon_color_state = 0;
  1187. *pflags = 0;
  1188. } else {
  1189. /* Turn on. */
  1190. ha->beacon_color_state = QLA_LED_ALL_ON;
  1191. *pflags = GPDX_LED_YELLOW_ON | GPDX_LED_AMBER_ON;
  1192. }
  1193. }
  1194. void
  1195. qla24xx_beacon_blink(struct scsi_qla_host *ha)
  1196. {
  1197. uint16_t led_color = 0;
  1198. uint32_t gpio_data;
  1199. unsigned long flags;
  1200. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1201. /* Save the Original GPIOD. */
  1202. spin_lock_irqsave(&ha->hardware_lock, flags);
  1203. gpio_data = RD_REG_DWORD(&reg->gpiod);
  1204. /* Enable the gpio_data reg for update. */
  1205. gpio_data |= GPDX_LED_UPDATE_MASK;
  1206. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  1207. gpio_data = RD_REG_DWORD(&reg->gpiod);
  1208. /* Set the color bits. */
  1209. qla24xx_flip_colors(ha, &led_color);
  1210. /* Clear out any previously set LED color. */
  1211. gpio_data &= ~GPDX_LED_COLOR_MASK;
  1212. /* Set the new input LED color to GPIOD. */
  1213. gpio_data |= led_color;
  1214. /* Set the modified gpio_data values. */
  1215. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  1216. gpio_data = RD_REG_DWORD(&reg->gpiod);
  1217. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1218. }
  1219. int
  1220. qla24xx_beacon_on(struct scsi_qla_host *ha)
  1221. {
  1222. uint32_t gpio_data;
  1223. unsigned long flags;
  1224. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1225. if (ha->beacon_blink_led == 0) {
  1226. /* Enable firmware for update */
  1227. ha->fw_options[1] |= ADD_FO1_DISABLE_GPIO_LED_CTRL;
  1228. if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS)
  1229. return QLA_FUNCTION_FAILED;
  1230. if (qla2x00_get_fw_options(ha, ha->fw_options) !=
  1231. QLA_SUCCESS) {
  1232. qla_printk(KERN_WARNING, ha,
  1233. "Unable to update fw options (beacon on).\n");
  1234. return QLA_FUNCTION_FAILED;
  1235. }
  1236. spin_lock_irqsave(&ha->hardware_lock, flags);
  1237. gpio_data = RD_REG_DWORD(&reg->gpiod);
  1238. /* Enable the gpio_data reg for update. */
  1239. gpio_data |= GPDX_LED_UPDATE_MASK;
  1240. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  1241. RD_REG_DWORD(&reg->gpiod);
  1242. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1243. }
  1244. /* So all colors blink together. */
  1245. ha->beacon_color_state = 0;
  1246. /* Let the per HBA timer kick off the blinking process. */
  1247. ha->beacon_blink_led = 1;
  1248. return QLA_SUCCESS;
  1249. }
  1250. int
  1251. qla24xx_beacon_off(struct scsi_qla_host *ha)
  1252. {
  1253. uint32_t gpio_data;
  1254. unsigned long flags;
  1255. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1256. ha->beacon_blink_led = 0;
  1257. ha->beacon_color_state = QLA_LED_ALL_ON;
  1258. ha->isp_ops->beacon_blink(ha); /* Will flip to all off. */
  1259. /* Give control back to firmware. */
  1260. spin_lock_irqsave(&ha->hardware_lock, flags);
  1261. gpio_data = RD_REG_DWORD(&reg->gpiod);
  1262. /* Disable the gpio_data reg for update. */
  1263. gpio_data &= ~GPDX_LED_UPDATE_MASK;
  1264. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  1265. RD_REG_DWORD(&reg->gpiod);
  1266. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1267. ha->fw_options[1] &= ~ADD_FO1_DISABLE_GPIO_LED_CTRL;
  1268. if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
  1269. qla_printk(KERN_WARNING, ha,
  1270. "Unable to update fw options (beacon off).\n");
  1271. return QLA_FUNCTION_FAILED;
  1272. }
  1273. if (qla2x00_get_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
  1274. qla_printk(KERN_WARNING, ha,
  1275. "Unable to get fw options (beacon off).\n");
  1276. return QLA_FUNCTION_FAILED;
  1277. }
  1278. return QLA_SUCCESS;
  1279. }
  1280. /*
  1281. * Flash support routines
  1282. */
  1283. /**
  1284. * qla2x00_flash_enable() - Setup flash for reading and writing.
  1285. * @ha: HA context
  1286. */
  1287. static void
  1288. qla2x00_flash_enable(scsi_qla_host_t *ha)
  1289. {
  1290. uint16_t data;
  1291. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1292. data = RD_REG_WORD(&reg->ctrl_status);
  1293. data |= CSR_FLASH_ENABLE;
  1294. WRT_REG_WORD(&reg->ctrl_status, data);
  1295. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1296. }
  1297. /**
  1298. * qla2x00_flash_disable() - Disable flash and allow RISC to run.
  1299. * @ha: HA context
  1300. */
  1301. static void
  1302. qla2x00_flash_disable(scsi_qla_host_t *ha)
  1303. {
  1304. uint16_t data;
  1305. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1306. data = RD_REG_WORD(&reg->ctrl_status);
  1307. data &= ~(CSR_FLASH_ENABLE);
  1308. WRT_REG_WORD(&reg->ctrl_status, data);
  1309. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1310. }
  1311. /**
  1312. * qla2x00_read_flash_byte() - Reads a byte from flash
  1313. * @ha: HA context
  1314. * @addr: Address in flash to read
  1315. *
  1316. * A word is read from the chip, but, only the lower byte is valid.
  1317. *
  1318. * Returns the byte read from flash @addr.
  1319. */
  1320. static uint8_t
  1321. qla2x00_read_flash_byte(scsi_qla_host_t *ha, uint32_t addr)
  1322. {
  1323. uint16_t data;
  1324. uint16_t bank_select;
  1325. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1326. bank_select = RD_REG_WORD(&reg->ctrl_status);
  1327. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  1328. /* Specify 64K address range: */
  1329. /* clear out Module Select and Flash Address bits [19:16]. */
  1330. bank_select &= ~0xf8;
  1331. bank_select |= addr >> 12 & 0xf0;
  1332. bank_select |= CSR_FLASH_64K_BANK;
  1333. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1334. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1335. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  1336. data = RD_REG_WORD(&reg->flash_data);
  1337. return (uint8_t)data;
  1338. }
  1339. /* Setup bit 16 of flash address. */
  1340. if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
  1341. bank_select |= CSR_FLASH_64K_BANK;
  1342. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1343. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1344. } else if (((addr & BIT_16) == 0) &&
  1345. (bank_select & CSR_FLASH_64K_BANK)) {
  1346. bank_select &= ~(CSR_FLASH_64K_BANK);
  1347. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1348. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1349. }
  1350. /* Always perform IO mapped accesses to the FLASH registers. */
  1351. if (ha->pio_address) {
  1352. uint16_t data2;
  1353. WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
  1354. do {
  1355. data = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
  1356. barrier();
  1357. cpu_relax();
  1358. data2 = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
  1359. } while (data != data2);
  1360. } else {
  1361. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  1362. data = qla2x00_debounce_register(&reg->flash_data);
  1363. }
  1364. return (uint8_t)data;
  1365. }
  1366. /**
  1367. * qla2x00_write_flash_byte() - Write a byte to flash
  1368. * @ha: HA context
  1369. * @addr: Address in flash to write
  1370. * @data: Data to write
  1371. */
  1372. static void
  1373. qla2x00_write_flash_byte(scsi_qla_host_t *ha, uint32_t addr, uint8_t data)
  1374. {
  1375. uint16_t bank_select;
  1376. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1377. bank_select = RD_REG_WORD(&reg->ctrl_status);
  1378. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  1379. /* Specify 64K address range: */
  1380. /* clear out Module Select and Flash Address bits [19:16]. */
  1381. bank_select &= ~0xf8;
  1382. bank_select |= addr >> 12 & 0xf0;
  1383. bank_select |= CSR_FLASH_64K_BANK;
  1384. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1385. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1386. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  1387. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1388. WRT_REG_WORD(&reg->flash_data, (uint16_t)data);
  1389. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1390. return;
  1391. }
  1392. /* Setup bit 16 of flash address. */
  1393. if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
  1394. bank_select |= CSR_FLASH_64K_BANK;
  1395. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1396. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1397. } else if (((addr & BIT_16) == 0) &&
  1398. (bank_select & CSR_FLASH_64K_BANK)) {
  1399. bank_select &= ~(CSR_FLASH_64K_BANK);
  1400. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1401. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1402. }
  1403. /* Always perform IO mapped accesses to the FLASH registers. */
  1404. if (ha->pio_address) {
  1405. WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
  1406. WRT_REG_WORD_PIO(PIO_REG(ha, flash_data), (uint16_t)data);
  1407. } else {
  1408. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  1409. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1410. WRT_REG_WORD(&reg->flash_data, (uint16_t)data);
  1411. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1412. }
  1413. }
  1414. /**
  1415. * qla2x00_poll_flash() - Polls flash for completion.
  1416. * @ha: HA context
  1417. * @addr: Address in flash to poll
  1418. * @poll_data: Data to be polled
  1419. * @man_id: Flash manufacturer ID
  1420. * @flash_id: Flash ID
  1421. *
  1422. * This function polls the device until bit 7 of what is read matches data
  1423. * bit 7 or until data bit 5 becomes a 1. If that hapens, the flash ROM timed
  1424. * out (a fatal error). The flash book recommeds reading bit 7 again after
  1425. * reading bit 5 as a 1.
  1426. *
  1427. * Returns 0 on success, else non-zero.
  1428. */
  1429. static int
  1430. qla2x00_poll_flash(scsi_qla_host_t *ha, uint32_t addr, uint8_t poll_data,
  1431. uint8_t man_id, uint8_t flash_id)
  1432. {
  1433. int status;
  1434. uint8_t flash_data;
  1435. uint32_t cnt;
  1436. status = 1;
  1437. /* Wait for 30 seconds for command to finish. */
  1438. poll_data &= BIT_7;
  1439. for (cnt = 3000000; cnt; cnt--) {
  1440. flash_data = qla2x00_read_flash_byte(ha, addr);
  1441. if ((flash_data & BIT_7) == poll_data) {
  1442. status = 0;
  1443. break;
  1444. }
  1445. if (man_id != 0x40 && man_id != 0xda) {
  1446. if ((flash_data & BIT_5) && cnt > 2)
  1447. cnt = 2;
  1448. }
  1449. udelay(10);
  1450. barrier();
  1451. cond_resched();
  1452. }
  1453. return status;
  1454. }
  1455. /**
  1456. * qla2x00_program_flash_address() - Programs a flash address
  1457. * @ha: HA context
  1458. * @addr: Address in flash to program
  1459. * @data: Data to be written in flash
  1460. * @man_id: Flash manufacturer ID
  1461. * @flash_id: Flash ID
  1462. *
  1463. * Returns 0 on success, else non-zero.
  1464. */
  1465. static int
  1466. qla2x00_program_flash_address(scsi_qla_host_t *ha, uint32_t addr, uint8_t data,
  1467. uint8_t man_id, uint8_t flash_id)
  1468. {
  1469. /* Write Program Command Sequence. */
  1470. if (IS_OEM_001(ha)) {
  1471. qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
  1472. qla2x00_write_flash_byte(ha, 0x555, 0x55);
  1473. qla2x00_write_flash_byte(ha, 0xaaa, 0xa0);
  1474. qla2x00_write_flash_byte(ha, addr, data);
  1475. } else {
  1476. if (man_id == 0xda && flash_id == 0xc1) {
  1477. qla2x00_write_flash_byte(ha, addr, data);
  1478. if (addr & 0x7e)
  1479. return 0;
  1480. } else {
  1481. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1482. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1483. qla2x00_write_flash_byte(ha, 0x5555, 0xa0);
  1484. qla2x00_write_flash_byte(ha, addr, data);
  1485. }
  1486. }
  1487. udelay(150);
  1488. /* Wait for write to complete. */
  1489. return qla2x00_poll_flash(ha, addr, data, man_id, flash_id);
  1490. }
  1491. /**
  1492. * qla2x00_erase_flash() - Erase the flash.
  1493. * @ha: HA context
  1494. * @man_id: Flash manufacturer ID
  1495. * @flash_id: Flash ID
  1496. *
  1497. * Returns 0 on success, else non-zero.
  1498. */
  1499. static int
  1500. qla2x00_erase_flash(scsi_qla_host_t *ha, uint8_t man_id, uint8_t flash_id)
  1501. {
  1502. /* Individual Sector Erase Command Sequence */
  1503. if (IS_OEM_001(ha)) {
  1504. qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
  1505. qla2x00_write_flash_byte(ha, 0x555, 0x55);
  1506. qla2x00_write_flash_byte(ha, 0xaaa, 0x80);
  1507. qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
  1508. qla2x00_write_flash_byte(ha, 0x555, 0x55);
  1509. qla2x00_write_flash_byte(ha, 0xaaa, 0x10);
  1510. } else {
  1511. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1512. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1513. qla2x00_write_flash_byte(ha, 0x5555, 0x80);
  1514. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1515. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1516. qla2x00_write_flash_byte(ha, 0x5555, 0x10);
  1517. }
  1518. udelay(150);
  1519. /* Wait for erase to complete. */
  1520. return qla2x00_poll_flash(ha, 0x00, 0x80, man_id, flash_id);
  1521. }
  1522. /**
  1523. * qla2x00_erase_flash_sector() - Erase a flash sector.
  1524. * @ha: HA context
  1525. * @addr: Flash sector to erase
  1526. * @sec_mask: Sector address mask
  1527. * @man_id: Flash manufacturer ID
  1528. * @flash_id: Flash ID
  1529. *
  1530. * Returns 0 on success, else non-zero.
  1531. */
  1532. static int
  1533. qla2x00_erase_flash_sector(scsi_qla_host_t *ha, uint32_t addr,
  1534. uint32_t sec_mask, uint8_t man_id, uint8_t flash_id)
  1535. {
  1536. /* Individual Sector Erase Command Sequence */
  1537. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1538. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1539. qla2x00_write_flash_byte(ha, 0x5555, 0x80);
  1540. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1541. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1542. if (man_id == 0x1f && flash_id == 0x13)
  1543. qla2x00_write_flash_byte(ha, addr & sec_mask, 0x10);
  1544. else
  1545. qla2x00_write_flash_byte(ha, addr & sec_mask, 0x30);
  1546. udelay(150);
  1547. /* Wait for erase to complete. */
  1548. return qla2x00_poll_flash(ha, addr, 0x80, man_id, flash_id);
  1549. }
  1550. /**
  1551. * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip.
  1552. * @man_id: Flash manufacturer ID
  1553. * @flash_id: Flash ID
  1554. */
  1555. static void
  1556. qla2x00_get_flash_manufacturer(scsi_qla_host_t *ha, uint8_t *man_id,
  1557. uint8_t *flash_id)
  1558. {
  1559. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1560. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1561. qla2x00_write_flash_byte(ha, 0x5555, 0x90);
  1562. *man_id = qla2x00_read_flash_byte(ha, 0x0000);
  1563. *flash_id = qla2x00_read_flash_byte(ha, 0x0001);
  1564. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1565. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1566. qla2x00_write_flash_byte(ha, 0x5555, 0xf0);
  1567. }
  1568. static void
  1569. qla2x00_read_flash_data(scsi_qla_host_t *ha, uint8_t *tmp_buf, uint32_t saddr,
  1570. uint32_t length)
  1571. {
  1572. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1573. uint32_t midpoint, ilength;
  1574. uint8_t data;
  1575. midpoint = length / 2;
  1576. WRT_REG_WORD(&reg->nvram, 0);
  1577. RD_REG_WORD(&reg->nvram);
  1578. for (ilength = 0; ilength < length; saddr++, ilength++, tmp_buf++) {
  1579. if (ilength == midpoint) {
  1580. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  1581. RD_REG_WORD(&reg->nvram);
  1582. }
  1583. data = qla2x00_read_flash_byte(ha, saddr);
  1584. if (saddr % 100)
  1585. udelay(10);
  1586. *tmp_buf = data;
  1587. cond_resched();
  1588. }
  1589. }
  1590. static inline void
  1591. qla2x00_suspend_hba(struct scsi_qla_host *ha)
  1592. {
  1593. int cnt;
  1594. unsigned long flags;
  1595. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1596. /* Suspend HBA. */
  1597. scsi_block_requests(ha->host);
  1598. ha->isp_ops->disable_intrs(ha);
  1599. set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1600. /* Pause RISC. */
  1601. spin_lock_irqsave(&ha->hardware_lock, flags);
  1602. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  1603. RD_REG_WORD(&reg->hccr);
  1604. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  1605. for (cnt = 0; cnt < 30000; cnt++) {
  1606. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
  1607. break;
  1608. udelay(100);
  1609. }
  1610. } else {
  1611. udelay(10);
  1612. }
  1613. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1614. }
  1615. static inline void
  1616. qla2x00_resume_hba(struct scsi_qla_host *ha)
  1617. {
  1618. /* Resume HBA. */
  1619. clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1620. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  1621. qla2xxx_wake_dpc(ha);
  1622. qla2x00_wait_for_hba_online(ha);
  1623. scsi_unblock_requests(ha->host);
  1624. }
  1625. uint8_t *
  1626. qla2x00_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1627. uint32_t offset, uint32_t length)
  1628. {
  1629. uint32_t addr, midpoint;
  1630. uint8_t *data;
  1631. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1632. /* Suspend HBA. */
  1633. qla2x00_suspend_hba(ha);
  1634. /* Go with read. */
  1635. midpoint = ha->optrom_size / 2;
  1636. qla2x00_flash_enable(ha);
  1637. WRT_REG_WORD(&reg->nvram, 0);
  1638. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  1639. for (addr = offset, data = buf; addr < length; addr++, data++) {
  1640. if (addr == midpoint) {
  1641. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  1642. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  1643. }
  1644. *data = qla2x00_read_flash_byte(ha, addr);
  1645. }
  1646. qla2x00_flash_disable(ha);
  1647. /* Resume HBA. */
  1648. qla2x00_resume_hba(ha);
  1649. return buf;
  1650. }
  1651. int
  1652. qla2x00_write_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1653. uint32_t offset, uint32_t length)
  1654. {
  1655. int rval;
  1656. uint8_t man_id, flash_id, sec_number, data;
  1657. uint16_t wd;
  1658. uint32_t addr, liter, sec_mask, rest_addr;
  1659. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1660. /* Suspend HBA. */
  1661. qla2x00_suspend_hba(ha);
  1662. rval = QLA_SUCCESS;
  1663. sec_number = 0;
  1664. /* Reset ISP chip. */
  1665. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  1666. pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
  1667. /* Go with write. */
  1668. qla2x00_flash_enable(ha);
  1669. do { /* Loop once to provide quick error exit */
  1670. /* Structure of flash memory based on manufacturer */
  1671. if (IS_OEM_001(ha)) {
  1672. /* OEM variant with special flash part. */
  1673. man_id = flash_id = 0;
  1674. rest_addr = 0xffff;
  1675. sec_mask = 0x10000;
  1676. goto update_flash;
  1677. }
  1678. qla2x00_get_flash_manufacturer(ha, &man_id, &flash_id);
  1679. switch (man_id) {
  1680. case 0x20: /* ST flash. */
  1681. if (flash_id == 0xd2 || flash_id == 0xe3) {
  1682. /*
  1683. * ST m29w008at part - 64kb sector size with
  1684. * 32kb,8kb,8kb,16kb sectors at memory address
  1685. * 0xf0000.
  1686. */
  1687. rest_addr = 0xffff;
  1688. sec_mask = 0x10000;
  1689. break;
  1690. }
  1691. /*
  1692. * ST m29w010b part - 16kb sector size
  1693. * Default to 16kb sectors
  1694. */
  1695. rest_addr = 0x3fff;
  1696. sec_mask = 0x1c000;
  1697. break;
  1698. case 0x40: /* Mostel flash. */
  1699. /* Mostel v29c51001 part - 512 byte sector size. */
  1700. rest_addr = 0x1ff;
  1701. sec_mask = 0x1fe00;
  1702. break;
  1703. case 0xbf: /* SST flash. */
  1704. /* SST39sf10 part - 4kb sector size. */
  1705. rest_addr = 0xfff;
  1706. sec_mask = 0x1f000;
  1707. break;
  1708. case 0xda: /* Winbond flash. */
  1709. /* Winbond W29EE011 part - 256 byte sector size. */
  1710. rest_addr = 0x7f;
  1711. sec_mask = 0x1ff80;
  1712. break;
  1713. case 0xc2: /* Macronix flash. */
  1714. /* 64k sector size. */
  1715. if (flash_id == 0x38 || flash_id == 0x4f) {
  1716. rest_addr = 0xffff;
  1717. sec_mask = 0x10000;
  1718. break;
  1719. }
  1720. /* Fall through... */
  1721. case 0x1f: /* Atmel flash. */
  1722. /* 512k sector size. */
  1723. if (flash_id == 0x13) {
  1724. rest_addr = 0x7fffffff;
  1725. sec_mask = 0x80000000;
  1726. break;
  1727. }
  1728. /* Fall through... */
  1729. case 0x01: /* AMD flash. */
  1730. if (flash_id == 0x38 || flash_id == 0x40 ||
  1731. flash_id == 0x4f) {
  1732. /* Am29LV081 part - 64kb sector size. */
  1733. /* Am29LV002BT part - 64kb sector size. */
  1734. rest_addr = 0xffff;
  1735. sec_mask = 0x10000;
  1736. break;
  1737. } else if (flash_id == 0x3e) {
  1738. /*
  1739. * Am29LV008b part - 64kb sector size with
  1740. * 32kb,8kb,8kb,16kb sector at memory address
  1741. * h0xf0000.
  1742. */
  1743. rest_addr = 0xffff;
  1744. sec_mask = 0x10000;
  1745. break;
  1746. } else if (flash_id == 0x20 || flash_id == 0x6e) {
  1747. /*
  1748. * Am29LV010 part or AM29f010 - 16kb sector
  1749. * size.
  1750. */
  1751. rest_addr = 0x3fff;
  1752. sec_mask = 0x1c000;
  1753. break;
  1754. } else if (flash_id == 0x6d) {
  1755. /* Am29LV001 part - 8kb sector size. */
  1756. rest_addr = 0x1fff;
  1757. sec_mask = 0x1e000;
  1758. break;
  1759. }
  1760. default:
  1761. /* Default to 16 kb sector size. */
  1762. rest_addr = 0x3fff;
  1763. sec_mask = 0x1c000;
  1764. break;
  1765. }
  1766. update_flash:
  1767. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  1768. if (qla2x00_erase_flash(ha, man_id, flash_id)) {
  1769. rval = QLA_FUNCTION_FAILED;
  1770. break;
  1771. }
  1772. }
  1773. for (addr = offset, liter = 0; liter < length; liter++,
  1774. addr++) {
  1775. data = buf[liter];
  1776. /* Are we at the beginning of a sector? */
  1777. if ((addr & rest_addr) == 0) {
  1778. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  1779. if (addr >= 0x10000UL) {
  1780. if (((addr >> 12) & 0xf0) &&
  1781. ((man_id == 0x01 &&
  1782. flash_id == 0x3e) ||
  1783. (man_id == 0x20 &&
  1784. flash_id == 0xd2))) {
  1785. sec_number++;
  1786. if (sec_number == 1) {
  1787. rest_addr =
  1788. 0x7fff;
  1789. sec_mask =
  1790. 0x18000;
  1791. } else if (
  1792. sec_number == 2 ||
  1793. sec_number == 3) {
  1794. rest_addr =
  1795. 0x1fff;
  1796. sec_mask =
  1797. 0x1e000;
  1798. } else if (
  1799. sec_number == 4) {
  1800. rest_addr =
  1801. 0x3fff;
  1802. sec_mask =
  1803. 0x1c000;
  1804. }
  1805. }
  1806. }
  1807. } else if (addr == ha->optrom_size / 2) {
  1808. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  1809. RD_REG_WORD(&reg->nvram);
  1810. }
  1811. if (flash_id == 0xda && man_id == 0xc1) {
  1812. qla2x00_write_flash_byte(ha, 0x5555,
  1813. 0xaa);
  1814. qla2x00_write_flash_byte(ha, 0x2aaa,
  1815. 0x55);
  1816. qla2x00_write_flash_byte(ha, 0x5555,
  1817. 0xa0);
  1818. } else if (!IS_QLA2322(ha) && !IS_QLA6322(ha)) {
  1819. /* Then erase it */
  1820. if (qla2x00_erase_flash_sector(ha,
  1821. addr, sec_mask, man_id,
  1822. flash_id)) {
  1823. rval = QLA_FUNCTION_FAILED;
  1824. break;
  1825. }
  1826. if (man_id == 0x01 && flash_id == 0x6d)
  1827. sec_number++;
  1828. }
  1829. }
  1830. if (man_id == 0x01 && flash_id == 0x6d) {
  1831. if (sec_number == 1 &&
  1832. addr == (rest_addr - 1)) {
  1833. rest_addr = 0x0fff;
  1834. sec_mask = 0x1f000;
  1835. } else if (sec_number == 3 && (addr & 0x7ffe)) {
  1836. rest_addr = 0x3fff;
  1837. sec_mask = 0x1c000;
  1838. }
  1839. }
  1840. if (qla2x00_program_flash_address(ha, addr, data,
  1841. man_id, flash_id)) {
  1842. rval = QLA_FUNCTION_FAILED;
  1843. break;
  1844. }
  1845. cond_resched();
  1846. }
  1847. } while (0);
  1848. qla2x00_flash_disable(ha);
  1849. /* Resume HBA. */
  1850. qla2x00_resume_hba(ha);
  1851. return rval;
  1852. }
  1853. uint8_t *
  1854. qla24xx_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1855. uint32_t offset, uint32_t length)
  1856. {
  1857. /* Suspend HBA. */
  1858. scsi_block_requests(ha->host);
  1859. set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1860. /* Go with read. */
  1861. qla24xx_read_flash_data(ha, (uint32_t *)buf, offset >> 2, length >> 2);
  1862. /* Resume HBA. */
  1863. clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1864. scsi_unblock_requests(ha->host);
  1865. return buf;
  1866. }
  1867. int
  1868. qla24xx_write_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1869. uint32_t offset, uint32_t length)
  1870. {
  1871. int rval;
  1872. /* Suspend HBA. */
  1873. scsi_block_requests(ha->host);
  1874. set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1875. /* Go with write. */
  1876. rval = qla24xx_write_flash_data(ha, (uint32_t *)buf, offset >> 2,
  1877. length >> 2);
  1878. /* Resume HBA -- RISC reset needed. */
  1879. clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1880. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  1881. qla2xxx_wake_dpc(ha);
  1882. qla2x00_wait_for_hba_online(ha);
  1883. scsi_unblock_requests(ha->host);
  1884. return rval;
  1885. }
  1886. uint8_t *
  1887. qla25xx_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1888. uint32_t offset, uint32_t length)
  1889. {
  1890. int rval;
  1891. dma_addr_t optrom_dma;
  1892. void *optrom;
  1893. uint8_t *pbuf;
  1894. uint32_t faddr, left, burst;
  1895. if (offset & 0xfff)
  1896. goto slow_read;
  1897. if (length < OPTROM_BURST_SIZE)
  1898. goto slow_read;
  1899. optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
  1900. &optrom_dma, GFP_KERNEL);
  1901. if (!optrom) {
  1902. qla_printk(KERN_DEBUG, ha,
  1903. "Unable to allocate memory for optrom burst read "
  1904. "(%x KB).\n", OPTROM_BURST_SIZE / 1024);
  1905. goto slow_read;
  1906. }
  1907. pbuf = buf;
  1908. faddr = offset >> 2;
  1909. left = length >> 2;
  1910. burst = OPTROM_BURST_DWORDS;
  1911. while (left != 0) {
  1912. if (burst > left)
  1913. burst = left;
  1914. rval = qla2x00_dump_ram(ha, optrom_dma,
  1915. flash_data_to_access_addr(faddr), burst);
  1916. if (rval) {
  1917. qla_printk(KERN_WARNING, ha,
  1918. "Unable to burst-read optrom segment "
  1919. "(%x/%x/%llx).\n", rval,
  1920. flash_data_to_access_addr(faddr),
  1921. (unsigned long long)optrom_dma);
  1922. qla_printk(KERN_WARNING, ha,
  1923. "Reverting to slow-read.\n");
  1924. dma_free_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
  1925. optrom, optrom_dma);
  1926. goto slow_read;
  1927. }
  1928. memcpy(pbuf, optrom, burst * 4);
  1929. left -= burst;
  1930. faddr += burst;
  1931. pbuf += burst * 4;
  1932. }
  1933. dma_free_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE, optrom,
  1934. optrom_dma);
  1935. return buf;
  1936. slow_read:
  1937. return qla24xx_read_optrom_data(ha, buf, offset, length);
  1938. }
  1939. /**
  1940. * qla2x00_get_fcode_version() - Determine an FCODE image's version.
  1941. * @ha: HA context
  1942. * @pcids: Pointer to the FCODE PCI data structure
  1943. *
  1944. * The process of retrieving the FCODE version information is at best
  1945. * described as interesting.
  1946. *
  1947. * Within the first 100h bytes of the image an ASCII string is present
  1948. * which contains several pieces of information including the FCODE
  1949. * version. Unfortunately it seems the only reliable way to retrieve
  1950. * the version is by scanning for another sentinel within the string,
  1951. * the FCODE build date:
  1952. *
  1953. * ... 2.00.02 10/17/02 ...
  1954. *
  1955. * Returns QLA_SUCCESS on successful retrieval of version.
  1956. */
  1957. static void
  1958. qla2x00_get_fcode_version(scsi_qla_host_t *ha, uint32_t pcids)
  1959. {
  1960. int ret = QLA_FUNCTION_FAILED;
  1961. uint32_t istart, iend, iter, vend;
  1962. uint8_t do_next, rbyte, *vbyte;
  1963. memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
  1964. /* Skip the PCI data structure. */
  1965. istart = pcids +
  1966. ((qla2x00_read_flash_byte(ha, pcids + 0x0B) << 8) |
  1967. qla2x00_read_flash_byte(ha, pcids + 0x0A));
  1968. iend = istart + 0x100;
  1969. do {
  1970. /* Scan for the sentinel date string...eeewww. */
  1971. do_next = 0;
  1972. iter = istart;
  1973. while ((iter < iend) && !do_next) {
  1974. iter++;
  1975. if (qla2x00_read_flash_byte(ha, iter) == '/') {
  1976. if (qla2x00_read_flash_byte(ha, iter + 2) ==
  1977. '/')
  1978. do_next++;
  1979. else if (qla2x00_read_flash_byte(ha,
  1980. iter + 3) == '/')
  1981. do_next++;
  1982. }
  1983. }
  1984. if (!do_next)
  1985. break;
  1986. /* Backtrack to previous ' ' (space). */
  1987. do_next = 0;
  1988. while ((iter > istart) && !do_next) {
  1989. iter--;
  1990. if (qla2x00_read_flash_byte(ha, iter) == ' ')
  1991. do_next++;
  1992. }
  1993. if (!do_next)
  1994. break;
  1995. /*
  1996. * Mark end of version tag, and find previous ' ' (space) or
  1997. * string length (recent FCODE images -- major hack ahead!!!).
  1998. */
  1999. vend = iter - 1;
  2000. do_next = 0;
  2001. while ((iter > istart) && !do_next) {
  2002. iter--;
  2003. rbyte = qla2x00_read_flash_byte(ha, iter);
  2004. if (rbyte == ' ' || rbyte == 0xd || rbyte == 0x10)
  2005. do_next++;
  2006. }
  2007. if (!do_next)
  2008. break;
  2009. /* Mark beginning of version tag, and copy data. */
  2010. iter++;
  2011. if ((vend - iter) &&
  2012. ((vend - iter) < sizeof(ha->fcode_revision))) {
  2013. vbyte = ha->fcode_revision;
  2014. while (iter <= vend) {
  2015. *vbyte++ = qla2x00_read_flash_byte(ha, iter);
  2016. iter++;
  2017. }
  2018. ret = QLA_SUCCESS;
  2019. }
  2020. } while (0);
  2021. if (ret != QLA_SUCCESS)
  2022. memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
  2023. }
  2024. int
  2025. qla2x00_get_flash_version(scsi_qla_host_t *ha, void *mbuf)
  2026. {
  2027. int ret = QLA_SUCCESS;
  2028. uint8_t code_type, last_image;
  2029. uint32_t pcihdr, pcids;
  2030. uint8_t *dbyte;
  2031. uint16_t *dcode;
  2032. if (!ha->pio_address || !mbuf)
  2033. return QLA_FUNCTION_FAILED;
  2034. memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
  2035. memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
  2036. memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
  2037. memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
  2038. qla2x00_flash_enable(ha);
  2039. /* Begin with first PCI expansion ROM header. */
  2040. pcihdr = 0;
  2041. last_image = 1;
  2042. do {
  2043. /* Verify PCI expansion ROM header. */
  2044. if (qla2x00_read_flash_byte(ha, pcihdr) != 0x55 ||
  2045. qla2x00_read_flash_byte(ha, pcihdr + 0x01) != 0xaa) {
  2046. /* No signature */
  2047. DEBUG2(printk("scsi(%ld): No matching ROM "
  2048. "signature.\n", ha->host_no));
  2049. ret = QLA_FUNCTION_FAILED;
  2050. break;
  2051. }
  2052. /* Locate PCI data structure. */
  2053. pcids = pcihdr +
  2054. ((qla2x00_read_flash_byte(ha, pcihdr + 0x19) << 8) |
  2055. qla2x00_read_flash_byte(ha, pcihdr + 0x18));
  2056. /* Validate signature of PCI data structure. */
  2057. if (qla2x00_read_flash_byte(ha, pcids) != 'P' ||
  2058. qla2x00_read_flash_byte(ha, pcids + 0x1) != 'C' ||
  2059. qla2x00_read_flash_byte(ha, pcids + 0x2) != 'I' ||
  2060. qla2x00_read_flash_byte(ha, pcids + 0x3) != 'R') {
  2061. /* Incorrect header. */
  2062. DEBUG2(printk("%s(): PCI data struct not found "
  2063. "pcir_adr=%x.\n", __func__, pcids));
  2064. ret = QLA_FUNCTION_FAILED;
  2065. break;
  2066. }
  2067. /* Read version */
  2068. code_type = qla2x00_read_flash_byte(ha, pcids + 0x14);
  2069. switch (code_type) {
  2070. case ROM_CODE_TYPE_BIOS:
  2071. /* Intel x86, PC-AT compatible. */
  2072. ha->bios_revision[0] =
  2073. qla2x00_read_flash_byte(ha, pcids + 0x12);
  2074. ha->bios_revision[1] =
  2075. qla2x00_read_flash_byte(ha, pcids + 0x13);
  2076. DEBUG3(printk("%s(): read BIOS %d.%d.\n", __func__,
  2077. ha->bios_revision[1], ha->bios_revision[0]));
  2078. break;
  2079. case ROM_CODE_TYPE_FCODE:
  2080. /* Open Firmware standard for PCI (FCode). */
  2081. /* Eeeewww... */
  2082. qla2x00_get_fcode_version(ha, pcids);
  2083. break;
  2084. case ROM_CODE_TYPE_EFI:
  2085. /* Extensible Firmware Interface (EFI). */
  2086. ha->efi_revision[0] =
  2087. qla2x00_read_flash_byte(ha, pcids + 0x12);
  2088. ha->efi_revision[1] =
  2089. qla2x00_read_flash_byte(ha, pcids + 0x13);
  2090. DEBUG3(printk("%s(): read EFI %d.%d.\n", __func__,
  2091. ha->efi_revision[1], ha->efi_revision[0]));
  2092. break;
  2093. default:
  2094. DEBUG2(printk("%s(): Unrecognized code type %x at "
  2095. "pcids %x.\n", __func__, code_type, pcids));
  2096. break;
  2097. }
  2098. last_image = qla2x00_read_flash_byte(ha, pcids + 0x15) & BIT_7;
  2099. /* Locate next PCI expansion ROM. */
  2100. pcihdr += ((qla2x00_read_flash_byte(ha, pcids + 0x11) << 8) |
  2101. qla2x00_read_flash_byte(ha, pcids + 0x10)) * 512;
  2102. } while (!last_image);
  2103. if (IS_QLA2322(ha)) {
  2104. /* Read firmware image information. */
  2105. memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
  2106. dbyte = mbuf;
  2107. memset(dbyte, 0, 8);
  2108. dcode = (uint16_t *)dbyte;
  2109. qla2x00_read_flash_data(ha, dbyte, ha->flt_region_fw * 4 + 10,
  2110. 8);
  2111. DEBUG3(printk("%s(%ld): dumping fw ver from flash:\n",
  2112. __func__, ha->host_no));
  2113. DEBUG3(qla2x00_dump_buffer((uint8_t *)dbyte, 8));
  2114. if ((dcode[0] == 0xffff && dcode[1] == 0xffff &&
  2115. dcode[2] == 0xffff && dcode[3] == 0xffff) ||
  2116. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  2117. dcode[3] == 0)) {
  2118. DEBUG2(printk("%s(): Unrecognized fw revision at "
  2119. "%x.\n", __func__, ha->flt_region_fw * 4));
  2120. } else {
  2121. /* values are in big endian */
  2122. ha->fw_revision[0] = dbyte[0] << 16 | dbyte[1];
  2123. ha->fw_revision[1] = dbyte[2] << 16 | dbyte[3];
  2124. ha->fw_revision[2] = dbyte[4] << 16 | dbyte[5];
  2125. }
  2126. }
  2127. qla2x00_flash_disable(ha);
  2128. return ret;
  2129. }
  2130. int
  2131. qla24xx_get_flash_version(scsi_qla_host_t *ha, void *mbuf)
  2132. {
  2133. int ret = QLA_SUCCESS;
  2134. uint32_t pcihdr, pcids;
  2135. uint32_t *dcode;
  2136. uint8_t *bcode;
  2137. uint8_t code_type, last_image;
  2138. int i;
  2139. if (!mbuf)
  2140. return QLA_FUNCTION_FAILED;
  2141. memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
  2142. memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
  2143. memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
  2144. memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
  2145. dcode = mbuf;
  2146. /* Begin with first PCI expansion ROM header. */
  2147. pcihdr = ha->flt_region_boot;
  2148. last_image = 1;
  2149. do {
  2150. /* Verify PCI expansion ROM header. */
  2151. qla24xx_read_flash_data(ha, dcode, pcihdr >> 2, 0x20);
  2152. bcode = mbuf + (pcihdr % 4);
  2153. if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa) {
  2154. /* No signature */
  2155. DEBUG2(printk("scsi(%ld): No matching ROM "
  2156. "signature.\n", ha->host_no));
  2157. ret = QLA_FUNCTION_FAILED;
  2158. break;
  2159. }
  2160. /* Locate PCI data structure. */
  2161. pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]);
  2162. qla24xx_read_flash_data(ha, dcode, pcids >> 2, 0x20);
  2163. bcode = mbuf + (pcihdr % 4);
  2164. /* Validate signature of PCI data structure. */
  2165. if (bcode[0x0] != 'P' || bcode[0x1] != 'C' ||
  2166. bcode[0x2] != 'I' || bcode[0x3] != 'R') {
  2167. /* Incorrect header. */
  2168. DEBUG2(printk("%s(): PCI data struct not found "
  2169. "pcir_adr=%x.\n", __func__, pcids));
  2170. ret = QLA_FUNCTION_FAILED;
  2171. break;
  2172. }
  2173. /* Read version */
  2174. code_type = bcode[0x14];
  2175. switch (code_type) {
  2176. case ROM_CODE_TYPE_BIOS:
  2177. /* Intel x86, PC-AT compatible. */
  2178. ha->bios_revision[0] = bcode[0x12];
  2179. ha->bios_revision[1] = bcode[0x13];
  2180. DEBUG3(printk("%s(): read BIOS %d.%d.\n", __func__,
  2181. ha->bios_revision[1], ha->bios_revision[0]));
  2182. break;
  2183. case ROM_CODE_TYPE_FCODE:
  2184. /* Open Firmware standard for PCI (FCode). */
  2185. ha->fcode_revision[0] = bcode[0x12];
  2186. ha->fcode_revision[1] = bcode[0x13];
  2187. DEBUG3(printk("%s(): read FCODE %d.%d.\n", __func__,
  2188. ha->fcode_revision[1], ha->fcode_revision[0]));
  2189. break;
  2190. case ROM_CODE_TYPE_EFI:
  2191. /* Extensible Firmware Interface (EFI). */
  2192. ha->efi_revision[0] = bcode[0x12];
  2193. ha->efi_revision[1] = bcode[0x13];
  2194. DEBUG3(printk("%s(): read EFI %d.%d.\n", __func__,
  2195. ha->efi_revision[1], ha->efi_revision[0]));
  2196. break;
  2197. default:
  2198. DEBUG2(printk("%s(): Unrecognized code type %x at "
  2199. "pcids %x.\n", __func__, code_type, pcids));
  2200. break;
  2201. }
  2202. last_image = bcode[0x15] & BIT_7;
  2203. /* Locate next PCI expansion ROM. */
  2204. pcihdr += ((bcode[0x11] << 8) | bcode[0x10]) * 512;
  2205. } while (!last_image);
  2206. /* Read firmware image information. */
  2207. memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
  2208. dcode = mbuf;
  2209. qla24xx_read_flash_data(ha, dcode, ha->flt_region_fw + 4, 4);
  2210. for (i = 0; i < 4; i++)
  2211. dcode[i] = be32_to_cpu(dcode[i]);
  2212. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  2213. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  2214. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  2215. dcode[3] == 0)) {
  2216. DEBUG2(printk("%s(): Unrecognized fw version at %x.\n",
  2217. __func__, ha->flt_region_fw));
  2218. } else {
  2219. ha->fw_revision[0] = dcode[0];
  2220. ha->fw_revision[1] = dcode[1];
  2221. ha->fw_revision[2] = dcode[2];
  2222. ha->fw_revision[3] = dcode[3];
  2223. }
  2224. return ret;
  2225. }
  2226. static int
  2227. qla2xxx_is_vpd_valid(uint8_t *pos, uint8_t *end)
  2228. {
  2229. if (pos >= end || *pos != 0x82)
  2230. return 0;
  2231. pos += 3 + pos[1];
  2232. if (pos >= end || *pos != 0x90)
  2233. return 0;
  2234. pos += 3 + pos[1];
  2235. if (pos >= end || *pos != 0x78)
  2236. return 0;
  2237. return 1;
  2238. }
  2239. int
  2240. qla2xxx_get_vpd_field(scsi_qla_host_t *ha, char *key, char *str, size_t size)
  2241. {
  2242. uint8_t *pos = ha->vpd;
  2243. uint8_t *end = pos + ha->vpd_size;
  2244. int len = 0;
  2245. if (!IS_FWI2_CAPABLE(ha) || !qla2xxx_is_vpd_valid(pos, end))
  2246. return 0;
  2247. while (pos < end && *pos != 0x78) {
  2248. len = (*pos == 0x82) ? pos[1] : pos[2];
  2249. if (!strncmp(pos, key, strlen(key)))
  2250. break;
  2251. if (*pos != 0x90 && *pos != 0x91)
  2252. pos += len;
  2253. pos += 3;
  2254. }
  2255. if (pos < end - len && *pos != 0x78)
  2256. return snprintf(str, size, "%.*s", len, pos + 3);
  2257. return 0;
  2258. }
  2259. static int
  2260. qla2xxx_hw_event_store(scsi_qla_host_t *ha, uint32_t *fdata)
  2261. {
  2262. uint32_t d[2], faddr;
  2263. /* Locate first empty entry. */
  2264. for (;;) {
  2265. if (ha->hw_event_ptr >=
  2266. ha->flt_region_hw_event + FA_HW_EVENT_SIZE) {
  2267. DEBUG2(qla_printk(KERN_WARNING, ha,
  2268. "HW event -- Log Full!\n"));
  2269. return QLA_MEMORY_ALLOC_FAILED;
  2270. }
  2271. qla24xx_read_flash_data(ha, d, ha->hw_event_ptr, 2);
  2272. faddr = flash_data_to_access_addr(ha->hw_event_ptr);
  2273. ha->hw_event_ptr += FA_HW_EVENT_ENTRY_SIZE;
  2274. if (d[0] == __constant_cpu_to_le32(0xffffffff) &&
  2275. d[1] == __constant_cpu_to_le32(0xffffffff)) {
  2276. qla24xx_unprotect_flash(ha);
  2277. qla24xx_write_flash_dword(ha, faddr++,
  2278. cpu_to_le32(jiffies));
  2279. qla24xx_write_flash_dword(ha, faddr++, 0);
  2280. qla24xx_write_flash_dword(ha, faddr++, *fdata++);
  2281. qla24xx_write_flash_dword(ha, faddr++, *fdata);
  2282. qla24xx_protect_flash(ha);
  2283. break;
  2284. }
  2285. }
  2286. return QLA_SUCCESS;
  2287. }
  2288. int
  2289. qla2xxx_hw_event_log(scsi_qla_host_t *ha, uint16_t code, uint16_t d1,
  2290. uint16_t d2, uint16_t d3)
  2291. {
  2292. #define QMARK(a, b, c, d) \
  2293. cpu_to_le32(LSB(a) << 24 | LSB(b) << 16 | LSB(c) << 8 | LSB(d))
  2294. int rval;
  2295. uint32_t marker[2], fdata[4];
  2296. if (ha->flt_region_hw_event == 0)
  2297. return QLA_FUNCTION_FAILED;
  2298. DEBUG2(qla_printk(KERN_WARNING, ha,
  2299. "HW event -- code=%x, d1=%x, d2=%x, d3=%x.\n", code, d1, d2, d3));
  2300. /* If marker not already found, locate or write. */
  2301. if (!ha->flags.hw_event_marker_found) {
  2302. /* Create marker. */
  2303. marker[0] = QMARK('L', ha->fw_major_version,
  2304. ha->fw_minor_version, ha->fw_subminor_version);
  2305. marker[1] = QMARK(QLA_DRIVER_MAJOR_VER, QLA_DRIVER_MINOR_VER,
  2306. QLA_DRIVER_PATCH_VER, QLA_DRIVER_BETA_VER);
  2307. /* Locate marker. */
  2308. ha->hw_event_ptr = ha->flt_region_hw_event;
  2309. for (;;) {
  2310. qla24xx_read_flash_data(ha, fdata, ha->hw_event_ptr,
  2311. 4);
  2312. if (fdata[0] == __constant_cpu_to_le32(0xffffffff) &&
  2313. fdata[1] == __constant_cpu_to_le32(0xffffffff))
  2314. break;
  2315. ha->hw_event_ptr += FA_HW_EVENT_ENTRY_SIZE;
  2316. if (ha->hw_event_ptr >=
  2317. ha->flt_region_hw_event + FA_HW_EVENT_SIZE) {
  2318. DEBUG2(qla_printk(KERN_WARNING, ha,
  2319. "HW event -- Log Full!\n"));
  2320. return QLA_MEMORY_ALLOC_FAILED;
  2321. }
  2322. if (fdata[2] == marker[0] && fdata[3] == marker[1]) {
  2323. ha->flags.hw_event_marker_found = 1;
  2324. break;
  2325. }
  2326. }
  2327. /* No marker, write it. */
  2328. if (!ha->flags.hw_event_marker_found) {
  2329. rval = qla2xxx_hw_event_store(ha, marker);
  2330. if (rval != QLA_SUCCESS) {
  2331. DEBUG2(qla_printk(KERN_WARNING, ha,
  2332. "HW event -- Failed marker write=%x.!\n",
  2333. rval));
  2334. return rval;
  2335. }
  2336. ha->flags.hw_event_marker_found = 1;
  2337. }
  2338. }
  2339. /* Store error. */
  2340. fdata[0] = cpu_to_le32(code << 16 | d1);
  2341. fdata[1] = cpu_to_le32(d2 << 16 | d3);
  2342. rval = qla2xxx_hw_event_store(ha, fdata);
  2343. if (rval != QLA_SUCCESS) {
  2344. DEBUG2(qla_printk(KERN_WARNING, ha,
  2345. "HW event -- Failed error write=%x.!\n",
  2346. rval));
  2347. }
  2348. return rval;
  2349. }