advansys.c 375 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858
  1. #define DRV_NAME "advansys"
  2. #define ASC_VERSION "3.4" /* AdvanSys Driver Version */
  3. /*
  4. * advansys.c - Linux Host Driver for AdvanSys SCSI Adapters
  5. *
  6. * Copyright (c) 1995-2000 Advanced System Products, Inc.
  7. * Copyright (c) 2000-2001 ConnectCom Solutions, Inc.
  8. * Copyright (c) 2007 Matthew Wilcox <matthew@wil.cx>
  9. * All Rights Reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. */
  16. /*
  17. * As of March 8, 2000 Advanced System Products, Inc. (AdvanSys)
  18. * changed its name to ConnectCom Solutions, Inc.
  19. * On June 18, 2001 Initio Corp. acquired ConnectCom's SCSI assets
  20. */
  21. #include <linux/module.h>
  22. #include <linux/string.h>
  23. #include <linux/kernel.h>
  24. #include <linux/types.h>
  25. #include <linux/ioport.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/delay.h>
  28. #include <linux/slab.h>
  29. #include <linux/mm.h>
  30. #include <linux/proc_fs.h>
  31. #include <linux/init.h>
  32. #include <linux/blkdev.h>
  33. #include <linux/isa.h>
  34. #include <linux/eisa.h>
  35. #include <linux/pci.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/dma-mapping.h>
  38. #include <linux/firmware.h>
  39. #include <asm/io.h>
  40. #include <asm/dma.h>
  41. #include <scsi/scsi_cmnd.h>
  42. #include <scsi/scsi_device.h>
  43. #include <scsi/scsi_tcq.h>
  44. #include <scsi/scsi.h>
  45. #include <scsi/scsi_host.h>
  46. /* FIXME:
  47. *
  48. * 1. Although all of the necessary command mapping places have the
  49. * appropriate dma_map.. APIs, the driver still processes its internal
  50. * queue using bus_to_virt() and virt_to_bus() which are illegal under
  51. * the API. The entire queue processing structure will need to be
  52. * altered to fix this.
  53. * 2. Need to add memory mapping workaround. Test the memory mapping.
  54. * If it doesn't work revert to I/O port access. Can a test be done
  55. * safely?
  56. * 3. Handle an interrupt not working. Keep an interrupt counter in
  57. * the interrupt handler. In the timeout function if the interrupt
  58. * has not occurred then print a message and run in polled mode.
  59. * 4. Need to add support for target mode commands, cf. CAM XPT.
  60. * 5. check DMA mapping functions for failure
  61. * 6. Use scsi_transport_spi
  62. * 7. advansys_info is not safe against multiple simultaneous callers
  63. * 8. Add module_param to override ISA/VLB ioport array
  64. */
  65. #warning this driver is still not properly converted to the DMA API
  66. /* Enable driver /proc statistics. */
  67. #define ADVANSYS_STATS
  68. /* Enable driver tracing. */
  69. #undef ADVANSYS_DEBUG
  70. /*
  71. * Portable Data Types
  72. *
  73. * Any instance where a 32-bit long or pointer type is assumed
  74. * for precision or HW defined structures, the following define
  75. * types must be used. In Linux the char, short, and int types
  76. * are all consistent at 8, 16, and 32 bits respectively. Pointers
  77. * and long types are 64 bits on Alpha and UltraSPARC.
  78. */
  79. #define ASC_PADDR __u32 /* Physical/Bus address data type. */
  80. #define ASC_VADDR __u32 /* Virtual address data type. */
  81. #define ASC_DCNT __u32 /* Unsigned Data count type. */
  82. #define ASC_SDCNT __s32 /* Signed Data count type. */
  83. typedef unsigned char uchar;
  84. #ifndef TRUE
  85. #define TRUE (1)
  86. #endif
  87. #ifndef FALSE
  88. #define FALSE (0)
  89. #endif
  90. #define ERR (-1)
  91. #define UW_ERR (uint)(0xFFFF)
  92. #define isodd_word(val) ((((uint)val) & (uint)0x0001) != 0)
  93. #define PCI_VENDOR_ID_ASP 0x10cd
  94. #define PCI_DEVICE_ID_ASP_1200A 0x1100
  95. #define PCI_DEVICE_ID_ASP_ABP940 0x1200
  96. #define PCI_DEVICE_ID_ASP_ABP940U 0x1300
  97. #define PCI_DEVICE_ID_ASP_ABP940UW 0x2300
  98. #define PCI_DEVICE_ID_38C0800_REV1 0x2500
  99. #define PCI_DEVICE_ID_38C1600_REV1 0x2700
  100. /*
  101. * Enable CC_VERY_LONG_SG_LIST to support up to 64K element SG lists.
  102. * The SRB structure will have to be changed and the ASC_SRB2SCSIQ()
  103. * macro re-defined to be able to obtain a ASC_SCSI_Q pointer from the
  104. * SRB structure.
  105. */
  106. #define CC_VERY_LONG_SG_LIST 0
  107. #define ASC_SRB2SCSIQ(srb_ptr) (srb_ptr)
  108. #define PortAddr unsigned int /* port address size */
  109. #define inp(port) inb(port)
  110. #define outp(port, byte) outb((byte), (port))
  111. #define inpw(port) inw(port)
  112. #define outpw(port, word) outw((word), (port))
  113. #define ASC_MAX_SG_QUEUE 7
  114. #define ASC_MAX_SG_LIST 255
  115. #define ASC_CS_TYPE unsigned short
  116. #define ASC_IS_ISA (0x0001)
  117. #define ASC_IS_ISAPNP (0x0081)
  118. #define ASC_IS_EISA (0x0002)
  119. #define ASC_IS_PCI (0x0004)
  120. #define ASC_IS_PCI_ULTRA (0x0104)
  121. #define ASC_IS_PCMCIA (0x0008)
  122. #define ASC_IS_MCA (0x0020)
  123. #define ASC_IS_VL (0x0040)
  124. #define ASC_IS_WIDESCSI_16 (0x0100)
  125. #define ASC_IS_WIDESCSI_32 (0x0200)
  126. #define ASC_IS_BIG_ENDIAN (0x8000)
  127. #define ASC_CHIP_MIN_VER_VL (0x01)
  128. #define ASC_CHIP_MAX_VER_VL (0x07)
  129. #define ASC_CHIP_MIN_VER_PCI (0x09)
  130. #define ASC_CHIP_MAX_VER_PCI (0x0F)
  131. #define ASC_CHIP_VER_PCI_BIT (0x08)
  132. #define ASC_CHIP_MIN_VER_ISA (0x11)
  133. #define ASC_CHIP_MIN_VER_ISA_PNP (0x21)
  134. #define ASC_CHIP_MAX_VER_ISA (0x27)
  135. #define ASC_CHIP_VER_ISA_BIT (0x30)
  136. #define ASC_CHIP_VER_ISAPNP_BIT (0x20)
  137. #define ASC_CHIP_VER_ASYN_BUG (0x21)
  138. #define ASC_CHIP_VER_PCI 0x08
  139. #define ASC_CHIP_VER_PCI_ULTRA_3150 (ASC_CHIP_VER_PCI | 0x02)
  140. #define ASC_CHIP_VER_PCI_ULTRA_3050 (ASC_CHIP_VER_PCI | 0x03)
  141. #define ASC_CHIP_MIN_VER_EISA (0x41)
  142. #define ASC_CHIP_MAX_VER_EISA (0x47)
  143. #define ASC_CHIP_VER_EISA_BIT (0x40)
  144. #define ASC_CHIP_LATEST_VER_EISA ((ASC_CHIP_MIN_VER_EISA - 1) + 3)
  145. #define ASC_MAX_VL_DMA_COUNT (0x07FFFFFFL)
  146. #define ASC_MAX_PCI_DMA_COUNT (0xFFFFFFFFL)
  147. #define ASC_MAX_ISA_DMA_COUNT (0x00FFFFFFL)
  148. #define ASC_SCSI_ID_BITS 3
  149. #define ASC_SCSI_TIX_TYPE uchar
  150. #define ASC_ALL_DEVICE_BIT_SET 0xFF
  151. #define ASC_SCSI_BIT_ID_TYPE uchar
  152. #define ASC_MAX_TID 7
  153. #define ASC_MAX_LUN 7
  154. #define ASC_SCSI_WIDTH_BIT_SET 0xFF
  155. #define ASC_MAX_SENSE_LEN 32
  156. #define ASC_MIN_SENSE_LEN 14
  157. #define ASC_SCSI_RESET_HOLD_TIME_US 60
  158. /*
  159. * Narrow boards only support 12-byte commands, while wide boards
  160. * extend to 16-byte commands.
  161. */
  162. #define ASC_MAX_CDB_LEN 12
  163. #define ADV_MAX_CDB_LEN 16
  164. #define MS_SDTR_LEN 0x03
  165. #define MS_WDTR_LEN 0x02
  166. #define ASC_SG_LIST_PER_Q 7
  167. #define QS_FREE 0x00
  168. #define QS_READY 0x01
  169. #define QS_DISC1 0x02
  170. #define QS_DISC2 0x04
  171. #define QS_BUSY 0x08
  172. #define QS_ABORTED 0x40
  173. #define QS_DONE 0x80
  174. #define QC_NO_CALLBACK 0x01
  175. #define QC_SG_SWAP_QUEUE 0x02
  176. #define QC_SG_HEAD 0x04
  177. #define QC_DATA_IN 0x08
  178. #define QC_DATA_OUT 0x10
  179. #define QC_URGENT 0x20
  180. #define QC_MSG_OUT 0x40
  181. #define QC_REQ_SENSE 0x80
  182. #define QCSG_SG_XFER_LIST 0x02
  183. #define QCSG_SG_XFER_MORE 0x04
  184. #define QCSG_SG_XFER_END 0x08
  185. #define QD_IN_PROGRESS 0x00
  186. #define QD_NO_ERROR 0x01
  187. #define QD_ABORTED_BY_HOST 0x02
  188. #define QD_WITH_ERROR 0x04
  189. #define QD_INVALID_REQUEST 0x80
  190. #define QD_INVALID_HOST_NUM 0x81
  191. #define QD_INVALID_DEVICE 0x82
  192. #define QD_ERR_INTERNAL 0xFF
  193. #define QHSTA_NO_ERROR 0x00
  194. #define QHSTA_M_SEL_TIMEOUT 0x11
  195. #define QHSTA_M_DATA_OVER_RUN 0x12
  196. #define QHSTA_M_DATA_UNDER_RUN 0x12
  197. #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
  198. #define QHSTA_M_BAD_BUS_PHASE_SEQ 0x14
  199. #define QHSTA_D_QDONE_SG_LIST_CORRUPTED 0x21
  200. #define QHSTA_D_ASC_DVC_ERROR_CODE_SET 0x22
  201. #define QHSTA_D_HOST_ABORT_FAILED 0x23
  202. #define QHSTA_D_EXE_SCSI_Q_FAILED 0x24
  203. #define QHSTA_D_EXE_SCSI_Q_BUSY_TIMEOUT 0x25
  204. #define QHSTA_D_ASPI_NO_BUF_POOL 0x26
  205. #define QHSTA_M_WTM_TIMEOUT 0x41
  206. #define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
  207. #define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
  208. #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
  209. #define QHSTA_M_TARGET_STATUS_BUSY 0x45
  210. #define QHSTA_M_BAD_TAG_CODE 0x46
  211. #define QHSTA_M_BAD_QUEUE_FULL_OR_BUSY 0x47
  212. #define QHSTA_M_HUNG_REQ_SCSI_BUS_RESET 0x48
  213. #define QHSTA_D_LRAM_CMP_ERROR 0x81
  214. #define QHSTA_M_MICRO_CODE_ERROR_HALT 0xA1
  215. #define ASC_FLAG_SCSIQ_REQ 0x01
  216. #define ASC_FLAG_BIOS_SCSIQ_REQ 0x02
  217. #define ASC_FLAG_BIOS_ASYNC_IO 0x04
  218. #define ASC_FLAG_SRB_LINEAR_ADDR 0x08
  219. #define ASC_FLAG_WIN16 0x10
  220. #define ASC_FLAG_WIN32 0x20
  221. #define ASC_FLAG_ISA_OVER_16MB 0x40
  222. #define ASC_FLAG_DOS_VM_CALLBACK 0x80
  223. #define ASC_TAG_FLAG_EXTRA_BYTES 0x10
  224. #define ASC_TAG_FLAG_DISABLE_DISCONNECT 0x04
  225. #define ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX 0x08
  226. #define ASC_TAG_FLAG_DISABLE_CHK_COND_INT_HOST 0x40
  227. #define ASC_SCSIQ_CPY_BEG 4
  228. #define ASC_SCSIQ_SGHD_CPY_BEG 2
  229. #define ASC_SCSIQ_B_FWD 0
  230. #define ASC_SCSIQ_B_BWD 1
  231. #define ASC_SCSIQ_B_STATUS 2
  232. #define ASC_SCSIQ_B_QNO 3
  233. #define ASC_SCSIQ_B_CNTL 4
  234. #define ASC_SCSIQ_B_SG_QUEUE_CNT 5
  235. #define ASC_SCSIQ_D_DATA_ADDR 8
  236. #define ASC_SCSIQ_D_DATA_CNT 12
  237. #define ASC_SCSIQ_B_SENSE_LEN 20
  238. #define ASC_SCSIQ_DONE_INFO_BEG 22
  239. #define ASC_SCSIQ_D_SRBPTR 22
  240. #define ASC_SCSIQ_B_TARGET_IX 26
  241. #define ASC_SCSIQ_B_CDB_LEN 28
  242. #define ASC_SCSIQ_B_TAG_CODE 29
  243. #define ASC_SCSIQ_W_VM_ID 30
  244. #define ASC_SCSIQ_DONE_STATUS 32
  245. #define ASC_SCSIQ_HOST_STATUS 33
  246. #define ASC_SCSIQ_SCSI_STATUS 34
  247. #define ASC_SCSIQ_CDB_BEG 36
  248. #define ASC_SCSIQ_DW_REMAIN_XFER_ADDR 56
  249. #define ASC_SCSIQ_DW_REMAIN_XFER_CNT 60
  250. #define ASC_SCSIQ_B_FIRST_SG_WK_QP 48
  251. #define ASC_SCSIQ_B_SG_WK_QP 49
  252. #define ASC_SCSIQ_B_SG_WK_IX 50
  253. #define ASC_SCSIQ_W_ALT_DC1 52
  254. #define ASC_SCSIQ_B_LIST_CNT 6
  255. #define ASC_SCSIQ_B_CUR_LIST_CNT 7
  256. #define ASC_SGQ_B_SG_CNTL 4
  257. #define ASC_SGQ_B_SG_HEAD_QP 5
  258. #define ASC_SGQ_B_SG_LIST_CNT 6
  259. #define ASC_SGQ_B_SG_CUR_LIST_CNT 7
  260. #define ASC_SGQ_LIST_BEG 8
  261. #define ASC_DEF_SCSI1_QNG 4
  262. #define ASC_MAX_SCSI1_QNG 4
  263. #define ASC_DEF_SCSI2_QNG 16
  264. #define ASC_MAX_SCSI2_QNG 32
  265. #define ASC_TAG_CODE_MASK 0x23
  266. #define ASC_STOP_REQ_RISC_STOP 0x01
  267. #define ASC_STOP_ACK_RISC_STOP 0x03
  268. #define ASC_STOP_CLEAN_UP_BUSY_Q 0x10
  269. #define ASC_STOP_CLEAN_UP_DISC_Q 0x20
  270. #define ASC_STOP_HOST_REQ_RISC_HALT 0x40
  271. #define ASC_TIDLUN_TO_IX(tid, lun) (ASC_SCSI_TIX_TYPE)((tid) + ((lun)<<ASC_SCSI_ID_BITS))
  272. #define ASC_TID_TO_TARGET_ID(tid) (ASC_SCSI_BIT_ID_TYPE)(0x01 << (tid))
  273. #define ASC_TIX_TO_TARGET_ID(tix) (0x01 << ((tix) & ASC_MAX_TID))
  274. #define ASC_TIX_TO_TID(tix) ((tix) & ASC_MAX_TID)
  275. #define ASC_TID_TO_TIX(tid) ((tid) & ASC_MAX_TID)
  276. #define ASC_TIX_TO_LUN(tix) (((tix) >> ASC_SCSI_ID_BITS) & ASC_MAX_LUN)
  277. #define ASC_QNO_TO_QADDR(q_no) ((ASC_QADR_BEG)+((int)(q_no) << 6))
  278. typedef struct asc_scsiq_1 {
  279. uchar status;
  280. uchar q_no;
  281. uchar cntl;
  282. uchar sg_queue_cnt;
  283. uchar target_id;
  284. uchar target_lun;
  285. ASC_PADDR data_addr;
  286. ASC_DCNT data_cnt;
  287. ASC_PADDR sense_addr;
  288. uchar sense_len;
  289. uchar extra_bytes;
  290. } ASC_SCSIQ_1;
  291. typedef struct asc_scsiq_2 {
  292. ASC_VADDR srb_ptr;
  293. uchar target_ix;
  294. uchar flag;
  295. uchar cdb_len;
  296. uchar tag_code;
  297. ushort vm_id;
  298. } ASC_SCSIQ_2;
  299. typedef struct asc_scsiq_3 {
  300. uchar done_stat;
  301. uchar host_stat;
  302. uchar scsi_stat;
  303. uchar scsi_msg;
  304. } ASC_SCSIQ_3;
  305. typedef struct asc_scsiq_4 {
  306. uchar cdb[ASC_MAX_CDB_LEN];
  307. uchar y_first_sg_list_qp;
  308. uchar y_working_sg_qp;
  309. uchar y_working_sg_ix;
  310. uchar y_res;
  311. ushort x_req_count;
  312. ushort x_reconnect_rtn;
  313. ASC_PADDR x_saved_data_addr;
  314. ASC_DCNT x_saved_data_cnt;
  315. } ASC_SCSIQ_4;
  316. typedef struct asc_q_done_info {
  317. ASC_SCSIQ_2 d2;
  318. ASC_SCSIQ_3 d3;
  319. uchar q_status;
  320. uchar q_no;
  321. uchar cntl;
  322. uchar sense_len;
  323. uchar extra_bytes;
  324. uchar res;
  325. ASC_DCNT remain_bytes;
  326. } ASC_QDONE_INFO;
  327. typedef struct asc_sg_list {
  328. ASC_PADDR addr;
  329. ASC_DCNT bytes;
  330. } ASC_SG_LIST;
  331. typedef struct asc_sg_head {
  332. ushort entry_cnt;
  333. ushort queue_cnt;
  334. ushort entry_to_copy;
  335. ushort res;
  336. ASC_SG_LIST sg_list[0];
  337. } ASC_SG_HEAD;
  338. typedef struct asc_scsi_q {
  339. ASC_SCSIQ_1 q1;
  340. ASC_SCSIQ_2 q2;
  341. uchar *cdbptr;
  342. ASC_SG_HEAD *sg_head;
  343. ushort remain_sg_entry_cnt;
  344. ushort next_sg_index;
  345. } ASC_SCSI_Q;
  346. typedef struct asc_scsi_req_q {
  347. ASC_SCSIQ_1 r1;
  348. ASC_SCSIQ_2 r2;
  349. uchar *cdbptr;
  350. ASC_SG_HEAD *sg_head;
  351. uchar *sense_ptr;
  352. ASC_SCSIQ_3 r3;
  353. uchar cdb[ASC_MAX_CDB_LEN];
  354. uchar sense[ASC_MIN_SENSE_LEN];
  355. } ASC_SCSI_REQ_Q;
  356. typedef struct asc_scsi_bios_req_q {
  357. ASC_SCSIQ_1 r1;
  358. ASC_SCSIQ_2 r2;
  359. uchar *cdbptr;
  360. ASC_SG_HEAD *sg_head;
  361. uchar *sense_ptr;
  362. ASC_SCSIQ_3 r3;
  363. uchar cdb[ASC_MAX_CDB_LEN];
  364. uchar sense[ASC_MIN_SENSE_LEN];
  365. } ASC_SCSI_BIOS_REQ_Q;
  366. typedef struct asc_risc_q {
  367. uchar fwd;
  368. uchar bwd;
  369. ASC_SCSIQ_1 i1;
  370. ASC_SCSIQ_2 i2;
  371. ASC_SCSIQ_3 i3;
  372. ASC_SCSIQ_4 i4;
  373. } ASC_RISC_Q;
  374. typedef struct asc_sg_list_q {
  375. uchar seq_no;
  376. uchar q_no;
  377. uchar cntl;
  378. uchar sg_head_qp;
  379. uchar sg_list_cnt;
  380. uchar sg_cur_list_cnt;
  381. } ASC_SG_LIST_Q;
  382. typedef struct asc_risc_sg_list_q {
  383. uchar fwd;
  384. uchar bwd;
  385. ASC_SG_LIST_Q sg;
  386. ASC_SG_LIST sg_list[7];
  387. } ASC_RISC_SG_LIST_Q;
  388. #define ASCQ_ERR_Q_STATUS 0x0D
  389. #define ASCQ_ERR_CUR_QNG 0x17
  390. #define ASCQ_ERR_SG_Q_LINKS 0x18
  391. #define ASCQ_ERR_ISR_RE_ENTRY 0x1A
  392. #define ASCQ_ERR_CRITICAL_RE_ENTRY 0x1B
  393. #define ASCQ_ERR_ISR_ON_CRITICAL 0x1C
  394. /*
  395. * Warning code values are set in ASC_DVC_VAR 'warn_code'.
  396. */
  397. #define ASC_WARN_NO_ERROR 0x0000
  398. #define ASC_WARN_IO_PORT_ROTATE 0x0001
  399. #define ASC_WARN_EEPROM_CHKSUM 0x0002
  400. #define ASC_WARN_IRQ_MODIFIED 0x0004
  401. #define ASC_WARN_AUTO_CONFIG 0x0008
  402. #define ASC_WARN_CMD_QNG_CONFLICT 0x0010
  403. #define ASC_WARN_EEPROM_RECOVER 0x0020
  404. #define ASC_WARN_CFG_MSW_RECOVER 0x0040
  405. /*
  406. * Error code values are set in {ASC/ADV}_DVC_VAR 'err_code'.
  407. */
  408. #define ASC_IERR_NO_CARRIER 0x0001 /* No more carrier memory */
  409. #define ASC_IERR_MCODE_CHKSUM 0x0002 /* micro code check sum error */
  410. #define ASC_IERR_SET_PC_ADDR 0x0004
  411. #define ASC_IERR_START_STOP_CHIP 0x0008 /* start/stop chip failed */
  412. #define ASC_IERR_ILLEGAL_CONNECTION 0x0010 /* Illegal cable connection */
  413. #define ASC_IERR_SINGLE_END_DEVICE 0x0020 /* SE device on DIFF bus */
  414. #define ASC_IERR_REVERSED_CABLE 0x0040 /* Narrow flat cable reversed */
  415. #define ASC_IERR_SET_SCSI_ID 0x0080 /* set SCSI ID failed */
  416. #define ASC_IERR_HVD_DEVICE 0x0100 /* HVD device on LVD port */
  417. #define ASC_IERR_BAD_SIGNATURE 0x0200 /* signature not found */
  418. #define ASC_IERR_NO_BUS_TYPE 0x0400
  419. #define ASC_IERR_BIST_PRE_TEST 0x0800 /* BIST pre-test error */
  420. #define ASC_IERR_BIST_RAM_TEST 0x1000 /* BIST RAM test error */
  421. #define ASC_IERR_BAD_CHIPTYPE 0x2000 /* Invalid chip_type setting */
  422. #define ASC_DEF_MAX_TOTAL_QNG (0xF0)
  423. #define ASC_MIN_TAG_Q_PER_DVC (0x04)
  424. #define ASC_MIN_FREE_Q (0x02)
  425. #define ASC_MIN_TOTAL_QNG ((ASC_MAX_SG_QUEUE)+(ASC_MIN_FREE_Q))
  426. #define ASC_MAX_TOTAL_QNG 240
  427. #define ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG 16
  428. #define ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG 8
  429. #define ASC_MAX_PCI_INRAM_TOTAL_QNG 20
  430. #define ASC_MAX_INRAM_TAG_QNG 16
  431. #define ASC_IOADR_GAP 0x10
  432. #define ASC_SYN_MAX_OFFSET 0x0F
  433. #define ASC_DEF_SDTR_OFFSET 0x0F
  434. #define ASC_SDTR_ULTRA_PCI_10MB_INDEX 0x02
  435. #define ASYN_SDTR_DATA_FIX_PCI_REV_AB 0x41
  436. /* The narrow chip only supports a limited selection of transfer rates.
  437. * These are encoded in the range 0..7 or 0..15 depending whether the chip
  438. * is Ultra-capable or not. These tables let us convert from one to the other.
  439. */
  440. static const unsigned char asc_syn_xfer_period[8] = {
  441. 25, 30, 35, 40, 50, 60, 70, 85
  442. };
  443. static const unsigned char asc_syn_ultra_xfer_period[16] = {
  444. 12, 19, 25, 32, 38, 44, 50, 57, 63, 69, 75, 82, 88, 94, 100, 107
  445. };
  446. typedef struct ext_msg {
  447. uchar msg_type;
  448. uchar msg_len;
  449. uchar msg_req;
  450. union {
  451. struct {
  452. uchar sdtr_xfer_period;
  453. uchar sdtr_req_ack_offset;
  454. } sdtr;
  455. struct {
  456. uchar wdtr_width;
  457. } wdtr;
  458. struct {
  459. uchar mdp_b3;
  460. uchar mdp_b2;
  461. uchar mdp_b1;
  462. uchar mdp_b0;
  463. } mdp;
  464. } u_ext_msg;
  465. uchar res;
  466. } EXT_MSG;
  467. #define xfer_period u_ext_msg.sdtr.sdtr_xfer_period
  468. #define req_ack_offset u_ext_msg.sdtr.sdtr_req_ack_offset
  469. #define wdtr_width u_ext_msg.wdtr.wdtr_width
  470. #define mdp_b3 u_ext_msg.mdp_b3
  471. #define mdp_b2 u_ext_msg.mdp_b2
  472. #define mdp_b1 u_ext_msg.mdp_b1
  473. #define mdp_b0 u_ext_msg.mdp_b0
  474. typedef struct asc_dvc_cfg {
  475. ASC_SCSI_BIT_ID_TYPE can_tagged_qng;
  476. ASC_SCSI_BIT_ID_TYPE cmd_qng_enabled;
  477. ASC_SCSI_BIT_ID_TYPE disc_enable;
  478. ASC_SCSI_BIT_ID_TYPE sdtr_enable;
  479. uchar chip_scsi_id;
  480. uchar isa_dma_speed;
  481. uchar isa_dma_channel;
  482. uchar chip_version;
  483. ushort mcode_date;
  484. ushort mcode_version;
  485. uchar max_tag_qng[ASC_MAX_TID + 1];
  486. uchar sdtr_period_offset[ASC_MAX_TID + 1];
  487. uchar adapter_info[6];
  488. } ASC_DVC_CFG;
  489. #define ASC_DEF_DVC_CNTL 0xFFFF
  490. #define ASC_DEF_CHIP_SCSI_ID 7
  491. #define ASC_DEF_ISA_DMA_SPEED 4
  492. #define ASC_INIT_STATE_BEG_GET_CFG 0x0001
  493. #define ASC_INIT_STATE_END_GET_CFG 0x0002
  494. #define ASC_INIT_STATE_BEG_SET_CFG 0x0004
  495. #define ASC_INIT_STATE_END_SET_CFG 0x0008
  496. #define ASC_INIT_STATE_BEG_LOAD_MC 0x0010
  497. #define ASC_INIT_STATE_END_LOAD_MC 0x0020
  498. #define ASC_INIT_STATE_BEG_INQUIRY 0x0040
  499. #define ASC_INIT_STATE_END_INQUIRY 0x0080
  500. #define ASC_INIT_RESET_SCSI_DONE 0x0100
  501. #define ASC_INIT_STATE_WITHOUT_EEP 0x8000
  502. #define ASC_BUG_FIX_IF_NOT_DWB 0x0001
  503. #define ASC_BUG_FIX_ASYN_USE_SYN 0x0002
  504. #define ASC_MIN_TAGGED_CMD 7
  505. #define ASC_MAX_SCSI_RESET_WAIT 30
  506. #define ASC_OVERRUN_BSIZE 64
  507. struct asc_dvc_var; /* Forward Declaration. */
  508. typedef struct asc_dvc_var {
  509. PortAddr iop_base;
  510. ushort err_code;
  511. ushort dvc_cntl;
  512. ushort bug_fix_cntl;
  513. ushort bus_type;
  514. ASC_SCSI_BIT_ID_TYPE init_sdtr;
  515. ASC_SCSI_BIT_ID_TYPE sdtr_done;
  516. ASC_SCSI_BIT_ID_TYPE use_tagged_qng;
  517. ASC_SCSI_BIT_ID_TYPE unit_not_ready;
  518. ASC_SCSI_BIT_ID_TYPE queue_full_or_busy;
  519. ASC_SCSI_BIT_ID_TYPE start_motor;
  520. uchar *overrun_buf;
  521. dma_addr_t overrun_dma;
  522. uchar scsi_reset_wait;
  523. uchar chip_no;
  524. char is_in_int;
  525. uchar max_total_qng;
  526. uchar cur_total_qng;
  527. uchar in_critical_cnt;
  528. uchar last_q_shortage;
  529. ushort init_state;
  530. uchar cur_dvc_qng[ASC_MAX_TID + 1];
  531. uchar max_dvc_qng[ASC_MAX_TID + 1];
  532. ASC_SCSI_Q *scsiq_busy_head[ASC_MAX_TID + 1];
  533. ASC_SCSI_Q *scsiq_busy_tail[ASC_MAX_TID + 1];
  534. const uchar *sdtr_period_tbl;
  535. ASC_DVC_CFG *cfg;
  536. ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer_always;
  537. char redo_scam;
  538. ushort res2;
  539. uchar dos_int13_table[ASC_MAX_TID + 1];
  540. ASC_DCNT max_dma_count;
  541. ASC_SCSI_BIT_ID_TYPE no_scam;
  542. ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer;
  543. uchar min_sdtr_index;
  544. uchar max_sdtr_index;
  545. struct asc_board *drv_ptr;
  546. int ptr_map_count;
  547. void **ptr_map;
  548. ASC_DCNT uc_break;
  549. } ASC_DVC_VAR;
  550. typedef struct asc_dvc_inq_info {
  551. uchar type[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
  552. } ASC_DVC_INQ_INFO;
  553. typedef struct asc_cap_info {
  554. ASC_DCNT lba;
  555. ASC_DCNT blk_size;
  556. } ASC_CAP_INFO;
  557. typedef struct asc_cap_info_array {
  558. ASC_CAP_INFO cap_info[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
  559. } ASC_CAP_INFO_ARRAY;
  560. #define ASC_MCNTL_NO_SEL_TIMEOUT (ushort)0x0001
  561. #define ASC_MCNTL_NULL_TARGET (ushort)0x0002
  562. #define ASC_CNTL_INITIATOR (ushort)0x0001
  563. #define ASC_CNTL_BIOS_GT_1GB (ushort)0x0002
  564. #define ASC_CNTL_BIOS_GT_2_DISK (ushort)0x0004
  565. #define ASC_CNTL_BIOS_REMOVABLE (ushort)0x0008
  566. #define ASC_CNTL_NO_SCAM (ushort)0x0010
  567. #define ASC_CNTL_INT_MULTI_Q (ushort)0x0080
  568. #define ASC_CNTL_NO_LUN_SUPPORT (ushort)0x0040
  569. #define ASC_CNTL_NO_VERIFY_COPY (ushort)0x0100
  570. #define ASC_CNTL_RESET_SCSI (ushort)0x0200
  571. #define ASC_CNTL_INIT_INQUIRY (ushort)0x0400
  572. #define ASC_CNTL_INIT_VERBOSE (ushort)0x0800
  573. #define ASC_CNTL_SCSI_PARITY (ushort)0x1000
  574. #define ASC_CNTL_BURST_MODE (ushort)0x2000
  575. #define ASC_CNTL_SDTR_ENABLE_ULTRA (ushort)0x4000
  576. #define ASC_EEP_DVC_CFG_BEG_VL 2
  577. #define ASC_EEP_MAX_DVC_ADDR_VL 15
  578. #define ASC_EEP_DVC_CFG_BEG 32
  579. #define ASC_EEP_MAX_DVC_ADDR 45
  580. #define ASC_EEP_MAX_RETRY 20
  581. /*
  582. * These macros keep the chip SCSI id and ISA DMA speed
  583. * bitfields in board order. C bitfields aren't portable
  584. * between big and little-endian platforms so they are
  585. * not used.
  586. */
  587. #define ASC_EEP_GET_CHIP_ID(cfg) ((cfg)->id_speed & 0x0f)
  588. #define ASC_EEP_GET_DMA_SPD(cfg) (((cfg)->id_speed & 0xf0) >> 4)
  589. #define ASC_EEP_SET_CHIP_ID(cfg, sid) \
  590. ((cfg)->id_speed = ((cfg)->id_speed & 0xf0) | ((sid) & ASC_MAX_TID))
  591. #define ASC_EEP_SET_DMA_SPD(cfg, spd) \
  592. ((cfg)->id_speed = ((cfg)->id_speed & 0x0f) | ((spd) & 0x0f) << 4)
  593. typedef struct asceep_config {
  594. ushort cfg_lsw;
  595. ushort cfg_msw;
  596. uchar init_sdtr;
  597. uchar disc_enable;
  598. uchar use_cmd_qng;
  599. uchar start_motor;
  600. uchar max_total_qng;
  601. uchar max_tag_qng;
  602. uchar bios_scan;
  603. uchar power_up_wait;
  604. uchar no_scam;
  605. uchar id_speed; /* low order 4 bits is chip scsi id */
  606. /* high order 4 bits is isa dma speed */
  607. uchar dos_int13_table[ASC_MAX_TID + 1];
  608. uchar adapter_info[6];
  609. ushort cntl;
  610. ushort chksum;
  611. } ASCEEP_CONFIG;
  612. #define ASC_EEP_CMD_READ 0x80
  613. #define ASC_EEP_CMD_WRITE 0x40
  614. #define ASC_EEP_CMD_WRITE_ABLE 0x30
  615. #define ASC_EEP_CMD_WRITE_DISABLE 0x00
  616. #define ASCV_MSGOUT_BEG 0x0000
  617. #define ASCV_MSGOUT_SDTR_PERIOD (ASCV_MSGOUT_BEG+3)
  618. #define ASCV_MSGOUT_SDTR_OFFSET (ASCV_MSGOUT_BEG+4)
  619. #define ASCV_BREAK_SAVED_CODE (ushort)0x0006
  620. #define ASCV_MSGIN_BEG (ASCV_MSGOUT_BEG+8)
  621. #define ASCV_MSGIN_SDTR_PERIOD (ASCV_MSGIN_BEG+3)
  622. #define ASCV_MSGIN_SDTR_OFFSET (ASCV_MSGIN_BEG+4)
  623. #define ASCV_SDTR_DATA_BEG (ASCV_MSGIN_BEG+8)
  624. #define ASCV_SDTR_DONE_BEG (ASCV_SDTR_DATA_BEG+8)
  625. #define ASCV_MAX_DVC_QNG_BEG (ushort)0x0020
  626. #define ASCV_BREAK_ADDR (ushort)0x0028
  627. #define ASCV_BREAK_NOTIFY_COUNT (ushort)0x002A
  628. #define ASCV_BREAK_CONTROL (ushort)0x002C
  629. #define ASCV_BREAK_HIT_COUNT (ushort)0x002E
  630. #define ASCV_ASCDVC_ERR_CODE_W (ushort)0x0030
  631. #define ASCV_MCODE_CHKSUM_W (ushort)0x0032
  632. #define ASCV_MCODE_SIZE_W (ushort)0x0034
  633. #define ASCV_STOP_CODE_B (ushort)0x0036
  634. #define ASCV_DVC_ERR_CODE_B (ushort)0x0037
  635. #define ASCV_OVERRUN_PADDR_D (ushort)0x0038
  636. #define ASCV_OVERRUN_BSIZE_D (ushort)0x003C
  637. #define ASCV_HALTCODE_W (ushort)0x0040
  638. #define ASCV_CHKSUM_W (ushort)0x0042
  639. #define ASCV_MC_DATE_W (ushort)0x0044
  640. #define ASCV_MC_VER_W (ushort)0x0046
  641. #define ASCV_NEXTRDY_B (ushort)0x0048
  642. #define ASCV_DONENEXT_B (ushort)0x0049
  643. #define ASCV_USE_TAGGED_QNG_B (ushort)0x004A
  644. #define ASCV_SCSIBUSY_B (ushort)0x004B
  645. #define ASCV_Q_DONE_IN_PROGRESS_B (ushort)0x004C
  646. #define ASCV_CURCDB_B (ushort)0x004D
  647. #define ASCV_RCLUN_B (ushort)0x004E
  648. #define ASCV_BUSY_QHEAD_B (ushort)0x004F
  649. #define ASCV_DISC1_QHEAD_B (ushort)0x0050
  650. #define ASCV_DISC_ENABLE_B (ushort)0x0052
  651. #define ASCV_CAN_TAGGED_QNG_B (ushort)0x0053
  652. #define ASCV_HOSTSCSI_ID_B (ushort)0x0055
  653. #define ASCV_MCODE_CNTL_B (ushort)0x0056
  654. #define ASCV_NULL_TARGET_B (ushort)0x0057
  655. #define ASCV_FREE_Q_HEAD_W (ushort)0x0058
  656. #define ASCV_DONE_Q_TAIL_W (ushort)0x005A
  657. #define ASCV_FREE_Q_HEAD_B (ushort)(ASCV_FREE_Q_HEAD_W+1)
  658. #define ASCV_DONE_Q_TAIL_B (ushort)(ASCV_DONE_Q_TAIL_W+1)
  659. #define ASCV_HOST_FLAG_B (ushort)0x005D
  660. #define ASCV_TOTAL_READY_Q_B (ushort)0x0064
  661. #define ASCV_VER_SERIAL_B (ushort)0x0065
  662. #define ASCV_HALTCODE_SAVED_W (ushort)0x0066
  663. #define ASCV_WTM_FLAG_B (ushort)0x0068
  664. #define ASCV_RISC_FLAG_B (ushort)0x006A
  665. #define ASCV_REQ_SG_LIST_QP (ushort)0x006B
  666. #define ASC_HOST_FLAG_IN_ISR 0x01
  667. #define ASC_HOST_FLAG_ACK_INT 0x02
  668. #define ASC_RISC_FLAG_GEN_INT 0x01
  669. #define ASC_RISC_FLAG_REQ_SG_LIST 0x02
  670. #define IOP_CTRL (0x0F)
  671. #define IOP_STATUS (0x0E)
  672. #define IOP_INT_ACK IOP_STATUS
  673. #define IOP_REG_IFC (0x0D)
  674. #define IOP_SYN_OFFSET (0x0B)
  675. #define IOP_EXTRA_CONTROL (0x0D)
  676. #define IOP_REG_PC (0x0C)
  677. #define IOP_RAM_ADDR (0x0A)
  678. #define IOP_RAM_DATA (0x08)
  679. #define IOP_EEP_DATA (0x06)
  680. #define IOP_EEP_CMD (0x07)
  681. #define IOP_VERSION (0x03)
  682. #define IOP_CONFIG_HIGH (0x04)
  683. #define IOP_CONFIG_LOW (0x02)
  684. #define IOP_SIG_BYTE (0x01)
  685. #define IOP_SIG_WORD (0x00)
  686. #define IOP_REG_DC1 (0x0E)
  687. #define IOP_REG_DC0 (0x0C)
  688. #define IOP_REG_SB (0x0B)
  689. #define IOP_REG_DA1 (0x0A)
  690. #define IOP_REG_DA0 (0x08)
  691. #define IOP_REG_SC (0x09)
  692. #define IOP_DMA_SPEED (0x07)
  693. #define IOP_REG_FLAG (0x07)
  694. #define IOP_FIFO_H (0x06)
  695. #define IOP_FIFO_L (0x04)
  696. #define IOP_REG_ID (0x05)
  697. #define IOP_REG_QP (0x03)
  698. #define IOP_REG_IH (0x02)
  699. #define IOP_REG_IX (0x01)
  700. #define IOP_REG_AX (0x00)
  701. #define IFC_REG_LOCK (0x00)
  702. #define IFC_REG_UNLOCK (0x09)
  703. #define IFC_WR_EN_FILTER (0x10)
  704. #define IFC_RD_NO_EEPROM (0x10)
  705. #define IFC_SLEW_RATE (0x20)
  706. #define IFC_ACT_NEG (0x40)
  707. #define IFC_INP_FILTER (0x80)
  708. #define IFC_INIT_DEFAULT (IFC_ACT_NEG | IFC_REG_UNLOCK)
  709. #define SC_SEL (uchar)(0x80)
  710. #define SC_BSY (uchar)(0x40)
  711. #define SC_ACK (uchar)(0x20)
  712. #define SC_REQ (uchar)(0x10)
  713. #define SC_ATN (uchar)(0x08)
  714. #define SC_IO (uchar)(0x04)
  715. #define SC_CD (uchar)(0x02)
  716. #define SC_MSG (uchar)(0x01)
  717. #define SEC_SCSI_CTL (uchar)(0x80)
  718. #define SEC_ACTIVE_NEGATE (uchar)(0x40)
  719. #define SEC_SLEW_RATE (uchar)(0x20)
  720. #define SEC_ENABLE_FILTER (uchar)(0x10)
  721. #define ASC_HALT_EXTMSG_IN (ushort)0x8000
  722. #define ASC_HALT_CHK_CONDITION (ushort)0x8100
  723. #define ASC_HALT_SS_QUEUE_FULL (ushort)0x8200
  724. #define ASC_HALT_DISABLE_ASYN_USE_SYN_FIX (ushort)0x8300
  725. #define ASC_HALT_ENABLE_ASYN_USE_SYN_FIX (ushort)0x8400
  726. #define ASC_HALT_SDTR_REJECTED (ushort)0x4000
  727. #define ASC_HALT_HOST_COPY_SG_LIST_TO_RISC ( ushort )0x2000
  728. #define ASC_MAX_QNO 0xF8
  729. #define ASC_DATA_SEC_BEG (ushort)0x0080
  730. #define ASC_DATA_SEC_END (ushort)0x0080
  731. #define ASC_CODE_SEC_BEG (ushort)0x0080
  732. #define ASC_CODE_SEC_END (ushort)0x0080
  733. #define ASC_QADR_BEG (0x4000)
  734. #define ASC_QADR_USED (ushort)(ASC_MAX_QNO * 64)
  735. #define ASC_QADR_END (ushort)0x7FFF
  736. #define ASC_QLAST_ADR (ushort)0x7FC0
  737. #define ASC_QBLK_SIZE 0x40
  738. #define ASC_BIOS_DATA_QBEG 0xF8
  739. #define ASC_MIN_ACTIVE_QNO 0x01
  740. #define ASC_QLINK_END 0xFF
  741. #define ASC_EEPROM_WORDS 0x10
  742. #define ASC_MAX_MGS_LEN 0x10
  743. #define ASC_BIOS_ADDR_DEF 0xDC00
  744. #define ASC_BIOS_SIZE 0x3800
  745. #define ASC_BIOS_RAM_OFF 0x3800
  746. #define ASC_BIOS_RAM_SIZE 0x800
  747. #define ASC_BIOS_MIN_ADDR 0xC000
  748. #define ASC_BIOS_MAX_ADDR 0xEC00
  749. #define ASC_BIOS_BANK_SIZE 0x0400
  750. #define ASC_MCODE_START_ADDR 0x0080
  751. #define ASC_CFG0_HOST_INT_ON 0x0020
  752. #define ASC_CFG0_BIOS_ON 0x0040
  753. #define ASC_CFG0_VERA_BURST_ON 0x0080
  754. #define ASC_CFG0_SCSI_PARITY_ON 0x0800
  755. #define ASC_CFG1_SCSI_TARGET_ON 0x0080
  756. #define ASC_CFG1_LRAM_8BITS_ON 0x0800
  757. #define ASC_CFG_MSW_CLR_MASK 0x3080
  758. #define CSW_TEST1 (ASC_CS_TYPE)0x8000
  759. #define CSW_AUTO_CONFIG (ASC_CS_TYPE)0x4000
  760. #define CSW_RESERVED1 (ASC_CS_TYPE)0x2000
  761. #define CSW_IRQ_WRITTEN (ASC_CS_TYPE)0x1000
  762. #define CSW_33MHZ_SELECTED (ASC_CS_TYPE)0x0800
  763. #define CSW_TEST2 (ASC_CS_TYPE)0x0400
  764. #define CSW_TEST3 (ASC_CS_TYPE)0x0200
  765. #define CSW_RESERVED2 (ASC_CS_TYPE)0x0100
  766. #define CSW_DMA_DONE (ASC_CS_TYPE)0x0080
  767. #define CSW_FIFO_RDY (ASC_CS_TYPE)0x0040
  768. #define CSW_EEP_READ_DONE (ASC_CS_TYPE)0x0020
  769. #define CSW_HALTED (ASC_CS_TYPE)0x0010
  770. #define CSW_SCSI_RESET_ACTIVE (ASC_CS_TYPE)0x0008
  771. #define CSW_PARITY_ERR (ASC_CS_TYPE)0x0004
  772. #define CSW_SCSI_RESET_LATCH (ASC_CS_TYPE)0x0002
  773. #define CSW_INT_PENDING (ASC_CS_TYPE)0x0001
  774. #define CIW_CLR_SCSI_RESET_INT (ASC_CS_TYPE)0x1000
  775. #define CIW_INT_ACK (ASC_CS_TYPE)0x0100
  776. #define CIW_TEST1 (ASC_CS_TYPE)0x0200
  777. #define CIW_TEST2 (ASC_CS_TYPE)0x0400
  778. #define CIW_SEL_33MHZ (ASC_CS_TYPE)0x0800
  779. #define CIW_IRQ_ACT (ASC_CS_TYPE)0x1000
  780. #define CC_CHIP_RESET (uchar)0x80
  781. #define CC_SCSI_RESET (uchar)0x40
  782. #define CC_HALT (uchar)0x20
  783. #define CC_SINGLE_STEP (uchar)0x10
  784. #define CC_DMA_ABLE (uchar)0x08
  785. #define CC_TEST (uchar)0x04
  786. #define CC_BANK_ONE (uchar)0x02
  787. #define CC_DIAG (uchar)0x01
  788. #define ASC_1000_ID0W 0x04C1
  789. #define ASC_1000_ID0W_FIX 0x00C1
  790. #define ASC_1000_ID1B 0x25
  791. #define ASC_EISA_REV_IOP_MASK (0x0C83)
  792. #define ASC_EISA_CFG_IOP_MASK (0x0C86)
  793. #define ASC_GET_EISA_SLOT(iop) (PortAddr)((iop) & 0xF000)
  794. #define INS_HALTINT (ushort)0x6281
  795. #define INS_HALT (ushort)0x6280
  796. #define INS_SINT (ushort)0x6200
  797. #define INS_RFLAG_WTM (ushort)0x7380
  798. #define ASC_MC_SAVE_CODE_WSIZE 0x500
  799. #define ASC_MC_SAVE_DATA_WSIZE 0x40
  800. typedef struct asc_mc_saved {
  801. ushort data[ASC_MC_SAVE_DATA_WSIZE];
  802. ushort code[ASC_MC_SAVE_CODE_WSIZE];
  803. } ASC_MC_SAVED;
  804. #define AscGetQDoneInProgress(port) AscReadLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B)
  805. #define AscPutQDoneInProgress(port, val) AscWriteLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B, val)
  806. #define AscGetVarFreeQHead(port) AscReadLramWord((port), ASCV_FREE_Q_HEAD_W)
  807. #define AscGetVarDoneQTail(port) AscReadLramWord((port), ASCV_DONE_Q_TAIL_W)
  808. #define AscPutVarFreeQHead(port, val) AscWriteLramWord((port), ASCV_FREE_Q_HEAD_W, val)
  809. #define AscPutVarDoneQTail(port, val) AscWriteLramWord((port), ASCV_DONE_Q_TAIL_W, val)
  810. #define AscGetRiscVarFreeQHead(port) AscReadLramByte((port), ASCV_NEXTRDY_B)
  811. #define AscGetRiscVarDoneQTail(port) AscReadLramByte((port), ASCV_DONENEXT_B)
  812. #define AscPutRiscVarFreeQHead(port, val) AscWriteLramByte((port), ASCV_NEXTRDY_B, val)
  813. #define AscPutRiscVarDoneQTail(port, val) AscWriteLramByte((port), ASCV_DONENEXT_B, val)
  814. #define AscPutMCodeSDTRDoneAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id), (data))
  815. #define AscGetMCodeSDTRDoneAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id))
  816. #define AscPutMCodeInitSDTRAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id), data)
  817. #define AscGetMCodeInitSDTRAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id))
  818. #define AscGetChipSignatureByte(port) (uchar)inp((port)+IOP_SIG_BYTE)
  819. #define AscGetChipSignatureWord(port) (ushort)inpw((port)+IOP_SIG_WORD)
  820. #define AscGetChipVerNo(port) (uchar)inp((port)+IOP_VERSION)
  821. #define AscGetChipCfgLsw(port) (ushort)inpw((port)+IOP_CONFIG_LOW)
  822. #define AscGetChipCfgMsw(port) (ushort)inpw((port)+IOP_CONFIG_HIGH)
  823. #define AscSetChipCfgLsw(port, data) outpw((port)+IOP_CONFIG_LOW, data)
  824. #define AscSetChipCfgMsw(port, data) outpw((port)+IOP_CONFIG_HIGH, data)
  825. #define AscGetChipEEPCmd(port) (uchar)inp((port)+IOP_EEP_CMD)
  826. #define AscSetChipEEPCmd(port, data) outp((port)+IOP_EEP_CMD, data)
  827. #define AscGetChipEEPData(port) (ushort)inpw((port)+IOP_EEP_DATA)
  828. #define AscSetChipEEPData(port, data) outpw((port)+IOP_EEP_DATA, data)
  829. #define AscGetChipLramAddr(port) (ushort)inpw((PortAddr)((port)+IOP_RAM_ADDR))
  830. #define AscSetChipLramAddr(port, addr) outpw((PortAddr)((port)+IOP_RAM_ADDR), addr)
  831. #define AscGetChipLramData(port) (ushort)inpw((port)+IOP_RAM_DATA)
  832. #define AscSetChipLramData(port, data) outpw((port)+IOP_RAM_DATA, data)
  833. #define AscGetChipIFC(port) (uchar)inp((port)+IOP_REG_IFC)
  834. #define AscSetChipIFC(port, data) outp((port)+IOP_REG_IFC, data)
  835. #define AscGetChipStatus(port) (ASC_CS_TYPE)inpw((port)+IOP_STATUS)
  836. #define AscSetChipStatus(port, cs_val) outpw((port)+IOP_STATUS, cs_val)
  837. #define AscGetChipControl(port) (uchar)inp((port)+IOP_CTRL)
  838. #define AscSetChipControl(port, cc_val) outp((port)+IOP_CTRL, cc_val)
  839. #define AscGetChipSyn(port) (uchar)inp((port)+IOP_SYN_OFFSET)
  840. #define AscSetChipSyn(port, data) outp((port)+IOP_SYN_OFFSET, data)
  841. #define AscSetPCAddr(port, data) outpw((port)+IOP_REG_PC, data)
  842. #define AscGetPCAddr(port) (ushort)inpw((port)+IOP_REG_PC)
  843. #define AscIsIntPending(port) (AscGetChipStatus(port) & (CSW_INT_PENDING | CSW_SCSI_RESET_LATCH))
  844. #define AscGetChipScsiID(port) ((AscGetChipCfgLsw(port) >> 8) & ASC_MAX_TID)
  845. #define AscGetExtraControl(port) (uchar)inp((port)+IOP_EXTRA_CONTROL)
  846. #define AscSetExtraControl(port, data) outp((port)+IOP_EXTRA_CONTROL, data)
  847. #define AscReadChipAX(port) (ushort)inpw((port)+IOP_REG_AX)
  848. #define AscWriteChipAX(port, data) outpw((port)+IOP_REG_AX, data)
  849. #define AscReadChipIX(port) (uchar)inp((port)+IOP_REG_IX)
  850. #define AscWriteChipIX(port, data) outp((port)+IOP_REG_IX, data)
  851. #define AscReadChipIH(port) (ushort)inpw((port)+IOP_REG_IH)
  852. #define AscWriteChipIH(port, data) outpw((port)+IOP_REG_IH, data)
  853. #define AscReadChipQP(port) (uchar)inp((port)+IOP_REG_QP)
  854. #define AscWriteChipQP(port, data) outp((port)+IOP_REG_QP, data)
  855. #define AscReadChipFIFO_L(port) (ushort)inpw((port)+IOP_REG_FIFO_L)
  856. #define AscWriteChipFIFO_L(port, data) outpw((port)+IOP_REG_FIFO_L, data)
  857. #define AscReadChipFIFO_H(port) (ushort)inpw((port)+IOP_REG_FIFO_H)
  858. #define AscWriteChipFIFO_H(port, data) outpw((port)+IOP_REG_FIFO_H, data)
  859. #define AscReadChipDmaSpeed(port) (uchar)inp((port)+IOP_DMA_SPEED)
  860. #define AscWriteChipDmaSpeed(port, data) outp((port)+IOP_DMA_SPEED, data)
  861. #define AscReadChipDA0(port) (ushort)inpw((port)+IOP_REG_DA0)
  862. #define AscWriteChipDA0(port) outpw((port)+IOP_REG_DA0, data)
  863. #define AscReadChipDA1(port) (ushort)inpw((port)+IOP_REG_DA1)
  864. #define AscWriteChipDA1(port) outpw((port)+IOP_REG_DA1, data)
  865. #define AscReadChipDC0(port) (ushort)inpw((port)+IOP_REG_DC0)
  866. #define AscWriteChipDC0(port) outpw((port)+IOP_REG_DC0, data)
  867. #define AscReadChipDC1(port) (ushort)inpw((port)+IOP_REG_DC1)
  868. #define AscWriteChipDC1(port) outpw((port)+IOP_REG_DC1, data)
  869. #define AscReadChipDvcID(port) (uchar)inp((port)+IOP_REG_ID)
  870. #define AscWriteChipDvcID(port, data) outp((port)+IOP_REG_ID, data)
  871. /*
  872. * Portable Data Types
  873. *
  874. * Any instance where a 32-bit long or pointer type is assumed
  875. * for precision or HW defined structures, the following define
  876. * types must be used. In Linux the char, short, and int types
  877. * are all consistent at 8, 16, and 32 bits respectively. Pointers
  878. * and long types are 64 bits on Alpha and UltraSPARC.
  879. */
  880. #define ADV_PADDR __u32 /* Physical address data type. */
  881. #define ADV_VADDR __u32 /* Virtual address data type. */
  882. #define ADV_DCNT __u32 /* Unsigned Data count type. */
  883. #define ADV_SDCNT __s32 /* Signed Data count type. */
  884. /*
  885. * These macros are used to convert a virtual address to a
  886. * 32-bit value. This currently can be used on Linux Alpha
  887. * which uses 64-bit virtual address but a 32-bit bus address.
  888. * This is likely to break in the future, but doing this now
  889. * will give us time to change the HW and FW to handle 64-bit
  890. * addresses.
  891. */
  892. #define ADV_VADDR_TO_U32 virt_to_bus
  893. #define ADV_U32_TO_VADDR bus_to_virt
  894. #define AdvPortAddr void __iomem * /* Virtual memory address size */
  895. /*
  896. * Define Adv Library required memory access macros.
  897. */
  898. #define ADV_MEM_READB(addr) readb(addr)
  899. #define ADV_MEM_READW(addr) readw(addr)
  900. #define ADV_MEM_WRITEB(addr, byte) writeb(byte, addr)
  901. #define ADV_MEM_WRITEW(addr, word) writew(word, addr)
  902. #define ADV_MEM_WRITEDW(addr, dword) writel(dword, addr)
  903. #define ADV_CARRIER_COUNT (ASC_DEF_MAX_HOST_QNG + 15)
  904. /*
  905. * Define total number of simultaneous maximum element scatter-gather
  906. * request blocks per wide adapter. ASC_DEF_MAX_HOST_QNG (253) is the
  907. * maximum number of outstanding commands per wide host adapter. Each
  908. * command uses one or more ADV_SG_BLOCK each with 15 scatter-gather
  909. * elements. Allow each command to have at least one ADV_SG_BLOCK structure.
  910. * This allows about 15 commands to have the maximum 17 ADV_SG_BLOCK
  911. * structures or 255 scatter-gather elements.
  912. */
  913. #define ADV_TOT_SG_BLOCK ASC_DEF_MAX_HOST_QNG
  914. /*
  915. * Define maximum number of scatter-gather elements per request.
  916. */
  917. #define ADV_MAX_SG_LIST 255
  918. #define NO_OF_SG_PER_BLOCK 15
  919. #define ADV_EEP_DVC_CFG_BEGIN (0x00)
  920. #define ADV_EEP_DVC_CFG_END (0x15)
  921. #define ADV_EEP_DVC_CTL_BEGIN (0x16) /* location of OEM name */
  922. #define ADV_EEP_MAX_WORD_ADDR (0x1E)
  923. #define ADV_EEP_DELAY_MS 100
  924. #define ADV_EEPROM_BIG_ENDIAN 0x8000 /* EEPROM Bit 15 */
  925. #define ADV_EEPROM_BIOS_ENABLE 0x4000 /* EEPROM Bit 14 */
  926. /*
  927. * For the ASC3550 Bit 13 is Termination Polarity control bit.
  928. * For later ICs Bit 13 controls whether the CIS (Card Information
  929. * Service Section) is loaded from EEPROM.
  930. */
  931. #define ADV_EEPROM_TERM_POL 0x2000 /* EEPROM Bit 13 */
  932. #define ADV_EEPROM_CIS_LD 0x2000 /* EEPROM Bit 13 */
  933. /*
  934. * ASC38C1600 Bit 11
  935. *
  936. * If EEPROM Bit 11 is 0 for Function 0, then Function 0 will specify
  937. * INT A in the PCI Configuration Space Int Pin field. If it is 1, then
  938. * Function 0 will specify INT B.
  939. *
  940. * If EEPROM Bit 11 is 0 for Function 1, then Function 1 will specify
  941. * INT B in the PCI Configuration Space Int Pin field. If it is 1, then
  942. * Function 1 will specify INT A.
  943. */
  944. #define ADV_EEPROM_INTAB 0x0800 /* EEPROM Bit 11 */
  945. typedef struct adveep_3550_config {
  946. /* Word Offset, Description */
  947. ushort cfg_lsw; /* 00 power up initialization */
  948. /* bit 13 set - Term Polarity Control */
  949. /* bit 14 set - BIOS Enable */
  950. /* bit 15 set - Big Endian Mode */
  951. ushort cfg_msw; /* 01 unused */
  952. ushort disc_enable; /* 02 disconnect enable */
  953. ushort wdtr_able; /* 03 Wide DTR able */
  954. ushort sdtr_able; /* 04 Synchronous DTR able */
  955. ushort start_motor; /* 05 send start up motor */
  956. ushort tagqng_able; /* 06 tag queuing able */
  957. ushort bios_scan; /* 07 BIOS device control */
  958. ushort scam_tolerant; /* 08 no scam */
  959. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  960. uchar bios_boot_delay; /* power up wait */
  961. uchar scsi_reset_delay; /* 10 reset delay */
  962. uchar bios_id_lun; /* first boot device scsi id & lun */
  963. /* high nibble is lun */
  964. /* low nibble is scsi id */
  965. uchar termination; /* 11 0 - automatic */
  966. /* 1 - low off / high off */
  967. /* 2 - low off / high on */
  968. /* 3 - low on / high on */
  969. /* There is no low on / high off */
  970. uchar reserved1; /* reserved byte (not used) */
  971. ushort bios_ctrl; /* 12 BIOS control bits */
  972. /* bit 0 BIOS don't act as initiator. */
  973. /* bit 1 BIOS > 1 GB support */
  974. /* bit 2 BIOS > 2 Disk Support */
  975. /* bit 3 BIOS don't support removables */
  976. /* bit 4 BIOS support bootable CD */
  977. /* bit 5 BIOS scan enabled */
  978. /* bit 6 BIOS support multiple LUNs */
  979. /* bit 7 BIOS display of message */
  980. /* bit 8 SCAM disabled */
  981. /* bit 9 Reset SCSI bus during init. */
  982. /* bit 10 */
  983. /* bit 11 No verbose initialization. */
  984. /* bit 12 SCSI parity enabled */
  985. /* bit 13 */
  986. /* bit 14 */
  987. /* bit 15 */
  988. ushort ultra_able; /* 13 ULTRA speed able */
  989. ushort reserved2; /* 14 reserved */
  990. uchar max_host_qng; /* 15 maximum host queuing */
  991. uchar max_dvc_qng; /* maximum per device queuing */
  992. ushort dvc_cntl; /* 16 control bit for driver */
  993. ushort bug_fix; /* 17 control bit for bug fix */
  994. ushort serial_number_word1; /* 18 Board serial number word 1 */
  995. ushort serial_number_word2; /* 19 Board serial number word 2 */
  996. ushort serial_number_word3; /* 20 Board serial number word 3 */
  997. ushort check_sum; /* 21 EEP check sum */
  998. uchar oem_name[16]; /* 22 OEM name */
  999. ushort dvc_err_code; /* 30 last device driver error code */
  1000. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  1001. ushort adv_err_addr; /* 32 last uc error address */
  1002. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  1003. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  1004. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  1005. ushort num_of_err; /* 36 number of error */
  1006. } ADVEEP_3550_CONFIG;
  1007. typedef struct adveep_38C0800_config {
  1008. /* Word Offset, Description */
  1009. ushort cfg_lsw; /* 00 power up initialization */
  1010. /* bit 13 set - Load CIS */
  1011. /* bit 14 set - BIOS Enable */
  1012. /* bit 15 set - Big Endian Mode */
  1013. ushort cfg_msw; /* 01 unused */
  1014. ushort disc_enable; /* 02 disconnect enable */
  1015. ushort wdtr_able; /* 03 Wide DTR able */
  1016. ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
  1017. ushort start_motor; /* 05 send start up motor */
  1018. ushort tagqng_able; /* 06 tag queuing able */
  1019. ushort bios_scan; /* 07 BIOS device control */
  1020. ushort scam_tolerant; /* 08 no scam */
  1021. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  1022. uchar bios_boot_delay; /* power up wait */
  1023. uchar scsi_reset_delay; /* 10 reset delay */
  1024. uchar bios_id_lun; /* first boot device scsi id & lun */
  1025. /* high nibble is lun */
  1026. /* low nibble is scsi id */
  1027. uchar termination_se; /* 11 0 - automatic */
  1028. /* 1 - low off / high off */
  1029. /* 2 - low off / high on */
  1030. /* 3 - low on / high on */
  1031. /* There is no low on / high off */
  1032. uchar termination_lvd; /* 11 0 - automatic */
  1033. /* 1 - low off / high off */
  1034. /* 2 - low off / high on */
  1035. /* 3 - low on / high on */
  1036. /* There is no low on / high off */
  1037. ushort bios_ctrl; /* 12 BIOS control bits */
  1038. /* bit 0 BIOS don't act as initiator. */
  1039. /* bit 1 BIOS > 1 GB support */
  1040. /* bit 2 BIOS > 2 Disk Support */
  1041. /* bit 3 BIOS don't support removables */
  1042. /* bit 4 BIOS support bootable CD */
  1043. /* bit 5 BIOS scan enabled */
  1044. /* bit 6 BIOS support multiple LUNs */
  1045. /* bit 7 BIOS display of message */
  1046. /* bit 8 SCAM disabled */
  1047. /* bit 9 Reset SCSI bus during init. */
  1048. /* bit 10 */
  1049. /* bit 11 No verbose initialization. */
  1050. /* bit 12 SCSI parity enabled */
  1051. /* bit 13 */
  1052. /* bit 14 */
  1053. /* bit 15 */
  1054. ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
  1055. ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
  1056. uchar max_host_qng; /* 15 maximum host queueing */
  1057. uchar max_dvc_qng; /* maximum per device queuing */
  1058. ushort dvc_cntl; /* 16 control bit for driver */
  1059. ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
  1060. ushort serial_number_word1; /* 18 Board serial number word 1 */
  1061. ushort serial_number_word2; /* 19 Board serial number word 2 */
  1062. ushort serial_number_word3; /* 20 Board serial number word 3 */
  1063. ushort check_sum; /* 21 EEP check sum */
  1064. uchar oem_name[16]; /* 22 OEM name */
  1065. ushort dvc_err_code; /* 30 last device driver error code */
  1066. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  1067. ushort adv_err_addr; /* 32 last uc error address */
  1068. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  1069. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  1070. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  1071. ushort reserved36; /* 36 reserved */
  1072. ushort reserved37; /* 37 reserved */
  1073. ushort reserved38; /* 38 reserved */
  1074. ushort reserved39; /* 39 reserved */
  1075. ushort reserved40; /* 40 reserved */
  1076. ushort reserved41; /* 41 reserved */
  1077. ushort reserved42; /* 42 reserved */
  1078. ushort reserved43; /* 43 reserved */
  1079. ushort reserved44; /* 44 reserved */
  1080. ushort reserved45; /* 45 reserved */
  1081. ushort reserved46; /* 46 reserved */
  1082. ushort reserved47; /* 47 reserved */
  1083. ushort reserved48; /* 48 reserved */
  1084. ushort reserved49; /* 49 reserved */
  1085. ushort reserved50; /* 50 reserved */
  1086. ushort reserved51; /* 51 reserved */
  1087. ushort reserved52; /* 52 reserved */
  1088. ushort reserved53; /* 53 reserved */
  1089. ushort reserved54; /* 54 reserved */
  1090. ushort reserved55; /* 55 reserved */
  1091. ushort cisptr_lsw; /* 56 CIS PTR LSW */
  1092. ushort cisprt_msw; /* 57 CIS PTR MSW */
  1093. ushort subsysvid; /* 58 SubSystem Vendor ID */
  1094. ushort subsysid; /* 59 SubSystem ID */
  1095. ushort reserved60; /* 60 reserved */
  1096. ushort reserved61; /* 61 reserved */
  1097. ushort reserved62; /* 62 reserved */
  1098. ushort reserved63; /* 63 reserved */
  1099. } ADVEEP_38C0800_CONFIG;
  1100. typedef struct adveep_38C1600_config {
  1101. /* Word Offset, Description */
  1102. ushort cfg_lsw; /* 00 power up initialization */
  1103. /* bit 11 set - Func. 0 INTB, Func. 1 INTA */
  1104. /* clear - Func. 0 INTA, Func. 1 INTB */
  1105. /* bit 13 set - Load CIS */
  1106. /* bit 14 set - BIOS Enable */
  1107. /* bit 15 set - Big Endian Mode */
  1108. ushort cfg_msw; /* 01 unused */
  1109. ushort disc_enable; /* 02 disconnect enable */
  1110. ushort wdtr_able; /* 03 Wide DTR able */
  1111. ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
  1112. ushort start_motor; /* 05 send start up motor */
  1113. ushort tagqng_able; /* 06 tag queuing able */
  1114. ushort bios_scan; /* 07 BIOS device control */
  1115. ushort scam_tolerant; /* 08 no scam */
  1116. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  1117. uchar bios_boot_delay; /* power up wait */
  1118. uchar scsi_reset_delay; /* 10 reset delay */
  1119. uchar bios_id_lun; /* first boot device scsi id & lun */
  1120. /* high nibble is lun */
  1121. /* low nibble is scsi id */
  1122. uchar termination_se; /* 11 0 - automatic */
  1123. /* 1 - low off / high off */
  1124. /* 2 - low off / high on */
  1125. /* 3 - low on / high on */
  1126. /* There is no low on / high off */
  1127. uchar termination_lvd; /* 11 0 - automatic */
  1128. /* 1 - low off / high off */
  1129. /* 2 - low off / high on */
  1130. /* 3 - low on / high on */
  1131. /* There is no low on / high off */
  1132. ushort bios_ctrl; /* 12 BIOS control bits */
  1133. /* bit 0 BIOS don't act as initiator. */
  1134. /* bit 1 BIOS > 1 GB support */
  1135. /* bit 2 BIOS > 2 Disk Support */
  1136. /* bit 3 BIOS don't support removables */
  1137. /* bit 4 BIOS support bootable CD */
  1138. /* bit 5 BIOS scan enabled */
  1139. /* bit 6 BIOS support multiple LUNs */
  1140. /* bit 7 BIOS display of message */
  1141. /* bit 8 SCAM disabled */
  1142. /* bit 9 Reset SCSI bus during init. */
  1143. /* bit 10 Basic Integrity Checking disabled */
  1144. /* bit 11 No verbose initialization. */
  1145. /* bit 12 SCSI parity enabled */
  1146. /* bit 13 AIPP (Asyn. Info. Ph. Prot.) dis. */
  1147. /* bit 14 */
  1148. /* bit 15 */
  1149. ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
  1150. ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
  1151. uchar max_host_qng; /* 15 maximum host queueing */
  1152. uchar max_dvc_qng; /* maximum per device queuing */
  1153. ushort dvc_cntl; /* 16 control bit for driver */
  1154. ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
  1155. ushort serial_number_word1; /* 18 Board serial number word 1 */
  1156. ushort serial_number_word2; /* 19 Board serial number word 2 */
  1157. ushort serial_number_word3; /* 20 Board serial number word 3 */
  1158. ushort check_sum; /* 21 EEP check sum */
  1159. uchar oem_name[16]; /* 22 OEM name */
  1160. ushort dvc_err_code; /* 30 last device driver error code */
  1161. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  1162. ushort adv_err_addr; /* 32 last uc error address */
  1163. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  1164. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  1165. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  1166. ushort reserved36; /* 36 reserved */
  1167. ushort reserved37; /* 37 reserved */
  1168. ushort reserved38; /* 38 reserved */
  1169. ushort reserved39; /* 39 reserved */
  1170. ushort reserved40; /* 40 reserved */
  1171. ushort reserved41; /* 41 reserved */
  1172. ushort reserved42; /* 42 reserved */
  1173. ushort reserved43; /* 43 reserved */
  1174. ushort reserved44; /* 44 reserved */
  1175. ushort reserved45; /* 45 reserved */
  1176. ushort reserved46; /* 46 reserved */
  1177. ushort reserved47; /* 47 reserved */
  1178. ushort reserved48; /* 48 reserved */
  1179. ushort reserved49; /* 49 reserved */
  1180. ushort reserved50; /* 50 reserved */
  1181. ushort reserved51; /* 51 reserved */
  1182. ushort reserved52; /* 52 reserved */
  1183. ushort reserved53; /* 53 reserved */
  1184. ushort reserved54; /* 54 reserved */
  1185. ushort reserved55; /* 55 reserved */
  1186. ushort cisptr_lsw; /* 56 CIS PTR LSW */
  1187. ushort cisprt_msw; /* 57 CIS PTR MSW */
  1188. ushort subsysvid; /* 58 SubSystem Vendor ID */
  1189. ushort subsysid; /* 59 SubSystem ID */
  1190. ushort reserved60; /* 60 reserved */
  1191. ushort reserved61; /* 61 reserved */
  1192. ushort reserved62; /* 62 reserved */
  1193. ushort reserved63; /* 63 reserved */
  1194. } ADVEEP_38C1600_CONFIG;
  1195. /*
  1196. * EEPROM Commands
  1197. */
  1198. #define ASC_EEP_CMD_DONE 0x0200
  1199. /* bios_ctrl */
  1200. #define BIOS_CTRL_BIOS 0x0001
  1201. #define BIOS_CTRL_EXTENDED_XLAT 0x0002
  1202. #define BIOS_CTRL_GT_2_DISK 0x0004
  1203. #define BIOS_CTRL_BIOS_REMOVABLE 0x0008
  1204. #define BIOS_CTRL_BOOTABLE_CD 0x0010
  1205. #define BIOS_CTRL_MULTIPLE_LUN 0x0040
  1206. #define BIOS_CTRL_DISPLAY_MSG 0x0080
  1207. #define BIOS_CTRL_NO_SCAM 0x0100
  1208. #define BIOS_CTRL_RESET_SCSI_BUS 0x0200
  1209. #define BIOS_CTRL_INIT_VERBOSE 0x0800
  1210. #define BIOS_CTRL_SCSI_PARITY 0x1000
  1211. #define BIOS_CTRL_AIPP_DIS 0x2000
  1212. #define ADV_3550_MEMSIZE 0x2000 /* 8 KB Internal Memory */
  1213. #define ADV_38C0800_MEMSIZE 0x4000 /* 16 KB Internal Memory */
  1214. /*
  1215. * XXX - Since ASC38C1600 Rev.3 has a local RAM failure issue, there is
  1216. * a special 16K Adv Library and Microcode version. After the issue is
  1217. * resolved, should restore 32K support.
  1218. *
  1219. * #define ADV_38C1600_MEMSIZE 0x8000L * 32 KB Internal Memory *
  1220. */
  1221. #define ADV_38C1600_MEMSIZE 0x4000 /* 16 KB Internal Memory */
  1222. /*
  1223. * Byte I/O register address from base of 'iop_base'.
  1224. */
  1225. #define IOPB_INTR_STATUS_REG 0x00
  1226. #define IOPB_CHIP_ID_1 0x01
  1227. #define IOPB_INTR_ENABLES 0x02
  1228. #define IOPB_CHIP_TYPE_REV 0x03
  1229. #define IOPB_RES_ADDR_4 0x04
  1230. #define IOPB_RES_ADDR_5 0x05
  1231. #define IOPB_RAM_DATA 0x06
  1232. #define IOPB_RES_ADDR_7 0x07
  1233. #define IOPB_FLAG_REG 0x08
  1234. #define IOPB_RES_ADDR_9 0x09
  1235. #define IOPB_RISC_CSR 0x0A
  1236. #define IOPB_RES_ADDR_B 0x0B
  1237. #define IOPB_RES_ADDR_C 0x0C
  1238. #define IOPB_RES_ADDR_D 0x0D
  1239. #define IOPB_SOFT_OVER_WR 0x0E
  1240. #define IOPB_RES_ADDR_F 0x0F
  1241. #define IOPB_MEM_CFG 0x10
  1242. #define IOPB_RES_ADDR_11 0x11
  1243. #define IOPB_GPIO_DATA 0x12
  1244. #define IOPB_RES_ADDR_13 0x13
  1245. #define IOPB_FLASH_PAGE 0x14
  1246. #define IOPB_RES_ADDR_15 0x15
  1247. #define IOPB_GPIO_CNTL 0x16
  1248. #define IOPB_RES_ADDR_17 0x17
  1249. #define IOPB_FLASH_DATA 0x18
  1250. #define IOPB_RES_ADDR_19 0x19
  1251. #define IOPB_RES_ADDR_1A 0x1A
  1252. #define IOPB_RES_ADDR_1B 0x1B
  1253. #define IOPB_RES_ADDR_1C 0x1C
  1254. #define IOPB_RES_ADDR_1D 0x1D
  1255. #define IOPB_RES_ADDR_1E 0x1E
  1256. #define IOPB_RES_ADDR_1F 0x1F
  1257. #define IOPB_DMA_CFG0 0x20
  1258. #define IOPB_DMA_CFG1 0x21
  1259. #define IOPB_TICKLE 0x22
  1260. #define IOPB_DMA_REG_WR 0x23
  1261. #define IOPB_SDMA_STATUS 0x24
  1262. #define IOPB_SCSI_BYTE_CNT 0x25
  1263. #define IOPB_HOST_BYTE_CNT 0x26
  1264. #define IOPB_BYTE_LEFT_TO_XFER 0x27
  1265. #define IOPB_BYTE_TO_XFER_0 0x28
  1266. #define IOPB_BYTE_TO_XFER_1 0x29
  1267. #define IOPB_BYTE_TO_XFER_2 0x2A
  1268. #define IOPB_BYTE_TO_XFER_3 0x2B
  1269. #define IOPB_ACC_GRP 0x2C
  1270. #define IOPB_RES_ADDR_2D 0x2D
  1271. #define IOPB_DEV_ID 0x2E
  1272. #define IOPB_RES_ADDR_2F 0x2F
  1273. #define IOPB_SCSI_DATA 0x30
  1274. #define IOPB_RES_ADDR_31 0x31
  1275. #define IOPB_RES_ADDR_32 0x32
  1276. #define IOPB_SCSI_DATA_HSHK 0x33
  1277. #define IOPB_SCSI_CTRL 0x34
  1278. #define IOPB_RES_ADDR_35 0x35
  1279. #define IOPB_RES_ADDR_36 0x36
  1280. #define IOPB_RES_ADDR_37 0x37
  1281. #define IOPB_RAM_BIST 0x38
  1282. #define IOPB_PLL_TEST 0x39
  1283. #define IOPB_PCI_INT_CFG 0x3A
  1284. #define IOPB_RES_ADDR_3B 0x3B
  1285. #define IOPB_RFIFO_CNT 0x3C
  1286. #define IOPB_RES_ADDR_3D 0x3D
  1287. #define IOPB_RES_ADDR_3E 0x3E
  1288. #define IOPB_RES_ADDR_3F 0x3F
  1289. /*
  1290. * Word I/O register address from base of 'iop_base'.
  1291. */
  1292. #define IOPW_CHIP_ID_0 0x00 /* CID0 */
  1293. #define IOPW_CTRL_REG 0x02 /* CC */
  1294. #define IOPW_RAM_ADDR 0x04 /* LA */
  1295. #define IOPW_RAM_DATA 0x06 /* LD */
  1296. #define IOPW_RES_ADDR_08 0x08
  1297. #define IOPW_RISC_CSR 0x0A /* CSR */
  1298. #define IOPW_SCSI_CFG0 0x0C /* CFG0 */
  1299. #define IOPW_SCSI_CFG1 0x0E /* CFG1 */
  1300. #define IOPW_RES_ADDR_10 0x10
  1301. #define IOPW_SEL_MASK 0x12 /* SM */
  1302. #define IOPW_RES_ADDR_14 0x14
  1303. #define IOPW_FLASH_ADDR 0x16 /* FA */
  1304. #define IOPW_RES_ADDR_18 0x18
  1305. #define IOPW_EE_CMD 0x1A /* EC */
  1306. #define IOPW_EE_DATA 0x1C /* ED */
  1307. #define IOPW_SFIFO_CNT 0x1E /* SFC */
  1308. #define IOPW_RES_ADDR_20 0x20
  1309. #define IOPW_Q_BASE 0x22 /* QB */
  1310. #define IOPW_QP 0x24 /* QP */
  1311. #define IOPW_IX 0x26 /* IX */
  1312. #define IOPW_SP 0x28 /* SP */
  1313. #define IOPW_PC 0x2A /* PC */
  1314. #define IOPW_RES_ADDR_2C 0x2C
  1315. #define IOPW_RES_ADDR_2E 0x2E
  1316. #define IOPW_SCSI_DATA 0x30 /* SD */
  1317. #define IOPW_SCSI_DATA_HSHK 0x32 /* SDH */
  1318. #define IOPW_SCSI_CTRL 0x34 /* SC */
  1319. #define IOPW_HSHK_CFG 0x36 /* HCFG */
  1320. #define IOPW_SXFR_STATUS 0x36 /* SXS */
  1321. #define IOPW_SXFR_CNTL 0x38 /* SXL */
  1322. #define IOPW_SXFR_CNTH 0x3A /* SXH */
  1323. #define IOPW_RES_ADDR_3C 0x3C
  1324. #define IOPW_RFIFO_DATA 0x3E /* RFD */
  1325. /*
  1326. * Doubleword I/O register address from base of 'iop_base'.
  1327. */
  1328. #define IOPDW_RES_ADDR_0 0x00
  1329. #define IOPDW_RAM_DATA 0x04
  1330. #define IOPDW_RES_ADDR_8 0x08
  1331. #define IOPDW_RES_ADDR_C 0x0C
  1332. #define IOPDW_RES_ADDR_10 0x10
  1333. #define IOPDW_COMMA 0x14
  1334. #define IOPDW_COMMB 0x18
  1335. #define IOPDW_RES_ADDR_1C 0x1C
  1336. #define IOPDW_SDMA_ADDR0 0x20
  1337. #define IOPDW_SDMA_ADDR1 0x24
  1338. #define IOPDW_SDMA_COUNT 0x28
  1339. #define IOPDW_SDMA_ERROR 0x2C
  1340. #define IOPDW_RDMA_ADDR0 0x30
  1341. #define IOPDW_RDMA_ADDR1 0x34
  1342. #define IOPDW_RDMA_COUNT 0x38
  1343. #define IOPDW_RDMA_ERROR 0x3C
  1344. #define ADV_CHIP_ID_BYTE 0x25
  1345. #define ADV_CHIP_ID_WORD 0x04C1
  1346. #define ADV_INTR_ENABLE_HOST_INTR 0x01
  1347. #define ADV_INTR_ENABLE_SEL_INTR 0x02
  1348. #define ADV_INTR_ENABLE_DPR_INTR 0x04
  1349. #define ADV_INTR_ENABLE_RTA_INTR 0x08
  1350. #define ADV_INTR_ENABLE_RMA_INTR 0x10
  1351. #define ADV_INTR_ENABLE_RST_INTR 0x20
  1352. #define ADV_INTR_ENABLE_DPE_INTR 0x40
  1353. #define ADV_INTR_ENABLE_GLOBAL_INTR 0x80
  1354. #define ADV_INTR_STATUS_INTRA 0x01
  1355. #define ADV_INTR_STATUS_INTRB 0x02
  1356. #define ADV_INTR_STATUS_INTRC 0x04
  1357. #define ADV_RISC_CSR_STOP (0x0000)
  1358. #define ADV_RISC_TEST_COND (0x2000)
  1359. #define ADV_RISC_CSR_RUN (0x4000)
  1360. #define ADV_RISC_CSR_SINGLE_STEP (0x8000)
  1361. #define ADV_CTRL_REG_HOST_INTR 0x0100
  1362. #define ADV_CTRL_REG_SEL_INTR 0x0200
  1363. #define ADV_CTRL_REG_DPR_INTR 0x0400
  1364. #define ADV_CTRL_REG_RTA_INTR 0x0800
  1365. #define ADV_CTRL_REG_RMA_INTR 0x1000
  1366. #define ADV_CTRL_REG_RES_BIT14 0x2000
  1367. #define ADV_CTRL_REG_DPE_INTR 0x4000
  1368. #define ADV_CTRL_REG_POWER_DONE 0x8000
  1369. #define ADV_CTRL_REG_ANY_INTR 0xFF00
  1370. #define ADV_CTRL_REG_CMD_RESET 0x00C6
  1371. #define ADV_CTRL_REG_CMD_WR_IO_REG 0x00C5
  1372. #define ADV_CTRL_REG_CMD_RD_IO_REG 0x00C4
  1373. #define ADV_CTRL_REG_CMD_WR_PCI_CFG_SPACE 0x00C3
  1374. #define ADV_CTRL_REG_CMD_RD_PCI_CFG_SPACE 0x00C2
  1375. #define ADV_TICKLE_NOP 0x00
  1376. #define ADV_TICKLE_A 0x01
  1377. #define ADV_TICKLE_B 0x02
  1378. #define ADV_TICKLE_C 0x03
  1379. #define AdvIsIntPending(port) \
  1380. (AdvReadWordRegister(port, IOPW_CTRL_REG) & ADV_CTRL_REG_HOST_INTR)
  1381. /*
  1382. * SCSI_CFG0 Register bit definitions
  1383. */
  1384. #define TIMER_MODEAB 0xC000 /* Watchdog, Second, and Select. Timer Ctrl. */
  1385. #define PARITY_EN 0x2000 /* Enable SCSI Parity Error detection */
  1386. #define EVEN_PARITY 0x1000 /* Select Even Parity */
  1387. #define WD_LONG 0x0800 /* Watchdog Interval, 1: 57 min, 0: 13 sec */
  1388. #define QUEUE_128 0x0400 /* Queue Size, 1: 128 byte, 0: 64 byte */
  1389. #define PRIM_MODE 0x0100 /* Primitive SCSI mode */
  1390. #define SCAM_EN 0x0080 /* Enable SCAM selection */
  1391. #define SEL_TMO_LONG 0x0040 /* Sel/Resel Timeout, 1: 400 ms, 0: 1.6 ms */
  1392. #define CFRM_ID 0x0020 /* SCAM id sel. confirm., 1: fast, 0: 6.4 ms */
  1393. #define OUR_ID_EN 0x0010 /* Enable OUR_ID bits */
  1394. #define OUR_ID 0x000F /* SCSI ID */
  1395. /*
  1396. * SCSI_CFG1 Register bit definitions
  1397. */
  1398. #define BIG_ENDIAN 0x8000 /* Enable Big Endian Mode MIO:15, EEP:15 */
  1399. #define TERM_POL 0x2000 /* Terminator Polarity Ctrl. MIO:13, EEP:13 */
  1400. #define SLEW_RATE 0x1000 /* SCSI output buffer slew rate */
  1401. #define FILTER_SEL 0x0C00 /* Filter Period Selection */
  1402. #define FLTR_DISABLE 0x0000 /* Input Filtering Disabled */
  1403. #define FLTR_11_TO_20NS 0x0800 /* Input Filtering 11ns to 20ns */
  1404. #define FLTR_21_TO_39NS 0x0C00 /* Input Filtering 21ns to 39ns */
  1405. #define ACTIVE_DBL 0x0200 /* Disable Active Negation */
  1406. #define DIFF_MODE 0x0100 /* SCSI differential Mode (Read-Only) */
  1407. #define DIFF_SENSE 0x0080 /* 1: No SE cables, 0: SE cable (Read-Only) */
  1408. #define TERM_CTL_SEL 0x0040 /* Enable TERM_CTL_H and TERM_CTL_L */
  1409. #define TERM_CTL 0x0030 /* External SCSI Termination Bits */
  1410. #define TERM_CTL_H 0x0020 /* Enable External SCSI Upper Termination */
  1411. #define TERM_CTL_L 0x0010 /* Enable External SCSI Lower Termination */
  1412. #define CABLE_DETECT 0x000F /* External SCSI Cable Connection Status */
  1413. /*
  1414. * Addendum for ASC-38C0800 Chip
  1415. *
  1416. * The ASC-38C1600 Chip uses the same definitions except that the
  1417. * bus mode override bits [12:10] have been moved to byte register
  1418. * offset 0xE (IOPB_SOFT_OVER_WR) bits [12:10]. The [12:10] bits in
  1419. * SCSI_CFG1 are read-only and always available. Bit 14 (DIS_TERM_DRV)
  1420. * is not needed. The [12:10] bits in IOPB_SOFT_OVER_WR are write-only.
  1421. * Also each ASC-38C1600 function or channel uses only cable bits [5:4]
  1422. * and [1:0]. Bits [14], [7:6], [3:2] are unused.
  1423. */
  1424. #define DIS_TERM_DRV 0x4000 /* 1: Read c_det[3:0], 0: cannot read */
  1425. #define HVD_LVD_SE 0x1C00 /* Device Detect Bits */
  1426. #define HVD 0x1000 /* HVD Device Detect */
  1427. #define LVD 0x0800 /* LVD Device Detect */
  1428. #define SE 0x0400 /* SE Device Detect */
  1429. #define TERM_LVD 0x00C0 /* LVD Termination Bits */
  1430. #define TERM_LVD_HI 0x0080 /* Enable LVD Upper Termination */
  1431. #define TERM_LVD_LO 0x0040 /* Enable LVD Lower Termination */
  1432. #define TERM_SE 0x0030 /* SE Termination Bits */
  1433. #define TERM_SE_HI 0x0020 /* Enable SE Upper Termination */
  1434. #define TERM_SE_LO 0x0010 /* Enable SE Lower Termination */
  1435. #define C_DET_LVD 0x000C /* LVD Cable Detect Bits */
  1436. #define C_DET3 0x0008 /* Cable Detect for LVD External Wide */
  1437. #define C_DET2 0x0004 /* Cable Detect for LVD Internal Wide */
  1438. #define C_DET_SE 0x0003 /* SE Cable Detect Bits */
  1439. #define C_DET1 0x0002 /* Cable Detect for SE Internal Wide */
  1440. #define C_DET0 0x0001 /* Cable Detect for SE Internal Narrow */
  1441. #define CABLE_ILLEGAL_A 0x7
  1442. /* x 0 0 0 | on on | Illegal (all 3 connectors are used) */
  1443. #define CABLE_ILLEGAL_B 0xB
  1444. /* 0 x 0 0 | on on | Illegal (all 3 connectors are used) */
  1445. /*
  1446. * MEM_CFG Register bit definitions
  1447. */
  1448. #define BIOS_EN 0x40 /* BIOS Enable MIO:14,EEP:14 */
  1449. #define FAST_EE_CLK 0x20 /* Diagnostic Bit */
  1450. #define RAM_SZ 0x1C /* Specify size of RAM to RISC */
  1451. #define RAM_SZ_2KB 0x00 /* 2 KB */
  1452. #define RAM_SZ_4KB 0x04 /* 4 KB */
  1453. #define RAM_SZ_8KB 0x08 /* 8 KB */
  1454. #define RAM_SZ_16KB 0x0C /* 16 KB */
  1455. #define RAM_SZ_32KB 0x10 /* 32 KB */
  1456. #define RAM_SZ_64KB 0x14 /* 64 KB */
  1457. /*
  1458. * DMA_CFG0 Register bit definitions
  1459. *
  1460. * This register is only accessible to the host.
  1461. */
  1462. #define BC_THRESH_ENB 0x80 /* PCI DMA Start Conditions */
  1463. #define FIFO_THRESH 0x70 /* PCI DMA FIFO Threshold */
  1464. #define FIFO_THRESH_16B 0x00 /* 16 bytes */
  1465. #define FIFO_THRESH_32B 0x20 /* 32 bytes */
  1466. #define FIFO_THRESH_48B 0x30 /* 48 bytes */
  1467. #define FIFO_THRESH_64B 0x40 /* 64 bytes */
  1468. #define FIFO_THRESH_80B 0x50 /* 80 bytes (default) */
  1469. #define FIFO_THRESH_96B 0x60 /* 96 bytes */
  1470. #define FIFO_THRESH_112B 0x70 /* 112 bytes */
  1471. #define START_CTL 0x0C /* DMA start conditions */
  1472. #define START_CTL_TH 0x00 /* Wait threshold level (default) */
  1473. #define START_CTL_ID 0x04 /* Wait SDMA/SBUS idle */
  1474. #define START_CTL_THID 0x08 /* Wait threshold and SDMA/SBUS idle */
  1475. #define START_CTL_EMFU 0x0C /* Wait SDMA FIFO empty/full */
  1476. #define READ_CMD 0x03 /* Memory Read Method */
  1477. #define READ_CMD_MR 0x00 /* Memory Read */
  1478. #define READ_CMD_MRL 0x02 /* Memory Read Long */
  1479. #define READ_CMD_MRM 0x03 /* Memory Read Multiple (default) */
  1480. /*
  1481. * ASC-38C0800 RAM BIST Register bit definitions
  1482. */
  1483. #define RAM_TEST_MODE 0x80
  1484. #define PRE_TEST_MODE 0x40
  1485. #define NORMAL_MODE 0x00
  1486. #define RAM_TEST_DONE 0x10
  1487. #define RAM_TEST_STATUS 0x0F
  1488. #define RAM_TEST_HOST_ERROR 0x08
  1489. #define RAM_TEST_INTRAM_ERROR 0x04
  1490. #define RAM_TEST_RISC_ERROR 0x02
  1491. #define RAM_TEST_SCSI_ERROR 0x01
  1492. #define RAM_TEST_SUCCESS 0x00
  1493. #define PRE_TEST_VALUE 0x05
  1494. #define NORMAL_VALUE 0x00
  1495. /*
  1496. * ASC38C1600 Definitions
  1497. *
  1498. * IOPB_PCI_INT_CFG Bit Field Definitions
  1499. */
  1500. #define INTAB_LD 0x80 /* Value loaded from EEPROM Bit 11. */
  1501. /*
  1502. * Bit 1 can be set to change the interrupt for the Function to operate in
  1503. * Totem Pole mode. By default Bit 1 is 0 and the interrupt operates in
  1504. * Open Drain mode. Both functions of the ASC38C1600 must be set to the same
  1505. * mode, otherwise the operating mode is undefined.
  1506. */
  1507. #define TOTEMPOLE 0x02
  1508. /*
  1509. * Bit 0 can be used to change the Int Pin for the Function. The value is
  1510. * 0 by default for both Functions with Function 0 using INT A and Function
  1511. * B using INT B. For Function 0 if set, INT B is used. For Function 1 if set,
  1512. * INT A is used.
  1513. *
  1514. * EEPROM Word 0 Bit 11 for each Function may change the initial Int Pin
  1515. * value specified in the PCI Configuration Space.
  1516. */
  1517. #define INTAB 0x01
  1518. /*
  1519. * Adv Library Status Definitions
  1520. */
  1521. #define ADV_TRUE 1
  1522. #define ADV_FALSE 0
  1523. #define ADV_SUCCESS 1
  1524. #define ADV_BUSY 0
  1525. #define ADV_ERROR (-1)
  1526. /*
  1527. * ADV_DVC_VAR 'warn_code' values
  1528. */
  1529. #define ASC_WARN_BUSRESET_ERROR 0x0001 /* SCSI Bus Reset error */
  1530. #define ASC_WARN_EEPROM_CHKSUM 0x0002 /* EEP check sum error */
  1531. #define ASC_WARN_EEPROM_TERMINATION 0x0004 /* EEP termination bad field */
  1532. #define ASC_WARN_ERROR 0xFFFF /* ADV_ERROR return */
  1533. #define ADV_MAX_TID 15 /* max. target identifier */
  1534. #define ADV_MAX_LUN 7 /* max. logical unit number */
  1535. /*
  1536. * Fixed locations of microcode operating variables.
  1537. */
  1538. #define ASC_MC_CODE_BEGIN_ADDR 0x0028 /* microcode start address */
  1539. #define ASC_MC_CODE_END_ADDR 0x002A /* microcode end address */
  1540. #define ASC_MC_CODE_CHK_SUM 0x002C /* microcode code checksum */
  1541. #define ASC_MC_VERSION_DATE 0x0038 /* microcode version */
  1542. #define ASC_MC_VERSION_NUM 0x003A /* microcode number */
  1543. #define ASC_MC_BIOSMEM 0x0040 /* BIOS RISC Memory Start */
  1544. #define ASC_MC_BIOSLEN 0x0050 /* BIOS RISC Memory Length */
  1545. #define ASC_MC_BIOS_SIGNATURE 0x0058 /* BIOS Signature 0x55AA */
  1546. #define ASC_MC_BIOS_VERSION 0x005A /* BIOS Version (2 bytes) */
  1547. #define ASC_MC_SDTR_SPEED1 0x0090 /* SDTR Speed for TID 0-3 */
  1548. #define ASC_MC_SDTR_SPEED2 0x0092 /* SDTR Speed for TID 4-7 */
  1549. #define ASC_MC_SDTR_SPEED3 0x0094 /* SDTR Speed for TID 8-11 */
  1550. #define ASC_MC_SDTR_SPEED4 0x0096 /* SDTR Speed for TID 12-15 */
  1551. #define ASC_MC_CHIP_TYPE 0x009A
  1552. #define ASC_MC_INTRB_CODE 0x009B
  1553. #define ASC_MC_WDTR_ABLE 0x009C
  1554. #define ASC_MC_SDTR_ABLE 0x009E
  1555. #define ASC_MC_TAGQNG_ABLE 0x00A0
  1556. #define ASC_MC_DISC_ENABLE 0x00A2
  1557. #define ASC_MC_IDLE_CMD_STATUS 0x00A4
  1558. #define ASC_MC_IDLE_CMD 0x00A6
  1559. #define ASC_MC_IDLE_CMD_PARAMETER 0x00A8
  1560. #define ASC_MC_DEFAULT_SCSI_CFG0 0x00AC
  1561. #define ASC_MC_DEFAULT_SCSI_CFG1 0x00AE
  1562. #define ASC_MC_DEFAULT_MEM_CFG 0x00B0
  1563. #define ASC_MC_DEFAULT_SEL_MASK 0x00B2
  1564. #define ASC_MC_SDTR_DONE 0x00B6
  1565. #define ASC_MC_NUMBER_OF_QUEUED_CMD 0x00C0
  1566. #define ASC_MC_NUMBER_OF_MAX_CMD 0x00D0
  1567. #define ASC_MC_DEVICE_HSHK_CFG_TABLE 0x0100
  1568. #define ASC_MC_CONTROL_FLAG 0x0122 /* Microcode control flag. */
  1569. #define ASC_MC_WDTR_DONE 0x0124
  1570. #define ASC_MC_CAM_MODE_MASK 0x015E /* CAM mode TID bitmask. */
  1571. #define ASC_MC_ICQ 0x0160
  1572. #define ASC_MC_IRQ 0x0164
  1573. #define ASC_MC_PPR_ABLE 0x017A
  1574. /*
  1575. * BIOS LRAM variable absolute offsets.
  1576. */
  1577. #define BIOS_CODESEG 0x54
  1578. #define BIOS_CODELEN 0x56
  1579. #define BIOS_SIGNATURE 0x58
  1580. #define BIOS_VERSION 0x5A
  1581. /*
  1582. * Microcode Control Flags
  1583. *
  1584. * Flags set by the Adv Library in RISC variable 'control_flag' (0x122)
  1585. * and handled by the microcode.
  1586. */
  1587. #define CONTROL_FLAG_IGNORE_PERR 0x0001 /* Ignore DMA Parity Errors */
  1588. #define CONTROL_FLAG_ENABLE_AIPP 0x0002 /* Enabled AIPP checking. */
  1589. /*
  1590. * ASC_MC_DEVICE_HSHK_CFG_TABLE microcode table or HSHK_CFG register format
  1591. */
  1592. #define HSHK_CFG_WIDE_XFR 0x8000
  1593. #define HSHK_CFG_RATE 0x0F00
  1594. #define HSHK_CFG_OFFSET 0x001F
  1595. #define ASC_DEF_MAX_HOST_QNG 0xFD /* Max. number of host commands (253) */
  1596. #define ASC_DEF_MIN_HOST_QNG 0x10 /* Min. number of host commands (16) */
  1597. #define ASC_DEF_MAX_DVC_QNG 0x3F /* Max. number commands per device (63) */
  1598. #define ASC_DEF_MIN_DVC_QNG 0x04 /* Min. number commands per device (4) */
  1599. #define ASC_QC_DATA_CHECK 0x01 /* Require ASC_QC_DATA_OUT set or clear. */
  1600. #define ASC_QC_DATA_OUT 0x02 /* Data out DMA transfer. */
  1601. #define ASC_QC_START_MOTOR 0x04 /* Send auto-start motor before request. */
  1602. #define ASC_QC_NO_OVERRUN 0x08 /* Don't report overrun. */
  1603. #define ASC_QC_FREEZE_TIDQ 0x10 /* Freeze TID queue after request. XXX TBD */
  1604. #define ASC_QSC_NO_DISC 0x01 /* Don't allow disconnect for request. */
  1605. #define ASC_QSC_NO_TAGMSG 0x02 /* Don't allow tag queuing for request. */
  1606. #define ASC_QSC_NO_SYNC 0x04 /* Don't use Synch. transfer on request. */
  1607. #define ASC_QSC_NO_WIDE 0x08 /* Don't use Wide transfer on request. */
  1608. #define ASC_QSC_REDO_DTR 0x10 /* Renegotiate WDTR/SDTR before request. */
  1609. /*
  1610. * Note: If a Tag Message is to be sent and neither ASC_QSC_HEAD_TAG or
  1611. * ASC_QSC_ORDERED_TAG is set, then a Simple Tag Message (0x20) is used.
  1612. */
  1613. #define ASC_QSC_HEAD_TAG 0x40 /* Use Head Tag Message (0x21). */
  1614. #define ASC_QSC_ORDERED_TAG 0x80 /* Use Ordered Tag Message (0x22). */
  1615. /*
  1616. * All fields here are accessed by the board microcode and need to be
  1617. * little-endian.
  1618. */
  1619. typedef struct adv_carr_t {
  1620. ADV_VADDR carr_va; /* Carrier Virtual Address */
  1621. ADV_PADDR carr_pa; /* Carrier Physical Address */
  1622. ADV_VADDR areq_vpa; /* ASC_SCSI_REQ_Q Virtual or Physical Address */
  1623. /*
  1624. * next_vpa [31:4] Carrier Virtual or Physical Next Pointer
  1625. *
  1626. * next_vpa [3:1] Reserved Bits
  1627. * next_vpa [0] Done Flag set in Response Queue.
  1628. */
  1629. ADV_VADDR next_vpa;
  1630. } ADV_CARR_T;
  1631. /*
  1632. * Mask used to eliminate low 4 bits of carrier 'next_vpa' field.
  1633. */
  1634. #define ASC_NEXT_VPA_MASK 0xFFFFFFF0
  1635. #define ASC_RQ_DONE 0x00000001
  1636. #define ASC_RQ_GOOD 0x00000002
  1637. #define ASC_CQ_STOPPER 0x00000000
  1638. #define ASC_GET_CARRP(carrp) ((carrp) & ASC_NEXT_VPA_MASK)
  1639. #define ADV_CARRIER_NUM_PAGE_CROSSING \
  1640. (((ADV_CARRIER_COUNT * sizeof(ADV_CARR_T)) + (PAGE_SIZE - 1))/PAGE_SIZE)
  1641. #define ADV_CARRIER_BUFSIZE \
  1642. ((ADV_CARRIER_COUNT + ADV_CARRIER_NUM_PAGE_CROSSING) * sizeof(ADV_CARR_T))
  1643. /*
  1644. * ASC_SCSI_REQ_Q 'a_flag' definitions
  1645. *
  1646. * The Adv Library should limit use to the lower nibble (4 bits) of
  1647. * a_flag. Drivers are free to use the upper nibble (4 bits) of a_flag.
  1648. */
  1649. #define ADV_POLL_REQUEST 0x01 /* poll for request completion */
  1650. #define ADV_SCSIQ_DONE 0x02 /* request done */
  1651. #define ADV_DONT_RETRY 0x08 /* don't do retry */
  1652. #define ADV_CHIP_ASC3550 0x01 /* Ultra-Wide IC */
  1653. #define ADV_CHIP_ASC38C0800 0x02 /* Ultra2-Wide/LVD IC */
  1654. #define ADV_CHIP_ASC38C1600 0x03 /* Ultra3-Wide/LVD2 IC */
  1655. /*
  1656. * Adapter temporary configuration structure
  1657. *
  1658. * This structure can be discarded after initialization. Don't add
  1659. * fields here needed after initialization.
  1660. *
  1661. * Field naming convention:
  1662. *
  1663. * *_enable indicates the field enables or disables a feature. The
  1664. * value of the field is never reset.
  1665. */
  1666. typedef struct adv_dvc_cfg {
  1667. ushort disc_enable; /* enable disconnection */
  1668. uchar chip_version; /* chip version */
  1669. uchar termination; /* Term. Ctrl. bits 6-5 of SCSI_CFG1 register */
  1670. ushort control_flag; /* Microcode Control Flag */
  1671. ushort mcode_date; /* Microcode date */
  1672. ushort mcode_version; /* Microcode version */
  1673. ushort serial1; /* EEPROM serial number word 1 */
  1674. ushort serial2; /* EEPROM serial number word 2 */
  1675. ushort serial3; /* EEPROM serial number word 3 */
  1676. } ADV_DVC_CFG;
  1677. struct adv_dvc_var;
  1678. struct adv_scsi_req_q;
  1679. typedef struct asc_sg_block {
  1680. uchar reserved1;
  1681. uchar reserved2;
  1682. uchar reserved3;
  1683. uchar sg_cnt; /* Valid entries in block. */
  1684. ADV_PADDR sg_ptr; /* Pointer to next sg block. */
  1685. struct {
  1686. ADV_PADDR sg_addr; /* SG element address. */
  1687. ADV_DCNT sg_count; /* SG element count. */
  1688. } sg_list[NO_OF_SG_PER_BLOCK];
  1689. } ADV_SG_BLOCK;
  1690. /*
  1691. * ADV_SCSI_REQ_Q - microcode request structure
  1692. *
  1693. * All fields in this structure up to byte 60 are used by the microcode.
  1694. * The microcode makes assumptions about the size and ordering of fields
  1695. * in this structure. Do not change the structure definition here without
  1696. * coordinating the change with the microcode.
  1697. *
  1698. * All fields accessed by microcode must be maintained in little_endian
  1699. * order.
  1700. */
  1701. typedef struct adv_scsi_req_q {
  1702. uchar cntl; /* Ucode flags and state (ASC_MC_QC_*). */
  1703. uchar target_cmd;
  1704. uchar target_id; /* Device target identifier. */
  1705. uchar target_lun; /* Device target logical unit number. */
  1706. ADV_PADDR data_addr; /* Data buffer physical address. */
  1707. ADV_DCNT data_cnt; /* Data count. Ucode sets to residual. */
  1708. ADV_PADDR sense_addr;
  1709. ADV_PADDR carr_pa;
  1710. uchar mflag;
  1711. uchar sense_len;
  1712. uchar cdb_len; /* SCSI CDB length. Must <= 16 bytes. */
  1713. uchar scsi_cntl;
  1714. uchar done_status; /* Completion status. */
  1715. uchar scsi_status; /* SCSI status byte. */
  1716. uchar host_status; /* Ucode host status. */
  1717. uchar sg_working_ix;
  1718. uchar cdb[12]; /* SCSI CDB bytes 0-11. */
  1719. ADV_PADDR sg_real_addr; /* SG list physical address. */
  1720. ADV_PADDR scsiq_rptr;
  1721. uchar cdb16[4]; /* SCSI CDB bytes 12-15. */
  1722. ADV_VADDR scsiq_ptr;
  1723. ADV_VADDR carr_va;
  1724. /*
  1725. * End of microcode structure - 60 bytes. The rest of the structure
  1726. * is used by the Adv Library and ignored by the microcode.
  1727. */
  1728. ADV_VADDR srb_ptr;
  1729. ADV_SG_BLOCK *sg_list_ptr; /* SG list virtual address. */
  1730. char *vdata_addr; /* Data buffer virtual address. */
  1731. uchar a_flag;
  1732. uchar pad[2]; /* Pad out to a word boundary. */
  1733. } ADV_SCSI_REQ_Q;
  1734. /*
  1735. * The following two structures are used to process Wide Board requests.
  1736. *
  1737. * The ADV_SCSI_REQ_Q structure in adv_req_t is passed to the Adv Library
  1738. * and microcode with the ADV_SCSI_REQ_Q field 'srb_ptr' pointing to the
  1739. * adv_req_t. The adv_req_t structure 'cmndp' field in turn points to the
  1740. * Mid-Level SCSI request structure.
  1741. *
  1742. * Zero or more ADV_SG_BLOCK are used with each ADV_SCSI_REQ_Q. Each
  1743. * ADV_SG_BLOCK structure holds 15 scatter-gather elements. Under Linux
  1744. * up to 255 scatter-gather elements may be used per request or
  1745. * ADV_SCSI_REQ_Q.
  1746. *
  1747. * Both structures must be 32 byte aligned.
  1748. */
  1749. typedef struct adv_sgblk {
  1750. ADV_SG_BLOCK sg_block; /* Sgblock structure. */
  1751. uchar align[32]; /* Sgblock structure padding. */
  1752. struct adv_sgblk *next_sgblkp; /* Next scatter-gather structure. */
  1753. } adv_sgblk_t;
  1754. typedef struct adv_req {
  1755. ADV_SCSI_REQ_Q scsi_req_q; /* Adv Library request structure. */
  1756. uchar align[32]; /* Request structure padding. */
  1757. struct scsi_cmnd *cmndp; /* Mid-Level SCSI command pointer. */
  1758. adv_sgblk_t *sgblkp; /* Adv Library scatter-gather pointer. */
  1759. struct adv_req *next_reqp; /* Next Request Structure. */
  1760. } adv_req_t;
  1761. /*
  1762. * Adapter operation variable structure.
  1763. *
  1764. * One structure is required per host adapter.
  1765. *
  1766. * Field naming convention:
  1767. *
  1768. * *_able indicates both whether a feature should be enabled or disabled
  1769. * and whether a device isi capable of the feature. At initialization
  1770. * this field may be set, but later if a device is found to be incapable
  1771. * of the feature, the field is cleared.
  1772. */
  1773. typedef struct adv_dvc_var {
  1774. AdvPortAddr iop_base; /* I/O port address */
  1775. ushort err_code; /* fatal error code */
  1776. ushort bios_ctrl; /* BIOS control word, EEPROM word 12 */
  1777. ushort wdtr_able; /* try WDTR for a device */
  1778. ushort sdtr_able; /* try SDTR for a device */
  1779. ushort ultra_able; /* try SDTR Ultra speed for a device */
  1780. ushort sdtr_speed1; /* EEPROM SDTR Speed for TID 0-3 */
  1781. ushort sdtr_speed2; /* EEPROM SDTR Speed for TID 4-7 */
  1782. ushort sdtr_speed3; /* EEPROM SDTR Speed for TID 8-11 */
  1783. ushort sdtr_speed4; /* EEPROM SDTR Speed for TID 12-15 */
  1784. ushort tagqng_able; /* try tagged queuing with a device */
  1785. ushort ppr_able; /* PPR message capable per TID bitmask. */
  1786. uchar max_dvc_qng; /* maximum number of tagged commands per device */
  1787. ushort start_motor; /* start motor command allowed */
  1788. uchar scsi_reset_wait; /* delay in seconds after scsi bus reset */
  1789. uchar chip_no; /* should be assigned by caller */
  1790. uchar max_host_qng; /* maximum number of Q'ed command allowed */
  1791. ushort no_scam; /* scam_tolerant of EEPROM */
  1792. struct asc_board *drv_ptr; /* driver pointer to private structure */
  1793. uchar chip_scsi_id; /* chip SCSI target ID */
  1794. uchar chip_type;
  1795. uchar bist_err_code;
  1796. ADV_CARR_T *carrier_buf;
  1797. ADV_CARR_T *carr_freelist; /* Carrier free list. */
  1798. ADV_CARR_T *icq_sp; /* Initiator command queue stopper pointer. */
  1799. ADV_CARR_T *irq_sp; /* Initiator response queue stopper pointer. */
  1800. ushort carr_pending_cnt; /* Count of pending carriers. */
  1801. struct adv_req *orig_reqp; /* adv_req_t memory block. */
  1802. /*
  1803. * Note: The following fields will not be used after initialization. The
  1804. * driver may discard the buffer after initialization is done.
  1805. */
  1806. ADV_DVC_CFG *cfg; /* temporary configuration structure */
  1807. } ADV_DVC_VAR;
  1808. /*
  1809. * Microcode idle loop commands
  1810. */
  1811. #define IDLE_CMD_COMPLETED 0
  1812. #define IDLE_CMD_STOP_CHIP 0x0001
  1813. #define IDLE_CMD_STOP_CHIP_SEND_INT 0x0002
  1814. #define IDLE_CMD_SEND_INT 0x0004
  1815. #define IDLE_CMD_ABORT 0x0008
  1816. #define IDLE_CMD_DEVICE_RESET 0x0010
  1817. #define IDLE_CMD_SCSI_RESET_START 0x0020 /* Assert SCSI Bus Reset */
  1818. #define IDLE_CMD_SCSI_RESET_END 0x0040 /* Deassert SCSI Bus Reset */
  1819. #define IDLE_CMD_SCSIREQ 0x0080
  1820. #define IDLE_CMD_STATUS_SUCCESS 0x0001
  1821. #define IDLE_CMD_STATUS_FAILURE 0x0002
  1822. /*
  1823. * AdvSendIdleCmd() flag definitions.
  1824. */
  1825. #define ADV_NOWAIT 0x01
  1826. /*
  1827. * Wait loop time out values.
  1828. */
  1829. #define SCSI_WAIT_100_MSEC 100UL /* 100 milliseconds */
  1830. #define SCSI_US_PER_MSEC 1000 /* microseconds per millisecond */
  1831. #define SCSI_MAX_RETRY 10 /* retry count */
  1832. #define ADV_ASYNC_RDMA_FAILURE 0x01 /* Fatal RDMA failure. */
  1833. #define ADV_ASYNC_SCSI_BUS_RESET_DET 0x02 /* Detected SCSI Bus Reset. */
  1834. #define ADV_ASYNC_CARRIER_READY_FAILURE 0x03 /* Carrier Ready failure. */
  1835. #define ADV_RDMA_IN_CARR_AND_Q_INVALID 0x04 /* RDMAed-in data invalid. */
  1836. #define ADV_HOST_SCSI_BUS_RESET 0x80 /* Host Initiated SCSI Bus Reset. */
  1837. /* Read byte from a register. */
  1838. #define AdvReadByteRegister(iop_base, reg_off) \
  1839. (ADV_MEM_READB((iop_base) + (reg_off)))
  1840. /* Write byte to a register. */
  1841. #define AdvWriteByteRegister(iop_base, reg_off, byte) \
  1842. (ADV_MEM_WRITEB((iop_base) + (reg_off), (byte)))
  1843. /* Read word (2 bytes) from a register. */
  1844. #define AdvReadWordRegister(iop_base, reg_off) \
  1845. (ADV_MEM_READW((iop_base) + (reg_off)))
  1846. /* Write word (2 bytes) to a register. */
  1847. #define AdvWriteWordRegister(iop_base, reg_off, word) \
  1848. (ADV_MEM_WRITEW((iop_base) + (reg_off), (word)))
  1849. /* Write dword (4 bytes) to a register. */
  1850. #define AdvWriteDWordRegister(iop_base, reg_off, dword) \
  1851. (ADV_MEM_WRITEDW((iop_base) + (reg_off), (dword)))
  1852. /* Read byte from LRAM. */
  1853. #define AdvReadByteLram(iop_base, addr, byte) \
  1854. do { \
  1855. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
  1856. (byte) = ADV_MEM_READB((iop_base) + IOPB_RAM_DATA); \
  1857. } while (0)
  1858. /* Write byte to LRAM. */
  1859. #define AdvWriteByteLram(iop_base, addr, byte) \
  1860. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1861. ADV_MEM_WRITEB((iop_base) + IOPB_RAM_DATA, (byte)))
  1862. /* Read word (2 bytes) from LRAM. */
  1863. #define AdvReadWordLram(iop_base, addr, word) \
  1864. do { \
  1865. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
  1866. (word) = (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA)); \
  1867. } while (0)
  1868. /* Write word (2 bytes) to LRAM. */
  1869. #define AdvWriteWordLram(iop_base, addr, word) \
  1870. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1871. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
  1872. /* Write little-endian double word (4 bytes) to LRAM */
  1873. /* Because of unspecified C language ordering don't use auto-increment. */
  1874. #define AdvWriteDWordLramNoSwap(iop_base, addr, dword) \
  1875. ((ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1876. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
  1877. cpu_to_le16((ushort) ((dword) & 0xFFFF)))), \
  1878. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr) + 2), \
  1879. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
  1880. cpu_to_le16((ushort) ((dword >> 16) & 0xFFFF)))))
  1881. /* Read word (2 bytes) from LRAM assuming that the address is already set. */
  1882. #define AdvReadWordAutoIncLram(iop_base) \
  1883. (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA))
  1884. /* Write word (2 bytes) to LRAM assuming that the address is already set. */
  1885. #define AdvWriteWordAutoIncLram(iop_base, word) \
  1886. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
  1887. /*
  1888. * Define macro to check for Condor signature.
  1889. *
  1890. * Evaluate to ADV_TRUE if a Condor chip is found the specified port
  1891. * address 'iop_base'. Otherwise evalue to ADV_FALSE.
  1892. */
  1893. #define AdvFindSignature(iop_base) \
  1894. (((AdvReadByteRegister((iop_base), IOPB_CHIP_ID_1) == \
  1895. ADV_CHIP_ID_BYTE) && \
  1896. (AdvReadWordRegister((iop_base), IOPW_CHIP_ID_0) == \
  1897. ADV_CHIP_ID_WORD)) ? ADV_TRUE : ADV_FALSE)
  1898. /*
  1899. * Define macro to Return the version number of the chip at 'iop_base'.
  1900. *
  1901. * The second parameter 'bus_type' is currently unused.
  1902. */
  1903. #define AdvGetChipVersion(iop_base, bus_type) \
  1904. AdvReadByteRegister((iop_base), IOPB_CHIP_TYPE_REV)
  1905. /*
  1906. * Abort an SRB in the chip's RISC Memory. The 'srb_ptr' argument must
  1907. * match the ASC_SCSI_REQ_Q 'srb_ptr' field.
  1908. *
  1909. * If the request has not yet been sent to the device it will simply be
  1910. * aborted from RISC memory. If the request is disconnected it will be
  1911. * aborted on reselection by sending an Abort Message to the target ID.
  1912. *
  1913. * Return value:
  1914. * ADV_TRUE(1) - Queue was successfully aborted.
  1915. * ADV_FALSE(0) - Queue was not found on the active queue list.
  1916. */
  1917. #define AdvAbortQueue(asc_dvc, scsiq) \
  1918. AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_ABORT, \
  1919. (ADV_DCNT) (scsiq))
  1920. /*
  1921. * Send a Bus Device Reset Message to the specified target ID.
  1922. *
  1923. * All outstanding commands will be purged if sending the
  1924. * Bus Device Reset Message is successful.
  1925. *
  1926. * Return Value:
  1927. * ADV_TRUE(1) - All requests on the target are purged.
  1928. * ADV_FALSE(0) - Couldn't issue Bus Device Reset Message; Requests
  1929. * are not purged.
  1930. */
  1931. #define AdvResetDevice(asc_dvc, target_id) \
  1932. AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_DEVICE_RESET, \
  1933. (ADV_DCNT) (target_id))
  1934. /*
  1935. * SCSI Wide Type definition.
  1936. */
  1937. #define ADV_SCSI_BIT_ID_TYPE ushort
  1938. /*
  1939. * AdvInitScsiTarget() 'cntl_flag' options.
  1940. */
  1941. #define ADV_SCAN_LUN 0x01
  1942. #define ADV_CAPINFO_NOLUN 0x02
  1943. /*
  1944. * Convert target id to target id bit mask.
  1945. */
  1946. #define ADV_TID_TO_TIDMASK(tid) (0x01 << ((tid) & ADV_MAX_TID))
  1947. /*
  1948. * ASC_SCSI_REQ_Q 'done_status' and 'host_status' return values.
  1949. */
  1950. #define QD_NO_STATUS 0x00 /* Request not completed yet. */
  1951. #define QD_NO_ERROR 0x01
  1952. #define QD_ABORTED_BY_HOST 0x02
  1953. #define QD_WITH_ERROR 0x04
  1954. #define QHSTA_NO_ERROR 0x00
  1955. #define QHSTA_M_SEL_TIMEOUT 0x11
  1956. #define QHSTA_M_DATA_OVER_RUN 0x12
  1957. #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
  1958. #define QHSTA_M_QUEUE_ABORTED 0x15
  1959. #define QHSTA_M_SXFR_SDMA_ERR 0x16 /* SXFR_STATUS SCSI DMA Error */
  1960. #define QHSTA_M_SXFR_SXFR_PERR 0x17 /* SXFR_STATUS SCSI Bus Parity Error */
  1961. #define QHSTA_M_RDMA_PERR 0x18 /* RISC PCI DMA parity error */
  1962. #define QHSTA_M_SXFR_OFF_UFLW 0x19 /* SXFR_STATUS Offset Underflow */
  1963. #define QHSTA_M_SXFR_OFF_OFLW 0x20 /* SXFR_STATUS Offset Overflow */
  1964. #define QHSTA_M_SXFR_WD_TMO 0x21 /* SXFR_STATUS Watchdog Timeout */
  1965. #define QHSTA_M_SXFR_DESELECTED 0x22 /* SXFR_STATUS Deselected */
  1966. /* Note: QHSTA_M_SXFR_XFR_OFLW is identical to QHSTA_M_DATA_OVER_RUN. */
  1967. #define QHSTA_M_SXFR_XFR_OFLW 0x12 /* SXFR_STATUS Transfer Overflow */
  1968. #define QHSTA_M_SXFR_XFR_PH_ERR 0x24 /* SXFR_STATUS Transfer Phase Error */
  1969. #define QHSTA_M_SXFR_UNKNOWN_ERROR 0x25 /* SXFR_STATUS Unknown Error */
  1970. #define QHSTA_M_SCSI_BUS_RESET 0x30 /* Request aborted from SBR */
  1971. #define QHSTA_M_SCSI_BUS_RESET_UNSOL 0x31 /* Request aborted from unsol. SBR */
  1972. #define QHSTA_M_BUS_DEVICE_RESET 0x32 /* Request aborted from BDR */
  1973. #define QHSTA_M_DIRECTION_ERR 0x35 /* Data Phase mismatch */
  1974. #define QHSTA_M_DIRECTION_ERR_HUNG 0x36 /* Data Phase mismatch and bus hang */
  1975. #define QHSTA_M_WTM_TIMEOUT 0x41
  1976. #define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
  1977. #define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
  1978. #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
  1979. #define QHSTA_M_INVALID_DEVICE 0x45 /* Bad target ID */
  1980. #define QHSTA_M_FROZEN_TIDQ 0x46 /* TID Queue frozen. */
  1981. #define QHSTA_M_SGBACKUP_ERROR 0x47 /* Scatter-Gather backup error */
  1982. /* Return the address that is aligned at the next doubleword >= to 'addr'. */
  1983. #define ADV_8BALIGN(addr) (((ulong) (addr) + 0x7) & ~0x7)
  1984. #define ADV_16BALIGN(addr) (((ulong) (addr) + 0xF) & ~0xF)
  1985. #define ADV_32BALIGN(addr) (((ulong) (addr) + 0x1F) & ~0x1F)
  1986. /*
  1987. * Total contiguous memory needed for driver SG blocks.
  1988. *
  1989. * ADV_MAX_SG_LIST must be defined by a driver. It is the maximum
  1990. * number of scatter-gather elements the driver supports in a
  1991. * single request.
  1992. */
  1993. #define ADV_SG_LIST_MAX_BYTE_SIZE \
  1994. (sizeof(ADV_SG_BLOCK) * \
  1995. ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK))
  1996. /* struct asc_board flags */
  1997. #define ASC_IS_WIDE_BOARD 0x04 /* AdvanSys Wide Board */
  1998. #define ASC_NARROW_BOARD(boardp) (((boardp)->flags & ASC_IS_WIDE_BOARD) == 0)
  1999. #define NO_ISA_DMA 0xff /* No ISA DMA Channel Used */
  2000. #define ASC_INFO_SIZE 128 /* advansys_info() line size */
  2001. #ifdef CONFIG_PROC_FS
  2002. /* /proc/scsi/advansys/[0...] related definitions */
  2003. #define ASC_PRTBUF_SIZE 2048
  2004. #define ASC_PRTLINE_SIZE 160
  2005. #define ASC_PRT_NEXT() \
  2006. if (cp) { \
  2007. totlen += len; \
  2008. leftlen -= len; \
  2009. if (leftlen == 0) { \
  2010. return totlen; \
  2011. } \
  2012. cp += len; \
  2013. }
  2014. #endif /* CONFIG_PROC_FS */
  2015. /* Asc Library return codes */
  2016. #define ASC_TRUE 1
  2017. #define ASC_FALSE 0
  2018. #define ASC_NOERROR 1
  2019. #define ASC_BUSY 0
  2020. #define ASC_ERROR (-1)
  2021. /* struct scsi_cmnd function return codes */
  2022. #define STATUS_BYTE(byte) (byte)
  2023. #define MSG_BYTE(byte) ((byte) << 8)
  2024. #define HOST_BYTE(byte) ((byte) << 16)
  2025. #define DRIVER_BYTE(byte) ((byte) << 24)
  2026. #define ASC_STATS(shost, counter) ASC_STATS_ADD(shost, counter, 1)
  2027. #ifndef ADVANSYS_STATS
  2028. #define ASC_STATS_ADD(shost, counter, count)
  2029. #else /* ADVANSYS_STATS */
  2030. #define ASC_STATS_ADD(shost, counter, count) \
  2031. (((struct asc_board *) shost_priv(shost))->asc_stats.counter += (count))
  2032. #endif /* ADVANSYS_STATS */
  2033. /* If the result wraps when calculating tenths, return 0. */
  2034. #define ASC_TENTHS(num, den) \
  2035. (((10 * ((num)/(den))) > (((num) * 10)/(den))) ? \
  2036. 0 : ((((num) * 10)/(den)) - (10 * ((num)/(den)))))
  2037. /*
  2038. * Display a message to the console.
  2039. */
  2040. #define ASC_PRINT(s) \
  2041. { \
  2042. printk("advansys: "); \
  2043. printk(s); \
  2044. }
  2045. #define ASC_PRINT1(s, a1) \
  2046. { \
  2047. printk("advansys: "); \
  2048. printk((s), (a1)); \
  2049. }
  2050. #define ASC_PRINT2(s, a1, a2) \
  2051. { \
  2052. printk("advansys: "); \
  2053. printk((s), (a1), (a2)); \
  2054. }
  2055. #define ASC_PRINT3(s, a1, a2, a3) \
  2056. { \
  2057. printk("advansys: "); \
  2058. printk((s), (a1), (a2), (a3)); \
  2059. }
  2060. #define ASC_PRINT4(s, a1, a2, a3, a4) \
  2061. { \
  2062. printk("advansys: "); \
  2063. printk((s), (a1), (a2), (a3), (a4)); \
  2064. }
  2065. #ifndef ADVANSYS_DEBUG
  2066. #define ASC_DBG(lvl, s...)
  2067. #define ASC_DBG_PRT_SCSI_HOST(lvl, s)
  2068. #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp)
  2069. #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
  2070. #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone)
  2071. #define ADV_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
  2072. #define ASC_DBG_PRT_HEX(lvl, name, start, length)
  2073. #define ASC_DBG_PRT_CDB(lvl, cdb, len)
  2074. #define ASC_DBG_PRT_SENSE(lvl, sense, len)
  2075. #define ASC_DBG_PRT_INQUIRY(lvl, inq, len)
  2076. #else /* ADVANSYS_DEBUG */
  2077. /*
  2078. * Debugging Message Levels:
  2079. * 0: Errors Only
  2080. * 1: High-Level Tracing
  2081. * 2-N: Verbose Tracing
  2082. */
  2083. #define ASC_DBG(lvl, format, arg...) { \
  2084. if (asc_dbglvl >= (lvl)) \
  2085. printk(KERN_DEBUG "%s: %s: " format, DRV_NAME, \
  2086. __func__ , ## arg); \
  2087. }
  2088. #define ASC_DBG_PRT_SCSI_HOST(lvl, s) \
  2089. { \
  2090. if (asc_dbglvl >= (lvl)) { \
  2091. asc_prt_scsi_host(s); \
  2092. } \
  2093. }
  2094. #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp) \
  2095. { \
  2096. if (asc_dbglvl >= (lvl)) { \
  2097. asc_prt_asc_scsi_q(scsiqp); \
  2098. } \
  2099. }
  2100. #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone) \
  2101. { \
  2102. if (asc_dbglvl >= (lvl)) { \
  2103. asc_prt_asc_qdone_info(qdone); \
  2104. } \
  2105. }
  2106. #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp) \
  2107. { \
  2108. if (asc_dbglvl >= (lvl)) { \
  2109. asc_prt_adv_scsi_req_q(scsiqp); \
  2110. } \
  2111. }
  2112. #define ASC_DBG_PRT_HEX(lvl, name, start, length) \
  2113. { \
  2114. if (asc_dbglvl >= (lvl)) { \
  2115. asc_prt_hex((name), (start), (length)); \
  2116. } \
  2117. }
  2118. #define ASC_DBG_PRT_CDB(lvl, cdb, len) \
  2119. ASC_DBG_PRT_HEX((lvl), "CDB", (uchar *) (cdb), (len));
  2120. #define ASC_DBG_PRT_SENSE(lvl, sense, len) \
  2121. ASC_DBG_PRT_HEX((lvl), "SENSE", (uchar *) (sense), (len));
  2122. #define ASC_DBG_PRT_INQUIRY(lvl, inq, len) \
  2123. ASC_DBG_PRT_HEX((lvl), "INQUIRY", (uchar *) (inq), (len));
  2124. #endif /* ADVANSYS_DEBUG */
  2125. #ifdef ADVANSYS_STATS
  2126. /* Per board statistics structure */
  2127. struct asc_stats {
  2128. /* Driver Entrypoint Statistics */
  2129. ADV_DCNT queuecommand; /* # calls to advansys_queuecommand() */
  2130. ADV_DCNT reset; /* # calls to advansys_eh_bus_reset() */
  2131. ADV_DCNT biosparam; /* # calls to advansys_biosparam() */
  2132. ADV_DCNT interrupt; /* # advansys_interrupt() calls */
  2133. ADV_DCNT callback; /* # calls to asc/adv_isr_callback() */
  2134. ADV_DCNT done; /* # calls to request's scsi_done function */
  2135. ADV_DCNT build_error; /* # asc/adv_build_req() ASC_ERROR returns. */
  2136. ADV_DCNT adv_build_noreq; /* # adv_build_req() adv_req_t alloc. fail. */
  2137. ADV_DCNT adv_build_nosg; /* # adv_build_req() adv_sgblk_t alloc. fail. */
  2138. /* AscExeScsiQueue()/AdvExeScsiQueue() Statistics */
  2139. ADV_DCNT exe_noerror; /* # ASC_NOERROR returns. */
  2140. ADV_DCNT exe_busy; /* # ASC_BUSY returns. */
  2141. ADV_DCNT exe_error; /* # ASC_ERROR returns. */
  2142. ADV_DCNT exe_unknown; /* # unknown returns. */
  2143. /* Data Transfer Statistics */
  2144. ADV_DCNT xfer_cnt; /* # I/O requests received */
  2145. ADV_DCNT xfer_elem; /* # scatter-gather elements */
  2146. ADV_DCNT xfer_sect; /* # 512-byte blocks */
  2147. };
  2148. #endif /* ADVANSYS_STATS */
  2149. /*
  2150. * Structure allocated for each board.
  2151. *
  2152. * This structure is allocated by scsi_host_alloc() at the end
  2153. * of the 'Scsi_Host' structure starting at the 'hostdata'
  2154. * field. It is guaranteed to be allocated from DMA-able memory.
  2155. */
  2156. struct asc_board {
  2157. struct device *dev;
  2158. uint flags; /* Board flags */
  2159. unsigned int irq;
  2160. union {
  2161. ASC_DVC_VAR asc_dvc_var; /* Narrow board */
  2162. ADV_DVC_VAR adv_dvc_var; /* Wide board */
  2163. } dvc_var;
  2164. union {
  2165. ASC_DVC_CFG asc_dvc_cfg; /* Narrow board */
  2166. ADV_DVC_CFG adv_dvc_cfg; /* Wide board */
  2167. } dvc_cfg;
  2168. ushort asc_n_io_port; /* Number I/O ports. */
  2169. ADV_SCSI_BIT_ID_TYPE init_tidmask; /* Target init./valid mask */
  2170. ushort reqcnt[ADV_MAX_TID + 1]; /* Starvation request count */
  2171. ADV_SCSI_BIT_ID_TYPE queue_full; /* Queue full mask */
  2172. ushort queue_full_cnt[ADV_MAX_TID + 1]; /* Queue full count */
  2173. union {
  2174. ASCEEP_CONFIG asc_eep; /* Narrow EEPROM config. */
  2175. ADVEEP_3550_CONFIG adv_3550_eep; /* 3550 EEPROM config. */
  2176. ADVEEP_38C0800_CONFIG adv_38C0800_eep; /* 38C0800 EEPROM config. */
  2177. ADVEEP_38C1600_CONFIG adv_38C1600_eep; /* 38C1600 EEPROM config. */
  2178. } eep_config;
  2179. ulong last_reset; /* Saved last reset time */
  2180. /* /proc/scsi/advansys/[0...] */
  2181. char *prtbuf; /* /proc print buffer */
  2182. #ifdef ADVANSYS_STATS
  2183. struct asc_stats asc_stats; /* Board statistics */
  2184. #endif /* ADVANSYS_STATS */
  2185. /*
  2186. * The following fields are used only for Narrow Boards.
  2187. */
  2188. uchar sdtr_data[ASC_MAX_TID + 1]; /* SDTR information */
  2189. /*
  2190. * The following fields are used only for Wide Boards.
  2191. */
  2192. void __iomem *ioremap_addr; /* I/O Memory remap address. */
  2193. ushort ioport; /* I/O Port address. */
  2194. adv_req_t *adv_reqp; /* Request structures. */
  2195. adv_sgblk_t *adv_sgblkp; /* Scatter-gather structures. */
  2196. ushort bios_signature; /* BIOS Signature. */
  2197. ushort bios_version; /* BIOS Version. */
  2198. ushort bios_codeseg; /* BIOS Code Segment. */
  2199. ushort bios_codelen; /* BIOS Code Segment Length. */
  2200. };
  2201. #define asc_dvc_to_board(asc_dvc) container_of(asc_dvc, struct asc_board, \
  2202. dvc_var.asc_dvc_var)
  2203. #define adv_dvc_to_board(adv_dvc) container_of(adv_dvc, struct asc_board, \
  2204. dvc_var.adv_dvc_var)
  2205. #define adv_dvc_to_pdev(adv_dvc) to_pci_dev(adv_dvc_to_board(adv_dvc)->dev)
  2206. #ifdef ADVANSYS_DEBUG
  2207. static int asc_dbglvl = 3;
  2208. /*
  2209. * asc_prt_asc_dvc_var()
  2210. */
  2211. static void asc_prt_asc_dvc_var(ASC_DVC_VAR *h)
  2212. {
  2213. printk("ASC_DVC_VAR at addr 0x%lx\n", (ulong)h);
  2214. printk(" iop_base 0x%x, err_code 0x%x, dvc_cntl 0x%x, bug_fix_cntl "
  2215. "%d,\n", h->iop_base, h->err_code, h->dvc_cntl, h->bug_fix_cntl);
  2216. printk(" bus_type %d, init_sdtr 0x%x,\n", h->bus_type,
  2217. (unsigned)h->init_sdtr);
  2218. printk(" sdtr_done 0x%x, use_tagged_qng 0x%x, unit_not_ready 0x%x, "
  2219. "chip_no 0x%x,\n", (unsigned)h->sdtr_done,
  2220. (unsigned)h->use_tagged_qng, (unsigned)h->unit_not_ready,
  2221. (unsigned)h->chip_no);
  2222. printk(" queue_full_or_busy 0x%x, start_motor 0x%x, scsi_reset_wait "
  2223. "%u,\n", (unsigned)h->queue_full_or_busy,
  2224. (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
  2225. printk(" is_in_int %u, max_total_qng %u, cur_total_qng %u, "
  2226. "in_critical_cnt %u,\n", (unsigned)h->is_in_int,
  2227. (unsigned)h->max_total_qng, (unsigned)h->cur_total_qng,
  2228. (unsigned)h->in_critical_cnt);
  2229. printk(" last_q_shortage %u, init_state 0x%x, no_scam 0x%x, "
  2230. "pci_fix_asyn_xfer 0x%x,\n", (unsigned)h->last_q_shortage,
  2231. (unsigned)h->init_state, (unsigned)h->no_scam,
  2232. (unsigned)h->pci_fix_asyn_xfer);
  2233. printk(" cfg 0x%lx\n", (ulong)h->cfg);
  2234. }
  2235. /*
  2236. * asc_prt_asc_dvc_cfg()
  2237. */
  2238. static void asc_prt_asc_dvc_cfg(ASC_DVC_CFG *h)
  2239. {
  2240. printk("ASC_DVC_CFG at addr 0x%lx\n", (ulong)h);
  2241. printk(" can_tagged_qng 0x%x, cmd_qng_enabled 0x%x,\n",
  2242. h->can_tagged_qng, h->cmd_qng_enabled);
  2243. printk(" disc_enable 0x%x, sdtr_enable 0x%x,\n",
  2244. h->disc_enable, h->sdtr_enable);
  2245. printk(" chip_scsi_id %d, isa_dma_speed %d, isa_dma_channel %d, "
  2246. "chip_version %d,\n", h->chip_scsi_id, h->isa_dma_speed,
  2247. h->isa_dma_channel, h->chip_version);
  2248. printk(" mcode_date 0x%x, mcode_version %d\n",
  2249. h->mcode_date, h->mcode_version);
  2250. }
  2251. /*
  2252. * asc_prt_adv_dvc_var()
  2253. *
  2254. * Display an ADV_DVC_VAR structure.
  2255. */
  2256. static void asc_prt_adv_dvc_var(ADV_DVC_VAR *h)
  2257. {
  2258. printk(" ADV_DVC_VAR at addr 0x%lx\n", (ulong)h);
  2259. printk(" iop_base 0x%lx, err_code 0x%x, ultra_able 0x%x\n",
  2260. (ulong)h->iop_base, h->err_code, (unsigned)h->ultra_able);
  2261. printk(" sdtr_able 0x%x, wdtr_able 0x%x\n",
  2262. (unsigned)h->sdtr_able, (unsigned)h->wdtr_able);
  2263. printk(" start_motor 0x%x, scsi_reset_wait 0x%x\n",
  2264. (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
  2265. printk(" max_host_qng %u, max_dvc_qng %u, carr_freelist 0x%lxn\n",
  2266. (unsigned)h->max_host_qng, (unsigned)h->max_dvc_qng,
  2267. (ulong)h->carr_freelist);
  2268. printk(" icq_sp 0x%lx, irq_sp 0x%lx\n",
  2269. (ulong)h->icq_sp, (ulong)h->irq_sp);
  2270. printk(" no_scam 0x%x, tagqng_able 0x%x\n",
  2271. (unsigned)h->no_scam, (unsigned)h->tagqng_able);
  2272. printk(" chip_scsi_id 0x%x, cfg 0x%lx\n",
  2273. (unsigned)h->chip_scsi_id, (ulong)h->cfg);
  2274. }
  2275. /*
  2276. * asc_prt_adv_dvc_cfg()
  2277. *
  2278. * Display an ADV_DVC_CFG structure.
  2279. */
  2280. static void asc_prt_adv_dvc_cfg(ADV_DVC_CFG *h)
  2281. {
  2282. printk(" ADV_DVC_CFG at addr 0x%lx\n", (ulong)h);
  2283. printk(" disc_enable 0x%x, termination 0x%x\n",
  2284. h->disc_enable, h->termination);
  2285. printk(" chip_version 0x%x, mcode_date 0x%x\n",
  2286. h->chip_version, h->mcode_date);
  2287. printk(" mcode_version 0x%x, control_flag 0x%x\n",
  2288. h->mcode_version, h->control_flag);
  2289. }
  2290. /*
  2291. * asc_prt_scsi_host()
  2292. */
  2293. static void asc_prt_scsi_host(struct Scsi_Host *s)
  2294. {
  2295. struct asc_board *boardp = shost_priv(s);
  2296. printk("Scsi_Host at addr 0x%p, device %s\n", s, dev_name(boardp->dev));
  2297. printk(" host_busy %u, host_no %d, last_reset %d,\n",
  2298. s->host_busy, s->host_no, (unsigned)s->last_reset);
  2299. printk(" base 0x%lx, io_port 0x%lx, irq %d,\n",
  2300. (ulong)s->base, (ulong)s->io_port, boardp->irq);
  2301. printk(" dma_channel %d, this_id %d, can_queue %d,\n",
  2302. s->dma_channel, s->this_id, s->can_queue);
  2303. printk(" cmd_per_lun %d, sg_tablesize %d, unchecked_isa_dma %d\n",
  2304. s->cmd_per_lun, s->sg_tablesize, s->unchecked_isa_dma);
  2305. if (ASC_NARROW_BOARD(boardp)) {
  2306. asc_prt_asc_dvc_var(&boardp->dvc_var.asc_dvc_var);
  2307. asc_prt_asc_dvc_cfg(&boardp->dvc_cfg.asc_dvc_cfg);
  2308. } else {
  2309. asc_prt_adv_dvc_var(&boardp->dvc_var.adv_dvc_var);
  2310. asc_prt_adv_dvc_cfg(&boardp->dvc_cfg.adv_dvc_cfg);
  2311. }
  2312. }
  2313. /*
  2314. * asc_prt_hex()
  2315. *
  2316. * Print hexadecimal output in 4 byte groupings 32 bytes
  2317. * or 8 double-words per line.
  2318. */
  2319. static void asc_prt_hex(char *f, uchar *s, int l)
  2320. {
  2321. int i;
  2322. int j;
  2323. int k;
  2324. int m;
  2325. printk("%s: (%d bytes)\n", f, l);
  2326. for (i = 0; i < l; i += 32) {
  2327. /* Display a maximum of 8 double-words per line. */
  2328. if ((k = (l - i) / 4) >= 8) {
  2329. k = 8;
  2330. m = 0;
  2331. } else {
  2332. m = (l - i) % 4;
  2333. }
  2334. for (j = 0; j < k; j++) {
  2335. printk(" %2.2X%2.2X%2.2X%2.2X",
  2336. (unsigned)s[i + (j * 4)],
  2337. (unsigned)s[i + (j * 4) + 1],
  2338. (unsigned)s[i + (j * 4) + 2],
  2339. (unsigned)s[i + (j * 4) + 3]);
  2340. }
  2341. switch (m) {
  2342. case 0:
  2343. default:
  2344. break;
  2345. case 1:
  2346. printk(" %2.2X", (unsigned)s[i + (j * 4)]);
  2347. break;
  2348. case 2:
  2349. printk(" %2.2X%2.2X",
  2350. (unsigned)s[i + (j * 4)],
  2351. (unsigned)s[i + (j * 4) + 1]);
  2352. break;
  2353. case 3:
  2354. printk(" %2.2X%2.2X%2.2X",
  2355. (unsigned)s[i + (j * 4) + 1],
  2356. (unsigned)s[i + (j * 4) + 2],
  2357. (unsigned)s[i + (j * 4) + 3]);
  2358. break;
  2359. }
  2360. printk("\n");
  2361. }
  2362. }
  2363. /*
  2364. * asc_prt_asc_scsi_q()
  2365. */
  2366. static void asc_prt_asc_scsi_q(ASC_SCSI_Q *q)
  2367. {
  2368. ASC_SG_HEAD *sgp;
  2369. int i;
  2370. printk("ASC_SCSI_Q at addr 0x%lx\n", (ulong)q);
  2371. printk
  2372. (" target_ix 0x%x, target_lun %u, srb_ptr 0x%lx, tag_code 0x%x,\n",
  2373. q->q2.target_ix, q->q1.target_lun, (ulong)q->q2.srb_ptr,
  2374. q->q2.tag_code);
  2375. printk
  2376. (" data_addr 0x%lx, data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
  2377. (ulong)le32_to_cpu(q->q1.data_addr),
  2378. (ulong)le32_to_cpu(q->q1.data_cnt),
  2379. (ulong)le32_to_cpu(q->q1.sense_addr), q->q1.sense_len);
  2380. printk(" cdbptr 0x%lx, cdb_len %u, sg_head 0x%lx, sg_queue_cnt %u\n",
  2381. (ulong)q->cdbptr, q->q2.cdb_len,
  2382. (ulong)q->sg_head, q->q1.sg_queue_cnt);
  2383. if (q->sg_head) {
  2384. sgp = q->sg_head;
  2385. printk("ASC_SG_HEAD at addr 0x%lx\n", (ulong)sgp);
  2386. printk(" entry_cnt %u, queue_cnt %u\n", sgp->entry_cnt,
  2387. sgp->queue_cnt);
  2388. for (i = 0; i < sgp->entry_cnt; i++) {
  2389. printk(" [%u]: addr 0x%lx, bytes %lu\n",
  2390. i, (ulong)le32_to_cpu(sgp->sg_list[i].addr),
  2391. (ulong)le32_to_cpu(sgp->sg_list[i].bytes));
  2392. }
  2393. }
  2394. }
  2395. /*
  2396. * asc_prt_asc_qdone_info()
  2397. */
  2398. static void asc_prt_asc_qdone_info(ASC_QDONE_INFO *q)
  2399. {
  2400. printk("ASC_QDONE_INFO at addr 0x%lx\n", (ulong)q);
  2401. printk(" srb_ptr 0x%lx, target_ix %u, cdb_len %u, tag_code %u,\n",
  2402. (ulong)q->d2.srb_ptr, q->d2.target_ix, q->d2.cdb_len,
  2403. q->d2.tag_code);
  2404. printk
  2405. (" done_stat 0x%x, host_stat 0x%x, scsi_stat 0x%x, scsi_msg 0x%x\n",
  2406. q->d3.done_stat, q->d3.host_stat, q->d3.scsi_stat, q->d3.scsi_msg);
  2407. }
  2408. /*
  2409. * asc_prt_adv_sgblock()
  2410. *
  2411. * Display an ADV_SG_BLOCK structure.
  2412. */
  2413. static void asc_prt_adv_sgblock(int sgblockno, ADV_SG_BLOCK *b)
  2414. {
  2415. int i;
  2416. printk(" ASC_SG_BLOCK at addr 0x%lx (sgblockno %d)\n",
  2417. (ulong)b, sgblockno);
  2418. printk(" sg_cnt %u, sg_ptr 0x%lx\n",
  2419. b->sg_cnt, (ulong)le32_to_cpu(b->sg_ptr));
  2420. BUG_ON(b->sg_cnt > NO_OF_SG_PER_BLOCK);
  2421. if (b->sg_ptr != 0)
  2422. BUG_ON(b->sg_cnt != NO_OF_SG_PER_BLOCK);
  2423. for (i = 0; i < b->sg_cnt; i++) {
  2424. printk(" [%u]: sg_addr 0x%lx, sg_count 0x%lx\n",
  2425. i, (ulong)b->sg_list[i].sg_addr,
  2426. (ulong)b->sg_list[i].sg_count);
  2427. }
  2428. }
  2429. /*
  2430. * asc_prt_adv_scsi_req_q()
  2431. *
  2432. * Display an ADV_SCSI_REQ_Q structure.
  2433. */
  2434. static void asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q *q)
  2435. {
  2436. int sg_blk_cnt;
  2437. struct asc_sg_block *sg_ptr;
  2438. printk("ADV_SCSI_REQ_Q at addr 0x%lx\n", (ulong)q);
  2439. printk(" target_id %u, target_lun %u, srb_ptr 0x%lx, a_flag 0x%x\n",
  2440. q->target_id, q->target_lun, (ulong)q->srb_ptr, q->a_flag);
  2441. printk(" cntl 0x%x, data_addr 0x%lx, vdata_addr 0x%lx\n",
  2442. q->cntl, (ulong)le32_to_cpu(q->data_addr), (ulong)q->vdata_addr);
  2443. printk(" data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
  2444. (ulong)le32_to_cpu(q->data_cnt),
  2445. (ulong)le32_to_cpu(q->sense_addr), q->sense_len);
  2446. printk
  2447. (" cdb_len %u, done_status 0x%x, host_status 0x%x, scsi_status 0x%x\n",
  2448. q->cdb_len, q->done_status, q->host_status, q->scsi_status);
  2449. printk(" sg_working_ix 0x%x, target_cmd %u\n",
  2450. q->sg_working_ix, q->target_cmd);
  2451. printk(" scsiq_rptr 0x%lx, sg_real_addr 0x%lx, sg_list_ptr 0x%lx\n",
  2452. (ulong)le32_to_cpu(q->scsiq_rptr),
  2453. (ulong)le32_to_cpu(q->sg_real_addr), (ulong)q->sg_list_ptr);
  2454. /* Display the request's ADV_SG_BLOCK structures. */
  2455. if (q->sg_list_ptr != NULL) {
  2456. sg_blk_cnt = 0;
  2457. while (1) {
  2458. /*
  2459. * 'sg_ptr' is a physical address. Convert it to a virtual
  2460. * address by indexing 'sg_blk_cnt' into the virtual address
  2461. * array 'sg_list_ptr'.
  2462. *
  2463. * XXX - Assumes all SG physical blocks are virtually contiguous.
  2464. */
  2465. sg_ptr =
  2466. &(((ADV_SG_BLOCK *)(q->sg_list_ptr))[sg_blk_cnt]);
  2467. asc_prt_adv_sgblock(sg_blk_cnt, sg_ptr);
  2468. if (sg_ptr->sg_ptr == 0) {
  2469. break;
  2470. }
  2471. sg_blk_cnt++;
  2472. }
  2473. }
  2474. }
  2475. #endif /* ADVANSYS_DEBUG */
  2476. /*
  2477. * The advansys chip/microcode contains a 32-bit identifier for each command
  2478. * known as the 'srb'. I don't know what it stands for. The driver used
  2479. * to encode the scsi_cmnd pointer by calling virt_to_bus and retrieve it
  2480. * with bus_to_virt. Now the driver keeps a per-host map of integers to
  2481. * pointers. It auto-expands when full, unless it can't allocate memory.
  2482. * Note that an srb of 0 is treated specially by the chip/firmware, hence
  2483. * the return of i+1 in this routine, and the corresponding subtraction in
  2484. * the inverse routine.
  2485. */
  2486. #define BAD_SRB 0
  2487. static u32 advansys_ptr_to_srb(struct asc_dvc_var *asc_dvc, void *ptr)
  2488. {
  2489. int i;
  2490. void **new_ptr;
  2491. for (i = 0; i < asc_dvc->ptr_map_count; i++) {
  2492. if (!asc_dvc->ptr_map[i])
  2493. goto out;
  2494. }
  2495. if (asc_dvc->ptr_map_count == 0)
  2496. asc_dvc->ptr_map_count = 1;
  2497. else
  2498. asc_dvc->ptr_map_count *= 2;
  2499. new_ptr = krealloc(asc_dvc->ptr_map,
  2500. asc_dvc->ptr_map_count * sizeof(void *), GFP_ATOMIC);
  2501. if (!new_ptr)
  2502. return BAD_SRB;
  2503. asc_dvc->ptr_map = new_ptr;
  2504. out:
  2505. ASC_DBG(3, "Putting ptr %p into array offset %d\n", ptr, i);
  2506. asc_dvc->ptr_map[i] = ptr;
  2507. return i + 1;
  2508. }
  2509. static void * advansys_srb_to_ptr(struct asc_dvc_var *asc_dvc, u32 srb)
  2510. {
  2511. void *ptr;
  2512. srb--;
  2513. if (srb >= asc_dvc->ptr_map_count) {
  2514. printk("advansys: bad SRB %u, max %u\n", srb,
  2515. asc_dvc->ptr_map_count);
  2516. return NULL;
  2517. }
  2518. ptr = asc_dvc->ptr_map[srb];
  2519. asc_dvc->ptr_map[srb] = NULL;
  2520. ASC_DBG(3, "Returning ptr %p from array offset %d\n", ptr, srb);
  2521. return ptr;
  2522. }
  2523. /*
  2524. * advansys_info()
  2525. *
  2526. * Return suitable for printing on the console with the argument
  2527. * adapter's configuration information.
  2528. *
  2529. * Note: The information line should not exceed ASC_INFO_SIZE bytes,
  2530. * otherwise the static 'info' array will be overrun.
  2531. */
  2532. static const char *advansys_info(struct Scsi_Host *shost)
  2533. {
  2534. static char info[ASC_INFO_SIZE];
  2535. struct asc_board *boardp = shost_priv(shost);
  2536. ASC_DVC_VAR *asc_dvc_varp;
  2537. ADV_DVC_VAR *adv_dvc_varp;
  2538. char *busname;
  2539. char *widename = NULL;
  2540. if (ASC_NARROW_BOARD(boardp)) {
  2541. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  2542. ASC_DBG(1, "begin\n");
  2543. if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
  2544. if ((asc_dvc_varp->bus_type & ASC_IS_ISAPNP) ==
  2545. ASC_IS_ISAPNP) {
  2546. busname = "ISA PnP";
  2547. } else {
  2548. busname = "ISA";
  2549. }
  2550. sprintf(info,
  2551. "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X, DMA 0x%X",
  2552. ASC_VERSION, busname,
  2553. (ulong)shost->io_port,
  2554. (ulong)shost->io_port + ASC_IOADR_GAP - 1,
  2555. boardp->irq, shost->dma_channel);
  2556. } else {
  2557. if (asc_dvc_varp->bus_type & ASC_IS_VL) {
  2558. busname = "VL";
  2559. } else if (asc_dvc_varp->bus_type & ASC_IS_EISA) {
  2560. busname = "EISA";
  2561. } else if (asc_dvc_varp->bus_type & ASC_IS_PCI) {
  2562. if ((asc_dvc_varp->bus_type & ASC_IS_PCI_ULTRA)
  2563. == ASC_IS_PCI_ULTRA) {
  2564. busname = "PCI Ultra";
  2565. } else {
  2566. busname = "PCI";
  2567. }
  2568. } else {
  2569. busname = "?";
  2570. shost_printk(KERN_ERR, shost, "unknown bus "
  2571. "type %d\n", asc_dvc_varp->bus_type);
  2572. }
  2573. sprintf(info,
  2574. "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X",
  2575. ASC_VERSION, busname, (ulong)shost->io_port,
  2576. (ulong)shost->io_port + ASC_IOADR_GAP - 1,
  2577. boardp->irq);
  2578. }
  2579. } else {
  2580. /*
  2581. * Wide Adapter Information
  2582. *
  2583. * Memory-mapped I/O is used instead of I/O space to access
  2584. * the adapter, but display the I/O Port range. The Memory
  2585. * I/O address is displayed through the driver /proc file.
  2586. */
  2587. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  2588. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2589. widename = "Ultra-Wide";
  2590. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2591. widename = "Ultra2-Wide";
  2592. } else {
  2593. widename = "Ultra3-Wide";
  2594. }
  2595. sprintf(info,
  2596. "AdvanSys SCSI %s: PCI %s: PCIMEM 0x%lX-0x%lX, IRQ 0x%X",
  2597. ASC_VERSION, widename, (ulong)adv_dvc_varp->iop_base,
  2598. (ulong)adv_dvc_varp->iop_base + boardp->asc_n_io_port - 1, boardp->irq);
  2599. }
  2600. BUG_ON(strlen(info) >= ASC_INFO_SIZE);
  2601. ASC_DBG(1, "end\n");
  2602. return info;
  2603. }
  2604. #ifdef CONFIG_PROC_FS
  2605. /*
  2606. * asc_prt_line()
  2607. *
  2608. * If 'cp' is NULL print to the console, otherwise print to a buffer.
  2609. *
  2610. * Return 0 if printing to the console, otherwise return the number of
  2611. * bytes written to the buffer.
  2612. *
  2613. * Note: If any single line is greater than ASC_PRTLINE_SIZE bytes the stack
  2614. * will be corrupted. 's[]' is defined to be ASC_PRTLINE_SIZE bytes.
  2615. */
  2616. static int asc_prt_line(char *buf, int buflen, char *fmt, ...)
  2617. {
  2618. va_list args;
  2619. int ret;
  2620. char s[ASC_PRTLINE_SIZE];
  2621. va_start(args, fmt);
  2622. ret = vsprintf(s, fmt, args);
  2623. BUG_ON(ret >= ASC_PRTLINE_SIZE);
  2624. if (buf == NULL) {
  2625. (void)printk(s);
  2626. ret = 0;
  2627. } else {
  2628. ret = min(buflen, ret);
  2629. memcpy(buf, s, ret);
  2630. }
  2631. va_end(args);
  2632. return ret;
  2633. }
  2634. /*
  2635. * asc_prt_board_devices()
  2636. *
  2637. * Print driver information for devices attached to the board.
  2638. *
  2639. * Note: no single line should be greater than ASC_PRTLINE_SIZE,
  2640. * cf. asc_prt_line().
  2641. *
  2642. * Return the number of characters copied into 'cp'. No more than
  2643. * 'cplen' characters will be copied to 'cp'.
  2644. */
  2645. static int asc_prt_board_devices(struct Scsi_Host *shost, char *cp, int cplen)
  2646. {
  2647. struct asc_board *boardp = shost_priv(shost);
  2648. int leftlen;
  2649. int totlen;
  2650. int len;
  2651. int chip_scsi_id;
  2652. int i;
  2653. leftlen = cplen;
  2654. totlen = len = 0;
  2655. len = asc_prt_line(cp, leftlen,
  2656. "\nDevice Information for AdvanSys SCSI Host %d:\n",
  2657. shost->host_no);
  2658. ASC_PRT_NEXT();
  2659. if (ASC_NARROW_BOARD(boardp)) {
  2660. chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
  2661. } else {
  2662. chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
  2663. }
  2664. len = asc_prt_line(cp, leftlen, "Target IDs Detected:");
  2665. ASC_PRT_NEXT();
  2666. for (i = 0; i <= ADV_MAX_TID; i++) {
  2667. if (boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) {
  2668. len = asc_prt_line(cp, leftlen, " %X,", i);
  2669. ASC_PRT_NEXT();
  2670. }
  2671. }
  2672. len = asc_prt_line(cp, leftlen, " (%X=Host Adapter)\n", chip_scsi_id);
  2673. ASC_PRT_NEXT();
  2674. return totlen;
  2675. }
  2676. /*
  2677. * Display Wide Board BIOS Information.
  2678. */
  2679. static int asc_prt_adv_bios(struct Scsi_Host *shost, char *cp, int cplen)
  2680. {
  2681. struct asc_board *boardp = shost_priv(shost);
  2682. int leftlen;
  2683. int totlen;
  2684. int len;
  2685. ushort major, minor, letter;
  2686. leftlen = cplen;
  2687. totlen = len = 0;
  2688. len = asc_prt_line(cp, leftlen, "\nROM BIOS Version: ");
  2689. ASC_PRT_NEXT();
  2690. /*
  2691. * If the BIOS saved a valid signature, then fill in
  2692. * the BIOS code segment base address.
  2693. */
  2694. if (boardp->bios_signature != 0x55AA) {
  2695. len = asc_prt_line(cp, leftlen, "Disabled or Pre-3.1\n");
  2696. ASC_PRT_NEXT();
  2697. len = asc_prt_line(cp, leftlen,
  2698. "BIOS either disabled or Pre-3.1. If it is pre-3.1, then a newer version\n");
  2699. ASC_PRT_NEXT();
  2700. len = asc_prt_line(cp, leftlen,
  2701. "can be found at the ConnectCom FTP site: ftp://ftp.connectcom.net/pub\n");
  2702. ASC_PRT_NEXT();
  2703. } else {
  2704. major = (boardp->bios_version >> 12) & 0xF;
  2705. minor = (boardp->bios_version >> 8) & 0xF;
  2706. letter = (boardp->bios_version & 0xFF);
  2707. len = asc_prt_line(cp, leftlen, "%d.%d%c\n",
  2708. major, minor,
  2709. letter >= 26 ? '?' : letter + 'A');
  2710. ASC_PRT_NEXT();
  2711. /*
  2712. * Current available ROM BIOS release is 3.1I for UW
  2713. * and 3.2I for U2W. This code doesn't differentiate
  2714. * UW and U2W boards.
  2715. */
  2716. if (major < 3 || (major <= 3 && minor < 1) ||
  2717. (major <= 3 && minor <= 1 && letter < ('I' - 'A'))) {
  2718. len = asc_prt_line(cp, leftlen,
  2719. "Newer version of ROM BIOS is available at the ConnectCom FTP site:\n");
  2720. ASC_PRT_NEXT();
  2721. len = asc_prt_line(cp, leftlen,
  2722. "ftp://ftp.connectcom.net/pub\n");
  2723. ASC_PRT_NEXT();
  2724. }
  2725. }
  2726. return totlen;
  2727. }
  2728. /*
  2729. * Add serial number to information bar if signature AAh
  2730. * is found in at bit 15-9 (7 bits) of word 1.
  2731. *
  2732. * Serial Number consists fo 12 alpha-numeric digits.
  2733. *
  2734. * 1 - Product type (A,B,C,D..) Word0: 15-13 (3 bits)
  2735. * 2 - MFG Location (A,B,C,D..) Word0: 12-10 (3 bits)
  2736. * 3-4 - Product ID (0-99) Word0: 9-0 (10 bits)
  2737. * 5 - Product revision (A-J) Word0: " "
  2738. *
  2739. * Signature Word1: 15-9 (7 bits)
  2740. * 6 - Year (0-9) Word1: 8-6 (3 bits) & Word2: 15 (1 bit)
  2741. * 7-8 - Week of the year (1-52) Word1: 5-0 (6 bits)
  2742. *
  2743. * 9-12 - Serial Number (A001-Z999) Word2: 14-0 (15 bits)
  2744. *
  2745. * Note 1: Only production cards will have a serial number.
  2746. *
  2747. * Note 2: Signature is most significant 7 bits (0xFE).
  2748. *
  2749. * Returns ASC_TRUE if serial number found, otherwise returns ASC_FALSE.
  2750. */
  2751. static int asc_get_eeprom_string(ushort *serialnum, uchar *cp)
  2752. {
  2753. ushort w, num;
  2754. if ((serialnum[1] & 0xFE00) != ((ushort)0xAA << 8)) {
  2755. return ASC_FALSE;
  2756. } else {
  2757. /*
  2758. * First word - 6 digits.
  2759. */
  2760. w = serialnum[0];
  2761. /* Product type - 1st digit. */
  2762. if ((*cp = 'A' + ((w & 0xE000) >> 13)) == 'H') {
  2763. /* Product type is P=Prototype */
  2764. *cp += 0x8;
  2765. }
  2766. cp++;
  2767. /* Manufacturing location - 2nd digit. */
  2768. *cp++ = 'A' + ((w & 0x1C00) >> 10);
  2769. /* Product ID - 3rd, 4th digits. */
  2770. num = w & 0x3FF;
  2771. *cp++ = '0' + (num / 100);
  2772. num %= 100;
  2773. *cp++ = '0' + (num / 10);
  2774. /* Product revision - 5th digit. */
  2775. *cp++ = 'A' + (num % 10);
  2776. /*
  2777. * Second word
  2778. */
  2779. w = serialnum[1];
  2780. /*
  2781. * Year - 6th digit.
  2782. *
  2783. * If bit 15 of third word is set, then the
  2784. * last digit of the year is greater than 7.
  2785. */
  2786. if (serialnum[2] & 0x8000) {
  2787. *cp++ = '8' + ((w & 0x1C0) >> 6);
  2788. } else {
  2789. *cp++ = '0' + ((w & 0x1C0) >> 6);
  2790. }
  2791. /* Week of year - 7th, 8th digits. */
  2792. num = w & 0x003F;
  2793. *cp++ = '0' + num / 10;
  2794. num %= 10;
  2795. *cp++ = '0' + num;
  2796. /*
  2797. * Third word
  2798. */
  2799. w = serialnum[2] & 0x7FFF;
  2800. /* Serial number - 9th digit. */
  2801. *cp++ = 'A' + (w / 1000);
  2802. /* 10th, 11th, 12th digits. */
  2803. num = w % 1000;
  2804. *cp++ = '0' + num / 100;
  2805. num %= 100;
  2806. *cp++ = '0' + num / 10;
  2807. num %= 10;
  2808. *cp++ = '0' + num;
  2809. *cp = '\0'; /* Null Terminate the string. */
  2810. return ASC_TRUE;
  2811. }
  2812. }
  2813. /*
  2814. * asc_prt_asc_board_eeprom()
  2815. *
  2816. * Print board EEPROM configuration.
  2817. *
  2818. * Note: no single line should be greater than ASC_PRTLINE_SIZE,
  2819. * cf. asc_prt_line().
  2820. *
  2821. * Return the number of characters copied into 'cp'. No more than
  2822. * 'cplen' characters will be copied to 'cp'.
  2823. */
  2824. static int asc_prt_asc_board_eeprom(struct Scsi_Host *shost, char *cp, int cplen)
  2825. {
  2826. struct asc_board *boardp = shost_priv(shost);
  2827. ASC_DVC_VAR *asc_dvc_varp;
  2828. int leftlen;
  2829. int totlen;
  2830. int len;
  2831. ASCEEP_CONFIG *ep;
  2832. int i;
  2833. #ifdef CONFIG_ISA
  2834. int isa_dma_speed[] = { 10, 8, 7, 6, 5, 4, 3, 2 };
  2835. #endif /* CONFIG_ISA */
  2836. uchar serialstr[13];
  2837. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  2838. ep = &boardp->eep_config.asc_eep;
  2839. leftlen = cplen;
  2840. totlen = len = 0;
  2841. len = asc_prt_line(cp, leftlen,
  2842. "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
  2843. shost->host_no);
  2844. ASC_PRT_NEXT();
  2845. if (asc_get_eeprom_string((ushort *)&ep->adapter_info[0], serialstr)
  2846. == ASC_TRUE) {
  2847. len =
  2848. asc_prt_line(cp, leftlen, " Serial Number: %s\n",
  2849. serialstr);
  2850. ASC_PRT_NEXT();
  2851. } else {
  2852. if (ep->adapter_info[5] == 0xBB) {
  2853. len = asc_prt_line(cp, leftlen,
  2854. " Default Settings Used for EEPROM-less Adapter.\n");
  2855. ASC_PRT_NEXT();
  2856. } else {
  2857. len = asc_prt_line(cp, leftlen,
  2858. " Serial Number Signature Not Present.\n");
  2859. ASC_PRT_NEXT();
  2860. }
  2861. }
  2862. len = asc_prt_line(cp, leftlen,
  2863. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2864. ASC_EEP_GET_CHIP_ID(ep), ep->max_total_qng,
  2865. ep->max_tag_qng);
  2866. ASC_PRT_NEXT();
  2867. len = asc_prt_line(cp, leftlen,
  2868. " cntl 0x%x, no_scam 0x%x\n", ep->cntl, ep->no_scam);
  2869. ASC_PRT_NEXT();
  2870. len = asc_prt_line(cp, leftlen, " Target ID: ");
  2871. ASC_PRT_NEXT();
  2872. for (i = 0; i <= ASC_MAX_TID; i++) {
  2873. len = asc_prt_line(cp, leftlen, " %d", i);
  2874. ASC_PRT_NEXT();
  2875. }
  2876. len = asc_prt_line(cp, leftlen, "\n");
  2877. ASC_PRT_NEXT();
  2878. len = asc_prt_line(cp, leftlen, " Disconnects: ");
  2879. ASC_PRT_NEXT();
  2880. for (i = 0; i <= ASC_MAX_TID; i++) {
  2881. len = asc_prt_line(cp, leftlen, " %c",
  2882. (ep->
  2883. disc_enable & ADV_TID_TO_TIDMASK(i)) ? 'Y' :
  2884. 'N');
  2885. ASC_PRT_NEXT();
  2886. }
  2887. len = asc_prt_line(cp, leftlen, "\n");
  2888. ASC_PRT_NEXT();
  2889. len = asc_prt_line(cp, leftlen, " Command Queuing: ");
  2890. ASC_PRT_NEXT();
  2891. for (i = 0; i <= ASC_MAX_TID; i++) {
  2892. len = asc_prt_line(cp, leftlen, " %c",
  2893. (ep->
  2894. use_cmd_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' :
  2895. 'N');
  2896. ASC_PRT_NEXT();
  2897. }
  2898. len = asc_prt_line(cp, leftlen, "\n");
  2899. ASC_PRT_NEXT();
  2900. len = asc_prt_line(cp, leftlen, " Start Motor: ");
  2901. ASC_PRT_NEXT();
  2902. for (i = 0; i <= ASC_MAX_TID; i++) {
  2903. len = asc_prt_line(cp, leftlen, " %c",
  2904. (ep->
  2905. start_motor & ADV_TID_TO_TIDMASK(i)) ? 'Y' :
  2906. 'N');
  2907. ASC_PRT_NEXT();
  2908. }
  2909. len = asc_prt_line(cp, leftlen, "\n");
  2910. ASC_PRT_NEXT();
  2911. len = asc_prt_line(cp, leftlen, " Synchronous Transfer:");
  2912. ASC_PRT_NEXT();
  2913. for (i = 0; i <= ASC_MAX_TID; i++) {
  2914. len = asc_prt_line(cp, leftlen, " %c",
  2915. (ep->
  2916. init_sdtr & ADV_TID_TO_TIDMASK(i)) ? 'Y' :
  2917. 'N');
  2918. ASC_PRT_NEXT();
  2919. }
  2920. len = asc_prt_line(cp, leftlen, "\n");
  2921. ASC_PRT_NEXT();
  2922. #ifdef CONFIG_ISA
  2923. if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
  2924. len = asc_prt_line(cp, leftlen,
  2925. " Host ISA DMA speed: %d MB/S\n",
  2926. isa_dma_speed[ASC_EEP_GET_DMA_SPD(ep)]);
  2927. ASC_PRT_NEXT();
  2928. }
  2929. #endif /* CONFIG_ISA */
  2930. return totlen;
  2931. }
  2932. /*
  2933. * asc_prt_adv_board_eeprom()
  2934. *
  2935. * Print board EEPROM configuration.
  2936. *
  2937. * Note: no single line should be greater than ASC_PRTLINE_SIZE,
  2938. * cf. asc_prt_line().
  2939. *
  2940. * Return the number of characters copied into 'cp'. No more than
  2941. * 'cplen' characters will be copied to 'cp'.
  2942. */
  2943. static int asc_prt_adv_board_eeprom(struct Scsi_Host *shost, char *cp, int cplen)
  2944. {
  2945. struct asc_board *boardp = shost_priv(shost);
  2946. ADV_DVC_VAR *adv_dvc_varp;
  2947. int leftlen;
  2948. int totlen;
  2949. int len;
  2950. int i;
  2951. char *termstr;
  2952. uchar serialstr[13];
  2953. ADVEEP_3550_CONFIG *ep_3550 = NULL;
  2954. ADVEEP_38C0800_CONFIG *ep_38C0800 = NULL;
  2955. ADVEEP_38C1600_CONFIG *ep_38C1600 = NULL;
  2956. ushort word;
  2957. ushort *wordp;
  2958. ushort sdtr_speed = 0;
  2959. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  2960. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2961. ep_3550 = &boardp->eep_config.adv_3550_eep;
  2962. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2963. ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
  2964. } else {
  2965. ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
  2966. }
  2967. leftlen = cplen;
  2968. totlen = len = 0;
  2969. len = asc_prt_line(cp, leftlen,
  2970. "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
  2971. shost->host_no);
  2972. ASC_PRT_NEXT();
  2973. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2974. wordp = &ep_3550->serial_number_word1;
  2975. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2976. wordp = &ep_38C0800->serial_number_word1;
  2977. } else {
  2978. wordp = &ep_38C1600->serial_number_word1;
  2979. }
  2980. if (asc_get_eeprom_string(wordp, serialstr) == ASC_TRUE) {
  2981. len =
  2982. asc_prt_line(cp, leftlen, " Serial Number: %s\n",
  2983. serialstr);
  2984. ASC_PRT_NEXT();
  2985. } else {
  2986. len = asc_prt_line(cp, leftlen,
  2987. " Serial Number Signature Not Present.\n");
  2988. ASC_PRT_NEXT();
  2989. }
  2990. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2991. len = asc_prt_line(cp, leftlen,
  2992. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2993. ep_3550->adapter_scsi_id,
  2994. ep_3550->max_host_qng, ep_3550->max_dvc_qng);
  2995. ASC_PRT_NEXT();
  2996. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2997. len = asc_prt_line(cp, leftlen,
  2998. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2999. ep_38C0800->adapter_scsi_id,
  3000. ep_38C0800->max_host_qng,
  3001. ep_38C0800->max_dvc_qng);
  3002. ASC_PRT_NEXT();
  3003. } else {
  3004. len = asc_prt_line(cp, leftlen,
  3005. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  3006. ep_38C1600->adapter_scsi_id,
  3007. ep_38C1600->max_host_qng,
  3008. ep_38C1600->max_dvc_qng);
  3009. ASC_PRT_NEXT();
  3010. }
  3011. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  3012. word = ep_3550->termination;
  3013. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  3014. word = ep_38C0800->termination_lvd;
  3015. } else {
  3016. word = ep_38C1600->termination_lvd;
  3017. }
  3018. switch (word) {
  3019. case 1:
  3020. termstr = "Low Off/High Off";
  3021. break;
  3022. case 2:
  3023. termstr = "Low Off/High On";
  3024. break;
  3025. case 3:
  3026. termstr = "Low On/High On";
  3027. break;
  3028. default:
  3029. case 0:
  3030. termstr = "Automatic";
  3031. break;
  3032. }
  3033. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  3034. len = asc_prt_line(cp, leftlen,
  3035. " termination: %u (%s), bios_ctrl: 0x%x\n",
  3036. ep_3550->termination, termstr,
  3037. ep_3550->bios_ctrl);
  3038. ASC_PRT_NEXT();
  3039. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  3040. len = asc_prt_line(cp, leftlen,
  3041. " termination: %u (%s), bios_ctrl: 0x%x\n",
  3042. ep_38C0800->termination_lvd, termstr,
  3043. ep_38C0800->bios_ctrl);
  3044. ASC_PRT_NEXT();
  3045. } else {
  3046. len = asc_prt_line(cp, leftlen,
  3047. " termination: %u (%s), bios_ctrl: 0x%x\n",
  3048. ep_38C1600->termination_lvd, termstr,
  3049. ep_38C1600->bios_ctrl);
  3050. ASC_PRT_NEXT();
  3051. }
  3052. len = asc_prt_line(cp, leftlen, " Target ID: ");
  3053. ASC_PRT_NEXT();
  3054. for (i = 0; i <= ADV_MAX_TID; i++) {
  3055. len = asc_prt_line(cp, leftlen, " %X", i);
  3056. ASC_PRT_NEXT();
  3057. }
  3058. len = asc_prt_line(cp, leftlen, "\n");
  3059. ASC_PRT_NEXT();
  3060. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  3061. word = ep_3550->disc_enable;
  3062. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  3063. word = ep_38C0800->disc_enable;
  3064. } else {
  3065. word = ep_38C1600->disc_enable;
  3066. }
  3067. len = asc_prt_line(cp, leftlen, " Disconnects: ");
  3068. ASC_PRT_NEXT();
  3069. for (i = 0; i <= ADV_MAX_TID; i++) {
  3070. len = asc_prt_line(cp, leftlen, " %c",
  3071. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3072. ASC_PRT_NEXT();
  3073. }
  3074. len = asc_prt_line(cp, leftlen, "\n");
  3075. ASC_PRT_NEXT();
  3076. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  3077. word = ep_3550->tagqng_able;
  3078. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  3079. word = ep_38C0800->tagqng_able;
  3080. } else {
  3081. word = ep_38C1600->tagqng_able;
  3082. }
  3083. len = asc_prt_line(cp, leftlen, " Command Queuing: ");
  3084. ASC_PRT_NEXT();
  3085. for (i = 0; i <= ADV_MAX_TID; i++) {
  3086. len = asc_prt_line(cp, leftlen, " %c",
  3087. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3088. ASC_PRT_NEXT();
  3089. }
  3090. len = asc_prt_line(cp, leftlen, "\n");
  3091. ASC_PRT_NEXT();
  3092. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  3093. word = ep_3550->start_motor;
  3094. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  3095. word = ep_38C0800->start_motor;
  3096. } else {
  3097. word = ep_38C1600->start_motor;
  3098. }
  3099. len = asc_prt_line(cp, leftlen, " Start Motor: ");
  3100. ASC_PRT_NEXT();
  3101. for (i = 0; i <= ADV_MAX_TID; i++) {
  3102. len = asc_prt_line(cp, leftlen, " %c",
  3103. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3104. ASC_PRT_NEXT();
  3105. }
  3106. len = asc_prt_line(cp, leftlen, "\n");
  3107. ASC_PRT_NEXT();
  3108. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  3109. len = asc_prt_line(cp, leftlen, " Synchronous Transfer:");
  3110. ASC_PRT_NEXT();
  3111. for (i = 0; i <= ADV_MAX_TID; i++) {
  3112. len = asc_prt_line(cp, leftlen, " %c",
  3113. (ep_3550->
  3114. sdtr_able & ADV_TID_TO_TIDMASK(i)) ?
  3115. 'Y' : 'N');
  3116. ASC_PRT_NEXT();
  3117. }
  3118. len = asc_prt_line(cp, leftlen, "\n");
  3119. ASC_PRT_NEXT();
  3120. }
  3121. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  3122. len = asc_prt_line(cp, leftlen, " Ultra Transfer: ");
  3123. ASC_PRT_NEXT();
  3124. for (i = 0; i <= ADV_MAX_TID; i++) {
  3125. len = asc_prt_line(cp, leftlen, " %c",
  3126. (ep_3550->
  3127. ultra_able & ADV_TID_TO_TIDMASK(i))
  3128. ? 'Y' : 'N');
  3129. ASC_PRT_NEXT();
  3130. }
  3131. len = asc_prt_line(cp, leftlen, "\n");
  3132. ASC_PRT_NEXT();
  3133. }
  3134. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  3135. word = ep_3550->wdtr_able;
  3136. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  3137. word = ep_38C0800->wdtr_able;
  3138. } else {
  3139. word = ep_38C1600->wdtr_able;
  3140. }
  3141. len = asc_prt_line(cp, leftlen, " Wide Transfer: ");
  3142. ASC_PRT_NEXT();
  3143. for (i = 0; i <= ADV_MAX_TID; i++) {
  3144. len = asc_prt_line(cp, leftlen, " %c",
  3145. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3146. ASC_PRT_NEXT();
  3147. }
  3148. len = asc_prt_line(cp, leftlen, "\n");
  3149. ASC_PRT_NEXT();
  3150. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800 ||
  3151. adv_dvc_varp->chip_type == ADV_CHIP_ASC38C1600) {
  3152. len = asc_prt_line(cp, leftlen,
  3153. " Synchronous Transfer Speed (Mhz):\n ");
  3154. ASC_PRT_NEXT();
  3155. for (i = 0; i <= ADV_MAX_TID; i++) {
  3156. char *speed_str;
  3157. if (i == 0) {
  3158. sdtr_speed = adv_dvc_varp->sdtr_speed1;
  3159. } else if (i == 4) {
  3160. sdtr_speed = adv_dvc_varp->sdtr_speed2;
  3161. } else if (i == 8) {
  3162. sdtr_speed = adv_dvc_varp->sdtr_speed3;
  3163. } else if (i == 12) {
  3164. sdtr_speed = adv_dvc_varp->sdtr_speed4;
  3165. }
  3166. switch (sdtr_speed & ADV_MAX_TID) {
  3167. case 0:
  3168. speed_str = "Off";
  3169. break;
  3170. case 1:
  3171. speed_str = " 5";
  3172. break;
  3173. case 2:
  3174. speed_str = " 10";
  3175. break;
  3176. case 3:
  3177. speed_str = " 20";
  3178. break;
  3179. case 4:
  3180. speed_str = " 40";
  3181. break;
  3182. case 5:
  3183. speed_str = " 80";
  3184. break;
  3185. default:
  3186. speed_str = "Unk";
  3187. break;
  3188. }
  3189. len = asc_prt_line(cp, leftlen, "%X:%s ", i, speed_str);
  3190. ASC_PRT_NEXT();
  3191. if (i == 7) {
  3192. len = asc_prt_line(cp, leftlen, "\n ");
  3193. ASC_PRT_NEXT();
  3194. }
  3195. sdtr_speed >>= 4;
  3196. }
  3197. len = asc_prt_line(cp, leftlen, "\n");
  3198. ASC_PRT_NEXT();
  3199. }
  3200. return totlen;
  3201. }
  3202. /*
  3203. * asc_prt_driver_conf()
  3204. *
  3205. * Note: no single line should be greater than ASC_PRTLINE_SIZE,
  3206. * cf. asc_prt_line().
  3207. *
  3208. * Return the number of characters copied into 'cp'. No more than
  3209. * 'cplen' characters will be copied to 'cp'.
  3210. */
  3211. static int asc_prt_driver_conf(struct Scsi_Host *shost, char *cp, int cplen)
  3212. {
  3213. struct asc_board *boardp = shost_priv(shost);
  3214. int leftlen;
  3215. int totlen;
  3216. int len;
  3217. int chip_scsi_id;
  3218. leftlen = cplen;
  3219. totlen = len = 0;
  3220. len = asc_prt_line(cp, leftlen,
  3221. "\nLinux Driver Configuration and Information for AdvanSys SCSI Host %d:\n",
  3222. shost->host_no);
  3223. ASC_PRT_NEXT();
  3224. len = asc_prt_line(cp, leftlen,
  3225. " host_busy %u, last_reset %u, max_id %u, max_lun %u, max_channel %u\n",
  3226. shost->host_busy, shost->last_reset, shost->max_id,
  3227. shost->max_lun, shost->max_channel);
  3228. ASC_PRT_NEXT();
  3229. len = asc_prt_line(cp, leftlen,
  3230. " unique_id %d, can_queue %d, this_id %d, sg_tablesize %u, cmd_per_lun %u\n",
  3231. shost->unique_id, shost->can_queue, shost->this_id,
  3232. shost->sg_tablesize, shost->cmd_per_lun);
  3233. ASC_PRT_NEXT();
  3234. len = asc_prt_line(cp, leftlen,
  3235. " unchecked_isa_dma %d, use_clustering %d\n",
  3236. shost->unchecked_isa_dma, shost->use_clustering);
  3237. ASC_PRT_NEXT();
  3238. len = asc_prt_line(cp, leftlen,
  3239. " flags 0x%x, last_reset 0x%x, jiffies 0x%x, asc_n_io_port 0x%x\n",
  3240. boardp->flags, boardp->last_reset, jiffies,
  3241. boardp->asc_n_io_port);
  3242. ASC_PRT_NEXT();
  3243. len = asc_prt_line(cp, leftlen, " io_port 0x%x\n", shost->io_port);
  3244. ASC_PRT_NEXT();
  3245. if (ASC_NARROW_BOARD(boardp)) {
  3246. chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
  3247. } else {
  3248. chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
  3249. }
  3250. return totlen;
  3251. }
  3252. /*
  3253. * asc_prt_asc_board_info()
  3254. *
  3255. * Print dynamic board configuration information.
  3256. *
  3257. * Note: no single line should be greater than ASC_PRTLINE_SIZE,
  3258. * cf. asc_prt_line().
  3259. *
  3260. * Return the number of characters copied into 'cp'. No more than
  3261. * 'cplen' characters will be copied to 'cp'.
  3262. */
  3263. static int asc_prt_asc_board_info(struct Scsi_Host *shost, char *cp, int cplen)
  3264. {
  3265. struct asc_board *boardp = shost_priv(shost);
  3266. int chip_scsi_id;
  3267. int leftlen;
  3268. int totlen;
  3269. int len;
  3270. ASC_DVC_VAR *v;
  3271. ASC_DVC_CFG *c;
  3272. int i;
  3273. int renegotiate = 0;
  3274. v = &boardp->dvc_var.asc_dvc_var;
  3275. c = &boardp->dvc_cfg.asc_dvc_cfg;
  3276. chip_scsi_id = c->chip_scsi_id;
  3277. leftlen = cplen;
  3278. totlen = len = 0;
  3279. len = asc_prt_line(cp, leftlen,
  3280. "\nAsc Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
  3281. shost->host_no);
  3282. ASC_PRT_NEXT();
  3283. len = asc_prt_line(cp, leftlen, " chip_version %u, mcode_date 0x%x, "
  3284. "mcode_version 0x%x, err_code %u\n",
  3285. c->chip_version, c->mcode_date, c->mcode_version,
  3286. v->err_code);
  3287. ASC_PRT_NEXT();
  3288. /* Current number of commands waiting for the host. */
  3289. len = asc_prt_line(cp, leftlen,
  3290. " Total Command Pending: %d\n", v->cur_total_qng);
  3291. ASC_PRT_NEXT();
  3292. len = asc_prt_line(cp, leftlen, " Command Queuing:");
  3293. ASC_PRT_NEXT();
  3294. for (i = 0; i <= ASC_MAX_TID; i++) {
  3295. if ((chip_scsi_id == i) ||
  3296. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3297. continue;
  3298. }
  3299. len = asc_prt_line(cp, leftlen, " %X:%c",
  3300. i,
  3301. (v->
  3302. use_tagged_qng & ADV_TID_TO_TIDMASK(i)) ?
  3303. 'Y' : 'N');
  3304. ASC_PRT_NEXT();
  3305. }
  3306. len = asc_prt_line(cp, leftlen, "\n");
  3307. ASC_PRT_NEXT();
  3308. /* Current number of commands waiting for a device. */
  3309. len = asc_prt_line(cp, leftlen, " Command Queue Pending:");
  3310. ASC_PRT_NEXT();
  3311. for (i = 0; i <= ASC_MAX_TID; i++) {
  3312. if ((chip_scsi_id == i) ||
  3313. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3314. continue;
  3315. }
  3316. len = asc_prt_line(cp, leftlen, " %X:%u", i, v->cur_dvc_qng[i]);
  3317. ASC_PRT_NEXT();
  3318. }
  3319. len = asc_prt_line(cp, leftlen, "\n");
  3320. ASC_PRT_NEXT();
  3321. /* Current limit on number of commands that can be sent to a device. */
  3322. len = asc_prt_line(cp, leftlen, " Command Queue Limit:");
  3323. ASC_PRT_NEXT();
  3324. for (i = 0; i <= ASC_MAX_TID; i++) {
  3325. if ((chip_scsi_id == i) ||
  3326. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3327. continue;
  3328. }
  3329. len = asc_prt_line(cp, leftlen, " %X:%u", i, v->max_dvc_qng[i]);
  3330. ASC_PRT_NEXT();
  3331. }
  3332. len = asc_prt_line(cp, leftlen, "\n");
  3333. ASC_PRT_NEXT();
  3334. /* Indicate whether the device has returned queue full status. */
  3335. len = asc_prt_line(cp, leftlen, " Command Queue Full:");
  3336. ASC_PRT_NEXT();
  3337. for (i = 0; i <= ASC_MAX_TID; i++) {
  3338. if ((chip_scsi_id == i) ||
  3339. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3340. continue;
  3341. }
  3342. if (boardp->queue_full & ADV_TID_TO_TIDMASK(i)) {
  3343. len = asc_prt_line(cp, leftlen, " %X:Y-%d",
  3344. i, boardp->queue_full_cnt[i]);
  3345. } else {
  3346. len = asc_prt_line(cp, leftlen, " %X:N", i);
  3347. }
  3348. ASC_PRT_NEXT();
  3349. }
  3350. len = asc_prt_line(cp, leftlen, "\n");
  3351. ASC_PRT_NEXT();
  3352. len = asc_prt_line(cp, leftlen, " Synchronous Transfer:");
  3353. ASC_PRT_NEXT();
  3354. for (i = 0; i <= ASC_MAX_TID; i++) {
  3355. if ((chip_scsi_id == i) ||
  3356. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3357. continue;
  3358. }
  3359. len = asc_prt_line(cp, leftlen, " %X:%c",
  3360. i,
  3361. (v->
  3362. sdtr_done & ADV_TID_TO_TIDMASK(i)) ? 'Y' :
  3363. 'N');
  3364. ASC_PRT_NEXT();
  3365. }
  3366. len = asc_prt_line(cp, leftlen, "\n");
  3367. ASC_PRT_NEXT();
  3368. for (i = 0; i <= ASC_MAX_TID; i++) {
  3369. uchar syn_period_ix;
  3370. if ((chip_scsi_id == i) ||
  3371. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
  3372. ((v->init_sdtr & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3373. continue;
  3374. }
  3375. len = asc_prt_line(cp, leftlen, " %X:", i);
  3376. ASC_PRT_NEXT();
  3377. if ((boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET) == 0) {
  3378. len = asc_prt_line(cp, leftlen, " Asynchronous");
  3379. ASC_PRT_NEXT();
  3380. } else {
  3381. syn_period_ix =
  3382. (boardp->sdtr_data[i] >> 4) & (v->max_sdtr_index -
  3383. 1);
  3384. len = asc_prt_line(cp, leftlen,
  3385. " Transfer Period Factor: %d (%d.%d Mhz),",
  3386. v->sdtr_period_tbl[syn_period_ix],
  3387. 250 /
  3388. v->sdtr_period_tbl[syn_period_ix],
  3389. ASC_TENTHS(250,
  3390. v->
  3391. sdtr_period_tbl
  3392. [syn_period_ix]));
  3393. ASC_PRT_NEXT();
  3394. len = asc_prt_line(cp, leftlen, " REQ/ACK Offset: %d",
  3395. boardp->
  3396. sdtr_data[i] & ASC_SYN_MAX_OFFSET);
  3397. ASC_PRT_NEXT();
  3398. }
  3399. if ((v->sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  3400. len = asc_prt_line(cp, leftlen, "*\n");
  3401. renegotiate = 1;
  3402. } else {
  3403. len = asc_prt_line(cp, leftlen, "\n");
  3404. }
  3405. ASC_PRT_NEXT();
  3406. }
  3407. if (renegotiate) {
  3408. len = asc_prt_line(cp, leftlen,
  3409. " * = Re-negotiation pending before next command.\n");
  3410. ASC_PRT_NEXT();
  3411. }
  3412. return totlen;
  3413. }
  3414. /*
  3415. * asc_prt_adv_board_info()
  3416. *
  3417. * Print dynamic board configuration information.
  3418. *
  3419. * Note: no single line should be greater than ASC_PRTLINE_SIZE,
  3420. * cf. asc_prt_line().
  3421. *
  3422. * Return the number of characters copied into 'cp'. No more than
  3423. * 'cplen' characters will be copied to 'cp'.
  3424. */
  3425. static int asc_prt_adv_board_info(struct Scsi_Host *shost, char *cp, int cplen)
  3426. {
  3427. struct asc_board *boardp = shost_priv(shost);
  3428. int leftlen;
  3429. int totlen;
  3430. int len;
  3431. int i;
  3432. ADV_DVC_VAR *v;
  3433. ADV_DVC_CFG *c;
  3434. AdvPortAddr iop_base;
  3435. ushort chip_scsi_id;
  3436. ushort lramword;
  3437. uchar lrambyte;
  3438. ushort tagqng_able;
  3439. ushort sdtr_able, wdtr_able;
  3440. ushort wdtr_done, sdtr_done;
  3441. ushort period = 0;
  3442. int renegotiate = 0;
  3443. v = &boardp->dvc_var.adv_dvc_var;
  3444. c = &boardp->dvc_cfg.adv_dvc_cfg;
  3445. iop_base = v->iop_base;
  3446. chip_scsi_id = v->chip_scsi_id;
  3447. leftlen = cplen;
  3448. totlen = len = 0;
  3449. len = asc_prt_line(cp, leftlen,
  3450. "\nAdv Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
  3451. shost->host_no);
  3452. ASC_PRT_NEXT();
  3453. len = asc_prt_line(cp, leftlen,
  3454. " iop_base 0x%lx, cable_detect: %X, err_code %u\n",
  3455. v->iop_base,
  3456. AdvReadWordRegister(iop_base,
  3457. IOPW_SCSI_CFG1) & CABLE_DETECT,
  3458. v->err_code);
  3459. ASC_PRT_NEXT();
  3460. len = asc_prt_line(cp, leftlen, " chip_version %u, mcode_date 0x%x, "
  3461. "mcode_version 0x%x\n", c->chip_version,
  3462. c->mcode_date, c->mcode_version);
  3463. ASC_PRT_NEXT();
  3464. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  3465. len = asc_prt_line(cp, leftlen, " Queuing Enabled:");
  3466. ASC_PRT_NEXT();
  3467. for (i = 0; i <= ADV_MAX_TID; i++) {
  3468. if ((chip_scsi_id == i) ||
  3469. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3470. continue;
  3471. }
  3472. len = asc_prt_line(cp, leftlen, " %X:%c",
  3473. i,
  3474. (tagqng_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' :
  3475. 'N');
  3476. ASC_PRT_NEXT();
  3477. }
  3478. len = asc_prt_line(cp, leftlen, "\n");
  3479. ASC_PRT_NEXT();
  3480. len = asc_prt_line(cp, leftlen, " Queue Limit:");
  3481. ASC_PRT_NEXT();
  3482. for (i = 0; i <= ADV_MAX_TID; i++) {
  3483. if ((chip_scsi_id == i) ||
  3484. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3485. continue;
  3486. }
  3487. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + i,
  3488. lrambyte);
  3489. len = asc_prt_line(cp, leftlen, " %X:%d", i, lrambyte);
  3490. ASC_PRT_NEXT();
  3491. }
  3492. len = asc_prt_line(cp, leftlen, "\n");
  3493. ASC_PRT_NEXT();
  3494. len = asc_prt_line(cp, leftlen, " Command Pending:");
  3495. ASC_PRT_NEXT();
  3496. for (i = 0; i <= ADV_MAX_TID; i++) {
  3497. if ((chip_scsi_id == i) ||
  3498. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3499. continue;
  3500. }
  3501. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_QUEUED_CMD + i,
  3502. lrambyte);
  3503. len = asc_prt_line(cp, leftlen, " %X:%d", i, lrambyte);
  3504. ASC_PRT_NEXT();
  3505. }
  3506. len = asc_prt_line(cp, leftlen, "\n");
  3507. ASC_PRT_NEXT();
  3508. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  3509. len = asc_prt_line(cp, leftlen, " Wide Enabled:");
  3510. ASC_PRT_NEXT();
  3511. for (i = 0; i <= ADV_MAX_TID; i++) {
  3512. if ((chip_scsi_id == i) ||
  3513. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3514. continue;
  3515. }
  3516. len = asc_prt_line(cp, leftlen, " %X:%c",
  3517. i,
  3518. (wdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' :
  3519. 'N');
  3520. ASC_PRT_NEXT();
  3521. }
  3522. len = asc_prt_line(cp, leftlen, "\n");
  3523. ASC_PRT_NEXT();
  3524. AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, wdtr_done);
  3525. len = asc_prt_line(cp, leftlen, " Transfer Bit Width:");
  3526. ASC_PRT_NEXT();
  3527. for (i = 0; i <= ADV_MAX_TID; i++) {
  3528. if ((chip_scsi_id == i) ||
  3529. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3530. continue;
  3531. }
  3532. AdvReadWordLram(iop_base,
  3533. ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
  3534. lramword);
  3535. len = asc_prt_line(cp, leftlen, " %X:%d",
  3536. i, (lramword & 0x8000) ? 16 : 8);
  3537. ASC_PRT_NEXT();
  3538. if ((wdtr_able & ADV_TID_TO_TIDMASK(i)) &&
  3539. (wdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  3540. len = asc_prt_line(cp, leftlen, "*");
  3541. ASC_PRT_NEXT();
  3542. renegotiate = 1;
  3543. }
  3544. }
  3545. len = asc_prt_line(cp, leftlen, "\n");
  3546. ASC_PRT_NEXT();
  3547. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  3548. len = asc_prt_line(cp, leftlen, " Synchronous Enabled:");
  3549. ASC_PRT_NEXT();
  3550. for (i = 0; i <= ADV_MAX_TID; i++) {
  3551. if ((chip_scsi_id == i) ||
  3552. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3553. continue;
  3554. }
  3555. len = asc_prt_line(cp, leftlen, " %X:%c",
  3556. i,
  3557. (sdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' :
  3558. 'N');
  3559. ASC_PRT_NEXT();
  3560. }
  3561. len = asc_prt_line(cp, leftlen, "\n");
  3562. ASC_PRT_NEXT();
  3563. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, sdtr_done);
  3564. for (i = 0; i <= ADV_MAX_TID; i++) {
  3565. AdvReadWordLram(iop_base,
  3566. ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
  3567. lramword);
  3568. lramword &= ~0x8000;
  3569. if ((chip_scsi_id == i) ||
  3570. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
  3571. ((sdtr_able & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3572. continue;
  3573. }
  3574. len = asc_prt_line(cp, leftlen, " %X:", i);
  3575. ASC_PRT_NEXT();
  3576. if ((lramword & 0x1F) == 0) { /* Check for REQ/ACK Offset 0. */
  3577. len = asc_prt_line(cp, leftlen, " Asynchronous");
  3578. ASC_PRT_NEXT();
  3579. } else {
  3580. len =
  3581. asc_prt_line(cp, leftlen,
  3582. " Transfer Period Factor: ");
  3583. ASC_PRT_NEXT();
  3584. if ((lramword & 0x1F00) == 0x1100) { /* 80 Mhz */
  3585. len =
  3586. asc_prt_line(cp, leftlen, "9 (80.0 Mhz),");
  3587. ASC_PRT_NEXT();
  3588. } else if ((lramword & 0x1F00) == 0x1000) { /* 40 Mhz */
  3589. len =
  3590. asc_prt_line(cp, leftlen, "10 (40.0 Mhz),");
  3591. ASC_PRT_NEXT();
  3592. } else { /* 20 Mhz or below. */
  3593. period = (((lramword >> 8) * 25) + 50) / 4;
  3594. if (period == 0) { /* Should never happen. */
  3595. len =
  3596. asc_prt_line(cp, leftlen,
  3597. "%d (? Mhz), ");
  3598. ASC_PRT_NEXT();
  3599. } else {
  3600. len = asc_prt_line(cp, leftlen,
  3601. "%d (%d.%d Mhz),",
  3602. period, 250 / period,
  3603. ASC_TENTHS(250,
  3604. period));
  3605. ASC_PRT_NEXT();
  3606. }
  3607. }
  3608. len = asc_prt_line(cp, leftlen, " REQ/ACK Offset: %d",
  3609. lramword & 0x1F);
  3610. ASC_PRT_NEXT();
  3611. }
  3612. if ((sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  3613. len = asc_prt_line(cp, leftlen, "*\n");
  3614. renegotiate = 1;
  3615. } else {
  3616. len = asc_prt_line(cp, leftlen, "\n");
  3617. }
  3618. ASC_PRT_NEXT();
  3619. }
  3620. if (renegotiate) {
  3621. len = asc_prt_line(cp, leftlen,
  3622. " * = Re-negotiation pending before next command.\n");
  3623. ASC_PRT_NEXT();
  3624. }
  3625. return totlen;
  3626. }
  3627. /*
  3628. * asc_proc_copy()
  3629. *
  3630. * Copy proc information to a read buffer taking into account the current
  3631. * read offset in the file and the remaining space in the read buffer.
  3632. */
  3633. static int
  3634. asc_proc_copy(off_t advoffset, off_t offset, char *curbuf, int leftlen,
  3635. char *cp, int cplen)
  3636. {
  3637. int cnt = 0;
  3638. ASC_DBG(2, "offset %d, advoffset %d, cplen %d\n",
  3639. (unsigned)offset, (unsigned)advoffset, cplen);
  3640. if (offset <= advoffset) {
  3641. /* Read offset below current offset, copy everything. */
  3642. cnt = min(cplen, leftlen);
  3643. ASC_DBG(2, "curbuf 0x%lx, cp 0x%lx, cnt %d\n",
  3644. (ulong)curbuf, (ulong)cp, cnt);
  3645. memcpy(curbuf, cp, cnt);
  3646. } else if (offset < advoffset + cplen) {
  3647. /* Read offset within current range, partial copy. */
  3648. cnt = (advoffset + cplen) - offset;
  3649. cp = (cp + cplen) - cnt;
  3650. cnt = min(cnt, leftlen);
  3651. ASC_DBG(2, "curbuf 0x%lx, cp 0x%lx, cnt %d\n",
  3652. (ulong)curbuf, (ulong)cp, cnt);
  3653. memcpy(curbuf, cp, cnt);
  3654. }
  3655. return cnt;
  3656. }
  3657. #ifdef ADVANSYS_STATS
  3658. /*
  3659. * asc_prt_board_stats()
  3660. *
  3661. * Note: no single line should be greater than ASC_PRTLINE_SIZE,
  3662. * cf. asc_prt_line().
  3663. *
  3664. * Return the number of characters copied into 'cp'. No more than
  3665. * 'cplen' characters will be copied to 'cp'.
  3666. */
  3667. static int asc_prt_board_stats(struct Scsi_Host *shost, char *cp, int cplen)
  3668. {
  3669. struct asc_board *boardp = shost_priv(shost);
  3670. struct asc_stats *s = &boardp->asc_stats;
  3671. int leftlen = cplen;
  3672. int len, totlen = 0;
  3673. len = asc_prt_line(cp, leftlen,
  3674. "\nLinux Driver Statistics for AdvanSys SCSI Host %d:\n",
  3675. shost->host_no);
  3676. ASC_PRT_NEXT();
  3677. len = asc_prt_line(cp, leftlen,
  3678. " queuecommand %lu, reset %lu, biosparam %lu, interrupt %lu\n",
  3679. s->queuecommand, s->reset, s->biosparam,
  3680. s->interrupt);
  3681. ASC_PRT_NEXT();
  3682. len = asc_prt_line(cp, leftlen,
  3683. " callback %lu, done %lu, build_error %lu, build_noreq %lu, build_nosg %lu\n",
  3684. s->callback, s->done, s->build_error,
  3685. s->adv_build_noreq, s->adv_build_nosg);
  3686. ASC_PRT_NEXT();
  3687. len = asc_prt_line(cp, leftlen,
  3688. " exe_noerror %lu, exe_busy %lu, exe_error %lu, exe_unknown %lu\n",
  3689. s->exe_noerror, s->exe_busy, s->exe_error,
  3690. s->exe_unknown);
  3691. ASC_PRT_NEXT();
  3692. /*
  3693. * Display data transfer statistics.
  3694. */
  3695. if (s->xfer_cnt > 0) {
  3696. len = asc_prt_line(cp, leftlen, " xfer_cnt %lu, xfer_elem %lu, ",
  3697. s->xfer_cnt, s->xfer_elem);
  3698. ASC_PRT_NEXT();
  3699. len = asc_prt_line(cp, leftlen, "xfer_bytes %lu.%01lu kb\n",
  3700. s->xfer_sect / 2, ASC_TENTHS(s->xfer_sect, 2));
  3701. ASC_PRT_NEXT();
  3702. /* Scatter gather transfer statistics */
  3703. len = asc_prt_line(cp, leftlen, " avg_num_elem %lu.%01lu, ",
  3704. s->xfer_elem / s->xfer_cnt,
  3705. ASC_TENTHS(s->xfer_elem, s->xfer_cnt));
  3706. ASC_PRT_NEXT();
  3707. len = asc_prt_line(cp, leftlen, "avg_elem_size %lu.%01lu kb, ",
  3708. (s->xfer_sect / 2) / s->xfer_elem,
  3709. ASC_TENTHS((s->xfer_sect / 2), s->xfer_elem));
  3710. ASC_PRT_NEXT();
  3711. len = asc_prt_line(cp, leftlen, "avg_xfer_size %lu.%01lu kb\n",
  3712. (s->xfer_sect / 2) / s->xfer_cnt,
  3713. ASC_TENTHS((s->xfer_sect / 2), s->xfer_cnt));
  3714. ASC_PRT_NEXT();
  3715. }
  3716. return totlen;
  3717. }
  3718. #endif /* ADVANSYS_STATS */
  3719. /*
  3720. * advansys_proc_info() - /proc/scsi/advansys/{0,1,2,3,...}
  3721. *
  3722. * *buffer: I/O buffer
  3723. * **start: if inout == FALSE pointer into buffer where user read should start
  3724. * offset: current offset into a /proc/scsi/advansys/[0...] file
  3725. * length: length of buffer
  3726. * hostno: Scsi_Host host_no
  3727. * inout: TRUE - user is writing; FALSE - user is reading
  3728. *
  3729. * Return the number of bytes read from or written to a
  3730. * /proc/scsi/advansys/[0...] file.
  3731. *
  3732. * Note: This function uses the per board buffer 'prtbuf' which is
  3733. * allocated when the board is initialized in advansys_detect(). The
  3734. * buffer is ASC_PRTBUF_SIZE bytes. The function asc_proc_copy() is
  3735. * used to write to the buffer. The way asc_proc_copy() is written
  3736. * if 'prtbuf' is too small it will not be overwritten. Instead the
  3737. * user just won't get all the available statistics.
  3738. */
  3739. static int
  3740. advansys_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
  3741. off_t offset, int length, int inout)
  3742. {
  3743. struct asc_board *boardp = shost_priv(shost);
  3744. char *cp;
  3745. int cplen;
  3746. int cnt;
  3747. int totcnt;
  3748. int leftlen;
  3749. char *curbuf;
  3750. off_t advoffset;
  3751. ASC_DBG(1, "begin\n");
  3752. /*
  3753. * User write not supported.
  3754. */
  3755. if (inout == TRUE)
  3756. return -ENOSYS;
  3757. /*
  3758. * User read of /proc/scsi/advansys/[0...] file.
  3759. */
  3760. /* Copy read data starting at the beginning of the buffer. */
  3761. *start = buffer;
  3762. curbuf = buffer;
  3763. advoffset = 0;
  3764. totcnt = 0;
  3765. leftlen = length;
  3766. /*
  3767. * Get board configuration information.
  3768. *
  3769. * advansys_info() returns the board string from its own static buffer.
  3770. */
  3771. cp = (char *)advansys_info(shost);
  3772. strcat(cp, "\n");
  3773. cplen = strlen(cp);
  3774. /* Copy board information. */
  3775. cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
  3776. totcnt += cnt;
  3777. leftlen -= cnt;
  3778. if (leftlen == 0) {
  3779. ASC_DBG(1, "totcnt %d\n", totcnt);
  3780. return totcnt;
  3781. }
  3782. advoffset += cplen;
  3783. curbuf += cnt;
  3784. /*
  3785. * Display Wide Board BIOS Information.
  3786. */
  3787. if (!ASC_NARROW_BOARD(boardp)) {
  3788. cp = boardp->prtbuf;
  3789. cplen = asc_prt_adv_bios(shost, cp, ASC_PRTBUF_SIZE);
  3790. BUG_ON(cplen >= ASC_PRTBUF_SIZE);
  3791. cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp,
  3792. cplen);
  3793. totcnt += cnt;
  3794. leftlen -= cnt;
  3795. if (leftlen == 0) {
  3796. ASC_DBG(1, "totcnt %d\n", totcnt);
  3797. return totcnt;
  3798. }
  3799. advoffset += cplen;
  3800. curbuf += cnt;
  3801. }
  3802. /*
  3803. * Display driver information for each device attached to the board.
  3804. */
  3805. cp = boardp->prtbuf;
  3806. cplen = asc_prt_board_devices(shost, cp, ASC_PRTBUF_SIZE);
  3807. BUG_ON(cplen >= ASC_PRTBUF_SIZE);
  3808. cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
  3809. totcnt += cnt;
  3810. leftlen -= cnt;
  3811. if (leftlen == 0) {
  3812. ASC_DBG(1, "totcnt %d\n", totcnt);
  3813. return totcnt;
  3814. }
  3815. advoffset += cplen;
  3816. curbuf += cnt;
  3817. /*
  3818. * Display EEPROM configuration for the board.
  3819. */
  3820. cp = boardp->prtbuf;
  3821. if (ASC_NARROW_BOARD(boardp)) {
  3822. cplen = asc_prt_asc_board_eeprom(shost, cp, ASC_PRTBUF_SIZE);
  3823. } else {
  3824. cplen = asc_prt_adv_board_eeprom(shost, cp, ASC_PRTBUF_SIZE);
  3825. }
  3826. BUG_ON(cplen >= ASC_PRTBUF_SIZE);
  3827. cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
  3828. totcnt += cnt;
  3829. leftlen -= cnt;
  3830. if (leftlen == 0) {
  3831. ASC_DBG(1, "totcnt %d\n", totcnt);
  3832. return totcnt;
  3833. }
  3834. advoffset += cplen;
  3835. curbuf += cnt;
  3836. /*
  3837. * Display driver configuration and information for the board.
  3838. */
  3839. cp = boardp->prtbuf;
  3840. cplen = asc_prt_driver_conf(shost, cp, ASC_PRTBUF_SIZE);
  3841. BUG_ON(cplen >= ASC_PRTBUF_SIZE);
  3842. cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
  3843. totcnt += cnt;
  3844. leftlen -= cnt;
  3845. if (leftlen == 0) {
  3846. ASC_DBG(1, "totcnt %d\n", totcnt);
  3847. return totcnt;
  3848. }
  3849. advoffset += cplen;
  3850. curbuf += cnt;
  3851. #ifdef ADVANSYS_STATS
  3852. /*
  3853. * Display driver statistics for the board.
  3854. */
  3855. cp = boardp->prtbuf;
  3856. cplen = asc_prt_board_stats(shost, cp, ASC_PRTBUF_SIZE);
  3857. BUG_ON(cplen >= ASC_PRTBUF_SIZE);
  3858. cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
  3859. totcnt += cnt;
  3860. leftlen -= cnt;
  3861. if (leftlen == 0) {
  3862. ASC_DBG(1, "totcnt %d\n", totcnt);
  3863. return totcnt;
  3864. }
  3865. advoffset += cplen;
  3866. curbuf += cnt;
  3867. #endif /* ADVANSYS_STATS */
  3868. /*
  3869. * Display Asc Library dynamic configuration information
  3870. * for the board.
  3871. */
  3872. cp = boardp->prtbuf;
  3873. if (ASC_NARROW_BOARD(boardp)) {
  3874. cplen = asc_prt_asc_board_info(shost, cp, ASC_PRTBUF_SIZE);
  3875. } else {
  3876. cplen = asc_prt_adv_board_info(shost, cp, ASC_PRTBUF_SIZE);
  3877. }
  3878. BUG_ON(cplen >= ASC_PRTBUF_SIZE);
  3879. cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
  3880. totcnt += cnt;
  3881. leftlen -= cnt;
  3882. if (leftlen == 0) {
  3883. ASC_DBG(1, "totcnt %d\n", totcnt);
  3884. return totcnt;
  3885. }
  3886. advoffset += cplen;
  3887. curbuf += cnt;
  3888. ASC_DBG(1, "totcnt %d\n", totcnt);
  3889. return totcnt;
  3890. }
  3891. #endif /* CONFIG_PROC_FS */
  3892. static void asc_scsi_done(struct scsi_cmnd *scp)
  3893. {
  3894. scsi_dma_unmap(scp);
  3895. ASC_STATS(scp->device->host, done);
  3896. scp->scsi_done(scp);
  3897. }
  3898. static void AscSetBank(PortAddr iop_base, uchar bank)
  3899. {
  3900. uchar val;
  3901. val = AscGetChipControl(iop_base) &
  3902. (~
  3903. (CC_SINGLE_STEP | CC_TEST | CC_DIAG | CC_SCSI_RESET |
  3904. CC_CHIP_RESET));
  3905. if (bank == 1) {
  3906. val |= CC_BANK_ONE;
  3907. } else if (bank == 2) {
  3908. val |= CC_DIAG | CC_BANK_ONE;
  3909. } else {
  3910. val &= ~CC_BANK_ONE;
  3911. }
  3912. AscSetChipControl(iop_base, val);
  3913. }
  3914. static void AscSetChipIH(PortAddr iop_base, ushort ins_code)
  3915. {
  3916. AscSetBank(iop_base, 1);
  3917. AscWriteChipIH(iop_base, ins_code);
  3918. AscSetBank(iop_base, 0);
  3919. }
  3920. static int AscStartChip(PortAddr iop_base)
  3921. {
  3922. AscSetChipControl(iop_base, 0);
  3923. if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
  3924. return (0);
  3925. }
  3926. return (1);
  3927. }
  3928. static int AscStopChip(PortAddr iop_base)
  3929. {
  3930. uchar cc_val;
  3931. cc_val =
  3932. AscGetChipControl(iop_base) &
  3933. (~(CC_SINGLE_STEP | CC_TEST | CC_DIAG));
  3934. AscSetChipControl(iop_base, (uchar)(cc_val | CC_HALT));
  3935. AscSetChipIH(iop_base, INS_HALT);
  3936. AscSetChipIH(iop_base, INS_RFLAG_WTM);
  3937. if ((AscGetChipStatus(iop_base) & CSW_HALTED) == 0) {
  3938. return (0);
  3939. }
  3940. return (1);
  3941. }
  3942. static int AscIsChipHalted(PortAddr iop_base)
  3943. {
  3944. if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
  3945. if ((AscGetChipControl(iop_base) & CC_HALT) != 0) {
  3946. return (1);
  3947. }
  3948. }
  3949. return (0);
  3950. }
  3951. static int AscResetChipAndScsiBus(ASC_DVC_VAR *asc_dvc)
  3952. {
  3953. PortAddr iop_base;
  3954. int i = 10;
  3955. iop_base = asc_dvc->iop_base;
  3956. while ((AscGetChipStatus(iop_base) & CSW_SCSI_RESET_ACTIVE)
  3957. && (i-- > 0)) {
  3958. mdelay(100);
  3959. }
  3960. AscStopChip(iop_base);
  3961. AscSetChipControl(iop_base, CC_CHIP_RESET | CC_SCSI_RESET | CC_HALT);
  3962. udelay(60);
  3963. AscSetChipIH(iop_base, INS_RFLAG_WTM);
  3964. AscSetChipIH(iop_base, INS_HALT);
  3965. AscSetChipControl(iop_base, CC_CHIP_RESET | CC_HALT);
  3966. AscSetChipControl(iop_base, CC_HALT);
  3967. mdelay(200);
  3968. AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
  3969. AscSetChipStatus(iop_base, 0);
  3970. return (AscIsChipHalted(iop_base));
  3971. }
  3972. static int AscFindSignature(PortAddr iop_base)
  3973. {
  3974. ushort sig_word;
  3975. ASC_DBG(1, "AscGetChipSignatureByte(0x%x) 0x%x\n",
  3976. iop_base, AscGetChipSignatureByte(iop_base));
  3977. if (AscGetChipSignatureByte(iop_base) == (uchar)ASC_1000_ID1B) {
  3978. ASC_DBG(1, "AscGetChipSignatureWord(0x%x) 0x%x\n",
  3979. iop_base, AscGetChipSignatureWord(iop_base));
  3980. sig_word = AscGetChipSignatureWord(iop_base);
  3981. if ((sig_word == (ushort)ASC_1000_ID0W) ||
  3982. (sig_word == (ushort)ASC_1000_ID0W_FIX)) {
  3983. return (1);
  3984. }
  3985. }
  3986. return (0);
  3987. }
  3988. static void AscEnableInterrupt(PortAddr iop_base)
  3989. {
  3990. ushort cfg;
  3991. cfg = AscGetChipCfgLsw(iop_base);
  3992. AscSetChipCfgLsw(iop_base, cfg | ASC_CFG0_HOST_INT_ON);
  3993. }
  3994. static void AscDisableInterrupt(PortAddr iop_base)
  3995. {
  3996. ushort cfg;
  3997. cfg = AscGetChipCfgLsw(iop_base);
  3998. AscSetChipCfgLsw(iop_base, cfg & (~ASC_CFG0_HOST_INT_ON));
  3999. }
  4000. static uchar AscReadLramByte(PortAddr iop_base, ushort addr)
  4001. {
  4002. unsigned char byte_data;
  4003. unsigned short word_data;
  4004. if (isodd_word(addr)) {
  4005. AscSetChipLramAddr(iop_base, addr - 1);
  4006. word_data = AscGetChipLramData(iop_base);
  4007. byte_data = (word_data >> 8) & 0xFF;
  4008. } else {
  4009. AscSetChipLramAddr(iop_base, addr);
  4010. word_data = AscGetChipLramData(iop_base);
  4011. byte_data = word_data & 0xFF;
  4012. }
  4013. return byte_data;
  4014. }
  4015. static ushort AscReadLramWord(PortAddr iop_base, ushort addr)
  4016. {
  4017. ushort word_data;
  4018. AscSetChipLramAddr(iop_base, addr);
  4019. word_data = AscGetChipLramData(iop_base);
  4020. return (word_data);
  4021. }
  4022. #if CC_VERY_LONG_SG_LIST
  4023. static ASC_DCNT AscReadLramDWord(PortAddr iop_base, ushort addr)
  4024. {
  4025. ushort val_low, val_high;
  4026. ASC_DCNT dword_data;
  4027. AscSetChipLramAddr(iop_base, addr);
  4028. val_low = AscGetChipLramData(iop_base);
  4029. val_high = AscGetChipLramData(iop_base);
  4030. dword_data = ((ASC_DCNT) val_high << 16) | (ASC_DCNT) val_low;
  4031. return (dword_data);
  4032. }
  4033. #endif /* CC_VERY_LONG_SG_LIST */
  4034. static void
  4035. AscMemWordSetLram(PortAddr iop_base, ushort s_addr, ushort set_wval, int words)
  4036. {
  4037. int i;
  4038. AscSetChipLramAddr(iop_base, s_addr);
  4039. for (i = 0; i < words; i++) {
  4040. AscSetChipLramData(iop_base, set_wval);
  4041. }
  4042. }
  4043. static void AscWriteLramWord(PortAddr iop_base, ushort addr, ushort word_val)
  4044. {
  4045. AscSetChipLramAddr(iop_base, addr);
  4046. AscSetChipLramData(iop_base, word_val);
  4047. }
  4048. static void AscWriteLramByte(PortAddr iop_base, ushort addr, uchar byte_val)
  4049. {
  4050. ushort word_data;
  4051. if (isodd_word(addr)) {
  4052. addr--;
  4053. word_data = AscReadLramWord(iop_base, addr);
  4054. word_data &= 0x00FF;
  4055. word_data |= (((ushort)byte_val << 8) & 0xFF00);
  4056. } else {
  4057. word_data = AscReadLramWord(iop_base, addr);
  4058. word_data &= 0xFF00;
  4059. word_data |= ((ushort)byte_val & 0x00FF);
  4060. }
  4061. AscWriteLramWord(iop_base, addr, word_data);
  4062. }
  4063. /*
  4064. * Copy 2 bytes to LRAM.
  4065. *
  4066. * The source data is assumed to be in little-endian order in memory
  4067. * and is maintained in little-endian order when written to LRAM.
  4068. */
  4069. static void
  4070. AscMemWordCopyPtrToLram(PortAddr iop_base, ushort s_addr,
  4071. const uchar *s_buffer, int words)
  4072. {
  4073. int i;
  4074. AscSetChipLramAddr(iop_base, s_addr);
  4075. for (i = 0; i < 2 * words; i += 2) {
  4076. /*
  4077. * On a little-endian system the second argument below
  4078. * produces a little-endian ushort which is written to
  4079. * LRAM in little-endian order. On a big-endian system
  4080. * the second argument produces a big-endian ushort which
  4081. * is "transparently" byte-swapped by outpw() and written
  4082. * in little-endian order to LRAM.
  4083. */
  4084. outpw(iop_base + IOP_RAM_DATA,
  4085. ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]);
  4086. }
  4087. }
  4088. /*
  4089. * Copy 4 bytes to LRAM.
  4090. *
  4091. * The source data is assumed to be in little-endian order in memory
  4092. * and is maintained in little-endian order when written to LRAM.
  4093. */
  4094. static void
  4095. AscMemDWordCopyPtrToLram(PortAddr iop_base,
  4096. ushort s_addr, uchar *s_buffer, int dwords)
  4097. {
  4098. int i;
  4099. AscSetChipLramAddr(iop_base, s_addr);
  4100. for (i = 0; i < 4 * dwords; i += 4) {
  4101. outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]); /* LSW */
  4102. outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 3] << 8) | s_buffer[i + 2]); /* MSW */
  4103. }
  4104. }
  4105. /*
  4106. * Copy 2 bytes from LRAM.
  4107. *
  4108. * The source data is assumed to be in little-endian order in LRAM
  4109. * and is maintained in little-endian order when written to memory.
  4110. */
  4111. static void
  4112. AscMemWordCopyPtrFromLram(PortAddr iop_base,
  4113. ushort s_addr, uchar *d_buffer, int words)
  4114. {
  4115. int i;
  4116. ushort word;
  4117. AscSetChipLramAddr(iop_base, s_addr);
  4118. for (i = 0; i < 2 * words; i += 2) {
  4119. word = inpw(iop_base + IOP_RAM_DATA);
  4120. d_buffer[i] = word & 0xff;
  4121. d_buffer[i + 1] = (word >> 8) & 0xff;
  4122. }
  4123. }
  4124. static ASC_DCNT AscMemSumLramWord(PortAddr iop_base, ushort s_addr, int words)
  4125. {
  4126. ASC_DCNT sum;
  4127. int i;
  4128. sum = 0L;
  4129. for (i = 0; i < words; i++, s_addr += 2) {
  4130. sum += AscReadLramWord(iop_base, s_addr);
  4131. }
  4132. return (sum);
  4133. }
  4134. static ushort AscInitLram(ASC_DVC_VAR *asc_dvc)
  4135. {
  4136. uchar i;
  4137. ushort s_addr;
  4138. PortAddr iop_base;
  4139. ushort warn_code;
  4140. iop_base = asc_dvc->iop_base;
  4141. warn_code = 0;
  4142. AscMemWordSetLram(iop_base, ASC_QADR_BEG, 0,
  4143. (ushort)(((int)(asc_dvc->max_total_qng + 2 + 1) *
  4144. 64) >> 1));
  4145. i = ASC_MIN_ACTIVE_QNO;
  4146. s_addr = ASC_QADR_BEG + ASC_QBLK_SIZE;
  4147. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  4148. (uchar)(i + 1));
  4149. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  4150. (uchar)(asc_dvc->max_total_qng));
  4151. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  4152. (uchar)i);
  4153. i++;
  4154. s_addr += ASC_QBLK_SIZE;
  4155. for (; i < asc_dvc->max_total_qng; i++, s_addr += ASC_QBLK_SIZE) {
  4156. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  4157. (uchar)(i + 1));
  4158. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  4159. (uchar)(i - 1));
  4160. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  4161. (uchar)i);
  4162. }
  4163. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  4164. (uchar)ASC_QLINK_END);
  4165. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  4166. (uchar)(asc_dvc->max_total_qng - 1));
  4167. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  4168. (uchar)asc_dvc->max_total_qng);
  4169. i++;
  4170. s_addr += ASC_QBLK_SIZE;
  4171. for (; i <= (uchar)(asc_dvc->max_total_qng + 3);
  4172. i++, s_addr += ASC_QBLK_SIZE) {
  4173. AscWriteLramByte(iop_base,
  4174. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_FWD), i);
  4175. AscWriteLramByte(iop_base,
  4176. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_BWD), i);
  4177. AscWriteLramByte(iop_base,
  4178. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_QNO), i);
  4179. }
  4180. return warn_code;
  4181. }
  4182. static ASC_DCNT
  4183. AscLoadMicroCode(PortAddr iop_base, ushort s_addr,
  4184. const uchar *mcode_buf, ushort mcode_size)
  4185. {
  4186. ASC_DCNT chksum;
  4187. ushort mcode_word_size;
  4188. ushort mcode_chksum;
  4189. /* Write the microcode buffer starting at LRAM address 0. */
  4190. mcode_word_size = (ushort)(mcode_size >> 1);
  4191. AscMemWordSetLram(iop_base, s_addr, 0, mcode_word_size);
  4192. AscMemWordCopyPtrToLram(iop_base, s_addr, mcode_buf, mcode_word_size);
  4193. chksum = AscMemSumLramWord(iop_base, s_addr, mcode_word_size);
  4194. ASC_DBG(1, "chksum 0x%lx\n", (ulong)chksum);
  4195. mcode_chksum = (ushort)AscMemSumLramWord(iop_base,
  4196. (ushort)ASC_CODE_SEC_BEG,
  4197. (ushort)((mcode_size -
  4198. s_addr - (ushort)
  4199. ASC_CODE_SEC_BEG) /
  4200. 2));
  4201. ASC_DBG(1, "mcode_chksum 0x%lx\n", (ulong)mcode_chksum);
  4202. AscWriteLramWord(iop_base, ASCV_MCODE_CHKSUM_W, mcode_chksum);
  4203. AscWriteLramWord(iop_base, ASCV_MCODE_SIZE_W, mcode_size);
  4204. return chksum;
  4205. }
  4206. static void AscInitQLinkVar(ASC_DVC_VAR *asc_dvc)
  4207. {
  4208. PortAddr iop_base;
  4209. int i;
  4210. ushort lram_addr;
  4211. iop_base = asc_dvc->iop_base;
  4212. AscPutRiscVarFreeQHead(iop_base, 1);
  4213. AscPutRiscVarDoneQTail(iop_base, asc_dvc->max_total_qng);
  4214. AscPutVarFreeQHead(iop_base, 1);
  4215. AscPutVarDoneQTail(iop_base, asc_dvc->max_total_qng);
  4216. AscWriteLramByte(iop_base, ASCV_BUSY_QHEAD_B,
  4217. (uchar)((int)asc_dvc->max_total_qng + 1));
  4218. AscWriteLramByte(iop_base, ASCV_DISC1_QHEAD_B,
  4219. (uchar)((int)asc_dvc->max_total_qng + 2));
  4220. AscWriteLramByte(iop_base, (ushort)ASCV_TOTAL_READY_Q_B,
  4221. asc_dvc->max_total_qng);
  4222. AscWriteLramWord(iop_base, ASCV_ASCDVC_ERR_CODE_W, 0);
  4223. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  4224. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, 0);
  4225. AscWriteLramByte(iop_base, ASCV_SCSIBUSY_B, 0);
  4226. AscWriteLramByte(iop_base, ASCV_WTM_FLAG_B, 0);
  4227. AscPutQDoneInProgress(iop_base, 0);
  4228. lram_addr = ASC_QADR_BEG;
  4229. for (i = 0; i < 32; i++, lram_addr += 2) {
  4230. AscWriteLramWord(iop_base, lram_addr, 0);
  4231. }
  4232. }
  4233. static ushort AscInitMicroCodeVar(ASC_DVC_VAR *asc_dvc)
  4234. {
  4235. int i;
  4236. ushort warn_code;
  4237. PortAddr iop_base;
  4238. ASC_PADDR phy_addr;
  4239. ASC_DCNT phy_size;
  4240. struct asc_board *board = asc_dvc_to_board(asc_dvc);
  4241. iop_base = asc_dvc->iop_base;
  4242. warn_code = 0;
  4243. for (i = 0; i <= ASC_MAX_TID; i++) {
  4244. AscPutMCodeInitSDTRAtID(iop_base, i,
  4245. asc_dvc->cfg->sdtr_period_offset[i]);
  4246. }
  4247. AscInitQLinkVar(asc_dvc);
  4248. AscWriteLramByte(iop_base, ASCV_DISC_ENABLE_B,
  4249. asc_dvc->cfg->disc_enable);
  4250. AscWriteLramByte(iop_base, ASCV_HOSTSCSI_ID_B,
  4251. ASC_TID_TO_TARGET_ID(asc_dvc->cfg->chip_scsi_id));
  4252. /* Ensure overrun buffer is aligned on an 8 byte boundary. */
  4253. BUG_ON((unsigned long)asc_dvc->overrun_buf & 7);
  4254. asc_dvc->overrun_dma = dma_map_single(board->dev, asc_dvc->overrun_buf,
  4255. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  4256. if (dma_mapping_error(board->dev, asc_dvc->overrun_dma)) {
  4257. warn_code = -ENOMEM;
  4258. goto err_dma_map;
  4259. }
  4260. phy_addr = cpu_to_le32(asc_dvc->overrun_dma);
  4261. AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_PADDR_D,
  4262. (uchar *)&phy_addr, 1);
  4263. phy_size = cpu_to_le32(ASC_OVERRUN_BSIZE);
  4264. AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_BSIZE_D,
  4265. (uchar *)&phy_size, 1);
  4266. asc_dvc->cfg->mcode_date =
  4267. AscReadLramWord(iop_base, (ushort)ASCV_MC_DATE_W);
  4268. asc_dvc->cfg->mcode_version =
  4269. AscReadLramWord(iop_base, (ushort)ASCV_MC_VER_W);
  4270. AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
  4271. if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
  4272. asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
  4273. warn_code = UW_ERR;
  4274. goto err_mcode_start;
  4275. }
  4276. if (AscStartChip(iop_base) != 1) {
  4277. asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
  4278. warn_code = UW_ERR;
  4279. goto err_mcode_start;
  4280. }
  4281. return warn_code;
  4282. err_mcode_start:
  4283. dma_unmap_single(board->dev, asc_dvc->overrun_dma,
  4284. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  4285. err_dma_map:
  4286. asc_dvc->overrun_dma = 0;
  4287. return warn_code;
  4288. }
  4289. static ushort AscInitAsc1000Driver(ASC_DVC_VAR *asc_dvc)
  4290. {
  4291. const struct firmware *fw;
  4292. const char fwname[] = "advansys/mcode.bin";
  4293. int err;
  4294. unsigned long chksum;
  4295. ushort warn_code;
  4296. PortAddr iop_base;
  4297. iop_base = asc_dvc->iop_base;
  4298. warn_code = 0;
  4299. if ((asc_dvc->dvc_cntl & ASC_CNTL_RESET_SCSI) &&
  4300. !(asc_dvc->init_state & ASC_INIT_RESET_SCSI_DONE)) {
  4301. AscResetChipAndScsiBus(asc_dvc);
  4302. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  4303. }
  4304. asc_dvc->init_state |= ASC_INIT_STATE_BEG_LOAD_MC;
  4305. if (asc_dvc->err_code != 0)
  4306. return UW_ERR;
  4307. if (!AscFindSignature(asc_dvc->iop_base)) {
  4308. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  4309. return warn_code;
  4310. }
  4311. AscDisableInterrupt(iop_base);
  4312. warn_code |= AscInitLram(asc_dvc);
  4313. if (asc_dvc->err_code != 0)
  4314. return UW_ERR;
  4315. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  4316. if (err) {
  4317. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  4318. fwname, err);
  4319. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  4320. return err;
  4321. }
  4322. if (fw->size < 4) {
  4323. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  4324. fw->size, fwname);
  4325. release_firmware(fw);
  4326. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  4327. return -EINVAL;
  4328. }
  4329. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  4330. (fw->data[1] << 8) | fw->data[0];
  4331. ASC_DBG(1, "_asc_mcode_chksum 0x%lx\n", (ulong)chksum);
  4332. if (AscLoadMicroCode(iop_base, 0, &fw->data[4],
  4333. fw->size - 4) != chksum) {
  4334. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  4335. release_firmware(fw);
  4336. return warn_code;
  4337. }
  4338. release_firmware(fw);
  4339. warn_code |= AscInitMicroCodeVar(asc_dvc);
  4340. if (!asc_dvc->overrun_dma)
  4341. return warn_code;
  4342. asc_dvc->init_state |= ASC_INIT_STATE_END_LOAD_MC;
  4343. AscEnableInterrupt(iop_base);
  4344. return warn_code;
  4345. }
  4346. /*
  4347. * Load the Microcode
  4348. *
  4349. * Write the microcode image to RISC memory starting at address 0.
  4350. *
  4351. * The microcode is stored compressed in the following format:
  4352. *
  4353. * 254 word (508 byte) table indexed by byte code followed
  4354. * by the following byte codes:
  4355. *
  4356. * 1-Byte Code:
  4357. * 00: Emit word 0 in table.
  4358. * 01: Emit word 1 in table.
  4359. * .
  4360. * FD: Emit word 253 in table.
  4361. *
  4362. * Multi-Byte Code:
  4363. * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
  4364. * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
  4365. *
  4366. * Returns 0 or an error if the checksum doesn't match
  4367. */
  4368. static int AdvLoadMicrocode(AdvPortAddr iop_base, const unsigned char *buf,
  4369. int size, int memsize, int chksum)
  4370. {
  4371. int i, j, end, len = 0;
  4372. ADV_DCNT sum;
  4373. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
  4374. for (i = 253 * 2; i < size; i++) {
  4375. if (buf[i] == 0xff) {
  4376. unsigned short word = (buf[i + 3] << 8) | buf[i + 2];
  4377. for (j = 0; j < buf[i + 1]; j++) {
  4378. AdvWriteWordAutoIncLram(iop_base, word);
  4379. len += 2;
  4380. }
  4381. i += 3;
  4382. } else if (buf[i] == 0xfe) {
  4383. unsigned short word = (buf[i + 2] << 8) | buf[i + 1];
  4384. AdvWriteWordAutoIncLram(iop_base, word);
  4385. i += 2;
  4386. len += 2;
  4387. } else {
  4388. unsigned int off = buf[i] * 2;
  4389. unsigned short word = (buf[off + 1] << 8) | buf[off];
  4390. AdvWriteWordAutoIncLram(iop_base, word);
  4391. len += 2;
  4392. }
  4393. }
  4394. end = len;
  4395. while (len < memsize) {
  4396. AdvWriteWordAutoIncLram(iop_base, 0);
  4397. len += 2;
  4398. }
  4399. /* Verify the microcode checksum. */
  4400. sum = 0;
  4401. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
  4402. for (len = 0; len < end; len += 2) {
  4403. sum += AdvReadWordAutoIncLram(iop_base);
  4404. }
  4405. if (sum != chksum)
  4406. return ASC_IERR_MCODE_CHKSUM;
  4407. return 0;
  4408. }
  4409. static void AdvBuildCarrierFreelist(struct adv_dvc_var *asc_dvc)
  4410. {
  4411. ADV_CARR_T *carrp;
  4412. ADV_SDCNT buf_size;
  4413. ADV_PADDR carr_paddr;
  4414. carrp = (ADV_CARR_T *) ADV_16BALIGN(asc_dvc->carrier_buf);
  4415. asc_dvc->carr_freelist = NULL;
  4416. if (carrp == asc_dvc->carrier_buf) {
  4417. buf_size = ADV_CARRIER_BUFSIZE;
  4418. } else {
  4419. buf_size = ADV_CARRIER_BUFSIZE - sizeof(ADV_CARR_T);
  4420. }
  4421. do {
  4422. /* Get physical address of the carrier 'carrp'. */
  4423. carr_paddr = cpu_to_le32(virt_to_bus(carrp));
  4424. buf_size -= sizeof(ADV_CARR_T);
  4425. carrp->carr_pa = carr_paddr;
  4426. carrp->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(carrp));
  4427. /*
  4428. * Insert the carrier at the beginning of the freelist.
  4429. */
  4430. carrp->next_vpa =
  4431. cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
  4432. asc_dvc->carr_freelist = carrp;
  4433. carrp++;
  4434. } while (buf_size > 0);
  4435. }
  4436. /*
  4437. * Send an idle command to the chip and wait for completion.
  4438. *
  4439. * Command completion is polled for once per microsecond.
  4440. *
  4441. * The function can be called from anywhere including an interrupt handler.
  4442. * But the function is not re-entrant, so it uses the DvcEnter/LeaveCritical()
  4443. * functions to prevent reentrancy.
  4444. *
  4445. * Return Values:
  4446. * ADV_TRUE - command completed successfully
  4447. * ADV_FALSE - command failed
  4448. * ADV_ERROR - command timed out
  4449. */
  4450. static int
  4451. AdvSendIdleCmd(ADV_DVC_VAR *asc_dvc,
  4452. ushort idle_cmd, ADV_DCNT idle_cmd_parameter)
  4453. {
  4454. int result;
  4455. ADV_DCNT i, j;
  4456. AdvPortAddr iop_base;
  4457. iop_base = asc_dvc->iop_base;
  4458. /*
  4459. * Clear the idle command status which is set by the microcode
  4460. * to a non-zero value to indicate when the command is completed.
  4461. * The non-zero result is one of the IDLE_CMD_STATUS_* values
  4462. */
  4463. AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, (ushort)0);
  4464. /*
  4465. * Write the idle command value after the idle command parameter
  4466. * has been written to avoid a race condition. If the order is not
  4467. * followed, the microcode may process the idle command before the
  4468. * parameters have been written to LRAM.
  4469. */
  4470. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IDLE_CMD_PARAMETER,
  4471. cpu_to_le32(idle_cmd_parameter));
  4472. AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD, idle_cmd);
  4473. /*
  4474. * Tickle the RISC to tell it to process the idle command.
  4475. */
  4476. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_B);
  4477. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  4478. /*
  4479. * Clear the tickle value. In the ASC-3550 the RISC flag
  4480. * command 'clr_tickle_b' does not work unless the host
  4481. * value is cleared.
  4482. */
  4483. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
  4484. }
  4485. /* Wait for up to 100 millisecond for the idle command to timeout. */
  4486. for (i = 0; i < SCSI_WAIT_100_MSEC; i++) {
  4487. /* Poll once each microsecond for command completion. */
  4488. for (j = 0; j < SCSI_US_PER_MSEC; j++) {
  4489. AdvReadWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS,
  4490. result);
  4491. if (result != 0)
  4492. return result;
  4493. udelay(1);
  4494. }
  4495. }
  4496. BUG(); /* The idle command should never timeout. */
  4497. return ADV_ERROR;
  4498. }
  4499. /*
  4500. * Reset SCSI Bus and purge all outstanding requests.
  4501. *
  4502. * Return Value:
  4503. * ADV_TRUE(1) - All requests are purged and SCSI Bus is reset.
  4504. * ADV_FALSE(0) - Microcode command failed.
  4505. * ADV_ERROR(-1) - Microcode command timed-out. Microcode or IC
  4506. * may be hung which requires driver recovery.
  4507. */
  4508. static int AdvResetSB(ADV_DVC_VAR *asc_dvc)
  4509. {
  4510. int status;
  4511. /*
  4512. * Send the SCSI Bus Reset idle start idle command which asserts
  4513. * the SCSI Bus Reset signal.
  4514. */
  4515. status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_START, 0L);
  4516. if (status != ADV_TRUE) {
  4517. return status;
  4518. }
  4519. /*
  4520. * Delay for the specified SCSI Bus Reset hold time.
  4521. *
  4522. * The hold time delay is done on the host because the RISC has no
  4523. * microsecond accurate timer.
  4524. */
  4525. udelay(ASC_SCSI_RESET_HOLD_TIME_US);
  4526. /*
  4527. * Send the SCSI Bus Reset end idle command which de-asserts
  4528. * the SCSI Bus Reset signal and purges any pending requests.
  4529. */
  4530. status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_END, 0L);
  4531. if (status != ADV_TRUE) {
  4532. return status;
  4533. }
  4534. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  4535. return status;
  4536. }
  4537. /*
  4538. * Initialize the ASC-3550.
  4539. *
  4540. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  4541. *
  4542. * For a non-fatal error return a warning code. If there are no warnings
  4543. * then 0 is returned.
  4544. *
  4545. * Needed after initialization for error recovery.
  4546. */
  4547. static int AdvInitAsc3550Driver(ADV_DVC_VAR *asc_dvc)
  4548. {
  4549. const struct firmware *fw;
  4550. const char fwname[] = "advansys/3550.bin";
  4551. AdvPortAddr iop_base;
  4552. ushort warn_code;
  4553. int begin_addr;
  4554. int end_addr;
  4555. ushort code_sum;
  4556. int word;
  4557. int i;
  4558. int err;
  4559. unsigned long chksum;
  4560. ushort scsi_cfg1;
  4561. uchar tid;
  4562. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  4563. ushort wdtr_able = 0, sdtr_able, tagqng_able;
  4564. uchar max_cmd[ADV_MAX_TID + 1];
  4565. /* If there is already an error, don't continue. */
  4566. if (asc_dvc->err_code != 0)
  4567. return ADV_ERROR;
  4568. /*
  4569. * The caller must set 'chip_type' to ADV_CHIP_ASC3550.
  4570. */
  4571. if (asc_dvc->chip_type != ADV_CHIP_ASC3550) {
  4572. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  4573. return ADV_ERROR;
  4574. }
  4575. warn_code = 0;
  4576. iop_base = asc_dvc->iop_base;
  4577. /*
  4578. * Save the RISC memory BIOS region before writing the microcode.
  4579. * The BIOS may already be loaded and using its RISC LRAM region
  4580. * so its region must be saved and restored.
  4581. *
  4582. * Note: This code makes the assumption, which is currently true,
  4583. * that a chip reset does not clear RISC LRAM.
  4584. */
  4585. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4586. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4587. bios_mem[i]);
  4588. }
  4589. /*
  4590. * Save current per TID negotiated values.
  4591. */
  4592. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] == 0x55AA) {
  4593. ushort bios_version, major, minor;
  4594. bios_version =
  4595. bios_mem[(ASC_MC_BIOS_VERSION - ASC_MC_BIOSMEM) / 2];
  4596. major = (bios_version >> 12) & 0xF;
  4597. minor = (bios_version >> 8) & 0xF;
  4598. if (major < 3 || (major == 3 && minor == 1)) {
  4599. /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */
  4600. AdvReadWordLram(iop_base, 0x120, wdtr_able);
  4601. } else {
  4602. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4603. }
  4604. }
  4605. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4606. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  4607. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4608. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4609. max_cmd[tid]);
  4610. }
  4611. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  4612. if (err) {
  4613. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  4614. fwname, err);
  4615. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4616. return err;
  4617. }
  4618. if (fw->size < 4) {
  4619. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  4620. fw->size, fwname);
  4621. release_firmware(fw);
  4622. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4623. return -EINVAL;
  4624. }
  4625. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  4626. (fw->data[1] << 8) | fw->data[0];
  4627. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  4628. fw->size - 4, ADV_3550_MEMSIZE,
  4629. chksum);
  4630. release_firmware(fw);
  4631. if (asc_dvc->err_code)
  4632. return ADV_ERROR;
  4633. /*
  4634. * Restore the RISC memory BIOS region.
  4635. */
  4636. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4637. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4638. bios_mem[i]);
  4639. }
  4640. /*
  4641. * Calculate and write the microcode code checksum to the microcode
  4642. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  4643. */
  4644. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  4645. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  4646. code_sum = 0;
  4647. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  4648. for (word = begin_addr; word < end_addr; word += 2) {
  4649. code_sum += AdvReadWordAutoIncLram(iop_base);
  4650. }
  4651. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  4652. /*
  4653. * Read and save microcode version and date.
  4654. */
  4655. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  4656. asc_dvc->cfg->mcode_date);
  4657. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  4658. asc_dvc->cfg->mcode_version);
  4659. /*
  4660. * Set the chip type to indicate the ASC3550.
  4661. */
  4662. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC3550);
  4663. /*
  4664. * If the PCI Configuration Command Register "Parity Error Response
  4665. * Control" Bit was clear (0), then set the microcode variable
  4666. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  4667. * to ignore DMA parity errors.
  4668. */
  4669. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  4670. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4671. word |= CONTROL_FLAG_IGNORE_PERR;
  4672. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4673. }
  4674. /*
  4675. * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO
  4676. * threshold of 128 bytes. This register is only accessible to the host.
  4677. */
  4678. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  4679. START_CTL_EMFU | READ_CMD_MRM);
  4680. /*
  4681. * Microcode operating variables for WDTR, SDTR, and command tag
  4682. * queuing will be set in slave_configure() based on what a
  4683. * device reports it is capable of in Inquiry byte 7.
  4684. *
  4685. * If SCSI Bus Resets have been disabled, then directly set
  4686. * SDTR and WDTR from the EEPROM configuration. This will allow
  4687. * the BIOS and warm boot to work without a SCSI bus hang on
  4688. * the Inquiry caused by host and target mismatched DTR values.
  4689. * Without the SCSI Bus Reset, before an Inquiry a device can't
  4690. * be assumed to be in Asynchronous, Narrow mode.
  4691. */
  4692. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  4693. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  4694. asc_dvc->wdtr_able);
  4695. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  4696. asc_dvc->sdtr_able);
  4697. }
  4698. /*
  4699. * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2,
  4700. * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID
  4701. * bitmask. These values determine the maximum SDTR speed negotiated
  4702. * with a device.
  4703. *
  4704. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  4705. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  4706. * without determining here whether the device supports SDTR.
  4707. *
  4708. * 4-bit speed SDTR speed name
  4709. * =========== ===============
  4710. * 0000b (0x0) SDTR disabled
  4711. * 0001b (0x1) 5 Mhz
  4712. * 0010b (0x2) 10 Mhz
  4713. * 0011b (0x3) 20 Mhz (Ultra)
  4714. * 0100b (0x4) 40 Mhz (LVD/Ultra2)
  4715. * 0101b (0x5) 80 Mhz (LVD2/Ultra3)
  4716. * 0110b (0x6) Undefined
  4717. * .
  4718. * 1111b (0xF) Undefined
  4719. */
  4720. word = 0;
  4721. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4722. if (ADV_TID_TO_TIDMASK(tid) & asc_dvc->ultra_able) {
  4723. /* Set Ultra speed for TID 'tid'. */
  4724. word |= (0x3 << (4 * (tid % 4)));
  4725. } else {
  4726. /* Set Fast speed for TID 'tid'. */
  4727. word |= (0x2 << (4 * (tid % 4)));
  4728. }
  4729. if (tid == 3) { /* Check if done with sdtr_speed1. */
  4730. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, word);
  4731. word = 0;
  4732. } else if (tid == 7) { /* Check if done with sdtr_speed2. */
  4733. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, word);
  4734. word = 0;
  4735. } else if (tid == 11) { /* Check if done with sdtr_speed3. */
  4736. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, word);
  4737. word = 0;
  4738. } else if (tid == 15) { /* Check if done with sdtr_speed4. */
  4739. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, word);
  4740. /* End of loop. */
  4741. }
  4742. }
  4743. /*
  4744. * Set microcode operating variable for the disconnect per TID bitmask.
  4745. */
  4746. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  4747. asc_dvc->cfg->disc_enable);
  4748. /*
  4749. * Set SCSI_CFG0 Microcode Default Value.
  4750. *
  4751. * The microcode will set the SCSI_CFG0 register using this value
  4752. * after it is started below.
  4753. */
  4754. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  4755. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  4756. asc_dvc->chip_scsi_id);
  4757. /*
  4758. * Determine SCSI_CFG1 Microcode Default Value.
  4759. *
  4760. * The microcode will set the SCSI_CFG1 register using this value
  4761. * after it is started below.
  4762. */
  4763. /* Read current SCSI_CFG1 Register value. */
  4764. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4765. /*
  4766. * If all three connectors are in use, return an error.
  4767. */
  4768. if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 ||
  4769. (scsi_cfg1 & CABLE_ILLEGAL_B) == 0) {
  4770. asc_dvc->err_code |= ASC_IERR_ILLEGAL_CONNECTION;
  4771. return ADV_ERROR;
  4772. }
  4773. /*
  4774. * If the internal narrow cable is reversed all of the SCSI_CTRL
  4775. * register signals will be set. Check for and return an error if
  4776. * this condition is found.
  4777. */
  4778. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  4779. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  4780. return ADV_ERROR;
  4781. }
  4782. /*
  4783. * If this is a differential board and a single-ended device
  4784. * is attached to one of the connectors, return an error.
  4785. */
  4786. if ((scsi_cfg1 & DIFF_MODE) && (scsi_cfg1 & DIFF_SENSE) == 0) {
  4787. asc_dvc->err_code |= ASC_IERR_SINGLE_END_DEVICE;
  4788. return ADV_ERROR;
  4789. }
  4790. /*
  4791. * If automatic termination control is enabled, then set the
  4792. * termination value based on a table listed in a_condor.h.
  4793. *
  4794. * If manual termination was specified with an EEPROM setting
  4795. * then 'termination' was set-up in AdvInitFrom3550EEPROM() and
  4796. * is ready to be 'ored' into SCSI_CFG1.
  4797. */
  4798. if (asc_dvc->cfg->termination == 0) {
  4799. /*
  4800. * The software always controls termination by setting TERM_CTL_SEL.
  4801. * If TERM_CTL_SEL were set to 0, the hardware would set termination.
  4802. */
  4803. asc_dvc->cfg->termination |= TERM_CTL_SEL;
  4804. switch (scsi_cfg1 & CABLE_DETECT) {
  4805. /* TERM_CTL_H: on, TERM_CTL_L: on */
  4806. case 0x3:
  4807. case 0x7:
  4808. case 0xB:
  4809. case 0xD:
  4810. case 0xE:
  4811. case 0xF:
  4812. asc_dvc->cfg->termination |= (TERM_CTL_H | TERM_CTL_L);
  4813. break;
  4814. /* TERM_CTL_H: on, TERM_CTL_L: off */
  4815. case 0x1:
  4816. case 0x5:
  4817. case 0x9:
  4818. case 0xA:
  4819. case 0xC:
  4820. asc_dvc->cfg->termination |= TERM_CTL_H;
  4821. break;
  4822. /* TERM_CTL_H: off, TERM_CTL_L: off */
  4823. case 0x2:
  4824. case 0x6:
  4825. break;
  4826. }
  4827. }
  4828. /*
  4829. * Clear any set TERM_CTL_H and TERM_CTL_L bits.
  4830. */
  4831. scsi_cfg1 &= ~TERM_CTL;
  4832. /*
  4833. * Invert the TERM_CTL_H and TERM_CTL_L bits and then
  4834. * set 'scsi_cfg1'. The TERM_POL bit does not need to be
  4835. * referenced, because the hardware internally inverts
  4836. * the Termination High and Low bits if TERM_POL is set.
  4837. */
  4838. scsi_cfg1 |= (TERM_CTL_SEL | (~asc_dvc->cfg->termination & TERM_CTL));
  4839. /*
  4840. * Set SCSI_CFG1 Microcode Default Value
  4841. *
  4842. * Set filter value and possibly modified termination control
  4843. * bits in the Microcode SCSI_CFG1 Register Value.
  4844. *
  4845. * The microcode will set the SCSI_CFG1 register using this value
  4846. * after it is started below.
  4847. */
  4848. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1,
  4849. FLTR_DISABLE | scsi_cfg1);
  4850. /*
  4851. * Set MEM_CFG Microcode Default Value
  4852. *
  4853. * The microcode will set the MEM_CFG register using this value
  4854. * after it is started below.
  4855. *
  4856. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  4857. * are defined.
  4858. *
  4859. * ASC-3550 has 8KB internal memory.
  4860. */
  4861. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  4862. BIOS_EN | RAM_SZ_8KB);
  4863. /*
  4864. * Set SEL_MASK Microcode Default Value
  4865. *
  4866. * The microcode will set the SEL_MASK register using this value
  4867. * after it is started below.
  4868. */
  4869. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  4870. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  4871. AdvBuildCarrierFreelist(asc_dvc);
  4872. /*
  4873. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  4874. */
  4875. if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL) {
  4876. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4877. return ADV_ERROR;
  4878. }
  4879. asc_dvc->carr_freelist = (ADV_CARR_T *)
  4880. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
  4881. /*
  4882. * The first command issued will be placed in the stopper carrier.
  4883. */
  4884. asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  4885. /*
  4886. * Set RISC ICQ physical address start value.
  4887. */
  4888. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  4889. /*
  4890. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  4891. */
  4892. if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL) {
  4893. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4894. return ADV_ERROR;
  4895. }
  4896. asc_dvc->carr_freelist = (ADV_CARR_T *)
  4897. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
  4898. /*
  4899. * The first command completed by the RISC will be placed in
  4900. * the stopper.
  4901. *
  4902. * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
  4903. * completed the RISC will set the ASC_RQ_STOPPER bit.
  4904. */
  4905. asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  4906. /*
  4907. * Set RISC IRQ physical address start value.
  4908. */
  4909. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  4910. asc_dvc->carr_pending_cnt = 0;
  4911. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  4912. (ADV_INTR_ENABLE_HOST_INTR |
  4913. ADV_INTR_ENABLE_GLOBAL_INTR));
  4914. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  4915. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  4916. /* finally, finally, gentlemen, start your engine */
  4917. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  4918. /*
  4919. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  4920. * Resets should be performed. The RISC has to be running
  4921. * to issue a SCSI Bus Reset.
  4922. */
  4923. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  4924. /*
  4925. * If the BIOS Signature is present in memory, restore the
  4926. * BIOS Handshake Configuration Table and do not perform
  4927. * a SCSI Bus Reset.
  4928. */
  4929. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  4930. 0x55AA) {
  4931. /*
  4932. * Restore per TID negotiated values.
  4933. */
  4934. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4935. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4936. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  4937. tagqng_able);
  4938. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4939. AdvWriteByteLram(iop_base,
  4940. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4941. max_cmd[tid]);
  4942. }
  4943. } else {
  4944. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  4945. warn_code = ASC_WARN_BUSRESET_ERROR;
  4946. }
  4947. }
  4948. }
  4949. return warn_code;
  4950. }
  4951. /*
  4952. * Initialize the ASC-38C0800.
  4953. *
  4954. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  4955. *
  4956. * For a non-fatal error return a warning code. If there are no warnings
  4957. * then 0 is returned.
  4958. *
  4959. * Needed after initialization for error recovery.
  4960. */
  4961. static int AdvInitAsc38C0800Driver(ADV_DVC_VAR *asc_dvc)
  4962. {
  4963. const struct firmware *fw;
  4964. const char fwname[] = "advansys/38C0800.bin";
  4965. AdvPortAddr iop_base;
  4966. ushort warn_code;
  4967. int begin_addr;
  4968. int end_addr;
  4969. ushort code_sum;
  4970. int word;
  4971. int i;
  4972. int err;
  4973. unsigned long chksum;
  4974. ushort scsi_cfg1;
  4975. uchar byte;
  4976. uchar tid;
  4977. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  4978. ushort wdtr_able, sdtr_able, tagqng_able;
  4979. uchar max_cmd[ADV_MAX_TID + 1];
  4980. /* If there is already an error, don't continue. */
  4981. if (asc_dvc->err_code != 0)
  4982. return ADV_ERROR;
  4983. /*
  4984. * The caller must set 'chip_type' to ADV_CHIP_ASC38C0800.
  4985. */
  4986. if (asc_dvc->chip_type != ADV_CHIP_ASC38C0800) {
  4987. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  4988. return ADV_ERROR;
  4989. }
  4990. warn_code = 0;
  4991. iop_base = asc_dvc->iop_base;
  4992. /*
  4993. * Save the RISC memory BIOS region before writing the microcode.
  4994. * The BIOS may already be loaded and using its RISC LRAM region
  4995. * so its region must be saved and restored.
  4996. *
  4997. * Note: This code makes the assumption, which is currently true,
  4998. * that a chip reset does not clear RISC LRAM.
  4999. */
  5000. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  5001. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  5002. bios_mem[i]);
  5003. }
  5004. /*
  5005. * Save current per TID negotiated values.
  5006. */
  5007. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5008. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5009. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5010. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5011. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5012. max_cmd[tid]);
  5013. }
  5014. /*
  5015. * RAM BIST (RAM Built-In Self Test)
  5016. *
  5017. * Address : I/O base + offset 0x38h register (byte).
  5018. * Function: Bit 7-6(RW) : RAM mode
  5019. * Normal Mode : 0x00
  5020. * Pre-test Mode : 0x40
  5021. * RAM Test Mode : 0x80
  5022. * Bit 5 : unused
  5023. * Bit 4(RO) : Done bit
  5024. * Bit 3-0(RO) : Status
  5025. * Host Error : 0x08
  5026. * Int_RAM Error : 0x04
  5027. * RISC Error : 0x02
  5028. * SCSI Error : 0x01
  5029. * No Error : 0x00
  5030. *
  5031. * Note: RAM BIST code should be put right here, before loading the
  5032. * microcode and after saving the RISC memory BIOS region.
  5033. */
  5034. /*
  5035. * LRAM Pre-test
  5036. *
  5037. * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
  5038. * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
  5039. * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
  5040. * to NORMAL_MODE, return an error too.
  5041. */
  5042. for (i = 0; i < 2; i++) {
  5043. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
  5044. mdelay(10); /* Wait for 10ms before reading back. */
  5045. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  5046. if ((byte & RAM_TEST_DONE) == 0
  5047. || (byte & 0x0F) != PRE_TEST_VALUE) {
  5048. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  5049. return ADV_ERROR;
  5050. }
  5051. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  5052. mdelay(10); /* Wait for 10ms before reading back. */
  5053. if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
  5054. != NORMAL_VALUE) {
  5055. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  5056. return ADV_ERROR;
  5057. }
  5058. }
  5059. /*
  5060. * LRAM Test - It takes about 1.5 ms to run through the test.
  5061. *
  5062. * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
  5063. * If Done bit not set or Status not 0, save register byte, set the
  5064. * err_code, and return an error.
  5065. */
  5066. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
  5067. mdelay(10); /* Wait for 10ms before checking status. */
  5068. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  5069. if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
  5070. /* Get here if Done bit not set or Status not 0. */
  5071. asc_dvc->bist_err_code = byte; /* for BIOS display message */
  5072. asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
  5073. return ADV_ERROR;
  5074. }
  5075. /* We need to reset back to normal mode after LRAM test passes. */
  5076. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  5077. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  5078. if (err) {
  5079. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  5080. fwname, err);
  5081. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  5082. return err;
  5083. }
  5084. if (fw->size < 4) {
  5085. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  5086. fw->size, fwname);
  5087. release_firmware(fw);
  5088. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  5089. return -EINVAL;
  5090. }
  5091. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  5092. (fw->data[1] << 8) | fw->data[0];
  5093. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  5094. fw->size - 4, ADV_38C0800_MEMSIZE,
  5095. chksum);
  5096. release_firmware(fw);
  5097. if (asc_dvc->err_code)
  5098. return ADV_ERROR;
  5099. /*
  5100. * Restore the RISC memory BIOS region.
  5101. */
  5102. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  5103. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  5104. bios_mem[i]);
  5105. }
  5106. /*
  5107. * Calculate and write the microcode code checksum to the microcode
  5108. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  5109. */
  5110. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  5111. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  5112. code_sum = 0;
  5113. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  5114. for (word = begin_addr; word < end_addr; word += 2) {
  5115. code_sum += AdvReadWordAutoIncLram(iop_base);
  5116. }
  5117. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  5118. /*
  5119. * Read microcode version and date.
  5120. */
  5121. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  5122. asc_dvc->cfg->mcode_date);
  5123. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  5124. asc_dvc->cfg->mcode_version);
  5125. /*
  5126. * Set the chip type to indicate the ASC38C0800.
  5127. */
  5128. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C0800);
  5129. /*
  5130. * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
  5131. * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
  5132. * cable detection and then we are able to read C_DET[3:0].
  5133. *
  5134. * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
  5135. * Microcode Default Value' section below.
  5136. */
  5137. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  5138. AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
  5139. scsi_cfg1 | DIS_TERM_DRV);
  5140. /*
  5141. * If the PCI Configuration Command Register "Parity Error Response
  5142. * Control" Bit was clear (0), then set the microcode variable
  5143. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  5144. * to ignore DMA parity errors.
  5145. */
  5146. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  5147. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5148. word |= CONTROL_FLAG_IGNORE_PERR;
  5149. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5150. }
  5151. /*
  5152. * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and START_CTL_TH [3:2]
  5153. * bits for the default FIFO threshold.
  5154. *
  5155. * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
  5156. *
  5157. * For DMA Errata #4 set the BC_THRESH_ENB bit.
  5158. */
  5159. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  5160. BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH |
  5161. READ_CMD_MRM);
  5162. /*
  5163. * Microcode operating variables for WDTR, SDTR, and command tag
  5164. * queuing will be set in slave_configure() based on what a
  5165. * device reports it is capable of in Inquiry byte 7.
  5166. *
  5167. * If SCSI Bus Resets have been disabled, then directly set
  5168. * SDTR and WDTR from the EEPROM configuration. This will allow
  5169. * the BIOS and warm boot to work without a SCSI bus hang on
  5170. * the Inquiry caused by host and target mismatched DTR values.
  5171. * Without the SCSI Bus Reset, before an Inquiry a device can't
  5172. * be assumed to be in Asynchronous, Narrow mode.
  5173. */
  5174. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  5175. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  5176. asc_dvc->wdtr_able);
  5177. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  5178. asc_dvc->sdtr_able);
  5179. }
  5180. /*
  5181. * Set microcode operating variables for DISC and SDTR_SPEED1,
  5182. * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
  5183. * configuration values.
  5184. *
  5185. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  5186. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  5187. * without determining here whether the device supports SDTR.
  5188. */
  5189. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  5190. asc_dvc->cfg->disc_enable);
  5191. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
  5192. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
  5193. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
  5194. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
  5195. /*
  5196. * Set SCSI_CFG0 Microcode Default Value.
  5197. *
  5198. * The microcode will set the SCSI_CFG0 register using this value
  5199. * after it is started below.
  5200. */
  5201. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  5202. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  5203. asc_dvc->chip_scsi_id);
  5204. /*
  5205. * Determine SCSI_CFG1 Microcode Default Value.
  5206. *
  5207. * The microcode will set the SCSI_CFG1 register using this value
  5208. * after it is started below.
  5209. */
  5210. /* Read current SCSI_CFG1 Register value. */
  5211. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  5212. /*
  5213. * If the internal narrow cable is reversed all of the SCSI_CTRL
  5214. * register signals will be set. Check for and return an error if
  5215. * this condition is found.
  5216. */
  5217. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  5218. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  5219. return ADV_ERROR;
  5220. }
  5221. /*
  5222. * All kind of combinations of devices attached to one of four
  5223. * connectors are acceptable except HVD device attached. For example,
  5224. * LVD device can be attached to SE connector while SE device attached
  5225. * to LVD connector. If LVD device attached to SE connector, it only
  5226. * runs up to Ultra speed.
  5227. *
  5228. * If an HVD device is attached to one of LVD connectors, return an
  5229. * error. However, there is no way to detect HVD device attached to
  5230. * SE connectors.
  5231. */
  5232. if (scsi_cfg1 & HVD) {
  5233. asc_dvc->err_code = ASC_IERR_HVD_DEVICE;
  5234. return ADV_ERROR;
  5235. }
  5236. /*
  5237. * If either SE or LVD automatic termination control is enabled, then
  5238. * set the termination value based on a table listed in a_condor.h.
  5239. *
  5240. * If manual termination was specified with an EEPROM setting then
  5241. * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready
  5242. * to be 'ored' into SCSI_CFG1.
  5243. */
  5244. if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
  5245. /* SE automatic termination control is enabled. */
  5246. switch (scsi_cfg1 & C_DET_SE) {
  5247. /* TERM_SE_HI: on, TERM_SE_LO: on */
  5248. case 0x1:
  5249. case 0x2:
  5250. case 0x3:
  5251. asc_dvc->cfg->termination |= TERM_SE;
  5252. break;
  5253. /* TERM_SE_HI: on, TERM_SE_LO: off */
  5254. case 0x0:
  5255. asc_dvc->cfg->termination |= TERM_SE_HI;
  5256. break;
  5257. }
  5258. }
  5259. if ((asc_dvc->cfg->termination & TERM_LVD) == 0) {
  5260. /* LVD automatic termination control is enabled. */
  5261. switch (scsi_cfg1 & C_DET_LVD) {
  5262. /* TERM_LVD_HI: on, TERM_LVD_LO: on */
  5263. case 0x4:
  5264. case 0x8:
  5265. case 0xC:
  5266. asc_dvc->cfg->termination |= TERM_LVD;
  5267. break;
  5268. /* TERM_LVD_HI: off, TERM_LVD_LO: off */
  5269. case 0x0:
  5270. break;
  5271. }
  5272. }
  5273. /*
  5274. * Clear any set TERM_SE and TERM_LVD bits.
  5275. */
  5276. scsi_cfg1 &= (~TERM_SE & ~TERM_LVD);
  5277. /*
  5278. * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
  5279. */
  5280. scsi_cfg1 |= (~asc_dvc->cfg->termination & 0xF0);
  5281. /*
  5282. * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE
  5283. * bits and set possibly modified termination control bits in the
  5284. * Microcode SCSI_CFG1 Register Value.
  5285. */
  5286. scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL & ~HVD_LVD_SE);
  5287. /*
  5288. * Set SCSI_CFG1 Microcode Default Value
  5289. *
  5290. * Set possibly modified termination control and reset DIS_TERM_DRV
  5291. * bits in the Microcode SCSI_CFG1 Register Value.
  5292. *
  5293. * The microcode will set the SCSI_CFG1 register using this value
  5294. * after it is started below.
  5295. */
  5296. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
  5297. /*
  5298. * Set MEM_CFG Microcode Default Value
  5299. *
  5300. * The microcode will set the MEM_CFG register using this value
  5301. * after it is started below.
  5302. *
  5303. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  5304. * are defined.
  5305. *
  5306. * ASC-38C0800 has 16KB internal memory.
  5307. */
  5308. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5309. BIOS_EN | RAM_SZ_16KB);
  5310. /*
  5311. * Set SEL_MASK Microcode Default Value
  5312. *
  5313. * The microcode will set the SEL_MASK register using this value
  5314. * after it is started below.
  5315. */
  5316. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  5317. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  5318. AdvBuildCarrierFreelist(asc_dvc);
  5319. /*
  5320. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  5321. */
  5322. if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL) {
  5323. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5324. return ADV_ERROR;
  5325. }
  5326. asc_dvc->carr_freelist = (ADV_CARR_T *)
  5327. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
  5328. /*
  5329. * The first command issued will be placed in the stopper carrier.
  5330. */
  5331. asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  5332. /*
  5333. * Set RISC ICQ physical address start value.
  5334. * carr_pa is LE, must be native before write
  5335. */
  5336. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  5337. /*
  5338. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  5339. */
  5340. if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL) {
  5341. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5342. return ADV_ERROR;
  5343. }
  5344. asc_dvc->carr_freelist = (ADV_CARR_T *)
  5345. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
  5346. /*
  5347. * The first command completed by the RISC will be placed in
  5348. * the stopper.
  5349. *
  5350. * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
  5351. * completed the RISC will set the ASC_RQ_STOPPER bit.
  5352. */
  5353. asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  5354. /*
  5355. * Set RISC IRQ physical address start value.
  5356. *
  5357. * carr_pa is LE, must be native before write *
  5358. */
  5359. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  5360. asc_dvc->carr_pending_cnt = 0;
  5361. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  5362. (ADV_INTR_ENABLE_HOST_INTR |
  5363. ADV_INTR_ENABLE_GLOBAL_INTR));
  5364. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  5365. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  5366. /* finally, finally, gentlemen, start your engine */
  5367. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  5368. /*
  5369. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  5370. * Resets should be performed. The RISC has to be running
  5371. * to issue a SCSI Bus Reset.
  5372. */
  5373. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  5374. /*
  5375. * If the BIOS Signature is present in memory, restore the
  5376. * BIOS Handshake Configuration Table and do not perform
  5377. * a SCSI Bus Reset.
  5378. */
  5379. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  5380. 0x55AA) {
  5381. /*
  5382. * Restore per TID negotiated values.
  5383. */
  5384. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5385. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5386. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  5387. tagqng_able);
  5388. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5389. AdvWriteByteLram(iop_base,
  5390. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5391. max_cmd[tid]);
  5392. }
  5393. } else {
  5394. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  5395. warn_code = ASC_WARN_BUSRESET_ERROR;
  5396. }
  5397. }
  5398. }
  5399. return warn_code;
  5400. }
  5401. /*
  5402. * Initialize the ASC-38C1600.
  5403. *
  5404. * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
  5405. *
  5406. * For a non-fatal error return a warning code. If there are no warnings
  5407. * then 0 is returned.
  5408. *
  5409. * Needed after initialization for error recovery.
  5410. */
  5411. static int AdvInitAsc38C1600Driver(ADV_DVC_VAR *asc_dvc)
  5412. {
  5413. const struct firmware *fw;
  5414. const char fwname[] = "advansys/38C1600.bin";
  5415. AdvPortAddr iop_base;
  5416. ushort warn_code;
  5417. int begin_addr;
  5418. int end_addr;
  5419. ushort code_sum;
  5420. long word;
  5421. int i;
  5422. int err;
  5423. unsigned long chksum;
  5424. ushort scsi_cfg1;
  5425. uchar byte;
  5426. uchar tid;
  5427. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  5428. ushort wdtr_able, sdtr_able, ppr_able, tagqng_able;
  5429. uchar max_cmd[ASC_MAX_TID + 1];
  5430. /* If there is already an error, don't continue. */
  5431. if (asc_dvc->err_code != 0) {
  5432. return ADV_ERROR;
  5433. }
  5434. /*
  5435. * The caller must set 'chip_type' to ADV_CHIP_ASC38C1600.
  5436. */
  5437. if (asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
  5438. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  5439. return ADV_ERROR;
  5440. }
  5441. warn_code = 0;
  5442. iop_base = asc_dvc->iop_base;
  5443. /*
  5444. * Save the RISC memory BIOS region before writing the microcode.
  5445. * The BIOS may already be loaded and using its RISC LRAM region
  5446. * so its region must be saved and restored.
  5447. *
  5448. * Note: This code makes the assumption, which is currently true,
  5449. * that a chip reset does not clear RISC LRAM.
  5450. */
  5451. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  5452. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  5453. bios_mem[i]);
  5454. }
  5455. /*
  5456. * Save current per TID negotiated values.
  5457. */
  5458. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5459. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5460. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5461. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5462. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  5463. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5464. max_cmd[tid]);
  5465. }
  5466. /*
  5467. * RAM BIST (Built-In Self Test)
  5468. *
  5469. * Address : I/O base + offset 0x38h register (byte).
  5470. * Function: Bit 7-6(RW) : RAM mode
  5471. * Normal Mode : 0x00
  5472. * Pre-test Mode : 0x40
  5473. * RAM Test Mode : 0x80
  5474. * Bit 5 : unused
  5475. * Bit 4(RO) : Done bit
  5476. * Bit 3-0(RO) : Status
  5477. * Host Error : 0x08
  5478. * Int_RAM Error : 0x04
  5479. * RISC Error : 0x02
  5480. * SCSI Error : 0x01
  5481. * No Error : 0x00
  5482. *
  5483. * Note: RAM BIST code should be put right here, before loading the
  5484. * microcode and after saving the RISC memory BIOS region.
  5485. */
  5486. /*
  5487. * LRAM Pre-test
  5488. *
  5489. * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
  5490. * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
  5491. * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
  5492. * to NORMAL_MODE, return an error too.
  5493. */
  5494. for (i = 0; i < 2; i++) {
  5495. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
  5496. mdelay(10); /* Wait for 10ms before reading back. */
  5497. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  5498. if ((byte & RAM_TEST_DONE) == 0
  5499. || (byte & 0x0F) != PRE_TEST_VALUE) {
  5500. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  5501. return ADV_ERROR;
  5502. }
  5503. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  5504. mdelay(10); /* Wait for 10ms before reading back. */
  5505. if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
  5506. != NORMAL_VALUE) {
  5507. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  5508. return ADV_ERROR;
  5509. }
  5510. }
  5511. /*
  5512. * LRAM Test - It takes about 1.5 ms to run through the test.
  5513. *
  5514. * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
  5515. * If Done bit not set or Status not 0, save register byte, set the
  5516. * err_code, and return an error.
  5517. */
  5518. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
  5519. mdelay(10); /* Wait for 10ms before checking status. */
  5520. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  5521. if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
  5522. /* Get here if Done bit not set or Status not 0. */
  5523. asc_dvc->bist_err_code = byte; /* for BIOS display message */
  5524. asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
  5525. return ADV_ERROR;
  5526. }
  5527. /* We need to reset back to normal mode after LRAM test passes. */
  5528. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  5529. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  5530. if (err) {
  5531. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  5532. fwname, err);
  5533. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  5534. return err;
  5535. }
  5536. if (fw->size < 4) {
  5537. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  5538. fw->size, fwname);
  5539. release_firmware(fw);
  5540. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  5541. return -EINVAL;
  5542. }
  5543. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  5544. (fw->data[1] << 8) | fw->data[0];
  5545. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  5546. fw->size - 4, ADV_38C1600_MEMSIZE,
  5547. chksum);
  5548. release_firmware(fw);
  5549. if (asc_dvc->err_code)
  5550. return ADV_ERROR;
  5551. /*
  5552. * Restore the RISC memory BIOS region.
  5553. */
  5554. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  5555. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  5556. bios_mem[i]);
  5557. }
  5558. /*
  5559. * Calculate and write the microcode code checksum to the microcode
  5560. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  5561. */
  5562. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  5563. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  5564. code_sum = 0;
  5565. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  5566. for (word = begin_addr; word < end_addr; word += 2) {
  5567. code_sum += AdvReadWordAutoIncLram(iop_base);
  5568. }
  5569. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  5570. /*
  5571. * Read microcode version and date.
  5572. */
  5573. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  5574. asc_dvc->cfg->mcode_date);
  5575. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  5576. asc_dvc->cfg->mcode_version);
  5577. /*
  5578. * Set the chip type to indicate the ASC38C1600.
  5579. */
  5580. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C1600);
  5581. /*
  5582. * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
  5583. * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
  5584. * cable detection and then we are able to read C_DET[3:0].
  5585. *
  5586. * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
  5587. * Microcode Default Value' section below.
  5588. */
  5589. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  5590. AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
  5591. scsi_cfg1 | DIS_TERM_DRV);
  5592. /*
  5593. * If the PCI Configuration Command Register "Parity Error Response
  5594. * Control" Bit was clear (0), then set the microcode variable
  5595. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  5596. * to ignore DMA parity errors.
  5597. */
  5598. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  5599. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5600. word |= CONTROL_FLAG_IGNORE_PERR;
  5601. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5602. }
  5603. /*
  5604. * If the BIOS control flag AIPP (Asynchronous Information
  5605. * Phase Protection) disable bit is not set, then set the firmware
  5606. * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable
  5607. * AIPP checking and encoding.
  5608. */
  5609. if ((asc_dvc->bios_ctrl & BIOS_CTRL_AIPP_DIS) == 0) {
  5610. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5611. word |= CONTROL_FLAG_ENABLE_AIPP;
  5612. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5613. }
  5614. /*
  5615. * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4],
  5616. * and START_CTL_TH [3:2].
  5617. */
  5618. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  5619. FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
  5620. /*
  5621. * Microcode operating variables for WDTR, SDTR, and command tag
  5622. * queuing will be set in slave_configure() based on what a
  5623. * device reports it is capable of in Inquiry byte 7.
  5624. *
  5625. * If SCSI Bus Resets have been disabled, then directly set
  5626. * SDTR and WDTR from the EEPROM configuration. This will allow
  5627. * the BIOS and warm boot to work without a SCSI bus hang on
  5628. * the Inquiry caused by host and target mismatched DTR values.
  5629. * Without the SCSI Bus Reset, before an Inquiry a device can't
  5630. * be assumed to be in Asynchronous, Narrow mode.
  5631. */
  5632. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  5633. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  5634. asc_dvc->wdtr_able);
  5635. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  5636. asc_dvc->sdtr_able);
  5637. }
  5638. /*
  5639. * Set microcode operating variables for DISC and SDTR_SPEED1,
  5640. * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
  5641. * configuration values.
  5642. *
  5643. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  5644. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  5645. * without determining here whether the device supports SDTR.
  5646. */
  5647. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  5648. asc_dvc->cfg->disc_enable);
  5649. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
  5650. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
  5651. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
  5652. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
  5653. /*
  5654. * Set SCSI_CFG0 Microcode Default Value.
  5655. *
  5656. * The microcode will set the SCSI_CFG0 register using this value
  5657. * after it is started below.
  5658. */
  5659. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  5660. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  5661. asc_dvc->chip_scsi_id);
  5662. /*
  5663. * Calculate SCSI_CFG1 Microcode Default Value.
  5664. *
  5665. * The microcode will set the SCSI_CFG1 register using this value
  5666. * after it is started below.
  5667. *
  5668. * Each ASC-38C1600 function has only two cable detect bits.
  5669. * The bus mode override bits are in IOPB_SOFT_OVER_WR.
  5670. */
  5671. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  5672. /*
  5673. * If the cable is reversed all of the SCSI_CTRL register signals
  5674. * will be set. Check for and return an error if this condition is
  5675. * found.
  5676. */
  5677. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  5678. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  5679. return ADV_ERROR;
  5680. }
  5681. /*
  5682. * Each ASC-38C1600 function has two connectors. Only an HVD device
  5683. * can not be connected to either connector. An LVD device or SE device
  5684. * may be connected to either connecor. If an SE device is connected,
  5685. * then at most Ultra speed (20 Mhz) can be used on both connectors.
  5686. *
  5687. * If an HVD device is attached, return an error.
  5688. */
  5689. if (scsi_cfg1 & HVD) {
  5690. asc_dvc->err_code |= ASC_IERR_HVD_DEVICE;
  5691. return ADV_ERROR;
  5692. }
  5693. /*
  5694. * Each function in the ASC-38C1600 uses only the SE cable detect and
  5695. * termination because there are two connectors for each function. Each
  5696. * function may use either LVD or SE mode. Corresponding the SE automatic
  5697. * termination control EEPROM bits are used for each function. Each
  5698. * function has its own EEPROM. If SE automatic control is enabled for
  5699. * the function, then set the termination value based on a table listed
  5700. * in a_condor.h.
  5701. *
  5702. * If manual termination is specified in the EEPROM for the function,
  5703. * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is
  5704. * ready to be 'ored' into SCSI_CFG1.
  5705. */
  5706. if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
  5707. struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
  5708. /* SE automatic termination control is enabled. */
  5709. switch (scsi_cfg1 & C_DET_SE) {
  5710. /* TERM_SE_HI: on, TERM_SE_LO: on */
  5711. case 0x1:
  5712. case 0x2:
  5713. case 0x3:
  5714. asc_dvc->cfg->termination |= TERM_SE;
  5715. break;
  5716. case 0x0:
  5717. if (PCI_FUNC(pdev->devfn) == 0) {
  5718. /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */
  5719. } else {
  5720. /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */
  5721. asc_dvc->cfg->termination |= TERM_SE_HI;
  5722. }
  5723. break;
  5724. }
  5725. }
  5726. /*
  5727. * Clear any set TERM_SE bits.
  5728. */
  5729. scsi_cfg1 &= ~TERM_SE;
  5730. /*
  5731. * Invert the TERM_SE bits and then set 'scsi_cfg1'.
  5732. */
  5733. scsi_cfg1 |= (~asc_dvc->cfg->termination & TERM_SE);
  5734. /*
  5735. * Clear Big Endian and Terminator Polarity bits and set possibly
  5736. * modified termination control bits in the Microcode SCSI_CFG1
  5737. * Register Value.
  5738. *
  5739. * Big Endian bit is not used even on big endian machines.
  5740. */
  5741. scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL);
  5742. /*
  5743. * Set SCSI_CFG1 Microcode Default Value
  5744. *
  5745. * Set possibly modified termination control bits in the Microcode
  5746. * SCSI_CFG1 Register Value.
  5747. *
  5748. * The microcode will set the SCSI_CFG1 register using this value
  5749. * after it is started below.
  5750. */
  5751. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
  5752. /*
  5753. * Set MEM_CFG Microcode Default Value
  5754. *
  5755. * The microcode will set the MEM_CFG register using this value
  5756. * after it is started below.
  5757. *
  5758. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  5759. * are defined.
  5760. *
  5761. * ASC-38C1600 has 32KB internal memory.
  5762. *
  5763. * XXX - Since ASC38C1600 Rev.3 has a Local RAM failure issue, we come
  5764. * out a special 16K Adv Library and Microcode version. After the issue
  5765. * resolved, we should turn back to the 32K support. Both a_condor.h and
  5766. * mcode.sas files also need to be updated.
  5767. *
  5768. * AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5769. * BIOS_EN | RAM_SZ_32KB);
  5770. */
  5771. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5772. BIOS_EN | RAM_SZ_16KB);
  5773. /*
  5774. * Set SEL_MASK Microcode Default Value
  5775. *
  5776. * The microcode will set the SEL_MASK register using this value
  5777. * after it is started below.
  5778. */
  5779. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  5780. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  5781. AdvBuildCarrierFreelist(asc_dvc);
  5782. /*
  5783. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  5784. */
  5785. if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL) {
  5786. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5787. return ADV_ERROR;
  5788. }
  5789. asc_dvc->carr_freelist = (ADV_CARR_T *)
  5790. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
  5791. /*
  5792. * The first command issued will be placed in the stopper carrier.
  5793. */
  5794. asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  5795. /*
  5796. * Set RISC ICQ physical address start value. Initialize the
  5797. * COMMA register to the same value otherwise the RISC will
  5798. * prematurely detect a command is available.
  5799. */
  5800. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  5801. AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
  5802. le32_to_cpu(asc_dvc->icq_sp->carr_pa));
  5803. /*
  5804. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  5805. */
  5806. if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL) {
  5807. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5808. return ADV_ERROR;
  5809. }
  5810. asc_dvc->carr_freelist = (ADV_CARR_T *)
  5811. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
  5812. /*
  5813. * The first command completed by the RISC will be placed in
  5814. * the stopper.
  5815. *
  5816. * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
  5817. * completed the RISC will set the ASC_RQ_STOPPER bit.
  5818. */
  5819. asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  5820. /*
  5821. * Set RISC IRQ physical address start value.
  5822. */
  5823. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  5824. asc_dvc->carr_pending_cnt = 0;
  5825. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  5826. (ADV_INTR_ENABLE_HOST_INTR |
  5827. ADV_INTR_ENABLE_GLOBAL_INTR));
  5828. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  5829. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  5830. /* finally, finally, gentlemen, start your engine */
  5831. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  5832. /*
  5833. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  5834. * Resets should be performed. The RISC has to be running
  5835. * to issue a SCSI Bus Reset.
  5836. */
  5837. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  5838. /*
  5839. * If the BIOS Signature is present in memory, restore the
  5840. * per TID microcode operating variables.
  5841. */
  5842. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  5843. 0x55AA) {
  5844. /*
  5845. * Restore per TID negotiated values.
  5846. */
  5847. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5848. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5849. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5850. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  5851. tagqng_able);
  5852. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  5853. AdvWriteByteLram(iop_base,
  5854. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5855. max_cmd[tid]);
  5856. }
  5857. } else {
  5858. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  5859. warn_code = ASC_WARN_BUSRESET_ERROR;
  5860. }
  5861. }
  5862. }
  5863. return warn_code;
  5864. }
  5865. /*
  5866. * Reset chip and SCSI Bus.
  5867. *
  5868. * Return Value:
  5869. * ADV_TRUE(1) - Chip re-initialization and SCSI Bus Reset successful.
  5870. * ADV_FALSE(0) - Chip re-initialization and SCSI Bus Reset failure.
  5871. */
  5872. static int AdvResetChipAndSB(ADV_DVC_VAR *asc_dvc)
  5873. {
  5874. int status;
  5875. ushort wdtr_able, sdtr_able, tagqng_able;
  5876. ushort ppr_able = 0;
  5877. uchar tid, max_cmd[ADV_MAX_TID + 1];
  5878. AdvPortAddr iop_base;
  5879. ushort bios_sig;
  5880. iop_base = asc_dvc->iop_base;
  5881. /*
  5882. * Save current per TID negotiated values.
  5883. */
  5884. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5885. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5886. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5887. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5888. }
  5889. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5890. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5891. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5892. max_cmd[tid]);
  5893. }
  5894. /*
  5895. * Force the AdvInitAsc3550/38C0800Driver() function to
  5896. * perform a SCSI Bus Reset by clearing the BIOS signature word.
  5897. * The initialization functions assumes a SCSI Bus Reset is not
  5898. * needed if the BIOS signature word is present.
  5899. */
  5900. AdvReadWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
  5901. AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, 0);
  5902. /*
  5903. * Stop chip and reset it.
  5904. */
  5905. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_STOP);
  5906. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_RESET);
  5907. mdelay(100);
  5908. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  5909. ADV_CTRL_REG_CMD_WR_IO_REG);
  5910. /*
  5911. * Reset Adv Library error code, if any, and try
  5912. * re-initializing the chip.
  5913. */
  5914. asc_dvc->err_code = 0;
  5915. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5916. status = AdvInitAsc38C1600Driver(asc_dvc);
  5917. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  5918. status = AdvInitAsc38C0800Driver(asc_dvc);
  5919. } else {
  5920. status = AdvInitAsc3550Driver(asc_dvc);
  5921. }
  5922. /* Translate initialization return value to status value. */
  5923. if (status == 0) {
  5924. status = ADV_TRUE;
  5925. } else {
  5926. status = ADV_FALSE;
  5927. }
  5928. /*
  5929. * Restore the BIOS signature word.
  5930. */
  5931. AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
  5932. /*
  5933. * Restore per TID negotiated values.
  5934. */
  5935. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5936. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5937. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5938. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5939. }
  5940. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5941. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5942. AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5943. max_cmd[tid]);
  5944. }
  5945. return status;
  5946. }
  5947. /*
  5948. * adv_async_callback() - Adv Library asynchronous event callback function.
  5949. */
  5950. static void adv_async_callback(ADV_DVC_VAR *adv_dvc_varp, uchar code)
  5951. {
  5952. switch (code) {
  5953. case ADV_ASYNC_SCSI_BUS_RESET_DET:
  5954. /*
  5955. * The firmware detected a SCSI Bus reset.
  5956. */
  5957. ASC_DBG(0, "ADV_ASYNC_SCSI_BUS_RESET_DET\n");
  5958. break;
  5959. case ADV_ASYNC_RDMA_FAILURE:
  5960. /*
  5961. * Handle RDMA failure by resetting the SCSI Bus and
  5962. * possibly the chip if it is unresponsive. Log the error
  5963. * with a unique code.
  5964. */
  5965. ASC_DBG(0, "ADV_ASYNC_RDMA_FAILURE\n");
  5966. AdvResetChipAndSB(adv_dvc_varp);
  5967. break;
  5968. case ADV_HOST_SCSI_BUS_RESET:
  5969. /*
  5970. * Host generated SCSI bus reset occurred.
  5971. */
  5972. ASC_DBG(0, "ADV_HOST_SCSI_BUS_RESET\n");
  5973. break;
  5974. default:
  5975. ASC_DBG(0, "unknown code 0x%x\n", code);
  5976. break;
  5977. }
  5978. }
  5979. /*
  5980. * adv_isr_callback() - Second Level Interrupt Handler called by AdvISR().
  5981. *
  5982. * Callback function for the Wide SCSI Adv Library.
  5983. */
  5984. static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
  5985. {
  5986. struct asc_board *boardp;
  5987. adv_req_t *reqp;
  5988. adv_sgblk_t *sgblkp;
  5989. struct scsi_cmnd *scp;
  5990. struct Scsi_Host *shost;
  5991. ADV_DCNT resid_cnt;
  5992. ASC_DBG(1, "adv_dvc_varp 0x%lx, scsiqp 0x%lx\n",
  5993. (ulong)adv_dvc_varp, (ulong)scsiqp);
  5994. ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
  5995. /*
  5996. * Get the adv_req_t structure for the command that has been
  5997. * completed. The adv_req_t structure actually contains the
  5998. * completed ADV_SCSI_REQ_Q structure.
  5999. */
  6000. reqp = (adv_req_t *)ADV_U32_TO_VADDR(scsiqp->srb_ptr);
  6001. ASC_DBG(1, "reqp 0x%lx\n", (ulong)reqp);
  6002. if (reqp == NULL) {
  6003. ASC_PRINT("adv_isr_callback: reqp is NULL\n");
  6004. return;
  6005. }
  6006. /*
  6007. * Get the struct scsi_cmnd structure and Scsi_Host structure for the
  6008. * command that has been completed.
  6009. *
  6010. * Note: The adv_req_t request structure and adv_sgblk_t structure,
  6011. * if any, are dropped, because a board structure pointer can not be
  6012. * determined.
  6013. */
  6014. scp = reqp->cmndp;
  6015. ASC_DBG(1, "scp 0x%p\n", scp);
  6016. if (scp == NULL) {
  6017. ASC_PRINT
  6018. ("adv_isr_callback: scp is NULL; adv_req_t dropped.\n");
  6019. return;
  6020. }
  6021. ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
  6022. shost = scp->device->host;
  6023. ASC_STATS(shost, callback);
  6024. ASC_DBG(1, "shost 0x%p\n", shost);
  6025. boardp = shost_priv(shost);
  6026. BUG_ON(adv_dvc_varp != &boardp->dvc_var.adv_dvc_var);
  6027. /*
  6028. * 'done_status' contains the command's ending status.
  6029. */
  6030. switch (scsiqp->done_status) {
  6031. case QD_NO_ERROR:
  6032. ASC_DBG(2, "QD_NO_ERROR\n");
  6033. scp->result = 0;
  6034. /*
  6035. * Check for an underrun condition.
  6036. *
  6037. * If there was no error and an underrun condition, then
  6038. * then return the number of underrun bytes.
  6039. */
  6040. resid_cnt = le32_to_cpu(scsiqp->data_cnt);
  6041. if (scsi_bufflen(scp) != 0 && resid_cnt != 0 &&
  6042. resid_cnt <= scsi_bufflen(scp)) {
  6043. ASC_DBG(1, "underrun condition %lu bytes\n",
  6044. (ulong)resid_cnt);
  6045. scsi_set_resid(scp, resid_cnt);
  6046. }
  6047. break;
  6048. case QD_WITH_ERROR:
  6049. ASC_DBG(2, "QD_WITH_ERROR\n");
  6050. switch (scsiqp->host_status) {
  6051. case QHSTA_NO_ERROR:
  6052. if (scsiqp->scsi_status == SAM_STAT_CHECK_CONDITION) {
  6053. ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
  6054. ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
  6055. SCSI_SENSE_BUFFERSIZE);
  6056. /*
  6057. * Note: The 'status_byte()' macro used by
  6058. * target drivers defined in scsi.h shifts the
  6059. * status byte returned by host drivers right
  6060. * by 1 bit. This is why target drivers also
  6061. * use right shifted status byte definitions.
  6062. * For instance target drivers use
  6063. * CHECK_CONDITION, defined to 0x1, instead of
  6064. * the SCSI defined check condition value of
  6065. * 0x2. Host drivers are supposed to return
  6066. * the status byte as it is defined by SCSI.
  6067. */
  6068. scp->result = DRIVER_BYTE(DRIVER_SENSE) |
  6069. STATUS_BYTE(scsiqp->scsi_status);
  6070. } else {
  6071. scp->result = STATUS_BYTE(scsiqp->scsi_status);
  6072. }
  6073. break;
  6074. default:
  6075. /* Some other QHSTA error occurred. */
  6076. ASC_DBG(1, "host_status 0x%x\n", scsiqp->host_status);
  6077. scp->result = HOST_BYTE(DID_BAD_TARGET);
  6078. break;
  6079. }
  6080. break;
  6081. case QD_ABORTED_BY_HOST:
  6082. ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
  6083. scp->result =
  6084. HOST_BYTE(DID_ABORT) | STATUS_BYTE(scsiqp->scsi_status);
  6085. break;
  6086. default:
  6087. ASC_DBG(1, "done_status 0x%x\n", scsiqp->done_status);
  6088. scp->result =
  6089. HOST_BYTE(DID_ERROR) | STATUS_BYTE(scsiqp->scsi_status);
  6090. break;
  6091. }
  6092. /*
  6093. * If the 'init_tidmask' bit isn't already set for the target and the
  6094. * current request finished normally, then set the bit for the target
  6095. * to indicate that a device is present.
  6096. */
  6097. if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
  6098. scsiqp->done_status == QD_NO_ERROR &&
  6099. scsiqp->host_status == QHSTA_NO_ERROR) {
  6100. boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
  6101. }
  6102. asc_scsi_done(scp);
  6103. /*
  6104. * Free all 'adv_sgblk_t' structures allocated for the request.
  6105. */
  6106. while ((sgblkp = reqp->sgblkp) != NULL) {
  6107. /* Remove 'sgblkp' from the request list. */
  6108. reqp->sgblkp = sgblkp->next_sgblkp;
  6109. /* Add 'sgblkp' to the board free list. */
  6110. sgblkp->next_sgblkp = boardp->adv_sgblkp;
  6111. boardp->adv_sgblkp = sgblkp;
  6112. }
  6113. /*
  6114. * Free the adv_req_t structure used with the command by adding
  6115. * it back to the board free list.
  6116. */
  6117. reqp->next_reqp = boardp->adv_reqp;
  6118. boardp->adv_reqp = reqp;
  6119. ASC_DBG(1, "done\n");
  6120. }
  6121. /*
  6122. * Adv Library Interrupt Service Routine
  6123. *
  6124. * This function is called by a driver's interrupt service routine.
  6125. * The function disables and re-enables interrupts.
  6126. *
  6127. * When a microcode idle command is completed, the ADV_DVC_VAR
  6128. * 'idle_cmd_done' field is set to ADV_TRUE.
  6129. *
  6130. * Note: AdvISR() can be called when interrupts are disabled or even
  6131. * when there is no hardware interrupt condition present. It will
  6132. * always check for completed idle commands and microcode requests.
  6133. * This is an important feature that shouldn't be changed because it
  6134. * allows commands to be completed from polling mode loops.
  6135. *
  6136. * Return:
  6137. * ADV_TRUE(1) - interrupt was pending
  6138. * ADV_FALSE(0) - no interrupt was pending
  6139. */
  6140. static int AdvISR(ADV_DVC_VAR *asc_dvc)
  6141. {
  6142. AdvPortAddr iop_base;
  6143. uchar int_stat;
  6144. ushort target_bit;
  6145. ADV_CARR_T *free_carrp;
  6146. ADV_VADDR irq_next_vpa;
  6147. ADV_SCSI_REQ_Q *scsiq;
  6148. iop_base = asc_dvc->iop_base;
  6149. /* Reading the register clears the interrupt. */
  6150. int_stat = AdvReadByteRegister(iop_base, IOPB_INTR_STATUS_REG);
  6151. if ((int_stat & (ADV_INTR_STATUS_INTRA | ADV_INTR_STATUS_INTRB |
  6152. ADV_INTR_STATUS_INTRC)) == 0) {
  6153. return ADV_FALSE;
  6154. }
  6155. /*
  6156. * Notify the driver of an asynchronous microcode condition by
  6157. * calling the adv_async_callback function. The function
  6158. * is passed the microcode ASC_MC_INTRB_CODE byte value.
  6159. */
  6160. if (int_stat & ADV_INTR_STATUS_INTRB) {
  6161. uchar intrb_code;
  6162. AdvReadByteLram(iop_base, ASC_MC_INTRB_CODE, intrb_code);
  6163. if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
  6164. asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  6165. if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE &&
  6166. asc_dvc->carr_pending_cnt != 0) {
  6167. AdvWriteByteRegister(iop_base, IOPB_TICKLE,
  6168. ADV_TICKLE_A);
  6169. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  6170. AdvWriteByteRegister(iop_base,
  6171. IOPB_TICKLE,
  6172. ADV_TICKLE_NOP);
  6173. }
  6174. }
  6175. }
  6176. adv_async_callback(asc_dvc, intrb_code);
  6177. }
  6178. /*
  6179. * Check if the IRQ stopper carrier contains a completed request.
  6180. */
  6181. while (((irq_next_vpa =
  6182. le32_to_cpu(asc_dvc->irq_sp->next_vpa)) & ASC_RQ_DONE) != 0) {
  6183. /*
  6184. * Get a pointer to the newly completed ADV_SCSI_REQ_Q structure.
  6185. * The RISC will have set 'areq_vpa' to a virtual address.
  6186. *
  6187. * The firmware will have copied the ASC_SCSI_REQ_Q.scsiq_ptr
  6188. * field to the carrier ADV_CARR_T.areq_vpa field. The conversion
  6189. * below complements the conversion of ASC_SCSI_REQ_Q.scsiq_ptr'
  6190. * in AdvExeScsiQueue().
  6191. */
  6192. scsiq = (ADV_SCSI_REQ_Q *)
  6193. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->areq_vpa));
  6194. /*
  6195. * Request finished with good status and the queue was not
  6196. * DMAed to host memory by the firmware. Set all status fields
  6197. * to indicate good status.
  6198. */
  6199. if ((irq_next_vpa & ASC_RQ_GOOD) != 0) {
  6200. scsiq->done_status = QD_NO_ERROR;
  6201. scsiq->host_status = scsiq->scsi_status = 0;
  6202. scsiq->data_cnt = 0L;
  6203. }
  6204. /*
  6205. * Advance the stopper pointer to the next carrier
  6206. * ignoring the lower four bits. Free the previous
  6207. * stopper carrier.
  6208. */
  6209. free_carrp = asc_dvc->irq_sp;
  6210. asc_dvc->irq_sp = (ADV_CARR_T *)
  6211. ADV_U32_TO_VADDR(ASC_GET_CARRP(irq_next_vpa));
  6212. free_carrp->next_vpa =
  6213. cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
  6214. asc_dvc->carr_freelist = free_carrp;
  6215. asc_dvc->carr_pending_cnt--;
  6216. target_bit = ADV_TID_TO_TIDMASK(scsiq->target_id);
  6217. /*
  6218. * Clear request microcode control flag.
  6219. */
  6220. scsiq->cntl = 0;
  6221. /*
  6222. * Notify the driver of the completed request by passing
  6223. * the ADV_SCSI_REQ_Q pointer to its callback function.
  6224. */
  6225. scsiq->a_flag |= ADV_SCSIQ_DONE;
  6226. adv_isr_callback(asc_dvc, scsiq);
  6227. /*
  6228. * Note: After the driver callback function is called, 'scsiq'
  6229. * can no longer be referenced.
  6230. *
  6231. * Fall through and continue processing other completed
  6232. * requests...
  6233. */
  6234. }
  6235. return ADV_TRUE;
  6236. }
  6237. static int AscSetLibErrorCode(ASC_DVC_VAR *asc_dvc, ushort err_code)
  6238. {
  6239. if (asc_dvc->err_code == 0) {
  6240. asc_dvc->err_code = err_code;
  6241. AscWriteLramWord(asc_dvc->iop_base, ASCV_ASCDVC_ERR_CODE_W,
  6242. err_code);
  6243. }
  6244. return err_code;
  6245. }
  6246. static void AscAckInterrupt(PortAddr iop_base)
  6247. {
  6248. uchar host_flag;
  6249. uchar risc_flag;
  6250. ushort loop;
  6251. loop = 0;
  6252. do {
  6253. risc_flag = AscReadLramByte(iop_base, ASCV_RISC_FLAG_B);
  6254. if (loop++ > 0x7FFF) {
  6255. break;
  6256. }
  6257. } while ((risc_flag & ASC_RISC_FLAG_GEN_INT) != 0);
  6258. host_flag =
  6259. AscReadLramByte(iop_base,
  6260. ASCV_HOST_FLAG_B) & (~ASC_HOST_FLAG_ACK_INT);
  6261. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
  6262. (uchar)(host_flag | ASC_HOST_FLAG_ACK_INT));
  6263. AscSetChipStatus(iop_base, CIW_INT_ACK);
  6264. loop = 0;
  6265. while (AscGetChipStatus(iop_base) & CSW_INT_PENDING) {
  6266. AscSetChipStatus(iop_base, CIW_INT_ACK);
  6267. if (loop++ > 3) {
  6268. break;
  6269. }
  6270. }
  6271. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
  6272. }
  6273. static uchar AscGetSynPeriodIndex(ASC_DVC_VAR *asc_dvc, uchar syn_time)
  6274. {
  6275. const uchar *period_table;
  6276. int max_index;
  6277. int min_index;
  6278. int i;
  6279. period_table = asc_dvc->sdtr_period_tbl;
  6280. max_index = (int)asc_dvc->max_sdtr_index;
  6281. min_index = (int)asc_dvc->min_sdtr_index;
  6282. if ((syn_time <= period_table[max_index])) {
  6283. for (i = min_index; i < (max_index - 1); i++) {
  6284. if (syn_time <= period_table[i]) {
  6285. return (uchar)i;
  6286. }
  6287. }
  6288. return (uchar)max_index;
  6289. } else {
  6290. return (uchar)(max_index + 1);
  6291. }
  6292. }
  6293. static uchar
  6294. AscMsgOutSDTR(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar sdtr_offset)
  6295. {
  6296. EXT_MSG sdtr_buf;
  6297. uchar sdtr_period_index;
  6298. PortAddr iop_base;
  6299. iop_base = asc_dvc->iop_base;
  6300. sdtr_buf.msg_type = EXTENDED_MESSAGE;
  6301. sdtr_buf.msg_len = MS_SDTR_LEN;
  6302. sdtr_buf.msg_req = EXTENDED_SDTR;
  6303. sdtr_buf.xfer_period = sdtr_period;
  6304. sdtr_offset &= ASC_SYN_MAX_OFFSET;
  6305. sdtr_buf.req_ack_offset = sdtr_offset;
  6306. sdtr_period_index = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
  6307. if (sdtr_period_index <= asc_dvc->max_sdtr_index) {
  6308. AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
  6309. (uchar *)&sdtr_buf,
  6310. sizeof(EXT_MSG) >> 1);
  6311. return ((sdtr_period_index << 4) | sdtr_offset);
  6312. } else {
  6313. sdtr_buf.req_ack_offset = 0;
  6314. AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
  6315. (uchar *)&sdtr_buf,
  6316. sizeof(EXT_MSG) >> 1);
  6317. return 0;
  6318. }
  6319. }
  6320. static uchar
  6321. AscCalSDTRData(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar syn_offset)
  6322. {
  6323. uchar byte;
  6324. uchar sdtr_period_ix;
  6325. sdtr_period_ix = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
  6326. if (sdtr_period_ix > asc_dvc->max_sdtr_index)
  6327. return 0xFF;
  6328. byte = (sdtr_period_ix << 4) | (syn_offset & ASC_SYN_MAX_OFFSET);
  6329. return byte;
  6330. }
  6331. static int AscSetChipSynRegAtID(PortAddr iop_base, uchar id, uchar sdtr_data)
  6332. {
  6333. ASC_SCSI_BIT_ID_TYPE org_id;
  6334. int i;
  6335. int sta = TRUE;
  6336. AscSetBank(iop_base, 1);
  6337. org_id = AscReadChipDvcID(iop_base);
  6338. for (i = 0; i <= ASC_MAX_TID; i++) {
  6339. if (org_id == (0x01 << i))
  6340. break;
  6341. }
  6342. org_id = (ASC_SCSI_BIT_ID_TYPE) i;
  6343. AscWriteChipDvcID(iop_base, id);
  6344. if (AscReadChipDvcID(iop_base) == (0x01 << id)) {
  6345. AscSetBank(iop_base, 0);
  6346. AscSetChipSyn(iop_base, sdtr_data);
  6347. if (AscGetChipSyn(iop_base) != sdtr_data) {
  6348. sta = FALSE;
  6349. }
  6350. } else {
  6351. sta = FALSE;
  6352. }
  6353. AscSetBank(iop_base, 1);
  6354. AscWriteChipDvcID(iop_base, org_id);
  6355. AscSetBank(iop_base, 0);
  6356. return (sta);
  6357. }
  6358. static void AscSetChipSDTR(PortAddr iop_base, uchar sdtr_data, uchar tid_no)
  6359. {
  6360. AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
  6361. AscPutMCodeSDTRDoneAtID(iop_base, tid_no, sdtr_data);
  6362. }
  6363. static int AscIsrChipHalted(ASC_DVC_VAR *asc_dvc)
  6364. {
  6365. EXT_MSG ext_msg;
  6366. EXT_MSG out_msg;
  6367. ushort halt_q_addr;
  6368. int sdtr_accept;
  6369. ushort int_halt_code;
  6370. ASC_SCSI_BIT_ID_TYPE scsi_busy;
  6371. ASC_SCSI_BIT_ID_TYPE target_id;
  6372. PortAddr iop_base;
  6373. uchar tag_code;
  6374. uchar q_status;
  6375. uchar halt_qp;
  6376. uchar sdtr_data;
  6377. uchar target_ix;
  6378. uchar q_cntl, tid_no;
  6379. uchar cur_dvc_qng;
  6380. uchar asyn_sdtr;
  6381. uchar scsi_status;
  6382. struct asc_board *boardp;
  6383. BUG_ON(!asc_dvc->drv_ptr);
  6384. boardp = asc_dvc->drv_ptr;
  6385. iop_base = asc_dvc->iop_base;
  6386. int_halt_code = AscReadLramWord(iop_base, ASCV_HALTCODE_W);
  6387. halt_qp = AscReadLramByte(iop_base, ASCV_CURCDB_B);
  6388. halt_q_addr = ASC_QNO_TO_QADDR(halt_qp);
  6389. target_ix = AscReadLramByte(iop_base,
  6390. (ushort)(halt_q_addr +
  6391. (ushort)ASC_SCSIQ_B_TARGET_IX));
  6392. q_cntl = AscReadLramByte(iop_base,
  6393. (ushort)(halt_q_addr + (ushort)ASC_SCSIQ_B_CNTL));
  6394. tid_no = ASC_TIX_TO_TID(target_ix);
  6395. target_id = (uchar)ASC_TID_TO_TARGET_ID(tid_no);
  6396. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  6397. asyn_sdtr = ASYN_SDTR_DATA_FIX_PCI_REV_AB;
  6398. } else {
  6399. asyn_sdtr = 0;
  6400. }
  6401. if (int_halt_code == ASC_HALT_DISABLE_ASYN_USE_SYN_FIX) {
  6402. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  6403. AscSetChipSDTR(iop_base, 0, tid_no);
  6404. boardp->sdtr_data[tid_no] = 0;
  6405. }
  6406. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6407. return (0);
  6408. } else if (int_halt_code == ASC_HALT_ENABLE_ASYN_USE_SYN_FIX) {
  6409. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  6410. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  6411. boardp->sdtr_data[tid_no] = asyn_sdtr;
  6412. }
  6413. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6414. return (0);
  6415. } else if (int_halt_code == ASC_HALT_EXTMSG_IN) {
  6416. AscMemWordCopyPtrFromLram(iop_base,
  6417. ASCV_MSGIN_BEG,
  6418. (uchar *)&ext_msg,
  6419. sizeof(EXT_MSG) >> 1);
  6420. if (ext_msg.msg_type == EXTENDED_MESSAGE &&
  6421. ext_msg.msg_req == EXTENDED_SDTR &&
  6422. ext_msg.msg_len == MS_SDTR_LEN) {
  6423. sdtr_accept = TRUE;
  6424. if ((ext_msg.req_ack_offset > ASC_SYN_MAX_OFFSET)) {
  6425. sdtr_accept = FALSE;
  6426. ext_msg.req_ack_offset = ASC_SYN_MAX_OFFSET;
  6427. }
  6428. if ((ext_msg.xfer_period <
  6429. asc_dvc->sdtr_period_tbl[asc_dvc->min_sdtr_index])
  6430. || (ext_msg.xfer_period >
  6431. asc_dvc->sdtr_period_tbl[asc_dvc->
  6432. max_sdtr_index])) {
  6433. sdtr_accept = FALSE;
  6434. ext_msg.xfer_period =
  6435. asc_dvc->sdtr_period_tbl[asc_dvc->
  6436. min_sdtr_index];
  6437. }
  6438. if (sdtr_accept) {
  6439. sdtr_data =
  6440. AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
  6441. ext_msg.req_ack_offset);
  6442. if ((sdtr_data == 0xFF)) {
  6443. q_cntl |= QC_MSG_OUT;
  6444. asc_dvc->init_sdtr &= ~target_id;
  6445. asc_dvc->sdtr_done &= ~target_id;
  6446. AscSetChipSDTR(iop_base, asyn_sdtr,
  6447. tid_no);
  6448. boardp->sdtr_data[tid_no] = asyn_sdtr;
  6449. }
  6450. }
  6451. if (ext_msg.req_ack_offset == 0) {
  6452. q_cntl &= ~QC_MSG_OUT;
  6453. asc_dvc->init_sdtr &= ~target_id;
  6454. asc_dvc->sdtr_done &= ~target_id;
  6455. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  6456. } else {
  6457. if (sdtr_accept && (q_cntl & QC_MSG_OUT)) {
  6458. q_cntl &= ~QC_MSG_OUT;
  6459. asc_dvc->sdtr_done |= target_id;
  6460. asc_dvc->init_sdtr |= target_id;
  6461. asc_dvc->pci_fix_asyn_xfer &=
  6462. ~target_id;
  6463. sdtr_data =
  6464. AscCalSDTRData(asc_dvc,
  6465. ext_msg.xfer_period,
  6466. ext_msg.
  6467. req_ack_offset);
  6468. AscSetChipSDTR(iop_base, sdtr_data,
  6469. tid_no);
  6470. boardp->sdtr_data[tid_no] = sdtr_data;
  6471. } else {
  6472. q_cntl |= QC_MSG_OUT;
  6473. AscMsgOutSDTR(asc_dvc,
  6474. ext_msg.xfer_period,
  6475. ext_msg.req_ack_offset);
  6476. asc_dvc->pci_fix_asyn_xfer &=
  6477. ~target_id;
  6478. sdtr_data =
  6479. AscCalSDTRData(asc_dvc,
  6480. ext_msg.xfer_period,
  6481. ext_msg.
  6482. req_ack_offset);
  6483. AscSetChipSDTR(iop_base, sdtr_data,
  6484. tid_no);
  6485. boardp->sdtr_data[tid_no] = sdtr_data;
  6486. asc_dvc->sdtr_done |= target_id;
  6487. asc_dvc->init_sdtr |= target_id;
  6488. }
  6489. }
  6490. AscWriteLramByte(iop_base,
  6491. (ushort)(halt_q_addr +
  6492. (ushort)ASC_SCSIQ_B_CNTL),
  6493. q_cntl);
  6494. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6495. return (0);
  6496. } else if (ext_msg.msg_type == EXTENDED_MESSAGE &&
  6497. ext_msg.msg_req == EXTENDED_WDTR &&
  6498. ext_msg.msg_len == MS_WDTR_LEN) {
  6499. ext_msg.wdtr_width = 0;
  6500. AscMemWordCopyPtrToLram(iop_base,
  6501. ASCV_MSGOUT_BEG,
  6502. (uchar *)&ext_msg,
  6503. sizeof(EXT_MSG) >> 1);
  6504. q_cntl |= QC_MSG_OUT;
  6505. AscWriteLramByte(iop_base,
  6506. (ushort)(halt_q_addr +
  6507. (ushort)ASC_SCSIQ_B_CNTL),
  6508. q_cntl);
  6509. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6510. return (0);
  6511. } else {
  6512. ext_msg.msg_type = MESSAGE_REJECT;
  6513. AscMemWordCopyPtrToLram(iop_base,
  6514. ASCV_MSGOUT_BEG,
  6515. (uchar *)&ext_msg,
  6516. sizeof(EXT_MSG) >> 1);
  6517. q_cntl |= QC_MSG_OUT;
  6518. AscWriteLramByte(iop_base,
  6519. (ushort)(halt_q_addr +
  6520. (ushort)ASC_SCSIQ_B_CNTL),
  6521. q_cntl);
  6522. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6523. return (0);
  6524. }
  6525. } else if (int_halt_code == ASC_HALT_CHK_CONDITION) {
  6526. q_cntl |= QC_REQ_SENSE;
  6527. if ((asc_dvc->init_sdtr & target_id) != 0) {
  6528. asc_dvc->sdtr_done &= ~target_id;
  6529. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  6530. q_cntl |= QC_MSG_OUT;
  6531. AscMsgOutSDTR(asc_dvc,
  6532. asc_dvc->
  6533. sdtr_period_tbl[(sdtr_data >> 4) &
  6534. (uchar)(asc_dvc->
  6535. max_sdtr_index -
  6536. 1)],
  6537. (uchar)(sdtr_data & (uchar)
  6538. ASC_SYN_MAX_OFFSET));
  6539. }
  6540. AscWriteLramByte(iop_base,
  6541. (ushort)(halt_q_addr +
  6542. (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
  6543. tag_code = AscReadLramByte(iop_base,
  6544. (ushort)(halt_q_addr + (ushort)
  6545. ASC_SCSIQ_B_TAG_CODE));
  6546. tag_code &= 0xDC;
  6547. if ((asc_dvc->pci_fix_asyn_xfer & target_id)
  6548. && !(asc_dvc->pci_fix_asyn_xfer_always & target_id)
  6549. ) {
  6550. tag_code |= (ASC_TAG_FLAG_DISABLE_DISCONNECT
  6551. | ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX);
  6552. }
  6553. AscWriteLramByte(iop_base,
  6554. (ushort)(halt_q_addr +
  6555. (ushort)ASC_SCSIQ_B_TAG_CODE),
  6556. tag_code);
  6557. q_status = AscReadLramByte(iop_base,
  6558. (ushort)(halt_q_addr + (ushort)
  6559. ASC_SCSIQ_B_STATUS));
  6560. q_status |= (QS_READY | QS_BUSY);
  6561. AscWriteLramByte(iop_base,
  6562. (ushort)(halt_q_addr +
  6563. (ushort)ASC_SCSIQ_B_STATUS),
  6564. q_status);
  6565. scsi_busy = AscReadLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B);
  6566. scsi_busy &= ~target_id;
  6567. AscWriteLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B, scsi_busy);
  6568. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6569. return (0);
  6570. } else if (int_halt_code == ASC_HALT_SDTR_REJECTED) {
  6571. AscMemWordCopyPtrFromLram(iop_base,
  6572. ASCV_MSGOUT_BEG,
  6573. (uchar *)&out_msg,
  6574. sizeof(EXT_MSG) >> 1);
  6575. if ((out_msg.msg_type == EXTENDED_MESSAGE) &&
  6576. (out_msg.msg_len == MS_SDTR_LEN) &&
  6577. (out_msg.msg_req == EXTENDED_SDTR)) {
  6578. asc_dvc->init_sdtr &= ~target_id;
  6579. asc_dvc->sdtr_done &= ~target_id;
  6580. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  6581. boardp->sdtr_data[tid_no] = asyn_sdtr;
  6582. }
  6583. q_cntl &= ~QC_MSG_OUT;
  6584. AscWriteLramByte(iop_base,
  6585. (ushort)(halt_q_addr +
  6586. (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
  6587. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6588. return (0);
  6589. } else if (int_halt_code == ASC_HALT_SS_QUEUE_FULL) {
  6590. scsi_status = AscReadLramByte(iop_base,
  6591. (ushort)((ushort)halt_q_addr +
  6592. (ushort)
  6593. ASC_SCSIQ_SCSI_STATUS));
  6594. cur_dvc_qng =
  6595. AscReadLramByte(iop_base,
  6596. (ushort)((ushort)ASC_QADR_BEG +
  6597. (ushort)target_ix));
  6598. if ((cur_dvc_qng > 0) && (asc_dvc->cur_dvc_qng[tid_no] > 0)) {
  6599. scsi_busy = AscReadLramByte(iop_base,
  6600. (ushort)ASCV_SCSIBUSY_B);
  6601. scsi_busy |= target_id;
  6602. AscWriteLramByte(iop_base,
  6603. (ushort)ASCV_SCSIBUSY_B, scsi_busy);
  6604. asc_dvc->queue_full_or_busy |= target_id;
  6605. if (scsi_status == SAM_STAT_TASK_SET_FULL) {
  6606. if (cur_dvc_qng > ASC_MIN_TAGGED_CMD) {
  6607. cur_dvc_qng -= 1;
  6608. asc_dvc->max_dvc_qng[tid_no] =
  6609. cur_dvc_qng;
  6610. AscWriteLramByte(iop_base,
  6611. (ushort)((ushort)
  6612. ASCV_MAX_DVC_QNG_BEG
  6613. + (ushort)
  6614. tid_no),
  6615. cur_dvc_qng);
  6616. /*
  6617. * Set the device queue depth to the
  6618. * number of active requests when the
  6619. * QUEUE FULL condition was encountered.
  6620. */
  6621. boardp->queue_full |= target_id;
  6622. boardp->queue_full_cnt[tid_no] =
  6623. cur_dvc_qng;
  6624. }
  6625. }
  6626. }
  6627. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6628. return (0);
  6629. }
  6630. #if CC_VERY_LONG_SG_LIST
  6631. else if (int_halt_code == ASC_HALT_HOST_COPY_SG_LIST_TO_RISC) {
  6632. uchar q_no;
  6633. ushort q_addr;
  6634. uchar sg_wk_q_no;
  6635. uchar first_sg_wk_q_no;
  6636. ASC_SCSI_Q *scsiq; /* Ptr to driver request. */
  6637. ASC_SG_HEAD *sg_head; /* Ptr to driver SG request. */
  6638. ASC_SG_LIST_Q scsi_sg_q; /* Structure written to queue. */
  6639. ushort sg_list_dwords;
  6640. ushort sg_entry_cnt;
  6641. uchar next_qp;
  6642. int i;
  6643. q_no = AscReadLramByte(iop_base, (ushort)ASCV_REQ_SG_LIST_QP);
  6644. if (q_no == ASC_QLINK_END)
  6645. return 0;
  6646. q_addr = ASC_QNO_TO_QADDR(q_no);
  6647. /*
  6648. * Convert the request's SRB pointer to a host ASC_SCSI_REQ
  6649. * structure pointer using a macro provided by the driver.
  6650. * The ASC_SCSI_REQ pointer provides a pointer to the
  6651. * host ASC_SG_HEAD structure.
  6652. */
  6653. /* Read request's SRB pointer. */
  6654. scsiq = (ASC_SCSI_Q *)
  6655. ASC_SRB2SCSIQ(ASC_U32_TO_VADDR(AscReadLramDWord(iop_base,
  6656. (ushort)
  6657. (q_addr +
  6658. ASC_SCSIQ_D_SRBPTR))));
  6659. /*
  6660. * Get request's first and working SG queue.
  6661. */
  6662. sg_wk_q_no = AscReadLramByte(iop_base,
  6663. (ushort)(q_addr +
  6664. ASC_SCSIQ_B_SG_WK_QP));
  6665. first_sg_wk_q_no = AscReadLramByte(iop_base,
  6666. (ushort)(q_addr +
  6667. ASC_SCSIQ_B_FIRST_SG_WK_QP));
  6668. /*
  6669. * Reset request's working SG queue back to the
  6670. * first SG queue.
  6671. */
  6672. AscWriteLramByte(iop_base,
  6673. (ushort)(q_addr +
  6674. (ushort)ASC_SCSIQ_B_SG_WK_QP),
  6675. first_sg_wk_q_no);
  6676. sg_head = scsiq->sg_head;
  6677. /*
  6678. * Set sg_entry_cnt to the number of SG elements
  6679. * that will be completed on this interrupt.
  6680. *
  6681. * Note: The allocated SG queues contain ASC_MAX_SG_LIST - 1
  6682. * SG elements. The data_cnt and data_addr fields which
  6683. * add 1 to the SG element capacity are not used when
  6684. * restarting SG handling after a halt.
  6685. */
  6686. if (scsiq->remain_sg_entry_cnt > (ASC_MAX_SG_LIST - 1)) {
  6687. sg_entry_cnt = ASC_MAX_SG_LIST - 1;
  6688. /*
  6689. * Keep track of remaining number of SG elements that
  6690. * will need to be handled on the next interrupt.
  6691. */
  6692. scsiq->remain_sg_entry_cnt -= (ASC_MAX_SG_LIST - 1);
  6693. } else {
  6694. sg_entry_cnt = scsiq->remain_sg_entry_cnt;
  6695. scsiq->remain_sg_entry_cnt = 0;
  6696. }
  6697. /*
  6698. * Copy SG elements into the list of allocated SG queues.
  6699. *
  6700. * Last index completed is saved in scsiq->next_sg_index.
  6701. */
  6702. next_qp = first_sg_wk_q_no;
  6703. q_addr = ASC_QNO_TO_QADDR(next_qp);
  6704. scsi_sg_q.sg_head_qp = q_no;
  6705. scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
  6706. for (i = 0; i < sg_head->queue_cnt; i++) {
  6707. scsi_sg_q.seq_no = i + 1;
  6708. if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
  6709. sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2);
  6710. sg_entry_cnt -= ASC_SG_LIST_PER_Q;
  6711. /*
  6712. * After very first SG queue RISC FW uses next
  6713. * SG queue first element then checks sg_list_cnt
  6714. * against zero and then decrements, so set
  6715. * sg_list_cnt 1 less than number of SG elements
  6716. * in each SG queue.
  6717. */
  6718. scsi_sg_q.sg_list_cnt = ASC_SG_LIST_PER_Q - 1;
  6719. scsi_sg_q.sg_cur_list_cnt =
  6720. ASC_SG_LIST_PER_Q - 1;
  6721. } else {
  6722. /*
  6723. * This is the last SG queue in the list of
  6724. * allocated SG queues. If there are more
  6725. * SG elements than will fit in the allocated
  6726. * queues, then set the QCSG_SG_XFER_MORE flag.
  6727. */
  6728. if (scsiq->remain_sg_entry_cnt != 0) {
  6729. scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
  6730. } else {
  6731. scsi_sg_q.cntl |= QCSG_SG_XFER_END;
  6732. }
  6733. /* equals sg_entry_cnt * 2 */
  6734. sg_list_dwords = sg_entry_cnt << 1;
  6735. scsi_sg_q.sg_list_cnt = sg_entry_cnt - 1;
  6736. scsi_sg_q.sg_cur_list_cnt = sg_entry_cnt - 1;
  6737. sg_entry_cnt = 0;
  6738. }
  6739. scsi_sg_q.q_no = next_qp;
  6740. AscMemWordCopyPtrToLram(iop_base,
  6741. q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
  6742. (uchar *)&scsi_sg_q,
  6743. sizeof(ASC_SG_LIST_Q) >> 1);
  6744. AscMemDWordCopyPtrToLram(iop_base,
  6745. q_addr + ASC_SGQ_LIST_BEG,
  6746. (uchar *)&sg_head->
  6747. sg_list[scsiq->next_sg_index],
  6748. sg_list_dwords);
  6749. scsiq->next_sg_index += ASC_SG_LIST_PER_Q;
  6750. /*
  6751. * If the just completed SG queue contained the
  6752. * last SG element, then no more SG queues need
  6753. * to be written.
  6754. */
  6755. if (scsi_sg_q.cntl & QCSG_SG_XFER_END) {
  6756. break;
  6757. }
  6758. next_qp = AscReadLramByte(iop_base,
  6759. (ushort)(q_addr +
  6760. ASC_SCSIQ_B_FWD));
  6761. q_addr = ASC_QNO_TO_QADDR(next_qp);
  6762. }
  6763. /*
  6764. * Clear the halt condition so the RISC will be restarted
  6765. * after the return.
  6766. */
  6767. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6768. return (0);
  6769. }
  6770. #endif /* CC_VERY_LONG_SG_LIST */
  6771. return (0);
  6772. }
  6773. /*
  6774. * void
  6775. * DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
  6776. *
  6777. * Calling/Exit State:
  6778. * none
  6779. *
  6780. * Description:
  6781. * Input an ASC_QDONE_INFO structure from the chip
  6782. */
  6783. static void
  6784. DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
  6785. {
  6786. int i;
  6787. ushort word;
  6788. AscSetChipLramAddr(iop_base, s_addr);
  6789. for (i = 0; i < 2 * words; i += 2) {
  6790. if (i == 10) {
  6791. continue;
  6792. }
  6793. word = inpw(iop_base + IOP_RAM_DATA);
  6794. inbuf[i] = word & 0xff;
  6795. inbuf[i + 1] = (word >> 8) & 0xff;
  6796. }
  6797. ASC_DBG_PRT_HEX(2, "DvcGetQinfo", inbuf, 2 * words);
  6798. }
  6799. static uchar
  6800. _AscCopyLramScsiDoneQ(PortAddr iop_base,
  6801. ushort q_addr,
  6802. ASC_QDONE_INFO *scsiq, ASC_DCNT max_dma_count)
  6803. {
  6804. ushort _val;
  6805. uchar sg_queue_cnt;
  6806. DvcGetQinfo(iop_base,
  6807. q_addr + ASC_SCSIQ_DONE_INFO_BEG,
  6808. (uchar *)scsiq,
  6809. (sizeof(ASC_SCSIQ_2) + sizeof(ASC_SCSIQ_3)) / 2);
  6810. _val = AscReadLramWord(iop_base,
  6811. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS));
  6812. scsiq->q_status = (uchar)_val;
  6813. scsiq->q_no = (uchar)(_val >> 8);
  6814. _val = AscReadLramWord(iop_base,
  6815. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_CNTL));
  6816. scsiq->cntl = (uchar)_val;
  6817. sg_queue_cnt = (uchar)(_val >> 8);
  6818. _val = AscReadLramWord(iop_base,
  6819. (ushort)(q_addr +
  6820. (ushort)ASC_SCSIQ_B_SENSE_LEN));
  6821. scsiq->sense_len = (uchar)_val;
  6822. scsiq->extra_bytes = (uchar)(_val >> 8);
  6823. /*
  6824. * Read high word of remain bytes from alternate location.
  6825. */
  6826. scsiq->remain_bytes = (((ADV_DCNT)AscReadLramWord(iop_base,
  6827. (ushort)(q_addr +
  6828. (ushort)
  6829. ASC_SCSIQ_W_ALT_DC1)))
  6830. << 16);
  6831. /*
  6832. * Read low word of remain bytes from original location.
  6833. */
  6834. scsiq->remain_bytes += AscReadLramWord(iop_base,
  6835. (ushort)(q_addr + (ushort)
  6836. ASC_SCSIQ_DW_REMAIN_XFER_CNT));
  6837. scsiq->remain_bytes &= max_dma_count;
  6838. return sg_queue_cnt;
  6839. }
  6840. /*
  6841. * asc_isr_callback() - Second Level Interrupt Handler called by AscISR().
  6842. *
  6843. * Interrupt callback function for the Narrow SCSI Asc Library.
  6844. */
  6845. static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
  6846. {
  6847. struct asc_board *boardp;
  6848. struct scsi_cmnd *scp;
  6849. struct Scsi_Host *shost;
  6850. ASC_DBG(1, "asc_dvc_varp 0x%p, qdonep 0x%p\n", asc_dvc_varp, qdonep);
  6851. ASC_DBG_PRT_ASC_QDONE_INFO(2, qdonep);
  6852. scp = advansys_srb_to_ptr(asc_dvc_varp, qdonep->d2.srb_ptr);
  6853. if (!scp)
  6854. return;
  6855. ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
  6856. shost = scp->device->host;
  6857. ASC_STATS(shost, callback);
  6858. ASC_DBG(1, "shost 0x%p\n", shost);
  6859. boardp = shost_priv(shost);
  6860. BUG_ON(asc_dvc_varp != &boardp->dvc_var.asc_dvc_var);
  6861. dma_unmap_single(boardp->dev, scp->SCp.dma_handle,
  6862. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  6863. /*
  6864. * 'qdonep' contains the command's ending status.
  6865. */
  6866. switch (qdonep->d3.done_stat) {
  6867. case QD_NO_ERROR:
  6868. ASC_DBG(2, "QD_NO_ERROR\n");
  6869. scp->result = 0;
  6870. /*
  6871. * Check for an underrun condition.
  6872. *
  6873. * If there was no error and an underrun condition, then
  6874. * return the number of underrun bytes.
  6875. */
  6876. if (scsi_bufflen(scp) != 0 && qdonep->remain_bytes != 0 &&
  6877. qdonep->remain_bytes <= scsi_bufflen(scp)) {
  6878. ASC_DBG(1, "underrun condition %u bytes\n",
  6879. (unsigned)qdonep->remain_bytes);
  6880. scsi_set_resid(scp, qdonep->remain_bytes);
  6881. }
  6882. break;
  6883. case QD_WITH_ERROR:
  6884. ASC_DBG(2, "QD_WITH_ERROR\n");
  6885. switch (qdonep->d3.host_stat) {
  6886. case QHSTA_NO_ERROR:
  6887. if (qdonep->d3.scsi_stat == SAM_STAT_CHECK_CONDITION) {
  6888. ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
  6889. ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
  6890. SCSI_SENSE_BUFFERSIZE);
  6891. /*
  6892. * Note: The 'status_byte()' macro used by
  6893. * target drivers defined in scsi.h shifts the
  6894. * status byte returned by host drivers right
  6895. * by 1 bit. This is why target drivers also
  6896. * use right shifted status byte definitions.
  6897. * For instance target drivers use
  6898. * CHECK_CONDITION, defined to 0x1, instead of
  6899. * the SCSI defined check condition value of
  6900. * 0x2. Host drivers are supposed to return
  6901. * the status byte as it is defined by SCSI.
  6902. */
  6903. scp->result = DRIVER_BYTE(DRIVER_SENSE) |
  6904. STATUS_BYTE(qdonep->d3.scsi_stat);
  6905. } else {
  6906. scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
  6907. }
  6908. break;
  6909. default:
  6910. /* QHSTA error occurred */
  6911. ASC_DBG(1, "host_stat 0x%x\n", qdonep->d3.host_stat);
  6912. scp->result = HOST_BYTE(DID_BAD_TARGET);
  6913. break;
  6914. }
  6915. break;
  6916. case QD_ABORTED_BY_HOST:
  6917. ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
  6918. scp->result =
  6919. HOST_BYTE(DID_ABORT) | MSG_BYTE(qdonep->d3.
  6920. scsi_msg) |
  6921. STATUS_BYTE(qdonep->d3.scsi_stat);
  6922. break;
  6923. default:
  6924. ASC_DBG(1, "done_stat 0x%x\n", qdonep->d3.done_stat);
  6925. scp->result =
  6926. HOST_BYTE(DID_ERROR) | MSG_BYTE(qdonep->d3.
  6927. scsi_msg) |
  6928. STATUS_BYTE(qdonep->d3.scsi_stat);
  6929. break;
  6930. }
  6931. /*
  6932. * If the 'init_tidmask' bit isn't already set for the target and the
  6933. * current request finished normally, then set the bit for the target
  6934. * to indicate that a device is present.
  6935. */
  6936. if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
  6937. qdonep->d3.done_stat == QD_NO_ERROR &&
  6938. qdonep->d3.host_stat == QHSTA_NO_ERROR) {
  6939. boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
  6940. }
  6941. asc_scsi_done(scp);
  6942. }
  6943. static int AscIsrQDone(ASC_DVC_VAR *asc_dvc)
  6944. {
  6945. uchar next_qp;
  6946. uchar n_q_used;
  6947. uchar sg_list_qp;
  6948. uchar sg_queue_cnt;
  6949. uchar q_cnt;
  6950. uchar done_q_tail;
  6951. uchar tid_no;
  6952. ASC_SCSI_BIT_ID_TYPE scsi_busy;
  6953. ASC_SCSI_BIT_ID_TYPE target_id;
  6954. PortAddr iop_base;
  6955. ushort q_addr;
  6956. ushort sg_q_addr;
  6957. uchar cur_target_qng;
  6958. ASC_QDONE_INFO scsiq_buf;
  6959. ASC_QDONE_INFO *scsiq;
  6960. int false_overrun;
  6961. iop_base = asc_dvc->iop_base;
  6962. n_q_used = 1;
  6963. scsiq = (ASC_QDONE_INFO *)&scsiq_buf;
  6964. done_q_tail = (uchar)AscGetVarDoneQTail(iop_base);
  6965. q_addr = ASC_QNO_TO_QADDR(done_q_tail);
  6966. next_qp = AscReadLramByte(iop_base,
  6967. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_FWD));
  6968. if (next_qp != ASC_QLINK_END) {
  6969. AscPutVarDoneQTail(iop_base, next_qp);
  6970. q_addr = ASC_QNO_TO_QADDR(next_qp);
  6971. sg_queue_cnt = _AscCopyLramScsiDoneQ(iop_base, q_addr, scsiq,
  6972. asc_dvc->max_dma_count);
  6973. AscWriteLramByte(iop_base,
  6974. (ushort)(q_addr +
  6975. (ushort)ASC_SCSIQ_B_STATUS),
  6976. (uchar)(scsiq->
  6977. q_status & (uchar)~(QS_READY |
  6978. QS_ABORTED)));
  6979. tid_no = ASC_TIX_TO_TID(scsiq->d2.target_ix);
  6980. target_id = ASC_TIX_TO_TARGET_ID(scsiq->d2.target_ix);
  6981. if ((scsiq->cntl & QC_SG_HEAD) != 0) {
  6982. sg_q_addr = q_addr;
  6983. sg_list_qp = next_qp;
  6984. for (q_cnt = 0; q_cnt < sg_queue_cnt; q_cnt++) {
  6985. sg_list_qp = AscReadLramByte(iop_base,
  6986. (ushort)(sg_q_addr
  6987. + (ushort)
  6988. ASC_SCSIQ_B_FWD));
  6989. sg_q_addr = ASC_QNO_TO_QADDR(sg_list_qp);
  6990. if (sg_list_qp == ASC_QLINK_END) {
  6991. AscSetLibErrorCode(asc_dvc,
  6992. ASCQ_ERR_SG_Q_LINKS);
  6993. scsiq->d3.done_stat = QD_WITH_ERROR;
  6994. scsiq->d3.host_stat =
  6995. QHSTA_D_QDONE_SG_LIST_CORRUPTED;
  6996. goto FATAL_ERR_QDONE;
  6997. }
  6998. AscWriteLramByte(iop_base,
  6999. (ushort)(sg_q_addr + (ushort)
  7000. ASC_SCSIQ_B_STATUS),
  7001. QS_FREE);
  7002. }
  7003. n_q_used = sg_queue_cnt + 1;
  7004. AscPutVarDoneQTail(iop_base, sg_list_qp);
  7005. }
  7006. if (asc_dvc->queue_full_or_busy & target_id) {
  7007. cur_target_qng = AscReadLramByte(iop_base,
  7008. (ushort)((ushort)
  7009. ASC_QADR_BEG
  7010. + (ushort)
  7011. scsiq->d2.
  7012. target_ix));
  7013. if (cur_target_qng < asc_dvc->max_dvc_qng[tid_no]) {
  7014. scsi_busy = AscReadLramByte(iop_base, (ushort)
  7015. ASCV_SCSIBUSY_B);
  7016. scsi_busy &= ~target_id;
  7017. AscWriteLramByte(iop_base,
  7018. (ushort)ASCV_SCSIBUSY_B,
  7019. scsi_busy);
  7020. asc_dvc->queue_full_or_busy &= ~target_id;
  7021. }
  7022. }
  7023. if (asc_dvc->cur_total_qng >= n_q_used) {
  7024. asc_dvc->cur_total_qng -= n_q_used;
  7025. if (asc_dvc->cur_dvc_qng[tid_no] != 0) {
  7026. asc_dvc->cur_dvc_qng[tid_no]--;
  7027. }
  7028. } else {
  7029. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CUR_QNG);
  7030. scsiq->d3.done_stat = QD_WITH_ERROR;
  7031. goto FATAL_ERR_QDONE;
  7032. }
  7033. if ((scsiq->d2.srb_ptr == 0UL) ||
  7034. ((scsiq->q_status & QS_ABORTED) != 0)) {
  7035. return (0x11);
  7036. } else if (scsiq->q_status == QS_DONE) {
  7037. false_overrun = FALSE;
  7038. if (scsiq->extra_bytes != 0) {
  7039. scsiq->remain_bytes +=
  7040. (ADV_DCNT)scsiq->extra_bytes;
  7041. }
  7042. if (scsiq->d3.done_stat == QD_WITH_ERROR) {
  7043. if (scsiq->d3.host_stat ==
  7044. QHSTA_M_DATA_OVER_RUN) {
  7045. if ((scsiq->
  7046. cntl & (QC_DATA_IN | QC_DATA_OUT))
  7047. == 0) {
  7048. scsiq->d3.done_stat =
  7049. QD_NO_ERROR;
  7050. scsiq->d3.host_stat =
  7051. QHSTA_NO_ERROR;
  7052. } else if (false_overrun) {
  7053. scsiq->d3.done_stat =
  7054. QD_NO_ERROR;
  7055. scsiq->d3.host_stat =
  7056. QHSTA_NO_ERROR;
  7057. }
  7058. } else if (scsiq->d3.host_stat ==
  7059. QHSTA_M_HUNG_REQ_SCSI_BUS_RESET) {
  7060. AscStopChip(iop_base);
  7061. AscSetChipControl(iop_base,
  7062. (uchar)(CC_SCSI_RESET
  7063. | CC_HALT));
  7064. udelay(60);
  7065. AscSetChipControl(iop_base, CC_HALT);
  7066. AscSetChipStatus(iop_base,
  7067. CIW_CLR_SCSI_RESET_INT);
  7068. AscSetChipStatus(iop_base, 0);
  7069. AscSetChipControl(iop_base, 0);
  7070. }
  7071. }
  7072. if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
  7073. asc_isr_callback(asc_dvc, scsiq);
  7074. } else {
  7075. if ((AscReadLramByte(iop_base,
  7076. (ushort)(q_addr + (ushort)
  7077. ASC_SCSIQ_CDB_BEG))
  7078. == START_STOP)) {
  7079. asc_dvc->unit_not_ready &= ~target_id;
  7080. if (scsiq->d3.done_stat != QD_NO_ERROR) {
  7081. asc_dvc->start_motor &=
  7082. ~target_id;
  7083. }
  7084. }
  7085. }
  7086. return (1);
  7087. } else {
  7088. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_Q_STATUS);
  7089. FATAL_ERR_QDONE:
  7090. if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
  7091. asc_isr_callback(asc_dvc, scsiq);
  7092. }
  7093. return (0x80);
  7094. }
  7095. }
  7096. return (0);
  7097. }
  7098. static int AscISR(ASC_DVC_VAR *asc_dvc)
  7099. {
  7100. ASC_CS_TYPE chipstat;
  7101. PortAddr iop_base;
  7102. ushort saved_ram_addr;
  7103. uchar ctrl_reg;
  7104. uchar saved_ctrl_reg;
  7105. int int_pending;
  7106. int status;
  7107. uchar host_flag;
  7108. iop_base = asc_dvc->iop_base;
  7109. int_pending = FALSE;
  7110. if (AscIsIntPending(iop_base) == 0)
  7111. return int_pending;
  7112. if ((asc_dvc->init_state & ASC_INIT_STATE_END_LOAD_MC) == 0) {
  7113. return ERR;
  7114. }
  7115. if (asc_dvc->in_critical_cnt != 0) {
  7116. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_ON_CRITICAL);
  7117. return ERR;
  7118. }
  7119. if (asc_dvc->is_in_int) {
  7120. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_RE_ENTRY);
  7121. return ERR;
  7122. }
  7123. asc_dvc->is_in_int = TRUE;
  7124. ctrl_reg = AscGetChipControl(iop_base);
  7125. saved_ctrl_reg = ctrl_reg & (~(CC_SCSI_RESET | CC_CHIP_RESET |
  7126. CC_SINGLE_STEP | CC_DIAG | CC_TEST));
  7127. chipstat = AscGetChipStatus(iop_base);
  7128. if (chipstat & CSW_SCSI_RESET_LATCH) {
  7129. if (!(asc_dvc->bus_type & (ASC_IS_VL | ASC_IS_EISA))) {
  7130. int i = 10;
  7131. int_pending = TRUE;
  7132. asc_dvc->sdtr_done = 0;
  7133. saved_ctrl_reg &= (uchar)(~CC_HALT);
  7134. while ((AscGetChipStatus(iop_base) &
  7135. CSW_SCSI_RESET_ACTIVE) && (i-- > 0)) {
  7136. mdelay(100);
  7137. }
  7138. AscSetChipControl(iop_base, (CC_CHIP_RESET | CC_HALT));
  7139. AscSetChipControl(iop_base, CC_HALT);
  7140. AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
  7141. AscSetChipStatus(iop_base, 0);
  7142. chipstat = AscGetChipStatus(iop_base);
  7143. }
  7144. }
  7145. saved_ram_addr = AscGetChipLramAddr(iop_base);
  7146. host_flag = AscReadLramByte(iop_base,
  7147. ASCV_HOST_FLAG_B) &
  7148. (uchar)(~ASC_HOST_FLAG_IN_ISR);
  7149. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
  7150. (uchar)(host_flag | (uchar)ASC_HOST_FLAG_IN_ISR));
  7151. if ((chipstat & CSW_INT_PENDING) || (int_pending)) {
  7152. AscAckInterrupt(iop_base);
  7153. int_pending = TRUE;
  7154. if ((chipstat & CSW_HALTED) && (ctrl_reg & CC_SINGLE_STEP)) {
  7155. if (AscIsrChipHalted(asc_dvc) == ERR) {
  7156. goto ISR_REPORT_QDONE_FATAL_ERROR;
  7157. } else {
  7158. saved_ctrl_reg &= (uchar)(~CC_HALT);
  7159. }
  7160. } else {
  7161. ISR_REPORT_QDONE_FATAL_ERROR:
  7162. if ((asc_dvc->dvc_cntl & ASC_CNTL_INT_MULTI_Q) != 0) {
  7163. while (((status =
  7164. AscIsrQDone(asc_dvc)) & 0x01) != 0) {
  7165. }
  7166. } else {
  7167. do {
  7168. if ((status =
  7169. AscIsrQDone(asc_dvc)) == 1) {
  7170. break;
  7171. }
  7172. } while (status == 0x11);
  7173. }
  7174. if ((status & 0x80) != 0)
  7175. int_pending = ERR;
  7176. }
  7177. }
  7178. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
  7179. AscSetChipLramAddr(iop_base, saved_ram_addr);
  7180. AscSetChipControl(iop_base, saved_ctrl_reg);
  7181. asc_dvc->is_in_int = FALSE;
  7182. return int_pending;
  7183. }
  7184. /*
  7185. * advansys_reset()
  7186. *
  7187. * Reset the bus associated with the command 'scp'.
  7188. *
  7189. * This function runs its own thread. Interrupts must be blocked but
  7190. * sleeping is allowed and no locking other than for host structures is
  7191. * required. Returns SUCCESS or FAILED.
  7192. */
  7193. static int advansys_reset(struct scsi_cmnd *scp)
  7194. {
  7195. struct Scsi_Host *shost = scp->device->host;
  7196. struct asc_board *boardp = shost_priv(shost);
  7197. unsigned long flags;
  7198. int status;
  7199. int ret = SUCCESS;
  7200. ASC_DBG(1, "0x%p\n", scp);
  7201. ASC_STATS(shost, reset);
  7202. scmd_printk(KERN_INFO, scp, "SCSI bus reset started...\n");
  7203. if (ASC_NARROW_BOARD(boardp)) {
  7204. ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  7205. /* Reset the chip and SCSI bus. */
  7206. ASC_DBG(1, "before AscInitAsc1000Driver()\n");
  7207. status = AscInitAsc1000Driver(asc_dvc);
  7208. /* Refer to ASC_IERR_* definitions for meaning of 'err_code'. */
  7209. if (asc_dvc->err_code || !asc_dvc->overrun_dma) {
  7210. scmd_printk(KERN_INFO, scp, "SCSI bus reset error: "
  7211. "0x%x, status: 0x%x\n", asc_dvc->err_code,
  7212. status);
  7213. ret = FAILED;
  7214. } else if (status) {
  7215. scmd_printk(KERN_INFO, scp, "SCSI bus reset warning: "
  7216. "0x%x\n", status);
  7217. } else {
  7218. scmd_printk(KERN_INFO, scp, "SCSI bus reset "
  7219. "successful\n");
  7220. }
  7221. ASC_DBG(1, "after AscInitAsc1000Driver()\n");
  7222. spin_lock_irqsave(shost->host_lock, flags);
  7223. } else {
  7224. /*
  7225. * If the suggest reset bus flags are set, then reset the bus.
  7226. * Otherwise only reset the device.
  7227. */
  7228. ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
  7229. /*
  7230. * Reset the target's SCSI bus.
  7231. */
  7232. ASC_DBG(1, "before AdvResetChipAndSB()\n");
  7233. switch (AdvResetChipAndSB(adv_dvc)) {
  7234. case ASC_TRUE:
  7235. scmd_printk(KERN_INFO, scp, "SCSI bus reset "
  7236. "successful\n");
  7237. break;
  7238. case ASC_FALSE:
  7239. default:
  7240. scmd_printk(KERN_INFO, scp, "SCSI bus reset error\n");
  7241. ret = FAILED;
  7242. break;
  7243. }
  7244. spin_lock_irqsave(shost->host_lock, flags);
  7245. AdvISR(adv_dvc);
  7246. }
  7247. /* Save the time of the most recently completed reset. */
  7248. boardp->last_reset = jiffies;
  7249. spin_unlock_irqrestore(shost->host_lock, flags);
  7250. ASC_DBG(1, "ret %d\n", ret);
  7251. return ret;
  7252. }
  7253. /*
  7254. * advansys_biosparam()
  7255. *
  7256. * Translate disk drive geometry if the "BIOS greater than 1 GB"
  7257. * support is enabled for a drive.
  7258. *
  7259. * ip (information pointer) is an int array with the following definition:
  7260. * ip[0]: heads
  7261. * ip[1]: sectors
  7262. * ip[2]: cylinders
  7263. */
  7264. static int
  7265. advansys_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  7266. sector_t capacity, int ip[])
  7267. {
  7268. struct asc_board *boardp = shost_priv(sdev->host);
  7269. ASC_DBG(1, "begin\n");
  7270. ASC_STATS(sdev->host, biosparam);
  7271. if (ASC_NARROW_BOARD(boardp)) {
  7272. if ((boardp->dvc_var.asc_dvc_var.dvc_cntl &
  7273. ASC_CNTL_BIOS_GT_1GB) && capacity > 0x200000) {
  7274. ip[0] = 255;
  7275. ip[1] = 63;
  7276. } else {
  7277. ip[0] = 64;
  7278. ip[1] = 32;
  7279. }
  7280. } else {
  7281. if ((boardp->dvc_var.adv_dvc_var.bios_ctrl &
  7282. BIOS_CTRL_EXTENDED_XLAT) && capacity > 0x200000) {
  7283. ip[0] = 255;
  7284. ip[1] = 63;
  7285. } else {
  7286. ip[0] = 64;
  7287. ip[1] = 32;
  7288. }
  7289. }
  7290. ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
  7291. ASC_DBG(1, "end\n");
  7292. return 0;
  7293. }
  7294. /*
  7295. * First-level interrupt handler.
  7296. *
  7297. * 'dev_id' is a pointer to the interrupting adapter's Scsi_Host.
  7298. */
  7299. static irqreturn_t advansys_interrupt(int irq, void *dev_id)
  7300. {
  7301. struct Scsi_Host *shost = dev_id;
  7302. struct asc_board *boardp = shost_priv(shost);
  7303. irqreturn_t result = IRQ_NONE;
  7304. ASC_DBG(2, "boardp 0x%p\n", boardp);
  7305. spin_lock(shost->host_lock);
  7306. if (ASC_NARROW_BOARD(boardp)) {
  7307. if (AscIsIntPending(shost->io_port)) {
  7308. result = IRQ_HANDLED;
  7309. ASC_STATS(shost, interrupt);
  7310. ASC_DBG(1, "before AscISR()\n");
  7311. AscISR(&boardp->dvc_var.asc_dvc_var);
  7312. }
  7313. } else {
  7314. ASC_DBG(1, "before AdvISR()\n");
  7315. if (AdvISR(&boardp->dvc_var.adv_dvc_var)) {
  7316. result = IRQ_HANDLED;
  7317. ASC_STATS(shost, interrupt);
  7318. }
  7319. }
  7320. spin_unlock(shost->host_lock);
  7321. ASC_DBG(1, "end\n");
  7322. return result;
  7323. }
  7324. static int AscHostReqRiscHalt(PortAddr iop_base)
  7325. {
  7326. int count = 0;
  7327. int sta = 0;
  7328. uchar saved_stop_code;
  7329. if (AscIsChipHalted(iop_base))
  7330. return (1);
  7331. saved_stop_code = AscReadLramByte(iop_base, ASCV_STOP_CODE_B);
  7332. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
  7333. ASC_STOP_HOST_REQ_RISC_HALT | ASC_STOP_REQ_RISC_STOP);
  7334. do {
  7335. if (AscIsChipHalted(iop_base)) {
  7336. sta = 1;
  7337. break;
  7338. }
  7339. mdelay(100);
  7340. } while (count++ < 20);
  7341. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, saved_stop_code);
  7342. return (sta);
  7343. }
  7344. static int
  7345. AscSetRunChipSynRegAtID(PortAddr iop_base, uchar tid_no, uchar sdtr_data)
  7346. {
  7347. int sta = FALSE;
  7348. if (AscHostReqRiscHalt(iop_base)) {
  7349. sta = AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
  7350. AscStartChip(iop_base);
  7351. }
  7352. return sta;
  7353. }
  7354. static void AscAsyncFix(ASC_DVC_VAR *asc_dvc, struct scsi_device *sdev)
  7355. {
  7356. char type = sdev->type;
  7357. ASC_SCSI_BIT_ID_TYPE tid_bits = 1 << sdev->id;
  7358. if (!(asc_dvc->bug_fix_cntl & ASC_BUG_FIX_ASYN_USE_SYN))
  7359. return;
  7360. if (asc_dvc->init_sdtr & tid_bits)
  7361. return;
  7362. if ((type == TYPE_ROM) && (strncmp(sdev->vendor, "HP ", 3) == 0))
  7363. asc_dvc->pci_fix_asyn_xfer_always |= tid_bits;
  7364. asc_dvc->pci_fix_asyn_xfer |= tid_bits;
  7365. if ((type == TYPE_PROCESSOR) || (type == TYPE_SCANNER) ||
  7366. (type == TYPE_ROM) || (type == TYPE_TAPE))
  7367. asc_dvc->pci_fix_asyn_xfer &= ~tid_bits;
  7368. if (asc_dvc->pci_fix_asyn_xfer & tid_bits)
  7369. AscSetRunChipSynRegAtID(asc_dvc->iop_base, sdev->id,
  7370. ASYN_SDTR_DATA_FIX_PCI_REV_AB);
  7371. }
  7372. static void
  7373. advansys_narrow_slave_configure(struct scsi_device *sdev, ASC_DVC_VAR *asc_dvc)
  7374. {
  7375. ASC_SCSI_BIT_ID_TYPE tid_bit = 1 << sdev->id;
  7376. ASC_SCSI_BIT_ID_TYPE orig_use_tagged_qng = asc_dvc->use_tagged_qng;
  7377. if (sdev->lun == 0) {
  7378. ASC_SCSI_BIT_ID_TYPE orig_init_sdtr = asc_dvc->init_sdtr;
  7379. if ((asc_dvc->cfg->sdtr_enable & tid_bit) && sdev->sdtr) {
  7380. asc_dvc->init_sdtr |= tid_bit;
  7381. } else {
  7382. asc_dvc->init_sdtr &= ~tid_bit;
  7383. }
  7384. if (orig_init_sdtr != asc_dvc->init_sdtr)
  7385. AscAsyncFix(asc_dvc, sdev);
  7386. }
  7387. if (sdev->tagged_supported) {
  7388. if (asc_dvc->cfg->cmd_qng_enabled & tid_bit) {
  7389. if (sdev->lun == 0) {
  7390. asc_dvc->cfg->can_tagged_qng |= tid_bit;
  7391. asc_dvc->use_tagged_qng |= tid_bit;
  7392. }
  7393. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
  7394. asc_dvc->max_dvc_qng[sdev->id]);
  7395. }
  7396. } else {
  7397. if (sdev->lun == 0) {
  7398. asc_dvc->cfg->can_tagged_qng &= ~tid_bit;
  7399. asc_dvc->use_tagged_qng &= ~tid_bit;
  7400. }
  7401. scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
  7402. }
  7403. if ((sdev->lun == 0) &&
  7404. (orig_use_tagged_qng != asc_dvc->use_tagged_qng)) {
  7405. AscWriteLramByte(asc_dvc->iop_base, ASCV_DISC_ENABLE_B,
  7406. asc_dvc->cfg->disc_enable);
  7407. AscWriteLramByte(asc_dvc->iop_base, ASCV_USE_TAGGED_QNG_B,
  7408. asc_dvc->use_tagged_qng);
  7409. AscWriteLramByte(asc_dvc->iop_base, ASCV_CAN_TAGGED_QNG_B,
  7410. asc_dvc->cfg->can_tagged_qng);
  7411. asc_dvc->max_dvc_qng[sdev->id] =
  7412. asc_dvc->cfg->max_tag_qng[sdev->id];
  7413. AscWriteLramByte(asc_dvc->iop_base,
  7414. (ushort)(ASCV_MAX_DVC_QNG_BEG + sdev->id),
  7415. asc_dvc->max_dvc_qng[sdev->id]);
  7416. }
  7417. }
  7418. /*
  7419. * Wide Transfers
  7420. *
  7421. * If the EEPROM enabled WDTR for the device and the device supports wide
  7422. * bus (16 bit) transfers, then turn on the device's 'wdtr_able' bit and
  7423. * write the new value to the microcode.
  7424. */
  7425. static void
  7426. advansys_wide_enable_wdtr(AdvPortAddr iop_base, unsigned short tidmask)
  7427. {
  7428. unsigned short cfg_word;
  7429. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
  7430. if ((cfg_word & tidmask) != 0)
  7431. return;
  7432. cfg_word |= tidmask;
  7433. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
  7434. /*
  7435. * Clear the microcode SDTR and WDTR negotiation done indicators for
  7436. * the target to cause it to negotiate with the new setting set above.
  7437. * WDTR when accepted causes the target to enter asynchronous mode, so
  7438. * SDTR must be negotiated.
  7439. */
  7440. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  7441. cfg_word &= ~tidmask;
  7442. AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  7443. AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
  7444. cfg_word &= ~tidmask;
  7445. AdvWriteWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
  7446. }
  7447. /*
  7448. * Synchronous Transfers
  7449. *
  7450. * If the EEPROM enabled SDTR for the device and the device
  7451. * supports synchronous transfers, then turn on the device's
  7452. * 'sdtr_able' bit. Write the new value to the microcode.
  7453. */
  7454. static void
  7455. advansys_wide_enable_sdtr(AdvPortAddr iop_base, unsigned short tidmask)
  7456. {
  7457. unsigned short cfg_word;
  7458. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
  7459. if ((cfg_word & tidmask) != 0)
  7460. return;
  7461. cfg_word |= tidmask;
  7462. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
  7463. /*
  7464. * Clear the microcode "SDTR negotiation" done indicator for the
  7465. * target to cause it to negotiate with the new setting set above.
  7466. */
  7467. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  7468. cfg_word &= ~tidmask;
  7469. AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  7470. }
  7471. /*
  7472. * PPR (Parallel Protocol Request) Capable
  7473. *
  7474. * If the device supports DT mode, then it must be PPR capable.
  7475. * The PPR message will be used in place of the SDTR and WDTR
  7476. * messages to negotiate synchronous speed and offset, transfer
  7477. * width, and protocol options.
  7478. */
  7479. static void advansys_wide_enable_ppr(ADV_DVC_VAR *adv_dvc,
  7480. AdvPortAddr iop_base, unsigned short tidmask)
  7481. {
  7482. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
  7483. adv_dvc->ppr_able |= tidmask;
  7484. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
  7485. }
  7486. static void
  7487. advansys_wide_slave_configure(struct scsi_device *sdev, ADV_DVC_VAR *adv_dvc)
  7488. {
  7489. AdvPortAddr iop_base = adv_dvc->iop_base;
  7490. unsigned short tidmask = 1 << sdev->id;
  7491. if (sdev->lun == 0) {
  7492. /*
  7493. * Handle WDTR, SDTR, and Tag Queuing. If the feature
  7494. * is enabled in the EEPROM and the device supports the
  7495. * feature, then enable it in the microcode.
  7496. */
  7497. if ((adv_dvc->wdtr_able & tidmask) && sdev->wdtr)
  7498. advansys_wide_enable_wdtr(iop_base, tidmask);
  7499. if ((adv_dvc->sdtr_able & tidmask) && sdev->sdtr)
  7500. advansys_wide_enable_sdtr(iop_base, tidmask);
  7501. if (adv_dvc->chip_type == ADV_CHIP_ASC38C1600 && sdev->ppr)
  7502. advansys_wide_enable_ppr(adv_dvc, iop_base, tidmask);
  7503. /*
  7504. * Tag Queuing is disabled for the BIOS which runs in polled
  7505. * mode and would see no benefit from Tag Queuing. Also by
  7506. * disabling Tag Queuing in the BIOS devices with Tag Queuing
  7507. * bugs will at least work with the BIOS.
  7508. */
  7509. if ((adv_dvc->tagqng_able & tidmask) &&
  7510. sdev->tagged_supported) {
  7511. unsigned short cfg_word;
  7512. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word);
  7513. cfg_word |= tidmask;
  7514. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  7515. cfg_word);
  7516. AdvWriteByteLram(iop_base,
  7517. ASC_MC_NUMBER_OF_MAX_CMD + sdev->id,
  7518. adv_dvc->max_dvc_qng);
  7519. }
  7520. }
  7521. if ((adv_dvc->tagqng_able & tidmask) && sdev->tagged_supported) {
  7522. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
  7523. adv_dvc->max_dvc_qng);
  7524. } else {
  7525. scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
  7526. }
  7527. }
  7528. /*
  7529. * Set the number of commands to queue per device for the
  7530. * specified host adapter.
  7531. */
  7532. static int advansys_slave_configure(struct scsi_device *sdev)
  7533. {
  7534. struct asc_board *boardp = shost_priv(sdev->host);
  7535. if (ASC_NARROW_BOARD(boardp))
  7536. advansys_narrow_slave_configure(sdev,
  7537. &boardp->dvc_var.asc_dvc_var);
  7538. else
  7539. advansys_wide_slave_configure(sdev,
  7540. &boardp->dvc_var.adv_dvc_var);
  7541. return 0;
  7542. }
  7543. static __le32 advansys_get_sense_buffer_dma(struct scsi_cmnd *scp)
  7544. {
  7545. struct asc_board *board = shost_priv(scp->device->host);
  7546. scp->SCp.dma_handle = dma_map_single(board->dev, scp->sense_buffer,
  7547. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  7548. dma_cache_sync(board->dev, scp->sense_buffer,
  7549. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  7550. return cpu_to_le32(scp->SCp.dma_handle);
  7551. }
  7552. static int asc_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
  7553. struct asc_scsi_q *asc_scsi_q)
  7554. {
  7555. struct asc_dvc_var *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  7556. int use_sg;
  7557. memset(asc_scsi_q, 0, sizeof(*asc_scsi_q));
  7558. /*
  7559. * Point the ASC_SCSI_Q to the 'struct scsi_cmnd'.
  7560. */
  7561. asc_scsi_q->q2.srb_ptr = advansys_ptr_to_srb(asc_dvc, scp);
  7562. if (asc_scsi_q->q2.srb_ptr == BAD_SRB) {
  7563. scp->result = HOST_BYTE(DID_SOFT_ERROR);
  7564. return ASC_ERROR;
  7565. }
  7566. /*
  7567. * Build the ASC_SCSI_Q request.
  7568. */
  7569. asc_scsi_q->cdbptr = &scp->cmnd[0];
  7570. asc_scsi_q->q2.cdb_len = scp->cmd_len;
  7571. asc_scsi_q->q1.target_id = ASC_TID_TO_TARGET_ID(scp->device->id);
  7572. asc_scsi_q->q1.target_lun = scp->device->lun;
  7573. asc_scsi_q->q2.target_ix =
  7574. ASC_TIDLUN_TO_IX(scp->device->id, scp->device->lun);
  7575. asc_scsi_q->q1.sense_addr = advansys_get_sense_buffer_dma(scp);
  7576. asc_scsi_q->q1.sense_len = SCSI_SENSE_BUFFERSIZE;
  7577. /*
  7578. * If there are any outstanding requests for the current target,
  7579. * then every 255th request send an ORDERED request. This heuristic
  7580. * tries to retain the benefit of request sorting while preventing
  7581. * request starvation. 255 is the max number of tags or pending commands
  7582. * a device may have outstanding.
  7583. *
  7584. * The request count is incremented below for every successfully
  7585. * started request.
  7586. *
  7587. */
  7588. if ((asc_dvc->cur_dvc_qng[scp->device->id] > 0) &&
  7589. (boardp->reqcnt[scp->device->id] % 255) == 0) {
  7590. asc_scsi_q->q2.tag_code = MSG_ORDERED_TAG;
  7591. } else {
  7592. asc_scsi_q->q2.tag_code = MSG_SIMPLE_TAG;
  7593. }
  7594. /* Build ASC_SCSI_Q */
  7595. use_sg = scsi_dma_map(scp);
  7596. if (use_sg != 0) {
  7597. int sgcnt;
  7598. struct scatterlist *slp;
  7599. struct asc_sg_head *asc_sg_head;
  7600. if (use_sg > scp->device->host->sg_tablesize) {
  7601. scmd_printk(KERN_ERR, scp, "use_sg %d > "
  7602. "sg_tablesize %d\n", use_sg,
  7603. scp->device->host->sg_tablesize);
  7604. scsi_dma_unmap(scp);
  7605. scp->result = HOST_BYTE(DID_ERROR);
  7606. return ASC_ERROR;
  7607. }
  7608. asc_sg_head = kzalloc(sizeof(asc_scsi_q->sg_head) +
  7609. use_sg * sizeof(struct asc_sg_list), GFP_ATOMIC);
  7610. if (!asc_sg_head) {
  7611. scsi_dma_unmap(scp);
  7612. scp->result = HOST_BYTE(DID_SOFT_ERROR);
  7613. return ASC_ERROR;
  7614. }
  7615. asc_scsi_q->q1.cntl |= QC_SG_HEAD;
  7616. asc_scsi_q->sg_head = asc_sg_head;
  7617. asc_scsi_q->q1.data_cnt = 0;
  7618. asc_scsi_q->q1.data_addr = 0;
  7619. /* This is a byte value, otherwise it would need to be swapped. */
  7620. asc_sg_head->entry_cnt = asc_scsi_q->q1.sg_queue_cnt = use_sg;
  7621. ASC_STATS_ADD(scp->device->host, xfer_elem,
  7622. asc_sg_head->entry_cnt);
  7623. /*
  7624. * Convert scatter-gather list into ASC_SG_HEAD list.
  7625. */
  7626. scsi_for_each_sg(scp, slp, use_sg, sgcnt) {
  7627. asc_sg_head->sg_list[sgcnt].addr =
  7628. cpu_to_le32(sg_dma_address(slp));
  7629. asc_sg_head->sg_list[sgcnt].bytes =
  7630. cpu_to_le32(sg_dma_len(slp));
  7631. ASC_STATS_ADD(scp->device->host, xfer_sect,
  7632. DIV_ROUND_UP(sg_dma_len(slp), 512));
  7633. }
  7634. }
  7635. ASC_STATS(scp->device->host, xfer_cnt);
  7636. ASC_DBG_PRT_ASC_SCSI_Q(2, asc_scsi_q);
  7637. ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
  7638. return ASC_NOERROR;
  7639. }
  7640. /*
  7641. * Build scatter-gather list for Adv Library (Wide Board).
  7642. *
  7643. * Additional ADV_SG_BLOCK structures will need to be allocated
  7644. * if the total number of scatter-gather elements exceeds
  7645. * NO_OF_SG_PER_BLOCK (15). The ADV_SG_BLOCK structures are
  7646. * assumed to be physically contiguous.
  7647. *
  7648. * Return:
  7649. * ADV_SUCCESS(1) - SG List successfully created
  7650. * ADV_ERROR(-1) - SG List creation failed
  7651. */
  7652. static int
  7653. adv_get_sglist(struct asc_board *boardp, adv_req_t *reqp, struct scsi_cmnd *scp,
  7654. int use_sg)
  7655. {
  7656. adv_sgblk_t *sgblkp;
  7657. ADV_SCSI_REQ_Q *scsiqp;
  7658. struct scatterlist *slp;
  7659. int sg_elem_cnt;
  7660. ADV_SG_BLOCK *sg_block, *prev_sg_block;
  7661. ADV_PADDR sg_block_paddr;
  7662. int i;
  7663. scsiqp = (ADV_SCSI_REQ_Q *)ADV_32BALIGN(&reqp->scsi_req_q);
  7664. slp = scsi_sglist(scp);
  7665. sg_elem_cnt = use_sg;
  7666. prev_sg_block = NULL;
  7667. reqp->sgblkp = NULL;
  7668. for (;;) {
  7669. /*
  7670. * Allocate a 'adv_sgblk_t' structure from the board free
  7671. * list. One 'adv_sgblk_t' structure holds NO_OF_SG_PER_BLOCK
  7672. * (15) scatter-gather elements.
  7673. */
  7674. if ((sgblkp = boardp->adv_sgblkp) == NULL) {
  7675. ASC_DBG(1, "no free adv_sgblk_t\n");
  7676. ASC_STATS(scp->device->host, adv_build_nosg);
  7677. /*
  7678. * Allocation failed. Free 'adv_sgblk_t' structures
  7679. * already allocated for the request.
  7680. */
  7681. while ((sgblkp = reqp->sgblkp) != NULL) {
  7682. /* Remove 'sgblkp' from the request list. */
  7683. reqp->sgblkp = sgblkp->next_sgblkp;
  7684. /* Add 'sgblkp' to the board free list. */
  7685. sgblkp->next_sgblkp = boardp->adv_sgblkp;
  7686. boardp->adv_sgblkp = sgblkp;
  7687. }
  7688. return ASC_BUSY;
  7689. }
  7690. /* Complete 'adv_sgblk_t' board allocation. */
  7691. boardp->adv_sgblkp = sgblkp->next_sgblkp;
  7692. sgblkp->next_sgblkp = NULL;
  7693. /*
  7694. * Get 8 byte aligned virtual and physical addresses
  7695. * for the allocated ADV_SG_BLOCK structure.
  7696. */
  7697. sg_block = (ADV_SG_BLOCK *)ADV_8BALIGN(&sgblkp->sg_block);
  7698. sg_block_paddr = virt_to_bus(sg_block);
  7699. /*
  7700. * Check if this is the first 'adv_sgblk_t' for the
  7701. * request.
  7702. */
  7703. if (reqp->sgblkp == NULL) {
  7704. /* Request's first scatter-gather block. */
  7705. reqp->sgblkp = sgblkp;
  7706. /*
  7707. * Set ADV_SCSI_REQ_T ADV_SG_BLOCK virtual and physical
  7708. * address pointers.
  7709. */
  7710. scsiqp->sg_list_ptr = sg_block;
  7711. scsiqp->sg_real_addr = cpu_to_le32(sg_block_paddr);
  7712. } else {
  7713. /* Request's second or later scatter-gather block. */
  7714. sgblkp->next_sgblkp = reqp->sgblkp;
  7715. reqp->sgblkp = sgblkp;
  7716. /*
  7717. * Point the previous ADV_SG_BLOCK structure to
  7718. * the newly allocated ADV_SG_BLOCK structure.
  7719. */
  7720. prev_sg_block->sg_ptr = cpu_to_le32(sg_block_paddr);
  7721. }
  7722. for (i = 0; i < NO_OF_SG_PER_BLOCK; i++) {
  7723. sg_block->sg_list[i].sg_addr =
  7724. cpu_to_le32(sg_dma_address(slp));
  7725. sg_block->sg_list[i].sg_count =
  7726. cpu_to_le32(sg_dma_len(slp));
  7727. ASC_STATS_ADD(scp->device->host, xfer_sect,
  7728. DIV_ROUND_UP(sg_dma_len(slp), 512));
  7729. if (--sg_elem_cnt == 0) { /* Last ADV_SG_BLOCK and scatter-gather entry. */
  7730. sg_block->sg_cnt = i + 1;
  7731. sg_block->sg_ptr = 0L; /* Last ADV_SG_BLOCK in list. */
  7732. return ADV_SUCCESS;
  7733. }
  7734. slp++;
  7735. }
  7736. sg_block->sg_cnt = NO_OF_SG_PER_BLOCK;
  7737. prev_sg_block = sg_block;
  7738. }
  7739. }
  7740. /*
  7741. * Build a request structure for the Adv Library (Wide Board).
  7742. *
  7743. * If an adv_req_t can not be allocated to issue the request,
  7744. * then return ASC_BUSY. If an error occurs, then return ASC_ERROR.
  7745. *
  7746. * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the
  7747. * microcode for DMA addresses or math operations are byte swapped
  7748. * to little-endian order.
  7749. */
  7750. static int
  7751. adv_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
  7752. ADV_SCSI_REQ_Q **adv_scsiqpp)
  7753. {
  7754. adv_req_t *reqp;
  7755. ADV_SCSI_REQ_Q *scsiqp;
  7756. int i;
  7757. int ret;
  7758. int use_sg;
  7759. /*
  7760. * Allocate an adv_req_t structure from the board to execute
  7761. * the command.
  7762. */
  7763. if (boardp->adv_reqp == NULL) {
  7764. ASC_DBG(1, "no free adv_req_t\n");
  7765. ASC_STATS(scp->device->host, adv_build_noreq);
  7766. return ASC_BUSY;
  7767. } else {
  7768. reqp = boardp->adv_reqp;
  7769. boardp->adv_reqp = reqp->next_reqp;
  7770. reqp->next_reqp = NULL;
  7771. }
  7772. /*
  7773. * Get 32-byte aligned ADV_SCSI_REQ_Q and ADV_SG_BLOCK pointers.
  7774. */
  7775. scsiqp = (ADV_SCSI_REQ_Q *)ADV_32BALIGN(&reqp->scsi_req_q);
  7776. /*
  7777. * Initialize the structure.
  7778. */
  7779. scsiqp->cntl = scsiqp->scsi_cntl = scsiqp->done_status = 0;
  7780. /*
  7781. * Set the ADV_SCSI_REQ_Q 'srb_ptr' to point to the adv_req_t structure.
  7782. */
  7783. scsiqp->srb_ptr = ADV_VADDR_TO_U32(reqp);
  7784. /*
  7785. * Set the adv_req_t 'cmndp' to point to the struct scsi_cmnd structure.
  7786. */
  7787. reqp->cmndp = scp;
  7788. /*
  7789. * Build the ADV_SCSI_REQ_Q request.
  7790. */
  7791. /* Set CDB length and copy it to the request structure. */
  7792. scsiqp->cdb_len = scp->cmd_len;
  7793. /* Copy first 12 CDB bytes to cdb[]. */
  7794. for (i = 0; i < scp->cmd_len && i < 12; i++) {
  7795. scsiqp->cdb[i] = scp->cmnd[i];
  7796. }
  7797. /* Copy last 4 CDB bytes, if present, to cdb16[]. */
  7798. for (; i < scp->cmd_len; i++) {
  7799. scsiqp->cdb16[i - 12] = scp->cmnd[i];
  7800. }
  7801. scsiqp->target_id = scp->device->id;
  7802. scsiqp->target_lun = scp->device->lun;
  7803. scsiqp->sense_addr = cpu_to_le32(virt_to_bus(&scp->sense_buffer[0]));
  7804. scsiqp->sense_len = SCSI_SENSE_BUFFERSIZE;
  7805. /* Build ADV_SCSI_REQ_Q */
  7806. use_sg = scsi_dma_map(scp);
  7807. if (use_sg == 0) {
  7808. /* Zero-length transfer */
  7809. reqp->sgblkp = NULL;
  7810. scsiqp->data_cnt = 0;
  7811. scsiqp->vdata_addr = NULL;
  7812. scsiqp->data_addr = 0;
  7813. scsiqp->sg_list_ptr = NULL;
  7814. scsiqp->sg_real_addr = 0;
  7815. } else {
  7816. if (use_sg > ADV_MAX_SG_LIST) {
  7817. scmd_printk(KERN_ERR, scp, "use_sg %d > "
  7818. "ADV_MAX_SG_LIST %d\n", use_sg,
  7819. scp->device->host->sg_tablesize);
  7820. scsi_dma_unmap(scp);
  7821. scp->result = HOST_BYTE(DID_ERROR);
  7822. /*
  7823. * Free the 'adv_req_t' structure by adding it back
  7824. * to the board free list.
  7825. */
  7826. reqp->next_reqp = boardp->adv_reqp;
  7827. boardp->adv_reqp = reqp;
  7828. return ASC_ERROR;
  7829. }
  7830. scsiqp->data_cnt = cpu_to_le32(scsi_bufflen(scp));
  7831. ret = adv_get_sglist(boardp, reqp, scp, use_sg);
  7832. if (ret != ADV_SUCCESS) {
  7833. /*
  7834. * Free the adv_req_t structure by adding it back to
  7835. * the board free list.
  7836. */
  7837. reqp->next_reqp = boardp->adv_reqp;
  7838. boardp->adv_reqp = reqp;
  7839. return ret;
  7840. }
  7841. ASC_STATS_ADD(scp->device->host, xfer_elem, use_sg);
  7842. }
  7843. ASC_STATS(scp->device->host, xfer_cnt);
  7844. ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
  7845. ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
  7846. *adv_scsiqpp = scsiqp;
  7847. return ASC_NOERROR;
  7848. }
  7849. static int AscSgListToQueue(int sg_list)
  7850. {
  7851. int n_sg_list_qs;
  7852. n_sg_list_qs = ((sg_list - 1) / ASC_SG_LIST_PER_Q);
  7853. if (((sg_list - 1) % ASC_SG_LIST_PER_Q) != 0)
  7854. n_sg_list_qs++;
  7855. return n_sg_list_qs + 1;
  7856. }
  7857. static uint
  7858. AscGetNumOfFreeQueue(ASC_DVC_VAR *asc_dvc, uchar target_ix, uchar n_qs)
  7859. {
  7860. uint cur_used_qs;
  7861. uint cur_free_qs;
  7862. ASC_SCSI_BIT_ID_TYPE target_id;
  7863. uchar tid_no;
  7864. target_id = ASC_TIX_TO_TARGET_ID(target_ix);
  7865. tid_no = ASC_TIX_TO_TID(target_ix);
  7866. if ((asc_dvc->unit_not_ready & target_id) ||
  7867. (asc_dvc->queue_full_or_busy & target_id)) {
  7868. return 0;
  7869. }
  7870. if (n_qs == 1) {
  7871. cur_used_qs = (uint) asc_dvc->cur_total_qng +
  7872. (uint) asc_dvc->last_q_shortage + (uint) ASC_MIN_FREE_Q;
  7873. } else {
  7874. cur_used_qs = (uint) asc_dvc->cur_total_qng +
  7875. (uint) ASC_MIN_FREE_Q;
  7876. }
  7877. if ((uint) (cur_used_qs + n_qs) <= (uint) asc_dvc->max_total_qng) {
  7878. cur_free_qs = (uint) asc_dvc->max_total_qng - cur_used_qs;
  7879. if (asc_dvc->cur_dvc_qng[tid_no] >=
  7880. asc_dvc->max_dvc_qng[tid_no]) {
  7881. return 0;
  7882. }
  7883. return cur_free_qs;
  7884. }
  7885. if (n_qs > 1) {
  7886. if ((n_qs > asc_dvc->last_q_shortage)
  7887. && (n_qs <= (asc_dvc->max_total_qng - ASC_MIN_FREE_Q))) {
  7888. asc_dvc->last_q_shortage = n_qs;
  7889. }
  7890. }
  7891. return 0;
  7892. }
  7893. static uchar AscAllocFreeQueue(PortAddr iop_base, uchar free_q_head)
  7894. {
  7895. ushort q_addr;
  7896. uchar next_qp;
  7897. uchar q_status;
  7898. q_addr = ASC_QNO_TO_QADDR(free_q_head);
  7899. q_status = (uchar)AscReadLramByte(iop_base,
  7900. (ushort)(q_addr +
  7901. ASC_SCSIQ_B_STATUS));
  7902. next_qp = AscReadLramByte(iop_base, (ushort)(q_addr + ASC_SCSIQ_B_FWD));
  7903. if (((q_status & QS_READY) == 0) && (next_qp != ASC_QLINK_END))
  7904. return next_qp;
  7905. return ASC_QLINK_END;
  7906. }
  7907. static uchar
  7908. AscAllocMultipleFreeQueue(PortAddr iop_base, uchar free_q_head, uchar n_free_q)
  7909. {
  7910. uchar i;
  7911. for (i = 0; i < n_free_q; i++) {
  7912. free_q_head = AscAllocFreeQueue(iop_base, free_q_head);
  7913. if (free_q_head == ASC_QLINK_END)
  7914. break;
  7915. }
  7916. return free_q_head;
  7917. }
  7918. /*
  7919. * void
  7920. * DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
  7921. *
  7922. * Calling/Exit State:
  7923. * none
  7924. *
  7925. * Description:
  7926. * Output an ASC_SCSI_Q structure to the chip
  7927. */
  7928. static void
  7929. DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
  7930. {
  7931. int i;
  7932. ASC_DBG_PRT_HEX(2, "DvcPutScsiQ", outbuf, 2 * words);
  7933. AscSetChipLramAddr(iop_base, s_addr);
  7934. for (i = 0; i < 2 * words; i += 2) {
  7935. if (i == 4 || i == 20) {
  7936. continue;
  7937. }
  7938. outpw(iop_base + IOP_RAM_DATA,
  7939. ((ushort)outbuf[i + 1] << 8) | outbuf[i]);
  7940. }
  7941. }
  7942. static int AscPutReadyQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
  7943. {
  7944. ushort q_addr;
  7945. uchar tid_no;
  7946. uchar sdtr_data;
  7947. uchar syn_period_ix;
  7948. uchar syn_offset;
  7949. PortAddr iop_base;
  7950. iop_base = asc_dvc->iop_base;
  7951. if (((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) &&
  7952. ((asc_dvc->sdtr_done & scsiq->q1.target_id) == 0)) {
  7953. tid_no = ASC_TIX_TO_TID(scsiq->q2.target_ix);
  7954. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  7955. syn_period_ix =
  7956. (sdtr_data >> 4) & (asc_dvc->max_sdtr_index - 1);
  7957. syn_offset = sdtr_data & ASC_SYN_MAX_OFFSET;
  7958. AscMsgOutSDTR(asc_dvc,
  7959. asc_dvc->sdtr_period_tbl[syn_period_ix],
  7960. syn_offset);
  7961. scsiq->q1.cntl |= QC_MSG_OUT;
  7962. }
  7963. q_addr = ASC_QNO_TO_QADDR(q_no);
  7964. if ((scsiq->q1.target_id & asc_dvc->use_tagged_qng) == 0) {
  7965. scsiq->q2.tag_code &= ~MSG_SIMPLE_TAG;
  7966. }
  7967. scsiq->q1.status = QS_FREE;
  7968. AscMemWordCopyPtrToLram(iop_base,
  7969. q_addr + ASC_SCSIQ_CDB_BEG,
  7970. (uchar *)scsiq->cdbptr, scsiq->q2.cdb_len >> 1);
  7971. DvcPutScsiQ(iop_base,
  7972. q_addr + ASC_SCSIQ_CPY_BEG,
  7973. (uchar *)&scsiq->q1.cntl,
  7974. ((sizeof(ASC_SCSIQ_1) + sizeof(ASC_SCSIQ_2)) / 2) - 1);
  7975. AscWriteLramWord(iop_base,
  7976. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS),
  7977. (ushort)(((ushort)scsiq->q1.
  7978. q_no << 8) | (ushort)QS_READY));
  7979. return 1;
  7980. }
  7981. static int
  7982. AscPutReadySgListQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
  7983. {
  7984. int sta;
  7985. int i;
  7986. ASC_SG_HEAD *sg_head;
  7987. ASC_SG_LIST_Q scsi_sg_q;
  7988. ASC_DCNT saved_data_addr;
  7989. ASC_DCNT saved_data_cnt;
  7990. PortAddr iop_base;
  7991. ushort sg_list_dwords;
  7992. ushort sg_index;
  7993. ushort sg_entry_cnt;
  7994. ushort q_addr;
  7995. uchar next_qp;
  7996. iop_base = asc_dvc->iop_base;
  7997. sg_head = scsiq->sg_head;
  7998. saved_data_addr = scsiq->q1.data_addr;
  7999. saved_data_cnt = scsiq->q1.data_cnt;
  8000. scsiq->q1.data_addr = (ASC_PADDR) sg_head->sg_list[0].addr;
  8001. scsiq->q1.data_cnt = (ASC_DCNT) sg_head->sg_list[0].bytes;
  8002. #if CC_VERY_LONG_SG_LIST
  8003. /*
  8004. * If sg_head->entry_cnt is greater than ASC_MAX_SG_LIST
  8005. * then not all SG elements will fit in the allocated queues.
  8006. * The rest of the SG elements will be copied when the RISC
  8007. * completes the SG elements that fit and halts.
  8008. */
  8009. if (sg_head->entry_cnt > ASC_MAX_SG_LIST) {
  8010. /*
  8011. * Set sg_entry_cnt to be the number of SG elements that
  8012. * will fit in the allocated SG queues. It is minus 1, because
  8013. * the first SG element is handled above. ASC_MAX_SG_LIST is
  8014. * already inflated by 1 to account for this. For example it
  8015. * may be 50 which is 1 + 7 queues * 7 SG elements.
  8016. */
  8017. sg_entry_cnt = ASC_MAX_SG_LIST - 1;
  8018. /*
  8019. * Keep track of remaining number of SG elements that will
  8020. * need to be handled from a_isr.c.
  8021. */
  8022. scsiq->remain_sg_entry_cnt =
  8023. sg_head->entry_cnt - ASC_MAX_SG_LIST;
  8024. } else {
  8025. #endif /* CC_VERY_LONG_SG_LIST */
  8026. /*
  8027. * Set sg_entry_cnt to be the number of SG elements that
  8028. * will fit in the allocated SG queues. It is minus 1, because
  8029. * the first SG element is handled above.
  8030. */
  8031. sg_entry_cnt = sg_head->entry_cnt - 1;
  8032. #if CC_VERY_LONG_SG_LIST
  8033. }
  8034. #endif /* CC_VERY_LONG_SG_LIST */
  8035. if (sg_entry_cnt != 0) {
  8036. scsiq->q1.cntl |= QC_SG_HEAD;
  8037. q_addr = ASC_QNO_TO_QADDR(q_no);
  8038. sg_index = 1;
  8039. scsiq->q1.sg_queue_cnt = sg_head->queue_cnt;
  8040. scsi_sg_q.sg_head_qp = q_no;
  8041. scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
  8042. for (i = 0; i < sg_head->queue_cnt; i++) {
  8043. scsi_sg_q.seq_no = i + 1;
  8044. if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
  8045. sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2);
  8046. sg_entry_cnt -= ASC_SG_LIST_PER_Q;
  8047. if (i == 0) {
  8048. scsi_sg_q.sg_list_cnt =
  8049. ASC_SG_LIST_PER_Q;
  8050. scsi_sg_q.sg_cur_list_cnt =
  8051. ASC_SG_LIST_PER_Q;
  8052. } else {
  8053. scsi_sg_q.sg_list_cnt =
  8054. ASC_SG_LIST_PER_Q - 1;
  8055. scsi_sg_q.sg_cur_list_cnt =
  8056. ASC_SG_LIST_PER_Q - 1;
  8057. }
  8058. } else {
  8059. #if CC_VERY_LONG_SG_LIST
  8060. /*
  8061. * This is the last SG queue in the list of
  8062. * allocated SG queues. If there are more
  8063. * SG elements than will fit in the allocated
  8064. * queues, then set the QCSG_SG_XFER_MORE flag.
  8065. */
  8066. if (sg_head->entry_cnt > ASC_MAX_SG_LIST) {
  8067. scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
  8068. } else {
  8069. #endif /* CC_VERY_LONG_SG_LIST */
  8070. scsi_sg_q.cntl |= QCSG_SG_XFER_END;
  8071. #if CC_VERY_LONG_SG_LIST
  8072. }
  8073. #endif /* CC_VERY_LONG_SG_LIST */
  8074. sg_list_dwords = sg_entry_cnt << 1;
  8075. if (i == 0) {
  8076. scsi_sg_q.sg_list_cnt = sg_entry_cnt;
  8077. scsi_sg_q.sg_cur_list_cnt =
  8078. sg_entry_cnt;
  8079. } else {
  8080. scsi_sg_q.sg_list_cnt =
  8081. sg_entry_cnt - 1;
  8082. scsi_sg_q.sg_cur_list_cnt =
  8083. sg_entry_cnt - 1;
  8084. }
  8085. sg_entry_cnt = 0;
  8086. }
  8087. next_qp = AscReadLramByte(iop_base,
  8088. (ushort)(q_addr +
  8089. ASC_SCSIQ_B_FWD));
  8090. scsi_sg_q.q_no = next_qp;
  8091. q_addr = ASC_QNO_TO_QADDR(next_qp);
  8092. AscMemWordCopyPtrToLram(iop_base,
  8093. q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
  8094. (uchar *)&scsi_sg_q,
  8095. sizeof(ASC_SG_LIST_Q) >> 1);
  8096. AscMemDWordCopyPtrToLram(iop_base,
  8097. q_addr + ASC_SGQ_LIST_BEG,
  8098. (uchar *)&sg_head->
  8099. sg_list[sg_index],
  8100. sg_list_dwords);
  8101. sg_index += ASC_SG_LIST_PER_Q;
  8102. scsiq->next_sg_index = sg_index;
  8103. }
  8104. } else {
  8105. scsiq->q1.cntl &= ~QC_SG_HEAD;
  8106. }
  8107. sta = AscPutReadyQueue(asc_dvc, scsiq, q_no);
  8108. scsiq->q1.data_addr = saved_data_addr;
  8109. scsiq->q1.data_cnt = saved_data_cnt;
  8110. return (sta);
  8111. }
  8112. static int
  8113. AscSendScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar n_q_required)
  8114. {
  8115. PortAddr iop_base;
  8116. uchar free_q_head;
  8117. uchar next_qp;
  8118. uchar tid_no;
  8119. uchar target_ix;
  8120. int sta;
  8121. iop_base = asc_dvc->iop_base;
  8122. target_ix = scsiq->q2.target_ix;
  8123. tid_no = ASC_TIX_TO_TID(target_ix);
  8124. sta = 0;
  8125. free_q_head = (uchar)AscGetVarFreeQHead(iop_base);
  8126. if (n_q_required > 1) {
  8127. next_qp = AscAllocMultipleFreeQueue(iop_base, free_q_head,
  8128. (uchar)n_q_required);
  8129. if (next_qp != ASC_QLINK_END) {
  8130. asc_dvc->last_q_shortage = 0;
  8131. scsiq->sg_head->queue_cnt = n_q_required - 1;
  8132. scsiq->q1.q_no = free_q_head;
  8133. sta = AscPutReadySgListQueue(asc_dvc, scsiq,
  8134. free_q_head);
  8135. }
  8136. } else if (n_q_required == 1) {
  8137. next_qp = AscAllocFreeQueue(iop_base, free_q_head);
  8138. if (next_qp != ASC_QLINK_END) {
  8139. scsiq->q1.q_no = free_q_head;
  8140. sta = AscPutReadyQueue(asc_dvc, scsiq, free_q_head);
  8141. }
  8142. }
  8143. if (sta == 1) {
  8144. AscPutVarFreeQHead(iop_base, next_qp);
  8145. asc_dvc->cur_total_qng += n_q_required;
  8146. asc_dvc->cur_dvc_qng[tid_no]++;
  8147. }
  8148. return sta;
  8149. }
  8150. #define ASC_SYN_OFFSET_ONE_DISABLE_LIST 16
  8151. static uchar _syn_offset_one_disable_cmd[ASC_SYN_OFFSET_ONE_DISABLE_LIST] = {
  8152. INQUIRY,
  8153. REQUEST_SENSE,
  8154. READ_CAPACITY,
  8155. READ_TOC,
  8156. MODE_SELECT,
  8157. MODE_SENSE,
  8158. MODE_SELECT_10,
  8159. MODE_SENSE_10,
  8160. 0xFF,
  8161. 0xFF,
  8162. 0xFF,
  8163. 0xFF,
  8164. 0xFF,
  8165. 0xFF,
  8166. 0xFF,
  8167. 0xFF
  8168. };
  8169. static int AscExeScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq)
  8170. {
  8171. PortAddr iop_base;
  8172. int sta;
  8173. int n_q_required;
  8174. int disable_syn_offset_one_fix;
  8175. int i;
  8176. ASC_PADDR addr;
  8177. ushort sg_entry_cnt = 0;
  8178. ushort sg_entry_cnt_minus_one = 0;
  8179. uchar target_ix;
  8180. uchar tid_no;
  8181. uchar sdtr_data;
  8182. uchar extra_bytes;
  8183. uchar scsi_cmd;
  8184. uchar disable_cmd;
  8185. ASC_SG_HEAD *sg_head;
  8186. ASC_DCNT data_cnt;
  8187. iop_base = asc_dvc->iop_base;
  8188. sg_head = scsiq->sg_head;
  8189. if (asc_dvc->err_code != 0)
  8190. return (ERR);
  8191. scsiq->q1.q_no = 0;
  8192. if ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES) == 0) {
  8193. scsiq->q1.extra_bytes = 0;
  8194. }
  8195. sta = 0;
  8196. target_ix = scsiq->q2.target_ix;
  8197. tid_no = ASC_TIX_TO_TID(target_ix);
  8198. n_q_required = 1;
  8199. if (scsiq->cdbptr[0] == REQUEST_SENSE) {
  8200. if ((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) {
  8201. asc_dvc->sdtr_done &= ~scsiq->q1.target_id;
  8202. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  8203. AscMsgOutSDTR(asc_dvc,
  8204. asc_dvc->
  8205. sdtr_period_tbl[(sdtr_data >> 4) &
  8206. (uchar)(asc_dvc->
  8207. max_sdtr_index -
  8208. 1)],
  8209. (uchar)(sdtr_data & (uchar)
  8210. ASC_SYN_MAX_OFFSET));
  8211. scsiq->q1.cntl |= (QC_MSG_OUT | QC_URGENT);
  8212. }
  8213. }
  8214. if (asc_dvc->in_critical_cnt != 0) {
  8215. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CRITICAL_RE_ENTRY);
  8216. return (ERR);
  8217. }
  8218. asc_dvc->in_critical_cnt++;
  8219. if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
  8220. if ((sg_entry_cnt = sg_head->entry_cnt) == 0) {
  8221. asc_dvc->in_critical_cnt--;
  8222. return (ERR);
  8223. }
  8224. #if !CC_VERY_LONG_SG_LIST
  8225. if (sg_entry_cnt > ASC_MAX_SG_LIST) {
  8226. asc_dvc->in_critical_cnt--;
  8227. return (ERR);
  8228. }
  8229. #endif /* !CC_VERY_LONG_SG_LIST */
  8230. if (sg_entry_cnt == 1) {
  8231. scsiq->q1.data_addr =
  8232. (ADV_PADDR)sg_head->sg_list[0].addr;
  8233. scsiq->q1.data_cnt =
  8234. (ADV_DCNT)sg_head->sg_list[0].bytes;
  8235. scsiq->q1.cntl &= ~(QC_SG_HEAD | QC_SG_SWAP_QUEUE);
  8236. }
  8237. sg_entry_cnt_minus_one = sg_entry_cnt - 1;
  8238. }
  8239. scsi_cmd = scsiq->cdbptr[0];
  8240. disable_syn_offset_one_fix = FALSE;
  8241. if ((asc_dvc->pci_fix_asyn_xfer & scsiq->q1.target_id) &&
  8242. !(asc_dvc->pci_fix_asyn_xfer_always & scsiq->q1.target_id)) {
  8243. if (scsiq->q1.cntl & QC_SG_HEAD) {
  8244. data_cnt = 0;
  8245. for (i = 0; i < sg_entry_cnt; i++) {
  8246. data_cnt +=
  8247. (ADV_DCNT)le32_to_cpu(sg_head->sg_list[i].
  8248. bytes);
  8249. }
  8250. } else {
  8251. data_cnt = le32_to_cpu(scsiq->q1.data_cnt);
  8252. }
  8253. if (data_cnt != 0UL) {
  8254. if (data_cnt < 512UL) {
  8255. disable_syn_offset_one_fix = TRUE;
  8256. } else {
  8257. for (i = 0; i < ASC_SYN_OFFSET_ONE_DISABLE_LIST;
  8258. i++) {
  8259. disable_cmd =
  8260. _syn_offset_one_disable_cmd[i];
  8261. if (disable_cmd == 0xFF) {
  8262. break;
  8263. }
  8264. if (scsi_cmd == disable_cmd) {
  8265. disable_syn_offset_one_fix =
  8266. TRUE;
  8267. break;
  8268. }
  8269. }
  8270. }
  8271. }
  8272. }
  8273. if (disable_syn_offset_one_fix) {
  8274. scsiq->q2.tag_code &= ~MSG_SIMPLE_TAG;
  8275. scsiq->q2.tag_code |= (ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX |
  8276. ASC_TAG_FLAG_DISABLE_DISCONNECT);
  8277. } else {
  8278. scsiq->q2.tag_code &= 0x27;
  8279. }
  8280. if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
  8281. if (asc_dvc->bug_fix_cntl) {
  8282. if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
  8283. if ((scsi_cmd == READ_6) ||
  8284. (scsi_cmd == READ_10)) {
  8285. addr =
  8286. (ADV_PADDR)le32_to_cpu(sg_head->
  8287. sg_list
  8288. [sg_entry_cnt_minus_one].
  8289. addr) +
  8290. (ADV_DCNT)le32_to_cpu(sg_head->
  8291. sg_list
  8292. [sg_entry_cnt_minus_one].
  8293. bytes);
  8294. extra_bytes =
  8295. (uchar)((ushort)addr & 0x0003);
  8296. if ((extra_bytes != 0)
  8297. &&
  8298. ((scsiq->q2.
  8299. tag_code &
  8300. ASC_TAG_FLAG_EXTRA_BYTES)
  8301. == 0)) {
  8302. scsiq->q2.tag_code |=
  8303. ASC_TAG_FLAG_EXTRA_BYTES;
  8304. scsiq->q1.extra_bytes =
  8305. extra_bytes;
  8306. data_cnt =
  8307. le32_to_cpu(sg_head->
  8308. sg_list
  8309. [sg_entry_cnt_minus_one].
  8310. bytes);
  8311. data_cnt -=
  8312. (ASC_DCNT) extra_bytes;
  8313. sg_head->
  8314. sg_list
  8315. [sg_entry_cnt_minus_one].
  8316. bytes =
  8317. cpu_to_le32(data_cnt);
  8318. }
  8319. }
  8320. }
  8321. }
  8322. sg_head->entry_to_copy = sg_head->entry_cnt;
  8323. #if CC_VERY_LONG_SG_LIST
  8324. /*
  8325. * Set the sg_entry_cnt to the maximum possible. The rest of
  8326. * the SG elements will be copied when the RISC completes the
  8327. * SG elements that fit and halts.
  8328. */
  8329. if (sg_entry_cnt > ASC_MAX_SG_LIST) {
  8330. sg_entry_cnt = ASC_MAX_SG_LIST;
  8331. }
  8332. #endif /* CC_VERY_LONG_SG_LIST */
  8333. n_q_required = AscSgListToQueue(sg_entry_cnt);
  8334. if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, n_q_required) >=
  8335. (uint) n_q_required)
  8336. || ((scsiq->q1.cntl & QC_URGENT) != 0)) {
  8337. if ((sta =
  8338. AscSendScsiQueue(asc_dvc, scsiq,
  8339. n_q_required)) == 1) {
  8340. asc_dvc->in_critical_cnt--;
  8341. return (sta);
  8342. }
  8343. }
  8344. } else {
  8345. if (asc_dvc->bug_fix_cntl) {
  8346. if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
  8347. if ((scsi_cmd == READ_6) ||
  8348. (scsi_cmd == READ_10)) {
  8349. addr =
  8350. le32_to_cpu(scsiq->q1.data_addr) +
  8351. le32_to_cpu(scsiq->q1.data_cnt);
  8352. extra_bytes =
  8353. (uchar)((ushort)addr & 0x0003);
  8354. if ((extra_bytes != 0)
  8355. &&
  8356. ((scsiq->q2.
  8357. tag_code &
  8358. ASC_TAG_FLAG_EXTRA_BYTES)
  8359. == 0)) {
  8360. data_cnt =
  8361. le32_to_cpu(scsiq->q1.
  8362. data_cnt);
  8363. if (((ushort)data_cnt & 0x01FF)
  8364. == 0) {
  8365. scsiq->q2.tag_code |=
  8366. ASC_TAG_FLAG_EXTRA_BYTES;
  8367. data_cnt -= (ASC_DCNT)
  8368. extra_bytes;
  8369. scsiq->q1.data_cnt =
  8370. cpu_to_le32
  8371. (data_cnt);
  8372. scsiq->q1.extra_bytes =
  8373. extra_bytes;
  8374. }
  8375. }
  8376. }
  8377. }
  8378. }
  8379. n_q_required = 1;
  8380. if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, 1) >= 1) ||
  8381. ((scsiq->q1.cntl & QC_URGENT) != 0)) {
  8382. if ((sta = AscSendScsiQueue(asc_dvc, scsiq,
  8383. n_q_required)) == 1) {
  8384. asc_dvc->in_critical_cnt--;
  8385. return (sta);
  8386. }
  8387. }
  8388. }
  8389. asc_dvc->in_critical_cnt--;
  8390. return (sta);
  8391. }
  8392. /*
  8393. * AdvExeScsiQueue() - Send a request to the RISC microcode program.
  8394. *
  8395. * Allocate a carrier structure, point the carrier to the ADV_SCSI_REQ_Q,
  8396. * add the carrier to the ICQ (Initiator Command Queue), and tickle the
  8397. * RISC to notify it a new command is ready to be executed.
  8398. *
  8399. * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
  8400. * set to SCSI_MAX_RETRY.
  8401. *
  8402. * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the microcode
  8403. * for DMA addresses or math operations are byte swapped to little-endian
  8404. * order.
  8405. *
  8406. * Return:
  8407. * ADV_SUCCESS(1) - The request was successfully queued.
  8408. * ADV_BUSY(0) - Resource unavailable; Retry again after pending
  8409. * request completes.
  8410. * ADV_ERROR(-1) - Invalid ADV_SCSI_REQ_Q request structure
  8411. * host IC error.
  8412. */
  8413. static int AdvExeScsiQueue(ADV_DVC_VAR *asc_dvc, ADV_SCSI_REQ_Q *scsiq)
  8414. {
  8415. AdvPortAddr iop_base;
  8416. ADV_PADDR req_paddr;
  8417. ADV_CARR_T *new_carrp;
  8418. /*
  8419. * The ADV_SCSI_REQ_Q 'target_id' field should never exceed ADV_MAX_TID.
  8420. */
  8421. if (scsiq->target_id > ADV_MAX_TID) {
  8422. scsiq->host_status = QHSTA_M_INVALID_DEVICE;
  8423. scsiq->done_status = QD_WITH_ERROR;
  8424. return ADV_ERROR;
  8425. }
  8426. iop_base = asc_dvc->iop_base;
  8427. /*
  8428. * Allocate a carrier ensuring at least one carrier always
  8429. * remains on the freelist and initialize fields.
  8430. */
  8431. if ((new_carrp = asc_dvc->carr_freelist) == NULL) {
  8432. return ADV_BUSY;
  8433. }
  8434. asc_dvc->carr_freelist = (ADV_CARR_T *)
  8435. ADV_U32_TO_VADDR(le32_to_cpu(new_carrp->next_vpa));
  8436. asc_dvc->carr_pending_cnt++;
  8437. /*
  8438. * Set the carrier to be a stopper by setting 'next_vpa'
  8439. * to the stopper value. The current stopper will be changed
  8440. * below to point to the new stopper.
  8441. */
  8442. new_carrp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  8443. /*
  8444. * Clear the ADV_SCSI_REQ_Q done flag.
  8445. */
  8446. scsiq->a_flag &= ~ADV_SCSIQ_DONE;
  8447. req_paddr = virt_to_bus(scsiq);
  8448. BUG_ON(req_paddr & 31);
  8449. /* Wait for assertion before making little-endian */
  8450. req_paddr = cpu_to_le32(req_paddr);
  8451. /* Save virtual and physical address of ADV_SCSI_REQ_Q and carrier. */
  8452. scsiq->scsiq_ptr = cpu_to_le32(ADV_VADDR_TO_U32(scsiq));
  8453. scsiq->scsiq_rptr = req_paddr;
  8454. scsiq->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->icq_sp));
  8455. /*
  8456. * Every ADV_CARR_T.carr_pa is byte swapped to little-endian
  8457. * order during initialization.
  8458. */
  8459. scsiq->carr_pa = asc_dvc->icq_sp->carr_pa;
  8460. /*
  8461. * Use the current stopper to send the ADV_SCSI_REQ_Q command to
  8462. * the microcode. The newly allocated stopper will become the new
  8463. * stopper.
  8464. */
  8465. asc_dvc->icq_sp->areq_vpa = req_paddr;
  8466. /*
  8467. * Set the 'next_vpa' pointer for the old stopper to be the
  8468. * physical address of the new stopper. The RISC can only
  8469. * follow physical addresses.
  8470. */
  8471. asc_dvc->icq_sp->next_vpa = new_carrp->carr_pa;
  8472. /*
  8473. * Set the host adapter stopper pointer to point to the new carrier.
  8474. */
  8475. asc_dvc->icq_sp = new_carrp;
  8476. if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
  8477. asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  8478. /*
  8479. * Tickle the RISC to tell it to read its Command Queue Head pointer.
  8480. */
  8481. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A);
  8482. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  8483. /*
  8484. * Clear the tickle value. In the ASC-3550 the RISC flag
  8485. * command 'clr_tickle_a' does not work unless the host
  8486. * value is cleared.
  8487. */
  8488. AdvWriteByteRegister(iop_base, IOPB_TICKLE,
  8489. ADV_TICKLE_NOP);
  8490. }
  8491. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  8492. /*
  8493. * Notify the RISC a carrier is ready by writing the physical
  8494. * address of the new carrier stopper to the COMMA register.
  8495. */
  8496. AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
  8497. le32_to_cpu(new_carrp->carr_pa));
  8498. }
  8499. return ADV_SUCCESS;
  8500. }
  8501. /*
  8502. * Execute a single 'Scsi_Cmnd'.
  8503. */
  8504. static int asc_execute_scsi_cmnd(struct scsi_cmnd *scp)
  8505. {
  8506. int ret, err_code;
  8507. struct asc_board *boardp = shost_priv(scp->device->host);
  8508. ASC_DBG(1, "scp 0x%p\n", scp);
  8509. if (ASC_NARROW_BOARD(boardp)) {
  8510. ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  8511. struct asc_scsi_q asc_scsi_q;
  8512. /* asc_build_req() can not return ASC_BUSY. */
  8513. ret = asc_build_req(boardp, scp, &asc_scsi_q);
  8514. if (ret == ASC_ERROR) {
  8515. ASC_STATS(scp->device->host, build_error);
  8516. return ASC_ERROR;
  8517. }
  8518. ret = AscExeScsiQueue(asc_dvc, &asc_scsi_q);
  8519. kfree(asc_scsi_q.sg_head);
  8520. err_code = asc_dvc->err_code;
  8521. } else {
  8522. ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
  8523. ADV_SCSI_REQ_Q *adv_scsiqp;
  8524. switch (adv_build_req(boardp, scp, &adv_scsiqp)) {
  8525. case ASC_NOERROR:
  8526. ASC_DBG(3, "adv_build_req ASC_NOERROR\n");
  8527. break;
  8528. case ASC_BUSY:
  8529. ASC_DBG(1, "adv_build_req ASC_BUSY\n");
  8530. /*
  8531. * The asc_stats fields 'adv_build_noreq' and
  8532. * 'adv_build_nosg' count wide board busy conditions.
  8533. * They are updated in adv_build_req and
  8534. * adv_get_sglist, respectively.
  8535. */
  8536. return ASC_BUSY;
  8537. case ASC_ERROR:
  8538. default:
  8539. ASC_DBG(1, "adv_build_req ASC_ERROR\n");
  8540. ASC_STATS(scp->device->host, build_error);
  8541. return ASC_ERROR;
  8542. }
  8543. ret = AdvExeScsiQueue(adv_dvc, adv_scsiqp);
  8544. err_code = adv_dvc->err_code;
  8545. }
  8546. switch (ret) {
  8547. case ASC_NOERROR:
  8548. ASC_STATS(scp->device->host, exe_noerror);
  8549. /*
  8550. * Increment monotonically increasing per device
  8551. * successful request counter. Wrapping doesn't matter.
  8552. */
  8553. boardp->reqcnt[scp->device->id]++;
  8554. ASC_DBG(1, "ExeScsiQueue() ASC_NOERROR\n");
  8555. break;
  8556. case ASC_BUSY:
  8557. ASC_STATS(scp->device->host, exe_busy);
  8558. break;
  8559. case ASC_ERROR:
  8560. scmd_printk(KERN_ERR, scp, "ExeScsiQueue() ASC_ERROR, "
  8561. "err_code 0x%x\n", err_code);
  8562. ASC_STATS(scp->device->host, exe_error);
  8563. scp->result = HOST_BYTE(DID_ERROR);
  8564. break;
  8565. default:
  8566. scmd_printk(KERN_ERR, scp, "ExeScsiQueue() unknown, "
  8567. "err_code 0x%x\n", err_code);
  8568. ASC_STATS(scp->device->host, exe_unknown);
  8569. scp->result = HOST_BYTE(DID_ERROR);
  8570. break;
  8571. }
  8572. ASC_DBG(1, "end\n");
  8573. return ret;
  8574. }
  8575. /*
  8576. * advansys_queuecommand() - interrupt-driven I/O entrypoint.
  8577. *
  8578. * This function always returns 0. Command return status is saved
  8579. * in the 'scp' result field.
  8580. */
  8581. static int
  8582. advansys_queuecommand_lck(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *))
  8583. {
  8584. struct Scsi_Host *shost = scp->device->host;
  8585. int asc_res, result = 0;
  8586. ASC_STATS(shost, queuecommand);
  8587. scp->scsi_done = done;
  8588. asc_res = asc_execute_scsi_cmnd(scp);
  8589. switch (asc_res) {
  8590. case ASC_NOERROR:
  8591. break;
  8592. case ASC_BUSY:
  8593. result = SCSI_MLQUEUE_HOST_BUSY;
  8594. break;
  8595. case ASC_ERROR:
  8596. default:
  8597. asc_scsi_done(scp);
  8598. break;
  8599. }
  8600. return result;
  8601. }
  8602. static DEF_SCSI_QCMD(advansys_queuecommand)
  8603. static ushort __devinit AscGetEisaChipCfg(PortAddr iop_base)
  8604. {
  8605. PortAddr eisa_cfg_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
  8606. (PortAddr) (ASC_EISA_CFG_IOP_MASK);
  8607. return inpw(eisa_cfg_iop);
  8608. }
  8609. /*
  8610. * Return the BIOS address of the adapter at the specified
  8611. * I/O port and with the specified bus type.
  8612. */
  8613. static unsigned short __devinit
  8614. AscGetChipBiosAddress(PortAddr iop_base, unsigned short bus_type)
  8615. {
  8616. unsigned short cfg_lsw;
  8617. unsigned short bios_addr;
  8618. /*
  8619. * The PCI BIOS is re-located by the motherboard BIOS. Because
  8620. * of this the driver can not determine where a PCI BIOS is
  8621. * loaded and executes.
  8622. */
  8623. if (bus_type & ASC_IS_PCI)
  8624. return 0;
  8625. if ((bus_type & ASC_IS_EISA) != 0) {
  8626. cfg_lsw = AscGetEisaChipCfg(iop_base);
  8627. cfg_lsw &= 0x000F;
  8628. bios_addr = ASC_BIOS_MIN_ADDR + cfg_lsw * ASC_BIOS_BANK_SIZE;
  8629. return bios_addr;
  8630. }
  8631. cfg_lsw = AscGetChipCfgLsw(iop_base);
  8632. /*
  8633. * ISA PnP uses the top bit as the 32K BIOS flag
  8634. */
  8635. if (bus_type == ASC_IS_ISAPNP)
  8636. cfg_lsw &= 0x7FFF;
  8637. bios_addr = ASC_BIOS_MIN_ADDR + (cfg_lsw >> 12) * ASC_BIOS_BANK_SIZE;
  8638. return bios_addr;
  8639. }
  8640. static uchar __devinit AscSetChipScsiID(PortAddr iop_base, uchar new_host_id)
  8641. {
  8642. ushort cfg_lsw;
  8643. if (AscGetChipScsiID(iop_base) == new_host_id) {
  8644. return (new_host_id);
  8645. }
  8646. cfg_lsw = AscGetChipCfgLsw(iop_base);
  8647. cfg_lsw &= 0xF8FF;
  8648. cfg_lsw |= (ushort)((new_host_id & ASC_MAX_TID) << 8);
  8649. AscSetChipCfgLsw(iop_base, cfg_lsw);
  8650. return (AscGetChipScsiID(iop_base));
  8651. }
  8652. static unsigned char __devinit AscGetChipScsiCtrl(PortAddr iop_base)
  8653. {
  8654. unsigned char sc;
  8655. AscSetBank(iop_base, 1);
  8656. sc = inp(iop_base + IOP_REG_SC);
  8657. AscSetBank(iop_base, 0);
  8658. return sc;
  8659. }
  8660. static unsigned char __devinit
  8661. AscGetChipVersion(PortAddr iop_base, unsigned short bus_type)
  8662. {
  8663. if (bus_type & ASC_IS_EISA) {
  8664. PortAddr eisa_iop;
  8665. unsigned char revision;
  8666. eisa_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
  8667. (PortAddr) ASC_EISA_REV_IOP_MASK;
  8668. revision = inp(eisa_iop);
  8669. return ASC_CHIP_MIN_VER_EISA - 1 + revision;
  8670. }
  8671. return AscGetChipVerNo(iop_base);
  8672. }
  8673. #ifdef CONFIG_ISA
  8674. static void __devinit AscEnableIsaDma(uchar dma_channel)
  8675. {
  8676. if (dma_channel < 4) {
  8677. outp(0x000B, (ushort)(0xC0 | dma_channel));
  8678. outp(0x000A, dma_channel);
  8679. } else if (dma_channel < 8) {
  8680. outp(0x00D6, (ushort)(0xC0 | (dma_channel - 4)));
  8681. outp(0x00D4, (ushort)(dma_channel - 4));
  8682. }
  8683. }
  8684. #endif /* CONFIG_ISA */
  8685. static int AscStopQueueExe(PortAddr iop_base)
  8686. {
  8687. int count = 0;
  8688. if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) == 0) {
  8689. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
  8690. ASC_STOP_REQ_RISC_STOP);
  8691. do {
  8692. if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) &
  8693. ASC_STOP_ACK_RISC_STOP) {
  8694. return (1);
  8695. }
  8696. mdelay(100);
  8697. } while (count++ < 20);
  8698. }
  8699. return (0);
  8700. }
  8701. static ASC_DCNT __devinit AscGetMaxDmaCount(ushort bus_type)
  8702. {
  8703. if (bus_type & ASC_IS_ISA)
  8704. return ASC_MAX_ISA_DMA_COUNT;
  8705. else if (bus_type & (ASC_IS_EISA | ASC_IS_VL))
  8706. return ASC_MAX_VL_DMA_COUNT;
  8707. return ASC_MAX_PCI_DMA_COUNT;
  8708. }
  8709. #ifdef CONFIG_ISA
  8710. static ushort __devinit AscGetIsaDmaChannel(PortAddr iop_base)
  8711. {
  8712. ushort channel;
  8713. channel = AscGetChipCfgLsw(iop_base) & 0x0003;
  8714. if (channel == 0x03)
  8715. return (0);
  8716. else if (channel == 0x00)
  8717. return (7);
  8718. return (channel + 4);
  8719. }
  8720. static ushort __devinit AscSetIsaDmaChannel(PortAddr iop_base, ushort dma_channel)
  8721. {
  8722. ushort cfg_lsw;
  8723. uchar value;
  8724. if ((dma_channel >= 5) && (dma_channel <= 7)) {
  8725. if (dma_channel == 7)
  8726. value = 0x00;
  8727. else
  8728. value = dma_channel - 4;
  8729. cfg_lsw = AscGetChipCfgLsw(iop_base) & 0xFFFC;
  8730. cfg_lsw |= value;
  8731. AscSetChipCfgLsw(iop_base, cfg_lsw);
  8732. return (AscGetIsaDmaChannel(iop_base));
  8733. }
  8734. return 0;
  8735. }
  8736. static uchar __devinit AscGetIsaDmaSpeed(PortAddr iop_base)
  8737. {
  8738. uchar speed_value;
  8739. AscSetBank(iop_base, 1);
  8740. speed_value = AscReadChipDmaSpeed(iop_base);
  8741. speed_value &= 0x07;
  8742. AscSetBank(iop_base, 0);
  8743. return speed_value;
  8744. }
  8745. static uchar __devinit AscSetIsaDmaSpeed(PortAddr iop_base, uchar speed_value)
  8746. {
  8747. speed_value &= 0x07;
  8748. AscSetBank(iop_base, 1);
  8749. AscWriteChipDmaSpeed(iop_base, speed_value);
  8750. AscSetBank(iop_base, 0);
  8751. return AscGetIsaDmaSpeed(iop_base);
  8752. }
  8753. #endif /* CONFIG_ISA */
  8754. static ushort __devinit AscInitAscDvcVar(ASC_DVC_VAR *asc_dvc)
  8755. {
  8756. int i;
  8757. PortAddr iop_base;
  8758. ushort warn_code;
  8759. uchar chip_version;
  8760. iop_base = asc_dvc->iop_base;
  8761. warn_code = 0;
  8762. asc_dvc->err_code = 0;
  8763. if ((asc_dvc->bus_type &
  8764. (ASC_IS_ISA | ASC_IS_PCI | ASC_IS_EISA | ASC_IS_VL)) == 0) {
  8765. asc_dvc->err_code |= ASC_IERR_NO_BUS_TYPE;
  8766. }
  8767. AscSetChipControl(iop_base, CC_HALT);
  8768. AscSetChipStatus(iop_base, 0);
  8769. asc_dvc->bug_fix_cntl = 0;
  8770. asc_dvc->pci_fix_asyn_xfer = 0;
  8771. asc_dvc->pci_fix_asyn_xfer_always = 0;
  8772. /* asc_dvc->init_state initialized in AscInitGetConfig(). */
  8773. asc_dvc->sdtr_done = 0;
  8774. asc_dvc->cur_total_qng = 0;
  8775. asc_dvc->is_in_int = 0;
  8776. asc_dvc->in_critical_cnt = 0;
  8777. asc_dvc->last_q_shortage = 0;
  8778. asc_dvc->use_tagged_qng = 0;
  8779. asc_dvc->no_scam = 0;
  8780. asc_dvc->unit_not_ready = 0;
  8781. asc_dvc->queue_full_or_busy = 0;
  8782. asc_dvc->redo_scam = 0;
  8783. asc_dvc->res2 = 0;
  8784. asc_dvc->min_sdtr_index = 0;
  8785. asc_dvc->cfg->can_tagged_qng = 0;
  8786. asc_dvc->cfg->cmd_qng_enabled = 0;
  8787. asc_dvc->dvc_cntl = ASC_DEF_DVC_CNTL;
  8788. asc_dvc->init_sdtr = 0;
  8789. asc_dvc->max_total_qng = ASC_DEF_MAX_TOTAL_QNG;
  8790. asc_dvc->scsi_reset_wait = 3;
  8791. asc_dvc->start_motor = ASC_SCSI_WIDTH_BIT_SET;
  8792. asc_dvc->max_dma_count = AscGetMaxDmaCount(asc_dvc->bus_type);
  8793. asc_dvc->cfg->sdtr_enable = ASC_SCSI_WIDTH_BIT_SET;
  8794. asc_dvc->cfg->disc_enable = ASC_SCSI_WIDTH_BIT_SET;
  8795. asc_dvc->cfg->chip_scsi_id = ASC_DEF_CHIP_SCSI_ID;
  8796. chip_version = AscGetChipVersion(iop_base, asc_dvc->bus_type);
  8797. asc_dvc->cfg->chip_version = chip_version;
  8798. asc_dvc->sdtr_period_tbl = asc_syn_xfer_period;
  8799. asc_dvc->max_sdtr_index = 7;
  8800. if ((asc_dvc->bus_type & ASC_IS_PCI) &&
  8801. (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3150)) {
  8802. asc_dvc->bus_type = ASC_IS_PCI_ULTRA;
  8803. asc_dvc->sdtr_period_tbl = asc_syn_ultra_xfer_period;
  8804. asc_dvc->max_sdtr_index = 15;
  8805. if (chip_version == ASC_CHIP_VER_PCI_ULTRA_3150) {
  8806. AscSetExtraControl(iop_base,
  8807. (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
  8808. } else if (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3050) {
  8809. AscSetExtraControl(iop_base,
  8810. (SEC_ACTIVE_NEGATE |
  8811. SEC_ENABLE_FILTER));
  8812. }
  8813. }
  8814. if (asc_dvc->bus_type == ASC_IS_PCI) {
  8815. AscSetExtraControl(iop_base,
  8816. (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
  8817. }
  8818. asc_dvc->cfg->isa_dma_speed = ASC_DEF_ISA_DMA_SPEED;
  8819. #ifdef CONFIG_ISA
  8820. if ((asc_dvc->bus_type & ASC_IS_ISA) != 0) {
  8821. if (chip_version >= ASC_CHIP_MIN_VER_ISA_PNP) {
  8822. AscSetChipIFC(iop_base, IFC_INIT_DEFAULT);
  8823. asc_dvc->bus_type = ASC_IS_ISAPNP;
  8824. }
  8825. asc_dvc->cfg->isa_dma_channel =
  8826. (uchar)AscGetIsaDmaChannel(iop_base);
  8827. }
  8828. #endif /* CONFIG_ISA */
  8829. for (i = 0; i <= ASC_MAX_TID; i++) {
  8830. asc_dvc->cur_dvc_qng[i] = 0;
  8831. asc_dvc->max_dvc_qng[i] = ASC_MAX_SCSI1_QNG;
  8832. asc_dvc->scsiq_busy_head[i] = (ASC_SCSI_Q *)0L;
  8833. asc_dvc->scsiq_busy_tail[i] = (ASC_SCSI_Q *)0L;
  8834. asc_dvc->cfg->max_tag_qng[i] = ASC_MAX_INRAM_TAG_QNG;
  8835. }
  8836. return warn_code;
  8837. }
  8838. static int __devinit AscWriteEEPCmdReg(PortAddr iop_base, uchar cmd_reg)
  8839. {
  8840. int retry;
  8841. for (retry = 0; retry < ASC_EEP_MAX_RETRY; retry++) {
  8842. unsigned char read_back;
  8843. AscSetChipEEPCmd(iop_base, cmd_reg);
  8844. mdelay(1);
  8845. read_back = AscGetChipEEPCmd(iop_base);
  8846. if (read_back == cmd_reg)
  8847. return 1;
  8848. }
  8849. return 0;
  8850. }
  8851. static void __devinit AscWaitEEPRead(void)
  8852. {
  8853. mdelay(1);
  8854. }
  8855. static ushort __devinit AscReadEEPWord(PortAddr iop_base, uchar addr)
  8856. {
  8857. ushort read_wval;
  8858. uchar cmd_reg;
  8859. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
  8860. AscWaitEEPRead();
  8861. cmd_reg = addr | ASC_EEP_CMD_READ;
  8862. AscWriteEEPCmdReg(iop_base, cmd_reg);
  8863. AscWaitEEPRead();
  8864. read_wval = AscGetChipEEPData(iop_base);
  8865. AscWaitEEPRead();
  8866. return read_wval;
  8867. }
  8868. static ushort __devinit
  8869. AscGetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf, ushort bus_type)
  8870. {
  8871. ushort wval;
  8872. ushort sum;
  8873. ushort *wbuf;
  8874. int cfg_beg;
  8875. int cfg_end;
  8876. int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
  8877. int s_addr;
  8878. wbuf = (ushort *)cfg_buf;
  8879. sum = 0;
  8880. /* Read two config words; Byte-swapping done by AscReadEEPWord(). */
  8881. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  8882. *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
  8883. sum += *wbuf;
  8884. }
  8885. if (bus_type & ASC_IS_VL) {
  8886. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  8887. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  8888. } else {
  8889. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  8890. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  8891. }
  8892. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  8893. wval = AscReadEEPWord(iop_base, (uchar)s_addr);
  8894. if (s_addr <= uchar_end_in_config) {
  8895. /*
  8896. * Swap all char fields - must unswap bytes already swapped
  8897. * by AscReadEEPWord().
  8898. */
  8899. *wbuf = le16_to_cpu(wval);
  8900. } else {
  8901. /* Don't swap word field at the end - cntl field. */
  8902. *wbuf = wval;
  8903. }
  8904. sum += wval; /* Checksum treats all EEPROM data as words. */
  8905. }
  8906. /*
  8907. * Read the checksum word which will be compared against 'sum'
  8908. * by the caller. Word field already swapped.
  8909. */
  8910. *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
  8911. return sum;
  8912. }
  8913. static int __devinit AscTestExternalLram(ASC_DVC_VAR *asc_dvc)
  8914. {
  8915. PortAddr iop_base;
  8916. ushort q_addr;
  8917. ushort saved_word;
  8918. int sta;
  8919. iop_base = asc_dvc->iop_base;
  8920. sta = 0;
  8921. q_addr = ASC_QNO_TO_QADDR(241);
  8922. saved_word = AscReadLramWord(iop_base, q_addr);
  8923. AscSetChipLramAddr(iop_base, q_addr);
  8924. AscSetChipLramData(iop_base, 0x55AA);
  8925. mdelay(10);
  8926. AscSetChipLramAddr(iop_base, q_addr);
  8927. if (AscGetChipLramData(iop_base) == 0x55AA) {
  8928. sta = 1;
  8929. AscWriteLramWord(iop_base, q_addr, saved_word);
  8930. }
  8931. return (sta);
  8932. }
  8933. static void __devinit AscWaitEEPWrite(void)
  8934. {
  8935. mdelay(20);
  8936. }
  8937. static int __devinit AscWriteEEPDataReg(PortAddr iop_base, ushort data_reg)
  8938. {
  8939. ushort read_back;
  8940. int retry;
  8941. retry = 0;
  8942. while (TRUE) {
  8943. AscSetChipEEPData(iop_base, data_reg);
  8944. mdelay(1);
  8945. read_back = AscGetChipEEPData(iop_base);
  8946. if (read_back == data_reg) {
  8947. return (1);
  8948. }
  8949. if (retry++ > ASC_EEP_MAX_RETRY) {
  8950. return (0);
  8951. }
  8952. }
  8953. }
  8954. static ushort __devinit
  8955. AscWriteEEPWord(PortAddr iop_base, uchar addr, ushort word_val)
  8956. {
  8957. ushort read_wval;
  8958. read_wval = AscReadEEPWord(iop_base, addr);
  8959. if (read_wval != word_val) {
  8960. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_ABLE);
  8961. AscWaitEEPRead();
  8962. AscWriteEEPDataReg(iop_base, word_val);
  8963. AscWaitEEPRead();
  8964. AscWriteEEPCmdReg(iop_base,
  8965. (uchar)((uchar)ASC_EEP_CMD_WRITE | addr));
  8966. AscWaitEEPWrite();
  8967. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
  8968. AscWaitEEPRead();
  8969. return (AscReadEEPWord(iop_base, addr));
  8970. }
  8971. return (read_wval);
  8972. }
  8973. static int __devinit
  8974. AscSetEEPConfigOnce(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf, ushort bus_type)
  8975. {
  8976. int n_error;
  8977. ushort *wbuf;
  8978. ushort word;
  8979. ushort sum;
  8980. int s_addr;
  8981. int cfg_beg;
  8982. int cfg_end;
  8983. int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
  8984. wbuf = (ushort *)cfg_buf;
  8985. n_error = 0;
  8986. sum = 0;
  8987. /* Write two config words; AscWriteEEPWord() will swap bytes. */
  8988. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  8989. sum += *wbuf;
  8990. if (*wbuf != AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
  8991. n_error++;
  8992. }
  8993. }
  8994. if (bus_type & ASC_IS_VL) {
  8995. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  8996. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  8997. } else {
  8998. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  8999. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  9000. }
  9001. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  9002. if (s_addr <= uchar_end_in_config) {
  9003. /*
  9004. * This is a char field. Swap char fields before they are
  9005. * swapped again by AscWriteEEPWord().
  9006. */
  9007. word = cpu_to_le16(*wbuf);
  9008. if (word !=
  9009. AscWriteEEPWord(iop_base, (uchar)s_addr, word)) {
  9010. n_error++;
  9011. }
  9012. } else {
  9013. /* Don't swap word field at the end - cntl field. */
  9014. if (*wbuf !=
  9015. AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
  9016. n_error++;
  9017. }
  9018. }
  9019. sum += *wbuf; /* Checksum calculated from word values. */
  9020. }
  9021. /* Write checksum word. It will be swapped by AscWriteEEPWord(). */
  9022. *wbuf = sum;
  9023. if (sum != AscWriteEEPWord(iop_base, (uchar)s_addr, sum)) {
  9024. n_error++;
  9025. }
  9026. /* Read EEPROM back again. */
  9027. wbuf = (ushort *)cfg_buf;
  9028. /*
  9029. * Read two config words; Byte-swapping done by AscReadEEPWord().
  9030. */
  9031. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  9032. if (*wbuf != AscReadEEPWord(iop_base, (uchar)s_addr)) {
  9033. n_error++;
  9034. }
  9035. }
  9036. if (bus_type & ASC_IS_VL) {
  9037. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  9038. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  9039. } else {
  9040. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  9041. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  9042. }
  9043. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  9044. if (s_addr <= uchar_end_in_config) {
  9045. /*
  9046. * Swap all char fields. Must unswap bytes already swapped
  9047. * by AscReadEEPWord().
  9048. */
  9049. word =
  9050. le16_to_cpu(AscReadEEPWord
  9051. (iop_base, (uchar)s_addr));
  9052. } else {
  9053. /* Don't swap word field at the end - cntl field. */
  9054. word = AscReadEEPWord(iop_base, (uchar)s_addr);
  9055. }
  9056. if (*wbuf != word) {
  9057. n_error++;
  9058. }
  9059. }
  9060. /* Read checksum; Byte swapping not needed. */
  9061. if (AscReadEEPWord(iop_base, (uchar)s_addr) != sum) {
  9062. n_error++;
  9063. }
  9064. return n_error;
  9065. }
  9066. static int __devinit
  9067. AscSetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf, ushort bus_type)
  9068. {
  9069. int retry;
  9070. int n_error;
  9071. retry = 0;
  9072. while (TRUE) {
  9073. if ((n_error = AscSetEEPConfigOnce(iop_base, cfg_buf,
  9074. bus_type)) == 0) {
  9075. break;
  9076. }
  9077. if (++retry > ASC_EEP_MAX_RETRY) {
  9078. break;
  9079. }
  9080. }
  9081. return n_error;
  9082. }
  9083. static ushort __devinit AscInitFromEEP(ASC_DVC_VAR *asc_dvc)
  9084. {
  9085. ASCEEP_CONFIG eep_config_buf;
  9086. ASCEEP_CONFIG *eep_config;
  9087. PortAddr iop_base;
  9088. ushort chksum;
  9089. ushort warn_code;
  9090. ushort cfg_msw, cfg_lsw;
  9091. int i;
  9092. int write_eep = 0;
  9093. iop_base = asc_dvc->iop_base;
  9094. warn_code = 0;
  9095. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0x00FE);
  9096. AscStopQueueExe(iop_base);
  9097. if ((AscStopChip(iop_base) == FALSE) ||
  9098. (AscGetChipScsiCtrl(iop_base) != 0)) {
  9099. asc_dvc->init_state |= ASC_INIT_RESET_SCSI_DONE;
  9100. AscResetChipAndScsiBus(asc_dvc);
  9101. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  9102. }
  9103. if (AscIsChipHalted(iop_base) == FALSE) {
  9104. asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
  9105. return (warn_code);
  9106. }
  9107. AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
  9108. if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
  9109. asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
  9110. return (warn_code);
  9111. }
  9112. eep_config = (ASCEEP_CONFIG *)&eep_config_buf;
  9113. cfg_msw = AscGetChipCfgMsw(iop_base);
  9114. cfg_lsw = AscGetChipCfgLsw(iop_base);
  9115. if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
  9116. cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  9117. warn_code |= ASC_WARN_CFG_MSW_RECOVER;
  9118. AscSetChipCfgMsw(iop_base, cfg_msw);
  9119. }
  9120. chksum = AscGetEEPConfig(iop_base, eep_config, asc_dvc->bus_type);
  9121. ASC_DBG(1, "chksum 0x%x\n", chksum);
  9122. if (chksum == 0) {
  9123. chksum = 0xaa55;
  9124. }
  9125. if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
  9126. warn_code |= ASC_WARN_AUTO_CONFIG;
  9127. if (asc_dvc->cfg->chip_version == 3) {
  9128. if (eep_config->cfg_lsw != cfg_lsw) {
  9129. warn_code |= ASC_WARN_EEPROM_RECOVER;
  9130. eep_config->cfg_lsw =
  9131. AscGetChipCfgLsw(iop_base);
  9132. }
  9133. if (eep_config->cfg_msw != cfg_msw) {
  9134. warn_code |= ASC_WARN_EEPROM_RECOVER;
  9135. eep_config->cfg_msw =
  9136. AscGetChipCfgMsw(iop_base);
  9137. }
  9138. }
  9139. }
  9140. eep_config->cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  9141. eep_config->cfg_lsw |= ASC_CFG0_HOST_INT_ON;
  9142. ASC_DBG(1, "eep_config->chksum 0x%x\n", eep_config->chksum);
  9143. if (chksum != eep_config->chksum) {
  9144. if (AscGetChipVersion(iop_base, asc_dvc->bus_type) ==
  9145. ASC_CHIP_VER_PCI_ULTRA_3050) {
  9146. ASC_DBG(1, "chksum error ignored; EEPROM-less board\n");
  9147. eep_config->init_sdtr = 0xFF;
  9148. eep_config->disc_enable = 0xFF;
  9149. eep_config->start_motor = 0xFF;
  9150. eep_config->use_cmd_qng = 0;
  9151. eep_config->max_total_qng = 0xF0;
  9152. eep_config->max_tag_qng = 0x20;
  9153. eep_config->cntl = 0xBFFF;
  9154. ASC_EEP_SET_CHIP_ID(eep_config, 7);
  9155. eep_config->no_scam = 0;
  9156. eep_config->adapter_info[0] = 0;
  9157. eep_config->adapter_info[1] = 0;
  9158. eep_config->adapter_info[2] = 0;
  9159. eep_config->adapter_info[3] = 0;
  9160. eep_config->adapter_info[4] = 0;
  9161. /* Indicate EEPROM-less board. */
  9162. eep_config->adapter_info[5] = 0xBB;
  9163. } else {
  9164. ASC_PRINT
  9165. ("AscInitFromEEP: EEPROM checksum error; Will try to re-write EEPROM.\n");
  9166. write_eep = 1;
  9167. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  9168. }
  9169. }
  9170. asc_dvc->cfg->sdtr_enable = eep_config->init_sdtr;
  9171. asc_dvc->cfg->disc_enable = eep_config->disc_enable;
  9172. asc_dvc->cfg->cmd_qng_enabled = eep_config->use_cmd_qng;
  9173. asc_dvc->cfg->isa_dma_speed = ASC_EEP_GET_DMA_SPD(eep_config);
  9174. asc_dvc->start_motor = eep_config->start_motor;
  9175. asc_dvc->dvc_cntl = eep_config->cntl;
  9176. asc_dvc->no_scam = eep_config->no_scam;
  9177. asc_dvc->cfg->adapter_info[0] = eep_config->adapter_info[0];
  9178. asc_dvc->cfg->adapter_info[1] = eep_config->adapter_info[1];
  9179. asc_dvc->cfg->adapter_info[2] = eep_config->adapter_info[2];
  9180. asc_dvc->cfg->adapter_info[3] = eep_config->adapter_info[3];
  9181. asc_dvc->cfg->adapter_info[4] = eep_config->adapter_info[4];
  9182. asc_dvc->cfg->adapter_info[5] = eep_config->adapter_info[5];
  9183. if (!AscTestExternalLram(asc_dvc)) {
  9184. if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) ==
  9185. ASC_IS_PCI_ULTRA)) {
  9186. eep_config->max_total_qng =
  9187. ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG;
  9188. eep_config->max_tag_qng =
  9189. ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG;
  9190. } else {
  9191. eep_config->cfg_msw |= 0x0800;
  9192. cfg_msw |= 0x0800;
  9193. AscSetChipCfgMsw(iop_base, cfg_msw);
  9194. eep_config->max_total_qng = ASC_MAX_PCI_INRAM_TOTAL_QNG;
  9195. eep_config->max_tag_qng = ASC_MAX_INRAM_TAG_QNG;
  9196. }
  9197. } else {
  9198. }
  9199. if (eep_config->max_total_qng < ASC_MIN_TOTAL_QNG) {
  9200. eep_config->max_total_qng = ASC_MIN_TOTAL_QNG;
  9201. }
  9202. if (eep_config->max_total_qng > ASC_MAX_TOTAL_QNG) {
  9203. eep_config->max_total_qng = ASC_MAX_TOTAL_QNG;
  9204. }
  9205. if (eep_config->max_tag_qng > eep_config->max_total_qng) {
  9206. eep_config->max_tag_qng = eep_config->max_total_qng;
  9207. }
  9208. if (eep_config->max_tag_qng < ASC_MIN_TAG_Q_PER_DVC) {
  9209. eep_config->max_tag_qng = ASC_MIN_TAG_Q_PER_DVC;
  9210. }
  9211. asc_dvc->max_total_qng = eep_config->max_total_qng;
  9212. if ((eep_config->use_cmd_qng & eep_config->disc_enable) !=
  9213. eep_config->use_cmd_qng) {
  9214. eep_config->disc_enable = eep_config->use_cmd_qng;
  9215. warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
  9216. }
  9217. ASC_EEP_SET_CHIP_ID(eep_config,
  9218. ASC_EEP_GET_CHIP_ID(eep_config) & ASC_MAX_TID);
  9219. asc_dvc->cfg->chip_scsi_id = ASC_EEP_GET_CHIP_ID(eep_config);
  9220. if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) &&
  9221. !(asc_dvc->dvc_cntl & ASC_CNTL_SDTR_ENABLE_ULTRA)) {
  9222. asc_dvc->min_sdtr_index = ASC_SDTR_ULTRA_PCI_10MB_INDEX;
  9223. }
  9224. for (i = 0; i <= ASC_MAX_TID; i++) {
  9225. asc_dvc->dos_int13_table[i] = eep_config->dos_int13_table[i];
  9226. asc_dvc->cfg->max_tag_qng[i] = eep_config->max_tag_qng;
  9227. asc_dvc->cfg->sdtr_period_offset[i] =
  9228. (uchar)(ASC_DEF_SDTR_OFFSET |
  9229. (asc_dvc->min_sdtr_index << 4));
  9230. }
  9231. eep_config->cfg_msw = AscGetChipCfgMsw(iop_base);
  9232. if (write_eep) {
  9233. if ((i = AscSetEEPConfig(iop_base, eep_config,
  9234. asc_dvc->bus_type)) != 0) {
  9235. ASC_PRINT1
  9236. ("AscInitFromEEP: Failed to re-write EEPROM with %d errors.\n",
  9237. i);
  9238. } else {
  9239. ASC_PRINT
  9240. ("AscInitFromEEP: Successfully re-wrote EEPROM.\n");
  9241. }
  9242. }
  9243. return (warn_code);
  9244. }
  9245. static int __devinit AscInitGetConfig(struct Scsi_Host *shost)
  9246. {
  9247. struct asc_board *board = shost_priv(shost);
  9248. ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
  9249. unsigned short warn_code = 0;
  9250. asc_dvc->init_state = ASC_INIT_STATE_BEG_GET_CFG;
  9251. if (asc_dvc->err_code != 0)
  9252. return asc_dvc->err_code;
  9253. if (AscFindSignature(asc_dvc->iop_base)) {
  9254. warn_code |= AscInitAscDvcVar(asc_dvc);
  9255. warn_code |= AscInitFromEEP(asc_dvc);
  9256. asc_dvc->init_state |= ASC_INIT_STATE_END_GET_CFG;
  9257. if (asc_dvc->scsi_reset_wait > ASC_MAX_SCSI_RESET_WAIT)
  9258. asc_dvc->scsi_reset_wait = ASC_MAX_SCSI_RESET_WAIT;
  9259. } else {
  9260. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  9261. }
  9262. switch (warn_code) {
  9263. case 0: /* No error */
  9264. break;
  9265. case ASC_WARN_IO_PORT_ROTATE:
  9266. shost_printk(KERN_WARNING, shost, "I/O port address "
  9267. "modified\n");
  9268. break;
  9269. case ASC_WARN_AUTO_CONFIG:
  9270. shost_printk(KERN_WARNING, shost, "I/O port increment switch "
  9271. "enabled\n");
  9272. break;
  9273. case ASC_WARN_EEPROM_CHKSUM:
  9274. shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
  9275. break;
  9276. case ASC_WARN_IRQ_MODIFIED:
  9277. shost_printk(KERN_WARNING, shost, "IRQ modified\n");
  9278. break;
  9279. case ASC_WARN_CMD_QNG_CONFLICT:
  9280. shost_printk(KERN_WARNING, shost, "tag queuing enabled w/o "
  9281. "disconnects\n");
  9282. break;
  9283. default:
  9284. shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
  9285. warn_code);
  9286. break;
  9287. }
  9288. if (asc_dvc->err_code != 0)
  9289. shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
  9290. "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
  9291. return asc_dvc->err_code;
  9292. }
  9293. static int __devinit AscInitSetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
  9294. {
  9295. struct asc_board *board = shost_priv(shost);
  9296. ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
  9297. PortAddr iop_base = asc_dvc->iop_base;
  9298. unsigned short cfg_msw;
  9299. unsigned short warn_code = 0;
  9300. asc_dvc->init_state |= ASC_INIT_STATE_BEG_SET_CFG;
  9301. if (asc_dvc->err_code != 0)
  9302. return asc_dvc->err_code;
  9303. if (!AscFindSignature(asc_dvc->iop_base)) {
  9304. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  9305. return asc_dvc->err_code;
  9306. }
  9307. cfg_msw = AscGetChipCfgMsw(iop_base);
  9308. if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
  9309. cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  9310. warn_code |= ASC_WARN_CFG_MSW_RECOVER;
  9311. AscSetChipCfgMsw(iop_base, cfg_msw);
  9312. }
  9313. if ((asc_dvc->cfg->cmd_qng_enabled & asc_dvc->cfg->disc_enable) !=
  9314. asc_dvc->cfg->cmd_qng_enabled) {
  9315. asc_dvc->cfg->disc_enable = asc_dvc->cfg->cmd_qng_enabled;
  9316. warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
  9317. }
  9318. if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
  9319. warn_code |= ASC_WARN_AUTO_CONFIG;
  9320. }
  9321. #ifdef CONFIG_PCI
  9322. if (asc_dvc->bus_type & ASC_IS_PCI) {
  9323. cfg_msw &= 0xFFC0;
  9324. AscSetChipCfgMsw(iop_base, cfg_msw);
  9325. if ((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) {
  9326. } else {
  9327. if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
  9328. (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
  9329. asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_IF_NOT_DWB;
  9330. asc_dvc->bug_fix_cntl |=
  9331. ASC_BUG_FIX_ASYN_USE_SYN;
  9332. }
  9333. }
  9334. } else
  9335. #endif /* CONFIG_PCI */
  9336. if (asc_dvc->bus_type == ASC_IS_ISAPNP) {
  9337. if (AscGetChipVersion(iop_base, asc_dvc->bus_type)
  9338. == ASC_CHIP_VER_ASYN_BUG) {
  9339. asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_ASYN_USE_SYN;
  9340. }
  9341. }
  9342. if (AscSetChipScsiID(iop_base, asc_dvc->cfg->chip_scsi_id) !=
  9343. asc_dvc->cfg->chip_scsi_id) {
  9344. asc_dvc->err_code |= ASC_IERR_SET_SCSI_ID;
  9345. }
  9346. #ifdef CONFIG_ISA
  9347. if (asc_dvc->bus_type & ASC_IS_ISA) {
  9348. AscSetIsaDmaChannel(iop_base, asc_dvc->cfg->isa_dma_channel);
  9349. AscSetIsaDmaSpeed(iop_base, asc_dvc->cfg->isa_dma_speed);
  9350. }
  9351. #endif /* CONFIG_ISA */
  9352. asc_dvc->init_state |= ASC_INIT_STATE_END_SET_CFG;
  9353. switch (warn_code) {
  9354. case 0: /* No error. */
  9355. break;
  9356. case ASC_WARN_IO_PORT_ROTATE:
  9357. shost_printk(KERN_WARNING, shost, "I/O port address "
  9358. "modified\n");
  9359. break;
  9360. case ASC_WARN_AUTO_CONFIG:
  9361. shost_printk(KERN_WARNING, shost, "I/O port increment switch "
  9362. "enabled\n");
  9363. break;
  9364. case ASC_WARN_EEPROM_CHKSUM:
  9365. shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
  9366. break;
  9367. case ASC_WARN_IRQ_MODIFIED:
  9368. shost_printk(KERN_WARNING, shost, "IRQ modified\n");
  9369. break;
  9370. case ASC_WARN_CMD_QNG_CONFLICT:
  9371. shost_printk(KERN_WARNING, shost, "tag queuing w/o "
  9372. "disconnects\n");
  9373. break;
  9374. default:
  9375. shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
  9376. warn_code);
  9377. break;
  9378. }
  9379. if (asc_dvc->err_code != 0)
  9380. shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
  9381. "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
  9382. return asc_dvc->err_code;
  9383. }
  9384. /*
  9385. * EEPROM Configuration.
  9386. *
  9387. * All drivers should use this structure to set the default EEPROM
  9388. * configuration. The BIOS now uses this structure when it is built.
  9389. * Additional structure information can be found in a_condor.h where
  9390. * the structure is defined.
  9391. *
  9392. * The *_Field_IsChar structs are needed to correct for endianness.
  9393. * These values are read from the board 16 bits at a time directly
  9394. * into the structs. Because some fields are char, the values will be
  9395. * in the wrong order. The *_Field_IsChar tells when to flip the
  9396. * bytes. Data read and written to PCI memory is automatically swapped
  9397. * on big-endian platforms so char fields read as words are actually being
  9398. * unswapped on big-endian platforms.
  9399. */
  9400. static ADVEEP_3550_CONFIG Default_3550_EEPROM_Config __devinitdata = {
  9401. ADV_EEPROM_BIOS_ENABLE, /* cfg_lsw */
  9402. 0x0000, /* cfg_msw */
  9403. 0xFFFF, /* disc_enable */
  9404. 0xFFFF, /* wdtr_able */
  9405. 0xFFFF, /* sdtr_able */
  9406. 0xFFFF, /* start_motor */
  9407. 0xFFFF, /* tagqng_able */
  9408. 0xFFFF, /* bios_scan */
  9409. 0, /* scam_tolerant */
  9410. 7, /* adapter_scsi_id */
  9411. 0, /* bios_boot_delay */
  9412. 3, /* scsi_reset_delay */
  9413. 0, /* bios_id_lun */
  9414. 0, /* termination */
  9415. 0, /* reserved1 */
  9416. 0xFFE7, /* bios_ctrl */
  9417. 0xFFFF, /* ultra_able */
  9418. 0, /* reserved2 */
  9419. ASC_DEF_MAX_HOST_QNG, /* max_host_qng */
  9420. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  9421. 0, /* dvc_cntl */
  9422. 0, /* bug_fix */
  9423. 0, /* serial_number_word1 */
  9424. 0, /* serial_number_word2 */
  9425. 0, /* serial_number_word3 */
  9426. 0, /* check_sum */
  9427. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  9428. , /* oem_name[16] */
  9429. 0, /* dvc_err_code */
  9430. 0, /* adv_err_code */
  9431. 0, /* adv_err_addr */
  9432. 0, /* saved_dvc_err_code */
  9433. 0, /* saved_adv_err_code */
  9434. 0, /* saved_adv_err_addr */
  9435. 0 /* num_of_err */
  9436. };
  9437. static ADVEEP_3550_CONFIG ADVEEP_3550_Config_Field_IsChar __devinitdata = {
  9438. 0, /* cfg_lsw */
  9439. 0, /* cfg_msw */
  9440. 0, /* -disc_enable */
  9441. 0, /* wdtr_able */
  9442. 0, /* sdtr_able */
  9443. 0, /* start_motor */
  9444. 0, /* tagqng_able */
  9445. 0, /* bios_scan */
  9446. 0, /* scam_tolerant */
  9447. 1, /* adapter_scsi_id */
  9448. 1, /* bios_boot_delay */
  9449. 1, /* scsi_reset_delay */
  9450. 1, /* bios_id_lun */
  9451. 1, /* termination */
  9452. 1, /* reserved1 */
  9453. 0, /* bios_ctrl */
  9454. 0, /* ultra_able */
  9455. 0, /* reserved2 */
  9456. 1, /* max_host_qng */
  9457. 1, /* max_dvc_qng */
  9458. 0, /* dvc_cntl */
  9459. 0, /* bug_fix */
  9460. 0, /* serial_number_word1 */
  9461. 0, /* serial_number_word2 */
  9462. 0, /* serial_number_word3 */
  9463. 0, /* check_sum */
  9464. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  9465. , /* oem_name[16] */
  9466. 0, /* dvc_err_code */
  9467. 0, /* adv_err_code */
  9468. 0, /* adv_err_addr */
  9469. 0, /* saved_dvc_err_code */
  9470. 0, /* saved_adv_err_code */
  9471. 0, /* saved_adv_err_addr */
  9472. 0 /* num_of_err */
  9473. };
  9474. static ADVEEP_38C0800_CONFIG Default_38C0800_EEPROM_Config __devinitdata = {
  9475. ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
  9476. 0x0000, /* 01 cfg_msw */
  9477. 0xFFFF, /* 02 disc_enable */
  9478. 0xFFFF, /* 03 wdtr_able */
  9479. 0x4444, /* 04 sdtr_speed1 */
  9480. 0xFFFF, /* 05 start_motor */
  9481. 0xFFFF, /* 06 tagqng_able */
  9482. 0xFFFF, /* 07 bios_scan */
  9483. 0, /* 08 scam_tolerant */
  9484. 7, /* 09 adapter_scsi_id */
  9485. 0, /* bios_boot_delay */
  9486. 3, /* 10 scsi_reset_delay */
  9487. 0, /* bios_id_lun */
  9488. 0, /* 11 termination_se */
  9489. 0, /* termination_lvd */
  9490. 0xFFE7, /* 12 bios_ctrl */
  9491. 0x4444, /* 13 sdtr_speed2 */
  9492. 0x4444, /* 14 sdtr_speed3 */
  9493. ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
  9494. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  9495. 0, /* 16 dvc_cntl */
  9496. 0x4444, /* 17 sdtr_speed4 */
  9497. 0, /* 18 serial_number_word1 */
  9498. 0, /* 19 serial_number_word2 */
  9499. 0, /* 20 serial_number_word3 */
  9500. 0, /* 21 check_sum */
  9501. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  9502. , /* 22-29 oem_name[16] */
  9503. 0, /* 30 dvc_err_code */
  9504. 0, /* 31 adv_err_code */
  9505. 0, /* 32 adv_err_addr */
  9506. 0, /* 33 saved_dvc_err_code */
  9507. 0, /* 34 saved_adv_err_code */
  9508. 0, /* 35 saved_adv_err_addr */
  9509. 0, /* 36 reserved */
  9510. 0, /* 37 reserved */
  9511. 0, /* 38 reserved */
  9512. 0, /* 39 reserved */
  9513. 0, /* 40 reserved */
  9514. 0, /* 41 reserved */
  9515. 0, /* 42 reserved */
  9516. 0, /* 43 reserved */
  9517. 0, /* 44 reserved */
  9518. 0, /* 45 reserved */
  9519. 0, /* 46 reserved */
  9520. 0, /* 47 reserved */
  9521. 0, /* 48 reserved */
  9522. 0, /* 49 reserved */
  9523. 0, /* 50 reserved */
  9524. 0, /* 51 reserved */
  9525. 0, /* 52 reserved */
  9526. 0, /* 53 reserved */
  9527. 0, /* 54 reserved */
  9528. 0, /* 55 reserved */
  9529. 0, /* 56 cisptr_lsw */
  9530. 0, /* 57 cisprt_msw */
  9531. PCI_VENDOR_ID_ASP, /* 58 subsysvid */
  9532. PCI_DEVICE_ID_38C0800_REV1, /* 59 subsysid */
  9533. 0, /* 60 reserved */
  9534. 0, /* 61 reserved */
  9535. 0, /* 62 reserved */
  9536. 0 /* 63 reserved */
  9537. };
  9538. static ADVEEP_38C0800_CONFIG ADVEEP_38C0800_Config_Field_IsChar __devinitdata = {
  9539. 0, /* 00 cfg_lsw */
  9540. 0, /* 01 cfg_msw */
  9541. 0, /* 02 disc_enable */
  9542. 0, /* 03 wdtr_able */
  9543. 0, /* 04 sdtr_speed1 */
  9544. 0, /* 05 start_motor */
  9545. 0, /* 06 tagqng_able */
  9546. 0, /* 07 bios_scan */
  9547. 0, /* 08 scam_tolerant */
  9548. 1, /* 09 adapter_scsi_id */
  9549. 1, /* bios_boot_delay */
  9550. 1, /* 10 scsi_reset_delay */
  9551. 1, /* bios_id_lun */
  9552. 1, /* 11 termination_se */
  9553. 1, /* termination_lvd */
  9554. 0, /* 12 bios_ctrl */
  9555. 0, /* 13 sdtr_speed2 */
  9556. 0, /* 14 sdtr_speed3 */
  9557. 1, /* 15 max_host_qng */
  9558. 1, /* max_dvc_qng */
  9559. 0, /* 16 dvc_cntl */
  9560. 0, /* 17 sdtr_speed4 */
  9561. 0, /* 18 serial_number_word1 */
  9562. 0, /* 19 serial_number_word2 */
  9563. 0, /* 20 serial_number_word3 */
  9564. 0, /* 21 check_sum */
  9565. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  9566. , /* 22-29 oem_name[16] */
  9567. 0, /* 30 dvc_err_code */
  9568. 0, /* 31 adv_err_code */
  9569. 0, /* 32 adv_err_addr */
  9570. 0, /* 33 saved_dvc_err_code */
  9571. 0, /* 34 saved_adv_err_code */
  9572. 0, /* 35 saved_adv_err_addr */
  9573. 0, /* 36 reserved */
  9574. 0, /* 37 reserved */
  9575. 0, /* 38 reserved */
  9576. 0, /* 39 reserved */
  9577. 0, /* 40 reserved */
  9578. 0, /* 41 reserved */
  9579. 0, /* 42 reserved */
  9580. 0, /* 43 reserved */
  9581. 0, /* 44 reserved */
  9582. 0, /* 45 reserved */
  9583. 0, /* 46 reserved */
  9584. 0, /* 47 reserved */
  9585. 0, /* 48 reserved */
  9586. 0, /* 49 reserved */
  9587. 0, /* 50 reserved */
  9588. 0, /* 51 reserved */
  9589. 0, /* 52 reserved */
  9590. 0, /* 53 reserved */
  9591. 0, /* 54 reserved */
  9592. 0, /* 55 reserved */
  9593. 0, /* 56 cisptr_lsw */
  9594. 0, /* 57 cisprt_msw */
  9595. 0, /* 58 subsysvid */
  9596. 0, /* 59 subsysid */
  9597. 0, /* 60 reserved */
  9598. 0, /* 61 reserved */
  9599. 0, /* 62 reserved */
  9600. 0 /* 63 reserved */
  9601. };
  9602. static ADVEEP_38C1600_CONFIG Default_38C1600_EEPROM_Config __devinitdata = {
  9603. ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
  9604. 0x0000, /* 01 cfg_msw */
  9605. 0xFFFF, /* 02 disc_enable */
  9606. 0xFFFF, /* 03 wdtr_able */
  9607. 0x5555, /* 04 sdtr_speed1 */
  9608. 0xFFFF, /* 05 start_motor */
  9609. 0xFFFF, /* 06 tagqng_able */
  9610. 0xFFFF, /* 07 bios_scan */
  9611. 0, /* 08 scam_tolerant */
  9612. 7, /* 09 adapter_scsi_id */
  9613. 0, /* bios_boot_delay */
  9614. 3, /* 10 scsi_reset_delay */
  9615. 0, /* bios_id_lun */
  9616. 0, /* 11 termination_se */
  9617. 0, /* termination_lvd */
  9618. 0xFFE7, /* 12 bios_ctrl */
  9619. 0x5555, /* 13 sdtr_speed2 */
  9620. 0x5555, /* 14 sdtr_speed3 */
  9621. ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
  9622. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  9623. 0, /* 16 dvc_cntl */
  9624. 0x5555, /* 17 sdtr_speed4 */
  9625. 0, /* 18 serial_number_word1 */
  9626. 0, /* 19 serial_number_word2 */
  9627. 0, /* 20 serial_number_word3 */
  9628. 0, /* 21 check_sum */
  9629. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  9630. , /* 22-29 oem_name[16] */
  9631. 0, /* 30 dvc_err_code */
  9632. 0, /* 31 adv_err_code */
  9633. 0, /* 32 adv_err_addr */
  9634. 0, /* 33 saved_dvc_err_code */
  9635. 0, /* 34 saved_adv_err_code */
  9636. 0, /* 35 saved_adv_err_addr */
  9637. 0, /* 36 reserved */
  9638. 0, /* 37 reserved */
  9639. 0, /* 38 reserved */
  9640. 0, /* 39 reserved */
  9641. 0, /* 40 reserved */
  9642. 0, /* 41 reserved */
  9643. 0, /* 42 reserved */
  9644. 0, /* 43 reserved */
  9645. 0, /* 44 reserved */
  9646. 0, /* 45 reserved */
  9647. 0, /* 46 reserved */
  9648. 0, /* 47 reserved */
  9649. 0, /* 48 reserved */
  9650. 0, /* 49 reserved */
  9651. 0, /* 50 reserved */
  9652. 0, /* 51 reserved */
  9653. 0, /* 52 reserved */
  9654. 0, /* 53 reserved */
  9655. 0, /* 54 reserved */
  9656. 0, /* 55 reserved */
  9657. 0, /* 56 cisptr_lsw */
  9658. 0, /* 57 cisprt_msw */
  9659. PCI_VENDOR_ID_ASP, /* 58 subsysvid */
  9660. PCI_DEVICE_ID_38C1600_REV1, /* 59 subsysid */
  9661. 0, /* 60 reserved */
  9662. 0, /* 61 reserved */
  9663. 0, /* 62 reserved */
  9664. 0 /* 63 reserved */
  9665. };
  9666. static ADVEEP_38C1600_CONFIG ADVEEP_38C1600_Config_Field_IsChar __devinitdata = {
  9667. 0, /* 00 cfg_lsw */
  9668. 0, /* 01 cfg_msw */
  9669. 0, /* 02 disc_enable */
  9670. 0, /* 03 wdtr_able */
  9671. 0, /* 04 sdtr_speed1 */
  9672. 0, /* 05 start_motor */
  9673. 0, /* 06 tagqng_able */
  9674. 0, /* 07 bios_scan */
  9675. 0, /* 08 scam_tolerant */
  9676. 1, /* 09 adapter_scsi_id */
  9677. 1, /* bios_boot_delay */
  9678. 1, /* 10 scsi_reset_delay */
  9679. 1, /* bios_id_lun */
  9680. 1, /* 11 termination_se */
  9681. 1, /* termination_lvd */
  9682. 0, /* 12 bios_ctrl */
  9683. 0, /* 13 sdtr_speed2 */
  9684. 0, /* 14 sdtr_speed3 */
  9685. 1, /* 15 max_host_qng */
  9686. 1, /* max_dvc_qng */
  9687. 0, /* 16 dvc_cntl */
  9688. 0, /* 17 sdtr_speed4 */
  9689. 0, /* 18 serial_number_word1 */
  9690. 0, /* 19 serial_number_word2 */
  9691. 0, /* 20 serial_number_word3 */
  9692. 0, /* 21 check_sum */
  9693. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  9694. , /* 22-29 oem_name[16] */
  9695. 0, /* 30 dvc_err_code */
  9696. 0, /* 31 adv_err_code */
  9697. 0, /* 32 adv_err_addr */
  9698. 0, /* 33 saved_dvc_err_code */
  9699. 0, /* 34 saved_adv_err_code */
  9700. 0, /* 35 saved_adv_err_addr */
  9701. 0, /* 36 reserved */
  9702. 0, /* 37 reserved */
  9703. 0, /* 38 reserved */
  9704. 0, /* 39 reserved */
  9705. 0, /* 40 reserved */
  9706. 0, /* 41 reserved */
  9707. 0, /* 42 reserved */
  9708. 0, /* 43 reserved */
  9709. 0, /* 44 reserved */
  9710. 0, /* 45 reserved */
  9711. 0, /* 46 reserved */
  9712. 0, /* 47 reserved */
  9713. 0, /* 48 reserved */
  9714. 0, /* 49 reserved */
  9715. 0, /* 50 reserved */
  9716. 0, /* 51 reserved */
  9717. 0, /* 52 reserved */
  9718. 0, /* 53 reserved */
  9719. 0, /* 54 reserved */
  9720. 0, /* 55 reserved */
  9721. 0, /* 56 cisptr_lsw */
  9722. 0, /* 57 cisprt_msw */
  9723. 0, /* 58 subsysvid */
  9724. 0, /* 59 subsysid */
  9725. 0, /* 60 reserved */
  9726. 0, /* 61 reserved */
  9727. 0, /* 62 reserved */
  9728. 0 /* 63 reserved */
  9729. };
  9730. #ifdef CONFIG_PCI
  9731. /*
  9732. * Wait for EEPROM command to complete
  9733. */
  9734. static void __devinit AdvWaitEEPCmd(AdvPortAddr iop_base)
  9735. {
  9736. int eep_delay_ms;
  9737. for (eep_delay_ms = 0; eep_delay_ms < ADV_EEP_DELAY_MS; eep_delay_ms++) {
  9738. if (AdvReadWordRegister(iop_base, IOPW_EE_CMD) &
  9739. ASC_EEP_CMD_DONE) {
  9740. break;
  9741. }
  9742. mdelay(1);
  9743. }
  9744. if ((AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE) ==
  9745. 0)
  9746. BUG();
  9747. }
  9748. /*
  9749. * Read the EEPROM from specified location
  9750. */
  9751. static ushort __devinit AdvReadEEPWord(AdvPortAddr iop_base, int eep_word_addr)
  9752. {
  9753. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9754. ASC_EEP_CMD_READ | eep_word_addr);
  9755. AdvWaitEEPCmd(iop_base);
  9756. return AdvReadWordRegister(iop_base, IOPW_EE_DATA);
  9757. }
  9758. /*
  9759. * Write the EEPROM from 'cfg_buf'.
  9760. */
  9761. static void __devinit
  9762. AdvSet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf)
  9763. {
  9764. ushort *wbuf;
  9765. ushort addr, chksum;
  9766. ushort *charfields;
  9767. wbuf = (ushort *)cfg_buf;
  9768. charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
  9769. chksum = 0;
  9770. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  9771. AdvWaitEEPCmd(iop_base);
  9772. /*
  9773. * Write EEPROM from word 0 to word 20.
  9774. */
  9775. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  9776. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  9777. ushort word;
  9778. if (*charfields++) {
  9779. word = cpu_to_le16(*wbuf);
  9780. } else {
  9781. word = *wbuf;
  9782. }
  9783. chksum += *wbuf; /* Checksum is calculated from word values. */
  9784. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9785. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9786. ASC_EEP_CMD_WRITE | addr);
  9787. AdvWaitEEPCmd(iop_base);
  9788. mdelay(ADV_EEP_DELAY_MS);
  9789. }
  9790. /*
  9791. * Write EEPROM checksum at word 21.
  9792. */
  9793. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  9794. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  9795. AdvWaitEEPCmd(iop_base);
  9796. wbuf++;
  9797. charfields++;
  9798. /*
  9799. * Write EEPROM OEM name at words 22 to 29.
  9800. */
  9801. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  9802. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  9803. ushort word;
  9804. if (*charfields++) {
  9805. word = cpu_to_le16(*wbuf);
  9806. } else {
  9807. word = *wbuf;
  9808. }
  9809. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9810. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9811. ASC_EEP_CMD_WRITE | addr);
  9812. AdvWaitEEPCmd(iop_base);
  9813. }
  9814. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  9815. AdvWaitEEPCmd(iop_base);
  9816. }
  9817. /*
  9818. * Write the EEPROM from 'cfg_buf'.
  9819. */
  9820. static void __devinit
  9821. AdvSet38C0800EEPConfig(AdvPortAddr iop_base, ADVEEP_38C0800_CONFIG *cfg_buf)
  9822. {
  9823. ushort *wbuf;
  9824. ushort *charfields;
  9825. ushort addr, chksum;
  9826. wbuf = (ushort *)cfg_buf;
  9827. charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
  9828. chksum = 0;
  9829. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  9830. AdvWaitEEPCmd(iop_base);
  9831. /*
  9832. * Write EEPROM from word 0 to word 20.
  9833. */
  9834. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  9835. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  9836. ushort word;
  9837. if (*charfields++) {
  9838. word = cpu_to_le16(*wbuf);
  9839. } else {
  9840. word = *wbuf;
  9841. }
  9842. chksum += *wbuf; /* Checksum is calculated from word values. */
  9843. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9844. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9845. ASC_EEP_CMD_WRITE | addr);
  9846. AdvWaitEEPCmd(iop_base);
  9847. mdelay(ADV_EEP_DELAY_MS);
  9848. }
  9849. /*
  9850. * Write EEPROM checksum at word 21.
  9851. */
  9852. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  9853. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  9854. AdvWaitEEPCmd(iop_base);
  9855. wbuf++;
  9856. charfields++;
  9857. /*
  9858. * Write EEPROM OEM name at words 22 to 29.
  9859. */
  9860. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  9861. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  9862. ushort word;
  9863. if (*charfields++) {
  9864. word = cpu_to_le16(*wbuf);
  9865. } else {
  9866. word = *wbuf;
  9867. }
  9868. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9869. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9870. ASC_EEP_CMD_WRITE | addr);
  9871. AdvWaitEEPCmd(iop_base);
  9872. }
  9873. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  9874. AdvWaitEEPCmd(iop_base);
  9875. }
  9876. /*
  9877. * Write the EEPROM from 'cfg_buf'.
  9878. */
  9879. static void __devinit
  9880. AdvSet38C1600EEPConfig(AdvPortAddr iop_base, ADVEEP_38C1600_CONFIG *cfg_buf)
  9881. {
  9882. ushort *wbuf;
  9883. ushort *charfields;
  9884. ushort addr, chksum;
  9885. wbuf = (ushort *)cfg_buf;
  9886. charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
  9887. chksum = 0;
  9888. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  9889. AdvWaitEEPCmd(iop_base);
  9890. /*
  9891. * Write EEPROM from word 0 to word 20.
  9892. */
  9893. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  9894. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  9895. ushort word;
  9896. if (*charfields++) {
  9897. word = cpu_to_le16(*wbuf);
  9898. } else {
  9899. word = *wbuf;
  9900. }
  9901. chksum += *wbuf; /* Checksum is calculated from word values. */
  9902. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9903. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9904. ASC_EEP_CMD_WRITE | addr);
  9905. AdvWaitEEPCmd(iop_base);
  9906. mdelay(ADV_EEP_DELAY_MS);
  9907. }
  9908. /*
  9909. * Write EEPROM checksum at word 21.
  9910. */
  9911. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  9912. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  9913. AdvWaitEEPCmd(iop_base);
  9914. wbuf++;
  9915. charfields++;
  9916. /*
  9917. * Write EEPROM OEM name at words 22 to 29.
  9918. */
  9919. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  9920. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  9921. ushort word;
  9922. if (*charfields++) {
  9923. word = cpu_to_le16(*wbuf);
  9924. } else {
  9925. word = *wbuf;
  9926. }
  9927. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9928. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9929. ASC_EEP_CMD_WRITE | addr);
  9930. AdvWaitEEPCmd(iop_base);
  9931. }
  9932. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  9933. AdvWaitEEPCmd(iop_base);
  9934. }
  9935. /*
  9936. * Read EEPROM configuration into the specified buffer.
  9937. *
  9938. * Return a checksum based on the EEPROM configuration read.
  9939. */
  9940. static ushort __devinit
  9941. AdvGet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf)
  9942. {
  9943. ushort wval, chksum;
  9944. ushort *wbuf;
  9945. int eep_addr;
  9946. ushort *charfields;
  9947. charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
  9948. wbuf = (ushort *)cfg_buf;
  9949. chksum = 0;
  9950. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  9951. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  9952. wval = AdvReadEEPWord(iop_base, eep_addr);
  9953. chksum += wval; /* Checksum is calculated from word values. */
  9954. if (*charfields++) {
  9955. *wbuf = le16_to_cpu(wval);
  9956. } else {
  9957. *wbuf = wval;
  9958. }
  9959. }
  9960. /* Read checksum word. */
  9961. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9962. wbuf++;
  9963. charfields++;
  9964. /* Read rest of EEPROM not covered by the checksum. */
  9965. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  9966. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  9967. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9968. if (*charfields++) {
  9969. *wbuf = le16_to_cpu(*wbuf);
  9970. }
  9971. }
  9972. return chksum;
  9973. }
  9974. /*
  9975. * Read EEPROM configuration into the specified buffer.
  9976. *
  9977. * Return a checksum based on the EEPROM configuration read.
  9978. */
  9979. static ushort __devinit
  9980. AdvGet38C0800EEPConfig(AdvPortAddr iop_base, ADVEEP_38C0800_CONFIG *cfg_buf)
  9981. {
  9982. ushort wval, chksum;
  9983. ushort *wbuf;
  9984. int eep_addr;
  9985. ushort *charfields;
  9986. charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
  9987. wbuf = (ushort *)cfg_buf;
  9988. chksum = 0;
  9989. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  9990. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  9991. wval = AdvReadEEPWord(iop_base, eep_addr);
  9992. chksum += wval; /* Checksum is calculated from word values. */
  9993. if (*charfields++) {
  9994. *wbuf = le16_to_cpu(wval);
  9995. } else {
  9996. *wbuf = wval;
  9997. }
  9998. }
  9999. /* Read checksum word. */
  10000. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  10001. wbuf++;
  10002. charfields++;
  10003. /* Read rest of EEPROM not covered by the checksum. */
  10004. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  10005. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  10006. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  10007. if (*charfields++) {
  10008. *wbuf = le16_to_cpu(*wbuf);
  10009. }
  10010. }
  10011. return chksum;
  10012. }
  10013. /*
  10014. * Read EEPROM configuration into the specified buffer.
  10015. *
  10016. * Return a checksum based on the EEPROM configuration read.
  10017. */
  10018. static ushort __devinit
  10019. AdvGet38C1600EEPConfig(AdvPortAddr iop_base, ADVEEP_38C1600_CONFIG *cfg_buf)
  10020. {
  10021. ushort wval, chksum;
  10022. ushort *wbuf;
  10023. int eep_addr;
  10024. ushort *charfields;
  10025. charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
  10026. wbuf = (ushort *)cfg_buf;
  10027. chksum = 0;
  10028. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  10029. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  10030. wval = AdvReadEEPWord(iop_base, eep_addr);
  10031. chksum += wval; /* Checksum is calculated from word values. */
  10032. if (*charfields++) {
  10033. *wbuf = le16_to_cpu(wval);
  10034. } else {
  10035. *wbuf = wval;
  10036. }
  10037. }
  10038. /* Read checksum word. */
  10039. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  10040. wbuf++;
  10041. charfields++;
  10042. /* Read rest of EEPROM not covered by the checksum. */
  10043. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  10044. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  10045. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  10046. if (*charfields++) {
  10047. *wbuf = le16_to_cpu(*wbuf);
  10048. }
  10049. }
  10050. return chksum;
  10051. }
  10052. /*
  10053. * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
  10054. * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
  10055. * all of this is done.
  10056. *
  10057. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  10058. *
  10059. * For a non-fatal error return a warning code. If there are no warnings
  10060. * then 0 is returned.
  10061. *
  10062. * Note: Chip is stopped on entry.
  10063. */
  10064. static int __devinit AdvInitFrom3550EEP(ADV_DVC_VAR *asc_dvc)
  10065. {
  10066. AdvPortAddr iop_base;
  10067. ushort warn_code;
  10068. ADVEEP_3550_CONFIG eep_config;
  10069. iop_base = asc_dvc->iop_base;
  10070. warn_code = 0;
  10071. /*
  10072. * Read the board's EEPROM configuration.
  10073. *
  10074. * Set default values if a bad checksum is found.
  10075. */
  10076. if (AdvGet3550EEPConfig(iop_base, &eep_config) != eep_config.check_sum) {
  10077. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  10078. /*
  10079. * Set EEPROM default values.
  10080. */
  10081. memcpy(&eep_config, &Default_3550_EEPROM_Config,
  10082. sizeof(ADVEEP_3550_CONFIG));
  10083. /*
  10084. * Assume the 6 byte board serial number that was read from
  10085. * EEPROM is correct even if the EEPROM checksum failed.
  10086. */
  10087. eep_config.serial_number_word3 =
  10088. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  10089. eep_config.serial_number_word2 =
  10090. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  10091. eep_config.serial_number_word1 =
  10092. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  10093. AdvSet3550EEPConfig(iop_base, &eep_config);
  10094. }
  10095. /*
  10096. * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
  10097. * EEPROM configuration that was read.
  10098. *
  10099. * This is the mapping of EEPROM fields to Adv Library fields.
  10100. */
  10101. asc_dvc->wdtr_able = eep_config.wdtr_able;
  10102. asc_dvc->sdtr_able = eep_config.sdtr_able;
  10103. asc_dvc->ultra_able = eep_config.ultra_able;
  10104. asc_dvc->tagqng_able = eep_config.tagqng_able;
  10105. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  10106. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10107. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10108. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
  10109. asc_dvc->start_motor = eep_config.start_motor;
  10110. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  10111. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  10112. asc_dvc->no_scam = eep_config.scam_tolerant;
  10113. asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
  10114. asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
  10115. asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
  10116. /*
  10117. * Set the host maximum queuing (max. 253, min. 16) and the per device
  10118. * maximum queuing (max. 63, min. 4).
  10119. */
  10120. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  10121. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10122. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  10123. /* If the value is zero, assume it is uninitialized. */
  10124. if (eep_config.max_host_qng == 0) {
  10125. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10126. } else {
  10127. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  10128. }
  10129. }
  10130. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  10131. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10132. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  10133. /* If the value is zero, assume it is uninitialized. */
  10134. if (eep_config.max_dvc_qng == 0) {
  10135. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10136. } else {
  10137. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  10138. }
  10139. }
  10140. /*
  10141. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  10142. * set 'max_dvc_qng' to 'max_host_qng'.
  10143. */
  10144. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  10145. eep_config.max_dvc_qng = eep_config.max_host_qng;
  10146. }
  10147. /*
  10148. * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
  10149. * values based on possibly adjusted EEPROM values.
  10150. */
  10151. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10152. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10153. /*
  10154. * If the EEPROM 'termination' field is set to automatic (0), then set
  10155. * the ADV_DVC_CFG 'termination' field to automatic also.
  10156. *
  10157. * If the termination is specified with a non-zero 'termination'
  10158. * value check that a legal value is set and set the ADV_DVC_CFG
  10159. * 'termination' field appropriately.
  10160. */
  10161. if (eep_config.termination == 0) {
  10162. asc_dvc->cfg->termination = 0; /* auto termination */
  10163. } else {
  10164. /* Enable manual control with low off / high off. */
  10165. if (eep_config.termination == 1) {
  10166. asc_dvc->cfg->termination = TERM_CTL_SEL;
  10167. /* Enable manual control with low off / high on. */
  10168. } else if (eep_config.termination == 2) {
  10169. asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H;
  10170. /* Enable manual control with low on / high on. */
  10171. } else if (eep_config.termination == 3) {
  10172. asc_dvc->cfg->termination =
  10173. TERM_CTL_SEL | TERM_CTL_H | TERM_CTL_L;
  10174. } else {
  10175. /*
  10176. * The EEPROM 'termination' field contains a bad value. Use
  10177. * automatic termination instead.
  10178. */
  10179. asc_dvc->cfg->termination = 0;
  10180. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10181. }
  10182. }
  10183. return warn_code;
  10184. }
  10185. /*
  10186. * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
  10187. * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
  10188. * all of this is done.
  10189. *
  10190. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  10191. *
  10192. * For a non-fatal error return a warning code. If there are no warnings
  10193. * then 0 is returned.
  10194. *
  10195. * Note: Chip is stopped on entry.
  10196. */
  10197. static int __devinit AdvInitFrom38C0800EEP(ADV_DVC_VAR *asc_dvc)
  10198. {
  10199. AdvPortAddr iop_base;
  10200. ushort warn_code;
  10201. ADVEEP_38C0800_CONFIG eep_config;
  10202. uchar tid, termination;
  10203. ushort sdtr_speed = 0;
  10204. iop_base = asc_dvc->iop_base;
  10205. warn_code = 0;
  10206. /*
  10207. * Read the board's EEPROM configuration.
  10208. *
  10209. * Set default values if a bad checksum is found.
  10210. */
  10211. if (AdvGet38C0800EEPConfig(iop_base, &eep_config) !=
  10212. eep_config.check_sum) {
  10213. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  10214. /*
  10215. * Set EEPROM default values.
  10216. */
  10217. memcpy(&eep_config, &Default_38C0800_EEPROM_Config,
  10218. sizeof(ADVEEP_38C0800_CONFIG));
  10219. /*
  10220. * Assume the 6 byte board serial number that was read from
  10221. * EEPROM is correct even if the EEPROM checksum failed.
  10222. */
  10223. eep_config.serial_number_word3 =
  10224. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  10225. eep_config.serial_number_word2 =
  10226. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  10227. eep_config.serial_number_word1 =
  10228. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  10229. AdvSet38C0800EEPConfig(iop_base, &eep_config);
  10230. }
  10231. /*
  10232. * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
  10233. * EEPROM configuration that was read.
  10234. *
  10235. * This is the mapping of EEPROM fields to Adv Library fields.
  10236. */
  10237. asc_dvc->wdtr_able = eep_config.wdtr_able;
  10238. asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
  10239. asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
  10240. asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
  10241. asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
  10242. asc_dvc->tagqng_able = eep_config.tagqng_able;
  10243. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  10244. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10245. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10246. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
  10247. asc_dvc->start_motor = eep_config.start_motor;
  10248. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  10249. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  10250. asc_dvc->no_scam = eep_config.scam_tolerant;
  10251. asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
  10252. asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
  10253. asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
  10254. /*
  10255. * For every Target ID if any of its 'sdtr_speed[1234]' bits
  10256. * are set, then set an 'sdtr_able' bit for it.
  10257. */
  10258. asc_dvc->sdtr_able = 0;
  10259. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  10260. if (tid == 0) {
  10261. sdtr_speed = asc_dvc->sdtr_speed1;
  10262. } else if (tid == 4) {
  10263. sdtr_speed = asc_dvc->sdtr_speed2;
  10264. } else if (tid == 8) {
  10265. sdtr_speed = asc_dvc->sdtr_speed3;
  10266. } else if (tid == 12) {
  10267. sdtr_speed = asc_dvc->sdtr_speed4;
  10268. }
  10269. if (sdtr_speed & ADV_MAX_TID) {
  10270. asc_dvc->sdtr_able |= (1 << tid);
  10271. }
  10272. sdtr_speed >>= 4;
  10273. }
  10274. /*
  10275. * Set the host maximum queuing (max. 253, min. 16) and the per device
  10276. * maximum queuing (max. 63, min. 4).
  10277. */
  10278. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  10279. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10280. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  10281. /* If the value is zero, assume it is uninitialized. */
  10282. if (eep_config.max_host_qng == 0) {
  10283. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10284. } else {
  10285. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  10286. }
  10287. }
  10288. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  10289. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10290. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  10291. /* If the value is zero, assume it is uninitialized. */
  10292. if (eep_config.max_dvc_qng == 0) {
  10293. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10294. } else {
  10295. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  10296. }
  10297. }
  10298. /*
  10299. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  10300. * set 'max_dvc_qng' to 'max_host_qng'.
  10301. */
  10302. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  10303. eep_config.max_dvc_qng = eep_config.max_host_qng;
  10304. }
  10305. /*
  10306. * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
  10307. * values based on possibly adjusted EEPROM values.
  10308. */
  10309. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10310. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10311. /*
  10312. * If the EEPROM 'termination' field is set to automatic (0), then set
  10313. * the ADV_DVC_CFG 'termination' field to automatic also.
  10314. *
  10315. * If the termination is specified with a non-zero 'termination'
  10316. * value check that a legal value is set and set the ADV_DVC_CFG
  10317. * 'termination' field appropriately.
  10318. */
  10319. if (eep_config.termination_se == 0) {
  10320. termination = 0; /* auto termination for SE */
  10321. } else {
  10322. /* Enable manual control with low off / high off. */
  10323. if (eep_config.termination_se == 1) {
  10324. termination = 0;
  10325. /* Enable manual control with low off / high on. */
  10326. } else if (eep_config.termination_se == 2) {
  10327. termination = TERM_SE_HI;
  10328. /* Enable manual control with low on / high on. */
  10329. } else if (eep_config.termination_se == 3) {
  10330. termination = TERM_SE;
  10331. } else {
  10332. /*
  10333. * The EEPROM 'termination_se' field contains a bad value.
  10334. * Use automatic termination instead.
  10335. */
  10336. termination = 0;
  10337. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10338. }
  10339. }
  10340. if (eep_config.termination_lvd == 0) {
  10341. asc_dvc->cfg->termination = termination; /* auto termination for LVD */
  10342. } else {
  10343. /* Enable manual control with low off / high off. */
  10344. if (eep_config.termination_lvd == 1) {
  10345. asc_dvc->cfg->termination = termination;
  10346. /* Enable manual control with low off / high on. */
  10347. } else if (eep_config.termination_lvd == 2) {
  10348. asc_dvc->cfg->termination = termination | TERM_LVD_HI;
  10349. /* Enable manual control with low on / high on. */
  10350. } else if (eep_config.termination_lvd == 3) {
  10351. asc_dvc->cfg->termination = termination | TERM_LVD;
  10352. } else {
  10353. /*
  10354. * The EEPROM 'termination_lvd' field contains a bad value.
  10355. * Use automatic termination instead.
  10356. */
  10357. asc_dvc->cfg->termination = termination;
  10358. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10359. }
  10360. }
  10361. return warn_code;
  10362. }
  10363. /*
  10364. * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and
  10365. * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while
  10366. * all of this is done.
  10367. *
  10368. * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
  10369. *
  10370. * For a non-fatal error return a warning code. If there are no warnings
  10371. * then 0 is returned.
  10372. *
  10373. * Note: Chip is stopped on entry.
  10374. */
  10375. static int __devinit AdvInitFrom38C1600EEP(ADV_DVC_VAR *asc_dvc)
  10376. {
  10377. AdvPortAddr iop_base;
  10378. ushort warn_code;
  10379. ADVEEP_38C1600_CONFIG eep_config;
  10380. uchar tid, termination;
  10381. ushort sdtr_speed = 0;
  10382. iop_base = asc_dvc->iop_base;
  10383. warn_code = 0;
  10384. /*
  10385. * Read the board's EEPROM configuration.
  10386. *
  10387. * Set default values if a bad checksum is found.
  10388. */
  10389. if (AdvGet38C1600EEPConfig(iop_base, &eep_config) !=
  10390. eep_config.check_sum) {
  10391. struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
  10392. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  10393. /*
  10394. * Set EEPROM default values.
  10395. */
  10396. memcpy(&eep_config, &Default_38C1600_EEPROM_Config,
  10397. sizeof(ADVEEP_38C1600_CONFIG));
  10398. if (PCI_FUNC(pdev->devfn) != 0) {
  10399. u8 ints;
  10400. /*
  10401. * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60
  10402. * and old Mac system booting problem. The Expansion
  10403. * ROM must be disabled in Function 1 for these systems
  10404. */
  10405. eep_config.cfg_lsw &= ~ADV_EEPROM_BIOS_ENABLE;
  10406. /*
  10407. * Clear the INTAB (bit 11) if the GPIO 0 input
  10408. * indicates the Function 1 interrupt line is wired
  10409. * to INTB.
  10410. *
  10411. * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
  10412. * 1 - Function 1 interrupt line wired to INT A.
  10413. * 0 - Function 1 interrupt line wired to INT B.
  10414. *
  10415. * Note: Function 0 is always wired to INTA.
  10416. * Put all 5 GPIO bits in input mode and then read
  10417. * their input values.
  10418. */
  10419. AdvWriteByteRegister(iop_base, IOPB_GPIO_CNTL, 0);
  10420. ints = AdvReadByteRegister(iop_base, IOPB_GPIO_DATA);
  10421. if ((ints & 0x01) == 0)
  10422. eep_config.cfg_lsw &= ~ADV_EEPROM_INTAB;
  10423. }
  10424. /*
  10425. * Assume the 6 byte board serial number that was read from
  10426. * EEPROM is correct even if the EEPROM checksum failed.
  10427. */
  10428. eep_config.serial_number_word3 =
  10429. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  10430. eep_config.serial_number_word2 =
  10431. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  10432. eep_config.serial_number_word1 =
  10433. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  10434. AdvSet38C1600EEPConfig(iop_base, &eep_config);
  10435. }
  10436. /*
  10437. * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
  10438. * EEPROM configuration that was read.
  10439. *
  10440. * This is the mapping of EEPROM fields to Adv Library fields.
  10441. */
  10442. asc_dvc->wdtr_able = eep_config.wdtr_able;
  10443. asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
  10444. asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
  10445. asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
  10446. asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
  10447. asc_dvc->ppr_able = 0;
  10448. asc_dvc->tagqng_able = eep_config.tagqng_able;
  10449. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  10450. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10451. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10452. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ASC_MAX_TID);
  10453. asc_dvc->start_motor = eep_config.start_motor;
  10454. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  10455. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  10456. asc_dvc->no_scam = eep_config.scam_tolerant;
  10457. /*
  10458. * For every Target ID if any of its 'sdtr_speed[1234]' bits
  10459. * are set, then set an 'sdtr_able' bit for it.
  10460. */
  10461. asc_dvc->sdtr_able = 0;
  10462. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  10463. if (tid == 0) {
  10464. sdtr_speed = asc_dvc->sdtr_speed1;
  10465. } else if (tid == 4) {
  10466. sdtr_speed = asc_dvc->sdtr_speed2;
  10467. } else if (tid == 8) {
  10468. sdtr_speed = asc_dvc->sdtr_speed3;
  10469. } else if (tid == 12) {
  10470. sdtr_speed = asc_dvc->sdtr_speed4;
  10471. }
  10472. if (sdtr_speed & ASC_MAX_TID) {
  10473. asc_dvc->sdtr_able |= (1 << tid);
  10474. }
  10475. sdtr_speed >>= 4;
  10476. }
  10477. /*
  10478. * Set the host maximum queuing (max. 253, min. 16) and the per device
  10479. * maximum queuing (max. 63, min. 4).
  10480. */
  10481. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  10482. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10483. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  10484. /* If the value is zero, assume it is uninitialized. */
  10485. if (eep_config.max_host_qng == 0) {
  10486. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10487. } else {
  10488. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  10489. }
  10490. }
  10491. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  10492. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10493. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  10494. /* If the value is zero, assume it is uninitialized. */
  10495. if (eep_config.max_dvc_qng == 0) {
  10496. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10497. } else {
  10498. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  10499. }
  10500. }
  10501. /*
  10502. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  10503. * set 'max_dvc_qng' to 'max_host_qng'.
  10504. */
  10505. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  10506. eep_config.max_dvc_qng = eep_config.max_host_qng;
  10507. }
  10508. /*
  10509. * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng'
  10510. * values based on possibly adjusted EEPROM values.
  10511. */
  10512. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10513. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10514. /*
  10515. * If the EEPROM 'termination' field is set to automatic (0), then set
  10516. * the ASC_DVC_CFG 'termination' field to automatic also.
  10517. *
  10518. * If the termination is specified with a non-zero 'termination'
  10519. * value check that a legal value is set and set the ASC_DVC_CFG
  10520. * 'termination' field appropriately.
  10521. */
  10522. if (eep_config.termination_se == 0) {
  10523. termination = 0; /* auto termination for SE */
  10524. } else {
  10525. /* Enable manual control with low off / high off. */
  10526. if (eep_config.termination_se == 1) {
  10527. termination = 0;
  10528. /* Enable manual control with low off / high on. */
  10529. } else if (eep_config.termination_se == 2) {
  10530. termination = TERM_SE_HI;
  10531. /* Enable manual control with low on / high on. */
  10532. } else if (eep_config.termination_se == 3) {
  10533. termination = TERM_SE;
  10534. } else {
  10535. /*
  10536. * The EEPROM 'termination_se' field contains a bad value.
  10537. * Use automatic termination instead.
  10538. */
  10539. termination = 0;
  10540. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10541. }
  10542. }
  10543. if (eep_config.termination_lvd == 0) {
  10544. asc_dvc->cfg->termination = termination; /* auto termination for LVD */
  10545. } else {
  10546. /* Enable manual control with low off / high off. */
  10547. if (eep_config.termination_lvd == 1) {
  10548. asc_dvc->cfg->termination = termination;
  10549. /* Enable manual control with low off / high on. */
  10550. } else if (eep_config.termination_lvd == 2) {
  10551. asc_dvc->cfg->termination = termination | TERM_LVD_HI;
  10552. /* Enable manual control with low on / high on. */
  10553. } else if (eep_config.termination_lvd == 3) {
  10554. asc_dvc->cfg->termination = termination | TERM_LVD;
  10555. } else {
  10556. /*
  10557. * The EEPROM 'termination_lvd' field contains a bad value.
  10558. * Use automatic termination instead.
  10559. */
  10560. asc_dvc->cfg->termination = termination;
  10561. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10562. }
  10563. }
  10564. return warn_code;
  10565. }
  10566. /*
  10567. * Initialize the ADV_DVC_VAR structure.
  10568. *
  10569. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  10570. *
  10571. * For a non-fatal error return a warning code. If there are no warnings
  10572. * then 0 is returned.
  10573. */
  10574. static int __devinit
  10575. AdvInitGetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
  10576. {
  10577. struct asc_board *board = shost_priv(shost);
  10578. ADV_DVC_VAR *asc_dvc = &board->dvc_var.adv_dvc_var;
  10579. unsigned short warn_code = 0;
  10580. AdvPortAddr iop_base = asc_dvc->iop_base;
  10581. u16 cmd;
  10582. int status;
  10583. asc_dvc->err_code = 0;
  10584. /*
  10585. * Save the state of the PCI Configuration Command Register
  10586. * "Parity Error Response Control" Bit. If the bit is clear (0),
  10587. * in AdvInitAsc3550/38C0800Driver() tell the microcode to ignore
  10588. * DMA parity errors.
  10589. */
  10590. asc_dvc->cfg->control_flag = 0;
  10591. pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  10592. if ((cmd & PCI_COMMAND_PARITY) == 0)
  10593. asc_dvc->cfg->control_flag |= CONTROL_FLAG_IGNORE_PERR;
  10594. asc_dvc->cfg->chip_version =
  10595. AdvGetChipVersion(iop_base, asc_dvc->bus_type);
  10596. ASC_DBG(1, "iopb_chip_id_1: 0x%x 0x%x\n",
  10597. (ushort)AdvReadByteRegister(iop_base, IOPB_CHIP_ID_1),
  10598. (ushort)ADV_CHIP_ID_BYTE);
  10599. ASC_DBG(1, "iopw_chip_id_0: 0x%x 0x%x\n",
  10600. (ushort)AdvReadWordRegister(iop_base, IOPW_CHIP_ID_0),
  10601. (ushort)ADV_CHIP_ID_WORD);
  10602. /*
  10603. * Reset the chip to start and allow register writes.
  10604. */
  10605. if (AdvFindSignature(iop_base) == 0) {
  10606. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  10607. return ADV_ERROR;
  10608. } else {
  10609. /*
  10610. * The caller must set 'chip_type' to a valid setting.
  10611. */
  10612. if (asc_dvc->chip_type != ADV_CHIP_ASC3550 &&
  10613. asc_dvc->chip_type != ADV_CHIP_ASC38C0800 &&
  10614. asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
  10615. asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE;
  10616. return ADV_ERROR;
  10617. }
  10618. /*
  10619. * Reset Chip.
  10620. */
  10621. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  10622. ADV_CTRL_REG_CMD_RESET);
  10623. mdelay(100);
  10624. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  10625. ADV_CTRL_REG_CMD_WR_IO_REG);
  10626. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  10627. status = AdvInitFrom38C1600EEP(asc_dvc);
  10628. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  10629. status = AdvInitFrom38C0800EEP(asc_dvc);
  10630. } else {
  10631. status = AdvInitFrom3550EEP(asc_dvc);
  10632. }
  10633. warn_code |= status;
  10634. }
  10635. if (warn_code != 0)
  10636. shost_printk(KERN_WARNING, shost, "warning: 0x%x\n", warn_code);
  10637. if (asc_dvc->err_code)
  10638. shost_printk(KERN_ERR, shost, "error code 0x%x\n",
  10639. asc_dvc->err_code);
  10640. return asc_dvc->err_code;
  10641. }
  10642. #endif
  10643. static struct scsi_host_template advansys_template = {
  10644. .proc_name = DRV_NAME,
  10645. #ifdef CONFIG_PROC_FS
  10646. .proc_info = advansys_proc_info,
  10647. #endif
  10648. .name = DRV_NAME,
  10649. .info = advansys_info,
  10650. .queuecommand = advansys_queuecommand,
  10651. .eh_bus_reset_handler = advansys_reset,
  10652. .bios_param = advansys_biosparam,
  10653. .slave_configure = advansys_slave_configure,
  10654. /*
  10655. * Because the driver may control an ISA adapter 'unchecked_isa_dma'
  10656. * must be set. The flag will be cleared in advansys_board_found
  10657. * for non-ISA adapters.
  10658. */
  10659. .unchecked_isa_dma = 1,
  10660. /*
  10661. * All adapters controlled by this driver are capable of large
  10662. * scatter-gather lists. According to the mid-level SCSI documentation
  10663. * this obviates any performance gain provided by setting
  10664. * 'use_clustering'. But empirically while CPU utilization is increased
  10665. * by enabling clustering, I/O throughput increases as well.
  10666. */
  10667. .use_clustering = ENABLE_CLUSTERING,
  10668. };
  10669. static int __devinit advansys_wide_init_chip(struct Scsi_Host *shost)
  10670. {
  10671. struct asc_board *board = shost_priv(shost);
  10672. struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
  10673. int req_cnt = 0;
  10674. adv_req_t *reqp = NULL;
  10675. int sg_cnt = 0;
  10676. adv_sgblk_t *sgp;
  10677. int warn_code, err_code;
  10678. /*
  10679. * Allocate buffer carrier structures. The total size
  10680. * is about 4 KB, so allocate all at once.
  10681. */
  10682. adv_dvc->carrier_buf = kmalloc(ADV_CARRIER_BUFSIZE, GFP_KERNEL);
  10683. ASC_DBG(1, "carrier_buf 0x%p\n", adv_dvc->carrier_buf);
  10684. if (!adv_dvc->carrier_buf)
  10685. goto kmalloc_failed;
  10686. /*
  10687. * Allocate up to 'max_host_qng' request structures for the Wide
  10688. * board. The total size is about 16 KB, so allocate all at once.
  10689. * If the allocation fails decrement and try again.
  10690. */
  10691. for (req_cnt = adv_dvc->max_host_qng; req_cnt > 0; req_cnt--) {
  10692. reqp = kmalloc(sizeof(adv_req_t) * req_cnt, GFP_KERNEL);
  10693. ASC_DBG(1, "reqp 0x%p, req_cnt %d, bytes %lu\n", reqp, req_cnt,
  10694. (ulong)sizeof(adv_req_t) * req_cnt);
  10695. if (reqp)
  10696. break;
  10697. }
  10698. if (!reqp)
  10699. goto kmalloc_failed;
  10700. adv_dvc->orig_reqp = reqp;
  10701. /*
  10702. * Allocate up to ADV_TOT_SG_BLOCK request structures for
  10703. * the Wide board. Each structure is about 136 bytes.
  10704. */
  10705. board->adv_sgblkp = NULL;
  10706. for (sg_cnt = 0; sg_cnt < ADV_TOT_SG_BLOCK; sg_cnt++) {
  10707. sgp = kmalloc(sizeof(adv_sgblk_t), GFP_KERNEL);
  10708. if (!sgp)
  10709. break;
  10710. sgp->next_sgblkp = board->adv_sgblkp;
  10711. board->adv_sgblkp = sgp;
  10712. }
  10713. ASC_DBG(1, "sg_cnt %d * %lu = %lu bytes\n", sg_cnt, sizeof(adv_sgblk_t),
  10714. sizeof(adv_sgblk_t) * sg_cnt);
  10715. if (!board->adv_sgblkp)
  10716. goto kmalloc_failed;
  10717. /*
  10718. * Point 'adv_reqp' to the request structures and
  10719. * link them together.
  10720. */
  10721. req_cnt--;
  10722. reqp[req_cnt].next_reqp = NULL;
  10723. for (; req_cnt > 0; req_cnt--) {
  10724. reqp[req_cnt - 1].next_reqp = &reqp[req_cnt];
  10725. }
  10726. board->adv_reqp = &reqp[0];
  10727. if (adv_dvc->chip_type == ADV_CHIP_ASC3550) {
  10728. ASC_DBG(2, "AdvInitAsc3550Driver()\n");
  10729. warn_code = AdvInitAsc3550Driver(adv_dvc);
  10730. } else if (adv_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  10731. ASC_DBG(2, "AdvInitAsc38C0800Driver()\n");
  10732. warn_code = AdvInitAsc38C0800Driver(adv_dvc);
  10733. } else {
  10734. ASC_DBG(2, "AdvInitAsc38C1600Driver()\n");
  10735. warn_code = AdvInitAsc38C1600Driver(adv_dvc);
  10736. }
  10737. err_code = adv_dvc->err_code;
  10738. if (warn_code || err_code) {
  10739. shost_printk(KERN_WARNING, shost, "error: warn 0x%x, error "
  10740. "0x%x\n", warn_code, err_code);
  10741. }
  10742. goto exit;
  10743. kmalloc_failed:
  10744. shost_printk(KERN_ERR, shost, "error: kmalloc() failed\n");
  10745. err_code = ADV_ERROR;
  10746. exit:
  10747. return err_code;
  10748. }
  10749. static void advansys_wide_free_mem(struct asc_board *board)
  10750. {
  10751. struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
  10752. kfree(adv_dvc->carrier_buf);
  10753. adv_dvc->carrier_buf = NULL;
  10754. kfree(adv_dvc->orig_reqp);
  10755. adv_dvc->orig_reqp = board->adv_reqp = NULL;
  10756. while (board->adv_sgblkp) {
  10757. adv_sgblk_t *sgp = board->adv_sgblkp;
  10758. board->adv_sgblkp = sgp->next_sgblkp;
  10759. kfree(sgp);
  10760. }
  10761. }
  10762. static int __devinit advansys_board_found(struct Scsi_Host *shost,
  10763. unsigned int iop, int bus_type)
  10764. {
  10765. struct pci_dev *pdev;
  10766. struct asc_board *boardp = shost_priv(shost);
  10767. ASC_DVC_VAR *asc_dvc_varp = NULL;
  10768. ADV_DVC_VAR *adv_dvc_varp = NULL;
  10769. int share_irq, warn_code, ret;
  10770. pdev = (bus_type == ASC_IS_PCI) ? to_pci_dev(boardp->dev) : NULL;
  10771. if (ASC_NARROW_BOARD(boardp)) {
  10772. ASC_DBG(1, "narrow board\n");
  10773. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  10774. asc_dvc_varp->bus_type = bus_type;
  10775. asc_dvc_varp->drv_ptr = boardp;
  10776. asc_dvc_varp->cfg = &boardp->dvc_cfg.asc_dvc_cfg;
  10777. asc_dvc_varp->iop_base = iop;
  10778. } else {
  10779. #ifdef CONFIG_PCI
  10780. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  10781. adv_dvc_varp->drv_ptr = boardp;
  10782. adv_dvc_varp->cfg = &boardp->dvc_cfg.adv_dvc_cfg;
  10783. if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW) {
  10784. ASC_DBG(1, "wide board ASC-3550\n");
  10785. adv_dvc_varp->chip_type = ADV_CHIP_ASC3550;
  10786. } else if (pdev->device == PCI_DEVICE_ID_38C0800_REV1) {
  10787. ASC_DBG(1, "wide board ASC-38C0800\n");
  10788. adv_dvc_varp->chip_type = ADV_CHIP_ASC38C0800;
  10789. } else {
  10790. ASC_DBG(1, "wide board ASC-38C1600\n");
  10791. adv_dvc_varp->chip_type = ADV_CHIP_ASC38C1600;
  10792. }
  10793. boardp->asc_n_io_port = pci_resource_len(pdev, 1);
  10794. boardp->ioremap_addr = pci_ioremap_bar(pdev, 1);
  10795. if (!boardp->ioremap_addr) {
  10796. shost_printk(KERN_ERR, shost, "ioremap(%lx, %d) "
  10797. "returned NULL\n",
  10798. (long)pci_resource_start(pdev, 1),
  10799. boardp->asc_n_io_port);
  10800. ret = -ENODEV;
  10801. goto err_shost;
  10802. }
  10803. adv_dvc_varp->iop_base = (AdvPortAddr)boardp->ioremap_addr;
  10804. ASC_DBG(1, "iop_base: 0x%p\n", adv_dvc_varp->iop_base);
  10805. /*
  10806. * Even though it isn't used to access wide boards, other
  10807. * than for the debug line below, save I/O Port address so
  10808. * that it can be reported.
  10809. */
  10810. boardp->ioport = iop;
  10811. ASC_DBG(1, "iopb_chip_id_1 0x%x, iopw_chip_id_0 0x%x\n",
  10812. (ushort)inp(iop + 1), (ushort)inpw(iop));
  10813. #endif /* CONFIG_PCI */
  10814. }
  10815. #ifdef CONFIG_PROC_FS
  10816. /*
  10817. * Allocate buffer for printing information from
  10818. * /proc/scsi/advansys/[0...].
  10819. */
  10820. boardp->prtbuf = kmalloc(ASC_PRTBUF_SIZE, GFP_KERNEL);
  10821. if (!boardp->prtbuf) {
  10822. shost_printk(KERN_ERR, shost, "kmalloc(%d) returned NULL\n",
  10823. ASC_PRTBUF_SIZE);
  10824. ret = -ENOMEM;
  10825. goto err_unmap;
  10826. }
  10827. #endif /* CONFIG_PROC_FS */
  10828. if (ASC_NARROW_BOARD(boardp)) {
  10829. /*
  10830. * Set the board bus type and PCI IRQ before
  10831. * calling AscInitGetConfig().
  10832. */
  10833. switch (asc_dvc_varp->bus_type) {
  10834. #ifdef CONFIG_ISA
  10835. case ASC_IS_ISA:
  10836. shost->unchecked_isa_dma = TRUE;
  10837. share_irq = 0;
  10838. break;
  10839. case ASC_IS_VL:
  10840. shost->unchecked_isa_dma = FALSE;
  10841. share_irq = 0;
  10842. break;
  10843. case ASC_IS_EISA:
  10844. shost->unchecked_isa_dma = FALSE;
  10845. share_irq = IRQF_SHARED;
  10846. break;
  10847. #endif /* CONFIG_ISA */
  10848. #ifdef CONFIG_PCI
  10849. case ASC_IS_PCI:
  10850. shost->unchecked_isa_dma = FALSE;
  10851. share_irq = IRQF_SHARED;
  10852. break;
  10853. #endif /* CONFIG_PCI */
  10854. default:
  10855. shost_printk(KERN_ERR, shost, "unknown adapter type: "
  10856. "%d\n", asc_dvc_varp->bus_type);
  10857. shost->unchecked_isa_dma = TRUE;
  10858. share_irq = 0;
  10859. break;
  10860. }
  10861. /*
  10862. * NOTE: AscInitGetConfig() may change the board's
  10863. * bus_type value. The bus_type value should no
  10864. * longer be used. If the bus_type field must be
  10865. * referenced only use the bit-wise AND operator "&".
  10866. */
  10867. ASC_DBG(2, "AscInitGetConfig()\n");
  10868. ret = AscInitGetConfig(shost) ? -ENODEV : 0;
  10869. } else {
  10870. #ifdef CONFIG_PCI
  10871. /*
  10872. * For Wide boards set PCI information before calling
  10873. * AdvInitGetConfig().
  10874. */
  10875. shost->unchecked_isa_dma = FALSE;
  10876. share_irq = IRQF_SHARED;
  10877. ASC_DBG(2, "AdvInitGetConfig()\n");
  10878. ret = AdvInitGetConfig(pdev, shost) ? -ENODEV : 0;
  10879. #endif /* CONFIG_PCI */
  10880. }
  10881. if (ret)
  10882. goto err_free_proc;
  10883. /*
  10884. * Save the EEPROM configuration so that it can be displayed
  10885. * from /proc/scsi/advansys/[0...].
  10886. */
  10887. if (ASC_NARROW_BOARD(boardp)) {
  10888. ASCEEP_CONFIG *ep;
  10889. /*
  10890. * Set the adapter's target id bit in the 'init_tidmask' field.
  10891. */
  10892. boardp->init_tidmask |=
  10893. ADV_TID_TO_TIDMASK(asc_dvc_varp->cfg->chip_scsi_id);
  10894. /*
  10895. * Save EEPROM settings for the board.
  10896. */
  10897. ep = &boardp->eep_config.asc_eep;
  10898. ep->init_sdtr = asc_dvc_varp->cfg->sdtr_enable;
  10899. ep->disc_enable = asc_dvc_varp->cfg->disc_enable;
  10900. ep->use_cmd_qng = asc_dvc_varp->cfg->cmd_qng_enabled;
  10901. ASC_EEP_SET_DMA_SPD(ep, asc_dvc_varp->cfg->isa_dma_speed);
  10902. ep->start_motor = asc_dvc_varp->start_motor;
  10903. ep->cntl = asc_dvc_varp->dvc_cntl;
  10904. ep->no_scam = asc_dvc_varp->no_scam;
  10905. ep->max_total_qng = asc_dvc_varp->max_total_qng;
  10906. ASC_EEP_SET_CHIP_ID(ep, asc_dvc_varp->cfg->chip_scsi_id);
  10907. /* 'max_tag_qng' is set to the same value for every device. */
  10908. ep->max_tag_qng = asc_dvc_varp->cfg->max_tag_qng[0];
  10909. ep->adapter_info[0] = asc_dvc_varp->cfg->adapter_info[0];
  10910. ep->adapter_info[1] = asc_dvc_varp->cfg->adapter_info[1];
  10911. ep->adapter_info[2] = asc_dvc_varp->cfg->adapter_info[2];
  10912. ep->adapter_info[3] = asc_dvc_varp->cfg->adapter_info[3];
  10913. ep->adapter_info[4] = asc_dvc_varp->cfg->adapter_info[4];
  10914. ep->adapter_info[5] = asc_dvc_varp->cfg->adapter_info[5];
  10915. /*
  10916. * Modify board configuration.
  10917. */
  10918. ASC_DBG(2, "AscInitSetConfig()\n");
  10919. ret = AscInitSetConfig(pdev, shost) ? -ENODEV : 0;
  10920. if (ret)
  10921. goto err_free_proc;
  10922. } else {
  10923. ADVEEP_3550_CONFIG *ep_3550;
  10924. ADVEEP_38C0800_CONFIG *ep_38C0800;
  10925. ADVEEP_38C1600_CONFIG *ep_38C1600;
  10926. /*
  10927. * Save Wide EEP Configuration Information.
  10928. */
  10929. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  10930. ep_3550 = &boardp->eep_config.adv_3550_eep;
  10931. ep_3550->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
  10932. ep_3550->max_host_qng = adv_dvc_varp->max_host_qng;
  10933. ep_3550->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10934. ep_3550->termination = adv_dvc_varp->cfg->termination;
  10935. ep_3550->disc_enable = adv_dvc_varp->cfg->disc_enable;
  10936. ep_3550->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10937. ep_3550->wdtr_able = adv_dvc_varp->wdtr_able;
  10938. ep_3550->sdtr_able = adv_dvc_varp->sdtr_able;
  10939. ep_3550->ultra_able = adv_dvc_varp->ultra_able;
  10940. ep_3550->tagqng_able = adv_dvc_varp->tagqng_able;
  10941. ep_3550->start_motor = adv_dvc_varp->start_motor;
  10942. ep_3550->scsi_reset_delay =
  10943. adv_dvc_varp->scsi_reset_wait;
  10944. ep_3550->serial_number_word1 =
  10945. adv_dvc_varp->cfg->serial1;
  10946. ep_3550->serial_number_word2 =
  10947. adv_dvc_varp->cfg->serial2;
  10948. ep_3550->serial_number_word3 =
  10949. adv_dvc_varp->cfg->serial3;
  10950. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  10951. ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
  10952. ep_38C0800->adapter_scsi_id =
  10953. adv_dvc_varp->chip_scsi_id;
  10954. ep_38C0800->max_host_qng = adv_dvc_varp->max_host_qng;
  10955. ep_38C0800->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10956. ep_38C0800->termination_lvd =
  10957. adv_dvc_varp->cfg->termination;
  10958. ep_38C0800->disc_enable =
  10959. adv_dvc_varp->cfg->disc_enable;
  10960. ep_38C0800->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10961. ep_38C0800->wdtr_able = adv_dvc_varp->wdtr_able;
  10962. ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
  10963. ep_38C0800->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
  10964. ep_38C0800->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
  10965. ep_38C0800->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
  10966. ep_38C0800->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
  10967. ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
  10968. ep_38C0800->start_motor = adv_dvc_varp->start_motor;
  10969. ep_38C0800->scsi_reset_delay =
  10970. adv_dvc_varp->scsi_reset_wait;
  10971. ep_38C0800->serial_number_word1 =
  10972. adv_dvc_varp->cfg->serial1;
  10973. ep_38C0800->serial_number_word2 =
  10974. adv_dvc_varp->cfg->serial2;
  10975. ep_38C0800->serial_number_word3 =
  10976. adv_dvc_varp->cfg->serial3;
  10977. } else {
  10978. ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
  10979. ep_38C1600->adapter_scsi_id =
  10980. adv_dvc_varp->chip_scsi_id;
  10981. ep_38C1600->max_host_qng = adv_dvc_varp->max_host_qng;
  10982. ep_38C1600->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10983. ep_38C1600->termination_lvd =
  10984. adv_dvc_varp->cfg->termination;
  10985. ep_38C1600->disc_enable =
  10986. adv_dvc_varp->cfg->disc_enable;
  10987. ep_38C1600->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10988. ep_38C1600->wdtr_able = adv_dvc_varp->wdtr_able;
  10989. ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
  10990. ep_38C1600->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
  10991. ep_38C1600->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
  10992. ep_38C1600->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
  10993. ep_38C1600->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
  10994. ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
  10995. ep_38C1600->start_motor = adv_dvc_varp->start_motor;
  10996. ep_38C1600->scsi_reset_delay =
  10997. adv_dvc_varp->scsi_reset_wait;
  10998. ep_38C1600->serial_number_word1 =
  10999. adv_dvc_varp->cfg->serial1;
  11000. ep_38C1600->serial_number_word2 =
  11001. adv_dvc_varp->cfg->serial2;
  11002. ep_38C1600->serial_number_word3 =
  11003. adv_dvc_varp->cfg->serial3;
  11004. }
  11005. /*
  11006. * Set the adapter's target id bit in the 'init_tidmask' field.
  11007. */
  11008. boardp->init_tidmask |=
  11009. ADV_TID_TO_TIDMASK(adv_dvc_varp->chip_scsi_id);
  11010. }
  11011. /*
  11012. * Channels are numbered beginning with 0. For AdvanSys one host
  11013. * structure supports one channel. Multi-channel boards have a
  11014. * separate host structure for each channel.
  11015. */
  11016. shost->max_channel = 0;
  11017. if (ASC_NARROW_BOARD(boardp)) {
  11018. shost->max_id = ASC_MAX_TID + 1;
  11019. shost->max_lun = ASC_MAX_LUN + 1;
  11020. shost->max_cmd_len = ASC_MAX_CDB_LEN;
  11021. shost->io_port = asc_dvc_varp->iop_base;
  11022. boardp->asc_n_io_port = ASC_IOADR_GAP;
  11023. shost->this_id = asc_dvc_varp->cfg->chip_scsi_id;
  11024. /* Set maximum number of queues the adapter can handle. */
  11025. shost->can_queue = asc_dvc_varp->max_total_qng;
  11026. } else {
  11027. shost->max_id = ADV_MAX_TID + 1;
  11028. shost->max_lun = ADV_MAX_LUN + 1;
  11029. shost->max_cmd_len = ADV_MAX_CDB_LEN;
  11030. /*
  11031. * Save the I/O Port address and length even though
  11032. * I/O ports are not used to access Wide boards.
  11033. * Instead the Wide boards are accessed with
  11034. * PCI Memory Mapped I/O.
  11035. */
  11036. shost->io_port = iop;
  11037. shost->this_id = adv_dvc_varp->chip_scsi_id;
  11038. /* Set maximum number of queues the adapter can handle. */
  11039. shost->can_queue = adv_dvc_varp->max_host_qng;
  11040. }
  11041. /*
  11042. * Following v1.3.89, 'cmd_per_lun' is no longer needed
  11043. * and should be set to zero.
  11044. *
  11045. * But because of a bug introduced in v1.3.89 if the driver is
  11046. * compiled as a module and 'cmd_per_lun' is zero, the Mid-Level
  11047. * SCSI function 'allocate_device' will panic. To allow the driver
  11048. * to work as a module in these kernels set 'cmd_per_lun' to 1.
  11049. *
  11050. * Note: This is wrong. cmd_per_lun should be set to the depth
  11051. * you want on untagged devices always.
  11052. #ifdef MODULE
  11053. */
  11054. shost->cmd_per_lun = 1;
  11055. /* #else
  11056. shost->cmd_per_lun = 0;
  11057. #endif */
  11058. /*
  11059. * Set the maximum number of scatter-gather elements the
  11060. * adapter can handle.
  11061. */
  11062. if (ASC_NARROW_BOARD(boardp)) {
  11063. /*
  11064. * Allow two commands with 'sg_tablesize' scatter-gather
  11065. * elements to be executed simultaneously. This value is
  11066. * the theoretical hardware limit. It may be decreased
  11067. * below.
  11068. */
  11069. shost->sg_tablesize =
  11070. (((asc_dvc_varp->max_total_qng - 2) / 2) *
  11071. ASC_SG_LIST_PER_Q) + 1;
  11072. } else {
  11073. shost->sg_tablesize = ADV_MAX_SG_LIST;
  11074. }
  11075. /*
  11076. * The value of 'sg_tablesize' can not exceed the SCSI
  11077. * mid-level driver definition of SG_ALL. SG_ALL also
  11078. * must not be exceeded, because it is used to define the
  11079. * size of the scatter-gather table in 'struct asc_sg_head'.
  11080. */
  11081. if (shost->sg_tablesize > SG_ALL) {
  11082. shost->sg_tablesize = SG_ALL;
  11083. }
  11084. ASC_DBG(1, "sg_tablesize: %d\n", shost->sg_tablesize);
  11085. /* BIOS start address. */
  11086. if (ASC_NARROW_BOARD(boardp)) {
  11087. shost->base = AscGetChipBiosAddress(asc_dvc_varp->iop_base,
  11088. asc_dvc_varp->bus_type);
  11089. } else {
  11090. /*
  11091. * Fill-in BIOS board variables. The Wide BIOS saves
  11092. * information in LRAM that is used by the driver.
  11093. */
  11094. AdvReadWordLram(adv_dvc_varp->iop_base,
  11095. BIOS_SIGNATURE, boardp->bios_signature);
  11096. AdvReadWordLram(adv_dvc_varp->iop_base,
  11097. BIOS_VERSION, boardp->bios_version);
  11098. AdvReadWordLram(adv_dvc_varp->iop_base,
  11099. BIOS_CODESEG, boardp->bios_codeseg);
  11100. AdvReadWordLram(adv_dvc_varp->iop_base,
  11101. BIOS_CODELEN, boardp->bios_codelen);
  11102. ASC_DBG(1, "bios_signature 0x%x, bios_version 0x%x\n",
  11103. boardp->bios_signature, boardp->bios_version);
  11104. ASC_DBG(1, "bios_codeseg 0x%x, bios_codelen 0x%x\n",
  11105. boardp->bios_codeseg, boardp->bios_codelen);
  11106. /*
  11107. * If the BIOS saved a valid signature, then fill in
  11108. * the BIOS code segment base address.
  11109. */
  11110. if (boardp->bios_signature == 0x55AA) {
  11111. /*
  11112. * Convert x86 realmode code segment to a linear
  11113. * address by shifting left 4.
  11114. */
  11115. shost->base = ((ulong)boardp->bios_codeseg << 4);
  11116. } else {
  11117. shost->base = 0;
  11118. }
  11119. }
  11120. /*
  11121. * Register Board Resources - I/O Port, DMA, IRQ
  11122. */
  11123. /* Register DMA Channel for Narrow boards. */
  11124. shost->dma_channel = NO_ISA_DMA; /* Default to no ISA DMA. */
  11125. #ifdef CONFIG_ISA
  11126. if (ASC_NARROW_BOARD(boardp)) {
  11127. /* Register DMA channel for ISA bus. */
  11128. if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
  11129. shost->dma_channel = asc_dvc_varp->cfg->isa_dma_channel;
  11130. ret = request_dma(shost->dma_channel, DRV_NAME);
  11131. if (ret) {
  11132. shost_printk(KERN_ERR, shost, "request_dma() "
  11133. "%d failed %d\n",
  11134. shost->dma_channel, ret);
  11135. goto err_free_proc;
  11136. }
  11137. AscEnableIsaDma(shost->dma_channel);
  11138. }
  11139. }
  11140. #endif /* CONFIG_ISA */
  11141. /* Register IRQ Number. */
  11142. ASC_DBG(2, "request_irq(%d, %p)\n", boardp->irq, shost);
  11143. ret = request_irq(boardp->irq, advansys_interrupt, share_irq,
  11144. DRV_NAME, shost);
  11145. if (ret) {
  11146. if (ret == -EBUSY) {
  11147. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  11148. "already in use\n", boardp->irq);
  11149. } else if (ret == -EINVAL) {
  11150. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  11151. "not valid\n", boardp->irq);
  11152. } else {
  11153. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  11154. "failed with %d\n", boardp->irq, ret);
  11155. }
  11156. goto err_free_dma;
  11157. }
  11158. /*
  11159. * Initialize board RISC chip and enable interrupts.
  11160. */
  11161. if (ASC_NARROW_BOARD(boardp)) {
  11162. ASC_DBG(2, "AscInitAsc1000Driver()\n");
  11163. asc_dvc_varp->overrun_buf = kzalloc(ASC_OVERRUN_BSIZE, GFP_KERNEL);
  11164. if (!asc_dvc_varp->overrun_buf) {
  11165. ret = -ENOMEM;
  11166. goto err_free_irq;
  11167. }
  11168. warn_code = AscInitAsc1000Driver(asc_dvc_varp);
  11169. if (warn_code || asc_dvc_varp->err_code) {
  11170. shost_printk(KERN_ERR, shost, "error: init_state 0x%x, "
  11171. "warn 0x%x, error 0x%x\n",
  11172. asc_dvc_varp->init_state, warn_code,
  11173. asc_dvc_varp->err_code);
  11174. if (!asc_dvc_varp->overrun_dma) {
  11175. ret = -ENODEV;
  11176. goto err_free_mem;
  11177. }
  11178. }
  11179. } else {
  11180. if (advansys_wide_init_chip(shost)) {
  11181. ret = -ENODEV;
  11182. goto err_free_mem;
  11183. }
  11184. }
  11185. ASC_DBG_PRT_SCSI_HOST(2, shost);
  11186. ret = scsi_add_host(shost, boardp->dev);
  11187. if (ret)
  11188. goto err_free_mem;
  11189. scsi_scan_host(shost);
  11190. return 0;
  11191. err_free_mem:
  11192. if (ASC_NARROW_BOARD(boardp)) {
  11193. if (asc_dvc_varp->overrun_dma)
  11194. dma_unmap_single(boardp->dev, asc_dvc_varp->overrun_dma,
  11195. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  11196. kfree(asc_dvc_varp->overrun_buf);
  11197. } else
  11198. advansys_wide_free_mem(boardp);
  11199. err_free_irq:
  11200. free_irq(boardp->irq, shost);
  11201. err_free_dma:
  11202. #ifdef CONFIG_ISA
  11203. if (shost->dma_channel != NO_ISA_DMA)
  11204. free_dma(shost->dma_channel);
  11205. #endif
  11206. err_free_proc:
  11207. kfree(boardp->prtbuf);
  11208. err_unmap:
  11209. if (boardp->ioremap_addr)
  11210. iounmap(boardp->ioremap_addr);
  11211. err_shost:
  11212. return ret;
  11213. }
  11214. /*
  11215. * advansys_release()
  11216. *
  11217. * Release resources allocated for a single AdvanSys adapter.
  11218. */
  11219. static int advansys_release(struct Scsi_Host *shost)
  11220. {
  11221. struct asc_board *board = shost_priv(shost);
  11222. ASC_DBG(1, "begin\n");
  11223. scsi_remove_host(shost);
  11224. free_irq(board->irq, shost);
  11225. #ifdef CONFIG_ISA
  11226. if (shost->dma_channel != NO_ISA_DMA) {
  11227. ASC_DBG(1, "free_dma()\n");
  11228. free_dma(shost->dma_channel);
  11229. }
  11230. #endif
  11231. if (ASC_NARROW_BOARD(board)) {
  11232. dma_unmap_single(board->dev,
  11233. board->dvc_var.asc_dvc_var.overrun_dma,
  11234. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  11235. kfree(board->dvc_var.asc_dvc_var.overrun_buf);
  11236. } else {
  11237. iounmap(board->ioremap_addr);
  11238. advansys_wide_free_mem(board);
  11239. }
  11240. kfree(board->prtbuf);
  11241. scsi_host_put(shost);
  11242. ASC_DBG(1, "end\n");
  11243. return 0;
  11244. }
  11245. #define ASC_IOADR_TABLE_MAX_IX 11
  11246. static PortAddr _asc_def_iop_base[ASC_IOADR_TABLE_MAX_IX] = {
  11247. 0x100, 0x0110, 0x120, 0x0130, 0x140, 0x0150, 0x0190,
  11248. 0x0210, 0x0230, 0x0250, 0x0330
  11249. };
  11250. /*
  11251. * The ISA IRQ number is found in bits 2 and 3 of the CfgLsw. It decodes as:
  11252. * 00: 10
  11253. * 01: 11
  11254. * 10: 12
  11255. * 11: 15
  11256. */
  11257. static unsigned int __devinit advansys_isa_irq_no(PortAddr iop_base)
  11258. {
  11259. unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
  11260. unsigned int chip_irq = ((cfg_lsw >> 2) & 0x03) + 10;
  11261. if (chip_irq == 13)
  11262. chip_irq = 15;
  11263. return chip_irq;
  11264. }
  11265. static int __devinit advansys_isa_probe(struct device *dev, unsigned int id)
  11266. {
  11267. int err = -ENODEV;
  11268. PortAddr iop_base = _asc_def_iop_base[id];
  11269. struct Scsi_Host *shost;
  11270. struct asc_board *board;
  11271. if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
  11272. ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
  11273. return -ENODEV;
  11274. }
  11275. ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
  11276. if (!AscFindSignature(iop_base))
  11277. goto release_region;
  11278. if (!(AscGetChipVersion(iop_base, ASC_IS_ISA) & ASC_CHIP_VER_ISA_BIT))
  11279. goto release_region;
  11280. err = -ENOMEM;
  11281. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  11282. if (!shost)
  11283. goto release_region;
  11284. board = shost_priv(shost);
  11285. board->irq = advansys_isa_irq_no(iop_base);
  11286. board->dev = dev;
  11287. err = advansys_board_found(shost, iop_base, ASC_IS_ISA);
  11288. if (err)
  11289. goto free_host;
  11290. dev_set_drvdata(dev, shost);
  11291. return 0;
  11292. free_host:
  11293. scsi_host_put(shost);
  11294. release_region:
  11295. release_region(iop_base, ASC_IOADR_GAP);
  11296. return err;
  11297. }
  11298. static int __devexit advansys_isa_remove(struct device *dev, unsigned int id)
  11299. {
  11300. int ioport = _asc_def_iop_base[id];
  11301. advansys_release(dev_get_drvdata(dev));
  11302. release_region(ioport, ASC_IOADR_GAP);
  11303. return 0;
  11304. }
  11305. static struct isa_driver advansys_isa_driver = {
  11306. .probe = advansys_isa_probe,
  11307. .remove = __devexit_p(advansys_isa_remove),
  11308. .driver = {
  11309. .owner = THIS_MODULE,
  11310. .name = DRV_NAME,
  11311. },
  11312. };
  11313. /*
  11314. * The VLB IRQ number is found in bits 2 to 4 of the CfgLsw. It decodes as:
  11315. * 000: invalid
  11316. * 001: 10
  11317. * 010: 11
  11318. * 011: 12
  11319. * 100: invalid
  11320. * 101: 14
  11321. * 110: 15
  11322. * 111: invalid
  11323. */
  11324. static unsigned int __devinit advansys_vlb_irq_no(PortAddr iop_base)
  11325. {
  11326. unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
  11327. unsigned int chip_irq = ((cfg_lsw >> 2) & 0x07) + 9;
  11328. if ((chip_irq < 10) || (chip_irq == 13) || (chip_irq > 15))
  11329. return 0;
  11330. return chip_irq;
  11331. }
  11332. static int __devinit advansys_vlb_probe(struct device *dev, unsigned int id)
  11333. {
  11334. int err = -ENODEV;
  11335. PortAddr iop_base = _asc_def_iop_base[id];
  11336. struct Scsi_Host *shost;
  11337. struct asc_board *board;
  11338. if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
  11339. ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
  11340. return -ENODEV;
  11341. }
  11342. ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
  11343. if (!AscFindSignature(iop_base))
  11344. goto release_region;
  11345. /*
  11346. * I don't think this condition can actually happen, but the old
  11347. * driver did it, and the chances of finding a VLB setup in 2007
  11348. * to do testing with is slight to none.
  11349. */
  11350. if (AscGetChipVersion(iop_base, ASC_IS_VL) > ASC_CHIP_MAX_VER_VL)
  11351. goto release_region;
  11352. err = -ENOMEM;
  11353. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  11354. if (!shost)
  11355. goto release_region;
  11356. board = shost_priv(shost);
  11357. board->irq = advansys_vlb_irq_no(iop_base);
  11358. board->dev = dev;
  11359. err = advansys_board_found(shost, iop_base, ASC_IS_VL);
  11360. if (err)
  11361. goto free_host;
  11362. dev_set_drvdata(dev, shost);
  11363. return 0;
  11364. free_host:
  11365. scsi_host_put(shost);
  11366. release_region:
  11367. release_region(iop_base, ASC_IOADR_GAP);
  11368. return -ENODEV;
  11369. }
  11370. static struct isa_driver advansys_vlb_driver = {
  11371. .probe = advansys_vlb_probe,
  11372. .remove = __devexit_p(advansys_isa_remove),
  11373. .driver = {
  11374. .owner = THIS_MODULE,
  11375. .name = "advansys_vlb",
  11376. },
  11377. };
  11378. static struct eisa_device_id advansys_eisa_table[] __devinitdata = {
  11379. { "ABP7401" },
  11380. { "ABP7501" },
  11381. { "" }
  11382. };
  11383. MODULE_DEVICE_TABLE(eisa, advansys_eisa_table);
  11384. /*
  11385. * EISA is a little more tricky than PCI; each EISA device may have two
  11386. * channels, and this driver is written to make each channel its own Scsi_Host
  11387. */
  11388. struct eisa_scsi_data {
  11389. struct Scsi_Host *host[2];
  11390. };
  11391. /*
  11392. * The EISA IRQ number is found in bits 8 to 10 of the CfgLsw. It decodes as:
  11393. * 000: 10
  11394. * 001: 11
  11395. * 010: 12
  11396. * 011: invalid
  11397. * 100: 14
  11398. * 101: 15
  11399. * 110: invalid
  11400. * 111: invalid
  11401. */
  11402. static unsigned int __devinit advansys_eisa_irq_no(struct eisa_device *edev)
  11403. {
  11404. unsigned short cfg_lsw = inw(edev->base_addr + 0xc86);
  11405. unsigned int chip_irq = ((cfg_lsw >> 8) & 0x07) + 10;
  11406. if ((chip_irq == 13) || (chip_irq > 15))
  11407. return 0;
  11408. return chip_irq;
  11409. }
  11410. static int __devinit advansys_eisa_probe(struct device *dev)
  11411. {
  11412. int i, ioport, irq = 0;
  11413. int err;
  11414. struct eisa_device *edev = to_eisa_device(dev);
  11415. struct eisa_scsi_data *data;
  11416. err = -ENOMEM;
  11417. data = kzalloc(sizeof(*data), GFP_KERNEL);
  11418. if (!data)
  11419. goto fail;
  11420. ioport = edev->base_addr + 0xc30;
  11421. err = -ENODEV;
  11422. for (i = 0; i < 2; i++, ioport += 0x20) {
  11423. struct asc_board *board;
  11424. struct Scsi_Host *shost;
  11425. if (!request_region(ioport, ASC_IOADR_GAP, DRV_NAME)) {
  11426. printk(KERN_WARNING "Region %x-%x busy\n", ioport,
  11427. ioport + ASC_IOADR_GAP - 1);
  11428. continue;
  11429. }
  11430. if (!AscFindSignature(ioport)) {
  11431. release_region(ioport, ASC_IOADR_GAP);
  11432. continue;
  11433. }
  11434. /*
  11435. * I don't know why we need to do this for EISA chips, but
  11436. * not for any others. It looks to be equivalent to
  11437. * AscGetChipCfgMsw, but I may have overlooked something,
  11438. * so I'm not converting it until I get an EISA board to
  11439. * test with.
  11440. */
  11441. inw(ioport + 4);
  11442. if (!irq)
  11443. irq = advansys_eisa_irq_no(edev);
  11444. err = -ENOMEM;
  11445. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  11446. if (!shost)
  11447. goto release_region;
  11448. board = shost_priv(shost);
  11449. board->irq = irq;
  11450. board->dev = dev;
  11451. err = advansys_board_found(shost, ioport, ASC_IS_EISA);
  11452. if (!err) {
  11453. data->host[i] = shost;
  11454. continue;
  11455. }
  11456. scsi_host_put(shost);
  11457. release_region:
  11458. release_region(ioport, ASC_IOADR_GAP);
  11459. break;
  11460. }
  11461. if (err)
  11462. goto free_data;
  11463. dev_set_drvdata(dev, data);
  11464. return 0;
  11465. free_data:
  11466. kfree(data->host[0]);
  11467. kfree(data->host[1]);
  11468. kfree(data);
  11469. fail:
  11470. return err;
  11471. }
  11472. static __devexit int advansys_eisa_remove(struct device *dev)
  11473. {
  11474. int i;
  11475. struct eisa_scsi_data *data = dev_get_drvdata(dev);
  11476. for (i = 0; i < 2; i++) {
  11477. int ioport;
  11478. struct Scsi_Host *shost = data->host[i];
  11479. if (!shost)
  11480. continue;
  11481. ioport = shost->io_port;
  11482. advansys_release(shost);
  11483. release_region(ioport, ASC_IOADR_GAP);
  11484. }
  11485. kfree(data);
  11486. return 0;
  11487. }
  11488. static struct eisa_driver advansys_eisa_driver = {
  11489. .id_table = advansys_eisa_table,
  11490. .driver = {
  11491. .name = DRV_NAME,
  11492. .probe = advansys_eisa_probe,
  11493. .remove = __devexit_p(advansys_eisa_remove),
  11494. }
  11495. };
  11496. /* PCI Devices supported by this driver */
  11497. static struct pci_device_id advansys_pci_tbl[] __devinitdata = {
  11498. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_1200A,
  11499. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11500. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940,
  11501. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11502. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940U,
  11503. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11504. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940UW,
  11505. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11506. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C0800_REV1,
  11507. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11508. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C1600_REV1,
  11509. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11510. {}
  11511. };
  11512. MODULE_DEVICE_TABLE(pci, advansys_pci_tbl);
  11513. static void __devinit advansys_set_latency(struct pci_dev *pdev)
  11514. {
  11515. if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
  11516. (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
  11517. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0);
  11518. } else {
  11519. u8 latency;
  11520. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
  11521. if (latency < 0x20)
  11522. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x20);
  11523. }
  11524. }
  11525. static int __devinit
  11526. advansys_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  11527. {
  11528. int err, ioport;
  11529. struct Scsi_Host *shost;
  11530. struct asc_board *board;
  11531. err = pci_enable_device(pdev);
  11532. if (err)
  11533. goto fail;
  11534. err = pci_request_regions(pdev, DRV_NAME);
  11535. if (err)
  11536. goto disable_device;
  11537. pci_set_master(pdev);
  11538. advansys_set_latency(pdev);
  11539. err = -ENODEV;
  11540. if (pci_resource_len(pdev, 0) == 0)
  11541. goto release_region;
  11542. ioport = pci_resource_start(pdev, 0);
  11543. err = -ENOMEM;
  11544. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  11545. if (!shost)
  11546. goto release_region;
  11547. board = shost_priv(shost);
  11548. board->irq = pdev->irq;
  11549. board->dev = &pdev->dev;
  11550. if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW ||
  11551. pdev->device == PCI_DEVICE_ID_38C0800_REV1 ||
  11552. pdev->device == PCI_DEVICE_ID_38C1600_REV1) {
  11553. board->flags |= ASC_IS_WIDE_BOARD;
  11554. }
  11555. err = advansys_board_found(shost, ioport, ASC_IS_PCI);
  11556. if (err)
  11557. goto free_host;
  11558. pci_set_drvdata(pdev, shost);
  11559. return 0;
  11560. free_host:
  11561. scsi_host_put(shost);
  11562. release_region:
  11563. pci_release_regions(pdev);
  11564. disable_device:
  11565. pci_disable_device(pdev);
  11566. fail:
  11567. return err;
  11568. }
  11569. static void __devexit advansys_pci_remove(struct pci_dev *pdev)
  11570. {
  11571. advansys_release(pci_get_drvdata(pdev));
  11572. pci_release_regions(pdev);
  11573. pci_disable_device(pdev);
  11574. }
  11575. static struct pci_driver advansys_pci_driver = {
  11576. .name = DRV_NAME,
  11577. .id_table = advansys_pci_tbl,
  11578. .probe = advansys_pci_probe,
  11579. .remove = __devexit_p(advansys_pci_remove),
  11580. };
  11581. static int __init advansys_init(void)
  11582. {
  11583. int error;
  11584. error = isa_register_driver(&advansys_isa_driver,
  11585. ASC_IOADR_TABLE_MAX_IX);
  11586. if (error)
  11587. goto fail;
  11588. error = isa_register_driver(&advansys_vlb_driver,
  11589. ASC_IOADR_TABLE_MAX_IX);
  11590. if (error)
  11591. goto unregister_isa;
  11592. error = eisa_driver_register(&advansys_eisa_driver);
  11593. if (error)
  11594. goto unregister_vlb;
  11595. error = pci_register_driver(&advansys_pci_driver);
  11596. if (error)
  11597. goto unregister_eisa;
  11598. return 0;
  11599. unregister_eisa:
  11600. eisa_driver_unregister(&advansys_eisa_driver);
  11601. unregister_vlb:
  11602. isa_unregister_driver(&advansys_vlb_driver);
  11603. unregister_isa:
  11604. isa_unregister_driver(&advansys_isa_driver);
  11605. fail:
  11606. return error;
  11607. }
  11608. static void __exit advansys_exit(void)
  11609. {
  11610. pci_unregister_driver(&advansys_pci_driver);
  11611. eisa_driver_unregister(&advansys_eisa_driver);
  11612. isa_unregister_driver(&advansys_vlb_driver);
  11613. isa_unregister_driver(&advansys_isa_driver);
  11614. }
  11615. module_init(advansys_init);
  11616. module_exit(advansys_exit);
  11617. MODULE_LICENSE("GPL");
  11618. MODULE_FIRMWARE("advansys/mcode.bin");
  11619. MODULE_FIRMWARE("advansys/3550.bin");
  11620. MODULE_FIRMWARE("advansys/38C0800.bin");
  11621. MODULE_FIRMWARE("advansys/38C1600.bin");