mptbase.c 209 KB

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