qla_init.c 146 KB

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