qla_sup.c 74 KB

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