qla_init.c 107 KB

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