qla_sup.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730
  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_32K 0x8000
  624. #define FLASH_BLK_SIZE_64K 0x10000
  625. const char *loc, *locations[] = { "MID", "FDT" };
  626. uint16_t cnt, chksum;
  627. uint16_t *wptr;
  628. struct qla_fdt_layout *fdt;
  629. uint8_t man_id, flash_id;
  630. uint16_t mid, fid;
  631. wptr = (uint16_t *)ha->request_ring;
  632. fdt = (struct qla_fdt_layout *)ha->request_ring;
  633. ha->isp_ops->read_optrom(ha, (uint8_t *)ha->request_ring,
  634. ha->flt_region_fdt << 2, OPTROM_BURST_SIZE);
  635. if (*wptr == __constant_cpu_to_le16(0xffff))
  636. goto no_flash_data;
  637. if (fdt->sig[0] != 'Q' || fdt->sig[1] != 'L' || fdt->sig[2] != 'I' ||
  638. fdt->sig[3] != 'D')
  639. goto no_flash_data;
  640. for (cnt = 0, chksum = 0; cnt < sizeof(struct qla_fdt_layout) >> 1;
  641. cnt++)
  642. chksum += le16_to_cpu(*wptr++);
  643. if (chksum) {
  644. DEBUG2(qla_printk(KERN_INFO, ha, "Inconsistent FDT detected: "
  645. "checksum=0x%x id=%c version=0x%x.\n", chksum, fdt->sig[0],
  646. le16_to_cpu(fdt->version)));
  647. DEBUG9(qla2x00_dump_buffer((uint8_t *)fdt, sizeof(*fdt)));
  648. goto no_flash_data;
  649. }
  650. loc = locations[1];
  651. mid = le16_to_cpu(fdt->man_id);
  652. fid = le16_to_cpu(fdt->id);
  653. ha->fdt_odd_index = mid == 0x1f;
  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_odd_index = 1;
  686. ha->fdt_block_size = FLASH_BLK_SIZE_64K;
  687. ha->fdt_erase_cmd = flash_conf_to_access_addr(0x0320);
  688. ha->fdt_unprotect_sec_cmd = flash_conf_to_access_addr(0x0339);
  689. ha->fdt_protect_sec_cmd = flash_conf_to_access_addr(0x0336);
  690. break;
  691. default:
  692. /* Default to 64 kb sector size. */
  693. ha->fdt_block_size = FLASH_BLK_SIZE_64K;
  694. break;
  695. }
  696. done:
  697. DEBUG2(qla_printk(KERN_DEBUG, ha, "FDT[%s]: (0x%x/0x%x) erase=0x%x "
  698. "pro=%x upro=%x idx=%d wrtd=0x%x blk=0x%x.\n", loc, mid, fid,
  699. ha->fdt_erase_cmd, ha->fdt_protect_sec_cmd,
  700. ha->fdt_unprotect_sec_cmd, ha->fdt_odd_index, ha->fdt_wrt_disable,
  701. ha->fdt_block_size));
  702. }
  703. int
  704. qla2xxx_get_flash_info(scsi_qla_host_t *ha)
  705. {
  706. int ret;
  707. uint32_t flt_addr;
  708. if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
  709. return QLA_SUCCESS;
  710. ret = qla2xxx_find_flt_start(ha, &flt_addr);
  711. if (ret != QLA_SUCCESS)
  712. return ret;
  713. qla2xxx_get_flt_info(ha, flt_addr);
  714. qla2xxx_get_fdt_info(ha);
  715. return QLA_SUCCESS;
  716. }
  717. void
  718. qla2xxx_flash_npiv_conf(scsi_qla_host_t *ha)
  719. {
  720. #define NPIV_CONFIG_SIZE (16*1024)
  721. void *data;
  722. uint16_t *wptr;
  723. uint16_t cnt, chksum;
  724. struct qla_npiv_header hdr;
  725. struct qla_npiv_entry *entry;
  726. if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
  727. return;
  728. ha->isp_ops->read_optrom(ha, (uint8_t *)&hdr,
  729. ha->flt_region_npiv_conf << 2, sizeof(struct qla_npiv_header));
  730. if (hdr.version == __constant_cpu_to_le16(0xffff))
  731. return;
  732. if (hdr.version != __constant_cpu_to_le16(1)) {
  733. DEBUG2(qla_printk(KERN_INFO, ha, "Unsupported NPIV-Config "
  734. "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
  735. le16_to_cpu(hdr.version), le16_to_cpu(hdr.entries),
  736. le16_to_cpu(hdr.checksum)));
  737. return;
  738. }
  739. data = kmalloc(NPIV_CONFIG_SIZE, GFP_KERNEL);
  740. if (!data) {
  741. DEBUG2(qla_printk(KERN_INFO, ha, "NPIV-Config: Unable to "
  742. "allocate memory.\n"));
  743. return;
  744. }
  745. ha->isp_ops->read_optrom(ha, (uint8_t *)data,
  746. ha->flt_region_npiv_conf << 2, NPIV_CONFIG_SIZE);
  747. cnt = (sizeof(struct qla_npiv_header) + le16_to_cpu(hdr.entries) *
  748. sizeof(struct qla_npiv_entry)) >> 1;
  749. for (wptr = data, chksum = 0; cnt; cnt--)
  750. chksum += le16_to_cpu(*wptr++);
  751. if (chksum) {
  752. DEBUG2(qla_printk(KERN_INFO, ha, "Inconsistent NPIV-Config "
  753. "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
  754. le16_to_cpu(hdr.version), le16_to_cpu(hdr.entries),
  755. chksum));
  756. goto done;
  757. }
  758. entry = data + sizeof(struct qla_npiv_header);
  759. cnt = le16_to_cpu(hdr.entries);
  760. for ( ; cnt; cnt--, entry++) {
  761. uint16_t flags;
  762. struct fc_vport_identifiers vid;
  763. struct fc_vport *vport;
  764. flags = le16_to_cpu(entry->flags);
  765. if (flags == 0xffff)
  766. continue;
  767. if ((flags & BIT_0) == 0)
  768. continue;
  769. memset(&vid, 0, sizeof(vid));
  770. vid.roles = FC_PORT_ROLE_FCP_INITIATOR;
  771. vid.vport_type = FC_PORTTYPE_NPIV;
  772. vid.disable = false;
  773. vid.port_name = wwn_to_u64(entry->port_name);
  774. vid.node_name = wwn_to_u64(entry->node_name);
  775. DEBUG2(qla_printk(KERN_DEBUG, ha, "NPIV[%02x]: wwpn=%llx "
  776. "wwnn=%llx vf_id=0x%x qos=0x%x.\n", cnt,
  777. (unsigned long long)vid.port_name,
  778. (unsigned long long)vid.node_name,
  779. le16_to_cpu(entry->vf_id), le16_to_cpu(entry->qos)));
  780. vport = fc_vport_create(ha->host, 0, &vid);
  781. if (!vport)
  782. qla_printk(KERN_INFO, ha, "NPIV-Config: Failed to "
  783. "create vport [%02x]: wwpn=%llx wwnn=%llx.\n", cnt,
  784. (unsigned long long)vid.port_name,
  785. (unsigned long long)vid.node_name);
  786. }
  787. done:
  788. kfree(data);
  789. }
  790. static void
  791. qla24xx_unprotect_flash(scsi_qla_host_t *ha)
  792. {
  793. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  794. /* Enable flash write. */
  795. WRT_REG_DWORD(&reg->ctrl_status,
  796. RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
  797. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  798. if (!ha->fdt_wrt_disable)
  799. return;
  800. /* Disable flash write-protection. */
  801. qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0);
  802. /* Some flash parts need an additional zero-write to clear bits.*/
  803. qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101), 0);
  804. }
  805. static void
  806. qla24xx_protect_flash(scsi_qla_host_t *ha)
  807. {
  808. uint32_t cnt;
  809. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  810. if (!ha->fdt_wrt_disable)
  811. goto skip_wrt_protect;
  812. /* Enable flash write-protection and wait for completion. */
  813. qla24xx_write_flash_dword(ha, flash_conf_to_access_addr(0x101),
  814. ha->fdt_wrt_disable);
  815. for (cnt = 300; cnt &&
  816. qla24xx_read_flash_dword(ha,
  817. flash_conf_to_access_addr(0x005)) & BIT_0;
  818. cnt--) {
  819. udelay(10);
  820. }
  821. skip_wrt_protect:
  822. /* Disable flash write. */
  823. WRT_REG_DWORD(&reg->ctrl_status,
  824. RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
  825. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  826. }
  827. static int
  828. qla24xx_write_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
  829. uint32_t dwords)
  830. {
  831. int ret;
  832. uint32_t liter, miter;
  833. uint32_t sec_mask, rest_addr;
  834. uint32_t fdata, findex;
  835. dma_addr_t optrom_dma;
  836. void *optrom = NULL;
  837. uint32_t *s, *d;
  838. ret = QLA_SUCCESS;
  839. /* Prepare burst-capable write on supported ISPs. */
  840. if (IS_QLA25XX(ha) && !(faddr & 0xfff) &&
  841. dwords > OPTROM_BURST_DWORDS) {
  842. optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
  843. &optrom_dma, GFP_KERNEL);
  844. if (!optrom) {
  845. qla_printk(KERN_DEBUG, ha,
  846. "Unable to allocate memory for optrom burst write "
  847. "(%x KB).\n", OPTROM_BURST_SIZE / 1024);
  848. }
  849. }
  850. rest_addr = (ha->fdt_block_size >> 2) - 1;
  851. sec_mask = 0x80000 - (ha->fdt_block_size >> 2);
  852. qla24xx_unprotect_flash(ha);
  853. for (liter = 0; liter < dwords; liter++, faddr++, dwptr++) {
  854. if (ha->fdt_odd_index) {
  855. findex = faddr << 2;
  856. fdata = findex & sec_mask;
  857. } else {
  858. findex = faddr;
  859. fdata = (findex & sec_mask) << 2;
  860. }
  861. /* Are we at the beginning of a sector? */
  862. if ((findex & rest_addr) == 0) {
  863. /* Do sector unprotect. */
  864. if (ha->fdt_unprotect_sec_cmd)
  865. qla24xx_write_flash_dword(ha,
  866. ha->fdt_unprotect_sec_cmd,
  867. (fdata & 0xff00) | ((fdata << 16) &
  868. 0xff0000) | ((fdata >> 16) & 0xff));
  869. ret = qla24xx_write_flash_dword(ha, ha->fdt_erase_cmd,
  870. (fdata & 0xff00) |((fdata << 16) &
  871. 0xff0000) | ((fdata >> 16) & 0xff));
  872. if (ret != QLA_SUCCESS) {
  873. DEBUG9(printk("%s(%ld) Unable to flash "
  874. "sector: address=%x.\n", __func__,
  875. ha->host_no, faddr));
  876. break;
  877. }
  878. }
  879. /* Go with burst-write. */
  880. if (optrom && (liter + OPTROM_BURST_DWORDS) <= dwords) {
  881. /* Copy data to DMA'ble buffer. */
  882. for (miter = 0, s = optrom, d = dwptr;
  883. miter < OPTROM_BURST_DWORDS; miter++, s++, d++)
  884. *s = cpu_to_le32(*d);
  885. ret = qla2x00_load_ram(ha, optrom_dma,
  886. flash_data_to_access_addr(faddr),
  887. OPTROM_BURST_DWORDS);
  888. if (ret != QLA_SUCCESS) {
  889. qla_printk(KERN_WARNING, ha,
  890. "Unable to burst-write optrom segment "
  891. "(%x/%x/%llx).\n", ret,
  892. flash_data_to_access_addr(faddr),
  893. (unsigned long long)optrom_dma);
  894. qla_printk(KERN_WARNING, ha,
  895. "Reverting to slow-write.\n");
  896. dma_free_coherent(&ha->pdev->dev,
  897. OPTROM_BURST_SIZE, optrom, optrom_dma);
  898. optrom = NULL;
  899. } else {
  900. liter += OPTROM_BURST_DWORDS - 1;
  901. faddr += OPTROM_BURST_DWORDS - 1;
  902. dwptr += OPTROM_BURST_DWORDS - 1;
  903. continue;
  904. }
  905. }
  906. ret = qla24xx_write_flash_dword(ha,
  907. flash_data_to_access_addr(faddr), cpu_to_le32(*dwptr));
  908. if (ret != QLA_SUCCESS) {
  909. DEBUG9(printk("%s(%ld) Unable to program flash "
  910. "address=%x data=%x.\n", __func__,
  911. ha->host_no, faddr, *dwptr));
  912. break;
  913. }
  914. /* Do sector protect. */
  915. if (ha->fdt_unprotect_sec_cmd &&
  916. ((faddr & rest_addr) == rest_addr))
  917. qla24xx_write_flash_dword(ha,
  918. ha->fdt_protect_sec_cmd,
  919. (fdata & 0xff00) | ((fdata << 16) &
  920. 0xff0000) | ((fdata >> 16) & 0xff));
  921. }
  922. qla24xx_protect_flash(ha);
  923. if (optrom)
  924. dma_free_coherent(&ha->pdev->dev,
  925. OPTROM_BURST_SIZE, optrom, optrom_dma);
  926. return ret;
  927. }
  928. uint8_t *
  929. qla2x00_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  930. uint32_t bytes)
  931. {
  932. uint32_t i;
  933. uint16_t *wptr;
  934. /* Word reads to NVRAM via registers. */
  935. wptr = (uint16_t *)buf;
  936. qla2x00_lock_nvram_access(ha);
  937. for (i = 0; i < bytes >> 1; i++, naddr++)
  938. wptr[i] = cpu_to_le16(qla2x00_get_nvram_word(ha,
  939. naddr));
  940. qla2x00_unlock_nvram_access(ha);
  941. return buf;
  942. }
  943. uint8_t *
  944. qla24xx_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  945. uint32_t bytes)
  946. {
  947. uint32_t i;
  948. uint32_t *dwptr;
  949. /* Dword reads to flash. */
  950. dwptr = (uint32_t *)buf;
  951. for (i = 0; i < bytes >> 2; i++, naddr++)
  952. dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
  953. nvram_data_to_access_addr(naddr)));
  954. return buf;
  955. }
  956. int
  957. qla2x00_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  958. uint32_t bytes)
  959. {
  960. int ret, stat;
  961. uint32_t i;
  962. uint16_t *wptr;
  963. unsigned long flags;
  964. ret = QLA_SUCCESS;
  965. spin_lock_irqsave(&ha->hardware_lock, flags);
  966. qla2x00_lock_nvram_access(ha);
  967. /* Disable NVRAM write-protection. */
  968. stat = qla2x00_clear_nvram_protection(ha);
  969. wptr = (uint16_t *)buf;
  970. for (i = 0; i < bytes >> 1; i++, naddr++) {
  971. qla2x00_write_nvram_word(ha, naddr,
  972. cpu_to_le16(*wptr));
  973. wptr++;
  974. }
  975. /* Enable NVRAM write-protection. */
  976. qla2x00_set_nvram_protection(ha, stat);
  977. qla2x00_unlock_nvram_access(ha);
  978. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  979. return ret;
  980. }
  981. int
  982. qla24xx_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  983. uint32_t bytes)
  984. {
  985. int ret;
  986. uint32_t i;
  987. uint32_t *dwptr;
  988. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  989. ret = QLA_SUCCESS;
  990. /* Enable flash write. */
  991. WRT_REG_DWORD(&reg->ctrl_status,
  992. RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
  993. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  994. /* Disable NVRAM write-protection. */
  995. qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
  996. 0);
  997. qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
  998. 0);
  999. /* Dword writes to flash. */
  1000. dwptr = (uint32_t *)buf;
  1001. for (i = 0; i < bytes >> 2; i++, naddr++, dwptr++) {
  1002. ret = qla24xx_write_flash_dword(ha,
  1003. nvram_data_to_access_addr(naddr),
  1004. cpu_to_le32(*dwptr));
  1005. if (ret != QLA_SUCCESS) {
  1006. DEBUG9(printk("%s(%ld) Unable to program "
  1007. "nvram address=%x data=%x.\n", __func__,
  1008. ha->host_no, naddr, *dwptr));
  1009. break;
  1010. }
  1011. }
  1012. /* Enable NVRAM write-protection. */
  1013. qla24xx_write_flash_dword(ha, nvram_conf_to_access_addr(0x101),
  1014. 0x8c);
  1015. /* Disable flash write. */
  1016. WRT_REG_DWORD(&reg->ctrl_status,
  1017. RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
  1018. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  1019. return ret;
  1020. }
  1021. uint8_t *
  1022. qla25xx_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  1023. uint32_t bytes)
  1024. {
  1025. uint32_t i;
  1026. uint32_t *dwptr;
  1027. /* Dword reads to flash. */
  1028. dwptr = (uint32_t *)buf;
  1029. for (i = 0; i < bytes >> 2; i++, naddr++)
  1030. dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
  1031. flash_data_to_access_addr(ha->flt_region_vpd_nvram |
  1032. naddr)));
  1033. return buf;
  1034. }
  1035. int
  1036. qla25xx_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
  1037. uint32_t bytes)
  1038. {
  1039. #define RMW_BUFFER_SIZE (64 * 1024)
  1040. uint8_t *dbuf;
  1041. dbuf = vmalloc(RMW_BUFFER_SIZE);
  1042. if (!dbuf)
  1043. return QLA_MEMORY_ALLOC_FAILED;
  1044. ha->isp_ops->read_optrom(ha, dbuf, ha->flt_region_vpd_nvram << 2,
  1045. RMW_BUFFER_SIZE);
  1046. memcpy(dbuf + (naddr << 2), buf, bytes);
  1047. ha->isp_ops->write_optrom(ha, dbuf, ha->flt_region_vpd_nvram << 2,
  1048. RMW_BUFFER_SIZE);
  1049. vfree(dbuf);
  1050. return QLA_SUCCESS;
  1051. }
  1052. static inline void
  1053. qla2x00_flip_colors(scsi_qla_host_t *ha, uint16_t *pflags)
  1054. {
  1055. if (IS_QLA2322(ha)) {
  1056. /* Flip all colors. */
  1057. if (ha->beacon_color_state == QLA_LED_ALL_ON) {
  1058. /* Turn off. */
  1059. ha->beacon_color_state = 0;
  1060. *pflags = GPIO_LED_ALL_OFF;
  1061. } else {
  1062. /* Turn on. */
  1063. ha->beacon_color_state = QLA_LED_ALL_ON;
  1064. *pflags = GPIO_LED_RGA_ON;
  1065. }
  1066. } else {
  1067. /* Flip green led only. */
  1068. if (ha->beacon_color_state == QLA_LED_GRN_ON) {
  1069. /* Turn off. */
  1070. ha->beacon_color_state = 0;
  1071. *pflags = GPIO_LED_GREEN_OFF_AMBER_OFF;
  1072. } else {
  1073. /* Turn on. */
  1074. ha->beacon_color_state = QLA_LED_GRN_ON;
  1075. *pflags = GPIO_LED_GREEN_ON_AMBER_OFF;
  1076. }
  1077. }
  1078. }
  1079. #define PIO_REG(h, r) ((h)->pio_address + offsetof(struct device_reg_2xxx, r))
  1080. void
  1081. qla2x00_beacon_blink(struct scsi_qla_host *ha)
  1082. {
  1083. uint16_t gpio_enable;
  1084. uint16_t gpio_data;
  1085. uint16_t led_color = 0;
  1086. unsigned long flags;
  1087. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1088. spin_lock_irqsave(&ha->hardware_lock, flags);
  1089. /* Save the Original GPIOE. */
  1090. if (ha->pio_address) {
  1091. gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
  1092. gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
  1093. } else {
  1094. gpio_enable = RD_REG_WORD(&reg->gpioe);
  1095. gpio_data = RD_REG_WORD(&reg->gpiod);
  1096. }
  1097. /* Set the modified gpio_enable values */
  1098. gpio_enable |= GPIO_LED_MASK;
  1099. if (ha->pio_address) {
  1100. WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
  1101. } else {
  1102. WRT_REG_WORD(&reg->gpioe, gpio_enable);
  1103. RD_REG_WORD(&reg->gpioe);
  1104. }
  1105. qla2x00_flip_colors(ha, &led_color);
  1106. /* Clear out any previously set LED color. */
  1107. gpio_data &= ~GPIO_LED_MASK;
  1108. /* Set the new input LED color to GPIOD. */
  1109. gpio_data |= led_color;
  1110. /* Set the modified gpio_data values */
  1111. if (ha->pio_address) {
  1112. WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
  1113. } else {
  1114. WRT_REG_WORD(&reg->gpiod, gpio_data);
  1115. RD_REG_WORD(&reg->gpiod);
  1116. }
  1117. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1118. }
  1119. int
  1120. qla2x00_beacon_on(struct scsi_qla_host *ha)
  1121. {
  1122. uint16_t gpio_enable;
  1123. uint16_t gpio_data;
  1124. unsigned long flags;
  1125. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1126. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  1127. ha->fw_options[1] |= FO1_DISABLE_GPIO6_7;
  1128. if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
  1129. qla_printk(KERN_WARNING, ha,
  1130. "Unable to update fw options (beacon on).\n");
  1131. return QLA_FUNCTION_FAILED;
  1132. }
  1133. /* Turn off LEDs. */
  1134. spin_lock_irqsave(&ha->hardware_lock, flags);
  1135. if (ha->pio_address) {
  1136. gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
  1137. gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
  1138. } else {
  1139. gpio_enable = RD_REG_WORD(&reg->gpioe);
  1140. gpio_data = RD_REG_WORD(&reg->gpiod);
  1141. }
  1142. gpio_enable |= GPIO_LED_MASK;
  1143. /* Set the modified gpio_enable values. */
  1144. if (ha->pio_address) {
  1145. WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
  1146. } else {
  1147. WRT_REG_WORD(&reg->gpioe, gpio_enable);
  1148. RD_REG_WORD(&reg->gpioe);
  1149. }
  1150. /* Clear out previously set LED colour. */
  1151. gpio_data &= ~GPIO_LED_MASK;
  1152. if (ha->pio_address) {
  1153. WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
  1154. } else {
  1155. WRT_REG_WORD(&reg->gpiod, gpio_data);
  1156. RD_REG_WORD(&reg->gpiod);
  1157. }
  1158. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1159. /*
  1160. * Let the per HBA timer kick off the blinking process based on
  1161. * the following flags. No need to do anything else now.
  1162. */
  1163. ha->beacon_blink_led = 1;
  1164. ha->beacon_color_state = 0;
  1165. return QLA_SUCCESS;
  1166. }
  1167. int
  1168. qla2x00_beacon_off(struct scsi_qla_host *ha)
  1169. {
  1170. int rval = QLA_SUCCESS;
  1171. ha->beacon_blink_led = 0;
  1172. /* Set the on flag so when it gets flipped it will be off. */
  1173. if (IS_QLA2322(ha))
  1174. ha->beacon_color_state = QLA_LED_ALL_ON;
  1175. else
  1176. ha->beacon_color_state = QLA_LED_GRN_ON;
  1177. ha->isp_ops->beacon_blink(ha); /* This turns green LED off */
  1178. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  1179. ha->fw_options[1] &= ~FO1_DISABLE_GPIO6_7;
  1180. rval = qla2x00_set_fw_options(ha, ha->fw_options);
  1181. if (rval != QLA_SUCCESS)
  1182. qla_printk(KERN_WARNING, ha,
  1183. "Unable to update fw options (beacon off).\n");
  1184. return rval;
  1185. }
  1186. static inline void
  1187. qla24xx_flip_colors(scsi_qla_host_t *ha, uint16_t *pflags)
  1188. {
  1189. /* Flip all colors. */
  1190. if (ha->beacon_color_state == QLA_LED_ALL_ON) {
  1191. /* Turn off. */
  1192. ha->beacon_color_state = 0;
  1193. *pflags = 0;
  1194. } else {
  1195. /* Turn on. */
  1196. ha->beacon_color_state = QLA_LED_ALL_ON;
  1197. *pflags = GPDX_LED_YELLOW_ON | GPDX_LED_AMBER_ON;
  1198. }
  1199. }
  1200. void
  1201. qla24xx_beacon_blink(struct scsi_qla_host *ha)
  1202. {
  1203. uint16_t led_color = 0;
  1204. uint32_t gpio_data;
  1205. unsigned long flags;
  1206. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1207. /* Save the Original GPIOD. */
  1208. spin_lock_irqsave(&ha->hardware_lock, flags);
  1209. gpio_data = RD_REG_DWORD(&reg->gpiod);
  1210. /* Enable the gpio_data reg for update. */
  1211. gpio_data |= GPDX_LED_UPDATE_MASK;
  1212. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  1213. gpio_data = RD_REG_DWORD(&reg->gpiod);
  1214. /* Set the color bits. */
  1215. qla24xx_flip_colors(ha, &led_color);
  1216. /* Clear out any previously set LED color. */
  1217. gpio_data &= ~GPDX_LED_COLOR_MASK;
  1218. /* Set the new input LED color to GPIOD. */
  1219. gpio_data |= led_color;
  1220. /* Set the modified gpio_data values. */
  1221. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  1222. gpio_data = RD_REG_DWORD(&reg->gpiod);
  1223. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1224. }
  1225. int
  1226. qla24xx_beacon_on(struct scsi_qla_host *ha)
  1227. {
  1228. uint32_t gpio_data;
  1229. unsigned long flags;
  1230. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1231. if (ha->beacon_blink_led == 0) {
  1232. /* Enable firmware for update */
  1233. ha->fw_options[1] |= ADD_FO1_DISABLE_GPIO_LED_CTRL;
  1234. if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS)
  1235. return QLA_FUNCTION_FAILED;
  1236. if (qla2x00_get_fw_options(ha, ha->fw_options) !=
  1237. QLA_SUCCESS) {
  1238. qla_printk(KERN_WARNING, ha,
  1239. "Unable to update fw options (beacon on).\n");
  1240. return QLA_FUNCTION_FAILED;
  1241. }
  1242. spin_lock_irqsave(&ha->hardware_lock, flags);
  1243. gpio_data = RD_REG_DWORD(&reg->gpiod);
  1244. /* Enable the gpio_data reg for update. */
  1245. gpio_data |= GPDX_LED_UPDATE_MASK;
  1246. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  1247. RD_REG_DWORD(&reg->gpiod);
  1248. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1249. }
  1250. /* So all colors blink together. */
  1251. ha->beacon_color_state = 0;
  1252. /* Let the per HBA timer kick off the blinking process. */
  1253. ha->beacon_blink_led = 1;
  1254. return QLA_SUCCESS;
  1255. }
  1256. int
  1257. qla24xx_beacon_off(struct scsi_qla_host *ha)
  1258. {
  1259. uint32_t gpio_data;
  1260. unsigned long flags;
  1261. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1262. ha->beacon_blink_led = 0;
  1263. ha->beacon_color_state = QLA_LED_ALL_ON;
  1264. ha->isp_ops->beacon_blink(ha); /* Will flip to all off. */
  1265. /* Give control back to firmware. */
  1266. spin_lock_irqsave(&ha->hardware_lock, flags);
  1267. gpio_data = RD_REG_DWORD(&reg->gpiod);
  1268. /* Disable the gpio_data reg for update. */
  1269. gpio_data &= ~GPDX_LED_UPDATE_MASK;
  1270. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  1271. RD_REG_DWORD(&reg->gpiod);
  1272. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1273. ha->fw_options[1] &= ~ADD_FO1_DISABLE_GPIO_LED_CTRL;
  1274. if (qla2x00_set_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
  1275. qla_printk(KERN_WARNING, ha,
  1276. "Unable to update fw options (beacon off).\n");
  1277. return QLA_FUNCTION_FAILED;
  1278. }
  1279. if (qla2x00_get_fw_options(ha, ha->fw_options) != QLA_SUCCESS) {
  1280. qla_printk(KERN_WARNING, ha,
  1281. "Unable to get fw options (beacon off).\n");
  1282. return QLA_FUNCTION_FAILED;
  1283. }
  1284. return QLA_SUCCESS;
  1285. }
  1286. /*
  1287. * Flash support routines
  1288. */
  1289. /**
  1290. * qla2x00_flash_enable() - Setup flash for reading and writing.
  1291. * @ha: HA context
  1292. */
  1293. static void
  1294. qla2x00_flash_enable(scsi_qla_host_t *ha)
  1295. {
  1296. uint16_t data;
  1297. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1298. data = RD_REG_WORD(&reg->ctrl_status);
  1299. data |= CSR_FLASH_ENABLE;
  1300. WRT_REG_WORD(&reg->ctrl_status, data);
  1301. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1302. }
  1303. /**
  1304. * qla2x00_flash_disable() - Disable flash and allow RISC to run.
  1305. * @ha: HA context
  1306. */
  1307. static void
  1308. qla2x00_flash_disable(scsi_qla_host_t *ha)
  1309. {
  1310. uint16_t data;
  1311. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1312. data = RD_REG_WORD(&reg->ctrl_status);
  1313. data &= ~(CSR_FLASH_ENABLE);
  1314. WRT_REG_WORD(&reg->ctrl_status, data);
  1315. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1316. }
  1317. /**
  1318. * qla2x00_read_flash_byte() - Reads a byte from flash
  1319. * @ha: HA context
  1320. * @addr: Address in flash to read
  1321. *
  1322. * A word is read from the chip, but, only the lower byte is valid.
  1323. *
  1324. * Returns the byte read from flash @addr.
  1325. */
  1326. static uint8_t
  1327. qla2x00_read_flash_byte(scsi_qla_host_t *ha, uint32_t addr)
  1328. {
  1329. uint16_t data;
  1330. uint16_t bank_select;
  1331. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1332. bank_select = RD_REG_WORD(&reg->ctrl_status);
  1333. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  1334. /* Specify 64K address range: */
  1335. /* clear out Module Select and Flash Address bits [19:16]. */
  1336. bank_select &= ~0xf8;
  1337. bank_select |= addr >> 12 & 0xf0;
  1338. bank_select |= CSR_FLASH_64K_BANK;
  1339. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1340. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1341. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  1342. data = RD_REG_WORD(&reg->flash_data);
  1343. return (uint8_t)data;
  1344. }
  1345. /* Setup bit 16 of flash address. */
  1346. if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
  1347. bank_select |= CSR_FLASH_64K_BANK;
  1348. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1349. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1350. } else if (((addr & BIT_16) == 0) &&
  1351. (bank_select & CSR_FLASH_64K_BANK)) {
  1352. bank_select &= ~(CSR_FLASH_64K_BANK);
  1353. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1354. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1355. }
  1356. /* Always perform IO mapped accesses to the FLASH registers. */
  1357. if (ha->pio_address) {
  1358. uint16_t data2;
  1359. WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
  1360. do {
  1361. data = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
  1362. barrier();
  1363. cpu_relax();
  1364. data2 = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
  1365. } while (data != data2);
  1366. } else {
  1367. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  1368. data = qla2x00_debounce_register(&reg->flash_data);
  1369. }
  1370. return (uint8_t)data;
  1371. }
  1372. /**
  1373. * qla2x00_write_flash_byte() - Write a byte to flash
  1374. * @ha: HA context
  1375. * @addr: Address in flash to write
  1376. * @data: Data to write
  1377. */
  1378. static void
  1379. qla2x00_write_flash_byte(scsi_qla_host_t *ha, uint32_t addr, uint8_t data)
  1380. {
  1381. uint16_t bank_select;
  1382. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1383. bank_select = RD_REG_WORD(&reg->ctrl_status);
  1384. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  1385. /* Specify 64K address range: */
  1386. /* clear out Module Select and Flash Address bits [19:16]. */
  1387. bank_select &= ~0xf8;
  1388. bank_select |= addr >> 12 & 0xf0;
  1389. bank_select |= CSR_FLASH_64K_BANK;
  1390. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1391. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1392. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  1393. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1394. WRT_REG_WORD(&reg->flash_data, (uint16_t)data);
  1395. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1396. return;
  1397. }
  1398. /* Setup bit 16 of flash address. */
  1399. if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
  1400. bank_select |= CSR_FLASH_64K_BANK;
  1401. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1402. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1403. } else if (((addr & BIT_16) == 0) &&
  1404. (bank_select & CSR_FLASH_64K_BANK)) {
  1405. bank_select &= ~(CSR_FLASH_64K_BANK);
  1406. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1407. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1408. }
  1409. /* Always perform IO mapped accesses to the FLASH registers. */
  1410. if (ha->pio_address) {
  1411. WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
  1412. WRT_REG_WORD_PIO(PIO_REG(ha, flash_data), (uint16_t)data);
  1413. } else {
  1414. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  1415. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1416. WRT_REG_WORD(&reg->flash_data, (uint16_t)data);
  1417. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1418. }
  1419. }
  1420. /**
  1421. * qla2x00_poll_flash() - Polls flash for completion.
  1422. * @ha: HA context
  1423. * @addr: Address in flash to poll
  1424. * @poll_data: Data to be polled
  1425. * @man_id: Flash manufacturer ID
  1426. * @flash_id: Flash ID
  1427. *
  1428. * This function polls the device until bit 7 of what is read matches data
  1429. * bit 7 or until data bit 5 becomes a 1. If that hapens, the flash ROM timed
  1430. * out (a fatal error). The flash book recommeds reading bit 7 again after
  1431. * reading bit 5 as a 1.
  1432. *
  1433. * Returns 0 on success, else non-zero.
  1434. */
  1435. static int
  1436. qla2x00_poll_flash(scsi_qla_host_t *ha, uint32_t addr, uint8_t poll_data,
  1437. uint8_t man_id, uint8_t flash_id)
  1438. {
  1439. int status;
  1440. uint8_t flash_data;
  1441. uint32_t cnt;
  1442. status = 1;
  1443. /* Wait for 30 seconds for command to finish. */
  1444. poll_data &= BIT_7;
  1445. for (cnt = 3000000; cnt; cnt--) {
  1446. flash_data = qla2x00_read_flash_byte(ha, addr);
  1447. if ((flash_data & BIT_7) == poll_data) {
  1448. status = 0;
  1449. break;
  1450. }
  1451. if (man_id != 0x40 && man_id != 0xda) {
  1452. if ((flash_data & BIT_5) && cnt > 2)
  1453. cnt = 2;
  1454. }
  1455. udelay(10);
  1456. barrier();
  1457. cond_resched();
  1458. }
  1459. return status;
  1460. }
  1461. /**
  1462. * qla2x00_program_flash_address() - Programs a flash address
  1463. * @ha: HA context
  1464. * @addr: Address in flash to program
  1465. * @data: Data to be written in flash
  1466. * @man_id: Flash manufacturer ID
  1467. * @flash_id: Flash ID
  1468. *
  1469. * Returns 0 on success, else non-zero.
  1470. */
  1471. static int
  1472. qla2x00_program_flash_address(scsi_qla_host_t *ha, uint32_t addr, uint8_t data,
  1473. uint8_t man_id, uint8_t flash_id)
  1474. {
  1475. /* Write Program Command Sequence. */
  1476. if (IS_OEM_001(ha)) {
  1477. qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
  1478. qla2x00_write_flash_byte(ha, 0x555, 0x55);
  1479. qla2x00_write_flash_byte(ha, 0xaaa, 0xa0);
  1480. qla2x00_write_flash_byte(ha, addr, data);
  1481. } else {
  1482. if (man_id == 0xda && flash_id == 0xc1) {
  1483. qla2x00_write_flash_byte(ha, addr, data);
  1484. if (addr & 0x7e)
  1485. return 0;
  1486. } else {
  1487. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1488. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1489. qla2x00_write_flash_byte(ha, 0x5555, 0xa0);
  1490. qla2x00_write_flash_byte(ha, addr, data);
  1491. }
  1492. }
  1493. udelay(150);
  1494. /* Wait for write to complete. */
  1495. return qla2x00_poll_flash(ha, addr, data, man_id, flash_id);
  1496. }
  1497. /**
  1498. * qla2x00_erase_flash() - Erase the flash.
  1499. * @ha: HA context
  1500. * @man_id: Flash manufacturer ID
  1501. * @flash_id: Flash ID
  1502. *
  1503. * Returns 0 on success, else non-zero.
  1504. */
  1505. static int
  1506. qla2x00_erase_flash(scsi_qla_host_t *ha, uint8_t man_id, uint8_t flash_id)
  1507. {
  1508. /* Individual Sector Erase Command Sequence */
  1509. if (IS_OEM_001(ha)) {
  1510. qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
  1511. qla2x00_write_flash_byte(ha, 0x555, 0x55);
  1512. qla2x00_write_flash_byte(ha, 0xaaa, 0x80);
  1513. qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
  1514. qla2x00_write_flash_byte(ha, 0x555, 0x55);
  1515. qla2x00_write_flash_byte(ha, 0xaaa, 0x10);
  1516. } else {
  1517. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1518. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1519. qla2x00_write_flash_byte(ha, 0x5555, 0x80);
  1520. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1521. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1522. qla2x00_write_flash_byte(ha, 0x5555, 0x10);
  1523. }
  1524. udelay(150);
  1525. /* Wait for erase to complete. */
  1526. return qla2x00_poll_flash(ha, 0x00, 0x80, man_id, flash_id);
  1527. }
  1528. /**
  1529. * qla2x00_erase_flash_sector() - Erase a flash sector.
  1530. * @ha: HA context
  1531. * @addr: Flash sector to erase
  1532. * @sec_mask: Sector address mask
  1533. * @man_id: Flash manufacturer ID
  1534. * @flash_id: Flash ID
  1535. *
  1536. * Returns 0 on success, else non-zero.
  1537. */
  1538. static int
  1539. qla2x00_erase_flash_sector(scsi_qla_host_t *ha, uint32_t addr,
  1540. uint32_t sec_mask, uint8_t man_id, uint8_t flash_id)
  1541. {
  1542. /* Individual Sector Erase Command Sequence */
  1543. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1544. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1545. qla2x00_write_flash_byte(ha, 0x5555, 0x80);
  1546. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1547. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1548. if (man_id == 0x1f && flash_id == 0x13)
  1549. qla2x00_write_flash_byte(ha, addr & sec_mask, 0x10);
  1550. else
  1551. qla2x00_write_flash_byte(ha, addr & sec_mask, 0x30);
  1552. udelay(150);
  1553. /* Wait for erase to complete. */
  1554. return qla2x00_poll_flash(ha, addr, 0x80, man_id, flash_id);
  1555. }
  1556. /**
  1557. * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip.
  1558. * @man_id: Flash manufacturer ID
  1559. * @flash_id: Flash ID
  1560. */
  1561. static void
  1562. qla2x00_get_flash_manufacturer(scsi_qla_host_t *ha, uint8_t *man_id,
  1563. uint8_t *flash_id)
  1564. {
  1565. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1566. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1567. qla2x00_write_flash_byte(ha, 0x5555, 0x90);
  1568. *man_id = qla2x00_read_flash_byte(ha, 0x0000);
  1569. *flash_id = qla2x00_read_flash_byte(ha, 0x0001);
  1570. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1571. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1572. qla2x00_write_flash_byte(ha, 0x5555, 0xf0);
  1573. }
  1574. static void
  1575. qla2x00_read_flash_data(scsi_qla_host_t *ha, uint8_t *tmp_buf, uint32_t saddr,
  1576. uint32_t length)
  1577. {
  1578. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1579. uint32_t midpoint, ilength;
  1580. uint8_t data;
  1581. midpoint = length / 2;
  1582. WRT_REG_WORD(&reg->nvram, 0);
  1583. RD_REG_WORD(&reg->nvram);
  1584. for (ilength = 0; ilength < length; saddr++, ilength++, tmp_buf++) {
  1585. if (ilength == midpoint) {
  1586. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  1587. RD_REG_WORD(&reg->nvram);
  1588. }
  1589. data = qla2x00_read_flash_byte(ha, saddr);
  1590. if (saddr % 100)
  1591. udelay(10);
  1592. *tmp_buf = data;
  1593. cond_resched();
  1594. }
  1595. }
  1596. static inline void
  1597. qla2x00_suspend_hba(struct scsi_qla_host *ha)
  1598. {
  1599. int cnt;
  1600. unsigned long flags;
  1601. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1602. /* Suspend HBA. */
  1603. scsi_block_requests(ha->host);
  1604. ha->isp_ops->disable_intrs(ha);
  1605. set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1606. /* Pause RISC. */
  1607. spin_lock_irqsave(&ha->hardware_lock, flags);
  1608. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  1609. RD_REG_WORD(&reg->hccr);
  1610. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  1611. for (cnt = 0; cnt < 30000; cnt++) {
  1612. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
  1613. break;
  1614. udelay(100);
  1615. }
  1616. } else {
  1617. udelay(10);
  1618. }
  1619. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1620. }
  1621. static inline void
  1622. qla2x00_resume_hba(struct scsi_qla_host *ha)
  1623. {
  1624. /* Resume HBA. */
  1625. clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1626. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  1627. qla2xxx_wake_dpc(ha);
  1628. qla2x00_wait_for_hba_online(ha);
  1629. scsi_unblock_requests(ha->host);
  1630. }
  1631. uint8_t *
  1632. qla2x00_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1633. uint32_t offset, uint32_t length)
  1634. {
  1635. uint32_t addr, midpoint;
  1636. uint8_t *data;
  1637. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1638. /* Suspend HBA. */
  1639. qla2x00_suspend_hba(ha);
  1640. /* Go with read. */
  1641. midpoint = ha->optrom_size / 2;
  1642. qla2x00_flash_enable(ha);
  1643. WRT_REG_WORD(&reg->nvram, 0);
  1644. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  1645. for (addr = offset, data = buf; addr < length; addr++, data++) {
  1646. if (addr == midpoint) {
  1647. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  1648. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  1649. }
  1650. *data = qla2x00_read_flash_byte(ha, addr);
  1651. }
  1652. qla2x00_flash_disable(ha);
  1653. /* Resume HBA. */
  1654. qla2x00_resume_hba(ha);
  1655. return buf;
  1656. }
  1657. int
  1658. qla2x00_write_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1659. uint32_t offset, uint32_t length)
  1660. {
  1661. int rval;
  1662. uint8_t man_id, flash_id, sec_number, data;
  1663. uint16_t wd;
  1664. uint32_t addr, liter, sec_mask, rest_addr;
  1665. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1666. /* Suspend HBA. */
  1667. qla2x00_suspend_hba(ha);
  1668. rval = QLA_SUCCESS;
  1669. sec_number = 0;
  1670. /* Reset ISP chip. */
  1671. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  1672. pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
  1673. /* Go with write. */
  1674. qla2x00_flash_enable(ha);
  1675. do { /* Loop once to provide quick error exit */
  1676. /* Structure of flash memory based on manufacturer */
  1677. if (IS_OEM_001(ha)) {
  1678. /* OEM variant with special flash part. */
  1679. man_id = flash_id = 0;
  1680. rest_addr = 0xffff;
  1681. sec_mask = 0x10000;
  1682. goto update_flash;
  1683. }
  1684. qla2x00_get_flash_manufacturer(ha, &man_id, &flash_id);
  1685. switch (man_id) {
  1686. case 0x20: /* ST flash. */
  1687. if (flash_id == 0xd2 || flash_id == 0xe3) {
  1688. /*
  1689. * ST m29w008at part - 64kb sector size with
  1690. * 32kb,8kb,8kb,16kb sectors at memory address
  1691. * 0xf0000.
  1692. */
  1693. rest_addr = 0xffff;
  1694. sec_mask = 0x10000;
  1695. break;
  1696. }
  1697. /*
  1698. * ST m29w010b part - 16kb sector size
  1699. * Default to 16kb sectors
  1700. */
  1701. rest_addr = 0x3fff;
  1702. sec_mask = 0x1c000;
  1703. break;
  1704. case 0x40: /* Mostel flash. */
  1705. /* Mostel v29c51001 part - 512 byte sector size. */
  1706. rest_addr = 0x1ff;
  1707. sec_mask = 0x1fe00;
  1708. break;
  1709. case 0xbf: /* SST flash. */
  1710. /* SST39sf10 part - 4kb sector size. */
  1711. rest_addr = 0xfff;
  1712. sec_mask = 0x1f000;
  1713. break;
  1714. case 0xda: /* Winbond flash. */
  1715. /* Winbond W29EE011 part - 256 byte sector size. */
  1716. rest_addr = 0x7f;
  1717. sec_mask = 0x1ff80;
  1718. break;
  1719. case 0xc2: /* Macronix flash. */
  1720. /* 64k sector size. */
  1721. if (flash_id == 0x38 || flash_id == 0x4f) {
  1722. rest_addr = 0xffff;
  1723. sec_mask = 0x10000;
  1724. break;
  1725. }
  1726. /* Fall through... */
  1727. case 0x1f: /* Atmel flash. */
  1728. /* 512k sector size. */
  1729. if (flash_id == 0x13) {
  1730. rest_addr = 0x7fffffff;
  1731. sec_mask = 0x80000000;
  1732. break;
  1733. }
  1734. /* Fall through... */
  1735. case 0x01: /* AMD flash. */
  1736. if (flash_id == 0x38 || flash_id == 0x40 ||
  1737. flash_id == 0x4f) {
  1738. /* Am29LV081 part - 64kb sector size. */
  1739. /* Am29LV002BT part - 64kb sector size. */
  1740. rest_addr = 0xffff;
  1741. sec_mask = 0x10000;
  1742. break;
  1743. } else if (flash_id == 0x3e) {
  1744. /*
  1745. * Am29LV008b part - 64kb sector size with
  1746. * 32kb,8kb,8kb,16kb sector at memory address
  1747. * h0xf0000.
  1748. */
  1749. rest_addr = 0xffff;
  1750. sec_mask = 0x10000;
  1751. break;
  1752. } else if (flash_id == 0x20 || flash_id == 0x6e) {
  1753. /*
  1754. * Am29LV010 part or AM29f010 - 16kb sector
  1755. * size.
  1756. */
  1757. rest_addr = 0x3fff;
  1758. sec_mask = 0x1c000;
  1759. break;
  1760. } else if (flash_id == 0x6d) {
  1761. /* Am29LV001 part - 8kb sector size. */
  1762. rest_addr = 0x1fff;
  1763. sec_mask = 0x1e000;
  1764. break;
  1765. }
  1766. default:
  1767. /* Default to 16 kb sector size. */
  1768. rest_addr = 0x3fff;
  1769. sec_mask = 0x1c000;
  1770. break;
  1771. }
  1772. update_flash:
  1773. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  1774. if (qla2x00_erase_flash(ha, man_id, flash_id)) {
  1775. rval = QLA_FUNCTION_FAILED;
  1776. break;
  1777. }
  1778. }
  1779. for (addr = offset, liter = 0; liter < length; liter++,
  1780. addr++) {
  1781. data = buf[liter];
  1782. /* Are we at the beginning of a sector? */
  1783. if ((addr & rest_addr) == 0) {
  1784. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  1785. if (addr >= 0x10000UL) {
  1786. if (((addr >> 12) & 0xf0) &&
  1787. ((man_id == 0x01 &&
  1788. flash_id == 0x3e) ||
  1789. (man_id == 0x20 &&
  1790. flash_id == 0xd2))) {
  1791. sec_number++;
  1792. if (sec_number == 1) {
  1793. rest_addr =
  1794. 0x7fff;
  1795. sec_mask =
  1796. 0x18000;
  1797. } else if (
  1798. sec_number == 2 ||
  1799. sec_number == 3) {
  1800. rest_addr =
  1801. 0x1fff;
  1802. sec_mask =
  1803. 0x1e000;
  1804. } else if (
  1805. sec_number == 4) {
  1806. rest_addr =
  1807. 0x3fff;
  1808. sec_mask =
  1809. 0x1c000;
  1810. }
  1811. }
  1812. }
  1813. } else if (addr == ha->optrom_size / 2) {
  1814. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  1815. RD_REG_WORD(&reg->nvram);
  1816. }
  1817. if (flash_id == 0xda && man_id == 0xc1) {
  1818. qla2x00_write_flash_byte(ha, 0x5555,
  1819. 0xaa);
  1820. qla2x00_write_flash_byte(ha, 0x2aaa,
  1821. 0x55);
  1822. qla2x00_write_flash_byte(ha, 0x5555,
  1823. 0xa0);
  1824. } else if (!IS_QLA2322(ha) && !IS_QLA6322(ha)) {
  1825. /* Then erase it */
  1826. if (qla2x00_erase_flash_sector(ha,
  1827. addr, sec_mask, man_id,
  1828. flash_id)) {
  1829. rval = QLA_FUNCTION_FAILED;
  1830. break;
  1831. }
  1832. if (man_id == 0x01 && flash_id == 0x6d)
  1833. sec_number++;
  1834. }
  1835. }
  1836. if (man_id == 0x01 && flash_id == 0x6d) {
  1837. if (sec_number == 1 &&
  1838. addr == (rest_addr - 1)) {
  1839. rest_addr = 0x0fff;
  1840. sec_mask = 0x1f000;
  1841. } else if (sec_number == 3 && (addr & 0x7ffe)) {
  1842. rest_addr = 0x3fff;
  1843. sec_mask = 0x1c000;
  1844. }
  1845. }
  1846. if (qla2x00_program_flash_address(ha, addr, data,
  1847. man_id, flash_id)) {
  1848. rval = QLA_FUNCTION_FAILED;
  1849. break;
  1850. }
  1851. cond_resched();
  1852. }
  1853. } while (0);
  1854. qla2x00_flash_disable(ha);
  1855. /* Resume HBA. */
  1856. qla2x00_resume_hba(ha);
  1857. return rval;
  1858. }
  1859. uint8_t *
  1860. qla24xx_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1861. uint32_t offset, uint32_t length)
  1862. {
  1863. /* Suspend HBA. */
  1864. scsi_block_requests(ha->host);
  1865. set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1866. /* Go with read. */
  1867. qla24xx_read_flash_data(ha, (uint32_t *)buf, offset >> 2, length >> 2);
  1868. /* Resume HBA. */
  1869. clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1870. scsi_unblock_requests(ha->host);
  1871. return buf;
  1872. }
  1873. int
  1874. qla24xx_write_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1875. uint32_t offset, uint32_t length)
  1876. {
  1877. int rval;
  1878. /* Suspend HBA. */
  1879. scsi_block_requests(ha->host);
  1880. set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1881. /* Go with write. */
  1882. rval = qla24xx_write_flash_data(ha, (uint32_t *)buf, offset >> 2,
  1883. length >> 2);
  1884. /* Resume HBA -- RISC reset needed. */
  1885. clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1886. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  1887. qla2xxx_wake_dpc(ha);
  1888. qla2x00_wait_for_hba_online(ha);
  1889. scsi_unblock_requests(ha->host);
  1890. return rval;
  1891. }
  1892. uint8_t *
  1893. qla25xx_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  1894. uint32_t offset, uint32_t length)
  1895. {
  1896. int rval;
  1897. dma_addr_t optrom_dma;
  1898. void *optrom;
  1899. uint8_t *pbuf;
  1900. uint32_t faddr, left, burst;
  1901. if (offset & 0xfff)
  1902. goto slow_read;
  1903. if (length < OPTROM_BURST_SIZE)
  1904. goto slow_read;
  1905. optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
  1906. &optrom_dma, GFP_KERNEL);
  1907. if (!optrom) {
  1908. qla_printk(KERN_DEBUG, ha,
  1909. "Unable to allocate memory for optrom burst read "
  1910. "(%x KB).\n", OPTROM_BURST_SIZE / 1024);
  1911. goto slow_read;
  1912. }
  1913. pbuf = buf;
  1914. faddr = offset >> 2;
  1915. left = length >> 2;
  1916. burst = OPTROM_BURST_DWORDS;
  1917. while (left != 0) {
  1918. if (burst > left)
  1919. burst = left;
  1920. rval = qla2x00_dump_ram(ha, optrom_dma,
  1921. flash_data_to_access_addr(faddr), burst);
  1922. if (rval) {
  1923. qla_printk(KERN_WARNING, ha,
  1924. "Unable to burst-read optrom segment "
  1925. "(%x/%x/%llx).\n", rval,
  1926. flash_data_to_access_addr(faddr),
  1927. (unsigned long long)optrom_dma);
  1928. qla_printk(KERN_WARNING, ha,
  1929. "Reverting to slow-read.\n");
  1930. dma_free_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
  1931. optrom, optrom_dma);
  1932. goto slow_read;
  1933. }
  1934. memcpy(pbuf, optrom, burst * 4);
  1935. left -= burst;
  1936. faddr += burst;
  1937. pbuf += burst * 4;
  1938. }
  1939. dma_free_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE, optrom,
  1940. optrom_dma);
  1941. return buf;
  1942. slow_read:
  1943. return qla24xx_read_optrom_data(ha, buf, offset, length);
  1944. }
  1945. /**
  1946. * qla2x00_get_fcode_version() - Determine an FCODE image's version.
  1947. * @ha: HA context
  1948. * @pcids: Pointer to the FCODE PCI data structure
  1949. *
  1950. * The process of retrieving the FCODE version information is at best
  1951. * described as interesting.
  1952. *
  1953. * Within the first 100h bytes of the image an ASCII string is present
  1954. * which contains several pieces of information including the FCODE
  1955. * version. Unfortunately it seems the only reliable way to retrieve
  1956. * the version is by scanning for another sentinel within the string,
  1957. * the FCODE build date:
  1958. *
  1959. * ... 2.00.02 10/17/02 ...
  1960. *
  1961. * Returns QLA_SUCCESS on successful retrieval of version.
  1962. */
  1963. static void
  1964. qla2x00_get_fcode_version(scsi_qla_host_t *ha, uint32_t pcids)
  1965. {
  1966. int ret = QLA_FUNCTION_FAILED;
  1967. uint32_t istart, iend, iter, vend;
  1968. uint8_t do_next, rbyte, *vbyte;
  1969. memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
  1970. /* Skip the PCI data structure. */
  1971. istart = pcids +
  1972. ((qla2x00_read_flash_byte(ha, pcids + 0x0B) << 8) |
  1973. qla2x00_read_flash_byte(ha, pcids + 0x0A));
  1974. iend = istart + 0x100;
  1975. do {
  1976. /* Scan for the sentinel date string...eeewww. */
  1977. do_next = 0;
  1978. iter = istart;
  1979. while ((iter < iend) && !do_next) {
  1980. iter++;
  1981. if (qla2x00_read_flash_byte(ha, iter) == '/') {
  1982. if (qla2x00_read_flash_byte(ha, iter + 2) ==
  1983. '/')
  1984. do_next++;
  1985. else if (qla2x00_read_flash_byte(ha,
  1986. iter + 3) == '/')
  1987. do_next++;
  1988. }
  1989. }
  1990. if (!do_next)
  1991. break;
  1992. /* Backtrack to previous ' ' (space). */
  1993. do_next = 0;
  1994. while ((iter > istart) && !do_next) {
  1995. iter--;
  1996. if (qla2x00_read_flash_byte(ha, iter) == ' ')
  1997. do_next++;
  1998. }
  1999. if (!do_next)
  2000. break;
  2001. /*
  2002. * Mark end of version tag, and find previous ' ' (space) or
  2003. * string length (recent FCODE images -- major hack ahead!!!).
  2004. */
  2005. vend = iter - 1;
  2006. do_next = 0;
  2007. while ((iter > istart) && !do_next) {
  2008. iter--;
  2009. rbyte = qla2x00_read_flash_byte(ha, iter);
  2010. if (rbyte == ' ' || rbyte == 0xd || rbyte == 0x10)
  2011. do_next++;
  2012. }
  2013. if (!do_next)
  2014. break;
  2015. /* Mark beginning of version tag, and copy data. */
  2016. iter++;
  2017. if ((vend - iter) &&
  2018. ((vend - iter) < sizeof(ha->fcode_revision))) {
  2019. vbyte = ha->fcode_revision;
  2020. while (iter <= vend) {
  2021. *vbyte++ = qla2x00_read_flash_byte(ha, iter);
  2022. iter++;
  2023. }
  2024. ret = QLA_SUCCESS;
  2025. }
  2026. } while (0);
  2027. if (ret != QLA_SUCCESS)
  2028. memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
  2029. }
  2030. int
  2031. qla2x00_get_flash_version(scsi_qla_host_t *ha, void *mbuf)
  2032. {
  2033. int ret = QLA_SUCCESS;
  2034. uint8_t code_type, last_image;
  2035. uint32_t pcihdr, pcids;
  2036. uint8_t *dbyte;
  2037. uint16_t *dcode;
  2038. if (!ha->pio_address || !mbuf)
  2039. return QLA_FUNCTION_FAILED;
  2040. memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
  2041. memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
  2042. memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
  2043. memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
  2044. qla2x00_flash_enable(ha);
  2045. /* Begin with first PCI expansion ROM header. */
  2046. pcihdr = 0;
  2047. last_image = 1;
  2048. do {
  2049. /* Verify PCI expansion ROM header. */
  2050. if (qla2x00_read_flash_byte(ha, pcihdr) != 0x55 ||
  2051. qla2x00_read_flash_byte(ha, pcihdr + 0x01) != 0xaa) {
  2052. /* No signature */
  2053. DEBUG2(printk("scsi(%ld): No matching ROM "
  2054. "signature.\n", ha->host_no));
  2055. ret = QLA_FUNCTION_FAILED;
  2056. break;
  2057. }
  2058. /* Locate PCI data structure. */
  2059. pcids = pcihdr +
  2060. ((qla2x00_read_flash_byte(ha, pcihdr + 0x19) << 8) |
  2061. qla2x00_read_flash_byte(ha, pcihdr + 0x18));
  2062. /* Validate signature of PCI data structure. */
  2063. if (qla2x00_read_flash_byte(ha, pcids) != 'P' ||
  2064. qla2x00_read_flash_byte(ha, pcids + 0x1) != 'C' ||
  2065. qla2x00_read_flash_byte(ha, pcids + 0x2) != 'I' ||
  2066. qla2x00_read_flash_byte(ha, pcids + 0x3) != 'R') {
  2067. /* Incorrect header. */
  2068. DEBUG2(printk("%s(): PCI data struct not found "
  2069. "pcir_adr=%x.\n", __func__, pcids));
  2070. ret = QLA_FUNCTION_FAILED;
  2071. break;
  2072. }
  2073. /* Read version */
  2074. code_type = qla2x00_read_flash_byte(ha, pcids + 0x14);
  2075. switch (code_type) {
  2076. case ROM_CODE_TYPE_BIOS:
  2077. /* Intel x86, PC-AT compatible. */
  2078. ha->bios_revision[0] =
  2079. qla2x00_read_flash_byte(ha, pcids + 0x12);
  2080. ha->bios_revision[1] =
  2081. qla2x00_read_flash_byte(ha, pcids + 0x13);
  2082. DEBUG3(printk("%s(): read BIOS %d.%d.\n", __func__,
  2083. ha->bios_revision[1], ha->bios_revision[0]));
  2084. break;
  2085. case ROM_CODE_TYPE_FCODE:
  2086. /* Open Firmware standard for PCI (FCode). */
  2087. /* Eeeewww... */
  2088. qla2x00_get_fcode_version(ha, pcids);
  2089. break;
  2090. case ROM_CODE_TYPE_EFI:
  2091. /* Extensible Firmware Interface (EFI). */
  2092. ha->efi_revision[0] =
  2093. qla2x00_read_flash_byte(ha, pcids + 0x12);
  2094. ha->efi_revision[1] =
  2095. qla2x00_read_flash_byte(ha, pcids + 0x13);
  2096. DEBUG3(printk("%s(): read EFI %d.%d.\n", __func__,
  2097. ha->efi_revision[1], ha->efi_revision[0]));
  2098. break;
  2099. default:
  2100. DEBUG2(printk("%s(): Unrecognized code type %x at "
  2101. "pcids %x.\n", __func__, code_type, pcids));
  2102. break;
  2103. }
  2104. last_image = qla2x00_read_flash_byte(ha, pcids + 0x15) & BIT_7;
  2105. /* Locate next PCI expansion ROM. */
  2106. pcihdr += ((qla2x00_read_flash_byte(ha, pcids + 0x11) << 8) |
  2107. qla2x00_read_flash_byte(ha, pcids + 0x10)) * 512;
  2108. } while (!last_image);
  2109. if (IS_QLA2322(ha)) {
  2110. /* Read firmware image information. */
  2111. memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
  2112. dbyte = mbuf;
  2113. memset(dbyte, 0, 8);
  2114. dcode = (uint16_t *)dbyte;
  2115. qla2x00_read_flash_data(ha, dbyte, ha->flt_region_fw * 4 + 10,
  2116. 8);
  2117. DEBUG3(printk("%s(%ld): dumping fw ver from flash:\n",
  2118. __func__, ha->host_no));
  2119. DEBUG3(qla2x00_dump_buffer((uint8_t *)dbyte, 8));
  2120. if ((dcode[0] == 0xffff && dcode[1] == 0xffff &&
  2121. dcode[2] == 0xffff && dcode[3] == 0xffff) ||
  2122. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  2123. dcode[3] == 0)) {
  2124. DEBUG2(printk("%s(): Unrecognized fw revision at "
  2125. "%x.\n", __func__, ha->flt_region_fw * 4));
  2126. } else {
  2127. /* values are in big endian */
  2128. ha->fw_revision[0] = dbyte[0] << 16 | dbyte[1];
  2129. ha->fw_revision[1] = dbyte[2] << 16 | dbyte[3];
  2130. ha->fw_revision[2] = dbyte[4] << 16 | dbyte[5];
  2131. }
  2132. }
  2133. qla2x00_flash_disable(ha);
  2134. return ret;
  2135. }
  2136. int
  2137. qla24xx_get_flash_version(scsi_qla_host_t *ha, void *mbuf)
  2138. {
  2139. int ret = QLA_SUCCESS;
  2140. uint32_t pcihdr, pcids;
  2141. uint32_t *dcode;
  2142. uint8_t *bcode;
  2143. uint8_t code_type, last_image;
  2144. int i;
  2145. if (!mbuf)
  2146. return QLA_FUNCTION_FAILED;
  2147. memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
  2148. memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
  2149. memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
  2150. memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
  2151. dcode = mbuf;
  2152. /* Begin with first PCI expansion ROM header. */
  2153. pcihdr = ha->flt_region_boot;
  2154. last_image = 1;
  2155. do {
  2156. /* Verify PCI expansion ROM header. */
  2157. qla24xx_read_flash_data(ha, dcode, pcihdr >> 2, 0x20);
  2158. bcode = mbuf + (pcihdr % 4);
  2159. if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa) {
  2160. /* No signature */
  2161. DEBUG2(printk("scsi(%ld): No matching ROM "
  2162. "signature.\n", ha->host_no));
  2163. ret = QLA_FUNCTION_FAILED;
  2164. break;
  2165. }
  2166. /* Locate PCI data structure. */
  2167. pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]);
  2168. qla24xx_read_flash_data(ha, dcode, pcids >> 2, 0x20);
  2169. bcode = mbuf + (pcihdr % 4);
  2170. /* Validate signature of PCI data structure. */
  2171. if (bcode[0x0] != 'P' || bcode[0x1] != 'C' ||
  2172. bcode[0x2] != 'I' || bcode[0x3] != 'R') {
  2173. /* Incorrect header. */
  2174. DEBUG2(printk("%s(): PCI data struct not found "
  2175. "pcir_adr=%x.\n", __func__, pcids));
  2176. ret = QLA_FUNCTION_FAILED;
  2177. break;
  2178. }
  2179. /* Read version */
  2180. code_type = bcode[0x14];
  2181. switch (code_type) {
  2182. case ROM_CODE_TYPE_BIOS:
  2183. /* Intel x86, PC-AT compatible. */
  2184. ha->bios_revision[0] = bcode[0x12];
  2185. ha->bios_revision[1] = bcode[0x13];
  2186. DEBUG3(printk("%s(): read BIOS %d.%d.\n", __func__,
  2187. ha->bios_revision[1], ha->bios_revision[0]));
  2188. break;
  2189. case ROM_CODE_TYPE_FCODE:
  2190. /* Open Firmware standard for PCI (FCode). */
  2191. ha->fcode_revision[0] = bcode[0x12];
  2192. ha->fcode_revision[1] = bcode[0x13];
  2193. DEBUG3(printk("%s(): read FCODE %d.%d.\n", __func__,
  2194. ha->fcode_revision[1], ha->fcode_revision[0]));
  2195. break;
  2196. case ROM_CODE_TYPE_EFI:
  2197. /* Extensible Firmware Interface (EFI). */
  2198. ha->efi_revision[0] = bcode[0x12];
  2199. ha->efi_revision[1] = bcode[0x13];
  2200. DEBUG3(printk("%s(): read EFI %d.%d.\n", __func__,
  2201. ha->efi_revision[1], ha->efi_revision[0]));
  2202. break;
  2203. default:
  2204. DEBUG2(printk("%s(): Unrecognized code type %x at "
  2205. "pcids %x.\n", __func__, code_type, pcids));
  2206. break;
  2207. }
  2208. last_image = bcode[0x15] & BIT_7;
  2209. /* Locate next PCI expansion ROM. */
  2210. pcihdr += ((bcode[0x11] << 8) | bcode[0x10]) * 512;
  2211. } while (!last_image);
  2212. /* Read firmware image information. */
  2213. memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
  2214. dcode = mbuf;
  2215. qla24xx_read_flash_data(ha, dcode, ha->flt_region_fw + 4, 4);
  2216. for (i = 0; i < 4; i++)
  2217. dcode[i] = be32_to_cpu(dcode[i]);
  2218. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  2219. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  2220. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  2221. dcode[3] == 0)) {
  2222. DEBUG2(printk("%s(): Unrecognized fw version at %x.\n",
  2223. __func__, ha->flt_region_fw));
  2224. } else {
  2225. ha->fw_revision[0] = dcode[0];
  2226. ha->fw_revision[1] = dcode[1];
  2227. ha->fw_revision[2] = dcode[2];
  2228. ha->fw_revision[3] = dcode[3];
  2229. }
  2230. return ret;
  2231. }
  2232. static int
  2233. qla2xxx_is_vpd_valid(uint8_t *pos, uint8_t *end)
  2234. {
  2235. if (pos >= end || *pos != 0x82)
  2236. return 0;
  2237. pos += 3 + pos[1];
  2238. if (pos >= end || *pos != 0x90)
  2239. return 0;
  2240. pos += 3 + pos[1];
  2241. if (pos >= end || *pos != 0x78)
  2242. return 0;
  2243. return 1;
  2244. }
  2245. int
  2246. qla2xxx_get_vpd_field(scsi_qla_host_t *ha, char *key, char *str, size_t size)
  2247. {
  2248. uint8_t *pos = ha->vpd;
  2249. uint8_t *end = pos + ha->vpd_size;
  2250. int len = 0;
  2251. if (!IS_FWI2_CAPABLE(ha) || !qla2xxx_is_vpd_valid(pos, end))
  2252. return 0;
  2253. while (pos < end && *pos != 0x78) {
  2254. len = (*pos == 0x82) ? pos[1] : pos[2];
  2255. if (!strncmp(pos, key, strlen(key)))
  2256. break;
  2257. if (*pos != 0x90 && *pos != 0x91)
  2258. pos += len;
  2259. pos += 3;
  2260. }
  2261. if (pos < end - len && *pos != 0x78)
  2262. return snprintf(str, size, "%.*s", len, pos + 3);
  2263. return 0;
  2264. }
  2265. static int
  2266. qla2xxx_hw_event_store(scsi_qla_host_t *ha, uint32_t *fdata)
  2267. {
  2268. uint32_t d[2], faddr;
  2269. /* Locate first empty entry. */
  2270. for (;;) {
  2271. if (ha->hw_event_ptr >=
  2272. ha->flt_region_hw_event + FA_HW_EVENT_SIZE) {
  2273. DEBUG2(qla_printk(KERN_WARNING, ha,
  2274. "HW event -- Log Full!\n"));
  2275. return QLA_MEMORY_ALLOC_FAILED;
  2276. }
  2277. qla24xx_read_flash_data(ha, d, ha->hw_event_ptr, 2);
  2278. faddr = flash_data_to_access_addr(ha->hw_event_ptr);
  2279. ha->hw_event_ptr += FA_HW_EVENT_ENTRY_SIZE;
  2280. if (d[0] == __constant_cpu_to_le32(0xffffffff) &&
  2281. d[1] == __constant_cpu_to_le32(0xffffffff)) {
  2282. qla24xx_unprotect_flash(ha);
  2283. qla24xx_write_flash_dword(ha, faddr++,
  2284. cpu_to_le32(jiffies));
  2285. qla24xx_write_flash_dword(ha, faddr++, 0);
  2286. qla24xx_write_flash_dword(ha, faddr++, *fdata++);
  2287. qla24xx_write_flash_dword(ha, faddr++, *fdata);
  2288. qla24xx_protect_flash(ha);
  2289. break;
  2290. }
  2291. }
  2292. return QLA_SUCCESS;
  2293. }
  2294. int
  2295. qla2xxx_hw_event_log(scsi_qla_host_t *ha, uint16_t code, uint16_t d1,
  2296. uint16_t d2, uint16_t d3)
  2297. {
  2298. #define QMARK(a, b, c, d) \
  2299. cpu_to_le32(LSB(a) << 24 | LSB(b) << 16 | LSB(c) << 8 | LSB(d))
  2300. int rval;
  2301. uint32_t marker[2], fdata[4];
  2302. if (ha->flt_region_hw_event == 0)
  2303. return QLA_FUNCTION_FAILED;
  2304. DEBUG2(qla_printk(KERN_WARNING, ha,
  2305. "HW event -- code=%x, d1=%x, d2=%x, d3=%x.\n", code, d1, d2, d3));
  2306. /* If marker not already found, locate or write. */
  2307. if (!ha->flags.hw_event_marker_found) {
  2308. /* Create marker. */
  2309. marker[0] = QMARK('L', ha->fw_major_version,
  2310. ha->fw_minor_version, ha->fw_subminor_version);
  2311. marker[1] = QMARK(QLA_DRIVER_MAJOR_VER, QLA_DRIVER_MINOR_VER,
  2312. QLA_DRIVER_PATCH_VER, QLA_DRIVER_BETA_VER);
  2313. /* Locate marker. */
  2314. ha->hw_event_ptr = ha->flt_region_hw_event;
  2315. for (;;) {
  2316. qla24xx_read_flash_data(ha, fdata, ha->hw_event_ptr,
  2317. 4);
  2318. if (fdata[0] == __constant_cpu_to_le32(0xffffffff) &&
  2319. fdata[1] == __constant_cpu_to_le32(0xffffffff))
  2320. break;
  2321. ha->hw_event_ptr += FA_HW_EVENT_ENTRY_SIZE;
  2322. if (ha->hw_event_ptr >=
  2323. ha->flt_region_hw_event + FA_HW_EVENT_SIZE) {
  2324. DEBUG2(qla_printk(KERN_WARNING, ha,
  2325. "HW event -- Log Full!\n"));
  2326. return QLA_MEMORY_ALLOC_FAILED;
  2327. }
  2328. if (fdata[2] == marker[0] && fdata[3] == marker[1]) {
  2329. ha->flags.hw_event_marker_found = 1;
  2330. break;
  2331. }
  2332. }
  2333. /* No marker, write it. */
  2334. if (!ha->flags.hw_event_marker_found) {
  2335. rval = qla2xxx_hw_event_store(ha, marker);
  2336. if (rval != QLA_SUCCESS) {
  2337. DEBUG2(qla_printk(KERN_WARNING, ha,
  2338. "HW event -- Failed marker write=%x.!\n",
  2339. rval));
  2340. return rval;
  2341. }
  2342. ha->flags.hw_event_marker_found = 1;
  2343. }
  2344. }
  2345. /* Store error. */
  2346. fdata[0] = cpu_to_le32(code << 16 | d1);
  2347. fdata[1] = cpu_to_le32(d2 << 16 | d3);
  2348. rval = qla2xxx_hw_event_store(ha, fdata);
  2349. if (rval != QLA_SUCCESS) {
  2350. DEBUG2(qla_printk(KERN_WARNING, ha,
  2351. "HW event -- Failed error write=%x.!\n",
  2352. rval));
  2353. }
  2354. return rval;
  2355. }