ql4_nx.c 115 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2013 QLogic Corporation
  4. *
  5. * See LICENSE.qla4xxx for copyright and licensing details.
  6. */
  7. #include <linux/delay.h>
  8. #include <linux/io.h>
  9. #include <linux/pci.h>
  10. #include <linux/ratelimit.h>
  11. #include "ql4_def.h"
  12. #include "ql4_glbl.h"
  13. #include "ql4_inline.h"
  14. #include <linux/io-64-nonatomic-lo-hi.h>
  15. #define TIMEOUT_100_MS 100
  16. #define MASK(n) DMA_BIT_MASK(n)
  17. #define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff))
  18. #define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff))
  19. #define MS_WIN(addr) (addr & 0x0ffc0000)
  20. #define QLA82XX_PCI_MN_2M (0)
  21. #define QLA82XX_PCI_MS_2M (0x80000)
  22. #define QLA82XX_PCI_OCM0_2M (0xc0000)
  23. #define VALID_OCM_ADDR(addr) (((addr) & 0x3f800) != 0x3f800)
  24. #define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
  25. /* CRB window related */
  26. #define CRB_BLK(off) ((off >> 20) & 0x3f)
  27. #define CRB_SUBBLK(off) ((off >> 16) & 0xf)
  28. #define CRB_WINDOW_2M (0x130060)
  29. #define CRB_HI(off) ((qla4_82xx_crb_hub_agt[CRB_BLK(off)] << 20) | \
  30. ((off) & 0xf0000))
  31. #define QLA82XX_PCI_CAMQM_2M_END (0x04800800UL)
  32. #define QLA82XX_PCI_CAMQM_2M_BASE (0x000ff800UL)
  33. #define CRB_INDIRECT_2M (0x1e0000UL)
  34. static inline void __iomem *
  35. qla4_8xxx_pci_base_offsetfset(struct scsi_qla_host *ha, unsigned long off)
  36. {
  37. if ((off < ha->first_page_group_end) &&
  38. (off >= ha->first_page_group_start))
  39. return (void __iomem *)(ha->nx_pcibase + off);
  40. return NULL;
  41. }
  42. static const int MD_MIU_TEST_AGT_RDDATA[] = { 0x410000A8,
  43. 0x410000AC, 0x410000B8, 0x410000BC };
  44. #define MAX_CRB_XFORM 60
  45. static unsigned long crb_addr_xform[MAX_CRB_XFORM];
  46. static int qla4_8xxx_crb_table_initialized;
  47. #define qla4_8xxx_crb_addr_transform(name) \
  48. (crb_addr_xform[QLA82XX_HW_PX_MAP_CRB_##name] = \
  49. QLA82XX_HW_CRB_HUB_AGT_ADR_##name << 20)
  50. static void
  51. qla4_82xx_crb_addr_transform_setup(void)
  52. {
  53. qla4_8xxx_crb_addr_transform(XDMA);
  54. qla4_8xxx_crb_addr_transform(TIMR);
  55. qla4_8xxx_crb_addr_transform(SRE);
  56. qla4_8xxx_crb_addr_transform(SQN3);
  57. qla4_8xxx_crb_addr_transform(SQN2);
  58. qla4_8xxx_crb_addr_transform(SQN1);
  59. qla4_8xxx_crb_addr_transform(SQN0);
  60. qla4_8xxx_crb_addr_transform(SQS3);
  61. qla4_8xxx_crb_addr_transform(SQS2);
  62. qla4_8xxx_crb_addr_transform(SQS1);
  63. qla4_8xxx_crb_addr_transform(SQS0);
  64. qla4_8xxx_crb_addr_transform(RPMX7);
  65. qla4_8xxx_crb_addr_transform(RPMX6);
  66. qla4_8xxx_crb_addr_transform(RPMX5);
  67. qla4_8xxx_crb_addr_transform(RPMX4);
  68. qla4_8xxx_crb_addr_transform(RPMX3);
  69. qla4_8xxx_crb_addr_transform(RPMX2);
  70. qla4_8xxx_crb_addr_transform(RPMX1);
  71. qla4_8xxx_crb_addr_transform(RPMX0);
  72. qla4_8xxx_crb_addr_transform(ROMUSB);
  73. qla4_8xxx_crb_addr_transform(SN);
  74. qla4_8xxx_crb_addr_transform(QMN);
  75. qla4_8xxx_crb_addr_transform(QMS);
  76. qla4_8xxx_crb_addr_transform(PGNI);
  77. qla4_8xxx_crb_addr_transform(PGND);
  78. qla4_8xxx_crb_addr_transform(PGN3);
  79. qla4_8xxx_crb_addr_transform(PGN2);
  80. qla4_8xxx_crb_addr_transform(PGN1);
  81. qla4_8xxx_crb_addr_transform(PGN0);
  82. qla4_8xxx_crb_addr_transform(PGSI);
  83. qla4_8xxx_crb_addr_transform(PGSD);
  84. qla4_8xxx_crb_addr_transform(PGS3);
  85. qla4_8xxx_crb_addr_transform(PGS2);
  86. qla4_8xxx_crb_addr_transform(PGS1);
  87. qla4_8xxx_crb_addr_transform(PGS0);
  88. qla4_8xxx_crb_addr_transform(PS);
  89. qla4_8xxx_crb_addr_transform(PH);
  90. qla4_8xxx_crb_addr_transform(NIU);
  91. qla4_8xxx_crb_addr_transform(I2Q);
  92. qla4_8xxx_crb_addr_transform(EG);
  93. qla4_8xxx_crb_addr_transform(MN);
  94. qla4_8xxx_crb_addr_transform(MS);
  95. qla4_8xxx_crb_addr_transform(CAS2);
  96. qla4_8xxx_crb_addr_transform(CAS1);
  97. qla4_8xxx_crb_addr_transform(CAS0);
  98. qla4_8xxx_crb_addr_transform(CAM);
  99. qla4_8xxx_crb_addr_transform(C2C1);
  100. qla4_8xxx_crb_addr_transform(C2C0);
  101. qla4_8xxx_crb_addr_transform(SMB);
  102. qla4_8xxx_crb_addr_transform(OCM0);
  103. qla4_8xxx_crb_addr_transform(I2C0);
  104. qla4_8xxx_crb_table_initialized = 1;
  105. }
  106. static struct crb_128M_2M_block_map crb_128M_2M_map[64] = {
  107. {{{0, 0, 0, 0} } }, /* 0: PCI */
  108. {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */
  109. {1, 0x0110000, 0x0120000, 0x130000},
  110. {1, 0x0120000, 0x0122000, 0x124000},
  111. {1, 0x0130000, 0x0132000, 0x126000},
  112. {1, 0x0140000, 0x0142000, 0x128000},
  113. {1, 0x0150000, 0x0152000, 0x12a000},
  114. {1, 0x0160000, 0x0170000, 0x110000},
  115. {1, 0x0170000, 0x0172000, 0x12e000},
  116. {0, 0x0000000, 0x0000000, 0x000000},
  117. {0, 0x0000000, 0x0000000, 0x000000},
  118. {0, 0x0000000, 0x0000000, 0x000000},
  119. {0, 0x0000000, 0x0000000, 0x000000},
  120. {0, 0x0000000, 0x0000000, 0x000000},
  121. {0, 0x0000000, 0x0000000, 0x000000},
  122. {1, 0x01e0000, 0x01e0800, 0x122000},
  123. {0, 0x0000000, 0x0000000, 0x000000} } },
  124. {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */
  125. {{{0, 0, 0, 0} } }, /* 3: */
  126. {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */
  127. {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */
  128. {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */
  129. {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */
  130. {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */
  131. {0, 0x0000000, 0x0000000, 0x000000},
  132. {0, 0x0000000, 0x0000000, 0x000000},
  133. {0, 0x0000000, 0x0000000, 0x000000},
  134. {0, 0x0000000, 0x0000000, 0x000000},
  135. {0, 0x0000000, 0x0000000, 0x000000},
  136. {0, 0x0000000, 0x0000000, 0x000000},
  137. {0, 0x0000000, 0x0000000, 0x000000},
  138. {0, 0x0000000, 0x0000000, 0x000000},
  139. {0, 0x0000000, 0x0000000, 0x000000},
  140. {0, 0x0000000, 0x0000000, 0x000000},
  141. {0, 0x0000000, 0x0000000, 0x000000},
  142. {0, 0x0000000, 0x0000000, 0x000000},
  143. {0, 0x0000000, 0x0000000, 0x000000},
  144. {0, 0x0000000, 0x0000000, 0x000000},
  145. {1, 0x08f0000, 0x08f2000, 0x172000} } },
  146. {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/
  147. {0, 0x0000000, 0x0000000, 0x000000},
  148. {0, 0x0000000, 0x0000000, 0x000000},
  149. {0, 0x0000000, 0x0000000, 0x000000},
  150. {0, 0x0000000, 0x0000000, 0x000000},
  151. {0, 0x0000000, 0x0000000, 0x000000},
  152. {0, 0x0000000, 0x0000000, 0x000000},
  153. {0, 0x0000000, 0x0000000, 0x000000},
  154. {0, 0x0000000, 0x0000000, 0x000000},
  155. {0, 0x0000000, 0x0000000, 0x000000},
  156. {0, 0x0000000, 0x0000000, 0x000000},
  157. {0, 0x0000000, 0x0000000, 0x000000},
  158. {0, 0x0000000, 0x0000000, 0x000000},
  159. {0, 0x0000000, 0x0000000, 0x000000},
  160. {0, 0x0000000, 0x0000000, 0x000000},
  161. {1, 0x09f0000, 0x09f2000, 0x176000} } },
  162. {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/
  163. {0, 0x0000000, 0x0000000, 0x000000},
  164. {0, 0x0000000, 0x0000000, 0x000000},
  165. {0, 0x0000000, 0x0000000, 0x000000},
  166. {0, 0x0000000, 0x0000000, 0x000000},
  167. {0, 0x0000000, 0x0000000, 0x000000},
  168. {0, 0x0000000, 0x0000000, 0x000000},
  169. {0, 0x0000000, 0x0000000, 0x000000},
  170. {0, 0x0000000, 0x0000000, 0x000000},
  171. {0, 0x0000000, 0x0000000, 0x000000},
  172. {0, 0x0000000, 0x0000000, 0x000000},
  173. {0, 0x0000000, 0x0000000, 0x000000},
  174. {0, 0x0000000, 0x0000000, 0x000000},
  175. {0, 0x0000000, 0x0000000, 0x000000},
  176. {0, 0x0000000, 0x0000000, 0x000000},
  177. {1, 0x0af0000, 0x0af2000, 0x17a000} } },
  178. {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/
  179. {0, 0x0000000, 0x0000000, 0x000000},
  180. {0, 0x0000000, 0x0000000, 0x000000},
  181. {0, 0x0000000, 0x0000000, 0x000000},
  182. {0, 0x0000000, 0x0000000, 0x000000},
  183. {0, 0x0000000, 0x0000000, 0x000000},
  184. {0, 0x0000000, 0x0000000, 0x000000},
  185. {0, 0x0000000, 0x0000000, 0x000000},
  186. {0, 0x0000000, 0x0000000, 0x000000},
  187. {0, 0x0000000, 0x0000000, 0x000000},
  188. {0, 0x0000000, 0x0000000, 0x000000},
  189. {0, 0x0000000, 0x0000000, 0x000000},
  190. {0, 0x0000000, 0x0000000, 0x000000},
  191. {0, 0x0000000, 0x0000000, 0x000000},
  192. {0, 0x0000000, 0x0000000, 0x000000},
  193. {1, 0x0bf0000, 0x0bf2000, 0x17e000} } },
  194. {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */
  195. {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */
  196. {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */
  197. {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */
  198. {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */
  199. {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */
  200. {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */
  201. {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */
  202. {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */
  203. {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */
  204. {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */
  205. {{{0, 0, 0, 0} } }, /* 23: */
  206. {{{0, 0, 0, 0} } }, /* 24: */
  207. {{{0, 0, 0, 0} } }, /* 25: */
  208. {{{0, 0, 0, 0} } }, /* 26: */
  209. {{{0, 0, 0, 0} } }, /* 27: */
  210. {{{0, 0, 0, 0} } }, /* 28: */
  211. {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */
  212. {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */
  213. {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */
  214. {{{0} } }, /* 32: PCI */
  215. {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */
  216. {1, 0x2110000, 0x2120000, 0x130000},
  217. {1, 0x2120000, 0x2122000, 0x124000},
  218. {1, 0x2130000, 0x2132000, 0x126000},
  219. {1, 0x2140000, 0x2142000, 0x128000},
  220. {1, 0x2150000, 0x2152000, 0x12a000},
  221. {1, 0x2160000, 0x2170000, 0x110000},
  222. {1, 0x2170000, 0x2172000, 0x12e000},
  223. {0, 0x0000000, 0x0000000, 0x000000},
  224. {0, 0x0000000, 0x0000000, 0x000000},
  225. {0, 0x0000000, 0x0000000, 0x000000},
  226. {0, 0x0000000, 0x0000000, 0x000000},
  227. {0, 0x0000000, 0x0000000, 0x000000},
  228. {0, 0x0000000, 0x0000000, 0x000000},
  229. {0, 0x0000000, 0x0000000, 0x000000},
  230. {0, 0x0000000, 0x0000000, 0x000000} } },
  231. {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */
  232. {{{0} } }, /* 35: */
  233. {{{0} } }, /* 36: */
  234. {{{0} } }, /* 37: */
  235. {{{0} } }, /* 38: */
  236. {{{0} } }, /* 39: */
  237. {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */
  238. {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */
  239. {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */
  240. {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */
  241. {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */
  242. {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */
  243. {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */
  244. {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */
  245. {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */
  246. {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */
  247. {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */
  248. {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */
  249. {{{0} } }, /* 52: */
  250. {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */
  251. {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */
  252. {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */
  253. {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */
  254. {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */
  255. {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */
  256. {{{0} } }, /* 59: I2C0 */
  257. {{{0} } }, /* 60: I2C1 */
  258. {{{1, 0x3d00000, 0x3d04000, 0x1dc000} } },/* 61: LPC */
  259. {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */
  260. {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */
  261. };
  262. /*
  263. * top 12 bits of crb internal address (hub, agent)
  264. */
  265. static unsigned qla4_82xx_crb_hub_agt[64] = {
  266. 0,
  267. QLA82XX_HW_CRB_HUB_AGT_ADR_PS,
  268. QLA82XX_HW_CRB_HUB_AGT_ADR_MN,
  269. QLA82XX_HW_CRB_HUB_AGT_ADR_MS,
  270. 0,
  271. QLA82XX_HW_CRB_HUB_AGT_ADR_SRE,
  272. QLA82XX_HW_CRB_HUB_AGT_ADR_NIU,
  273. QLA82XX_HW_CRB_HUB_AGT_ADR_QMN,
  274. QLA82XX_HW_CRB_HUB_AGT_ADR_SQN0,
  275. QLA82XX_HW_CRB_HUB_AGT_ADR_SQN1,
  276. QLA82XX_HW_CRB_HUB_AGT_ADR_SQN2,
  277. QLA82XX_HW_CRB_HUB_AGT_ADR_SQN3,
  278. QLA82XX_HW_CRB_HUB_AGT_ADR_I2Q,
  279. QLA82XX_HW_CRB_HUB_AGT_ADR_TIMR,
  280. QLA82XX_HW_CRB_HUB_AGT_ADR_ROMUSB,
  281. QLA82XX_HW_CRB_HUB_AGT_ADR_PGN4,
  282. QLA82XX_HW_CRB_HUB_AGT_ADR_XDMA,
  283. QLA82XX_HW_CRB_HUB_AGT_ADR_PGN0,
  284. QLA82XX_HW_CRB_HUB_AGT_ADR_PGN1,
  285. QLA82XX_HW_CRB_HUB_AGT_ADR_PGN2,
  286. QLA82XX_HW_CRB_HUB_AGT_ADR_PGN3,
  287. QLA82XX_HW_CRB_HUB_AGT_ADR_PGND,
  288. QLA82XX_HW_CRB_HUB_AGT_ADR_PGNI,
  289. QLA82XX_HW_CRB_HUB_AGT_ADR_PGS0,
  290. QLA82XX_HW_CRB_HUB_AGT_ADR_PGS1,
  291. QLA82XX_HW_CRB_HUB_AGT_ADR_PGS2,
  292. QLA82XX_HW_CRB_HUB_AGT_ADR_PGS3,
  293. 0,
  294. QLA82XX_HW_CRB_HUB_AGT_ADR_PGSI,
  295. QLA82XX_HW_CRB_HUB_AGT_ADR_SN,
  296. 0,
  297. QLA82XX_HW_CRB_HUB_AGT_ADR_EG,
  298. 0,
  299. QLA82XX_HW_CRB_HUB_AGT_ADR_PS,
  300. QLA82XX_HW_CRB_HUB_AGT_ADR_CAM,
  301. 0,
  302. 0,
  303. 0,
  304. 0,
  305. 0,
  306. QLA82XX_HW_CRB_HUB_AGT_ADR_TIMR,
  307. 0,
  308. QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX1,
  309. QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX2,
  310. QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX3,
  311. QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX4,
  312. QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX5,
  313. QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX6,
  314. QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX7,
  315. QLA82XX_HW_CRB_HUB_AGT_ADR_XDMA,
  316. QLA82XX_HW_CRB_HUB_AGT_ADR_I2Q,
  317. QLA82XX_HW_CRB_HUB_AGT_ADR_ROMUSB,
  318. 0,
  319. QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX0,
  320. QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX8,
  321. QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX9,
  322. QLA82XX_HW_CRB_HUB_AGT_ADR_OCM0,
  323. 0,
  324. QLA82XX_HW_CRB_HUB_AGT_ADR_SMB,
  325. QLA82XX_HW_CRB_HUB_AGT_ADR_I2C0,
  326. QLA82XX_HW_CRB_HUB_AGT_ADR_I2C1,
  327. 0,
  328. QLA82XX_HW_CRB_HUB_AGT_ADR_PGNC,
  329. 0,
  330. };
  331. /* Device states */
  332. static char *qdev_state[] = {
  333. "Unknown",
  334. "Cold",
  335. "Initializing",
  336. "Ready",
  337. "Need Reset",
  338. "Need Quiescent",
  339. "Failed",
  340. "Quiescent",
  341. };
  342. /*
  343. * In: 'off' is offset from CRB space in 128M pci map
  344. * Out: 'off' is 2M pci map addr
  345. * side effect: lock crb window
  346. */
  347. static void
  348. qla4_82xx_pci_set_crbwindow_2M(struct scsi_qla_host *ha, ulong *off)
  349. {
  350. u32 win_read;
  351. ha->crb_win = CRB_HI(*off);
  352. writel(ha->crb_win,
  353. (void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase));
  354. /* Read back value to make sure write has gone through before trying
  355. * to use it. */
  356. win_read = readl((void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase));
  357. if (win_read != ha->crb_win) {
  358. DEBUG2(ql4_printk(KERN_INFO, ha,
  359. "%s: Written crbwin (0x%x) != Read crbwin (0x%x),"
  360. " off=0x%lx\n", __func__, ha->crb_win, win_read, *off));
  361. }
  362. *off = (*off & MASK(16)) + CRB_INDIRECT_2M + ha->nx_pcibase;
  363. }
  364. void
  365. qla4_82xx_wr_32(struct scsi_qla_host *ha, ulong off, u32 data)
  366. {
  367. unsigned long flags = 0;
  368. int rv;
  369. rv = qla4_82xx_pci_get_crb_addr_2M(ha, &off);
  370. BUG_ON(rv == -1);
  371. if (rv == 1) {
  372. write_lock_irqsave(&ha->hw_lock, flags);
  373. qla4_82xx_crb_win_lock(ha);
  374. qla4_82xx_pci_set_crbwindow_2M(ha, &off);
  375. }
  376. writel(data, (void __iomem *)off);
  377. if (rv == 1) {
  378. qla4_82xx_crb_win_unlock(ha);
  379. write_unlock_irqrestore(&ha->hw_lock, flags);
  380. }
  381. }
  382. uint32_t qla4_82xx_rd_32(struct scsi_qla_host *ha, ulong off)
  383. {
  384. unsigned long flags = 0;
  385. int rv;
  386. u32 data;
  387. rv = qla4_82xx_pci_get_crb_addr_2M(ha, &off);
  388. BUG_ON(rv == -1);
  389. if (rv == 1) {
  390. write_lock_irqsave(&ha->hw_lock, flags);
  391. qla4_82xx_crb_win_lock(ha);
  392. qla4_82xx_pci_set_crbwindow_2M(ha, &off);
  393. }
  394. data = readl((void __iomem *)off);
  395. if (rv == 1) {
  396. qla4_82xx_crb_win_unlock(ha);
  397. write_unlock_irqrestore(&ha->hw_lock, flags);
  398. }
  399. return data;
  400. }
  401. /* Minidump related functions */
  402. int qla4_82xx_md_rd_32(struct scsi_qla_host *ha, uint32_t off, uint32_t *data)
  403. {
  404. uint32_t win_read, off_value;
  405. int rval = QLA_SUCCESS;
  406. off_value = off & 0xFFFF0000;
  407. writel(off_value, (void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase));
  408. /*
  409. * Read back value to make sure write has gone through before trying
  410. * to use it.
  411. */
  412. win_read = readl((void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase));
  413. if (win_read != off_value) {
  414. DEBUG2(ql4_printk(KERN_INFO, ha,
  415. "%s: Written (0x%x) != Read (0x%x), off=0x%x\n",
  416. __func__, off_value, win_read, off));
  417. rval = QLA_ERROR;
  418. } else {
  419. off_value = off & 0x0000FFFF;
  420. *data = readl((void __iomem *)(off_value + CRB_INDIRECT_2M +
  421. ha->nx_pcibase));
  422. }
  423. return rval;
  424. }
  425. int qla4_82xx_md_wr_32(struct scsi_qla_host *ha, uint32_t off, uint32_t data)
  426. {
  427. uint32_t win_read, off_value;
  428. int rval = QLA_SUCCESS;
  429. off_value = off & 0xFFFF0000;
  430. writel(off_value, (void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase));
  431. /* Read back value to make sure write has gone through before trying
  432. * to use it.
  433. */
  434. win_read = readl((void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase));
  435. if (win_read != off_value) {
  436. DEBUG2(ql4_printk(KERN_INFO, ha,
  437. "%s: Written (0x%x) != Read (0x%x), off=0x%x\n",
  438. __func__, off_value, win_read, off));
  439. rval = QLA_ERROR;
  440. } else {
  441. off_value = off & 0x0000FFFF;
  442. writel(data, (void __iomem *)(off_value + CRB_INDIRECT_2M +
  443. ha->nx_pcibase));
  444. }
  445. return rval;
  446. }
  447. #define CRB_WIN_LOCK_TIMEOUT 100000000
  448. int qla4_82xx_crb_win_lock(struct scsi_qla_host *ha)
  449. {
  450. int i;
  451. int done = 0, timeout = 0;
  452. while (!done) {
  453. /* acquire semaphore3 from PCI HW block */
  454. done = qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM7_LOCK));
  455. if (done == 1)
  456. break;
  457. if (timeout >= CRB_WIN_LOCK_TIMEOUT)
  458. return -1;
  459. timeout++;
  460. /* Yield CPU */
  461. if (!in_interrupt())
  462. schedule();
  463. else {
  464. for (i = 0; i < 20; i++)
  465. cpu_relax(); /*This a nop instr on i386*/
  466. }
  467. }
  468. qla4_82xx_wr_32(ha, QLA82XX_CRB_WIN_LOCK_ID, ha->func_num);
  469. return 0;
  470. }
  471. void qla4_82xx_crb_win_unlock(struct scsi_qla_host *ha)
  472. {
  473. qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM7_UNLOCK));
  474. }
  475. #define IDC_LOCK_TIMEOUT 100000000
  476. /**
  477. * qla4_82xx_idc_lock - hw_lock
  478. * @ha: pointer to adapter structure
  479. *
  480. * General purpose lock used to synchronize access to
  481. * CRB_DEV_STATE, CRB_DEV_REF_COUNT, etc.
  482. **/
  483. int qla4_82xx_idc_lock(struct scsi_qla_host *ha)
  484. {
  485. int i;
  486. int done = 0, timeout = 0;
  487. while (!done) {
  488. /* acquire semaphore5 from PCI HW block */
  489. done = qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM5_LOCK));
  490. if (done == 1)
  491. break;
  492. if (timeout >= IDC_LOCK_TIMEOUT)
  493. return -1;
  494. timeout++;
  495. /* Yield CPU */
  496. if (!in_interrupt())
  497. schedule();
  498. else {
  499. for (i = 0; i < 20; i++)
  500. cpu_relax(); /*This a nop instr on i386*/
  501. }
  502. }
  503. return 0;
  504. }
  505. void qla4_82xx_idc_unlock(struct scsi_qla_host *ha)
  506. {
  507. qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM5_UNLOCK));
  508. }
  509. int
  510. qla4_82xx_pci_get_crb_addr_2M(struct scsi_qla_host *ha, ulong *off)
  511. {
  512. struct crb_128M_2M_sub_block_map *m;
  513. if (*off >= QLA82XX_CRB_MAX)
  514. return -1;
  515. if (*off >= QLA82XX_PCI_CAMQM && (*off < QLA82XX_PCI_CAMQM_2M_END)) {
  516. *off = (*off - QLA82XX_PCI_CAMQM) +
  517. QLA82XX_PCI_CAMQM_2M_BASE + ha->nx_pcibase;
  518. return 0;
  519. }
  520. if (*off < QLA82XX_PCI_CRBSPACE)
  521. return -1;
  522. *off -= QLA82XX_PCI_CRBSPACE;
  523. /*
  524. * Try direct map
  525. */
  526. m = &crb_128M_2M_map[CRB_BLK(*off)].sub_block[CRB_SUBBLK(*off)];
  527. if (m->valid && (m->start_128M <= *off) && (m->end_128M > *off)) {
  528. *off = *off + m->start_2M - m->start_128M + ha->nx_pcibase;
  529. return 0;
  530. }
  531. /*
  532. * Not in direct map, use crb window
  533. */
  534. return 1;
  535. }
  536. /*
  537. * check memory access boundary.
  538. * used by test agent. support ddr access only for now
  539. */
  540. static unsigned long
  541. qla4_82xx_pci_mem_bound_check(struct scsi_qla_host *ha,
  542. unsigned long long addr, int size)
  543. {
  544. if (!QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_DDR_NET,
  545. QLA8XXX_ADDR_DDR_NET_MAX) ||
  546. !QLA8XXX_ADDR_IN_RANGE(addr + size - 1,
  547. QLA8XXX_ADDR_DDR_NET, QLA8XXX_ADDR_DDR_NET_MAX) ||
  548. ((size != 1) && (size != 2) && (size != 4) && (size != 8))) {
  549. return 0;
  550. }
  551. return 1;
  552. }
  553. static int qla4_82xx_pci_set_window_warning_count;
  554. static unsigned long
  555. qla4_82xx_pci_set_window(struct scsi_qla_host *ha, unsigned long long addr)
  556. {
  557. int window;
  558. u32 win_read;
  559. if (QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_DDR_NET,
  560. QLA8XXX_ADDR_DDR_NET_MAX)) {
  561. /* DDR network side */
  562. window = MN_WIN(addr);
  563. ha->ddr_mn_window = window;
  564. qla4_82xx_wr_32(ha, ha->mn_win_crb |
  565. QLA82XX_PCI_CRBSPACE, window);
  566. win_read = qla4_82xx_rd_32(ha, ha->mn_win_crb |
  567. QLA82XX_PCI_CRBSPACE);
  568. if ((win_read << 17) != window) {
  569. ql4_printk(KERN_WARNING, ha,
  570. "%s: Written MNwin (0x%x) != Read MNwin (0x%x)\n",
  571. __func__, window, win_read);
  572. }
  573. addr = GET_MEM_OFFS_2M(addr) + QLA82XX_PCI_DDR_NET;
  574. } else if (QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_OCM0,
  575. QLA8XXX_ADDR_OCM0_MAX)) {
  576. unsigned int temp1;
  577. /* if bits 19:18&17:11 are on */
  578. if ((addr & 0x00ff800) == 0xff800) {
  579. printk("%s: QM access not handled.\n", __func__);
  580. addr = -1UL;
  581. }
  582. window = OCM_WIN(addr);
  583. ha->ddr_mn_window = window;
  584. qla4_82xx_wr_32(ha, ha->mn_win_crb |
  585. QLA82XX_PCI_CRBSPACE, window);
  586. win_read = qla4_82xx_rd_32(ha, ha->mn_win_crb |
  587. QLA82XX_PCI_CRBSPACE);
  588. temp1 = ((window & 0x1FF) << 7) |
  589. ((window & 0x0FFFE0000) >> 17);
  590. if (win_read != temp1) {
  591. printk("%s: Written OCMwin (0x%x) != Read"
  592. " OCMwin (0x%x)\n", __func__, temp1, win_read);
  593. }
  594. addr = GET_MEM_OFFS_2M(addr) + QLA82XX_PCI_OCM0_2M;
  595. } else if (QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_QDR_NET,
  596. QLA82XX_P3_ADDR_QDR_NET_MAX)) {
  597. /* QDR network side */
  598. window = MS_WIN(addr);
  599. ha->qdr_sn_window = window;
  600. qla4_82xx_wr_32(ha, ha->ms_win_crb |
  601. QLA82XX_PCI_CRBSPACE, window);
  602. win_read = qla4_82xx_rd_32(ha,
  603. ha->ms_win_crb | QLA82XX_PCI_CRBSPACE);
  604. if (win_read != window) {
  605. printk("%s: Written MSwin (0x%x) != Read "
  606. "MSwin (0x%x)\n", __func__, window, win_read);
  607. }
  608. addr = GET_MEM_OFFS_2M(addr) + QLA82XX_PCI_QDR_NET;
  609. } else {
  610. /*
  611. * peg gdb frequently accesses memory that doesn't exist,
  612. * this limits the chit chat so debugging isn't slowed down.
  613. */
  614. if ((qla4_82xx_pci_set_window_warning_count++ < 8) ||
  615. (qla4_82xx_pci_set_window_warning_count%64 == 0)) {
  616. printk("%s: Warning:%s Unknown address range!\n",
  617. __func__, DRIVER_NAME);
  618. }
  619. addr = -1UL;
  620. }
  621. return addr;
  622. }
  623. /* check if address is in the same windows as the previous access */
  624. static int qla4_82xx_pci_is_same_window(struct scsi_qla_host *ha,
  625. unsigned long long addr)
  626. {
  627. int window;
  628. unsigned long long qdr_max;
  629. qdr_max = QLA82XX_P3_ADDR_QDR_NET_MAX;
  630. if (QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_DDR_NET,
  631. QLA8XXX_ADDR_DDR_NET_MAX)) {
  632. /* DDR network side */
  633. BUG(); /* MN access can not come here */
  634. } else if (QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_OCM0,
  635. QLA8XXX_ADDR_OCM0_MAX)) {
  636. return 1;
  637. } else if (QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_OCM1,
  638. QLA8XXX_ADDR_OCM1_MAX)) {
  639. return 1;
  640. } else if (QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_QDR_NET,
  641. qdr_max)) {
  642. /* QDR network side */
  643. window = ((addr - QLA8XXX_ADDR_QDR_NET) >> 22) & 0x3f;
  644. if (ha->qdr_sn_window == window)
  645. return 1;
  646. }
  647. return 0;
  648. }
  649. static int qla4_82xx_pci_mem_read_direct(struct scsi_qla_host *ha,
  650. u64 off, void *data, int size)
  651. {
  652. unsigned long flags;
  653. void __iomem *addr;
  654. int ret = 0;
  655. u64 start;
  656. void __iomem *mem_ptr = NULL;
  657. unsigned long mem_base;
  658. unsigned long mem_page;
  659. write_lock_irqsave(&ha->hw_lock, flags);
  660. /*
  661. * If attempting to access unknown address or straddle hw windows,
  662. * do not access.
  663. */
  664. start = qla4_82xx_pci_set_window(ha, off);
  665. if ((start == -1UL) ||
  666. (qla4_82xx_pci_is_same_window(ha, off + size - 1) == 0)) {
  667. write_unlock_irqrestore(&ha->hw_lock, flags);
  668. printk(KERN_ERR"%s out of bound pci memory access. "
  669. "offset is 0x%llx\n", DRIVER_NAME, off);
  670. return -1;
  671. }
  672. addr = qla4_8xxx_pci_base_offsetfset(ha, start);
  673. if (!addr) {
  674. write_unlock_irqrestore(&ha->hw_lock, flags);
  675. mem_base = pci_resource_start(ha->pdev, 0);
  676. mem_page = start & PAGE_MASK;
  677. /* Map two pages whenever user tries to access addresses in two
  678. consecutive pages.
  679. */
  680. if (mem_page != ((start + size - 1) & PAGE_MASK))
  681. mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE * 2);
  682. else
  683. mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
  684. if (mem_ptr == NULL) {
  685. *(u8 *)data = 0;
  686. return -1;
  687. }
  688. addr = mem_ptr;
  689. addr += start & (PAGE_SIZE - 1);
  690. write_lock_irqsave(&ha->hw_lock, flags);
  691. }
  692. switch (size) {
  693. case 1:
  694. *(u8 *)data = readb(addr);
  695. break;
  696. case 2:
  697. *(u16 *)data = readw(addr);
  698. break;
  699. case 4:
  700. *(u32 *)data = readl(addr);
  701. break;
  702. case 8:
  703. *(u64 *)data = readq(addr);
  704. break;
  705. default:
  706. ret = -1;
  707. break;
  708. }
  709. write_unlock_irqrestore(&ha->hw_lock, flags);
  710. if (mem_ptr)
  711. iounmap(mem_ptr);
  712. return ret;
  713. }
  714. static int
  715. qla4_82xx_pci_mem_write_direct(struct scsi_qla_host *ha, u64 off,
  716. void *data, int size)
  717. {
  718. unsigned long flags;
  719. void __iomem *addr;
  720. int ret = 0;
  721. u64 start;
  722. void __iomem *mem_ptr = NULL;
  723. unsigned long mem_base;
  724. unsigned long mem_page;
  725. write_lock_irqsave(&ha->hw_lock, flags);
  726. /*
  727. * If attempting to access unknown address or straddle hw windows,
  728. * do not access.
  729. */
  730. start = qla4_82xx_pci_set_window(ha, off);
  731. if ((start == -1UL) ||
  732. (qla4_82xx_pci_is_same_window(ha, off + size - 1) == 0)) {
  733. write_unlock_irqrestore(&ha->hw_lock, flags);
  734. printk(KERN_ERR"%s out of bound pci memory access. "
  735. "offset is 0x%llx\n", DRIVER_NAME, off);
  736. return -1;
  737. }
  738. addr = qla4_8xxx_pci_base_offsetfset(ha, start);
  739. if (!addr) {
  740. write_unlock_irqrestore(&ha->hw_lock, flags);
  741. mem_base = pci_resource_start(ha->pdev, 0);
  742. mem_page = start & PAGE_MASK;
  743. /* Map two pages whenever user tries to access addresses in two
  744. consecutive pages.
  745. */
  746. if (mem_page != ((start + size - 1) & PAGE_MASK))
  747. mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE*2);
  748. else
  749. mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
  750. if (mem_ptr == NULL)
  751. return -1;
  752. addr = mem_ptr;
  753. addr += start & (PAGE_SIZE - 1);
  754. write_lock_irqsave(&ha->hw_lock, flags);
  755. }
  756. switch (size) {
  757. case 1:
  758. writeb(*(u8 *)data, addr);
  759. break;
  760. case 2:
  761. writew(*(u16 *)data, addr);
  762. break;
  763. case 4:
  764. writel(*(u32 *)data, addr);
  765. break;
  766. case 8:
  767. writeq(*(u64 *)data, addr);
  768. break;
  769. default:
  770. ret = -1;
  771. break;
  772. }
  773. write_unlock_irqrestore(&ha->hw_lock, flags);
  774. if (mem_ptr)
  775. iounmap(mem_ptr);
  776. return ret;
  777. }
  778. #define MTU_FUDGE_FACTOR 100
  779. static unsigned long
  780. qla4_82xx_decode_crb_addr(unsigned long addr)
  781. {
  782. int i;
  783. unsigned long base_addr, offset, pci_base;
  784. if (!qla4_8xxx_crb_table_initialized)
  785. qla4_82xx_crb_addr_transform_setup();
  786. pci_base = ADDR_ERROR;
  787. base_addr = addr & 0xfff00000;
  788. offset = addr & 0x000fffff;
  789. for (i = 0; i < MAX_CRB_XFORM; i++) {
  790. if (crb_addr_xform[i] == base_addr) {
  791. pci_base = i << 20;
  792. break;
  793. }
  794. }
  795. if (pci_base == ADDR_ERROR)
  796. return pci_base;
  797. else
  798. return pci_base + offset;
  799. }
  800. static long rom_max_timeout = 100;
  801. static long qla4_82xx_rom_lock_timeout = 100;
  802. static int
  803. qla4_82xx_rom_lock(struct scsi_qla_host *ha)
  804. {
  805. int i;
  806. int done = 0, timeout = 0;
  807. while (!done) {
  808. /* acquire semaphore2 from PCI HW block */
  809. done = qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM2_LOCK));
  810. if (done == 1)
  811. break;
  812. if (timeout >= qla4_82xx_rom_lock_timeout)
  813. return -1;
  814. timeout++;
  815. /* Yield CPU */
  816. if (!in_interrupt())
  817. schedule();
  818. else {
  819. for (i = 0; i < 20; i++)
  820. cpu_relax(); /*This a nop instr on i386*/
  821. }
  822. }
  823. qla4_82xx_wr_32(ha, QLA82XX_ROM_LOCK_ID, ROM_LOCK_DRIVER);
  824. return 0;
  825. }
  826. static void
  827. qla4_82xx_rom_unlock(struct scsi_qla_host *ha)
  828. {
  829. qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM2_UNLOCK));
  830. }
  831. static int
  832. qla4_82xx_wait_rom_done(struct scsi_qla_host *ha)
  833. {
  834. long timeout = 0;
  835. long done = 0 ;
  836. while (done == 0) {
  837. done = qla4_82xx_rd_32(ha, QLA82XX_ROMUSB_GLB_STATUS);
  838. done &= 2;
  839. timeout++;
  840. if (timeout >= rom_max_timeout) {
  841. printk("%s: Timeout reached waiting for rom done",
  842. DRIVER_NAME);
  843. return -1;
  844. }
  845. }
  846. return 0;
  847. }
  848. static int
  849. qla4_82xx_do_rom_fast_read(struct scsi_qla_host *ha, int addr, int *valp)
  850. {
  851. qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_ADDRESS, addr);
  852. qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_DUMMY_BYTE_CNT, 0);
  853. qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_ABYTE_CNT, 3);
  854. qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_INSTR_OPCODE, 0xb);
  855. if (qla4_82xx_wait_rom_done(ha)) {
  856. printk("%s: Error waiting for rom done\n", DRIVER_NAME);
  857. return -1;
  858. }
  859. /* reset abyte_cnt and dummy_byte_cnt */
  860. qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_DUMMY_BYTE_CNT, 0);
  861. udelay(10);
  862. qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_ABYTE_CNT, 0);
  863. *valp = qla4_82xx_rd_32(ha, QLA82XX_ROMUSB_ROM_RDATA);
  864. return 0;
  865. }
  866. static int
  867. qla4_82xx_rom_fast_read(struct scsi_qla_host *ha, int addr, int *valp)
  868. {
  869. int ret, loops = 0;
  870. while ((qla4_82xx_rom_lock(ha) != 0) && (loops < 50000)) {
  871. udelay(100);
  872. loops++;
  873. }
  874. if (loops >= 50000) {
  875. ql4_printk(KERN_WARNING, ha, "%s: qla4_82xx_rom_lock failed\n",
  876. DRIVER_NAME);
  877. return -1;
  878. }
  879. ret = qla4_82xx_do_rom_fast_read(ha, addr, valp);
  880. qla4_82xx_rom_unlock(ha);
  881. return ret;
  882. }
  883. /**
  884. * This routine does CRB initialize sequence
  885. * to put the ISP into operational state
  886. **/
  887. static int
  888. qla4_82xx_pinit_from_rom(struct scsi_qla_host *ha, int verbose)
  889. {
  890. int addr, val;
  891. int i ;
  892. struct crb_addr_pair *buf;
  893. unsigned long off;
  894. unsigned offset, n;
  895. struct crb_addr_pair {
  896. long addr;
  897. long data;
  898. };
  899. /* Halt all the indiviual PEGs and other blocks of the ISP */
  900. qla4_82xx_rom_lock(ha);
  901. /* disable all I2Q */
  902. qla4_82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x10, 0x0);
  903. qla4_82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x14, 0x0);
  904. qla4_82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x18, 0x0);
  905. qla4_82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x1c, 0x0);
  906. qla4_82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x20, 0x0);
  907. qla4_82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x24, 0x0);
  908. /* disable all niu interrupts */
  909. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x40, 0xff);
  910. /* disable xge rx/tx */
  911. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x70000, 0x00);
  912. /* disable xg1 rx/tx */
  913. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x80000, 0x00);
  914. /* disable sideband mac */
  915. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x90000, 0x00);
  916. /* disable ap0 mac */
  917. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0xa0000, 0x00);
  918. /* disable ap1 mac */
  919. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0xb0000, 0x00);
  920. /* halt sre */
  921. val = qla4_82xx_rd_32(ha, QLA82XX_CRB_SRE + 0x1000);
  922. qla4_82xx_wr_32(ha, QLA82XX_CRB_SRE + 0x1000, val & (~(0x1)));
  923. /* halt epg */
  924. qla4_82xx_wr_32(ha, QLA82XX_CRB_EPG + 0x1300, 0x1);
  925. /* halt timers */
  926. qla4_82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x0, 0x0);
  927. qla4_82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x8, 0x0);
  928. qla4_82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x10, 0x0);
  929. qla4_82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x18, 0x0);
  930. qla4_82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x100, 0x0);
  931. qla4_82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x200, 0x0);
  932. /* halt pegs */
  933. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_0 + 0x3c, 1);
  934. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_1 + 0x3c, 1);
  935. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_2 + 0x3c, 1);
  936. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_3 + 0x3c, 1);
  937. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_4 + 0x3c, 1);
  938. msleep(5);
  939. /* big hammer */
  940. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  941. /* don't reset CAM block on reset */
  942. qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, 0xfeffffff);
  943. else
  944. qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, 0xffffffff);
  945. qla4_82xx_rom_unlock(ha);
  946. /* Read the signature value from the flash.
  947. * Offset 0: Contain signature (0xcafecafe)
  948. * Offset 4: Offset and number of addr/value pairs
  949. * that present in CRB initialize sequence
  950. */
  951. if (qla4_82xx_rom_fast_read(ha, 0, &n) != 0 || n != 0xcafecafeUL ||
  952. qla4_82xx_rom_fast_read(ha, 4, &n) != 0) {
  953. ql4_printk(KERN_WARNING, ha,
  954. "[ERROR] Reading crb_init area: n: %08x\n", n);
  955. return -1;
  956. }
  957. /* Offset in flash = lower 16 bits
  958. * Number of enteries = upper 16 bits
  959. */
  960. offset = n & 0xffffU;
  961. n = (n >> 16) & 0xffffU;
  962. /* number of addr/value pair should not exceed 1024 enteries */
  963. if (n >= 1024) {
  964. ql4_printk(KERN_WARNING, ha,
  965. "%s: %s:n=0x%x [ERROR] Card flash not initialized.\n",
  966. DRIVER_NAME, __func__, n);
  967. return -1;
  968. }
  969. ql4_printk(KERN_INFO, ha,
  970. "%s: %d CRB init values found in ROM.\n", DRIVER_NAME, n);
  971. buf = kmalloc_array(n, sizeof(struct crb_addr_pair), GFP_KERNEL);
  972. if (buf == NULL) {
  973. ql4_printk(KERN_WARNING, ha,
  974. "%s: [ERROR] Unable to malloc memory.\n", DRIVER_NAME);
  975. return -1;
  976. }
  977. for (i = 0; i < n; i++) {
  978. if (qla4_82xx_rom_fast_read(ha, 8*i + 4*offset, &val) != 0 ||
  979. qla4_82xx_rom_fast_read(ha, 8*i + 4*offset + 4, &addr) !=
  980. 0) {
  981. kfree(buf);
  982. return -1;
  983. }
  984. buf[i].addr = addr;
  985. buf[i].data = val;
  986. }
  987. for (i = 0; i < n; i++) {
  988. /* Translate internal CRB initialization
  989. * address to PCI bus address
  990. */
  991. off = qla4_82xx_decode_crb_addr((unsigned long)buf[i].addr) +
  992. QLA82XX_PCI_CRBSPACE;
  993. /* Not all CRB addr/value pair to be written,
  994. * some of them are skipped
  995. */
  996. /* skip if LS bit is set*/
  997. if (off & 0x1) {
  998. DEBUG2(ql4_printk(KERN_WARNING, ha,
  999. "Skip CRB init replay for offset = 0x%lx\n", off));
  1000. continue;
  1001. }
  1002. /* skipping cold reboot MAGIC */
  1003. if (off == QLA82XX_CAM_RAM(0x1fc))
  1004. continue;
  1005. /* do not reset PCI */
  1006. if (off == (ROMUSB_GLB + 0xbc))
  1007. continue;
  1008. /* skip core clock, so that firmware can increase the clock */
  1009. if (off == (ROMUSB_GLB + 0xc8))
  1010. continue;
  1011. /* skip the function enable register */
  1012. if (off == QLA82XX_PCIE_REG(PCIE_SETUP_FUNCTION))
  1013. continue;
  1014. if (off == QLA82XX_PCIE_REG(PCIE_SETUP_FUNCTION2))
  1015. continue;
  1016. if ((off & 0x0ff00000) == QLA82XX_CRB_SMB)
  1017. continue;
  1018. if ((off & 0x0ff00000) == QLA82XX_CRB_DDR_NET)
  1019. continue;
  1020. if (off == ADDR_ERROR) {
  1021. ql4_printk(KERN_WARNING, ha,
  1022. "%s: [ERROR] Unknown addr: 0x%08lx\n",
  1023. DRIVER_NAME, buf[i].addr);
  1024. continue;
  1025. }
  1026. qla4_82xx_wr_32(ha, off, buf[i].data);
  1027. /* ISP requires much bigger delay to settle down,
  1028. * else crb_window returns 0xffffffff
  1029. */
  1030. if (off == QLA82XX_ROMUSB_GLB_SW_RESET)
  1031. msleep(1000);
  1032. /* ISP requires millisec delay between
  1033. * successive CRB register updation
  1034. */
  1035. msleep(1);
  1036. }
  1037. kfree(buf);
  1038. /* Resetting the data and instruction cache */
  1039. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_D+0xec, 0x1e);
  1040. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_D+0x4c, 8);
  1041. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_I+0x4c, 8);
  1042. /* Clear all protocol processing engines */
  1043. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_0+0x8, 0);
  1044. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_0+0xc, 0);
  1045. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_1+0x8, 0);
  1046. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_1+0xc, 0);
  1047. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_2+0x8, 0);
  1048. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_2+0xc, 0);
  1049. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_3+0x8, 0);
  1050. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_3+0xc, 0);
  1051. return 0;
  1052. }
  1053. /**
  1054. * qla4_8xxx_ms_mem_write_128b - Writes data to MS/off-chip memory
  1055. * @ha: Pointer to adapter structure
  1056. * @addr: Flash address to write to
  1057. * @data: Data to be written
  1058. * @count: word_count to be written
  1059. *
  1060. * Return: On success return QLA_SUCCESS
  1061. * On error return QLA_ERROR
  1062. **/
  1063. int qla4_8xxx_ms_mem_write_128b(struct scsi_qla_host *ha, uint64_t addr,
  1064. uint32_t *data, uint32_t count)
  1065. {
  1066. int i, j;
  1067. uint32_t agt_ctrl;
  1068. unsigned long flags;
  1069. int ret_val = QLA_SUCCESS;
  1070. /* Only 128-bit aligned access */
  1071. if (addr & 0xF) {
  1072. ret_val = QLA_ERROR;
  1073. goto exit_ms_mem_write;
  1074. }
  1075. write_lock_irqsave(&ha->hw_lock, flags);
  1076. /* Write address */
  1077. ret_val = ha->isp_ops->wr_reg_indirect(ha, MD_MIU_TEST_AGT_ADDR_HI, 0);
  1078. if (ret_val == QLA_ERROR) {
  1079. ql4_printk(KERN_ERR, ha, "%s: write to AGT_ADDR_HI failed\n",
  1080. __func__);
  1081. goto exit_ms_mem_write_unlock;
  1082. }
  1083. for (i = 0; i < count; i++, addr += 16) {
  1084. if (!((QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_QDR_NET,
  1085. QLA8XXX_ADDR_QDR_NET_MAX)) ||
  1086. (QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_DDR_NET,
  1087. QLA8XXX_ADDR_DDR_NET_MAX)))) {
  1088. ret_val = QLA_ERROR;
  1089. goto exit_ms_mem_write_unlock;
  1090. }
  1091. ret_val = ha->isp_ops->wr_reg_indirect(ha,
  1092. MD_MIU_TEST_AGT_ADDR_LO,
  1093. addr);
  1094. /* Write data */
  1095. ret_val |= ha->isp_ops->wr_reg_indirect(ha,
  1096. MD_MIU_TEST_AGT_WRDATA_LO,
  1097. *data++);
  1098. ret_val |= ha->isp_ops->wr_reg_indirect(ha,
  1099. MD_MIU_TEST_AGT_WRDATA_HI,
  1100. *data++);
  1101. ret_val |= ha->isp_ops->wr_reg_indirect(ha,
  1102. MD_MIU_TEST_AGT_WRDATA_ULO,
  1103. *data++);
  1104. ret_val |= ha->isp_ops->wr_reg_indirect(ha,
  1105. MD_MIU_TEST_AGT_WRDATA_UHI,
  1106. *data++);
  1107. if (ret_val == QLA_ERROR) {
  1108. ql4_printk(KERN_ERR, ha, "%s: write to AGT_WRDATA failed\n",
  1109. __func__);
  1110. goto exit_ms_mem_write_unlock;
  1111. }
  1112. /* Check write status */
  1113. ret_val = ha->isp_ops->wr_reg_indirect(ha, MD_MIU_TEST_AGT_CTRL,
  1114. MIU_TA_CTL_WRITE_ENABLE);
  1115. ret_val |= ha->isp_ops->wr_reg_indirect(ha,
  1116. MD_MIU_TEST_AGT_CTRL,
  1117. MIU_TA_CTL_WRITE_START);
  1118. if (ret_val == QLA_ERROR) {
  1119. ql4_printk(KERN_ERR, ha, "%s: write to AGT_CTRL failed\n",
  1120. __func__);
  1121. goto exit_ms_mem_write_unlock;
  1122. }
  1123. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1124. ret_val = ha->isp_ops->rd_reg_indirect(ha,
  1125. MD_MIU_TEST_AGT_CTRL,
  1126. &agt_ctrl);
  1127. if (ret_val == QLA_ERROR) {
  1128. ql4_printk(KERN_ERR, ha, "%s: failed to read MD_MIU_TEST_AGT_CTRL\n",
  1129. __func__);
  1130. goto exit_ms_mem_write_unlock;
  1131. }
  1132. if ((agt_ctrl & MIU_TA_CTL_BUSY) == 0)
  1133. break;
  1134. }
  1135. /* Status check failed */
  1136. if (j >= MAX_CTL_CHECK) {
  1137. printk_ratelimited(KERN_ERR "%s: MS memory write failed!\n",
  1138. __func__);
  1139. ret_val = QLA_ERROR;
  1140. goto exit_ms_mem_write_unlock;
  1141. }
  1142. }
  1143. exit_ms_mem_write_unlock:
  1144. write_unlock_irqrestore(&ha->hw_lock, flags);
  1145. exit_ms_mem_write:
  1146. return ret_val;
  1147. }
  1148. static int
  1149. qla4_82xx_load_from_flash(struct scsi_qla_host *ha, uint32_t image_start)
  1150. {
  1151. int i, rval = 0;
  1152. long size = 0;
  1153. long flashaddr, memaddr;
  1154. u64 data;
  1155. u32 high, low;
  1156. flashaddr = memaddr = ha->hw.flt_region_bootload;
  1157. size = (image_start - flashaddr) / 8;
  1158. DEBUG2(printk("scsi%ld: %s: bootldr=0x%lx, fw_image=0x%x\n",
  1159. ha->host_no, __func__, flashaddr, image_start));
  1160. for (i = 0; i < size; i++) {
  1161. if ((qla4_82xx_rom_fast_read(ha, flashaddr, (int *)&low)) ||
  1162. (qla4_82xx_rom_fast_read(ha, flashaddr + 4,
  1163. (int *)&high))) {
  1164. rval = -1;
  1165. goto exit_load_from_flash;
  1166. }
  1167. data = ((u64)high << 32) | low ;
  1168. rval = qla4_82xx_pci_mem_write_2M(ha, memaddr, &data, 8);
  1169. if (rval)
  1170. goto exit_load_from_flash;
  1171. flashaddr += 8;
  1172. memaddr += 8;
  1173. if (i % 0x1000 == 0)
  1174. msleep(1);
  1175. }
  1176. udelay(100);
  1177. read_lock(&ha->hw_lock);
  1178. qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_0 + 0x18, 0x1020);
  1179. qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, 0x80001e);
  1180. read_unlock(&ha->hw_lock);
  1181. exit_load_from_flash:
  1182. return rval;
  1183. }
  1184. static int qla4_82xx_load_fw(struct scsi_qla_host *ha, uint32_t image_start)
  1185. {
  1186. u32 rst;
  1187. qla4_82xx_wr_32(ha, CRB_CMDPEG_STATE, 0);
  1188. if (qla4_82xx_pinit_from_rom(ha, 0) != QLA_SUCCESS) {
  1189. printk(KERN_WARNING "%s: Error during CRB Initialization\n",
  1190. __func__);
  1191. return QLA_ERROR;
  1192. }
  1193. udelay(500);
  1194. /* at this point, QM is in reset. This could be a problem if there are
  1195. * incoming d* transition queue messages. QM/PCIE could wedge.
  1196. * To get around this, QM is brought out of reset.
  1197. */
  1198. rst = qla4_82xx_rd_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET);
  1199. /* unreset qm */
  1200. rst &= ~(1 << 28);
  1201. qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, rst);
  1202. if (qla4_82xx_load_from_flash(ha, image_start)) {
  1203. printk("%s: Error trying to load fw from flash!\n", __func__);
  1204. return QLA_ERROR;
  1205. }
  1206. return QLA_SUCCESS;
  1207. }
  1208. int
  1209. qla4_82xx_pci_mem_read_2M(struct scsi_qla_host *ha,
  1210. u64 off, void *data, int size)
  1211. {
  1212. int i, j = 0, k, start, end, loop, sz[2], off0[2];
  1213. int shift_amount;
  1214. uint32_t temp;
  1215. uint64_t off8, val, mem_crb, word[2] = {0, 0};
  1216. /*
  1217. * If not MN, go check for MS or invalid.
  1218. */
  1219. if (off >= QLA8XXX_ADDR_QDR_NET && off <= QLA82XX_P3_ADDR_QDR_NET_MAX)
  1220. mem_crb = QLA82XX_CRB_QDR_NET;
  1221. else {
  1222. mem_crb = QLA82XX_CRB_DDR_NET;
  1223. if (qla4_82xx_pci_mem_bound_check(ha, off, size) == 0)
  1224. return qla4_82xx_pci_mem_read_direct(ha,
  1225. off, data, size);
  1226. }
  1227. off8 = off & 0xfffffff0;
  1228. off0[0] = off & 0xf;
  1229. sz[0] = (size < (16 - off0[0])) ? size : (16 - off0[0]);
  1230. shift_amount = 4;
  1231. loop = ((off0[0] + size - 1) >> shift_amount) + 1;
  1232. off0[1] = 0;
  1233. sz[1] = size - sz[0];
  1234. for (i = 0; i < loop; i++) {
  1235. temp = off8 + (i << shift_amount);
  1236. qla4_82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_ADDR_LO, temp);
  1237. temp = 0;
  1238. qla4_82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_ADDR_HI, temp);
  1239. temp = MIU_TA_CTL_ENABLE;
  1240. qla4_82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_CTRL, temp);
  1241. temp = MIU_TA_CTL_START_ENABLE;
  1242. qla4_82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_CTRL, temp);
  1243. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1244. temp = qla4_82xx_rd_32(ha, mem_crb + MIU_TEST_AGT_CTRL);
  1245. if ((temp & MIU_TA_CTL_BUSY) == 0)
  1246. break;
  1247. }
  1248. if (j >= MAX_CTL_CHECK) {
  1249. printk_ratelimited(KERN_ERR
  1250. "%s: failed to read through agent\n",
  1251. __func__);
  1252. break;
  1253. }
  1254. start = off0[i] >> 2;
  1255. end = (off0[i] + sz[i] - 1) >> 2;
  1256. for (k = start; k <= end; k++) {
  1257. temp = qla4_82xx_rd_32(ha,
  1258. mem_crb + MIU_TEST_AGT_RDDATA(k));
  1259. word[i] |= ((uint64_t)temp << (32 * (k & 1)));
  1260. }
  1261. }
  1262. if (j >= MAX_CTL_CHECK)
  1263. return -1;
  1264. if ((off0[0] & 7) == 0) {
  1265. val = word[0];
  1266. } else {
  1267. val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
  1268. ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
  1269. }
  1270. switch (size) {
  1271. case 1:
  1272. *(uint8_t *)data = val;
  1273. break;
  1274. case 2:
  1275. *(uint16_t *)data = val;
  1276. break;
  1277. case 4:
  1278. *(uint32_t *)data = val;
  1279. break;
  1280. case 8:
  1281. *(uint64_t *)data = val;
  1282. break;
  1283. }
  1284. return 0;
  1285. }
  1286. int
  1287. qla4_82xx_pci_mem_write_2M(struct scsi_qla_host *ha,
  1288. u64 off, void *data, int size)
  1289. {
  1290. int i, j, ret = 0, loop, sz[2], off0;
  1291. int scale, shift_amount, startword;
  1292. uint32_t temp;
  1293. uint64_t off8, mem_crb, tmpw, word[2] = {0, 0};
  1294. /*
  1295. * If not MN, go check for MS or invalid.
  1296. */
  1297. if (off >= QLA8XXX_ADDR_QDR_NET && off <= QLA82XX_P3_ADDR_QDR_NET_MAX)
  1298. mem_crb = QLA82XX_CRB_QDR_NET;
  1299. else {
  1300. mem_crb = QLA82XX_CRB_DDR_NET;
  1301. if (qla4_82xx_pci_mem_bound_check(ha, off, size) == 0)
  1302. return qla4_82xx_pci_mem_write_direct(ha,
  1303. off, data, size);
  1304. }
  1305. off0 = off & 0x7;
  1306. sz[0] = (size < (8 - off0)) ? size : (8 - off0);
  1307. sz[1] = size - sz[0];
  1308. off8 = off & 0xfffffff0;
  1309. loop = (((off & 0xf) + size - 1) >> 4) + 1;
  1310. shift_amount = 4;
  1311. scale = 2;
  1312. startword = (off & 0xf)/8;
  1313. for (i = 0; i < loop; i++) {
  1314. if (qla4_82xx_pci_mem_read_2M(ha, off8 +
  1315. (i << shift_amount), &word[i * scale], 8))
  1316. return -1;
  1317. }
  1318. switch (size) {
  1319. case 1:
  1320. tmpw = *((uint8_t *)data);
  1321. break;
  1322. case 2:
  1323. tmpw = *((uint16_t *)data);
  1324. break;
  1325. case 4:
  1326. tmpw = *((uint32_t *)data);
  1327. break;
  1328. case 8:
  1329. default:
  1330. tmpw = *((uint64_t *)data);
  1331. break;
  1332. }
  1333. if (sz[0] == 8)
  1334. word[startword] = tmpw;
  1335. else {
  1336. word[startword] &=
  1337. ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
  1338. word[startword] |= tmpw << (off0 * 8);
  1339. }
  1340. if (sz[1] != 0) {
  1341. word[startword+1] &= ~(~0ULL << (sz[1] * 8));
  1342. word[startword+1] |= tmpw >> (sz[0] * 8);
  1343. }
  1344. for (i = 0; i < loop; i++) {
  1345. temp = off8 + (i << shift_amount);
  1346. qla4_82xx_wr_32(ha, mem_crb+MIU_TEST_AGT_ADDR_LO, temp);
  1347. temp = 0;
  1348. qla4_82xx_wr_32(ha, mem_crb+MIU_TEST_AGT_ADDR_HI, temp);
  1349. temp = word[i * scale] & 0xffffffff;
  1350. qla4_82xx_wr_32(ha, mem_crb+MIU_TEST_AGT_WRDATA_LO, temp);
  1351. temp = (word[i * scale] >> 32) & 0xffffffff;
  1352. qla4_82xx_wr_32(ha, mem_crb+MIU_TEST_AGT_WRDATA_HI, temp);
  1353. temp = word[i*scale + 1] & 0xffffffff;
  1354. qla4_82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_WRDATA_UPPER_LO,
  1355. temp);
  1356. temp = (word[i*scale + 1] >> 32) & 0xffffffff;
  1357. qla4_82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_WRDATA_UPPER_HI,
  1358. temp);
  1359. temp = MIU_TA_CTL_WRITE_ENABLE;
  1360. qla4_82xx_wr_32(ha, mem_crb+MIU_TEST_AGT_CTRL, temp);
  1361. temp = MIU_TA_CTL_WRITE_START;
  1362. qla4_82xx_wr_32(ha, mem_crb+MIU_TEST_AGT_CTRL, temp);
  1363. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1364. temp = qla4_82xx_rd_32(ha, mem_crb + MIU_TEST_AGT_CTRL);
  1365. if ((temp & MIU_TA_CTL_BUSY) == 0)
  1366. break;
  1367. }
  1368. if (j >= MAX_CTL_CHECK) {
  1369. if (printk_ratelimit())
  1370. ql4_printk(KERN_ERR, ha,
  1371. "%s: failed to read through agent\n",
  1372. __func__);
  1373. ret = -1;
  1374. break;
  1375. }
  1376. }
  1377. return ret;
  1378. }
  1379. static int qla4_82xx_cmdpeg_ready(struct scsi_qla_host *ha, int pegtune_val)
  1380. {
  1381. u32 val = 0;
  1382. int retries = 60;
  1383. if (!pegtune_val) {
  1384. do {
  1385. val = qla4_82xx_rd_32(ha, CRB_CMDPEG_STATE);
  1386. if ((val == PHAN_INITIALIZE_COMPLETE) ||
  1387. (val == PHAN_INITIALIZE_ACK))
  1388. return 0;
  1389. set_current_state(TASK_UNINTERRUPTIBLE);
  1390. schedule_timeout(500);
  1391. } while (--retries);
  1392. if (!retries) {
  1393. pegtune_val = qla4_82xx_rd_32(ha,
  1394. QLA82XX_ROMUSB_GLB_PEGTUNE_DONE);
  1395. printk(KERN_WARNING "%s: init failed, "
  1396. "pegtune_val = %x\n", __func__, pegtune_val);
  1397. return -1;
  1398. }
  1399. }
  1400. return 0;
  1401. }
  1402. static int qla4_82xx_rcvpeg_ready(struct scsi_qla_host *ha)
  1403. {
  1404. uint32_t state = 0;
  1405. int loops = 0;
  1406. /* Window 1 call */
  1407. read_lock(&ha->hw_lock);
  1408. state = qla4_82xx_rd_32(ha, CRB_RCVPEG_STATE);
  1409. read_unlock(&ha->hw_lock);
  1410. while ((state != PHAN_PEG_RCV_INITIALIZED) && (loops < 30000)) {
  1411. udelay(100);
  1412. /* Window 1 call */
  1413. read_lock(&ha->hw_lock);
  1414. state = qla4_82xx_rd_32(ha, CRB_RCVPEG_STATE);
  1415. read_unlock(&ha->hw_lock);
  1416. loops++;
  1417. }
  1418. if (loops >= 30000) {
  1419. DEBUG2(ql4_printk(KERN_INFO, ha,
  1420. "Receive Peg initialization not complete: 0x%x.\n", state));
  1421. return QLA_ERROR;
  1422. }
  1423. return QLA_SUCCESS;
  1424. }
  1425. void
  1426. qla4_8xxx_set_drv_active(struct scsi_qla_host *ha)
  1427. {
  1428. uint32_t drv_active;
  1429. drv_active = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_ACTIVE);
  1430. /*
  1431. * For ISP8324 and ISP8042, drv_active register has 1 bit per function,
  1432. * shift 1 by func_num to set a bit for the function.
  1433. * For ISP8022, drv_active has 4 bits per function
  1434. */
  1435. if (is_qla8032(ha) || is_qla8042(ha))
  1436. drv_active |= (1 << ha->func_num);
  1437. else
  1438. drv_active |= (1 << (ha->func_num * 4));
  1439. ql4_printk(KERN_INFO, ha, "%s(%ld): drv_active: 0x%08x\n",
  1440. __func__, ha->host_no, drv_active);
  1441. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_ACTIVE, drv_active);
  1442. }
  1443. void
  1444. qla4_8xxx_clear_drv_active(struct scsi_qla_host *ha)
  1445. {
  1446. uint32_t drv_active;
  1447. drv_active = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_ACTIVE);
  1448. /*
  1449. * For ISP8324 and ISP8042, drv_active register has 1 bit per function,
  1450. * shift 1 by func_num to set a bit for the function.
  1451. * For ISP8022, drv_active has 4 bits per function
  1452. */
  1453. if (is_qla8032(ha) || is_qla8042(ha))
  1454. drv_active &= ~(1 << (ha->func_num));
  1455. else
  1456. drv_active &= ~(1 << (ha->func_num * 4));
  1457. ql4_printk(KERN_INFO, ha, "%s(%ld): drv_active: 0x%08x\n",
  1458. __func__, ha->host_no, drv_active);
  1459. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_ACTIVE, drv_active);
  1460. }
  1461. inline int qla4_8xxx_need_reset(struct scsi_qla_host *ha)
  1462. {
  1463. uint32_t drv_state, drv_active;
  1464. int rval;
  1465. drv_active = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_ACTIVE);
  1466. drv_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_STATE);
  1467. /*
  1468. * For ISP8324 and ISP8042, drv_active register has 1 bit per function,
  1469. * shift 1 by func_num to set a bit for the function.
  1470. * For ISP8022, drv_active has 4 bits per function
  1471. */
  1472. if (is_qla8032(ha) || is_qla8042(ha))
  1473. rval = drv_state & (1 << ha->func_num);
  1474. else
  1475. rval = drv_state & (1 << (ha->func_num * 4));
  1476. if ((test_bit(AF_EEH_BUSY, &ha->flags)) && drv_active)
  1477. rval = 1;
  1478. return rval;
  1479. }
  1480. void qla4_8xxx_set_rst_ready(struct scsi_qla_host *ha)
  1481. {
  1482. uint32_t drv_state;
  1483. drv_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_STATE);
  1484. /*
  1485. * For ISP8324 and ISP8042, drv_active register has 1 bit per function,
  1486. * shift 1 by func_num to set a bit for the function.
  1487. * For ISP8022, drv_active has 4 bits per function
  1488. */
  1489. if (is_qla8032(ha) || is_qla8042(ha))
  1490. drv_state |= (1 << ha->func_num);
  1491. else
  1492. drv_state |= (1 << (ha->func_num * 4));
  1493. ql4_printk(KERN_INFO, ha, "%s(%ld): drv_state: 0x%08x\n",
  1494. __func__, ha->host_no, drv_state);
  1495. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, drv_state);
  1496. }
  1497. void qla4_8xxx_clear_rst_ready(struct scsi_qla_host *ha)
  1498. {
  1499. uint32_t drv_state;
  1500. drv_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_STATE);
  1501. /*
  1502. * For ISP8324 and ISP8042, drv_active register has 1 bit per function,
  1503. * shift 1 by func_num to set a bit for the function.
  1504. * For ISP8022, drv_active has 4 bits per function
  1505. */
  1506. if (is_qla8032(ha) || is_qla8042(ha))
  1507. drv_state &= ~(1 << ha->func_num);
  1508. else
  1509. drv_state &= ~(1 << (ha->func_num * 4));
  1510. ql4_printk(KERN_INFO, ha, "%s(%ld): drv_state: 0x%08x\n",
  1511. __func__, ha->host_no, drv_state);
  1512. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, drv_state);
  1513. }
  1514. static inline void
  1515. qla4_8xxx_set_qsnt_ready(struct scsi_qla_host *ha)
  1516. {
  1517. uint32_t qsnt_state;
  1518. qsnt_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_STATE);
  1519. /*
  1520. * For ISP8324 and ISP8042, drv_active register has 1 bit per function,
  1521. * shift 1 by func_num to set a bit for the function.
  1522. * For ISP8022, drv_active has 4 bits per function.
  1523. */
  1524. if (is_qla8032(ha) || is_qla8042(ha))
  1525. qsnt_state |= (1 << ha->func_num);
  1526. else
  1527. qsnt_state |= (2 << (ha->func_num * 4));
  1528. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, qsnt_state);
  1529. }
  1530. static int
  1531. qla4_82xx_start_firmware(struct scsi_qla_host *ha, uint32_t image_start)
  1532. {
  1533. uint16_t lnk;
  1534. /* scrub dma mask expansion register */
  1535. qla4_82xx_wr_32(ha, CRB_DMA_SHIFT, 0x55555555);
  1536. /* Overwrite stale initialization register values */
  1537. qla4_82xx_wr_32(ha, CRB_CMDPEG_STATE, 0);
  1538. qla4_82xx_wr_32(ha, CRB_RCVPEG_STATE, 0);
  1539. qla4_82xx_wr_32(ha, QLA82XX_PEG_HALT_STATUS1, 0);
  1540. qla4_82xx_wr_32(ha, QLA82XX_PEG_HALT_STATUS2, 0);
  1541. if (qla4_82xx_load_fw(ha, image_start) != QLA_SUCCESS) {
  1542. printk("%s: Error trying to start fw!\n", __func__);
  1543. return QLA_ERROR;
  1544. }
  1545. /* Handshake with the card before we register the devices. */
  1546. if (qla4_82xx_cmdpeg_ready(ha, 0) != QLA_SUCCESS) {
  1547. printk("%s: Error during card handshake!\n", __func__);
  1548. return QLA_ERROR;
  1549. }
  1550. /* Negotiated Link width */
  1551. pcie_capability_read_word(ha->pdev, PCI_EXP_LNKSTA, &lnk);
  1552. ha->link_width = (lnk >> 4) & 0x3f;
  1553. /* Synchronize with Receive peg */
  1554. return qla4_82xx_rcvpeg_ready(ha);
  1555. }
  1556. int qla4_82xx_try_start_fw(struct scsi_qla_host *ha)
  1557. {
  1558. int rval = QLA_ERROR;
  1559. /*
  1560. * FW Load priority:
  1561. * 1) Operational firmware residing in flash.
  1562. * 2) Fail
  1563. */
  1564. ql4_printk(KERN_INFO, ha,
  1565. "FW: Retrieving flash offsets from FLT/FDT ...\n");
  1566. rval = qla4_8xxx_get_flash_info(ha);
  1567. if (rval != QLA_SUCCESS)
  1568. return rval;
  1569. ql4_printk(KERN_INFO, ha,
  1570. "FW: Attempting to load firmware from flash...\n");
  1571. rval = qla4_82xx_start_firmware(ha, ha->hw.flt_region_fw);
  1572. if (rval != QLA_SUCCESS) {
  1573. ql4_printk(KERN_ERR, ha, "FW: Load firmware from flash"
  1574. " FAILED...\n");
  1575. return rval;
  1576. }
  1577. return rval;
  1578. }
  1579. void qla4_82xx_rom_lock_recovery(struct scsi_qla_host *ha)
  1580. {
  1581. if (qla4_82xx_rom_lock(ha)) {
  1582. /* Someone else is holding the lock. */
  1583. dev_info(&ha->pdev->dev, "Resetting rom_lock\n");
  1584. }
  1585. /*
  1586. * Either we got the lock, or someone
  1587. * else died while holding it.
  1588. * In either case, unlock.
  1589. */
  1590. qla4_82xx_rom_unlock(ha);
  1591. }
  1592. static uint32_t ql4_84xx_poll_wait_for_ready(struct scsi_qla_host *ha,
  1593. uint32_t addr1, uint32_t mask)
  1594. {
  1595. unsigned long timeout;
  1596. uint32_t rval = QLA_SUCCESS;
  1597. uint32_t temp;
  1598. timeout = jiffies + msecs_to_jiffies(TIMEOUT_100_MS);
  1599. do {
  1600. ha->isp_ops->rd_reg_indirect(ha, addr1, &temp);
  1601. if ((temp & mask) != 0)
  1602. break;
  1603. if (time_after_eq(jiffies, timeout)) {
  1604. ql4_printk(KERN_INFO, ha, "Error in processing rdmdio entry\n");
  1605. return QLA_ERROR;
  1606. }
  1607. } while (1);
  1608. return rval;
  1609. }
  1610. static uint32_t ql4_84xx_ipmdio_rd_reg(struct scsi_qla_host *ha, uint32_t addr1,
  1611. uint32_t addr3, uint32_t mask, uint32_t addr,
  1612. uint32_t *data_ptr)
  1613. {
  1614. int rval = QLA_SUCCESS;
  1615. uint32_t temp;
  1616. uint32_t data;
  1617. rval = ql4_84xx_poll_wait_for_ready(ha, addr1, mask);
  1618. if (rval)
  1619. goto exit_ipmdio_rd_reg;
  1620. temp = (0x40000000 | addr);
  1621. ha->isp_ops->wr_reg_indirect(ha, addr1, temp);
  1622. rval = ql4_84xx_poll_wait_for_ready(ha, addr1, mask);
  1623. if (rval)
  1624. goto exit_ipmdio_rd_reg;
  1625. ha->isp_ops->rd_reg_indirect(ha, addr3, &data);
  1626. *data_ptr = data;
  1627. exit_ipmdio_rd_reg:
  1628. return rval;
  1629. }
  1630. static uint32_t ql4_84xx_poll_wait_ipmdio_bus_idle(struct scsi_qla_host *ha,
  1631. uint32_t addr1,
  1632. uint32_t addr2,
  1633. uint32_t addr3,
  1634. uint32_t mask)
  1635. {
  1636. unsigned long timeout;
  1637. uint32_t temp;
  1638. uint32_t rval = QLA_SUCCESS;
  1639. timeout = jiffies + msecs_to_jiffies(TIMEOUT_100_MS);
  1640. do {
  1641. ql4_84xx_ipmdio_rd_reg(ha, addr1, addr3, mask, addr2, &temp);
  1642. if ((temp & 0x1) != 1)
  1643. break;
  1644. if (time_after_eq(jiffies, timeout)) {
  1645. ql4_printk(KERN_INFO, ha, "Error in processing mdiobus idle\n");
  1646. return QLA_ERROR;
  1647. }
  1648. } while (1);
  1649. return rval;
  1650. }
  1651. static int ql4_84xx_ipmdio_wr_reg(struct scsi_qla_host *ha,
  1652. uint32_t addr1, uint32_t addr3,
  1653. uint32_t mask, uint32_t addr,
  1654. uint32_t value)
  1655. {
  1656. int rval = QLA_SUCCESS;
  1657. rval = ql4_84xx_poll_wait_for_ready(ha, addr1, mask);
  1658. if (rval)
  1659. goto exit_ipmdio_wr_reg;
  1660. ha->isp_ops->wr_reg_indirect(ha, addr3, value);
  1661. ha->isp_ops->wr_reg_indirect(ha, addr1, addr);
  1662. rval = ql4_84xx_poll_wait_for_ready(ha, addr1, mask);
  1663. if (rval)
  1664. goto exit_ipmdio_wr_reg;
  1665. exit_ipmdio_wr_reg:
  1666. return rval;
  1667. }
  1668. static void qla4_8xxx_minidump_process_rdcrb(struct scsi_qla_host *ha,
  1669. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  1670. uint32_t **d_ptr)
  1671. {
  1672. uint32_t r_addr, r_stride, loop_cnt, i, r_value;
  1673. struct qla8xxx_minidump_entry_crb *crb_hdr;
  1674. uint32_t *data_ptr = *d_ptr;
  1675. DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
  1676. crb_hdr = (struct qla8xxx_minidump_entry_crb *)entry_hdr;
  1677. r_addr = crb_hdr->addr;
  1678. r_stride = crb_hdr->crb_strd.addr_stride;
  1679. loop_cnt = crb_hdr->op_count;
  1680. for (i = 0; i < loop_cnt; i++) {
  1681. ha->isp_ops->rd_reg_indirect(ha, r_addr, &r_value);
  1682. *data_ptr++ = cpu_to_le32(r_addr);
  1683. *data_ptr++ = cpu_to_le32(r_value);
  1684. r_addr += r_stride;
  1685. }
  1686. *d_ptr = data_ptr;
  1687. }
  1688. static int qla4_83xx_check_dma_engine_state(struct scsi_qla_host *ha)
  1689. {
  1690. int rval = QLA_SUCCESS;
  1691. uint32_t dma_eng_num = 0, cmd_sts_and_cntrl = 0;
  1692. uint64_t dma_base_addr = 0;
  1693. struct qla4_8xxx_minidump_template_hdr *tmplt_hdr = NULL;
  1694. tmplt_hdr = (struct qla4_8xxx_minidump_template_hdr *)
  1695. ha->fw_dump_tmplt_hdr;
  1696. dma_eng_num =
  1697. tmplt_hdr->saved_state_array[QLA83XX_PEX_DMA_ENGINE_INDEX];
  1698. dma_base_addr = QLA83XX_PEX_DMA_BASE_ADDRESS +
  1699. (dma_eng_num * QLA83XX_PEX_DMA_NUM_OFFSET);
  1700. /* Read the pex-dma's command-status-and-control register. */
  1701. rval = ha->isp_ops->rd_reg_indirect(ha,
  1702. (dma_base_addr + QLA83XX_PEX_DMA_CMD_STS_AND_CNTRL),
  1703. &cmd_sts_and_cntrl);
  1704. if (rval)
  1705. return QLA_ERROR;
  1706. /* Check if requested pex-dma engine is available. */
  1707. if (cmd_sts_and_cntrl & BIT_31)
  1708. return QLA_SUCCESS;
  1709. else
  1710. return QLA_ERROR;
  1711. }
  1712. static int qla4_83xx_start_pex_dma(struct scsi_qla_host *ha,
  1713. struct qla4_83xx_minidump_entry_rdmem_pex_dma *m_hdr)
  1714. {
  1715. int rval = QLA_SUCCESS, wait = 0;
  1716. uint32_t dma_eng_num = 0, cmd_sts_and_cntrl = 0;
  1717. uint64_t dma_base_addr = 0;
  1718. struct qla4_8xxx_minidump_template_hdr *tmplt_hdr = NULL;
  1719. tmplt_hdr = (struct qla4_8xxx_minidump_template_hdr *)
  1720. ha->fw_dump_tmplt_hdr;
  1721. dma_eng_num =
  1722. tmplt_hdr->saved_state_array[QLA83XX_PEX_DMA_ENGINE_INDEX];
  1723. dma_base_addr = QLA83XX_PEX_DMA_BASE_ADDRESS +
  1724. (dma_eng_num * QLA83XX_PEX_DMA_NUM_OFFSET);
  1725. rval = ha->isp_ops->wr_reg_indirect(ha,
  1726. dma_base_addr + QLA83XX_PEX_DMA_CMD_ADDR_LOW,
  1727. m_hdr->desc_card_addr);
  1728. if (rval)
  1729. goto error_exit;
  1730. rval = ha->isp_ops->wr_reg_indirect(ha,
  1731. dma_base_addr + QLA83XX_PEX_DMA_CMD_ADDR_HIGH, 0);
  1732. if (rval)
  1733. goto error_exit;
  1734. rval = ha->isp_ops->wr_reg_indirect(ha,
  1735. dma_base_addr + QLA83XX_PEX_DMA_CMD_STS_AND_CNTRL,
  1736. m_hdr->start_dma_cmd);
  1737. if (rval)
  1738. goto error_exit;
  1739. /* Wait for dma operation to complete. */
  1740. for (wait = 0; wait < QLA83XX_PEX_DMA_MAX_WAIT; wait++) {
  1741. rval = ha->isp_ops->rd_reg_indirect(ha,
  1742. (dma_base_addr + QLA83XX_PEX_DMA_CMD_STS_AND_CNTRL),
  1743. &cmd_sts_and_cntrl);
  1744. if (rval)
  1745. goto error_exit;
  1746. if ((cmd_sts_and_cntrl & BIT_1) == 0)
  1747. break;
  1748. else
  1749. udelay(10);
  1750. }
  1751. /* Wait a max of 100 ms, otherwise fallback to rdmem entry read */
  1752. if (wait >= QLA83XX_PEX_DMA_MAX_WAIT) {
  1753. rval = QLA_ERROR;
  1754. goto error_exit;
  1755. }
  1756. error_exit:
  1757. return rval;
  1758. }
  1759. static int qla4_8xxx_minidump_pex_dma_read(struct scsi_qla_host *ha,
  1760. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  1761. uint32_t **d_ptr)
  1762. {
  1763. int rval = QLA_SUCCESS;
  1764. struct qla4_83xx_minidump_entry_rdmem_pex_dma *m_hdr = NULL;
  1765. uint32_t size, read_size;
  1766. uint8_t *data_ptr = (uint8_t *)*d_ptr;
  1767. void *rdmem_buffer = NULL;
  1768. dma_addr_t rdmem_dma;
  1769. struct qla4_83xx_pex_dma_descriptor dma_desc;
  1770. DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
  1771. rval = qla4_83xx_check_dma_engine_state(ha);
  1772. if (rval != QLA_SUCCESS) {
  1773. DEBUG2(ql4_printk(KERN_INFO, ha,
  1774. "%s: DMA engine not available. Fallback to rdmem-read.\n",
  1775. __func__));
  1776. return QLA_ERROR;
  1777. }
  1778. m_hdr = (struct qla4_83xx_minidump_entry_rdmem_pex_dma *)entry_hdr;
  1779. rdmem_buffer = dma_alloc_coherent(&ha->pdev->dev,
  1780. QLA83XX_PEX_DMA_READ_SIZE,
  1781. &rdmem_dma, GFP_KERNEL);
  1782. if (!rdmem_buffer) {
  1783. DEBUG2(ql4_printk(KERN_INFO, ha,
  1784. "%s: Unable to allocate rdmem dma buffer\n",
  1785. __func__));
  1786. return QLA_ERROR;
  1787. }
  1788. /* Prepare pex-dma descriptor to be written to MS memory. */
  1789. /* dma-desc-cmd layout:
  1790. * 0-3: dma-desc-cmd 0-3
  1791. * 4-7: pcid function number
  1792. * 8-15: dma-desc-cmd 8-15
  1793. */
  1794. dma_desc.cmd.dma_desc_cmd = (m_hdr->dma_desc_cmd & 0xff0f);
  1795. dma_desc.cmd.dma_desc_cmd |= ((PCI_FUNC(ha->pdev->devfn) & 0xf) << 0x4);
  1796. dma_desc.dma_bus_addr = rdmem_dma;
  1797. size = 0;
  1798. read_size = 0;
  1799. /*
  1800. * Perform rdmem operation using pex-dma.
  1801. * Prepare dma in chunks of QLA83XX_PEX_DMA_READ_SIZE.
  1802. */
  1803. while (read_size < m_hdr->read_data_size) {
  1804. if (m_hdr->read_data_size - read_size >=
  1805. QLA83XX_PEX_DMA_READ_SIZE)
  1806. size = QLA83XX_PEX_DMA_READ_SIZE;
  1807. else {
  1808. size = (m_hdr->read_data_size - read_size);
  1809. if (rdmem_buffer)
  1810. dma_free_coherent(&ha->pdev->dev,
  1811. QLA83XX_PEX_DMA_READ_SIZE,
  1812. rdmem_buffer, rdmem_dma);
  1813. rdmem_buffer = dma_alloc_coherent(&ha->pdev->dev, size,
  1814. &rdmem_dma,
  1815. GFP_KERNEL);
  1816. if (!rdmem_buffer) {
  1817. DEBUG2(ql4_printk(KERN_INFO, ha,
  1818. "%s: Unable to allocate rdmem dma buffer\n",
  1819. __func__));
  1820. return QLA_ERROR;
  1821. }
  1822. dma_desc.dma_bus_addr = rdmem_dma;
  1823. }
  1824. dma_desc.src_addr = m_hdr->read_addr + read_size;
  1825. dma_desc.cmd.read_data_size = size;
  1826. /* Prepare: Write pex-dma descriptor to MS memory. */
  1827. rval = qla4_8xxx_ms_mem_write_128b(ha,
  1828. (uint64_t)m_hdr->desc_card_addr,
  1829. (uint32_t *)&dma_desc,
  1830. (sizeof(struct qla4_83xx_pex_dma_descriptor)/16));
  1831. if (rval != QLA_SUCCESS) {
  1832. ql4_printk(KERN_INFO, ha,
  1833. "%s: Error writing rdmem-dma-init to MS !!!\n",
  1834. __func__);
  1835. goto error_exit;
  1836. }
  1837. DEBUG2(ql4_printk(KERN_INFO, ha,
  1838. "%s: Dma-desc: Instruct for rdmem dma (size 0x%x).\n",
  1839. __func__, size));
  1840. /* Execute: Start pex-dma operation. */
  1841. rval = qla4_83xx_start_pex_dma(ha, m_hdr);
  1842. if (rval != QLA_SUCCESS) {
  1843. DEBUG2(ql4_printk(KERN_INFO, ha,
  1844. "scsi(%ld): start-pex-dma failed rval=0x%x\n",
  1845. ha->host_no, rval));
  1846. goto error_exit;
  1847. }
  1848. memcpy(data_ptr, rdmem_buffer, size);
  1849. data_ptr += size;
  1850. read_size += size;
  1851. }
  1852. DEBUG2(ql4_printk(KERN_INFO, ha, "Leaving fn: %s\n", __func__));
  1853. *d_ptr = (uint32_t *)data_ptr;
  1854. error_exit:
  1855. if (rdmem_buffer)
  1856. dma_free_coherent(&ha->pdev->dev, size, rdmem_buffer,
  1857. rdmem_dma);
  1858. return rval;
  1859. }
  1860. static int qla4_8xxx_minidump_process_l2tag(struct scsi_qla_host *ha,
  1861. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  1862. uint32_t **d_ptr)
  1863. {
  1864. uint32_t addr, r_addr, c_addr, t_r_addr;
  1865. uint32_t i, k, loop_count, t_value, r_cnt, r_value;
  1866. unsigned long p_wait, w_time, p_mask;
  1867. uint32_t c_value_w, c_value_r;
  1868. struct qla8xxx_minidump_entry_cache *cache_hdr;
  1869. int rval = QLA_ERROR;
  1870. uint32_t *data_ptr = *d_ptr;
  1871. DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
  1872. cache_hdr = (struct qla8xxx_minidump_entry_cache *)entry_hdr;
  1873. loop_count = cache_hdr->op_count;
  1874. r_addr = cache_hdr->read_addr;
  1875. c_addr = cache_hdr->control_addr;
  1876. c_value_w = cache_hdr->cache_ctrl.write_value;
  1877. t_r_addr = cache_hdr->tag_reg_addr;
  1878. t_value = cache_hdr->addr_ctrl.init_tag_value;
  1879. r_cnt = cache_hdr->read_ctrl.read_addr_cnt;
  1880. p_wait = cache_hdr->cache_ctrl.poll_wait;
  1881. p_mask = cache_hdr->cache_ctrl.poll_mask;
  1882. for (i = 0; i < loop_count; i++) {
  1883. ha->isp_ops->wr_reg_indirect(ha, t_r_addr, t_value);
  1884. if (c_value_w)
  1885. ha->isp_ops->wr_reg_indirect(ha, c_addr, c_value_w);
  1886. if (p_mask) {
  1887. w_time = jiffies + p_wait;
  1888. do {
  1889. ha->isp_ops->rd_reg_indirect(ha, c_addr,
  1890. &c_value_r);
  1891. if ((c_value_r & p_mask) == 0) {
  1892. break;
  1893. } else if (time_after_eq(jiffies, w_time)) {
  1894. /* capturing dump failed */
  1895. return rval;
  1896. }
  1897. } while (1);
  1898. }
  1899. addr = r_addr;
  1900. for (k = 0; k < r_cnt; k++) {
  1901. ha->isp_ops->rd_reg_indirect(ha, addr, &r_value);
  1902. *data_ptr++ = cpu_to_le32(r_value);
  1903. addr += cache_hdr->read_ctrl.read_addr_stride;
  1904. }
  1905. t_value += cache_hdr->addr_ctrl.tag_value_stride;
  1906. }
  1907. *d_ptr = data_ptr;
  1908. return QLA_SUCCESS;
  1909. }
  1910. static int qla4_8xxx_minidump_process_control(struct scsi_qla_host *ha,
  1911. struct qla8xxx_minidump_entry_hdr *entry_hdr)
  1912. {
  1913. struct qla8xxx_minidump_entry_crb *crb_entry;
  1914. uint32_t read_value, opcode, poll_time, addr, index, rval = QLA_SUCCESS;
  1915. uint32_t crb_addr;
  1916. unsigned long wtime;
  1917. struct qla4_8xxx_minidump_template_hdr *tmplt_hdr;
  1918. int i;
  1919. DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
  1920. tmplt_hdr = (struct qla4_8xxx_minidump_template_hdr *)
  1921. ha->fw_dump_tmplt_hdr;
  1922. crb_entry = (struct qla8xxx_minidump_entry_crb *)entry_hdr;
  1923. crb_addr = crb_entry->addr;
  1924. for (i = 0; i < crb_entry->op_count; i++) {
  1925. opcode = crb_entry->crb_ctrl.opcode;
  1926. if (opcode & QLA8XXX_DBG_OPCODE_WR) {
  1927. ha->isp_ops->wr_reg_indirect(ha, crb_addr,
  1928. crb_entry->value_1);
  1929. opcode &= ~QLA8XXX_DBG_OPCODE_WR;
  1930. }
  1931. if (opcode & QLA8XXX_DBG_OPCODE_RW) {
  1932. ha->isp_ops->rd_reg_indirect(ha, crb_addr, &read_value);
  1933. ha->isp_ops->wr_reg_indirect(ha, crb_addr, read_value);
  1934. opcode &= ~QLA8XXX_DBG_OPCODE_RW;
  1935. }
  1936. if (opcode & QLA8XXX_DBG_OPCODE_AND) {
  1937. ha->isp_ops->rd_reg_indirect(ha, crb_addr, &read_value);
  1938. read_value &= crb_entry->value_2;
  1939. opcode &= ~QLA8XXX_DBG_OPCODE_AND;
  1940. if (opcode & QLA8XXX_DBG_OPCODE_OR) {
  1941. read_value |= crb_entry->value_3;
  1942. opcode &= ~QLA8XXX_DBG_OPCODE_OR;
  1943. }
  1944. ha->isp_ops->wr_reg_indirect(ha, crb_addr, read_value);
  1945. }
  1946. if (opcode & QLA8XXX_DBG_OPCODE_OR) {
  1947. ha->isp_ops->rd_reg_indirect(ha, crb_addr, &read_value);
  1948. read_value |= crb_entry->value_3;
  1949. ha->isp_ops->wr_reg_indirect(ha, crb_addr, read_value);
  1950. opcode &= ~QLA8XXX_DBG_OPCODE_OR;
  1951. }
  1952. if (opcode & QLA8XXX_DBG_OPCODE_POLL) {
  1953. poll_time = crb_entry->crb_strd.poll_timeout;
  1954. wtime = jiffies + poll_time;
  1955. ha->isp_ops->rd_reg_indirect(ha, crb_addr, &read_value);
  1956. do {
  1957. if ((read_value & crb_entry->value_2) ==
  1958. crb_entry->value_1) {
  1959. break;
  1960. } else if (time_after_eq(jiffies, wtime)) {
  1961. /* capturing dump failed */
  1962. rval = QLA_ERROR;
  1963. break;
  1964. } else {
  1965. ha->isp_ops->rd_reg_indirect(ha,
  1966. crb_addr, &read_value);
  1967. }
  1968. } while (1);
  1969. opcode &= ~QLA8XXX_DBG_OPCODE_POLL;
  1970. }
  1971. if (opcode & QLA8XXX_DBG_OPCODE_RDSTATE) {
  1972. if (crb_entry->crb_strd.state_index_a) {
  1973. index = crb_entry->crb_strd.state_index_a;
  1974. addr = tmplt_hdr->saved_state_array[index];
  1975. } else {
  1976. addr = crb_addr;
  1977. }
  1978. ha->isp_ops->rd_reg_indirect(ha, addr, &read_value);
  1979. index = crb_entry->crb_ctrl.state_index_v;
  1980. tmplt_hdr->saved_state_array[index] = read_value;
  1981. opcode &= ~QLA8XXX_DBG_OPCODE_RDSTATE;
  1982. }
  1983. if (opcode & QLA8XXX_DBG_OPCODE_WRSTATE) {
  1984. if (crb_entry->crb_strd.state_index_a) {
  1985. index = crb_entry->crb_strd.state_index_a;
  1986. addr = tmplt_hdr->saved_state_array[index];
  1987. } else {
  1988. addr = crb_addr;
  1989. }
  1990. if (crb_entry->crb_ctrl.state_index_v) {
  1991. index = crb_entry->crb_ctrl.state_index_v;
  1992. read_value =
  1993. tmplt_hdr->saved_state_array[index];
  1994. } else {
  1995. read_value = crb_entry->value_1;
  1996. }
  1997. ha->isp_ops->wr_reg_indirect(ha, addr, read_value);
  1998. opcode &= ~QLA8XXX_DBG_OPCODE_WRSTATE;
  1999. }
  2000. if (opcode & QLA8XXX_DBG_OPCODE_MDSTATE) {
  2001. index = crb_entry->crb_ctrl.state_index_v;
  2002. read_value = tmplt_hdr->saved_state_array[index];
  2003. read_value <<= crb_entry->crb_ctrl.shl;
  2004. read_value >>= crb_entry->crb_ctrl.shr;
  2005. if (crb_entry->value_2)
  2006. read_value &= crb_entry->value_2;
  2007. read_value |= crb_entry->value_3;
  2008. read_value += crb_entry->value_1;
  2009. tmplt_hdr->saved_state_array[index] = read_value;
  2010. opcode &= ~QLA8XXX_DBG_OPCODE_MDSTATE;
  2011. }
  2012. crb_addr += crb_entry->crb_strd.addr_stride;
  2013. }
  2014. DEBUG2(ql4_printk(KERN_INFO, ha, "Leaving fn: %s\n", __func__));
  2015. return rval;
  2016. }
  2017. static void qla4_8xxx_minidump_process_rdocm(struct scsi_qla_host *ha,
  2018. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  2019. uint32_t **d_ptr)
  2020. {
  2021. uint32_t r_addr, r_stride, loop_cnt, i, r_value;
  2022. struct qla8xxx_minidump_entry_rdocm *ocm_hdr;
  2023. uint32_t *data_ptr = *d_ptr;
  2024. DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
  2025. ocm_hdr = (struct qla8xxx_minidump_entry_rdocm *)entry_hdr;
  2026. r_addr = ocm_hdr->read_addr;
  2027. r_stride = ocm_hdr->read_addr_stride;
  2028. loop_cnt = ocm_hdr->op_count;
  2029. DEBUG2(ql4_printk(KERN_INFO, ha,
  2030. "[%s]: r_addr: 0x%x, r_stride: 0x%x, loop_cnt: 0x%x\n",
  2031. __func__, r_addr, r_stride, loop_cnt));
  2032. for (i = 0; i < loop_cnt; i++) {
  2033. r_value = readl((void __iomem *)(r_addr + ha->nx_pcibase));
  2034. *data_ptr++ = cpu_to_le32(r_value);
  2035. r_addr += r_stride;
  2036. }
  2037. DEBUG2(ql4_printk(KERN_INFO, ha, "Leaving fn: %s datacount: 0x%lx\n",
  2038. __func__, (long unsigned int) (loop_cnt * sizeof(uint32_t))));
  2039. *d_ptr = data_ptr;
  2040. }
  2041. static void qla4_8xxx_minidump_process_rdmux(struct scsi_qla_host *ha,
  2042. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  2043. uint32_t **d_ptr)
  2044. {
  2045. uint32_t r_addr, s_stride, s_addr, s_value, loop_cnt, i, r_value;
  2046. struct qla8xxx_minidump_entry_mux *mux_hdr;
  2047. uint32_t *data_ptr = *d_ptr;
  2048. DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
  2049. mux_hdr = (struct qla8xxx_minidump_entry_mux *)entry_hdr;
  2050. r_addr = mux_hdr->read_addr;
  2051. s_addr = mux_hdr->select_addr;
  2052. s_stride = mux_hdr->select_value_stride;
  2053. s_value = mux_hdr->select_value;
  2054. loop_cnt = mux_hdr->op_count;
  2055. for (i = 0; i < loop_cnt; i++) {
  2056. ha->isp_ops->wr_reg_indirect(ha, s_addr, s_value);
  2057. ha->isp_ops->rd_reg_indirect(ha, r_addr, &r_value);
  2058. *data_ptr++ = cpu_to_le32(s_value);
  2059. *data_ptr++ = cpu_to_le32(r_value);
  2060. s_value += s_stride;
  2061. }
  2062. *d_ptr = data_ptr;
  2063. }
  2064. static void qla4_8xxx_minidump_process_l1cache(struct scsi_qla_host *ha,
  2065. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  2066. uint32_t **d_ptr)
  2067. {
  2068. uint32_t addr, r_addr, c_addr, t_r_addr;
  2069. uint32_t i, k, loop_count, t_value, r_cnt, r_value;
  2070. uint32_t c_value_w;
  2071. struct qla8xxx_minidump_entry_cache *cache_hdr;
  2072. uint32_t *data_ptr = *d_ptr;
  2073. cache_hdr = (struct qla8xxx_minidump_entry_cache *)entry_hdr;
  2074. loop_count = cache_hdr->op_count;
  2075. r_addr = cache_hdr->read_addr;
  2076. c_addr = cache_hdr->control_addr;
  2077. c_value_w = cache_hdr->cache_ctrl.write_value;
  2078. t_r_addr = cache_hdr->tag_reg_addr;
  2079. t_value = cache_hdr->addr_ctrl.init_tag_value;
  2080. r_cnt = cache_hdr->read_ctrl.read_addr_cnt;
  2081. for (i = 0; i < loop_count; i++) {
  2082. ha->isp_ops->wr_reg_indirect(ha, t_r_addr, t_value);
  2083. ha->isp_ops->wr_reg_indirect(ha, c_addr, c_value_w);
  2084. addr = r_addr;
  2085. for (k = 0; k < r_cnt; k++) {
  2086. ha->isp_ops->rd_reg_indirect(ha, addr, &r_value);
  2087. *data_ptr++ = cpu_to_le32(r_value);
  2088. addr += cache_hdr->read_ctrl.read_addr_stride;
  2089. }
  2090. t_value += cache_hdr->addr_ctrl.tag_value_stride;
  2091. }
  2092. *d_ptr = data_ptr;
  2093. }
  2094. static void qla4_8xxx_minidump_process_queue(struct scsi_qla_host *ha,
  2095. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  2096. uint32_t **d_ptr)
  2097. {
  2098. uint32_t s_addr, r_addr;
  2099. uint32_t r_stride, r_value, r_cnt, qid = 0;
  2100. uint32_t i, k, loop_cnt;
  2101. struct qla8xxx_minidump_entry_queue *q_hdr;
  2102. uint32_t *data_ptr = *d_ptr;
  2103. DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
  2104. q_hdr = (struct qla8xxx_minidump_entry_queue *)entry_hdr;
  2105. s_addr = q_hdr->select_addr;
  2106. r_cnt = q_hdr->rd_strd.read_addr_cnt;
  2107. r_stride = q_hdr->rd_strd.read_addr_stride;
  2108. loop_cnt = q_hdr->op_count;
  2109. for (i = 0; i < loop_cnt; i++) {
  2110. ha->isp_ops->wr_reg_indirect(ha, s_addr, qid);
  2111. r_addr = q_hdr->read_addr;
  2112. for (k = 0; k < r_cnt; k++) {
  2113. ha->isp_ops->rd_reg_indirect(ha, r_addr, &r_value);
  2114. *data_ptr++ = cpu_to_le32(r_value);
  2115. r_addr += r_stride;
  2116. }
  2117. qid += q_hdr->q_strd.queue_id_stride;
  2118. }
  2119. *d_ptr = data_ptr;
  2120. }
  2121. #define MD_DIRECT_ROM_WINDOW 0x42110030
  2122. #define MD_DIRECT_ROM_READ_BASE 0x42150000
  2123. static void qla4_82xx_minidump_process_rdrom(struct scsi_qla_host *ha,
  2124. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  2125. uint32_t **d_ptr)
  2126. {
  2127. uint32_t r_addr, r_value;
  2128. uint32_t i, loop_cnt;
  2129. struct qla8xxx_minidump_entry_rdrom *rom_hdr;
  2130. uint32_t *data_ptr = *d_ptr;
  2131. DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
  2132. rom_hdr = (struct qla8xxx_minidump_entry_rdrom *)entry_hdr;
  2133. r_addr = rom_hdr->read_addr;
  2134. loop_cnt = rom_hdr->read_data_size/sizeof(uint32_t);
  2135. DEBUG2(ql4_printk(KERN_INFO, ha,
  2136. "[%s]: flash_addr: 0x%x, read_data_size: 0x%x\n",
  2137. __func__, r_addr, loop_cnt));
  2138. for (i = 0; i < loop_cnt; i++) {
  2139. ha->isp_ops->wr_reg_indirect(ha, MD_DIRECT_ROM_WINDOW,
  2140. (r_addr & 0xFFFF0000));
  2141. ha->isp_ops->rd_reg_indirect(ha,
  2142. MD_DIRECT_ROM_READ_BASE + (r_addr & 0x0000FFFF),
  2143. &r_value);
  2144. *data_ptr++ = cpu_to_le32(r_value);
  2145. r_addr += sizeof(uint32_t);
  2146. }
  2147. *d_ptr = data_ptr;
  2148. }
  2149. #define MD_MIU_TEST_AGT_CTRL 0x41000090
  2150. #define MD_MIU_TEST_AGT_ADDR_LO 0x41000094
  2151. #define MD_MIU_TEST_AGT_ADDR_HI 0x41000098
  2152. static int __qla4_8xxx_minidump_process_rdmem(struct scsi_qla_host *ha,
  2153. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  2154. uint32_t **d_ptr)
  2155. {
  2156. uint32_t r_addr, r_value, r_data;
  2157. uint32_t i, j, loop_cnt;
  2158. struct qla8xxx_minidump_entry_rdmem *m_hdr;
  2159. unsigned long flags;
  2160. uint32_t *data_ptr = *d_ptr;
  2161. DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
  2162. m_hdr = (struct qla8xxx_minidump_entry_rdmem *)entry_hdr;
  2163. r_addr = m_hdr->read_addr;
  2164. loop_cnt = m_hdr->read_data_size/16;
  2165. DEBUG2(ql4_printk(KERN_INFO, ha,
  2166. "[%s]: Read addr: 0x%x, read_data_size: 0x%x\n",
  2167. __func__, r_addr, m_hdr->read_data_size));
  2168. if (r_addr & 0xf) {
  2169. DEBUG2(ql4_printk(KERN_INFO, ha,
  2170. "[%s]: Read addr 0x%x not 16 bytes aligned\n",
  2171. __func__, r_addr));
  2172. return QLA_ERROR;
  2173. }
  2174. if (m_hdr->read_data_size % 16) {
  2175. DEBUG2(ql4_printk(KERN_INFO, ha,
  2176. "[%s]: Read data[0x%x] not multiple of 16 bytes\n",
  2177. __func__, m_hdr->read_data_size));
  2178. return QLA_ERROR;
  2179. }
  2180. DEBUG2(ql4_printk(KERN_INFO, ha,
  2181. "[%s]: rdmem_addr: 0x%x, read_data_size: 0x%x, loop_cnt: 0x%x\n",
  2182. __func__, r_addr, m_hdr->read_data_size, loop_cnt));
  2183. write_lock_irqsave(&ha->hw_lock, flags);
  2184. for (i = 0; i < loop_cnt; i++) {
  2185. ha->isp_ops->wr_reg_indirect(ha, MD_MIU_TEST_AGT_ADDR_LO,
  2186. r_addr);
  2187. r_value = 0;
  2188. ha->isp_ops->wr_reg_indirect(ha, MD_MIU_TEST_AGT_ADDR_HI,
  2189. r_value);
  2190. r_value = MIU_TA_CTL_ENABLE;
  2191. ha->isp_ops->wr_reg_indirect(ha, MD_MIU_TEST_AGT_CTRL, r_value);
  2192. r_value = MIU_TA_CTL_START_ENABLE;
  2193. ha->isp_ops->wr_reg_indirect(ha, MD_MIU_TEST_AGT_CTRL, r_value);
  2194. for (j = 0; j < MAX_CTL_CHECK; j++) {
  2195. ha->isp_ops->rd_reg_indirect(ha, MD_MIU_TEST_AGT_CTRL,
  2196. &r_value);
  2197. if ((r_value & MIU_TA_CTL_BUSY) == 0)
  2198. break;
  2199. }
  2200. if (j >= MAX_CTL_CHECK) {
  2201. printk_ratelimited(KERN_ERR
  2202. "%s: failed to read through agent\n",
  2203. __func__);
  2204. write_unlock_irqrestore(&ha->hw_lock, flags);
  2205. return QLA_SUCCESS;
  2206. }
  2207. for (j = 0; j < 4; j++) {
  2208. ha->isp_ops->rd_reg_indirect(ha,
  2209. MD_MIU_TEST_AGT_RDDATA[j],
  2210. &r_data);
  2211. *data_ptr++ = cpu_to_le32(r_data);
  2212. }
  2213. r_addr += 16;
  2214. }
  2215. write_unlock_irqrestore(&ha->hw_lock, flags);
  2216. DEBUG2(ql4_printk(KERN_INFO, ha, "Leaving fn: %s datacount: 0x%x\n",
  2217. __func__, (loop_cnt * 16)));
  2218. *d_ptr = data_ptr;
  2219. return QLA_SUCCESS;
  2220. }
  2221. static int qla4_8xxx_minidump_process_rdmem(struct scsi_qla_host *ha,
  2222. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  2223. uint32_t **d_ptr)
  2224. {
  2225. uint32_t *data_ptr = *d_ptr;
  2226. int rval = QLA_SUCCESS;
  2227. rval = qla4_8xxx_minidump_pex_dma_read(ha, entry_hdr, &data_ptr);
  2228. if (rval != QLA_SUCCESS)
  2229. rval = __qla4_8xxx_minidump_process_rdmem(ha, entry_hdr,
  2230. &data_ptr);
  2231. *d_ptr = data_ptr;
  2232. return rval;
  2233. }
  2234. static void qla4_8xxx_mark_entry_skipped(struct scsi_qla_host *ha,
  2235. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  2236. int index)
  2237. {
  2238. entry_hdr->d_ctrl.driver_flags |= QLA8XXX_DBG_SKIPPED_FLAG;
  2239. DEBUG2(ql4_printk(KERN_INFO, ha,
  2240. "scsi(%ld): Skipping entry[%d]: ETYPE[0x%x]-ELEVEL[0x%x]\n",
  2241. ha->host_no, index, entry_hdr->entry_type,
  2242. entry_hdr->d_ctrl.entry_capture_mask));
  2243. /* If driver encounters a new entry type that it cannot process,
  2244. * it should just skip the entry and adjust the total buffer size by
  2245. * from subtracting the skipped bytes from it
  2246. */
  2247. ha->fw_dump_skip_size += entry_hdr->entry_capture_size;
  2248. }
  2249. /* ISP83xx functions to process new minidump entries... */
  2250. static uint32_t qla83xx_minidump_process_pollrd(struct scsi_qla_host *ha,
  2251. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  2252. uint32_t **d_ptr)
  2253. {
  2254. uint32_t r_addr, s_addr, s_value, r_value, poll_wait, poll_mask;
  2255. uint16_t s_stride, i;
  2256. uint32_t *data_ptr = *d_ptr;
  2257. uint32_t rval = QLA_SUCCESS;
  2258. struct qla83xx_minidump_entry_pollrd *pollrd_hdr;
  2259. pollrd_hdr = (struct qla83xx_minidump_entry_pollrd *)entry_hdr;
  2260. s_addr = le32_to_cpu(pollrd_hdr->select_addr);
  2261. r_addr = le32_to_cpu(pollrd_hdr->read_addr);
  2262. s_value = le32_to_cpu(pollrd_hdr->select_value);
  2263. s_stride = le32_to_cpu(pollrd_hdr->select_value_stride);
  2264. poll_wait = le32_to_cpu(pollrd_hdr->poll_wait);
  2265. poll_mask = le32_to_cpu(pollrd_hdr->poll_mask);
  2266. for (i = 0; i < le32_to_cpu(pollrd_hdr->op_count); i++) {
  2267. ha->isp_ops->wr_reg_indirect(ha, s_addr, s_value);
  2268. poll_wait = le32_to_cpu(pollrd_hdr->poll_wait);
  2269. while (1) {
  2270. ha->isp_ops->rd_reg_indirect(ha, s_addr, &r_value);
  2271. if ((r_value & poll_mask) != 0) {
  2272. break;
  2273. } else {
  2274. msleep(1);
  2275. if (--poll_wait == 0) {
  2276. ql4_printk(KERN_ERR, ha, "%s: TIMEOUT\n",
  2277. __func__);
  2278. rval = QLA_ERROR;
  2279. goto exit_process_pollrd;
  2280. }
  2281. }
  2282. }
  2283. ha->isp_ops->rd_reg_indirect(ha, r_addr, &r_value);
  2284. *data_ptr++ = cpu_to_le32(s_value);
  2285. *data_ptr++ = cpu_to_le32(r_value);
  2286. s_value += s_stride;
  2287. }
  2288. *d_ptr = data_ptr;
  2289. exit_process_pollrd:
  2290. return rval;
  2291. }
  2292. static uint32_t qla4_84xx_minidump_process_rddfe(struct scsi_qla_host *ha,
  2293. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  2294. uint32_t **d_ptr)
  2295. {
  2296. int loop_cnt;
  2297. uint32_t addr1, addr2, value, data, temp, wrval;
  2298. uint8_t stride, stride2;
  2299. uint16_t count;
  2300. uint32_t poll, mask, data_size, modify_mask;
  2301. uint32_t wait_count = 0;
  2302. uint32_t *data_ptr = *d_ptr;
  2303. struct qla8044_minidump_entry_rddfe *rddfe;
  2304. uint32_t rval = QLA_SUCCESS;
  2305. rddfe = (struct qla8044_minidump_entry_rddfe *)entry_hdr;
  2306. addr1 = le32_to_cpu(rddfe->addr_1);
  2307. value = le32_to_cpu(rddfe->value);
  2308. stride = le32_to_cpu(rddfe->stride);
  2309. stride2 = le32_to_cpu(rddfe->stride2);
  2310. count = le32_to_cpu(rddfe->count);
  2311. poll = le32_to_cpu(rddfe->poll);
  2312. mask = le32_to_cpu(rddfe->mask);
  2313. modify_mask = le32_to_cpu(rddfe->modify_mask);
  2314. data_size = le32_to_cpu(rddfe->data_size);
  2315. addr2 = addr1 + stride;
  2316. for (loop_cnt = 0x0; loop_cnt < count; loop_cnt++) {
  2317. ha->isp_ops->wr_reg_indirect(ha, addr1, (0x40000000 | value));
  2318. wait_count = 0;
  2319. while (wait_count < poll) {
  2320. ha->isp_ops->rd_reg_indirect(ha, addr1, &temp);
  2321. if ((temp & mask) != 0)
  2322. break;
  2323. wait_count++;
  2324. }
  2325. if (wait_count == poll) {
  2326. ql4_printk(KERN_ERR, ha, "%s: TIMEOUT\n", __func__);
  2327. rval = QLA_ERROR;
  2328. goto exit_process_rddfe;
  2329. } else {
  2330. ha->isp_ops->rd_reg_indirect(ha, addr2, &temp);
  2331. temp = temp & modify_mask;
  2332. temp = (temp | ((loop_cnt << 16) | loop_cnt));
  2333. wrval = ((temp << 16) | temp);
  2334. ha->isp_ops->wr_reg_indirect(ha, addr2, wrval);
  2335. ha->isp_ops->wr_reg_indirect(ha, addr1, value);
  2336. wait_count = 0;
  2337. while (wait_count < poll) {
  2338. ha->isp_ops->rd_reg_indirect(ha, addr1, &temp);
  2339. if ((temp & mask) != 0)
  2340. break;
  2341. wait_count++;
  2342. }
  2343. if (wait_count == poll) {
  2344. ql4_printk(KERN_ERR, ha, "%s: TIMEOUT\n",
  2345. __func__);
  2346. rval = QLA_ERROR;
  2347. goto exit_process_rddfe;
  2348. }
  2349. ha->isp_ops->wr_reg_indirect(ha, addr1,
  2350. ((0x40000000 | value) +
  2351. stride2));
  2352. wait_count = 0;
  2353. while (wait_count < poll) {
  2354. ha->isp_ops->rd_reg_indirect(ha, addr1, &temp);
  2355. if ((temp & mask) != 0)
  2356. break;
  2357. wait_count++;
  2358. }
  2359. if (wait_count == poll) {
  2360. ql4_printk(KERN_ERR, ha, "%s: TIMEOUT\n",
  2361. __func__);
  2362. rval = QLA_ERROR;
  2363. goto exit_process_rddfe;
  2364. }
  2365. ha->isp_ops->rd_reg_indirect(ha, addr2, &data);
  2366. *data_ptr++ = cpu_to_le32(wrval);
  2367. *data_ptr++ = cpu_to_le32(data);
  2368. }
  2369. }
  2370. *d_ptr = data_ptr;
  2371. exit_process_rddfe:
  2372. return rval;
  2373. }
  2374. static uint32_t qla4_84xx_minidump_process_rdmdio(struct scsi_qla_host *ha,
  2375. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  2376. uint32_t **d_ptr)
  2377. {
  2378. int rval = QLA_SUCCESS;
  2379. uint32_t addr1, addr2, value1, value2, data, selval;
  2380. uint8_t stride1, stride2;
  2381. uint32_t addr3, addr4, addr5, addr6, addr7;
  2382. uint16_t count, loop_cnt;
  2383. uint32_t poll, mask;
  2384. uint32_t *data_ptr = *d_ptr;
  2385. struct qla8044_minidump_entry_rdmdio *rdmdio;
  2386. rdmdio = (struct qla8044_minidump_entry_rdmdio *)entry_hdr;
  2387. addr1 = le32_to_cpu(rdmdio->addr_1);
  2388. addr2 = le32_to_cpu(rdmdio->addr_2);
  2389. value1 = le32_to_cpu(rdmdio->value_1);
  2390. stride1 = le32_to_cpu(rdmdio->stride_1);
  2391. stride2 = le32_to_cpu(rdmdio->stride_2);
  2392. count = le32_to_cpu(rdmdio->count);
  2393. poll = le32_to_cpu(rdmdio->poll);
  2394. mask = le32_to_cpu(rdmdio->mask);
  2395. value2 = le32_to_cpu(rdmdio->value_2);
  2396. addr3 = addr1 + stride1;
  2397. for (loop_cnt = 0; loop_cnt < count; loop_cnt++) {
  2398. rval = ql4_84xx_poll_wait_ipmdio_bus_idle(ha, addr1, addr2,
  2399. addr3, mask);
  2400. if (rval)
  2401. goto exit_process_rdmdio;
  2402. addr4 = addr2 - stride1;
  2403. rval = ql4_84xx_ipmdio_wr_reg(ha, addr1, addr3, mask, addr4,
  2404. value2);
  2405. if (rval)
  2406. goto exit_process_rdmdio;
  2407. addr5 = addr2 - (2 * stride1);
  2408. rval = ql4_84xx_ipmdio_wr_reg(ha, addr1, addr3, mask, addr5,
  2409. value1);
  2410. if (rval)
  2411. goto exit_process_rdmdio;
  2412. addr6 = addr2 - (3 * stride1);
  2413. rval = ql4_84xx_ipmdio_wr_reg(ha, addr1, addr3, mask,
  2414. addr6, 0x2);
  2415. if (rval)
  2416. goto exit_process_rdmdio;
  2417. rval = ql4_84xx_poll_wait_ipmdio_bus_idle(ha, addr1, addr2,
  2418. addr3, mask);
  2419. if (rval)
  2420. goto exit_process_rdmdio;
  2421. addr7 = addr2 - (4 * stride1);
  2422. rval = ql4_84xx_ipmdio_rd_reg(ha, addr1, addr3,
  2423. mask, addr7, &data);
  2424. if (rval)
  2425. goto exit_process_rdmdio;
  2426. selval = (value2 << 18) | (value1 << 2) | 2;
  2427. stride2 = le32_to_cpu(rdmdio->stride_2);
  2428. *data_ptr++ = cpu_to_le32(selval);
  2429. *data_ptr++ = cpu_to_le32(data);
  2430. value1 = value1 + stride2;
  2431. *d_ptr = data_ptr;
  2432. }
  2433. exit_process_rdmdio:
  2434. return rval;
  2435. }
  2436. static uint32_t qla4_84xx_minidump_process_pollwr(struct scsi_qla_host *ha,
  2437. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  2438. uint32_t **d_ptr)
  2439. {
  2440. uint32_t addr1, addr2, value1, value2, poll, mask, r_value;
  2441. struct qla8044_minidump_entry_pollwr *pollwr_hdr;
  2442. uint32_t wait_count = 0;
  2443. uint32_t rval = QLA_SUCCESS;
  2444. pollwr_hdr = (struct qla8044_minidump_entry_pollwr *)entry_hdr;
  2445. addr1 = le32_to_cpu(pollwr_hdr->addr_1);
  2446. addr2 = le32_to_cpu(pollwr_hdr->addr_2);
  2447. value1 = le32_to_cpu(pollwr_hdr->value_1);
  2448. value2 = le32_to_cpu(pollwr_hdr->value_2);
  2449. poll = le32_to_cpu(pollwr_hdr->poll);
  2450. mask = le32_to_cpu(pollwr_hdr->mask);
  2451. while (wait_count < poll) {
  2452. ha->isp_ops->rd_reg_indirect(ha, addr1, &r_value);
  2453. if ((r_value & poll) != 0)
  2454. break;
  2455. wait_count++;
  2456. }
  2457. if (wait_count == poll) {
  2458. ql4_printk(KERN_ERR, ha, "%s: TIMEOUT\n", __func__);
  2459. rval = QLA_ERROR;
  2460. goto exit_process_pollwr;
  2461. }
  2462. ha->isp_ops->wr_reg_indirect(ha, addr2, value2);
  2463. ha->isp_ops->wr_reg_indirect(ha, addr1, value1);
  2464. wait_count = 0;
  2465. while (wait_count < poll) {
  2466. ha->isp_ops->rd_reg_indirect(ha, addr1, &r_value);
  2467. if ((r_value & poll) != 0)
  2468. break;
  2469. wait_count++;
  2470. }
  2471. exit_process_pollwr:
  2472. return rval;
  2473. }
  2474. static void qla83xx_minidump_process_rdmux2(struct scsi_qla_host *ha,
  2475. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  2476. uint32_t **d_ptr)
  2477. {
  2478. uint32_t sel_val1, sel_val2, t_sel_val, data, i;
  2479. uint32_t sel_addr1, sel_addr2, sel_val_mask, read_addr;
  2480. struct qla83xx_minidump_entry_rdmux2 *rdmux2_hdr;
  2481. uint32_t *data_ptr = *d_ptr;
  2482. rdmux2_hdr = (struct qla83xx_minidump_entry_rdmux2 *)entry_hdr;
  2483. sel_val1 = le32_to_cpu(rdmux2_hdr->select_value_1);
  2484. sel_val2 = le32_to_cpu(rdmux2_hdr->select_value_2);
  2485. sel_addr1 = le32_to_cpu(rdmux2_hdr->select_addr_1);
  2486. sel_addr2 = le32_to_cpu(rdmux2_hdr->select_addr_2);
  2487. sel_val_mask = le32_to_cpu(rdmux2_hdr->select_value_mask);
  2488. read_addr = le32_to_cpu(rdmux2_hdr->read_addr);
  2489. for (i = 0; i < rdmux2_hdr->op_count; i++) {
  2490. ha->isp_ops->wr_reg_indirect(ha, sel_addr1, sel_val1);
  2491. t_sel_val = sel_val1 & sel_val_mask;
  2492. *data_ptr++ = cpu_to_le32(t_sel_val);
  2493. ha->isp_ops->wr_reg_indirect(ha, sel_addr2, t_sel_val);
  2494. ha->isp_ops->rd_reg_indirect(ha, read_addr, &data);
  2495. *data_ptr++ = cpu_to_le32(data);
  2496. ha->isp_ops->wr_reg_indirect(ha, sel_addr1, sel_val2);
  2497. t_sel_val = sel_val2 & sel_val_mask;
  2498. *data_ptr++ = cpu_to_le32(t_sel_val);
  2499. ha->isp_ops->wr_reg_indirect(ha, sel_addr2, t_sel_val);
  2500. ha->isp_ops->rd_reg_indirect(ha, read_addr, &data);
  2501. *data_ptr++ = cpu_to_le32(data);
  2502. sel_val1 += rdmux2_hdr->select_value_stride;
  2503. sel_val2 += rdmux2_hdr->select_value_stride;
  2504. }
  2505. *d_ptr = data_ptr;
  2506. }
  2507. static uint32_t qla83xx_minidump_process_pollrdmwr(struct scsi_qla_host *ha,
  2508. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  2509. uint32_t **d_ptr)
  2510. {
  2511. uint32_t poll_wait, poll_mask, r_value, data;
  2512. uint32_t addr_1, addr_2, value_1, value_2;
  2513. uint32_t *data_ptr = *d_ptr;
  2514. uint32_t rval = QLA_SUCCESS;
  2515. struct qla83xx_minidump_entry_pollrdmwr *poll_hdr;
  2516. poll_hdr = (struct qla83xx_minidump_entry_pollrdmwr *)entry_hdr;
  2517. addr_1 = le32_to_cpu(poll_hdr->addr_1);
  2518. addr_2 = le32_to_cpu(poll_hdr->addr_2);
  2519. value_1 = le32_to_cpu(poll_hdr->value_1);
  2520. value_2 = le32_to_cpu(poll_hdr->value_2);
  2521. poll_mask = le32_to_cpu(poll_hdr->poll_mask);
  2522. ha->isp_ops->wr_reg_indirect(ha, addr_1, value_1);
  2523. poll_wait = le32_to_cpu(poll_hdr->poll_wait);
  2524. while (1) {
  2525. ha->isp_ops->rd_reg_indirect(ha, addr_1, &r_value);
  2526. if ((r_value & poll_mask) != 0) {
  2527. break;
  2528. } else {
  2529. msleep(1);
  2530. if (--poll_wait == 0) {
  2531. ql4_printk(KERN_ERR, ha, "%s: TIMEOUT_1\n",
  2532. __func__);
  2533. rval = QLA_ERROR;
  2534. goto exit_process_pollrdmwr;
  2535. }
  2536. }
  2537. }
  2538. ha->isp_ops->rd_reg_indirect(ha, addr_2, &data);
  2539. data &= le32_to_cpu(poll_hdr->modify_mask);
  2540. ha->isp_ops->wr_reg_indirect(ha, addr_2, data);
  2541. ha->isp_ops->wr_reg_indirect(ha, addr_1, value_2);
  2542. poll_wait = le32_to_cpu(poll_hdr->poll_wait);
  2543. while (1) {
  2544. ha->isp_ops->rd_reg_indirect(ha, addr_1, &r_value);
  2545. if ((r_value & poll_mask) != 0) {
  2546. break;
  2547. } else {
  2548. msleep(1);
  2549. if (--poll_wait == 0) {
  2550. ql4_printk(KERN_ERR, ha, "%s: TIMEOUT_2\n",
  2551. __func__);
  2552. rval = QLA_ERROR;
  2553. goto exit_process_pollrdmwr;
  2554. }
  2555. }
  2556. }
  2557. *data_ptr++ = cpu_to_le32(addr_2);
  2558. *data_ptr++ = cpu_to_le32(data);
  2559. *d_ptr = data_ptr;
  2560. exit_process_pollrdmwr:
  2561. return rval;
  2562. }
  2563. static uint32_t qla4_83xx_minidump_process_rdrom(struct scsi_qla_host *ha,
  2564. struct qla8xxx_minidump_entry_hdr *entry_hdr,
  2565. uint32_t **d_ptr)
  2566. {
  2567. uint32_t fl_addr, u32_count, rval;
  2568. struct qla8xxx_minidump_entry_rdrom *rom_hdr;
  2569. uint32_t *data_ptr = *d_ptr;
  2570. rom_hdr = (struct qla8xxx_minidump_entry_rdrom *)entry_hdr;
  2571. fl_addr = le32_to_cpu(rom_hdr->read_addr);
  2572. u32_count = le32_to_cpu(rom_hdr->read_data_size)/sizeof(uint32_t);
  2573. DEBUG2(ql4_printk(KERN_INFO, ha, "[%s]: fl_addr: 0x%x, count: 0x%x\n",
  2574. __func__, fl_addr, u32_count));
  2575. rval = qla4_83xx_lockless_flash_read_u32(ha, fl_addr,
  2576. (u8 *)(data_ptr), u32_count);
  2577. if (rval == QLA_ERROR) {
  2578. ql4_printk(KERN_ERR, ha, "%s: Flash Read Error,Count=%d\n",
  2579. __func__, u32_count);
  2580. goto exit_process_rdrom;
  2581. }
  2582. data_ptr += u32_count;
  2583. *d_ptr = data_ptr;
  2584. exit_process_rdrom:
  2585. return rval;
  2586. }
  2587. /**
  2588. * qla4_8xxx_collect_md_data - Retrieve firmware minidump data.
  2589. * @ha: pointer to adapter structure
  2590. **/
  2591. static int qla4_8xxx_collect_md_data(struct scsi_qla_host *ha)
  2592. {
  2593. int num_entry_hdr = 0;
  2594. struct qla8xxx_minidump_entry_hdr *entry_hdr;
  2595. struct qla4_8xxx_minidump_template_hdr *tmplt_hdr;
  2596. uint32_t *data_ptr;
  2597. uint32_t data_collected = 0;
  2598. int i, rval = QLA_ERROR;
  2599. uint64_t now;
  2600. uint32_t timestamp;
  2601. ha->fw_dump_skip_size = 0;
  2602. if (!ha->fw_dump) {
  2603. ql4_printk(KERN_INFO, ha, "%s(%ld) No buffer to dump\n",
  2604. __func__, ha->host_no);
  2605. return rval;
  2606. }
  2607. tmplt_hdr = (struct qla4_8xxx_minidump_template_hdr *)
  2608. ha->fw_dump_tmplt_hdr;
  2609. data_ptr = (uint32_t *)((uint8_t *)ha->fw_dump +
  2610. ha->fw_dump_tmplt_size);
  2611. data_collected += ha->fw_dump_tmplt_size;
  2612. num_entry_hdr = tmplt_hdr->num_of_entries;
  2613. ql4_printk(KERN_INFO, ha, "[%s]: starting data ptr: %p\n",
  2614. __func__, data_ptr);
  2615. ql4_printk(KERN_INFO, ha,
  2616. "[%s]: no of entry headers in Template: 0x%x\n",
  2617. __func__, num_entry_hdr);
  2618. ql4_printk(KERN_INFO, ha, "[%s]: Capture Mask obtained: 0x%x\n",
  2619. __func__, ha->fw_dump_capture_mask);
  2620. ql4_printk(KERN_INFO, ha, "[%s]: Total_data_size 0x%x, %d obtained\n",
  2621. __func__, ha->fw_dump_size, ha->fw_dump_size);
  2622. /* Update current timestamp before taking dump */
  2623. now = get_jiffies_64();
  2624. timestamp = (u32)(jiffies_to_msecs(now) / 1000);
  2625. tmplt_hdr->driver_timestamp = timestamp;
  2626. entry_hdr = (struct qla8xxx_minidump_entry_hdr *)
  2627. (((uint8_t *)ha->fw_dump_tmplt_hdr) +
  2628. tmplt_hdr->first_entry_offset);
  2629. if (is_qla8032(ha) || is_qla8042(ha))
  2630. tmplt_hdr->saved_state_array[QLA83XX_SS_OCM_WNDREG_INDEX] =
  2631. tmplt_hdr->ocm_window_reg[ha->func_num];
  2632. /* Walk through the entry headers - validate/perform required action */
  2633. for (i = 0; i < num_entry_hdr; i++) {
  2634. if (data_collected > ha->fw_dump_size) {
  2635. ql4_printk(KERN_INFO, ha,
  2636. "Data collected: [0x%x], Total Dump size: [0x%x]\n",
  2637. data_collected, ha->fw_dump_size);
  2638. return rval;
  2639. }
  2640. if (!(entry_hdr->d_ctrl.entry_capture_mask &
  2641. ha->fw_dump_capture_mask)) {
  2642. entry_hdr->d_ctrl.driver_flags |=
  2643. QLA8XXX_DBG_SKIPPED_FLAG;
  2644. goto skip_nxt_entry;
  2645. }
  2646. DEBUG2(ql4_printk(KERN_INFO, ha,
  2647. "Data collected: [0x%x], Dump size left:[0x%x]\n",
  2648. data_collected,
  2649. (ha->fw_dump_size - data_collected)));
  2650. /* Decode the entry type and take required action to capture
  2651. * debug data
  2652. */
  2653. switch (entry_hdr->entry_type) {
  2654. case QLA8XXX_RDEND:
  2655. qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
  2656. break;
  2657. case QLA8XXX_CNTRL:
  2658. rval = qla4_8xxx_minidump_process_control(ha,
  2659. entry_hdr);
  2660. if (rval != QLA_SUCCESS) {
  2661. qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
  2662. goto md_failed;
  2663. }
  2664. break;
  2665. case QLA8XXX_RDCRB:
  2666. qla4_8xxx_minidump_process_rdcrb(ha, entry_hdr,
  2667. &data_ptr);
  2668. break;
  2669. case QLA8XXX_RDMEM:
  2670. rval = qla4_8xxx_minidump_process_rdmem(ha, entry_hdr,
  2671. &data_ptr);
  2672. if (rval != QLA_SUCCESS) {
  2673. qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
  2674. goto md_failed;
  2675. }
  2676. break;
  2677. case QLA8XXX_BOARD:
  2678. case QLA8XXX_RDROM:
  2679. if (is_qla8022(ha)) {
  2680. qla4_82xx_minidump_process_rdrom(ha, entry_hdr,
  2681. &data_ptr);
  2682. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  2683. rval = qla4_83xx_minidump_process_rdrom(ha,
  2684. entry_hdr,
  2685. &data_ptr);
  2686. if (rval != QLA_SUCCESS)
  2687. qla4_8xxx_mark_entry_skipped(ha,
  2688. entry_hdr,
  2689. i);
  2690. }
  2691. break;
  2692. case QLA8XXX_L2DTG:
  2693. case QLA8XXX_L2ITG:
  2694. case QLA8XXX_L2DAT:
  2695. case QLA8XXX_L2INS:
  2696. rval = qla4_8xxx_minidump_process_l2tag(ha, entry_hdr,
  2697. &data_ptr);
  2698. if (rval != QLA_SUCCESS) {
  2699. qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
  2700. goto md_failed;
  2701. }
  2702. break;
  2703. case QLA8XXX_L1DTG:
  2704. case QLA8XXX_L1ITG:
  2705. case QLA8XXX_L1DAT:
  2706. case QLA8XXX_L1INS:
  2707. qla4_8xxx_minidump_process_l1cache(ha, entry_hdr,
  2708. &data_ptr);
  2709. break;
  2710. case QLA8XXX_RDOCM:
  2711. qla4_8xxx_minidump_process_rdocm(ha, entry_hdr,
  2712. &data_ptr);
  2713. break;
  2714. case QLA8XXX_RDMUX:
  2715. qla4_8xxx_minidump_process_rdmux(ha, entry_hdr,
  2716. &data_ptr);
  2717. break;
  2718. case QLA8XXX_QUEUE:
  2719. qla4_8xxx_minidump_process_queue(ha, entry_hdr,
  2720. &data_ptr);
  2721. break;
  2722. case QLA83XX_POLLRD:
  2723. if (is_qla8022(ha)) {
  2724. qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
  2725. break;
  2726. }
  2727. rval = qla83xx_minidump_process_pollrd(ha, entry_hdr,
  2728. &data_ptr);
  2729. if (rval != QLA_SUCCESS)
  2730. qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
  2731. break;
  2732. case QLA83XX_RDMUX2:
  2733. if (is_qla8022(ha)) {
  2734. qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
  2735. break;
  2736. }
  2737. qla83xx_minidump_process_rdmux2(ha, entry_hdr,
  2738. &data_ptr);
  2739. break;
  2740. case QLA83XX_POLLRDMWR:
  2741. if (is_qla8022(ha)) {
  2742. qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
  2743. break;
  2744. }
  2745. rval = qla83xx_minidump_process_pollrdmwr(ha, entry_hdr,
  2746. &data_ptr);
  2747. if (rval != QLA_SUCCESS)
  2748. qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
  2749. break;
  2750. case QLA8044_RDDFE:
  2751. rval = qla4_84xx_minidump_process_rddfe(ha, entry_hdr,
  2752. &data_ptr);
  2753. if (rval != QLA_SUCCESS)
  2754. qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
  2755. break;
  2756. case QLA8044_RDMDIO:
  2757. rval = qla4_84xx_minidump_process_rdmdio(ha, entry_hdr,
  2758. &data_ptr);
  2759. if (rval != QLA_SUCCESS)
  2760. qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
  2761. break;
  2762. case QLA8044_POLLWR:
  2763. rval = qla4_84xx_minidump_process_pollwr(ha, entry_hdr,
  2764. &data_ptr);
  2765. if (rval != QLA_SUCCESS)
  2766. qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
  2767. break;
  2768. case QLA8XXX_RDNOP:
  2769. default:
  2770. qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
  2771. break;
  2772. }
  2773. data_collected = (uint8_t *)data_ptr - (uint8_t *)ha->fw_dump;
  2774. skip_nxt_entry:
  2775. /* next entry in the template */
  2776. entry_hdr = (struct qla8xxx_minidump_entry_hdr *)
  2777. (((uint8_t *)entry_hdr) +
  2778. entry_hdr->entry_size);
  2779. }
  2780. if ((data_collected + ha->fw_dump_skip_size) != ha->fw_dump_size) {
  2781. ql4_printk(KERN_INFO, ha,
  2782. "Dump data mismatch: Data collected: [0x%x], total_data_size:[0x%x]\n",
  2783. data_collected, ha->fw_dump_size);
  2784. rval = QLA_ERROR;
  2785. goto md_failed;
  2786. }
  2787. DEBUG2(ql4_printk(KERN_INFO, ha, "Leaving fn: %s Last entry: 0x%x\n",
  2788. __func__, i));
  2789. md_failed:
  2790. return rval;
  2791. }
  2792. /**
  2793. * qla4_8xxx_uevent_emit - Send uevent when the firmware dump is ready.
  2794. * @ha: pointer to adapter structure
  2795. **/
  2796. static void qla4_8xxx_uevent_emit(struct scsi_qla_host *ha, u32 code)
  2797. {
  2798. char event_string[40];
  2799. char *envp[] = { event_string, NULL };
  2800. switch (code) {
  2801. case QL4_UEVENT_CODE_FW_DUMP:
  2802. snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
  2803. ha->host_no);
  2804. break;
  2805. default:
  2806. /*do nothing*/
  2807. break;
  2808. }
  2809. kobject_uevent_env(&(&ha->pdev->dev)->kobj, KOBJ_CHANGE, envp);
  2810. }
  2811. void qla4_8xxx_get_minidump(struct scsi_qla_host *ha)
  2812. {
  2813. if (ql4xenablemd && test_bit(AF_FW_RECOVERY, &ha->flags) &&
  2814. !test_bit(AF_82XX_FW_DUMPED, &ha->flags)) {
  2815. if (!qla4_8xxx_collect_md_data(ha)) {
  2816. qla4_8xxx_uevent_emit(ha, QL4_UEVENT_CODE_FW_DUMP);
  2817. set_bit(AF_82XX_FW_DUMPED, &ha->flags);
  2818. } else {
  2819. ql4_printk(KERN_INFO, ha, "%s: Unable to collect minidump\n",
  2820. __func__);
  2821. }
  2822. }
  2823. }
  2824. /**
  2825. * qla4_8xxx_device_bootstrap - Initialize device, set DEV_READY, start fw
  2826. * @ha: pointer to adapter structure
  2827. *
  2828. * Note: IDC lock must be held upon entry
  2829. **/
  2830. int qla4_8xxx_device_bootstrap(struct scsi_qla_host *ha)
  2831. {
  2832. int rval = QLA_ERROR;
  2833. int i;
  2834. uint32_t old_count, count;
  2835. int need_reset = 0;
  2836. need_reset = ha->isp_ops->need_reset(ha);
  2837. if (need_reset) {
  2838. /* We are trying to perform a recovery here. */
  2839. if (test_bit(AF_FW_RECOVERY, &ha->flags))
  2840. ha->isp_ops->rom_lock_recovery(ha);
  2841. } else {
  2842. old_count = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_ALIVE_COUNTER);
  2843. for (i = 0; i < 10; i++) {
  2844. msleep(200);
  2845. count = qla4_8xxx_rd_direct(ha,
  2846. QLA8XXX_PEG_ALIVE_COUNTER);
  2847. if (count != old_count) {
  2848. rval = QLA_SUCCESS;
  2849. goto dev_ready;
  2850. }
  2851. }
  2852. ha->isp_ops->rom_lock_recovery(ha);
  2853. }
  2854. /* set to DEV_INITIALIZING */
  2855. ql4_printk(KERN_INFO, ha, "HW State: INITIALIZING\n");
  2856. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  2857. QLA8XXX_DEV_INITIALIZING);
  2858. ha->isp_ops->idc_unlock(ha);
  2859. if (is_qla8022(ha))
  2860. qla4_8xxx_get_minidump(ha);
  2861. rval = ha->isp_ops->restart_firmware(ha);
  2862. ha->isp_ops->idc_lock(ha);
  2863. if (rval != QLA_SUCCESS) {
  2864. ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
  2865. qla4_8xxx_clear_drv_active(ha);
  2866. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  2867. QLA8XXX_DEV_FAILED);
  2868. return rval;
  2869. }
  2870. dev_ready:
  2871. ql4_printk(KERN_INFO, ha, "HW State: READY\n");
  2872. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, QLA8XXX_DEV_READY);
  2873. return rval;
  2874. }
  2875. /**
  2876. * qla4_82xx_need_reset_handler - Code to start reset sequence
  2877. * @ha: pointer to adapter structure
  2878. *
  2879. * Note: IDC lock must be held upon entry
  2880. **/
  2881. static void
  2882. qla4_82xx_need_reset_handler(struct scsi_qla_host *ha)
  2883. {
  2884. uint32_t dev_state, drv_state, drv_active;
  2885. uint32_t active_mask = 0xFFFFFFFF;
  2886. unsigned long reset_timeout;
  2887. ql4_printk(KERN_INFO, ha,
  2888. "Performing ISP error recovery\n");
  2889. if (test_and_clear_bit(AF_ONLINE, &ha->flags)) {
  2890. qla4_82xx_idc_unlock(ha);
  2891. ha->isp_ops->disable_intrs(ha);
  2892. qla4_82xx_idc_lock(ha);
  2893. }
  2894. if (!test_bit(AF_8XXX_RST_OWNER, &ha->flags)) {
  2895. DEBUG2(ql4_printk(KERN_INFO, ha,
  2896. "%s(%ld): reset acknowledged\n",
  2897. __func__, ha->host_no));
  2898. qla4_8xxx_set_rst_ready(ha);
  2899. } else {
  2900. active_mask = (~(1 << (ha->func_num * 4)));
  2901. }
  2902. /* wait for 10 seconds for reset ack from all functions */
  2903. reset_timeout = jiffies + (ha->nx_reset_timeout * HZ);
  2904. drv_state = qla4_82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
  2905. drv_active = qla4_82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
  2906. ql4_printk(KERN_INFO, ha,
  2907. "%s(%ld): drv_state = 0x%x, drv_active = 0x%x\n",
  2908. __func__, ha->host_no, drv_state, drv_active);
  2909. while (drv_state != (drv_active & active_mask)) {
  2910. if (time_after_eq(jiffies, reset_timeout)) {
  2911. ql4_printk(KERN_INFO, ha,
  2912. "%s: RESET TIMEOUT! drv_state: 0x%08x, drv_active: 0x%08x\n",
  2913. DRIVER_NAME, drv_state, drv_active);
  2914. break;
  2915. }
  2916. /*
  2917. * When reset_owner times out, check which functions
  2918. * acked/did not ack
  2919. */
  2920. if (test_bit(AF_8XXX_RST_OWNER, &ha->flags)) {
  2921. ql4_printk(KERN_INFO, ha,
  2922. "%s(%ld): drv_state = 0x%x, drv_active = 0x%x\n",
  2923. __func__, ha->host_no, drv_state,
  2924. drv_active);
  2925. }
  2926. qla4_82xx_idc_unlock(ha);
  2927. msleep(1000);
  2928. qla4_82xx_idc_lock(ha);
  2929. drv_state = qla4_82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
  2930. drv_active = qla4_82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
  2931. }
  2932. /* Clear RESET OWNER as we are not going to use it any further */
  2933. clear_bit(AF_8XXX_RST_OWNER, &ha->flags);
  2934. dev_state = qla4_82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
  2935. ql4_printk(KERN_INFO, ha, "Device state is 0x%x = %s\n", dev_state,
  2936. dev_state < MAX_STATES ? qdev_state[dev_state] : "Unknown");
  2937. /* Force to DEV_COLD unless someone else is starting a reset */
  2938. if (dev_state != QLA8XXX_DEV_INITIALIZING) {
  2939. ql4_printk(KERN_INFO, ha, "HW State: COLD/RE-INIT\n");
  2940. qla4_82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, QLA8XXX_DEV_COLD);
  2941. qla4_8xxx_set_rst_ready(ha);
  2942. }
  2943. }
  2944. /**
  2945. * qla4_8xxx_need_qsnt_handler - Code to start qsnt
  2946. * @ha: pointer to adapter structure
  2947. **/
  2948. void
  2949. qla4_8xxx_need_qsnt_handler(struct scsi_qla_host *ha)
  2950. {
  2951. ha->isp_ops->idc_lock(ha);
  2952. qla4_8xxx_set_qsnt_ready(ha);
  2953. ha->isp_ops->idc_unlock(ha);
  2954. }
  2955. static void qla4_82xx_set_idc_ver(struct scsi_qla_host *ha)
  2956. {
  2957. int idc_ver;
  2958. uint32_t drv_active;
  2959. drv_active = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_ACTIVE);
  2960. if (drv_active == (1 << (ha->func_num * 4))) {
  2961. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_IDC_VERSION,
  2962. QLA82XX_IDC_VERSION);
  2963. ql4_printk(KERN_INFO, ha,
  2964. "%s: IDC version updated to %d\n", __func__,
  2965. QLA82XX_IDC_VERSION);
  2966. } else {
  2967. idc_ver = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_IDC_VERSION);
  2968. if (QLA82XX_IDC_VERSION != idc_ver) {
  2969. ql4_printk(KERN_INFO, ha,
  2970. "%s: qla4xxx driver IDC version %d is not compatible with IDC version %d of other drivers!\n",
  2971. __func__, QLA82XX_IDC_VERSION, idc_ver);
  2972. }
  2973. }
  2974. }
  2975. static int qla4_83xx_set_idc_ver(struct scsi_qla_host *ha)
  2976. {
  2977. int idc_ver;
  2978. uint32_t drv_active;
  2979. int rval = QLA_SUCCESS;
  2980. drv_active = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_ACTIVE);
  2981. if (drv_active == (1 << ha->func_num)) {
  2982. idc_ver = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_IDC_VERSION);
  2983. idc_ver &= (~0xFF);
  2984. idc_ver |= QLA83XX_IDC_VER_MAJ_VALUE;
  2985. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_IDC_VERSION, idc_ver);
  2986. ql4_printk(KERN_INFO, ha,
  2987. "%s: IDC version updated to %d\n", __func__,
  2988. idc_ver);
  2989. } else {
  2990. idc_ver = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_IDC_VERSION);
  2991. idc_ver &= 0xFF;
  2992. if (QLA83XX_IDC_VER_MAJ_VALUE != idc_ver) {
  2993. ql4_printk(KERN_INFO, ha,
  2994. "%s: qla4xxx driver IDC version %d is not compatible with IDC version %d of other drivers!\n",
  2995. __func__, QLA83XX_IDC_VER_MAJ_VALUE,
  2996. idc_ver);
  2997. rval = QLA_ERROR;
  2998. goto exit_set_idc_ver;
  2999. }
  3000. }
  3001. /* Update IDC_MINOR_VERSION */
  3002. idc_ver = qla4_83xx_rd_reg(ha, QLA83XX_CRB_IDC_VER_MINOR);
  3003. idc_ver &= ~(0x03 << (ha->func_num * 2));
  3004. idc_ver |= (QLA83XX_IDC_VER_MIN_VALUE << (ha->func_num * 2));
  3005. qla4_83xx_wr_reg(ha, QLA83XX_CRB_IDC_VER_MINOR, idc_ver);
  3006. exit_set_idc_ver:
  3007. return rval;
  3008. }
  3009. int qla4_8xxx_update_idc_reg(struct scsi_qla_host *ha)
  3010. {
  3011. uint32_t drv_active;
  3012. int rval = QLA_SUCCESS;
  3013. if (test_bit(AF_INIT_DONE, &ha->flags))
  3014. goto exit_update_idc_reg;
  3015. ha->isp_ops->idc_lock(ha);
  3016. qla4_8xxx_set_drv_active(ha);
  3017. /*
  3018. * If we are the first driver to load and
  3019. * ql4xdontresethba is not set, clear IDC_CTRL BIT0.
  3020. */
  3021. if (is_qla8032(ha) || is_qla8042(ha)) {
  3022. drv_active = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_ACTIVE);
  3023. if ((drv_active == (1 << ha->func_num)) && !ql4xdontresethba)
  3024. qla4_83xx_clear_idc_dontreset(ha);
  3025. }
  3026. if (is_qla8022(ha)) {
  3027. qla4_82xx_set_idc_ver(ha);
  3028. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  3029. rval = qla4_83xx_set_idc_ver(ha);
  3030. if (rval == QLA_ERROR)
  3031. qla4_8xxx_clear_drv_active(ha);
  3032. }
  3033. ha->isp_ops->idc_unlock(ha);
  3034. exit_update_idc_reg:
  3035. return rval;
  3036. }
  3037. /**
  3038. * qla4_8xxx_device_state_handler - Adapter state machine
  3039. * @ha: pointer to host adapter structure.
  3040. *
  3041. * Note: IDC lock must be UNLOCKED upon entry
  3042. **/
  3043. int qla4_8xxx_device_state_handler(struct scsi_qla_host *ha)
  3044. {
  3045. uint32_t dev_state;
  3046. int rval = QLA_SUCCESS;
  3047. unsigned long dev_init_timeout;
  3048. rval = qla4_8xxx_update_idc_reg(ha);
  3049. if (rval == QLA_ERROR)
  3050. goto exit_state_handler;
  3051. dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
  3052. DEBUG2(ql4_printk(KERN_INFO, ha, "Device state is 0x%x = %s\n",
  3053. dev_state, dev_state < MAX_STATES ?
  3054. qdev_state[dev_state] : "Unknown"));
  3055. /* wait for 30 seconds for device to go ready */
  3056. dev_init_timeout = jiffies + (ha->nx_dev_init_timeout * HZ);
  3057. ha->isp_ops->idc_lock(ha);
  3058. while (1) {
  3059. if (time_after_eq(jiffies, dev_init_timeout)) {
  3060. ql4_printk(KERN_WARNING, ha,
  3061. "%s: Device Init Failed 0x%x = %s\n",
  3062. DRIVER_NAME,
  3063. dev_state, dev_state < MAX_STATES ?
  3064. qdev_state[dev_state] : "Unknown");
  3065. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  3066. QLA8XXX_DEV_FAILED);
  3067. }
  3068. dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
  3069. ql4_printk(KERN_INFO, ha, "Device state is 0x%x = %s\n",
  3070. dev_state, dev_state < MAX_STATES ?
  3071. qdev_state[dev_state] : "Unknown");
  3072. /* NOTE: Make sure idc unlocked upon exit of switch statement */
  3073. switch (dev_state) {
  3074. case QLA8XXX_DEV_READY:
  3075. goto exit;
  3076. case QLA8XXX_DEV_COLD:
  3077. rval = qla4_8xxx_device_bootstrap(ha);
  3078. goto exit;
  3079. case QLA8XXX_DEV_INITIALIZING:
  3080. ha->isp_ops->idc_unlock(ha);
  3081. msleep(1000);
  3082. ha->isp_ops->idc_lock(ha);
  3083. break;
  3084. case QLA8XXX_DEV_NEED_RESET:
  3085. /*
  3086. * For ISP8324 and ISP8042, if NEED_RESET is set by any
  3087. * driver, it should be honored, irrespective of
  3088. * IDC_CTRL DONTRESET_BIT0
  3089. */
  3090. if (is_qla8032(ha) || is_qla8042(ha)) {
  3091. qla4_83xx_need_reset_handler(ha);
  3092. } else if (is_qla8022(ha)) {
  3093. if (!ql4xdontresethba) {
  3094. qla4_82xx_need_reset_handler(ha);
  3095. /* Update timeout value after need
  3096. * reset handler */
  3097. dev_init_timeout = jiffies +
  3098. (ha->nx_dev_init_timeout * HZ);
  3099. } else {
  3100. ha->isp_ops->idc_unlock(ha);
  3101. msleep(1000);
  3102. ha->isp_ops->idc_lock(ha);
  3103. }
  3104. }
  3105. break;
  3106. case QLA8XXX_DEV_NEED_QUIESCENT:
  3107. /* idc locked/unlocked in handler */
  3108. qla4_8xxx_need_qsnt_handler(ha);
  3109. break;
  3110. case QLA8XXX_DEV_QUIESCENT:
  3111. ha->isp_ops->idc_unlock(ha);
  3112. msleep(1000);
  3113. ha->isp_ops->idc_lock(ha);
  3114. break;
  3115. case QLA8XXX_DEV_FAILED:
  3116. ha->isp_ops->idc_unlock(ha);
  3117. qla4xxx_dead_adapter_cleanup(ha);
  3118. rval = QLA_ERROR;
  3119. ha->isp_ops->idc_lock(ha);
  3120. goto exit;
  3121. default:
  3122. ha->isp_ops->idc_unlock(ha);
  3123. qla4xxx_dead_adapter_cleanup(ha);
  3124. rval = QLA_ERROR;
  3125. ha->isp_ops->idc_lock(ha);
  3126. goto exit;
  3127. }
  3128. }
  3129. exit:
  3130. ha->isp_ops->idc_unlock(ha);
  3131. exit_state_handler:
  3132. return rval;
  3133. }
  3134. int qla4_8xxx_load_risc(struct scsi_qla_host *ha)
  3135. {
  3136. int retval;
  3137. /* clear the interrupt */
  3138. if (is_qla8032(ha) || is_qla8042(ha)) {
  3139. writel(0, &ha->qla4_83xx_reg->risc_intr);
  3140. readl(&ha->qla4_83xx_reg->risc_intr);
  3141. } else if (is_qla8022(ha)) {
  3142. writel(0, &ha->qla4_82xx_reg->host_int);
  3143. readl(&ha->qla4_82xx_reg->host_int);
  3144. }
  3145. retval = qla4_8xxx_device_state_handler(ha);
  3146. /* Initialize request and response queues. */
  3147. if (retval == QLA_SUCCESS)
  3148. qla4xxx_init_rings(ha);
  3149. if (retval == QLA_SUCCESS && !test_bit(AF_IRQ_ATTACHED, &ha->flags))
  3150. retval = qla4xxx_request_irqs(ha);
  3151. return retval;
  3152. }
  3153. /*****************************************************************************/
  3154. /* Flash Manipulation Routines */
  3155. /*****************************************************************************/
  3156. #define OPTROM_BURST_SIZE 0x1000
  3157. #define OPTROM_BURST_DWORDS (OPTROM_BURST_SIZE / 4)
  3158. #define FARX_DATA_FLAG BIT_31
  3159. #define FARX_ACCESS_FLASH_CONF 0x7FFD0000
  3160. #define FARX_ACCESS_FLASH_DATA 0x7FF00000
  3161. static inline uint32_t
  3162. flash_conf_addr(struct ql82xx_hw_data *hw, uint32_t faddr)
  3163. {
  3164. return hw->flash_conf_off | faddr;
  3165. }
  3166. static inline uint32_t
  3167. flash_data_addr(struct ql82xx_hw_data *hw, uint32_t faddr)
  3168. {
  3169. return hw->flash_data_off | faddr;
  3170. }
  3171. static uint32_t *
  3172. qla4_82xx_read_flash_data(struct scsi_qla_host *ha, uint32_t *dwptr,
  3173. uint32_t faddr, uint32_t length)
  3174. {
  3175. uint32_t i;
  3176. uint32_t val;
  3177. int loops = 0;
  3178. while ((qla4_82xx_rom_lock(ha) != 0) && (loops < 50000)) {
  3179. udelay(100);
  3180. cond_resched();
  3181. loops++;
  3182. }
  3183. if (loops >= 50000) {
  3184. ql4_printk(KERN_WARNING, ha, "ROM lock failed\n");
  3185. return dwptr;
  3186. }
  3187. /* Dword reads to flash. */
  3188. for (i = 0; i < length/4; i++, faddr += 4) {
  3189. if (qla4_82xx_do_rom_fast_read(ha, faddr, &val)) {
  3190. ql4_printk(KERN_WARNING, ha,
  3191. "Do ROM fast read failed\n");
  3192. goto done_read;
  3193. }
  3194. dwptr[i] = __constant_cpu_to_le32(val);
  3195. }
  3196. done_read:
  3197. qla4_82xx_rom_unlock(ha);
  3198. return dwptr;
  3199. }
  3200. /**
  3201. * Address and length are byte address
  3202. **/
  3203. static uint8_t *
  3204. qla4_82xx_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
  3205. uint32_t offset, uint32_t length)
  3206. {
  3207. qla4_82xx_read_flash_data(ha, (uint32_t *)buf, offset, length);
  3208. return buf;
  3209. }
  3210. static int
  3211. qla4_8xxx_find_flt_start(struct scsi_qla_host *ha, uint32_t *start)
  3212. {
  3213. const char *loc, *locations[] = { "DEF", "PCI" };
  3214. /*
  3215. * FLT-location structure resides after the last PCI region.
  3216. */
  3217. /* Begin with sane defaults. */
  3218. loc = locations[0];
  3219. *start = FA_FLASH_LAYOUT_ADDR_82;
  3220. DEBUG2(ql4_printk(KERN_INFO, ha, "FLTL[%s] = 0x%x.\n", loc, *start));
  3221. return QLA_SUCCESS;
  3222. }
  3223. static void
  3224. qla4_8xxx_get_flt_info(struct scsi_qla_host *ha, uint32_t flt_addr)
  3225. {
  3226. const char *loc, *locations[] = { "DEF", "FLT" };
  3227. uint16_t *wptr;
  3228. uint16_t cnt, chksum;
  3229. uint32_t start, status;
  3230. struct qla_flt_header *flt;
  3231. struct qla_flt_region *region;
  3232. struct ql82xx_hw_data *hw = &ha->hw;
  3233. hw->flt_region_flt = flt_addr;
  3234. wptr = (uint16_t *)ha->request_ring;
  3235. flt = (struct qla_flt_header *)ha->request_ring;
  3236. region = (struct qla_flt_region *)&flt[1];
  3237. if (is_qla8022(ha)) {
  3238. qla4_82xx_read_optrom_data(ha, (uint8_t *)ha->request_ring,
  3239. flt_addr << 2, OPTROM_BURST_SIZE);
  3240. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  3241. status = qla4_83xx_flash_read_u32(ha, flt_addr << 2,
  3242. (uint8_t *)ha->request_ring,
  3243. 0x400);
  3244. if (status != QLA_SUCCESS)
  3245. goto no_flash_data;
  3246. }
  3247. if (*wptr == __constant_cpu_to_le16(0xffff))
  3248. goto no_flash_data;
  3249. if (flt->version != __constant_cpu_to_le16(1)) {
  3250. DEBUG2(ql4_printk(KERN_INFO, ha, "Unsupported FLT detected: "
  3251. "version=0x%x length=0x%x checksum=0x%x.\n",
  3252. le16_to_cpu(flt->version), le16_to_cpu(flt->length),
  3253. le16_to_cpu(flt->checksum)));
  3254. goto no_flash_data;
  3255. }
  3256. cnt = (sizeof(struct qla_flt_header) + le16_to_cpu(flt->length)) >> 1;
  3257. for (chksum = 0; cnt; cnt--)
  3258. chksum += le16_to_cpu(*wptr++);
  3259. if (chksum) {
  3260. DEBUG2(ql4_printk(KERN_INFO, ha, "Inconsistent FLT detected: "
  3261. "version=0x%x length=0x%x checksum=0x%x.\n",
  3262. le16_to_cpu(flt->version), le16_to_cpu(flt->length),
  3263. chksum));
  3264. goto no_flash_data;
  3265. }
  3266. loc = locations[1];
  3267. cnt = le16_to_cpu(flt->length) / sizeof(struct qla_flt_region);
  3268. for ( ; cnt; cnt--, region++) {
  3269. /* Store addresses as DWORD offsets. */
  3270. start = le32_to_cpu(region->start) >> 2;
  3271. DEBUG3(ql4_printk(KERN_DEBUG, ha, "FLT[%02x]: start=0x%x "
  3272. "end=0x%x size=0x%x.\n", le32_to_cpu(region->code), start,
  3273. le32_to_cpu(region->end) >> 2, le32_to_cpu(region->size)));
  3274. switch (le32_to_cpu(region->code) & 0xff) {
  3275. case FLT_REG_FDT:
  3276. hw->flt_region_fdt = start;
  3277. break;
  3278. case FLT_REG_BOOT_CODE_82:
  3279. hw->flt_region_boot = start;
  3280. break;
  3281. case FLT_REG_FW_82:
  3282. case FLT_REG_FW_82_1:
  3283. hw->flt_region_fw = start;
  3284. break;
  3285. case FLT_REG_BOOTLOAD_82:
  3286. hw->flt_region_bootload = start;
  3287. break;
  3288. case FLT_REG_ISCSI_PARAM:
  3289. hw->flt_iscsi_param = start;
  3290. break;
  3291. case FLT_REG_ISCSI_CHAP:
  3292. hw->flt_region_chap = start;
  3293. hw->flt_chap_size = le32_to_cpu(region->size);
  3294. break;
  3295. case FLT_REG_ISCSI_DDB:
  3296. hw->flt_region_ddb = start;
  3297. hw->flt_ddb_size = le32_to_cpu(region->size);
  3298. break;
  3299. }
  3300. }
  3301. goto done;
  3302. no_flash_data:
  3303. /* Use hardcoded defaults. */
  3304. loc = locations[0];
  3305. hw->flt_region_fdt = FA_FLASH_DESCR_ADDR_82;
  3306. hw->flt_region_boot = FA_BOOT_CODE_ADDR_82;
  3307. hw->flt_region_bootload = FA_BOOT_LOAD_ADDR_82;
  3308. hw->flt_region_fw = FA_RISC_CODE_ADDR_82;
  3309. hw->flt_region_chap = FA_FLASH_ISCSI_CHAP >> 2;
  3310. hw->flt_chap_size = FA_FLASH_CHAP_SIZE;
  3311. hw->flt_region_ddb = FA_FLASH_ISCSI_DDB >> 2;
  3312. hw->flt_ddb_size = FA_FLASH_DDB_SIZE;
  3313. done:
  3314. DEBUG2(ql4_printk(KERN_INFO, ha,
  3315. "FLT[%s]: flt=0x%x fdt=0x%x boot=0x%x bootload=0x%x fw=0x%x chap=0x%x chap_size=0x%x ddb=0x%x ddb_size=0x%x\n",
  3316. loc, hw->flt_region_flt, hw->flt_region_fdt,
  3317. hw->flt_region_boot, hw->flt_region_bootload,
  3318. hw->flt_region_fw, hw->flt_region_chap,
  3319. hw->flt_chap_size, hw->flt_region_ddb,
  3320. hw->flt_ddb_size));
  3321. }
  3322. static void
  3323. qla4_82xx_get_fdt_info(struct scsi_qla_host *ha)
  3324. {
  3325. #define FLASH_BLK_SIZE_4K 0x1000
  3326. #define FLASH_BLK_SIZE_32K 0x8000
  3327. #define FLASH_BLK_SIZE_64K 0x10000
  3328. const char *loc, *locations[] = { "MID", "FDT" };
  3329. uint16_t cnt, chksum;
  3330. uint16_t *wptr;
  3331. struct qla_fdt_layout *fdt;
  3332. uint16_t mid = 0;
  3333. uint16_t fid = 0;
  3334. struct ql82xx_hw_data *hw = &ha->hw;
  3335. hw->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  3336. hw->flash_data_off = FARX_ACCESS_FLASH_DATA;
  3337. wptr = (uint16_t *)ha->request_ring;
  3338. fdt = (struct qla_fdt_layout *)ha->request_ring;
  3339. qla4_82xx_read_optrom_data(ha, (uint8_t *)ha->request_ring,
  3340. hw->flt_region_fdt << 2, OPTROM_BURST_SIZE);
  3341. if (*wptr == __constant_cpu_to_le16(0xffff))
  3342. goto no_flash_data;
  3343. if (fdt->sig[0] != 'Q' || fdt->sig[1] != 'L' || fdt->sig[2] != 'I' ||
  3344. fdt->sig[3] != 'D')
  3345. goto no_flash_data;
  3346. for (cnt = 0, chksum = 0; cnt < sizeof(struct qla_fdt_layout) >> 1;
  3347. cnt++)
  3348. chksum += le16_to_cpu(*wptr++);
  3349. if (chksum) {
  3350. DEBUG2(ql4_printk(KERN_INFO, ha, "Inconsistent FDT detected: "
  3351. "checksum=0x%x id=%c version=0x%x.\n", chksum, fdt->sig[0],
  3352. le16_to_cpu(fdt->version)));
  3353. goto no_flash_data;
  3354. }
  3355. loc = locations[1];
  3356. mid = le16_to_cpu(fdt->man_id);
  3357. fid = le16_to_cpu(fdt->id);
  3358. hw->fdt_wrt_disable = fdt->wrt_disable_bits;
  3359. hw->fdt_erase_cmd = flash_conf_addr(hw, 0x0300 | fdt->erase_cmd);
  3360. hw->fdt_block_size = le32_to_cpu(fdt->block_size);
  3361. if (fdt->unprotect_sec_cmd) {
  3362. hw->fdt_unprotect_sec_cmd = flash_conf_addr(hw, 0x0300 |
  3363. fdt->unprotect_sec_cmd);
  3364. hw->fdt_protect_sec_cmd = fdt->protect_sec_cmd ?
  3365. flash_conf_addr(hw, 0x0300 | fdt->protect_sec_cmd) :
  3366. flash_conf_addr(hw, 0x0336);
  3367. }
  3368. goto done;
  3369. no_flash_data:
  3370. loc = locations[0];
  3371. hw->fdt_block_size = FLASH_BLK_SIZE_64K;
  3372. done:
  3373. DEBUG2(ql4_printk(KERN_INFO, ha, "FDT[%s]: (0x%x/0x%x) erase=0x%x "
  3374. "pro=%x upro=%x wrtd=0x%x blk=0x%x.\n", loc, mid, fid,
  3375. hw->fdt_erase_cmd, hw->fdt_protect_sec_cmd,
  3376. hw->fdt_unprotect_sec_cmd, hw->fdt_wrt_disable,
  3377. hw->fdt_block_size));
  3378. }
  3379. static void
  3380. qla4_82xx_get_idc_param(struct scsi_qla_host *ha)
  3381. {
  3382. #define QLA82XX_IDC_PARAM_ADDR 0x003e885c
  3383. uint32_t *wptr;
  3384. if (!is_qla8022(ha))
  3385. return;
  3386. wptr = (uint32_t *)ha->request_ring;
  3387. qla4_82xx_read_optrom_data(ha, (uint8_t *)ha->request_ring,
  3388. QLA82XX_IDC_PARAM_ADDR , 8);
  3389. if (*wptr == __constant_cpu_to_le32(0xffffffff)) {
  3390. ha->nx_dev_init_timeout = ROM_DEV_INIT_TIMEOUT;
  3391. ha->nx_reset_timeout = ROM_DRV_RESET_ACK_TIMEOUT;
  3392. } else {
  3393. ha->nx_dev_init_timeout = le32_to_cpu(*wptr++);
  3394. ha->nx_reset_timeout = le32_to_cpu(*wptr);
  3395. }
  3396. DEBUG2(ql4_printk(KERN_DEBUG, ha,
  3397. "ha->nx_dev_init_timeout = %d\n", ha->nx_dev_init_timeout));
  3398. DEBUG2(ql4_printk(KERN_DEBUG, ha,
  3399. "ha->nx_reset_timeout = %d\n", ha->nx_reset_timeout));
  3400. return;
  3401. }
  3402. void qla4_82xx_queue_mbox_cmd(struct scsi_qla_host *ha, uint32_t *mbx_cmd,
  3403. int in_count)
  3404. {
  3405. int i;
  3406. /* Load all mailbox registers, except mailbox 0. */
  3407. for (i = 1; i < in_count; i++)
  3408. writel(mbx_cmd[i], &ha->qla4_82xx_reg->mailbox_in[i]);
  3409. /* Wakeup firmware */
  3410. writel(mbx_cmd[0], &ha->qla4_82xx_reg->mailbox_in[0]);
  3411. readl(&ha->qla4_82xx_reg->mailbox_in[0]);
  3412. writel(HINT_MBX_INT_PENDING, &ha->qla4_82xx_reg->hint);
  3413. readl(&ha->qla4_82xx_reg->hint);
  3414. }
  3415. void qla4_82xx_process_mbox_intr(struct scsi_qla_host *ha, int out_count)
  3416. {
  3417. int intr_status;
  3418. intr_status = readl(&ha->qla4_82xx_reg->host_int);
  3419. if (intr_status & ISRX_82XX_RISC_INT) {
  3420. ha->mbox_status_count = out_count;
  3421. intr_status = readl(&ha->qla4_82xx_reg->host_status);
  3422. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  3423. if (test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
  3424. (!ha->pdev->msi_enabled && !ha->pdev->msix_enabled))
  3425. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg,
  3426. 0xfbff);
  3427. }
  3428. }
  3429. int
  3430. qla4_8xxx_get_flash_info(struct scsi_qla_host *ha)
  3431. {
  3432. int ret;
  3433. uint32_t flt_addr;
  3434. ret = qla4_8xxx_find_flt_start(ha, &flt_addr);
  3435. if (ret != QLA_SUCCESS)
  3436. return ret;
  3437. qla4_8xxx_get_flt_info(ha, flt_addr);
  3438. if (is_qla8022(ha)) {
  3439. qla4_82xx_get_fdt_info(ha);
  3440. qla4_82xx_get_idc_param(ha);
  3441. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  3442. qla4_83xx_get_idc_param(ha);
  3443. }
  3444. return QLA_SUCCESS;
  3445. }
  3446. /**
  3447. * qla4_8xxx_stop_firmware - stops firmware on specified adapter instance
  3448. * @ha: pointer to host adapter structure.
  3449. *
  3450. * Remarks:
  3451. * For iSCSI, throws away all I/O and AENs into bit bucket, so they will
  3452. * not be available after successful return. Driver must cleanup potential
  3453. * outstanding I/O's after calling this funcion.
  3454. **/
  3455. int
  3456. qla4_8xxx_stop_firmware(struct scsi_qla_host *ha)
  3457. {
  3458. int status;
  3459. uint32_t mbox_cmd[MBOX_REG_COUNT];
  3460. uint32_t mbox_sts[MBOX_REG_COUNT];
  3461. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  3462. memset(&mbox_sts, 0, sizeof(mbox_sts));
  3463. mbox_cmd[0] = MBOX_CMD_STOP_FW;
  3464. status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1,
  3465. &mbox_cmd[0], &mbox_sts[0]);
  3466. DEBUG2(printk("scsi%ld: %s: status = %d\n", ha->host_no,
  3467. __func__, status));
  3468. return status;
  3469. }
  3470. /**
  3471. * qla4_82xx_isp_reset - Resets ISP and aborts all outstanding commands.
  3472. * @ha: pointer to host adapter structure.
  3473. **/
  3474. int
  3475. qla4_82xx_isp_reset(struct scsi_qla_host *ha)
  3476. {
  3477. int rval;
  3478. uint32_t dev_state;
  3479. qla4_82xx_idc_lock(ha);
  3480. dev_state = qla4_82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
  3481. if (dev_state == QLA8XXX_DEV_READY) {
  3482. ql4_printk(KERN_INFO, ha, "HW State: NEED RESET\n");
  3483. qla4_82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3484. QLA8XXX_DEV_NEED_RESET);
  3485. set_bit(AF_8XXX_RST_OWNER, &ha->flags);
  3486. } else
  3487. ql4_printk(KERN_INFO, ha, "HW State: DEVICE INITIALIZING\n");
  3488. qla4_82xx_idc_unlock(ha);
  3489. rval = qla4_8xxx_device_state_handler(ha);
  3490. qla4_82xx_idc_lock(ha);
  3491. qla4_8xxx_clear_rst_ready(ha);
  3492. qla4_82xx_idc_unlock(ha);
  3493. if (rval == QLA_SUCCESS) {
  3494. ql4_printk(KERN_INFO, ha, "Clearing AF_RECOVERY in qla4_82xx_isp_reset\n");
  3495. clear_bit(AF_FW_RECOVERY, &ha->flags);
  3496. }
  3497. return rval;
  3498. }
  3499. /**
  3500. * qla4_8xxx_get_sys_info - get adapter MAC address(es) and serial number
  3501. * @ha: pointer to host adapter structure.
  3502. *
  3503. **/
  3504. int qla4_8xxx_get_sys_info(struct scsi_qla_host *ha)
  3505. {
  3506. uint32_t mbox_cmd[MBOX_REG_COUNT];
  3507. uint32_t mbox_sts[MBOX_REG_COUNT];
  3508. struct mbx_sys_info *sys_info;
  3509. dma_addr_t sys_info_dma;
  3510. int status = QLA_ERROR;
  3511. sys_info = dma_zalloc_coherent(&ha->pdev->dev, sizeof(*sys_info),
  3512. &sys_info_dma, GFP_KERNEL);
  3513. if (sys_info == NULL) {
  3514. DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
  3515. ha->host_no, __func__));
  3516. return status;
  3517. }
  3518. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  3519. memset(&mbox_sts, 0, sizeof(mbox_sts));
  3520. mbox_cmd[0] = MBOX_CMD_GET_SYS_INFO;
  3521. mbox_cmd[1] = LSDW(sys_info_dma);
  3522. mbox_cmd[2] = MSDW(sys_info_dma);
  3523. mbox_cmd[4] = sizeof(*sys_info);
  3524. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 6, &mbox_cmd[0],
  3525. &mbox_sts[0]) != QLA_SUCCESS) {
  3526. DEBUG2(printk("scsi%ld: %s: GET_SYS_INFO failed\n",
  3527. ha->host_no, __func__));
  3528. goto exit_validate_mac82;
  3529. }
  3530. /* Make sure we receive the minimum required data to cache internally */
  3531. if (((is_qla8032(ha) || is_qla8042(ha)) ? mbox_sts[3] : mbox_sts[4]) <
  3532. offsetof(struct mbx_sys_info, reserved)) {
  3533. DEBUG2(printk("scsi%ld: %s: GET_SYS_INFO data receive"
  3534. " error (%x)\n", ha->host_no, __func__, mbox_sts[4]));
  3535. goto exit_validate_mac82;
  3536. }
  3537. /* Save M.A.C. address & serial_number */
  3538. ha->port_num = sys_info->port_num;
  3539. memcpy(ha->my_mac, &sys_info->mac_addr[0],
  3540. min(sizeof(ha->my_mac), sizeof(sys_info->mac_addr)));
  3541. memcpy(ha->serial_number, &sys_info->serial_number,
  3542. min(sizeof(ha->serial_number), sizeof(sys_info->serial_number)));
  3543. memcpy(ha->model_name, &sys_info->board_id_str,
  3544. min(sizeof(ha->model_name), sizeof(sys_info->board_id_str)));
  3545. ha->phy_port_cnt = sys_info->phys_port_cnt;
  3546. ha->phy_port_num = sys_info->port_num;
  3547. ha->iscsi_pci_func_cnt = sys_info->iscsi_pci_func_cnt;
  3548. DEBUG2(printk("scsi%ld: %s: mac %pM serial %s\n",
  3549. ha->host_no, __func__, ha->my_mac, ha->serial_number));
  3550. status = QLA_SUCCESS;
  3551. exit_validate_mac82:
  3552. dma_free_coherent(&ha->pdev->dev, sizeof(*sys_info), sys_info,
  3553. sys_info_dma);
  3554. return status;
  3555. }
  3556. /* Interrupt handling helpers. */
  3557. int qla4_8xxx_intr_enable(struct scsi_qla_host *ha)
  3558. {
  3559. uint32_t mbox_cmd[MBOX_REG_COUNT];
  3560. uint32_t mbox_sts[MBOX_REG_COUNT];
  3561. DEBUG2(ql4_printk(KERN_INFO, ha, "%s\n", __func__));
  3562. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  3563. memset(&mbox_sts, 0, sizeof(mbox_sts));
  3564. mbox_cmd[0] = MBOX_CMD_ENABLE_INTRS;
  3565. mbox_cmd[1] = INTR_ENABLE;
  3566. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
  3567. &mbox_sts[0]) != QLA_SUCCESS) {
  3568. DEBUG2(ql4_printk(KERN_INFO, ha,
  3569. "%s: MBOX_CMD_ENABLE_INTRS failed (0x%04x)\n",
  3570. __func__, mbox_sts[0]));
  3571. return QLA_ERROR;
  3572. }
  3573. return QLA_SUCCESS;
  3574. }
  3575. int qla4_8xxx_intr_disable(struct scsi_qla_host *ha)
  3576. {
  3577. uint32_t mbox_cmd[MBOX_REG_COUNT];
  3578. uint32_t mbox_sts[MBOX_REG_COUNT];
  3579. DEBUG2(ql4_printk(KERN_INFO, ha, "%s\n", __func__));
  3580. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  3581. memset(&mbox_sts, 0, sizeof(mbox_sts));
  3582. mbox_cmd[0] = MBOX_CMD_ENABLE_INTRS;
  3583. mbox_cmd[1] = INTR_DISABLE;
  3584. if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
  3585. &mbox_sts[0]) != QLA_SUCCESS) {
  3586. DEBUG2(ql4_printk(KERN_INFO, ha,
  3587. "%s: MBOX_CMD_ENABLE_INTRS failed (0x%04x)\n",
  3588. __func__, mbox_sts[0]));
  3589. return QLA_ERROR;
  3590. }
  3591. return QLA_SUCCESS;
  3592. }
  3593. void
  3594. qla4_82xx_enable_intrs(struct scsi_qla_host *ha)
  3595. {
  3596. qla4_8xxx_intr_enable(ha);
  3597. spin_lock_irq(&ha->hardware_lock);
  3598. /* BIT 10 - reset */
  3599. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0xfbff);
  3600. spin_unlock_irq(&ha->hardware_lock);
  3601. set_bit(AF_INTERRUPTS_ON, &ha->flags);
  3602. }
  3603. void
  3604. qla4_82xx_disable_intrs(struct scsi_qla_host *ha)
  3605. {
  3606. if (test_and_clear_bit(AF_INTERRUPTS_ON, &ha->flags))
  3607. qla4_8xxx_intr_disable(ha);
  3608. spin_lock_irq(&ha->hardware_lock);
  3609. /* BIT 10 - set */
  3610. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0x0400);
  3611. spin_unlock_irq(&ha->hardware_lock);
  3612. }
  3613. int
  3614. qla4_8xxx_enable_msix(struct scsi_qla_host *ha)
  3615. {
  3616. int ret;
  3617. ret = pci_alloc_irq_vectors(ha->pdev, QLA_MSIX_ENTRIES,
  3618. QLA_MSIX_ENTRIES, PCI_IRQ_MSIX);
  3619. if (ret < 0) {
  3620. ql4_printk(KERN_WARNING, ha,
  3621. "MSI-X: Failed to enable support -- %d/%d\n",
  3622. QLA_MSIX_ENTRIES, ret);
  3623. return ret;
  3624. }
  3625. ret = request_irq(pci_irq_vector(ha->pdev, 0),
  3626. qla4_8xxx_default_intr_handler, 0, "qla4xxx (default)",
  3627. ha);
  3628. if (ret)
  3629. goto out_free_vectors;
  3630. ret = request_irq(pci_irq_vector(ha->pdev, 1),
  3631. qla4_8xxx_msix_rsp_q, 0, "qla4xxx (rsp_q)", ha);
  3632. if (ret)
  3633. goto out_free_default_irq;
  3634. return 0;
  3635. out_free_default_irq:
  3636. free_irq(pci_irq_vector(ha->pdev, 0), ha);
  3637. out_free_vectors:
  3638. pci_free_irq_vectors(ha->pdev);
  3639. return ret;
  3640. }
  3641. int qla4_8xxx_check_init_adapter_retry(struct scsi_qla_host *ha)
  3642. {
  3643. int status = QLA_SUCCESS;
  3644. /* Dont retry adapter initialization if IRQ allocation failed */
  3645. if (!test_bit(AF_IRQ_ATTACHED, &ha->flags)) {
  3646. ql4_printk(KERN_WARNING, ha, "%s: Skipping retry of adapter initialization as IRQs are not attached\n",
  3647. __func__);
  3648. status = QLA_ERROR;
  3649. goto exit_init_adapter_failure;
  3650. }
  3651. /* Since interrupts are registered in start_firmware for
  3652. * 8xxx, release them here if initialize_adapter fails
  3653. * and retry adapter initialization */
  3654. qla4xxx_free_irqs(ha);
  3655. exit_init_adapter_failure:
  3656. return status;
  3657. }