qla_init.c 175 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2014 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include "qla_gbl.h"
  9. #include <linux/delay.h>
  10. #include <linux/slab.h>
  11. #include <linux/vmalloc.h>
  12. #include "qla_devtbl.h"
  13. #ifdef CONFIG_SPARC
  14. #include <asm/prom.h>
  15. #endif
  16. #include <target/target_core_base.h>
  17. #include "qla_target.h"
  18. /*
  19. * QLogic ISP2x00 Hardware Support Function Prototypes.
  20. */
  21. static int qla2x00_isp_firmware(scsi_qla_host_t *);
  22. static int qla2x00_setup_chip(scsi_qla_host_t *);
  23. static int qla2x00_fw_ready(scsi_qla_host_t *);
  24. static int qla2x00_configure_hba(scsi_qla_host_t *);
  25. static int qla2x00_configure_loop(scsi_qla_host_t *);
  26. static int qla2x00_configure_local_loop(scsi_qla_host_t *);
  27. static int qla2x00_configure_fabric(scsi_qla_host_t *);
  28. static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
  29. static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
  30. uint16_t *);
  31. static int qla2x00_restart_isp(scsi_qla_host_t *);
  32. static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
  33. static int qla84xx_init_chip(scsi_qla_host_t *);
  34. static int qla25xx_init_queues(struct qla_hw_data *);
  35. /* SRB Extensions ---------------------------------------------------------- */
  36. void
  37. qla2x00_sp_timeout(unsigned long __data)
  38. {
  39. srb_t *sp = (srb_t *)__data;
  40. struct srb_iocb *iocb;
  41. fc_port_t *fcport = sp->fcport;
  42. struct qla_hw_data *ha = fcport->vha->hw;
  43. struct req_que *req;
  44. unsigned long flags;
  45. spin_lock_irqsave(&ha->hardware_lock, flags);
  46. req = ha->req_q_map[0];
  47. req->outstanding_cmds[sp->handle] = NULL;
  48. iocb = &sp->u.iocb_cmd;
  49. iocb->timeout(sp);
  50. sp->free(fcport->vha, sp);
  51. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  52. }
  53. void
  54. qla2x00_sp_free(void *data, void *ptr)
  55. {
  56. srb_t *sp = (srb_t *)ptr;
  57. struct srb_iocb *iocb = &sp->u.iocb_cmd;
  58. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  59. del_timer(&iocb->timer);
  60. qla2x00_rel_sp(vha, sp);
  61. }
  62. /* Asynchronous Login/Logout Routines -------------------------------------- */
  63. unsigned long
  64. qla2x00_get_async_timeout(struct scsi_qla_host *vha)
  65. {
  66. unsigned long tmo;
  67. struct qla_hw_data *ha = vha->hw;
  68. /* Firmware should use switch negotiated r_a_tov for timeout. */
  69. tmo = ha->r_a_tov / 10 * 2;
  70. if (IS_QLAFX00(ha)) {
  71. tmo = FX00_DEF_RATOV * 2;
  72. } else if (!IS_FWI2_CAPABLE(ha)) {
  73. /*
  74. * Except for earlier ISPs where the timeout is seeded from the
  75. * initialization control block.
  76. */
  77. tmo = ha->login_timeout;
  78. }
  79. return tmo;
  80. }
  81. static void
  82. qla2x00_async_iocb_timeout(void *data)
  83. {
  84. srb_t *sp = (srb_t *)data;
  85. fc_port_t *fcport = sp->fcport;
  86. ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
  87. "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
  88. sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area,
  89. fcport->d_id.b.al_pa);
  90. fcport->flags &= ~FCF_ASYNC_SENT;
  91. if (sp->type == SRB_LOGIN_CMD) {
  92. struct srb_iocb *lio = &sp->u.iocb_cmd;
  93. qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
  94. /* Retry as needed. */
  95. lio->u.logio.data[0] = MBS_COMMAND_ERROR;
  96. lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
  97. QLA_LOGIO_LOGIN_RETRIED : 0;
  98. qla2x00_post_async_login_done_work(fcport->vha, fcport,
  99. lio->u.logio.data);
  100. } else if (sp->type == SRB_LOGOUT_CMD) {
  101. qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT);
  102. }
  103. }
  104. static void
  105. qla2x00_async_login_sp_done(void *data, void *ptr, int res)
  106. {
  107. srb_t *sp = (srb_t *)ptr;
  108. struct srb_iocb *lio = &sp->u.iocb_cmd;
  109. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  110. if (!test_bit(UNLOADING, &vha->dpc_flags))
  111. qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
  112. lio->u.logio.data);
  113. sp->free(sp->fcport->vha, sp);
  114. }
  115. int
  116. qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
  117. uint16_t *data)
  118. {
  119. srb_t *sp;
  120. struct srb_iocb *lio;
  121. int rval;
  122. rval = QLA_FUNCTION_FAILED;
  123. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  124. if (!sp)
  125. goto done;
  126. sp->type = SRB_LOGIN_CMD;
  127. sp->name = "login";
  128. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  129. lio = &sp->u.iocb_cmd;
  130. lio->timeout = qla2x00_async_iocb_timeout;
  131. sp->done = qla2x00_async_login_sp_done;
  132. lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
  133. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  134. lio->u.logio.flags |= SRB_LOGIN_RETRIED;
  135. rval = qla2x00_start_sp(sp);
  136. if (rval != QLA_SUCCESS) {
  137. fcport->flags &= ~FCF_ASYNC_SENT;
  138. fcport->flags |= FCF_LOGIN_NEEDED;
  139. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  140. goto done_free_sp;
  141. }
  142. ql_dbg(ql_dbg_disc, vha, 0x2072,
  143. "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
  144. "retries=%d.\n", sp->handle, fcport->loop_id,
  145. fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
  146. fcport->login_retry);
  147. return rval;
  148. done_free_sp:
  149. sp->free(fcport->vha, sp);
  150. done:
  151. return rval;
  152. }
  153. static void
  154. qla2x00_async_logout_sp_done(void *data, void *ptr, int res)
  155. {
  156. srb_t *sp = (srb_t *)ptr;
  157. struct srb_iocb *lio = &sp->u.iocb_cmd;
  158. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  159. if (!test_bit(UNLOADING, &vha->dpc_flags))
  160. qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
  161. lio->u.logio.data);
  162. sp->free(sp->fcport->vha, sp);
  163. }
  164. int
  165. qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
  166. {
  167. srb_t *sp;
  168. struct srb_iocb *lio;
  169. int rval;
  170. rval = QLA_FUNCTION_FAILED;
  171. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  172. if (!sp)
  173. goto done;
  174. sp->type = SRB_LOGOUT_CMD;
  175. sp->name = "logout";
  176. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  177. lio = &sp->u.iocb_cmd;
  178. lio->timeout = qla2x00_async_iocb_timeout;
  179. sp->done = qla2x00_async_logout_sp_done;
  180. rval = qla2x00_start_sp(sp);
  181. if (rval != QLA_SUCCESS)
  182. goto done_free_sp;
  183. ql_dbg(ql_dbg_disc, vha, 0x2070,
  184. "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
  185. sp->handle, fcport->loop_id, fcport->d_id.b.domain,
  186. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  187. return rval;
  188. done_free_sp:
  189. sp->free(fcport->vha, sp);
  190. done:
  191. return rval;
  192. }
  193. static void
  194. qla2x00_async_adisc_sp_done(void *data, void *ptr, int res)
  195. {
  196. srb_t *sp = (srb_t *)ptr;
  197. struct srb_iocb *lio = &sp->u.iocb_cmd;
  198. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  199. if (!test_bit(UNLOADING, &vha->dpc_flags))
  200. qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
  201. lio->u.logio.data);
  202. sp->free(sp->fcport->vha, sp);
  203. }
  204. int
  205. qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
  206. uint16_t *data)
  207. {
  208. srb_t *sp;
  209. struct srb_iocb *lio;
  210. int rval;
  211. rval = QLA_FUNCTION_FAILED;
  212. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  213. if (!sp)
  214. goto done;
  215. sp->type = SRB_ADISC_CMD;
  216. sp->name = "adisc";
  217. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  218. lio = &sp->u.iocb_cmd;
  219. lio->timeout = qla2x00_async_iocb_timeout;
  220. sp->done = qla2x00_async_adisc_sp_done;
  221. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  222. lio->u.logio.flags |= SRB_LOGIN_RETRIED;
  223. rval = qla2x00_start_sp(sp);
  224. if (rval != QLA_SUCCESS)
  225. goto done_free_sp;
  226. ql_dbg(ql_dbg_disc, vha, 0x206f,
  227. "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
  228. sp->handle, fcport->loop_id, fcport->d_id.b.domain,
  229. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  230. return rval;
  231. done_free_sp:
  232. sp->free(fcport->vha, sp);
  233. done:
  234. return rval;
  235. }
  236. static void
  237. qla2x00_tmf_iocb_timeout(void *data)
  238. {
  239. srb_t *sp = (srb_t *)data;
  240. struct srb_iocb *tmf = &sp->u.iocb_cmd;
  241. tmf->u.tmf.comp_status = CS_TIMEOUT;
  242. complete(&tmf->u.tmf.comp);
  243. }
  244. static void
  245. qla2x00_tmf_sp_done(void *data, void *ptr, int res)
  246. {
  247. srb_t *sp = (srb_t *)ptr;
  248. struct srb_iocb *tmf = &sp->u.iocb_cmd;
  249. complete(&tmf->u.tmf.comp);
  250. }
  251. int
  252. qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
  253. uint32_t tag)
  254. {
  255. struct scsi_qla_host *vha = fcport->vha;
  256. struct srb_iocb *tm_iocb;
  257. srb_t *sp;
  258. int rval = QLA_FUNCTION_FAILED;
  259. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  260. if (!sp)
  261. goto done;
  262. tm_iocb = &sp->u.iocb_cmd;
  263. sp->type = SRB_TM_CMD;
  264. sp->name = "tmf";
  265. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
  266. tm_iocb->u.tmf.flags = flags;
  267. tm_iocb->u.tmf.lun = lun;
  268. tm_iocb->u.tmf.data = tag;
  269. sp->done = qla2x00_tmf_sp_done;
  270. tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
  271. init_completion(&tm_iocb->u.tmf.comp);
  272. rval = qla2x00_start_sp(sp);
  273. if (rval != QLA_SUCCESS)
  274. goto done_free_sp;
  275. ql_dbg(ql_dbg_taskm, vha, 0x802f,
  276. "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
  277. sp->handle, fcport->loop_id, fcport->d_id.b.domain,
  278. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  279. wait_for_completion(&tm_iocb->u.tmf.comp);
  280. rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
  281. QLA_SUCCESS : QLA_FUNCTION_FAILED;
  282. if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
  283. ql_dbg(ql_dbg_taskm, vha, 0x8030,
  284. "TM IOCB failed (%x).\n", rval);
  285. }
  286. if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
  287. flags = tm_iocb->u.tmf.flags;
  288. lun = (uint16_t)tm_iocb->u.tmf.lun;
  289. /* Issue Marker IOCB */
  290. qla2x00_marker(vha, vha->hw->req_q_map[0],
  291. vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
  292. flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
  293. }
  294. done_free_sp:
  295. sp->free(vha, sp);
  296. done:
  297. return rval;
  298. }
  299. static void
  300. qla24xx_abort_iocb_timeout(void *data)
  301. {
  302. srb_t *sp = (srb_t *)data;
  303. struct srb_iocb *abt = &sp->u.iocb_cmd;
  304. abt->u.abt.comp_status = CS_TIMEOUT;
  305. complete(&abt->u.abt.comp);
  306. }
  307. static void
  308. qla24xx_abort_sp_done(void *data, void *ptr, int res)
  309. {
  310. srb_t *sp = (srb_t *)ptr;
  311. struct srb_iocb *abt = &sp->u.iocb_cmd;
  312. complete(&abt->u.abt.comp);
  313. }
  314. static int
  315. qla24xx_async_abort_cmd(srb_t *cmd_sp)
  316. {
  317. scsi_qla_host_t *vha = cmd_sp->fcport->vha;
  318. fc_port_t *fcport = cmd_sp->fcport;
  319. struct srb_iocb *abt_iocb;
  320. srb_t *sp;
  321. int rval = QLA_FUNCTION_FAILED;
  322. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  323. if (!sp)
  324. goto done;
  325. abt_iocb = &sp->u.iocb_cmd;
  326. sp->type = SRB_ABT_CMD;
  327. sp->name = "abort";
  328. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
  329. abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
  330. sp->done = qla24xx_abort_sp_done;
  331. abt_iocb->timeout = qla24xx_abort_iocb_timeout;
  332. init_completion(&abt_iocb->u.abt.comp);
  333. rval = qla2x00_start_sp(sp);
  334. if (rval != QLA_SUCCESS)
  335. goto done_free_sp;
  336. ql_dbg(ql_dbg_async, vha, 0x507c,
  337. "Abort command issued - hdl=%x, target_id=%x\n",
  338. cmd_sp->handle, fcport->tgt_id);
  339. wait_for_completion(&abt_iocb->u.abt.comp);
  340. rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
  341. QLA_SUCCESS : QLA_FUNCTION_FAILED;
  342. done_free_sp:
  343. sp->free(vha, sp);
  344. done:
  345. return rval;
  346. }
  347. int
  348. qla24xx_async_abort_command(srb_t *sp)
  349. {
  350. unsigned long flags = 0;
  351. uint32_t handle;
  352. fc_port_t *fcport = sp->fcport;
  353. struct scsi_qla_host *vha = fcport->vha;
  354. struct qla_hw_data *ha = vha->hw;
  355. struct req_que *req = vha->req;
  356. spin_lock_irqsave(&ha->hardware_lock, flags);
  357. for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
  358. if (req->outstanding_cmds[handle] == sp)
  359. break;
  360. }
  361. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  362. if (handle == req->num_outstanding_cmds) {
  363. /* Command not found. */
  364. return QLA_FUNCTION_FAILED;
  365. }
  366. if (sp->type == SRB_FXIOCB_DCMD)
  367. return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
  368. FXDISC_ABORT_IOCTL);
  369. return qla24xx_async_abort_cmd(sp);
  370. }
  371. void
  372. qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  373. uint16_t *data)
  374. {
  375. int rval;
  376. switch (data[0]) {
  377. case MBS_COMMAND_COMPLETE:
  378. /*
  379. * Driver must validate login state - If PRLI not complete,
  380. * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
  381. * requests.
  382. */
  383. rval = qla2x00_get_port_database(vha, fcport, 0);
  384. if (rval == QLA_NOT_LOGGED_IN) {
  385. fcport->flags &= ~FCF_ASYNC_SENT;
  386. fcport->flags |= FCF_LOGIN_NEEDED;
  387. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  388. break;
  389. }
  390. if (rval != QLA_SUCCESS) {
  391. qla2x00_post_async_logout_work(vha, fcport, NULL);
  392. qla2x00_post_async_login_work(vha, fcport, NULL);
  393. break;
  394. }
  395. if (fcport->flags & FCF_FCP2_DEVICE) {
  396. qla2x00_post_async_adisc_work(vha, fcport, data);
  397. break;
  398. }
  399. qla2x00_update_fcport(vha, fcport);
  400. break;
  401. case MBS_COMMAND_ERROR:
  402. fcport->flags &= ~FCF_ASYNC_SENT;
  403. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  404. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  405. else
  406. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  407. break;
  408. case MBS_PORT_ID_USED:
  409. fcport->loop_id = data[1];
  410. qla2x00_post_async_logout_work(vha, fcport, NULL);
  411. qla2x00_post_async_login_work(vha, fcport, NULL);
  412. break;
  413. case MBS_LOOP_ID_USED:
  414. fcport->loop_id++;
  415. rval = qla2x00_find_new_loop_id(vha, fcport);
  416. if (rval != QLA_SUCCESS) {
  417. fcport->flags &= ~FCF_ASYNC_SENT;
  418. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  419. break;
  420. }
  421. qla2x00_post_async_login_work(vha, fcport, NULL);
  422. break;
  423. }
  424. return;
  425. }
  426. void
  427. qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  428. uint16_t *data)
  429. {
  430. /* Don't re-login in target mode */
  431. if (!fcport->tgt_session)
  432. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  433. qlt_logo_completion_handler(fcport, data[0]);
  434. return;
  435. }
  436. void
  437. qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  438. uint16_t *data)
  439. {
  440. if (data[0] == MBS_COMMAND_COMPLETE) {
  441. qla2x00_update_fcport(vha, fcport);
  442. return;
  443. }
  444. /* Retry login. */
  445. fcport->flags &= ~FCF_ASYNC_SENT;
  446. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  447. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  448. else
  449. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  450. return;
  451. }
  452. /****************************************************************************/
  453. /* QLogic ISP2x00 Hardware Support Functions. */
  454. /****************************************************************************/
  455. static int
  456. qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
  457. {
  458. int rval = QLA_SUCCESS;
  459. struct qla_hw_data *ha = vha->hw;
  460. uint32_t idc_major_ver, idc_minor_ver;
  461. uint16_t config[4];
  462. qla83xx_idc_lock(vha, 0);
  463. /* SV: TODO: Assign initialization timeout from
  464. * flash-info / other param
  465. */
  466. ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
  467. ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
  468. /* Set our fcoe function presence */
  469. if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
  470. ql_dbg(ql_dbg_p3p, vha, 0xb077,
  471. "Error while setting DRV-Presence.\n");
  472. rval = QLA_FUNCTION_FAILED;
  473. goto exit;
  474. }
  475. /* Decide the reset ownership */
  476. qla83xx_reset_ownership(vha);
  477. /*
  478. * On first protocol driver load:
  479. * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
  480. * register.
  481. * Others: Check compatibility with current IDC Major version.
  482. */
  483. qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
  484. if (ha->flags.nic_core_reset_owner) {
  485. /* Set IDC Major version */
  486. idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
  487. qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
  488. /* Clearing IDC-Lock-Recovery register */
  489. qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
  490. } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
  491. /*
  492. * Clear further IDC participation if we are not compatible with
  493. * the current IDC Major Version.
  494. */
  495. ql_log(ql_log_warn, vha, 0xb07d,
  496. "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
  497. idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
  498. __qla83xx_clear_drv_presence(vha);
  499. rval = QLA_FUNCTION_FAILED;
  500. goto exit;
  501. }
  502. /* Each function sets its supported Minor version. */
  503. qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
  504. idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
  505. qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
  506. if (ha->flags.nic_core_reset_owner) {
  507. memset(config, 0, sizeof(config));
  508. if (!qla81xx_get_port_config(vha, config))
  509. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
  510. QLA8XXX_DEV_READY);
  511. }
  512. rval = qla83xx_idc_state_handler(vha);
  513. exit:
  514. qla83xx_idc_unlock(vha, 0);
  515. return rval;
  516. }
  517. /*
  518. * qla2x00_initialize_adapter
  519. * Initialize board.
  520. *
  521. * Input:
  522. * ha = adapter block pointer.
  523. *
  524. * Returns:
  525. * 0 = success
  526. */
  527. int
  528. qla2x00_initialize_adapter(scsi_qla_host_t *vha)
  529. {
  530. int rval;
  531. struct qla_hw_data *ha = vha->hw;
  532. struct req_que *req = ha->req_q_map[0];
  533. memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
  534. memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
  535. /* Clear adapter flags. */
  536. vha->flags.online = 0;
  537. ha->flags.chip_reset_done = 0;
  538. vha->flags.reset_active = 0;
  539. ha->flags.pci_channel_io_perm_failure = 0;
  540. ha->flags.eeh_busy = 0;
  541. vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
  542. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  543. atomic_set(&vha->loop_state, LOOP_DOWN);
  544. vha->device_flags = DFLG_NO_CABLE;
  545. vha->dpc_flags = 0;
  546. vha->flags.management_server_logged_in = 0;
  547. vha->marker_needed = 0;
  548. ha->isp_abort_cnt = 0;
  549. ha->beacon_blink_led = 0;
  550. set_bit(0, ha->req_qid_map);
  551. set_bit(0, ha->rsp_qid_map);
  552. ql_dbg(ql_dbg_init, vha, 0x0040,
  553. "Configuring PCI space...\n");
  554. rval = ha->isp_ops->pci_config(vha);
  555. if (rval) {
  556. ql_log(ql_log_warn, vha, 0x0044,
  557. "Unable to configure PCI space.\n");
  558. return (rval);
  559. }
  560. ha->isp_ops->reset_chip(vha);
  561. rval = qla2xxx_get_flash_info(vha);
  562. if (rval) {
  563. ql_log(ql_log_fatal, vha, 0x004f,
  564. "Unable to validate FLASH data.\n");
  565. return rval;
  566. }
  567. if (IS_QLA8044(ha)) {
  568. qla8044_read_reset_template(vha);
  569. /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
  570. * If DONRESET_BIT0 is set, drivers should not set dev_state
  571. * to NEED_RESET. But if NEED_RESET is set, drivers should
  572. * should honor the reset. */
  573. if (ql2xdontresethba == 1)
  574. qla8044_set_idc_dontreset(vha);
  575. }
  576. ha->isp_ops->get_flash_version(vha, req->ring);
  577. ql_dbg(ql_dbg_init, vha, 0x0061,
  578. "Configure NVRAM parameters...\n");
  579. ha->isp_ops->nvram_config(vha);
  580. if (ha->flags.disable_serdes) {
  581. /* Mask HBA via NVRAM settings? */
  582. ql_log(ql_log_info, vha, 0x0077,
  583. "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
  584. return QLA_FUNCTION_FAILED;
  585. }
  586. ql_dbg(ql_dbg_init, vha, 0x0078,
  587. "Verifying loaded RISC code...\n");
  588. if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
  589. rval = ha->isp_ops->chip_diag(vha);
  590. if (rval)
  591. return (rval);
  592. rval = qla2x00_setup_chip(vha);
  593. if (rval)
  594. return (rval);
  595. }
  596. if (IS_QLA84XX(ha)) {
  597. ha->cs84xx = qla84xx_get_chip(vha);
  598. if (!ha->cs84xx) {
  599. ql_log(ql_log_warn, vha, 0x00d0,
  600. "Unable to configure ISP84XX.\n");
  601. return QLA_FUNCTION_FAILED;
  602. }
  603. }
  604. if (qla_ini_mode_enabled(vha))
  605. rval = qla2x00_init_rings(vha);
  606. ha->flags.chip_reset_done = 1;
  607. if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
  608. /* Issue verify 84xx FW IOCB to complete 84xx initialization */
  609. rval = qla84xx_init_chip(vha);
  610. if (rval != QLA_SUCCESS) {
  611. ql_log(ql_log_warn, vha, 0x00d4,
  612. "Unable to initialize ISP84XX.\n");
  613. qla84xx_put_chip(vha);
  614. }
  615. }
  616. /* Load the NIC Core f/w if we are the first protocol driver. */
  617. if (IS_QLA8031(ha)) {
  618. rval = qla83xx_nic_core_fw_load(vha);
  619. if (rval)
  620. ql_log(ql_log_warn, vha, 0x0124,
  621. "Error in initializing NIC Core f/w.\n");
  622. }
  623. if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
  624. qla24xx_read_fcp_prio_cfg(vha);
  625. if (IS_P3P_TYPE(ha))
  626. qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
  627. else
  628. qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
  629. return (rval);
  630. }
  631. /**
  632. * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
  633. * @ha: HA context
  634. *
  635. * Returns 0 on success.
  636. */
  637. int
  638. qla2100_pci_config(scsi_qla_host_t *vha)
  639. {
  640. uint16_t w;
  641. unsigned long flags;
  642. struct qla_hw_data *ha = vha->hw;
  643. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  644. pci_set_master(ha->pdev);
  645. pci_try_set_mwi(ha->pdev);
  646. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  647. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  648. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  649. pci_disable_rom(ha->pdev);
  650. /* Get PCI bus information. */
  651. spin_lock_irqsave(&ha->hardware_lock, flags);
  652. ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
  653. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  654. return QLA_SUCCESS;
  655. }
  656. /**
  657. * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
  658. * @ha: HA context
  659. *
  660. * Returns 0 on success.
  661. */
  662. int
  663. qla2300_pci_config(scsi_qla_host_t *vha)
  664. {
  665. uint16_t w;
  666. unsigned long flags = 0;
  667. uint32_t cnt;
  668. struct qla_hw_data *ha = vha->hw;
  669. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  670. pci_set_master(ha->pdev);
  671. pci_try_set_mwi(ha->pdev);
  672. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  673. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  674. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  675. w &= ~PCI_COMMAND_INTX_DISABLE;
  676. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  677. /*
  678. * If this is a 2300 card and not 2312, reset the
  679. * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
  680. * the 2310 also reports itself as a 2300 so we need to get the
  681. * fb revision level -- a 6 indicates it really is a 2300 and
  682. * not a 2310.
  683. */
  684. if (IS_QLA2300(ha)) {
  685. spin_lock_irqsave(&ha->hardware_lock, flags);
  686. /* Pause RISC. */
  687. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  688. for (cnt = 0; cnt < 30000; cnt++) {
  689. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
  690. break;
  691. udelay(10);
  692. }
  693. /* Select FPM registers. */
  694. WRT_REG_WORD(&reg->ctrl_status, 0x20);
  695. RD_REG_WORD(&reg->ctrl_status);
  696. /* Get the fb rev level */
  697. ha->fb_rev = RD_FB_CMD_REG(ha, reg);
  698. if (ha->fb_rev == FPM_2300)
  699. pci_clear_mwi(ha->pdev);
  700. /* Deselect FPM registers. */
  701. WRT_REG_WORD(&reg->ctrl_status, 0x0);
  702. RD_REG_WORD(&reg->ctrl_status);
  703. /* Release RISC module. */
  704. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  705. for (cnt = 0; cnt < 30000; cnt++) {
  706. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
  707. break;
  708. udelay(10);
  709. }
  710. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  711. }
  712. pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
  713. pci_disable_rom(ha->pdev);
  714. /* Get PCI bus information. */
  715. spin_lock_irqsave(&ha->hardware_lock, flags);
  716. ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
  717. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  718. return QLA_SUCCESS;
  719. }
  720. /**
  721. * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
  722. * @ha: HA context
  723. *
  724. * Returns 0 on success.
  725. */
  726. int
  727. qla24xx_pci_config(scsi_qla_host_t *vha)
  728. {
  729. uint16_t w;
  730. unsigned long flags = 0;
  731. struct qla_hw_data *ha = vha->hw;
  732. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  733. pci_set_master(ha->pdev);
  734. pci_try_set_mwi(ha->pdev);
  735. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  736. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  737. w &= ~PCI_COMMAND_INTX_DISABLE;
  738. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  739. pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
  740. /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
  741. if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
  742. pcix_set_mmrbc(ha->pdev, 2048);
  743. /* PCIe -- adjust Maximum Read Request Size (2048). */
  744. if (pci_is_pcie(ha->pdev))
  745. pcie_set_readrq(ha->pdev, 4096);
  746. pci_disable_rom(ha->pdev);
  747. ha->chip_revision = ha->pdev->revision;
  748. /* Get PCI bus information. */
  749. spin_lock_irqsave(&ha->hardware_lock, flags);
  750. ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
  751. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  752. return QLA_SUCCESS;
  753. }
  754. /**
  755. * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
  756. * @ha: HA context
  757. *
  758. * Returns 0 on success.
  759. */
  760. int
  761. qla25xx_pci_config(scsi_qla_host_t *vha)
  762. {
  763. uint16_t w;
  764. struct qla_hw_data *ha = vha->hw;
  765. pci_set_master(ha->pdev);
  766. pci_try_set_mwi(ha->pdev);
  767. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  768. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  769. w &= ~PCI_COMMAND_INTX_DISABLE;
  770. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  771. /* PCIe -- adjust Maximum Read Request Size (2048). */
  772. if (pci_is_pcie(ha->pdev))
  773. pcie_set_readrq(ha->pdev, 4096);
  774. pci_disable_rom(ha->pdev);
  775. ha->chip_revision = ha->pdev->revision;
  776. return QLA_SUCCESS;
  777. }
  778. /**
  779. * qla2x00_isp_firmware() - Choose firmware image.
  780. * @ha: HA context
  781. *
  782. * Returns 0 on success.
  783. */
  784. static int
  785. qla2x00_isp_firmware(scsi_qla_host_t *vha)
  786. {
  787. int rval;
  788. uint16_t loop_id, topo, sw_cap;
  789. uint8_t domain, area, al_pa;
  790. struct qla_hw_data *ha = vha->hw;
  791. /* Assume loading risc code */
  792. rval = QLA_FUNCTION_FAILED;
  793. if (ha->flags.disable_risc_code_load) {
  794. ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
  795. /* Verify checksum of loaded RISC code. */
  796. rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
  797. if (rval == QLA_SUCCESS) {
  798. /* And, verify we are not in ROM code. */
  799. rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
  800. &area, &domain, &topo, &sw_cap);
  801. }
  802. }
  803. if (rval)
  804. ql_dbg(ql_dbg_init, vha, 0x007a,
  805. "**** Load RISC code ****.\n");
  806. return (rval);
  807. }
  808. /**
  809. * qla2x00_reset_chip() - Reset ISP chip.
  810. * @ha: HA context
  811. *
  812. * Returns 0 on success.
  813. */
  814. void
  815. qla2x00_reset_chip(scsi_qla_host_t *vha)
  816. {
  817. unsigned long flags = 0;
  818. struct qla_hw_data *ha = vha->hw;
  819. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  820. uint32_t cnt;
  821. uint16_t cmd;
  822. if (unlikely(pci_channel_offline(ha->pdev)))
  823. return;
  824. ha->isp_ops->disable_intrs(ha);
  825. spin_lock_irqsave(&ha->hardware_lock, flags);
  826. /* Turn off master enable */
  827. cmd = 0;
  828. pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
  829. cmd &= ~PCI_COMMAND_MASTER;
  830. pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
  831. if (!IS_QLA2100(ha)) {
  832. /* Pause RISC. */
  833. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  834. if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
  835. for (cnt = 0; cnt < 30000; cnt++) {
  836. if ((RD_REG_WORD(&reg->hccr) &
  837. HCCR_RISC_PAUSE) != 0)
  838. break;
  839. udelay(100);
  840. }
  841. } else {
  842. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  843. udelay(10);
  844. }
  845. /* Select FPM registers. */
  846. WRT_REG_WORD(&reg->ctrl_status, 0x20);
  847. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  848. /* FPM Soft Reset. */
  849. WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
  850. RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
  851. /* Toggle Fpm Reset. */
  852. if (!IS_QLA2200(ha)) {
  853. WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
  854. RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
  855. }
  856. /* Select frame buffer registers. */
  857. WRT_REG_WORD(&reg->ctrl_status, 0x10);
  858. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  859. /* Reset frame buffer FIFOs. */
  860. if (IS_QLA2200(ha)) {
  861. WRT_FB_CMD_REG(ha, reg, 0xa000);
  862. RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
  863. } else {
  864. WRT_FB_CMD_REG(ha, reg, 0x00fc);
  865. /* Read back fb_cmd until zero or 3 seconds max */
  866. for (cnt = 0; cnt < 3000; cnt++) {
  867. if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
  868. break;
  869. udelay(100);
  870. }
  871. }
  872. /* Select RISC module registers. */
  873. WRT_REG_WORD(&reg->ctrl_status, 0);
  874. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  875. /* Reset RISC processor. */
  876. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  877. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  878. /* Release RISC processor. */
  879. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  880. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  881. }
  882. WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
  883. WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
  884. /* Reset ISP chip. */
  885. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  886. /* Wait for RISC to recover from reset. */
  887. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  888. /*
  889. * It is necessary to for a delay here since the card doesn't
  890. * respond to PCI reads during a reset. On some architectures
  891. * this will result in an MCA.
  892. */
  893. udelay(20);
  894. for (cnt = 30000; cnt; cnt--) {
  895. if ((RD_REG_WORD(&reg->ctrl_status) &
  896. CSR_ISP_SOFT_RESET) == 0)
  897. break;
  898. udelay(100);
  899. }
  900. } else
  901. udelay(10);
  902. /* Reset RISC processor. */
  903. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  904. WRT_REG_WORD(&reg->semaphore, 0);
  905. /* Release RISC processor. */
  906. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  907. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  908. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  909. for (cnt = 0; cnt < 30000; cnt++) {
  910. if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
  911. break;
  912. udelay(100);
  913. }
  914. } else
  915. udelay(100);
  916. /* Turn on master enable */
  917. cmd |= PCI_COMMAND_MASTER;
  918. pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
  919. /* Disable RISC pause on FPM parity error. */
  920. if (!IS_QLA2100(ha)) {
  921. WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
  922. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  923. }
  924. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  925. }
  926. /**
  927. * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
  928. *
  929. * Returns 0 on success.
  930. */
  931. static int
  932. qla81xx_reset_mpi(scsi_qla_host_t *vha)
  933. {
  934. uint16_t mb[4] = {0x1010, 0, 1, 0};
  935. if (!IS_QLA81XX(vha->hw))
  936. return QLA_SUCCESS;
  937. return qla81xx_write_mpi_register(vha, mb);
  938. }
  939. /**
  940. * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
  941. * @ha: HA context
  942. *
  943. * Returns 0 on success.
  944. */
  945. static inline int
  946. qla24xx_reset_risc(scsi_qla_host_t *vha)
  947. {
  948. unsigned long flags = 0;
  949. struct qla_hw_data *ha = vha->hw;
  950. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  951. uint32_t cnt;
  952. uint16_t wd;
  953. static int abts_cnt; /* ISP abort retry counts */
  954. int rval = QLA_SUCCESS;
  955. spin_lock_irqsave(&ha->hardware_lock, flags);
  956. /* Reset RISC. */
  957. WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
  958. for (cnt = 0; cnt < 30000; cnt++) {
  959. if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
  960. break;
  961. udelay(10);
  962. }
  963. if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE))
  964. set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
  965. ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
  966. "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
  967. RD_REG_DWORD(&reg->hccr),
  968. RD_REG_DWORD(&reg->ctrl_status),
  969. (RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE));
  970. WRT_REG_DWORD(&reg->ctrl_status,
  971. CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
  972. pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
  973. udelay(100);
  974. /* Wait for firmware to complete NVRAM accesses. */
  975. RD_REG_WORD(&reg->mailbox0);
  976. for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
  977. rval == QLA_SUCCESS; cnt--) {
  978. barrier();
  979. if (cnt)
  980. udelay(5);
  981. else
  982. rval = QLA_FUNCTION_TIMEOUT;
  983. }
  984. if (rval == QLA_SUCCESS)
  985. set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
  986. ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
  987. "HCCR: 0x%x, MailBox0 Status 0x%x\n",
  988. RD_REG_DWORD(&reg->hccr),
  989. RD_REG_DWORD(&reg->mailbox0));
  990. /* Wait for soft-reset to complete. */
  991. RD_REG_DWORD(&reg->ctrl_status);
  992. for (cnt = 0; cnt < 6000000; cnt++) {
  993. barrier();
  994. if ((RD_REG_DWORD(&reg->ctrl_status) &
  995. CSRX_ISP_SOFT_RESET) == 0)
  996. break;
  997. udelay(5);
  998. }
  999. if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_ISP_SOFT_RESET))
  1000. set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
  1001. ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
  1002. "HCCR: 0x%x, Soft Reset status: 0x%x\n",
  1003. RD_REG_DWORD(&reg->hccr),
  1004. RD_REG_DWORD(&reg->ctrl_status));
  1005. /* If required, do an MPI FW reset now */
  1006. if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
  1007. if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
  1008. if (++abts_cnt < 5) {
  1009. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  1010. set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
  1011. } else {
  1012. /*
  1013. * We exhausted the ISP abort retries. We have to
  1014. * set the board offline.
  1015. */
  1016. abts_cnt = 0;
  1017. vha->flags.online = 0;
  1018. }
  1019. }
  1020. }
  1021. WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
  1022. RD_REG_DWORD(&reg->hccr);
  1023. WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  1024. RD_REG_DWORD(&reg->hccr);
  1025. WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
  1026. RD_REG_DWORD(&reg->hccr);
  1027. RD_REG_WORD(&reg->mailbox0);
  1028. for (cnt = 6000000; RD_REG_WORD(&reg->mailbox0) != 0 &&
  1029. rval == QLA_SUCCESS; cnt--) {
  1030. barrier();
  1031. if (cnt)
  1032. udelay(5);
  1033. else
  1034. rval = QLA_FUNCTION_TIMEOUT;
  1035. }
  1036. if (rval == QLA_SUCCESS)
  1037. set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
  1038. ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
  1039. "Host Risc 0x%x, mailbox0 0x%x\n",
  1040. RD_REG_DWORD(&reg->hccr),
  1041. RD_REG_WORD(&reg->mailbox0));
  1042. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1043. ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
  1044. "Driver in %s mode\n",
  1045. IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
  1046. if (IS_NOPOLLING_TYPE(ha))
  1047. ha->isp_ops->enable_intrs(ha);
  1048. return rval;
  1049. }
  1050. static void
  1051. qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
  1052. {
  1053. struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
  1054. WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
  1055. *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
  1056. }
  1057. static void
  1058. qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
  1059. {
  1060. struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
  1061. WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
  1062. WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
  1063. }
  1064. static void
  1065. qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
  1066. {
  1067. uint32_t wd32 = 0;
  1068. uint delta_msec = 100;
  1069. uint elapsed_msec = 0;
  1070. uint timeout_msec;
  1071. ulong n;
  1072. if (vha->hw->pdev->subsystem_device != 0x0175 &&
  1073. vha->hw->pdev->subsystem_device != 0x0240)
  1074. return;
  1075. WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
  1076. udelay(100);
  1077. attempt:
  1078. timeout_msec = TIMEOUT_SEMAPHORE;
  1079. n = timeout_msec / delta_msec;
  1080. while (n--) {
  1081. qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
  1082. qla25xx_read_risc_sema_reg(vha, &wd32);
  1083. if (wd32 & RISC_SEMAPHORE)
  1084. break;
  1085. msleep(delta_msec);
  1086. elapsed_msec += delta_msec;
  1087. if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
  1088. goto force;
  1089. }
  1090. if (!(wd32 & RISC_SEMAPHORE))
  1091. goto force;
  1092. if (!(wd32 & RISC_SEMAPHORE_FORCE))
  1093. goto acquired;
  1094. qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
  1095. timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
  1096. n = timeout_msec / delta_msec;
  1097. while (n--) {
  1098. qla25xx_read_risc_sema_reg(vha, &wd32);
  1099. if (!(wd32 & RISC_SEMAPHORE_FORCE))
  1100. break;
  1101. msleep(delta_msec);
  1102. elapsed_msec += delta_msec;
  1103. if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
  1104. goto force;
  1105. }
  1106. if (wd32 & RISC_SEMAPHORE_FORCE)
  1107. qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
  1108. goto attempt;
  1109. force:
  1110. qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
  1111. acquired:
  1112. return;
  1113. }
  1114. /**
  1115. * qla24xx_reset_chip() - Reset ISP24xx chip.
  1116. * @ha: HA context
  1117. *
  1118. * Returns 0 on success.
  1119. */
  1120. void
  1121. qla24xx_reset_chip(scsi_qla_host_t *vha)
  1122. {
  1123. struct qla_hw_data *ha = vha->hw;
  1124. if (pci_channel_offline(ha->pdev) &&
  1125. ha->flags.pci_channel_io_perm_failure) {
  1126. return;
  1127. }
  1128. ha->isp_ops->disable_intrs(ha);
  1129. qla25xx_manipulate_risc_semaphore(vha);
  1130. /* Perform RISC reset. */
  1131. qla24xx_reset_risc(vha);
  1132. }
  1133. /**
  1134. * qla2x00_chip_diag() - Test chip for proper operation.
  1135. * @ha: HA context
  1136. *
  1137. * Returns 0 on success.
  1138. */
  1139. int
  1140. qla2x00_chip_diag(scsi_qla_host_t *vha)
  1141. {
  1142. int rval;
  1143. struct qla_hw_data *ha = vha->hw;
  1144. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1145. unsigned long flags = 0;
  1146. uint16_t data;
  1147. uint32_t cnt;
  1148. uint16_t mb[5];
  1149. struct req_que *req = ha->req_q_map[0];
  1150. /* Assume a failed state */
  1151. rval = QLA_FUNCTION_FAILED;
  1152. ql_dbg(ql_dbg_init, vha, 0x007b,
  1153. "Testing device at %lx.\n", (u_long)&reg->flash_address);
  1154. spin_lock_irqsave(&ha->hardware_lock, flags);
  1155. /* Reset ISP chip. */
  1156. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  1157. /*
  1158. * We need to have a delay here since the card will not respond while
  1159. * in reset causing an MCA on some architectures.
  1160. */
  1161. udelay(20);
  1162. data = qla2x00_debounce_register(&reg->ctrl_status);
  1163. for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
  1164. udelay(5);
  1165. data = RD_REG_WORD(&reg->ctrl_status);
  1166. barrier();
  1167. }
  1168. if (!cnt)
  1169. goto chip_diag_failed;
  1170. ql_dbg(ql_dbg_init, vha, 0x007c,
  1171. "Reset register cleared by chip reset.\n");
  1172. /* Reset RISC processor. */
  1173. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  1174. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  1175. /* Workaround for QLA2312 PCI parity error */
  1176. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  1177. data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
  1178. for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
  1179. udelay(5);
  1180. data = RD_MAILBOX_REG(ha, reg, 0);
  1181. barrier();
  1182. }
  1183. } else
  1184. udelay(10);
  1185. if (!cnt)
  1186. goto chip_diag_failed;
  1187. /* Check product ID of chip */
  1188. ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
  1189. mb[1] = RD_MAILBOX_REG(ha, reg, 1);
  1190. mb[2] = RD_MAILBOX_REG(ha, reg, 2);
  1191. mb[3] = RD_MAILBOX_REG(ha, reg, 3);
  1192. mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
  1193. if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
  1194. mb[3] != PROD_ID_3) {
  1195. ql_log(ql_log_warn, vha, 0x0062,
  1196. "Wrong product ID = 0x%x,0x%x,0x%x.\n",
  1197. mb[1], mb[2], mb[3]);
  1198. goto chip_diag_failed;
  1199. }
  1200. ha->product_id[0] = mb[1];
  1201. ha->product_id[1] = mb[2];
  1202. ha->product_id[2] = mb[3];
  1203. ha->product_id[3] = mb[4];
  1204. /* Adjust fw RISC transfer size */
  1205. if (req->length > 1024)
  1206. ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
  1207. else
  1208. ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
  1209. req->length;
  1210. if (IS_QLA2200(ha) &&
  1211. RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
  1212. /* Limit firmware transfer size with a 2200A */
  1213. ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
  1214. ha->device_type |= DT_ISP2200A;
  1215. ha->fw_transfer_size = 128;
  1216. }
  1217. /* Wrap Incoming Mailboxes Test. */
  1218. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1219. ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
  1220. rval = qla2x00_mbx_reg_test(vha);
  1221. if (rval)
  1222. ql_log(ql_log_warn, vha, 0x0080,
  1223. "Failed mailbox send register test.\n");
  1224. else
  1225. /* Flag a successful rval */
  1226. rval = QLA_SUCCESS;
  1227. spin_lock_irqsave(&ha->hardware_lock, flags);
  1228. chip_diag_failed:
  1229. if (rval)
  1230. ql_log(ql_log_info, vha, 0x0081,
  1231. "Chip diagnostics **** FAILED ****.\n");
  1232. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1233. return (rval);
  1234. }
  1235. /**
  1236. * qla24xx_chip_diag() - Test ISP24xx for proper operation.
  1237. * @ha: HA context
  1238. *
  1239. * Returns 0 on success.
  1240. */
  1241. int
  1242. qla24xx_chip_diag(scsi_qla_host_t *vha)
  1243. {
  1244. int rval;
  1245. struct qla_hw_data *ha = vha->hw;
  1246. struct req_que *req = ha->req_q_map[0];
  1247. if (IS_P3P_TYPE(ha))
  1248. return QLA_SUCCESS;
  1249. ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
  1250. rval = qla2x00_mbx_reg_test(vha);
  1251. if (rval) {
  1252. ql_log(ql_log_warn, vha, 0x0082,
  1253. "Failed mailbox send register test.\n");
  1254. } else {
  1255. /* Flag a successful rval */
  1256. rval = QLA_SUCCESS;
  1257. }
  1258. return rval;
  1259. }
  1260. void
  1261. qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
  1262. {
  1263. int rval;
  1264. uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
  1265. eft_size, fce_size, mq_size;
  1266. dma_addr_t tc_dma;
  1267. void *tc;
  1268. struct qla_hw_data *ha = vha->hw;
  1269. struct req_que *req = ha->req_q_map[0];
  1270. struct rsp_que *rsp = ha->rsp_q_map[0];
  1271. if (ha->fw_dump) {
  1272. ql_dbg(ql_dbg_init, vha, 0x00bd,
  1273. "Firmware dump already allocated.\n");
  1274. return;
  1275. }
  1276. ha->fw_dumped = 0;
  1277. ha->fw_dump_cap_flags = 0;
  1278. dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
  1279. req_q_size = rsp_q_size = 0;
  1280. if (IS_QLA27XX(ha))
  1281. goto try_fce;
  1282. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  1283. fixed_size = sizeof(struct qla2100_fw_dump);
  1284. } else if (IS_QLA23XX(ha)) {
  1285. fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
  1286. mem_size = (ha->fw_memory_size - 0x11000 + 1) *
  1287. sizeof(uint16_t);
  1288. } else if (IS_FWI2_CAPABLE(ha)) {
  1289. if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
  1290. fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
  1291. else if (IS_QLA81XX(ha))
  1292. fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
  1293. else if (IS_QLA25XX(ha))
  1294. fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
  1295. else
  1296. fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
  1297. mem_size = (ha->fw_memory_size - 0x100000 + 1) *
  1298. sizeof(uint32_t);
  1299. if (ha->mqenable) {
  1300. if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
  1301. mq_size = sizeof(struct qla2xxx_mq_chain);
  1302. /*
  1303. * Allocate maximum buffer size for all queues.
  1304. * Resizing must be done at end-of-dump processing.
  1305. */
  1306. mq_size += ha->max_req_queues *
  1307. (req->length * sizeof(request_t));
  1308. mq_size += ha->max_rsp_queues *
  1309. (rsp->length * sizeof(response_t));
  1310. }
  1311. if (ha->tgt.atio_ring)
  1312. mq_size += ha->tgt.atio_q_length * sizeof(request_t);
  1313. /* Allocate memory for Fibre Channel Event Buffer. */
  1314. if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
  1315. !IS_QLA27XX(ha))
  1316. goto try_eft;
  1317. try_fce:
  1318. if (ha->fce)
  1319. dma_free_coherent(&ha->pdev->dev,
  1320. FCE_SIZE, ha->fce, ha->fce_dma);
  1321. /* Allocate memory for Fibre Channel Event Buffer. */
  1322. tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
  1323. GFP_KERNEL);
  1324. if (!tc) {
  1325. ql_log(ql_log_warn, vha, 0x00be,
  1326. "Unable to allocate (%d KB) for FCE.\n",
  1327. FCE_SIZE / 1024);
  1328. goto try_eft;
  1329. }
  1330. rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
  1331. ha->fce_mb, &ha->fce_bufs);
  1332. if (rval) {
  1333. ql_log(ql_log_warn, vha, 0x00bf,
  1334. "Unable to initialize FCE (%d).\n", rval);
  1335. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
  1336. tc_dma);
  1337. ha->flags.fce_enabled = 0;
  1338. goto try_eft;
  1339. }
  1340. ql_dbg(ql_dbg_init, vha, 0x00c0,
  1341. "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
  1342. fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
  1343. ha->flags.fce_enabled = 1;
  1344. ha->fce_dma = tc_dma;
  1345. ha->fce = tc;
  1346. try_eft:
  1347. if (ha->eft)
  1348. dma_free_coherent(&ha->pdev->dev,
  1349. EFT_SIZE, ha->eft, ha->eft_dma);
  1350. /* Allocate memory for Extended Trace Buffer. */
  1351. tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
  1352. GFP_KERNEL);
  1353. if (!tc) {
  1354. ql_log(ql_log_warn, vha, 0x00c1,
  1355. "Unable to allocate (%d KB) for EFT.\n",
  1356. EFT_SIZE / 1024);
  1357. goto cont_alloc;
  1358. }
  1359. rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
  1360. if (rval) {
  1361. ql_log(ql_log_warn, vha, 0x00c2,
  1362. "Unable to initialize EFT (%d).\n", rval);
  1363. dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
  1364. tc_dma);
  1365. goto cont_alloc;
  1366. }
  1367. ql_dbg(ql_dbg_init, vha, 0x00c3,
  1368. "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
  1369. eft_size = EFT_SIZE;
  1370. ha->eft_dma = tc_dma;
  1371. ha->eft = tc;
  1372. }
  1373. cont_alloc:
  1374. if (IS_QLA27XX(ha)) {
  1375. if (!ha->fw_dump_template) {
  1376. ql_log(ql_log_warn, vha, 0x00ba,
  1377. "Failed missing fwdump template\n");
  1378. return;
  1379. }
  1380. dump_size = qla27xx_fwdt_calculate_dump_size(vha);
  1381. ql_dbg(ql_dbg_init, vha, 0x00fa,
  1382. "-> allocating fwdump (%x bytes)...\n", dump_size);
  1383. goto allocate;
  1384. }
  1385. req_q_size = req->length * sizeof(request_t);
  1386. rsp_q_size = rsp->length * sizeof(response_t);
  1387. dump_size = offsetof(struct qla2xxx_fw_dump, isp);
  1388. dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
  1389. ha->chain_offset = dump_size;
  1390. dump_size += mq_size + fce_size;
  1391. allocate:
  1392. ha->fw_dump = vmalloc(dump_size);
  1393. if (!ha->fw_dump) {
  1394. ql_log(ql_log_warn, vha, 0x00c4,
  1395. "Unable to allocate (%d KB) for firmware dump.\n",
  1396. dump_size / 1024);
  1397. if (ha->fce) {
  1398. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
  1399. ha->fce_dma);
  1400. ha->fce = NULL;
  1401. ha->fce_dma = 0;
  1402. }
  1403. if (ha->eft) {
  1404. dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
  1405. ha->eft_dma);
  1406. ha->eft = NULL;
  1407. ha->eft_dma = 0;
  1408. }
  1409. return;
  1410. }
  1411. ha->fw_dump_len = dump_size;
  1412. ql_dbg(ql_dbg_init, vha, 0x00c5,
  1413. "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
  1414. if (IS_QLA27XX(ha))
  1415. return;
  1416. ha->fw_dump->signature[0] = 'Q';
  1417. ha->fw_dump->signature[1] = 'L';
  1418. ha->fw_dump->signature[2] = 'G';
  1419. ha->fw_dump->signature[3] = 'C';
  1420. ha->fw_dump->version = htonl(1);
  1421. ha->fw_dump->fixed_size = htonl(fixed_size);
  1422. ha->fw_dump->mem_size = htonl(mem_size);
  1423. ha->fw_dump->req_q_size = htonl(req_q_size);
  1424. ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
  1425. ha->fw_dump->eft_size = htonl(eft_size);
  1426. ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
  1427. ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
  1428. ha->fw_dump->header_size =
  1429. htonl(offsetof(struct qla2xxx_fw_dump, isp));
  1430. }
  1431. static int
  1432. qla81xx_mpi_sync(scsi_qla_host_t *vha)
  1433. {
  1434. #define MPS_MASK 0xe0
  1435. int rval;
  1436. uint16_t dc;
  1437. uint32_t dw;
  1438. if (!IS_QLA81XX(vha->hw))
  1439. return QLA_SUCCESS;
  1440. rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
  1441. if (rval != QLA_SUCCESS) {
  1442. ql_log(ql_log_warn, vha, 0x0105,
  1443. "Unable to acquire semaphore.\n");
  1444. goto done;
  1445. }
  1446. pci_read_config_word(vha->hw->pdev, 0x54, &dc);
  1447. rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
  1448. if (rval != QLA_SUCCESS) {
  1449. ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
  1450. goto done_release;
  1451. }
  1452. dc &= MPS_MASK;
  1453. if (dc == (dw & MPS_MASK))
  1454. goto done_release;
  1455. dw &= ~MPS_MASK;
  1456. dw |= dc;
  1457. rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
  1458. if (rval != QLA_SUCCESS) {
  1459. ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
  1460. }
  1461. done_release:
  1462. rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
  1463. if (rval != QLA_SUCCESS) {
  1464. ql_log(ql_log_warn, vha, 0x006d,
  1465. "Unable to release semaphore.\n");
  1466. }
  1467. done:
  1468. return rval;
  1469. }
  1470. int
  1471. qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
  1472. {
  1473. /* Don't try to reallocate the array */
  1474. if (req->outstanding_cmds)
  1475. return QLA_SUCCESS;
  1476. if (!IS_FWI2_CAPABLE(ha) || (ha->mqiobase &&
  1477. (ql2xmultique_tag || ql2xmaxqueues > 1)))
  1478. req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
  1479. else {
  1480. if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
  1481. req->num_outstanding_cmds = ha->cur_fw_xcb_count;
  1482. else
  1483. req->num_outstanding_cmds = ha->cur_fw_iocb_count;
  1484. }
  1485. req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
  1486. req->num_outstanding_cmds, GFP_KERNEL);
  1487. if (!req->outstanding_cmds) {
  1488. /*
  1489. * Try to allocate a minimal size just so we can get through
  1490. * initialization.
  1491. */
  1492. req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
  1493. req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
  1494. req->num_outstanding_cmds, GFP_KERNEL);
  1495. if (!req->outstanding_cmds) {
  1496. ql_log(ql_log_fatal, NULL, 0x0126,
  1497. "Failed to allocate memory for "
  1498. "outstanding_cmds for req_que %p.\n", req);
  1499. req->num_outstanding_cmds = 0;
  1500. return QLA_FUNCTION_FAILED;
  1501. }
  1502. }
  1503. return QLA_SUCCESS;
  1504. }
  1505. /**
  1506. * qla2x00_setup_chip() - Load and start RISC firmware.
  1507. * @ha: HA context
  1508. *
  1509. * Returns 0 on success.
  1510. */
  1511. static int
  1512. qla2x00_setup_chip(scsi_qla_host_t *vha)
  1513. {
  1514. int rval;
  1515. uint32_t srisc_address = 0;
  1516. struct qla_hw_data *ha = vha->hw;
  1517. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1518. unsigned long flags;
  1519. uint16_t fw_major_version;
  1520. if (IS_P3P_TYPE(ha)) {
  1521. rval = ha->isp_ops->load_risc(vha, &srisc_address);
  1522. if (rval == QLA_SUCCESS) {
  1523. qla2x00_stop_firmware(vha);
  1524. goto enable_82xx_npiv;
  1525. } else
  1526. goto failed;
  1527. }
  1528. if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
  1529. /* Disable SRAM, Instruction RAM and GP RAM parity. */
  1530. spin_lock_irqsave(&ha->hardware_lock, flags);
  1531. WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
  1532. RD_REG_WORD(&reg->hccr);
  1533. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1534. }
  1535. qla81xx_mpi_sync(vha);
  1536. /* Load firmware sequences */
  1537. rval = ha->isp_ops->load_risc(vha, &srisc_address);
  1538. if (rval == QLA_SUCCESS) {
  1539. ql_dbg(ql_dbg_init, vha, 0x00c9,
  1540. "Verifying Checksum of loaded RISC code.\n");
  1541. rval = qla2x00_verify_checksum(vha, srisc_address);
  1542. if (rval == QLA_SUCCESS) {
  1543. /* Start firmware execution. */
  1544. ql_dbg(ql_dbg_init, vha, 0x00ca,
  1545. "Starting firmware.\n");
  1546. if (ql2xexlogins)
  1547. ha->flags.exlogins_enabled = 1;
  1548. if (ql2xexchoffld)
  1549. ha->flags.exchoffld_enabled = 1;
  1550. rval = qla2x00_execute_fw(vha, srisc_address);
  1551. /* Retrieve firmware information. */
  1552. if (rval == QLA_SUCCESS) {
  1553. rval = qla2x00_set_exlogins_buffer(vha);
  1554. if (rval != QLA_SUCCESS)
  1555. goto failed;
  1556. rval = qla2x00_set_exchoffld_buffer(vha);
  1557. if (rval != QLA_SUCCESS)
  1558. goto failed;
  1559. enable_82xx_npiv:
  1560. fw_major_version = ha->fw_major_version;
  1561. if (IS_P3P_TYPE(ha))
  1562. qla82xx_check_md_needed(vha);
  1563. else
  1564. rval = qla2x00_get_fw_version(vha);
  1565. if (rval != QLA_SUCCESS)
  1566. goto failed;
  1567. ha->flags.npiv_supported = 0;
  1568. if (IS_QLA2XXX_MIDTYPE(ha) &&
  1569. (ha->fw_attributes & BIT_2)) {
  1570. ha->flags.npiv_supported = 1;
  1571. if ((!ha->max_npiv_vports) ||
  1572. ((ha->max_npiv_vports + 1) %
  1573. MIN_MULTI_ID_FABRIC))
  1574. ha->max_npiv_vports =
  1575. MIN_MULTI_ID_FABRIC - 1;
  1576. }
  1577. qla2x00_get_resource_cnts(vha);
  1578. /*
  1579. * Allocate the array of outstanding commands
  1580. * now that we know the firmware resources.
  1581. */
  1582. rval = qla2x00_alloc_outstanding_cmds(ha,
  1583. vha->req);
  1584. if (rval != QLA_SUCCESS)
  1585. goto failed;
  1586. if (!fw_major_version && ql2xallocfwdump
  1587. && !(IS_P3P_TYPE(ha)))
  1588. qla2x00_alloc_fw_dump(vha);
  1589. } else {
  1590. goto failed;
  1591. }
  1592. } else {
  1593. ql_log(ql_log_fatal, vha, 0x00cd,
  1594. "ISP Firmware failed checksum.\n");
  1595. goto failed;
  1596. }
  1597. } else
  1598. goto failed;
  1599. if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
  1600. /* Enable proper parity. */
  1601. spin_lock_irqsave(&ha->hardware_lock, flags);
  1602. if (IS_QLA2300(ha))
  1603. /* SRAM parity */
  1604. WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
  1605. else
  1606. /* SRAM, Instruction RAM and GP RAM parity */
  1607. WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
  1608. RD_REG_WORD(&reg->hccr);
  1609. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1610. }
  1611. if (IS_QLA27XX(ha))
  1612. ha->flags.fac_supported = 1;
  1613. else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
  1614. uint32_t size;
  1615. rval = qla81xx_fac_get_sector_size(vha, &size);
  1616. if (rval == QLA_SUCCESS) {
  1617. ha->flags.fac_supported = 1;
  1618. ha->fdt_block_size = size << 2;
  1619. } else {
  1620. ql_log(ql_log_warn, vha, 0x00ce,
  1621. "Unsupported FAC firmware (%d.%02d.%02d).\n",
  1622. ha->fw_major_version, ha->fw_minor_version,
  1623. ha->fw_subminor_version);
  1624. if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
  1625. ha->flags.fac_supported = 0;
  1626. rval = QLA_SUCCESS;
  1627. }
  1628. }
  1629. }
  1630. failed:
  1631. if (rval) {
  1632. ql_log(ql_log_fatal, vha, 0x00cf,
  1633. "Setup chip ****FAILED****.\n");
  1634. }
  1635. return (rval);
  1636. }
  1637. /**
  1638. * qla2x00_init_response_q_entries() - Initializes response queue entries.
  1639. * @ha: HA context
  1640. *
  1641. * Beginning of request ring has initialization control block already built
  1642. * by nvram config routine.
  1643. *
  1644. * Returns 0 on success.
  1645. */
  1646. void
  1647. qla2x00_init_response_q_entries(struct rsp_que *rsp)
  1648. {
  1649. uint16_t cnt;
  1650. response_t *pkt;
  1651. rsp->ring_ptr = rsp->ring;
  1652. rsp->ring_index = 0;
  1653. rsp->status_srb = NULL;
  1654. pkt = rsp->ring_ptr;
  1655. for (cnt = 0; cnt < rsp->length; cnt++) {
  1656. pkt->signature = RESPONSE_PROCESSED;
  1657. pkt++;
  1658. }
  1659. }
  1660. /**
  1661. * qla2x00_update_fw_options() - Read and process firmware options.
  1662. * @ha: HA context
  1663. *
  1664. * Returns 0 on success.
  1665. */
  1666. void
  1667. qla2x00_update_fw_options(scsi_qla_host_t *vha)
  1668. {
  1669. uint16_t swing, emphasis, tx_sens, rx_sens;
  1670. struct qla_hw_data *ha = vha->hw;
  1671. memset(ha->fw_options, 0, sizeof(ha->fw_options));
  1672. qla2x00_get_fw_options(vha, ha->fw_options);
  1673. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  1674. return;
  1675. /* Serial Link options. */
  1676. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
  1677. "Serial link options.\n");
  1678. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
  1679. (uint8_t *)&ha->fw_seriallink_options,
  1680. sizeof(ha->fw_seriallink_options));
  1681. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  1682. if (ha->fw_seriallink_options[3] & BIT_2) {
  1683. ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
  1684. /* 1G settings */
  1685. swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
  1686. emphasis = (ha->fw_seriallink_options[2] &
  1687. (BIT_4 | BIT_3)) >> 3;
  1688. tx_sens = ha->fw_seriallink_options[0] &
  1689. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1690. rx_sens = (ha->fw_seriallink_options[0] &
  1691. (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
  1692. ha->fw_options[10] = (emphasis << 14) | (swing << 8);
  1693. if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  1694. if (rx_sens == 0x0)
  1695. rx_sens = 0x3;
  1696. ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
  1697. } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1698. ha->fw_options[10] |= BIT_5 |
  1699. ((rx_sens & (BIT_1 | BIT_0)) << 2) |
  1700. (tx_sens & (BIT_1 | BIT_0));
  1701. /* 2G settings */
  1702. swing = (ha->fw_seriallink_options[2] &
  1703. (BIT_7 | BIT_6 | BIT_5)) >> 5;
  1704. emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
  1705. tx_sens = ha->fw_seriallink_options[1] &
  1706. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1707. rx_sens = (ha->fw_seriallink_options[1] &
  1708. (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
  1709. ha->fw_options[11] = (emphasis << 14) | (swing << 8);
  1710. if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  1711. if (rx_sens == 0x0)
  1712. rx_sens = 0x3;
  1713. ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
  1714. } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1715. ha->fw_options[11] |= BIT_5 |
  1716. ((rx_sens & (BIT_1 | BIT_0)) << 2) |
  1717. (tx_sens & (BIT_1 | BIT_0));
  1718. }
  1719. /* FCP2 options. */
  1720. /* Return command IOCBs without waiting for an ABTS to complete. */
  1721. ha->fw_options[3] |= BIT_13;
  1722. /* LED scheme. */
  1723. if (ha->flags.enable_led_scheme)
  1724. ha->fw_options[2] |= BIT_12;
  1725. /* Detect ISP6312. */
  1726. if (IS_QLA6312(ha))
  1727. ha->fw_options[2] |= BIT_13;
  1728. /* Set Retry FLOGI in case of P2P connection */
  1729. if (ha->operating_mode == P2P) {
  1730. ha->fw_options[2] |= BIT_3;
  1731. ql_dbg(ql_dbg_disc, vha, 0x2100,
  1732. "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
  1733. __func__, ha->fw_options[2]);
  1734. }
  1735. /* Update firmware options. */
  1736. qla2x00_set_fw_options(vha, ha->fw_options);
  1737. }
  1738. void
  1739. qla24xx_update_fw_options(scsi_qla_host_t *vha)
  1740. {
  1741. int rval;
  1742. struct qla_hw_data *ha = vha->hw;
  1743. if (IS_P3P_TYPE(ha))
  1744. return;
  1745. /* Hold status IOCBs until ABTS response received. */
  1746. if (ql2xfwholdabts)
  1747. ha->fw_options[3] |= BIT_12;
  1748. /* Set Retry FLOGI in case of P2P connection */
  1749. if (ha->operating_mode == P2P) {
  1750. ha->fw_options[2] |= BIT_3;
  1751. ql_dbg(ql_dbg_disc, vha, 0x2101,
  1752. "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
  1753. __func__, ha->fw_options[2]);
  1754. }
  1755. /* Update Serial Link options. */
  1756. if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
  1757. return;
  1758. rval = qla2x00_set_serdes_params(vha,
  1759. le16_to_cpu(ha->fw_seriallink_options24[1]),
  1760. le16_to_cpu(ha->fw_seriallink_options24[2]),
  1761. le16_to_cpu(ha->fw_seriallink_options24[3]));
  1762. if (rval != QLA_SUCCESS) {
  1763. ql_log(ql_log_warn, vha, 0x0104,
  1764. "Unable to update Serial Link options (%x).\n", rval);
  1765. }
  1766. }
  1767. void
  1768. qla2x00_config_rings(struct scsi_qla_host *vha)
  1769. {
  1770. struct qla_hw_data *ha = vha->hw;
  1771. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1772. struct req_que *req = ha->req_q_map[0];
  1773. struct rsp_que *rsp = ha->rsp_q_map[0];
  1774. /* Setup ring parameters in initialization control block. */
  1775. ha->init_cb->request_q_outpointer = cpu_to_le16(0);
  1776. ha->init_cb->response_q_inpointer = cpu_to_le16(0);
  1777. ha->init_cb->request_q_length = cpu_to_le16(req->length);
  1778. ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
  1779. ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
  1780. ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
  1781. ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
  1782. ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
  1783. WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
  1784. WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
  1785. WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
  1786. WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
  1787. RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
  1788. }
  1789. void
  1790. qla24xx_config_rings(struct scsi_qla_host *vha)
  1791. {
  1792. struct qla_hw_data *ha = vha->hw;
  1793. device_reg_t *reg = ISP_QUE_REG(ha, 0);
  1794. struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
  1795. struct qla_msix_entry *msix;
  1796. struct init_cb_24xx *icb;
  1797. uint16_t rid = 0;
  1798. struct req_que *req = ha->req_q_map[0];
  1799. struct rsp_que *rsp = ha->rsp_q_map[0];
  1800. /* Setup ring parameters in initialization control block. */
  1801. icb = (struct init_cb_24xx *)ha->init_cb;
  1802. icb->request_q_outpointer = cpu_to_le16(0);
  1803. icb->response_q_inpointer = cpu_to_le16(0);
  1804. icb->request_q_length = cpu_to_le16(req->length);
  1805. icb->response_q_length = cpu_to_le16(rsp->length);
  1806. icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
  1807. icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
  1808. icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
  1809. icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
  1810. /* Setup ATIO queue dma pointers for target mode */
  1811. icb->atio_q_inpointer = cpu_to_le16(0);
  1812. icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
  1813. icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
  1814. icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
  1815. if (IS_SHADOW_REG_CAPABLE(ha))
  1816. icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
  1817. if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
  1818. icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
  1819. icb->rid = cpu_to_le16(rid);
  1820. if (ha->flags.msix_enabled) {
  1821. msix = &ha->msix_entries[1];
  1822. ql_dbg(ql_dbg_init, vha, 0x00fd,
  1823. "Registering vector 0x%x for base que.\n",
  1824. msix->entry);
  1825. icb->msix = cpu_to_le16(msix->entry);
  1826. }
  1827. /* Use alternate PCI bus number */
  1828. if (MSB(rid))
  1829. icb->firmware_options_2 |= cpu_to_le32(BIT_19);
  1830. /* Use alternate PCI devfn */
  1831. if (LSB(rid))
  1832. icb->firmware_options_2 |= cpu_to_le32(BIT_18);
  1833. /* Use Disable MSIX Handshake mode for capable adapters */
  1834. if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
  1835. (ha->flags.msix_enabled)) {
  1836. icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
  1837. ha->flags.disable_msix_handshake = 1;
  1838. ql_dbg(ql_dbg_init, vha, 0x00fe,
  1839. "MSIX Handshake Disable Mode turned on.\n");
  1840. } else {
  1841. icb->firmware_options_2 |= cpu_to_le32(BIT_22);
  1842. }
  1843. icb->firmware_options_2 |= cpu_to_le32(BIT_23);
  1844. WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
  1845. WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
  1846. WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
  1847. WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
  1848. } else {
  1849. WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
  1850. WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
  1851. WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
  1852. WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
  1853. }
  1854. qlt_24xx_config_rings(vha);
  1855. /* PCI posting */
  1856. RD_REG_DWORD(&ioreg->hccr);
  1857. }
  1858. /**
  1859. * qla2x00_init_rings() - Initializes firmware.
  1860. * @ha: HA context
  1861. *
  1862. * Beginning of request ring has initialization control block already built
  1863. * by nvram config routine.
  1864. *
  1865. * Returns 0 on success.
  1866. */
  1867. int
  1868. qla2x00_init_rings(scsi_qla_host_t *vha)
  1869. {
  1870. int rval;
  1871. unsigned long flags = 0;
  1872. int cnt, que;
  1873. struct qla_hw_data *ha = vha->hw;
  1874. struct req_que *req;
  1875. struct rsp_que *rsp;
  1876. struct mid_init_cb_24xx *mid_init_cb =
  1877. (struct mid_init_cb_24xx *) ha->init_cb;
  1878. spin_lock_irqsave(&ha->hardware_lock, flags);
  1879. /* Clear outstanding commands array. */
  1880. for (que = 0; que < ha->max_req_queues; que++) {
  1881. req = ha->req_q_map[que];
  1882. if (!req || !test_bit(que, ha->req_qid_map))
  1883. continue;
  1884. req->out_ptr = (void *)(req->ring + req->length);
  1885. *req->out_ptr = 0;
  1886. for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
  1887. req->outstanding_cmds[cnt] = NULL;
  1888. req->current_outstanding_cmd = 1;
  1889. /* Initialize firmware. */
  1890. req->ring_ptr = req->ring;
  1891. req->ring_index = 0;
  1892. req->cnt = req->length;
  1893. }
  1894. for (que = 0; que < ha->max_rsp_queues; que++) {
  1895. rsp = ha->rsp_q_map[que];
  1896. if (!rsp || !test_bit(que, ha->rsp_qid_map))
  1897. continue;
  1898. rsp->in_ptr = (void *)(rsp->ring + rsp->length);
  1899. *rsp->in_ptr = 0;
  1900. /* Initialize response queue entries */
  1901. if (IS_QLAFX00(ha))
  1902. qlafx00_init_response_q_entries(rsp);
  1903. else
  1904. qla2x00_init_response_q_entries(rsp);
  1905. }
  1906. ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
  1907. ha->tgt.atio_ring_index = 0;
  1908. /* Initialize ATIO queue entries */
  1909. qlt_init_atio_q_entries(vha);
  1910. ha->isp_ops->config_rings(vha);
  1911. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1912. ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
  1913. if (IS_QLAFX00(ha)) {
  1914. rval = qlafx00_init_firmware(vha, ha->init_cb_size);
  1915. goto next_check;
  1916. }
  1917. /* Update any ISP specific firmware options before initialization. */
  1918. ha->isp_ops->update_fw_options(vha);
  1919. if (ha->flags.npiv_supported) {
  1920. if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
  1921. ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
  1922. mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
  1923. }
  1924. if (IS_FWI2_CAPABLE(ha)) {
  1925. mid_init_cb->options = cpu_to_le16(BIT_1);
  1926. mid_init_cb->init_cb.execution_throttle =
  1927. cpu_to_le16(ha->cur_fw_xcb_count);
  1928. ha->flags.dport_enabled =
  1929. (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
  1930. ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
  1931. (ha->flags.dport_enabled) ? "enabled" : "disabled");
  1932. /* FA-WWPN Status */
  1933. ha->flags.fawwpn_enabled =
  1934. (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
  1935. ql_dbg(ql_dbg_init, vha, 0x0141, "FA-WWPN Support: %s.\n",
  1936. (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
  1937. }
  1938. rval = qla2x00_init_firmware(vha, ha->init_cb_size);
  1939. next_check:
  1940. if (rval) {
  1941. ql_log(ql_log_fatal, vha, 0x00d2,
  1942. "Init Firmware **** FAILED ****.\n");
  1943. } else {
  1944. ql_dbg(ql_dbg_init, vha, 0x00d3,
  1945. "Init Firmware -- success.\n");
  1946. }
  1947. return (rval);
  1948. }
  1949. /**
  1950. * qla2x00_fw_ready() - Waits for firmware ready.
  1951. * @ha: HA context
  1952. *
  1953. * Returns 0 on success.
  1954. */
  1955. static int
  1956. qla2x00_fw_ready(scsi_qla_host_t *vha)
  1957. {
  1958. int rval;
  1959. unsigned long wtime, mtime, cs84xx_time;
  1960. uint16_t min_wait; /* Minimum wait time if loop is down */
  1961. uint16_t wait_time; /* Wait time if loop is coming ready */
  1962. uint16_t state[6];
  1963. struct qla_hw_data *ha = vha->hw;
  1964. if (IS_QLAFX00(vha->hw))
  1965. return qlafx00_fw_ready(vha);
  1966. rval = QLA_SUCCESS;
  1967. /* Time to wait for loop down */
  1968. if (IS_P3P_TYPE(ha))
  1969. min_wait = 30;
  1970. else
  1971. min_wait = 20;
  1972. /*
  1973. * Firmware should take at most one RATOV to login, plus 5 seconds for
  1974. * our own processing.
  1975. */
  1976. if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
  1977. wait_time = min_wait;
  1978. }
  1979. /* Min wait time if loop down */
  1980. mtime = jiffies + (min_wait * HZ);
  1981. /* wait time before firmware ready */
  1982. wtime = jiffies + (wait_time * HZ);
  1983. /* Wait for ISP to finish LIP */
  1984. if (!vha->flags.init_done)
  1985. ql_log(ql_log_info, vha, 0x801e,
  1986. "Waiting for LIP to complete.\n");
  1987. do {
  1988. memset(state, -1, sizeof(state));
  1989. rval = qla2x00_get_firmware_state(vha, state);
  1990. if (rval == QLA_SUCCESS) {
  1991. if (state[0] < FSTATE_LOSS_OF_SYNC) {
  1992. vha->device_flags &= ~DFLG_NO_CABLE;
  1993. }
  1994. if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
  1995. ql_dbg(ql_dbg_taskm, vha, 0x801f,
  1996. "fw_state=%x 84xx=%x.\n", state[0],
  1997. state[2]);
  1998. if ((state[2] & FSTATE_LOGGED_IN) &&
  1999. (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
  2000. ql_dbg(ql_dbg_taskm, vha, 0x8028,
  2001. "Sending verify iocb.\n");
  2002. cs84xx_time = jiffies;
  2003. rval = qla84xx_init_chip(vha);
  2004. if (rval != QLA_SUCCESS) {
  2005. ql_log(ql_log_warn,
  2006. vha, 0x8007,
  2007. "Init chip failed.\n");
  2008. break;
  2009. }
  2010. /* Add time taken to initialize. */
  2011. cs84xx_time = jiffies - cs84xx_time;
  2012. wtime += cs84xx_time;
  2013. mtime += cs84xx_time;
  2014. ql_dbg(ql_dbg_taskm, vha, 0x8008,
  2015. "Increasing wait time by %ld. "
  2016. "New time %ld.\n", cs84xx_time,
  2017. wtime);
  2018. }
  2019. } else if (state[0] == FSTATE_READY) {
  2020. ql_dbg(ql_dbg_taskm, vha, 0x8037,
  2021. "F/W Ready - OK.\n");
  2022. qla2x00_get_retry_cnt(vha, &ha->retry_count,
  2023. &ha->login_timeout, &ha->r_a_tov);
  2024. rval = QLA_SUCCESS;
  2025. break;
  2026. }
  2027. rval = QLA_FUNCTION_FAILED;
  2028. if (atomic_read(&vha->loop_down_timer) &&
  2029. state[0] != FSTATE_READY) {
  2030. /* Loop down. Timeout on min_wait for states
  2031. * other than Wait for Login.
  2032. */
  2033. if (time_after_eq(jiffies, mtime)) {
  2034. ql_log(ql_log_info, vha, 0x8038,
  2035. "Cable is unplugged...\n");
  2036. vha->device_flags |= DFLG_NO_CABLE;
  2037. break;
  2038. }
  2039. }
  2040. } else {
  2041. /* Mailbox cmd failed. Timeout on min_wait. */
  2042. if (time_after_eq(jiffies, mtime) ||
  2043. ha->flags.isp82xx_fw_hung)
  2044. break;
  2045. }
  2046. if (time_after_eq(jiffies, wtime))
  2047. break;
  2048. /* Delay for a while */
  2049. msleep(500);
  2050. } while (1);
  2051. ql_dbg(ql_dbg_taskm, vha, 0x803a,
  2052. "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
  2053. state[1], state[2], state[3], state[4], state[5], jiffies);
  2054. if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
  2055. ql_log(ql_log_warn, vha, 0x803b,
  2056. "Firmware ready **** FAILED ****.\n");
  2057. }
  2058. return (rval);
  2059. }
  2060. /*
  2061. * qla2x00_configure_hba
  2062. * Setup adapter context.
  2063. *
  2064. * Input:
  2065. * ha = adapter state pointer.
  2066. *
  2067. * Returns:
  2068. * 0 = success
  2069. *
  2070. * Context:
  2071. * Kernel context.
  2072. */
  2073. static int
  2074. qla2x00_configure_hba(scsi_qla_host_t *vha)
  2075. {
  2076. int rval;
  2077. uint16_t loop_id;
  2078. uint16_t topo;
  2079. uint16_t sw_cap;
  2080. uint8_t al_pa;
  2081. uint8_t area;
  2082. uint8_t domain;
  2083. char connect_type[22];
  2084. struct qla_hw_data *ha = vha->hw;
  2085. unsigned long flags;
  2086. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  2087. /* Get host addresses. */
  2088. rval = qla2x00_get_adapter_id(vha,
  2089. &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
  2090. if (rval != QLA_SUCCESS) {
  2091. if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
  2092. IS_CNA_CAPABLE(ha) ||
  2093. (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
  2094. ql_dbg(ql_dbg_disc, vha, 0x2008,
  2095. "Loop is in a transition state.\n");
  2096. } else {
  2097. ql_log(ql_log_warn, vha, 0x2009,
  2098. "Unable to get host loop ID.\n");
  2099. if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
  2100. (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
  2101. ql_log(ql_log_warn, vha, 0x1151,
  2102. "Doing link init.\n");
  2103. if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
  2104. return rval;
  2105. }
  2106. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  2107. }
  2108. return (rval);
  2109. }
  2110. if (topo == 4) {
  2111. ql_log(ql_log_info, vha, 0x200a,
  2112. "Cannot get topology - retrying.\n");
  2113. return (QLA_FUNCTION_FAILED);
  2114. }
  2115. vha->loop_id = loop_id;
  2116. /* initialize */
  2117. ha->min_external_loopid = SNS_FIRST_LOOP_ID;
  2118. ha->operating_mode = LOOP;
  2119. ha->switch_cap = 0;
  2120. switch (topo) {
  2121. case 0:
  2122. ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
  2123. ha->current_topology = ISP_CFG_NL;
  2124. strcpy(connect_type, "(Loop)");
  2125. break;
  2126. case 1:
  2127. ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
  2128. ha->switch_cap = sw_cap;
  2129. ha->current_topology = ISP_CFG_FL;
  2130. strcpy(connect_type, "(FL_Port)");
  2131. break;
  2132. case 2:
  2133. ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
  2134. ha->operating_mode = P2P;
  2135. ha->current_topology = ISP_CFG_N;
  2136. strcpy(connect_type, "(N_Port-to-N_Port)");
  2137. break;
  2138. case 3:
  2139. ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
  2140. ha->switch_cap = sw_cap;
  2141. ha->operating_mode = P2P;
  2142. ha->current_topology = ISP_CFG_F;
  2143. strcpy(connect_type, "(F_Port)");
  2144. break;
  2145. default:
  2146. ql_dbg(ql_dbg_disc, vha, 0x200f,
  2147. "HBA in unknown topology %x, using NL.\n", topo);
  2148. ha->current_topology = ISP_CFG_NL;
  2149. strcpy(connect_type, "(Loop)");
  2150. break;
  2151. }
  2152. /* Save Host port and loop ID. */
  2153. /* byte order - Big Endian */
  2154. vha->d_id.b.domain = domain;
  2155. vha->d_id.b.area = area;
  2156. vha->d_id.b.al_pa = al_pa;
  2157. spin_lock_irqsave(&ha->vport_slock, flags);
  2158. qlt_update_vp_map(vha, SET_AL_PA);
  2159. spin_unlock_irqrestore(&ha->vport_slock, flags);
  2160. if (!vha->flags.init_done)
  2161. ql_log(ql_log_info, vha, 0x2010,
  2162. "Topology - %s, Host Loop address 0x%x.\n",
  2163. connect_type, vha->loop_id);
  2164. return(rval);
  2165. }
  2166. inline void
  2167. qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
  2168. char *def)
  2169. {
  2170. char *st, *en;
  2171. uint16_t index;
  2172. struct qla_hw_data *ha = vha->hw;
  2173. int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
  2174. !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
  2175. if (memcmp(model, BINZERO, len) != 0) {
  2176. strncpy(ha->model_number, model, len);
  2177. st = en = ha->model_number;
  2178. en += len - 1;
  2179. while (en > st) {
  2180. if (*en != 0x20 && *en != 0x00)
  2181. break;
  2182. *en-- = '\0';
  2183. }
  2184. index = (ha->pdev->subsystem_device & 0xff);
  2185. if (use_tbl &&
  2186. ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
  2187. index < QLA_MODEL_NAMES)
  2188. strncpy(ha->model_desc,
  2189. qla2x00_model_name[index * 2 + 1],
  2190. sizeof(ha->model_desc) - 1);
  2191. } else {
  2192. index = (ha->pdev->subsystem_device & 0xff);
  2193. if (use_tbl &&
  2194. ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
  2195. index < QLA_MODEL_NAMES) {
  2196. strcpy(ha->model_number,
  2197. qla2x00_model_name[index * 2]);
  2198. strncpy(ha->model_desc,
  2199. qla2x00_model_name[index * 2 + 1],
  2200. sizeof(ha->model_desc) - 1);
  2201. } else {
  2202. strcpy(ha->model_number, def);
  2203. }
  2204. }
  2205. if (IS_FWI2_CAPABLE(ha))
  2206. qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
  2207. sizeof(ha->model_desc));
  2208. }
  2209. /* On sparc systems, obtain port and node WWN from firmware
  2210. * properties.
  2211. */
  2212. static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
  2213. {
  2214. #ifdef CONFIG_SPARC
  2215. struct qla_hw_data *ha = vha->hw;
  2216. struct pci_dev *pdev = ha->pdev;
  2217. struct device_node *dp = pci_device_to_OF_node(pdev);
  2218. const u8 *val;
  2219. int len;
  2220. val = of_get_property(dp, "port-wwn", &len);
  2221. if (val && len >= WWN_SIZE)
  2222. memcpy(nv->port_name, val, WWN_SIZE);
  2223. val = of_get_property(dp, "node-wwn", &len);
  2224. if (val && len >= WWN_SIZE)
  2225. memcpy(nv->node_name, val, WWN_SIZE);
  2226. #endif
  2227. }
  2228. /*
  2229. * NVRAM configuration for ISP 2xxx
  2230. *
  2231. * Input:
  2232. * ha = adapter block pointer.
  2233. *
  2234. * Output:
  2235. * initialization control block in response_ring
  2236. * host adapters parameters in host adapter block
  2237. *
  2238. * Returns:
  2239. * 0 = success.
  2240. */
  2241. int
  2242. qla2x00_nvram_config(scsi_qla_host_t *vha)
  2243. {
  2244. int rval;
  2245. uint8_t chksum = 0;
  2246. uint16_t cnt;
  2247. uint8_t *dptr1, *dptr2;
  2248. struct qla_hw_data *ha = vha->hw;
  2249. init_cb_t *icb = ha->init_cb;
  2250. nvram_t *nv = ha->nvram;
  2251. uint8_t *ptr = ha->nvram;
  2252. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2253. rval = QLA_SUCCESS;
  2254. /* Determine NVRAM starting address. */
  2255. ha->nvram_size = sizeof(nvram_t);
  2256. ha->nvram_base = 0;
  2257. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
  2258. if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
  2259. ha->nvram_base = 0x80;
  2260. /* Get NVRAM data and calculate checksum. */
  2261. ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
  2262. for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
  2263. chksum += *ptr++;
  2264. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
  2265. "Contents of NVRAM.\n");
  2266. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
  2267. (uint8_t *)nv, ha->nvram_size);
  2268. /* Bad NVRAM data, set defaults parameters. */
  2269. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
  2270. nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
  2271. /* Reset NVRAM data. */
  2272. ql_log(ql_log_warn, vha, 0x0064,
  2273. "Inconsistent NVRAM "
  2274. "detected: checksum=0x%x id=%c version=0x%x.\n",
  2275. chksum, nv->id[0], nv->nvram_version);
  2276. ql_log(ql_log_warn, vha, 0x0065,
  2277. "Falling back to "
  2278. "functioning (yet invalid -- WWPN) defaults.\n");
  2279. /*
  2280. * Set default initialization control block.
  2281. */
  2282. memset(nv, 0, ha->nvram_size);
  2283. nv->parameter_block_version = ICB_VERSION;
  2284. if (IS_QLA23XX(ha)) {
  2285. nv->firmware_options[0] = BIT_2 | BIT_1;
  2286. nv->firmware_options[1] = BIT_7 | BIT_5;
  2287. nv->add_firmware_options[0] = BIT_5;
  2288. nv->add_firmware_options[1] = BIT_5 | BIT_4;
  2289. nv->frame_payload_size = 2048;
  2290. nv->special_options[1] = BIT_7;
  2291. } else if (IS_QLA2200(ha)) {
  2292. nv->firmware_options[0] = BIT_2 | BIT_1;
  2293. nv->firmware_options[1] = BIT_7 | BIT_5;
  2294. nv->add_firmware_options[0] = BIT_5;
  2295. nv->add_firmware_options[1] = BIT_5 | BIT_4;
  2296. nv->frame_payload_size = 1024;
  2297. } else if (IS_QLA2100(ha)) {
  2298. nv->firmware_options[0] = BIT_3 | BIT_1;
  2299. nv->firmware_options[1] = BIT_5;
  2300. nv->frame_payload_size = 1024;
  2301. }
  2302. nv->max_iocb_allocation = cpu_to_le16(256);
  2303. nv->execution_throttle = cpu_to_le16(16);
  2304. nv->retry_count = 8;
  2305. nv->retry_delay = 1;
  2306. nv->port_name[0] = 33;
  2307. nv->port_name[3] = 224;
  2308. nv->port_name[4] = 139;
  2309. qla2xxx_nvram_wwn_from_ofw(vha, nv);
  2310. nv->login_timeout = 4;
  2311. /*
  2312. * Set default host adapter parameters
  2313. */
  2314. nv->host_p[1] = BIT_2;
  2315. nv->reset_delay = 5;
  2316. nv->port_down_retry_count = 8;
  2317. nv->max_luns_per_target = cpu_to_le16(8);
  2318. nv->link_down_timeout = 60;
  2319. rval = 1;
  2320. }
  2321. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  2322. /*
  2323. * The SN2 does not provide BIOS emulation which means you can't change
  2324. * potentially bogus BIOS settings. Force the use of default settings
  2325. * for link rate and frame size. Hope that the rest of the settings
  2326. * are valid.
  2327. */
  2328. if (ia64_platform_is("sn2")) {
  2329. nv->frame_payload_size = 2048;
  2330. if (IS_QLA23XX(ha))
  2331. nv->special_options[1] = BIT_7;
  2332. }
  2333. #endif
  2334. /* Reset Initialization control block */
  2335. memset(icb, 0, ha->init_cb_size);
  2336. /*
  2337. * Setup driver NVRAM options.
  2338. */
  2339. nv->firmware_options[0] |= (BIT_6 | BIT_1);
  2340. nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
  2341. nv->firmware_options[1] |= (BIT_5 | BIT_0);
  2342. nv->firmware_options[1] &= ~BIT_4;
  2343. if (IS_QLA23XX(ha)) {
  2344. nv->firmware_options[0] |= BIT_2;
  2345. nv->firmware_options[0] &= ~BIT_3;
  2346. nv->special_options[0] &= ~BIT_6;
  2347. nv->add_firmware_options[1] |= BIT_5 | BIT_4;
  2348. if (IS_QLA2300(ha)) {
  2349. if (ha->fb_rev == FPM_2310) {
  2350. strcpy(ha->model_number, "QLA2310");
  2351. } else {
  2352. strcpy(ha->model_number, "QLA2300");
  2353. }
  2354. } else {
  2355. qla2x00_set_model_info(vha, nv->model_number,
  2356. sizeof(nv->model_number), "QLA23xx");
  2357. }
  2358. } else if (IS_QLA2200(ha)) {
  2359. nv->firmware_options[0] |= BIT_2;
  2360. /*
  2361. * 'Point-to-point preferred, else loop' is not a safe
  2362. * connection mode setting.
  2363. */
  2364. if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
  2365. (BIT_5 | BIT_4)) {
  2366. /* Force 'loop preferred, else point-to-point'. */
  2367. nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
  2368. nv->add_firmware_options[0] |= BIT_5;
  2369. }
  2370. strcpy(ha->model_number, "QLA22xx");
  2371. } else /*if (IS_QLA2100(ha))*/ {
  2372. strcpy(ha->model_number, "QLA2100");
  2373. }
  2374. /*
  2375. * Copy over NVRAM RISC parameter block to initialization control block.
  2376. */
  2377. dptr1 = (uint8_t *)icb;
  2378. dptr2 = (uint8_t *)&nv->parameter_block_version;
  2379. cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
  2380. while (cnt--)
  2381. *dptr1++ = *dptr2++;
  2382. /* Copy 2nd half. */
  2383. dptr1 = (uint8_t *)icb->add_firmware_options;
  2384. cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
  2385. while (cnt--)
  2386. *dptr1++ = *dptr2++;
  2387. /* Use alternate WWN? */
  2388. if (nv->host_p[1] & BIT_7) {
  2389. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  2390. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  2391. }
  2392. /* Prepare nodename */
  2393. if ((icb->firmware_options[1] & BIT_6) == 0) {
  2394. /*
  2395. * Firmware will apply the following mask if the nodename was
  2396. * not provided.
  2397. */
  2398. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  2399. icb->node_name[0] &= 0xF0;
  2400. }
  2401. /*
  2402. * Set host adapter parameters.
  2403. */
  2404. /*
  2405. * BIT_7 in the host-parameters section allows for modification to
  2406. * internal driver logging.
  2407. */
  2408. if (nv->host_p[0] & BIT_7)
  2409. ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
  2410. ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
  2411. /* Always load RISC code on non ISP2[12]00 chips. */
  2412. if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
  2413. ha->flags.disable_risc_code_load = 0;
  2414. ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
  2415. ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
  2416. ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
  2417. ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
  2418. ha->flags.disable_serdes = 0;
  2419. ha->operating_mode =
  2420. (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
  2421. memcpy(ha->fw_seriallink_options, nv->seriallink_options,
  2422. sizeof(ha->fw_seriallink_options));
  2423. /* save HBA serial number */
  2424. ha->serial0 = icb->port_name[5];
  2425. ha->serial1 = icb->port_name[6];
  2426. ha->serial2 = icb->port_name[7];
  2427. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  2428. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  2429. icb->execution_throttle = cpu_to_le16(0xFFFF);
  2430. ha->retry_count = nv->retry_count;
  2431. /* Set minimum login_timeout to 4 seconds. */
  2432. if (nv->login_timeout != ql2xlogintimeout)
  2433. nv->login_timeout = ql2xlogintimeout;
  2434. if (nv->login_timeout < 4)
  2435. nv->login_timeout = 4;
  2436. ha->login_timeout = nv->login_timeout;
  2437. /* Set minimum RATOV to 100 tenths of a second. */
  2438. ha->r_a_tov = 100;
  2439. ha->loop_reset_delay = nv->reset_delay;
  2440. /* Link Down Timeout = 0:
  2441. *
  2442. * When Port Down timer expires we will start returning
  2443. * I/O's to OS with "DID_NO_CONNECT".
  2444. *
  2445. * Link Down Timeout != 0:
  2446. *
  2447. * The driver waits for the link to come up after link down
  2448. * before returning I/Os to OS with "DID_NO_CONNECT".
  2449. */
  2450. if (nv->link_down_timeout == 0) {
  2451. ha->loop_down_abort_time =
  2452. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  2453. } else {
  2454. ha->link_down_timeout = nv->link_down_timeout;
  2455. ha->loop_down_abort_time =
  2456. (LOOP_DOWN_TIME - ha->link_down_timeout);
  2457. }
  2458. /*
  2459. * Need enough time to try and get the port back.
  2460. */
  2461. ha->port_down_retry_count = nv->port_down_retry_count;
  2462. if (qlport_down_retry)
  2463. ha->port_down_retry_count = qlport_down_retry;
  2464. /* Set login_retry_count */
  2465. ha->login_retry_count = nv->retry_count;
  2466. if (ha->port_down_retry_count == nv->port_down_retry_count &&
  2467. ha->port_down_retry_count > 3)
  2468. ha->login_retry_count = ha->port_down_retry_count;
  2469. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  2470. ha->login_retry_count = ha->port_down_retry_count;
  2471. if (ql2xloginretrycount)
  2472. ha->login_retry_count = ql2xloginretrycount;
  2473. icb->lun_enables = cpu_to_le16(0);
  2474. icb->command_resource_count = 0;
  2475. icb->immediate_notify_resource_count = 0;
  2476. icb->timeout = cpu_to_le16(0);
  2477. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  2478. /* Enable RIO */
  2479. icb->firmware_options[0] &= ~BIT_3;
  2480. icb->add_firmware_options[0] &=
  2481. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
  2482. icb->add_firmware_options[0] |= BIT_2;
  2483. icb->response_accumulation_timer = 3;
  2484. icb->interrupt_delay_timer = 5;
  2485. vha->flags.process_response_queue = 1;
  2486. } else {
  2487. /* Enable ZIO. */
  2488. if (!vha->flags.init_done) {
  2489. ha->zio_mode = icb->add_firmware_options[0] &
  2490. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  2491. ha->zio_timer = icb->interrupt_delay_timer ?
  2492. icb->interrupt_delay_timer: 2;
  2493. }
  2494. icb->add_firmware_options[0] &=
  2495. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
  2496. vha->flags.process_response_queue = 0;
  2497. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  2498. ha->zio_mode = QLA_ZIO_MODE_6;
  2499. ql_log(ql_log_info, vha, 0x0068,
  2500. "ZIO mode %d enabled; timer delay (%d us).\n",
  2501. ha->zio_mode, ha->zio_timer * 100);
  2502. icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
  2503. icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
  2504. vha->flags.process_response_queue = 1;
  2505. }
  2506. }
  2507. if (rval) {
  2508. ql_log(ql_log_warn, vha, 0x0069,
  2509. "NVRAM configuration failed.\n");
  2510. }
  2511. return (rval);
  2512. }
  2513. static void
  2514. qla2x00_rport_del(void *data)
  2515. {
  2516. fc_port_t *fcport = data;
  2517. struct fc_rport *rport;
  2518. unsigned long flags;
  2519. spin_lock_irqsave(fcport->vha->host->host_lock, flags);
  2520. rport = fcport->drport ? fcport->drport: fcport->rport;
  2521. fcport->drport = NULL;
  2522. spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
  2523. if (rport)
  2524. fc_remote_port_delete(rport);
  2525. }
  2526. /**
  2527. * qla2x00_alloc_fcport() - Allocate a generic fcport.
  2528. * @ha: HA context
  2529. * @flags: allocation flags
  2530. *
  2531. * Returns a pointer to the allocated fcport, or NULL, if none available.
  2532. */
  2533. fc_port_t *
  2534. qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
  2535. {
  2536. fc_port_t *fcport;
  2537. fcport = kzalloc(sizeof(fc_port_t), flags);
  2538. if (!fcport)
  2539. return NULL;
  2540. /* Setup fcport template structure. */
  2541. fcport->vha = vha;
  2542. fcport->port_type = FCT_UNKNOWN;
  2543. fcport->loop_id = FC_NO_LOOP_ID;
  2544. qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
  2545. fcport->supported_classes = FC_COS_UNSPECIFIED;
  2546. return fcport;
  2547. }
  2548. /*
  2549. * qla2x00_configure_loop
  2550. * Updates Fibre Channel Device Database with what is actually on loop.
  2551. *
  2552. * Input:
  2553. * ha = adapter block pointer.
  2554. *
  2555. * Returns:
  2556. * 0 = success.
  2557. * 1 = error.
  2558. * 2 = database was full and device was not configured.
  2559. */
  2560. static int
  2561. qla2x00_configure_loop(scsi_qla_host_t *vha)
  2562. {
  2563. int rval;
  2564. unsigned long flags, save_flags;
  2565. struct qla_hw_data *ha = vha->hw;
  2566. rval = QLA_SUCCESS;
  2567. /* Get Initiator ID */
  2568. if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
  2569. rval = qla2x00_configure_hba(vha);
  2570. if (rval != QLA_SUCCESS) {
  2571. ql_dbg(ql_dbg_disc, vha, 0x2013,
  2572. "Unable to configure HBA.\n");
  2573. return (rval);
  2574. }
  2575. }
  2576. save_flags = flags = vha->dpc_flags;
  2577. ql_dbg(ql_dbg_disc, vha, 0x2014,
  2578. "Configure loop -- dpc flags = 0x%lx.\n", flags);
  2579. /*
  2580. * If we have both an RSCN and PORT UPDATE pending then handle them
  2581. * both at the same time.
  2582. */
  2583. clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2584. clear_bit(RSCN_UPDATE, &vha->dpc_flags);
  2585. qla2x00_get_data_rate(vha);
  2586. /* Determine what we need to do */
  2587. if (ha->current_topology == ISP_CFG_FL &&
  2588. (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
  2589. set_bit(RSCN_UPDATE, &flags);
  2590. } else if (ha->current_topology == ISP_CFG_F &&
  2591. (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
  2592. set_bit(RSCN_UPDATE, &flags);
  2593. clear_bit(LOCAL_LOOP_UPDATE, &flags);
  2594. } else if (ha->current_topology == ISP_CFG_N) {
  2595. clear_bit(RSCN_UPDATE, &flags);
  2596. } else if (!vha->flags.online ||
  2597. (test_bit(ABORT_ISP_ACTIVE, &flags))) {
  2598. set_bit(RSCN_UPDATE, &flags);
  2599. set_bit(LOCAL_LOOP_UPDATE, &flags);
  2600. }
  2601. if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
  2602. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  2603. ql_dbg(ql_dbg_disc, vha, 0x2015,
  2604. "Loop resync needed, failing.\n");
  2605. rval = QLA_FUNCTION_FAILED;
  2606. } else
  2607. rval = qla2x00_configure_local_loop(vha);
  2608. }
  2609. if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
  2610. if (LOOP_TRANSITION(vha)) {
  2611. ql_dbg(ql_dbg_disc, vha, 0x201e,
  2612. "Needs RSCN update and loop transition.\n");
  2613. rval = QLA_FUNCTION_FAILED;
  2614. }
  2615. else
  2616. rval = qla2x00_configure_fabric(vha);
  2617. }
  2618. if (rval == QLA_SUCCESS) {
  2619. if (atomic_read(&vha->loop_down_timer) ||
  2620. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  2621. rval = QLA_FUNCTION_FAILED;
  2622. } else {
  2623. atomic_set(&vha->loop_state, LOOP_READY);
  2624. ql_dbg(ql_dbg_disc, vha, 0x2069,
  2625. "LOOP READY.\n");
  2626. /*
  2627. * Process any ATIO queue entries that came in
  2628. * while we weren't online.
  2629. */
  2630. if (qla_tgt_mode_enabled(vha)) {
  2631. if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) {
  2632. spin_lock_irqsave(&ha->tgt.atio_lock,
  2633. flags);
  2634. qlt_24xx_process_atio_queue(vha, 0);
  2635. spin_unlock_irqrestore(
  2636. &ha->tgt.atio_lock, flags);
  2637. } else {
  2638. spin_lock_irqsave(&ha->hardware_lock,
  2639. flags);
  2640. qlt_24xx_process_atio_queue(vha, 1);
  2641. spin_unlock_irqrestore(
  2642. &ha->hardware_lock, flags);
  2643. }
  2644. }
  2645. }
  2646. }
  2647. if (rval) {
  2648. ql_dbg(ql_dbg_disc, vha, 0x206a,
  2649. "%s *** FAILED ***.\n", __func__);
  2650. } else {
  2651. ql_dbg(ql_dbg_disc, vha, 0x206b,
  2652. "%s: exiting normally.\n", __func__);
  2653. }
  2654. /* Restore state if a resync event occurred during processing */
  2655. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  2656. if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
  2657. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2658. if (test_bit(RSCN_UPDATE, &save_flags)) {
  2659. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  2660. }
  2661. }
  2662. return (rval);
  2663. }
  2664. /*
  2665. * qla2x00_configure_local_loop
  2666. * Updates Fibre Channel Device Database with local loop devices.
  2667. *
  2668. * Input:
  2669. * ha = adapter block pointer.
  2670. *
  2671. * Returns:
  2672. * 0 = success.
  2673. */
  2674. static int
  2675. qla2x00_configure_local_loop(scsi_qla_host_t *vha)
  2676. {
  2677. int rval, rval2;
  2678. int found_devs;
  2679. int found;
  2680. fc_port_t *fcport, *new_fcport;
  2681. uint16_t index;
  2682. uint16_t entries;
  2683. char *id_iter;
  2684. uint16_t loop_id;
  2685. uint8_t domain, area, al_pa;
  2686. struct qla_hw_data *ha = vha->hw;
  2687. found_devs = 0;
  2688. new_fcport = NULL;
  2689. entries = MAX_FIBRE_DEVICES_LOOP;
  2690. /* Get list of logged in devices. */
  2691. memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
  2692. rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
  2693. &entries);
  2694. if (rval != QLA_SUCCESS)
  2695. goto cleanup_allocation;
  2696. ql_dbg(ql_dbg_disc, vha, 0x2017,
  2697. "Entries in ID list (%d).\n", entries);
  2698. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
  2699. (uint8_t *)ha->gid_list,
  2700. entries * sizeof(struct gid_list_info));
  2701. /* Allocate temporary fcport for any new fcports discovered. */
  2702. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  2703. if (new_fcport == NULL) {
  2704. ql_log(ql_log_warn, vha, 0x2018,
  2705. "Memory allocation failed for fcport.\n");
  2706. rval = QLA_MEMORY_ALLOC_FAILED;
  2707. goto cleanup_allocation;
  2708. }
  2709. new_fcport->flags &= ~FCF_FABRIC_DEVICE;
  2710. /*
  2711. * Mark local devices that were present with FCF_DEVICE_LOST for now.
  2712. */
  2713. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2714. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  2715. fcport->port_type != FCT_BROADCAST &&
  2716. (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  2717. ql_dbg(ql_dbg_disc, vha, 0x2019,
  2718. "Marking port lost loop_id=0x%04x.\n",
  2719. fcport->loop_id);
  2720. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2721. }
  2722. }
  2723. /* Add devices to port list. */
  2724. id_iter = (char *)ha->gid_list;
  2725. for (index = 0; index < entries; index++) {
  2726. domain = ((struct gid_list_info *)id_iter)->domain;
  2727. area = ((struct gid_list_info *)id_iter)->area;
  2728. al_pa = ((struct gid_list_info *)id_iter)->al_pa;
  2729. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  2730. loop_id = (uint16_t)
  2731. ((struct gid_list_info *)id_iter)->loop_id_2100;
  2732. else
  2733. loop_id = le16_to_cpu(
  2734. ((struct gid_list_info *)id_iter)->loop_id);
  2735. id_iter += ha->gid_list_info_size;
  2736. /* Bypass reserved domain fields. */
  2737. if ((domain & 0xf0) == 0xf0)
  2738. continue;
  2739. /* Bypass if not same domain and area of adapter. */
  2740. if (area && domain &&
  2741. (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
  2742. continue;
  2743. /* Bypass invalid local loop ID. */
  2744. if (loop_id > LAST_LOCAL_LOOP_ID)
  2745. continue;
  2746. memset(new_fcport, 0, sizeof(fc_port_t));
  2747. /* Fill in member data. */
  2748. new_fcport->d_id.b.domain = domain;
  2749. new_fcport->d_id.b.area = area;
  2750. new_fcport->d_id.b.al_pa = al_pa;
  2751. new_fcport->loop_id = loop_id;
  2752. rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
  2753. if (rval2 != QLA_SUCCESS) {
  2754. ql_dbg(ql_dbg_disc, vha, 0x201a,
  2755. "Failed to retrieve fcport information "
  2756. "-- get_port_database=%x, loop_id=0x%04x.\n",
  2757. rval2, new_fcport->loop_id);
  2758. ql_dbg(ql_dbg_disc, vha, 0x201b,
  2759. "Scheduling resync.\n");
  2760. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2761. continue;
  2762. }
  2763. /* Check for matching device in port list. */
  2764. found = 0;
  2765. fcport = NULL;
  2766. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2767. if (memcmp(new_fcport->port_name, fcport->port_name,
  2768. WWN_SIZE))
  2769. continue;
  2770. fcport->flags &= ~FCF_FABRIC_DEVICE;
  2771. fcport->loop_id = new_fcport->loop_id;
  2772. fcport->port_type = new_fcport->port_type;
  2773. fcport->d_id.b24 = new_fcport->d_id.b24;
  2774. memcpy(fcport->node_name, new_fcport->node_name,
  2775. WWN_SIZE);
  2776. found++;
  2777. break;
  2778. }
  2779. if (!found) {
  2780. /* New device, add to fcports list. */
  2781. list_add_tail(&new_fcport->list, &vha->vp_fcports);
  2782. /* Allocate a new replacement fcport. */
  2783. fcport = new_fcport;
  2784. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  2785. if (new_fcport == NULL) {
  2786. ql_log(ql_log_warn, vha, 0x201c,
  2787. "Failed to allocate memory for fcport.\n");
  2788. rval = QLA_MEMORY_ALLOC_FAILED;
  2789. goto cleanup_allocation;
  2790. }
  2791. new_fcport->flags &= ~FCF_FABRIC_DEVICE;
  2792. }
  2793. /* Base iIDMA settings on HBA port speed. */
  2794. fcport->fp_speed = ha->link_data_rate;
  2795. qla2x00_update_fcport(vha, fcport);
  2796. found_devs++;
  2797. }
  2798. cleanup_allocation:
  2799. kfree(new_fcport);
  2800. if (rval != QLA_SUCCESS) {
  2801. ql_dbg(ql_dbg_disc, vha, 0x201d,
  2802. "Configure local loop error exit: rval=%x.\n", rval);
  2803. }
  2804. return (rval);
  2805. }
  2806. static void
  2807. qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
  2808. {
  2809. int rval;
  2810. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2811. struct qla_hw_data *ha = vha->hw;
  2812. if (!IS_IIDMA_CAPABLE(ha))
  2813. return;
  2814. if (atomic_read(&fcport->state) != FCS_ONLINE)
  2815. return;
  2816. if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
  2817. fcport->fp_speed > ha->link_data_rate)
  2818. return;
  2819. rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
  2820. mb);
  2821. if (rval != QLA_SUCCESS) {
  2822. ql_dbg(ql_dbg_disc, vha, 0x2004,
  2823. "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
  2824. fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
  2825. } else {
  2826. ql_dbg(ql_dbg_disc, vha, 0x2005,
  2827. "iIDMA adjusted to %s GB/s on %8phN.\n",
  2828. qla2x00_get_link_speed_str(ha, fcport->fp_speed),
  2829. fcport->port_name);
  2830. }
  2831. }
  2832. static void
  2833. qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
  2834. {
  2835. struct fc_rport_identifiers rport_ids;
  2836. struct fc_rport *rport;
  2837. unsigned long flags;
  2838. rport_ids.node_name = wwn_to_u64(fcport->node_name);
  2839. rport_ids.port_name = wwn_to_u64(fcport->port_name);
  2840. rport_ids.port_id = fcport->d_id.b.domain << 16 |
  2841. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  2842. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  2843. fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
  2844. if (!rport) {
  2845. ql_log(ql_log_warn, vha, 0x2006,
  2846. "Unable to allocate fc remote port.\n");
  2847. return;
  2848. }
  2849. /*
  2850. * Create target mode FC NEXUS in qla_target.c if target mode is
  2851. * enabled..
  2852. */
  2853. qlt_fc_port_added(vha, fcport);
  2854. spin_lock_irqsave(fcport->vha->host->host_lock, flags);
  2855. *((fc_port_t **)rport->dd_data) = fcport;
  2856. spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
  2857. rport->supported_classes = fcport->supported_classes;
  2858. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  2859. if (fcport->port_type == FCT_INITIATOR)
  2860. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  2861. if (fcport->port_type == FCT_TARGET)
  2862. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  2863. fc_remote_port_rolechg(rport, rport_ids.roles);
  2864. }
  2865. /*
  2866. * qla2x00_update_fcport
  2867. * Updates device on list.
  2868. *
  2869. * Input:
  2870. * ha = adapter block pointer.
  2871. * fcport = port structure pointer.
  2872. *
  2873. * Return:
  2874. * 0 - Success
  2875. * BIT_0 - error
  2876. *
  2877. * Context:
  2878. * Kernel context.
  2879. */
  2880. void
  2881. qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
  2882. {
  2883. fcport->vha = vha;
  2884. if (IS_QLAFX00(vha->hw)) {
  2885. qla2x00_set_fcport_state(fcport, FCS_ONLINE);
  2886. goto reg_port;
  2887. }
  2888. fcport->login_retry = 0;
  2889. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  2890. qla2x00_set_fcport_state(fcport, FCS_ONLINE);
  2891. qla2x00_iidma_fcport(vha, fcport);
  2892. qla24xx_update_fcport_fcp_prio(vha, fcport);
  2893. reg_port:
  2894. if (qla_ini_mode_enabled(vha))
  2895. qla2x00_reg_remote_port(vha, fcport);
  2896. else {
  2897. /*
  2898. * Create target mode FC NEXUS in qla_target.c
  2899. */
  2900. qlt_fc_port_added(vha, fcport);
  2901. }
  2902. }
  2903. /*
  2904. * qla2x00_configure_fabric
  2905. * Setup SNS devices with loop ID's.
  2906. *
  2907. * Input:
  2908. * ha = adapter block pointer.
  2909. *
  2910. * Returns:
  2911. * 0 = success.
  2912. * BIT_0 = error
  2913. */
  2914. static int
  2915. qla2x00_configure_fabric(scsi_qla_host_t *vha)
  2916. {
  2917. int rval;
  2918. fc_port_t *fcport, *fcptemp;
  2919. uint16_t next_loopid;
  2920. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2921. uint16_t loop_id;
  2922. LIST_HEAD(new_fcports);
  2923. struct qla_hw_data *ha = vha->hw;
  2924. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  2925. int discovery_gen;
  2926. /* If FL port exists, then SNS is present */
  2927. if (IS_FWI2_CAPABLE(ha))
  2928. loop_id = NPH_F_PORT;
  2929. else
  2930. loop_id = SNS_FL_PORT;
  2931. rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
  2932. if (rval != QLA_SUCCESS) {
  2933. ql_dbg(ql_dbg_disc, vha, 0x201f,
  2934. "MBX_GET_PORT_NAME failed, No FL Port.\n");
  2935. vha->device_flags &= ~SWITCH_FOUND;
  2936. return (QLA_SUCCESS);
  2937. }
  2938. vha->device_flags |= SWITCH_FOUND;
  2939. do {
  2940. /* FDMI support. */
  2941. if (ql2xfdmienable &&
  2942. test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
  2943. qla2x00_fdmi_register(vha);
  2944. /* Ensure we are logged into the SNS. */
  2945. if (IS_FWI2_CAPABLE(ha))
  2946. loop_id = NPH_SNS;
  2947. else
  2948. loop_id = SIMPLE_NAME_SERVER;
  2949. rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
  2950. 0xfc, mb, BIT_1|BIT_0);
  2951. if (rval != QLA_SUCCESS) {
  2952. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2953. return rval;
  2954. }
  2955. if (mb[0] != MBS_COMMAND_COMPLETE) {
  2956. ql_dbg(ql_dbg_disc, vha, 0x2042,
  2957. "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
  2958. "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
  2959. mb[2], mb[6], mb[7]);
  2960. return (QLA_SUCCESS);
  2961. }
  2962. if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
  2963. if (qla2x00_rft_id(vha)) {
  2964. /* EMPTY */
  2965. ql_dbg(ql_dbg_disc, vha, 0x2045,
  2966. "Register FC-4 TYPE failed.\n");
  2967. }
  2968. if (qla2x00_rff_id(vha)) {
  2969. /* EMPTY */
  2970. ql_dbg(ql_dbg_disc, vha, 0x2049,
  2971. "Register FC-4 Features failed.\n");
  2972. }
  2973. if (qla2x00_rnn_id(vha)) {
  2974. /* EMPTY */
  2975. ql_dbg(ql_dbg_disc, vha, 0x204f,
  2976. "Register Node Name failed.\n");
  2977. } else if (qla2x00_rsnn_nn(vha)) {
  2978. /* EMPTY */
  2979. ql_dbg(ql_dbg_disc, vha, 0x2053,
  2980. "Register Symobilic Node Name failed.\n");
  2981. }
  2982. }
  2983. #define QLA_FCPORT_SCAN 1
  2984. #define QLA_FCPORT_FOUND 2
  2985. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2986. fcport->scan_state = QLA_FCPORT_SCAN;
  2987. }
  2988. /* Mark the time right before querying FW for connected ports.
  2989. * This process is long, asynchronous and by the time it's done,
  2990. * collected information might not be accurate anymore. E.g.
  2991. * disconnected port might have re-connected and a brand new
  2992. * session has been created. In this case session's generation
  2993. * will be newer than discovery_gen. */
  2994. qlt_do_generation_tick(vha, &discovery_gen);
  2995. rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
  2996. if (rval != QLA_SUCCESS)
  2997. break;
  2998. /*
  2999. * Logout all previous fabric devices marked lost, except
  3000. * FCP2 devices.
  3001. */
  3002. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3003. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  3004. break;
  3005. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
  3006. continue;
  3007. if (fcport->scan_state == QLA_FCPORT_SCAN) {
  3008. if (qla_ini_mode_enabled(base_vha) &&
  3009. atomic_read(&fcport->state) == FCS_ONLINE) {
  3010. qla2x00_mark_device_lost(vha, fcport,
  3011. ql2xplogiabsentdevice, 0);
  3012. if (fcport->loop_id != FC_NO_LOOP_ID &&
  3013. (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
  3014. fcport->port_type != FCT_INITIATOR &&
  3015. fcport->port_type != FCT_BROADCAST) {
  3016. ha->isp_ops->fabric_logout(vha,
  3017. fcport->loop_id,
  3018. fcport->d_id.b.domain,
  3019. fcport->d_id.b.area,
  3020. fcport->d_id.b.al_pa);
  3021. qla2x00_clear_loop_id(fcport);
  3022. }
  3023. } else if (!qla_ini_mode_enabled(base_vha)) {
  3024. /*
  3025. * In target mode, explicitly kill
  3026. * sessions and log out of devices
  3027. * that are gone, so that we don't
  3028. * end up with an initiator using the
  3029. * wrong ACL (if the fabric recycles
  3030. * an FC address and we have a stale
  3031. * session around) and so that we don't
  3032. * report initiators that are no longer
  3033. * on the fabric.
  3034. */
  3035. ql_dbg(ql_dbg_tgt_mgt, vha, 0xf077,
  3036. "port gone, logging out/killing session: "
  3037. "%8phC state 0x%x flags 0x%x fc4_type 0x%x "
  3038. "scan_state %d\n",
  3039. fcport->port_name,
  3040. atomic_read(&fcport->state),
  3041. fcport->flags, fcport->fc4_type,
  3042. fcport->scan_state);
  3043. qlt_fc_port_deleted(vha, fcport,
  3044. discovery_gen);
  3045. }
  3046. }
  3047. }
  3048. /* Starting free loop ID. */
  3049. next_loopid = ha->min_external_loopid;
  3050. /*
  3051. * Scan through our port list and login entries that need to be
  3052. * logged in.
  3053. */
  3054. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3055. if (atomic_read(&vha->loop_down_timer) ||
  3056. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  3057. break;
  3058. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
  3059. (fcport->flags & FCF_LOGIN_NEEDED) == 0)
  3060. continue;
  3061. /*
  3062. * If we're not an initiator, skip looking for devices
  3063. * and logging in. There's no reason for us to do it,
  3064. * and it seems to actively cause problems in target
  3065. * mode if we race with the initiator logging into us
  3066. * (we might get the "port ID used" status back from
  3067. * our login command and log out the initiator, which
  3068. * seems to cause havoc).
  3069. */
  3070. if (!qla_ini_mode_enabled(base_vha)) {
  3071. if (fcport->scan_state == QLA_FCPORT_FOUND) {
  3072. ql_dbg(ql_dbg_tgt_mgt, vha, 0xf078,
  3073. "port %8phC state 0x%x flags 0x%x fc4_type 0x%x "
  3074. "scan_state %d (initiator mode disabled; skipping "
  3075. "login)\n", fcport->port_name,
  3076. atomic_read(&fcport->state),
  3077. fcport->flags, fcport->fc4_type,
  3078. fcport->scan_state);
  3079. }
  3080. continue;
  3081. }
  3082. if (fcport->loop_id == FC_NO_LOOP_ID) {
  3083. fcport->loop_id = next_loopid;
  3084. rval = qla2x00_find_new_loop_id(
  3085. base_vha, fcport);
  3086. if (rval != QLA_SUCCESS) {
  3087. /* Ran out of IDs to use */
  3088. break;
  3089. }
  3090. }
  3091. /* Login and update database */
  3092. qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
  3093. }
  3094. /* Exit if out of loop IDs. */
  3095. if (rval != QLA_SUCCESS) {
  3096. break;
  3097. }
  3098. /*
  3099. * Login and add the new devices to our port list.
  3100. */
  3101. list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
  3102. if (atomic_read(&vha->loop_down_timer) ||
  3103. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  3104. break;
  3105. /*
  3106. * If we're not an initiator, skip looking for devices
  3107. * and logging in. There's no reason for us to do it,
  3108. * and it seems to actively cause problems in target
  3109. * mode if we race with the initiator logging into us
  3110. * (we might get the "port ID used" status back from
  3111. * our login command and log out the initiator, which
  3112. * seems to cause havoc).
  3113. */
  3114. if (qla_ini_mode_enabled(base_vha)) {
  3115. /* Find a new loop ID to use. */
  3116. fcport->loop_id = next_loopid;
  3117. rval = qla2x00_find_new_loop_id(base_vha,
  3118. fcport);
  3119. if (rval != QLA_SUCCESS) {
  3120. /* Ran out of IDs to use */
  3121. break;
  3122. }
  3123. /* Login and update database */
  3124. qla2x00_fabric_dev_login(vha, fcport,
  3125. &next_loopid);
  3126. } else {
  3127. ql_dbg(ql_dbg_tgt_mgt, vha, 0xf079,
  3128. "new port %8phC state 0x%x flags 0x%x fc4_type "
  3129. "0x%x scan_state %d (initiator mode disabled; "
  3130. "skipping login)\n",
  3131. fcport->port_name,
  3132. atomic_read(&fcport->state),
  3133. fcport->flags, fcport->fc4_type,
  3134. fcport->scan_state);
  3135. }
  3136. list_move_tail(&fcport->list, &vha->vp_fcports);
  3137. }
  3138. } while (0);
  3139. /* Free all new device structures not processed. */
  3140. list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
  3141. list_del(&fcport->list);
  3142. kfree(fcport);
  3143. }
  3144. if (rval) {
  3145. ql_dbg(ql_dbg_disc, vha, 0x2068,
  3146. "Configure fabric error exit rval=%d.\n", rval);
  3147. }
  3148. return (rval);
  3149. }
  3150. /*
  3151. * qla2x00_find_all_fabric_devs
  3152. *
  3153. * Input:
  3154. * ha = adapter block pointer.
  3155. * dev = database device entry pointer.
  3156. *
  3157. * Returns:
  3158. * 0 = success.
  3159. *
  3160. * Context:
  3161. * Kernel context.
  3162. */
  3163. static int
  3164. qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
  3165. struct list_head *new_fcports)
  3166. {
  3167. int rval;
  3168. uint16_t loop_id;
  3169. fc_port_t *fcport, *new_fcport, *fcptemp;
  3170. int found;
  3171. sw_info_t *swl;
  3172. int swl_idx;
  3173. int first_dev, last_dev;
  3174. port_id_t wrap = {}, nxt_d_id;
  3175. struct qla_hw_data *ha = vha->hw;
  3176. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  3177. rval = QLA_SUCCESS;
  3178. /* Try GID_PT to get device list, else GAN. */
  3179. if (!ha->swl)
  3180. ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
  3181. GFP_KERNEL);
  3182. swl = ha->swl;
  3183. if (!swl) {
  3184. /*EMPTY*/
  3185. ql_dbg(ql_dbg_disc, vha, 0x2054,
  3186. "GID_PT allocations failed, fallback on GA_NXT.\n");
  3187. } else {
  3188. memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
  3189. if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
  3190. swl = NULL;
  3191. } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
  3192. swl = NULL;
  3193. } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
  3194. swl = NULL;
  3195. } else if (ql2xiidmaenable &&
  3196. qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
  3197. qla2x00_gpsc(vha, swl);
  3198. }
  3199. /* If other queries succeeded probe for FC-4 type */
  3200. if (swl)
  3201. qla2x00_gff_id(vha, swl);
  3202. }
  3203. swl_idx = 0;
  3204. /* Allocate temporary fcport for any new fcports discovered. */
  3205. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  3206. if (new_fcport == NULL) {
  3207. ql_log(ql_log_warn, vha, 0x205e,
  3208. "Failed to allocate memory for fcport.\n");
  3209. return (QLA_MEMORY_ALLOC_FAILED);
  3210. }
  3211. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  3212. /* Set start port ID scan at adapter ID. */
  3213. first_dev = 1;
  3214. last_dev = 0;
  3215. /* Starting free loop ID. */
  3216. loop_id = ha->min_external_loopid;
  3217. for (; loop_id <= ha->max_loop_id; loop_id++) {
  3218. if (qla2x00_is_reserved_id(vha, loop_id))
  3219. continue;
  3220. if (ha->current_topology == ISP_CFG_FL &&
  3221. (atomic_read(&vha->loop_down_timer) ||
  3222. LOOP_TRANSITION(vha))) {
  3223. atomic_set(&vha->loop_down_timer, 0);
  3224. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3225. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  3226. break;
  3227. }
  3228. if (swl != NULL) {
  3229. if (last_dev) {
  3230. wrap.b24 = new_fcport->d_id.b24;
  3231. } else {
  3232. new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
  3233. memcpy(new_fcport->node_name,
  3234. swl[swl_idx].node_name, WWN_SIZE);
  3235. memcpy(new_fcport->port_name,
  3236. swl[swl_idx].port_name, WWN_SIZE);
  3237. memcpy(new_fcport->fabric_port_name,
  3238. swl[swl_idx].fabric_port_name, WWN_SIZE);
  3239. new_fcport->fp_speed = swl[swl_idx].fp_speed;
  3240. new_fcport->fc4_type = swl[swl_idx].fc4_type;
  3241. if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
  3242. last_dev = 1;
  3243. }
  3244. swl_idx++;
  3245. }
  3246. } else {
  3247. /* Send GA_NXT to the switch */
  3248. rval = qla2x00_ga_nxt(vha, new_fcport);
  3249. if (rval != QLA_SUCCESS) {
  3250. ql_log(ql_log_warn, vha, 0x2064,
  3251. "SNS scan failed -- assuming "
  3252. "zero-entry result.\n");
  3253. list_for_each_entry_safe(fcport, fcptemp,
  3254. new_fcports, list) {
  3255. list_del(&fcport->list);
  3256. kfree(fcport);
  3257. }
  3258. rval = QLA_SUCCESS;
  3259. break;
  3260. }
  3261. }
  3262. /* If wrap on switch device list, exit. */
  3263. if (first_dev) {
  3264. wrap.b24 = new_fcport->d_id.b24;
  3265. first_dev = 0;
  3266. } else if (new_fcport->d_id.b24 == wrap.b24) {
  3267. ql_dbg(ql_dbg_disc, vha, 0x2065,
  3268. "Device wrap (%02x%02x%02x).\n",
  3269. new_fcport->d_id.b.domain,
  3270. new_fcport->d_id.b.area,
  3271. new_fcport->d_id.b.al_pa);
  3272. break;
  3273. }
  3274. /* Bypass if same physical adapter. */
  3275. if (new_fcport->d_id.b24 == base_vha->d_id.b24)
  3276. continue;
  3277. /* Bypass virtual ports of the same host. */
  3278. if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
  3279. continue;
  3280. /* Bypass if same domain and area of adapter. */
  3281. if (((new_fcport->d_id.b24 & 0xffff00) ==
  3282. (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
  3283. ISP_CFG_FL)
  3284. continue;
  3285. /* Bypass reserved domain fields. */
  3286. if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
  3287. continue;
  3288. /* Bypass ports whose FCP-4 type is not FCP_SCSI */
  3289. if (ql2xgffidenable &&
  3290. (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
  3291. new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
  3292. continue;
  3293. /* Locate matching device in database. */
  3294. found = 0;
  3295. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3296. if (memcmp(new_fcport->port_name, fcport->port_name,
  3297. WWN_SIZE))
  3298. continue;
  3299. fcport->scan_state = QLA_FCPORT_FOUND;
  3300. found++;
  3301. /* Update port state. */
  3302. memcpy(fcport->fabric_port_name,
  3303. new_fcport->fabric_port_name, WWN_SIZE);
  3304. fcport->fp_speed = new_fcport->fp_speed;
  3305. /*
  3306. * If address the same and state FCS_ONLINE
  3307. * (or in target mode), nothing changed.
  3308. */
  3309. if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
  3310. (atomic_read(&fcport->state) == FCS_ONLINE ||
  3311. !qla_ini_mode_enabled(base_vha))) {
  3312. break;
  3313. }
  3314. /*
  3315. * If device was not a fabric device before.
  3316. */
  3317. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  3318. fcport->d_id.b24 = new_fcport->d_id.b24;
  3319. qla2x00_clear_loop_id(fcport);
  3320. fcport->flags |= (FCF_FABRIC_DEVICE |
  3321. FCF_LOGIN_NEEDED);
  3322. break;
  3323. }
  3324. /*
  3325. * Port ID changed or device was marked to be updated;
  3326. * Log it out if still logged in and mark it for
  3327. * relogin later.
  3328. */
  3329. if (!qla_ini_mode_enabled(base_vha)) {
  3330. ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
  3331. "port changed FC ID, %8phC"
  3332. " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
  3333. fcport->port_name,
  3334. fcport->d_id.b.domain,
  3335. fcport->d_id.b.area,
  3336. fcport->d_id.b.al_pa,
  3337. fcport->loop_id,
  3338. new_fcport->d_id.b.domain,
  3339. new_fcport->d_id.b.area,
  3340. new_fcport->d_id.b.al_pa);
  3341. fcport->d_id.b24 = new_fcport->d_id.b24;
  3342. break;
  3343. }
  3344. fcport->d_id.b24 = new_fcport->d_id.b24;
  3345. fcport->flags |= FCF_LOGIN_NEEDED;
  3346. if (fcport->loop_id != FC_NO_LOOP_ID &&
  3347. (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
  3348. (fcport->flags & FCF_ASYNC_SENT) == 0 &&
  3349. fcport->port_type != FCT_INITIATOR &&
  3350. fcport->port_type != FCT_BROADCAST) {
  3351. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3352. fcport->d_id.b.domain, fcport->d_id.b.area,
  3353. fcport->d_id.b.al_pa);
  3354. qla2x00_clear_loop_id(fcport);
  3355. }
  3356. break;
  3357. }
  3358. if (found)
  3359. continue;
  3360. /* If device was not in our fcports list, then add it. */
  3361. new_fcport->scan_state = QLA_FCPORT_FOUND;
  3362. list_add_tail(&new_fcport->list, new_fcports);
  3363. /* Allocate a new replacement fcport. */
  3364. nxt_d_id.b24 = new_fcport->d_id.b24;
  3365. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  3366. if (new_fcport == NULL) {
  3367. ql_log(ql_log_warn, vha, 0x2066,
  3368. "Memory allocation failed for fcport.\n");
  3369. return (QLA_MEMORY_ALLOC_FAILED);
  3370. }
  3371. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  3372. new_fcport->d_id.b24 = nxt_d_id.b24;
  3373. }
  3374. kfree(new_fcport);
  3375. return (rval);
  3376. }
  3377. /*
  3378. * qla2x00_find_new_loop_id
  3379. * Scan through our port list and find a new usable loop ID.
  3380. *
  3381. * Input:
  3382. * ha: adapter state pointer.
  3383. * dev: port structure pointer.
  3384. *
  3385. * Returns:
  3386. * qla2x00 local function return status code.
  3387. *
  3388. * Context:
  3389. * Kernel context.
  3390. */
  3391. int
  3392. qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
  3393. {
  3394. int rval;
  3395. struct qla_hw_data *ha = vha->hw;
  3396. unsigned long flags = 0;
  3397. rval = QLA_SUCCESS;
  3398. spin_lock_irqsave(&ha->vport_slock, flags);
  3399. dev->loop_id = find_first_zero_bit(ha->loop_id_map,
  3400. LOOPID_MAP_SIZE);
  3401. if (dev->loop_id >= LOOPID_MAP_SIZE ||
  3402. qla2x00_is_reserved_id(vha, dev->loop_id)) {
  3403. dev->loop_id = FC_NO_LOOP_ID;
  3404. rval = QLA_FUNCTION_FAILED;
  3405. } else
  3406. set_bit(dev->loop_id, ha->loop_id_map);
  3407. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3408. if (rval == QLA_SUCCESS)
  3409. ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
  3410. "Assigning new loopid=%x, portid=%x.\n",
  3411. dev->loop_id, dev->d_id.b24);
  3412. else
  3413. ql_log(ql_log_warn, dev->vha, 0x2087,
  3414. "No loop_id's available, portid=%x.\n",
  3415. dev->d_id.b24);
  3416. return (rval);
  3417. }
  3418. /*
  3419. * qla2x00_fabric_dev_login
  3420. * Login fabric target device and update FC port database.
  3421. *
  3422. * Input:
  3423. * ha: adapter state pointer.
  3424. * fcport: port structure list pointer.
  3425. * next_loopid: contains value of a new loop ID that can be used
  3426. * by the next login attempt.
  3427. *
  3428. * Returns:
  3429. * qla2x00 local function return status code.
  3430. *
  3431. * Context:
  3432. * Kernel context.
  3433. */
  3434. static int
  3435. qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
  3436. uint16_t *next_loopid)
  3437. {
  3438. int rval;
  3439. uint8_t opts;
  3440. struct qla_hw_data *ha = vha->hw;
  3441. rval = QLA_SUCCESS;
  3442. if (IS_ALOGIO_CAPABLE(ha)) {
  3443. if (fcport->flags & FCF_ASYNC_SENT)
  3444. return rval;
  3445. fcport->flags |= FCF_ASYNC_SENT;
  3446. rval = qla2x00_post_async_login_work(vha, fcport, NULL);
  3447. if (!rval)
  3448. return rval;
  3449. }
  3450. fcport->flags &= ~FCF_ASYNC_SENT;
  3451. rval = qla2x00_fabric_login(vha, fcport, next_loopid);
  3452. if (rval == QLA_SUCCESS) {
  3453. /* Send an ADISC to FCP2 devices.*/
  3454. opts = 0;
  3455. if (fcport->flags & FCF_FCP2_DEVICE)
  3456. opts |= BIT_1;
  3457. rval = qla2x00_get_port_database(vha, fcport, opts);
  3458. if (rval != QLA_SUCCESS) {
  3459. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3460. fcport->d_id.b.domain, fcport->d_id.b.area,
  3461. fcport->d_id.b.al_pa);
  3462. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3463. } else {
  3464. qla2x00_update_fcport(vha, fcport);
  3465. }
  3466. } else {
  3467. /* Retry Login. */
  3468. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3469. }
  3470. return (rval);
  3471. }
  3472. /*
  3473. * qla2x00_fabric_login
  3474. * Issue fabric login command.
  3475. *
  3476. * Input:
  3477. * ha = adapter block pointer.
  3478. * device = pointer to FC device type structure.
  3479. *
  3480. * Returns:
  3481. * 0 - Login successfully
  3482. * 1 - Login failed
  3483. * 2 - Initiator device
  3484. * 3 - Fatal error
  3485. */
  3486. int
  3487. qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
  3488. uint16_t *next_loopid)
  3489. {
  3490. int rval;
  3491. int retry;
  3492. uint16_t tmp_loopid;
  3493. uint16_t mb[MAILBOX_REGISTER_COUNT];
  3494. struct qla_hw_data *ha = vha->hw;
  3495. retry = 0;
  3496. tmp_loopid = 0;
  3497. for (;;) {
  3498. ql_dbg(ql_dbg_disc, vha, 0x2000,
  3499. "Trying Fabric Login w/loop id 0x%04x for port "
  3500. "%02x%02x%02x.\n",
  3501. fcport->loop_id, fcport->d_id.b.domain,
  3502. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  3503. /* Login fcport on switch. */
  3504. rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
  3505. fcport->d_id.b.domain, fcport->d_id.b.area,
  3506. fcport->d_id.b.al_pa, mb, BIT_0);
  3507. if (rval != QLA_SUCCESS) {
  3508. return rval;
  3509. }
  3510. if (mb[0] == MBS_PORT_ID_USED) {
  3511. /*
  3512. * Device has another loop ID. The firmware team
  3513. * recommends the driver perform an implicit login with
  3514. * the specified ID again. The ID we just used is save
  3515. * here so we return with an ID that can be tried by
  3516. * the next login.
  3517. */
  3518. retry++;
  3519. tmp_loopid = fcport->loop_id;
  3520. fcport->loop_id = mb[1];
  3521. ql_dbg(ql_dbg_disc, vha, 0x2001,
  3522. "Fabric Login: port in use - next loop "
  3523. "id=0x%04x, port id= %02x%02x%02x.\n",
  3524. fcport->loop_id, fcport->d_id.b.domain,
  3525. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  3526. } else if (mb[0] == MBS_COMMAND_COMPLETE) {
  3527. /*
  3528. * Login succeeded.
  3529. */
  3530. if (retry) {
  3531. /* A retry occurred before. */
  3532. *next_loopid = tmp_loopid;
  3533. } else {
  3534. /*
  3535. * No retry occurred before. Just increment the
  3536. * ID value for next login.
  3537. */
  3538. *next_loopid = (fcport->loop_id + 1);
  3539. }
  3540. if (mb[1] & BIT_0) {
  3541. fcport->port_type = FCT_INITIATOR;
  3542. } else {
  3543. fcport->port_type = FCT_TARGET;
  3544. if (mb[1] & BIT_1) {
  3545. fcport->flags |= FCF_FCP2_DEVICE;
  3546. }
  3547. }
  3548. if (mb[10] & BIT_0)
  3549. fcport->supported_classes |= FC_COS_CLASS2;
  3550. if (mb[10] & BIT_1)
  3551. fcport->supported_classes |= FC_COS_CLASS3;
  3552. if (IS_FWI2_CAPABLE(ha)) {
  3553. if (mb[10] & BIT_7)
  3554. fcport->flags |=
  3555. FCF_CONF_COMP_SUPPORTED;
  3556. }
  3557. rval = QLA_SUCCESS;
  3558. break;
  3559. } else if (mb[0] == MBS_LOOP_ID_USED) {
  3560. /*
  3561. * Loop ID already used, try next loop ID.
  3562. */
  3563. fcport->loop_id++;
  3564. rval = qla2x00_find_new_loop_id(vha, fcport);
  3565. if (rval != QLA_SUCCESS) {
  3566. /* Ran out of loop IDs to use */
  3567. break;
  3568. }
  3569. } else if (mb[0] == MBS_COMMAND_ERROR) {
  3570. /*
  3571. * Firmware possibly timed out during login. If NO
  3572. * retries are left to do then the device is declared
  3573. * dead.
  3574. */
  3575. *next_loopid = fcport->loop_id;
  3576. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3577. fcport->d_id.b.domain, fcport->d_id.b.area,
  3578. fcport->d_id.b.al_pa);
  3579. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3580. rval = 1;
  3581. break;
  3582. } else {
  3583. /*
  3584. * unrecoverable / not handled error
  3585. */
  3586. ql_dbg(ql_dbg_disc, vha, 0x2002,
  3587. "Failed=%x port_id=%02x%02x%02x loop_id=%x "
  3588. "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
  3589. fcport->d_id.b.area, fcport->d_id.b.al_pa,
  3590. fcport->loop_id, jiffies);
  3591. *next_loopid = fcport->loop_id;
  3592. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3593. fcport->d_id.b.domain, fcport->d_id.b.area,
  3594. fcport->d_id.b.al_pa);
  3595. qla2x00_clear_loop_id(fcport);
  3596. fcport->login_retry = 0;
  3597. rval = 3;
  3598. break;
  3599. }
  3600. }
  3601. return (rval);
  3602. }
  3603. /*
  3604. * qla2x00_local_device_login
  3605. * Issue local device login command.
  3606. *
  3607. * Input:
  3608. * ha = adapter block pointer.
  3609. * loop_id = loop id of device to login to.
  3610. *
  3611. * Returns (Where's the #define!!!!):
  3612. * 0 - Login successfully
  3613. * 1 - Login failed
  3614. * 3 - Fatal error
  3615. */
  3616. int
  3617. qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
  3618. {
  3619. int rval;
  3620. uint16_t mb[MAILBOX_REGISTER_COUNT];
  3621. memset(mb, 0, sizeof(mb));
  3622. rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
  3623. if (rval == QLA_SUCCESS) {
  3624. /* Interrogate mailbox registers for any errors */
  3625. if (mb[0] == MBS_COMMAND_ERROR)
  3626. rval = 1;
  3627. else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
  3628. /* device not in PCB table */
  3629. rval = 3;
  3630. }
  3631. return (rval);
  3632. }
  3633. /*
  3634. * qla2x00_loop_resync
  3635. * Resync with fibre channel devices.
  3636. *
  3637. * Input:
  3638. * ha = adapter block pointer.
  3639. *
  3640. * Returns:
  3641. * 0 = success
  3642. */
  3643. int
  3644. qla2x00_loop_resync(scsi_qla_host_t *vha)
  3645. {
  3646. int rval = QLA_SUCCESS;
  3647. uint32_t wait_time;
  3648. struct req_que *req;
  3649. struct rsp_que *rsp;
  3650. if (vha->hw->flags.cpu_affinity_enabled)
  3651. req = vha->hw->req_q_map[0];
  3652. else
  3653. req = vha->req;
  3654. rsp = req->rsp;
  3655. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3656. if (vha->flags.online) {
  3657. if (!(rval = qla2x00_fw_ready(vha))) {
  3658. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  3659. wait_time = 256;
  3660. do {
  3661. if (!IS_QLAFX00(vha->hw)) {
  3662. /*
  3663. * Issue a marker after FW becomes
  3664. * ready.
  3665. */
  3666. qla2x00_marker(vha, req, rsp, 0, 0,
  3667. MK_SYNC_ALL);
  3668. vha->marker_needed = 0;
  3669. }
  3670. /* Remap devices on Loop. */
  3671. clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3672. if (IS_QLAFX00(vha->hw))
  3673. qlafx00_configure_devices(vha);
  3674. else
  3675. qla2x00_configure_loop(vha);
  3676. wait_time--;
  3677. } while (!atomic_read(&vha->loop_down_timer) &&
  3678. !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  3679. && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
  3680. &vha->dpc_flags)));
  3681. }
  3682. }
  3683. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  3684. return (QLA_FUNCTION_FAILED);
  3685. if (rval)
  3686. ql_dbg(ql_dbg_disc, vha, 0x206c,
  3687. "%s *** FAILED ***.\n", __func__);
  3688. return (rval);
  3689. }
  3690. /*
  3691. * qla2x00_perform_loop_resync
  3692. * Description: This function will set the appropriate flags and call
  3693. * qla2x00_loop_resync. If successful loop will be resynced
  3694. * Arguments : scsi_qla_host_t pointer
  3695. * returm : Success or Failure
  3696. */
  3697. int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
  3698. {
  3699. int32_t rval = 0;
  3700. if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
  3701. /*Configure the flags so that resync happens properly*/
  3702. atomic_set(&ha->loop_down_timer, 0);
  3703. if (!(ha->device_flags & DFLG_NO_CABLE)) {
  3704. atomic_set(&ha->loop_state, LOOP_UP);
  3705. set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
  3706. set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
  3707. set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
  3708. rval = qla2x00_loop_resync(ha);
  3709. } else
  3710. atomic_set(&ha->loop_state, LOOP_DEAD);
  3711. clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
  3712. }
  3713. return rval;
  3714. }
  3715. void
  3716. qla2x00_update_fcports(scsi_qla_host_t *base_vha)
  3717. {
  3718. fc_port_t *fcport;
  3719. struct scsi_qla_host *vha;
  3720. struct qla_hw_data *ha = base_vha->hw;
  3721. unsigned long flags;
  3722. spin_lock_irqsave(&ha->vport_slock, flags);
  3723. /* Go with deferred removal of rport references. */
  3724. list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
  3725. atomic_inc(&vha->vref_count);
  3726. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3727. if (fcport->drport &&
  3728. atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
  3729. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3730. qla2x00_rport_del(fcport);
  3731. /*
  3732. * Release the target mode FC NEXUS in
  3733. * qla_target.c, if target mod is enabled.
  3734. */
  3735. qlt_fc_port_deleted(vha, fcport,
  3736. base_vha->total_fcport_update_gen);
  3737. spin_lock_irqsave(&ha->vport_slock, flags);
  3738. }
  3739. }
  3740. atomic_dec(&vha->vref_count);
  3741. wake_up(&vha->vref_waitq);
  3742. }
  3743. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3744. }
  3745. /* Assumes idc_lock always held on entry */
  3746. void
  3747. qla83xx_reset_ownership(scsi_qla_host_t *vha)
  3748. {
  3749. struct qla_hw_data *ha = vha->hw;
  3750. uint32_t drv_presence, drv_presence_mask;
  3751. uint32_t dev_part_info1, dev_part_info2, class_type;
  3752. uint32_t class_type_mask = 0x3;
  3753. uint16_t fcoe_other_function = 0xffff, i;
  3754. if (IS_QLA8044(ha)) {
  3755. drv_presence = qla8044_rd_direct(vha,
  3756. QLA8044_CRB_DRV_ACTIVE_INDEX);
  3757. dev_part_info1 = qla8044_rd_direct(vha,
  3758. QLA8044_CRB_DEV_PART_INFO_INDEX);
  3759. dev_part_info2 = qla8044_rd_direct(vha,
  3760. QLA8044_CRB_DEV_PART_INFO2);
  3761. } else {
  3762. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3763. qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
  3764. qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
  3765. }
  3766. for (i = 0; i < 8; i++) {
  3767. class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
  3768. if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
  3769. (i != ha->portnum)) {
  3770. fcoe_other_function = i;
  3771. break;
  3772. }
  3773. }
  3774. if (fcoe_other_function == 0xffff) {
  3775. for (i = 0; i < 8; i++) {
  3776. class_type = ((dev_part_info2 >> (i * 4)) &
  3777. class_type_mask);
  3778. if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
  3779. ((i + 8) != ha->portnum)) {
  3780. fcoe_other_function = i + 8;
  3781. break;
  3782. }
  3783. }
  3784. }
  3785. /*
  3786. * Prepare drv-presence mask based on fcoe functions present.
  3787. * However consider only valid physical fcoe function numbers (0-15).
  3788. */
  3789. drv_presence_mask = ~((1 << (ha->portnum)) |
  3790. ((fcoe_other_function == 0xffff) ?
  3791. 0 : (1 << (fcoe_other_function))));
  3792. /* We are the reset owner iff:
  3793. * - No other protocol drivers present.
  3794. * - This is the lowest among fcoe functions. */
  3795. if (!(drv_presence & drv_presence_mask) &&
  3796. (ha->portnum < fcoe_other_function)) {
  3797. ql_dbg(ql_dbg_p3p, vha, 0xb07f,
  3798. "This host is Reset owner.\n");
  3799. ha->flags.nic_core_reset_owner = 1;
  3800. }
  3801. }
  3802. static int
  3803. __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
  3804. {
  3805. int rval = QLA_SUCCESS;
  3806. struct qla_hw_data *ha = vha->hw;
  3807. uint32_t drv_ack;
  3808. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
  3809. if (rval == QLA_SUCCESS) {
  3810. drv_ack |= (1 << ha->portnum);
  3811. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
  3812. }
  3813. return rval;
  3814. }
  3815. static int
  3816. __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
  3817. {
  3818. int rval = QLA_SUCCESS;
  3819. struct qla_hw_data *ha = vha->hw;
  3820. uint32_t drv_ack;
  3821. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
  3822. if (rval == QLA_SUCCESS) {
  3823. drv_ack &= ~(1 << ha->portnum);
  3824. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
  3825. }
  3826. return rval;
  3827. }
  3828. static const char *
  3829. qla83xx_dev_state_to_string(uint32_t dev_state)
  3830. {
  3831. switch (dev_state) {
  3832. case QLA8XXX_DEV_COLD:
  3833. return "COLD/RE-INIT";
  3834. case QLA8XXX_DEV_INITIALIZING:
  3835. return "INITIALIZING";
  3836. case QLA8XXX_DEV_READY:
  3837. return "READY";
  3838. case QLA8XXX_DEV_NEED_RESET:
  3839. return "NEED RESET";
  3840. case QLA8XXX_DEV_NEED_QUIESCENT:
  3841. return "NEED QUIESCENT";
  3842. case QLA8XXX_DEV_FAILED:
  3843. return "FAILED";
  3844. case QLA8XXX_DEV_QUIESCENT:
  3845. return "QUIESCENT";
  3846. default:
  3847. return "Unknown";
  3848. }
  3849. }
  3850. /* Assumes idc-lock always held on entry */
  3851. void
  3852. qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
  3853. {
  3854. struct qla_hw_data *ha = vha->hw;
  3855. uint32_t idc_audit_reg = 0, duration_secs = 0;
  3856. switch (audit_type) {
  3857. case IDC_AUDIT_TIMESTAMP:
  3858. ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
  3859. idc_audit_reg = (ha->portnum) |
  3860. (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
  3861. qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
  3862. break;
  3863. case IDC_AUDIT_COMPLETION:
  3864. duration_secs = ((jiffies_to_msecs(jiffies) -
  3865. jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
  3866. idc_audit_reg = (ha->portnum) |
  3867. (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
  3868. qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
  3869. break;
  3870. default:
  3871. ql_log(ql_log_warn, vha, 0xb078,
  3872. "Invalid audit type specified.\n");
  3873. break;
  3874. }
  3875. }
  3876. /* Assumes idc_lock always held on entry */
  3877. static int
  3878. qla83xx_initiating_reset(scsi_qla_host_t *vha)
  3879. {
  3880. struct qla_hw_data *ha = vha->hw;
  3881. uint32_t idc_control, dev_state;
  3882. __qla83xx_get_idc_control(vha, &idc_control);
  3883. if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
  3884. ql_log(ql_log_info, vha, 0xb080,
  3885. "NIC Core reset has been disabled. idc-control=0x%x\n",
  3886. idc_control);
  3887. return QLA_FUNCTION_FAILED;
  3888. }
  3889. /* Set NEED-RESET iff in READY state and we are the reset-owner */
  3890. qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3891. if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
  3892. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
  3893. QLA8XXX_DEV_NEED_RESET);
  3894. ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
  3895. qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
  3896. } else {
  3897. const char *state = qla83xx_dev_state_to_string(dev_state);
  3898. ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
  3899. /* SV: XXX: Is timeout required here? */
  3900. /* Wait for IDC state change READY -> NEED_RESET */
  3901. while (dev_state == QLA8XXX_DEV_READY) {
  3902. qla83xx_idc_unlock(vha, 0);
  3903. msleep(200);
  3904. qla83xx_idc_lock(vha, 0);
  3905. qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3906. }
  3907. }
  3908. /* Send IDC ack by writing to drv-ack register */
  3909. __qla83xx_set_drv_ack(vha);
  3910. return QLA_SUCCESS;
  3911. }
  3912. int
  3913. __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
  3914. {
  3915. return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
  3916. }
  3917. int
  3918. __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
  3919. {
  3920. return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
  3921. }
  3922. static int
  3923. qla83xx_check_driver_presence(scsi_qla_host_t *vha)
  3924. {
  3925. uint32_t drv_presence = 0;
  3926. struct qla_hw_data *ha = vha->hw;
  3927. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3928. if (drv_presence & (1 << ha->portnum))
  3929. return QLA_SUCCESS;
  3930. else
  3931. return QLA_TEST_FAILED;
  3932. }
  3933. int
  3934. qla83xx_nic_core_reset(scsi_qla_host_t *vha)
  3935. {
  3936. int rval = QLA_SUCCESS;
  3937. struct qla_hw_data *ha = vha->hw;
  3938. ql_dbg(ql_dbg_p3p, vha, 0xb058,
  3939. "Entered %s().\n", __func__);
  3940. if (vha->device_flags & DFLG_DEV_FAILED) {
  3941. ql_log(ql_log_warn, vha, 0xb059,
  3942. "Device in unrecoverable FAILED state.\n");
  3943. return QLA_FUNCTION_FAILED;
  3944. }
  3945. qla83xx_idc_lock(vha, 0);
  3946. if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
  3947. ql_log(ql_log_warn, vha, 0xb05a,
  3948. "Function=0x%x has been removed from IDC participation.\n",
  3949. ha->portnum);
  3950. rval = QLA_FUNCTION_FAILED;
  3951. goto exit;
  3952. }
  3953. qla83xx_reset_ownership(vha);
  3954. rval = qla83xx_initiating_reset(vha);
  3955. /*
  3956. * Perform reset if we are the reset-owner,
  3957. * else wait till IDC state changes to READY/FAILED.
  3958. */
  3959. if (rval == QLA_SUCCESS) {
  3960. rval = qla83xx_idc_state_handler(vha);
  3961. if (rval == QLA_SUCCESS)
  3962. ha->flags.nic_core_hung = 0;
  3963. __qla83xx_clear_drv_ack(vha);
  3964. }
  3965. exit:
  3966. qla83xx_idc_unlock(vha, 0);
  3967. ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
  3968. return rval;
  3969. }
  3970. int
  3971. qla2xxx_mctp_dump(scsi_qla_host_t *vha)
  3972. {
  3973. struct qla_hw_data *ha = vha->hw;
  3974. int rval = QLA_FUNCTION_FAILED;
  3975. if (!IS_MCTP_CAPABLE(ha)) {
  3976. /* This message can be removed from the final version */
  3977. ql_log(ql_log_info, vha, 0x506d,
  3978. "This board is not MCTP capable\n");
  3979. return rval;
  3980. }
  3981. if (!ha->mctp_dump) {
  3982. ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
  3983. MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
  3984. if (!ha->mctp_dump) {
  3985. ql_log(ql_log_warn, vha, 0x506e,
  3986. "Failed to allocate memory for mctp dump\n");
  3987. return rval;
  3988. }
  3989. }
  3990. #define MCTP_DUMP_STR_ADDR 0x00000000
  3991. rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
  3992. MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
  3993. if (rval != QLA_SUCCESS) {
  3994. ql_log(ql_log_warn, vha, 0x506f,
  3995. "Failed to capture mctp dump\n");
  3996. } else {
  3997. ql_log(ql_log_info, vha, 0x5070,
  3998. "Mctp dump capture for host (%ld/%p).\n",
  3999. vha->host_no, ha->mctp_dump);
  4000. ha->mctp_dumped = 1;
  4001. }
  4002. if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
  4003. ha->flags.nic_core_reset_hdlr_active = 1;
  4004. rval = qla83xx_restart_nic_firmware(vha);
  4005. if (rval)
  4006. /* NIC Core reset failed. */
  4007. ql_log(ql_log_warn, vha, 0x5071,
  4008. "Failed to restart nic firmware\n");
  4009. else
  4010. ql_dbg(ql_dbg_p3p, vha, 0xb084,
  4011. "Restarted NIC firmware successfully.\n");
  4012. ha->flags.nic_core_reset_hdlr_active = 0;
  4013. }
  4014. return rval;
  4015. }
  4016. /*
  4017. * qla2x00_quiesce_io
  4018. * Description: This function will block the new I/Os
  4019. * Its not aborting any I/Os as context
  4020. * is not destroyed during quiescence
  4021. * Arguments: scsi_qla_host_t
  4022. * return : void
  4023. */
  4024. void
  4025. qla2x00_quiesce_io(scsi_qla_host_t *vha)
  4026. {
  4027. struct qla_hw_data *ha = vha->hw;
  4028. struct scsi_qla_host *vp;
  4029. ql_dbg(ql_dbg_dpc, vha, 0x401d,
  4030. "Quiescing I/O - ha=%p.\n", ha);
  4031. atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
  4032. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  4033. atomic_set(&vha->loop_state, LOOP_DOWN);
  4034. qla2x00_mark_all_devices_lost(vha, 0);
  4035. list_for_each_entry(vp, &ha->vp_list, list)
  4036. qla2x00_mark_all_devices_lost(vp, 0);
  4037. } else {
  4038. if (!atomic_read(&vha->loop_down_timer))
  4039. atomic_set(&vha->loop_down_timer,
  4040. LOOP_DOWN_TIME);
  4041. }
  4042. /* Wait for pending cmds to complete */
  4043. qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
  4044. }
  4045. void
  4046. qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
  4047. {
  4048. struct qla_hw_data *ha = vha->hw;
  4049. struct scsi_qla_host *vp;
  4050. unsigned long flags;
  4051. fc_port_t *fcport;
  4052. /* For ISP82XX, driver waits for completion of the commands.
  4053. * online flag should be set.
  4054. */
  4055. if (!(IS_P3P_TYPE(ha)))
  4056. vha->flags.online = 0;
  4057. ha->flags.chip_reset_done = 0;
  4058. clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  4059. vha->qla_stats.total_isp_aborts++;
  4060. ql_log(ql_log_info, vha, 0x00af,
  4061. "Performing ISP error recovery - ha=%p.\n", ha);
  4062. /* For ISP82XX, reset_chip is just disabling interrupts.
  4063. * Driver waits for the completion of the commands.
  4064. * the interrupts need to be enabled.
  4065. */
  4066. if (!(IS_P3P_TYPE(ha)))
  4067. ha->isp_ops->reset_chip(vha);
  4068. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  4069. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  4070. atomic_set(&vha->loop_state, LOOP_DOWN);
  4071. qla2x00_mark_all_devices_lost(vha, 0);
  4072. spin_lock_irqsave(&ha->vport_slock, flags);
  4073. list_for_each_entry(vp, &ha->vp_list, list) {
  4074. atomic_inc(&vp->vref_count);
  4075. spin_unlock_irqrestore(&ha->vport_slock, flags);
  4076. qla2x00_mark_all_devices_lost(vp, 0);
  4077. spin_lock_irqsave(&ha->vport_slock, flags);
  4078. atomic_dec(&vp->vref_count);
  4079. }
  4080. spin_unlock_irqrestore(&ha->vport_slock, flags);
  4081. } else {
  4082. if (!atomic_read(&vha->loop_down_timer))
  4083. atomic_set(&vha->loop_down_timer,
  4084. LOOP_DOWN_TIME);
  4085. }
  4086. /* Clear all async request states across all VPs. */
  4087. list_for_each_entry(fcport, &vha->vp_fcports, list)
  4088. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  4089. spin_lock_irqsave(&ha->vport_slock, flags);
  4090. list_for_each_entry(vp, &ha->vp_list, list) {
  4091. atomic_inc(&vp->vref_count);
  4092. spin_unlock_irqrestore(&ha->vport_slock, flags);
  4093. list_for_each_entry(fcport, &vp->vp_fcports, list)
  4094. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  4095. spin_lock_irqsave(&ha->vport_slock, flags);
  4096. atomic_dec(&vp->vref_count);
  4097. }
  4098. spin_unlock_irqrestore(&ha->vport_slock, flags);
  4099. if (!ha->flags.eeh_busy) {
  4100. /* Make sure for ISP 82XX IO DMA is complete */
  4101. if (IS_P3P_TYPE(ha)) {
  4102. qla82xx_chip_reset_cleanup(vha);
  4103. ql_log(ql_log_info, vha, 0x00b4,
  4104. "Done chip reset cleanup.\n");
  4105. /* Done waiting for pending commands.
  4106. * Reset the online flag.
  4107. */
  4108. vha->flags.online = 0;
  4109. }
  4110. /* Requeue all commands in outstanding command list. */
  4111. qla2x00_abort_all_cmds(vha, DID_RESET << 16);
  4112. }
  4113. ha->chip_reset++;
  4114. /* memory barrier */
  4115. wmb();
  4116. }
  4117. /*
  4118. * qla2x00_abort_isp
  4119. * Resets ISP and aborts all outstanding commands.
  4120. *
  4121. * Input:
  4122. * ha = adapter block pointer.
  4123. *
  4124. * Returns:
  4125. * 0 = success
  4126. */
  4127. int
  4128. qla2x00_abort_isp(scsi_qla_host_t *vha)
  4129. {
  4130. int rval;
  4131. uint8_t status = 0;
  4132. struct qla_hw_data *ha = vha->hw;
  4133. struct scsi_qla_host *vp;
  4134. struct req_que *req = ha->req_q_map[0];
  4135. unsigned long flags;
  4136. if (vha->flags.online) {
  4137. qla2x00_abort_isp_cleanup(vha);
  4138. if (IS_QLA8031(ha)) {
  4139. ql_dbg(ql_dbg_p3p, vha, 0xb05c,
  4140. "Clearing fcoe driver presence.\n");
  4141. if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
  4142. ql_dbg(ql_dbg_p3p, vha, 0xb073,
  4143. "Error while clearing DRV-Presence.\n");
  4144. }
  4145. if (unlikely(pci_channel_offline(ha->pdev) &&
  4146. ha->flags.pci_channel_io_perm_failure)) {
  4147. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  4148. status = 0;
  4149. return status;
  4150. }
  4151. ha->isp_ops->get_flash_version(vha, req->ring);
  4152. ha->isp_ops->nvram_config(vha);
  4153. if (!qla2x00_restart_isp(vha)) {
  4154. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4155. if (!atomic_read(&vha->loop_down_timer)) {
  4156. /*
  4157. * Issue marker command only when we are going
  4158. * to start the I/O .
  4159. */
  4160. vha->marker_needed = 1;
  4161. }
  4162. vha->flags.online = 1;
  4163. ha->isp_ops->enable_intrs(ha);
  4164. ha->isp_abort_cnt = 0;
  4165. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  4166. if (IS_QLA81XX(ha) || IS_QLA8031(ha))
  4167. qla2x00_get_fw_version(vha);
  4168. if (ha->fce) {
  4169. ha->flags.fce_enabled = 1;
  4170. memset(ha->fce, 0,
  4171. fce_calc_size(ha->fce_bufs));
  4172. rval = qla2x00_enable_fce_trace(vha,
  4173. ha->fce_dma, ha->fce_bufs, ha->fce_mb,
  4174. &ha->fce_bufs);
  4175. if (rval) {
  4176. ql_log(ql_log_warn, vha, 0x8033,
  4177. "Unable to reinitialize FCE "
  4178. "(%d).\n", rval);
  4179. ha->flags.fce_enabled = 0;
  4180. }
  4181. }
  4182. if (ha->eft) {
  4183. memset(ha->eft, 0, EFT_SIZE);
  4184. rval = qla2x00_enable_eft_trace(vha,
  4185. ha->eft_dma, EFT_NUM_BUFFERS);
  4186. if (rval) {
  4187. ql_log(ql_log_warn, vha, 0x8034,
  4188. "Unable to reinitialize EFT "
  4189. "(%d).\n", rval);
  4190. }
  4191. }
  4192. } else { /* failed the ISP abort */
  4193. vha->flags.online = 1;
  4194. if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
  4195. if (ha->isp_abort_cnt == 0) {
  4196. ql_log(ql_log_fatal, vha, 0x8035,
  4197. "ISP error recover failed - "
  4198. "board disabled.\n");
  4199. /*
  4200. * The next call disables the board
  4201. * completely.
  4202. */
  4203. ha->isp_ops->reset_adapter(vha);
  4204. vha->flags.online = 0;
  4205. clear_bit(ISP_ABORT_RETRY,
  4206. &vha->dpc_flags);
  4207. status = 0;
  4208. } else { /* schedule another ISP abort */
  4209. ha->isp_abort_cnt--;
  4210. ql_dbg(ql_dbg_taskm, vha, 0x8020,
  4211. "ISP abort - retry remaining %d.\n",
  4212. ha->isp_abort_cnt);
  4213. status = 1;
  4214. }
  4215. } else {
  4216. ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
  4217. ql_dbg(ql_dbg_taskm, vha, 0x8021,
  4218. "ISP error recovery - retrying (%d) "
  4219. "more times.\n", ha->isp_abort_cnt);
  4220. set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  4221. status = 1;
  4222. }
  4223. }
  4224. }
  4225. if (!status) {
  4226. ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
  4227. spin_lock_irqsave(&ha->vport_slock, flags);
  4228. list_for_each_entry(vp, &ha->vp_list, list) {
  4229. if (vp->vp_idx) {
  4230. atomic_inc(&vp->vref_count);
  4231. spin_unlock_irqrestore(&ha->vport_slock, flags);
  4232. qla2x00_vp_abort_isp(vp);
  4233. spin_lock_irqsave(&ha->vport_slock, flags);
  4234. atomic_dec(&vp->vref_count);
  4235. }
  4236. }
  4237. spin_unlock_irqrestore(&ha->vport_slock, flags);
  4238. if (IS_QLA8031(ha)) {
  4239. ql_dbg(ql_dbg_p3p, vha, 0xb05d,
  4240. "Setting back fcoe driver presence.\n");
  4241. if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
  4242. ql_dbg(ql_dbg_p3p, vha, 0xb074,
  4243. "Error while setting DRV-Presence.\n");
  4244. }
  4245. } else {
  4246. ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
  4247. __func__);
  4248. }
  4249. return(status);
  4250. }
  4251. /*
  4252. * qla2x00_restart_isp
  4253. * restarts the ISP after a reset
  4254. *
  4255. * Input:
  4256. * ha = adapter block pointer.
  4257. *
  4258. * Returns:
  4259. * 0 = success
  4260. */
  4261. static int
  4262. qla2x00_restart_isp(scsi_qla_host_t *vha)
  4263. {
  4264. int status = 0;
  4265. struct qla_hw_data *ha = vha->hw;
  4266. struct req_que *req = ha->req_q_map[0];
  4267. struct rsp_que *rsp = ha->rsp_q_map[0];
  4268. /* If firmware needs to be loaded */
  4269. if (qla2x00_isp_firmware(vha)) {
  4270. vha->flags.online = 0;
  4271. status = ha->isp_ops->chip_diag(vha);
  4272. if (!status)
  4273. status = qla2x00_setup_chip(vha);
  4274. }
  4275. if (!status && !(status = qla2x00_init_rings(vha))) {
  4276. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4277. ha->flags.chip_reset_done = 1;
  4278. /* Initialize the queues in use */
  4279. qla25xx_init_queues(ha);
  4280. status = qla2x00_fw_ready(vha);
  4281. if (!status) {
  4282. /* Issue a marker after FW becomes ready. */
  4283. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  4284. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  4285. }
  4286. /* if no cable then assume it's good */
  4287. if ((vha->device_flags & DFLG_NO_CABLE))
  4288. status = 0;
  4289. }
  4290. return (status);
  4291. }
  4292. static int
  4293. qla25xx_init_queues(struct qla_hw_data *ha)
  4294. {
  4295. struct rsp_que *rsp = NULL;
  4296. struct req_que *req = NULL;
  4297. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  4298. int ret = -1;
  4299. int i;
  4300. for (i = 1; i < ha->max_rsp_queues; i++) {
  4301. rsp = ha->rsp_q_map[i];
  4302. if (rsp && test_bit(i, ha->rsp_qid_map)) {
  4303. rsp->options &= ~BIT_0;
  4304. ret = qla25xx_init_rsp_que(base_vha, rsp);
  4305. if (ret != QLA_SUCCESS)
  4306. ql_dbg(ql_dbg_init, base_vha, 0x00ff,
  4307. "%s Rsp que: %d init failed.\n",
  4308. __func__, rsp->id);
  4309. else
  4310. ql_dbg(ql_dbg_init, base_vha, 0x0100,
  4311. "%s Rsp que: %d inited.\n",
  4312. __func__, rsp->id);
  4313. }
  4314. }
  4315. for (i = 1; i < ha->max_req_queues; i++) {
  4316. req = ha->req_q_map[i];
  4317. if (req && test_bit(i, ha->req_qid_map)) {
  4318. /* Clear outstanding commands array. */
  4319. req->options &= ~BIT_0;
  4320. ret = qla25xx_init_req_que(base_vha, req);
  4321. if (ret != QLA_SUCCESS)
  4322. ql_dbg(ql_dbg_init, base_vha, 0x0101,
  4323. "%s Req que: %d init failed.\n",
  4324. __func__, req->id);
  4325. else
  4326. ql_dbg(ql_dbg_init, base_vha, 0x0102,
  4327. "%s Req que: %d inited.\n",
  4328. __func__, req->id);
  4329. }
  4330. }
  4331. return ret;
  4332. }
  4333. /*
  4334. * qla2x00_reset_adapter
  4335. * Reset adapter.
  4336. *
  4337. * Input:
  4338. * ha = adapter block pointer.
  4339. */
  4340. void
  4341. qla2x00_reset_adapter(scsi_qla_host_t *vha)
  4342. {
  4343. unsigned long flags = 0;
  4344. struct qla_hw_data *ha = vha->hw;
  4345. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  4346. vha->flags.online = 0;
  4347. ha->isp_ops->disable_intrs(ha);
  4348. spin_lock_irqsave(&ha->hardware_lock, flags);
  4349. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  4350. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  4351. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  4352. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  4353. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4354. }
  4355. void
  4356. qla24xx_reset_adapter(scsi_qla_host_t *vha)
  4357. {
  4358. unsigned long flags = 0;
  4359. struct qla_hw_data *ha = vha->hw;
  4360. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  4361. if (IS_P3P_TYPE(ha))
  4362. return;
  4363. vha->flags.online = 0;
  4364. ha->isp_ops->disable_intrs(ha);
  4365. spin_lock_irqsave(&ha->hardware_lock, flags);
  4366. WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
  4367. RD_REG_DWORD(&reg->hccr);
  4368. WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  4369. RD_REG_DWORD(&reg->hccr);
  4370. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4371. if (IS_NOPOLLING_TYPE(ha))
  4372. ha->isp_ops->enable_intrs(ha);
  4373. }
  4374. /* On sparc systems, obtain port and node WWN from firmware
  4375. * properties.
  4376. */
  4377. static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
  4378. struct nvram_24xx *nv)
  4379. {
  4380. #ifdef CONFIG_SPARC
  4381. struct qla_hw_data *ha = vha->hw;
  4382. struct pci_dev *pdev = ha->pdev;
  4383. struct device_node *dp = pci_device_to_OF_node(pdev);
  4384. const u8 *val;
  4385. int len;
  4386. val = of_get_property(dp, "port-wwn", &len);
  4387. if (val && len >= WWN_SIZE)
  4388. memcpy(nv->port_name, val, WWN_SIZE);
  4389. val = of_get_property(dp, "node-wwn", &len);
  4390. if (val && len >= WWN_SIZE)
  4391. memcpy(nv->node_name, val, WWN_SIZE);
  4392. #endif
  4393. }
  4394. int
  4395. qla24xx_nvram_config(scsi_qla_host_t *vha)
  4396. {
  4397. int rval;
  4398. struct init_cb_24xx *icb;
  4399. struct nvram_24xx *nv;
  4400. uint32_t *dptr;
  4401. uint8_t *dptr1, *dptr2;
  4402. uint32_t chksum;
  4403. uint16_t cnt;
  4404. struct qla_hw_data *ha = vha->hw;
  4405. rval = QLA_SUCCESS;
  4406. icb = (struct init_cb_24xx *)ha->init_cb;
  4407. nv = ha->nvram;
  4408. /* Determine NVRAM starting address. */
  4409. if (ha->port_no == 0) {
  4410. ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
  4411. ha->vpd_base = FA_NVRAM_VPD0_ADDR;
  4412. } else {
  4413. ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
  4414. ha->vpd_base = FA_NVRAM_VPD1_ADDR;
  4415. }
  4416. ha->nvram_size = sizeof(struct nvram_24xx);
  4417. ha->vpd_size = FA_NVRAM_VPD_SIZE;
  4418. /* Get VPD data into cache */
  4419. ha->vpd = ha->nvram + VPD_OFFSET;
  4420. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
  4421. ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
  4422. /* Get NVRAM data into cache and calculate checksum. */
  4423. dptr = (uint32_t *)nv;
  4424. ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
  4425. ha->nvram_size);
  4426. for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
  4427. chksum += le32_to_cpu(*dptr);
  4428. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
  4429. "Contents of NVRAM\n");
  4430. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
  4431. (uint8_t *)nv, ha->nvram_size);
  4432. /* Bad NVRAM data, set defaults parameters. */
  4433. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
  4434. || nv->id[3] != ' ' ||
  4435. nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
  4436. /* Reset NVRAM data. */
  4437. ql_log(ql_log_warn, vha, 0x006b,
  4438. "Inconsistent NVRAM detected: checksum=0x%x id=%c "
  4439. "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
  4440. ql_log(ql_log_warn, vha, 0x006c,
  4441. "Falling back to functioning (yet invalid -- WWPN) "
  4442. "defaults.\n");
  4443. /*
  4444. * Set default initialization control block.
  4445. */
  4446. memset(nv, 0, ha->nvram_size);
  4447. nv->nvram_version = cpu_to_le16(ICB_VERSION);
  4448. nv->version = cpu_to_le16(ICB_VERSION);
  4449. nv->frame_payload_size = 2048;
  4450. nv->execution_throttle = cpu_to_le16(0xFFFF);
  4451. nv->exchange_count = cpu_to_le16(0);
  4452. nv->hard_address = cpu_to_le16(124);
  4453. nv->port_name[0] = 0x21;
  4454. nv->port_name[1] = 0x00 + ha->port_no + 1;
  4455. nv->port_name[2] = 0x00;
  4456. nv->port_name[3] = 0xe0;
  4457. nv->port_name[4] = 0x8b;
  4458. nv->port_name[5] = 0x1c;
  4459. nv->port_name[6] = 0x55;
  4460. nv->port_name[7] = 0x86;
  4461. nv->node_name[0] = 0x20;
  4462. nv->node_name[1] = 0x00;
  4463. nv->node_name[2] = 0x00;
  4464. nv->node_name[3] = 0xe0;
  4465. nv->node_name[4] = 0x8b;
  4466. nv->node_name[5] = 0x1c;
  4467. nv->node_name[6] = 0x55;
  4468. nv->node_name[7] = 0x86;
  4469. qla24xx_nvram_wwn_from_ofw(vha, nv);
  4470. nv->login_retry_count = cpu_to_le16(8);
  4471. nv->interrupt_delay_timer = cpu_to_le16(0);
  4472. nv->login_timeout = cpu_to_le16(0);
  4473. nv->firmware_options_1 =
  4474. cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
  4475. nv->firmware_options_2 = cpu_to_le32(2 << 4);
  4476. nv->firmware_options_2 |= cpu_to_le32(BIT_12);
  4477. nv->firmware_options_3 = cpu_to_le32(2 << 13);
  4478. nv->host_p = cpu_to_le32(BIT_11|BIT_10);
  4479. nv->efi_parameters = cpu_to_le32(0);
  4480. nv->reset_delay = 5;
  4481. nv->max_luns_per_target = cpu_to_le16(128);
  4482. nv->port_down_retry_count = cpu_to_le16(30);
  4483. nv->link_down_timeout = cpu_to_le16(30);
  4484. rval = 1;
  4485. }
  4486. if (!qla_ini_mode_enabled(vha)) {
  4487. /* Don't enable full login after initial LIP */
  4488. nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
  4489. /* Don't enable LIP full login for initiator */
  4490. nv->host_p &= cpu_to_le32(~BIT_10);
  4491. }
  4492. qlt_24xx_config_nvram_stage1(vha, nv);
  4493. /* Reset Initialization control block */
  4494. memset(icb, 0, ha->init_cb_size);
  4495. /* Copy 1st segment. */
  4496. dptr1 = (uint8_t *)icb;
  4497. dptr2 = (uint8_t *)&nv->version;
  4498. cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
  4499. while (cnt--)
  4500. *dptr1++ = *dptr2++;
  4501. icb->login_retry_count = nv->login_retry_count;
  4502. icb->link_down_on_nos = nv->link_down_on_nos;
  4503. /* Copy 2nd segment. */
  4504. dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
  4505. dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
  4506. cnt = (uint8_t *)&icb->reserved_3 -
  4507. (uint8_t *)&icb->interrupt_delay_timer;
  4508. while (cnt--)
  4509. *dptr1++ = *dptr2++;
  4510. /*
  4511. * Setup driver NVRAM options.
  4512. */
  4513. qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
  4514. "QLA2462");
  4515. qlt_24xx_config_nvram_stage2(vha, icb);
  4516. if (nv->host_p & cpu_to_le32(BIT_15)) {
  4517. /* Use alternate WWN? */
  4518. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  4519. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  4520. }
  4521. /* Prepare nodename */
  4522. if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
  4523. /*
  4524. * Firmware will apply the following mask if the nodename was
  4525. * not provided.
  4526. */
  4527. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  4528. icb->node_name[0] &= 0xF0;
  4529. }
  4530. /* Set host adapter parameters. */
  4531. ha->flags.disable_risc_code_load = 0;
  4532. ha->flags.enable_lip_reset = 0;
  4533. ha->flags.enable_lip_full_login =
  4534. le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
  4535. ha->flags.enable_target_reset =
  4536. le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
  4537. ha->flags.enable_led_scheme = 0;
  4538. ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
  4539. ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
  4540. (BIT_6 | BIT_5 | BIT_4)) >> 4;
  4541. memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
  4542. sizeof(ha->fw_seriallink_options24));
  4543. /* save HBA serial number */
  4544. ha->serial0 = icb->port_name[5];
  4545. ha->serial1 = icb->port_name[6];
  4546. ha->serial2 = icb->port_name[7];
  4547. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  4548. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  4549. icb->execution_throttle = cpu_to_le16(0xFFFF);
  4550. ha->retry_count = le16_to_cpu(nv->login_retry_count);
  4551. /* Set minimum login_timeout to 4 seconds. */
  4552. if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
  4553. nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
  4554. if (le16_to_cpu(nv->login_timeout) < 4)
  4555. nv->login_timeout = cpu_to_le16(4);
  4556. ha->login_timeout = le16_to_cpu(nv->login_timeout);
  4557. /* Set minimum RATOV to 100 tenths of a second. */
  4558. ha->r_a_tov = 100;
  4559. ha->loop_reset_delay = nv->reset_delay;
  4560. /* Link Down Timeout = 0:
  4561. *
  4562. * When Port Down timer expires we will start returning
  4563. * I/O's to OS with "DID_NO_CONNECT".
  4564. *
  4565. * Link Down Timeout != 0:
  4566. *
  4567. * The driver waits for the link to come up after link down
  4568. * before returning I/Os to OS with "DID_NO_CONNECT".
  4569. */
  4570. if (le16_to_cpu(nv->link_down_timeout) == 0) {
  4571. ha->loop_down_abort_time =
  4572. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  4573. } else {
  4574. ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
  4575. ha->loop_down_abort_time =
  4576. (LOOP_DOWN_TIME - ha->link_down_timeout);
  4577. }
  4578. /* Need enough time to try and get the port back. */
  4579. ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
  4580. if (qlport_down_retry)
  4581. ha->port_down_retry_count = qlport_down_retry;
  4582. /* Set login_retry_count */
  4583. ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
  4584. if (ha->port_down_retry_count ==
  4585. le16_to_cpu(nv->port_down_retry_count) &&
  4586. ha->port_down_retry_count > 3)
  4587. ha->login_retry_count = ha->port_down_retry_count;
  4588. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  4589. ha->login_retry_count = ha->port_down_retry_count;
  4590. if (ql2xloginretrycount)
  4591. ha->login_retry_count = ql2xloginretrycount;
  4592. /* Enable ZIO. */
  4593. if (!vha->flags.init_done) {
  4594. ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
  4595. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  4596. ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
  4597. le16_to_cpu(icb->interrupt_delay_timer): 2;
  4598. }
  4599. icb->firmware_options_2 &= cpu_to_le32(
  4600. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
  4601. vha->flags.process_response_queue = 0;
  4602. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  4603. ha->zio_mode = QLA_ZIO_MODE_6;
  4604. ql_log(ql_log_info, vha, 0x006f,
  4605. "ZIO mode %d enabled; timer delay (%d us).\n",
  4606. ha->zio_mode, ha->zio_timer * 100);
  4607. icb->firmware_options_2 |= cpu_to_le32(
  4608. (uint32_t)ha->zio_mode);
  4609. icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
  4610. vha->flags.process_response_queue = 1;
  4611. }
  4612. if (rval) {
  4613. ql_log(ql_log_warn, vha, 0x0070,
  4614. "NVRAM configuration failed.\n");
  4615. }
  4616. return (rval);
  4617. }
  4618. uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
  4619. {
  4620. struct qla27xx_image_status pri_image_status, sec_image_status;
  4621. uint8_t valid_pri_image, valid_sec_image;
  4622. uint32_t *wptr;
  4623. uint32_t cnt, chksum, size;
  4624. struct qla_hw_data *ha = vha->hw;
  4625. valid_pri_image = valid_sec_image = 1;
  4626. ha->active_image = 0;
  4627. size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
  4628. if (!ha->flt_region_img_status_pri) {
  4629. valid_pri_image = 0;
  4630. goto check_sec_image;
  4631. }
  4632. qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
  4633. ha->flt_region_img_status_pri, size);
  4634. if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
  4635. ql_dbg(ql_dbg_init, vha, 0x018b,
  4636. "Primary image signature (0x%x) not valid\n",
  4637. pri_image_status.signature);
  4638. valid_pri_image = 0;
  4639. goto check_sec_image;
  4640. }
  4641. wptr = (uint32_t *)(&pri_image_status);
  4642. cnt = size;
  4643. for (chksum = 0; cnt--; wptr++)
  4644. chksum += le32_to_cpu(*wptr);
  4645. if (chksum) {
  4646. ql_dbg(ql_dbg_init, vha, 0x018c,
  4647. "Checksum validation failed for primary image (0x%x)\n",
  4648. chksum);
  4649. valid_pri_image = 0;
  4650. }
  4651. check_sec_image:
  4652. if (!ha->flt_region_img_status_sec) {
  4653. valid_sec_image = 0;
  4654. goto check_valid_image;
  4655. }
  4656. qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
  4657. ha->flt_region_img_status_sec, size);
  4658. if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
  4659. ql_dbg(ql_dbg_init, vha, 0x018d,
  4660. "Secondary image signature(0x%x) not valid\n",
  4661. sec_image_status.signature);
  4662. valid_sec_image = 0;
  4663. goto check_valid_image;
  4664. }
  4665. wptr = (uint32_t *)(&sec_image_status);
  4666. cnt = size;
  4667. for (chksum = 0; cnt--; wptr++)
  4668. chksum += le32_to_cpu(*wptr);
  4669. if (chksum) {
  4670. ql_dbg(ql_dbg_init, vha, 0x018e,
  4671. "Checksum validation failed for secondary image (0x%x)\n",
  4672. chksum);
  4673. valid_sec_image = 0;
  4674. }
  4675. check_valid_image:
  4676. if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
  4677. ha->active_image = QLA27XX_PRIMARY_IMAGE;
  4678. if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
  4679. if (!ha->active_image ||
  4680. pri_image_status.generation_number <
  4681. sec_image_status.generation_number)
  4682. ha->active_image = QLA27XX_SECONDARY_IMAGE;
  4683. }
  4684. ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n",
  4685. ha->active_image == 0 ? "default bootld and fw" :
  4686. ha->active_image == 1 ? "primary" :
  4687. ha->active_image == 2 ? "secondary" :
  4688. "Invalid");
  4689. return ha->active_image;
  4690. }
  4691. static int
  4692. qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
  4693. uint32_t faddr)
  4694. {
  4695. int rval = QLA_SUCCESS;
  4696. int segments, fragment;
  4697. uint32_t *dcode, dlen;
  4698. uint32_t risc_addr;
  4699. uint32_t risc_size;
  4700. uint32_t i;
  4701. struct qla_hw_data *ha = vha->hw;
  4702. struct req_que *req = ha->req_q_map[0];
  4703. ql_dbg(ql_dbg_init, vha, 0x008b,
  4704. "FW: Loading firmware from flash (%x).\n", faddr);
  4705. rval = QLA_SUCCESS;
  4706. segments = FA_RISC_CODE_SEGMENTS;
  4707. dcode = (uint32_t *)req->ring;
  4708. *srisc_addr = 0;
  4709. if (IS_QLA27XX(ha) &&
  4710. qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
  4711. faddr = ha->flt_region_fw_sec;
  4712. /* Validate firmware image by checking version. */
  4713. qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
  4714. for (i = 0; i < 4; i++)
  4715. dcode[i] = be32_to_cpu(dcode[i]);
  4716. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  4717. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  4718. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  4719. dcode[3] == 0)) {
  4720. ql_log(ql_log_fatal, vha, 0x008c,
  4721. "Unable to verify the integrity of flash firmware "
  4722. "image.\n");
  4723. ql_log(ql_log_fatal, vha, 0x008d,
  4724. "Firmware data: %08x %08x %08x %08x.\n",
  4725. dcode[0], dcode[1], dcode[2], dcode[3]);
  4726. return QLA_FUNCTION_FAILED;
  4727. }
  4728. while (segments && rval == QLA_SUCCESS) {
  4729. /* Read segment's load information. */
  4730. qla24xx_read_flash_data(vha, dcode, faddr, 4);
  4731. risc_addr = be32_to_cpu(dcode[2]);
  4732. *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
  4733. risc_size = be32_to_cpu(dcode[3]);
  4734. fragment = 0;
  4735. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4736. dlen = (uint32_t)(ha->fw_transfer_size >> 2);
  4737. if (dlen > risc_size)
  4738. dlen = risc_size;
  4739. ql_dbg(ql_dbg_init, vha, 0x008e,
  4740. "Loading risc segment@ risc addr %x "
  4741. "number of dwords 0x%x offset 0x%x.\n",
  4742. risc_addr, dlen, faddr);
  4743. qla24xx_read_flash_data(vha, dcode, faddr, dlen);
  4744. for (i = 0; i < dlen; i++)
  4745. dcode[i] = swab32(dcode[i]);
  4746. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4747. dlen);
  4748. if (rval) {
  4749. ql_log(ql_log_fatal, vha, 0x008f,
  4750. "Failed to load segment %d of firmware.\n",
  4751. fragment);
  4752. return QLA_FUNCTION_FAILED;
  4753. }
  4754. faddr += dlen;
  4755. risc_addr += dlen;
  4756. risc_size -= dlen;
  4757. fragment++;
  4758. }
  4759. /* Next segment. */
  4760. segments--;
  4761. }
  4762. if (!IS_QLA27XX(ha))
  4763. return rval;
  4764. if (ha->fw_dump_template)
  4765. vfree(ha->fw_dump_template);
  4766. ha->fw_dump_template = NULL;
  4767. ha->fw_dump_template_len = 0;
  4768. ql_dbg(ql_dbg_init, vha, 0x0161,
  4769. "Loading fwdump template from %x\n", faddr);
  4770. qla24xx_read_flash_data(vha, dcode, faddr, 7);
  4771. risc_size = be32_to_cpu(dcode[2]);
  4772. ql_dbg(ql_dbg_init, vha, 0x0162,
  4773. "-> array size %x dwords\n", risc_size);
  4774. if (risc_size == 0 || risc_size == ~0)
  4775. goto default_template;
  4776. dlen = (risc_size - 8) * sizeof(*dcode);
  4777. ql_dbg(ql_dbg_init, vha, 0x0163,
  4778. "-> template allocating %x bytes...\n", dlen);
  4779. ha->fw_dump_template = vmalloc(dlen);
  4780. if (!ha->fw_dump_template) {
  4781. ql_log(ql_log_warn, vha, 0x0164,
  4782. "Failed fwdump template allocate %x bytes.\n", risc_size);
  4783. goto default_template;
  4784. }
  4785. faddr += 7;
  4786. risc_size -= 8;
  4787. dcode = ha->fw_dump_template;
  4788. qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
  4789. for (i = 0; i < risc_size; i++)
  4790. dcode[i] = le32_to_cpu(dcode[i]);
  4791. if (!qla27xx_fwdt_template_valid(dcode)) {
  4792. ql_log(ql_log_warn, vha, 0x0165,
  4793. "Failed fwdump template validate\n");
  4794. goto default_template;
  4795. }
  4796. dlen = qla27xx_fwdt_template_size(dcode);
  4797. ql_dbg(ql_dbg_init, vha, 0x0166,
  4798. "-> template size %x bytes\n", dlen);
  4799. if (dlen > risc_size * sizeof(*dcode)) {
  4800. ql_log(ql_log_warn, vha, 0x0167,
  4801. "Failed fwdump template exceeds array by %x bytes\n",
  4802. (uint32_t)(dlen - risc_size * sizeof(*dcode)));
  4803. goto default_template;
  4804. }
  4805. ha->fw_dump_template_len = dlen;
  4806. return rval;
  4807. default_template:
  4808. ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
  4809. if (ha->fw_dump_template)
  4810. vfree(ha->fw_dump_template);
  4811. ha->fw_dump_template = NULL;
  4812. ha->fw_dump_template_len = 0;
  4813. dlen = qla27xx_fwdt_template_default_size();
  4814. ql_dbg(ql_dbg_init, vha, 0x0169,
  4815. "-> template allocating %x bytes...\n", dlen);
  4816. ha->fw_dump_template = vmalloc(dlen);
  4817. if (!ha->fw_dump_template) {
  4818. ql_log(ql_log_warn, vha, 0x016a,
  4819. "Failed fwdump template allocate %x bytes.\n", risc_size);
  4820. goto failed_template;
  4821. }
  4822. dcode = ha->fw_dump_template;
  4823. risc_size = dlen / sizeof(*dcode);
  4824. memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
  4825. for (i = 0; i < risc_size; i++)
  4826. dcode[i] = be32_to_cpu(dcode[i]);
  4827. if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
  4828. ql_log(ql_log_warn, vha, 0x016b,
  4829. "Failed fwdump template validate\n");
  4830. goto failed_template;
  4831. }
  4832. dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
  4833. ql_dbg(ql_dbg_init, vha, 0x016c,
  4834. "-> template size %x bytes\n", dlen);
  4835. ha->fw_dump_template_len = dlen;
  4836. return rval;
  4837. failed_template:
  4838. ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
  4839. if (ha->fw_dump_template)
  4840. vfree(ha->fw_dump_template);
  4841. ha->fw_dump_template = NULL;
  4842. ha->fw_dump_template_len = 0;
  4843. return rval;
  4844. }
  4845. #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
  4846. int
  4847. qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4848. {
  4849. int rval;
  4850. int i, fragment;
  4851. uint16_t *wcode, *fwcode;
  4852. uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
  4853. struct fw_blob *blob;
  4854. struct qla_hw_data *ha = vha->hw;
  4855. struct req_que *req = ha->req_q_map[0];
  4856. /* Load firmware blob. */
  4857. blob = qla2x00_request_firmware(vha);
  4858. if (!blob) {
  4859. ql_log(ql_log_info, vha, 0x0083,
  4860. "Firmware image unavailable.\n");
  4861. ql_log(ql_log_info, vha, 0x0084,
  4862. "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
  4863. return QLA_FUNCTION_FAILED;
  4864. }
  4865. rval = QLA_SUCCESS;
  4866. wcode = (uint16_t *)req->ring;
  4867. *srisc_addr = 0;
  4868. fwcode = (uint16_t *)blob->fw->data;
  4869. fwclen = 0;
  4870. /* Validate firmware image by checking version. */
  4871. if (blob->fw->size < 8 * sizeof(uint16_t)) {
  4872. ql_log(ql_log_fatal, vha, 0x0085,
  4873. "Unable to verify integrity of firmware image (%Zd).\n",
  4874. blob->fw->size);
  4875. goto fail_fw_integrity;
  4876. }
  4877. for (i = 0; i < 4; i++)
  4878. wcode[i] = be16_to_cpu(fwcode[i + 4]);
  4879. if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
  4880. wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
  4881. wcode[2] == 0 && wcode[3] == 0)) {
  4882. ql_log(ql_log_fatal, vha, 0x0086,
  4883. "Unable to verify integrity of firmware image.\n");
  4884. ql_log(ql_log_fatal, vha, 0x0087,
  4885. "Firmware data: %04x %04x %04x %04x.\n",
  4886. wcode[0], wcode[1], wcode[2], wcode[3]);
  4887. goto fail_fw_integrity;
  4888. }
  4889. seg = blob->segs;
  4890. while (*seg && rval == QLA_SUCCESS) {
  4891. risc_addr = *seg;
  4892. *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
  4893. risc_size = be16_to_cpu(fwcode[3]);
  4894. /* Validate firmware image size. */
  4895. fwclen += risc_size * sizeof(uint16_t);
  4896. if (blob->fw->size < fwclen) {
  4897. ql_log(ql_log_fatal, vha, 0x0088,
  4898. "Unable to verify integrity of firmware image "
  4899. "(%Zd).\n", blob->fw->size);
  4900. goto fail_fw_integrity;
  4901. }
  4902. fragment = 0;
  4903. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4904. wlen = (uint16_t)(ha->fw_transfer_size >> 1);
  4905. if (wlen > risc_size)
  4906. wlen = risc_size;
  4907. ql_dbg(ql_dbg_init, vha, 0x0089,
  4908. "Loading risc segment@ risc addr %x number of "
  4909. "words 0x%x.\n", risc_addr, wlen);
  4910. for (i = 0; i < wlen; i++)
  4911. wcode[i] = swab16(fwcode[i]);
  4912. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4913. wlen);
  4914. if (rval) {
  4915. ql_log(ql_log_fatal, vha, 0x008a,
  4916. "Failed to load segment %d of firmware.\n",
  4917. fragment);
  4918. break;
  4919. }
  4920. fwcode += wlen;
  4921. risc_addr += wlen;
  4922. risc_size -= wlen;
  4923. fragment++;
  4924. }
  4925. /* Next segment. */
  4926. seg++;
  4927. }
  4928. return rval;
  4929. fail_fw_integrity:
  4930. return QLA_FUNCTION_FAILED;
  4931. }
  4932. static int
  4933. qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4934. {
  4935. int rval;
  4936. int segments, fragment;
  4937. uint32_t *dcode, dlen;
  4938. uint32_t risc_addr;
  4939. uint32_t risc_size;
  4940. uint32_t i;
  4941. struct fw_blob *blob;
  4942. const uint32_t *fwcode;
  4943. uint32_t fwclen;
  4944. struct qla_hw_data *ha = vha->hw;
  4945. struct req_que *req = ha->req_q_map[0];
  4946. /* Load firmware blob. */
  4947. blob = qla2x00_request_firmware(vha);
  4948. if (!blob) {
  4949. ql_log(ql_log_warn, vha, 0x0090,
  4950. "Firmware image unavailable.\n");
  4951. ql_log(ql_log_warn, vha, 0x0091,
  4952. "Firmware images can be retrieved from: "
  4953. QLA_FW_URL ".\n");
  4954. return QLA_FUNCTION_FAILED;
  4955. }
  4956. ql_dbg(ql_dbg_init, vha, 0x0092,
  4957. "FW: Loading via request-firmware.\n");
  4958. rval = QLA_SUCCESS;
  4959. segments = FA_RISC_CODE_SEGMENTS;
  4960. dcode = (uint32_t *)req->ring;
  4961. *srisc_addr = 0;
  4962. fwcode = (uint32_t *)blob->fw->data;
  4963. fwclen = 0;
  4964. /* Validate firmware image by checking version. */
  4965. if (blob->fw->size < 8 * sizeof(uint32_t)) {
  4966. ql_log(ql_log_fatal, vha, 0x0093,
  4967. "Unable to verify integrity of firmware image (%Zd).\n",
  4968. blob->fw->size);
  4969. return QLA_FUNCTION_FAILED;
  4970. }
  4971. for (i = 0; i < 4; i++)
  4972. dcode[i] = be32_to_cpu(fwcode[i + 4]);
  4973. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  4974. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  4975. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  4976. dcode[3] == 0)) {
  4977. ql_log(ql_log_fatal, vha, 0x0094,
  4978. "Unable to verify integrity of firmware image (%Zd).\n",
  4979. blob->fw->size);
  4980. ql_log(ql_log_fatal, vha, 0x0095,
  4981. "Firmware data: %08x %08x %08x %08x.\n",
  4982. dcode[0], dcode[1], dcode[2], dcode[3]);
  4983. return QLA_FUNCTION_FAILED;
  4984. }
  4985. while (segments && rval == QLA_SUCCESS) {
  4986. risc_addr = be32_to_cpu(fwcode[2]);
  4987. *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
  4988. risc_size = be32_to_cpu(fwcode[3]);
  4989. /* Validate firmware image size. */
  4990. fwclen += risc_size * sizeof(uint32_t);
  4991. if (blob->fw->size < fwclen) {
  4992. ql_log(ql_log_fatal, vha, 0x0096,
  4993. "Unable to verify integrity of firmware image "
  4994. "(%Zd).\n", blob->fw->size);
  4995. return QLA_FUNCTION_FAILED;
  4996. }
  4997. fragment = 0;
  4998. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4999. dlen = (uint32_t)(ha->fw_transfer_size >> 2);
  5000. if (dlen > risc_size)
  5001. dlen = risc_size;
  5002. ql_dbg(ql_dbg_init, vha, 0x0097,
  5003. "Loading risc segment@ risc addr %x "
  5004. "number of dwords 0x%x.\n", risc_addr, dlen);
  5005. for (i = 0; i < dlen; i++)
  5006. dcode[i] = swab32(fwcode[i]);
  5007. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  5008. dlen);
  5009. if (rval) {
  5010. ql_log(ql_log_fatal, vha, 0x0098,
  5011. "Failed to load segment %d of firmware.\n",
  5012. fragment);
  5013. return QLA_FUNCTION_FAILED;
  5014. }
  5015. fwcode += dlen;
  5016. risc_addr += dlen;
  5017. risc_size -= dlen;
  5018. fragment++;
  5019. }
  5020. /* Next segment. */
  5021. segments--;
  5022. }
  5023. if (!IS_QLA27XX(ha))
  5024. return rval;
  5025. if (ha->fw_dump_template)
  5026. vfree(ha->fw_dump_template);
  5027. ha->fw_dump_template = NULL;
  5028. ha->fw_dump_template_len = 0;
  5029. ql_dbg(ql_dbg_init, vha, 0x171,
  5030. "Loading fwdump template from %x\n",
  5031. (uint32_t)((void *)fwcode - (void *)blob->fw->data));
  5032. risc_size = be32_to_cpu(fwcode[2]);
  5033. ql_dbg(ql_dbg_init, vha, 0x172,
  5034. "-> array size %x dwords\n", risc_size);
  5035. if (risc_size == 0 || risc_size == ~0)
  5036. goto default_template;
  5037. dlen = (risc_size - 8) * sizeof(*fwcode);
  5038. ql_dbg(ql_dbg_init, vha, 0x0173,
  5039. "-> template allocating %x bytes...\n", dlen);
  5040. ha->fw_dump_template = vmalloc(dlen);
  5041. if (!ha->fw_dump_template) {
  5042. ql_log(ql_log_warn, vha, 0x0174,
  5043. "Failed fwdump template allocate %x bytes.\n", risc_size);
  5044. goto default_template;
  5045. }
  5046. fwcode += 7;
  5047. risc_size -= 8;
  5048. dcode = ha->fw_dump_template;
  5049. for (i = 0; i < risc_size; i++)
  5050. dcode[i] = le32_to_cpu(fwcode[i]);
  5051. if (!qla27xx_fwdt_template_valid(dcode)) {
  5052. ql_log(ql_log_warn, vha, 0x0175,
  5053. "Failed fwdump template validate\n");
  5054. goto default_template;
  5055. }
  5056. dlen = qla27xx_fwdt_template_size(dcode);
  5057. ql_dbg(ql_dbg_init, vha, 0x0176,
  5058. "-> template size %x bytes\n", dlen);
  5059. if (dlen > risc_size * sizeof(*fwcode)) {
  5060. ql_log(ql_log_warn, vha, 0x0177,
  5061. "Failed fwdump template exceeds array by %x bytes\n",
  5062. (uint32_t)(dlen - risc_size * sizeof(*fwcode)));
  5063. goto default_template;
  5064. }
  5065. ha->fw_dump_template_len = dlen;
  5066. return rval;
  5067. default_template:
  5068. ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
  5069. if (ha->fw_dump_template)
  5070. vfree(ha->fw_dump_template);
  5071. ha->fw_dump_template = NULL;
  5072. ha->fw_dump_template_len = 0;
  5073. dlen = qla27xx_fwdt_template_default_size();
  5074. ql_dbg(ql_dbg_init, vha, 0x0179,
  5075. "-> template allocating %x bytes...\n", dlen);
  5076. ha->fw_dump_template = vmalloc(dlen);
  5077. if (!ha->fw_dump_template) {
  5078. ql_log(ql_log_warn, vha, 0x017a,
  5079. "Failed fwdump template allocate %x bytes.\n", risc_size);
  5080. goto failed_template;
  5081. }
  5082. dcode = ha->fw_dump_template;
  5083. risc_size = dlen / sizeof(*fwcode);
  5084. fwcode = qla27xx_fwdt_template_default();
  5085. for (i = 0; i < risc_size; i++)
  5086. dcode[i] = be32_to_cpu(fwcode[i]);
  5087. if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
  5088. ql_log(ql_log_warn, vha, 0x017b,
  5089. "Failed fwdump template validate\n");
  5090. goto failed_template;
  5091. }
  5092. dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
  5093. ql_dbg(ql_dbg_init, vha, 0x017c,
  5094. "-> template size %x bytes\n", dlen);
  5095. ha->fw_dump_template_len = dlen;
  5096. return rval;
  5097. failed_template:
  5098. ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
  5099. if (ha->fw_dump_template)
  5100. vfree(ha->fw_dump_template);
  5101. ha->fw_dump_template = NULL;
  5102. ha->fw_dump_template_len = 0;
  5103. return rval;
  5104. }
  5105. int
  5106. qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  5107. {
  5108. int rval;
  5109. if (ql2xfwloadbin == 1)
  5110. return qla81xx_load_risc(vha, srisc_addr);
  5111. /*
  5112. * FW Load priority:
  5113. * 1) Firmware via request-firmware interface (.bin file).
  5114. * 2) Firmware residing in flash.
  5115. */
  5116. rval = qla24xx_load_risc_blob(vha, srisc_addr);
  5117. if (rval == QLA_SUCCESS)
  5118. return rval;
  5119. return qla24xx_load_risc_flash(vha, srisc_addr,
  5120. vha->hw->flt_region_fw);
  5121. }
  5122. int
  5123. qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  5124. {
  5125. int rval;
  5126. struct qla_hw_data *ha = vha->hw;
  5127. if (ql2xfwloadbin == 2)
  5128. goto try_blob_fw;
  5129. /*
  5130. * FW Load priority:
  5131. * 1) Firmware residing in flash.
  5132. * 2) Firmware via request-firmware interface (.bin file).
  5133. * 3) Golden-Firmware residing in flash -- limited operation.
  5134. */
  5135. rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
  5136. if (rval == QLA_SUCCESS)
  5137. return rval;
  5138. try_blob_fw:
  5139. rval = qla24xx_load_risc_blob(vha, srisc_addr);
  5140. if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
  5141. return rval;
  5142. ql_log(ql_log_info, vha, 0x0099,
  5143. "Attempting to fallback to golden firmware.\n");
  5144. rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
  5145. if (rval != QLA_SUCCESS)
  5146. return rval;
  5147. ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
  5148. ha->flags.running_gold_fw = 1;
  5149. return rval;
  5150. }
  5151. void
  5152. qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
  5153. {
  5154. int ret, retries;
  5155. struct qla_hw_data *ha = vha->hw;
  5156. if (ha->flags.pci_channel_io_perm_failure)
  5157. return;
  5158. if (!IS_FWI2_CAPABLE(ha))
  5159. return;
  5160. if (!ha->fw_major_version)
  5161. return;
  5162. ret = qla2x00_stop_firmware(vha);
  5163. for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
  5164. ret != QLA_INVALID_COMMAND && retries ; retries--) {
  5165. ha->isp_ops->reset_chip(vha);
  5166. if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
  5167. continue;
  5168. if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
  5169. continue;
  5170. ql_log(ql_log_info, vha, 0x8015,
  5171. "Attempting retry of stop-firmware command.\n");
  5172. ret = qla2x00_stop_firmware(vha);
  5173. }
  5174. }
  5175. int
  5176. qla24xx_configure_vhba(scsi_qla_host_t *vha)
  5177. {
  5178. int rval = QLA_SUCCESS;
  5179. int rval2;
  5180. uint16_t mb[MAILBOX_REGISTER_COUNT];
  5181. struct qla_hw_data *ha = vha->hw;
  5182. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  5183. struct req_que *req;
  5184. struct rsp_que *rsp;
  5185. if (!vha->vp_idx)
  5186. return -EINVAL;
  5187. rval = qla2x00_fw_ready(base_vha);
  5188. if (ha->flags.cpu_affinity_enabled)
  5189. req = ha->req_q_map[0];
  5190. else
  5191. req = vha->req;
  5192. rsp = req->rsp;
  5193. if (rval == QLA_SUCCESS) {
  5194. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  5195. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  5196. }
  5197. vha->flags.management_server_logged_in = 0;
  5198. /* Login to SNS first */
  5199. rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
  5200. BIT_1);
  5201. if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
  5202. if (rval2 == QLA_MEMORY_ALLOC_FAILED)
  5203. ql_dbg(ql_dbg_init, vha, 0x0120,
  5204. "Failed SNS login: loop_id=%x, rval2=%d\n",
  5205. NPH_SNS, rval2);
  5206. else
  5207. ql_dbg(ql_dbg_init, vha, 0x0103,
  5208. "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
  5209. "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
  5210. NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
  5211. return (QLA_FUNCTION_FAILED);
  5212. }
  5213. atomic_set(&vha->loop_down_timer, 0);
  5214. atomic_set(&vha->loop_state, LOOP_UP);
  5215. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  5216. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  5217. rval = qla2x00_loop_resync(base_vha);
  5218. return rval;
  5219. }
  5220. /* 84XX Support **************************************************************/
  5221. static LIST_HEAD(qla_cs84xx_list);
  5222. static DEFINE_MUTEX(qla_cs84xx_mutex);
  5223. static struct qla_chip_state_84xx *
  5224. qla84xx_get_chip(struct scsi_qla_host *vha)
  5225. {
  5226. struct qla_chip_state_84xx *cs84xx;
  5227. struct qla_hw_data *ha = vha->hw;
  5228. mutex_lock(&qla_cs84xx_mutex);
  5229. /* Find any shared 84xx chip. */
  5230. list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
  5231. if (cs84xx->bus == ha->pdev->bus) {
  5232. kref_get(&cs84xx->kref);
  5233. goto done;
  5234. }
  5235. }
  5236. cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
  5237. if (!cs84xx)
  5238. goto done;
  5239. kref_init(&cs84xx->kref);
  5240. spin_lock_init(&cs84xx->access_lock);
  5241. mutex_init(&cs84xx->fw_update_mutex);
  5242. cs84xx->bus = ha->pdev->bus;
  5243. list_add_tail(&cs84xx->list, &qla_cs84xx_list);
  5244. done:
  5245. mutex_unlock(&qla_cs84xx_mutex);
  5246. return cs84xx;
  5247. }
  5248. static void
  5249. __qla84xx_chip_release(struct kref *kref)
  5250. {
  5251. struct qla_chip_state_84xx *cs84xx =
  5252. container_of(kref, struct qla_chip_state_84xx, kref);
  5253. mutex_lock(&qla_cs84xx_mutex);
  5254. list_del(&cs84xx->list);
  5255. mutex_unlock(&qla_cs84xx_mutex);
  5256. kfree(cs84xx);
  5257. }
  5258. void
  5259. qla84xx_put_chip(struct scsi_qla_host *vha)
  5260. {
  5261. struct qla_hw_data *ha = vha->hw;
  5262. if (ha->cs84xx)
  5263. kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
  5264. }
  5265. static int
  5266. qla84xx_init_chip(scsi_qla_host_t *vha)
  5267. {
  5268. int rval;
  5269. uint16_t status[2];
  5270. struct qla_hw_data *ha = vha->hw;
  5271. mutex_lock(&ha->cs84xx->fw_update_mutex);
  5272. rval = qla84xx_verify_chip(vha, status);
  5273. mutex_unlock(&ha->cs84xx->fw_update_mutex);
  5274. return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
  5275. QLA_SUCCESS;
  5276. }
  5277. /* 81XX Support **************************************************************/
  5278. int
  5279. qla81xx_nvram_config(scsi_qla_host_t *vha)
  5280. {
  5281. int rval;
  5282. struct init_cb_81xx *icb;
  5283. struct nvram_81xx *nv;
  5284. uint32_t *dptr;
  5285. uint8_t *dptr1, *dptr2;
  5286. uint32_t chksum;
  5287. uint16_t cnt;
  5288. struct qla_hw_data *ha = vha->hw;
  5289. rval = QLA_SUCCESS;
  5290. icb = (struct init_cb_81xx *)ha->init_cb;
  5291. nv = ha->nvram;
  5292. /* Determine NVRAM starting address. */
  5293. ha->nvram_size = sizeof(struct nvram_81xx);
  5294. ha->vpd_size = FA_NVRAM_VPD_SIZE;
  5295. if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
  5296. ha->vpd_size = FA_VPD_SIZE_82XX;
  5297. /* Get VPD data into cache */
  5298. ha->vpd = ha->nvram + VPD_OFFSET;
  5299. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  5300. ha->vpd_size);
  5301. /* Get NVRAM data into cache and calculate checksum. */
  5302. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  5303. ha->nvram_size);
  5304. dptr = (uint32_t *)nv;
  5305. for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
  5306. chksum += le32_to_cpu(*dptr);
  5307. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
  5308. "Contents of NVRAM:\n");
  5309. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
  5310. (uint8_t *)nv, ha->nvram_size);
  5311. /* Bad NVRAM data, set defaults parameters. */
  5312. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
  5313. || nv->id[3] != ' ' ||
  5314. nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
  5315. /* Reset NVRAM data. */
  5316. ql_log(ql_log_info, vha, 0x0073,
  5317. "Inconsistent NVRAM detected: checksum=0x%x id=%c "
  5318. "version=0x%x.\n", chksum, nv->id[0],
  5319. le16_to_cpu(nv->nvram_version));
  5320. ql_log(ql_log_info, vha, 0x0074,
  5321. "Falling back to functioning (yet invalid -- WWPN) "
  5322. "defaults.\n");
  5323. /*
  5324. * Set default initialization control block.
  5325. */
  5326. memset(nv, 0, ha->nvram_size);
  5327. nv->nvram_version = cpu_to_le16(ICB_VERSION);
  5328. nv->version = cpu_to_le16(ICB_VERSION);
  5329. nv->frame_payload_size = 2048;
  5330. nv->execution_throttle = cpu_to_le16(0xFFFF);
  5331. nv->exchange_count = cpu_to_le16(0);
  5332. nv->port_name[0] = 0x21;
  5333. nv->port_name[1] = 0x00 + ha->port_no + 1;
  5334. nv->port_name[2] = 0x00;
  5335. nv->port_name[3] = 0xe0;
  5336. nv->port_name[4] = 0x8b;
  5337. nv->port_name[5] = 0x1c;
  5338. nv->port_name[6] = 0x55;
  5339. nv->port_name[7] = 0x86;
  5340. nv->node_name[0] = 0x20;
  5341. nv->node_name[1] = 0x00;
  5342. nv->node_name[2] = 0x00;
  5343. nv->node_name[3] = 0xe0;
  5344. nv->node_name[4] = 0x8b;
  5345. nv->node_name[5] = 0x1c;
  5346. nv->node_name[6] = 0x55;
  5347. nv->node_name[7] = 0x86;
  5348. nv->login_retry_count = cpu_to_le16(8);
  5349. nv->interrupt_delay_timer = cpu_to_le16(0);
  5350. nv->login_timeout = cpu_to_le16(0);
  5351. nv->firmware_options_1 =
  5352. cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
  5353. nv->firmware_options_2 = cpu_to_le32(2 << 4);
  5354. nv->firmware_options_2 |= cpu_to_le32(BIT_12);
  5355. nv->firmware_options_3 = cpu_to_le32(2 << 13);
  5356. nv->host_p = cpu_to_le32(BIT_11|BIT_10);
  5357. nv->efi_parameters = cpu_to_le32(0);
  5358. nv->reset_delay = 5;
  5359. nv->max_luns_per_target = cpu_to_le16(128);
  5360. nv->port_down_retry_count = cpu_to_le16(30);
  5361. nv->link_down_timeout = cpu_to_le16(180);
  5362. nv->enode_mac[0] = 0x00;
  5363. nv->enode_mac[1] = 0xC0;
  5364. nv->enode_mac[2] = 0xDD;
  5365. nv->enode_mac[3] = 0x04;
  5366. nv->enode_mac[4] = 0x05;
  5367. nv->enode_mac[5] = 0x06 + ha->port_no + 1;
  5368. rval = 1;
  5369. }
  5370. if (IS_T10_PI_CAPABLE(ha))
  5371. nv->frame_payload_size &= ~7;
  5372. qlt_81xx_config_nvram_stage1(vha, nv);
  5373. /* Reset Initialization control block */
  5374. memset(icb, 0, ha->init_cb_size);
  5375. /* Copy 1st segment. */
  5376. dptr1 = (uint8_t *)icb;
  5377. dptr2 = (uint8_t *)&nv->version;
  5378. cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
  5379. while (cnt--)
  5380. *dptr1++ = *dptr2++;
  5381. icb->login_retry_count = nv->login_retry_count;
  5382. /* Copy 2nd segment. */
  5383. dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
  5384. dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
  5385. cnt = (uint8_t *)&icb->reserved_5 -
  5386. (uint8_t *)&icb->interrupt_delay_timer;
  5387. while (cnt--)
  5388. *dptr1++ = *dptr2++;
  5389. memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
  5390. /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
  5391. if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
  5392. icb->enode_mac[0] = 0x00;
  5393. icb->enode_mac[1] = 0xC0;
  5394. icb->enode_mac[2] = 0xDD;
  5395. icb->enode_mac[3] = 0x04;
  5396. icb->enode_mac[4] = 0x05;
  5397. icb->enode_mac[5] = 0x06 + ha->port_no + 1;
  5398. }
  5399. /* Use extended-initialization control block. */
  5400. memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
  5401. /*
  5402. * Setup driver NVRAM options.
  5403. */
  5404. qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
  5405. "QLE8XXX");
  5406. qlt_81xx_config_nvram_stage2(vha, icb);
  5407. /* Use alternate WWN? */
  5408. if (nv->host_p & cpu_to_le32(BIT_15)) {
  5409. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  5410. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  5411. }
  5412. /* Prepare nodename */
  5413. if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
  5414. /*
  5415. * Firmware will apply the following mask if the nodename was
  5416. * not provided.
  5417. */
  5418. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  5419. icb->node_name[0] &= 0xF0;
  5420. }
  5421. /* Set host adapter parameters. */
  5422. ha->flags.disable_risc_code_load = 0;
  5423. ha->flags.enable_lip_reset = 0;
  5424. ha->flags.enable_lip_full_login =
  5425. le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
  5426. ha->flags.enable_target_reset =
  5427. le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
  5428. ha->flags.enable_led_scheme = 0;
  5429. ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
  5430. ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
  5431. (BIT_6 | BIT_5 | BIT_4)) >> 4;
  5432. /* save HBA serial number */
  5433. ha->serial0 = icb->port_name[5];
  5434. ha->serial1 = icb->port_name[6];
  5435. ha->serial2 = icb->port_name[7];
  5436. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  5437. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  5438. icb->execution_throttle = cpu_to_le16(0xFFFF);
  5439. ha->retry_count = le16_to_cpu(nv->login_retry_count);
  5440. /* Set minimum login_timeout to 4 seconds. */
  5441. if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
  5442. nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
  5443. if (le16_to_cpu(nv->login_timeout) < 4)
  5444. nv->login_timeout = cpu_to_le16(4);
  5445. ha->login_timeout = le16_to_cpu(nv->login_timeout);
  5446. /* Set minimum RATOV to 100 tenths of a second. */
  5447. ha->r_a_tov = 100;
  5448. ha->loop_reset_delay = nv->reset_delay;
  5449. /* Link Down Timeout = 0:
  5450. *
  5451. * When Port Down timer expires we will start returning
  5452. * I/O's to OS with "DID_NO_CONNECT".
  5453. *
  5454. * Link Down Timeout != 0:
  5455. *
  5456. * The driver waits for the link to come up after link down
  5457. * before returning I/Os to OS with "DID_NO_CONNECT".
  5458. */
  5459. if (le16_to_cpu(nv->link_down_timeout) == 0) {
  5460. ha->loop_down_abort_time =
  5461. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  5462. } else {
  5463. ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
  5464. ha->loop_down_abort_time =
  5465. (LOOP_DOWN_TIME - ha->link_down_timeout);
  5466. }
  5467. /* Need enough time to try and get the port back. */
  5468. ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
  5469. if (qlport_down_retry)
  5470. ha->port_down_retry_count = qlport_down_retry;
  5471. /* Set login_retry_count */
  5472. ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
  5473. if (ha->port_down_retry_count ==
  5474. le16_to_cpu(nv->port_down_retry_count) &&
  5475. ha->port_down_retry_count > 3)
  5476. ha->login_retry_count = ha->port_down_retry_count;
  5477. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  5478. ha->login_retry_count = ha->port_down_retry_count;
  5479. if (ql2xloginretrycount)
  5480. ha->login_retry_count = ql2xloginretrycount;
  5481. /* if not running MSI-X we need handshaking on interrupts */
  5482. if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
  5483. icb->firmware_options_2 |= cpu_to_le32(BIT_22);
  5484. /* Enable ZIO. */
  5485. if (!vha->flags.init_done) {
  5486. ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
  5487. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  5488. ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
  5489. le16_to_cpu(icb->interrupt_delay_timer): 2;
  5490. }
  5491. icb->firmware_options_2 &= cpu_to_le32(
  5492. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
  5493. vha->flags.process_response_queue = 0;
  5494. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  5495. ha->zio_mode = QLA_ZIO_MODE_6;
  5496. ql_log(ql_log_info, vha, 0x0075,
  5497. "ZIO mode %d enabled; timer delay (%d us).\n",
  5498. ha->zio_mode,
  5499. ha->zio_timer * 100);
  5500. icb->firmware_options_2 |= cpu_to_le32(
  5501. (uint32_t)ha->zio_mode);
  5502. icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
  5503. vha->flags.process_response_queue = 1;
  5504. }
  5505. if (rval) {
  5506. ql_log(ql_log_warn, vha, 0x0076,
  5507. "NVRAM configuration failed.\n");
  5508. }
  5509. return (rval);
  5510. }
  5511. int
  5512. qla82xx_restart_isp(scsi_qla_host_t *vha)
  5513. {
  5514. int status, rval;
  5515. struct qla_hw_data *ha = vha->hw;
  5516. struct req_que *req = ha->req_q_map[0];
  5517. struct rsp_que *rsp = ha->rsp_q_map[0];
  5518. struct scsi_qla_host *vp;
  5519. unsigned long flags;
  5520. status = qla2x00_init_rings(vha);
  5521. if (!status) {
  5522. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  5523. ha->flags.chip_reset_done = 1;
  5524. status = qla2x00_fw_ready(vha);
  5525. if (!status) {
  5526. /* Issue a marker after FW becomes ready. */
  5527. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  5528. vha->flags.online = 1;
  5529. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  5530. }
  5531. /* if no cable then assume it's good */
  5532. if ((vha->device_flags & DFLG_NO_CABLE))
  5533. status = 0;
  5534. }
  5535. if (!status) {
  5536. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  5537. if (!atomic_read(&vha->loop_down_timer)) {
  5538. /*
  5539. * Issue marker command only when we are going
  5540. * to start the I/O .
  5541. */
  5542. vha->marker_needed = 1;
  5543. }
  5544. ha->isp_ops->enable_intrs(ha);
  5545. ha->isp_abort_cnt = 0;
  5546. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  5547. /* Update the firmware version */
  5548. status = qla82xx_check_md_needed(vha);
  5549. if (ha->fce) {
  5550. ha->flags.fce_enabled = 1;
  5551. memset(ha->fce, 0,
  5552. fce_calc_size(ha->fce_bufs));
  5553. rval = qla2x00_enable_fce_trace(vha,
  5554. ha->fce_dma, ha->fce_bufs, ha->fce_mb,
  5555. &ha->fce_bufs);
  5556. if (rval) {
  5557. ql_log(ql_log_warn, vha, 0x8001,
  5558. "Unable to reinitialize FCE (%d).\n",
  5559. rval);
  5560. ha->flags.fce_enabled = 0;
  5561. }
  5562. }
  5563. if (ha->eft) {
  5564. memset(ha->eft, 0, EFT_SIZE);
  5565. rval = qla2x00_enable_eft_trace(vha,
  5566. ha->eft_dma, EFT_NUM_BUFFERS);
  5567. if (rval) {
  5568. ql_log(ql_log_warn, vha, 0x8010,
  5569. "Unable to reinitialize EFT (%d).\n",
  5570. rval);
  5571. }
  5572. }
  5573. }
  5574. if (!status) {
  5575. ql_dbg(ql_dbg_taskm, vha, 0x8011,
  5576. "qla82xx_restart_isp succeeded.\n");
  5577. spin_lock_irqsave(&ha->vport_slock, flags);
  5578. list_for_each_entry(vp, &ha->vp_list, list) {
  5579. if (vp->vp_idx) {
  5580. atomic_inc(&vp->vref_count);
  5581. spin_unlock_irqrestore(&ha->vport_slock, flags);
  5582. qla2x00_vp_abort_isp(vp);
  5583. spin_lock_irqsave(&ha->vport_slock, flags);
  5584. atomic_dec(&vp->vref_count);
  5585. }
  5586. }
  5587. spin_unlock_irqrestore(&ha->vport_slock, flags);
  5588. } else {
  5589. ql_log(ql_log_warn, vha, 0x8016,
  5590. "qla82xx_restart_isp **** FAILED ****.\n");
  5591. }
  5592. return status;
  5593. }
  5594. void
  5595. qla81xx_update_fw_options(scsi_qla_host_t *vha)
  5596. {
  5597. struct qla_hw_data *ha = vha->hw;
  5598. /* Hold status IOCBs until ABTS response received. */
  5599. if (ql2xfwholdabts)
  5600. ha->fw_options[3] |= BIT_12;
  5601. /* Set Retry FLOGI in case of P2P connection */
  5602. if (ha->operating_mode == P2P) {
  5603. ha->fw_options[2] |= BIT_3;
  5604. ql_dbg(ql_dbg_disc, vha, 0x2103,
  5605. "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
  5606. __func__, ha->fw_options[2]);
  5607. }
  5608. if (!ql2xetsenable)
  5609. goto out;
  5610. /* Enable ETS Burst. */
  5611. memset(ha->fw_options, 0, sizeof(ha->fw_options));
  5612. ha->fw_options[2] |= BIT_9;
  5613. out:
  5614. qla2x00_set_fw_options(vha, ha->fw_options);
  5615. }
  5616. /*
  5617. * qla24xx_get_fcp_prio
  5618. * Gets the fcp cmd priority value for the logged in port.
  5619. * Looks for a match of the port descriptors within
  5620. * each of the fcp prio config entries. If a match is found,
  5621. * the tag (priority) value is returned.
  5622. *
  5623. * Input:
  5624. * vha = scsi host structure pointer.
  5625. * fcport = port structure pointer.
  5626. *
  5627. * Return:
  5628. * non-zero (if found)
  5629. * -1 (if not found)
  5630. *
  5631. * Context:
  5632. * Kernel context
  5633. */
  5634. static int
  5635. qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
  5636. {
  5637. int i, entries;
  5638. uint8_t pid_match, wwn_match;
  5639. int priority;
  5640. uint32_t pid1, pid2;
  5641. uint64_t wwn1, wwn2;
  5642. struct qla_fcp_prio_entry *pri_entry;
  5643. struct qla_hw_data *ha = vha->hw;
  5644. if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
  5645. return -1;
  5646. priority = -1;
  5647. entries = ha->fcp_prio_cfg->num_entries;
  5648. pri_entry = &ha->fcp_prio_cfg->entry[0];
  5649. for (i = 0; i < entries; i++) {
  5650. pid_match = wwn_match = 0;
  5651. if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
  5652. pri_entry++;
  5653. continue;
  5654. }
  5655. /* check source pid for a match */
  5656. if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
  5657. pid1 = pri_entry->src_pid & INVALID_PORT_ID;
  5658. pid2 = vha->d_id.b24 & INVALID_PORT_ID;
  5659. if (pid1 == INVALID_PORT_ID)
  5660. pid_match++;
  5661. else if (pid1 == pid2)
  5662. pid_match++;
  5663. }
  5664. /* check destination pid for a match */
  5665. if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
  5666. pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
  5667. pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
  5668. if (pid1 == INVALID_PORT_ID)
  5669. pid_match++;
  5670. else if (pid1 == pid2)
  5671. pid_match++;
  5672. }
  5673. /* check source WWN for a match */
  5674. if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
  5675. wwn1 = wwn_to_u64(vha->port_name);
  5676. wwn2 = wwn_to_u64(pri_entry->src_wwpn);
  5677. if (wwn2 == (uint64_t)-1)
  5678. wwn_match++;
  5679. else if (wwn1 == wwn2)
  5680. wwn_match++;
  5681. }
  5682. /* check destination WWN for a match */
  5683. if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
  5684. wwn1 = wwn_to_u64(fcport->port_name);
  5685. wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
  5686. if (wwn2 == (uint64_t)-1)
  5687. wwn_match++;
  5688. else if (wwn1 == wwn2)
  5689. wwn_match++;
  5690. }
  5691. if (pid_match == 2 || wwn_match == 2) {
  5692. /* Found a matching entry */
  5693. if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
  5694. priority = pri_entry->tag;
  5695. break;
  5696. }
  5697. pri_entry++;
  5698. }
  5699. return priority;
  5700. }
  5701. /*
  5702. * qla24xx_update_fcport_fcp_prio
  5703. * Activates fcp priority for the logged in fc port
  5704. *
  5705. * Input:
  5706. * vha = scsi host structure pointer.
  5707. * fcp = port structure pointer.
  5708. *
  5709. * Return:
  5710. * QLA_SUCCESS or QLA_FUNCTION_FAILED
  5711. *
  5712. * Context:
  5713. * Kernel context.
  5714. */
  5715. int
  5716. qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
  5717. {
  5718. int ret;
  5719. int priority;
  5720. uint16_t mb[5];
  5721. if (fcport->port_type != FCT_TARGET ||
  5722. fcport->loop_id == FC_NO_LOOP_ID)
  5723. return QLA_FUNCTION_FAILED;
  5724. priority = qla24xx_get_fcp_prio(vha, fcport);
  5725. if (priority < 0)
  5726. return QLA_FUNCTION_FAILED;
  5727. if (IS_P3P_TYPE(vha->hw)) {
  5728. fcport->fcp_prio = priority & 0xf;
  5729. return QLA_SUCCESS;
  5730. }
  5731. ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
  5732. if (ret == QLA_SUCCESS) {
  5733. if (fcport->fcp_prio != priority)
  5734. ql_dbg(ql_dbg_user, vha, 0x709e,
  5735. "Updated FCP_CMND priority - value=%d loop_id=%d "
  5736. "port_id=%02x%02x%02x.\n", priority,
  5737. fcport->loop_id, fcport->d_id.b.domain,
  5738. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  5739. fcport->fcp_prio = priority & 0xf;
  5740. } else
  5741. ql_dbg(ql_dbg_user, vha, 0x704f,
  5742. "Unable to update FCP_CMND priority - ret=0x%x for "
  5743. "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
  5744. fcport->d_id.b.domain, fcport->d_id.b.area,
  5745. fcport->d_id.b.al_pa);
  5746. return ret;
  5747. }
  5748. /*
  5749. * qla24xx_update_all_fcp_prio
  5750. * Activates fcp priority for all the logged in ports
  5751. *
  5752. * Input:
  5753. * ha = adapter block pointer.
  5754. *
  5755. * Return:
  5756. * QLA_SUCCESS or QLA_FUNCTION_FAILED
  5757. *
  5758. * Context:
  5759. * Kernel context.
  5760. */
  5761. int
  5762. qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
  5763. {
  5764. int ret;
  5765. fc_port_t *fcport;
  5766. ret = QLA_FUNCTION_FAILED;
  5767. /* We need to set priority for all logged in ports */
  5768. list_for_each_entry(fcport, &vha->vp_fcports, list)
  5769. ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
  5770. return ret;
  5771. }