gdth.c 175 KB

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