qla_init.c 159 KB

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