qla_sup.c 70 KB

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