mptbase.c 166 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946
  1. /*
  2. * linux/drivers/message/fusion/mptbase.c
  3. * High performance SCSI + LAN / Fibre Channel device drivers.
  4. * This is the Fusion MPT base driver which supports multiple
  5. * (SCSI + LAN) specialized protocol drivers.
  6. * For use with PCI chip/adapter(s):
  7. * LSIFC9xx/LSI409xx Fibre Channel
  8. * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
  9. *
  10. * Credits:
  11. * There are lots of people not mentioned below that deserve credit
  12. * and thanks but won't get it here - sorry in advance that you
  13. * got overlooked.
  14. *
  15. * This driver would not exist if not for Alan Cox's development
  16. * of the linux i2o driver.
  17. *
  18. * A special thanks to Noah Romer (LSI Logic) for tons of work
  19. * and tough debugging on the LAN driver, especially early on;-)
  20. * And to Roger Hickerson (LSI Logic) for tirelessly supporting
  21. * this driver project.
  22. *
  23. * A special thanks to Pamela Delaney (LSI Logic) for tons of work
  24. * and countless enhancements while adding support for the 1030
  25. * chip family. Pam has been instrumental in the development of
  26. * of the 2.xx.xx series fusion drivers, and her contributions are
  27. * far too numerous to hope to list in one place.
  28. *
  29. * All manner of help from Stephen Shirron (LSI Logic):
  30. * low-level FC analysis, debug + various fixes in FCxx firmware,
  31. * initial port to alpha platform, various driver code optimizations,
  32. * being a faithful sounding board on all sorts of issues & ideas,
  33. * etc.
  34. *
  35. * A huge debt of gratitude is owed to David S. Miller (DaveM)
  36. * for fixing much of the stupid and broken stuff in the early
  37. * driver while porting to sparc64 platform. THANK YOU!
  38. *
  39. * Special thanks goes to the I2O LAN driver people at the
  40. * University of Helsinki, who, unbeknownst to them, provided
  41. * the inspiration and initial structure for this driver.
  42. *
  43. * A really huge debt of gratitude is owed to Eddie C. Dost
  44. * for gobs of hard work fixing and optimizing LAN code.
  45. * THANK YOU!
  46. *
  47. * Copyright (c) 1999-2004 LSI Logic Corporation
  48. * Originally By: Steven J. Ralston
  49. * (mailto:sjralston1@netscape.net)
  50. * (mailto:mpt_linux_developer@lsil.com)
  51. *
  52. * $Id: mptbase.c,v 1.126 2002/12/16 15:28:45 pdelaney Exp $
  53. */
  54. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  55. /*
  56. This program is free software; you can redistribute it and/or modify
  57. it under the terms of the GNU General Public License as published by
  58. the Free Software Foundation; version 2 of the License.
  59. This program is distributed in the hope that it will be useful,
  60. but WITHOUT ANY WARRANTY; without even the implied warranty of
  61. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  62. GNU General Public License for more details.
  63. NO WARRANTY
  64. THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  65. CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  66. LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  67. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  68. solely responsible for determining the appropriateness of using and
  69. distributing the Program and assumes all risks associated with its
  70. exercise of rights under this Agreement, including but not limited to
  71. the risks and costs of program errors, damage to or loss of data,
  72. programs or equipment, and unavailability or interruption of operations.
  73. DISCLAIMER OF LIABILITY
  74. NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  75. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  76. DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  77. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  78. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  79. USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  80. HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  81. You should have received a copy of the GNU General Public License
  82. along with this program; if not, write to the Free Software
  83. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  84. */
  85. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  86. #include <linux/config.h>
  87. #include <linux/version.h>
  88. #include <linux/kernel.h>
  89. #include <linux/module.h>
  90. #include <linux/errno.h>
  91. #include <linux/init.h>
  92. #include <linux/slab.h>
  93. #include <linux/types.h>
  94. #include <linux/pci.h>
  95. #include <linux/kdev_t.h>
  96. #include <linux/blkdev.h>
  97. #include <linux/delay.h>
  98. #include <linux/interrupt.h> /* needed for in_interrupt() proto */
  99. #include <asm/io.h>
  100. #ifdef CONFIG_MTRR
  101. #include <asm/mtrr.h>
  102. #endif
  103. #ifdef __sparc__
  104. #include <asm/irq.h> /* needed for __irq_itoa() proto */
  105. #endif
  106. #include "mptbase.h"
  107. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  108. #define my_NAME "Fusion MPT base driver"
  109. #define my_VERSION MPT_LINUX_VERSION_COMMON
  110. #define MYNAM "mptbase"
  111. MODULE_AUTHOR(MODULEAUTHOR);
  112. MODULE_DESCRIPTION(my_NAME);
  113. MODULE_LICENSE("GPL");
  114. /*
  115. * cmd line parameters
  116. */
  117. #ifdef MFCNT
  118. static int mfcounter = 0;
  119. #define PRINT_MF_COUNT 20000
  120. #endif
  121. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  122. /*
  123. * Public data...
  124. */
  125. int mpt_lan_index = -1;
  126. int mpt_stm_index = -1;
  127. struct proc_dir_entry *mpt_proc_root_dir;
  128. #define WHOINIT_UNKNOWN 0xAA
  129. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  130. /*
  131. * Private data...
  132. */
  133. /* Adapter link list */
  134. LIST_HEAD(ioc_list);
  135. /* Callback lookup table */
  136. static MPT_CALLBACK MptCallbacks[MPT_MAX_PROTOCOL_DRIVERS];
  137. /* Protocol driver class lookup table */
  138. static int MptDriverClass[MPT_MAX_PROTOCOL_DRIVERS];
  139. /* Event handler lookup table */
  140. static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
  141. /* Reset handler lookup table */
  142. static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
  143. static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
  144. static int mpt_base_index = -1;
  145. static int last_drv_idx = -1;
  146. static DECLARE_WAIT_QUEUE_HEAD(mpt_waitq);
  147. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  148. /*
  149. * Forward protos...
  150. */
  151. static irqreturn_t mpt_interrupt(int irq, void *bus_id, struct pt_regs *r);
  152. static int mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
  153. static int mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes,
  154. u32 *req, int replyBytes, u16 *u16reply, int maxwait,
  155. int sleepFlag);
  156. static int mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag);
  157. static void mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev);
  158. static void mpt_adapter_disable(MPT_ADAPTER *ioc);
  159. static void mpt_adapter_dispose(MPT_ADAPTER *ioc);
  160. static void MptDisplayIocCapabilities(MPT_ADAPTER *ioc);
  161. static int MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag);
  162. //static u32 mpt_GetIocState(MPT_ADAPTER *ioc, int cooked);
  163. static int GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason);
  164. static int GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
  165. static int SendIocInit(MPT_ADAPTER *ioc, int sleepFlag);
  166. static int SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
  167. static int mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag);
  168. static int mpt_downloadboot(MPT_ADAPTER *ioc, int sleepFlag);
  169. static int mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
  170. static int KickStart(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
  171. static int SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag);
  172. static int PrimeIocFifos(MPT_ADAPTER *ioc);
  173. static int WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
  174. static int WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
  175. static int WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
  176. static int GetLanConfigPages(MPT_ADAPTER *ioc);
  177. static int GetFcPortPage0(MPT_ADAPTER *ioc, int portnum);
  178. static int GetIoUnitPage2(MPT_ADAPTER *ioc);
  179. static int mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum);
  180. static int mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum);
  181. static void mpt_read_ioc_pg_1(MPT_ADAPTER *ioc);
  182. static void mpt_read_ioc_pg_4(MPT_ADAPTER *ioc);
  183. static void mpt_timer_expired(unsigned long data);
  184. static int SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch);
  185. static int SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp);
  186. #ifdef CONFIG_PROC_FS
  187. static int procmpt_summary_read(char *buf, char **start, off_t offset,
  188. int request, int *eof, void *data);
  189. static int procmpt_version_read(char *buf, char **start, off_t offset,
  190. int request, int *eof, void *data);
  191. static int procmpt_iocinfo_read(char *buf, char **start, off_t offset,
  192. int request, int *eof, void *data);
  193. #endif
  194. static void mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc);
  195. //int mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag);
  196. static int ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *evReply, int *evHandlers);
  197. static void mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf);
  198. static void mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info);
  199. static void mpt_sp_log_info(MPT_ADAPTER *ioc, u32 log_info);
  200. /* module entry point */
  201. static int __devinit mptbase_probe (struct pci_dev *, const struct pci_device_id *);
  202. static void __devexit mptbase_remove(struct pci_dev *);
  203. static void mptbase_shutdown(struct device * );
  204. static int __init fusion_init (void);
  205. static void __exit fusion_exit (void);
  206. /****************************************************************************
  207. * Supported hardware
  208. */
  209. static struct pci_device_id mptbase_pci_table[] = {
  210. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC909,
  211. PCI_ANY_ID, PCI_ANY_ID },
  212. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC929,
  213. PCI_ANY_ID, PCI_ANY_ID },
  214. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC919,
  215. PCI_ANY_ID, PCI_ANY_ID },
  216. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC929X,
  217. PCI_ANY_ID, PCI_ANY_ID },
  218. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC919X,
  219. PCI_ANY_ID, PCI_ANY_ID },
  220. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1030,
  221. PCI_ANY_ID, PCI_ANY_ID },
  222. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_1030_53C1035,
  223. PCI_ANY_ID, PCI_ANY_ID },
  224. {0} /* Terminating entry */
  225. };
  226. MODULE_DEVICE_TABLE(pci, mptbase_pci_table);
  227. #define CHIPREG_READ32(addr) readl_relaxed(addr)
  228. #define CHIPREG_READ32_dmasync(addr) readl(addr)
  229. #define CHIPREG_WRITE32(addr,val) writel(val, addr)
  230. #define CHIPREG_PIO_WRITE32(addr,val) outl(val, (unsigned long)addr)
  231. #define CHIPREG_PIO_READ32(addr) inl((unsigned long)addr)
  232. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  233. /*
  234. * mpt_interrupt - MPT adapter (IOC) specific interrupt handler.
  235. * @irq: irq number (not used)
  236. * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
  237. * @r: pt_regs pointer (not used)
  238. *
  239. * This routine is registered via the request_irq() kernel API call,
  240. * and handles all interrupts generated from a specific MPT adapter
  241. * (also referred to as a IO Controller or IOC).
  242. * This routine must clear the interrupt from the adapter and does
  243. * so by reading the reply FIFO. Multiple replies may be processed
  244. * per single call to this routine; up to MPT_MAX_REPLIES_PER_ISR
  245. * which is currently set to 32 in mptbase.h.
  246. *
  247. * This routine handles register-level access of the adapter but
  248. * dispatches (calls) a protocol-specific callback routine to handle
  249. * the protocol-specific details of the MPT request completion.
  250. */
  251. static irqreturn_t
  252. mpt_interrupt(int irq, void *bus_id, struct pt_regs *r)
  253. {
  254. MPT_ADAPTER *ioc;
  255. MPT_FRAME_HDR *mf;
  256. MPT_FRAME_HDR *mr;
  257. u32 pa;
  258. int req_idx;
  259. int cb_idx;
  260. int type;
  261. int freeme;
  262. ioc = (MPT_ADAPTER *)bus_id;
  263. /*
  264. * Drain the reply FIFO!
  265. *
  266. * NOTES: I've seen up to 10 replies processed in this loop, so far...
  267. * Update: I've seen up to 9182 replies processed in this loop! ??
  268. * Update: Limit ourselves to processing max of N replies
  269. * (bottom of loop).
  270. */
  271. while (1) {
  272. if ((pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo)) == 0xFFFFFFFF)
  273. return IRQ_HANDLED;
  274. cb_idx = 0;
  275. freeme = 0;
  276. /*
  277. * Check for non-TURBO reply!
  278. */
  279. if (pa & MPI_ADDRESS_REPLY_A_BIT) {
  280. u32 reply_dma_low;
  281. u16 ioc_stat;
  282. /* non-TURBO reply! Hmmm, something may be up...
  283. * Newest turbo reply mechanism; get address
  284. * via left shift 1 (get rid of MPI_ADDRESS_REPLY_A_BIT)!
  285. */
  286. /* Map DMA address of reply header to cpu address.
  287. * pa is 32 bits - but the dma address may be 32 or 64 bits
  288. * get offset based only only the low addresses
  289. */
  290. reply_dma_low = (pa = (pa << 1));
  291. mr = (MPT_FRAME_HDR *)((u8 *)ioc->reply_frames +
  292. (reply_dma_low - ioc->reply_frames_low_dma));
  293. req_idx = le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx);
  294. cb_idx = mr->u.frame.hwhdr.msgctxu.fld.cb_idx;
  295. mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
  296. dmfprintk((MYIOC_s_INFO_FMT "Got non-TURBO reply=%p req_idx=%x\n",
  297. ioc->name, mr, req_idx));
  298. DBG_DUMP_REPLY_FRAME(mr)
  299. /* NEW! 20010301 -sralston
  300. * Check/log IOC log info
  301. */
  302. ioc_stat = le16_to_cpu(mr->u.reply.IOCStatus);
  303. if (ioc_stat & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
  304. u32 log_info = le32_to_cpu(mr->u.reply.IOCLogInfo);
  305. if (ioc->bus_type == FC)
  306. mpt_fc_log_info(ioc, log_info);
  307. else if (ioc->bus_type == SCSI)
  308. mpt_sp_log_info(ioc, log_info);
  309. }
  310. if (ioc_stat & MPI_IOCSTATUS_MASK) {
  311. if (ioc->bus_type == SCSI)
  312. mpt_sp_ioc_info(ioc, (u32)ioc_stat, mf);
  313. }
  314. } else {
  315. /*
  316. * Process turbo (context) reply...
  317. */
  318. dmfprintk((MYIOC_s_INFO_FMT "Got TURBO reply req_idx=%08x\n", ioc->name, pa));
  319. type = (pa >> MPI_CONTEXT_REPLY_TYPE_SHIFT);
  320. if (type == MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET) {
  321. cb_idx = mpt_stm_index;
  322. mf = NULL;
  323. mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
  324. } else if (type == MPI_CONTEXT_REPLY_TYPE_LAN) {
  325. cb_idx = mpt_lan_index;
  326. /*
  327. * BUG FIX! 20001218 -sralston
  328. * Blind set of mf to NULL here was fatal
  329. * after lan_reply says "freeme"
  330. * Fix sort of combined with an optimization here;
  331. * added explicit check for case where lan_reply
  332. * was just returning 1 and doing nothing else.
  333. * For this case skip the callback, but set up
  334. * proper mf value first here:-)
  335. */
  336. if ((pa & 0x58000000) == 0x58000000) {
  337. req_idx = pa & 0x0000FFFF;
  338. mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
  339. freeme = 1;
  340. /*
  341. * IMPORTANT! Invalidate the callback!
  342. */
  343. cb_idx = 0;
  344. } else {
  345. mf = NULL;
  346. }
  347. mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
  348. } else {
  349. req_idx = pa & 0x0000FFFF;
  350. cb_idx = (pa & 0x00FF0000) >> 16;
  351. mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
  352. mr = NULL;
  353. }
  354. pa = 0; /* No reply flush! */
  355. }
  356. #ifdef MPT_DEBUG_IRQ
  357. if (ioc->bus_type == SCSI) {
  358. /* Verify mf, mr are reasonable.
  359. */
  360. if ((mf) && ((mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))
  361. || (mf < ioc->req_frames)) ) {
  362. printk(MYIOC_s_WARN_FMT
  363. "mpt_interrupt: Invalid mf (%p) req_idx (%d)!\n", ioc->name, (void *)mf, req_idx);
  364. cb_idx = 0;
  365. pa = 0;
  366. freeme = 0;
  367. }
  368. if ((pa) && (mr) && ((mr >= MPT_INDEX_2_RFPTR(ioc, ioc->req_depth))
  369. || (mr < ioc->reply_frames)) ) {
  370. printk(MYIOC_s_WARN_FMT
  371. "mpt_interrupt: Invalid rf (%p)!\n", ioc->name, (void *)mr);
  372. cb_idx = 0;
  373. pa = 0;
  374. freeme = 0;
  375. }
  376. if (cb_idx > (MPT_MAX_PROTOCOL_DRIVERS-1)) {
  377. printk(MYIOC_s_WARN_FMT
  378. "mpt_interrupt: Invalid cb_idx (%d)!\n", ioc->name, cb_idx);
  379. cb_idx = 0;
  380. pa = 0;
  381. freeme = 0;
  382. }
  383. }
  384. #endif
  385. /* Check for (valid) IO callback! */
  386. if (cb_idx) {
  387. /* Do the callback! */
  388. freeme = (*(MptCallbacks[cb_idx]))(ioc, mf, mr);
  389. }
  390. if (pa) {
  391. /* Flush (non-TURBO) reply with a WRITE! */
  392. CHIPREG_WRITE32(&ioc->chip->ReplyFifo, pa);
  393. }
  394. if (freeme) {
  395. unsigned long flags;
  396. /* Put Request back on FreeQ! */
  397. spin_lock_irqsave(&ioc->FreeQlock, flags);
  398. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
  399. #ifdef MFCNT
  400. ioc->mfcnt--;
  401. #endif
  402. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  403. }
  404. mb();
  405. } /* drain reply FIFO */
  406. return IRQ_HANDLED;
  407. }
  408. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  409. /*
  410. * mpt_base_reply - MPT base driver's callback routine; all base driver
  411. * "internal" request/reply processing is routed here.
  412. * Currently used for EventNotification and EventAck handling.
  413. * @ioc: Pointer to MPT_ADAPTER structure
  414. * @mf: Pointer to original MPT request frame
  415. * @reply: Pointer to MPT reply frame (NULL if TurboReply)
  416. *
  417. * Returns 1 indicating original alloc'd request frame ptr
  418. * should be freed, or 0 if it shouldn't.
  419. */
  420. static int
  421. mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
  422. {
  423. int freereq = 1;
  424. u8 func;
  425. dprintk((MYIOC_s_INFO_FMT "mpt_base_reply() called\n", ioc->name));
  426. if ((mf == NULL) ||
  427. (mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))) {
  428. printk(MYIOC_s_ERR_FMT "NULL or BAD request frame ptr! (=%p)\n",
  429. ioc->name, (void *)mf);
  430. return 1;
  431. }
  432. if (reply == NULL) {
  433. dprintk((MYIOC_s_ERR_FMT "Unexpected NULL Event (turbo?) reply!\n",
  434. ioc->name));
  435. return 1;
  436. }
  437. if (!(reply->u.hdr.MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)) {
  438. dmfprintk((KERN_INFO MYNAM ": Original request frame (@%p) header\n", mf));
  439. DBG_DUMP_REQUEST_FRAME_HDR(mf)
  440. }
  441. func = reply->u.hdr.Function;
  442. dprintk((MYIOC_s_INFO_FMT "mpt_base_reply, Function=%02Xh\n",
  443. ioc->name, func));
  444. if (func == MPI_FUNCTION_EVENT_NOTIFICATION) {
  445. EventNotificationReply_t *pEvReply = (EventNotificationReply_t *) reply;
  446. int evHandlers = 0;
  447. int results;
  448. results = ProcessEventNotification(ioc, pEvReply, &evHandlers);
  449. if (results != evHandlers) {
  450. /* CHECKME! Any special handling needed here? */
  451. devtprintk((MYIOC_s_WARN_FMT "Called %d event handlers, sum results = %d\n",
  452. ioc->name, evHandlers, results));
  453. }
  454. /*
  455. * Hmmm... It seems that EventNotificationReply is an exception
  456. * to the rule of one reply per request.
  457. */
  458. if (pEvReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)
  459. freereq = 0;
  460. #ifdef CONFIG_PROC_FS
  461. // LogEvent(ioc, pEvReply);
  462. #endif
  463. } else if (func == MPI_FUNCTION_EVENT_ACK) {
  464. dprintk((MYIOC_s_INFO_FMT "mpt_base_reply, EventAck reply received\n",
  465. ioc->name));
  466. } else if (func == MPI_FUNCTION_CONFIG ||
  467. func == MPI_FUNCTION_TOOLBOX) {
  468. CONFIGPARMS *pCfg;
  469. unsigned long flags;
  470. dcprintk((MYIOC_s_INFO_FMT "config_complete (mf=%p,mr=%p)\n",
  471. ioc->name, mf, reply));
  472. pCfg = * ((CONFIGPARMS **)((u8 *) mf + ioc->req_sz - sizeof(void *)));
  473. if (pCfg) {
  474. /* disable timer and remove from linked list */
  475. del_timer(&pCfg->timer);
  476. spin_lock_irqsave(&ioc->FreeQlock, flags);
  477. list_del(&pCfg->linkage);
  478. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  479. /*
  480. * If IOC Status is SUCCESS, save the header
  481. * and set the status code to GOOD.
  482. */
  483. pCfg->status = MPT_CONFIG_ERROR;
  484. if (reply) {
  485. ConfigReply_t *pReply = (ConfigReply_t *)reply;
  486. u16 status;
  487. status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  488. dcprintk((KERN_NOTICE " IOCStatus=%04xh, IOCLogInfo=%08xh\n",
  489. status, le32_to_cpu(pReply->IOCLogInfo)));
  490. pCfg->status = status;
  491. if (status == MPI_IOCSTATUS_SUCCESS) {
  492. pCfg->hdr->PageVersion = pReply->Header.PageVersion;
  493. pCfg->hdr->PageLength = pReply->Header.PageLength;
  494. pCfg->hdr->PageNumber = pReply->Header.PageNumber;
  495. pCfg->hdr->PageType = pReply->Header.PageType;
  496. }
  497. }
  498. /*
  499. * Wake up the original calling thread
  500. */
  501. pCfg->wait_done = 1;
  502. wake_up(&mpt_waitq);
  503. }
  504. } else {
  505. printk(MYIOC_s_ERR_FMT "Unexpected msg function (=%02Xh) reply received!\n",
  506. ioc->name, func);
  507. }
  508. /*
  509. * Conditionally tell caller to free the original
  510. * EventNotification/EventAck/unexpected request frame!
  511. */
  512. return freereq;
  513. }
  514. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  515. /**
  516. * mpt_register - Register protocol-specific main callback handler.
  517. * @cbfunc: callback function pointer
  518. * @dclass: Protocol driver's class (%MPT_DRIVER_CLASS enum value)
  519. *
  520. * This routine is called by a protocol-specific driver (SCSI host,
  521. * LAN, SCSI target) to register it's reply callback routine. Each
  522. * protocol-specific driver must do this before it will be able to
  523. * use any IOC resources, such as obtaining request frames.
  524. *
  525. * NOTES: The SCSI protocol driver currently calls this routine thrice
  526. * in order to register separate callbacks; one for "normal" SCSI IO;
  527. * one for MptScsiTaskMgmt requests; one for Scan/DV requests.
  528. *
  529. * Returns a positive integer valued "handle" in the
  530. * range (and S.O.D. order) {N,...,7,6,5,...,1} if successful.
  531. * Any non-positive return value (including zero!) should be considered
  532. * an error by the caller.
  533. */
  534. int
  535. mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass)
  536. {
  537. int i;
  538. last_drv_idx = -1;
  539. /*
  540. * Search for empty callback slot in this order: {N,...,7,6,5,...,1}
  541. * (slot/handle 0 is reserved!)
  542. */
  543. for (i = MPT_MAX_PROTOCOL_DRIVERS-1; i; i--) {
  544. if (MptCallbacks[i] == NULL) {
  545. MptCallbacks[i] = cbfunc;
  546. MptDriverClass[i] = dclass;
  547. MptEvHandlers[i] = NULL;
  548. last_drv_idx = i;
  549. break;
  550. }
  551. }
  552. return last_drv_idx;
  553. }
  554. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  555. /**
  556. * mpt_deregister - Deregister a protocol drivers resources.
  557. * @cb_idx: previously registered callback handle
  558. *
  559. * Each protocol-specific driver should call this routine when it's
  560. * module is unloaded.
  561. */
  562. void
  563. mpt_deregister(int cb_idx)
  564. {
  565. if ((cb_idx >= 0) && (cb_idx < MPT_MAX_PROTOCOL_DRIVERS)) {
  566. MptCallbacks[cb_idx] = NULL;
  567. MptDriverClass[cb_idx] = MPTUNKNOWN_DRIVER;
  568. MptEvHandlers[cb_idx] = NULL;
  569. last_drv_idx++;
  570. }
  571. }
  572. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  573. /**
  574. * mpt_event_register - Register protocol-specific event callback
  575. * handler.
  576. * @cb_idx: previously registered (via mpt_register) callback handle
  577. * @ev_cbfunc: callback function
  578. *
  579. * This routine can be called by one or more protocol-specific drivers
  580. * if/when they choose to be notified of MPT events.
  581. *
  582. * Returns 0 for success.
  583. */
  584. int
  585. mpt_event_register(int cb_idx, MPT_EVHANDLER ev_cbfunc)
  586. {
  587. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  588. return -1;
  589. MptEvHandlers[cb_idx] = ev_cbfunc;
  590. return 0;
  591. }
  592. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  593. /**
  594. * mpt_event_deregister - Deregister protocol-specific event callback
  595. * handler.
  596. * @cb_idx: previously registered callback handle
  597. *
  598. * Each protocol-specific driver should call this routine
  599. * when it does not (or can no longer) handle events,
  600. * or when it's module is unloaded.
  601. */
  602. void
  603. mpt_event_deregister(int cb_idx)
  604. {
  605. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  606. return;
  607. MptEvHandlers[cb_idx] = NULL;
  608. }
  609. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  610. /**
  611. * mpt_reset_register - Register protocol-specific IOC reset handler.
  612. * @cb_idx: previously registered (via mpt_register) callback handle
  613. * @reset_func: reset function
  614. *
  615. * This routine can be called by one or more protocol-specific drivers
  616. * if/when they choose to be notified of IOC resets.
  617. *
  618. * Returns 0 for success.
  619. */
  620. int
  621. mpt_reset_register(int cb_idx, MPT_RESETHANDLER reset_func)
  622. {
  623. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  624. return -1;
  625. MptResetHandlers[cb_idx] = reset_func;
  626. return 0;
  627. }
  628. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  629. /**
  630. * mpt_reset_deregister - Deregister protocol-specific IOC reset handler.
  631. * @cb_idx: previously registered callback handle
  632. *
  633. * Each protocol-specific driver should call this routine
  634. * when it does not (or can no longer) handle IOC reset handling,
  635. * or when it's module is unloaded.
  636. */
  637. void
  638. mpt_reset_deregister(int cb_idx)
  639. {
  640. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  641. return;
  642. MptResetHandlers[cb_idx] = NULL;
  643. }
  644. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  645. /**
  646. * mpt_device_driver_register - Register device driver hooks
  647. */
  648. int
  649. mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, int cb_idx)
  650. {
  651. MPT_ADAPTER *ioc;
  652. int error=0;
  653. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS) {
  654. error= -EINVAL;
  655. return error;
  656. }
  657. MptDeviceDriverHandlers[cb_idx] = dd_cbfunc;
  658. /* call per pci device probe entry point */
  659. list_for_each_entry(ioc, &ioc_list, list) {
  660. if(dd_cbfunc->probe) {
  661. error = dd_cbfunc->probe(ioc->pcidev,
  662. ioc->pcidev->driver->id_table);
  663. if(error != 0)
  664. return error;
  665. }
  666. }
  667. return error;
  668. }
  669. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  670. /**
  671. * mpt_device_driver_deregister - DeRegister device driver hooks
  672. */
  673. void
  674. mpt_device_driver_deregister(int cb_idx)
  675. {
  676. struct mpt_pci_driver *dd_cbfunc;
  677. MPT_ADAPTER *ioc;
  678. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  679. return;
  680. dd_cbfunc = MptDeviceDriverHandlers[cb_idx];
  681. list_for_each_entry(ioc, &ioc_list, list) {
  682. if (dd_cbfunc->remove)
  683. dd_cbfunc->remove(ioc->pcidev);
  684. }
  685. MptDeviceDriverHandlers[cb_idx] = NULL;
  686. }
  687. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  688. /**
  689. * mpt_get_msg_frame - Obtain a MPT request frame from the pool (of 1024)
  690. * allocated per MPT adapter.
  691. * @handle: Handle of registered MPT protocol driver
  692. * @ioc: Pointer to MPT adapter structure
  693. *
  694. * Returns pointer to a MPT request frame or %NULL if none are available
  695. * or IOC is not active.
  696. */
  697. MPT_FRAME_HDR*
  698. mpt_get_msg_frame(int handle, MPT_ADAPTER *ioc)
  699. {
  700. MPT_FRAME_HDR *mf;
  701. unsigned long flags;
  702. u16 req_idx; /* Request index */
  703. /* validate handle and ioc identifier */
  704. #ifdef MFCNT
  705. if (!ioc->active)
  706. printk(KERN_WARNING "IOC Not Active! mpt_get_msg_frame returning NULL!\n");
  707. #endif
  708. /* If interrupts are not attached, do not return a request frame */
  709. if (!ioc->active)
  710. return NULL;
  711. spin_lock_irqsave(&ioc->FreeQlock, flags);
  712. if (!list_empty(&ioc->FreeQ)) {
  713. int req_offset;
  714. mf = list_entry(ioc->FreeQ.next, MPT_FRAME_HDR,
  715. u.frame.linkage.list);
  716. list_del(&mf->u.frame.linkage.list);
  717. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle; /* byte */
  718. req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
  719. /* u16! */
  720. req_idx = cpu_to_le16(req_offset / ioc->req_sz);
  721. mf->u.frame.hwhdr.msgctxu.fld.req_idx = req_idx;
  722. mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
  723. ioc->RequestNB[req_idx] = ioc->NB_for_64_byte_frame; /* Default, will be changed if necessary in SG generation */
  724. #ifdef MFCNT
  725. ioc->mfcnt++;
  726. #endif
  727. }
  728. else
  729. mf = NULL;
  730. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  731. #ifdef MFCNT
  732. if (mf == NULL)
  733. printk(KERN_WARNING "IOC Active. No free Msg Frames! Count 0x%x Max 0x%x\n", ioc->mfcnt, ioc->req_depth);
  734. mfcounter++;
  735. if (mfcounter == PRINT_MF_COUNT)
  736. printk(KERN_INFO "MF Count 0x%x Max 0x%x \n", ioc->mfcnt, ioc->req_depth);
  737. #endif
  738. dmfprintk((KERN_INFO MYNAM ": %s: mpt_get_msg_frame(%d,%d), got mf=%p\n",
  739. ioc->name, handle, ioc->id, mf));
  740. return mf;
  741. }
  742. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  743. /**
  744. * mpt_put_msg_frame - Send a protocol specific MPT request frame
  745. * to a IOC.
  746. * @handle: Handle of registered MPT protocol driver
  747. * @ioc: Pointer to MPT adapter structure
  748. * @mf: Pointer to MPT request frame
  749. *
  750. * This routine posts a MPT request frame to the request post FIFO of a
  751. * specific MPT adapter.
  752. */
  753. void
  754. mpt_put_msg_frame(int handle, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
  755. {
  756. u32 mf_dma_addr;
  757. int req_offset;
  758. u16 req_idx; /* Request index */
  759. /* ensure values are reset properly! */
  760. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle; /* byte */
  761. req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
  762. /* u16! */
  763. req_idx = cpu_to_le16(req_offset / ioc->req_sz);
  764. mf->u.frame.hwhdr.msgctxu.fld.req_idx = req_idx;
  765. mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
  766. #ifdef MPT_DEBUG_MSG_FRAME
  767. {
  768. u32 *m = mf->u.frame.hwhdr.__hdr;
  769. int ii, n;
  770. printk(KERN_INFO MYNAM ": %s: About to Put msg frame @ %p:\n" KERN_INFO " ",
  771. ioc->name, m);
  772. n = ioc->req_sz/4 - 1;
  773. while (m[n] == 0)
  774. n--;
  775. for (ii=0; ii<=n; ii++) {
  776. if (ii && ((ii%8)==0))
  777. printk("\n" KERN_INFO " ");
  778. printk(" %08x", le32_to_cpu(m[ii]));
  779. }
  780. printk("\n");
  781. }
  782. #endif
  783. mf_dma_addr = (ioc->req_frames_low_dma + req_offset) | ioc->RequestNB[req_idx];
  784. dsgprintk((MYIOC_s_INFO_FMT "mf_dma_addr=%x req_idx=%d RequestNB=%x\n", ioc->name, mf_dma_addr, req_idx, ioc->RequestNB[req_idx]));
  785. CHIPREG_WRITE32(&ioc->chip->RequestFifo, mf_dma_addr);
  786. }
  787. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  788. /**
  789. * mpt_free_msg_frame - Place MPT request frame back on FreeQ.
  790. * @handle: Handle of registered MPT protocol driver
  791. * @ioc: Pointer to MPT adapter structure
  792. * @mf: Pointer to MPT request frame
  793. *
  794. * This routine places a MPT request frame back on the MPT adapter's
  795. * FreeQ.
  796. */
  797. void
  798. mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
  799. {
  800. unsigned long flags;
  801. /* Put Request back on FreeQ! */
  802. spin_lock_irqsave(&ioc->FreeQlock, flags);
  803. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
  804. #ifdef MFCNT
  805. ioc->mfcnt--;
  806. #endif
  807. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  808. }
  809. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  810. /**
  811. * mpt_add_sge - Place a simple SGE at address pAddr.
  812. * @pAddr: virtual address for SGE
  813. * @flagslength: SGE flags and data transfer length
  814. * @dma_addr: Physical address
  815. *
  816. * This routine places a MPT request frame back on the MPT adapter's
  817. * FreeQ.
  818. */
  819. void
  820. mpt_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
  821. {
  822. if (sizeof(dma_addr_t) == sizeof(u64)) {
  823. SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
  824. u32 tmp = dma_addr & 0xFFFFFFFF;
  825. pSge->FlagsLength = cpu_to_le32(flagslength);
  826. pSge->Address.Low = cpu_to_le32(tmp);
  827. tmp = (u32) ((u64)dma_addr >> 32);
  828. pSge->Address.High = cpu_to_le32(tmp);
  829. } else {
  830. SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
  831. pSge->FlagsLength = cpu_to_le32(flagslength);
  832. pSge->Address = cpu_to_le32(dma_addr);
  833. }
  834. }
  835. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  836. /**
  837. * mpt_send_handshake_request - Send MPT request via doorbell
  838. * handshake method.
  839. * @handle: Handle of registered MPT protocol driver
  840. * @ioc: Pointer to MPT adapter structure
  841. * @reqBytes: Size of the request in bytes
  842. * @req: Pointer to MPT request frame
  843. * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
  844. *
  845. * This routine is used exclusively to send MptScsiTaskMgmt
  846. * requests since they are required to be sent via doorbell handshake.
  847. *
  848. * NOTE: It is the callers responsibility to byte-swap fields in the
  849. * request which are greater than 1 byte in size.
  850. *
  851. * Returns 0 for success, non-zero for failure.
  852. */
  853. int
  854. mpt_send_handshake_request(int handle, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag)
  855. {
  856. int r = 0;
  857. u8 *req_as_bytes;
  858. int ii;
  859. /* State is known to be good upon entering
  860. * this function so issue the bus reset
  861. * request.
  862. */
  863. /*
  864. * Emulate what mpt_put_msg_frame() does /wrt to sanity
  865. * setting cb_idx/req_idx. But ONLY if this request
  866. * is in proper (pre-alloc'd) request buffer range...
  867. */
  868. ii = MFPTR_2_MPT_INDEX(ioc,(MPT_FRAME_HDR*)req);
  869. if (reqBytes >= 12 && ii >= 0 && ii < ioc->req_depth) {
  870. MPT_FRAME_HDR *mf = (MPT_FRAME_HDR*)req;
  871. mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(ii);
  872. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle;
  873. }
  874. /* Make sure there are no doorbells */
  875. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  876. CHIPREG_WRITE32(&ioc->chip->Doorbell,
  877. ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
  878. ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
  879. /* Wait for IOC doorbell int */
  880. if ((ii = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0) {
  881. return ii;
  882. }
  883. /* Read doorbell and check for active bit */
  884. if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
  885. return -5;
  886. dhsprintk((KERN_INFO MYNAM ": %s: mpt_send_handshake_request start, WaitCnt=%d\n",
  887. ioc->name, ii));
  888. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  889. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
  890. return -2;
  891. }
  892. /* Send request via doorbell handshake */
  893. req_as_bytes = (u8 *) req;
  894. for (ii = 0; ii < reqBytes/4; ii++) {
  895. u32 word;
  896. word = ((req_as_bytes[(ii*4) + 0] << 0) |
  897. (req_as_bytes[(ii*4) + 1] << 8) |
  898. (req_as_bytes[(ii*4) + 2] << 16) |
  899. (req_as_bytes[(ii*4) + 3] << 24));
  900. CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
  901. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
  902. r = -3;
  903. break;
  904. }
  905. }
  906. if (r >= 0 && WaitForDoorbellInt(ioc, 10, sleepFlag) >= 0)
  907. r = 0;
  908. else
  909. r = -4;
  910. /* Make sure there are no doorbells */
  911. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  912. return r;
  913. }
  914. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  915. /**
  916. * mpt_verify_adapter - Given a unique IOC identifier, set pointer to
  917. * the associated MPT adapter structure.
  918. * @iocid: IOC unique identifier (integer)
  919. * @iocpp: Pointer to pointer to IOC adapter
  920. *
  921. * Returns iocid and sets iocpp.
  922. */
  923. int
  924. mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp)
  925. {
  926. MPT_ADAPTER *ioc;
  927. list_for_each_entry(ioc,&ioc_list,list) {
  928. if (ioc->id == iocid) {
  929. *iocpp =ioc;
  930. return iocid;
  931. }
  932. }
  933. *iocpp = NULL;
  934. return -1;
  935. }
  936. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  937. /*
  938. * mptbase_probe - Install a PCI intelligent MPT adapter.
  939. * @pdev: Pointer to pci_dev structure
  940. *
  941. * This routine performs all the steps necessary to bring the IOC of
  942. * a MPT adapter to a OPERATIONAL state. This includes registering
  943. * memory regions, registering the interrupt, and allocating request
  944. * and reply memory pools.
  945. *
  946. * This routine also pre-fetches the LAN MAC address of a Fibre Channel
  947. * MPT adapter.
  948. *
  949. * Returns 0 for success, non-zero for failure.
  950. *
  951. * TODO: Add support for polled controllers
  952. */
  953. static int __devinit
  954. mptbase_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  955. {
  956. MPT_ADAPTER *ioc;
  957. u8 __iomem *mem;
  958. unsigned long mem_phys;
  959. unsigned long port;
  960. u32 msize;
  961. u32 psize;
  962. int ii;
  963. int r = -ENODEV;
  964. u64 mask = 0xffffffffffffffffULL;
  965. u8 revision;
  966. u8 pcixcmd;
  967. static int mpt_ids = 0;
  968. #ifdef CONFIG_PROC_FS
  969. struct proc_dir_entry *dent, *ent;
  970. #endif
  971. if (pci_enable_device(pdev))
  972. return r;
  973. dinitprintk((KERN_WARNING MYNAM ": mpt_adapter_install\n"));
  974. if (!pci_set_dma_mask(pdev, mask)) {
  975. dprintk((KERN_INFO MYNAM
  976. ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n"));
  977. } else if (pci_set_dma_mask(pdev, (u64) 0xffffffff)) {
  978. printk(KERN_WARNING MYNAM ": 32 BIT PCI BUS DMA ADDRESSING NOT SUPPORTED\n");
  979. return r;
  980. }
  981. if (!pci_set_consistent_dma_mask(pdev, mask))
  982. dprintk((KERN_INFO MYNAM
  983. ": Using 64 bit consistent mask\n"));
  984. else
  985. dprintk((KERN_INFO MYNAM
  986. ": Not using 64 bit consistent mask\n"));
  987. ioc = kmalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC);
  988. if (ioc == NULL) {
  989. printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
  990. return -ENOMEM;
  991. }
  992. memset(ioc, 0, sizeof(MPT_ADAPTER));
  993. ioc->alloc_total = sizeof(MPT_ADAPTER);
  994. ioc->req_sz = MPT_DEFAULT_FRAME_SIZE; /* avoid div by zero! */
  995. ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
  996. ioc->pcidev = pdev;
  997. ioc->diagPending = 0;
  998. spin_lock_init(&ioc->diagLock);
  999. /* Initialize the event logging.
  1000. */
  1001. ioc->eventTypes = 0; /* None */
  1002. ioc->eventContext = 0;
  1003. ioc->eventLogSize = 0;
  1004. ioc->events = NULL;
  1005. #ifdef MFCNT
  1006. ioc->mfcnt = 0;
  1007. #endif
  1008. ioc->cached_fw = NULL;
  1009. /* Initilize SCSI Config Data structure
  1010. */
  1011. memset(&ioc->spi_data, 0, sizeof(ScsiCfgData));
  1012. /* Initialize the running configQ head.
  1013. */
  1014. INIT_LIST_HEAD(&ioc->configQ);
  1015. /* Find lookup slot. */
  1016. INIT_LIST_HEAD(&ioc->list);
  1017. ioc->id = mpt_ids++;
  1018. mem_phys = msize = 0;
  1019. port = psize = 0;
  1020. for (ii=0; ii < DEVICE_COUNT_RESOURCE; ii++) {
  1021. if (pci_resource_flags(pdev, ii) & PCI_BASE_ADDRESS_SPACE_IO) {
  1022. /* Get I/O space! */
  1023. port = pci_resource_start(pdev, ii);
  1024. psize = pci_resource_len(pdev,ii);
  1025. } else {
  1026. /* Get memmap */
  1027. mem_phys = pci_resource_start(pdev, ii);
  1028. msize = pci_resource_len(pdev,ii);
  1029. break;
  1030. }
  1031. }
  1032. ioc->mem_size = msize;
  1033. if (ii == DEVICE_COUNT_RESOURCE) {
  1034. printk(KERN_ERR MYNAM ": ERROR - MPT adapter has no memory regions defined!\n");
  1035. kfree(ioc);
  1036. return -EINVAL;
  1037. }
  1038. dinitprintk((KERN_INFO MYNAM ": MPT adapter @ %lx, msize=%dd bytes\n", mem_phys, msize));
  1039. dinitprintk((KERN_INFO MYNAM ": (port i/o @ %lx, psize=%dd bytes)\n", port, psize));
  1040. mem = NULL;
  1041. /* Get logical ptr for PciMem0 space */
  1042. /*mem = ioremap(mem_phys, msize);*/
  1043. mem = ioremap(mem_phys, 0x100);
  1044. if (mem == NULL) {
  1045. printk(KERN_ERR MYNAM ": ERROR - Unable to map adapter memory!\n");
  1046. kfree(ioc);
  1047. return -EINVAL;
  1048. }
  1049. ioc->memmap = mem;
  1050. dinitprintk((KERN_INFO MYNAM ": mem = %p, mem_phys = %lx\n", mem, mem_phys));
  1051. dinitprintk((KERN_INFO MYNAM ": facts @ %p, pfacts[0] @ %p\n",
  1052. &ioc->facts, &ioc->pfacts[0]));
  1053. ioc->mem_phys = mem_phys;
  1054. ioc->chip = (SYSIF_REGS __iomem *)mem;
  1055. /* Save Port IO values in case we need to do downloadboot */
  1056. {
  1057. u8 *pmem = (u8*)port;
  1058. ioc->pio_mem_phys = port;
  1059. ioc->pio_chip = (SYSIF_REGS __iomem *)pmem;
  1060. }
  1061. if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC909) {
  1062. ioc->prod_name = "LSIFC909";
  1063. ioc->bus_type = FC;
  1064. }
  1065. if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC929) {
  1066. ioc->prod_name = "LSIFC929";
  1067. ioc->bus_type = FC;
  1068. }
  1069. else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC919) {
  1070. ioc->prod_name = "LSIFC919";
  1071. ioc->bus_type = FC;
  1072. }
  1073. else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC929X) {
  1074. pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
  1075. ioc->bus_type = FC;
  1076. if (revision < XL_929) {
  1077. ioc->prod_name = "LSIFC929X";
  1078. /* 929X Chip Fix. Set Split transactions level
  1079. * for PCIX. Set MOST bits to zero.
  1080. */
  1081. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1082. pcixcmd &= 0x8F;
  1083. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1084. } else {
  1085. ioc->prod_name = "LSIFC929XL";
  1086. /* 929XL Chip Fix. Set MMRBC to 0x08.
  1087. */
  1088. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1089. pcixcmd |= 0x08;
  1090. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1091. }
  1092. }
  1093. else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC919X) {
  1094. ioc->prod_name = "LSIFC919X";
  1095. ioc->bus_type = FC;
  1096. /* 919X Chip Fix. Set Split transactions level
  1097. * for PCIX. Set MOST bits to zero.
  1098. */
  1099. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1100. pcixcmd &= 0x8F;
  1101. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1102. }
  1103. else if (pdev->device == MPI_MANUFACTPAGE_DEVID_53C1030) {
  1104. ioc->prod_name = "LSI53C1030";
  1105. ioc->bus_type = SCSI;
  1106. /* 1030 Chip Fix. Disable Split transactions
  1107. * for PCIX. Set MOST bits to zero if Rev < C0( = 8).
  1108. */
  1109. pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
  1110. if (revision < C0_1030) {
  1111. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1112. pcixcmd &= 0x8F;
  1113. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1114. }
  1115. }
  1116. else if (pdev->device == MPI_MANUFACTPAGE_DEVID_1030_53C1035) {
  1117. ioc->prod_name = "LSI53C1035";
  1118. ioc->bus_type = SCSI;
  1119. }
  1120. sprintf(ioc->name, "ioc%d", ioc->id);
  1121. spin_lock_init(&ioc->FreeQlock);
  1122. /* Disable all! */
  1123. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1124. ioc->active = 0;
  1125. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1126. /* Set lookup ptr. */
  1127. list_add_tail(&ioc->list, &ioc_list);
  1128. ioc->pci_irq = -1;
  1129. if (pdev->irq) {
  1130. r = request_irq(pdev->irq, mpt_interrupt, SA_SHIRQ, ioc->name, ioc);
  1131. if (r < 0) {
  1132. #ifndef __sparc__
  1133. printk(MYIOC_s_ERR_FMT "Unable to allocate interrupt %d!\n",
  1134. ioc->name, pdev->irq);
  1135. #else
  1136. printk(MYIOC_s_ERR_FMT "Unable to allocate interrupt %s!\n",
  1137. ioc->name, __irq_itoa(pdev->irq));
  1138. #endif
  1139. list_del(&ioc->list);
  1140. iounmap(mem);
  1141. kfree(ioc);
  1142. return -EBUSY;
  1143. }
  1144. ioc->pci_irq = pdev->irq;
  1145. pci_set_master(pdev); /* ?? */
  1146. pci_set_drvdata(pdev, ioc);
  1147. #ifndef __sparc__
  1148. dprintk((KERN_INFO MYNAM ": %s installed at interrupt %d\n", ioc->name, pdev->irq));
  1149. #else
  1150. dprintk((KERN_INFO MYNAM ": %s installed at interrupt %s\n", ioc->name, __irq_itoa(pdev->irq)));
  1151. #endif
  1152. }
  1153. /* NEW! 20010220 -sralston
  1154. * Check for "bound ports" (929, 929X, 1030, 1035) to reduce redundant resets.
  1155. */
  1156. mpt_detect_bound_ports(ioc, pdev);
  1157. if ((r = mpt_do_ioc_recovery(ioc,
  1158. MPT_HOSTEVENT_IOC_BRINGUP, CAN_SLEEP)) != 0) {
  1159. printk(KERN_WARNING MYNAM
  1160. ": WARNING - %s did not initialize properly! (%d)\n",
  1161. ioc->name, r);
  1162. list_del(&ioc->list);
  1163. free_irq(ioc->pci_irq, ioc);
  1164. iounmap(mem);
  1165. kfree(ioc);
  1166. pci_set_drvdata(pdev, NULL);
  1167. return r;
  1168. }
  1169. /* call per device driver probe entry point */
  1170. for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
  1171. if(MptDeviceDriverHandlers[ii] &&
  1172. MptDeviceDriverHandlers[ii]->probe) {
  1173. MptDeviceDriverHandlers[ii]->probe(pdev,id);
  1174. }
  1175. }
  1176. #ifdef CONFIG_PROC_FS
  1177. /*
  1178. * Create "/proc/mpt/iocN" subdirectory entry for each MPT adapter.
  1179. */
  1180. dent = proc_mkdir(ioc->name, mpt_proc_root_dir);
  1181. if (dent) {
  1182. ent = create_proc_entry("info", S_IFREG|S_IRUGO, dent);
  1183. if (ent) {
  1184. ent->read_proc = procmpt_iocinfo_read;
  1185. ent->data = ioc;
  1186. }
  1187. ent = create_proc_entry("summary", S_IFREG|S_IRUGO, dent);
  1188. if (ent) {
  1189. ent->read_proc = procmpt_summary_read;
  1190. ent->data = ioc;
  1191. }
  1192. }
  1193. #endif
  1194. return 0;
  1195. }
  1196. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1197. /*
  1198. * mptbase_remove - Remove a PCI intelligent MPT adapter.
  1199. * @pdev: Pointer to pci_dev structure
  1200. *
  1201. */
  1202. static void __devexit
  1203. mptbase_remove(struct pci_dev *pdev)
  1204. {
  1205. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1206. char pname[32];
  1207. int ii;
  1208. sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/summary", ioc->name);
  1209. remove_proc_entry(pname, NULL);
  1210. sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/info", ioc->name);
  1211. remove_proc_entry(pname, NULL);
  1212. sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s", ioc->name);
  1213. remove_proc_entry(pname, NULL);
  1214. /* call per device driver remove entry point */
  1215. for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
  1216. if(MptDeviceDriverHandlers[ii] &&
  1217. MptDeviceDriverHandlers[ii]->remove) {
  1218. MptDeviceDriverHandlers[ii]->remove(pdev);
  1219. }
  1220. }
  1221. /* Disable interrupts! */
  1222. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1223. ioc->active = 0;
  1224. synchronize_irq(pdev->irq);
  1225. /* Clear any lingering interrupt */
  1226. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1227. CHIPREG_READ32(&ioc->chip->IntStatus);
  1228. mpt_adapter_dispose(ioc);
  1229. pci_set_drvdata(pdev, NULL);
  1230. }
  1231. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1232. /*
  1233. * mptbase_shutdown -
  1234. *
  1235. */
  1236. static void
  1237. mptbase_shutdown(struct device * dev)
  1238. {
  1239. int ii;
  1240. /* call per device driver shutdown entry point */
  1241. for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
  1242. if(MptDeviceDriverHandlers[ii] &&
  1243. MptDeviceDriverHandlers[ii]->shutdown) {
  1244. MptDeviceDriverHandlers[ii]->shutdown(dev);
  1245. }
  1246. }
  1247. }
  1248. /**************************************************************************
  1249. * Power Management
  1250. */
  1251. #ifdef CONFIG_PM
  1252. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1253. /*
  1254. * mptbase_suspend - Fusion MPT base driver suspend routine.
  1255. *
  1256. *
  1257. */
  1258. static int
  1259. mptbase_suspend(struct pci_dev *pdev, pm_message_t state)
  1260. {
  1261. u32 device_state;
  1262. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1263. int ii;
  1264. switch(state)
  1265. {
  1266. case 1: /* S1 */
  1267. device_state=1; /* D1 */;
  1268. break;
  1269. case 3: /* S3 */
  1270. case 4: /* S4 */
  1271. device_state=3; /* D3 */;
  1272. break;
  1273. default:
  1274. return -EAGAIN /*FIXME*/;
  1275. break;
  1276. }
  1277. printk(MYIOC_s_INFO_FMT
  1278. "pci-suspend: pdev=0x%p, slot=%s, Entering operating state [D%d]\n",
  1279. ioc->name, pdev, pci_name(pdev), device_state);
  1280. /* call per device driver suspend entry point */
  1281. for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
  1282. if(MptDeviceDriverHandlers[ii] &&
  1283. MptDeviceDriverHandlers[ii]->suspend) {
  1284. MptDeviceDriverHandlers[ii]->suspend(pdev, state);
  1285. }
  1286. }
  1287. pci_save_state(pdev);
  1288. /* put ioc into READY_STATE */
  1289. if(SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, CAN_SLEEP)) {
  1290. printk(MYIOC_s_ERR_FMT
  1291. "pci-suspend: IOC msg unit reset failed!\n", ioc->name);
  1292. }
  1293. /* disable interrupts */
  1294. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1295. ioc->active = 0;
  1296. /* Clear any lingering interrupt */
  1297. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1298. pci_disable_device(pdev);
  1299. pci_set_power_state(pdev, device_state);
  1300. return 0;
  1301. }
  1302. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1303. /*
  1304. * mptbase_resume - Fusion MPT base driver resume routine.
  1305. *
  1306. *
  1307. */
  1308. static int
  1309. mptbase_resume(struct pci_dev *pdev)
  1310. {
  1311. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1312. u32 device_state = pdev->current_state;
  1313. int recovery_state;
  1314. int ii;
  1315. printk(MYIOC_s_INFO_FMT
  1316. "pci-resume: pdev=0x%p, slot=%s, Previous operating state [D%d]\n",
  1317. ioc->name, pdev, pci_name(pdev), device_state);
  1318. pci_set_power_state(pdev, 0);
  1319. pci_restore_state(pdev);
  1320. pci_enable_device(pdev);
  1321. /* enable interrupts */
  1322. CHIPREG_WRITE32(&ioc->chip->IntMask, ~(MPI_HIM_RIM));
  1323. ioc->active = 1;
  1324. /* F/W not running */
  1325. if(!CHIPREG_READ32(&ioc->chip->Doorbell)) {
  1326. /* enable domain validation flags */
  1327. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  1328. ioc->spi_data.dvStatus[ii] |= MPT_SCSICFG_NEED_DV;
  1329. }
  1330. }
  1331. printk(MYIOC_s_INFO_FMT
  1332. "pci-resume: ioc-state=0x%x,doorbell=0x%x\n",
  1333. ioc->name,
  1334. (mpt_GetIocState(ioc, 1) >> MPI_IOC_STATE_SHIFT),
  1335. CHIPREG_READ32(&ioc->chip->Doorbell));
  1336. /* bring ioc to operational state */
  1337. if ((recovery_state = mpt_do_ioc_recovery(ioc,
  1338. MPT_HOSTEVENT_IOC_RECOVER, CAN_SLEEP)) != 0) {
  1339. printk(MYIOC_s_INFO_FMT
  1340. "pci-resume: Cannot recover, error:[%x]\n",
  1341. ioc->name, recovery_state);
  1342. } else {
  1343. printk(MYIOC_s_INFO_FMT
  1344. "pci-resume: success\n", ioc->name);
  1345. }
  1346. /* call per device driver resume entry point */
  1347. for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
  1348. if(MptDeviceDriverHandlers[ii] &&
  1349. MptDeviceDriverHandlers[ii]->resume) {
  1350. MptDeviceDriverHandlers[ii]->resume(pdev);
  1351. }
  1352. }
  1353. return 0;
  1354. }
  1355. #endif
  1356. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1357. /*
  1358. * mpt_do_ioc_recovery - Initialize or recover MPT adapter.
  1359. * @ioc: Pointer to MPT adapter structure
  1360. * @reason: Event word / reason
  1361. * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
  1362. *
  1363. * This routine performs all the steps necessary to bring the IOC
  1364. * to a OPERATIONAL state.
  1365. *
  1366. * This routine also pre-fetches the LAN MAC address of a Fibre Channel
  1367. * MPT adapter.
  1368. *
  1369. * Returns:
  1370. * 0 for success
  1371. * -1 if failed to get board READY
  1372. * -2 if READY but IOCFacts Failed
  1373. * -3 if READY but PrimeIOCFifos Failed
  1374. * -4 if READY but IOCInit Failed
  1375. */
  1376. static int
  1377. mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
  1378. {
  1379. int hard_reset_done = 0;
  1380. int alt_ioc_ready = 0;
  1381. int hard;
  1382. int rc=0;
  1383. int ii;
  1384. int handlers;
  1385. int ret = 0;
  1386. int reset_alt_ioc_active = 0;
  1387. printk(KERN_INFO MYNAM ": Initiating %s %s\n",
  1388. ioc->name, reason==MPT_HOSTEVENT_IOC_BRINGUP ? "bringup" : "recovery");
  1389. /* Disable reply interrupts (also blocks FreeQ) */
  1390. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1391. ioc->active = 0;
  1392. if (ioc->alt_ioc) {
  1393. if (ioc->alt_ioc->active)
  1394. reset_alt_ioc_active = 1;
  1395. /* Disable alt-IOC's reply interrupts (and FreeQ) for a bit ... */
  1396. CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, 0xFFFFFFFF);
  1397. ioc->alt_ioc->active = 0;
  1398. }
  1399. hard = 1;
  1400. if (reason == MPT_HOSTEVENT_IOC_BRINGUP)
  1401. hard = 0;
  1402. if ((hard_reset_done = MakeIocReady(ioc, hard, sleepFlag)) < 0) {
  1403. if (hard_reset_done == -4) {
  1404. printk(KERN_WARNING MYNAM ": %s Owned by PEER..skipping!\n",
  1405. ioc->name);
  1406. if (reset_alt_ioc_active && ioc->alt_ioc) {
  1407. /* (re)Enable alt-IOC! (reply interrupt, FreeQ) */
  1408. dprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
  1409. ioc->alt_ioc->name));
  1410. CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, ~(MPI_HIM_RIM));
  1411. ioc->alt_ioc->active = 1;
  1412. }
  1413. } else {
  1414. printk(KERN_WARNING MYNAM ": %s NOT READY WARNING!\n",
  1415. ioc->name);
  1416. }
  1417. return -1;
  1418. }
  1419. /* hard_reset_done = 0 if a soft reset was performed
  1420. * and 1 if a hard reset was performed.
  1421. */
  1422. if (hard_reset_done && reset_alt_ioc_active && ioc->alt_ioc) {
  1423. if ((rc = MakeIocReady(ioc->alt_ioc, 0, sleepFlag)) == 0)
  1424. alt_ioc_ready = 1;
  1425. else
  1426. printk(KERN_WARNING MYNAM
  1427. ": alt-%s: Not ready WARNING!\n",
  1428. ioc->alt_ioc->name);
  1429. }
  1430. for (ii=0; ii<5; ii++) {
  1431. /* Get IOC facts! Allow 5 retries */
  1432. if ((rc = GetIocFacts(ioc, sleepFlag, reason)) == 0)
  1433. break;
  1434. }
  1435. if (ii == 5) {
  1436. dinitprintk((MYIOC_s_INFO_FMT "Retry IocFacts failed rc=%x\n", ioc->name, rc));
  1437. ret = -2;
  1438. } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  1439. MptDisplayIocCapabilities(ioc);
  1440. }
  1441. if (alt_ioc_ready) {
  1442. if ((rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason)) != 0) {
  1443. dinitprintk((MYIOC_s_INFO_FMT "Initial Alt IocFacts failed rc=%x\n", ioc->name, rc));
  1444. /* Retry - alt IOC was initialized once
  1445. */
  1446. rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason);
  1447. }
  1448. if (rc) {
  1449. dinitprintk((MYIOC_s_INFO_FMT "Retry Alt IocFacts failed rc=%x\n", ioc->name, rc));
  1450. alt_ioc_ready = 0;
  1451. reset_alt_ioc_active = 0;
  1452. } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  1453. MptDisplayIocCapabilities(ioc->alt_ioc);
  1454. }
  1455. }
  1456. /* Prime reply & request queues!
  1457. * (mucho alloc's) Must be done prior to
  1458. * init as upper addresses are needed for init.
  1459. * If fails, continue with alt-ioc processing
  1460. */
  1461. if ((ret == 0) && ((rc = PrimeIocFifos(ioc)) != 0))
  1462. ret = -3;
  1463. /* May need to check/upload firmware & data here!
  1464. * If fails, continue with alt-ioc processing
  1465. */
  1466. if ((ret == 0) && ((rc = SendIocInit(ioc, sleepFlag)) != 0))
  1467. ret = -4;
  1468. // NEW!
  1469. if (alt_ioc_ready && ((rc = PrimeIocFifos(ioc->alt_ioc)) != 0)) {
  1470. printk(KERN_WARNING MYNAM ": alt-%s: (%d) FIFO mgmt alloc WARNING!\n",
  1471. ioc->alt_ioc->name, rc);
  1472. alt_ioc_ready = 0;
  1473. reset_alt_ioc_active = 0;
  1474. }
  1475. if (alt_ioc_ready) {
  1476. if ((rc = SendIocInit(ioc->alt_ioc, sleepFlag)) != 0) {
  1477. alt_ioc_ready = 0;
  1478. reset_alt_ioc_active = 0;
  1479. printk(KERN_WARNING MYNAM
  1480. ": alt-%s: (%d) init failure WARNING!\n",
  1481. ioc->alt_ioc->name, rc);
  1482. }
  1483. }
  1484. if (reason == MPT_HOSTEVENT_IOC_BRINGUP){
  1485. if (ioc->upload_fw) {
  1486. ddlprintk((MYIOC_s_INFO_FMT
  1487. "firmware upload required!\n", ioc->name));
  1488. /* Controller is not operational, cannot do upload
  1489. */
  1490. if (ret == 0) {
  1491. rc = mpt_do_upload(ioc, sleepFlag);
  1492. if (rc != 0)
  1493. printk(KERN_WARNING MYNAM ": firmware upload failure!\n");
  1494. }
  1495. }
  1496. }
  1497. if (ret == 0) {
  1498. /* Enable! (reply interrupt) */
  1499. CHIPREG_WRITE32(&ioc->chip->IntMask, ~(MPI_HIM_RIM));
  1500. ioc->active = 1;
  1501. }
  1502. if (reset_alt_ioc_active && ioc->alt_ioc) {
  1503. /* (re)Enable alt-IOC! (reply interrupt) */
  1504. dprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
  1505. ioc->alt_ioc->name));
  1506. CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, ~(MPI_HIM_RIM));
  1507. ioc->alt_ioc->active = 1;
  1508. }
  1509. /* NEW! 20010120 -sralston
  1510. * Enable MPT base driver management of EventNotification
  1511. * and EventAck handling.
  1512. */
  1513. if ((ret == 0) && (!ioc->facts.EventState))
  1514. (void) SendEventNotification(ioc, 1); /* 1=Enable EventNotification */
  1515. if (ioc->alt_ioc && alt_ioc_ready && !ioc->alt_ioc->facts.EventState)
  1516. (void) SendEventNotification(ioc->alt_ioc, 1); /* 1=Enable EventNotification */
  1517. /* (Bugzilla:fibrebugs, #513)
  1518. * Bug fix (part 2)! 20010905 -sralston
  1519. * Add additional "reason" check before call to GetLanConfigPages
  1520. * (combined with GetIoUnitPage2 call). This prevents a somewhat
  1521. * recursive scenario; GetLanConfigPages times out, timer expired
  1522. * routine calls HardResetHandler, which calls into here again,
  1523. * and we try GetLanConfigPages again...
  1524. */
  1525. if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
  1526. if (ioc->bus_type == FC) {
  1527. /*
  1528. * Pre-fetch FC port WWN and stuff...
  1529. * (FCPortPage0_t stuff)
  1530. */
  1531. for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
  1532. (void) GetFcPortPage0(ioc, ii);
  1533. }
  1534. if ((ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) &&
  1535. (ioc->lan_cnfg_page0.Header.PageLength == 0)) {
  1536. /*
  1537. * Pre-fetch the ports LAN MAC address!
  1538. * (LANPage1_t stuff)
  1539. */
  1540. (void) GetLanConfigPages(ioc);
  1541. #ifdef MPT_DEBUG
  1542. {
  1543. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  1544. dprintk((MYIOC_s_INFO_FMT "LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
  1545. ioc->name, a[5], a[4], a[3], a[2], a[1], a[0] ));
  1546. }
  1547. #endif
  1548. }
  1549. } else {
  1550. /* Get NVRAM and adapter maximums from SPP 0 and 2
  1551. */
  1552. mpt_GetScsiPortSettings(ioc, 0);
  1553. /* Get version and length of SDP 1
  1554. */
  1555. mpt_readScsiDevicePageHeaders(ioc, 0);
  1556. /* Find IM volumes
  1557. */
  1558. if (ioc->facts.MsgVersion >= 0x0102)
  1559. mpt_findImVolumes(ioc);
  1560. /* Check, and possibly reset, the coalescing value
  1561. */
  1562. mpt_read_ioc_pg_1(ioc);
  1563. mpt_read_ioc_pg_4(ioc);
  1564. }
  1565. GetIoUnitPage2(ioc);
  1566. }
  1567. /*
  1568. * Call each currently registered protocol IOC reset handler
  1569. * with post-reset indication.
  1570. * NOTE: If we're doing _IOC_BRINGUP, there can be no
  1571. * MptResetHandlers[] registered yet.
  1572. */
  1573. if (hard_reset_done) {
  1574. rc = handlers = 0;
  1575. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  1576. if ((ret == 0) && MptResetHandlers[ii]) {
  1577. dprintk((MYIOC_s_INFO_FMT "Calling IOC post_reset handler #%d\n",
  1578. ioc->name, ii));
  1579. rc += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_POST_RESET);
  1580. handlers++;
  1581. }
  1582. if (alt_ioc_ready && MptResetHandlers[ii]) {
  1583. dprintk((MYIOC_s_INFO_FMT "Calling alt-%s post_reset handler #%d\n",
  1584. ioc->name, ioc->alt_ioc->name, ii));
  1585. rc += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_POST_RESET);
  1586. handlers++;
  1587. }
  1588. }
  1589. /* FIXME? Examine results here? */
  1590. }
  1591. return ret;
  1592. }
  1593. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1594. /*
  1595. * mpt_detect_bound_ports - Search for PCI bus/dev_function
  1596. * which matches PCI bus/dev_function (+/-1) for newly discovered 929,
  1597. * 929X, 1030 or 1035.
  1598. * @ioc: Pointer to MPT adapter structure
  1599. * @pdev: Pointer to (struct pci_dev) structure
  1600. *
  1601. * If match on PCI dev_function +/-1 is found, bind the two MPT adapters
  1602. * using alt_ioc pointer fields in their %MPT_ADAPTER structures.
  1603. */
  1604. static void
  1605. mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
  1606. {
  1607. unsigned int match_lo, match_hi;
  1608. MPT_ADAPTER *ioc_srch;
  1609. match_lo = pdev->devfn-1;
  1610. match_hi = pdev->devfn+1;
  1611. dprintk((MYIOC_s_INFO_FMT "PCI bus/devfn=%x/%x, searching for devfn match on %x or %x\n",
  1612. ioc->name, pdev->bus->number, pdev->devfn, match_lo, match_hi));
  1613. list_for_each_entry(ioc_srch, &ioc_list, list) {
  1614. struct pci_dev *_pcidev = ioc_srch->pcidev;
  1615. if ((_pcidev->device == pdev->device) &&
  1616. (_pcidev->bus->number == pdev->bus->number) &&
  1617. (_pcidev->devfn == match_lo || _pcidev->devfn == match_hi) ) {
  1618. /* Paranoia checks */
  1619. if (ioc->alt_ioc != NULL) {
  1620. printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
  1621. ioc->name, ioc->alt_ioc->name);
  1622. break;
  1623. } else if (ioc_srch->alt_ioc != NULL) {
  1624. printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
  1625. ioc_srch->name, ioc_srch->alt_ioc->name);
  1626. break;
  1627. }
  1628. dprintk((KERN_INFO MYNAM ": FOUND! binding %s <==> %s\n",
  1629. ioc->name, ioc_srch->name));
  1630. ioc_srch->alt_ioc = ioc;
  1631. ioc->alt_ioc = ioc_srch;
  1632. break;
  1633. }
  1634. }
  1635. }
  1636. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1637. /*
  1638. * mpt_adapter_disable - Disable misbehaving MPT adapter.
  1639. * @this: Pointer to MPT adapter structure
  1640. */
  1641. static void
  1642. mpt_adapter_disable(MPT_ADAPTER *ioc)
  1643. {
  1644. int sz;
  1645. int ret;
  1646. if (ioc->cached_fw != NULL) {
  1647. ddlprintk((KERN_INFO MYNAM ": mpt_adapter_disable: Pushing FW onto adapter\n"));
  1648. if ((ret = mpt_downloadboot(ioc, NO_SLEEP)) < 0) {
  1649. printk(KERN_WARNING MYNAM
  1650. ": firmware downloadboot failure (%d)!\n", ret);
  1651. }
  1652. }
  1653. /* Disable adapter interrupts! */
  1654. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1655. ioc->active = 0;
  1656. /* Clear any lingering interrupt */
  1657. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1658. if (ioc->alloc != NULL) {
  1659. sz = ioc->alloc_sz;
  1660. dexitprintk((KERN_INFO MYNAM ": %s.free @ %p, sz=%d bytes\n",
  1661. ioc->name, ioc->alloc, ioc->alloc_sz));
  1662. pci_free_consistent(ioc->pcidev, sz,
  1663. ioc->alloc, ioc->alloc_dma);
  1664. ioc->reply_frames = NULL;
  1665. ioc->req_frames = NULL;
  1666. ioc->alloc = NULL;
  1667. ioc->alloc_total -= sz;
  1668. }
  1669. if (ioc->sense_buf_pool != NULL) {
  1670. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  1671. pci_free_consistent(ioc->pcidev, sz,
  1672. ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
  1673. ioc->sense_buf_pool = NULL;
  1674. ioc->alloc_total -= sz;
  1675. }
  1676. if (ioc->events != NULL){
  1677. sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
  1678. kfree(ioc->events);
  1679. ioc->events = NULL;
  1680. ioc->alloc_total -= sz;
  1681. }
  1682. if (ioc->cached_fw != NULL) {
  1683. sz = ioc->facts.FWImageSize;
  1684. pci_free_consistent(ioc->pcidev, sz,
  1685. ioc->cached_fw, ioc->cached_fw_dma);
  1686. ioc->cached_fw = NULL;
  1687. ioc->alloc_total -= sz;
  1688. }
  1689. if (ioc->spi_data.nvram != NULL) {
  1690. kfree(ioc->spi_data.nvram);
  1691. ioc->spi_data.nvram = NULL;
  1692. }
  1693. if (ioc->spi_data.pIocPg3 != NULL) {
  1694. kfree(ioc->spi_data.pIocPg3);
  1695. ioc->spi_data.pIocPg3 = NULL;
  1696. }
  1697. if (ioc->spi_data.pIocPg4 != NULL) {
  1698. sz = ioc->spi_data.IocPg4Sz;
  1699. pci_free_consistent(ioc->pcidev, sz,
  1700. ioc->spi_data.pIocPg4,
  1701. ioc->spi_data.IocPg4_dma);
  1702. ioc->spi_data.pIocPg4 = NULL;
  1703. ioc->alloc_total -= sz;
  1704. }
  1705. if (ioc->ReqToChain != NULL) {
  1706. kfree(ioc->ReqToChain);
  1707. kfree(ioc->RequestNB);
  1708. ioc->ReqToChain = NULL;
  1709. }
  1710. if (ioc->ChainToChain != NULL) {
  1711. kfree(ioc->ChainToChain);
  1712. ioc->ChainToChain = NULL;
  1713. }
  1714. }
  1715. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1716. /*
  1717. * mpt_adapter_dispose - Free all resources associated with a MPT
  1718. * adapter.
  1719. * @ioc: Pointer to MPT adapter structure
  1720. *
  1721. * This routine unregisters h/w resources and frees all alloc'd memory
  1722. * associated with a MPT adapter structure.
  1723. */
  1724. static void
  1725. mpt_adapter_dispose(MPT_ADAPTER *ioc)
  1726. {
  1727. if (ioc != NULL) {
  1728. int sz_first, sz_last;
  1729. sz_first = ioc->alloc_total;
  1730. mpt_adapter_disable(ioc);
  1731. if (ioc->pci_irq != -1) {
  1732. free_irq(ioc->pci_irq, ioc);
  1733. ioc->pci_irq = -1;
  1734. }
  1735. if (ioc->memmap != NULL)
  1736. iounmap(ioc->memmap);
  1737. #if defined(CONFIG_MTRR) && 0
  1738. if (ioc->mtrr_reg > 0) {
  1739. mtrr_del(ioc->mtrr_reg, 0, 0);
  1740. dprintk((KERN_INFO MYNAM ": %s: MTRR region de-registered\n", ioc->name));
  1741. }
  1742. #endif
  1743. /* Zap the adapter lookup ptr! */
  1744. list_del(&ioc->list);
  1745. sz_last = ioc->alloc_total;
  1746. dprintk((KERN_INFO MYNAM ": %s: free'd %d of %d bytes\n",
  1747. ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
  1748. kfree(ioc);
  1749. }
  1750. }
  1751. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1752. /*
  1753. * MptDisplayIocCapabilities - Disply IOC's capacilities.
  1754. * @ioc: Pointer to MPT adapter structure
  1755. */
  1756. static void
  1757. MptDisplayIocCapabilities(MPT_ADAPTER *ioc)
  1758. {
  1759. int i = 0;
  1760. printk(KERN_INFO "%s: ", ioc->name);
  1761. if (ioc->prod_name && strlen(ioc->prod_name) > 3)
  1762. printk("%s: ", ioc->prod_name+3);
  1763. printk("Capabilities={");
  1764. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) {
  1765. printk("Initiator");
  1766. i++;
  1767. }
  1768. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
  1769. printk("%sTarget", i ? "," : "");
  1770. i++;
  1771. }
  1772. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
  1773. printk("%sLAN", i ? "," : "");
  1774. i++;
  1775. }
  1776. #if 0
  1777. /*
  1778. * This would probably evoke more questions than it's worth
  1779. */
  1780. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
  1781. printk("%sLogBusAddr", i ? "," : "");
  1782. i++;
  1783. }
  1784. #endif
  1785. printk("}\n");
  1786. }
  1787. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1788. /*
  1789. * MakeIocReady - Get IOC to a READY state, using KickStart if needed.
  1790. * @ioc: Pointer to MPT_ADAPTER structure
  1791. * @force: Force hard KickStart of IOC
  1792. * @sleepFlag: Specifies whether the process can sleep
  1793. *
  1794. * Returns:
  1795. * 1 - DIAG reset and READY
  1796. * 0 - READY initially OR soft reset and READY
  1797. * -1 - Any failure on KickStart
  1798. * -2 - Msg Unit Reset Failed
  1799. * -3 - IO Unit Reset Failed
  1800. * -4 - IOC owned by a PEER
  1801. */
  1802. static int
  1803. MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
  1804. {
  1805. u32 ioc_state;
  1806. int statefault = 0;
  1807. int cntdn;
  1808. int hard_reset_done = 0;
  1809. int r;
  1810. int ii;
  1811. int whoinit;
  1812. /* Get current [raw] IOC state */
  1813. ioc_state = mpt_GetIocState(ioc, 0);
  1814. dhsprintk((KERN_INFO MYNAM "::MakeIocReady, %s [raw] state=%08x\n", ioc->name, ioc_state));
  1815. /*
  1816. * Check to see if IOC got left/stuck in doorbell handshake
  1817. * grip of death. If so, hard reset the IOC.
  1818. */
  1819. if (ioc_state & MPI_DOORBELL_ACTIVE) {
  1820. statefault = 1;
  1821. printk(MYIOC_s_WARN_FMT "Unexpected doorbell active!\n",
  1822. ioc->name);
  1823. }
  1824. /* Is it already READY? */
  1825. if (!statefault && (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)
  1826. return 0;
  1827. /*
  1828. * Check to see if IOC is in FAULT state.
  1829. */
  1830. if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
  1831. statefault = 2;
  1832. printk(MYIOC_s_WARN_FMT "IOC is in FAULT state!!!\n",
  1833. ioc->name);
  1834. printk(KERN_WARNING " FAULT code = %04xh\n",
  1835. ioc_state & MPI_DOORBELL_DATA_MASK);
  1836. }
  1837. /*
  1838. * Hmmm... Did it get left operational?
  1839. */
  1840. if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) {
  1841. dinitprintk((MYIOC_s_WARN_FMT "IOC operational unexpected\n",
  1842. ioc->name));
  1843. /* Check WhoInit.
  1844. * If PCI Peer, exit.
  1845. * Else, if no fault conditions are present, issue a MessageUnitReset
  1846. * Else, fall through to KickStart case
  1847. */
  1848. whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT;
  1849. dprintk((KERN_WARNING MYNAM
  1850. ": whoinit 0x%x\n statefault %d force %d\n",
  1851. whoinit, statefault, force));
  1852. if (whoinit == MPI_WHOINIT_PCI_PEER)
  1853. return -4;
  1854. else {
  1855. if ((statefault == 0 ) && (force == 0)) {
  1856. if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) == 0)
  1857. return 0;
  1858. }
  1859. statefault = 3;
  1860. }
  1861. }
  1862. hard_reset_done = KickStart(ioc, statefault||force, sleepFlag);
  1863. if (hard_reset_done < 0)
  1864. return -1;
  1865. /*
  1866. * Loop here waiting for IOC to come READY.
  1867. */
  1868. ii = 0;
  1869. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
  1870. while ((ioc_state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
  1871. if (ioc_state == MPI_IOC_STATE_OPERATIONAL) {
  1872. /*
  1873. * BIOS or previous driver load left IOC in OP state.
  1874. * Reset messaging FIFOs.
  1875. */
  1876. if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) != 0) {
  1877. printk(MYIOC_s_ERR_FMT "IOC msg unit reset failed!\n", ioc->name);
  1878. return -2;
  1879. }
  1880. } else if (ioc_state == MPI_IOC_STATE_RESET) {
  1881. /*
  1882. * Something is wrong. Try to get IOC back
  1883. * to a known state.
  1884. */
  1885. if ((r = SendIocReset(ioc, MPI_FUNCTION_IO_UNIT_RESET, sleepFlag)) != 0) {
  1886. printk(MYIOC_s_ERR_FMT "IO unit reset failed!\n", ioc->name);
  1887. return -3;
  1888. }
  1889. }
  1890. ii++; cntdn--;
  1891. if (!cntdn) {
  1892. printk(MYIOC_s_ERR_FMT "Wait IOC_READY state timeout(%d)!\n",
  1893. ioc->name, (int)((ii+5)/HZ));
  1894. return -ETIME;
  1895. }
  1896. if (sleepFlag == CAN_SLEEP) {
  1897. msleep_interruptible(1);
  1898. } else {
  1899. mdelay (1); /* 1 msec delay */
  1900. }
  1901. }
  1902. if (statefault < 3) {
  1903. printk(MYIOC_s_INFO_FMT "Recovered from %s\n",
  1904. ioc->name,
  1905. statefault==1 ? "stuck handshake" : "IOC FAULT");
  1906. }
  1907. return hard_reset_done;
  1908. }
  1909. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1910. /*
  1911. * mpt_GetIocState - Get the current state of a MPT adapter.
  1912. * @ioc: Pointer to MPT_ADAPTER structure
  1913. * @cooked: Request raw or cooked IOC state
  1914. *
  1915. * Returns all IOC Doorbell register bits if cooked==0, else just the
  1916. * Doorbell bits in MPI_IOC_STATE_MASK.
  1917. */
  1918. u32
  1919. mpt_GetIocState(MPT_ADAPTER *ioc, int cooked)
  1920. {
  1921. u32 s, sc;
  1922. /* Get! */
  1923. s = CHIPREG_READ32(&ioc->chip->Doorbell);
  1924. // dprintk((MYIOC_s_INFO_FMT "raw state = %08x\n", ioc->name, s));
  1925. sc = s & MPI_IOC_STATE_MASK;
  1926. /* Save! */
  1927. ioc->last_state = sc;
  1928. return cooked ? sc : s;
  1929. }
  1930. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1931. /*
  1932. * GetIocFacts - Send IOCFacts request to MPT adapter.
  1933. * @ioc: Pointer to MPT_ADAPTER structure
  1934. * @sleepFlag: Specifies whether the process can sleep
  1935. * @reason: If recovery, only update facts.
  1936. *
  1937. * Returns 0 for success, non-zero for failure.
  1938. */
  1939. static int
  1940. GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
  1941. {
  1942. IOCFacts_t get_facts;
  1943. IOCFactsReply_t *facts;
  1944. int r;
  1945. int req_sz;
  1946. int reply_sz;
  1947. int sz;
  1948. u32 status, vv;
  1949. u8 shiftFactor=1;
  1950. /* IOC *must* NOT be in RESET state! */
  1951. if (ioc->last_state == MPI_IOC_STATE_RESET) {
  1952. printk(KERN_ERR MYNAM ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
  1953. ioc->name,
  1954. ioc->last_state );
  1955. return -44;
  1956. }
  1957. facts = &ioc->facts;
  1958. /* Destination (reply area)... */
  1959. reply_sz = sizeof(*facts);
  1960. memset(facts, 0, reply_sz);
  1961. /* Request area (get_facts on the stack right now!) */
  1962. req_sz = sizeof(get_facts);
  1963. memset(&get_facts, 0, req_sz);
  1964. get_facts.Function = MPI_FUNCTION_IOC_FACTS;
  1965. /* Assert: All other get_facts fields are zero! */
  1966. dinitprintk((MYIOC_s_INFO_FMT
  1967. "Sending get IocFacts request req_sz=%d reply_sz=%d\n",
  1968. ioc->name, req_sz, reply_sz));
  1969. /* No non-zero fields in the get_facts request are greater than
  1970. * 1 byte in size, so we can just fire it off as is.
  1971. */
  1972. r = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_facts,
  1973. reply_sz, (u16*)facts, 5 /*seconds*/, sleepFlag);
  1974. if (r != 0)
  1975. return r;
  1976. /*
  1977. * Now byte swap (GRRR) the necessary fields before any further
  1978. * inspection of reply contents.
  1979. *
  1980. * But need to do some sanity checks on MsgLength (byte) field
  1981. * to make sure we don't zero IOC's req_sz!
  1982. */
  1983. /* Did we get a valid reply? */
  1984. if (facts->MsgLength > offsetof(IOCFactsReply_t, RequestFrameSize)/sizeof(u32)) {
  1985. if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  1986. /*
  1987. * If not been here, done that, save off first WhoInit value
  1988. */
  1989. if (ioc->FirstWhoInit == WHOINIT_UNKNOWN)
  1990. ioc->FirstWhoInit = facts->WhoInit;
  1991. }
  1992. facts->MsgVersion = le16_to_cpu(facts->MsgVersion);
  1993. facts->MsgContext = le32_to_cpu(facts->MsgContext);
  1994. facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions);
  1995. facts->IOCStatus = le16_to_cpu(facts->IOCStatus);
  1996. facts->IOCLogInfo = le32_to_cpu(facts->IOCLogInfo);
  1997. status = facts->IOCStatus & MPI_IOCSTATUS_MASK;
  1998. /* CHECKME! IOCStatus, IOCLogInfo */
  1999. facts->ReplyQueueDepth = le16_to_cpu(facts->ReplyQueueDepth);
  2000. facts->RequestFrameSize = le16_to_cpu(facts->RequestFrameSize);
  2001. /*
  2002. * FC f/w version changed between 1.1 and 1.2
  2003. * Old: u16{Major(4),Minor(4),SubMinor(8)}
  2004. * New: u32{Major(8),Minor(8),Unit(8),Dev(8)}
  2005. */
  2006. if (facts->MsgVersion < 0x0102) {
  2007. /*
  2008. * Handle old FC f/w style, convert to new...
  2009. */
  2010. u16 oldv = le16_to_cpu(facts->Reserved_0101_FWVersion);
  2011. facts->FWVersion.Word =
  2012. ((oldv<<12) & 0xFF000000) |
  2013. ((oldv<<8) & 0x000FFF00);
  2014. } else
  2015. facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word);
  2016. facts->ProductID = le16_to_cpu(facts->ProductID);
  2017. facts->CurrentHostMfaHighAddr =
  2018. le32_to_cpu(facts->CurrentHostMfaHighAddr);
  2019. facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits);
  2020. facts->CurrentSenseBufferHighAddr =
  2021. le32_to_cpu(facts->CurrentSenseBufferHighAddr);
  2022. facts->CurReplyFrameSize =
  2023. le16_to_cpu(facts->CurReplyFrameSize);
  2024. /*
  2025. * Handle NEW (!) IOCFactsReply fields in MPI-1.01.xx
  2026. * Older MPI-1.00.xx struct had 13 dwords, and enlarged
  2027. * to 14 in MPI-1.01.0x.
  2028. */
  2029. if (facts->MsgLength >= (offsetof(IOCFactsReply_t,FWImageSize) + 7)/4 &&
  2030. facts->MsgVersion > 0x0100) {
  2031. facts->FWImageSize = le32_to_cpu(facts->FWImageSize);
  2032. }
  2033. sz = facts->FWImageSize;
  2034. if ( sz & 0x01 )
  2035. sz += 1;
  2036. if ( sz & 0x02 )
  2037. sz += 2;
  2038. facts->FWImageSize = sz;
  2039. if (!facts->RequestFrameSize) {
  2040. /* Something is wrong! */
  2041. printk(MYIOC_s_ERR_FMT "IOC reported invalid 0 request size!\n",
  2042. ioc->name);
  2043. return -55;
  2044. }
  2045. r = sz = le32_to_cpu(facts->BlockSize);
  2046. vv = ((63 / (sz * 4)) + 1) & 0x03;
  2047. ioc->NB_for_64_byte_frame = vv;
  2048. while ( sz )
  2049. {
  2050. shiftFactor++;
  2051. sz = sz >> 1;
  2052. }
  2053. ioc->NBShiftFactor = shiftFactor;
  2054. dinitprintk((MYIOC_s_INFO_FMT "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
  2055. ioc->name, vv, shiftFactor, r));
  2056. if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  2057. /*
  2058. * Set values for this IOC's request & reply frame sizes,
  2059. * and request & reply queue depths...
  2060. */
  2061. ioc->req_sz = min(MPT_DEFAULT_FRAME_SIZE, facts->RequestFrameSize * 4);
  2062. ioc->req_depth = min_t(int, MPT_MAX_REQ_DEPTH, facts->GlobalCredits);
  2063. ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
  2064. ioc->reply_depth = min_t(int, MPT_DEFAULT_REPLY_DEPTH, facts->ReplyQueueDepth);
  2065. dinitprintk((MYIOC_s_INFO_FMT "reply_sz=%3d, reply_depth=%4d\n",
  2066. ioc->name, ioc->reply_sz, ioc->reply_depth));
  2067. dinitprintk((MYIOC_s_INFO_FMT "req_sz =%3d, req_depth =%4d\n",
  2068. ioc->name, ioc->req_sz, ioc->req_depth));
  2069. /* Get port facts! */
  2070. if ( (r = GetPortFacts(ioc, 0, sleepFlag)) != 0 )
  2071. return r;
  2072. }
  2073. } else {
  2074. printk(MYIOC_s_ERR_FMT
  2075. "Invalid IOC facts reply, msgLength=%d offsetof=%zd!\n",
  2076. ioc->name, facts->MsgLength, (offsetof(IOCFactsReply_t,
  2077. RequestFrameSize)/sizeof(u32)));
  2078. return -66;
  2079. }
  2080. return 0;
  2081. }
  2082. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2083. /*
  2084. * GetPortFacts - Send PortFacts request to MPT adapter.
  2085. * @ioc: Pointer to MPT_ADAPTER structure
  2086. * @portnum: Port number
  2087. * @sleepFlag: Specifies whether the process can sleep
  2088. *
  2089. * Returns 0 for success, non-zero for failure.
  2090. */
  2091. static int
  2092. GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
  2093. {
  2094. PortFacts_t get_pfacts;
  2095. PortFactsReply_t *pfacts;
  2096. int ii;
  2097. int req_sz;
  2098. int reply_sz;
  2099. /* IOC *must* NOT be in RESET state! */
  2100. if (ioc->last_state == MPI_IOC_STATE_RESET) {
  2101. printk(KERN_ERR MYNAM ": ERROR - Can't get PortFacts, %s NOT READY! (%08x)\n",
  2102. ioc->name,
  2103. ioc->last_state );
  2104. return -4;
  2105. }
  2106. pfacts = &ioc->pfacts[portnum];
  2107. /* Destination (reply area)... */
  2108. reply_sz = sizeof(*pfacts);
  2109. memset(pfacts, 0, reply_sz);
  2110. /* Request area (get_pfacts on the stack right now!) */
  2111. req_sz = sizeof(get_pfacts);
  2112. memset(&get_pfacts, 0, req_sz);
  2113. get_pfacts.Function = MPI_FUNCTION_PORT_FACTS;
  2114. get_pfacts.PortNumber = portnum;
  2115. /* Assert: All other get_pfacts fields are zero! */
  2116. dinitprintk((MYIOC_s_INFO_FMT "Sending get PortFacts(%d) request\n",
  2117. ioc->name, portnum));
  2118. /* No non-zero fields in the get_pfacts request are greater than
  2119. * 1 byte in size, so we can just fire it off as is.
  2120. */
  2121. ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_pfacts,
  2122. reply_sz, (u16*)pfacts, 5 /*seconds*/, sleepFlag);
  2123. if (ii != 0)
  2124. return ii;
  2125. /* Did we get a valid reply? */
  2126. /* Now byte swap the necessary fields in the response. */
  2127. pfacts->MsgContext = le32_to_cpu(pfacts->MsgContext);
  2128. pfacts->IOCStatus = le16_to_cpu(pfacts->IOCStatus);
  2129. pfacts->IOCLogInfo = le32_to_cpu(pfacts->IOCLogInfo);
  2130. pfacts->MaxDevices = le16_to_cpu(pfacts->MaxDevices);
  2131. pfacts->PortSCSIID = le16_to_cpu(pfacts->PortSCSIID);
  2132. pfacts->ProtocolFlags = le16_to_cpu(pfacts->ProtocolFlags);
  2133. pfacts->MaxPostedCmdBuffers = le16_to_cpu(pfacts->MaxPostedCmdBuffers);
  2134. pfacts->MaxPersistentIDs = le16_to_cpu(pfacts->MaxPersistentIDs);
  2135. pfacts->MaxLanBuckets = le16_to_cpu(pfacts->MaxLanBuckets);
  2136. return 0;
  2137. }
  2138. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2139. /*
  2140. * SendIocInit - Send IOCInit request to MPT adapter.
  2141. * @ioc: Pointer to MPT_ADAPTER structure
  2142. * @sleepFlag: Specifies whether the process can sleep
  2143. *
  2144. * Send IOCInit followed by PortEnable to bring IOC to OPERATIONAL state.
  2145. *
  2146. * Returns 0 for success, non-zero for failure.
  2147. */
  2148. static int
  2149. SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
  2150. {
  2151. IOCInit_t ioc_init;
  2152. MPIDefaultReply_t init_reply;
  2153. u32 state;
  2154. int r;
  2155. int count;
  2156. int cntdn;
  2157. memset(&ioc_init, 0, sizeof(ioc_init));
  2158. memset(&init_reply, 0, sizeof(init_reply));
  2159. ioc_init.WhoInit = MPI_WHOINIT_HOST_DRIVER;
  2160. ioc_init.Function = MPI_FUNCTION_IOC_INIT;
  2161. /* If we are in a recovery mode and we uploaded the FW image,
  2162. * then this pointer is not NULL. Skip the upload a second time.
  2163. * Set this flag if cached_fw set for either IOC.
  2164. */
  2165. if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
  2166. ioc->upload_fw = 1;
  2167. else
  2168. ioc->upload_fw = 0;
  2169. ddlprintk((MYIOC_s_INFO_FMT "upload_fw %d facts.Flags=%x\n",
  2170. ioc->name, ioc->upload_fw, ioc->facts.Flags));
  2171. if (ioc->bus_type == FC)
  2172. ioc_init.MaxDevices = MPT_MAX_FC_DEVICES;
  2173. else
  2174. ioc_init.MaxDevices = MPT_MAX_SCSI_DEVICES;
  2175. ioc_init.MaxBuses = MPT_MAX_BUS;
  2176. ioc_init.ReplyFrameSize = cpu_to_le16(ioc->reply_sz); /* in BYTES */
  2177. if (sizeof(dma_addr_t) == sizeof(u64)) {
  2178. /* Save the upper 32-bits of the request
  2179. * (reply) and sense buffers.
  2180. */
  2181. ioc_init.HostMfaHighAddr = cpu_to_le32((u32)((u64)ioc->alloc_dma >> 32));
  2182. ioc_init.SenseBufferHighAddr = cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
  2183. } else {
  2184. /* Force 32-bit addressing */
  2185. ioc_init.HostMfaHighAddr = cpu_to_le32(0);
  2186. ioc_init.SenseBufferHighAddr = cpu_to_le32(0);
  2187. }
  2188. ioc->facts.CurrentHostMfaHighAddr = ioc_init.HostMfaHighAddr;
  2189. ioc->facts.CurrentSenseBufferHighAddr = ioc_init.SenseBufferHighAddr;
  2190. dhsprintk((MYIOC_s_INFO_FMT "Sending IOCInit (req @ %p)\n",
  2191. ioc->name, &ioc_init));
  2192. r = mpt_handshake_req_reply_wait(ioc, sizeof(IOCInit_t), (u32*)&ioc_init,
  2193. sizeof(MPIDefaultReply_t), (u16*)&init_reply, 10 /*seconds*/, sleepFlag);
  2194. if (r != 0)
  2195. return r;
  2196. /* No need to byte swap the multibyte fields in the reply
  2197. * since we don't even look at it's contents.
  2198. */
  2199. dhsprintk((MYIOC_s_INFO_FMT "Sending PortEnable (req @ %p)\n",
  2200. ioc->name, &ioc_init));
  2201. if ((r = SendPortEnable(ioc, 0, sleepFlag)) != 0)
  2202. return r;
  2203. /* YIKES! SUPER IMPORTANT!!!
  2204. * Poll IocState until _OPERATIONAL while IOC is doing
  2205. * LoopInit and TargetDiscovery!
  2206. */
  2207. count = 0;
  2208. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 60; /* 60 seconds */
  2209. state = mpt_GetIocState(ioc, 1);
  2210. while (state != MPI_IOC_STATE_OPERATIONAL && --cntdn) {
  2211. if (sleepFlag == CAN_SLEEP) {
  2212. msleep_interruptible(1);
  2213. } else {
  2214. mdelay(1);
  2215. }
  2216. if (!cntdn) {
  2217. printk(MYIOC_s_ERR_FMT "Wait IOC_OP state timeout(%d)!\n",
  2218. ioc->name, (int)((count+5)/HZ));
  2219. return -9;
  2220. }
  2221. state = mpt_GetIocState(ioc, 1);
  2222. count++;
  2223. }
  2224. dhsprintk((MYIOC_s_INFO_FMT "INFO - Wait IOC_OPERATIONAL state (cnt=%d)\n",
  2225. ioc->name, count));
  2226. return r;
  2227. }
  2228. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2229. /*
  2230. * SendPortEnable - Send PortEnable request to MPT adapter port.
  2231. * @ioc: Pointer to MPT_ADAPTER structure
  2232. * @portnum: Port number to enable
  2233. * @sleepFlag: Specifies whether the process can sleep
  2234. *
  2235. * Send PortEnable to bring IOC to OPERATIONAL state.
  2236. *
  2237. * Returns 0 for success, non-zero for failure.
  2238. */
  2239. static int
  2240. SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
  2241. {
  2242. PortEnable_t port_enable;
  2243. MPIDefaultReply_t reply_buf;
  2244. int ii;
  2245. int req_sz;
  2246. int reply_sz;
  2247. /* Destination... */
  2248. reply_sz = sizeof(MPIDefaultReply_t);
  2249. memset(&reply_buf, 0, reply_sz);
  2250. req_sz = sizeof(PortEnable_t);
  2251. memset(&port_enable, 0, req_sz);
  2252. port_enable.Function = MPI_FUNCTION_PORT_ENABLE;
  2253. port_enable.PortNumber = portnum;
  2254. /* port_enable.ChainOffset = 0; */
  2255. /* port_enable.MsgFlags = 0; */
  2256. /* port_enable.MsgContext = 0; */
  2257. dinitprintk((MYIOC_s_INFO_FMT "Sending Port(%d)Enable (req @ %p)\n",
  2258. ioc->name, portnum, &port_enable));
  2259. /* RAID FW may take a long time to enable
  2260. */
  2261. if (ioc->bus_type == FC) {
  2262. ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&port_enable,
  2263. reply_sz, (u16*)&reply_buf, 65 /*seconds*/, sleepFlag);
  2264. } else {
  2265. ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&port_enable,
  2266. reply_sz, (u16*)&reply_buf, 300 /*seconds*/, sleepFlag);
  2267. }
  2268. if (ii != 0)
  2269. return ii;
  2270. /* We do not even look at the reply, so we need not
  2271. * swap the multi-byte fields.
  2272. */
  2273. return 0;
  2274. }
  2275. /*
  2276. * ioc: Pointer to MPT_ADAPTER structure
  2277. * size - total FW bytes
  2278. */
  2279. void
  2280. mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size)
  2281. {
  2282. if (ioc->cached_fw)
  2283. return; /* use already allocated memory */
  2284. if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
  2285. ioc->cached_fw = ioc->alt_ioc->cached_fw; /* use alt_ioc's memory */
  2286. ioc->cached_fw_dma = ioc->alt_ioc->cached_fw_dma;
  2287. } else {
  2288. if ( (ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma) ) )
  2289. ioc->alloc_total += size;
  2290. }
  2291. }
  2292. /*
  2293. * If alt_img is NULL, delete from ioc structure.
  2294. * Else, delete a secondary image in same format.
  2295. */
  2296. void
  2297. mpt_free_fw_memory(MPT_ADAPTER *ioc)
  2298. {
  2299. int sz;
  2300. sz = ioc->facts.FWImageSize;
  2301. dinitprintk((KERN_WARNING MYNAM "free_fw_memory: FW Image @ %p[%p], sz=%d[%x] bytes\n",
  2302. ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
  2303. pci_free_consistent(ioc->pcidev, sz,
  2304. ioc->cached_fw, ioc->cached_fw_dma);
  2305. ioc->cached_fw = NULL;
  2306. return;
  2307. }
  2308. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2309. /*
  2310. * mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
  2311. * @ioc: Pointer to MPT_ADAPTER structure
  2312. * @sleepFlag: Specifies whether the process can sleep
  2313. *
  2314. * Returns 0 for success, >0 for handshake failure
  2315. * <0 for fw upload failure.
  2316. *
  2317. * Remark: If bound IOC and a successful FWUpload was performed
  2318. * on the bound IOC, the second image is discarded
  2319. * and memory is free'd. Both channels must upload to prevent
  2320. * IOC from running in degraded mode.
  2321. */
  2322. static int
  2323. mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
  2324. {
  2325. u8 request[ioc->req_sz];
  2326. u8 reply[sizeof(FWUploadReply_t)];
  2327. FWUpload_t *prequest;
  2328. FWUploadReply_t *preply;
  2329. FWUploadTCSGE_t *ptcsge;
  2330. int sgeoffset;
  2331. u32 flagsLength;
  2332. int ii, sz, reply_sz;
  2333. int cmdStatus;
  2334. /* If the image size is 0, we are done.
  2335. */
  2336. if ((sz = ioc->facts.FWImageSize) == 0)
  2337. return 0;
  2338. mpt_alloc_fw_memory(ioc, sz);
  2339. dinitprintk((KERN_WARNING MYNAM ": FW Image @ %p[%p], sz=%d[%x] bytes\n",
  2340. ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
  2341. if (ioc->cached_fw == NULL) {
  2342. /* Major Failure.
  2343. */
  2344. return -ENOMEM;
  2345. }
  2346. prequest = (FWUpload_t *)&request;
  2347. preply = (FWUploadReply_t *)&reply;
  2348. /* Destination... */
  2349. memset(prequest, 0, ioc->req_sz);
  2350. reply_sz = sizeof(reply);
  2351. memset(preply, 0, reply_sz);
  2352. prequest->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM;
  2353. prequest->Function = MPI_FUNCTION_FW_UPLOAD;
  2354. ptcsge = (FWUploadTCSGE_t *) &prequest->SGL;
  2355. ptcsge->DetailsLength = 12;
  2356. ptcsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
  2357. ptcsge->ImageSize = cpu_to_le32(sz);
  2358. sgeoffset = sizeof(FWUpload_t) - sizeof(SGE_MPI_UNION) + sizeof(FWUploadTCSGE_t);
  2359. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | sz;
  2360. mpt_add_sge(&request[sgeoffset], flagsLength, ioc->cached_fw_dma);
  2361. sgeoffset += sizeof(u32) + sizeof(dma_addr_t);
  2362. dinitprintk((KERN_WARNING MYNAM "Sending FW Upload (req @ %p) sgeoffset=%d \n",
  2363. prequest, sgeoffset));
  2364. DBG_DUMP_FW_REQUEST_FRAME(prequest)
  2365. ii = mpt_handshake_req_reply_wait(ioc, sgeoffset, (u32*)prequest,
  2366. reply_sz, (u16*)preply, 65 /*seconds*/, sleepFlag);
  2367. dinitprintk((KERN_WARNING MYNAM "FW Upload completed rc=%x \n", ii));
  2368. cmdStatus = -EFAULT;
  2369. if (ii == 0) {
  2370. /* Handshake transfer was complete and successful.
  2371. * Check the Reply Frame.
  2372. */
  2373. int status, transfer_sz;
  2374. status = le16_to_cpu(preply->IOCStatus);
  2375. if (status == MPI_IOCSTATUS_SUCCESS) {
  2376. transfer_sz = le32_to_cpu(preply->ActualImageSize);
  2377. if (transfer_sz == sz)
  2378. cmdStatus = 0;
  2379. }
  2380. }
  2381. dinitprintk((MYIOC_s_INFO_FMT ": do_upload status %d \n",
  2382. ioc->name, cmdStatus));
  2383. if (cmdStatus) {
  2384. ddlprintk((MYIOC_s_INFO_FMT ": fw upload failed, freeing image \n",
  2385. ioc->name));
  2386. mpt_free_fw_memory(ioc);
  2387. }
  2388. return cmdStatus;
  2389. }
  2390. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2391. /*
  2392. * mpt_downloadboot - DownloadBoot code
  2393. * @ioc: Pointer to MPT_ADAPTER structure
  2394. * @flag: Specify which part of IOC memory is to be uploaded.
  2395. * @sleepFlag: Specifies whether the process can sleep
  2396. *
  2397. * FwDownloadBoot requires Programmed IO access.
  2398. *
  2399. * Returns 0 for success
  2400. * -1 FW Image size is 0
  2401. * -2 No valid cached_fw Pointer
  2402. * <0 for fw upload failure.
  2403. */
  2404. static int
  2405. mpt_downloadboot(MPT_ADAPTER *ioc, int sleepFlag)
  2406. {
  2407. MpiFwHeader_t *pFwHeader;
  2408. MpiExtImageHeader_t *pExtImage;
  2409. u32 fwSize;
  2410. u32 diag0val;
  2411. int count;
  2412. u32 *ptrFw;
  2413. u32 diagRwData;
  2414. u32 nextImage;
  2415. u32 load_addr;
  2416. u32 ioc_state=0;
  2417. ddlprintk((MYIOC_s_INFO_FMT "downloadboot: fw size 0x%x, ioc FW Ptr %p\n",
  2418. ioc->name, ioc->facts.FWImageSize, ioc->cached_fw));
  2419. if ( ioc->facts.FWImageSize == 0 )
  2420. return -1;
  2421. if (ioc->cached_fw == NULL)
  2422. return -2;
  2423. /* prevent a second downloadboot and memory free with alt_ioc */
  2424. if (ioc->alt_ioc && ioc->alt_ioc->cached_fw)
  2425. ioc->alt_ioc->cached_fw = NULL;
  2426. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2427. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  2428. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  2429. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  2430. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  2431. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  2432. CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM));
  2433. /* wait 1 msec */
  2434. if (sleepFlag == CAN_SLEEP) {
  2435. msleep_interruptible(1);
  2436. } else {
  2437. mdelay (1);
  2438. }
  2439. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2440. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
  2441. for (count = 0; count < 30; count ++) {
  2442. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2443. if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
  2444. ddlprintk((MYIOC_s_INFO_FMT "RESET_ADAPTER cleared, count=%d\n",
  2445. ioc->name, count));
  2446. break;
  2447. }
  2448. /* wait 1 sec */
  2449. if (sleepFlag == CAN_SLEEP) {
  2450. msleep_interruptible (1000);
  2451. } else {
  2452. mdelay (1000);
  2453. }
  2454. }
  2455. if ( count == 30 ) {
  2456. ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! Unable to RESET_ADAPTER diag0val=%x\n",
  2457. ioc->name, diag0val));
  2458. return -3;
  2459. }
  2460. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2461. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  2462. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  2463. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  2464. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  2465. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  2466. /* Set the DiagRwEn and Disable ARM bits */
  2467. CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_RW_ENABLE | MPI_DIAG_DISABLE_ARM));
  2468. pFwHeader = (MpiFwHeader_t *) ioc->cached_fw;
  2469. fwSize = (pFwHeader->ImageSize + 3)/4;
  2470. ptrFw = (u32 *) pFwHeader;
  2471. /* Write the LoadStartAddress to the DiagRw Address Register
  2472. * using Programmed IO
  2473. */
  2474. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->LoadStartAddress);
  2475. ddlprintk((MYIOC_s_INFO_FMT "LoadStart addr written 0x%x \n",
  2476. ioc->name, pFwHeader->LoadStartAddress));
  2477. ddlprintk((MYIOC_s_INFO_FMT "Write FW Image: 0x%x bytes @ %p\n",
  2478. ioc->name, fwSize*4, ptrFw));
  2479. while (fwSize--) {
  2480. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
  2481. }
  2482. nextImage = pFwHeader->NextImageHeaderOffset;
  2483. while (nextImage) {
  2484. pExtImage = (MpiExtImageHeader_t *) ((char *)pFwHeader + nextImage);
  2485. load_addr = pExtImage->LoadStartAddress;
  2486. fwSize = (pExtImage->ImageSize + 3) >> 2;
  2487. ptrFw = (u32 *)pExtImage;
  2488. ddlprintk((MYIOC_s_INFO_FMT "Write Ext Image: 0x%x bytes @ %p load_addr=%x\n",
  2489. ioc->name, fwSize*4, ptrFw, load_addr));
  2490. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, load_addr);
  2491. while (fwSize--) {
  2492. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
  2493. }
  2494. nextImage = pExtImage->NextImageHeaderOffset;
  2495. }
  2496. /* Write the IopResetVectorRegAddr */
  2497. ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Addr=%x! \n", ioc->name, pFwHeader->IopResetRegAddr));
  2498. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->IopResetRegAddr);
  2499. /* Write the IopResetVectorValue */
  2500. ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Value=%x! \n", ioc->name, pFwHeader->IopResetVectorValue));
  2501. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, pFwHeader->IopResetVectorValue);
  2502. /* Clear the internal flash bad bit - autoincrementing register,
  2503. * so must do two writes.
  2504. */
  2505. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
  2506. diagRwData = CHIPREG_PIO_READ32(&ioc->pio_chip->DiagRwData);
  2507. diagRwData |= 0x4000000;
  2508. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
  2509. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, diagRwData);
  2510. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2511. ddlprintk((MYIOC_s_INFO_FMT "downloadboot diag0val=%x, turning off PREVENT_IOC_BOOT, DISABLE_ARM\n",
  2512. ioc->name, diag0val));
  2513. diag0val &= ~(MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM);
  2514. ddlprintk((MYIOC_s_INFO_FMT "downloadboot now diag0val=%x\n",
  2515. ioc->name, diag0val));
  2516. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
  2517. /* Write 0xFF to reset the sequencer */
  2518. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2519. for (count=0; count<HZ*20; count++) {
  2520. if ((ioc_state = mpt_GetIocState(ioc, 0)) & MPI_IOC_STATE_READY) {
  2521. ddlprintk((MYIOC_s_INFO_FMT "downloadboot successful! (count=%d) IocState=%x\n",
  2522. ioc->name, count, ioc_state));
  2523. if ((SendIocInit(ioc, sleepFlag)) != 0) {
  2524. ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit failed\n",
  2525. ioc->name));
  2526. return -EFAULT;
  2527. }
  2528. ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit successful\n",
  2529. ioc->name));
  2530. return 0;
  2531. }
  2532. if (sleepFlag == CAN_SLEEP) {
  2533. msleep_interruptible (10);
  2534. } else {
  2535. mdelay (10);
  2536. }
  2537. }
  2538. ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! IocState=%x\n",
  2539. ioc->name, ioc_state));
  2540. return -EFAULT;
  2541. }
  2542. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2543. /*
  2544. * KickStart - Perform hard reset of MPT adapter.
  2545. * @ioc: Pointer to MPT_ADAPTER structure
  2546. * @force: Force hard reset
  2547. * @sleepFlag: Specifies whether the process can sleep
  2548. *
  2549. * This routine places MPT adapter in diagnostic mode via the
  2550. * WriteSequence register, and then performs a hard reset of adapter
  2551. * via the Diagnostic register.
  2552. *
  2553. * Inputs: sleepflag - CAN_SLEEP (non-interrupt thread)
  2554. * or NO_SLEEP (interrupt thread, use mdelay)
  2555. * force - 1 if doorbell active, board fault state
  2556. * board operational, IOC_RECOVERY or
  2557. * IOC_BRINGUP and there is an alt_ioc.
  2558. * 0 else
  2559. *
  2560. * Returns:
  2561. * 1 - hard reset, READY
  2562. * 0 - no reset due to History bit, READY
  2563. * -1 - no reset due to History bit but not READY
  2564. * OR reset but failed to come READY
  2565. * -2 - no reset, could not enter DIAG mode
  2566. * -3 - reset but bad FW bit
  2567. */
  2568. static int
  2569. KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
  2570. {
  2571. int hard_reset_done = 0;
  2572. u32 ioc_state=0;
  2573. int cnt,cntdn;
  2574. dinitprintk((KERN_WARNING MYNAM ": KickStarting %s!\n", ioc->name));
  2575. if (ioc->bus_type == SCSI) {
  2576. /* Always issue a Msg Unit Reset first. This will clear some
  2577. * SCSI bus hang conditions.
  2578. */
  2579. SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag);
  2580. if (sleepFlag == CAN_SLEEP) {
  2581. msleep_interruptible (1000);
  2582. } else {
  2583. mdelay (1000);
  2584. }
  2585. }
  2586. hard_reset_done = mpt_diag_reset(ioc, force, sleepFlag);
  2587. if (hard_reset_done < 0)
  2588. return hard_reset_done;
  2589. dinitprintk((MYIOC_s_INFO_FMT "Diagnostic reset successful!\n",
  2590. ioc->name));
  2591. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 2; /* 2 seconds */
  2592. for (cnt=0; cnt<cntdn; cnt++) {
  2593. ioc_state = mpt_GetIocState(ioc, 1);
  2594. if ((ioc_state == MPI_IOC_STATE_READY) || (ioc_state == MPI_IOC_STATE_OPERATIONAL)) {
  2595. dinitprintk((MYIOC_s_INFO_FMT "KickStart successful! (cnt=%d)\n",
  2596. ioc->name, cnt));
  2597. return hard_reset_done;
  2598. }
  2599. if (sleepFlag == CAN_SLEEP) {
  2600. msleep_interruptible (10);
  2601. } else {
  2602. mdelay (10);
  2603. }
  2604. }
  2605. printk(MYIOC_s_ERR_FMT "Failed to come READY after reset! IocState=%x\n",
  2606. ioc->name, ioc_state);
  2607. return -1;
  2608. }
  2609. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2610. /*
  2611. * mpt_diag_reset - Perform hard reset of the adapter.
  2612. * @ioc: Pointer to MPT_ADAPTER structure
  2613. * @ignore: Set if to honor and clear to ignore
  2614. * the reset history bit
  2615. * @sleepflag: CAN_SLEEP if called in a non-interrupt thread,
  2616. * else set to NO_SLEEP (use mdelay instead)
  2617. *
  2618. * This routine places the adapter in diagnostic mode via the
  2619. * WriteSequence register and then performs a hard reset of adapter
  2620. * via the Diagnostic register. Adapter should be in ready state
  2621. * upon successful completion.
  2622. *
  2623. * Returns: 1 hard reset successful
  2624. * 0 no reset performed because reset history bit set
  2625. * -2 enabling diagnostic mode failed
  2626. * -3 diagnostic reset failed
  2627. */
  2628. static int
  2629. mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
  2630. {
  2631. u32 diag0val;
  2632. u32 doorbell;
  2633. int hard_reset_done = 0;
  2634. int count = 0;
  2635. #ifdef MPT_DEBUG
  2636. u32 diag1val = 0;
  2637. #endif
  2638. /* Clear any existing interrupts */
  2639. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  2640. /* Use "Diagnostic reset" method! (only thing available!) */
  2641. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2642. #ifdef MPT_DEBUG
  2643. if (ioc->alt_ioc)
  2644. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  2645. dprintk((MYIOC_s_INFO_FMT "DbG1: diag0=%08x, diag1=%08x\n",
  2646. ioc->name, diag0val, diag1val));
  2647. #endif
  2648. /* Do the reset if we are told to ignore the reset history
  2649. * or if the reset history is 0
  2650. */
  2651. if (ignore || !(diag0val & MPI_DIAG_RESET_HISTORY)) {
  2652. while ((diag0val & MPI_DIAG_DRWE) == 0) {
  2653. /* Write magic sequence to WriteSequence register
  2654. * Loop until in diagnostic mode
  2655. */
  2656. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2657. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  2658. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  2659. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  2660. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  2661. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  2662. /* wait 100 msec */
  2663. if (sleepFlag == CAN_SLEEP) {
  2664. msleep_interruptible (100);
  2665. } else {
  2666. mdelay (100);
  2667. }
  2668. count++;
  2669. if (count > 20) {
  2670. printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
  2671. ioc->name, diag0val);
  2672. return -2;
  2673. }
  2674. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2675. dprintk((MYIOC_s_INFO_FMT "Wrote magic DiagWriteEn sequence (%x)\n",
  2676. ioc->name, diag0val));
  2677. }
  2678. #ifdef MPT_DEBUG
  2679. if (ioc->alt_ioc)
  2680. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  2681. dprintk((MYIOC_s_INFO_FMT "DbG2: diag0=%08x, diag1=%08x\n",
  2682. ioc->name, diag0val, diag1val));
  2683. #endif
  2684. /*
  2685. * Disable the ARM (Bug fix)
  2686. *
  2687. */
  2688. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_DISABLE_ARM);
  2689. mdelay (1);
  2690. /*
  2691. * Now hit the reset bit in the Diagnostic register
  2692. * (THE BIG HAMMER!) (Clears DRWE bit).
  2693. */
  2694. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
  2695. hard_reset_done = 1;
  2696. dprintk((MYIOC_s_INFO_FMT "Diagnostic reset performed\n",
  2697. ioc->name));
  2698. /*
  2699. * Call each currently registered protocol IOC reset handler
  2700. * with pre-reset indication.
  2701. * NOTE: If we're doing _IOC_BRINGUP, there can be no
  2702. * MptResetHandlers[] registered yet.
  2703. */
  2704. {
  2705. int ii;
  2706. int r = 0;
  2707. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  2708. if (MptResetHandlers[ii]) {
  2709. dprintk((MYIOC_s_INFO_FMT "Calling IOC pre_reset handler #%d\n",
  2710. ioc->name, ii));
  2711. r += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_PRE_RESET);
  2712. if (ioc->alt_ioc) {
  2713. dprintk((MYIOC_s_INFO_FMT "Calling alt-%s pre_reset handler #%d\n",
  2714. ioc->name, ioc->alt_ioc->name, ii));
  2715. r += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_PRE_RESET);
  2716. }
  2717. }
  2718. }
  2719. /* FIXME? Examine results here? */
  2720. }
  2721. if (ioc->cached_fw) {
  2722. /* If the DownloadBoot operation fails, the
  2723. * IOC will be left unusable. This is a fatal error
  2724. * case. _diag_reset will return < 0
  2725. */
  2726. for (count = 0; count < 30; count ++) {
  2727. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2728. if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
  2729. break;
  2730. }
  2731. /* wait 1 sec */
  2732. if (sleepFlag == CAN_SLEEP) {
  2733. ssleep(1);
  2734. } else {
  2735. mdelay (1000);
  2736. }
  2737. }
  2738. if ((count = mpt_downloadboot(ioc, sleepFlag)) < 0) {
  2739. printk(KERN_WARNING MYNAM
  2740. ": firmware downloadboot failure (%d)!\n", count);
  2741. }
  2742. } else {
  2743. /* Wait for FW to reload and for board
  2744. * to go to the READY state.
  2745. * Maximum wait is 60 seconds.
  2746. * If fail, no error will check again
  2747. * with calling program.
  2748. */
  2749. for (count = 0; count < 60; count ++) {
  2750. doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
  2751. doorbell &= MPI_IOC_STATE_MASK;
  2752. if (doorbell == MPI_IOC_STATE_READY) {
  2753. break;
  2754. }
  2755. /* wait 1 sec */
  2756. if (sleepFlag == CAN_SLEEP) {
  2757. msleep_interruptible (1000);
  2758. } else {
  2759. mdelay (1000);
  2760. }
  2761. }
  2762. }
  2763. }
  2764. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2765. #ifdef MPT_DEBUG
  2766. if (ioc->alt_ioc)
  2767. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  2768. dprintk((MYIOC_s_INFO_FMT "DbG3: diag0=%08x, diag1=%08x\n",
  2769. ioc->name, diag0val, diag1val));
  2770. #endif
  2771. /* Clear RESET_HISTORY bit! Place board in the
  2772. * diagnostic mode to update the diag register.
  2773. */
  2774. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2775. count = 0;
  2776. while ((diag0val & MPI_DIAG_DRWE) == 0) {
  2777. /* Write magic sequence to WriteSequence register
  2778. * Loop until in diagnostic mode
  2779. */
  2780. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2781. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  2782. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  2783. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  2784. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  2785. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  2786. /* wait 100 msec */
  2787. if (sleepFlag == CAN_SLEEP) {
  2788. msleep_interruptible (100);
  2789. } else {
  2790. mdelay (100);
  2791. }
  2792. count++;
  2793. if (count > 20) {
  2794. printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
  2795. ioc->name, diag0val);
  2796. break;
  2797. }
  2798. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2799. }
  2800. diag0val &= ~MPI_DIAG_RESET_HISTORY;
  2801. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
  2802. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2803. if (diag0val & MPI_DIAG_RESET_HISTORY) {
  2804. printk(MYIOC_s_WARN_FMT "ResetHistory bit failed to clear!\n",
  2805. ioc->name);
  2806. }
  2807. /* Disable Diagnostic Mode
  2808. */
  2809. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFFFFFFFF);
  2810. /* Check FW reload status flags.
  2811. */
  2812. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2813. if (diag0val & (MPI_DIAG_FLASH_BAD_SIG | MPI_DIAG_RESET_ADAPTER | MPI_DIAG_DISABLE_ARM)) {
  2814. printk(MYIOC_s_ERR_FMT "Diagnostic reset FAILED! (%02xh)\n",
  2815. ioc->name, diag0val);
  2816. return -3;
  2817. }
  2818. #ifdef MPT_DEBUG
  2819. if (ioc->alt_ioc)
  2820. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  2821. dprintk((MYIOC_s_INFO_FMT "DbG4: diag0=%08x, diag1=%08x\n",
  2822. ioc->name, diag0val, diag1val));
  2823. #endif
  2824. /*
  2825. * Reset flag that says we've enabled event notification
  2826. */
  2827. ioc->facts.EventState = 0;
  2828. if (ioc->alt_ioc)
  2829. ioc->alt_ioc->facts.EventState = 0;
  2830. return hard_reset_done;
  2831. }
  2832. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2833. /*
  2834. * SendIocReset - Send IOCReset request to MPT adapter.
  2835. * @ioc: Pointer to MPT_ADAPTER structure
  2836. * @reset_type: reset type, expected values are
  2837. * %MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET or %MPI_FUNCTION_IO_UNIT_RESET
  2838. *
  2839. * Send IOCReset request to the MPT adapter.
  2840. *
  2841. * Returns 0 for success, non-zero for failure.
  2842. */
  2843. static int
  2844. SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag)
  2845. {
  2846. int r;
  2847. u32 state;
  2848. int cntdn, count;
  2849. drsprintk((KERN_WARNING MYNAM ": %s: Sending IOC reset(0x%02x)!\n",
  2850. ioc->name, reset_type));
  2851. CHIPREG_WRITE32(&ioc->chip->Doorbell, reset_type<<MPI_DOORBELL_FUNCTION_SHIFT);
  2852. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  2853. return r;
  2854. /* FW ACK'd request, wait for READY state
  2855. */
  2856. count = 0;
  2857. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
  2858. while ((state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
  2859. cntdn--;
  2860. count++;
  2861. if (!cntdn) {
  2862. if (sleepFlag != CAN_SLEEP)
  2863. count *= 10;
  2864. printk(KERN_ERR MYNAM ": %s: ERROR - Wait IOC_READY state timeout(%d)!\n",
  2865. ioc->name, (int)((count+5)/HZ));
  2866. return -ETIME;
  2867. }
  2868. if (sleepFlag == CAN_SLEEP) {
  2869. msleep_interruptible(1);
  2870. } else {
  2871. mdelay (1); /* 1 msec delay */
  2872. }
  2873. }
  2874. /* TODO!
  2875. * Cleanup all event stuff for this IOC; re-issue EventNotification
  2876. * request if needed.
  2877. */
  2878. if (ioc->facts.Function)
  2879. ioc->facts.EventState = 0;
  2880. return 0;
  2881. }
  2882. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2883. /*
  2884. * initChainBuffers - Allocate memory for and initialize
  2885. * chain buffers, chain buffer control arrays and spinlock.
  2886. * @hd: Pointer to MPT_SCSI_HOST structure
  2887. * @init: If set, initialize the spin lock.
  2888. */
  2889. static int
  2890. initChainBuffers(MPT_ADAPTER *ioc)
  2891. {
  2892. u8 *mem;
  2893. int sz, ii, num_chain;
  2894. int scale, num_sge, numSGE;
  2895. /* ReqToChain size must equal the req_depth
  2896. * index = req_idx
  2897. */
  2898. if (ioc->ReqToChain == NULL) {
  2899. sz = ioc->req_depth * sizeof(int);
  2900. mem = kmalloc(sz, GFP_ATOMIC);
  2901. if (mem == NULL)
  2902. return -1;
  2903. ioc->ReqToChain = (int *) mem;
  2904. dinitprintk((KERN_INFO MYNAM ": %s ReqToChain alloc @ %p, sz=%d bytes\n",
  2905. ioc->name, mem, sz));
  2906. mem = kmalloc(sz, GFP_ATOMIC);
  2907. if (mem == NULL)
  2908. return -1;
  2909. ioc->RequestNB = (int *) mem;
  2910. dinitprintk((KERN_INFO MYNAM ": %s RequestNB alloc @ %p, sz=%d bytes\n",
  2911. ioc->name, mem, sz));
  2912. }
  2913. for (ii = 0; ii < ioc->req_depth; ii++) {
  2914. ioc->ReqToChain[ii] = MPT_HOST_NO_CHAIN;
  2915. }
  2916. /* ChainToChain size must equal the total number
  2917. * of chain buffers to be allocated.
  2918. * index = chain_idx
  2919. *
  2920. * Calculate the number of chain buffers needed(plus 1) per I/O
  2921. * then multiply the the maximum number of simultaneous cmds
  2922. *
  2923. * num_sge = num sge in request frame + last chain buffer
  2924. * scale = num sge per chain buffer if no chain element
  2925. */
  2926. scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
  2927. if (sizeof(dma_addr_t) == sizeof(u64))
  2928. num_sge = scale + (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
  2929. else
  2930. num_sge = 1+ scale + (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
  2931. if (sizeof(dma_addr_t) == sizeof(u64)) {
  2932. numSGE = (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
  2933. (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
  2934. } else {
  2935. numSGE = 1 + (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
  2936. (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
  2937. }
  2938. dinitprintk((KERN_INFO MYNAM ": %s num_sge=%d numSGE=%d\n",
  2939. ioc->name, num_sge, numSGE));
  2940. if ( numSGE > MPT_SCSI_SG_DEPTH )
  2941. numSGE = MPT_SCSI_SG_DEPTH;
  2942. num_chain = 1;
  2943. while (numSGE - num_sge > 0) {
  2944. num_chain++;
  2945. num_sge += (scale - 1);
  2946. }
  2947. num_chain++;
  2948. dinitprintk((KERN_INFO MYNAM ": %s Now numSGE=%d num_sge=%d num_chain=%d\n",
  2949. ioc->name, numSGE, num_sge, num_chain));
  2950. if (ioc->bus_type == SCSI)
  2951. num_chain *= MPT_SCSI_CAN_QUEUE;
  2952. else
  2953. num_chain *= MPT_FC_CAN_QUEUE;
  2954. ioc->num_chain = num_chain;
  2955. sz = num_chain * sizeof(int);
  2956. if (ioc->ChainToChain == NULL) {
  2957. mem = kmalloc(sz, GFP_ATOMIC);
  2958. if (mem == NULL)
  2959. return -1;
  2960. ioc->ChainToChain = (int *) mem;
  2961. dinitprintk((KERN_INFO MYNAM ": %s ChainToChain alloc @ %p, sz=%d bytes\n",
  2962. ioc->name, mem, sz));
  2963. } else {
  2964. mem = (u8 *) ioc->ChainToChain;
  2965. }
  2966. memset(mem, 0xFF, sz);
  2967. return num_chain;
  2968. }
  2969. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2970. /*
  2971. * PrimeIocFifos - Initialize IOC request and reply FIFOs.
  2972. * @ioc: Pointer to MPT_ADAPTER structure
  2973. *
  2974. * This routine allocates memory for the MPT reply and request frame
  2975. * pools (if necessary), and primes the IOC reply FIFO with
  2976. * reply frames.
  2977. *
  2978. * Returns 0 for success, non-zero for failure.
  2979. */
  2980. static int
  2981. PrimeIocFifos(MPT_ADAPTER *ioc)
  2982. {
  2983. MPT_FRAME_HDR *mf;
  2984. unsigned long flags;
  2985. dma_addr_t alloc_dma;
  2986. u8 *mem;
  2987. int i, reply_sz, sz, total_size, num_chain;
  2988. /* Prime reply FIFO... */
  2989. if (ioc->reply_frames == NULL) {
  2990. if ( (num_chain = initChainBuffers(ioc)) < 0)
  2991. return -1;
  2992. total_size = reply_sz = (ioc->reply_sz * ioc->reply_depth);
  2993. dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffer sz=%d bytes, ReplyDepth=%d\n",
  2994. ioc->name, ioc->reply_sz, ioc->reply_depth));
  2995. dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffer sz=%d[%x] bytes\n",
  2996. ioc->name, reply_sz, reply_sz));
  2997. sz = (ioc->req_sz * ioc->req_depth);
  2998. dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffer sz=%d bytes, RequestDepth=%d\n",
  2999. ioc->name, ioc->req_sz, ioc->req_depth));
  3000. dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffer sz=%d[%x] bytes\n",
  3001. ioc->name, sz, sz));
  3002. total_size += sz;
  3003. sz = num_chain * ioc->req_sz; /* chain buffer pool size */
  3004. dinitprintk((KERN_INFO MYNAM ": %s.ChainBuffer sz=%d bytes, ChainDepth=%d\n",
  3005. ioc->name, ioc->req_sz, num_chain));
  3006. dinitprintk((KERN_INFO MYNAM ": %s.ChainBuffer sz=%d[%x] bytes num_chain=%d\n",
  3007. ioc->name, sz, sz, num_chain));
  3008. total_size += sz;
  3009. mem = pci_alloc_consistent(ioc->pcidev, total_size, &alloc_dma);
  3010. if (mem == NULL) {
  3011. printk(MYIOC_s_ERR_FMT "Unable to allocate Reply, Request, Chain Buffers!\n",
  3012. ioc->name);
  3013. goto out_fail;
  3014. }
  3015. dinitprintk((KERN_INFO MYNAM ": %s.Total alloc @ %p[%p], sz=%d[%x] bytes\n",
  3016. ioc->name, mem, (void *)(ulong)alloc_dma, total_size, total_size));
  3017. memset(mem, 0, total_size);
  3018. ioc->alloc_total += total_size;
  3019. ioc->alloc = mem;
  3020. ioc->alloc_dma = alloc_dma;
  3021. ioc->alloc_sz = total_size;
  3022. ioc->reply_frames = (MPT_FRAME_HDR *) mem;
  3023. ioc->reply_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
  3024. alloc_dma += reply_sz;
  3025. mem += reply_sz;
  3026. /* Request FIFO - WE manage this! */
  3027. ioc->req_frames = (MPT_FRAME_HDR *) mem;
  3028. ioc->req_frames_dma = alloc_dma;
  3029. dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffers @ %p[%p]\n",
  3030. ioc->name, mem, (void *)(ulong)alloc_dma));
  3031. ioc->req_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
  3032. #if defined(CONFIG_MTRR) && 0
  3033. /*
  3034. * Enable Write Combining MTRR for IOC's memory region.
  3035. * (at least as much as we can; "size and base must be
  3036. * multiples of 4 kiB"
  3037. */
  3038. ioc->mtrr_reg = mtrr_add(ioc->req_frames_dma,
  3039. sz,
  3040. MTRR_TYPE_WRCOMB, 1);
  3041. dprintk((MYIOC_s_INFO_FMT "MTRR region registered (base:size=%08x:%x)\n",
  3042. ioc->name, ioc->req_frames_dma, sz));
  3043. #endif
  3044. for (i = 0; i < ioc->req_depth; i++) {
  3045. alloc_dma += ioc->req_sz;
  3046. mem += ioc->req_sz;
  3047. }
  3048. ioc->ChainBuffer = mem;
  3049. ioc->ChainBufferDMA = alloc_dma;
  3050. dinitprintk((KERN_INFO MYNAM " :%s.ChainBuffers @ %p(%p)\n",
  3051. ioc->name, ioc->ChainBuffer, (void *)(ulong)ioc->ChainBufferDMA));
  3052. /* Initialize the free chain Q.
  3053. */
  3054. INIT_LIST_HEAD(&ioc->FreeChainQ);
  3055. /* Post the chain buffers to the FreeChainQ.
  3056. */
  3057. mem = (u8 *)ioc->ChainBuffer;
  3058. for (i=0; i < num_chain; i++) {
  3059. mf = (MPT_FRAME_HDR *) mem;
  3060. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeChainQ);
  3061. mem += ioc->req_sz;
  3062. }
  3063. /* Initialize Request frames linked list
  3064. */
  3065. alloc_dma = ioc->req_frames_dma;
  3066. mem = (u8 *) ioc->req_frames;
  3067. spin_lock_irqsave(&ioc->FreeQlock, flags);
  3068. INIT_LIST_HEAD(&ioc->FreeQ);
  3069. for (i = 0; i < ioc->req_depth; i++) {
  3070. mf = (MPT_FRAME_HDR *) mem;
  3071. /* Queue REQUESTs *internally*! */
  3072. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
  3073. mem += ioc->req_sz;
  3074. }
  3075. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  3076. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  3077. ioc->sense_buf_pool =
  3078. pci_alloc_consistent(ioc->pcidev, sz, &ioc->sense_buf_pool_dma);
  3079. if (ioc->sense_buf_pool == NULL) {
  3080. printk(MYIOC_s_ERR_FMT "Unable to allocate Sense Buffers!\n",
  3081. ioc->name);
  3082. goto out_fail;
  3083. }
  3084. ioc->sense_buf_low_dma = (u32) (ioc->sense_buf_pool_dma & 0xFFFFFFFF);
  3085. ioc->alloc_total += sz;
  3086. dinitprintk((KERN_INFO MYNAM ": %s.SenseBuffers @ %p[%p]\n",
  3087. ioc->name, ioc->sense_buf_pool, (void *)(ulong)ioc->sense_buf_pool_dma));
  3088. }
  3089. /* Post Reply frames to FIFO
  3090. */
  3091. alloc_dma = ioc->alloc_dma;
  3092. dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffers @ %p[%p]\n",
  3093. ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
  3094. for (i = 0; i < ioc->reply_depth; i++) {
  3095. /* Write each address to the IOC! */
  3096. CHIPREG_WRITE32(&ioc->chip->ReplyFifo, alloc_dma);
  3097. alloc_dma += ioc->reply_sz;
  3098. }
  3099. return 0;
  3100. out_fail:
  3101. if (ioc->alloc != NULL) {
  3102. sz = ioc->alloc_sz;
  3103. pci_free_consistent(ioc->pcidev,
  3104. sz,
  3105. ioc->alloc, ioc->alloc_dma);
  3106. ioc->reply_frames = NULL;
  3107. ioc->req_frames = NULL;
  3108. ioc->alloc_total -= sz;
  3109. }
  3110. if (ioc->sense_buf_pool != NULL) {
  3111. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  3112. pci_free_consistent(ioc->pcidev,
  3113. sz,
  3114. ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
  3115. ioc->sense_buf_pool = NULL;
  3116. }
  3117. return -1;
  3118. }
  3119. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3120. /**
  3121. * mpt_handshake_req_reply_wait - Send MPT request to and receive reply
  3122. * from IOC via doorbell handshake method.
  3123. * @ioc: Pointer to MPT_ADAPTER structure
  3124. * @reqBytes: Size of the request in bytes
  3125. * @req: Pointer to MPT request frame
  3126. * @replyBytes: Expected size of the reply in bytes
  3127. * @u16reply: Pointer to area where reply should be written
  3128. * @maxwait: Max wait time for a reply (in seconds)
  3129. * @sleepFlag: Specifies whether the process can sleep
  3130. *
  3131. * NOTES: It is the callers responsibility to byte-swap fields in the
  3132. * request which are greater than 1 byte in size. It is also the
  3133. * callers responsibility to byte-swap response fields which are
  3134. * greater than 1 byte in size.
  3135. *
  3136. * Returns 0 for success, non-zero for failure.
  3137. */
  3138. static int
  3139. mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req,
  3140. int replyBytes, u16 *u16reply, int maxwait, int sleepFlag)
  3141. {
  3142. MPIDefaultReply_t *mptReply;
  3143. int failcnt = 0;
  3144. int t;
  3145. /*
  3146. * Get ready to cache a handshake reply
  3147. */
  3148. ioc->hs_reply_idx = 0;
  3149. mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
  3150. mptReply->MsgLength = 0;
  3151. /*
  3152. * Make sure there are no doorbells (WRITE 0 to IntStatus reg),
  3153. * then tell IOC that we want to handshake a request of N words.
  3154. * (WRITE u32val to Doorbell reg).
  3155. */
  3156. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3157. CHIPREG_WRITE32(&ioc->chip->Doorbell,
  3158. ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
  3159. ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
  3160. /*
  3161. * Wait for IOC's doorbell handshake int
  3162. */
  3163. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  3164. failcnt++;
  3165. dhsprintk((MYIOC_s_INFO_FMT "HandShake request start reqBytes=%d, WaitCnt=%d%s\n",
  3166. ioc->name, reqBytes, t, failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
  3167. /* Read doorbell and check for active bit */
  3168. if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
  3169. return -1;
  3170. /*
  3171. * Clear doorbell int (WRITE 0 to IntStatus reg),
  3172. * then wait for IOC to ACKnowledge that it's ready for
  3173. * our handshake request.
  3174. */
  3175. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3176. if (!failcnt && (t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  3177. failcnt++;
  3178. if (!failcnt) {
  3179. int ii;
  3180. u8 *req_as_bytes = (u8 *) req;
  3181. /*
  3182. * Stuff request words via doorbell handshake,
  3183. * with ACK from IOC for each.
  3184. */
  3185. for (ii = 0; !failcnt && ii < reqBytes/4; ii++) {
  3186. u32 word = ((req_as_bytes[(ii*4) + 0] << 0) |
  3187. (req_as_bytes[(ii*4) + 1] << 8) |
  3188. (req_as_bytes[(ii*4) + 2] << 16) |
  3189. (req_as_bytes[(ii*4) + 3] << 24));
  3190. CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
  3191. if ((t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  3192. failcnt++;
  3193. }
  3194. dhsprintk((KERN_INFO MYNAM ": Handshake request frame (@%p) header\n", req));
  3195. DBG_DUMP_REQUEST_FRAME_HDR(req)
  3196. dhsprintk((MYIOC_s_INFO_FMT "HandShake request post done, WaitCnt=%d%s\n",
  3197. ioc->name, t, failcnt ? " - MISSING DOORBELL ACK!" : ""));
  3198. /*
  3199. * Wait for completion of doorbell handshake reply from the IOC
  3200. */
  3201. if (!failcnt && (t = WaitForDoorbellReply(ioc, maxwait, sleepFlag)) < 0)
  3202. failcnt++;
  3203. dhsprintk((MYIOC_s_INFO_FMT "HandShake reply count=%d%s\n",
  3204. ioc->name, t, failcnt ? " - MISSING DOORBELL REPLY!" : ""));
  3205. /*
  3206. * Copy out the cached reply...
  3207. */
  3208. for (ii=0; ii < min(replyBytes/2,mptReply->MsgLength*2); ii++)
  3209. u16reply[ii] = ioc->hs_reply[ii];
  3210. } else {
  3211. return -99;
  3212. }
  3213. return -failcnt;
  3214. }
  3215. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3216. /*
  3217. * WaitForDoorbellAck - Wait for IOC to clear the IOP_DOORBELL_STATUS bit
  3218. * in it's IntStatus register.
  3219. * @ioc: Pointer to MPT_ADAPTER structure
  3220. * @howlong: How long to wait (in seconds)
  3221. * @sleepFlag: Specifies whether the process can sleep
  3222. *
  3223. * This routine waits (up to ~2 seconds max) for IOC doorbell
  3224. * handshake ACKnowledge.
  3225. *
  3226. * Returns a negative value on failure, else wait loop count.
  3227. */
  3228. static int
  3229. WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  3230. {
  3231. int cntdn;
  3232. int count = 0;
  3233. u32 intstat=0;
  3234. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * howlong;
  3235. if (sleepFlag == CAN_SLEEP) {
  3236. while (--cntdn) {
  3237. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  3238. if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
  3239. break;
  3240. msleep_interruptible (1);
  3241. count++;
  3242. }
  3243. } else {
  3244. while (--cntdn) {
  3245. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  3246. if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
  3247. break;
  3248. mdelay (1);
  3249. count++;
  3250. }
  3251. }
  3252. if (cntdn) {
  3253. dprintk((MYIOC_s_INFO_FMT "WaitForDoorbell ACK (count=%d)\n",
  3254. ioc->name, count));
  3255. return count;
  3256. }
  3257. printk(MYIOC_s_ERR_FMT "Doorbell ACK timeout (count=%d), IntStatus=%x!\n",
  3258. ioc->name, count, intstat);
  3259. return -1;
  3260. }
  3261. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3262. /*
  3263. * WaitForDoorbellInt - Wait for IOC to set the HIS_DOORBELL_INTERRUPT bit
  3264. * in it's IntStatus register.
  3265. * @ioc: Pointer to MPT_ADAPTER structure
  3266. * @howlong: How long to wait (in seconds)
  3267. * @sleepFlag: Specifies whether the process can sleep
  3268. *
  3269. * This routine waits (up to ~2 seconds max) for IOC doorbell interrupt.
  3270. *
  3271. * Returns a negative value on failure, else wait loop count.
  3272. */
  3273. static int
  3274. WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  3275. {
  3276. int cntdn;
  3277. int count = 0;
  3278. u32 intstat=0;
  3279. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * howlong;
  3280. if (sleepFlag == CAN_SLEEP) {
  3281. while (--cntdn) {
  3282. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  3283. if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
  3284. break;
  3285. msleep_interruptible(1);
  3286. count++;
  3287. }
  3288. } else {
  3289. while (--cntdn) {
  3290. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  3291. if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
  3292. break;
  3293. mdelay(1);
  3294. count++;
  3295. }
  3296. }
  3297. if (cntdn) {
  3298. dprintk((MYIOC_s_INFO_FMT "WaitForDoorbell INT (cnt=%d) howlong=%d\n",
  3299. ioc->name, count, howlong));
  3300. return count;
  3301. }
  3302. printk(MYIOC_s_ERR_FMT "Doorbell INT timeout (count=%d), IntStatus=%x!\n",
  3303. ioc->name, count, intstat);
  3304. return -1;
  3305. }
  3306. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3307. /*
  3308. * WaitForDoorbellReply - Wait for and capture a IOC handshake reply.
  3309. * @ioc: Pointer to MPT_ADAPTER structure
  3310. * @howlong: How long to wait (in seconds)
  3311. * @sleepFlag: Specifies whether the process can sleep
  3312. *
  3313. * This routine polls the IOC for a handshake reply, 16 bits at a time.
  3314. * Reply is cached to IOC private area large enough to hold a maximum
  3315. * of 128 bytes of reply data.
  3316. *
  3317. * Returns a negative value on failure, else size of reply in WORDS.
  3318. */
  3319. static int
  3320. WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  3321. {
  3322. int u16cnt = 0;
  3323. int failcnt = 0;
  3324. int t;
  3325. u16 *hs_reply = ioc->hs_reply;
  3326. volatile MPIDefaultReply_t *mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
  3327. u16 hword;
  3328. hs_reply[0] = hs_reply[1] = hs_reply[7] = 0;
  3329. /*
  3330. * Get first two u16's so we can look at IOC's intended reply MsgLength
  3331. */
  3332. u16cnt=0;
  3333. if ((t = WaitForDoorbellInt(ioc, howlong, sleepFlag)) < 0) {
  3334. failcnt++;
  3335. } else {
  3336. hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  3337. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3338. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  3339. failcnt++;
  3340. else {
  3341. hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  3342. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3343. }
  3344. }
  3345. dhsprintk((MYIOC_s_INFO_FMT "WaitCnt=%d First handshake reply word=%08x%s\n",
  3346. ioc->name, t, le32_to_cpu(*(u32 *)hs_reply),
  3347. failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
  3348. /*
  3349. * If no error (and IOC said MsgLength is > 0), piece together
  3350. * reply 16 bits at a time.
  3351. */
  3352. for (u16cnt=2; !failcnt && u16cnt < (2 * mptReply->MsgLength); u16cnt++) {
  3353. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  3354. failcnt++;
  3355. hword = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  3356. /* don't overflow our IOC hs_reply[] buffer! */
  3357. if (u16cnt < sizeof(ioc->hs_reply) / sizeof(ioc->hs_reply[0]))
  3358. hs_reply[u16cnt] = hword;
  3359. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3360. }
  3361. if (!failcnt && (t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  3362. failcnt++;
  3363. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3364. if (failcnt) {
  3365. printk(MYIOC_s_ERR_FMT "Handshake reply failure!\n",
  3366. ioc->name);
  3367. return -failcnt;
  3368. }
  3369. #if 0
  3370. else if (u16cnt != (2 * mptReply->MsgLength)) {
  3371. return -101;
  3372. }
  3373. else if ((mptReply->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
  3374. return -102;
  3375. }
  3376. #endif
  3377. dhsprintk((MYIOC_s_INFO_FMT "Got Handshake reply:\n", ioc->name));
  3378. DBG_DUMP_REPLY_FRAME(mptReply)
  3379. dhsprintk((MYIOC_s_INFO_FMT "WaitForDoorbell REPLY WaitCnt=%d (sz=%d)\n",
  3380. ioc->name, t, u16cnt/2));
  3381. return u16cnt/2;
  3382. }
  3383. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3384. /*
  3385. * GetLanConfigPages - Fetch LANConfig pages.
  3386. * @ioc: Pointer to MPT_ADAPTER structure
  3387. *
  3388. * Return: 0 for success
  3389. * -ENOMEM if no memory available
  3390. * -EPERM if not allowed due to ISR context
  3391. * -EAGAIN if no msg frames currently available
  3392. * -EFAULT for non-successful reply or no reply (timeout)
  3393. */
  3394. static int
  3395. GetLanConfigPages(MPT_ADAPTER *ioc)
  3396. {
  3397. ConfigPageHeader_t hdr;
  3398. CONFIGPARMS cfg;
  3399. LANPage0_t *ppage0_alloc;
  3400. dma_addr_t page0_dma;
  3401. LANPage1_t *ppage1_alloc;
  3402. dma_addr_t page1_dma;
  3403. int rc = 0;
  3404. int data_sz;
  3405. int copy_sz;
  3406. /* Get LAN Page 0 header */
  3407. hdr.PageVersion = 0;
  3408. hdr.PageLength = 0;
  3409. hdr.PageNumber = 0;
  3410. hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
  3411. cfg.hdr = &hdr;
  3412. cfg.physAddr = -1;
  3413. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3414. cfg.dir = 0;
  3415. cfg.pageAddr = 0;
  3416. cfg.timeout = 0;
  3417. if ((rc = mpt_config(ioc, &cfg)) != 0)
  3418. return rc;
  3419. if (hdr.PageLength > 0) {
  3420. data_sz = hdr.PageLength * 4;
  3421. ppage0_alloc = (LANPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
  3422. rc = -ENOMEM;
  3423. if (ppage0_alloc) {
  3424. memset((u8 *)ppage0_alloc, 0, data_sz);
  3425. cfg.physAddr = page0_dma;
  3426. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3427. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  3428. /* save the data */
  3429. copy_sz = min_t(int, sizeof(LANPage0_t), data_sz);
  3430. memcpy(&ioc->lan_cnfg_page0, ppage0_alloc, copy_sz);
  3431. }
  3432. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
  3433. /* FIXME!
  3434. * Normalize endianness of structure data,
  3435. * by byte-swapping all > 1 byte fields!
  3436. */
  3437. }
  3438. if (rc)
  3439. return rc;
  3440. }
  3441. /* Get LAN Page 1 header */
  3442. hdr.PageVersion = 0;
  3443. hdr.PageLength = 0;
  3444. hdr.PageNumber = 1;
  3445. hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
  3446. cfg.hdr = &hdr;
  3447. cfg.physAddr = -1;
  3448. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3449. cfg.dir = 0;
  3450. cfg.pageAddr = 0;
  3451. if ((rc = mpt_config(ioc, &cfg)) != 0)
  3452. return rc;
  3453. if (hdr.PageLength == 0)
  3454. return 0;
  3455. data_sz = hdr.PageLength * 4;
  3456. rc = -ENOMEM;
  3457. ppage1_alloc = (LANPage1_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page1_dma);
  3458. if (ppage1_alloc) {
  3459. memset((u8 *)ppage1_alloc, 0, data_sz);
  3460. cfg.physAddr = page1_dma;
  3461. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3462. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  3463. /* save the data */
  3464. copy_sz = min_t(int, sizeof(LANPage1_t), data_sz);
  3465. memcpy(&ioc->lan_cnfg_page1, ppage1_alloc, copy_sz);
  3466. }
  3467. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage1_alloc, page1_dma);
  3468. /* FIXME!
  3469. * Normalize endianness of structure data,
  3470. * by byte-swapping all > 1 byte fields!
  3471. */
  3472. }
  3473. return rc;
  3474. }
  3475. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3476. /*
  3477. * GetFcPortPage0 - Fetch FCPort config Page0.
  3478. * @ioc: Pointer to MPT_ADAPTER structure
  3479. * @portnum: IOC Port number
  3480. *
  3481. * Return: 0 for success
  3482. * -ENOMEM if no memory available
  3483. * -EPERM if not allowed due to ISR context
  3484. * -EAGAIN if no msg frames currently available
  3485. * -EFAULT for non-successful reply or no reply (timeout)
  3486. */
  3487. static int
  3488. GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
  3489. {
  3490. ConfigPageHeader_t hdr;
  3491. CONFIGPARMS cfg;
  3492. FCPortPage0_t *ppage0_alloc;
  3493. FCPortPage0_t *pp0dest;
  3494. dma_addr_t page0_dma;
  3495. int data_sz;
  3496. int copy_sz;
  3497. int rc;
  3498. /* Get FCPort Page 0 header */
  3499. hdr.PageVersion = 0;
  3500. hdr.PageLength = 0;
  3501. hdr.PageNumber = 0;
  3502. hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
  3503. cfg.hdr = &hdr;
  3504. cfg.physAddr = -1;
  3505. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3506. cfg.dir = 0;
  3507. cfg.pageAddr = portnum;
  3508. cfg.timeout = 0;
  3509. if ((rc = mpt_config(ioc, &cfg)) != 0)
  3510. return rc;
  3511. if (hdr.PageLength == 0)
  3512. return 0;
  3513. data_sz = hdr.PageLength * 4;
  3514. rc = -ENOMEM;
  3515. ppage0_alloc = (FCPortPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
  3516. if (ppage0_alloc) {
  3517. memset((u8 *)ppage0_alloc, 0, data_sz);
  3518. cfg.physAddr = page0_dma;
  3519. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3520. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  3521. /* save the data */
  3522. pp0dest = &ioc->fc_port_page0[portnum];
  3523. copy_sz = min_t(int, sizeof(FCPortPage0_t), data_sz);
  3524. memcpy(pp0dest, ppage0_alloc, copy_sz);
  3525. /*
  3526. * Normalize endianness of structure data,
  3527. * by byte-swapping all > 1 byte fields!
  3528. */
  3529. pp0dest->Flags = le32_to_cpu(pp0dest->Flags);
  3530. pp0dest->PortIdentifier = le32_to_cpu(pp0dest->PortIdentifier);
  3531. pp0dest->WWNN.Low = le32_to_cpu(pp0dest->WWNN.Low);
  3532. pp0dest->WWNN.High = le32_to_cpu(pp0dest->WWNN.High);
  3533. pp0dest->WWPN.Low = le32_to_cpu(pp0dest->WWPN.Low);
  3534. pp0dest->WWPN.High = le32_to_cpu(pp0dest->WWPN.High);
  3535. pp0dest->SupportedServiceClass = le32_to_cpu(pp0dest->SupportedServiceClass);
  3536. pp0dest->SupportedSpeeds = le32_to_cpu(pp0dest->SupportedSpeeds);
  3537. pp0dest->CurrentSpeed = le32_to_cpu(pp0dest->CurrentSpeed);
  3538. pp0dest->MaxFrameSize = le32_to_cpu(pp0dest->MaxFrameSize);
  3539. pp0dest->FabricWWNN.Low = le32_to_cpu(pp0dest->FabricWWNN.Low);
  3540. pp0dest->FabricWWNN.High = le32_to_cpu(pp0dest->FabricWWNN.High);
  3541. pp0dest->FabricWWPN.Low = le32_to_cpu(pp0dest->FabricWWPN.Low);
  3542. pp0dest->FabricWWPN.High = le32_to_cpu(pp0dest->FabricWWPN.High);
  3543. pp0dest->DiscoveredPortsCount = le32_to_cpu(pp0dest->DiscoveredPortsCount);
  3544. pp0dest->MaxInitiators = le32_to_cpu(pp0dest->MaxInitiators);
  3545. }
  3546. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
  3547. }
  3548. return rc;
  3549. }
  3550. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3551. /*
  3552. * GetIoUnitPage2 - Retrieve BIOS version and boot order information.
  3553. * @ioc: Pointer to MPT_ADAPTER structure
  3554. *
  3555. * Returns: 0 for success
  3556. * -ENOMEM if no memory available
  3557. * -EPERM if not allowed due to ISR context
  3558. * -EAGAIN if no msg frames currently available
  3559. * -EFAULT for non-successful reply or no reply (timeout)
  3560. */
  3561. static int
  3562. GetIoUnitPage2(MPT_ADAPTER *ioc)
  3563. {
  3564. ConfigPageHeader_t hdr;
  3565. CONFIGPARMS cfg;
  3566. IOUnitPage2_t *ppage_alloc;
  3567. dma_addr_t page_dma;
  3568. int data_sz;
  3569. int rc;
  3570. /* Get the page header */
  3571. hdr.PageVersion = 0;
  3572. hdr.PageLength = 0;
  3573. hdr.PageNumber = 2;
  3574. hdr.PageType = MPI_CONFIG_PAGETYPE_IO_UNIT;
  3575. cfg.hdr = &hdr;
  3576. cfg.physAddr = -1;
  3577. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3578. cfg.dir = 0;
  3579. cfg.pageAddr = 0;
  3580. cfg.timeout = 0;
  3581. if ((rc = mpt_config(ioc, &cfg)) != 0)
  3582. return rc;
  3583. if (hdr.PageLength == 0)
  3584. return 0;
  3585. /* Read the config page */
  3586. data_sz = hdr.PageLength * 4;
  3587. rc = -ENOMEM;
  3588. ppage_alloc = (IOUnitPage2_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
  3589. if (ppage_alloc) {
  3590. memset((u8 *)ppage_alloc, 0, data_sz);
  3591. cfg.physAddr = page_dma;
  3592. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3593. /* If Good, save data */
  3594. if ((rc = mpt_config(ioc, &cfg)) == 0)
  3595. ioc->biosVersion = le32_to_cpu(ppage_alloc->BiosVersion);
  3596. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage_alloc, page_dma);
  3597. }
  3598. return rc;
  3599. }
  3600. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3601. /* mpt_GetScsiPortSettings - read SCSI Port Page 0 and 2
  3602. * @ioc: Pointer to a Adapter Strucutre
  3603. * @portnum: IOC port number
  3604. *
  3605. * Return: -EFAULT if read of config page header fails
  3606. * or if no nvram
  3607. * If read of SCSI Port Page 0 fails,
  3608. * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
  3609. * Adapter settings: async, narrow
  3610. * Return 1
  3611. * If read of SCSI Port Page 2 fails,
  3612. * Adapter settings valid
  3613. * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
  3614. * Return 1
  3615. * Else
  3616. * Both valid
  3617. * Return 0
  3618. * CHECK - what type of locking mechanisms should be used????
  3619. */
  3620. static int
  3621. mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
  3622. {
  3623. u8 *pbuf;
  3624. dma_addr_t buf_dma;
  3625. CONFIGPARMS cfg;
  3626. ConfigPageHeader_t header;
  3627. int ii;
  3628. int data, rc = 0;
  3629. /* Allocate memory
  3630. */
  3631. if (!ioc->spi_data.nvram) {
  3632. int sz;
  3633. u8 *mem;
  3634. sz = MPT_MAX_SCSI_DEVICES * sizeof(int);
  3635. mem = kmalloc(sz, GFP_ATOMIC);
  3636. if (mem == NULL)
  3637. return -EFAULT;
  3638. ioc->spi_data.nvram = (int *) mem;
  3639. dprintk((MYIOC_s_INFO_FMT "SCSI device NVRAM settings @ %p, sz=%d\n",
  3640. ioc->name, ioc->spi_data.nvram, sz));
  3641. }
  3642. /* Invalidate NVRAM information
  3643. */
  3644. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  3645. ioc->spi_data.nvram[ii] = MPT_HOST_NVRAM_INVALID;
  3646. }
  3647. /* Read SPP0 header, allocate memory, then read page.
  3648. */
  3649. header.PageVersion = 0;
  3650. header.PageLength = 0;
  3651. header.PageNumber = 0;
  3652. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
  3653. cfg.hdr = &header;
  3654. cfg.physAddr = -1;
  3655. cfg.pageAddr = portnum;
  3656. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3657. cfg.dir = 0;
  3658. cfg.timeout = 0; /* use default */
  3659. if (mpt_config(ioc, &cfg) != 0)
  3660. return -EFAULT;
  3661. if (header.PageLength > 0) {
  3662. pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
  3663. if (pbuf) {
  3664. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3665. cfg.physAddr = buf_dma;
  3666. if (mpt_config(ioc, &cfg) != 0) {
  3667. ioc->spi_data.maxBusWidth = MPT_NARROW;
  3668. ioc->spi_data.maxSyncOffset = 0;
  3669. ioc->spi_data.minSyncFactor = MPT_ASYNC;
  3670. ioc->spi_data.busType = MPT_HOST_BUS_UNKNOWN;
  3671. rc = 1;
  3672. } else {
  3673. /* Save the Port Page 0 data
  3674. */
  3675. SCSIPortPage0_t *pPP0 = (SCSIPortPage0_t *) pbuf;
  3676. pPP0->Capabilities = le32_to_cpu(pPP0->Capabilities);
  3677. pPP0->PhysicalInterface = le32_to_cpu(pPP0->PhysicalInterface);
  3678. if ( (pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_QAS) == 0 ) {
  3679. ioc->spi_data.noQas |= MPT_TARGET_NO_NEGO_QAS;
  3680. dinitprintk((KERN_INFO MYNAM " :%s noQas due to Capabilities=%x\n",
  3681. ioc->name, pPP0->Capabilities));
  3682. }
  3683. ioc->spi_data.maxBusWidth = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_WIDE ? 1 : 0;
  3684. data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MAX_SYNC_OFFSET_MASK;
  3685. if (data) {
  3686. ioc->spi_data.maxSyncOffset = (u8) (data >> 16);
  3687. data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MIN_SYNC_PERIOD_MASK;
  3688. ioc->spi_data.minSyncFactor = (u8) (data >> 8);
  3689. } else {
  3690. ioc->spi_data.maxSyncOffset = 0;
  3691. ioc->spi_data.minSyncFactor = MPT_ASYNC;
  3692. }
  3693. ioc->spi_data.busType = pPP0->PhysicalInterface & MPI_SCSIPORTPAGE0_PHY_SIGNAL_TYPE_MASK;
  3694. /* Update the minSyncFactor based on bus type.
  3695. */
  3696. if ((ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_HVD) ||
  3697. (ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_SE)) {
  3698. if (ioc->spi_data.minSyncFactor < MPT_ULTRA)
  3699. ioc->spi_data.minSyncFactor = MPT_ULTRA;
  3700. }
  3701. }
  3702. if (pbuf) {
  3703. pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
  3704. }
  3705. }
  3706. }
  3707. /* SCSI Port Page 2 - Read the header then the page.
  3708. */
  3709. header.PageVersion = 0;
  3710. header.PageLength = 0;
  3711. header.PageNumber = 2;
  3712. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
  3713. cfg.hdr = &header;
  3714. cfg.physAddr = -1;
  3715. cfg.pageAddr = portnum;
  3716. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3717. cfg.dir = 0;
  3718. if (mpt_config(ioc, &cfg) != 0)
  3719. return -EFAULT;
  3720. if (header.PageLength > 0) {
  3721. /* Allocate memory and read SCSI Port Page 2
  3722. */
  3723. pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
  3724. if (pbuf) {
  3725. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_NVRAM;
  3726. cfg.physAddr = buf_dma;
  3727. if (mpt_config(ioc, &cfg) != 0) {
  3728. /* Nvram data is left with INVALID mark
  3729. */
  3730. rc = 1;
  3731. } else {
  3732. SCSIPortPage2_t *pPP2 = (SCSIPortPage2_t *) pbuf;
  3733. MpiDeviceInfo_t *pdevice = NULL;
  3734. /* Save the Port Page 2 data
  3735. * (reformat into a 32bit quantity)
  3736. */
  3737. data = le32_to_cpu(pPP2->PortFlags) & MPI_SCSIPORTPAGE2_PORT_FLAGS_DV_MASK;
  3738. ioc->spi_data.PortFlags = data;
  3739. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  3740. pdevice = &pPP2->DeviceSettings[ii];
  3741. data = (le16_to_cpu(pdevice->DeviceFlags) << 16) |
  3742. (pdevice->SyncFactor << 8) | pdevice->Timeout;
  3743. ioc->spi_data.nvram[ii] = data;
  3744. }
  3745. }
  3746. pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
  3747. }
  3748. }
  3749. /* Update Adapter limits with those from NVRAM
  3750. * Comment: Don't need to do this. Target performance
  3751. * parameters will never exceed the adapters limits.
  3752. */
  3753. return rc;
  3754. }
  3755. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3756. /* mpt_readScsiDevicePageHeaders - save version and length of SDP1
  3757. * @ioc: Pointer to a Adapter Strucutre
  3758. * @portnum: IOC port number
  3759. *
  3760. * Return: -EFAULT if read of config page header fails
  3761. * or 0 if success.
  3762. */
  3763. static int
  3764. mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
  3765. {
  3766. CONFIGPARMS cfg;
  3767. ConfigPageHeader_t header;
  3768. /* Read the SCSI Device Page 1 header
  3769. */
  3770. header.PageVersion = 0;
  3771. header.PageLength = 0;
  3772. header.PageNumber = 1;
  3773. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  3774. cfg.hdr = &header;
  3775. cfg.physAddr = -1;
  3776. cfg.pageAddr = portnum;
  3777. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3778. cfg.dir = 0;
  3779. cfg.timeout = 0;
  3780. if (mpt_config(ioc, &cfg) != 0)
  3781. return -EFAULT;
  3782. ioc->spi_data.sdp1version = cfg.hdr->PageVersion;
  3783. ioc->spi_data.sdp1length = cfg.hdr->PageLength;
  3784. header.PageVersion = 0;
  3785. header.PageLength = 0;
  3786. header.PageNumber = 0;
  3787. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  3788. if (mpt_config(ioc, &cfg) != 0)
  3789. return -EFAULT;
  3790. ioc->spi_data.sdp0version = cfg.hdr->PageVersion;
  3791. ioc->spi_data.sdp0length = cfg.hdr->PageLength;
  3792. dcprintk((MYIOC_s_INFO_FMT "Headers: 0: version %d length %d\n",
  3793. ioc->name, ioc->spi_data.sdp0version, ioc->spi_data.sdp0length));
  3794. dcprintk((MYIOC_s_INFO_FMT "Headers: 1: version %d length %d\n",
  3795. ioc->name, ioc->spi_data.sdp1version, ioc->spi_data.sdp1length));
  3796. return 0;
  3797. }
  3798. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3799. /**
  3800. * mpt_findImVolumes - Identify IDs of hidden disks and RAID Volumes
  3801. * @ioc: Pointer to a Adapter Strucutre
  3802. * @portnum: IOC port number
  3803. *
  3804. * Return:
  3805. * 0 on success
  3806. * -EFAULT if read of config page header fails or data pointer not NULL
  3807. * -ENOMEM if pci_alloc failed
  3808. */
  3809. int
  3810. mpt_findImVolumes(MPT_ADAPTER *ioc)
  3811. {
  3812. IOCPage2_t *pIoc2;
  3813. u8 *mem;
  3814. ConfigPageIoc2RaidVol_t *pIocRv;
  3815. dma_addr_t ioc2_dma;
  3816. CONFIGPARMS cfg;
  3817. ConfigPageHeader_t header;
  3818. int jj;
  3819. int rc = 0;
  3820. int iocpage2sz;
  3821. u8 nVols, nPhys;
  3822. u8 vid, vbus, vioc;
  3823. /* Read IOCP2 header then the page.
  3824. */
  3825. header.PageVersion = 0;
  3826. header.PageLength = 0;
  3827. header.PageNumber = 2;
  3828. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  3829. cfg.hdr = &header;
  3830. cfg.physAddr = -1;
  3831. cfg.pageAddr = 0;
  3832. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3833. cfg.dir = 0;
  3834. cfg.timeout = 0;
  3835. if (mpt_config(ioc, &cfg) != 0)
  3836. return -EFAULT;
  3837. if (header.PageLength == 0)
  3838. return -EFAULT;
  3839. iocpage2sz = header.PageLength * 4;
  3840. pIoc2 = pci_alloc_consistent(ioc->pcidev, iocpage2sz, &ioc2_dma);
  3841. if (!pIoc2)
  3842. return -ENOMEM;
  3843. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3844. cfg.physAddr = ioc2_dma;
  3845. if (mpt_config(ioc, &cfg) != 0)
  3846. goto done_and_free;
  3847. if ( (mem = (u8 *)ioc->spi_data.pIocPg2) == NULL ) {
  3848. mem = kmalloc(iocpage2sz, GFP_ATOMIC);
  3849. if (mem) {
  3850. ioc->spi_data.pIocPg2 = (IOCPage2_t *) mem;
  3851. } else {
  3852. goto done_and_free;
  3853. }
  3854. }
  3855. memcpy(mem, (u8 *)pIoc2, iocpage2sz);
  3856. /* Identify RAID Volume Id's */
  3857. nVols = pIoc2->NumActiveVolumes;
  3858. if ( nVols == 0) {
  3859. /* No RAID Volume.
  3860. */
  3861. goto done_and_free;
  3862. } else {
  3863. /* At least 1 RAID Volume
  3864. */
  3865. pIocRv = pIoc2->RaidVolume;
  3866. ioc->spi_data.isRaid = 0;
  3867. for (jj = 0; jj < nVols; jj++, pIocRv++) {
  3868. vid = pIocRv->VolumeID;
  3869. vbus = pIocRv->VolumeBus;
  3870. vioc = pIocRv->VolumeIOC;
  3871. /* find the match
  3872. */
  3873. if (vbus == 0) {
  3874. ioc->spi_data.isRaid |= (1 << vid);
  3875. } else {
  3876. /* Error! Always bus 0
  3877. */
  3878. }
  3879. }
  3880. }
  3881. /* Identify Hidden Physical Disk Id's */
  3882. nPhys = pIoc2->NumActivePhysDisks;
  3883. if (nPhys == 0) {
  3884. /* No physical disks.
  3885. */
  3886. } else {
  3887. mpt_read_ioc_pg_3(ioc);
  3888. }
  3889. done_and_free:
  3890. pci_free_consistent(ioc->pcidev, iocpage2sz, pIoc2, ioc2_dma);
  3891. return rc;
  3892. }
  3893. int
  3894. mpt_read_ioc_pg_3(MPT_ADAPTER *ioc)
  3895. {
  3896. IOCPage3_t *pIoc3;
  3897. u8 *mem;
  3898. CONFIGPARMS cfg;
  3899. ConfigPageHeader_t header;
  3900. dma_addr_t ioc3_dma;
  3901. int iocpage3sz = 0;
  3902. /* Free the old page
  3903. */
  3904. if (ioc->spi_data.pIocPg3) {
  3905. kfree(ioc->spi_data.pIocPg3);
  3906. ioc->spi_data.pIocPg3 = NULL;
  3907. }
  3908. /* There is at least one physical disk.
  3909. * Read and save IOC Page 3
  3910. */
  3911. header.PageVersion = 0;
  3912. header.PageLength = 0;
  3913. header.PageNumber = 3;
  3914. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  3915. cfg.hdr = &header;
  3916. cfg.physAddr = -1;
  3917. cfg.pageAddr = 0;
  3918. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3919. cfg.dir = 0;
  3920. cfg.timeout = 0;
  3921. if (mpt_config(ioc, &cfg) != 0)
  3922. return 0;
  3923. if (header.PageLength == 0)
  3924. return 0;
  3925. /* Read Header good, alloc memory
  3926. */
  3927. iocpage3sz = header.PageLength * 4;
  3928. pIoc3 = pci_alloc_consistent(ioc->pcidev, iocpage3sz, &ioc3_dma);
  3929. if (!pIoc3)
  3930. return 0;
  3931. /* Read the Page and save the data
  3932. * into malloc'd memory.
  3933. */
  3934. cfg.physAddr = ioc3_dma;
  3935. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3936. if (mpt_config(ioc, &cfg) == 0) {
  3937. mem = kmalloc(iocpage3sz, GFP_ATOMIC);
  3938. if (mem) {
  3939. memcpy(mem, (u8 *)pIoc3, iocpage3sz);
  3940. ioc->spi_data.pIocPg3 = (IOCPage3_t *) mem;
  3941. }
  3942. }
  3943. pci_free_consistent(ioc->pcidev, iocpage3sz, pIoc3, ioc3_dma);
  3944. return 0;
  3945. }
  3946. static void
  3947. mpt_read_ioc_pg_4(MPT_ADAPTER *ioc)
  3948. {
  3949. IOCPage4_t *pIoc4;
  3950. CONFIGPARMS cfg;
  3951. ConfigPageHeader_t header;
  3952. dma_addr_t ioc4_dma;
  3953. int iocpage4sz;
  3954. /* Read and save IOC Page 4
  3955. */
  3956. header.PageVersion = 0;
  3957. header.PageLength = 0;
  3958. header.PageNumber = 4;
  3959. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  3960. cfg.hdr = &header;
  3961. cfg.physAddr = -1;
  3962. cfg.pageAddr = 0;
  3963. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3964. cfg.dir = 0;
  3965. cfg.timeout = 0;
  3966. if (mpt_config(ioc, &cfg) != 0)
  3967. return;
  3968. if (header.PageLength == 0)
  3969. return;
  3970. if ( (pIoc4 = ioc->spi_data.pIocPg4) == NULL ) {
  3971. iocpage4sz = (header.PageLength + 4) * 4; /* Allow 4 additional SEP's */
  3972. pIoc4 = pci_alloc_consistent(ioc->pcidev, iocpage4sz, &ioc4_dma);
  3973. if (!pIoc4)
  3974. return;
  3975. } else {
  3976. ioc4_dma = ioc->spi_data.IocPg4_dma;
  3977. iocpage4sz = ioc->spi_data.IocPg4Sz;
  3978. }
  3979. /* Read the Page into dma memory.
  3980. */
  3981. cfg.physAddr = ioc4_dma;
  3982. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3983. if (mpt_config(ioc, &cfg) == 0) {
  3984. ioc->spi_data.pIocPg4 = (IOCPage4_t *) pIoc4;
  3985. ioc->spi_data.IocPg4_dma = ioc4_dma;
  3986. ioc->spi_data.IocPg4Sz = iocpage4sz;
  3987. } else {
  3988. pci_free_consistent(ioc->pcidev, iocpage4sz, pIoc4, ioc4_dma);
  3989. ioc->spi_data.pIocPg4 = NULL;
  3990. }
  3991. }
  3992. static void
  3993. mpt_read_ioc_pg_1(MPT_ADAPTER *ioc)
  3994. {
  3995. IOCPage1_t *pIoc1;
  3996. CONFIGPARMS cfg;
  3997. ConfigPageHeader_t header;
  3998. dma_addr_t ioc1_dma;
  3999. int iocpage1sz = 0;
  4000. u32 tmp;
  4001. /* Check the Coalescing Timeout in IOC Page 1
  4002. */
  4003. header.PageVersion = 0;
  4004. header.PageLength = 0;
  4005. header.PageNumber = 1;
  4006. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  4007. cfg.hdr = &header;
  4008. cfg.physAddr = -1;
  4009. cfg.pageAddr = 0;
  4010. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4011. cfg.dir = 0;
  4012. cfg.timeout = 0;
  4013. if (mpt_config(ioc, &cfg) != 0)
  4014. return;
  4015. if (header.PageLength == 0)
  4016. return;
  4017. /* Read Header good, alloc memory
  4018. */
  4019. iocpage1sz = header.PageLength * 4;
  4020. pIoc1 = pci_alloc_consistent(ioc->pcidev, iocpage1sz, &ioc1_dma);
  4021. if (!pIoc1)
  4022. return;
  4023. /* Read the Page and check coalescing timeout
  4024. */
  4025. cfg.physAddr = ioc1_dma;
  4026. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4027. if (mpt_config(ioc, &cfg) == 0) {
  4028. tmp = le32_to_cpu(pIoc1->Flags) & MPI_IOCPAGE1_REPLY_COALESCING;
  4029. if (tmp == MPI_IOCPAGE1_REPLY_COALESCING) {
  4030. tmp = le32_to_cpu(pIoc1->CoalescingTimeout);
  4031. dprintk((MYIOC_s_INFO_FMT "Coalescing Enabled Timeout = %d\n",
  4032. ioc->name, tmp));
  4033. if (tmp > MPT_COALESCING_TIMEOUT) {
  4034. pIoc1->CoalescingTimeout = cpu_to_le32(MPT_COALESCING_TIMEOUT);
  4035. /* Write NVRAM and current
  4036. */
  4037. cfg.dir = 1;
  4038. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  4039. if (mpt_config(ioc, &cfg) == 0) {
  4040. dprintk((MYIOC_s_INFO_FMT "Reset Current Coalescing Timeout to = %d\n",
  4041. ioc->name, MPT_COALESCING_TIMEOUT));
  4042. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM;
  4043. if (mpt_config(ioc, &cfg) == 0) {
  4044. dprintk((MYIOC_s_INFO_FMT "Reset NVRAM Coalescing Timeout to = %d\n",
  4045. ioc->name, MPT_COALESCING_TIMEOUT));
  4046. } else {
  4047. dprintk((MYIOC_s_INFO_FMT "Reset NVRAM Coalescing Timeout Failed\n",
  4048. ioc->name));
  4049. }
  4050. } else {
  4051. dprintk((MYIOC_s_WARN_FMT "Reset of Current Coalescing Timeout Failed!\n",
  4052. ioc->name));
  4053. }
  4054. }
  4055. } else {
  4056. dprintk((MYIOC_s_WARN_FMT "Coalescing Disabled\n", ioc->name));
  4057. }
  4058. }
  4059. pci_free_consistent(ioc->pcidev, iocpage1sz, pIoc1, ioc1_dma);
  4060. return;
  4061. }
  4062. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4063. /*
  4064. * SendEventNotification - Send EventNotification (on or off) request
  4065. * to MPT adapter.
  4066. * @ioc: Pointer to MPT_ADAPTER structure
  4067. * @EvSwitch: Event switch flags
  4068. */
  4069. static int
  4070. SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch)
  4071. {
  4072. EventNotification_t *evnp;
  4073. evnp = (EventNotification_t *) mpt_get_msg_frame(mpt_base_index, ioc);
  4074. if (evnp == NULL) {
  4075. dprintk((MYIOC_s_WARN_FMT "Unable to allocate event request frame!\n",
  4076. ioc->name));
  4077. return 0;
  4078. }
  4079. memset(evnp, 0, sizeof(*evnp));
  4080. dprintk((MYIOC_s_INFO_FMT "Sending EventNotification(%d)\n", ioc->name, EvSwitch));
  4081. evnp->Function = MPI_FUNCTION_EVENT_NOTIFICATION;
  4082. evnp->ChainOffset = 0;
  4083. evnp->MsgFlags = 0;
  4084. evnp->Switch = EvSwitch;
  4085. mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)evnp);
  4086. return 0;
  4087. }
  4088. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4089. /**
  4090. * SendEventAck - Send EventAck request to MPT adapter.
  4091. * @ioc: Pointer to MPT_ADAPTER structure
  4092. * @evnp: Pointer to original EventNotification request
  4093. */
  4094. static int
  4095. SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp)
  4096. {
  4097. EventAck_t *pAck;
  4098. if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  4099. printk(MYIOC_s_WARN_FMT "Unable to allocate event ACK request frame!\n",
  4100. ioc->name);
  4101. return -1;
  4102. }
  4103. memset(pAck, 0, sizeof(*pAck));
  4104. dprintk((MYIOC_s_INFO_FMT "Sending EventAck\n", ioc->name));
  4105. pAck->Function = MPI_FUNCTION_EVENT_ACK;
  4106. pAck->ChainOffset = 0;
  4107. pAck->MsgFlags = 0;
  4108. pAck->Event = evnp->Event;
  4109. pAck->EventContext = evnp->EventContext;
  4110. mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)pAck);
  4111. return 0;
  4112. }
  4113. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4114. /**
  4115. * mpt_config - Generic function to issue config message
  4116. * @ioc - Pointer to an adapter structure
  4117. * @cfg - Pointer to a configuration structure. Struct contains
  4118. * action, page address, direction, physical address
  4119. * and pointer to a configuration page header
  4120. * Page header is updated.
  4121. *
  4122. * Returns 0 for success
  4123. * -EPERM if not allowed due to ISR context
  4124. * -EAGAIN if no msg frames currently available
  4125. * -EFAULT for non-successful reply or no reply (timeout)
  4126. */
  4127. int
  4128. mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
  4129. {
  4130. Config_t *pReq;
  4131. MPT_FRAME_HDR *mf;
  4132. unsigned long flags;
  4133. int ii, rc;
  4134. u32 flagsLength;
  4135. int in_isr;
  4136. /* (Bugzilla:fibrebugs, #513)
  4137. * Bug fix (part 1)! 20010905 -sralston
  4138. * Prevent calling wait_event() (below), if caller happens
  4139. * to be in ISR context, because that is fatal!
  4140. */
  4141. in_isr = in_interrupt();
  4142. if (in_isr) {
  4143. dcprintk((MYIOC_s_WARN_FMT "Config request not allowed in ISR context!\n",
  4144. ioc->name));
  4145. return -EPERM;
  4146. }
  4147. /* Get and Populate a free Frame
  4148. */
  4149. if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  4150. dcprintk((MYIOC_s_WARN_FMT "mpt_config: no msg frames!\n",
  4151. ioc->name));
  4152. return -EAGAIN;
  4153. }
  4154. pReq = (Config_t *)mf;
  4155. pReq->Action = pCfg->action;
  4156. pReq->Reserved = 0;
  4157. pReq->ChainOffset = 0;
  4158. pReq->Function = MPI_FUNCTION_CONFIG;
  4159. pReq->ExtPageLength = 0;
  4160. pReq->ExtPageType = 0;
  4161. pReq->MsgFlags = 0;
  4162. for (ii=0; ii < 8; ii++)
  4163. pReq->Reserved2[ii] = 0;
  4164. pReq->Header.PageVersion = pCfg->hdr->PageVersion;
  4165. pReq->Header.PageLength = pCfg->hdr->PageLength;
  4166. pReq->Header.PageNumber = pCfg->hdr->PageNumber;
  4167. pReq->Header.PageType = (pCfg->hdr->PageType & MPI_CONFIG_PAGETYPE_MASK);
  4168. pReq->PageAddress = cpu_to_le32(pCfg->pageAddr);
  4169. /* Add a SGE to the config request.
  4170. */
  4171. if (pCfg->dir)
  4172. flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
  4173. else
  4174. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
  4175. flagsLength |= pCfg->hdr->PageLength * 4;
  4176. mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
  4177. dcprintk((MYIOC_s_INFO_FMT "Sending Config request type %d, page %d and action %d\n",
  4178. ioc->name, pReq->Header.PageType, pReq->Header.PageNumber, pReq->Action));
  4179. /* Append pCfg pointer to end of mf
  4180. */
  4181. *((void **) (((u8 *) mf) + (ioc->req_sz - sizeof(void *)))) = (void *) pCfg;
  4182. /* Initalize the timer
  4183. */
  4184. init_timer(&pCfg->timer);
  4185. pCfg->timer.data = (unsigned long) ioc;
  4186. pCfg->timer.function = mpt_timer_expired;
  4187. pCfg->wait_done = 0;
  4188. /* Set the timer; ensure 10 second minimum */
  4189. if (pCfg->timeout < 10)
  4190. pCfg->timer.expires = jiffies + HZ*10;
  4191. else
  4192. pCfg->timer.expires = jiffies + HZ*pCfg->timeout;
  4193. /* Add to end of Q, set timer and then issue this command */
  4194. spin_lock_irqsave(&ioc->FreeQlock, flags);
  4195. list_add_tail(&pCfg->linkage, &ioc->configQ);
  4196. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4197. add_timer(&pCfg->timer);
  4198. mpt_put_msg_frame(mpt_base_index, ioc, mf);
  4199. wait_event(mpt_waitq, pCfg->wait_done);
  4200. /* mf has been freed - do not access */
  4201. rc = pCfg->status;
  4202. return rc;
  4203. }
  4204. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4205. /**
  4206. * mpt_toolbox - Generic function to issue toolbox message
  4207. * @ioc - Pointer to an adapter structure
  4208. * @cfg - Pointer to a toolbox structure. Struct contains
  4209. * action, page address, direction, physical address
  4210. * and pointer to a configuration page header
  4211. * Page header is updated.
  4212. *
  4213. * Returns 0 for success
  4214. * -EPERM if not allowed due to ISR context
  4215. * -EAGAIN if no msg frames currently available
  4216. * -EFAULT for non-successful reply or no reply (timeout)
  4217. */
  4218. int
  4219. mpt_toolbox(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
  4220. {
  4221. ToolboxIstwiReadWriteRequest_t *pReq;
  4222. MPT_FRAME_HDR *mf;
  4223. struct pci_dev *pdev;
  4224. unsigned long flags;
  4225. int rc;
  4226. u32 flagsLength;
  4227. int in_isr;
  4228. /* (Bugzilla:fibrebugs, #513)
  4229. * Bug fix (part 1)! 20010905 -sralston
  4230. * Prevent calling wait_event() (below), if caller happens
  4231. * to be in ISR context, because that is fatal!
  4232. */
  4233. in_isr = in_interrupt();
  4234. if (in_isr) {
  4235. dcprintk((MYIOC_s_WARN_FMT "toobox request not allowed in ISR context!\n",
  4236. ioc->name));
  4237. return -EPERM;
  4238. }
  4239. /* Get and Populate a free Frame
  4240. */
  4241. if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  4242. dcprintk((MYIOC_s_WARN_FMT "mpt_toolbox: no msg frames!\n",
  4243. ioc->name));
  4244. return -EAGAIN;
  4245. }
  4246. pReq = (ToolboxIstwiReadWriteRequest_t *)mf;
  4247. pReq->Tool = pCfg->action;
  4248. pReq->Reserved = 0;
  4249. pReq->ChainOffset = 0;
  4250. pReq->Function = MPI_FUNCTION_TOOLBOX;
  4251. pReq->Reserved1 = 0;
  4252. pReq->Reserved2 = 0;
  4253. pReq->MsgFlags = 0;
  4254. pReq->Flags = pCfg->dir;
  4255. pReq->BusNum = 0;
  4256. pReq->Reserved3 = 0;
  4257. pReq->NumAddressBytes = 0x01;
  4258. pReq->Reserved4 = 0;
  4259. pReq->DataLength = 0x04;
  4260. pdev = (struct pci_dev *) ioc->pcidev;
  4261. if (pdev->devfn & 1)
  4262. pReq->DeviceAddr = 0xB2;
  4263. else
  4264. pReq->DeviceAddr = 0xB0;
  4265. pReq->Addr1 = 0;
  4266. pReq->Addr2 = 0;
  4267. pReq->Addr3 = 0;
  4268. pReq->Reserved5 = 0;
  4269. /* Add a SGE to the config request.
  4270. */
  4271. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | 4;
  4272. mpt_add_sge((char *)&pReq->SGL, flagsLength, pCfg->physAddr);
  4273. dcprintk((MYIOC_s_INFO_FMT "Sending Toolbox request, Tool=%x\n",
  4274. ioc->name, pReq->Tool));
  4275. /* Append pCfg pointer to end of mf
  4276. */
  4277. *((void **) (((u8 *) mf) + (ioc->req_sz - sizeof(void *)))) = (void *) pCfg;
  4278. /* Initalize the timer
  4279. */
  4280. init_timer(&pCfg->timer);
  4281. pCfg->timer.data = (unsigned long) ioc;
  4282. pCfg->timer.function = mpt_timer_expired;
  4283. pCfg->wait_done = 0;
  4284. /* Set the timer; ensure 10 second minimum */
  4285. if (pCfg->timeout < 10)
  4286. pCfg->timer.expires = jiffies + HZ*10;
  4287. else
  4288. pCfg->timer.expires = jiffies + HZ*pCfg->timeout;
  4289. /* Add to end of Q, set timer and then issue this command */
  4290. spin_lock_irqsave(&ioc->FreeQlock, flags);
  4291. list_add_tail(&pCfg->linkage, &ioc->configQ);
  4292. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4293. add_timer(&pCfg->timer);
  4294. mpt_put_msg_frame(mpt_base_index, ioc, mf);
  4295. wait_event(mpt_waitq, pCfg->wait_done);
  4296. /* mf has been freed - do not access */
  4297. rc = pCfg->status;
  4298. return rc;
  4299. }
  4300. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4301. /*
  4302. * mpt_timer_expired - Call back for timer process.
  4303. * Used only internal config functionality.
  4304. * @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
  4305. */
  4306. static void
  4307. mpt_timer_expired(unsigned long data)
  4308. {
  4309. MPT_ADAPTER *ioc = (MPT_ADAPTER *) data;
  4310. dcprintk((MYIOC_s_WARN_FMT "mpt_timer_expired! \n", ioc->name));
  4311. /* Perform a FW reload */
  4312. if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0)
  4313. printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", ioc->name);
  4314. /* No more processing.
  4315. * Hard reset clean-up will wake up
  4316. * process and free all resources.
  4317. */
  4318. dcprintk((MYIOC_s_WARN_FMT "mpt_timer_expired complete!\n", ioc->name));
  4319. return;
  4320. }
  4321. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4322. /*
  4323. * mpt_ioc_reset - Base cleanup for hard reset
  4324. * @ioc: Pointer to the adapter structure
  4325. * @reset_phase: Indicates pre- or post-reset functionality
  4326. *
  4327. * Remark: Free's resources with internally generated commands.
  4328. */
  4329. static int
  4330. mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  4331. {
  4332. CONFIGPARMS *pCfg;
  4333. unsigned long flags;
  4334. dprintk((KERN_WARNING MYNAM
  4335. ": IOC %s_reset routed to MPT base driver!\n",
  4336. reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
  4337. reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
  4338. if (reset_phase == MPT_IOC_SETUP_RESET) {
  4339. ;
  4340. } else if (reset_phase == MPT_IOC_PRE_RESET) {
  4341. /* If the internal config Q is not empty -
  4342. * delete timer. MF resources will be freed when
  4343. * the FIFO's are primed.
  4344. */
  4345. spin_lock_irqsave(&ioc->FreeQlock, flags);
  4346. list_for_each_entry(pCfg, &ioc->configQ, linkage)
  4347. del_timer(&pCfg->timer);
  4348. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4349. } else {
  4350. CONFIGPARMS *pNext;
  4351. /* Search the configQ for internal commands.
  4352. * Flush the Q, and wake up all suspended threads.
  4353. */
  4354. spin_lock_irqsave(&ioc->FreeQlock, flags);
  4355. list_for_each_entry_safe(pCfg, pNext, &ioc->configQ, linkage) {
  4356. list_del(&pCfg->linkage);
  4357. pCfg->status = MPT_CONFIG_ERROR;
  4358. pCfg->wait_done = 1;
  4359. wake_up(&mpt_waitq);
  4360. }
  4361. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4362. }
  4363. return 1; /* currently means nothing really */
  4364. }
  4365. #ifdef CONFIG_PROC_FS /* { */
  4366. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4367. /*
  4368. * procfs (%MPT_PROCFS_MPTBASEDIR/...) support stuff...
  4369. */
  4370. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4371. /*
  4372. * procmpt_create - Create %MPT_PROCFS_MPTBASEDIR entries.
  4373. *
  4374. * Returns 0 for success, non-zero for failure.
  4375. */
  4376. static int
  4377. procmpt_create(void)
  4378. {
  4379. struct proc_dir_entry *ent;
  4380. mpt_proc_root_dir = proc_mkdir(MPT_PROCFS_MPTBASEDIR, NULL);
  4381. if (mpt_proc_root_dir == NULL)
  4382. return -ENOTDIR;
  4383. ent = create_proc_entry("summary", S_IFREG|S_IRUGO, mpt_proc_root_dir);
  4384. if (ent)
  4385. ent->read_proc = procmpt_summary_read;
  4386. ent = create_proc_entry("version", S_IFREG|S_IRUGO, mpt_proc_root_dir);
  4387. if (ent)
  4388. ent->read_proc = procmpt_version_read;
  4389. return 0;
  4390. }
  4391. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4392. /*
  4393. * procmpt_destroy - Tear down %MPT_PROCFS_MPTBASEDIR entries.
  4394. *
  4395. * Returns 0 for success, non-zero for failure.
  4396. */
  4397. static void
  4398. procmpt_destroy(void)
  4399. {
  4400. remove_proc_entry("version", mpt_proc_root_dir);
  4401. remove_proc_entry("summary", mpt_proc_root_dir);
  4402. remove_proc_entry(MPT_PROCFS_MPTBASEDIR, NULL);
  4403. }
  4404. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4405. /*
  4406. * procmpt_summary_read - Handle read request from /proc/mpt/summary
  4407. * or from /proc/mpt/iocN/summary.
  4408. * @buf: Pointer to area to write information
  4409. * @start: Pointer to start pointer
  4410. * @offset: Offset to start writing
  4411. * @request:
  4412. * @eof: Pointer to EOF integer
  4413. * @data: Pointer
  4414. *
  4415. * Returns number of characters written to process performing the read.
  4416. */
  4417. static int
  4418. procmpt_summary_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
  4419. {
  4420. MPT_ADAPTER *ioc;
  4421. char *out = buf;
  4422. int len;
  4423. if (data) {
  4424. int more = 0;
  4425. ioc = data;
  4426. mpt_print_ioc_summary(ioc, out, &more, 0, 1);
  4427. out += more;
  4428. } else {
  4429. list_for_each_entry(ioc, &ioc_list, list) {
  4430. int more = 0;
  4431. mpt_print_ioc_summary(ioc, out, &more, 0, 1);
  4432. out += more;
  4433. if ((out-buf) >= request)
  4434. break;
  4435. }
  4436. }
  4437. len = out - buf;
  4438. MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
  4439. }
  4440. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4441. /*
  4442. * procmpt_version_read - Handle read request from /proc/mpt/version.
  4443. * @buf: Pointer to area to write information
  4444. * @start: Pointer to start pointer
  4445. * @offset: Offset to start writing
  4446. * @request:
  4447. * @eof: Pointer to EOF integer
  4448. * @data: Pointer
  4449. *
  4450. * Returns number of characters written to process performing the read.
  4451. */
  4452. static int
  4453. procmpt_version_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
  4454. {
  4455. int ii;
  4456. int scsi, lan, ctl, targ, dmp;
  4457. char *drvname;
  4458. int len;
  4459. len = sprintf(buf, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON);
  4460. len += sprintf(buf+len, " Fusion MPT base driver\n");
  4461. scsi = lan = ctl = targ = dmp = 0;
  4462. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  4463. drvname = NULL;
  4464. if (MptCallbacks[ii]) {
  4465. switch (MptDriverClass[ii]) {
  4466. case MPTSCSIH_DRIVER:
  4467. if (!scsi++) drvname = "SCSI host";
  4468. break;
  4469. case MPTLAN_DRIVER:
  4470. if (!lan++) drvname = "LAN";
  4471. break;
  4472. case MPTSTM_DRIVER:
  4473. if (!targ++) drvname = "SCSI target";
  4474. break;
  4475. case MPTCTL_DRIVER:
  4476. if (!ctl++) drvname = "ioctl";
  4477. break;
  4478. }
  4479. if (drvname)
  4480. len += sprintf(buf+len, " Fusion MPT %s driver\n", drvname);
  4481. }
  4482. }
  4483. MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
  4484. }
  4485. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4486. /*
  4487. * procmpt_iocinfo_read - Handle read request from /proc/mpt/iocN/info.
  4488. * @buf: Pointer to area to write information
  4489. * @start: Pointer to start pointer
  4490. * @offset: Offset to start writing
  4491. * @request:
  4492. * @eof: Pointer to EOF integer
  4493. * @data: Pointer
  4494. *
  4495. * Returns number of characters written to process performing the read.
  4496. */
  4497. static int
  4498. procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
  4499. {
  4500. MPT_ADAPTER *ioc = data;
  4501. int len;
  4502. char expVer[32];
  4503. int sz;
  4504. int p;
  4505. mpt_get_fw_exp_ver(expVer, ioc);
  4506. len = sprintf(buf, "%s:", ioc->name);
  4507. if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
  4508. len += sprintf(buf+len, " (f/w download boot flag set)");
  4509. // if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL)
  4510. // len += sprintf(buf+len, " CONFIG_CHECKSUM_FAIL!");
  4511. len += sprintf(buf+len, "\n ProductID = 0x%04x (%s)\n",
  4512. ioc->facts.ProductID,
  4513. ioc->prod_name);
  4514. len += sprintf(buf+len, " FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer);
  4515. if (ioc->facts.FWImageSize)
  4516. len += sprintf(buf+len, " (fw_size=%d)", ioc->facts.FWImageSize);
  4517. len += sprintf(buf+len, "\n MsgVersion = 0x%04x\n", ioc->facts.MsgVersion);
  4518. len += sprintf(buf+len, " FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit);
  4519. len += sprintf(buf+len, " EventState = 0x%02x\n", ioc->facts.EventState);
  4520. len += sprintf(buf+len, " CurrentHostMfaHighAddr = 0x%08x\n",
  4521. ioc->facts.CurrentHostMfaHighAddr);
  4522. len += sprintf(buf+len, " CurrentSenseBufferHighAddr = 0x%08x\n",
  4523. ioc->facts.CurrentSenseBufferHighAddr);
  4524. len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
  4525. len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
  4526. len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
  4527. (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
  4528. /*
  4529. * Rounding UP to nearest 4-kB boundary here...
  4530. */
  4531. sz = (ioc->req_sz * ioc->req_depth) + 128;
  4532. sz = ((sz + 0x1000UL - 1UL) / 0x1000) * 0x1000;
  4533. len += sprintf(buf+len, " {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n",
  4534. ioc->req_sz, ioc->req_depth, ioc->req_sz*ioc->req_depth, sz);
  4535. len += sprintf(buf+len, " {MaxReqSz=%d} {MaxReqDepth=%d}\n",
  4536. 4*ioc->facts.RequestFrameSize,
  4537. ioc->facts.GlobalCredits);
  4538. len += sprintf(buf+len, " Frames @ 0x%p (Dma @ 0x%p)\n",
  4539. (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
  4540. sz = (ioc->reply_sz * ioc->reply_depth) + 128;
  4541. len += sprintf(buf+len, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
  4542. ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
  4543. len += sprintf(buf+len, " {MaxRepSz=%d} {MaxRepDepth=%d}\n",
  4544. ioc->facts.CurReplyFrameSize,
  4545. ioc->facts.ReplyQueueDepth);
  4546. len += sprintf(buf+len, " MaxDevices = %d\n",
  4547. (ioc->facts.MaxDevices==0) ? 255 : ioc->facts.MaxDevices);
  4548. len += sprintf(buf+len, " MaxBuses = %d\n", ioc->facts.MaxBuses);
  4549. /* per-port info */
  4550. for (p=0; p < ioc->facts.NumberOfPorts; p++) {
  4551. len += sprintf(buf+len, " PortNumber = %d (of %d)\n",
  4552. p+1,
  4553. ioc->facts.NumberOfPorts);
  4554. if (ioc->bus_type == FC) {
  4555. if (ioc->pfacts[p].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
  4556. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  4557. len += sprintf(buf+len, " LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
  4558. a[5], a[4], a[3], a[2], a[1], a[0]);
  4559. }
  4560. len += sprintf(buf+len, " WWN = %08X%08X:%08X%08X\n",
  4561. ioc->fc_port_page0[p].WWNN.High,
  4562. ioc->fc_port_page0[p].WWNN.Low,
  4563. ioc->fc_port_page0[p].WWPN.High,
  4564. ioc->fc_port_page0[p].WWPN.Low);
  4565. }
  4566. }
  4567. MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
  4568. }
  4569. #endif /* CONFIG_PROC_FS } */
  4570. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4571. static void
  4572. mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc)
  4573. {
  4574. buf[0] ='\0';
  4575. if ((ioc->facts.FWVersion.Word >> 24) == 0x0E) {
  4576. sprintf(buf, " (Exp %02d%02d)",
  4577. (ioc->facts.FWVersion.Word >> 16) & 0x00FF, /* Month */
  4578. (ioc->facts.FWVersion.Word >> 8) & 0x1F); /* Day */
  4579. /* insider hack! */
  4580. if ((ioc->facts.FWVersion.Word >> 8) & 0x80)
  4581. strcat(buf, " [MDBG]");
  4582. }
  4583. }
  4584. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4585. /**
  4586. * mpt_print_ioc_summary - Write ASCII summary of IOC to a buffer.
  4587. * @ioc: Pointer to MPT_ADAPTER structure
  4588. * @buffer: Pointer to buffer where IOC summary info should be written
  4589. * @size: Pointer to number of bytes we wrote (set by this routine)
  4590. * @len: Offset at which to start writing in buffer
  4591. * @showlan: Display LAN stuff?
  4592. *
  4593. * This routine writes (english readable) ASCII text, which represents
  4594. * a summary of IOC information, to a buffer.
  4595. */
  4596. void
  4597. mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int showlan)
  4598. {
  4599. char expVer[32];
  4600. int y;
  4601. mpt_get_fw_exp_ver(expVer, ioc);
  4602. /*
  4603. * Shorter summary of attached ioc's...
  4604. */
  4605. y = sprintf(buffer+len, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
  4606. ioc->name,
  4607. ioc->prod_name,
  4608. MPT_FW_REV_MAGIC_ID_STRING, /* "FwRev=" or somesuch */
  4609. ioc->facts.FWVersion.Word,
  4610. expVer,
  4611. ioc->facts.NumberOfPorts,
  4612. ioc->req_depth);
  4613. if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
  4614. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  4615. y += sprintf(buffer+len+y, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
  4616. a[5], a[4], a[3], a[2], a[1], a[0]);
  4617. }
  4618. #ifndef __sparc__
  4619. y += sprintf(buffer+len+y, ", IRQ=%d", ioc->pci_irq);
  4620. #else
  4621. y += sprintf(buffer+len+y, ", IRQ=%s", __irq_itoa(ioc->pci_irq));
  4622. #endif
  4623. if (!ioc->active)
  4624. y += sprintf(buffer+len+y, " (disabled)");
  4625. y += sprintf(buffer+len+y, "\n");
  4626. *size = y;
  4627. }
  4628. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4629. /*
  4630. * Reset Handling
  4631. */
  4632. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4633. /**
  4634. * mpt_HardResetHandler - Generic reset handler, issue SCSI Task
  4635. * Management call based on input arg values. If TaskMgmt fails,
  4636. * return associated SCSI request.
  4637. * @ioc: Pointer to MPT_ADAPTER structure
  4638. * @sleepFlag: Indicates if sleep or schedule must be called.
  4639. *
  4640. * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
  4641. * or a non-interrupt thread. In the former, must not call schedule().
  4642. *
  4643. * Remark: A return of -1 is a FATAL error case, as it means a
  4644. * FW reload/initialization failed.
  4645. *
  4646. * Returns 0 for SUCCESS or -1 if FAILED.
  4647. */
  4648. int
  4649. mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
  4650. {
  4651. int rc;
  4652. unsigned long flags;
  4653. dtmprintk((MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name));
  4654. #ifdef MFCNT
  4655. printk(MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name);
  4656. printk("MF count 0x%x !\n", ioc->mfcnt);
  4657. #endif
  4658. /* Reset the adapter. Prevent more than 1 call to
  4659. * mpt_do_ioc_recovery at any instant in time.
  4660. */
  4661. spin_lock_irqsave(&ioc->diagLock, flags);
  4662. if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)){
  4663. spin_unlock_irqrestore(&ioc->diagLock, flags);
  4664. return 0;
  4665. } else {
  4666. ioc->diagPending = 1;
  4667. }
  4668. spin_unlock_irqrestore(&ioc->diagLock, flags);
  4669. /* FIXME: If do_ioc_recovery fails, repeat....
  4670. */
  4671. /* The SCSI driver needs to adjust timeouts on all current
  4672. * commands prior to the diagnostic reset being issued.
  4673. * Prevents timeouts occuring during a diagnostic reset...very bad.
  4674. * For all other protocol drivers, this is a no-op.
  4675. */
  4676. {
  4677. int ii;
  4678. int r = 0;
  4679. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  4680. if (MptResetHandlers[ii]) {
  4681. dtmprintk((MYIOC_s_INFO_FMT "Calling IOC reset_setup handler #%d\n",
  4682. ioc->name, ii));
  4683. r += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_SETUP_RESET);
  4684. if (ioc->alt_ioc) {
  4685. dtmprintk((MYIOC_s_INFO_FMT "Calling alt-%s setup reset handler #%d\n",
  4686. ioc->name, ioc->alt_ioc->name, ii));
  4687. r += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_SETUP_RESET);
  4688. }
  4689. }
  4690. }
  4691. }
  4692. if ((rc = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_RECOVER, sleepFlag)) != 0) {
  4693. printk(KERN_WARNING MYNAM ": WARNING - (%d) Cannot recover %s\n",
  4694. rc, ioc->name);
  4695. }
  4696. ioc->reload_fw = 0;
  4697. if (ioc->alt_ioc)
  4698. ioc->alt_ioc->reload_fw = 0;
  4699. spin_lock_irqsave(&ioc->diagLock, flags);
  4700. ioc->diagPending = 0;
  4701. if (ioc->alt_ioc)
  4702. ioc->alt_ioc->diagPending = 0;
  4703. spin_unlock_irqrestore(&ioc->diagLock, flags);
  4704. dtmprintk((MYIOC_s_INFO_FMT "HardResetHandler rc = %d!\n", ioc->name, rc));
  4705. return rc;
  4706. }
  4707. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4708. static char *
  4709. EventDescriptionStr(u8 event, u32 evData0)
  4710. {
  4711. char *ds;
  4712. switch(event) {
  4713. case MPI_EVENT_NONE:
  4714. ds = "None";
  4715. break;
  4716. case MPI_EVENT_LOG_DATA:
  4717. ds = "Log Data";
  4718. break;
  4719. case MPI_EVENT_STATE_CHANGE:
  4720. ds = "State Change";
  4721. break;
  4722. case MPI_EVENT_UNIT_ATTENTION:
  4723. ds = "Unit Attention";
  4724. break;
  4725. case MPI_EVENT_IOC_BUS_RESET:
  4726. ds = "IOC Bus Reset";
  4727. break;
  4728. case MPI_EVENT_EXT_BUS_RESET:
  4729. ds = "External Bus Reset";
  4730. break;
  4731. case MPI_EVENT_RESCAN:
  4732. ds = "Bus Rescan Event";
  4733. /* Ok, do we need to do anything here? As far as
  4734. I can tell, this is when a new device gets added
  4735. to the loop. */
  4736. break;
  4737. case MPI_EVENT_LINK_STATUS_CHANGE:
  4738. if (evData0 == MPI_EVENT_LINK_STATUS_FAILURE)
  4739. ds = "Link Status(FAILURE) Change";
  4740. else
  4741. ds = "Link Status(ACTIVE) Change";
  4742. break;
  4743. case MPI_EVENT_LOOP_STATE_CHANGE:
  4744. if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LIP)
  4745. ds = "Loop State(LIP) Change";
  4746. else if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LPE)
  4747. ds = "Loop State(LPE) Change"; /* ??? */
  4748. else
  4749. ds = "Loop State(LPB) Change"; /* ??? */
  4750. break;
  4751. case MPI_EVENT_LOGOUT:
  4752. ds = "Logout";
  4753. break;
  4754. case MPI_EVENT_EVENT_CHANGE:
  4755. if (evData0)
  4756. ds = "Events(ON) Change";
  4757. else
  4758. ds = "Events(OFF) Change";
  4759. break;
  4760. case MPI_EVENT_INTEGRATED_RAID:
  4761. ds = "Integrated Raid";
  4762. break;
  4763. /*
  4764. * MPT base "custom" events may be added here...
  4765. */
  4766. default:
  4767. ds = "Unknown";
  4768. break;
  4769. }
  4770. return ds;
  4771. }
  4772. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4773. /*
  4774. * ProcessEventNotification - Route a received EventNotificationReply to
  4775. * all currently regeistered event handlers.
  4776. * @ioc: Pointer to MPT_ADAPTER structure
  4777. * @pEventReply: Pointer to EventNotification reply frame
  4778. * @evHandlers: Pointer to integer, number of event handlers
  4779. *
  4780. * Returns sum of event handlers return values.
  4781. */
  4782. static int
  4783. ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply, int *evHandlers)
  4784. {
  4785. u16 evDataLen;
  4786. u32 evData0 = 0;
  4787. // u32 evCtx;
  4788. int ii;
  4789. int r = 0;
  4790. int handlers = 0;
  4791. char *evStr;
  4792. u8 event;
  4793. /*
  4794. * Do platform normalization of values
  4795. */
  4796. event = le32_to_cpu(pEventReply->Event) & 0xFF;
  4797. // evCtx = le32_to_cpu(pEventReply->EventContext);
  4798. evDataLen = le16_to_cpu(pEventReply->EventDataLength);
  4799. if (evDataLen) {
  4800. evData0 = le32_to_cpu(pEventReply->Data[0]);
  4801. }
  4802. evStr = EventDescriptionStr(event, evData0);
  4803. devtprintk((MYIOC_s_INFO_FMT "MPT event (%s=%02Xh) detected!\n",
  4804. ioc->name,
  4805. evStr,
  4806. event));
  4807. #if defined(MPT_DEBUG) || defined(MPT_DEBUG_EVENTS)
  4808. printk(KERN_INFO MYNAM ": Event data:\n" KERN_INFO);
  4809. for (ii = 0; ii < evDataLen; ii++)
  4810. printk(" %08x", le32_to_cpu(pEventReply->Data[ii]));
  4811. printk("\n");
  4812. #endif
  4813. /*
  4814. * Do general / base driver event processing
  4815. */
  4816. switch(event) {
  4817. case MPI_EVENT_NONE: /* 00 */
  4818. case MPI_EVENT_LOG_DATA: /* 01 */
  4819. case MPI_EVENT_STATE_CHANGE: /* 02 */
  4820. case MPI_EVENT_UNIT_ATTENTION: /* 03 */
  4821. case MPI_EVENT_IOC_BUS_RESET: /* 04 */
  4822. case MPI_EVENT_EXT_BUS_RESET: /* 05 */
  4823. case MPI_EVENT_RESCAN: /* 06 */
  4824. case MPI_EVENT_LINK_STATUS_CHANGE: /* 07 */
  4825. case MPI_EVENT_LOOP_STATE_CHANGE: /* 08 */
  4826. case MPI_EVENT_LOGOUT: /* 09 */
  4827. case MPI_EVENT_INTEGRATED_RAID: /* 0B */
  4828. case MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE: /* 0C */
  4829. default:
  4830. break;
  4831. case MPI_EVENT_EVENT_CHANGE: /* 0A */
  4832. if (evDataLen) {
  4833. u8 evState = evData0 & 0xFF;
  4834. /* CHECKME! What if evState unexpectedly says OFF (0)? */
  4835. /* Update EventState field in cached IocFacts */
  4836. if (ioc->facts.Function) {
  4837. ioc->facts.EventState = evState;
  4838. }
  4839. }
  4840. break;
  4841. }
  4842. /*
  4843. * Should this event be logged? Events are written sequentially.
  4844. * When buffer is full, start again at the top.
  4845. */
  4846. if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
  4847. int idx;
  4848. idx = ioc->eventContext % ioc->eventLogSize;
  4849. ioc->events[idx].event = event;
  4850. ioc->events[idx].eventContext = ioc->eventContext;
  4851. for (ii = 0; ii < 2; ii++) {
  4852. if (ii < evDataLen)
  4853. ioc->events[idx].data[ii] = le32_to_cpu(pEventReply->Data[ii]);
  4854. else
  4855. ioc->events[idx].data[ii] = 0;
  4856. }
  4857. ioc->eventContext++;
  4858. }
  4859. /*
  4860. * Call each currently registered protocol event handler.
  4861. */
  4862. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  4863. if (MptEvHandlers[ii]) {
  4864. devtprintk((MYIOC_s_INFO_FMT "Routing Event to event handler #%d\n",
  4865. ioc->name, ii));
  4866. r += (*(MptEvHandlers[ii]))(ioc, pEventReply);
  4867. handlers++;
  4868. }
  4869. }
  4870. /* FIXME? Examine results here? */
  4871. /*
  4872. * If needed, send (a single) EventAck.
  4873. */
  4874. if (pEventReply->AckRequired == MPI_EVENT_NOTIFICATION_ACK_REQUIRED) {
  4875. if ((ii = SendEventAck(ioc, pEventReply)) != 0) {
  4876. devtprintk((MYIOC_s_WARN_FMT "SendEventAck returned %d\n",
  4877. ioc->name, ii));
  4878. }
  4879. }
  4880. *evHandlers = handlers;
  4881. return r;
  4882. }
  4883. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4884. /*
  4885. * mpt_fc_log_info - Log information returned from Fibre Channel IOC.
  4886. * @ioc: Pointer to MPT_ADAPTER structure
  4887. * @log_info: U32 LogInfo reply word from the IOC
  4888. *
  4889. * Refer to lsi/fc_log.h.
  4890. */
  4891. static void
  4892. mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info)
  4893. {
  4894. static char *subcl_str[8] = {
  4895. "FCP Initiator", "FCP Target", "LAN", "MPI Message Layer",
  4896. "FC Link", "Context Manager", "Invalid Field Offset", "State Change Info"
  4897. };
  4898. u8 subcl = (log_info >> 24) & 0x7;
  4899. printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): SubCl={%s}\n",
  4900. ioc->name, log_info, subcl_str[subcl]);
  4901. }
  4902. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4903. /*
  4904. * mpt_sp_log_info - Log information returned from SCSI Parallel IOC.
  4905. * @ioc: Pointer to MPT_ADAPTER structure
  4906. * @mr: Pointer to MPT reply frame
  4907. * @log_info: U32 LogInfo word from the IOC
  4908. *
  4909. * Refer to lsi/sp_log.h.
  4910. */
  4911. static void
  4912. mpt_sp_log_info(MPT_ADAPTER *ioc, u32 log_info)
  4913. {
  4914. u32 info = log_info & 0x00FF0000;
  4915. char *desc = "unknown";
  4916. switch (info) {
  4917. case 0x00010000:
  4918. desc = "bug! MID not found";
  4919. if (ioc->reload_fw == 0)
  4920. ioc->reload_fw++;
  4921. break;
  4922. case 0x00020000:
  4923. desc = "Parity Error";
  4924. break;
  4925. case 0x00030000:
  4926. desc = "ASYNC Outbound Overrun";
  4927. break;
  4928. case 0x00040000:
  4929. desc = "SYNC Offset Error";
  4930. break;
  4931. case 0x00050000:
  4932. desc = "BM Change";
  4933. break;
  4934. case 0x00060000:
  4935. desc = "Msg In Overflow";
  4936. break;
  4937. case 0x00070000:
  4938. desc = "DMA Error";
  4939. break;
  4940. case 0x00080000:
  4941. desc = "Outbound DMA Overrun";
  4942. break;
  4943. case 0x00090000:
  4944. desc = "Task Management";
  4945. break;
  4946. case 0x000A0000:
  4947. desc = "Device Problem";
  4948. break;
  4949. case 0x000B0000:
  4950. desc = "Invalid Phase Change";
  4951. break;
  4952. case 0x000C0000:
  4953. desc = "Untagged Table Size";
  4954. break;
  4955. }
  4956. printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): F/W: %s\n", ioc->name, log_info, desc);
  4957. }
  4958. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4959. /*
  4960. * mpt_sp_ioc_info - IOC information returned from SCSI Parallel IOC.
  4961. * @ioc: Pointer to MPT_ADAPTER structure
  4962. * @ioc_status: U32 IOCStatus word from IOC
  4963. * @mf: Pointer to MPT request frame
  4964. *
  4965. * Refer to lsi/mpi.h.
  4966. */
  4967. static void
  4968. mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
  4969. {
  4970. u32 status = ioc_status & MPI_IOCSTATUS_MASK;
  4971. char *desc = "";
  4972. switch (status) {
  4973. case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
  4974. desc = "Invalid Function";
  4975. break;
  4976. case MPI_IOCSTATUS_BUSY: /* 0x0002 */
  4977. desc = "Busy";
  4978. break;
  4979. case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
  4980. desc = "Invalid SGL";
  4981. break;
  4982. case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
  4983. desc = "Internal Error";
  4984. break;
  4985. case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
  4986. desc = "Reserved";
  4987. break;
  4988. case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
  4989. desc = "Insufficient Resources";
  4990. break;
  4991. case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
  4992. desc = "Invalid Field";
  4993. break;
  4994. case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
  4995. desc = "Invalid State";
  4996. break;
  4997. case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
  4998. case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
  4999. case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
  5000. case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
  5001. case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
  5002. case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
  5003. /* No message for Config IOCStatus values */
  5004. break;
  5005. case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
  5006. /* No message for recovered error
  5007. desc = "SCSI Recovered Error";
  5008. */
  5009. break;
  5010. case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
  5011. desc = "SCSI Invalid Bus";
  5012. break;
  5013. case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
  5014. desc = "SCSI Invalid TargetID";
  5015. break;
  5016. case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
  5017. {
  5018. SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
  5019. U8 cdb = pScsiReq->CDB[0];
  5020. if (cdb != 0x12) { /* Inquiry is issued for device scanning */
  5021. desc = "SCSI Device Not There";
  5022. }
  5023. break;
  5024. }
  5025. case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
  5026. desc = "SCSI Data Overrun";
  5027. break;
  5028. case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
  5029. /* This error is checked in scsi_io_done(). Skip.
  5030. desc = "SCSI Data Underrun";
  5031. */
  5032. break;
  5033. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  5034. desc = "SCSI I/O Data Error";
  5035. break;
  5036. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  5037. desc = "SCSI Protocol Error";
  5038. break;
  5039. case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
  5040. desc = "SCSI Task Terminated";
  5041. break;
  5042. case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
  5043. desc = "SCSI Residual Mismatch";
  5044. break;
  5045. case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
  5046. desc = "SCSI Task Management Failed";
  5047. break;
  5048. case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
  5049. desc = "SCSI IOC Terminated";
  5050. break;
  5051. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  5052. desc = "SCSI Ext Terminated";
  5053. break;
  5054. default:
  5055. desc = "Others";
  5056. break;
  5057. }
  5058. if (desc != "")
  5059. printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04x): %s\n", ioc->name, status, desc);
  5060. }
  5061. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5062. EXPORT_SYMBOL(ioc_list);
  5063. EXPORT_SYMBOL(mpt_proc_root_dir);
  5064. EXPORT_SYMBOL(mpt_register);
  5065. EXPORT_SYMBOL(mpt_deregister);
  5066. EXPORT_SYMBOL(mpt_event_register);
  5067. EXPORT_SYMBOL(mpt_event_deregister);
  5068. EXPORT_SYMBOL(mpt_reset_register);
  5069. EXPORT_SYMBOL(mpt_reset_deregister);
  5070. EXPORT_SYMBOL(mpt_device_driver_register);
  5071. EXPORT_SYMBOL(mpt_device_driver_deregister);
  5072. EXPORT_SYMBOL(mpt_get_msg_frame);
  5073. EXPORT_SYMBOL(mpt_put_msg_frame);
  5074. EXPORT_SYMBOL(mpt_free_msg_frame);
  5075. EXPORT_SYMBOL(mpt_add_sge);
  5076. EXPORT_SYMBOL(mpt_send_handshake_request);
  5077. EXPORT_SYMBOL(mpt_verify_adapter);
  5078. EXPORT_SYMBOL(mpt_GetIocState);
  5079. EXPORT_SYMBOL(mpt_print_ioc_summary);
  5080. EXPORT_SYMBOL(mpt_lan_index);
  5081. EXPORT_SYMBOL(mpt_stm_index);
  5082. EXPORT_SYMBOL(mpt_HardResetHandler);
  5083. EXPORT_SYMBOL(mpt_config);
  5084. EXPORT_SYMBOL(mpt_toolbox);
  5085. EXPORT_SYMBOL(mpt_findImVolumes);
  5086. EXPORT_SYMBOL(mpt_read_ioc_pg_3);
  5087. EXPORT_SYMBOL(mpt_alloc_fw_memory);
  5088. EXPORT_SYMBOL(mpt_free_fw_memory);
  5089. static struct pci_driver mptbase_driver = {
  5090. .name = "mptbase",
  5091. .id_table = mptbase_pci_table,
  5092. .probe = mptbase_probe,
  5093. .remove = __devexit_p(mptbase_remove),
  5094. .driver = {
  5095. .shutdown = mptbase_shutdown,
  5096. },
  5097. #ifdef CONFIG_PM
  5098. .suspend = mptbase_suspend,
  5099. .resume = mptbase_resume,
  5100. #endif
  5101. };
  5102. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5103. /*
  5104. * fusion_init - Fusion MPT base driver initialization routine.
  5105. *
  5106. * Returns 0 for success, non-zero for failure.
  5107. */
  5108. static int __init
  5109. fusion_init(void)
  5110. {
  5111. int i;
  5112. int r;
  5113. show_mptmod_ver(my_NAME, my_VERSION);
  5114. printk(KERN_INFO COPYRIGHT "\n");
  5115. for (i = 0; i < MPT_MAX_PROTOCOL_DRIVERS; i++) {
  5116. MptCallbacks[i] = NULL;
  5117. MptDriverClass[i] = MPTUNKNOWN_DRIVER;
  5118. MptEvHandlers[i] = NULL;
  5119. MptResetHandlers[i] = NULL;
  5120. }
  5121. /* NEW! 20010120 -sralston
  5122. * Register ourselves (mptbase) in order to facilitate
  5123. * EventNotification handling.
  5124. */
  5125. mpt_base_index = mpt_register(mpt_base_reply, MPTBASE_DRIVER);
  5126. /* Register for hard reset handling callbacks.
  5127. */
  5128. if (mpt_reset_register(mpt_base_index, mpt_ioc_reset) == 0) {
  5129. dprintk((KERN_INFO MYNAM ": Register for IOC reset notification\n"));
  5130. } else {
  5131. /* FIXME! */
  5132. }
  5133. #ifdef CONFIG_PROC_FS
  5134. (void) procmpt_create();
  5135. #endif
  5136. r = pci_register_driver(&mptbase_driver);
  5137. if(r)
  5138. return(r);
  5139. return r;
  5140. }
  5141. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5142. /*
  5143. * fusion_exit - Perform driver unload cleanup.
  5144. *
  5145. * This routine frees all resources associated with each MPT adapter
  5146. * and removes all %MPT_PROCFS_MPTBASEDIR entries.
  5147. */
  5148. static void __exit
  5149. fusion_exit(void)
  5150. {
  5151. dexitprintk((KERN_INFO MYNAM ": fusion_exit() called!\n"));
  5152. pci_unregister_driver(&mptbase_driver);
  5153. mpt_reset_deregister(mpt_base_index);
  5154. #ifdef CONFIG_PROC_FS
  5155. procmpt_destroy();
  5156. #endif
  5157. }
  5158. module_init(fusion_init);
  5159. module_exit(fusion_exit);