mptbase.c 211 KB

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