qla_sup.c 70 KB

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