gdth.c 174 KB

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