mptbase.c 214 KB

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