gdth.c 201 KB

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