mptbase.c 164 KB

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