mptbase.c 199 KB

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