mptbase.c 204 KB

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