qla_os.c 184 KB

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