qla_os.c 232 KB

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