qla_init.c 157 KB

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