qla_init.c 143 KB

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