ql4_nx.c 116 KB

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