DAC960.c 260 KB

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