DAC960.c 260 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236
  1. /*
  2. Linux Driver for Mylex DAC960/AcceleRAID/eXtremeRAID PCI RAID Controllers
  3. Copyright 1998-2001 by Leonard N. Zubkoff <lnz@dandelion.com>
  4. Portions Copyright 2002 by Mylex (An IBM Business Unit)
  5. This program is free software; you may redistribute and/or modify it under
  6. the terms of the GNU General Public License Version 2 as published by the
  7. Free Software Foundation.
  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
  10. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for complete details.
  12. */
  13. #define DAC960_DriverVersion "2.5.49"
  14. #define DAC960_DriverDate "21 Aug 2007"
  15. #include <linux/module.h>
  16. #include <linux/types.h>
  17. #include <linux/miscdevice.h>
  18. #include <linux/blkdev.h>
  19. #include <linux/bio.h>
  20. #include <linux/completion.h>
  21. #include <linux/delay.h>
  22. #include <linux/genhd.h>
  23. #include <linux/hdreg.h>
  24. #include <linux/blkpg.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/ioport.h>
  28. #include <linux/mm.h>
  29. #include <linux/slab.h>
  30. #include <linux/smp_lock.h>
  31. #include <linux/proc_fs.h>
  32. #include <linux/seq_file.h>
  33. #include <linux/reboot.h>
  34. #include <linux/spinlock.h>
  35. #include <linux/timer.h>
  36. #include <linux/pci.h>
  37. #include <linux/init.h>
  38. #include <linux/jiffies.h>
  39. #include <linux/random.h>
  40. #include <linux/scatterlist.h>
  41. #include <asm/io.h>
  42. #include <asm/uaccess.h>
  43. #include "DAC960.h"
  44. #define DAC960_GAM_MINOR 252
  45. static DAC960_Controller_T *DAC960_Controllers[DAC960_MaxControllers];
  46. static int DAC960_ControllerCount;
  47. static struct proc_dir_entry *DAC960_ProcDirectoryEntry;
  48. static long disk_size(DAC960_Controller_T *p, int drive_nr)
  49. {
  50. if (p->FirmwareType == DAC960_V1_Controller) {
  51. if (drive_nr >= p->LogicalDriveCount)
  52. return 0;
  53. return p->V1.LogicalDriveInformation[drive_nr].
  54. LogicalDriveSize;
  55. } else {
  56. DAC960_V2_LogicalDeviceInfo_T *i =
  57. p->V2.LogicalDeviceInformation[drive_nr];
  58. if (i == NULL)
  59. return 0;
  60. return i->ConfigurableDeviceSize;
  61. }
  62. }
  63. static int DAC960_open(struct block_device *bdev, fmode_t mode)
  64. {
  65. struct gendisk *disk = bdev->bd_disk;
  66. DAC960_Controller_T *p = disk->queue->queuedata;
  67. int drive_nr = (long)disk->private_data;
  68. if (p->FirmwareType == DAC960_V1_Controller) {
  69. if (p->V1.LogicalDriveInformation[drive_nr].
  70. LogicalDriveState == DAC960_V1_LogicalDrive_Offline)
  71. return -ENXIO;
  72. } else {
  73. DAC960_V2_LogicalDeviceInfo_T *i =
  74. p->V2.LogicalDeviceInformation[drive_nr];
  75. if (!i || i->LogicalDeviceState == DAC960_V2_LogicalDevice_Offline)
  76. return -ENXIO;
  77. }
  78. check_disk_change(bdev);
  79. if (!get_capacity(p->disks[drive_nr]))
  80. return -ENXIO;
  81. return 0;
  82. }
  83. static int DAC960_getgeo(struct block_device *bdev, struct hd_geometry *geo)
  84. {
  85. struct gendisk *disk = bdev->bd_disk;
  86. DAC960_Controller_T *p = disk->queue->queuedata;
  87. int drive_nr = (long)disk->private_data;
  88. if (p->FirmwareType == DAC960_V1_Controller) {
  89. geo->heads = p->V1.GeometryTranslationHeads;
  90. geo->sectors = p->V1.GeometryTranslationSectors;
  91. geo->cylinders = p->V1.LogicalDriveInformation[drive_nr].
  92. LogicalDriveSize / (geo->heads * geo->sectors);
  93. } else {
  94. DAC960_V2_LogicalDeviceInfo_T *i =
  95. p->V2.LogicalDeviceInformation[drive_nr];
  96. switch (i->DriveGeometry) {
  97. case DAC960_V2_Geometry_128_32:
  98. geo->heads = 128;
  99. geo->sectors = 32;
  100. break;
  101. case DAC960_V2_Geometry_255_63:
  102. geo->heads = 255;
  103. geo->sectors = 63;
  104. break;
  105. default:
  106. DAC960_Error("Illegal Logical Device Geometry %d\n",
  107. p, i->DriveGeometry);
  108. return -EINVAL;
  109. }
  110. geo->cylinders = i->ConfigurableDeviceSize /
  111. (geo->heads * geo->sectors);
  112. }
  113. return 0;
  114. }
  115. static int DAC960_media_changed(struct gendisk *disk)
  116. {
  117. DAC960_Controller_T *p = disk->queue->queuedata;
  118. int drive_nr = (long)disk->private_data;
  119. if (!p->LogicalDriveInitiallyAccessible[drive_nr])
  120. return 1;
  121. return 0;
  122. }
  123. static int DAC960_revalidate_disk(struct gendisk *disk)
  124. {
  125. DAC960_Controller_T *p = disk->queue->queuedata;
  126. int unit = (long)disk->private_data;
  127. set_capacity(disk, disk_size(p, unit));
  128. return 0;
  129. }
  130. static const struct block_device_operations DAC960_BlockDeviceOperations = {
  131. .owner = THIS_MODULE,
  132. .open = DAC960_open,
  133. .getgeo = DAC960_getgeo,
  134. .media_changed = DAC960_media_changed,
  135. .revalidate_disk = DAC960_revalidate_disk,
  136. };
  137. /*
  138. DAC960_AnnounceDriver announces the Driver Version and Date, Author's Name,
  139. Copyright Notice, and Electronic Mail Address.
  140. */
  141. static void DAC960_AnnounceDriver(DAC960_Controller_T *Controller)
  142. {
  143. DAC960_Announce("***** DAC960 RAID Driver Version "
  144. DAC960_DriverVersion " of "
  145. DAC960_DriverDate " *****\n", Controller);
  146. DAC960_Announce("Copyright 1998-2001 by Leonard N. Zubkoff "
  147. "<lnz@dandelion.com>\n", Controller);
  148. }
  149. /*
  150. DAC960_Failure prints a standardized error message, and then returns false.
  151. */
  152. static bool DAC960_Failure(DAC960_Controller_T *Controller,
  153. unsigned char *ErrorMessage)
  154. {
  155. DAC960_Error("While configuring DAC960 PCI RAID Controller at\n",
  156. Controller);
  157. if (Controller->IO_Address == 0)
  158. DAC960_Error("PCI Bus %d Device %d Function %d I/O Address N/A "
  159. "PCI Address 0x%X\n", Controller,
  160. Controller->Bus, Controller->Device,
  161. Controller->Function, Controller->PCI_Address);
  162. else DAC960_Error("PCI Bus %d Device %d Function %d I/O Address "
  163. "0x%X PCI Address 0x%X\n", Controller,
  164. Controller->Bus, Controller->Device,
  165. Controller->Function, Controller->IO_Address,
  166. Controller->PCI_Address);
  167. DAC960_Error("%s FAILED - DETACHING\n", Controller, ErrorMessage);
  168. return false;
  169. }
  170. /*
  171. init_dma_loaf() and slice_dma_loaf() are helper functions for
  172. aggregating the dma-mapped memory for a well-known collection of
  173. data structures that are of different lengths.
  174. These routines don't guarantee any alignment. The caller must
  175. include any space needed for alignment in the sizes of the structures
  176. that are passed in.
  177. */
  178. static bool init_dma_loaf(struct pci_dev *dev, struct dma_loaf *loaf,
  179. size_t len)
  180. {
  181. void *cpu_addr;
  182. dma_addr_t dma_handle;
  183. cpu_addr = pci_alloc_consistent(dev, len, &dma_handle);
  184. if (cpu_addr == NULL)
  185. return false;
  186. loaf->cpu_free = loaf->cpu_base = cpu_addr;
  187. loaf->dma_free =loaf->dma_base = dma_handle;
  188. loaf->length = len;
  189. memset(cpu_addr, 0, len);
  190. return true;
  191. }
  192. static void *slice_dma_loaf(struct dma_loaf *loaf, size_t len,
  193. dma_addr_t *dma_handle)
  194. {
  195. void *cpu_end = loaf->cpu_free + len;
  196. void *cpu_addr = loaf->cpu_free;
  197. BUG_ON(cpu_end > loaf->cpu_base + loaf->length);
  198. *dma_handle = loaf->dma_free;
  199. loaf->cpu_free = cpu_end;
  200. loaf->dma_free += len;
  201. return cpu_addr;
  202. }
  203. static void free_dma_loaf(struct pci_dev *dev, struct dma_loaf *loaf_handle)
  204. {
  205. if (loaf_handle->cpu_base != NULL)
  206. pci_free_consistent(dev, loaf_handle->length,
  207. loaf_handle->cpu_base, loaf_handle->dma_base);
  208. }
  209. /*
  210. DAC960_CreateAuxiliaryStructures allocates and initializes the auxiliary
  211. data structures for Controller. It returns true on success and false on
  212. failure.
  213. */
  214. static bool DAC960_CreateAuxiliaryStructures(DAC960_Controller_T *Controller)
  215. {
  216. int CommandAllocationLength, CommandAllocationGroupSize;
  217. int CommandsRemaining = 0, CommandIdentifier, CommandGroupByteCount;
  218. void *AllocationPointer = NULL;
  219. void *ScatterGatherCPU = NULL;
  220. dma_addr_t ScatterGatherDMA;
  221. struct pci_pool *ScatterGatherPool;
  222. void *RequestSenseCPU = NULL;
  223. dma_addr_t RequestSenseDMA;
  224. struct pci_pool *RequestSensePool = NULL;
  225. if (Controller->FirmwareType == DAC960_V1_Controller)
  226. {
  227. CommandAllocationLength = offsetof(DAC960_Command_T, V1.EndMarker);
  228. CommandAllocationGroupSize = DAC960_V1_CommandAllocationGroupSize;
  229. ScatterGatherPool = pci_pool_create("DAC960_V1_ScatterGather",
  230. Controller->PCIDevice,
  231. DAC960_V1_ScatterGatherLimit * sizeof(DAC960_V1_ScatterGatherSegment_T),
  232. sizeof(DAC960_V1_ScatterGatherSegment_T), 0);
  233. if (ScatterGatherPool == NULL)
  234. return DAC960_Failure(Controller,
  235. "AUXILIARY STRUCTURE CREATION (SG)");
  236. Controller->ScatterGatherPool = ScatterGatherPool;
  237. }
  238. else
  239. {
  240. CommandAllocationLength = offsetof(DAC960_Command_T, V2.EndMarker);
  241. CommandAllocationGroupSize = DAC960_V2_CommandAllocationGroupSize;
  242. ScatterGatherPool = pci_pool_create("DAC960_V2_ScatterGather",
  243. Controller->PCIDevice,
  244. DAC960_V2_ScatterGatherLimit * sizeof(DAC960_V2_ScatterGatherSegment_T),
  245. sizeof(DAC960_V2_ScatterGatherSegment_T), 0);
  246. if (ScatterGatherPool == NULL)
  247. return DAC960_Failure(Controller,
  248. "AUXILIARY STRUCTURE CREATION (SG)");
  249. RequestSensePool = pci_pool_create("DAC960_V2_RequestSense",
  250. Controller->PCIDevice, sizeof(DAC960_SCSI_RequestSense_T),
  251. sizeof(int), 0);
  252. if (RequestSensePool == NULL) {
  253. pci_pool_destroy(ScatterGatherPool);
  254. return DAC960_Failure(Controller,
  255. "AUXILIARY STRUCTURE CREATION (SG)");
  256. }
  257. Controller->ScatterGatherPool = ScatterGatherPool;
  258. Controller->V2.RequestSensePool = RequestSensePool;
  259. }
  260. Controller->CommandAllocationGroupSize = CommandAllocationGroupSize;
  261. Controller->FreeCommands = NULL;
  262. for (CommandIdentifier = 1;
  263. CommandIdentifier <= Controller->DriverQueueDepth;
  264. CommandIdentifier++)
  265. {
  266. DAC960_Command_T *Command;
  267. if (--CommandsRemaining <= 0)
  268. {
  269. CommandsRemaining =
  270. Controller->DriverQueueDepth - CommandIdentifier + 1;
  271. if (CommandsRemaining > CommandAllocationGroupSize)
  272. CommandsRemaining = CommandAllocationGroupSize;
  273. CommandGroupByteCount =
  274. CommandsRemaining * CommandAllocationLength;
  275. AllocationPointer = kzalloc(CommandGroupByteCount, GFP_ATOMIC);
  276. if (AllocationPointer == NULL)
  277. return DAC960_Failure(Controller,
  278. "AUXILIARY STRUCTURE CREATION");
  279. }
  280. Command = (DAC960_Command_T *) AllocationPointer;
  281. AllocationPointer += CommandAllocationLength;
  282. Command->CommandIdentifier = CommandIdentifier;
  283. Command->Controller = Controller;
  284. Command->Next = Controller->FreeCommands;
  285. Controller->FreeCommands = Command;
  286. Controller->Commands[CommandIdentifier-1] = Command;
  287. ScatterGatherCPU = pci_pool_alloc(ScatterGatherPool, GFP_ATOMIC,
  288. &ScatterGatherDMA);
  289. if (ScatterGatherCPU == NULL)
  290. return DAC960_Failure(Controller, "AUXILIARY STRUCTURE CREATION");
  291. if (RequestSensePool != NULL) {
  292. RequestSenseCPU = pci_pool_alloc(RequestSensePool, GFP_ATOMIC,
  293. &RequestSenseDMA);
  294. if (RequestSenseCPU == NULL) {
  295. pci_pool_free(ScatterGatherPool, ScatterGatherCPU,
  296. ScatterGatherDMA);
  297. return DAC960_Failure(Controller,
  298. "AUXILIARY STRUCTURE CREATION");
  299. }
  300. }
  301. if (Controller->FirmwareType == DAC960_V1_Controller) {
  302. Command->cmd_sglist = Command->V1.ScatterList;
  303. Command->V1.ScatterGatherList =
  304. (DAC960_V1_ScatterGatherSegment_T *)ScatterGatherCPU;
  305. Command->V1.ScatterGatherListDMA = ScatterGatherDMA;
  306. sg_init_table(Command->cmd_sglist, DAC960_V1_ScatterGatherLimit);
  307. } else {
  308. Command->cmd_sglist = Command->V2.ScatterList;
  309. Command->V2.ScatterGatherList =
  310. (DAC960_V2_ScatterGatherSegment_T *)ScatterGatherCPU;
  311. Command->V2.ScatterGatherListDMA = ScatterGatherDMA;
  312. Command->V2.RequestSense =
  313. (DAC960_SCSI_RequestSense_T *)RequestSenseCPU;
  314. Command->V2.RequestSenseDMA = RequestSenseDMA;
  315. sg_init_table(Command->cmd_sglist, DAC960_V2_ScatterGatherLimit);
  316. }
  317. }
  318. return true;
  319. }
  320. /*
  321. DAC960_DestroyAuxiliaryStructures deallocates the auxiliary data
  322. structures for Controller.
  323. */
  324. static void DAC960_DestroyAuxiliaryStructures(DAC960_Controller_T *Controller)
  325. {
  326. int i;
  327. struct pci_pool *ScatterGatherPool = Controller->ScatterGatherPool;
  328. struct pci_pool *RequestSensePool = NULL;
  329. void *ScatterGatherCPU;
  330. dma_addr_t ScatterGatherDMA;
  331. void *RequestSenseCPU;
  332. dma_addr_t RequestSenseDMA;
  333. DAC960_Command_T *CommandGroup = NULL;
  334. if (Controller->FirmwareType == DAC960_V2_Controller)
  335. RequestSensePool = Controller->V2.RequestSensePool;
  336. Controller->FreeCommands = NULL;
  337. for (i = 0; i < Controller->DriverQueueDepth; i++)
  338. {
  339. DAC960_Command_T *Command = Controller->Commands[i];
  340. if (Command == NULL)
  341. continue;
  342. if (Controller->FirmwareType == DAC960_V1_Controller) {
  343. ScatterGatherCPU = (void *)Command->V1.ScatterGatherList;
  344. ScatterGatherDMA = Command->V1.ScatterGatherListDMA;
  345. RequestSenseCPU = NULL;
  346. RequestSenseDMA = (dma_addr_t)0;
  347. } else {
  348. ScatterGatherCPU = (void *)Command->V2.ScatterGatherList;
  349. ScatterGatherDMA = Command->V2.ScatterGatherListDMA;
  350. RequestSenseCPU = (void *)Command->V2.RequestSense;
  351. RequestSenseDMA = Command->V2.RequestSenseDMA;
  352. }
  353. if (ScatterGatherCPU != NULL)
  354. pci_pool_free(ScatterGatherPool, ScatterGatherCPU, ScatterGatherDMA);
  355. if (RequestSenseCPU != NULL)
  356. pci_pool_free(RequestSensePool, RequestSenseCPU, RequestSenseDMA);
  357. if ((Command->CommandIdentifier
  358. % Controller->CommandAllocationGroupSize) == 1) {
  359. /*
  360. * We can't free the group of commands until all of the
  361. * request sense and scatter gather dma structures are free.
  362. * Remember the beginning of the group, but don't free it
  363. * until we've reached the beginning of the next group.
  364. */
  365. kfree(CommandGroup);
  366. CommandGroup = Command;
  367. }
  368. Controller->Commands[i] = NULL;
  369. }
  370. kfree(CommandGroup);
  371. if (Controller->CombinedStatusBuffer != NULL)
  372. {
  373. kfree(Controller->CombinedStatusBuffer);
  374. Controller->CombinedStatusBuffer = NULL;
  375. Controller->CurrentStatusBuffer = NULL;
  376. }
  377. if (ScatterGatherPool != NULL)
  378. pci_pool_destroy(ScatterGatherPool);
  379. if (Controller->FirmwareType == DAC960_V1_Controller)
  380. return;
  381. if (RequestSensePool != NULL)
  382. pci_pool_destroy(RequestSensePool);
  383. for (i = 0; i < DAC960_MaxLogicalDrives; i++) {
  384. kfree(Controller->V2.LogicalDeviceInformation[i]);
  385. Controller->V2.LogicalDeviceInformation[i] = NULL;
  386. }
  387. for (i = 0; i < DAC960_V2_MaxPhysicalDevices; i++)
  388. {
  389. kfree(Controller->V2.PhysicalDeviceInformation[i]);
  390. Controller->V2.PhysicalDeviceInformation[i] = NULL;
  391. kfree(Controller->V2.InquiryUnitSerialNumber[i]);
  392. Controller->V2.InquiryUnitSerialNumber[i] = NULL;
  393. }
  394. }
  395. /*
  396. DAC960_V1_ClearCommand clears critical fields of Command for DAC960 V1
  397. Firmware Controllers.
  398. */
  399. static inline void DAC960_V1_ClearCommand(DAC960_Command_T *Command)
  400. {
  401. DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  402. memset(CommandMailbox, 0, sizeof(DAC960_V1_CommandMailbox_T));
  403. Command->V1.CommandStatus = 0;
  404. }
  405. /*
  406. DAC960_V2_ClearCommand clears critical fields of Command for DAC960 V2
  407. Firmware Controllers.
  408. */
  409. static inline void DAC960_V2_ClearCommand(DAC960_Command_T *Command)
  410. {
  411. DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  412. memset(CommandMailbox, 0, sizeof(DAC960_V2_CommandMailbox_T));
  413. Command->V2.CommandStatus = 0;
  414. }
  415. /*
  416. DAC960_AllocateCommand allocates a Command structure from Controller's
  417. free list. During driver initialization, a special initialization command
  418. has been placed on the free list to guarantee that command allocation can
  419. never fail.
  420. */
  421. static inline DAC960_Command_T *DAC960_AllocateCommand(DAC960_Controller_T
  422. *Controller)
  423. {
  424. DAC960_Command_T *Command = Controller->FreeCommands;
  425. if (Command == NULL) return NULL;
  426. Controller->FreeCommands = Command->Next;
  427. Command->Next = NULL;
  428. return Command;
  429. }
  430. /*
  431. DAC960_DeallocateCommand deallocates Command, returning it to Controller's
  432. free list.
  433. */
  434. static inline void DAC960_DeallocateCommand(DAC960_Command_T *Command)
  435. {
  436. DAC960_Controller_T *Controller = Command->Controller;
  437. Command->Request = NULL;
  438. Command->Next = Controller->FreeCommands;
  439. Controller->FreeCommands = Command;
  440. }
  441. /*
  442. DAC960_WaitForCommand waits for a wake_up on Controller's Command Wait Queue.
  443. */
  444. static void DAC960_WaitForCommand(DAC960_Controller_T *Controller)
  445. {
  446. spin_unlock_irq(&Controller->queue_lock);
  447. __wait_event(Controller->CommandWaitQueue, Controller->FreeCommands);
  448. spin_lock_irq(&Controller->queue_lock);
  449. }
  450. /*
  451. DAC960_GEM_QueueCommand queues Command for DAC960 GEM Series Controllers.
  452. */
  453. static void DAC960_GEM_QueueCommand(DAC960_Command_T *Command)
  454. {
  455. DAC960_Controller_T *Controller = Command->Controller;
  456. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  457. DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  458. DAC960_V2_CommandMailbox_T *NextCommandMailbox =
  459. Controller->V2.NextCommandMailbox;
  460. CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  461. DAC960_GEM_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
  462. if (Controller->V2.PreviousCommandMailbox1->Words[0] == 0 ||
  463. Controller->V2.PreviousCommandMailbox2->Words[0] == 0)
  464. DAC960_GEM_MemoryMailboxNewCommand(ControllerBaseAddress);
  465. Controller->V2.PreviousCommandMailbox2 =
  466. Controller->V2.PreviousCommandMailbox1;
  467. Controller->V2.PreviousCommandMailbox1 = NextCommandMailbox;
  468. if (++NextCommandMailbox > Controller->V2.LastCommandMailbox)
  469. NextCommandMailbox = Controller->V2.FirstCommandMailbox;
  470. Controller->V2.NextCommandMailbox = NextCommandMailbox;
  471. }
  472. /*
  473. DAC960_BA_QueueCommand queues Command for DAC960 BA Series Controllers.
  474. */
  475. static void DAC960_BA_QueueCommand(DAC960_Command_T *Command)
  476. {
  477. DAC960_Controller_T *Controller = Command->Controller;
  478. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  479. DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  480. DAC960_V2_CommandMailbox_T *NextCommandMailbox =
  481. Controller->V2.NextCommandMailbox;
  482. CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  483. DAC960_BA_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
  484. if (Controller->V2.PreviousCommandMailbox1->Words[0] == 0 ||
  485. Controller->V2.PreviousCommandMailbox2->Words[0] == 0)
  486. DAC960_BA_MemoryMailboxNewCommand(ControllerBaseAddress);
  487. Controller->V2.PreviousCommandMailbox2 =
  488. Controller->V2.PreviousCommandMailbox1;
  489. Controller->V2.PreviousCommandMailbox1 = NextCommandMailbox;
  490. if (++NextCommandMailbox > Controller->V2.LastCommandMailbox)
  491. NextCommandMailbox = Controller->V2.FirstCommandMailbox;
  492. Controller->V2.NextCommandMailbox = NextCommandMailbox;
  493. }
  494. /*
  495. DAC960_LP_QueueCommand queues Command for DAC960 LP Series Controllers.
  496. */
  497. static void DAC960_LP_QueueCommand(DAC960_Command_T *Command)
  498. {
  499. DAC960_Controller_T *Controller = Command->Controller;
  500. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  501. DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  502. DAC960_V2_CommandMailbox_T *NextCommandMailbox =
  503. Controller->V2.NextCommandMailbox;
  504. CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  505. DAC960_LP_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
  506. if (Controller->V2.PreviousCommandMailbox1->Words[0] == 0 ||
  507. Controller->V2.PreviousCommandMailbox2->Words[0] == 0)
  508. DAC960_LP_MemoryMailboxNewCommand(ControllerBaseAddress);
  509. Controller->V2.PreviousCommandMailbox2 =
  510. Controller->V2.PreviousCommandMailbox1;
  511. Controller->V2.PreviousCommandMailbox1 = NextCommandMailbox;
  512. if (++NextCommandMailbox > Controller->V2.LastCommandMailbox)
  513. NextCommandMailbox = Controller->V2.FirstCommandMailbox;
  514. Controller->V2.NextCommandMailbox = NextCommandMailbox;
  515. }
  516. /*
  517. DAC960_LA_QueueCommandDualMode queues Command for DAC960 LA Series
  518. Controllers with Dual Mode Firmware.
  519. */
  520. static void DAC960_LA_QueueCommandDualMode(DAC960_Command_T *Command)
  521. {
  522. DAC960_Controller_T *Controller = Command->Controller;
  523. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  524. DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  525. DAC960_V1_CommandMailbox_T *NextCommandMailbox =
  526. Controller->V1.NextCommandMailbox;
  527. CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  528. DAC960_LA_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
  529. if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
  530. Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
  531. DAC960_LA_MemoryMailboxNewCommand(ControllerBaseAddress);
  532. Controller->V1.PreviousCommandMailbox2 =
  533. Controller->V1.PreviousCommandMailbox1;
  534. Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
  535. if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
  536. NextCommandMailbox = Controller->V1.FirstCommandMailbox;
  537. Controller->V1.NextCommandMailbox = NextCommandMailbox;
  538. }
  539. /*
  540. DAC960_LA_QueueCommandSingleMode queues Command for DAC960 LA Series
  541. Controllers with Single Mode Firmware.
  542. */
  543. static void DAC960_LA_QueueCommandSingleMode(DAC960_Command_T *Command)
  544. {
  545. DAC960_Controller_T *Controller = Command->Controller;
  546. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  547. DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  548. DAC960_V1_CommandMailbox_T *NextCommandMailbox =
  549. Controller->V1.NextCommandMailbox;
  550. CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  551. DAC960_LA_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
  552. if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
  553. Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
  554. DAC960_LA_HardwareMailboxNewCommand(ControllerBaseAddress);
  555. Controller->V1.PreviousCommandMailbox2 =
  556. Controller->V1.PreviousCommandMailbox1;
  557. Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
  558. if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
  559. NextCommandMailbox = Controller->V1.FirstCommandMailbox;
  560. Controller->V1.NextCommandMailbox = NextCommandMailbox;
  561. }
  562. /*
  563. DAC960_PG_QueueCommandDualMode queues Command for DAC960 PG Series
  564. Controllers with Dual Mode Firmware.
  565. */
  566. static void DAC960_PG_QueueCommandDualMode(DAC960_Command_T *Command)
  567. {
  568. DAC960_Controller_T *Controller = Command->Controller;
  569. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  570. DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  571. DAC960_V1_CommandMailbox_T *NextCommandMailbox =
  572. Controller->V1.NextCommandMailbox;
  573. CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  574. DAC960_PG_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
  575. if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
  576. Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
  577. DAC960_PG_MemoryMailboxNewCommand(ControllerBaseAddress);
  578. Controller->V1.PreviousCommandMailbox2 =
  579. Controller->V1.PreviousCommandMailbox1;
  580. Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
  581. if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
  582. NextCommandMailbox = Controller->V1.FirstCommandMailbox;
  583. Controller->V1.NextCommandMailbox = NextCommandMailbox;
  584. }
  585. /*
  586. DAC960_PG_QueueCommandSingleMode queues Command for DAC960 PG Series
  587. Controllers with Single Mode Firmware.
  588. */
  589. static void DAC960_PG_QueueCommandSingleMode(DAC960_Command_T *Command)
  590. {
  591. DAC960_Controller_T *Controller = Command->Controller;
  592. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  593. DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  594. DAC960_V1_CommandMailbox_T *NextCommandMailbox =
  595. Controller->V1.NextCommandMailbox;
  596. CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  597. DAC960_PG_WriteCommandMailbox(NextCommandMailbox, CommandMailbox);
  598. if (Controller->V1.PreviousCommandMailbox1->Words[0] == 0 ||
  599. Controller->V1.PreviousCommandMailbox2->Words[0] == 0)
  600. DAC960_PG_HardwareMailboxNewCommand(ControllerBaseAddress);
  601. Controller->V1.PreviousCommandMailbox2 =
  602. Controller->V1.PreviousCommandMailbox1;
  603. Controller->V1.PreviousCommandMailbox1 = NextCommandMailbox;
  604. if (++NextCommandMailbox > Controller->V1.LastCommandMailbox)
  605. NextCommandMailbox = Controller->V1.FirstCommandMailbox;
  606. Controller->V1.NextCommandMailbox = NextCommandMailbox;
  607. }
  608. /*
  609. DAC960_PD_QueueCommand queues Command for DAC960 PD Series Controllers.
  610. */
  611. static void DAC960_PD_QueueCommand(DAC960_Command_T *Command)
  612. {
  613. DAC960_Controller_T *Controller = Command->Controller;
  614. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  615. DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  616. CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  617. while (DAC960_PD_MailboxFullP(ControllerBaseAddress))
  618. udelay(1);
  619. DAC960_PD_WriteCommandMailbox(ControllerBaseAddress, CommandMailbox);
  620. DAC960_PD_NewCommand(ControllerBaseAddress);
  621. }
  622. /*
  623. DAC960_P_QueueCommand queues Command for DAC960 P Series Controllers.
  624. */
  625. static void DAC960_P_QueueCommand(DAC960_Command_T *Command)
  626. {
  627. DAC960_Controller_T *Controller = Command->Controller;
  628. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  629. DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  630. CommandMailbox->Common.CommandIdentifier = Command->CommandIdentifier;
  631. switch (CommandMailbox->Common.CommandOpcode)
  632. {
  633. case DAC960_V1_Enquiry:
  634. CommandMailbox->Common.CommandOpcode = DAC960_V1_Enquiry_Old;
  635. break;
  636. case DAC960_V1_GetDeviceState:
  637. CommandMailbox->Common.CommandOpcode = DAC960_V1_GetDeviceState_Old;
  638. break;
  639. case DAC960_V1_Read:
  640. CommandMailbox->Common.CommandOpcode = DAC960_V1_Read_Old;
  641. DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
  642. break;
  643. case DAC960_V1_Write:
  644. CommandMailbox->Common.CommandOpcode = DAC960_V1_Write_Old;
  645. DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
  646. break;
  647. case DAC960_V1_ReadWithScatterGather:
  648. CommandMailbox->Common.CommandOpcode =
  649. DAC960_V1_ReadWithScatterGather_Old;
  650. DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
  651. break;
  652. case DAC960_V1_WriteWithScatterGather:
  653. CommandMailbox->Common.CommandOpcode =
  654. DAC960_V1_WriteWithScatterGather_Old;
  655. DAC960_PD_To_P_TranslateReadWriteCommand(CommandMailbox);
  656. break;
  657. default:
  658. break;
  659. }
  660. while (DAC960_PD_MailboxFullP(ControllerBaseAddress))
  661. udelay(1);
  662. DAC960_PD_WriteCommandMailbox(ControllerBaseAddress, CommandMailbox);
  663. DAC960_PD_NewCommand(ControllerBaseAddress);
  664. }
  665. /*
  666. DAC960_ExecuteCommand executes Command and waits for completion.
  667. */
  668. static void DAC960_ExecuteCommand(DAC960_Command_T *Command)
  669. {
  670. DAC960_Controller_T *Controller = Command->Controller;
  671. DECLARE_COMPLETION_ONSTACK(Completion);
  672. unsigned long flags;
  673. Command->Completion = &Completion;
  674. spin_lock_irqsave(&Controller->queue_lock, flags);
  675. DAC960_QueueCommand(Command);
  676. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  677. if (in_interrupt())
  678. return;
  679. wait_for_completion(&Completion);
  680. }
  681. /*
  682. DAC960_V1_ExecuteType3 executes a DAC960 V1 Firmware Controller Type 3
  683. Command and waits for completion. It returns true on success and false
  684. on failure.
  685. */
  686. static bool DAC960_V1_ExecuteType3(DAC960_Controller_T *Controller,
  687. DAC960_V1_CommandOpcode_T CommandOpcode,
  688. dma_addr_t DataDMA)
  689. {
  690. DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
  691. DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  692. DAC960_V1_CommandStatus_T CommandStatus;
  693. DAC960_V1_ClearCommand(Command);
  694. Command->CommandType = DAC960_ImmediateCommand;
  695. CommandMailbox->Type3.CommandOpcode = CommandOpcode;
  696. CommandMailbox->Type3.BusAddress = DataDMA;
  697. DAC960_ExecuteCommand(Command);
  698. CommandStatus = Command->V1.CommandStatus;
  699. DAC960_DeallocateCommand(Command);
  700. return (CommandStatus == DAC960_V1_NormalCompletion);
  701. }
  702. /*
  703. DAC960_V1_ExecuteTypeB executes a DAC960 V1 Firmware Controller Type 3B
  704. Command and waits for completion. It returns true on success and false
  705. on failure.
  706. */
  707. static bool DAC960_V1_ExecuteType3B(DAC960_Controller_T *Controller,
  708. DAC960_V1_CommandOpcode_T CommandOpcode,
  709. unsigned char CommandOpcode2,
  710. dma_addr_t DataDMA)
  711. {
  712. DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
  713. DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  714. DAC960_V1_CommandStatus_T CommandStatus;
  715. DAC960_V1_ClearCommand(Command);
  716. Command->CommandType = DAC960_ImmediateCommand;
  717. CommandMailbox->Type3B.CommandOpcode = CommandOpcode;
  718. CommandMailbox->Type3B.CommandOpcode2 = CommandOpcode2;
  719. CommandMailbox->Type3B.BusAddress = DataDMA;
  720. DAC960_ExecuteCommand(Command);
  721. CommandStatus = Command->V1.CommandStatus;
  722. DAC960_DeallocateCommand(Command);
  723. return (CommandStatus == DAC960_V1_NormalCompletion);
  724. }
  725. /*
  726. DAC960_V1_ExecuteType3D executes a DAC960 V1 Firmware Controller Type 3D
  727. Command and waits for completion. It returns true on success and false
  728. on failure.
  729. */
  730. static bool DAC960_V1_ExecuteType3D(DAC960_Controller_T *Controller,
  731. DAC960_V1_CommandOpcode_T CommandOpcode,
  732. unsigned char Channel,
  733. unsigned char TargetID,
  734. dma_addr_t DataDMA)
  735. {
  736. DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
  737. DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  738. DAC960_V1_CommandStatus_T CommandStatus;
  739. DAC960_V1_ClearCommand(Command);
  740. Command->CommandType = DAC960_ImmediateCommand;
  741. CommandMailbox->Type3D.CommandOpcode = CommandOpcode;
  742. CommandMailbox->Type3D.Channel = Channel;
  743. CommandMailbox->Type3D.TargetID = TargetID;
  744. CommandMailbox->Type3D.BusAddress = DataDMA;
  745. DAC960_ExecuteCommand(Command);
  746. CommandStatus = Command->V1.CommandStatus;
  747. DAC960_DeallocateCommand(Command);
  748. return (CommandStatus == DAC960_V1_NormalCompletion);
  749. }
  750. /*
  751. DAC960_V2_GeneralInfo executes a DAC960 V2 Firmware General Information
  752. Reading IOCTL Command and waits for completion. It returns true on success
  753. and false on failure.
  754. Return data in The controller's HealthStatusBuffer, which is dma-able memory
  755. */
  756. static bool DAC960_V2_GeneralInfo(DAC960_Controller_T *Controller)
  757. {
  758. DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
  759. DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  760. DAC960_V2_CommandStatus_T CommandStatus;
  761. DAC960_V2_ClearCommand(Command);
  762. Command->CommandType = DAC960_ImmediateCommand;
  763. CommandMailbox->Common.CommandOpcode = DAC960_V2_IOCTL;
  764. CommandMailbox->Common.CommandControlBits
  765. .DataTransferControllerToHost = true;
  766. CommandMailbox->Common.CommandControlBits
  767. .NoAutoRequestSense = true;
  768. CommandMailbox->Common.DataTransferSize = sizeof(DAC960_V2_HealthStatusBuffer_T);
  769. CommandMailbox->Common.IOCTL_Opcode = DAC960_V2_GetHealthStatus;
  770. CommandMailbox->Common.DataTransferMemoryAddress
  771. .ScatterGatherSegments[0]
  772. .SegmentDataPointer =
  773. Controller->V2.HealthStatusBufferDMA;
  774. CommandMailbox->Common.DataTransferMemoryAddress
  775. .ScatterGatherSegments[0]
  776. .SegmentByteCount =
  777. CommandMailbox->Common.DataTransferSize;
  778. DAC960_ExecuteCommand(Command);
  779. CommandStatus = Command->V2.CommandStatus;
  780. DAC960_DeallocateCommand(Command);
  781. return (CommandStatus == DAC960_V2_NormalCompletion);
  782. }
  783. /*
  784. DAC960_V2_ControllerInfo executes a DAC960 V2 Firmware Controller
  785. Information Reading IOCTL Command and waits for completion. It returns
  786. true on success and false on failure.
  787. Data is returned in the controller's V2.NewControllerInformation dma-able
  788. memory buffer.
  789. */
  790. static bool DAC960_V2_NewControllerInfo(DAC960_Controller_T *Controller)
  791. {
  792. DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
  793. DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  794. DAC960_V2_CommandStatus_T CommandStatus;
  795. DAC960_V2_ClearCommand(Command);
  796. Command->CommandType = DAC960_ImmediateCommand;
  797. CommandMailbox->ControllerInfo.CommandOpcode = DAC960_V2_IOCTL;
  798. CommandMailbox->ControllerInfo.CommandControlBits
  799. .DataTransferControllerToHost = true;
  800. CommandMailbox->ControllerInfo.CommandControlBits
  801. .NoAutoRequestSense = true;
  802. CommandMailbox->ControllerInfo.DataTransferSize = sizeof(DAC960_V2_ControllerInfo_T);
  803. CommandMailbox->ControllerInfo.ControllerNumber = 0;
  804. CommandMailbox->ControllerInfo.IOCTL_Opcode = DAC960_V2_GetControllerInfo;
  805. CommandMailbox->ControllerInfo.DataTransferMemoryAddress
  806. .ScatterGatherSegments[0]
  807. .SegmentDataPointer =
  808. Controller->V2.NewControllerInformationDMA;
  809. CommandMailbox->ControllerInfo.DataTransferMemoryAddress
  810. .ScatterGatherSegments[0]
  811. .SegmentByteCount =
  812. CommandMailbox->ControllerInfo.DataTransferSize;
  813. DAC960_ExecuteCommand(Command);
  814. CommandStatus = Command->V2.CommandStatus;
  815. DAC960_DeallocateCommand(Command);
  816. return (CommandStatus == DAC960_V2_NormalCompletion);
  817. }
  818. /*
  819. DAC960_V2_LogicalDeviceInfo executes a DAC960 V2 Firmware Controller Logical
  820. Device Information Reading IOCTL Command and waits for completion. It
  821. returns true on success and false on failure.
  822. Data is returned in the controller's V2.NewLogicalDeviceInformation
  823. */
  824. static bool DAC960_V2_NewLogicalDeviceInfo(DAC960_Controller_T *Controller,
  825. unsigned short LogicalDeviceNumber)
  826. {
  827. DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
  828. DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  829. DAC960_V2_CommandStatus_T CommandStatus;
  830. DAC960_V2_ClearCommand(Command);
  831. Command->CommandType = DAC960_ImmediateCommand;
  832. CommandMailbox->LogicalDeviceInfo.CommandOpcode =
  833. DAC960_V2_IOCTL;
  834. CommandMailbox->LogicalDeviceInfo.CommandControlBits
  835. .DataTransferControllerToHost = true;
  836. CommandMailbox->LogicalDeviceInfo.CommandControlBits
  837. .NoAutoRequestSense = true;
  838. CommandMailbox->LogicalDeviceInfo.DataTransferSize =
  839. sizeof(DAC960_V2_LogicalDeviceInfo_T);
  840. CommandMailbox->LogicalDeviceInfo.LogicalDevice.LogicalDeviceNumber =
  841. LogicalDeviceNumber;
  842. CommandMailbox->LogicalDeviceInfo.IOCTL_Opcode = DAC960_V2_GetLogicalDeviceInfoValid;
  843. CommandMailbox->LogicalDeviceInfo.DataTransferMemoryAddress
  844. .ScatterGatherSegments[0]
  845. .SegmentDataPointer =
  846. Controller->V2.NewLogicalDeviceInformationDMA;
  847. CommandMailbox->LogicalDeviceInfo.DataTransferMemoryAddress
  848. .ScatterGatherSegments[0]
  849. .SegmentByteCount =
  850. CommandMailbox->LogicalDeviceInfo.DataTransferSize;
  851. DAC960_ExecuteCommand(Command);
  852. CommandStatus = Command->V2.CommandStatus;
  853. DAC960_DeallocateCommand(Command);
  854. return (CommandStatus == DAC960_V2_NormalCompletion);
  855. }
  856. /*
  857. DAC960_V2_PhysicalDeviceInfo executes a DAC960 V2 Firmware Controller "Read
  858. Physical Device Information" IOCTL Command and waits for completion. It
  859. returns true on success and false on failure.
  860. The Channel, TargetID, LogicalUnit arguments should be 0 the first time
  861. this function is called for a given controller. This will return data
  862. for the "first" device on that controller. The returned data includes a
  863. Channel, TargetID, LogicalUnit that can be passed in to this routine to
  864. get data for the NEXT device on that controller.
  865. Data is stored in the controller's V2.NewPhysicalDeviceInfo dma-able
  866. memory buffer.
  867. */
  868. static bool DAC960_V2_NewPhysicalDeviceInfo(DAC960_Controller_T *Controller,
  869. unsigned char Channel,
  870. unsigned char TargetID,
  871. unsigned char LogicalUnit)
  872. {
  873. DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
  874. DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  875. DAC960_V2_CommandStatus_T CommandStatus;
  876. DAC960_V2_ClearCommand(Command);
  877. Command->CommandType = DAC960_ImmediateCommand;
  878. CommandMailbox->PhysicalDeviceInfo.CommandOpcode = DAC960_V2_IOCTL;
  879. CommandMailbox->PhysicalDeviceInfo.CommandControlBits
  880. .DataTransferControllerToHost = true;
  881. CommandMailbox->PhysicalDeviceInfo.CommandControlBits
  882. .NoAutoRequestSense = true;
  883. CommandMailbox->PhysicalDeviceInfo.DataTransferSize =
  884. sizeof(DAC960_V2_PhysicalDeviceInfo_T);
  885. CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.LogicalUnit = LogicalUnit;
  886. CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.TargetID = TargetID;
  887. CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.Channel = Channel;
  888. CommandMailbox->PhysicalDeviceInfo.IOCTL_Opcode =
  889. DAC960_V2_GetPhysicalDeviceInfoValid;
  890. CommandMailbox->PhysicalDeviceInfo.DataTransferMemoryAddress
  891. .ScatterGatherSegments[0]
  892. .SegmentDataPointer =
  893. Controller->V2.NewPhysicalDeviceInformationDMA;
  894. CommandMailbox->PhysicalDeviceInfo.DataTransferMemoryAddress
  895. .ScatterGatherSegments[0]
  896. .SegmentByteCount =
  897. CommandMailbox->PhysicalDeviceInfo.DataTransferSize;
  898. DAC960_ExecuteCommand(Command);
  899. CommandStatus = Command->V2.CommandStatus;
  900. DAC960_DeallocateCommand(Command);
  901. return (CommandStatus == DAC960_V2_NormalCompletion);
  902. }
  903. static void DAC960_V2_ConstructNewUnitSerialNumber(
  904. DAC960_Controller_T *Controller,
  905. DAC960_V2_CommandMailbox_T *CommandMailbox, int Channel, int TargetID,
  906. int LogicalUnit)
  907. {
  908. CommandMailbox->SCSI_10.CommandOpcode = DAC960_V2_SCSI_10_Passthru;
  909. CommandMailbox->SCSI_10.CommandControlBits
  910. .DataTransferControllerToHost = true;
  911. CommandMailbox->SCSI_10.CommandControlBits
  912. .NoAutoRequestSense = true;
  913. CommandMailbox->SCSI_10.DataTransferSize =
  914. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
  915. CommandMailbox->SCSI_10.PhysicalDevice.LogicalUnit = LogicalUnit;
  916. CommandMailbox->SCSI_10.PhysicalDevice.TargetID = TargetID;
  917. CommandMailbox->SCSI_10.PhysicalDevice.Channel = Channel;
  918. CommandMailbox->SCSI_10.CDBLength = 6;
  919. CommandMailbox->SCSI_10.SCSI_CDB[0] = 0x12; /* INQUIRY */
  920. CommandMailbox->SCSI_10.SCSI_CDB[1] = 1; /* EVPD = 1 */
  921. CommandMailbox->SCSI_10.SCSI_CDB[2] = 0x80; /* Page Code */
  922. CommandMailbox->SCSI_10.SCSI_CDB[3] = 0; /* Reserved */
  923. CommandMailbox->SCSI_10.SCSI_CDB[4] =
  924. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
  925. CommandMailbox->SCSI_10.SCSI_CDB[5] = 0; /* Control */
  926. CommandMailbox->SCSI_10.DataTransferMemoryAddress
  927. .ScatterGatherSegments[0]
  928. .SegmentDataPointer =
  929. Controller->V2.NewInquiryUnitSerialNumberDMA;
  930. CommandMailbox->SCSI_10.DataTransferMemoryAddress
  931. .ScatterGatherSegments[0]
  932. .SegmentByteCount =
  933. CommandMailbox->SCSI_10.DataTransferSize;
  934. }
  935. /*
  936. DAC960_V2_NewUnitSerialNumber executes an SCSI pass-through
  937. Inquiry command to a SCSI device identified by Channel number,
  938. Target id, Logical Unit Number. This function Waits for completion
  939. of the command.
  940. The return data includes Unit Serial Number information for the
  941. specified device.
  942. Data is stored in the controller's V2.NewPhysicalDeviceInfo dma-able
  943. memory buffer.
  944. */
  945. static bool DAC960_V2_NewInquiryUnitSerialNumber(DAC960_Controller_T *Controller,
  946. int Channel, int TargetID, int LogicalUnit)
  947. {
  948. DAC960_Command_T *Command;
  949. DAC960_V2_CommandMailbox_T *CommandMailbox;
  950. DAC960_V2_CommandStatus_T CommandStatus;
  951. Command = DAC960_AllocateCommand(Controller);
  952. CommandMailbox = &Command->V2.CommandMailbox;
  953. DAC960_V2_ClearCommand(Command);
  954. Command->CommandType = DAC960_ImmediateCommand;
  955. DAC960_V2_ConstructNewUnitSerialNumber(Controller, CommandMailbox,
  956. Channel, TargetID, LogicalUnit);
  957. DAC960_ExecuteCommand(Command);
  958. CommandStatus = Command->V2.CommandStatus;
  959. DAC960_DeallocateCommand(Command);
  960. return (CommandStatus == DAC960_V2_NormalCompletion);
  961. }
  962. /*
  963. DAC960_V2_DeviceOperation executes a DAC960 V2 Firmware Controller Device
  964. Operation IOCTL Command and waits for completion. It returns true on
  965. success and false on failure.
  966. */
  967. static bool DAC960_V2_DeviceOperation(DAC960_Controller_T *Controller,
  968. DAC960_V2_IOCTL_Opcode_T IOCTL_Opcode,
  969. DAC960_V2_OperationDevice_T
  970. OperationDevice)
  971. {
  972. DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
  973. DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  974. DAC960_V2_CommandStatus_T CommandStatus;
  975. DAC960_V2_ClearCommand(Command);
  976. Command->CommandType = DAC960_ImmediateCommand;
  977. CommandMailbox->DeviceOperation.CommandOpcode = DAC960_V2_IOCTL;
  978. CommandMailbox->DeviceOperation.CommandControlBits
  979. .DataTransferControllerToHost = true;
  980. CommandMailbox->DeviceOperation.CommandControlBits
  981. .NoAutoRequestSense = true;
  982. CommandMailbox->DeviceOperation.IOCTL_Opcode = IOCTL_Opcode;
  983. CommandMailbox->DeviceOperation.OperationDevice = OperationDevice;
  984. DAC960_ExecuteCommand(Command);
  985. CommandStatus = Command->V2.CommandStatus;
  986. DAC960_DeallocateCommand(Command);
  987. return (CommandStatus == DAC960_V2_NormalCompletion);
  988. }
  989. /*
  990. DAC960_V1_EnableMemoryMailboxInterface enables the Memory Mailbox Interface
  991. for DAC960 V1 Firmware Controllers.
  992. PD and P controller types have no memory mailbox, but still need the
  993. other dma mapped memory.
  994. */
  995. static bool DAC960_V1_EnableMemoryMailboxInterface(DAC960_Controller_T
  996. *Controller)
  997. {
  998. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  999. DAC960_HardwareType_T hw_type = Controller->HardwareType;
  1000. struct pci_dev *PCI_Device = Controller->PCIDevice;
  1001. struct dma_loaf *DmaPages = &Controller->DmaPages;
  1002. size_t DmaPagesSize;
  1003. size_t CommandMailboxesSize;
  1004. size_t StatusMailboxesSize;
  1005. DAC960_V1_CommandMailbox_T *CommandMailboxesMemory;
  1006. dma_addr_t CommandMailboxesMemoryDMA;
  1007. DAC960_V1_StatusMailbox_T *StatusMailboxesMemory;
  1008. dma_addr_t StatusMailboxesMemoryDMA;
  1009. DAC960_V1_CommandMailbox_T CommandMailbox;
  1010. DAC960_V1_CommandStatus_T CommandStatus;
  1011. int TimeoutCounter;
  1012. int i;
  1013. if (pci_set_dma_mask(Controller->PCIDevice, DMA_BIT_MASK(32)))
  1014. return DAC960_Failure(Controller, "DMA mask out of range");
  1015. Controller->BounceBufferLimit = DMA_BIT_MASK(32);
  1016. if ((hw_type == DAC960_PD_Controller) || (hw_type == DAC960_P_Controller)) {
  1017. CommandMailboxesSize = 0;
  1018. StatusMailboxesSize = 0;
  1019. } else {
  1020. CommandMailboxesSize = DAC960_V1_CommandMailboxCount * sizeof(DAC960_V1_CommandMailbox_T);
  1021. StatusMailboxesSize = DAC960_V1_StatusMailboxCount * sizeof(DAC960_V1_StatusMailbox_T);
  1022. }
  1023. DmaPagesSize = CommandMailboxesSize + StatusMailboxesSize +
  1024. sizeof(DAC960_V1_DCDB_T) + sizeof(DAC960_V1_Enquiry_T) +
  1025. sizeof(DAC960_V1_ErrorTable_T) + sizeof(DAC960_V1_EventLogEntry_T) +
  1026. sizeof(DAC960_V1_RebuildProgress_T) +
  1027. sizeof(DAC960_V1_LogicalDriveInformationArray_T) +
  1028. sizeof(DAC960_V1_BackgroundInitializationStatus_T) +
  1029. sizeof(DAC960_V1_DeviceState_T) + sizeof(DAC960_SCSI_Inquiry_T) +
  1030. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
  1031. if (!init_dma_loaf(PCI_Device, DmaPages, DmaPagesSize))
  1032. return false;
  1033. if ((hw_type == DAC960_PD_Controller) || (hw_type == DAC960_P_Controller))
  1034. goto skip_mailboxes;
  1035. CommandMailboxesMemory = slice_dma_loaf(DmaPages,
  1036. CommandMailboxesSize, &CommandMailboxesMemoryDMA);
  1037. /* These are the base addresses for the command memory mailbox array */
  1038. Controller->V1.FirstCommandMailbox = CommandMailboxesMemory;
  1039. Controller->V1.FirstCommandMailboxDMA = CommandMailboxesMemoryDMA;
  1040. CommandMailboxesMemory += DAC960_V1_CommandMailboxCount - 1;
  1041. Controller->V1.LastCommandMailbox = CommandMailboxesMemory;
  1042. Controller->V1.NextCommandMailbox = Controller->V1.FirstCommandMailbox;
  1043. Controller->V1.PreviousCommandMailbox1 = Controller->V1.LastCommandMailbox;
  1044. Controller->V1.PreviousCommandMailbox2 =
  1045. Controller->V1.LastCommandMailbox - 1;
  1046. /* These are the base addresses for the status memory mailbox array */
  1047. StatusMailboxesMemory = slice_dma_loaf(DmaPages,
  1048. StatusMailboxesSize, &StatusMailboxesMemoryDMA);
  1049. Controller->V1.FirstStatusMailbox = StatusMailboxesMemory;
  1050. Controller->V1.FirstStatusMailboxDMA = StatusMailboxesMemoryDMA;
  1051. StatusMailboxesMemory += DAC960_V1_StatusMailboxCount - 1;
  1052. Controller->V1.LastStatusMailbox = StatusMailboxesMemory;
  1053. Controller->V1.NextStatusMailbox = Controller->V1.FirstStatusMailbox;
  1054. skip_mailboxes:
  1055. Controller->V1.MonitoringDCDB = slice_dma_loaf(DmaPages,
  1056. sizeof(DAC960_V1_DCDB_T),
  1057. &Controller->V1.MonitoringDCDB_DMA);
  1058. Controller->V1.NewEnquiry = slice_dma_loaf(DmaPages,
  1059. sizeof(DAC960_V1_Enquiry_T),
  1060. &Controller->V1.NewEnquiryDMA);
  1061. Controller->V1.NewErrorTable = slice_dma_loaf(DmaPages,
  1062. sizeof(DAC960_V1_ErrorTable_T),
  1063. &Controller->V1.NewErrorTableDMA);
  1064. Controller->V1.EventLogEntry = slice_dma_loaf(DmaPages,
  1065. sizeof(DAC960_V1_EventLogEntry_T),
  1066. &Controller->V1.EventLogEntryDMA);
  1067. Controller->V1.RebuildProgress = slice_dma_loaf(DmaPages,
  1068. sizeof(DAC960_V1_RebuildProgress_T),
  1069. &Controller->V1.RebuildProgressDMA);
  1070. Controller->V1.NewLogicalDriveInformation = slice_dma_loaf(DmaPages,
  1071. sizeof(DAC960_V1_LogicalDriveInformationArray_T),
  1072. &Controller->V1.NewLogicalDriveInformationDMA);
  1073. Controller->V1.BackgroundInitializationStatus = slice_dma_loaf(DmaPages,
  1074. sizeof(DAC960_V1_BackgroundInitializationStatus_T),
  1075. &Controller->V1.BackgroundInitializationStatusDMA);
  1076. Controller->V1.NewDeviceState = slice_dma_loaf(DmaPages,
  1077. sizeof(DAC960_V1_DeviceState_T),
  1078. &Controller->V1.NewDeviceStateDMA);
  1079. Controller->V1.NewInquiryStandardData = slice_dma_loaf(DmaPages,
  1080. sizeof(DAC960_SCSI_Inquiry_T),
  1081. &Controller->V1.NewInquiryStandardDataDMA);
  1082. Controller->V1.NewInquiryUnitSerialNumber = slice_dma_loaf(DmaPages,
  1083. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T),
  1084. &Controller->V1.NewInquiryUnitSerialNumberDMA);
  1085. if ((hw_type == DAC960_PD_Controller) || (hw_type == DAC960_P_Controller))
  1086. return true;
  1087. /* Enable the Memory Mailbox Interface. */
  1088. Controller->V1.DualModeMemoryMailboxInterface = true;
  1089. CommandMailbox.TypeX.CommandOpcode = 0x2B;
  1090. CommandMailbox.TypeX.CommandIdentifier = 0;
  1091. CommandMailbox.TypeX.CommandOpcode2 = 0x14;
  1092. CommandMailbox.TypeX.CommandMailboxesBusAddress =
  1093. Controller->V1.FirstCommandMailboxDMA;
  1094. CommandMailbox.TypeX.StatusMailboxesBusAddress =
  1095. Controller->V1.FirstStatusMailboxDMA;
  1096. #define TIMEOUT_COUNT 1000000
  1097. for (i = 0; i < 2; i++)
  1098. switch (Controller->HardwareType)
  1099. {
  1100. case DAC960_LA_Controller:
  1101. TimeoutCounter = TIMEOUT_COUNT;
  1102. while (--TimeoutCounter >= 0)
  1103. {
  1104. if (!DAC960_LA_HardwareMailboxFullP(ControllerBaseAddress))
  1105. break;
  1106. udelay(10);
  1107. }
  1108. if (TimeoutCounter < 0) return false;
  1109. DAC960_LA_WriteHardwareMailbox(ControllerBaseAddress, &CommandMailbox);
  1110. DAC960_LA_HardwareMailboxNewCommand(ControllerBaseAddress);
  1111. TimeoutCounter = TIMEOUT_COUNT;
  1112. while (--TimeoutCounter >= 0)
  1113. {
  1114. if (DAC960_LA_HardwareMailboxStatusAvailableP(
  1115. ControllerBaseAddress))
  1116. break;
  1117. udelay(10);
  1118. }
  1119. if (TimeoutCounter < 0) return false;
  1120. CommandStatus = DAC960_LA_ReadStatusRegister(ControllerBaseAddress);
  1121. DAC960_LA_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
  1122. DAC960_LA_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
  1123. if (CommandStatus == DAC960_V1_NormalCompletion) return true;
  1124. Controller->V1.DualModeMemoryMailboxInterface = false;
  1125. CommandMailbox.TypeX.CommandOpcode2 = 0x10;
  1126. break;
  1127. case DAC960_PG_Controller:
  1128. TimeoutCounter = TIMEOUT_COUNT;
  1129. while (--TimeoutCounter >= 0)
  1130. {
  1131. if (!DAC960_PG_HardwareMailboxFullP(ControllerBaseAddress))
  1132. break;
  1133. udelay(10);
  1134. }
  1135. if (TimeoutCounter < 0) return false;
  1136. DAC960_PG_WriteHardwareMailbox(ControllerBaseAddress, &CommandMailbox);
  1137. DAC960_PG_HardwareMailboxNewCommand(ControllerBaseAddress);
  1138. TimeoutCounter = TIMEOUT_COUNT;
  1139. while (--TimeoutCounter >= 0)
  1140. {
  1141. if (DAC960_PG_HardwareMailboxStatusAvailableP(
  1142. ControllerBaseAddress))
  1143. break;
  1144. udelay(10);
  1145. }
  1146. if (TimeoutCounter < 0) return false;
  1147. CommandStatus = DAC960_PG_ReadStatusRegister(ControllerBaseAddress);
  1148. DAC960_PG_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
  1149. DAC960_PG_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
  1150. if (CommandStatus == DAC960_V1_NormalCompletion) return true;
  1151. Controller->V1.DualModeMemoryMailboxInterface = false;
  1152. CommandMailbox.TypeX.CommandOpcode2 = 0x10;
  1153. break;
  1154. default:
  1155. DAC960_Failure(Controller, "Unknown Controller Type\n");
  1156. break;
  1157. }
  1158. return false;
  1159. }
  1160. /*
  1161. DAC960_V2_EnableMemoryMailboxInterface enables the Memory Mailbox Interface
  1162. for DAC960 V2 Firmware Controllers.
  1163. Aggregate the space needed for the controller's memory mailbox and
  1164. the other data structures that will be targets of dma transfers with
  1165. the controller. Allocate a dma-mapped region of memory to hold these
  1166. structures. Then, save CPU pointers and dma_addr_t values to reference
  1167. the structures that are contained in that region.
  1168. */
  1169. static bool DAC960_V2_EnableMemoryMailboxInterface(DAC960_Controller_T
  1170. *Controller)
  1171. {
  1172. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  1173. struct pci_dev *PCI_Device = Controller->PCIDevice;
  1174. struct dma_loaf *DmaPages = &Controller->DmaPages;
  1175. size_t DmaPagesSize;
  1176. size_t CommandMailboxesSize;
  1177. size_t StatusMailboxesSize;
  1178. DAC960_V2_CommandMailbox_T *CommandMailboxesMemory;
  1179. dma_addr_t CommandMailboxesMemoryDMA;
  1180. DAC960_V2_StatusMailbox_T *StatusMailboxesMemory;
  1181. dma_addr_t StatusMailboxesMemoryDMA;
  1182. DAC960_V2_CommandMailbox_T *CommandMailbox;
  1183. dma_addr_t CommandMailboxDMA;
  1184. DAC960_V2_CommandStatus_T CommandStatus;
  1185. if (!pci_set_dma_mask(Controller->PCIDevice, DMA_BIT_MASK(64)))
  1186. Controller->BounceBufferLimit = DMA_BIT_MASK(64);
  1187. else if (!pci_set_dma_mask(Controller->PCIDevice, DMA_BIT_MASK(32)))
  1188. Controller->BounceBufferLimit = DMA_BIT_MASK(32);
  1189. else
  1190. return DAC960_Failure(Controller, "DMA mask out of range");
  1191. /* This is a temporary dma mapping, used only in the scope of this function */
  1192. CommandMailbox = pci_alloc_consistent(PCI_Device,
  1193. sizeof(DAC960_V2_CommandMailbox_T), &CommandMailboxDMA);
  1194. if (CommandMailbox == NULL)
  1195. return false;
  1196. CommandMailboxesSize = DAC960_V2_CommandMailboxCount * sizeof(DAC960_V2_CommandMailbox_T);
  1197. StatusMailboxesSize = DAC960_V2_StatusMailboxCount * sizeof(DAC960_V2_StatusMailbox_T);
  1198. DmaPagesSize =
  1199. CommandMailboxesSize + StatusMailboxesSize +
  1200. sizeof(DAC960_V2_HealthStatusBuffer_T) +
  1201. sizeof(DAC960_V2_ControllerInfo_T) +
  1202. sizeof(DAC960_V2_LogicalDeviceInfo_T) +
  1203. sizeof(DAC960_V2_PhysicalDeviceInfo_T) +
  1204. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T) +
  1205. sizeof(DAC960_V2_Event_T) +
  1206. sizeof(DAC960_V2_PhysicalToLogicalDevice_T);
  1207. if (!init_dma_loaf(PCI_Device, DmaPages, DmaPagesSize)) {
  1208. pci_free_consistent(PCI_Device, sizeof(DAC960_V2_CommandMailbox_T),
  1209. CommandMailbox, CommandMailboxDMA);
  1210. return false;
  1211. }
  1212. CommandMailboxesMemory = slice_dma_loaf(DmaPages,
  1213. CommandMailboxesSize, &CommandMailboxesMemoryDMA);
  1214. /* These are the base addresses for the command memory mailbox array */
  1215. Controller->V2.FirstCommandMailbox = CommandMailboxesMemory;
  1216. Controller->V2.FirstCommandMailboxDMA = CommandMailboxesMemoryDMA;
  1217. CommandMailboxesMemory += DAC960_V2_CommandMailboxCount - 1;
  1218. Controller->V2.LastCommandMailbox = CommandMailboxesMemory;
  1219. Controller->V2.NextCommandMailbox = Controller->V2.FirstCommandMailbox;
  1220. Controller->V2.PreviousCommandMailbox1 = Controller->V2.LastCommandMailbox;
  1221. Controller->V2.PreviousCommandMailbox2 =
  1222. Controller->V2.LastCommandMailbox - 1;
  1223. /* These are the base addresses for the status memory mailbox array */
  1224. StatusMailboxesMemory = slice_dma_loaf(DmaPages,
  1225. StatusMailboxesSize, &StatusMailboxesMemoryDMA);
  1226. Controller->V2.FirstStatusMailbox = StatusMailboxesMemory;
  1227. Controller->V2.FirstStatusMailboxDMA = StatusMailboxesMemoryDMA;
  1228. StatusMailboxesMemory += DAC960_V2_StatusMailboxCount - 1;
  1229. Controller->V2.LastStatusMailbox = StatusMailboxesMemory;
  1230. Controller->V2.NextStatusMailbox = Controller->V2.FirstStatusMailbox;
  1231. Controller->V2.HealthStatusBuffer = slice_dma_loaf(DmaPages,
  1232. sizeof(DAC960_V2_HealthStatusBuffer_T),
  1233. &Controller->V2.HealthStatusBufferDMA);
  1234. Controller->V2.NewControllerInformation = slice_dma_loaf(DmaPages,
  1235. sizeof(DAC960_V2_ControllerInfo_T),
  1236. &Controller->V2.NewControllerInformationDMA);
  1237. Controller->V2.NewLogicalDeviceInformation = slice_dma_loaf(DmaPages,
  1238. sizeof(DAC960_V2_LogicalDeviceInfo_T),
  1239. &Controller->V2.NewLogicalDeviceInformationDMA);
  1240. Controller->V2.NewPhysicalDeviceInformation = slice_dma_loaf(DmaPages,
  1241. sizeof(DAC960_V2_PhysicalDeviceInfo_T),
  1242. &Controller->V2.NewPhysicalDeviceInformationDMA);
  1243. Controller->V2.NewInquiryUnitSerialNumber = slice_dma_loaf(DmaPages,
  1244. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T),
  1245. &Controller->V2.NewInquiryUnitSerialNumberDMA);
  1246. Controller->V2.Event = slice_dma_loaf(DmaPages,
  1247. sizeof(DAC960_V2_Event_T),
  1248. &Controller->V2.EventDMA);
  1249. Controller->V2.PhysicalToLogicalDevice = slice_dma_loaf(DmaPages,
  1250. sizeof(DAC960_V2_PhysicalToLogicalDevice_T),
  1251. &Controller->V2.PhysicalToLogicalDeviceDMA);
  1252. /*
  1253. Enable the Memory Mailbox Interface.
  1254. I don't know why we can't just use one of the memory mailboxes
  1255. we just allocated to do this, instead of using this temporary one.
  1256. Try this change later.
  1257. */
  1258. memset(CommandMailbox, 0, sizeof(DAC960_V2_CommandMailbox_T));
  1259. CommandMailbox->SetMemoryMailbox.CommandIdentifier = 1;
  1260. CommandMailbox->SetMemoryMailbox.CommandOpcode = DAC960_V2_IOCTL;
  1261. CommandMailbox->SetMemoryMailbox.CommandControlBits.NoAutoRequestSense = true;
  1262. CommandMailbox->SetMemoryMailbox.FirstCommandMailboxSizeKB =
  1263. (DAC960_V2_CommandMailboxCount * sizeof(DAC960_V2_CommandMailbox_T)) >> 10;
  1264. CommandMailbox->SetMemoryMailbox.FirstStatusMailboxSizeKB =
  1265. (DAC960_V2_StatusMailboxCount * sizeof(DAC960_V2_StatusMailbox_T)) >> 10;
  1266. CommandMailbox->SetMemoryMailbox.SecondCommandMailboxSizeKB = 0;
  1267. CommandMailbox->SetMemoryMailbox.SecondStatusMailboxSizeKB = 0;
  1268. CommandMailbox->SetMemoryMailbox.RequestSenseSize = 0;
  1269. CommandMailbox->SetMemoryMailbox.IOCTL_Opcode = DAC960_V2_SetMemoryMailbox;
  1270. CommandMailbox->SetMemoryMailbox.HealthStatusBufferSizeKB = 1;
  1271. CommandMailbox->SetMemoryMailbox.HealthStatusBufferBusAddress =
  1272. Controller->V2.HealthStatusBufferDMA;
  1273. CommandMailbox->SetMemoryMailbox.FirstCommandMailboxBusAddress =
  1274. Controller->V2.FirstCommandMailboxDMA;
  1275. CommandMailbox->SetMemoryMailbox.FirstStatusMailboxBusAddress =
  1276. Controller->V2.FirstStatusMailboxDMA;
  1277. switch (Controller->HardwareType)
  1278. {
  1279. case DAC960_GEM_Controller:
  1280. while (DAC960_GEM_HardwareMailboxFullP(ControllerBaseAddress))
  1281. udelay(1);
  1282. DAC960_GEM_WriteHardwareMailbox(ControllerBaseAddress, CommandMailboxDMA);
  1283. DAC960_GEM_HardwareMailboxNewCommand(ControllerBaseAddress);
  1284. while (!DAC960_GEM_HardwareMailboxStatusAvailableP(ControllerBaseAddress))
  1285. udelay(1);
  1286. CommandStatus = DAC960_GEM_ReadCommandStatus(ControllerBaseAddress);
  1287. DAC960_GEM_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
  1288. DAC960_GEM_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
  1289. break;
  1290. case DAC960_BA_Controller:
  1291. while (DAC960_BA_HardwareMailboxFullP(ControllerBaseAddress))
  1292. udelay(1);
  1293. DAC960_BA_WriteHardwareMailbox(ControllerBaseAddress, CommandMailboxDMA);
  1294. DAC960_BA_HardwareMailboxNewCommand(ControllerBaseAddress);
  1295. while (!DAC960_BA_HardwareMailboxStatusAvailableP(ControllerBaseAddress))
  1296. udelay(1);
  1297. CommandStatus = DAC960_BA_ReadCommandStatus(ControllerBaseAddress);
  1298. DAC960_BA_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
  1299. DAC960_BA_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
  1300. break;
  1301. case DAC960_LP_Controller:
  1302. while (DAC960_LP_HardwareMailboxFullP(ControllerBaseAddress))
  1303. udelay(1);
  1304. DAC960_LP_WriteHardwareMailbox(ControllerBaseAddress, CommandMailboxDMA);
  1305. DAC960_LP_HardwareMailboxNewCommand(ControllerBaseAddress);
  1306. while (!DAC960_LP_HardwareMailboxStatusAvailableP(ControllerBaseAddress))
  1307. udelay(1);
  1308. CommandStatus = DAC960_LP_ReadCommandStatus(ControllerBaseAddress);
  1309. DAC960_LP_AcknowledgeHardwareMailboxInterrupt(ControllerBaseAddress);
  1310. DAC960_LP_AcknowledgeHardwareMailboxStatus(ControllerBaseAddress);
  1311. break;
  1312. default:
  1313. DAC960_Failure(Controller, "Unknown Controller Type\n");
  1314. CommandStatus = DAC960_V2_AbormalCompletion;
  1315. break;
  1316. }
  1317. pci_free_consistent(PCI_Device, sizeof(DAC960_V2_CommandMailbox_T),
  1318. CommandMailbox, CommandMailboxDMA);
  1319. return (CommandStatus == DAC960_V2_NormalCompletion);
  1320. }
  1321. /*
  1322. DAC960_V1_ReadControllerConfiguration reads the Configuration Information
  1323. from DAC960 V1 Firmware Controllers and initializes the Controller structure.
  1324. */
  1325. static bool DAC960_V1_ReadControllerConfiguration(DAC960_Controller_T
  1326. *Controller)
  1327. {
  1328. DAC960_V1_Enquiry2_T *Enquiry2;
  1329. dma_addr_t Enquiry2DMA;
  1330. DAC960_V1_Config2_T *Config2;
  1331. dma_addr_t Config2DMA;
  1332. int LogicalDriveNumber, Channel, TargetID;
  1333. struct dma_loaf local_dma;
  1334. if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
  1335. sizeof(DAC960_V1_Enquiry2_T) + sizeof(DAC960_V1_Config2_T)))
  1336. return DAC960_Failure(Controller, "LOGICAL DEVICE ALLOCATION");
  1337. Enquiry2 = slice_dma_loaf(&local_dma, sizeof(DAC960_V1_Enquiry2_T), &Enquiry2DMA);
  1338. Config2 = slice_dma_loaf(&local_dma, sizeof(DAC960_V1_Config2_T), &Config2DMA);
  1339. if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_Enquiry,
  1340. Controller->V1.NewEnquiryDMA)) {
  1341. free_dma_loaf(Controller->PCIDevice, &local_dma);
  1342. return DAC960_Failure(Controller, "ENQUIRY");
  1343. }
  1344. memcpy(&Controller->V1.Enquiry, Controller->V1.NewEnquiry,
  1345. sizeof(DAC960_V1_Enquiry_T));
  1346. if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_Enquiry2, Enquiry2DMA)) {
  1347. free_dma_loaf(Controller->PCIDevice, &local_dma);
  1348. return DAC960_Failure(Controller, "ENQUIRY2");
  1349. }
  1350. if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_ReadConfig2, Config2DMA)) {
  1351. free_dma_loaf(Controller->PCIDevice, &local_dma);
  1352. return DAC960_Failure(Controller, "READ CONFIG2");
  1353. }
  1354. if (!DAC960_V1_ExecuteType3(Controller, DAC960_V1_GetLogicalDriveInformation,
  1355. Controller->V1.NewLogicalDriveInformationDMA)) {
  1356. free_dma_loaf(Controller->PCIDevice, &local_dma);
  1357. return DAC960_Failure(Controller, "GET LOGICAL DRIVE INFORMATION");
  1358. }
  1359. memcpy(&Controller->V1.LogicalDriveInformation,
  1360. Controller->V1.NewLogicalDriveInformation,
  1361. sizeof(DAC960_V1_LogicalDriveInformationArray_T));
  1362. for (Channel = 0; Channel < Enquiry2->ActualChannels; Channel++)
  1363. for (TargetID = 0; TargetID < Enquiry2->MaxTargets; TargetID++) {
  1364. if (!DAC960_V1_ExecuteType3D(Controller, DAC960_V1_GetDeviceState,
  1365. Channel, TargetID,
  1366. Controller->V1.NewDeviceStateDMA)) {
  1367. free_dma_loaf(Controller->PCIDevice, &local_dma);
  1368. return DAC960_Failure(Controller, "GET DEVICE STATE");
  1369. }
  1370. memcpy(&Controller->V1.DeviceState[Channel][TargetID],
  1371. Controller->V1.NewDeviceState, sizeof(DAC960_V1_DeviceState_T));
  1372. }
  1373. /*
  1374. Initialize the Controller Model Name and Full Model Name fields.
  1375. */
  1376. switch (Enquiry2->HardwareID.SubModel)
  1377. {
  1378. case DAC960_V1_P_PD_PU:
  1379. if (Enquiry2->SCSICapability.BusSpeed == DAC960_V1_Ultra)
  1380. strcpy(Controller->ModelName, "DAC960PU");
  1381. else strcpy(Controller->ModelName, "DAC960PD");
  1382. break;
  1383. case DAC960_V1_PL:
  1384. strcpy(Controller->ModelName, "DAC960PL");
  1385. break;
  1386. case DAC960_V1_PG:
  1387. strcpy(Controller->ModelName, "DAC960PG");
  1388. break;
  1389. case DAC960_V1_PJ:
  1390. strcpy(Controller->ModelName, "DAC960PJ");
  1391. break;
  1392. case DAC960_V1_PR:
  1393. strcpy(Controller->ModelName, "DAC960PR");
  1394. break;
  1395. case DAC960_V1_PT:
  1396. strcpy(Controller->ModelName, "DAC960PT");
  1397. break;
  1398. case DAC960_V1_PTL0:
  1399. strcpy(Controller->ModelName, "DAC960PTL0");
  1400. break;
  1401. case DAC960_V1_PRL:
  1402. strcpy(Controller->ModelName, "DAC960PRL");
  1403. break;
  1404. case DAC960_V1_PTL1:
  1405. strcpy(Controller->ModelName, "DAC960PTL1");
  1406. break;
  1407. case DAC960_V1_1164P:
  1408. strcpy(Controller->ModelName, "DAC1164P");
  1409. break;
  1410. default:
  1411. free_dma_loaf(Controller->PCIDevice, &local_dma);
  1412. return DAC960_Failure(Controller, "MODEL VERIFICATION");
  1413. }
  1414. strcpy(Controller->FullModelName, "Mylex ");
  1415. strcat(Controller->FullModelName, Controller->ModelName);
  1416. /*
  1417. Initialize the Controller Firmware Version field and verify that it
  1418. is a supported firmware version. The supported firmware versions are:
  1419. DAC1164P 5.06 and above
  1420. DAC960PTL/PRL/PJ/PG 4.06 and above
  1421. DAC960PU/PD/PL 3.51 and above
  1422. DAC960PU/PD/PL/P 2.73 and above
  1423. */
  1424. #if defined(CONFIG_ALPHA)
  1425. /*
  1426. DEC Alpha machines were often equipped with DAC960 cards that were
  1427. OEMed from Mylex, and had their own custom firmware. Version 2.70,
  1428. the last custom FW revision to be released by DEC for these older
  1429. controllers, appears to work quite well with this driver.
  1430. Cards tested successfully were several versions each of the PD and
  1431. PU, called by DEC the KZPSC and KZPAC, respectively, and having
  1432. the Manufacturer Numbers (from Mylex), usually on a sticker on the
  1433. back of the board, of:
  1434. KZPSC: D040347 (1-channel) or D040348 (2-channel) or D040349 (3-channel)
  1435. KZPAC: D040395 (1-channel) or D040396 (2-channel) or D040397 (3-channel)
  1436. */
  1437. # define FIRMWARE_27X "2.70"
  1438. #else
  1439. # define FIRMWARE_27X "2.73"
  1440. #endif
  1441. if (Enquiry2->FirmwareID.MajorVersion == 0)
  1442. {
  1443. Enquiry2->FirmwareID.MajorVersion =
  1444. Controller->V1.Enquiry.MajorFirmwareVersion;
  1445. Enquiry2->FirmwareID.MinorVersion =
  1446. Controller->V1.Enquiry.MinorFirmwareVersion;
  1447. Enquiry2->FirmwareID.FirmwareType = '0';
  1448. Enquiry2->FirmwareID.TurnID = 0;
  1449. }
  1450. sprintf(Controller->FirmwareVersion, "%d.%02d-%c-%02d",
  1451. Enquiry2->FirmwareID.MajorVersion, Enquiry2->FirmwareID.MinorVersion,
  1452. Enquiry2->FirmwareID.FirmwareType, Enquiry2->FirmwareID.TurnID);
  1453. if (!((Controller->FirmwareVersion[0] == '5' &&
  1454. strcmp(Controller->FirmwareVersion, "5.06") >= 0) ||
  1455. (Controller->FirmwareVersion[0] == '4' &&
  1456. strcmp(Controller->FirmwareVersion, "4.06") >= 0) ||
  1457. (Controller->FirmwareVersion[0] == '3' &&
  1458. strcmp(Controller->FirmwareVersion, "3.51") >= 0) ||
  1459. (Controller->FirmwareVersion[0] == '2' &&
  1460. strcmp(Controller->FirmwareVersion, FIRMWARE_27X) >= 0)))
  1461. {
  1462. DAC960_Failure(Controller, "FIRMWARE VERSION VERIFICATION");
  1463. DAC960_Error("Firmware Version = '%s'\n", Controller,
  1464. Controller->FirmwareVersion);
  1465. free_dma_loaf(Controller->PCIDevice, &local_dma);
  1466. return false;
  1467. }
  1468. /*
  1469. Initialize the Controller Channels, Targets, Memory Size, and SAF-TE
  1470. Enclosure Management Enabled fields.
  1471. */
  1472. Controller->Channels = Enquiry2->ActualChannels;
  1473. Controller->Targets = Enquiry2->MaxTargets;
  1474. Controller->MemorySize = Enquiry2->MemorySize >> 20;
  1475. Controller->V1.SAFTE_EnclosureManagementEnabled =
  1476. (Enquiry2->FaultManagementType == DAC960_V1_SAFTE);
  1477. /*
  1478. Initialize the Controller Queue Depth, Driver Queue Depth, Logical Drive
  1479. Count, Maximum Blocks per Command, Controller Scatter/Gather Limit, and
  1480. Driver Scatter/Gather Limit. The Driver Queue Depth must be at most one
  1481. less than the Controller Queue Depth to allow for an automatic drive
  1482. rebuild operation.
  1483. */
  1484. Controller->ControllerQueueDepth = Controller->V1.Enquiry.MaxCommands;
  1485. Controller->DriverQueueDepth = Controller->ControllerQueueDepth - 1;
  1486. if (Controller->DriverQueueDepth > DAC960_MaxDriverQueueDepth)
  1487. Controller->DriverQueueDepth = DAC960_MaxDriverQueueDepth;
  1488. Controller->LogicalDriveCount =
  1489. Controller->V1.Enquiry.NumberOfLogicalDrives;
  1490. Controller->MaxBlocksPerCommand = Enquiry2->MaxBlocksPerCommand;
  1491. Controller->ControllerScatterGatherLimit = Enquiry2->MaxScatterGatherEntries;
  1492. Controller->DriverScatterGatherLimit =
  1493. Controller->ControllerScatterGatherLimit;
  1494. if (Controller->DriverScatterGatherLimit > DAC960_V1_ScatterGatherLimit)
  1495. Controller->DriverScatterGatherLimit = DAC960_V1_ScatterGatherLimit;
  1496. /*
  1497. Initialize the Stripe Size, Segment Size, and Geometry Translation.
  1498. */
  1499. Controller->V1.StripeSize = Config2->BlocksPerStripe * Config2->BlockFactor
  1500. >> (10 - DAC960_BlockSizeBits);
  1501. Controller->V1.SegmentSize = Config2->BlocksPerCacheLine * Config2->BlockFactor
  1502. >> (10 - DAC960_BlockSizeBits);
  1503. switch (Config2->DriveGeometry)
  1504. {
  1505. case DAC960_V1_Geometry_128_32:
  1506. Controller->V1.GeometryTranslationHeads = 128;
  1507. Controller->V1.GeometryTranslationSectors = 32;
  1508. break;
  1509. case DAC960_V1_Geometry_255_63:
  1510. Controller->V1.GeometryTranslationHeads = 255;
  1511. Controller->V1.GeometryTranslationSectors = 63;
  1512. break;
  1513. default:
  1514. free_dma_loaf(Controller->PCIDevice, &local_dma);
  1515. return DAC960_Failure(Controller, "CONFIG2 DRIVE GEOMETRY");
  1516. }
  1517. /*
  1518. Initialize the Background Initialization Status.
  1519. */
  1520. if ((Controller->FirmwareVersion[0] == '4' &&
  1521. strcmp(Controller->FirmwareVersion, "4.08") >= 0) ||
  1522. (Controller->FirmwareVersion[0] == '5' &&
  1523. strcmp(Controller->FirmwareVersion, "5.08") >= 0))
  1524. {
  1525. Controller->V1.BackgroundInitializationStatusSupported = true;
  1526. DAC960_V1_ExecuteType3B(Controller,
  1527. DAC960_V1_BackgroundInitializationControl, 0x20,
  1528. Controller->
  1529. V1.BackgroundInitializationStatusDMA);
  1530. memcpy(&Controller->V1.LastBackgroundInitializationStatus,
  1531. Controller->V1.BackgroundInitializationStatus,
  1532. sizeof(DAC960_V1_BackgroundInitializationStatus_T));
  1533. }
  1534. /*
  1535. Initialize the Logical Drive Initially Accessible flag.
  1536. */
  1537. for (LogicalDriveNumber = 0;
  1538. LogicalDriveNumber < Controller->LogicalDriveCount;
  1539. LogicalDriveNumber++)
  1540. if (Controller->V1.LogicalDriveInformation
  1541. [LogicalDriveNumber].LogicalDriveState !=
  1542. DAC960_V1_LogicalDrive_Offline)
  1543. Controller->LogicalDriveInitiallyAccessible[LogicalDriveNumber] = true;
  1544. Controller->V1.LastRebuildStatus = DAC960_V1_NoRebuildOrCheckInProgress;
  1545. free_dma_loaf(Controller->PCIDevice, &local_dma);
  1546. return true;
  1547. }
  1548. /*
  1549. DAC960_V2_ReadControllerConfiguration reads the Configuration Information
  1550. from DAC960 V2 Firmware Controllers and initializes the Controller structure.
  1551. */
  1552. static bool DAC960_V2_ReadControllerConfiguration(DAC960_Controller_T
  1553. *Controller)
  1554. {
  1555. DAC960_V2_ControllerInfo_T *ControllerInfo =
  1556. &Controller->V2.ControllerInformation;
  1557. unsigned short LogicalDeviceNumber = 0;
  1558. int ModelNameLength;
  1559. /* Get data into dma-able area, then copy into permanant location */
  1560. if (!DAC960_V2_NewControllerInfo(Controller))
  1561. return DAC960_Failure(Controller, "GET CONTROLLER INFO");
  1562. memcpy(ControllerInfo, Controller->V2.NewControllerInformation,
  1563. sizeof(DAC960_V2_ControllerInfo_T));
  1564. if (!DAC960_V2_GeneralInfo(Controller))
  1565. return DAC960_Failure(Controller, "GET HEALTH STATUS");
  1566. /*
  1567. Initialize the Controller Model Name and Full Model Name fields.
  1568. */
  1569. ModelNameLength = sizeof(ControllerInfo->ControllerName);
  1570. if (ModelNameLength > sizeof(Controller->ModelName)-1)
  1571. ModelNameLength = sizeof(Controller->ModelName)-1;
  1572. memcpy(Controller->ModelName, ControllerInfo->ControllerName,
  1573. ModelNameLength);
  1574. ModelNameLength--;
  1575. while (Controller->ModelName[ModelNameLength] == ' ' ||
  1576. Controller->ModelName[ModelNameLength] == '\0')
  1577. ModelNameLength--;
  1578. Controller->ModelName[++ModelNameLength] = '\0';
  1579. strcpy(Controller->FullModelName, "Mylex ");
  1580. strcat(Controller->FullModelName, Controller->ModelName);
  1581. /*
  1582. Initialize the Controller Firmware Version field.
  1583. */
  1584. sprintf(Controller->FirmwareVersion, "%d.%02d-%02d",
  1585. ControllerInfo->FirmwareMajorVersion,
  1586. ControllerInfo->FirmwareMinorVersion,
  1587. ControllerInfo->FirmwareTurnNumber);
  1588. if (ControllerInfo->FirmwareMajorVersion == 6 &&
  1589. ControllerInfo->FirmwareMinorVersion == 0 &&
  1590. ControllerInfo->FirmwareTurnNumber < 1)
  1591. {
  1592. DAC960_Info("FIRMWARE VERSION %s DOES NOT PROVIDE THE CONTROLLER\n",
  1593. Controller, Controller->FirmwareVersion);
  1594. DAC960_Info("STATUS MONITORING FUNCTIONALITY NEEDED BY THIS DRIVER.\n",
  1595. Controller);
  1596. DAC960_Info("PLEASE UPGRADE TO VERSION 6.00-01 OR ABOVE.\n",
  1597. Controller);
  1598. }
  1599. /*
  1600. Initialize the Controller Channels, Targets, and Memory Size.
  1601. */
  1602. Controller->Channels = ControllerInfo->NumberOfPhysicalChannelsPresent;
  1603. Controller->Targets =
  1604. ControllerInfo->MaximumTargetsPerChannel
  1605. [ControllerInfo->NumberOfPhysicalChannelsPresent-1];
  1606. Controller->MemorySize = ControllerInfo->MemorySizeMB;
  1607. /*
  1608. Initialize the Controller Queue Depth, Driver Queue Depth, Logical Drive
  1609. Count, Maximum Blocks per Command, Controller Scatter/Gather Limit, and
  1610. Driver Scatter/Gather Limit. The Driver Queue Depth must be at most one
  1611. less than the Controller Queue Depth to allow for an automatic drive
  1612. rebuild operation.
  1613. */
  1614. Controller->ControllerQueueDepth = ControllerInfo->MaximumParallelCommands;
  1615. Controller->DriverQueueDepth = Controller->ControllerQueueDepth - 1;
  1616. if (Controller->DriverQueueDepth > DAC960_MaxDriverQueueDepth)
  1617. Controller->DriverQueueDepth = DAC960_MaxDriverQueueDepth;
  1618. Controller->LogicalDriveCount = ControllerInfo->LogicalDevicesPresent;
  1619. Controller->MaxBlocksPerCommand =
  1620. ControllerInfo->MaximumDataTransferSizeInBlocks;
  1621. Controller->ControllerScatterGatherLimit =
  1622. ControllerInfo->MaximumScatterGatherEntries;
  1623. Controller->DriverScatterGatherLimit =
  1624. Controller->ControllerScatterGatherLimit;
  1625. if (Controller->DriverScatterGatherLimit > DAC960_V2_ScatterGatherLimit)
  1626. Controller->DriverScatterGatherLimit = DAC960_V2_ScatterGatherLimit;
  1627. /*
  1628. Initialize the Logical Device Information.
  1629. */
  1630. while (true)
  1631. {
  1632. DAC960_V2_LogicalDeviceInfo_T *NewLogicalDeviceInfo =
  1633. Controller->V2.NewLogicalDeviceInformation;
  1634. DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo;
  1635. DAC960_V2_PhysicalDevice_T PhysicalDevice;
  1636. if (!DAC960_V2_NewLogicalDeviceInfo(Controller, LogicalDeviceNumber))
  1637. break;
  1638. LogicalDeviceNumber = NewLogicalDeviceInfo->LogicalDeviceNumber;
  1639. if (LogicalDeviceNumber >= DAC960_MaxLogicalDrives) {
  1640. DAC960_Error("DAC960: Logical Drive Number %d not supported\n",
  1641. Controller, LogicalDeviceNumber);
  1642. break;
  1643. }
  1644. if (NewLogicalDeviceInfo->DeviceBlockSizeInBytes != DAC960_BlockSize) {
  1645. DAC960_Error("DAC960: Logical Drive Block Size %d not supported\n",
  1646. Controller, NewLogicalDeviceInfo->DeviceBlockSizeInBytes);
  1647. LogicalDeviceNumber++;
  1648. continue;
  1649. }
  1650. PhysicalDevice.Controller = 0;
  1651. PhysicalDevice.Channel = NewLogicalDeviceInfo->Channel;
  1652. PhysicalDevice.TargetID = NewLogicalDeviceInfo->TargetID;
  1653. PhysicalDevice.LogicalUnit = NewLogicalDeviceInfo->LogicalUnit;
  1654. Controller->V2.LogicalDriveToVirtualDevice[LogicalDeviceNumber] =
  1655. PhysicalDevice;
  1656. if (NewLogicalDeviceInfo->LogicalDeviceState !=
  1657. DAC960_V2_LogicalDevice_Offline)
  1658. Controller->LogicalDriveInitiallyAccessible[LogicalDeviceNumber] = true;
  1659. LogicalDeviceInfo = kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T),
  1660. GFP_ATOMIC);
  1661. if (LogicalDeviceInfo == NULL)
  1662. return DAC960_Failure(Controller, "LOGICAL DEVICE ALLOCATION");
  1663. Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber] =
  1664. LogicalDeviceInfo;
  1665. memcpy(LogicalDeviceInfo, NewLogicalDeviceInfo,
  1666. sizeof(DAC960_V2_LogicalDeviceInfo_T));
  1667. LogicalDeviceNumber++;
  1668. }
  1669. return true;
  1670. }
  1671. /*
  1672. DAC960_ReportControllerConfiguration reports the Configuration Information
  1673. for Controller.
  1674. */
  1675. static bool DAC960_ReportControllerConfiguration(DAC960_Controller_T
  1676. *Controller)
  1677. {
  1678. DAC960_Info("Configuring Mylex %s PCI RAID Controller\n",
  1679. Controller, Controller->ModelName);
  1680. DAC960_Info(" Firmware Version: %s, Channels: %d, Memory Size: %dMB\n",
  1681. Controller, Controller->FirmwareVersion,
  1682. Controller->Channels, Controller->MemorySize);
  1683. DAC960_Info(" PCI Bus: %d, Device: %d, Function: %d, I/O Address: ",
  1684. Controller, Controller->Bus,
  1685. Controller->Device, Controller->Function);
  1686. if (Controller->IO_Address == 0)
  1687. DAC960_Info("Unassigned\n", Controller);
  1688. else DAC960_Info("0x%X\n", Controller, Controller->IO_Address);
  1689. DAC960_Info(" PCI Address: 0x%X mapped at 0x%lX, IRQ Channel: %d\n",
  1690. Controller, Controller->PCI_Address,
  1691. (unsigned long) Controller->BaseAddress,
  1692. Controller->IRQ_Channel);
  1693. DAC960_Info(" Controller Queue Depth: %d, "
  1694. "Maximum Blocks per Command: %d\n",
  1695. Controller, Controller->ControllerQueueDepth,
  1696. Controller->MaxBlocksPerCommand);
  1697. DAC960_Info(" Driver Queue Depth: %d, "
  1698. "Scatter/Gather Limit: %d of %d Segments\n",
  1699. Controller, Controller->DriverQueueDepth,
  1700. Controller->DriverScatterGatherLimit,
  1701. Controller->ControllerScatterGatherLimit);
  1702. if (Controller->FirmwareType == DAC960_V1_Controller)
  1703. {
  1704. DAC960_Info(" Stripe Size: %dKB, Segment Size: %dKB, "
  1705. "BIOS Geometry: %d/%d\n", Controller,
  1706. Controller->V1.StripeSize,
  1707. Controller->V1.SegmentSize,
  1708. Controller->V1.GeometryTranslationHeads,
  1709. Controller->V1.GeometryTranslationSectors);
  1710. if (Controller->V1.SAFTE_EnclosureManagementEnabled)
  1711. DAC960_Info(" SAF-TE Enclosure Management Enabled\n", Controller);
  1712. }
  1713. return true;
  1714. }
  1715. /*
  1716. DAC960_V1_ReadDeviceConfiguration reads the Device Configuration Information
  1717. for DAC960 V1 Firmware Controllers by requesting the SCSI Inquiry and SCSI
  1718. Inquiry Unit Serial Number information for each device connected to
  1719. Controller.
  1720. */
  1721. static bool DAC960_V1_ReadDeviceConfiguration(DAC960_Controller_T
  1722. *Controller)
  1723. {
  1724. struct dma_loaf local_dma;
  1725. dma_addr_t DCDBs_dma[DAC960_V1_MaxChannels];
  1726. DAC960_V1_DCDB_T *DCDBs_cpu[DAC960_V1_MaxChannels];
  1727. dma_addr_t SCSI_Inquiry_dma[DAC960_V1_MaxChannels];
  1728. DAC960_SCSI_Inquiry_T *SCSI_Inquiry_cpu[DAC960_V1_MaxChannels];
  1729. dma_addr_t SCSI_NewInquiryUnitSerialNumberDMA[DAC960_V1_MaxChannels];
  1730. DAC960_SCSI_Inquiry_UnitSerialNumber_T *SCSI_NewInquiryUnitSerialNumberCPU[DAC960_V1_MaxChannels];
  1731. struct completion Completions[DAC960_V1_MaxChannels];
  1732. unsigned long flags;
  1733. int Channel, TargetID;
  1734. if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
  1735. DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
  1736. sizeof(DAC960_SCSI_Inquiry_T) +
  1737. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T))))
  1738. return DAC960_Failure(Controller,
  1739. "DMA ALLOCATION FAILED IN ReadDeviceConfiguration");
  1740. for (Channel = 0; Channel < Controller->Channels; Channel++) {
  1741. DCDBs_cpu[Channel] = slice_dma_loaf(&local_dma,
  1742. sizeof(DAC960_V1_DCDB_T), DCDBs_dma + Channel);
  1743. SCSI_Inquiry_cpu[Channel] = slice_dma_loaf(&local_dma,
  1744. sizeof(DAC960_SCSI_Inquiry_T),
  1745. SCSI_Inquiry_dma + Channel);
  1746. SCSI_NewInquiryUnitSerialNumberCPU[Channel] = slice_dma_loaf(&local_dma,
  1747. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T),
  1748. SCSI_NewInquiryUnitSerialNumberDMA + Channel);
  1749. }
  1750. for (TargetID = 0; TargetID < Controller->Targets; TargetID++)
  1751. {
  1752. /*
  1753. * For each channel, submit a probe for a device on that channel.
  1754. * The timeout interval for a device that is present is 10 seconds.
  1755. * With this approach, the timeout periods can elapse in parallel
  1756. * on each channel.
  1757. */
  1758. for (Channel = 0; Channel < Controller->Channels; Channel++)
  1759. {
  1760. dma_addr_t NewInquiryStandardDataDMA = SCSI_Inquiry_dma[Channel];
  1761. DAC960_V1_DCDB_T *DCDB = DCDBs_cpu[Channel];
  1762. dma_addr_t DCDB_dma = DCDBs_dma[Channel];
  1763. DAC960_Command_T *Command = Controller->Commands[Channel];
  1764. struct completion *Completion = &Completions[Channel];
  1765. init_completion(Completion);
  1766. DAC960_V1_ClearCommand(Command);
  1767. Command->CommandType = DAC960_ImmediateCommand;
  1768. Command->Completion = Completion;
  1769. Command->V1.CommandMailbox.Type3.CommandOpcode = DAC960_V1_DCDB;
  1770. Command->V1.CommandMailbox.Type3.BusAddress = DCDB_dma;
  1771. DCDB->Channel = Channel;
  1772. DCDB->TargetID = TargetID;
  1773. DCDB->Direction = DAC960_V1_DCDB_DataTransferDeviceToSystem;
  1774. DCDB->EarlyStatus = false;
  1775. DCDB->Timeout = DAC960_V1_DCDB_Timeout_10_seconds;
  1776. DCDB->NoAutomaticRequestSense = false;
  1777. DCDB->DisconnectPermitted = true;
  1778. DCDB->TransferLength = sizeof(DAC960_SCSI_Inquiry_T);
  1779. DCDB->BusAddress = NewInquiryStandardDataDMA;
  1780. DCDB->CDBLength = 6;
  1781. DCDB->TransferLengthHigh4 = 0;
  1782. DCDB->SenseLength = sizeof(DCDB->SenseData);
  1783. DCDB->CDB[0] = 0x12; /* INQUIRY */
  1784. DCDB->CDB[1] = 0; /* EVPD = 0 */
  1785. DCDB->CDB[2] = 0; /* Page Code */
  1786. DCDB->CDB[3] = 0; /* Reserved */
  1787. DCDB->CDB[4] = sizeof(DAC960_SCSI_Inquiry_T);
  1788. DCDB->CDB[5] = 0; /* Control */
  1789. spin_lock_irqsave(&Controller->queue_lock, flags);
  1790. DAC960_QueueCommand(Command);
  1791. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  1792. }
  1793. /*
  1794. * Wait for the problems submitted in the previous loop
  1795. * to complete. On the probes that are successful,
  1796. * get the serial number of the device that was found.
  1797. */
  1798. for (Channel = 0; Channel < Controller->Channels; Channel++)
  1799. {
  1800. DAC960_SCSI_Inquiry_T *InquiryStandardData =
  1801. &Controller->V1.InquiryStandardData[Channel][TargetID];
  1802. DAC960_SCSI_Inquiry_T *NewInquiryStandardData = SCSI_Inquiry_cpu[Channel];
  1803. dma_addr_t NewInquiryUnitSerialNumberDMA =
  1804. SCSI_NewInquiryUnitSerialNumberDMA[Channel];
  1805. DAC960_SCSI_Inquiry_UnitSerialNumber_T *NewInquiryUnitSerialNumber =
  1806. SCSI_NewInquiryUnitSerialNumberCPU[Channel];
  1807. DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
  1808. &Controller->V1.InquiryUnitSerialNumber[Channel][TargetID];
  1809. DAC960_Command_T *Command = Controller->Commands[Channel];
  1810. DAC960_V1_DCDB_T *DCDB = DCDBs_cpu[Channel];
  1811. struct completion *Completion = &Completions[Channel];
  1812. wait_for_completion(Completion);
  1813. if (Command->V1.CommandStatus != DAC960_V1_NormalCompletion) {
  1814. memset(InquiryStandardData, 0, sizeof(DAC960_SCSI_Inquiry_T));
  1815. InquiryStandardData->PeripheralDeviceType = 0x1F;
  1816. continue;
  1817. } else
  1818. memcpy(InquiryStandardData, NewInquiryStandardData, sizeof(DAC960_SCSI_Inquiry_T));
  1819. /* Preserve Channel and TargetID values from the previous loop */
  1820. Command->Completion = Completion;
  1821. DCDB->TransferLength = sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
  1822. DCDB->BusAddress = NewInquiryUnitSerialNumberDMA;
  1823. DCDB->SenseLength = sizeof(DCDB->SenseData);
  1824. DCDB->CDB[0] = 0x12; /* INQUIRY */
  1825. DCDB->CDB[1] = 1; /* EVPD = 1 */
  1826. DCDB->CDB[2] = 0x80; /* Page Code */
  1827. DCDB->CDB[3] = 0; /* Reserved */
  1828. DCDB->CDB[4] = sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
  1829. DCDB->CDB[5] = 0; /* Control */
  1830. spin_lock_irqsave(&Controller->queue_lock, flags);
  1831. DAC960_QueueCommand(Command);
  1832. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  1833. wait_for_completion(Completion);
  1834. if (Command->V1.CommandStatus != DAC960_V1_NormalCompletion) {
  1835. memset(InquiryUnitSerialNumber, 0,
  1836. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
  1837. InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
  1838. } else
  1839. memcpy(InquiryUnitSerialNumber, NewInquiryUnitSerialNumber,
  1840. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
  1841. }
  1842. }
  1843. free_dma_loaf(Controller->PCIDevice, &local_dma);
  1844. return true;
  1845. }
  1846. /*
  1847. DAC960_V2_ReadDeviceConfiguration reads the Device Configuration Information
  1848. for DAC960 V2 Firmware Controllers by requesting the Physical Device
  1849. Information and SCSI Inquiry Unit Serial Number information for each
  1850. device connected to Controller.
  1851. */
  1852. static bool DAC960_V2_ReadDeviceConfiguration(DAC960_Controller_T
  1853. *Controller)
  1854. {
  1855. unsigned char Channel = 0, TargetID = 0, LogicalUnit = 0;
  1856. unsigned short PhysicalDeviceIndex = 0;
  1857. while (true)
  1858. {
  1859. DAC960_V2_PhysicalDeviceInfo_T *NewPhysicalDeviceInfo =
  1860. Controller->V2.NewPhysicalDeviceInformation;
  1861. DAC960_V2_PhysicalDeviceInfo_T *PhysicalDeviceInfo;
  1862. DAC960_SCSI_Inquiry_UnitSerialNumber_T *NewInquiryUnitSerialNumber =
  1863. Controller->V2.NewInquiryUnitSerialNumber;
  1864. DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber;
  1865. if (!DAC960_V2_NewPhysicalDeviceInfo(Controller, Channel, TargetID, LogicalUnit))
  1866. break;
  1867. PhysicalDeviceInfo = kmalloc(sizeof(DAC960_V2_PhysicalDeviceInfo_T),
  1868. GFP_ATOMIC);
  1869. if (PhysicalDeviceInfo == NULL)
  1870. return DAC960_Failure(Controller, "PHYSICAL DEVICE ALLOCATION");
  1871. Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex] =
  1872. PhysicalDeviceInfo;
  1873. memcpy(PhysicalDeviceInfo, NewPhysicalDeviceInfo,
  1874. sizeof(DAC960_V2_PhysicalDeviceInfo_T));
  1875. InquiryUnitSerialNumber = kmalloc(
  1876. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T), GFP_ATOMIC);
  1877. if (InquiryUnitSerialNumber == NULL) {
  1878. kfree(PhysicalDeviceInfo);
  1879. return DAC960_Failure(Controller, "SERIAL NUMBER ALLOCATION");
  1880. }
  1881. Controller->V2.InquiryUnitSerialNumber[PhysicalDeviceIndex] =
  1882. InquiryUnitSerialNumber;
  1883. Channel = NewPhysicalDeviceInfo->Channel;
  1884. TargetID = NewPhysicalDeviceInfo->TargetID;
  1885. LogicalUnit = NewPhysicalDeviceInfo->LogicalUnit;
  1886. /*
  1887. Some devices do NOT have Unit Serial Numbers.
  1888. This command fails for them. But, we still want to
  1889. remember those devices are there. Construct a
  1890. UnitSerialNumber structure for the failure case.
  1891. */
  1892. if (!DAC960_V2_NewInquiryUnitSerialNumber(Controller, Channel, TargetID, LogicalUnit)) {
  1893. memset(InquiryUnitSerialNumber, 0,
  1894. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
  1895. InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
  1896. } else
  1897. memcpy(InquiryUnitSerialNumber, NewInquiryUnitSerialNumber,
  1898. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
  1899. PhysicalDeviceIndex++;
  1900. LogicalUnit++;
  1901. }
  1902. return true;
  1903. }
  1904. /*
  1905. DAC960_SanitizeInquiryData sanitizes the Vendor, Model, Revision, and
  1906. Product Serial Number fields of the Inquiry Standard Data and Inquiry
  1907. Unit Serial Number structures.
  1908. */
  1909. static void DAC960_SanitizeInquiryData(DAC960_SCSI_Inquiry_T
  1910. *InquiryStandardData,
  1911. DAC960_SCSI_Inquiry_UnitSerialNumber_T
  1912. *InquiryUnitSerialNumber,
  1913. unsigned char *Vendor,
  1914. unsigned char *Model,
  1915. unsigned char *Revision,
  1916. unsigned char *SerialNumber)
  1917. {
  1918. int SerialNumberLength, i;
  1919. if (InquiryStandardData->PeripheralDeviceType == 0x1F) return;
  1920. for (i = 0; i < sizeof(InquiryStandardData->VendorIdentification); i++)
  1921. {
  1922. unsigned char VendorCharacter =
  1923. InquiryStandardData->VendorIdentification[i];
  1924. Vendor[i] = (VendorCharacter >= ' ' && VendorCharacter <= '~'
  1925. ? VendorCharacter : ' ');
  1926. }
  1927. Vendor[sizeof(InquiryStandardData->VendorIdentification)] = '\0';
  1928. for (i = 0; i < sizeof(InquiryStandardData->ProductIdentification); i++)
  1929. {
  1930. unsigned char ModelCharacter =
  1931. InquiryStandardData->ProductIdentification[i];
  1932. Model[i] = (ModelCharacter >= ' ' && ModelCharacter <= '~'
  1933. ? ModelCharacter : ' ');
  1934. }
  1935. Model[sizeof(InquiryStandardData->ProductIdentification)] = '\0';
  1936. for (i = 0; i < sizeof(InquiryStandardData->ProductRevisionLevel); i++)
  1937. {
  1938. unsigned char RevisionCharacter =
  1939. InquiryStandardData->ProductRevisionLevel[i];
  1940. Revision[i] = (RevisionCharacter >= ' ' && RevisionCharacter <= '~'
  1941. ? RevisionCharacter : ' ');
  1942. }
  1943. Revision[sizeof(InquiryStandardData->ProductRevisionLevel)] = '\0';
  1944. if (InquiryUnitSerialNumber->PeripheralDeviceType == 0x1F) return;
  1945. SerialNumberLength = InquiryUnitSerialNumber->PageLength;
  1946. if (SerialNumberLength >
  1947. sizeof(InquiryUnitSerialNumber->ProductSerialNumber))
  1948. SerialNumberLength = sizeof(InquiryUnitSerialNumber->ProductSerialNumber);
  1949. for (i = 0; i < SerialNumberLength; i++)
  1950. {
  1951. unsigned char SerialNumberCharacter =
  1952. InquiryUnitSerialNumber->ProductSerialNumber[i];
  1953. SerialNumber[i] =
  1954. (SerialNumberCharacter >= ' ' && SerialNumberCharacter <= '~'
  1955. ? SerialNumberCharacter : ' ');
  1956. }
  1957. SerialNumber[SerialNumberLength] = '\0';
  1958. }
  1959. /*
  1960. DAC960_V1_ReportDeviceConfiguration reports the Device Configuration
  1961. Information for DAC960 V1 Firmware Controllers.
  1962. */
  1963. static bool DAC960_V1_ReportDeviceConfiguration(DAC960_Controller_T
  1964. *Controller)
  1965. {
  1966. int LogicalDriveNumber, Channel, TargetID;
  1967. DAC960_Info(" Physical Devices:\n", Controller);
  1968. for (Channel = 0; Channel < Controller->Channels; Channel++)
  1969. for (TargetID = 0; TargetID < Controller->Targets; TargetID++)
  1970. {
  1971. DAC960_SCSI_Inquiry_T *InquiryStandardData =
  1972. &Controller->V1.InquiryStandardData[Channel][TargetID];
  1973. DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
  1974. &Controller->V1.InquiryUnitSerialNumber[Channel][TargetID];
  1975. DAC960_V1_DeviceState_T *DeviceState =
  1976. &Controller->V1.DeviceState[Channel][TargetID];
  1977. DAC960_V1_ErrorTableEntry_T *ErrorEntry =
  1978. &Controller->V1.ErrorTable.ErrorTableEntries[Channel][TargetID];
  1979. char Vendor[1+sizeof(InquiryStandardData->VendorIdentification)];
  1980. char Model[1+sizeof(InquiryStandardData->ProductIdentification)];
  1981. char Revision[1+sizeof(InquiryStandardData->ProductRevisionLevel)];
  1982. char SerialNumber[1+sizeof(InquiryUnitSerialNumber
  1983. ->ProductSerialNumber)];
  1984. if (InquiryStandardData->PeripheralDeviceType == 0x1F) continue;
  1985. DAC960_SanitizeInquiryData(InquiryStandardData, InquiryUnitSerialNumber,
  1986. Vendor, Model, Revision, SerialNumber);
  1987. DAC960_Info(" %d:%d%s Vendor: %s Model: %s Revision: %s\n",
  1988. Controller, Channel, TargetID, (TargetID < 10 ? " " : ""),
  1989. Vendor, Model, Revision);
  1990. if (InquiryUnitSerialNumber->PeripheralDeviceType != 0x1F)
  1991. DAC960_Info(" Serial Number: %s\n", Controller, SerialNumber);
  1992. if (DeviceState->Present &&
  1993. DeviceState->DeviceType == DAC960_V1_DiskType)
  1994. {
  1995. if (Controller->V1.DeviceResetCount[Channel][TargetID] > 0)
  1996. DAC960_Info(" Disk Status: %s, %u blocks, %d resets\n",
  1997. Controller,
  1998. (DeviceState->DeviceState == DAC960_V1_Device_Dead
  1999. ? "Dead"
  2000. : DeviceState->DeviceState
  2001. == DAC960_V1_Device_WriteOnly
  2002. ? "Write-Only"
  2003. : DeviceState->DeviceState
  2004. == DAC960_V1_Device_Online
  2005. ? "Online" : "Standby"),
  2006. DeviceState->DiskSize,
  2007. Controller->V1.DeviceResetCount[Channel][TargetID]);
  2008. else
  2009. DAC960_Info(" Disk Status: %s, %u blocks\n", Controller,
  2010. (DeviceState->DeviceState == DAC960_V1_Device_Dead
  2011. ? "Dead"
  2012. : DeviceState->DeviceState
  2013. == DAC960_V1_Device_WriteOnly
  2014. ? "Write-Only"
  2015. : DeviceState->DeviceState
  2016. == DAC960_V1_Device_Online
  2017. ? "Online" : "Standby"),
  2018. DeviceState->DiskSize);
  2019. }
  2020. if (ErrorEntry->ParityErrorCount > 0 ||
  2021. ErrorEntry->SoftErrorCount > 0 ||
  2022. ErrorEntry->HardErrorCount > 0 ||
  2023. ErrorEntry->MiscErrorCount > 0)
  2024. DAC960_Info(" Errors - Parity: %d, Soft: %d, "
  2025. "Hard: %d, Misc: %d\n", Controller,
  2026. ErrorEntry->ParityErrorCount,
  2027. ErrorEntry->SoftErrorCount,
  2028. ErrorEntry->HardErrorCount,
  2029. ErrorEntry->MiscErrorCount);
  2030. }
  2031. DAC960_Info(" Logical Drives:\n", Controller);
  2032. for (LogicalDriveNumber = 0;
  2033. LogicalDriveNumber < Controller->LogicalDriveCount;
  2034. LogicalDriveNumber++)
  2035. {
  2036. DAC960_V1_LogicalDriveInformation_T *LogicalDriveInformation =
  2037. &Controller->V1.LogicalDriveInformation[LogicalDriveNumber];
  2038. DAC960_Info(" /dev/rd/c%dd%d: RAID-%d, %s, %u blocks, %s\n",
  2039. Controller, Controller->ControllerNumber, LogicalDriveNumber,
  2040. LogicalDriveInformation->RAIDLevel,
  2041. (LogicalDriveInformation->LogicalDriveState
  2042. == DAC960_V1_LogicalDrive_Online
  2043. ? "Online"
  2044. : LogicalDriveInformation->LogicalDriveState
  2045. == DAC960_V1_LogicalDrive_Critical
  2046. ? "Critical" : "Offline"),
  2047. LogicalDriveInformation->LogicalDriveSize,
  2048. (LogicalDriveInformation->WriteBack
  2049. ? "Write Back" : "Write Thru"));
  2050. }
  2051. return true;
  2052. }
  2053. /*
  2054. DAC960_V2_ReportDeviceConfiguration reports the Device Configuration
  2055. Information for DAC960 V2 Firmware Controllers.
  2056. */
  2057. static bool DAC960_V2_ReportDeviceConfiguration(DAC960_Controller_T
  2058. *Controller)
  2059. {
  2060. int PhysicalDeviceIndex, LogicalDriveNumber;
  2061. DAC960_Info(" Physical Devices:\n", Controller);
  2062. for (PhysicalDeviceIndex = 0;
  2063. PhysicalDeviceIndex < DAC960_V2_MaxPhysicalDevices;
  2064. PhysicalDeviceIndex++)
  2065. {
  2066. DAC960_V2_PhysicalDeviceInfo_T *PhysicalDeviceInfo =
  2067. Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex];
  2068. DAC960_SCSI_Inquiry_T *InquiryStandardData =
  2069. (DAC960_SCSI_Inquiry_T *) &PhysicalDeviceInfo->SCSI_InquiryData;
  2070. DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
  2071. Controller->V2.InquiryUnitSerialNumber[PhysicalDeviceIndex];
  2072. char Vendor[1+sizeof(InquiryStandardData->VendorIdentification)];
  2073. char Model[1+sizeof(InquiryStandardData->ProductIdentification)];
  2074. char Revision[1+sizeof(InquiryStandardData->ProductRevisionLevel)];
  2075. char SerialNumber[1+sizeof(InquiryUnitSerialNumber->ProductSerialNumber)];
  2076. if (PhysicalDeviceInfo == NULL) break;
  2077. DAC960_SanitizeInquiryData(InquiryStandardData, InquiryUnitSerialNumber,
  2078. Vendor, Model, Revision, SerialNumber);
  2079. DAC960_Info(" %d:%d%s Vendor: %s Model: %s Revision: %s\n",
  2080. Controller,
  2081. PhysicalDeviceInfo->Channel,
  2082. PhysicalDeviceInfo->TargetID,
  2083. (PhysicalDeviceInfo->TargetID < 10 ? " " : ""),
  2084. Vendor, Model, Revision);
  2085. if (PhysicalDeviceInfo->NegotiatedSynchronousMegaTransfers == 0)
  2086. DAC960_Info(" %sAsynchronous\n", Controller,
  2087. (PhysicalDeviceInfo->NegotiatedDataWidthBits == 16
  2088. ? "Wide " :""));
  2089. else
  2090. DAC960_Info(" %sSynchronous at %d MB/sec\n", Controller,
  2091. (PhysicalDeviceInfo->NegotiatedDataWidthBits == 16
  2092. ? "Wide " :""),
  2093. (PhysicalDeviceInfo->NegotiatedSynchronousMegaTransfers
  2094. * PhysicalDeviceInfo->NegotiatedDataWidthBits/8));
  2095. if (InquiryUnitSerialNumber->PeripheralDeviceType != 0x1F)
  2096. DAC960_Info(" Serial Number: %s\n", Controller, SerialNumber);
  2097. if (PhysicalDeviceInfo->PhysicalDeviceState ==
  2098. DAC960_V2_Device_Unconfigured)
  2099. continue;
  2100. DAC960_Info(" Disk Status: %s, %u blocks\n", Controller,
  2101. (PhysicalDeviceInfo->PhysicalDeviceState
  2102. == DAC960_V2_Device_Online
  2103. ? "Online"
  2104. : PhysicalDeviceInfo->PhysicalDeviceState
  2105. == DAC960_V2_Device_Rebuild
  2106. ? "Rebuild"
  2107. : PhysicalDeviceInfo->PhysicalDeviceState
  2108. == DAC960_V2_Device_Missing
  2109. ? "Missing"
  2110. : PhysicalDeviceInfo->PhysicalDeviceState
  2111. == DAC960_V2_Device_Critical
  2112. ? "Critical"
  2113. : PhysicalDeviceInfo->PhysicalDeviceState
  2114. == DAC960_V2_Device_Dead
  2115. ? "Dead"
  2116. : PhysicalDeviceInfo->PhysicalDeviceState
  2117. == DAC960_V2_Device_SuspectedDead
  2118. ? "Suspected-Dead"
  2119. : PhysicalDeviceInfo->PhysicalDeviceState
  2120. == DAC960_V2_Device_CommandedOffline
  2121. ? "Commanded-Offline"
  2122. : PhysicalDeviceInfo->PhysicalDeviceState
  2123. == DAC960_V2_Device_Standby
  2124. ? "Standby" : "Unknown"),
  2125. PhysicalDeviceInfo->ConfigurableDeviceSize);
  2126. if (PhysicalDeviceInfo->ParityErrors == 0 &&
  2127. PhysicalDeviceInfo->SoftErrors == 0 &&
  2128. PhysicalDeviceInfo->HardErrors == 0 &&
  2129. PhysicalDeviceInfo->MiscellaneousErrors == 0 &&
  2130. PhysicalDeviceInfo->CommandTimeouts == 0 &&
  2131. PhysicalDeviceInfo->Retries == 0 &&
  2132. PhysicalDeviceInfo->Aborts == 0 &&
  2133. PhysicalDeviceInfo->PredictedFailuresDetected == 0)
  2134. continue;
  2135. DAC960_Info(" Errors - Parity: %d, Soft: %d, "
  2136. "Hard: %d, Misc: %d\n", Controller,
  2137. PhysicalDeviceInfo->ParityErrors,
  2138. PhysicalDeviceInfo->SoftErrors,
  2139. PhysicalDeviceInfo->HardErrors,
  2140. PhysicalDeviceInfo->MiscellaneousErrors);
  2141. DAC960_Info(" Timeouts: %d, Retries: %d, "
  2142. "Aborts: %d, Predicted: %d\n", Controller,
  2143. PhysicalDeviceInfo->CommandTimeouts,
  2144. PhysicalDeviceInfo->Retries,
  2145. PhysicalDeviceInfo->Aborts,
  2146. PhysicalDeviceInfo->PredictedFailuresDetected);
  2147. }
  2148. DAC960_Info(" Logical Drives:\n", Controller);
  2149. for (LogicalDriveNumber = 0;
  2150. LogicalDriveNumber < DAC960_MaxLogicalDrives;
  2151. LogicalDriveNumber++)
  2152. {
  2153. DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
  2154. Controller->V2.LogicalDeviceInformation[LogicalDriveNumber];
  2155. unsigned char *ReadCacheStatus[] = { "Read Cache Disabled",
  2156. "Read Cache Enabled",
  2157. "Read Ahead Enabled",
  2158. "Intelligent Read Ahead Enabled",
  2159. "-", "-", "-", "-" };
  2160. unsigned char *WriteCacheStatus[] = { "Write Cache Disabled",
  2161. "Logical Device Read Only",
  2162. "Write Cache Enabled",
  2163. "Intelligent Write Cache Enabled",
  2164. "-", "-", "-", "-" };
  2165. unsigned char *GeometryTranslation;
  2166. if (LogicalDeviceInfo == NULL) continue;
  2167. switch (LogicalDeviceInfo->DriveGeometry)
  2168. {
  2169. case DAC960_V2_Geometry_128_32:
  2170. GeometryTranslation = "128/32";
  2171. break;
  2172. case DAC960_V2_Geometry_255_63:
  2173. GeometryTranslation = "255/63";
  2174. break;
  2175. default:
  2176. GeometryTranslation = "Invalid";
  2177. DAC960_Error("Illegal Logical Device Geometry %d\n",
  2178. Controller, LogicalDeviceInfo->DriveGeometry);
  2179. break;
  2180. }
  2181. DAC960_Info(" /dev/rd/c%dd%d: RAID-%d, %s, %u blocks\n",
  2182. Controller, Controller->ControllerNumber, LogicalDriveNumber,
  2183. LogicalDeviceInfo->RAIDLevel,
  2184. (LogicalDeviceInfo->LogicalDeviceState
  2185. == DAC960_V2_LogicalDevice_Online
  2186. ? "Online"
  2187. : LogicalDeviceInfo->LogicalDeviceState
  2188. == DAC960_V2_LogicalDevice_Critical
  2189. ? "Critical" : "Offline"),
  2190. LogicalDeviceInfo->ConfigurableDeviceSize);
  2191. DAC960_Info(" Logical Device %s, BIOS Geometry: %s\n",
  2192. Controller,
  2193. (LogicalDeviceInfo->LogicalDeviceControl
  2194. .LogicalDeviceInitialized
  2195. ? "Initialized" : "Uninitialized"),
  2196. GeometryTranslation);
  2197. if (LogicalDeviceInfo->StripeSize == 0)
  2198. {
  2199. if (LogicalDeviceInfo->CacheLineSize == 0)
  2200. DAC960_Info(" Stripe Size: N/A, "
  2201. "Segment Size: N/A\n", Controller);
  2202. else
  2203. DAC960_Info(" Stripe Size: N/A, "
  2204. "Segment Size: %dKB\n", Controller,
  2205. 1 << (LogicalDeviceInfo->CacheLineSize - 2));
  2206. }
  2207. else
  2208. {
  2209. if (LogicalDeviceInfo->CacheLineSize == 0)
  2210. DAC960_Info(" Stripe Size: %dKB, "
  2211. "Segment Size: N/A\n", Controller,
  2212. 1 << (LogicalDeviceInfo->StripeSize - 2));
  2213. else
  2214. DAC960_Info(" Stripe Size: %dKB, "
  2215. "Segment Size: %dKB\n", Controller,
  2216. 1 << (LogicalDeviceInfo->StripeSize - 2),
  2217. 1 << (LogicalDeviceInfo->CacheLineSize - 2));
  2218. }
  2219. DAC960_Info(" %s, %s\n", Controller,
  2220. ReadCacheStatus[
  2221. LogicalDeviceInfo->LogicalDeviceControl.ReadCache],
  2222. WriteCacheStatus[
  2223. LogicalDeviceInfo->LogicalDeviceControl.WriteCache]);
  2224. if (LogicalDeviceInfo->SoftErrors > 0 ||
  2225. LogicalDeviceInfo->CommandsFailed > 0 ||
  2226. LogicalDeviceInfo->DeferredWriteErrors)
  2227. DAC960_Info(" Errors - Soft: %d, Failed: %d, "
  2228. "Deferred Write: %d\n", Controller,
  2229. LogicalDeviceInfo->SoftErrors,
  2230. LogicalDeviceInfo->CommandsFailed,
  2231. LogicalDeviceInfo->DeferredWriteErrors);
  2232. }
  2233. return true;
  2234. }
  2235. /*
  2236. DAC960_RegisterBlockDevice registers the Block Device structures
  2237. associated with Controller.
  2238. */
  2239. static bool DAC960_RegisterBlockDevice(DAC960_Controller_T *Controller)
  2240. {
  2241. int MajorNumber = DAC960_MAJOR + Controller->ControllerNumber;
  2242. int n;
  2243. /*
  2244. Register the Block Device Major Number for this DAC960 Controller.
  2245. */
  2246. if (register_blkdev(MajorNumber, "dac960") < 0)
  2247. return false;
  2248. for (n = 0; n < DAC960_MaxLogicalDrives; n++) {
  2249. struct gendisk *disk = Controller->disks[n];
  2250. struct request_queue *RequestQueue;
  2251. /* for now, let all request queues share controller's lock */
  2252. RequestQueue = blk_init_queue(DAC960_RequestFunction,&Controller->queue_lock);
  2253. if (!RequestQueue) {
  2254. printk("DAC960: failure to allocate request queue\n");
  2255. continue;
  2256. }
  2257. Controller->RequestQueue[n] = RequestQueue;
  2258. blk_queue_bounce_limit(RequestQueue, Controller->BounceBufferLimit);
  2259. RequestQueue->queuedata = Controller;
  2260. blk_queue_max_hw_segments(RequestQueue, Controller->DriverScatterGatherLimit);
  2261. blk_queue_max_phys_segments(RequestQueue, Controller->DriverScatterGatherLimit);
  2262. blk_queue_max_sectors(RequestQueue, Controller->MaxBlocksPerCommand);
  2263. disk->queue = RequestQueue;
  2264. sprintf(disk->disk_name, "rd/c%dd%d", Controller->ControllerNumber, n);
  2265. disk->major = MajorNumber;
  2266. disk->first_minor = n << DAC960_MaxPartitionsBits;
  2267. disk->fops = &DAC960_BlockDeviceOperations;
  2268. }
  2269. /*
  2270. Indicate the Block Device Registration completed successfully,
  2271. */
  2272. return true;
  2273. }
  2274. /*
  2275. DAC960_UnregisterBlockDevice unregisters the Block Device structures
  2276. associated with Controller.
  2277. */
  2278. static void DAC960_UnregisterBlockDevice(DAC960_Controller_T *Controller)
  2279. {
  2280. int MajorNumber = DAC960_MAJOR + Controller->ControllerNumber;
  2281. int disk;
  2282. /* does order matter when deleting gendisk and cleanup in request queue? */
  2283. for (disk = 0; disk < DAC960_MaxLogicalDrives; disk++) {
  2284. del_gendisk(Controller->disks[disk]);
  2285. blk_cleanup_queue(Controller->RequestQueue[disk]);
  2286. Controller->RequestQueue[disk] = NULL;
  2287. }
  2288. /*
  2289. Unregister the Block Device Major Number for this DAC960 Controller.
  2290. */
  2291. unregister_blkdev(MajorNumber, "dac960");
  2292. }
  2293. /*
  2294. DAC960_ComputeGenericDiskInfo computes the values for the Generic Disk
  2295. Information Partition Sector Counts and Block Sizes.
  2296. */
  2297. static void DAC960_ComputeGenericDiskInfo(DAC960_Controller_T *Controller)
  2298. {
  2299. int disk;
  2300. for (disk = 0; disk < DAC960_MaxLogicalDrives; disk++)
  2301. set_capacity(Controller->disks[disk], disk_size(Controller, disk));
  2302. }
  2303. /*
  2304. DAC960_ReportErrorStatus reports Controller BIOS Messages passed through
  2305. the Error Status Register when the driver performs the BIOS handshaking.
  2306. It returns true for fatal errors and false otherwise.
  2307. */
  2308. static bool DAC960_ReportErrorStatus(DAC960_Controller_T *Controller,
  2309. unsigned char ErrorStatus,
  2310. unsigned char Parameter0,
  2311. unsigned char Parameter1)
  2312. {
  2313. switch (ErrorStatus)
  2314. {
  2315. case 0x00:
  2316. DAC960_Notice("Physical Device %d:%d Not Responding\n",
  2317. Controller, Parameter1, Parameter0);
  2318. break;
  2319. case 0x08:
  2320. if (Controller->DriveSpinUpMessageDisplayed) break;
  2321. DAC960_Notice("Spinning Up Drives\n", Controller);
  2322. Controller->DriveSpinUpMessageDisplayed = true;
  2323. break;
  2324. case 0x30:
  2325. DAC960_Notice("Configuration Checksum Error\n", Controller);
  2326. break;
  2327. case 0x60:
  2328. DAC960_Notice("Mirror Race Recovery Failed\n", Controller);
  2329. break;
  2330. case 0x70:
  2331. DAC960_Notice("Mirror Race Recovery In Progress\n", Controller);
  2332. break;
  2333. case 0x90:
  2334. DAC960_Notice("Physical Device %d:%d COD Mismatch\n",
  2335. Controller, Parameter1, Parameter0);
  2336. break;
  2337. case 0xA0:
  2338. DAC960_Notice("Logical Drive Installation Aborted\n", Controller);
  2339. break;
  2340. case 0xB0:
  2341. DAC960_Notice("Mirror Race On A Critical Logical Drive\n", Controller);
  2342. break;
  2343. case 0xD0:
  2344. DAC960_Notice("New Controller Configuration Found\n", Controller);
  2345. break;
  2346. case 0xF0:
  2347. DAC960_Error("Fatal Memory Parity Error for Controller at\n", Controller);
  2348. return true;
  2349. default:
  2350. DAC960_Error("Unknown Initialization Error %02X for Controller at\n",
  2351. Controller, ErrorStatus);
  2352. return true;
  2353. }
  2354. return false;
  2355. }
  2356. /*
  2357. * DAC960_DetectCleanup releases the resources that were allocated
  2358. * during DAC960_DetectController(). DAC960_DetectController can
  2359. * has several internal failure points, so not ALL resources may
  2360. * have been allocated. It's important to free only
  2361. * resources that HAVE been allocated. The code below always
  2362. * tests that the resource has been allocated before attempting to
  2363. * free it.
  2364. */
  2365. static void DAC960_DetectCleanup(DAC960_Controller_T *Controller)
  2366. {
  2367. int i;
  2368. /* Free the memory mailbox, status, and related structures */
  2369. free_dma_loaf(Controller->PCIDevice, &Controller->DmaPages);
  2370. if (Controller->MemoryMappedAddress) {
  2371. switch(Controller->HardwareType)
  2372. {
  2373. case DAC960_GEM_Controller:
  2374. DAC960_GEM_DisableInterrupts(Controller->BaseAddress);
  2375. break;
  2376. case DAC960_BA_Controller:
  2377. DAC960_BA_DisableInterrupts(Controller->BaseAddress);
  2378. break;
  2379. case DAC960_LP_Controller:
  2380. DAC960_LP_DisableInterrupts(Controller->BaseAddress);
  2381. break;
  2382. case DAC960_LA_Controller:
  2383. DAC960_LA_DisableInterrupts(Controller->BaseAddress);
  2384. break;
  2385. case DAC960_PG_Controller:
  2386. DAC960_PG_DisableInterrupts(Controller->BaseAddress);
  2387. break;
  2388. case DAC960_PD_Controller:
  2389. DAC960_PD_DisableInterrupts(Controller->BaseAddress);
  2390. break;
  2391. case DAC960_P_Controller:
  2392. DAC960_PD_DisableInterrupts(Controller->BaseAddress);
  2393. break;
  2394. }
  2395. iounmap(Controller->MemoryMappedAddress);
  2396. }
  2397. if (Controller->IRQ_Channel)
  2398. free_irq(Controller->IRQ_Channel, Controller);
  2399. if (Controller->IO_Address)
  2400. release_region(Controller->IO_Address, 0x80);
  2401. pci_disable_device(Controller->PCIDevice);
  2402. for (i = 0; (i < DAC960_MaxLogicalDrives) && Controller->disks[i]; i++)
  2403. put_disk(Controller->disks[i]);
  2404. DAC960_Controllers[Controller->ControllerNumber] = NULL;
  2405. kfree(Controller);
  2406. }
  2407. /*
  2408. DAC960_DetectController detects Mylex DAC960/AcceleRAID/eXtremeRAID
  2409. PCI RAID Controllers by interrogating the PCI Configuration Space for
  2410. Controller Type.
  2411. */
  2412. static DAC960_Controller_T *
  2413. DAC960_DetectController(struct pci_dev *PCI_Device,
  2414. const struct pci_device_id *entry)
  2415. {
  2416. struct DAC960_privdata *privdata =
  2417. (struct DAC960_privdata *)entry->driver_data;
  2418. irq_handler_t InterruptHandler = privdata->InterruptHandler;
  2419. unsigned int MemoryWindowSize = privdata->MemoryWindowSize;
  2420. DAC960_Controller_T *Controller = NULL;
  2421. unsigned char DeviceFunction = PCI_Device->devfn;
  2422. unsigned char ErrorStatus, Parameter0, Parameter1;
  2423. unsigned int IRQ_Channel;
  2424. void __iomem *BaseAddress;
  2425. int i;
  2426. Controller = kzalloc(sizeof(DAC960_Controller_T), GFP_ATOMIC);
  2427. if (Controller == NULL) {
  2428. DAC960_Error("Unable to allocate Controller structure for "
  2429. "Controller at\n", NULL);
  2430. return NULL;
  2431. }
  2432. Controller->ControllerNumber = DAC960_ControllerCount;
  2433. DAC960_Controllers[DAC960_ControllerCount++] = Controller;
  2434. Controller->Bus = PCI_Device->bus->number;
  2435. Controller->FirmwareType = privdata->FirmwareType;
  2436. Controller->HardwareType = privdata->HardwareType;
  2437. Controller->Device = DeviceFunction >> 3;
  2438. Controller->Function = DeviceFunction & 0x7;
  2439. Controller->PCIDevice = PCI_Device;
  2440. strcpy(Controller->FullModelName, "DAC960");
  2441. if (pci_enable_device(PCI_Device))
  2442. goto Failure;
  2443. switch (Controller->HardwareType)
  2444. {
  2445. case DAC960_GEM_Controller:
  2446. Controller->PCI_Address = pci_resource_start(PCI_Device, 0);
  2447. break;
  2448. case DAC960_BA_Controller:
  2449. Controller->PCI_Address = pci_resource_start(PCI_Device, 0);
  2450. break;
  2451. case DAC960_LP_Controller:
  2452. Controller->PCI_Address = pci_resource_start(PCI_Device, 0);
  2453. break;
  2454. case DAC960_LA_Controller:
  2455. Controller->PCI_Address = pci_resource_start(PCI_Device, 0);
  2456. break;
  2457. case DAC960_PG_Controller:
  2458. Controller->PCI_Address = pci_resource_start(PCI_Device, 0);
  2459. break;
  2460. case DAC960_PD_Controller:
  2461. Controller->IO_Address = pci_resource_start(PCI_Device, 0);
  2462. Controller->PCI_Address = pci_resource_start(PCI_Device, 1);
  2463. break;
  2464. case DAC960_P_Controller:
  2465. Controller->IO_Address = pci_resource_start(PCI_Device, 0);
  2466. Controller->PCI_Address = pci_resource_start(PCI_Device, 1);
  2467. break;
  2468. }
  2469. pci_set_drvdata(PCI_Device, (void *)((long)Controller->ControllerNumber));
  2470. for (i = 0; i < DAC960_MaxLogicalDrives; i++) {
  2471. Controller->disks[i] = alloc_disk(1<<DAC960_MaxPartitionsBits);
  2472. if (!Controller->disks[i])
  2473. goto Failure;
  2474. Controller->disks[i]->private_data = (void *)((long)i);
  2475. }
  2476. init_waitqueue_head(&Controller->CommandWaitQueue);
  2477. init_waitqueue_head(&Controller->HealthStatusWaitQueue);
  2478. spin_lock_init(&Controller->queue_lock);
  2479. DAC960_AnnounceDriver(Controller);
  2480. /*
  2481. Map the Controller Register Window.
  2482. */
  2483. if (MemoryWindowSize < PAGE_SIZE)
  2484. MemoryWindowSize = PAGE_SIZE;
  2485. Controller->MemoryMappedAddress =
  2486. ioremap_nocache(Controller->PCI_Address & PAGE_MASK, MemoryWindowSize);
  2487. Controller->BaseAddress =
  2488. Controller->MemoryMappedAddress + (Controller->PCI_Address & ~PAGE_MASK);
  2489. if (Controller->MemoryMappedAddress == NULL)
  2490. {
  2491. DAC960_Error("Unable to map Controller Register Window for "
  2492. "Controller at\n", Controller);
  2493. goto Failure;
  2494. }
  2495. BaseAddress = Controller->BaseAddress;
  2496. switch (Controller->HardwareType)
  2497. {
  2498. case DAC960_GEM_Controller:
  2499. DAC960_GEM_DisableInterrupts(BaseAddress);
  2500. DAC960_GEM_AcknowledgeHardwareMailboxStatus(BaseAddress);
  2501. udelay(1000);
  2502. while (DAC960_GEM_InitializationInProgressP(BaseAddress))
  2503. {
  2504. if (DAC960_GEM_ReadErrorStatus(BaseAddress, &ErrorStatus,
  2505. &Parameter0, &Parameter1) &&
  2506. DAC960_ReportErrorStatus(Controller, ErrorStatus,
  2507. Parameter0, Parameter1))
  2508. goto Failure;
  2509. udelay(10);
  2510. }
  2511. if (!DAC960_V2_EnableMemoryMailboxInterface(Controller))
  2512. {
  2513. DAC960_Error("Unable to Enable Memory Mailbox Interface "
  2514. "for Controller at\n", Controller);
  2515. goto Failure;
  2516. }
  2517. DAC960_GEM_EnableInterrupts(BaseAddress);
  2518. Controller->QueueCommand = DAC960_GEM_QueueCommand;
  2519. Controller->ReadControllerConfiguration =
  2520. DAC960_V2_ReadControllerConfiguration;
  2521. Controller->ReadDeviceConfiguration =
  2522. DAC960_V2_ReadDeviceConfiguration;
  2523. Controller->ReportDeviceConfiguration =
  2524. DAC960_V2_ReportDeviceConfiguration;
  2525. Controller->QueueReadWriteCommand =
  2526. DAC960_V2_QueueReadWriteCommand;
  2527. break;
  2528. case DAC960_BA_Controller:
  2529. DAC960_BA_DisableInterrupts(BaseAddress);
  2530. DAC960_BA_AcknowledgeHardwareMailboxStatus(BaseAddress);
  2531. udelay(1000);
  2532. while (DAC960_BA_InitializationInProgressP(BaseAddress))
  2533. {
  2534. if (DAC960_BA_ReadErrorStatus(BaseAddress, &ErrorStatus,
  2535. &Parameter0, &Parameter1) &&
  2536. DAC960_ReportErrorStatus(Controller, ErrorStatus,
  2537. Parameter0, Parameter1))
  2538. goto Failure;
  2539. udelay(10);
  2540. }
  2541. if (!DAC960_V2_EnableMemoryMailboxInterface(Controller))
  2542. {
  2543. DAC960_Error("Unable to Enable Memory Mailbox Interface "
  2544. "for Controller at\n", Controller);
  2545. goto Failure;
  2546. }
  2547. DAC960_BA_EnableInterrupts(BaseAddress);
  2548. Controller->QueueCommand = DAC960_BA_QueueCommand;
  2549. Controller->ReadControllerConfiguration =
  2550. DAC960_V2_ReadControllerConfiguration;
  2551. Controller->ReadDeviceConfiguration =
  2552. DAC960_V2_ReadDeviceConfiguration;
  2553. Controller->ReportDeviceConfiguration =
  2554. DAC960_V2_ReportDeviceConfiguration;
  2555. Controller->QueueReadWriteCommand =
  2556. DAC960_V2_QueueReadWriteCommand;
  2557. break;
  2558. case DAC960_LP_Controller:
  2559. DAC960_LP_DisableInterrupts(BaseAddress);
  2560. DAC960_LP_AcknowledgeHardwareMailboxStatus(BaseAddress);
  2561. udelay(1000);
  2562. while (DAC960_LP_InitializationInProgressP(BaseAddress))
  2563. {
  2564. if (DAC960_LP_ReadErrorStatus(BaseAddress, &ErrorStatus,
  2565. &Parameter0, &Parameter1) &&
  2566. DAC960_ReportErrorStatus(Controller, ErrorStatus,
  2567. Parameter0, Parameter1))
  2568. goto Failure;
  2569. udelay(10);
  2570. }
  2571. if (!DAC960_V2_EnableMemoryMailboxInterface(Controller))
  2572. {
  2573. DAC960_Error("Unable to Enable Memory Mailbox Interface "
  2574. "for Controller at\n", Controller);
  2575. goto Failure;
  2576. }
  2577. DAC960_LP_EnableInterrupts(BaseAddress);
  2578. Controller->QueueCommand = DAC960_LP_QueueCommand;
  2579. Controller->ReadControllerConfiguration =
  2580. DAC960_V2_ReadControllerConfiguration;
  2581. Controller->ReadDeviceConfiguration =
  2582. DAC960_V2_ReadDeviceConfiguration;
  2583. Controller->ReportDeviceConfiguration =
  2584. DAC960_V2_ReportDeviceConfiguration;
  2585. Controller->QueueReadWriteCommand =
  2586. DAC960_V2_QueueReadWriteCommand;
  2587. break;
  2588. case DAC960_LA_Controller:
  2589. DAC960_LA_DisableInterrupts(BaseAddress);
  2590. DAC960_LA_AcknowledgeHardwareMailboxStatus(BaseAddress);
  2591. udelay(1000);
  2592. while (DAC960_LA_InitializationInProgressP(BaseAddress))
  2593. {
  2594. if (DAC960_LA_ReadErrorStatus(BaseAddress, &ErrorStatus,
  2595. &Parameter0, &Parameter1) &&
  2596. DAC960_ReportErrorStatus(Controller, ErrorStatus,
  2597. Parameter0, Parameter1))
  2598. goto Failure;
  2599. udelay(10);
  2600. }
  2601. if (!DAC960_V1_EnableMemoryMailboxInterface(Controller))
  2602. {
  2603. DAC960_Error("Unable to Enable Memory Mailbox Interface "
  2604. "for Controller at\n", Controller);
  2605. goto Failure;
  2606. }
  2607. DAC960_LA_EnableInterrupts(BaseAddress);
  2608. if (Controller->V1.DualModeMemoryMailboxInterface)
  2609. Controller->QueueCommand = DAC960_LA_QueueCommandDualMode;
  2610. else Controller->QueueCommand = DAC960_LA_QueueCommandSingleMode;
  2611. Controller->ReadControllerConfiguration =
  2612. DAC960_V1_ReadControllerConfiguration;
  2613. Controller->ReadDeviceConfiguration =
  2614. DAC960_V1_ReadDeviceConfiguration;
  2615. Controller->ReportDeviceConfiguration =
  2616. DAC960_V1_ReportDeviceConfiguration;
  2617. Controller->QueueReadWriteCommand =
  2618. DAC960_V1_QueueReadWriteCommand;
  2619. break;
  2620. case DAC960_PG_Controller:
  2621. DAC960_PG_DisableInterrupts(BaseAddress);
  2622. DAC960_PG_AcknowledgeHardwareMailboxStatus(BaseAddress);
  2623. udelay(1000);
  2624. while (DAC960_PG_InitializationInProgressP(BaseAddress))
  2625. {
  2626. if (DAC960_PG_ReadErrorStatus(BaseAddress, &ErrorStatus,
  2627. &Parameter0, &Parameter1) &&
  2628. DAC960_ReportErrorStatus(Controller, ErrorStatus,
  2629. Parameter0, Parameter1))
  2630. goto Failure;
  2631. udelay(10);
  2632. }
  2633. if (!DAC960_V1_EnableMemoryMailboxInterface(Controller))
  2634. {
  2635. DAC960_Error("Unable to Enable Memory Mailbox Interface "
  2636. "for Controller at\n", Controller);
  2637. goto Failure;
  2638. }
  2639. DAC960_PG_EnableInterrupts(BaseAddress);
  2640. if (Controller->V1.DualModeMemoryMailboxInterface)
  2641. Controller->QueueCommand = DAC960_PG_QueueCommandDualMode;
  2642. else Controller->QueueCommand = DAC960_PG_QueueCommandSingleMode;
  2643. Controller->ReadControllerConfiguration =
  2644. DAC960_V1_ReadControllerConfiguration;
  2645. Controller->ReadDeviceConfiguration =
  2646. DAC960_V1_ReadDeviceConfiguration;
  2647. Controller->ReportDeviceConfiguration =
  2648. DAC960_V1_ReportDeviceConfiguration;
  2649. Controller->QueueReadWriteCommand =
  2650. DAC960_V1_QueueReadWriteCommand;
  2651. break;
  2652. case DAC960_PD_Controller:
  2653. if (!request_region(Controller->IO_Address, 0x80,
  2654. Controller->FullModelName)) {
  2655. DAC960_Error("IO port 0x%d busy for Controller at\n",
  2656. Controller, Controller->IO_Address);
  2657. goto Failure;
  2658. }
  2659. DAC960_PD_DisableInterrupts(BaseAddress);
  2660. DAC960_PD_AcknowledgeStatus(BaseAddress);
  2661. udelay(1000);
  2662. while (DAC960_PD_InitializationInProgressP(BaseAddress))
  2663. {
  2664. if (DAC960_PD_ReadErrorStatus(BaseAddress, &ErrorStatus,
  2665. &Parameter0, &Parameter1) &&
  2666. DAC960_ReportErrorStatus(Controller, ErrorStatus,
  2667. Parameter0, Parameter1))
  2668. goto Failure;
  2669. udelay(10);
  2670. }
  2671. if (!DAC960_V1_EnableMemoryMailboxInterface(Controller))
  2672. {
  2673. DAC960_Error("Unable to allocate DMA mapped memory "
  2674. "for Controller at\n", Controller);
  2675. goto Failure;
  2676. }
  2677. DAC960_PD_EnableInterrupts(BaseAddress);
  2678. Controller->QueueCommand = DAC960_PD_QueueCommand;
  2679. Controller->ReadControllerConfiguration =
  2680. DAC960_V1_ReadControllerConfiguration;
  2681. Controller->ReadDeviceConfiguration =
  2682. DAC960_V1_ReadDeviceConfiguration;
  2683. Controller->ReportDeviceConfiguration =
  2684. DAC960_V1_ReportDeviceConfiguration;
  2685. Controller->QueueReadWriteCommand =
  2686. DAC960_V1_QueueReadWriteCommand;
  2687. break;
  2688. case DAC960_P_Controller:
  2689. if (!request_region(Controller->IO_Address, 0x80,
  2690. Controller->FullModelName)){
  2691. DAC960_Error("IO port 0x%d busy for Controller at\n",
  2692. Controller, Controller->IO_Address);
  2693. goto Failure;
  2694. }
  2695. DAC960_PD_DisableInterrupts(BaseAddress);
  2696. DAC960_PD_AcknowledgeStatus(BaseAddress);
  2697. udelay(1000);
  2698. while (DAC960_PD_InitializationInProgressP(BaseAddress))
  2699. {
  2700. if (DAC960_PD_ReadErrorStatus(BaseAddress, &ErrorStatus,
  2701. &Parameter0, &Parameter1) &&
  2702. DAC960_ReportErrorStatus(Controller, ErrorStatus,
  2703. Parameter0, Parameter1))
  2704. goto Failure;
  2705. udelay(10);
  2706. }
  2707. if (!DAC960_V1_EnableMemoryMailboxInterface(Controller))
  2708. {
  2709. DAC960_Error("Unable to allocate DMA mapped memory"
  2710. "for Controller at\n", Controller);
  2711. goto Failure;
  2712. }
  2713. DAC960_PD_EnableInterrupts(BaseAddress);
  2714. Controller->QueueCommand = DAC960_P_QueueCommand;
  2715. Controller->ReadControllerConfiguration =
  2716. DAC960_V1_ReadControllerConfiguration;
  2717. Controller->ReadDeviceConfiguration =
  2718. DAC960_V1_ReadDeviceConfiguration;
  2719. Controller->ReportDeviceConfiguration =
  2720. DAC960_V1_ReportDeviceConfiguration;
  2721. Controller->QueueReadWriteCommand =
  2722. DAC960_V1_QueueReadWriteCommand;
  2723. break;
  2724. }
  2725. /*
  2726. Acquire shared access to the IRQ Channel.
  2727. */
  2728. IRQ_Channel = PCI_Device->irq;
  2729. if (request_irq(IRQ_Channel, InterruptHandler, IRQF_SHARED,
  2730. Controller->FullModelName, Controller) < 0)
  2731. {
  2732. DAC960_Error("Unable to acquire IRQ Channel %d for Controller at\n",
  2733. Controller, Controller->IRQ_Channel);
  2734. goto Failure;
  2735. }
  2736. Controller->IRQ_Channel = IRQ_Channel;
  2737. Controller->InitialCommand.CommandIdentifier = 1;
  2738. Controller->InitialCommand.Controller = Controller;
  2739. Controller->Commands[0] = &Controller->InitialCommand;
  2740. Controller->FreeCommands = &Controller->InitialCommand;
  2741. return Controller;
  2742. Failure:
  2743. if (Controller->IO_Address == 0)
  2744. DAC960_Error("PCI Bus %d Device %d Function %d I/O Address N/A "
  2745. "PCI Address 0x%X\n", Controller,
  2746. Controller->Bus, Controller->Device,
  2747. Controller->Function, Controller->PCI_Address);
  2748. else
  2749. DAC960_Error("PCI Bus %d Device %d Function %d I/O Address "
  2750. "0x%X PCI Address 0x%X\n", Controller,
  2751. Controller->Bus, Controller->Device,
  2752. Controller->Function, Controller->IO_Address,
  2753. Controller->PCI_Address);
  2754. DAC960_DetectCleanup(Controller);
  2755. DAC960_ControllerCount--;
  2756. return NULL;
  2757. }
  2758. /*
  2759. DAC960_InitializeController initializes Controller.
  2760. */
  2761. static bool
  2762. DAC960_InitializeController(DAC960_Controller_T *Controller)
  2763. {
  2764. if (DAC960_ReadControllerConfiguration(Controller) &&
  2765. DAC960_ReportControllerConfiguration(Controller) &&
  2766. DAC960_CreateAuxiliaryStructures(Controller) &&
  2767. DAC960_ReadDeviceConfiguration(Controller) &&
  2768. DAC960_ReportDeviceConfiguration(Controller) &&
  2769. DAC960_RegisterBlockDevice(Controller))
  2770. {
  2771. /*
  2772. Initialize the Monitoring Timer.
  2773. */
  2774. init_timer(&Controller->MonitoringTimer);
  2775. Controller->MonitoringTimer.expires =
  2776. jiffies + DAC960_MonitoringTimerInterval;
  2777. Controller->MonitoringTimer.data = (unsigned long) Controller;
  2778. Controller->MonitoringTimer.function = DAC960_MonitoringTimerFunction;
  2779. add_timer(&Controller->MonitoringTimer);
  2780. Controller->ControllerInitialized = true;
  2781. return true;
  2782. }
  2783. return false;
  2784. }
  2785. /*
  2786. DAC960_FinalizeController finalizes Controller.
  2787. */
  2788. static void DAC960_FinalizeController(DAC960_Controller_T *Controller)
  2789. {
  2790. if (Controller->ControllerInitialized)
  2791. {
  2792. unsigned long flags;
  2793. /*
  2794. * Acquiring and releasing lock here eliminates
  2795. * a very low probability race.
  2796. *
  2797. * The code below allocates controller command structures
  2798. * from the free list without holding the controller lock.
  2799. * This is safe assuming there is no other activity on
  2800. * the controller at the time.
  2801. *
  2802. * But, there might be a monitoring command still
  2803. * in progress. Setting the Shutdown flag while holding
  2804. * the lock ensures that there is no monitoring command
  2805. * in the interrupt handler currently, and any monitoring
  2806. * commands that complete from this time on will NOT return
  2807. * their command structure to the free list.
  2808. */
  2809. spin_lock_irqsave(&Controller->queue_lock, flags);
  2810. Controller->ShutdownMonitoringTimer = 1;
  2811. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  2812. del_timer_sync(&Controller->MonitoringTimer);
  2813. if (Controller->FirmwareType == DAC960_V1_Controller)
  2814. {
  2815. DAC960_Notice("Flushing Cache...", Controller);
  2816. DAC960_V1_ExecuteType3(Controller, DAC960_V1_Flush, 0);
  2817. DAC960_Notice("done\n", Controller);
  2818. if (Controller->HardwareType == DAC960_PD_Controller)
  2819. release_region(Controller->IO_Address, 0x80);
  2820. }
  2821. else
  2822. {
  2823. DAC960_Notice("Flushing Cache...", Controller);
  2824. DAC960_V2_DeviceOperation(Controller, DAC960_V2_PauseDevice,
  2825. DAC960_V2_RAID_Controller);
  2826. DAC960_Notice("done\n", Controller);
  2827. }
  2828. }
  2829. DAC960_UnregisterBlockDevice(Controller);
  2830. DAC960_DestroyAuxiliaryStructures(Controller);
  2831. DAC960_DestroyProcEntries(Controller);
  2832. DAC960_DetectCleanup(Controller);
  2833. }
  2834. /*
  2835. DAC960_Probe verifies controller's existence and
  2836. initializes the DAC960 Driver for that controller.
  2837. */
  2838. static int
  2839. DAC960_Probe(struct pci_dev *dev, const struct pci_device_id *entry)
  2840. {
  2841. int disk;
  2842. DAC960_Controller_T *Controller;
  2843. if (DAC960_ControllerCount == DAC960_MaxControllers)
  2844. {
  2845. DAC960_Error("More than %d DAC960 Controllers detected - "
  2846. "ignoring from Controller at\n",
  2847. NULL, DAC960_MaxControllers);
  2848. return -ENODEV;
  2849. }
  2850. Controller = DAC960_DetectController(dev, entry);
  2851. if (!Controller)
  2852. return -ENODEV;
  2853. if (!DAC960_InitializeController(Controller)) {
  2854. DAC960_FinalizeController(Controller);
  2855. return -ENODEV;
  2856. }
  2857. for (disk = 0; disk < DAC960_MaxLogicalDrives; disk++) {
  2858. set_capacity(Controller->disks[disk], disk_size(Controller, disk));
  2859. add_disk(Controller->disks[disk]);
  2860. }
  2861. DAC960_CreateProcEntries(Controller);
  2862. return 0;
  2863. }
  2864. /*
  2865. DAC960_Finalize finalizes the DAC960 Driver.
  2866. */
  2867. static void DAC960_Remove(struct pci_dev *PCI_Device)
  2868. {
  2869. int Controller_Number = (long)pci_get_drvdata(PCI_Device);
  2870. DAC960_Controller_T *Controller = DAC960_Controllers[Controller_Number];
  2871. if (Controller != NULL)
  2872. DAC960_FinalizeController(Controller);
  2873. }
  2874. /*
  2875. DAC960_V1_QueueReadWriteCommand prepares and queues a Read/Write Command for
  2876. DAC960 V1 Firmware Controllers.
  2877. */
  2878. static void DAC960_V1_QueueReadWriteCommand(DAC960_Command_T *Command)
  2879. {
  2880. DAC960_Controller_T *Controller = Command->Controller;
  2881. DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  2882. DAC960_V1_ScatterGatherSegment_T *ScatterGatherList =
  2883. Command->V1.ScatterGatherList;
  2884. struct scatterlist *ScatterList = Command->V1.ScatterList;
  2885. DAC960_V1_ClearCommand(Command);
  2886. if (Command->SegmentCount == 1)
  2887. {
  2888. if (Command->DmaDirection == PCI_DMA_FROMDEVICE)
  2889. CommandMailbox->Type5.CommandOpcode = DAC960_V1_Read;
  2890. else
  2891. CommandMailbox->Type5.CommandOpcode = DAC960_V1_Write;
  2892. CommandMailbox->Type5.LD.TransferLength = Command->BlockCount;
  2893. CommandMailbox->Type5.LD.LogicalDriveNumber = Command->LogicalDriveNumber;
  2894. CommandMailbox->Type5.LogicalBlockAddress = Command->BlockNumber;
  2895. CommandMailbox->Type5.BusAddress =
  2896. (DAC960_BusAddress32_T)sg_dma_address(ScatterList);
  2897. }
  2898. else
  2899. {
  2900. int i;
  2901. if (Command->DmaDirection == PCI_DMA_FROMDEVICE)
  2902. CommandMailbox->Type5.CommandOpcode = DAC960_V1_ReadWithScatterGather;
  2903. else
  2904. CommandMailbox->Type5.CommandOpcode = DAC960_V1_WriteWithScatterGather;
  2905. CommandMailbox->Type5.LD.TransferLength = Command->BlockCount;
  2906. CommandMailbox->Type5.LD.LogicalDriveNumber = Command->LogicalDriveNumber;
  2907. CommandMailbox->Type5.LogicalBlockAddress = Command->BlockNumber;
  2908. CommandMailbox->Type5.BusAddress = Command->V1.ScatterGatherListDMA;
  2909. CommandMailbox->Type5.ScatterGatherCount = Command->SegmentCount;
  2910. for (i = 0; i < Command->SegmentCount; i++, ScatterList++, ScatterGatherList++) {
  2911. ScatterGatherList->SegmentDataPointer =
  2912. (DAC960_BusAddress32_T)sg_dma_address(ScatterList);
  2913. ScatterGatherList->SegmentByteCount =
  2914. (DAC960_ByteCount32_T)sg_dma_len(ScatterList);
  2915. }
  2916. }
  2917. DAC960_QueueCommand(Command);
  2918. }
  2919. /*
  2920. DAC960_V2_QueueReadWriteCommand prepares and queues a Read/Write Command for
  2921. DAC960 V2 Firmware Controllers.
  2922. */
  2923. static void DAC960_V2_QueueReadWriteCommand(DAC960_Command_T *Command)
  2924. {
  2925. DAC960_Controller_T *Controller = Command->Controller;
  2926. DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  2927. struct scatterlist *ScatterList = Command->V2.ScatterList;
  2928. DAC960_V2_ClearCommand(Command);
  2929. CommandMailbox->SCSI_10.CommandOpcode = DAC960_V2_SCSI_10;
  2930. CommandMailbox->SCSI_10.CommandControlBits.DataTransferControllerToHost =
  2931. (Command->DmaDirection == PCI_DMA_FROMDEVICE);
  2932. CommandMailbox->SCSI_10.DataTransferSize =
  2933. Command->BlockCount << DAC960_BlockSizeBits;
  2934. CommandMailbox->SCSI_10.RequestSenseBusAddress = Command->V2.RequestSenseDMA;
  2935. CommandMailbox->SCSI_10.PhysicalDevice =
  2936. Controller->V2.LogicalDriveToVirtualDevice[Command->LogicalDriveNumber];
  2937. CommandMailbox->SCSI_10.RequestSenseSize = sizeof(DAC960_SCSI_RequestSense_T);
  2938. CommandMailbox->SCSI_10.CDBLength = 10;
  2939. CommandMailbox->SCSI_10.SCSI_CDB[0] =
  2940. (Command->DmaDirection == PCI_DMA_FROMDEVICE ? 0x28 : 0x2A);
  2941. CommandMailbox->SCSI_10.SCSI_CDB[2] = Command->BlockNumber >> 24;
  2942. CommandMailbox->SCSI_10.SCSI_CDB[3] = Command->BlockNumber >> 16;
  2943. CommandMailbox->SCSI_10.SCSI_CDB[4] = Command->BlockNumber >> 8;
  2944. CommandMailbox->SCSI_10.SCSI_CDB[5] = Command->BlockNumber;
  2945. CommandMailbox->SCSI_10.SCSI_CDB[7] = Command->BlockCount >> 8;
  2946. CommandMailbox->SCSI_10.SCSI_CDB[8] = Command->BlockCount;
  2947. if (Command->SegmentCount == 1)
  2948. {
  2949. CommandMailbox->SCSI_10.DataTransferMemoryAddress
  2950. .ScatterGatherSegments[0]
  2951. .SegmentDataPointer =
  2952. (DAC960_BusAddress64_T)sg_dma_address(ScatterList);
  2953. CommandMailbox->SCSI_10.DataTransferMemoryAddress
  2954. .ScatterGatherSegments[0]
  2955. .SegmentByteCount =
  2956. CommandMailbox->SCSI_10.DataTransferSize;
  2957. }
  2958. else
  2959. {
  2960. DAC960_V2_ScatterGatherSegment_T *ScatterGatherList;
  2961. int i;
  2962. if (Command->SegmentCount > 2)
  2963. {
  2964. ScatterGatherList = Command->V2.ScatterGatherList;
  2965. CommandMailbox->SCSI_10.CommandControlBits
  2966. .AdditionalScatterGatherListMemory = true;
  2967. CommandMailbox->SCSI_10.DataTransferMemoryAddress
  2968. .ExtendedScatterGather.ScatterGatherList0Length = Command->SegmentCount;
  2969. CommandMailbox->SCSI_10.DataTransferMemoryAddress
  2970. .ExtendedScatterGather.ScatterGatherList0Address =
  2971. Command->V2.ScatterGatherListDMA;
  2972. }
  2973. else
  2974. ScatterGatherList = CommandMailbox->SCSI_10.DataTransferMemoryAddress
  2975. .ScatterGatherSegments;
  2976. for (i = 0; i < Command->SegmentCount; i++, ScatterList++, ScatterGatherList++) {
  2977. ScatterGatherList->SegmentDataPointer =
  2978. (DAC960_BusAddress64_T)sg_dma_address(ScatterList);
  2979. ScatterGatherList->SegmentByteCount =
  2980. (DAC960_ByteCount64_T)sg_dma_len(ScatterList);
  2981. }
  2982. }
  2983. DAC960_QueueCommand(Command);
  2984. }
  2985. static int DAC960_process_queue(DAC960_Controller_T *Controller, struct request_queue *req_q)
  2986. {
  2987. struct request *Request;
  2988. DAC960_Command_T *Command;
  2989. while(1) {
  2990. Request = blk_peek_request(req_q);
  2991. if (!Request)
  2992. return 1;
  2993. Command = DAC960_AllocateCommand(Controller);
  2994. if (Command == NULL)
  2995. return 0;
  2996. if (rq_data_dir(Request) == READ) {
  2997. Command->DmaDirection = PCI_DMA_FROMDEVICE;
  2998. Command->CommandType = DAC960_ReadCommand;
  2999. } else {
  3000. Command->DmaDirection = PCI_DMA_TODEVICE;
  3001. Command->CommandType = DAC960_WriteCommand;
  3002. }
  3003. Command->Completion = Request->end_io_data;
  3004. Command->LogicalDriveNumber = (long)Request->rq_disk->private_data;
  3005. Command->BlockNumber = blk_rq_pos(Request);
  3006. Command->BlockCount = blk_rq_sectors(Request);
  3007. Command->Request = Request;
  3008. blk_start_request(Request);
  3009. Command->SegmentCount = blk_rq_map_sg(req_q,
  3010. Command->Request, Command->cmd_sglist);
  3011. /* pci_map_sg MAY change the value of SegCount */
  3012. Command->SegmentCount = pci_map_sg(Controller->PCIDevice, Command->cmd_sglist,
  3013. Command->SegmentCount, Command->DmaDirection);
  3014. DAC960_QueueReadWriteCommand(Command);
  3015. }
  3016. }
  3017. /*
  3018. DAC960_ProcessRequest attempts to remove one I/O Request from Controller's
  3019. I/O Request Queue and queues it to the Controller. WaitForCommand is true if
  3020. this function should wait for a Command to become available if necessary.
  3021. This function returns true if an I/O Request was queued and false otherwise.
  3022. */
  3023. static void DAC960_ProcessRequest(DAC960_Controller_T *controller)
  3024. {
  3025. int i;
  3026. if (!controller->ControllerInitialized)
  3027. return;
  3028. /* Do this better later! */
  3029. for (i = controller->req_q_index; i < DAC960_MaxLogicalDrives; i++) {
  3030. struct request_queue *req_q = controller->RequestQueue[i];
  3031. if (req_q == NULL)
  3032. continue;
  3033. if (!DAC960_process_queue(controller, req_q)) {
  3034. controller->req_q_index = i;
  3035. return;
  3036. }
  3037. }
  3038. if (controller->req_q_index == 0)
  3039. return;
  3040. for (i = 0; i < controller->req_q_index; i++) {
  3041. struct request_queue *req_q = controller->RequestQueue[i];
  3042. if (req_q == NULL)
  3043. continue;
  3044. if (!DAC960_process_queue(controller, req_q)) {
  3045. controller->req_q_index = i;
  3046. return;
  3047. }
  3048. }
  3049. }
  3050. /*
  3051. DAC960_queue_partial_rw extracts one bio from the request already
  3052. associated with argument command, and construct a new command block to retry I/O
  3053. only on that bio. Queue that command to the controller.
  3054. This function re-uses a previously-allocated Command,
  3055. there is no failure mode from trying to allocate a command.
  3056. */
  3057. static void DAC960_queue_partial_rw(DAC960_Command_T *Command)
  3058. {
  3059. DAC960_Controller_T *Controller = Command->Controller;
  3060. struct request *Request = Command->Request;
  3061. struct request_queue *req_q = Controller->RequestQueue[Command->LogicalDriveNumber];
  3062. if (Command->DmaDirection == PCI_DMA_FROMDEVICE)
  3063. Command->CommandType = DAC960_ReadRetryCommand;
  3064. else
  3065. Command->CommandType = DAC960_WriteRetryCommand;
  3066. /*
  3067. * We could be more efficient with these mapping requests
  3068. * and map only the portions that we need. But since this
  3069. * code should almost never be called, just go with a
  3070. * simple coding.
  3071. */
  3072. (void)blk_rq_map_sg(req_q, Command->Request, Command->cmd_sglist);
  3073. (void)pci_map_sg(Controller->PCIDevice, Command->cmd_sglist, 1, Command->DmaDirection);
  3074. /*
  3075. * Resubmitting the request sector at a time is really tedious.
  3076. * But, this should almost never happen. So, we're willing to pay
  3077. * this price so that in the end, as much of the transfer is completed
  3078. * successfully as possible.
  3079. */
  3080. Command->SegmentCount = 1;
  3081. Command->BlockNumber = blk_rq_pos(Request);
  3082. Command->BlockCount = 1;
  3083. DAC960_QueueReadWriteCommand(Command);
  3084. return;
  3085. }
  3086. /*
  3087. DAC960_RequestFunction is the I/O Request Function for DAC960 Controllers.
  3088. */
  3089. static void DAC960_RequestFunction(struct request_queue *RequestQueue)
  3090. {
  3091. DAC960_ProcessRequest(RequestQueue->queuedata);
  3092. }
  3093. /*
  3094. DAC960_ProcessCompletedBuffer performs completion processing for an
  3095. individual Buffer.
  3096. */
  3097. static inline bool DAC960_ProcessCompletedRequest(DAC960_Command_T *Command,
  3098. bool SuccessfulIO)
  3099. {
  3100. struct request *Request = Command->Request;
  3101. int Error = SuccessfulIO ? 0 : -EIO;
  3102. pci_unmap_sg(Command->Controller->PCIDevice, Command->cmd_sglist,
  3103. Command->SegmentCount, Command->DmaDirection);
  3104. if (!__blk_end_request(Request, Error, Command->BlockCount << 9)) {
  3105. if (Command->Completion) {
  3106. complete(Command->Completion);
  3107. Command->Completion = NULL;
  3108. }
  3109. return true;
  3110. }
  3111. return false;
  3112. }
  3113. /*
  3114. DAC960_V1_ReadWriteError prints an appropriate error message for Command
  3115. when an error occurs on a Read or Write operation.
  3116. */
  3117. static void DAC960_V1_ReadWriteError(DAC960_Command_T *Command)
  3118. {
  3119. DAC960_Controller_T *Controller = Command->Controller;
  3120. unsigned char *CommandName = "UNKNOWN";
  3121. switch (Command->CommandType)
  3122. {
  3123. case DAC960_ReadCommand:
  3124. case DAC960_ReadRetryCommand:
  3125. CommandName = "READ";
  3126. break;
  3127. case DAC960_WriteCommand:
  3128. case DAC960_WriteRetryCommand:
  3129. CommandName = "WRITE";
  3130. break;
  3131. case DAC960_MonitoringCommand:
  3132. case DAC960_ImmediateCommand:
  3133. case DAC960_QueuedCommand:
  3134. break;
  3135. }
  3136. switch (Command->V1.CommandStatus)
  3137. {
  3138. case DAC960_V1_IrrecoverableDataError:
  3139. DAC960_Error("Irrecoverable Data Error on %s:\n",
  3140. Controller, CommandName);
  3141. break;
  3142. case DAC960_V1_LogicalDriveNonexistentOrOffline:
  3143. DAC960_Error("Logical Drive Nonexistent or Offline on %s:\n",
  3144. Controller, CommandName);
  3145. break;
  3146. case DAC960_V1_AccessBeyondEndOfLogicalDrive:
  3147. DAC960_Error("Attempt to Access Beyond End of Logical Drive "
  3148. "on %s:\n", Controller, CommandName);
  3149. break;
  3150. case DAC960_V1_BadDataEncountered:
  3151. DAC960_Error("Bad Data Encountered on %s:\n", Controller, CommandName);
  3152. break;
  3153. default:
  3154. DAC960_Error("Unexpected Error Status %04X on %s:\n",
  3155. Controller, Command->V1.CommandStatus, CommandName);
  3156. break;
  3157. }
  3158. DAC960_Error(" /dev/rd/c%dd%d: absolute blocks %u..%u\n",
  3159. Controller, Controller->ControllerNumber,
  3160. Command->LogicalDriveNumber, Command->BlockNumber,
  3161. Command->BlockNumber + Command->BlockCount - 1);
  3162. }
  3163. /*
  3164. DAC960_V1_ProcessCompletedCommand performs completion processing for Command
  3165. for DAC960 V1 Firmware Controllers.
  3166. */
  3167. static void DAC960_V1_ProcessCompletedCommand(DAC960_Command_T *Command)
  3168. {
  3169. DAC960_Controller_T *Controller = Command->Controller;
  3170. DAC960_CommandType_T CommandType = Command->CommandType;
  3171. DAC960_V1_CommandOpcode_T CommandOpcode =
  3172. Command->V1.CommandMailbox.Common.CommandOpcode;
  3173. DAC960_V1_CommandStatus_T CommandStatus = Command->V1.CommandStatus;
  3174. if (CommandType == DAC960_ReadCommand ||
  3175. CommandType == DAC960_WriteCommand)
  3176. {
  3177. #ifdef FORCE_RETRY_DEBUG
  3178. CommandStatus = DAC960_V1_IrrecoverableDataError;
  3179. #endif
  3180. if (CommandStatus == DAC960_V1_NormalCompletion) {
  3181. if (!DAC960_ProcessCompletedRequest(Command, true))
  3182. BUG();
  3183. } else if (CommandStatus == DAC960_V1_IrrecoverableDataError ||
  3184. CommandStatus == DAC960_V1_BadDataEncountered)
  3185. {
  3186. /*
  3187. * break the command down into pieces and resubmit each
  3188. * piece, hoping that some of them will succeed.
  3189. */
  3190. DAC960_queue_partial_rw(Command);
  3191. return;
  3192. }
  3193. else
  3194. {
  3195. if (CommandStatus != DAC960_V1_LogicalDriveNonexistentOrOffline)
  3196. DAC960_V1_ReadWriteError(Command);
  3197. if (!DAC960_ProcessCompletedRequest(Command, false))
  3198. BUG();
  3199. }
  3200. }
  3201. else if (CommandType == DAC960_ReadRetryCommand ||
  3202. CommandType == DAC960_WriteRetryCommand)
  3203. {
  3204. bool normal_completion;
  3205. #ifdef FORCE_RETRY_FAILURE_DEBUG
  3206. static int retry_count = 1;
  3207. #endif
  3208. /*
  3209. Perform completion processing for the portion that was
  3210. retried, and submit the next portion, if any.
  3211. */
  3212. normal_completion = true;
  3213. if (CommandStatus != DAC960_V1_NormalCompletion) {
  3214. normal_completion = false;
  3215. if (CommandStatus != DAC960_V1_LogicalDriveNonexistentOrOffline)
  3216. DAC960_V1_ReadWriteError(Command);
  3217. }
  3218. #ifdef FORCE_RETRY_FAILURE_DEBUG
  3219. if (!(++retry_count % 10000)) {
  3220. printk("V1 error retry failure test\n");
  3221. normal_completion = false;
  3222. DAC960_V1_ReadWriteError(Command);
  3223. }
  3224. #endif
  3225. if (!DAC960_ProcessCompletedRequest(Command, normal_completion)) {
  3226. DAC960_queue_partial_rw(Command);
  3227. return;
  3228. }
  3229. }
  3230. else if (CommandType == DAC960_MonitoringCommand)
  3231. {
  3232. if (Controller->ShutdownMonitoringTimer)
  3233. return;
  3234. if (CommandOpcode == DAC960_V1_Enquiry)
  3235. {
  3236. DAC960_V1_Enquiry_T *OldEnquiry = &Controller->V1.Enquiry;
  3237. DAC960_V1_Enquiry_T *NewEnquiry = Controller->V1.NewEnquiry;
  3238. unsigned int OldCriticalLogicalDriveCount =
  3239. OldEnquiry->CriticalLogicalDriveCount;
  3240. unsigned int NewCriticalLogicalDriveCount =
  3241. NewEnquiry->CriticalLogicalDriveCount;
  3242. if (NewEnquiry->NumberOfLogicalDrives > Controller->LogicalDriveCount)
  3243. {
  3244. int LogicalDriveNumber = Controller->LogicalDriveCount - 1;
  3245. while (++LogicalDriveNumber < NewEnquiry->NumberOfLogicalDrives)
  3246. DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
  3247. "Now Exists\n", Controller,
  3248. LogicalDriveNumber,
  3249. Controller->ControllerNumber,
  3250. LogicalDriveNumber);
  3251. Controller->LogicalDriveCount = NewEnquiry->NumberOfLogicalDrives;
  3252. DAC960_ComputeGenericDiskInfo(Controller);
  3253. }
  3254. if (NewEnquiry->NumberOfLogicalDrives < Controller->LogicalDriveCount)
  3255. {
  3256. int LogicalDriveNumber = NewEnquiry->NumberOfLogicalDrives - 1;
  3257. while (++LogicalDriveNumber < Controller->LogicalDriveCount)
  3258. DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
  3259. "No Longer Exists\n", Controller,
  3260. LogicalDriveNumber,
  3261. Controller->ControllerNumber,
  3262. LogicalDriveNumber);
  3263. Controller->LogicalDriveCount = NewEnquiry->NumberOfLogicalDrives;
  3264. DAC960_ComputeGenericDiskInfo(Controller);
  3265. }
  3266. if (NewEnquiry->StatusFlags.DeferredWriteError !=
  3267. OldEnquiry->StatusFlags.DeferredWriteError)
  3268. DAC960_Critical("Deferred Write Error Flag is now %s\n", Controller,
  3269. (NewEnquiry->StatusFlags.DeferredWriteError
  3270. ? "TRUE" : "FALSE"));
  3271. if ((NewCriticalLogicalDriveCount > 0 ||
  3272. NewCriticalLogicalDriveCount != OldCriticalLogicalDriveCount) ||
  3273. (NewEnquiry->OfflineLogicalDriveCount > 0 ||
  3274. NewEnquiry->OfflineLogicalDriveCount !=
  3275. OldEnquiry->OfflineLogicalDriveCount) ||
  3276. (NewEnquiry->DeadDriveCount > 0 ||
  3277. NewEnquiry->DeadDriveCount !=
  3278. OldEnquiry->DeadDriveCount) ||
  3279. (NewEnquiry->EventLogSequenceNumber !=
  3280. OldEnquiry->EventLogSequenceNumber) ||
  3281. Controller->MonitoringTimerCount == 0 ||
  3282. time_after_eq(jiffies, Controller->SecondaryMonitoringTime
  3283. + DAC960_SecondaryMonitoringInterval))
  3284. {
  3285. Controller->V1.NeedLogicalDriveInformation = true;
  3286. Controller->V1.NewEventLogSequenceNumber =
  3287. NewEnquiry->EventLogSequenceNumber;
  3288. Controller->V1.NeedErrorTableInformation = true;
  3289. Controller->V1.NeedDeviceStateInformation = true;
  3290. Controller->V1.StartDeviceStateScan = true;
  3291. Controller->V1.NeedBackgroundInitializationStatus =
  3292. Controller->V1.BackgroundInitializationStatusSupported;
  3293. Controller->SecondaryMonitoringTime = jiffies;
  3294. }
  3295. if (NewEnquiry->RebuildFlag == DAC960_V1_StandbyRebuildInProgress ||
  3296. NewEnquiry->RebuildFlag
  3297. == DAC960_V1_BackgroundRebuildInProgress ||
  3298. OldEnquiry->RebuildFlag == DAC960_V1_StandbyRebuildInProgress ||
  3299. OldEnquiry->RebuildFlag == DAC960_V1_BackgroundRebuildInProgress)
  3300. {
  3301. Controller->V1.NeedRebuildProgress = true;
  3302. Controller->V1.RebuildProgressFirst =
  3303. (NewEnquiry->CriticalLogicalDriveCount <
  3304. OldEnquiry->CriticalLogicalDriveCount);
  3305. }
  3306. if (OldEnquiry->RebuildFlag == DAC960_V1_BackgroundCheckInProgress)
  3307. switch (NewEnquiry->RebuildFlag)
  3308. {
  3309. case DAC960_V1_NoStandbyRebuildOrCheckInProgress:
  3310. DAC960_Progress("Consistency Check Completed Successfully\n",
  3311. Controller);
  3312. break;
  3313. case DAC960_V1_StandbyRebuildInProgress:
  3314. case DAC960_V1_BackgroundRebuildInProgress:
  3315. break;
  3316. case DAC960_V1_BackgroundCheckInProgress:
  3317. Controller->V1.NeedConsistencyCheckProgress = true;
  3318. break;
  3319. case DAC960_V1_StandbyRebuildCompletedWithError:
  3320. DAC960_Progress("Consistency Check Completed with Error\n",
  3321. Controller);
  3322. break;
  3323. case DAC960_V1_BackgroundRebuildOrCheckFailed_DriveFailed:
  3324. DAC960_Progress("Consistency Check Failed - "
  3325. "Physical Device Failed\n", Controller);
  3326. break;
  3327. case DAC960_V1_BackgroundRebuildOrCheckFailed_LogicalDriveFailed:
  3328. DAC960_Progress("Consistency Check Failed - "
  3329. "Logical Drive Failed\n", Controller);
  3330. break;
  3331. case DAC960_V1_BackgroundRebuildOrCheckFailed_OtherCauses:
  3332. DAC960_Progress("Consistency Check Failed - Other Causes\n",
  3333. Controller);
  3334. break;
  3335. case DAC960_V1_BackgroundRebuildOrCheckSuccessfullyTerminated:
  3336. DAC960_Progress("Consistency Check Successfully Terminated\n",
  3337. Controller);
  3338. break;
  3339. }
  3340. else if (NewEnquiry->RebuildFlag
  3341. == DAC960_V1_BackgroundCheckInProgress)
  3342. Controller->V1.NeedConsistencyCheckProgress = true;
  3343. Controller->MonitoringAlertMode =
  3344. (NewEnquiry->CriticalLogicalDriveCount > 0 ||
  3345. NewEnquiry->OfflineLogicalDriveCount > 0 ||
  3346. NewEnquiry->DeadDriveCount > 0);
  3347. if (NewEnquiry->RebuildFlag > DAC960_V1_BackgroundCheckInProgress)
  3348. {
  3349. Controller->V1.PendingRebuildFlag = NewEnquiry->RebuildFlag;
  3350. Controller->V1.RebuildFlagPending = true;
  3351. }
  3352. memcpy(&Controller->V1.Enquiry, &Controller->V1.NewEnquiry,
  3353. sizeof(DAC960_V1_Enquiry_T));
  3354. }
  3355. else if (CommandOpcode == DAC960_V1_PerformEventLogOperation)
  3356. {
  3357. static char
  3358. *DAC960_EventMessages[] =
  3359. { "killed because write recovery failed",
  3360. "killed because of SCSI bus reset failure",
  3361. "killed because of double check condition",
  3362. "killed because it was removed",
  3363. "killed because of gross error on SCSI chip",
  3364. "killed because of bad tag returned from drive",
  3365. "killed because of timeout on SCSI command",
  3366. "killed because of reset SCSI command issued from system",
  3367. "killed because busy or parity error count exceeded limit",
  3368. "killed because of 'kill drive' command from system",
  3369. "killed because of selection timeout",
  3370. "killed due to SCSI phase sequence error",
  3371. "killed due to unknown status" };
  3372. DAC960_V1_EventLogEntry_T *EventLogEntry =
  3373. Controller->V1.EventLogEntry;
  3374. if (EventLogEntry->SequenceNumber ==
  3375. Controller->V1.OldEventLogSequenceNumber)
  3376. {
  3377. unsigned char SenseKey = EventLogEntry->SenseKey;
  3378. unsigned char AdditionalSenseCode =
  3379. EventLogEntry->AdditionalSenseCode;
  3380. unsigned char AdditionalSenseCodeQualifier =
  3381. EventLogEntry->AdditionalSenseCodeQualifier;
  3382. if (SenseKey == DAC960_SenseKey_VendorSpecific &&
  3383. AdditionalSenseCode == 0x80 &&
  3384. AdditionalSenseCodeQualifier <
  3385. ARRAY_SIZE(DAC960_EventMessages))
  3386. DAC960_Critical("Physical Device %d:%d %s\n", Controller,
  3387. EventLogEntry->Channel,
  3388. EventLogEntry->TargetID,
  3389. DAC960_EventMessages[
  3390. AdditionalSenseCodeQualifier]);
  3391. else if (SenseKey == DAC960_SenseKey_UnitAttention &&
  3392. AdditionalSenseCode == 0x29)
  3393. {
  3394. if (Controller->MonitoringTimerCount > 0)
  3395. Controller->V1.DeviceResetCount[EventLogEntry->Channel]
  3396. [EventLogEntry->TargetID]++;
  3397. }
  3398. else if (!(SenseKey == DAC960_SenseKey_NoSense ||
  3399. (SenseKey == DAC960_SenseKey_NotReady &&
  3400. AdditionalSenseCode == 0x04 &&
  3401. (AdditionalSenseCodeQualifier == 0x01 ||
  3402. AdditionalSenseCodeQualifier == 0x02))))
  3403. {
  3404. DAC960_Critical("Physical Device %d:%d Error Log: "
  3405. "Sense Key = %X, ASC = %02X, ASCQ = %02X\n",
  3406. Controller,
  3407. EventLogEntry->Channel,
  3408. EventLogEntry->TargetID,
  3409. SenseKey,
  3410. AdditionalSenseCode,
  3411. AdditionalSenseCodeQualifier);
  3412. DAC960_Critical("Physical Device %d:%d Error Log: "
  3413. "Information = %02X%02X%02X%02X "
  3414. "%02X%02X%02X%02X\n",
  3415. Controller,
  3416. EventLogEntry->Channel,
  3417. EventLogEntry->TargetID,
  3418. EventLogEntry->Information[0],
  3419. EventLogEntry->Information[1],
  3420. EventLogEntry->Information[2],
  3421. EventLogEntry->Information[3],
  3422. EventLogEntry->CommandSpecificInformation[0],
  3423. EventLogEntry->CommandSpecificInformation[1],
  3424. EventLogEntry->CommandSpecificInformation[2],
  3425. EventLogEntry->CommandSpecificInformation[3]);
  3426. }
  3427. }
  3428. Controller->V1.OldEventLogSequenceNumber++;
  3429. }
  3430. else if (CommandOpcode == DAC960_V1_GetErrorTable)
  3431. {
  3432. DAC960_V1_ErrorTable_T *OldErrorTable = &Controller->V1.ErrorTable;
  3433. DAC960_V1_ErrorTable_T *NewErrorTable = Controller->V1.NewErrorTable;
  3434. int Channel, TargetID;
  3435. for (Channel = 0; Channel < Controller->Channels; Channel++)
  3436. for (TargetID = 0; TargetID < Controller->Targets; TargetID++)
  3437. {
  3438. DAC960_V1_ErrorTableEntry_T *NewErrorEntry =
  3439. &NewErrorTable->ErrorTableEntries[Channel][TargetID];
  3440. DAC960_V1_ErrorTableEntry_T *OldErrorEntry =
  3441. &OldErrorTable->ErrorTableEntries[Channel][TargetID];
  3442. if ((NewErrorEntry->ParityErrorCount !=
  3443. OldErrorEntry->ParityErrorCount) ||
  3444. (NewErrorEntry->SoftErrorCount !=
  3445. OldErrorEntry->SoftErrorCount) ||
  3446. (NewErrorEntry->HardErrorCount !=
  3447. OldErrorEntry->HardErrorCount) ||
  3448. (NewErrorEntry->MiscErrorCount !=
  3449. OldErrorEntry->MiscErrorCount))
  3450. DAC960_Critical("Physical Device %d:%d Errors: "
  3451. "Parity = %d, Soft = %d, "
  3452. "Hard = %d, Misc = %d\n",
  3453. Controller, Channel, TargetID,
  3454. NewErrorEntry->ParityErrorCount,
  3455. NewErrorEntry->SoftErrorCount,
  3456. NewErrorEntry->HardErrorCount,
  3457. NewErrorEntry->MiscErrorCount);
  3458. }
  3459. memcpy(&Controller->V1.ErrorTable, Controller->V1.NewErrorTable,
  3460. sizeof(DAC960_V1_ErrorTable_T));
  3461. }
  3462. else if (CommandOpcode == DAC960_V1_GetDeviceState)
  3463. {
  3464. DAC960_V1_DeviceState_T *OldDeviceState =
  3465. &Controller->V1.DeviceState[Controller->V1.DeviceStateChannel]
  3466. [Controller->V1.DeviceStateTargetID];
  3467. DAC960_V1_DeviceState_T *NewDeviceState =
  3468. Controller->V1.NewDeviceState;
  3469. if (NewDeviceState->DeviceState != OldDeviceState->DeviceState)
  3470. DAC960_Critical("Physical Device %d:%d is now %s\n", Controller,
  3471. Controller->V1.DeviceStateChannel,
  3472. Controller->V1.DeviceStateTargetID,
  3473. (NewDeviceState->DeviceState
  3474. == DAC960_V1_Device_Dead
  3475. ? "DEAD"
  3476. : NewDeviceState->DeviceState
  3477. == DAC960_V1_Device_WriteOnly
  3478. ? "WRITE-ONLY"
  3479. : NewDeviceState->DeviceState
  3480. == DAC960_V1_Device_Online
  3481. ? "ONLINE" : "STANDBY"));
  3482. if (OldDeviceState->DeviceState == DAC960_V1_Device_Dead &&
  3483. NewDeviceState->DeviceState != DAC960_V1_Device_Dead)
  3484. {
  3485. Controller->V1.NeedDeviceInquiryInformation = true;
  3486. Controller->V1.NeedDeviceSerialNumberInformation = true;
  3487. Controller->V1.DeviceResetCount
  3488. [Controller->V1.DeviceStateChannel]
  3489. [Controller->V1.DeviceStateTargetID] = 0;
  3490. }
  3491. memcpy(OldDeviceState, NewDeviceState,
  3492. sizeof(DAC960_V1_DeviceState_T));
  3493. }
  3494. else if (CommandOpcode == DAC960_V1_GetLogicalDriveInformation)
  3495. {
  3496. int LogicalDriveNumber;
  3497. for (LogicalDriveNumber = 0;
  3498. LogicalDriveNumber < Controller->LogicalDriveCount;
  3499. LogicalDriveNumber++)
  3500. {
  3501. DAC960_V1_LogicalDriveInformation_T *OldLogicalDriveInformation =
  3502. &Controller->V1.LogicalDriveInformation[LogicalDriveNumber];
  3503. DAC960_V1_LogicalDriveInformation_T *NewLogicalDriveInformation =
  3504. &(*Controller->V1.NewLogicalDriveInformation)[LogicalDriveNumber];
  3505. if (NewLogicalDriveInformation->LogicalDriveState !=
  3506. OldLogicalDriveInformation->LogicalDriveState)
  3507. DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
  3508. "is now %s\n", Controller,
  3509. LogicalDriveNumber,
  3510. Controller->ControllerNumber,
  3511. LogicalDriveNumber,
  3512. (NewLogicalDriveInformation->LogicalDriveState
  3513. == DAC960_V1_LogicalDrive_Online
  3514. ? "ONLINE"
  3515. : NewLogicalDriveInformation->LogicalDriveState
  3516. == DAC960_V1_LogicalDrive_Critical
  3517. ? "CRITICAL" : "OFFLINE"));
  3518. if (NewLogicalDriveInformation->WriteBack !=
  3519. OldLogicalDriveInformation->WriteBack)
  3520. DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
  3521. "is now %s\n", Controller,
  3522. LogicalDriveNumber,
  3523. Controller->ControllerNumber,
  3524. LogicalDriveNumber,
  3525. (NewLogicalDriveInformation->WriteBack
  3526. ? "WRITE BACK" : "WRITE THRU"));
  3527. }
  3528. memcpy(&Controller->V1.LogicalDriveInformation,
  3529. Controller->V1.NewLogicalDriveInformation,
  3530. sizeof(DAC960_V1_LogicalDriveInformationArray_T));
  3531. }
  3532. else if (CommandOpcode == DAC960_V1_GetRebuildProgress)
  3533. {
  3534. unsigned int LogicalDriveNumber =
  3535. Controller->V1.RebuildProgress->LogicalDriveNumber;
  3536. unsigned int LogicalDriveSize =
  3537. Controller->V1.RebuildProgress->LogicalDriveSize;
  3538. unsigned int BlocksCompleted =
  3539. LogicalDriveSize - Controller->V1.RebuildProgress->RemainingBlocks;
  3540. if (CommandStatus == DAC960_V1_NoRebuildOrCheckInProgress &&
  3541. Controller->V1.LastRebuildStatus == DAC960_V1_NormalCompletion)
  3542. CommandStatus = DAC960_V1_RebuildSuccessful;
  3543. switch (CommandStatus)
  3544. {
  3545. case DAC960_V1_NormalCompletion:
  3546. Controller->EphemeralProgressMessage = true;
  3547. DAC960_Progress("Rebuild in Progress: "
  3548. "Logical Drive %d (/dev/rd/c%dd%d) "
  3549. "%d%% completed\n",
  3550. Controller, LogicalDriveNumber,
  3551. Controller->ControllerNumber,
  3552. LogicalDriveNumber,
  3553. (100 * (BlocksCompleted >> 7))
  3554. / (LogicalDriveSize >> 7));
  3555. Controller->EphemeralProgressMessage = false;
  3556. break;
  3557. case DAC960_V1_RebuildFailed_LogicalDriveFailure:
  3558. DAC960_Progress("Rebuild Failed due to "
  3559. "Logical Drive Failure\n", Controller);
  3560. break;
  3561. case DAC960_V1_RebuildFailed_BadBlocksOnOther:
  3562. DAC960_Progress("Rebuild Failed due to "
  3563. "Bad Blocks on Other Drives\n", Controller);
  3564. break;
  3565. case DAC960_V1_RebuildFailed_NewDriveFailed:
  3566. DAC960_Progress("Rebuild Failed due to "
  3567. "Failure of Drive Being Rebuilt\n", Controller);
  3568. break;
  3569. case DAC960_V1_NoRebuildOrCheckInProgress:
  3570. break;
  3571. case DAC960_V1_RebuildSuccessful:
  3572. DAC960_Progress("Rebuild Completed Successfully\n", Controller);
  3573. break;
  3574. case DAC960_V1_RebuildSuccessfullyTerminated:
  3575. DAC960_Progress("Rebuild Successfully Terminated\n", Controller);
  3576. break;
  3577. }
  3578. Controller->V1.LastRebuildStatus = CommandStatus;
  3579. if (CommandType != DAC960_MonitoringCommand &&
  3580. Controller->V1.RebuildStatusPending)
  3581. {
  3582. Command->V1.CommandStatus = Controller->V1.PendingRebuildStatus;
  3583. Controller->V1.RebuildStatusPending = false;
  3584. }
  3585. else if (CommandType == DAC960_MonitoringCommand &&
  3586. CommandStatus != DAC960_V1_NormalCompletion &&
  3587. CommandStatus != DAC960_V1_NoRebuildOrCheckInProgress)
  3588. {
  3589. Controller->V1.PendingRebuildStatus = CommandStatus;
  3590. Controller->V1.RebuildStatusPending = true;
  3591. }
  3592. }
  3593. else if (CommandOpcode == DAC960_V1_RebuildStat)
  3594. {
  3595. unsigned int LogicalDriveNumber =
  3596. Controller->V1.RebuildProgress->LogicalDriveNumber;
  3597. unsigned int LogicalDriveSize =
  3598. Controller->V1.RebuildProgress->LogicalDriveSize;
  3599. unsigned int BlocksCompleted =
  3600. LogicalDriveSize - Controller->V1.RebuildProgress->RemainingBlocks;
  3601. if (CommandStatus == DAC960_V1_NormalCompletion)
  3602. {
  3603. Controller->EphemeralProgressMessage = true;
  3604. DAC960_Progress("Consistency Check in Progress: "
  3605. "Logical Drive %d (/dev/rd/c%dd%d) "
  3606. "%d%% completed\n",
  3607. Controller, LogicalDriveNumber,
  3608. Controller->ControllerNumber,
  3609. LogicalDriveNumber,
  3610. (100 * (BlocksCompleted >> 7))
  3611. / (LogicalDriveSize >> 7));
  3612. Controller->EphemeralProgressMessage = false;
  3613. }
  3614. }
  3615. else if (CommandOpcode == DAC960_V1_BackgroundInitializationControl)
  3616. {
  3617. unsigned int LogicalDriveNumber =
  3618. Controller->V1.BackgroundInitializationStatus->LogicalDriveNumber;
  3619. unsigned int LogicalDriveSize =
  3620. Controller->V1.BackgroundInitializationStatus->LogicalDriveSize;
  3621. unsigned int BlocksCompleted =
  3622. Controller->V1.BackgroundInitializationStatus->BlocksCompleted;
  3623. switch (CommandStatus)
  3624. {
  3625. case DAC960_V1_NormalCompletion:
  3626. switch (Controller->V1.BackgroundInitializationStatus->Status)
  3627. {
  3628. case DAC960_V1_BackgroundInitializationInvalid:
  3629. break;
  3630. case DAC960_V1_BackgroundInitializationStarted:
  3631. DAC960_Progress("Background Initialization Started\n",
  3632. Controller);
  3633. break;
  3634. case DAC960_V1_BackgroundInitializationInProgress:
  3635. if (BlocksCompleted ==
  3636. Controller->V1.LastBackgroundInitializationStatus.
  3637. BlocksCompleted &&
  3638. LogicalDriveNumber ==
  3639. Controller->V1.LastBackgroundInitializationStatus.
  3640. LogicalDriveNumber)
  3641. break;
  3642. Controller->EphemeralProgressMessage = true;
  3643. DAC960_Progress("Background Initialization in Progress: "
  3644. "Logical Drive %d (/dev/rd/c%dd%d) "
  3645. "%d%% completed\n",
  3646. Controller, LogicalDriveNumber,
  3647. Controller->ControllerNumber,
  3648. LogicalDriveNumber,
  3649. (100 * (BlocksCompleted >> 7))
  3650. / (LogicalDriveSize >> 7));
  3651. Controller->EphemeralProgressMessage = false;
  3652. break;
  3653. case DAC960_V1_BackgroundInitializationSuspended:
  3654. DAC960_Progress("Background Initialization Suspended\n",
  3655. Controller);
  3656. break;
  3657. case DAC960_V1_BackgroundInitializationCancelled:
  3658. DAC960_Progress("Background Initialization Cancelled\n",
  3659. Controller);
  3660. break;
  3661. }
  3662. memcpy(&Controller->V1.LastBackgroundInitializationStatus,
  3663. Controller->V1.BackgroundInitializationStatus,
  3664. sizeof(DAC960_V1_BackgroundInitializationStatus_T));
  3665. break;
  3666. case DAC960_V1_BackgroundInitSuccessful:
  3667. if (Controller->V1.BackgroundInitializationStatus->Status ==
  3668. DAC960_V1_BackgroundInitializationInProgress)
  3669. DAC960_Progress("Background Initialization "
  3670. "Completed Successfully\n", Controller);
  3671. Controller->V1.BackgroundInitializationStatus->Status =
  3672. DAC960_V1_BackgroundInitializationInvalid;
  3673. break;
  3674. case DAC960_V1_BackgroundInitAborted:
  3675. if (Controller->V1.BackgroundInitializationStatus->Status ==
  3676. DAC960_V1_BackgroundInitializationInProgress)
  3677. DAC960_Progress("Background Initialization Aborted\n",
  3678. Controller);
  3679. Controller->V1.BackgroundInitializationStatus->Status =
  3680. DAC960_V1_BackgroundInitializationInvalid;
  3681. break;
  3682. case DAC960_V1_NoBackgroundInitInProgress:
  3683. break;
  3684. }
  3685. }
  3686. else if (CommandOpcode == DAC960_V1_DCDB)
  3687. {
  3688. /*
  3689. This is a bit ugly.
  3690. The InquiryStandardData and
  3691. the InquiryUntitSerialNumber information
  3692. retrieval operations BOTH use the DAC960_V1_DCDB
  3693. commands. the test above can't distinguish between
  3694. these two cases.
  3695. Instead, we rely on the order of code later in this
  3696. function to ensure that DeviceInquiryInformation commands
  3697. are submitted before DeviceSerialNumber commands.
  3698. */
  3699. if (Controller->V1.NeedDeviceInquiryInformation)
  3700. {
  3701. DAC960_SCSI_Inquiry_T *InquiryStandardData =
  3702. &Controller->V1.InquiryStandardData
  3703. [Controller->V1.DeviceStateChannel]
  3704. [Controller->V1.DeviceStateTargetID];
  3705. if (CommandStatus != DAC960_V1_NormalCompletion)
  3706. {
  3707. memset(InquiryStandardData, 0,
  3708. sizeof(DAC960_SCSI_Inquiry_T));
  3709. InquiryStandardData->PeripheralDeviceType = 0x1F;
  3710. }
  3711. else
  3712. memcpy(InquiryStandardData,
  3713. Controller->V1.NewInquiryStandardData,
  3714. sizeof(DAC960_SCSI_Inquiry_T));
  3715. Controller->V1.NeedDeviceInquiryInformation = false;
  3716. }
  3717. else if (Controller->V1.NeedDeviceSerialNumberInformation)
  3718. {
  3719. DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
  3720. &Controller->V1.InquiryUnitSerialNumber
  3721. [Controller->V1.DeviceStateChannel]
  3722. [Controller->V1.DeviceStateTargetID];
  3723. if (CommandStatus != DAC960_V1_NormalCompletion)
  3724. {
  3725. memset(InquiryUnitSerialNumber, 0,
  3726. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
  3727. InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
  3728. }
  3729. else
  3730. memcpy(InquiryUnitSerialNumber,
  3731. Controller->V1.NewInquiryUnitSerialNumber,
  3732. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
  3733. Controller->V1.NeedDeviceSerialNumberInformation = false;
  3734. }
  3735. }
  3736. /*
  3737. Begin submitting new monitoring commands.
  3738. */
  3739. if (Controller->V1.NewEventLogSequenceNumber
  3740. - Controller->V1.OldEventLogSequenceNumber > 0)
  3741. {
  3742. Command->V1.CommandMailbox.Type3E.CommandOpcode =
  3743. DAC960_V1_PerformEventLogOperation;
  3744. Command->V1.CommandMailbox.Type3E.OperationType =
  3745. DAC960_V1_GetEventLogEntry;
  3746. Command->V1.CommandMailbox.Type3E.OperationQualifier = 1;
  3747. Command->V1.CommandMailbox.Type3E.SequenceNumber =
  3748. Controller->V1.OldEventLogSequenceNumber;
  3749. Command->V1.CommandMailbox.Type3E.BusAddress =
  3750. Controller->V1.EventLogEntryDMA;
  3751. DAC960_QueueCommand(Command);
  3752. return;
  3753. }
  3754. if (Controller->V1.NeedErrorTableInformation)
  3755. {
  3756. Controller->V1.NeedErrorTableInformation = false;
  3757. Command->V1.CommandMailbox.Type3.CommandOpcode =
  3758. DAC960_V1_GetErrorTable;
  3759. Command->V1.CommandMailbox.Type3.BusAddress =
  3760. Controller->V1.NewErrorTableDMA;
  3761. DAC960_QueueCommand(Command);
  3762. return;
  3763. }
  3764. if (Controller->V1.NeedRebuildProgress &&
  3765. Controller->V1.RebuildProgressFirst)
  3766. {
  3767. Controller->V1.NeedRebuildProgress = false;
  3768. Command->V1.CommandMailbox.Type3.CommandOpcode =
  3769. DAC960_V1_GetRebuildProgress;
  3770. Command->V1.CommandMailbox.Type3.BusAddress =
  3771. Controller->V1.RebuildProgressDMA;
  3772. DAC960_QueueCommand(Command);
  3773. return;
  3774. }
  3775. if (Controller->V1.NeedDeviceStateInformation)
  3776. {
  3777. if (Controller->V1.NeedDeviceInquiryInformation)
  3778. {
  3779. DAC960_V1_DCDB_T *DCDB = Controller->V1.MonitoringDCDB;
  3780. dma_addr_t DCDB_DMA = Controller->V1.MonitoringDCDB_DMA;
  3781. dma_addr_t NewInquiryStandardDataDMA =
  3782. Controller->V1.NewInquiryStandardDataDMA;
  3783. Command->V1.CommandMailbox.Type3.CommandOpcode = DAC960_V1_DCDB;
  3784. Command->V1.CommandMailbox.Type3.BusAddress = DCDB_DMA;
  3785. DCDB->Channel = Controller->V1.DeviceStateChannel;
  3786. DCDB->TargetID = Controller->V1.DeviceStateTargetID;
  3787. DCDB->Direction = DAC960_V1_DCDB_DataTransferDeviceToSystem;
  3788. DCDB->EarlyStatus = false;
  3789. DCDB->Timeout = DAC960_V1_DCDB_Timeout_10_seconds;
  3790. DCDB->NoAutomaticRequestSense = false;
  3791. DCDB->DisconnectPermitted = true;
  3792. DCDB->TransferLength = sizeof(DAC960_SCSI_Inquiry_T);
  3793. DCDB->BusAddress = NewInquiryStandardDataDMA;
  3794. DCDB->CDBLength = 6;
  3795. DCDB->TransferLengthHigh4 = 0;
  3796. DCDB->SenseLength = sizeof(DCDB->SenseData);
  3797. DCDB->CDB[0] = 0x12; /* INQUIRY */
  3798. DCDB->CDB[1] = 0; /* EVPD = 0 */
  3799. DCDB->CDB[2] = 0; /* Page Code */
  3800. DCDB->CDB[3] = 0; /* Reserved */
  3801. DCDB->CDB[4] = sizeof(DAC960_SCSI_Inquiry_T);
  3802. DCDB->CDB[5] = 0; /* Control */
  3803. DAC960_QueueCommand(Command);
  3804. return;
  3805. }
  3806. if (Controller->V1.NeedDeviceSerialNumberInformation)
  3807. {
  3808. DAC960_V1_DCDB_T *DCDB = Controller->V1.MonitoringDCDB;
  3809. dma_addr_t DCDB_DMA = Controller->V1.MonitoringDCDB_DMA;
  3810. dma_addr_t NewInquiryUnitSerialNumberDMA =
  3811. Controller->V1.NewInquiryUnitSerialNumberDMA;
  3812. Command->V1.CommandMailbox.Type3.CommandOpcode = DAC960_V1_DCDB;
  3813. Command->V1.CommandMailbox.Type3.BusAddress = DCDB_DMA;
  3814. DCDB->Channel = Controller->V1.DeviceStateChannel;
  3815. DCDB->TargetID = Controller->V1.DeviceStateTargetID;
  3816. DCDB->Direction = DAC960_V1_DCDB_DataTransferDeviceToSystem;
  3817. DCDB->EarlyStatus = false;
  3818. DCDB->Timeout = DAC960_V1_DCDB_Timeout_10_seconds;
  3819. DCDB->NoAutomaticRequestSense = false;
  3820. DCDB->DisconnectPermitted = true;
  3821. DCDB->TransferLength =
  3822. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
  3823. DCDB->BusAddress = NewInquiryUnitSerialNumberDMA;
  3824. DCDB->CDBLength = 6;
  3825. DCDB->TransferLengthHigh4 = 0;
  3826. DCDB->SenseLength = sizeof(DCDB->SenseData);
  3827. DCDB->CDB[0] = 0x12; /* INQUIRY */
  3828. DCDB->CDB[1] = 1; /* EVPD = 1 */
  3829. DCDB->CDB[2] = 0x80; /* Page Code */
  3830. DCDB->CDB[3] = 0; /* Reserved */
  3831. DCDB->CDB[4] = sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T);
  3832. DCDB->CDB[5] = 0; /* Control */
  3833. DAC960_QueueCommand(Command);
  3834. return;
  3835. }
  3836. if (Controller->V1.StartDeviceStateScan)
  3837. {
  3838. Controller->V1.DeviceStateChannel = 0;
  3839. Controller->V1.DeviceStateTargetID = 0;
  3840. Controller->V1.StartDeviceStateScan = false;
  3841. }
  3842. else if (++Controller->V1.DeviceStateTargetID == Controller->Targets)
  3843. {
  3844. Controller->V1.DeviceStateChannel++;
  3845. Controller->V1.DeviceStateTargetID = 0;
  3846. }
  3847. if (Controller->V1.DeviceStateChannel < Controller->Channels)
  3848. {
  3849. Controller->V1.NewDeviceState->DeviceState =
  3850. DAC960_V1_Device_Dead;
  3851. Command->V1.CommandMailbox.Type3D.CommandOpcode =
  3852. DAC960_V1_GetDeviceState;
  3853. Command->V1.CommandMailbox.Type3D.Channel =
  3854. Controller->V1.DeviceStateChannel;
  3855. Command->V1.CommandMailbox.Type3D.TargetID =
  3856. Controller->V1.DeviceStateTargetID;
  3857. Command->V1.CommandMailbox.Type3D.BusAddress =
  3858. Controller->V1.NewDeviceStateDMA;
  3859. DAC960_QueueCommand(Command);
  3860. return;
  3861. }
  3862. Controller->V1.NeedDeviceStateInformation = false;
  3863. }
  3864. if (Controller->V1.NeedLogicalDriveInformation)
  3865. {
  3866. Controller->V1.NeedLogicalDriveInformation = false;
  3867. Command->V1.CommandMailbox.Type3.CommandOpcode =
  3868. DAC960_V1_GetLogicalDriveInformation;
  3869. Command->V1.CommandMailbox.Type3.BusAddress =
  3870. Controller->V1.NewLogicalDriveInformationDMA;
  3871. DAC960_QueueCommand(Command);
  3872. return;
  3873. }
  3874. if (Controller->V1.NeedRebuildProgress)
  3875. {
  3876. Controller->V1.NeedRebuildProgress = false;
  3877. Command->V1.CommandMailbox.Type3.CommandOpcode =
  3878. DAC960_V1_GetRebuildProgress;
  3879. Command->V1.CommandMailbox.Type3.BusAddress =
  3880. Controller->V1.RebuildProgressDMA;
  3881. DAC960_QueueCommand(Command);
  3882. return;
  3883. }
  3884. if (Controller->V1.NeedConsistencyCheckProgress)
  3885. {
  3886. Controller->V1.NeedConsistencyCheckProgress = false;
  3887. Command->V1.CommandMailbox.Type3.CommandOpcode =
  3888. DAC960_V1_RebuildStat;
  3889. Command->V1.CommandMailbox.Type3.BusAddress =
  3890. Controller->V1.RebuildProgressDMA;
  3891. DAC960_QueueCommand(Command);
  3892. return;
  3893. }
  3894. if (Controller->V1.NeedBackgroundInitializationStatus)
  3895. {
  3896. Controller->V1.NeedBackgroundInitializationStatus = false;
  3897. Command->V1.CommandMailbox.Type3B.CommandOpcode =
  3898. DAC960_V1_BackgroundInitializationControl;
  3899. Command->V1.CommandMailbox.Type3B.CommandOpcode2 = 0x20;
  3900. Command->V1.CommandMailbox.Type3B.BusAddress =
  3901. Controller->V1.BackgroundInitializationStatusDMA;
  3902. DAC960_QueueCommand(Command);
  3903. return;
  3904. }
  3905. Controller->MonitoringTimerCount++;
  3906. Controller->MonitoringTimer.expires =
  3907. jiffies + DAC960_MonitoringTimerInterval;
  3908. add_timer(&Controller->MonitoringTimer);
  3909. }
  3910. if (CommandType == DAC960_ImmediateCommand)
  3911. {
  3912. complete(Command->Completion);
  3913. Command->Completion = NULL;
  3914. return;
  3915. }
  3916. if (CommandType == DAC960_QueuedCommand)
  3917. {
  3918. DAC960_V1_KernelCommand_T *KernelCommand = Command->V1.KernelCommand;
  3919. KernelCommand->CommandStatus = Command->V1.CommandStatus;
  3920. Command->V1.KernelCommand = NULL;
  3921. if (CommandOpcode == DAC960_V1_DCDB)
  3922. Controller->V1.DirectCommandActive[KernelCommand->DCDB->Channel]
  3923. [KernelCommand->DCDB->TargetID] =
  3924. false;
  3925. DAC960_DeallocateCommand(Command);
  3926. KernelCommand->CompletionFunction(KernelCommand);
  3927. return;
  3928. }
  3929. /*
  3930. Queue a Status Monitoring Command to the Controller using the just
  3931. completed Command if one was deferred previously due to lack of a
  3932. free Command when the Monitoring Timer Function was called.
  3933. */
  3934. if (Controller->MonitoringCommandDeferred)
  3935. {
  3936. Controller->MonitoringCommandDeferred = false;
  3937. DAC960_V1_QueueMonitoringCommand(Command);
  3938. return;
  3939. }
  3940. /*
  3941. Deallocate the Command.
  3942. */
  3943. DAC960_DeallocateCommand(Command);
  3944. /*
  3945. Wake up any processes waiting on a free Command.
  3946. */
  3947. wake_up(&Controller->CommandWaitQueue);
  3948. }
  3949. /*
  3950. DAC960_V2_ReadWriteError prints an appropriate error message for Command
  3951. when an error occurs on a Read or Write operation.
  3952. */
  3953. static void DAC960_V2_ReadWriteError(DAC960_Command_T *Command)
  3954. {
  3955. DAC960_Controller_T *Controller = Command->Controller;
  3956. unsigned char *SenseErrors[] = { "NO SENSE", "RECOVERED ERROR",
  3957. "NOT READY", "MEDIUM ERROR",
  3958. "HARDWARE ERROR", "ILLEGAL REQUEST",
  3959. "UNIT ATTENTION", "DATA PROTECT",
  3960. "BLANK CHECK", "VENDOR-SPECIFIC",
  3961. "COPY ABORTED", "ABORTED COMMAND",
  3962. "EQUAL", "VOLUME OVERFLOW",
  3963. "MISCOMPARE", "RESERVED" };
  3964. unsigned char *CommandName = "UNKNOWN";
  3965. switch (Command->CommandType)
  3966. {
  3967. case DAC960_ReadCommand:
  3968. case DAC960_ReadRetryCommand:
  3969. CommandName = "READ";
  3970. break;
  3971. case DAC960_WriteCommand:
  3972. case DAC960_WriteRetryCommand:
  3973. CommandName = "WRITE";
  3974. break;
  3975. case DAC960_MonitoringCommand:
  3976. case DAC960_ImmediateCommand:
  3977. case DAC960_QueuedCommand:
  3978. break;
  3979. }
  3980. DAC960_Error("Error Condition %s on %s:\n", Controller,
  3981. SenseErrors[Command->V2.RequestSense->SenseKey], CommandName);
  3982. DAC960_Error(" /dev/rd/c%dd%d: absolute blocks %u..%u\n",
  3983. Controller, Controller->ControllerNumber,
  3984. Command->LogicalDriveNumber, Command->BlockNumber,
  3985. Command->BlockNumber + Command->BlockCount - 1);
  3986. }
  3987. /*
  3988. DAC960_V2_ReportEvent prints an appropriate message when a Controller Event
  3989. occurs.
  3990. */
  3991. static void DAC960_V2_ReportEvent(DAC960_Controller_T *Controller,
  3992. DAC960_V2_Event_T *Event)
  3993. {
  3994. DAC960_SCSI_RequestSense_T *RequestSense =
  3995. (DAC960_SCSI_RequestSense_T *) &Event->RequestSenseData;
  3996. unsigned char MessageBuffer[DAC960_LineBufferSize];
  3997. static struct { int EventCode; unsigned char *EventMessage; } EventList[] =
  3998. { /* Physical Device Events (0x0000 - 0x007F) */
  3999. { 0x0001, "P Online" },
  4000. { 0x0002, "P Standby" },
  4001. { 0x0005, "P Automatic Rebuild Started" },
  4002. { 0x0006, "P Manual Rebuild Started" },
  4003. { 0x0007, "P Rebuild Completed" },
  4004. { 0x0008, "P Rebuild Cancelled" },
  4005. { 0x0009, "P Rebuild Failed for Unknown Reasons" },
  4006. { 0x000A, "P Rebuild Failed due to New Physical Device" },
  4007. { 0x000B, "P Rebuild Failed due to Logical Drive Failure" },
  4008. { 0x000C, "S Offline" },
  4009. { 0x000D, "P Found" },
  4010. { 0x000E, "P Removed" },
  4011. { 0x000F, "P Unconfigured" },
  4012. { 0x0010, "P Expand Capacity Started" },
  4013. { 0x0011, "P Expand Capacity Completed" },
  4014. { 0x0012, "P Expand Capacity Failed" },
  4015. { 0x0013, "P Command Timed Out" },
  4016. { 0x0014, "P Command Aborted" },
  4017. { 0x0015, "P Command Retried" },
  4018. { 0x0016, "P Parity Error" },
  4019. { 0x0017, "P Soft Error" },
  4020. { 0x0018, "P Miscellaneous Error" },
  4021. { 0x0019, "P Reset" },
  4022. { 0x001A, "P Active Spare Found" },
  4023. { 0x001B, "P Warm Spare Found" },
  4024. { 0x001C, "S Sense Data Received" },
  4025. { 0x001D, "P Initialization Started" },
  4026. { 0x001E, "P Initialization Completed" },
  4027. { 0x001F, "P Initialization Failed" },
  4028. { 0x0020, "P Initialization Cancelled" },
  4029. { 0x0021, "P Failed because Write Recovery Failed" },
  4030. { 0x0022, "P Failed because SCSI Bus Reset Failed" },
  4031. { 0x0023, "P Failed because of Double Check Condition" },
  4032. { 0x0024, "P Failed because Device Cannot Be Accessed" },
  4033. { 0x0025, "P Failed because of Gross Error on SCSI Processor" },
  4034. { 0x0026, "P Failed because of Bad Tag from Device" },
  4035. { 0x0027, "P Failed because of Command Timeout" },
  4036. { 0x0028, "P Failed because of System Reset" },
  4037. { 0x0029, "P Failed because of Busy Status or Parity Error" },
  4038. { 0x002A, "P Failed because Host Set Device to Failed State" },
  4039. { 0x002B, "P Failed because of Selection Timeout" },
  4040. { 0x002C, "P Failed because of SCSI Bus Phase Error" },
  4041. { 0x002D, "P Failed because Device Returned Unknown Status" },
  4042. { 0x002E, "P Failed because Device Not Ready" },
  4043. { 0x002F, "P Failed because Device Not Found at Startup" },
  4044. { 0x0030, "P Failed because COD Write Operation Failed" },
  4045. { 0x0031, "P Failed because BDT Write Operation Failed" },
  4046. { 0x0039, "P Missing at Startup" },
  4047. { 0x003A, "P Start Rebuild Failed due to Physical Drive Too Small" },
  4048. { 0x003C, "P Temporarily Offline Device Automatically Made Online" },
  4049. { 0x003D, "P Standby Rebuild Started" },
  4050. /* Logical Device Events (0x0080 - 0x00FF) */
  4051. { 0x0080, "M Consistency Check Started" },
  4052. { 0x0081, "M Consistency Check Completed" },
  4053. { 0x0082, "M Consistency Check Cancelled" },
  4054. { 0x0083, "M Consistency Check Completed With Errors" },
  4055. { 0x0084, "M Consistency Check Failed due to Logical Drive Failure" },
  4056. { 0x0085, "M Consistency Check Failed due to Physical Device Failure" },
  4057. { 0x0086, "L Offline" },
  4058. { 0x0087, "L Critical" },
  4059. { 0x0088, "L Online" },
  4060. { 0x0089, "M Automatic Rebuild Started" },
  4061. { 0x008A, "M Manual Rebuild Started" },
  4062. { 0x008B, "M Rebuild Completed" },
  4063. { 0x008C, "M Rebuild Cancelled" },
  4064. { 0x008D, "M Rebuild Failed for Unknown Reasons" },
  4065. { 0x008E, "M Rebuild Failed due to New Physical Device" },
  4066. { 0x008F, "M Rebuild Failed due to Logical Drive Failure" },
  4067. { 0x0090, "M Initialization Started" },
  4068. { 0x0091, "M Initialization Completed" },
  4069. { 0x0092, "M Initialization Cancelled" },
  4070. { 0x0093, "M Initialization Failed" },
  4071. { 0x0094, "L Found" },
  4072. { 0x0095, "L Deleted" },
  4073. { 0x0096, "M Expand Capacity Started" },
  4074. { 0x0097, "M Expand Capacity Completed" },
  4075. { 0x0098, "M Expand Capacity Failed" },
  4076. { 0x0099, "L Bad Block Found" },
  4077. { 0x009A, "L Size Changed" },
  4078. { 0x009B, "L Type Changed" },
  4079. { 0x009C, "L Bad Data Block Found" },
  4080. { 0x009E, "L Read of Data Block in BDT" },
  4081. { 0x009F, "L Write Back Data for Disk Block Lost" },
  4082. { 0x00A0, "L Temporarily Offline RAID-5/3 Drive Made Online" },
  4083. { 0x00A1, "L Temporarily Offline RAID-6/1/0/7 Drive Made Online" },
  4084. { 0x00A2, "L Standby Rebuild Started" },
  4085. /* Fault Management Events (0x0100 - 0x017F) */
  4086. { 0x0140, "E Fan %d Failed" },
  4087. { 0x0141, "E Fan %d OK" },
  4088. { 0x0142, "E Fan %d Not Present" },
  4089. { 0x0143, "E Power Supply %d Failed" },
  4090. { 0x0144, "E Power Supply %d OK" },
  4091. { 0x0145, "E Power Supply %d Not Present" },
  4092. { 0x0146, "E Temperature Sensor %d Temperature Exceeds Safe Limit" },
  4093. { 0x0147, "E Temperature Sensor %d Temperature Exceeds Working Limit" },
  4094. { 0x0148, "E Temperature Sensor %d Temperature Normal" },
  4095. { 0x0149, "E Temperature Sensor %d Not Present" },
  4096. { 0x014A, "E Enclosure Management Unit %d Access Critical" },
  4097. { 0x014B, "E Enclosure Management Unit %d Access OK" },
  4098. { 0x014C, "E Enclosure Management Unit %d Access Offline" },
  4099. /* Controller Events (0x0180 - 0x01FF) */
  4100. { 0x0181, "C Cache Write Back Error" },
  4101. { 0x0188, "C Battery Backup Unit Found" },
  4102. { 0x0189, "C Battery Backup Unit Charge Level Low" },
  4103. { 0x018A, "C Battery Backup Unit Charge Level OK" },
  4104. { 0x0193, "C Installation Aborted" },
  4105. { 0x0195, "C Battery Backup Unit Physically Removed" },
  4106. { 0x0196, "C Memory Error During Warm Boot" },
  4107. { 0x019E, "C Memory Soft ECC Error Corrected" },
  4108. { 0x019F, "C Memory Hard ECC Error Corrected" },
  4109. { 0x01A2, "C Battery Backup Unit Failed" },
  4110. { 0x01AB, "C Mirror Race Recovery Failed" },
  4111. { 0x01AC, "C Mirror Race on Critical Drive" },
  4112. /* Controller Internal Processor Events */
  4113. { 0x0380, "C Internal Controller Hung" },
  4114. { 0x0381, "C Internal Controller Firmware Breakpoint" },
  4115. { 0x0390, "C Internal Controller i960 Processor Specific Error" },
  4116. { 0x03A0, "C Internal Controller StrongARM Processor Specific Error" },
  4117. { 0, "" } };
  4118. int EventListIndex = 0, EventCode;
  4119. unsigned char EventType, *EventMessage;
  4120. if (Event->EventCode == 0x1C &&
  4121. RequestSense->SenseKey == DAC960_SenseKey_VendorSpecific &&
  4122. (RequestSense->AdditionalSenseCode == 0x80 ||
  4123. RequestSense->AdditionalSenseCode == 0x81))
  4124. Event->EventCode = ((RequestSense->AdditionalSenseCode - 0x80) << 8) |
  4125. RequestSense->AdditionalSenseCodeQualifier;
  4126. while (true)
  4127. {
  4128. EventCode = EventList[EventListIndex].EventCode;
  4129. if (EventCode == Event->EventCode || EventCode == 0) break;
  4130. EventListIndex++;
  4131. }
  4132. EventType = EventList[EventListIndex].EventMessage[0];
  4133. EventMessage = &EventList[EventListIndex].EventMessage[2];
  4134. if (EventCode == 0)
  4135. {
  4136. DAC960_Critical("Unknown Controller Event Code %04X\n",
  4137. Controller, Event->EventCode);
  4138. return;
  4139. }
  4140. switch (EventType)
  4141. {
  4142. case 'P':
  4143. DAC960_Critical("Physical Device %d:%d %s\n", Controller,
  4144. Event->Channel, Event->TargetID, EventMessage);
  4145. break;
  4146. case 'L':
  4147. DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) %s\n", Controller,
  4148. Event->LogicalUnit, Controller->ControllerNumber,
  4149. Event->LogicalUnit, EventMessage);
  4150. break;
  4151. case 'M':
  4152. DAC960_Progress("Logical Drive %d (/dev/rd/c%dd%d) %s\n", Controller,
  4153. Event->LogicalUnit, Controller->ControllerNumber,
  4154. Event->LogicalUnit, EventMessage);
  4155. break;
  4156. case 'S':
  4157. if (RequestSense->SenseKey == DAC960_SenseKey_NoSense ||
  4158. (RequestSense->SenseKey == DAC960_SenseKey_NotReady &&
  4159. RequestSense->AdditionalSenseCode == 0x04 &&
  4160. (RequestSense->AdditionalSenseCodeQualifier == 0x01 ||
  4161. RequestSense->AdditionalSenseCodeQualifier == 0x02)))
  4162. break;
  4163. DAC960_Critical("Physical Device %d:%d %s\n", Controller,
  4164. Event->Channel, Event->TargetID, EventMessage);
  4165. DAC960_Critical("Physical Device %d:%d Request Sense: "
  4166. "Sense Key = %X, ASC = %02X, ASCQ = %02X\n",
  4167. Controller,
  4168. Event->Channel,
  4169. Event->TargetID,
  4170. RequestSense->SenseKey,
  4171. RequestSense->AdditionalSenseCode,
  4172. RequestSense->AdditionalSenseCodeQualifier);
  4173. DAC960_Critical("Physical Device %d:%d Request Sense: "
  4174. "Information = %02X%02X%02X%02X "
  4175. "%02X%02X%02X%02X\n",
  4176. Controller,
  4177. Event->Channel,
  4178. Event->TargetID,
  4179. RequestSense->Information[0],
  4180. RequestSense->Information[1],
  4181. RequestSense->Information[2],
  4182. RequestSense->Information[3],
  4183. RequestSense->CommandSpecificInformation[0],
  4184. RequestSense->CommandSpecificInformation[1],
  4185. RequestSense->CommandSpecificInformation[2],
  4186. RequestSense->CommandSpecificInformation[3]);
  4187. break;
  4188. case 'E':
  4189. if (Controller->SuppressEnclosureMessages) break;
  4190. sprintf(MessageBuffer, EventMessage, Event->LogicalUnit);
  4191. DAC960_Critical("Enclosure %d %s\n", Controller,
  4192. Event->TargetID, MessageBuffer);
  4193. break;
  4194. case 'C':
  4195. DAC960_Critical("Controller %s\n", Controller, EventMessage);
  4196. break;
  4197. default:
  4198. DAC960_Critical("Unknown Controller Event Code %04X\n",
  4199. Controller, Event->EventCode);
  4200. break;
  4201. }
  4202. }
  4203. /*
  4204. DAC960_V2_ReportProgress prints an appropriate progress message for
  4205. Logical Device Long Operations.
  4206. */
  4207. static void DAC960_V2_ReportProgress(DAC960_Controller_T *Controller,
  4208. unsigned char *MessageString,
  4209. unsigned int LogicalDeviceNumber,
  4210. unsigned long BlocksCompleted,
  4211. unsigned long LogicalDeviceSize)
  4212. {
  4213. Controller->EphemeralProgressMessage = true;
  4214. DAC960_Progress("%s in Progress: Logical Drive %d (/dev/rd/c%dd%d) "
  4215. "%d%% completed\n", Controller,
  4216. MessageString,
  4217. LogicalDeviceNumber,
  4218. Controller->ControllerNumber,
  4219. LogicalDeviceNumber,
  4220. (100 * (BlocksCompleted >> 7)) / (LogicalDeviceSize >> 7));
  4221. Controller->EphemeralProgressMessage = false;
  4222. }
  4223. /*
  4224. DAC960_V2_ProcessCompletedCommand performs completion processing for Command
  4225. for DAC960 V2 Firmware Controllers.
  4226. */
  4227. static void DAC960_V2_ProcessCompletedCommand(DAC960_Command_T *Command)
  4228. {
  4229. DAC960_Controller_T *Controller = Command->Controller;
  4230. DAC960_CommandType_T CommandType = Command->CommandType;
  4231. DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  4232. DAC960_V2_IOCTL_Opcode_T CommandOpcode = CommandMailbox->Common.IOCTL_Opcode;
  4233. DAC960_V2_CommandStatus_T CommandStatus = Command->V2.CommandStatus;
  4234. if (CommandType == DAC960_ReadCommand ||
  4235. CommandType == DAC960_WriteCommand)
  4236. {
  4237. #ifdef FORCE_RETRY_DEBUG
  4238. CommandStatus = DAC960_V2_AbormalCompletion;
  4239. #endif
  4240. Command->V2.RequestSense->SenseKey = DAC960_SenseKey_MediumError;
  4241. if (CommandStatus == DAC960_V2_NormalCompletion) {
  4242. if (!DAC960_ProcessCompletedRequest(Command, true))
  4243. BUG();
  4244. } else if (Command->V2.RequestSense->SenseKey == DAC960_SenseKey_MediumError)
  4245. {
  4246. /*
  4247. * break the command down into pieces and resubmit each
  4248. * piece, hoping that some of them will succeed.
  4249. */
  4250. DAC960_queue_partial_rw(Command);
  4251. return;
  4252. }
  4253. else
  4254. {
  4255. if (Command->V2.RequestSense->SenseKey != DAC960_SenseKey_NotReady)
  4256. DAC960_V2_ReadWriteError(Command);
  4257. /*
  4258. Perform completion processing for all buffers in this I/O Request.
  4259. */
  4260. (void)DAC960_ProcessCompletedRequest(Command, false);
  4261. }
  4262. }
  4263. else if (CommandType == DAC960_ReadRetryCommand ||
  4264. CommandType == DAC960_WriteRetryCommand)
  4265. {
  4266. bool normal_completion;
  4267. #ifdef FORCE_RETRY_FAILURE_DEBUG
  4268. static int retry_count = 1;
  4269. #endif
  4270. /*
  4271. Perform completion processing for the portion that was
  4272. retried, and submit the next portion, if any.
  4273. */
  4274. normal_completion = true;
  4275. if (CommandStatus != DAC960_V2_NormalCompletion) {
  4276. normal_completion = false;
  4277. if (Command->V2.RequestSense->SenseKey != DAC960_SenseKey_NotReady)
  4278. DAC960_V2_ReadWriteError(Command);
  4279. }
  4280. #ifdef FORCE_RETRY_FAILURE_DEBUG
  4281. if (!(++retry_count % 10000)) {
  4282. printk("V2 error retry failure test\n");
  4283. normal_completion = false;
  4284. DAC960_V2_ReadWriteError(Command);
  4285. }
  4286. #endif
  4287. if (!DAC960_ProcessCompletedRequest(Command, normal_completion)) {
  4288. DAC960_queue_partial_rw(Command);
  4289. return;
  4290. }
  4291. }
  4292. else if (CommandType == DAC960_MonitoringCommand)
  4293. {
  4294. if (Controller->ShutdownMonitoringTimer)
  4295. return;
  4296. if (CommandOpcode == DAC960_V2_GetControllerInfo)
  4297. {
  4298. DAC960_V2_ControllerInfo_T *NewControllerInfo =
  4299. Controller->V2.NewControllerInformation;
  4300. DAC960_V2_ControllerInfo_T *ControllerInfo =
  4301. &Controller->V2.ControllerInformation;
  4302. Controller->LogicalDriveCount =
  4303. NewControllerInfo->LogicalDevicesPresent;
  4304. Controller->V2.NeedLogicalDeviceInformation = true;
  4305. Controller->V2.NeedPhysicalDeviceInformation = true;
  4306. Controller->V2.StartLogicalDeviceInformationScan = true;
  4307. Controller->V2.StartPhysicalDeviceInformationScan = true;
  4308. Controller->MonitoringAlertMode =
  4309. (NewControllerInfo->LogicalDevicesCritical > 0 ||
  4310. NewControllerInfo->LogicalDevicesOffline > 0 ||
  4311. NewControllerInfo->PhysicalDisksCritical > 0 ||
  4312. NewControllerInfo->PhysicalDisksOffline > 0);
  4313. memcpy(ControllerInfo, NewControllerInfo,
  4314. sizeof(DAC960_V2_ControllerInfo_T));
  4315. }
  4316. else if (CommandOpcode == DAC960_V2_GetEvent)
  4317. {
  4318. if (CommandStatus == DAC960_V2_NormalCompletion) {
  4319. DAC960_V2_ReportEvent(Controller, Controller->V2.Event);
  4320. }
  4321. Controller->V2.NextEventSequenceNumber++;
  4322. }
  4323. else if (CommandOpcode == DAC960_V2_GetPhysicalDeviceInfoValid &&
  4324. CommandStatus == DAC960_V2_NormalCompletion)
  4325. {
  4326. DAC960_V2_PhysicalDeviceInfo_T *NewPhysicalDeviceInfo =
  4327. Controller->V2.NewPhysicalDeviceInformation;
  4328. unsigned int PhysicalDeviceIndex = Controller->V2.PhysicalDeviceIndex;
  4329. DAC960_V2_PhysicalDeviceInfo_T *PhysicalDeviceInfo =
  4330. Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex];
  4331. DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
  4332. Controller->V2.InquiryUnitSerialNumber[PhysicalDeviceIndex];
  4333. unsigned int DeviceIndex;
  4334. while (PhysicalDeviceInfo != NULL &&
  4335. (NewPhysicalDeviceInfo->Channel >
  4336. PhysicalDeviceInfo->Channel ||
  4337. (NewPhysicalDeviceInfo->Channel ==
  4338. PhysicalDeviceInfo->Channel &&
  4339. (NewPhysicalDeviceInfo->TargetID >
  4340. PhysicalDeviceInfo->TargetID ||
  4341. (NewPhysicalDeviceInfo->TargetID ==
  4342. PhysicalDeviceInfo->TargetID &&
  4343. NewPhysicalDeviceInfo->LogicalUnit >
  4344. PhysicalDeviceInfo->LogicalUnit)))))
  4345. {
  4346. DAC960_Critical("Physical Device %d:%d No Longer Exists\n",
  4347. Controller,
  4348. PhysicalDeviceInfo->Channel,
  4349. PhysicalDeviceInfo->TargetID);
  4350. Controller->V2.PhysicalDeviceInformation
  4351. [PhysicalDeviceIndex] = NULL;
  4352. Controller->V2.InquiryUnitSerialNumber
  4353. [PhysicalDeviceIndex] = NULL;
  4354. kfree(PhysicalDeviceInfo);
  4355. kfree(InquiryUnitSerialNumber);
  4356. for (DeviceIndex = PhysicalDeviceIndex;
  4357. DeviceIndex < DAC960_V2_MaxPhysicalDevices - 1;
  4358. DeviceIndex++)
  4359. {
  4360. Controller->V2.PhysicalDeviceInformation[DeviceIndex] =
  4361. Controller->V2.PhysicalDeviceInformation[DeviceIndex+1];
  4362. Controller->V2.InquiryUnitSerialNumber[DeviceIndex] =
  4363. Controller->V2.InquiryUnitSerialNumber[DeviceIndex+1];
  4364. }
  4365. Controller->V2.PhysicalDeviceInformation
  4366. [DAC960_V2_MaxPhysicalDevices-1] = NULL;
  4367. Controller->V2.InquiryUnitSerialNumber
  4368. [DAC960_V2_MaxPhysicalDevices-1] = NULL;
  4369. PhysicalDeviceInfo =
  4370. Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex];
  4371. InquiryUnitSerialNumber =
  4372. Controller->V2.InquiryUnitSerialNumber[PhysicalDeviceIndex];
  4373. }
  4374. if (PhysicalDeviceInfo == NULL ||
  4375. (NewPhysicalDeviceInfo->Channel !=
  4376. PhysicalDeviceInfo->Channel) ||
  4377. (NewPhysicalDeviceInfo->TargetID !=
  4378. PhysicalDeviceInfo->TargetID) ||
  4379. (NewPhysicalDeviceInfo->LogicalUnit !=
  4380. PhysicalDeviceInfo->LogicalUnit))
  4381. {
  4382. PhysicalDeviceInfo =
  4383. kmalloc(sizeof(DAC960_V2_PhysicalDeviceInfo_T), GFP_ATOMIC);
  4384. InquiryUnitSerialNumber =
  4385. kmalloc(sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T),
  4386. GFP_ATOMIC);
  4387. if (InquiryUnitSerialNumber == NULL ||
  4388. PhysicalDeviceInfo == NULL)
  4389. {
  4390. kfree(InquiryUnitSerialNumber);
  4391. InquiryUnitSerialNumber = NULL;
  4392. kfree(PhysicalDeviceInfo);
  4393. PhysicalDeviceInfo = NULL;
  4394. }
  4395. DAC960_Critical("Physical Device %d:%d Now Exists%s\n",
  4396. Controller,
  4397. NewPhysicalDeviceInfo->Channel,
  4398. NewPhysicalDeviceInfo->TargetID,
  4399. (PhysicalDeviceInfo != NULL
  4400. ? "" : " - Allocation Failed"));
  4401. if (PhysicalDeviceInfo != NULL)
  4402. {
  4403. memset(PhysicalDeviceInfo, 0,
  4404. sizeof(DAC960_V2_PhysicalDeviceInfo_T));
  4405. PhysicalDeviceInfo->PhysicalDeviceState =
  4406. DAC960_V2_Device_InvalidState;
  4407. memset(InquiryUnitSerialNumber, 0,
  4408. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
  4409. InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
  4410. for (DeviceIndex = DAC960_V2_MaxPhysicalDevices - 1;
  4411. DeviceIndex > PhysicalDeviceIndex;
  4412. DeviceIndex--)
  4413. {
  4414. Controller->V2.PhysicalDeviceInformation[DeviceIndex] =
  4415. Controller->V2.PhysicalDeviceInformation[DeviceIndex-1];
  4416. Controller->V2.InquiryUnitSerialNumber[DeviceIndex] =
  4417. Controller->V2.InquiryUnitSerialNumber[DeviceIndex-1];
  4418. }
  4419. Controller->V2.PhysicalDeviceInformation
  4420. [PhysicalDeviceIndex] =
  4421. PhysicalDeviceInfo;
  4422. Controller->V2.InquiryUnitSerialNumber
  4423. [PhysicalDeviceIndex] =
  4424. InquiryUnitSerialNumber;
  4425. Controller->V2.NeedDeviceSerialNumberInformation = true;
  4426. }
  4427. }
  4428. if (PhysicalDeviceInfo != NULL)
  4429. {
  4430. if (NewPhysicalDeviceInfo->PhysicalDeviceState !=
  4431. PhysicalDeviceInfo->PhysicalDeviceState)
  4432. DAC960_Critical(
  4433. "Physical Device %d:%d is now %s\n", Controller,
  4434. NewPhysicalDeviceInfo->Channel,
  4435. NewPhysicalDeviceInfo->TargetID,
  4436. (NewPhysicalDeviceInfo->PhysicalDeviceState
  4437. == DAC960_V2_Device_Online
  4438. ? "ONLINE"
  4439. : NewPhysicalDeviceInfo->PhysicalDeviceState
  4440. == DAC960_V2_Device_Rebuild
  4441. ? "REBUILD"
  4442. : NewPhysicalDeviceInfo->PhysicalDeviceState
  4443. == DAC960_V2_Device_Missing
  4444. ? "MISSING"
  4445. : NewPhysicalDeviceInfo->PhysicalDeviceState
  4446. == DAC960_V2_Device_Critical
  4447. ? "CRITICAL"
  4448. : NewPhysicalDeviceInfo->PhysicalDeviceState
  4449. == DAC960_V2_Device_Dead
  4450. ? "DEAD"
  4451. : NewPhysicalDeviceInfo->PhysicalDeviceState
  4452. == DAC960_V2_Device_SuspectedDead
  4453. ? "SUSPECTED-DEAD"
  4454. : NewPhysicalDeviceInfo->PhysicalDeviceState
  4455. == DAC960_V2_Device_CommandedOffline
  4456. ? "COMMANDED-OFFLINE"
  4457. : NewPhysicalDeviceInfo->PhysicalDeviceState
  4458. == DAC960_V2_Device_Standby
  4459. ? "STANDBY" : "UNKNOWN"));
  4460. if ((NewPhysicalDeviceInfo->ParityErrors !=
  4461. PhysicalDeviceInfo->ParityErrors) ||
  4462. (NewPhysicalDeviceInfo->SoftErrors !=
  4463. PhysicalDeviceInfo->SoftErrors) ||
  4464. (NewPhysicalDeviceInfo->HardErrors !=
  4465. PhysicalDeviceInfo->HardErrors) ||
  4466. (NewPhysicalDeviceInfo->MiscellaneousErrors !=
  4467. PhysicalDeviceInfo->MiscellaneousErrors) ||
  4468. (NewPhysicalDeviceInfo->CommandTimeouts !=
  4469. PhysicalDeviceInfo->CommandTimeouts) ||
  4470. (NewPhysicalDeviceInfo->Retries !=
  4471. PhysicalDeviceInfo->Retries) ||
  4472. (NewPhysicalDeviceInfo->Aborts !=
  4473. PhysicalDeviceInfo->Aborts) ||
  4474. (NewPhysicalDeviceInfo->PredictedFailuresDetected !=
  4475. PhysicalDeviceInfo->PredictedFailuresDetected))
  4476. {
  4477. DAC960_Critical("Physical Device %d:%d Errors: "
  4478. "Parity = %d, Soft = %d, "
  4479. "Hard = %d, Misc = %d\n",
  4480. Controller,
  4481. NewPhysicalDeviceInfo->Channel,
  4482. NewPhysicalDeviceInfo->TargetID,
  4483. NewPhysicalDeviceInfo->ParityErrors,
  4484. NewPhysicalDeviceInfo->SoftErrors,
  4485. NewPhysicalDeviceInfo->HardErrors,
  4486. NewPhysicalDeviceInfo->MiscellaneousErrors);
  4487. DAC960_Critical("Physical Device %d:%d Errors: "
  4488. "Timeouts = %d, Retries = %d, "
  4489. "Aborts = %d, Predicted = %d\n",
  4490. Controller,
  4491. NewPhysicalDeviceInfo->Channel,
  4492. NewPhysicalDeviceInfo->TargetID,
  4493. NewPhysicalDeviceInfo->CommandTimeouts,
  4494. NewPhysicalDeviceInfo->Retries,
  4495. NewPhysicalDeviceInfo->Aborts,
  4496. NewPhysicalDeviceInfo
  4497. ->PredictedFailuresDetected);
  4498. }
  4499. if ((PhysicalDeviceInfo->PhysicalDeviceState
  4500. == DAC960_V2_Device_Dead ||
  4501. PhysicalDeviceInfo->PhysicalDeviceState
  4502. == DAC960_V2_Device_InvalidState) &&
  4503. NewPhysicalDeviceInfo->PhysicalDeviceState
  4504. != DAC960_V2_Device_Dead)
  4505. Controller->V2.NeedDeviceSerialNumberInformation = true;
  4506. memcpy(PhysicalDeviceInfo, NewPhysicalDeviceInfo,
  4507. sizeof(DAC960_V2_PhysicalDeviceInfo_T));
  4508. }
  4509. NewPhysicalDeviceInfo->LogicalUnit++;
  4510. Controller->V2.PhysicalDeviceIndex++;
  4511. }
  4512. else if (CommandOpcode == DAC960_V2_GetPhysicalDeviceInfoValid)
  4513. {
  4514. unsigned int DeviceIndex;
  4515. for (DeviceIndex = Controller->V2.PhysicalDeviceIndex;
  4516. DeviceIndex < DAC960_V2_MaxPhysicalDevices;
  4517. DeviceIndex++)
  4518. {
  4519. DAC960_V2_PhysicalDeviceInfo_T *PhysicalDeviceInfo =
  4520. Controller->V2.PhysicalDeviceInformation[DeviceIndex];
  4521. DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
  4522. Controller->V2.InquiryUnitSerialNumber[DeviceIndex];
  4523. if (PhysicalDeviceInfo == NULL) break;
  4524. DAC960_Critical("Physical Device %d:%d No Longer Exists\n",
  4525. Controller,
  4526. PhysicalDeviceInfo->Channel,
  4527. PhysicalDeviceInfo->TargetID);
  4528. Controller->V2.PhysicalDeviceInformation[DeviceIndex] = NULL;
  4529. Controller->V2.InquiryUnitSerialNumber[DeviceIndex] = NULL;
  4530. kfree(PhysicalDeviceInfo);
  4531. kfree(InquiryUnitSerialNumber);
  4532. }
  4533. Controller->V2.NeedPhysicalDeviceInformation = false;
  4534. }
  4535. else if (CommandOpcode == DAC960_V2_GetLogicalDeviceInfoValid &&
  4536. CommandStatus == DAC960_V2_NormalCompletion)
  4537. {
  4538. DAC960_V2_LogicalDeviceInfo_T *NewLogicalDeviceInfo =
  4539. Controller->V2.NewLogicalDeviceInformation;
  4540. unsigned short LogicalDeviceNumber =
  4541. NewLogicalDeviceInfo->LogicalDeviceNumber;
  4542. DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
  4543. Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber];
  4544. if (LogicalDeviceInfo == NULL)
  4545. {
  4546. DAC960_V2_PhysicalDevice_T PhysicalDevice;
  4547. PhysicalDevice.Controller = 0;
  4548. PhysicalDevice.Channel = NewLogicalDeviceInfo->Channel;
  4549. PhysicalDevice.TargetID = NewLogicalDeviceInfo->TargetID;
  4550. PhysicalDevice.LogicalUnit = NewLogicalDeviceInfo->LogicalUnit;
  4551. Controller->V2.LogicalDriveToVirtualDevice[LogicalDeviceNumber] =
  4552. PhysicalDevice;
  4553. LogicalDeviceInfo = kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T),
  4554. GFP_ATOMIC);
  4555. Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber] =
  4556. LogicalDeviceInfo;
  4557. DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
  4558. "Now Exists%s\n", Controller,
  4559. LogicalDeviceNumber,
  4560. Controller->ControllerNumber,
  4561. LogicalDeviceNumber,
  4562. (LogicalDeviceInfo != NULL
  4563. ? "" : " - Allocation Failed"));
  4564. if (LogicalDeviceInfo != NULL)
  4565. {
  4566. memset(LogicalDeviceInfo, 0,
  4567. sizeof(DAC960_V2_LogicalDeviceInfo_T));
  4568. DAC960_ComputeGenericDiskInfo(Controller);
  4569. }
  4570. }
  4571. if (LogicalDeviceInfo != NULL)
  4572. {
  4573. unsigned long LogicalDeviceSize =
  4574. NewLogicalDeviceInfo->ConfigurableDeviceSize;
  4575. if (NewLogicalDeviceInfo->LogicalDeviceState !=
  4576. LogicalDeviceInfo->LogicalDeviceState)
  4577. DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
  4578. "is now %s\n", Controller,
  4579. LogicalDeviceNumber,
  4580. Controller->ControllerNumber,
  4581. LogicalDeviceNumber,
  4582. (NewLogicalDeviceInfo->LogicalDeviceState
  4583. == DAC960_V2_LogicalDevice_Online
  4584. ? "ONLINE"
  4585. : NewLogicalDeviceInfo->LogicalDeviceState
  4586. == DAC960_V2_LogicalDevice_Critical
  4587. ? "CRITICAL" : "OFFLINE"));
  4588. if ((NewLogicalDeviceInfo->SoftErrors !=
  4589. LogicalDeviceInfo->SoftErrors) ||
  4590. (NewLogicalDeviceInfo->CommandsFailed !=
  4591. LogicalDeviceInfo->CommandsFailed) ||
  4592. (NewLogicalDeviceInfo->DeferredWriteErrors !=
  4593. LogicalDeviceInfo->DeferredWriteErrors))
  4594. DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) Errors: "
  4595. "Soft = %d, Failed = %d, Deferred Write = %d\n",
  4596. Controller, LogicalDeviceNumber,
  4597. Controller->ControllerNumber,
  4598. LogicalDeviceNumber,
  4599. NewLogicalDeviceInfo->SoftErrors,
  4600. NewLogicalDeviceInfo->CommandsFailed,
  4601. NewLogicalDeviceInfo->DeferredWriteErrors);
  4602. if (NewLogicalDeviceInfo->ConsistencyCheckInProgress)
  4603. DAC960_V2_ReportProgress(Controller,
  4604. "Consistency Check",
  4605. LogicalDeviceNumber,
  4606. NewLogicalDeviceInfo
  4607. ->ConsistencyCheckBlockNumber,
  4608. LogicalDeviceSize);
  4609. else if (NewLogicalDeviceInfo->RebuildInProgress)
  4610. DAC960_V2_ReportProgress(Controller,
  4611. "Rebuild",
  4612. LogicalDeviceNumber,
  4613. NewLogicalDeviceInfo
  4614. ->RebuildBlockNumber,
  4615. LogicalDeviceSize);
  4616. else if (NewLogicalDeviceInfo->BackgroundInitializationInProgress)
  4617. DAC960_V2_ReportProgress(Controller,
  4618. "Background Initialization",
  4619. LogicalDeviceNumber,
  4620. NewLogicalDeviceInfo
  4621. ->BackgroundInitializationBlockNumber,
  4622. LogicalDeviceSize);
  4623. else if (NewLogicalDeviceInfo->ForegroundInitializationInProgress)
  4624. DAC960_V2_ReportProgress(Controller,
  4625. "Foreground Initialization",
  4626. LogicalDeviceNumber,
  4627. NewLogicalDeviceInfo
  4628. ->ForegroundInitializationBlockNumber,
  4629. LogicalDeviceSize);
  4630. else if (NewLogicalDeviceInfo->DataMigrationInProgress)
  4631. DAC960_V2_ReportProgress(Controller,
  4632. "Data Migration",
  4633. LogicalDeviceNumber,
  4634. NewLogicalDeviceInfo
  4635. ->DataMigrationBlockNumber,
  4636. LogicalDeviceSize);
  4637. else if (NewLogicalDeviceInfo->PatrolOperationInProgress)
  4638. DAC960_V2_ReportProgress(Controller,
  4639. "Patrol Operation",
  4640. LogicalDeviceNumber,
  4641. NewLogicalDeviceInfo
  4642. ->PatrolOperationBlockNumber,
  4643. LogicalDeviceSize);
  4644. if (LogicalDeviceInfo->BackgroundInitializationInProgress &&
  4645. !NewLogicalDeviceInfo->BackgroundInitializationInProgress)
  4646. DAC960_Progress("Logical Drive %d (/dev/rd/c%dd%d) "
  4647. "Background Initialization %s\n",
  4648. Controller,
  4649. LogicalDeviceNumber,
  4650. Controller->ControllerNumber,
  4651. LogicalDeviceNumber,
  4652. (NewLogicalDeviceInfo->LogicalDeviceControl
  4653. .LogicalDeviceInitialized
  4654. ? "Completed" : "Failed"));
  4655. memcpy(LogicalDeviceInfo, NewLogicalDeviceInfo,
  4656. sizeof(DAC960_V2_LogicalDeviceInfo_T));
  4657. }
  4658. Controller->V2.LogicalDriveFoundDuringScan
  4659. [LogicalDeviceNumber] = true;
  4660. NewLogicalDeviceInfo->LogicalDeviceNumber++;
  4661. }
  4662. else if (CommandOpcode == DAC960_V2_GetLogicalDeviceInfoValid)
  4663. {
  4664. int LogicalDriveNumber;
  4665. for (LogicalDriveNumber = 0;
  4666. LogicalDriveNumber < DAC960_MaxLogicalDrives;
  4667. LogicalDriveNumber++)
  4668. {
  4669. DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
  4670. Controller->V2.LogicalDeviceInformation[LogicalDriveNumber];
  4671. if (LogicalDeviceInfo == NULL ||
  4672. Controller->V2.LogicalDriveFoundDuringScan
  4673. [LogicalDriveNumber])
  4674. continue;
  4675. DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
  4676. "No Longer Exists\n", Controller,
  4677. LogicalDriveNumber,
  4678. Controller->ControllerNumber,
  4679. LogicalDriveNumber);
  4680. Controller->V2.LogicalDeviceInformation
  4681. [LogicalDriveNumber] = NULL;
  4682. kfree(LogicalDeviceInfo);
  4683. Controller->LogicalDriveInitiallyAccessible
  4684. [LogicalDriveNumber] = false;
  4685. DAC960_ComputeGenericDiskInfo(Controller);
  4686. }
  4687. Controller->V2.NeedLogicalDeviceInformation = false;
  4688. }
  4689. else if (CommandOpcode == DAC960_V2_SCSI_10_Passthru)
  4690. {
  4691. DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
  4692. Controller->V2.InquiryUnitSerialNumber[Controller->V2.PhysicalDeviceIndex - 1];
  4693. if (CommandStatus != DAC960_V2_NormalCompletion) {
  4694. memset(InquiryUnitSerialNumber,
  4695. 0, sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
  4696. InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
  4697. } else
  4698. memcpy(InquiryUnitSerialNumber,
  4699. Controller->V2.NewInquiryUnitSerialNumber,
  4700. sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T));
  4701. Controller->V2.NeedDeviceSerialNumberInformation = false;
  4702. }
  4703. if (Controller->V2.HealthStatusBuffer->NextEventSequenceNumber
  4704. - Controller->V2.NextEventSequenceNumber > 0)
  4705. {
  4706. CommandMailbox->GetEvent.CommandOpcode = DAC960_V2_IOCTL;
  4707. CommandMailbox->GetEvent.DataTransferSize = sizeof(DAC960_V2_Event_T);
  4708. CommandMailbox->GetEvent.EventSequenceNumberHigh16 =
  4709. Controller->V2.NextEventSequenceNumber >> 16;
  4710. CommandMailbox->GetEvent.ControllerNumber = 0;
  4711. CommandMailbox->GetEvent.IOCTL_Opcode =
  4712. DAC960_V2_GetEvent;
  4713. CommandMailbox->GetEvent.EventSequenceNumberLow16 =
  4714. Controller->V2.NextEventSequenceNumber & 0xFFFF;
  4715. CommandMailbox->GetEvent.DataTransferMemoryAddress
  4716. .ScatterGatherSegments[0]
  4717. .SegmentDataPointer =
  4718. Controller->V2.EventDMA;
  4719. CommandMailbox->GetEvent.DataTransferMemoryAddress
  4720. .ScatterGatherSegments[0]
  4721. .SegmentByteCount =
  4722. CommandMailbox->GetEvent.DataTransferSize;
  4723. DAC960_QueueCommand(Command);
  4724. return;
  4725. }
  4726. if (Controller->V2.NeedPhysicalDeviceInformation)
  4727. {
  4728. if (Controller->V2.NeedDeviceSerialNumberInformation)
  4729. {
  4730. DAC960_SCSI_Inquiry_UnitSerialNumber_T *InquiryUnitSerialNumber =
  4731. Controller->V2.NewInquiryUnitSerialNumber;
  4732. InquiryUnitSerialNumber->PeripheralDeviceType = 0x1F;
  4733. DAC960_V2_ConstructNewUnitSerialNumber(Controller, CommandMailbox,
  4734. Controller->V2.NewPhysicalDeviceInformation->Channel,
  4735. Controller->V2.NewPhysicalDeviceInformation->TargetID,
  4736. Controller->V2.NewPhysicalDeviceInformation->LogicalUnit - 1);
  4737. DAC960_QueueCommand(Command);
  4738. return;
  4739. }
  4740. if (Controller->V2.StartPhysicalDeviceInformationScan)
  4741. {
  4742. Controller->V2.PhysicalDeviceIndex = 0;
  4743. Controller->V2.NewPhysicalDeviceInformation->Channel = 0;
  4744. Controller->V2.NewPhysicalDeviceInformation->TargetID = 0;
  4745. Controller->V2.NewPhysicalDeviceInformation->LogicalUnit = 0;
  4746. Controller->V2.StartPhysicalDeviceInformationScan = false;
  4747. }
  4748. CommandMailbox->PhysicalDeviceInfo.CommandOpcode = DAC960_V2_IOCTL;
  4749. CommandMailbox->PhysicalDeviceInfo.DataTransferSize =
  4750. sizeof(DAC960_V2_PhysicalDeviceInfo_T);
  4751. CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.LogicalUnit =
  4752. Controller->V2.NewPhysicalDeviceInformation->LogicalUnit;
  4753. CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.TargetID =
  4754. Controller->V2.NewPhysicalDeviceInformation->TargetID;
  4755. CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.Channel =
  4756. Controller->V2.NewPhysicalDeviceInformation->Channel;
  4757. CommandMailbox->PhysicalDeviceInfo.IOCTL_Opcode =
  4758. DAC960_V2_GetPhysicalDeviceInfoValid;
  4759. CommandMailbox->PhysicalDeviceInfo.DataTransferMemoryAddress
  4760. .ScatterGatherSegments[0]
  4761. .SegmentDataPointer =
  4762. Controller->V2.NewPhysicalDeviceInformationDMA;
  4763. CommandMailbox->PhysicalDeviceInfo.DataTransferMemoryAddress
  4764. .ScatterGatherSegments[0]
  4765. .SegmentByteCount =
  4766. CommandMailbox->PhysicalDeviceInfo.DataTransferSize;
  4767. DAC960_QueueCommand(Command);
  4768. return;
  4769. }
  4770. if (Controller->V2.NeedLogicalDeviceInformation)
  4771. {
  4772. if (Controller->V2.StartLogicalDeviceInformationScan)
  4773. {
  4774. int LogicalDriveNumber;
  4775. for (LogicalDriveNumber = 0;
  4776. LogicalDriveNumber < DAC960_MaxLogicalDrives;
  4777. LogicalDriveNumber++)
  4778. Controller->V2.LogicalDriveFoundDuringScan
  4779. [LogicalDriveNumber] = false;
  4780. Controller->V2.NewLogicalDeviceInformation->LogicalDeviceNumber = 0;
  4781. Controller->V2.StartLogicalDeviceInformationScan = false;
  4782. }
  4783. CommandMailbox->LogicalDeviceInfo.CommandOpcode = DAC960_V2_IOCTL;
  4784. CommandMailbox->LogicalDeviceInfo.DataTransferSize =
  4785. sizeof(DAC960_V2_LogicalDeviceInfo_T);
  4786. CommandMailbox->LogicalDeviceInfo.LogicalDevice.LogicalDeviceNumber =
  4787. Controller->V2.NewLogicalDeviceInformation->LogicalDeviceNumber;
  4788. CommandMailbox->LogicalDeviceInfo.IOCTL_Opcode =
  4789. DAC960_V2_GetLogicalDeviceInfoValid;
  4790. CommandMailbox->LogicalDeviceInfo.DataTransferMemoryAddress
  4791. .ScatterGatherSegments[0]
  4792. .SegmentDataPointer =
  4793. Controller->V2.NewLogicalDeviceInformationDMA;
  4794. CommandMailbox->LogicalDeviceInfo.DataTransferMemoryAddress
  4795. .ScatterGatherSegments[0]
  4796. .SegmentByteCount =
  4797. CommandMailbox->LogicalDeviceInfo.DataTransferSize;
  4798. DAC960_QueueCommand(Command);
  4799. return;
  4800. }
  4801. Controller->MonitoringTimerCount++;
  4802. Controller->MonitoringTimer.expires =
  4803. jiffies + DAC960_HealthStatusMonitoringInterval;
  4804. add_timer(&Controller->MonitoringTimer);
  4805. }
  4806. if (CommandType == DAC960_ImmediateCommand)
  4807. {
  4808. complete(Command->Completion);
  4809. Command->Completion = NULL;
  4810. return;
  4811. }
  4812. if (CommandType == DAC960_QueuedCommand)
  4813. {
  4814. DAC960_V2_KernelCommand_T *KernelCommand = Command->V2.KernelCommand;
  4815. KernelCommand->CommandStatus = CommandStatus;
  4816. KernelCommand->RequestSenseLength = Command->V2.RequestSenseLength;
  4817. KernelCommand->DataTransferLength = Command->V2.DataTransferResidue;
  4818. Command->V2.KernelCommand = NULL;
  4819. DAC960_DeallocateCommand(Command);
  4820. KernelCommand->CompletionFunction(KernelCommand);
  4821. return;
  4822. }
  4823. /*
  4824. Queue a Status Monitoring Command to the Controller using the just
  4825. completed Command if one was deferred previously due to lack of a
  4826. free Command when the Monitoring Timer Function was called.
  4827. */
  4828. if (Controller->MonitoringCommandDeferred)
  4829. {
  4830. Controller->MonitoringCommandDeferred = false;
  4831. DAC960_V2_QueueMonitoringCommand(Command);
  4832. return;
  4833. }
  4834. /*
  4835. Deallocate the Command.
  4836. */
  4837. DAC960_DeallocateCommand(Command);
  4838. /*
  4839. Wake up any processes waiting on a free Command.
  4840. */
  4841. wake_up(&Controller->CommandWaitQueue);
  4842. }
  4843. /*
  4844. DAC960_GEM_InterruptHandler handles hardware interrupts from DAC960 GEM Series
  4845. Controllers.
  4846. */
  4847. static irqreturn_t DAC960_GEM_InterruptHandler(int IRQ_Channel,
  4848. void *DeviceIdentifier)
  4849. {
  4850. DAC960_Controller_T *Controller = DeviceIdentifier;
  4851. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  4852. DAC960_V2_StatusMailbox_T *NextStatusMailbox;
  4853. unsigned long flags;
  4854. spin_lock_irqsave(&Controller->queue_lock, flags);
  4855. DAC960_GEM_AcknowledgeInterrupt(ControllerBaseAddress);
  4856. NextStatusMailbox = Controller->V2.NextStatusMailbox;
  4857. while (NextStatusMailbox->Fields.CommandIdentifier > 0)
  4858. {
  4859. DAC960_V2_CommandIdentifier_T CommandIdentifier =
  4860. NextStatusMailbox->Fields.CommandIdentifier;
  4861. DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
  4862. Command->V2.CommandStatus = NextStatusMailbox->Fields.CommandStatus;
  4863. Command->V2.RequestSenseLength =
  4864. NextStatusMailbox->Fields.RequestSenseLength;
  4865. Command->V2.DataTransferResidue =
  4866. NextStatusMailbox->Fields.DataTransferResidue;
  4867. NextStatusMailbox->Words[0] = 0;
  4868. if (++NextStatusMailbox > Controller->V2.LastStatusMailbox)
  4869. NextStatusMailbox = Controller->V2.FirstStatusMailbox;
  4870. DAC960_V2_ProcessCompletedCommand(Command);
  4871. }
  4872. Controller->V2.NextStatusMailbox = NextStatusMailbox;
  4873. /*
  4874. Attempt to remove additional I/O Requests from the Controller's
  4875. I/O Request Queue and queue them to the Controller.
  4876. */
  4877. DAC960_ProcessRequest(Controller);
  4878. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  4879. return IRQ_HANDLED;
  4880. }
  4881. /*
  4882. DAC960_BA_InterruptHandler handles hardware interrupts from DAC960 BA Series
  4883. Controllers.
  4884. */
  4885. static irqreturn_t DAC960_BA_InterruptHandler(int IRQ_Channel,
  4886. void *DeviceIdentifier)
  4887. {
  4888. DAC960_Controller_T *Controller = DeviceIdentifier;
  4889. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  4890. DAC960_V2_StatusMailbox_T *NextStatusMailbox;
  4891. unsigned long flags;
  4892. spin_lock_irqsave(&Controller->queue_lock, flags);
  4893. DAC960_BA_AcknowledgeInterrupt(ControllerBaseAddress);
  4894. NextStatusMailbox = Controller->V2.NextStatusMailbox;
  4895. while (NextStatusMailbox->Fields.CommandIdentifier > 0)
  4896. {
  4897. DAC960_V2_CommandIdentifier_T CommandIdentifier =
  4898. NextStatusMailbox->Fields.CommandIdentifier;
  4899. DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
  4900. Command->V2.CommandStatus = NextStatusMailbox->Fields.CommandStatus;
  4901. Command->V2.RequestSenseLength =
  4902. NextStatusMailbox->Fields.RequestSenseLength;
  4903. Command->V2.DataTransferResidue =
  4904. NextStatusMailbox->Fields.DataTransferResidue;
  4905. NextStatusMailbox->Words[0] = 0;
  4906. if (++NextStatusMailbox > Controller->V2.LastStatusMailbox)
  4907. NextStatusMailbox = Controller->V2.FirstStatusMailbox;
  4908. DAC960_V2_ProcessCompletedCommand(Command);
  4909. }
  4910. Controller->V2.NextStatusMailbox = NextStatusMailbox;
  4911. /*
  4912. Attempt to remove additional I/O Requests from the Controller's
  4913. I/O Request Queue and queue them to the Controller.
  4914. */
  4915. DAC960_ProcessRequest(Controller);
  4916. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  4917. return IRQ_HANDLED;
  4918. }
  4919. /*
  4920. DAC960_LP_InterruptHandler handles hardware interrupts from DAC960 LP Series
  4921. Controllers.
  4922. */
  4923. static irqreturn_t DAC960_LP_InterruptHandler(int IRQ_Channel,
  4924. void *DeviceIdentifier)
  4925. {
  4926. DAC960_Controller_T *Controller = DeviceIdentifier;
  4927. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  4928. DAC960_V2_StatusMailbox_T *NextStatusMailbox;
  4929. unsigned long flags;
  4930. spin_lock_irqsave(&Controller->queue_lock, flags);
  4931. DAC960_LP_AcknowledgeInterrupt(ControllerBaseAddress);
  4932. NextStatusMailbox = Controller->V2.NextStatusMailbox;
  4933. while (NextStatusMailbox->Fields.CommandIdentifier > 0)
  4934. {
  4935. DAC960_V2_CommandIdentifier_T CommandIdentifier =
  4936. NextStatusMailbox->Fields.CommandIdentifier;
  4937. DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
  4938. Command->V2.CommandStatus = NextStatusMailbox->Fields.CommandStatus;
  4939. Command->V2.RequestSenseLength =
  4940. NextStatusMailbox->Fields.RequestSenseLength;
  4941. Command->V2.DataTransferResidue =
  4942. NextStatusMailbox->Fields.DataTransferResidue;
  4943. NextStatusMailbox->Words[0] = 0;
  4944. if (++NextStatusMailbox > Controller->V2.LastStatusMailbox)
  4945. NextStatusMailbox = Controller->V2.FirstStatusMailbox;
  4946. DAC960_V2_ProcessCompletedCommand(Command);
  4947. }
  4948. Controller->V2.NextStatusMailbox = NextStatusMailbox;
  4949. /*
  4950. Attempt to remove additional I/O Requests from the Controller's
  4951. I/O Request Queue and queue them to the Controller.
  4952. */
  4953. DAC960_ProcessRequest(Controller);
  4954. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  4955. return IRQ_HANDLED;
  4956. }
  4957. /*
  4958. DAC960_LA_InterruptHandler handles hardware interrupts from DAC960 LA Series
  4959. Controllers.
  4960. */
  4961. static irqreturn_t DAC960_LA_InterruptHandler(int IRQ_Channel,
  4962. void *DeviceIdentifier)
  4963. {
  4964. DAC960_Controller_T *Controller = DeviceIdentifier;
  4965. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  4966. DAC960_V1_StatusMailbox_T *NextStatusMailbox;
  4967. unsigned long flags;
  4968. spin_lock_irqsave(&Controller->queue_lock, flags);
  4969. DAC960_LA_AcknowledgeInterrupt(ControllerBaseAddress);
  4970. NextStatusMailbox = Controller->V1.NextStatusMailbox;
  4971. while (NextStatusMailbox->Fields.Valid)
  4972. {
  4973. DAC960_V1_CommandIdentifier_T CommandIdentifier =
  4974. NextStatusMailbox->Fields.CommandIdentifier;
  4975. DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
  4976. Command->V1.CommandStatus = NextStatusMailbox->Fields.CommandStatus;
  4977. NextStatusMailbox->Word = 0;
  4978. if (++NextStatusMailbox > Controller->V1.LastStatusMailbox)
  4979. NextStatusMailbox = Controller->V1.FirstStatusMailbox;
  4980. DAC960_V1_ProcessCompletedCommand(Command);
  4981. }
  4982. Controller->V1.NextStatusMailbox = NextStatusMailbox;
  4983. /*
  4984. Attempt to remove additional I/O Requests from the Controller's
  4985. I/O Request Queue and queue them to the Controller.
  4986. */
  4987. DAC960_ProcessRequest(Controller);
  4988. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  4989. return IRQ_HANDLED;
  4990. }
  4991. /*
  4992. DAC960_PG_InterruptHandler handles hardware interrupts from DAC960 PG Series
  4993. Controllers.
  4994. */
  4995. static irqreturn_t DAC960_PG_InterruptHandler(int IRQ_Channel,
  4996. void *DeviceIdentifier)
  4997. {
  4998. DAC960_Controller_T *Controller = DeviceIdentifier;
  4999. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  5000. DAC960_V1_StatusMailbox_T *NextStatusMailbox;
  5001. unsigned long flags;
  5002. spin_lock_irqsave(&Controller->queue_lock, flags);
  5003. DAC960_PG_AcknowledgeInterrupt(ControllerBaseAddress);
  5004. NextStatusMailbox = Controller->V1.NextStatusMailbox;
  5005. while (NextStatusMailbox->Fields.Valid)
  5006. {
  5007. DAC960_V1_CommandIdentifier_T CommandIdentifier =
  5008. NextStatusMailbox->Fields.CommandIdentifier;
  5009. DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
  5010. Command->V1.CommandStatus = NextStatusMailbox->Fields.CommandStatus;
  5011. NextStatusMailbox->Word = 0;
  5012. if (++NextStatusMailbox > Controller->V1.LastStatusMailbox)
  5013. NextStatusMailbox = Controller->V1.FirstStatusMailbox;
  5014. DAC960_V1_ProcessCompletedCommand(Command);
  5015. }
  5016. Controller->V1.NextStatusMailbox = NextStatusMailbox;
  5017. /*
  5018. Attempt to remove additional I/O Requests from the Controller's
  5019. I/O Request Queue and queue them to the Controller.
  5020. */
  5021. DAC960_ProcessRequest(Controller);
  5022. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  5023. return IRQ_HANDLED;
  5024. }
  5025. /*
  5026. DAC960_PD_InterruptHandler handles hardware interrupts from DAC960 PD Series
  5027. Controllers.
  5028. */
  5029. static irqreturn_t DAC960_PD_InterruptHandler(int IRQ_Channel,
  5030. void *DeviceIdentifier)
  5031. {
  5032. DAC960_Controller_T *Controller = DeviceIdentifier;
  5033. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  5034. unsigned long flags;
  5035. spin_lock_irqsave(&Controller->queue_lock, flags);
  5036. while (DAC960_PD_StatusAvailableP(ControllerBaseAddress))
  5037. {
  5038. DAC960_V1_CommandIdentifier_T CommandIdentifier =
  5039. DAC960_PD_ReadStatusCommandIdentifier(ControllerBaseAddress);
  5040. DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
  5041. Command->V1.CommandStatus =
  5042. DAC960_PD_ReadStatusRegister(ControllerBaseAddress);
  5043. DAC960_PD_AcknowledgeInterrupt(ControllerBaseAddress);
  5044. DAC960_PD_AcknowledgeStatus(ControllerBaseAddress);
  5045. DAC960_V1_ProcessCompletedCommand(Command);
  5046. }
  5047. /*
  5048. Attempt to remove additional I/O Requests from the Controller's
  5049. I/O Request Queue and queue them to the Controller.
  5050. */
  5051. DAC960_ProcessRequest(Controller);
  5052. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  5053. return IRQ_HANDLED;
  5054. }
  5055. /*
  5056. DAC960_P_InterruptHandler handles hardware interrupts from DAC960 P Series
  5057. Controllers.
  5058. Translations of DAC960_V1_Enquiry and DAC960_V1_GetDeviceState rely
  5059. on the data having been placed into DAC960_Controller_T, rather than
  5060. an arbitrary buffer.
  5061. */
  5062. static irqreturn_t DAC960_P_InterruptHandler(int IRQ_Channel,
  5063. void *DeviceIdentifier)
  5064. {
  5065. DAC960_Controller_T *Controller = DeviceIdentifier;
  5066. void __iomem *ControllerBaseAddress = Controller->BaseAddress;
  5067. unsigned long flags;
  5068. spin_lock_irqsave(&Controller->queue_lock, flags);
  5069. while (DAC960_PD_StatusAvailableP(ControllerBaseAddress))
  5070. {
  5071. DAC960_V1_CommandIdentifier_T CommandIdentifier =
  5072. DAC960_PD_ReadStatusCommandIdentifier(ControllerBaseAddress);
  5073. DAC960_Command_T *Command = Controller->Commands[CommandIdentifier-1];
  5074. DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  5075. DAC960_V1_CommandOpcode_T CommandOpcode =
  5076. CommandMailbox->Common.CommandOpcode;
  5077. Command->V1.CommandStatus =
  5078. DAC960_PD_ReadStatusRegister(ControllerBaseAddress);
  5079. DAC960_PD_AcknowledgeInterrupt(ControllerBaseAddress);
  5080. DAC960_PD_AcknowledgeStatus(ControllerBaseAddress);
  5081. switch (CommandOpcode)
  5082. {
  5083. case DAC960_V1_Enquiry_Old:
  5084. Command->V1.CommandMailbox.Common.CommandOpcode = DAC960_V1_Enquiry;
  5085. DAC960_P_To_PD_TranslateEnquiry(Controller->V1.NewEnquiry);
  5086. break;
  5087. case DAC960_V1_GetDeviceState_Old:
  5088. Command->V1.CommandMailbox.Common.CommandOpcode =
  5089. DAC960_V1_GetDeviceState;
  5090. DAC960_P_To_PD_TranslateDeviceState(Controller->V1.NewDeviceState);
  5091. break;
  5092. case DAC960_V1_Read_Old:
  5093. Command->V1.CommandMailbox.Common.CommandOpcode = DAC960_V1_Read;
  5094. DAC960_P_To_PD_TranslateReadWriteCommand(CommandMailbox);
  5095. break;
  5096. case DAC960_V1_Write_Old:
  5097. Command->V1.CommandMailbox.Common.CommandOpcode = DAC960_V1_Write;
  5098. DAC960_P_To_PD_TranslateReadWriteCommand(CommandMailbox);
  5099. break;
  5100. case DAC960_V1_ReadWithScatterGather_Old:
  5101. Command->V1.CommandMailbox.Common.CommandOpcode =
  5102. DAC960_V1_ReadWithScatterGather;
  5103. DAC960_P_To_PD_TranslateReadWriteCommand(CommandMailbox);
  5104. break;
  5105. case DAC960_V1_WriteWithScatterGather_Old:
  5106. Command->V1.CommandMailbox.Common.CommandOpcode =
  5107. DAC960_V1_WriteWithScatterGather;
  5108. DAC960_P_To_PD_TranslateReadWriteCommand(CommandMailbox);
  5109. break;
  5110. default:
  5111. break;
  5112. }
  5113. DAC960_V1_ProcessCompletedCommand(Command);
  5114. }
  5115. /*
  5116. Attempt to remove additional I/O Requests from the Controller's
  5117. I/O Request Queue and queue them to the Controller.
  5118. */
  5119. DAC960_ProcessRequest(Controller);
  5120. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  5121. return IRQ_HANDLED;
  5122. }
  5123. /*
  5124. DAC960_V1_QueueMonitoringCommand queues a Monitoring Command to DAC960 V1
  5125. Firmware Controllers.
  5126. */
  5127. static void DAC960_V1_QueueMonitoringCommand(DAC960_Command_T *Command)
  5128. {
  5129. DAC960_Controller_T *Controller = Command->Controller;
  5130. DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  5131. DAC960_V1_ClearCommand(Command);
  5132. Command->CommandType = DAC960_MonitoringCommand;
  5133. CommandMailbox->Type3.CommandOpcode = DAC960_V1_Enquiry;
  5134. CommandMailbox->Type3.BusAddress = Controller->V1.NewEnquiryDMA;
  5135. DAC960_QueueCommand(Command);
  5136. }
  5137. /*
  5138. DAC960_V2_QueueMonitoringCommand queues a Monitoring Command to DAC960 V2
  5139. Firmware Controllers.
  5140. */
  5141. static void DAC960_V2_QueueMonitoringCommand(DAC960_Command_T *Command)
  5142. {
  5143. DAC960_Controller_T *Controller = Command->Controller;
  5144. DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
  5145. DAC960_V2_ClearCommand(Command);
  5146. Command->CommandType = DAC960_MonitoringCommand;
  5147. CommandMailbox->ControllerInfo.CommandOpcode = DAC960_V2_IOCTL;
  5148. CommandMailbox->ControllerInfo.CommandControlBits
  5149. .DataTransferControllerToHost = true;
  5150. CommandMailbox->ControllerInfo.CommandControlBits
  5151. .NoAutoRequestSense = true;
  5152. CommandMailbox->ControllerInfo.DataTransferSize =
  5153. sizeof(DAC960_V2_ControllerInfo_T);
  5154. CommandMailbox->ControllerInfo.ControllerNumber = 0;
  5155. CommandMailbox->ControllerInfo.IOCTL_Opcode = DAC960_V2_GetControllerInfo;
  5156. CommandMailbox->ControllerInfo.DataTransferMemoryAddress
  5157. .ScatterGatherSegments[0]
  5158. .SegmentDataPointer =
  5159. Controller->V2.NewControllerInformationDMA;
  5160. CommandMailbox->ControllerInfo.DataTransferMemoryAddress
  5161. .ScatterGatherSegments[0]
  5162. .SegmentByteCount =
  5163. CommandMailbox->ControllerInfo.DataTransferSize;
  5164. DAC960_QueueCommand(Command);
  5165. }
  5166. /*
  5167. DAC960_MonitoringTimerFunction is the timer function for monitoring
  5168. the status of DAC960 Controllers.
  5169. */
  5170. static void DAC960_MonitoringTimerFunction(unsigned long TimerData)
  5171. {
  5172. DAC960_Controller_T *Controller = (DAC960_Controller_T *) TimerData;
  5173. DAC960_Command_T *Command;
  5174. unsigned long flags;
  5175. if (Controller->FirmwareType == DAC960_V1_Controller)
  5176. {
  5177. spin_lock_irqsave(&Controller->queue_lock, flags);
  5178. /*
  5179. Queue a Status Monitoring Command to Controller.
  5180. */
  5181. Command = DAC960_AllocateCommand(Controller);
  5182. if (Command != NULL)
  5183. DAC960_V1_QueueMonitoringCommand(Command);
  5184. else Controller->MonitoringCommandDeferred = true;
  5185. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  5186. }
  5187. else
  5188. {
  5189. DAC960_V2_ControllerInfo_T *ControllerInfo =
  5190. &Controller->V2.ControllerInformation;
  5191. unsigned int StatusChangeCounter =
  5192. Controller->V2.HealthStatusBuffer->StatusChangeCounter;
  5193. bool ForceMonitoringCommand = false;
  5194. if (time_after(jiffies, Controller->SecondaryMonitoringTime
  5195. + DAC960_SecondaryMonitoringInterval))
  5196. {
  5197. int LogicalDriveNumber;
  5198. for (LogicalDriveNumber = 0;
  5199. LogicalDriveNumber < DAC960_MaxLogicalDrives;
  5200. LogicalDriveNumber++)
  5201. {
  5202. DAC960_V2_LogicalDeviceInfo_T *LogicalDeviceInfo =
  5203. Controller->V2.LogicalDeviceInformation[LogicalDriveNumber];
  5204. if (LogicalDeviceInfo == NULL) continue;
  5205. if (!LogicalDeviceInfo->LogicalDeviceControl
  5206. .LogicalDeviceInitialized)
  5207. {
  5208. ForceMonitoringCommand = true;
  5209. break;
  5210. }
  5211. }
  5212. Controller->SecondaryMonitoringTime = jiffies;
  5213. }
  5214. if (StatusChangeCounter == Controller->V2.StatusChangeCounter &&
  5215. Controller->V2.HealthStatusBuffer->NextEventSequenceNumber
  5216. == Controller->V2.NextEventSequenceNumber &&
  5217. (ControllerInfo->BackgroundInitializationsActive +
  5218. ControllerInfo->LogicalDeviceInitializationsActive +
  5219. ControllerInfo->PhysicalDeviceInitializationsActive +
  5220. ControllerInfo->ConsistencyChecksActive +
  5221. ControllerInfo->RebuildsActive +
  5222. ControllerInfo->OnlineExpansionsActive == 0 ||
  5223. time_before(jiffies, Controller->PrimaryMonitoringTime
  5224. + DAC960_MonitoringTimerInterval)) &&
  5225. !ForceMonitoringCommand)
  5226. {
  5227. Controller->MonitoringTimer.expires =
  5228. jiffies + DAC960_HealthStatusMonitoringInterval;
  5229. add_timer(&Controller->MonitoringTimer);
  5230. return;
  5231. }
  5232. Controller->V2.StatusChangeCounter = StatusChangeCounter;
  5233. Controller->PrimaryMonitoringTime = jiffies;
  5234. spin_lock_irqsave(&Controller->queue_lock, flags);
  5235. /*
  5236. Queue a Status Monitoring Command to Controller.
  5237. */
  5238. Command = DAC960_AllocateCommand(Controller);
  5239. if (Command != NULL)
  5240. DAC960_V2_QueueMonitoringCommand(Command);
  5241. else Controller->MonitoringCommandDeferred = true;
  5242. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  5243. /*
  5244. Wake up any processes waiting on a Health Status Buffer change.
  5245. */
  5246. wake_up(&Controller->HealthStatusWaitQueue);
  5247. }
  5248. }
  5249. /*
  5250. DAC960_CheckStatusBuffer verifies that there is room to hold ByteCount
  5251. additional bytes in the Combined Status Buffer and grows the buffer if
  5252. necessary. It returns true if there is enough room and false otherwise.
  5253. */
  5254. static bool DAC960_CheckStatusBuffer(DAC960_Controller_T *Controller,
  5255. unsigned int ByteCount)
  5256. {
  5257. unsigned char *NewStatusBuffer;
  5258. if (Controller->InitialStatusLength + 1 +
  5259. Controller->CurrentStatusLength + ByteCount + 1 <=
  5260. Controller->CombinedStatusBufferLength)
  5261. return true;
  5262. if (Controller->CombinedStatusBufferLength == 0)
  5263. {
  5264. unsigned int NewStatusBufferLength = DAC960_InitialStatusBufferSize;
  5265. while (NewStatusBufferLength < ByteCount)
  5266. NewStatusBufferLength *= 2;
  5267. Controller->CombinedStatusBuffer = kmalloc(NewStatusBufferLength,
  5268. GFP_ATOMIC);
  5269. if (Controller->CombinedStatusBuffer == NULL) return false;
  5270. Controller->CombinedStatusBufferLength = NewStatusBufferLength;
  5271. return true;
  5272. }
  5273. NewStatusBuffer = kmalloc(2 * Controller->CombinedStatusBufferLength,
  5274. GFP_ATOMIC);
  5275. if (NewStatusBuffer == NULL)
  5276. {
  5277. DAC960_Warning("Unable to expand Combined Status Buffer - Truncating\n",
  5278. Controller);
  5279. return false;
  5280. }
  5281. memcpy(NewStatusBuffer, Controller->CombinedStatusBuffer,
  5282. Controller->CombinedStatusBufferLength);
  5283. kfree(Controller->CombinedStatusBuffer);
  5284. Controller->CombinedStatusBuffer = NewStatusBuffer;
  5285. Controller->CombinedStatusBufferLength *= 2;
  5286. Controller->CurrentStatusBuffer =
  5287. &NewStatusBuffer[Controller->InitialStatusLength + 1];
  5288. return true;
  5289. }
  5290. /*
  5291. DAC960_Message prints Driver Messages.
  5292. */
  5293. static void DAC960_Message(DAC960_MessageLevel_T MessageLevel,
  5294. unsigned char *Format,
  5295. DAC960_Controller_T *Controller,
  5296. ...)
  5297. {
  5298. static unsigned char Buffer[DAC960_LineBufferSize];
  5299. static bool BeginningOfLine = true;
  5300. va_list Arguments;
  5301. int Length = 0;
  5302. va_start(Arguments, Controller);
  5303. Length = vsprintf(Buffer, Format, Arguments);
  5304. va_end(Arguments);
  5305. if (Controller == NULL)
  5306. printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel],
  5307. DAC960_ControllerCount, Buffer);
  5308. else if (MessageLevel == DAC960_AnnounceLevel ||
  5309. MessageLevel == DAC960_InfoLevel)
  5310. {
  5311. if (!Controller->ControllerInitialized)
  5312. {
  5313. if (DAC960_CheckStatusBuffer(Controller, Length))
  5314. {
  5315. strcpy(&Controller->CombinedStatusBuffer
  5316. [Controller->InitialStatusLength],
  5317. Buffer);
  5318. Controller->InitialStatusLength += Length;
  5319. Controller->CurrentStatusBuffer =
  5320. &Controller->CombinedStatusBuffer
  5321. [Controller->InitialStatusLength + 1];
  5322. }
  5323. if (MessageLevel == DAC960_AnnounceLevel)
  5324. {
  5325. static int AnnouncementLines = 0;
  5326. if (++AnnouncementLines <= 2)
  5327. printk("%sDAC960: %s", DAC960_MessageLevelMap[MessageLevel],
  5328. Buffer);
  5329. }
  5330. else
  5331. {
  5332. if (BeginningOfLine)
  5333. {
  5334. if (Buffer[0] != '\n' || Length > 1)
  5335. printk("%sDAC960#%d: %s",
  5336. DAC960_MessageLevelMap[MessageLevel],
  5337. Controller->ControllerNumber, Buffer);
  5338. }
  5339. else printk("%s", Buffer);
  5340. }
  5341. }
  5342. else if (DAC960_CheckStatusBuffer(Controller, Length))
  5343. {
  5344. strcpy(&Controller->CurrentStatusBuffer[
  5345. Controller->CurrentStatusLength], Buffer);
  5346. Controller->CurrentStatusLength += Length;
  5347. }
  5348. }
  5349. else if (MessageLevel == DAC960_ProgressLevel)
  5350. {
  5351. strcpy(Controller->ProgressBuffer, Buffer);
  5352. Controller->ProgressBufferLength = Length;
  5353. if (Controller->EphemeralProgressMessage)
  5354. {
  5355. if (time_after_eq(jiffies, Controller->LastProgressReportTime
  5356. + DAC960_ProgressReportingInterval))
  5357. {
  5358. printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel],
  5359. Controller->ControllerNumber, Buffer);
  5360. Controller->LastProgressReportTime = jiffies;
  5361. }
  5362. }
  5363. else printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel],
  5364. Controller->ControllerNumber, Buffer);
  5365. }
  5366. else if (MessageLevel == DAC960_UserCriticalLevel)
  5367. {
  5368. strcpy(&Controller->UserStatusBuffer[Controller->UserStatusLength],
  5369. Buffer);
  5370. Controller->UserStatusLength += Length;
  5371. if (Buffer[0] != '\n' || Length > 1)
  5372. printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel],
  5373. Controller->ControllerNumber, Buffer);
  5374. }
  5375. else
  5376. {
  5377. if (BeginningOfLine)
  5378. printk("%sDAC960#%d: %s", DAC960_MessageLevelMap[MessageLevel],
  5379. Controller->ControllerNumber, Buffer);
  5380. else printk("%s", Buffer);
  5381. }
  5382. BeginningOfLine = (Buffer[Length-1] == '\n');
  5383. }
  5384. /*
  5385. DAC960_ParsePhysicalDevice parses spaces followed by a Physical Device
  5386. Channel:TargetID specification from a User Command string. It updates
  5387. Channel and TargetID and returns true on success and false on failure.
  5388. */
  5389. static bool DAC960_ParsePhysicalDevice(DAC960_Controller_T *Controller,
  5390. char *UserCommandString,
  5391. unsigned char *Channel,
  5392. unsigned char *TargetID)
  5393. {
  5394. char *NewUserCommandString = UserCommandString;
  5395. unsigned long XChannel, XTargetID;
  5396. while (*UserCommandString == ' ') UserCommandString++;
  5397. if (UserCommandString == NewUserCommandString)
  5398. return false;
  5399. XChannel = simple_strtoul(UserCommandString, &NewUserCommandString, 10);
  5400. if (NewUserCommandString == UserCommandString ||
  5401. *NewUserCommandString != ':' ||
  5402. XChannel >= Controller->Channels)
  5403. return false;
  5404. UserCommandString = ++NewUserCommandString;
  5405. XTargetID = simple_strtoul(UserCommandString, &NewUserCommandString, 10);
  5406. if (NewUserCommandString == UserCommandString ||
  5407. *NewUserCommandString != '\0' ||
  5408. XTargetID >= Controller->Targets)
  5409. return false;
  5410. *Channel = XChannel;
  5411. *TargetID = XTargetID;
  5412. return true;
  5413. }
  5414. /*
  5415. DAC960_ParseLogicalDrive parses spaces followed by a Logical Drive Number
  5416. specification from a User Command string. It updates LogicalDriveNumber and
  5417. returns true on success and false on failure.
  5418. */
  5419. static bool DAC960_ParseLogicalDrive(DAC960_Controller_T *Controller,
  5420. char *UserCommandString,
  5421. unsigned char *LogicalDriveNumber)
  5422. {
  5423. char *NewUserCommandString = UserCommandString;
  5424. unsigned long XLogicalDriveNumber;
  5425. while (*UserCommandString == ' ') UserCommandString++;
  5426. if (UserCommandString == NewUserCommandString)
  5427. return false;
  5428. XLogicalDriveNumber =
  5429. simple_strtoul(UserCommandString, &NewUserCommandString, 10);
  5430. if (NewUserCommandString == UserCommandString ||
  5431. *NewUserCommandString != '\0' ||
  5432. XLogicalDriveNumber > DAC960_MaxLogicalDrives - 1)
  5433. return false;
  5434. *LogicalDriveNumber = XLogicalDriveNumber;
  5435. return true;
  5436. }
  5437. /*
  5438. DAC960_V1_SetDeviceState sets the Device State for a Physical Device for
  5439. DAC960 V1 Firmware Controllers.
  5440. */
  5441. static void DAC960_V1_SetDeviceState(DAC960_Controller_T *Controller,
  5442. DAC960_Command_T *Command,
  5443. unsigned char Channel,
  5444. unsigned char TargetID,
  5445. DAC960_V1_PhysicalDeviceState_T
  5446. DeviceState,
  5447. const unsigned char *DeviceStateString)
  5448. {
  5449. DAC960_V1_CommandMailbox_T *CommandMailbox = &Command->V1.CommandMailbox;
  5450. CommandMailbox->Type3D.CommandOpcode = DAC960_V1_StartDevice;
  5451. CommandMailbox->Type3D.Channel = Channel;
  5452. CommandMailbox->Type3D.TargetID = TargetID;
  5453. CommandMailbox->Type3D.DeviceState = DeviceState;
  5454. CommandMailbox->Type3D.Modifier = 0;
  5455. DAC960_ExecuteCommand(Command);
  5456. switch (Command->V1.CommandStatus)
  5457. {
  5458. case DAC960_V1_NormalCompletion:
  5459. DAC960_UserCritical("%s of Physical Device %d:%d Succeeded\n", Controller,
  5460. DeviceStateString, Channel, TargetID);
  5461. break;
  5462. case DAC960_V1_UnableToStartDevice:
  5463. DAC960_UserCritical("%s of Physical Device %d:%d Failed - "
  5464. "Unable to Start Device\n", Controller,
  5465. DeviceStateString, Channel, TargetID);
  5466. break;
  5467. case DAC960_V1_NoDeviceAtAddress:
  5468. DAC960_UserCritical("%s of Physical Device %d:%d Failed - "
  5469. "No Device at Address\n", Controller,
  5470. DeviceStateString, Channel, TargetID);
  5471. break;
  5472. case DAC960_V1_InvalidChannelOrTargetOrModifier:
  5473. DAC960_UserCritical("%s of Physical Device %d:%d Failed - "
  5474. "Invalid Channel or Target or Modifier\n",
  5475. Controller, DeviceStateString, Channel, TargetID);
  5476. break;
  5477. case DAC960_V1_ChannelBusy:
  5478. DAC960_UserCritical("%s of Physical Device %d:%d Failed - "
  5479. "Channel Busy\n", Controller,
  5480. DeviceStateString, Channel, TargetID);
  5481. break;
  5482. default:
  5483. DAC960_UserCritical("%s of Physical Device %d:%d Failed - "
  5484. "Unexpected Status %04X\n", Controller,
  5485. DeviceStateString, Channel, TargetID,
  5486. Command->V1.CommandStatus);
  5487. break;
  5488. }
  5489. }
  5490. /*
  5491. DAC960_V1_ExecuteUserCommand executes a User Command for DAC960 V1 Firmware
  5492. Controllers.
  5493. */
  5494. static bool DAC960_V1_ExecuteUserCommand(DAC960_Controller_T *Controller,
  5495. unsigned char *UserCommand)
  5496. {
  5497. DAC960_Command_T *Command;
  5498. DAC960_V1_CommandMailbox_T *CommandMailbox;
  5499. unsigned long flags;
  5500. unsigned char Channel, TargetID, LogicalDriveNumber;
  5501. spin_lock_irqsave(&Controller->queue_lock, flags);
  5502. while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
  5503. DAC960_WaitForCommand(Controller);
  5504. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  5505. Controller->UserStatusLength = 0;
  5506. DAC960_V1_ClearCommand(Command);
  5507. Command->CommandType = DAC960_ImmediateCommand;
  5508. CommandMailbox = &Command->V1.CommandMailbox;
  5509. if (strcmp(UserCommand, "flush-cache") == 0)
  5510. {
  5511. CommandMailbox->Type3.CommandOpcode = DAC960_V1_Flush;
  5512. DAC960_ExecuteCommand(Command);
  5513. DAC960_UserCritical("Cache Flush Completed\n", Controller);
  5514. }
  5515. else if (strncmp(UserCommand, "kill", 4) == 0 &&
  5516. DAC960_ParsePhysicalDevice(Controller, &UserCommand[4],
  5517. &Channel, &TargetID))
  5518. {
  5519. DAC960_V1_DeviceState_T *DeviceState =
  5520. &Controller->V1.DeviceState[Channel][TargetID];
  5521. if (DeviceState->Present &&
  5522. DeviceState->DeviceType == DAC960_V1_DiskType &&
  5523. DeviceState->DeviceState != DAC960_V1_Device_Dead)
  5524. DAC960_V1_SetDeviceState(Controller, Command, Channel, TargetID,
  5525. DAC960_V1_Device_Dead, "Kill");
  5526. else DAC960_UserCritical("Kill of Physical Device %d:%d Illegal\n",
  5527. Controller, Channel, TargetID);
  5528. }
  5529. else if (strncmp(UserCommand, "make-online", 11) == 0 &&
  5530. DAC960_ParsePhysicalDevice(Controller, &UserCommand[11],
  5531. &Channel, &TargetID))
  5532. {
  5533. DAC960_V1_DeviceState_T *DeviceState =
  5534. &Controller->V1.DeviceState[Channel][TargetID];
  5535. if (DeviceState->Present &&
  5536. DeviceState->DeviceType == DAC960_V1_DiskType &&
  5537. DeviceState->DeviceState == DAC960_V1_Device_Dead)
  5538. DAC960_V1_SetDeviceState(Controller, Command, Channel, TargetID,
  5539. DAC960_V1_Device_Online, "Make Online");
  5540. else DAC960_UserCritical("Make Online of Physical Device %d:%d Illegal\n",
  5541. Controller, Channel, TargetID);
  5542. }
  5543. else if (strncmp(UserCommand, "make-standby", 12) == 0 &&
  5544. DAC960_ParsePhysicalDevice(Controller, &UserCommand[12],
  5545. &Channel, &TargetID))
  5546. {
  5547. DAC960_V1_DeviceState_T *DeviceState =
  5548. &Controller->V1.DeviceState[Channel][TargetID];
  5549. if (DeviceState->Present &&
  5550. DeviceState->DeviceType == DAC960_V1_DiskType &&
  5551. DeviceState->DeviceState == DAC960_V1_Device_Dead)
  5552. DAC960_V1_SetDeviceState(Controller, Command, Channel, TargetID,
  5553. DAC960_V1_Device_Standby, "Make Standby");
  5554. else DAC960_UserCritical("Make Standby of Physical "
  5555. "Device %d:%d Illegal\n",
  5556. Controller, Channel, TargetID);
  5557. }
  5558. else if (strncmp(UserCommand, "rebuild", 7) == 0 &&
  5559. DAC960_ParsePhysicalDevice(Controller, &UserCommand[7],
  5560. &Channel, &TargetID))
  5561. {
  5562. CommandMailbox->Type3D.CommandOpcode = DAC960_V1_RebuildAsync;
  5563. CommandMailbox->Type3D.Channel = Channel;
  5564. CommandMailbox->Type3D.TargetID = TargetID;
  5565. DAC960_ExecuteCommand(Command);
  5566. switch (Command->V1.CommandStatus)
  5567. {
  5568. case DAC960_V1_NormalCompletion:
  5569. DAC960_UserCritical("Rebuild of Physical Device %d:%d Initiated\n",
  5570. Controller, Channel, TargetID);
  5571. break;
  5572. case DAC960_V1_AttemptToRebuildOnlineDrive:
  5573. DAC960_UserCritical("Rebuild of Physical Device %d:%d Failed - "
  5574. "Attempt to Rebuild Online or "
  5575. "Unresponsive Drive\n",
  5576. Controller, Channel, TargetID);
  5577. break;
  5578. case DAC960_V1_NewDiskFailedDuringRebuild:
  5579. DAC960_UserCritical("Rebuild of Physical Device %d:%d Failed - "
  5580. "New Disk Failed During Rebuild\n",
  5581. Controller, Channel, TargetID);
  5582. break;
  5583. case DAC960_V1_InvalidDeviceAddress:
  5584. DAC960_UserCritical("Rebuild of Physical Device %d:%d Failed - "
  5585. "Invalid Device Address\n",
  5586. Controller, Channel, TargetID);
  5587. break;
  5588. case DAC960_V1_RebuildOrCheckAlreadyInProgress:
  5589. DAC960_UserCritical("Rebuild of Physical Device %d:%d Failed - "
  5590. "Rebuild or Consistency Check Already "
  5591. "in Progress\n", Controller, Channel, TargetID);
  5592. break;
  5593. default:
  5594. DAC960_UserCritical("Rebuild of Physical Device %d:%d Failed - "
  5595. "Unexpected Status %04X\n", Controller,
  5596. Channel, TargetID, Command->V1.CommandStatus);
  5597. break;
  5598. }
  5599. }
  5600. else if (strncmp(UserCommand, "check-consistency", 17) == 0 &&
  5601. DAC960_ParseLogicalDrive(Controller, &UserCommand[17],
  5602. &LogicalDriveNumber))
  5603. {
  5604. CommandMailbox->Type3C.CommandOpcode = DAC960_V1_CheckConsistencyAsync;
  5605. CommandMailbox->Type3C.LogicalDriveNumber = LogicalDriveNumber;
  5606. CommandMailbox->Type3C.AutoRestore = true;
  5607. DAC960_ExecuteCommand(Command);
  5608. switch (Command->V1.CommandStatus)
  5609. {
  5610. case DAC960_V1_NormalCompletion:
  5611. DAC960_UserCritical("Consistency Check of Logical Drive %d "
  5612. "(/dev/rd/c%dd%d) Initiated\n",
  5613. Controller, LogicalDriveNumber,
  5614. Controller->ControllerNumber,
  5615. LogicalDriveNumber);
  5616. break;
  5617. case DAC960_V1_DependentDiskIsDead:
  5618. DAC960_UserCritical("Consistency Check of Logical Drive %d "
  5619. "(/dev/rd/c%dd%d) Failed - "
  5620. "Dependent Physical Device is DEAD\n",
  5621. Controller, LogicalDriveNumber,
  5622. Controller->ControllerNumber,
  5623. LogicalDriveNumber);
  5624. break;
  5625. case DAC960_V1_InvalidOrNonredundantLogicalDrive:
  5626. DAC960_UserCritical("Consistency Check of Logical Drive %d "
  5627. "(/dev/rd/c%dd%d) Failed - "
  5628. "Invalid or Nonredundant Logical Drive\n",
  5629. Controller, LogicalDriveNumber,
  5630. Controller->ControllerNumber,
  5631. LogicalDriveNumber);
  5632. break;
  5633. case DAC960_V1_RebuildOrCheckAlreadyInProgress:
  5634. DAC960_UserCritical("Consistency Check of Logical Drive %d "
  5635. "(/dev/rd/c%dd%d) Failed - Rebuild or "
  5636. "Consistency Check Already in Progress\n",
  5637. Controller, LogicalDriveNumber,
  5638. Controller->ControllerNumber,
  5639. LogicalDriveNumber);
  5640. break;
  5641. default:
  5642. DAC960_UserCritical("Consistency Check of Logical Drive %d "
  5643. "(/dev/rd/c%dd%d) Failed - "
  5644. "Unexpected Status %04X\n",
  5645. Controller, LogicalDriveNumber,
  5646. Controller->ControllerNumber,
  5647. LogicalDriveNumber, Command->V1.CommandStatus);
  5648. break;
  5649. }
  5650. }
  5651. else if (strcmp(UserCommand, "cancel-rebuild") == 0 ||
  5652. strcmp(UserCommand, "cancel-consistency-check") == 0)
  5653. {
  5654. /*
  5655. the OldRebuildRateConstant is never actually used
  5656. once its value is retrieved from the controller.
  5657. */
  5658. unsigned char *OldRebuildRateConstant;
  5659. dma_addr_t OldRebuildRateConstantDMA;
  5660. OldRebuildRateConstant = pci_alloc_consistent( Controller->PCIDevice,
  5661. sizeof(char), &OldRebuildRateConstantDMA);
  5662. if (OldRebuildRateConstant == NULL) {
  5663. DAC960_UserCritical("Cancellation of Rebuild or "
  5664. "Consistency Check Failed - "
  5665. "Out of Memory",
  5666. Controller);
  5667. goto failure;
  5668. }
  5669. CommandMailbox->Type3R.CommandOpcode = DAC960_V1_RebuildControl;
  5670. CommandMailbox->Type3R.RebuildRateConstant = 0xFF;
  5671. CommandMailbox->Type3R.BusAddress = OldRebuildRateConstantDMA;
  5672. DAC960_ExecuteCommand(Command);
  5673. switch (Command->V1.CommandStatus)
  5674. {
  5675. case DAC960_V1_NormalCompletion:
  5676. DAC960_UserCritical("Rebuild or Consistency Check Cancelled\n",
  5677. Controller);
  5678. break;
  5679. default:
  5680. DAC960_UserCritical("Cancellation of Rebuild or "
  5681. "Consistency Check Failed - "
  5682. "Unexpected Status %04X\n",
  5683. Controller, Command->V1.CommandStatus);
  5684. break;
  5685. }
  5686. failure:
  5687. pci_free_consistent(Controller->PCIDevice, sizeof(char),
  5688. OldRebuildRateConstant, OldRebuildRateConstantDMA);
  5689. }
  5690. else DAC960_UserCritical("Illegal User Command: '%s'\n",
  5691. Controller, UserCommand);
  5692. spin_lock_irqsave(&Controller->queue_lock, flags);
  5693. DAC960_DeallocateCommand(Command);
  5694. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  5695. return true;
  5696. }
  5697. /*
  5698. DAC960_V2_TranslatePhysicalDevice translates a Physical Device Channel and
  5699. TargetID into a Logical Device. It returns true on success and false
  5700. on failure.
  5701. */
  5702. static bool DAC960_V2_TranslatePhysicalDevice(DAC960_Command_T *Command,
  5703. unsigned char Channel,
  5704. unsigned char TargetID,
  5705. unsigned short
  5706. *LogicalDeviceNumber)
  5707. {
  5708. DAC960_V2_CommandMailbox_T SavedCommandMailbox, *CommandMailbox;
  5709. DAC960_Controller_T *Controller = Command->Controller;
  5710. CommandMailbox = &Command->V2.CommandMailbox;
  5711. memcpy(&SavedCommandMailbox, CommandMailbox,
  5712. sizeof(DAC960_V2_CommandMailbox_T));
  5713. CommandMailbox->PhysicalDeviceInfo.CommandOpcode = DAC960_V2_IOCTL;
  5714. CommandMailbox->PhysicalDeviceInfo.CommandControlBits
  5715. .DataTransferControllerToHost = true;
  5716. CommandMailbox->PhysicalDeviceInfo.CommandControlBits
  5717. .NoAutoRequestSense = true;
  5718. CommandMailbox->PhysicalDeviceInfo.DataTransferSize =
  5719. sizeof(DAC960_V2_PhysicalToLogicalDevice_T);
  5720. CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.TargetID = TargetID;
  5721. CommandMailbox->PhysicalDeviceInfo.PhysicalDevice.Channel = Channel;
  5722. CommandMailbox->PhysicalDeviceInfo.IOCTL_Opcode =
  5723. DAC960_V2_TranslatePhysicalToLogicalDevice;
  5724. CommandMailbox->Common.DataTransferMemoryAddress
  5725. .ScatterGatherSegments[0]
  5726. .SegmentDataPointer =
  5727. Controller->V2.PhysicalToLogicalDeviceDMA;
  5728. CommandMailbox->Common.DataTransferMemoryAddress
  5729. .ScatterGatherSegments[0]
  5730. .SegmentByteCount =
  5731. CommandMailbox->Common.DataTransferSize;
  5732. DAC960_ExecuteCommand(Command);
  5733. *LogicalDeviceNumber = Controller->V2.PhysicalToLogicalDevice->LogicalDeviceNumber;
  5734. memcpy(CommandMailbox, &SavedCommandMailbox,
  5735. sizeof(DAC960_V2_CommandMailbox_T));
  5736. return (Command->V2.CommandStatus == DAC960_V2_NormalCompletion);
  5737. }
  5738. /*
  5739. DAC960_V2_ExecuteUserCommand executes a User Command for DAC960 V2 Firmware
  5740. Controllers.
  5741. */
  5742. static bool DAC960_V2_ExecuteUserCommand(DAC960_Controller_T *Controller,
  5743. unsigned char *UserCommand)
  5744. {
  5745. DAC960_Command_T *Command;
  5746. DAC960_V2_CommandMailbox_T *CommandMailbox;
  5747. unsigned long flags;
  5748. unsigned char Channel, TargetID, LogicalDriveNumber;
  5749. unsigned short LogicalDeviceNumber;
  5750. spin_lock_irqsave(&Controller->queue_lock, flags);
  5751. while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
  5752. DAC960_WaitForCommand(Controller);
  5753. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  5754. Controller->UserStatusLength = 0;
  5755. DAC960_V2_ClearCommand(Command);
  5756. Command->CommandType = DAC960_ImmediateCommand;
  5757. CommandMailbox = &Command->V2.CommandMailbox;
  5758. CommandMailbox->Common.CommandOpcode = DAC960_V2_IOCTL;
  5759. CommandMailbox->Common.CommandControlBits.DataTransferControllerToHost = true;
  5760. CommandMailbox->Common.CommandControlBits.NoAutoRequestSense = true;
  5761. if (strcmp(UserCommand, "flush-cache") == 0)
  5762. {
  5763. CommandMailbox->DeviceOperation.IOCTL_Opcode = DAC960_V2_PauseDevice;
  5764. CommandMailbox->DeviceOperation.OperationDevice =
  5765. DAC960_V2_RAID_Controller;
  5766. DAC960_ExecuteCommand(Command);
  5767. DAC960_UserCritical("Cache Flush Completed\n", Controller);
  5768. }
  5769. else if (strncmp(UserCommand, "kill", 4) == 0 &&
  5770. DAC960_ParsePhysicalDevice(Controller, &UserCommand[4],
  5771. &Channel, &TargetID) &&
  5772. DAC960_V2_TranslatePhysicalDevice(Command, Channel, TargetID,
  5773. &LogicalDeviceNumber))
  5774. {
  5775. CommandMailbox->SetDeviceState.LogicalDevice.LogicalDeviceNumber =
  5776. LogicalDeviceNumber;
  5777. CommandMailbox->SetDeviceState.IOCTL_Opcode =
  5778. DAC960_V2_SetDeviceState;
  5779. CommandMailbox->SetDeviceState.DeviceState.PhysicalDeviceState =
  5780. DAC960_V2_Device_Dead;
  5781. DAC960_ExecuteCommand(Command);
  5782. DAC960_UserCritical("Kill of Physical Device %d:%d %s\n",
  5783. Controller, Channel, TargetID,
  5784. (Command->V2.CommandStatus
  5785. == DAC960_V2_NormalCompletion
  5786. ? "Succeeded" : "Failed"));
  5787. }
  5788. else if (strncmp(UserCommand, "make-online", 11) == 0 &&
  5789. DAC960_ParsePhysicalDevice(Controller, &UserCommand[11],
  5790. &Channel, &TargetID) &&
  5791. DAC960_V2_TranslatePhysicalDevice(Command, Channel, TargetID,
  5792. &LogicalDeviceNumber))
  5793. {
  5794. CommandMailbox->SetDeviceState.LogicalDevice.LogicalDeviceNumber =
  5795. LogicalDeviceNumber;
  5796. CommandMailbox->SetDeviceState.IOCTL_Opcode =
  5797. DAC960_V2_SetDeviceState;
  5798. CommandMailbox->SetDeviceState.DeviceState.PhysicalDeviceState =
  5799. DAC960_V2_Device_Online;
  5800. DAC960_ExecuteCommand(Command);
  5801. DAC960_UserCritical("Make Online of Physical Device %d:%d %s\n",
  5802. Controller, Channel, TargetID,
  5803. (Command->V2.CommandStatus
  5804. == DAC960_V2_NormalCompletion
  5805. ? "Succeeded" : "Failed"));
  5806. }
  5807. else if (strncmp(UserCommand, "make-standby", 12) == 0 &&
  5808. DAC960_ParsePhysicalDevice(Controller, &UserCommand[12],
  5809. &Channel, &TargetID) &&
  5810. DAC960_V2_TranslatePhysicalDevice(Command, Channel, TargetID,
  5811. &LogicalDeviceNumber))
  5812. {
  5813. CommandMailbox->SetDeviceState.LogicalDevice.LogicalDeviceNumber =
  5814. LogicalDeviceNumber;
  5815. CommandMailbox->SetDeviceState.IOCTL_Opcode =
  5816. DAC960_V2_SetDeviceState;
  5817. CommandMailbox->SetDeviceState.DeviceState.PhysicalDeviceState =
  5818. DAC960_V2_Device_Standby;
  5819. DAC960_ExecuteCommand(Command);
  5820. DAC960_UserCritical("Make Standby of Physical Device %d:%d %s\n",
  5821. Controller, Channel, TargetID,
  5822. (Command->V2.CommandStatus
  5823. == DAC960_V2_NormalCompletion
  5824. ? "Succeeded" : "Failed"));
  5825. }
  5826. else if (strncmp(UserCommand, "rebuild", 7) == 0 &&
  5827. DAC960_ParsePhysicalDevice(Controller, &UserCommand[7],
  5828. &Channel, &TargetID) &&
  5829. DAC960_V2_TranslatePhysicalDevice(Command, Channel, TargetID,
  5830. &LogicalDeviceNumber))
  5831. {
  5832. CommandMailbox->LogicalDeviceInfo.LogicalDevice.LogicalDeviceNumber =
  5833. LogicalDeviceNumber;
  5834. CommandMailbox->LogicalDeviceInfo.IOCTL_Opcode =
  5835. DAC960_V2_RebuildDeviceStart;
  5836. DAC960_ExecuteCommand(Command);
  5837. DAC960_UserCritical("Rebuild of Physical Device %d:%d %s\n",
  5838. Controller, Channel, TargetID,
  5839. (Command->V2.CommandStatus
  5840. == DAC960_V2_NormalCompletion
  5841. ? "Initiated" : "Not Initiated"));
  5842. }
  5843. else if (strncmp(UserCommand, "cancel-rebuild", 14) == 0 &&
  5844. DAC960_ParsePhysicalDevice(Controller, &UserCommand[14],
  5845. &Channel, &TargetID) &&
  5846. DAC960_V2_TranslatePhysicalDevice(Command, Channel, TargetID,
  5847. &LogicalDeviceNumber))
  5848. {
  5849. CommandMailbox->LogicalDeviceInfo.LogicalDevice.LogicalDeviceNumber =
  5850. LogicalDeviceNumber;
  5851. CommandMailbox->LogicalDeviceInfo.IOCTL_Opcode =
  5852. DAC960_V2_RebuildDeviceStop;
  5853. DAC960_ExecuteCommand(Command);
  5854. DAC960_UserCritical("Rebuild of Physical Device %d:%d %s\n",
  5855. Controller, Channel, TargetID,
  5856. (Command->V2.CommandStatus
  5857. == DAC960_V2_NormalCompletion
  5858. ? "Cancelled" : "Not Cancelled"));
  5859. }
  5860. else if (strncmp(UserCommand, "check-consistency", 17) == 0 &&
  5861. DAC960_ParseLogicalDrive(Controller, &UserCommand[17],
  5862. &LogicalDriveNumber))
  5863. {
  5864. CommandMailbox->ConsistencyCheck.LogicalDevice.LogicalDeviceNumber =
  5865. LogicalDriveNumber;
  5866. CommandMailbox->ConsistencyCheck.IOCTL_Opcode =
  5867. DAC960_V2_ConsistencyCheckStart;
  5868. CommandMailbox->ConsistencyCheck.RestoreConsistency = true;
  5869. CommandMailbox->ConsistencyCheck.InitializedAreaOnly = false;
  5870. DAC960_ExecuteCommand(Command);
  5871. DAC960_UserCritical("Consistency Check of Logical Drive %d "
  5872. "(/dev/rd/c%dd%d) %s\n",
  5873. Controller, LogicalDriveNumber,
  5874. Controller->ControllerNumber,
  5875. LogicalDriveNumber,
  5876. (Command->V2.CommandStatus
  5877. == DAC960_V2_NormalCompletion
  5878. ? "Initiated" : "Not Initiated"));
  5879. }
  5880. else if (strncmp(UserCommand, "cancel-consistency-check", 24) == 0 &&
  5881. DAC960_ParseLogicalDrive(Controller, &UserCommand[24],
  5882. &LogicalDriveNumber))
  5883. {
  5884. CommandMailbox->ConsistencyCheck.LogicalDevice.LogicalDeviceNumber =
  5885. LogicalDriveNumber;
  5886. CommandMailbox->ConsistencyCheck.IOCTL_Opcode =
  5887. DAC960_V2_ConsistencyCheckStop;
  5888. DAC960_ExecuteCommand(Command);
  5889. DAC960_UserCritical("Consistency Check of Logical Drive %d "
  5890. "(/dev/rd/c%dd%d) %s\n",
  5891. Controller, LogicalDriveNumber,
  5892. Controller->ControllerNumber,
  5893. LogicalDriveNumber,
  5894. (Command->V2.CommandStatus
  5895. == DAC960_V2_NormalCompletion
  5896. ? "Cancelled" : "Not Cancelled"));
  5897. }
  5898. else if (strcmp(UserCommand, "perform-discovery") == 0)
  5899. {
  5900. CommandMailbox->Common.IOCTL_Opcode = DAC960_V2_StartDiscovery;
  5901. DAC960_ExecuteCommand(Command);
  5902. DAC960_UserCritical("Discovery %s\n", Controller,
  5903. (Command->V2.CommandStatus
  5904. == DAC960_V2_NormalCompletion
  5905. ? "Initiated" : "Not Initiated"));
  5906. if (Command->V2.CommandStatus == DAC960_V2_NormalCompletion)
  5907. {
  5908. CommandMailbox->ControllerInfo.CommandOpcode = DAC960_V2_IOCTL;
  5909. CommandMailbox->ControllerInfo.CommandControlBits
  5910. .DataTransferControllerToHost = true;
  5911. CommandMailbox->ControllerInfo.CommandControlBits
  5912. .NoAutoRequestSense = true;
  5913. CommandMailbox->ControllerInfo.DataTransferSize =
  5914. sizeof(DAC960_V2_ControllerInfo_T);
  5915. CommandMailbox->ControllerInfo.ControllerNumber = 0;
  5916. CommandMailbox->ControllerInfo.IOCTL_Opcode =
  5917. DAC960_V2_GetControllerInfo;
  5918. /*
  5919. * How does this NOT race with the queued Monitoring
  5920. * usage of this structure?
  5921. */
  5922. CommandMailbox->ControllerInfo.DataTransferMemoryAddress
  5923. .ScatterGatherSegments[0]
  5924. .SegmentDataPointer =
  5925. Controller->V2.NewControllerInformationDMA;
  5926. CommandMailbox->ControllerInfo.DataTransferMemoryAddress
  5927. .ScatterGatherSegments[0]
  5928. .SegmentByteCount =
  5929. CommandMailbox->ControllerInfo.DataTransferSize;
  5930. DAC960_ExecuteCommand(Command);
  5931. while (Controller->V2.NewControllerInformation->PhysicalScanActive)
  5932. {
  5933. DAC960_ExecuteCommand(Command);
  5934. sleep_on_timeout(&Controller->CommandWaitQueue, HZ);
  5935. }
  5936. DAC960_UserCritical("Discovery Completed\n", Controller);
  5937. }
  5938. }
  5939. else if (strcmp(UserCommand, "suppress-enclosure-messages") == 0)
  5940. Controller->SuppressEnclosureMessages = true;
  5941. else DAC960_UserCritical("Illegal User Command: '%s'\n",
  5942. Controller, UserCommand);
  5943. spin_lock_irqsave(&Controller->queue_lock, flags);
  5944. DAC960_DeallocateCommand(Command);
  5945. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  5946. return true;
  5947. }
  5948. static int dac960_proc_show(struct seq_file *m, void *v)
  5949. {
  5950. unsigned char *StatusMessage = "OK\n";
  5951. int ControllerNumber;
  5952. for (ControllerNumber = 0;
  5953. ControllerNumber < DAC960_ControllerCount;
  5954. ControllerNumber++)
  5955. {
  5956. DAC960_Controller_T *Controller = DAC960_Controllers[ControllerNumber];
  5957. if (Controller == NULL) continue;
  5958. if (Controller->MonitoringAlertMode)
  5959. {
  5960. StatusMessage = "ALERT\n";
  5961. break;
  5962. }
  5963. }
  5964. seq_puts(m, StatusMessage);
  5965. return 0;
  5966. }
  5967. static int dac960_proc_open(struct inode *inode, struct file *file)
  5968. {
  5969. return single_open(file, dac960_proc_show, NULL);
  5970. }
  5971. static const struct file_operations dac960_proc_fops = {
  5972. .owner = THIS_MODULE,
  5973. .open = dac960_proc_open,
  5974. .read = seq_read,
  5975. .llseek = seq_lseek,
  5976. .release = single_release,
  5977. };
  5978. static int dac960_initial_status_proc_show(struct seq_file *m, void *v)
  5979. {
  5980. DAC960_Controller_T *Controller = (DAC960_Controller_T *)m->private;
  5981. seq_printf(m, "%.*s", Controller->InitialStatusLength, Controller->CombinedStatusBuffer);
  5982. return 0;
  5983. }
  5984. static int dac960_initial_status_proc_open(struct inode *inode, struct file *file)
  5985. {
  5986. return single_open(file, dac960_initial_status_proc_show, PDE(inode)->data);
  5987. }
  5988. static const struct file_operations dac960_initial_status_proc_fops = {
  5989. .owner = THIS_MODULE,
  5990. .open = dac960_initial_status_proc_open,
  5991. .read = seq_read,
  5992. .llseek = seq_lseek,
  5993. .release = single_release,
  5994. };
  5995. static int dac960_current_status_proc_show(struct seq_file *m, void *v)
  5996. {
  5997. DAC960_Controller_T *Controller = (DAC960_Controller_T *) m->private;
  5998. unsigned char *StatusMessage =
  5999. "No Rebuild or Consistency Check in Progress\n";
  6000. int ProgressMessageLength = strlen(StatusMessage);
  6001. if (jiffies != Controller->LastCurrentStatusTime)
  6002. {
  6003. Controller->CurrentStatusLength = 0;
  6004. DAC960_AnnounceDriver(Controller);
  6005. DAC960_ReportControllerConfiguration(Controller);
  6006. DAC960_ReportDeviceConfiguration(Controller);
  6007. if (Controller->ProgressBufferLength > 0)
  6008. ProgressMessageLength = Controller->ProgressBufferLength;
  6009. if (DAC960_CheckStatusBuffer(Controller, 2 + ProgressMessageLength))
  6010. {
  6011. unsigned char *CurrentStatusBuffer = Controller->CurrentStatusBuffer;
  6012. CurrentStatusBuffer[Controller->CurrentStatusLength++] = ' ';
  6013. CurrentStatusBuffer[Controller->CurrentStatusLength++] = ' ';
  6014. if (Controller->ProgressBufferLength > 0)
  6015. strcpy(&CurrentStatusBuffer[Controller->CurrentStatusLength],
  6016. Controller->ProgressBuffer);
  6017. else
  6018. strcpy(&CurrentStatusBuffer[Controller->CurrentStatusLength],
  6019. StatusMessage);
  6020. Controller->CurrentStatusLength += ProgressMessageLength;
  6021. }
  6022. Controller->LastCurrentStatusTime = jiffies;
  6023. }
  6024. seq_printf(m, "%.*s", Controller->CurrentStatusLength, Controller->CurrentStatusBuffer);
  6025. return 0;
  6026. }
  6027. static int dac960_current_status_proc_open(struct inode *inode, struct file *file)
  6028. {
  6029. return single_open(file, dac960_current_status_proc_show, PDE(inode)->data);
  6030. }
  6031. static const struct file_operations dac960_current_status_proc_fops = {
  6032. .owner = THIS_MODULE,
  6033. .open = dac960_current_status_proc_open,
  6034. .read = seq_read,
  6035. .llseek = seq_lseek,
  6036. .release = single_release,
  6037. };
  6038. static int dac960_user_command_proc_show(struct seq_file *m, void *v)
  6039. {
  6040. DAC960_Controller_T *Controller = (DAC960_Controller_T *)m->private;
  6041. seq_printf(m, "%.*s", Controller->UserStatusLength, Controller->UserStatusBuffer);
  6042. return 0;
  6043. }
  6044. static int dac960_user_command_proc_open(struct inode *inode, struct file *file)
  6045. {
  6046. return single_open(file, dac960_user_command_proc_show, PDE(inode)->data);
  6047. }
  6048. static ssize_t dac960_user_command_proc_write(struct file *file,
  6049. const char __user *Buffer,
  6050. size_t Count, loff_t *pos)
  6051. {
  6052. DAC960_Controller_T *Controller = (DAC960_Controller_T *) PDE(file->f_path.dentry->d_inode)->data;
  6053. unsigned char CommandBuffer[80];
  6054. int Length;
  6055. if (Count > sizeof(CommandBuffer)-1) return -EINVAL;
  6056. if (copy_from_user(CommandBuffer, Buffer, Count)) return -EFAULT;
  6057. CommandBuffer[Count] = '\0';
  6058. Length = strlen(CommandBuffer);
  6059. if (Length > 0 && CommandBuffer[Length-1] == '\n')
  6060. CommandBuffer[--Length] = '\0';
  6061. if (Controller->FirmwareType == DAC960_V1_Controller)
  6062. return (DAC960_V1_ExecuteUserCommand(Controller, CommandBuffer)
  6063. ? Count : -EBUSY);
  6064. else
  6065. return (DAC960_V2_ExecuteUserCommand(Controller, CommandBuffer)
  6066. ? Count : -EBUSY);
  6067. }
  6068. static const struct file_operations dac960_user_command_proc_fops = {
  6069. .owner = THIS_MODULE,
  6070. .open = dac960_user_command_proc_open,
  6071. .read = seq_read,
  6072. .llseek = seq_lseek,
  6073. .release = single_release,
  6074. .write = dac960_user_command_proc_write,
  6075. };
  6076. /*
  6077. DAC960_CreateProcEntries creates the /proc/rd/... entries for the
  6078. DAC960 Driver.
  6079. */
  6080. static void DAC960_CreateProcEntries(DAC960_Controller_T *Controller)
  6081. {
  6082. struct proc_dir_entry *StatusProcEntry;
  6083. struct proc_dir_entry *ControllerProcEntry;
  6084. struct proc_dir_entry *UserCommandProcEntry;
  6085. if (DAC960_ProcDirectoryEntry == NULL) {
  6086. DAC960_ProcDirectoryEntry = proc_mkdir("rd", NULL);
  6087. StatusProcEntry = proc_create("status", 0,
  6088. DAC960_ProcDirectoryEntry,
  6089. &dac960_proc_fops);
  6090. }
  6091. sprintf(Controller->ControllerName, "c%d", Controller->ControllerNumber);
  6092. ControllerProcEntry = proc_mkdir(Controller->ControllerName,
  6093. DAC960_ProcDirectoryEntry);
  6094. proc_create_data("initial_status", 0, ControllerProcEntry, &dac960_initial_status_proc_fops, Controller);
  6095. proc_create_data("current_status", 0, ControllerProcEntry, &dac960_current_status_proc_fops, Controller);
  6096. UserCommandProcEntry = proc_create_data("user_command", S_IWUSR | S_IRUSR, ControllerProcEntry, &dac960_user_command_proc_fops, Controller);
  6097. Controller->ControllerProcEntry = ControllerProcEntry;
  6098. }
  6099. /*
  6100. DAC960_DestroyProcEntries destroys the /proc/rd/... entries for the
  6101. DAC960 Driver.
  6102. */
  6103. static void DAC960_DestroyProcEntries(DAC960_Controller_T *Controller)
  6104. {
  6105. if (Controller->ControllerProcEntry == NULL)
  6106. return;
  6107. remove_proc_entry("initial_status", Controller->ControllerProcEntry);
  6108. remove_proc_entry("current_status", Controller->ControllerProcEntry);
  6109. remove_proc_entry("user_command", Controller->ControllerProcEntry);
  6110. remove_proc_entry(Controller->ControllerName, DAC960_ProcDirectoryEntry);
  6111. Controller->ControllerProcEntry = NULL;
  6112. }
  6113. #ifdef DAC960_GAM_MINOR
  6114. /*
  6115. * DAC960_gam_ioctl is the ioctl function for performing RAID operations.
  6116. */
  6117. static long DAC960_gam_ioctl(struct file *file, unsigned int Request,
  6118. unsigned long Argument)
  6119. {
  6120. long ErrorCode = 0;
  6121. if (!capable(CAP_SYS_ADMIN)) return -EACCES;
  6122. lock_kernel();
  6123. switch (Request)
  6124. {
  6125. case DAC960_IOCTL_GET_CONTROLLER_COUNT:
  6126. ErrorCode = DAC960_ControllerCount;
  6127. break;
  6128. case DAC960_IOCTL_GET_CONTROLLER_INFO:
  6129. {
  6130. DAC960_ControllerInfo_T __user *UserSpaceControllerInfo =
  6131. (DAC960_ControllerInfo_T __user *) Argument;
  6132. DAC960_ControllerInfo_T ControllerInfo;
  6133. DAC960_Controller_T *Controller;
  6134. int ControllerNumber;
  6135. if (UserSpaceControllerInfo == NULL)
  6136. ErrorCode = -EINVAL;
  6137. else ErrorCode = get_user(ControllerNumber,
  6138. &UserSpaceControllerInfo->ControllerNumber);
  6139. if (ErrorCode != 0)
  6140. break;
  6141. ErrorCode = -ENXIO;
  6142. if (ControllerNumber < 0 ||
  6143. ControllerNumber > DAC960_ControllerCount - 1) {
  6144. break;
  6145. }
  6146. Controller = DAC960_Controllers[ControllerNumber];
  6147. if (Controller == NULL)
  6148. break;
  6149. memset(&ControllerInfo, 0, sizeof(DAC960_ControllerInfo_T));
  6150. ControllerInfo.ControllerNumber = ControllerNumber;
  6151. ControllerInfo.FirmwareType = Controller->FirmwareType;
  6152. ControllerInfo.Channels = Controller->Channels;
  6153. ControllerInfo.Targets = Controller->Targets;
  6154. ControllerInfo.PCI_Bus = Controller->Bus;
  6155. ControllerInfo.PCI_Device = Controller->Device;
  6156. ControllerInfo.PCI_Function = Controller->Function;
  6157. ControllerInfo.IRQ_Channel = Controller->IRQ_Channel;
  6158. ControllerInfo.PCI_Address = Controller->PCI_Address;
  6159. strcpy(ControllerInfo.ModelName, Controller->ModelName);
  6160. strcpy(ControllerInfo.FirmwareVersion, Controller->FirmwareVersion);
  6161. ErrorCode = (copy_to_user(UserSpaceControllerInfo, &ControllerInfo,
  6162. sizeof(DAC960_ControllerInfo_T)) ? -EFAULT : 0);
  6163. break;
  6164. }
  6165. case DAC960_IOCTL_V1_EXECUTE_COMMAND:
  6166. {
  6167. DAC960_V1_UserCommand_T __user *UserSpaceUserCommand =
  6168. (DAC960_V1_UserCommand_T __user *) Argument;
  6169. DAC960_V1_UserCommand_T UserCommand;
  6170. DAC960_Controller_T *Controller;
  6171. DAC960_Command_T *Command = NULL;
  6172. DAC960_V1_CommandOpcode_T CommandOpcode;
  6173. DAC960_V1_CommandStatus_T CommandStatus;
  6174. DAC960_V1_DCDB_T DCDB;
  6175. DAC960_V1_DCDB_T *DCDB_IOBUF = NULL;
  6176. dma_addr_t DCDB_IOBUFDMA;
  6177. unsigned long flags;
  6178. int ControllerNumber, DataTransferLength;
  6179. unsigned char *DataTransferBuffer = NULL;
  6180. dma_addr_t DataTransferBufferDMA;
  6181. if (UserSpaceUserCommand == NULL) {
  6182. ErrorCode = -EINVAL;
  6183. break;
  6184. }
  6185. if (copy_from_user(&UserCommand, UserSpaceUserCommand,
  6186. sizeof(DAC960_V1_UserCommand_T))) {
  6187. ErrorCode = -EFAULT;
  6188. break;
  6189. }
  6190. ControllerNumber = UserCommand.ControllerNumber;
  6191. ErrorCode = -ENXIO;
  6192. if (ControllerNumber < 0 ||
  6193. ControllerNumber > DAC960_ControllerCount - 1)
  6194. break;
  6195. Controller = DAC960_Controllers[ControllerNumber];
  6196. if (Controller == NULL)
  6197. break;
  6198. ErrorCode = -EINVAL;
  6199. if (Controller->FirmwareType != DAC960_V1_Controller)
  6200. break;
  6201. CommandOpcode = UserCommand.CommandMailbox.Common.CommandOpcode;
  6202. DataTransferLength = UserCommand.DataTransferLength;
  6203. if (CommandOpcode & 0x80)
  6204. break;
  6205. if (CommandOpcode == DAC960_V1_DCDB)
  6206. {
  6207. if (copy_from_user(&DCDB, UserCommand.DCDB,
  6208. sizeof(DAC960_V1_DCDB_T))) {
  6209. ErrorCode = -EFAULT;
  6210. break;
  6211. }
  6212. if (DCDB.Channel >= DAC960_V1_MaxChannels)
  6213. break;
  6214. if (!((DataTransferLength == 0 &&
  6215. DCDB.Direction
  6216. == DAC960_V1_DCDB_NoDataTransfer) ||
  6217. (DataTransferLength > 0 &&
  6218. DCDB.Direction
  6219. == DAC960_V1_DCDB_DataTransferDeviceToSystem) ||
  6220. (DataTransferLength < 0 &&
  6221. DCDB.Direction
  6222. == DAC960_V1_DCDB_DataTransferSystemToDevice)))
  6223. break;
  6224. if (((DCDB.TransferLengthHigh4 << 16) | DCDB.TransferLength)
  6225. != abs(DataTransferLength))
  6226. break;
  6227. DCDB_IOBUF = pci_alloc_consistent(Controller->PCIDevice,
  6228. sizeof(DAC960_V1_DCDB_T), &DCDB_IOBUFDMA);
  6229. if (DCDB_IOBUF == NULL) {
  6230. ErrorCode = -ENOMEM;
  6231. break;
  6232. }
  6233. }
  6234. ErrorCode = -ENOMEM;
  6235. if (DataTransferLength > 0)
  6236. {
  6237. DataTransferBuffer = pci_alloc_consistent(Controller->PCIDevice,
  6238. DataTransferLength, &DataTransferBufferDMA);
  6239. if (DataTransferBuffer == NULL)
  6240. break;
  6241. memset(DataTransferBuffer, 0, DataTransferLength);
  6242. }
  6243. else if (DataTransferLength < 0)
  6244. {
  6245. DataTransferBuffer = pci_alloc_consistent(Controller->PCIDevice,
  6246. -DataTransferLength, &DataTransferBufferDMA);
  6247. if (DataTransferBuffer == NULL)
  6248. break;
  6249. if (copy_from_user(DataTransferBuffer,
  6250. UserCommand.DataTransferBuffer,
  6251. -DataTransferLength)) {
  6252. ErrorCode = -EFAULT;
  6253. break;
  6254. }
  6255. }
  6256. if (CommandOpcode == DAC960_V1_DCDB)
  6257. {
  6258. spin_lock_irqsave(&Controller->queue_lock, flags);
  6259. while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
  6260. DAC960_WaitForCommand(Controller);
  6261. while (Controller->V1.DirectCommandActive[DCDB.Channel]
  6262. [DCDB.TargetID])
  6263. {
  6264. spin_unlock_irq(&Controller->queue_lock);
  6265. __wait_event(Controller->CommandWaitQueue,
  6266. !Controller->V1.DirectCommandActive
  6267. [DCDB.Channel][DCDB.TargetID]);
  6268. spin_lock_irq(&Controller->queue_lock);
  6269. }
  6270. Controller->V1.DirectCommandActive[DCDB.Channel]
  6271. [DCDB.TargetID] = true;
  6272. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  6273. DAC960_V1_ClearCommand(Command);
  6274. Command->CommandType = DAC960_ImmediateCommand;
  6275. memcpy(&Command->V1.CommandMailbox, &UserCommand.CommandMailbox,
  6276. sizeof(DAC960_V1_CommandMailbox_T));
  6277. Command->V1.CommandMailbox.Type3.BusAddress = DCDB_IOBUFDMA;
  6278. DCDB.BusAddress = DataTransferBufferDMA;
  6279. memcpy(DCDB_IOBUF, &DCDB, sizeof(DAC960_V1_DCDB_T));
  6280. }
  6281. else
  6282. {
  6283. spin_lock_irqsave(&Controller->queue_lock, flags);
  6284. while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
  6285. DAC960_WaitForCommand(Controller);
  6286. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  6287. DAC960_V1_ClearCommand(Command);
  6288. Command->CommandType = DAC960_ImmediateCommand;
  6289. memcpy(&Command->V1.CommandMailbox, &UserCommand.CommandMailbox,
  6290. sizeof(DAC960_V1_CommandMailbox_T));
  6291. if (DataTransferBuffer != NULL)
  6292. Command->V1.CommandMailbox.Type3.BusAddress =
  6293. DataTransferBufferDMA;
  6294. }
  6295. DAC960_ExecuteCommand(Command);
  6296. CommandStatus = Command->V1.CommandStatus;
  6297. spin_lock_irqsave(&Controller->queue_lock, flags);
  6298. DAC960_DeallocateCommand(Command);
  6299. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  6300. if (DataTransferLength > 0)
  6301. {
  6302. if (copy_to_user(UserCommand.DataTransferBuffer,
  6303. DataTransferBuffer, DataTransferLength)) {
  6304. ErrorCode = -EFAULT;
  6305. goto Failure1;
  6306. }
  6307. }
  6308. if (CommandOpcode == DAC960_V1_DCDB)
  6309. {
  6310. /*
  6311. I don't believe Target or Channel in the DCDB_IOBUF
  6312. should be any different from the contents of DCDB.
  6313. */
  6314. Controller->V1.DirectCommandActive[DCDB.Channel]
  6315. [DCDB.TargetID] = false;
  6316. if (copy_to_user(UserCommand.DCDB, DCDB_IOBUF,
  6317. sizeof(DAC960_V1_DCDB_T))) {
  6318. ErrorCode = -EFAULT;
  6319. goto Failure1;
  6320. }
  6321. }
  6322. ErrorCode = CommandStatus;
  6323. Failure1:
  6324. if (DataTransferBuffer != NULL)
  6325. pci_free_consistent(Controller->PCIDevice, abs(DataTransferLength),
  6326. DataTransferBuffer, DataTransferBufferDMA);
  6327. if (DCDB_IOBUF != NULL)
  6328. pci_free_consistent(Controller->PCIDevice, sizeof(DAC960_V1_DCDB_T),
  6329. DCDB_IOBUF, DCDB_IOBUFDMA);
  6330. break;
  6331. }
  6332. case DAC960_IOCTL_V2_EXECUTE_COMMAND:
  6333. {
  6334. DAC960_V2_UserCommand_T __user *UserSpaceUserCommand =
  6335. (DAC960_V2_UserCommand_T __user *) Argument;
  6336. DAC960_V2_UserCommand_T UserCommand;
  6337. DAC960_Controller_T *Controller;
  6338. DAC960_Command_T *Command = NULL;
  6339. DAC960_V2_CommandMailbox_T *CommandMailbox;
  6340. DAC960_V2_CommandStatus_T CommandStatus;
  6341. unsigned long flags;
  6342. int ControllerNumber, DataTransferLength;
  6343. int DataTransferResidue, RequestSenseLength;
  6344. unsigned char *DataTransferBuffer = NULL;
  6345. dma_addr_t DataTransferBufferDMA;
  6346. unsigned char *RequestSenseBuffer = NULL;
  6347. dma_addr_t RequestSenseBufferDMA;
  6348. ErrorCode = -EINVAL;
  6349. if (UserSpaceUserCommand == NULL)
  6350. break;
  6351. if (copy_from_user(&UserCommand, UserSpaceUserCommand,
  6352. sizeof(DAC960_V2_UserCommand_T))) {
  6353. ErrorCode = -EFAULT;
  6354. break;
  6355. }
  6356. ErrorCode = -ENXIO;
  6357. ControllerNumber = UserCommand.ControllerNumber;
  6358. if (ControllerNumber < 0 ||
  6359. ControllerNumber > DAC960_ControllerCount - 1)
  6360. break;
  6361. Controller = DAC960_Controllers[ControllerNumber];
  6362. if (Controller == NULL)
  6363. break;
  6364. if (Controller->FirmwareType != DAC960_V2_Controller){
  6365. ErrorCode = -EINVAL;
  6366. break;
  6367. }
  6368. DataTransferLength = UserCommand.DataTransferLength;
  6369. ErrorCode = -ENOMEM;
  6370. if (DataTransferLength > 0)
  6371. {
  6372. DataTransferBuffer = pci_alloc_consistent(Controller->PCIDevice,
  6373. DataTransferLength, &DataTransferBufferDMA);
  6374. if (DataTransferBuffer == NULL)
  6375. break;
  6376. memset(DataTransferBuffer, 0, DataTransferLength);
  6377. }
  6378. else if (DataTransferLength < 0)
  6379. {
  6380. DataTransferBuffer = pci_alloc_consistent(Controller->PCIDevice,
  6381. -DataTransferLength, &DataTransferBufferDMA);
  6382. if (DataTransferBuffer == NULL)
  6383. break;
  6384. if (copy_from_user(DataTransferBuffer,
  6385. UserCommand.DataTransferBuffer,
  6386. -DataTransferLength)) {
  6387. ErrorCode = -EFAULT;
  6388. goto Failure2;
  6389. }
  6390. }
  6391. RequestSenseLength = UserCommand.RequestSenseLength;
  6392. if (RequestSenseLength > 0)
  6393. {
  6394. RequestSenseBuffer = pci_alloc_consistent(Controller->PCIDevice,
  6395. RequestSenseLength, &RequestSenseBufferDMA);
  6396. if (RequestSenseBuffer == NULL)
  6397. {
  6398. ErrorCode = -ENOMEM;
  6399. goto Failure2;
  6400. }
  6401. memset(RequestSenseBuffer, 0, RequestSenseLength);
  6402. }
  6403. spin_lock_irqsave(&Controller->queue_lock, flags);
  6404. while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
  6405. DAC960_WaitForCommand(Controller);
  6406. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  6407. DAC960_V2_ClearCommand(Command);
  6408. Command->CommandType = DAC960_ImmediateCommand;
  6409. CommandMailbox = &Command->V2.CommandMailbox;
  6410. memcpy(CommandMailbox, &UserCommand.CommandMailbox,
  6411. sizeof(DAC960_V2_CommandMailbox_T));
  6412. CommandMailbox->Common.CommandControlBits
  6413. .AdditionalScatterGatherListMemory = false;
  6414. CommandMailbox->Common.CommandControlBits
  6415. .NoAutoRequestSense = true;
  6416. CommandMailbox->Common.DataTransferSize = 0;
  6417. CommandMailbox->Common.DataTransferPageNumber = 0;
  6418. memset(&CommandMailbox->Common.DataTransferMemoryAddress, 0,
  6419. sizeof(DAC960_V2_DataTransferMemoryAddress_T));
  6420. if (DataTransferLength != 0)
  6421. {
  6422. if (DataTransferLength > 0)
  6423. {
  6424. CommandMailbox->Common.CommandControlBits
  6425. .DataTransferControllerToHost = true;
  6426. CommandMailbox->Common.DataTransferSize = DataTransferLength;
  6427. }
  6428. else
  6429. {
  6430. CommandMailbox->Common.CommandControlBits
  6431. .DataTransferControllerToHost = false;
  6432. CommandMailbox->Common.DataTransferSize = -DataTransferLength;
  6433. }
  6434. CommandMailbox->Common.DataTransferMemoryAddress
  6435. .ScatterGatherSegments[0]
  6436. .SegmentDataPointer = DataTransferBufferDMA;
  6437. CommandMailbox->Common.DataTransferMemoryAddress
  6438. .ScatterGatherSegments[0]
  6439. .SegmentByteCount =
  6440. CommandMailbox->Common.DataTransferSize;
  6441. }
  6442. if (RequestSenseLength > 0)
  6443. {
  6444. CommandMailbox->Common.CommandControlBits
  6445. .NoAutoRequestSense = false;
  6446. CommandMailbox->Common.RequestSenseSize = RequestSenseLength;
  6447. CommandMailbox->Common.RequestSenseBusAddress =
  6448. RequestSenseBufferDMA;
  6449. }
  6450. DAC960_ExecuteCommand(Command);
  6451. CommandStatus = Command->V2.CommandStatus;
  6452. RequestSenseLength = Command->V2.RequestSenseLength;
  6453. DataTransferResidue = Command->V2.DataTransferResidue;
  6454. spin_lock_irqsave(&Controller->queue_lock, flags);
  6455. DAC960_DeallocateCommand(Command);
  6456. spin_unlock_irqrestore(&Controller->queue_lock, flags);
  6457. if (RequestSenseLength > UserCommand.RequestSenseLength)
  6458. RequestSenseLength = UserCommand.RequestSenseLength;
  6459. if (copy_to_user(&UserSpaceUserCommand->DataTransferLength,
  6460. &DataTransferResidue,
  6461. sizeof(DataTransferResidue))) {
  6462. ErrorCode = -EFAULT;
  6463. goto Failure2;
  6464. }
  6465. if (copy_to_user(&UserSpaceUserCommand->RequestSenseLength,
  6466. &RequestSenseLength, sizeof(RequestSenseLength))) {
  6467. ErrorCode = -EFAULT;
  6468. goto Failure2;
  6469. }
  6470. if (DataTransferLength > 0)
  6471. {
  6472. if (copy_to_user(UserCommand.DataTransferBuffer,
  6473. DataTransferBuffer, DataTransferLength)) {
  6474. ErrorCode = -EFAULT;
  6475. goto Failure2;
  6476. }
  6477. }
  6478. if (RequestSenseLength > 0)
  6479. {
  6480. if (copy_to_user(UserCommand.RequestSenseBuffer,
  6481. RequestSenseBuffer, RequestSenseLength)) {
  6482. ErrorCode = -EFAULT;
  6483. goto Failure2;
  6484. }
  6485. }
  6486. ErrorCode = CommandStatus;
  6487. Failure2:
  6488. pci_free_consistent(Controller->PCIDevice, abs(DataTransferLength),
  6489. DataTransferBuffer, DataTransferBufferDMA);
  6490. if (RequestSenseBuffer != NULL)
  6491. pci_free_consistent(Controller->PCIDevice, RequestSenseLength,
  6492. RequestSenseBuffer, RequestSenseBufferDMA);
  6493. break;
  6494. }
  6495. case DAC960_IOCTL_V2_GET_HEALTH_STATUS:
  6496. {
  6497. DAC960_V2_GetHealthStatus_T __user *UserSpaceGetHealthStatus =
  6498. (DAC960_V2_GetHealthStatus_T __user *) Argument;
  6499. DAC960_V2_GetHealthStatus_T GetHealthStatus;
  6500. DAC960_V2_HealthStatusBuffer_T HealthStatusBuffer;
  6501. DAC960_Controller_T *Controller;
  6502. int ControllerNumber;
  6503. if (UserSpaceGetHealthStatus == NULL) {
  6504. ErrorCode = -EINVAL;
  6505. break;
  6506. }
  6507. if (copy_from_user(&GetHealthStatus, UserSpaceGetHealthStatus,
  6508. sizeof(DAC960_V2_GetHealthStatus_T))) {
  6509. ErrorCode = -EFAULT;
  6510. break;
  6511. }
  6512. ErrorCode = -ENXIO;
  6513. ControllerNumber = GetHealthStatus.ControllerNumber;
  6514. if (ControllerNumber < 0 ||
  6515. ControllerNumber > DAC960_ControllerCount - 1)
  6516. break;
  6517. Controller = DAC960_Controllers[ControllerNumber];
  6518. if (Controller == NULL)
  6519. break;
  6520. if (Controller->FirmwareType != DAC960_V2_Controller) {
  6521. ErrorCode = -EINVAL;
  6522. break;
  6523. }
  6524. if (copy_from_user(&HealthStatusBuffer,
  6525. GetHealthStatus.HealthStatusBuffer,
  6526. sizeof(DAC960_V2_HealthStatusBuffer_T))) {
  6527. ErrorCode = -EFAULT;
  6528. break;
  6529. }
  6530. while (Controller->V2.HealthStatusBuffer->StatusChangeCounter
  6531. == HealthStatusBuffer.StatusChangeCounter &&
  6532. Controller->V2.HealthStatusBuffer->NextEventSequenceNumber
  6533. == HealthStatusBuffer.NextEventSequenceNumber)
  6534. {
  6535. interruptible_sleep_on_timeout(&Controller->HealthStatusWaitQueue,
  6536. DAC960_MonitoringTimerInterval);
  6537. if (signal_pending(current)) {
  6538. ErrorCode = -EINTR;
  6539. break;
  6540. }
  6541. }
  6542. if (copy_to_user(GetHealthStatus.HealthStatusBuffer,
  6543. Controller->V2.HealthStatusBuffer,
  6544. sizeof(DAC960_V2_HealthStatusBuffer_T)))
  6545. ErrorCode = -EFAULT;
  6546. else
  6547. ErrorCode = 0;
  6548. }
  6549. default:
  6550. ErrorCode = -ENOTTY;
  6551. }
  6552. unlock_kernel();
  6553. return ErrorCode;
  6554. }
  6555. static const struct file_operations DAC960_gam_fops = {
  6556. .owner = THIS_MODULE,
  6557. .unlocked_ioctl = DAC960_gam_ioctl
  6558. };
  6559. static struct miscdevice DAC960_gam_dev = {
  6560. DAC960_GAM_MINOR,
  6561. "dac960_gam",
  6562. &DAC960_gam_fops
  6563. };
  6564. static int DAC960_gam_init(void)
  6565. {
  6566. int ret;
  6567. ret = misc_register(&DAC960_gam_dev);
  6568. if (ret)
  6569. printk(KERN_ERR "DAC960_gam: can't misc_register on minor %d\n", DAC960_GAM_MINOR);
  6570. return ret;
  6571. }
  6572. static void DAC960_gam_cleanup(void)
  6573. {
  6574. misc_deregister(&DAC960_gam_dev);
  6575. }
  6576. #endif /* DAC960_GAM_MINOR */
  6577. static struct DAC960_privdata DAC960_GEM_privdata = {
  6578. .HardwareType = DAC960_GEM_Controller,
  6579. .FirmwareType = DAC960_V2_Controller,
  6580. .InterruptHandler = DAC960_GEM_InterruptHandler,
  6581. .MemoryWindowSize = DAC960_GEM_RegisterWindowSize,
  6582. };
  6583. static struct DAC960_privdata DAC960_BA_privdata = {
  6584. .HardwareType = DAC960_BA_Controller,
  6585. .FirmwareType = DAC960_V2_Controller,
  6586. .InterruptHandler = DAC960_BA_InterruptHandler,
  6587. .MemoryWindowSize = DAC960_BA_RegisterWindowSize,
  6588. };
  6589. static struct DAC960_privdata DAC960_LP_privdata = {
  6590. .HardwareType = DAC960_LP_Controller,
  6591. .FirmwareType = DAC960_LP_Controller,
  6592. .InterruptHandler = DAC960_LP_InterruptHandler,
  6593. .MemoryWindowSize = DAC960_LP_RegisterWindowSize,
  6594. };
  6595. static struct DAC960_privdata DAC960_LA_privdata = {
  6596. .HardwareType = DAC960_LA_Controller,
  6597. .FirmwareType = DAC960_V1_Controller,
  6598. .InterruptHandler = DAC960_LA_InterruptHandler,
  6599. .MemoryWindowSize = DAC960_LA_RegisterWindowSize,
  6600. };
  6601. static struct DAC960_privdata DAC960_PG_privdata = {
  6602. .HardwareType = DAC960_PG_Controller,
  6603. .FirmwareType = DAC960_V1_Controller,
  6604. .InterruptHandler = DAC960_PG_InterruptHandler,
  6605. .MemoryWindowSize = DAC960_PG_RegisterWindowSize,
  6606. };
  6607. static struct DAC960_privdata DAC960_PD_privdata = {
  6608. .HardwareType = DAC960_PD_Controller,
  6609. .FirmwareType = DAC960_V1_Controller,
  6610. .InterruptHandler = DAC960_PD_InterruptHandler,
  6611. .MemoryWindowSize = DAC960_PD_RegisterWindowSize,
  6612. };
  6613. static struct DAC960_privdata DAC960_P_privdata = {
  6614. .HardwareType = DAC960_P_Controller,
  6615. .FirmwareType = DAC960_V1_Controller,
  6616. .InterruptHandler = DAC960_P_InterruptHandler,
  6617. .MemoryWindowSize = DAC960_PD_RegisterWindowSize,
  6618. };
  6619. static struct pci_device_id DAC960_id_table[] = {
  6620. {
  6621. .vendor = PCI_VENDOR_ID_MYLEX,
  6622. .device = PCI_DEVICE_ID_MYLEX_DAC960_GEM,
  6623. .subvendor = PCI_VENDOR_ID_MYLEX,
  6624. .subdevice = PCI_ANY_ID,
  6625. .driver_data = (unsigned long) &DAC960_GEM_privdata,
  6626. },
  6627. {
  6628. .vendor = PCI_VENDOR_ID_MYLEX,
  6629. .device = PCI_DEVICE_ID_MYLEX_DAC960_BA,
  6630. .subvendor = PCI_ANY_ID,
  6631. .subdevice = PCI_ANY_ID,
  6632. .driver_data = (unsigned long) &DAC960_BA_privdata,
  6633. },
  6634. {
  6635. .vendor = PCI_VENDOR_ID_MYLEX,
  6636. .device = PCI_DEVICE_ID_MYLEX_DAC960_LP,
  6637. .subvendor = PCI_ANY_ID,
  6638. .subdevice = PCI_ANY_ID,
  6639. .driver_data = (unsigned long) &DAC960_LP_privdata,
  6640. },
  6641. {
  6642. .vendor = PCI_VENDOR_ID_DEC,
  6643. .device = PCI_DEVICE_ID_DEC_21285,
  6644. .subvendor = PCI_VENDOR_ID_MYLEX,
  6645. .subdevice = PCI_DEVICE_ID_MYLEX_DAC960_LA,
  6646. .driver_data = (unsigned long) &DAC960_LA_privdata,
  6647. },
  6648. {
  6649. .vendor = PCI_VENDOR_ID_MYLEX,
  6650. .device = PCI_DEVICE_ID_MYLEX_DAC960_PG,
  6651. .subvendor = PCI_ANY_ID,
  6652. .subdevice = PCI_ANY_ID,
  6653. .driver_data = (unsigned long) &DAC960_PG_privdata,
  6654. },
  6655. {
  6656. .vendor = PCI_VENDOR_ID_MYLEX,
  6657. .device = PCI_DEVICE_ID_MYLEX_DAC960_PD,
  6658. .subvendor = PCI_ANY_ID,
  6659. .subdevice = PCI_ANY_ID,
  6660. .driver_data = (unsigned long) &DAC960_PD_privdata,
  6661. },
  6662. {
  6663. .vendor = PCI_VENDOR_ID_MYLEX,
  6664. .device = PCI_DEVICE_ID_MYLEX_DAC960_P,
  6665. .subvendor = PCI_ANY_ID,
  6666. .subdevice = PCI_ANY_ID,
  6667. .driver_data = (unsigned long) &DAC960_P_privdata,
  6668. },
  6669. {0, },
  6670. };
  6671. MODULE_DEVICE_TABLE(pci, DAC960_id_table);
  6672. static struct pci_driver DAC960_pci_driver = {
  6673. .name = "DAC960",
  6674. .id_table = DAC960_id_table,
  6675. .probe = DAC960_Probe,
  6676. .remove = DAC960_Remove,
  6677. };
  6678. static int __init DAC960_init_module(void)
  6679. {
  6680. int ret;
  6681. ret = pci_register_driver(&DAC960_pci_driver);
  6682. #ifdef DAC960_GAM_MINOR
  6683. if (!ret)
  6684. DAC960_gam_init();
  6685. #endif
  6686. return ret;
  6687. }
  6688. static void __exit DAC960_cleanup_module(void)
  6689. {
  6690. int i;
  6691. #ifdef DAC960_GAM_MINOR
  6692. DAC960_gam_cleanup();
  6693. #endif
  6694. for (i = 0; i < DAC960_ControllerCount; i++) {
  6695. DAC960_Controller_T *Controller = DAC960_Controllers[i];
  6696. if (Controller == NULL)
  6697. continue;
  6698. DAC960_FinalizeController(Controller);
  6699. }
  6700. if (DAC960_ProcDirectoryEntry != NULL) {
  6701. remove_proc_entry("rd/status", NULL);
  6702. remove_proc_entry("rd", NULL);
  6703. }
  6704. DAC960_ControllerCount = 0;
  6705. pci_unregister_driver(&DAC960_pci_driver);
  6706. }
  6707. module_init(DAC960_init_module);
  6708. module_exit(DAC960_cleanup_module);
  6709. MODULE_LICENSE("GPL");