qla_init.c 105 KB

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