qla_init.c 102 KB

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