qla_init.c 101 KB

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