DAC960.c 260 KB

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