gdth.c 175 KB

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