qla_sup.c 70 KB

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