qla_init.c 144 KB

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