qla_sup.c 70 KB

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