mptbase.c 222 KB

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