DAC960.c 260 KB

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