qla_init.c 156 KB

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