gdth.c 174 KB

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