qla_init.c 127 KB

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