qla_sup.c 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2014 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/slab.h>
  10. #include <linux/vmalloc.h>
  11. #include <linux/uaccess.h>
  12. /*
  13. * NVRAM support routines
  14. */
  15. /**
  16. * qla2x00_lock_nvram_access() -
  17. * @ha: HA context
  18. */
  19. static void
  20. qla2x00_lock_nvram_access(struct qla_hw_data *ha)
  21. {
  22. uint16_t data;
  23. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  24. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) {
  25. data = RD_REG_WORD(&reg->nvram);
  26. while (data & NVR_BUSY) {
  27. udelay(100);
  28. data = RD_REG_WORD(&reg->nvram);
  29. }
  30. /* Lock resource */
  31. WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0x1);
  32. RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  33. udelay(5);
  34. data = RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  35. while ((data & BIT_0) == 0) {
  36. /* Lock failed */
  37. udelay(100);
  38. WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0x1);
  39. RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  40. udelay(5);
  41. data = RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  42. }
  43. }
  44. }
  45. /**
  46. * qla2x00_unlock_nvram_access() -
  47. * @ha: HA context
  48. */
  49. static void
  50. qla2x00_unlock_nvram_access(struct qla_hw_data *ha)
  51. {
  52. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  53. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) {
  54. WRT_REG_WORD(&reg->u.isp2300.host_semaphore, 0);
  55. RD_REG_WORD(&reg->u.isp2300.host_semaphore);
  56. }
  57. }
  58. /**
  59. * qla2x00_nv_write() - Prepare for NVRAM read/write operation.
  60. * @ha: HA context
  61. * @data: Serial interface selector
  62. */
  63. static void
  64. qla2x00_nv_write(struct qla_hw_data *ha, uint16_t data)
  65. {
  66. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  67. WRT_REG_WORD(&reg->nvram, data | NVR_SELECT | NVR_WRT_ENABLE);
  68. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  69. NVRAM_DELAY();
  70. WRT_REG_WORD(&reg->nvram, data | NVR_SELECT | NVR_CLOCK |
  71. NVR_WRT_ENABLE);
  72. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  73. NVRAM_DELAY();
  74. WRT_REG_WORD(&reg->nvram, data | NVR_SELECT | NVR_WRT_ENABLE);
  75. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  76. NVRAM_DELAY();
  77. }
  78. /**
  79. * qla2x00_nvram_request() - Sends read command to NVRAM and gets data from
  80. * NVRAM.
  81. * @ha: HA context
  82. * @nv_cmd: NVRAM command
  83. *
  84. * Bit definitions for NVRAM command:
  85. *
  86. * Bit 26 = start bit
  87. * Bit 25, 24 = opcode
  88. * Bit 23-16 = address
  89. * Bit 15-0 = write data
  90. *
  91. * Returns the word read from nvram @addr.
  92. */
  93. static uint16_t
  94. qla2x00_nvram_request(struct qla_hw_data *ha, uint32_t nv_cmd)
  95. {
  96. uint8_t cnt;
  97. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  98. uint16_t data = 0;
  99. uint16_t reg_data;
  100. /* Send command to NVRAM. */
  101. nv_cmd <<= 5;
  102. for (cnt = 0; cnt < 11; cnt++) {
  103. if (nv_cmd & BIT_31)
  104. qla2x00_nv_write(ha, NVR_DATA_OUT);
  105. else
  106. qla2x00_nv_write(ha, 0);
  107. nv_cmd <<= 1;
  108. }
  109. /* Read data from NVRAM. */
  110. for (cnt = 0; cnt < 16; cnt++) {
  111. WRT_REG_WORD(&reg->nvram, NVR_SELECT | NVR_CLOCK);
  112. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  113. NVRAM_DELAY();
  114. data <<= 1;
  115. reg_data = RD_REG_WORD(&reg->nvram);
  116. if (reg_data & NVR_DATA_IN)
  117. data |= BIT_0;
  118. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  119. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  120. NVRAM_DELAY();
  121. }
  122. /* Deselect chip. */
  123. WRT_REG_WORD(&reg->nvram, NVR_DESELECT);
  124. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  125. NVRAM_DELAY();
  126. return data;
  127. }
  128. /**
  129. * qla2x00_get_nvram_word() - Calculates word position in NVRAM and calls the
  130. * request routine to get the word from NVRAM.
  131. * @ha: HA context
  132. * @addr: Address in NVRAM to read
  133. *
  134. * Returns the word read from nvram @addr.
  135. */
  136. static uint16_t
  137. qla2x00_get_nvram_word(struct qla_hw_data *ha, uint32_t addr)
  138. {
  139. uint16_t data;
  140. uint32_t nv_cmd;
  141. nv_cmd = addr << 16;
  142. nv_cmd |= NV_READ_OP;
  143. data = qla2x00_nvram_request(ha, nv_cmd);
  144. return (data);
  145. }
  146. /**
  147. * qla2x00_nv_deselect() - Deselect NVRAM operations.
  148. * @ha: HA context
  149. */
  150. static void
  151. qla2x00_nv_deselect(struct qla_hw_data *ha)
  152. {
  153. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  154. WRT_REG_WORD(&reg->nvram, NVR_DESELECT);
  155. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  156. NVRAM_DELAY();
  157. }
  158. /**
  159. * qla2x00_write_nvram_word() - Write NVRAM data.
  160. * @ha: HA context
  161. * @addr: Address in NVRAM to write
  162. * @data: word to program
  163. */
  164. static void
  165. qla2x00_write_nvram_word(struct qla_hw_data *ha, uint32_t addr, uint16_t data)
  166. {
  167. int count;
  168. uint16_t word;
  169. uint32_t nv_cmd, wait_cnt;
  170. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  171. scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
  172. qla2x00_nv_write(ha, NVR_DATA_OUT);
  173. qla2x00_nv_write(ha, 0);
  174. qla2x00_nv_write(ha, 0);
  175. for (word = 0; word < 8; word++)
  176. qla2x00_nv_write(ha, NVR_DATA_OUT);
  177. qla2x00_nv_deselect(ha);
  178. /* Write data */
  179. nv_cmd = (addr << 16) | NV_WRITE_OP;
  180. nv_cmd |= data;
  181. nv_cmd <<= 5;
  182. for (count = 0; count < 27; count++) {
  183. if (nv_cmd & BIT_31)
  184. qla2x00_nv_write(ha, NVR_DATA_OUT);
  185. else
  186. qla2x00_nv_write(ha, 0);
  187. nv_cmd <<= 1;
  188. }
  189. qla2x00_nv_deselect(ha);
  190. /* Wait for NVRAM to become ready */
  191. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  192. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  193. wait_cnt = NVR_WAIT_CNT;
  194. do {
  195. if (!--wait_cnt) {
  196. ql_dbg(ql_dbg_user, vha, 0x708d,
  197. "NVRAM didn't go ready...\n");
  198. break;
  199. }
  200. NVRAM_DELAY();
  201. word = RD_REG_WORD(&reg->nvram);
  202. } while ((word & NVR_DATA_IN) == 0);
  203. qla2x00_nv_deselect(ha);
  204. /* Disable writes */
  205. qla2x00_nv_write(ha, NVR_DATA_OUT);
  206. for (count = 0; count < 10; count++)
  207. qla2x00_nv_write(ha, 0);
  208. qla2x00_nv_deselect(ha);
  209. }
  210. static int
  211. qla2x00_write_nvram_word_tmo(struct qla_hw_data *ha, uint32_t addr,
  212. uint16_t data, uint32_t tmo)
  213. {
  214. int ret, count;
  215. uint16_t word;
  216. uint32_t nv_cmd;
  217. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  218. ret = QLA_SUCCESS;
  219. qla2x00_nv_write(ha, NVR_DATA_OUT);
  220. qla2x00_nv_write(ha, 0);
  221. qla2x00_nv_write(ha, 0);
  222. for (word = 0; word < 8; word++)
  223. qla2x00_nv_write(ha, NVR_DATA_OUT);
  224. qla2x00_nv_deselect(ha);
  225. /* Write data */
  226. nv_cmd = (addr << 16) | NV_WRITE_OP;
  227. nv_cmd |= data;
  228. nv_cmd <<= 5;
  229. for (count = 0; count < 27; count++) {
  230. if (nv_cmd & BIT_31)
  231. qla2x00_nv_write(ha, NVR_DATA_OUT);
  232. else
  233. qla2x00_nv_write(ha, 0);
  234. nv_cmd <<= 1;
  235. }
  236. qla2x00_nv_deselect(ha);
  237. /* Wait for NVRAM to become ready */
  238. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  239. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  240. do {
  241. NVRAM_DELAY();
  242. word = RD_REG_WORD(&reg->nvram);
  243. if (!--tmo) {
  244. ret = QLA_FUNCTION_FAILED;
  245. break;
  246. }
  247. } while ((word & NVR_DATA_IN) == 0);
  248. qla2x00_nv_deselect(ha);
  249. /* Disable writes */
  250. qla2x00_nv_write(ha, NVR_DATA_OUT);
  251. for (count = 0; count < 10; count++)
  252. qla2x00_nv_write(ha, 0);
  253. qla2x00_nv_deselect(ha);
  254. return ret;
  255. }
  256. /**
  257. * qla2x00_clear_nvram_protection() -
  258. * @ha: HA context
  259. */
  260. static int
  261. qla2x00_clear_nvram_protection(struct qla_hw_data *ha)
  262. {
  263. int ret, stat;
  264. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  265. uint32_t word, wait_cnt;
  266. uint16_t wprot, wprot_old;
  267. scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
  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. 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. ql_dbg(ql_dbg_user, vha, 0x708e,
  303. "NVRAM didn't go ready...\n");
  304. break;
  305. }
  306. NVRAM_DELAY();
  307. word = RD_REG_WORD(&reg->nvram);
  308. } while ((word & NVR_DATA_IN) == 0);
  309. if (wait_cnt)
  310. ret = QLA_SUCCESS;
  311. } else
  312. qla2x00_write_nvram_word(ha, ha->nvram_base, wprot_old);
  313. return ret;
  314. }
  315. static void
  316. qla2x00_set_nvram_protection(struct qla_hw_data *ha, int stat)
  317. {
  318. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  319. uint32_t word, wait_cnt;
  320. scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
  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. ql_dbg(ql_dbg_user, vha, 0x708f,
  352. "NVRAM didn't go ready...\n");
  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. static inline uint32_t
  363. flash_conf_addr(struct qla_hw_data *ha, uint32_t faddr)
  364. {
  365. return ha->flash_conf_off | faddr;
  366. }
  367. static inline uint32_t
  368. flash_data_addr(struct qla_hw_data *ha, uint32_t faddr)
  369. {
  370. return ha->flash_data_off | faddr;
  371. }
  372. static inline uint32_t
  373. nvram_conf_addr(struct qla_hw_data *ha, uint32_t naddr)
  374. {
  375. return ha->nvram_conf_off | naddr;
  376. }
  377. static inline uint32_t
  378. nvram_data_addr(struct qla_hw_data *ha, uint32_t naddr)
  379. {
  380. return ha->nvram_data_off | naddr;
  381. }
  382. static uint32_t
  383. qla24xx_read_flash_dword(struct qla_hw_data *ha, uint32_t addr)
  384. {
  385. int rval;
  386. uint32_t cnt, data;
  387. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  388. WRT_REG_DWORD(&reg->flash_addr, addr & ~FARX_DATA_FLAG);
  389. /* Wait for READ cycle to complete. */
  390. rval = QLA_SUCCESS;
  391. for (cnt = 3000;
  392. (RD_REG_DWORD(&reg->flash_addr) & FARX_DATA_FLAG) == 0 &&
  393. rval == QLA_SUCCESS; cnt--) {
  394. if (cnt)
  395. udelay(10);
  396. else
  397. rval = QLA_FUNCTION_TIMEOUT;
  398. cond_resched();
  399. }
  400. /* TODO: What happens if we time out? */
  401. data = 0xDEADDEAD;
  402. if (rval == QLA_SUCCESS)
  403. data = RD_REG_DWORD(&reg->flash_data);
  404. return data;
  405. }
  406. uint32_t *
  407. qla24xx_read_flash_data(scsi_qla_host_t *vha, uint32_t *dwptr, uint32_t faddr,
  408. uint32_t dwords)
  409. {
  410. uint32_t i;
  411. struct qla_hw_data *ha = vha->hw;
  412. /* Dword reads to flash. */
  413. for (i = 0; i < dwords; i++, faddr++)
  414. dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
  415. flash_data_addr(ha, faddr)));
  416. return dwptr;
  417. }
  418. static int
  419. qla24xx_write_flash_dword(struct qla_hw_data *ha, uint32_t addr, uint32_t data)
  420. {
  421. int rval;
  422. uint32_t cnt;
  423. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  424. WRT_REG_DWORD(&reg->flash_data, data);
  425. RD_REG_DWORD(&reg->flash_data); /* PCI Posting. */
  426. WRT_REG_DWORD(&reg->flash_addr, addr | FARX_DATA_FLAG);
  427. /* Wait for Write cycle to complete. */
  428. rval = QLA_SUCCESS;
  429. for (cnt = 500000; (RD_REG_DWORD(&reg->flash_addr) & FARX_DATA_FLAG) &&
  430. rval == QLA_SUCCESS; cnt--) {
  431. if (cnt)
  432. udelay(10);
  433. else
  434. rval = QLA_FUNCTION_TIMEOUT;
  435. cond_resched();
  436. }
  437. return rval;
  438. }
  439. static void
  440. qla24xx_get_flash_manufacturer(struct qla_hw_data *ha, uint8_t *man_id,
  441. uint8_t *flash_id)
  442. {
  443. uint32_t ids;
  444. ids = qla24xx_read_flash_dword(ha, flash_conf_addr(ha, 0x03ab));
  445. *man_id = LSB(ids);
  446. *flash_id = MSB(ids);
  447. /* Check if man_id and flash_id are valid. */
  448. if (ids != 0xDEADDEAD && (*man_id == 0 || *flash_id == 0)) {
  449. /* Read information using 0x9f opcode
  450. * Device ID, Mfg ID would be read in the format:
  451. * <Ext Dev Info><Device ID Part2><Device ID Part 1><Mfg ID>
  452. * Example: ATMEL 0x00 01 45 1F
  453. * Extract MFG and Dev ID from last two bytes.
  454. */
  455. ids = qla24xx_read_flash_dword(ha, flash_conf_addr(ha, 0x009f));
  456. *man_id = LSB(ids);
  457. *flash_id = MSB(ids);
  458. }
  459. }
  460. static int
  461. qla2xxx_find_flt_start(scsi_qla_host_t *vha, uint32_t *start)
  462. {
  463. const char *loc, *locations[] = { "DEF", "PCI" };
  464. uint32_t pcihdr, pcids;
  465. uint32_t *dcode;
  466. uint8_t *buf, *bcode, last_image;
  467. uint16_t cnt, chksum, *wptr;
  468. struct qla_flt_location *fltl;
  469. struct qla_hw_data *ha = vha->hw;
  470. struct req_que *req = ha->req_q_map[0];
  471. /*
  472. * FLT-location structure resides after the last PCI region.
  473. */
  474. /* Begin with sane defaults. */
  475. loc = locations[0];
  476. *start = 0;
  477. if (IS_QLA24XX_TYPE(ha))
  478. *start = FA_FLASH_LAYOUT_ADDR_24;
  479. else if (IS_QLA25XX(ha))
  480. *start = FA_FLASH_LAYOUT_ADDR;
  481. else if (IS_QLA81XX(ha))
  482. *start = FA_FLASH_LAYOUT_ADDR_81;
  483. else if (IS_P3P_TYPE(ha)) {
  484. *start = FA_FLASH_LAYOUT_ADDR_82;
  485. goto end;
  486. } else if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
  487. *start = FA_FLASH_LAYOUT_ADDR_83;
  488. goto end;
  489. }
  490. /* Begin with first PCI expansion ROM header. */
  491. buf = (uint8_t *)req->ring;
  492. dcode = (uint32_t *)req->ring;
  493. pcihdr = 0;
  494. last_image = 1;
  495. do {
  496. /* Verify PCI expansion ROM header. */
  497. qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, 0x20);
  498. bcode = buf + (pcihdr % 4);
  499. if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa)
  500. goto end;
  501. /* Locate PCI data structure. */
  502. pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]);
  503. qla24xx_read_flash_data(vha, dcode, pcids >> 2, 0x20);
  504. bcode = buf + (pcihdr % 4);
  505. /* Validate signature of PCI data structure. */
  506. if (bcode[0x0] != 'P' || bcode[0x1] != 'C' ||
  507. bcode[0x2] != 'I' || bcode[0x3] != 'R')
  508. goto end;
  509. last_image = bcode[0x15] & BIT_7;
  510. /* Locate next PCI expansion ROM. */
  511. pcihdr += ((bcode[0x11] << 8) | bcode[0x10]) * 512;
  512. } while (!last_image);
  513. /* Now verify FLT-location structure. */
  514. fltl = (struct qla_flt_location *)req->ring;
  515. qla24xx_read_flash_data(vha, dcode, pcihdr >> 2,
  516. sizeof(struct qla_flt_location) >> 2);
  517. if (fltl->sig[0] != 'Q' || fltl->sig[1] != 'F' ||
  518. fltl->sig[2] != 'L' || fltl->sig[3] != 'T')
  519. goto end;
  520. wptr = (uint16_t *)req->ring;
  521. cnt = sizeof(struct qla_flt_location) >> 1;
  522. for (chksum = 0; cnt--; wptr++)
  523. chksum += le16_to_cpu(*wptr);
  524. if (chksum) {
  525. ql_log(ql_log_fatal, vha, 0x0045,
  526. "Inconsistent FLTL detected: checksum=0x%x.\n", chksum);
  527. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010e,
  528. buf, sizeof(struct qla_flt_location));
  529. return QLA_FUNCTION_FAILED;
  530. }
  531. /* Good data. Use specified location. */
  532. loc = locations[1];
  533. *start = (le16_to_cpu(fltl->start_hi) << 16 |
  534. le16_to_cpu(fltl->start_lo)) >> 2;
  535. end:
  536. ql_dbg(ql_dbg_init, vha, 0x0046,
  537. "FLTL[%s] = 0x%x.\n",
  538. loc, *start);
  539. return QLA_SUCCESS;
  540. }
  541. static void
  542. qla2xxx_get_flt_info(scsi_qla_host_t *vha, uint32_t flt_addr)
  543. {
  544. const char *loc, *locations[] = { "DEF", "FLT" };
  545. const uint32_t def_fw[] =
  546. { FA_RISC_CODE_ADDR, FA_RISC_CODE_ADDR, FA_RISC_CODE_ADDR_81 };
  547. const uint32_t def_boot[] =
  548. { FA_BOOT_CODE_ADDR, FA_BOOT_CODE_ADDR, FA_BOOT_CODE_ADDR_81 };
  549. const uint32_t def_vpd_nvram[] =
  550. { FA_VPD_NVRAM_ADDR, FA_VPD_NVRAM_ADDR, FA_VPD_NVRAM_ADDR_81 };
  551. const uint32_t def_vpd0[] =
  552. { 0, 0, FA_VPD0_ADDR_81 };
  553. const uint32_t def_vpd1[] =
  554. { 0, 0, FA_VPD1_ADDR_81 };
  555. const uint32_t def_nvram0[] =
  556. { 0, 0, FA_NVRAM0_ADDR_81 };
  557. const uint32_t def_nvram1[] =
  558. { 0, 0, FA_NVRAM1_ADDR_81 };
  559. const uint32_t def_fdt[] =
  560. { FA_FLASH_DESCR_ADDR_24, FA_FLASH_DESCR_ADDR,
  561. FA_FLASH_DESCR_ADDR_81 };
  562. const uint32_t def_npiv_conf0[] =
  563. { FA_NPIV_CONF0_ADDR_24, FA_NPIV_CONF0_ADDR,
  564. FA_NPIV_CONF0_ADDR_81 };
  565. const uint32_t def_npiv_conf1[] =
  566. { FA_NPIV_CONF1_ADDR_24, FA_NPIV_CONF1_ADDR,
  567. FA_NPIV_CONF1_ADDR_81 };
  568. const uint32_t fcp_prio_cfg0[] =
  569. { FA_FCP_PRIO0_ADDR, FA_FCP_PRIO0_ADDR_25,
  570. 0 };
  571. const uint32_t fcp_prio_cfg1[] =
  572. { FA_FCP_PRIO1_ADDR, FA_FCP_PRIO1_ADDR_25,
  573. 0 };
  574. uint32_t def;
  575. uint16_t *wptr;
  576. uint16_t cnt, chksum;
  577. uint32_t start;
  578. struct qla_flt_header *flt;
  579. struct qla_flt_region *region;
  580. struct qla_hw_data *ha = vha->hw;
  581. struct req_que *req = ha->req_q_map[0];
  582. def = 0;
  583. if (IS_QLA25XX(ha))
  584. def = 1;
  585. else if (IS_QLA81XX(ha))
  586. def = 2;
  587. /* Assign FCP prio region since older adapters may not have FLT, or
  588. FCP prio region in it's FLT.
  589. */
  590. ha->flt_region_fcp_prio = (ha->port_no == 0) ?
  591. fcp_prio_cfg0[def] : fcp_prio_cfg1[def];
  592. ha->flt_region_flt = flt_addr;
  593. wptr = (uint16_t *)req->ring;
  594. flt = (struct qla_flt_header *)req->ring;
  595. region = (struct qla_flt_region *)&flt[1];
  596. ha->isp_ops->read_optrom(vha, (uint8_t *)req->ring,
  597. flt_addr << 2, OPTROM_BURST_SIZE);
  598. if (*wptr == cpu_to_le16(0xffff))
  599. goto no_flash_data;
  600. if (flt->version != cpu_to_le16(1)) {
  601. ql_log(ql_log_warn, vha, 0x0047,
  602. "Unsupported FLT detected: version=0x%x length=0x%x checksum=0x%x.\n",
  603. le16_to_cpu(flt->version), le16_to_cpu(flt->length),
  604. le16_to_cpu(flt->checksum));
  605. goto no_flash_data;
  606. }
  607. cnt = (sizeof(struct qla_flt_header) + le16_to_cpu(flt->length)) >> 1;
  608. for (chksum = 0; cnt--; wptr++)
  609. chksum += le16_to_cpu(*wptr);
  610. if (chksum) {
  611. ql_log(ql_log_fatal, vha, 0x0048,
  612. "Inconsistent FLT detected: version=0x%x length=0x%x checksum=0x%x.\n",
  613. le16_to_cpu(flt->version), le16_to_cpu(flt->length),
  614. le16_to_cpu(flt->checksum));
  615. goto no_flash_data;
  616. }
  617. loc = locations[1];
  618. cnt = le16_to_cpu(flt->length) / sizeof(struct qla_flt_region);
  619. for ( ; cnt; cnt--, region++) {
  620. /* Store addresses as DWORD offsets. */
  621. start = le32_to_cpu(region->start) >> 2;
  622. ql_dbg(ql_dbg_init, vha, 0x0049,
  623. "FLT[%02x]: start=0x%x "
  624. "end=0x%x size=0x%x.\n", le32_to_cpu(region->code) & 0xff,
  625. start, le32_to_cpu(region->end) >> 2,
  626. le32_to_cpu(region->size));
  627. switch (le32_to_cpu(region->code) & 0xff) {
  628. case FLT_REG_FCOE_FW:
  629. if (!IS_QLA8031(ha))
  630. break;
  631. ha->flt_region_fw = start;
  632. break;
  633. case FLT_REG_FW:
  634. if (IS_QLA8031(ha))
  635. break;
  636. ha->flt_region_fw = start;
  637. break;
  638. case FLT_REG_BOOT_CODE:
  639. ha->flt_region_boot = start;
  640. break;
  641. case FLT_REG_VPD_0:
  642. if (IS_QLA8031(ha))
  643. break;
  644. ha->flt_region_vpd_nvram = start;
  645. if (IS_P3P_TYPE(ha))
  646. break;
  647. if (ha->port_no == 0)
  648. ha->flt_region_vpd = start;
  649. break;
  650. case FLT_REG_VPD_1:
  651. if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
  652. break;
  653. if (ha->port_no == 1)
  654. ha->flt_region_vpd = start;
  655. break;
  656. case FLT_REG_VPD_2:
  657. if (!IS_QLA27XX(ha))
  658. break;
  659. if (ha->port_no == 2)
  660. ha->flt_region_vpd = start;
  661. break;
  662. case FLT_REG_VPD_3:
  663. if (!IS_QLA27XX(ha))
  664. break;
  665. if (ha->port_no == 3)
  666. ha->flt_region_vpd = start;
  667. break;
  668. case FLT_REG_NVRAM_0:
  669. if (IS_QLA8031(ha))
  670. break;
  671. if (ha->port_no == 0)
  672. ha->flt_region_nvram = start;
  673. break;
  674. case FLT_REG_NVRAM_1:
  675. if (IS_QLA8031(ha))
  676. break;
  677. if (ha->port_no == 1)
  678. ha->flt_region_nvram = start;
  679. break;
  680. case FLT_REG_NVRAM_2:
  681. if (!IS_QLA27XX(ha))
  682. break;
  683. if (ha->port_no == 2)
  684. ha->flt_region_nvram = start;
  685. break;
  686. case FLT_REG_NVRAM_3:
  687. if (!IS_QLA27XX(ha))
  688. break;
  689. if (ha->port_no == 3)
  690. ha->flt_region_nvram = start;
  691. break;
  692. case FLT_REG_FDT:
  693. ha->flt_region_fdt = start;
  694. break;
  695. case FLT_REG_NPIV_CONF_0:
  696. if (ha->port_no == 0)
  697. ha->flt_region_npiv_conf = start;
  698. break;
  699. case FLT_REG_NPIV_CONF_1:
  700. if (ha->port_no == 1)
  701. ha->flt_region_npiv_conf = start;
  702. break;
  703. case FLT_REG_GOLD_FW:
  704. ha->flt_region_gold_fw = start;
  705. break;
  706. case FLT_REG_FCP_PRIO_0:
  707. if (ha->port_no == 0)
  708. ha->flt_region_fcp_prio = start;
  709. break;
  710. case FLT_REG_FCP_PRIO_1:
  711. if (ha->port_no == 1)
  712. ha->flt_region_fcp_prio = start;
  713. break;
  714. case FLT_REG_BOOT_CODE_82XX:
  715. ha->flt_region_boot = start;
  716. break;
  717. case FLT_REG_BOOT_CODE_8044:
  718. if (IS_QLA8044(ha))
  719. ha->flt_region_boot = start;
  720. break;
  721. case FLT_REG_FW_82XX:
  722. ha->flt_region_fw = start;
  723. break;
  724. case FLT_REG_CNA_FW:
  725. if (IS_CNA_CAPABLE(ha))
  726. ha->flt_region_fw = start;
  727. break;
  728. case FLT_REG_GOLD_FW_82XX:
  729. ha->flt_region_gold_fw = start;
  730. break;
  731. case FLT_REG_BOOTLOAD_82XX:
  732. ha->flt_region_bootload = start;
  733. break;
  734. case FLT_REG_VPD_8XXX:
  735. if (IS_CNA_CAPABLE(ha))
  736. ha->flt_region_vpd = start;
  737. break;
  738. case FLT_REG_FCOE_NVRAM_0:
  739. if (!(IS_QLA8031(ha) || IS_QLA8044(ha)))
  740. break;
  741. if (ha->port_no == 0)
  742. ha->flt_region_nvram = start;
  743. break;
  744. case FLT_REG_FCOE_NVRAM_1:
  745. if (!(IS_QLA8031(ha) || IS_QLA8044(ha)))
  746. break;
  747. if (ha->port_no == 1)
  748. ha->flt_region_nvram = start;
  749. break;
  750. case FLT_REG_IMG_PRI_27XX:
  751. if (IS_QLA27XX(ha))
  752. ha->flt_region_img_status_pri = start;
  753. break;
  754. case FLT_REG_IMG_SEC_27XX:
  755. if (IS_QLA27XX(ha))
  756. ha->flt_region_img_status_sec = start;
  757. break;
  758. case FLT_REG_FW_SEC_27XX:
  759. if (IS_QLA27XX(ha))
  760. ha->flt_region_fw_sec = start;
  761. break;
  762. case FLT_REG_BOOTLOAD_SEC_27XX:
  763. if (IS_QLA27XX(ha))
  764. ha->flt_region_boot_sec = start;
  765. break;
  766. case FLT_REG_VPD_SEC_27XX_0:
  767. if (IS_QLA27XX(ha))
  768. ha->flt_region_vpd_sec = start;
  769. break;
  770. case FLT_REG_VPD_SEC_27XX_1:
  771. if (IS_QLA27XX(ha))
  772. ha->flt_region_vpd_sec = start;
  773. break;
  774. case FLT_REG_VPD_SEC_27XX_2:
  775. if (IS_QLA27XX(ha))
  776. ha->flt_region_vpd_sec = start;
  777. break;
  778. case FLT_REG_VPD_SEC_27XX_3:
  779. if (IS_QLA27XX(ha))
  780. ha->flt_region_vpd_sec = start;
  781. break;
  782. }
  783. }
  784. goto done;
  785. no_flash_data:
  786. /* Use hardcoded defaults. */
  787. loc = locations[0];
  788. ha->flt_region_fw = def_fw[def];
  789. ha->flt_region_boot = def_boot[def];
  790. ha->flt_region_vpd_nvram = def_vpd_nvram[def];
  791. ha->flt_region_vpd = (ha->port_no == 0) ?
  792. def_vpd0[def] : def_vpd1[def];
  793. ha->flt_region_nvram = (ha->port_no == 0) ?
  794. def_nvram0[def] : def_nvram1[def];
  795. ha->flt_region_fdt = def_fdt[def];
  796. ha->flt_region_npiv_conf = (ha->port_no == 0) ?
  797. def_npiv_conf0[def] : def_npiv_conf1[def];
  798. done:
  799. ql_dbg(ql_dbg_init, vha, 0x004a,
  800. "FLT[%s]: boot=0x%x fw=0x%x vpd_nvram=0x%x vpd=0x%x nvram=0x%x "
  801. "fdt=0x%x flt=0x%x npiv=0x%x fcp_prif_cfg=0x%x.\n",
  802. loc, ha->flt_region_boot, ha->flt_region_fw,
  803. ha->flt_region_vpd_nvram, ha->flt_region_vpd, ha->flt_region_nvram,
  804. ha->flt_region_fdt, ha->flt_region_flt, ha->flt_region_npiv_conf,
  805. ha->flt_region_fcp_prio);
  806. }
  807. static void
  808. qla2xxx_get_fdt_info(scsi_qla_host_t *vha)
  809. {
  810. #define FLASH_BLK_SIZE_4K 0x1000
  811. #define FLASH_BLK_SIZE_32K 0x8000
  812. #define FLASH_BLK_SIZE_64K 0x10000
  813. const char *loc, *locations[] = { "MID", "FDT" };
  814. uint16_t cnt, chksum;
  815. uint16_t *wptr;
  816. struct qla_fdt_layout *fdt;
  817. uint8_t man_id, flash_id;
  818. uint16_t mid = 0, fid = 0;
  819. struct qla_hw_data *ha = vha->hw;
  820. struct req_que *req = ha->req_q_map[0];
  821. wptr = (uint16_t *)req->ring;
  822. fdt = (struct qla_fdt_layout *)req->ring;
  823. ha->isp_ops->read_optrom(vha, (uint8_t *)req->ring,
  824. ha->flt_region_fdt << 2, OPTROM_BURST_SIZE);
  825. if (*wptr == cpu_to_le16(0xffff))
  826. goto no_flash_data;
  827. if (fdt->sig[0] != 'Q' || fdt->sig[1] != 'L' || fdt->sig[2] != 'I' ||
  828. fdt->sig[3] != 'D')
  829. goto no_flash_data;
  830. for (cnt = 0, chksum = 0; cnt < sizeof(*fdt) >> 1; cnt++, wptr++)
  831. chksum += le16_to_cpu(*wptr);
  832. if (chksum) {
  833. ql_dbg(ql_dbg_init, vha, 0x004c,
  834. "Inconsistent FDT detected:"
  835. " checksum=0x%x id=%c version0x%x.\n", chksum,
  836. fdt->sig[0], le16_to_cpu(fdt->version));
  837. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0113,
  838. (uint8_t *)fdt, sizeof(*fdt));
  839. goto no_flash_data;
  840. }
  841. loc = locations[1];
  842. mid = le16_to_cpu(fdt->man_id);
  843. fid = le16_to_cpu(fdt->id);
  844. ha->fdt_wrt_disable = fdt->wrt_disable_bits;
  845. ha->fdt_wrt_enable = fdt->wrt_enable_bits;
  846. ha->fdt_wrt_sts_reg_cmd = fdt->wrt_sts_reg_cmd;
  847. if (IS_QLA8044(ha))
  848. ha->fdt_erase_cmd = fdt->erase_cmd;
  849. else
  850. ha->fdt_erase_cmd =
  851. flash_conf_addr(ha, 0x0300 | fdt->erase_cmd);
  852. ha->fdt_block_size = le32_to_cpu(fdt->block_size);
  853. if (fdt->unprotect_sec_cmd) {
  854. ha->fdt_unprotect_sec_cmd = flash_conf_addr(ha, 0x0300 |
  855. fdt->unprotect_sec_cmd);
  856. ha->fdt_protect_sec_cmd = fdt->protect_sec_cmd ?
  857. flash_conf_addr(ha, 0x0300 | fdt->protect_sec_cmd):
  858. flash_conf_addr(ha, 0x0336);
  859. }
  860. goto done;
  861. no_flash_data:
  862. loc = locations[0];
  863. if (IS_P3P_TYPE(ha)) {
  864. ha->fdt_block_size = FLASH_BLK_SIZE_64K;
  865. goto done;
  866. }
  867. qla24xx_get_flash_manufacturer(ha, &man_id, &flash_id);
  868. mid = man_id;
  869. fid = flash_id;
  870. ha->fdt_wrt_disable = 0x9c;
  871. ha->fdt_erase_cmd = flash_conf_addr(ha, 0x03d8);
  872. switch (man_id) {
  873. case 0xbf: /* STT flash. */
  874. if (flash_id == 0x8e)
  875. ha->fdt_block_size = FLASH_BLK_SIZE_64K;
  876. else
  877. ha->fdt_block_size = FLASH_BLK_SIZE_32K;
  878. if (flash_id == 0x80)
  879. ha->fdt_erase_cmd = flash_conf_addr(ha, 0x0352);
  880. break;
  881. case 0x13: /* ST M25P80. */
  882. ha->fdt_block_size = FLASH_BLK_SIZE_64K;
  883. break;
  884. case 0x1f: /* Atmel 26DF081A. */
  885. ha->fdt_block_size = FLASH_BLK_SIZE_4K;
  886. ha->fdt_erase_cmd = flash_conf_addr(ha, 0x0320);
  887. ha->fdt_unprotect_sec_cmd = flash_conf_addr(ha, 0x0339);
  888. ha->fdt_protect_sec_cmd = flash_conf_addr(ha, 0x0336);
  889. break;
  890. default:
  891. /* Default to 64 kb sector size. */
  892. ha->fdt_block_size = FLASH_BLK_SIZE_64K;
  893. break;
  894. }
  895. done:
  896. ql_dbg(ql_dbg_init, vha, 0x004d,
  897. "FDT[%s]: (0x%x/0x%x) erase=0x%x "
  898. "pr=%x wrtd=0x%x blk=0x%x.\n",
  899. loc, mid, fid,
  900. ha->fdt_erase_cmd, ha->fdt_protect_sec_cmd,
  901. ha->fdt_wrt_disable, ha->fdt_block_size);
  902. }
  903. static void
  904. qla2xxx_get_idc_param(scsi_qla_host_t *vha)
  905. {
  906. #define QLA82XX_IDC_PARAM_ADDR 0x003e885c
  907. uint32_t *wptr;
  908. struct qla_hw_data *ha = vha->hw;
  909. struct req_que *req = ha->req_q_map[0];
  910. if (!(IS_P3P_TYPE(ha)))
  911. return;
  912. wptr = (uint32_t *)req->ring;
  913. ha->isp_ops->read_optrom(vha, (uint8_t *)req->ring,
  914. QLA82XX_IDC_PARAM_ADDR , 8);
  915. if (*wptr == cpu_to_le32(0xffffffff)) {
  916. ha->fcoe_dev_init_timeout = QLA82XX_ROM_DEV_INIT_TIMEOUT;
  917. ha->fcoe_reset_timeout = QLA82XX_ROM_DRV_RESET_ACK_TIMEOUT;
  918. } else {
  919. ha->fcoe_dev_init_timeout = le32_to_cpu(*wptr);
  920. wptr++;
  921. ha->fcoe_reset_timeout = le32_to_cpu(*wptr);
  922. }
  923. ql_dbg(ql_dbg_init, vha, 0x004e,
  924. "fcoe_dev_init_timeout=%d "
  925. "fcoe_reset_timeout=%d.\n", ha->fcoe_dev_init_timeout,
  926. ha->fcoe_reset_timeout);
  927. return;
  928. }
  929. int
  930. qla2xxx_get_flash_info(scsi_qla_host_t *vha)
  931. {
  932. int ret;
  933. uint32_t flt_addr;
  934. struct qla_hw_data *ha = vha->hw;
  935. if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
  936. !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha) && !IS_QLA27XX(ha))
  937. return QLA_SUCCESS;
  938. ret = qla2xxx_find_flt_start(vha, &flt_addr);
  939. if (ret != QLA_SUCCESS)
  940. return ret;
  941. qla2xxx_get_flt_info(vha, flt_addr);
  942. qla2xxx_get_fdt_info(vha);
  943. qla2xxx_get_idc_param(vha);
  944. return QLA_SUCCESS;
  945. }
  946. void
  947. qla2xxx_flash_npiv_conf(scsi_qla_host_t *vha)
  948. {
  949. #define NPIV_CONFIG_SIZE (16*1024)
  950. void *data;
  951. uint16_t *wptr;
  952. uint16_t cnt, chksum;
  953. int i;
  954. struct qla_npiv_header hdr;
  955. struct qla_npiv_entry *entry;
  956. struct qla_hw_data *ha = vha->hw;
  957. if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
  958. !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha))
  959. return;
  960. if (ha->flags.nic_core_reset_hdlr_active)
  961. return;
  962. if (IS_QLA8044(ha))
  963. return;
  964. ha->isp_ops->read_optrom(vha, (uint8_t *)&hdr,
  965. ha->flt_region_npiv_conf << 2, sizeof(struct qla_npiv_header));
  966. if (hdr.version == cpu_to_le16(0xffff))
  967. return;
  968. if (hdr.version != cpu_to_le16(1)) {
  969. ql_dbg(ql_dbg_user, vha, 0x7090,
  970. "Unsupported NPIV-Config "
  971. "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
  972. le16_to_cpu(hdr.version), le16_to_cpu(hdr.entries),
  973. le16_to_cpu(hdr.checksum));
  974. return;
  975. }
  976. data = kmalloc(NPIV_CONFIG_SIZE, GFP_KERNEL);
  977. if (!data) {
  978. ql_log(ql_log_warn, vha, 0x7091,
  979. "Unable to allocate memory for data.\n");
  980. return;
  981. }
  982. ha->isp_ops->read_optrom(vha, (uint8_t *)data,
  983. ha->flt_region_npiv_conf << 2, NPIV_CONFIG_SIZE);
  984. cnt = (sizeof(hdr) + le16_to_cpu(hdr.entries) * sizeof(*entry)) >> 1;
  985. for (wptr = data, chksum = 0; cnt--; wptr++)
  986. chksum += le16_to_cpu(*wptr);
  987. if (chksum) {
  988. ql_dbg(ql_dbg_user, vha, 0x7092,
  989. "Inconsistent NPIV-Config "
  990. "detected: version=0x%x entries=0x%x checksum=0x%x.\n",
  991. le16_to_cpu(hdr.version), le16_to_cpu(hdr.entries),
  992. le16_to_cpu(hdr.checksum));
  993. goto done;
  994. }
  995. entry = data + sizeof(struct qla_npiv_header);
  996. cnt = le16_to_cpu(hdr.entries);
  997. for (i = 0; cnt; cnt--, entry++, i++) {
  998. uint16_t flags;
  999. struct fc_vport_identifiers vid;
  1000. struct fc_vport *vport;
  1001. memcpy(&ha->npiv_info[i], entry, sizeof(struct qla_npiv_entry));
  1002. flags = le16_to_cpu(entry->flags);
  1003. if (flags == 0xffff)
  1004. continue;
  1005. if ((flags & BIT_0) == 0)
  1006. continue;
  1007. memset(&vid, 0, sizeof(vid));
  1008. vid.roles = FC_PORT_ROLE_FCP_INITIATOR;
  1009. vid.vport_type = FC_PORTTYPE_NPIV;
  1010. vid.disable = false;
  1011. vid.port_name = wwn_to_u64(entry->port_name);
  1012. vid.node_name = wwn_to_u64(entry->node_name);
  1013. ql_dbg(ql_dbg_user, vha, 0x7093,
  1014. "NPIV[%02x]: wwpn=%llx "
  1015. "wwnn=%llx vf_id=0x%x Q_qos=0x%x F_qos=0x%x.\n", cnt,
  1016. (unsigned long long)vid.port_name,
  1017. (unsigned long long)vid.node_name,
  1018. le16_to_cpu(entry->vf_id),
  1019. entry->q_qos, entry->f_qos);
  1020. if (i < QLA_PRECONFIG_VPORTS) {
  1021. vport = fc_vport_create(vha->host, 0, &vid);
  1022. if (!vport)
  1023. ql_log(ql_log_warn, vha, 0x7094,
  1024. "NPIV-Config Failed to create vport [%02x]: "
  1025. "wwpn=%llx wwnn=%llx.\n", cnt,
  1026. (unsigned long long)vid.port_name,
  1027. (unsigned long long)vid.node_name);
  1028. }
  1029. }
  1030. done:
  1031. kfree(data);
  1032. }
  1033. static int
  1034. qla24xx_unprotect_flash(scsi_qla_host_t *vha)
  1035. {
  1036. struct qla_hw_data *ha = vha->hw;
  1037. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1038. if (ha->flags.fac_supported)
  1039. return qla81xx_fac_do_write_enable(vha, 1);
  1040. /* Enable flash write. */
  1041. WRT_REG_DWORD(&reg->ctrl_status,
  1042. RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
  1043. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  1044. if (!ha->fdt_wrt_disable)
  1045. goto done;
  1046. /* Disable flash write-protection, first clear SR protection bit */
  1047. qla24xx_write_flash_dword(ha, flash_conf_addr(ha, 0x101), 0);
  1048. /* Then write zero again to clear remaining SR bits.*/
  1049. qla24xx_write_flash_dword(ha, flash_conf_addr(ha, 0x101), 0);
  1050. done:
  1051. return QLA_SUCCESS;
  1052. }
  1053. static int
  1054. qla24xx_protect_flash(scsi_qla_host_t *vha)
  1055. {
  1056. uint32_t cnt;
  1057. struct qla_hw_data *ha = vha->hw;
  1058. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1059. if (ha->flags.fac_supported)
  1060. return qla81xx_fac_do_write_enable(vha, 0);
  1061. if (!ha->fdt_wrt_disable)
  1062. goto skip_wrt_protect;
  1063. /* Enable flash write-protection and wait for completion. */
  1064. qla24xx_write_flash_dword(ha, flash_conf_addr(ha, 0x101),
  1065. ha->fdt_wrt_disable);
  1066. for (cnt = 300; cnt &&
  1067. qla24xx_read_flash_dword(ha, flash_conf_addr(ha, 0x005)) & BIT_0;
  1068. cnt--) {
  1069. udelay(10);
  1070. }
  1071. skip_wrt_protect:
  1072. /* Disable flash write. */
  1073. WRT_REG_DWORD(&reg->ctrl_status,
  1074. RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
  1075. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  1076. return QLA_SUCCESS;
  1077. }
  1078. static int
  1079. qla24xx_erase_sector(scsi_qla_host_t *vha, uint32_t fdata)
  1080. {
  1081. struct qla_hw_data *ha = vha->hw;
  1082. uint32_t start, finish;
  1083. if (ha->flags.fac_supported) {
  1084. start = fdata >> 2;
  1085. finish = start + (ha->fdt_block_size >> 2) - 1;
  1086. return qla81xx_fac_erase_sector(vha, flash_data_addr(ha,
  1087. start), flash_data_addr(ha, finish));
  1088. }
  1089. return qla24xx_write_flash_dword(ha, ha->fdt_erase_cmd,
  1090. (fdata & 0xff00) | ((fdata << 16) & 0xff0000) |
  1091. ((fdata >> 16) & 0xff));
  1092. }
  1093. static int
  1094. qla24xx_write_flash_data(scsi_qla_host_t *vha, uint32_t *dwptr, uint32_t faddr,
  1095. uint32_t dwords)
  1096. {
  1097. int ret;
  1098. uint32_t liter;
  1099. uint32_t sec_mask, rest_addr;
  1100. uint32_t fdata;
  1101. dma_addr_t optrom_dma;
  1102. void *optrom = NULL;
  1103. struct qla_hw_data *ha = vha->hw;
  1104. /* Prepare burst-capable write on supported ISPs. */
  1105. if ((IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
  1106. IS_QLA27XX(ha)) &&
  1107. !(faddr & 0xfff) && dwords > OPTROM_BURST_DWORDS) {
  1108. optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
  1109. &optrom_dma, GFP_KERNEL);
  1110. if (!optrom) {
  1111. ql_log(ql_log_warn, vha, 0x7095,
  1112. "Unable to allocate "
  1113. "memory for optrom burst write (%x KB).\n",
  1114. OPTROM_BURST_SIZE / 1024);
  1115. }
  1116. }
  1117. rest_addr = (ha->fdt_block_size >> 2) - 1;
  1118. sec_mask = ~rest_addr;
  1119. ret = qla24xx_unprotect_flash(vha);
  1120. if (ret != QLA_SUCCESS) {
  1121. ql_log(ql_log_warn, vha, 0x7096,
  1122. "Unable to unprotect flash for update.\n");
  1123. goto done;
  1124. }
  1125. for (liter = 0; liter < dwords; liter++, faddr++, dwptr++) {
  1126. fdata = (faddr & sec_mask) << 2;
  1127. /* Are we at the beginning of a sector? */
  1128. if ((faddr & rest_addr) == 0) {
  1129. /* Do sector unprotect. */
  1130. if (ha->fdt_unprotect_sec_cmd)
  1131. qla24xx_write_flash_dword(ha,
  1132. ha->fdt_unprotect_sec_cmd,
  1133. (fdata & 0xff00) | ((fdata << 16) &
  1134. 0xff0000) | ((fdata >> 16) & 0xff));
  1135. ret = qla24xx_erase_sector(vha, fdata);
  1136. if (ret != QLA_SUCCESS) {
  1137. ql_dbg(ql_dbg_user, vha, 0x7007,
  1138. "Unable to erase erase sector: address=%x.\n",
  1139. faddr);
  1140. break;
  1141. }
  1142. }
  1143. /* Go with burst-write. */
  1144. if (optrom && (liter + OPTROM_BURST_DWORDS) <= dwords) {
  1145. /* Copy data to DMA'ble buffer. */
  1146. memcpy(optrom, dwptr, OPTROM_BURST_SIZE);
  1147. ret = qla2x00_load_ram(vha, optrom_dma,
  1148. flash_data_addr(ha, faddr),
  1149. OPTROM_BURST_DWORDS);
  1150. if (ret != QLA_SUCCESS) {
  1151. ql_log(ql_log_warn, vha, 0x7097,
  1152. "Unable to burst-write optrom segment "
  1153. "(%x/%x/%llx).\n", ret,
  1154. flash_data_addr(ha, faddr),
  1155. (unsigned long long)optrom_dma);
  1156. ql_log(ql_log_warn, vha, 0x7098,
  1157. "Reverting to slow-write.\n");
  1158. dma_free_coherent(&ha->pdev->dev,
  1159. OPTROM_BURST_SIZE, optrom, optrom_dma);
  1160. optrom = NULL;
  1161. } else {
  1162. liter += OPTROM_BURST_DWORDS - 1;
  1163. faddr += OPTROM_BURST_DWORDS - 1;
  1164. dwptr += OPTROM_BURST_DWORDS - 1;
  1165. continue;
  1166. }
  1167. }
  1168. ret = qla24xx_write_flash_dword(ha,
  1169. flash_data_addr(ha, faddr), cpu_to_le32(*dwptr));
  1170. if (ret != QLA_SUCCESS) {
  1171. ql_dbg(ql_dbg_user, vha, 0x7006,
  1172. "Unable to program flash address=%x data=%x.\n",
  1173. faddr, *dwptr);
  1174. break;
  1175. }
  1176. /* Do sector protect. */
  1177. if (ha->fdt_unprotect_sec_cmd &&
  1178. ((faddr & rest_addr) == rest_addr))
  1179. qla24xx_write_flash_dword(ha,
  1180. ha->fdt_protect_sec_cmd,
  1181. (fdata & 0xff00) | ((fdata << 16) &
  1182. 0xff0000) | ((fdata >> 16) & 0xff));
  1183. }
  1184. ret = qla24xx_protect_flash(vha);
  1185. if (ret != QLA_SUCCESS)
  1186. ql_log(ql_log_warn, vha, 0x7099,
  1187. "Unable to protect flash after update.\n");
  1188. done:
  1189. if (optrom)
  1190. dma_free_coherent(&ha->pdev->dev,
  1191. OPTROM_BURST_SIZE, optrom, optrom_dma);
  1192. return ret;
  1193. }
  1194. uint8_t *
  1195. qla2x00_read_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
  1196. uint32_t bytes)
  1197. {
  1198. uint32_t i;
  1199. uint16_t *wptr;
  1200. struct qla_hw_data *ha = vha->hw;
  1201. /* Word reads to NVRAM via registers. */
  1202. wptr = (uint16_t *)buf;
  1203. qla2x00_lock_nvram_access(ha);
  1204. for (i = 0; i < bytes >> 1; i++, naddr++)
  1205. wptr[i] = cpu_to_le16(qla2x00_get_nvram_word(ha,
  1206. naddr));
  1207. qla2x00_unlock_nvram_access(ha);
  1208. return buf;
  1209. }
  1210. uint8_t *
  1211. qla24xx_read_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
  1212. uint32_t bytes)
  1213. {
  1214. uint32_t i;
  1215. uint32_t *dwptr;
  1216. struct qla_hw_data *ha = vha->hw;
  1217. if (IS_P3P_TYPE(ha))
  1218. return buf;
  1219. /* Dword reads to flash. */
  1220. dwptr = (uint32_t *)buf;
  1221. for (i = 0; i < bytes >> 2; i++, naddr++)
  1222. dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
  1223. nvram_data_addr(ha, naddr)));
  1224. return buf;
  1225. }
  1226. int
  1227. qla2x00_write_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
  1228. uint32_t bytes)
  1229. {
  1230. int ret, stat;
  1231. uint32_t i;
  1232. uint16_t *wptr;
  1233. unsigned long flags;
  1234. struct qla_hw_data *ha = vha->hw;
  1235. ret = QLA_SUCCESS;
  1236. spin_lock_irqsave(&ha->hardware_lock, flags);
  1237. qla2x00_lock_nvram_access(ha);
  1238. /* Disable NVRAM write-protection. */
  1239. stat = qla2x00_clear_nvram_protection(ha);
  1240. wptr = (uint16_t *)buf;
  1241. for (i = 0; i < bytes >> 1; i++, naddr++) {
  1242. qla2x00_write_nvram_word(ha, naddr,
  1243. cpu_to_le16(*wptr));
  1244. wptr++;
  1245. }
  1246. /* Enable NVRAM write-protection. */
  1247. qla2x00_set_nvram_protection(ha, stat);
  1248. qla2x00_unlock_nvram_access(ha);
  1249. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1250. return ret;
  1251. }
  1252. int
  1253. qla24xx_write_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
  1254. uint32_t bytes)
  1255. {
  1256. int ret;
  1257. uint32_t i;
  1258. uint32_t *dwptr;
  1259. struct qla_hw_data *ha = vha->hw;
  1260. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1261. ret = QLA_SUCCESS;
  1262. if (IS_P3P_TYPE(ha))
  1263. return ret;
  1264. /* Enable flash write. */
  1265. WRT_REG_DWORD(&reg->ctrl_status,
  1266. RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
  1267. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  1268. /* Disable NVRAM write-protection. */
  1269. qla24xx_write_flash_dword(ha, nvram_conf_addr(ha, 0x101), 0);
  1270. qla24xx_write_flash_dword(ha, nvram_conf_addr(ha, 0x101), 0);
  1271. /* Dword writes to flash. */
  1272. dwptr = (uint32_t *)buf;
  1273. for (i = 0; i < bytes >> 2; i++, naddr++, dwptr++) {
  1274. ret = qla24xx_write_flash_dword(ha,
  1275. nvram_data_addr(ha, naddr), cpu_to_le32(*dwptr));
  1276. if (ret != QLA_SUCCESS) {
  1277. ql_dbg(ql_dbg_user, vha, 0x709a,
  1278. "Unable to program nvram address=%x data=%x.\n",
  1279. naddr, *dwptr);
  1280. break;
  1281. }
  1282. }
  1283. /* Enable NVRAM write-protection. */
  1284. qla24xx_write_flash_dword(ha, nvram_conf_addr(ha, 0x101), 0x8c);
  1285. /* Disable flash write. */
  1286. WRT_REG_DWORD(&reg->ctrl_status,
  1287. RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
  1288. RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
  1289. return ret;
  1290. }
  1291. uint8_t *
  1292. qla25xx_read_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
  1293. uint32_t bytes)
  1294. {
  1295. uint32_t i;
  1296. uint32_t *dwptr;
  1297. struct qla_hw_data *ha = vha->hw;
  1298. /* Dword reads to flash. */
  1299. dwptr = (uint32_t *)buf;
  1300. for (i = 0; i < bytes >> 2; i++, naddr++)
  1301. dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
  1302. flash_data_addr(ha, ha->flt_region_vpd_nvram | naddr)));
  1303. return buf;
  1304. }
  1305. int
  1306. qla25xx_write_nvram_data(scsi_qla_host_t *vha, uint8_t *buf, uint32_t naddr,
  1307. uint32_t bytes)
  1308. {
  1309. struct qla_hw_data *ha = vha->hw;
  1310. #define RMW_BUFFER_SIZE (64 * 1024)
  1311. uint8_t *dbuf;
  1312. dbuf = vmalloc(RMW_BUFFER_SIZE);
  1313. if (!dbuf)
  1314. return QLA_MEMORY_ALLOC_FAILED;
  1315. ha->isp_ops->read_optrom(vha, dbuf, ha->flt_region_vpd_nvram << 2,
  1316. RMW_BUFFER_SIZE);
  1317. memcpy(dbuf + (naddr << 2), buf, bytes);
  1318. ha->isp_ops->write_optrom(vha, dbuf, ha->flt_region_vpd_nvram << 2,
  1319. RMW_BUFFER_SIZE);
  1320. vfree(dbuf);
  1321. return QLA_SUCCESS;
  1322. }
  1323. static inline void
  1324. qla2x00_flip_colors(struct qla_hw_data *ha, uint16_t *pflags)
  1325. {
  1326. if (IS_QLA2322(ha)) {
  1327. /* Flip all colors. */
  1328. if (ha->beacon_color_state == QLA_LED_ALL_ON) {
  1329. /* Turn off. */
  1330. ha->beacon_color_state = 0;
  1331. *pflags = GPIO_LED_ALL_OFF;
  1332. } else {
  1333. /* Turn on. */
  1334. ha->beacon_color_state = QLA_LED_ALL_ON;
  1335. *pflags = GPIO_LED_RGA_ON;
  1336. }
  1337. } else {
  1338. /* Flip green led only. */
  1339. if (ha->beacon_color_state == QLA_LED_GRN_ON) {
  1340. /* Turn off. */
  1341. ha->beacon_color_state = 0;
  1342. *pflags = GPIO_LED_GREEN_OFF_AMBER_OFF;
  1343. } else {
  1344. /* Turn on. */
  1345. ha->beacon_color_state = QLA_LED_GRN_ON;
  1346. *pflags = GPIO_LED_GREEN_ON_AMBER_OFF;
  1347. }
  1348. }
  1349. }
  1350. #define PIO_REG(h, r) ((h)->pio_address + offsetof(struct device_reg_2xxx, r))
  1351. void
  1352. qla2x00_beacon_blink(struct scsi_qla_host *vha)
  1353. {
  1354. uint16_t gpio_enable;
  1355. uint16_t gpio_data;
  1356. uint16_t led_color = 0;
  1357. unsigned long flags;
  1358. struct qla_hw_data *ha = vha->hw;
  1359. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1360. if (IS_P3P_TYPE(ha))
  1361. return;
  1362. spin_lock_irqsave(&ha->hardware_lock, flags);
  1363. /* Save the Original GPIOE. */
  1364. if (ha->pio_address) {
  1365. gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
  1366. gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
  1367. } else {
  1368. gpio_enable = RD_REG_WORD(&reg->gpioe);
  1369. gpio_data = RD_REG_WORD(&reg->gpiod);
  1370. }
  1371. /* Set the modified gpio_enable values */
  1372. gpio_enable |= GPIO_LED_MASK;
  1373. if (ha->pio_address) {
  1374. WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
  1375. } else {
  1376. WRT_REG_WORD(&reg->gpioe, gpio_enable);
  1377. RD_REG_WORD(&reg->gpioe);
  1378. }
  1379. qla2x00_flip_colors(ha, &led_color);
  1380. /* Clear out any previously set LED color. */
  1381. gpio_data &= ~GPIO_LED_MASK;
  1382. /* Set the new input LED color to GPIOD. */
  1383. gpio_data |= led_color;
  1384. /* Set the modified gpio_data values */
  1385. if (ha->pio_address) {
  1386. WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
  1387. } else {
  1388. WRT_REG_WORD(&reg->gpiod, gpio_data);
  1389. RD_REG_WORD(&reg->gpiod);
  1390. }
  1391. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1392. }
  1393. int
  1394. qla2x00_beacon_on(struct scsi_qla_host *vha)
  1395. {
  1396. uint16_t gpio_enable;
  1397. uint16_t gpio_data;
  1398. unsigned long flags;
  1399. struct qla_hw_data *ha = vha->hw;
  1400. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1401. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  1402. ha->fw_options[1] |= FO1_DISABLE_GPIO6_7;
  1403. if (qla2x00_set_fw_options(vha, ha->fw_options) != QLA_SUCCESS) {
  1404. ql_log(ql_log_warn, vha, 0x709b,
  1405. "Unable to update fw options (beacon on).\n");
  1406. return QLA_FUNCTION_FAILED;
  1407. }
  1408. /* Turn off LEDs. */
  1409. spin_lock_irqsave(&ha->hardware_lock, flags);
  1410. if (ha->pio_address) {
  1411. gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
  1412. gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
  1413. } else {
  1414. gpio_enable = RD_REG_WORD(&reg->gpioe);
  1415. gpio_data = RD_REG_WORD(&reg->gpiod);
  1416. }
  1417. gpio_enable |= GPIO_LED_MASK;
  1418. /* Set the modified gpio_enable values. */
  1419. if (ha->pio_address) {
  1420. WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
  1421. } else {
  1422. WRT_REG_WORD(&reg->gpioe, gpio_enable);
  1423. RD_REG_WORD(&reg->gpioe);
  1424. }
  1425. /* Clear out previously set LED colour. */
  1426. gpio_data &= ~GPIO_LED_MASK;
  1427. if (ha->pio_address) {
  1428. WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
  1429. } else {
  1430. WRT_REG_WORD(&reg->gpiod, gpio_data);
  1431. RD_REG_WORD(&reg->gpiod);
  1432. }
  1433. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1434. /*
  1435. * Let the per HBA timer kick off the blinking process based on
  1436. * the following flags. No need to do anything else now.
  1437. */
  1438. ha->beacon_blink_led = 1;
  1439. ha->beacon_color_state = 0;
  1440. return QLA_SUCCESS;
  1441. }
  1442. int
  1443. qla2x00_beacon_off(struct scsi_qla_host *vha)
  1444. {
  1445. int rval = QLA_SUCCESS;
  1446. struct qla_hw_data *ha = vha->hw;
  1447. ha->beacon_blink_led = 0;
  1448. /* Set the on flag so when it gets flipped it will be off. */
  1449. if (IS_QLA2322(ha))
  1450. ha->beacon_color_state = QLA_LED_ALL_ON;
  1451. else
  1452. ha->beacon_color_state = QLA_LED_GRN_ON;
  1453. ha->isp_ops->beacon_blink(vha); /* This turns green LED off */
  1454. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  1455. ha->fw_options[1] &= ~FO1_DISABLE_GPIO6_7;
  1456. rval = qla2x00_set_fw_options(vha, ha->fw_options);
  1457. if (rval != QLA_SUCCESS)
  1458. ql_log(ql_log_warn, vha, 0x709c,
  1459. "Unable to update fw options (beacon off).\n");
  1460. return rval;
  1461. }
  1462. static inline void
  1463. qla24xx_flip_colors(struct qla_hw_data *ha, uint16_t *pflags)
  1464. {
  1465. /* Flip all colors. */
  1466. if (ha->beacon_color_state == QLA_LED_ALL_ON) {
  1467. /* Turn off. */
  1468. ha->beacon_color_state = 0;
  1469. *pflags = 0;
  1470. } else {
  1471. /* Turn on. */
  1472. ha->beacon_color_state = QLA_LED_ALL_ON;
  1473. *pflags = GPDX_LED_YELLOW_ON | GPDX_LED_AMBER_ON;
  1474. }
  1475. }
  1476. void
  1477. qla24xx_beacon_blink(struct scsi_qla_host *vha)
  1478. {
  1479. uint16_t led_color = 0;
  1480. uint32_t gpio_data;
  1481. unsigned long flags;
  1482. struct qla_hw_data *ha = vha->hw;
  1483. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1484. /* Save the Original GPIOD. */
  1485. spin_lock_irqsave(&ha->hardware_lock, flags);
  1486. gpio_data = RD_REG_DWORD(&reg->gpiod);
  1487. /* Enable the gpio_data reg for update. */
  1488. gpio_data |= GPDX_LED_UPDATE_MASK;
  1489. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  1490. gpio_data = RD_REG_DWORD(&reg->gpiod);
  1491. /* Set the color bits. */
  1492. qla24xx_flip_colors(ha, &led_color);
  1493. /* Clear out any previously set LED color. */
  1494. gpio_data &= ~GPDX_LED_COLOR_MASK;
  1495. /* Set the new input LED color to GPIOD. */
  1496. gpio_data |= led_color;
  1497. /* Set the modified gpio_data values. */
  1498. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  1499. gpio_data = RD_REG_DWORD(&reg->gpiod);
  1500. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1501. }
  1502. static uint32_t
  1503. qla83xx_select_led_port(struct qla_hw_data *ha)
  1504. {
  1505. uint32_t led_select_value = 0;
  1506. if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
  1507. goto out;
  1508. if (ha->port_no == 0)
  1509. led_select_value = QLA83XX_LED_PORT0;
  1510. else
  1511. led_select_value = QLA83XX_LED_PORT1;
  1512. out:
  1513. return led_select_value;
  1514. }
  1515. void
  1516. qla83xx_beacon_blink(struct scsi_qla_host *vha)
  1517. {
  1518. uint32_t led_select_value;
  1519. struct qla_hw_data *ha = vha->hw;
  1520. uint16_t led_cfg[6];
  1521. uint16_t orig_led_cfg[6];
  1522. uint32_t led_10_value, led_43_value;
  1523. if (!IS_QLA83XX(ha) && !IS_QLA81XX(ha) && !IS_QLA27XX(ha))
  1524. return;
  1525. if (!ha->beacon_blink_led)
  1526. return;
  1527. if (IS_QLA27XX(ha)) {
  1528. qla2x00_write_ram_word(vha, 0x1003, 0x40000230);
  1529. qla2x00_write_ram_word(vha, 0x1004, 0x40000230);
  1530. } else if (IS_QLA2031(ha)) {
  1531. led_select_value = qla83xx_select_led_port(ha);
  1532. qla83xx_wr_reg(vha, led_select_value, 0x40000230);
  1533. qla83xx_wr_reg(vha, led_select_value + 4, 0x40000230);
  1534. } else if (IS_QLA8031(ha)) {
  1535. led_select_value = qla83xx_select_led_port(ha);
  1536. qla83xx_rd_reg(vha, led_select_value, &led_10_value);
  1537. qla83xx_rd_reg(vha, led_select_value + 0x10, &led_43_value);
  1538. qla83xx_wr_reg(vha, led_select_value, 0x01f44000);
  1539. msleep(500);
  1540. qla83xx_wr_reg(vha, led_select_value, 0x400001f4);
  1541. msleep(1000);
  1542. qla83xx_wr_reg(vha, led_select_value, led_10_value);
  1543. qla83xx_wr_reg(vha, led_select_value + 0x10, led_43_value);
  1544. } else if (IS_QLA81XX(ha)) {
  1545. int rval;
  1546. /* Save Current */
  1547. rval = qla81xx_get_led_config(vha, orig_led_cfg);
  1548. /* Do the blink */
  1549. if (rval == QLA_SUCCESS) {
  1550. if (IS_QLA81XX(ha)) {
  1551. led_cfg[0] = 0x4000;
  1552. led_cfg[1] = 0x2000;
  1553. led_cfg[2] = 0;
  1554. led_cfg[3] = 0;
  1555. led_cfg[4] = 0;
  1556. led_cfg[5] = 0;
  1557. } else {
  1558. led_cfg[0] = 0x4000;
  1559. led_cfg[1] = 0x4000;
  1560. led_cfg[2] = 0x4000;
  1561. led_cfg[3] = 0x2000;
  1562. led_cfg[4] = 0;
  1563. led_cfg[5] = 0x2000;
  1564. }
  1565. rval = qla81xx_set_led_config(vha, led_cfg);
  1566. msleep(1000);
  1567. if (IS_QLA81XX(ha)) {
  1568. led_cfg[0] = 0x4000;
  1569. led_cfg[1] = 0x2000;
  1570. led_cfg[2] = 0;
  1571. } else {
  1572. led_cfg[0] = 0x4000;
  1573. led_cfg[1] = 0x2000;
  1574. led_cfg[2] = 0x4000;
  1575. led_cfg[3] = 0x4000;
  1576. led_cfg[4] = 0;
  1577. led_cfg[5] = 0x2000;
  1578. }
  1579. rval = qla81xx_set_led_config(vha, led_cfg);
  1580. }
  1581. /* On exit, restore original (presumes no status change) */
  1582. qla81xx_set_led_config(vha, orig_led_cfg);
  1583. }
  1584. }
  1585. int
  1586. qla24xx_beacon_on(struct scsi_qla_host *vha)
  1587. {
  1588. uint32_t gpio_data;
  1589. unsigned long flags;
  1590. struct qla_hw_data *ha = vha->hw;
  1591. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1592. if (IS_P3P_TYPE(ha))
  1593. return QLA_SUCCESS;
  1594. if (IS_QLA8031(ha) || IS_QLA81XX(ha))
  1595. goto skip_gpio; /* let blink handle it */
  1596. if (ha->beacon_blink_led == 0) {
  1597. /* Enable firmware for update */
  1598. ha->fw_options[1] |= ADD_FO1_DISABLE_GPIO_LED_CTRL;
  1599. if (qla2x00_set_fw_options(vha, ha->fw_options) != QLA_SUCCESS)
  1600. return QLA_FUNCTION_FAILED;
  1601. if (qla2x00_get_fw_options(vha, ha->fw_options) !=
  1602. QLA_SUCCESS) {
  1603. ql_log(ql_log_warn, vha, 0x7009,
  1604. "Unable to update fw options (beacon on).\n");
  1605. return QLA_FUNCTION_FAILED;
  1606. }
  1607. if (IS_QLA2031(ha) || IS_QLA27XX(ha))
  1608. goto skip_gpio;
  1609. spin_lock_irqsave(&ha->hardware_lock, flags);
  1610. gpio_data = RD_REG_DWORD(&reg->gpiod);
  1611. /* Enable the gpio_data reg for update. */
  1612. gpio_data |= GPDX_LED_UPDATE_MASK;
  1613. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  1614. RD_REG_DWORD(&reg->gpiod);
  1615. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1616. }
  1617. /* So all colors blink together. */
  1618. ha->beacon_color_state = 0;
  1619. skip_gpio:
  1620. /* Let the per HBA timer kick off the blinking process. */
  1621. ha->beacon_blink_led = 1;
  1622. return QLA_SUCCESS;
  1623. }
  1624. int
  1625. qla24xx_beacon_off(struct scsi_qla_host *vha)
  1626. {
  1627. uint32_t gpio_data;
  1628. unsigned long flags;
  1629. struct qla_hw_data *ha = vha->hw;
  1630. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1631. if (IS_P3P_TYPE(ha))
  1632. return QLA_SUCCESS;
  1633. ha->beacon_blink_led = 0;
  1634. if (IS_QLA2031(ha) || IS_QLA27XX(ha))
  1635. goto set_fw_options;
  1636. if (IS_QLA8031(ha) || IS_QLA81XX(ha))
  1637. return QLA_SUCCESS;
  1638. ha->beacon_color_state = QLA_LED_ALL_ON;
  1639. ha->isp_ops->beacon_blink(vha); /* Will flip to all off. */
  1640. /* Give control back to firmware. */
  1641. spin_lock_irqsave(&ha->hardware_lock, flags);
  1642. gpio_data = RD_REG_DWORD(&reg->gpiod);
  1643. /* Disable the gpio_data reg for update. */
  1644. gpio_data &= ~GPDX_LED_UPDATE_MASK;
  1645. WRT_REG_DWORD(&reg->gpiod, gpio_data);
  1646. RD_REG_DWORD(&reg->gpiod);
  1647. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1648. set_fw_options:
  1649. ha->fw_options[1] &= ~ADD_FO1_DISABLE_GPIO_LED_CTRL;
  1650. if (qla2x00_set_fw_options(vha, ha->fw_options) != QLA_SUCCESS) {
  1651. ql_log(ql_log_warn, vha, 0x704d,
  1652. "Unable to update fw options (beacon on).\n");
  1653. return QLA_FUNCTION_FAILED;
  1654. }
  1655. if (qla2x00_get_fw_options(vha, ha->fw_options) != QLA_SUCCESS) {
  1656. ql_log(ql_log_warn, vha, 0x704e,
  1657. "Unable to update fw options (beacon on).\n");
  1658. return QLA_FUNCTION_FAILED;
  1659. }
  1660. return QLA_SUCCESS;
  1661. }
  1662. /*
  1663. * Flash support routines
  1664. */
  1665. /**
  1666. * qla2x00_flash_enable() - Setup flash for reading and writing.
  1667. * @ha: HA context
  1668. */
  1669. static void
  1670. qla2x00_flash_enable(struct qla_hw_data *ha)
  1671. {
  1672. uint16_t data;
  1673. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1674. data = RD_REG_WORD(&reg->ctrl_status);
  1675. data |= CSR_FLASH_ENABLE;
  1676. WRT_REG_WORD(&reg->ctrl_status, data);
  1677. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1678. }
  1679. /**
  1680. * qla2x00_flash_disable() - Disable flash and allow RISC to run.
  1681. * @ha: HA context
  1682. */
  1683. static void
  1684. qla2x00_flash_disable(struct qla_hw_data *ha)
  1685. {
  1686. uint16_t data;
  1687. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1688. data = RD_REG_WORD(&reg->ctrl_status);
  1689. data &= ~(CSR_FLASH_ENABLE);
  1690. WRT_REG_WORD(&reg->ctrl_status, data);
  1691. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1692. }
  1693. /**
  1694. * qla2x00_read_flash_byte() - Reads a byte from flash
  1695. * @ha: HA context
  1696. * @addr: Address in flash to read
  1697. *
  1698. * A word is read from the chip, but, only the lower byte is valid.
  1699. *
  1700. * Returns the byte read from flash @addr.
  1701. */
  1702. static uint8_t
  1703. qla2x00_read_flash_byte(struct qla_hw_data *ha, uint32_t addr)
  1704. {
  1705. uint16_t data;
  1706. uint16_t bank_select;
  1707. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1708. bank_select = RD_REG_WORD(&reg->ctrl_status);
  1709. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  1710. /* Specify 64K address range: */
  1711. /* clear out Module Select and Flash Address bits [19:16]. */
  1712. bank_select &= ~0xf8;
  1713. bank_select |= addr >> 12 & 0xf0;
  1714. bank_select |= CSR_FLASH_64K_BANK;
  1715. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1716. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1717. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  1718. data = RD_REG_WORD(&reg->flash_data);
  1719. return (uint8_t)data;
  1720. }
  1721. /* Setup bit 16 of flash address. */
  1722. if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
  1723. bank_select |= CSR_FLASH_64K_BANK;
  1724. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1725. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1726. } else if (((addr & BIT_16) == 0) &&
  1727. (bank_select & CSR_FLASH_64K_BANK)) {
  1728. bank_select &= ~(CSR_FLASH_64K_BANK);
  1729. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1730. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1731. }
  1732. /* Always perform IO mapped accesses to the FLASH registers. */
  1733. if (ha->pio_address) {
  1734. uint16_t data2;
  1735. WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
  1736. do {
  1737. data = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
  1738. barrier();
  1739. cpu_relax();
  1740. data2 = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
  1741. } while (data != data2);
  1742. } else {
  1743. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  1744. data = qla2x00_debounce_register(&reg->flash_data);
  1745. }
  1746. return (uint8_t)data;
  1747. }
  1748. /**
  1749. * qla2x00_write_flash_byte() - Write a byte to flash
  1750. * @ha: HA context
  1751. * @addr: Address in flash to write
  1752. * @data: Data to write
  1753. */
  1754. static void
  1755. qla2x00_write_flash_byte(struct qla_hw_data *ha, uint32_t addr, uint8_t data)
  1756. {
  1757. uint16_t bank_select;
  1758. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1759. bank_select = RD_REG_WORD(&reg->ctrl_status);
  1760. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  1761. /* Specify 64K address range: */
  1762. /* clear out Module Select and Flash Address bits [19:16]. */
  1763. bank_select &= ~0xf8;
  1764. bank_select |= addr >> 12 & 0xf0;
  1765. bank_select |= CSR_FLASH_64K_BANK;
  1766. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1767. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1768. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  1769. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1770. WRT_REG_WORD(&reg->flash_data, (uint16_t)data);
  1771. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1772. return;
  1773. }
  1774. /* Setup bit 16 of flash address. */
  1775. if ((addr & BIT_16) && ((bank_select & CSR_FLASH_64K_BANK) == 0)) {
  1776. bank_select |= CSR_FLASH_64K_BANK;
  1777. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1778. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1779. } else if (((addr & BIT_16) == 0) &&
  1780. (bank_select & CSR_FLASH_64K_BANK)) {
  1781. bank_select &= ~(CSR_FLASH_64K_BANK);
  1782. WRT_REG_WORD(&reg->ctrl_status, bank_select);
  1783. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1784. }
  1785. /* Always perform IO mapped accesses to the FLASH registers. */
  1786. if (ha->pio_address) {
  1787. WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
  1788. WRT_REG_WORD_PIO(PIO_REG(ha, flash_data), (uint16_t)data);
  1789. } else {
  1790. WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
  1791. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1792. WRT_REG_WORD(&reg->flash_data, (uint16_t)data);
  1793. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  1794. }
  1795. }
  1796. /**
  1797. * qla2x00_poll_flash() - Polls flash for completion.
  1798. * @ha: HA context
  1799. * @addr: Address in flash to poll
  1800. * @poll_data: Data to be polled
  1801. * @man_id: Flash manufacturer ID
  1802. * @flash_id: Flash ID
  1803. *
  1804. * This function polls the device until bit 7 of what is read matches data
  1805. * bit 7 or until data bit 5 becomes a 1. If that hapens, the flash ROM timed
  1806. * out (a fatal error). The flash book recommeds reading bit 7 again after
  1807. * reading bit 5 as a 1.
  1808. *
  1809. * Returns 0 on success, else non-zero.
  1810. */
  1811. static int
  1812. qla2x00_poll_flash(struct qla_hw_data *ha, uint32_t addr, uint8_t poll_data,
  1813. uint8_t man_id, uint8_t flash_id)
  1814. {
  1815. int status;
  1816. uint8_t flash_data;
  1817. uint32_t cnt;
  1818. status = 1;
  1819. /* Wait for 30 seconds for command to finish. */
  1820. poll_data &= BIT_7;
  1821. for (cnt = 3000000; cnt; cnt--) {
  1822. flash_data = qla2x00_read_flash_byte(ha, addr);
  1823. if ((flash_data & BIT_7) == poll_data) {
  1824. status = 0;
  1825. break;
  1826. }
  1827. if (man_id != 0x40 && man_id != 0xda) {
  1828. if ((flash_data & BIT_5) && cnt > 2)
  1829. cnt = 2;
  1830. }
  1831. udelay(10);
  1832. barrier();
  1833. cond_resched();
  1834. }
  1835. return status;
  1836. }
  1837. /**
  1838. * qla2x00_program_flash_address() - Programs a flash address
  1839. * @ha: HA context
  1840. * @addr: Address in flash to program
  1841. * @data: Data to be written in flash
  1842. * @man_id: Flash manufacturer ID
  1843. * @flash_id: Flash ID
  1844. *
  1845. * Returns 0 on success, else non-zero.
  1846. */
  1847. static int
  1848. qla2x00_program_flash_address(struct qla_hw_data *ha, uint32_t addr,
  1849. uint8_t data, uint8_t man_id, uint8_t flash_id)
  1850. {
  1851. /* Write Program Command Sequence. */
  1852. if (IS_OEM_001(ha)) {
  1853. qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
  1854. qla2x00_write_flash_byte(ha, 0x555, 0x55);
  1855. qla2x00_write_flash_byte(ha, 0xaaa, 0xa0);
  1856. qla2x00_write_flash_byte(ha, addr, data);
  1857. } else {
  1858. if (man_id == 0xda && flash_id == 0xc1) {
  1859. qla2x00_write_flash_byte(ha, addr, data);
  1860. if (addr & 0x7e)
  1861. return 0;
  1862. } else {
  1863. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1864. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1865. qla2x00_write_flash_byte(ha, 0x5555, 0xa0);
  1866. qla2x00_write_flash_byte(ha, addr, data);
  1867. }
  1868. }
  1869. udelay(150);
  1870. /* Wait for write to complete. */
  1871. return qla2x00_poll_flash(ha, addr, data, man_id, flash_id);
  1872. }
  1873. /**
  1874. * qla2x00_erase_flash() - Erase the flash.
  1875. * @ha: HA context
  1876. * @man_id: Flash manufacturer ID
  1877. * @flash_id: Flash ID
  1878. *
  1879. * Returns 0 on success, else non-zero.
  1880. */
  1881. static int
  1882. qla2x00_erase_flash(struct qla_hw_data *ha, uint8_t man_id, uint8_t flash_id)
  1883. {
  1884. /* Individual Sector Erase Command Sequence */
  1885. if (IS_OEM_001(ha)) {
  1886. qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
  1887. qla2x00_write_flash_byte(ha, 0x555, 0x55);
  1888. qla2x00_write_flash_byte(ha, 0xaaa, 0x80);
  1889. qla2x00_write_flash_byte(ha, 0xaaa, 0xaa);
  1890. qla2x00_write_flash_byte(ha, 0x555, 0x55);
  1891. qla2x00_write_flash_byte(ha, 0xaaa, 0x10);
  1892. } else {
  1893. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1894. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1895. qla2x00_write_flash_byte(ha, 0x5555, 0x80);
  1896. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1897. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1898. qla2x00_write_flash_byte(ha, 0x5555, 0x10);
  1899. }
  1900. udelay(150);
  1901. /* Wait for erase to complete. */
  1902. return qla2x00_poll_flash(ha, 0x00, 0x80, man_id, flash_id);
  1903. }
  1904. /**
  1905. * qla2x00_erase_flash_sector() - Erase a flash sector.
  1906. * @ha: HA context
  1907. * @addr: Flash sector to erase
  1908. * @sec_mask: Sector address mask
  1909. * @man_id: Flash manufacturer ID
  1910. * @flash_id: Flash ID
  1911. *
  1912. * Returns 0 on success, else non-zero.
  1913. */
  1914. static int
  1915. qla2x00_erase_flash_sector(struct qla_hw_data *ha, uint32_t addr,
  1916. uint32_t sec_mask, uint8_t man_id, uint8_t flash_id)
  1917. {
  1918. /* Individual Sector Erase Command Sequence */
  1919. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1920. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1921. qla2x00_write_flash_byte(ha, 0x5555, 0x80);
  1922. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1923. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1924. if (man_id == 0x1f && flash_id == 0x13)
  1925. qla2x00_write_flash_byte(ha, addr & sec_mask, 0x10);
  1926. else
  1927. qla2x00_write_flash_byte(ha, addr & sec_mask, 0x30);
  1928. udelay(150);
  1929. /* Wait for erase to complete. */
  1930. return qla2x00_poll_flash(ha, addr, 0x80, man_id, flash_id);
  1931. }
  1932. /**
  1933. * qla2x00_get_flash_manufacturer() - Read manufacturer ID from flash chip.
  1934. * @man_id: Flash manufacturer ID
  1935. * @flash_id: Flash ID
  1936. */
  1937. static void
  1938. qla2x00_get_flash_manufacturer(struct qla_hw_data *ha, uint8_t *man_id,
  1939. uint8_t *flash_id)
  1940. {
  1941. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1942. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1943. qla2x00_write_flash_byte(ha, 0x5555, 0x90);
  1944. *man_id = qla2x00_read_flash_byte(ha, 0x0000);
  1945. *flash_id = qla2x00_read_flash_byte(ha, 0x0001);
  1946. qla2x00_write_flash_byte(ha, 0x5555, 0xaa);
  1947. qla2x00_write_flash_byte(ha, 0x2aaa, 0x55);
  1948. qla2x00_write_flash_byte(ha, 0x5555, 0xf0);
  1949. }
  1950. static void
  1951. qla2x00_read_flash_data(struct qla_hw_data *ha, uint8_t *tmp_buf,
  1952. uint32_t saddr, uint32_t length)
  1953. {
  1954. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1955. uint32_t midpoint, ilength;
  1956. uint8_t data;
  1957. midpoint = length / 2;
  1958. WRT_REG_WORD(&reg->nvram, 0);
  1959. RD_REG_WORD(&reg->nvram);
  1960. for (ilength = 0; ilength < length; saddr++, ilength++, tmp_buf++) {
  1961. if (ilength == midpoint) {
  1962. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  1963. RD_REG_WORD(&reg->nvram);
  1964. }
  1965. data = qla2x00_read_flash_byte(ha, saddr);
  1966. if (saddr % 100)
  1967. udelay(10);
  1968. *tmp_buf = data;
  1969. cond_resched();
  1970. }
  1971. }
  1972. static inline void
  1973. qla2x00_suspend_hba(struct scsi_qla_host *vha)
  1974. {
  1975. int cnt;
  1976. unsigned long flags;
  1977. struct qla_hw_data *ha = vha->hw;
  1978. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1979. /* Suspend HBA. */
  1980. scsi_block_requests(vha->host);
  1981. ha->isp_ops->disable_intrs(ha);
  1982. set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  1983. /* Pause RISC. */
  1984. spin_lock_irqsave(&ha->hardware_lock, flags);
  1985. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  1986. RD_REG_WORD(&reg->hccr);
  1987. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  1988. for (cnt = 0; cnt < 30000; cnt++) {
  1989. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
  1990. break;
  1991. udelay(100);
  1992. }
  1993. } else {
  1994. udelay(10);
  1995. }
  1996. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1997. }
  1998. static inline void
  1999. qla2x00_resume_hba(struct scsi_qla_host *vha)
  2000. {
  2001. struct qla_hw_data *ha = vha->hw;
  2002. /* Resume HBA. */
  2003. clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  2004. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  2005. qla2xxx_wake_dpc(vha);
  2006. qla2x00_wait_for_chip_reset(vha);
  2007. scsi_unblock_requests(vha->host);
  2008. }
  2009. uint8_t *
  2010. qla2x00_read_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
  2011. uint32_t offset, uint32_t length)
  2012. {
  2013. uint32_t addr, midpoint;
  2014. uint8_t *data;
  2015. struct qla_hw_data *ha = vha->hw;
  2016. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2017. /* Suspend HBA. */
  2018. qla2x00_suspend_hba(vha);
  2019. /* Go with read. */
  2020. midpoint = ha->optrom_size / 2;
  2021. qla2x00_flash_enable(ha);
  2022. WRT_REG_WORD(&reg->nvram, 0);
  2023. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  2024. for (addr = offset, data = buf; addr < length; addr++, data++) {
  2025. if (addr == midpoint) {
  2026. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  2027. RD_REG_WORD(&reg->nvram); /* PCI Posting. */
  2028. }
  2029. *data = qla2x00_read_flash_byte(ha, addr);
  2030. }
  2031. qla2x00_flash_disable(ha);
  2032. /* Resume HBA. */
  2033. qla2x00_resume_hba(vha);
  2034. return buf;
  2035. }
  2036. int
  2037. qla2x00_write_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
  2038. uint32_t offset, uint32_t length)
  2039. {
  2040. int rval;
  2041. uint8_t man_id, flash_id, sec_number, data;
  2042. uint16_t wd;
  2043. uint32_t addr, liter, sec_mask, rest_addr;
  2044. struct qla_hw_data *ha = vha->hw;
  2045. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2046. /* Suspend HBA. */
  2047. qla2x00_suspend_hba(vha);
  2048. rval = QLA_SUCCESS;
  2049. sec_number = 0;
  2050. /* Reset ISP chip. */
  2051. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  2052. pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
  2053. /* Go with write. */
  2054. qla2x00_flash_enable(ha);
  2055. do { /* Loop once to provide quick error exit */
  2056. /* Structure of flash memory based on manufacturer */
  2057. if (IS_OEM_001(ha)) {
  2058. /* OEM variant with special flash part. */
  2059. man_id = flash_id = 0;
  2060. rest_addr = 0xffff;
  2061. sec_mask = 0x10000;
  2062. goto update_flash;
  2063. }
  2064. qla2x00_get_flash_manufacturer(ha, &man_id, &flash_id);
  2065. switch (man_id) {
  2066. case 0x20: /* ST flash. */
  2067. if (flash_id == 0xd2 || flash_id == 0xe3) {
  2068. /*
  2069. * ST m29w008at part - 64kb sector size with
  2070. * 32kb,8kb,8kb,16kb sectors at memory address
  2071. * 0xf0000.
  2072. */
  2073. rest_addr = 0xffff;
  2074. sec_mask = 0x10000;
  2075. break;
  2076. }
  2077. /*
  2078. * ST m29w010b part - 16kb sector size
  2079. * Default to 16kb sectors
  2080. */
  2081. rest_addr = 0x3fff;
  2082. sec_mask = 0x1c000;
  2083. break;
  2084. case 0x40: /* Mostel flash. */
  2085. /* Mostel v29c51001 part - 512 byte sector size. */
  2086. rest_addr = 0x1ff;
  2087. sec_mask = 0x1fe00;
  2088. break;
  2089. case 0xbf: /* SST flash. */
  2090. /* SST39sf10 part - 4kb sector size. */
  2091. rest_addr = 0xfff;
  2092. sec_mask = 0x1f000;
  2093. break;
  2094. case 0xda: /* Winbond flash. */
  2095. /* Winbond W29EE011 part - 256 byte sector size. */
  2096. rest_addr = 0x7f;
  2097. sec_mask = 0x1ff80;
  2098. break;
  2099. case 0xc2: /* Macronix flash. */
  2100. /* 64k sector size. */
  2101. if (flash_id == 0x38 || flash_id == 0x4f) {
  2102. rest_addr = 0xffff;
  2103. sec_mask = 0x10000;
  2104. break;
  2105. }
  2106. /* Fall through... */
  2107. case 0x1f: /* Atmel flash. */
  2108. /* 512k sector size. */
  2109. if (flash_id == 0x13) {
  2110. rest_addr = 0x7fffffff;
  2111. sec_mask = 0x80000000;
  2112. break;
  2113. }
  2114. /* Fall through... */
  2115. case 0x01: /* AMD flash. */
  2116. if (flash_id == 0x38 || flash_id == 0x40 ||
  2117. flash_id == 0x4f) {
  2118. /* Am29LV081 part - 64kb sector size. */
  2119. /* Am29LV002BT part - 64kb sector size. */
  2120. rest_addr = 0xffff;
  2121. sec_mask = 0x10000;
  2122. break;
  2123. } else if (flash_id == 0x3e) {
  2124. /*
  2125. * Am29LV008b part - 64kb sector size with
  2126. * 32kb,8kb,8kb,16kb sector at memory address
  2127. * h0xf0000.
  2128. */
  2129. rest_addr = 0xffff;
  2130. sec_mask = 0x10000;
  2131. break;
  2132. } else if (flash_id == 0x20 || flash_id == 0x6e) {
  2133. /*
  2134. * Am29LV010 part or AM29f010 - 16kb sector
  2135. * size.
  2136. */
  2137. rest_addr = 0x3fff;
  2138. sec_mask = 0x1c000;
  2139. break;
  2140. } else if (flash_id == 0x6d) {
  2141. /* Am29LV001 part - 8kb sector size. */
  2142. rest_addr = 0x1fff;
  2143. sec_mask = 0x1e000;
  2144. break;
  2145. }
  2146. default:
  2147. /* Default to 16 kb sector size. */
  2148. rest_addr = 0x3fff;
  2149. sec_mask = 0x1c000;
  2150. break;
  2151. }
  2152. update_flash:
  2153. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  2154. if (qla2x00_erase_flash(ha, man_id, flash_id)) {
  2155. rval = QLA_FUNCTION_FAILED;
  2156. break;
  2157. }
  2158. }
  2159. for (addr = offset, liter = 0; liter < length; liter++,
  2160. addr++) {
  2161. data = buf[liter];
  2162. /* Are we at the beginning of a sector? */
  2163. if ((addr & rest_addr) == 0) {
  2164. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  2165. if (addr >= 0x10000UL) {
  2166. if (((addr >> 12) & 0xf0) &&
  2167. ((man_id == 0x01 &&
  2168. flash_id == 0x3e) ||
  2169. (man_id == 0x20 &&
  2170. flash_id == 0xd2))) {
  2171. sec_number++;
  2172. if (sec_number == 1) {
  2173. rest_addr =
  2174. 0x7fff;
  2175. sec_mask =
  2176. 0x18000;
  2177. } else if (
  2178. sec_number == 2 ||
  2179. sec_number == 3) {
  2180. rest_addr =
  2181. 0x1fff;
  2182. sec_mask =
  2183. 0x1e000;
  2184. } else if (
  2185. sec_number == 4) {
  2186. rest_addr =
  2187. 0x3fff;
  2188. sec_mask =
  2189. 0x1c000;
  2190. }
  2191. }
  2192. }
  2193. } else if (addr == ha->optrom_size / 2) {
  2194. WRT_REG_WORD(&reg->nvram, NVR_SELECT);
  2195. RD_REG_WORD(&reg->nvram);
  2196. }
  2197. if (flash_id == 0xda && man_id == 0xc1) {
  2198. qla2x00_write_flash_byte(ha, 0x5555,
  2199. 0xaa);
  2200. qla2x00_write_flash_byte(ha, 0x2aaa,
  2201. 0x55);
  2202. qla2x00_write_flash_byte(ha, 0x5555,
  2203. 0xa0);
  2204. } else if (!IS_QLA2322(ha) && !IS_QLA6322(ha)) {
  2205. /* Then erase it */
  2206. if (qla2x00_erase_flash_sector(ha,
  2207. addr, sec_mask, man_id,
  2208. flash_id)) {
  2209. rval = QLA_FUNCTION_FAILED;
  2210. break;
  2211. }
  2212. if (man_id == 0x01 && flash_id == 0x6d)
  2213. sec_number++;
  2214. }
  2215. }
  2216. if (man_id == 0x01 && flash_id == 0x6d) {
  2217. if (sec_number == 1 &&
  2218. addr == (rest_addr - 1)) {
  2219. rest_addr = 0x0fff;
  2220. sec_mask = 0x1f000;
  2221. } else if (sec_number == 3 && (addr & 0x7ffe)) {
  2222. rest_addr = 0x3fff;
  2223. sec_mask = 0x1c000;
  2224. }
  2225. }
  2226. if (qla2x00_program_flash_address(ha, addr, data,
  2227. man_id, flash_id)) {
  2228. rval = QLA_FUNCTION_FAILED;
  2229. break;
  2230. }
  2231. cond_resched();
  2232. }
  2233. } while (0);
  2234. qla2x00_flash_disable(ha);
  2235. /* Resume HBA. */
  2236. qla2x00_resume_hba(vha);
  2237. return rval;
  2238. }
  2239. uint8_t *
  2240. qla24xx_read_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
  2241. uint32_t offset, uint32_t length)
  2242. {
  2243. struct qla_hw_data *ha = vha->hw;
  2244. /* Suspend HBA. */
  2245. scsi_block_requests(vha->host);
  2246. set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  2247. /* Go with read. */
  2248. qla24xx_read_flash_data(vha, (uint32_t *)buf, offset >> 2, length >> 2);
  2249. /* Resume HBA. */
  2250. clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  2251. scsi_unblock_requests(vha->host);
  2252. return buf;
  2253. }
  2254. int
  2255. qla24xx_write_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
  2256. uint32_t offset, uint32_t length)
  2257. {
  2258. int rval;
  2259. struct qla_hw_data *ha = vha->hw;
  2260. /* Suspend HBA. */
  2261. scsi_block_requests(vha->host);
  2262. set_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  2263. /* Go with write. */
  2264. rval = qla24xx_write_flash_data(vha, (uint32_t *)buf, offset >> 2,
  2265. length >> 2);
  2266. clear_bit(MBX_UPDATE_FLASH_ACTIVE, &ha->mbx_cmd_flags);
  2267. scsi_unblock_requests(vha->host);
  2268. return rval;
  2269. }
  2270. uint8_t *
  2271. qla25xx_read_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
  2272. uint32_t offset, uint32_t length)
  2273. {
  2274. int rval;
  2275. dma_addr_t optrom_dma;
  2276. void *optrom;
  2277. uint8_t *pbuf;
  2278. uint32_t faddr, left, burst;
  2279. struct qla_hw_data *ha = vha->hw;
  2280. if (IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
  2281. IS_QLA27XX(ha))
  2282. goto try_fast;
  2283. if (offset & 0xfff)
  2284. goto slow_read;
  2285. if (length < OPTROM_BURST_SIZE)
  2286. goto slow_read;
  2287. try_fast:
  2288. optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
  2289. &optrom_dma, GFP_KERNEL);
  2290. if (!optrom) {
  2291. ql_log(ql_log_warn, vha, 0x00cc,
  2292. "Unable to allocate memory for optrom burst read (%x KB).\n",
  2293. OPTROM_BURST_SIZE / 1024);
  2294. goto slow_read;
  2295. }
  2296. pbuf = buf;
  2297. faddr = offset >> 2;
  2298. left = length >> 2;
  2299. burst = OPTROM_BURST_DWORDS;
  2300. while (left != 0) {
  2301. if (burst > left)
  2302. burst = left;
  2303. rval = qla2x00_dump_ram(vha, optrom_dma,
  2304. flash_data_addr(ha, faddr), burst);
  2305. if (rval) {
  2306. ql_log(ql_log_warn, vha, 0x00f5,
  2307. "Unable to burst-read optrom segment (%x/%x/%llx).\n",
  2308. rval, flash_data_addr(ha, faddr),
  2309. (unsigned long long)optrom_dma);
  2310. ql_log(ql_log_warn, vha, 0x00f6,
  2311. "Reverting to slow-read.\n");
  2312. dma_free_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
  2313. optrom, optrom_dma);
  2314. goto slow_read;
  2315. }
  2316. memcpy(pbuf, optrom, burst * 4);
  2317. left -= burst;
  2318. faddr += burst;
  2319. pbuf += burst * 4;
  2320. }
  2321. dma_free_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE, optrom,
  2322. optrom_dma);
  2323. return buf;
  2324. slow_read:
  2325. return qla24xx_read_optrom_data(vha, buf, offset, length);
  2326. }
  2327. /**
  2328. * qla2x00_get_fcode_version() - Determine an FCODE image's version.
  2329. * @ha: HA context
  2330. * @pcids: Pointer to the FCODE PCI data structure
  2331. *
  2332. * The process of retrieving the FCODE version information is at best
  2333. * described as interesting.
  2334. *
  2335. * Within the first 100h bytes of the image an ASCII string is present
  2336. * which contains several pieces of information including the FCODE
  2337. * version. Unfortunately it seems the only reliable way to retrieve
  2338. * the version is by scanning for another sentinel within the string,
  2339. * the FCODE build date:
  2340. *
  2341. * ... 2.00.02 10/17/02 ...
  2342. *
  2343. * Returns QLA_SUCCESS on successful retrieval of version.
  2344. */
  2345. static void
  2346. qla2x00_get_fcode_version(struct qla_hw_data *ha, uint32_t pcids)
  2347. {
  2348. int ret = QLA_FUNCTION_FAILED;
  2349. uint32_t istart, iend, iter, vend;
  2350. uint8_t do_next, rbyte, *vbyte;
  2351. memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
  2352. /* Skip the PCI data structure. */
  2353. istart = pcids +
  2354. ((qla2x00_read_flash_byte(ha, pcids + 0x0B) << 8) |
  2355. qla2x00_read_flash_byte(ha, pcids + 0x0A));
  2356. iend = istart + 0x100;
  2357. do {
  2358. /* Scan for the sentinel date string...eeewww. */
  2359. do_next = 0;
  2360. iter = istart;
  2361. while ((iter < iend) && !do_next) {
  2362. iter++;
  2363. if (qla2x00_read_flash_byte(ha, iter) == '/') {
  2364. if (qla2x00_read_flash_byte(ha, iter + 2) ==
  2365. '/')
  2366. do_next++;
  2367. else if (qla2x00_read_flash_byte(ha,
  2368. iter + 3) == '/')
  2369. do_next++;
  2370. }
  2371. }
  2372. if (!do_next)
  2373. break;
  2374. /* Backtrack to previous ' ' (space). */
  2375. do_next = 0;
  2376. while ((iter > istart) && !do_next) {
  2377. iter--;
  2378. if (qla2x00_read_flash_byte(ha, iter) == ' ')
  2379. do_next++;
  2380. }
  2381. if (!do_next)
  2382. break;
  2383. /*
  2384. * Mark end of version tag, and find previous ' ' (space) or
  2385. * string length (recent FCODE images -- major hack ahead!!!).
  2386. */
  2387. vend = iter - 1;
  2388. do_next = 0;
  2389. while ((iter > istart) && !do_next) {
  2390. iter--;
  2391. rbyte = qla2x00_read_flash_byte(ha, iter);
  2392. if (rbyte == ' ' || rbyte == 0xd || rbyte == 0x10)
  2393. do_next++;
  2394. }
  2395. if (!do_next)
  2396. break;
  2397. /* Mark beginning of version tag, and copy data. */
  2398. iter++;
  2399. if ((vend - iter) &&
  2400. ((vend - iter) < sizeof(ha->fcode_revision))) {
  2401. vbyte = ha->fcode_revision;
  2402. while (iter <= vend) {
  2403. *vbyte++ = qla2x00_read_flash_byte(ha, iter);
  2404. iter++;
  2405. }
  2406. ret = QLA_SUCCESS;
  2407. }
  2408. } while (0);
  2409. if (ret != QLA_SUCCESS)
  2410. memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
  2411. }
  2412. int
  2413. qla2x00_get_flash_version(scsi_qla_host_t *vha, void *mbuf)
  2414. {
  2415. int ret = QLA_SUCCESS;
  2416. uint8_t code_type, last_image;
  2417. uint32_t pcihdr, pcids;
  2418. uint8_t *dbyte;
  2419. uint16_t *dcode;
  2420. struct qla_hw_data *ha = vha->hw;
  2421. if (!ha->pio_address || !mbuf)
  2422. return QLA_FUNCTION_FAILED;
  2423. memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
  2424. memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
  2425. memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
  2426. memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
  2427. qla2x00_flash_enable(ha);
  2428. /* Begin with first PCI expansion ROM header. */
  2429. pcihdr = 0;
  2430. last_image = 1;
  2431. do {
  2432. /* Verify PCI expansion ROM header. */
  2433. if (qla2x00_read_flash_byte(ha, pcihdr) != 0x55 ||
  2434. qla2x00_read_flash_byte(ha, pcihdr + 0x01) != 0xaa) {
  2435. /* No signature */
  2436. ql_log(ql_log_fatal, vha, 0x0050,
  2437. "No matching ROM signature.\n");
  2438. ret = QLA_FUNCTION_FAILED;
  2439. break;
  2440. }
  2441. /* Locate PCI data structure. */
  2442. pcids = pcihdr +
  2443. ((qla2x00_read_flash_byte(ha, pcihdr + 0x19) << 8) |
  2444. qla2x00_read_flash_byte(ha, pcihdr + 0x18));
  2445. /* Validate signature of PCI data structure. */
  2446. if (qla2x00_read_flash_byte(ha, pcids) != 'P' ||
  2447. qla2x00_read_flash_byte(ha, pcids + 0x1) != 'C' ||
  2448. qla2x00_read_flash_byte(ha, pcids + 0x2) != 'I' ||
  2449. qla2x00_read_flash_byte(ha, pcids + 0x3) != 'R') {
  2450. /* Incorrect header. */
  2451. ql_log(ql_log_fatal, vha, 0x0051,
  2452. "PCI data struct not found pcir_adr=%x.\n", pcids);
  2453. ret = QLA_FUNCTION_FAILED;
  2454. break;
  2455. }
  2456. /* Read version */
  2457. code_type = qla2x00_read_flash_byte(ha, pcids + 0x14);
  2458. switch (code_type) {
  2459. case ROM_CODE_TYPE_BIOS:
  2460. /* Intel x86, PC-AT compatible. */
  2461. ha->bios_revision[0] =
  2462. qla2x00_read_flash_byte(ha, pcids + 0x12);
  2463. ha->bios_revision[1] =
  2464. qla2x00_read_flash_byte(ha, pcids + 0x13);
  2465. ql_dbg(ql_dbg_init, vha, 0x0052,
  2466. "Read BIOS %d.%d.\n",
  2467. ha->bios_revision[1], ha->bios_revision[0]);
  2468. break;
  2469. case ROM_CODE_TYPE_FCODE:
  2470. /* Open Firmware standard for PCI (FCode). */
  2471. /* Eeeewww... */
  2472. qla2x00_get_fcode_version(ha, pcids);
  2473. break;
  2474. case ROM_CODE_TYPE_EFI:
  2475. /* Extensible Firmware Interface (EFI). */
  2476. ha->efi_revision[0] =
  2477. qla2x00_read_flash_byte(ha, pcids + 0x12);
  2478. ha->efi_revision[1] =
  2479. qla2x00_read_flash_byte(ha, pcids + 0x13);
  2480. ql_dbg(ql_dbg_init, vha, 0x0053,
  2481. "Read EFI %d.%d.\n",
  2482. ha->efi_revision[1], ha->efi_revision[0]);
  2483. break;
  2484. default:
  2485. ql_log(ql_log_warn, vha, 0x0054,
  2486. "Unrecognized code type %x at pcids %x.\n",
  2487. code_type, pcids);
  2488. break;
  2489. }
  2490. last_image = qla2x00_read_flash_byte(ha, pcids + 0x15) & BIT_7;
  2491. /* Locate next PCI expansion ROM. */
  2492. pcihdr += ((qla2x00_read_flash_byte(ha, pcids + 0x11) << 8) |
  2493. qla2x00_read_flash_byte(ha, pcids + 0x10)) * 512;
  2494. } while (!last_image);
  2495. if (IS_QLA2322(ha)) {
  2496. /* Read firmware image information. */
  2497. memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
  2498. dbyte = mbuf;
  2499. memset(dbyte, 0, 8);
  2500. dcode = (uint16_t *)dbyte;
  2501. qla2x00_read_flash_data(ha, dbyte, ha->flt_region_fw * 4 + 10,
  2502. 8);
  2503. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010a,
  2504. "Dumping fw "
  2505. "ver from flash:.\n");
  2506. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010b,
  2507. (uint8_t *)dbyte, 8);
  2508. if ((dcode[0] == 0xffff && dcode[1] == 0xffff &&
  2509. dcode[2] == 0xffff && dcode[3] == 0xffff) ||
  2510. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  2511. dcode[3] == 0)) {
  2512. ql_log(ql_log_warn, vha, 0x0057,
  2513. "Unrecognized fw revision at %x.\n",
  2514. ha->flt_region_fw * 4);
  2515. } else {
  2516. /* values are in big endian */
  2517. ha->fw_revision[0] = dbyte[0] << 16 | dbyte[1];
  2518. ha->fw_revision[1] = dbyte[2] << 16 | dbyte[3];
  2519. ha->fw_revision[2] = dbyte[4] << 16 | dbyte[5];
  2520. ql_dbg(ql_dbg_init, vha, 0x0058,
  2521. "FW Version: "
  2522. "%d.%d.%d.\n", ha->fw_revision[0],
  2523. ha->fw_revision[1], ha->fw_revision[2]);
  2524. }
  2525. }
  2526. qla2x00_flash_disable(ha);
  2527. return ret;
  2528. }
  2529. int
  2530. qla82xx_get_flash_version(scsi_qla_host_t *vha, void *mbuf)
  2531. {
  2532. int ret = QLA_SUCCESS;
  2533. uint32_t pcihdr, pcids;
  2534. uint32_t *dcode;
  2535. uint8_t *bcode;
  2536. uint8_t code_type, last_image;
  2537. struct qla_hw_data *ha = vha->hw;
  2538. if (!mbuf)
  2539. return QLA_FUNCTION_FAILED;
  2540. memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
  2541. memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
  2542. memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
  2543. memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
  2544. dcode = mbuf;
  2545. /* Begin with first PCI expansion ROM header. */
  2546. pcihdr = ha->flt_region_boot << 2;
  2547. last_image = 1;
  2548. do {
  2549. /* Verify PCI expansion ROM header. */
  2550. ha->isp_ops->read_optrom(vha, (uint8_t *)dcode, pcihdr,
  2551. 0x20 * 4);
  2552. bcode = mbuf + (pcihdr % 4);
  2553. if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa) {
  2554. /* No signature */
  2555. ql_log(ql_log_fatal, vha, 0x0154,
  2556. "No matching ROM signature.\n");
  2557. ret = QLA_FUNCTION_FAILED;
  2558. break;
  2559. }
  2560. /* Locate PCI data structure. */
  2561. pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]);
  2562. ha->isp_ops->read_optrom(vha, (uint8_t *)dcode, pcids,
  2563. 0x20 * 4);
  2564. bcode = mbuf + (pcihdr % 4);
  2565. /* Validate signature of PCI data structure. */
  2566. if (bcode[0x0] != 'P' || bcode[0x1] != 'C' ||
  2567. bcode[0x2] != 'I' || bcode[0x3] != 'R') {
  2568. /* Incorrect header. */
  2569. ql_log(ql_log_fatal, vha, 0x0155,
  2570. "PCI data struct not found pcir_adr=%x.\n", pcids);
  2571. ret = QLA_FUNCTION_FAILED;
  2572. break;
  2573. }
  2574. /* Read version */
  2575. code_type = bcode[0x14];
  2576. switch (code_type) {
  2577. case ROM_CODE_TYPE_BIOS:
  2578. /* Intel x86, PC-AT compatible. */
  2579. ha->bios_revision[0] = bcode[0x12];
  2580. ha->bios_revision[1] = bcode[0x13];
  2581. ql_dbg(ql_dbg_init, vha, 0x0156,
  2582. "Read BIOS %d.%d.\n",
  2583. ha->bios_revision[1], ha->bios_revision[0]);
  2584. break;
  2585. case ROM_CODE_TYPE_FCODE:
  2586. /* Open Firmware standard for PCI (FCode). */
  2587. ha->fcode_revision[0] = bcode[0x12];
  2588. ha->fcode_revision[1] = bcode[0x13];
  2589. ql_dbg(ql_dbg_init, vha, 0x0157,
  2590. "Read FCODE %d.%d.\n",
  2591. ha->fcode_revision[1], ha->fcode_revision[0]);
  2592. break;
  2593. case ROM_CODE_TYPE_EFI:
  2594. /* Extensible Firmware Interface (EFI). */
  2595. ha->efi_revision[0] = bcode[0x12];
  2596. ha->efi_revision[1] = bcode[0x13];
  2597. ql_dbg(ql_dbg_init, vha, 0x0158,
  2598. "Read EFI %d.%d.\n",
  2599. ha->efi_revision[1], ha->efi_revision[0]);
  2600. break;
  2601. default:
  2602. ql_log(ql_log_warn, vha, 0x0159,
  2603. "Unrecognized code type %x at pcids %x.\n",
  2604. code_type, pcids);
  2605. break;
  2606. }
  2607. last_image = bcode[0x15] & BIT_7;
  2608. /* Locate next PCI expansion ROM. */
  2609. pcihdr += ((bcode[0x11] << 8) | bcode[0x10]) * 512;
  2610. } while (!last_image);
  2611. /* Read firmware image information. */
  2612. memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
  2613. dcode = mbuf;
  2614. ha->isp_ops->read_optrom(vha, (uint8_t *)dcode, ha->flt_region_fw << 2,
  2615. 0x20);
  2616. bcode = mbuf + (pcihdr % 4);
  2617. /* Validate signature of PCI data structure. */
  2618. if (bcode[0x0] == 0x3 && bcode[0x1] == 0x0 &&
  2619. bcode[0x2] == 0x40 && bcode[0x3] == 0x40) {
  2620. ha->fw_revision[0] = bcode[0x4];
  2621. ha->fw_revision[1] = bcode[0x5];
  2622. ha->fw_revision[2] = bcode[0x6];
  2623. ql_dbg(ql_dbg_init, vha, 0x0153,
  2624. "Firmware revision %d.%d.%d\n",
  2625. ha->fw_revision[0], ha->fw_revision[1],
  2626. ha->fw_revision[2]);
  2627. }
  2628. return ret;
  2629. }
  2630. int
  2631. qla24xx_get_flash_version(scsi_qla_host_t *vha, void *mbuf)
  2632. {
  2633. int ret = QLA_SUCCESS;
  2634. uint32_t pcihdr, pcids;
  2635. uint32_t *dcode;
  2636. uint8_t *bcode;
  2637. uint8_t code_type, last_image;
  2638. int i;
  2639. struct qla_hw_data *ha = vha->hw;
  2640. uint32_t faddr = 0;
  2641. pcihdr = pcids = 0;
  2642. if (IS_P3P_TYPE(ha))
  2643. return ret;
  2644. if (!mbuf)
  2645. return QLA_FUNCTION_FAILED;
  2646. memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
  2647. memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
  2648. memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
  2649. memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
  2650. dcode = mbuf;
  2651. pcihdr = ha->flt_region_boot << 2;
  2652. if (IS_QLA27XX(ha) &&
  2653. qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
  2654. pcihdr = ha->flt_region_boot_sec << 2;
  2655. last_image = 1;
  2656. do {
  2657. /* Verify PCI expansion ROM header. */
  2658. qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, 0x20);
  2659. bcode = mbuf + (pcihdr % 4);
  2660. if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa) {
  2661. /* No signature */
  2662. ql_log(ql_log_fatal, vha, 0x0059,
  2663. "No matching ROM signature.\n");
  2664. ret = QLA_FUNCTION_FAILED;
  2665. break;
  2666. }
  2667. /* Locate PCI data structure. */
  2668. pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]);
  2669. qla24xx_read_flash_data(vha, dcode, pcids >> 2, 0x20);
  2670. bcode = mbuf + (pcihdr % 4);
  2671. /* Validate signature of PCI data structure. */
  2672. if (bcode[0x0] != 'P' || bcode[0x1] != 'C' ||
  2673. bcode[0x2] != 'I' || bcode[0x3] != 'R') {
  2674. /* Incorrect header. */
  2675. ql_log(ql_log_fatal, vha, 0x005a,
  2676. "PCI data struct not found pcir_adr=%x.\n", pcids);
  2677. ret = QLA_FUNCTION_FAILED;
  2678. break;
  2679. }
  2680. /* Read version */
  2681. code_type = bcode[0x14];
  2682. switch (code_type) {
  2683. case ROM_CODE_TYPE_BIOS:
  2684. /* Intel x86, PC-AT compatible. */
  2685. ha->bios_revision[0] = bcode[0x12];
  2686. ha->bios_revision[1] = bcode[0x13];
  2687. ql_dbg(ql_dbg_init, vha, 0x005b,
  2688. "Read BIOS %d.%d.\n",
  2689. ha->bios_revision[1], ha->bios_revision[0]);
  2690. break;
  2691. case ROM_CODE_TYPE_FCODE:
  2692. /* Open Firmware standard for PCI (FCode). */
  2693. ha->fcode_revision[0] = bcode[0x12];
  2694. ha->fcode_revision[1] = bcode[0x13];
  2695. ql_dbg(ql_dbg_init, vha, 0x005c,
  2696. "Read FCODE %d.%d.\n",
  2697. ha->fcode_revision[1], ha->fcode_revision[0]);
  2698. break;
  2699. case ROM_CODE_TYPE_EFI:
  2700. /* Extensible Firmware Interface (EFI). */
  2701. ha->efi_revision[0] = bcode[0x12];
  2702. ha->efi_revision[1] = bcode[0x13];
  2703. ql_dbg(ql_dbg_init, vha, 0x005d,
  2704. "Read EFI %d.%d.\n",
  2705. ha->efi_revision[1], ha->efi_revision[0]);
  2706. break;
  2707. default:
  2708. ql_log(ql_log_warn, vha, 0x005e,
  2709. "Unrecognized code type %x at pcids %x.\n",
  2710. code_type, pcids);
  2711. break;
  2712. }
  2713. last_image = bcode[0x15] & BIT_7;
  2714. /* Locate next PCI expansion ROM. */
  2715. pcihdr += ((bcode[0x11] << 8) | bcode[0x10]) * 512;
  2716. } while (!last_image);
  2717. /* Read firmware image information. */
  2718. memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
  2719. dcode = mbuf;
  2720. faddr = ha->flt_region_fw;
  2721. if (IS_QLA27XX(ha) &&
  2722. qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
  2723. faddr = ha->flt_region_fw_sec;
  2724. qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
  2725. for (i = 0; i < 4; i++)
  2726. dcode[i] = be32_to_cpu(dcode[i]);
  2727. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  2728. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  2729. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  2730. dcode[3] == 0)) {
  2731. ql_log(ql_log_warn, vha, 0x005f,
  2732. "Unrecognized fw revision at %x.\n",
  2733. ha->flt_region_fw * 4);
  2734. } else {
  2735. ha->fw_revision[0] = dcode[0];
  2736. ha->fw_revision[1] = dcode[1];
  2737. ha->fw_revision[2] = dcode[2];
  2738. ha->fw_revision[3] = dcode[3];
  2739. ql_dbg(ql_dbg_init, vha, 0x0060,
  2740. "Firmware revision %d.%d.%d (%x).\n",
  2741. ha->fw_revision[0], ha->fw_revision[1],
  2742. ha->fw_revision[2], ha->fw_revision[3]);
  2743. }
  2744. /* Check for golden firmware and get version if available */
  2745. if (!IS_QLA81XX(ha)) {
  2746. /* Golden firmware is not present in non 81XX adapters */
  2747. return ret;
  2748. }
  2749. memset(ha->gold_fw_version, 0, sizeof(ha->gold_fw_version));
  2750. dcode = mbuf;
  2751. ha->isp_ops->read_optrom(vha, (uint8_t *)dcode,
  2752. ha->flt_region_gold_fw << 2, 32);
  2753. if (dcode[4] == 0xFFFFFFFF && dcode[5] == 0xFFFFFFFF &&
  2754. dcode[6] == 0xFFFFFFFF && dcode[7] == 0xFFFFFFFF) {
  2755. ql_log(ql_log_warn, vha, 0x0056,
  2756. "Unrecognized golden fw at 0x%x.\n",
  2757. ha->flt_region_gold_fw * 4);
  2758. return ret;
  2759. }
  2760. for (i = 4; i < 8; i++)
  2761. ha->gold_fw_version[i-4] = be32_to_cpu(dcode[i]);
  2762. return ret;
  2763. }
  2764. static int
  2765. qla2xxx_is_vpd_valid(uint8_t *pos, uint8_t *end)
  2766. {
  2767. if (pos >= end || *pos != 0x82)
  2768. return 0;
  2769. pos += 3 + pos[1];
  2770. if (pos >= end || *pos != 0x90)
  2771. return 0;
  2772. pos += 3 + pos[1];
  2773. if (pos >= end || *pos != 0x78)
  2774. return 0;
  2775. return 1;
  2776. }
  2777. int
  2778. qla2xxx_get_vpd_field(scsi_qla_host_t *vha, char *key, char *str, size_t size)
  2779. {
  2780. struct qla_hw_data *ha = vha->hw;
  2781. uint8_t *pos = ha->vpd;
  2782. uint8_t *end = pos + ha->vpd_size;
  2783. int len = 0;
  2784. if (!IS_FWI2_CAPABLE(ha) || !qla2xxx_is_vpd_valid(pos, end))
  2785. return 0;
  2786. while (pos < end && *pos != 0x78) {
  2787. len = (*pos == 0x82) ? pos[1] : pos[2];
  2788. if (!strncmp(pos, key, strlen(key)))
  2789. break;
  2790. if (*pos != 0x90 && *pos != 0x91)
  2791. pos += len;
  2792. pos += 3;
  2793. }
  2794. if (pos < end - len && *pos != 0x78)
  2795. return scnprintf(str, size, "%.*s", len, pos + 3);
  2796. return 0;
  2797. }
  2798. int
  2799. qla24xx_read_fcp_prio_cfg(scsi_qla_host_t *vha)
  2800. {
  2801. int len, max_len;
  2802. uint32_t fcp_prio_addr;
  2803. struct qla_hw_data *ha = vha->hw;
  2804. if (!ha->fcp_prio_cfg) {
  2805. ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
  2806. if (!ha->fcp_prio_cfg) {
  2807. ql_log(ql_log_warn, vha, 0x00d5,
  2808. "Unable to allocate memory for fcp priority data (%x).\n",
  2809. FCP_PRIO_CFG_SIZE);
  2810. return QLA_FUNCTION_FAILED;
  2811. }
  2812. }
  2813. memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
  2814. fcp_prio_addr = ha->flt_region_fcp_prio;
  2815. /* first read the fcp priority data header from flash */
  2816. ha->isp_ops->read_optrom(vha, (uint8_t *)ha->fcp_prio_cfg,
  2817. fcp_prio_addr << 2, FCP_PRIO_CFG_HDR_SIZE);
  2818. if (!qla24xx_fcp_prio_cfg_valid(vha, ha->fcp_prio_cfg, 0))
  2819. goto fail;
  2820. /* read remaining FCP CMD config data from flash */
  2821. fcp_prio_addr += (FCP_PRIO_CFG_HDR_SIZE >> 2);
  2822. len = ha->fcp_prio_cfg->num_entries * FCP_PRIO_CFG_ENTRY_SIZE;
  2823. max_len = FCP_PRIO_CFG_SIZE - FCP_PRIO_CFG_HDR_SIZE;
  2824. ha->isp_ops->read_optrom(vha, (uint8_t *)&ha->fcp_prio_cfg->entry[0],
  2825. fcp_prio_addr << 2, (len < max_len ? len : max_len));
  2826. /* revalidate the entire FCP priority config data, including entries */
  2827. if (!qla24xx_fcp_prio_cfg_valid(vha, ha->fcp_prio_cfg, 1))
  2828. goto fail;
  2829. ha->flags.fcp_prio_enabled = 1;
  2830. return QLA_SUCCESS;
  2831. fail:
  2832. vfree(ha->fcp_prio_cfg);
  2833. ha->fcp_prio_cfg = NULL;
  2834. return QLA_FUNCTION_FAILED;
  2835. }