qla_init.c 175 KB

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