qla_init.c 102 KB

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