qla_os.c 190 KB

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