mptbase.c 209 KB

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