gdth.c 175 KB

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