DAC960.c 259 KB

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