qla_os.c 190 KB

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