DAC960.c 259 KB

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