mptbase.c 237 KB

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