qla_os.c 190 KB

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