qla_os.c 156 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2013 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/moduleparam.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/delay.h>
  11. #include <linux/kthread.h>
  12. #include <linux/mutex.h>
  13. #include <linux/kobject.h>
  14. #include <linux/slab.h>
  15. #include <scsi/scsi_tcq.h>
  16. #include <scsi/scsicam.h>
  17. #include <scsi/scsi_transport.h>
  18. #include <scsi/scsi_transport_fc.h>
  19. #include "qla_target.h"
  20. /*
  21. * Driver version
  22. */
  23. char qla2x00_version_str[40];
  24. static int apidev_major;
  25. /*
  26. * SRB allocation cache
  27. */
  28. static struct kmem_cache *srb_cachep;
  29. /*
  30. * CT6 CTX allocation cache
  31. */
  32. static struct kmem_cache *ctx_cachep;
  33. /*
  34. * error level for logging
  35. */
  36. int ql_errlev = ql_log_all;
  37. static int ql2xenableclass2;
  38. module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
  39. MODULE_PARM_DESC(ql2xenableclass2,
  40. "Specify if Class 2 operations are supported from the very "
  41. "beginning. Default is 0 - class 2 not supported.");
  42. int ql2xlogintimeout = 20;
  43. module_param(ql2xlogintimeout, int, S_IRUGO);
  44. MODULE_PARM_DESC(ql2xlogintimeout,
  45. "Login timeout value in seconds.");
  46. int qlport_down_retry;
  47. module_param(qlport_down_retry, int, S_IRUGO);
  48. MODULE_PARM_DESC(qlport_down_retry,
  49. "Maximum number of command retries to a port that returns "
  50. "a PORT-DOWN status.");
  51. int ql2xplogiabsentdevice;
  52. module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
  53. MODULE_PARM_DESC(ql2xplogiabsentdevice,
  54. "Option to enable PLOGI to devices that are not present after "
  55. "a Fabric scan. This is needed for several broken switches. "
  56. "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
  57. int ql2xloginretrycount = 0;
  58. module_param(ql2xloginretrycount, int, S_IRUGO);
  59. MODULE_PARM_DESC(ql2xloginretrycount,
  60. "Specify an alternate value for the NVRAM login retry count.");
  61. int ql2xallocfwdump = 1;
  62. module_param(ql2xallocfwdump, int, S_IRUGO);
  63. MODULE_PARM_DESC(ql2xallocfwdump,
  64. "Option to enable allocation of memory for a firmware dump "
  65. "during HBA initialization. Memory allocation requirements "
  66. "vary by ISP type. Default is 1 - allocate memory.");
  67. int ql2xextended_error_logging;
  68. module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
  69. MODULE_PARM_DESC(ql2xextended_error_logging,
  70. "Option to enable extended error logging,\n"
  71. "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
  72. "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
  73. "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
  74. "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
  75. "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
  76. "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
  77. "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
  78. "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
  79. "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
  80. "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
  81. "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
  82. "\t\t0x1e400000 - Preferred value for capturing essential "
  83. "debug information (equivalent to old "
  84. "ql2xextended_error_logging=1).\n"
  85. "\t\tDo LOGICAL OR of the value to enable more than one level");
  86. int ql2xshiftctondsd = 6;
  87. module_param(ql2xshiftctondsd, int, S_IRUGO);
  88. MODULE_PARM_DESC(ql2xshiftctondsd,
  89. "Set to control shifting of command type processing "
  90. "based on total number of SG elements.");
  91. int ql2xfdmienable=1;
  92. module_param(ql2xfdmienable, int, S_IRUGO);
  93. MODULE_PARM_DESC(ql2xfdmienable,
  94. "Enables FDMI registrations. "
  95. "0 - no FDMI. Default is 1 - perform FDMI.");
  96. int ql2xmaxqdepth = MAX_Q_DEPTH;
  97. module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
  98. MODULE_PARM_DESC(ql2xmaxqdepth,
  99. "Maximum queue depth to set for each LUN. "
  100. "Default is 32.");
  101. int ql2xenabledif = 2;
  102. module_param(ql2xenabledif, int, S_IRUGO);
  103. MODULE_PARM_DESC(ql2xenabledif,
  104. " Enable T10-CRC-DIF "
  105. " Default is 0 - No DIF Support. 1 - Enable it"
  106. ", 2 - Enable DIF for all types, except Type 0.");
  107. int ql2xenablehba_err_chk = 2;
  108. module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
  109. MODULE_PARM_DESC(ql2xenablehba_err_chk,
  110. " Enable T10-CRC-DIF Error isolation by HBA:\n"
  111. " Default is 1.\n"
  112. " 0 -- Error isolation disabled\n"
  113. " 1 -- Error isolation enabled only for DIX Type 0\n"
  114. " 2 -- Error isolation enabled for all Types\n");
  115. int ql2xiidmaenable=1;
  116. module_param(ql2xiidmaenable, int, S_IRUGO);
  117. MODULE_PARM_DESC(ql2xiidmaenable,
  118. "Enables iIDMA settings "
  119. "Default is 1 - perform iIDMA. 0 - no iIDMA.");
  120. int ql2xmaxqueues = 1;
  121. module_param(ql2xmaxqueues, int, S_IRUGO);
  122. MODULE_PARM_DESC(ql2xmaxqueues,
  123. "Enables MQ settings "
  124. "Default is 1 for single queue. Set it to number "
  125. "of queues in MQ mode.");
  126. int ql2xmultique_tag;
  127. module_param(ql2xmultique_tag, int, S_IRUGO);
  128. MODULE_PARM_DESC(ql2xmultique_tag,
  129. "Enables CPU affinity settings for the driver "
  130. "Default is 0 for no affinity of request and response IO. "
  131. "Set it to 1 to turn on the cpu affinity.");
  132. int ql2xfwloadbin;
  133. module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
  134. MODULE_PARM_DESC(ql2xfwloadbin,
  135. "Option to specify location from which to load ISP firmware:.\n"
  136. " 2 -- load firmware via the request_firmware() (hotplug).\n"
  137. " interface.\n"
  138. " 1 -- load firmware from flash.\n"
  139. " 0 -- use default semantics.\n");
  140. int ql2xetsenable;
  141. module_param(ql2xetsenable, int, S_IRUGO);
  142. MODULE_PARM_DESC(ql2xetsenable,
  143. "Enables firmware ETS burst."
  144. "Default is 0 - skip ETS enablement.");
  145. int ql2xdbwr = 1;
  146. module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
  147. MODULE_PARM_DESC(ql2xdbwr,
  148. "Option to specify scheme for request queue posting.\n"
  149. " 0 -- Regular doorbell.\n"
  150. " 1 -- CAMRAM doorbell (faster).\n");
  151. int ql2xtargetreset = 1;
  152. module_param(ql2xtargetreset, int, S_IRUGO);
  153. MODULE_PARM_DESC(ql2xtargetreset,
  154. "Enable target reset."
  155. "Default is 1 - use hw defaults.");
  156. int ql2xgffidenable;
  157. module_param(ql2xgffidenable, int, S_IRUGO);
  158. MODULE_PARM_DESC(ql2xgffidenable,
  159. "Enables GFF_ID checks of port type. "
  160. "Default is 0 - Do not use GFF_ID information.");
  161. int ql2xasynctmfenable;
  162. module_param(ql2xasynctmfenable, int, S_IRUGO);
  163. MODULE_PARM_DESC(ql2xasynctmfenable,
  164. "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
  165. "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
  166. int ql2xdontresethba;
  167. module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
  168. MODULE_PARM_DESC(ql2xdontresethba,
  169. "Option to specify reset behaviour.\n"
  170. " 0 (Default) -- Reset on failure.\n"
  171. " 1 -- Do not reset on failure.\n");
  172. uint ql2xmaxlun = MAX_LUNS;
  173. module_param(ql2xmaxlun, uint, S_IRUGO);
  174. MODULE_PARM_DESC(ql2xmaxlun,
  175. "Defines the maximum LU number to register with the SCSI "
  176. "midlayer. Default is 65535.");
  177. int ql2xmdcapmask = 0x1F;
  178. module_param(ql2xmdcapmask, int, S_IRUGO);
  179. MODULE_PARM_DESC(ql2xmdcapmask,
  180. "Set the Minidump driver capture mask level. "
  181. "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
  182. int ql2xmdenable = 1;
  183. module_param(ql2xmdenable, int, S_IRUGO);
  184. MODULE_PARM_DESC(ql2xmdenable,
  185. "Enable/disable MiniDump. "
  186. "0 - MiniDump disabled. "
  187. "1 (Default) - MiniDump enabled.");
  188. /*
  189. * SCSI host template entry points
  190. */
  191. static int qla2xxx_slave_configure(struct scsi_device * device);
  192. static int qla2xxx_slave_alloc(struct scsi_device *);
  193. static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
  194. static void qla2xxx_scan_start(struct Scsi_Host *);
  195. static void qla2xxx_slave_destroy(struct scsi_device *);
  196. static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  197. static int qla2xxx_eh_abort(struct scsi_cmnd *);
  198. static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
  199. static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
  200. static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
  201. static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
  202. static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
  203. static int qla2x00_change_queue_type(struct scsi_device *, int);
  204. static void qla2x00_free_device(scsi_qla_host_t *);
  205. struct scsi_host_template qla2xxx_driver_template = {
  206. .module = THIS_MODULE,
  207. .name = QLA2XXX_DRIVER_NAME,
  208. .queuecommand = qla2xxx_queuecommand,
  209. .eh_abort_handler = qla2xxx_eh_abort,
  210. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  211. .eh_target_reset_handler = qla2xxx_eh_target_reset,
  212. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  213. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  214. .slave_configure = qla2xxx_slave_configure,
  215. .slave_alloc = qla2xxx_slave_alloc,
  216. .slave_destroy = qla2xxx_slave_destroy,
  217. .scan_finished = qla2xxx_scan_finished,
  218. .scan_start = qla2xxx_scan_start,
  219. .change_queue_depth = qla2x00_change_queue_depth,
  220. .change_queue_type = qla2x00_change_queue_type,
  221. .this_id = -1,
  222. .cmd_per_lun = 3,
  223. .use_clustering = ENABLE_CLUSTERING,
  224. .sg_tablesize = SG_ALL,
  225. .max_sectors = 0xFFFF,
  226. .shost_attrs = qla2x00_host_attrs,
  227. .supported_mode = MODE_INITIATOR,
  228. };
  229. static struct scsi_transport_template *qla2xxx_transport_template = NULL;
  230. struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
  231. /* TODO Convert to inlines
  232. *
  233. * Timer routines
  234. */
  235. __inline__ void
  236. qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
  237. {
  238. init_timer(&vha->timer);
  239. vha->timer.expires = jiffies + interval * HZ;
  240. vha->timer.data = (unsigned long)vha;
  241. vha->timer.function = (void (*)(unsigned long))func;
  242. add_timer(&vha->timer);
  243. vha->timer_active = 1;
  244. }
  245. static inline void
  246. qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
  247. {
  248. /* Currently used for 82XX only. */
  249. if (vha->device_flags & DFLG_DEV_FAILED) {
  250. ql_dbg(ql_dbg_timer, vha, 0x600d,
  251. "Device in a failed state, returning.\n");
  252. return;
  253. }
  254. mod_timer(&vha->timer, jiffies + interval * HZ);
  255. }
  256. static __inline__ void
  257. qla2x00_stop_timer(scsi_qla_host_t *vha)
  258. {
  259. del_timer_sync(&vha->timer);
  260. vha->timer_active = 0;
  261. }
  262. static int qla2x00_do_dpc(void *data);
  263. static void qla2x00_rst_aen(scsi_qla_host_t *);
  264. static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
  265. struct req_que **, struct rsp_que **);
  266. static void qla2x00_free_fw_dump(struct qla_hw_data *);
  267. static void qla2x00_mem_free(struct qla_hw_data *);
  268. /* -------------------------------------------------------------------------- */
  269. static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
  270. struct rsp_que *rsp)
  271. {
  272. scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
  273. ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
  274. GFP_KERNEL);
  275. if (!ha->req_q_map) {
  276. ql_log(ql_log_fatal, vha, 0x003b,
  277. "Unable to allocate memory for request queue ptrs.\n");
  278. goto fail_req_map;
  279. }
  280. ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
  281. GFP_KERNEL);
  282. if (!ha->rsp_q_map) {
  283. ql_log(ql_log_fatal, vha, 0x003c,
  284. "Unable to allocate memory for response queue ptrs.\n");
  285. goto fail_rsp_map;
  286. }
  287. /*
  288. * Make sure we record at least the request and response queue zero in
  289. * case we need to free them if part of the probe fails.
  290. */
  291. ha->rsp_q_map[0] = rsp;
  292. ha->req_q_map[0] = req;
  293. set_bit(0, ha->rsp_qid_map);
  294. set_bit(0, ha->req_qid_map);
  295. return 1;
  296. fail_rsp_map:
  297. kfree(ha->req_q_map);
  298. ha->req_q_map = NULL;
  299. fail_req_map:
  300. return -ENOMEM;
  301. }
  302. static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
  303. {
  304. if (IS_QLAFX00(ha)) {
  305. if (req && req->ring_fx00)
  306. dma_free_coherent(&ha->pdev->dev,
  307. (req->length_fx00 + 1) * sizeof(request_t),
  308. req->ring_fx00, req->dma_fx00);
  309. } else if (req && req->ring)
  310. dma_free_coherent(&ha->pdev->dev,
  311. (req->length + 1) * sizeof(request_t),
  312. req->ring, req->dma);
  313. if (req)
  314. kfree(req->outstanding_cmds);
  315. kfree(req);
  316. req = NULL;
  317. }
  318. static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
  319. {
  320. if (IS_QLAFX00(ha)) {
  321. if (rsp && rsp->ring)
  322. dma_free_coherent(&ha->pdev->dev,
  323. (rsp->length_fx00 + 1) * sizeof(request_t),
  324. rsp->ring_fx00, rsp->dma_fx00);
  325. } else if (rsp && rsp->ring) {
  326. dma_free_coherent(&ha->pdev->dev,
  327. (rsp->length + 1) * sizeof(response_t),
  328. rsp->ring, rsp->dma);
  329. }
  330. kfree(rsp);
  331. rsp = NULL;
  332. }
  333. static void qla2x00_free_queues(struct qla_hw_data *ha)
  334. {
  335. struct req_que *req;
  336. struct rsp_que *rsp;
  337. int cnt;
  338. for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
  339. req = ha->req_q_map[cnt];
  340. qla2x00_free_req_que(ha, req);
  341. }
  342. kfree(ha->req_q_map);
  343. ha->req_q_map = NULL;
  344. for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
  345. rsp = ha->rsp_q_map[cnt];
  346. qla2x00_free_rsp_que(ha, rsp);
  347. }
  348. kfree(ha->rsp_q_map);
  349. ha->rsp_q_map = NULL;
  350. }
  351. static int qla25xx_setup_mode(struct scsi_qla_host *vha)
  352. {
  353. uint16_t options = 0;
  354. int ques, req, ret;
  355. struct qla_hw_data *ha = vha->hw;
  356. if (!(ha->fw_attributes & BIT_6)) {
  357. ql_log(ql_log_warn, vha, 0x00d8,
  358. "Firmware is not multi-queue capable.\n");
  359. goto fail;
  360. }
  361. if (ql2xmultique_tag) {
  362. /* create a request queue for IO */
  363. options |= BIT_7;
  364. req = qla25xx_create_req_que(ha, options, 0, 0, -1,
  365. QLA_DEFAULT_QUE_QOS);
  366. if (!req) {
  367. ql_log(ql_log_warn, vha, 0x00e0,
  368. "Failed to create request queue.\n");
  369. goto fail;
  370. }
  371. ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
  372. vha->req = ha->req_q_map[req];
  373. options |= BIT_1;
  374. for (ques = 1; ques < ha->max_rsp_queues; ques++) {
  375. ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
  376. if (!ret) {
  377. ql_log(ql_log_warn, vha, 0x00e8,
  378. "Failed to create response queue.\n");
  379. goto fail2;
  380. }
  381. }
  382. ha->flags.cpu_affinity_enabled = 1;
  383. ql_dbg(ql_dbg_multiq, vha, 0xc007,
  384. "CPU affinity mode enalbed, "
  385. "no. of response queues:%d no. of request queues:%d.\n",
  386. ha->max_rsp_queues, ha->max_req_queues);
  387. ql_dbg(ql_dbg_init, vha, 0x00e9,
  388. "CPU affinity mode enalbed, "
  389. "no. of response queues:%d no. of request queues:%d.\n",
  390. ha->max_rsp_queues, ha->max_req_queues);
  391. }
  392. return 0;
  393. fail2:
  394. qla25xx_delete_queues(vha);
  395. destroy_workqueue(ha->wq);
  396. ha->wq = NULL;
  397. vha->req = ha->req_q_map[0];
  398. fail:
  399. ha->mqenable = 0;
  400. kfree(ha->req_q_map);
  401. kfree(ha->rsp_q_map);
  402. ha->max_req_queues = ha->max_rsp_queues = 1;
  403. return 1;
  404. }
  405. static char *
  406. qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
  407. {
  408. struct qla_hw_data *ha = vha->hw;
  409. static char *pci_bus_modes[] = {
  410. "33", "66", "100", "133",
  411. };
  412. uint16_t pci_bus;
  413. strcpy(str, "PCI");
  414. pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
  415. if (pci_bus) {
  416. strcat(str, "-X (");
  417. strcat(str, pci_bus_modes[pci_bus]);
  418. } else {
  419. pci_bus = (ha->pci_attr & BIT_8) >> 8;
  420. strcat(str, " (");
  421. strcat(str, pci_bus_modes[pci_bus]);
  422. }
  423. strcat(str, " MHz)");
  424. return (str);
  425. }
  426. static char *
  427. qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
  428. {
  429. static char *pci_bus_modes[] = { "33", "66", "100", "133", };
  430. struct qla_hw_data *ha = vha->hw;
  431. uint32_t pci_bus;
  432. int pcie_reg;
  433. pcie_reg = pci_pcie_cap(ha->pdev);
  434. if (pcie_reg) {
  435. char lwstr[6];
  436. uint16_t pcie_lstat, lspeed, lwidth;
  437. pcie_reg += PCI_EXP_LNKCAP;
  438. pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
  439. lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
  440. lwidth = (pcie_lstat &
  441. (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
  442. strcpy(str, "PCIe (");
  443. switch (lspeed) {
  444. case 1:
  445. strcat(str, "2.5GT/s ");
  446. break;
  447. case 2:
  448. strcat(str, "5.0GT/s ");
  449. break;
  450. case 3:
  451. strcat(str, "8.0GT/s ");
  452. break;
  453. default:
  454. strcat(str, "<unknown> ");
  455. break;
  456. }
  457. snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
  458. strcat(str, lwstr);
  459. return str;
  460. }
  461. strcpy(str, "PCI");
  462. pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
  463. if (pci_bus == 0 || pci_bus == 8) {
  464. strcat(str, " (");
  465. strcat(str, pci_bus_modes[pci_bus >> 3]);
  466. } else {
  467. strcat(str, "-X ");
  468. if (pci_bus & BIT_2)
  469. strcat(str, "Mode 2");
  470. else
  471. strcat(str, "Mode 1");
  472. strcat(str, " (");
  473. strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
  474. }
  475. strcat(str, " MHz)");
  476. return str;
  477. }
  478. static char *
  479. qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
  480. {
  481. char un_str[10];
  482. struct qla_hw_data *ha = vha->hw;
  483. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  484. ha->fw_minor_version,
  485. ha->fw_subminor_version);
  486. if (ha->fw_attributes & BIT_9) {
  487. strcat(str, "FLX");
  488. return (str);
  489. }
  490. switch (ha->fw_attributes & 0xFF) {
  491. case 0x7:
  492. strcat(str, "EF");
  493. break;
  494. case 0x17:
  495. strcat(str, "TP");
  496. break;
  497. case 0x37:
  498. strcat(str, "IP");
  499. break;
  500. case 0x77:
  501. strcat(str, "VI");
  502. break;
  503. default:
  504. sprintf(un_str, "(%x)", ha->fw_attributes);
  505. strcat(str, un_str);
  506. break;
  507. }
  508. if (ha->fw_attributes & 0x100)
  509. strcat(str, "X");
  510. return (str);
  511. }
  512. static char *
  513. qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
  514. {
  515. struct qla_hw_data *ha = vha->hw;
  516. sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
  517. ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
  518. return str;
  519. }
  520. void
  521. qla2x00_sp_free_dma(void *vha, void *ptr)
  522. {
  523. srb_t *sp = (srb_t *)ptr;
  524. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  525. struct qla_hw_data *ha = sp->fcport->vha->hw;
  526. void *ctx = GET_CMD_CTX_SP(sp);
  527. if (sp->flags & SRB_DMA_VALID) {
  528. scsi_dma_unmap(cmd);
  529. sp->flags &= ~SRB_DMA_VALID;
  530. }
  531. if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
  532. dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
  533. scsi_prot_sg_count(cmd), cmd->sc_data_direction);
  534. sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
  535. }
  536. if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
  537. /* List assured to be having elements */
  538. qla2x00_clean_dsd_pool(ha, sp);
  539. sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
  540. }
  541. if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
  542. dma_pool_free(ha->dl_dma_pool, ctx,
  543. ((struct crc_context *)ctx)->crc_ctx_dma);
  544. sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
  545. }
  546. if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
  547. struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
  548. dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
  549. ctx1->fcp_cmnd_dma);
  550. list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
  551. ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
  552. ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
  553. mempool_free(ctx1, ha->ctx_mempool);
  554. ctx1 = NULL;
  555. }
  556. CMD_SP(cmd) = NULL;
  557. qla2x00_rel_sp(sp->fcport->vha, sp);
  558. }
  559. static void
  560. qla2x00_sp_compl(void *data, void *ptr, int res)
  561. {
  562. struct qla_hw_data *ha = (struct qla_hw_data *)data;
  563. srb_t *sp = (srb_t *)ptr;
  564. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  565. cmd->result = res;
  566. if (atomic_read(&sp->ref_count) == 0) {
  567. ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
  568. "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
  569. sp, GET_CMD_SP(sp));
  570. if (ql2xextended_error_logging & ql_dbg_io)
  571. BUG();
  572. return;
  573. }
  574. if (!atomic_dec_and_test(&sp->ref_count))
  575. return;
  576. qla2x00_sp_free_dma(ha, sp);
  577. cmd->scsi_done(cmd);
  578. }
  579. /* If we are SP1 here, we need to still take and release the host_lock as SP1
  580. * does not have the changes necessary to avoid taking host->host_lock.
  581. */
  582. static int
  583. qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  584. {
  585. scsi_qla_host_t *vha = shost_priv(host);
  586. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  587. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  588. struct qla_hw_data *ha = vha->hw;
  589. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  590. srb_t *sp;
  591. int rval;
  592. if (ha->flags.eeh_busy) {
  593. if (ha->flags.pci_channel_io_perm_failure) {
  594. ql_dbg(ql_dbg_aer, vha, 0x9010,
  595. "PCI Channel IO permanent failure, exiting "
  596. "cmd=%p.\n", cmd);
  597. cmd->result = DID_NO_CONNECT << 16;
  598. } else {
  599. ql_dbg(ql_dbg_aer, vha, 0x9011,
  600. "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
  601. cmd->result = DID_REQUEUE << 16;
  602. }
  603. goto qc24_fail_command;
  604. }
  605. rval = fc_remote_port_chkready(rport);
  606. if (rval) {
  607. cmd->result = rval;
  608. ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
  609. "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
  610. cmd, rval);
  611. goto qc24_fail_command;
  612. }
  613. if (!vha->flags.difdix_supported &&
  614. scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
  615. ql_dbg(ql_dbg_io, vha, 0x3004,
  616. "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
  617. cmd);
  618. cmd->result = DID_NO_CONNECT << 16;
  619. goto qc24_fail_command;
  620. }
  621. if (!fcport) {
  622. cmd->result = DID_NO_CONNECT << 16;
  623. goto qc24_fail_command;
  624. }
  625. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  626. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  627. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  628. ql_dbg(ql_dbg_io, vha, 0x3005,
  629. "Returning DNC, fcport_state=%d loop_state=%d.\n",
  630. atomic_read(&fcport->state),
  631. atomic_read(&base_vha->loop_state));
  632. cmd->result = DID_NO_CONNECT << 16;
  633. goto qc24_fail_command;
  634. }
  635. goto qc24_target_busy;
  636. }
  637. sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
  638. if (!sp) {
  639. set_bit(HOST_RAMP_DOWN_QUEUE_DEPTH, &vha->dpc_flags);
  640. goto qc24_host_busy;
  641. }
  642. sp->u.scmd.cmd = cmd;
  643. sp->type = SRB_SCSI_CMD;
  644. atomic_set(&sp->ref_count, 1);
  645. CMD_SP(cmd) = (void *)sp;
  646. sp->free = qla2x00_sp_free_dma;
  647. sp->done = qla2x00_sp_compl;
  648. rval = ha->isp_ops->start_scsi(sp);
  649. if (rval != QLA_SUCCESS) {
  650. ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
  651. "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
  652. set_bit(HOST_RAMP_DOWN_QUEUE_DEPTH, &vha->dpc_flags);
  653. goto qc24_host_busy_free_sp;
  654. }
  655. return 0;
  656. qc24_host_busy_free_sp:
  657. qla2x00_sp_free_dma(ha, sp);
  658. qc24_host_busy:
  659. return SCSI_MLQUEUE_HOST_BUSY;
  660. qc24_target_busy:
  661. return SCSI_MLQUEUE_TARGET_BUSY;
  662. qc24_fail_command:
  663. cmd->scsi_done(cmd);
  664. return 0;
  665. }
  666. /*
  667. * qla2x00_eh_wait_on_command
  668. * Waits for the command to be returned by the Firmware for some
  669. * max time.
  670. *
  671. * Input:
  672. * cmd = Scsi Command to wait on.
  673. *
  674. * Return:
  675. * Not Found : 0
  676. * Found : 1
  677. */
  678. static int
  679. qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
  680. {
  681. #define ABORT_POLLING_PERIOD 1000
  682. #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
  683. unsigned long wait_iter = ABORT_WAIT_ITER;
  684. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  685. struct qla_hw_data *ha = vha->hw;
  686. int ret = QLA_SUCCESS;
  687. if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
  688. ql_dbg(ql_dbg_taskm, vha, 0x8005,
  689. "Return:eh_wait.\n");
  690. return ret;
  691. }
  692. while (CMD_SP(cmd) && wait_iter--) {
  693. msleep(ABORT_POLLING_PERIOD);
  694. }
  695. if (CMD_SP(cmd))
  696. ret = QLA_FUNCTION_FAILED;
  697. return ret;
  698. }
  699. /*
  700. * qla2x00_wait_for_hba_online
  701. * Wait till the HBA is online after going through
  702. * <= MAX_RETRIES_OF_ISP_ABORT or
  703. * finally HBA is disabled ie marked offline
  704. *
  705. * Input:
  706. * ha - pointer to host adapter structure
  707. *
  708. * Note:
  709. * Does context switching-Release SPIN_LOCK
  710. * (if any) before calling this routine.
  711. *
  712. * Return:
  713. * Success (Adapter is online) : 0
  714. * Failed (Adapter is offline/disabled) : 1
  715. */
  716. int
  717. qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
  718. {
  719. int return_status;
  720. unsigned long wait_online;
  721. struct qla_hw_data *ha = vha->hw;
  722. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  723. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  724. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  725. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  726. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  727. ha->dpc_active) && time_before(jiffies, wait_online)) {
  728. msleep(1000);
  729. }
  730. if (base_vha->flags.online)
  731. return_status = QLA_SUCCESS;
  732. else
  733. return_status = QLA_FUNCTION_FAILED;
  734. return (return_status);
  735. }
  736. /*
  737. * qla2x00_wait_for_reset_ready
  738. * Wait till the HBA is online after going through
  739. * <= MAX_RETRIES_OF_ISP_ABORT or
  740. * finally HBA is disabled ie marked offline or flash
  741. * operations are in progress.
  742. *
  743. * Input:
  744. * ha - pointer to host adapter structure
  745. *
  746. * Note:
  747. * Does context switching-Release SPIN_LOCK
  748. * (if any) before calling this routine.
  749. *
  750. * Return:
  751. * Success (Adapter is online/no flash ops) : 0
  752. * Failed (Adapter is offline/disabled/flash ops in progress) : 1
  753. */
  754. static int
  755. qla2x00_wait_for_reset_ready(scsi_qla_host_t *vha)
  756. {
  757. int return_status;
  758. unsigned long wait_online;
  759. struct qla_hw_data *ha = vha->hw;
  760. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  761. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  762. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  763. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  764. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  765. ha->optrom_state != QLA_SWAITING ||
  766. ha->dpc_active) && time_before(jiffies, wait_online))
  767. msleep(1000);
  768. if (base_vha->flags.online && ha->optrom_state == QLA_SWAITING)
  769. return_status = QLA_SUCCESS;
  770. else
  771. return_status = QLA_FUNCTION_FAILED;
  772. ql_dbg(ql_dbg_taskm, vha, 0x8019,
  773. "%s return status=%d.\n", __func__, return_status);
  774. return return_status;
  775. }
  776. int
  777. qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
  778. {
  779. int return_status;
  780. unsigned long wait_reset;
  781. struct qla_hw_data *ha = vha->hw;
  782. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  783. wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  784. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  785. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  786. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  787. ha->dpc_active) && time_before(jiffies, wait_reset)) {
  788. msleep(1000);
  789. if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  790. ha->flags.chip_reset_done)
  791. break;
  792. }
  793. if (ha->flags.chip_reset_done)
  794. return_status = QLA_SUCCESS;
  795. else
  796. return_status = QLA_FUNCTION_FAILED;
  797. return return_status;
  798. }
  799. static void
  800. sp_get(struct srb *sp)
  801. {
  802. atomic_inc(&sp->ref_count);
  803. }
  804. /**************************************************************************
  805. * qla2xxx_eh_abort
  806. *
  807. * Description:
  808. * The abort function will abort the specified command.
  809. *
  810. * Input:
  811. * cmd = Linux SCSI command packet to be aborted.
  812. *
  813. * Returns:
  814. * Either SUCCESS or FAILED.
  815. *
  816. * Note:
  817. * Only return FAILED if command not returned by firmware.
  818. **************************************************************************/
  819. static int
  820. qla2xxx_eh_abort(struct scsi_cmnd *cmd)
  821. {
  822. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  823. srb_t *sp;
  824. int ret;
  825. unsigned int id, lun;
  826. unsigned long flags;
  827. int wait = 0;
  828. struct qla_hw_data *ha = vha->hw;
  829. if (!CMD_SP(cmd))
  830. return SUCCESS;
  831. ret = fc_block_scsi_eh(cmd);
  832. if (ret != 0)
  833. return ret;
  834. ret = SUCCESS;
  835. id = cmd->device->id;
  836. lun = cmd->device->lun;
  837. spin_lock_irqsave(&ha->hardware_lock, flags);
  838. sp = (srb_t *) CMD_SP(cmd);
  839. if (!sp) {
  840. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  841. return SUCCESS;
  842. }
  843. ql_dbg(ql_dbg_taskm, vha, 0x8002,
  844. "Aborting from RISC nexus=%ld:%d:%d sp=%p cmd=%p\n",
  845. vha->host_no, id, lun, sp, cmd);
  846. /* Get a reference to the sp and drop the lock.*/
  847. sp_get(sp);
  848. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  849. if (ha->isp_ops->abort_command(sp)) {
  850. ret = FAILED;
  851. ql_dbg(ql_dbg_taskm, vha, 0x8003,
  852. "Abort command mbx failed cmd=%p.\n", cmd);
  853. } else {
  854. ql_dbg(ql_dbg_taskm, vha, 0x8004,
  855. "Abort command mbx success cmd=%p.\n", cmd);
  856. wait = 1;
  857. }
  858. spin_lock_irqsave(&ha->hardware_lock, flags);
  859. sp->done(ha, sp, 0);
  860. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  861. /* Did the command return during mailbox execution? */
  862. if (ret == FAILED && !CMD_SP(cmd))
  863. ret = SUCCESS;
  864. /* Wait for the command to be returned. */
  865. if (wait) {
  866. if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
  867. ql_log(ql_log_warn, vha, 0x8006,
  868. "Abort handler timed out cmd=%p.\n", cmd);
  869. ret = FAILED;
  870. }
  871. }
  872. ql_log(ql_log_info, vha, 0x801c,
  873. "Abort command issued nexus=%ld:%d:%d -- %d %x.\n",
  874. vha->host_no, id, lun, wait, ret);
  875. return ret;
  876. }
  877. int
  878. qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
  879. unsigned int l, enum nexus_wait_type type)
  880. {
  881. int cnt, match, status;
  882. unsigned long flags;
  883. struct qla_hw_data *ha = vha->hw;
  884. struct req_que *req;
  885. srb_t *sp;
  886. struct scsi_cmnd *cmd;
  887. status = QLA_SUCCESS;
  888. spin_lock_irqsave(&ha->hardware_lock, flags);
  889. req = vha->req;
  890. for (cnt = 1; status == QLA_SUCCESS &&
  891. cnt < req->num_outstanding_cmds; cnt++) {
  892. sp = req->outstanding_cmds[cnt];
  893. if (!sp)
  894. continue;
  895. if (sp->type != SRB_SCSI_CMD)
  896. continue;
  897. if (vha->vp_idx != sp->fcport->vha->vp_idx)
  898. continue;
  899. match = 0;
  900. cmd = GET_CMD_SP(sp);
  901. switch (type) {
  902. case WAIT_HOST:
  903. match = 1;
  904. break;
  905. case WAIT_TARGET:
  906. match = cmd->device->id == t;
  907. break;
  908. case WAIT_LUN:
  909. match = (cmd->device->id == t &&
  910. cmd->device->lun == l);
  911. break;
  912. }
  913. if (!match)
  914. continue;
  915. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  916. status = qla2x00_eh_wait_on_command(cmd);
  917. spin_lock_irqsave(&ha->hardware_lock, flags);
  918. }
  919. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  920. return status;
  921. }
  922. static char *reset_errors[] = {
  923. "HBA not online",
  924. "HBA not ready",
  925. "Task management failed",
  926. "Waiting for command completions",
  927. };
  928. static int
  929. __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
  930. struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
  931. {
  932. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  933. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  934. int err;
  935. if (!fcport) {
  936. return FAILED;
  937. }
  938. err = fc_block_scsi_eh(cmd);
  939. if (err != 0)
  940. return err;
  941. ql_log(ql_log_info, vha, 0x8009,
  942. "%s RESET ISSUED nexus=%ld:%d:%d cmd=%p.\n", name, vha->host_no,
  943. cmd->device->id, cmd->device->lun, cmd);
  944. err = 0;
  945. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  946. ql_log(ql_log_warn, vha, 0x800a,
  947. "Wait for hba online failed for cmd=%p.\n", cmd);
  948. goto eh_reset_failed;
  949. }
  950. err = 2;
  951. if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
  952. != QLA_SUCCESS) {
  953. ql_log(ql_log_warn, vha, 0x800c,
  954. "do_reset failed for cmd=%p.\n", cmd);
  955. goto eh_reset_failed;
  956. }
  957. err = 3;
  958. if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
  959. cmd->device->lun, type) != QLA_SUCCESS) {
  960. ql_log(ql_log_warn, vha, 0x800d,
  961. "wait for pending cmds failed for cmd=%p.\n", cmd);
  962. goto eh_reset_failed;
  963. }
  964. ql_log(ql_log_info, vha, 0x800e,
  965. "%s RESET SUCCEEDED nexus:%ld:%d:%d cmd=%p.\n", name,
  966. vha->host_no, cmd->device->id, cmd->device->lun, cmd);
  967. return SUCCESS;
  968. eh_reset_failed:
  969. ql_log(ql_log_info, vha, 0x800f,
  970. "%s RESET FAILED: %s nexus=%ld:%d:%d cmd=%p.\n", name,
  971. reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
  972. cmd);
  973. return FAILED;
  974. }
  975. static int
  976. qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
  977. {
  978. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  979. struct qla_hw_data *ha = vha->hw;
  980. return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
  981. ha->isp_ops->lun_reset);
  982. }
  983. static int
  984. qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
  985. {
  986. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  987. struct qla_hw_data *ha = vha->hw;
  988. return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
  989. ha->isp_ops->target_reset);
  990. }
  991. /**************************************************************************
  992. * qla2xxx_eh_bus_reset
  993. *
  994. * Description:
  995. * The bus reset function will reset the bus and abort any executing
  996. * commands.
  997. *
  998. * Input:
  999. * cmd = Linux SCSI command packet of the command that cause the
  1000. * bus reset.
  1001. *
  1002. * Returns:
  1003. * SUCCESS/FAILURE (defined as macro in scsi.h).
  1004. *
  1005. **************************************************************************/
  1006. static int
  1007. qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
  1008. {
  1009. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1010. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  1011. int ret = FAILED;
  1012. unsigned int id, lun;
  1013. id = cmd->device->id;
  1014. lun = cmd->device->lun;
  1015. if (!fcport) {
  1016. return ret;
  1017. }
  1018. ret = fc_block_scsi_eh(cmd);
  1019. if (ret != 0)
  1020. return ret;
  1021. ret = FAILED;
  1022. ql_log(ql_log_info, vha, 0x8012,
  1023. "BUS RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
  1024. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  1025. ql_log(ql_log_fatal, vha, 0x8013,
  1026. "Wait for hba online failed board disabled.\n");
  1027. goto eh_bus_reset_done;
  1028. }
  1029. if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
  1030. ret = SUCCESS;
  1031. if (ret == FAILED)
  1032. goto eh_bus_reset_done;
  1033. /* Flush outstanding commands. */
  1034. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
  1035. QLA_SUCCESS) {
  1036. ql_log(ql_log_warn, vha, 0x8014,
  1037. "Wait for pending commands failed.\n");
  1038. ret = FAILED;
  1039. }
  1040. eh_bus_reset_done:
  1041. ql_log(ql_log_warn, vha, 0x802b,
  1042. "BUS RESET %s nexus=%ld:%d:%d.\n",
  1043. (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
  1044. return ret;
  1045. }
  1046. /**************************************************************************
  1047. * qla2xxx_eh_host_reset
  1048. *
  1049. * Description:
  1050. * The reset function will reset the Adapter.
  1051. *
  1052. * Input:
  1053. * cmd = Linux SCSI command packet of the command that cause the
  1054. * adapter reset.
  1055. *
  1056. * Returns:
  1057. * Either SUCCESS or FAILED.
  1058. *
  1059. * Note:
  1060. **************************************************************************/
  1061. static int
  1062. qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
  1063. {
  1064. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1065. struct qla_hw_data *ha = vha->hw;
  1066. int ret = FAILED;
  1067. unsigned int id, lun;
  1068. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  1069. id = cmd->device->id;
  1070. lun = cmd->device->lun;
  1071. ql_log(ql_log_info, vha, 0x8018,
  1072. "ADAPTER RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
  1073. if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
  1074. goto eh_host_reset_lock;
  1075. if (vha != base_vha) {
  1076. if (qla2x00_vp_abort_isp(vha))
  1077. goto eh_host_reset_lock;
  1078. } else {
  1079. if (IS_P3P_TYPE(vha->hw)) {
  1080. if (!qla82xx_fcoe_ctx_reset(vha)) {
  1081. /* Ctx reset success */
  1082. ret = SUCCESS;
  1083. goto eh_host_reset_lock;
  1084. }
  1085. /* fall thru if ctx reset failed */
  1086. }
  1087. if (ha->wq)
  1088. flush_workqueue(ha->wq);
  1089. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1090. if (ha->isp_ops->abort_isp(base_vha)) {
  1091. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1092. /* failed. schedule dpc to try */
  1093. set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
  1094. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  1095. ql_log(ql_log_warn, vha, 0x802a,
  1096. "wait for hba online failed.\n");
  1097. goto eh_host_reset_lock;
  1098. }
  1099. }
  1100. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1101. }
  1102. /* Waiting for command to be returned to OS.*/
  1103. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
  1104. QLA_SUCCESS)
  1105. ret = SUCCESS;
  1106. eh_host_reset_lock:
  1107. ql_log(ql_log_info, vha, 0x8017,
  1108. "ADAPTER RESET %s nexus=%ld:%d:%d.\n",
  1109. (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
  1110. return ret;
  1111. }
  1112. /*
  1113. * qla2x00_loop_reset
  1114. * Issue loop reset.
  1115. *
  1116. * Input:
  1117. * ha = adapter block pointer.
  1118. *
  1119. * Returns:
  1120. * 0 = success
  1121. */
  1122. int
  1123. qla2x00_loop_reset(scsi_qla_host_t *vha)
  1124. {
  1125. int ret;
  1126. struct fc_port *fcport;
  1127. struct qla_hw_data *ha = vha->hw;
  1128. if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
  1129. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1130. if (fcport->port_type != FCT_TARGET)
  1131. continue;
  1132. ret = ha->isp_ops->target_reset(fcport, 0, 0);
  1133. if (ret != QLA_SUCCESS) {
  1134. ql_dbg(ql_dbg_taskm, vha, 0x802c,
  1135. "Bus Reset failed: Target Reset=%d "
  1136. "d_id=%x.\n", ret, fcport->d_id.b24);
  1137. }
  1138. }
  1139. }
  1140. if (IS_QLAFX00(ha))
  1141. return QLA_SUCCESS;
  1142. if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
  1143. atomic_set(&vha->loop_state, LOOP_DOWN);
  1144. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  1145. qla2x00_mark_all_devices_lost(vha, 0);
  1146. ret = qla2x00_full_login_lip(vha);
  1147. if (ret != QLA_SUCCESS) {
  1148. ql_dbg(ql_dbg_taskm, vha, 0x802d,
  1149. "full_login_lip=%d.\n", ret);
  1150. }
  1151. }
  1152. if (ha->flags.enable_lip_reset) {
  1153. ret = qla2x00_lip_reset(vha);
  1154. if (ret != QLA_SUCCESS)
  1155. ql_dbg(ql_dbg_taskm, vha, 0x802e,
  1156. "lip_reset failed (%d).\n", ret);
  1157. }
  1158. /* Issue marker command only when we are going to start the I/O */
  1159. vha->marker_needed = 1;
  1160. return QLA_SUCCESS;
  1161. }
  1162. void
  1163. qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
  1164. {
  1165. int que, cnt;
  1166. unsigned long flags;
  1167. srb_t *sp;
  1168. struct qla_hw_data *ha = vha->hw;
  1169. struct req_que *req;
  1170. spin_lock_irqsave(&ha->hardware_lock, flags);
  1171. for (que = 0; que < ha->max_req_queues; que++) {
  1172. req = ha->req_q_map[que];
  1173. if (!req)
  1174. continue;
  1175. if (!req->outstanding_cmds)
  1176. continue;
  1177. for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
  1178. sp = req->outstanding_cmds[cnt];
  1179. if (sp) {
  1180. req->outstanding_cmds[cnt] = NULL;
  1181. sp->done(vha, sp, res);
  1182. }
  1183. }
  1184. }
  1185. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1186. }
  1187. static int
  1188. qla2xxx_slave_alloc(struct scsi_device *sdev)
  1189. {
  1190. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  1191. if (!rport || fc_remote_port_chkready(rport))
  1192. return -ENXIO;
  1193. sdev->hostdata = *(fc_port_t **)rport->dd_data;
  1194. return 0;
  1195. }
  1196. static int
  1197. qla2xxx_slave_configure(struct scsi_device *sdev)
  1198. {
  1199. scsi_qla_host_t *vha = shost_priv(sdev->host);
  1200. struct req_que *req = vha->req;
  1201. if (IS_T10_PI_CAPABLE(vha->hw))
  1202. blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
  1203. if (sdev->tagged_supported)
  1204. scsi_activate_tcq(sdev, req->max_q_depth);
  1205. else
  1206. scsi_deactivate_tcq(sdev, req->max_q_depth);
  1207. return 0;
  1208. }
  1209. static void
  1210. qla2xxx_slave_destroy(struct scsi_device *sdev)
  1211. {
  1212. sdev->hostdata = NULL;
  1213. }
  1214. static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
  1215. {
  1216. fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
  1217. if (!scsi_track_queue_full(sdev, qdepth))
  1218. return;
  1219. ql_dbg(ql_dbg_io, fcport->vha, 0x3029,
  1220. "Queue depth adjusted-down to %d for nexus=%ld:%d:%d.\n",
  1221. sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
  1222. }
  1223. static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
  1224. {
  1225. fc_port_t *fcport = sdev->hostdata;
  1226. struct scsi_qla_host *vha = fcport->vha;
  1227. struct req_que *req = NULL;
  1228. req = vha->req;
  1229. if (!req)
  1230. return;
  1231. if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
  1232. return;
  1233. if (sdev->ordered_tags)
  1234. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
  1235. else
  1236. scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
  1237. ql_dbg(ql_dbg_io, vha, 0x302a,
  1238. "Queue depth adjusted-up to %d for nexus=%ld:%d:%d.\n",
  1239. sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
  1240. }
  1241. static int
  1242. qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
  1243. {
  1244. switch (reason) {
  1245. case SCSI_QDEPTH_DEFAULT:
  1246. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  1247. break;
  1248. case SCSI_QDEPTH_QFULL:
  1249. qla2x00_handle_queue_full(sdev, qdepth);
  1250. break;
  1251. case SCSI_QDEPTH_RAMP_UP:
  1252. qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
  1253. break;
  1254. default:
  1255. return -EOPNOTSUPP;
  1256. }
  1257. return sdev->queue_depth;
  1258. }
  1259. static int
  1260. qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
  1261. {
  1262. if (sdev->tagged_supported) {
  1263. scsi_set_tag_type(sdev, tag_type);
  1264. if (tag_type)
  1265. scsi_activate_tcq(sdev, sdev->queue_depth);
  1266. else
  1267. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  1268. } else
  1269. tag_type = 0;
  1270. return tag_type;
  1271. }
  1272. static void
  1273. qla2x00_host_ramp_down_queuedepth(scsi_qla_host_t *vha)
  1274. {
  1275. scsi_qla_host_t *vp;
  1276. struct Scsi_Host *shost;
  1277. struct scsi_device *sdev;
  1278. struct qla_hw_data *ha = vha->hw;
  1279. unsigned long flags;
  1280. ha->host_last_rampdown_time = jiffies;
  1281. if (ha->cfg_lun_q_depth <= vha->host->cmd_per_lun)
  1282. return;
  1283. if ((ha->cfg_lun_q_depth / 2) < vha->host->cmd_per_lun)
  1284. ha->cfg_lun_q_depth = vha->host->cmd_per_lun;
  1285. else
  1286. ha->cfg_lun_q_depth = ha->cfg_lun_q_depth / 2;
  1287. /*
  1288. * Geometrically ramp down the queue depth for all devices on this
  1289. * adapter
  1290. */
  1291. spin_lock_irqsave(&ha->vport_slock, flags);
  1292. list_for_each_entry(vp, &ha->vp_list, list) {
  1293. shost = vp->host;
  1294. shost_for_each_device(sdev, shost) {
  1295. if (sdev->queue_depth > shost->cmd_per_lun) {
  1296. if (sdev->queue_depth < ha->cfg_lun_q_depth)
  1297. continue;
  1298. ql_log(ql_log_warn, vp, 0x3031,
  1299. "%ld:%d:%d: Ramping down queue depth to %d",
  1300. vp->host_no, sdev->id, sdev->lun,
  1301. ha->cfg_lun_q_depth);
  1302. qla2x00_change_queue_depth(sdev,
  1303. ha->cfg_lun_q_depth, SCSI_QDEPTH_DEFAULT);
  1304. }
  1305. }
  1306. }
  1307. spin_unlock_irqrestore(&ha->vport_slock, flags);
  1308. return;
  1309. }
  1310. static void
  1311. qla2x00_host_ramp_up_queuedepth(scsi_qla_host_t *vha)
  1312. {
  1313. scsi_qla_host_t *vp;
  1314. struct Scsi_Host *shost;
  1315. struct scsi_device *sdev;
  1316. struct qla_hw_data *ha = vha->hw;
  1317. unsigned long flags;
  1318. ha->host_last_rampup_time = jiffies;
  1319. ha->cfg_lun_q_depth++;
  1320. /*
  1321. * Linearly ramp up the queue depth for all devices on this
  1322. * adapter
  1323. */
  1324. spin_lock_irqsave(&ha->vport_slock, flags);
  1325. list_for_each_entry(vp, &ha->vp_list, list) {
  1326. shost = vp->host;
  1327. shost_for_each_device(sdev, shost) {
  1328. if (sdev->queue_depth > ha->cfg_lun_q_depth)
  1329. continue;
  1330. qla2x00_change_queue_depth(sdev, ha->cfg_lun_q_depth,
  1331. SCSI_QDEPTH_RAMP_UP);
  1332. }
  1333. }
  1334. spin_unlock_irqrestore(&ha->vport_slock, flags);
  1335. return;
  1336. }
  1337. /**
  1338. * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
  1339. * @ha: HA context
  1340. *
  1341. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  1342. * supported addressing method.
  1343. */
  1344. static void
  1345. qla2x00_config_dma_addressing(struct qla_hw_data *ha)
  1346. {
  1347. /* Assume a 32bit DMA mask. */
  1348. ha->flags.enable_64bit_addressing = 0;
  1349. if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
  1350. /* Any upper-dword bits set? */
  1351. if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
  1352. !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  1353. /* Ok, a 64bit DMA mask is applicable. */
  1354. ha->flags.enable_64bit_addressing = 1;
  1355. ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
  1356. ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
  1357. return;
  1358. }
  1359. }
  1360. dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
  1361. pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  1362. }
  1363. static void
  1364. qla2x00_enable_intrs(struct qla_hw_data *ha)
  1365. {
  1366. unsigned long flags = 0;
  1367. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1368. spin_lock_irqsave(&ha->hardware_lock, flags);
  1369. ha->interrupts_on = 1;
  1370. /* enable risc and host interrupts */
  1371. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  1372. RD_REG_WORD(&reg->ictrl);
  1373. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1374. }
  1375. static void
  1376. qla2x00_disable_intrs(struct qla_hw_data *ha)
  1377. {
  1378. unsigned long flags = 0;
  1379. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1380. spin_lock_irqsave(&ha->hardware_lock, flags);
  1381. ha->interrupts_on = 0;
  1382. /* disable risc and host interrupts */
  1383. WRT_REG_WORD(&reg->ictrl, 0);
  1384. RD_REG_WORD(&reg->ictrl);
  1385. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1386. }
  1387. static void
  1388. qla24xx_enable_intrs(struct qla_hw_data *ha)
  1389. {
  1390. unsigned long flags = 0;
  1391. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1392. spin_lock_irqsave(&ha->hardware_lock, flags);
  1393. ha->interrupts_on = 1;
  1394. WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
  1395. RD_REG_DWORD(&reg->ictrl);
  1396. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1397. }
  1398. static void
  1399. qla24xx_disable_intrs(struct qla_hw_data *ha)
  1400. {
  1401. unsigned long flags = 0;
  1402. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1403. if (IS_NOPOLLING_TYPE(ha))
  1404. return;
  1405. spin_lock_irqsave(&ha->hardware_lock, flags);
  1406. ha->interrupts_on = 0;
  1407. WRT_REG_DWORD(&reg->ictrl, 0);
  1408. RD_REG_DWORD(&reg->ictrl);
  1409. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1410. }
  1411. static int
  1412. qla2x00_iospace_config(struct qla_hw_data *ha)
  1413. {
  1414. resource_size_t pio;
  1415. uint16_t msix;
  1416. int cpus;
  1417. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1418. QLA2XXX_DRIVER_NAME)) {
  1419. ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
  1420. "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
  1421. pci_name(ha->pdev));
  1422. goto iospace_error_exit;
  1423. }
  1424. if (!(ha->bars & 1))
  1425. goto skip_pio;
  1426. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  1427. pio = pci_resource_start(ha->pdev, 0);
  1428. if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
  1429. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1430. ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
  1431. "Invalid pci I/O region size (%s).\n",
  1432. pci_name(ha->pdev));
  1433. pio = 0;
  1434. }
  1435. } else {
  1436. ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
  1437. "Region #0 no a PIO resource (%s).\n",
  1438. pci_name(ha->pdev));
  1439. pio = 0;
  1440. }
  1441. ha->pio_address = pio;
  1442. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
  1443. "PIO address=%llu.\n",
  1444. (unsigned long long)ha->pio_address);
  1445. skip_pio:
  1446. /* Use MMIO operations for all accesses. */
  1447. if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
  1448. ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
  1449. "Region #1 not an MMIO resource (%s), aborting.\n",
  1450. pci_name(ha->pdev));
  1451. goto iospace_error_exit;
  1452. }
  1453. if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
  1454. ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
  1455. "Invalid PCI mem region size (%s), aborting.\n",
  1456. pci_name(ha->pdev));
  1457. goto iospace_error_exit;
  1458. }
  1459. ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
  1460. if (!ha->iobase) {
  1461. ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
  1462. "Cannot remap MMIO (%s), aborting.\n",
  1463. pci_name(ha->pdev));
  1464. goto iospace_error_exit;
  1465. }
  1466. /* Determine queue resources */
  1467. ha->max_req_queues = ha->max_rsp_queues = 1;
  1468. if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
  1469. (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
  1470. (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
  1471. goto mqiobase_exit;
  1472. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
  1473. pci_resource_len(ha->pdev, 3));
  1474. if (ha->mqiobase) {
  1475. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
  1476. "MQIO Base=%p.\n", ha->mqiobase);
  1477. /* Read MSIX vector size of the board */
  1478. pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
  1479. ha->msix_count = msix;
  1480. /* Max queues are bounded by available msix vectors */
  1481. /* queue 0 uses two msix vectors */
  1482. if (ql2xmultique_tag) {
  1483. cpus = num_online_cpus();
  1484. ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
  1485. (cpus + 1) : (ha->msix_count - 1);
  1486. ha->max_req_queues = 2;
  1487. } else if (ql2xmaxqueues > 1) {
  1488. ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
  1489. QLA_MQ_SIZE : ql2xmaxqueues;
  1490. ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
  1491. "QoS mode set, max no of request queues:%d.\n",
  1492. ha->max_req_queues);
  1493. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
  1494. "QoS mode set, max no of request queues:%d.\n",
  1495. ha->max_req_queues);
  1496. }
  1497. ql_log_pci(ql_log_info, ha->pdev, 0x001a,
  1498. "MSI-X vector count: %d.\n", msix);
  1499. } else
  1500. ql_log_pci(ql_log_info, ha->pdev, 0x001b,
  1501. "BAR 3 not enabled.\n");
  1502. mqiobase_exit:
  1503. ha->msix_count = ha->max_rsp_queues + 1;
  1504. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
  1505. "MSIX Count:%d.\n", ha->msix_count);
  1506. return (0);
  1507. iospace_error_exit:
  1508. return (-ENOMEM);
  1509. }
  1510. static int
  1511. qla83xx_iospace_config(struct qla_hw_data *ha)
  1512. {
  1513. uint16_t msix;
  1514. int cpus;
  1515. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1516. QLA2XXX_DRIVER_NAME)) {
  1517. ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
  1518. "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
  1519. pci_name(ha->pdev));
  1520. goto iospace_error_exit;
  1521. }
  1522. /* Use MMIO operations for all accesses. */
  1523. if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
  1524. ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
  1525. "Invalid pci I/O region size (%s).\n",
  1526. pci_name(ha->pdev));
  1527. goto iospace_error_exit;
  1528. }
  1529. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1530. ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
  1531. "Invalid PCI mem region size (%s), aborting\n",
  1532. pci_name(ha->pdev));
  1533. goto iospace_error_exit;
  1534. }
  1535. ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
  1536. if (!ha->iobase) {
  1537. ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
  1538. "Cannot remap MMIO (%s), aborting.\n",
  1539. pci_name(ha->pdev));
  1540. goto iospace_error_exit;
  1541. }
  1542. /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
  1543. /* 83XX 26XX always use MQ type access for queues
  1544. * - mbar 2, a.k.a region 4 */
  1545. ha->max_req_queues = ha->max_rsp_queues = 1;
  1546. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
  1547. pci_resource_len(ha->pdev, 4));
  1548. if (!ha->mqiobase) {
  1549. ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
  1550. "BAR2/region4 not enabled\n");
  1551. goto mqiobase_exit;
  1552. }
  1553. ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
  1554. pci_resource_len(ha->pdev, 2));
  1555. if (ha->msixbase) {
  1556. /* Read MSIX vector size of the board */
  1557. pci_read_config_word(ha->pdev,
  1558. QLA_83XX_PCI_MSIX_CONTROL, &msix);
  1559. ha->msix_count = msix;
  1560. /* Max queues are bounded by available msix vectors */
  1561. /* queue 0 uses two msix vectors */
  1562. if (ql2xmultique_tag) {
  1563. cpus = num_online_cpus();
  1564. ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
  1565. (cpus + 1) : (ha->msix_count - 1);
  1566. ha->max_req_queues = 2;
  1567. } else if (ql2xmaxqueues > 1) {
  1568. ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
  1569. QLA_MQ_SIZE : ql2xmaxqueues;
  1570. ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
  1571. "QoS mode set, max no of request queues:%d.\n",
  1572. ha->max_req_queues);
  1573. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
  1574. "QoS mode set, max no of request queues:%d.\n",
  1575. ha->max_req_queues);
  1576. }
  1577. ql_log_pci(ql_log_info, ha->pdev, 0x011c,
  1578. "MSI-X vector count: %d.\n", msix);
  1579. } else
  1580. ql_log_pci(ql_log_info, ha->pdev, 0x011e,
  1581. "BAR 1 not enabled.\n");
  1582. mqiobase_exit:
  1583. ha->msix_count = ha->max_rsp_queues + 1;
  1584. qlt_83xx_iospace_config(ha);
  1585. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
  1586. "MSIX Count:%d.\n", ha->msix_count);
  1587. return 0;
  1588. iospace_error_exit:
  1589. return -ENOMEM;
  1590. }
  1591. static struct isp_operations qla2100_isp_ops = {
  1592. .pci_config = qla2100_pci_config,
  1593. .reset_chip = qla2x00_reset_chip,
  1594. .chip_diag = qla2x00_chip_diag,
  1595. .config_rings = qla2x00_config_rings,
  1596. .reset_adapter = qla2x00_reset_adapter,
  1597. .nvram_config = qla2x00_nvram_config,
  1598. .update_fw_options = qla2x00_update_fw_options,
  1599. .load_risc = qla2x00_load_risc,
  1600. .pci_info_str = qla2x00_pci_info_str,
  1601. .fw_version_str = qla2x00_fw_version_str,
  1602. .intr_handler = qla2100_intr_handler,
  1603. .enable_intrs = qla2x00_enable_intrs,
  1604. .disable_intrs = qla2x00_disable_intrs,
  1605. .abort_command = qla2x00_abort_command,
  1606. .target_reset = qla2x00_abort_target,
  1607. .lun_reset = qla2x00_lun_reset,
  1608. .fabric_login = qla2x00_login_fabric,
  1609. .fabric_logout = qla2x00_fabric_logout,
  1610. .calc_req_entries = qla2x00_calc_iocbs_32,
  1611. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1612. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1613. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1614. .read_nvram = qla2x00_read_nvram_data,
  1615. .write_nvram = qla2x00_write_nvram_data,
  1616. .fw_dump = qla2100_fw_dump,
  1617. .beacon_on = NULL,
  1618. .beacon_off = NULL,
  1619. .beacon_blink = NULL,
  1620. .read_optrom = qla2x00_read_optrom_data,
  1621. .write_optrom = qla2x00_write_optrom_data,
  1622. .get_flash_version = qla2x00_get_flash_version,
  1623. .start_scsi = qla2x00_start_scsi,
  1624. .abort_isp = qla2x00_abort_isp,
  1625. .iospace_config = qla2x00_iospace_config,
  1626. .initialize_adapter = qla2x00_initialize_adapter,
  1627. };
  1628. static struct isp_operations qla2300_isp_ops = {
  1629. .pci_config = qla2300_pci_config,
  1630. .reset_chip = qla2x00_reset_chip,
  1631. .chip_diag = qla2x00_chip_diag,
  1632. .config_rings = qla2x00_config_rings,
  1633. .reset_adapter = qla2x00_reset_adapter,
  1634. .nvram_config = qla2x00_nvram_config,
  1635. .update_fw_options = qla2x00_update_fw_options,
  1636. .load_risc = qla2x00_load_risc,
  1637. .pci_info_str = qla2x00_pci_info_str,
  1638. .fw_version_str = qla2x00_fw_version_str,
  1639. .intr_handler = qla2300_intr_handler,
  1640. .enable_intrs = qla2x00_enable_intrs,
  1641. .disable_intrs = qla2x00_disable_intrs,
  1642. .abort_command = qla2x00_abort_command,
  1643. .target_reset = qla2x00_abort_target,
  1644. .lun_reset = qla2x00_lun_reset,
  1645. .fabric_login = qla2x00_login_fabric,
  1646. .fabric_logout = qla2x00_fabric_logout,
  1647. .calc_req_entries = qla2x00_calc_iocbs_32,
  1648. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1649. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1650. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1651. .read_nvram = qla2x00_read_nvram_data,
  1652. .write_nvram = qla2x00_write_nvram_data,
  1653. .fw_dump = qla2300_fw_dump,
  1654. .beacon_on = qla2x00_beacon_on,
  1655. .beacon_off = qla2x00_beacon_off,
  1656. .beacon_blink = qla2x00_beacon_blink,
  1657. .read_optrom = qla2x00_read_optrom_data,
  1658. .write_optrom = qla2x00_write_optrom_data,
  1659. .get_flash_version = qla2x00_get_flash_version,
  1660. .start_scsi = qla2x00_start_scsi,
  1661. .abort_isp = qla2x00_abort_isp,
  1662. .iospace_config = qla2x00_iospace_config,
  1663. .initialize_adapter = qla2x00_initialize_adapter,
  1664. };
  1665. static struct isp_operations qla24xx_isp_ops = {
  1666. .pci_config = qla24xx_pci_config,
  1667. .reset_chip = qla24xx_reset_chip,
  1668. .chip_diag = qla24xx_chip_diag,
  1669. .config_rings = qla24xx_config_rings,
  1670. .reset_adapter = qla24xx_reset_adapter,
  1671. .nvram_config = qla24xx_nvram_config,
  1672. .update_fw_options = qla24xx_update_fw_options,
  1673. .load_risc = qla24xx_load_risc,
  1674. .pci_info_str = qla24xx_pci_info_str,
  1675. .fw_version_str = qla24xx_fw_version_str,
  1676. .intr_handler = qla24xx_intr_handler,
  1677. .enable_intrs = qla24xx_enable_intrs,
  1678. .disable_intrs = qla24xx_disable_intrs,
  1679. .abort_command = qla24xx_abort_command,
  1680. .target_reset = qla24xx_abort_target,
  1681. .lun_reset = qla24xx_lun_reset,
  1682. .fabric_login = qla24xx_login_fabric,
  1683. .fabric_logout = qla24xx_fabric_logout,
  1684. .calc_req_entries = NULL,
  1685. .build_iocbs = NULL,
  1686. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1687. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1688. .read_nvram = qla24xx_read_nvram_data,
  1689. .write_nvram = qla24xx_write_nvram_data,
  1690. .fw_dump = qla24xx_fw_dump,
  1691. .beacon_on = qla24xx_beacon_on,
  1692. .beacon_off = qla24xx_beacon_off,
  1693. .beacon_blink = qla24xx_beacon_blink,
  1694. .read_optrom = qla24xx_read_optrom_data,
  1695. .write_optrom = qla24xx_write_optrom_data,
  1696. .get_flash_version = qla24xx_get_flash_version,
  1697. .start_scsi = qla24xx_start_scsi,
  1698. .abort_isp = qla2x00_abort_isp,
  1699. .iospace_config = qla2x00_iospace_config,
  1700. .initialize_adapter = qla2x00_initialize_adapter,
  1701. };
  1702. static struct isp_operations qla25xx_isp_ops = {
  1703. .pci_config = qla25xx_pci_config,
  1704. .reset_chip = qla24xx_reset_chip,
  1705. .chip_diag = qla24xx_chip_diag,
  1706. .config_rings = qla24xx_config_rings,
  1707. .reset_adapter = qla24xx_reset_adapter,
  1708. .nvram_config = qla24xx_nvram_config,
  1709. .update_fw_options = qla24xx_update_fw_options,
  1710. .load_risc = qla24xx_load_risc,
  1711. .pci_info_str = qla24xx_pci_info_str,
  1712. .fw_version_str = qla24xx_fw_version_str,
  1713. .intr_handler = qla24xx_intr_handler,
  1714. .enable_intrs = qla24xx_enable_intrs,
  1715. .disable_intrs = qla24xx_disable_intrs,
  1716. .abort_command = qla24xx_abort_command,
  1717. .target_reset = qla24xx_abort_target,
  1718. .lun_reset = qla24xx_lun_reset,
  1719. .fabric_login = qla24xx_login_fabric,
  1720. .fabric_logout = qla24xx_fabric_logout,
  1721. .calc_req_entries = NULL,
  1722. .build_iocbs = NULL,
  1723. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1724. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1725. .read_nvram = qla25xx_read_nvram_data,
  1726. .write_nvram = qla25xx_write_nvram_data,
  1727. .fw_dump = qla25xx_fw_dump,
  1728. .beacon_on = qla24xx_beacon_on,
  1729. .beacon_off = qla24xx_beacon_off,
  1730. .beacon_blink = qla24xx_beacon_blink,
  1731. .read_optrom = qla25xx_read_optrom_data,
  1732. .write_optrom = qla24xx_write_optrom_data,
  1733. .get_flash_version = qla24xx_get_flash_version,
  1734. .start_scsi = qla24xx_dif_start_scsi,
  1735. .abort_isp = qla2x00_abort_isp,
  1736. .iospace_config = qla2x00_iospace_config,
  1737. .initialize_adapter = qla2x00_initialize_adapter,
  1738. };
  1739. static struct isp_operations qla81xx_isp_ops = {
  1740. .pci_config = qla25xx_pci_config,
  1741. .reset_chip = qla24xx_reset_chip,
  1742. .chip_diag = qla24xx_chip_diag,
  1743. .config_rings = qla24xx_config_rings,
  1744. .reset_adapter = qla24xx_reset_adapter,
  1745. .nvram_config = qla81xx_nvram_config,
  1746. .update_fw_options = qla81xx_update_fw_options,
  1747. .load_risc = qla81xx_load_risc,
  1748. .pci_info_str = qla24xx_pci_info_str,
  1749. .fw_version_str = qla24xx_fw_version_str,
  1750. .intr_handler = qla24xx_intr_handler,
  1751. .enable_intrs = qla24xx_enable_intrs,
  1752. .disable_intrs = qla24xx_disable_intrs,
  1753. .abort_command = qla24xx_abort_command,
  1754. .target_reset = qla24xx_abort_target,
  1755. .lun_reset = qla24xx_lun_reset,
  1756. .fabric_login = qla24xx_login_fabric,
  1757. .fabric_logout = qla24xx_fabric_logout,
  1758. .calc_req_entries = NULL,
  1759. .build_iocbs = NULL,
  1760. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1761. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1762. .read_nvram = NULL,
  1763. .write_nvram = NULL,
  1764. .fw_dump = qla81xx_fw_dump,
  1765. .beacon_on = qla24xx_beacon_on,
  1766. .beacon_off = qla24xx_beacon_off,
  1767. .beacon_blink = qla83xx_beacon_blink,
  1768. .read_optrom = qla25xx_read_optrom_data,
  1769. .write_optrom = qla24xx_write_optrom_data,
  1770. .get_flash_version = qla24xx_get_flash_version,
  1771. .start_scsi = qla24xx_dif_start_scsi,
  1772. .abort_isp = qla2x00_abort_isp,
  1773. .iospace_config = qla2x00_iospace_config,
  1774. .initialize_adapter = qla2x00_initialize_adapter,
  1775. };
  1776. static struct isp_operations qla82xx_isp_ops = {
  1777. .pci_config = qla82xx_pci_config,
  1778. .reset_chip = qla82xx_reset_chip,
  1779. .chip_diag = qla24xx_chip_diag,
  1780. .config_rings = qla82xx_config_rings,
  1781. .reset_adapter = qla24xx_reset_adapter,
  1782. .nvram_config = qla81xx_nvram_config,
  1783. .update_fw_options = qla24xx_update_fw_options,
  1784. .load_risc = qla82xx_load_risc,
  1785. .pci_info_str = qla24xx_pci_info_str,
  1786. .fw_version_str = qla24xx_fw_version_str,
  1787. .intr_handler = qla82xx_intr_handler,
  1788. .enable_intrs = qla82xx_enable_intrs,
  1789. .disable_intrs = qla82xx_disable_intrs,
  1790. .abort_command = qla24xx_abort_command,
  1791. .target_reset = qla24xx_abort_target,
  1792. .lun_reset = qla24xx_lun_reset,
  1793. .fabric_login = qla24xx_login_fabric,
  1794. .fabric_logout = qla24xx_fabric_logout,
  1795. .calc_req_entries = NULL,
  1796. .build_iocbs = NULL,
  1797. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1798. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1799. .read_nvram = qla24xx_read_nvram_data,
  1800. .write_nvram = qla24xx_write_nvram_data,
  1801. .fw_dump = qla24xx_fw_dump,
  1802. .beacon_on = qla82xx_beacon_on,
  1803. .beacon_off = qla82xx_beacon_off,
  1804. .beacon_blink = NULL,
  1805. .read_optrom = qla82xx_read_optrom_data,
  1806. .write_optrom = qla82xx_write_optrom_data,
  1807. .get_flash_version = qla82xx_get_flash_version,
  1808. .start_scsi = qla82xx_start_scsi,
  1809. .abort_isp = qla82xx_abort_isp,
  1810. .iospace_config = qla82xx_iospace_config,
  1811. .initialize_adapter = qla2x00_initialize_adapter,
  1812. };
  1813. static struct isp_operations qla8044_isp_ops = {
  1814. .pci_config = qla82xx_pci_config,
  1815. .reset_chip = qla82xx_reset_chip,
  1816. .chip_diag = qla24xx_chip_diag,
  1817. .config_rings = qla82xx_config_rings,
  1818. .reset_adapter = qla24xx_reset_adapter,
  1819. .nvram_config = qla81xx_nvram_config,
  1820. .update_fw_options = qla24xx_update_fw_options,
  1821. .load_risc = qla82xx_load_risc,
  1822. .pci_info_str = qla24xx_pci_info_str,
  1823. .fw_version_str = qla24xx_fw_version_str,
  1824. .intr_handler = qla8044_intr_handler,
  1825. .enable_intrs = qla82xx_enable_intrs,
  1826. .disable_intrs = qla82xx_disable_intrs,
  1827. .abort_command = qla24xx_abort_command,
  1828. .target_reset = qla24xx_abort_target,
  1829. .lun_reset = qla24xx_lun_reset,
  1830. .fabric_login = qla24xx_login_fabric,
  1831. .fabric_logout = qla24xx_fabric_logout,
  1832. .calc_req_entries = NULL,
  1833. .build_iocbs = NULL,
  1834. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1835. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1836. .read_nvram = NULL,
  1837. .write_nvram = NULL,
  1838. .fw_dump = qla24xx_fw_dump,
  1839. .beacon_on = qla82xx_beacon_on,
  1840. .beacon_off = qla82xx_beacon_off,
  1841. .beacon_blink = NULL,
  1842. .read_optrom = qla82xx_read_optrom_data,
  1843. .write_optrom = qla8044_write_optrom_data,
  1844. .get_flash_version = qla82xx_get_flash_version,
  1845. .start_scsi = qla82xx_start_scsi,
  1846. .abort_isp = qla8044_abort_isp,
  1847. .iospace_config = qla82xx_iospace_config,
  1848. .initialize_adapter = qla2x00_initialize_adapter,
  1849. };
  1850. static struct isp_operations qla83xx_isp_ops = {
  1851. .pci_config = qla25xx_pci_config,
  1852. .reset_chip = qla24xx_reset_chip,
  1853. .chip_diag = qla24xx_chip_diag,
  1854. .config_rings = qla24xx_config_rings,
  1855. .reset_adapter = qla24xx_reset_adapter,
  1856. .nvram_config = qla81xx_nvram_config,
  1857. .update_fw_options = qla81xx_update_fw_options,
  1858. .load_risc = qla81xx_load_risc,
  1859. .pci_info_str = qla24xx_pci_info_str,
  1860. .fw_version_str = qla24xx_fw_version_str,
  1861. .intr_handler = qla24xx_intr_handler,
  1862. .enable_intrs = qla24xx_enable_intrs,
  1863. .disable_intrs = qla24xx_disable_intrs,
  1864. .abort_command = qla24xx_abort_command,
  1865. .target_reset = qla24xx_abort_target,
  1866. .lun_reset = qla24xx_lun_reset,
  1867. .fabric_login = qla24xx_login_fabric,
  1868. .fabric_logout = qla24xx_fabric_logout,
  1869. .calc_req_entries = NULL,
  1870. .build_iocbs = NULL,
  1871. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1872. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1873. .read_nvram = NULL,
  1874. .write_nvram = NULL,
  1875. .fw_dump = qla83xx_fw_dump,
  1876. .beacon_on = qla24xx_beacon_on,
  1877. .beacon_off = qla24xx_beacon_off,
  1878. .beacon_blink = qla83xx_beacon_blink,
  1879. .read_optrom = qla25xx_read_optrom_data,
  1880. .write_optrom = qla24xx_write_optrom_data,
  1881. .get_flash_version = qla24xx_get_flash_version,
  1882. .start_scsi = qla24xx_dif_start_scsi,
  1883. .abort_isp = qla2x00_abort_isp,
  1884. .iospace_config = qla83xx_iospace_config,
  1885. .initialize_adapter = qla2x00_initialize_adapter,
  1886. };
  1887. static struct isp_operations qlafx00_isp_ops = {
  1888. .pci_config = qlafx00_pci_config,
  1889. .reset_chip = qlafx00_soft_reset,
  1890. .chip_diag = qlafx00_chip_diag,
  1891. .config_rings = qlafx00_config_rings,
  1892. .reset_adapter = qlafx00_soft_reset,
  1893. .nvram_config = NULL,
  1894. .update_fw_options = NULL,
  1895. .load_risc = NULL,
  1896. .pci_info_str = qlafx00_pci_info_str,
  1897. .fw_version_str = qlafx00_fw_version_str,
  1898. .intr_handler = qlafx00_intr_handler,
  1899. .enable_intrs = qlafx00_enable_intrs,
  1900. .disable_intrs = qlafx00_disable_intrs,
  1901. .abort_command = qlafx00_abort_command,
  1902. .target_reset = qlafx00_abort_target,
  1903. .lun_reset = qlafx00_lun_reset,
  1904. .fabric_login = NULL,
  1905. .fabric_logout = NULL,
  1906. .calc_req_entries = NULL,
  1907. .build_iocbs = NULL,
  1908. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1909. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1910. .read_nvram = qla24xx_read_nvram_data,
  1911. .write_nvram = qla24xx_write_nvram_data,
  1912. .fw_dump = NULL,
  1913. .beacon_on = qla24xx_beacon_on,
  1914. .beacon_off = qla24xx_beacon_off,
  1915. .beacon_blink = NULL,
  1916. .read_optrom = qla24xx_read_optrom_data,
  1917. .write_optrom = qla24xx_write_optrom_data,
  1918. .get_flash_version = qla24xx_get_flash_version,
  1919. .start_scsi = qlafx00_start_scsi,
  1920. .abort_isp = qlafx00_abort_isp,
  1921. .iospace_config = qlafx00_iospace_config,
  1922. .initialize_adapter = qlafx00_initialize_adapter,
  1923. };
  1924. static inline void
  1925. qla2x00_set_isp_flags(struct qla_hw_data *ha)
  1926. {
  1927. ha->device_type = DT_EXTENDED_IDS;
  1928. switch (ha->pdev->device) {
  1929. case PCI_DEVICE_ID_QLOGIC_ISP2100:
  1930. ha->device_type |= DT_ISP2100;
  1931. ha->device_type &= ~DT_EXTENDED_IDS;
  1932. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1933. break;
  1934. case PCI_DEVICE_ID_QLOGIC_ISP2200:
  1935. ha->device_type |= DT_ISP2200;
  1936. ha->device_type &= ~DT_EXTENDED_IDS;
  1937. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1938. break;
  1939. case PCI_DEVICE_ID_QLOGIC_ISP2300:
  1940. ha->device_type |= DT_ISP2300;
  1941. ha->device_type |= DT_ZIO_SUPPORTED;
  1942. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1943. break;
  1944. case PCI_DEVICE_ID_QLOGIC_ISP2312:
  1945. ha->device_type |= DT_ISP2312;
  1946. ha->device_type |= DT_ZIO_SUPPORTED;
  1947. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1948. break;
  1949. case PCI_DEVICE_ID_QLOGIC_ISP2322:
  1950. ha->device_type |= DT_ISP2322;
  1951. ha->device_type |= DT_ZIO_SUPPORTED;
  1952. if (ha->pdev->subsystem_vendor == 0x1028 &&
  1953. ha->pdev->subsystem_device == 0x0170)
  1954. ha->device_type |= DT_OEM_001;
  1955. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1956. break;
  1957. case PCI_DEVICE_ID_QLOGIC_ISP6312:
  1958. ha->device_type |= DT_ISP6312;
  1959. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1960. break;
  1961. case PCI_DEVICE_ID_QLOGIC_ISP6322:
  1962. ha->device_type |= DT_ISP6322;
  1963. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1964. break;
  1965. case PCI_DEVICE_ID_QLOGIC_ISP2422:
  1966. ha->device_type |= DT_ISP2422;
  1967. ha->device_type |= DT_ZIO_SUPPORTED;
  1968. ha->device_type |= DT_FWI2;
  1969. ha->device_type |= DT_IIDMA;
  1970. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1971. break;
  1972. case PCI_DEVICE_ID_QLOGIC_ISP2432:
  1973. ha->device_type |= DT_ISP2432;
  1974. ha->device_type |= DT_ZIO_SUPPORTED;
  1975. ha->device_type |= DT_FWI2;
  1976. ha->device_type |= DT_IIDMA;
  1977. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1978. break;
  1979. case PCI_DEVICE_ID_QLOGIC_ISP8432:
  1980. ha->device_type |= DT_ISP8432;
  1981. ha->device_type |= DT_ZIO_SUPPORTED;
  1982. ha->device_type |= DT_FWI2;
  1983. ha->device_type |= DT_IIDMA;
  1984. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1985. break;
  1986. case PCI_DEVICE_ID_QLOGIC_ISP5422:
  1987. ha->device_type |= DT_ISP5422;
  1988. ha->device_type |= DT_FWI2;
  1989. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1990. break;
  1991. case PCI_DEVICE_ID_QLOGIC_ISP5432:
  1992. ha->device_type |= DT_ISP5432;
  1993. ha->device_type |= DT_FWI2;
  1994. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1995. break;
  1996. case PCI_DEVICE_ID_QLOGIC_ISP2532:
  1997. ha->device_type |= DT_ISP2532;
  1998. ha->device_type |= DT_ZIO_SUPPORTED;
  1999. ha->device_type |= DT_FWI2;
  2000. ha->device_type |= DT_IIDMA;
  2001. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2002. break;
  2003. case PCI_DEVICE_ID_QLOGIC_ISP8001:
  2004. ha->device_type |= DT_ISP8001;
  2005. ha->device_type |= DT_ZIO_SUPPORTED;
  2006. ha->device_type |= DT_FWI2;
  2007. ha->device_type |= DT_IIDMA;
  2008. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2009. break;
  2010. case PCI_DEVICE_ID_QLOGIC_ISP8021:
  2011. ha->device_type |= DT_ISP8021;
  2012. ha->device_type |= DT_ZIO_SUPPORTED;
  2013. ha->device_type |= DT_FWI2;
  2014. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2015. /* Initialize 82XX ISP flags */
  2016. qla82xx_init_flags(ha);
  2017. break;
  2018. case PCI_DEVICE_ID_QLOGIC_ISP8044:
  2019. ha->device_type |= DT_ISP8044;
  2020. ha->device_type |= DT_ZIO_SUPPORTED;
  2021. ha->device_type |= DT_FWI2;
  2022. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2023. /* Initialize 82XX ISP flags */
  2024. qla82xx_init_flags(ha);
  2025. break;
  2026. case PCI_DEVICE_ID_QLOGIC_ISP2031:
  2027. ha->device_type |= DT_ISP2031;
  2028. ha->device_type |= DT_ZIO_SUPPORTED;
  2029. ha->device_type |= DT_FWI2;
  2030. ha->device_type |= DT_IIDMA;
  2031. ha->device_type |= DT_T10_PI;
  2032. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2033. break;
  2034. case PCI_DEVICE_ID_QLOGIC_ISP8031:
  2035. ha->device_type |= DT_ISP8031;
  2036. ha->device_type |= DT_ZIO_SUPPORTED;
  2037. ha->device_type |= DT_FWI2;
  2038. ha->device_type |= DT_IIDMA;
  2039. ha->device_type |= DT_T10_PI;
  2040. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2041. break;
  2042. case PCI_DEVICE_ID_QLOGIC_ISPF001:
  2043. ha->device_type |= DT_ISPFX00;
  2044. break;
  2045. }
  2046. if (IS_QLA82XX(ha))
  2047. ha->port_no = !(ha->portnum & 1);
  2048. else
  2049. /* Get adapter physical port no from interrupt pin register. */
  2050. pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
  2051. if (ha->port_no & 1)
  2052. ha->flags.port0 = 1;
  2053. else
  2054. ha->flags.port0 = 0;
  2055. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
  2056. "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
  2057. ha->device_type, ha->flags.port0, ha->fw_srisc_address);
  2058. }
  2059. static void
  2060. qla2xxx_scan_start(struct Scsi_Host *shost)
  2061. {
  2062. scsi_qla_host_t *vha = shost_priv(shost);
  2063. if (vha->hw->flags.running_gold_fw)
  2064. return;
  2065. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2066. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2067. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  2068. set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
  2069. }
  2070. static int
  2071. qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
  2072. {
  2073. scsi_qla_host_t *vha = shost_priv(shost);
  2074. if (!vha->host)
  2075. return 1;
  2076. if (time > vha->hw->loop_reset_delay * HZ)
  2077. return 1;
  2078. return atomic_read(&vha->loop_state) == LOOP_READY;
  2079. }
  2080. /*
  2081. * PCI driver interface
  2082. */
  2083. static int
  2084. qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  2085. {
  2086. int ret = -ENODEV;
  2087. struct Scsi_Host *host;
  2088. scsi_qla_host_t *base_vha = NULL;
  2089. struct qla_hw_data *ha;
  2090. char pci_info[30];
  2091. char fw_str[30], wq_name[30];
  2092. struct scsi_host_template *sht;
  2093. int bars, mem_only = 0;
  2094. uint16_t req_length = 0, rsp_length = 0;
  2095. struct req_que *req = NULL;
  2096. struct rsp_que *rsp = NULL;
  2097. bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
  2098. sht = &qla2xxx_driver_template;
  2099. if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
  2100. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
  2101. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
  2102. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
  2103. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
  2104. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
  2105. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
  2106. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
  2107. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
  2108. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
  2109. pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
  2110. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044) {
  2111. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  2112. mem_only = 1;
  2113. ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
  2114. "Mem only adapter.\n");
  2115. }
  2116. ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
  2117. "Bars=%d.\n", bars);
  2118. if (mem_only) {
  2119. if (pci_enable_device_mem(pdev))
  2120. goto probe_out;
  2121. } else {
  2122. if (pci_enable_device(pdev))
  2123. goto probe_out;
  2124. }
  2125. /* This may fail but that's ok */
  2126. pci_enable_pcie_error_reporting(pdev);
  2127. ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
  2128. if (!ha) {
  2129. ql_log_pci(ql_log_fatal, pdev, 0x0009,
  2130. "Unable to allocate memory for ha.\n");
  2131. goto probe_out;
  2132. }
  2133. ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
  2134. "Memory allocated for ha=%p.\n", ha);
  2135. ha->pdev = pdev;
  2136. ha->tgt.enable_class_2 = ql2xenableclass2;
  2137. /* Clear our data area */
  2138. ha->bars = bars;
  2139. ha->mem_only = mem_only;
  2140. spin_lock_init(&ha->hardware_lock);
  2141. spin_lock_init(&ha->vport_slock);
  2142. mutex_init(&ha->selflogin_lock);
  2143. /* Set ISP-type information. */
  2144. qla2x00_set_isp_flags(ha);
  2145. /* Set EEH reset type to fundamental if required by hba */
  2146. if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
  2147. IS_QLA83XX(ha))
  2148. pdev->needs_freset = 1;
  2149. ha->prev_topology = 0;
  2150. ha->init_cb_size = sizeof(init_cb_t);
  2151. ha->link_data_rate = PORT_SPEED_UNKNOWN;
  2152. ha->optrom_size = OPTROM_SIZE_2300;
  2153. ha->cfg_lun_q_depth = ql2xmaxqdepth;
  2154. /* Assign ISP specific operations. */
  2155. if (IS_QLA2100(ha)) {
  2156. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
  2157. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  2158. req_length = REQUEST_ENTRY_CNT_2100;
  2159. rsp_length = RESPONSE_ENTRY_CNT_2100;
  2160. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  2161. ha->gid_list_info_size = 4;
  2162. ha->flash_conf_off = ~0;
  2163. ha->flash_data_off = ~0;
  2164. ha->nvram_conf_off = ~0;
  2165. ha->nvram_data_off = ~0;
  2166. ha->isp_ops = &qla2100_isp_ops;
  2167. } else if (IS_QLA2200(ha)) {
  2168. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
  2169. ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
  2170. req_length = REQUEST_ENTRY_CNT_2200;
  2171. rsp_length = RESPONSE_ENTRY_CNT_2100;
  2172. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  2173. ha->gid_list_info_size = 4;
  2174. ha->flash_conf_off = ~0;
  2175. ha->flash_data_off = ~0;
  2176. ha->nvram_conf_off = ~0;
  2177. ha->nvram_data_off = ~0;
  2178. ha->isp_ops = &qla2100_isp_ops;
  2179. } else if (IS_QLA23XX(ha)) {
  2180. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
  2181. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2182. req_length = REQUEST_ENTRY_CNT_2200;
  2183. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2184. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2185. ha->gid_list_info_size = 6;
  2186. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  2187. ha->optrom_size = OPTROM_SIZE_2322;
  2188. ha->flash_conf_off = ~0;
  2189. ha->flash_data_off = ~0;
  2190. ha->nvram_conf_off = ~0;
  2191. ha->nvram_data_off = ~0;
  2192. ha->isp_ops = &qla2300_isp_ops;
  2193. } else if (IS_QLA24XX_TYPE(ha)) {
  2194. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2195. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2196. req_length = REQUEST_ENTRY_CNT_24XX;
  2197. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2198. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2199. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2200. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  2201. ha->gid_list_info_size = 8;
  2202. ha->optrom_size = OPTROM_SIZE_24XX;
  2203. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
  2204. ha->isp_ops = &qla24xx_isp_ops;
  2205. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2206. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2207. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2208. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2209. } else if (IS_QLA25XX(ha)) {
  2210. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2211. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2212. req_length = REQUEST_ENTRY_CNT_24XX;
  2213. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2214. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2215. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2216. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  2217. ha->gid_list_info_size = 8;
  2218. ha->optrom_size = OPTROM_SIZE_25XX;
  2219. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2220. ha->isp_ops = &qla25xx_isp_ops;
  2221. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2222. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2223. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2224. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2225. } else if (IS_QLA81XX(ha)) {
  2226. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2227. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2228. req_length = REQUEST_ENTRY_CNT_24XX;
  2229. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2230. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2231. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2232. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2233. ha->gid_list_info_size = 8;
  2234. ha->optrom_size = OPTROM_SIZE_81XX;
  2235. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2236. ha->isp_ops = &qla81xx_isp_ops;
  2237. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  2238. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  2239. ha->nvram_conf_off = ~0;
  2240. ha->nvram_data_off = ~0;
  2241. } else if (IS_QLA82XX(ha)) {
  2242. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2243. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2244. req_length = REQUEST_ENTRY_CNT_82XX;
  2245. rsp_length = RESPONSE_ENTRY_CNT_82XX;
  2246. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2247. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2248. ha->gid_list_info_size = 8;
  2249. ha->optrom_size = OPTROM_SIZE_82XX;
  2250. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2251. ha->isp_ops = &qla82xx_isp_ops;
  2252. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2253. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2254. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2255. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2256. } else if (IS_QLA8044(ha)) {
  2257. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2258. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2259. req_length = REQUEST_ENTRY_CNT_82XX;
  2260. rsp_length = RESPONSE_ENTRY_CNT_82XX;
  2261. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2262. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2263. ha->gid_list_info_size = 8;
  2264. ha->optrom_size = OPTROM_SIZE_83XX;
  2265. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2266. ha->isp_ops = &qla8044_isp_ops;
  2267. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2268. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2269. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2270. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2271. } else if (IS_QLA83XX(ha)) {
  2272. ha->portnum = PCI_FUNC(ha->pdev->devfn);
  2273. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2274. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2275. req_length = REQUEST_ENTRY_CNT_24XX;
  2276. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2277. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2278. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2279. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2280. ha->gid_list_info_size = 8;
  2281. ha->optrom_size = OPTROM_SIZE_83XX;
  2282. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2283. ha->isp_ops = &qla83xx_isp_ops;
  2284. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  2285. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  2286. ha->nvram_conf_off = ~0;
  2287. ha->nvram_data_off = ~0;
  2288. } else if (IS_QLAFX00(ha)) {
  2289. ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
  2290. ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
  2291. ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
  2292. req_length = REQUEST_ENTRY_CNT_FX00;
  2293. rsp_length = RESPONSE_ENTRY_CNT_FX00;
  2294. ha->init_cb_size = sizeof(struct init_cb_fx);
  2295. ha->isp_ops = &qlafx00_isp_ops;
  2296. ha->port_down_retry_count = 30; /* default value */
  2297. ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
  2298. ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
  2299. ha->mr.fw_hbt_en = 1;
  2300. }
  2301. ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
  2302. "mbx_count=%d, req_length=%d, "
  2303. "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
  2304. "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
  2305. "max_fibre_devices=%d.\n",
  2306. ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
  2307. ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
  2308. ha->nvram_npiv_size, ha->max_fibre_devices);
  2309. ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
  2310. "isp_ops=%p, flash_conf_off=%d, "
  2311. "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
  2312. ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
  2313. ha->nvram_conf_off, ha->nvram_data_off);
  2314. /* Configure PCI I/O space */
  2315. ret = ha->isp_ops->iospace_config(ha);
  2316. if (ret)
  2317. goto iospace_config_failed;
  2318. ql_log_pci(ql_log_info, pdev, 0x001d,
  2319. "Found an ISP%04X irq %d iobase 0x%p.\n",
  2320. pdev->device, pdev->irq, ha->iobase);
  2321. mutex_init(&ha->vport_lock);
  2322. init_completion(&ha->mbx_cmd_comp);
  2323. complete(&ha->mbx_cmd_comp);
  2324. init_completion(&ha->mbx_intr_comp);
  2325. init_completion(&ha->dcbx_comp);
  2326. init_completion(&ha->lb_portup_comp);
  2327. set_bit(0, (unsigned long *) ha->vp_idx_map);
  2328. qla2x00_config_dma_addressing(ha);
  2329. ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
  2330. "64 Bit addressing is %s.\n",
  2331. ha->flags.enable_64bit_addressing ? "enable" :
  2332. "disable");
  2333. ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
  2334. if (!ret) {
  2335. ql_log_pci(ql_log_fatal, pdev, 0x0031,
  2336. "Failed to allocate memory for adapter, aborting.\n");
  2337. goto probe_hw_failed;
  2338. }
  2339. req->max_q_depth = MAX_Q_DEPTH;
  2340. if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
  2341. req->max_q_depth = ql2xmaxqdepth;
  2342. base_vha = qla2x00_create_host(sht, ha);
  2343. if (!base_vha) {
  2344. ret = -ENOMEM;
  2345. qla2x00_mem_free(ha);
  2346. qla2x00_free_req_que(ha, req);
  2347. qla2x00_free_rsp_que(ha, rsp);
  2348. goto probe_hw_failed;
  2349. }
  2350. pci_set_drvdata(pdev, base_vha);
  2351. host = base_vha->host;
  2352. base_vha->req = req;
  2353. if (IS_QLAFX00(ha))
  2354. host->can_queue = 1024;
  2355. else
  2356. host->can_queue = req->length + 128;
  2357. if (IS_QLA2XXX_MIDTYPE(ha))
  2358. base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
  2359. else
  2360. base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
  2361. base_vha->vp_idx;
  2362. /* Setup fcport template structure. */
  2363. ha->mr.fcport.vha = base_vha;
  2364. ha->mr.fcport.port_type = FCT_UNKNOWN;
  2365. ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
  2366. qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
  2367. ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
  2368. ha->mr.fcport.scan_state = 1;
  2369. /* Set the SG table size based on ISP type */
  2370. if (!IS_FWI2_CAPABLE(ha)) {
  2371. if (IS_QLA2100(ha))
  2372. host->sg_tablesize = 32;
  2373. } else {
  2374. if (!IS_QLA82XX(ha))
  2375. host->sg_tablesize = QLA_SG_ALL;
  2376. }
  2377. ql_dbg(ql_dbg_init, base_vha, 0x0032,
  2378. "can_queue=%d, req=%p, "
  2379. "mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
  2380. host->can_queue, base_vha->req,
  2381. base_vha->mgmt_svr_loop_id, host->sg_tablesize);
  2382. host->max_id = ha->max_fibre_devices;
  2383. host->cmd_per_lun = 3;
  2384. host->unique_id = host->host_no;
  2385. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
  2386. host->max_cmd_len = 32;
  2387. else
  2388. host->max_cmd_len = MAX_CMDSZ;
  2389. host->max_channel = MAX_BUSES - 1;
  2390. host->max_lun = ql2xmaxlun;
  2391. host->transportt = qla2xxx_transport_template;
  2392. sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
  2393. ql_dbg(ql_dbg_init, base_vha, 0x0033,
  2394. "max_id=%d this_id=%d "
  2395. "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
  2396. "max_lun=%d transportt=%p, vendor_id=%llu.\n", host->max_id,
  2397. host->this_id, host->cmd_per_lun, host->unique_id,
  2398. host->max_cmd_len, host->max_channel, host->max_lun,
  2399. host->transportt, sht->vendor_id);
  2400. que_init:
  2401. /* Alloc arrays of request and response ring ptrs */
  2402. if (!qla2x00_alloc_queues(ha, req, rsp)) {
  2403. ql_log(ql_log_fatal, base_vha, 0x003d,
  2404. "Failed to allocate memory for queue pointers..."
  2405. "aborting.\n");
  2406. goto probe_init_failed;
  2407. }
  2408. qlt_probe_one_stage1(base_vha, ha);
  2409. /* Set up the irqs */
  2410. ret = qla2x00_request_irqs(ha, rsp);
  2411. if (ret)
  2412. goto probe_init_failed;
  2413. pci_save_state(pdev);
  2414. /* Assign back pointers */
  2415. rsp->req = req;
  2416. req->rsp = rsp;
  2417. if (IS_QLAFX00(ha)) {
  2418. ha->rsp_q_map[0] = rsp;
  2419. ha->req_q_map[0] = req;
  2420. set_bit(0, ha->req_qid_map);
  2421. set_bit(0, ha->rsp_qid_map);
  2422. }
  2423. /* FWI2-capable only. */
  2424. req->req_q_in = &ha->iobase->isp24.req_q_in;
  2425. req->req_q_out = &ha->iobase->isp24.req_q_out;
  2426. rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
  2427. rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
  2428. if (ha->mqenable || IS_QLA83XX(ha)) {
  2429. req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
  2430. req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
  2431. rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
  2432. rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
  2433. }
  2434. if (IS_QLAFX00(ha)) {
  2435. req->req_q_in = &ha->iobase->ispfx00.req_q_in;
  2436. req->req_q_out = &ha->iobase->ispfx00.req_q_out;
  2437. rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
  2438. rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
  2439. }
  2440. if (IS_P3P_TYPE(ha)) {
  2441. req->req_q_out = &ha->iobase->isp82.req_q_out[0];
  2442. rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
  2443. rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
  2444. }
  2445. ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
  2446. "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
  2447. ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
  2448. ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
  2449. "req->req_q_in=%p req->req_q_out=%p "
  2450. "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
  2451. req->req_q_in, req->req_q_out,
  2452. rsp->rsp_q_in, rsp->rsp_q_out);
  2453. ql_dbg(ql_dbg_init, base_vha, 0x003e,
  2454. "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
  2455. ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
  2456. ql_dbg(ql_dbg_init, base_vha, 0x003f,
  2457. "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
  2458. req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
  2459. if (ha->isp_ops->initialize_adapter(base_vha)) {
  2460. ql_log(ql_log_fatal, base_vha, 0x00d6,
  2461. "Failed to initialize adapter - Adapter flags %x.\n",
  2462. base_vha->device_flags);
  2463. if (IS_QLA82XX(ha)) {
  2464. qla82xx_idc_lock(ha);
  2465. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  2466. QLA8XXX_DEV_FAILED);
  2467. qla82xx_idc_unlock(ha);
  2468. ql_log(ql_log_fatal, base_vha, 0x00d7,
  2469. "HW State: FAILED.\n");
  2470. } else if (IS_QLA8044(ha)) {
  2471. qla8044_idc_lock(ha);
  2472. qla8044_wr_direct(base_vha,
  2473. QLA8044_CRB_DEV_STATE_INDEX,
  2474. QLA8XXX_DEV_FAILED);
  2475. qla8044_idc_unlock(ha);
  2476. ql_log(ql_log_fatal, base_vha, 0x0150,
  2477. "HW State: FAILED.\n");
  2478. }
  2479. ret = -ENODEV;
  2480. goto probe_failed;
  2481. }
  2482. if (ha->mqenable) {
  2483. if (qla25xx_setup_mode(base_vha)) {
  2484. ql_log(ql_log_warn, base_vha, 0x00ec,
  2485. "Failed to create queues, falling back to single queue mode.\n");
  2486. goto que_init;
  2487. }
  2488. }
  2489. if (ha->flags.running_gold_fw)
  2490. goto skip_dpc;
  2491. /*
  2492. * Startup the kernel thread for this host adapter
  2493. */
  2494. ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
  2495. "%s_dpc", base_vha->host_str);
  2496. if (IS_ERR(ha->dpc_thread)) {
  2497. ql_log(ql_log_fatal, base_vha, 0x00ed,
  2498. "Failed to start DPC thread.\n");
  2499. ret = PTR_ERR(ha->dpc_thread);
  2500. goto probe_failed;
  2501. }
  2502. ql_dbg(ql_dbg_init, base_vha, 0x00ee,
  2503. "DPC thread started successfully.\n");
  2504. /*
  2505. * If we're not coming up in initiator mode, we might sit for
  2506. * a while without waking up the dpc thread, which leads to a
  2507. * stuck process warning. So just kick the dpc once here and
  2508. * let the kthread start (and go back to sleep in qla2x00_do_dpc).
  2509. */
  2510. qla2xxx_wake_dpc(base_vha);
  2511. if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
  2512. sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
  2513. ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
  2514. INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
  2515. sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
  2516. ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
  2517. INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
  2518. INIT_WORK(&ha->idc_state_handler,
  2519. qla83xx_idc_state_handler_work);
  2520. INIT_WORK(&ha->nic_core_unrecoverable,
  2521. qla83xx_nic_core_unrecoverable_work);
  2522. }
  2523. skip_dpc:
  2524. list_add_tail(&base_vha->list, &ha->vp_list);
  2525. base_vha->host->irq = ha->pdev->irq;
  2526. /* Initialized the timer */
  2527. qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
  2528. ql_dbg(ql_dbg_init, base_vha, 0x00ef,
  2529. "Started qla2x00_timer with "
  2530. "interval=%d.\n", WATCH_INTERVAL);
  2531. ql_dbg(ql_dbg_init, base_vha, 0x00f0,
  2532. "Detected hba at address=%p.\n",
  2533. ha);
  2534. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  2535. if (ha->fw_attributes & BIT_4) {
  2536. int prot = 0, guard;
  2537. base_vha->flags.difdix_supported = 1;
  2538. ql_dbg(ql_dbg_init, base_vha, 0x00f1,
  2539. "Registering for DIF/DIX type 1 and 3 protection.\n");
  2540. if (ql2xenabledif == 1)
  2541. prot = SHOST_DIX_TYPE0_PROTECTION;
  2542. scsi_host_set_prot(host,
  2543. prot | SHOST_DIF_TYPE1_PROTECTION
  2544. | SHOST_DIF_TYPE2_PROTECTION
  2545. | SHOST_DIF_TYPE3_PROTECTION
  2546. | SHOST_DIX_TYPE1_PROTECTION
  2547. | SHOST_DIX_TYPE2_PROTECTION
  2548. | SHOST_DIX_TYPE3_PROTECTION);
  2549. guard = SHOST_DIX_GUARD_CRC;
  2550. if (IS_PI_IPGUARD_CAPABLE(ha) &&
  2551. (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
  2552. guard |= SHOST_DIX_GUARD_IP;
  2553. scsi_host_set_guard(host, guard);
  2554. } else
  2555. base_vha->flags.difdix_supported = 0;
  2556. }
  2557. ha->isp_ops->enable_intrs(ha);
  2558. ret = scsi_add_host(host, &pdev->dev);
  2559. if (ret)
  2560. goto probe_failed;
  2561. base_vha->flags.init_done = 1;
  2562. base_vha->flags.online = 1;
  2563. ql_dbg(ql_dbg_init, base_vha, 0x00f2,
  2564. "Init done and hba is online.\n");
  2565. if (qla_ini_mode_enabled(base_vha))
  2566. scsi_scan_host(host);
  2567. else
  2568. ql_dbg(ql_dbg_init, base_vha, 0x0122,
  2569. "skipping scsi_scan_host() for non-initiator port\n");
  2570. qla2x00_alloc_sysfs_attr(base_vha);
  2571. if (IS_QLAFX00(ha)) {
  2572. ret = qlafx00_fx_disc(base_vha,
  2573. &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
  2574. ret = qlafx00_fx_disc(base_vha,
  2575. &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
  2576. /* Register system information */
  2577. ret = qlafx00_fx_disc(base_vha,
  2578. &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
  2579. }
  2580. qla2x00_init_host_attr(base_vha);
  2581. qla2x00_dfs_setup(base_vha);
  2582. ql_log(ql_log_info, base_vha, 0x00fb,
  2583. "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
  2584. ql_log(ql_log_info, base_vha, 0x00fc,
  2585. "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
  2586. pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
  2587. pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
  2588. base_vha->host_no,
  2589. ha->isp_ops->fw_version_str(base_vha, fw_str));
  2590. qlt_add_target(ha, base_vha);
  2591. return 0;
  2592. probe_init_failed:
  2593. qla2x00_free_req_que(ha, req);
  2594. ha->req_q_map[0] = NULL;
  2595. clear_bit(0, ha->req_qid_map);
  2596. qla2x00_free_rsp_que(ha, rsp);
  2597. ha->rsp_q_map[0] = NULL;
  2598. clear_bit(0, ha->rsp_qid_map);
  2599. ha->max_req_queues = ha->max_rsp_queues = 0;
  2600. probe_failed:
  2601. if (base_vha->timer_active)
  2602. qla2x00_stop_timer(base_vha);
  2603. base_vha->flags.online = 0;
  2604. if (ha->dpc_thread) {
  2605. struct task_struct *t = ha->dpc_thread;
  2606. ha->dpc_thread = NULL;
  2607. kthread_stop(t);
  2608. }
  2609. qla2x00_free_device(base_vha);
  2610. scsi_host_put(base_vha->host);
  2611. probe_hw_failed:
  2612. if (IS_QLA82XX(ha)) {
  2613. qla82xx_idc_lock(ha);
  2614. qla82xx_clear_drv_active(ha);
  2615. qla82xx_idc_unlock(ha);
  2616. }
  2617. if (IS_QLA8044(ha)) {
  2618. qla8044_idc_lock(ha);
  2619. qla8044_clear_drv_active(base_vha);
  2620. qla8044_idc_unlock(ha);
  2621. }
  2622. iospace_config_failed:
  2623. if (IS_P3P_TYPE(ha)) {
  2624. if (!ha->nx_pcibase)
  2625. iounmap((device_reg_t __iomem *)ha->nx_pcibase);
  2626. if (!ql2xdbwr)
  2627. iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
  2628. } else {
  2629. if (ha->iobase)
  2630. iounmap(ha->iobase);
  2631. if (ha->cregbase)
  2632. iounmap(ha->cregbase);
  2633. }
  2634. pci_release_selected_regions(ha->pdev, ha->bars);
  2635. kfree(ha);
  2636. ha = NULL;
  2637. probe_out:
  2638. pci_disable_device(pdev);
  2639. return ret;
  2640. }
  2641. static void
  2642. qla2x00_stop_dpc_thread(scsi_qla_host_t *vha)
  2643. {
  2644. struct qla_hw_data *ha = vha->hw;
  2645. struct task_struct *t = ha->dpc_thread;
  2646. if (ha->dpc_thread == NULL)
  2647. return;
  2648. /*
  2649. * qla2xxx_wake_dpc checks for ->dpc_thread
  2650. * so we need to zero it out.
  2651. */
  2652. ha->dpc_thread = NULL;
  2653. kthread_stop(t);
  2654. }
  2655. static void
  2656. qla2x00_shutdown(struct pci_dev *pdev)
  2657. {
  2658. scsi_qla_host_t *vha;
  2659. struct qla_hw_data *ha;
  2660. if (!atomic_read(&pdev->enable_cnt))
  2661. return;
  2662. vha = pci_get_drvdata(pdev);
  2663. ha = vha->hw;
  2664. /* Turn-off FCE trace */
  2665. if (ha->flags.fce_enabled) {
  2666. qla2x00_disable_fce_trace(vha, NULL, NULL);
  2667. ha->flags.fce_enabled = 0;
  2668. }
  2669. /* Turn-off EFT trace */
  2670. if (ha->eft)
  2671. qla2x00_disable_eft_trace(vha);
  2672. /* Stop currently executing firmware. */
  2673. qla2x00_try_to_stop_firmware(vha);
  2674. /* Turn adapter off line */
  2675. vha->flags.online = 0;
  2676. /* turn-off interrupts on the card */
  2677. if (ha->interrupts_on) {
  2678. vha->flags.init_done = 0;
  2679. ha->isp_ops->disable_intrs(ha);
  2680. }
  2681. qla2x00_free_irqs(vha);
  2682. qla2x00_free_fw_dump(ha);
  2683. }
  2684. static void
  2685. qla2x00_remove_one(struct pci_dev *pdev)
  2686. {
  2687. scsi_qla_host_t *base_vha, *vha;
  2688. struct qla_hw_data *ha;
  2689. unsigned long flags;
  2690. /*
  2691. * If the PCI device is disabled that means that probe failed and any
  2692. * resources should be have cleaned up on probe exit.
  2693. */
  2694. if (!atomic_read(&pdev->enable_cnt))
  2695. return;
  2696. base_vha = pci_get_drvdata(pdev);
  2697. ha = base_vha->hw;
  2698. ha->flags.host_shutting_down = 1;
  2699. set_bit(UNLOADING, &base_vha->dpc_flags);
  2700. mutex_lock(&ha->vport_lock);
  2701. while (ha->cur_vport_count) {
  2702. spin_lock_irqsave(&ha->vport_slock, flags);
  2703. BUG_ON(base_vha->list.next == &ha->vp_list);
  2704. /* This assumes first entry in ha->vp_list is always base vha */
  2705. vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
  2706. scsi_host_get(vha->host);
  2707. spin_unlock_irqrestore(&ha->vport_slock, flags);
  2708. mutex_unlock(&ha->vport_lock);
  2709. fc_vport_terminate(vha->fc_vport);
  2710. scsi_host_put(vha->host);
  2711. mutex_lock(&ha->vport_lock);
  2712. }
  2713. mutex_unlock(&ha->vport_lock);
  2714. if (IS_QLA8031(ha)) {
  2715. ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
  2716. "Clearing fcoe driver presence.\n");
  2717. if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
  2718. ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
  2719. "Error while clearing DRV-Presence.\n");
  2720. }
  2721. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  2722. qla2x00_dfs_remove(base_vha);
  2723. qla84xx_put_chip(base_vha);
  2724. /* Disable timer */
  2725. if (base_vha->timer_active)
  2726. qla2x00_stop_timer(base_vha);
  2727. base_vha->flags.online = 0;
  2728. /* Flush the work queue and remove it */
  2729. if (ha->wq) {
  2730. flush_workqueue(ha->wq);
  2731. destroy_workqueue(ha->wq);
  2732. ha->wq = NULL;
  2733. }
  2734. /* Cancel all work and destroy DPC workqueues */
  2735. if (ha->dpc_lp_wq) {
  2736. cancel_work_sync(&ha->idc_aen);
  2737. destroy_workqueue(ha->dpc_lp_wq);
  2738. ha->dpc_lp_wq = NULL;
  2739. }
  2740. if (ha->dpc_hp_wq) {
  2741. cancel_work_sync(&ha->nic_core_reset);
  2742. cancel_work_sync(&ha->idc_state_handler);
  2743. cancel_work_sync(&ha->nic_core_unrecoverable);
  2744. destroy_workqueue(ha->dpc_hp_wq);
  2745. ha->dpc_hp_wq = NULL;
  2746. }
  2747. /* Kill the kernel thread for this host */
  2748. if (ha->dpc_thread) {
  2749. struct task_struct *t = ha->dpc_thread;
  2750. /*
  2751. * qla2xxx_wake_dpc checks for ->dpc_thread
  2752. * so we need to zero it out.
  2753. */
  2754. ha->dpc_thread = NULL;
  2755. kthread_stop(t);
  2756. }
  2757. qlt_remove_target(ha, base_vha);
  2758. qla2x00_free_sysfs_attr(base_vha);
  2759. fc_remove_host(base_vha->host);
  2760. scsi_remove_host(base_vha->host);
  2761. qla2x00_free_device(base_vha);
  2762. scsi_host_put(base_vha->host);
  2763. if (IS_QLA8044(ha)) {
  2764. qla8044_idc_lock(ha);
  2765. qla8044_clear_drv_active(base_vha);
  2766. qla8044_idc_unlock(ha);
  2767. }
  2768. if (IS_QLA82XX(ha)) {
  2769. qla82xx_idc_lock(ha);
  2770. qla82xx_clear_drv_active(ha);
  2771. qla82xx_idc_unlock(ha);
  2772. iounmap((device_reg_t __iomem *)ha->nx_pcibase);
  2773. if (!ql2xdbwr)
  2774. iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
  2775. } else {
  2776. if (ha->iobase)
  2777. iounmap(ha->iobase);
  2778. if (ha->cregbase)
  2779. iounmap(ha->cregbase);
  2780. if (ha->mqiobase)
  2781. iounmap(ha->mqiobase);
  2782. if (IS_QLA83XX(ha) && ha->msixbase)
  2783. iounmap(ha->msixbase);
  2784. }
  2785. pci_release_selected_regions(ha->pdev, ha->bars);
  2786. kfree(ha);
  2787. ha = NULL;
  2788. pci_disable_pcie_error_reporting(pdev);
  2789. pci_disable_device(pdev);
  2790. pci_set_drvdata(pdev, NULL);
  2791. }
  2792. static void
  2793. qla2x00_free_device(scsi_qla_host_t *vha)
  2794. {
  2795. struct qla_hw_data *ha = vha->hw;
  2796. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  2797. /* Disable timer */
  2798. if (vha->timer_active)
  2799. qla2x00_stop_timer(vha);
  2800. qla2x00_stop_dpc_thread(vha);
  2801. qla25xx_delete_queues(vha);
  2802. if (ha->flags.fce_enabled)
  2803. qla2x00_disable_fce_trace(vha, NULL, NULL);
  2804. if (ha->eft)
  2805. qla2x00_disable_eft_trace(vha);
  2806. /* Stop currently executing firmware. */
  2807. qla2x00_try_to_stop_firmware(vha);
  2808. vha->flags.online = 0;
  2809. /* turn-off interrupts on the card */
  2810. if (ha->interrupts_on) {
  2811. vha->flags.init_done = 0;
  2812. ha->isp_ops->disable_intrs(ha);
  2813. }
  2814. qla2x00_free_irqs(vha);
  2815. qla2x00_free_fcports(vha);
  2816. qla2x00_mem_free(ha);
  2817. qla82xx_md_free(vha);
  2818. qla2x00_free_queues(ha);
  2819. }
  2820. void qla2x00_free_fcports(struct scsi_qla_host *vha)
  2821. {
  2822. fc_port_t *fcport, *tfcport;
  2823. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  2824. list_del(&fcport->list);
  2825. qla2x00_clear_loop_id(fcport);
  2826. kfree(fcport);
  2827. fcport = NULL;
  2828. }
  2829. }
  2830. static inline void
  2831. qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
  2832. int defer)
  2833. {
  2834. struct fc_rport *rport;
  2835. scsi_qla_host_t *base_vha;
  2836. unsigned long flags;
  2837. if (!fcport->rport)
  2838. return;
  2839. rport = fcport->rport;
  2840. if (defer) {
  2841. base_vha = pci_get_drvdata(vha->hw->pdev);
  2842. spin_lock_irqsave(vha->host->host_lock, flags);
  2843. fcport->drport = rport;
  2844. spin_unlock_irqrestore(vha->host->host_lock, flags);
  2845. set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  2846. qla2xxx_wake_dpc(base_vha);
  2847. } else {
  2848. fc_remote_port_delete(rport);
  2849. qlt_fc_port_deleted(vha, fcport);
  2850. }
  2851. }
  2852. /*
  2853. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  2854. *
  2855. * Input: ha = adapter block pointer. fcport = port structure pointer.
  2856. *
  2857. * Return: None.
  2858. *
  2859. * Context:
  2860. */
  2861. void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
  2862. int do_login, int defer)
  2863. {
  2864. if (IS_QLAFX00(vha->hw)) {
  2865. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2866. qla2x00_schedule_rport_del(vha, fcport, defer);
  2867. return;
  2868. }
  2869. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  2870. vha->vp_idx == fcport->vha->vp_idx) {
  2871. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2872. qla2x00_schedule_rport_del(vha, fcport, defer);
  2873. }
  2874. /*
  2875. * We may need to retry the login, so don't change the state of the
  2876. * port but do the retries.
  2877. */
  2878. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  2879. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2880. if (!do_login)
  2881. return;
  2882. if (fcport->login_retry == 0) {
  2883. fcport->login_retry = vha->hw->login_retry_count;
  2884. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  2885. ql_dbg(ql_dbg_disc, vha, 0x2067,
  2886. "Port login retry %8phN, id = 0x%04x retry cnt=%d.\n",
  2887. fcport->port_name, fcport->loop_id, fcport->login_retry);
  2888. }
  2889. }
  2890. /*
  2891. * qla2x00_mark_all_devices_lost
  2892. * Updates fcport state when device goes offline.
  2893. *
  2894. * Input:
  2895. * ha = adapter block pointer.
  2896. * fcport = port structure pointer.
  2897. *
  2898. * Return:
  2899. * None.
  2900. *
  2901. * Context:
  2902. */
  2903. void
  2904. qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
  2905. {
  2906. fc_port_t *fcport;
  2907. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2908. if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
  2909. continue;
  2910. /*
  2911. * No point in marking the device as lost, if the device is
  2912. * already DEAD.
  2913. */
  2914. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  2915. continue;
  2916. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  2917. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2918. if (defer)
  2919. qla2x00_schedule_rport_del(vha, fcport, defer);
  2920. else if (vha->vp_idx == fcport->vha->vp_idx)
  2921. qla2x00_schedule_rport_del(vha, fcport, defer);
  2922. }
  2923. }
  2924. }
  2925. /*
  2926. * qla2x00_mem_alloc
  2927. * Allocates adapter memory.
  2928. *
  2929. * Returns:
  2930. * 0 = success.
  2931. * !0 = failure.
  2932. */
  2933. static int
  2934. qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
  2935. struct req_que **req, struct rsp_que **rsp)
  2936. {
  2937. char name[16];
  2938. ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
  2939. &ha->init_cb_dma, GFP_KERNEL);
  2940. if (!ha->init_cb)
  2941. goto fail;
  2942. if (qlt_mem_alloc(ha) < 0)
  2943. goto fail_free_init_cb;
  2944. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
  2945. qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
  2946. if (!ha->gid_list)
  2947. goto fail_free_tgt_mem;
  2948. ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
  2949. if (!ha->srb_mempool)
  2950. goto fail_free_gid_list;
  2951. if (IS_P3P_TYPE(ha)) {
  2952. /* Allocate cache for CT6 Ctx. */
  2953. if (!ctx_cachep) {
  2954. ctx_cachep = kmem_cache_create("qla2xxx_ctx",
  2955. sizeof(struct ct6_dsd), 0,
  2956. SLAB_HWCACHE_ALIGN, NULL);
  2957. if (!ctx_cachep)
  2958. goto fail_free_gid_list;
  2959. }
  2960. ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
  2961. ctx_cachep);
  2962. if (!ha->ctx_mempool)
  2963. goto fail_free_srb_mempool;
  2964. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
  2965. "ctx_cachep=%p ctx_mempool=%p.\n",
  2966. ctx_cachep, ha->ctx_mempool);
  2967. }
  2968. /* Get memory for cached NVRAM */
  2969. ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
  2970. if (!ha->nvram)
  2971. goto fail_free_ctx_mempool;
  2972. snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
  2973. ha->pdev->device);
  2974. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2975. DMA_POOL_SIZE, 8, 0);
  2976. if (!ha->s_dma_pool)
  2977. goto fail_free_nvram;
  2978. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
  2979. "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
  2980. ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
  2981. if (IS_P3P_TYPE(ha) || ql2xenabledif) {
  2982. ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2983. DSD_LIST_DMA_POOL_SIZE, 8, 0);
  2984. if (!ha->dl_dma_pool) {
  2985. ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
  2986. "Failed to allocate memory for dl_dma_pool.\n");
  2987. goto fail_s_dma_pool;
  2988. }
  2989. ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2990. FCP_CMND_DMA_POOL_SIZE, 8, 0);
  2991. if (!ha->fcp_cmnd_dma_pool) {
  2992. ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
  2993. "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
  2994. goto fail_dl_dma_pool;
  2995. }
  2996. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
  2997. "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
  2998. ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
  2999. }
  3000. /* Allocate memory for SNS commands */
  3001. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  3002. /* Get consistent memory allocated for SNS commands */
  3003. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  3004. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
  3005. if (!ha->sns_cmd)
  3006. goto fail_dma_pool;
  3007. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
  3008. "sns_cmd: %p.\n", ha->sns_cmd);
  3009. } else {
  3010. /* Get consistent memory allocated for MS IOCB */
  3011. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  3012. &ha->ms_iocb_dma);
  3013. if (!ha->ms_iocb)
  3014. goto fail_dma_pool;
  3015. /* Get consistent memory allocated for CT SNS commands */
  3016. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  3017. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
  3018. if (!ha->ct_sns)
  3019. goto fail_free_ms_iocb;
  3020. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
  3021. "ms_iocb=%p ct_sns=%p.\n",
  3022. ha->ms_iocb, ha->ct_sns);
  3023. }
  3024. /* Allocate memory for request ring */
  3025. *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
  3026. if (!*req) {
  3027. ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
  3028. "Failed to allocate memory for req.\n");
  3029. goto fail_req;
  3030. }
  3031. (*req)->length = req_len;
  3032. (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
  3033. ((*req)->length + 1) * sizeof(request_t),
  3034. &(*req)->dma, GFP_KERNEL);
  3035. if (!(*req)->ring) {
  3036. ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
  3037. "Failed to allocate memory for req_ring.\n");
  3038. goto fail_req_ring;
  3039. }
  3040. /* Allocate memory for response ring */
  3041. *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
  3042. if (!*rsp) {
  3043. ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
  3044. "Failed to allocate memory for rsp.\n");
  3045. goto fail_rsp;
  3046. }
  3047. (*rsp)->hw = ha;
  3048. (*rsp)->length = rsp_len;
  3049. (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
  3050. ((*rsp)->length + 1) * sizeof(response_t),
  3051. &(*rsp)->dma, GFP_KERNEL);
  3052. if (!(*rsp)->ring) {
  3053. ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
  3054. "Failed to allocate memory for rsp_ring.\n");
  3055. goto fail_rsp_ring;
  3056. }
  3057. (*req)->rsp = *rsp;
  3058. (*rsp)->req = *req;
  3059. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
  3060. "req=%p req->length=%d req->ring=%p rsp=%p "
  3061. "rsp->length=%d rsp->ring=%p.\n",
  3062. *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
  3063. (*rsp)->ring);
  3064. /* Allocate memory for NVRAM data for vports */
  3065. if (ha->nvram_npiv_size) {
  3066. ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
  3067. ha->nvram_npiv_size, GFP_KERNEL);
  3068. if (!ha->npiv_info) {
  3069. ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
  3070. "Failed to allocate memory for npiv_info.\n");
  3071. goto fail_npiv_info;
  3072. }
  3073. } else
  3074. ha->npiv_info = NULL;
  3075. /* Get consistent memory allocated for EX-INIT-CB. */
  3076. if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha)) {
  3077. ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  3078. &ha->ex_init_cb_dma);
  3079. if (!ha->ex_init_cb)
  3080. goto fail_ex_init_cb;
  3081. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
  3082. "ex_init_cb=%p.\n", ha->ex_init_cb);
  3083. }
  3084. INIT_LIST_HEAD(&ha->gbl_dsd_list);
  3085. /* Get consistent memory allocated for Async Port-Database. */
  3086. if (!IS_FWI2_CAPABLE(ha)) {
  3087. ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  3088. &ha->async_pd_dma);
  3089. if (!ha->async_pd)
  3090. goto fail_async_pd;
  3091. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
  3092. "async_pd=%p.\n", ha->async_pd);
  3093. }
  3094. INIT_LIST_HEAD(&ha->vp_list);
  3095. /* Allocate memory for our loop_id bitmap */
  3096. ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
  3097. GFP_KERNEL);
  3098. if (!ha->loop_id_map)
  3099. goto fail_async_pd;
  3100. else {
  3101. qla2x00_set_reserved_loop_ids(ha);
  3102. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
  3103. "loop_id_map=%p. \n", ha->loop_id_map);
  3104. }
  3105. return 1;
  3106. fail_async_pd:
  3107. dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
  3108. fail_ex_init_cb:
  3109. kfree(ha->npiv_info);
  3110. fail_npiv_info:
  3111. dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
  3112. sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
  3113. (*rsp)->ring = NULL;
  3114. (*rsp)->dma = 0;
  3115. fail_rsp_ring:
  3116. kfree(*rsp);
  3117. fail_rsp:
  3118. dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
  3119. sizeof(request_t), (*req)->ring, (*req)->dma);
  3120. (*req)->ring = NULL;
  3121. (*req)->dma = 0;
  3122. fail_req_ring:
  3123. kfree(*req);
  3124. fail_req:
  3125. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  3126. ha->ct_sns, ha->ct_sns_dma);
  3127. ha->ct_sns = NULL;
  3128. ha->ct_sns_dma = 0;
  3129. fail_free_ms_iocb:
  3130. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  3131. ha->ms_iocb = NULL;
  3132. ha->ms_iocb_dma = 0;
  3133. fail_dma_pool:
  3134. if (IS_QLA82XX(ha) || ql2xenabledif) {
  3135. dma_pool_destroy(ha->fcp_cmnd_dma_pool);
  3136. ha->fcp_cmnd_dma_pool = NULL;
  3137. }
  3138. fail_dl_dma_pool:
  3139. if (IS_QLA82XX(ha) || ql2xenabledif) {
  3140. dma_pool_destroy(ha->dl_dma_pool);
  3141. ha->dl_dma_pool = NULL;
  3142. }
  3143. fail_s_dma_pool:
  3144. dma_pool_destroy(ha->s_dma_pool);
  3145. ha->s_dma_pool = NULL;
  3146. fail_free_nvram:
  3147. kfree(ha->nvram);
  3148. ha->nvram = NULL;
  3149. fail_free_ctx_mempool:
  3150. mempool_destroy(ha->ctx_mempool);
  3151. ha->ctx_mempool = NULL;
  3152. fail_free_srb_mempool:
  3153. mempool_destroy(ha->srb_mempool);
  3154. ha->srb_mempool = NULL;
  3155. fail_free_gid_list:
  3156. dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
  3157. ha->gid_list,
  3158. ha->gid_list_dma);
  3159. ha->gid_list = NULL;
  3160. ha->gid_list_dma = 0;
  3161. fail_free_tgt_mem:
  3162. qlt_mem_free(ha);
  3163. fail_free_init_cb:
  3164. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
  3165. ha->init_cb_dma);
  3166. ha->init_cb = NULL;
  3167. ha->init_cb_dma = 0;
  3168. fail:
  3169. ql_log(ql_log_fatal, NULL, 0x0030,
  3170. "Memory allocation failure.\n");
  3171. return -ENOMEM;
  3172. }
  3173. /*
  3174. * qla2x00_free_fw_dump
  3175. * Frees fw dump stuff.
  3176. *
  3177. * Input:
  3178. * ha = adapter block pointer
  3179. */
  3180. static void
  3181. qla2x00_free_fw_dump(struct qla_hw_data *ha)
  3182. {
  3183. if (ha->fce)
  3184. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
  3185. ha->fce_dma);
  3186. if (ha->fw_dump) {
  3187. if (ha->eft)
  3188. dma_free_coherent(&ha->pdev->dev,
  3189. ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
  3190. vfree(ha->fw_dump);
  3191. }
  3192. ha->fce = NULL;
  3193. ha->fce_dma = 0;
  3194. ha->eft = NULL;
  3195. ha->eft_dma = 0;
  3196. ha->fw_dump = NULL;
  3197. ha->fw_dumped = 0;
  3198. ha->fw_dump_reading = 0;
  3199. }
  3200. /*
  3201. * qla2x00_mem_free
  3202. * Frees all adapter allocated memory.
  3203. *
  3204. * Input:
  3205. * ha = adapter block pointer.
  3206. */
  3207. static void
  3208. qla2x00_mem_free(struct qla_hw_data *ha)
  3209. {
  3210. qla2x00_free_fw_dump(ha);
  3211. if (ha->mctp_dump)
  3212. dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
  3213. ha->mctp_dump_dma);
  3214. if (ha->srb_mempool)
  3215. mempool_destroy(ha->srb_mempool);
  3216. if (ha->dcbx_tlv)
  3217. dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  3218. ha->dcbx_tlv, ha->dcbx_tlv_dma);
  3219. if (ha->xgmac_data)
  3220. dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  3221. ha->xgmac_data, ha->xgmac_data_dma);
  3222. if (ha->sns_cmd)
  3223. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  3224. ha->sns_cmd, ha->sns_cmd_dma);
  3225. if (ha->ct_sns)
  3226. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  3227. ha->ct_sns, ha->ct_sns_dma);
  3228. if (ha->sfp_data)
  3229. dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
  3230. if (ha->ms_iocb)
  3231. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  3232. if (ha->ex_init_cb)
  3233. dma_pool_free(ha->s_dma_pool,
  3234. ha->ex_init_cb, ha->ex_init_cb_dma);
  3235. if (ha->async_pd)
  3236. dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
  3237. if (ha->s_dma_pool)
  3238. dma_pool_destroy(ha->s_dma_pool);
  3239. if (ha->gid_list)
  3240. dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
  3241. ha->gid_list, ha->gid_list_dma);
  3242. if (IS_QLA82XX(ha)) {
  3243. if (!list_empty(&ha->gbl_dsd_list)) {
  3244. struct dsd_dma *dsd_ptr, *tdsd_ptr;
  3245. /* clean up allocated prev pool */
  3246. list_for_each_entry_safe(dsd_ptr,
  3247. tdsd_ptr, &ha->gbl_dsd_list, list) {
  3248. dma_pool_free(ha->dl_dma_pool,
  3249. dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
  3250. list_del(&dsd_ptr->list);
  3251. kfree(dsd_ptr);
  3252. }
  3253. }
  3254. }
  3255. if (ha->dl_dma_pool)
  3256. dma_pool_destroy(ha->dl_dma_pool);
  3257. if (ha->fcp_cmnd_dma_pool)
  3258. dma_pool_destroy(ha->fcp_cmnd_dma_pool);
  3259. if (ha->ctx_mempool)
  3260. mempool_destroy(ha->ctx_mempool);
  3261. qlt_mem_free(ha);
  3262. if (ha->init_cb)
  3263. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
  3264. ha->init_cb, ha->init_cb_dma);
  3265. vfree(ha->optrom_buffer);
  3266. kfree(ha->nvram);
  3267. kfree(ha->npiv_info);
  3268. kfree(ha->swl);
  3269. kfree(ha->loop_id_map);
  3270. ha->srb_mempool = NULL;
  3271. ha->ctx_mempool = NULL;
  3272. ha->sns_cmd = NULL;
  3273. ha->sns_cmd_dma = 0;
  3274. ha->ct_sns = NULL;
  3275. ha->ct_sns_dma = 0;
  3276. ha->ms_iocb = NULL;
  3277. ha->ms_iocb_dma = 0;
  3278. ha->init_cb = NULL;
  3279. ha->init_cb_dma = 0;
  3280. ha->ex_init_cb = NULL;
  3281. ha->ex_init_cb_dma = 0;
  3282. ha->async_pd = NULL;
  3283. ha->async_pd_dma = 0;
  3284. ha->s_dma_pool = NULL;
  3285. ha->dl_dma_pool = NULL;
  3286. ha->fcp_cmnd_dma_pool = NULL;
  3287. ha->gid_list = NULL;
  3288. ha->gid_list_dma = 0;
  3289. ha->tgt.atio_ring = NULL;
  3290. ha->tgt.atio_dma = 0;
  3291. ha->tgt.tgt_vp_map = NULL;
  3292. }
  3293. struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
  3294. struct qla_hw_data *ha)
  3295. {
  3296. struct Scsi_Host *host;
  3297. struct scsi_qla_host *vha = NULL;
  3298. host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
  3299. if (host == NULL) {
  3300. ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
  3301. "Failed to allocate host from the scsi layer, aborting.\n");
  3302. goto fail;
  3303. }
  3304. /* Clear our data area */
  3305. vha = shost_priv(host);
  3306. memset(vha, 0, sizeof(scsi_qla_host_t));
  3307. vha->host = host;
  3308. vha->host_no = host->host_no;
  3309. vha->hw = ha;
  3310. INIT_LIST_HEAD(&vha->vp_fcports);
  3311. INIT_LIST_HEAD(&vha->work_list);
  3312. INIT_LIST_HEAD(&vha->list);
  3313. spin_lock_init(&vha->work_lock);
  3314. sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
  3315. ql_dbg(ql_dbg_init, vha, 0x0041,
  3316. "Allocated the host=%p hw=%p vha=%p dev_name=%s",
  3317. vha->host, vha->hw, vha,
  3318. dev_name(&(ha->pdev->dev)));
  3319. return vha;
  3320. fail:
  3321. return vha;
  3322. }
  3323. static struct qla_work_evt *
  3324. qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
  3325. {
  3326. struct qla_work_evt *e;
  3327. uint8_t bail;
  3328. QLA_VHA_MARK_BUSY(vha, bail);
  3329. if (bail)
  3330. return NULL;
  3331. e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
  3332. if (!e) {
  3333. QLA_VHA_MARK_NOT_BUSY(vha);
  3334. return NULL;
  3335. }
  3336. INIT_LIST_HEAD(&e->list);
  3337. e->type = type;
  3338. e->flags = QLA_EVT_FLAG_FREE;
  3339. return e;
  3340. }
  3341. static int
  3342. qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
  3343. {
  3344. unsigned long flags;
  3345. spin_lock_irqsave(&vha->work_lock, flags);
  3346. list_add_tail(&e->list, &vha->work_list);
  3347. spin_unlock_irqrestore(&vha->work_lock, flags);
  3348. qla2xxx_wake_dpc(vha);
  3349. return QLA_SUCCESS;
  3350. }
  3351. int
  3352. qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
  3353. u32 data)
  3354. {
  3355. struct qla_work_evt *e;
  3356. e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
  3357. if (!e)
  3358. return QLA_FUNCTION_FAILED;
  3359. e->u.aen.code = code;
  3360. e->u.aen.data = data;
  3361. return qla2x00_post_work(vha, e);
  3362. }
  3363. int
  3364. qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
  3365. {
  3366. struct qla_work_evt *e;
  3367. e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
  3368. if (!e)
  3369. return QLA_FUNCTION_FAILED;
  3370. memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
  3371. return qla2x00_post_work(vha, e);
  3372. }
  3373. #define qla2x00_post_async_work(name, type) \
  3374. int qla2x00_post_async_##name##_work( \
  3375. struct scsi_qla_host *vha, \
  3376. fc_port_t *fcport, uint16_t *data) \
  3377. { \
  3378. struct qla_work_evt *e; \
  3379. \
  3380. e = qla2x00_alloc_work(vha, type); \
  3381. if (!e) \
  3382. return QLA_FUNCTION_FAILED; \
  3383. \
  3384. e->u.logio.fcport = fcport; \
  3385. if (data) { \
  3386. e->u.logio.data[0] = data[0]; \
  3387. e->u.logio.data[1] = data[1]; \
  3388. } \
  3389. return qla2x00_post_work(vha, e); \
  3390. }
  3391. qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
  3392. qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
  3393. qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
  3394. qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
  3395. qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
  3396. qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
  3397. int
  3398. qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
  3399. {
  3400. struct qla_work_evt *e;
  3401. e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
  3402. if (!e)
  3403. return QLA_FUNCTION_FAILED;
  3404. e->u.uevent.code = code;
  3405. return qla2x00_post_work(vha, e);
  3406. }
  3407. static void
  3408. qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
  3409. {
  3410. char event_string[40];
  3411. char *envp[] = { event_string, NULL };
  3412. switch (code) {
  3413. case QLA_UEVENT_CODE_FW_DUMP:
  3414. snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
  3415. vha->host_no);
  3416. break;
  3417. default:
  3418. /* do nothing */
  3419. break;
  3420. }
  3421. kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
  3422. }
  3423. int
  3424. qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
  3425. uint32_t *data, int cnt)
  3426. {
  3427. struct qla_work_evt *e;
  3428. e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
  3429. if (!e)
  3430. return QLA_FUNCTION_FAILED;
  3431. e->u.aenfx.evtcode = evtcode;
  3432. e->u.aenfx.count = cnt;
  3433. memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
  3434. return qla2x00_post_work(vha, e);
  3435. }
  3436. void
  3437. qla2x00_do_work(struct scsi_qla_host *vha)
  3438. {
  3439. struct qla_work_evt *e, *tmp;
  3440. unsigned long flags;
  3441. LIST_HEAD(work);
  3442. spin_lock_irqsave(&vha->work_lock, flags);
  3443. list_splice_init(&vha->work_list, &work);
  3444. spin_unlock_irqrestore(&vha->work_lock, flags);
  3445. list_for_each_entry_safe(e, tmp, &work, list) {
  3446. list_del_init(&e->list);
  3447. switch (e->type) {
  3448. case QLA_EVT_AEN:
  3449. fc_host_post_event(vha->host, fc_get_event_number(),
  3450. e->u.aen.code, e->u.aen.data);
  3451. break;
  3452. case QLA_EVT_IDC_ACK:
  3453. qla81xx_idc_ack(vha, e->u.idc_ack.mb);
  3454. break;
  3455. case QLA_EVT_ASYNC_LOGIN:
  3456. qla2x00_async_login(vha, e->u.logio.fcport,
  3457. e->u.logio.data);
  3458. break;
  3459. case QLA_EVT_ASYNC_LOGIN_DONE:
  3460. qla2x00_async_login_done(vha, e->u.logio.fcport,
  3461. e->u.logio.data);
  3462. break;
  3463. case QLA_EVT_ASYNC_LOGOUT:
  3464. qla2x00_async_logout(vha, e->u.logio.fcport);
  3465. break;
  3466. case QLA_EVT_ASYNC_LOGOUT_DONE:
  3467. qla2x00_async_logout_done(vha, e->u.logio.fcport,
  3468. e->u.logio.data);
  3469. break;
  3470. case QLA_EVT_ASYNC_ADISC:
  3471. qla2x00_async_adisc(vha, e->u.logio.fcport,
  3472. e->u.logio.data);
  3473. break;
  3474. case QLA_EVT_ASYNC_ADISC_DONE:
  3475. qla2x00_async_adisc_done(vha, e->u.logio.fcport,
  3476. e->u.logio.data);
  3477. break;
  3478. case QLA_EVT_UEVENT:
  3479. qla2x00_uevent_emit(vha, e->u.uevent.code);
  3480. break;
  3481. case QLA_EVT_AENFX:
  3482. qlafx00_process_aen(vha, e);
  3483. break;
  3484. }
  3485. if (e->flags & QLA_EVT_FLAG_FREE)
  3486. kfree(e);
  3487. /* For each work completed decrement vha ref count */
  3488. QLA_VHA_MARK_NOT_BUSY(vha);
  3489. }
  3490. }
  3491. /* Relogins all the fcports of a vport
  3492. * Context: dpc thread
  3493. */
  3494. void qla2x00_relogin(struct scsi_qla_host *vha)
  3495. {
  3496. fc_port_t *fcport;
  3497. int status;
  3498. uint16_t next_loopid = 0;
  3499. struct qla_hw_data *ha = vha->hw;
  3500. uint16_t data[2];
  3501. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3502. /*
  3503. * If the port is not ONLINE then try to login
  3504. * to it if we haven't run out of retries.
  3505. */
  3506. if (atomic_read(&fcport->state) != FCS_ONLINE &&
  3507. fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
  3508. fcport->login_retry--;
  3509. if (fcport->flags & FCF_FABRIC_DEVICE) {
  3510. if (fcport->flags & FCF_FCP2_DEVICE)
  3511. ha->isp_ops->fabric_logout(vha,
  3512. fcport->loop_id,
  3513. fcport->d_id.b.domain,
  3514. fcport->d_id.b.area,
  3515. fcport->d_id.b.al_pa);
  3516. if (fcport->loop_id == FC_NO_LOOP_ID) {
  3517. fcport->loop_id = next_loopid =
  3518. ha->min_external_loopid;
  3519. status = qla2x00_find_new_loop_id(
  3520. vha, fcport);
  3521. if (status != QLA_SUCCESS) {
  3522. /* Ran out of IDs to use */
  3523. break;
  3524. }
  3525. }
  3526. if (IS_ALOGIO_CAPABLE(ha)) {
  3527. fcport->flags |= FCF_ASYNC_SENT;
  3528. data[0] = 0;
  3529. data[1] = QLA_LOGIO_LOGIN_RETRIED;
  3530. status = qla2x00_post_async_login_work(
  3531. vha, fcport, data);
  3532. if (status == QLA_SUCCESS)
  3533. continue;
  3534. /* Attempt a retry. */
  3535. status = 1;
  3536. } else {
  3537. status = qla2x00_fabric_login(vha,
  3538. fcport, &next_loopid);
  3539. if (status == QLA_SUCCESS) {
  3540. int status2;
  3541. uint8_t opts;
  3542. opts = 0;
  3543. if (fcport->flags &
  3544. FCF_FCP2_DEVICE)
  3545. opts |= BIT_1;
  3546. status2 =
  3547. qla2x00_get_port_database(
  3548. vha, fcport, opts);
  3549. if (status2 != QLA_SUCCESS)
  3550. status = 1;
  3551. }
  3552. }
  3553. } else
  3554. status = qla2x00_local_device_login(vha,
  3555. fcport);
  3556. if (status == QLA_SUCCESS) {
  3557. fcport->old_loop_id = fcport->loop_id;
  3558. ql_dbg(ql_dbg_disc, vha, 0x2003,
  3559. "Port login OK: logged in ID 0x%x.\n",
  3560. fcport->loop_id);
  3561. qla2x00_update_fcport(vha, fcport);
  3562. } else if (status == 1) {
  3563. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  3564. /* retry the login again */
  3565. ql_dbg(ql_dbg_disc, vha, 0x2007,
  3566. "Retrying %d login again loop_id 0x%x.\n",
  3567. fcport->login_retry, fcport->loop_id);
  3568. } else {
  3569. fcport->login_retry = 0;
  3570. }
  3571. if (fcport->login_retry == 0 && status != QLA_SUCCESS)
  3572. qla2x00_clear_loop_id(fcport);
  3573. }
  3574. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  3575. break;
  3576. }
  3577. }
  3578. /* Schedule work on any of the dpc-workqueues */
  3579. void
  3580. qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
  3581. {
  3582. struct qla_hw_data *ha = base_vha->hw;
  3583. switch (work_code) {
  3584. case MBA_IDC_AEN: /* 0x8200 */
  3585. if (ha->dpc_lp_wq)
  3586. queue_work(ha->dpc_lp_wq, &ha->idc_aen);
  3587. break;
  3588. case QLA83XX_NIC_CORE_RESET: /* 0x1 */
  3589. if (!ha->flags.nic_core_reset_hdlr_active) {
  3590. if (ha->dpc_hp_wq)
  3591. queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
  3592. } else
  3593. ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
  3594. "NIC Core reset is already active. Skip "
  3595. "scheduling it again.\n");
  3596. break;
  3597. case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
  3598. if (ha->dpc_hp_wq)
  3599. queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
  3600. break;
  3601. case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
  3602. if (ha->dpc_hp_wq)
  3603. queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
  3604. break;
  3605. default:
  3606. ql_log(ql_log_warn, base_vha, 0xb05f,
  3607. "Unknow work-code=0x%x.\n", work_code);
  3608. }
  3609. return;
  3610. }
  3611. /* Work: Perform NIC Core Unrecoverable state handling */
  3612. void
  3613. qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
  3614. {
  3615. struct qla_hw_data *ha =
  3616. container_of(work, struct qla_hw_data, nic_core_unrecoverable);
  3617. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3618. uint32_t dev_state = 0;
  3619. qla83xx_idc_lock(base_vha, 0);
  3620. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3621. qla83xx_reset_ownership(base_vha);
  3622. if (ha->flags.nic_core_reset_owner) {
  3623. ha->flags.nic_core_reset_owner = 0;
  3624. qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
  3625. QLA8XXX_DEV_FAILED);
  3626. ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
  3627. qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
  3628. }
  3629. qla83xx_idc_unlock(base_vha, 0);
  3630. }
  3631. /* Work: Execute IDC state handler */
  3632. void
  3633. qla83xx_idc_state_handler_work(struct work_struct *work)
  3634. {
  3635. struct qla_hw_data *ha =
  3636. container_of(work, struct qla_hw_data, idc_state_handler);
  3637. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3638. uint32_t dev_state = 0;
  3639. qla83xx_idc_lock(base_vha, 0);
  3640. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3641. if (dev_state == QLA8XXX_DEV_FAILED ||
  3642. dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
  3643. qla83xx_idc_state_handler(base_vha);
  3644. qla83xx_idc_unlock(base_vha, 0);
  3645. }
  3646. static int
  3647. qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
  3648. {
  3649. int rval = QLA_SUCCESS;
  3650. unsigned long heart_beat_wait = jiffies + (1 * HZ);
  3651. uint32_t heart_beat_counter1, heart_beat_counter2;
  3652. do {
  3653. if (time_after(jiffies, heart_beat_wait)) {
  3654. ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
  3655. "Nic Core f/w is not alive.\n");
  3656. rval = QLA_FUNCTION_FAILED;
  3657. break;
  3658. }
  3659. qla83xx_idc_lock(base_vha, 0);
  3660. qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
  3661. &heart_beat_counter1);
  3662. qla83xx_idc_unlock(base_vha, 0);
  3663. msleep(100);
  3664. qla83xx_idc_lock(base_vha, 0);
  3665. qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
  3666. &heart_beat_counter2);
  3667. qla83xx_idc_unlock(base_vha, 0);
  3668. } while (heart_beat_counter1 == heart_beat_counter2);
  3669. return rval;
  3670. }
  3671. /* Work: Perform NIC Core Reset handling */
  3672. void
  3673. qla83xx_nic_core_reset_work(struct work_struct *work)
  3674. {
  3675. struct qla_hw_data *ha =
  3676. container_of(work, struct qla_hw_data, nic_core_reset);
  3677. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3678. uint32_t dev_state = 0;
  3679. if (IS_QLA2031(ha)) {
  3680. if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
  3681. ql_log(ql_log_warn, base_vha, 0xb081,
  3682. "Failed to dump mctp\n");
  3683. return;
  3684. }
  3685. if (!ha->flags.nic_core_reset_hdlr_active) {
  3686. if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
  3687. qla83xx_idc_lock(base_vha, 0);
  3688. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
  3689. &dev_state);
  3690. qla83xx_idc_unlock(base_vha, 0);
  3691. if (dev_state != QLA8XXX_DEV_NEED_RESET) {
  3692. ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
  3693. "Nic Core f/w is alive.\n");
  3694. return;
  3695. }
  3696. }
  3697. ha->flags.nic_core_reset_hdlr_active = 1;
  3698. if (qla83xx_nic_core_reset(base_vha)) {
  3699. /* NIC Core reset failed. */
  3700. ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
  3701. "NIC Core reset failed.\n");
  3702. }
  3703. ha->flags.nic_core_reset_hdlr_active = 0;
  3704. }
  3705. }
  3706. /* Work: Handle 8200 IDC aens */
  3707. void
  3708. qla83xx_service_idc_aen(struct work_struct *work)
  3709. {
  3710. struct qla_hw_data *ha =
  3711. container_of(work, struct qla_hw_data, idc_aen);
  3712. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3713. uint32_t dev_state, idc_control;
  3714. qla83xx_idc_lock(base_vha, 0);
  3715. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3716. qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
  3717. qla83xx_idc_unlock(base_vha, 0);
  3718. if (dev_state == QLA8XXX_DEV_NEED_RESET) {
  3719. if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
  3720. ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
  3721. "Application requested NIC Core Reset.\n");
  3722. qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
  3723. } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
  3724. QLA_SUCCESS) {
  3725. ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
  3726. "Other protocol driver requested NIC Core Reset.\n");
  3727. qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
  3728. }
  3729. } else if (dev_state == QLA8XXX_DEV_FAILED ||
  3730. dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
  3731. qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
  3732. }
  3733. }
  3734. static void
  3735. qla83xx_wait_logic(void)
  3736. {
  3737. int i;
  3738. /* Yield CPU */
  3739. if (!in_interrupt()) {
  3740. /*
  3741. * Wait about 200ms before retrying again.
  3742. * This controls the number of retries for single
  3743. * lock operation.
  3744. */
  3745. msleep(100);
  3746. schedule();
  3747. } else {
  3748. for (i = 0; i < 20; i++)
  3749. cpu_relax(); /* This a nop instr on i386 */
  3750. }
  3751. }
  3752. static int
  3753. qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
  3754. {
  3755. int rval;
  3756. uint32_t data;
  3757. uint32_t idc_lck_rcvry_stage_mask = 0x3;
  3758. uint32_t idc_lck_rcvry_owner_mask = 0x3c;
  3759. struct qla_hw_data *ha = base_vha->hw;
  3760. ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
  3761. "Trying force recovery of the IDC lock.\n");
  3762. rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
  3763. if (rval)
  3764. return rval;
  3765. if ((data & idc_lck_rcvry_stage_mask) > 0) {
  3766. return QLA_SUCCESS;
  3767. } else {
  3768. data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
  3769. rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
  3770. data);
  3771. if (rval)
  3772. return rval;
  3773. msleep(200);
  3774. rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
  3775. &data);
  3776. if (rval)
  3777. return rval;
  3778. if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
  3779. data &= (IDC_LOCK_RECOVERY_STAGE2 |
  3780. ~(idc_lck_rcvry_stage_mask));
  3781. rval = qla83xx_wr_reg(base_vha,
  3782. QLA83XX_IDC_LOCK_RECOVERY, data);
  3783. if (rval)
  3784. return rval;
  3785. /* Forcefully perform IDC UnLock */
  3786. rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
  3787. &data);
  3788. if (rval)
  3789. return rval;
  3790. /* Clear lock-id by setting 0xff */
  3791. rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
  3792. 0xff);
  3793. if (rval)
  3794. return rval;
  3795. /* Clear lock-recovery by setting 0x0 */
  3796. rval = qla83xx_wr_reg(base_vha,
  3797. QLA83XX_IDC_LOCK_RECOVERY, 0x0);
  3798. if (rval)
  3799. return rval;
  3800. } else
  3801. return QLA_SUCCESS;
  3802. }
  3803. return rval;
  3804. }
  3805. static int
  3806. qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
  3807. {
  3808. int rval = QLA_SUCCESS;
  3809. uint32_t o_drv_lockid, n_drv_lockid;
  3810. unsigned long lock_recovery_timeout;
  3811. lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
  3812. retry_lockid:
  3813. rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
  3814. if (rval)
  3815. goto exit;
  3816. /* MAX wait time before forcing IDC Lock recovery = 2 secs */
  3817. if (time_after_eq(jiffies, lock_recovery_timeout)) {
  3818. if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
  3819. return QLA_SUCCESS;
  3820. else
  3821. return QLA_FUNCTION_FAILED;
  3822. }
  3823. rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
  3824. if (rval)
  3825. goto exit;
  3826. if (o_drv_lockid == n_drv_lockid) {
  3827. qla83xx_wait_logic();
  3828. goto retry_lockid;
  3829. } else
  3830. return QLA_SUCCESS;
  3831. exit:
  3832. return rval;
  3833. }
  3834. void
  3835. qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
  3836. {
  3837. uint16_t options = (requester_id << 15) | BIT_6;
  3838. uint32_t data;
  3839. uint32_t lock_owner;
  3840. struct qla_hw_data *ha = base_vha->hw;
  3841. /* IDC-lock implementation using driver-lock/lock-id remote registers */
  3842. retry_lock:
  3843. if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
  3844. == QLA_SUCCESS) {
  3845. if (data) {
  3846. /* Setting lock-id to our function-number */
  3847. qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
  3848. ha->portnum);
  3849. } else {
  3850. qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
  3851. &lock_owner);
  3852. ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
  3853. "Failed to acquire IDC lock, acquired by %d, "
  3854. "retrying...\n", lock_owner);
  3855. /* Retry/Perform IDC-Lock recovery */
  3856. if (qla83xx_idc_lock_recovery(base_vha)
  3857. == QLA_SUCCESS) {
  3858. qla83xx_wait_logic();
  3859. goto retry_lock;
  3860. } else
  3861. ql_log(ql_log_warn, base_vha, 0xb075,
  3862. "IDC Lock recovery FAILED.\n");
  3863. }
  3864. }
  3865. return;
  3866. /* XXX: IDC-lock implementation using access-control mbx */
  3867. retry_lock2:
  3868. if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
  3869. ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
  3870. "Failed to acquire IDC lock. retrying...\n");
  3871. /* Retry/Perform IDC-Lock recovery */
  3872. if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
  3873. qla83xx_wait_logic();
  3874. goto retry_lock2;
  3875. } else
  3876. ql_log(ql_log_warn, base_vha, 0xb076,
  3877. "IDC Lock recovery FAILED.\n");
  3878. }
  3879. return;
  3880. }
  3881. void
  3882. qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
  3883. {
  3884. uint16_t options = (requester_id << 15) | BIT_7, retry;
  3885. uint32_t data;
  3886. struct qla_hw_data *ha = base_vha->hw;
  3887. /* IDC-unlock implementation using driver-unlock/lock-id
  3888. * remote registers
  3889. */
  3890. retry = 0;
  3891. retry_unlock:
  3892. if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
  3893. == QLA_SUCCESS) {
  3894. if (data == ha->portnum) {
  3895. qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
  3896. /* Clearing lock-id by setting 0xff */
  3897. qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
  3898. } else if (retry < 10) {
  3899. /* SV: XXX: IDC unlock retrying needed here? */
  3900. /* Retry for IDC-unlock */
  3901. qla83xx_wait_logic();
  3902. retry++;
  3903. ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
  3904. "Failed to release IDC lock, retyring=%d\n", retry);
  3905. goto retry_unlock;
  3906. }
  3907. } else if (retry < 10) {
  3908. /* Retry for IDC-unlock */
  3909. qla83xx_wait_logic();
  3910. retry++;
  3911. ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
  3912. "Failed to read drv-lockid, retyring=%d\n", retry);
  3913. goto retry_unlock;
  3914. }
  3915. return;
  3916. /* XXX: IDC-unlock implementation using access-control mbx */
  3917. retry = 0;
  3918. retry_unlock2:
  3919. if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
  3920. if (retry < 10) {
  3921. /* Retry for IDC-unlock */
  3922. qla83xx_wait_logic();
  3923. retry++;
  3924. ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
  3925. "Failed to release IDC lock, retyring=%d\n", retry);
  3926. goto retry_unlock2;
  3927. }
  3928. }
  3929. return;
  3930. }
  3931. int
  3932. __qla83xx_set_drv_presence(scsi_qla_host_t *vha)
  3933. {
  3934. int rval = QLA_SUCCESS;
  3935. struct qla_hw_data *ha = vha->hw;
  3936. uint32_t drv_presence;
  3937. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3938. if (rval == QLA_SUCCESS) {
  3939. drv_presence |= (1 << ha->portnum);
  3940. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
  3941. drv_presence);
  3942. }
  3943. return rval;
  3944. }
  3945. int
  3946. qla83xx_set_drv_presence(scsi_qla_host_t *vha)
  3947. {
  3948. int rval = QLA_SUCCESS;
  3949. qla83xx_idc_lock(vha, 0);
  3950. rval = __qla83xx_set_drv_presence(vha);
  3951. qla83xx_idc_unlock(vha, 0);
  3952. return rval;
  3953. }
  3954. int
  3955. __qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
  3956. {
  3957. int rval = QLA_SUCCESS;
  3958. struct qla_hw_data *ha = vha->hw;
  3959. uint32_t drv_presence;
  3960. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3961. if (rval == QLA_SUCCESS) {
  3962. drv_presence &= ~(1 << ha->portnum);
  3963. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
  3964. drv_presence);
  3965. }
  3966. return rval;
  3967. }
  3968. int
  3969. qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
  3970. {
  3971. int rval = QLA_SUCCESS;
  3972. qla83xx_idc_lock(vha, 0);
  3973. rval = __qla83xx_clear_drv_presence(vha);
  3974. qla83xx_idc_unlock(vha, 0);
  3975. return rval;
  3976. }
  3977. static void
  3978. qla83xx_need_reset_handler(scsi_qla_host_t *vha)
  3979. {
  3980. struct qla_hw_data *ha = vha->hw;
  3981. uint32_t drv_ack, drv_presence;
  3982. unsigned long ack_timeout;
  3983. /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
  3984. ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
  3985. while (1) {
  3986. qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
  3987. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3988. if ((drv_ack & drv_presence) == drv_presence)
  3989. break;
  3990. if (time_after_eq(jiffies, ack_timeout)) {
  3991. ql_log(ql_log_warn, vha, 0xb067,
  3992. "RESET ACK TIMEOUT! drv_presence=0x%x "
  3993. "drv_ack=0x%x\n", drv_presence, drv_ack);
  3994. /*
  3995. * The function(s) which did not ack in time are forced
  3996. * to withdraw any further participation in the IDC
  3997. * reset.
  3998. */
  3999. if (drv_ack != drv_presence)
  4000. qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
  4001. drv_ack);
  4002. break;
  4003. }
  4004. qla83xx_idc_unlock(vha, 0);
  4005. msleep(1000);
  4006. qla83xx_idc_lock(vha, 0);
  4007. }
  4008. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
  4009. ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
  4010. }
  4011. static int
  4012. qla83xx_device_bootstrap(scsi_qla_host_t *vha)
  4013. {
  4014. int rval = QLA_SUCCESS;
  4015. uint32_t idc_control;
  4016. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
  4017. ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
  4018. /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
  4019. __qla83xx_get_idc_control(vha, &idc_control);
  4020. idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
  4021. __qla83xx_set_idc_control(vha, 0);
  4022. qla83xx_idc_unlock(vha, 0);
  4023. rval = qla83xx_restart_nic_firmware(vha);
  4024. qla83xx_idc_lock(vha, 0);
  4025. if (rval != QLA_SUCCESS) {
  4026. ql_log(ql_log_fatal, vha, 0xb06a,
  4027. "Failed to restart NIC f/w.\n");
  4028. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
  4029. ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
  4030. } else {
  4031. ql_dbg(ql_dbg_p3p, vha, 0xb06c,
  4032. "Success in restarting nic f/w.\n");
  4033. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
  4034. ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
  4035. }
  4036. return rval;
  4037. }
  4038. /* Assumes idc_lock always held on entry */
  4039. int
  4040. qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
  4041. {
  4042. struct qla_hw_data *ha = base_vha->hw;
  4043. int rval = QLA_SUCCESS;
  4044. unsigned long dev_init_timeout;
  4045. uint32_t dev_state;
  4046. /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
  4047. dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
  4048. while (1) {
  4049. if (time_after_eq(jiffies, dev_init_timeout)) {
  4050. ql_log(ql_log_warn, base_vha, 0xb06e,
  4051. "Initialization TIMEOUT!\n");
  4052. /* Init timeout. Disable further NIC Core
  4053. * communication.
  4054. */
  4055. qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
  4056. QLA8XXX_DEV_FAILED);
  4057. ql_log(ql_log_info, base_vha, 0xb06f,
  4058. "HW State: FAILED.\n");
  4059. }
  4060. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  4061. switch (dev_state) {
  4062. case QLA8XXX_DEV_READY:
  4063. if (ha->flags.nic_core_reset_owner)
  4064. qla83xx_idc_audit(base_vha,
  4065. IDC_AUDIT_COMPLETION);
  4066. ha->flags.nic_core_reset_owner = 0;
  4067. ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
  4068. "Reset_owner reset by 0x%x.\n",
  4069. ha->portnum);
  4070. goto exit;
  4071. case QLA8XXX_DEV_COLD:
  4072. if (ha->flags.nic_core_reset_owner)
  4073. rval = qla83xx_device_bootstrap(base_vha);
  4074. else {
  4075. /* Wait for AEN to change device-state */
  4076. qla83xx_idc_unlock(base_vha, 0);
  4077. msleep(1000);
  4078. qla83xx_idc_lock(base_vha, 0);
  4079. }
  4080. break;
  4081. case QLA8XXX_DEV_INITIALIZING:
  4082. /* Wait for AEN to change device-state */
  4083. qla83xx_idc_unlock(base_vha, 0);
  4084. msleep(1000);
  4085. qla83xx_idc_lock(base_vha, 0);
  4086. break;
  4087. case QLA8XXX_DEV_NEED_RESET:
  4088. if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
  4089. qla83xx_need_reset_handler(base_vha);
  4090. else {
  4091. /* Wait for AEN to change device-state */
  4092. qla83xx_idc_unlock(base_vha, 0);
  4093. msleep(1000);
  4094. qla83xx_idc_lock(base_vha, 0);
  4095. }
  4096. /* reset timeout value after need reset handler */
  4097. dev_init_timeout = jiffies +
  4098. (ha->fcoe_dev_init_timeout * HZ);
  4099. break;
  4100. case QLA8XXX_DEV_NEED_QUIESCENT:
  4101. /* XXX: DEBUG for now */
  4102. qla83xx_idc_unlock(base_vha, 0);
  4103. msleep(1000);
  4104. qla83xx_idc_lock(base_vha, 0);
  4105. break;
  4106. case QLA8XXX_DEV_QUIESCENT:
  4107. /* XXX: DEBUG for now */
  4108. if (ha->flags.quiesce_owner)
  4109. goto exit;
  4110. qla83xx_idc_unlock(base_vha, 0);
  4111. msleep(1000);
  4112. qla83xx_idc_lock(base_vha, 0);
  4113. dev_init_timeout = jiffies +
  4114. (ha->fcoe_dev_init_timeout * HZ);
  4115. break;
  4116. case QLA8XXX_DEV_FAILED:
  4117. if (ha->flags.nic_core_reset_owner)
  4118. qla83xx_idc_audit(base_vha,
  4119. IDC_AUDIT_COMPLETION);
  4120. ha->flags.nic_core_reset_owner = 0;
  4121. __qla83xx_clear_drv_presence(base_vha);
  4122. qla83xx_idc_unlock(base_vha, 0);
  4123. qla8xxx_dev_failed_handler(base_vha);
  4124. rval = QLA_FUNCTION_FAILED;
  4125. qla83xx_idc_lock(base_vha, 0);
  4126. goto exit;
  4127. case QLA8XXX_BAD_VALUE:
  4128. qla83xx_idc_unlock(base_vha, 0);
  4129. msleep(1000);
  4130. qla83xx_idc_lock(base_vha, 0);
  4131. break;
  4132. default:
  4133. ql_log(ql_log_warn, base_vha, 0xb071,
  4134. "Unknow Device State: %x.\n", dev_state);
  4135. qla83xx_idc_unlock(base_vha, 0);
  4136. qla8xxx_dev_failed_handler(base_vha);
  4137. rval = QLA_FUNCTION_FAILED;
  4138. qla83xx_idc_lock(base_vha, 0);
  4139. goto exit;
  4140. }
  4141. }
  4142. exit:
  4143. return rval;
  4144. }
  4145. /**************************************************************************
  4146. * qla2x00_do_dpc
  4147. * This kernel thread is a task that is schedule by the interrupt handler
  4148. * to perform the background processing for interrupts.
  4149. *
  4150. * Notes:
  4151. * This task always run in the context of a kernel thread. It
  4152. * is kick-off by the driver's detect code and starts up
  4153. * up one per adapter. It immediately goes to sleep and waits for
  4154. * some fibre event. When either the interrupt handler or
  4155. * the timer routine detects a event it will one of the task
  4156. * bits then wake us up.
  4157. **************************************************************************/
  4158. static int
  4159. qla2x00_do_dpc(void *data)
  4160. {
  4161. int rval;
  4162. scsi_qla_host_t *base_vha;
  4163. struct qla_hw_data *ha;
  4164. ha = (struct qla_hw_data *)data;
  4165. base_vha = pci_get_drvdata(ha->pdev);
  4166. set_user_nice(current, -20);
  4167. set_current_state(TASK_INTERRUPTIBLE);
  4168. while (!kthread_should_stop()) {
  4169. ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
  4170. "DPC handler sleeping.\n");
  4171. schedule();
  4172. __set_current_state(TASK_RUNNING);
  4173. if (!base_vha->flags.init_done || ha->flags.mbox_busy)
  4174. goto end_loop;
  4175. if (ha->flags.eeh_busy) {
  4176. ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
  4177. "eeh_busy=%d.\n", ha->flags.eeh_busy);
  4178. goto end_loop;
  4179. }
  4180. ha->dpc_active = 1;
  4181. ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
  4182. "DPC handler waking up, dpc_flags=0x%lx.\n",
  4183. base_vha->dpc_flags);
  4184. qla2x00_do_work(base_vha);
  4185. if (IS_P3P_TYPE(ha)) {
  4186. if (IS_QLA8044(ha)) {
  4187. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  4188. &base_vha->dpc_flags)) {
  4189. qla8044_idc_lock(ha);
  4190. qla8044_wr_direct(base_vha,
  4191. QLA8044_CRB_DEV_STATE_INDEX,
  4192. QLA8XXX_DEV_FAILED);
  4193. qla8044_idc_unlock(ha);
  4194. ql_log(ql_log_info, base_vha, 0x4004,
  4195. "HW State: FAILED.\n");
  4196. qla8044_device_state_handler(base_vha);
  4197. continue;
  4198. }
  4199. } else {
  4200. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  4201. &base_vha->dpc_flags)) {
  4202. qla82xx_idc_lock(ha);
  4203. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  4204. QLA8XXX_DEV_FAILED);
  4205. qla82xx_idc_unlock(ha);
  4206. ql_log(ql_log_info, base_vha, 0x0151,
  4207. "HW State: FAILED.\n");
  4208. qla82xx_device_state_handler(base_vha);
  4209. continue;
  4210. }
  4211. }
  4212. if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
  4213. &base_vha->dpc_flags)) {
  4214. ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
  4215. "FCoE context reset scheduled.\n");
  4216. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  4217. &base_vha->dpc_flags))) {
  4218. if (qla82xx_fcoe_ctx_reset(base_vha)) {
  4219. /* FCoE-ctx reset failed.
  4220. * Escalate to chip-reset
  4221. */
  4222. set_bit(ISP_ABORT_NEEDED,
  4223. &base_vha->dpc_flags);
  4224. }
  4225. clear_bit(ABORT_ISP_ACTIVE,
  4226. &base_vha->dpc_flags);
  4227. }
  4228. ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
  4229. "FCoE context reset end.\n");
  4230. }
  4231. } else if (IS_QLAFX00(ha)) {
  4232. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  4233. &base_vha->dpc_flags)) {
  4234. ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
  4235. "Firmware Reset Recovery\n");
  4236. if (qlafx00_reset_initialize(base_vha)) {
  4237. /* Failed. Abort isp later. */
  4238. if (!test_bit(UNLOADING,
  4239. &base_vha->dpc_flags))
  4240. set_bit(ISP_UNRECOVERABLE,
  4241. &base_vha->dpc_flags);
  4242. ql_dbg(ql_dbg_dpc, base_vha,
  4243. 0x4021,
  4244. "Reset Recovery Failed\n");
  4245. }
  4246. }
  4247. if (test_and_clear_bit(FX00_TARGET_SCAN,
  4248. &base_vha->dpc_flags)) {
  4249. ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
  4250. "ISPFx00 Target Scan scheduled\n");
  4251. if (qlafx00_rescan_isp(base_vha)) {
  4252. if (!test_bit(UNLOADING,
  4253. &base_vha->dpc_flags))
  4254. set_bit(ISP_UNRECOVERABLE,
  4255. &base_vha->dpc_flags);
  4256. ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
  4257. "ISPFx00 Target Scan Failed\n");
  4258. }
  4259. ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
  4260. "ISPFx00 Target Scan End\n");
  4261. }
  4262. }
  4263. if (test_and_clear_bit(ISP_ABORT_NEEDED,
  4264. &base_vha->dpc_flags)) {
  4265. ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
  4266. "ISP abort scheduled.\n");
  4267. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  4268. &base_vha->dpc_flags))) {
  4269. if (ha->isp_ops->abort_isp(base_vha)) {
  4270. /* failed. retry later */
  4271. set_bit(ISP_ABORT_NEEDED,
  4272. &base_vha->dpc_flags);
  4273. }
  4274. clear_bit(ABORT_ISP_ACTIVE,
  4275. &base_vha->dpc_flags);
  4276. }
  4277. ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
  4278. "ISP abort end.\n");
  4279. }
  4280. if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
  4281. &base_vha->dpc_flags)) {
  4282. qla2x00_update_fcports(base_vha);
  4283. }
  4284. if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
  4285. int ret;
  4286. ret = qla2x00_send_change_request(base_vha, 0x3, 0);
  4287. if (ret != QLA_SUCCESS)
  4288. ql_log(ql_log_warn, base_vha, 0x121,
  4289. "Failed to enable receiving of RSCN "
  4290. "requests: 0x%x.\n", ret);
  4291. clear_bit(SCR_PENDING, &base_vha->dpc_flags);
  4292. }
  4293. if (IS_QLAFX00(ha))
  4294. goto loop_resync_check;
  4295. if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
  4296. ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
  4297. "Quiescence mode scheduled.\n");
  4298. if (IS_P3P_TYPE(ha)) {
  4299. if (IS_QLA82XX(ha))
  4300. qla82xx_device_state_handler(base_vha);
  4301. if (IS_QLA8044(ha))
  4302. qla8044_device_state_handler(base_vha);
  4303. clear_bit(ISP_QUIESCE_NEEDED,
  4304. &base_vha->dpc_flags);
  4305. if (!ha->flags.quiesce_owner) {
  4306. qla2x00_perform_loop_resync(base_vha);
  4307. if (IS_QLA82XX(ha)) {
  4308. qla82xx_idc_lock(ha);
  4309. qla82xx_clear_qsnt_ready(
  4310. base_vha);
  4311. qla82xx_idc_unlock(ha);
  4312. } else if (IS_QLA8044(ha)) {
  4313. qla8044_idc_lock(ha);
  4314. qla8044_clear_qsnt_ready(
  4315. base_vha);
  4316. qla8044_idc_unlock(ha);
  4317. }
  4318. }
  4319. } else {
  4320. clear_bit(ISP_QUIESCE_NEEDED,
  4321. &base_vha->dpc_flags);
  4322. qla2x00_quiesce_io(base_vha);
  4323. }
  4324. ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
  4325. "Quiescence mode end.\n");
  4326. }
  4327. if (test_and_clear_bit(RESET_MARKER_NEEDED,
  4328. &base_vha->dpc_flags) &&
  4329. (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
  4330. ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
  4331. "Reset marker scheduled.\n");
  4332. qla2x00_rst_aen(base_vha);
  4333. clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
  4334. ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
  4335. "Reset marker end.\n");
  4336. }
  4337. /* Retry each device up to login retry count */
  4338. if ((test_and_clear_bit(RELOGIN_NEEDED,
  4339. &base_vha->dpc_flags)) &&
  4340. !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
  4341. atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
  4342. ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
  4343. "Relogin scheduled.\n");
  4344. qla2x00_relogin(base_vha);
  4345. ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
  4346. "Relogin end.\n");
  4347. }
  4348. loop_resync_check:
  4349. if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
  4350. &base_vha->dpc_flags)) {
  4351. ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
  4352. "Loop resync scheduled.\n");
  4353. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
  4354. &base_vha->dpc_flags))) {
  4355. rval = qla2x00_loop_resync(base_vha);
  4356. clear_bit(LOOP_RESYNC_ACTIVE,
  4357. &base_vha->dpc_flags);
  4358. }
  4359. ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
  4360. "Loop resync end.\n");
  4361. }
  4362. if (IS_QLAFX00(ha))
  4363. goto intr_on_check;
  4364. if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
  4365. atomic_read(&base_vha->loop_state) == LOOP_READY) {
  4366. clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
  4367. qla2xxx_flash_npiv_conf(base_vha);
  4368. }
  4369. if (test_and_clear_bit(HOST_RAMP_DOWN_QUEUE_DEPTH,
  4370. &base_vha->dpc_flags)) {
  4371. /* Prevents simultaneous ramp up and down */
  4372. clear_bit(HOST_RAMP_UP_QUEUE_DEPTH,
  4373. &base_vha->dpc_flags);
  4374. qla2x00_host_ramp_down_queuedepth(base_vha);
  4375. }
  4376. if (test_and_clear_bit(HOST_RAMP_UP_QUEUE_DEPTH,
  4377. &base_vha->dpc_flags))
  4378. qla2x00_host_ramp_up_queuedepth(base_vha);
  4379. intr_on_check:
  4380. if (!ha->interrupts_on)
  4381. ha->isp_ops->enable_intrs(ha);
  4382. if (test_and_clear_bit(BEACON_BLINK_NEEDED,
  4383. &base_vha->dpc_flags))
  4384. ha->isp_ops->beacon_blink(base_vha);
  4385. if (!IS_QLAFX00(ha))
  4386. qla2x00_do_dpc_all_vps(base_vha);
  4387. ha->dpc_active = 0;
  4388. end_loop:
  4389. set_current_state(TASK_INTERRUPTIBLE);
  4390. } /* End of while(1) */
  4391. __set_current_state(TASK_RUNNING);
  4392. ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
  4393. "DPC handler exiting.\n");
  4394. /*
  4395. * Make sure that nobody tries to wake us up again.
  4396. */
  4397. ha->dpc_active = 0;
  4398. /* Cleanup any residual CTX SRBs. */
  4399. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  4400. return 0;
  4401. }
  4402. void
  4403. qla2xxx_wake_dpc(struct scsi_qla_host *vha)
  4404. {
  4405. struct qla_hw_data *ha = vha->hw;
  4406. struct task_struct *t = ha->dpc_thread;
  4407. if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
  4408. wake_up_process(t);
  4409. }
  4410. /*
  4411. * qla2x00_rst_aen
  4412. * Processes asynchronous reset.
  4413. *
  4414. * Input:
  4415. * ha = adapter block pointer.
  4416. */
  4417. static void
  4418. qla2x00_rst_aen(scsi_qla_host_t *vha)
  4419. {
  4420. if (vha->flags.online && !vha->flags.reset_active &&
  4421. !atomic_read(&vha->loop_down_timer) &&
  4422. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
  4423. do {
  4424. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4425. /*
  4426. * Issue marker command only when we are going to start
  4427. * the I/O.
  4428. */
  4429. vha->marker_needed = 1;
  4430. } while (!atomic_read(&vha->loop_down_timer) &&
  4431. (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
  4432. }
  4433. }
  4434. /**************************************************************************
  4435. * qla2x00_timer
  4436. *
  4437. * Description:
  4438. * One second timer
  4439. *
  4440. * Context: Interrupt
  4441. ***************************************************************************/
  4442. void
  4443. qla2x00_timer(scsi_qla_host_t *vha)
  4444. {
  4445. unsigned long cpu_flags = 0;
  4446. int start_dpc = 0;
  4447. int index;
  4448. srb_t *sp;
  4449. uint16_t w;
  4450. struct qla_hw_data *ha = vha->hw;
  4451. struct req_que *req;
  4452. if (ha->flags.eeh_busy) {
  4453. ql_dbg(ql_dbg_timer, vha, 0x6000,
  4454. "EEH = %d, restarting timer.\n",
  4455. ha->flags.eeh_busy);
  4456. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  4457. return;
  4458. }
  4459. /* Hardware read to raise pending EEH errors during mailbox waits. */
  4460. if (!pci_channel_offline(ha->pdev))
  4461. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  4462. /* Make sure qla82xx_watchdog is run only for physical port */
  4463. if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
  4464. if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
  4465. start_dpc++;
  4466. if (IS_QLA82XX(ha))
  4467. qla82xx_watchdog(vha);
  4468. else if (IS_QLA8044(ha))
  4469. qla8044_watchdog(vha);
  4470. }
  4471. if (!vha->vp_idx && IS_QLAFX00(ha))
  4472. qlafx00_timer_routine(vha);
  4473. /* Loop down handler. */
  4474. if (atomic_read(&vha->loop_down_timer) > 0 &&
  4475. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
  4476. !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
  4477. && vha->flags.online) {
  4478. if (atomic_read(&vha->loop_down_timer) ==
  4479. vha->loop_down_abort_time) {
  4480. ql_log(ql_log_info, vha, 0x6008,
  4481. "Loop down - aborting the queues before time expires.\n");
  4482. if (!IS_QLA2100(ha) && vha->link_down_timeout)
  4483. atomic_set(&vha->loop_state, LOOP_DEAD);
  4484. /*
  4485. * Schedule an ISP abort to return any FCP2-device
  4486. * commands.
  4487. */
  4488. /* NPIV - scan physical port only */
  4489. if (!vha->vp_idx) {
  4490. spin_lock_irqsave(&ha->hardware_lock,
  4491. cpu_flags);
  4492. req = ha->req_q_map[0];
  4493. for (index = 1;
  4494. index < req->num_outstanding_cmds;
  4495. index++) {
  4496. fc_port_t *sfcp;
  4497. sp = req->outstanding_cmds[index];
  4498. if (!sp)
  4499. continue;
  4500. if (sp->type != SRB_SCSI_CMD)
  4501. continue;
  4502. sfcp = sp->fcport;
  4503. if (!(sfcp->flags & FCF_FCP2_DEVICE))
  4504. continue;
  4505. if (IS_QLA82XX(ha))
  4506. set_bit(FCOE_CTX_RESET_NEEDED,
  4507. &vha->dpc_flags);
  4508. else
  4509. set_bit(ISP_ABORT_NEEDED,
  4510. &vha->dpc_flags);
  4511. break;
  4512. }
  4513. spin_unlock_irqrestore(&ha->hardware_lock,
  4514. cpu_flags);
  4515. }
  4516. start_dpc++;
  4517. }
  4518. /* if the loop has been down for 4 minutes, reinit adapter */
  4519. if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
  4520. if (!(vha->device_flags & DFLG_NO_CABLE)) {
  4521. ql_log(ql_log_warn, vha, 0x6009,
  4522. "Loop down - aborting ISP.\n");
  4523. if (IS_QLA82XX(ha))
  4524. set_bit(FCOE_CTX_RESET_NEEDED,
  4525. &vha->dpc_flags);
  4526. else
  4527. set_bit(ISP_ABORT_NEEDED,
  4528. &vha->dpc_flags);
  4529. }
  4530. }
  4531. ql_dbg(ql_dbg_timer, vha, 0x600a,
  4532. "Loop down - seconds remaining %d.\n",
  4533. atomic_read(&vha->loop_down_timer));
  4534. }
  4535. /* Check if beacon LED needs to be blinked for physical host only */
  4536. if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
  4537. /* There is no beacon_blink function for ISP82xx */
  4538. if (!IS_P3P_TYPE(ha)) {
  4539. set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
  4540. start_dpc++;
  4541. }
  4542. }
  4543. /* Process any deferred work. */
  4544. if (!list_empty(&vha->work_list))
  4545. start_dpc++;
  4546. /* Schedule the DPC routine if needed */
  4547. if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  4548. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
  4549. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
  4550. start_dpc ||
  4551. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
  4552. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
  4553. test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
  4554. test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
  4555. test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
  4556. test_bit(RELOGIN_NEEDED, &vha->dpc_flags) ||
  4557. test_bit(HOST_RAMP_DOWN_QUEUE_DEPTH, &vha->dpc_flags) ||
  4558. test_bit(HOST_RAMP_UP_QUEUE_DEPTH, &vha->dpc_flags))) {
  4559. ql_dbg(ql_dbg_timer, vha, 0x600b,
  4560. "isp_abort_needed=%d loop_resync_needed=%d "
  4561. "fcport_update_needed=%d start_dpc=%d "
  4562. "reset_marker_needed=%d",
  4563. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
  4564. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
  4565. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
  4566. start_dpc,
  4567. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
  4568. ql_dbg(ql_dbg_timer, vha, 0x600c,
  4569. "beacon_blink_needed=%d isp_unrecoverable=%d "
  4570. "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
  4571. "relogin_needed=%d, host_ramp_down_needed=%d "
  4572. "host_ramp_up_needed=%d.\n",
  4573. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
  4574. test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
  4575. test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
  4576. test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
  4577. test_bit(RELOGIN_NEEDED, &vha->dpc_flags),
  4578. test_bit(HOST_RAMP_UP_QUEUE_DEPTH, &vha->dpc_flags),
  4579. test_bit(HOST_RAMP_DOWN_QUEUE_DEPTH, &vha->dpc_flags));
  4580. qla2xxx_wake_dpc(vha);
  4581. }
  4582. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  4583. }
  4584. /* Firmware interface routines. */
  4585. #define FW_BLOBS 10
  4586. #define FW_ISP21XX 0
  4587. #define FW_ISP22XX 1
  4588. #define FW_ISP2300 2
  4589. #define FW_ISP2322 3
  4590. #define FW_ISP24XX 4
  4591. #define FW_ISP25XX 5
  4592. #define FW_ISP81XX 6
  4593. #define FW_ISP82XX 7
  4594. #define FW_ISP2031 8
  4595. #define FW_ISP8031 9
  4596. #define FW_FILE_ISP21XX "ql2100_fw.bin"
  4597. #define FW_FILE_ISP22XX "ql2200_fw.bin"
  4598. #define FW_FILE_ISP2300 "ql2300_fw.bin"
  4599. #define FW_FILE_ISP2322 "ql2322_fw.bin"
  4600. #define FW_FILE_ISP24XX "ql2400_fw.bin"
  4601. #define FW_FILE_ISP25XX "ql2500_fw.bin"
  4602. #define FW_FILE_ISP81XX "ql8100_fw.bin"
  4603. #define FW_FILE_ISP82XX "ql8200_fw.bin"
  4604. #define FW_FILE_ISP2031 "ql2600_fw.bin"
  4605. #define FW_FILE_ISP8031 "ql8300_fw.bin"
  4606. static DEFINE_MUTEX(qla_fw_lock);
  4607. static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
  4608. { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
  4609. { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
  4610. { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
  4611. { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
  4612. { .name = FW_FILE_ISP24XX, },
  4613. { .name = FW_FILE_ISP25XX, },
  4614. { .name = FW_FILE_ISP81XX, },
  4615. { .name = FW_FILE_ISP82XX, },
  4616. { .name = FW_FILE_ISP2031, },
  4617. { .name = FW_FILE_ISP8031, },
  4618. };
  4619. struct fw_blob *
  4620. qla2x00_request_firmware(scsi_qla_host_t *vha)
  4621. {
  4622. struct qla_hw_data *ha = vha->hw;
  4623. struct fw_blob *blob;
  4624. if (IS_QLA2100(ha)) {
  4625. blob = &qla_fw_blobs[FW_ISP21XX];
  4626. } else if (IS_QLA2200(ha)) {
  4627. blob = &qla_fw_blobs[FW_ISP22XX];
  4628. } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  4629. blob = &qla_fw_blobs[FW_ISP2300];
  4630. } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  4631. blob = &qla_fw_blobs[FW_ISP2322];
  4632. } else if (IS_QLA24XX_TYPE(ha)) {
  4633. blob = &qla_fw_blobs[FW_ISP24XX];
  4634. } else if (IS_QLA25XX(ha)) {
  4635. blob = &qla_fw_blobs[FW_ISP25XX];
  4636. } else if (IS_QLA81XX(ha)) {
  4637. blob = &qla_fw_blobs[FW_ISP81XX];
  4638. } else if (IS_QLA82XX(ha)) {
  4639. blob = &qla_fw_blobs[FW_ISP82XX];
  4640. } else if (IS_QLA2031(ha)) {
  4641. blob = &qla_fw_blobs[FW_ISP2031];
  4642. } else if (IS_QLA8031(ha)) {
  4643. blob = &qla_fw_blobs[FW_ISP8031];
  4644. } else {
  4645. return NULL;
  4646. }
  4647. mutex_lock(&qla_fw_lock);
  4648. if (blob->fw)
  4649. goto out;
  4650. if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
  4651. ql_log(ql_log_warn, vha, 0x0063,
  4652. "Failed to load firmware image (%s).\n", blob->name);
  4653. blob->fw = NULL;
  4654. blob = NULL;
  4655. goto out;
  4656. }
  4657. out:
  4658. mutex_unlock(&qla_fw_lock);
  4659. return blob;
  4660. }
  4661. static void
  4662. qla2x00_release_firmware(void)
  4663. {
  4664. int idx;
  4665. mutex_lock(&qla_fw_lock);
  4666. for (idx = 0; idx < FW_BLOBS; idx++)
  4667. release_firmware(qla_fw_blobs[idx].fw);
  4668. mutex_unlock(&qla_fw_lock);
  4669. }
  4670. static pci_ers_result_t
  4671. qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  4672. {
  4673. scsi_qla_host_t *vha = pci_get_drvdata(pdev);
  4674. struct qla_hw_data *ha = vha->hw;
  4675. ql_dbg(ql_dbg_aer, vha, 0x9000,
  4676. "PCI error detected, state %x.\n", state);
  4677. switch (state) {
  4678. case pci_channel_io_normal:
  4679. ha->flags.eeh_busy = 0;
  4680. return PCI_ERS_RESULT_CAN_RECOVER;
  4681. case pci_channel_io_frozen:
  4682. ha->flags.eeh_busy = 1;
  4683. /* For ISP82XX complete any pending mailbox cmd */
  4684. if (IS_QLA82XX(ha)) {
  4685. ha->flags.isp82xx_fw_hung = 1;
  4686. ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
  4687. qla82xx_clear_pending_mbx(vha);
  4688. }
  4689. qla2x00_free_irqs(vha);
  4690. pci_disable_device(pdev);
  4691. /* Return back all IOs */
  4692. qla2x00_abort_all_cmds(vha, DID_RESET << 16);
  4693. return PCI_ERS_RESULT_NEED_RESET;
  4694. case pci_channel_io_perm_failure:
  4695. ha->flags.pci_channel_io_perm_failure = 1;
  4696. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  4697. return PCI_ERS_RESULT_DISCONNECT;
  4698. }
  4699. return PCI_ERS_RESULT_NEED_RESET;
  4700. }
  4701. static pci_ers_result_t
  4702. qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
  4703. {
  4704. int risc_paused = 0;
  4705. uint32_t stat;
  4706. unsigned long flags;
  4707. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  4708. struct qla_hw_data *ha = base_vha->hw;
  4709. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  4710. struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
  4711. if (IS_QLA82XX(ha))
  4712. return PCI_ERS_RESULT_RECOVERED;
  4713. spin_lock_irqsave(&ha->hardware_lock, flags);
  4714. if (IS_QLA2100(ha) || IS_QLA2200(ha)){
  4715. stat = RD_REG_DWORD(&reg->hccr);
  4716. if (stat & HCCR_RISC_PAUSE)
  4717. risc_paused = 1;
  4718. } else if (IS_QLA23XX(ha)) {
  4719. stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
  4720. if (stat & HSR_RISC_PAUSED)
  4721. risc_paused = 1;
  4722. } else if (IS_FWI2_CAPABLE(ha)) {
  4723. stat = RD_REG_DWORD(&reg24->host_status);
  4724. if (stat & HSRX_RISC_PAUSED)
  4725. risc_paused = 1;
  4726. }
  4727. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4728. if (risc_paused) {
  4729. ql_log(ql_log_info, base_vha, 0x9003,
  4730. "RISC paused -- mmio_enabled, Dumping firmware.\n");
  4731. ha->isp_ops->fw_dump(base_vha, 0);
  4732. return PCI_ERS_RESULT_NEED_RESET;
  4733. } else
  4734. return PCI_ERS_RESULT_RECOVERED;
  4735. }
  4736. static uint32_t
  4737. qla82xx_error_recovery(scsi_qla_host_t *base_vha)
  4738. {
  4739. uint32_t rval = QLA_FUNCTION_FAILED;
  4740. uint32_t drv_active = 0;
  4741. struct qla_hw_data *ha = base_vha->hw;
  4742. int fn;
  4743. struct pci_dev *other_pdev = NULL;
  4744. ql_dbg(ql_dbg_aer, base_vha, 0x9006,
  4745. "Entered %s.\n", __func__);
  4746. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  4747. if (base_vha->flags.online) {
  4748. /* Abort all outstanding commands,
  4749. * so as to be requeued later */
  4750. qla2x00_abort_isp_cleanup(base_vha);
  4751. }
  4752. fn = PCI_FUNC(ha->pdev->devfn);
  4753. while (fn > 0) {
  4754. fn--;
  4755. ql_dbg(ql_dbg_aer, base_vha, 0x9007,
  4756. "Finding pci device at function = 0x%x.\n", fn);
  4757. other_pdev =
  4758. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  4759. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  4760. fn));
  4761. if (!other_pdev)
  4762. continue;
  4763. if (atomic_read(&other_pdev->enable_cnt)) {
  4764. ql_dbg(ql_dbg_aer, base_vha, 0x9008,
  4765. "Found PCI func available and enable at 0x%x.\n",
  4766. fn);
  4767. pci_dev_put(other_pdev);
  4768. break;
  4769. }
  4770. pci_dev_put(other_pdev);
  4771. }
  4772. if (!fn) {
  4773. /* Reset owner */
  4774. ql_dbg(ql_dbg_aer, base_vha, 0x9009,
  4775. "This devfn is reset owner = 0x%x.\n",
  4776. ha->pdev->devfn);
  4777. qla82xx_idc_lock(ha);
  4778. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  4779. QLA8XXX_DEV_INITIALIZING);
  4780. qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
  4781. QLA82XX_IDC_VERSION);
  4782. drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
  4783. ql_dbg(ql_dbg_aer, base_vha, 0x900a,
  4784. "drv_active = 0x%x.\n", drv_active);
  4785. qla82xx_idc_unlock(ha);
  4786. /* Reset if device is not already reset
  4787. * drv_active would be 0 if a reset has already been done
  4788. */
  4789. if (drv_active)
  4790. rval = qla82xx_start_firmware(base_vha);
  4791. else
  4792. rval = QLA_SUCCESS;
  4793. qla82xx_idc_lock(ha);
  4794. if (rval != QLA_SUCCESS) {
  4795. ql_log(ql_log_info, base_vha, 0x900b,
  4796. "HW State: FAILED.\n");
  4797. qla82xx_clear_drv_active(ha);
  4798. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  4799. QLA8XXX_DEV_FAILED);
  4800. } else {
  4801. ql_log(ql_log_info, base_vha, 0x900c,
  4802. "HW State: READY.\n");
  4803. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  4804. QLA8XXX_DEV_READY);
  4805. qla82xx_idc_unlock(ha);
  4806. ha->flags.isp82xx_fw_hung = 0;
  4807. rval = qla82xx_restart_isp(base_vha);
  4808. qla82xx_idc_lock(ha);
  4809. /* Clear driver state register */
  4810. qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
  4811. qla82xx_set_drv_active(base_vha);
  4812. }
  4813. qla82xx_idc_unlock(ha);
  4814. } else {
  4815. ql_dbg(ql_dbg_aer, base_vha, 0x900d,
  4816. "This devfn is not reset owner = 0x%x.\n",
  4817. ha->pdev->devfn);
  4818. if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
  4819. QLA8XXX_DEV_READY)) {
  4820. ha->flags.isp82xx_fw_hung = 0;
  4821. rval = qla82xx_restart_isp(base_vha);
  4822. qla82xx_idc_lock(ha);
  4823. qla82xx_set_drv_active(base_vha);
  4824. qla82xx_idc_unlock(ha);
  4825. }
  4826. }
  4827. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  4828. return rval;
  4829. }
  4830. static pci_ers_result_t
  4831. qla2xxx_pci_slot_reset(struct pci_dev *pdev)
  4832. {
  4833. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  4834. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  4835. struct qla_hw_data *ha = base_vha->hw;
  4836. struct rsp_que *rsp;
  4837. int rc, retries = 10;
  4838. ql_dbg(ql_dbg_aer, base_vha, 0x9004,
  4839. "Slot Reset.\n");
  4840. /* Workaround: qla2xxx driver which access hardware earlier
  4841. * needs error state to be pci_channel_io_online.
  4842. * Otherwise mailbox command timesout.
  4843. */
  4844. pdev->error_state = pci_channel_io_normal;
  4845. pci_restore_state(pdev);
  4846. /* pci_restore_state() clears the saved_state flag of the device
  4847. * save restored state which resets saved_state flag
  4848. */
  4849. pci_save_state(pdev);
  4850. if (ha->mem_only)
  4851. rc = pci_enable_device_mem(pdev);
  4852. else
  4853. rc = pci_enable_device(pdev);
  4854. if (rc) {
  4855. ql_log(ql_log_warn, base_vha, 0x9005,
  4856. "Can't re-enable PCI device after reset.\n");
  4857. goto exit_slot_reset;
  4858. }
  4859. rsp = ha->rsp_q_map[0];
  4860. if (qla2x00_request_irqs(ha, rsp))
  4861. goto exit_slot_reset;
  4862. if (ha->isp_ops->pci_config(base_vha))
  4863. goto exit_slot_reset;
  4864. if (IS_QLA82XX(ha)) {
  4865. if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
  4866. ret = PCI_ERS_RESULT_RECOVERED;
  4867. goto exit_slot_reset;
  4868. } else
  4869. goto exit_slot_reset;
  4870. }
  4871. while (ha->flags.mbox_busy && retries--)
  4872. msleep(1000);
  4873. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  4874. if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
  4875. ret = PCI_ERS_RESULT_RECOVERED;
  4876. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  4877. exit_slot_reset:
  4878. ql_dbg(ql_dbg_aer, base_vha, 0x900e,
  4879. "slot_reset return %x.\n", ret);
  4880. return ret;
  4881. }
  4882. static void
  4883. qla2xxx_pci_resume(struct pci_dev *pdev)
  4884. {
  4885. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  4886. struct qla_hw_data *ha = base_vha->hw;
  4887. int ret;
  4888. ql_dbg(ql_dbg_aer, base_vha, 0x900f,
  4889. "pci_resume.\n");
  4890. ret = qla2x00_wait_for_hba_online(base_vha);
  4891. if (ret != QLA_SUCCESS) {
  4892. ql_log(ql_log_fatal, base_vha, 0x9002,
  4893. "The device failed to resume I/O from slot/link_reset.\n");
  4894. }
  4895. pci_cleanup_aer_uncorrect_error_status(pdev);
  4896. ha->flags.eeh_busy = 0;
  4897. }
  4898. static const struct pci_error_handlers qla2xxx_err_handler = {
  4899. .error_detected = qla2xxx_pci_error_detected,
  4900. .mmio_enabled = qla2xxx_pci_mmio_enabled,
  4901. .slot_reset = qla2xxx_pci_slot_reset,
  4902. .resume = qla2xxx_pci_resume,
  4903. };
  4904. static struct pci_device_id qla2xxx_pci_tbl[] = {
  4905. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
  4906. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
  4907. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
  4908. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
  4909. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
  4910. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
  4911. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
  4912. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
  4913. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
  4914. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
  4915. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
  4916. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
  4917. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
  4918. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
  4919. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
  4920. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
  4921. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
  4922. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
  4923. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
  4924. { 0 },
  4925. };
  4926. MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
  4927. static struct pci_driver qla2xxx_pci_driver = {
  4928. .name = QLA2XXX_DRIVER_NAME,
  4929. .driver = {
  4930. .owner = THIS_MODULE,
  4931. },
  4932. .id_table = qla2xxx_pci_tbl,
  4933. .probe = qla2x00_probe_one,
  4934. .remove = qla2x00_remove_one,
  4935. .shutdown = qla2x00_shutdown,
  4936. .err_handler = &qla2xxx_err_handler,
  4937. };
  4938. static const struct file_operations apidev_fops = {
  4939. .owner = THIS_MODULE,
  4940. .llseek = noop_llseek,
  4941. };
  4942. /**
  4943. * qla2x00_module_init - Module initialization.
  4944. **/
  4945. static int __init
  4946. qla2x00_module_init(void)
  4947. {
  4948. int ret = 0;
  4949. /* Allocate cache for SRBs. */
  4950. srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
  4951. SLAB_HWCACHE_ALIGN, NULL);
  4952. if (srb_cachep == NULL) {
  4953. ql_log(ql_log_fatal, NULL, 0x0001,
  4954. "Unable to allocate SRB cache...Failing load!.\n");
  4955. return -ENOMEM;
  4956. }
  4957. /* Initialize target kmem_cache and mem_pools */
  4958. ret = qlt_init();
  4959. if (ret < 0) {
  4960. kmem_cache_destroy(srb_cachep);
  4961. return ret;
  4962. } else if (ret > 0) {
  4963. /*
  4964. * If initiator mode is explictly disabled by qlt_init(),
  4965. * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
  4966. * performing scsi_scan_target() during LOOP UP event.
  4967. */
  4968. qla2xxx_transport_functions.disable_target_scan = 1;
  4969. qla2xxx_transport_vport_functions.disable_target_scan = 1;
  4970. }
  4971. /* Derive version string. */
  4972. strcpy(qla2x00_version_str, QLA2XXX_VERSION);
  4973. if (ql2xextended_error_logging)
  4974. strcat(qla2x00_version_str, "-debug");
  4975. qla2xxx_transport_template =
  4976. fc_attach_transport(&qla2xxx_transport_functions);
  4977. if (!qla2xxx_transport_template) {
  4978. kmem_cache_destroy(srb_cachep);
  4979. ql_log(ql_log_fatal, NULL, 0x0002,
  4980. "fc_attach_transport failed...Failing load!.\n");
  4981. qlt_exit();
  4982. return -ENODEV;
  4983. }
  4984. apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
  4985. if (apidev_major < 0) {
  4986. ql_log(ql_log_fatal, NULL, 0x0003,
  4987. "Unable to register char device %s.\n", QLA2XXX_APIDEV);
  4988. }
  4989. qla2xxx_transport_vport_template =
  4990. fc_attach_transport(&qla2xxx_transport_vport_functions);
  4991. if (!qla2xxx_transport_vport_template) {
  4992. kmem_cache_destroy(srb_cachep);
  4993. qlt_exit();
  4994. fc_release_transport(qla2xxx_transport_template);
  4995. ql_log(ql_log_fatal, NULL, 0x0004,
  4996. "fc_attach_transport vport failed...Failing load!.\n");
  4997. return -ENODEV;
  4998. }
  4999. ql_log(ql_log_info, NULL, 0x0005,
  5000. "QLogic Fibre Channel HBA Driver: %s.\n",
  5001. qla2x00_version_str);
  5002. ret = pci_register_driver(&qla2xxx_pci_driver);
  5003. if (ret) {
  5004. kmem_cache_destroy(srb_cachep);
  5005. qlt_exit();
  5006. fc_release_transport(qla2xxx_transport_template);
  5007. fc_release_transport(qla2xxx_transport_vport_template);
  5008. ql_log(ql_log_fatal, NULL, 0x0006,
  5009. "pci_register_driver failed...ret=%d Failing load!.\n",
  5010. ret);
  5011. }
  5012. return ret;
  5013. }
  5014. /**
  5015. * qla2x00_module_exit - Module cleanup.
  5016. **/
  5017. static void __exit
  5018. qla2x00_module_exit(void)
  5019. {
  5020. unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
  5021. pci_unregister_driver(&qla2xxx_pci_driver);
  5022. qla2x00_release_firmware();
  5023. kmem_cache_destroy(srb_cachep);
  5024. qlt_exit();
  5025. if (ctx_cachep)
  5026. kmem_cache_destroy(ctx_cachep);
  5027. fc_release_transport(qla2xxx_transport_template);
  5028. fc_release_transport(qla2xxx_transport_vport_template);
  5029. }
  5030. module_init(qla2x00_module_init);
  5031. module_exit(qla2x00_module_exit);
  5032. MODULE_AUTHOR("QLogic Corporation");
  5033. MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
  5034. MODULE_LICENSE("GPL");
  5035. MODULE_VERSION(QLA2XXX_VERSION);
  5036. MODULE_FIRMWARE(FW_FILE_ISP21XX);
  5037. MODULE_FIRMWARE(FW_FILE_ISP22XX);
  5038. MODULE_FIRMWARE(FW_FILE_ISP2300);
  5039. MODULE_FIRMWARE(FW_FILE_ISP2322);
  5040. MODULE_FIRMWARE(FW_FILE_ISP24XX);
  5041. MODULE_FIRMWARE(FW_FILE_ISP25XX);