DAC960.c 260 KB

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