qla_init.c 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690
  1. /*
  2. * QLOGIC LINUX SOFTWARE
  3. *
  4. * QLogic ISP2x00 device driver for Linux 2.6.x
  5. * Copyright (C) 2003-2005 QLogic Corporation
  6. * (www.qlogic.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2, or (at your option) any
  11. * later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. */
  19. #include "qla_def.h"
  20. #include <linux/delay.h>
  21. #include <linux/vmalloc.h>
  22. #include <linux/firmware.h>
  23. #include <scsi/scsi_transport_fc.h>
  24. #include "qla_devtbl.h"
  25. /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
  26. #ifndef EXT_IS_LUN_BIT_SET
  27. #define EXT_IS_LUN_BIT_SET(P,L) \
  28. (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
  29. #define EXT_SET_LUN_BIT(P,L) \
  30. ((P)->mask[L/8] |= (0x80 >> (L%8)))
  31. #endif
  32. /*
  33. * QLogic ISP2x00 Hardware Support Function Prototypes.
  34. */
  35. static int qla2x00_isp_firmware(scsi_qla_host_t *);
  36. static void qla2x00_resize_request_q(scsi_qla_host_t *);
  37. static int qla2x00_setup_chip(scsi_qla_host_t *);
  38. static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
  39. static int qla2x00_init_rings(scsi_qla_host_t *);
  40. static int qla2x00_fw_ready(scsi_qla_host_t *);
  41. static int qla2x00_configure_hba(scsi_qla_host_t *);
  42. static int qla2x00_configure_loop(scsi_qla_host_t *);
  43. static int qla2x00_configure_local_loop(scsi_qla_host_t *);
  44. static void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *);
  45. static int qla2x00_configure_fabric(scsi_qla_host_t *);
  46. static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
  47. static int qla2x00_device_resync(scsi_qla_host_t *);
  48. static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
  49. uint16_t *);
  50. static int qla2x00_restart_isp(scsi_qla_host_t *);
  51. /****************************************************************************/
  52. /* QLogic ISP2x00 Hardware Support Functions. */
  53. /****************************************************************************/
  54. /*
  55. * qla2x00_initialize_adapter
  56. * Initialize board.
  57. *
  58. * Input:
  59. * ha = adapter block pointer.
  60. *
  61. * Returns:
  62. * 0 = success
  63. */
  64. int
  65. qla2x00_initialize_adapter(scsi_qla_host_t *ha)
  66. {
  67. int rval;
  68. uint8_t restart_risc = 0;
  69. uint8_t retry;
  70. uint32_t wait_time;
  71. /* Clear adapter flags. */
  72. ha->flags.online = 0;
  73. ha->flags.reset_active = 0;
  74. atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
  75. atomic_set(&ha->loop_state, LOOP_DOWN);
  76. ha->device_flags = 0;
  77. ha->dpc_flags = 0;
  78. ha->flags.management_server_logged_in = 0;
  79. ha->marker_needed = 0;
  80. ha->mbx_flags = 0;
  81. ha->isp_abort_cnt = 0;
  82. ha->beacon_blink_led = 0;
  83. qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
  84. rval = ha->isp_ops.pci_config(ha);
  85. if (rval) {
  86. DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
  87. ha->host_no));
  88. return (rval);
  89. }
  90. ha->isp_ops.reset_chip(ha);
  91. qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
  92. ha->isp_ops.nvram_config(ha);
  93. qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
  94. retry = 10;
  95. /*
  96. * Try to configure the loop.
  97. */
  98. do {
  99. restart_risc = 0;
  100. /* If firmware needs to be loaded */
  101. if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
  102. if ((rval = ha->isp_ops.chip_diag(ha)) == QLA_SUCCESS) {
  103. rval = qla2x00_setup_chip(ha);
  104. }
  105. }
  106. if (rval == QLA_SUCCESS &&
  107. (rval = qla2x00_init_rings(ha)) == QLA_SUCCESS) {
  108. check_fw_ready_again:
  109. /*
  110. * Wait for a successful LIP up to a maximum
  111. * of (in seconds): RISC login timeout value,
  112. * RISC retry count value, and port down retry
  113. * value OR a minimum of 4 seconds OR If no
  114. * cable, only 5 seconds.
  115. */
  116. rval = qla2x00_fw_ready(ha);
  117. if (rval == QLA_SUCCESS) {
  118. clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
  119. /* Issue a marker after FW becomes ready. */
  120. qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
  121. /*
  122. * Wait at most MAX_TARGET RSCNs for a stable
  123. * link.
  124. */
  125. wait_time = 256;
  126. do {
  127. clear_bit(LOOP_RESYNC_NEEDED,
  128. &ha->dpc_flags);
  129. rval = qla2x00_configure_loop(ha);
  130. if (test_and_clear_bit(ISP_ABORT_NEEDED,
  131. &ha->dpc_flags)) {
  132. restart_risc = 1;
  133. break;
  134. }
  135. /*
  136. * If loop state change while we were
  137. * discoverying devices then wait for
  138. * LIP to complete
  139. */
  140. if (atomic_read(&ha->loop_state) ==
  141. LOOP_DOWN && retry--) {
  142. goto check_fw_ready_again;
  143. }
  144. wait_time--;
  145. } while (!atomic_read(&ha->loop_down_timer) &&
  146. retry &&
  147. wait_time &&
  148. (test_bit(LOOP_RESYNC_NEEDED,
  149. &ha->dpc_flags)));
  150. if (wait_time == 0)
  151. rval = QLA_FUNCTION_FAILED;
  152. } else if (ha->device_flags & DFLG_NO_CABLE)
  153. /* If no cable, then all is good. */
  154. rval = QLA_SUCCESS;
  155. }
  156. } while (restart_risc && retry--);
  157. if (rval == QLA_SUCCESS) {
  158. clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
  159. qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
  160. ha->marker_needed = 0;
  161. ha->flags.online = 1;
  162. } else {
  163. DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
  164. }
  165. return (rval);
  166. }
  167. /**
  168. * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
  169. * @ha: HA context
  170. *
  171. * Returns 0 on success.
  172. */
  173. int
  174. qla2100_pci_config(scsi_qla_host_t *ha)
  175. {
  176. uint16_t w, mwi;
  177. unsigned long flags;
  178. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  179. pci_set_master(ha->pdev);
  180. mwi = 0;
  181. if (pci_set_mwi(ha->pdev))
  182. mwi = PCI_COMMAND_INVALIDATE;
  183. pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
  184. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  185. w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  186. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  187. /* Reset expansion ROM address decode enable */
  188. pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
  189. w &= ~PCI_ROM_ADDRESS_ENABLE;
  190. pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
  191. /* Get PCI bus information. */
  192. spin_lock_irqsave(&ha->hardware_lock, flags);
  193. ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
  194. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  195. return QLA_SUCCESS;
  196. }
  197. /**
  198. * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
  199. * @ha: HA context
  200. *
  201. * Returns 0 on success.
  202. */
  203. int
  204. qla2300_pci_config(scsi_qla_host_t *ha)
  205. {
  206. uint16_t w, mwi;
  207. unsigned long flags = 0;
  208. uint32_t cnt;
  209. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  210. pci_set_master(ha->pdev);
  211. mwi = 0;
  212. if (pci_set_mwi(ha->pdev))
  213. mwi = PCI_COMMAND_INVALIDATE;
  214. pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
  215. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  216. w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  217. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  218. w &= ~PCI_COMMAND_INTX_DISABLE;
  219. /*
  220. * If this is a 2300 card and not 2312, reset the
  221. * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
  222. * the 2310 also reports itself as a 2300 so we need to get the
  223. * fb revision level -- a 6 indicates it really is a 2300 and
  224. * not a 2310.
  225. */
  226. if (IS_QLA2300(ha)) {
  227. spin_lock_irqsave(&ha->hardware_lock, flags);
  228. /* Pause RISC. */
  229. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  230. for (cnt = 0; cnt < 30000; cnt++) {
  231. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
  232. break;
  233. udelay(10);
  234. }
  235. /* Select FPM registers. */
  236. WRT_REG_WORD(&reg->ctrl_status, 0x20);
  237. RD_REG_WORD(&reg->ctrl_status);
  238. /* Get the fb rev level */
  239. ha->fb_rev = RD_FB_CMD_REG(ha, reg);
  240. if (ha->fb_rev == FPM_2300)
  241. w &= ~PCI_COMMAND_INVALIDATE;
  242. /* Deselect FPM registers. */
  243. WRT_REG_WORD(&reg->ctrl_status, 0x0);
  244. RD_REG_WORD(&reg->ctrl_status);
  245. /* Release RISC module. */
  246. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  247. for (cnt = 0; cnt < 30000; cnt++) {
  248. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
  249. break;
  250. udelay(10);
  251. }
  252. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  253. }
  254. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  255. pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
  256. /* Reset expansion ROM address decode enable */
  257. pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
  258. w &= ~PCI_ROM_ADDRESS_ENABLE;
  259. pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
  260. /* Get PCI bus information. */
  261. spin_lock_irqsave(&ha->hardware_lock, flags);
  262. ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
  263. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  264. return QLA_SUCCESS;
  265. }
  266. /**
  267. * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
  268. * @ha: HA context
  269. *
  270. * Returns 0 on success.
  271. */
  272. int
  273. qla24xx_pci_config(scsi_qla_host_t *ha)
  274. {
  275. uint16_t w, mwi;
  276. unsigned long flags = 0;
  277. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  278. int pcix_cmd_reg, pcie_dctl_reg;
  279. pci_set_master(ha->pdev);
  280. mwi = 0;
  281. if (pci_set_mwi(ha->pdev))
  282. mwi = PCI_COMMAND_INVALIDATE;
  283. pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
  284. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  285. w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  286. w &= ~PCI_COMMAND_INTX_DISABLE;
  287. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  288. pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
  289. /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
  290. pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
  291. if (pcix_cmd_reg) {
  292. uint16_t pcix_cmd;
  293. pcix_cmd_reg += PCI_X_CMD;
  294. pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
  295. pcix_cmd &= ~PCI_X_CMD_MAX_READ;
  296. pcix_cmd |= 0x0008;
  297. pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
  298. }
  299. /* PCIe -- adjust Maximum Read Request Size (2048). */
  300. pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
  301. if (pcie_dctl_reg) {
  302. uint16_t pcie_dctl;
  303. pcie_dctl_reg += PCI_EXP_DEVCTL;
  304. pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
  305. pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
  306. pcie_dctl |= 0x4000;
  307. pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
  308. }
  309. /* Reset expansion ROM address decode enable */
  310. pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
  311. w &= ~PCI_ROM_ADDRESS_ENABLE;
  312. pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
  313. /* Get PCI bus information. */
  314. spin_lock_irqsave(&ha->hardware_lock, flags);
  315. ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
  316. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  317. return QLA_SUCCESS;
  318. }
  319. /**
  320. * qla2x00_isp_firmware() - Choose firmware image.
  321. * @ha: HA context
  322. *
  323. * Returns 0 on success.
  324. */
  325. static int
  326. qla2x00_isp_firmware(scsi_qla_host_t *ha)
  327. {
  328. int rval;
  329. /* Assume loading risc code */
  330. rval = QLA_FUNCTION_FAILED;
  331. if (ha->flags.disable_risc_code_load) {
  332. DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
  333. ha->host_no));
  334. qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
  335. /* Verify checksum of loaded RISC code. */
  336. rval = qla2x00_verify_checksum(ha,
  337. IS_QLA24XX(ha) || IS_QLA25XX(ha) ? RISC_SADDRESS :
  338. *ha->brd_info->fw_info[0].fwstart);
  339. }
  340. if (rval) {
  341. DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
  342. ha->host_no));
  343. }
  344. return (rval);
  345. }
  346. /**
  347. * qla2x00_reset_chip() - Reset ISP chip.
  348. * @ha: HA context
  349. *
  350. * Returns 0 on success.
  351. */
  352. void
  353. qla2x00_reset_chip(scsi_qla_host_t *ha)
  354. {
  355. unsigned long flags = 0;
  356. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  357. uint32_t cnt;
  358. unsigned long mbx_flags = 0;
  359. uint16_t cmd;
  360. ha->isp_ops.disable_intrs(ha);
  361. spin_lock_irqsave(&ha->hardware_lock, flags);
  362. /* Turn off master enable */
  363. cmd = 0;
  364. pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
  365. cmd &= ~PCI_COMMAND_MASTER;
  366. pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
  367. if (!IS_QLA2100(ha)) {
  368. /* Pause RISC. */
  369. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  370. if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
  371. for (cnt = 0; cnt < 30000; cnt++) {
  372. if ((RD_REG_WORD(&reg->hccr) &
  373. HCCR_RISC_PAUSE) != 0)
  374. break;
  375. udelay(100);
  376. }
  377. } else {
  378. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  379. udelay(10);
  380. }
  381. /* Select FPM registers. */
  382. WRT_REG_WORD(&reg->ctrl_status, 0x20);
  383. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  384. /* FPM Soft Reset. */
  385. WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
  386. RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
  387. /* Toggle Fpm Reset. */
  388. if (!IS_QLA2200(ha)) {
  389. WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
  390. RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
  391. }
  392. /* Select frame buffer registers. */
  393. WRT_REG_WORD(&reg->ctrl_status, 0x10);
  394. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  395. /* Reset frame buffer FIFOs. */
  396. if (IS_QLA2200(ha)) {
  397. WRT_FB_CMD_REG(ha, reg, 0xa000);
  398. RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
  399. } else {
  400. WRT_FB_CMD_REG(ha, reg, 0x00fc);
  401. /* Read back fb_cmd until zero or 3 seconds max */
  402. for (cnt = 0; cnt < 3000; cnt++) {
  403. if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
  404. break;
  405. udelay(100);
  406. }
  407. }
  408. /* Select RISC module registers. */
  409. WRT_REG_WORD(&reg->ctrl_status, 0);
  410. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  411. /* Reset RISC processor. */
  412. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  413. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  414. /* Release RISC processor. */
  415. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  416. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  417. }
  418. WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
  419. WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
  420. /* Reset ISP chip. */
  421. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  422. /* Wait for RISC to recover from reset. */
  423. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  424. /*
  425. * It is necessary to for a delay here since the card doesn't
  426. * respond to PCI reads during a reset. On some architectures
  427. * this will result in an MCA.
  428. */
  429. udelay(20);
  430. for (cnt = 30000; cnt; cnt--) {
  431. if ((RD_REG_WORD(&reg->ctrl_status) &
  432. CSR_ISP_SOFT_RESET) == 0)
  433. break;
  434. udelay(100);
  435. }
  436. } else
  437. udelay(10);
  438. /* Reset RISC processor. */
  439. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  440. WRT_REG_WORD(&reg->semaphore, 0);
  441. /* Release RISC processor. */
  442. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  443. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  444. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  445. for (cnt = 0; cnt < 30000; cnt++) {
  446. if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
  447. spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
  448. if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
  449. if (!(test_bit(ABORT_ISP_ACTIVE,
  450. &ha->dpc_flags)))
  451. spin_unlock_irqrestore(
  452. &ha->mbx_reg_lock, mbx_flags);
  453. break;
  454. }
  455. if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
  456. spin_unlock_irqrestore(&ha->mbx_reg_lock,
  457. mbx_flags);
  458. udelay(100);
  459. }
  460. } else
  461. udelay(100);
  462. /* Turn on master enable */
  463. cmd |= PCI_COMMAND_MASTER;
  464. pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
  465. /* Disable RISC pause on FPM parity error. */
  466. if (!IS_QLA2100(ha)) {
  467. WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
  468. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  469. }
  470. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  471. }
  472. /**
  473. * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
  474. * @ha: HA context
  475. *
  476. * Returns 0 on success.
  477. */
  478. static inline void
  479. qla24xx_reset_risc(scsi_qla_host_t *ha)
  480. {
  481. unsigned long flags = 0;
  482. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  483. uint32_t cnt, d2;
  484. spin_lock_irqsave(&ha->hardware_lock, flags);
  485. /* Reset RISC. */
  486. WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
  487. for (cnt = 0; cnt < 30000; cnt++) {
  488. if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
  489. break;
  490. udelay(10);
  491. }
  492. WRT_REG_DWORD(&reg->ctrl_status,
  493. CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
  494. RD_REG_DWORD(&reg->ctrl_status);
  495. /* Wait for firmware to complete NVRAM accesses. */
  496. udelay(5);
  497. d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
  498. for (cnt = 10000 ; cnt && d2; cnt--) {
  499. udelay(5);
  500. d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
  501. barrier();
  502. }
  503. udelay(20);
  504. d2 = RD_REG_DWORD(&reg->ctrl_status);
  505. for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
  506. udelay(5);
  507. d2 = RD_REG_DWORD(&reg->ctrl_status);
  508. barrier();
  509. }
  510. WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
  511. RD_REG_DWORD(&reg->hccr);
  512. WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  513. RD_REG_DWORD(&reg->hccr);
  514. WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
  515. RD_REG_DWORD(&reg->hccr);
  516. d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
  517. for (cnt = 6000000 ; cnt && d2; cnt--) {
  518. udelay(5);
  519. d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
  520. barrier();
  521. }
  522. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  523. }
  524. /**
  525. * qla24xx_reset_chip() - Reset ISP24xx chip.
  526. * @ha: HA context
  527. *
  528. * Returns 0 on success.
  529. */
  530. void
  531. qla24xx_reset_chip(scsi_qla_host_t *ha)
  532. {
  533. ha->isp_ops.disable_intrs(ha);
  534. /* Perform RISC reset. */
  535. qla24xx_reset_risc(ha);
  536. }
  537. /**
  538. * qla2x00_chip_diag() - Test chip for proper operation.
  539. * @ha: HA context
  540. *
  541. * Returns 0 on success.
  542. */
  543. int
  544. qla2x00_chip_diag(scsi_qla_host_t *ha)
  545. {
  546. int rval;
  547. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  548. unsigned long flags = 0;
  549. uint16_t data;
  550. uint32_t cnt;
  551. uint16_t mb[5];
  552. /* Assume a failed state */
  553. rval = QLA_FUNCTION_FAILED;
  554. DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
  555. ha->host_no, (u_long)&reg->flash_address));
  556. spin_lock_irqsave(&ha->hardware_lock, flags);
  557. /* Reset ISP chip. */
  558. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  559. /*
  560. * We need to have a delay here since the card will not respond while
  561. * in reset causing an MCA on some architectures.
  562. */
  563. udelay(20);
  564. data = qla2x00_debounce_register(&reg->ctrl_status);
  565. for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
  566. udelay(5);
  567. data = RD_REG_WORD(&reg->ctrl_status);
  568. barrier();
  569. }
  570. if (!cnt)
  571. goto chip_diag_failed;
  572. DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
  573. ha->host_no));
  574. /* Reset RISC processor. */
  575. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  576. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  577. /* Workaround for QLA2312 PCI parity error */
  578. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  579. data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
  580. for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
  581. udelay(5);
  582. data = RD_MAILBOX_REG(ha, reg, 0);
  583. barrier();
  584. }
  585. } else
  586. udelay(10);
  587. if (!cnt)
  588. goto chip_diag_failed;
  589. /* Check product ID of chip */
  590. DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
  591. mb[1] = RD_MAILBOX_REG(ha, reg, 1);
  592. mb[2] = RD_MAILBOX_REG(ha, reg, 2);
  593. mb[3] = RD_MAILBOX_REG(ha, reg, 3);
  594. mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
  595. if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
  596. mb[3] != PROD_ID_3) {
  597. qla_printk(KERN_WARNING, ha,
  598. "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
  599. goto chip_diag_failed;
  600. }
  601. ha->product_id[0] = mb[1];
  602. ha->product_id[1] = mb[2];
  603. ha->product_id[2] = mb[3];
  604. ha->product_id[3] = mb[4];
  605. /* Adjust fw RISC transfer size */
  606. if (ha->request_q_length > 1024)
  607. ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
  608. else
  609. ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
  610. ha->request_q_length;
  611. if (IS_QLA2200(ha) &&
  612. RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
  613. /* Limit firmware transfer size with a 2200A */
  614. DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
  615. ha->host_no));
  616. ha->fw_transfer_size = 128;
  617. }
  618. /* Wrap Incoming Mailboxes Test. */
  619. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  620. DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
  621. rval = qla2x00_mbx_reg_test(ha);
  622. if (rval) {
  623. DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
  624. ha->host_no));
  625. qla_printk(KERN_WARNING, ha,
  626. "Failed mailbox send register test\n");
  627. }
  628. else {
  629. /* Flag a successful rval */
  630. rval = QLA_SUCCESS;
  631. }
  632. spin_lock_irqsave(&ha->hardware_lock, flags);
  633. chip_diag_failed:
  634. if (rval)
  635. DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
  636. "****\n", ha->host_no));
  637. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  638. return (rval);
  639. }
  640. /**
  641. * qla24xx_chip_diag() - Test ISP24xx for proper operation.
  642. * @ha: HA context
  643. *
  644. * Returns 0 on success.
  645. */
  646. int
  647. qla24xx_chip_diag(scsi_qla_host_t *ha)
  648. {
  649. int rval;
  650. /* Perform RISC reset. */
  651. qla24xx_reset_risc(ha);
  652. ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
  653. rval = qla2x00_mbx_reg_test(ha);
  654. if (rval) {
  655. DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
  656. ha->host_no));
  657. qla_printk(KERN_WARNING, ha,
  658. "Failed mailbox send register test\n");
  659. } else {
  660. /* Flag a successful rval */
  661. rval = QLA_SUCCESS;
  662. }
  663. return rval;
  664. }
  665. static void
  666. qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
  667. {
  668. ha->fw_dumped = 0;
  669. ha->fw_dump24_len = sizeof(struct qla24xx_fw_dump);
  670. ha->fw_dump24_len += (ha->fw_memory_size - 0x100000) * sizeof(uint32_t);
  671. ha->fw_dump24 = vmalloc(ha->fw_dump24_len);
  672. if (ha->fw_dump24)
  673. qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware "
  674. "dump...\n", ha->fw_dump24_len / 1024);
  675. else
  676. qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
  677. "firmware dump!!!\n", ha->fw_dump24_len / 1024);
  678. }
  679. /**
  680. * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
  681. * @ha: HA context
  682. *
  683. * Returns 0 on success.
  684. */
  685. static void
  686. qla2x00_resize_request_q(scsi_qla_host_t *ha)
  687. {
  688. int rval;
  689. uint16_t fw_iocb_cnt = 0;
  690. uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
  691. dma_addr_t request_dma;
  692. request_t *request_ring;
  693. /* Valid only on recent ISPs. */
  694. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  695. return;
  696. if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
  697. qla2x00_alloc_fw_dump(ha);
  698. /* Retrieve IOCB counts available to the firmware. */
  699. rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
  700. if (rval)
  701. return;
  702. /* No point in continuing if current settings are sufficient. */
  703. if (fw_iocb_cnt < 1024)
  704. return;
  705. if (ha->request_q_length >= request_q_length)
  706. return;
  707. /* Attempt to claim larger area for request queue. */
  708. request_ring = dma_alloc_coherent(&ha->pdev->dev,
  709. (request_q_length + 1) * sizeof(request_t), &request_dma,
  710. GFP_KERNEL);
  711. if (request_ring == NULL)
  712. return;
  713. /* Resize successful, report extensions. */
  714. qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
  715. (ha->fw_memory_size + 1) / 1024);
  716. qla_printk(KERN_INFO, ha, "Resizing request queue depth "
  717. "(%d -> %d)...\n", ha->request_q_length, request_q_length);
  718. /* Clear old allocations. */
  719. dma_free_coherent(&ha->pdev->dev,
  720. (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
  721. ha->request_dma);
  722. /* Begin using larger queue. */
  723. ha->request_q_length = request_q_length;
  724. ha->request_ring = request_ring;
  725. ha->request_dma = request_dma;
  726. }
  727. /**
  728. * qla2x00_setup_chip() - Load and start RISC firmware.
  729. * @ha: HA context
  730. *
  731. * Returns 0 on success.
  732. */
  733. static int
  734. qla2x00_setup_chip(scsi_qla_host_t *ha)
  735. {
  736. int rval;
  737. uint32_t srisc_address = 0;
  738. /* Load firmware sequences */
  739. rval = ha->isp_ops.load_risc(ha, &srisc_address);
  740. if (rval == QLA_SUCCESS) {
  741. DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
  742. "code.\n", ha->host_no));
  743. rval = qla2x00_verify_checksum(ha, srisc_address);
  744. if (rval == QLA_SUCCESS) {
  745. /* Start firmware execution. */
  746. DEBUG(printk("scsi(%ld): Checksum OK, start "
  747. "firmware.\n", ha->host_no));
  748. rval = qla2x00_execute_fw(ha, srisc_address);
  749. /* Retrieve firmware information. */
  750. if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
  751. qla2x00_get_fw_version(ha,
  752. &ha->fw_major_version,
  753. &ha->fw_minor_version,
  754. &ha->fw_subminor_version,
  755. &ha->fw_attributes, &ha->fw_memory_size);
  756. qla2x00_resize_request_q(ha);
  757. }
  758. } else {
  759. DEBUG2(printk(KERN_INFO
  760. "scsi(%ld): ISP Firmware failed checksum.\n",
  761. ha->host_no));
  762. }
  763. }
  764. if (rval) {
  765. DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
  766. ha->host_no));
  767. }
  768. return (rval);
  769. }
  770. /**
  771. * qla2x00_init_response_q_entries() - Initializes response queue entries.
  772. * @ha: HA context
  773. *
  774. * Beginning of request ring has initialization control block already built
  775. * by nvram config routine.
  776. *
  777. * Returns 0 on success.
  778. */
  779. static void
  780. qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
  781. {
  782. uint16_t cnt;
  783. response_t *pkt;
  784. pkt = ha->response_ring_ptr;
  785. for (cnt = 0; cnt < ha->response_q_length; cnt++) {
  786. pkt->signature = RESPONSE_PROCESSED;
  787. pkt++;
  788. }
  789. }
  790. /**
  791. * qla2x00_update_fw_options() - Read and process firmware options.
  792. * @ha: HA context
  793. *
  794. * Returns 0 on success.
  795. */
  796. void
  797. qla2x00_update_fw_options(scsi_qla_host_t *ha)
  798. {
  799. uint16_t swing, emphasis, tx_sens, rx_sens;
  800. memset(ha->fw_options, 0, sizeof(ha->fw_options));
  801. qla2x00_get_fw_options(ha, ha->fw_options);
  802. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  803. return;
  804. /* Serial Link options. */
  805. DEBUG3(printk("scsi(%ld): Serial link options:\n",
  806. ha->host_no));
  807. DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
  808. sizeof(ha->fw_seriallink_options)));
  809. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  810. if (ha->fw_seriallink_options[3] & BIT_2) {
  811. ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
  812. /* 1G settings */
  813. swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
  814. emphasis = (ha->fw_seriallink_options[2] &
  815. (BIT_4 | BIT_3)) >> 3;
  816. tx_sens = ha->fw_seriallink_options[0] &
  817. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  818. rx_sens = (ha->fw_seriallink_options[0] &
  819. (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
  820. ha->fw_options[10] = (emphasis << 14) | (swing << 8);
  821. if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  822. if (rx_sens == 0x0)
  823. rx_sens = 0x3;
  824. ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
  825. } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
  826. ha->fw_options[10] |= BIT_5 |
  827. ((rx_sens & (BIT_1 | BIT_0)) << 2) |
  828. (tx_sens & (BIT_1 | BIT_0));
  829. /* 2G settings */
  830. swing = (ha->fw_seriallink_options[2] &
  831. (BIT_7 | BIT_6 | BIT_5)) >> 5;
  832. emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
  833. tx_sens = ha->fw_seriallink_options[1] &
  834. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  835. rx_sens = (ha->fw_seriallink_options[1] &
  836. (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
  837. ha->fw_options[11] = (emphasis << 14) | (swing << 8);
  838. if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  839. if (rx_sens == 0x0)
  840. rx_sens = 0x3;
  841. ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
  842. } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
  843. ha->fw_options[11] |= BIT_5 |
  844. ((rx_sens & (BIT_1 | BIT_0)) << 2) |
  845. (tx_sens & (BIT_1 | BIT_0));
  846. }
  847. /* FCP2 options. */
  848. /* Return command IOCBs without waiting for an ABTS to complete. */
  849. ha->fw_options[3] |= BIT_13;
  850. /* LED scheme. */
  851. if (ha->flags.enable_led_scheme)
  852. ha->fw_options[2] |= BIT_12;
  853. /* Update firmware options. */
  854. qla2x00_set_fw_options(ha, ha->fw_options);
  855. }
  856. void
  857. qla24xx_update_fw_options(scsi_qla_host_t *ha)
  858. {
  859. int rval;
  860. /* Update Serial Link options. */
  861. if ((ha->fw_seriallink_options24[0] & BIT_0) == 0)
  862. return;
  863. rval = qla2x00_set_serdes_params(ha, ha->fw_seriallink_options24[1],
  864. ha->fw_seriallink_options24[2], ha->fw_seriallink_options24[3]);
  865. if (rval != QLA_SUCCESS) {
  866. qla_printk(KERN_WARNING, ha,
  867. "Unable to update Serial Link options (%x).\n", rval);
  868. }
  869. }
  870. void
  871. qla2x00_config_rings(struct scsi_qla_host *ha)
  872. {
  873. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  874. /* Setup ring parameters in initialization control block. */
  875. ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
  876. ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
  877. ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
  878. ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
  879. ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
  880. ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
  881. ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
  882. ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
  883. WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
  884. WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
  885. WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
  886. WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
  887. RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
  888. }
  889. void
  890. qla24xx_config_rings(struct scsi_qla_host *ha)
  891. {
  892. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  893. struct init_cb_24xx *icb;
  894. /* Setup ring parameters in initialization control block. */
  895. icb = (struct init_cb_24xx *)ha->init_cb;
  896. icb->request_q_outpointer = __constant_cpu_to_le16(0);
  897. icb->response_q_inpointer = __constant_cpu_to_le16(0);
  898. icb->request_q_length = cpu_to_le16(ha->request_q_length);
  899. icb->response_q_length = cpu_to_le16(ha->response_q_length);
  900. icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
  901. icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
  902. icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
  903. icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
  904. WRT_REG_DWORD(&reg->req_q_in, 0);
  905. WRT_REG_DWORD(&reg->req_q_out, 0);
  906. WRT_REG_DWORD(&reg->rsp_q_in, 0);
  907. WRT_REG_DWORD(&reg->rsp_q_out, 0);
  908. RD_REG_DWORD(&reg->rsp_q_out);
  909. }
  910. /**
  911. * qla2x00_init_rings() - Initializes firmware.
  912. * @ha: HA context
  913. *
  914. * Beginning of request ring has initialization control block already built
  915. * by nvram config routine.
  916. *
  917. * Returns 0 on success.
  918. */
  919. static int
  920. qla2x00_init_rings(scsi_qla_host_t *ha)
  921. {
  922. int rval;
  923. unsigned long flags = 0;
  924. int cnt;
  925. spin_lock_irqsave(&ha->hardware_lock, flags);
  926. /* Clear outstanding commands array. */
  927. for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
  928. ha->outstanding_cmds[cnt] = NULL;
  929. ha->current_outstanding_cmd = 0;
  930. /* Clear RSCN queue. */
  931. ha->rscn_in_ptr = 0;
  932. ha->rscn_out_ptr = 0;
  933. /* Initialize firmware. */
  934. ha->request_ring_ptr = ha->request_ring;
  935. ha->req_ring_index = 0;
  936. ha->req_q_cnt = ha->request_q_length;
  937. ha->response_ring_ptr = ha->response_ring;
  938. ha->rsp_ring_index = 0;
  939. /* Initialize response queue entries */
  940. qla2x00_init_response_q_entries(ha);
  941. ha->isp_ops.config_rings(ha);
  942. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  943. /* Update any ISP specific firmware options before initialization. */
  944. ha->isp_ops.update_fw_options(ha);
  945. DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
  946. rval = qla2x00_init_firmware(ha, ha->init_cb_size);
  947. if (rval) {
  948. DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
  949. ha->host_no));
  950. } else {
  951. DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
  952. ha->host_no));
  953. }
  954. return (rval);
  955. }
  956. /**
  957. * qla2x00_fw_ready() - Waits for firmware ready.
  958. * @ha: HA context
  959. *
  960. * Returns 0 on success.
  961. */
  962. static int
  963. qla2x00_fw_ready(scsi_qla_host_t *ha)
  964. {
  965. int rval;
  966. unsigned long wtime, mtime;
  967. uint16_t min_wait; /* Minimum wait time if loop is down */
  968. uint16_t wait_time; /* Wait time if loop is coming ready */
  969. uint16_t fw_state;
  970. rval = QLA_SUCCESS;
  971. /* 20 seconds for loop down. */
  972. min_wait = 20;
  973. /*
  974. * Firmware should take at most one RATOV to login, plus 5 seconds for
  975. * our own processing.
  976. */
  977. if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
  978. wait_time = min_wait;
  979. }
  980. /* Min wait time if loop down */
  981. mtime = jiffies + (min_wait * HZ);
  982. /* wait time before firmware ready */
  983. wtime = jiffies + (wait_time * HZ);
  984. /* Wait for ISP to finish LIP */
  985. if (!ha->flags.init_done)
  986. qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
  987. DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
  988. ha->host_no));
  989. do {
  990. rval = qla2x00_get_firmware_state(ha, &fw_state);
  991. if (rval == QLA_SUCCESS) {
  992. if (fw_state < FSTATE_LOSS_OF_SYNC) {
  993. ha->device_flags &= ~DFLG_NO_CABLE;
  994. }
  995. if (fw_state == FSTATE_READY) {
  996. DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
  997. ha->host_no));
  998. qla2x00_get_retry_cnt(ha, &ha->retry_count,
  999. &ha->login_timeout, &ha->r_a_tov);
  1000. rval = QLA_SUCCESS;
  1001. break;
  1002. }
  1003. rval = QLA_FUNCTION_FAILED;
  1004. if (atomic_read(&ha->loop_down_timer) &&
  1005. (fw_state >= FSTATE_LOSS_OF_SYNC ||
  1006. fw_state == FSTATE_WAIT_AL_PA)) {
  1007. /* Loop down. Timeout on min_wait for states
  1008. * other than Wait for Login.
  1009. */
  1010. if (time_after_eq(jiffies, mtime)) {
  1011. qla_printk(KERN_INFO, ha,
  1012. "Cable is unplugged...\n");
  1013. ha->device_flags |= DFLG_NO_CABLE;
  1014. break;
  1015. }
  1016. }
  1017. } else {
  1018. /* Mailbox cmd failed. Timeout on min_wait. */
  1019. if (time_after_eq(jiffies, mtime))
  1020. break;
  1021. }
  1022. if (time_after_eq(jiffies, wtime))
  1023. break;
  1024. /* Delay for a while */
  1025. msleep(500);
  1026. DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
  1027. ha->host_no, fw_state, jiffies));
  1028. } while (1);
  1029. DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
  1030. ha->host_no, fw_state, jiffies));
  1031. if (rval) {
  1032. DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
  1033. ha->host_no));
  1034. }
  1035. return (rval);
  1036. }
  1037. /*
  1038. * qla2x00_configure_hba
  1039. * Setup adapter context.
  1040. *
  1041. * Input:
  1042. * ha = adapter state pointer.
  1043. *
  1044. * Returns:
  1045. * 0 = success
  1046. *
  1047. * Context:
  1048. * Kernel context.
  1049. */
  1050. static int
  1051. qla2x00_configure_hba(scsi_qla_host_t *ha)
  1052. {
  1053. int rval;
  1054. uint16_t loop_id;
  1055. uint16_t topo;
  1056. uint8_t al_pa;
  1057. uint8_t area;
  1058. uint8_t domain;
  1059. char connect_type[22];
  1060. /* Get host addresses. */
  1061. rval = qla2x00_get_adapter_id(ha,
  1062. &loop_id, &al_pa, &area, &domain, &topo);
  1063. if (rval != QLA_SUCCESS) {
  1064. qla_printk(KERN_WARNING, ha,
  1065. "ERROR -- Unable to get host loop ID.\n");
  1066. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  1067. return (rval);
  1068. }
  1069. if (topo == 4) {
  1070. qla_printk(KERN_INFO, ha,
  1071. "Cannot get topology - retrying.\n");
  1072. return (QLA_FUNCTION_FAILED);
  1073. }
  1074. ha->loop_id = loop_id;
  1075. /* initialize */
  1076. ha->min_external_loopid = SNS_FIRST_LOOP_ID;
  1077. ha->operating_mode = LOOP;
  1078. switch (topo) {
  1079. case 0:
  1080. DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
  1081. ha->host_no));
  1082. ha->current_topology = ISP_CFG_NL;
  1083. strcpy(connect_type, "(Loop)");
  1084. break;
  1085. case 1:
  1086. DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
  1087. ha->host_no));
  1088. ha->current_topology = ISP_CFG_FL;
  1089. strcpy(connect_type, "(FL_Port)");
  1090. break;
  1091. case 2:
  1092. DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
  1093. ha->host_no));
  1094. ha->operating_mode = P2P;
  1095. ha->current_topology = ISP_CFG_N;
  1096. strcpy(connect_type, "(N_Port-to-N_Port)");
  1097. break;
  1098. case 3:
  1099. DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
  1100. ha->host_no));
  1101. ha->operating_mode = P2P;
  1102. ha->current_topology = ISP_CFG_F;
  1103. strcpy(connect_type, "(F_Port)");
  1104. break;
  1105. default:
  1106. DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
  1107. "Using NL.\n",
  1108. ha->host_no, topo));
  1109. ha->current_topology = ISP_CFG_NL;
  1110. strcpy(connect_type, "(Loop)");
  1111. break;
  1112. }
  1113. /* Save Host port and loop ID. */
  1114. /* byte order - Big Endian */
  1115. ha->d_id.b.domain = domain;
  1116. ha->d_id.b.area = area;
  1117. ha->d_id.b.al_pa = al_pa;
  1118. if (!ha->flags.init_done)
  1119. qla_printk(KERN_INFO, ha,
  1120. "Topology - %s, Host Loop address 0x%x\n",
  1121. connect_type, ha->loop_id);
  1122. if (rval) {
  1123. DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
  1124. } else {
  1125. DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
  1126. }
  1127. return(rval);
  1128. }
  1129. /*
  1130. * NVRAM configuration for ISP 2xxx
  1131. *
  1132. * Input:
  1133. * ha = adapter block pointer.
  1134. *
  1135. * Output:
  1136. * initialization control block in response_ring
  1137. * host adapters parameters in host adapter block
  1138. *
  1139. * Returns:
  1140. * 0 = success.
  1141. */
  1142. int
  1143. qla2x00_nvram_config(scsi_qla_host_t *ha)
  1144. {
  1145. int rval;
  1146. uint8_t chksum = 0;
  1147. uint16_t cnt;
  1148. uint8_t *dptr1, *dptr2;
  1149. init_cb_t *icb = ha->init_cb;
  1150. nvram_t *nv = (nvram_t *)ha->request_ring;
  1151. uint8_t *ptr = (uint8_t *)ha->request_ring;
  1152. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1153. uint8_t timer_mode;
  1154. rval = QLA_SUCCESS;
  1155. /* Determine NVRAM starting address. */
  1156. ha->nvram_size = sizeof(nvram_t);
  1157. ha->nvram_base = 0;
  1158. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
  1159. if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
  1160. ha->nvram_base = 0x80;
  1161. /* Get NVRAM data and calculate checksum. */
  1162. ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
  1163. for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
  1164. chksum += *ptr++;
  1165. DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
  1166. DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
  1167. ha->nvram_size));
  1168. /* Bad NVRAM data, set defaults parameters. */
  1169. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
  1170. nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
  1171. /* Reset NVRAM data. */
  1172. qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
  1173. "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
  1174. nv->nvram_version);
  1175. qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
  1176. "invalid -- WWPN) defaults.\n");
  1177. /*
  1178. * Set default initialization control block.
  1179. */
  1180. memset(nv, 0, ha->nvram_size);
  1181. nv->parameter_block_version = ICB_VERSION;
  1182. if (IS_QLA23XX(ha)) {
  1183. nv->firmware_options[0] = BIT_2 | BIT_1;
  1184. nv->firmware_options[1] = BIT_7 | BIT_5;
  1185. nv->add_firmware_options[0] = BIT_5;
  1186. nv->add_firmware_options[1] = BIT_5 | BIT_4;
  1187. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  1188. nv->special_options[1] = BIT_7;
  1189. } else if (IS_QLA2200(ha)) {
  1190. nv->firmware_options[0] = BIT_2 | BIT_1;
  1191. nv->firmware_options[1] = BIT_7 | BIT_5;
  1192. nv->add_firmware_options[0] = BIT_5;
  1193. nv->add_firmware_options[1] = BIT_5 | BIT_4;
  1194. nv->frame_payload_size = __constant_cpu_to_le16(1024);
  1195. } else if (IS_QLA2100(ha)) {
  1196. nv->firmware_options[0] = BIT_3 | BIT_1;
  1197. nv->firmware_options[1] = BIT_5;
  1198. nv->frame_payload_size = __constant_cpu_to_le16(1024);
  1199. }
  1200. nv->max_iocb_allocation = __constant_cpu_to_le16(256);
  1201. nv->execution_throttle = __constant_cpu_to_le16(16);
  1202. nv->retry_count = 8;
  1203. nv->retry_delay = 1;
  1204. nv->port_name[0] = 33;
  1205. nv->port_name[3] = 224;
  1206. nv->port_name[4] = 139;
  1207. nv->login_timeout = 4;
  1208. /*
  1209. * Set default host adapter parameters
  1210. */
  1211. nv->host_p[1] = BIT_2;
  1212. nv->reset_delay = 5;
  1213. nv->port_down_retry_count = 8;
  1214. nv->max_luns_per_target = __constant_cpu_to_le16(8);
  1215. nv->link_down_timeout = 60;
  1216. rval = 1;
  1217. }
  1218. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  1219. /*
  1220. * The SN2 does not provide BIOS emulation which means you can't change
  1221. * potentially bogus BIOS settings. Force the use of default settings
  1222. * for link rate and frame size. Hope that the rest of the settings
  1223. * are valid.
  1224. */
  1225. if (ia64_platform_is("sn2")) {
  1226. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  1227. if (IS_QLA23XX(ha))
  1228. nv->special_options[1] = BIT_7;
  1229. }
  1230. #endif
  1231. /* Reset Initialization control block */
  1232. memset(icb, 0, ha->init_cb_size);
  1233. /*
  1234. * Setup driver NVRAM options.
  1235. */
  1236. nv->firmware_options[0] |= (BIT_6 | BIT_1);
  1237. nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
  1238. nv->firmware_options[1] |= (BIT_5 | BIT_0);
  1239. nv->firmware_options[1] &= ~BIT_4;
  1240. if (IS_QLA23XX(ha)) {
  1241. nv->firmware_options[0] |= BIT_2;
  1242. nv->firmware_options[0] &= ~BIT_3;
  1243. nv->add_firmware_options[1] |= BIT_5 | BIT_4;
  1244. if (IS_QLA2300(ha)) {
  1245. if (ha->fb_rev == FPM_2310) {
  1246. strcpy(ha->model_number, "QLA2310");
  1247. } else {
  1248. strcpy(ha->model_number, "QLA2300");
  1249. }
  1250. } else {
  1251. if (rval == 0 &&
  1252. memcmp(nv->model_number, BINZERO,
  1253. sizeof(nv->model_number)) != 0) {
  1254. char *st, *en;
  1255. strncpy(ha->model_number, nv->model_number,
  1256. sizeof(nv->model_number));
  1257. st = en = ha->model_number;
  1258. en += sizeof(nv->model_number) - 1;
  1259. while (en > st) {
  1260. if (*en != 0x20 && *en != 0x00)
  1261. break;
  1262. *en-- = '\0';
  1263. }
  1264. } else {
  1265. uint16_t index;
  1266. index = (ha->pdev->subsystem_device & 0xff);
  1267. if (index < QLA_MODEL_NAMES) {
  1268. strcpy(ha->model_number,
  1269. qla2x00_model_name[index]);
  1270. ha->model_desc =
  1271. qla2x00_model_desc[index];
  1272. } else {
  1273. strcpy(ha->model_number, "QLA23xx");
  1274. }
  1275. }
  1276. }
  1277. } else if (IS_QLA2200(ha)) {
  1278. nv->firmware_options[0] |= BIT_2;
  1279. /*
  1280. * 'Point-to-point preferred, else loop' is not a safe
  1281. * connection mode setting.
  1282. */
  1283. if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
  1284. (BIT_5 | BIT_4)) {
  1285. /* Force 'loop preferred, else point-to-point'. */
  1286. nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
  1287. nv->add_firmware_options[0] |= BIT_5;
  1288. }
  1289. strcpy(ha->model_number, "QLA22xx");
  1290. } else /*if (IS_QLA2100(ha))*/ {
  1291. strcpy(ha->model_number, "QLA2100");
  1292. }
  1293. /*
  1294. * Copy over NVRAM RISC parameter block to initialization control block.
  1295. */
  1296. dptr1 = (uint8_t *)icb;
  1297. dptr2 = (uint8_t *)&nv->parameter_block_version;
  1298. cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
  1299. while (cnt--)
  1300. *dptr1++ = *dptr2++;
  1301. /* Copy 2nd half. */
  1302. dptr1 = (uint8_t *)icb->add_firmware_options;
  1303. cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
  1304. while (cnt--)
  1305. *dptr1++ = *dptr2++;
  1306. /* Prepare nodename */
  1307. if ((icb->firmware_options[1] & BIT_6) == 0) {
  1308. /*
  1309. * Firmware will apply the following mask if the nodename was
  1310. * not provided.
  1311. */
  1312. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  1313. icb->node_name[0] &= 0xF0;
  1314. }
  1315. /*
  1316. * Set host adapter parameters.
  1317. */
  1318. ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
  1319. /* Always load RISC code on non ISP2[12]00 chips. */
  1320. if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
  1321. ha->flags.disable_risc_code_load = 0;
  1322. ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
  1323. ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
  1324. ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
  1325. ha->flags.enable_led_scheme = ((nv->efi_parameters & BIT_3) ? 1 : 0);
  1326. ha->operating_mode =
  1327. (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
  1328. memcpy(ha->fw_seriallink_options, nv->seriallink_options,
  1329. sizeof(ha->fw_seriallink_options));
  1330. /* save HBA serial number */
  1331. ha->serial0 = icb->port_name[5];
  1332. ha->serial1 = icb->port_name[6];
  1333. ha->serial2 = icb->port_name[7];
  1334. ha->node_name = icb->node_name;
  1335. ha->port_name = icb->port_name;
  1336. icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  1337. ha->retry_count = nv->retry_count;
  1338. /* Set minimum login_timeout to 4 seconds. */
  1339. if (nv->login_timeout < ql2xlogintimeout)
  1340. nv->login_timeout = ql2xlogintimeout;
  1341. if (nv->login_timeout < 4)
  1342. nv->login_timeout = 4;
  1343. ha->login_timeout = nv->login_timeout;
  1344. icb->login_timeout = nv->login_timeout;
  1345. /* Set minimum RATOV to 200 tenths of a second. */
  1346. ha->r_a_tov = 200;
  1347. ha->loop_reset_delay = nv->reset_delay;
  1348. /* Link Down Timeout = 0:
  1349. *
  1350. * When Port Down timer expires we will start returning
  1351. * I/O's to OS with "DID_NO_CONNECT".
  1352. *
  1353. * Link Down Timeout != 0:
  1354. *
  1355. * The driver waits for the link to come up after link down
  1356. * before returning I/Os to OS with "DID_NO_CONNECT".
  1357. */
  1358. if (nv->link_down_timeout == 0) {
  1359. ha->loop_down_abort_time =
  1360. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  1361. } else {
  1362. ha->link_down_timeout = nv->link_down_timeout;
  1363. ha->loop_down_abort_time =
  1364. (LOOP_DOWN_TIME - ha->link_down_timeout);
  1365. }
  1366. /*
  1367. * Need enough time to try and get the port back.
  1368. */
  1369. ha->port_down_retry_count = nv->port_down_retry_count;
  1370. if (qlport_down_retry)
  1371. ha->port_down_retry_count = qlport_down_retry;
  1372. /* Set login_retry_count */
  1373. ha->login_retry_count = nv->retry_count;
  1374. if (ha->port_down_retry_count == nv->port_down_retry_count &&
  1375. ha->port_down_retry_count > 3)
  1376. ha->login_retry_count = ha->port_down_retry_count;
  1377. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  1378. ha->login_retry_count = ha->port_down_retry_count;
  1379. if (ql2xloginretrycount)
  1380. ha->login_retry_count = ql2xloginretrycount;
  1381. icb->lun_enables = __constant_cpu_to_le16(0);
  1382. icb->command_resource_count = 0;
  1383. icb->immediate_notify_resource_count = 0;
  1384. icb->timeout = __constant_cpu_to_le16(0);
  1385. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  1386. /* Enable RIO */
  1387. icb->firmware_options[0] &= ~BIT_3;
  1388. icb->add_firmware_options[0] &=
  1389. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1390. icb->add_firmware_options[0] |= BIT_2;
  1391. icb->response_accumulation_timer = 3;
  1392. icb->interrupt_delay_timer = 5;
  1393. ha->flags.process_response_queue = 1;
  1394. } else {
  1395. /* Enable ZIO -- Support mode 5 only. */
  1396. timer_mode = icb->add_firmware_options[0] &
  1397. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1398. icb->add_firmware_options[0] &=
  1399. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1400. if (ql2xenablezio)
  1401. timer_mode = BIT_2 | BIT_0;
  1402. if (timer_mode == (BIT_2 | BIT_0)) {
  1403. DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay "
  1404. "(%d).\n", ha->host_no, ql2xintrdelaytimer));
  1405. qla_printk(KERN_INFO, ha,
  1406. "ZIO enabled; timer delay (%d).\n",
  1407. ql2xintrdelaytimer);
  1408. icb->add_firmware_options[0] |= timer_mode;
  1409. icb->interrupt_delay_timer = ql2xintrdelaytimer;
  1410. ha->flags.process_response_queue = 1;
  1411. }
  1412. }
  1413. if (rval) {
  1414. DEBUG2_3(printk(KERN_WARNING
  1415. "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
  1416. }
  1417. return (rval);
  1418. }
  1419. /**
  1420. * qla2x00_alloc_fcport() - Allocate a generic fcport.
  1421. * @ha: HA context
  1422. * @flags: allocation flags
  1423. *
  1424. * Returns a pointer to the allocated fcport, or NULL, if none available.
  1425. */
  1426. fc_port_t *
  1427. qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags)
  1428. {
  1429. fc_port_t *fcport;
  1430. fcport = kmalloc(sizeof(fc_port_t), flags);
  1431. if (fcport == NULL)
  1432. return (fcport);
  1433. /* Setup fcport template structure. */
  1434. memset(fcport, 0, sizeof (fc_port_t));
  1435. fcport->ha = ha;
  1436. fcport->port_type = FCT_UNKNOWN;
  1437. fcport->loop_id = FC_NO_LOOP_ID;
  1438. fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
  1439. atomic_set(&fcport->state, FCS_UNCONFIGURED);
  1440. fcport->flags = FCF_RLC_SUPPORT;
  1441. return (fcport);
  1442. }
  1443. /*
  1444. * qla2x00_configure_loop
  1445. * Updates Fibre Channel Device Database with what is actually on loop.
  1446. *
  1447. * Input:
  1448. * ha = adapter block pointer.
  1449. *
  1450. * Returns:
  1451. * 0 = success.
  1452. * 1 = error.
  1453. * 2 = database was full and device was not configured.
  1454. */
  1455. static int
  1456. qla2x00_configure_loop(scsi_qla_host_t *ha)
  1457. {
  1458. int rval;
  1459. unsigned long flags, save_flags;
  1460. rval = QLA_SUCCESS;
  1461. /* Get Initiator ID */
  1462. if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
  1463. rval = qla2x00_configure_hba(ha);
  1464. if (rval != QLA_SUCCESS) {
  1465. DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
  1466. ha->host_no));
  1467. return (rval);
  1468. }
  1469. }
  1470. save_flags = flags = ha->dpc_flags;
  1471. DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
  1472. ha->host_no, flags));
  1473. /*
  1474. * If we have both an RSCN and PORT UPDATE pending then handle them
  1475. * both at the same time.
  1476. */
  1477. clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
  1478. clear_bit(RSCN_UPDATE, &ha->dpc_flags);
  1479. /* Determine what we need to do */
  1480. if (ha->current_topology == ISP_CFG_FL &&
  1481. (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
  1482. ha->flags.rscn_queue_overflow = 1;
  1483. set_bit(RSCN_UPDATE, &flags);
  1484. } else if (ha->current_topology == ISP_CFG_F &&
  1485. (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
  1486. ha->flags.rscn_queue_overflow = 1;
  1487. set_bit(RSCN_UPDATE, &flags);
  1488. clear_bit(LOCAL_LOOP_UPDATE, &flags);
  1489. } else if (!ha->flags.online ||
  1490. (test_bit(ABORT_ISP_ACTIVE, &flags))) {
  1491. ha->flags.rscn_queue_overflow = 1;
  1492. set_bit(RSCN_UPDATE, &flags);
  1493. set_bit(LOCAL_LOOP_UPDATE, &flags);
  1494. }
  1495. if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
  1496. if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
  1497. rval = QLA_FUNCTION_FAILED;
  1498. } else {
  1499. rval = qla2x00_configure_local_loop(ha);
  1500. }
  1501. }
  1502. if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
  1503. if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
  1504. rval = QLA_FUNCTION_FAILED;
  1505. } else {
  1506. rval = qla2x00_configure_fabric(ha);
  1507. }
  1508. }
  1509. if (rval == QLA_SUCCESS) {
  1510. if (atomic_read(&ha->loop_down_timer) ||
  1511. test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
  1512. rval = QLA_FUNCTION_FAILED;
  1513. } else {
  1514. atomic_set(&ha->loop_state, LOOP_READY);
  1515. DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
  1516. }
  1517. }
  1518. if (rval) {
  1519. DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
  1520. __func__, ha->host_no));
  1521. } else {
  1522. DEBUG3(printk("%s: exiting normally\n", __func__));
  1523. }
  1524. /* Restore state if a resync event occured during processing */
  1525. if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
  1526. if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
  1527. set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
  1528. if (test_bit(RSCN_UPDATE, &save_flags))
  1529. set_bit(RSCN_UPDATE, &ha->dpc_flags);
  1530. }
  1531. return (rval);
  1532. }
  1533. /*
  1534. * qla2x00_configure_local_loop
  1535. * Updates Fibre Channel Device Database with local loop devices.
  1536. *
  1537. * Input:
  1538. * ha = adapter block pointer.
  1539. *
  1540. * Returns:
  1541. * 0 = success.
  1542. */
  1543. static int
  1544. qla2x00_configure_local_loop(scsi_qla_host_t *ha)
  1545. {
  1546. int rval, rval2;
  1547. int found_devs;
  1548. int found;
  1549. fc_port_t *fcport, *new_fcport;
  1550. uint16_t index;
  1551. uint16_t entries;
  1552. char *id_iter;
  1553. uint16_t loop_id;
  1554. uint8_t domain, area, al_pa;
  1555. found_devs = 0;
  1556. new_fcport = NULL;
  1557. entries = MAX_FIBRE_DEVICES;
  1558. DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
  1559. DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
  1560. /* Get list of logged in devices. */
  1561. memset(ha->gid_list, 0, GID_LIST_SIZE);
  1562. rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
  1563. &entries);
  1564. if (rval != QLA_SUCCESS)
  1565. goto cleanup_allocation;
  1566. DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
  1567. ha->host_no, entries));
  1568. DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
  1569. entries * sizeof(struct gid_list_info)));
  1570. /* Allocate temporary fcport for any new fcports discovered. */
  1571. new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
  1572. if (new_fcport == NULL) {
  1573. rval = QLA_MEMORY_ALLOC_FAILED;
  1574. goto cleanup_allocation;
  1575. }
  1576. new_fcport->flags &= ~FCF_FABRIC_DEVICE;
  1577. /*
  1578. * Mark local devices that were present with FCF_DEVICE_LOST for now.
  1579. */
  1580. list_for_each_entry(fcport, &ha->fcports, list) {
  1581. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  1582. fcport->port_type != FCT_BROADCAST &&
  1583. (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  1584. DEBUG(printk("scsi(%ld): Marking port lost, "
  1585. "loop_id=0x%04x\n",
  1586. ha->host_no, fcport->loop_id));
  1587. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1588. fcport->flags &= ~FCF_FARP_DONE;
  1589. }
  1590. }
  1591. /* Add devices to port list. */
  1592. id_iter = (char *)ha->gid_list;
  1593. for (index = 0; index < entries; index++) {
  1594. domain = ((struct gid_list_info *)id_iter)->domain;
  1595. area = ((struct gid_list_info *)id_iter)->area;
  1596. al_pa = ((struct gid_list_info *)id_iter)->al_pa;
  1597. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  1598. loop_id = (uint16_t)
  1599. ((struct gid_list_info *)id_iter)->loop_id_2100;
  1600. else
  1601. loop_id = le16_to_cpu(
  1602. ((struct gid_list_info *)id_iter)->loop_id);
  1603. id_iter += ha->gid_list_info_size;
  1604. /* Bypass reserved domain fields. */
  1605. if ((domain & 0xf0) == 0xf0)
  1606. continue;
  1607. /* Bypass if not same domain and area of adapter. */
  1608. if (area != ha->d_id.b.area || domain != ha->d_id.b.domain)
  1609. continue;
  1610. /* Bypass invalid local loop ID. */
  1611. if (loop_id > LAST_LOCAL_LOOP_ID)
  1612. continue;
  1613. /* Fill in member data. */
  1614. new_fcport->d_id.b.domain = domain;
  1615. new_fcport->d_id.b.area = area;
  1616. new_fcport->d_id.b.al_pa = al_pa;
  1617. new_fcport->loop_id = loop_id;
  1618. rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
  1619. if (rval2 != QLA_SUCCESS) {
  1620. DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
  1621. "information -- get_port_database=%x, "
  1622. "loop_id=0x%04x\n",
  1623. ha->host_no, rval2, new_fcport->loop_id));
  1624. continue;
  1625. }
  1626. /* Check for matching device in port list. */
  1627. found = 0;
  1628. fcport = NULL;
  1629. list_for_each_entry(fcport, &ha->fcports, list) {
  1630. if (memcmp(new_fcport->port_name, fcport->port_name,
  1631. WWN_SIZE))
  1632. continue;
  1633. fcport->flags &= ~(FCF_FABRIC_DEVICE |
  1634. FCF_PERSISTENT_BOUND);
  1635. fcport->loop_id = new_fcport->loop_id;
  1636. fcport->port_type = new_fcport->port_type;
  1637. fcport->d_id.b24 = new_fcport->d_id.b24;
  1638. memcpy(fcport->node_name, new_fcport->node_name,
  1639. WWN_SIZE);
  1640. found++;
  1641. break;
  1642. }
  1643. if (!found) {
  1644. /* New device, add to fcports list. */
  1645. new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
  1646. list_add_tail(&new_fcport->list, &ha->fcports);
  1647. /* Allocate a new replacement fcport. */
  1648. fcport = new_fcport;
  1649. new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
  1650. if (new_fcport == NULL) {
  1651. rval = QLA_MEMORY_ALLOC_FAILED;
  1652. goto cleanup_allocation;
  1653. }
  1654. new_fcport->flags &= ~FCF_FABRIC_DEVICE;
  1655. }
  1656. qla2x00_update_fcport(ha, fcport);
  1657. found_devs++;
  1658. }
  1659. cleanup_allocation:
  1660. if (new_fcport)
  1661. kfree(new_fcport);
  1662. if (rval != QLA_SUCCESS) {
  1663. DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
  1664. "rval=%x\n", ha->host_no, rval));
  1665. }
  1666. if (found_devs) {
  1667. ha->device_flags |= DFLG_LOCAL_DEVICES;
  1668. ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
  1669. }
  1670. return (rval);
  1671. }
  1672. static void
  1673. qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
  1674. {
  1675. fc_port_t *fcport;
  1676. qla2x00_mark_all_devices_lost(ha);
  1677. list_for_each_entry(fcport, &ha->fcports, list) {
  1678. if (fcport->port_type != FCT_TARGET)
  1679. continue;
  1680. qla2x00_update_fcport(ha, fcport);
  1681. }
  1682. }
  1683. /*
  1684. * qla2x00_update_fcport
  1685. * Updates device on list.
  1686. *
  1687. * Input:
  1688. * ha = adapter block pointer.
  1689. * fcport = port structure pointer.
  1690. *
  1691. * Return:
  1692. * 0 - Success
  1693. * BIT_0 - error
  1694. *
  1695. * Context:
  1696. * Kernel context.
  1697. */
  1698. static void
  1699. qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
  1700. {
  1701. uint16_t index;
  1702. unsigned long flags;
  1703. srb_t *sp;
  1704. fcport->ha = ha;
  1705. fcport->login_retry = 0;
  1706. fcport->port_login_retry_count = ha->port_down_retry_count *
  1707. PORT_RETRY_TIME;
  1708. atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
  1709. PORT_RETRY_TIME);
  1710. fcport->flags &= ~FCF_LOGIN_NEEDED;
  1711. /*
  1712. * Check for outstanding cmd on tape Bypass LUN discovery if active
  1713. * command on tape.
  1714. */
  1715. if (fcport->flags & FCF_TAPE_PRESENT) {
  1716. spin_lock_irqsave(&ha->hardware_lock, flags);
  1717. for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
  1718. fc_port_t *sfcp;
  1719. if ((sp = ha->outstanding_cmds[index]) != 0) {
  1720. sfcp = sp->fcport;
  1721. if (sfcp == fcport) {
  1722. atomic_set(&fcport->state, FCS_ONLINE);
  1723. spin_unlock_irqrestore(
  1724. &ha->hardware_lock, flags);
  1725. return;
  1726. }
  1727. }
  1728. }
  1729. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1730. }
  1731. if (fcport->port_type == FCT_INITIATOR ||
  1732. fcport->port_type == FCT_BROADCAST)
  1733. fcport->device_type = TYPE_PROCESSOR;
  1734. atomic_set(&fcport->state, FCS_ONLINE);
  1735. if (ha->flags.init_done)
  1736. qla2x00_reg_remote_port(ha, fcport);
  1737. }
  1738. void
  1739. qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
  1740. {
  1741. struct fc_rport_identifiers rport_ids;
  1742. struct fc_rport *rport;
  1743. if (fcport->rport) {
  1744. fc_remote_port_unblock(fcport->rport);
  1745. return;
  1746. }
  1747. rport_ids.node_name = be64_to_cpu(*(uint64_t *)fcport->node_name);
  1748. rport_ids.port_name = be64_to_cpu(*(uint64_t *)fcport->port_name);
  1749. rport_ids.port_id = fcport->d_id.b.domain << 16 |
  1750. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1751. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  1752. if (fcport->port_type == FCT_INITIATOR)
  1753. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  1754. if (fcport->port_type == FCT_TARGET)
  1755. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  1756. fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids);
  1757. if (!rport)
  1758. qla_printk(KERN_WARNING, ha,
  1759. "Unable to allocate fc remote port!\n");
  1760. if (rport->scsi_target_id != -1 &&
  1761. rport->scsi_target_id < ha->host->max_id)
  1762. fcport->os_target_id = rport->scsi_target_id;
  1763. rport->dd_data = fcport;
  1764. }
  1765. /*
  1766. * qla2x00_configure_fabric
  1767. * Setup SNS devices with loop ID's.
  1768. *
  1769. * Input:
  1770. * ha = adapter block pointer.
  1771. *
  1772. * Returns:
  1773. * 0 = success.
  1774. * BIT_0 = error
  1775. */
  1776. static int
  1777. qla2x00_configure_fabric(scsi_qla_host_t *ha)
  1778. {
  1779. int rval, rval2;
  1780. fc_port_t *fcport, *fcptemp;
  1781. uint16_t next_loopid;
  1782. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1783. uint16_t loop_id;
  1784. LIST_HEAD(new_fcports);
  1785. /* If FL port exists, then SNS is present */
  1786. if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
  1787. loop_id = NPH_F_PORT;
  1788. else
  1789. loop_id = SNS_FL_PORT;
  1790. rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
  1791. if (rval != QLA_SUCCESS) {
  1792. DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
  1793. "Port\n", ha->host_no));
  1794. ha->device_flags &= ~SWITCH_FOUND;
  1795. return (QLA_SUCCESS);
  1796. }
  1797. /* Mark devices that need re-synchronization. */
  1798. rval2 = qla2x00_device_resync(ha);
  1799. if (rval2 == QLA_RSCNS_HANDLED) {
  1800. /* No point doing the scan, just continue. */
  1801. return (QLA_SUCCESS);
  1802. }
  1803. do {
  1804. /* Ensure we are logged into the SNS. */
  1805. if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
  1806. loop_id = NPH_SNS;
  1807. else
  1808. loop_id = SIMPLE_NAME_SERVER;
  1809. ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
  1810. 0xfc, mb, BIT_1 | BIT_0);
  1811. if (mb[0] != MBS_COMMAND_COMPLETE) {
  1812. DEBUG2(qla_printk(KERN_INFO, ha,
  1813. "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
  1814. "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
  1815. mb[0], mb[1], mb[2], mb[6], mb[7]));
  1816. return (QLA_SUCCESS);
  1817. }
  1818. if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
  1819. if (qla2x00_rft_id(ha)) {
  1820. /* EMPTY */
  1821. DEBUG2(printk("scsi(%ld): Register FC-4 "
  1822. "TYPE failed.\n", ha->host_no));
  1823. }
  1824. if (qla2x00_rff_id(ha)) {
  1825. /* EMPTY */
  1826. DEBUG2(printk("scsi(%ld): Register FC-4 "
  1827. "Features failed.\n", ha->host_no));
  1828. }
  1829. if (qla2x00_rnn_id(ha)) {
  1830. /* EMPTY */
  1831. DEBUG2(printk("scsi(%ld): Register Node Name "
  1832. "failed.\n", ha->host_no));
  1833. } else if (qla2x00_rsnn_nn(ha)) {
  1834. /* EMPTY */
  1835. DEBUG2(printk("scsi(%ld): Register Symbolic "
  1836. "Node Name failed.\n", ha->host_no));
  1837. }
  1838. }
  1839. rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
  1840. if (rval != QLA_SUCCESS)
  1841. break;
  1842. /*
  1843. * Logout all previous fabric devices marked lost, except
  1844. * tape devices.
  1845. */
  1846. list_for_each_entry(fcport, &ha->fcports, list) {
  1847. if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
  1848. break;
  1849. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
  1850. continue;
  1851. if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
  1852. qla2x00_mark_device_lost(ha, fcport,
  1853. ql2xplogiabsentdevice);
  1854. if (fcport->loop_id != FC_NO_LOOP_ID &&
  1855. (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
  1856. fcport->port_type != FCT_INITIATOR &&
  1857. fcport->port_type != FCT_BROADCAST) {
  1858. ha->isp_ops.fabric_logout(ha,
  1859. fcport->loop_id,
  1860. fcport->d_id.b.domain,
  1861. fcport->d_id.b.area,
  1862. fcport->d_id.b.al_pa);
  1863. fcport->loop_id = FC_NO_LOOP_ID;
  1864. }
  1865. }
  1866. }
  1867. /* Starting free loop ID. */
  1868. next_loopid = ha->min_external_loopid;
  1869. /*
  1870. * Scan through our port list and login entries that need to be
  1871. * logged in.
  1872. */
  1873. list_for_each_entry(fcport, &ha->fcports, list) {
  1874. if (atomic_read(&ha->loop_down_timer) ||
  1875. test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
  1876. break;
  1877. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
  1878. (fcport->flags & FCF_LOGIN_NEEDED) == 0)
  1879. continue;
  1880. if (fcport->loop_id == FC_NO_LOOP_ID) {
  1881. fcport->loop_id = next_loopid;
  1882. rval = qla2x00_find_new_loop_id(ha, fcport);
  1883. if (rval != QLA_SUCCESS) {
  1884. /* Ran out of IDs to use */
  1885. break;
  1886. }
  1887. }
  1888. /* Login and update database */
  1889. qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
  1890. }
  1891. /* Exit if out of loop IDs. */
  1892. if (rval != QLA_SUCCESS) {
  1893. break;
  1894. }
  1895. /*
  1896. * Login and add the new devices to our port list.
  1897. */
  1898. list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
  1899. if (atomic_read(&ha->loop_down_timer) ||
  1900. test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
  1901. break;
  1902. /* Find a new loop ID to use. */
  1903. fcport->loop_id = next_loopid;
  1904. rval = qla2x00_find_new_loop_id(ha, fcport);
  1905. if (rval != QLA_SUCCESS) {
  1906. /* Ran out of IDs to use */
  1907. break;
  1908. }
  1909. /* Remove device from the new list and add it to DB */
  1910. list_del(&fcport->list);
  1911. list_add_tail(&fcport->list, &ha->fcports);
  1912. /* Login and update database */
  1913. qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
  1914. }
  1915. } while (0);
  1916. /* Free all new device structures not processed. */
  1917. list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
  1918. list_del(&fcport->list);
  1919. kfree(fcport);
  1920. }
  1921. if (rval) {
  1922. DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
  1923. "rval=%d\n", ha->host_no, rval));
  1924. }
  1925. return (rval);
  1926. }
  1927. /*
  1928. * qla2x00_find_all_fabric_devs
  1929. *
  1930. * Input:
  1931. * ha = adapter block pointer.
  1932. * dev = database device entry pointer.
  1933. *
  1934. * Returns:
  1935. * 0 = success.
  1936. *
  1937. * Context:
  1938. * Kernel context.
  1939. */
  1940. static int
  1941. qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
  1942. {
  1943. int rval;
  1944. uint16_t loop_id;
  1945. fc_port_t *fcport, *new_fcport, *fcptemp;
  1946. int found;
  1947. sw_info_t *swl;
  1948. int swl_idx;
  1949. int first_dev, last_dev;
  1950. port_id_t wrap, nxt_d_id;
  1951. rval = QLA_SUCCESS;
  1952. /* Try GID_PT to get device list, else GAN. */
  1953. swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
  1954. if (swl == NULL) {
  1955. /*EMPTY*/
  1956. DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
  1957. "on GA_NXT\n", ha->host_no));
  1958. } else {
  1959. memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
  1960. if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
  1961. kfree(swl);
  1962. swl = NULL;
  1963. } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
  1964. kfree(swl);
  1965. swl = NULL;
  1966. } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
  1967. kfree(swl);
  1968. swl = NULL;
  1969. }
  1970. }
  1971. swl_idx = 0;
  1972. /* Allocate temporary fcport for any new fcports discovered. */
  1973. new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
  1974. if (new_fcport == NULL) {
  1975. if (swl)
  1976. kfree(swl);
  1977. return (QLA_MEMORY_ALLOC_FAILED);
  1978. }
  1979. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  1980. /* Set start port ID scan at adapter ID. */
  1981. first_dev = 1;
  1982. last_dev = 0;
  1983. /* Starting free loop ID. */
  1984. loop_id = ha->min_external_loopid;
  1985. for (; loop_id <= ha->last_loop_id; loop_id++) {
  1986. if (qla2x00_is_reserved_id(ha, loop_id))
  1987. continue;
  1988. if (atomic_read(&ha->loop_down_timer) ||
  1989. test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
  1990. break;
  1991. if (swl != NULL) {
  1992. if (last_dev) {
  1993. wrap.b24 = new_fcport->d_id.b24;
  1994. } else {
  1995. new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
  1996. memcpy(new_fcport->node_name,
  1997. swl[swl_idx].node_name, WWN_SIZE);
  1998. memcpy(new_fcport->port_name,
  1999. swl[swl_idx].port_name, WWN_SIZE);
  2000. if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
  2001. last_dev = 1;
  2002. }
  2003. swl_idx++;
  2004. }
  2005. } else {
  2006. /* Send GA_NXT to the switch */
  2007. rval = qla2x00_ga_nxt(ha, new_fcport);
  2008. if (rval != QLA_SUCCESS) {
  2009. qla_printk(KERN_WARNING, ha,
  2010. "SNS scan failed -- assuming zero-entry "
  2011. "result...\n");
  2012. list_for_each_entry_safe(fcport, fcptemp,
  2013. new_fcports, list) {
  2014. list_del(&fcport->list);
  2015. kfree(fcport);
  2016. }
  2017. rval = QLA_SUCCESS;
  2018. break;
  2019. }
  2020. }
  2021. /* If wrap on switch device list, exit. */
  2022. if (first_dev) {
  2023. wrap.b24 = new_fcport->d_id.b24;
  2024. first_dev = 0;
  2025. } else if (new_fcport->d_id.b24 == wrap.b24) {
  2026. DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
  2027. ha->host_no, new_fcport->d_id.b.domain,
  2028. new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
  2029. break;
  2030. }
  2031. /* Bypass if host adapter. */
  2032. if (new_fcport->d_id.b24 == ha->d_id.b24)
  2033. continue;
  2034. /* Bypass reserved domain fields. */
  2035. if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
  2036. continue;
  2037. /* Locate matching device in database. */
  2038. found = 0;
  2039. list_for_each_entry(fcport, &ha->fcports, list) {
  2040. if (memcmp(new_fcport->port_name, fcport->port_name,
  2041. WWN_SIZE))
  2042. continue;
  2043. found++;
  2044. /*
  2045. * If address the same and state FCS_ONLINE, nothing
  2046. * changed.
  2047. */
  2048. if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
  2049. atomic_read(&fcport->state) == FCS_ONLINE) {
  2050. break;
  2051. }
  2052. /*
  2053. * If device was not a fabric device before.
  2054. */
  2055. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  2056. fcport->d_id.b24 = new_fcport->d_id.b24;
  2057. fcport->loop_id = FC_NO_LOOP_ID;
  2058. fcport->flags |= (FCF_FABRIC_DEVICE |
  2059. FCF_LOGIN_NEEDED);
  2060. fcport->flags &= ~FCF_PERSISTENT_BOUND;
  2061. break;
  2062. }
  2063. /*
  2064. * Port ID changed or device was marked to be updated;
  2065. * Log it out if still logged in and mark it for
  2066. * relogin later.
  2067. */
  2068. fcport->d_id.b24 = new_fcport->d_id.b24;
  2069. fcport->flags |= FCF_LOGIN_NEEDED;
  2070. if (fcport->loop_id != FC_NO_LOOP_ID &&
  2071. (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
  2072. fcport->port_type != FCT_INITIATOR &&
  2073. fcport->port_type != FCT_BROADCAST) {
  2074. ha->isp_ops.fabric_logout(ha, fcport->loop_id,
  2075. fcport->d_id.b.domain, fcport->d_id.b.area,
  2076. fcport->d_id.b.al_pa);
  2077. fcport->loop_id = FC_NO_LOOP_ID;
  2078. }
  2079. break;
  2080. }
  2081. if (found)
  2082. continue;
  2083. /* If device was not in our fcports list, then add it. */
  2084. list_add_tail(&new_fcport->list, new_fcports);
  2085. /* Allocate a new replacement fcport. */
  2086. nxt_d_id.b24 = new_fcport->d_id.b24;
  2087. new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
  2088. if (new_fcport == NULL) {
  2089. if (swl)
  2090. kfree(swl);
  2091. return (QLA_MEMORY_ALLOC_FAILED);
  2092. }
  2093. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  2094. new_fcport->d_id.b24 = nxt_d_id.b24;
  2095. }
  2096. if (swl)
  2097. kfree(swl);
  2098. if (new_fcport)
  2099. kfree(new_fcport);
  2100. if (!list_empty(new_fcports))
  2101. ha->device_flags |= DFLG_FABRIC_DEVICES;
  2102. return (rval);
  2103. }
  2104. /*
  2105. * qla2x00_find_new_loop_id
  2106. * Scan through our port list and find a new usable loop ID.
  2107. *
  2108. * Input:
  2109. * ha: adapter state pointer.
  2110. * dev: port structure pointer.
  2111. *
  2112. * Returns:
  2113. * qla2x00 local function return status code.
  2114. *
  2115. * Context:
  2116. * Kernel context.
  2117. */
  2118. int
  2119. qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
  2120. {
  2121. int rval;
  2122. int found;
  2123. fc_port_t *fcport;
  2124. uint16_t first_loop_id;
  2125. rval = QLA_SUCCESS;
  2126. /* Save starting loop ID. */
  2127. first_loop_id = dev->loop_id;
  2128. for (;;) {
  2129. /* Skip loop ID if already used by adapter. */
  2130. if (dev->loop_id == ha->loop_id) {
  2131. dev->loop_id++;
  2132. }
  2133. /* Skip reserved loop IDs. */
  2134. while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
  2135. dev->loop_id++;
  2136. }
  2137. /* Reset loop ID if passed the end. */
  2138. if (dev->loop_id > ha->last_loop_id) {
  2139. /* first loop ID. */
  2140. dev->loop_id = ha->min_external_loopid;
  2141. }
  2142. /* Check for loop ID being already in use. */
  2143. found = 0;
  2144. fcport = NULL;
  2145. list_for_each_entry(fcport, &ha->fcports, list) {
  2146. if (fcport->loop_id == dev->loop_id && fcport != dev) {
  2147. /* ID possibly in use */
  2148. found++;
  2149. break;
  2150. }
  2151. }
  2152. /* If not in use then it is free to use. */
  2153. if (!found) {
  2154. break;
  2155. }
  2156. /* ID in use. Try next value. */
  2157. dev->loop_id++;
  2158. /* If wrap around. No free ID to use. */
  2159. if (dev->loop_id == first_loop_id) {
  2160. dev->loop_id = FC_NO_LOOP_ID;
  2161. rval = QLA_FUNCTION_FAILED;
  2162. break;
  2163. }
  2164. }
  2165. return (rval);
  2166. }
  2167. /*
  2168. * qla2x00_device_resync
  2169. * Marks devices in the database that needs resynchronization.
  2170. *
  2171. * Input:
  2172. * ha = adapter block pointer.
  2173. *
  2174. * Context:
  2175. * Kernel context.
  2176. */
  2177. static int
  2178. qla2x00_device_resync(scsi_qla_host_t *ha)
  2179. {
  2180. int rval;
  2181. int rval2;
  2182. uint32_t mask;
  2183. fc_port_t *fcport;
  2184. uint32_t rscn_entry;
  2185. uint8_t rscn_out_iter;
  2186. uint8_t format;
  2187. port_id_t d_id;
  2188. rval = QLA_RSCNS_HANDLED;
  2189. while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
  2190. ha->flags.rscn_queue_overflow) {
  2191. rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
  2192. format = MSB(MSW(rscn_entry));
  2193. d_id.b.domain = LSB(MSW(rscn_entry));
  2194. d_id.b.area = MSB(LSW(rscn_entry));
  2195. d_id.b.al_pa = LSB(LSW(rscn_entry));
  2196. DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
  2197. "[%02x/%02x%02x%02x].\n",
  2198. ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
  2199. d_id.b.area, d_id.b.al_pa));
  2200. ha->rscn_out_ptr++;
  2201. if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
  2202. ha->rscn_out_ptr = 0;
  2203. /* Skip duplicate entries. */
  2204. for (rscn_out_iter = ha->rscn_out_ptr;
  2205. !ha->flags.rscn_queue_overflow &&
  2206. rscn_out_iter != ha->rscn_in_ptr;
  2207. rscn_out_iter = (rscn_out_iter ==
  2208. (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
  2209. if (rscn_entry != ha->rscn_queue[rscn_out_iter])
  2210. break;
  2211. DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
  2212. "entry found at [%d].\n", ha->host_no,
  2213. rscn_out_iter));
  2214. ha->rscn_out_ptr = rscn_out_iter;
  2215. }
  2216. /* Queue overflow, set switch default case. */
  2217. if (ha->flags.rscn_queue_overflow) {
  2218. DEBUG(printk("scsi(%ld): device_resync: rscn "
  2219. "overflow.\n", ha->host_no));
  2220. format = 3;
  2221. ha->flags.rscn_queue_overflow = 0;
  2222. }
  2223. switch (format) {
  2224. case 0:
  2225. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
  2226. !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
  2227. !IS_QLA24XX(ha) && !IS_QLA25XX(ha) &&
  2228. ha->flags.init_done) {
  2229. /* Handle port RSCN via asyncronous IOCBs */
  2230. rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
  2231. NULL, 0);
  2232. if (rval2 == QLA_SUCCESS)
  2233. continue;
  2234. }
  2235. mask = 0xffffff;
  2236. break;
  2237. case 1:
  2238. mask = 0xffff00;
  2239. break;
  2240. case 2:
  2241. mask = 0xff0000;
  2242. break;
  2243. default:
  2244. mask = 0x0;
  2245. d_id.b24 = 0;
  2246. ha->rscn_out_ptr = ha->rscn_in_ptr;
  2247. break;
  2248. }
  2249. rval = QLA_SUCCESS;
  2250. /* Abort any outstanding IO descriptors. */
  2251. if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
  2252. qla2x00_cancel_io_descriptors(ha);
  2253. list_for_each_entry(fcport, &ha->fcports, list) {
  2254. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
  2255. (fcport->d_id.b24 & mask) != d_id.b24 ||
  2256. fcport->port_type == FCT_BROADCAST)
  2257. continue;
  2258. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  2259. if (format != 3 ||
  2260. fcport->port_type != FCT_INITIATOR) {
  2261. qla2x00_mark_device_lost(ha, fcport, 0);
  2262. }
  2263. }
  2264. fcport->flags &= ~FCF_FARP_DONE;
  2265. }
  2266. }
  2267. return (rval);
  2268. }
  2269. /*
  2270. * qla2x00_fabric_dev_login
  2271. * Login fabric target device and update FC port database.
  2272. *
  2273. * Input:
  2274. * ha: adapter state pointer.
  2275. * fcport: port structure list pointer.
  2276. * next_loopid: contains value of a new loop ID that can be used
  2277. * by the next login attempt.
  2278. *
  2279. * Returns:
  2280. * qla2x00 local function return status code.
  2281. *
  2282. * Context:
  2283. * Kernel context.
  2284. */
  2285. static int
  2286. qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
  2287. uint16_t *next_loopid)
  2288. {
  2289. int rval;
  2290. int retry;
  2291. uint8_t opts;
  2292. rval = QLA_SUCCESS;
  2293. retry = 0;
  2294. rval = qla2x00_fabric_login(ha, fcport, next_loopid);
  2295. if (rval == QLA_SUCCESS) {
  2296. /* Send an ADISC to tape devices.*/
  2297. opts = 0;
  2298. if (fcport->flags & FCF_TAPE_PRESENT)
  2299. opts |= BIT_1;
  2300. rval = qla2x00_get_port_database(ha, fcport, opts);
  2301. if (rval != QLA_SUCCESS) {
  2302. ha->isp_ops.fabric_logout(ha, fcport->loop_id,
  2303. fcport->d_id.b.domain, fcport->d_id.b.area,
  2304. fcport->d_id.b.al_pa);
  2305. qla2x00_mark_device_lost(ha, fcport, 1);
  2306. } else {
  2307. qla2x00_update_fcport(ha, fcport);
  2308. }
  2309. }
  2310. return (rval);
  2311. }
  2312. /*
  2313. * qla2x00_fabric_login
  2314. * Issue fabric login command.
  2315. *
  2316. * Input:
  2317. * ha = adapter block pointer.
  2318. * device = pointer to FC device type structure.
  2319. *
  2320. * Returns:
  2321. * 0 - Login successfully
  2322. * 1 - Login failed
  2323. * 2 - Initiator device
  2324. * 3 - Fatal error
  2325. */
  2326. int
  2327. qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
  2328. uint16_t *next_loopid)
  2329. {
  2330. int rval;
  2331. int retry;
  2332. uint16_t tmp_loopid;
  2333. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2334. retry = 0;
  2335. tmp_loopid = 0;
  2336. for (;;) {
  2337. DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
  2338. "for port %02x%02x%02x.\n",
  2339. ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
  2340. fcport->d_id.b.area, fcport->d_id.b.al_pa));
  2341. /* Login fcport on switch. */
  2342. ha->isp_ops.fabric_login(ha, fcport->loop_id,
  2343. fcport->d_id.b.domain, fcport->d_id.b.area,
  2344. fcport->d_id.b.al_pa, mb, BIT_0);
  2345. if (mb[0] == MBS_PORT_ID_USED) {
  2346. /*
  2347. * Device has another loop ID. The firmware team
  2348. * recommends the driver perform an implicit login with
  2349. * the specified ID again. The ID we just used is save
  2350. * here so we return with an ID that can be tried by
  2351. * the next login.
  2352. */
  2353. retry++;
  2354. tmp_loopid = fcport->loop_id;
  2355. fcport->loop_id = mb[1];
  2356. DEBUG(printk("Fabric Login: port in use - next "
  2357. "loop id=0x%04x, port Id=%02x%02x%02x.\n",
  2358. fcport->loop_id, fcport->d_id.b.domain,
  2359. fcport->d_id.b.area, fcport->d_id.b.al_pa));
  2360. } else if (mb[0] == MBS_COMMAND_COMPLETE) {
  2361. /*
  2362. * Login succeeded.
  2363. */
  2364. if (retry) {
  2365. /* A retry occurred before. */
  2366. *next_loopid = tmp_loopid;
  2367. } else {
  2368. /*
  2369. * No retry occurred before. Just increment the
  2370. * ID value for next login.
  2371. */
  2372. *next_loopid = (fcport->loop_id + 1);
  2373. }
  2374. if (mb[1] & BIT_0) {
  2375. fcport->port_type = FCT_INITIATOR;
  2376. } else {
  2377. fcport->port_type = FCT_TARGET;
  2378. if (mb[1] & BIT_1) {
  2379. fcport->flags |= FCF_TAPE_PRESENT;
  2380. }
  2381. }
  2382. rval = QLA_SUCCESS;
  2383. break;
  2384. } else if (mb[0] == MBS_LOOP_ID_USED) {
  2385. /*
  2386. * Loop ID already used, try next loop ID.
  2387. */
  2388. fcport->loop_id++;
  2389. rval = qla2x00_find_new_loop_id(ha, fcport);
  2390. if (rval != QLA_SUCCESS) {
  2391. /* Ran out of loop IDs to use */
  2392. break;
  2393. }
  2394. } else if (mb[0] == MBS_COMMAND_ERROR) {
  2395. /*
  2396. * Firmware possibly timed out during login. If NO
  2397. * retries are left to do then the device is declared
  2398. * dead.
  2399. */
  2400. *next_loopid = fcport->loop_id;
  2401. ha->isp_ops.fabric_logout(ha, fcport->loop_id,
  2402. fcport->d_id.b.domain, fcport->d_id.b.area,
  2403. fcport->d_id.b.al_pa);
  2404. qla2x00_mark_device_lost(ha, fcport, 1);
  2405. rval = 1;
  2406. break;
  2407. } else {
  2408. /*
  2409. * unrecoverable / not handled error
  2410. */
  2411. DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
  2412. "loop_id=%x jiffies=%lx.\n",
  2413. __func__, ha->host_no, mb[0],
  2414. fcport->d_id.b.domain, fcport->d_id.b.area,
  2415. fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
  2416. *next_loopid = fcport->loop_id;
  2417. ha->isp_ops.fabric_logout(ha, fcport->loop_id,
  2418. fcport->d_id.b.domain, fcport->d_id.b.area,
  2419. fcport->d_id.b.al_pa);
  2420. fcport->loop_id = FC_NO_LOOP_ID;
  2421. atomic_set(&fcport->state, FCS_DEVICE_DEAD);
  2422. rval = 3;
  2423. break;
  2424. }
  2425. }
  2426. return (rval);
  2427. }
  2428. /*
  2429. * qla2x00_local_device_login
  2430. * Issue local device login command.
  2431. *
  2432. * Input:
  2433. * ha = adapter block pointer.
  2434. * loop_id = loop id of device to login to.
  2435. *
  2436. * Returns (Where's the #define!!!!):
  2437. * 0 - Login successfully
  2438. * 1 - Login failed
  2439. * 3 - Fatal error
  2440. */
  2441. int
  2442. qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
  2443. {
  2444. int rval;
  2445. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2446. memset(mb, 0, sizeof(mb));
  2447. rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
  2448. if (rval == QLA_SUCCESS) {
  2449. /* Interrogate mailbox registers for any errors */
  2450. if (mb[0] == MBS_COMMAND_ERROR)
  2451. rval = 1;
  2452. else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
  2453. /* device not in PCB table */
  2454. rval = 3;
  2455. }
  2456. return (rval);
  2457. }
  2458. /*
  2459. * qla2x00_loop_resync
  2460. * Resync with fibre channel devices.
  2461. *
  2462. * Input:
  2463. * ha = adapter block pointer.
  2464. *
  2465. * Returns:
  2466. * 0 = success
  2467. */
  2468. int
  2469. qla2x00_loop_resync(scsi_qla_host_t *ha)
  2470. {
  2471. int rval;
  2472. uint32_t wait_time;
  2473. rval = QLA_SUCCESS;
  2474. atomic_set(&ha->loop_state, LOOP_UPDATE);
  2475. clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
  2476. if (ha->flags.online) {
  2477. if (!(rval = qla2x00_fw_ready(ha))) {
  2478. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  2479. wait_time = 256;
  2480. do {
  2481. atomic_set(&ha->loop_state, LOOP_UPDATE);
  2482. /* Issue a marker after FW becomes ready. */
  2483. qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
  2484. ha->marker_needed = 0;
  2485. /* Remap devices on Loop. */
  2486. clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
  2487. qla2x00_configure_loop(ha);
  2488. wait_time--;
  2489. } while (!atomic_read(&ha->loop_down_timer) &&
  2490. !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
  2491. wait_time &&
  2492. (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
  2493. }
  2494. }
  2495. if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
  2496. return (QLA_FUNCTION_FAILED);
  2497. }
  2498. if (rval) {
  2499. DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
  2500. }
  2501. return (rval);
  2502. }
  2503. void
  2504. qla2x00_rescan_fcports(scsi_qla_host_t *ha)
  2505. {
  2506. int rescan_done;
  2507. fc_port_t *fcport;
  2508. rescan_done = 0;
  2509. list_for_each_entry(fcport, &ha->fcports, list) {
  2510. if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
  2511. continue;
  2512. qla2x00_update_fcport(ha, fcport);
  2513. fcport->flags &= ~FCF_RESCAN_NEEDED;
  2514. rescan_done = 1;
  2515. }
  2516. qla2x00_probe_for_all_luns(ha);
  2517. }
  2518. /*
  2519. * qla2x00_abort_isp
  2520. * Resets ISP and aborts all outstanding commands.
  2521. *
  2522. * Input:
  2523. * ha = adapter block pointer.
  2524. *
  2525. * Returns:
  2526. * 0 = success
  2527. */
  2528. int
  2529. qla2x00_abort_isp(scsi_qla_host_t *ha)
  2530. {
  2531. unsigned long flags = 0;
  2532. uint16_t cnt;
  2533. srb_t *sp;
  2534. uint8_t status = 0;
  2535. if (ha->flags.online) {
  2536. ha->flags.online = 0;
  2537. clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  2538. qla_printk(KERN_INFO, ha,
  2539. "Performing ISP error recovery - ha= %p.\n", ha);
  2540. ha->isp_ops.reset_chip(ha);
  2541. atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
  2542. if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
  2543. atomic_set(&ha->loop_state, LOOP_DOWN);
  2544. qla2x00_mark_all_devices_lost(ha);
  2545. } else {
  2546. if (!atomic_read(&ha->loop_down_timer))
  2547. atomic_set(&ha->loop_down_timer,
  2548. LOOP_DOWN_TIME);
  2549. }
  2550. spin_lock_irqsave(&ha->hardware_lock, flags);
  2551. /* Requeue all commands in outstanding command list. */
  2552. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  2553. sp = ha->outstanding_cmds[cnt];
  2554. if (sp) {
  2555. ha->outstanding_cmds[cnt] = NULL;
  2556. sp->flags = 0;
  2557. sp->cmd->result = DID_RESET << 16;
  2558. sp->cmd->host_scribble = (unsigned char *)NULL;
  2559. qla2x00_sp_compl(ha, sp);
  2560. }
  2561. }
  2562. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2563. ha->isp_ops.nvram_config(ha);
  2564. if (!qla2x00_restart_isp(ha)) {
  2565. clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
  2566. if (!atomic_read(&ha->loop_down_timer)) {
  2567. /*
  2568. * Issue marker command only when we are going
  2569. * to start the I/O .
  2570. */
  2571. ha->marker_needed = 1;
  2572. }
  2573. ha->flags.online = 1;
  2574. ha->isp_ops.enable_intrs(ha);
  2575. ha->isp_abort_cnt = 0;
  2576. clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
  2577. } else { /* failed the ISP abort */
  2578. ha->flags.online = 1;
  2579. if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
  2580. if (ha->isp_abort_cnt == 0) {
  2581. qla_printk(KERN_WARNING, ha,
  2582. "ISP error recovery failed - "
  2583. "board disabled\n");
  2584. /*
  2585. * The next call disables the board
  2586. * completely.
  2587. */
  2588. ha->isp_ops.reset_adapter(ha);
  2589. ha->flags.online = 0;
  2590. clear_bit(ISP_ABORT_RETRY,
  2591. &ha->dpc_flags);
  2592. status = 0;
  2593. } else { /* schedule another ISP abort */
  2594. ha->isp_abort_cnt--;
  2595. DEBUG(printk("qla%ld: ISP abort - "
  2596. "retry remaining %d\n",
  2597. ha->host_no, ha->isp_abort_cnt);)
  2598. status = 1;
  2599. }
  2600. } else {
  2601. ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
  2602. DEBUG(printk("qla2x00(%ld): ISP error recovery "
  2603. "- retrying (%d) more times\n",
  2604. ha->host_no, ha->isp_abort_cnt);)
  2605. set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
  2606. status = 1;
  2607. }
  2608. }
  2609. }
  2610. if (status) {
  2611. qla_printk(KERN_INFO, ha,
  2612. "qla2x00_abort_isp: **** FAILED ****\n");
  2613. } else {
  2614. DEBUG(printk(KERN_INFO
  2615. "qla2x00_abort_isp(%ld): exiting.\n",
  2616. ha->host_no);)
  2617. }
  2618. return(status);
  2619. }
  2620. /*
  2621. * qla2x00_restart_isp
  2622. * restarts the ISP after a reset
  2623. *
  2624. * Input:
  2625. * ha = adapter block pointer.
  2626. *
  2627. * Returns:
  2628. * 0 = success
  2629. */
  2630. static int
  2631. qla2x00_restart_isp(scsi_qla_host_t *ha)
  2632. {
  2633. uint8_t status = 0;
  2634. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2635. unsigned long flags = 0;
  2636. uint32_t wait_time;
  2637. /* If firmware needs to be loaded */
  2638. if (qla2x00_isp_firmware(ha)) {
  2639. ha->flags.online = 0;
  2640. if (!(status = ha->isp_ops.chip_diag(ha))) {
  2641. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  2642. status = qla2x00_setup_chip(ha);
  2643. goto done;
  2644. }
  2645. spin_lock_irqsave(&ha->hardware_lock, flags);
  2646. if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha)) {
  2647. /*
  2648. * Disable SRAM, Instruction RAM and GP RAM
  2649. * parity.
  2650. */
  2651. WRT_REG_WORD(&reg->hccr,
  2652. (HCCR_ENABLE_PARITY + 0x0));
  2653. RD_REG_WORD(&reg->hccr);
  2654. }
  2655. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2656. status = qla2x00_setup_chip(ha);
  2657. spin_lock_irqsave(&ha->hardware_lock, flags);
  2658. if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha)) {
  2659. /* Enable proper parity */
  2660. if (IS_QLA2300(ha))
  2661. /* SRAM parity */
  2662. WRT_REG_WORD(&reg->hccr,
  2663. (HCCR_ENABLE_PARITY + 0x1));
  2664. else
  2665. /*
  2666. * SRAM, Instruction RAM and GP RAM
  2667. * parity.
  2668. */
  2669. WRT_REG_WORD(&reg->hccr,
  2670. (HCCR_ENABLE_PARITY + 0x7));
  2671. RD_REG_WORD(&reg->hccr);
  2672. }
  2673. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2674. }
  2675. }
  2676. done:
  2677. if (!status && !(status = qla2x00_init_rings(ha))) {
  2678. clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
  2679. if (!(status = qla2x00_fw_ready(ha))) {
  2680. DEBUG(printk("%s(): Start configure loop, "
  2681. "status = %d\n", __func__, status);)
  2682. /* Issue a marker after FW becomes ready. */
  2683. qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
  2684. ha->flags.online = 1;
  2685. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  2686. wait_time = 256;
  2687. do {
  2688. clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
  2689. qla2x00_configure_loop(ha);
  2690. wait_time--;
  2691. } while (!atomic_read(&ha->loop_down_timer) &&
  2692. !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
  2693. wait_time &&
  2694. (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
  2695. }
  2696. /* if no cable then assume it's good */
  2697. if ((ha->device_flags & DFLG_NO_CABLE))
  2698. status = 0;
  2699. DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
  2700. __func__,
  2701. status);)
  2702. }
  2703. return (status);
  2704. }
  2705. /*
  2706. * qla2x00_reset_adapter
  2707. * Reset adapter.
  2708. *
  2709. * Input:
  2710. * ha = adapter block pointer.
  2711. */
  2712. void
  2713. qla2x00_reset_adapter(scsi_qla_host_t *ha)
  2714. {
  2715. unsigned long flags = 0;
  2716. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2717. ha->flags.online = 0;
  2718. ha->isp_ops.disable_intrs(ha);
  2719. spin_lock_irqsave(&ha->hardware_lock, flags);
  2720. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  2721. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  2722. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  2723. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  2724. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2725. }
  2726. void
  2727. qla24xx_reset_adapter(scsi_qla_host_t *ha)
  2728. {
  2729. unsigned long flags = 0;
  2730. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  2731. ha->flags.online = 0;
  2732. ha->isp_ops.disable_intrs(ha);
  2733. spin_lock_irqsave(&ha->hardware_lock, flags);
  2734. WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
  2735. RD_REG_DWORD(&reg->hccr);
  2736. WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  2737. RD_REG_DWORD(&reg->hccr);
  2738. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2739. }
  2740. int
  2741. qla24xx_nvram_config(scsi_qla_host_t *ha)
  2742. {
  2743. int rval;
  2744. struct init_cb_24xx *icb;
  2745. struct nvram_24xx *nv;
  2746. uint32_t *dptr;
  2747. uint8_t *dptr1, *dptr2;
  2748. uint32_t chksum;
  2749. uint16_t cnt;
  2750. rval = QLA_SUCCESS;
  2751. icb = (struct init_cb_24xx *)ha->init_cb;
  2752. nv = (struct nvram_24xx *)ha->request_ring;
  2753. /* Determine NVRAM starting address. */
  2754. ha->nvram_size = sizeof(struct nvram_24xx);
  2755. ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
  2756. if (PCI_FUNC(ha->pdev->devfn))
  2757. ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
  2758. /* Get NVRAM data and calculate checksum. */
  2759. dptr = (uint32_t *)nv;
  2760. ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
  2761. ha->nvram_size);
  2762. for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
  2763. chksum += le32_to_cpu(*dptr++);
  2764. DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
  2765. DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
  2766. ha->nvram_size));
  2767. /* Bad NVRAM data, set defaults parameters. */
  2768. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
  2769. || nv->id[3] != ' ' ||
  2770. nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
  2771. /* Reset NVRAM data. */
  2772. qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
  2773. "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
  2774. le16_to_cpu(nv->nvram_version));
  2775. qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
  2776. "invalid -- WWPN) defaults.\n");
  2777. /*
  2778. * Set default initialization control block.
  2779. */
  2780. memset(nv, 0, ha->nvram_size);
  2781. nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
  2782. nv->version = __constant_cpu_to_le16(ICB_VERSION);
  2783. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  2784. nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  2785. nv->exchange_count = __constant_cpu_to_le16(0);
  2786. nv->hard_address = __constant_cpu_to_le16(124);
  2787. nv->port_name[0] = 0x21;
  2788. nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
  2789. nv->port_name[2] = 0x00;
  2790. nv->port_name[3] = 0xe0;
  2791. nv->port_name[4] = 0x8b;
  2792. nv->port_name[5] = 0x1c;
  2793. nv->port_name[6] = 0x55;
  2794. nv->port_name[7] = 0x86;
  2795. nv->node_name[0] = 0x20;
  2796. nv->node_name[1] = 0x00;
  2797. nv->node_name[2] = 0x00;
  2798. nv->node_name[3] = 0xe0;
  2799. nv->node_name[4] = 0x8b;
  2800. nv->node_name[5] = 0x1c;
  2801. nv->node_name[6] = 0x55;
  2802. nv->node_name[7] = 0x86;
  2803. nv->login_retry_count = __constant_cpu_to_le16(8);
  2804. nv->link_down_timeout = __constant_cpu_to_le16(200);
  2805. nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
  2806. nv->login_timeout = __constant_cpu_to_le16(0);
  2807. nv->firmware_options_1 =
  2808. __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
  2809. nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
  2810. nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
  2811. nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
  2812. nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
  2813. nv->efi_parameters = __constant_cpu_to_le32(0);
  2814. nv->reset_delay = 5;
  2815. nv->max_luns_per_target = __constant_cpu_to_le16(128);
  2816. nv->port_down_retry_count = __constant_cpu_to_le16(30);
  2817. nv->link_down_timeout = __constant_cpu_to_le16(30);
  2818. rval = 1;
  2819. }
  2820. /* Reset Initialization control block */
  2821. memset(icb, 0, sizeof(struct init_cb_24xx));
  2822. /* Copy 1st segment. */
  2823. dptr1 = (uint8_t *)icb;
  2824. dptr2 = (uint8_t *)&nv->version;
  2825. cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
  2826. while (cnt--)
  2827. *dptr1++ = *dptr2++;
  2828. icb->login_retry_count = nv->login_retry_count;
  2829. icb->link_down_timeout = nv->link_down_timeout;
  2830. /* Copy 2nd segment. */
  2831. dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
  2832. dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
  2833. cnt = (uint8_t *)&icb->reserved_3 -
  2834. (uint8_t *)&icb->interrupt_delay_timer;
  2835. while (cnt--)
  2836. *dptr1++ = *dptr2++;
  2837. /*
  2838. * Setup driver NVRAM options.
  2839. */
  2840. if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
  2841. char *st, *en;
  2842. uint16_t index;
  2843. strncpy(ha->model_number, nv->model_name,
  2844. sizeof(nv->model_name));
  2845. st = en = ha->model_number;
  2846. en += sizeof(nv->model_name) - 1;
  2847. while (en > st) {
  2848. if (*en != 0x20 && *en != 0x00)
  2849. break;
  2850. *en-- = '\0';
  2851. }
  2852. index = (ha->pdev->subsystem_device & 0xff);
  2853. if (index < QLA_MODEL_NAMES)
  2854. ha->model_desc = qla2x00_model_desc[index];
  2855. } else
  2856. strcpy(ha->model_number, "QLA2462");
  2857. /* Prepare nodename */
  2858. if ((icb->firmware_options_1 & BIT_14) == 0) {
  2859. /*
  2860. * Firmware will apply the following mask if the nodename was
  2861. * not provided.
  2862. */
  2863. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  2864. icb->node_name[0] &= 0xF0;
  2865. }
  2866. /* Set host adapter parameters. */
  2867. ha->flags.disable_risc_code_load = 0;
  2868. ha->flags.enable_lip_reset = 1;
  2869. ha->flags.enable_lip_full_login = 1;
  2870. ha->flags.enable_target_reset = 1;
  2871. ha->flags.enable_led_scheme = 0;
  2872. ha->operating_mode =
  2873. (icb->firmware_options_2 & (BIT_6 | BIT_5 | BIT_4)) >> 4;
  2874. memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
  2875. sizeof(ha->fw_seriallink_options24));
  2876. /* save HBA serial number */
  2877. ha->serial0 = icb->port_name[5];
  2878. ha->serial1 = icb->port_name[6];
  2879. ha->serial2 = icb->port_name[7];
  2880. ha->node_name = icb->node_name;
  2881. ha->port_name = icb->port_name;
  2882. ha->retry_count = le16_to_cpu(nv->login_retry_count);
  2883. /* Set minimum login_timeout to 4 seconds. */
  2884. if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
  2885. nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
  2886. if (le16_to_cpu(nv->login_timeout) < 4)
  2887. nv->login_timeout = __constant_cpu_to_le16(4);
  2888. ha->login_timeout = le16_to_cpu(nv->login_timeout);
  2889. icb->login_timeout = cpu_to_le16(nv->login_timeout);
  2890. /* Set minimum RATOV to 200 tenths of a second. */
  2891. ha->r_a_tov = 200;
  2892. ha->loop_reset_delay = nv->reset_delay;
  2893. /* Link Down Timeout = 0:
  2894. *
  2895. * When Port Down timer expires we will start returning
  2896. * I/O's to OS with "DID_NO_CONNECT".
  2897. *
  2898. * Link Down Timeout != 0:
  2899. *
  2900. * The driver waits for the link to come up after link down
  2901. * before returning I/Os to OS with "DID_NO_CONNECT".
  2902. */
  2903. if (le16_to_cpu(nv->link_down_timeout) == 0) {
  2904. ha->loop_down_abort_time =
  2905. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  2906. } else {
  2907. ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
  2908. ha->loop_down_abort_time =
  2909. (LOOP_DOWN_TIME - ha->link_down_timeout);
  2910. }
  2911. /* Need enough time to try and get the port back. */
  2912. ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
  2913. if (qlport_down_retry)
  2914. ha->port_down_retry_count = qlport_down_retry;
  2915. /* Set login_retry_count */
  2916. ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
  2917. if (ha->port_down_retry_count ==
  2918. le16_to_cpu(nv->port_down_retry_count) &&
  2919. ha->port_down_retry_count > 3)
  2920. ha->login_retry_count = ha->port_down_retry_count;
  2921. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  2922. ha->login_retry_count = ha->port_down_retry_count;
  2923. if (ql2xloginretrycount)
  2924. ha->login_retry_count = ql2xloginretrycount;
  2925. if (rval) {
  2926. DEBUG2_3(printk(KERN_WARNING
  2927. "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
  2928. }
  2929. return (rval);
  2930. }
  2931. int
  2932. qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
  2933. {
  2934. int rval;
  2935. uint16_t cnt;
  2936. uint16_t *risc_code;
  2937. unsigned long risc_address;
  2938. unsigned long risc_code_size;
  2939. int num;
  2940. int i;
  2941. uint16_t *req_ring;
  2942. struct qla_fw_info *fw_iter;
  2943. rval = QLA_SUCCESS;
  2944. /* Load firmware sequences */
  2945. fw_iter = ha->brd_info->fw_info;
  2946. *srisc_addr = *ha->brd_info->fw_info->fwstart;
  2947. while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
  2948. risc_code = fw_iter->fwcode;
  2949. risc_code_size = *fw_iter->fwlen;
  2950. if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
  2951. risc_address = *fw_iter->fwstart;
  2952. } else {
  2953. /* Extended address */
  2954. risc_address = *fw_iter->lfwstart;
  2955. }
  2956. num = 0;
  2957. rval = 0;
  2958. while (risc_code_size > 0 && !rval) {
  2959. cnt = (uint16_t)(ha->fw_transfer_size >> 1);
  2960. if (cnt > risc_code_size)
  2961. cnt = risc_code_size;
  2962. DEBUG7(printk("scsi(%ld): Loading risc segment@ "
  2963. "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
  2964. ha->host_no, risc_code, cnt, risc_address));
  2965. req_ring = (uint16_t *)ha->request_ring;
  2966. for (i = 0; i < cnt; i++)
  2967. req_ring[i] = cpu_to_le16(risc_code[i]);
  2968. if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
  2969. rval = qla2x00_load_ram(ha, ha->request_dma,
  2970. risc_address, cnt);
  2971. } else {
  2972. rval = qla2x00_load_ram_ext(ha,
  2973. ha->request_dma, risc_address, cnt);
  2974. }
  2975. if (rval) {
  2976. DEBUG(printk("scsi(%ld): [ERROR] Failed to "
  2977. "load segment %d of firmware\n",
  2978. ha->host_no, num));
  2979. qla_printk(KERN_WARNING, ha,
  2980. "[ERROR] Failed to load segment %d of "
  2981. "firmware\n", num);
  2982. qla2x00_dump_regs(ha);
  2983. break;
  2984. }
  2985. risc_code += cnt;
  2986. risc_address += cnt;
  2987. risc_code_size -= cnt;
  2988. num++;
  2989. }
  2990. /* Next firmware sequence */
  2991. fw_iter++;
  2992. }
  2993. return (rval);
  2994. }
  2995. int
  2996. qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
  2997. {
  2998. int rval;
  2999. int segments, fragment;
  3000. uint32_t faddr;
  3001. uint32_t *dcode, dlen;
  3002. uint32_t risc_addr;
  3003. uint32_t risc_size;
  3004. uint32_t i;
  3005. rval = QLA_SUCCESS;
  3006. segments = FA_RISC_CODE_SEGMENTS;
  3007. faddr = FA_RISC_CODE_ADDR;
  3008. dcode = (uint32_t *)ha->request_ring;
  3009. *srisc_addr = 0;
  3010. /* Validate firmware image by checking version. */
  3011. qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
  3012. for (i = 0; i < 4; i++)
  3013. dcode[i] = be32_to_cpu(dcode[i]);
  3014. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  3015. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  3016. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  3017. dcode[3] == 0)) {
  3018. qla_printk(KERN_WARNING, ha,
  3019. "Unable to verify integrity of flash firmware image!\n");
  3020. qla_printk(KERN_WARNING, ha,
  3021. "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
  3022. dcode[1], dcode[2], dcode[3]);
  3023. return QLA_FUNCTION_FAILED;
  3024. }
  3025. while (segments && rval == QLA_SUCCESS) {
  3026. /* Read segment's load information. */
  3027. qla24xx_read_flash_data(ha, dcode, faddr, 4);
  3028. risc_addr = be32_to_cpu(dcode[2]);
  3029. *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
  3030. risc_size = be32_to_cpu(dcode[3]);
  3031. fragment = 0;
  3032. while (risc_size > 0 && rval == QLA_SUCCESS) {
  3033. dlen = (uint32_t)(ha->fw_transfer_size >> 2);
  3034. if (dlen > risc_size)
  3035. dlen = risc_size;
  3036. DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
  3037. "addr %x, number of dwords 0x%x, offset 0x%x.\n",
  3038. ha->host_no, risc_addr, dlen, faddr));
  3039. qla24xx_read_flash_data(ha, dcode, faddr, dlen);
  3040. for (i = 0; i < dlen; i++)
  3041. dcode[i] = swab32(dcode[i]);
  3042. rval = qla2x00_load_ram_ext(ha, ha->request_dma,
  3043. risc_addr, dlen);
  3044. if (rval) {
  3045. DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
  3046. "segment %d of firmware\n", ha->host_no,
  3047. fragment));
  3048. qla_printk(KERN_WARNING, ha,
  3049. "[ERROR] Failed to load segment %d of "
  3050. "firmware\n", fragment);
  3051. break;
  3052. }
  3053. faddr += dlen;
  3054. risc_addr += dlen;
  3055. risc_size -= dlen;
  3056. fragment++;
  3057. }
  3058. /* Next segment. */
  3059. segments--;
  3060. }
  3061. return rval;
  3062. }
  3063. int
  3064. qla24xx_load_risc_hotplug(scsi_qla_host_t *ha, uint32_t *srisc_addr)
  3065. {
  3066. int rval;
  3067. int segments, fragment;
  3068. uint32_t *dcode, dlen;
  3069. uint32_t risc_addr;
  3070. uint32_t risc_size;
  3071. uint32_t i;
  3072. const struct firmware *fw_entry;
  3073. uint32_t *fwcode, fwclen;
  3074. if (request_firmware(&fw_entry, ha->brd_info->fw_fname,
  3075. &ha->pdev->dev)) {
  3076. qla_printk(KERN_ERR, ha,
  3077. "Firmware image file not available: '%s'\n",
  3078. ha->brd_info->fw_fname);
  3079. return QLA_FUNCTION_FAILED;
  3080. }
  3081. rval = QLA_SUCCESS;
  3082. segments = FA_RISC_CODE_SEGMENTS;
  3083. dcode = (uint32_t *)ha->request_ring;
  3084. *srisc_addr = 0;
  3085. fwcode = (uint32_t *)fw_entry->data;
  3086. fwclen = 0;
  3087. /* Validate firmware image by checking version. */
  3088. if (fw_entry->size < 8 * sizeof(uint32_t)) {
  3089. qla_printk(KERN_WARNING, ha,
  3090. "Unable to verify integrity of flash firmware image "
  3091. "(%Zd)!\n", fw_entry->size);
  3092. goto fail_fw_integrity;
  3093. }
  3094. for (i = 0; i < 4; i++)
  3095. dcode[i] = be32_to_cpu(fwcode[i + 4]);
  3096. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  3097. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  3098. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  3099. dcode[3] == 0)) {
  3100. qla_printk(KERN_WARNING, ha,
  3101. "Unable to verify integrity of flash firmware image!\n");
  3102. qla_printk(KERN_WARNING, ha,
  3103. "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
  3104. dcode[1], dcode[2], dcode[3]);
  3105. goto fail_fw_integrity;
  3106. }
  3107. while (segments && rval == QLA_SUCCESS) {
  3108. risc_addr = be32_to_cpu(fwcode[2]);
  3109. *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
  3110. risc_size = be32_to_cpu(fwcode[3]);
  3111. /* Validate firmware image size. */
  3112. fwclen += risc_size * sizeof(uint32_t);
  3113. if (fw_entry->size < fwclen) {
  3114. qla_printk(KERN_WARNING, ha,
  3115. "Unable to verify integrity of flash firmware "
  3116. "image (%Zd)!\n", fw_entry->size);
  3117. goto fail_fw_integrity;
  3118. }
  3119. fragment = 0;
  3120. while (risc_size > 0 && rval == QLA_SUCCESS) {
  3121. dlen = (uint32_t)(ha->fw_transfer_size >> 2);
  3122. if (dlen > risc_size)
  3123. dlen = risc_size;
  3124. DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
  3125. "addr %x, number of dwords 0x%x.\n", ha->host_no,
  3126. risc_addr, dlen));
  3127. for (i = 0; i < dlen; i++)
  3128. dcode[i] = swab32(fwcode[i]);
  3129. rval = qla2x00_load_ram_ext(ha, ha->request_dma,
  3130. risc_addr, dlen);
  3131. if (rval) {
  3132. DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
  3133. "segment %d of firmware\n", ha->host_no,
  3134. fragment));
  3135. qla_printk(KERN_WARNING, ha,
  3136. "[ERROR] Failed to load segment %d of "
  3137. "firmware\n", fragment);
  3138. break;
  3139. }
  3140. fwcode += dlen;
  3141. risc_addr += dlen;
  3142. risc_size -= dlen;
  3143. fragment++;
  3144. }
  3145. /* Next segment. */
  3146. segments--;
  3147. }
  3148. release_firmware(fw_entry);
  3149. return rval;
  3150. fail_fw_integrity:
  3151. release_firmware(fw_entry);
  3152. return QLA_FUNCTION_FAILED;
  3153. }