mptbase.c 181 KB

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