advansys.c 346 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868
  1. /*
  2. * advansys.c - Linux Host Driver for AdvanSys SCSI Adapters
  3. *
  4. * Copyright (c) 1995-2000 Advanced System Products, Inc.
  5. * Copyright (c) 2000-2001 ConnectCom Solutions, Inc.
  6. * Copyright (c) 2007 Matthew Wilcox <matthew@wil.cx>
  7. * Copyright (c) 2014 Hannes Reinecke <hare@suse.de>
  8. * All Rights Reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. */
  15. /*
  16. * As of March 8, 2000 Advanced System Products, Inc. (AdvanSys)
  17. * changed its name to ConnectCom Solutions, Inc.
  18. * On June 18, 2001 Initio Corp. acquired ConnectCom's SCSI assets
  19. */
  20. #include <linux/module.h>
  21. #include <linux/string.h>
  22. #include <linux/kernel.h>
  23. #include <linux/types.h>
  24. #include <linux/ioport.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/delay.h>
  27. #include <linux/slab.h>
  28. #include <linux/mm.h>
  29. #include <linux/proc_fs.h>
  30. #include <linux/init.h>
  31. #include <linux/blkdev.h>
  32. #include <linux/isa.h>
  33. #include <linux/eisa.h>
  34. #include <linux/pci.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/firmware.h>
  38. #include <linux/dmapool.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. #define DRV_NAME "advansys"
  47. #define ASC_VERSION "3.5" /* AdvanSys Driver Version */
  48. /* FIXME:
  49. *
  50. * 1. Use scsi_transport_spi
  51. * 2. advansys_info is not safe against multiple simultaneous callers
  52. * 3. Add module_param to override ISA/VLB ioport array
  53. */
  54. /* Enable driver /proc statistics. */
  55. #define ADVANSYS_STATS
  56. /* Enable driver tracing. */
  57. #undef ADVANSYS_DEBUG
  58. typedef unsigned char uchar;
  59. #define isodd_word(val) ((((uint)val) & (uint)0x0001) != 0)
  60. #define PCI_VENDOR_ID_ASP 0x10cd
  61. #define PCI_DEVICE_ID_ASP_1200A 0x1100
  62. #define PCI_DEVICE_ID_ASP_ABP940 0x1200
  63. #define PCI_DEVICE_ID_ASP_ABP940U 0x1300
  64. #define PCI_DEVICE_ID_ASP_ABP940UW 0x2300
  65. #define PCI_DEVICE_ID_38C0800_REV1 0x2500
  66. #define PCI_DEVICE_ID_38C1600_REV1 0x2700
  67. #define PortAddr unsigned int /* port address size */
  68. #define inp(port) inb(port)
  69. #define outp(port, byte) outb((byte), (port))
  70. #define inpw(port) inw(port)
  71. #define outpw(port, word) outw((word), (port))
  72. #define ASC_MAX_SG_QUEUE 7
  73. #define ASC_MAX_SG_LIST 255
  74. #define ASC_CS_TYPE unsigned short
  75. #define ASC_IS_ISA (0x0001)
  76. #define ASC_IS_ISAPNP (0x0081)
  77. #define ASC_IS_EISA (0x0002)
  78. #define ASC_IS_PCI (0x0004)
  79. #define ASC_IS_PCI_ULTRA (0x0104)
  80. #define ASC_IS_PCMCIA (0x0008)
  81. #define ASC_IS_MCA (0x0020)
  82. #define ASC_IS_VL (0x0040)
  83. #define ASC_IS_WIDESCSI_16 (0x0100)
  84. #define ASC_IS_WIDESCSI_32 (0x0200)
  85. #define ASC_IS_BIG_ENDIAN (0x8000)
  86. #define ASC_CHIP_MIN_VER_VL (0x01)
  87. #define ASC_CHIP_MAX_VER_VL (0x07)
  88. #define ASC_CHIP_MIN_VER_PCI (0x09)
  89. #define ASC_CHIP_MAX_VER_PCI (0x0F)
  90. #define ASC_CHIP_VER_PCI_BIT (0x08)
  91. #define ASC_CHIP_MIN_VER_ISA (0x11)
  92. #define ASC_CHIP_MIN_VER_ISA_PNP (0x21)
  93. #define ASC_CHIP_MAX_VER_ISA (0x27)
  94. #define ASC_CHIP_VER_ISA_BIT (0x30)
  95. #define ASC_CHIP_VER_ISAPNP_BIT (0x20)
  96. #define ASC_CHIP_VER_ASYN_BUG (0x21)
  97. #define ASC_CHIP_VER_PCI 0x08
  98. #define ASC_CHIP_VER_PCI_ULTRA_3150 (ASC_CHIP_VER_PCI | 0x02)
  99. #define ASC_CHIP_VER_PCI_ULTRA_3050 (ASC_CHIP_VER_PCI | 0x03)
  100. #define ASC_CHIP_MIN_VER_EISA (0x41)
  101. #define ASC_CHIP_MAX_VER_EISA (0x47)
  102. #define ASC_CHIP_VER_EISA_BIT (0x40)
  103. #define ASC_CHIP_LATEST_VER_EISA ((ASC_CHIP_MIN_VER_EISA - 1) + 3)
  104. #define ASC_MAX_VL_DMA_COUNT (0x07FFFFFFL)
  105. #define ASC_MAX_PCI_DMA_COUNT (0xFFFFFFFFL)
  106. #define ASC_MAX_ISA_DMA_COUNT (0x00FFFFFFL)
  107. #define ASC_SCSI_ID_BITS 3
  108. #define ASC_SCSI_TIX_TYPE uchar
  109. #define ASC_ALL_DEVICE_BIT_SET 0xFF
  110. #define ASC_SCSI_BIT_ID_TYPE uchar
  111. #define ASC_MAX_TID 7
  112. #define ASC_MAX_LUN 7
  113. #define ASC_SCSI_WIDTH_BIT_SET 0xFF
  114. #define ASC_MAX_SENSE_LEN 32
  115. #define ASC_MIN_SENSE_LEN 14
  116. #define ASC_SCSI_RESET_HOLD_TIME_US 60
  117. /*
  118. * Narrow boards only support 12-byte commands, while wide boards
  119. * extend to 16-byte commands.
  120. */
  121. #define ASC_MAX_CDB_LEN 12
  122. #define ADV_MAX_CDB_LEN 16
  123. #define MS_SDTR_LEN 0x03
  124. #define MS_WDTR_LEN 0x02
  125. #define ASC_SG_LIST_PER_Q 7
  126. #define QS_FREE 0x00
  127. #define QS_READY 0x01
  128. #define QS_DISC1 0x02
  129. #define QS_DISC2 0x04
  130. #define QS_BUSY 0x08
  131. #define QS_ABORTED 0x40
  132. #define QS_DONE 0x80
  133. #define QC_NO_CALLBACK 0x01
  134. #define QC_SG_SWAP_QUEUE 0x02
  135. #define QC_SG_HEAD 0x04
  136. #define QC_DATA_IN 0x08
  137. #define QC_DATA_OUT 0x10
  138. #define QC_URGENT 0x20
  139. #define QC_MSG_OUT 0x40
  140. #define QC_REQ_SENSE 0x80
  141. #define QCSG_SG_XFER_LIST 0x02
  142. #define QCSG_SG_XFER_MORE 0x04
  143. #define QCSG_SG_XFER_END 0x08
  144. #define QD_IN_PROGRESS 0x00
  145. #define QD_NO_ERROR 0x01
  146. #define QD_ABORTED_BY_HOST 0x02
  147. #define QD_WITH_ERROR 0x04
  148. #define QD_INVALID_REQUEST 0x80
  149. #define QD_INVALID_HOST_NUM 0x81
  150. #define QD_INVALID_DEVICE 0x82
  151. #define QD_ERR_INTERNAL 0xFF
  152. #define QHSTA_NO_ERROR 0x00
  153. #define QHSTA_M_SEL_TIMEOUT 0x11
  154. #define QHSTA_M_DATA_OVER_RUN 0x12
  155. #define QHSTA_M_DATA_UNDER_RUN 0x12
  156. #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
  157. #define QHSTA_M_BAD_BUS_PHASE_SEQ 0x14
  158. #define QHSTA_D_QDONE_SG_LIST_CORRUPTED 0x21
  159. #define QHSTA_D_ASC_DVC_ERROR_CODE_SET 0x22
  160. #define QHSTA_D_HOST_ABORT_FAILED 0x23
  161. #define QHSTA_D_EXE_SCSI_Q_FAILED 0x24
  162. #define QHSTA_D_EXE_SCSI_Q_BUSY_TIMEOUT 0x25
  163. #define QHSTA_D_ASPI_NO_BUF_POOL 0x26
  164. #define QHSTA_M_WTM_TIMEOUT 0x41
  165. #define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
  166. #define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
  167. #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
  168. #define QHSTA_M_TARGET_STATUS_BUSY 0x45
  169. #define QHSTA_M_BAD_TAG_CODE 0x46
  170. #define QHSTA_M_BAD_QUEUE_FULL_OR_BUSY 0x47
  171. #define QHSTA_M_HUNG_REQ_SCSI_BUS_RESET 0x48
  172. #define QHSTA_D_LRAM_CMP_ERROR 0x81
  173. #define QHSTA_M_MICRO_CODE_ERROR_HALT 0xA1
  174. #define ASC_FLAG_SCSIQ_REQ 0x01
  175. #define ASC_FLAG_BIOS_SCSIQ_REQ 0x02
  176. #define ASC_FLAG_BIOS_ASYNC_IO 0x04
  177. #define ASC_FLAG_SRB_LINEAR_ADDR 0x08
  178. #define ASC_FLAG_WIN16 0x10
  179. #define ASC_FLAG_WIN32 0x20
  180. #define ASC_FLAG_ISA_OVER_16MB 0x40
  181. #define ASC_FLAG_DOS_VM_CALLBACK 0x80
  182. #define ASC_TAG_FLAG_EXTRA_BYTES 0x10
  183. #define ASC_TAG_FLAG_DISABLE_DISCONNECT 0x04
  184. #define ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX 0x08
  185. #define ASC_TAG_FLAG_DISABLE_CHK_COND_INT_HOST 0x40
  186. #define ASC_SCSIQ_CPY_BEG 4
  187. #define ASC_SCSIQ_SGHD_CPY_BEG 2
  188. #define ASC_SCSIQ_B_FWD 0
  189. #define ASC_SCSIQ_B_BWD 1
  190. #define ASC_SCSIQ_B_STATUS 2
  191. #define ASC_SCSIQ_B_QNO 3
  192. #define ASC_SCSIQ_B_CNTL 4
  193. #define ASC_SCSIQ_B_SG_QUEUE_CNT 5
  194. #define ASC_SCSIQ_D_DATA_ADDR 8
  195. #define ASC_SCSIQ_D_DATA_CNT 12
  196. #define ASC_SCSIQ_B_SENSE_LEN 20
  197. #define ASC_SCSIQ_DONE_INFO_BEG 22
  198. #define ASC_SCSIQ_D_SRBPTR 22
  199. #define ASC_SCSIQ_B_TARGET_IX 26
  200. #define ASC_SCSIQ_B_CDB_LEN 28
  201. #define ASC_SCSIQ_B_TAG_CODE 29
  202. #define ASC_SCSIQ_W_VM_ID 30
  203. #define ASC_SCSIQ_DONE_STATUS 32
  204. #define ASC_SCSIQ_HOST_STATUS 33
  205. #define ASC_SCSIQ_SCSI_STATUS 34
  206. #define ASC_SCSIQ_CDB_BEG 36
  207. #define ASC_SCSIQ_DW_REMAIN_XFER_ADDR 56
  208. #define ASC_SCSIQ_DW_REMAIN_XFER_CNT 60
  209. #define ASC_SCSIQ_B_FIRST_SG_WK_QP 48
  210. #define ASC_SCSIQ_B_SG_WK_QP 49
  211. #define ASC_SCSIQ_B_SG_WK_IX 50
  212. #define ASC_SCSIQ_W_ALT_DC1 52
  213. #define ASC_SCSIQ_B_LIST_CNT 6
  214. #define ASC_SCSIQ_B_CUR_LIST_CNT 7
  215. #define ASC_SGQ_B_SG_CNTL 4
  216. #define ASC_SGQ_B_SG_HEAD_QP 5
  217. #define ASC_SGQ_B_SG_LIST_CNT 6
  218. #define ASC_SGQ_B_SG_CUR_LIST_CNT 7
  219. #define ASC_SGQ_LIST_BEG 8
  220. #define ASC_DEF_SCSI1_QNG 4
  221. #define ASC_MAX_SCSI1_QNG 4
  222. #define ASC_DEF_SCSI2_QNG 16
  223. #define ASC_MAX_SCSI2_QNG 32
  224. #define ASC_TAG_CODE_MASK 0x23
  225. #define ASC_STOP_REQ_RISC_STOP 0x01
  226. #define ASC_STOP_ACK_RISC_STOP 0x03
  227. #define ASC_STOP_CLEAN_UP_BUSY_Q 0x10
  228. #define ASC_STOP_CLEAN_UP_DISC_Q 0x20
  229. #define ASC_STOP_HOST_REQ_RISC_HALT 0x40
  230. #define ASC_TIDLUN_TO_IX(tid, lun) (ASC_SCSI_TIX_TYPE)((tid) + ((lun)<<ASC_SCSI_ID_BITS))
  231. #define ASC_TID_TO_TARGET_ID(tid) (ASC_SCSI_BIT_ID_TYPE)(0x01 << (tid))
  232. #define ASC_TIX_TO_TARGET_ID(tix) (0x01 << ((tix) & ASC_MAX_TID))
  233. #define ASC_TIX_TO_TID(tix) ((tix) & ASC_MAX_TID)
  234. #define ASC_TID_TO_TIX(tid) ((tid) & ASC_MAX_TID)
  235. #define ASC_TIX_TO_LUN(tix) (((tix) >> ASC_SCSI_ID_BITS) & ASC_MAX_LUN)
  236. #define ASC_QNO_TO_QADDR(q_no) ((ASC_QADR_BEG)+((int)(q_no) << 6))
  237. typedef struct asc_scsiq_1 {
  238. uchar status;
  239. uchar q_no;
  240. uchar cntl;
  241. uchar sg_queue_cnt;
  242. uchar target_id;
  243. uchar target_lun;
  244. __le32 data_addr;
  245. __le32 data_cnt;
  246. __le32 sense_addr;
  247. uchar sense_len;
  248. uchar extra_bytes;
  249. } ASC_SCSIQ_1;
  250. typedef struct asc_scsiq_2 {
  251. u32 srb_tag;
  252. uchar target_ix;
  253. uchar flag;
  254. uchar cdb_len;
  255. uchar tag_code;
  256. ushort vm_id;
  257. } ASC_SCSIQ_2;
  258. typedef struct asc_scsiq_3 {
  259. uchar done_stat;
  260. uchar host_stat;
  261. uchar scsi_stat;
  262. uchar scsi_msg;
  263. } ASC_SCSIQ_3;
  264. typedef struct asc_scsiq_4 {
  265. uchar cdb[ASC_MAX_CDB_LEN];
  266. uchar y_first_sg_list_qp;
  267. uchar y_working_sg_qp;
  268. uchar y_working_sg_ix;
  269. uchar y_res;
  270. ushort x_req_count;
  271. ushort x_reconnect_rtn;
  272. __le32 x_saved_data_addr;
  273. __le32 x_saved_data_cnt;
  274. } ASC_SCSIQ_4;
  275. typedef struct asc_q_done_info {
  276. ASC_SCSIQ_2 d2;
  277. ASC_SCSIQ_3 d3;
  278. uchar q_status;
  279. uchar q_no;
  280. uchar cntl;
  281. uchar sense_len;
  282. uchar extra_bytes;
  283. uchar res;
  284. u32 remain_bytes;
  285. } ASC_QDONE_INFO;
  286. typedef struct asc_sg_list {
  287. __le32 addr;
  288. __le32 bytes;
  289. } ASC_SG_LIST;
  290. typedef struct asc_sg_head {
  291. ushort entry_cnt;
  292. ushort queue_cnt;
  293. ushort entry_to_copy;
  294. ushort res;
  295. ASC_SG_LIST sg_list[0];
  296. } ASC_SG_HEAD;
  297. typedef struct asc_scsi_q {
  298. ASC_SCSIQ_1 q1;
  299. ASC_SCSIQ_2 q2;
  300. uchar *cdbptr;
  301. ASC_SG_HEAD *sg_head;
  302. ushort remain_sg_entry_cnt;
  303. ushort next_sg_index;
  304. } ASC_SCSI_Q;
  305. typedef struct asc_scsi_bios_req_q {
  306. ASC_SCSIQ_1 r1;
  307. ASC_SCSIQ_2 r2;
  308. uchar *cdbptr;
  309. ASC_SG_HEAD *sg_head;
  310. uchar *sense_ptr;
  311. ASC_SCSIQ_3 r3;
  312. uchar cdb[ASC_MAX_CDB_LEN];
  313. uchar sense[ASC_MIN_SENSE_LEN];
  314. } ASC_SCSI_BIOS_REQ_Q;
  315. typedef struct asc_risc_q {
  316. uchar fwd;
  317. uchar bwd;
  318. ASC_SCSIQ_1 i1;
  319. ASC_SCSIQ_2 i2;
  320. ASC_SCSIQ_3 i3;
  321. ASC_SCSIQ_4 i4;
  322. } ASC_RISC_Q;
  323. typedef struct asc_sg_list_q {
  324. uchar seq_no;
  325. uchar q_no;
  326. uchar cntl;
  327. uchar sg_head_qp;
  328. uchar sg_list_cnt;
  329. uchar sg_cur_list_cnt;
  330. } ASC_SG_LIST_Q;
  331. typedef struct asc_risc_sg_list_q {
  332. uchar fwd;
  333. uchar bwd;
  334. ASC_SG_LIST_Q sg;
  335. ASC_SG_LIST sg_list[7];
  336. } ASC_RISC_SG_LIST_Q;
  337. #define ASCQ_ERR_Q_STATUS 0x0D
  338. #define ASCQ_ERR_CUR_QNG 0x17
  339. #define ASCQ_ERR_SG_Q_LINKS 0x18
  340. #define ASCQ_ERR_ISR_RE_ENTRY 0x1A
  341. #define ASCQ_ERR_CRITICAL_RE_ENTRY 0x1B
  342. #define ASCQ_ERR_ISR_ON_CRITICAL 0x1C
  343. /*
  344. * Warning code values are set in ASC_DVC_VAR 'warn_code'.
  345. */
  346. #define ASC_WARN_NO_ERROR 0x0000
  347. #define ASC_WARN_IO_PORT_ROTATE 0x0001
  348. #define ASC_WARN_EEPROM_CHKSUM 0x0002
  349. #define ASC_WARN_IRQ_MODIFIED 0x0004
  350. #define ASC_WARN_AUTO_CONFIG 0x0008
  351. #define ASC_WARN_CMD_QNG_CONFLICT 0x0010
  352. #define ASC_WARN_EEPROM_RECOVER 0x0020
  353. #define ASC_WARN_CFG_MSW_RECOVER 0x0040
  354. /*
  355. * Error code values are set in {ASC/ADV}_DVC_VAR 'err_code'.
  356. */
  357. #define ASC_IERR_NO_CARRIER 0x0001 /* No more carrier memory */
  358. #define ASC_IERR_MCODE_CHKSUM 0x0002 /* micro code check sum error */
  359. #define ASC_IERR_SET_PC_ADDR 0x0004
  360. #define ASC_IERR_START_STOP_CHIP 0x0008 /* start/stop chip failed */
  361. #define ASC_IERR_ILLEGAL_CONNECTION 0x0010 /* Illegal cable connection */
  362. #define ASC_IERR_SINGLE_END_DEVICE 0x0020 /* SE device on DIFF bus */
  363. #define ASC_IERR_REVERSED_CABLE 0x0040 /* Narrow flat cable reversed */
  364. #define ASC_IERR_SET_SCSI_ID 0x0080 /* set SCSI ID failed */
  365. #define ASC_IERR_HVD_DEVICE 0x0100 /* HVD device on LVD port */
  366. #define ASC_IERR_BAD_SIGNATURE 0x0200 /* signature not found */
  367. #define ASC_IERR_NO_BUS_TYPE 0x0400
  368. #define ASC_IERR_BIST_PRE_TEST 0x0800 /* BIST pre-test error */
  369. #define ASC_IERR_BIST_RAM_TEST 0x1000 /* BIST RAM test error */
  370. #define ASC_IERR_BAD_CHIPTYPE 0x2000 /* Invalid chip_type setting */
  371. #define ASC_DEF_MAX_TOTAL_QNG (0xF0)
  372. #define ASC_MIN_TAG_Q_PER_DVC (0x04)
  373. #define ASC_MIN_FREE_Q (0x02)
  374. #define ASC_MIN_TOTAL_QNG ((ASC_MAX_SG_QUEUE)+(ASC_MIN_FREE_Q))
  375. #define ASC_MAX_TOTAL_QNG 240
  376. #define ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG 16
  377. #define ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG 8
  378. #define ASC_MAX_PCI_INRAM_TOTAL_QNG 20
  379. #define ASC_MAX_INRAM_TAG_QNG 16
  380. #define ASC_IOADR_GAP 0x10
  381. #define ASC_SYN_MAX_OFFSET 0x0F
  382. #define ASC_DEF_SDTR_OFFSET 0x0F
  383. #define ASC_SDTR_ULTRA_PCI_10MB_INDEX 0x02
  384. #define ASYN_SDTR_DATA_FIX_PCI_REV_AB 0x41
  385. /* The narrow chip only supports a limited selection of transfer rates.
  386. * These are encoded in the range 0..7 or 0..15 depending whether the chip
  387. * is Ultra-capable or not. These tables let us convert from one to the other.
  388. */
  389. static const unsigned char asc_syn_xfer_period[8] = {
  390. 25, 30, 35, 40, 50, 60, 70, 85
  391. };
  392. static const unsigned char asc_syn_ultra_xfer_period[16] = {
  393. 12, 19, 25, 32, 38, 44, 50, 57, 63, 69, 75, 82, 88, 94, 100, 107
  394. };
  395. typedef struct ext_msg {
  396. uchar msg_type;
  397. uchar msg_len;
  398. uchar msg_req;
  399. union {
  400. struct {
  401. uchar sdtr_xfer_period;
  402. uchar sdtr_req_ack_offset;
  403. } sdtr;
  404. struct {
  405. uchar wdtr_width;
  406. } wdtr;
  407. struct {
  408. uchar mdp_b3;
  409. uchar mdp_b2;
  410. uchar mdp_b1;
  411. uchar mdp_b0;
  412. } mdp;
  413. } u_ext_msg;
  414. uchar res;
  415. } EXT_MSG;
  416. #define xfer_period u_ext_msg.sdtr.sdtr_xfer_period
  417. #define req_ack_offset u_ext_msg.sdtr.sdtr_req_ack_offset
  418. #define wdtr_width u_ext_msg.wdtr.wdtr_width
  419. #define mdp_b3 u_ext_msg.mdp_b3
  420. #define mdp_b2 u_ext_msg.mdp_b2
  421. #define mdp_b1 u_ext_msg.mdp_b1
  422. #define mdp_b0 u_ext_msg.mdp_b0
  423. typedef struct asc_dvc_cfg {
  424. ASC_SCSI_BIT_ID_TYPE can_tagged_qng;
  425. ASC_SCSI_BIT_ID_TYPE cmd_qng_enabled;
  426. ASC_SCSI_BIT_ID_TYPE disc_enable;
  427. ASC_SCSI_BIT_ID_TYPE sdtr_enable;
  428. uchar chip_scsi_id;
  429. uchar isa_dma_speed;
  430. uchar isa_dma_channel;
  431. uchar chip_version;
  432. ushort mcode_date;
  433. ushort mcode_version;
  434. uchar max_tag_qng[ASC_MAX_TID + 1];
  435. uchar sdtr_period_offset[ASC_MAX_TID + 1];
  436. uchar adapter_info[6];
  437. } ASC_DVC_CFG;
  438. #define ASC_DEF_DVC_CNTL 0xFFFF
  439. #define ASC_DEF_CHIP_SCSI_ID 7
  440. #define ASC_DEF_ISA_DMA_SPEED 4
  441. #define ASC_INIT_STATE_BEG_GET_CFG 0x0001
  442. #define ASC_INIT_STATE_END_GET_CFG 0x0002
  443. #define ASC_INIT_STATE_BEG_SET_CFG 0x0004
  444. #define ASC_INIT_STATE_END_SET_CFG 0x0008
  445. #define ASC_INIT_STATE_BEG_LOAD_MC 0x0010
  446. #define ASC_INIT_STATE_END_LOAD_MC 0x0020
  447. #define ASC_INIT_STATE_BEG_INQUIRY 0x0040
  448. #define ASC_INIT_STATE_END_INQUIRY 0x0080
  449. #define ASC_INIT_RESET_SCSI_DONE 0x0100
  450. #define ASC_INIT_STATE_WITHOUT_EEP 0x8000
  451. #define ASC_BUG_FIX_IF_NOT_DWB 0x0001
  452. #define ASC_BUG_FIX_ASYN_USE_SYN 0x0002
  453. #define ASC_MIN_TAGGED_CMD 7
  454. #define ASC_MAX_SCSI_RESET_WAIT 30
  455. #define ASC_OVERRUN_BSIZE 64
  456. struct asc_dvc_var; /* Forward Declaration. */
  457. typedef struct asc_dvc_var {
  458. PortAddr iop_base;
  459. ushort err_code;
  460. ushort dvc_cntl;
  461. ushort bug_fix_cntl;
  462. ushort bus_type;
  463. ASC_SCSI_BIT_ID_TYPE init_sdtr;
  464. ASC_SCSI_BIT_ID_TYPE sdtr_done;
  465. ASC_SCSI_BIT_ID_TYPE use_tagged_qng;
  466. ASC_SCSI_BIT_ID_TYPE unit_not_ready;
  467. ASC_SCSI_BIT_ID_TYPE queue_full_or_busy;
  468. ASC_SCSI_BIT_ID_TYPE start_motor;
  469. uchar *overrun_buf;
  470. dma_addr_t overrun_dma;
  471. uchar scsi_reset_wait;
  472. uchar chip_no;
  473. bool is_in_int;
  474. uchar max_total_qng;
  475. uchar cur_total_qng;
  476. uchar in_critical_cnt;
  477. uchar last_q_shortage;
  478. ushort init_state;
  479. uchar cur_dvc_qng[ASC_MAX_TID + 1];
  480. uchar max_dvc_qng[ASC_MAX_TID + 1];
  481. ASC_SCSI_Q *scsiq_busy_head[ASC_MAX_TID + 1];
  482. ASC_SCSI_Q *scsiq_busy_tail[ASC_MAX_TID + 1];
  483. const uchar *sdtr_period_tbl;
  484. ASC_DVC_CFG *cfg;
  485. ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer_always;
  486. char redo_scam;
  487. ushort res2;
  488. uchar dos_int13_table[ASC_MAX_TID + 1];
  489. unsigned int max_dma_count;
  490. ASC_SCSI_BIT_ID_TYPE no_scam;
  491. ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer;
  492. uchar min_sdtr_index;
  493. uchar max_sdtr_index;
  494. struct asc_board *drv_ptr;
  495. unsigned int uc_break;
  496. } ASC_DVC_VAR;
  497. typedef struct asc_dvc_inq_info {
  498. uchar type[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
  499. } ASC_DVC_INQ_INFO;
  500. typedef struct asc_cap_info {
  501. u32 lba;
  502. u32 blk_size;
  503. } ASC_CAP_INFO;
  504. typedef struct asc_cap_info_array {
  505. ASC_CAP_INFO cap_info[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
  506. } ASC_CAP_INFO_ARRAY;
  507. #define ASC_MCNTL_NO_SEL_TIMEOUT (ushort)0x0001
  508. #define ASC_MCNTL_NULL_TARGET (ushort)0x0002
  509. #define ASC_CNTL_INITIATOR (ushort)0x0001
  510. #define ASC_CNTL_BIOS_GT_1GB (ushort)0x0002
  511. #define ASC_CNTL_BIOS_GT_2_DISK (ushort)0x0004
  512. #define ASC_CNTL_BIOS_REMOVABLE (ushort)0x0008
  513. #define ASC_CNTL_NO_SCAM (ushort)0x0010
  514. #define ASC_CNTL_INT_MULTI_Q (ushort)0x0080
  515. #define ASC_CNTL_NO_LUN_SUPPORT (ushort)0x0040
  516. #define ASC_CNTL_NO_VERIFY_COPY (ushort)0x0100
  517. #define ASC_CNTL_RESET_SCSI (ushort)0x0200
  518. #define ASC_CNTL_INIT_INQUIRY (ushort)0x0400
  519. #define ASC_CNTL_INIT_VERBOSE (ushort)0x0800
  520. #define ASC_CNTL_SCSI_PARITY (ushort)0x1000
  521. #define ASC_CNTL_BURST_MODE (ushort)0x2000
  522. #define ASC_CNTL_SDTR_ENABLE_ULTRA (ushort)0x4000
  523. #define ASC_EEP_DVC_CFG_BEG_VL 2
  524. #define ASC_EEP_MAX_DVC_ADDR_VL 15
  525. #define ASC_EEP_DVC_CFG_BEG 32
  526. #define ASC_EEP_MAX_DVC_ADDR 45
  527. #define ASC_EEP_MAX_RETRY 20
  528. /*
  529. * These macros keep the chip SCSI id and ISA DMA speed
  530. * bitfields in board order. C bitfields aren't portable
  531. * between big and little-endian platforms so they are
  532. * not used.
  533. */
  534. #define ASC_EEP_GET_CHIP_ID(cfg) ((cfg)->id_speed & 0x0f)
  535. #define ASC_EEP_GET_DMA_SPD(cfg) (((cfg)->id_speed & 0xf0) >> 4)
  536. #define ASC_EEP_SET_CHIP_ID(cfg, sid) \
  537. ((cfg)->id_speed = ((cfg)->id_speed & 0xf0) | ((sid) & ASC_MAX_TID))
  538. #define ASC_EEP_SET_DMA_SPD(cfg, spd) \
  539. ((cfg)->id_speed = ((cfg)->id_speed & 0x0f) | ((spd) & 0x0f) << 4)
  540. typedef struct asceep_config {
  541. ushort cfg_lsw;
  542. ushort cfg_msw;
  543. uchar init_sdtr;
  544. uchar disc_enable;
  545. uchar use_cmd_qng;
  546. uchar start_motor;
  547. uchar max_total_qng;
  548. uchar max_tag_qng;
  549. uchar bios_scan;
  550. uchar power_up_wait;
  551. uchar no_scam;
  552. uchar id_speed; /* low order 4 bits is chip scsi id */
  553. /* high order 4 bits is isa dma speed */
  554. uchar dos_int13_table[ASC_MAX_TID + 1];
  555. uchar adapter_info[6];
  556. ushort cntl;
  557. ushort chksum;
  558. } ASCEEP_CONFIG;
  559. #define ASC_EEP_CMD_READ 0x80
  560. #define ASC_EEP_CMD_WRITE 0x40
  561. #define ASC_EEP_CMD_WRITE_ABLE 0x30
  562. #define ASC_EEP_CMD_WRITE_DISABLE 0x00
  563. #define ASCV_MSGOUT_BEG 0x0000
  564. #define ASCV_MSGOUT_SDTR_PERIOD (ASCV_MSGOUT_BEG+3)
  565. #define ASCV_MSGOUT_SDTR_OFFSET (ASCV_MSGOUT_BEG+4)
  566. #define ASCV_BREAK_SAVED_CODE (ushort)0x0006
  567. #define ASCV_MSGIN_BEG (ASCV_MSGOUT_BEG+8)
  568. #define ASCV_MSGIN_SDTR_PERIOD (ASCV_MSGIN_BEG+3)
  569. #define ASCV_MSGIN_SDTR_OFFSET (ASCV_MSGIN_BEG+4)
  570. #define ASCV_SDTR_DATA_BEG (ASCV_MSGIN_BEG+8)
  571. #define ASCV_SDTR_DONE_BEG (ASCV_SDTR_DATA_BEG+8)
  572. #define ASCV_MAX_DVC_QNG_BEG (ushort)0x0020
  573. #define ASCV_BREAK_ADDR (ushort)0x0028
  574. #define ASCV_BREAK_NOTIFY_COUNT (ushort)0x002A
  575. #define ASCV_BREAK_CONTROL (ushort)0x002C
  576. #define ASCV_BREAK_HIT_COUNT (ushort)0x002E
  577. #define ASCV_ASCDVC_ERR_CODE_W (ushort)0x0030
  578. #define ASCV_MCODE_CHKSUM_W (ushort)0x0032
  579. #define ASCV_MCODE_SIZE_W (ushort)0x0034
  580. #define ASCV_STOP_CODE_B (ushort)0x0036
  581. #define ASCV_DVC_ERR_CODE_B (ushort)0x0037
  582. #define ASCV_OVERRUN_PADDR_D (ushort)0x0038
  583. #define ASCV_OVERRUN_BSIZE_D (ushort)0x003C
  584. #define ASCV_HALTCODE_W (ushort)0x0040
  585. #define ASCV_CHKSUM_W (ushort)0x0042
  586. #define ASCV_MC_DATE_W (ushort)0x0044
  587. #define ASCV_MC_VER_W (ushort)0x0046
  588. #define ASCV_NEXTRDY_B (ushort)0x0048
  589. #define ASCV_DONENEXT_B (ushort)0x0049
  590. #define ASCV_USE_TAGGED_QNG_B (ushort)0x004A
  591. #define ASCV_SCSIBUSY_B (ushort)0x004B
  592. #define ASCV_Q_DONE_IN_PROGRESS_B (ushort)0x004C
  593. #define ASCV_CURCDB_B (ushort)0x004D
  594. #define ASCV_RCLUN_B (ushort)0x004E
  595. #define ASCV_BUSY_QHEAD_B (ushort)0x004F
  596. #define ASCV_DISC1_QHEAD_B (ushort)0x0050
  597. #define ASCV_DISC_ENABLE_B (ushort)0x0052
  598. #define ASCV_CAN_TAGGED_QNG_B (ushort)0x0053
  599. #define ASCV_HOSTSCSI_ID_B (ushort)0x0055
  600. #define ASCV_MCODE_CNTL_B (ushort)0x0056
  601. #define ASCV_NULL_TARGET_B (ushort)0x0057
  602. #define ASCV_FREE_Q_HEAD_W (ushort)0x0058
  603. #define ASCV_DONE_Q_TAIL_W (ushort)0x005A
  604. #define ASCV_FREE_Q_HEAD_B (ushort)(ASCV_FREE_Q_HEAD_W+1)
  605. #define ASCV_DONE_Q_TAIL_B (ushort)(ASCV_DONE_Q_TAIL_W+1)
  606. #define ASCV_HOST_FLAG_B (ushort)0x005D
  607. #define ASCV_TOTAL_READY_Q_B (ushort)0x0064
  608. #define ASCV_VER_SERIAL_B (ushort)0x0065
  609. #define ASCV_HALTCODE_SAVED_W (ushort)0x0066
  610. #define ASCV_WTM_FLAG_B (ushort)0x0068
  611. #define ASCV_RISC_FLAG_B (ushort)0x006A
  612. #define ASCV_REQ_SG_LIST_QP (ushort)0x006B
  613. #define ASC_HOST_FLAG_IN_ISR 0x01
  614. #define ASC_HOST_FLAG_ACK_INT 0x02
  615. #define ASC_RISC_FLAG_GEN_INT 0x01
  616. #define ASC_RISC_FLAG_REQ_SG_LIST 0x02
  617. #define IOP_CTRL (0x0F)
  618. #define IOP_STATUS (0x0E)
  619. #define IOP_INT_ACK IOP_STATUS
  620. #define IOP_REG_IFC (0x0D)
  621. #define IOP_SYN_OFFSET (0x0B)
  622. #define IOP_EXTRA_CONTROL (0x0D)
  623. #define IOP_REG_PC (0x0C)
  624. #define IOP_RAM_ADDR (0x0A)
  625. #define IOP_RAM_DATA (0x08)
  626. #define IOP_EEP_DATA (0x06)
  627. #define IOP_EEP_CMD (0x07)
  628. #define IOP_VERSION (0x03)
  629. #define IOP_CONFIG_HIGH (0x04)
  630. #define IOP_CONFIG_LOW (0x02)
  631. #define IOP_SIG_BYTE (0x01)
  632. #define IOP_SIG_WORD (0x00)
  633. #define IOP_REG_DC1 (0x0E)
  634. #define IOP_REG_DC0 (0x0C)
  635. #define IOP_REG_SB (0x0B)
  636. #define IOP_REG_DA1 (0x0A)
  637. #define IOP_REG_DA0 (0x08)
  638. #define IOP_REG_SC (0x09)
  639. #define IOP_DMA_SPEED (0x07)
  640. #define IOP_REG_FLAG (0x07)
  641. #define IOP_FIFO_H (0x06)
  642. #define IOP_FIFO_L (0x04)
  643. #define IOP_REG_ID (0x05)
  644. #define IOP_REG_QP (0x03)
  645. #define IOP_REG_IH (0x02)
  646. #define IOP_REG_IX (0x01)
  647. #define IOP_REG_AX (0x00)
  648. #define IFC_REG_LOCK (0x00)
  649. #define IFC_REG_UNLOCK (0x09)
  650. #define IFC_WR_EN_FILTER (0x10)
  651. #define IFC_RD_NO_EEPROM (0x10)
  652. #define IFC_SLEW_RATE (0x20)
  653. #define IFC_ACT_NEG (0x40)
  654. #define IFC_INP_FILTER (0x80)
  655. #define IFC_INIT_DEFAULT (IFC_ACT_NEG | IFC_REG_UNLOCK)
  656. #define SC_SEL (uchar)(0x80)
  657. #define SC_BSY (uchar)(0x40)
  658. #define SC_ACK (uchar)(0x20)
  659. #define SC_REQ (uchar)(0x10)
  660. #define SC_ATN (uchar)(0x08)
  661. #define SC_IO (uchar)(0x04)
  662. #define SC_CD (uchar)(0x02)
  663. #define SC_MSG (uchar)(0x01)
  664. #define SEC_SCSI_CTL (uchar)(0x80)
  665. #define SEC_ACTIVE_NEGATE (uchar)(0x40)
  666. #define SEC_SLEW_RATE (uchar)(0x20)
  667. #define SEC_ENABLE_FILTER (uchar)(0x10)
  668. #define ASC_HALT_EXTMSG_IN (ushort)0x8000
  669. #define ASC_HALT_CHK_CONDITION (ushort)0x8100
  670. #define ASC_HALT_SS_QUEUE_FULL (ushort)0x8200
  671. #define ASC_HALT_DISABLE_ASYN_USE_SYN_FIX (ushort)0x8300
  672. #define ASC_HALT_ENABLE_ASYN_USE_SYN_FIX (ushort)0x8400
  673. #define ASC_HALT_SDTR_REJECTED (ushort)0x4000
  674. #define ASC_HALT_HOST_COPY_SG_LIST_TO_RISC ( ushort )0x2000
  675. #define ASC_MAX_QNO 0xF8
  676. #define ASC_DATA_SEC_BEG (ushort)0x0080
  677. #define ASC_DATA_SEC_END (ushort)0x0080
  678. #define ASC_CODE_SEC_BEG (ushort)0x0080
  679. #define ASC_CODE_SEC_END (ushort)0x0080
  680. #define ASC_QADR_BEG (0x4000)
  681. #define ASC_QADR_USED (ushort)(ASC_MAX_QNO * 64)
  682. #define ASC_QADR_END (ushort)0x7FFF
  683. #define ASC_QLAST_ADR (ushort)0x7FC0
  684. #define ASC_QBLK_SIZE 0x40
  685. #define ASC_BIOS_DATA_QBEG 0xF8
  686. #define ASC_MIN_ACTIVE_QNO 0x01
  687. #define ASC_QLINK_END 0xFF
  688. #define ASC_EEPROM_WORDS 0x10
  689. #define ASC_MAX_MGS_LEN 0x10
  690. #define ASC_BIOS_ADDR_DEF 0xDC00
  691. #define ASC_BIOS_SIZE 0x3800
  692. #define ASC_BIOS_RAM_OFF 0x3800
  693. #define ASC_BIOS_RAM_SIZE 0x800
  694. #define ASC_BIOS_MIN_ADDR 0xC000
  695. #define ASC_BIOS_MAX_ADDR 0xEC00
  696. #define ASC_BIOS_BANK_SIZE 0x0400
  697. #define ASC_MCODE_START_ADDR 0x0080
  698. #define ASC_CFG0_HOST_INT_ON 0x0020
  699. #define ASC_CFG0_BIOS_ON 0x0040
  700. #define ASC_CFG0_VERA_BURST_ON 0x0080
  701. #define ASC_CFG0_SCSI_PARITY_ON 0x0800
  702. #define ASC_CFG1_SCSI_TARGET_ON 0x0080
  703. #define ASC_CFG1_LRAM_8BITS_ON 0x0800
  704. #define ASC_CFG_MSW_CLR_MASK 0x3080
  705. #define CSW_TEST1 (ASC_CS_TYPE)0x8000
  706. #define CSW_AUTO_CONFIG (ASC_CS_TYPE)0x4000
  707. #define CSW_RESERVED1 (ASC_CS_TYPE)0x2000
  708. #define CSW_IRQ_WRITTEN (ASC_CS_TYPE)0x1000
  709. #define CSW_33MHZ_SELECTED (ASC_CS_TYPE)0x0800
  710. #define CSW_TEST2 (ASC_CS_TYPE)0x0400
  711. #define CSW_TEST3 (ASC_CS_TYPE)0x0200
  712. #define CSW_RESERVED2 (ASC_CS_TYPE)0x0100
  713. #define CSW_DMA_DONE (ASC_CS_TYPE)0x0080
  714. #define CSW_FIFO_RDY (ASC_CS_TYPE)0x0040
  715. #define CSW_EEP_READ_DONE (ASC_CS_TYPE)0x0020
  716. #define CSW_HALTED (ASC_CS_TYPE)0x0010
  717. #define CSW_SCSI_RESET_ACTIVE (ASC_CS_TYPE)0x0008
  718. #define CSW_PARITY_ERR (ASC_CS_TYPE)0x0004
  719. #define CSW_SCSI_RESET_LATCH (ASC_CS_TYPE)0x0002
  720. #define CSW_INT_PENDING (ASC_CS_TYPE)0x0001
  721. #define CIW_CLR_SCSI_RESET_INT (ASC_CS_TYPE)0x1000
  722. #define CIW_INT_ACK (ASC_CS_TYPE)0x0100
  723. #define CIW_TEST1 (ASC_CS_TYPE)0x0200
  724. #define CIW_TEST2 (ASC_CS_TYPE)0x0400
  725. #define CIW_SEL_33MHZ (ASC_CS_TYPE)0x0800
  726. #define CIW_IRQ_ACT (ASC_CS_TYPE)0x1000
  727. #define CC_CHIP_RESET (uchar)0x80
  728. #define CC_SCSI_RESET (uchar)0x40
  729. #define CC_HALT (uchar)0x20
  730. #define CC_SINGLE_STEP (uchar)0x10
  731. #define CC_DMA_ABLE (uchar)0x08
  732. #define CC_TEST (uchar)0x04
  733. #define CC_BANK_ONE (uchar)0x02
  734. #define CC_DIAG (uchar)0x01
  735. #define ASC_1000_ID0W 0x04C1
  736. #define ASC_1000_ID0W_FIX 0x00C1
  737. #define ASC_1000_ID1B 0x25
  738. #define ASC_EISA_REV_IOP_MASK (0x0C83)
  739. #define ASC_EISA_CFG_IOP_MASK (0x0C86)
  740. #define ASC_GET_EISA_SLOT(iop) (PortAddr)((iop) & 0xF000)
  741. #define INS_HALTINT (ushort)0x6281
  742. #define INS_HALT (ushort)0x6280
  743. #define INS_SINT (ushort)0x6200
  744. #define INS_RFLAG_WTM (ushort)0x7380
  745. #define ASC_MC_SAVE_CODE_WSIZE 0x500
  746. #define ASC_MC_SAVE_DATA_WSIZE 0x40
  747. typedef struct asc_mc_saved {
  748. ushort data[ASC_MC_SAVE_DATA_WSIZE];
  749. ushort code[ASC_MC_SAVE_CODE_WSIZE];
  750. } ASC_MC_SAVED;
  751. #define AscGetQDoneInProgress(port) AscReadLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B)
  752. #define AscPutQDoneInProgress(port, val) AscWriteLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B, val)
  753. #define AscGetVarFreeQHead(port) AscReadLramWord((port), ASCV_FREE_Q_HEAD_W)
  754. #define AscGetVarDoneQTail(port) AscReadLramWord((port), ASCV_DONE_Q_TAIL_W)
  755. #define AscPutVarFreeQHead(port, val) AscWriteLramWord((port), ASCV_FREE_Q_HEAD_W, val)
  756. #define AscPutVarDoneQTail(port, val) AscWriteLramWord((port), ASCV_DONE_Q_TAIL_W, val)
  757. #define AscGetRiscVarFreeQHead(port) AscReadLramByte((port), ASCV_NEXTRDY_B)
  758. #define AscGetRiscVarDoneQTail(port) AscReadLramByte((port), ASCV_DONENEXT_B)
  759. #define AscPutRiscVarFreeQHead(port, val) AscWriteLramByte((port), ASCV_NEXTRDY_B, val)
  760. #define AscPutRiscVarDoneQTail(port, val) AscWriteLramByte((port), ASCV_DONENEXT_B, val)
  761. #define AscPutMCodeSDTRDoneAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id), (data))
  762. #define AscGetMCodeSDTRDoneAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id))
  763. #define AscPutMCodeInitSDTRAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id), data)
  764. #define AscGetMCodeInitSDTRAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id))
  765. #define AscGetChipSignatureByte(port) (uchar)inp((port)+IOP_SIG_BYTE)
  766. #define AscGetChipSignatureWord(port) (ushort)inpw((port)+IOP_SIG_WORD)
  767. #define AscGetChipVerNo(port) (uchar)inp((port)+IOP_VERSION)
  768. #define AscGetChipCfgLsw(port) (ushort)inpw((port)+IOP_CONFIG_LOW)
  769. #define AscGetChipCfgMsw(port) (ushort)inpw((port)+IOP_CONFIG_HIGH)
  770. #define AscSetChipCfgLsw(port, data) outpw((port)+IOP_CONFIG_LOW, data)
  771. #define AscSetChipCfgMsw(port, data) outpw((port)+IOP_CONFIG_HIGH, data)
  772. #define AscGetChipEEPCmd(port) (uchar)inp((port)+IOP_EEP_CMD)
  773. #define AscSetChipEEPCmd(port, data) outp((port)+IOP_EEP_CMD, data)
  774. #define AscGetChipEEPData(port) (ushort)inpw((port)+IOP_EEP_DATA)
  775. #define AscSetChipEEPData(port, data) outpw((port)+IOP_EEP_DATA, data)
  776. #define AscGetChipLramAddr(port) (ushort)inpw((PortAddr)((port)+IOP_RAM_ADDR))
  777. #define AscSetChipLramAddr(port, addr) outpw((PortAddr)((port)+IOP_RAM_ADDR), addr)
  778. #define AscGetChipLramData(port) (ushort)inpw((port)+IOP_RAM_DATA)
  779. #define AscSetChipLramData(port, data) outpw((port)+IOP_RAM_DATA, data)
  780. #define AscGetChipIFC(port) (uchar)inp((port)+IOP_REG_IFC)
  781. #define AscSetChipIFC(port, data) outp((port)+IOP_REG_IFC, data)
  782. #define AscGetChipStatus(port) (ASC_CS_TYPE)inpw((port)+IOP_STATUS)
  783. #define AscSetChipStatus(port, cs_val) outpw((port)+IOP_STATUS, cs_val)
  784. #define AscGetChipControl(port) (uchar)inp((port)+IOP_CTRL)
  785. #define AscSetChipControl(port, cc_val) outp((port)+IOP_CTRL, cc_val)
  786. #define AscGetChipSyn(port) (uchar)inp((port)+IOP_SYN_OFFSET)
  787. #define AscSetChipSyn(port, data) outp((port)+IOP_SYN_OFFSET, data)
  788. #define AscSetPCAddr(port, data) outpw((port)+IOP_REG_PC, data)
  789. #define AscGetPCAddr(port) (ushort)inpw((port)+IOP_REG_PC)
  790. #define AscIsIntPending(port) (AscGetChipStatus(port) & (CSW_INT_PENDING | CSW_SCSI_RESET_LATCH))
  791. #define AscGetChipScsiID(port) ((AscGetChipCfgLsw(port) >> 8) & ASC_MAX_TID)
  792. #define AscGetExtraControl(port) (uchar)inp((port)+IOP_EXTRA_CONTROL)
  793. #define AscSetExtraControl(port, data) outp((port)+IOP_EXTRA_CONTROL, data)
  794. #define AscReadChipAX(port) (ushort)inpw((port)+IOP_REG_AX)
  795. #define AscWriteChipAX(port, data) outpw((port)+IOP_REG_AX, data)
  796. #define AscReadChipIX(port) (uchar)inp((port)+IOP_REG_IX)
  797. #define AscWriteChipIX(port, data) outp((port)+IOP_REG_IX, data)
  798. #define AscReadChipIH(port) (ushort)inpw((port)+IOP_REG_IH)
  799. #define AscWriteChipIH(port, data) outpw((port)+IOP_REG_IH, data)
  800. #define AscReadChipQP(port) (uchar)inp((port)+IOP_REG_QP)
  801. #define AscWriteChipQP(port, data) outp((port)+IOP_REG_QP, data)
  802. #define AscReadChipFIFO_L(port) (ushort)inpw((port)+IOP_REG_FIFO_L)
  803. #define AscWriteChipFIFO_L(port, data) outpw((port)+IOP_REG_FIFO_L, data)
  804. #define AscReadChipFIFO_H(port) (ushort)inpw((port)+IOP_REG_FIFO_H)
  805. #define AscWriteChipFIFO_H(port, data) outpw((port)+IOP_REG_FIFO_H, data)
  806. #define AscReadChipDmaSpeed(port) (uchar)inp((port)+IOP_DMA_SPEED)
  807. #define AscWriteChipDmaSpeed(port, data) outp((port)+IOP_DMA_SPEED, data)
  808. #define AscReadChipDA0(port) (ushort)inpw((port)+IOP_REG_DA0)
  809. #define AscWriteChipDA0(port) outpw((port)+IOP_REG_DA0, data)
  810. #define AscReadChipDA1(port) (ushort)inpw((port)+IOP_REG_DA1)
  811. #define AscWriteChipDA1(port) outpw((port)+IOP_REG_DA1, data)
  812. #define AscReadChipDC0(port) (ushort)inpw((port)+IOP_REG_DC0)
  813. #define AscWriteChipDC0(port) outpw((port)+IOP_REG_DC0, data)
  814. #define AscReadChipDC1(port) (ushort)inpw((port)+IOP_REG_DC1)
  815. #define AscWriteChipDC1(port) outpw((port)+IOP_REG_DC1, data)
  816. #define AscReadChipDvcID(port) (uchar)inp((port)+IOP_REG_ID)
  817. #define AscWriteChipDvcID(port, data) outp((port)+IOP_REG_ID, data)
  818. #define AdvPortAddr void __iomem * /* Virtual memory address size */
  819. /*
  820. * Define Adv Library required memory access macros.
  821. */
  822. #define ADV_MEM_READB(addr) readb(addr)
  823. #define ADV_MEM_READW(addr) readw(addr)
  824. #define ADV_MEM_WRITEB(addr, byte) writeb(byte, addr)
  825. #define ADV_MEM_WRITEW(addr, word) writew(word, addr)
  826. #define ADV_MEM_WRITEDW(addr, dword) writel(dword, addr)
  827. /*
  828. * Define total number of simultaneous maximum element scatter-gather
  829. * request blocks per wide adapter. ASC_DEF_MAX_HOST_QNG (253) is the
  830. * maximum number of outstanding commands per wide host adapter. Each
  831. * command uses one or more ADV_SG_BLOCK each with 15 scatter-gather
  832. * elements. Allow each command to have at least one ADV_SG_BLOCK structure.
  833. * This allows about 15 commands to have the maximum 17 ADV_SG_BLOCK
  834. * structures or 255 scatter-gather elements.
  835. */
  836. #define ADV_TOT_SG_BLOCK ASC_DEF_MAX_HOST_QNG
  837. /*
  838. * Define maximum number of scatter-gather elements per request.
  839. */
  840. #define ADV_MAX_SG_LIST 255
  841. #define NO_OF_SG_PER_BLOCK 15
  842. #define ADV_EEP_DVC_CFG_BEGIN (0x00)
  843. #define ADV_EEP_DVC_CFG_END (0x15)
  844. #define ADV_EEP_DVC_CTL_BEGIN (0x16) /* location of OEM name */
  845. #define ADV_EEP_MAX_WORD_ADDR (0x1E)
  846. #define ADV_EEP_DELAY_MS 100
  847. #define ADV_EEPROM_BIG_ENDIAN 0x8000 /* EEPROM Bit 15 */
  848. #define ADV_EEPROM_BIOS_ENABLE 0x4000 /* EEPROM Bit 14 */
  849. /*
  850. * For the ASC3550 Bit 13 is Termination Polarity control bit.
  851. * For later ICs Bit 13 controls whether the CIS (Card Information
  852. * Service Section) is loaded from EEPROM.
  853. */
  854. #define ADV_EEPROM_TERM_POL 0x2000 /* EEPROM Bit 13 */
  855. #define ADV_EEPROM_CIS_LD 0x2000 /* EEPROM Bit 13 */
  856. /*
  857. * ASC38C1600 Bit 11
  858. *
  859. * If EEPROM Bit 11 is 0 for Function 0, then Function 0 will specify
  860. * INT A in the PCI Configuration Space Int Pin field. If it is 1, then
  861. * Function 0 will specify INT B.
  862. *
  863. * If EEPROM Bit 11 is 0 for Function 1, then Function 1 will specify
  864. * INT B in the PCI Configuration Space Int Pin field. If it is 1, then
  865. * Function 1 will specify INT A.
  866. */
  867. #define ADV_EEPROM_INTAB 0x0800 /* EEPROM Bit 11 */
  868. typedef struct adveep_3550_config {
  869. /* Word Offset, Description */
  870. ushort cfg_lsw; /* 00 power up initialization */
  871. /* bit 13 set - Term Polarity Control */
  872. /* bit 14 set - BIOS Enable */
  873. /* bit 15 set - Big Endian Mode */
  874. ushort cfg_msw; /* 01 unused */
  875. ushort disc_enable; /* 02 disconnect enable */
  876. ushort wdtr_able; /* 03 Wide DTR able */
  877. ushort sdtr_able; /* 04 Synchronous DTR able */
  878. ushort start_motor; /* 05 send start up motor */
  879. ushort tagqng_able; /* 06 tag queuing able */
  880. ushort bios_scan; /* 07 BIOS device control */
  881. ushort scam_tolerant; /* 08 no scam */
  882. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  883. uchar bios_boot_delay; /* power up wait */
  884. uchar scsi_reset_delay; /* 10 reset delay */
  885. uchar bios_id_lun; /* first boot device scsi id & lun */
  886. /* high nibble is lun */
  887. /* low nibble is scsi id */
  888. uchar termination; /* 11 0 - automatic */
  889. /* 1 - low off / high off */
  890. /* 2 - low off / high on */
  891. /* 3 - low on / high on */
  892. /* There is no low on / high off */
  893. uchar reserved1; /* reserved byte (not used) */
  894. ushort bios_ctrl; /* 12 BIOS control bits */
  895. /* bit 0 BIOS don't act as initiator. */
  896. /* bit 1 BIOS > 1 GB support */
  897. /* bit 2 BIOS > 2 Disk Support */
  898. /* bit 3 BIOS don't support removables */
  899. /* bit 4 BIOS support bootable CD */
  900. /* bit 5 BIOS scan enabled */
  901. /* bit 6 BIOS support multiple LUNs */
  902. /* bit 7 BIOS display of message */
  903. /* bit 8 SCAM disabled */
  904. /* bit 9 Reset SCSI bus during init. */
  905. /* bit 10 */
  906. /* bit 11 No verbose initialization. */
  907. /* bit 12 SCSI parity enabled */
  908. /* bit 13 */
  909. /* bit 14 */
  910. /* bit 15 */
  911. ushort ultra_able; /* 13 ULTRA speed able */
  912. ushort reserved2; /* 14 reserved */
  913. uchar max_host_qng; /* 15 maximum host queuing */
  914. uchar max_dvc_qng; /* maximum per device queuing */
  915. ushort dvc_cntl; /* 16 control bit for driver */
  916. ushort bug_fix; /* 17 control bit for bug fix */
  917. ushort serial_number_word1; /* 18 Board serial number word 1 */
  918. ushort serial_number_word2; /* 19 Board serial number word 2 */
  919. ushort serial_number_word3; /* 20 Board serial number word 3 */
  920. ushort check_sum; /* 21 EEP check sum */
  921. uchar oem_name[16]; /* 22 OEM name */
  922. ushort dvc_err_code; /* 30 last device driver error code */
  923. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  924. ushort adv_err_addr; /* 32 last uc error address */
  925. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  926. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  927. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  928. ushort num_of_err; /* 36 number of error */
  929. } ADVEEP_3550_CONFIG;
  930. typedef struct adveep_38C0800_config {
  931. /* Word Offset, Description */
  932. ushort cfg_lsw; /* 00 power up initialization */
  933. /* bit 13 set - Load CIS */
  934. /* bit 14 set - BIOS Enable */
  935. /* bit 15 set - Big Endian Mode */
  936. ushort cfg_msw; /* 01 unused */
  937. ushort disc_enable; /* 02 disconnect enable */
  938. ushort wdtr_able; /* 03 Wide DTR able */
  939. ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
  940. ushort start_motor; /* 05 send start up motor */
  941. ushort tagqng_able; /* 06 tag queuing able */
  942. ushort bios_scan; /* 07 BIOS device control */
  943. ushort scam_tolerant; /* 08 no scam */
  944. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  945. uchar bios_boot_delay; /* power up wait */
  946. uchar scsi_reset_delay; /* 10 reset delay */
  947. uchar bios_id_lun; /* first boot device scsi id & lun */
  948. /* high nibble is lun */
  949. /* low nibble is scsi id */
  950. uchar termination_se; /* 11 0 - automatic */
  951. /* 1 - low off / high off */
  952. /* 2 - low off / high on */
  953. /* 3 - low on / high on */
  954. /* There is no low on / high off */
  955. uchar termination_lvd; /* 11 0 - automatic */
  956. /* 1 - low off / high off */
  957. /* 2 - low off / high on */
  958. /* 3 - low on / high on */
  959. /* There is no low on / high off */
  960. ushort bios_ctrl; /* 12 BIOS control bits */
  961. /* bit 0 BIOS don't act as initiator. */
  962. /* bit 1 BIOS > 1 GB support */
  963. /* bit 2 BIOS > 2 Disk Support */
  964. /* bit 3 BIOS don't support removables */
  965. /* bit 4 BIOS support bootable CD */
  966. /* bit 5 BIOS scan enabled */
  967. /* bit 6 BIOS support multiple LUNs */
  968. /* bit 7 BIOS display of message */
  969. /* bit 8 SCAM disabled */
  970. /* bit 9 Reset SCSI bus during init. */
  971. /* bit 10 */
  972. /* bit 11 No verbose initialization. */
  973. /* bit 12 SCSI parity enabled */
  974. /* bit 13 */
  975. /* bit 14 */
  976. /* bit 15 */
  977. ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
  978. ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
  979. uchar max_host_qng; /* 15 maximum host queueing */
  980. uchar max_dvc_qng; /* maximum per device queuing */
  981. ushort dvc_cntl; /* 16 control bit for driver */
  982. ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
  983. ushort serial_number_word1; /* 18 Board serial number word 1 */
  984. ushort serial_number_word2; /* 19 Board serial number word 2 */
  985. ushort serial_number_word3; /* 20 Board serial number word 3 */
  986. ushort check_sum; /* 21 EEP check sum */
  987. uchar oem_name[16]; /* 22 OEM name */
  988. ushort dvc_err_code; /* 30 last device driver error code */
  989. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  990. ushort adv_err_addr; /* 32 last uc error address */
  991. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  992. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  993. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  994. ushort reserved36; /* 36 reserved */
  995. ushort reserved37; /* 37 reserved */
  996. ushort reserved38; /* 38 reserved */
  997. ushort reserved39; /* 39 reserved */
  998. ushort reserved40; /* 40 reserved */
  999. ushort reserved41; /* 41 reserved */
  1000. ushort reserved42; /* 42 reserved */
  1001. ushort reserved43; /* 43 reserved */
  1002. ushort reserved44; /* 44 reserved */
  1003. ushort reserved45; /* 45 reserved */
  1004. ushort reserved46; /* 46 reserved */
  1005. ushort reserved47; /* 47 reserved */
  1006. ushort reserved48; /* 48 reserved */
  1007. ushort reserved49; /* 49 reserved */
  1008. ushort reserved50; /* 50 reserved */
  1009. ushort reserved51; /* 51 reserved */
  1010. ushort reserved52; /* 52 reserved */
  1011. ushort reserved53; /* 53 reserved */
  1012. ushort reserved54; /* 54 reserved */
  1013. ushort reserved55; /* 55 reserved */
  1014. ushort cisptr_lsw; /* 56 CIS PTR LSW */
  1015. ushort cisprt_msw; /* 57 CIS PTR MSW */
  1016. ushort subsysvid; /* 58 SubSystem Vendor ID */
  1017. ushort subsysid; /* 59 SubSystem ID */
  1018. ushort reserved60; /* 60 reserved */
  1019. ushort reserved61; /* 61 reserved */
  1020. ushort reserved62; /* 62 reserved */
  1021. ushort reserved63; /* 63 reserved */
  1022. } ADVEEP_38C0800_CONFIG;
  1023. typedef struct adveep_38C1600_config {
  1024. /* Word Offset, Description */
  1025. ushort cfg_lsw; /* 00 power up initialization */
  1026. /* bit 11 set - Func. 0 INTB, Func. 1 INTA */
  1027. /* clear - Func. 0 INTA, Func. 1 INTB */
  1028. /* bit 13 set - Load CIS */
  1029. /* bit 14 set - BIOS Enable */
  1030. /* bit 15 set - Big Endian Mode */
  1031. ushort cfg_msw; /* 01 unused */
  1032. ushort disc_enable; /* 02 disconnect enable */
  1033. ushort wdtr_able; /* 03 Wide DTR able */
  1034. ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
  1035. ushort start_motor; /* 05 send start up motor */
  1036. ushort tagqng_able; /* 06 tag queuing able */
  1037. ushort bios_scan; /* 07 BIOS device control */
  1038. ushort scam_tolerant; /* 08 no scam */
  1039. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  1040. uchar bios_boot_delay; /* power up wait */
  1041. uchar scsi_reset_delay; /* 10 reset delay */
  1042. uchar bios_id_lun; /* first boot device scsi id & lun */
  1043. /* high nibble is lun */
  1044. /* low nibble is scsi id */
  1045. uchar termination_se; /* 11 0 - automatic */
  1046. /* 1 - low off / high off */
  1047. /* 2 - low off / high on */
  1048. /* 3 - low on / high on */
  1049. /* There is no low on / high off */
  1050. uchar termination_lvd; /* 11 0 - automatic */
  1051. /* 1 - low off / high off */
  1052. /* 2 - low off / high on */
  1053. /* 3 - low on / high on */
  1054. /* There is no low on / high off */
  1055. ushort bios_ctrl; /* 12 BIOS control bits */
  1056. /* bit 0 BIOS don't act as initiator. */
  1057. /* bit 1 BIOS > 1 GB support */
  1058. /* bit 2 BIOS > 2 Disk Support */
  1059. /* bit 3 BIOS don't support removables */
  1060. /* bit 4 BIOS support bootable CD */
  1061. /* bit 5 BIOS scan enabled */
  1062. /* bit 6 BIOS support multiple LUNs */
  1063. /* bit 7 BIOS display of message */
  1064. /* bit 8 SCAM disabled */
  1065. /* bit 9 Reset SCSI bus during init. */
  1066. /* bit 10 Basic Integrity Checking disabled */
  1067. /* bit 11 No verbose initialization. */
  1068. /* bit 12 SCSI parity enabled */
  1069. /* bit 13 AIPP (Asyn. Info. Ph. Prot.) dis. */
  1070. /* bit 14 */
  1071. /* bit 15 */
  1072. ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
  1073. ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
  1074. uchar max_host_qng; /* 15 maximum host queueing */
  1075. uchar max_dvc_qng; /* maximum per device queuing */
  1076. ushort dvc_cntl; /* 16 control bit for driver */
  1077. ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
  1078. ushort serial_number_word1; /* 18 Board serial number word 1 */
  1079. ushort serial_number_word2; /* 19 Board serial number word 2 */
  1080. ushort serial_number_word3; /* 20 Board serial number word 3 */
  1081. ushort check_sum; /* 21 EEP check sum */
  1082. uchar oem_name[16]; /* 22 OEM name */
  1083. ushort dvc_err_code; /* 30 last device driver error code */
  1084. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  1085. ushort adv_err_addr; /* 32 last uc error address */
  1086. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  1087. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  1088. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  1089. ushort reserved36; /* 36 reserved */
  1090. ushort reserved37; /* 37 reserved */
  1091. ushort reserved38; /* 38 reserved */
  1092. ushort reserved39; /* 39 reserved */
  1093. ushort reserved40; /* 40 reserved */
  1094. ushort reserved41; /* 41 reserved */
  1095. ushort reserved42; /* 42 reserved */
  1096. ushort reserved43; /* 43 reserved */
  1097. ushort reserved44; /* 44 reserved */
  1098. ushort reserved45; /* 45 reserved */
  1099. ushort reserved46; /* 46 reserved */
  1100. ushort reserved47; /* 47 reserved */
  1101. ushort reserved48; /* 48 reserved */
  1102. ushort reserved49; /* 49 reserved */
  1103. ushort reserved50; /* 50 reserved */
  1104. ushort reserved51; /* 51 reserved */
  1105. ushort reserved52; /* 52 reserved */
  1106. ushort reserved53; /* 53 reserved */
  1107. ushort reserved54; /* 54 reserved */
  1108. ushort reserved55; /* 55 reserved */
  1109. ushort cisptr_lsw; /* 56 CIS PTR LSW */
  1110. ushort cisprt_msw; /* 57 CIS PTR MSW */
  1111. ushort subsysvid; /* 58 SubSystem Vendor ID */
  1112. ushort subsysid; /* 59 SubSystem ID */
  1113. ushort reserved60; /* 60 reserved */
  1114. ushort reserved61; /* 61 reserved */
  1115. ushort reserved62; /* 62 reserved */
  1116. ushort reserved63; /* 63 reserved */
  1117. } ADVEEP_38C1600_CONFIG;
  1118. /*
  1119. * EEPROM Commands
  1120. */
  1121. #define ASC_EEP_CMD_DONE 0x0200
  1122. /* bios_ctrl */
  1123. #define BIOS_CTRL_BIOS 0x0001
  1124. #define BIOS_CTRL_EXTENDED_XLAT 0x0002
  1125. #define BIOS_CTRL_GT_2_DISK 0x0004
  1126. #define BIOS_CTRL_BIOS_REMOVABLE 0x0008
  1127. #define BIOS_CTRL_BOOTABLE_CD 0x0010
  1128. #define BIOS_CTRL_MULTIPLE_LUN 0x0040
  1129. #define BIOS_CTRL_DISPLAY_MSG 0x0080
  1130. #define BIOS_CTRL_NO_SCAM 0x0100
  1131. #define BIOS_CTRL_RESET_SCSI_BUS 0x0200
  1132. #define BIOS_CTRL_INIT_VERBOSE 0x0800
  1133. #define BIOS_CTRL_SCSI_PARITY 0x1000
  1134. #define BIOS_CTRL_AIPP_DIS 0x2000
  1135. #define ADV_3550_MEMSIZE 0x2000 /* 8 KB Internal Memory */
  1136. #define ADV_38C0800_MEMSIZE 0x4000 /* 16 KB Internal Memory */
  1137. /*
  1138. * XXX - Since ASC38C1600 Rev.3 has a local RAM failure issue, there is
  1139. * a special 16K Adv Library and Microcode version. After the issue is
  1140. * resolved, should restore 32K support.
  1141. *
  1142. * #define ADV_38C1600_MEMSIZE 0x8000L * 32 KB Internal Memory *
  1143. */
  1144. #define ADV_38C1600_MEMSIZE 0x4000 /* 16 KB Internal Memory */
  1145. /*
  1146. * Byte I/O register address from base of 'iop_base'.
  1147. */
  1148. #define IOPB_INTR_STATUS_REG 0x00
  1149. #define IOPB_CHIP_ID_1 0x01
  1150. #define IOPB_INTR_ENABLES 0x02
  1151. #define IOPB_CHIP_TYPE_REV 0x03
  1152. #define IOPB_RES_ADDR_4 0x04
  1153. #define IOPB_RES_ADDR_5 0x05
  1154. #define IOPB_RAM_DATA 0x06
  1155. #define IOPB_RES_ADDR_7 0x07
  1156. #define IOPB_FLAG_REG 0x08
  1157. #define IOPB_RES_ADDR_9 0x09
  1158. #define IOPB_RISC_CSR 0x0A
  1159. #define IOPB_RES_ADDR_B 0x0B
  1160. #define IOPB_RES_ADDR_C 0x0C
  1161. #define IOPB_RES_ADDR_D 0x0D
  1162. #define IOPB_SOFT_OVER_WR 0x0E
  1163. #define IOPB_RES_ADDR_F 0x0F
  1164. #define IOPB_MEM_CFG 0x10
  1165. #define IOPB_RES_ADDR_11 0x11
  1166. #define IOPB_GPIO_DATA 0x12
  1167. #define IOPB_RES_ADDR_13 0x13
  1168. #define IOPB_FLASH_PAGE 0x14
  1169. #define IOPB_RES_ADDR_15 0x15
  1170. #define IOPB_GPIO_CNTL 0x16
  1171. #define IOPB_RES_ADDR_17 0x17
  1172. #define IOPB_FLASH_DATA 0x18
  1173. #define IOPB_RES_ADDR_19 0x19
  1174. #define IOPB_RES_ADDR_1A 0x1A
  1175. #define IOPB_RES_ADDR_1B 0x1B
  1176. #define IOPB_RES_ADDR_1C 0x1C
  1177. #define IOPB_RES_ADDR_1D 0x1D
  1178. #define IOPB_RES_ADDR_1E 0x1E
  1179. #define IOPB_RES_ADDR_1F 0x1F
  1180. #define IOPB_DMA_CFG0 0x20
  1181. #define IOPB_DMA_CFG1 0x21
  1182. #define IOPB_TICKLE 0x22
  1183. #define IOPB_DMA_REG_WR 0x23
  1184. #define IOPB_SDMA_STATUS 0x24
  1185. #define IOPB_SCSI_BYTE_CNT 0x25
  1186. #define IOPB_HOST_BYTE_CNT 0x26
  1187. #define IOPB_BYTE_LEFT_TO_XFER 0x27
  1188. #define IOPB_BYTE_TO_XFER_0 0x28
  1189. #define IOPB_BYTE_TO_XFER_1 0x29
  1190. #define IOPB_BYTE_TO_XFER_2 0x2A
  1191. #define IOPB_BYTE_TO_XFER_3 0x2B
  1192. #define IOPB_ACC_GRP 0x2C
  1193. #define IOPB_RES_ADDR_2D 0x2D
  1194. #define IOPB_DEV_ID 0x2E
  1195. #define IOPB_RES_ADDR_2F 0x2F
  1196. #define IOPB_SCSI_DATA 0x30
  1197. #define IOPB_RES_ADDR_31 0x31
  1198. #define IOPB_RES_ADDR_32 0x32
  1199. #define IOPB_SCSI_DATA_HSHK 0x33
  1200. #define IOPB_SCSI_CTRL 0x34
  1201. #define IOPB_RES_ADDR_35 0x35
  1202. #define IOPB_RES_ADDR_36 0x36
  1203. #define IOPB_RES_ADDR_37 0x37
  1204. #define IOPB_RAM_BIST 0x38
  1205. #define IOPB_PLL_TEST 0x39
  1206. #define IOPB_PCI_INT_CFG 0x3A
  1207. #define IOPB_RES_ADDR_3B 0x3B
  1208. #define IOPB_RFIFO_CNT 0x3C
  1209. #define IOPB_RES_ADDR_3D 0x3D
  1210. #define IOPB_RES_ADDR_3E 0x3E
  1211. #define IOPB_RES_ADDR_3F 0x3F
  1212. /*
  1213. * Word I/O register address from base of 'iop_base'.
  1214. */
  1215. #define IOPW_CHIP_ID_0 0x00 /* CID0 */
  1216. #define IOPW_CTRL_REG 0x02 /* CC */
  1217. #define IOPW_RAM_ADDR 0x04 /* LA */
  1218. #define IOPW_RAM_DATA 0x06 /* LD */
  1219. #define IOPW_RES_ADDR_08 0x08
  1220. #define IOPW_RISC_CSR 0x0A /* CSR */
  1221. #define IOPW_SCSI_CFG0 0x0C /* CFG0 */
  1222. #define IOPW_SCSI_CFG1 0x0E /* CFG1 */
  1223. #define IOPW_RES_ADDR_10 0x10
  1224. #define IOPW_SEL_MASK 0x12 /* SM */
  1225. #define IOPW_RES_ADDR_14 0x14
  1226. #define IOPW_FLASH_ADDR 0x16 /* FA */
  1227. #define IOPW_RES_ADDR_18 0x18
  1228. #define IOPW_EE_CMD 0x1A /* EC */
  1229. #define IOPW_EE_DATA 0x1C /* ED */
  1230. #define IOPW_SFIFO_CNT 0x1E /* SFC */
  1231. #define IOPW_RES_ADDR_20 0x20
  1232. #define IOPW_Q_BASE 0x22 /* QB */
  1233. #define IOPW_QP 0x24 /* QP */
  1234. #define IOPW_IX 0x26 /* IX */
  1235. #define IOPW_SP 0x28 /* SP */
  1236. #define IOPW_PC 0x2A /* PC */
  1237. #define IOPW_RES_ADDR_2C 0x2C
  1238. #define IOPW_RES_ADDR_2E 0x2E
  1239. #define IOPW_SCSI_DATA 0x30 /* SD */
  1240. #define IOPW_SCSI_DATA_HSHK 0x32 /* SDH */
  1241. #define IOPW_SCSI_CTRL 0x34 /* SC */
  1242. #define IOPW_HSHK_CFG 0x36 /* HCFG */
  1243. #define IOPW_SXFR_STATUS 0x36 /* SXS */
  1244. #define IOPW_SXFR_CNTL 0x38 /* SXL */
  1245. #define IOPW_SXFR_CNTH 0x3A /* SXH */
  1246. #define IOPW_RES_ADDR_3C 0x3C
  1247. #define IOPW_RFIFO_DATA 0x3E /* RFD */
  1248. /*
  1249. * Doubleword I/O register address from base of 'iop_base'.
  1250. */
  1251. #define IOPDW_RES_ADDR_0 0x00
  1252. #define IOPDW_RAM_DATA 0x04
  1253. #define IOPDW_RES_ADDR_8 0x08
  1254. #define IOPDW_RES_ADDR_C 0x0C
  1255. #define IOPDW_RES_ADDR_10 0x10
  1256. #define IOPDW_COMMA 0x14
  1257. #define IOPDW_COMMB 0x18
  1258. #define IOPDW_RES_ADDR_1C 0x1C
  1259. #define IOPDW_SDMA_ADDR0 0x20
  1260. #define IOPDW_SDMA_ADDR1 0x24
  1261. #define IOPDW_SDMA_COUNT 0x28
  1262. #define IOPDW_SDMA_ERROR 0x2C
  1263. #define IOPDW_RDMA_ADDR0 0x30
  1264. #define IOPDW_RDMA_ADDR1 0x34
  1265. #define IOPDW_RDMA_COUNT 0x38
  1266. #define IOPDW_RDMA_ERROR 0x3C
  1267. #define ADV_CHIP_ID_BYTE 0x25
  1268. #define ADV_CHIP_ID_WORD 0x04C1
  1269. #define ADV_INTR_ENABLE_HOST_INTR 0x01
  1270. #define ADV_INTR_ENABLE_SEL_INTR 0x02
  1271. #define ADV_INTR_ENABLE_DPR_INTR 0x04
  1272. #define ADV_INTR_ENABLE_RTA_INTR 0x08
  1273. #define ADV_INTR_ENABLE_RMA_INTR 0x10
  1274. #define ADV_INTR_ENABLE_RST_INTR 0x20
  1275. #define ADV_INTR_ENABLE_DPE_INTR 0x40
  1276. #define ADV_INTR_ENABLE_GLOBAL_INTR 0x80
  1277. #define ADV_INTR_STATUS_INTRA 0x01
  1278. #define ADV_INTR_STATUS_INTRB 0x02
  1279. #define ADV_INTR_STATUS_INTRC 0x04
  1280. #define ADV_RISC_CSR_STOP (0x0000)
  1281. #define ADV_RISC_TEST_COND (0x2000)
  1282. #define ADV_RISC_CSR_RUN (0x4000)
  1283. #define ADV_RISC_CSR_SINGLE_STEP (0x8000)
  1284. #define ADV_CTRL_REG_HOST_INTR 0x0100
  1285. #define ADV_CTRL_REG_SEL_INTR 0x0200
  1286. #define ADV_CTRL_REG_DPR_INTR 0x0400
  1287. #define ADV_CTRL_REG_RTA_INTR 0x0800
  1288. #define ADV_CTRL_REG_RMA_INTR 0x1000
  1289. #define ADV_CTRL_REG_RES_BIT14 0x2000
  1290. #define ADV_CTRL_REG_DPE_INTR 0x4000
  1291. #define ADV_CTRL_REG_POWER_DONE 0x8000
  1292. #define ADV_CTRL_REG_ANY_INTR 0xFF00
  1293. #define ADV_CTRL_REG_CMD_RESET 0x00C6
  1294. #define ADV_CTRL_REG_CMD_WR_IO_REG 0x00C5
  1295. #define ADV_CTRL_REG_CMD_RD_IO_REG 0x00C4
  1296. #define ADV_CTRL_REG_CMD_WR_PCI_CFG_SPACE 0x00C3
  1297. #define ADV_CTRL_REG_CMD_RD_PCI_CFG_SPACE 0x00C2
  1298. #define ADV_TICKLE_NOP 0x00
  1299. #define ADV_TICKLE_A 0x01
  1300. #define ADV_TICKLE_B 0x02
  1301. #define ADV_TICKLE_C 0x03
  1302. #define AdvIsIntPending(port) \
  1303. (AdvReadWordRegister(port, IOPW_CTRL_REG) & ADV_CTRL_REG_HOST_INTR)
  1304. /*
  1305. * SCSI_CFG0 Register bit definitions
  1306. */
  1307. #define TIMER_MODEAB 0xC000 /* Watchdog, Second, and Select. Timer Ctrl. */
  1308. #define PARITY_EN 0x2000 /* Enable SCSI Parity Error detection */
  1309. #define EVEN_PARITY 0x1000 /* Select Even Parity */
  1310. #define WD_LONG 0x0800 /* Watchdog Interval, 1: 57 min, 0: 13 sec */
  1311. #define QUEUE_128 0x0400 /* Queue Size, 1: 128 byte, 0: 64 byte */
  1312. #define PRIM_MODE 0x0100 /* Primitive SCSI mode */
  1313. #define SCAM_EN 0x0080 /* Enable SCAM selection */
  1314. #define SEL_TMO_LONG 0x0040 /* Sel/Resel Timeout, 1: 400 ms, 0: 1.6 ms */
  1315. #define CFRM_ID 0x0020 /* SCAM id sel. confirm., 1: fast, 0: 6.4 ms */
  1316. #define OUR_ID_EN 0x0010 /* Enable OUR_ID bits */
  1317. #define OUR_ID 0x000F /* SCSI ID */
  1318. /*
  1319. * SCSI_CFG1 Register bit definitions
  1320. */
  1321. #define BIG_ENDIAN 0x8000 /* Enable Big Endian Mode MIO:15, EEP:15 */
  1322. #define TERM_POL 0x2000 /* Terminator Polarity Ctrl. MIO:13, EEP:13 */
  1323. #define SLEW_RATE 0x1000 /* SCSI output buffer slew rate */
  1324. #define FILTER_SEL 0x0C00 /* Filter Period Selection */
  1325. #define FLTR_DISABLE 0x0000 /* Input Filtering Disabled */
  1326. #define FLTR_11_TO_20NS 0x0800 /* Input Filtering 11ns to 20ns */
  1327. #define FLTR_21_TO_39NS 0x0C00 /* Input Filtering 21ns to 39ns */
  1328. #define ACTIVE_DBL 0x0200 /* Disable Active Negation */
  1329. #define DIFF_MODE 0x0100 /* SCSI differential Mode (Read-Only) */
  1330. #define DIFF_SENSE 0x0080 /* 1: No SE cables, 0: SE cable (Read-Only) */
  1331. #define TERM_CTL_SEL 0x0040 /* Enable TERM_CTL_H and TERM_CTL_L */
  1332. #define TERM_CTL 0x0030 /* External SCSI Termination Bits */
  1333. #define TERM_CTL_H 0x0020 /* Enable External SCSI Upper Termination */
  1334. #define TERM_CTL_L 0x0010 /* Enable External SCSI Lower Termination */
  1335. #define CABLE_DETECT 0x000F /* External SCSI Cable Connection Status */
  1336. /*
  1337. * Addendum for ASC-38C0800 Chip
  1338. *
  1339. * The ASC-38C1600 Chip uses the same definitions except that the
  1340. * bus mode override bits [12:10] have been moved to byte register
  1341. * offset 0xE (IOPB_SOFT_OVER_WR) bits [12:10]. The [12:10] bits in
  1342. * SCSI_CFG1 are read-only and always available. Bit 14 (DIS_TERM_DRV)
  1343. * is not needed. The [12:10] bits in IOPB_SOFT_OVER_WR are write-only.
  1344. * Also each ASC-38C1600 function or channel uses only cable bits [5:4]
  1345. * and [1:0]. Bits [14], [7:6], [3:2] are unused.
  1346. */
  1347. #define DIS_TERM_DRV 0x4000 /* 1: Read c_det[3:0], 0: cannot read */
  1348. #define HVD_LVD_SE 0x1C00 /* Device Detect Bits */
  1349. #define HVD 0x1000 /* HVD Device Detect */
  1350. #define LVD 0x0800 /* LVD Device Detect */
  1351. #define SE 0x0400 /* SE Device Detect */
  1352. #define TERM_LVD 0x00C0 /* LVD Termination Bits */
  1353. #define TERM_LVD_HI 0x0080 /* Enable LVD Upper Termination */
  1354. #define TERM_LVD_LO 0x0040 /* Enable LVD Lower Termination */
  1355. #define TERM_SE 0x0030 /* SE Termination Bits */
  1356. #define TERM_SE_HI 0x0020 /* Enable SE Upper Termination */
  1357. #define TERM_SE_LO 0x0010 /* Enable SE Lower Termination */
  1358. #define C_DET_LVD 0x000C /* LVD Cable Detect Bits */
  1359. #define C_DET3 0x0008 /* Cable Detect for LVD External Wide */
  1360. #define C_DET2 0x0004 /* Cable Detect for LVD Internal Wide */
  1361. #define C_DET_SE 0x0003 /* SE Cable Detect Bits */
  1362. #define C_DET1 0x0002 /* Cable Detect for SE Internal Wide */
  1363. #define C_DET0 0x0001 /* Cable Detect for SE Internal Narrow */
  1364. #define CABLE_ILLEGAL_A 0x7
  1365. /* x 0 0 0 | on on | Illegal (all 3 connectors are used) */
  1366. #define CABLE_ILLEGAL_B 0xB
  1367. /* 0 x 0 0 | on on | Illegal (all 3 connectors are used) */
  1368. /*
  1369. * MEM_CFG Register bit definitions
  1370. */
  1371. #define BIOS_EN 0x40 /* BIOS Enable MIO:14,EEP:14 */
  1372. #define FAST_EE_CLK 0x20 /* Diagnostic Bit */
  1373. #define RAM_SZ 0x1C /* Specify size of RAM to RISC */
  1374. #define RAM_SZ_2KB 0x00 /* 2 KB */
  1375. #define RAM_SZ_4KB 0x04 /* 4 KB */
  1376. #define RAM_SZ_8KB 0x08 /* 8 KB */
  1377. #define RAM_SZ_16KB 0x0C /* 16 KB */
  1378. #define RAM_SZ_32KB 0x10 /* 32 KB */
  1379. #define RAM_SZ_64KB 0x14 /* 64 KB */
  1380. /*
  1381. * DMA_CFG0 Register bit definitions
  1382. *
  1383. * This register is only accessible to the host.
  1384. */
  1385. #define BC_THRESH_ENB 0x80 /* PCI DMA Start Conditions */
  1386. #define FIFO_THRESH 0x70 /* PCI DMA FIFO Threshold */
  1387. #define FIFO_THRESH_16B 0x00 /* 16 bytes */
  1388. #define FIFO_THRESH_32B 0x20 /* 32 bytes */
  1389. #define FIFO_THRESH_48B 0x30 /* 48 bytes */
  1390. #define FIFO_THRESH_64B 0x40 /* 64 bytes */
  1391. #define FIFO_THRESH_80B 0x50 /* 80 bytes (default) */
  1392. #define FIFO_THRESH_96B 0x60 /* 96 bytes */
  1393. #define FIFO_THRESH_112B 0x70 /* 112 bytes */
  1394. #define START_CTL 0x0C /* DMA start conditions */
  1395. #define START_CTL_TH 0x00 /* Wait threshold level (default) */
  1396. #define START_CTL_ID 0x04 /* Wait SDMA/SBUS idle */
  1397. #define START_CTL_THID 0x08 /* Wait threshold and SDMA/SBUS idle */
  1398. #define START_CTL_EMFU 0x0C /* Wait SDMA FIFO empty/full */
  1399. #define READ_CMD 0x03 /* Memory Read Method */
  1400. #define READ_CMD_MR 0x00 /* Memory Read */
  1401. #define READ_CMD_MRL 0x02 /* Memory Read Long */
  1402. #define READ_CMD_MRM 0x03 /* Memory Read Multiple (default) */
  1403. /*
  1404. * ASC-38C0800 RAM BIST Register bit definitions
  1405. */
  1406. #define RAM_TEST_MODE 0x80
  1407. #define PRE_TEST_MODE 0x40
  1408. #define NORMAL_MODE 0x00
  1409. #define RAM_TEST_DONE 0x10
  1410. #define RAM_TEST_STATUS 0x0F
  1411. #define RAM_TEST_HOST_ERROR 0x08
  1412. #define RAM_TEST_INTRAM_ERROR 0x04
  1413. #define RAM_TEST_RISC_ERROR 0x02
  1414. #define RAM_TEST_SCSI_ERROR 0x01
  1415. #define RAM_TEST_SUCCESS 0x00
  1416. #define PRE_TEST_VALUE 0x05
  1417. #define NORMAL_VALUE 0x00
  1418. /*
  1419. * ASC38C1600 Definitions
  1420. *
  1421. * IOPB_PCI_INT_CFG Bit Field Definitions
  1422. */
  1423. #define INTAB_LD 0x80 /* Value loaded from EEPROM Bit 11. */
  1424. /*
  1425. * Bit 1 can be set to change the interrupt for the Function to operate in
  1426. * Totem Pole mode. By default Bit 1 is 0 and the interrupt operates in
  1427. * Open Drain mode. Both functions of the ASC38C1600 must be set to the same
  1428. * mode, otherwise the operating mode is undefined.
  1429. */
  1430. #define TOTEMPOLE 0x02
  1431. /*
  1432. * Bit 0 can be used to change the Int Pin for the Function. The value is
  1433. * 0 by default for both Functions with Function 0 using INT A and Function
  1434. * B using INT B. For Function 0 if set, INT B is used. For Function 1 if set,
  1435. * INT A is used.
  1436. *
  1437. * EEPROM Word 0 Bit 11 for each Function may change the initial Int Pin
  1438. * value specified in the PCI Configuration Space.
  1439. */
  1440. #define INTAB 0x01
  1441. /*
  1442. * Adv Library Status Definitions
  1443. */
  1444. #define ADV_TRUE 1
  1445. #define ADV_FALSE 0
  1446. #define ADV_SUCCESS 1
  1447. #define ADV_BUSY 0
  1448. #define ADV_ERROR (-1)
  1449. /*
  1450. * ADV_DVC_VAR 'warn_code' values
  1451. */
  1452. #define ASC_WARN_BUSRESET_ERROR 0x0001 /* SCSI Bus Reset error */
  1453. #define ASC_WARN_EEPROM_CHKSUM 0x0002 /* EEP check sum error */
  1454. #define ASC_WARN_EEPROM_TERMINATION 0x0004 /* EEP termination bad field */
  1455. #define ASC_WARN_ERROR 0xFFFF /* ADV_ERROR return */
  1456. #define ADV_MAX_TID 15 /* max. target identifier */
  1457. #define ADV_MAX_LUN 7 /* max. logical unit number */
  1458. /*
  1459. * Fixed locations of microcode operating variables.
  1460. */
  1461. #define ASC_MC_CODE_BEGIN_ADDR 0x0028 /* microcode start address */
  1462. #define ASC_MC_CODE_END_ADDR 0x002A /* microcode end address */
  1463. #define ASC_MC_CODE_CHK_SUM 0x002C /* microcode code checksum */
  1464. #define ASC_MC_VERSION_DATE 0x0038 /* microcode version */
  1465. #define ASC_MC_VERSION_NUM 0x003A /* microcode number */
  1466. #define ASC_MC_BIOSMEM 0x0040 /* BIOS RISC Memory Start */
  1467. #define ASC_MC_BIOSLEN 0x0050 /* BIOS RISC Memory Length */
  1468. #define ASC_MC_BIOS_SIGNATURE 0x0058 /* BIOS Signature 0x55AA */
  1469. #define ASC_MC_BIOS_VERSION 0x005A /* BIOS Version (2 bytes) */
  1470. #define ASC_MC_SDTR_SPEED1 0x0090 /* SDTR Speed for TID 0-3 */
  1471. #define ASC_MC_SDTR_SPEED2 0x0092 /* SDTR Speed for TID 4-7 */
  1472. #define ASC_MC_SDTR_SPEED3 0x0094 /* SDTR Speed for TID 8-11 */
  1473. #define ASC_MC_SDTR_SPEED4 0x0096 /* SDTR Speed for TID 12-15 */
  1474. #define ASC_MC_CHIP_TYPE 0x009A
  1475. #define ASC_MC_INTRB_CODE 0x009B
  1476. #define ASC_MC_WDTR_ABLE 0x009C
  1477. #define ASC_MC_SDTR_ABLE 0x009E
  1478. #define ASC_MC_TAGQNG_ABLE 0x00A0
  1479. #define ASC_MC_DISC_ENABLE 0x00A2
  1480. #define ASC_MC_IDLE_CMD_STATUS 0x00A4
  1481. #define ASC_MC_IDLE_CMD 0x00A6
  1482. #define ASC_MC_IDLE_CMD_PARAMETER 0x00A8
  1483. #define ASC_MC_DEFAULT_SCSI_CFG0 0x00AC
  1484. #define ASC_MC_DEFAULT_SCSI_CFG1 0x00AE
  1485. #define ASC_MC_DEFAULT_MEM_CFG 0x00B0
  1486. #define ASC_MC_DEFAULT_SEL_MASK 0x00B2
  1487. #define ASC_MC_SDTR_DONE 0x00B6
  1488. #define ASC_MC_NUMBER_OF_QUEUED_CMD 0x00C0
  1489. #define ASC_MC_NUMBER_OF_MAX_CMD 0x00D0
  1490. #define ASC_MC_DEVICE_HSHK_CFG_TABLE 0x0100
  1491. #define ASC_MC_CONTROL_FLAG 0x0122 /* Microcode control flag. */
  1492. #define ASC_MC_WDTR_DONE 0x0124
  1493. #define ASC_MC_CAM_MODE_MASK 0x015E /* CAM mode TID bitmask. */
  1494. #define ASC_MC_ICQ 0x0160
  1495. #define ASC_MC_IRQ 0x0164
  1496. #define ASC_MC_PPR_ABLE 0x017A
  1497. /*
  1498. * BIOS LRAM variable absolute offsets.
  1499. */
  1500. #define BIOS_CODESEG 0x54
  1501. #define BIOS_CODELEN 0x56
  1502. #define BIOS_SIGNATURE 0x58
  1503. #define BIOS_VERSION 0x5A
  1504. /*
  1505. * Microcode Control Flags
  1506. *
  1507. * Flags set by the Adv Library in RISC variable 'control_flag' (0x122)
  1508. * and handled by the microcode.
  1509. */
  1510. #define CONTROL_FLAG_IGNORE_PERR 0x0001 /* Ignore DMA Parity Errors */
  1511. #define CONTROL_FLAG_ENABLE_AIPP 0x0002 /* Enabled AIPP checking. */
  1512. /*
  1513. * ASC_MC_DEVICE_HSHK_CFG_TABLE microcode table or HSHK_CFG register format
  1514. */
  1515. #define HSHK_CFG_WIDE_XFR 0x8000
  1516. #define HSHK_CFG_RATE 0x0F00
  1517. #define HSHK_CFG_OFFSET 0x001F
  1518. #define ASC_DEF_MAX_HOST_QNG 0xFD /* Max. number of host commands (253) */
  1519. #define ASC_DEF_MIN_HOST_QNG 0x10 /* Min. number of host commands (16) */
  1520. #define ASC_DEF_MAX_DVC_QNG 0x3F /* Max. number commands per device (63) */
  1521. #define ASC_DEF_MIN_DVC_QNG 0x04 /* Min. number commands per device (4) */
  1522. #define ASC_QC_DATA_CHECK 0x01 /* Require ASC_QC_DATA_OUT set or clear. */
  1523. #define ASC_QC_DATA_OUT 0x02 /* Data out DMA transfer. */
  1524. #define ASC_QC_START_MOTOR 0x04 /* Send auto-start motor before request. */
  1525. #define ASC_QC_NO_OVERRUN 0x08 /* Don't report overrun. */
  1526. #define ASC_QC_FREEZE_TIDQ 0x10 /* Freeze TID queue after request. XXX TBD */
  1527. #define ASC_QSC_NO_DISC 0x01 /* Don't allow disconnect for request. */
  1528. #define ASC_QSC_NO_TAGMSG 0x02 /* Don't allow tag queuing for request. */
  1529. #define ASC_QSC_NO_SYNC 0x04 /* Don't use Synch. transfer on request. */
  1530. #define ASC_QSC_NO_WIDE 0x08 /* Don't use Wide transfer on request. */
  1531. #define ASC_QSC_REDO_DTR 0x10 /* Renegotiate WDTR/SDTR before request. */
  1532. /*
  1533. * Note: If a Tag Message is to be sent and neither ASC_QSC_HEAD_TAG or
  1534. * ASC_QSC_ORDERED_TAG is set, then a Simple Tag Message (0x20) is used.
  1535. */
  1536. #define ASC_QSC_HEAD_TAG 0x40 /* Use Head Tag Message (0x21). */
  1537. #define ASC_QSC_ORDERED_TAG 0x80 /* Use Ordered Tag Message (0x22). */
  1538. /*
  1539. * All fields here are accessed by the board microcode and need to be
  1540. * little-endian.
  1541. */
  1542. typedef struct adv_carr_t {
  1543. __le32 carr_va; /* Carrier Virtual Address */
  1544. __le32 carr_pa; /* Carrier Physical Address */
  1545. __le32 areq_vpa; /* ADV_SCSI_REQ_Q Virtual or Physical Address */
  1546. /*
  1547. * next_vpa [31:4] Carrier Virtual or Physical Next Pointer
  1548. *
  1549. * next_vpa [3:1] Reserved Bits
  1550. * next_vpa [0] Done Flag set in Response Queue.
  1551. */
  1552. __le32 next_vpa;
  1553. } ADV_CARR_T;
  1554. /*
  1555. * Mask used to eliminate low 4 bits of carrier 'next_vpa' field.
  1556. */
  1557. #define ADV_NEXT_VPA_MASK 0xFFFFFFF0
  1558. #define ADV_RQ_DONE 0x00000001
  1559. #define ADV_RQ_GOOD 0x00000002
  1560. #define ADV_CQ_STOPPER 0x00000000
  1561. #define ADV_GET_CARRP(carrp) ((carrp) & ADV_NEXT_VPA_MASK)
  1562. /*
  1563. * Each carrier is 64 bytes, and we need three additional
  1564. * carrier for icq, irq, and the termination carrier.
  1565. */
  1566. #define ADV_CARRIER_COUNT (ASC_DEF_MAX_HOST_QNG + 3)
  1567. #define ADV_CARRIER_BUFSIZE \
  1568. (ADV_CARRIER_COUNT * sizeof(ADV_CARR_T))
  1569. #define ADV_CHIP_ASC3550 0x01 /* Ultra-Wide IC */
  1570. #define ADV_CHIP_ASC38C0800 0x02 /* Ultra2-Wide/LVD IC */
  1571. #define ADV_CHIP_ASC38C1600 0x03 /* Ultra3-Wide/LVD2 IC */
  1572. /*
  1573. * Adapter temporary configuration structure
  1574. *
  1575. * This structure can be discarded after initialization. Don't add
  1576. * fields here needed after initialization.
  1577. *
  1578. * Field naming convention:
  1579. *
  1580. * *_enable indicates the field enables or disables a feature. The
  1581. * value of the field is never reset.
  1582. */
  1583. typedef struct adv_dvc_cfg {
  1584. ushort disc_enable; /* enable disconnection */
  1585. uchar chip_version; /* chip version */
  1586. uchar termination; /* Term. Ctrl. bits 6-5 of SCSI_CFG1 register */
  1587. ushort control_flag; /* Microcode Control Flag */
  1588. ushort mcode_date; /* Microcode date */
  1589. ushort mcode_version; /* Microcode version */
  1590. ushort serial1; /* EEPROM serial number word 1 */
  1591. ushort serial2; /* EEPROM serial number word 2 */
  1592. ushort serial3; /* EEPROM serial number word 3 */
  1593. } ADV_DVC_CFG;
  1594. struct adv_dvc_var;
  1595. struct adv_scsi_req_q;
  1596. typedef struct adv_sg_block {
  1597. uchar reserved1;
  1598. uchar reserved2;
  1599. uchar reserved3;
  1600. uchar sg_cnt; /* Valid entries in block. */
  1601. __le32 sg_ptr; /* Pointer to next sg block. */
  1602. struct {
  1603. __le32 sg_addr; /* SG element address. */
  1604. __le32 sg_count; /* SG element count. */
  1605. } sg_list[NO_OF_SG_PER_BLOCK];
  1606. } ADV_SG_BLOCK;
  1607. /*
  1608. * ADV_SCSI_REQ_Q - microcode request structure
  1609. *
  1610. * All fields in this structure up to byte 60 are used by the microcode.
  1611. * The microcode makes assumptions about the size and ordering of fields
  1612. * in this structure. Do not change the structure definition here without
  1613. * coordinating the change with the microcode.
  1614. *
  1615. * All fields accessed by microcode must be maintained in little_endian
  1616. * order.
  1617. */
  1618. typedef struct adv_scsi_req_q {
  1619. uchar cntl; /* Ucode flags and state (ASC_MC_QC_*). */
  1620. uchar target_cmd;
  1621. uchar target_id; /* Device target identifier. */
  1622. uchar target_lun; /* Device target logical unit number. */
  1623. __le32 data_addr; /* Data buffer physical address. */
  1624. __le32 data_cnt; /* Data count. Ucode sets to residual. */
  1625. __le32 sense_addr;
  1626. __le32 carr_pa;
  1627. uchar mflag;
  1628. uchar sense_len;
  1629. uchar cdb_len; /* SCSI CDB length. Must <= 16 bytes. */
  1630. uchar scsi_cntl;
  1631. uchar done_status; /* Completion status. */
  1632. uchar scsi_status; /* SCSI status byte. */
  1633. uchar host_status; /* Ucode host status. */
  1634. uchar sg_working_ix;
  1635. uchar cdb[12]; /* SCSI CDB bytes 0-11. */
  1636. __le32 sg_real_addr; /* SG list physical address. */
  1637. __le32 scsiq_rptr;
  1638. uchar cdb16[4]; /* SCSI CDB bytes 12-15. */
  1639. __le32 scsiq_ptr;
  1640. __le32 carr_va;
  1641. /*
  1642. * End of microcode structure - 60 bytes. The rest of the structure
  1643. * is used by the Adv Library and ignored by the microcode.
  1644. */
  1645. u32 srb_tag;
  1646. ADV_SG_BLOCK *sg_list_ptr; /* SG list virtual address. */
  1647. } ADV_SCSI_REQ_Q;
  1648. /*
  1649. * The following two structures are used to process Wide Board requests.
  1650. *
  1651. * The ADV_SCSI_REQ_Q structure in adv_req_t is passed to the Adv Library
  1652. * and microcode with the ADV_SCSI_REQ_Q field 'srb_tag' set to the
  1653. * SCSI request tag. The adv_req_t structure 'cmndp' field in turn points
  1654. * to the Mid-Level SCSI request structure.
  1655. *
  1656. * Zero or more ADV_SG_BLOCK are used with each ADV_SCSI_REQ_Q. Each
  1657. * ADV_SG_BLOCK structure holds 15 scatter-gather elements. Under Linux
  1658. * up to 255 scatter-gather elements may be used per request or
  1659. * ADV_SCSI_REQ_Q.
  1660. *
  1661. * Both structures must be 32 byte aligned.
  1662. */
  1663. typedef struct adv_sgblk {
  1664. ADV_SG_BLOCK sg_block; /* Sgblock structure. */
  1665. dma_addr_t sg_addr; /* Physical address */
  1666. struct adv_sgblk *next_sgblkp; /* Next scatter-gather structure. */
  1667. } adv_sgblk_t;
  1668. typedef struct adv_req {
  1669. ADV_SCSI_REQ_Q scsi_req_q; /* Adv Library request structure. */
  1670. uchar align[24]; /* Request structure padding. */
  1671. struct scsi_cmnd *cmndp; /* Mid-Level SCSI command pointer. */
  1672. dma_addr_t req_addr;
  1673. adv_sgblk_t *sgblkp; /* Adv Library scatter-gather pointer. */
  1674. } adv_req_t __aligned(32);
  1675. /*
  1676. * Adapter operation variable structure.
  1677. *
  1678. * One structure is required per host adapter.
  1679. *
  1680. * Field naming convention:
  1681. *
  1682. * *_able indicates both whether a feature should be enabled or disabled
  1683. * and whether a device isi capable of the feature. At initialization
  1684. * this field may be set, but later if a device is found to be incapable
  1685. * of the feature, the field is cleared.
  1686. */
  1687. typedef struct adv_dvc_var {
  1688. AdvPortAddr iop_base; /* I/O port address */
  1689. ushort err_code; /* fatal error code */
  1690. ushort bios_ctrl; /* BIOS control word, EEPROM word 12 */
  1691. ushort wdtr_able; /* try WDTR for a device */
  1692. ushort sdtr_able; /* try SDTR for a device */
  1693. ushort ultra_able; /* try SDTR Ultra speed for a device */
  1694. ushort sdtr_speed1; /* EEPROM SDTR Speed for TID 0-3 */
  1695. ushort sdtr_speed2; /* EEPROM SDTR Speed for TID 4-7 */
  1696. ushort sdtr_speed3; /* EEPROM SDTR Speed for TID 8-11 */
  1697. ushort sdtr_speed4; /* EEPROM SDTR Speed for TID 12-15 */
  1698. ushort tagqng_able; /* try tagged queuing with a device */
  1699. ushort ppr_able; /* PPR message capable per TID bitmask. */
  1700. uchar max_dvc_qng; /* maximum number of tagged commands per device */
  1701. ushort start_motor; /* start motor command allowed */
  1702. uchar scsi_reset_wait; /* delay in seconds after scsi bus reset */
  1703. uchar chip_no; /* should be assigned by caller */
  1704. uchar max_host_qng; /* maximum number of Q'ed command allowed */
  1705. ushort no_scam; /* scam_tolerant of EEPROM */
  1706. struct asc_board *drv_ptr; /* driver pointer to private structure */
  1707. uchar chip_scsi_id; /* chip SCSI target ID */
  1708. uchar chip_type;
  1709. uchar bist_err_code;
  1710. ADV_CARR_T *carrier;
  1711. ADV_CARR_T *carr_freelist; /* Carrier free list. */
  1712. dma_addr_t carrier_addr;
  1713. ADV_CARR_T *icq_sp; /* Initiator command queue stopper pointer. */
  1714. ADV_CARR_T *irq_sp; /* Initiator response queue stopper pointer. */
  1715. ushort carr_pending_cnt; /* Count of pending carriers. */
  1716. /*
  1717. * Note: The following fields will not be used after initialization. The
  1718. * driver may discard the buffer after initialization is done.
  1719. */
  1720. ADV_DVC_CFG *cfg; /* temporary configuration structure */
  1721. } ADV_DVC_VAR;
  1722. /*
  1723. * Microcode idle loop commands
  1724. */
  1725. #define IDLE_CMD_COMPLETED 0
  1726. #define IDLE_CMD_STOP_CHIP 0x0001
  1727. #define IDLE_CMD_STOP_CHIP_SEND_INT 0x0002
  1728. #define IDLE_CMD_SEND_INT 0x0004
  1729. #define IDLE_CMD_ABORT 0x0008
  1730. #define IDLE_CMD_DEVICE_RESET 0x0010
  1731. #define IDLE_CMD_SCSI_RESET_START 0x0020 /* Assert SCSI Bus Reset */
  1732. #define IDLE_CMD_SCSI_RESET_END 0x0040 /* Deassert SCSI Bus Reset */
  1733. #define IDLE_CMD_SCSIREQ 0x0080
  1734. #define IDLE_CMD_STATUS_SUCCESS 0x0001
  1735. #define IDLE_CMD_STATUS_FAILURE 0x0002
  1736. /*
  1737. * AdvSendIdleCmd() flag definitions.
  1738. */
  1739. #define ADV_NOWAIT 0x01
  1740. /*
  1741. * Wait loop time out values.
  1742. */
  1743. #define SCSI_WAIT_100_MSEC 100UL /* 100 milliseconds */
  1744. #define SCSI_US_PER_MSEC 1000 /* microseconds per millisecond */
  1745. #define SCSI_MAX_RETRY 10 /* retry count */
  1746. #define ADV_ASYNC_RDMA_FAILURE 0x01 /* Fatal RDMA failure. */
  1747. #define ADV_ASYNC_SCSI_BUS_RESET_DET 0x02 /* Detected SCSI Bus Reset. */
  1748. #define ADV_ASYNC_CARRIER_READY_FAILURE 0x03 /* Carrier Ready failure. */
  1749. #define ADV_RDMA_IN_CARR_AND_Q_INVALID 0x04 /* RDMAed-in data invalid. */
  1750. #define ADV_HOST_SCSI_BUS_RESET 0x80 /* Host Initiated SCSI Bus Reset. */
  1751. /* Read byte from a register. */
  1752. #define AdvReadByteRegister(iop_base, reg_off) \
  1753. (ADV_MEM_READB((iop_base) + (reg_off)))
  1754. /* Write byte to a register. */
  1755. #define AdvWriteByteRegister(iop_base, reg_off, byte) \
  1756. (ADV_MEM_WRITEB((iop_base) + (reg_off), (byte)))
  1757. /* Read word (2 bytes) from a register. */
  1758. #define AdvReadWordRegister(iop_base, reg_off) \
  1759. (ADV_MEM_READW((iop_base) + (reg_off)))
  1760. /* Write word (2 bytes) to a register. */
  1761. #define AdvWriteWordRegister(iop_base, reg_off, word) \
  1762. (ADV_MEM_WRITEW((iop_base) + (reg_off), (word)))
  1763. /* Write dword (4 bytes) to a register. */
  1764. #define AdvWriteDWordRegister(iop_base, reg_off, dword) \
  1765. (ADV_MEM_WRITEDW((iop_base) + (reg_off), (dword)))
  1766. /* Read byte from LRAM. */
  1767. #define AdvReadByteLram(iop_base, addr, byte) \
  1768. do { \
  1769. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
  1770. (byte) = ADV_MEM_READB((iop_base) + IOPB_RAM_DATA); \
  1771. } while (0)
  1772. /* Write byte to LRAM. */
  1773. #define AdvWriteByteLram(iop_base, addr, byte) \
  1774. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1775. ADV_MEM_WRITEB((iop_base) + IOPB_RAM_DATA, (byte)))
  1776. /* Read word (2 bytes) from LRAM. */
  1777. #define AdvReadWordLram(iop_base, addr, word) \
  1778. do { \
  1779. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
  1780. (word) = (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA)); \
  1781. } while (0)
  1782. /* Write word (2 bytes) to LRAM. */
  1783. #define AdvWriteWordLram(iop_base, addr, word) \
  1784. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1785. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
  1786. /* Write little-endian double word (4 bytes) to LRAM */
  1787. /* Because of unspecified C language ordering don't use auto-increment. */
  1788. #define AdvWriteDWordLramNoSwap(iop_base, addr, dword) \
  1789. ((ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1790. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
  1791. cpu_to_le16((ushort) ((dword) & 0xFFFF)))), \
  1792. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr) + 2), \
  1793. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
  1794. cpu_to_le16((ushort) ((dword >> 16) & 0xFFFF)))))
  1795. /* Read word (2 bytes) from LRAM assuming that the address is already set. */
  1796. #define AdvReadWordAutoIncLram(iop_base) \
  1797. (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA))
  1798. /* Write word (2 bytes) to LRAM assuming that the address is already set. */
  1799. #define AdvWriteWordAutoIncLram(iop_base, word) \
  1800. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
  1801. /*
  1802. * Define macro to check for Condor signature.
  1803. *
  1804. * Evaluate to ADV_TRUE if a Condor chip is found the specified port
  1805. * address 'iop_base'. Otherwise evalue to ADV_FALSE.
  1806. */
  1807. #define AdvFindSignature(iop_base) \
  1808. (((AdvReadByteRegister((iop_base), IOPB_CHIP_ID_1) == \
  1809. ADV_CHIP_ID_BYTE) && \
  1810. (AdvReadWordRegister((iop_base), IOPW_CHIP_ID_0) == \
  1811. ADV_CHIP_ID_WORD)) ? ADV_TRUE : ADV_FALSE)
  1812. /*
  1813. * Define macro to Return the version number of the chip at 'iop_base'.
  1814. *
  1815. * The second parameter 'bus_type' is currently unused.
  1816. */
  1817. #define AdvGetChipVersion(iop_base, bus_type) \
  1818. AdvReadByteRegister((iop_base), IOPB_CHIP_TYPE_REV)
  1819. /*
  1820. * Abort an SRB in the chip's RISC Memory. The 'srb_tag' argument must
  1821. * match the ADV_SCSI_REQ_Q 'srb_tag' field.
  1822. *
  1823. * If the request has not yet been sent to the device it will simply be
  1824. * aborted from RISC memory. If the request is disconnected it will be
  1825. * aborted on reselection by sending an Abort Message to the target ID.
  1826. *
  1827. * Return value:
  1828. * ADV_TRUE(1) - Queue was successfully aborted.
  1829. * ADV_FALSE(0) - Queue was not found on the active queue list.
  1830. */
  1831. #define AdvAbortQueue(asc_dvc, srb_tag) \
  1832. AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_ABORT, \
  1833. (ADV_DCNT) (srb_tag))
  1834. /*
  1835. * Send a Bus Device Reset Message to the specified target ID.
  1836. *
  1837. * All outstanding commands will be purged if sending the
  1838. * Bus Device Reset Message is successful.
  1839. *
  1840. * Return Value:
  1841. * ADV_TRUE(1) - All requests on the target are purged.
  1842. * ADV_FALSE(0) - Couldn't issue Bus Device Reset Message; Requests
  1843. * are not purged.
  1844. */
  1845. #define AdvResetDevice(asc_dvc, target_id) \
  1846. AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_DEVICE_RESET, \
  1847. (ADV_DCNT) (target_id))
  1848. /*
  1849. * SCSI Wide Type definition.
  1850. */
  1851. #define ADV_SCSI_BIT_ID_TYPE ushort
  1852. /*
  1853. * AdvInitScsiTarget() 'cntl_flag' options.
  1854. */
  1855. #define ADV_SCAN_LUN 0x01
  1856. #define ADV_CAPINFO_NOLUN 0x02
  1857. /*
  1858. * Convert target id to target id bit mask.
  1859. */
  1860. #define ADV_TID_TO_TIDMASK(tid) (0x01 << ((tid) & ADV_MAX_TID))
  1861. /*
  1862. * ADV_SCSI_REQ_Q 'done_status' and 'host_status' return values.
  1863. */
  1864. #define QD_NO_STATUS 0x00 /* Request not completed yet. */
  1865. #define QD_NO_ERROR 0x01
  1866. #define QD_ABORTED_BY_HOST 0x02
  1867. #define QD_WITH_ERROR 0x04
  1868. #define QHSTA_NO_ERROR 0x00
  1869. #define QHSTA_M_SEL_TIMEOUT 0x11
  1870. #define QHSTA_M_DATA_OVER_RUN 0x12
  1871. #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
  1872. #define QHSTA_M_QUEUE_ABORTED 0x15
  1873. #define QHSTA_M_SXFR_SDMA_ERR 0x16 /* SXFR_STATUS SCSI DMA Error */
  1874. #define QHSTA_M_SXFR_SXFR_PERR 0x17 /* SXFR_STATUS SCSI Bus Parity Error */
  1875. #define QHSTA_M_RDMA_PERR 0x18 /* RISC PCI DMA parity error */
  1876. #define QHSTA_M_SXFR_OFF_UFLW 0x19 /* SXFR_STATUS Offset Underflow */
  1877. #define QHSTA_M_SXFR_OFF_OFLW 0x20 /* SXFR_STATUS Offset Overflow */
  1878. #define QHSTA_M_SXFR_WD_TMO 0x21 /* SXFR_STATUS Watchdog Timeout */
  1879. #define QHSTA_M_SXFR_DESELECTED 0x22 /* SXFR_STATUS Deselected */
  1880. /* Note: QHSTA_M_SXFR_XFR_OFLW is identical to QHSTA_M_DATA_OVER_RUN. */
  1881. #define QHSTA_M_SXFR_XFR_OFLW 0x12 /* SXFR_STATUS Transfer Overflow */
  1882. #define QHSTA_M_SXFR_XFR_PH_ERR 0x24 /* SXFR_STATUS Transfer Phase Error */
  1883. #define QHSTA_M_SXFR_UNKNOWN_ERROR 0x25 /* SXFR_STATUS Unknown Error */
  1884. #define QHSTA_M_SCSI_BUS_RESET 0x30 /* Request aborted from SBR */
  1885. #define QHSTA_M_SCSI_BUS_RESET_UNSOL 0x31 /* Request aborted from unsol. SBR */
  1886. #define QHSTA_M_BUS_DEVICE_RESET 0x32 /* Request aborted from BDR */
  1887. #define QHSTA_M_DIRECTION_ERR 0x35 /* Data Phase mismatch */
  1888. #define QHSTA_M_DIRECTION_ERR_HUNG 0x36 /* Data Phase mismatch and bus hang */
  1889. #define QHSTA_M_WTM_TIMEOUT 0x41
  1890. #define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
  1891. #define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
  1892. #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
  1893. #define QHSTA_M_INVALID_DEVICE 0x45 /* Bad target ID */
  1894. #define QHSTA_M_FROZEN_TIDQ 0x46 /* TID Queue frozen. */
  1895. #define QHSTA_M_SGBACKUP_ERROR 0x47 /* Scatter-Gather backup error */
  1896. /* Return the address that is aligned at the next doubleword >= to 'addr'. */
  1897. #define ADV_32BALIGN(addr) (((ulong) (addr) + 0x1F) & ~0x1F)
  1898. /*
  1899. * Total contiguous memory needed for driver SG blocks.
  1900. *
  1901. * ADV_MAX_SG_LIST must be defined by a driver. It is the maximum
  1902. * number of scatter-gather elements the driver supports in a
  1903. * single request.
  1904. */
  1905. #define ADV_SG_LIST_MAX_BYTE_SIZE \
  1906. (sizeof(ADV_SG_BLOCK) * \
  1907. ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK))
  1908. /* struct asc_board flags */
  1909. #define ASC_IS_WIDE_BOARD 0x04 /* AdvanSys Wide Board */
  1910. #define ASC_NARROW_BOARD(boardp) (((boardp)->flags & ASC_IS_WIDE_BOARD) == 0)
  1911. #define NO_ISA_DMA 0xff /* No ISA DMA Channel Used */
  1912. #define ASC_INFO_SIZE 128 /* advansys_info() line size */
  1913. /* Asc Library return codes */
  1914. #define ASC_TRUE 1
  1915. #define ASC_FALSE 0
  1916. #define ASC_NOERROR 1
  1917. #define ASC_BUSY 0
  1918. #define ASC_ERROR (-1)
  1919. /* struct scsi_cmnd function return codes */
  1920. #define STATUS_BYTE(byte) (byte)
  1921. #define MSG_BYTE(byte) ((byte) << 8)
  1922. #define HOST_BYTE(byte) ((byte) << 16)
  1923. #define DRIVER_BYTE(byte) ((byte) << 24)
  1924. #define ASC_STATS(shost, counter) ASC_STATS_ADD(shost, counter, 1)
  1925. #ifndef ADVANSYS_STATS
  1926. #define ASC_STATS_ADD(shost, counter, count)
  1927. #else /* ADVANSYS_STATS */
  1928. #define ASC_STATS_ADD(shost, counter, count) \
  1929. (((struct asc_board *) shost_priv(shost))->asc_stats.counter += (count))
  1930. #endif /* ADVANSYS_STATS */
  1931. /* If the result wraps when calculating tenths, return 0. */
  1932. #define ASC_TENTHS(num, den) \
  1933. (((10 * ((num)/(den))) > (((num) * 10)/(den))) ? \
  1934. 0 : ((((num) * 10)/(den)) - (10 * ((num)/(den)))))
  1935. /*
  1936. * Display a message to the console.
  1937. */
  1938. #define ASC_PRINT(s) \
  1939. { \
  1940. printk("advansys: "); \
  1941. printk(s); \
  1942. }
  1943. #define ASC_PRINT1(s, a1) \
  1944. { \
  1945. printk("advansys: "); \
  1946. printk((s), (a1)); \
  1947. }
  1948. #define ASC_PRINT2(s, a1, a2) \
  1949. { \
  1950. printk("advansys: "); \
  1951. printk((s), (a1), (a2)); \
  1952. }
  1953. #define ASC_PRINT3(s, a1, a2, a3) \
  1954. { \
  1955. printk("advansys: "); \
  1956. printk((s), (a1), (a2), (a3)); \
  1957. }
  1958. #define ASC_PRINT4(s, a1, a2, a3, a4) \
  1959. { \
  1960. printk("advansys: "); \
  1961. printk((s), (a1), (a2), (a3), (a4)); \
  1962. }
  1963. #ifndef ADVANSYS_DEBUG
  1964. #define ASC_DBG(lvl, s...)
  1965. #define ASC_DBG_PRT_SCSI_HOST(lvl, s)
  1966. #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp)
  1967. #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
  1968. #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone)
  1969. #define ADV_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
  1970. #define ASC_DBG_PRT_HEX(lvl, name, start, length)
  1971. #define ASC_DBG_PRT_CDB(lvl, cdb, len)
  1972. #define ASC_DBG_PRT_SENSE(lvl, sense, len)
  1973. #define ASC_DBG_PRT_INQUIRY(lvl, inq, len)
  1974. #else /* ADVANSYS_DEBUG */
  1975. /*
  1976. * Debugging Message Levels:
  1977. * 0: Errors Only
  1978. * 1: High-Level Tracing
  1979. * 2-N: Verbose Tracing
  1980. */
  1981. #define ASC_DBG(lvl, format, arg...) { \
  1982. if (asc_dbglvl >= (lvl)) \
  1983. printk(KERN_DEBUG "%s: %s: " format, DRV_NAME, \
  1984. __func__ , ## arg); \
  1985. }
  1986. #define ASC_DBG_PRT_SCSI_HOST(lvl, s) \
  1987. { \
  1988. if (asc_dbglvl >= (lvl)) { \
  1989. asc_prt_scsi_host(s); \
  1990. } \
  1991. }
  1992. #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp) \
  1993. { \
  1994. if (asc_dbglvl >= (lvl)) { \
  1995. asc_prt_asc_scsi_q(scsiqp); \
  1996. } \
  1997. }
  1998. #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone) \
  1999. { \
  2000. if (asc_dbglvl >= (lvl)) { \
  2001. asc_prt_asc_qdone_info(qdone); \
  2002. } \
  2003. }
  2004. #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp) \
  2005. { \
  2006. if (asc_dbglvl >= (lvl)) { \
  2007. asc_prt_adv_scsi_req_q(scsiqp); \
  2008. } \
  2009. }
  2010. #define ASC_DBG_PRT_HEX(lvl, name, start, length) \
  2011. { \
  2012. if (asc_dbglvl >= (lvl)) { \
  2013. asc_prt_hex((name), (start), (length)); \
  2014. } \
  2015. }
  2016. #define ASC_DBG_PRT_CDB(lvl, cdb, len) \
  2017. ASC_DBG_PRT_HEX((lvl), "CDB", (uchar *) (cdb), (len));
  2018. #define ASC_DBG_PRT_SENSE(lvl, sense, len) \
  2019. ASC_DBG_PRT_HEX((lvl), "SENSE", (uchar *) (sense), (len));
  2020. #define ASC_DBG_PRT_INQUIRY(lvl, inq, len) \
  2021. ASC_DBG_PRT_HEX((lvl), "INQUIRY", (uchar *) (inq), (len));
  2022. #endif /* ADVANSYS_DEBUG */
  2023. #ifdef ADVANSYS_STATS
  2024. /* Per board statistics structure */
  2025. struct asc_stats {
  2026. /* Driver Entrypoint Statistics */
  2027. unsigned int queuecommand; /* # calls to advansys_queuecommand() */
  2028. unsigned int reset; /* # calls to advansys_eh_bus_reset() */
  2029. unsigned int biosparam; /* # calls to advansys_biosparam() */
  2030. unsigned int interrupt; /* # advansys_interrupt() calls */
  2031. unsigned int callback; /* # calls to asc/adv_isr_callback() */
  2032. unsigned int done; /* # calls to request's scsi_done function */
  2033. unsigned int build_error; /* # asc/adv_build_req() ASC_ERROR returns. */
  2034. unsigned int adv_build_noreq; /* # adv_build_req() adv_req_t alloc. fail. */
  2035. unsigned int adv_build_nosg; /* # adv_build_req() adv_sgblk_t alloc. fail. */
  2036. /* AscExeScsiQueue()/AdvExeScsiQueue() Statistics */
  2037. unsigned int exe_noerror; /* # ASC_NOERROR returns. */
  2038. unsigned int exe_busy; /* # ASC_BUSY returns. */
  2039. unsigned int exe_error; /* # ASC_ERROR returns. */
  2040. unsigned int exe_unknown; /* # unknown returns. */
  2041. /* Data Transfer Statistics */
  2042. unsigned int xfer_cnt; /* # I/O requests received */
  2043. unsigned int xfer_elem; /* # scatter-gather elements */
  2044. unsigned int xfer_sect; /* # 512-byte blocks */
  2045. };
  2046. #endif /* ADVANSYS_STATS */
  2047. /*
  2048. * Structure allocated for each board.
  2049. *
  2050. * This structure is allocated by scsi_host_alloc() at the end
  2051. * of the 'Scsi_Host' structure starting at the 'hostdata'
  2052. * field. It is guaranteed to be allocated from DMA-able memory.
  2053. */
  2054. struct asc_board {
  2055. struct device *dev;
  2056. struct Scsi_Host *shost;
  2057. uint flags; /* Board flags */
  2058. unsigned int irq;
  2059. union {
  2060. ASC_DVC_VAR asc_dvc_var; /* Narrow board */
  2061. ADV_DVC_VAR adv_dvc_var; /* Wide board */
  2062. } dvc_var;
  2063. union {
  2064. ASC_DVC_CFG asc_dvc_cfg; /* Narrow board */
  2065. ADV_DVC_CFG adv_dvc_cfg; /* Wide board */
  2066. } dvc_cfg;
  2067. ushort asc_n_io_port; /* Number I/O ports. */
  2068. ADV_SCSI_BIT_ID_TYPE init_tidmask; /* Target init./valid mask */
  2069. ushort reqcnt[ADV_MAX_TID + 1]; /* Starvation request count */
  2070. ADV_SCSI_BIT_ID_TYPE queue_full; /* Queue full mask */
  2071. ushort queue_full_cnt[ADV_MAX_TID + 1]; /* Queue full count */
  2072. union {
  2073. ASCEEP_CONFIG asc_eep; /* Narrow EEPROM config. */
  2074. ADVEEP_3550_CONFIG adv_3550_eep; /* 3550 EEPROM config. */
  2075. ADVEEP_38C0800_CONFIG adv_38C0800_eep; /* 38C0800 EEPROM config. */
  2076. ADVEEP_38C1600_CONFIG adv_38C1600_eep; /* 38C1600 EEPROM config. */
  2077. } eep_config;
  2078. /* /proc/scsi/advansys/[0...] */
  2079. #ifdef ADVANSYS_STATS
  2080. struct asc_stats asc_stats; /* Board statistics */
  2081. #endif /* ADVANSYS_STATS */
  2082. /*
  2083. * The following fields are used only for Narrow Boards.
  2084. */
  2085. uchar sdtr_data[ASC_MAX_TID + 1]; /* SDTR information */
  2086. /*
  2087. * The following fields are used only for Wide Boards.
  2088. */
  2089. void __iomem *ioremap_addr; /* I/O Memory remap address. */
  2090. ushort ioport; /* I/O Port address. */
  2091. adv_req_t *adv_reqp; /* Request structures. */
  2092. dma_addr_t adv_reqp_addr;
  2093. size_t adv_reqp_size;
  2094. struct dma_pool *adv_sgblk_pool; /* Scatter-gather structures. */
  2095. ushort bios_signature; /* BIOS Signature. */
  2096. ushort bios_version; /* BIOS Version. */
  2097. ushort bios_codeseg; /* BIOS Code Segment. */
  2098. ushort bios_codelen; /* BIOS Code Segment Length. */
  2099. };
  2100. #define asc_dvc_to_board(asc_dvc) container_of(asc_dvc, struct asc_board, \
  2101. dvc_var.asc_dvc_var)
  2102. #define adv_dvc_to_board(adv_dvc) container_of(adv_dvc, struct asc_board, \
  2103. dvc_var.adv_dvc_var)
  2104. #define adv_dvc_to_pdev(adv_dvc) to_pci_dev(adv_dvc_to_board(adv_dvc)->dev)
  2105. #ifdef ADVANSYS_DEBUG
  2106. static int asc_dbglvl = 3;
  2107. /*
  2108. * asc_prt_asc_dvc_var()
  2109. */
  2110. static void asc_prt_asc_dvc_var(ASC_DVC_VAR *h)
  2111. {
  2112. printk("ASC_DVC_VAR at addr 0x%lx\n", (ulong)h);
  2113. printk(" iop_base 0x%x, err_code 0x%x, dvc_cntl 0x%x, bug_fix_cntl "
  2114. "%d,\n", h->iop_base, h->err_code, h->dvc_cntl, h->bug_fix_cntl);
  2115. printk(" bus_type %d, init_sdtr 0x%x,\n", h->bus_type,
  2116. (unsigned)h->init_sdtr);
  2117. printk(" sdtr_done 0x%x, use_tagged_qng 0x%x, unit_not_ready 0x%x, "
  2118. "chip_no 0x%x,\n", (unsigned)h->sdtr_done,
  2119. (unsigned)h->use_tagged_qng, (unsigned)h->unit_not_ready,
  2120. (unsigned)h->chip_no);
  2121. printk(" queue_full_or_busy 0x%x, start_motor 0x%x, scsi_reset_wait "
  2122. "%u,\n", (unsigned)h->queue_full_or_busy,
  2123. (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
  2124. printk(" is_in_int %u, max_total_qng %u, cur_total_qng %u, "
  2125. "in_critical_cnt %u,\n", (unsigned)h->is_in_int,
  2126. (unsigned)h->max_total_qng, (unsigned)h->cur_total_qng,
  2127. (unsigned)h->in_critical_cnt);
  2128. printk(" last_q_shortage %u, init_state 0x%x, no_scam 0x%x, "
  2129. "pci_fix_asyn_xfer 0x%x,\n", (unsigned)h->last_q_shortage,
  2130. (unsigned)h->init_state, (unsigned)h->no_scam,
  2131. (unsigned)h->pci_fix_asyn_xfer);
  2132. printk(" cfg 0x%lx\n", (ulong)h->cfg);
  2133. }
  2134. /*
  2135. * asc_prt_asc_dvc_cfg()
  2136. */
  2137. static void asc_prt_asc_dvc_cfg(ASC_DVC_CFG *h)
  2138. {
  2139. printk("ASC_DVC_CFG at addr 0x%lx\n", (ulong)h);
  2140. printk(" can_tagged_qng 0x%x, cmd_qng_enabled 0x%x,\n",
  2141. h->can_tagged_qng, h->cmd_qng_enabled);
  2142. printk(" disc_enable 0x%x, sdtr_enable 0x%x,\n",
  2143. h->disc_enable, h->sdtr_enable);
  2144. printk(" chip_scsi_id %d, isa_dma_speed %d, isa_dma_channel %d, "
  2145. "chip_version %d,\n", h->chip_scsi_id, h->isa_dma_speed,
  2146. h->isa_dma_channel, h->chip_version);
  2147. printk(" mcode_date 0x%x, mcode_version %d\n",
  2148. h->mcode_date, h->mcode_version);
  2149. }
  2150. /*
  2151. * asc_prt_adv_dvc_var()
  2152. *
  2153. * Display an ADV_DVC_VAR structure.
  2154. */
  2155. static void asc_prt_adv_dvc_var(ADV_DVC_VAR *h)
  2156. {
  2157. printk(" ADV_DVC_VAR at addr 0x%lx\n", (ulong)h);
  2158. printk(" iop_base 0x%lx, err_code 0x%x, ultra_able 0x%x\n",
  2159. (ulong)h->iop_base, h->err_code, (unsigned)h->ultra_able);
  2160. printk(" sdtr_able 0x%x, wdtr_able 0x%x\n",
  2161. (unsigned)h->sdtr_able, (unsigned)h->wdtr_able);
  2162. printk(" start_motor 0x%x, scsi_reset_wait 0x%x\n",
  2163. (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
  2164. printk(" max_host_qng %u, max_dvc_qng %u, carr_freelist 0x%p\n",
  2165. (unsigned)h->max_host_qng, (unsigned)h->max_dvc_qng,
  2166. h->carr_freelist);
  2167. printk(" icq_sp 0x%p, irq_sp 0x%p\n", h->icq_sp, h->irq_sp);
  2168. printk(" no_scam 0x%x, tagqng_able 0x%x\n",
  2169. (unsigned)h->no_scam, (unsigned)h->tagqng_able);
  2170. printk(" chip_scsi_id 0x%x, cfg 0x%lx\n",
  2171. (unsigned)h->chip_scsi_id, (ulong)h->cfg);
  2172. }
  2173. /*
  2174. * asc_prt_adv_dvc_cfg()
  2175. *
  2176. * Display an ADV_DVC_CFG structure.
  2177. */
  2178. static void asc_prt_adv_dvc_cfg(ADV_DVC_CFG *h)
  2179. {
  2180. printk(" ADV_DVC_CFG at addr 0x%lx\n", (ulong)h);
  2181. printk(" disc_enable 0x%x, termination 0x%x\n",
  2182. h->disc_enable, h->termination);
  2183. printk(" chip_version 0x%x, mcode_date 0x%x\n",
  2184. h->chip_version, h->mcode_date);
  2185. printk(" mcode_version 0x%x, control_flag 0x%x\n",
  2186. h->mcode_version, h->control_flag);
  2187. }
  2188. /*
  2189. * asc_prt_scsi_host()
  2190. */
  2191. static void asc_prt_scsi_host(struct Scsi_Host *s)
  2192. {
  2193. struct asc_board *boardp = shost_priv(s);
  2194. printk("Scsi_Host at addr 0x%p, device %s\n", s, dev_name(boardp->dev));
  2195. printk(" host_busy %u, host_no %d,\n",
  2196. atomic_read(&s->host_busy), s->host_no);
  2197. printk(" base 0x%lx, io_port 0x%lx, irq %d,\n",
  2198. (ulong)s->base, (ulong)s->io_port, boardp->irq);
  2199. printk(" dma_channel %d, this_id %d, can_queue %d,\n",
  2200. s->dma_channel, s->this_id, s->can_queue);
  2201. printk(" cmd_per_lun %d, sg_tablesize %d, unchecked_isa_dma %d\n",
  2202. s->cmd_per_lun, s->sg_tablesize, s->unchecked_isa_dma);
  2203. if (ASC_NARROW_BOARD(boardp)) {
  2204. asc_prt_asc_dvc_var(&boardp->dvc_var.asc_dvc_var);
  2205. asc_prt_asc_dvc_cfg(&boardp->dvc_cfg.asc_dvc_cfg);
  2206. } else {
  2207. asc_prt_adv_dvc_var(&boardp->dvc_var.adv_dvc_var);
  2208. asc_prt_adv_dvc_cfg(&boardp->dvc_cfg.adv_dvc_cfg);
  2209. }
  2210. }
  2211. /*
  2212. * asc_prt_hex()
  2213. *
  2214. * Print hexadecimal output in 4 byte groupings 32 bytes
  2215. * or 8 double-words per line.
  2216. */
  2217. static void asc_prt_hex(char *f, uchar *s, int l)
  2218. {
  2219. int i;
  2220. int j;
  2221. int k;
  2222. int m;
  2223. printk("%s: (%d bytes)\n", f, l);
  2224. for (i = 0; i < l; i += 32) {
  2225. /* Display a maximum of 8 double-words per line. */
  2226. if ((k = (l - i) / 4) >= 8) {
  2227. k = 8;
  2228. m = 0;
  2229. } else {
  2230. m = (l - i) % 4;
  2231. }
  2232. for (j = 0; j < k; j++) {
  2233. printk(" %2.2X%2.2X%2.2X%2.2X",
  2234. (unsigned)s[i + (j * 4)],
  2235. (unsigned)s[i + (j * 4) + 1],
  2236. (unsigned)s[i + (j * 4) + 2],
  2237. (unsigned)s[i + (j * 4) + 3]);
  2238. }
  2239. switch (m) {
  2240. case 0:
  2241. default:
  2242. break;
  2243. case 1:
  2244. printk(" %2.2X", (unsigned)s[i + (j * 4)]);
  2245. break;
  2246. case 2:
  2247. printk(" %2.2X%2.2X",
  2248. (unsigned)s[i + (j * 4)],
  2249. (unsigned)s[i + (j * 4) + 1]);
  2250. break;
  2251. case 3:
  2252. printk(" %2.2X%2.2X%2.2X",
  2253. (unsigned)s[i + (j * 4) + 1],
  2254. (unsigned)s[i + (j * 4) + 2],
  2255. (unsigned)s[i + (j * 4) + 3]);
  2256. break;
  2257. }
  2258. printk("\n");
  2259. }
  2260. }
  2261. /*
  2262. * asc_prt_asc_scsi_q()
  2263. */
  2264. static void asc_prt_asc_scsi_q(ASC_SCSI_Q *q)
  2265. {
  2266. ASC_SG_HEAD *sgp;
  2267. int i;
  2268. printk("ASC_SCSI_Q at addr 0x%lx\n", (ulong)q);
  2269. printk
  2270. (" target_ix 0x%x, target_lun %u, srb_tag 0x%x, tag_code 0x%x,\n",
  2271. q->q2.target_ix, q->q1.target_lun, q->q2.srb_tag,
  2272. q->q2.tag_code);
  2273. printk
  2274. (" data_addr 0x%lx, data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
  2275. (ulong)le32_to_cpu(q->q1.data_addr),
  2276. (ulong)le32_to_cpu(q->q1.data_cnt),
  2277. (ulong)le32_to_cpu(q->q1.sense_addr), q->q1.sense_len);
  2278. printk(" cdbptr 0x%lx, cdb_len %u, sg_head 0x%lx, sg_queue_cnt %u\n",
  2279. (ulong)q->cdbptr, q->q2.cdb_len,
  2280. (ulong)q->sg_head, q->q1.sg_queue_cnt);
  2281. if (q->sg_head) {
  2282. sgp = q->sg_head;
  2283. printk("ASC_SG_HEAD at addr 0x%lx\n", (ulong)sgp);
  2284. printk(" entry_cnt %u, queue_cnt %u\n", sgp->entry_cnt,
  2285. sgp->queue_cnt);
  2286. for (i = 0; i < sgp->entry_cnt; i++) {
  2287. printk(" [%u]: addr 0x%lx, bytes %lu\n",
  2288. i, (ulong)le32_to_cpu(sgp->sg_list[i].addr),
  2289. (ulong)le32_to_cpu(sgp->sg_list[i].bytes));
  2290. }
  2291. }
  2292. }
  2293. /*
  2294. * asc_prt_asc_qdone_info()
  2295. */
  2296. static void asc_prt_asc_qdone_info(ASC_QDONE_INFO *q)
  2297. {
  2298. printk("ASC_QDONE_INFO at addr 0x%lx\n", (ulong)q);
  2299. printk(" srb_tag 0x%x, target_ix %u, cdb_len %u, tag_code %u,\n",
  2300. q->d2.srb_tag, q->d2.target_ix, q->d2.cdb_len,
  2301. q->d2.tag_code);
  2302. printk
  2303. (" done_stat 0x%x, host_stat 0x%x, scsi_stat 0x%x, scsi_msg 0x%x\n",
  2304. q->d3.done_stat, q->d3.host_stat, q->d3.scsi_stat, q->d3.scsi_msg);
  2305. }
  2306. /*
  2307. * asc_prt_adv_sgblock()
  2308. *
  2309. * Display an ADV_SG_BLOCK structure.
  2310. */
  2311. static void asc_prt_adv_sgblock(int sgblockno, ADV_SG_BLOCK *b)
  2312. {
  2313. int i;
  2314. printk(" ADV_SG_BLOCK at addr 0x%lx (sgblockno %d)\n",
  2315. (ulong)b, sgblockno);
  2316. printk(" sg_cnt %u, sg_ptr 0x%x\n",
  2317. b->sg_cnt, (u32)le32_to_cpu(b->sg_ptr));
  2318. BUG_ON(b->sg_cnt > NO_OF_SG_PER_BLOCK);
  2319. if (b->sg_ptr != 0)
  2320. BUG_ON(b->sg_cnt != NO_OF_SG_PER_BLOCK);
  2321. for (i = 0; i < b->sg_cnt; i++) {
  2322. printk(" [%u]: sg_addr 0x%x, sg_count 0x%x\n",
  2323. i, (u32)le32_to_cpu(b->sg_list[i].sg_addr),
  2324. (u32)le32_to_cpu(b->sg_list[i].sg_count));
  2325. }
  2326. }
  2327. /*
  2328. * asc_prt_adv_scsi_req_q()
  2329. *
  2330. * Display an ADV_SCSI_REQ_Q structure.
  2331. */
  2332. static void asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q *q)
  2333. {
  2334. int sg_blk_cnt;
  2335. struct adv_sg_block *sg_ptr;
  2336. adv_sgblk_t *sgblkp;
  2337. printk("ADV_SCSI_REQ_Q at addr 0x%lx\n", (ulong)q);
  2338. printk(" target_id %u, target_lun %u, srb_tag 0x%x\n",
  2339. q->target_id, q->target_lun, q->srb_tag);
  2340. printk(" cntl 0x%x, data_addr 0x%lx\n",
  2341. q->cntl, (ulong)le32_to_cpu(q->data_addr));
  2342. printk(" data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
  2343. (ulong)le32_to_cpu(q->data_cnt),
  2344. (ulong)le32_to_cpu(q->sense_addr), q->sense_len);
  2345. printk
  2346. (" cdb_len %u, done_status 0x%x, host_status 0x%x, scsi_status 0x%x\n",
  2347. q->cdb_len, q->done_status, q->host_status, q->scsi_status);
  2348. printk(" sg_working_ix 0x%x, target_cmd %u\n",
  2349. q->sg_working_ix, q->target_cmd);
  2350. printk(" scsiq_rptr 0x%lx, sg_real_addr 0x%lx, sg_list_ptr 0x%lx\n",
  2351. (ulong)le32_to_cpu(q->scsiq_rptr),
  2352. (ulong)le32_to_cpu(q->sg_real_addr), (ulong)q->sg_list_ptr);
  2353. /* Display the request's ADV_SG_BLOCK structures. */
  2354. if (q->sg_list_ptr != NULL) {
  2355. sgblkp = container_of(q->sg_list_ptr, adv_sgblk_t, sg_block);
  2356. sg_blk_cnt = 0;
  2357. while (sgblkp) {
  2358. sg_ptr = &sgblkp->sg_block;
  2359. asc_prt_adv_sgblock(sg_blk_cnt, sg_ptr);
  2360. if (sg_ptr->sg_ptr == 0) {
  2361. break;
  2362. }
  2363. sgblkp = sgblkp->next_sgblkp;
  2364. sg_blk_cnt++;
  2365. }
  2366. }
  2367. }
  2368. #endif /* ADVANSYS_DEBUG */
  2369. /*
  2370. * advansys_info()
  2371. *
  2372. * Return suitable for printing on the console with the argument
  2373. * adapter's configuration information.
  2374. *
  2375. * Note: The information line should not exceed ASC_INFO_SIZE bytes,
  2376. * otherwise the static 'info' array will be overrun.
  2377. */
  2378. static const char *advansys_info(struct Scsi_Host *shost)
  2379. {
  2380. static char info[ASC_INFO_SIZE];
  2381. struct asc_board *boardp = shost_priv(shost);
  2382. ASC_DVC_VAR *asc_dvc_varp;
  2383. ADV_DVC_VAR *adv_dvc_varp;
  2384. char *busname;
  2385. char *widename = NULL;
  2386. if (ASC_NARROW_BOARD(boardp)) {
  2387. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  2388. ASC_DBG(1, "begin\n");
  2389. if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
  2390. if ((asc_dvc_varp->bus_type & ASC_IS_ISAPNP) ==
  2391. ASC_IS_ISAPNP) {
  2392. busname = "ISA PnP";
  2393. } else {
  2394. busname = "ISA";
  2395. }
  2396. sprintf(info,
  2397. "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X, DMA 0x%X",
  2398. ASC_VERSION, busname,
  2399. (ulong)shost->io_port,
  2400. (ulong)shost->io_port + ASC_IOADR_GAP - 1,
  2401. boardp->irq, shost->dma_channel);
  2402. } else {
  2403. if (asc_dvc_varp->bus_type & ASC_IS_VL) {
  2404. busname = "VL";
  2405. } else if (asc_dvc_varp->bus_type & ASC_IS_EISA) {
  2406. busname = "EISA";
  2407. } else if (asc_dvc_varp->bus_type & ASC_IS_PCI) {
  2408. if ((asc_dvc_varp->bus_type & ASC_IS_PCI_ULTRA)
  2409. == ASC_IS_PCI_ULTRA) {
  2410. busname = "PCI Ultra";
  2411. } else {
  2412. busname = "PCI";
  2413. }
  2414. } else {
  2415. busname = "?";
  2416. shost_printk(KERN_ERR, shost, "unknown bus "
  2417. "type %d\n", asc_dvc_varp->bus_type);
  2418. }
  2419. sprintf(info,
  2420. "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X",
  2421. ASC_VERSION, busname, (ulong)shost->io_port,
  2422. (ulong)shost->io_port + ASC_IOADR_GAP - 1,
  2423. boardp->irq);
  2424. }
  2425. } else {
  2426. /*
  2427. * Wide Adapter Information
  2428. *
  2429. * Memory-mapped I/O is used instead of I/O space to access
  2430. * the adapter, but display the I/O Port range. The Memory
  2431. * I/O address is displayed through the driver /proc file.
  2432. */
  2433. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  2434. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2435. widename = "Ultra-Wide";
  2436. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2437. widename = "Ultra2-Wide";
  2438. } else {
  2439. widename = "Ultra3-Wide";
  2440. }
  2441. sprintf(info,
  2442. "AdvanSys SCSI %s: PCI %s: PCIMEM 0x%lX-0x%lX, IRQ 0x%X",
  2443. ASC_VERSION, widename, (ulong)adv_dvc_varp->iop_base,
  2444. (ulong)adv_dvc_varp->iop_base + boardp->asc_n_io_port - 1, boardp->irq);
  2445. }
  2446. BUG_ON(strlen(info) >= ASC_INFO_SIZE);
  2447. ASC_DBG(1, "end\n");
  2448. return info;
  2449. }
  2450. #ifdef CONFIG_PROC_FS
  2451. /*
  2452. * asc_prt_board_devices()
  2453. *
  2454. * Print driver information for devices attached to the board.
  2455. */
  2456. static void asc_prt_board_devices(struct seq_file *m, struct Scsi_Host *shost)
  2457. {
  2458. struct asc_board *boardp = shost_priv(shost);
  2459. int chip_scsi_id;
  2460. int i;
  2461. seq_printf(m,
  2462. "\nDevice Information for AdvanSys SCSI Host %d:\n",
  2463. shost->host_no);
  2464. if (ASC_NARROW_BOARD(boardp)) {
  2465. chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
  2466. } else {
  2467. chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
  2468. }
  2469. seq_puts(m, "Target IDs Detected:");
  2470. for (i = 0; i <= ADV_MAX_TID; i++) {
  2471. if (boardp->init_tidmask & ADV_TID_TO_TIDMASK(i))
  2472. seq_printf(m, " %X,", i);
  2473. }
  2474. seq_printf(m, " (%X=Host Adapter)\n", chip_scsi_id);
  2475. }
  2476. /*
  2477. * Display Wide Board BIOS Information.
  2478. */
  2479. static void asc_prt_adv_bios(struct seq_file *m, struct Scsi_Host *shost)
  2480. {
  2481. struct asc_board *boardp = shost_priv(shost);
  2482. ushort major, minor, letter;
  2483. seq_puts(m, "\nROM BIOS Version: ");
  2484. /*
  2485. * If the BIOS saved a valid signature, then fill in
  2486. * the BIOS code segment base address.
  2487. */
  2488. if (boardp->bios_signature != 0x55AA) {
  2489. seq_puts(m, "Disabled or Pre-3.1\n"
  2490. "BIOS either disabled or Pre-3.1. If it is pre-3.1, then a newer version\n"
  2491. "can be found at the ConnectCom FTP site: ftp://ftp.connectcom.net/pub\n");
  2492. } else {
  2493. major = (boardp->bios_version >> 12) & 0xF;
  2494. minor = (boardp->bios_version >> 8) & 0xF;
  2495. letter = (boardp->bios_version & 0xFF);
  2496. seq_printf(m, "%d.%d%c\n",
  2497. major, minor,
  2498. letter >= 26 ? '?' : letter + 'A');
  2499. /*
  2500. * Current available ROM BIOS release is 3.1I for UW
  2501. * and 3.2I for U2W. This code doesn't differentiate
  2502. * UW and U2W boards.
  2503. */
  2504. if (major < 3 || (major <= 3 && minor < 1) ||
  2505. (major <= 3 && minor <= 1 && letter < ('I' - 'A'))) {
  2506. seq_puts(m, "Newer version of ROM BIOS is available at the ConnectCom FTP site:\n"
  2507. "ftp://ftp.connectcom.net/pub\n");
  2508. }
  2509. }
  2510. }
  2511. /*
  2512. * Add serial number to information bar if signature AAh
  2513. * is found in at bit 15-9 (7 bits) of word 1.
  2514. *
  2515. * Serial Number consists fo 12 alpha-numeric digits.
  2516. *
  2517. * 1 - Product type (A,B,C,D..) Word0: 15-13 (3 bits)
  2518. * 2 - MFG Location (A,B,C,D..) Word0: 12-10 (3 bits)
  2519. * 3-4 - Product ID (0-99) Word0: 9-0 (10 bits)
  2520. * 5 - Product revision (A-J) Word0: " "
  2521. *
  2522. * Signature Word1: 15-9 (7 bits)
  2523. * 6 - Year (0-9) Word1: 8-6 (3 bits) & Word2: 15 (1 bit)
  2524. * 7-8 - Week of the year (1-52) Word1: 5-0 (6 bits)
  2525. *
  2526. * 9-12 - Serial Number (A001-Z999) Word2: 14-0 (15 bits)
  2527. *
  2528. * Note 1: Only production cards will have a serial number.
  2529. *
  2530. * Note 2: Signature is most significant 7 bits (0xFE).
  2531. *
  2532. * Returns ASC_TRUE if serial number found, otherwise returns ASC_FALSE.
  2533. */
  2534. static int asc_get_eeprom_string(ushort *serialnum, uchar *cp)
  2535. {
  2536. ushort w, num;
  2537. if ((serialnum[1] & 0xFE00) != ((ushort)0xAA << 8)) {
  2538. return ASC_FALSE;
  2539. } else {
  2540. /*
  2541. * First word - 6 digits.
  2542. */
  2543. w = serialnum[0];
  2544. /* Product type - 1st digit. */
  2545. if ((*cp = 'A' + ((w & 0xE000) >> 13)) == 'H') {
  2546. /* Product type is P=Prototype */
  2547. *cp += 0x8;
  2548. }
  2549. cp++;
  2550. /* Manufacturing location - 2nd digit. */
  2551. *cp++ = 'A' + ((w & 0x1C00) >> 10);
  2552. /* Product ID - 3rd, 4th digits. */
  2553. num = w & 0x3FF;
  2554. *cp++ = '0' + (num / 100);
  2555. num %= 100;
  2556. *cp++ = '0' + (num / 10);
  2557. /* Product revision - 5th digit. */
  2558. *cp++ = 'A' + (num % 10);
  2559. /*
  2560. * Second word
  2561. */
  2562. w = serialnum[1];
  2563. /*
  2564. * Year - 6th digit.
  2565. *
  2566. * If bit 15 of third word is set, then the
  2567. * last digit of the year is greater than 7.
  2568. */
  2569. if (serialnum[2] & 0x8000) {
  2570. *cp++ = '8' + ((w & 0x1C0) >> 6);
  2571. } else {
  2572. *cp++ = '0' + ((w & 0x1C0) >> 6);
  2573. }
  2574. /* Week of year - 7th, 8th digits. */
  2575. num = w & 0x003F;
  2576. *cp++ = '0' + num / 10;
  2577. num %= 10;
  2578. *cp++ = '0' + num;
  2579. /*
  2580. * Third word
  2581. */
  2582. w = serialnum[2] & 0x7FFF;
  2583. /* Serial number - 9th digit. */
  2584. *cp++ = 'A' + (w / 1000);
  2585. /* 10th, 11th, 12th digits. */
  2586. num = w % 1000;
  2587. *cp++ = '0' + num / 100;
  2588. num %= 100;
  2589. *cp++ = '0' + num / 10;
  2590. num %= 10;
  2591. *cp++ = '0' + num;
  2592. *cp = '\0'; /* Null Terminate the string. */
  2593. return ASC_TRUE;
  2594. }
  2595. }
  2596. /*
  2597. * asc_prt_asc_board_eeprom()
  2598. *
  2599. * Print board EEPROM configuration.
  2600. */
  2601. static void asc_prt_asc_board_eeprom(struct seq_file *m, struct Scsi_Host *shost)
  2602. {
  2603. struct asc_board *boardp = shost_priv(shost);
  2604. ASC_DVC_VAR *asc_dvc_varp;
  2605. ASCEEP_CONFIG *ep;
  2606. int i;
  2607. #ifdef CONFIG_ISA
  2608. int isa_dma_speed[] = { 10, 8, 7, 6, 5, 4, 3, 2 };
  2609. #endif /* CONFIG_ISA */
  2610. uchar serialstr[13];
  2611. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  2612. ep = &boardp->eep_config.asc_eep;
  2613. seq_printf(m,
  2614. "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
  2615. shost->host_no);
  2616. if (asc_get_eeprom_string((ushort *)&ep->adapter_info[0], serialstr)
  2617. == ASC_TRUE)
  2618. seq_printf(m, " Serial Number: %s\n", serialstr);
  2619. else if (ep->adapter_info[5] == 0xBB)
  2620. seq_puts(m,
  2621. " Default Settings Used for EEPROM-less Adapter.\n");
  2622. else
  2623. seq_puts(m, " Serial Number Signature Not Present.\n");
  2624. seq_printf(m,
  2625. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2626. ASC_EEP_GET_CHIP_ID(ep), ep->max_total_qng,
  2627. ep->max_tag_qng);
  2628. seq_printf(m,
  2629. " cntl 0x%x, no_scam 0x%x\n", ep->cntl, ep->no_scam);
  2630. seq_puts(m, " Target ID: ");
  2631. for (i = 0; i <= ASC_MAX_TID; i++)
  2632. seq_printf(m, " %d", i);
  2633. seq_puts(m, "\n Disconnects: ");
  2634. for (i = 0; i <= ASC_MAX_TID; i++)
  2635. seq_printf(m, " %c",
  2636. (ep->disc_enable & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2637. seq_puts(m, "\n Command Queuing: ");
  2638. for (i = 0; i <= ASC_MAX_TID; i++)
  2639. seq_printf(m, " %c",
  2640. (ep->use_cmd_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2641. seq_puts(m, "\n Start Motor: ");
  2642. for (i = 0; i <= ASC_MAX_TID; i++)
  2643. seq_printf(m, " %c",
  2644. (ep->start_motor & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2645. seq_puts(m, "\n Synchronous Transfer:");
  2646. for (i = 0; i <= ASC_MAX_TID; i++)
  2647. seq_printf(m, " %c",
  2648. (ep->init_sdtr & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2649. seq_putc(m, '\n');
  2650. #ifdef CONFIG_ISA
  2651. if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
  2652. seq_printf(m,
  2653. " Host ISA DMA speed: %d MB/S\n",
  2654. isa_dma_speed[ASC_EEP_GET_DMA_SPD(ep)]);
  2655. }
  2656. #endif /* CONFIG_ISA */
  2657. }
  2658. /*
  2659. * asc_prt_adv_board_eeprom()
  2660. *
  2661. * Print board EEPROM configuration.
  2662. */
  2663. static void asc_prt_adv_board_eeprom(struct seq_file *m, struct Scsi_Host *shost)
  2664. {
  2665. struct asc_board *boardp = shost_priv(shost);
  2666. ADV_DVC_VAR *adv_dvc_varp;
  2667. int i;
  2668. char *termstr;
  2669. uchar serialstr[13];
  2670. ADVEEP_3550_CONFIG *ep_3550 = NULL;
  2671. ADVEEP_38C0800_CONFIG *ep_38C0800 = NULL;
  2672. ADVEEP_38C1600_CONFIG *ep_38C1600 = NULL;
  2673. ushort word;
  2674. ushort *wordp;
  2675. ushort sdtr_speed = 0;
  2676. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  2677. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2678. ep_3550 = &boardp->eep_config.adv_3550_eep;
  2679. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2680. ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
  2681. } else {
  2682. ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
  2683. }
  2684. seq_printf(m,
  2685. "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
  2686. shost->host_no);
  2687. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2688. wordp = &ep_3550->serial_number_word1;
  2689. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2690. wordp = &ep_38C0800->serial_number_word1;
  2691. } else {
  2692. wordp = &ep_38C1600->serial_number_word1;
  2693. }
  2694. if (asc_get_eeprom_string(wordp, serialstr) == ASC_TRUE)
  2695. seq_printf(m, " Serial Number: %s\n", serialstr);
  2696. else
  2697. seq_puts(m, " Serial Number Signature Not Present.\n");
  2698. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
  2699. seq_printf(m,
  2700. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2701. ep_3550->adapter_scsi_id,
  2702. ep_3550->max_host_qng, ep_3550->max_dvc_qng);
  2703. else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
  2704. seq_printf(m,
  2705. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2706. ep_38C0800->adapter_scsi_id,
  2707. ep_38C0800->max_host_qng,
  2708. ep_38C0800->max_dvc_qng);
  2709. else
  2710. seq_printf(m,
  2711. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2712. ep_38C1600->adapter_scsi_id,
  2713. ep_38C1600->max_host_qng,
  2714. ep_38C1600->max_dvc_qng);
  2715. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2716. word = ep_3550->termination;
  2717. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2718. word = ep_38C0800->termination_lvd;
  2719. } else {
  2720. word = ep_38C1600->termination_lvd;
  2721. }
  2722. switch (word) {
  2723. case 1:
  2724. termstr = "Low Off/High Off";
  2725. break;
  2726. case 2:
  2727. termstr = "Low Off/High On";
  2728. break;
  2729. case 3:
  2730. termstr = "Low On/High On";
  2731. break;
  2732. default:
  2733. case 0:
  2734. termstr = "Automatic";
  2735. break;
  2736. }
  2737. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
  2738. seq_printf(m,
  2739. " termination: %u (%s), bios_ctrl: 0x%x\n",
  2740. ep_3550->termination, termstr,
  2741. ep_3550->bios_ctrl);
  2742. else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
  2743. seq_printf(m,
  2744. " termination: %u (%s), bios_ctrl: 0x%x\n",
  2745. ep_38C0800->termination_lvd, termstr,
  2746. ep_38C0800->bios_ctrl);
  2747. else
  2748. seq_printf(m,
  2749. " termination: %u (%s), bios_ctrl: 0x%x\n",
  2750. ep_38C1600->termination_lvd, termstr,
  2751. ep_38C1600->bios_ctrl);
  2752. seq_puts(m, " Target ID: ");
  2753. for (i = 0; i <= ADV_MAX_TID; i++)
  2754. seq_printf(m, " %X", i);
  2755. seq_putc(m, '\n');
  2756. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2757. word = ep_3550->disc_enable;
  2758. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2759. word = ep_38C0800->disc_enable;
  2760. } else {
  2761. word = ep_38C1600->disc_enable;
  2762. }
  2763. seq_puts(m, " Disconnects: ");
  2764. for (i = 0; i <= ADV_MAX_TID; i++)
  2765. seq_printf(m, " %c",
  2766. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2767. seq_putc(m, '\n');
  2768. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2769. word = ep_3550->tagqng_able;
  2770. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2771. word = ep_38C0800->tagqng_able;
  2772. } else {
  2773. word = ep_38C1600->tagqng_able;
  2774. }
  2775. seq_puts(m, " Command Queuing: ");
  2776. for (i = 0; i <= ADV_MAX_TID; i++)
  2777. seq_printf(m, " %c",
  2778. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2779. seq_putc(m, '\n');
  2780. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2781. word = ep_3550->start_motor;
  2782. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2783. word = ep_38C0800->start_motor;
  2784. } else {
  2785. word = ep_38C1600->start_motor;
  2786. }
  2787. seq_puts(m, " Start Motor: ");
  2788. for (i = 0; i <= ADV_MAX_TID; i++)
  2789. seq_printf(m, " %c",
  2790. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2791. seq_putc(m, '\n');
  2792. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2793. seq_puts(m, " Synchronous Transfer:");
  2794. for (i = 0; i <= ADV_MAX_TID; i++)
  2795. seq_printf(m, " %c",
  2796. (ep_3550->sdtr_able & ADV_TID_TO_TIDMASK(i)) ?
  2797. 'Y' : 'N');
  2798. seq_putc(m, '\n');
  2799. }
  2800. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2801. seq_puts(m, " Ultra Transfer: ");
  2802. for (i = 0; i <= ADV_MAX_TID; i++)
  2803. seq_printf(m, " %c",
  2804. (ep_3550->ultra_able & ADV_TID_TO_TIDMASK(i))
  2805. ? 'Y' : 'N');
  2806. seq_putc(m, '\n');
  2807. }
  2808. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2809. word = ep_3550->wdtr_able;
  2810. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2811. word = ep_38C0800->wdtr_able;
  2812. } else {
  2813. word = ep_38C1600->wdtr_able;
  2814. }
  2815. seq_puts(m, " Wide Transfer: ");
  2816. for (i = 0; i <= ADV_MAX_TID; i++)
  2817. seq_printf(m, " %c",
  2818. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2819. seq_putc(m, '\n');
  2820. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800 ||
  2821. adv_dvc_varp->chip_type == ADV_CHIP_ASC38C1600) {
  2822. seq_puts(m, " Synchronous Transfer Speed (Mhz):\n ");
  2823. for (i = 0; i <= ADV_MAX_TID; i++) {
  2824. char *speed_str;
  2825. if (i == 0) {
  2826. sdtr_speed = adv_dvc_varp->sdtr_speed1;
  2827. } else if (i == 4) {
  2828. sdtr_speed = adv_dvc_varp->sdtr_speed2;
  2829. } else if (i == 8) {
  2830. sdtr_speed = adv_dvc_varp->sdtr_speed3;
  2831. } else if (i == 12) {
  2832. sdtr_speed = adv_dvc_varp->sdtr_speed4;
  2833. }
  2834. switch (sdtr_speed & ADV_MAX_TID) {
  2835. case 0:
  2836. speed_str = "Off";
  2837. break;
  2838. case 1:
  2839. speed_str = " 5";
  2840. break;
  2841. case 2:
  2842. speed_str = " 10";
  2843. break;
  2844. case 3:
  2845. speed_str = " 20";
  2846. break;
  2847. case 4:
  2848. speed_str = " 40";
  2849. break;
  2850. case 5:
  2851. speed_str = " 80";
  2852. break;
  2853. default:
  2854. speed_str = "Unk";
  2855. break;
  2856. }
  2857. seq_printf(m, "%X:%s ", i, speed_str);
  2858. if (i == 7)
  2859. seq_puts(m, "\n ");
  2860. sdtr_speed >>= 4;
  2861. }
  2862. seq_putc(m, '\n');
  2863. }
  2864. }
  2865. /*
  2866. * asc_prt_driver_conf()
  2867. */
  2868. static void asc_prt_driver_conf(struct seq_file *m, struct Scsi_Host *shost)
  2869. {
  2870. struct asc_board *boardp = shost_priv(shost);
  2871. int chip_scsi_id;
  2872. seq_printf(m,
  2873. "\nLinux Driver Configuration and Information for AdvanSys SCSI Host %d:\n",
  2874. shost->host_no);
  2875. seq_printf(m,
  2876. " host_busy %u, max_id %u, max_lun %llu, max_channel %u\n",
  2877. atomic_read(&shost->host_busy), shost->max_id,
  2878. shost->max_lun, shost->max_channel);
  2879. seq_printf(m,
  2880. " unique_id %d, can_queue %d, this_id %d, sg_tablesize %u, cmd_per_lun %u\n",
  2881. shost->unique_id, shost->can_queue, shost->this_id,
  2882. shost->sg_tablesize, shost->cmd_per_lun);
  2883. seq_printf(m,
  2884. " unchecked_isa_dma %d, use_clustering %d\n",
  2885. shost->unchecked_isa_dma, shost->use_clustering);
  2886. seq_printf(m,
  2887. " flags 0x%x, last_reset 0x%lx, jiffies 0x%lx, asc_n_io_port 0x%x\n",
  2888. boardp->flags, shost->last_reset, jiffies,
  2889. boardp->asc_n_io_port);
  2890. seq_printf(m, " io_port 0x%lx\n", shost->io_port);
  2891. if (ASC_NARROW_BOARD(boardp)) {
  2892. chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
  2893. } else {
  2894. chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
  2895. }
  2896. }
  2897. /*
  2898. * asc_prt_asc_board_info()
  2899. *
  2900. * Print dynamic board configuration information.
  2901. */
  2902. static void asc_prt_asc_board_info(struct seq_file *m, struct Scsi_Host *shost)
  2903. {
  2904. struct asc_board *boardp = shost_priv(shost);
  2905. int chip_scsi_id;
  2906. ASC_DVC_VAR *v;
  2907. ASC_DVC_CFG *c;
  2908. int i;
  2909. int renegotiate = 0;
  2910. v = &boardp->dvc_var.asc_dvc_var;
  2911. c = &boardp->dvc_cfg.asc_dvc_cfg;
  2912. chip_scsi_id = c->chip_scsi_id;
  2913. seq_printf(m,
  2914. "\nAsc Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
  2915. shost->host_no);
  2916. seq_printf(m, " chip_version %u, mcode_date 0x%x, "
  2917. "mcode_version 0x%x, err_code %u\n",
  2918. c->chip_version, c->mcode_date, c->mcode_version,
  2919. v->err_code);
  2920. /* Current number of commands waiting for the host. */
  2921. seq_printf(m,
  2922. " Total Command Pending: %d\n", v->cur_total_qng);
  2923. seq_puts(m, " Command Queuing:");
  2924. for (i = 0; i <= ASC_MAX_TID; i++) {
  2925. if ((chip_scsi_id == i) ||
  2926. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2927. continue;
  2928. }
  2929. seq_printf(m, " %X:%c",
  2930. i,
  2931. (v->use_tagged_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2932. }
  2933. /* Current number of commands waiting for a device. */
  2934. seq_puts(m, "\n Command Queue Pending:");
  2935. for (i = 0; i <= ASC_MAX_TID; i++) {
  2936. if ((chip_scsi_id == i) ||
  2937. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2938. continue;
  2939. }
  2940. seq_printf(m, " %X:%u", i, v->cur_dvc_qng[i]);
  2941. }
  2942. /* Current limit on number of commands that can be sent to a device. */
  2943. seq_puts(m, "\n Command Queue Limit:");
  2944. for (i = 0; i <= ASC_MAX_TID; i++) {
  2945. if ((chip_scsi_id == i) ||
  2946. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2947. continue;
  2948. }
  2949. seq_printf(m, " %X:%u", i, v->max_dvc_qng[i]);
  2950. }
  2951. /* Indicate whether the device has returned queue full status. */
  2952. seq_puts(m, "\n Command Queue Full:");
  2953. for (i = 0; i <= ASC_MAX_TID; i++) {
  2954. if ((chip_scsi_id == i) ||
  2955. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2956. continue;
  2957. }
  2958. if (boardp->queue_full & ADV_TID_TO_TIDMASK(i))
  2959. seq_printf(m, " %X:Y-%d",
  2960. i, boardp->queue_full_cnt[i]);
  2961. else
  2962. seq_printf(m, " %X:N", i);
  2963. }
  2964. seq_puts(m, "\n Synchronous Transfer:");
  2965. for (i = 0; i <= ASC_MAX_TID; i++) {
  2966. if ((chip_scsi_id == i) ||
  2967. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2968. continue;
  2969. }
  2970. seq_printf(m, " %X:%c",
  2971. i,
  2972. (v->sdtr_done & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2973. }
  2974. seq_putc(m, '\n');
  2975. for (i = 0; i <= ASC_MAX_TID; i++) {
  2976. uchar syn_period_ix;
  2977. if ((chip_scsi_id == i) ||
  2978. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
  2979. ((v->init_sdtr & ADV_TID_TO_TIDMASK(i)) == 0)) {
  2980. continue;
  2981. }
  2982. seq_printf(m, " %X:", i);
  2983. if ((boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET) == 0) {
  2984. seq_puts(m, " Asynchronous");
  2985. } else {
  2986. syn_period_ix =
  2987. (boardp->sdtr_data[i] >> 4) & (v->max_sdtr_index -
  2988. 1);
  2989. seq_printf(m,
  2990. " Transfer Period Factor: %d (%d.%d Mhz),",
  2991. v->sdtr_period_tbl[syn_period_ix],
  2992. 250 / v->sdtr_period_tbl[syn_period_ix],
  2993. ASC_TENTHS(250,
  2994. v->sdtr_period_tbl[syn_period_ix]));
  2995. seq_printf(m, " REQ/ACK Offset: %d",
  2996. boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET);
  2997. }
  2998. if ((v->sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  2999. seq_puts(m, "*\n");
  3000. renegotiate = 1;
  3001. } else {
  3002. seq_putc(m, '\n');
  3003. }
  3004. }
  3005. if (renegotiate) {
  3006. seq_puts(m, " * = Re-negotiation pending before next command.\n");
  3007. }
  3008. }
  3009. /*
  3010. * asc_prt_adv_board_info()
  3011. *
  3012. * Print dynamic board configuration information.
  3013. */
  3014. static void asc_prt_adv_board_info(struct seq_file *m, struct Scsi_Host *shost)
  3015. {
  3016. struct asc_board *boardp = shost_priv(shost);
  3017. int i;
  3018. ADV_DVC_VAR *v;
  3019. ADV_DVC_CFG *c;
  3020. AdvPortAddr iop_base;
  3021. ushort chip_scsi_id;
  3022. ushort lramword;
  3023. uchar lrambyte;
  3024. ushort tagqng_able;
  3025. ushort sdtr_able, wdtr_able;
  3026. ushort wdtr_done, sdtr_done;
  3027. ushort period = 0;
  3028. int renegotiate = 0;
  3029. v = &boardp->dvc_var.adv_dvc_var;
  3030. c = &boardp->dvc_cfg.adv_dvc_cfg;
  3031. iop_base = v->iop_base;
  3032. chip_scsi_id = v->chip_scsi_id;
  3033. seq_printf(m,
  3034. "\nAdv Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
  3035. shost->host_no);
  3036. seq_printf(m,
  3037. " iop_base 0x%lx, cable_detect: %X, err_code %u\n",
  3038. (unsigned long)v->iop_base,
  3039. AdvReadWordRegister(iop_base,IOPW_SCSI_CFG1) & CABLE_DETECT,
  3040. v->err_code);
  3041. seq_printf(m, " chip_version %u, mcode_date 0x%x, "
  3042. "mcode_version 0x%x\n", c->chip_version,
  3043. c->mcode_date, c->mcode_version);
  3044. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  3045. seq_puts(m, " Queuing Enabled:");
  3046. for (i = 0; i <= ADV_MAX_TID; i++) {
  3047. if ((chip_scsi_id == i) ||
  3048. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3049. continue;
  3050. }
  3051. seq_printf(m, " %X:%c",
  3052. i,
  3053. (tagqng_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3054. }
  3055. seq_puts(m, "\n Queue Limit:");
  3056. for (i = 0; i <= ADV_MAX_TID; i++) {
  3057. if ((chip_scsi_id == i) ||
  3058. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3059. continue;
  3060. }
  3061. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + i,
  3062. lrambyte);
  3063. seq_printf(m, " %X:%d", i, lrambyte);
  3064. }
  3065. seq_puts(m, "\n Command Pending:");
  3066. for (i = 0; i <= ADV_MAX_TID; i++) {
  3067. if ((chip_scsi_id == i) ||
  3068. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3069. continue;
  3070. }
  3071. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_QUEUED_CMD + i,
  3072. lrambyte);
  3073. seq_printf(m, " %X:%d", i, lrambyte);
  3074. }
  3075. seq_putc(m, '\n');
  3076. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  3077. seq_puts(m, " Wide Enabled:");
  3078. for (i = 0; i <= ADV_MAX_TID; i++) {
  3079. if ((chip_scsi_id == i) ||
  3080. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3081. continue;
  3082. }
  3083. seq_printf(m, " %X:%c",
  3084. i,
  3085. (wdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3086. }
  3087. seq_putc(m, '\n');
  3088. AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, wdtr_done);
  3089. seq_puts(m, " Transfer Bit Width:");
  3090. for (i = 0; i <= ADV_MAX_TID; i++) {
  3091. if ((chip_scsi_id == i) ||
  3092. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3093. continue;
  3094. }
  3095. AdvReadWordLram(iop_base,
  3096. ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
  3097. lramword);
  3098. seq_printf(m, " %X:%d",
  3099. i, (lramword & 0x8000) ? 16 : 8);
  3100. if ((wdtr_able & ADV_TID_TO_TIDMASK(i)) &&
  3101. (wdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  3102. seq_putc(m, '*');
  3103. renegotiate = 1;
  3104. }
  3105. }
  3106. seq_putc(m, '\n');
  3107. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  3108. seq_puts(m, " Synchronous Enabled:");
  3109. for (i = 0; i <= ADV_MAX_TID; i++) {
  3110. if ((chip_scsi_id == i) ||
  3111. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3112. continue;
  3113. }
  3114. seq_printf(m, " %X:%c",
  3115. i,
  3116. (sdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3117. }
  3118. seq_putc(m, '\n');
  3119. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, sdtr_done);
  3120. for (i = 0; i <= ADV_MAX_TID; i++) {
  3121. AdvReadWordLram(iop_base,
  3122. ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
  3123. lramword);
  3124. lramword &= ~0x8000;
  3125. if ((chip_scsi_id == i) ||
  3126. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
  3127. ((sdtr_able & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3128. continue;
  3129. }
  3130. seq_printf(m, " %X:", i);
  3131. if ((lramword & 0x1F) == 0) { /* Check for REQ/ACK Offset 0. */
  3132. seq_puts(m, " Asynchronous");
  3133. } else {
  3134. seq_puts(m, " Transfer Period Factor: ");
  3135. if ((lramword & 0x1F00) == 0x1100) { /* 80 Mhz */
  3136. seq_puts(m, "9 (80.0 Mhz),");
  3137. } else if ((lramword & 0x1F00) == 0x1000) { /* 40 Mhz */
  3138. seq_puts(m, "10 (40.0 Mhz),");
  3139. } else { /* 20 Mhz or below. */
  3140. period = (((lramword >> 8) * 25) + 50) / 4;
  3141. if (period == 0) { /* Should never happen. */
  3142. seq_printf(m, "%d (? Mhz), ", period);
  3143. } else {
  3144. seq_printf(m,
  3145. "%d (%d.%d Mhz),",
  3146. period, 250 / period,
  3147. ASC_TENTHS(250, period));
  3148. }
  3149. }
  3150. seq_printf(m, " REQ/ACK Offset: %d",
  3151. lramword & 0x1F);
  3152. }
  3153. if ((sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  3154. seq_puts(m, "*\n");
  3155. renegotiate = 1;
  3156. } else {
  3157. seq_putc(m, '\n');
  3158. }
  3159. }
  3160. if (renegotiate) {
  3161. seq_puts(m, " * = Re-negotiation pending before next command.\n");
  3162. }
  3163. }
  3164. #ifdef ADVANSYS_STATS
  3165. /*
  3166. * asc_prt_board_stats()
  3167. */
  3168. static void asc_prt_board_stats(struct seq_file *m, struct Scsi_Host *shost)
  3169. {
  3170. struct asc_board *boardp = shost_priv(shost);
  3171. struct asc_stats *s = &boardp->asc_stats;
  3172. seq_printf(m,
  3173. "\nLinux Driver Statistics for AdvanSys SCSI Host %d:\n",
  3174. shost->host_no);
  3175. seq_printf(m,
  3176. " queuecommand %u, reset %u, biosparam %u, interrupt %u\n",
  3177. s->queuecommand, s->reset, s->biosparam,
  3178. s->interrupt);
  3179. seq_printf(m,
  3180. " callback %u, done %u, build_error %u, build_noreq %u, build_nosg %u\n",
  3181. s->callback, s->done, s->build_error,
  3182. s->adv_build_noreq, s->adv_build_nosg);
  3183. seq_printf(m,
  3184. " exe_noerror %u, exe_busy %u, exe_error %u, exe_unknown %u\n",
  3185. s->exe_noerror, s->exe_busy, s->exe_error,
  3186. s->exe_unknown);
  3187. /*
  3188. * Display data transfer statistics.
  3189. */
  3190. if (s->xfer_cnt > 0) {
  3191. seq_printf(m, " xfer_cnt %u, xfer_elem %u, ",
  3192. s->xfer_cnt, s->xfer_elem);
  3193. seq_printf(m, "xfer_bytes %u.%01u kb\n",
  3194. s->xfer_sect / 2, ASC_TENTHS(s->xfer_sect, 2));
  3195. /* Scatter gather transfer statistics */
  3196. seq_printf(m, " avg_num_elem %u.%01u, ",
  3197. s->xfer_elem / s->xfer_cnt,
  3198. ASC_TENTHS(s->xfer_elem, s->xfer_cnt));
  3199. seq_printf(m, "avg_elem_size %u.%01u kb, ",
  3200. (s->xfer_sect / 2) / s->xfer_elem,
  3201. ASC_TENTHS((s->xfer_sect / 2), s->xfer_elem));
  3202. seq_printf(m, "avg_xfer_size %u.%01u kb\n",
  3203. (s->xfer_sect / 2) / s->xfer_cnt,
  3204. ASC_TENTHS((s->xfer_sect / 2), s->xfer_cnt));
  3205. }
  3206. }
  3207. #endif /* ADVANSYS_STATS */
  3208. /*
  3209. * advansys_show_info() - /proc/scsi/advansys/{0,1,2,3,...}
  3210. *
  3211. * m: seq_file to print into
  3212. * shost: Scsi_Host
  3213. *
  3214. * Return the number of bytes read from or written to a
  3215. * /proc/scsi/advansys/[0...] file.
  3216. */
  3217. static int
  3218. advansys_show_info(struct seq_file *m, struct Scsi_Host *shost)
  3219. {
  3220. struct asc_board *boardp = shost_priv(shost);
  3221. ASC_DBG(1, "begin\n");
  3222. /*
  3223. * User read of /proc/scsi/advansys/[0...] file.
  3224. */
  3225. /*
  3226. * Get board configuration information.
  3227. *
  3228. * advansys_info() returns the board string from its own static buffer.
  3229. */
  3230. /* Copy board information. */
  3231. seq_printf(m, "%s\n", (char *)advansys_info(shost));
  3232. /*
  3233. * Display Wide Board BIOS Information.
  3234. */
  3235. if (!ASC_NARROW_BOARD(boardp))
  3236. asc_prt_adv_bios(m, shost);
  3237. /*
  3238. * Display driver information for each device attached to the board.
  3239. */
  3240. asc_prt_board_devices(m, shost);
  3241. /*
  3242. * Display EEPROM configuration for the board.
  3243. */
  3244. if (ASC_NARROW_BOARD(boardp))
  3245. asc_prt_asc_board_eeprom(m, shost);
  3246. else
  3247. asc_prt_adv_board_eeprom(m, shost);
  3248. /*
  3249. * Display driver configuration and information for the board.
  3250. */
  3251. asc_prt_driver_conf(m, shost);
  3252. #ifdef ADVANSYS_STATS
  3253. /*
  3254. * Display driver statistics for the board.
  3255. */
  3256. asc_prt_board_stats(m, shost);
  3257. #endif /* ADVANSYS_STATS */
  3258. /*
  3259. * Display Asc Library dynamic configuration information
  3260. * for the board.
  3261. */
  3262. if (ASC_NARROW_BOARD(boardp))
  3263. asc_prt_asc_board_info(m, shost);
  3264. else
  3265. asc_prt_adv_board_info(m, shost);
  3266. return 0;
  3267. }
  3268. #endif /* CONFIG_PROC_FS */
  3269. static void asc_scsi_done(struct scsi_cmnd *scp)
  3270. {
  3271. scsi_dma_unmap(scp);
  3272. ASC_STATS(scp->device->host, done);
  3273. scp->scsi_done(scp);
  3274. }
  3275. static void AscSetBank(PortAddr iop_base, uchar bank)
  3276. {
  3277. uchar val;
  3278. val = AscGetChipControl(iop_base) &
  3279. (~
  3280. (CC_SINGLE_STEP | CC_TEST | CC_DIAG | CC_SCSI_RESET |
  3281. CC_CHIP_RESET));
  3282. if (bank == 1) {
  3283. val |= CC_BANK_ONE;
  3284. } else if (bank == 2) {
  3285. val |= CC_DIAG | CC_BANK_ONE;
  3286. } else {
  3287. val &= ~CC_BANK_ONE;
  3288. }
  3289. AscSetChipControl(iop_base, val);
  3290. }
  3291. static void AscSetChipIH(PortAddr iop_base, ushort ins_code)
  3292. {
  3293. AscSetBank(iop_base, 1);
  3294. AscWriteChipIH(iop_base, ins_code);
  3295. AscSetBank(iop_base, 0);
  3296. }
  3297. static int AscStartChip(PortAddr iop_base)
  3298. {
  3299. AscSetChipControl(iop_base, 0);
  3300. if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
  3301. return (0);
  3302. }
  3303. return (1);
  3304. }
  3305. static bool AscStopChip(PortAddr iop_base)
  3306. {
  3307. uchar cc_val;
  3308. cc_val =
  3309. AscGetChipControl(iop_base) &
  3310. (~(CC_SINGLE_STEP | CC_TEST | CC_DIAG));
  3311. AscSetChipControl(iop_base, (uchar)(cc_val | CC_HALT));
  3312. AscSetChipIH(iop_base, INS_HALT);
  3313. AscSetChipIH(iop_base, INS_RFLAG_WTM);
  3314. if ((AscGetChipStatus(iop_base) & CSW_HALTED) == 0) {
  3315. return false;
  3316. }
  3317. return true;
  3318. }
  3319. static bool AscIsChipHalted(PortAddr iop_base)
  3320. {
  3321. if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
  3322. if ((AscGetChipControl(iop_base) & CC_HALT) != 0) {
  3323. return true;
  3324. }
  3325. }
  3326. return false;
  3327. }
  3328. static bool AscResetChipAndScsiBus(ASC_DVC_VAR *asc_dvc)
  3329. {
  3330. PortAddr iop_base;
  3331. int i = 10;
  3332. iop_base = asc_dvc->iop_base;
  3333. while ((AscGetChipStatus(iop_base) & CSW_SCSI_RESET_ACTIVE)
  3334. && (i-- > 0)) {
  3335. mdelay(100);
  3336. }
  3337. AscStopChip(iop_base);
  3338. AscSetChipControl(iop_base, CC_CHIP_RESET | CC_SCSI_RESET | CC_HALT);
  3339. udelay(60);
  3340. AscSetChipIH(iop_base, INS_RFLAG_WTM);
  3341. AscSetChipIH(iop_base, INS_HALT);
  3342. AscSetChipControl(iop_base, CC_CHIP_RESET | CC_HALT);
  3343. AscSetChipControl(iop_base, CC_HALT);
  3344. mdelay(200);
  3345. AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
  3346. AscSetChipStatus(iop_base, 0);
  3347. return (AscIsChipHalted(iop_base));
  3348. }
  3349. static int AscFindSignature(PortAddr iop_base)
  3350. {
  3351. ushort sig_word;
  3352. ASC_DBG(1, "AscGetChipSignatureByte(0x%x) 0x%x\n",
  3353. iop_base, AscGetChipSignatureByte(iop_base));
  3354. if (AscGetChipSignatureByte(iop_base) == (uchar)ASC_1000_ID1B) {
  3355. ASC_DBG(1, "AscGetChipSignatureWord(0x%x) 0x%x\n",
  3356. iop_base, AscGetChipSignatureWord(iop_base));
  3357. sig_word = AscGetChipSignatureWord(iop_base);
  3358. if ((sig_word == (ushort)ASC_1000_ID0W) ||
  3359. (sig_word == (ushort)ASC_1000_ID0W_FIX)) {
  3360. return (1);
  3361. }
  3362. }
  3363. return (0);
  3364. }
  3365. static void AscEnableInterrupt(PortAddr iop_base)
  3366. {
  3367. ushort cfg;
  3368. cfg = AscGetChipCfgLsw(iop_base);
  3369. AscSetChipCfgLsw(iop_base, cfg | ASC_CFG0_HOST_INT_ON);
  3370. }
  3371. static void AscDisableInterrupt(PortAddr iop_base)
  3372. {
  3373. ushort cfg;
  3374. cfg = AscGetChipCfgLsw(iop_base);
  3375. AscSetChipCfgLsw(iop_base, cfg & (~ASC_CFG0_HOST_INT_ON));
  3376. }
  3377. static uchar AscReadLramByte(PortAddr iop_base, ushort addr)
  3378. {
  3379. unsigned char byte_data;
  3380. unsigned short word_data;
  3381. if (isodd_word(addr)) {
  3382. AscSetChipLramAddr(iop_base, addr - 1);
  3383. word_data = AscGetChipLramData(iop_base);
  3384. byte_data = (word_data >> 8) & 0xFF;
  3385. } else {
  3386. AscSetChipLramAddr(iop_base, addr);
  3387. word_data = AscGetChipLramData(iop_base);
  3388. byte_data = word_data & 0xFF;
  3389. }
  3390. return byte_data;
  3391. }
  3392. static ushort AscReadLramWord(PortAddr iop_base, ushort addr)
  3393. {
  3394. ushort word_data;
  3395. AscSetChipLramAddr(iop_base, addr);
  3396. word_data = AscGetChipLramData(iop_base);
  3397. return (word_data);
  3398. }
  3399. static void
  3400. AscMemWordSetLram(PortAddr iop_base, ushort s_addr, ushort set_wval, int words)
  3401. {
  3402. int i;
  3403. AscSetChipLramAddr(iop_base, s_addr);
  3404. for (i = 0; i < words; i++) {
  3405. AscSetChipLramData(iop_base, set_wval);
  3406. }
  3407. }
  3408. static void AscWriteLramWord(PortAddr iop_base, ushort addr, ushort word_val)
  3409. {
  3410. AscSetChipLramAddr(iop_base, addr);
  3411. AscSetChipLramData(iop_base, word_val);
  3412. }
  3413. static void AscWriteLramByte(PortAddr iop_base, ushort addr, uchar byte_val)
  3414. {
  3415. ushort word_data;
  3416. if (isodd_word(addr)) {
  3417. addr--;
  3418. word_data = AscReadLramWord(iop_base, addr);
  3419. word_data &= 0x00FF;
  3420. word_data |= (((ushort)byte_val << 8) & 0xFF00);
  3421. } else {
  3422. word_data = AscReadLramWord(iop_base, addr);
  3423. word_data &= 0xFF00;
  3424. word_data |= ((ushort)byte_val & 0x00FF);
  3425. }
  3426. AscWriteLramWord(iop_base, addr, word_data);
  3427. }
  3428. /*
  3429. * Copy 2 bytes to LRAM.
  3430. *
  3431. * The source data is assumed to be in little-endian order in memory
  3432. * and is maintained in little-endian order when written to LRAM.
  3433. */
  3434. static void
  3435. AscMemWordCopyPtrToLram(PortAddr iop_base, ushort s_addr,
  3436. const uchar *s_buffer, int words)
  3437. {
  3438. int i;
  3439. AscSetChipLramAddr(iop_base, s_addr);
  3440. for (i = 0; i < 2 * words; i += 2) {
  3441. /*
  3442. * On a little-endian system the second argument below
  3443. * produces a little-endian ushort which is written to
  3444. * LRAM in little-endian order. On a big-endian system
  3445. * the second argument produces a big-endian ushort which
  3446. * is "transparently" byte-swapped by outpw() and written
  3447. * in little-endian order to LRAM.
  3448. */
  3449. outpw(iop_base + IOP_RAM_DATA,
  3450. ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]);
  3451. }
  3452. }
  3453. /*
  3454. * Copy 4 bytes to LRAM.
  3455. *
  3456. * The source data is assumed to be in little-endian order in memory
  3457. * and is maintained in little-endian order when written to LRAM.
  3458. */
  3459. static void
  3460. AscMemDWordCopyPtrToLram(PortAddr iop_base,
  3461. ushort s_addr, uchar *s_buffer, int dwords)
  3462. {
  3463. int i;
  3464. AscSetChipLramAddr(iop_base, s_addr);
  3465. for (i = 0; i < 4 * dwords; i += 4) {
  3466. outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]); /* LSW */
  3467. outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 3] << 8) | s_buffer[i + 2]); /* MSW */
  3468. }
  3469. }
  3470. /*
  3471. * Copy 2 bytes from LRAM.
  3472. *
  3473. * The source data is assumed to be in little-endian order in LRAM
  3474. * and is maintained in little-endian order when written to memory.
  3475. */
  3476. static void
  3477. AscMemWordCopyPtrFromLram(PortAddr iop_base,
  3478. ushort s_addr, uchar *d_buffer, int words)
  3479. {
  3480. int i;
  3481. ushort word;
  3482. AscSetChipLramAddr(iop_base, s_addr);
  3483. for (i = 0; i < 2 * words; i += 2) {
  3484. word = inpw(iop_base + IOP_RAM_DATA);
  3485. d_buffer[i] = word & 0xff;
  3486. d_buffer[i + 1] = (word >> 8) & 0xff;
  3487. }
  3488. }
  3489. static u32 AscMemSumLramWord(PortAddr iop_base, ushort s_addr, int words)
  3490. {
  3491. u32 sum = 0;
  3492. int i;
  3493. for (i = 0; i < words; i++, s_addr += 2) {
  3494. sum += AscReadLramWord(iop_base, s_addr);
  3495. }
  3496. return (sum);
  3497. }
  3498. static void AscInitLram(ASC_DVC_VAR *asc_dvc)
  3499. {
  3500. uchar i;
  3501. ushort s_addr;
  3502. PortAddr iop_base;
  3503. iop_base = asc_dvc->iop_base;
  3504. AscMemWordSetLram(iop_base, ASC_QADR_BEG, 0,
  3505. (ushort)(((int)(asc_dvc->max_total_qng + 2 + 1) *
  3506. 64) >> 1));
  3507. i = ASC_MIN_ACTIVE_QNO;
  3508. s_addr = ASC_QADR_BEG + ASC_QBLK_SIZE;
  3509. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  3510. (uchar)(i + 1));
  3511. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  3512. (uchar)(asc_dvc->max_total_qng));
  3513. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  3514. (uchar)i);
  3515. i++;
  3516. s_addr += ASC_QBLK_SIZE;
  3517. for (; i < asc_dvc->max_total_qng; i++, s_addr += ASC_QBLK_SIZE) {
  3518. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  3519. (uchar)(i + 1));
  3520. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  3521. (uchar)(i - 1));
  3522. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  3523. (uchar)i);
  3524. }
  3525. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  3526. (uchar)ASC_QLINK_END);
  3527. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  3528. (uchar)(asc_dvc->max_total_qng - 1));
  3529. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  3530. (uchar)asc_dvc->max_total_qng);
  3531. i++;
  3532. s_addr += ASC_QBLK_SIZE;
  3533. for (; i <= (uchar)(asc_dvc->max_total_qng + 3);
  3534. i++, s_addr += ASC_QBLK_SIZE) {
  3535. AscWriteLramByte(iop_base,
  3536. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_FWD), i);
  3537. AscWriteLramByte(iop_base,
  3538. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_BWD), i);
  3539. AscWriteLramByte(iop_base,
  3540. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_QNO), i);
  3541. }
  3542. }
  3543. static u32
  3544. AscLoadMicroCode(PortAddr iop_base, ushort s_addr,
  3545. const uchar *mcode_buf, ushort mcode_size)
  3546. {
  3547. u32 chksum;
  3548. ushort mcode_word_size;
  3549. ushort mcode_chksum;
  3550. /* Write the microcode buffer starting at LRAM address 0. */
  3551. mcode_word_size = (ushort)(mcode_size >> 1);
  3552. AscMemWordSetLram(iop_base, s_addr, 0, mcode_word_size);
  3553. AscMemWordCopyPtrToLram(iop_base, s_addr, mcode_buf, mcode_word_size);
  3554. chksum = AscMemSumLramWord(iop_base, s_addr, mcode_word_size);
  3555. ASC_DBG(1, "chksum 0x%lx\n", (ulong)chksum);
  3556. mcode_chksum = (ushort)AscMemSumLramWord(iop_base,
  3557. (ushort)ASC_CODE_SEC_BEG,
  3558. (ushort)((mcode_size -
  3559. s_addr - (ushort)
  3560. ASC_CODE_SEC_BEG) /
  3561. 2));
  3562. ASC_DBG(1, "mcode_chksum 0x%lx\n", (ulong)mcode_chksum);
  3563. AscWriteLramWord(iop_base, ASCV_MCODE_CHKSUM_W, mcode_chksum);
  3564. AscWriteLramWord(iop_base, ASCV_MCODE_SIZE_W, mcode_size);
  3565. return chksum;
  3566. }
  3567. static void AscInitQLinkVar(ASC_DVC_VAR *asc_dvc)
  3568. {
  3569. PortAddr iop_base;
  3570. int i;
  3571. ushort lram_addr;
  3572. iop_base = asc_dvc->iop_base;
  3573. AscPutRiscVarFreeQHead(iop_base, 1);
  3574. AscPutRiscVarDoneQTail(iop_base, asc_dvc->max_total_qng);
  3575. AscPutVarFreeQHead(iop_base, 1);
  3576. AscPutVarDoneQTail(iop_base, asc_dvc->max_total_qng);
  3577. AscWriteLramByte(iop_base, ASCV_BUSY_QHEAD_B,
  3578. (uchar)((int)asc_dvc->max_total_qng + 1));
  3579. AscWriteLramByte(iop_base, ASCV_DISC1_QHEAD_B,
  3580. (uchar)((int)asc_dvc->max_total_qng + 2));
  3581. AscWriteLramByte(iop_base, (ushort)ASCV_TOTAL_READY_Q_B,
  3582. asc_dvc->max_total_qng);
  3583. AscWriteLramWord(iop_base, ASCV_ASCDVC_ERR_CODE_W, 0);
  3584. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  3585. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, 0);
  3586. AscWriteLramByte(iop_base, ASCV_SCSIBUSY_B, 0);
  3587. AscWriteLramByte(iop_base, ASCV_WTM_FLAG_B, 0);
  3588. AscPutQDoneInProgress(iop_base, 0);
  3589. lram_addr = ASC_QADR_BEG;
  3590. for (i = 0; i < 32; i++, lram_addr += 2) {
  3591. AscWriteLramWord(iop_base, lram_addr, 0);
  3592. }
  3593. }
  3594. static int AscInitMicroCodeVar(ASC_DVC_VAR *asc_dvc)
  3595. {
  3596. int i;
  3597. int warn_code;
  3598. PortAddr iop_base;
  3599. __le32 phy_addr;
  3600. __le32 phy_size;
  3601. struct asc_board *board = asc_dvc_to_board(asc_dvc);
  3602. iop_base = asc_dvc->iop_base;
  3603. warn_code = 0;
  3604. for (i = 0; i <= ASC_MAX_TID; i++) {
  3605. AscPutMCodeInitSDTRAtID(iop_base, i,
  3606. asc_dvc->cfg->sdtr_period_offset[i]);
  3607. }
  3608. AscInitQLinkVar(asc_dvc);
  3609. AscWriteLramByte(iop_base, ASCV_DISC_ENABLE_B,
  3610. asc_dvc->cfg->disc_enable);
  3611. AscWriteLramByte(iop_base, ASCV_HOSTSCSI_ID_B,
  3612. ASC_TID_TO_TARGET_ID(asc_dvc->cfg->chip_scsi_id));
  3613. /* Ensure overrun buffer is aligned on an 8 byte boundary. */
  3614. BUG_ON((unsigned long)asc_dvc->overrun_buf & 7);
  3615. asc_dvc->overrun_dma = dma_map_single(board->dev, asc_dvc->overrun_buf,
  3616. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  3617. if (dma_mapping_error(board->dev, asc_dvc->overrun_dma)) {
  3618. warn_code = -ENOMEM;
  3619. goto err_dma_map;
  3620. }
  3621. phy_addr = cpu_to_le32(asc_dvc->overrun_dma);
  3622. AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_PADDR_D,
  3623. (uchar *)&phy_addr, 1);
  3624. phy_size = cpu_to_le32(ASC_OVERRUN_BSIZE);
  3625. AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_BSIZE_D,
  3626. (uchar *)&phy_size, 1);
  3627. asc_dvc->cfg->mcode_date =
  3628. AscReadLramWord(iop_base, (ushort)ASCV_MC_DATE_W);
  3629. asc_dvc->cfg->mcode_version =
  3630. AscReadLramWord(iop_base, (ushort)ASCV_MC_VER_W);
  3631. AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
  3632. if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
  3633. asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
  3634. warn_code = -EINVAL;
  3635. goto err_mcode_start;
  3636. }
  3637. if (AscStartChip(iop_base) != 1) {
  3638. asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
  3639. warn_code = -EIO;
  3640. goto err_mcode_start;
  3641. }
  3642. return warn_code;
  3643. err_mcode_start:
  3644. dma_unmap_single(board->dev, asc_dvc->overrun_dma,
  3645. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  3646. err_dma_map:
  3647. asc_dvc->overrun_dma = 0;
  3648. return warn_code;
  3649. }
  3650. static int AscInitAsc1000Driver(ASC_DVC_VAR *asc_dvc)
  3651. {
  3652. const struct firmware *fw;
  3653. const char fwname[] = "/*(DEBLOBBED)*/";
  3654. int err;
  3655. unsigned long chksum;
  3656. int warn_code;
  3657. PortAddr iop_base;
  3658. iop_base = asc_dvc->iop_base;
  3659. warn_code = 0;
  3660. if ((asc_dvc->dvc_cntl & ASC_CNTL_RESET_SCSI) &&
  3661. !(asc_dvc->init_state & ASC_INIT_RESET_SCSI_DONE)) {
  3662. AscResetChipAndScsiBus(asc_dvc);
  3663. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  3664. }
  3665. asc_dvc->init_state |= ASC_INIT_STATE_BEG_LOAD_MC;
  3666. if (asc_dvc->err_code != 0)
  3667. return ASC_ERROR;
  3668. if (!AscFindSignature(asc_dvc->iop_base)) {
  3669. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  3670. return warn_code;
  3671. }
  3672. AscDisableInterrupt(iop_base);
  3673. AscInitLram(asc_dvc);
  3674. err = reject_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  3675. if (err) {
  3676. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  3677. fwname, err);
  3678. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  3679. return err;
  3680. }
  3681. if (fw->size < 4) {
  3682. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  3683. fw->size, fwname);
  3684. release_firmware(fw);
  3685. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  3686. return -EINVAL;
  3687. }
  3688. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  3689. (fw->data[1] << 8) | fw->data[0];
  3690. ASC_DBG(1, "_asc_mcode_chksum 0x%lx\n", (ulong)chksum);
  3691. if (AscLoadMicroCode(iop_base, 0, &fw->data[4],
  3692. fw->size - 4) != chksum) {
  3693. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  3694. release_firmware(fw);
  3695. return warn_code;
  3696. }
  3697. release_firmware(fw);
  3698. warn_code |= AscInitMicroCodeVar(asc_dvc);
  3699. if (!asc_dvc->overrun_dma)
  3700. return warn_code;
  3701. asc_dvc->init_state |= ASC_INIT_STATE_END_LOAD_MC;
  3702. AscEnableInterrupt(iop_base);
  3703. return warn_code;
  3704. }
  3705. /*
  3706. * Load the Microcode
  3707. *
  3708. * Write the microcode image to RISC memory starting at address 0.
  3709. *
  3710. * The microcode is stored compressed in the following format:
  3711. *
  3712. * 254 word (508 byte) table indexed by byte code followed
  3713. * by the following byte codes:
  3714. *
  3715. * 1-Byte Code:
  3716. * 00: Emit word 0 in table.
  3717. * 01: Emit word 1 in table.
  3718. * .
  3719. * FD: Emit word 253 in table.
  3720. *
  3721. * Multi-Byte Code:
  3722. * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
  3723. * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
  3724. *
  3725. * Returns 0 or an error if the checksum doesn't match
  3726. */
  3727. static int AdvLoadMicrocode(AdvPortAddr iop_base, const unsigned char *buf,
  3728. int size, int memsize, int chksum)
  3729. {
  3730. int i, j, end, len = 0;
  3731. u32 sum;
  3732. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
  3733. for (i = 253 * 2; i < size; i++) {
  3734. if (buf[i] == 0xff) {
  3735. unsigned short word = (buf[i + 3] << 8) | buf[i + 2];
  3736. for (j = 0; j < buf[i + 1]; j++) {
  3737. AdvWriteWordAutoIncLram(iop_base, word);
  3738. len += 2;
  3739. }
  3740. i += 3;
  3741. } else if (buf[i] == 0xfe) {
  3742. unsigned short word = (buf[i + 2] << 8) | buf[i + 1];
  3743. AdvWriteWordAutoIncLram(iop_base, word);
  3744. i += 2;
  3745. len += 2;
  3746. } else {
  3747. unsigned int off = buf[i] * 2;
  3748. unsigned short word = (buf[off + 1] << 8) | buf[off];
  3749. AdvWriteWordAutoIncLram(iop_base, word);
  3750. len += 2;
  3751. }
  3752. }
  3753. end = len;
  3754. while (len < memsize) {
  3755. AdvWriteWordAutoIncLram(iop_base, 0);
  3756. len += 2;
  3757. }
  3758. /* Verify the microcode checksum. */
  3759. sum = 0;
  3760. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
  3761. for (len = 0; len < end; len += 2) {
  3762. sum += AdvReadWordAutoIncLram(iop_base);
  3763. }
  3764. if (sum != chksum)
  3765. return ASC_IERR_MCODE_CHKSUM;
  3766. return 0;
  3767. }
  3768. static void AdvBuildCarrierFreelist(struct adv_dvc_var *adv_dvc)
  3769. {
  3770. off_t carr_offset = 0, next_offset;
  3771. dma_addr_t carr_paddr;
  3772. int carr_num = ADV_CARRIER_BUFSIZE / sizeof(ADV_CARR_T), i;
  3773. for (i = 0; i < carr_num; i++) {
  3774. carr_offset = i * sizeof(ADV_CARR_T);
  3775. /* Get physical address of the carrier 'carrp'. */
  3776. carr_paddr = adv_dvc->carrier_addr + carr_offset;
  3777. adv_dvc->carrier[i].carr_pa = cpu_to_le32(carr_paddr);
  3778. adv_dvc->carrier[i].carr_va = cpu_to_le32(carr_offset);
  3779. adv_dvc->carrier[i].areq_vpa = 0;
  3780. next_offset = carr_offset + sizeof(ADV_CARR_T);
  3781. if (i == carr_num)
  3782. next_offset = ~0;
  3783. adv_dvc->carrier[i].next_vpa = cpu_to_le32(next_offset);
  3784. }
  3785. /*
  3786. * We cannot have a carrier with 'carr_va' of '0', as
  3787. * a reference to this carrier would be interpreted as
  3788. * list termination.
  3789. * So start at carrier 1 with the freelist.
  3790. */
  3791. adv_dvc->carr_freelist = &adv_dvc->carrier[1];
  3792. }
  3793. static ADV_CARR_T *adv_get_carrier(struct adv_dvc_var *adv_dvc, u32 offset)
  3794. {
  3795. int index;
  3796. BUG_ON(offset > ADV_CARRIER_BUFSIZE);
  3797. index = offset / sizeof(ADV_CARR_T);
  3798. return &adv_dvc->carrier[index];
  3799. }
  3800. static ADV_CARR_T *adv_get_next_carrier(struct adv_dvc_var *adv_dvc)
  3801. {
  3802. ADV_CARR_T *carrp = adv_dvc->carr_freelist;
  3803. u32 next_vpa = le32_to_cpu(carrp->next_vpa);
  3804. if (next_vpa == 0 || next_vpa == ~0) {
  3805. ASC_DBG(1, "invalid vpa offset 0x%x\n", next_vpa);
  3806. return NULL;
  3807. }
  3808. adv_dvc->carr_freelist = adv_get_carrier(adv_dvc, next_vpa);
  3809. /*
  3810. * insert stopper carrier to terminate list
  3811. */
  3812. carrp->next_vpa = cpu_to_le32(ADV_CQ_STOPPER);
  3813. return carrp;
  3814. }
  3815. /*
  3816. * 'offset' is the index in the request pointer array
  3817. */
  3818. static adv_req_t * adv_get_reqp(struct adv_dvc_var *adv_dvc, u32 offset)
  3819. {
  3820. struct asc_board *boardp = adv_dvc->drv_ptr;
  3821. BUG_ON(offset > adv_dvc->max_host_qng);
  3822. return &boardp->adv_reqp[offset];
  3823. }
  3824. /*
  3825. * Send an idle command to the chip and wait for completion.
  3826. *
  3827. * Command completion is polled for once per microsecond.
  3828. *
  3829. * The function can be called from anywhere including an interrupt handler.
  3830. * But the function is not re-entrant, so it uses the DvcEnter/LeaveCritical()
  3831. * functions to prevent reentrancy.
  3832. *
  3833. * Return Values:
  3834. * ADV_TRUE - command completed successfully
  3835. * ADV_FALSE - command failed
  3836. * ADV_ERROR - command timed out
  3837. */
  3838. static int
  3839. AdvSendIdleCmd(ADV_DVC_VAR *asc_dvc,
  3840. ushort idle_cmd, u32 idle_cmd_parameter)
  3841. {
  3842. int result, i, j;
  3843. AdvPortAddr iop_base;
  3844. iop_base = asc_dvc->iop_base;
  3845. /*
  3846. * Clear the idle command status which is set by the microcode
  3847. * to a non-zero value to indicate when the command is completed.
  3848. * The non-zero result is one of the IDLE_CMD_STATUS_* values
  3849. */
  3850. AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, (ushort)0);
  3851. /*
  3852. * Write the idle command value after the idle command parameter
  3853. * has been written to avoid a race condition. If the order is not
  3854. * followed, the microcode may process the idle command before the
  3855. * parameters have been written to LRAM.
  3856. */
  3857. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IDLE_CMD_PARAMETER,
  3858. cpu_to_le32(idle_cmd_parameter));
  3859. AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD, idle_cmd);
  3860. /*
  3861. * Tickle the RISC to tell it to process the idle command.
  3862. */
  3863. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_B);
  3864. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  3865. /*
  3866. * Clear the tickle value. In the ASC-3550 the RISC flag
  3867. * command 'clr_tickle_b' does not work unless the host
  3868. * value is cleared.
  3869. */
  3870. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
  3871. }
  3872. /* Wait for up to 100 millisecond for the idle command to timeout. */
  3873. for (i = 0; i < SCSI_WAIT_100_MSEC; i++) {
  3874. /* Poll once each microsecond for command completion. */
  3875. for (j = 0; j < SCSI_US_PER_MSEC; j++) {
  3876. AdvReadWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS,
  3877. result);
  3878. if (result != 0)
  3879. return result;
  3880. udelay(1);
  3881. }
  3882. }
  3883. BUG(); /* The idle command should never timeout. */
  3884. return ADV_ERROR;
  3885. }
  3886. /*
  3887. * Reset SCSI Bus and purge all outstanding requests.
  3888. *
  3889. * Return Value:
  3890. * ADV_TRUE(1) - All requests are purged and SCSI Bus is reset.
  3891. * ADV_FALSE(0) - Microcode command failed.
  3892. * ADV_ERROR(-1) - Microcode command timed-out. Microcode or IC
  3893. * may be hung which requires driver recovery.
  3894. */
  3895. static int AdvResetSB(ADV_DVC_VAR *asc_dvc)
  3896. {
  3897. int status;
  3898. /*
  3899. * Send the SCSI Bus Reset idle start idle command which asserts
  3900. * the SCSI Bus Reset signal.
  3901. */
  3902. status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_START, 0L);
  3903. if (status != ADV_TRUE) {
  3904. return status;
  3905. }
  3906. /*
  3907. * Delay for the specified SCSI Bus Reset hold time.
  3908. *
  3909. * The hold time delay is done on the host because the RISC has no
  3910. * microsecond accurate timer.
  3911. */
  3912. udelay(ASC_SCSI_RESET_HOLD_TIME_US);
  3913. /*
  3914. * Send the SCSI Bus Reset end idle command which de-asserts
  3915. * the SCSI Bus Reset signal and purges any pending requests.
  3916. */
  3917. status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_END, 0L);
  3918. if (status != ADV_TRUE) {
  3919. return status;
  3920. }
  3921. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  3922. return status;
  3923. }
  3924. /*
  3925. * Initialize the ASC-3550.
  3926. *
  3927. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  3928. *
  3929. * For a non-fatal error return a warning code. If there are no warnings
  3930. * then 0 is returned.
  3931. *
  3932. * Needed after initialization for error recovery.
  3933. */
  3934. static int AdvInitAsc3550Driver(ADV_DVC_VAR *asc_dvc)
  3935. {
  3936. const struct firmware *fw;
  3937. const char fwname[] = "/*(DEBLOBBED)*/";
  3938. AdvPortAddr iop_base;
  3939. ushort warn_code;
  3940. int begin_addr;
  3941. int end_addr;
  3942. ushort code_sum;
  3943. int word;
  3944. int i;
  3945. int err;
  3946. unsigned long chksum;
  3947. ushort scsi_cfg1;
  3948. uchar tid;
  3949. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  3950. ushort wdtr_able = 0, sdtr_able, tagqng_able;
  3951. uchar max_cmd[ADV_MAX_TID + 1];
  3952. /* If there is already an error, don't continue. */
  3953. if (asc_dvc->err_code != 0)
  3954. return ADV_ERROR;
  3955. /*
  3956. * The caller must set 'chip_type' to ADV_CHIP_ASC3550.
  3957. */
  3958. if (asc_dvc->chip_type != ADV_CHIP_ASC3550) {
  3959. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  3960. return ADV_ERROR;
  3961. }
  3962. warn_code = 0;
  3963. iop_base = asc_dvc->iop_base;
  3964. /*
  3965. * Save the RISC memory BIOS region before writing the microcode.
  3966. * The BIOS may already be loaded and using its RISC LRAM region
  3967. * so its region must be saved and restored.
  3968. *
  3969. * Note: This code makes the assumption, which is currently true,
  3970. * that a chip reset does not clear RISC LRAM.
  3971. */
  3972. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  3973. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  3974. bios_mem[i]);
  3975. }
  3976. /*
  3977. * Save current per TID negotiated values.
  3978. */
  3979. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] == 0x55AA) {
  3980. ushort bios_version, major, minor;
  3981. bios_version =
  3982. bios_mem[(ASC_MC_BIOS_VERSION - ASC_MC_BIOSMEM) / 2];
  3983. major = (bios_version >> 12) & 0xF;
  3984. minor = (bios_version >> 8) & 0xF;
  3985. if (major < 3 || (major == 3 && minor == 1)) {
  3986. /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */
  3987. AdvReadWordLram(iop_base, 0x120, wdtr_able);
  3988. } else {
  3989. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  3990. }
  3991. }
  3992. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  3993. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  3994. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  3995. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  3996. max_cmd[tid]);
  3997. }
  3998. err = reject_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  3999. if (err) {
  4000. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  4001. fwname, err);
  4002. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4003. return err;
  4004. }
  4005. if (fw->size < 4) {
  4006. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  4007. fw->size, fwname);
  4008. release_firmware(fw);
  4009. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4010. return -EINVAL;
  4011. }
  4012. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  4013. (fw->data[1] << 8) | fw->data[0];
  4014. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  4015. fw->size - 4, ADV_3550_MEMSIZE,
  4016. chksum);
  4017. release_firmware(fw);
  4018. if (asc_dvc->err_code)
  4019. return ADV_ERROR;
  4020. /*
  4021. * Restore the RISC memory BIOS region.
  4022. */
  4023. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4024. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4025. bios_mem[i]);
  4026. }
  4027. /*
  4028. * Calculate and write the microcode code checksum to the microcode
  4029. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  4030. */
  4031. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  4032. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  4033. code_sum = 0;
  4034. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  4035. for (word = begin_addr; word < end_addr; word += 2) {
  4036. code_sum += AdvReadWordAutoIncLram(iop_base);
  4037. }
  4038. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  4039. /*
  4040. * Read and save microcode version and date.
  4041. */
  4042. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  4043. asc_dvc->cfg->mcode_date);
  4044. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  4045. asc_dvc->cfg->mcode_version);
  4046. /*
  4047. * Set the chip type to indicate the ASC3550.
  4048. */
  4049. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC3550);
  4050. /*
  4051. * If the PCI Configuration Command Register "Parity Error Response
  4052. * Control" Bit was clear (0), then set the microcode variable
  4053. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  4054. * to ignore DMA parity errors.
  4055. */
  4056. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  4057. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4058. word |= CONTROL_FLAG_IGNORE_PERR;
  4059. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4060. }
  4061. /*
  4062. * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO
  4063. * threshold of 128 bytes. This register is only accessible to the host.
  4064. */
  4065. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  4066. START_CTL_EMFU | READ_CMD_MRM);
  4067. /*
  4068. * Microcode operating variables for WDTR, SDTR, and command tag
  4069. * queuing will be set in slave_configure() based on what a
  4070. * device reports it is capable of in Inquiry byte 7.
  4071. *
  4072. * If SCSI Bus Resets have been disabled, then directly set
  4073. * SDTR and WDTR from the EEPROM configuration. This will allow
  4074. * the BIOS and warm boot to work without a SCSI bus hang on
  4075. * the Inquiry caused by host and target mismatched DTR values.
  4076. * Without the SCSI Bus Reset, before an Inquiry a device can't
  4077. * be assumed to be in Asynchronous, Narrow mode.
  4078. */
  4079. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  4080. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  4081. asc_dvc->wdtr_able);
  4082. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  4083. asc_dvc->sdtr_able);
  4084. }
  4085. /*
  4086. * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2,
  4087. * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID
  4088. * bitmask. These values determine the maximum SDTR speed negotiated
  4089. * with a device.
  4090. *
  4091. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  4092. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  4093. * without determining here whether the device supports SDTR.
  4094. *
  4095. * 4-bit speed SDTR speed name
  4096. * =========== ===============
  4097. * 0000b (0x0) SDTR disabled
  4098. * 0001b (0x1) 5 Mhz
  4099. * 0010b (0x2) 10 Mhz
  4100. * 0011b (0x3) 20 Mhz (Ultra)
  4101. * 0100b (0x4) 40 Mhz (LVD/Ultra2)
  4102. * 0101b (0x5) 80 Mhz (LVD2/Ultra3)
  4103. * 0110b (0x6) Undefined
  4104. * .
  4105. * 1111b (0xF) Undefined
  4106. */
  4107. word = 0;
  4108. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4109. if (ADV_TID_TO_TIDMASK(tid) & asc_dvc->ultra_able) {
  4110. /* Set Ultra speed for TID 'tid'. */
  4111. word |= (0x3 << (4 * (tid % 4)));
  4112. } else {
  4113. /* Set Fast speed for TID 'tid'. */
  4114. word |= (0x2 << (4 * (tid % 4)));
  4115. }
  4116. if (tid == 3) { /* Check if done with sdtr_speed1. */
  4117. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, word);
  4118. word = 0;
  4119. } else if (tid == 7) { /* Check if done with sdtr_speed2. */
  4120. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, word);
  4121. word = 0;
  4122. } else if (tid == 11) { /* Check if done with sdtr_speed3. */
  4123. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, word);
  4124. word = 0;
  4125. } else if (tid == 15) { /* Check if done with sdtr_speed4. */
  4126. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, word);
  4127. /* End of loop. */
  4128. }
  4129. }
  4130. /*
  4131. * Set microcode operating variable for the disconnect per TID bitmask.
  4132. */
  4133. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  4134. asc_dvc->cfg->disc_enable);
  4135. /*
  4136. * Set SCSI_CFG0 Microcode Default Value.
  4137. *
  4138. * The microcode will set the SCSI_CFG0 register using this value
  4139. * after it is started below.
  4140. */
  4141. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  4142. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  4143. asc_dvc->chip_scsi_id);
  4144. /*
  4145. * Determine SCSI_CFG1 Microcode Default Value.
  4146. *
  4147. * The microcode will set the SCSI_CFG1 register using this value
  4148. * after it is started below.
  4149. */
  4150. /* Read current SCSI_CFG1 Register value. */
  4151. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4152. /*
  4153. * If all three connectors are in use, return an error.
  4154. */
  4155. if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 ||
  4156. (scsi_cfg1 & CABLE_ILLEGAL_B) == 0) {
  4157. asc_dvc->err_code |= ASC_IERR_ILLEGAL_CONNECTION;
  4158. return ADV_ERROR;
  4159. }
  4160. /*
  4161. * If the internal narrow cable is reversed all of the SCSI_CTRL
  4162. * register signals will be set. Check for and return an error if
  4163. * this condition is found.
  4164. */
  4165. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  4166. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  4167. return ADV_ERROR;
  4168. }
  4169. /*
  4170. * If this is a differential board and a single-ended device
  4171. * is attached to one of the connectors, return an error.
  4172. */
  4173. if ((scsi_cfg1 & DIFF_MODE) && (scsi_cfg1 & DIFF_SENSE) == 0) {
  4174. asc_dvc->err_code |= ASC_IERR_SINGLE_END_DEVICE;
  4175. return ADV_ERROR;
  4176. }
  4177. /*
  4178. * If automatic termination control is enabled, then set the
  4179. * termination value based on a table listed in a_condor.h.
  4180. *
  4181. * If manual termination was specified with an EEPROM setting
  4182. * then 'termination' was set-up in AdvInitFrom3550EEPROM() and
  4183. * is ready to be 'ored' into SCSI_CFG1.
  4184. */
  4185. if (asc_dvc->cfg->termination == 0) {
  4186. /*
  4187. * The software always controls termination by setting TERM_CTL_SEL.
  4188. * If TERM_CTL_SEL were set to 0, the hardware would set termination.
  4189. */
  4190. asc_dvc->cfg->termination |= TERM_CTL_SEL;
  4191. switch (scsi_cfg1 & CABLE_DETECT) {
  4192. /* TERM_CTL_H: on, TERM_CTL_L: on */
  4193. case 0x3:
  4194. case 0x7:
  4195. case 0xB:
  4196. case 0xD:
  4197. case 0xE:
  4198. case 0xF:
  4199. asc_dvc->cfg->termination |= (TERM_CTL_H | TERM_CTL_L);
  4200. break;
  4201. /* TERM_CTL_H: on, TERM_CTL_L: off */
  4202. case 0x1:
  4203. case 0x5:
  4204. case 0x9:
  4205. case 0xA:
  4206. case 0xC:
  4207. asc_dvc->cfg->termination |= TERM_CTL_H;
  4208. break;
  4209. /* TERM_CTL_H: off, TERM_CTL_L: off */
  4210. case 0x2:
  4211. case 0x6:
  4212. break;
  4213. }
  4214. }
  4215. /*
  4216. * Clear any set TERM_CTL_H and TERM_CTL_L bits.
  4217. */
  4218. scsi_cfg1 &= ~TERM_CTL;
  4219. /*
  4220. * Invert the TERM_CTL_H and TERM_CTL_L bits and then
  4221. * set 'scsi_cfg1'. The TERM_POL bit does not need to be
  4222. * referenced, because the hardware internally inverts
  4223. * the Termination High and Low bits if TERM_POL is set.
  4224. */
  4225. scsi_cfg1 |= (TERM_CTL_SEL | (~asc_dvc->cfg->termination & TERM_CTL));
  4226. /*
  4227. * Set SCSI_CFG1 Microcode Default Value
  4228. *
  4229. * Set filter value and possibly modified termination control
  4230. * bits in the Microcode SCSI_CFG1 Register Value.
  4231. *
  4232. * The microcode will set the SCSI_CFG1 register using this value
  4233. * after it is started below.
  4234. */
  4235. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1,
  4236. FLTR_DISABLE | scsi_cfg1);
  4237. /*
  4238. * Set MEM_CFG Microcode Default Value
  4239. *
  4240. * The microcode will set the MEM_CFG register using this value
  4241. * after it is started below.
  4242. *
  4243. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  4244. * are defined.
  4245. *
  4246. * ASC-3550 has 8KB internal memory.
  4247. */
  4248. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  4249. BIOS_EN | RAM_SZ_8KB);
  4250. /*
  4251. * Set SEL_MASK Microcode Default Value
  4252. *
  4253. * The microcode will set the SEL_MASK register using this value
  4254. * after it is started below.
  4255. */
  4256. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  4257. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  4258. AdvBuildCarrierFreelist(asc_dvc);
  4259. /*
  4260. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  4261. */
  4262. asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
  4263. if (!asc_dvc->icq_sp) {
  4264. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4265. return ADV_ERROR;
  4266. }
  4267. /*
  4268. * Set RISC ICQ physical address start value.
  4269. */
  4270. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  4271. /*
  4272. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  4273. */
  4274. asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
  4275. if (!asc_dvc->irq_sp) {
  4276. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4277. return ADV_ERROR;
  4278. }
  4279. /*
  4280. * Set RISC IRQ physical address start value.
  4281. */
  4282. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  4283. asc_dvc->carr_pending_cnt = 0;
  4284. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  4285. (ADV_INTR_ENABLE_HOST_INTR |
  4286. ADV_INTR_ENABLE_GLOBAL_INTR));
  4287. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  4288. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  4289. /* finally, finally, gentlemen, start your engine */
  4290. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  4291. /*
  4292. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  4293. * Resets should be performed. The RISC has to be running
  4294. * to issue a SCSI Bus Reset.
  4295. */
  4296. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  4297. /*
  4298. * If the BIOS Signature is present in memory, restore the
  4299. * BIOS Handshake Configuration Table and do not perform
  4300. * a SCSI Bus Reset.
  4301. */
  4302. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  4303. 0x55AA) {
  4304. /*
  4305. * Restore per TID negotiated values.
  4306. */
  4307. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4308. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4309. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  4310. tagqng_able);
  4311. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4312. AdvWriteByteLram(iop_base,
  4313. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4314. max_cmd[tid]);
  4315. }
  4316. } else {
  4317. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  4318. warn_code = ASC_WARN_BUSRESET_ERROR;
  4319. }
  4320. }
  4321. }
  4322. return warn_code;
  4323. }
  4324. /*
  4325. * Initialize the ASC-38C0800.
  4326. *
  4327. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  4328. *
  4329. * For a non-fatal error return a warning code. If there are no warnings
  4330. * then 0 is returned.
  4331. *
  4332. * Needed after initialization for error recovery.
  4333. */
  4334. static int AdvInitAsc38C0800Driver(ADV_DVC_VAR *asc_dvc)
  4335. {
  4336. const struct firmware *fw;
  4337. const char fwname[] = "/*(DEBLOBBED)*/";
  4338. AdvPortAddr iop_base;
  4339. ushort warn_code;
  4340. int begin_addr;
  4341. int end_addr;
  4342. ushort code_sum;
  4343. int word;
  4344. int i;
  4345. int err;
  4346. unsigned long chksum;
  4347. ushort scsi_cfg1;
  4348. uchar byte;
  4349. uchar tid;
  4350. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  4351. ushort wdtr_able, sdtr_able, tagqng_able;
  4352. uchar max_cmd[ADV_MAX_TID + 1];
  4353. /* If there is already an error, don't continue. */
  4354. if (asc_dvc->err_code != 0)
  4355. return ADV_ERROR;
  4356. /*
  4357. * The caller must set 'chip_type' to ADV_CHIP_ASC38C0800.
  4358. */
  4359. if (asc_dvc->chip_type != ADV_CHIP_ASC38C0800) {
  4360. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  4361. return ADV_ERROR;
  4362. }
  4363. warn_code = 0;
  4364. iop_base = asc_dvc->iop_base;
  4365. /*
  4366. * Save the RISC memory BIOS region before writing the microcode.
  4367. * The BIOS may already be loaded and using its RISC LRAM region
  4368. * so its region must be saved and restored.
  4369. *
  4370. * Note: This code makes the assumption, which is currently true,
  4371. * that a chip reset does not clear RISC LRAM.
  4372. */
  4373. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4374. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4375. bios_mem[i]);
  4376. }
  4377. /*
  4378. * Save current per TID negotiated values.
  4379. */
  4380. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4381. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4382. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  4383. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4384. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4385. max_cmd[tid]);
  4386. }
  4387. /*
  4388. * RAM BIST (RAM Built-In Self Test)
  4389. *
  4390. * Address : I/O base + offset 0x38h register (byte).
  4391. * Function: Bit 7-6(RW) : RAM mode
  4392. * Normal Mode : 0x00
  4393. * Pre-test Mode : 0x40
  4394. * RAM Test Mode : 0x80
  4395. * Bit 5 : unused
  4396. * Bit 4(RO) : Done bit
  4397. * Bit 3-0(RO) : Status
  4398. * Host Error : 0x08
  4399. * Int_RAM Error : 0x04
  4400. * RISC Error : 0x02
  4401. * SCSI Error : 0x01
  4402. * No Error : 0x00
  4403. *
  4404. * Note: RAM BIST code should be put right here, before loading the
  4405. * microcode and after saving the RISC memory BIOS region.
  4406. */
  4407. /*
  4408. * LRAM Pre-test
  4409. *
  4410. * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
  4411. * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
  4412. * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
  4413. * to NORMAL_MODE, return an error too.
  4414. */
  4415. for (i = 0; i < 2; i++) {
  4416. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
  4417. mdelay(10); /* Wait for 10ms before reading back. */
  4418. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  4419. if ((byte & RAM_TEST_DONE) == 0
  4420. || (byte & 0x0F) != PRE_TEST_VALUE) {
  4421. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  4422. return ADV_ERROR;
  4423. }
  4424. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  4425. mdelay(10); /* Wait for 10ms before reading back. */
  4426. if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
  4427. != NORMAL_VALUE) {
  4428. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  4429. return ADV_ERROR;
  4430. }
  4431. }
  4432. /*
  4433. * LRAM Test - It takes about 1.5 ms to run through the test.
  4434. *
  4435. * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
  4436. * If Done bit not set or Status not 0, save register byte, set the
  4437. * err_code, and return an error.
  4438. */
  4439. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
  4440. mdelay(10); /* Wait for 10ms before checking status. */
  4441. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  4442. if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
  4443. /* Get here if Done bit not set or Status not 0. */
  4444. asc_dvc->bist_err_code = byte; /* for BIOS display message */
  4445. asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
  4446. return ADV_ERROR;
  4447. }
  4448. /* We need to reset back to normal mode after LRAM test passes. */
  4449. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  4450. err = reject_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  4451. if (err) {
  4452. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  4453. fwname, err);
  4454. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4455. return err;
  4456. }
  4457. if (fw->size < 4) {
  4458. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  4459. fw->size, fwname);
  4460. release_firmware(fw);
  4461. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4462. return -EINVAL;
  4463. }
  4464. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  4465. (fw->data[1] << 8) | fw->data[0];
  4466. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  4467. fw->size - 4, ADV_38C0800_MEMSIZE,
  4468. chksum);
  4469. release_firmware(fw);
  4470. if (asc_dvc->err_code)
  4471. return ADV_ERROR;
  4472. /*
  4473. * Restore the RISC memory BIOS region.
  4474. */
  4475. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4476. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4477. bios_mem[i]);
  4478. }
  4479. /*
  4480. * Calculate and write the microcode code checksum to the microcode
  4481. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  4482. */
  4483. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  4484. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  4485. code_sum = 0;
  4486. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  4487. for (word = begin_addr; word < end_addr; word += 2) {
  4488. code_sum += AdvReadWordAutoIncLram(iop_base);
  4489. }
  4490. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  4491. /*
  4492. * Read microcode version and date.
  4493. */
  4494. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  4495. asc_dvc->cfg->mcode_date);
  4496. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  4497. asc_dvc->cfg->mcode_version);
  4498. /*
  4499. * Set the chip type to indicate the ASC38C0800.
  4500. */
  4501. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C0800);
  4502. /*
  4503. * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
  4504. * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
  4505. * cable detection and then we are able to read C_DET[3:0].
  4506. *
  4507. * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
  4508. * Microcode Default Value' section below.
  4509. */
  4510. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4511. AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
  4512. scsi_cfg1 | DIS_TERM_DRV);
  4513. /*
  4514. * If the PCI Configuration Command Register "Parity Error Response
  4515. * Control" Bit was clear (0), then set the microcode variable
  4516. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  4517. * to ignore DMA parity errors.
  4518. */
  4519. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  4520. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4521. word |= CONTROL_FLAG_IGNORE_PERR;
  4522. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4523. }
  4524. /*
  4525. * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and START_CTL_TH [3:2]
  4526. * bits for the default FIFO threshold.
  4527. *
  4528. * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
  4529. *
  4530. * For DMA Errata #4 set the BC_THRESH_ENB bit.
  4531. */
  4532. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  4533. BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH |
  4534. READ_CMD_MRM);
  4535. /*
  4536. * Microcode operating variables for WDTR, SDTR, and command tag
  4537. * queuing will be set in slave_configure() based on what a
  4538. * device reports it is capable of in Inquiry byte 7.
  4539. *
  4540. * If SCSI Bus Resets have been disabled, then directly set
  4541. * SDTR and WDTR from the EEPROM configuration. This will allow
  4542. * the BIOS and warm boot to work without a SCSI bus hang on
  4543. * the Inquiry caused by host and target mismatched DTR values.
  4544. * Without the SCSI Bus Reset, before an Inquiry a device can't
  4545. * be assumed to be in Asynchronous, Narrow mode.
  4546. */
  4547. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  4548. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  4549. asc_dvc->wdtr_able);
  4550. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  4551. asc_dvc->sdtr_able);
  4552. }
  4553. /*
  4554. * Set microcode operating variables for DISC and SDTR_SPEED1,
  4555. * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
  4556. * configuration values.
  4557. *
  4558. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  4559. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  4560. * without determining here whether the device supports SDTR.
  4561. */
  4562. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  4563. asc_dvc->cfg->disc_enable);
  4564. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
  4565. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
  4566. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
  4567. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
  4568. /*
  4569. * Set SCSI_CFG0 Microcode Default Value.
  4570. *
  4571. * The microcode will set the SCSI_CFG0 register using this value
  4572. * after it is started below.
  4573. */
  4574. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  4575. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  4576. asc_dvc->chip_scsi_id);
  4577. /*
  4578. * Determine SCSI_CFG1 Microcode Default Value.
  4579. *
  4580. * The microcode will set the SCSI_CFG1 register using this value
  4581. * after it is started below.
  4582. */
  4583. /* Read current SCSI_CFG1 Register value. */
  4584. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4585. /*
  4586. * If the internal narrow cable is reversed all of the SCSI_CTRL
  4587. * register signals will be set. Check for and return an error if
  4588. * this condition is found.
  4589. */
  4590. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  4591. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  4592. return ADV_ERROR;
  4593. }
  4594. /*
  4595. * All kind of combinations of devices attached to one of four
  4596. * connectors are acceptable except HVD device attached. For example,
  4597. * LVD device can be attached to SE connector while SE device attached
  4598. * to LVD connector. If LVD device attached to SE connector, it only
  4599. * runs up to Ultra speed.
  4600. *
  4601. * If an HVD device is attached to one of LVD connectors, return an
  4602. * error. However, there is no way to detect HVD device attached to
  4603. * SE connectors.
  4604. */
  4605. if (scsi_cfg1 & HVD) {
  4606. asc_dvc->err_code = ASC_IERR_HVD_DEVICE;
  4607. return ADV_ERROR;
  4608. }
  4609. /*
  4610. * If either SE or LVD automatic termination control is enabled, then
  4611. * set the termination value based on a table listed in a_condor.h.
  4612. *
  4613. * If manual termination was specified with an EEPROM setting then
  4614. * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready
  4615. * to be 'ored' into SCSI_CFG1.
  4616. */
  4617. if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
  4618. /* SE automatic termination control is enabled. */
  4619. switch (scsi_cfg1 & C_DET_SE) {
  4620. /* TERM_SE_HI: on, TERM_SE_LO: on */
  4621. case 0x1:
  4622. case 0x2:
  4623. case 0x3:
  4624. asc_dvc->cfg->termination |= TERM_SE;
  4625. break;
  4626. /* TERM_SE_HI: on, TERM_SE_LO: off */
  4627. case 0x0:
  4628. asc_dvc->cfg->termination |= TERM_SE_HI;
  4629. break;
  4630. }
  4631. }
  4632. if ((asc_dvc->cfg->termination & TERM_LVD) == 0) {
  4633. /* LVD automatic termination control is enabled. */
  4634. switch (scsi_cfg1 & C_DET_LVD) {
  4635. /* TERM_LVD_HI: on, TERM_LVD_LO: on */
  4636. case 0x4:
  4637. case 0x8:
  4638. case 0xC:
  4639. asc_dvc->cfg->termination |= TERM_LVD;
  4640. break;
  4641. /* TERM_LVD_HI: off, TERM_LVD_LO: off */
  4642. case 0x0:
  4643. break;
  4644. }
  4645. }
  4646. /*
  4647. * Clear any set TERM_SE and TERM_LVD bits.
  4648. */
  4649. scsi_cfg1 &= (~TERM_SE & ~TERM_LVD);
  4650. /*
  4651. * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
  4652. */
  4653. scsi_cfg1 |= (~asc_dvc->cfg->termination & 0xF0);
  4654. /*
  4655. * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE
  4656. * bits and set possibly modified termination control bits in the
  4657. * Microcode SCSI_CFG1 Register Value.
  4658. */
  4659. scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL & ~HVD_LVD_SE);
  4660. /*
  4661. * Set SCSI_CFG1 Microcode Default Value
  4662. *
  4663. * Set possibly modified termination control and reset DIS_TERM_DRV
  4664. * bits in the Microcode SCSI_CFG1 Register Value.
  4665. *
  4666. * The microcode will set the SCSI_CFG1 register using this value
  4667. * after it is started below.
  4668. */
  4669. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
  4670. /*
  4671. * Set MEM_CFG Microcode Default Value
  4672. *
  4673. * The microcode will set the MEM_CFG register using this value
  4674. * after it is started below.
  4675. *
  4676. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  4677. * are defined.
  4678. *
  4679. * ASC-38C0800 has 16KB internal memory.
  4680. */
  4681. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  4682. BIOS_EN | RAM_SZ_16KB);
  4683. /*
  4684. * Set SEL_MASK Microcode Default Value
  4685. *
  4686. * The microcode will set the SEL_MASK register using this value
  4687. * after it is started below.
  4688. */
  4689. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  4690. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  4691. AdvBuildCarrierFreelist(asc_dvc);
  4692. /*
  4693. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  4694. */
  4695. asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
  4696. if (!asc_dvc->icq_sp) {
  4697. ASC_DBG(0, "Failed to get ICQ carrier\n");
  4698. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4699. return ADV_ERROR;
  4700. }
  4701. /*
  4702. * Set RISC ICQ physical address start value.
  4703. * carr_pa is LE, must be native before write
  4704. */
  4705. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  4706. /*
  4707. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  4708. */
  4709. asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
  4710. if (!asc_dvc->irq_sp) {
  4711. ASC_DBG(0, "Failed to get IRQ carrier\n");
  4712. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4713. return ADV_ERROR;
  4714. }
  4715. /*
  4716. * Set RISC IRQ physical address start value.
  4717. *
  4718. * carr_pa is LE, must be native before write *
  4719. */
  4720. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  4721. asc_dvc->carr_pending_cnt = 0;
  4722. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  4723. (ADV_INTR_ENABLE_HOST_INTR |
  4724. ADV_INTR_ENABLE_GLOBAL_INTR));
  4725. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  4726. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  4727. /* finally, finally, gentlemen, start your engine */
  4728. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  4729. /*
  4730. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  4731. * Resets should be performed. The RISC has to be running
  4732. * to issue a SCSI Bus Reset.
  4733. */
  4734. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  4735. /*
  4736. * If the BIOS Signature is present in memory, restore the
  4737. * BIOS Handshake Configuration Table and do not perform
  4738. * a SCSI Bus Reset.
  4739. */
  4740. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  4741. 0x55AA) {
  4742. /*
  4743. * Restore per TID negotiated values.
  4744. */
  4745. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4746. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4747. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  4748. tagqng_able);
  4749. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4750. AdvWriteByteLram(iop_base,
  4751. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4752. max_cmd[tid]);
  4753. }
  4754. } else {
  4755. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  4756. warn_code = ASC_WARN_BUSRESET_ERROR;
  4757. }
  4758. }
  4759. }
  4760. return warn_code;
  4761. }
  4762. /*
  4763. * Initialize the ASC-38C1600.
  4764. *
  4765. * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
  4766. *
  4767. * For a non-fatal error return a warning code. If there are no warnings
  4768. * then 0 is returned.
  4769. *
  4770. * Needed after initialization for error recovery.
  4771. */
  4772. static int AdvInitAsc38C1600Driver(ADV_DVC_VAR *asc_dvc)
  4773. {
  4774. const struct firmware *fw;
  4775. const char fwname[] = "/*(DEBLOBBED)*/";
  4776. AdvPortAddr iop_base;
  4777. ushort warn_code;
  4778. int begin_addr;
  4779. int end_addr;
  4780. ushort code_sum;
  4781. long word;
  4782. int i;
  4783. int err;
  4784. unsigned long chksum;
  4785. ushort scsi_cfg1;
  4786. uchar byte;
  4787. uchar tid;
  4788. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  4789. ushort wdtr_able, sdtr_able, ppr_able, tagqng_able;
  4790. uchar max_cmd[ASC_MAX_TID + 1];
  4791. /* If there is already an error, don't continue. */
  4792. if (asc_dvc->err_code != 0) {
  4793. return ADV_ERROR;
  4794. }
  4795. /*
  4796. * The caller must set 'chip_type' to ADV_CHIP_ASC38C1600.
  4797. */
  4798. if (asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
  4799. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  4800. return ADV_ERROR;
  4801. }
  4802. warn_code = 0;
  4803. iop_base = asc_dvc->iop_base;
  4804. /*
  4805. * Save the RISC memory BIOS region before writing the microcode.
  4806. * The BIOS may already be loaded and using its RISC LRAM region
  4807. * so its region must be saved and restored.
  4808. *
  4809. * Note: This code makes the assumption, which is currently true,
  4810. * that a chip reset does not clear RISC LRAM.
  4811. */
  4812. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4813. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4814. bios_mem[i]);
  4815. }
  4816. /*
  4817. * Save current per TID negotiated values.
  4818. */
  4819. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4820. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4821. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  4822. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  4823. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  4824. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4825. max_cmd[tid]);
  4826. }
  4827. /*
  4828. * RAM BIST (Built-In Self Test)
  4829. *
  4830. * Address : I/O base + offset 0x38h register (byte).
  4831. * Function: Bit 7-6(RW) : RAM mode
  4832. * Normal Mode : 0x00
  4833. * Pre-test Mode : 0x40
  4834. * RAM Test Mode : 0x80
  4835. * Bit 5 : unused
  4836. * Bit 4(RO) : Done bit
  4837. * Bit 3-0(RO) : Status
  4838. * Host Error : 0x08
  4839. * Int_RAM Error : 0x04
  4840. * RISC Error : 0x02
  4841. * SCSI Error : 0x01
  4842. * No Error : 0x00
  4843. *
  4844. * Note: RAM BIST code should be put right here, before loading the
  4845. * microcode and after saving the RISC memory BIOS region.
  4846. */
  4847. /*
  4848. * LRAM Pre-test
  4849. *
  4850. * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
  4851. * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
  4852. * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
  4853. * to NORMAL_MODE, return an error too.
  4854. */
  4855. for (i = 0; i < 2; i++) {
  4856. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
  4857. mdelay(10); /* Wait for 10ms before reading back. */
  4858. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  4859. if ((byte & RAM_TEST_DONE) == 0
  4860. || (byte & 0x0F) != PRE_TEST_VALUE) {
  4861. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  4862. return ADV_ERROR;
  4863. }
  4864. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  4865. mdelay(10); /* Wait for 10ms before reading back. */
  4866. if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
  4867. != NORMAL_VALUE) {
  4868. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  4869. return ADV_ERROR;
  4870. }
  4871. }
  4872. /*
  4873. * LRAM Test - It takes about 1.5 ms to run through the test.
  4874. *
  4875. * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
  4876. * If Done bit not set or Status not 0, save register byte, set the
  4877. * err_code, and return an error.
  4878. */
  4879. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
  4880. mdelay(10); /* Wait for 10ms before checking status. */
  4881. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  4882. if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
  4883. /* Get here if Done bit not set or Status not 0. */
  4884. asc_dvc->bist_err_code = byte; /* for BIOS display message */
  4885. asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
  4886. return ADV_ERROR;
  4887. }
  4888. /* We need to reset back to normal mode after LRAM test passes. */
  4889. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  4890. err = reject_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  4891. if (err) {
  4892. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  4893. fwname, err);
  4894. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4895. return err;
  4896. }
  4897. if (fw->size < 4) {
  4898. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  4899. fw->size, fwname);
  4900. release_firmware(fw);
  4901. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4902. return -EINVAL;
  4903. }
  4904. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  4905. (fw->data[1] << 8) | fw->data[0];
  4906. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  4907. fw->size - 4, ADV_38C1600_MEMSIZE,
  4908. chksum);
  4909. release_firmware(fw);
  4910. if (asc_dvc->err_code)
  4911. return ADV_ERROR;
  4912. /*
  4913. * Restore the RISC memory BIOS region.
  4914. */
  4915. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4916. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4917. bios_mem[i]);
  4918. }
  4919. /*
  4920. * Calculate and write the microcode code checksum to the microcode
  4921. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  4922. */
  4923. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  4924. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  4925. code_sum = 0;
  4926. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  4927. for (word = begin_addr; word < end_addr; word += 2) {
  4928. code_sum += AdvReadWordAutoIncLram(iop_base);
  4929. }
  4930. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  4931. /*
  4932. * Read microcode version and date.
  4933. */
  4934. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  4935. asc_dvc->cfg->mcode_date);
  4936. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  4937. asc_dvc->cfg->mcode_version);
  4938. /*
  4939. * Set the chip type to indicate the ASC38C1600.
  4940. */
  4941. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C1600);
  4942. /*
  4943. * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
  4944. * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
  4945. * cable detection and then we are able to read C_DET[3:0].
  4946. *
  4947. * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
  4948. * Microcode Default Value' section below.
  4949. */
  4950. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4951. AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
  4952. scsi_cfg1 | DIS_TERM_DRV);
  4953. /*
  4954. * If the PCI Configuration Command Register "Parity Error Response
  4955. * Control" Bit was clear (0), then set the microcode variable
  4956. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  4957. * to ignore DMA parity errors.
  4958. */
  4959. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  4960. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4961. word |= CONTROL_FLAG_IGNORE_PERR;
  4962. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4963. }
  4964. /*
  4965. * If the BIOS control flag AIPP (Asynchronous Information
  4966. * Phase Protection) disable bit is not set, then set the firmware
  4967. * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable
  4968. * AIPP checking and encoding.
  4969. */
  4970. if ((asc_dvc->bios_ctrl & BIOS_CTRL_AIPP_DIS) == 0) {
  4971. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4972. word |= CONTROL_FLAG_ENABLE_AIPP;
  4973. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4974. }
  4975. /*
  4976. * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4],
  4977. * and START_CTL_TH [3:2].
  4978. */
  4979. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  4980. FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
  4981. /*
  4982. * Microcode operating variables for WDTR, SDTR, and command tag
  4983. * queuing will be set in slave_configure() based on what a
  4984. * device reports it is capable of in Inquiry byte 7.
  4985. *
  4986. * If SCSI Bus Resets have been disabled, then directly set
  4987. * SDTR and WDTR from the EEPROM configuration. This will allow
  4988. * the BIOS and warm boot to work without a SCSI bus hang on
  4989. * the Inquiry caused by host and target mismatched DTR values.
  4990. * Without the SCSI Bus Reset, before an Inquiry a device can't
  4991. * be assumed to be in Asynchronous, Narrow mode.
  4992. */
  4993. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  4994. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  4995. asc_dvc->wdtr_able);
  4996. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  4997. asc_dvc->sdtr_able);
  4998. }
  4999. /*
  5000. * Set microcode operating variables for DISC and SDTR_SPEED1,
  5001. * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
  5002. * configuration values.
  5003. *
  5004. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  5005. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  5006. * without determining here whether the device supports SDTR.
  5007. */
  5008. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  5009. asc_dvc->cfg->disc_enable);
  5010. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
  5011. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
  5012. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
  5013. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
  5014. /*
  5015. * Set SCSI_CFG0 Microcode Default Value.
  5016. *
  5017. * The microcode will set the SCSI_CFG0 register using this value
  5018. * after it is started below.
  5019. */
  5020. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  5021. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  5022. asc_dvc->chip_scsi_id);
  5023. /*
  5024. * Calculate SCSI_CFG1 Microcode Default Value.
  5025. *
  5026. * The microcode will set the SCSI_CFG1 register using this value
  5027. * after it is started below.
  5028. *
  5029. * Each ASC-38C1600 function has only two cable detect bits.
  5030. * The bus mode override bits are in IOPB_SOFT_OVER_WR.
  5031. */
  5032. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  5033. /*
  5034. * If the cable is reversed all of the SCSI_CTRL register signals
  5035. * will be set. Check for and return an error if this condition is
  5036. * found.
  5037. */
  5038. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  5039. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  5040. return ADV_ERROR;
  5041. }
  5042. /*
  5043. * Each ASC-38C1600 function has two connectors. Only an HVD device
  5044. * can not be connected to either connector. An LVD device or SE device
  5045. * may be connected to either connecor. If an SE device is connected,
  5046. * then at most Ultra speed (20 Mhz) can be used on both connectors.
  5047. *
  5048. * If an HVD device is attached, return an error.
  5049. */
  5050. if (scsi_cfg1 & HVD) {
  5051. asc_dvc->err_code |= ASC_IERR_HVD_DEVICE;
  5052. return ADV_ERROR;
  5053. }
  5054. /*
  5055. * Each function in the ASC-38C1600 uses only the SE cable detect and
  5056. * termination because there are two connectors for each function. Each
  5057. * function may use either LVD or SE mode. Corresponding the SE automatic
  5058. * termination control EEPROM bits are used for each function. Each
  5059. * function has its own EEPROM. If SE automatic control is enabled for
  5060. * the function, then set the termination value based on a table listed
  5061. * in a_condor.h.
  5062. *
  5063. * If manual termination is specified in the EEPROM for the function,
  5064. * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is
  5065. * ready to be 'ored' into SCSI_CFG1.
  5066. */
  5067. if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
  5068. struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
  5069. /* SE automatic termination control is enabled. */
  5070. switch (scsi_cfg1 & C_DET_SE) {
  5071. /* TERM_SE_HI: on, TERM_SE_LO: on */
  5072. case 0x1:
  5073. case 0x2:
  5074. case 0x3:
  5075. asc_dvc->cfg->termination |= TERM_SE;
  5076. break;
  5077. case 0x0:
  5078. if (PCI_FUNC(pdev->devfn) == 0) {
  5079. /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */
  5080. } else {
  5081. /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */
  5082. asc_dvc->cfg->termination |= TERM_SE_HI;
  5083. }
  5084. break;
  5085. }
  5086. }
  5087. /*
  5088. * Clear any set TERM_SE bits.
  5089. */
  5090. scsi_cfg1 &= ~TERM_SE;
  5091. /*
  5092. * Invert the TERM_SE bits and then set 'scsi_cfg1'.
  5093. */
  5094. scsi_cfg1 |= (~asc_dvc->cfg->termination & TERM_SE);
  5095. /*
  5096. * Clear Big Endian and Terminator Polarity bits and set possibly
  5097. * modified termination control bits in the Microcode SCSI_CFG1
  5098. * Register Value.
  5099. *
  5100. * Big Endian bit is not used even on big endian machines.
  5101. */
  5102. scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL);
  5103. /*
  5104. * Set SCSI_CFG1 Microcode Default Value
  5105. *
  5106. * Set possibly modified termination control bits in the Microcode
  5107. * SCSI_CFG1 Register Value.
  5108. *
  5109. * The microcode will set the SCSI_CFG1 register using this value
  5110. * after it is started below.
  5111. */
  5112. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
  5113. /*
  5114. * Set MEM_CFG Microcode Default Value
  5115. *
  5116. * The microcode will set the MEM_CFG register using this value
  5117. * after it is started below.
  5118. *
  5119. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  5120. * are defined.
  5121. *
  5122. * ASC-38C1600 has 32KB internal memory.
  5123. *
  5124. * XXX - Since ASC38C1600 Rev.3 has a Local RAM failure issue, we come
  5125. * out a special 16K Adv Library and Microcode version. After the issue
  5126. * resolved, we should turn back to the 32K support. Both a_condor.h and
  5127. * mcode.sas files also need to be updated.
  5128. *
  5129. * AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5130. * BIOS_EN | RAM_SZ_32KB);
  5131. */
  5132. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5133. BIOS_EN | RAM_SZ_16KB);
  5134. /*
  5135. * Set SEL_MASK Microcode Default Value
  5136. *
  5137. * The microcode will set the SEL_MASK register using this value
  5138. * after it is started below.
  5139. */
  5140. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  5141. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  5142. AdvBuildCarrierFreelist(asc_dvc);
  5143. /*
  5144. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  5145. */
  5146. asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc);
  5147. if (!asc_dvc->icq_sp) {
  5148. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5149. return ADV_ERROR;
  5150. }
  5151. /*
  5152. * Set RISC ICQ physical address start value. Initialize the
  5153. * COMMA register to the same value otherwise the RISC will
  5154. * prematurely detect a command is available.
  5155. */
  5156. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  5157. AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
  5158. le32_to_cpu(asc_dvc->icq_sp->carr_pa));
  5159. /*
  5160. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  5161. */
  5162. asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc);
  5163. if (!asc_dvc->irq_sp) {
  5164. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5165. return ADV_ERROR;
  5166. }
  5167. /*
  5168. * Set RISC IRQ physical address start value.
  5169. */
  5170. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  5171. asc_dvc->carr_pending_cnt = 0;
  5172. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  5173. (ADV_INTR_ENABLE_HOST_INTR |
  5174. ADV_INTR_ENABLE_GLOBAL_INTR));
  5175. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  5176. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  5177. /* finally, finally, gentlemen, start your engine */
  5178. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  5179. /*
  5180. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  5181. * Resets should be performed. The RISC has to be running
  5182. * to issue a SCSI Bus Reset.
  5183. */
  5184. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  5185. /*
  5186. * If the BIOS Signature is present in memory, restore the
  5187. * per TID microcode operating variables.
  5188. */
  5189. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  5190. 0x55AA) {
  5191. /*
  5192. * Restore per TID negotiated values.
  5193. */
  5194. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5195. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5196. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5197. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  5198. tagqng_able);
  5199. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  5200. AdvWriteByteLram(iop_base,
  5201. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5202. max_cmd[tid]);
  5203. }
  5204. } else {
  5205. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  5206. warn_code = ASC_WARN_BUSRESET_ERROR;
  5207. }
  5208. }
  5209. }
  5210. return warn_code;
  5211. }
  5212. /*
  5213. * Reset chip and SCSI Bus.
  5214. *
  5215. * Return Value:
  5216. * ADV_TRUE(1) - Chip re-initialization and SCSI Bus Reset successful.
  5217. * ADV_FALSE(0) - Chip re-initialization and SCSI Bus Reset failure.
  5218. */
  5219. static int AdvResetChipAndSB(ADV_DVC_VAR *asc_dvc)
  5220. {
  5221. int status;
  5222. ushort wdtr_able, sdtr_able, tagqng_able;
  5223. ushort ppr_able = 0;
  5224. uchar tid, max_cmd[ADV_MAX_TID + 1];
  5225. AdvPortAddr iop_base;
  5226. ushort bios_sig;
  5227. iop_base = asc_dvc->iop_base;
  5228. /*
  5229. * Save current per TID negotiated values.
  5230. */
  5231. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5232. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5233. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5234. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5235. }
  5236. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5237. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5238. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5239. max_cmd[tid]);
  5240. }
  5241. /*
  5242. * Force the AdvInitAsc3550/38C0800Driver() function to
  5243. * perform a SCSI Bus Reset by clearing the BIOS signature word.
  5244. * The initialization functions assumes a SCSI Bus Reset is not
  5245. * needed if the BIOS signature word is present.
  5246. */
  5247. AdvReadWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
  5248. AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, 0);
  5249. /*
  5250. * Stop chip and reset it.
  5251. */
  5252. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_STOP);
  5253. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_RESET);
  5254. mdelay(100);
  5255. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  5256. ADV_CTRL_REG_CMD_WR_IO_REG);
  5257. /*
  5258. * Reset Adv Library error code, if any, and try
  5259. * re-initializing the chip.
  5260. */
  5261. asc_dvc->err_code = 0;
  5262. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5263. status = AdvInitAsc38C1600Driver(asc_dvc);
  5264. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  5265. status = AdvInitAsc38C0800Driver(asc_dvc);
  5266. } else {
  5267. status = AdvInitAsc3550Driver(asc_dvc);
  5268. }
  5269. /* Translate initialization return value to status value. */
  5270. if (status == 0) {
  5271. status = ADV_TRUE;
  5272. } else {
  5273. status = ADV_FALSE;
  5274. }
  5275. /*
  5276. * Restore the BIOS signature word.
  5277. */
  5278. AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
  5279. /*
  5280. * Restore per TID negotiated values.
  5281. */
  5282. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5283. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5284. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5285. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5286. }
  5287. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5288. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5289. AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5290. max_cmd[tid]);
  5291. }
  5292. return status;
  5293. }
  5294. /*
  5295. * adv_async_callback() - Adv Library asynchronous event callback function.
  5296. */
  5297. static void adv_async_callback(ADV_DVC_VAR *adv_dvc_varp, uchar code)
  5298. {
  5299. switch (code) {
  5300. case ADV_ASYNC_SCSI_BUS_RESET_DET:
  5301. /*
  5302. * The firmware detected a SCSI Bus reset.
  5303. */
  5304. ASC_DBG(0, "ADV_ASYNC_SCSI_BUS_RESET_DET\n");
  5305. break;
  5306. case ADV_ASYNC_RDMA_FAILURE:
  5307. /*
  5308. * Handle RDMA failure by resetting the SCSI Bus and
  5309. * possibly the chip if it is unresponsive. Log the error
  5310. * with a unique code.
  5311. */
  5312. ASC_DBG(0, "ADV_ASYNC_RDMA_FAILURE\n");
  5313. AdvResetChipAndSB(adv_dvc_varp);
  5314. break;
  5315. case ADV_HOST_SCSI_BUS_RESET:
  5316. /*
  5317. * Host generated SCSI bus reset occurred.
  5318. */
  5319. ASC_DBG(0, "ADV_HOST_SCSI_BUS_RESET\n");
  5320. break;
  5321. default:
  5322. ASC_DBG(0, "unknown code 0x%x\n", code);
  5323. break;
  5324. }
  5325. }
  5326. /*
  5327. * adv_isr_callback() - Second Level Interrupt Handler called by AdvISR().
  5328. *
  5329. * Callback function for the Wide SCSI Adv Library.
  5330. */
  5331. static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
  5332. {
  5333. struct asc_board *boardp = adv_dvc_varp->drv_ptr;
  5334. u32 srb_tag;
  5335. adv_req_t *reqp;
  5336. adv_sgblk_t *sgblkp;
  5337. struct scsi_cmnd *scp;
  5338. u32 resid_cnt;
  5339. dma_addr_t sense_addr;
  5340. ASC_DBG(1, "adv_dvc_varp 0x%p, scsiqp 0x%p\n",
  5341. adv_dvc_varp, scsiqp);
  5342. ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
  5343. /*
  5344. * Get the adv_req_t structure for the command that has been
  5345. * completed. The adv_req_t structure actually contains the
  5346. * completed ADV_SCSI_REQ_Q structure.
  5347. */
  5348. srb_tag = le32_to_cpu(scsiqp->srb_tag);
  5349. scp = scsi_host_find_tag(boardp->shost, scsiqp->srb_tag);
  5350. ASC_DBG(1, "scp 0x%p\n", scp);
  5351. if (scp == NULL) {
  5352. ASC_PRINT
  5353. ("adv_isr_callback: scp is NULL; adv_req_t dropped.\n");
  5354. return;
  5355. }
  5356. ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
  5357. reqp = (adv_req_t *)scp->host_scribble;
  5358. ASC_DBG(1, "reqp 0x%lx\n", (ulong)reqp);
  5359. if (reqp == NULL) {
  5360. ASC_PRINT("adv_isr_callback: reqp is NULL\n");
  5361. return;
  5362. }
  5363. /*
  5364. * Remove backreferences to avoid duplicate
  5365. * command completions.
  5366. */
  5367. scp->host_scribble = NULL;
  5368. reqp->cmndp = NULL;
  5369. ASC_STATS(boardp->shost, callback);
  5370. ASC_DBG(1, "shost 0x%p\n", boardp->shost);
  5371. sense_addr = le32_to_cpu(scsiqp->sense_addr);
  5372. dma_unmap_single(boardp->dev, sense_addr,
  5373. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  5374. /*
  5375. * 'done_status' contains the command's ending status.
  5376. */
  5377. switch (scsiqp->done_status) {
  5378. case QD_NO_ERROR:
  5379. ASC_DBG(2, "QD_NO_ERROR\n");
  5380. scp->result = 0;
  5381. /*
  5382. * Check for an underrun condition.
  5383. *
  5384. * If there was no error and an underrun condition, then
  5385. * then return the number of underrun bytes.
  5386. */
  5387. resid_cnt = le32_to_cpu(scsiqp->data_cnt);
  5388. if (scsi_bufflen(scp) != 0 && resid_cnt != 0 &&
  5389. resid_cnt <= scsi_bufflen(scp)) {
  5390. ASC_DBG(1, "underrun condition %lu bytes\n",
  5391. (ulong)resid_cnt);
  5392. scsi_set_resid(scp, resid_cnt);
  5393. }
  5394. break;
  5395. case QD_WITH_ERROR:
  5396. ASC_DBG(2, "QD_WITH_ERROR\n");
  5397. switch (scsiqp->host_status) {
  5398. case QHSTA_NO_ERROR:
  5399. if (scsiqp->scsi_status == SAM_STAT_CHECK_CONDITION) {
  5400. ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
  5401. ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
  5402. SCSI_SENSE_BUFFERSIZE);
  5403. /*
  5404. * Note: The 'status_byte()' macro used by
  5405. * target drivers defined in scsi.h shifts the
  5406. * status byte returned by host drivers right
  5407. * by 1 bit. This is why target drivers also
  5408. * use right shifted status byte definitions.
  5409. * For instance target drivers use
  5410. * CHECK_CONDITION, defined to 0x1, instead of
  5411. * the SCSI defined check condition value of
  5412. * 0x2. Host drivers are supposed to return
  5413. * the status byte as it is defined by SCSI.
  5414. */
  5415. scp->result = DRIVER_BYTE(DRIVER_SENSE) |
  5416. STATUS_BYTE(scsiqp->scsi_status);
  5417. } else {
  5418. scp->result = STATUS_BYTE(scsiqp->scsi_status);
  5419. }
  5420. break;
  5421. default:
  5422. /* Some other QHSTA error occurred. */
  5423. ASC_DBG(1, "host_status 0x%x\n", scsiqp->host_status);
  5424. scp->result = HOST_BYTE(DID_BAD_TARGET);
  5425. break;
  5426. }
  5427. break;
  5428. case QD_ABORTED_BY_HOST:
  5429. ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
  5430. scp->result =
  5431. HOST_BYTE(DID_ABORT) | STATUS_BYTE(scsiqp->scsi_status);
  5432. break;
  5433. default:
  5434. ASC_DBG(1, "done_status 0x%x\n", scsiqp->done_status);
  5435. scp->result =
  5436. HOST_BYTE(DID_ERROR) | STATUS_BYTE(scsiqp->scsi_status);
  5437. break;
  5438. }
  5439. /*
  5440. * If the 'init_tidmask' bit isn't already set for the target and the
  5441. * current request finished normally, then set the bit for the target
  5442. * to indicate that a device is present.
  5443. */
  5444. if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
  5445. scsiqp->done_status == QD_NO_ERROR &&
  5446. scsiqp->host_status == QHSTA_NO_ERROR) {
  5447. boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
  5448. }
  5449. asc_scsi_done(scp);
  5450. /*
  5451. * Free all 'adv_sgblk_t' structures allocated for the request.
  5452. */
  5453. while ((sgblkp = reqp->sgblkp) != NULL) {
  5454. /* Remove 'sgblkp' from the request list. */
  5455. reqp->sgblkp = sgblkp->next_sgblkp;
  5456. dma_pool_free(boardp->adv_sgblk_pool, sgblkp,
  5457. sgblkp->sg_addr);
  5458. }
  5459. ASC_DBG(1, "done\n");
  5460. }
  5461. /*
  5462. * Adv Library Interrupt Service Routine
  5463. *
  5464. * This function is called by a driver's interrupt service routine.
  5465. * The function disables and re-enables interrupts.
  5466. *
  5467. * When a microcode idle command is completed, the ADV_DVC_VAR
  5468. * 'idle_cmd_done' field is set to ADV_TRUE.
  5469. *
  5470. * Note: AdvISR() can be called when interrupts are disabled or even
  5471. * when there is no hardware interrupt condition present. It will
  5472. * always check for completed idle commands and microcode requests.
  5473. * This is an important feature that shouldn't be changed because it
  5474. * allows commands to be completed from polling mode loops.
  5475. *
  5476. * Return:
  5477. * ADV_TRUE(1) - interrupt was pending
  5478. * ADV_FALSE(0) - no interrupt was pending
  5479. */
  5480. static int AdvISR(ADV_DVC_VAR *asc_dvc)
  5481. {
  5482. AdvPortAddr iop_base;
  5483. uchar int_stat;
  5484. ushort target_bit;
  5485. ADV_CARR_T *free_carrp;
  5486. __le32 irq_next_vpa;
  5487. ADV_SCSI_REQ_Q *scsiq;
  5488. adv_req_t *reqp;
  5489. iop_base = asc_dvc->iop_base;
  5490. /* Reading the register clears the interrupt. */
  5491. int_stat = AdvReadByteRegister(iop_base, IOPB_INTR_STATUS_REG);
  5492. if ((int_stat & (ADV_INTR_STATUS_INTRA | ADV_INTR_STATUS_INTRB |
  5493. ADV_INTR_STATUS_INTRC)) == 0) {
  5494. return ADV_FALSE;
  5495. }
  5496. /*
  5497. * Notify the driver of an asynchronous microcode condition by
  5498. * calling the adv_async_callback function. The function
  5499. * is passed the microcode ASC_MC_INTRB_CODE byte value.
  5500. */
  5501. if (int_stat & ADV_INTR_STATUS_INTRB) {
  5502. uchar intrb_code;
  5503. AdvReadByteLram(iop_base, ASC_MC_INTRB_CODE, intrb_code);
  5504. if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
  5505. asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  5506. if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE &&
  5507. asc_dvc->carr_pending_cnt != 0) {
  5508. AdvWriteByteRegister(iop_base, IOPB_TICKLE,
  5509. ADV_TICKLE_A);
  5510. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  5511. AdvWriteByteRegister(iop_base,
  5512. IOPB_TICKLE,
  5513. ADV_TICKLE_NOP);
  5514. }
  5515. }
  5516. }
  5517. adv_async_callback(asc_dvc, intrb_code);
  5518. }
  5519. /*
  5520. * Check if the IRQ stopper carrier contains a completed request.
  5521. */
  5522. while (((irq_next_vpa =
  5523. le32_to_cpu(asc_dvc->irq_sp->next_vpa)) & ADV_RQ_DONE) != 0) {
  5524. /*
  5525. * Get a pointer to the newly completed ADV_SCSI_REQ_Q structure.
  5526. * The RISC will have set 'areq_vpa' to a virtual address.
  5527. *
  5528. * The firmware will have copied the ADV_SCSI_REQ_Q.scsiq_ptr
  5529. * field to the carrier ADV_CARR_T.areq_vpa field. The conversion
  5530. * below complements the conversion of ADV_SCSI_REQ_Q.scsiq_ptr'
  5531. * in AdvExeScsiQueue().
  5532. */
  5533. u32 pa_offset = le32_to_cpu(asc_dvc->irq_sp->areq_vpa);
  5534. ASC_DBG(1, "irq_sp %p areq_vpa %u\n",
  5535. asc_dvc->irq_sp, pa_offset);
  5536. reqp = adv_get_reqp(asc_dvc, pa_offset);
  5537. scsiq = &reqp->scsi_req_q;
  5538. /*
  5539. * Request finished with good status and the queue was not
  5540. * DMAed to host memory by the firmware. Set all status fields
  5541. * to indicate good status.
  5542. */
  5543. if ((irq_next_vpa & ADV_RQ_GOOD) != 0) {
  5544. scsiq->done_status = QD_NO_ERROR;
  5545. scsiq->host_status = scsiq->scsi_status = 0;
  5546. scsiq->data_cnt = 0L;
  5547. }
  5548. /*
  5549. * Advance the stopper pointer to the next carrier
  5550. * ignoring the lower four bits. Free the previous
  5551. * stopper carrier.
  5552. */
  5553. free_carrp = asc_dvc->irq_sp;
  5554. asc_dvc->irq_sp = adv_get_carrier(asc_dvc,
  5555. ADV_GET_CARRP(irq_next_vpa));
  5556. free_carrp->next_vpa = asc_dvc->carr_freelist->carr_va;
  5557. asc_dvc->carr_freelist = free_carrp;
  5558. asc_dvc->carr_pending_cnt--;
  5559. target_bit = ADV_TID_TO_TIDMASK(scsiq->target_id);
  5560. /*
  5561. * Clear request microcode control flag.
  5562. */
  5563. scsiq->cntl = 0;
  5564. /*
  5565. * Notify the driver of the completed request by passing
  5566. * the ADV_SCSI_REQ_Q pointer to its callback function.
  5567. */
  5568. adv_isr_callback(asc_dvc, scsiq);
  5569. /*
  5570. * Note: After the driver callback function is called, 'scsiq'
  5571. * can no longer be referenced.
  5572. *
  5573. * Fall through and continue processing other completed
  5574. * requests...
  5575. */
  5576. }
  5577. return ADV_TRUE;
  5578. }
  5579. static int AscSetLibErrorCode(ASC_DVC_VAR *asc_dvc, ushort err_code)
  5580. {
  5581. if (asc_dvc->err_code == 0) {
  5582. asc_dvc->err_code = err_code;
  5583. AscWriteLramWord(asc_dvc->iop_base, ASCV_ASCDVC_ERR_CODE_W,
  5584. err_code);
  5585. }
  5586. return err_code;
  5587. }
  5588. static void AscAckInterrupt(PortAddr iop_base)
  5589. {
  5590. uchar host_flag;
  5591. uchar risc_flag;
  5592. ushort loop;
  5593. loop = 0;
  5594. do {
  5595. risc_flag = AscReadLramByte(iop_base, ASCV_RISC_FLAG_B);
  5596. if (loop++ > 0x7FFF) {
  5597. break;
  5598. }
  5599. } while ((risc_flag & ASC_RISC_FLAG_GEN_INT) != 0);
  5600. host_flag =
  5601. AscReadLramByte(iop_base,
  5602. ASCV_HOST_FLAG_B) & (~ASC_HOST_FLAG_ACK_INT);
  5603. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
  5604. (uchar)(host_flag | ASC_HOST_FLAG_ACK_INT));
  5605. AscSetChipStatus(iop_base, CIW_INT_ACK);
  5606. loop = 0;
  5607. while (AscGetChipStatus(iop_base) & CSW_INT_PENDING) {
  5608. AscSetChipStatus(iop_base, CIW_INT_ACK);
  5609. if (loop++ > 3) {
  5610. break;
  5611. }
  5612. }
  5613. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
  5614. }
  5615. static uchar AscGetSynPeriodIndex(ASC_DVC_VAR *asc_dvc, uchar syn_time)
  5616. {
  5617. const uchar *period_table;
  5618. int max_index;
  5619. int min_index;
  5620. int i;
  5621. period_table = asc_dvc->sdtr_period_tbl;
  5622. max_index = (int)asc_dvc->max_sdtr_index;
  5623. min_index = (int)asc_dvc->min_sdtr_index;
  5624. if ((syn_time <= period_table[max_index])) {
  5625. for (i = min_index; i < (max_index - 1); i++) {
  5626. if (syn_time <= period_table[i]) {
  5627. return (uchar)i;
  5628. }
  5629. }
  5630. return (uchar)max_index;
  5631. } else {
  5632. return (uchar)(max_index + 1);
  5633. }
  5634. }
  5635. static uchar
  5636. AscMsgOutSDTR(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar sdtr_offset)
  5637. {
  5638. EXT_MSG sdtr_buf;
  5639. uchar sdtr_period_index;
  5640. PortAddr iop_base;
  5641. iop_base = asc_dvc->iop_base;
  5642. sdtr_buf.msg_type = EXTENDED_MESSAGE;
  5643. sdtr_buf.msg_len = MS_SDTR_LEN;
  5644. sdtr_buf.msg_req = EXTENDED_SDTR;
  5645. sdtr_buf.xfer_period = sdtr_period;
  5646. sdtr_offset &= ASC_SYN_MAX_OFFSET;
  5647. sdtr_buf.req_ack_offset = sdtr_offset;
  5648. sdtr_period_index = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
  5649. if (sdtr_period_index <= asc_dvc->max_sdtr_index) {
  5650. AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
  5651. (uchar *)&sdtr_buf,
  5652. sizeof(EXT_MSG) >> 1);
  5653. return ((sdtr_period_index << 4) | sdtr_offset);
  5654. } else {
  5655. sdtr_buf.req_ack_offset = 0;
  5656. AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
  5657. (uchar *)&sdtr_buf,
  5658. sizeof(EXT_MSG) >> 1);
  5659. return 0;
  5660. }
  5661. }
  5662. static uchar
  5663. AscCalSDTRData(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar syn_offset)
  5664. {
  5665. uchar byte;
  5666. uchar sdtr_period_ix;
  5667. sdtr_period_ix = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
  5668. if (sdtr_period_ix > asc_dvc->max_sdtr_index)
  5669. return 0xFF;
  5670. byte = (sdtr_period_ix << 4) | (syn_offset & ASC_SYN_MAX_OFFSET);
  5671. return byte;
  5672. }
  5673. static bool AscSetChipSynRegAtID(PortAddr iop_base, uchar id, uchar sdtr_data)
  5674. {
  5675. ASC_SCSI_BIT_ID_TYPE org_id;
  5676. int i;
  5677. bool sta = true;
  5678. AscSetBank(iop_base, 1);
  5679. org_id = AscReadChipDvcID(iop_base);
  5680. for (i = 0; i <= ASC_MAX_TID; i++) {
  5681. if (org_id == (0x01 << i))
  5682. break;
  5683. }
  5684. org_id = (ASC_SCSI_BIT_ID_TYPE) i;
  5685. AscWriteChipDvcID(iop_base, id);
  5686. if (AscReadChipDvcID(iop_base) == (0x01 << id)) {
  5687. AscSetBank(iop_base, 0);
  5688. AscSetChipSyn(iop_base, sdtr_data);
  5689. if (AscGetChipSyn(iop_base) != sdtr_data) {
  5690. sta = false;
  5691. }
  5692. } else {
  5693. sta = false;
  5694. }
  5695. AscSetBank(iop_base, 1);
  5696. AscWriteChipDvcID(iop_base, org_id);
  5697. AscSetBank(iop_base, 0);
  5698. return (sta);
  5699. }
  5700. static void AscSetChipSDTR(PortAddr iop_base, uchar sdtr_data, uchar tid_no)
  5701. {
  5702. AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
  5703. AscPutMCodeSDTRDoneAtID(iop_base, tid_no, sdtr_data);
  5704. }
  5705. static void AscIsrChipHalted(ASC_DVC_VAR *asc_dvc)
  5706. {
  5707. EXT_MSG ext_msg;
  5708. EXT_MSG out_msg;
  5709. ushort halt_q_addr;
  5710. bool sdtr_accept;
  5711. ushort int_halt_code;
  5712. ASC_SCSI_BIT_ID_TYPE scsi_busy;
  5713. ASC_SCSI_BIT_ID_TYPE target_id;
  5714. PortAddr iop_base;
  5715. uchar tag_code;
  5716. uchar q_status;
  5717. uchar halt_qp;
  5718. uchar sdtr_data;
  5719. uchar target_ix;
  5720. uchar q_cntl, tid_no;
  5721. uchar cur_dvc_qng;
  5722. uchar asyn_sdtr;
  5723. uchar scsi_status;
  5724. struct asc_board *boardp;
  5725. BUG_ON(!asc_dvc->drv_ptr);
  5726. boardp = asc_dvc->drv_ptr;
  5727. iop_base = asc_dvc->iop_base;
  5728. int_halt_code = AscReadLramWord(iop_base, ASCV_HALTCODE_W);
  5729. halt_qp = AscReadLramByte(iop_base, ASCV_CURCDB_B);
  5730. halt_q_addr = ASC_QNO_TO_QADDR(halt_qp);
  5731. target_ix = AscReadLramByte(iop_base,
  5732. (ushort)(halt_q_addr +
  5733. (ushort)ASC_SCSIQ_B_TARGET_IX));
  5734. q_cntl = AscReadLramByte(iop_base,
  5735. (ushort)(halt_q_addr + (ushort)ASC_SCSIQ_B_CNTL));
  5736. tid_no = ASC_TIX_TO_TID(target_ix);
  5737. target_id = (uchar)ASC_TID_TO_TARGET_ID(tid_no);
  5738. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  5739. asyn_sdtr = ASYN_SDTR_DATA_FIX_PCI_REV_AB;
  5740. } else {
  5741. asyn_sdtr = 0;
  5742. }
  5743. if (int_halt_code == ASC_HALT_DISABLE_ASYN_USE_SYN_FIX) {
  5744. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  5745. AscSetChipSDTR(iop_base, 0, tid_no);
  5746. boardp->sdtr_data[tid_no] = 0;
  5747. }
  5748. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5749. return;
  5750. } else if (int_halt_code == ASC_HALT_ENABLE_ASYN_USE_SYN_FIX) {
  5751. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  5752. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  5753. boardp->sdtr_data[tid_no] = asyn_sdtr;
  5754. }
  5755. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5756. return;
  5757. } else if (int_halt_code == ASC_HALT_EXTMSG_IN) {
  5758. AscMemWordCopyPtrFromLram(iop_base,
  5759. ASCV_MSGIN_BEG,
  5760. (uchar *)&ext_msg,
  5761. sizeof(EXT_MSG) >> 1);
  5762. if (ext_msg.msg_type == EXTENDED_MESSAGE &&
  5763. ext_msg.msg_req == EXTENDED_SDTR &&
  5764. ext_msg.msg_len == MS_SDTR_LEN) {
  5765. sdtr_accept = true;
  5766. if ((ext_msg.req_ack_offset > ASC_SYN_MAX_OFFSET)) {
  5767. sdtr_accept = false;
  5768. ext_msg.req_ack_offset = ASC_SYN_MAX_OFFSET;
  5769. }
  5770. if ((ext_msg.xfer_period <
  5771. asc_dvc->sdtr_period_tbl[asc_dvc->min_sdtr_index])
  5772. || (ext_msg.xfer_period >
  5773. asc_dvc->sdtr_period_tbl[asc_dvc->
  5774. max_sdtr_index])) {
  5775. sdtr_accept = false;
  5776. ext_msg.xfer_period =
  5777. asc_dvc->sdtr_period_tbl[asc_dvc->
  5778. min_sdtr_index];
  5779. }
  5780. if (sdtr_accept) {
  5781. sdtr_data =
  5782. AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
  5783. ext_msg.req_ack_offset);
  5784. if ((sdtr_data == 0xFF)) {
  5785. q_cntl |= QC_MSG_OUT;
  5786. asc_dvc->init_sdtr &= ~target_id;
  5787. asc_dvc->sdtr_done &= ~target_id;
  5788. AscSetChipSDTR(iop_base, asyn_sdtr,
  5789. tid_no);
  5790. boardp->sdtr_data[tid_no] = asyn_sdtr;
  5791. }
  5792. }
  5793. if (ext_msg.req_ack_offset == 0) {
  5794. q_cntl &= ~QC_MSG_OUT;
  5795. asc_dvc->init_sdtr &= ~target_id;
  5796. asc_dvc->sdtr_done &= ~target_id;
  5797. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  5798. } else {
  5799. if (sdtr_accept && (q_cntl & QC_MSG_OUT)) {
  5800. q_cntl &= ~QC_MSG_OUT;
  5801. asc_dvc->sdtr_done |= target_id;
  5802. asc_dvc->init_sdtr |= target_id;
  5803. asc_dvc->pci_fix_asyn_xfer &=
  5804. ~target_id;
  5805. sdtr_data =
  5806. AscCalSDTRData(asc_dvc,
  5807. ext_msg.xfer_period,
  5808. ext_msg.
  5809. req_ack_offset);
  5810. AscSetChipSDTR(iop_base, sdtr_data,
  5811. tid_no);
  5812. boardp->sdtr_data[tid_no] = sdtr_data;
  5813. } else {
  5814. q_cntl |= QC_MSG_OUT;
  5815. AscMsgOutSDTR(asc_dvc,
  5816. ext_msg.xfer_period,
  5817. ext_msg.req_ack_offset);
  5818. asc_dvc->pci_fix_asyn_xfer &=
  5819. ~target_id;
  5820. sdtr_data =
  5821. AscCalSDTRData(asc_dvc,
  5822. ext_msg.xfer_period,
  5823. ext_msg.
  5824. req_ack_offset);
  5825. AscSetChipSDTR(iop_base, sdtr_data,
  5826. tid_no);
  5827. boardp->sdtr_data[tid_no] = sdtr_data;
  5828. asc_dvc->sdtr_done |= target_id;
  5829. asc_dvc->init_sdtr |= target_id;
  5830. }
  5831. }
  5832. AscWriteLramByte(iop_base,
  5833. (ushort)(halt_q_addr +
  5834. (ushort)ASC_SCSIQ_B_CNTL),
  5835. q_cntl);
  5836. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5837. return;
  5838. } else if (ext_msg.msg_type == EXTENDED_MESSAGE &&
  5839. ext_msg.msg_req == EXTENDED_WDTR &&
  5840. ext_msg.msg_len == MS_WDTR_LEN) {
  5841. ext_msg.wdtr_width = 0;
  5842. AscMemWordCopyPtrToLram(iop_base,
  5843. ASCV_MSGOUT_BEG,
  5844. (uchar *)&ext_msg,
  5845. sizeof(EXT_MSG) >> 1);
  5846. q_cntl |= QC_MSG_OUT;
  5847. AscWriteLramByte(iop_base,
  5848. (ushort)(halt_q_addr +
  5849. (ushort)ASC_SCSIQ_B_CNTL),
  5850. q_cntl);
  5851. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5852. return;
  5853. } else {
  5854. ext_msg.msg_type = MESSAGE_REJECT;
  5855. AscMemWordCopyPtrToLram(iop_base,
  5856. ASCV_MSGOUT_BEG,
  5857. (uchar *)&ext_msg,
  5858. sizeof(EXT_MSG) >> 1);
  5859. q_cntl |= QC_MSG_OUT;
  5860. AscWriteLramByte(iop_base,
  5861. (ushort)(halt_q_addr +
  5862. (ushort)ASC_SCSIQ_B_CNTL),
  5863. q_cntl);
  5864. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5865. return;
  5866. }
  5867. } else if (int_halt_code == ASC_HALT_CHK_CONDITION) {
  5868. q_cntl |= QC_REQ_SENSE;
  5869. if ((asc_dvc->init_sdtr & target_id) != 0) {
  5870. asc_dvc->sdtr_done &= ~target_id;
  5871. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  5872. q_cntl |= QC_MSG_OUT;
  5873. AscMsgOutSDTR(asc_dvc,
  5874. asc_dvc->
  5875. sdtr_period_tbl[(sdtr_data >> 4) &
  5876. (uchar)(asc_dvc->
  5877. max_sdtr_index -
  5878. 1)],
  5879. (uchar)(sdtr_data & (uchar)
  5880. ASC_SYN_MAX_OFFSET));
  5881. }
  5882. AscWriteLramByte(iop_base,
  5883. (ushort)(halt_q_addr +
  5884. (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
  5885. tag_code = AscReadLramByte(iop_base,
  5886. (ushort)(halt_q_addr + (ushort)
  5887. ASC_SCSIQ_B_TAG_CODE));
  5888. tag_code &= 0xDC;
  5889. if ((asc_dvc->pci_fix_asyn_xfer & target_id)
  5890. && !(asc_dvc->pci_fix_asyn_xfer_always & target_id)
  5891. ) {
  5892. tag_code |= (ASC_TAG_FLAG_DISABLE_DISCONNECT
  5893. | ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX);
  5894. }
  5895. AscWriteLramByte(iop_base,
  5896. (ushort)(halt_q_addr +
  5897. (ushort)ASC_SCSIQ_B_TAG_CODE),
  5898. tag_code);
  5899. q_status = AscReadLramByte(iop_base,
  5900. (ushort)(halt_q_addr + (ushort)
  5901. ASC_SCSIQ_B_STATUS));
  5902. q_status |= (QS_READY | QS_BUSY);
  5903. AscWriteLramByte(iop_base,
  5904. (ushort)(halt_q_addr +
  5905. (ushort)ASC_SCSIQ_B_STATUS),
  5906. q_status);
  5907. scsi_busy = AscReadLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B);
  5908. scsi_busy &= ~target_id;
  5909. AscWriteLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B, scsi_busy);
  5910. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5911. return;
  5912. } else if (int_halt_code == ASC_HALT_SDTR_REJECTED) {
  5913. AscMemWordCopyPtrFromLram(iop_base,
  5914. ASCV_MSGOUT_BEG,
  5915. (uchar *)&out_msg,
  5916. sizeof(EXT_MSG) >> 1);
  5917. if ((out_msg.msg_type == EXTENDED_MESSAGE) &&
  5918. (out_msg.msg_len == MS_SDTR_LEN) &&
  5919. (out_msg.msg_req == EXTENDED_SDTR)) {
  5920. asc_dvc->init_sdtr &= ~target_id;
  5921. asc_dvc->sdtr_done &= ~target_id;
  5922. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  5923. boardp->sdtr_data[tid_no] = asyn_sdtr;
  5924. }
  5925. q_cntl &= ~QC_MSG_OUT;
  5926. AscWriteLramByte(iop_base,
  5927. (ushort)(halt_q_addr +
  5928. (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
  5929. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5930. return;
  5931. } else if (int_halt_code == ASC_HALT_SS_QUEUE_FULL) {
  5932. scsi_status = AscReadLramByte(iop_base,
  5933. (ushort)((ushort)halt_q_addr +
  5934. (ushort)
  5935. ASC_SCSIQ_SCSI_STATUS));
  5936. cur_dvc_qng =
  5937. AscReadLramByte(iop_base,
  5938. (ushort)((ushort)ASC_QADR_BEG +
  5939. (ushort)target_ix));
  5940. if ((cur_dvc_qng > 0) && (asc_dvc->cur_dvc_qng[tid_no] > 0)) {
  5941. scsi_busy = AscReadLramByte(iop_base,
  5942. (ushort)ASCV_SCSIBUSY_B);
  5943. scsi_busy |= target_id;
  5944. AscWriteLramByte(iop_base,
  5945. (ushort)ASCV_SCSIBUSY_B, scsi_busy);
  5946. asc_dvc->queue_full_or_busy |= target_id;
  5947. if (scsi_status == SAM_STAT_TASK_SET_FULL) {
  5948. if (cur_dvc_qng > ASC_MIN_TAGGED_CMD) {
  5949. cur_dvc_qng -= 1;
  5950. asc_dvc->max_dvc_qng[tid_no] =
  5951. cur_dvc_qng;
  5952. AscWriteLramByte(iop_base,
  5953. (ushort)((ushort)
  5954. ASCV_MAX_DVC_QNG_BEG
  5955. + (ushort)
  5956. tid_no),
  5957. cur_dvc_qng);
  5958. /*
  5959. * Set the device queue depth to the
  5960. * number of active requests when the
  5961. * QUEUE FULL condition was encountered.
  5962. */
  5963. boardp->queue_full |= target_id;
  5964. boardp->queue_full_cnt[tid_no] =
  5965. cur_dvc_qng;
  5966. }
  5967. }
  5968. }
  5969. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5970. return;
  5971. }
  5972. return;
  5973. }
  5974. /*
  5975. * void
  5976. * DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
  5977. *
  5978. * Calling/Exit State:
  5979. * none
  5980. *
  5981. * Description:
  5982. * Input an ASC_QDONE_INFO structure from the chip
  5983. */
  5984. static void
  5985. DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
  5986. {
  5987. int i;
  5988. ushort word;
  5989. AscSetChipLramAddr(iop_base, s_addr);
  5990. for (i = 0; i < 2 * words; i += 2) {
  5991. if (i == 10) {
  5992. continue;
  5993. }
  5994. word = inpw(iop_base + IOP_RAM_DATA);
  5995. inbuf[i] = word & 0xff;
  5996. inbuf[i + 1] = (word >> 8) & 0xff;
  5997. }
  5998. ASC_DBG_PRT_HEX(2, "DvcGetQinfo", inbuf, 2 * words);
  5999. }
  6000. static uchar
  6001. _AscCopyLramScsiDoneQ(PortAddr iop_base,
  6002. ushort q_addr,
  6003. ASC_QDONE_INFO *scsiq, unsigned int max_dma_count)
  6004. {
  6005. ushort _val;
  6006. uchar sg_queue_cnt;
  6007. DvcGetQinfo(iop_base,
  6008. q_addr + ASC_SCSIQ_DONE_INFO_BEG,
  6009. (uchar *)scsiq,
  6010. (sizeof(ASC_SCSIQ_2) + sizeof(ASC_SCSIQ_3)) / 2);
  6011. _val = AscReadLramWord(iop_base,
  6012. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS));
  6013. scsiq->q_status = (uchar)_val;
  6014. scsiq->q_no = (uchar)(_val >> 8);
  6015. _val = AscReadLramWord(iop_base,
  6016. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_CNTL));
  6017. scsiq->cntl = (uchar)_val;
  6018. sg_queue_cnt = (uchar)(_val >> 8);
  6019. _val = AscReadLramWord(iop_base,
  6020. (ushort)(q_addr +
  6021. (ushort)ASC_SCSIQ_B_SENSE_LEN));
  6022. scsiq->sense_len = (uchar)_val;
  6023. scsiq->extra_bytes = (uchar)(_val >> 8);
  6024. /*
  6025. * Read high word of remain bytes from alternate location.
  6026. */
  6027. scsiq->remain_bytes = (((u32)AscReadLramWord(iop_base,
  6028. (ushort)(q_addr +
  6029. (ushort)
  6030. ASC_SCSIQ_W_ALT_DC1)))
  6031. << 16);
  6032. /*
  6033. * Read low word of remain bytes from original location.
  6034. */
  6035. scsiq->remain_bytes += AscReadLramWord(iop_base,
  6036. (ushort)(q_addr + (ushort)
  6037. ASC_SCSIQ_DW_REMAIN_XFER_CNT));
  6038. scsiq->remain_bytes &= max_dma_count;
  6039. return sg_queue_cnt;
  6040. }
  6041. /*
  6042. * asc_isr_callback() - Second Level Interrupt Handler called by AscISR().
  6043. *
  6044. * Interrupt callback function for the Narrow SCSI Asc Library.
  6045. */
  6046. static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
  6047. {
  6048. struct asc_board *boardp = asc_dvc_varp->drv_ptr;
  6049. u32 srb_tag;
  6050. struct scsi_cmnd *scp;
  6051. ASC_DBG(1, "asc_dvc_varp 0x%p, qdonep 0x%p\n", asc_dvc_varp, qdonep);
  6052. ASC_DBG_PRT_ASC_QDONE_INFO(2, qdonep);
  6053. /*
  6054. * Decrease the srb_tag by 1 to find the SCSI command
  6055. */
  6056. srb_tag = qdonep->d2.srb_tag - 1;
  6057. scp = scsi_host_find_tag(boardp->shost, srb_tag);
  6058. if (!scp)
  6059. return;
  6060. ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
  6061. ASC_STATS(boardp->shost, callback);
  6062. dma_unmap_single(boardp->dev, scp->SCp.dma_handle,
  6063. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  6064. /*
  6065. * 'qdonep' contains the command's ending status.
  6066. */
  6067. switch (qdonep->d3.done_stat) {
  6068. case QD_NO_ERROR:
  6069. ASC_DBG(2, "QD_NO_ERROR\n");
  6070. scp->result = 0;
  6071. /*
  6072. * Check for an underrun condition.
  6073. *
  6074. * If there was no error and an underrun condition, then
  6075. * return the number of underrun bytes.
  6076. */
  6077. if (scsi_bufflen(scp) != 0 && qdonep->remain_bytes != 0 &&
  6078. qdonep->remain_bytes <= scsi_bufflen(scp)) {
  6079. ASC_DBG(1, "underrun condition %u bytes\n",
  6080. (unsigned)qdonep->remain_bytes);
  6081. scsi_set_resid(scp, qdonep->remain_bytes);
  6082. }
  6083. break;
  6084. case QD_WITH_ERROR:
  6085. ASC_DBG(2, "QD_WITH_ERROR\n");
  6086. switch (qdonep->d3.host_stat) {
  6087. case QHSTA_NO_ERROR:
  6088. if (qdonep->d3.scsi_stat == SAM_STAT_CHECK_CONDITION) {
  6089. ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
  6090. ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
  6091. SCSI_SENSE_BUFFERSIZE);
  6092. /*
  6093. * Note: The 'status_byte()' macro used by
  6094. * target drivers defined in scsi.h shifts the
  6095. * status byte returned by host drivers right
  6096. * by 1 bit. This is why target drivers also
  6097. * use right shifted status byte definitions.
  6098. * For instance target drivers use
  6099. * CHECK_CONDITION, defined to 0x1, instead of
  6100. * the SCSI defined check condition value of
  6101. * 0x2. Host drivers are supposed to return
  6102. * the status byte as it is defined by SCSI.
  6103. */
  6104. scp->result = DRIVER_BYTE(DRIVER_SENSE) |
  6105. STATUS_BYTE(qdonep->d3.scsi_stat);
  6106. } else {
  6107. scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
  6108. }
  6109. break;
  6110. default:
  6111. /* QHSTA error occurred */
  6112. ASC_DBG(1, "host_stat 0x%x\n", qdonep->d3.host_stat);
  6113. scp->result = HOST_BYTE(DID_BAD_TARGET);
  6114. break;
  6115. }
  6116. break;
  6117. case QD_ABORTED_BY_HOST:
  6118. ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
  6119. scp->result =
  6120. HOST_BYTE(DID_ABORT) | MSG_BYTE(qdonep->d3.
  6121. scsi_msg) |
  6122. STATUS_BYTE(qdonep->d3.scsi_stat);
  6123. break;
  6124. default:
  6125. ASC_DBG(1, "done_stat 0x%x\n", qdonep->d3.done_stat);
  6126. scp->result =
  6127. HOST_BYTE(DID_ERROR) | MSG_BYTE(qdonep->d3.
  6128. scsi_msg) |
  6129. STATUS_BYTE(qdonep->d3.scsi_stat);
  6130. break;
  6131. }
  6132. /*
  6133. * If the 'init_tidmask' bit isn't already set for the target and the
  6134. * current request finished normally, then set the bit for the target
  6135. * to indicate that a device is present.
  6136. */
  6137. if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
  6138. qdonep->d3.done_stat == QD_NO_ERROR &&
  6139. qdonep->d3.host_stat == QHSTA_NO_ERROR) {
  6140. boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
  6141. }
  6142. asc_scsi_done(scp);
  6143. }
  6144. static int AscIsrQDone(ASC_DVC_VAR *asc_dvc)
  6145. {
  6146. uchar next_qp;
  6147. uchar n_q_used;
  6148. uchar sg_list_qp;
  6149. uchar sg_queue_cnt;
  6150. uchar q_cnt;
  6151. uchar done_q_tail;
  6152. uchar tid_no;
  6153. ASC_SCSI_BIT_ID_TYPE scsi_busy;
  6154. ASC_SCSI_BIT_ID_TYPE target_id;
  6155. PortAddr iop_base;
  6156. ushort q_addr;
  6157. ushort sg_q_addr;
  6158. uchar cur_target_qng;
  6159. ASC_QDONE_INFO scsiq_buf;
  6160. ASC_QDONE_INFO *scsiq;
  6161. bool false_overrun;
  6162. iop_base = asc_dvc->iop_base;
  6163. n_q_used = 1;
  6164. scsiq = (ASC_QDONE_INFO *)&scsiq_buf;
  6165. done_q_tail = (uchar)AscGetVarDoneQTail(iop_base);
  6166. q_addr = ASC_QNO_TO_QADDR(done_q_tail);
  6167. next_qp = AscReadLramByte(iop_base,
  6168. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_FWD));
  6169. if (next_qp != ASC_QLINK_END) {
  6170. AscPutVarDoneQTail(iop_base, next_qp);
  6171. q_addr = ASC_QNO_TO_QADDR(next_qp);
  6172. sg_queue_cnt = _AscCopyLramScsiDoneQ(iop_base, q_addr, scsiq,
  6173. asc_dvc->max_dma_count);
  6174. AscWriteLramByte(iop_base,
  6175. (ushort)(q_addr +
  6176. (ushort)ASC_SCSIQ_B_STATUS),
  6177. (uchar)(scsiq->
  6178. q_status & (uchar)~(QS_READY |
  6179. QS_ABORTED)));
  6180. tid_no = ASC_TIX_TO_TID(scsiq->d2.target_ix);
  6181. target_id = ASC_TIX_TO_TARGET_ID(scsiq->d2.target_ix);
  6182. if ((scsiq->cntl & QC_SG_HEAD) != 0) {
  6183. sg_q_addr = q_addr;
  6184. sg_list_qp = next_qp;
  6185. for (q_cnt = 0; q_cnt < sg_queue_cnt; q_cnt++) {
  6186. sg_list_qp = AscReadLramByte(iop_base,
  6187. (ushort)(sg_q_addr
  6188. + (ushort)
  6189. ASC_SCSIQ_B_FWD));
  6190. sg_q_addr = ASC_QNO_TO_QADDR(sg_list_qp);
  6191. if (sg_list_qp == ASC_QLINK_END) {
  6192. AscSetLibErrorCode(asc_dvc,
  6193. ASCQ_ERR_SG_Q_LINKS);
  6194. scsiq->d3.done_stat = QD_WITH_ERROR;
  6195. scsiq->d3.host_stat =
  6196. QHSTA_D_QDONE_SG_LIST_CORRUPTED;
  6197. goto FATAL_ERR_QDONE;
  6198. }
  6199. AscWriteLramByte(iop_base,
  6200. (ushort)(sg_q_addr + (ushort)
  6201. ASC_SCSIQ_B_STATUS),
  6202. QS_FREE);
  6203. }
  6204. n_q_used = sg_queue_cnt + 1;
  6205. AscPutVarDoneQTail(iop_base, sg_list_qp);
  6206. }
  6207. if (asc_dvc->queue_full_or_busy & target_id) {
  6208. cur_target_qng = AscReadLramByte(iop_base,
  6209. (ushort)((ushort)
  6210. ASC_QADR_BEG
  6211. + (ushort)
  6212. scsiq->d2.
  6213. target_ix));
  6214. if (cur_target_qng < asc_dvc->max_dvc_qng[tid_no]) {
  6215. scsi_busy = AscReadLramByte(iop_base, (ushort)
  6216. ASCV_SCSIBUSY_B);
  6217. scsi_busy &= ~target_id;
  6218. AscWriteLramByte(iop_base,
  6219. (ushort)ASCV_SCSIBUSY_B,
  6220. scsi_busy);
  6221. asc_dvc->queue_full_or_busy &= ~target_id;
  6222. }
  6223. }
  6224. if (asc_dvc->cur_total_qng >= n_q_used) {
  6225. asc_dvc->cur_total_qng -= n_q_used;
  6226. if (asc_dvc->cur_dvc_qng[tid_no] != 0) {
  6227. asc_dvc->cur_dvc_qng[tid_no]--;
  6228. }
  6229. } else {
  6230. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CUR_QNG);
  6231. scsiq->d3.done_stat = QD_WITH_ERROR;
  6232. goto FATAL_ERR_QDONE;
  6233. }
  6234. if ((scsiq->d2.srb_tag == 0UL) ||
  6235. ((scsiq->q_status & QS_ABORTED) != 0)) {
  6236. return (0x11);
  6237. } else if (scsiq->q_status == QS_DONE) {
  6238. /*
  6239. * This is also curious.
  6240. * false_overrun will _always_ be set to 'false'
  6241. */
  6242. false_overrun = false;
  6243. if (scsiq->extra_bytes != 0) {
  6244. scsiq->remain_bytes += scsiq->extra_bytes;
  6245. }
  6246. if (scsiq->d3.done_stat == QD_WITH_ERROR) {
  6247. if (scsiq->d3.host_stat ==
  6248. QHSTA_M_DATA_OVER_RUN) {
  6249. if ((scsiq->
  6250. cntl & (QC_DATA_IN | QC_DATA_OUT))
  6251. == 0) {
  6252. scsiq->d3.done_stat =
  6253. QD_NO_ERROR;
  6254. scsiq->d3.host_stat =
  6255. QHSTA_NO_ERROR;
  6256. } else if (false_overrun) {
  6257. scsiq->d3.done_stat =
  6258. QD_NO_ERROR;
  6259. scsiq->d3.host_stat =
  6260. QHSTA_NO_ERROR;
  6261. }
  6262. } else if (scsiq->d3.host_stat ==
  6263. QHSTA_M_HUNG_REQ_SCSI_BUS_RESET) {
  6264. AscStopChip(iop_base);
  6265. AscSetChipControl(iop_base,
  6266. (uchar)(CC_SCSI_RESET
  6267. | CC_HALT));
  6268. udelay(60);
  6269. AscSetChipControl(iop_base, CC_HALT);
  6270. AscSetChipStatus(iop_base,
  6271. CIW_CLR_SCSI_RESET_INT);
  6272. AscSetChipStatus(iop_base, 0);
  6273. AscSetChipControl(iop_base, 0);
  6274. }
  6275. }
  6276. if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
  6277. asc_isr_callback(asc_dvc, scsiq);
  6278. } else {
  6279. if ((AscReadLramByte(iop_base,
  6280. (ushort)(q_addr + (ushort)
  6281. ASC_SCSIQ_CDB_BEG))
  6282. == START_STOP)) {
  6283. asc_dvc->unit_not_ready &= ~target_id;
  6284. if (scsiq->d3.done_stat != QD_NO_ERROR) {
  6285. asc_dvc->start_motor &=
  6286. ~target_id;
  6287. }
  6288. }
  6289. }
  6290. return (1);
  6291. } else {
  6292. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_Q_STATUS);
  6293. FATAL_ERR_QDONE:
  6294. if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
  6295. asc_isr_callback(asc_dvc, scsiq);
  6296. }
  6297. return (0x80);
  6298. }
  6299. }
  6300. return (0);
  6301. }
  6302. static int AscISR(ASC_DVC_VAR *asc_dvc)
  6303. {
  6304. ASC_CS_TYPE chipstat;
  6305. PortAddr iop_base;
  6306. ushort saved_ram_addr;
  6307. uchar ctrl_reg;
  6308. uchar saved_ctrl_reg;
  6309. int int_pending;
  6310. int status;
  6311. uchar host_flag;
  6312. iop_base = asc_dvc->iop_base;
  6313. int_pending = ASC_FALSE;
  6314. if (AscIsIntPending(iop_base) == 0)
  6315. return int_pending;
  6316. if ((asc_dvc->init_state & ASC_INIT_STATE_END_LOAD_MC) == 0) {
  6317. return ASC_ERROR;
  6318. }
  6319. if (asc_dvc->in_critical_cnt != 0) {
  6320. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_ON_CRITICAL);
  6321. return ASC_ERROR;
  6322. }
  6323. if (asc_dvc->is_in_int) {
  6324. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_RE_ENTRY);
  6325. return ASC_ERROR;
  6326. }
  6327. asc_dvc->is_in_int = true;
  6328. ctrl_reg = AscGetChipControl(iop_base);
  6329. saved_ctrl_reg = ctrl_reg & (~(CC_SCSI_RESET | CC_CHIP_RESET |
  6330. CC_SINGLE_STEP | CC_DIAG | CC_TEST));
  6331. chipstat = AscGetChipStatus(iop_base);
  6332. if (chipstat & CSW_SCSI_RESET_LATCH) {
  6333. if (!(asc_dvc->bus_type & (ASC_IS_VL | ASC_IS_EISA))) {
  6334. int i = 10;
  6335. int_pending = ASC_TRUE;
  6336. asc_dvc->sdtr_done = 0;
  6337. saved_ctrl_reg &= (uchar)(~CC_HALT);
  6338. while ((AscGetChipStatus(iop_base) &
  6339. CSW_SCSI_RESET_ACTIVE) && (i-- > 0)) {
  6340. mdelay(100);
  6341. }
  6342. AscSetChipControl(iop_base, (CC_CHIP_RESET | CC_HALT));
  6343. AscSetChipControl(iop_base, CC_HALT);
  6344. AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
  6345. AscSetChipStatus(iop_base, 0);
  6346. chipstat = AscGetChipStatus(iop_base);
  6347. }
  6348. }
  6349. saved_ram_addr = AscGetChipLramAddr(iop_base);
  6350. host_flag = AscReadLramByte(iop_base,
  6351. ASCV_HOST_FLAG_B) &
  6352. (uchar)(~ASC_HOST_FLAG_IN_ISR);
  6353. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
  6354. (uchar)(host_flag | (uchar)ASC_HOST_FLAG_IN_ISR));
  6355. if ((chipstat & CSW_INT_PENDING) || (int_pending)) {
  6356. AscAckInterrupt(iop_base);
  6357. int_pending = ASC_TRUE;
  6358. if ((chipstat & CSW_HALTED) && (ctrl_reg & CC_SINGLE_STEP)) {
  6359. AscIsrChipHalted(asc_dvc);
  6360. saved_ctrl_reg &= (uchar)(~CC_HALT);
  6361. } else {
  6362. if ((asc_dvc->dvc_cntl & ASC_CNTL_INT_MULTI_Q) != 0) {
  6363. while (((status =
  6364. AscIsrQDone(asc_dvc)) & 0x01) != 0) {
  6365. }
  6366. } else {
  6367. do {
  6368. if ((status =
  6369. AscIsrQDone(asc_dvc)) == 1) {
  6370. break;
  6371. }
  6372. } while (status == 0x11);
  6373. }
  6374. if ((status & 0x80) != 0)
  6375. int_pending = ASC_ERROR;
  6376. }
  6377. }
  6378. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
  6379. AscSetChipLramAddr(iop_base, saved_ram_addr);
  6380. AscSetChipControl(iop_base, saved_ctrl_reg);
  6381. asc_dvc->is_in_int = false;
  6382. return int_pending;
  6383. }
  6384. /*
  6385. * advansys_reset()
  6386. *
  6387. * Reset the host associated with the command 'scp'.
  6388. *
  6389. * This function runs its own thread. Interrupts must be blocked but
  6390. * sleeping is allowed and no locking other than for host structures is
  6391. * required. Returns SUCCESS or FAILED.
  6392. */
  6393. static int advansys_reset(struct scsi_cmnd *scp)
  6394. {
  6395. struct Scsi_Host *shost = scp->device->host;
  6396. struct asc_board *boardp = shost_priv(shost);
  6397. unsigned long flags;
  6398. int status;
  6399. int ret = SUCCESS;
  6400. ASC_DBG(1, "0x%p\n", scp);
  6401. ASC_STATS(shost, reset);
  6402. scmd_printk(KERN_INFO, scp, "SCSI host reset started...\n");
  6403. if (ASC_NARROW_BOARD(boardp)) {
  6404. ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  6405. /* Reset the chip and SCSI bus. */
  6406. ASC_DBG(1, "before AscInitAsc1000Driver()\n");
  6407. status = AscInitAsc1000Driver(asc_dvc);
  6408. /* Refer to ASC_IERR_* definitions for meaning of 'err_code'. */
  6409. if (asc_dvc->err_code || !asc_dvc->overrun_dma) {
  6410. scmd_printk(KERN_INFO, scp, "SCSI host reset error: "
  6411. "0x%x, status: 0x%x\n", asc_dvc->err_code,
  6412. status);
  6413. ret = FAILED;
  6414. } else if (status) {
  6415. scmd_printk(KERN_INFO, scp, "SCSI host reset warning: "
  6416. "0x%x\n", status);
  6417. } else {
  6418. scmd_printk(KERN_INFO, scp, "SCSI host reset "
  6419. "successful\n");
  6420. }
  6421. ASC_DBG(1, "after AscInitAsc1000Driver()\n");
  6422. } else {
  6423. /*
  6424. * If the suggest reset bus flags are set, then reset the bus.
  6425. * Otherwise only reset the device.
  6426. */
  6427. ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
  6428. /*
  6429. * Reset the chip and SCSI bus.
  6430. */
  6431. ASC_DBG(1, "before AdvResetChipAndSB()\n");
  6432. switch (AdvResetChipAndSB(adv_dvc)) {
  6433. case ASC_TRUE:
  6434. scmd_printk(KERN_INFO, scp, "SCSI host reset "
  6435. "successful\n");
  6436. break;
  6437. case ASC_FALSE:
  6438. default:
  6439. scmd_printk(KERN_INFO, scp, "SCSI host reset error\n");
  6440. ret = FAILED;
  6441. break;
  6442. }
  6443. spin_lock_irqsave(shost->host_lock, flags);
  6444. AdvISR(adv_dvc);
  6445. spin_unlock_irqrestore(shost->host_lock, flags);
  6446. }
  6447. ASC_DBG(1, "ret %d\n", ret);
  6448. return ret;
  6449. }
  6450. /*
  6451. * advansys_biosparam()
  6452. *
  6453. * Translate disk drive geometry if the "BIOS greater than 1 GB"
  6454. * support is enabled for a drive.
  6455. *
  6456. * ip (information pointer) is an int array with the following definition:
  6457. * ip[0]: heads
  6458. * ip[1]: sectors
  6459. * ip[2]: cylinders
  6460. */
  6461. static int
  6462. advansys_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  6463. sector_t capacity, int ip[])
  6464. {
  6465. struct asc_board *boardp = shost_priv(sdev->host);
  6466. ASC_DBG(1, "begin\n");
  6467. ASC_STATS(sdev->host, biosparam);
  6468. if (ASC_NARROW_BOARD(boardp)) {
  6469. if ((boardp->dvc_var.asc_dvc_var.dvc_cntl &
  6470. ASC_CNTL_BIOS_GT_1GB) && capacity > 0x200000) {
  6471. ip[0] = 255;
  6472. ip[1] = 63;
  6473. } else {
  6474. ip[0] = 64;
  6475. ip[1] = 32;
  6476. }
  6477. } else {
  6478. if ((boardp->dvc_var.adv_dvc_var.bios_ctrl &
  6479. BIOS_CTRL_EXTENDED_XLAT) && capacity > 0x200000) {
  6480. ip[0] = 255;
  6481. ip[1] = 63;
  6482. } else {
  6483. ip[0] = 64;
  6484. ip[1] = 32;
  6485. }
  6486. }
  6487. ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
  6488. ASC_DBG(1, "end\n");
  6489. return 0;
  6490. }
  6491. /*
  6492. * First-level interrupt handler.
  6493. *
  6494. * 'dev_id' is a pointer to the interrupting adapter's Scsi_Host.
  6495. */
  6496. static irqreturn_t advansys_interrupt(int irq, void *dev_id)
  6497. {
  6498. struct Scsi_Host *shost = dev_id;
  6499. struct asc_board *boardp = shost_priv(shost);
  6500. irqreturn_t result = IRQ_NONE;
  6501. unsigned long flags;
  6502. ASC_DBG(2, "boardp 0x%p\n", boardp);
  6503. spin_lock_irqsave(shost->host_lock, flags);
  6504. if (ASC_NARROW_BOARD(boardp)) {
  6505. if (AscIsIntPending(shost->io_port)) {
  6506. result = IRQ_HANDLED;
  6507. ASC_STATS(shost, interrupt);
  6508. ASC_DBG(1, "before AscISR()\n");
  6509. AscISR(&boardp->dvc_var.asc_dvc_var);
  6510. }
  6511. } else {
  6512. ASC_DBG(1, "before AdvISR()\n");
  6513. if (AdvISR(&boardp->dvc_var.adv_dvc_var)) {
  6514. result = IRQ_HANDLED;
  6515. ASC_STATS(shost, interrupt);
  6516. }
  6517. }
  6518. spin_unlock_irqrestore(shost->host_lock, flags);
  6519. ASC_DBG(1, "end\n");
  6520. return result;
  6521. }
  6522. static bool AscHostReqRiscHalt(PortAddr iop_base)
  6523. {
  6524. int count = 0;
  6525. bool sta = false;
  6526. uchar saved_stop_code;
  6527. if (AscIsChipHalted(iop_base))
  6528. return true;
  6529. saved_stop_code = AscReadLramByte(iop_base, ASCV_STOP_CODE_B);
  6530. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
  6531. ASC_STOP_HOST_REQ_RISC_HALT | ASC_STOP_REQ_RISC_STOP);
  6532. do {
  6533. if (AscIsChipHalted(iop_base)) {
  6534. sta = true;
  6535. break;
  6536. }
  6537. mdelay(100);
  6538. } while (count++ < 20);
  6539. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, saved_stop_code);
  6540. return sta;
  6541. }
  6542. static bool
  6543. AscSetRunChipSynRegAtID(PortAddr iop_base, uchar tid_no, uchar sdtr_data)
  6544. {
  6545. bool sta = false;
  6546. if (AscHostReqRiscHalt(iop_base)) {
  6547. sta = AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
  6548. AscStartChip(iop_base);
  6549. }
  6550. return sta;
  6551. }
  6552. static void AscAsyncFix(ASC_DVC_VAR *asc_dvc, struct scsi_device *sdev)
  6553. {
  6554. char type = sdev->type;
  6555. ASC_SCSI_BIT_ID_TYPE tid_bits = 1 << sdev->id;
  6556. if (!(asc_dvc->bug_fix_cntl & ASC_BUG_FIX_ASYN_USE_SYN))
  6557. return;
  6558. if (asc_dvc->init_sdtr & tid_bits)
  6559. return;
  6560. if ((type == TYPE_ROM) && (strncmp(sdev->vendor, "HP ", 3) == 0))
  6561. asc_dvc->pci_fix_asyn_xfer_always |= tid_bits;
  6562. asc_dvc->pci_fix_asyn_xfer |= tid_bits;
  6563. if ((type == TYPE_PROCESSOR) || (type == TYPE_SCANNER) ||
  6564. (type == TYPE_ROM) || (type == TYPE_TAPE))
  6565. asc_dvc->pci_fix_asyn_xfer &= ~tid_bits;
  6566. if (asc_dvc->pci_fix_asyn_xfer & tid_bits)
  6567. AscSetRunChipSynRegAtID(asc_dvc->iop_base, sdev->id,
  6568. ASYN_SDTR_DATA_FIX_PCI_REV_AB);
  6569. }
  6570. static void
  6571. advansys_narrow_slave_configure(struct scsi_device *sdev, ASC_DVC_VAR *asc_dvc)
  6572. {
  6573. ASC_SCSI_BIT_ID_TYPE tid_bit = 1 << sdev->id;
  6574. ASC_SCSI_BIT_ID_TYPE orig_use_tagged_qng = asc_dvc->use_tagged_qng;
  6575. if (sdev->lun == 0) {
  6576. ASC_SCSI_BIT_ID_TYPE orig_init_sdtr = asc_dvc->init_sdtr;
  6577. if ((asc_dvc->cfg->sdtr_enable & tid_bit) && sdev->sdtr) {
  6578. asc_dvc->init_sdtr |= tid_bit;
  6579. } else {
  6580. asc_dvc->init_sdtr &= ~tid_bit;
  6581. }
  6582. if (orig_init_sdtr != asc_dvc->init_sdtr)
  6583. AscAsyncFix(asc_dvc, sdev);
  6584. }
  6585. if (sdev->tagged_supported) {
  6586. if (asc_dvc->cfg->cmd_qng_enabled & tid_bit) {
  6587. if (sdev->lun == 0) {
  6588. asc_dvc->cfg->can_tagged_qng |= tid_bit;
  6589. asc_dvc->use_tagged_qng |= tid_bit;
  6590. }
  6591. scsi_change_queue_depth(sdev,
  6592. asc_dvc->max_dvc_qng[sdev->id]);
  6593. }
  6594. } else {
  6595. if (sdev->lun == 0) {
  6596. asc_dvc->cfg->can_tagged_qng &= ~tid_bit;
  6597. asc_dvc->use_tagged_qng &= ~tid_bit;
  6598. }
  6599. }
  6600. if ((sdev->lun == 0) &&
  6601. (orig_use_tagged_qng != asc_dvc->use_tagged_qng)) {
  6602. AscWriteLramByte(asc_dvc->iop_base, ASCV_DISC_ENABLE_B,
  6603. asc_dvc->cfg->disc_enable);
  6604. AscWriteLramByte(asc_dvc->iop_base, ASCV_USE_TAGGED_QNG_B,
  6605. asc_dvc->use_tagged_qng);
  6606. AscWriteLramByte(asc_dvc->iop_base, ASCV_CAN_TAGGED_QNG_B,
  6607. asc_dvc->cfg->can_tagged_qng);
  6608. asc_dvc->max_dvc_qng[sdev->id] =
  6609. asc_dvc->cfg->max_tag_qng[sdev->id];
  6610. AscWriteLramByte(asc_dvc->iop_base,
  6611. (ushort)(ASCV_MAX_DVC_QNG_BEG + sdev->id),
  6612. asc_dvc->max_dvc_qng[sdev->id]);
  6613. }
  6614. }
  6615. /*
  6616. * Wide Transfers
  6617. *
  6618. * If the EEPROM enabled WDTR for the device and the device supports wide
  6619. * bus (16 bit) transfers, then turn on the device's 'wdtr_able' bit and
  6620. * write the new value to the microcode.
  6621. */
  6622. static void
  6623. advansys_wide_enable_wdtr(AdvPortAddr iop_base, unsigned short tidmask)
  6624. {
  6625. unsigned short cfg_word;
  6626. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
  6627. if ((cfg_word & tidmask) != 0)
  6628. return;
  6629. cfg_word |= tidmask;
  6630. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
  6631. /*
  6632. * Clear the microcode SDTR and WDTR negotiation done indicators for
  6633. * the target to cause it to negotiate with the new setting set above.
  6634. * WDTR when accepted causes the target to enter asynchronous mode, so
  6635. * SDTR must be negotiated.
  6636. */
  6637. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  6638. cfg_word &= ~tidmask;
  6639. AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  6640. AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
  6641. cfg_word &= ~tidmask;
  6642. AdvWriteWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
  6643. }
  6644. /*
  6645. * Synchronous Transfers
  6646. *
  6647. * If the EEPROM enabled SDTR for the device and the device
  6648. * supports synchronous transfers, then turn on the device's
  6649. * 'sdtr_able' bit. Write the new value to the microcode.
  6650. */
  6651. static void
  6652. advansys_wide_enable_sdtr(AdvPortAddr iop_base, unsigned short tidmask)
  6653. {
  6654. unsigned short cfg_word;
  6655. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
  6656. if ((cfg_word & tidmask) != 0)
  6657. return;
  6658. cfg_word |= tidmask;
  6659. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
  6660. /*
  6661. * Clear the microcode "SDTR negotiation" done indicator for the
  6662. * target to cause it to negotiate with the new setting set above.
  6663. */
  6664. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  6665. cfg_word &= ~tidmask;
  6666. AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  6667. }
  6668. /*
  6669. * PPR (Parallel Protocol Request) Capable
  6670. *
  6671. * If the device supports DT mode, then it must be PPR capable.
  6672. * The PPR message will be used in place of the SDTR and WDTR
  6673. * messages to negotiate synchronous speed and offset, transfer
  6674. * width, and protocol options.
  6675. */
  6676. static void advansys_wide_enable_ppr(ADV_DVC_VAR *adv_dvc,
  6677. AdvPortAddr iop_base, unsigned short tidmask)
  6678. {
  6679. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
  6680. adv_dvc->ppr_able |= tidmask;
  6681. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
  6682. }
  6683. static void
  6684. advansys_wide_slave_configure(struct scsi_device *sdev, ADV_DVC_VAR *adv_dvc)
  6685. {
  6686. AdvPortAddr iop_base = adv_dvc->iop_base;
  6687. unsigned short tidmask = 1 << sdev->id;
  6688. if (sdev->lun == 0) {
  6689. /*
  6690. * Handle WDTR, SDTR, and Tag Queuing. If the feature
  6691. * is enabled in the EEPROM and the device supports the
  6692. * feature, then enable it in the microcode.
  6693. */
  6694. if ((adv_dvc->wdtr_able & tidmask) && sdev->wdtr)
  6695. advansys_wide_enable_wdtr(iop_base, tidmask);
  6696. if ((adv_dvc->sdtr_able & tidmask) && sdev->sdtr)
  6697. advansys_wide_enable_sdtr(iop_base, tidmask);
  6698. if (adv_dvc->chip_type == ADV_CHIP_ASC38C1600 && sdev->ppr)
  6699. advansys_wide_enable_ppr(adv_dvc, iop_base, tidmask);
  6700. /*
  6701. * Tag Queuing is disabled for the BIOS which runs in polled
  6702. * mode and would see no benefit from Tag Queuing. Also by
  6703. * disabling Tag Queuing in the BIOS devices with Tag Queuing
  6704. * bugs will at least work with the BIOS.
  6705. */
  6706. if ((adv_dvc->tagqng_able & tidmask) &&
  6707. sdev->tagged_supported) {
  6708. unsigned short cfg_word;
  6709. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word);
  6710. cfg_word |= tidmask;
  6711. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  6712. cfg_word);
  6713. AdvWriteByteLram(iop_base,
  6714. ASC_MC_NUMBER_OF_MAX_CMD + sdev->id,
  6715. adv_dvc->max_dvc_qng);
  6716. }
  6717. }
  6718. if ((adv_dvc->tagqng_able & tidmask) && sdev->tagged_supported)
  6719. scsi_change_queue_depth(sdev, adv_dvc->max_dvc_qng);
  6720. }
  6721. /*
  6722. * Set the number of commands to queue per device for the
  6723. * specified host adapter.
  6724. */
  6725. static int advansys_slave_configure(struct scsi_device *sdev)
  6726. {
  6727. struct asc_board *boardp = shost_priv(sdev->host);
  6728. if (ASC_NARROW_BOARD(boardp))
  6729. advansys_narrow_slave_configure(sdev,
  6730. &boardp->dvc_var.asc_dvc_var);
  6731. else
  6732. advansys_wide_slave_configure(sdev,
  6733. &boardp->dvc_var.adv_dvc_var);
  6734. return 0;
  6735. }
  6736. static __le32 asc_get_sense_buffer_dma(struct scsi_cmnd *scp)
  6737. {
  6738. struct asc_board *board = shost_priv(scp->device->host);
  6739. scp->SCp.dma_handle = dma_map_single(board->dev, scp->sense_buffer,
  6740. SCSI_SENSE_BUFFERSIZE,
  6741. DMA_FROM_DEVICE);
  6742. if (dma_mapping_error(board->dev, scp->SCp.dma_handle)) {
  6743. ASC_DBG(1, "failed to map sense buffer\n");
  6744. return 0;
  6745. }
  6746. return cpu_to_le32(scp->SCp.dma_handle);
  6747. }
  6748. static int asc_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
  6749. struct asc_scsi_q *asc_scsi_q)
  6750. {
  6751. struct asc_dvc_var *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  6752. int use_sg;
  6753. u32 srb_tag;
  6754. memset(asc_scsi_q, 0, sizeof(*asc_scsi_q));
  6755. /*
  6756. * Set the srb_tag to the command tag + 1, as
  6757. * srb_tag '0' is used internally by the chip.
  6758. */
  6759. srb_tag = scp->request->tag + 1;
  6760. asc_scsi_q->q2.srb_tag = srb_tag;
  6761. /*
  6762. * Build the ASC_SCSI_Q request.
  6763. */
  6764. asc_scsi_q->cdbptr = &scp->cmnd[0];
  6765. asc_scsi_q->q2.cdb_len = scp->cmd_len;
  6766. asc_scsi_q->q1.target_id = ASC_TID_TO_TARGET_ID(scp->device->id);
  6767. asc_scsi_q->q1.target_lun = scp->device->lun;
  6768. asc_scsi_q->q2.target_ix =
  6769. ASC_TIDLUN_TO_IX(scp->device->id, scp->device->lun);
  6770. asc_scsi_q->q1.sense_addr = asc_get_sense_buffer_dma(scp);
  6771. asc_scsi_q->q1.sense_len = SCSI_SENSE_BUFFERSIZE;
  6772. if (!asc_scsi_q->q1.sense_addr)
  6773. return ASC_BUSY;
  6774. /*
  6775. * If there are any outstanding requests for the current target,
  6776. * then every 255th request send an ORDERED request. This heuristic
  6777. * tries to retain the benefit of request sorting while preventing
  6778. * request starvation. 255 is the max number of tags or pending commands
  6779. * a device may have outstanding.
  6780. *
  6781. * The request count is incremented below for every successfully
  6782. * started request.
  6783. *
  6784. */
  6785. if ((asc_dvc->cur_dvc_qng[scp->device->id] > 0) &&
  6786. (boardp->reqcnt[scp->device->id] % 255) == 0) {
  6787. asc_scsi_q->q2.tag_code = ORDERED_QUEUE_TAG;
  6788. } else {
  6789. asc_scsi_q->q2.tag_code = SIMPLE_QUEUE_TAG;
  6790. }
  6791. /* Build ASC_SCSI_Q */
  6792. use_sg = scsi_dma_map(scp);
  6793. if (use_sg < 0) {
  6794. ASC_DBG(1, "failed to map sglist\n");
  6795. return ASC_BUSY;
  6796. } else if (use_sg > 0) {
  6797. int sgcnt;
  6798. struct scatterlist *slp;
  6799. struct asc_sg_head *asc_sg_head;
  6800. if (use_sg > scp->device->host->sg_tablesize) {
  6801. scmd_printk(KERN_ERR, scp, "use_sg %d > "
  6802. "sg_tablesize %d\n", use_sg,
  6803. scp->device->host->sg_tablesize);
  6804. scsi_dma_unmap(scp);
  6805. scp->result = HOST_BYTE(DID_ERROR);
  6806. return ASC_ERROR;
  6807. }
  6808. asc_sg_head = kzalloc(sizeof(asc_scsi_q->sg_head) +
  6809. use_sg * sizeof(struct asc_sg_list), GFP_ATOMIC);
  6810. if (!asc_sg_head) {
  6811. scsi_dma_unmap(scp);
  6812. scp->result = HOST_BYTE(DID_SOFT_ERROR);
  6813. return ASC_ERROR;
  6814. }
  6815. asc_scsi_q->q1.cntl |= QC_SG_HEAD;
  6816. asc_scsi_q->sg_head = asc_sg_head;
  6817. asc_scsi_q->q1.data_cnt = 0;
  6818. asc_scsi_q->q1.data_addr = 0;
  6819. /* This is a byte value, otherwise it would need to be swapped. */
  6820. asc_sg_head->entry_cnt = asc_scsi_q->q1.sg_queue_cnt = use_sg;
  6821. ASC_STATS_ADD(scp->device->host, xfer_elem,
  6822. asc_sg_head->entry_cnt);
  6823. /*
  6824. * Convert scatter-gather list into ASC_SG_HEAD list.
  6825. */
  6826. scsi_for_each_sg(scp, slp, use_sg, sgcnt) {
  6827. asc_sg_head->sg_list[sgcnt].addr =
  6828. cpu_to_le32(sg_dma_address(slp));
  6829. asc_sg_head->sg_list[sgcnt].bytes =
  6830. cpu_to_le32(sg_dma_len(slp));
  6831. ASC_STATS_ADD(scp->device->host, xfer_sect,
  6832. DIV_ROUND_UP(sg_dma_len(slp), 512));
  6833. }
  6834. }
  6835. ASC_STATS(scp->device->host, xfer_cnt);
  6836. ASC_DBG_PRT_ASC_SCSI_Q(2, asc_scsi_q);
  6837. ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
  6838. return ASC_NOERROR;
  6839. }
  6840. /*
  6841. * Build scatter-gather list for Adv Library (Wide Board).
  6842. *
  6843. * Additional ADV_SG_BLOCK structures will need to be allocated
  6844. * if the total number of scatter-gather elements exceeds
  6845. * NO_OF_SG_PER_BLOCK (15). The ADV_SG_BLOCK structures are
  6846. * assumed to be physically contiguous.
  6847. *
  6848. * Return:
  6849. * ADV_SUCCESS(1) - SG List successfully created
  6850. * ADV_ERROR(-1) - SG List creation failed
  6851. */
  6852. static int
  6853. adv_get_sglist(struct asc_board *boardp, adv_req_t *reqp,
  6854. ADV_SCSI_REQ_Q *scsiqp, struct scsi_cmnd *scp, int use_sg)
  6855. {
  6856. adv_sgblk_t *sgblkp, *prev_sgblkp;
  6857. struct scatterlist *slp;
  6858. int sg_elem_cnt;
  6859. ADV_SG_BLOCK *sg_block, *prev_sg_block;
  6860. dma_addr_t sgblk_paddr;
  6861. int i;
  6862. slp = scsi_sglist(scp);
  6863. sg_elem_cnt = use_sg;
  6864. prev_sgblkp = NULL;
  6865. prev_sg_block = NULL;
  6866. reqp->sgblkp = NULL;
  6867. for (;;) {
  6868. /*
  6869. * Allocate a 'adv_sgblk_t' structure from the board free
  6870. * list. One 'adv_sgblk_t' structure holds NO_OF_SG_PER_BLOCK
  6871. * (15) scatter-gather elements.
  6872. */
  6873. sgblkp = dma_pool_alloc(boardp->adv_sgblk_pool, GFP_ATOMIC,
  6874. &sgblk_paddr);
  6875. if (!sgblkp) {
  6876. ASC_DBG(1, "no free adv_sgblk_t\n");
  6877. ASC_STATS(scp->device->host, adv_build_nosg);
  6878. /*
  6879. * Allocation failed. Free 'adv_sgblk_t' structures
  6880. * already allocated for the request.
  6881. */
  6882. while ((sgblkp = reqp->sgblkp) != NULL) {
  6883. /* Remove 'sgblkp' from the request list. */
  6884. reqp->sgblkp = sgblkp->next_sgblkp;
  6885. sgblkp->next_sgblkp = NULL;
  6886. dma_pool_free(boardp->adv_sgblk_pool, sgblkp,
  6887. sgblkp->sg_addr);
  6888. }
  6889. return ASC_BUSY;
  6890. }
  6891. /* Complete 'adv_sgblk_t' board allocation. */
  6892. sgblkp->sg_addr = sgblk_paddr;
  6893. sgblkp->next_sgblkp = NULL;
  6894. sg_block = &sgblkp->sg_block;
  6895. /*
  6896. * Check if this is the first 'adv_sgblk_t' for the
  6897. * request.
  6898. */
  6899. if (reqp->sgblkp == NULL) {
  6900. /* Request's first scatter-gather block. */
  6901. reqp->sgblkp = sgblkp;
  6902. /*
  6903. * Set ADV_SCSI_REQ_T ADV_SG_BLOCK virtual and physical
  6904. * address pointers.
  6905. */
  6906. scsiqp->sg_list_ptr = sg_block;
  6907. scsiqp->sg_real_addr = cpu_to_le32(sgblk_paddr);
  6908. } else {
  6909. /* Request's second or later scatter-gather block. */
  6910. prev_sgblkp->next_sgblkp = sgblkp;
  6911. /*
  6912. * Point the previous ADV_SG_BLOCK structure to
  6913. * the newly allocated ADV_SG_BLOCK structure.
  6914. */
  6915. prev_sg_block->sg_ptr = cpu_to_le32(sgblk_paddr);
  6916. }
  6917. for (i = 0; i < NO_OF_SG_PER_BLOCK; i++) {
  6918. sg_block->sg_list[i].sg_addr =
  6919. cpu_to_le32(sg_dma_address(slp));
  6920. sg_block->sg_list[i].sg_count =
  6921. cpu_to_le32(sg_dma_len(slp));
  6922. ASC_STATS_ADD(scp->device->host, xfer_sect,
  6923. DIV_ROUND_UP(sg_dma_len(slp), 512));
  6924. if (--sg_elem_cnt == 0) {
  6925. /*
  6926. * Last ADV_SG_BLOCK and scatter-gather entry.
  6927. */
  6928. sg_block->sg_cnt = i + 1;
  6929. sg_block->sg_ptr = 0L; /* Last ADV_SG_BLOCK in list. */
  6930. return ADV_SUCCESS;
  6931. }
  6932. slp++;
  6933. }
  6934. sg_block->sg_cnt = NO_OF_SG_PER_BLOCK;
  6935. prev_sg_block = sg_block;
  6936. prev_sgblkp = sgblkp;
  6937. }
  6938. }
  6939. /*
  6940. * Build a request structure for the Adv Library (Wide Board).
  6941. *
  6942. * If an adv_req_t can not be allocated to issue the request,
  6943. * then return ASC_BUSY. If an error occurs, then return ASC_ERROR.
  6944. *
  6945. * Multi-byte fields in the ADV_SCSI_REQ_Q that are used by the
  6946. * microcode for DMA addresses or math operations are byte swapped
  6947. * to little-endian order.
  6948. */
  6949. static int
  6950. adv_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
  6951. adv_req_t **adv_reqpp)
  6952. {
  6953. u32 srb_tag = scp->request->tag;
  6954. adv_req_t *reqp;
  6955. ADV_SCSI_REQ_Q *scsiqp;
  6956. int ret;
  6957. int use_sg;
  6958. dma_addr_t sense_addr;
  6959. /*
  6960. * Allocate an adv_req_t structure from the board to execute
  6961. * the command.
  6962. */
  6963. reqp = &boardp->adv_reqp[srb_tag];
  6964. if (reqp->cmndp && reqp->cmndp != scp ) {
  6965. ASC_DBG(1, "no free adv_req_t\n");
  6966. ASC_STATS(scp->device->host, adv_build_noreq);
  6967. return ASC_BUSY;
  6968. }
  6969. reqp->req_addr = boardp->adv_reqp_addr + (srb_tag * sizeof(adv_req_t));
  6970. scsiqp = &reqp->scsi_req_q;
  6971. /*
  6972. * Initialize the structure.
  6973. */
  6974. scsiqp->cntl = scsiqp->scsi_cntl = scsiqp->done_status = 0;
  6975. /*
  6976. * Set the srb_tag to the command tag.
  6977. */
  6978. scsiqp->srb_tag = srb_tag;
  6979. /*
  6980. * Set 'host_scribble' to point to the adv_req_t structure.
  6981. */
  6982. reqp->cmndp = scp;
  6983. scp->host_scribble = (void *)reqp;
  6984. /*
  6985. * Build the ADV_SCSI_REQ_Q request.
  6986. */
  6987. /* Set CDB length and copy it to the request structure. */
  6988. scsiqp->cdb_len = scp->cmd_len;
  6989. /* Copy first 12 CDB bytes to cdb[]. */
  6990. memcpy(scsiqp->cdb, scp->cmnd, scp->cmd_len < 12 ? scp->cmd_len : 12);
  6991. /* Copy last 4 CDB bytes, if present, to cdb16[]. */
  6992. if (scp->cmd_len > 12) {
  6993. int cdb16_len = scp->cmd_len - 12;
  6994. memcpy(scsiqp->cdb16, &scp->cmnd[12], cdb16_len);
  6995. }
  6996. scsiqp->target_id = scp->device->id;
  6997. scsiqp->target_lun = scp->device->lun;
  6998. sense_addr = dma_map_single(boardp->dev, scp->sense_buffer,
  6999. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  7000. if (dma_mapping_error(boardp->dev, sense_addr)) {
  7001. ASC_DBG(1, "failed to map sense buffer\n");
  7002. ASC_STATS(scp->device->host, adv_build_noreq);
  7003. return ASC_BUSY;
  7004. }
  7005. scsiqp->sense_addr = cpu_to_le32(sense_addr);
  7006. scsiqp->sense_len = cpu_to_le32(SCSI_SENSE_BUFFERSIZE);
  7007. /* Build ADV_SCSI_REQ_Q */
  7008. use_sg = scsi_dma_map(scp);
  7009. if (use_sg < 0) {
  7010. ASC_DBG(1, "failed to map SG list\n");
  7011. ASC_STATS(scp->device->host, adv_build_noreq);
  7012. return ASC_BUSY;
  7013. } else if (use_sg == 0) {
  7014. /* Zero-length transfer */
  7015. reqp->sgblkp = NULL;
  7016. scsiqp->data_cnt = 0;
  7017. scsiqp->data_addr = 0;
  7018. scsiqp->sg_list_ptr = NULL;
  7019. scsiqp->sg_real_addr = 0;
  7020. } else {
  7021. if (use_sg > ADV_MAX_SG_LIST) {
  7022. scmd_printk(KERN_ERR, scp, "use_sg %d > "
  7023. "ADV_MAX_SG_LIST %d\n", use_sg,
  7024. scp->device->host->sg_tablesize);
  7025. scsi_dma_unmap(scp);
  7026. scp->result = HOST_BYTE(DID_ERROR);
  7027. reqp->cmndp = NULL;
  7028. scp->host_scribble = NULL;
  7029. return ASC_ERROR;
  7030. }
  7031. scsiqp->data_cnt = cpu_to_le32(scsi_bufflen(scp));
  7032. ret = adv_get_sglist(boardp, reqp, scsiqp, scp, use_sg);
  7033. if (ret != ADV_SUCCESS) {
  7034. scsi_dma_unmap(scp);
  7035. scp->result = HOST_BYTE(DID_ERROR);
  7036. reqp->cmndp = NULL;
  7037. scp->host_scribble = NULL;
  7038. return ret;
  7039. }
  7040. ASC_STATS_ADD(scp->device->host, xfer_elem, use_sg);
  7041. }
  7042. ASC_STATS(scp->device->host, xfer_cnt);
  7043. ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
  7044. ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
  7045. *adv_reqpp = reqp;
  7046. return ASC_NOERROR;
  7047. }
  7048. static int AscSgListToQueue(int sg_list)
  7049. {
  7050. int n_sg_list_qs;
  7051. n_sg_list_qs = ((sg_list - 1) / ASC_SG_LIST_PER_Q);
  7052. if (((sg_list - 1) % ASC_SG_LIST_PER_Q) != 0)
  7053. n_sg_list_qs++;
  7054. return n_sg_list_qs + 1;
  7055. }
  7056. static uint
  7057. AscGetNumOfFreeQueue(ASC_DVC_VAR *asc_dvc, uchar target_ix, uchar n_qs)
  7058. {
  7059. uint cur_used_qs;
  7060. uint cur_free_qs;
  7061. ASC_SCSI_BIT_ID_TYPE target_id;
  7062. uchar tid_no;
  7063. target_id = ASC_TIX_TO_TARGET_ID(target_ix);
  7064. tid_no = ASC_TIX_TO_TID(target_ix);
  7065. if ((asc_dvc->unit_not_ready & target_id) ||
  7066. (asc_dvc->queue_full_or_busy & target_id)) {
  7067. return 0;
  7068. }
  7069. if (n_qs == 1) {
  7070. cur_used_qs = (uint) asc_dvc->cur_total_qng +
  7071. (uint) asc_dvc->last_q_shortage + (uint) ASC_MIN_FREE_Q;
  7072. } else {
  7073. cur_used_qs = (uint) asc_dvc->cur_total_qng +
  7074. (uint) ASC_MIN_FREE_Q;
  7075. }
  7076. if ((uint) (cur_used_qs + n_qs) <= (uint) asc_dvc->max_total_qng) {
  7077. cur_free_qs = (uint) asc_dvc->max_total_qng - cur_used_qs;
  7078. if (asc_dvc->cur_dvc_qng[tid_no] >=
  7079. asc_dvc->max_dvc_qng[tid_no]) {
  7080. return 0;
  7081. }
  7082. return cur_free_qs;
  7083. }
  7084. if (n_qs > 1) {
  7085. if ((n_qs > asc_dvc->last_q_shortage)
  7086. && (n_qs <= (asc_dvc->max_total_qng - ASC_MIN_FREE_Q))) {
  7087. asc_dvc->last_q_shortage = n_qs;
  7088. }
  7089. }
  7090. return 0;
  7091. }
  7092. static uchar AscAllocFreeQueue(PortAddr iop_base, uchar free_q_head)
  7093. {
  7094. ushort q_addr;
  7095. uchar next_qp;
  7096. uchar q_status;
  7097. q_addr = ASC_QNO_TO_QADDR(free_q_head);
  7098. q_status = (uchar)AscReadLramByte(iop_base,
  7099. (ushort)(q_addr +
  7100. ASC_SCSIQ_B_STATUS));
  7101. next_qp = AscReadLramByte(iop_base, (ushort)(q_addr + ASC_SCSIQ_B_FWD));
  7102. if (((q_status & QS_READY) == 0) && (next_qp != ASC_QLINK_END))
  7103. return next_qp;
  7104. return ASC_QLINK_END;
  7105. }
  7106. static uchar
  7107. AscAllocMultipleFreeQueue(PortAddr iop_base, uchar free_q_head, uchar n_free_q)
  7108. {
  7109. uchar i;
  7110. for (i = 0; i < n_free_q; i++) {
  7111. free_q_head = AscAllocFreeQueue(iop_base, free_q_head);
  7112. if (free_q_head == ASC_QLINK_END)
  7113. break;
  7114. }
  7115. return free_q_head;
  7116. }
  7117. /*
  7118. * void
  7119. * DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
  7120. *
  7121. * Calling/Exit State:
  7122. * none
  7123. *
  7124. * Description:
  7125. * Output an ASC_SCSI_Q structure to the chip
  7126. */
  7127. static void
  7128. DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
  7129. {
  7130. int i;
  7131. ASC_DBG_PRT_HEX(2, "DvcPutScsiQ", outbuf, 2 * words);
  7132. AscSetChipLramAddr(iop_base, s_addr);
  7133. for (i = 0; i < 2 * words; i += 2) {
  7134. if (i == 4 || i == 20) {
  7135. continue;
  7136. }
  7137. outpw(iop_base + IOP_RAM_DATA,
  7138. ((ushort)outbuf[i + 1] << 8) | outbuf[i]);
  7139. }
  7140. }
  7141. static int AscPutReadyQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
  7142. {
  7143. ushort q_addr;
  7144. uchar tid_no;
  7145. uchar sdtr_data;
  7146. uchar syn_period_ix;
  7147. uchar syn_offset;
  7148. PortAddr iop_base;
  7149. iop_base = asc_dvc->iop_base;
  7150. if (((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) &&
  7151. ((asc_dvc->sdtr_done & scsiq->q1.target_id) == 0)) {
  7152. tid_no = ASC_TIX_TO_TID(scsiq->q2.target_ix);
  7153. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  7154. syn_period_ix =
  7155. (sdtr_data >> 4) & (asc_dvc->max_sdtr_index - 1);
  7156. syn_offset = sdtr_data & ASC_SYN_MAX_OFFSET;
  7157. AscMsgOutSDTR(asc_dvc,
  7158. asc_dvc->sdtr_period_tbl[syn_period_ix],
  7159. syn_offset);
  7160. scsiq->q1.cntl |= QC_MSG_OUT;
  7161. }
  7162. q_addr = ASC_QNO_TO_QADDR(q_no);
  7163. if ((scsiq->q1.target_id & asc_dvc->use_tagged_qng) == 0) {
  7164. scsiq->q2.tag_code &= ~SIMPLE_QUEUE_TAG;
  7165. }
  7166. scsiq->q1.status = QS_FREE;
  7167. AscMemWordCopyPtrToLram(iop_base,
  7168. q_addr + ASC_SCSIQ_CDB_BEG,
  7169. (uchar *)scsiq->cdbptr, scsiq->q2.cdb_len >> 1);
  7170. DvcPutScsiQ(iop_base,
  7171. q_addr + ASC_SCSIQ_CPY_BEG,
  7172. (uchar *)&scsiq->q1.cntl,
  7173. ((sizeof(ASC_SCSIQ_1) + sizeof(ASC_SCSIQ_2)) / 2) - 1);
  7174. AscWriteLramWord(iop_base,
  7175. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS),
  7176. (ushort)(((ushort)scsiq->q1.
  7177. q_no << 8) | (ushort)QS_READY));
  7178. return 1;
  7179. }
  7180. static int
  7181. AscPutReadySgListQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
  7182. {
  7183. int sta;
  7184. int i;
  7185. ASC_SG_HEAD *sg_head;
  7186. ASC_SG_LIST_Q scsi_sg_q;
  7187. __le32 saved_data_addr;
  7188. __le32 saved_data_cnt;
  7189. PortAddr iop_base;
  7190. ushort sg_list_dwords;
  7191. ushort sg_index;
  7192. ushort sg_entry_cnt;
  7193. ushort q_addr;
  7194. uchar next_qp;
  7195. iop_base = asc_dvc->iop_base;
  7196. sg_head = scsiq->sg_head;
  7197. saved_data_addr = scsiq->q1.data_addr;
  7198. saved_data_cnt = scsiq->q1.data_cnt;
  7199. scsiq->q1.data_addr = cpu_to_le32(sg_head->sg_list[0].addr);
  7200. scsiq->q1.data_cnt = cpu_to_le32(sg_head->sg_list[0].bytes);
  7201. /*
  7202. * Set sg_entry_cnt to be the number of SG elements that
  7203. * will fit in the allocated SG queues. It is minus 1, because
  7204. * the first SG element is handled above.
  7205. */
  7206. sg_entry_cnt = sg_head->entry_cnt - 1;
  7207. if (sg_entry_cnt != 0) {
  7208. scsiq->q1.cntl |= QC_SG_HEAD;
  7209. q_addr = ASC_QNO_TO_QADDR(q_no);
  7210. sg_index = 1;
  7211. scsiq->q1.sg_queue_cnt = sg_head->queue_cnt;
  7212. scsi_sg_q.sg_head_qp = q_no;
  7213. scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
  7214. for (i = 0; i < sg_head->queue_cnt; i++) {
  7215. scsi_sg_q.seq_no = i + 1;
  7216. if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
  7217. sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2);
  7218. sg_entry_cnt -= ASC_SG_LIST_PER_Q;
  7219. if (i == 0) {
  7220. scsi_sg_q.sg_list_cnt =
  7221. ASC_SG_LIST_PER_Q;
  7222. scsi_sg_q.sg_cur_list_cnt =
  7223. ASC_SG_LIST_PER_Q;
  7224. } else {
  7225. scsi_sg_q.sg_list_cnt =
  7226. ASC_SG_LIST_PER_Q - 1;
  7227. scsi_sg_q.sg_cur_list_cnt =
  7228. ASC_SG_LIST_PER_Q - 1;
  7229. }
  7230. } else {
  7231. scsi_sg_q.cntl |= QCSG_SG_XFER_END;
  7232. sg_list_dwords = sg_entry_cnt << 1;
  7233. if (i == 0) {
  7234. scsi_sg_q.sg_list_cnt = sg_entry_cnt;
  7235. scsi_sg_q.sg_cur_list_cnt =
  7236. sg_entry_cnt;
  7237. } else {
  7238. scsi_sg_q.sg_list_cnt =
  7239. sg_entry_cnt - 1;
  7240. scsi_sg_q.sg_cur_list_cnt =
  7241. sg_entry_cnt - 1;
  7242. }
  7243. sg_entry_cnt = 0;
  7244. }
  7245. next_qp = AscReadLramByte(iop_base,
  7246. (ushort)(q_addr +
  7247. ASC_SCSIQ_B_FWD));
  7248. scsi_sg_q.q_no = next_qp;
  7249. q_addr = ASC_QNO_TO_QADDR(next_qp);
  7250. AscMemWordCopyPtrToLram(iop_base,
  7251. q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
  7252. (uchar *)&scsi_sg_q,
  7253. sizeof(ASC_SG_LIST_Q) >> 1);
  7254. AscMemDWordCopyPtrToLram(iop_base,
  7255. q_addr + ASC_SGQ_LIST_BEG,
  7256. (uchar *)&sg_head->
  7257. sg_list[sg_index],
  7258. sg_list_dwords);
  7259. sg_index += ASC_SG_LIST_PER_Q;
  7260. scsiq->next_sg_index = sg_index;
  7261. }
  7262. } else {
  7263. scsiq->q1.cntl &= ~QC_SG_HEAD;
  7264. }
  7265. sta = AscPutReadyQueue(asc_dvc, scsiq, q_no);
  7266. scsiq->q1.data_addr = saved_data_addr;
  7267. scsiq->q1.data_cnt = saved_data_cnt;
  7268. return (sta);
  7269. }
  7270. static int
  7271. AscSendScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar n_q_required)
  7272. {
  7273. PortAddr iop_base;
  7274. uchar free_q_head;
  7275. uchar next_qp;
  7276. uchar tid_no;
  7277. uchar target_ix;
  7278. int sta;
  7279. iop_base = asc_dvc->iop_base;
  7280. target_ix = scsiq->q2.target_ix;
  7281. tid_no = ASC_TIX_TO_TID(target_ix);
  7282. sta = 0;
  7283. free_q_head = (uchar)AscGetVarFreeQHead(iop_base);
  7284. if (n_q_required > 1) {
  7285. next_qp = AscAllocMultipleFreeQueue(iop_base, free_q_head,
  7286. (uchar)n_q_required);
  7287. if (next_qp != ASC_QLINK_END) {
  7288. asc_dvc->last_q_shortage = 0;
  7289. scsiq->sg_head->queue_cnt = n_q_required - 1;
  7290. scsiq->q1.q_no = free_q_head;
  7291. sta = AscPutReadySgListQueue(asc_dvc, scsiq,
  7292. free_q_head);
  7293. }
  7294. } else if (n_q_required == 1) {
  7295. next_qp = AscAllocFreeQueue(iop_base, free_q_head);
  7296. if (next_qp != ASC_QLINK_END) {
  7297. scsiq->q1.q_no = free_q_head;
  7298. sta = AscPutReadyQueue(asc_dvc, scsiq, free_q_head);
  7299. }
  7300. }
  7301. if (sta == 1) {
  7302. AscPutVarFreeQHead(iop_base, next_qp);
  7303. asc_dvc->cur_total_qng += n_q_required;
  7304. asc_dvc->cur_dvc_qng[tid_no]++;
  7305. }
  7306. return sta;
  7307. }
  7308. #define ASC_SYN_OFFSET_ONE_DISABLE_LIST 16
  7309. static uchar _syn_offset_one_disable_cmd[ASC_SYN_OFFSET_ONE_DISABLE_LIST] = {
  7310. INQUIRY,
  7311. REQUEST_SENSE,
  7312. READ_CAPACITY,
  7313. READ_TOC,
  7314. MODE_SELECT,
  7315. MODE_SENSE,
  7316. MODE_SELECT_10,
  7317. MODE_SENSE_10,
  7318. 0xFF,
  7319. 0xFF,
  7320. 0xFF,
  7321. 0xFF,
  7322. 0xFF,
  7323. 0xFF,
  7324. 0xFF,
  7325. 0xFF
  7326. };
  7327. static int AscExeScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq)
  7328. {
  7329. PortAddr iop_base;
  7330. int sta;
  7331. int n_q_required;
  7332. bool disable_syn_offset_one_fix;
  7333. int i;
  7334. u32 addr;
  7335. ushort sg_entry_cnt = 0;
  7336. ushort sg_entry_cnt_minus_one = 0;
  7337. uchar target_ix;
  7338. uchar tid_no;
  7339. uchar sdtr_data;
  7340. uchar extra_bytes;
  7341. uchar scsi_cmd;
  7342. uchar disable_cmd;
  7343. ASC_SG_HEAD *sg_head;
  7344. unsigned long data_cnt;
  7345. iop_base = asc_dvc->iop_base;
  7346. sg_head = scsiq->sg_head;
  7347. if (asc_dvc->err_code != 0)
  7348. return ASC_ERROR;
  7349. scsiq->q1.q_no = 0;
  7350. if ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES) == 0) {
  7351. scsiq->q1.extra_bytes = 0;
  7352. }
  7353. sta = 0;
  7354. target_ix = scsiq->q2.target_ix;
  7355. tid_no = ASC_TIX_TO_TID(target_ix);
  7356. n_q_required = 1;
  7357. if (scsiq->cdbptr[0] == REQUEST_SENSE) {
  7358. if ((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) {
  7359. asc_dvc->sdtr_done &= ~scsiq->q1.target_id;
  7360. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  7361. AscMsgOutSDTR(asc_dvc,
  7362. asc_dvc->
  7363. sdtr_period_tbl[(sdtr_data >> 4) &
  7364. (uchar)(asc_dvc->
  7365. max_sdtr_index -
  7366. 1)],
  7367. (uchar)(sdtr_data & (uchar)
  7368. ASC_SYN_MAX_OFFSET));
  7369. scsiq->q1.cntl |= (QC_MSG_OUT | QC_URGENT);
  7370. }
  7371. }
  7372. if (asc_dvc->in_critical_cnt != 0) {
  7373. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CRITICAL_RE_ENTRY);
  7374. return ASC_ERROR;
  7375. }
  7376. asc_dvc->in_critical_cnt++;
  7377. if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
  7378. if ((sg_entry_cnt = sg_head->entry_cnt) == 0) {
  7379. asc_dvc->in_critical_cnt--;
  7380. return ASC_ERROR;
  7381. }
  7382. if (sg_entry_cnt > ASC_MAX_SG_LIST) {
  7383. asc_dvc->in_critical_cnt--;
  7384. return ASC_ERROR;
  7385. }
  7386. if (sg_entry_cnt == 1) {
  7387. scsiq->q1.data_addr = cpu_to_le32(sg_head->sg_list[0].addr);
  7388. scsiq->q1.data_cnt = cpu_to_le32(sg_head->sg_list[0].bytes);
  7389. scsiq->q1.cntl &= ~(QC_SG_HEAD | QC_SG_SWAP_QUEUE);
  7390. }
  7391. sg_entry_cnt_minus_one = sg_entry_cnt - 1;
  7392. }
  7393. scsi_cmd = scsiq->cdbptr[0];
  7394. disable_syn_offset_one_fix = false;
  7395. if ((asc_dvc->pci_fix_asyn_xfer & scsiq->q1.target_id) &&
  7396. !(asc_dvc->pci_fix_asyn_xfer_always & scsiq->q1.target_id)) {
  7397. if (scsiq->q1.cntl & QC_SG_HEAD) {
  7398. data_cnt = 0;
  7399. for (i = 0; i < sg_entry_cnt; i++) {
  7400. data_cnt += le32_to_cpu(sg_head->sg_list[i].
  7401. bytes);
  7402. }
  7403. } else {
  7404. data_cnt = le32_to_cpu(scsiq->q1.data_cnt);
  7405. }
  7406. if (data_cnt != 0UL) {
  7407. if (data_cnt < 512UL) {
  7408. disable_syn_offset_one_fix = true;
  7409. } else {
  7410. for (i = 0; i < ASC_SYN_OFFSET_ONE_DISABLE_LIST;
  7411. i++) {
  7412. disable_cmd =
  7413. _syn_offset_one_disable_cmd[i];
  7414. if (disable_cmd == 0xFF) {
  7415. break;
  7416. }
  7417. if (scsi_cmd == disable_cmd) {
  7418. disable_syn_offset_one_fix =
  7419. true;
  7420. break;
  7421. }
  7422. }
  7423. }
  7424. }
  7425. }
  7426. if (disable_syn_offset_one_fix) {
  7427. scsiq->q2.tag_code &= ~SIMPLE_QUEUE_TAG;
  7428. scsiq->q2.tag_code |= (ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX |
  7429. ASC_TAG_FLAG_DISABLE_DISCONNECT);
  7430. } else {
  7431. scsiq->q2.tag_code &= 0x27;
  7432. }
  7433. if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
  7434. if (asc_dvc->bug_fix_cntl) {
  7435. if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
  7436. if ((scsi_cmd == READ_6) ||
  7437. (scsi_cmd == READ_10)) {
  7438. addr = le32_to_cpu(sg_head->
  7439. sg_list
  7440. [sg_entry_cnt_minus_one].
  7441. addr) +
  7442. le32_to_cpu(sg_head->
  7443. sg_list
  7444. [sg_entry_cnt_minus_one].
  7445. bytes);
  7446. extra_bytes =
  7447. (uchar)((ushort)addr & 0x0003);
  7448. if ((extra_bytes != 0)
  7449. &&
  7450. ((scsiq->q2.
  7451. tag_code &
  7452. ASC_TAG_FLAG_EXTRA_BYTES)
  7453. == 0)) {
  7454. scsiq->q2.tag_code |=
  7455. ASC_TAG_FLAG_EXTRA_BYTES;
  7456. scsiq->q1.extra_bytes =
  7457. extra_bytes;
  7458. data_cnt =
  7459. le32_to_cpu(sg_head->
  7460. sg_list
  7461. [sg_entry_cnt_minus_one].
  7462. bytes);
  7463. data_cnt -= extra_bytes;
  7464. sg_head->
  7465. sg_list
  7466. [sg_entry_cnt_minus_one].
  7467. bytes =
  7468. cpu_to_le32(data_cnt);
  7469. }
  7470. }
  7471. }
  7472. }
  7473. sg_head->entry_to_copy = sg_head->entry_cnt;
  7474. n_q_required = AscSgListToQueue(sg_entry_cnt);
  7475. if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, n_q_required) >=
  7476. (uint) n_q_required)
  7477. || ((scsiq->q1.cntl & QC_URGENT) != 0)) {
  7478. if ((sta =
  7479. AscSendScsiQueue(asc_dvc, scsiq,
  7480. n_q_required)) == 1) {
  7481. asc_dvc->in_critical_cnt--;
  7482. return (sta);
  7483. }
  7484. }
  7485. } else {
  7486. if (asc_dvc->bug_fix_cntl) {
  7487. if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
  7488. if ((scsi_cmd == READ_6) ||
  7489. (scsi_cmd == READ_10)) {
  7490. addr =
  7491. le32_to_cpu(scsiq->q1.data_addr) +
  7492. le32_to_cpu(scsiq->q1.data_cnt);
  7493. extra_bytes =
  7494. (uchar)((ushort)addr & 0x0003);
  7495. if ((extra_bytes != 0)
  7496. &&
  7497. ((scsiq->q2.
  7498. tag_code &
  7499. ASC_TAG_FLAG_EXTRA_BYTES)
  7500. == 0)) {
  7501. data_cnt =
  7502. le32_to_cpu(scsiq->q1.
  7503. data_cnt);
  7504. if (((ushort)data_cnt & 0x01FF)
  7505. == 0) {
  7506. scsiq->q2.tag_code |=
  7507. ASC_TAG_FLAG_EXTRA_BYTES;
  7508. data_cnt -= extra_bytes;
  7509. scsiq->q1.data_cnt =
  7510. cpu_to_le32
  7511. (data_cnt);
  7512. scsiq->q1.extra_bytes =
  7513. extra_bytes;
  7514. }
  7515. }
  7516. }
  7517. }
  7518. }
  7519. n_q_required = 1;
  7520. if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, 1) >= 1) ||
  7521. ((scsiq->q1.cntl & QC_URGENT) != 0)) {
  7522. if ((sta = AscSendScsiQueue(asc_dvc, scsiq,
  7523. n_q_required)) == 1) {
  7524. asc_dvc->in_critical_cnt--;
  7525. return (sta);
  7526. }
  7527. }
  7528. }
  7529. asc_dvc->in_critical_cnt--;
  7530. return (sta);
  7531. }
  7532. /*
  7533. * AdvExeScsiQueue() - Send a request to the RISC microcode program.
  7534. *
  7535. * Allocate a carrier structure, point the carrier to the ADV_SCSI_REQ_Q,
  7536. * add the carrier to the ICQ (Initiator Command Queue), and tickle the
  7537. * RISC to notify it a new command is ready to be executed.
  7538. *
  7539. * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
  7540. * set to SCSI_MAX_RETRY.
  7541. *
  7542. * Multi-byte fields in the ADV_SCSI_REQ_Q that are used by the microcode
  7543. * for DMA addresses or math operations are byte swapped to little-endian
  7544. * order.
  7545. *
  7546. * Return:
  7547. * ADV_SUCCESS(1) - The request was successfully queued.
  7548. * ADV_BUSY(0) - Resource unavailable; Retry again after pending
  7549. * request completes.
  7550. * ADV_ERROR(-1) - Invalid ADV_SCSI_REQ_Q request structure
  7551. * host IC error.
  7552. */
  7553. static int AdvExeScsiQueue(ADV_DVC_VAR *asc_dvc, adv_req_t *reqp)
  7554. {
  7555. AdvPortAddr iop_base;
  7556. ADV_CARR_T *new_carrp;
  7557. ADV_SCSI_REQ_Q *scsiq = &reqp->scsi_req_q;
  7558. /*
  7559. * The ADV_SCSI_REQ_Q 'target_id' field should never exceed ADV_MAX_TID.
  7560. */
  7561. if (scsiq->target_id > ADV_MAX_TID) {
  7562. scsiq->host_status = QHSTA_M_INVALID_DEVICE;
  7563. scsiq->done_status = QD_WITH_ERROR;
  7564. return ADV_ERROR;
  7565. }
  7566. iop_base = asc_dvc->iop_base;
  7567. /*
  7568. * Allocate a carrier ensuring at least one carrier always
  7569. * remains on the freelist and initialize fields.
  7570. */
  7571. new_carrp = adv_get_next_carrier(asc_dvc);
  7572. if (!new_carrp) {
  7573. ASC_DBG(1, "No free carriers\n");
  7574. return ADV_BUSY;
  7575. }
  7576. asc_dvc->carr_pending_cnt++;
  7577. /* Save virtual and physical address of ADV_SCSI_REQ_Q and carrier. */
  7578. scsiq->scsiq_ptr = cpu_to_le32(scsiq->srb_tag);
  7579. scsiq->scsiq_rptr = cpu_to_le32(reqp->req_addr);
  7580. scsiq->carr_va = asc_dvc->icq_sp->carr_va;
  7581. scsiq->carr_pa = asc_dvc->icq_sp->carr_pa;
  7582. /*
  7583. * Use the current stopper to send the ADV_SCSI_REQ_Q command to
  7584. * the microcode. The newly allocated stopper will become the new
  7585. * stopper.
  7586. */
  7587. asc_dvc->icq_sp->areq_vpa = scsiq->scsiq_rptr;
  7588. /*
  7589. * Set the 'next_vpa' pointer for the old stopper to be the
  7590. * physical address of the new stopper. The RISC can only
  7591. * follow physical addresses.
  7592. */
  7593. asc_dvc->icq_sp->next_vpa = new_carrp->carr_pa;
  7594. /*
  7595. * Set the host adapter stopper pointer to point to the new carrier.
  7596. */
  7597. asc_dvc->icq_sp = new_carrp;
  7598. if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
  7599. asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  7600. /*
  7601. * Tickle the RISC to tell it to read its Command Queue Head pointer.
  7602. */
  7603. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A);
  7604. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  7605. /*
  7606. * Clear the tickle value. In the ASC-3550 the RISC flag
  7607. * command 'clr_tickle_a' does not work unless the host
  7608. * value is cleared.
  7609. */
  7610. AdvWriteByteRegister(iop_base, IOPB_TICKLE,
  7611. ADV_TICKLE_NOP);
  7612. }
  7613. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  7614. /*
  7615. * Notify the RISC a carrier is ready by writing the physical
  7616. * address of the new carrier stopper to the COMMA register.
  7617. */
  7618. AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
  7619. le32_to_cpu(new_carrp->carr_pa));
  7620. }
  7621. return ADV_SUCCESS;
  7622. }
  7623. /*
  7624. * Execute a single 'Scsi_Cmnd'.
  7625. */
  7626. static int asc_execute_scsi_cmnd(struct scsi_cmnd *scp)
  7627. {
  7628. int ret, err_code;
  7629. struct asc_board *boardp = shost_priv(scp->device->host);
  7630. ASC_DBG(1, "scp 0x%p\n", scp);
  7631. if (ASC_NARROW_BOARD(boardp)) {
  7632. ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  7633. struct asc_scsi_q asc_scsi_q;
  7634. ret = asc_build_req(boardp, scp, &asc_scsi_q);
  7635. if (ret != ASC_NOERROR) {
  7636. ASC_STATS(scp->device->host, build_error);
  7637. return ret;
  7638. }
  7639. ret = AscExeScsiQueue(asc_dvc, &asc_scsi_q);
  7640. kfree(asc_scsi_q.sg_head);
  7641. err_code = asc_dvc->err_code;
  7642. } else {
  7643. ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
  7644. adv_req_t *adv_reqp;
  7645. switch (adv_build_req(boardp, scp, &adv_reqp)) {
  7646. case ASC_NOERROR:
  7647. ASC_DBG(3, "adv_build_req ASC_NOERROR\n");
  7648. break;
  7649. case ASC_BUSY:
  7650. ASC_DBG(1, "adv_build_req ASC_BUSY\n");
  7651. /*
  7652. * The asc_stats fields 'adv_build_noreq' and
  7653. * 'adv_build_nosg' count wide board busy conditions.
  7654. * They are updated in adv_build_req and
  7655. * adv_get_sglist, respectively.
  7656. */
  7657. return ASC_BUSY;
  7658. case ASC_ERROR:
  7659. default:
  7660. ASC_DBG(1, "adv_build_req ASC_ERROR\n");
  7661. ASC_STATS(scp->device->host, build_error);
  7662. return ASC_ERROR;
  7663. }
  7664. ret = AdvExeScsiQueue(adv_dvc, adv_reqp);
  7665. err_code = adv_dvc->err_code;
  7666. }
  7667. switch (ret) {
  7668. case ASC_NOERROR:
  7669. ASC_STATS(scp->device->host, exe_noerror);
  7670. /*
  7671. * Increment monotonically increasing per device
  7672. * successful request counter. Wrapping doesn't matter.
  7673. */
  7674. boardp->reqcnt[scp->device->id]++;
  7675. ASC_DBG(1, "ExeScsiQueue() ASC_NOERROR\n");
  7676. break;
  7677. case ASC_BUSY:
  7678. ASC_DBG(1, "ExeScsiQueue() ASC_BUSY\n");
  7679. ASC_STATS(scp->device->host, exe_busy);
  7680. break;
  7681. case ASC_ERROR:
  7682. scmd_printk(KERN_ERR, scp, "ExeScsiQueue() ASC_ERROR, "
  7683. "err_code 0x%x\n", err_code);
  7684. ASC_STATS(scp->device->host, exe_error);
  7685. scp->result = HOST_BYTE(DID_ERROR);
  7686. break;
  7687. default:
  7688. scmd_printk(KERN_ERR, scp, "ExeScsiQueue() unknown, "
  7689. "err_code 0x%x\n", err_code);
  7690. ASC_STATS(scp->device->host, exe_unknown);
  7691. scp->result = HOST_BYTE(DID_ERROR);
  7692. break;
  7693. }
  7694. ASC_DBG(1, "end\n");
  7695. return ret;
  7696. }
  7697. /*
  7698. * advansys_queuecommand() - interrupt-driven I/O entrypoint.
  7699. *
  7700. * This function always returns 0. Command return status is saved
  7701. * in the 'scp' result field.
  7702. */
  7703. static int
  7704. advansys_queuecommand_lck(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *))
  7705. {
  7706. struct Scsi_Host *shost = scp->device->host;
  7707. int asc_res, result = 0;
  7708. ASC_STATS(shost, queuecommand);
  7709. scp->scsi_done = done;
  7710. asc_res = asc_execute_scsi_cmnd(scp);
  7711. switch (asc_res) {
  7712. case ASC_NOERROR:
  7713. break;
  7714. case ASC_BUSY:
  7715. result = SCSI_MLQUEUE_HOST_BUSY;
  7716. break;
  7717. case ASC_ERROR:
  7718. default:
  7719. asc_scsi_done(scp);
  7720. break;
  7721. }
  7722. return result;
  7723. }
  7724. static DEF_SCSI_QCMD(advansys_queuecommand)
  7725. static ushort AscGetEisaChipCfg(PortAddr iop_base)
  7726. {
  7727. PortAddr eisa_cfg_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
  7728. (PortAddr) (ASC_EISA_CFG_IOP_MASK);
  7729. return inpw(eisa_cfg_iop);
  7730. }
  7731. /*
  7732. * Return the BIOS address of the adapter at the specified
  7733. * I/O port and with the specified bus type.
  7734. */
  7735. static unsigned short AscGetChipBiosAddress(PortAddr iop_base,
  7736. unsigned short bus_type)
  7737. {
  7738. unsigned short cfg_lsw;
  7739. unsigned short bios_addr;
  7740. /*
  7741. * The PCI BIOS is re-located by the motherboard BIOS. Because
  7742. * of this the driver can not determine where a PCI BIOS is
  7743. * loaded and executes.
  7744. */
  7745. if (bus_type & ASC_IS_PCI)
  7746. return 0;
  7747. if ((bus_type & ASC_IS_EISA) != 0) {
  7748. cfg_lsw = AscGetEisaChipCfg(iop_base);
  7749. cfg_lsw &= 0x000F;
  7750. bios_addr = ASC_BIOS_MIN_ADDR + cfg_lsw * ASC_BIOS_BANK_SIZE;
  7751. return bios_addr;
  7752. }
  7753. cfg_lsw = AscGetChipCfgLsw(iop_base);
  7754. /*
  7755. * ISA PnP uses the top bit as the 32K BIOS flag
  7756. */
  7757. if (bus_type == ASC_IS_ISAPNP)
  7758. cfg_lsw &= 0x7FFF;
  7759. bios_addr = ASC_BIOS_MIN_ADDR + (cfg_lsw >> 12) * ASC_BIOS_BANK_SIZE;
  7760. return bios_addr;
  7761. }
  7762. static uchar AscSetChipScsiID(PortAddr iop_base, uchar new_host_id)
  7763. {
  7764. ushort cfg_lsw;
  7765. if (AscGetChipScsiID(iop_base) == new_host_id) {
  7766. return (new_host_id);
  7767. }
  7768. cfg_lsw = AscGetChipCfgLsw(iop_base);
  7769. cfg_lsw &= 0xF8FF;
  7770. cfg_lsw |= (ushort)((new_host_id & ASC_MAX_TID) << 8);
  7771. AscSetChipCfgLsw(iop_base, cfg_lsw);
  7772. return (AscGetChipScsiID(iop_base));
  7773. }
  7774. static unsigned char AscGetChipScsiCtrl(PortAddr iop_base)
  7775. {
  7776. unsigned char sc;
  7777. AscSetBank(iop_base, 1);
  7778. sc = inp(iop_base + IOP_REG_SC);
  7779. AscSetBank(iop_base, 0);
  7780. return sc;
  7781. }
  7782. static unsigned char AscGetChipVersion(PortAddr iop_base,
  7783. unsigned short bus_type)
  7784. {
  7785. if (bus_type & ASC_IS_EISA) {
  7786. PortAddr eisa_iop;
  7787. unsigned char revision;
  7788. eisa_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
  7789. (PortAddr) ASC_EISA_REV_IOP_MASK;
  7790. revision = inp(eisa_iop);
  7791. return ASC_CHIP_MIN_VER_EISA - 1 + revision;
  7792. }
  7793. return AscGetChipVerNo(iop_base);
  7794. }
  7795. #ifdef CONFIG_ISA
  7796. static void AscEnableIsaDma(uchar dma_channel)
  7797. {
  7798. if (dma_channel < 4) {
  7799. outp(0x000B, (ushort)(0xC0 | dma_channel));
  7800. outp(0x000A, dma_channel);
  7801. } else if (dma_channel < 8) {
  7802. outp(0x00D6, (ushort)(0xC0 | (dma_channel - 4)));
  7803. outp(0x00D4, (ushort)(dma_channel - 4));
  7804. }
  7805. }
  7806. #endif /* CONFIG_ISA */
  7807. static int AscStopQueueExe(PortAddr iop_base)
  7808. {
  7809. int count = 0;
  7810. if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) == 0) {
  7811. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
  7812. ASC_STOP_REQ_RISC_STOP);
  7813. do {
  7814. if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) &
  7815. ASC_STOP_ACK_RISC_STOP) {
  7816. return (1);
  7817. }
  7818. mdelay(100);
  7819. } while (count++ < 20);
  7820. }
  7821. return (0);
  7822. }
  7823. static unsigned int AscGetMaxDmaCount(ushort bus_type)
  7824. {
  7825. if (bus_type & ASC_IS_ISA)
  7826. return ASC_MAX_ISA_DMA_COUNT;
  7827. else if (bus_type & (ASC_IS_EISA | ASC_IS_VL))
  7828. return ASC_MAX_VL_DMA_COUNT;
  7829. return ASC_MAX_PCI_DMA_COUNT;
  7830. }
  7831. #ifdef CONFIG_ISA
  7832. static ushort AscGetIsaDmaChannel(PortAddr iop_base)
  7833. {
  7834. ushort channel;
  7835. channel = AscGetChipCfgLsw(iop_base) & 0x0003;
  7836. if (channel == 0x03)
  7837. return (0);
  7838. else if (channel == 0x00)
  7839. return (7);
  7840. return (channel + 4);
  7841. }
  7842. static ushort AscSetIsaDmaChannel(PortAddr iop_base, ushort dma_channel)
  7843. {
  7844. ushort cfg_lsw;
  7845. uchar value;
  7846. if ((dma_channel >= 5) && (dma_channel <= 7)) {
  7847. if (dma_channel == 7)
  7848. value = 0x00;
  7849. else
  7850. value = dma_channel - 4;
  7851. cfg_lsw = AscGetChipCfgLsw(iop_base) & 0xFFFC;
  7852. cfg_lsw |= value;
  7853. AscSetChipCfgLsw(iop_base, cfg_lsw);
  7854. return (AscGetIsaDmaChannel(iop_base));
  7855. }
  7856. return 0;
  7857. }
  7858. static uchar AscGetIsaDmaSpeed(PortAddr iop_base)
  7859. {
  7860. uchar speed_value;
  7861. AscSetBank(iop_base, 1);
  7862. speed_value = AscReadChipDmaSpeed(iop_base);
  7863. speed_value &= 0x07;
  7864. AscSetBank(iop_base, 0);
  7865. return speed_value;
  7866. }
  7867. static uchar AscSetIsaDmaSpeed(PortAddr iop_base, uchar speed_value)
  7868. {
  7869. speed_value &= 0x07;
  7870. AscSetBank(iop_base, 1);
  7871. AscWriteChipDmaSpeed(iop_base, speed_value);
  7872. AscSetBank(iop_base, 0);
  7873. return AscGetIsaDmaSpeed(iop_base);
  7874. }
  7875. #endif /* CONFIG_ISA */
  7876. static void AscInitAscDvcVar(ASC_DVC_VAR *asc_dvc)
  7877. {
  7878. int i;
  7879. PortAddr iop_base;
  7880. uchar chip_version;
  7881. iop_base = asc_dvc->iop_base;
  7882. asc_dvc->err_code = 0;
  7883. if ((asc_dvc->bus_type &
  7884. (ASC_IS_ISA | ASC_IS_PCI | ASC_IS_EISA | ASC_IS_VL)) == 0) {
  7885. asc_dvc->err_code |= ASC_IERR_NO_BUS_TYPE;
  7886. }
  7887. AscSetChipControl(iop_base, CC_HALT);
  7888. AscSetChipStatus(iop_base, 0);
  7889. asc_dvc->bug_fix_cntl = 0;
  7890. asc_dvc->pci_fix_asyn_xfer = 0;
  7891. asc_dvc->pci_fix_asyn_xfer_always = 0;
  7892. /* asc_dvc->init_state initialized in AscInitGetConfig(). */
  7893. asc_dvc->sdtr_done = 0;
  7894. asc_dvc->cur_total_qng = 0;
  7895. asc_dvc->is_in_int = false;
  7896. asc_dvc->in_critical_cnt = 0;
  7897. asc_dvc->last_q_shortage = 0;
  7898. asc_dvc->use_tagged_qng = 0;
  7899. asc_dvc->no_scam = 0;
  7900. asc_dvc->unit_not_ready = 0;
  7901. asc_dvc->queue_full_or_busy = 0;
  7902. asc_dvc->redo_scam = 0;
  7903. asc_dvc->res2 = 0;
  7904. asc_dvc->min_sdtr_index = 0;
  7905. asc_dvc->cfg->can_tagged_qng = 0;
  7906. asc_dvc->cfg->cmd_qng_enabled = 0;
  7907. asc_dvc->dvc_cntl = ASC_DEF_DVC_CNTL;
  7908. asc_dvc->init_sdtr = 0;
  7909. asc_dvc->max_total_qng = ASC_DEF_MAX_TOTAL_QNG;
  7910. asc_dvc->scsi_reset_wait = 3;
  7911. asc_dvc->start_motor = ASC_SCSI_WIDTH_BIT_SET;
  7912. asc_dvc->max_dma_count = AscGetMaxDmaCount(asc_dvc->bus_type);
  7913. asc_dvc->cfg->sdtr_enable = ASC_SCSI_WIDTH_BIT_SET;
  7914. asc_dvc->cfg->disc_enable = ASC_SCSI_WIDTH_BIT_SET;
  7915. asc_dvc->cfg->chip_scsi_id = ASC_DEF_CHIP_SCSI_ID;
  7916. chip_version = AscGetChipVersion(iop_base, asc_dvc->bus_type);
  7917. asc_dvc->cfg->chip_version = chip_version;
  7918. asc_dvc->sdtr_period_tbl = asc_syn_xfer_period;
  7919. asc_dvc->max_sdtr_index = 7;
  7920. if ((asc_dvc->bus_type & ASC_IS_PCI) &&
  7921. (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3150)) {
  7922. asc_dvc->bus_type = ASC_IS_PCI_ULTRA;
  7923. asc_dvc->sdtr_period_tbl = asc_syn_ultra_xfer_period;
  7924. asc_dvc->max_sdtr_index = 15;
  7925. if (chip_version == ASC_CHIP_VER_PCI_ULTRA_3150) {
  7926. AscSetExtraControl(iop_base,
  7927. (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
  7928. } else if (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3050) {
  7929. AscSetExtraControl(iop_base,
  7930. (SEC_ACTIVE_NEGATE |
  7931. SEC_ENABLE_FILTER));
  7932. }
  7933. }
  7934. if (asc_dvc->bus_type == ASC_IS_PCI) {
  7935. AscSetExtraControl(iop_base,
  7936. (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
  7937. }
  7938. asc_dvc->cfg->isa_dma_speed = ASC_DEF_ISA_DMA_SPEED;
  7939. #ifdef CONFIG_ISA
  7940. if ((asc_dvc->bus_type & ASC_IS_ISA) != 0) {
  7941. if (chip_version >= ASC_CHIP_MIN_VER_ISA_PNP) {
  7942. AscSetChipIFC(iop_base, IFC_INIT_DEFAULT);
  7943. asc_dvc->bus_type = ASC_IS_ISAPNP;
  7944. }
  7945. asc_dvc->cfg->isa_dma_channel =
  7946. (uchar)AscGetIsaDmaChannel(iop_base);
  7947. }
  7948. #endif /* CONFIG_ISA */
  7949. for (i = 0; i <= ASC_MAX_TID; i++) {
  7950. asc_dvc->cur_dvc_qng[i] = 0;
  7951. asc_dvc->max_dvc_qng[i] = ASC_MAX_SCSI1_QNG;
  7952. asc_dvc->scsiq_busy_head[i] = (ASC_SCSI_Q *)0L;
  7953. asc_dvc->scsiq_busy_tail[i] = (ASC_SCSI_Q *)0L;
  7954. asc_dvc->cfg->max_tag_qng[i] = ASC_MAX_INRAM_TAG_QNG;
  7955. }
  7956. }
  7957. static int AscWriteEEPCmdReg(PortAddr iop_base, uchar cmd_reg)
  7958. {
  7959. int retry;
  7960. for (retry = 0; retry < ASC_EEP_MAX_RETRY; retry++) {
  7961. unsigned char read_back;
  7962. AscSetChipEEPCmd(iop_base, cmd_reg);
  7963. mdelay(1);
  7964. read_back = AscGetChipEEPCmd(iop_base);
  7965. if (read_back == cmd_reg)
  7966. return 1;
  7967. }
  7968. return 0;
  7969. }
  7970. static void AscWaitEEPRead(void)
  7971. {
  7972. mdelay(1);
  7973. }
  7974. static ushort AscReadEEPWord(PortAddr iop_base, uchar addr)
  7975. {
  7976. ushort read_wval;
  7977. uchar cmd_reg;
  7978. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
  7979. AscWaitEEPRead();
  7980. cmd_reg = addr | ASC_EEP_CMD_READ;
  7981. AscWriteEEPCmdReg(iop_base, cmd_reg);
  7982. AscWaitEEPRead();
  7983. read_wval = AscGetChipEEPData(iop_base);
  7984. AscWaitEEPRead();
  7985. return read_wval;
  7986. }
  7987. static ushort AscGetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
  7988. ushort bus_type)
  7989. {
  7990. ushort wval;
  7991. ushort sum;
  7992. ushort *wbuf;
  7993. int cfg_beg;
  7994. int cfg_end;
  7995. int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
  7996. int s_addr;
  7997. wbuf = (ushort *)cfg_buf;
  7998. sum = 0;
  7999. /* Read two config words; Byte-swapping done by AscReadEEPWord(). */
  8000. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  8001. *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
  8002. sum += *wbuf;
  8003. }
  8004. if (bus_type & ASC_IS_VL) {
  8005. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  8006. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  8007. } else {
  8008. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  8009. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  8010. }
  8011. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  8012. wval = AscReadEEPWord(iop_base, (uchar)s_addr);
  8013. if (s_addr <= uchar_end_in_config) {
  8014. /*
  8015. * Swap all char fields - must unswap bytes already swapped
  8016. * by AscReadEEPWord().
  8017. */
  8018. *wbuf = le16_to_cpu(wval);
  8019. } else {
  8020. /* Don't swap word field at the end - cntl field. */
  8021. *wbuf = wval;
  8022. }
  8023. sum += wval; /* Checksum treats all EEPROM data as words. */
  8024. }
  8025. /*
  8026. * Read the checksum word which will be compared against 'sum'
  8027. * by the caller. Word field already swapped.
  8028. */
  8029. *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
  8030. return sum;
  8031. }
  8032. static int AscTestExternalLram(ASC_DVC_VAR *asc_dvc)
  8033. {
  8034. PortAddr iop_base;
  8035. ushort q_addr;
  8036. ushort saved_word;
  8037. int sta;
  8038. iop_base = asc_dvc->iop_base;
  8039. sta = 0;
  8040. q_addr = ASC_QNO_TO_QADDR(241);
  8041. saved_word = AscReadLramWord(iop_base, q_addr);
  8042. AscSetChipLramAddr(iop_base, q_addr);
  8043. AscSetChipLramData(iop_base, 0x55AA);
  8044. mdelay(10);
  8045. AscSetChipLramAddr(iop_base, q_addr);
  8046. if (AscGetChipLramData(iop_base) == 0x55AA) {
  8047. sta = 1;
  8048. AscWriteLramWord(iop_base, q_addr, saved_word);
  8049. }
  8050. return (sta);
  8051. }
  8052. static void AscWaitEEPWrite(void)
  8053. {
  8054. mdelay(20);
  8055. }
  8056. static int AscWriteEEPDataReg(PortAddr iop_base, ushort data_reg)
  8057. {
  8058. ushort read_back;
  8059. int retry;
  8060. retry = 0;
  8061. while (true) {
  8062. AscSetChipEEPData(iop_base, data_reg);
  8063. mdelay(1);
  8064. read_back = AscGetChipEEPData(iop_base);
  8065. if (read_back == data_reg) {
  8066. return (1);
  8067. }
  8068. if (retry++ > ASC_EEP_MAX_RETRY) {
  8069. return (0);
  8070. }
  8071. }
  8072. }
  8073. static ushort AscWriteEEPWord(PortAddr iop_base, uchar addr, ushort word_val)
  8074. {
  8075. ushort read_wval;
  8076. read_wval = AscReadEEPWord(iop_base, addr);
  8077. if (read_wval != word_val) {
  8078. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_ABLE);
  8079. AscWaitEEPRead();
  8080. AscWriteEEPDataReg(iop_base, word_val);
  8081. AscWaitEEPRead();
  8082. AscWriteEEPCmdReg(iop_base,
  8083. (uchar)((uchar)ASC_EEP_CMD_WRITE | addr));
  8084. AscWaitEEPWrite();
  8085. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
  8086. AscWaitEEPRead();
  8087. return (AscReadEEPWord(iop_base, addr));
  8088. }
  8089. return (read_wval);
  8090. }
  8091. static int AscSetEEPConfigOnce(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
  8092. ushort bus_type)
  8093. {
  8094. int n_error;
  8095. ushort *wbuf;
  8096. ushort word;
  8097. ushort sum;
  8098. int s_addr;
  8099. int cfg_beg;
  8100. int cfg_end;
  8101. int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
  8102. wbuf = (ushort *)cfg_buf;
  8103. n_error = 0;
  8104. sum = 0;
  8105. /* Write two config words; AscWriteEEPWord() will swap bytes. */
  8106. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  8107. sum += *wbuf;
  8108. if (*wbuf != AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
  8109. n_error++;
  8110. }
  8111. }
  8112. if (bus_type & ASC_IS_VL) {
  8113. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  8114. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  8115. } else {
  8116. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  8117. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  8118. }
  8119. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  8120. if (s_addr <= uchar_end_in_config) {
  8121. /*
  8122. * This is a char field. Swap char fields before they are
  8123. * swapped again by AscWriteEEPWord().
  8124. */
  8125. word = cpu_to_le16(*wbuf);
  8126. if (word !=
  8127. AscWriteEEPWord(iop_base, (uchar)s_addr, word)) {
  8128. n_error++;
  8129. }
  8130. } else {
  8131. /* Don't swap word field at the end - cntl field. */
  8132. if (*wbuf !=
  8133. AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
  8134. n_error++;
  8135. }
  8136. }
  8137. sum += *wbuf; /* Checksum calculated from word values. */
  8138. }
  8139. /* Write checksum word. It will be swapped by AscWriteEEPWord(). */
  8140. *wbuf = sum;
  8141. if (sum != AscWriteEEPWord(iop_base, (uchar)s_addr, sum)) {
  8142. n_error++;
  8143. }
  8144. /* Read EEPROM back again. */
  8145. wbuf = (ushort *)cfg_buf;
  8146. /*
  8147. * Read two config words; Byte-swapping done by AscReadEEPWord().
  8148. */
  8149. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  8150. if (*wbuf != AscReadEEPWord(iop_base, (uchar)s_addr)) {
  8151. n_error++;
  8152. }
  8153. }
  8154. if (bus_type & ASC_IS_VL) {
  8155. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  8156. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  8157. } else {
  8158. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  8159. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  8160. }
  8161. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  8162. if (s_addr <= uchar_end_in_config) {
  8163. /*
  8164. * Swap all char fields. Must unswap bytes already swapped
  8165. * by AscReadEEPWord().
  8166. */
  8167. word =
  8168. le16_to_cpu(AscReadEEPWord
  8169. (iop_base, (uchar)s_addr));
  8170. } else {
  8171. /* Don't swap word field at the end - cntl field. */
  8172. word = AscReadEEPWord(iop_base, (uchar)s_addr);
  8173. }
  8174. if (*wbuf != word) {
  8175. n_error++;
  8176. }
  8177. }
  8178. /* Read checksum; Byte swapping not needed. */
  8179. if (AscReadEEPWord(iop_base, (uchar)s_addr) != sum) {
  8180. n_error++;
  8181. }
  8182. return n_error;
  8183. }
  8184. static int AscSetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
  8185. ushort bus_type)
  8186. {
  8187. int retry;
  8188. int n_error;
  8189. retry = 0;
  8190. while (true) {
  8191. if ((n_error = AscSetEEPConfigOnce(iop_base, cfg_buf,
  8192. bus_type)) == 0) {
  8193. break;
  8194. }
  8195. if (++retry > ASC_EEP_MAX_RETRY) {
  8196. break;
  8197. }
  8198. }
  8199. return n_error;
  8200. }
  8201. static int AscInitFromEEP(ASC_DVC_VAR *asc_dvc)
  8202. {
  8203. ASCEEP_CONFIG eep_config_buf;
  8204. ASCEEP_CONFIG *eep_config;
  8205. PortAddr iop_base;
  8206. ushort chksum;
  8207. ushort warn_code;
  8208. ushort cfg_msw, cfg_lsw;
  8209. int i;
  8210. int write_eep = 0;
  8211. iop_base = asc_dvc->iop_base;
  8212. warn_code = 0;
  8213. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0x00FE);
  8214. AscStopQueueExe(iop_base);
  8215. if ((AscStopChip(iop_base)) ||
  8216. (AscGetChipScsiCtrl(iop_base) != 0)) {
  8217. asc_dvc->init_state |= ASC_INIT_RESET_SCSI_DONE;
  8218. AscResetChipAndScsiBus(asc_dvc);
  8219. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  8220. }
  8221. if (!AscIsChipHalted(iop_base)) {
  8222. asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
  8223. return (warn_code);
  8224. }
  8225. AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
  8226. if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
  8227. asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
  8228. return (warn_code);
  8229. }
  8230. eep_config = (ASCEEP_CONFIG *)&eep_config_buf;
  8231. cfg_msw = AscGetChipCfgMsw(iop_base);
  8232. cfg_lsw = AscGetChipCfgLsw(iop_base);
  8233. if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
  8234. cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  8235. warn_code |= ASC_WARN_CFG_MSW_RECOVER;
  8236. AscSetChipCfgMsw(iop_base, cfg_msw);
  8237. }
  8238. chksum = AscGetEEPConfig(iop_base, eep_config, asc_dvc->bus_type);
  8239. ASC_DBG(1, "chksum 0x%x\n", chksum);
  8240. if (chksum == 0) {
  8241. chksum = 0xaa55;
  8242. }
  8243. if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
  8244. warn_code |= ASC_WARN_AUTO_CONFIG;
  8245. if (asc_dvc->cfg->chip_version == 3) {
  8246. if (eep_config->cfg_lsw != cfg_lsw) {
  8247. warn_code |= ASC_WARN_EEPROM_RECOVER;
  8248. eep_config->cfg_lsw =
  8249. AscGetChipCfgLsw(iop_base);
  8250. }
  8251. if (eep_config->cfg_msw != cfg_msw) {
  8252. warn_code |= ASC_WARN_EEPROM_RECOVER;
  8253. eep_config->cfg_msw =
  8254. AscGetChipCfgMsw(iop_base);
  8255. }
  8256. }
  8257. }
  8258. eep_config->cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  8259. eep_config->cfg_lsw |= ASC_CFG0_HOST_INT_ON;
  8260. ASC_DBG(1, "eep_config->chksum 0x%x\n", eep_config->chksum);
  8261. if (chksum != eep_config->chksum) {
  8262. if (AscGetChipVersion(iop_base, asc_dvc->bus_type) ==
  8263. ASC_CHIP_VER_PCI_ULTRA_3050) {
  8264. ASC_DBG(1, "chksum error ignored; EEPROM-less board\n");
  8265. eep_config->init_sdtr = 0xFF;
  8266. eep_config->disc_enable = 0xFF;
  8267. eep_config->start_motor = 0xFF;
  8268. eep_config->use_cmd_qng = 0;
  8269. eep_config->max_total_qng = 0xF0;
  8270. eep_config->max_tag_qng = 0x20;
  8271. eep_config->cntl = 0xBFFF;
  8272. ASC_EEP_SET_CHIP_ID(eep_config, 7);
  8273. eep_config->no_scam = 0;
  8274. eep_config->adapter_info[0] = 0;
  8275. eep_config->adapter_info[1] = 0;
  8276. eep_config->adapter_info[2] = 0;
  8277. eep_config->adapter_info[3] = 0;
  8278. eep_config->adapter_info[4] = 0;
  8279. /* Indicate EEPROM-less board. */
  8280. eep_config->adapter_info[5] = 0xBB;
  8281. } else {
  8282. ASC_PRINT
  8283. ("AscInitFromEEP: EEPROM checksum error; Will try to re-write EEPROM.\n");
  8284. write_eep = 1;
  8285. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  8286. }
  8287. }
  8288. asc_dvc->cfg->sdtr_enable = eep_config->init_sdtr;
  8289. asc_dvc->cfg->disc_enable = eep_config->disc_enable;
  8290. asc_dvc->cfg->cmd_qng_enabled = eep_config->use_cmd_qng;
  8291. asc_dvc->cfg->isa_dma_speed = ASC_EEP_GET_DMA_SPD(eep_config);
  8292. asc_dvc->start_motor = eep_config->start_motor;
  8293. asc_dvc->dvc_cntl = eep_config->cntl;
  8294. asc_dvc->no_scam = eep_config->no_scam;
  8295. asc_dvc->cfg->adapter_info[0] = eep_config->adapter_info[0];
  8296. asc_dvc->cfg->adapter_info[1] = eep_config->adapter_info[1];
  8297. asc_dvc->cfg->adapter_info[2] = eep_config->adapter_info[2];
  8298. asc_dvc->cfg->adapter_info[3] = eep_config->adapter_info[3];
  8299. asc_dvc->cfg->adapter_info[4] = eep_config->adapter_info[4];
  8300. asc_dvc->cfg->adapter_info[5] = eep_config->adapter_info[5];
  8301. if (!AscTestExternalLram(asc_dvc)) {
  8302. if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) ==
  8303. ASC_IS_PCI_ULTRA)) {
  8304. eep_config->max_total_qng =
  8305. ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG;
  8306. eep_config->max_tag_qng =
  8307. ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG;
  8308. } else {
  8309. eep_config->cfg_msw |= 0x0800;
  8310. cfg_msw |= 0x0800;
  8311. AscSetChipCfgMsw(iop_base, cfg_msw);
  8312. eep_config->max_total_qng = ASC_MAX_PCI_INRAM_TOTAL_QNG;
  8313. eep_config->max_tag_qng = ASC_MAX_INRAM_TAG_QNG;
  8314. }
  8315. } else {
  8316. }
  8317. if (eep_config->max_total_qng < ASC_MIN_TOTAL_QNG) {
  8318. eep_config->max_total_qng = ASC_MIN_TOTAL_QNG;
  8319. }
  8320. if (eep_config->max_total_qng > ASC_MAX_TOTAL_QNG) {
  8321. eep_config->max_total_qng = ASC_MAX_TOTAL_QNG;
  8322. }
  8323. if (eep_config->max_tag_qng > eep_config->max_total_qng) {
  8324. eep_config->max_tag_qng = eep_config->max_total_qng;
  8325. }
  8326. if (eep_config->max_tag_qng < ASC_MIN_TAG_Q_PER_DVC) {
  8327. eep_config->max_tag_qng = ASC_MIN_TAG_Q_PER_DVC;
  8328. }
  8329. asc_dvc->max_total_qng = eep_config->max_total_qng;
  8330. if ((eep_config->use_cmd_qng & eep_config->disc_enable) !=
  8331. eep_config->use_cmd_qng) {
  8332. eep_config->disc_enable = eep_config->use_cmd_qng;
  8333. warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
  8334. }
  8335. ASC_EEP_SET_CHIP_ID(eep_config,
  8336. ASC_EEP_GET_CHIP_ID(eep_config) & ASC_MAX_TID);
  8337. asc_dvc->cfg->chip_scsi_id = ASC_EEP_GET_CHIP_ID(eep_config);
  8338. if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) &&
  8339. !(asc_dvc->dvc_cntl & ASC_CNTL_SDTR_ENABLE_ULTRA)) {
  8340. asc_dvc->min_sdtr_index = ASC_SDTR_ULTRA_PCI_10MB_INDEX;
  8341. }
  8342. for (i = 0; i <= ASC_MAX_TID; i++) {
  8343. asc_dvc->dos_int13_table[i] = eep_config->dos_int13_table[i];
  8344. asc_dvc->cfg->max_tag_qng[i] = eep_config->max_tag_qng;
  8345. asc_dvc->cfg->sdtr_period_offset[i] =
  8346. (uchar)(ASC_DEF_SDTR_OFFSET |
  8347. (asc_dvc->min_sdtr_index << 4));
  8348. }
  8349. eep_config->cfg_msw = AscGetChipCfgMsw(iop_base);
  8350. if (write_eep) {
  8351. if ((i = AscSetEEPConfig(iop_base, eep_config,
  8352. asc_dvc->bus_type)) != 0) {
  8353. ASC_PRINT1
  8354. ("AscInitFromEEP: Failed to re-write EEPROM with %d errors.\n",
  8355. i);
  8356. } else {
  8357. ASC_PRINT
  8358. ("AscInitFromEEP: Successfully re-wrote EEPROM.\n");
  8359. }
  8360. }
  8361. return (warn_code);
  8362. }
  8363. static int AscInitGetConfig(struct Scsi_Host *shost)
  8364. {
  8365. struct asc_board *board = shost_priv(shost);
  8366. ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
  8367. unsigned short warn_code = 0;
  8368. asc_dvc->init_state = ASC_INIT_STATE_BEG_GET_CFG;
  8369. if (asc_dvc->err_code != 0)
  8370. return asc_dvc->err_code;
  8371. if (AscFindSignature(asc_dvc->iop_base)) {
  8372. AscInitAscDvcVar(asc_dvc);
  8373. warn_code = AscInitFromEEP(asc_dvc);
  8374. asc_dvc->init_state |= ASC_INIT_STATE_END_GET_CFG;
  8375. if (asc_dvc->scsi_reset_wait > ASC_MAX_SCSI_RESET_WAIT)
  8376. asc_dvc->scsi_reset_wait = ASC_MAX_SCSI_RESET_WAIT;
  8377. } else {
  8378. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  8379. }
  8380. switch (warn_code) {
  8381. case 0: /* No error */
  8382. break;
  8383. case ASC_WARN_IO_PORT_ROTATE:
  8384. shost_printk(KERN_WARNING, shost, "I/O port address "
  8385. "modified\n");
  8386. break;
  8387. case ASC_WARN_AUTO_CONFIG:
  8388. shost_printk(KERN_WARNING, shost, "I/O port increment switch "
  8389. "enabled\n");
  8390. break;
  8391. case ASC_WARN_EEPROM_CHKSUM:
  8392. shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
  8393. break;
  8394. case ASC_WARN_IRQ_MODIFIED:
  8395. shost_printk(KERN_WARNING, shost, "IRQ modified\n");
  8396. break;
  8397. case ASC_WARN_CMD_QNG_CONFLICT:
  8398. shost_printk(KERN_WARNING, shost, "tag queuing enabled w/o "
  8399. "disconnects\n");
  8400. break;
  8401. default:
  8402. shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
  8403. warn_code);
  8404. break;
  8405. }
  8406. if (asc_dvc->err_code != 0)
  8407. shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
  8408. "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
  8409. return asc_dvc->err_code;
  8410. }
  8411. static int AscInitSetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
  8412. {
  8413. struct asc_board *board = shost_priv(shost);
  8414. ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
  8415. PortAddr iop_base = asc_dvc->iop_base;
  8416. unsigned short cfg_msw;
  8417. unsigned short warn_code = 0;
  8418. asc_dvc->init_state |= ASC_INIT_STATE_BEG_SET_CFG;
  8419. if (asc_dvc->err_code != 0)
  8420. return asc_dvc->err_code;
  8421. if (!AscFindSignature(asc_dvc->iop_base)) {
  8422. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  8423. return asc_dvc->err_code;
  8424. }
  8425. cfg_msw = AscGetChipCfgMsw(iop_base);
  8426. if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
  8427. cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  8428. warn_code |= ASC_WARN_CFG_MSW_RECOVER;
  8429. AscSetChipCfgMsw(iop_base, cfg_msw);
  8430. }
  8431. if ((asc_dvc->cfg->cmd_qng_enabled & asc_dvc->cfg->disc_enable) !=
  8432. asc_dvc->cfg->cmd_qng_enabled) {
  8433. asc_dvc->cfg->disc_enable = asc_dvc->cfg->cmd_qng_enabled;
  8434. warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
  8435. }
  8436. if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
  8437. warn_code |= ASC_WARN_AUTO_CONFIG;
  8438. }
  8439. #ifdef CONFIG_PCI
  8440. if (asc_dvc->bus_type & ASC_IS_PCI) {
  8441. cfg_msw &= 0xFFC0;
  8442. AscSetChipCfgMsw(iop_base, cfg_msw);
  8443. if ((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) {
  8444. } else {
  8445. if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
  8446. (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
  8447. asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_IF_NOT_DWB;
  8448. asc_dvc->bug_fix_cntl |=
  8449. ASC_BUG_FIX_ASYN_USE_SYN;
  8450. }
  8451. }
  8452. } else
  8453. #endif /* CONFIG_PCI */
  8454. if (asc_dvc->bus_type == ASC_IS_ISAPNP) {
  8455. if (AscGetChipVersion(iop_base, asc_dvc->bus_type)
  8456. == ASC_CHIP_VER_ASYN_BUG) {
  8457. asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_ASYN_USE_SYN;
  8458. }
  8459. }
  8460. if (AscSetChipScsiID(iop_base, asc_dvc->cfg->chip_scsi_id) !=
  8461. asc_dvc->cfg->chip_scsi_id) {
  8462. asc_dvc->err_code |= ASC_IERR_SET_SCSI_ID;
  8463. }
  8464. #ifdef CONFIG_ISA
  8465. if (asc_dvc->bus_type & ASC_IS_ISA) {
  8466. AscSetIsaDmaChannel(iop_base, asc_dvc->cfg->isa_dma_channel);
  8467. AscSetIsaDmaSpeed(iop_base, asc_dvc->cfg->isa_dma_speed);
  8468. }
  8469. #endif /* CONFIG_ISA */
  8470. asc_dvc->init_state |= ASC_INIT_STATE_END_SET_CFG;
  8471. switch (warn_code) {
  8472. case 0: /* No error. */
  8473. break;
  8474. case ASC_WARN_IO_PORT_ROTATE:
  8475. shost_printk(KERN_WARNING, shost, "I/O port address "
  8476. "modified\n");
  8477. break;
  8478. case ASC_WARN_AUTO_CONFIG:
  8479. shost_printk(KERN_WARNING, shost, "I/O port increment switch "
  8480. "enabled\n");
  8481. break;
  8482. case ASC_WARN_EEPROM_CHKSUM:
  8483. shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
  8484. break;
  8485. case ASC_WARN_IRQ_MODIFIED:
  8486. shost_printk(KERN_WARNING, shost, "IRQ modified\n");
  8487. break;
  8488. case ASC_WARN_CMD_QNG_CONFLICT:
  8489. shost_printk(KERN_WARNING, shost, "tag queuing w/o "
  8490. "disconnects\n");
  8491. break;
  8492. default:
  8493. shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
  8494. warn_code);
  8495. break;
  8496. }
  8497. if (asc_dvc->err_code != 0)
  8498. shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
  8499. "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
  8500. return asc_dvc->err_code;
  8501. }
  8502. /*
  8503. * EEPROM Configuration.
  8504. *
  8505. * All drivers should use this structure to set the default EEPROM
  8506. * configuration. The BIOS now uses this structure when it is built.
  8507. * Additional structure information can be found in a_condor.h where
  8508. * the structure is defined.
  8509. *
  8510. * The *_Field_IsChar structs are needed to correct for endianness.
  8511. * These values are read from the board 16 bits at a time directly
  8512. * into the structs. Because some fields are char, the values will be
  8513. * in the wrong order. The *_Field_IsChar tells when to flip the
  8514. * bytes. Data read and written to PCI memory is automatically swapped
  8515. * on big-endian platforms so char fields read as words are actually being
  8516. * unswapped on big-endian platforms.
  8517. */
  8518. #ifdef CONFIG_PCI
  8519. static ADVEEP_3550_CONFIG Default_3550_EEPROM_Config = {
  8520. ADV_EEPROM_BIOS_ENABLE, /* cfg_lsw */
  8521. 0x0000, /* cfg_msw */
  8522. 0xFFFF, /* disc_enable */
  8523. 0xFFFF, /* wdtr_able */
  8524. 0xFFFF, /* sdtr_able */
  8525. 0xFFFF, /* start_motor */
  8526. 0xFFFF, /* tagqng_able */
  8527. 0xFFFF, /* bios_scan */
  8528. 0, /* scam_tolerant */
  8529. 7, /* adapter_scsi_id */
  8530. 0, /* bios_boot_delay */
  8531. 3, /* scsi_reset_delay */
  8532. 0, /* bios_id_lun */
  8533. 0, /* termination */
  8534. 0, /* reserved1 */
  8535. 0xFFE7, /* bios_ctrl */
  8536. 0xFFFF, /* ultra_able */
  8537. 0, /* reserved2 */
  8538. ASC_DEF_MAX_HOST_QNG, /* max_host_qng */
  8539. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  8540. 0, /* dvc_cntl */
  8541. 0, /* bug_fix */
  8542. 0, /* serial_number_word1 */
  8543. 0, /* serial_number_word2 */
  8544. 0, /* serial_number_word3 */
  8545. 0, /* check_sum */
  8546. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  8547. , /* oem_name[16] */
  8548. 0, /* dvc_err_code */
  8549. 0, /* adv_err_code */
  8550. 0, /* adv_err_addr */
  8551. 0, /* saved_dvc_err_code */
  8552. 0, /* saved_adv_err_code */
  8553. 0, /* saved_adv_err_addr */
  8554. 0 /* num_of_err */
  8555. };
  8556. static ADVEEP_3550_CONFIG ADVEEP_3550_Config_Field_IsChar = {
  8557. 0, /* cfg_lsw */
  8558. 0, /* cfg_msw */
  8559. 0, /* -disc_enable */
  8560. 0, /* wdtr_able */
  8561. 0, /* sdtr_able */
  8562. 0, /* start_motor */
  8563. 0, /* tagqng_able */
  8564. 0, /* bios_scan */
  8565. 0, /* scam_tolerant */
  8566. 1, /* adapter_scsi_id */
  8567. 1, /* bios_boot_delay */
  8568. 1, /* scsi_reset_delay */
  8569. 1, /* bios_id_lun */
  8570. 1, /* termination */
  8571. 1, /* reserved1 */
  8572. 0, /* bios_ctrl */
  8573. 0, /* ultra_able */
  8574. 0, /* reserved2 */
  8575. 1, /* max_host_qng */
  8576. 1, /* max_dvc_qng */
  8577. 0, /* dvc_cntl */
  8578. 0, /* bug_fix */
  8579. 0, /* serial_number_word1 */
  8580. 0, /* serial_number_word2 */
  8581. 0, /* serial_number_word3 */
  8582. 0, /* check_sum */
  8583. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  8584. , /* oem_name[16] */
  8585. 0, /* dvc_err_code */
  8586. 0, /* adv_err_code */
  8587. 0, /* adv_err_addr */
  8588. 0, /* saved_dvc_err_code */
  8589. 0, /* saved_adv_err_code */
  8590. 0, /* saved_adv_err_addr */
  8591. 0 /* num_of_err */
  8592. };
  8593. static ADVEEP_38C0800_CONFIG Default_38C0800_EEPROM_Config = {
  8594. ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
  8595. 0x0000, /* 01 cfg_msw */
  8596. 0xFFFF, /* 02 disc_enable */
  8597. 0xFFFF, /* 03 wdtr_able */
  8598. 0x4444, /* 04 sdtr_speed1 */
  8599. 0xFFFF, /* 05 start_motor */
  8600. 0xFFFF, /* 06 tagqng_able */
  8601. 0xFFFF, /* 07 bios_scan */
  8602. 0, /* 08 scam_tolerant */
  8603. 7, /* 09 adapter_scsi_id */
  8604. 0, /* bios_boot_delay */
  8605. 3, /* 10 scsi_reset_delay */
  8606. 0, /* bios_id_lun */
  8607. 0, /* 11 termination_se */
  8608. 0, /* termination_lvd */
  8609. 0xFFE7, /* 12 bios_ctrl */
  8610. 0x4444, /* 13 sdtr_speed2 */
  8611. 0x4444, /* 14 sdtr_speed3 */
  8612. ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
  8613. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  8614. 0, /* 16 dvc_cntl */
  8615. 0x4444, /* 17 sdtr_speed4 */
  8616. 0, /* 18 serial_number_word1 */
  8617. 0, /* 19 serial_number_word2 */
  8618. 0, /* 20 serial_number_word3 */
  8619. 0, /* 21 check_sum */
  8620. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  8621. , /* 22-29 oem_name[16] */
  8622. 0, /* 30 dvc_err_code */
  8623. 0, /* 31 adv_err_code */
  8624. 0, /* 32 adv_err_addr */
  8625. 0, /* 33 saved_dvc_err_code */
  8626. 0, /* 34 saved_adv_err_code */
  8627. 0, /* 35 saved_adv_err_addr */
  8628. 0, /* 36 reserved */
  8629. 0, /* 37 reserved */
  8630. 0, /* 38 reserved */
  8631. 0, /* 39 reserved */
  8632. 0, /* 40 reserved */
  8633. 0, /* 41 reserved */
  8634. 0, /* 42 reserved */
  8635. 0, /* 43 reserved */
  8636. 0, /* 44 reserved */
  8637. 0, /* 45 reserved */
  8638. 0, /* 46 reserved */
  8639. 0, /* 47 reserved */
  8640. 0, /* 48 reserved */
  8641. 0, /* 49 reserved */
  8642. 0, /* 50 reserved */
  8643. 0, /* 51 reserved */
  8644. 0, /* 52 reserved */
  8645. 0, /* 53 reserved */
  8646. 0, /* 54 reserved */
  8647. 0, /* 55 reserved */
  8648. 0, /* 56 cisptr_lsw */
  8649. 0, /* 57 cisprt_msw */
  8650. PCI_VENDOR_ID_ASP, /* 58 subsysvid */
  8651. PCI_DEVICE_ID_38C0800_REV1, /* 59 subsysid */
  8652. 0, /* 60 reserved */
  8653. 0, /* 61 reserved */
  8654. 0, /* 62 reserved */
  8655. 0 /* 63 reserved */
  8656. };
  8657. static ADVEEP_38C0800_CONFIG ADVEEP_38C0800_Config_Field_IsChar = {
  8658. 0, /* 00 cfg_lsw */
  8659. 0, /* 01 cfg_msw */
  8660. 0, /* 02 disc_enable */
  8661. 0, /* 03 wdtr_able */
  8662. 0, /* 04 sdtr_speed1 */
  8663. 0, /* 05 start_motor */
  8664. 0, /* 06 tagqng_able */
  8665. 0, /* 07 bios_scan */
  8666. 0, /* 08 scam_tolerant */
  8667. 1, /* 09 adapter_scsi_id */
  8668. 1, /* bios_boot_delay */
  8669. 1, /* 10 scsi_reset_delay */
  8670. 1, /* bios_id_lun */
  8671. 1, /* 11 termination_se */
  8672. 1, /* termination_lvd */
  8673. 0, /* 12 bios_ctrl */
  8674. 0, /* 13 sdtr_speed2 */
  8675. 0, /* 14 sdtr_speed3 */
  8676. 1, /* 15 max_host_qng */
  8677. 1, /* max_dvc_qng */
  8678. 0, /* 16 dvc_cntl */
  8679. 0, /* 17 sdtr_speed4 */
  8680. 0, /* 18 serial_number_word1 */
  8681. 0, /* 19 serial_number_word2 */
  8682. 0, /* 20 serial_number_word3 */
  8683. 0, /* 21 check_sum */
  8684. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  8685. , /* 22-29 oem_name[16] */
  8686. 0, /* 30 dvc_err_code */
  8687. 0, /* 31 adv_err_code */
  8688. 0, /* 32 adv_err_addr */
  8689. 0, /* 33 saved_dvc_err_code */
  8690. 0, /* 34 saved_adv_err_code */
  8691. 0, /* 35 saved_adv_err_addr */
  8692. 0, /* 36 reserved */
  8693. 0, /* 37 reserved */
  8694. 0, /* 38 reserved */
  8695. 0, /* 39 reserved */
  8696. 0, /* 40 reserved */
  8697. 0, /* 41 reserved */
  8698. 0, /* 42 reserved */
  8699. 0, /* 43 reserved */
  8700. 0, /* 44 reserved */
  8701. 0, /* 45 reserved */
  8702. 0, /* 46 reserved */
  8703. 0, /* 47 reserved */
  8704. 0, /* 48 reserved */
  8705. 0, /* 49 reserved */
  8706. 0, /* 50 reserved */
  8707. 0, /* 51 reserved */
  8708. 0, /* 52 reserved */
  8709. 0, /* 53 reserved */
  8710. 0, /* 54 reserved */
  8711. 0, /* 55 reserved */
  8712. 0, /* 56 cisptr_lsw */
  8713. 0, /* 57 cisprt_msw */
  8714. 0, /* 58 subsysvid */
  8715. 0, /* 59 subsysid */
  8716. 0, /* 60 reserved */
  8717. 0, /* 61 reserved */
  8718. 0, /* 62 reserved */
  8719. 0 /* 63 reserved */
  8720. };
  8721. static ADVEEP_38C1600_CONFIG Default_38C1600_EEPROM_Config = {
  8722. ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
  8723. 0x0000, /* 01 cfg_msw */
  8724. 0xFFFF, /* 02 disc_enable */
  8725. 0xFFFF, /* 03 wdtr_able */
  8726. 0x5555, /* 04 sdtr_speed1 */
  8727. 0xFFFF, /* 05 start_motor */
  8728. 0xFFFF, /* 06 tagqng_able */
  8729. 0xFFFF, /* 07 bios_scan */
  8730. 0, /* 08 scam_tolerant */
  8731. 7, /* 09 adapter_scsi_id */
  8732. 0, /* bios_boot_delay */
  8733. 3, /* 10 scsi_reset_delay */
  8734. 0, /* bios_id_lun */
  8735. 0, /* 11 termination_se */
  8736. 0, /* termination_lvd */
  8737. 0xFFE7, /* 12 bios_ctrl */
  8738. 0x5555, /* 13 sdtr_speed2 */
  8739. 0x5555, /* 14 sdtr_speed3 */
  8740. ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
  8741. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  8742. 0, /* 16 dvc_cntl */
  8743. 0x5555, /* 17 sdtr_speed4 */
  8744. 0, /* 18 serial_number_word1 */
  8745. 0, /* 19 serial_number_word2 */
  8746. 0, /* 20 serial_number_word3 */
  8747. 0, /* 21 check_sum */
  8748. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  8749. , /* 22-29 oem_name[16] */
  8750. 0, /* 30 dvc_err_code */
  8751. 0, /* 31 adv_err_code */
  8752. 0, /* 32 adv_err_addr */
  8753. 0, /* 33 saved_dvc_err_code */
  8754. 0, /* 34 saved_adv_err_code */
  8755. 0, /* 35 saved_adv_err_addr */
  8756. 0, /* 36 reserved */
  8757. 0, /* 37 reserved */
  8758. 0, /* 38 reserved */
  8759. 0, /* 39 reserved */
  8760. 0, /* 40 reserved */
  8761. 0, /* 41 reserved */
  8762. 0, /* 42 reserved */
  8763. 0, /* 43 reserved */
  8764. 0, /* 44 reserved */
  8765. 0, /* 45 reserved */
  8766. 0, /* 46 reserved */
  8767. 0, /* 47 reserved */
  8768. 0, /* 48 reserved */
  8769. 0, /* 49 reserved */
  8770. 0, /* 50 reserved */
  8771. 0, /* 51 reserved */
  8772. 0, /* 52 reserved */
  8773. 0, /* 53 reserved */
  8774. 0, /* 54 reserved */
  8775. 0, /* 55 reserved */
  8776. 0, /* 56 cisptr_lsw */
  8777. 0, /* 57 cisprt_msw */
  8778. PCI_VENDOR_ID_ASP, /* 58 subsysvid */
  8779. PCI_DEVICE_ID_38C1600_REV1, /* 59 subsysid */
  8780. 0, /* 60 reserved */
  8781. 0, /* 61 reserved */
  8782. 0, /* 62 reserved */
  8783. 0 /* 63 reserved */
  8784. };
  8785. static ADVEEP_38C1600_CONFIG ADVEEP_38C1600_Config_Field_IsChar = {
  8786. 0, /* 00 cfg_lsw */
  8787. 0, /* 01 cfg_msw */
  8788. 0, /* 02 disc_enable */
  8789. 0, /* 03 wdtr_able */
  8790. 0, /* 04 sdtr_speed1 */
  8791. 0, /* 05 start_motor */
  8792. 0, /* 06 tagqng_able */
  8793. 0, /* 07 bios_scan */
  8794. 0, /* 08 scam_tolerant */
  8795. 1, /* 09 adapter_scsi_id */
  8796. 1, /* bios_boot_delay */
  8797. 1, /* 10 scsi_reset_delay */
  8798. 1, /* bios_id_lun */
  8799. 1, /* 11 termination_se */
  8800. 1, /* termination_lvd */
  8801. 0, /* 12 bios_ctrl */
  8802. 0, /* 13 sdtr_speed2 */
  8803. 0, /* 14 sdtr_speed3 */
  8804. 1, /* 15 max_host_qng */
  8805. 1, /* max_dvc_qng */
  8806. 0, /* 16 dvc_cntl */
  8807. 0, /* 17 sdtr_speed4 */
  8808. 0, /* 18 serial_number_word1 */
  8809. 0, /* 19 serial_number_word2 */
  8810. 0, /* 20 serial_number_word3 */
  8811. 0, /* 21 check_sum */
  8812. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  8813. , /* 22-29 oem_name[16] */
  8814. 0, /* 30 dvc_err_code */
  8815. 0, /* 31 adv_err_code */
  8816. 0, /* 32 adv_err_addr */
  8817. 0, /* 33 saved_dvc_err_code */
  8818. 0, /* 34 saved_adv_err_code */
  8819. 0, /* 35 saved_adv_err_addr */
  8820. 0, /* 36 reserved */
  8821. 0, /* 37 reserved */
  8822. 0, /* 38 reserved */
  8823. 0, /* 39 reserved */
  8824. 0, /* 40 reserved */
  8825. 0, /* 41 reserved */
  8826. 0, /* 42 reserved */
  8827. 0, /* 43 reserved */
  8828. 0, /* 44 reserved */
  8829. 0, /* 45 reserved */
  8830. 0, /* 46 reserved */
  8831. 0, /* 47 reserved */
  8832. 0, /* 48 reserved */
  8833. 0, /* 49 reserved */
  8834. 0, /* 50 reserved */
  8835. 0, /* 51 reserved */
  8836. 0, /* 52 reserved */
  8837. 0, /* 53 reserved */
  8838. 0, /* 54 reserved */
  8839. 0, /* 55 reserved */
  8840. 0, /* 56 cisptr_lsw */
  8841. 0, /* 57 cisprt_msw */
  8842. 0, /* 58 subsysvid */
  8843. 0, /* 59 subsysid */
  8844. 0, /* 60 reserved */
  8845. 0, /* 61 reserved */
  8846. 0, /* 62 reserved */
  8847. 0 /* 63 reserved */
  8848. };
  8849. /*
  8850. * Wait for EEPROM command to complete
  8851. */
  8852. static void AdvWaitEEPCmd(AdvPortAddr iop_base)
  8853. {
  8854. int eep_delay_ms;
  8855. for (eep_delay_ms = 0; eep_delay_ms < ADV_EEP_DELAY_MS; eep_delay_ms++) {
  8856. if (AdvReadWordRegister(iop_base, IOPW_EE_CMD) &
  8857. ASC_EEP_CMD_DONE) {
  8858. break;
  8859. }
  8860. mdelay(1);
  8861. }
  8862. if ((AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE) ==
  8863. 0)
  8864. BUG();
  8865. }
  8866. /*
  8867. * Read the EEPROM from specified location
  8868. */
  8869. static ushort AdvReadEEPWord(AdvPortAddr iop_base, int eep_word_addr)
  8870. {
  8871. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8872. ASC_EEP_CMD_READ | eep_word_addr);
  8873. AdvWaitEEPCmd(iop_base);
  8874. return AdvReadWordRegister(iop_base, IOPW_EE_DATA);
  8875. }
  8876. /*
  8877. * Write the EEPROM from 'cfg_buf'.
  8878. */
  8879. static void AdvSet3550EEPConfig(AdvPortAddr iop_base,
  8880. ADVEEP_3550_CONFIG *cfg_buf)
  8881. {
  8882. ushort *wbuf;
  8883. ushort addr, chksum;
  8884. ushort *charfields;
  8885. wbuf = (ushort *)cfg_buf;
  8886. charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
  8887. chksum = 0;
  8888. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  8889. AdvWaitEEPCmd(iop_base);
  8890. /*
  8891. * Write EEPROM from word 0 to word 20.
  8892. */
  8893. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  8894. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  8895. ushort word;
  8896. if (*charfields++) {
  8897. word = cpu_to_le16(*wbuf);
  8898. } else {
  8899. word = *wbuf;
  8900. }
  8901. chksum += *wbuf; /* Checksum is calculated from word values. */
  8902. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  8903. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8904. ASC_EEP_CMD_WRITE | addr);
  8905. AdvWaitEEPCmd(iop_base);
  8906. mdelay(ADV_EEP_DELAY_MS);
  8907. }
  8908. /*
  8909. * Write EEPROM checksum at word 21.
  8910. */
  8911. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  8912. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  8913. AdvWaitEEPCmd(iop_base);
  8914. wbuf++;
  8915. charfields++;
  8916. /*
  8917. * Write EEPROM OEM name at words 22 to 29.
  8918. */
  8919. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  8920. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  8921. ushort word;
  8922. if (*charfields++) {
  8923. word = cpu_to_le16(*wbuf);
  8924. } else {
  8925. word = *wbuf;
  8926. }
  8927. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  8928. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8929. ASC_EEP_CMD_WRITE | addr);
  8930. AdvWaitEEPCmd(iop_base);
  8931. }
  8932. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  8933. AdvWaitEEPCmd(iop_base);
  8934. }
  8935. /*
  8936. * Write the EEPROM from 'cfg_buf'.
  8937. */
  8938. static void AdvSet38C0800EEPConfig(AdvPortAddr iop_base,
  8939. ADVEEP_38C0800_CONFIG *cfg_buf)
  8940. {
  8941. ushort *wbuf;
  8942. ushort *charfields;
  8943. ushort addr, chksum;
  8944. wbuf = (ushort *)cfg_buf;
  8945. charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
  8946. chksum = 0;
  8947. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  8948. AdvWaitEEPCmd(iop_base);
  8949. /*
  8950. * Write EEPROM from word 0 to word 20.
  8951. */
  8952. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  8953. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  8954. ushort word;
  8955. if (*charfields++) {
  8956. word = cpu_to_le16(*wbuf);
  8957. } else {
  8958. word = *wbuf;
  8959. }
  8960. chksum += *wbuf; /* Checksum is calculated from word values. */
  8961. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  8962. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8963. ASC_EEP_CMD_WRITE | addr);
  8964. AdvWaitEEPCmd(iop_base);
  8965. mdelay(ADV_EEP_DELAY_MS);
  8966. }
  8967. /*
  8968. * Write EEPROM checksum at word 21.
  8969. */
  8970. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  8971. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  8972. AdvWaitEEPCmd(iop_base);
  8973. wbuf++;
  8974. charfields++;
  8975. /*
  8976. * Write EEPROM OEM name at words 22 to 29.
  8977. */
  8978. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  8979. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  8980. ushort word;
  8981. if (*charfields++) {
  8982. word = cpu_to_le16(*wbuf);
  8983. } else {
  8984. word = *wbuf;
  8985. }
  8986. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  8987. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  8988. ASC_EEP_CMD_WRITE | addr);
  8989. AdvWaitEEPCmd(iop_base);
  8990. }
  8991. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  8992. AdvWaitEEPCmd(iop_base);
  8993. }
  8994. /*
  8995. * Write the EEPROM from 'cfg_buf'.
  8996. */
  8997. static void AdvSet38C1600EEPConfig(AdvPortAddr iop_base,
  8998. ADVEEP_38C1600_CONFIG *cfg_buf)
  8999. {
  9000. ushort *wbuf;
  9001. ushort *charfields;
  9002. ushort addr, chksum;
  9003. wbuf = (ushort *)cfg_buf;
  9004. charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
  9005. chksum = 0;
  9006. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  9007. AdvWaitEEPCmd(iop_base);
  9008. /*
  9009. * Write EEPROM from word 0 to word 20.
  9010. */
  9011. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  9012. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  9013. ushort word;
  9014. if (*charfields++) {
  9015. word = cpu_to_le16(*wbuf);
  9016. } else {
  9017. word = *wbuf;
  9018. }
  9019. chksum += *wbuf; /* Checksum is calculated from word values. */
  9020. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9021. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9022. ASC_EEP_CMD_WRITE | addr);
  9023. AdvWaitEEPCmd(iop_base);
  9024. mdelay(ADV_EEP_DELAY_MS);
  9025. }
  9026. /*
  9027. * Write EEPROM checksum at word 21.
  9028. */
  9029. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  9030. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  9031. AdvWaitEEPCmd(iop_base);
  9032. wbuf++;
  9033. charfields++;
  9034. /*
  9035. * Write EEPROM OEM name at words 22 to 29.
  9036. */
  9037. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  9038. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  9039. ushort word;
  9040. if (*charfields++) {
  9041. word = cpu_to_le16(*wbuf);
  9042. } else {
  9043. word = *wbuf;
  9044. }
  9045. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9046. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9047. ASC_EEP_CMD_WRITE | addr);
  9048. AdvWaitEEPCmd(iop_base);
  9049. }
  9050. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  9051. AdvWaitEEPCmd(iop_base);
  9052. }
  9053. /*
  9054. * Read EEPROM configuration into the specified buffer.
  9055. *
  9056. * Return a checksum based on the EEPROM configuration read.
  9057. */
  9058. static ushort AdvGet3550EEPConfig(AdvPortAddr iop_base,
  9059. ADVEEP_3550_CONFIG *cfg_buf)
  9060. {
  9061. ushort wval, chksum;
  9062. ushort *wbuf;
  9063. int eep_addr;
  9064. ushort *charfields;
  9065. charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
  9066. wbuf = (ushort *)cfg_buf;
  9067. chksum = 0;
  9068. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  9069. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  9070. wval = AdvReadEEPWord(iop_base, eep_addr);
  9071. chksum += wval; /* Checksum is calculated from word values. */
  9072. if (*charfields++) {
  9073. *wbuf = le16_to_cpu(wval);
  9074. } else {
  9075. *wbuf = wval;
  9076. }
  9077. }
  9078. /* Read checksum word. */
  9079. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9080. wbuf++;
  9081. charfields++;
  9082. /* Read rest of EEPROM not covered by the checksum. */
  9083. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  9084. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  9085. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9086. if (*charfields++) {
  9087. *wbuf = le16_to_cpu(*wbuf);
  9088. }
  9089. }
  9090. return chksum;
  9091. }
  9092. /*
  9093. * Read EEPROM configuration into the specified buffer.
  9094. *
  9095. * Return a checksum based on the EEPROM configuration read.
  9096. */
  9097. static ushort AdvGet38C0800EEPConfig(AdvPortAddr iop_base,
  9098. ADVEEP_38C0800_CONFIG *cfg_buf)
  9099. {
  9100. ushort wval, chksum;
  9101. ushort *wbuf;
  9102. int eep_addr;
  9103. ushort *charfields;
  9104. charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
  9105. wbuf = (ushort *)cfg_buf;
  9106. chksum = 0;
  9107. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  9108. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  9109. wval = AdvReadEEPWord(iop_base, eep_addr);
  9110. chksum += wval; /* Checksum is calculated from word values. */
  9111. if (*charfields++) {
  9112. *wbuf = le16_to_cpu(wval);
  9113. } else {
  9114. *wbuf = wval;
  9115. }
  9116. }
  9117. /* Read checksum word. */
  9118. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9119. wbuf++;
  9120. charfields++;
  9121. /* Read rest of EEPROM not covered by the checksum. */
  9122. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  9123. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  9124. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9125. if (*charfields++) {
  9126. *wbuf = le16_to_cpu(*wbuf);
  9127. }
  9128. }
  9129. return chksum;
  9130. }
  9131. /*
  9132. * Read EEPROM configuration into the specified buffer.
  9133. *
  9134. * Return a checksum based on the EEPROM configuration read.
  9135. */
  9136. static ushort AdvGet38C1600EEPConfig(AdvPortAddr iop_base,
  9137. ADVEEP_38C1600_CONFIG *cfg_buf)
  9138. {
  9139. ushort wval, chksum;
  9140. ushort *wbuf;
  9141. int eep_addr;
  9142. ushort *charfields;
  9143. charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
  9144. wbuf = (ushort *)cfg_buf;
  9145. chksum = 0;
  9146. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  9147. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  9148. wval = AdvReadEEPWord(iop_base, eep_addr);
  9149. chksum += wval; /* Checksum is calculated from word values. */
  9150. if (*charfields++) {
  9151. *wbuf = le16_to_cpu(wval);
  9152. } else {
  9153. *wbuf = wval;
  9154. }
  9155. }
  9156. /* Read checksum word. */
  9157. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9158. wbuf++;
  9159. charfields++;
  9160. /* Read rest of EEPROM not covered by the checksum. */
  9161. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  9162. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  9163. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9164. if (*charfields++) {
  9165. *wbuf = le16_to_cpu(*wbuf);
  9166. }
  9167. }
  9168. return chksum;
  9169. }
  9170. /*
  9171. * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
  9172. * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
  9173. * all of this is done.
  9174. *
  9175. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  9176. *
  9177. * For a non-fatal error return a warning code. If there are no warnings
  9178. * then 0 is returned.
  9179. *
  9180. * Note: Chip is stopped on entry.
  9181. */
  9182. static int AdvInitFrom3550EEP(ADV_DVC_VAR *asc_dvc)
  9183. {
  9184. AdvPortAddr iop_base;
  9185. ushort warn_code;
  9186. ADVEEP_3550_CONFIG eep_config;
  9187. iop_base = asc_dvc->iop_base;
  9188. warn_code = 0;
  9189. /*
  9190. * Read the board's EEPROM configuration.
  9191. *
  9192. * Set default values if a bad checksum is found.
  9193. */
  9194. if (AdvGet3550EEPConfig(iop_base, &eep_config) != eep_config.check_sum) {
  9195. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  9196. /*
  9197. * Set EEPROM default values.
  9198. */
  9199. memcpy(&eep_config, &Default_3550_EEPROM_Config,
  9200. sizeof(ADVEEP_3550_CONFIG));
  9201. /*
  9202. * Assume the 6 byte board serial number that was read from
  9203. * EEPROM is correct even if the EEPROM checksum failed.
  9204. */
  9205. eep_config.serial_number_word3 =
  9206. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  9207. eep_config.serial_number_word2 =
  9208. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  9209. eep_config.serial_number_word1 =
  9210. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  9211. AdvSet3550EEPConfig(iop_base, &eep_config);
  9212. }
  9213. /*
  9214. * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
  9215. * EEPROM configuration that was read.
  9216. *
  9217. * This is the mapping of EEPROM fields to Adv Library fields.
  9218. */
  9219. asc_dvc->wdtr_able = eep_config.wdtr_able;
  9220. asc_dvc->sdtr_able = eep_config.sdtr_able;
  9221. asc_dvc->ultra_able = eep_config.ultra_able;
  9222. asc_dvc->tagqng_able = eep_config.tagqng_able;
  9223. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  9224. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9225. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9226. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
  9227. asc_dvc->start_motor = eep_config.start_motor;
  9228. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  9229. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  9230. asc_dvc->no_scam = eep_config.scam_tolerant;
  9231. asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
  9232. asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
  9233. asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
  9234. /*
  9235. * Set the host maximum queuing (max. 253, min. 16) and the per device
  9236. * maximum queuing (max. 63, min. 4).
  9237. */
  9238. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  9239. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9240. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  9241. /* If the value is zero, assume it is uninitialized. */
  9242. if (eep_config.max_host_qng == 0) {
  9243. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9244. } else {
  9245. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  9246. }
  9247. }
  9248. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  9249. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9250. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  9251. /* If the value is zero, assume it is uninitialized. */
  9252. if (eep_config.max_dvc_qng == 0) {
  9253. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9254. } else {
  9255. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  9256. }
  9257. }
  9258. /*
  9259. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  9260. * set 'max_dvc_qng' to 'max_host_qng'.
  9261. */
  9262. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  9263. eep_config.max_dvc_qng = eep_config.max_host_qng;
  9264. }
  9265. /*
  9266. * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
  9267. * values based on possibly adjusted EEPROM values.
  9268. */
  9269. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9270. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9271. /*
  9272. * If the EEPROM 'termination' field is set to automatic (0), then set
  9273. * the ADV_DVC_CFG 'termination' field to automatic also.
  9274. *
  9275. * If the termination is specified with a non-zero 'termination'
  9276. * value check that a legal value is set and set the ADV_DVC_CFG
  9277. * 'termination' field appropriately.
  9278. */
  9279. if (eep_config.termination == 0) {
  9280. asc_dvc->cfg->termination = 0; /* auto termination */
  9281. } else {
  9282. /* Enable manual control with low off / high off. */
  9283. if (eep_config.termination == 1) {
  9284. asc_dvc->cfg->termination = TERM_CTL_SEL;
  9285. /* Enable manual control with low off / high on. */
  9286. } else if (eep_config.termination == 2) {
  9287. asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H;
  9288. /* Enable manual control with low on / high on. */
  9289. } else if (eep_config.termination == 3) {
  9290. asc_dvc->cfg->termination =
  9291. TERM_CTL_SEL | TERM_CTL_H | TERM_CTL_L;
  9292. } else {
  9293. /*
  9294. * The EEPROM 'termination' field contains a bad value. Use
  9295. * automatic termination instead.
  9296. */
  9297. asc_dvc->cfg->termination = 0;
  9298. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9299. }
  9300. }
  9301. return warn_code;
  9302. }
  9303. /*
  9304. * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
  9305. * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
  9306. * all of this is done.
  9307. *
  9308. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  9309. *
  9310. * For a non-fatal error return a warning code. If there are no warnings
  9311. * then 0 is returned.
  9312. *
  9313. * Note: Chip is stopped on entry.
  9314. */
  9315. static int AdvInitFrom38C0800EEP(ADV_DVC_VAR *asc_dvc)
  9316. {
  9317. AdvPortAddr iop_base;
  9318. ushort warn_code;
  9319. ADVEEP_38C0800_CONFIG eep_config;
  9320. uchar tid, termination;
  9321. ushort sdtr_speed = 0;
  9322. iop_base = asc_dvc->iop_base;
  9323. warn_code = 0;
  9324. /*
  9325. * Read the board's EEPROM configuration.
  9326. *
  9327. * Set default values if a bad checksum is found.
  9328. */
  9329. if (AdvGet38C0800EEPConfig(iop_base, &eep_config) !=
  9330. eep_config.check_sum) {
  9331. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  9332. /*
  9333. * Set EEPROM default values.
  9334. */
  9335. memcpy(&eep_config, &Default_38C0800_EEPROM_Config,
  9336. sizeof(ADVEEP_38C0800_CONFIG));
  9337. /*
  9338. * Assume the 6 byte board serial number that was read from
  9339. * EEPROM is correct even if the EEPROM checksum failed.
  9340. */
  9341. eep_config.serial_number_word3 =
  9342. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  9343. eep_config.serial_number_word2 =
  9344. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  9345. eep_config.serial_number_word1 =
  9346. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  9347. AdvSet38C0800EEPConfig(iop_base, &eep_config);
  9348. }
  9349. /*
  9350. * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
  9351. * EEPROM configuration that was read.
  9352. *
  9353. * This is the mapping of EEPROM fields to Adv Library fields.
  9354. */
  9355. asc_dvc->wdtr_able = eep_config.wdtr_able;
  9356. asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
  9357. asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
  9358. asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
  9359. asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
  9360. asc_dvc->tagqng_able = eep_config.tagqng_able;
  9361. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  9362. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9363. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9364. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
  9365. asc_dvc->start_motor = eep_config.start_motor;
  9366. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  9367. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  9368. asc_dvc->no_scam = eep_config.scam_tolerant;
  9369. asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
  9370. asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
  9371. asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
  9372. /*
  9373. * For every Target ID if any of its 'sdtr_speed[1234]' bits
  9374. * are set, then set an 'sdtr_able' bit for it.
  9375. */
  9376. asc_dvc->sdtr_able = 0;
  9377. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  9378. if (tid == 0) {
  9379. sdtr_speed = asc_dvc->sdtr_speed1;
  9380. } else if (tid == 4) {
  9381. sdtr_speed = asc_dvc->sdtr_speed2;
  9382. } else if (tid == 8) {
  9383. sdtr_speed = asc_dvc->sdtr_speed3;
  9384. } else if (tid == 12) {
  9385. sdtr_speed = asc_dvc->sdtr_speed4;
  9386. }
  9387. if (sdtr_speed & ADV_MAX_TID) {
  9388. asc_dvc->sdtr_able |= (1 << tid);
  9389. }
  9390. sdtr_speed >>= 4;
  9391. }
  9392. /*
  9393. * Set the host maximum queuing (max. 253, min. 16) and the per device
  9394. * maximum queuing (max. 63, min. 4).
  9395. */
  9396. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  9397. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9398. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  9399. /* If the value is zero, assume it is uninitialized. */
  9400. if (eep_config.max_host_qng == 0) {
  9401. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9402. } else {
  9403. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  9404. }
  9405. }
  9406. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  9407. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9408. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  9409. /* If the value is zero, assume it is uninitialized. */
  9410. if (eep_config.max_dvc_qng == 0) {
  9411. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9412. } else {
  9413. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  9414. }
  9415. }
  9416. /*
  9417. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  9418. * set 'max_dvc_qng' to 'max_host_qng'.
  9419. */
  9420. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  9421. eep_config.max_dvc_qng = eep_config.max_host_qng;
  9422. }
  9423. /*
  9424. * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
  9425. * values based on possibly adjusted EEPROM values.
  9426. */
  9427. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9428. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9429. /*
  9430. * If the EEPROM 'termination' field is set to automatic (0), then set
  9431. * the ADV_DVC_CFG 'termination' field to automatic also.
  9432. *
  9433. * If the termination is specified with a non-zero 'termination'
  9434. * value check that a legal value is set and set the ADV_DVC_CFG
  9435. * 'termination' field appropriately.
  9436. */
  9437. if (eep_config.termination_se == 0) {
  9438. termination = 0; /* auto termination for SE */
  9439. } else {
  9440. /* Enable manual control with low off / high off. */
  9441. if (eep_config.termination_se == 1) {
  9442. termination = 0;
  9443. /* Enable manual control with low off / high on. */
  9444. } else if (eep_config.termination_se == 2) {
  9445. termination = TERM_SE_HI;
  9446. /* Enable manual control with low on / high on. */
  9447. } else if (eep_config.termination_se == 3) {
  9448. termination = TERM_SE;
  9449. } else {
  9450. /*
  9451. * The EEPROM 'termination_se' field contains a bad value.
  9452. * Use automatic termination instead.
  9453. */
  9454. termination = 0;
  9455. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9456. }
  9457. }
  9458. if (eep_config.termination_lvd == 0) {
  9459. asc_dvc->cfg->termination = termination; /* auto termination for LVD */
  9460. } else {
  9461. /* Enable manual control with low off / high off. */
  9462. if (eep_config.termination_lvd == 1) {
  9463. asc_dvc->cfg->termination = termination;
  9464. /* Enable manual control with low off / high on. */
  9465. } else if (eep_config.termination_lvd == 2) {
  9466. asc_dvc->cfg->termination = termination | TERM_LVD_HI;
  9467. /* Enable manual control with low on / high on. */
  9468. } else if (eep_config.termination_lvd == 3) {
  9469. asc_dvc->cfg->termination = termination | TERM_LVD;
  9470. } else {
  9471. /*
  9472. * The EEPROM 'termination_lvd' field contains a bad value.
  9473. * Use automatic termination instead.
  9474. */
  9475. asc_dvc->cfg->termination = termination;
  9476. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9477. }
  9478. }
  9479. return warn_code;
  9480. }
  9481. /*
  9482. * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and
  9483. * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while
  9484. * all of this is done.
  9485. *
  9486. * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
  9487. *
  9488. * For a non-fatal error return a warning code. If there are no warnings
  9489. * then 0 is returned.
  9490. *
  9491. * Note: Chip is stopped on entry.
  9492. */
  9493. static int AdvInitFrom38C1600EEP(ADV_DVC_VAR *asc_dvc)
  9494. {
  9495. AdvPortAddr iop_base;
  9496. ushort warn_code;
  9497. ADVEEP_38C1600_CONFIG eep_config;
  9498. uchar tid, termination;
  9499. ushort sdtr_speed = 0;
  9500. iop_base = asc_dvc->iop_base;
  9501. warn_code = 0;
  9502. /*
  9503. * Read the board's EEPROM configuration.
  9504. *
  9505. * Set default values if a bad checksum is found.
  9506. */
  9507. if (AdvGet38C1600EEPConfig(iop_base, &eep_config) !=
  9508. eep_config.check_sum) {
  9509. struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
  9510. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  9511. /*
  9512. * Set EEPROM default values.
  9513. */
  9514. memcpy(&eep_config, &Default_38C1600_EEPROM_Config,
  9515. sizeof(ADVEEP_38C1600_CONFIG));
  9516. if (PCI_FUNC(pdev->devfn) != 0) {
  9517. u8 ints;
  9518. /*
  9519. * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60
  9520. * and old Mac system booting problem. The Expansion
  9521. * ROM must be disabled in Function 1 for these systems
  9522. */
  9523. eep_config.cfg_lsw &= ~ADV_EEPROM_BIOS_ENABLE;
  9524. /*
  9525. * Clear the INTAB (bit 11) if the GPIO 0 input
  9526. * indicates the Function 1 interrupt line is wired
  9527. * to INTB.
  9528. *
  9529. * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
  9530. * 1 - Function 1 interrupt line wired to INT A.
  9531. * 0 - Function 1 interrupt line wired to INT B.
  9532. *
  9533. * Note: Function 0 is always wired to INTA.
  9534. * Put all 5 GPIO bits in input mode and then read
  9535. * their input values.
  9536. */
  9537. AdvWriteByteRegister(iop_base, IOPB_GPIO_CNTL, 0);
  9538. ints = AdvReadByteRegister(iop_base, IOPB_GPIO_DATA);
  9539. if ((ints & 0x01) == 0)
  9540. eep_config.cfg_lsw &= ~ADV_EEPROM_INTAB;
  9541. }
  9542. /*
  9543. * Assume the 6 byte board serial number that was read from
  9544. * EEPROM is correct even if the EEPROM checksum failed.
  9545. */
  9546. eep_config.serial_number_word3 =
  9547. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  9548. eep_config.serial_number_word2 =
  9549. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  9550. eep_config.serial_number_word1 =
  9551. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  9552. AdvSet38C1600EEPConfig(iop_base, &eep_config);
  9553. }
  9554. /*
  9555. * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
  9556. * EEPROM configuration that was read.
  9557. *
  9558. * This is the mapping of EEPROM fields to Adv Library fields.
  9559. */
  9560. asc_dvc->wdtr_able = eep_config.wdtr_able;
  9561. asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
  9562. asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
  9563. asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
  9564. asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
  9565. asc_dvc->ppr_able = 0;
  9566. asc_dvc->tagqng_able = eep_config.tagqng_able;
  9567. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  9568. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9569. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9570. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ASC_MAX_TID);
  9571. asc_dvc->start_motor = eep_config.start_motor;
  9572. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  9573. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  9574. asc_dvc->no_scam = eep_config.scam_tolerant;
  9575. /*
  9576. * For every Target ID if any of its 'sdtr_speed[1234]' bits
  9577. * are set, then set an 'sdtr_able' bit for it.
  9578. */
  9579. asc_dvc->sdtr_able = 0;
  9580. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  9581. if (tid == 0) {
  9582. sdtr_speed = asc_dvc->sdtr_speed1;
  9583. } else if (tid == 4) {
  9584. sdtr_speed = asc_dvc->sdtr_speed2;
  9585. } else if (tid == 8) {
  9586. sdtr_speed = asc_dvc->sdtr_speed3;
  9587. } else if (tid == 12) {
  9588. sdtr_speed = asc_dvc->sdtr_speed4;
  9589. }
  9590. if (sdtr_speed & ASC_MAX_TID) {
  9591. asc_dvc->sdtr_able |= (1 << tid);
  9592. }
  9593. sdtr_speed >>= 4;
  9594. }
  9595. /*
  9596. * Set the host maximum queuing (max. 253, min. 16) and the per device
  9597. * maximum queuing (max. 63, min. 4).
  9598. */
  9599. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  9600. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9601. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  9602. /* If the value is zero, assume it is uninitialized. */
  9603. if (eep_config.max_host_qng == 0) {
  9604. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9605. } else {
  9606. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  9607. }
  9608. }
  9609. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  9610. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9611. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  9612. /* If the value is zero, assume it is uninitialized. */
  9613. if (eep_config.max_dvc_qng == 0) {
  9614. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9615. } else {
  9616. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  9617. }
  9618. }
  9619. /*
  9620. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  9621. * set 'max_dvc_qng' to 'max_host_qng'.
  9622. */
  9623. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  9624. eep_config.max_dvc_qng = eep_config.max_host_qng;
  9625. }
  9626. /*
  9627. * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng'
  9628. * values based on possibly adjusted EEPROM values.
  9629. */
  9630. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9631. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9632. /*
  9633. * If the EEPROM 'termination' field is set to automatic (0), then set
  9634. * the ASC_DVC_CFG 'termination' field to automatic also.
  9635. *
  9636. * If the termination is specified with a non-zero 'termination'
  9637. * value check that a legal value is set and set the ASC_DVC_CFG
  9638. * 'termination' field appropriately.
  9639. */
  9640. if (eep_config.termination_se == 0) {
  9641. termination = 0; /* auto termination for SE */
  9642. } else {
  9643. /* Enable manual control with low off / high off. */
  9644. if (eep_config.termination_se == 1) {
  9645. termination = 0;
  9646. /* Enable manual control with low off / high on. */
  9647. } else if (eep_config.termination_se == 2) {
  9648. termination = TERM_SE_HI;
  9649. /* Enable manual control with low on / high on. */
  9650. } else if (eep_config.termination_se == 3) {
  9651. termination = TERM_SE;
  9652. } else {
  9653. /*
  9654. * The EEPROM 'termination_se' field contains a bad value.
  9655. * Use automatic termination instead.
  9656. */
  9657. termination = 0;
  9658. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9659. }
  9660. }
  9661. if (eep_config.termination_lvd == 0) {
  9662. asc_dvc->cfg->termination = termination; /* auto termination for LVD */
  9663. } else {
  9664. /* Enable manual control with low off / high off. */
  9665. if (eep_config.termination_lvd == 1) {
  9666. asc_dvc->cfg->termination = termination;
  9667. /* Enable manual control with low off / high on. */
  9668. } else if (eep_config.termination_lvd == 2) {
  9669. asc_dvc->cfg->termination = termination | TERM_LVD_HI;
  9670. /* Enable manual control with low on / high on. */
  9671. } else if (eep_config.termination_lvd == 3) {
  9672. asc_dvc->cfg->termination = termination | TERM_LVD;
  9673. } else {
  9674. /*
  9675. * The EEPROM 'termination_lvd' field contains a bad value.
  9676. * Use automatic termination instead.
  9677. */
  9678. asc_dvc->cfg->termination = termination;
  9679. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9680. }
  9681. }
  9682. return warn_code;
  9683. }
  9684. /*
  9685. * Initialize the ADV_DVC_VAR structure.
  9686. *
  9687. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  9688. *
  9689. * For a non-fatal error return a warning code. If there are no warnings
  9690. * then 0 is returned.
  9691. */
  9692. static int AdvInitGetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
  9693. {
  9694. struct asc_board *board = shost_priv(shost);
  9695. ADV_DVC_VAR *asc_dvc = &board->dvc_var.adv_dvc_var;
  9696. unsigned short warn_code = 0;
  9697. AdvPortAddr iop_base = asc_dvc->iop_base;
  9698. u16 cmd;
  9699. int status;
  9700. asc_dvc->err_code = 0;
  9701. /*
  9702. * Save the state of the PCI Configuration Command Register
  9703. * "Parity Error Response Control" Bit. If the bit is clear (0),
  9704. * in AdvInitAsc3550/38C0800Driver() tell the microcode to ignore
  9705. * DMA parity errors.
  9706. */
  9707. asc_dvc->cfg->control_flag = 0;
  9708. pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  9709. if ((cmd & PCI_COMMAND_PARITY) == 0)
  9710. asc_dvc->cfg->control_flag |= CONTROL_FLAG_IGNORE_PERR;
  9711. asc_dvc->cfg->chip_version =
  9712. AdvGetChipVersion(iop_base, asc_dvc->bus_type);
  9713. ASC_DBG(1, "iopb_chip_id_1: 0x%x 0x%x\n",
  9714. (ushort)AdvReadByteRegister(iop_base, IOPB_CHIP_ID_1),
  9715. (ushort)ADV_CHIP_ID_BYTE);
  9716. ASC_DBG(1, "iopw_chip_id_0: 0x%x 0x%x\n",
  9717. (ushort)AdvReadWordRegister(iop_base, IOPW_CHIP_ID_0),
  9718. (ushort)ADV_CHIP_ID_WORD);
  9719. /*
  9720. * Reset the chip to start and allow register writes.
  9721. */
  9722. if (AdvFindSignature(iop_base) == 0) {
  9723. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  9724. return ADV_ERROR;
  9725. } else {
  9726. /*
  9727. * The caller must set 'chip_type' to a valid setting.
  9728. */
  9729. if (asc_dvc->chip_type != ADV_CHIP_ASC3550 &&
  9730. asc_dvc->chip_type != ADV_CHIP_ASC38C0800 &&
  9731. asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
  9732. asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE;
  9733. return ADV_ERROR;
  9734. }
  9735. /*
  9736. * Reset Chip.
  9737. */
  9738. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  9739. ADV_CTRL_REG_CMD_RESET);
  9740. mdelay(100);
  9741. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  9742. ADV_CTRL_REG_CMD_WR_IO_REG);
  9743. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  9744. status = AdvInitFrom38C1600EEP(asc_dvc);
  9745. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  9746. status = AdvInitFrom38C0800EEP(asc_dvc);
  9747. } else {
  9748. status = AdvInitFrom3550EEP(asc_dvc);
  9749. }
  9750. warn_code |= status;
  9751. }
  9752. if (warn_code != 0)
  9753. shost_printk(KERN_WARNING, shost, "warning: 0x%x\n", warn_code);
  9754. if (asc_dvc->err_code)
  9755. shost_printk(KERN_ERR, shost, "error code 0x%x\n",
  9756. asc_dvc->err_code);
  9757. return asc_dvc->err_code;
  9758. }
  9759. #endif
  9760. static struct scsi_host_template advansys_template = {
  9761. .proc_name = DRV_NAME,
  9762. #ifdef CONFIG_PROC_FS
  9763. .show_info = advansys_show_info,
  9764. #endif
  9765. .name = DRV_NAME,
  9766. .info = advansys_info,
  9767. .queuecommand = advansys_queuecommand,
  9768. .eh_host_reset_handler = advansys_reset,
  9769. .bios_param = advansys_biosparam,
  9770. .slave_configure = advansys_slave_configure,
  9771. /*
  9772. * Because the driver may control an ISA adapter 'unchecked_isa_dma'
  9773. * must be set. The flag will be cleared in advansys_board_found
  9774. * for non-ISA adapters.
  9775. */
  9776. .unchecked_isa_dma = true,
  9777. /*
  9778. * All adapters controlled by this driver are capable of large
  9779. * scatter-gather lists. According to the mid-level SCSI documentation
  9780. * this obviates any performance gain provided by setting
  9781. * 'use_clustering'. But empirically while CPU utilization is increased
  9782. * by enabling clustering, I/O throughput increases as well.
  9783. */
  9784. .use_clustering = ENABLE_CLUSTERING,
  9785. .use_blk_tags = 1,
  9786. };
  9787. static int advansys_wide_init_chip(struct Scsi_Host *shost)
  9788. {
  9789. struct asc_board *board = shost_priv(shost);
  9790. struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
  9791. size_t sgblk_pool_size;
  9792. int warn_code, err_code;
  9793. /*
  9794. * Allocate buffer carrier structures. The total size
  9795. * is about 8 KB, so allocate all at once.
  9796. */
  9797. adv_dvc->carrier = dma_alloc_coherent(board->dev,
  9798. ADV_CARRIER_BUFSIZE, &adv_dvc->carrier_addr, GFP_KERNEL);
  9799. ASC_DBG(1, "carrier 0x%p\n", adv_dvc->carrier);
  9800. if (!adv_dvc->carrier)
  9801. goto kmalloc_failed;
  9802. /*
  9803. * Allocate up to 'max_host_qng' request structures for the Wide
  9804. * board. The total size is about 16 KB, so allocate all at once.
  9805. * If the allocation fails decrement and try again.
  9806. */
  9807. board->adv_reqp_size = adv_dvc->max_host_qng * sizeof(adv_req_t);
  9808. if (board->adv_reqp_size & 0x1f) {
  9809. ASC_DBG(1, "unaligned reqp %lu bytes\n", sizeof(adv_req_t));
  9810. board->adv_reqp_size = ADV_32BALIGN(board->adv_reqp_size);
  9811. }
  9812. board->adv_reqp = dma_alloc_coherent(board->dev, board->adv_reqp_size,
  9813. &board->adv_reqp_addr, GFP_KERNEL);
  9814. if (!board->adv_reqp)
  9815. goto kmalloc_failed;
  9816. ASC_DBG(1, "reqp 0x%p, req_cnt %d, bytes %lu\n", board->adv_reqp,
  9817. adv_dvc->max_host_qng, board->adv_reqp_size);
  9818. /*
  9819. * Allocate up to ADV_TOT_SG_BLOCK request structures for
  9820. * the Wide board. Each structure is about 136 bytes.
  9821. */
  9822. sgblk_pool_size = sizeof(adv_sgblk_t) * ADV_TOT_SG_BLOCK;
  9823. board->adv_sgblk_pool = dma_pool_create("adv_sgblk", board->dev,
  9824. sgblk_pool_size, 32, 0);
  9825. ASC_DBG(1, "sg_cnt %d * %lu = %lu bytes\n", ADV_TOT_SG_BLOCK,
  9826. sizeof(adv_sgblk_t), sgblk_pool_size);
  9827. if (!board->adv_sgblk_pool)
  9828. goto kmalloc_failed;
  9829. if (adv_dvc->chip_type == ADV_CHIP_ASC3550) {
  9830. ASC_DBG(2, "AdvInitAsc3550Driver()\n");
  9831. warn_code = AdvInitAsc3550Driver(adv_dvc);
  9832. } else if (adv_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  9833. ASC_DBG(2, "AdvInitAsc38C0800Driver()\n");
  9834. warn_code = AdvInitAsc38C0800Driver(adv_dvc);
  9835. } else {
  9836. ASC_DBG(2, "AdvInitAsc38C1600Driver()\n");
  9837. warn_code = AdvInitAsc38C1600Driver(adv_dvc);
  9838. }
  9839. err_code = adv_dvc->err_code;
  9840. if (warn_code || err_code) {
  9841. shost_printk(KERN_WARNING, shost, "error: warn 0x%x, error "
  9842. "0x%x\n", warn_code, err_code);
  9843. }
  9844. goto exit;
  9845. kmalloc_failed:
  9846. shost_printk(KERN_ERR, shost, "error: kmalloc() failed\n");
  9847. err_code = ADV_ERROR;
  9848. exit:
  9849. return err_code;
  9850. }
  9851. static void advansys_wide_free_mem(struct asc_board *board)
  9852. {
  9853. struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
  9854. if (adv_dvc->carrier) {
  9855. dma_free_coherent(board->dev, ADV_CARRIER_BUFSIZE,
  9856. adv_dvc->carrier, adv_dvc->carrier_addr);
  9857. adv_dvc->carrier = NULL;
  9858. }
  9859. if (board->adv_reqp) {
  9860. dma_free_coherent(board->dev, board->adv_reqp_size,
  9861. board->adv_reqp, board->adv_reqp_addr);
  9862. board->adv_reqp = NULL;
  9863. }
  9864. if (board->adv_sgblk_pool) {
  9865. dma_pool_destroy(board->adv_sgblk_pool);
  9866. board->adv_sgblk_pool = NULL;
  9867. }
  9868. }
  9869. static int advansys_board_found(struct Scsi_Host *shost, unsigned int iop,
  9870. int bus_type)
  9871. {
  9872. struct pci_dev *pdev;
  9873. struct asc_board *boardp = shost_priv(shost);
  9874. ASC_DVC_VAR *asc_dvc_varp = NULL;
  9875. ADV_DVC_VAR *adv_dvc_varp = NULL;
  9876. int share_irq, warn_code, ret;
  9877. pdev = (bus_type == ASC_IS_PCI) ? to_pci_dev(boardp->dev) : NULL;
  9878. if (ASC_NARROW_BOARD(boardp)) {
  9879. ASC_DBG(1, "narrow board\n");
  9880. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  9881. asc_dvc_varp->bus_type = bus_type;
  9882. asc_dvc_varp->drv_ptr = boardp;
  9883. asc_dvc_varp->cfg = &boardp->dvc_cfg.asc_dvc_cfg;
  9884. asc_dvc_varp->iop_base = iop;
  9885. } else {
  9886. #ifdef CONFIG_PCI
  9887. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  9888. adv_dvc_varp->drv_ptr = boardp;
  9889. adv_dvc_varp->cfg = &boardp->dvc_cfg.adv_dvc_cfg;
  9890. if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW) {
  9891. ASC_DBG(1, "wide board ASC-3550\n");
  9892. adv_dvc_varp->chip_type = ADV_CHIP_ASC3550;
  9893. } else if (pdev->device == PCI_DEVICE_ID_38C0800_REV1) {
  9894. ASC_DBG(1, "wide board ASC-38C0800\n");
  9895. adv_dvc_varp->chip_type = ADV_CHIP_ASC38C0800;
  9896. } else {
  9897. ASC_DBG(1, "wide board ASC-38C1600\n");
  9898. adv_dvc_varp->chip_type = ADV_CHIP_ASC38C1600;
  9899. }
  9900. boardp->asc_n_io_port = pci_resource_len(pdev, 1);
  9901. boardp->ioremap_addr = pci_ioremap_bar(pdev, 1);
  9902. if (!boardp->ioremap_addr) {
  9903. shost_printk(KERN_ERR, shost, "ioremap(%lx, %d) "
  9904. "returned NULL\n",
  9905. (long)pci_resource_start(pdev, 1),
  9906. boardp->asc_n_io_port);
  9907. ret = -ENODEV;
  9908. goto err_shost;
  9909. }
  9910. adv_dvc_varp->iop_base = (AdvPortAddr)boardp->ioremap_addr;
  9911. ASC_DBG(1, "iop_base: 0x%p\n", adv_dvc_varp->iop_base);
  9912. /*
  9913. * Even though it isn't used to access wide boards, other
  9914. * than for the debug line below, save I/O Port address so
  9915. * that it can be reported.
  9916. */
  9917. boardp->ioport = iop;
  9918. ASC_DBG(1, "iopb_chip_id_1 0x%x, iopw_chip_id_0 0x%x\n",
  9919. (ushort)inp(iop + 1), (ushort)inpw(iop));
  9920. #endif /* CONFIG_PCI */
  9921. }
  9922. if (ASC_NARROW_BOARD(boardp)) {
  9923. /*
  9924. * Set the board bus type and PCI IRQ before
  9925. * calling AscInitGetConfig().
  9926. */
  9927. switch (asc_dvc_varp->bus_type) {
  9928. #ifdef CONFIG_ISA
  9929. case ASC_IS_ISA:
  9930. shost->unchecked_isa_dma = true;
  9931. share_irq = 0;
  9932. break;
  9933. case ASC_IS_VL:
  9934. shost->unchecked_isa_dma = false;
  9935. share_irq = 0;
  9936. break;
  9937. case ASC_IS_EISA:
  9938. shost->unchecked_isa_dma = false;
  9939. share_irq = IRQF_SHARED;
  9940. break;
  9941. #endif /* CONFIG_ISA */
  9942. #ifdef CONFIG_PCI
  9943. case ASC_IS_PCI:
  9944. shost->unchecked_isa_dma = false;
  9945. share_irq = IRQF_SHARED;
  9946. break;
  9947. #endif /* CONFIG_PCI */
  9948. default:
  9949. shost_printk(KERN_ERR, shost, "unknown adapter type: "
  9950. "%d\n", asc_dvc_varp->bus_type);
  9951. shost->unchecked_isa_dma = false;
  9952. share_irq = 0;
  9953. break;
  9954. }
  9955. /*
  9956. * NOTE: AscInitGetConfig() may change the board's
  9957. * bus_type value. The bus_type value should no
  9958. * longer be used. If the bus_type field must be
  9959. * referenced only use the bit-wise AND operator "&".
  9960. */
  9961. ASC_DBG(2, "AscInitGetConfig()\n");
  9962. ret = AscInitGetConfig(shost) ? -ENODEV : 0;
  9963. } else {
  9964. #ifdef CONFIG_PCI
  9965. /*
  9966. * For Wide boards set PCI information before calling
  9967. * AdvInitGetConfig().
  9968. */
  9969. shost->unchecked_isa_dma = false;
  9970. share_irq = IRQF_SHARED;
  9971. ASC_DBG(2, "AdvInitGetConfig()\n");
  9972. ret = AdvInitGetConfig(pdev, shost) ? -ENODEV : 0;
  9973. #endif /* CONFIG_PCI */
  9974. }
  9975. if (ret)
  9976. goto err_unmap;
  9977. /*
  9978. * Save the EEPROM configuration so that it can be displayed
  9979. * from /proc/scsi/advansys/[0...].
  9980. */
  9981. if (ASC_NARROW_BOARD(boardp)) {
  9982. ASCEEP_CONFIG *ep;
  9983. /*
  9984. * Set the adapter's target id bit in the 'init_tidmask' field.
  9985. */
  9986. boardp->init_tidmask |=
  9987. ADV_TID_TO_TIDMASK(asc_dvc_varp->cfg->chip_scsi_id);
  9988. /*
  9989. * Save EEPROM settings for the board.
  9990. */
  9991. ep = &boardp->eep_config.asc_eep;
  9992. ep->init_sdtr = asc_dvc_varp->cfg->sdtr_enable;
  9993. ep->disc_enable = asc_dvc_varp->cfg->disc_enable;
  9994. ep->use_cmd_qng = asc_dvc_varp->cfg->cmd_qng_enabled;
  9995. ASC_EEP_SET_DMA_SPD(ep, asc_dvc_varp->cfg->isa_dma_speed);
  9996. ep->start_motor = asc_dvc_varp->start_motor;
  9997. ep->cntl = asc_dvc_varp->dvc_cntl;
  9998. ep->no_scam = asc_dvc_varp->no_scam;
  9999. ep->max_total_qng = asc_dvc_varp->max_total_qng;
  10000. ASC_EEP_SET_CHIP_ID(ep, asc_dvc_varp->cfg->chip_scsi_id);
  10001. /* 'max_tag_qng' is set to the same value for every device. */
  10002. ep->max_tag_qng = asc_dvc_varp->cfg->max_tag_qng[0];
  10003. ep->adapter_info[0] = asc_dvc_varp->cfg->adapter_info[0];
  10004. ep->adapter_info[1] = asc_dvc_varp->cfg->adapter_info[1];
  10005. ep->adapter_info[2] = asc_dvc_varp->cfg->adapter_info[2];
  10006. ep->adapter_info[3] = asc_dvc_varp->cfg->adapter_info[3];
  10007. ep->adapter_info[4] = asc_dvc_varp->cfg->adapter_info[4];
  10008. ep->adapter_info[5] = asc_dvc_varp->cfg->adapter_info[5];
  10009. /*
  10010. * Modify board configuration.
  10011. */
  10012. ASC_DBG(2, "AscInitSetConfig()\n");
  10013. ret = AscInitSetConfig(pdev, shost) ? -ENODEV : 0;
  10014. if (ret)
  10015. goto err_unmap;
  10016. } else {
  10017. ADVEEP_3550_CONFIG *ep_3550;
  10018. ADVEEP_38C0800_CONFIG *ep_38C0800;
  10019. ADVEEP_38C1600_CONFIG *ep_38C1600;
  10020. /*
  10021. * Save Wide EEP Configuration Information.
  10022. */
  10023. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  10024. ep_3550 = &boardp->eep_config.adv_3550_eep;
  10025. ep_3550->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
  10026. ep_3550->max_host_qng = adv_dvc_varp->max_host_qng;
  10027. ep_3550->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10028. ep_3550->termination = adv_dvc_varp->cfg->termination;
  10029. ep_3550->disc_enable = adv_dvc_varp->cfg->disc_enable;
  10030. ep_3550->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10031. ep_3550->wdtr_able = adv_dvc_varp->wdtr_able;
  10032. ep_3550->sdtr_able = adv_dvc_varp->sdtr_able;
  10033. ep_3550->ultra_able = adv_dvc_varp->ultra_able;
  10034. ep_3550->tagqng_able = adv_dvc_varp->tagqng_able;
  10035. ep_3550->start_motor = adv_dvc_varp->start_motor;
  10036. ep_3550->scsi_reset_delay =
  10037. adv_dvc_varp->scsi_reset_wait;
  10038. ep_3550->serial_number_word1 =
  10039. adv_dvc_varp->cfg->serial1;
  10040. ep_3550->serial_number_word2 =
  10041. adv_dvc_varp->cfg->serial2;
  10042. ep_3550->serial_number_word3 =
  10043. adv_dvc_varp->cfg->serial3;
  10044. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  10045. ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
  10046. ep_38C0800->adapter_scsi_id =
  10047. adv_dvc_varp->chip_scsi_id;
  10048. ep_38C0800->max_host_qng = adv_dvc_varp->max_host_qng;
  10049. ep_38C0800->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10050. ep_38C0800->termination_lvd =
  10051. adv_dvc_varp->cfg->termination;
  10052. ep_38C0800->disc_enable =
  10053. adv_dvc_varp->cfg->disc_enable;
  10054. ep_38C0800->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10055. ep_38C0800->wdtr_able = adv_dvc_varp->wdtr_able;
  10056. ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
  10057. ep_38C0800->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
  10058. ep_38C0800->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
  10059. ep_38C0800->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
  10060. ep_38C0800->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
  10061. ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
  10062. ep_38C0800->start_motor = adv_dvc_varp->start_motor;
  10063. ep_38C0800->scsi_reset_delay =
  10064. adv_dvc_varp->scsi_reset_wait;
  10065. ep_38C0800->serial_number_word1 =
  10066. adv_dvc_varp->cfg->serial1;
  10067. ep_38C0800->serial_number_word2 =
  10068. adv_dvc_varp->cfg->serial2;
  10069. ep_38C0800->serial_number_word3 =
  10070. adv_dvc_varp->cfg->serial3;
  10071. } else {
  10072. ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
  10073. ep_38C1600->adapter_scsi_id =
  10074. adv_dvc_varp->chip_scsi_id;
  10075. ep_38C1600->max_host_qng = adv_dvc_varp->max_host_qng;
  10076. ep_38C1600->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10077. ep_38C1600->termination_lvd =
  10078. adv_dvc_varp->cfg->termination;
  10079. ep_38C1600->disc_enable =
  10080. adv_dvc_varp->cfg->disc_enable;
  10081. ep_38C1600->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10082. ep_38C1600->wdtr_able = adv_dvc_varp->wdtr_able;
  10083. ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
  10084. ep_38C1600->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
  10085. ep_38C1600->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
  10086. ep_38C1600->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
  10087. ep_38C1600->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
  10088. ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
  10089. ep_38C1600->start_motor = adv_dvc_varp->start_motor;
  10090. ep_38C1600->scsi_reset_delay =
  10091. adv_dvc_varp->scsi_reset_wait;
  10092. ep_38C1600->serial_number_word1 =
  10093. adv_dvc_varp->cfg->serial1;
  10094. ep_38C1600->serial_number_word2 =
  10095. adv_dvc_varp->cfg->serial2;
  10096. ep_38C1600->serial_number_word3 =
  10097. adv_dvc_varp->cfg->serial3;
  10098. }
  10099. /*
  10100. * Set the adapter's target id bit in the 'init_tidmask' field.
  10101. */
  10102. boardp->init_tidmask |=
  10103. ADV_TID_TO_TIDMASK(adv_dvc_varp->chip_scsi_id);
  10104. }
  10105. /*
  10106. * Channels are numbered beginning with 0. For AdvanSys one host
  10107. * structure supports one channel. Multi-channel boards have a
  10108. * separate host structure for each channel.
  10109. */
  10110. shost->max_channel = 0;
  10111. if (ASC_NARROW_BOARD(boardp)) {
  10112. shost->max_id = ASC_MAX_TID + 1;
  10113. shost->max_lun = ASC_MAX_LUN + 1;
  10114. shost->max_cmd_len = ASC_MAX_CDB_LEN;
  10115. shost->io_port = asc_dvc_varp->iop_base;
  10116. boardp->asc_n_io_port = ASC_IOADR_GAP;
  10117. shost->this_id = asc_dvc_varp->cfg->chip_scsi_id;
  10118. /* Set maximum number of queues the adapter can handle. */
  10119. shost->can_queue = asc_dvc_varp->max_total_qng;
  10120. } else {
  10121. shost->max_id = ADV_MAX_TID + 1;
  10122. shost->max_lun = ADV_MAX_LUN + 1;
  10123. shost->max_cmd_len = ADV_MAX_CDB_LEN;
  10124. /*
  10125. * Save the I/O Port address and length even though
  10126. * I/O ports are not used to access Wide boards.
  10127. * Instead the Wide boards are accessed with
  10128. * PCI Memory Mapped I/O.
  10129. */
  10130. shost->io_port = iop;
  10131. shost->this_id = adv_dvc_varp->chip_scsi_id;
  10132. /* Set maximum number of queues the adapter can handle. */
  10133. shost->can_queue = adv_dvc_varp->max_host_qng;
  10134. }
  10135. ret = scsi_init_shared_tag_map(shost, shost->can_queue);
  10136. if (ret) {
  10137. shost_printk(KERN_ERR, shost, "init tag map failed\n");
  10138. goto err_free_dma;
  10139. }
  10140. /*
  10141. * Set the maximum number of scatter-gather elements the
  10142. * adapter can handle.
  10143. */
  10144. if (ASC_NARROW_BOARD(boardp)) {
  10145. /*
  10146. * Allow two commands with 'sg_tablesize' scatter-gather
  10147. * elements to be executed simultaneously. This value is
  10148. * the theoretical hardware limit. It may be decreased
  10149. * below.
  10150. */
  10151. shost->sg_tablesize =
  10152. (((asc_dvc_varp->max_total_qng - 2) / 2) *
  10153. ASC_SG_LIST_PER_Q) + 1;
  10154. } else {
  10155. shost->sg_tablesize = ADV_MAX_SG_LIST;
  10156. }
  10157. /*
  10158. * The value of 'sg_tablesize' can not exceed the SCSI
  10159. * mid-level driver definition of SG_ALL. SG_ALL also
  10160. * must not be exceeded, because it is used to define the
  10161. * size of the scatter-gather table in 'struct asc_sg_head'.
  10162. */
  10163. if (shost->sg_tablesize > SG_ALL) {
  10164. shost->sg_tablesize = SG_ALL;
  10165. }
  10166. ASC_DBG(1, "sg_tablesize: %d\n", shost->sg_tablesize);
  10167. /* BIOS start address. */
  10168. if (ASC_NARROW_BOARD(boardp)) {
  10169. shost->base = AscGetChipBiosAddress(asc_dvc_varp->iop_base,
  10170. asc_dvc_varp->bus_type);
  10171. } else {
  10172. /*
  10173. * Fill-in BIOS board variables. The Wide BIOS saves
  10174. * information in LRAM that is used by the driver.
  10175. */
  10176. AdvReadWordLram(adv_dvc_varp->iop_base,
  10177. BIOS_SIGNATURE, boardp->bios_signature);
  10178. AdvReadWordLram(adv_dvc_varp->iop_base,
  10179. BIOS_VERSION, boardp->bios_version);
  10180. AdvReadWordLram(adv_dvc_varp->iop_base,
  10181. BIOS_CODESEG, boardp->bios_codeseg);
  10182. AdvReadWordLram(adv_dvc_varp->iop_base,
  10183. BIOS_CODELEN, boardp->bios_codelen);
  10184. ASC_DBG(1, "bios_signature 0x%x, bios_version 0x%x\n",
  10185. boardp->bios_signature, boardp->bios_version);
  10186. ASC_DBG(1, "bios_codeseg 0x%x, bios_codelen 0x%x\n",
  10187. boardp->bios_codeseg, boardp->bios_codelen);
  10188. /*
  10189. * If the BIOS saved a valid signature, then fill in
  10190. * the BIOS code segment base address.
  10191. */
  10192. if (boardp->bios_signature == 0x55AA) {
  10193. /*
  10194. * Convert x86 realmode code segment to a linear
  10195. * address by shifting left 4.
  10196. */
  10197. shost->base = ((ulong)boardp->bios_codeseg << 4);
  10198. } else {
  10199. shost->base = 0;
  10200. }
  10201. }
  10202. /*
  10203. * Register Board Resources - I/O Port, DMA, IRQ
  10204. */
  10205. /* Register DMA Channel for Narrow boards. */
  10206. shost->dma_channel = NO_ISA_DMA; /* Default to no ISA DMA. */
  10207. #ifdef CONFIG_ISA
  10208. if (ASC_NARROW_BOARD(boardp)) {
  10209. /* Register DMA channel for ISA bus. */
  10210. if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
  10211. shost->dma_channel = asc_dvc_varp->cfg->isa_dma_channel;
  10212. ret = request_dma(shost->dma_channel, DRV_NAME);
  10213. if (ret) {
  10214. shost_printk(KERN_ERR, shost, "request_dma() "
  10215. "%d failed %d\n",
  10216. shost->dma_channel, ret);
  10217. goto err_unmap;
  10218. }
  10219. AscEnableIsaDma(shost->dma_channel);
  10220. }
  10221. }
  10222. #endif /* CONFIG_ISA */
  10223. /* Register IRQ Number. */
  10224. ASC_DBG(2, "request_irq(%d, %p)\n", boardp->irq, shost);
  10225. ret = request_irq(boardp->irq, advansys_interrupt, share_irq,
  10226. DRV_NAME, shost);
  10227. if (ret) {
  10228. if (ret == -EBUSY) {
  10229. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  10230. "already in use\n", boardp->irq);
  10231. } else if (ret == -EINVAL) {
  10232. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  10233. "not valid\n", boardp->irq);
  10234. } else {
  10235. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  10236. "failed with %d\n", boardp->irq, ret);
  10237. }
  10238. goto err_free_dma;
  10239. }
  10240. /*
  10241. * Initialize board RISC chip and enable interrupts.
  10242. */
  10243. if (ASC_NARROW_BOARD(boardp)) {
  10244. ASC_DBG(2, "AscInitAsc1000Driver()\n");
  10245. asc_dvc_varp->overrun_buf = kzalloc(ASC_OVERRUN_BSIZE, GFP_KERNEL);
  10246. if (!asc_dvc_varp->overrun_buf) {
  10247. ret = -ENOMEM;
  10248. goto err_free_irq;
  10249. }
  10250. warn_code = AscInitAsc1000Driver(asc_dvc_varp);
  10251. if (warn_code || asc_dvc_varp->err_code) {
  10252. shost_printk(KERN_ERR, shost, "error: init_state 0x%x, "
  10253. "warn 0x%x, error 0x%x\n",
  10254. asc_dvc_varp->init_state, warn_code,
  10255. asc_dvc_varp->err_code);
  10256. if (!asc_dvc_varp->overrun_dma) {
  10257. ret = -ENODEV;
  10258. goto err_free_mem;
  10259. }
  10260. }
  10261. } else {
  10262. if (advansys_wide_init_chip(shost)) {
  10263. ret = -ENODEV;
  10264. goto err_free_mem;
  10265. }
  10266. }
  10267. ASC_DBG_PRT_SCSI_HOST(2, shost);
  10268. ret = scsi_add_host(shost, boardp->dev);
  10269. if (ret)
  10270. goto err_free_mem;
  10271. scsi_scan_host(shost);
  10272. return 0;
  10273. err_free_mem:
  10274. if (ASC_NARROW_BOARD(boardp)) {
  10275. if (asc_dvc_varp->overrun_dma)
  10276. dma_unmap_single(boardp->dev, asc_dvc_varp->overrun_dma,
  10277. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  10278. kfree(asc_dvc_varp->overrun_buf);
  10279. } else
  10280. advansys_wide_free_mem(boardp);
  10281. err_free_irq:
  10282. free_irq(boardp->irq, shost);
  10283. err_free_dma:
  10284. #ifdef CONFIG_ISA
  10285. if (shost->dma_channel != NO_ISA_DMA)
  10286. free_dma(shost->dma_channel);
  10287. #endif
  10288. err_unmap:
  10289. if (boardp->ioremap_addr)
  10290. iounmap(boardp->ioremap_addr);
  10291. #ifdef CONFIG_PCI
  10292. err_shost:
  10293. #endif
  10294. return ret;
  10295. }
  10296. /*
  10297. * advansys_release()
  10298. *
  10299. * Release resources allocated for a single AdvanSys adapter.
  10300. */
  10301. static int advansys_release(struct Scsi_Host *shost)
  10302. {
  10303. struct asc_board *board = shost_priv(shost);
  10304. ASC_DBG(1, "begin\n");
  10305. scsi_remove_host(shost);
  10306. free_irq(board->irq, shost);
  10307. #ifdef CONFIG_ISA
  10308. if (shost->dma_channel != NO_ISA_DMA) {
  10309. ASC_DBG(1, "free_dma()\n");
  10310. free_dma(shost->dma_channel);
  10311. }
  10312. #endif
  10313. if (ASC_NARROW_BOARD(board)) {
  10314. dma_unmap_single(board->dev,
  10315. board->dvc_var.asc_dvc_var.overrun_dma,
  10316. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  10317. kfree(board->dvc_var.asc_dvc_var.overrun_buf);
  10318. } else {
  10319. iounmap(board->ioremap_addr);
  10320. advansys_wide_free_mem(board);
  10321. }
  10322. scsi_host_put(shost);
  10323. ASC_DBG(1, "end\n");
  10324. return 0;
  10325. }
  10326. #define ASC_IOADR_TABLE_MAX_IX 11
  10327. static PortAddr _asc_def_iop_base[ASC_IOADR_TABLE_MAX_IX] = {
  10328. 0x100, 0x0110, 0x120, 0x0130, 0x140, 0x0150, 0x0190,
  10329. 0x0210, 0x0230, 0x0250, 0x0330
  10330. };
  10331. /*
  10332. * The ISA IRQ number is found in bits 2 and 3 of the CfgLsw. It decodes as:
  10333. * 00: 10
  10334. * 01: 11
  10335. * 10: 12
  10336. * 11: 15
  10337. */
  10338. static unsigned int advansys_isa_irq_no(PortAddr iop_base)
  10339. {
  10340. unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
  10341. unsigned int chip_irq = ((cfg_lsw >> 2) & 0x03) + 10;
  10342. if (chip_irq == 13)
  10343. chip_irq = 15;
  10344. return chip_irq;
  10345. }
  10346. static int advansys_isa_probe(struct device *dev, unsigned int id)
  10347. {
  10348. int err = -ENODEV;
  10349. PortAddr iop_base = _asc_def_iop_base[id];
  10350. struct Scsi_Host *shost;
  10351. struct asc_board *board;
  10352. if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
  10353. ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
  10354. return -ENODEV;
  10355. }
  10356. ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
  10357. if (!AscFindSignature(iop_base))
  10358. goto release_region;
  10359. if (!(AscGetChipVersion(iop_base, ASC_IS_ISA) & ASC_CHIP_VER_ISA_BIT))
  10360. goto release_region;
  10361. err = -ENOMEM;
  10362. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  10363. if (!shost)
  10364. goto release_region;
  10365. board = shost_priv(shost);
  10366. board->irq = advansys_isa_irq_no(iop_base);
  10367. board->dev = dev;
  10368. board->shost = shost;
  10369. err = advansys_board_found(shost, iop_base, ASC_IS_ISA);
  10370. if (err)
  10371. goto free_host;
  10372. dev_set_drvdata(dev, shost);
  10373. return 0;
  10374. free_host:
  10375. scsi_host_put(shost);
  10376. release_region:
  10377. release_region(iop_base, ASC_IOADR_GAP);
  10378. return err;
  10379. }
  10380. static int advansys_isa_remove(struct device *dev, unsigned int id)
  10381. {
  10382. int ioport = _asc_def_iop_base[id];
  10383. advansys_release(dev_get_drvdata(dev));
  10384. release_region(ioport, ASC_IOADR_GAP);
  10385. return 0;
  10386. }
  10387. static struct isa_driver advansys_isa_driver = {
  10388. .probe = advansys_isa_probe,
  10389. .remove = advansys_isa_remove,
  10390. .driver = {
  10391. .owner = THIS_MODULE,
  10392. .name = DRV_NAME,
  10393. },
  10394. };
  10395. /*
  10396. * The VLB IRQ number is found in bits 2 to 4 of the CfgLsw. It decodes as:
  10397. * 000: invalid
  10398. * 001: 10
  10399. * 010: 11
  10400. * 011: 12
  10401. * 100: invalid
  10402. * 101: 14
  10403. * 110: 15
  10404. * 111: invalid
  10405. */
  10406. static unsigned int advansys_vlb_irq_no(PortAddr iop_base)
  10407. {
  10408. unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
  10409. unsigned int chip_irq = ((cfg_lsw >> 2) & 0x07) + 9;
  10410. if ((chip_irq < 10) || (chip_irq == 13) || (chip_irq > 15))
  10411. return 0;
  10412. return chip_irq;
  10413. }
  10414. static int advansys_vlb_probe(struct device *dev, unsigned int id)
  10415. {
  10416. int err = -ENODEV;
  10417. PortAddr iop_base = _asc_def_iop_base[id];
  10418. struct Scsi_Host *shost;
  10419. struct asc_board *board;
  10420. if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
  10421. ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
  10422. return -ENODEV;
  10423. }
  10424. ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
  10425. if (!AscFindSignature(iop_base))
  10426. goto release_region;
  10427. /*
  10428. * I don't think this condition can actually happen, but the old
  10429. * driver did it, and the chances of finding a VLB setup in 2007
  10430. * to do testing with is slight to none.
  10431. */
  10432. if (AscGetChipVersion(iop_base, ASC_IS_VL) > ASC_CHIP_MAX_VER_VL)
  10433. goto release_region;
  10434. err = -ENOMEM;
  10435. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  10436. if (!shost)
  10437. goto release_region;
  10438. board = shost_priv(shost);
  10439. board->irq = advansys_vlb_irq_no(iop_base);
  10440. board->dev = dev;
  10441. board->shost = shost;
  10442. err = advansys_board_found(shost, iop_base, ASC_IS_VL);
  10443. if (err)
  10444. goto free_host;
  10445. dev_set_drvdata(dev, shost);
  10446. return 0;
  10447. free_host:
  10448. scsi_host_put(shost);
  10449. release_region:
  10450. release_region(iop_base, ASC_IOADR_GAP);
  10451. return -ENODEV;
  10452. }
  10453. static struct isa_driver advansys_vlb_driver = {
  10454. .probe = advansys_vlb_probe,
  10455. .remove = advansys_isa_remove,
  10456. .driver = {
  10457. .owner = THIS_MODULE,
  10458. .name = "advansys_vlb",
  10459. },
  10460. };
  10461. static struct eisa_device_id advansys_eisa_table[] = {
  10462. { "ABP7401" },
  10463. { "ABP7501" },
  10464. { "" }
  10465. };
  10466. MODULE_DEVICE_TABLE(eisa, advansys_eisa_table);
  10467. /*
  10468. * EISA is a little more tricky than PCI; each EISA device may have two
  10469. * channels, and this driver is written to make each channel its own Scsi_Host
  10470. */
  10471. struct eisa_scsi_data {
  10472. struct Scsi_Host *host[2];
  10473. };
  10474. /*
  10475. * The EISA IRQ number is found in bits 8 to 10 of the CfgLsw. It decodes as:
  10476. * 000: 10
  10477. * 001: 11
  10478. * 010: 12
  10479. * 011: invalid
  10480. * 100: 14
  10481. * 101: 15
  10482. * 110: invalid
  10483. * 111: invalid
  10484. */
  10485. static unsigned int advansys_eisa_irq_no(struct eisa_device *edev)
  10486. {
  10487. unsigned short cfg_lsw = inw(edev->base_addr + 0xc86);
  10488. unsigned int chip_irq = ((cfg_lsw >> 8) & 0x07) + 10;
  10489. if ((chip_irq == 13) || (chip_irq > 15))
  10490. return 0;
  10491. return chip_irq;
  10492. }
  10493. static int advansys_eisa_probe(struct device *dev)
  10494. {
  10495. int i, ioport, irq = 0;
  10496. int err;
  10497. struct eisa_device *edev = to_eisa_device(dev);
  10498. struct eisa_scsi_data *data;
  10499. err = -ENOMEM;
  10500. data = kzalloc(sizeof(*data), GFP_KERNEL);
  10501. if (!data)
  10502. goto fail;
  10503. ioport = edev->base_addr + 0xc30;
  10504. err = -ENODEV;
  10505. for (i = 0; i < 2; i++, ioport += 0x20) {
  10506. struct asc_board *board;
  10507. struct Scsi_Host *shost;
  10508. if (!request_region(ioport, ASC_IOADR_GAP, DRV_NAME)) {
  10509. printk(KERN_WARNING "Region %x-%x busy\n", ioport,
  10510. ioport + ASC_IOADR_GAP - 1);
  10511. continue;
  10512. }
  10513. if (!AscFindSignature(ioport)) {
  10514. release_region(ioport, ASC_IOADR_GAP);
  10515. continue;
  10516. }
  10517. /*
  10518. * I don't know why we need to do this for EISA chips, but
  10519. * not for any others. It looks to be equivalent to
  10520. * AscGetChipCfgMsw, but I may have overlooked something,
  10521. * so I'm not converting it until I get an EISA board to
  10522. * test with.
  10523. */
  10524. inw(ioport + 4);
  10525. if (!irq)
  10526. irq = advansys_eisa_irq_no(edev);
  10527. err = -ENOMEM;
  10528. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  10529. if (!shost)
  10530. goto release_region;
  10531. board = shost_priv(shost);
  10532. board->irq = irq;
  10533. board->dev = dev;
  10534. board->shost = shost;
  10535. err = advansys_board_found(shost, ioport, ASC_IS_EISA);
  10536. if (!err) {
  10537. data->host[i] = shost;
  10538. continue;
  10539. }
  10540. scsi_host_put(shost);
  10541. release_region:
  10542. release_region(ioport, ASC_IOADR_GAP);
  10543. break;
  10544. }
  10545. if (err)
  10546. goto free_data;
  10547. dev_set_drvdata(dev, data);
  10548. return 0;
  10549. free_data:
  10550. kfree(data->host[0]);
  10551. kfree(data->host[1]);
  10552. kfree(data);
  10553. fail:
  10554. return err;
  10555. }
  10556. static int advansys_eisa_remove(struct device *dev)
  10557. {
  10558. int i;
  10559. struct eisa_scsi_data *data = dev_get_drvdata(dev);
  10560. for (i = 0; i < 2; i++) {
  10561. int ioport;
  10562. struct Scsi_Host *shost = data->host[i];
  10563. if (!shost)
  10564. continue;
  10565. ioport = shost->io_port;
  10566. advansys_release(shost);
  10567. release_region(ioport, ASC_IOADR_GAP);
  10568. }
  10569. kfree(data);
  10570. return 0;
  10571. }
  10572. static struct eisa_driver advansys_eisa_driver = {
  10573. .id_table = advansys_eisa_table,
  10574. .driver = {
  10575. .name = DRV_NAME,
  10576. .probe = advansys_eisa_probe,
  10577. .remove = advansys_eisa_remove,
  10578. }
  10579. };
  10580. /* PCI Devices supported by this driver */
  10581. static struct pci_device_id advansys_pci_tbl[] = {
  10582. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_1200A,
  10583. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10584. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940,
  10585. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10586. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940U,
  10587. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10588. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940UW,
  10589. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10590. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C0800_REV1,
  10591. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10592. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C1600_REV1,
  10593. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  10594. {}
  10595. };
  10596. MODULE_DEVICE_TABLE(pci, advansys_pci_tbl);
  10597. static void advansys_set_latency(struct pci_dev *pdev)
  10598. {
  10599. if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
  10600. (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
  10601. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0);
  10602. } else {
  10603. u8 latency;
  10604. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
  10605. if (latency < 0x20)
  10606. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x20);
  10607. }
  10608. }
  10609. static int advansys_pci_probe(struct pci_dev *pdev,
  10610. const struct pci_device_id *ent)
  10611. {
  10612. int err, ioport;
  10613. struct Scsi_Host *shost;
  10614. struct asc_board *board;
  10615. err = pci_enable_device(pdev);
  10616. if (err)
  10617. goto fail;
  10618. err = pci_request_regions(pdev, DRV_NAME);
  10619. if (err)
  10620. goto disable_device;
  10621. pci_set_master(pdev);
  10622. advansys_set_latency(pdev);
  10623. err = -ENODEV;
  10624. if (pci_resource_len(pdev, 0) == 0)
  10625. goto release_region;
  10626. ioport = pci_resource_start(pdev, 0);
  10627. err = -ENOMEM;
  10628. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  10629. if (!shost)
  10630. goto release_region;
  10631. board = shost_priv(shost);
  10632. board->irq = pdev->irq;
  10633. board->dev = &pdev->dev;
  10634. board->shost = shost;
  10635. if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW ||
  10636. pdev->device == PCI_DEVICE_ID_38C0800_REV1 ||
  10637. pdev->device == PCI_DEVICE_ID_38C1600_REV1) {
  10638. board->flags |= ASC_IS_WIDE_BOARD;
  10639. }
  10640. err = advansys_board_found(shost, ioport, ASC_IS_PCI);
  10641. if (err)
  10642. goto free_host;
  10643. pci_set_drvdata(pdev, shost);
  10644. return 0;
  10645. free_host:
  10646. scsi_host_put(shost);
  10647. release_region:
  10648. pci_release_regions(pdev);
  10649. disable_device:
  10650. pci_disable_device(pdev);
  10651. fail:
  10652. return err;
  10653. }
  10654. static void advansys_pci_remove(struct pci_dev *pdev)
  10655. {
  10656. advansys_release(pci_get_drvdata(pdev));
  10657. pci_release_regions(pdev);
  10658. pci_disable_device(pdev);
  10659. }
  10660. static struct pci_driver advansys_pci_driver = {
  10661. .name = DRV_NAME,
  10662. .id_table = advansys_pci_tbl,
  10663. .probe = advansys_pci_probe,
  10664. .remove = advansys_pci_remove,
  10665. };
  10666. static int __init advansys_init(void)
  10667. {
  10668. int error;
  10669. error = isa_register_driver(&advansys_isa_driver,
  10670. ASC_IOADR_TABLE_MAX_IX);
  10671. if (error)
  10672. goto fail;
  10673. error = isa_register_driver(&advansys_vlb_driver,
  10674. ASC_IOADR_TABLE_MAX_IX);
  10675. if (error)
  10676. goto unregister_isa;
  10677. error = eisa_driver_register(&advansys_eisa_driver);
  10678. if (error)
  10679. goto unregister_vlb;
  10680. error = pci_register_driver(&advansys_pci_driver);
  10681. if (error)
  10682. goto unregister_eisa;
  10683. return 0;
  10684. unregister_eisa:
  10685. eisa_driver_unregister(&advansys_eisa_driver);
  10686. unregister_vlb:
  10687. isa_unregister_driver(&advansys_vlb_driver);
  10688. unregister_isa:
  10689. isa_unregister_driver(&advansys_isa_driver);
  10690. fail:
  10691. return error;
  10692. }
  10693. static void __exit advansys_exit(void)
  10694. {
  10695. pci_unregister_driver(&advansys_pci_driver);
  10696. eisa_driver_unregister(&advansys_eisa_driver);
  10697. isa_unregister_driver(&advansys_vlb_driver);
  10698. isa_unregister_driver(&advansys_isa_driver);
  10699. }
  10700. module_init(advansys_init);
  10701. module_exit(advansys_exit);
  10702. MODULE_LICENSE("GPL");
  10703. /*(DEBLOBBED)*/