mptbase.c 237 KB

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