gdth.c 201 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677
  1. /************************************************************************
  2. * Linux driver for *
  3. * ICP vortex GmbH: GDT ISA/EISA/PCI Disk Array Controllers *
  4. * Intel Corporation: Storage RAID Controllers *
  5. * *
  6. * gdth.c *
  7. * Copyright (C) 1995-06 ICP vortex GmbH, Achim Leubner *
  8. * Copyright (C) 2002-04 Intel Corporation *
  9. * Copyright (C) 2003-06 Adaptec Inc. *
  10. * <achim_leubner@adaptec.com> *
  11. * *
  12. * Additions/Fixes: *
  13. * Boji Tony Kannanthanam <boji.t.kannanthanam@intel.com> *
  14. * Johannes Dinner <johannes_dinner@adaptec.com> *
  15. * *
  16. * This program is free software; you can redistribute it and/or modify *
  17. * it under the terms of the GNU General Public License as published *
  18. * by the Free Software Foundation; either version 2 of the License, *
  19. * or (at your option) any later version. *
  20. * *
  21. * This program is distributed in the hope that it will be useful, *
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  24. * GNU General Public License for more details. *
  25. * *
  26. * You should have received a copy of the GNU General Public License *
  27. * along with this kernel; if not, write to the Free Software *
  28. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
  29. * *
  30. * Linux kernel 2.4.x, 2.6.x supported *
  31. * *
  32. * $Log: gdth.c,v $
  33. * Revision 1.74 2006/04/10 13:44:47 achim
  34. * Community changes for 2.6.x
  35. * Kernel 2.2.x no longer supported
  36. * scsi_request interface removed, thanks to Christoph Hellwig
  37. *
  38. * Revision 1.73 2004/03/31 13:33:03 achim
  39. * Special command 0xfd implemented to detect 64-bit DMA support
  40. *
  41. * Revision 1.72 2004/03/17 08:56:04 achim
  42. * 64-bit DMA only enabled if FW >= x.43
  43. *
  44. * Revision 1.71 2004/03/05 15:51:29 achim
  45. * Screen service: separate message buffer, bugfixes
  46. *
  47. * Revision 1.70 2004/02/27 12:19:07 achim
  48. * Bugfix: Reset bit in config (0xfe) call removed
  49. *
  50. * Revision 1.69 2004/02/20 09:50:24 achim
  51. * Compatibility changes for kernels < 2.4.20
  52. * Bugfix screen service command size
  53. * pci_set_dma_mask() error handling added
  54. *
  55. * Revision 1.68 2004/02/19 15:46:54 achim
  56. * 64-bit DMA bugfixes
  57. * Drive size bugfix for drives > 1TB
  58. *
  59. * Revision 1.67 2004/01/14 13:11:57 achim
  60. * Tool access over /proc no longer supported
  61. * Bugfixes IOCTLs
  62. *
  63. * Revision 1.66 2003/12/19 15:04:06 achim
  64. * Bugfixes support for drives > 2TB
  65. *
  66. * Revision 1.65 2003/12/15 11:21:56 achim
  67. * 64-bit DMA support added
  68. * Support for drives > 2 TB implemented
  69. * Kernels 2.2.x, 2.4.x, 2.6.x supported
  70. *
  71. * Revision 1.64 2003/09/17 08:30:26 achim
  72. * EISA/ISA controller scan disabled
  73. * Command line switch probe_eisa_isa added
  74. *
  75. * Revision 1.63 2003/07/12 14:01:00 Daniele Bellucci <bellucda@tiscali.it>
  76. * Minor cleanups in gdth_ioctl.
  77. *
  78. * Revision 1.62 2003/02/27 15:01:59 achim
  79. * Dynamic DMA mapping implemented
  80. * New (character device) IOCTL interface added
  81. * Other controller related changes made
  82. *
  83. * Revision 1.61 2002/11/08 13:09:52 boji
  84. * Added support for XSCALE based RAID Controllers
  85. * Fixed SCREENSERVICE initialization in SMP cases
  86. * Added checks for gdth_polling before GDTH_HA_LOCK
  87. *
  88. * Revision 1.60 2002/02/05 09:35:22 achim
  89. * MODULE_LICENSE only if kernel >= 2.4.11
  90. *
  91. * Revision 1.59 2002/01/30 09:46:33 achim
  92. * Small changes
  93. *
  94. * Revision 1.58 2002/01/29 15:30:02 achim
  95. * Set default value of shared_access to Y
  96. * New status S_CACHE_RESERV for clustering added
  97. *
  98. * Revision 1.57 2001/08/21 11:16:35 achim
  99. * Bugfix free_irq()
  100. *
  101. * Revision 1.56 2001/08/09 11:19:39 achim
  102. * Scsi_Host_Template changes
  103. *
  104. * Revision 1.55 2001/08/09 10:11:28 achim
  105. * Command HOST_UNFREEZE_IO before cache service init.
  106. *
  107. * Revision 1.54 2001/07/20 13:48:12 achim
  108. * Expand: gdth_analyse_hdrive() removed
  109. *
  110. * Revision 1.53 2001/07/17 09:52:49 achim
  111. * Small OEM related change
  112. *
  113. * Revision 1.52 2001/06/19 15:06:20 achim
  114. * New host command GDT_UNFREEZE_IO added
  115. *
  116. * Revision 1.51 2001/05/22 06:42:37 achim
  117. * PCI: Subdevice ID added
  118. *
  119. * Revision 1.50 2001/05/17 13:42:16 achim
  120. * Support for Intel Storage RAID Controllers added
  121. *
  122. * Revision 1.50 2001/05/17 12:12:34 achim
  123. * Support for Intel Storage RAID Controllers added
  124. *
  125. * Revision 1.49 2001/03/15 15:07:17 achim
  126. * New __setup interface for boot command line options added
  127. *
  128. * Revision 1.48 2001/02/06 12:36:28 achim
  129. * Bugfix Cluster protocol
  130. *
  131. * Revision 1.47 2001/01/10 14:42:06 achim
  132. * New switch shared_access added
  133. *
  134. * Revision 1.46 2001/01/09 08:11:35 achim
  135. * gdth_command() removed
  136. * meaning of Scsi_Pointer members changed
  137. *
  138. * Revision 1.45 2000/11/16 12:02:24 achim
  139. * Changes for kernel 2.4
  140. *
  141. * Revision 1.44 2000/10/11 08:44:10 achim
  142. * Clustering changes: New flag media_changed added
  143. *
  144. * Revision 1.43 2000/09/20 12:59:01 achim
  145. * DPMEM remap functions for all PCI controller types implemented
  146. * Small changes for ia64 platform
  147. *
  148. * Revision 1.42 2000/07/20 09:04:50 achim
  149. * Small changes for kernel 2.4
  150. *
  151. * Revision 1.41 2000/07/04 14:11:11 achim
  152. * gdth_analyse_hdrive() added to rescan drives after online expansion
  153. *
  154. * Revision 1.40 2000/06/27 11:24:16 achim
  155. * Changes Clustering, Screenservice
  156. *
  157. * Revision 1.39 2000/06/15 13:09:04 achim
  158. * Changes for gdth_do_cmd()
  159. *
  160. * Revision 1.38 2000/06/15 12:08:43 achim
  161. * Bugfix gdth_sync_event(), service SCREENSERVICE
  162. * Data direction for command 0xc2 changed to DOU
  163. *
  164. * Revision 1.37 2000/05/25 13:50:10 achim
  165. * New driver parameter virt_ctr added
  166. *
  167. * Revision 1.36 2000/05/04 08:50:46 achim
  168. * Event buffer now in gdth_ha_str
  169. *
  170. * Revision 1.35 2000/03/03 10:44:08 achim
  171. * New event_string only valid for the RP controller family
  172. *
  173. * Revision 1.34 2000/03/02 14:55:29 achim
  174. * New mechanism for async. event handling implemented
  175. *
  176. * Revision 1.33 2000/02/21 15:37:37 achim
  177. * Bugfix Alpha platform + DPMEM above 4GB
  178. *
  179. * Revision 1.32 2000/02/14 16:17:37 achim
  180. * Bugfix sense_buffer[] + raw devices
  181. *
  182. * Revision 1.31 2000/02/10 10:29:00 achim
  183. * Delete sense_buffer[0], if command OK
  184. *
  185. * Revision 1.30 1999/11/02 13:42:39 achim
  186. * ARRAY_DRV_LIST2 implemented
  187. * Now 255 log. and 100 host drives supported
  188. *
  189. * Revision 1.29 1999/10/05 13:28:47 achim
  190. * GDT_CLUST_RESET added
  191. *
  192. * Revision 1.28 1999/08/12 13:44:54 achim
  193. * MOUNTALL removed
  194. * Cluster drives -> removeable drives
  195. *
  196. * Revision 1.27 1999/06/22 07:22:38 achim
  197. * Small changes
  198. *
  199. * Revision 1.26 1999/06/10 16:09:12 achim
  200. * Cluster Host Drive support: Bugfixes
  201. *
  202. * Revision 1.25 1999/06/01 16:03:56 achim
  203. * gdth_init_pci(): Manipulate config. space to start RP controller
  204. *
  205. * Revision 1.24 1999/05/26 11:53:06 achim
  206. * Cluster Host Drive support added
  207. *
  208. * Revision 1.23 1999/03/26 09:12:31 achim
  209. * Default value for hdr_channel set to 0
  210. *
  211. * Revision 1.22 1999/03/22 16:27:16 achim
  212. * Bugfix: gdth_store_event() must not be locked with GDTH_LOCK_HA()
  213. *
  214. * Revision 1.21 1999/03/16 13:40:34 achim
  215. * Problems with reserved drives solved
  216. * gdth_eh_bus_reset() implemented
  217. *
  218. * Revision 1.20 1999/03/10 09:08:13 achim
  219. * Bugfix: Corrections in gdth_direction_tab[] made
  220. * Bugfix: Increase command timeout (gdth_update_timeout()) NOT in gdth_putq()
  221. *
  222. * Revision 1.19 1999/03/05 14:38:16 achim
  223. * Bugfix: Heads/Sectors mapping for reserved devices possibly wrong
  224. * -> gdth_eval_mapping() implemented, changes in gdth_bios_param()
  225. * INIT_RETRIES set to 100s to avoid DEINIT-Timeout for controllers
  226. * with BIOS disabled and memory test set to Intensive
  227. * Enhanced /proc support
  228. *
  229. * Revision 1.18 1999/02/24 09:54:33 achim
  230. * Command line parameter hdr_channel implemented
  231. * Bugfix for EISA controllers + Linux 2.2.x
  232. *
  233. * Revision 1.17 1998/12/17 15:58:11 achim
  234. * Command line parameters implemented
  235. * Changes for Alpha platforms
  236. * PCI controller scan changed
  237. * SMP support improved (spin_lock_irqsave(),...)
  238. * New async. events, new scan/reserve commands included
  239. *
  240. * Revision 1.16 1998/09/28 16:08:46 achim
  241. * GDT_PCIMPR: DPMEM remapping, if required
  242. * mdelay() added
  243. *
  244. * Revision 1.15 1998/06/03 14:54:06 achim
  245. * gdth_delay(), gdth_flush() implemented
  246. * Bugfix: gdth_release() changed
  247. *
  248. * Revision 1.14 1998/05/22 10:01:17 achim
  249. * mj: pcibios_strerror() removed
  250. * Improved SMP support (if version >= 2.1.95)
  251. * gdth_halt(): halt_called flag added (if version < 2.1)
  252. *
  253. * Revision 1.13 1998/04/16 09:14:57 achim
  254. * Reserve drives (for raw service) implemented
  255. * New error handling code enabled
  256. * Get controller name from board_info() IOCTL
  257. * Final round of PCI device driver patches by Martin Mares
  258. *
  259. * Revision 1.12 1998/03/03 09:32:37 achim
  260. * Fibre channel controller support added
  261. *
  262. * Revision 1.11 1998/01/27 16:19:14 achim
  263. * SA_SHIRQ added
  264. * add_timer()/del_timer() instead of GDTH_TIMER
  265. * scsi_add_timer()/scsi_del_timer() instead of SCSI_TIMER
  266. * New error handling included
  267. *
  268. * Revision 1.10 1997/10/31 12:29:57 achim
  269. * Read heads/sectors from host drive
  270. *
  271. * Revision 1.9 1997/09/04 10:07:25 achim
  272. * IO-mapping with virt_to_bus(), gdth_readb(), gdth_writeb(), ...
  273. * register_reboot_notifier() to get a notify on shutown used
  274. *
  275. * Revision 1.8 1997/04/02 12:14:30 achim
  276. * Version 1.00 (see gdth.h), tested with kernel 2.0.29
  277. *
  278. * Revision 1.7 1997/03/12 13:33:37 achim
  279. * gdth_reset() changed, new async. events
  280. *
  281. * Revision 1.6 1997/03/04 14:01:11 achim
  282. * Shutdown routine gdth_halt() implemented
  283. *
  284. * Revision 1.5 1997/02/21 09:08:36 achim
  285. * New controller included (RP, RP1, RP2 series)
  286. * IOCTL interface implemented
  287. *
  288. * Revision 1.4 1996/07/05 12:48:55 achim
  289. * Function gdth_bios_param() implemented
  290. * New constant GDTH_MAXC_P_L inserted
  291. * GDT_WRITE_THR, GDT_EXT_INFO implemented
  292. * Function gdth_reset() changed
  293. *
  294. * Revision 1.3 1996/05/10 09:04:41 achim
  295. * Small changes for Linux 1.2.13
  296. *
  297. * Revision 1.2 1996/05/09 12:45:27 achim
  298. * Loadable module support implemented
  299. * /proc support corrections made
  300. *
  301. * Revision 1.1 1996/04/11 07:35:57 achim
  302. * Initial revision
  303. *
  304. ************************************************************************/
  305. /* All GDT Disk Array Controllers are fully supported by this driver.
  306. * This includes the PCI/EISA/ISA SCSI Disk Array Controllers and the
  307. * PCI Fibre Channel Disk Array Controllers. See gdth.h for a complete
  308. * list of all controller types.
  309. *
  310. * If you have one or more GDT3000/3020 EISA controllers with
  311. * controller BIOS disabled, you have to set the IRQ values with the
  312. * command line option "gdth=irq1,irq2,...", where the irq1,irq2,... are
  313. * the IRQ values for the EISA controllers.
  314. *
  315. * After the optional list of IRQ values, other possible
  316. * command line options are:
  317. * disable:Y disable driver
  318. * disable:N enable driver
  319. * reserve_mode:0 reserve no drives for the raw service
  320. * reserve_mode:1 reserve all not init., removable drives
  321. * reserve_mode:2 reserve all not init. drives
  322. * reserve_list:h,b,t,l,h,b,t,l,... reserve particular drive(s) with
  323. * h- controller no., b- channel no.,
  324. * t- target ID, l- LUN
  325. * reverse_scan:Y reverse scan order for PCI controllers
  326. * reverse_scan:N scan PCI controllers like BIOS
  327. * max_ids:x x - target ID count per channel (1..MAXID)
  328. * rescan:Y rescan all channels/IDs
  329. * rescan:N use all devices found until now
  330. * virt_ctr:Y map every channel to a virtual controller
  331. * virt_ctr:N use multi channel support
  332. * hdr_channel:x x - number of virtual bus for host drives
  333. * shared_access:Y disable driver reserve/release protocol to
  334. * access a shared resource from several nodes,
  335. * appropriate controller firmware required
  336. * shared_access:N enable driver reserve/release protocol
  337. * probe_eisa_isa:Y scan for EISA/ISA controllers
  338. * probe_eisa_isa:N do not scan for EISA/ISA controllers
  339. * force_dma32:Y use only 32 bit DMA mode
  340. * force_dma32:N use 64 bit DMA mode, if supported
  341. *
  342. * The default values are: "gdth=disable:N,reserve_mode:1,reverse_scan:N,
  343. * max_ids:127,rescan:N,virt_ctr:N,hdr_channel:0,
  344. * shared_access:Y,probe_eisa_isa:N,force_dma32:N".
  345. * Here is another example: "gdth=reserve_list:0,1,2,0,0,1,3,0,rescan:Y".
  346. *
  347. * When loading the gdth driver as a module, the same options are available.
  348. * You can set the IRQs with "IRQ=...". However, the syntax to specify the
  349. * options changes slightly. You must replace all ',' between options
  350. * with ' ' and all ':' with '=' and you must use
  351. * '1' in place of 'Y' and '0' in place of 'N'.
  352. *
  353. * Default: "modprobe gdth disable=0 reserve_mode=1 reverse_scan=0
  354. * max_ids=127 rescan=0 virt_ctr=0 hdr_channel=0 shared_access=0
  355. * probe_eisa_isa=0 force_dma32=0"
  356. * The other example: "modprobe gdth reserve_list=0,1,2,0,0,1,3,0 rescan=1".
  357. */
  358. /* The meaning of the Scsi_Pointer members in this driver is as follows:
  359. * ptr: Chaining
  360. * this_residual: Command priority
  361. * buffer: phys. DMA sense buffer
  362. * dma_handle: phys. DMA buffer (kernel >= 2.4.0)
  363. * buffers_residual: Timeout value
  364. * Status: Command status (gdth_do_cmd()), DMA mem. mappings
  365. * Message: Additional info (gdth_do_cmd()), DMA direction
  366. * have_data_in: Flag for gdth_wait_completion()
  367. * sent_command: Opcode special command
  368. * phase: Service/parameter/return code special command
  369. */
  370. /* interrupt coalescing */
  371. /* #define INT_COAL */
  372. /* statistics */
  373. #define GDTH_STATISTICS
  374. #include <linux/module.h>
  375. #include <linux/version.h>
  376. #include <linux/kernel.h>
  377. #include <linux/types.h>
  378. #include <linux/pci.h>
  379. #include <linux/string.h>
  380. #include <linux/ctype.h>
  381. #include <linux/ioport.h>
  382. #include <linux/delay.h>
  383. #include <linux/interrupt.h>
  384. #include <linux/in.h>
  385. #include <linux/proc_fs.h>
  386. #include <linux/time.h>
  387. #include <linux/timer.h>
  388. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,6)
  389. #include <linux/dma-mapping.h>
  390. #else
  391. #define DMA_32BIT_MASK 0x00000000ffffffffULL
  392. #define DMA_64BIT_MASK 0xffffffffffffffffULL
  393. #endif
  394. #ifdef GDTH_RTC
  395. #include <linux/mc146818rtc.h>
  396. #endif
  397. #include <linux/reboot.h>
  398. #include <asm/dma.h>
  399. #include <asm/system.h>
  400. #include <asm/io.h>
  401. #include <asm/uaccess.h>
  402. #include <linux/spinlock.h>
  403. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  404. #include <linux/blkdev.h>
  405. #else
  406. #include <linux/blk.h>
  407. #include "sd.h"
  408. #endif
  409. #include "scsi.h"
  410. #include <scsi/scsi_host.h>
  411. #include "gdth_kcompat.h"
  412. #include "gdth.h"
  413. static void gdth_delay(int milliseconds);
  414. static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs);
  415. static irqreturn_t gdth_interrupt(int irq, void *dev_id);
  416. static int gdth_sync_event(int hanum,int service,unchar index,Scsi_Cmnd *scp);
  417. static int gdth_async_event(int hanum);
  418. static void gdth_log_event(gdth_evt_data *dvr, char *buffer);
  419. static void gdth_putq(int hanum,Scsi_Cmnd *scp,unchar priority);
  420. static void gdth_next(int hanum);
  421. static int gdth_fill_raw_cmd(int hanum,Scsi_Cmnd *scp,unchar b);
  422. static int gdth_special_cmd(int hanum,Scsi_Cmnd *scp);
  423. static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source,
  424. ushort idx, gdth_evt_data *evt);
  425. static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr);
  426. static void gdth_readapp_event(gdth_ha_str *ha, unchar application,
  427. gdth_evt_str *estr);
  428. static void gdth_clear_events(void);
  429. static void gdth_copy_internal_data(int hanum,Scsi_Cmnd *scp,
  430. char *buffer,ushort count);
  431. static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp);
  432. static int gdth_fill_cache_cmd(int hanum,Scsi_Cmnd *scp,ushort hdrive);
  433. static int gdth_search_eisa(ushort eisa_adr);
  434. static int gdth_search_isa(ulong32 bios_adr);
  435. static int gdth_search_pci(gdth_pci_str *pcistr);
  436. static void gdth_search_dev(gdth_pci_str *pcistr, ushort *cnt,
  437. ushort vendor, ushort dev);
  438. static void gdth_sort_pci(gdth_pci_str *pcistr, int cnt);
  439. static int gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha);
  440. static int gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha);
  441. static int gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha);
  442. static void gdth_enable_int(int hanum);
  443. static int gdth_get_status(unchar *pIStatus,int irq);
  444. static int gdth_test_busy(int hanum);
  445. static int gdth_get_cmd_index(int hanum);
  446. static void gdth_release_event(int hanum);
  447. static int gdth_wait(int hanum,int index,ulong32 time);
  448. static int gdth_internal_cmd(int hanum,unchar service,ushort opcode,ulong32 p1,
  449. ulong64 p2,ulong64 p3);
  450. static int gdth_search_drives(int hanum);
  451. static int gdth_analyse_hdrive(int hanum, ushort hdrive);
  452. static const char *gdth_ctr_name(int hanum);
  453. static int gdth_open(struct inode *inode, struct file *filep);
  454. static int gdth_close(struct inode *inode, struct file *filep);
  455. static int gdth_ioctl(struct inode *inode, struct file *filep,
  456. unsigned int cmd, unsigned long arg);
  457. static void gdth_flush(int hanum);
  458. static int gdth_halt(struct notifier_block *nb, ulong event, void *buf);
  459. static int gdth_queuecommand(Scsi_Cmnd *scp,void (*done)(Scsi_Cmnd *));
  460. static void gdth_scsi_done(struct scsi_cmnd *scp);
  461. #ifdef DEBUG_GDTH
  462. static unchar DebugState = DEBUG_GDTH;
  463. #ifdef __SERIAL__
  464. #define MAX_SERBUF 160
  465. static void ser_init(void);
  466. static void ser_puts(char *str);
  467. static void ser_putc(char c);
  468. static int ser_printk(const char *fmt, ...);
  469. static char strbuf[MAX_SERBUF+1];
  470. #ifdef __COM2__
  471. #define COM_BASE 0x2f8
  472. #else
  473. #define COM_BASE 0x3f8
  474. #endif
  475. static void ser_init()
  476. {
  477. unsigned port=COM_BASE;
  478. outb(0x80,port+3);
  479. outb(0,port+1);
  480. /* 19200 Baud, if 9600: outb(12,port) */
  481. outb(6, port);
  482. outb(3,port+3);
  483. outb(0,port+1);
  484. /*
  485. ser_putc('I');
  486. ser_putc(' ');
  487. */
  488. }
  489. static void ser_puts(char *str)
  490. {
  491. char *ptr;
  492. ser_init();
  493. for (ptr=str;*ptr;++ptr)
  494. ser_putc(*ptr);
  495. }
  496. static void ser_putc(char c)
  497. {
  498. unsigned port=COM_BASE;
  499. while ((inb(port+5) & 0x20)==0);
  500. outb(c,port);
  501. if (c==0x0a)
  502. {
  503. while ((inb(port+5) & 0x20)==0);
  504. outb(0x0d,port);
  505. }
  506. }
  507. static int ser_printk(const char *fmt, ...)
  508. {
  509. va_list args;
  510. int i;
  511. va_start(args,fmt);
  512. i = vsprintf(strbuf,fmt,args);
  513. ser_puts(strbuf);
  514. va_end(args);
  515. return i;
  516. }
  517. #define TRACE(a) {if (DebugState==1) {ser_printk a;}}
  518. #define TRACE2(a) {if (DebugState==1 || DebugState==2) {ser_printk a;}}
  519. #define TRACE3(a) {if (DebugState!=0) {ser_printk a;}}
  520. #else /* !__SERIAL__ */
  521. #define TRACE(a) {if (DebugState==1) {printk a;}}
  522. #define TRACE2(a) {if (DebugState==1 || DebugState==2) {printk a;}}
  523. #define TRACE3(a) {if (DebugState!=0) {printk a;}}
  524. #endif
  525. #else /* !DEBUG */
  526. #define TRACE(a)
  527. #define TRACE2(a)
  528. #define TRACE3(a)
  529. #endif
  530. #ifdef GDTH_STATISTICS
  531. static ulong32 max_rq=0, max_index=0, max_sg=0;
  532. #ifdef INT_COAL
  533. static ulong32 max_int_coal=0;
  534. #endif
  535. static ulong32 act_ints=0, act_ios=0, act_stats=0, act_rq=0;
  536. static struct timer_list gdth_timer;
  537. #endif
  538. #define PTR2USHORT(a) (ushort)(ulong)(a)
  539. #define GDTOFFSOF(a,b) (size_t)&(((a*)0)->b)
  540. #define INDEX_OK(i,t) ((i)<ARRAY_SIZE(t))
  541. #define NUMDATA(a) ( (gdth_num_str *)((a)->hostdata))
  542. #define HADATA(a) (&((gdth_ext_str *)((a)->hostdata))->haext)
  543. #define CMDDATA(a) (&((gdth_ext_str *)((a)->hostdata))->cmdext)
  544. #define BUS_L2P(a,b) ((b)>(a)->virt_bus ? (b-1):(b))
  545. #define gdth_readb(addr) readb(addr)
  546. #define gdth_readw(addr) readw(addr)
  547. #define gdth_readl(addr) readl(addr)
  548. #define gdth_writeb(b,addr) writeb((b),(addr))
  549. #define gdth_writew(b,addr) writew((b),(addr))
  550. #define gdth_writel(b,addr) writel((b),(addr))
  551. static unchar gdth_drq_tab[4] = {5,6,7,7}; /* DRQ table */
  552. static unchar gdth_irq_tab[6] = {0,10,11,12,14,0}; /* IRQ table */
  553. static unchar gdth_polling; /* polling if TRUE */
  554. static unchar gdth_from_wait = FALSE; /* gdth_wait() */
  555. static int wait_index,wait_hanum; /* gdth_wait() */
  556. static int gdth_ctr_count = 0; /* controller count */
  557. static int gdth_ctr_vcount = 0; /* virt. ctr. count */
  558. static int gdth_ctr_released = 0; /* gdth_release() */
  559. static struct Scsi_Host *gdth_ctr_tab[MAXHA]; /* controller table */
  560. static struct Scsi_Host *gdth_ctr_vtab[MAXHA*MAXBUS]; /* virt. ctr. table */
  561. static unchar gdth_write_through = FALSE; /* write through */
  562. static gdth_evt_str ebuffer[MAX_EVENTS]; /* event buffer */
  563. static int elastidx;
  564. static int eoldidx;
  565. static int major;
  566. #define DIN 1 /* IN data direction */
  567. #define DOU 2 /* OUT data direction */
  568. #define DNO DIN /* no data transfer */
  569. #define DUN DIN /* unknown data direction */
  570. static unchar gdth_direction_tab[0x100] = {
  571. DNO,DNO,DIN,DIN,DOU,DIN,DIN,DOU,DIN,DUN,DOU,DOU,DUN,DUN,DUN,DIN,
  572. DNO,DIN,DIN,DOU,DIN,DOU,DNO,DNO,DOU,DNO,DIN,DNO,DIN,DOU,DNO,DUN,
  573. DIN,DUN,DIN,DUN,DOU,DIN,DUN,DUN,DIN,DIN,DOU,DNO,DUN,DIN,DOU,DOU,
  574. DOU,DOU,DOU,DNO,DIN,DNO,DNO,DIN,DOU,DOU,DOU,DOU,DIN,DOU,DIN,DOU,
  575. DOU,DOU,DIN,DIN,DIN,DNO,DUN,DNO,DNO,DNO,DUN,DNO,DOU,DIN,DUN,DUN,
  576. DUN,DUN,DUN,DUN,DUN,DOU,DUN,DUN,DUN,DUN,DIN,DUN,DUN,DUN,DUN,DUN,
  577. DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
  578. DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
  579. DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DIN,DUN,DOU,DUN,DUN,DUN,DUN,DUN,
  580. DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DIN,DUN,
  581. DUN,DUN,DUN,DUN,DUN,DNO,DNO,DUN,DIN,DNO,DOU,DUN,DNO,DUN,DOU,DOU,
  582. DOU,DOU,DOU,DNO,DUN,DIN,DOU,DIN,DIN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
  583. DUN,DUN,DOU,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
  584. DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,
  585. DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DOU,DUN,DUN,DUN,DUN,DUN,
  586. DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN
  587. };
  588. /* LILO and modprobe/insmod parameters */
  589. /* IRQ list for GDT3000/3020 EISA controllers */
  590. static int irq[MAXHA] __initdata =
  591. {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  592. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
  593. /* disable driver flag */
  594. static int disable __initdata = 0;
  595. /* reserve flag */
  596. static int reserve_mode = 1;
  597. /* reserve list */
  598. static int reserve_list[MAX_RES_ARGS] =
  599. {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  600. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  601. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
  602. /* scan order for PCI controllers */
  603. static int reverse_scan = 0;
  604. /* virtual channel for the host drives */
  605. static int hdr_channel = 0;
  606. /* max. IDs per channel */
  607. static int max_ids = MAXID;
  608. /* rescan all IDs */
  609. static int rescan = 0;
  610. /* map channels to virtual controllers */
  611. static int virt_ctr = 0;
  612. /* shared access */
  613. static int shared_access = 1;
  614. /* enable support for EISA and ISA controllers */
  615. static int probe_eisa_isa = 0;
  616. /* 64 bit DMA mode, support for drives > 2 TB, if force_dma32 = 0 */
  617. static int force_dma32 = 0;
  618. /* parameters for modprobe/insmod */
  619. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
  620. module_param_array(irq, int, NULL, 0);
  621. module_param(disable, int, 0);
  622. module_param(reserve_mode, int, 0);
  623. module_param_array(reserve_list, int, NULL, 0);
  624. module_param(reverse_scan, int, 0);
  625. module_param(hdr_channel, int, 0);
  626. module_param(max_ids, int, 0);
  627. module_param(rescan, int, 0);
  628. module_param(virt_ctr, int, 0);
  629. module_param(shared_access, int, 0);
  630. module_param(probe_eisa_isa, int, 0);
  631. module_param(force_dma32, int, 0);
  632. #else
  633. MODULE_PARM(irq, "i");
  634. MODULE_PARM(disable, "i");
  635. MODULE_PARM(reserve_mode, "i");
  636. MODULE_PARM(reserve_list, "4-" __MODULE_STRING(MAX_RES_ARGS) "i");
  637. MODULE_PARM(reverse_scan, "i");
  638. MODULE_PARM(hdr_channel, "i");
  639. MODULE_PARM(max_ids, "i");
  640. MODULE_PARM(rescan, "i");
  641. MODULE_PARM(virt_ctr, "i");
  642. MODULE_PARM(shared_access, "i");
  643. MODULE_PARM(probe_eisa_isa, "i");
  644. MODULE_PARM(force_dma32, "i");
  645. #endif
  646. MODULE_AUTHOR("Achim Leubner");
  647. MODULE_LICENSE("GPL");
  648. /* ioctl interface */
  649. static const struct file_operations gdth_fops = {
  650. .ioctl = gdth_ioctl,
  651. .open = gdth_open,
  652. .release = gdth_close,
  653. };
  654. #define GDTH_MAGIC 0xc2e7c389 /* I got it from /dev/urandom */
  655. #define IS_GDTH_INTERNAL_CMD(scp) (scp->underflow == GDTH_MAGIC)
  656. #include "gdth_proc.h"
  657. #include "gdth_proc.c"
  658. /* notifier block to get a notify on system shutdown/halt/reboot */
  659. static struct notifier_block gdth_notifier = {
  660. gdth_halt, NULL, 0
  661. };
  662. static int notifier_disabled = 0;
  663. static void gdth_delay(int milliseconds)
  664. {
  665. if (milliseconds == 0) {
  666. udelay(1);
  667. } else {
  668. mdelay(milliseconds);
  669. }
  670. }
  671. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  672. static void gdth_scsi_done(struct scsi_cmnd *scp)
  673. {
  674. TRACE2(("gdth_scsi_done()\n"));
  675. if (IS_GDTH_INTERNAL_CMD(scp))
  676. complete((struct completion *)scp->request);
  677. }
  678. int __gdth_execute(struct scsi_device *sdev, gdth_cmd_str *gdtcmd, char *cmnd,
  679. int timeout, u32 *info)
  680. {
  681. Scsi_Cmnd *scp;
  682. DECLARE_COMPLETION_ONSTACK(wait);
  683. int rval;
  684. scp = kzalloc(sizeof(*scp), GFP_KERNEL);
  685. if (!scp)
  686. return -ENOMEM;
  687. scp->device = sdev;
  688. /* use request field to save the ptr. to completion struct. */
  689. scp->request = (struct request *)&wait;
  690. scp->timeout_per_command = timeout*HZ;
  691. scp->request_buffer = gdtcmd;
  692. scp->cmd_len = 12;
  693. memcpy(scp->cmnd, cmnd, 12);
  694. scp->SCp.this_residual = IOCTL_PRI; /* priority */
  695. scp->underflow = GDTH_MAGIC;
  696. gdth_queuecommand(scp, gdth_scsi_done);
  697. wait_for_completion(&wait);
  698. rval = scp->SCp.Status;
  699. if (info)
  700. *info = scp->SCp.Message;
  701. kfree(scp);
  702. return rval;
  703. }
  704. #else
  705. static void gdth_scsi_done(Scsi_Cmnd *scp)
  706. {
  707. TRACE2(("gdth_scsi_done()\n"));
  708. scp->request.rq_status = RQ_SCSI_DONE;
  709. if (scp->request.waiting)
  710. complete(scp->request.waiting);
  711. }
  712. int __gdth_execute(struct scsi_device *sdev, gdth_cmd_str *gdtcmd, char *cmnd,
  713. int timeout, u32 *info)
  714. {
  715. Scsi_Cmnd *scp = scsi_allocate_device(sdev, 1, FALSE);
  716. unsigned bufflen = gdtcmd ? sizeof(gdth_cmd_str) : 0;
  717. DECLARE_COMPLETION_ONSTACK(wait);
  718. int rval;
  719. if (!scp)
  720. return -ENOMEM;
  721. scp->cmd_len = 12;
  722. scp->use_sg = 0;
  723. scp->SCp.this_residual = IOCTL_PRI; /* priority */
  724. scp->request.rq_status = RQ_SCSI_BUSY;
  725. scp->request.waiting = &wait;
  726. scsi_do_cmd(scp, cmnd, gdtcmd, bufflen, gdth_scsi_done, timeout*HZ, 1);
  727. wait_for_completion(&wait);
  728. rval = scp->SCp.Status;
  729. if (info)
  730. *info = scp->SCp.Message;
  731. scsi_release_command(scp);
  732. return rval;
  733. }
  734. #endif
  735. int gdth_execute(struct Scsi_Host *shost, gdth_cmd_str *gdtcmd, char *cmnd,
  736. int timeout, u32 *info)
  737. {
  738. struct scsi_device *sdev = scsi_get_host_dev(shost);
  739. int rval = __gdth_execute(sdev, gdtcmd, cmnd, timeout, info);
  740. scsi_free_host_dev(sdev);
  741. return rval;
  742. }
  743. static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs)
  744. {
  745. *cyls = size /HEADS/SECS;
  746. if (*cyls <= MAXCYLS) {
  747. *heads = HEADS;
  748. *secs = SECS;
  749. } else { /* too high for 64*32 */
  750. *cyls = size /MEDHEADS/MEDSECS;
  751. if (*cyls <= MAXCYLS) {
  752. *heads = MEDHEADS;
  753. *secs = MEDSECS;
  754. } else { /* too high for 127*63 */
  755. *cyls = size /BIGHEADS/BIGSECS;
  756. *heads = BIGHEADS;
  757. *secs = BIGSECS;
  758. }
  759. }
  760. }
  761. /* controller search and initialization functions */
  762. static int __init gdth_search_eisa(ushort eisa_adr)
  763. {
  764. ulong32 id;
  765. TRACE(("gdth_search_eisa() adr. %x\n",eisa_adr));
  766. id = inl(eisa_adr+ID0REG);
  767. if (id == GDT3A_ID || id == GDT3B_ID) { /* GDT3000A or GDT3000B */
  768. if ((inb(eisa_adr+EISAREG) & 8) == 0)
  769. return 0; /* not EISA configured */
  770. return 1;
  771. }
  772. if (id == GDT3_ID) /* GDT3000 */
  773. return 1;
  774. return 0;
  775. }
  776. static int __init gdth_search_isa(ulong32 bios_adr)
  777. {
  778. void __iomem *addr;
  779. ulong32 id;
  780. TRACE(("gdth_search_isa() bios adr. %x\n",bios_adr));
  781. if ((addr = ioremap(bios_adr+BIOS_ID_OFFS, sizeof(ulong32))) != NULL) {
  782. id = gdth_readl(addr);
  783. iounmap(addr);
  784. if (id == GDT2_ID) /* GDT2000 */
  785. return 1;
  786. }
  787. return 0;
  788. }
  789. static int __init gdth_search_pci(gdth_pci_str *pcistr)
  790. {
  791. ushort device, cnt;
  792. TRACE(("gdth_search_pci()\n"));
  793. cnt = 0;
  794. for (device = 0; device <= PCI_DEVICE_ID_VORTEX_GDT6555; ++device)
  795. gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX, device);
  796. for (device = PCI_DEVICE_ID_VORTEX_GDT6x17RP;
  797. device <= PCI_DEVICE_ID_VORTEX_GDTMAXRP; ++device)
  798. gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX, device);
  799. gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX,
  800. PCI_DEVICE_ID_VORTEX_GDTNEWRX);
  801. gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_VORTEX,
  802. PCI_DEVICE_ID_VORTEX_GDTNEWRX2);
  803. gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_INTEL,
  804. PCI_DEVICE_ID_INTEL_SRC);
  805. gdth_search_dev(pcistr, &cnt, PCI_VENDOR_ID_INTEL,
  806. PCI_DEVICE_ID_INTEL_SRC_XSCALE);
  807. return cnt;
  808. }
  809. /* Vortex only makes RAID controllers.
  810. * We do not really want to specify all 550 ids here, so wildcard match.
  811. */
  812. static struct pci_device_id gdthtable[] __maybe_unused = {
  813. {PCI_VENDOR_ID_VORTEX,PCI_ANY_ID,PCI_ANY_ID, PCI_ANY_ID},
  814. {PCI_VENDOR_ID_INTEL,PCI_DEVICE_ID_INTEL_SRC,PCI_ANY_ID,PCI_ANY_ID},
  815. {PCI_VENDOR_ID_INTEL,PCI_DEVICE_ID_INTEL_SRC_XSCALE,PCI_ANY_ID,PCI_ANY_ID},
  816. {0}
  817. };
  818. MODULE_DEVICE_TABLE(pci,gdthtable);
  819. static void __init gdth_search_dev(gdth_pci_str *pcistr, ushort *cnt,
  820. ushort vendor, ushort device)
  821. {
  822. ulong base0, base1, base2;
  823. struct pci_dev *pdev;
  824. TRACE(("gdth_search_dev() cnt %d vendor %x device %x\n",
  825. *cnt, vendor, device));
  826. pdev = NULL;
  827. while ((pdev = pci_find_device(vendor, device, pdev))
  828. != NULL) {
  829. if (pci_enable_device(pdev))
  830. continue;
  831. if (*cnt >= MAXHA)
  832. return;
  833. /* GDT PCI controller found, resources are already in pdev */
  834. pcistr[*cnt].pdev = pdev;
  835. pcistr[*cnt].irq = pdev->irq;
  836. base0 = pci_resource_flags(pdev, 0);
  837. base1 = pci_resource_flags(pdev, 1);
  838. base2 = pci_resource_flags(pdev, 2);
  839. if (device <= PCI_DEVICE_ID_VORTEX_GDT6000B || /* GDT6000/B */
  840. device >= PCI_DEVICE_ID_VORTEX_GDT6x17RP) { /* MPR */
  841. if (!(base0 & IORESOURCE_MEM))
  842. continue;
  843. pcistr[*cnt].dpmem = pci_resource_start(pdev, 0);
  844. } else { /* GDT6110, GDT6120, .. */
  845. if (!(base0 & IORESOURCE_MEM) ||
  846. !(base2 & IORESOURCE_MEM) ||
  847. !(base1 & IORESOURCE_IO))
  848. continue;
  849. pcistr[*cnt].dpmem = pci_resource_start(pdev, 2);
  850. pcistr[*cnt].io_mm = pci_resource_start(pdev, 0);
  851. pcistr[*cnt].io = pci_resource_start(pdev, 1);
  852. }
  853. TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%lx\n",
  854. pcistr[*cnt].pdev->bus->number,
  855. PCI_SLOT(pcistr[*cnt].pdev->devfn),
  856. pcistr[*cnt].irq, pcistr[*cnt].dpmem));
  857. (*cnt)++;
  858. }
  859. }
  860. static void __init gdth_sort_pci(gdth_pci_str *pcistr, int cnt)
  861. {
  862. gdth_pci_str temp;
  863. int i, changed;
  864. TRACE(("gdth_sort_pci() cnt %d\n",cnt));
  865. if (cnt == 0)
  866. return;
  867. do {
  868. changed = FALSE;
  869. for (i = 0; i < cnt-1; ++i) {
  870. if (!reverse_scan) {
  871. if ((pcistr[i].pdev->bus->number > pcistr[i+1].pdev->bus->number) ||
  872. (pcistr[i].pdev->bus->number == pcistr[i+1].pdev->bus->number &&
  873. PCI_SLOT(pcistr[i].pdev->devfn) >
  874. PCI_SLOT(pcistr[i+1].pdev->devfn))) {
  875. temp = pcistr[i];
  876. pcistr[i] = pcistr[i+1];
  877. pcistr[i+1] = temp;
  878. changed = TRUE;
  879. }
  880. } else {
  881. if ((pcistr[i].pdev->bus->number < pcistr[i+1].pdev->bus->number) ||
  882. (pcistr[i].pdev->bus->number == pcistr[i+1].pdev->bus->number &&
  883. PCI_SLOT(pcistr[i].pdev->devfn) <
  884. PCI_SLOT(pcistr[i+1].pdev->devfn))) {
  885. temp = pcistr[i];
  886. pcistr[i] = pcistr[i+1];
  887. pcistr[i+1] = temp;
  888. changed = TRUE;
  889. }
  890. }
  891. }
  892. } while (changed);
  893. }
  894. static int __init gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha)
  895. {
  896. ulong32 retries,id;
  897. unchar prot_ver,eisacf,i,irq_found;
  898. TRACE(("gdth_init_eisa() adr. %x\n",eisa_adr));
  899. /* disable board interrupts, deinitialize services */
  900. outb(0xff,eisa_adr+EDOORREG);
  901. outb(0x00,eisa_adr+EDENABREG);
  902. outb(0x00,eisa_adr+EINTENABREG);
  903. outb(0xff,eisa_adr+LDOORREG);
  904. retries = INIT_RETRIES;
  905. gdth_delay(20);
  906. while (inb(eisa_adr+EDOORREG) != 0xff) {
  907. if (--retries == 0) {
  908. printk("GDT-EISA: Initialization error (DEINIT failed)\n");
  909. return 0;
  910. }
  911. gdth_delay(1);
  912. TRACE2(("wait for DEINIT: retries=%d\n",retries));
  913. }
  914. prot_ver = inb(eisa_adr+MAILBOXREG);
  915. outb(0xff,eisa_adr+EDOORREG);
  916. if (prot_ver != PROTOCOL_VERSION) {
  917. printk("GDT-EISA: Illegal protocol version\n");
  918. return 0;
  919. }
  920. ha->bmic = eisa_adr;
  921. ha->brd_phys = (ulong32)eisa_adr >> 12;
  922. outl(0,eisa_adr+MAILBOXREG);
  923. outl(0,eisa_adr+MAILBOXREG+4);
  924. outl(0,eisa_adr+MAILBOXREG+8);
  925. outl(0,eisa_adr+MAILBOXREG+12);
  926. /* detect IRQ */
  927. if ((id = inl(eisa_adr+ID0REG)) == GDT3_ID) {
  928. ha->oem_id = OEM_ID_ICP;
  929. ha->type = GDT_EISA;
  930. ha->stype = id;
  931. outl(1,eisa_adr+MAILBOXREG+8);
  932. outb(0xfe,eisa_adr+LDOORREG);
  933. retries = INIT_RETRIES;
  934. gdth_delay(20);
  935. while (inb(eisa_adr+EDOORREG) != 0xfe) {
  936. if (--retries == 0) {
  937. printk("GDT-EISA: Initialization error (get IRQ failed)\n");
  938. return 0;
  939. }
  940. gdth_delay(1);
  941. }
  942. ha->irq = inb(eisa_adr+MAILBOXREG);
  943. outb(0xff,eisa_adr+EDOORREG);
  944. TRACE2(("GDT3000/3020: IRQ=%d\n",ha->irq));
  945. /* check the result */
  946. if (ha->irq == 0) {
  947. TRACE2(("Unknown IRQ, use IRQ table from cmd line !\n"));
  948. for (i = 0, irq_found = FALSE;
  949. i < MAXHA && irq[i] != 0xff; ++i) {
  950. if (irq[i]==10 || irq[i]==11 || irq[i]==12 || irq[i]==14) {
  951. irq_found = TRUE;
  952. break;
  953. }
  954. }
  955. if (irq_found) {
  956. ha->irq = irq[i];
  957. irq[i] = 0;
  958. printk("GDT-EISA: Can not detect controller IRQ,\n");
  959. printk("Use IRQ setting from command line (IRQ = %d)\n",
  960. ha->irq);
  961. } else {
  962. printk("GDT-EISA: Initialization error (unknown IRQ), Enable\n");
  963. printk("the controller BIOS or use command line parameters\n");
  964. return 0;
  965. }
  966. }
  967. } else {
  968. eisacf = inb(eisa_adr+EISAREG) & 7;
  969. if (eisacf > 4) /* level triggered */
  970. eisacf -= 4;
  971. ha->irq = gdth_irq_tab[eisacf];
  972. ha->oem_id = OEM_ID_ICP;
  973. ha->type = GDT_EISA;
  974. ha->stype = id;
  975. }
  976. ha->dma64_support = 0;
  977. return 1;
  978. }
  979. static int __init gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha)
  980. {
  981. register gdt2_dpram_str __iomem *dp2_ptr;
  982. int i;
  983. unchar irq_drq,prot_ver;
  984. ulong32 retries;
  985. TRACE(("gdth_init_isa() bios adr. %x\n",bios_adr));
  986. ha->brd = ioremap(bios_adr, sizeof(gdt2_dpram_str));
  987. if (ha->brd == NULL) {
  988. printk("GDT-ISA: Initialization error (DPMEM remap error)\n");
  989. return 0;
  990. }
  991. dp2_ptr = ha->brd;
  992. gdth_writeb(1, &dp2_ptr->io.memlock); /* switch off write protection */
  993. /* reset interface area */
  994. memset_io(&dp2_ptr->u, 0, sizeof(dp2_ptr->u));
  995. if (gdth_readl(&dp2_ptr->u) != 0) {
  996. printk("GDT-ISA: Initialization error (DPMEM write error)\n");
  997. iounmap(ha->brd);
  998. return 0;
  999. }
  1000. /* disable board interrupts, read DRQ and IRQ */
  1001. gdth_writeb(0xff, &dp2_ptr->io.irqdel);
  1002. gdth_writeb(0x00, &dp2_ptr->io.irqen);
  1003. gdth_writeb(0x00, &dp2_ptr->u.ic.S_Status);
  1004. gdth_writeb(0x00, &dp2_ptr->u.ic.Cmd_Index);
  1005. irq_drq = gdth_readb(&dp2_ptr->io.rq);
  1006. for (i=0; i<3; ++i) {
  1007. if ((irq_drq & 1)==0)
  1008. break;
  1009. irq_drq >>= 1;
  1010. }
  1011. ha->drq = gdth_drq_tab[i];
  1012. irq_drq = gdth_readb(&dp2_ptr->io.rq) >> 3;
  1013. for (i=1; i<5; ++i) {
  1014. if ((irq_drq & 1)==0)
  1015. break;
  1016. irq_drq >>= 1;
  1017. }
  1018. ha->irq = gdth_irq_tab[i];
  1019. /* deinitialize services */
  1020. gdth_writel(bios_adr, &dp2_ptr->u.ic.S_Info[0]);
  1021. gdth_writeb(0xff, &dp2_ptr->u.ic.S_Cmd_Indx);
  1022. gdth_writeb(0, &dp2_ptr->io.event);
  1023. retries = INIT_RETRIES;
  1024. gdth_delay(20);
  1025. while (gdth_readb(&dp2_ptr->u.ic.S_Status) != 0xff) {
  1026. if (--retries == 0) {
  1027. printk("GDT-ISA: Initialization error (DEINIT failed)\n");
  1028. iounmap(ha->brd);
  1029. return 0;
  1030. }
  1031. gdth_delay(1);
  1032. }
  1033. prot_ver = (unchar)gdth_readl(&dp2_ptr->u.ic.S_Info[0]);
  1034. gdth_writeb(0, &dp2_ptr->u.ic.Status);
  1035. gdth_writeb(0xff, &dp2_ptr->io.irqdel);
  1036. if (prot_ver != PROTOCOL_VERSION) {
  1037. printk("GDT-ISA: Illegal protocol version\n");
  1038. iounmap(ha->brd);
  1039. return 0;
  1040. }
  1041. ha->oem_id = OEM_ID_ICP;
  1042. ha->type = GDT_ISA;
  1043. ha->ic_all_size = sizeof(dp2_ptr->u);
  1044. ha->stype= GDT2_ID;
  1045. ha->brd_phys = bios_adr >> 4;
  1046. /* special request to controller BIOS */
  1047. gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[0]);
  1048. gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[1]);
  1049. gdth_writel(0x01, &dp2_ptr->u.ic.S_Info[2]);
  1050. gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[3]);
  1051. gdth_writeb(0xfe, &dp2_ptr->u.ic.S_Cmd_Indx);
  1052. gdth_writeb(0, &dp2_ptr->io.event);
  1053. retries = INIT_RETRIES;
  1054. gdth_delay(20);
  1055. while (gdth_readb(&dp2_ptr->u.ic.S_Status) != 0xfe) {
  1056. if (--retries == 0) {
  1057. printk("GDT-ISA: Initialization error\n");
  1058. iounmap(ha->brd);
  1059. return 0;
  1060. }
  1061. gdth_delay(1);
  1062. }
  1063. gdth_writeb(0, &dp2_ptr->u.ic.Status);
  1064. gdth_writeb(0xff, &dp2_ptr->io.irqdel);
  1065. ha->dma64_support = 0;
  1066. return 1;
  1067. }
  1068. static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
  1069. {
  1070. register gdt6_dpram_str __iomem *dp6_ptr;
  1071. register gdt6c_dpram_str __iomem *dp6c_ptr;
  1072. register gdt6m_dpram_str __iomem *dp6m_ptr;
  1073. ulong32 retries;
  1074. unchar prot_ver;
  1075. ushort command;
  1076. int i, found = FALSE;
  1077. TRACE(("gdth_init_pci()\n"));
  1078. if (pcistr->pdev->vendor == PCI_VENDOR_ID_INTEL)
  1079. ha->oem_id = OEM_ID_INTEL;
  1080. else
  1081. ha->oem_id = OEM_ID_ICP;
  1082. ha->brd_phys = (pcistr->pdev->bus->number << 8) | (pcistr->pdev->devfn & 0xf8);
  1083. ha->stype = (ulong32)pcistr->pdev->device;
  1084. ha->irq = pcistr->irq;
  1085. ha->pdev = pcistr->pdev;
  1086. if (ha->pdev->device <= PCI_DEVICE_ID_VORTEX_GDT6000B) { /* GDT6000/B */
  1087. TRACE2(("init_pci() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
  1088. ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6_dpram_str));
  1089. if (ha->brd == NULL) {
  1090. printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
  1091. return 0;
  1092. }
  1093. /* check and reset interface area */
  1094. dp6_ptr = ha->brd;
  1095. gdth_writel(DPMEM_MAGIC, &dp6_ptr->u);
  1096. if (gdth_readl(&dp6_ptr->u) != DPMEM_MAGIC) {
  1097. printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
  1098. pcistr->dpmem);
  1099. found = FALSE;
  1100. for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
  1101. iounmap(ha->brd);
  1102. ha->brd = ioremap(i, sizeof(ushort));
  1103. if (ha->brd == NULL) {
  1104. printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
  1105. return 0;
  1106. }
  1107. if (gdth_readw(ha->brd) != 0xffff) {
  1108. TRACE2(("init_pci_old() address 0x%x busy\n", i));
  1109. continue;
  1110. }
  1111. iounmap(ha->brd);
  1112. pci_write_config_dword(pcistr->pdev,
  1113. PCI_BASE_ADDRESS_0, i);
  1114. ha->brd = ioremap(i, sizeof(gdt6_dpram_str));
  1115. if (ha->brd == NULL) {
  1116. printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
  1117. return 0;
  1118. }
  1119. dp6_ptr = ha->brd;
  1120. gdth_writel(DPMEM_MAGIC, &dp6_ptr->u);
  1121. if (gdth_readl(&dp6_ptr->u) == DPMEM_MAGIC) {
  1122. printk("GDT-PCI: Use free address at 0x%x\n", i);
  1123. found = TRUE;
  1124. break;
  1125. }
  1126. }
  1127. if (!found) {
  1128. printk("GDT-PCI: No free address found!\n");
  1129. iounmap(ha->brd);
  1130. return 0;
  1131. }
  1132. }
  1133. memset_io(&dp6_ptr->u, 0, sizeof(dp6_ptr->u));
  1134. if (gdth_readl(&dp6_ptr->u) != 0) {
  1135. printk("GDT-PCI: Initialization error (DPMEM write error)\n");
  1136. iounmap(ha->brd);
  1137. return 0;
  1138. }
  1139. /* disable board interrupts, deinit services */
  1140. gdth_writeb(0xff, &dp6_ptr->io.irqdel);
  1141. gdth_writeb(0x00, &dp6_ptr->io.irqen);
  1142. gdth_writeb(0x00, &dp6_ptr->u.ic.S_Status);
  1143. gdth_writeb(0x00, &dp6_ptr->u.ic.Cmd_Index);
  1144. gdth_writel(pcistr->dpmem, &dp6_ptr->u.ic.S_Info[0]);
  1145. gdth_writeb(0xff, &dp6_ptr->u.ic.S_Cmd_Indx);
  1146. gdth_writeb(0, &dp6_ptr->io.event);
  1147. retries = INIT_RETRIES;
  1148. gdth_delay(20);
  1149. while (gdth_readb(&dp6_ptr->u.ic.S_Status) != 0xff) {
  1150. if (--retries == 0) {
  1151. printk("GDT-PCI: Initialization error (DEINIT failed)\n");
  1152. iounmap(ha->brd);
  1153. return 0;
  1154. }
  1155. gdth_delay(1);
  1156. }
  1157. prot_ver = (unchar)gdth_readl(&dp6_ptr->u.ic.S_Info[0]);
  1158. gdth_writeb(0, &dp6_ptr->u.ic.S_Status);
  1159. gdth_writeb(0xff, &dp6_ptr->io.irqdel);
  1160. if (prot_ver != PROTOCOL_VERSION) {
  1161. printk("GDT-PCI: Illegal protocol version\n");
  1162. iounmap(ha->brd);
  1163. return 0;
  1164. }
  1165. ha->type = GDT_PCI;
  1166. ha->ic_all_size = sizeof(dp6_ptr->u);
  1167. /* special command to controller BIOS */
  1168. gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[0]);
  1169. gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[1]);
  1170. gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[2]);
  1171. gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[3]);
  1172. gdth_writeb(0xfe, &dp6_ptr->u.ic.S_Cmd_Indx);
  1173. gdth_writeb(0, &dp6_ptr->io.event);
  1174. retries = INIT_RETRIES;
  1175. gdth_delay(20);
  1176. while (gdth_readb(&dp6_ptr->u.ic.S_Status) != 0xfe) {
  1177. if (--retries == 0) {
  1178. printk("GDT-PCI: Initialization error\n");
  1179. iounmap(ha->brd);
  1180. return 0;
  1181. }
  1182. gdth_delay(1);
  1183. }
  1184. gdth_writeb(0, &dp6_ptr->u.ic.S_Status);
  1185. gdth_writeb(0xff, &dp6_ptr->io.irqdel);
  1186. ha->dma64_support = 0;
  1187. } else if (ha->pdev->device <= PCI_DEVICE_ID_VORTEX_GDT6555) { /* GDT6110, ... */
  1188. ha->plx = (gdt6c_plx_regs *)pcistr->io;
  1189. TRACE2(("init_pci_new() dpmem %lx irq %d\n",
  1190. pcistr->dpmem,ha->irq));
  1191. ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6c_dpram_str));
  1192. if (ha->brd == NULL) {
  1193. printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
  1194. iounmap(ha->brd);
  1195. return 0;
  1196. }
  1197. /* check and reset interface area */
  1198. dp6c_ptr = ha->brd;
  1199. gdth_writel(DPMEM_MAGIC, &dp6c_ptr->u);
  1200. if (gdth_readl(&dp6c_ptr->u) != DPMEM_MAGIC) {
  1201. printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
  1202. pcistr->dpmem);
  1203. found = FALSE;
  1204. for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
  1205. iounmap(ha->brd);
  1206. ha->brd = ioremap(i, sizeof(ushort));
  1207. if (ha->brd == NULL) {
  1208. printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
  1209. return 0;
  1210. }
  1211. if (gdth_readw(ha->brd) != 0xffff) {
  1212. TRACE2(("init_pci_plx() address 0x%x busy\n", i));
  1213. continue;
  1214. }
  1215. iounmap(ha->brd);
  1216. pci_write_config_dword(pcistr->pdev,
  1217. PCI_BASE_ADDRESS_2, i);
  1218. ha->brd = ioremap(i, sizeof(gdt6c_dpram_str));
  1219. if (ha->brd == NULL) {
  1220. printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
  1221. return 0;
  1222. }
  1223. dp6c_ptr = ha->brd;
  1224. gdth_writel(DPMEM_MAGIC, &dp6c_ptr->u);
  1225. if (gdth_readl(&dp6c_ptr->u) == DPMEM_MAGIC) {
  1226. printk("GDT-PCI: Use free address at 0x%x\n", i);
  1227. found = TRUE;
  1228. break;
  1229. }
  1230. }
  1231. if (!found) {
  1232. printk("GDT-PCI: No free address found!\n");
  1233. iounmap(ha->brd);
  1234. return 0;
  1235. }
  1236. }
  1237. memset_io(&dp6c_ptr->u, 0, sizeof(dp6c_ptr->u));
  1238. if (gdth_readl(&dp6c_ptr->u) != 0) {
  1239. printk("GDT-PCI: Initialization error (DPMEM write error)\n");
  1240. iounmap(ha->brd);
  1241. return 0;
  1242. }
  1243. /* disable board interrupts, deinit services */
  1244. outb(0x00,PTR2USHORT(&ha->plx->control1));
  1245. outb(0xff,PTR2USHORT(&ha->plx->edoor_reg));
  1246. gdth_writeb(0x00, &dp6c_ptr->u.ic.S_Status);
  1247. gdth_writeb(0x00, &dp6c_ptr->u.ic.Cmd_Index);
  1248. gdth_writel(pcistr->dpmem, &dp6c_ptr->u.ic.S_Info[0]);
  1249. gdth_writeb(0xff, &dp6c_ptr->u.ic.S_Cmd_Indx);
  1250. outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
  1251. retries = INIT_RETRIES;
  1252. gdth_delay(20);
  1253. while (gdth_readb(&dp6c_ptr->u.ic.S_Status) != 0xff) {
  1254. if (--retries == 0) {
  1255. printk("GDT-PCI: Initialization error (DEINIT failed)\n");
  1256. iounmap(ha->brd);
  1257. return 0;
  1258. }
  1259. gdth_delay(1);
  1260. }
  1261. prot_ver = (unchar)gdth_readl(&dp6c_ptr->u.ic.S_Info[0]);
  1262. gdth_writeb(0, &dp6c_ptr->u.ic.Status);
  1263. if (prot_ver != PROTOCOL_VERSION) {
  1264. printk("GDT-PCI: Illegal protocol version\n");
  1265. iounmap(ha->brd);
  1266. return 0;
  1267. }
  1268. ha->type = GDT_PCINEW;
  1269. ha->ic_all_size = sizeof(dp6c_ptr->u);
  1270. /* special command to controller BIOS */
  1271. gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[0]);
  1272. gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[1]);
  1273. gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[2]);
  1274. gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[3]);
  1275. gdth_writeb(0xfe, &dp6c_ptr->u.ic.S_Cmd_Indx);
  1276. outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
  1277. retries = INIT_RETRIES;
  1278. gdth_delay(20);
  1279. while (gdth_readb(&dp6c_ptr->u.ic.S_Status) != 0xfe) {
  1280. if (--retries == 0) {
  1281. printk("GDT-PCI: Initialization error\n");
  1282. iounmap(ha->brd);
  1283. return 0;
  1284. }
  1285. gdth_delay(1);
  1286. }
  1287. gdth_writeb(0, &dp6c_ptr->u.ic.S_Status);
  1288. ha->dma64_support = 0;
  1289. } else { /* MPR */
  1290. TRACE2(("init_pci_mpr() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
  1291. ha->brd = ioremap(pcistr->dpmem, sizeof(gdt6m_dpram_str));
  1292. if (ha->brd == NULL) {
  1293. printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
  1294. return 0;
  1295. }
  1296. /* manipulate config. space to enable DPMEM, start RP controller */
  1297. pci_read_config_word(pcistr->pdev, PCI_COMMAND, &command);
  1298. command |= 6;
  1299. pci_write_config_word(pcistr->pdev, PCI_COMMAND, command);
  1300. if (pci_resource_start(pcistr->pdev, 8) == 1UL)
  1301. pci_resource_start(pcistr->pdev, 8) = 0UL;
  1302. i = 0xFEFF0001UL;
  1303. pci_write_config_dword(pcistr->pdev, PCI_ROM_ADDRESS, i);
  1304. gdth_delay(1);
  1305. pci_write_config_dword(pcistr->pdev, PCI_ROM_ADDRESS,
  1306. pci_resource_start(pcistr->pdev, 8));
  1307. dp6m_ptr = ha->brd;
  1308. /* Ensure that it is safe to access the non HW portions of DPMEM.
  1309. * Aditional check needed for Xscale based RAID controllers */
  1310. while( ((int)gdth_readb(&dp6m_ptr->i960r.sema0_reg) ) & 3 )
  1311. gdth_delay(1);
  1312. /* check and reset interface area */
  1313. gdth_writel(DPMEM_MAGIC, &dp6m_ptr->u);
  1314. if (gdth_readl(&dp6m_ptr->u) != DPMEM_MAGIC) {
  1315. printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n",
  1316. pcistr->dpmem);
  1317. found = FALSE;
  1318. for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
  1319. iounmap(ha->brd);
  1320. ha->brd = ioremap(i, sizeof(ushort));
  1321. if (ha->brd == NULL) {
  1322. printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
  1323. return 0;
  1324. }
  1325. if (gdth_readw(ha->brd) != 0xffff) {
  1326. TRACE2(("init_pci_mpr() address 0x%x busy\n", i));
  1327. continue;
  1328. }
  1329. iounmap(ha->brd);
  1330. pci_write_config_dword(pcistr->pdev,
  1331. PCI_BASE_ADDRESS_0, i);
  1332. ha->brd = ioremap(i, sizeof(gdt6m_dpram_str));
  1333. if (ha->brd == NULL) {
  1334. printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
  1335. return 0;
  1336. }
  1337. dp6m_ptr = ha->brd;
  1338. gdth_writel(DPMEM_MAGIC, &dp6m_ptr->u);
  1339. if (gdth_readl(&dp6m_ptr->u) == DPMEM_MAGIC) {
  1340. printk("GDT-PCI: Use free address at 0x%x\n", i);
  1341. found = TRUE;
  1342. break;
  1343. }
  1344. }
  1345. if (!found) {
  1346. printk("GDT-PCI: No free address found!\n");
  1347. iounmap(ha->brd);
  1348. return 0;
  1349. }
  1350. }
  1351. memset_io(&dp6m_ptr->u, 0, sizeof(dp6m_ptr->u));
  1352. /* disable board interrupts, deinit services */
  1353. gdth_writeb(gdth_readb(&dp6m_ptr->i960r.edoor_en_reg) | 4,
  1354. &dp6m_ptr->i960r.edoor_en_reg);
  1355. gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
  1356. gdth_writeb(0x00, &dp6m_ptr->u.ic.S_Status);
  1357. gdth_writeb(0x00, &dp6m_ptr->u.ic.Cmd_Index);
  1358. gdth_writel(pcistr->dpmem, &dp6m_ptr->u.ic.S_Info[0]);
  1359. gdth_writeb(0xff, &dp6m_ptr->u.ic.S_Cmd_Indx);
  1360. gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
  1361. retries = INIT_RETRIES;
  1362. gdth_delay(20);
  1363. while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xff) {
  1364. if (--retries == 0) {
  1365. printk("GDT-PCI: Initialization error (DEINIT failed)\n");
  1366. iounmap(ha->brd);
  1367. return 0;
  1368. }
  1369. gdth_delay(1);
  1370. }
  1371. prot_ver = (unchar)gdth_readl(&dp6m_ptr->u.ic.S_Info[0]);
  1372. gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
  1373. if (prot_ver != PROTOCOL_VERSION) {
  1374. printk("GDT-PCI: Illegal protocol version\n");
  1375. iounmap(ha->brd);
  1376. return 0;
  1377. }
  1378. ha->type = GDT_PCIMPR;
  1379. ha->ic_all_size = sizeof(dp6m_ptr->u);
  1380. /* special command to controller BIOS */
  1381. gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[0]);
  1382. gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[1]);
  1383. gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[2]);
  1384. gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[3]);
  1385. gdth_writeb(0xfe, &dp6m_ptr->u.ic.S_Cmd_Indx);
  1386. gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
  1387. retries = INIT_RETRIES;
  1388. gdth_delay(20);
  1389. while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xfe) {
  1390. if (--retries == 0) {
  1391. printk("GDT-PCI: Initialization error\n");
  1392. iounmap(ha->brd);
  1393. return 0;
  1394. }
  1395. gdth_delay(1);
  1396. }
  1397. gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
  1398. /* read FW version to detect 64-bit DMA support */
  1399. gdth_writeb(0xfd, &dp6m_ptr->u.ic.S_Cmd_Indx);
  1400. gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
  1401. retries = INIT_RETRIES;
  1402. gdth_delay(20);
  1403. while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xfd) {
  1404. if (--retries == 0) {
  1405. printk("GDT-PCI: Initialization error (DEINIT failed)\n");
  1406. iounmap(ha->brd);
  1407. return 0;
  1408. }
  1409. gdth_delay(1);
  1410. }
  1411. prot_ver = (unchar)(gdth_readl(&dp6m_ptr->u.ic.S_Info[0]) >> 16);
  1412. gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
  1413. if (prot_ver < 0x2b) /* FW < x.43: no 64-bit DMA support */
  1414. ha->dma64_support = 0;
  1415. else
  1416. ha->dma64_support = 1;
  1417. }
  1418. return 1;
  1419. }
  1420. /* controller protocol functions */
  1421. static void __init gdth_enable_int(int hanum)
  1422. {
  1423. gdth_ha_str *ha;
  1424. ulong flags;
  1425. gdt2_dpram_str __iomem *dp2_ptr;
  1426. gdt6_dpram_str __iomem *dp6_ptr;
  1427. gdt6m_dpram_str __iomem *dp6m_ptr;
  1428. TRACE(("gdth_enable_int() hanum %d\n",hanum));
  1429. ha = HADATA(gdth_ctr_tab[hanum]);
  1430. spin_lock_irqsave(&ha->smp_lock, flags);
  1431. if (ha->type == GDT_EISA) {
  1432. outb(0xff, ha->bmic + EDOORREG);
  1433. outb(0xff, ha->bmic + EDENABREG);
  1434. outb(0x01, ha->bmic + EINTENABREG);
  1435. } else if (ha->type == GDT_ISA) {
  1436. dp2_ptr = ha->brd;
  1437. gdth_writeb(1, &dp2_ptr->io.irqdel);
  1438. gdth_writeb(0, &dp2_ptr->u.ic.Cmd_Index);
  1439. gdth_writeb(1, &dp2_ptr->io.irqen);
  1440. } else if (ha->type == GDT_PCI) {
  1441. dp6_ptr = ha->brd;
  1442. gdth_writeb(1, &dp6_ptr->io.irqdel);
  1443. gdth_writeb(0, &dp6_ptr->u.ic.Cmd_Index);
  1444. gdth_writeb(1, &dp6_ptr->io.irqen);
  1445. } else if (ha->type == GDT_PCINEW) {
  1446. outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
  1447. outb(0x03, PTR2USHORT(&ha->plx->control1));
  1448. } else if (ha->type == GDT_PCIMPR) {
  1449. dp6m_ptr = ha->brd;
  1450. gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
  1451. gdth_writeb(gdth_readb(&dp6m_ptr->i960r.edoor_en_reg) & ~4,
  1452. &dp6m_ptr->i960r.edoor_en_reg);
  1453. }
  1454. spin_unlock_irqrestore(&ha->smp_lock, flags);
  1455. }
  1456. static int gdth_get_status(unchar *pIStatus,int irq)
  1457. {
  1458. register gdth_ha_str *ha;
  1459. int i;
  1460. TRACE(("gdth_get_status() irq %d ctr_count %d\n",
  1461. irq,gdth_ctr_count));
  1462. *pIStatus = 0;
  1463. for (i=0; i<gdth_ctr_count; ++i) {
  1464. ha = HADATA(gdth_ctr_tab[i]);
  1465. if (ha->irq != (unchar)irq) /* check IRQ */
  1466. continue;
  1467. if (ha->type == GDT_EISA)
  1468. *pIStatus = inb((ushort)ha->bmic + EDOORREG);
  1469. else if (ha->type == GDT_ISA)
  1470. *pIStatus =
  1471. gdth_readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
  1472. else if (ha->type == GDT_PCI)
  1473. *pIStatus =
  1474. gdth_readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
  1475. else if (ha->type == GDT_PCINEW)
  1476. *pIStatus = inb(PTR2USHORT(&ha->plx->edoor_reg));
  1477. else if (ha->type == GDT_PCIMPR)
  1478. *pIStatus =
  1479. gdth_readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.edoor_reg);
  1480. if (*pIStatus)
  1481. return i; /* board found */
  1482. }
  1483. return -1;
  1484. }
  1485. static int gdth_test_busy(int hanum)
  1486. {
  1487. register gdth_ha_str *ha;
  1488. register int gdtsema0 = 0;
  1489. TRACE(("gdth_test_busy() hanum %d\n",hanum));
  1490. ha = HADATA(gdth_ctr_tab[hanum]);
  1491. if (ha->type == GDT_EISA)
  1492. gdtsema0 = (int)inb(ha->bmic + SEMA0REG);
  1493. else if (ha->type == GDT_ISA)
  1494. gdtsema0 = (int)gdth_readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
  1495. else if (ha->type == GDT_PCI)
  1496. gdtsema0 = (int)gdth_readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
  1497. else if (ha->type == GDT_PCINEW)
  1498. gdtsema0 = (int)inb(PTR2USHORT(&ha->plx->sema0_reg));
  1499. else if (ha->type == GDT_PCIMPR)
  1500. gdtsema0 =
  1501. (int)gdth_readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg);
  1502. return (gdtsema0 & 1);
  1503. }
  1504. static int gdth_get_cmd_index(int hanum)
  1505. {
  1506. register gdth_ha_str *ha;
  1507. int i;
  1508. TRACE(("gdth_get_cmd_index() hanum %d\n",hanum));
  1509. ha = HADATA(gdth_ctr_tab[hanum]);
  1510. for (i=0; i<GDTH_MAXCMDS; ++i) {
  1511. if (ha->cmd_tab[i].cmnd == UNUSED_CMND) {
  1512. ha->cmd_tab[i].cmnd = ha->pccb->RequestBuffer;
  1513. ha->cmd_tab[i].service = ha->pccb->Service;
  1514. ha->pccb->CommandIndex = (ulong32)i+2;
  1515. return (i+2);
  1516. }
  1517. }
  1518. return 0;
  1519. }
  1520. static void gdth_set_sema0(int hanum)
  1521. {
  1522. register gdth_ha_str *ha;
  1523. TRACE(("gdth_set_sema0() hanum %d\n",hanum));
  1524. ha = HADATA(gdth_ctr_tab[hanum]);
  1525. if (ha->type == GDT_EISA) {
  1526. outb(1, ha->bmic + SEMA0REG);
  1527. } else if (ha->type == GDT_ISA) {
  1528. gdth_writeb(1, &((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
  1529. } else if (ha->type == GDT_PCI) {
  1530. gdth_writeb(1, &((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
  1531. } else if (ha->type == GDT_PCINEW) {
  1532. outb(1, PTR2USHORT(&ha->plx->sema0_reg));
  1533. } else if (ha->type == GDT_PCIMPR) {
  1534. gdth_writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg);
  1535. }
  1536. }
  1537. static void gdth_copy_command(int hanum)
  1538. {
  1539. register gdth_ha_str *ha;
  1540. register gdth_cmd_str *cmd_ptr;
  1541. register gdt6m_dpram_str __iomem *dp6m_ptr;
  1542. register gdt6c_dpram_str __iomem *dp6c_ptr;
  1543. gdt6_dpram_str __iomem *dp6_ptr;
  1544. gdt2_dpram_str __iomem *dp2_ptr;
  1545. ushort cp_count,dp_offset,cmd_no;
  1546. TRACE(("gdth_copy_command() hanum %d\n",hanum));
  1547. ha = HADATA(gdth_ctr_tab[hanum]);
  1548. cp_count = ha->cmd_len;
  1549. dp_offset= ha->cmd_offs_dpmem;
  1550. cmd_no = ha->cmd_cnt;
  1551. cmd_ptr = ha->pccb;
  1552. ++ha->cmd_cnt;
  1553. if (ha->type == GDT_EISA)
  1554. return; /* no DPMEM, no copy */
  1555. /* set cpcount dword aligned */
  1556. if (cp_count & 3)
  1557. cp_count += (4 - (cp_count & 3));
  1558. ha->cmd_offs_dpmem += cp_count;
  1559. /* set offset and service, copy command to DPMEM */
  1560. if (ha->type == GDT_ISA) {
  1561. dp2_ptr = ha->brd;
  1562. gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
  1563. &dp2_ptr->u.ic.comm_queue[cmd_no].offset);
  1564. gdth_writew((ushort)cmd_ptr->Service,
  1565. &dp2_ptr->u.ic.comm_queue[cmd_no].serv_id);
  1566. memcpy_toio(&dp2_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
  1567. } else if (ha->type == GDT_PCI) {
  1568. dp6_ptr = ha->brd;
  1569. gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
  1570. &dp6_ptr->u.ic.comm_queue[cmd_no].offset);
  1571. gdth_writew((ushort)cmd_ptr->Service,
  1572. &dp6_ptr->u.ic.comm_queue[cmd_no].serv_id);
  1573. memcpy_toio(&dp6_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
  1574. } else if (ha->type == GDT_PCINEW) {
  1575. dp6c_ptr = ha->brd;
  1576. gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
  1577. &dp6c_ptr->u.ic.comm_queue[cmd_no].offset);
  1578. gdth_writew((ushort)cmd_ptr->Service,
  1579. &dp6c_ptr->u.ic.comm_queue[cmd_no].serv_id);
  1580. memcpy_toio(&dp6c_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
  1581. } else if (ha->type == GDT_PCIMPR) {
  1582. dp6m_ptr = ha->brd;
  1583. gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET,
  1584. &dp6m_ptr->u.ic.comm_queue[cmd_no].offset);
  1585. gdth_writew((ushort)cmd_ptr->Service,
  1586. &dp6m_ptr->u.ic.comm_queue[cmd_no].serv_id);
  1587. memcpy_toio(&dp6m_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
  1588. }
  1589. }
  1590. static void gdth_release_event(int hanum)
  1591. {
  1592. register gdth_ha_str *ha;
  1593. TRACE(("gdth_release_event() hanum %d\n",hanum));
  1594. ha = HADATA(gdth_ctr_tab[hanum]);
  1595. #ifdef GDTH_STATISTICS
  1596. {
  1597. ulong32 i,j;
  1598. for (i=0,j=0; j<GDTH_MAXCMDS; ++j) {
  1599. if (ha->cmd_tab[j].cmnd != UNUSED_CMND)
  1600. ++i;
  1601. }
  1602. if (max_index < i) {
  1603. max_index = i;
  1604. TRACE3(("GDT: max_index = %d\n",(ushort)i));
  1605. }
  1606. }
  1607. #endif
  1608. if (ha->pccb->OpCode == GDT_INIT)
  1609. ha->pccb->Service |= 0x80;
  1610. if (ha->type == GDT_EISA) {
  1611. if (ha->pccb->OpCode == GDT_INIT) /* store DMA buffer */
  1612. outl(ha->ccb_phys, ha->bmic + MAILBOXREG);
  1613. outb(ha->pccb->Service, ha->bmic + LDOORREG);
  1614. } else if (ha->type == GDT_ISA) {
  1615. gdth_writeb(0, &((gdt2_dpram_str __iomem *)ha->brd)->io.event);
  1616. } else if (ha->type == GDT_PCI) {
  1617. gdth_writeb(0, &((gdt6_dpram_str __iomem *)ha->brd)->io.event);
  1618. } else if (ha->type == GDT_PCINEW) {
  1619. outb(1, PTR2USHORT(&ha->plx->ldoor_reg));
  1620. } else if (ha->type == GDT_PCIMPR) {
  1621. gdth_writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.ldoor_reg);
  1622. }
  1623. }
  1624. static int gdth_wait(int hanum,int index,ulong32 time)
  1625. {
  1626. gdth_ha_str *ha;
  1627. int answer_found = FALSE;
  1628. TRACE(("gdth_wait() hanum %d index %d time %d\n",hanum,index,time));
  1629. ha = HADATA(gdth_ctr_tab[hanum]);
  1630. if (index == 0)
  1631. return 1; /* no wait required */
  1632. gdth_from_wait = TRUE;
  1633. do {
  1634. gdth_interrupt((int)ha->irq,ha);
  1635. if (wait_hanum==hanum && wait_index==index) {
  1636. answer_found = TRUE;
  1637. break;
  1638. }
  1639. gdth_delay(1);
  1640. } while (--time);
  1641. gdth_from_wait = FALSE;
  1642. while (gdth_test_busy(hanum))
  1643. gdth_delay(0);
  1644. return (answer_found);
  1645. }
  1646. static int gdth_internal_cmd(int hanum,unchar service,ushort opcode,ulong32 p1,
  1647. ulong64 p2,ulong64 p3)
  1648. {
  1649. register gdth_ha_str *ha;
  1650. register gdth_cmd_str *cmd_ptr;
  1651. int retries,index;
  1652. TRACE2(("gdth_internal_cmd() service %d opcode %d\n",service,opcode));
  1653. ha = HADATA(gdth_ctr_tab[hanum]);
  1654. cmd_ptr = ha->pccb;
  1655. memset((char*)cmd_ptr,0,sizeof(gdth_cmd_str));
  1656. /* make command */
  1657. for (retries = INIT_RETRIES;;) {
  1658. cmd_ptr->Service = service;
  1659. cmd_ptr->RequestBuffer = INTERNAL_CMND;
  1660. if (!(index=gdth_get_cmd_index(hanum))) {
  1661. TRACE(("GDT: No free command index found\n"));
  1662. return 0;
  1663. }
  1664. gdth_set_sema0(hanum);
  1665. cmd_ptr->OpCode = opcode;
  1666. cmd_ptr->BoardNode = LOCALBOARD;
  1667. if (service == CACHESERVICE) {
  1668. if (opcode == GDT_IOCTL) {
  1669. cmd_ptr->u.ioctl.subfunc = p1;
  1670. cmd_ptr->u.ioctl.channel = (ulong32)p2;
  1671. cmd_ptr->u.ioctl.param_size = (ushort)p3;
  1672. cmd_ptr->u.ioctl.p_param = ha->scratch_phys;
  1673. } else {
  1674. if (ha->cache_feat & GDT_64BIT) {
  1675. cmd_ptr->u.cache64.DeviceNo = (ushort)p1;
  1676. cmd_ptr->u.cache64.BlockNo = p2;
  1677. } else {
  1678. cmd_ptr->u.cache.DeviceNo = (ushort)p1;
  1679. cmd_ptr->u.cache.BlockNo = (ulong32)p2;
  1680. }
  1681. }
  1682. } else if (service == SCSIRAWSERVICE) {
  1683. if (ha->raw_feat & GDT_64BIT) {
  1684. cmd_ptr->u.raw64.direction = p1;
  1685. cmd_ptr->u.raw64.bus = (unchar)p2;
  1686. cmd_ptr->u.raw64.target = (unchar)p3;
  1687. cmd_ptr->u.raw64.lun = (unchar)(p3 >> 8);
  1688. } else {
  1689. cmd_ptr->u.raw.direction = p1;
  1690. cmd_ptr->u.raw.bus = (unchar)p2;
  1691. cmd_ptr->u.raw.target = (unchar)p3;
  1692. cmd_ptr->u.raw.lun = (unchar)(p3 >> 8);
  1693. }
  1694. } else if (service == SCREENSERVICE) {
  1695. if (opcode == GDT_REALTIME) {
  1696. *(ulong32 *)&cmd_ptr->u.screen.su.data[0] = p1;
  1697. *(ulong32 *)&cmd_ptr->u.screen.su.data[4] = (ulong32)p2;
  1698. *(ulong32 *)&cmd_ptr->u.screen.su.data[8] = (ulong32)p3;
  1699. }
  1700. }
  1701. ha->cmd_len = sizeof(gdth_cmd_str);
  1702. ha->cmd_offs_dpmem = 0;
  1703. ha->cmd_cnt = 0;
  1704. gdth_copy_command(hanum);
  1705. gdth_release_event(hanum);
  1706. gdth_delay(20);
  1707. if (!gdth_wait(hanum,index,INIT_TIMEOUT)) {
  1708. printk("GDT: Initialization error (timeout service %d)\n",service);
  1709. return 0;
  1710. }
  1711. if (ha->status != S_BSY || --retries == 0)
  1712. break;
  1713. gdth_delay(1);
  1714. }
  1715. return (ha->status != S_OK ? 0:1);
  1716. }
  1717. /* search for devices */
  1718. static int __init gdth_search_drives(int hanum)
  1719. {
  1720. register gdth_ha_str *ha;
  1721. ushort cdev_cnt, i;
  1722. int ok;
  1723. ulong32 bus_no, drv_cnt, drv_no, j;
  1724. gdth_getch_str *chn;
  1725. gdth_drlist_str *drl;
  1726. gdth_iochan_str *ioc;
  1727. gdth_raw_iochan_str *iocr;
  1728. gdth_arcdl_str *alst;
  1729. gdth_alist_str *alst2;
  1730. gdth_oem_str_ioctl *oemstr;
  1731. #ifdef INT_COAL
  1732. gdth_perf_modes *pmod;
  1733. #endif
  1734. #ifdef GDTH_RTC
  1735. unchar rtc[12];
  1736. ulong flags;
  1737. #endif
  1738. TRACE(("gdth_search_drives() hanum %d\n",hanum));
  1739. ha = HADATA(gdth_ctr_tab[hanum]);
  1740. ok = 0;
  1741. /* initialize controller services, at first: screen service */
  1742. ha->screen_feat = 0;
  1743. if (!force_dma32) {
  1744. ok = gdth_internal_cmd(hanum,SCREENSERVICE,GDT_X_INIT_SCR,0,0,0);
  1745. if (ok)
  1746. ha->screen_feat = GDT_64BIT;
  1747. }
  1748. if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
  1749. ok = gdth_internal_cmd(hanum,SCREENSERVICE,GDT_INIT,0,0,0);
  1750. if (!ok) {
  1751. printk("GDT-HA %d: Initialization error screen service (code %d)\n",
  1752. hanum, ha->status);
  1753. return 0;
  1754. }
  1755. TRACE2(("gdth_search_drives(): SCREENSERVICE initialized\n"));
  1756. #ifdef GDTH_RTC
  1757. /* read realtime clock info, send to controller */
  1758. /* 1. wait for the falling edge of update flag */
  1759. spin_lock_irqsave(&rtc_lock, flags);
  1760. for (j = 0; j < 1000000; ++j)
  1761. if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP)
  1762. break;
  1763. for (j = 0; j < 1000000; ++j)
  1764. if (!(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP))
  1765. break;
  1766. /* 2. read info */
  1767. do {
  1768. for (j = 0; j < 12; ++j)
  1769. rtc[j] = CMOS_READ(j);
  1770. } while (rtc[0] != CMOS_READ(0));
  1771. spin_unlock_irqrestore(&rtc_lock, flags);
  1772. TRACE2(("gdth_search_drives(): RTC: %x/%x/%x\n",*(ulong32 *)&rtc[0],
  1773. *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8]));
  1774. /* 3. send to controller firmware */
  1775. gdth_internal_cmd(hanum,SCREENSERVICE,GDT_REALTIME, *(ulong32 *)&rtc[0],
  1776. *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8]);
  1777. #endif
  1778. /* unfreeze all IOs */
  1779. gdth_internal_cmd(hanum,CACHESERVICE,GDT_UNFREEZE_IO,0,0,0);
  1780. /* initialize cache service */
  1781. ha->cache_feat = 0;
  1782. if (!force_dma32) {
  1783. ok = gdth_internal_cmd(hanum,CACHESERVICE,GDT_X_INIT_HOST,LINUX_OS,0,0);
  1784. if (ok)
  1785. ha->cache_feat = GDT_64BIT;
  1786. }
  1787. if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
  1788. ok = gdth_internal_cmd(hanum,CACHESERVICE,GDT_INIT,LINUX_OS,0,0);
  1789. if (!ok) {
  1790. printk("GDT-HA %d: Initialization error cache service (code %d)\n",
  1791. hanum, ha->status);
  1792. return 0;
  1793. }
  1794. TRACE2(("gdth_search_drives(): CACHESERVICE initialized\n"));
  1795. cdev_cnt = (ushort)ha->info;
  1796. ha->fw_vers = ha->service;
  1797. #ifdef INT_COAL
  1798. if (ha->type == GDT_PCIMPR) {
  1799. /* set perf. modes */
  1800. pmod = (gdth_perf_modes *)ha->pscratch;
  1801. pmod->version = 1;
  1802. pmod->st_mode = 1; /* enable one status buffer */
  1803. *((ulong64 *)&pmod->st_buff_addr1) = ha->coal_stat_phys;
  1804. pmod->st_buff_indx1 = COALINDEX;
  1805. pmod->st_buff_addr2 = 0;
  1806. pmod->st_buff_u_addr2 = 0;
  1807. pmod->st_buff_indx2 = 0;
  1808. pmod->st_buff_size = sizeof(gdth_coal_status) * MAXOFFSETS;
  1809. pmod->cmd_mode = 0; // disable all cmd buffers
  1810. pmod->cmd_buff_addr1 = 0;
  1811. pmod->cmd_buff_u_addr1 = 0;
  1812. pmod->cmd_buff_indx1 = 0;
  1813. pmod->cmd_buff_addr2 = 0;
  1814. pmod->cmd_buff_u_addr2 = 0;
  1815. pmod->cmd_buff_indx2 = 0;
  1816. pmod->cmd_buff_size = 0;
  1817. pmod->reserved1 = 0;
  1818. pmod->reserved2 = 0;
  1819. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,SET_PERF_MODES,
  1820. INVALID_CHANNEL,sizeof(gdth_perf_modes))) {
  1821. printk("GDT-HA %d: Interrupt coalescing activated\n", hanum);
  1822. }
  1823. }
  1824. #endif
  1825. /* detect number of buses - try new IOCTL */
  1826. iocr = (gdth_raw_iochan_str *)ha->pscratch;
  1827. iocr->hdr.version = 0xffffffff;
  1828. iocr->hdr.list_entries = MAXBUS;
  1829. iocr->hdr.first_chan = 0;
  1830. iocr->hdr.last_chan = MAXBUS-1;
  1831. iocr->hdr.list_offset = GDTOFFSOF(gdth_raw_iochan_str, list[0]);
  1832. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,IOCHAN_RAW_DESC,
  1833. INVALID_CHANNEL,sizeof(gdth_raw_iochan_str))) {
  1834. TRACE2(("IOCHAN_RAW_DESC supported!\n"));
  1835. ha->bus_cnt = iocr->hdr.chan_count;
  1836. for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
  1837. if (iocr->list[bus_no].proc_id < MAXID)
  1838. ha->bus_id[bus_no] = iocr->list[bus_no].proc_id;
  1839. else
  1840. ha->bus_id[bus_no] = 0xff;
  1841. }
  1842. } else {
  1843. /* old method */
  1844. chn = (gdth_getch_str *)ha->pscratch;
  1845. for (bus_no = 0; bus_no < MAXBUS; ++bus_no) {
  1846. chn->channel_no = bus_no;
  1847. if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
  1848. SCSI_CHAN_CNT | L_CTRL_PATTERN,
  1849. IO_CHANNEL | INVALID_CHANNEL,
  1850. sizeof(gdth_getch_str))) {
  1851. if (bus_no == 0) {
  1852. printk("GDT-HA %d: Error detecting channel count (0x%x)\n",
  1853. hanum, ha->status);
  1854. return 0;
  1855. }
  1856. break;
  1857. }
  1858. if (chn->siop_id < MAXID)
  1859. ha->bus_id[bus_no] = chn->siop_id;
  1860. else
  1861. ha->bus_id[bus_no] = 0xff;
  1862. }
  1863. ha->bus_cnt = (unchar)bus_no;
  1864. }
  1865. TRACE2(("gdth_search_drives() %d channels\n",ha->bus_cnt));
  1866. /* read cache configuration */
  1867. if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,CACHE_INFO,
  1868. INVALID_CHANNEL,sizeof(gdth_cinfo_str))) {
  1869. printk("GDT-HA %d: Initialization error cache service (code %d)\n",
  1870. hanum, ha->status);
  1871. return 0;
  1872. }
  1873. ha->cpar = ((gdth_cinfo_str *)ha->pscratch)->cpar;
  1874. TRACE2(("gdth_search_drives() cinfo: vs %x sta %d str %d dw %d b %d\n",
  1875. ha->cpar.version,ha->cpar.state,ha->cpar.strategy,
  1876. ha->cpar.write_back,ha->cpar.block_size));
  1877. /* read board info and features */
  1878. ha->more_proc = FALSE;
  1879. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,BOARD_INFO,
  1880. INVALID_CHANNEL,sizeof(gdth_binfo_str))) {
  1881. memcpy(&ha->binfo, (gdth_binfo_str *)ha->pscratch,
  1882. sizeof(gdth_binfo_str));
  1883. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,BOARD_FEATURES,
  1884. INVALID_CHANNEL,sizeof(gdth_bfeat_str))) {
  1885. TRACE2(("BOARD_INFO/BOARD_FEATURES supported\n"));
  1886. ha->bfeat = *(gdth_bfeat_str *)ha->pscratch;
  1887. ha->more_proc = TRUE;
  1888. }
  1889. } else {
  1890. TRACE2(("BOARD_INFO requires firmware >= 1.10/2.08\n"));
  1891. strcpy(ha->binfo.type_string, gdth_ctr_name(hanum));
  1892. }
  1893. TRACE2(("Controller name: %s\n",ha->binfo.type_string));
  1894. /* read more informations */
  1895. if (ha->more_proc) {
  1896. /* physical drives, channel addresses */
  1897. ioc = (gdth_iochan_str *)ha->pscratch;
  1898. ioc->hdr.version = 0xffffffff;
  1899. ioc->hdr.list_entries = MAXBUS;
  1900. ioc->hdr.first_chan = 0;
  1901. ioc->hdr.last_chan = MAXBUS-1;
  1902. ioc->hdr.list_offset = GDTOFFSOF(gdth_iochan_str, list[0]);
  1903. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,IOCHAN_DESC,
  1904. INVALID_CHANNEL,sizeof(gdth_iochan_str))) {
  1905. for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
  1906. ha->raw[bus_no].address = ioc->list[bus_no].address;
  1907. ha->raw[bus_no].local_no = ioc->list[bus_no].local_no;
  1908. }
  1909. } else {
  1910. for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
  1911. ha->raw[bus_no].address = IO_CHANNEL;
  1912. ha->raw[bus_no].local_no = bus_no;
  1913. }
  1914. }
  1915. for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
  1916. chn = (gdth_getch_str *)ha->pscratch;
  1917. chn->channel_no = ha->raw[bus_no].local_no;
  1918. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
  1919. SCSI_CHAN_CNT | L_CTRL_PATTERN,
  1920. ha->raw[bus_no].address | INVALID_CHANNEL,
  1921. sizeof(gdth_getch_str))) {
  1922. ha->raw[bus_no].pdev_cnt = chn->drive_cnt;
  1923. TRACE2(("Channel %d: %d phys. drives\n",
  1924. bus_no,chn->drive_cnt));
  1925. }
  1926. if (ha->raw[bus_no].pdev_cnt > 0) {
  1927. drl = (gdth_drlist_str *)ha->pscratch;
  1928. drl->sc_no = ha->raw[bus_no].local_no;
  1929. drl->sc_cnt = ha->raw[bus_no].pdev_cnt;
  1930. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
  1931. SCSI_DR_LIST | L_CTRL_PATTERN,
  1932. ha->raw[bus_no].address | INVALID_CHANNEL,
  1933. sizeof(gdth_drlist_str))) {
  1934. for (j = 0; j < ha->raw[bus_no].pdev_cnt; ++j)
  1935. ha->raw[bus_no].id_list[j] = drl->sc_list[j];
  1936. } else {
  1937. ha->raw[bus_no].pdev_cnt = 0;
  1938. }
  1939. }
  1940. }
  1941. /* logical drives */
  1942. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,CACHE_DRV_CNT,
  1943. INVALID_CHANNEL,sizeof(ulong32))) {
  1944. drv_cnt = *(ulong32 *)ha->pscratch;
  1945. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,CACHE_DRV_LIST,
  1946. INVALID_CHANNEL,drv_cnt * sizeof(ulong32))) {
  1947. for (j = 0; j < drv_cnt; ++j) {
  1948. drv_no = ((ulong32 *)ha->pscratch)[j];
  1949. if (drv_no < MAX_LDRIVES) {
  1950. ha->hdr[drv_no].is_logdrv = TRUE;
  1951. TRACE2(("Drive %d is log. drive\n",drv_no));
  1952. }
  1953. }
  1954. }
  1955. alst = (gdth_arcdl_str *)ha->pscratch;
  1956. alst->entries_avail = MAX_LDRIVES;
  1957. alst->first_entry = 0;
  1958. alst->list_offset = GDTOFFSOF(gdth_arcdl_str, list[0]);
  1959. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
  1960. ARRAY_DRV_LIST2 | LA_CTRL_PATTERN,
  1961. INVALID_CHANNEL, sizeof(gdth_arcdl_str) +
  1962. (alst->entries_avail-1) * sizeof(gdth_alist_str))) {
  1963. for (j = 0; j < alst->entries_init; ++j) {
  1964. ha->hdr[j].is_arraydrv = alst->list[j].is_arrayd;
  1965. ha->hdr[j].is_master = alst->list[j].is_master;
  1966. ha->hdr[j].is_parity = alst->list[j].is_parity;
  1967. ha->hdr[j].is_hotfix = alst->list[j].is_hotfix;
  1968. ha->hdr[j].master_no = alst->list[j].cd_handle;
  1969. }
  1970. } else if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
  1971. ARRAY_DRV_LIST | LA_CTRL_PATTERN,
  1972. 0, 35 * sizeof(gdth_alist_str))) {
  1973. for (j = 0; j < 35; ++j) {
  1974. alst2 = &((gdth_alist_str *)ha->pscratch)[j];
  1975. ha->hdr[j].is_arraydrv = alst2->is_arrayd;
  1976. ha->hdr[j].is_master = alst2->is_master;
  1977. ha->hdr[j].is_parity = alst2->is_parity;
  1978. ha->hdr[j].is_hotfix = alst2->is_hotfix;
  1979. ha->hdr[j].master_no = alst2->cd_handle;
  1980. }
  1981. }
  1982. }
  1983. }
  1984. /* initialize raw service */
  1985. ha->raw_feat = 0;
  1986. if (!force_dma32) {
  1987. ok = gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_X_INIT_RAW,0,0,0);
  1988. if (ok)
  1989. ha->raw_feat = GDT_64BIT;
  1990. }
  1991. if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC))
  1992. ok = gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_INIT,0,0,0);
  1993. if (!ok) {
  1994. printk("GDT-HA %d: Initialization error raw service (code %d)\n",
  1995. hanum, ha->status);
  1996. return 0;
  1997. }
  1998. TRACE2(("gdth_search_drives(): RAWSERVICE initialized\n"));
  1999. /* set/get features raw service (scatter/gather) */
  2000. if (gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_SET_FEAT,SCATTER_GATHER,
  2001. 0,0)) {
  2002. TRACE2(("gdth_search_drives(): set features RAWSERVICE OK\n"));
  2003. if (gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_GET_FEAT,0,0,0)) {
  2004. TRACE2(("gdth_search_dr(): get feat RAWSERVICE %d\n",
  2005. ha->info));
  2006. ha->raw_feat |= (ushort)ha->info;
  2007. }
  2008. }
  2009. /* set/get features cache service (equal to raw service) */
  2010. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_SET_FEAT,0,
  2011. SCATTER_GATHER,0)) {
  2012. TRACE2(("gdth_search_drives(): set features CACHESERVICE OK\n"));
  2013. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_GET_FEAT,0,0,0)) {
  2014. TRACE2(("gdth_search_dr(): get feat CACHESERV. %d\n",
  2015. ha->info));
  2016. ha->cache_feat |= (ushort)ha->info;
  2017. }
  2018. }
  2019. /* reserve drives for raw service */
  2020. if (reserve_mode != 0) {
  2021. gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_RESERVE_ALL,
  2022. reserve_mode == 1 ? 1 : 3, 0, 0);
  2023. TRACE2(("gdth_search_drives(): RESERVE_ALL code %d\n",
  2024. ha->status));
  2025. }
  2026. for (i = 0; i < MAX_RES_ARGS; i += 4) {
  2027. if (reserve_list[i] == hanum && reserve_list[i+1] < ha->bus_cnt &&
  2028. reserve_list[i+2] < ha->tid_cnt && reserve_list[i+3] < MAXLUN) {
  2029. TRACE2(("gdth_search_drives(): reserve ha %d bus %d id %d lun %d\n",
  2030. reserve_list[i], reserve_list[i+1],
  2031. reserve_list[i+2], reserve_list[i+3]));
  2032. if (!gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_RESERVE,0,
  2033. reserve_list[i+1], reserve_list[i+2] |
  2034. (reserve_list[i+3] << 8))) {
  2035. printk("GDT-HA %d: Error raw service (RESERVE, code %d)\n",
  2036. hanum, ha->status);
  2037. }
  2038. }
  2039. }
  2040. /* Determine OEM string using IOCTL */
  2041. oemstr = (gdth_oem_str_ioctl *)ha->pscratch;
  2042. oemstr->params.ctl_version = 0x01;
  2043. oemstr->params.buffer_size = sizeof(oemstr->text);
  2044. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
  2045. CACHE_READ_OEM_STRING_RECORD,INVALID_CHANNEL,
  2046. sizeof(gdth_oem_str_ioctl))) {
  2047. TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD OK\n"));
  2048. printk("GDT-HA %d: Vendor: %s Name: %s\n",
  2049. hanum,oemstr->text.oem_company_name,ha->binfo.type_string);
  2050. /* Save the Host Drive inquiry data */
  2051. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  2052. strlcpy(ha->oem_name,oemstr->text.scsi_host_drive_inquiry_vendor_id,
  2053. sizeof(ha->oem_name));
  2054. #else
  2055. strncpy(ha->oem_name,oemstr->text.scsi_host_drive_inquiry_vendor_id,7);
  2056. ha->oem_name[7] = '\0';
  2057. #endif
  2058. } else {
  2059. /* Old method, based on PCI ID */
  2060. TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD failed\n"));
  2061. printk("GDT-HA %d: Name: %s\n",
  2062. hanum,ha->binfo.type_string);
  2063. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  2064. if (ha->oem_id == OEM_ID_INTEL)
  2065. strlcpy(ha->oem_name,"Intel ", sizeof(ha->oem_name));
  2066. else
  2067. strlcpy(ha->oem_name,"ICP ", sizeof(ha->oem_name));
  2068. #else
  2069. if (ha->oem_id == OEM_ID_INTEL)
  2070. strcpy(ha->oem_name,"Intel ");
  2071. else
  2072. strcpy(ha->oem_name,"ICP ");
  2073. #endif
  2074. }
  2075. /* scanning for host drives */
  2076. for (i = 0; i < cdev_cnt; ++i)
  2077. gdth_analyse_hdrive(hanum,i);
  2078. TRACE(("gdth_search_drives() OK\n"));
  2079. return 1;
  2080. }
  2081. static int gdth_analyse_hdrive(int hanum,ushort hdrive)
  2082. {
  2083. register gdth_ha_str *ha;
  2084. ulong32 drv_cyls;
  2085. int drv_hds, drv_secs;
  2086. TRACE(("gdth_analyse_hdrive() hanum %d drive %d\n",hanum,hdrive));
  2087. if (hdrive >= MAX_HDRIVES)
  2088. return 0;
  2089. ha = HADATA(gdth_ctr_tab[hanum]);
  2090. if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_INFO,hdrive,0,0))
  2091. return 0;
  2092. ha->hdr[hdrive].present = TRUE;
  2093. ha->hdr[hdrive].size = ha->info;
  2094. /* evaluate mapping (sectors per head, heads per cylinder) */
  2095. ha->hdr[hdrive].size &= ~SECS32;
  2096. if (ha->info2 == 0) {
  2097. gdth_eval_mapping(ha->hdr[hdrive].size,&drv_cyls,&drv_hds,&drv_secs);
  2098. } else {
  2099. drv_hds = ha->info2 & 0xff;
  2100. drv_secs = (ha->info2 >> 8) & 0xff;
  2101. drv_cyls = (ulong32)ha->hdr[hdrive].size / drv_hds / drv_secs;
  2102. }
  2103. ha->hdr[hdrive].heads = (unchar)drv_hds;
  2104. ha->hdr[hdrive].secs = (unchar)drv_secs;
  2105. /* round size */
  2106. ha->hdr[hdrive].size = drv_cyls * drv_hds * drv_secs;
  2107. if (ha->cache_feat & GDT_64BIT) {
  2108. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_X_INFO,hdrive,0,0)
  2109. && ha->info2 != 0) {
  2110. ha->hdr[hdrive].size = ((ulong64)ha->info2 << 32) | ha->info;
  2111. }
  2112. }
  2113. TRACE2(("gdth_search_dr() cdr. %d size %d hds %d scs %d\n",
  2114. hdrive,ha->hdr[hdrive].size,drv_hds,drv_secs));
  2115. /* get informations about device */
  2116. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_DEVTYPE,hdrive,0,0)) {
  2117. TRACE2(("gdth_search_dr() cache drive %d devtype %d\n",
  2118. hdrive,ha->info));
  2119. ha->hdr[hdrive].devtype = (ushort)ha->info;
  2120. }
  2121. /* cluster info */
  2122. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_CLUST_INFO,hdrive,0,0)) {
  2123. TRACE2(("gdth_search_dr() cache drive %d cluster info %d\n",
  2124. hdrive,ha->info));
  2125. if (!shared_access)
  2126. ha->hdr[hdrive].cluster_type = (unchar)ha->info;
  2127. }
  2128. /* R/W attributes */
  2129. if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_RW_ATTRIBS,hdrive,0,0)) {
  2130. TRACE2(("gdth_search_dr() cache drive %d r/w attrib. %d\n",
  2131. hdrive,ha->info));
  2132. ha->hdr[hdrive].rw_attribs = (unchar)ha->info;
  2133. }
  2134. return 1;
  2135. }
  2136. /* command queueing/sending functions */
  2137. static void gdth_putq(int hanum,Scsi_Cmnd *scp,unchar priority)
  2138. {
  2139. register gdth_ha_str *ha;
  2140. register Scsi_Cmnd *pscp;
  2141. register Scsi_Cmnd *nscp;
  2142. ulong flags;
  2143. unchar b, t;
  2144. TRACE(("gdth_putq() priority %d\n",priority));
  2145. ha = HADATA(gdth_ctr_tab[hanum]);
  2146. spin_lock_irqsave(&ha->smp_lock, flags);
  2147. if (!IS_GDTH_INTERNAL_CMD(scp)) {
  2148. scp->SCp.this_residual = (int)priority;
  2149. b = virt_ctr ? NUMDATA(scp->device->host)->busnum:scp->device->channel;
  2150. t = scp->device->id;
  2151. if (priority >= DEFAULT_PRI) {
  2152. if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) ||
  2153. (b==ha->virt_bus && t<MAX_HDRIVES && ha->hdr[t].lock)) {
  2154. TRACE2(("gdth_putq(): locked IO ->update_timeout()\n"));
  2155. scp->SCp.buffers_residual = gdth_update_timeout(hanum, scp, 0);
  2156. }
  2157. }
  2158. }
  2159. if (ha->req_first==NULL) {
  2160. ha->req_first = scp; /* queue was empty */
  2161. scp->SCp.ptr = NULL;
  2162. } else { /* queue not empty */
  2163. pscp = ha->req_first;
  2164. nscp = (Scsi_Cmnd *)pscp->SCp.ptr;
  2165. /* priority: 0-highest,..,0xff-lowest */
  2166. while (nscp && (unchar)nscp->SCp.this_residual <= priority) {
  2167. pscp = nscp;
  2168. nscp = (Scsi_Cmnd *)pscp->SCp.ptr;
  2169. }
  2170. pscp->SCp.ptr = (char *)scp;
  2171. scp->SCp.ptr = (char *)nscp;
  2172. }
  2173. spin_unlock_irqrestore(&ha->smp_lock, flags);
  2174. #ifdef GDTH_STATISTICS
  2175. flags = 0;
  2176. for (nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr)
  2177. ++flags;
  2178. if (max_rq < flags) {
  2179. max_rq = flags;
  2180. TRACE3(("GDT: max_rq = %d\n",(ushort)max_rq));
  2181. }
  2182. #endif
  2183. }
  2184. static void gdth_next(int hanum)
  2185. {
  2186. register gdth_ha_str *ha;
  2187. register Scsi_Cmnd *pscp;
  2188. register Scsi_Cmnd *nscp;
  2189. unchar b, t, l, firsttime;
  2190. unchar this_cmd, next_cmd;
  2191. ulong flags = 0;
  2192. int cmd_index;
  2193. TRACE(("gdth_next() hanum %d\n",hanum));
  2194. ha = HADATA(gdth_ctr_tab[hanum]);
  2195. if (!gdth_polling)
  2196. spin_lock_irqsave(&ha->smp_lock, flags);
  2197. ha->cmd_cnt = ha->cmd_offs_dpmem = 0;
  2198. this_cmd = firsttime = TRUE;
  2199. next_cmd = gdth_polling ? FALSE:TRUE;
  2200. cmd_index = 0;
  2201. for (nscp = pscp = ha->req_first; nscp; nscp = (Scsi_Cmnd *)nscp->SCp.ptr) {
  2202. if (nscp != pscp && nscp != (Scsi_Cmnd *)pscp->SCp.ptr)
  2203. pscp = (Scsi_Cmnd *)pscp->SCp.ptr;
  2204. if (!IS_GDTH_INTERNAL_CMD(nscp)) {
  2205. b = virt_ctr ?
  2206. NUMDATA(nscp->device->host)->busnum : nscp->device->channel;
  2207. t = nscp->device->id;
  2208. l = nscp->device->lun;
  2209. if (nscp->SCp.this_residual >= DEFAULT_PRI) {
  2210. if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) ||
  2211. (b == ha->virt_bus && t < MAX_HDRIVES && ha->hdr[t].lock))
  2212. continue;
  2213. }
  2214. } else
  2215. b = t = l = 0;
  2216. if (firsttime) {
  2217. if (gdth_test_busy(hanum)) { /* controller busy ? */
  2218. TRACE(("gdth_next() controller %d busy !\n",hanum));
  2219. if (!gdth_polling) {
  2220. spin_unlock_irqrestore(&ha->smp_lock, flags);
  2221. return;
  2222. }
  2223. while (gdth_test_busy(hanum))
  2224. gdth_delay(1);
  2225. }
  2226. firsttime = FALSE;
  2227. }
  2228. if (!IS_GDTH_INTERNAL_CMD(nscp)) {
  2229. if (nscp->SCp.phase == -1) {
  2230. nscp->SCp.phase = CACHESERVICE; /* default: cache svc. */
  2231. if (nscp->cmnd[0] == TEST_UNIT_READY) {
  2232. TRACE2(("TEST_UNIT_READY Bus %d Id %d LUN %d\n",
  2233. b, t, l));
  2234. /* TEST_UNIT_READY -> set scan mode */
  2235. if ((ha->scan_mode & 0x0f) == 0) {
  2236. if (b == 0 && t == 0 && l == 0) {
  2237. ha->scan_mode |= 1;
  2238. TRACE2(("Scan mode: 0x%x\n", ha->scan_mode));
  2239. }
  2240. } else if ((ha->scan_mode & 0x0f) == 1) {
  2241. if (b == 0 && ((t == 0 && l == 1) ||
  2242. (t == 1 && l == 0))) {
  2243. nscp->SCp.sent_command = GDT_SCAN_START;
  2244. nscp->SCp.phase = ((ha->scan_mode & 0x10 ? 1:0) << 8)
  2245. | SCSIRAWSERVICE;
  2246. ha->scan_mode = 0x12;
  2247. TRACE2(("Scan mode: 0x%x (SCAN_START)\n",
  2248. ha->scan_mode));
  2249. } else {
  2250. ha->scan_mode &= 0x10;
  2251. TRACE2(("Scan mode: 0x%x\n", ha->scan_mode));
  2252. }
  2253. } else if (ha->scan_mode == 0x12) {
  2254. if (b == ha->bus_cnt && t == ha->tid_cnt-1) {
  2255. nscp->SCp.phase = SCSIRAWSERVICE;
  2256. nscp->SCp.sent_command = GDT_SCAN_END;
  2257. ha->scan_mode &= 0x10;
  2258. TRACE2(("Scan mode: 0x%x (SCAN_END)\n",
  2259. ha->scan_mode));
  2260. }
  2261. }
  2262. }
  2263. if (b == ha->virt_bus && nscp->cmnd[0] != INQUIRY &&
  2264. nscp->cmnd[0] != READ_CAPACITY && nscp->cmnd[0] != MODE_SENSE &&
  2265. (ha->hdr[t].cluster_type & CLUSTER_DRIVE)) {
  2266. /* always GDT_CLUST_INFO! */
  2267. nscp->SCp.sent_command = GDT_CLUST_INFO;
  2268. }
  2269. }
  2270. }
  2271. if (nscp->SCp.sent_command != -1) {
  2272. if ((nscp->SCp.phase & 0xff) == CACHESERVICE) {
  2273. if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
  2274. this_cmd = FALSE;
  2275. next_cmd = FALSE;
  2276. } else if ((nscp->SCp.phase & 0xff) == SCSIRAWSERVICE) {
  2277. if (!(cmd_index=gdth_fill_raw_cmd(hanum,nscp,BUS_L2P(ha,b))))
  2278. this_cmd = FALSE;
  2279. next_cmd = FALSE;
  2280. } else {
  2281. memset((char*)nscp->sense_buffer,0,16);
  2282. nscp->sense_buffer[0] = 0x70;
  2283. nscp->sense_buffer[2] = NOT_READY;
  2284. nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
  2285. if (!nscp->SCp.have_data_in)
  2286. nscp->SCp.have_data_in++;
  2287. else
  2288. nscp->scsi_done(nscp);
  2289. }
  2290. } else if (IS_GDTH_INTERNAL_CMD(nscp)) {
  2291. if (!(cmd_index=gdth_special_cmd(hanum,nscp)))
  2292. this_cmd = FALSE;
  2293. next_cmd = FALSE;
  2294. } else if (b != ha->virt_bus) {
  2295. if (ha->raw[BUS_L2P(ha,b)].io_cnt[t] >= GDTH_MAX_RAW ||
  2296. !(cmd_index=gdth_fill_raw_cmd(hanum,nscp,BUS_L2P(ha,b))))
  2297. this_cmd = FALSE;
  2298. else
  2299. ha->raw[BUS_L2P(ha,b)].io_cnt[t]++;
  2300. } else if (t >= MAX_HDRIVES || !ha->hdr[t].present || l != 0) {
  2301. TRACE2(("Command 0x%x to bus %d id %d lun %d -> IGNORE\n",
  2302. nscp->cmnd[0], b, t, l));
  2303. nscp->result = DID_BAD_TARGET << 16;
  2304. if (!nscp->SCp.have_data_in)
  2305. nscp->SCp.have_data_in++;
  2306. else
  2307. nscp->scsi_done(nscp);
  2308. } else {
  2309. switch (nscp->cmnd[0]) {
  2310. case TEST_UNIT_READY:
  2311. case INQUIRY:
  2312. case REQUEST_SENSE:
  2313. case READ_CAPACITY:
  2314. case VERIFY:
  2315. case START_STOP:
  2316. case MODE_SENSE:
  2317. case SERVICE_ACTION_IN:
  2318. TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
  2319. nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
  2320. nscp->cmnd[4],nscp->cmnd[5]));
  2321. if (ha->hdr[t].media_changed && nscp->cmnd[0] != INQUIRY) {
  2322. /* return UNIT_ATTENTION */
  2323. TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
  2324. nscp->cmnd[0], t));
  2325. ha->hdr[t].media_changed = FALSE;
  2326. memset((char*)nscp->sense_buffer,0,16);
  2327. nscp->sense_buffer[0] = 0x70;
  2328. nscp->sense_buffer[2] = UNIT_ATTENTION;
  2329. nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
  2330. if (!nscp->SCp.have_data_in)
  2331. nscp->SCp.have_data_in++;
  2332. else
  2333. nscp->scsi_done(nscp);
  2334. } else if (gdth_internal_cache_cmd(hanum,nscp))
  2335. nscp->scsi_done(nscp);
  2336. break;
  2337. case ALLOW_MEDIUM_REMOVAL:
  2338. TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
  2339. nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
  2340. nscp->cmnd[4],nscp->cmnd[5]));
  2341. if ( (nscp->cmnd[4]&1) && !(ha->hdr[t].devtype&1) ) {
  2342. TRACE(("Prevent r. nonremov. drive->do nothing\n"));
  2343. nscp->result = DID_OK << 16;
  2344. nscp->sense_buffer[0] = 0;
  2345. if (!nscp->SCp.have_data_in)
  2346. nscp->SCp.have_data_in++;
  2347. else
  2348. nscp->scsi_done(nscp);
  2349. } else {
  2350. nscp->cmnd[3] = (ha->hdr[t].devtype&1) ? 1:0;
  2351. TRACE(("Prevent/allow r. %d rem. drive %d\n",
  2352. nscp->cmnd[4],nscp->cmnd[3]));
  2353. if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
  2354. this_cmd = FALSE;
  2355. }
  2356. break;
  2357. case RESERVE:
  2358. case RELEASE:
  2359. TRACE2(("cache cmd %s\n",nscp->cmnd[0] == RESERVE ?
  2360. "RESERVE" : "RELEASE"));
  2361. if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
  2362. this_cmd = FALSE;
  2363. break;
  2364. case READ_6:
  2365. case WRITE_6:
  2366. case READ_10:
  2367. case WRITE_10:
  2368. case READ_16:
  2369. case WRITE_16:
  2370. if (ha->hdr[t].media_changed) {
  2371. /* return UNIT_ATTENTION */
  2372. TRACE2(("cmd 0x%x target %d: UNIT_ATTENTION\n",
  2373. nscp->cmnd[0], t));
  2374. ha->hdr[t].media_changed = FALSE;
  2375. memset((char*)nscp->sense_buffer,0,16);
  2376. nscp->sense_buffer[0] = 0x70;
  2377. nscp->sense_buffer[2] = UNIT_ATTENTION;
  2378. nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
  2379. if (!nscp->SCp.have_data_in)
  2380. nscp->SCp.have_data_in++;
  2381. else
  2382. nscp->scsi_done(nscp);
  2383. } else if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
  2384. this_cmd = FALSE;
  2385. break;
  2386. default:
  2387. TRACE2(("cache cmd %x/%x/%x/%x/%x/%x unknown\n",nscp->cmnd[0],
  2388. nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
  2389. nscp->cmnd[4],nscp->cmnd[5]));
  2390. printk("GDT-HA %d: Unknown SCSI command 0x%x to cache service !\n",
  2391. hanum, nscp->cmnd[0]);
  2392. nscp->result = DID_ABORT << 16;
  2393. if (!nscp->SCp.have_data_in)
  2394. nscp->SCp.have_data_in++;
  2395. else
  2396. nscp->scsi_done(nscp);
  2397. break;
  2398. }
  2399. }
  2400. if (!this_cmd)
  2401. break;
  2402. if (nscp == ha->req_first)
  2403. ha->req_first = pscp = (Scsi_Cmnd *)nscp->SCp.ptr;
  2404. else
  2405. pscp->SCp.ptr = nscp->SCp.ptr;
  2406. if (!next_cmd)
  2407. break;
  2408. }
  2409. if (ha->cmd_cnt > 0) {
  2410. gdth_release_event(hanum);
  2411. }
  2412. if (!gdth_polling)
  2413. spin_unlock_irqrestore(&ha->smp_lock, flags);
  2414. if (gdth_polling && ha->cmd_cnt > 0) {
  2415. if (!gdth_wait(hanum,cmd_index,POLL_TIMEOUT))
  2416. printk("GDT-HA %d: Command %d timed out !\n",
  2417. hanum,cmd_index);
  2418. }
  2419. }
  2420. static void gdth_copy_internal_data(int hanum,Scsi_Cmnd *scp,
  2421. char *buffer,ushort count)
  2422. {
  2423. ushort cpcount,i;
  2424. ushort cpsum,cpnow;
  2425. struct scatterlist *sl;
  2426. gdth_ha_str *ha;
  2427. char *address;
  2428. cpcount = count<=(ushort)scp->request_bufflen ? count:(ushort)scp->request_bufflen;
  2429. ha = HADATA(gdth_ctr_tab[hanum]);
  2430. if (scp->use_sg) {
  2431. sl = (struct scatterlist *)scp->request_buffer;
  2432. for (i=0,cpsum=0; i<scp->use_sg; ++i,++sl) {
  2433. unsigned long flags;
  2434. cpnow = (ushort)sl->length;
  2435. TRACE(("copy_internal() now %d sum %d count %d %d\n",
  2436. cpnow,cpsum,cpcount,(ushort)scp->bufflen));
  2437. if (cpsum+cpnow > cpcount)
  2438. cpnow = cpcount - cpsum;
  2439. cpsum += cpnow;
  2440. if (!sl->page) {
  2441. printk("GDT-HA %d: invalid sc/gt element in gdth_copy_internal_data()\n",
  2442. hanum);
  2443. return;
  2444. }
  2445. local_irq_save(flags);
  2446. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  2447. address = kmap_atomic(sl->page, KM_BIO_SRC_IRQ) + sl->offset;
  2448. memcpy(address,buffer,cpnow);
  2449. flush_dcache_page(sl->page);
  2450. kunmap_atomic(address, KM_BIO_SRC_IRQ);
  2451. #else
  2452. address = kmap_atomic(sl->page, KM_BH_IRQ) + sl->offset;
  2453. memcpy(address,buffer,cpnow);
  2454. flush_dcache_page(sl->page);
  2455. kunmap_atomic(address, KM_BH_IRQ);
  2456. #endif
  2457. local_irq_restore(flags);
  2458. if (cpsum == cpcount)
  2459. break;
  2460. buffer += cpnow;
  2461. }
  2462. } else {
  2463. TRACE(("copy_internal() count %d\n",cpcount));
  2464. memcpy((char*)scp->request_buffer,buffer,cpcount);
  2465. }
  2466. }
  2467. static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp)
  2468. {
  2469. register gdth_ha_str *ha;
  2470. unchar t;
  2471. gdth_inq_data inq;
  2472. gdth_rdcap_data rdc;
  2473. gdth_sense_data sd;
  2474. gdth_modep_data mpd;
  2475. ha = HADATA(gdth_ctr_tab[hanum]);
  2476. t = scp->device->id;
  2477. TRACE(("gdth_internal_cache_cmd() cmd 0x%x hdrive %d\n",
  2478. scp->cmnd[0],t));
  2479. scp->result = DID_OK << 16;
  2480. scp->sense_buffer[0] = 0;
  2481. switch (scp->cmnd[0]) {
  2482. case TEST_UNIT_READY:
  2483. case VERIFY:
  2484. case START_STOP:
  2485. TRACE2(("Test/Verify/Start hdrive %d\n",t));
  2486. break;
  2487. case INQUIRY:
  2488. TRACE2(("Inquiry hdrive %d devtype %d\n",
  2489. t,ha->hdr[t].devtype));
  2490. inq.type_qual = (ha->hdr[t].devtype&4) ? TYPE_ROM:TYPE_DISK;
  2491. /* you can here set all disks to removable, if you want to do
  2492. a flush using the ALLOW_MEDIUM_REMOVAL command */
  2493. inq.modif_rmb = 0x00;
  2494. if ((ha->hdr[t].devtype & 1) ||
  2495. (ha->hdr[t].cluster_type & CLUSTER_DRIVE))
  2496. inq.modif_rmb = 0x80;
  2497. inq.version = 2;
  2498. inq.resp_aenc = 2;
  2499. inq.add_length= 32;
  2500. strcpy(inq.vendor,ha->oem_name);
  2501. sprintf(inq.product,"Host Drive #%02d",t);
  2502. strcpy(inq.revision," ");
  2503. gdth_copy_internal_data(hanum,scp,(char*)&inq,sizeof(gdth_inq_data));
  2504. break;
  2505. case REQUEST_SENSE:
  2506. TRACE2(("Request sense hdrive %d\n",t));
  2507. sd.errorcode = 0x70;
  2508. sd.segno = 0x00;
  2509. sd.key = NO_SENSE;
  2510. sd.info = 0;
  2511. sd.add_length= 0;
  2512. gdth_copy_internal_data(hanum,scp,(char*)&sd,sizeof(gdth_sense_data));
  2513. break;
  2514. case MODE_SENSE:
  2515. TRACE2(("Mode sense hdrive %d\n",t));
  2516. memset((char*)&mpd,0,sizeof(gdth_modep_data));
  2517. mpd.hd.data_length = sizeof(gdth_modep_data);
  2518. mpd.hd.dev_par = (ha->hdr[t].devtype&2) ? 0x80:0;
  2519. mpd.hd.bd_length = sizeof(mpd.bd);
  2520. mpd.bd.block_length[0] = (SECTOR_SIZE & 0x00ff0000) >> 16;
  2521. mpd.bd.block_length[1] = (SECTOR_SIZE & 0x0000ff00) >> 8;
  2522. mpd.bd.block_length[2] = (SECTOR_SIZE & 0x000000ff);
  2523. gdth_copy_internal_data(hanum,scp,(char*)&mpd,sizeof(gdth_modep_data));
  2524. break;
  2525. case READ_CAPACITY:
  2526. TRACE2(("Read capacity hdrive %d\n",t));
  2527. if (ha->hdr[t].size > (ulong64)0xffffffff)
  2528. rdc.last_block_no = 0xffffffff;
  2529. else
  2530. rdc.last_block_no = cpu_to_be32(ha->hdr[t].size-1);
  2531. rdc.block_length = cpu_to_be32(SECTOR_SIZE);
  2532. gdth_copy_internal_data(hanum,scp,(char*)&rdc,sizeof(gdth_rdcap_data));
  2533. break;
  2534. case SERVICE_ACTION_IN:
  2535. if ((scp->cmnd[1] & 0x1f) == SAI_READ_CAPACITY_16 &&
  2536. (ha->cache_feat & GDT_64BIT)) {
  2537. gdth_rdcap16_data rdc16;
  2538. TRACE2(("Read capacity (16) hdrive %d\n",t));
  2539. rdc16.last_block_no = cpu_to_be64(ha->hdr[t].size-1);
  2540. rdc16.block_length = cpu_to_be32(SECTOR_SIZE);
  2541. gdth_copy_internal_data(hanum,scp,(char*)&rdc16,sizeof(gdth_rdcap16_data));
  2542. } else {
  2543. scp->result = DID_ABORT << 16;
  2544. }
  2545. break;
  2546. default:
  2547. TRACE2(("Internal cache cmd 0x%x unknown\n",scp->cmnd[0]));
  2548. break;
  2549. }
  2550. if (!scp->SCp.have_data_in)
  2551. scp->SCp.have_data_in++;
  2552. else
  2553. return 1;
  2554. return 0;
  2555. }
  2556. static int gdth_fill_cache_cmd(int hanum,Scsi_Cmnd *scp,ushort hdrive)
  2557. {
  2558. register gdth_ha_str *ha;
  2559. register gdth_cmd_str *cmdp;
  2560. struct scatterlist *sl;
  2561. ulong32 cnt, blockcnt;
  2562. ulong64 no, blockno;
  2563. dma_addr_t phys_addr;
  2564. int i, cmd_index, read_write, sgcnt, mode64;
  2565. struct page *page;
  2566. ulong offset;
  2567. ha = HADATA(gdth_ctr_tab[hanum]);
  2568. cmdp = ha->pccb;
  2569. TRACE(("gdth_fill_cache_cmd() cmd 0x%x cmdsize %d hdrive %d\n",
  2570. scp->cmnd[0],scp->cmd_len,hdrive));
  2571. if (ha->type==GDT_EISA && ha->cmd_cnt>0)
  2572. return 0;
  2573. mode64 = (ha->cache_feat & GDT_64BIT) ? TRUE : FALSE;
  2574. /* test for READ_16, WRITE_16 if !mode64 ? ---
  2575. not required, should not occur due to error return on
  2576. READ_CAPACITY_16 */
  2577. cmdp->Service = CACHESERVICE;
  2578. cmdp->RequestBuffer = scp;
  2579. /* search free command index */
  2580. if (!(cmd_index=gdth_get_cmd_index(hanum))) {
  2581. TRACE(("GDT: No free command index found\n"));
  2582. return 0;
  2583. }
  2584. /* if it's the first command, set command semaphore */
  2585. if (ha->cmd_cnt == 0)
  2586. gdth_set_sema0(hanum);
  2587. /* fill command */
  2588. read_write = 0;
  2589. if (scp->SCp.sent_command != -1)
  2590. cmdp->OpCode = scp->SCp.sent_command; /* special cache cmd. */
  2591. else if (scp->cmnd[0] == RESERVE)
  2592. cmdp->OpCode = GDT_RESERVE_DRV;
  2593. else if (scp->cmnd[0] == RELEASE)
  2594. cmdp->OpCode = GDT_RELEASE_DRV;
  2595. else if (scp->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
  2596. if (scp->cmnd[4] & 1) /* prevent ? */
  2597. cmdp->OpCode = GDT_MOUNT;
  2598. else if (scp->cmnd[3] & 1) /* removable drive ? */
  2599. cmdp->OpCode = GDT_UNMOUNT;
  2600. else
  2601. cmdp->OpCode = GDT_FLUSH;
  2602. } else if (scp->cmnd[0] == WRITE_6 || scp->cmnd[0] == WRITE_10 ||
  2603. scp->cmnd[0] == WRITE_12 || scp->cmnd[0] == WRITE_16
  2604. ) {
  2605. read_write = 1;
  2606. if (gdth_write_through || ((ha->hdr[hdrive].rw_attribs & 1) &&
  2607. (ha->cache_feat & GDT_WR_THROUGH)))
  2608. cmdp->OpCode = GDT_WRITE_THR;
  2609. else
  2610. cmdp->OpCode = GDT_WRITE;
  2611. } else {
  2612. read_write = 2;
  2613. cmdp->OpCode = GDT_READ;
  2614. }
  2615. cmdp->BoardNode = LOCALBOARD;
  2616. if (mode64) {
  2617. cmdp->u.cache64.DeviceNo = hdrive;
  2618. cmdp->u.cache64.BlockNo = 1;
  2619. cmdp->u.cache64.sg_canz = 0;
  2620. } else {
  2621. cmdp->u.cache.DeviceNo = hdrive;
  2622. cmdp->u.cache.BlockNo = 1;
  2623. cmdp->u.cache.sg_canz = 0;
  2624. }
  2625. if (read_write) {
  2626. if (scp->cmd_len == 16) {
  2627. memcpy(&no, &scp->cmnd[2], sizeof(ulong64));
  2628. blockno = be64_to_cpu(no);
  2629. memcpy(&cnt, &scp->cmnd[10], sizeof(ulong32));
  2630. blockcnt = be32_to_cpu(cnt);
  2631. } else if (scp->cmd_len == 10) {
  2632. memcpy(&no, &scp->cmnd[2], sizeof(ulong32));
  2633. blockno = be32_to_cpu(no);
  2634. memcpy(&cnt, &scp->cmnd[7], sizeof(ushort));
  2635. blockcnt = be16_to_cpu(cnt);
  2636. } else {
  2637. memcpy(&no, &scp->cmnd[0], sizeof(ulong32));
  2638. blockno = be32_to_cpu(no) & 0x001fffffUL;
  2639. blockcnt= scp->cmnd[4]==0 ? 0x100 : scp->cmnd[4];
  2640. }
  2641. if (mode64) {
  2642. cmdp->u.cache64.BlockNo = blockno;
  2643. cmdp->u.cache64.BlockCnt = blockcnt;
  2644. } else {
  2645. cmdp->u.cache.BlockNo = (ulong32)blockno;
  2646. cmdp->u.cache.BlockCnt = blockcnt;
  2647. }
  2648. if (scp->use_sg) {
  2649. sl = (struct scatterlist *)scp->request_buffer;
  2650. sgcnt = scp->use_sg;
  2651. scp->SCp.Status = GDTH_MAP_SG;
  2652. scp->SCp.Message = (read_write == 1 ?
  2653. PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
  2654. sgcnt = pci_map_sg(ha->pdev,sl,scp->use_sg,scp->SCp.Message);
  2655. if (mode64) {
  2656. cmdp->u.cache64.DestAddr= (ulong64)-1;
  2657. cmdp->u.cache64.sg_canz = sgcnt;
  2658. for (i=0; i<sgcnt; ++i,++sl) {
  2659. cmdp->u.cache64.sg_lst[i].sg_ptr = sg_dma_address(sl);
  2660. #ifdef GDTH_DMA_STATISTICS
  2661. if (cmdp->u.cache64.sg_lst[i].sg_ptr > (ulong64)0xffffffff)
  2662. ha->dma64_cnt++;
  2663. else
  2664. ha->dma32_cnt++;
  2665. #endif
  2666. cmdp->u.cache64.sg_lst[i].sg_len = sg_dma_len(sl);
  2667. }
  2668. } else {
  2669. cmdp->u.cache.DestAddr= 0xffffffff;
  2670. cmdp->u.cache.sg_canz = sgcnt;
  2671. for (i=0; i<sgcnt; ++i,++sl) {
  2672. cmdp->u.cache.sg_lst[i].sg_ptr = sg_dma_address(sl);
  2673. #ifdef GDTH_DMA_STATISTICS
  2674. ha->dma32_cnt++;
  2675. #endif
  2676. cmdp->u.cache.sg_lst[i].sg_len = sg_dma_len(sl);
  2677. }
  2678. }
  2679. #ifdef GDTH_STATISTICS
  2680. if (max_sg < (ulong32)sgcnt) {
  2681. max_sg = (ulong32)sgcnt;
  2682. TRACE3(("GDT: max_sg = %d\n",max_sg));
  2683. }
  2684. #endif
  2685. } else if (scp->request_bufflen) {
  2686. scp->SCp.Status = GDTH_MAP_SINGLE;
  2687. scp->SCp.Message = (read_write == 1 ?
  2688. PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
  2689. page = virt_to_page(scp->request_buffer);
  2690. offset = (ulong)scp->request_buffer & ~PAGE_MASK;
  2691. phys_addr = pci_map_page(ha->pdev,page,offset,
  2692. scp->request_bufflen,scp->SCp.Message);
  2693. scp->SCp.dma_handle = phys_addr;
  2694. if (mode64) {
  2695. if (ha->cache_feat & SCATTER_GATHER) {
  2696. cmdp->u.cache64.DestAddr = (ulong64)-1;
  2697. cmdp->u.cache64.sg_canz = 1;
  2698. cmdp->u.cache64.sg_lst[0].sg_ptr = phys_addr;
  2699. cmdp->u.cache64.sg_lst[0].sg_len = scp->request_bufflen;
  2700. cmdp->u.cache64.sg_lst[1].sg_len = 0;
  2701. } else {
  2702. cmdp->u.cache64.DestAddr = phys_addr;
  2703. cmdp->u.cache64.sg_canz= 0;
  2704. }
  2705. } else {
  2706. if (ha->cache_feat & SCATTER_GATHER) {
  2707. cmdp->u.cache.DestAddr = 0xffffffff;
  2708. cmdp->u.cache.sg_canz = 1;
  2709. cmdp->u.cache.sg_lst[0].sg_ptr = phys_addr;
  2710. cmdp->u.cache.sg_lst[0].sg_len = scp->request_bufflen;
  2711. cmdp->u.cache.sg_lst[1].sg_len = 0;
  2712. } else {
  2713. cmdp->u.cache.DestAddr = phys_addr;
  2714. cmdp->u.cache.sg_canz= 0;
  2715. }
  2716. }
  2717. }
  2718. }
  2719. /* evaluate command size, check space */
  2720. if (mode64) {
  2721. TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
  2722. cmdp->u.cache64.DestAddr,cmdp->u.cache64.sg_canz,
  2723. cmdp->u.cache64.sg_lst[0].sg_ptr,
  2724. cmdp->u.cache64.sg_lst[0].sg_len));
  2725. TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
  2726. cmdp->OpCode,cmdp->u.cache64.BlockNo,cmdp->u.cache64.BlockCnt));
  2727. ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) +
  2728. (ushort)cmdp->u.cache64.sg_canz * sizeof(gdth_sg64_str);
  2729. } else {
  2730. TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
  2731. cmdp->u.cache.DestAddr,cmdp->u.cache.sg_canz,
  2732. cmdp->u.cache.sg_lst[0].sg_ptr,
  2733. cmdp->u.cache.sg_lst[0].sg_len));
  2734. TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
  2735. cmdp->OpCode,cmdp->u.cache.BlockNo,cmdp->u.cache.BlockCnt));
  2736. ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) +
  2737. (ushort)cmdp->u.cache.sg_canz * sizeof(gdth_sg_str);
  2738. }
  2739. if (ha->cmd_len & 3)
  2740. ha->cmd_len += (4 - (ha->cmd_len & 3));
  2741. if (ha->cmd_cnt > 0) {
  2742. if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
  2743. ha->ic_all_size) {
  2744. TRACE2(("gdth_fill_cache() DPMEM overflow\n"));
  2745. ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
  2746. return 0;
  2747. }
  2748. }
  2749. /* copy command */
  2750. gdth_copy_command(hanum);
  2751. return cmd_index;
  2752. }
  2753. static int gdth_fill_raw_cmd(int hanum,Scsi_Cmnd *scp,unchar b)
  2754. {
  2755. register gdth_ha_str *ha;
  2756. register gdth_cmd_str *cmdp;
  2757. struct scatterlist *sl;
  2758. ushort i;
  2759. dma_addr_t phys_addr, sense_paddr;
  2760. int cmd_index, sgcnt, mode64;
  2761. unchar t,l;
  2762. struct page *page;
  2763. ulong offset;
  2764. ha = HADATA(gdth_ctr_tab[hanum]);
  2765. t = scp->device->id;
  2766. l = scp->device->lun;
  2767. cmdp = ha->pccb;
  2768. TRACE(("gdth_fill_raw_cmd() cmd 0x%x bus %d ID %d LUN %d\n",
  2769. scp->cmnd[0],b,t,l));
  2770. if (ha->type==GDT_EISA && ha->cmd_cnt>0)
  2771. return 0;
  2772. mode64 = (ha->raw_feat & GDT_64BIT) ? TRUE : FALSE;
  2773. cmdp->Service = SCSIRAWSERVICE;
  2774. cmdp->RequestBuffer = scp;
  2775. /* search free command index */
  2776. if (!(cmd_index=gdth_get_cmd_index(hanum))) {
  2777. TRACE(("GDT: No free command index found\n"));
  2778. return 0;
  2779. }
  2780. /* if it's the first command, set command semaphore */
  2781. if (ha->cmd_cnt == 0)
  2782. gdth_set_sema0(hanum);
  2783. /* fill command */
  2784. if (scp->SCp.sent_command != -1) {
  2785. cmdp->OpCode = scp->SCp.sent_command; /* special raw cmd. */
  2786. cmdp->BoardNode = LOCALBOARD;
  2787. if (mode64) {
  2788. cmdp->u.raw64.direction = (scp->SCp.phase >> 8);
  2789. TRACE2(("special raw cmd 0x%x param 0x%x\n",
  2790. cmdp->OpCode, cmdp->u.raw64.direction));
  2791. /* evaluate command size */
  2792. ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst);
  2793. } else {
  2794. cmdp->u.raw.direction = (scp->SCp.phase >> 8);
  2795. TRACE2(("special raw cmd 0x%x param 0x%x\n",
  2796. cmdp->OpCode, cmdp->u.raw.direction));
  2797. /* evaluate command size */
  2798. ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst);
  2799. }
  2800. } else {
  2801. page = virt_to_page(scp->sense_buffer);
  2802. offset = (ulong)scp->sense_buffer & ~PAGE_MASK;
  2803. sense_paddr = pci_map_page(ha->pdev,page,offset,
  2804. 16,PCI_DMA_FROMDEVICE);
  2805. *(ulong32 *)&scp->SCp.buffer = (ulong32)sense_paddr;
  2806. /* high part, if 64bit */
  2807. *(ulong32 *)&scp->host_scribble = (ulong32)((ulong64)sense_paddr >> 32);
  2808. cmdp->OpCode = GDT_WRITE; /* always */
  2809. cmdp->BoardNode = LOCALBOARD;
  2810. if (mode64) {
  2811. cmdp->u.raw64.reserved = 0;
  2812. cmdp->u.raw64.mdisc_time = 0;
  2813. cmdp->u.raw64.mcon_time = 0;
  2814. cmdp->u.raw64.clen = scp->cmd_len;
  2815. cmdp->u.raw64.target = t;
  2816. cmdp->u.raw64.lun = l;
  2817. cmdp->u.raw64.bus = b;
  2818. cmdp->u.raw64.priority = 0;
  2819. cmdp->u.raw64.sdlen = scp->request_bufflen;
  2820. cmdp->u.raw64.sense_len = 16;
  2821. cmdp->u.raw64.sense_data = sense_paddr;
  2822. cmdp->u.raw64.direction =
  2823. gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN;
  2824. memcpy(cmdp->u.raw64.cmd,scp->cmnd,16);
  2825. cmdp->u.raw64.sg_ranz = 0;
  2826. } else {
  2827. cmdp->u.raw.reserved = 0;
  2828. cmdp->u.raw.mdisc_time = 0;
  2829. cmdp->u.raw.mcon_time = 0;
  2830. cmdp->u.raw.clen = scp->cmd_len;
  2831. cmdp->u.raw.target = t;
  2832. cmdp->u.raw.lun = l;
  2833. cmdp->u.raw.bus = b;
  2834. cmdp->u.raw.priority = 0;
  2835. cmdp->u.raw.link_p = 0;
  2836. cmdp->u.raw.sdlen = scp->request_bufflen;
  2837. cmdp->u.raw.sense_len = 16;
  2838. cmdp->u.raw.sense_data = sense_paddr;
  2839. cmdp->u.raw.direction =
  2840. gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN;
  2841. memcpy(cmdp->u.raw.cmd,scp->cmnd,12);
  2842. cmdp->u.raw.sg_ranz = 0;
  2843. }
  2844. if (scp->use_sg) {
  2845. sl = (struct scatterlist *)scp->request_buffer;
  2846. sgcnt = scp->use_sg;
  2847. scp->SCp.Status = GDTH_MAP_SG;
  2848. scp->SCp.Message = PCI_DMA_BIDIRECTIONAL;
  2849. sgcnt = pci_map_sg(ha->pdev,sl,scp->use_sg,scp->SCp.Message);
  2850. if (mode64) {
  2851. cmdp->u.raw64.sdata = (ulong64)-1;
  2852. cmdp->u.raw64.sg_ranz = sgcnt;
  2853. for (i=0; i<sgcnt; ++i,++sl) {
  2854. cmdp->u.raw64.sg_lst[i].sg_ptr = sg_dma_address(sl);
  2855. #ifdef GDTH_DMA_STATISTICS
  2856. if (cmdp->u.raw64.sg_lst[i].sg_ptr > (ulong64)0xffffffff)
  2857. ha->dma64_cnt++;
  2858. else
  2859. ha->dma32_cnt++;
  2860. #endif
  2861. cmdp->u.raw64.sg_lst[i].sg_len = sg_dma_len(sl);
  2862. }
  2863. } else {
  2864. cmdp->u.raw.sdata = 0xffffffff;
  2865. cmdp->u.raw.sg_ranz = sgcnt;
  2866. for (i=0; i<sgcnt; ++i,++sl) {
  2867. cmdp->u.raw.sg_lst[i].sg_ptr = sg_dma_address(sl);
  2868. #ifdef GDTH_DMA_STATISTICS
  2869. ha->dma32_cnt++;
  2870. #endif
  2871. cmdp->u.raw.sg_lst[i].sg_len = sg_dma_len(sl);
  2872. }
  2873. }
  2874. #ifdef GDTH_STATISTICS
  2875. if (max_sg < sgcnt) {
  2876. max_sg = sgcnt;
  2877. TRACE3(("GDT: max_sg = %d\n",sgcnt));
  2878. }
  2879. #endif
  2880. } else if (scp->request_bufflen) {
  2881. scp->SCp.Status = GDTH_MAP_SINGLE;
  2882. scp->SCp.Message = PCI_DMA_BIDIRECTIONAL;
  2883. page = virt_to_page(scp->request_buffer);
  2884. offset = (ulong)scp->request_buffer & ~PAGE_MASK;
  2885. phys_addr = pci_map_page(ha->pdev,page,offset,
  2886. scp->request_bufflen,scp->SCp.Message);
  2887. scp->SCp.dma_handle = phys_addr;
  2888. if (mode64) {
  2889. if (ha->raw_feat & SCATTER_GATHER) {
  2890. cmdp->u.raw64.sdata = (ulong64)-1;
  2891. cmdp->u.raw64.sg_ranz= 1;
  2892. cmdp->u.raw64.sg_lst[0].sg_ptr = phys_addr;
  2893. cmdp->u.raw64.sg_lst[0].sg_len = scp->request_bufflen;
  2894. cmdp->u.raw64.sg_lst[1].sg_len = 0;
  2895. } else {
  2896. cmdp->u.raw64.sdata = phys_addr;
  2897. cmdp->u.raw64.sg_ranz= 0;
  2898. }
  2899. } else {
  2900. if (ha->raw_feat & SCATTER_GATHER) {
  2901. cmdp->u.raw.sdata = 0xffffffff;
  2902. cmdp->u.raw.sg_ranz= 1;
  2903. cmdp->u.raw.sg_lst[0].sg_ptr = phys_addr;
  2904. cmdp->u.raw.sg_lst[0].sg_len = scp->request_bufflen;
  2905. cmdp->u.raw.sg_lst[1].sg_len = 0;
  2906. } else {
  2907. cmdp->u.raw.sdata = phys_addr;
  2908. cmdp->u.raw.sg_ranz= 0;
  2909. }
  2910. }
  2911. }
  2912. if (mode64) {
  2913. TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
  2914. cmdp->u.raw64.sdata,cmdp->u.raw64.sg_ranz,
  2915. cmdp->u.raw64.sg_lst[0].sg_ptr,
  2916. cmdp->u.raw64.sg_lst[0].sg_len));
  2917. /* evaluate command size */
  2918. ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) +
  2919. (ushort)cmdp->u.raw64.sg_ranz * sizeof(gdth_sg64_str);
  2920. } else {
  2921. TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
  2922. cmdp->u.raw.sdata,cmdp->u.raw.sg_ranz,
  2923. cmdp->u.raw.sg_lst[0].sg_ptr,
  2924. cmdp->u.raw.sg_lst[0].sg_len));
  2925. /* evaluate command size */
  2926. ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) +
  2927. (ushort)cmdp->u.raw.sg_ranz * sizeof(gdth_sg_str);
  2928. }
  2929. }
  2930. /* check space */
  2931. if (ha->cmd_len & 3)
  2932. ha->cmd_len += (4 - (ha->cmd_len & 3));
  2933. if (ha->cmd_cnt > 0) {
  2934. if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
  2935. ha->ic_all_size) {
  2936. TRACE2(("gdth_fill_raw() DPMEM overflow\n"));
  2937. ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
  2938. return 0;
  2939. }
  2940. }
  2941. /* copy command */
  2942. gdth_copy_command(hanum);
  2943. return cmd_index;
  2944. }
  2945. static int gdth_special_cmd(int hanum,Scsi_Cmnd *scp)
  2946. {
  2947. register gdth_ha_str *ha;
  2948. register gdth_cmd_str *cmdp;
  2949. int cmd_index;
  2950. ha = HADATA(gdth_ctr_tab[hanum]);
  2951. cmdp= ha->pccb;
  2952. TRACE2(("gdth_special_cmd(): "));
  2953. if (ha->type==GDT_EISA && ha->cmd_cnt>0)
  2954. return 0;
  2955. memcpy( cmdp, scp->request_buffer, sizeof(gdth_cmd_str));
  2956. cmdp->RequestBuffer = scp;
  2957. /* search free command index */
  2958. if (!(cmd_index=gdth_get_cmd_index(hanum))) {
  2959. TRACE(("GDT: No free command index found\n"));
  2960. return 0;
  2961. }
  2962. /* if it's the first command, set command semaphore */
  2963. if (ha->cmd_cnt == 0)
  2964. gdth_set_sema0(hanum);
  2965. /* evaluate command size, check space */
  2966. if (cmdp->OpCode == GDT_IOCTL) {
  2967. TRACE2(("IOCTL\n"));
  2968. ha->cmd_len =
  2969. GDTOFFSOF(gdth_cmd_str,u.ioctl.p_param) + sizeof(ulong64);
  2970. } else if (cmdp->Service == CACHESERVICE) {
  2971. TRACE2(("cache command %d\n",cmdp->OpCode));
  2972. if (ha->cache_feat & GDT_64BIT)
  2973. ha->cmd_len =
  2974. GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) + sizeof(gdth_sg64_str);
  2975. else
  2976. ha->cmd_len =
  2977. GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) + sizeof(gdth_sg_str);
  2978. } else if (cmdp->Service == SCSIRAWSERVICE) {
  2979. TRACE2(("raw command %d\n",cmdp->OpCode));
  2980. if (ha->raw_feat & GDT_64BIT)
  2981. ha->cmd_len =
  2982. GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) + sizeof(gdth_sg64_str);
  2983. else
  2984. ha->cmd_len =
  2985. GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) + sizeof(gdth_sg_str);
  2986. }
  2987. if (ha->cmd_len & 3)
  2988. ha->cmd_len += (4 - (ha->cmd_len & 3));
  2989. if (ha->cmd_cnt > 0) {
  2990. if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
  2991. ha->ic_all_size) {
  2992. TRACE2(("gdth_special_cmd() DPMEM overflow\n"));
  2993. ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
  2994. return 0;
  2995. }
  2996. }
  2997. /* copy command */
  2998. gdth_copy_command(hanum);
  2999. return cmd_index;
  3000. }
  3001. /* Controller event handling functions */
  3002. static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source,
  3003. ushort idx, gdth_evt_data *evt)
  3004. {
  3005. gdth_evt_str *e;
  3006. struct timeval tv;
  3007. /* no GDTH_LOCK_HA() ! */
  3008. TRACE2(("gdth_store_event() source %d idx %d\n", source, idx));
  3009. if (source == 0) /* no source -> no event */
  3010. return NULL;
  3011. if (ebuffer[elastidx].event_source == source &&
  3012. ebuffer[elastidx].event_idx == idx &&
  3013. ((evt->size != 0 && ebuffer[elastidx].event_data.size != 0 &&
  3014. !memcmp((char *)&ebuffer[elastidx].event_data.eu,
  3015. (char *)&evt->eu, evt->size)) ||
  3016. (evt->size == 0 && ebuffer[elastidx].event_data.size == 0 &&
  3017. !strcmp((char *)&ebuffer[elastidx].event_data.event_string,
  3018. (char *)&evt->event_string)))) {
  3019. e = &ebuffer[elastidx];
  3020. do_gettimeofday(&tv);
  3021. e->last_stamp = tv.tv_sec;
  3022. ++e->same_count;
  3023. } else {
  3024. if (ebuffer[elastidx].event_source != 0) { /* entry not free ? */
  3025. ++elastidx;
  3026. if (elastidx == MAX_EVENTS)
  3027. elastidx = 0;
  3028. if (elastidx == eoldidx) { /* reached mark ? */
  3029. ++eoldidx;
  3030. if (eoldidx == MAX_EVENTS)
  3031. eoldidx = 0;
  3032. }
  3033. }
  3034. e = &ebuffer[elastidx];
  3035. e->event_source = source;
  3036. e->event_idx = idx;
  3037. do_gettimeofday(&tv);
  3038. e->first_stamp = e->last_stamp = tv.tv_sec;
  3039. e->same_count = 1;
  3040. e->event_data = *evt;
  3041. e->application = 0;
  3042. }
  3043. return e;
  3044. }
  3045. static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr)
  3046. {
  3047. gdth_evt_str *e;
  3048. int eindex;
  3049. ulong flags;
  3050. TRACE2(("gdth_read_event() handle %d\n", handle));
  3051. spin_lock_irqsave(&ha->smp_lock, flags);
  3052. if (handle == -1)
  3053. eindex = eoldidx;
  3054. else
  3055. eindex = handle;
  3056. estr->event_source = 0;
  3057. if (eindex >= MAX_EVENTS) {
  3058. spin_unlock_irqrestore(&ha->smp_lock, flags);
  3059. return eindex;
  3060. }
  3061. e = &ebuffer[eindex];
  3062. if (e->event_source != 0) {
  3063. if (eindex != elastidx) {
  3064. if (++eindex == MAX_EVENTS)
  3065. eindex = 0;
  3066. } else {
  3067. eindex = -1;
  3068. }
  3069. memcpy(estr, e, sizeof(gdth_evt_str));
  3070. }
  3071. spin_unlock_irqrestore(&ha->smp_lock, flags);
  3072. return eindex;
  3073. }
  3074. static void gdth_readapp_event(gdth_ha_str *ha,
  3075. unchar application, gdth_evt_str *estr)
  3076. {
  3077. gdth_evt_str *e;
  3078. int eindex;
  3079. ulong flags;
  3080. unchar found = FALSE;
  3081. TRACE2(("gdth_readapp_event() app. %d\n", application));
  3082. spin_lock_irqsave(&ha->smp_lock, flags);
  3083. eindex = eoldidx;
  3084. for (;;) {
  3085. e = &ebuffer[eindex];
  3086. if (e->event_source == 0)
  3087. break;
  3088. if ((e->application & application) == 0) {
  3089. e->application |= application;
  3090. found = TRUE;
  3091. break;
  3092. }
  3093. if (eindex == elastidx)
  3094. break;
  3095. if (++eindex == MAX_EVENTS)
  3096. eindex = 0;
  3097. }
  3098. if (found)
  3099. memcpy(estr, e, sizeof(gdth_evt_str));
  3100. else
  3101. estr->event_source = 0;
  3102. spin_unlock_irqrestore(&ha->smp_lock, flags);
  3103. }
  3104. static void gdth_clear_events(void)
  3105. {
  3106. TRACE(("gdth_clear_events()"));
  3107. eoldidx = elastidx = 0;
  3108. ebuffer[0].event_source = 0;
  3109. }
  3110. /* SCSI interface functions */
  3111. static irqreturn_t gdth_interrupt(int irq,void *dev_id)
  3112. {
  3113. gdth_ha_str *ha2 = (gdth_ha_str *)dev_id;
  3114. register gdth_ha_str *ha;
  3115. gdt6m_dpram_str __iomem *dp6m_ptr = NULL;
  3116. gdt6_dpram_str __iomem *dp6_ptr;
  3117. gdt2_dpram_str __iomem *dp2_ptr;
  3118. Scsi_Cmnd *scp;
  3119. int hanum, rval, i;
  3120. unchar IStatus;
  3121. ushort Service;
  3122. ulong flags = 0;
  3123. #ifdef INT_COAL
  3124. int coalesced = FALSE;
  3125. int next = FALSE;
  3126. gdth_coal_status *pcs = NULL;
  3127. int act_int_coal = 0;
  3128. #endif
  3129. TRACE(("gdth_interrupt() IRQ %d\n",irq));
  3130. /* if polling and not from gdth_wait() -> return */
  3131. if (gdth_polling) {
  3132. if (!gdth_from_wait) {
  3133. return IRQ_HANDLED;
  3134. }
  3135. }
  3136. if (!gdth_polling)
  3137. spin_lock_irqsave(&ha2->smp_lock, flags);
  3138. wait_index = 0;
  3139. /* search controller */
  3140. if ((hanum = gdth_get_status(&IStatus,irq)) == -1) {
  3141. /* spurious interrupt */
  3142. if (!gdth_polling)
  3143. spin_unlock_irqrestore(&ha2->smp_lock, flags);
  3144. return IRQ_HANDLED;
  3145. }
  3146. ha = HADATA(gdth_ctr_tab[hanum]);
  3147. #ifdef GDTH_STATISTICS
  3148. ++act_ints;
  3149. #endif
  3150. #ifdef INT_COAL
  3151. /* See if the fw is returning coalesced status */
  3152. if (IStatus == COALINDEX) {
  3153. /* Coalesced status. Setup the initial status
  3154. buffer pointer and flags */
  3155. pcs = ha->coal_stat;
  3156. coalesced = TRUE;
  3157. next = TRUE;
  3158. }
  3159. do {
  3160. if (coalesced) {
  3161. /* For coalesced requests all status
  3162. information is found in the status buffer */
  3163. IStatus = (unchar)(pcs->status & 0xff);
  3164. }
  3165. #endif
  3166. if (ha->type == GDT_EISA) {
  3167. if (IStatus & 0x80) { /* error flag */
  3168. IStatus &= ~0x80;
  3169. ha->status = inw(ha->bmic + MAILBOXREG+8);
  3170. TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
  3171. } else /* no error */
  3172. ha->status = S_OK;
  3173. ha->info = inl(ha->bmic + MAILBOXREG+12);
  3174. ha->service = inw(ha->bmic + MAILBOXREG+10);
  3175. ha->info2 = inl(ha->bmic + MAILBOXREG+4);
  3176. outb(0xff, ha->bmic + EDOORREG); /* acknowledge interrupt */
  3177. outb(0x00, ha->bmic + SEMA1REG); /* reset status semaphore */
  3178. } else if (ha->type == GDT_ISA) {
  3179. dp2_ptr = ha->brd;
  3180. if (IStatus & 0x80) { /* error flag */
  3181. IStatus &= ~0x80;
  3182. ha->status = gdth_readw(&dp2_ptr->u.ic.Status);
  3183. TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
  3184. } else /* no error */
  3185. ha->status = S_OK;
  3186. ha->info = gdth_readl(&dp2_ptr->u.ic.Info[0]);
  3187. ha->service = gdth_readw(&dp2_ptr->u.ic.Service);
  3188. ha->info2 = gdth_readl(&dp2_ptr->u.ic.Info[1]);
  3189. gdth_writeb(0xff, &dp2_ptr->io.irqdel); /* acknowledge interrupt */
  3190. gdth_writeb(0, &dp2_ptr->u.ic.Cmd_Index);/* reset command index */
  3191. gdth_writeb(0, &dp2_ptr->io.Sema1); /* reset status semaphore */
  3192. } else if (ha->type == GDT_PCI) {
  3193. dp6_ptr = ha->brd;
  3194. if (IStatus & 0x80) { /* error flag */
  3195. IStatus &= ~0x80;
  3196. ha->status = gdth_readw(&dp6_ptr->u.ic.Status);
  3197. TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
  3198. } else /* no error */
  3199. ha->status = S_OK;
  3200. ha->info = gdth_readl(&dp6_ptr->u.ic.Info[0]);
  3201. ha->service = gdth_readw(&dp6_ptr->u.ic.Service);
  3202. ha->info2 = gdth_readl(&dp6_ptr->u.ic.Info[1]);
  3203. gdth_writeb(0xff, &dp6_ptr->io.irqdel); /* acknowledge interrupt */
  3204. gdth_writeb(0, &dp6_ptr->u.ic.Cmd_Index);/* reset command index */
  3205. gdth_writeb(0, &dp6_ptr->io.Sema1); /* reset status semaphore */
  3206. } else if (ha->type == GDT_PCINEW) {
  3207. if (IStatus & 0x80) { /* error flag */
  3208. IStatus &= ~0x80;
  3209. ha->status = inw(PTR2USHORT(&ha->plx->status));
  3210. TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
  3211. } else
  3212. ha->status = S_OK;
  3213. ha->info = inl(PTR2USHORT(&ha->plx->info[0]));
  3214. ha->service = inw(PTR2USHORT(&ha->plx->service));
  3215. ha->info2 = inl(PTR2USHORT(&ha->plx->info[1]));
  3216. outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
  3217. outb(0x00, PTR2USHORT(&ha->plx->sema1_reg));
  3218. } else if (ha->type == GDT_PCIMPR) {
  3219. dp6m_ptr = ha->brd;
  3220. if (IStatus & 0x80) { /* error flag */
  3221. IStatus &= ~0x80;
  3222. #ifdef INT_COAL
  3223. if (coalesced)
  3224. ha->status = pcs->ext_status & 0xffff;
  3225. else
  3226. #endif
  3227. ha->status = gdth_readw(&dp6m_ptr->i960r.status);
  3228. TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
  3229. } else /* no error */
  3230. ha->status = S_OK;
  3231. #ifdef INT_COAL
  3232. /* get information */
  3233. if (coalesced) {
  3234. ha->info = pcs->info0;
  3235. ha->info2 = pcs->info1;
  3236. ha->service = (pcs->ext_status >> 16) & 0xffff;
  3237. } else
  3238. #endif
  3239. {
  3240. ha->info = gdth_readl(&dp6m_ptr->i960r.info[0]);
  3241. ha->service = gdth_readw(&dp6m_ptr->i960r.service);
  3242. ha->info2 = gdth_readl(&dp6m_ptr->i960r.info[1]);
  3243. }
  3244. /* event string */
  3245. if (IStatus == ASYNCINDEX) {
  3246. if (ha->service != SCREENSERVICE &&
  3247. (ha->fw_vers & 0xff) >= 0x1a) {
  3248. ha->dvr.severity = gdth_readb
  3249. (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.severity);
  3250. for (i = 0; i < 256; ++i) {
  3251. ha->dvr.event_string[i] = gdth_readb
  3252. (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.evt_str[i]);
  3253. if (ha->dvr.event_string[i] == 0)
  3254. break;
  3255. }
  3256. }
  3257. }
  3258. #ifdef INT_COAL
  3259. /* Make sure that non coalesced interrupts get cleared
  3260. before being handled by gdth_async_event/gdth_sync_event */
  3261. if (!coalesced)
  3262. #endif
  3263. {
  3264. gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
  3265. gdth_writeb(0, &dp6m_ptr->i960r.sema1_reg);
  3266. }
  3267. } else {
  3268. TRACE2(("gdth_interrupt() unknown controller type\n"));
  3269. if (!gdth_polling)
  3270. spin_unlock_irqrestore(&ha2->smp_lock, flags);
  3271. return IRQ_HANDLED;
  3272. }
  3273. TRACE(("gdth_interrupt() index %d stat %d info %d\n",
  3274. IStatus,ha->status,ha->info));
  3275. if (gdth_from_wait) {
  3276. wait_hanum = hanum;
  3277. wait_index = (int)IStatus;
  3278. }
  3279. if (IStatus == ASYNCINDEX) {
  3280. TRACE2(("gdth_interrupt() async. event\n"));
  3281. gdth_async_event(hanum);
  3282. if (!gdth_polling)
  3283. spin_unlock_irqrestore(&ha2->smp_lock, flags);
  3284. gdth_next(hanum);
  3285. return IRQ_HANDLED;
  3286. }
  3287. if (IStatus == SPEZINDEX) {
  3288. TRACE2(("Service unknown or not initialized !\n"));
  3289. ha->dvr.size = sizeof(ha->dvr.eu.driver);
  3290. ha->dvr.eu.driver.ionode = hanum;
  3291. gdth_store_event(ha, ES_DRIVER, 4, &ha->dvr);
  3292. if (!gdth_polling)
  3293. spin_unlock_irqrestore(&ha2->smp_lock, flags);
  3294. return IRQ_HANDLED;
  3295. }
  3296. scp = ha->cmd_tab[IStatus-2].cmnd;
  3297. Service = ha->cmd_tab[IStatus-2].service;
  3298. ha->cmd_tab[IStatus-2].cmnd = UNUSED_CMND;
  3299. if (scp == UNUSED_CMND) {
  3300. TRACE2(("gdth_interrupt() index to unused command (%d)\n",IStatus));
  3301. ha->dvr.size = sizeof(ha->dvr.eu.driver);
  3302. ha->dvr.eu.driver.ionode = hanum;
  3303. ha->dvr.eu.driver.index = IStatus;
  3304. gdth_store_event(ha, ES_DRIVER, 1, &ha->dvr);
  3305. if (!gdth_polling)
  3306. spin_unlock_irqrestore(&ha2->smp_lock, flags);
  3307. return IRQ_HANDLED;
  3308. }
  3309. if (scp == INTERNAL_CMND) {
  3310. TRACE(("gdth_interrupt() answer to internal command\n"));
  3311. if (!gdth_polling)
  3312. spin_unlock_irqrestore(&ha2->smp_lock, flags);
  3313. return IRQ_HANDLED;
  3314. }
  3315. TRACE(("gdth_interrupt() sync. status\n"));
  3316. rval = gdth_sync_event(hanum,Service,IStatus,scp);
  3317. if (!gdth_polling)
  3318. spin_unlock_irqrestore(&ha2->smp_lock, flags);
  3319. if (rval == 2) {
  3320. gdth_putq(hanum,scp,scp->SCp.this_residual);
  3321. } else if (rval == 1) {
  3322. scp->scsi_done(scp);
  3323. }
  3324. #ifdef INT_COAL
  3325. if (coalesced) {
  3326. /* go to the next status in the status buffer */
  3327. ++pcs;
  3328. #ifdef GDTH_STATISTICS
  3329. ++act_int_coal;
  3330. if (act_int_coal > max_int_coal) {
  3331. max_int_coal = act_int_coal;
  3332. printk("GDT: max_int_coal = %d\n",(ushort)max_int_coal);
  3333. }
  3334. #endif
  3335. /* see if there is another status */
  3336. if (pcs->status == 0)
  3337. /* Stop the coalesce loop */
  3338. next = FALSE;
  3339. }
  3340. } while (next);
  3341. /* coalescing only for new GDT_PCIMPR controllers available */
  3342. if (ha->type == GDT_PCIMPR && coalesced) {
  3343. gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
  3344. gdth_writeb(0, &dp6m_ptr->i960r.sema1_reg);
  3345. }
  3346. #endif
  3347. gdth_next(hanum);
  3348. return IRQ_HANDLED;
  3349. }
  3350. static int gdth_sync_event(int hanum,int service,unchar index,Scsi_Cmnd *scp)
  3351. {
  3352. register gdth_ha_str *ha;
  3353. gdth_msg_str *msg;
  3354. gdth_cmd_str *cmdp;
  3355. unchar b, t;
  3356. ha = HADATA(gdth_ctr_tab[hanum]);
  3357. cmdp = ha->pccb;
  3358. TRACE(("gdth_sync_event() serv %d status %d\n",
  3359. service,ha->status));
  3360. if (service == SCREENSERVICE) {
  3361. msg = ha->pmsg;
  3362. TRACE(("len: %d, answer: %d, ext: %d, alen: %d\n",
  3363. msg->msg_len,msg->msg_answer,msg->msg_ext,msg->msg_alen));
  3364. if (msg->msg_len > MSGLEN+1)
  3365. msg->msg_len = MSGLEN+1;
  3366. if (msg->msg_len)
  3367. if (!(msg->msg_answer && msg->msg_ext)) {
  3368. msg->msg_text[msg->msg_len] = '\0';
  3369. printk("%s",msg->msg_text);
  3370. }
  3371. if (msg->msg_ext && !msg->msg_answer) {
  3372. while (gdth_test_busy(hanum))
  3373. gdth_delay(0);
  3374. cmdp->Service = SCREENSERVICE;
  3375. cmdp->RequestBuffer = SCREEN_CMND;
  3376. gdth_get_cmd_index(hanum);
  3377. gdth_set_sema0(hanum);
  3378. cmdp->OpCode = GDT_READ;
  3379. cmdp->BoardNode = LOCALBOARD;
  3380. cmdp->u.screen.reserved = 0;
  3381. cmdp->u.screen.su.msg.msg_handle= msg->msg_handle;
  3382. cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
  3383. ha->cmd_offs_dpmem = 0;
  3384. ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
  3385. + sizeof(ulong64);
  3386. ha->cmd_cnt = 0;
  3387. gdth_copy_command(hanum);
  3388. gdth_release_event(hanum);
  3389. return 0;
  3390. }
  3391. if (msg->msg_answer && msg->msg_alen) {
  3392. /* default answers (getchar() not possible) */
  3393. if (msg->msg_alen == 1) {
  3394. msg->msg_alen = 0;
  3395. msg->msg_len = 1;
  3396. msg->msg_text[0] = 0;
  3397. } else {
  3398. msg->msg_alen -= 2;
  3399. msg->msg_len = 2;
  3400. msg->msg_text[0] = 1;
  3401. msg->msg_text[1] = 0;
  3402. }
  3403. msg->msg_ext = 0;
  3404. msg->msg_answer = 0;
  3405. while (gdth_test_busy(hanum))
  3406. gdth_delay(0);
  3407. cmdp->Service = SCREENSERVICE;
  3408. cmdp->RequestBuffer = SCREEN_CMND;
  3409. gdth_get_cmd_index(hanum);
  3410. gdth_set_sema0(hanum);
  3411. cmdp->OpCode = GDT_WRITE;
  3412. cmdp->BoardNode = LOCALBOARD;
  3413. cmdp->u.screen.reserved = 0;
  3414. cmdp->u.screen.su.msg.msg_handle= msg->msg_handle;
  3415. cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
  3416. ha->cmd_offs_dpmem = 0;
  3417. ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
  3418. + sizeof(ulong64);
  3419. ha->cmd_cnt = 0;
  3420. gdth_copy_command(hanum);
  3421. gdth_release_event(hanum);
  3422. return 0;
  3423. }
  3424. printk("\n");
  3425. } else {
  3426. b = virt_ctr ? NUMDATA(scp->device->host)->busnum : scp->device->channel;
  3427. t = scp->device->id;
  3428. if (scp->SCp.sent_command == -1 && b != ha->virt_bus) {
  3429. ha->raw[BUS_L2P(ha,b)].io_cnt[t]--;
  3430. }
  3431. /* cache or raw service */
  3432. if (ha->status == S_BSY) {
  3433. TRACE2(("Controller busy -> retry !\n"));
  3434. if (scp->SCp.sent_command == GDT_MOUNT)
  3435. scp->SCp.sent_command = GDT_CLUST_INFO;
  3436. /* retry */
  3437. return 2;
  3438. }
  3439. if (scp->SCp.Status == GDTH_MAP_SG)
  3440. pci_unmap_sg(ha->pdev,scp->request_buffer,
  3441. scp->use_sg,scp->SCp.Message);
  3442. else if (scp->SCp.Status == GDTH_MAP_SINGLE)
  3443. pci_unmap_page(ha->pdev,scp->SCp.dma_handle,
  3444. scp->request_bufflen,scp->SCp.Message);
  3445. if (scp->SCp.buffer) {
  3446. dma_addr_t addr;
  3447. addr = (dma_addr_t)*(ulong32 *)&scp->SCp.buffer;
  3448. if (scp->host_scribble)
  3449. addr += (dma_addr_t)
  3450. ((ulong64)(*(ulong32 *)&scp->host_scribble) << 32);
  3451. pci_unmap_page(ha->pdev,addr,16,PCI_DMA_FROMDEVICE);
  3452. }
  3453. if (ha->status == S_OK) {
  3454. scp->SCp.Status = S_OK;
  3455. scp->SCp.Message = ha->info;
  3456. if (scp->SCp.sent_command != -1) {
  3457. TRACE2(("gdth_sync_event(): special cmd 0x%x OK\n",
  3458. scp->SCp.sent_command));
  3459. /* special commands GDT_CLUST_INFO/GDT_MOUNT ? */
  3460. if (scp->SCp.sent_command == GDT_CLUST_INFO) {
  3461. ha->hdr[t].cluster_type = (unchar)ha->info;
  3462. if (!(ha->hdr[t].cluster_type &
  3463. CLUSTER_MOUNTED)) {
  3464. /* NOT MOUNTED -> MOUNT */
  3465. scp->SCp.sent_command = GDT_MOUNT;
  3466. if (ha->hdr[t].cluster_type &
  3467. CLUSTER_RESERVED) {
  3468. /* cluster drive RESERVED (on the other node) */
  3469. scp->SCp.phase = -2; /* reservation conflict */
  3470. }
  3471. } else {
  3472. scp->SCp.sent_command = -1;
  3473. }
  3474. } else {
  3475. if (scp->SCp.sent_command == GDT_MOUNT) {
  3476. ha->hdr[t].cluster_type |= CLUSTER_MOUNTED;
  3477. ha->hdr[t].media_changed = TRUE;
  3478. } else if (scp->SCp.sent_command == GDT_UNMOUNT) {
  3479. ha->hdr[t].cluster_type &= ~CLUSTER_MOUNTED;
  3480. ha->hdr[t].media_changed = TRUE;
  3481. }
  3482. scp->SCp.sent_command = -1;
  3483. }
  3484. /* retry */
  3485. scp->SCp.this_residual = HIGH_PRI;
  3486. return 2;
  3487. } else {
  3488. /* RESERVE/RELEASE ? */
  3489. if (scp->cmnd[0] == RESERVE) {
  3490. ha->hdr[t].cluster_type |= CLUSTER_RESERVED;
  3491. } else if (scp->cmnd[0] == RELEASE) {
  3492. ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED;
  3493. }
  3494. scp->result = DID_OK << 16;
  3495. scp->sense_buffer[0] = 0;
  3496. }
  3497. } else {
  3498. scp->SCp.Status = ha->status;
  3499. scp->SCp.Message = ha->info;
  3500. if (scp->SCp.sent_command != -1) {
  3501. TRACE2(("gdth_sync_event(): special cmd 0x%x error 0x%x\n",
  3502. scp->SCp.sent_command, ha->status));
  3503. if (scp->SCp.sent_command == GDT_SCAN_START ||
  3504. scp->SCp.sent_command == GDT_SCAN_END) {
  3505. scp->SCp.sent_command = -1;
  3506. /* retry */
  3507. scp->SCp.this_residual = HIGH_PRI;
  3508. return 2;
  3509. }
  3510. memset((char*)scp->sense_buffer,0,16);
  3511. scp->sense_buffer[0] = 0x70;
  3512. scp->sense_buffer[2] = NOT_READY;
  3513. scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
  3514. } else if (service == CACHESERVICE) {
  3515. if (ha->status == S_CACHE_UNKNOWN &&
  3516. (ha->hdr[t].cluster_type &
  3517. CLUSTER_RESERVE_STATE) == CLUSTER_RESERVE_STATE) {
  3518. /* bus reset -> force GDT_CLUST_INFO */
  3519. ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED;
  3520. }
  3521. memset((char*)scp->sense_buffer,0,16);
  3522. if (ha->status == (ushort)S_CACHE_RESERV) {
  3523. scp->result = (DID_OK << 16) | (RESERVATION_CONFLICT << 1);
  3524. } else {
  3525. scp->sense_buffer[0] = 0x70;
  3526. scp->sense_buffer[2] = NOT_READY;
  3527. scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
  3528. }
  3529. if (!IS_GDTH_INTERNAL_CMD(scp)) {
  3530. ha->dvr.size = sizeof(ha->dvr.eu.sync);
  3531. ha->dvr.eu.sync.ionode = hanum;
  3532. ha->dvr.eu.sync.service = service;
  3533. ha->dvr.eu.sync.status = ha->status;
  3534. ha->dvr.eu.sync.info = ha->info;
  3535. ha->dvr.eu.sync.hostdrive = t;
  3536. if (ha->status >= 0x8000)
  3537. gdth_store_event(ha, ES_SYNC, 0, &ha->dvr);
  3538. else
  3539. gdth_store_event(ha, ES_SYNC, service, &ha->dvr);
  3540. }
  3541. } else {
  3542. /* sense buffer filled from controller firmware (DMA) */
  3543. if (ha->status != S_RAW_SCSI || ha->info >= 0x100) {
  3544. scp->result = DID_BAD_TARGET << 16;
  3545. } else {
  3546. scp->result = (DID_OK << 16) | ha->info;
  3547. }
  3548. }
  3549. }
  3550. if (!scp->SCp.have_data_in)
  3551. scp->SCp.have_data_in++;
  3552. else
  3553. return 1;
  3554. }
  3555. return 0;
  3556. }
  3557. static char *async_cache_tab[] = {
  3558. /* 0*/ "\011\000\002\002\002\004\002\006\004"
  3559. "GDT HA %u, service %u, async. status %u/%lu unknown",
  3560. /* 1*/ "\011\000\002\002\002\004\002\006\004"
  3561. "GDT HA %u, service %u, async. status %u/%lu unknown",
  3562. /* 2*/ "\005\000\002\006\004"
  3563. "GDT HA %u, Host Drive %lu not ready",
  3564. /* 3*/ "\005\000\002\006\004"
  3565. "GDT HA %u, Host Drive %lu: REASSIGN not successful and/or data error on reassigned blocks. Drive may crash in the future and should be replaced",
  3566. /* 4*/ "\005\000\002\006\004"
  3567. "GDT HA %u, mirror update on Host Drive %lu failed",
  3568. /* 5*/ "\005\000\002\006\004"
  3569. "GDT HA %u, Mirror Drive %lu failed",
  3570. /* 6*/ "\005\000\002\006\004"
  3571. "GDT HA %u, Mirror Drive %lu: REASSIGN not successful and/or data error on reassigned blocks. Drive may crash in the future and should be replaced",
  3572. /* 7*/ "\005\000\002\006\004"
  3573. "GDT HA %u, Host Drive %lu write protected",
  3574. /* 8*/ "\005\000\002\006\004"
  3575. "GDT HA %u, media changed in Host Drive %lu",
  3576. /* 9*/ "\005\000\002\006\004"
  3577. "GDT HA %u, Host Drive %lu is offline",
  3578. /*10*/ "\005\000\002\006\004"
  3579. "GDT HA %u, media change of Mirror Drive %lu",
  3580. /*11*/ "\005\000\002\006\004"
  3581. "GDT HA %u, Mirror Drive %lu is write protected",
  3582. /*12*/ "\005\000\002\006\004"
  3583. "GDT HA %u, general error on Host Drive %lu. Please check the devices of this drive!",
  3584. /*13*/ "\007\000\002\006\002\010\002"
  3585. "GDT HA %u, Array Drive %u: Cache Drive %u failed",
  3586. /*14*/ "\005\000\002\006\002"
  3587. "GDT HA %u, Array Drive %u: FAIL state entered",
  3588. /*15*/ "\005\000\002\006\002"
  3589. "GDT HA %u, Array Drive %u: error",
  3590. /*16*/ "\007\000\002\006\002\010\002"
  3591. "GDT HA %u, Array Drive %u: failed drive replaced by Cache Drive %u",
  3592. /*17*/ "\005\000\002\006\002"
  3593. "GDT HA %u, Array Drive %u: parity build failed",
  3594. /*18*/ "\005\000\002\006\002"
  3595. "GDT HA %u, Array Drive %u: drive rebuild failed",
  3596. /*19*/ "\005\000\002\010\002"
  3597. "GDT HA %u, Test of Hot Fix %u failed",
  3598. /*20*/ "\005\000\002\006\002"
  3599. "GDT HA %u, Array Drive %u: drive build finished successfully",
  3600. /*21*/ "\005\000\002\006\002"
  3601. "GDT HA %u, Array Drive %u: drive rebuild finished successfully",
  3602. /*22*/ "\007\000\002\006\002\010\002"
  3603. "GDT HA %u, Array Drive %u: Hot Fix %u activated",
  3604. /*23*/ "\005\000\002\006\002"
  3605. "GDT HA %u, Host Drive %u: processing of i/o aborted due to serious drive error",
  3606. /*24*/ "\005\000\002\010\002"
  3607. "GDT HA %u, mirror update on Cache Drive %u completed",
  3608. /*25*/ "\005\000\002\010\002"
  3609. "GDT HA %u, mirror update on Cache Drive %lu failed",
  3610. /*26*/ "\005\000\002\006\002"
  3611. "GDT HA %u, Array Drive %u: drive rebuild started",
  3612. /*27*/ "\005\000\002\012\001"
  3613. "GDT HA %u, Fault bus %u: SHELF OK detected",
  3614. /*28*/ "\005\000\002\012\001"
  3615. "GDT HA %u, Fault bus %u: SHELF not OK detected",
  3616. /*29*/ "\007\000\002\012\001\013\001"
  3617. "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug started",
  3618. /*30*/ "\007\000\002\012\001\013\001"
  3619. "GDT HA %u, Fault bus %u, ID %u: new disk detected",
  3620. /*31*/ "\007\000\002\012\001\013\001"
  3621. "GDT HA %u, Fault bus %u, ID %u: old disk detected",
  3622. /*32*/ "\007\000\002\012\001\013\001"
  3623. "GDT HA %u, Fault bus %u, ID %u: plugging an active disk is invalid",
  3624. /*33*/ "\007\000\002\012\001\013\001"
  3625. "GDT HA %u, Fault bus %u, ID %u: invalid device detected",
  3626. /*34*/ "\011\000\002\012\001\013\001\006\004"
  3627. "GDT HA %u, Fault bus %u, ID %u: insufficient disk capacity (%lu MB required)",
  3628. /*35*/ "\007\000\002\012\001\013\001"
  3629. "GDT HA %u, Fault bus %u, ID %u: disk write protected",
  3630. /*36*/ "\007\000\002\012\001\013\001"
  3631. "GDT HA %u, Fault bus %u, ID %u: disk not available",
  3632. /*37*/ "\007\000\002\012\001\006\004"
  3633. "GDT HA %u, Fault bus %u: swap detected (%lu)",
  3634. /*38*/ "\007\000\002\012\001\013\001"
  3635. "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug finished successfully",
  3636. /*39*/ "\007\000\002\012\001\013\001"
  3637. "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted due to user Hot Plug",
  3638. /*40*/ "\007\000\002\012\001\013\001"
  3639. "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted",
  3640. /*41*/ "\007\000\002\012\001\013\001"
  3641. "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug for Hot Fix started",
  3642. /*42*/ "\005\000\002\006\002"
  3643. "GDT HA %u, Array Drive %u: drive build started",
  3644. /*43*/ "\003\000\002"
  3645. "GDT HA %u, DRAM parity error detected",
  3646. /*44*/ "\005\000\002\006\002"
  3647. "GDT HA %u, Mirror Drive %u: update started",
  3648. /*45*/ "\007\000\002\006\002\010\002"
  3649. "GDT HA %u, Mirror Drive %u: Hot Fix %u activated",
  3650. /*46*/ "\005\000\002\006\002"
  3651. "GDT HA %u, Array Drive %u: no matching Pool Hot Fix Drive available",
  3652. /*47*/ "\005\000\002\006\002"
  3653. "GDT HA %u, Array Drive %u: Pool Hot Fix Drive available",
  3654. /*48*/ "\005\000\002\006\002"
  3655. "GDT HA %u, Mirror Drive %u: no matching Pool Hot Fix Drive available",
  3656. /*49*/ "\005\000\002\006\002"
  3657. "GDT HA %u, Mirror Drive %u: Pool Hot Fix Drive available",
  3658. /*50*/ "\007\000\002\012\001\013\001"
  3659. "GDT HA %u, SCSI bus %u, ID %u: IGNORE_WIDE_RESIDUE message received",
  3660. /*51*/ "\005\000\002\006\002"
  3661. "GDT HA %u, Array Drive %u: expand started",
  3662. /*52*/ "\005\000\002\006\002"
  3663. "GDT HA %u, Array Drive %u: expand finished successfully",
  3664. /*53*/ "\005\000\002\006\002"
  3665. "GDT HA %u, Array Drive %u: expand failed",
  3666. /*54*/ "\003\000\002"
  3667. "GDT HA %u, CPU temperature critical",
  3668. /*55*/ "\003\000\002"
  3669. "GDT HA %u, CPU temperature OK",
  3670. /*56*/ "\005\000\002\006\004"
  3671. "GDT HA %u, Host drive %lu created",
  3672. /*57*/ "\005\000\002\006\002"
  3673. "GDT HA %u, Array Drive %u: expand restarted",
  3674. /*58*/ "\005\000\002\006\002"
  3675. "GDT HA %u, Array Drive %u: expand stopped",
  3676. /*59*/ "\005\000\002\010\002"
  3677. "GDT HA %u, Mirror Drive %u: drive build quited",
  3678. /*60*/ "\005\000\002\006\002"
  3679. "GDT HA %u, Array Drive %u: parity build quited",
  3680. /*61*/ "\005\000\002\006\002"
  3681. "GDT HA %u, Array Drive %u: drive rebuild quited",
  3682. /*62*/ "\005\000\002\006\002"
  3683. "GDT HA %u, Array Drive %u: parity verify started",
  3684. /*63*/ "\005\000\002\006\002"
  3685. "GDT HA %u, Array Drive %u: parity verify done",
  3686. /*64*/ "\005\000\002\006\002"
  3687. "GDT HA %u, Array Drive %u: parity verify failed",
  3688. /*65*/ "\005\000\002\006\002"
  3689. "GDT HA %u, Array Drive %u: parity error detected",
  3690. /*66*/ "\005\000\002\006\002"
  3691. "GDT HA %u, Array Drive %u: parity verify quited",
  3692. /*67*/ "\005\000\002\006\002"
  3693. "GDT HA %u, Host Drive %u reserved",
  3694. /*68*/ "\005\000\002\006\002"
  3695. "GDT HA %u, Host Drive %u mounted and released",
  3696. /*69*/ "\005\000\002\006\002"
  3697. "GDT HA %u, Host Drive %u released",
  3698. /*70*/ "\003\000\002"
  3699. "GDT HA %u, DRAM error detected and corrected with ECC",
  3700. /*71*/ "\003\000\002"
  3701. "GDT HA %u, Uncorrectable DRAM error detected with ECC",
  3702. /*72*/ "\011\000\002\012\001\013\001\014\001"
  3703. "GDT HA %u, SCSI bus %u, ID %u, LUN %u: reassigning block",
  3704. /*73*/ "\005\000\002\006\002"
  3705. "GDT HA %u, Host drive %u resetted locally",
  3706. /*74*/ "\005\000\002\006\002"
  3707. "GDT HA %u, Host drive %u resetted remotely",
  3708. /*75*/ "\003\000\002"
  3709. "GDT HA %u, async. status 75 unknown",
  3710. };
  3711. static int gdth_async_event(int hanum)
  3712. {
  3713. gdth_ha_str *ha;
  3714. gdth_cmd_str *cmdp;
  3715. int cmd_index;
  3716. ha = HADATA(gdth_ctr_tab[hanum]);
  3717. cmdp= ha->pccb;
  3718. TRACE2(("gdth_async_event() ha %d serv %d\n",
  3719. hanum,ha->service));
  3720. if (ha->service == SCREENSERVICE) {
  3721. if (ha->status == MSG_REQUEST) {
  3722. while (gdth_test_busy(hanum))
  3723. gdth_delay(0);
  3724. cmdp->Service = SCREENSERVICE;
  3725. cmdp->RequestBuffer = SCREEN_CMND;
  3726. cmd_index = gdth_get_cmd_index(hanum);
  3727. gdth_set_sema0(hanum);
  3728. cmdp->OpCode = GDT_READ;
  3729. cmdp->BoardNode = LOCALBOARD;
  3730. cmdp->u.screen.reserved = 0;
  3731. cmdp->u.screen.su.msg.msg_handle= MSG_INV_HANDLE;
  3732. cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
  3733. ha->cmd_offs_dpmem = 0;
  3734. ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
  3735. + sizeof(ulong64);
  3736. ha->cmd_cnt = 0;
  3737. gdth_copy_command(hanum);
  3738. if (ha->type == GDT_EISA)
  3739. printk("[EISA slot %d] ",(ushort)ha->brd_phys);
  3740. else if (ha->type == GDT_ISA)
  3741. printk("[DPMEM 0x%4X] ",(ushort)ha->brd_phys);
  3742. else
  3743. printk("[PCI %d/%d] ",(ushort)(ha->brd_phys>>8),
  3744. (ushort)((ha->brd_phys>>3)&0x1f));
  3745. gdth_release_event(hanum);
  3746. }
  3747. } else {
  3748. if (ha->type == GDT_PCIMPR &&
  3749. (ha->fw_vers & 0xff) >= 0x1a) {
  3750. ha->dvr.size = 0;
  3751. ha->dvr.eu.async.ionode = hanum;
  3752. ha->dvr.eu.async.status = ha->status;
  3753. /* severity and event_string already set! */
  3754. } else {
  3755. ha->dvr.size = sizeof(ha->dvr.eu.async);
  3756. ha->dvr.eu.async.ionode = hanum;
  3757. ha->dvr.eu.async.service = ha->service;
  3758. ha->dvr.eu.async.status = ha->status;
  3759. ha->dvr.eu.async.info = ha->info;
  3760. *(ulong32 *)ha->dvr.eu.async.scsi_coord = ha->info2;
  3761. }
  3762. gdth_store_event( ha, ES_ASYNC, ha->service, &ha->dvr );
  3763. gdth_log_event( &ha->dvr, NULL );
  3764. /* new host drive from expand? */
  3765. if (ha->service == CACHESERVICE && ha->status == 56) {
  3766. TRACE2(("gdth_async_event(): new host drive %d created\n",
  3767. (ushort)ha->info));
  3768. /* gdth_analyse_hdrive(hanum, (ushort)ha->info); */
  3769. }
  3770. }
  3771. return 1;
  3772. }
  3773. static void gdth_log_event(gdth_evt_data *dvr, char *buffer)
  3774. {
  3775. gdth_stackframe stack;
  3776. char *f = NULL;
  3777. int i,j;
  3778. TRACE2(("gdth_log_event()\n"));
  3779. if (dvr->size == 0) {
  3780. if (buffer == NULL) {
  3781. printk("Adapter %d: %s\n",dvr->eu.async.ionode,dvr->event_string);
  3782. } else {
  3783. sprintf(buffer,"Adapter %d: %s\n",
  3784. dvr->eu.async.ionode,dvr->event_string);
  3785. }
  3786. } else if (dvr->eu.async.service == CACHESERVICE &&
  3787. INDEX_OK(dvr->eu.async.status, async_cache_tab)) {
  3788. TRACE2(("GDT: Async. event cache service, event no.: %d\n",
  3789. dvr->eu.async.status));
  3790. f = async_cache_tab[dvr->eu.async.status];
  3791. /* i: parameter to push, j: stack element to fill */
  3792. for (j=0,i=1; i < f[0]; i+=2) {
  3793. switch (f[i+1]) {
  3794. case 4:
  3795. stack.b[j++] = *(ulong32*)&dvr->eu.stream[(int)f[i]];
  3796. break;
  3797. case 2:
  3798. stack.b[j++] = *(ushort*)&dvr->eu.stream[(int)f[i]];
  3799. break;
  3800. case 1:
  3801. stack.b[j++] = *(unchar*)&dvr->eu.stream[(int)f[i]];
  3802. break;
  3803. default:
  3804. break;
  3805. }
  3806. }
  3807. if (buffer == NULL) {
  3808. printk(&f[(int)f[0]],stack);
  3809. printk("\n");
  3810. } else {
  3811. sprintf(buffer,&f[(int)f[0]],stack);
  3812. }
  3813. } else {
  3814. if (buffer == NULL) {
  3815. printk("GDT HA %u, Unknown async. event service %d event no. %d\n",
  3816. dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status);
  3817. } else {
  3818. sprintf(buffer,"GDT HA %u, Unknown async. event service %d event no. %d",
  3819. dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status);
  3820. }
  3821. }
  3822. }
  3823. #ifdef GDTH_STATISTICS
  3824. static void gdth_timeout(ulong data)
  3825. {
  3826. ulong32 i;
  3827. Scsi_Cmnd *nscp;
  3828. gdth_ha_str *ha;
  3829. ulong flags;
  3830. int hanum = 0;
  3831. ha = HADATA(gdth_ctr_tab[hanum]);
  3832. spin_lock_irqsave(&ha->smp_lock, flags);
  3833. for (act_stats=0,i=0; i<GDTH_MAXCMDS; ++i)
  3834. if (ha->cmd_tab[i].cmnd != UNUSED_CMND)
  3835. ++act_stats;
  3836. for (act_rq=0,nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr)
  3837. ++act_rq;
  3838. TRACE2(("gdth_to(): ints %d, ios %d, act_stats %d, act_rq %d\n",
  3839. act_ints, act_ios, act_stats, act_rq));
  3840. act_ints = act_ios = 0;
  3841. gdth_timer.expires = jiffies + 30 * HZ;
  3842. add_timer(&gdth_timer);
  3843. spin_unlock_irqrestore(&ha->smp_lock, flags);
  3844. }
  3845. #endif
  3846. static void __init internal_setup(char *str,int *ints)
  3847. {
  3848. int i, argc;
  3849. char *cur_str, *argv;
  3850. TRACE2(("internal_setup() str %s ints[0] %d\n",
  3851. str ? str:"NULL", ints ? ints[0]:0));
  3852. /* read irq[] from ints[] */
  3853. if (ints) {
  3854. argc = ints[0];
  3855. if (argc > 0) {
  3856. if (argc > MAXHA)
  3857. argc = MAXHA;
  3858. for (i = 0; i < argc; ++i)
  3859. irq[i] = ints[i+1];
  3860. }
  3861. }
  3862. /* analyse string */
  3863. argv = str;
  3864. while (argv && (cur_str = strchr(argv, ':'))) {
  3865. int val = 0, c = *++cur_str;
  3866. if (c == 'n' || c == 'N')
  3867. val = 0;
  3868. else if (c == 'y' || c == 'Y')
  3869. val = 1;
  3870. else
  3871. val = (int)simple_strtoul(cur_str, NULL, 0);
  3872. if (!strncmp(argv, "disable:", 8))
  3873. disable = val;
  3874. else if (!strncmp(argv, "reserve_mode:", 13))
  3875. reserve_mode = val;
  3876. else if (!strncmp(argv, "reverse_scan:", 13))
  3877. reverse_scan = val;
  3878. else if (!strncmp(argv, "hdr_channel:", 12))
  3879. hdr_channel = val;
  3880. else if (!strncmp(argv, "max_ids:", 8))
  3881. max_ids = val;
  3882. else if (!strncmp(argv, "rescan:", 7))
  3883. rescan = val;
  3884. else if (!strncmp(argv, "virt_ctr:", 9))
  3885. virt_ctr = val;
  3886. else if (!strncmp(argv, "shared_access:", 14))
  3887. shared_access = val;
  3888. else if (!strncmp(argv, "probe_eisa_isa:", 15))
  3889. probe_eisa_isa = val;
  3890. else if (!strncmp(argv, "reserve_list:", 13)) {
  3891. reserve_list[0] = val;
  3892. for (i = 1; i < MAX_RES_ARGS; i++) {
  3893. cur_str = strchr(cur_str, ',');
  3894. if (!cur_str)
  3895. break;
  3896. if (!isdigit((int)*++cur_str)) {
  3897. --cur_str;
  3898. break;
  3899. }
  3900. reserve_list[i] =
  3901. (int)simple_strtoul(cur_str, NULL, 0);
  3902. }
  3903. if (!cur_str)
  3904. break;
  3905. argv = ++cur_str;
  3906. continue;
  3907. }
  3908. if ((argv = strchr(argv, ',')))
  3909. ++argv;
  3910. }
  3911. }
  3912. int __init option_setup(char *str)
  3913. {
  3914. int ints[MAXHA];
  3915. char *cur = str;
  3916. int i = 1;
  3917. TRACE2(("option_setup() str %s\n", str ? str:"NULL"));
  3918. while (cur && isdigit(*cur) && i <= MAXHA) {
  3919. ints[i++] = simple_strtoul(cur, NULL, 0);
  3920. if ((cur = strchr(cur, ',')) != NULL) cur++;
  3921. }
  3922. ints[0] = i - 1;
  3923. internal_setup(cur, ints);
  3924. return 1;
  3925. }
  3926. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  3927. static int __init gdth_detect(struct scsi_host_template *shtp)
  3928. #else
  3929. static int __init gdth_detect(Scsi_Host_Template *shtp)
  3930. #endif
  3931. {
  3932. struct Scsi_Host *shp;
  3933. gdth_pci_str pcistr[MAXHA];
  3934. gdth_ha_str *ha;
  3935. ulong32 isa_bios;
  3936. ushort eisa_slot;
  3937. int i,hanum,cnt,ctr,err;
  3938. unchar b;
  3939. #ifdef DEBUG_GDTH
  3940. printk("GDT: This driver contains debugging information !! Trace level = %d\n",
  3941. DebugState);
  3942. printk(" Destination of debugging information: ");
  3943. #ifdef __SERIAL__
  3944. #ifdef __COM2__
  3945. printk("Serial port COM2\n");
  3946. #else
  3947. printk("Serial port COM1\n");
  3948. #endif
  3949. #else
  3950. printk("Console\n");
  3951. #endif
  3952. gdth_delay(3000);
  3953. #endif
  3954. TRACE(("gdth_detect()\n"));
  3955. if (disable) {
  3956. printk("GDT-HA: Controller driver disabled from command line !\n");
  3957. return 0;
  3958. }
  3959. printk("GDT-HA: Storage RAID Controller Driver. Version: %s\n",GDTH_VERSION_STR);
  3960. /* initializations */
  3961. gdth_polling = TRUE; b = 0;
  3962. gdth_clear_events();
  3963. /* As default we do not probe for EISA or ISA controllers */
  3964. if (probe_eisa_isa) {
  3965. /* scanning for controllers, at first: ISA controller */
  3966. for (isa_bios=0xc8000UL; isa_bios<=0xd8000UL; isa_bios+=0x8000UL) {
  3967. dma_addr_t scratch_dma_handle;
  3968. scratch_dma_handle = 0;
  3969. if (gdth_ctr_count >= MAXHA)
  3970. break;
  3971. if (gdth_search_isa(isa_bios)) { /* controller found */
  3972. shp = scsi_register(shtp,sizeof(gdth_ext_str));
  3973. if (shp == NULL)
  3974. continue;
  3975. ha = HADATA(shp);
  3976. if (!gdth_init_isa(isa_bios,ha)) {
  3977. scsi_unregister(shp);
  3978. continue;
  3979. }
  3980. #ifdef __ia64__
  3981. break;
  3982. #else
  3983. /* controller found and initialized */
  3984. printk("Configuring GDT-ISA HA at BIOS 0x%05X IRQ %u DRQ %u\n",
  3985. isa_bios,ha->irq,ha->drq);
  3986. if (request_irq(ha->irq,gdth_interrupt,IRQF_DISABLED,"gdth",ha)) {
  3987. printk("GDT-ISA: Unable to allocate IRQ\n");
  3988. scsi_unregister(shp);
  3989. continue;
  3990. }
  3991. if (request_dma(ha->drq,"gdth")) {
  3992. printk("GDT-ISA: Unable to allocate DMA channel\n");
  3993. free_irq(ha->irq,ha);
  3994. scsi_unregister(shp);
  3995. continue;
  3996. }
  3997. set_dma_mode(ha->drq,DMA_MODE_CASCADE);
  3998. enable_dma(ha->drq);
  3999. shp->unchecked_isa_dma = 1;
  4000. shp->irq = ha->irq;
  4001. shp->dma_channel = ha->drq;
  4002. hanum = gdth_ctr_count;
  4003. gdth_ctr_tab[gdth_ctr_count++] = shp;
  4004. gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
  4005. NUMDATA(shp)->hanum = (ushort)hanum;
  4006. NUMDATA(shp)->busnum= 0;
  4007. ha->pccb = CMDDATA(shp);
  4008. ha->ccb_phys = 0L;
  4009. ha->pdev = NULL;
  4010. ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
  4011. &scratch_dma_handle);
  4012. ha->scratch_phys = scratch_dma_handle;
  4013. ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
  4014. &scratch_dma_handle);
  4015. ha->msg_phys = scratch_dma_handle;
  4016. #ifdef INT_COAL
  4017. ha->coal_stat = (gdth_coal_status *)
  4018. pci_alloc_consistent(ha->pdev, sizeof(gdth_coal_status) *
  4019. MAXOFFSETS, &scratch_dma_handle);
  4020. ha->coal_stat_phys = scratch_dma_handle;
  4021. #endif
  4022. ha->scratch_busy = FALSE;
  4023. ha->req_first = NULL;
  4024. ha->tid_cnt = MAX_HDRIVES;
  4025. if (max_ids > 0 && max_ids < ha->tid_cnt)
  4026. ha->tid_cnt = max_ids;
  4027. for (i=0; i<GDTH_MAXCMDS; ++i)
  4028. ha->cmd_tab[i].cmnd = UNUSED_CMND;
  4029. ha->scan_mode = rescan ? 0x10 : 0;
  4030. if (ha->pscratch == NULL || ha->pmsg == NULL ||
  4031. !gdth_search_drives(hanum)) {
  4032. printk("GDT-ISA: Error during device scan\n");
  4033. --gdth_ctr_count;
  4034. --gdth_ctr_vcount;
  4035. #ifdef INT_COAL
  4036. if (ha->coal_stat)
  4037. pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
  4038. MAXOFFSETS, ha->coal_stat,
  4039. ha->coal_stat_phys);
  4040. #endif
  4041. if (ha->pscratch)
  4042. pci_free_consistent(ha->pdev, GDTH_SCRATCH,
  4043. ha->pscratch, ha->scratch_phys);
  4044. if (ha->pmsg)
  4045. pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
  4046. ha->pmsg, ha->msg_phys);
  4047. free_irq(ha->irq,ha);
  4048. scsi_unregister(shp);
  4049. continue;
  4050. }
  4051. if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
  4052. hdr_channel = ha->bus_cnt;
  4053. ha->virt_bus = hdr_channel;
  4054. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) && \
  4055. LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  4056. shp->highmem_io = 0;
  4057. #endif
  4058. if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT)
  4059. shp->max_cmd_len = 16;
  4060. shp->max_id = ha->tid_cnt;
  4061. shp->max_lun = MAXLUN;
  4062. shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
  4063. if (virt_ctr) {
  4064. virt_ctr = 1;
  4065. /* register addit. SCSI channels as virtual controllers */
  4066. for (b = 1; b < ha->bus_cnt + 1; ++b) {
  4067. shp = scsi_register(shtp,sizeof(gdth_num_str));
  4068. shp->unchecked_isa_dma = 1;
  4069. shp->irq = ha->irq;
  4070. shp->dma_channel = ha->drq;
  4071. gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
  4072. NUMDATA(shp)->hanum = (ushort)hanum;
  4073. NUMDATA(shp)->busnum = b;
  4074. }
  4075. }
  4076. spin_lock_init(&ha->smp_lock);
  4077. gdth_enable_int(hanum);
  4078. #endif /* !__ia64__ */
  4079. }
  4080. }
  4081. /* scanning for EISA controllers */
  4082. for (eisa_slot=0x1000; eisa_slot<=0x8000; eisa_slot+=0x1000) {
  4083. dma_addr_t scratch_dma_handle;
  4084. scratch_dma_handle = 0;
  4085. if (gdth_ctr_count >= MAXHA)
  4086. break;
  4087. if (gdth_search_eisa(eisa_slot)) { /* controller found */
  4088. shp = scsi_register(shtp,sizeof(gdth_ext_str));
  4089. if (shp == NULL)
  4090. continue;
  4091. ha = HADATA(shp);
  4092. if (!gdth_init_eisa(eisa_slot,ha)) {
  4093. scsi_unregister(shp);
  4094. continue;
  4095. }
  4096. /* controller found and initialized */
  4097. printk("Configuring GDT-EISA HA at Slot %d IRQ %u\n",
  4098. eisa_slot>>12,ha->irq);
  4099. if (request_irq(ha->irq,gdth_interrupt,IRQF_DISABLED,"gdth",ha)) {
  4100. printk("GDT-EISA: Unable to allocate IRQ\n");
  4101. scsi_unregister(shp);
  4102. continue;
  4103. }
  4104. shp->unchecked_isa_dma = 0;
  4105. shp->irq = ha->irq;
  4106. shp->dma_channel = 0xff;
  4107. hanum = gdth_ctr_count;
  4108. gdth_ctr_tab[gdth_ctr_count++] = shp;
  4109. gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
  4110. NUMDATA(shp)->hanum = (ushort)hanum;
  4111. NUMDATA(shp)->busnum= 0;
  4112. TRACE2(("EISA detect Bus 0: hanum %d\n",
  4113. NUMDATA(shp)->hanum));
  4114. ha->pccb = CMDDATA(shp);
  4115. ha->ccb_phys = 0L;
  4116. ha->pdev = NULL;
  4117. ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
  4118. &scratch_dma_handle);
  4119. ha->scratch_phys = scratch_dma_handle;
  4120. ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
  4121. &scratch_dma_handle);
  4122. ha->msg_phys = scratch_dma_handle;
  4123. #ifdef INT_COAL
  4124. ha->coal_stat = (gdth_coal_status *)
  4125. pci_alloc_consistent(ha->pdev, sizeof(gdth_coal_status) *
  4126. MAXOFFSETS, &scratch_dma_handle);
  4127. ha->coal_stat_phys = scratch_dma_handle;
  4128. #endif
  4129. ha->ccb_phys =
  4130. pci_map_single(ha->pdev,ha->pccb,
  4131. sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
  4132. ha->scratch_busy = FALSE;
  4133. ha->req_first = NULL;
  4134. ha->tid_cnt = MAX_HDRIVES;
  4135. if (max_ids > 0 && max_ids < ha->tid_cnt)
  4136. ha->tid_cnt = max_ids;
  4137. for (i=0; i<GDTH_MAXCMDS; ++i)
  4138. ha->cmd_tab[i].cmnd = UNUSED_CMND;
  4139. ha->scan_mode = rescan ? 0x10 : 0;
  4140. if (ha->pscratch == NULL || ha->pmsg == NULL ||
  4141. !gdth_search_drives(hanum)) {
  4142. printk("GDT-EISA: Error during device scan\n");
  4143. --gdth_ctr_count;
  4144. --gdth_ctr_vcount;
  4145. #ifdef INT_COAL
  4146. if (ha->coal_stat)
  4147. pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
  4148. MAXOFFSETS, ha->coal_stat,
  4149. ha->coal_stat_phys);
  4150. #endif
  4151. if (ha->pscratch)
  4152. pci_free_consistent(ha->pdev, GDTH_SCRATCH,
  4153. ha->pscratch, ha->scratch_phys);
  4154. if (ha->pmsg)
  4155. pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
  4156. ha->pmsg, ha->msg_phys);
  4157. if (ha->ccb_phys)
  4158. pci_unmap_single(ha->pdev,ha->ccb_phys,
  4159. sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
  4160. free_irq(ha->irq,ha);
  4161. scsi_unregister(shp);
  4162. continue;
  4163. }
  4164. if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
  4165. hdr_channel = ha->bus_cnt;
  4166. ha->virt_bus = hdr_channel;
  4167. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) && \
  4168. LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  4169. shp->highmem_io = 0;
  4170. #endif
  4171. if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT)
  4172. shp->max_cmd_len = 16;
  4173. shp->max_id = ha->tid_cnt;
  4174. shp->max_lun = MAXLUN;
  4175. shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
  4176. if (virt_ctr) {
  4177. virt_ctr = 1;
  4178. /* register addit. SCSI channels as virtual controllers */
  4179. for (b = 1; b < ha->bus_cnt + 1; ++b) {
  4180. shp = scsi_register(shtp,sizeof(gdth_num_str));
  4181. shp->unchecked_isa_dma = 0;
  4182. shp->irq = ha->irq;
  4183. shp->dma_channel = 0xff;
  4184. gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
  4185. NUMDATA(shp)->hanum = (ushort)hanum;
  4186. NUMDATA(shp)->busnum = b;
  4187. }
  4188. }
  4189. spin_lock_init(&ha->smp_lock);
  4190. gdth_enable_int(hanum);
  4191. }
  4192. }
  4193. }
  4194. /* scanning for PCI controllers */
  4195. cnt = gdth_search_pci(pcistr);
  4196. printk("GDT-HA: Found %d PCI Storage RAID Controllers\n",cnt);
  4197. gdth_sort_pci(pcistr,cnt);
  4198. for (ctr = 0; ctr < cnt; ++ctr) {
  4199. dma_addr_t scratch_dma_handle;
  4200. scratch_dma_handle = 0;
  4201. if (gdth_ctr_count >= MAXHA)
  4202. break;
  4203. shp = scsi_register(shtp,sizeof(gdth_ext_str));
  4204. if (shp == NULL)
  4205. continue;
  4206. ha = HADATA(shp);
  4207. if (!gdth_init_pci(&pcistr[ctr],ha)) {
  4208. scsi_unregister(shp);
  4209. continue;
  4210. }
  4211. /* controller found and initialized */
  4212. printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n",
  4213. pcistr[ctr].pdev->bus->number,
  4214. PCI_SLOT(pcistr[ctr].pdev->devfn), ha->irq);
  4215. if (request_irq(ha->irq, gdth_interrupt,
  4216. IRQF_DISABLED|IRQF_SHARED, "gdth", ha))
  4217. {
  4218. printk("GDT-PCI: Unable to allocate IRQ\n");
  4219. scsi_unregister(shp);
  4220. continue;
  4221. }
  4222. shp->unchecked_isa_dma = 0;
  4223. shp->irq = ha->irq;
  4224. shp->dma_channel = 0xff;
  4225. hanum = gdth_ctr_count;
  4226. gdth_ctr_tab[gdth_ctr_count++] = shp;
  4227. gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
  4228. NUMDATA(shp)->hanum = (ushort)hanum;
  4229. NUMDATA(shp)->busnum= 0;
  4230. ha->pccb = CMDDATA(shp);
  4231. ha->ccb_phys = 0L;
  4232. ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
  4233. &scratch_dma_handle);
  4234. ha->scratch_phys = scratch_dma_handle;
  4235. ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
  4236. &scratch_dma_handle);
  4237. ha->msg_phys = scratch_dma_handle;
  4238. #ifdef INT_COAL
  4239. ha->coal_stat = (gdth_coal_status *)
  4240. pci_alloc_consistent(ha->pdev, sizeof(gdth_coal_status) *
  4241. MAXOFFSETS, &scratch_dma_handle);
  4242. ha->coal_stat_phys = scratch_dma_handle;
  4243. #endif
  4244. ha->scratch_busy = FALSE;
  4245. ha->req_first = NULL;
  4246. ha->tid_cnt = pcistr[ctr].pdev->device >= 0x200 ? MAXID : MAX_HDRIVES;
  4247. if (max_ids > 0 && max_ids < ha->tid_cnt)
  4248. ha->tid_cnt = max_ids;
  4249. for (i=0; i<GDTH_MAXCMDS; ++i)
  4250. ha->cmd_tab[i].cmnd = UNUSED_CMND;
  4251. ha->scan_mode = rescan ? 0x10 : 0;
  4252. err = FALSE;
  4253. if (ha->pscratch == NULL || ha->pmsg == NULL ||
  4254. !gdth_search_drives(hanum)) {
  4255. err = TRUE;
  4256. } else {
  4257. if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
  4258. hdr_channel = ha->bus_cnt;
  4259. ha->virt_bus = hdr_channel;
  4260. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  4261. scsi_set_pci_device(shp, pcistr[ctr].pdev);
  4262. #endif
  4263. if (!(ha->cache_feat & ha->raw_feat & ha->screen_feat &GDT_64BIT)||
  4264. /* 64-bit DMA only supported from FW >= x.43 */
  4265. (!ha->dma64_support)) {
  4266. if (pci_set_dma_mask(pcistr[ctr].pdev, DMA_32BIT_MASK)) {
  4267. printk(KERN_WARNING "GDT-PCI %d: Unable to set 32-bit DMA\n", hanum);
  4268. err = TRUE;
  4269. }
  4270. } else {
  4271. shp->max_cmd_len = 16;
  4272. if (!pci_set_dma_mask(pcistr[ctr].pdev, DMA_64BIT_MASK)) {
  4273. printk("GDT-PCI %d: 64-bit DMA enabled\n", hanum);
  4274. } else if (pci_set_dma_mask(pcistr[ctr].pdev, DMA_32BIT_MASK)) {
  4275. printk(KERN_WARNING "GDT-PCI %d: Unable to set 64/32-bit DMA\n", hanum);
  4276. err = TRUE;
  4277. }
  4278. }
  4279. }
  4280. if (err) {
  4281. printk("GDT-PCI %d: Error during device scan\n", hanum);
  4282. --gdth_ctr_count;
  4283. --gdth_ctr_vcount;
  4284. #ifdef INT_COAL
  4285. if (ha->coal_stat)
  4286. pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
  4287. MAXOFFSETS, ha->coal_stat,
  4288. ha->coal_stat_phys);
  4289. #endif
  4290. if (ha->pscratch)
  4291. pci_free_consistent(ha->pdev, GDTH_SCRATCH,
  4292. ha->pscratch, ha->scratch_phys);
  4293. if (ha->pmsg)
  4294. pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
  4295. ha->pmsg, ha->msg_phys);
  4296. free_irq(ha->irq,ha);
  4297. scsi_unregister(shp);
  4298. continue;
  4299. }
  4300. shp->max_id = ha->tid_cnt;
  4301. shp->max_lun = MAXLUN;
  4302. shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
  4303. if (virt_ctr) {
  4304. virt_ctr = 1;
  4305. /* register addit. SCSI channels as virtual controllers */
  4306. for (b = 1; b < ha->bus_cnt + 1; ++b) {
  4307. shp = scsi_register(shtp,sizeof(gdth_num_str));
  4308. shp->unchecked_isa_dma = 0;
  4309. shp->irq = ha->irq;
  4310. shp->dma_channel = 0xff;
  4311. gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
  4312. NUMDATA(shp)->hanum = (ushort)hanum;
  4313. NUMDATA(shp)->busnum = b;
  4314. }
  4315. }
  4316. spin_lock_init(&ha->smp_lock);
  4317. gdth_enable_int(hanum);
  4318. }
  4319. TRACE2(("gdth_detect() %d controller detected\n",gdth_ctr_count));
  4320. if (gdth_ctr_count > 0) {
  4321. #ifdef GDTH_STATISTICS
  4322. TRACE2(("gdth_detect(): Initializing timer !\n"));
  4323. init_timer(&gdth_timer);
  4324. gdth_timer.expires = jiffies + HZ;
  4325. gdth_timer.data = 0L;
  4326. gdth_timer.function = gdth_timeout;
  4327. add_timer(&gdth_timer);
  4328. #endif
  4329. major = register_chrdev(0,"gdth",&gdth_fops);
  4330. notifier_disabled = 0;
  4331. register_reboot_notifier(&gdth_notifier);
  4332. }
  4333. gdth_polling = FALSE;
  4334. return gdth_ctr_vcount;
  4335. }
  4336. static int gdth_release(struct Scsi_Host *shp)
  4337. {
  4338. int hanum;
  4339. gdth_ha_str *ha;
  4340. TRACE2(("gdth_release()\n"));
  4341. if (NUMDATA(shp)->busnum == 0) {
  4342. hanum = NUMDATA(shp)->hanum;
  4343. ha = HADATA(gdth_ctr_tab[hanum]);
  4344. if (ha->sdev) {
  4345. scsi_free_host_dev(ha->sdev);
  4346. ha->sdev = NULL;
  4347. }
  4348. gdth_flush(hanum);
  4349. if (shp->irq) {
  4350. free_irq(shp->irq,ha);
  4351. }
  4352. #ifndef __ia64__
  4353. if (shp->dma_channel != 0xff) {
  4354. free_dma(shp->dma_channel);
  4355. }
  4356. #endif
  4357. #ifdef INT_COAL
  4358. if (ha->coal_stat)
  4359. pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
  4360. MAXOFFSETS, ha->coal_stat, ha->coal_stat_phys);
  4361. #endif
  4362. if (ha->pscratch)
  4363. pci_free_consistent(ha->pdev, GDTH_SCRATCH,
  4364. ha->pscratch, ha->scratch_phys);
  4365. if (ha->pmsg)
  4366. pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
  4367. ha->pmsg, ha->msg_phys);
  4368. if (ha->ccb_phys)
  4369. pci_unmap_single(ha->pdev,ha->ccb_phys,
  4370. sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
  4371. gdth_ctr_released++;
  4372. TRACE2(("gdth_release(): HA %d of %d\n",
  4373. gdth_ctr_released, gdth_ctr_count));
  4374. if (gdth_ctr_released == gdth_ctr_count) {
  4375. #ifdef GDTH_STATISTICS
  4376. del_timer(&gdth_timer);
  4377. #endif
  4378. unregister_chrdev(major,"gdth");
  4379. unregister_reboot_notifier(&gdth_notifier);
  4380. }
  4381. }
  4382. scsi_unregister(shp);
  4383. return 0;
  4384. }
  4385. static const char *gdth_ctr_name(int hanum)
  4386. {
  4387. gdth_ha_str *ha;
  4388. TRACE2(("gdth_ctr_name()\n"));
  4389. ha = HADATA(gdth_ctr_tab[hanum]);
  4390. if (ha->type == GDT_EISA) {
  4391. switch (ha->stype) {
  4392. case GDT3_ID:
  4393. return("GDT3000/3020");
  4394. case GDT3A_ID:
  4395. return("GDT3000A/3020A/3050A");
  4396. case GDT3B_ID:
  4397. return("GDT3000B/3010A");
  4398. }
  4399. } else if (ha->type == GDT_ISA) {
  4400. return("GDT2000/2020");
  4401. } else if (ha->type == GDT_PCI) {
  4402. switch (ha->pdev->device) {
  4403. case PCI_DEVICE_ID_VORTEX_GDT60x0:
  4404. return("GDT6000/6020/6050");
  4405. case PCI_DEVICE_ID_VORTEX_GDT6000B:
  4406. return("GDT6000B/6010");
  4407. }
  4408. }
  4409. /* new controllers (GDT_PCINEW, GDT_PCIMPR, ..) use board_info IOCTL! */
  4410. return("");
  4411. }
  4412. static const char *gdth_info(struct Scsi_Host *shp)
  4413. {
  4414. int hanum;
  4415. gdth_ha_str *ha;
  4416. TRACE2(("gdth_info()\n"));
  4417. hanum = NUMDATA(shp)->hanum;
  4418. ha = HADATA(gdth_ctr_tab[hanum]);
  4419. return ((const char *)ha->binfo.type_string);
  4420. }
  4421. static int gdth_eh_bus_reset(Scsi_Cmnd *scp)
  4422. {
  4423. int i, hanum;
  4424. gdth_ha_str *ha;
  4425. ulong flags;
  4426. Scsi_Cmnd *cmnd;
  4427. unchar b;
  4428. TRACE2(("gdth_eh_bus_reset()\n"));
  4429. hanum = NUMDATA(scp->device->host)->hanum;
  4430. b = virt_ctr ? NUMDATA(scp->device->host)->busnum : scp->device->channel;
  4431. ha = HADATA(gdth_ctr_tab[hanum]);
  4432. /* clear command tab */
  4433. spin_lock_irqsave(&ha->smp_lock, flags);
  4434. for (i = 0; i < GDTH_MAXCMDS; ++i) {
  4435. cmnd = ha->cmd_tab[i].cmnd;
  4436. if (!SPECIAL_SCP(cmnd) && cmnd->device->channel == b)
  4437. ha->cmd_tab[i].cmnd = UNUSED_CMND;
  4438. }
  4439. spin_unlock_irqrestore(&ha->smp_lock, flags);
  4440. if (b == ha->virt_bus) {
  4441. /* host drives */
  4442. for (i = 0; i < MAX_HDRIVES; ++i) {
  4443. if (ha->hdr[i].present) {
  4444. spin_lock_irqsave(&ha->smp_lock, flags);
  4445. gdth_polling = TRUE;
  4446. while (gdth_test_busy(hanum))
  4447. gdth_delay(0);
  4448. if (gdth_internal_cmd(hanum, CACHESERVICE,
  4449. GDT_CLUST_RESET, i, 0, 0))
  4450. ha->hdr[i].cluster_type &= ~CLUSTER_RESERVED;
  4451. gdth_polling = FALSE;
  4452. spin_unlock_irqrestore(&ha->smp_lock, flags);
  4453. }
  4454. }
  4455. } else {
  4456. /* raw devices */
  4457. spin_lock_irqsave(&ha->smp_lock, flags);
  4458. for (i = 0; i < MAXID; ++i)
  4459. ha->raw[BUS_L2P(ha,b)].io_cnt[i] = 0;
  4460. gdth_polling = TRUE;
  4461. while (gdth_test_busy(hanum))
  4462. gdth_delay(0);
  4463. gdth_internal_cmd(hanum, SCSIRAWSERVICE, GDT_RESET_BUS,
  4464. BUS_L2P(ha,b), 0, 0);
  4465. gdth_polling = FALSE;
  4466. spin_unlock_irqrestore(&ha->smp_lock, flags);
  4467. }
  4468. return SUCCESS;
  4469. }
  4470. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  4471. static int gdth_bios_param(struct scsi_device *sdev,struct block_device *bdev,sector_t cap,int *ip)
  4472. #else
  4473. static int gdth_bios_param(Disk *disk,kdev_t dev,int *ip)
  4474. #endif
  4475. {
  4476. unchar b, t;
  4477. int hanum;
  4478. gdth_ha_str *ha;
  4479. struct scsi_device *sd;
  4480. unsigned capacity;
  4481. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  4482. sd = sdev;
  4483. capacity = cap;
  4484. #else
  4485. sd = disk->device;
  4486. capacity = disk->capacity;
  4487. #endif
  4488. hanum = NUMDATA(sd->host)->hanum;
  4489. b = virt_ctr ? NUMDATA(sd->host)->busnum : sd->channel;
  4490. t = sd->id;
  4491. TRACE2(("gdth_bios_param() ha %d bus %d target %d\n", hanum, b, t));
  4492. ha = HADATA(gdth_ctr_tab[hanum]);
  4493. if (b != ha->virt_bus || ha->hdr[t].heads == 0) {
  4494. /* raw device or host drive without mapping information */
  4495. TRACE2(("Evaluate mapping\n"));
  4496. gdth_eval_mapping(capacity,&ip[2],&ip[0],&ip[1]);
  4497. } else {
  4498. ip[0] = ha->hdr[t].heads;
  4499. ip[1] = ha->hdr[t].secs;
  4500. ip[2] = capacity / ip[0] / ip[1];
  4501. }
  4502. TRACE2(("gdth_bios_param(): %d heads, %d secs, %d cyls\n",
  4503. ip[0],ip[1],ip[2]));
  4504. return 0;
  4505. }
  4506. static int gdth_queuecommand(Scsi_Cmnd *scp,void (*done)(Scsi_Cmnd *))
  4507. {
  4508. int hanum;
  4509. int priority;
  4510. TRACE(("gdth_queuecommand() cmd 0x%x\n", scp->cmnd[0]));
  4511. scp->scsi_done = (void *)done;
  4512. scp->SCp.have_data_in = 1;
  4513. scp->SCp.phase = -1;
  4514. scp->SCp.sent_command = -1;
  4515. scp->SCp.Status = GDTH_MAP_NONE;
  4516. scp->SCp.buffer = (struct scatterlist *)NULL;
  4517. hanum = NUMDATA(scp->device->host)->hanum;
  4518. #ifdef GDTH_STATISTICS
  4519. ++act_ios;
  4520. #endif
  4521. priority = DEFAULT_PRI;
  4522. if (IS_GDTH_INTERNAL_CMD(scp))
  4523. priority = scp->SCp.this_residual;
  4524. else
  4525. gdth_update_timeout(hanum, scp, scp->timeout_per_command * 6);
  4526. gdth_putq( hanum, scp, priority );
  4527. gdth_next( hanum );
  4528. return 0;
  4529. }
  4530. static int gdth_open(struct inode *inode, struct file *filep)
  4531. {
  4532. gdth_ha_str *ha;
  4533. int i;
  4534. for (i = 0; i < gdth_ctr_count; i++) {
  4535. ha = HADATA(gdth_ctr_tab[i]);
  4536. if (!ha->sdev)
  4537. ha->sdev = scsi_get_host_dev(gdth_ctr_tab[i]);
  4538. }
  4539. TRACE(("gdth_open()\n"));
  4540. return 0;
  4541. }
  4542. static int gdth_close(struct inode *inode, struct file *filep)
  4543. {
  4544. TRACE(("gdth_close()\n"));
  4545. return 0;
  4546. }
  4547. static int ioc_event(void __user *arg)
  4548. {
  4549. gdth_ioctl_event evt;
  4550. gdth_ha_str *ha;
  4551. ulong flags;
  4552. if (copy_from_user(&evt, arg, sizeof(gdth_ioctl_event)) ||
  4553. evt.ionode >= gdth_ctr_count)
  4554. return -EFAULT;
  4555. ha = HADATA(gdth_ctr_tab[evt.ionode]);
  4556. if (evt.erase == 0xff) {
  4557. if (evt.event.event_source == ES_TEST)
  4558. evt.event.event_data.size=sizeof(evt.event.event_data.eu.test);
  4559. else if (evt.event.event_source == ES_DRIVER)
  4560. evt.event.event_data.size=sizeof(evt.event.event_data.eu.driver);
  4561. else if (evt.event.event_source == ES_SYNC)
  4562. evt.event.event_data.size=sizeof(evt.event.event_data.eu.sync);
  4563. else
  4564. evt.event.event_data.size=sizeof(evt.event.event_data.eu.async);
  4565. spin_lock_irqsave(&ha->smp_lock, flags);
  4566. gdth_store_event(ha, evt.event.event_source, evt.event.event_idx,
  4567. &evt.event.event_data);
  4568. spin_unlock_irqrestore(&ha->smp_lock, flags);
  4569. } else if (evt.erase == 0xfe) {
  4570. gdth_clear_events();
  4571. } else if (evt.erase == 0) {
  4572. evt.handle = gdth_read_event(ha, evt.handle, &evt.event);
  4573. } else {
  4574. gdth_readapp_event(ha, evt.erase, &evt.event);
  4575. }
  4576. if (copy_to_user(arg, &evt, sizeof(gdth_ioctl_event)))
  4577. return -EFAULT;
  4578. return 0;
  4579. }
  4580. static int ioc_lockdrv(void __user *arg)
  4581. {
  4582. gdth_ioctl_lockdrv ldrv;
  4583. unchar i, j;
  4584. ulong flags;
  4585. gdth_ha_str *ha;
  4586. if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)) ||
  4587. ldrv.ionode >= gdth_ctr_count)
  4588. return -EFAULT;
  4589. ha = HADATA(gdth_ctr_tab[ldrv.ionode]);
  4590. for (i = 0; i < ldrv.drive_cnt && i < MAX_HDRIVES; ++i) {
  4591. j = ldrv.drives[i];
  4592. if (j >= MAX_HDRIVES || !ha->hdr[j].present)
  4593. continue;
  4594. if (ldrv.lock) {
  4595. spin_lock_irqsave(&ha->smp_lock, flags);
  4596. ha->hdr[j].lock = 1;
  4597. spin_unlock_irqrestore(&ha->smp_lock, flags);
  4598. gdth_wait_completion(ldrv.ionode, ha->bus_cnt, j);
  4599. gdth_stop_timeout(ldrv.ionode, ha->bus_cnt, j);
  4600. } else {
  4601. spin_lock_irqsave(&ha->smp_lock, flags);
  4602. ha->hdr[j].lock = 0;
  4603. spin_unlock_irqrestore(&ha->smp_lock, flags);
  4604. gdth_start_timeout(ldrv.ionode, ha->bus_cnt, j);
  4605. gdth_next(ldrv.ionode);
  4606. }
  4607. }
  4608. return 0;
  4609. }
  4610. static int ioc_resetdrv(void __user *arg, char *cmnd)
  4611. {
  4612. gdth_ioctl_reset res;
  4613. gdth_cmd_str cmd;
  4614. int hanum;
  4615. gdth_ha_str *ha;
  4616. int rval;
  4617. if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
  4618. res.ionode >= gdth_ctr_count || res.number >= MAX_HDRIVES)
  4619. return -EFAULT;
  4620. hanum = res.ionode;
  4621. ha = HADATA(gdth_ctr_tab[hanum]);
  4622. if (!ha->hdr[res.number].present)
  4623. return 0;
  4624. memset(&cmd, 0, sizeof(gdth_cmd_str));
  4625. cmd.Service = CACHESERVICE;
  4626. cmd.OpCode = GDT_CLUST_RESET;
  4627. if (ha->cache_feat & GDT_64BIT)
  4628. cmd.u.cache64.DeviceNo = res.number;
  4629. else
  4630. cmd.u.cache.DeviceNo = res.number;
  4631. rval = __gdth_execute(ha->sdev, &cmd, cmnd, 30, NULL);
  4632. if (rval < 0)
  4633. return rval;
  4634. res.status = rval;
  4635. if (copy_to_user(arg, &res, sizeof(gdth_ioctl_reset)))
  4636. return -EFAULT;
  4637. return 0;
  4638. }
  4639. static int ioc_general(void __user *arg, char *cmnd)
  4640. {
  4641. gdth_ioctl_general gen;
  4642. char *buf = NULL;
  4643. ulong64 paddr;
  4644. int hanum;
  4645. gdth_ha_str *ha;
  4646. int rval;
  4647. if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)) ||
  4648. gen.ionode >= gdth_ctr_count)
  4649. return -EFAULT;
  4650. hanum = gen.ionode;
  4651. ha = HADATA(gdth_ctr_tab[hanum]);
  4652. if (gen.data_len + gen.sense_len != 0) {
  4653. if (!(buf = gdth_ioctl_alloc(hanum, gen.data_len + gen.sense_len,
  4654. FALSE, &paddr)))
  4655. return -EFAULT;
  4656. if (copy_from_user(buf, arg + sizeof(gdth_ioctl_general),
  4657. gen.data_len + gen.sense_len)) {
  4658. gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
  4659. return -EFAULT;
  4660. }
  4661. if (gen.command.OpCode == GDT_IOCTL) {
  4662. gen.command.u.ioctl.p_param = paddr;
  4663. } else if (gen.command.Service == CACHESERVICE) {
  4664. if (ha->cache_feat & GDT_64BIT) {
  4665. /* copy elements from 32-bit IOCTL structure */
  4666. gen.command.u.cache64.BlockCnt = gen.command.u.cache.BlockCnt;
  4667. gen.command.u.cache64.BlockNo = gen.command.u.cache.BlockNo;
  4668. gen.command.u.cache64.DeviceNo = gen.command.u.cache.DeviceNo;
  4669. /* addresses */
  4670. if (ha->cache_feat & SCATTER_GATHER) {
  4671. gen.command.u.cache64.DestAddr = (ulong64)-1;
  4672. gen.command.u.cache64.sg_canz = 1;
  4673. gen.command.u.cache64.sg_lst[0].sg_ptr = paddr;
  4674. gen.command.u.cache64.sg_lst[0].sg_len = gen.data_len;
  4675. gen.command.u.cache64.sg_lst[1].sg_len = 0;
  4676. } else {
  4677. gen.command.u.cache64.DestAddr = paddr;
  4678. gen.command.u.cache64.sg_canz = 0;
  4679. }
  4680. } else {
  4681. if (ha->cache_feat & SCATTER_GATHER) {
  4682. gen.command.u.cache.DestAddr = 0xffffffff;
  4683. gen.command.u.cache.sg_canz = 1;
  4684. gen.command.u.cache.sg_lst[0].sg_ptr = (ulong32)paddr;
  4685. gen.command.u.cache.sg_lst[0].sg_len = gen.data_len;
  4686. gen.command.u.cache.sg_lst[1].sg_len = 0;
  4687. } else {
  4688. gen.command.u.cache.DestAddr = paddr;
  4689. gen.command.u.cache.sg_canz = 0;
  4690. }
  4691. }
  4692. } else if (gen.command.Service == SCSIRAWSERVICE) {
  4693. if (ha->raw_feat & GDT_64BIT) {
  4694. /* copy elements from 32-bit IOCTL structure */
  4695. char cmd[16];
  4696. gen.command.u.raw64.sense_len = gen.command.u.raw.sense_len;
  4697. gen.command.u.raw64.bus = gen.command.u.raw.bus;
  4698. gen.command.u.raw64.lun = gen.command.u.raw.lun;
  4699. gen.command.u.raw64.target = gen.command.u.raw.target;
  4700. memcpy(cmd, gen.command.u.raw.cmd, 16);
  4701. memcpy(gen.command.u.raw64.cmd, cmd, 16);
  4702. gen.command.u.raw64.clen = gen.command.u.raw.clen;
  4703. gen.command.u.raw64.sdlen = gen.command.u.raw.sdlen;
  4704. gen.command.u.raw64.direction = gen.command.u.raw.direction;
  4705. /* addresses */
  4706. if (ha->raw_feat & SCATTER_GATHER) {
  4707. gen.command.u.raw64.sdata = (ulong64)-1;
  4708. gen.command.u.raw64.sg_ranz = 1;
  4709. gen.command.u.raw64.sg_lst[0].sg_ptr = paddr;
  4710. gen.command.u.raw64.sg_lst[0].sg_len = gen.data_len;
  4711. gen.command.u.raw64.sg_lst[1].sg_len = 0;
  4712. } else {
  4713. gen.command.u.raw64.sdata = paddr;
  4714. gen.command.u.raw64.sg_ranz = 0;
  4715. }
  4716. gen.command.u.raw64.sense_data = paddr + gen.data_len;
  4717. } else {
  4718. if (ha->raw_feat & SCATTER_GATHER) {
  4719. gen.command.u.raw.sdata = 0xffffffff;
  4720. gen.command.u.raw.sg_ranz = 1;
  4721. gen.command.u.raw.sg_lst[0].sg_ptr = (ulong32)paddr;
  4722. gen.command.u.raw.sg_lst[0].sg_len = gen.data_len;
  4723. gen.command.u.raw.sg_lst[1].sg_len = 0;
  4724. } else {
  4725. gen.command.u.raw.sdata = paddr;
  4726. gen.command.u.raw.sg_ranz = 0;
  4727. }
  4728. gen.command.u.raw.sense_data = (ulong32)paddr + gen.data_len;
  4729. }
  4730. } else {
  4731. gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
  4732. return -EFAULT;
  4733. }
  4734. }
  4735. rval = __gdth_execute(ha->sdev, &gen.command, cmnd, gen.timeout, &gen.info);
  4736. if (rval < 0)
  4737. return rval;
  4738. gen.status = rval;
  4739. if (copy_to_user(arg + sizeof(gdth_ioctl_general), buf,
  4740. gen.data_len + gen.sense_len)) {
  4741. gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
  4742. return -EFAULT;
  4743. }
  4744. if (copy_to_user(arg, &gen,
  4745. sizeof(gdth_ioctl_general) - sizeof(gdth_cmd_str))) {
  4746. gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
  4747. return -EFAULT;
  4748. }
  4749. gdth_ioctl_free(hanum, gen.data_len+gen.sense_len, buf, paddr);
  4750. return 0;
  4751. }
  4752. static int ioc_hdrlist(void __user *arg, char *cmnd)
  4753. {
  4754. gdth_ioctl_rescan *rsc;
  4755. gdth_cmd_str *cmd;
  4756. gdth_ha_str *ha;
  4757. unchar i;
  4758. int hanum, rc = -ENOMEM;
  4759. u32 cluster_type = 0;
  4760. rsc = kmalloc(sizeof(*rsc), GFP_KERNEL);
  4761. cmd = kmalloc(sizeof(*cmd), GFP_KERNEL);
  4762. if (!rsc || !cmd)
  4763. goto free_fail;
  4764. if (copy_from_user(rsc, arg, sizeof(gdth_ioctl_rescan)) ||
  4765. rsc->ionode >= gdth_ctr_count) {
  4766. rc = -EFAULT;
  4767. goto free_fail;
  4768. }
  4769. hanum = rsc->ionode;
  4770. ha = HADATA(gdth_ctr_tab[hanum]);
  4771. memset(cmd, 0, sizeof(gdth_cmd_str));
  4772. for (i = 0; i < MAX_HDRIVES; ++i) {
  4773. if (!ha->hdr[i].present) {
  4774. rsc->hdr_list[i].bus = 0xff;
  4775. continue;
  4776. }
  4777. rsc->hdr_list[i].bus = ha->virt_bus;
  4778. rsc->hdr_list[i].target = i;
  4779. rsc->hdr_list[i].lun = 0;
  4780. rsc->hdr_list[i].cluster_type = ha->hdr[i].cluster_type;
  4781. if (ha->hdr[i].cluster_type & CLUSTER_DRIVE) {
  4782. cmd->Service = CACHESERVICE;
  4783. cmd->OpCode = GDT_CLUST_INFO;
  4784. if (ha->cache_feat & GDT_64BIT)
  4785. cmd->u.cache64.DeviceNo = i;
  4786. else
  4787. cmd->u.cache.DeviceNo = i;
  4788. if (__gdth_execute(ha->sdev, cmd, cmnd, 30, &cluster_type) == S_OK)
  4789. rsc->hdr_list[i].cluster_type = cluster_type;
  4790. }
  4791. }
  4792. if (copy_to_user(arg, rsc, sizeof(gdth_ioctl_rescan)))
  4793. rc = -EFAULT;
  4794. else
  4795. rc = 0;
  4796. free_fail:
  4797. kfree(rsc);
  4798. kfree(cmd);
  4799. return rc;
  4800. }
  4801. static int ioc_rescan(void __user *arg, char *cmnd)
  4802. {
  4803. gdth_ioctl_rescan *rsc;
  4804. gdth_cmd_str *cmd;
  4805. ushort i, status, hdr_cnt;
  4806. ulong32 info;
  4807. int hanum, cyls, hds, secs;
  4808. int rc = -ENOMEM;
  4809. ulong flags;
  4810. gdth_ha_str *ha;
  4811. rsc = kmalloc(sizeof(*rsc), GFP_KERNEL);
  4812. cmd = kmalloc(sizeof(*cmd), GFP_KERNEL);
  4813. if (!cmd || !rsc)
  4814. goto free_fail;
  4815. if (copy_from_user(rsc, arg, sizeof(gdth_ioctl_rescan)) ||
  4816. rsc->ionode >= gdth_ctr_count) {
  4817. rc = -EFAULT;
  4818. goto free_fail;
  4819. }
  4820. hanum = rsc->ionode;
  4821. ha = HADATA(gdth_ctr_tab[hanum]);
  4822. memset(cmd, 0, sizeof(gdth_cmd_str));
  4823. if (rsc->flag == 0) {
  4824. /* old method: re-init. cache service */
  4825. cmd->Service = CACHESERVICE;
  4826. if (ha->cache_feat & GDT_64BIT) {
  4827. cmd->OpCode = GDT_X_INIT_HOST;
  4828. cmd->u.cache64.DeviceNo = LINUX_OS;
  4829. } else {
  4830. cmd->OpCode = GDT_INIT;
  4831. cmd->u.cache.DeviceNo = LINUX_OS;
  4832. }
  4833. status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
  4834. i = 0;
  4835. hdr_cnt = (status == S_OK ? (ushort)info : 0);
  4836. } else {
  4837. i = rsc->hdr_no;
  4838. hdr_cnt = i + 1;
  4839. }
  4840. for (; i < hdr_cnt && i < MAX_HDRIVES; ++i) {
  4841. cmd->Service = CACHESERVICE;
  4842. cmd->OpCode = GDT_INFO;
  4843. if (ha->cache_feat & GDT_64BIT)
  4844. cmd->u.cache64.DeviceNo = i;
  4845. else
  4846. cmd->u.cache.DeviceNo = i;
  4847. status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
  4848. spin_lock_irqsave(&ha->smp_lock, flags);
  4849. rsc->hdr_list[i].bus = ha->virt_bus;
  4850. rsc->hdr_list[i].target = i;
  4851. rsc->hdr_list[i].lun = 0;
  4852. if (status != S_OK) {
  4853. ha->hdr[i].present = FALSE;
  4854. } else {
  4855. ha->hdr[i].present = TRUE;
  4856. ha->hdr[i].size = info;
  4857. /* evaluate mapping */
  4858. ha->hdr[i].size &= ~SECS32;
  4859. gdth_eval_mapping(ha->hdr[i].size,&cyls,&hds,&secs);
  4860. ha->hdr[i].heads = hds;
  4861. ha->hdr[i].secs = secs;
  4862. /* round size */
  4863. ha->hdr[i].size = cyls * hds * secs;
  4864. }
  4865. spin_unlock_irqrestore(&ha->smp_lock, flags);
  4866. if (status != S_OK)
  4867. continue;
  4868. /* extended info, if GDT_64BIT, for drives > 2 TB */
  4869. /* but we need ha->info2, not yet stored in scp->SCp */
  4870. /* devtype, cluster info, R/W attribs */
  4871. cmd->Service = CACHESERVICE;
  4872. cmd->OpCode = GDT_DEVTYPE;
  4873. if (ha->cache_feat & GDT_64BIT)
  4874. cmd->u.cache64.DeviceNo = i;
  4875. else
  4876. cmd->u.cache.DeviceNo = i;
  4877. status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
  4878. spin_lock_irqsave(&ha->smp_lock, flags);
  4879. ha->hdr[i].devtype = (status == S_OK ? (ushort)info : 0);
  4880. spin_unlock_irqrestore(&ha->smp_lock, flags);
  4881. cmd->Service = CACHESERVICE;
  4882. cmd->OpCode = GDT_CLUST_INFO;
  4883. if (ha->cache_feat & GDT_64BIT)
  4884. cmd->u.cache64.DeviceNo = i;
  4885. else
  4886. cmd->u.cache.DeviceNo = i;
  4887. status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
  4888. spin_lock_irqsave(&ha->smp_lock, flags);
  4889. ha->hdr[i].cluster_type =
  4890. ((status == S_OK && !shared_access) ? (ushort)info : 0);
  4891. spin_unlock_irqrestore(&ha->smp_lock, flags);
  4892. rsc->hdr_list[i].cluster_type = ha->hdr[i].cluster_type;
  4893. cmd->Service = CACHESERVICE;
  4894. cmd->OpCode = GDT_RW_ATTRIBS;
  4895. if (ha->cache_feat & GDT_64BIT)
  4896. cmd->u.cache64.DeviceNo = i;
  4897. else
  4898. cmd->u.cache.DeviceNo = i;
  4899. status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
  4900. spin_lock_irqsave(&ha->smp_lock, flags);
  4901. ha->hdr[i].rw_attribs = (status == S_OK ? (ushort)info : 0);
  4902. spin_unlock_irqrestore(&ha->smp_lock, flags);
  4903. }
  4904. if (copy_to_user(arg, rsc, sizeof(gdth_ioctl_rescan)))
  4905. rc = -EFAULT;
  4906. else
  4907. rc = 0;
  4908. free_fail:
  4909. kfree(rsc);
  4910. kfree(cmd);
  4911. return rc;
  4912. }
  4913. static int gdth_ioctl(struct inode *inode, struct file *filep,
  4914. unsigned int cmd, unsigned long arg)
  4915. {
  4916. gdth_ha_str *ha;
  4917. Scsi_Cmnd *scp;
  4918. ulong flags;
  4919. char cmnd[MAX_COMMAND_SIZE];
  4920. void __user *argp = (void __user *)arg;
  4921. memset(cmnd, 0xff, 12);
  4922. TRACE(("gdth_ioctl() cmd 0x%x\n", cmd));
  4923. switch (cmd) {
  4924. case GDTIOCTL_CTRCNT:
  4925. {
  4926. int cnt = gdth_ctr_count;
  4927. if (put_user(cnt, (int __user *)argp))
  4928. return -EFAULT;
  4929. break;
  4930. }
  4931. case GDTIOCTL_DRVERS:
  4932. {
  4933. int ver = (GDTH_VERSION<<8) | GDTH_SUBVERSION;
  4934. if (put_user(ver, (int __user *)argp))
  4935. return -EFAULT;
  4936. break;
  4937. }
  4938. case GDTIOCTL_OSVERS:
  4939. {
  4940. gdth_ioctl_osvers osv;
  4941. osv.version = (unchar)(LINUX_VERSION_CODE >> 16);
  4942. osv.subversion = (unchar)(LINUX_VERSION_CODE >> 8);
  4943. osv.revision = (ushort)(LINUX_VERSION_CODE & 0xff);
  4944. if (copy_to_user(argp, &osv, sizeof(gdth_ioctl_osvers)))
  4945. return -EFAULT;
  4946. break;
  4947. }
  4948. case GDTIOCTL_CTRTYPE:
  4949. {
  4950. gdth_ioctl_ctrtype ctrt;
  4951. if (copy_from_user(&ctrt, argp, sizeof(gdth_ioctl_ctrtype)) ||
  4952. ctrt.ionode >= gdth_ctr_count)
  4953. return -EFAULT;
  4954. ha = HADATA(gdth_ctr_tab[ctrt.ionode]);
  4955. if (ha->type == GDT_ISA || ha->type == GDT_EISA) {
  4956. ctrt.type = (unchar)((ha->stype>>20) - 0x10);
  4957. } else {
  4958. if (ha->type != GDT_PCIMPR) {
  4959. ctrt.type = (unchar)((ha->stype<<4) + 6);
  4960. } else {
  4961. ctrt.type =
  4962. (ha->oem_id == OEM_ID_INTEL ? 0xfd : 0xfe);
  4963. if (ha->stype >= 0x300)
  4964. ctrt.ext_type = 0x6000 | ha->pdev->subsystem_device;
  4965. else
  4966. ctrt.ext_type = 0x6000 | ha->stype;
  4967. }
  4968. ctrt.device_id = ha->pdev->device;
  4969. ctrt.sub_device_id = ha->pdev->subsystem_device;
  4970. }
  4971. ctrt.info = ha->brd_phys;
  4972. ctrt.oem_id = ha->oem_id;
  4973. if (copy_to_user(argp, &ctrt, sizeof(gdth_ioctl_ctrtype)))
  4974. return -EFAULT;
  4975. break;
  4976. }
  4977. case GDTIOCTL_GENERAL:
  4978. return ioc_general(argp, cmnd);
  4979. case GDTIOCTL_EVENT:
  4980. return ioc_event(argp);
  4981. case GDTIOCTL_LOCKDRV:
  4982. return ioc_lockdrv(argp);
  4983. case GDTIOCTL_LOCKCHN:
  4984. {
  4985. gdth_ioctl_lockchn lchn;
  4986. unchar i, j;
  4987. if (copy_from_user(&lchn, argp, sizeof(gdth_ioctl_lockchn)) ||
  4988. lchn.ionode >= gdth_ctr_count)
  4989. return -EFAULT;
  4990. ha = HADATA(gdth_ctr_tab[lchn.ionode]);
  4991. i = lchn.channel;
  4992. if (i < ha->bus_cnt) {
  4993. if (lchn.lock) {
  4994. spin_lock_irqsave(&ha->smp_lock, flags);
  4995. ha->raw[i].lock = 1;
  4996. spin_unlock_irqrestore(&ha->smp_lock, flags);
  4997. for (j = 0; j < ha->tid_cnt; ++j) {
  4998. gdth_wait_completion(lchn.ionode, i, j);
  4999. gdth_stop_timeout(lchn.ionode, i, j);
  5000. }
  5001. } else {
  5002. spin_lock_irqsave(&ha->smp_lock, flags);
  5003. ha->raw[i].lock = 0;
  5004. spin_unlock_irqrestore(&ha->smp_lock, flags);
  5005. for (j = 0; j < ha->tid_cnt; ++j) {
  5006. gdth_start_timeout(lchn.ionode, i, j);
  5007. gdth_next(lchn.ionode);
  5008. }
  5009. }
  5010. }
  5011. break;
  5012. }
  5013. case GDTIOCTL_RESCAN:
  5014. return ioc_rescan(argp, cmnd);
  5015. case GDTIOCTL_HDRLIST:
  5016. return ioc_hdrlist(argp, cmnd);
  5017. case GDTIOCTL_RESET_BUS:
  5018. {
  5019. gdth_ioctl_reset res;
  5020. int hanum, rval;
  5021. if (copy_from_user(&res, argp, sizeof(gdth_ioctl_reset)) ||
  5022. res.ionode >= gdth_ctr_count)
  5023. return -EFAULT;
  5024. hanum = res.ionode;
  5025. ha = HADATA(gdth_ctr_tab[hanum]);
  5026. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  5027. scp = kzalloc(sizeof(*scp), GFP_KERNEL);
  5028. if (!scp)
  5029. return -ENOMEM;
  5030. scp->device = ha->sdev;
  5031. scp->cmd_len = 12;
  5032. scp->use_sg = 0;
  5033. scp->device->channel = virt_ctr ? 0 : res.number;
  5034. rval = gdth_eh_bus_reset(scp);
  5035. res.status = (rval == SUCCESS ? S_OK : S_GENERR);
  5036. kfree(scp);
  5037. #else
  5038. scp = scsi_allocate_device(ha->sdev, 1, FALSE);
  5039. if (!scp)
  5040. return -ENOMEM;
  5041. scp->cmd_len = 12;
  5042. scp->use_sg = 0;
  5043. scp->channel = virt_ctr ? 0 : res.number;
  5044. rval = gdth_eh_bus_reset(scp);
  5045. res.status = (rval == SUCCESS ? S_OK : S_GENERR);
  5046. scsi_release_command(scp);
  5047. #endif
  5048. if (copy_to_user(argp, &res, sizeof(gdth_ioctl_reset)))
  5049. return -EFAULT;
  5050. break;
  5051. }
  5052. case GDTIOCTL_RESET_DRV:
  5053. return ioc_resetdrv(argp, cmnd);
  5054. default:
  5055. break;
  5056. }
  5057. return 0;
  5058. }
  5059. /* flush routine */
  5060. static void gdth_flush(int hanum)
  5061. {
  5062. int i;
  5063. gdth_ha_str *ha;
  5064. gdth_cmd_str gdtcmd;
  5065. char cmnd[MAX_COMMAND_SIZE];
  5066. memset(cmnd, 0xff, MAX_COMMAND_SIZE);
  5067. TRACE2(("gdth_flush() hanum %d\n",hanum));
  5068. ha = HADATA(gdth_ctr_tab[hanum]);
  5069. for (i = 0; i < MAX_HDRIVES; ++i) {
  5070. if (ha->hdr[i].present) {
  5071. gdtcmd.BoardNode = LOCALBOARD;
  5072. gdtcmd.Service = CACHESERVICE;
  5073. gdtcmd.OpCode = GDT_FLUSH;
  5074. if (ha->cache_feat & GDT_64BIT) {
  5075. gdtcmd.u.cache64.DeviceNo = i;
  5076. gdtcmd.u.cache64.BlockNo = 1;
  5077. gdtcmd.u.cache64.sg_canz = 0;
  5078. } else {
  5079. gdtcmd.u.cache.DeviceNo = i;
  5080. gdtcmd.u.cache.BlockNo = 1;
  5081. gdtcmd.u.cache.sg_canz = 0;
  5082. }
  5083. TRACE2(("gdth_flush(): flush ha %d drive %d\n", hanum, i));
  5084. gdth_execute(gdth_ctr_tab[hanum], &gdtcmd, cmnd, 30, NULL);
  5085. }
  5086. }
  5087. }
  5088. /* shutdown routine */
  5089. static int gdth_halt(struct notifier_block *nb, ulong event, void *buf)
  5090. {
  5091. int hanum;
  5092. #ifndef __alpha__
  5093. gdth_cmd_str gdtcmd;
  5094. char cmnd[MAX_COMMAND_SIZE];
  5095. #endif
  5096. if (notifier_disabled)
  5097. return NOTIFY_OK;
  5098. TRACE2(("gdth_halt() event %d\n",(int)event));
  5099. if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
  5100. return NOTIFY_DONE;
  5101. notifier_disabled = 1;
  5102. printk("GDT-HA: Flushing all host drives .. ");
  5103. for (hanum = 0; hanum < gdth_ctr_count; ++hanum) {
  5104. gdth_flush(hanum);
  5105. #ifndef __alpha__
  5106. /* controller reset */
  5107. memset(cmnd, 0xff, MAX_COMMAND_SIZE);
  5108. gdtcmd.BoardNode = LOCALBOARD;
  5109. gdtcmd.Service = CACHESERVICE;
  5110. gdtcmd.OpCode = GDT_RESET;
  5111. TRACE2(("gdth_halt(): reset controller %d\n", hanum));
  5112. gdth_execute(gdth_ctr_tab[hanum], &gdtcmd, cmnd, 10, NULL);
  5113. #endif
  5114. }
  5115. printk("Done.\n");
  5116. #ifdef GDTH_STATISTICS
  5117. del_timer(&gdth_timer);
  5118. #endif
  5119. return NOTIFY_OK;
  5120. }
  5121. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  5122. /* configure lun */
  5123. static int gdth_slave_configure(struct scsi_device *sdev)
  5124. {
  5125. scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
  5126. sdev->skip_ms_page_3f = 1;
  5127. sdev->skip_ms_page_8 = 1;
  5128. return 0;
  5129. }
  5130. #endif
  5131. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  5132. static struct scsi_host_template driver_template = {
  5133. #else
  5134. static Scsi_Host_Template driver_template = {
  5135. #endif
  5136. .proc_name = "gdth",
  5137. .proc_info = gdth_proc_info,
  5138. .name = "GDT SCSI Disk Array Controller",
  5139. .detect = gdth_detect,
  5140. .release = gdth_release,
  5141. .info = gdth_info,
  5142. .queuecommand = gdth_queuecommand,
  5143. .eh_bus_reset_handler = gdth_eh_bus_reset,
  5144. .bios_param = gdth_bios_param,
  5145. .can_queue = GDTH_MAXCMDS,
  5146. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  5147. .slave_configure = gdth_slave_configure,
  5148. #endif
  5149. .this_id = -1,
  5150. .sg_tablesize = GDTH_MAXSG,
  5151. .cmd_per_lun = GDTH_MAXC_P_L,
  5152. .unchecked_isa_dma = 1,
  5153. .use_clustering = ENABLE_CLUSTERING,
  5154. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  5155. .use_new_eh_code = 1,
  5156. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
  5157. .highmem_io = 1,
  5158. #endif
  5159. #endif
  5160. };
  5161. #include "scsi_module.c"
  5162. #ifndef MODULE
  5163. __setup("gdth=", option_setup);
  5164. #endif