advansys.c 361 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345
  1. #define DRV_NAME "advansys"
  2. #define ASC_VERSION "3.4" /* AdvanSys Driver Version */
  3. /*
  4. * advansys.c - Linux Host Driver for AdvanSys SCSI Adapters
  5. *
  6. * Copyright (c) 1995-2000 Advanced System Products, Inc.
  7. * Copyright (c) 2000-2001 ConnectCom Solutions, Inc.
  8. * Copyright (c) 2007 Matthew Wilcox <matthew@wil.cx>
  9. * All Rights Reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. */
  16. /*
  17. * As of March 8, 2000 Advanced System Products, Inc. (AdvanSys)
  18. * changed its name to ConnectCom Solutions, Inc.
  19. * On June 18, 2001 Initio Corp. acquired ConnectCom's SCSI assets
  20. */
  21. #include <linux/module.h>
  22. #include <linux/string.h>
  23. #include <linux/kernel.h>
  24. #include <linux/types.h>
  25. #include <linux/ioport.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/delay.h>
  28. #include <linux/slab.h>
  29. #include <linux/mm.h>
  30. #include <linux/proc_fs.h>
  31. #include <linux/init.h>
  32. #include <linux/blkdev.h>
  33. #include <linux/isa.h>
  34. #include <linux/eisa.h>
  35. #include <linux/pci.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/dma-mapping.h>
  38. #include <linux/firmware.h>
  39. #include <asm/io.h>
  40. #include <asm/dma.h>
  41. #include <scsi/scsi_cmnd.h>
  42. #include <scsi/scsi_device.h>
  43. #include <scsi/scsi_tcq.h>
  44. #include <scsi/scsi.h>
  45. #include <scsi/scsi_host.h>
  46. /* FIXME:
  47. *
  48. * 1. Although all of the necessary command mapping places have the
  49. * appropriate dma_map.. APIs, the driver still processes its internal
  50. * queue using bus_to_virt() and virt_to_bus() which are illegal under
  51. * the API. The entire queue processing structure will need to be
  52. * altered to fix this.
  53. * 2. Need to add memory mapping workaround. Test the memory mapping.
  54. * If it doesn't work revert to I/O port access. Can a test be done
  55. * safely?
  56. * 3. Handle an interrupt not working. Keep an interrupt counter in
  57. * the interrupt handler. In the timeout function if the interrupt
  58. * has not occurred then print a message and run in polled mode.
  59. * 4. Need to add support for target mode commands, cf. CAM XPT.
  60. * 5. check DMA mapping functions for failure
  61. * 6. Use scsi_transport_spi
  62. * 7. advansys_info is not safe against multiple simultaneous callers
  63. * 8. Add module_param to override ISA/VLB ioport array
  64. */
  65. #warning this driver is still not properly converted to the DMA API
  66. /* Enable driver /proc statistics. */
  67. #define ADVANSYS_STATS
  68. /* Enable driver tracing. */
  69. #undef ADVANSYS_DEBUG
  70. /*
  71. * Portable Data Types
  72. *
  73. * Any instance where a 32-bit long or pointer type is assumed
  74. * for precision or HW defined structures, the following define
  75. * types must be used. In Linux the char, short, and int types
  76. * are all consistent at 8, 16, and 32 bits respectively. Pointers
  77. * and long types are 64 bits on Alpha and UltraSPARC.
  78. */
  79. #define ASC_PADDR __u32 /* Physical/Bus address data type. */
  80. #define ASC_VADDR __u32 /* Virtual address data type. */
  81. #define ASC_DCNT __u32 /* Unsigned Data count type. */
  82. #define ASC_SDCNT __s32 /* Signed Data count type. */
  83. typedef unsigned char uchar;
  84. #ifndef TRUE
  85. #define TRUE (1)
  86. #endif
  87. #ifndef FALSE
  88. #define FALSE (0)
  89. #endif
  90. #define ERR (-1)
  91. #define UW_ERR (uint)(0xFFFF)
  92. #define isodd_word(val) ((((uint)val) & (uint)0x0001) != 0)
  93. #define PCI_VENDOR_ID_ASP 0x10cd
  94. #define PCI_DEVICE_ID_ASP_1200A 0x1100
  95. #define PCI_DEVICE_ID_ASP_ABP940 0x1200
  96. #define PCI_DEVICE_ID_ASP_ABP940U 0x1300
  97. #define PCI_DEVICE_ID_ASP_ABP940UW 0x2300
  98. #define PCI_DEVICE_ID_38C0800_REV1 0x2500
  99. #define PCI_DEVICE_ID_38C1600_REV1 0x2700
  100. /*
  101. * Enable CC_VERY_LONG_SG_LIST to support up to 64K element SG lists.
  102. * The SRB structure will have to be changed and the ASC_SRB2SCSIQ()
  103. * macro re-defined to be able to obtain a ASC_SCSI_Q pointer from the
  104. * SRB structure.
  105. */
  106. #define CC_VERY_LONG_SG_LIST 0
  107. #define ASC_SRB2SCSIQ(srb_ptr) (srb_ptr)
  108. #define PortAddr unsigned int /* port address size */
  109. #define inp(port) inb(port)
  110. #define outp(port, byte) outb((byte), (port))
  111. #define inpw(port) inw(port)
  112. #define outpw(port, word) outw((word), (port))
  113. #define ASC_MAX_SG_QUEUE 7
  114. #define ASC_MAX_SG_LIST 255
  115. #define ASC_CS_TYPE unsigned short
  116. #define ASC_IS_ISA (0x0001)
  117. #define ASC_IS_ISAPNP (0x0081)
  118. #define ASC_IS_EISA (0x0002)
  119. #define ASC_IS_PCI (0x0004)
  120. #define ASC_IS_PCI_ULTRA (0x0104)
  121. #define ASC_IS_PCMCIA (0x0008)
  122. #define ASC_IS_MCA (0x0020)
  123. #define ASC_IS_VL (0x0040)
  124. #define ASC_IS_WIDESCSI_16 (0x0100)
  125. #define ASC_IS_WIDESCSI_32 (0x0200)
  126. #define ASC_IS_BIG_ENDIAN (0x8000)
  127. #define ASC_CHIP_MIN_VER_VL (0x01)
  128. #define ASC_CHIP_MAX_VER_VL (0x07)
  129. #define ASC_CHIP_MIN_VER_PCI (0x09)
  130. #define ASC_CHIP_MAX_VER_PCI (0x0F)
  131. #define ASC_CHIP_VER_PCI_BIT (0x08)
  132. #define ASC_CHIP_MIN_VER_ISA (0x11)
  133. #define ASC_CHIP_MIN_VER_ISA_PNP (0x21)
  134. #define ASC_CHIP_MAX_VER_ISA (0x27)
  135. #define ASC_CHIP_VER_ISA_BIT (0x30)
  136. #define ASC_CHIP_VER_ISAPNP_BIT (0x20)
  137. #define ASC_CHIP_VER_ASYN_BUG (0x21)
  138. #define ASC_CHIP_VER_PCI 0x08
  139. #define ASC_CHIP_VER_PCI_ULTRA_3150 (ASC_CHIP_VER_PCI | 0x02)
  140. #define ASC_CHIP_VER_PCI_ULTRA_3050 (ASC_CHIP_VER_PCI | 0x03)
  141. #define ASC_CHIP_MIN_VER_EISA (0x41)
  142. #define ASC_CHIP_MAX_VER_EISA (0x47)
  143. #define ASC_CHIP_VER_EISA_BIT (0x40)
  144. #define ASC_CHIP_LATEST_VER_EISA ((ASC_CHIP_MIN_VER_EISA - 1) + 3)
  145. #define ASC_MAX_VL_DMA_COUNT (0x07FFFFFFL)
  146. #define ASC_MAX_PCI_DMA_COUNT (0xFFFFFFFFL)
  147. #define ASC_MAX_ISA_DMA_COUNT (0x00FFFFFFL)
  148. #define ASC_SCSI_ID_BITS 3
  149. #define ASC_SCSI_TIX_TYPE uchar
  150. #define ASC_ALL_DEVICE_BIT_SET 0xFF
  151. #define ASC_SCSI_BIT_ID_TYPE uchar
  152. #define ASC_MAX_TID 7
  153. #define ASC_MAX_LUN 7
  154. #define ASC_SCSI_WIDTH_BIT_SET 0xFF
  155. #define ASC_MAX_SENSE_LEN 32
  156. #define ASC_MIN_SENSE_LEN 14
  157. #define ASC_SCSI_RESET_HOLD_TIME_US 60
  158. /*
  159. * Narrow boards only support 12-byte commands, while wide boards
  160. * extend to 16-byte commands.
  161. */
  162. #define ASC_MAX_CDB_LEN 12
  163. #define ADV_MAX_CDB_LEN 16
  164. #define MS_SDTR_LEN 0x03
  165. #define MS_WDTR_LEN 0x02
  166. #define ASC_SG_LIST_PER_Q 7
  167. #define QS_FREE 0x00
  168. #define QS_READY 0x01
  169. #define QS_DISC1 0x02
  170. #define QS_DISC2 0x04
  171. #define QS_BUSY 0x08
  172. #define QS_ABORTED 0x40
  173. #define QS_DONE 0x80
  174. #define QC_NO_CALLBACK 0x01
  175. #define QC_SG_SWAP_QUEUE 0x02
  176. #define QC_SG_HEAD 0x04
  177. #define QC_DATA_IN 0x08
  178. #define QC_DATA_OUT 0x10
  179. #define QC_URGENT 0x20
  180. #define QC_MSG_OUT 0x40
  181. #define QC_REQ_SENSE 0x80
  182. #define QCSG_SG_XFER_LIST 0x02
  183. #define QCSG_SG_XFER_MORE 0x04
  184. #define QCSG_SG_XFER_END 0x08
  185. #define QD_IN_PROGRESS 0x00
  186. #define QD_NO_ERROR 0x01
  187. #define QD_ABORTED_BY_HOST 0x02
  188. #define QD_WITH_ERROR 0x04
  189. #define QD_INVALID_REQUEST 0x80
  190. #define QD_INVALID_HOST_NUM 0x81
  191. #define QD_INVALID_DEVICE 0x82
  192. #define QD_ERR_INTERNAL 0xFF
  193. #define QHSTA_NO_ERROR 0x00
  194. #define QHSTA_M_SEL_TIMEOUT 0x11
  195. #define QHSTA_M_DATA_OVER_RUN 0x12
  196. #define QHSTA_M_DATA_UNDER_RUN 0x12
  197. #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
  198. #define QHSTA_M_BAD_BUS_PHASE_SEQ 0x14
  199. #define QHSTA_D_QDONE_SG_LIST_CORRUPTED 0x21
  200. #define QHSTA_D_ASC_DVC_ERROR_CODE_SET 0x22
  201. #define QHSTA_D_HOST_ABORT_FAILED 0x23
  202. #define QHSTA_D_EXE_SCSI_Q_FAILED 0x24
  203. #define QHSTA_D_EXE_SCSI_Q_BUSY_TIMEOUT 0x25
  204. #define QHSTA_D_ASPI_NO_BUF_POOL 0x26
  205. #define QHSTA_M_WTM_TIMEOUT 0x41
  206. #define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
  207. #define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
  208. #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
  209. #define QHSTA_M_TARGET_STATUS_BUSY 0x45
  210. #define QHSTA_M_BAD_TAG_CODE 0x46
  211. #define QHSTA_M_BAD_QUEUE_FULL_OR_BUSY 0x47
  212. #define QHSTA_M_HUNG_REQ_SCSI_BUS_RESET 0x48
  213. #define QHSTA_D_LRAM_CMP_ERROR 0x81
  214. #define QHSTA_M_MICRO_CODE_ERROR_HALT 0xA1
  215. #define ASC_FLAG_SCSIQ_REQ 0x01
  216. #define ASC_FLAG_BIOS_SCSIQ_REQ 0x02
  217. #define ASC_FLAG_BIOS_ASYNC_IO 0x04
  218. #define ASC_FLAG_SRB_LINEAR_ADDR 0x08
  219. #define ASC_FLAG_WIN16 0x10
  220. #define ASC_FLAG_WIN32 0x20
  221. #define ASC_FLAG_ISA_OVER_16MB 0x40
  222. #define ASC_FLAG_DOS_VM_CALLBACK 0x80
  223. #define ASC_TAG_FLAG_EXTRA_BYTES 0x10
  224. #define ASC_TAG_FLAG_DISABLE_DISCONNECT 0x04
  225. #define ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX 0x08
  226. #define ASC_TAG_FLAG_DISABLE_CHK_COND_INT_HOST 0x40
  227. #define ASC_SCSIQ_CPY_BEG 4
  228. #define ASC_SCSIQ_SGHD_CPY_BEG 2
  229. #define ASC_SCSIQ_B_FWD 0
  230. #define ASC_SCSIQ_B_BWD 1
  231. #define ASC_SCSIQ_B_STATUS 2
  232. #define ASC_SCSIQ_B_QNO 3
  233. #define ASC_SCSIQ_B_CNTL 4
  234. #define ASC_SCSIQ_B_SG_QUEUE_CNT 5
  235. #define ASC_SCSIQ_D_DATA_ADDR 8
  236. #define ASC_SCSIQ_D_DATA_CNT 12
  237. #define ASC_SCSIQ_B_SENSE_LEN 20
  238. #define ASC_SCSIQ_DONE_INFO_BEG 22
  239. #define ASC_SCSIQ_D_SRBPTR 22
  240. #define ASC_SCSIQ_B_TARGET_IX 26
  241. #define ASC_SCSIQ_B_CDB_LEN 28
  242. #define ASC_SCSIQ_B_TAG_CODE 29
  243. #define ASC_SCSIQ_W_VM_ID 30
  244. #define ASC_SCSIQ_DONE_STATUS 32
  245. #define ASC_SCSIQ_HOST_STATUS 33
  246. #define ASC_SCSIQ_SCSI_STATUS 34
  247. #define ASC_SCSIQ_CDB_BEG 36
  248. #define ASC_SCSIQ_DW_REMAIN_XFER_ADDR 56
  249. #define ASC_SCSIQ_DW_REMAIN_XFER_CNT 60
  250. #define ASC_SCSIQ_B_FIRST_SG_WK_QP 48
  251. #define ASC_SCSIQ_B_SG_WK_QP 49
  252. #define ASC_SCSIQ_B_SG_WK_IX 50
  253. #define ASC_SCSIQ_W_ALT_DC1 52
  254. #define ASC_SCSIQ_B_LIST_CNT 6
  255. #define ASC_SCSIQ_B_CUR_LIST_CNT 7
  256. #define ASC_SGQ_B_SG_CNTL 4
  257. #define ASC_SGQ_B_SG_HEAD_QP 5
  258. #define ASC_SGQ_B_SG_LIST_CNT 6
  259. #define ASC_SGQ_B_SG_CUR_LIST_CNT 7
  260. #define ASC_SGQ_LIST_BEG 8
  261. #define ASC_DEF_SCSI1_QNG 4
  262. #define ASC_MAX_SCSI1_QNG 4
  263. #define ASC_DEF_SCSI2_QNG 16
  264. #define ASC_MAX_SCSI2_QNG 32
  265. #define ASC_TAG_CODE_MASK 0x23
  266. #define ASC_STOP_REQ_RISC_STOP 0x01
  267. #define ASC_STOP_ACK_RISC_STOP 0x03
  268. #define ASC_STOP_CLEAN_UP_BUSY_Q 0x10
  269. #define ASC_STOP_CLEAN_UP_DISC_Q 0x20
  270. #define ASC_STOP_HOST_REQ_RISC_HALT 0x40
  271. #define ASC_TIDLUN_TO_IX(tid, lun) (ASC_SCSI_TIX_TYPE)((tid) + ((lun)<<ASC_SCSI_ID_BITS))
  272. #define ASC_TID_TO_TARGET_ID(tid) (ASC_SCSI_BIT_ID_TYPE)(0x01 << (tid))
  273. #define ASC_TIX_TO_TARGET_ID(tix) (0x01 << ((tix) & ASC_MAX_TID))
  274. #define ASC_TIX_TO_TID(tix) ((tix) & ASC_MAX_TID)
  275. #define ASC_TID_TO_TIX(tid) ((tid) & ASC_MAX_TID)
  276. #define ASC_TIX_TO_LUN(tix) (((tix) >> ASC_SCSI_ID_BITS) & ASC_MAX_LUN)
  277. #define ASC_QNO_TO_QADDR(q_no) ((ASC_QADR_BEG)+((int)(q_no) << 6))
  278. typedef struct asc_scsiq_1 {
  279. uchar status;
  280. uchar q_no;
  281. uchar cntl;
  282. uchar sg_queue_cnt;
  283. uchar target_id;
  284. uchar target_lun;
  285. ASC_PADDR data_addr;
  286. ASC_DCNT data_cnt;
  287. ASC_PADDR sense_addr;
  288. uchar sense_len;
  289. uchar extra_bytes;
  290. } ASC_SCSIQ_1;
  291. typedef struct asc_scsiq_2 {
  292. ASC_VADDR srb_ptr;
  293. uchar target_ix;
  294. uchar flag;
  295. uchar cdb_len;
  296. uchar tag_code;
  297. ushort vm_id;
  298. } ASC_SCSIQ_2;
  299. typedef struct asc_scsiq_3 {
  300. uchar done_stat;
  301. uchar host_stat;
  302. uchar scsi_stat;
  303. uchar scsi_msg;
  304. } ASC_SCSIQ_3;
  305. typedef struct asc_scsiq_4 {
  306. uchar cdb[ASC_MAX_CDB_LEN];
  307. uchar y_first_sg_list_qp;
  308. uchar y_working_sg_qp;
  309. uchar y_working_sg_ix;
  310. uchar y_res;
  311. ushort x_req_count;
  312. ushort x_reconnect_rtn;
  313. ASC_PADDR x_saved_data_addr;
  314. ASC_DCNT x_saved_data_cnt;
  315. } ASC_SCSIQ_4;
  316. typedef struct asc_q_done_info {
  317. ASC_SCSIQ_2 d2;
  318. ASC_SCSIQ_3 d3;
  319. uchar q_status;
  320. uchar q_no;
  321. uchar cntl;
  322. uchar sense_len;
  323. uchar extra_bytes;
  324. uchar res;
  325. ASC_DCNT remain_bytes;
  326. } ASC_QDONE_INFO;
  327. typedef struct asc_sg_list {
  328. ASC_PADDR addr;
  329. ASC_DCNT bytes;
  330. } ASC_SG_LIST;
  331. typedef struct asc_sg_head {
  332. ushort entry_cnt;
  333. ushort queue_cnt;
  334. ushort entry_to_copy;
  335. ushort res;
  336. ASC_SG_LIST sg_list[0];
  337. } ASC_SG_HEAD;
  338. typedef struct asc_scsi_q {
  339. ASC_SCSIQ_1 q1;
  340. ASC_SCSIQ_2 q2;
  341. uchar *cdbptr;
  342. ASC_SG_HEAD *sg_head;
  343. ushort remain_sg_entry_cnt;
  344. ushort next_sg_index;
  345. } ASC_SCSI_Q;
  346. typedef struct asc_scsi_req_q {
  347. ASC_SCSIQ_1 r1;
  348. ASC_SCSIQ_2 r2;
  349. uchar *cdbptr;
  350. ASC_SG_HEAD *sg_head;
  351. uchar *sense_ptr;
  352. ASC_SCSIQ_3 r3;
  353. uchar cdb[ASC_MAX_CDB_LEN];
  354. uchar sense[ASC_MIN_SENSE_LEN];
  355. } ASC_SCSI_REQ_Q;
  356. typedef struct asc_scsi_bios_req_q {
  357. ASC_SCSIQ_1 r1;
  358. ASC_SCSIQ_2 r2;
  359. uchar *cdbptr;
  360. ASC_SG_HEAD *sg_head;
  361. uchar *sense_ptr;
  362. ASC_SCSIQ_3 r3;
  363. uchar cdb[ASC_MAX_CDB_LEN];
  364. uchar sense[ASC_MIN_SENSE_LEN];
  365. } ASC_SCSI_BIOS_REQ_Q;
  366. typedef struct asc_risc_q {
  367. uchar fwd;
  368. uchar bwd;
  369. ASC_SCSIQ_1 i1;
  370. ASC_SCSIQ_2 i2;
  371. ASC_SCSIQ_3 i3;
  372. ASC_SCSIQ_4 i4;
  373. } ASC_RISC_Q;
  374. typedef struct asc_sg_list_q {
  375. uchar seq_no;
  376. uchar q_no;
  377. uchar cntl;
  378. uchar sg_head_qp;
  379. uchar sg_list_cnt;
  380. uchar sg_cur_list_cnt;
  381. } ASC_SG_LIST_Q;
  382. typedef struct asc_risc_sg_list_q {
  383. uchar fwd;
  384. uchar bwd;
  385. ASC_SG_LIST_Q sg;
  386. ASC_SG_LIST sg_list[7];
  387. } ASC_RISC_SG_LIST_Q;
  388. #define ASCQ_ERR_Q_STATUS 0x0D
  389. #define ASCQ_ERR_CUR_QNG 0x17
  390. #define ASCQ_ERR_SG_Q_LINKS 0x18
  391. #define ASCQ_ERR_ISR_RE_ENTRY 0x1A
  392. #define ASCQ_ERR_CRITICAL_RE_ENTRY 0x1B
  393. #define ASCQ_ERR_ISR_ON_CRITICAL 0x1C
  394. /*
  395. * Warning code values are set in ASC_DVC_VAR 'warn_code'.
  396. */
  397. #define ASC_WARN_NO_ERROR 0x0000
  398. #define ASC_WARN_IO_PORT_ROTATE 0x0001
  399. #define ASC_WARN_EEPROM_CHKSUM 0x0002
  400. #define ASC_WARN_IRQ_MODIFIED 0x0004
  401. #define ASC_WARN_AUTO_CONFIG 0x0008
  402. #define ASC_WARN_CMD_QNG_CONFLICT 0x0010
  403. #define ASC_WARN_EEPROM_RECOVER 0x0020
  404. #define ASC_WARN_CFG_MSW_RECOVER 0x0040
  405. /*
  406. * Error code values are set in {ASC/ADV}_DVC_VAR 'err_code'.
  407. */
  408. #define ASC_IERR_NO_CARRIER 0x0001 /* No more carrier memory */
  409. #define ASC_IERR_MCODE_CHKSUM 0x0002 /* micro code check sum error */
  410. #define ASC_IERR_SET_PC_ADDR 0x0004
  411. #define ASC_IERR_START_STOP_CHIP 0x0008 /* start/stop chip failed */
  412. #define ASC_IERR_ILLEGAL_CONNECTION 0x0010 /* Illegal cable connection */
  413. #define ASC_IERR_SINGLE_END_DEVICE 0x0020 /* SE device on DIFF bus */
  414. #define ASC_IERR_REVERSED_CABLE 0x0040 /* Narrow flat cable reversed */
  415. #define ASC_IERR_SET_SCSI_ID 0x0080 /* set SCSI ID failed */
  416. #define ASC_IERR_HVD_DEVICE 0x0100 /* HVD device on LVD port */
  417. #define ASC_IERR_BAD_SIGNATURE 0x0200 /* signature not found */
  418. #define ASC_IERR_NO_BUS_TYPE 0x0400
  419. #define ASC_IERR_BIST_PRE_TEST 0x0800 /* BIST pre-test error */
  420. #define ASC_IERR_BIST_RAM_TEST 0x1000 /* BIST RAM test error */
  421. #define ASC_IERR_BAD_CHIPTYPE 0x2000 /* Invalid chip_type setting */
  422. #define ASC_DEF_MAX_TOTAL_QNG (0xF0)
  423. #define ASC_MIN_TAG_Q_PER_DVC (0x04)
  424. #define ASC_MIN_FREE_Q (0x02)
  425. #define ASC_MIN_TOTAL_QNG ((ASC_MAX_SG_QUEUE)+(ASC_MIN_FREE_Q))
  426. #define ASC_MAX_TOTAL_QNG 240
  427. #define ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG 16
  428. #define ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG 8
  429. #define ASC_MAX_PCI_INRAM_TOTAL_QNG 20
  430. #define ASC_MAX_INRAM_TAG_QNG 16
  431. #define ASC_IOADR_GAP 0x10
  432. #define ASC_SYN_MAX_OFFSET 0x0F
  433. #define ASC_DEF_SDTR_OFFSET 0x0F
  434. #define ASC_SDTR_ULTRA_PCI_10MB_INDEX 0x02
  435. #define ASYN_SDTR_DATA_FIX_PCI_REV_AB 0x41
  436. /* The narrow chip only supports a limited selection of transfer rates.
  437. * These are encoded in the range 0..7 or 0..15 depending whether the chip
  438. * is Ultra-capable or not. These tables let us convert from one to the other.
  439. */
  440. static const unsigned char asc_syn_xfer_period[8] = {
  441. 25, 30, 35, 40, 50, 60, 70, 85
  442. };
  443. static const unsigned char asc_syn_ultra_xfer_period[16] = {
  444. 12, 19, 25, 32, 38, 44, 50, 57, 63, 69, 75, 82, 88, 94, 100, 107
  445. };
  446. typedef struct ext_msg {
  447. uchar msg_type;
  448. uchar msg_len;
  449. uchar msg_req;
  450. union {
  451. struct {
  452. uchar sdtr_xfer_period;
  453. uchar sdtr_req_ack_offset;
  454. } sdtr;
  455. struct {
  456. uchar wdtr_width;
  457. } wdtr;
  458. struct {
  459. uchar mdp_b3;
  460. uchar mdp_b2;
  461. uchar mdp_b1;
  462. uchar mdp_b0;
  463. } mdp;
  464. } u_ext_msg;
  465. uchar res;
  466. } EXT_MSG;
  467. #define xfer_period u_ext_msg.sdtr.sdtr_xfer_period
  468. #define req_ack_offset u_ext_msg.sdtr.sdtr_req_ack_offset
  469. #define wdtr_width u_ext_msg.wdtr.wdtr_width
  470. #define mdp_b3 u_ext_msg.mdp_b3
  471. #define mdp_b2 u_ext_msg.mdp_b2
  472. #define mdp_b1 u_ext_msg.mdp_b1
  473. #define mdp_b0 u_ext_msg.mdp_b0
  474. typedef struct asc_dvc_cfg {
  475. ASC_SCSI_BIT_ID_TYPE can_tagged_qng;
  476. ASC_SCSI_BIT_ID_TYPE cmd_qng_enabled;
  477. ASC_SCSI_BIT_ID_TYPE disc_enable;
  478. ASC_SCSI_BIT_ID_TYPE sdtr_enable;
  479. uchar chip_scsi_id;
  480. uchar isa_dma_speed;
  481. uchar isa_dma_channel;
  482. uchar chip_version;
  483. ushort mcode_date;
  484. ushort mcode_version;
  485. uchar max_tag_qng[ASC_MAX_TID + 1];
  486. uchar sdtr_period_offset[ASC_MAX_TID + 1];
  487. uchar adapter_info[6];
  488. } ASC_DVC_CFG;
  489. #define ASC_DEF_DVC_CNTL 0xFFFF
  490. #define ASC_DEF_CHIP_SCSI_ID 7
  491. #define ASC_DEF_ISA_DMA_SPEED 4
  492. #define ASC_INIT_STATE_BEG_GET_CFG 0x0001
  493. #define ASC_INIT_STATE_END_GET_CFG 0x0002
  494. #define ASC_INIT_STATE_BEG_SET_CFG 0x0004
  495. #define ASC_INIT_STATE_END_SET_CFG 0x0008
  496. #define ASC_INIT_STATE_BEG_LOAD_MC 0x0010
  497. #define ASC_INIT_STATE_END_LOAD_MC 0x0020
  498. #define ASC_INIT_STATE_BEG_INQUIRY 0x0040
  499. #define ASC_INIT_STATE_END_INQUIRY 0x0080
  500. #define ASC_INIT_RESET_SCSI_DONE 0x0100
  501. #define ASC_INIT_STATE_WITHOUT_EEP 0x8000
  502. #define ASC_BUG_FIX_IF_NOT_DWB 0x0001
  503. #define ASC_BUG_FIX_ASYN_USE_SYN 0x0002
  504. #define ASC_MIN_TAGGED_CMD 7
  505. #define ASC_MAX_SCSI_RESET_WAIT 30
  506. #define ASC_OVERRUN_BSIZE 64
  507. struct asc_dvc_var; /* Forward Declaration. */
  508. typedef struct asc_dvc_var {
  509. PortAddr iop_base;
  510. ushort err_code;
  511. ushort dvc_cntl;
  512. ushort bug_fix_cntl;
  513. ushort bus_type;
  514. ASC_SCSI_BIT_ID_TYPE init_sdtr;
  515. ASC_SCSI_BIT_ID_TYPE sdtr_done;
  516. ASC_SCSI_BIT_ID_TYPE use_tagged_qng;
  517. ASC_SCSI_BIT_ID_TYPE unit_not_ready;
  518. ASC_SCSI_BIT_ID_TYPE queue_full_or_busy;
  519. ASC_SCSI_BIT_ID_TYPE start_motor;
  520. uchar *overrun_buf;
  521. dma_addr_t overrun_dma;
  522. uchar scsi_reset_wait;
  523. uchar chip_no;
  524. char is_in_int;
  525. uchar max_total_qng;
  526. uchar cur_total_qng;
  527. uchar in_critical_cnt;
  528. uchar last_q_shortage;
  529. ushort init_state;
  530. uchar cur_dvc_qng[ASC_MAX_TID + 1];
  531. uchar max_dvc_qng[ASC_MAX_TID + 1];
  532. ASC_SCSI_Q *scsiq_busy_head[ASC_MAX_TID + 1];
  533. ASC_SCSI_Q *scsiq_busy_tail[ASC_MAX_TID + 1];
  534. const uchar *sdtr_period_tbl;
  535. ASC_DVC_CFG *cfg;
  536. ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer_always;
  537. char redo_scam;
  538. ushort res2;
  539. uchar dos_int13_table[ASC_MAX_TID + 1];
  540. ASC_DCNT max_dma_count;
  541. ASC_SCSI_BIT_ID_TYPE no_scam;
  542. ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer;
  543. uchar min_sdtr_index;
  544. uchar max_sdtr_index;
  545. struct asc_board *drv_ptr;
  546. int ptr_map_count;
  547. void **ptr_map;
  548. ASC_DCNT uc_break;
  549. } ASC_DVC_VAR;
  550. typedef struct asc_dvc_inq_info {
  551. uchar type[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
  552. } ASC_DVC_INQ_INFO;
  553. typedef struct asc_cap_info {
  554. ASC_DCNT lba;
  555. ASC_DCNT blk_size;
  556. } ASC_CAP_INFO;
  557. typedef struct asc_cap_info_array {
  558. ASC_CAP_INFO cap_info[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
  559. } ASC_CAP_INFO_ARRAY;
  560. #define ASC_MCNTL_NO_SEL_TIMEOUT (ushort)0x0001
  561. #define ASC_MCNTL_NULL_TARGET (ushort)0x0002
  562. #define ASC_CNTL_INITIATOR (ushort)0x0001
  563. #define ASC_CNTL_BIOS_GT_1GB (ushort)0x0002
  564. #define ASC_CNTL_BIOS_GT_2_DISK (ushort)0x0004
  565. #define ASC_CNTL_BIOS_REMOVABLE (ushort)0x0008
  566. #define ASC_CNTL_NO_SCAM (ushort)0x0010
  567. #define ASC_CNTL_INT_MULTI_Q (ushort)0x0080
  568. #define ASC_CNTL_NO_LUN_SUPPORT (ushort)0x0040
  569. #define ASC_CNTL_NO_VERIFY_COPY (ushort)0x0100
  570. #define ASC_CNTL_RESET_SCSI (ushort)0x0200
  571. #define ASC_CNTL_INIT_INQUIRY (ushort)0x0400
  572. #define ASC_CNTL_INIT_VERBOSE (ushort)0x0800
  573. #define ASC_CNTL_SCSI_PARITY (ushort)0x1000
  574. #define ASC_CNTL_BURST_MODE (ushort)0x2000
  575. #define ASC_CNTL_SDTR_ENABLE_ULTRA (ushort)0x4000
  576. #define ASC_EEP_DVC_CFG_BEG_VL 2
  577. #define ASC_EEP_MAX_DVC_ADDR_VL 15
  578. #define ASC_EEP_DVC_CFG_BEG 32
  579. #define ASC_EEP_MAX_DVC_ADDR 45
  580. #define ASC_EEP_MAX_RETRY 20
  581. /*
  582. * These macros keep the chip SCSI id and ISA DMA speed
  583. * bitfields in board order. C bitfields aren't portable
  584. * between big and little-endian platforms so they are
  585. * not used.
  586. */
  587. #define ASC_EEP_GET_CHIP_ID(cfg) ((cfg)->id_speed & 0x0f)
  588. #define ASC_EEP_GET_DMA_SPD(cfg) (((cfg)->id_speed & 0xf0) >> 4)
  589. #define ASC_EEP_SET_CHIP_ID(cfg, sid) \
  590. ((cfg)->id_speed = ((cfg)->id_speed & 0xf0) | ((sid) & ASC_MAX_TID))
  591. #define ASC_EEP_SET_DMA_SPD(cfg, spd) \
  592. ((cfg)->id_speed = ((cfg)->id_speed & 0x0f) | ((spd) & 0x0f) << 4)
  593. typedef struct asceep_config {
  594. ushort cfg_lsw;
  595. ushort cfg_msw;
  596. uchar init_sdtr;
  597. uchar disc_enable;
  598. uchar use_cmd_qng;
  599. uchar start_motor;
  600. uchar max_total_qng;
  601. uchar max_tag_qng;
  602. uchar bios_scan;
  603. uchar power_up_wait;
  604. uchar no_scam;
  605. uchar id_speed; /* low order 4 bits is chip scsi id */
  606. /* high order 4 bits is isa dma speed */
  607. uchar dos_int13_table[ASC_MAX_TID + 1];
  608. uchar adapter_info[6];
  609. ushort cntl;
  610. ushort chksum;
  611. } ASCEEP_CONFIG;
  612. #define ASC_EEP_CMD_READ 0x80
  613. #define ASC_EEP_CMD_WRITE 0x40
  614. #define ASC_EEP_CMD_WRITE_ABLE 0x30
  615. #define ASC_EEP_CMD_WRITE_DISABLE 0x00
  616. #define ASCV_MSGOUT_BEG 0x0000
  617. #define ASCV_MSGOUT_SDTR_PERIOD (ASCV_MSGOUT_BEG+3)
  618. #define ASCV_MSGOUT_SDTR_OFFSET (ASCV_MSGOUT_BEG+4)
  619. #define ASCV_BREAK_SAVED_CODE (ushort)0x0006
  620. #define ASCV_MSGIN_BEG (ASCV_MSGOUT_BEG+8)
  621. #define ASCV_MSGIN_SDTR_PERIOD (ASCV_MSGIN_BEG+3)
  622. #define ASCV_MSGIN_SDTR_OFFSET (ASCV_MSGIN_BEG+4)
  623. #define ASCV_SDTR_DATA_BEG (ASCV_MSGIN_BEG+8)
  624. #define ASCV_SDTR_DONE_BEG (ASCV_SDTR_DATA_BEG+8)
  625. #define ASCV_MAX_DVC_QNG_BEG (ushort)0x0020
  626. #define ASCV_BREAK_ADDR (ushort)0x0028
  627. #define ASCV_BREAK_NOTIFY_COUNT (ushort)0x002A
  628. #define ASCV_BREAK_CONTROL (ushort)0x002C
  629. #define ASCV_BREAK_HIT_COUNT (ushort)0x002E
  630. #define ASCV_ASCDVC_ERR_CODE_W (ushort)0x0030
  631. #define ASCV_MCODE_CHKSUM_W (ushort)0x0032
  632. #define ASCV_MCODE_SIZE_W (ushort)0x0034
  633. #define ASCV_STOP_CODE_B (ushort)0x0036
  634. #define ASCV_DVC_ERR_CODE_B (ushort)0x0037
  635. #define ASCV_OVERRUN_PADDR_D (ushort)0x0038
  636. #define ASCV_OVERRUN_BSIZE_D (ushort)0x003C
  637. #define ASCV_HALTCODE_W (ushort)0x0040
  638. #define ASCV_CHKSUM_W (ushort)0x0042
  639. #define ASCV_MC_DATE_W (ushort)0x0044
  640. #define ASCV_MC_VER_W (ushort)0x0046
  641. #define ASCV_NEXTRDY_B (ushort)0x0048
  642. #define ASCV_DONENEXT_B (ushort)0x0049
  643. #define ASCV_USE_TAGGED_QNG_B (ushort)0x004A
  644. #define ASCV_SCSIBUSY_B (ushort)0x004B
  645. #define ASCV_Q_DONE_IN_PROGRESS_B (ushort)0x004C
  646. #define ASCV_CURCDB_B (ushort)0x004D
  647. #define ASCV_RCLUN_B (ushort)0x004E
  648. #define ASCV_BUSY_QHEAD_B (ushort)0x004F
  649. #define ASCV_DISC1_QHEAD_B (ushort)0x0050
  650. #define ASCV_DISC_ENABLE_B (ushort)0x0052
  651. #define ASCV_CAN_TAGGED_QNG_B (ushort)0x0053
  652. #define ASCV_HOSTSCSI_ID_B (ushort)0x0055
  653. #define ASCV_MCODE_CNTL_B (ushort)0x0056
  654. #define ASCV_NULL_TARGET_B (ushort)0x0057
  655. #define ASCV_FREE_Q_HEAD_W (ushort)0x0058
  656. #define ASCV_DONE_Q_TAIL_W (ushort)0x005A
  657. #define ASCV_FREE_Q_HEAD_B (ushort)(ASCV_FREE_Q_HEAD_W+1)
  658. #define ASCV_DONE_Q_TAIL_B (ushort)(ASCV_DONE_Q_TAIL_W+1)
  659. #define ASCV_HOST_FLAG_B (ushort)0x005D
  660. #define ASCV_TOTAL_READY_Q_B (ushort)0x0064
  661. #define ASCV_VER_SERIAL_B (ushort)0x0065
  662. #define ASCV_HALTCODE_SAVED_W (ushort)0x0066
  663. #define ASCV_WTM_FLAG_B (ushort)0x0068
  664. #define ASCV_RISC_FLAG_B (ushort)0x006A
  665. #define ASCV_REQ_SG_LIST_QP (ushort)0x006B
  666. #define ASC_HOST_FLAG_IN_ISR 0x01
  667. #define ASC_HOST_FLAG_ACK_INT 0x02
  668. #define ASC_RISC_FLAG_GEN_INT 0x01
  669. #define ASC_RISC_FLAG_REQ_SG_LIST 0x02
  670. #define IOP_CTRL (0x0F)
  671. #define IOP_STATUS (0x0E)
  672. #define IOP_INT_ACK IOP_STATUS
  673. #define IOP_REG_IFC (0x0D)
  674. #define IOP_SYN_OFFSET (0x0B)
  675. #define IOP_EXTRA_CONTROL (0x0D)
  676. #define IOP_REG_PC (0x0C)
  677. #define IOP_RAM_ADDR (0x0A)
  678. #define IOP_RAM_DATA (0x08)
  679. #define IOP_EEP_DATA (0x06)
  680. #define IOP_EEP_CMD (0x07)
  681. #define IOP_VERSION (0x03)
  682. #define IOP_CONFIG_HIGH (0x04)
  683. #define IOP_CONFIG_LOW (0x02)
  684. #define IOP_SIG_BYTE (0x01)
  685. #define IOP_SIG_WORD (0x00)
  686. #define IOP_REG_DC1 (0x0E)
  687. #define IOP_REG_DC0 (0x0C)
  688. #define IOP_REG_SB (0x0B)
  689. #define IOP_REG_DA1 (0x0A)
  690. #define IOP_REG_DA0 (0x08)
  691. #define IOP_REG_SC (0x09)
  692. #define IOP_DMA_SPEED (0x07)
  693. #define IOP_REG_FLAG (0x07)
  694. #define IOP_FIFO_H (0x06)
  695. #define IOP_FIFO_L (0x04)
  696. #define IOP_REG_ID (0x05)
  697. #define IOP_REG_QP (0x03)
  698. #define IOP_REG_IH (0x02)
  699. #define IOP_REG_IX (0x01)
  700. #define IOP_REG_AX (0x00)
  701. #define IFC_REG_LOCK (0x00)
  702. #define IFC_REG_UNLOCK (0x09)
  703. #define IFC_WR_EN_FILTER (0x10)
  704. #define IFC_RD_NO_EEPROM (0x10)
  705. #define IFC_SLEW_RATE (0x20)
  706. #define IFC_ACT_NEG (0x40)
  707. #define IFC_INP_FILTER (0x80)
  708. #define IFC_INIT_DEFAULT (IFC_ACT_NEG | IFC_REG_UNLOCK)
  709. #define SC_SEL (uchar)(0x80)
  710. #define SC_BSY (uchar)(0x40)
  711. #define SC_ACK (uchar)(0x20)
  712. #define SC_REQ (uchar)(0x10)
  713. #define SC_ATN (uchar)(0x08)
  714. #define SC_IO (uchar)(0x04)
  715. #define SC_CD (uchar)(0x02)
  716. #define SC_MSG (uchar)(0x01)
  717. #define SEC_SCSI_CTL (uchar)(0x80)
  718. #define SEC_ACTIVE_NEGATE (uchar)(0x40)
  719. #define SEC_SLEW_RATE (uchar)(0x20)
  720. #define SEC_ENABLE_FILTER (uchar)(0x10)
  721. #define ASC_HALT_EXTMSG_IN (ushort)0x8000
  722. #define ASC_HALT_CHK_CONDITION (ushort)0x8100
  723. #define ASC_HALT_SS_QUEUE_FULL (ushort)0x8200
  724. #define ASC_HALT_DISABLE_ASYN_USE_SYN_FIX (ushort)0x8300
  725. #define ASC_HALT_ENABLE_ASYN_USE_SYN_FIX (ushort)0x8400
  726. #define ASC_HALT_SDTR_REJECTED (ushort)0x4000
  727. #define ASC_HALT_HOST_COPY_SG_LIST_TO_RISC ( ushort )0x2000
  728. #define ASC_MAX_QNO 0xF8
  729. #define ASC_DATA_SEC_BEG (ushort)0x0080
  730. #define ASC_DATA_SEC_END (ushort)0x0080
  731. #define ASC_CODE_SEC_BEG (ushort)0x0080
  732. #define ASC_CODE_SEC_END (ushort)0x0080
  733. #define ASC_QADR_BEG (0x4000)
  734. #define ASC_QADR_USED (ushort)(ASC_MAX_QNO * 64)
  735. #define ASC_QADR_END (ushort)0x7FFF
  736. #define ASC_QLAST_ADR (ushort)0x7FC0
  737. #define ASC_QBLK_SIZE 0x40
  738. #define ASC_BIOS_DATA_QBEG 0xF8
  739. #define ASC_MIN_ACTIVE_QNO 0x01
  740. #define ASC_QLINK_END 0xFF
  741. #define ASC_EEPROM_WORDS 0x10
  742. #define ASC_MAX_MGS_LEN 0x10
  743. #define ASC_BIOS_ADDR_DEF 0xDC00
  744. #define ASC_BIOS_SIZE 0x3800
  745. #define ASC_BIOS_RAM_OFF 0x3800
  746. #define ASC_BIOS_RAM_SIZE 0x800
  747. #define ASC_BIOS_MIN_ADDR 0xC000
  748. #define ASC_BIOS_MAX_ADDR 0xEC00
  749. #define ASC_BIOS_BANK_SIZE 0x0400
  750. #define ASC_MCODE_START_ADDR 0x0080
  751. #define ASC_CFG0_HOST_INT_ON 0x0020
  752. #define ASC_CFG0_BIOS_ON 0x0040
  753. #define ASC_CFG0_VERA_BURST_ON 0x0080
  754. #define ASC_CFG0_SCSI_PARITY_ON 0x0800
  755. #define ASC_CFG1_SCSI_TARGET_ON 0x0080
  756. #define ASC_CFG1_LRAM_8BITS_ON 0x0800
  757. #define ASC_CFG_MSW_CLR_MASK 0x3080
  758. #define CSW_TEST1 (ASC_CS_TYPE)0x8000
  759. #define CSW_AUTO_CONFIG (ASC_CS_TYPE)0x4000
  760. #define CSW_RESERVED1 (ASC_CS_TYPE)0x2000
  761. #define CSW_IRQ_WRITTEN (ASC_CS_TYPE)0x1000
  762. #define CSW_33MHZ_SELECTED (ASC_CS_TYPE)0x0800
  763. #define CSW_TEST2 (ASC_CS_TYPE)0x0400
  764. #define CSW_TEST3 (ASC_CS_TYPE)0x0200
  765. #define CSW_RESERVED2 (ASC_CS_TYPE)0x0100
  766. #define CSW_DMA_DONE (ASC_CS_TYPE)0x0080
  767. #define CSW_FIFO_RDY (ASC_CS_TYPE)0x0040
  768. #define CSW_EEP_READ_DONE (ASC_CS_TYPE)0x0020
  769. #define CSW_HALTED (ASC_CS_TYPE)0x0010
  770. #define CSW_SCSI_RESET_ACTIVE (ASC_CS_TYPE)0x0008
  771. #define CSW_PARITY_ERR (ASC_CS_TYPE)0x0004
  772. #define CSW_SCSI_RESET_LATCH (ASC_CS_TYPE)0x0002
  773. #define CSW_INT_PENDING (ASC_CS_TYPE)0x0001
  774. #define CIW_CLR_SCSI_RESET_INT (ASC_CS_TYPE)0x1000
  775. #define CIW_INT_ACK (ASC_CS_TYPE)0x0100
  776. #define CIW_TEST1 (ASC_CS_TYPE)0x0200
  777. #define CIW_TEST2 (ASC_CS_TYPE)0x0400
  778. #define CIW_SEL_33MHZ (ASC_CS_TYPE)0x0800
  779. #define CIW_IRQ_ACT (ASC_CS_TYPE)0x1000
  780. #define CC_CHIP_RESET (uchar)0x80
  781. #define CC_SCSI_RESET (uchar)0x40
  782. #define CC_HALT (uchar)0x20
  783. #define CC_SINGLE_STEP (uchar)0x10
  784. #define CC_DMA_ABLE (uchar)0x08
  785. #define CC_TEST (uchar)0x04
  786. #define CC_BANK_ONE (uchar)0x02
  787. #define CC_DIAG (uchar)0x01
  788. #define ASC_1000_ID0W 0x04C1
  789. #define ASC_1000_ID0W_FIX 0x00C1
  790. #define ASC_1000_ID1B 0x25
  791. #define ASC_EISA_REV_IOP_MASK (0x0C83)
  792. #define ASC_EISA_CFG_IOP_MASK (0x0C86)
  793. #define ASC_GET_EISA_SLOT(iop) (PortAddr)((iop) & 0xF000)
  794. #define INS_HALTINT (ushort)0x6281
  795. #define INS_HALT (ushort)0x6280
  796. #define INS_SINT (ushort)0x6200
  797. #define INS_RFLAG_WTM (ushort)0x7380
  798. #define ASC_MC_SAVE_CODE_WSIZE 0x500
  799. #define ASC_MC_SAVE_DATA_WSIZE 0x40
  800. typedef struct asc_mc_saved {
  801. ushort data[ASC_MC_SAVE_DATA_WSIZE];
  802. ushort code[ASC_MC_SAVE_CODE_WSIZE];
  803. } ASC_MC_SAVED;
  804. #define AscGetQDoneInProgress(port) AscReadLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B)
  805. #define AscPutQDoneInProgress(port, val) AscWriteLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B, val)
  806. #define AscGetVarFreeQHead(port) AscReadLramWord((port), ASCV_FREE_Q_HEAD_W)
  807. #define AscGetVarDoneQTail(port) AscReadLramWord((port), ASCV_DONE_Q_TAIL_W)
  808. #define AscPutVarFreeQHead(port, val) AscWriteLramWord((port), ASCV_FREE_Q_HEAD_W, val)
  809. #define AscPutVarDoneQTail(port, val) AscWriteLramWord((port), ASCV_DONE_Q_TAIL_W, val)
  810. #define AscGetRiscVarFreeQHead(port) AscReadLramByte((port), ASCV_NEXTRDY_B)
  811. #define AscGetRiscVarDoneQTail(port) AscReadLramByte((port), ASCV_DONENEXT_B)
  812. #define AscPutRiscVarFreeQHead(port, val) AscWriteLramByte((port), ASCV_NEXTRDY_B, val)
  813. #define AscPutRiscVarDoneQTail(port, val) AscWriteLramByte((port), ASCV_DONENEXT_B, val)
  814. #define AscPutMCodeSDTRDoneAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id), (data))
  815. #define AscGetMCodeSDTRDoneAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id))
  816. #define AscPutMCodeInitSDTRAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id), data)
  817. #define AscGetMCodeInitSDTRAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id))
  818. #define AscGetChipSignatureByte(port) (uchar)inp((port)+IOP_SIG_BYTE)
  819. #define AscGetChipSignatureWord(port) (ushort)inpw((port)+IOP_SIG_WORD)
  820. #define AscGetChipVerNo(port) (uchar)inp((port)+IOP_VERSION)
  821. #define AscGetChipCfgLsw(port) (ushort)inpw((port)+IOP_CONFIG_LOW)
  822. #define AscGetChipCfgMsw(port) (ushort)inpw((port)+IOP_CONFIG_HIGH)
  823. #define AscSetChipCfgLsw(port, data) outpw((port)+IOP_CONFIG_LOW, data)
  824. #define AscSetChipCfgMsw(port, data) outpw((port)+IOP_CONFIG_HIGH, data)
  825. #define AscGetChipEEPCmd(port) (uchar)inp((port)+IOP_EEP_CMD)
  826. #define AscSetChipEEPCmd(port, data) outp((port)+IOP_EEP_CMD, data)
  827. #define AscGetChipEEPData(port) (ushort)inpw((port)+IOP_EEP_DATA)
  828. #define AscSetChipEEPData(port, data) outpw((port)+IOP_EEP_DATA, data)
  829. #define AscGetChipLramAddr(port) (ushort)inpw((PortAddr)((port)+IOP_RAM_ADDR))
  830. #define AscSetChipLramAddr(port, addr) outpw((PortAddr)((port)+IOP_RAM_ADDR), addr)
  831. #define AscGetChipLramData(port) (ushort)inpw((port)+IOP_RAM_DATA)
  832. #define AscSetChipLramData(port, data) outpw((port)+IOP_RAM_DATA, data)
  833. #define AscGetChipIFC(port) (uchar)inp((port)+IOP_REG_IFC)
  834. #define AscSetChipIFC(port, data) outp((port)+IOP_REG_IFC, data)
  835. #define AscGetChipStatus(port) (ASC_CS_TYPE)inpw((port)+IOP_STATUS)
  836. #define AscSetChipStatus(port, cs_val) outpw((port)+IOP_STATUS, cs_val)
  837. #define AscGetChipControl(port) (uchar)inp((port)+IOP_CTRL)
  838. #define AscSetChipControl(port, cc_val) outp((port)+IOP_CTRL, cc_val)
  839. #define AscGetChipSyn(port) (uchar)inp((port)+IOP_SYN_OFFSET)
  840. #define AscSetChipSyn(port, data) outp((port)+IOP_SYN_OFFSET, data)
  841. #define AscSetPCAddr(port, data) outpw((port)+IOP_REG_PC, data)
  842. #define AscGetPCAddr(port) (ushort)inpw((port)+IOP_REG_PC)
  843. #define AscIsIntPending(port) (AscGetChipStatus(port) & (CSW_INT_PENDING | CSW_SCSI_RESET_LATCH))
  844. #define AscGetChipScsiID(port) ((AscGetChipCfgLsw(port) >> 8) & ASC_MAX_TID)
  845. #define AscGetExtraControl(port) (uchar)inp((port)+IOP_EXTRA_CONTROL)
  846. #define AscSetExtraControl(port, data) outp((port)+IOP_EXTRA_CONTROL, data)
  847. #define AscReadChipAX(port) (ushort)inpw((port)+IOP_REG_AX)
  848. #define AscWriteChipAX(port, data) outpw((port)+IOP_REG_AX, data)
  849. #define AscReadChipIX(port) (uchar)inp((port)+IOP_REG_IX)
  850. #define AscWriteChipIX(port, data) outp((port)+IOP_REG_IX, data)
  851. #define AscReadChipIH(port) (ushort)inpw((port)+IOP_REG_IH)
  852. #define AscWriteChipIH(port, data) outpw((port)+IOP_REG_IH, data)
  853. #define AscReadChipQP(port) (uchar)inp((port)+IOP_REG_QP)
  854. #define AscWriteChipQP(port, data) outp((port)+IOP_REG_QP, data)
  855. #define AscReadChipFIFO_L(port) (ushort)inpw((port)+IOP_REG_FIFO_L)
  856. #define AscWriteChipFIFO_L(port, data) outpw((port)+IOP_REG_FIFO_L, data)
  857. #define AscReadChipFIFO_H(port) (ushort)inpw((port)+IOP_REG_FIFO_H)
  858. #define AscWriteChipFIFO_H(port, data) outpw((port)+IOP_REG_FIFO_H, data)
  859. #define AscReadChipDmaSpeed(port) (uchar)inp((port)+IOP_DMA_SPEED)
  860. #define AscWriteChipDmaSpeed(port, data) outp((port)+IOP_DMA_SPEED, data)
  861. #define AscReadChipDA0(port) (ushort)inpw((port)+IOP_REG_DA0)
  862. #define AscWriteChipDA0(port) outpw((port)+IOP_REG_DA0, data)
  863. #define AscReadChipDA1(port) (ushort)inpw((port)+IOP_REG_DA1)
  864. #define AscWriteChipDA1(port) outpw((port)+IOP_REG_DA1, data)
  865. #define AscReadChipDC0(port) (ushort)inpw((port)+IOP_REG_DC0)
  866. #define AscWriteChipDC0(port) outpw((port)+IOP_REG_DC0, data)
  867. #define AscReadChipDC1(port) (ushort)inpw((port)+IOP_REG_DC1)
  868. #define AscWriteChipDC1(port) outpw((port)+IOP_REG_DC1, data)
  869. #define AscReadChipDvcID(port) (uchar)inp((port)+IOP_REG_ID)
  870. #define AscWriteChipDvcID(port, data) outp((port)+IOP_REG_ID, data)
  871. /*
  872. * Portable Data Types
  873. *
  874. * Any instance where a 32-bit long or pointer type is assumed
  875. * for precision or HW defined structures, the following define
  876. * types must be used. In Linux the char, short, and int types
  877. * are all consistent at 8, 16, and 32 bits respectively. Pointers
  878. * and long types are 64 bits on Alpha and UltraSPARC.
  879. */
  880. #define ADV_PADDR __u32 /* Physical address data type. */
  881. #define ADV_VADDR __u32 /* Virtual address data type. */
  882. #define ADV_DCNT __u32 /* Unsigned Data count type. */
  883. #define ADV_SDCNT __s32 /* Signed Data count type. */
  884. /*
  885. * These macros are used to convert a virtual address to a
  886. * 32-bit value. This currently can be used on Linux Alpha
  887. * which uses 64-bit virtual address but a 32-bit bus address.
  888. * This is likely to break in the future, but doing this now
  889. * will give us time to change the HW and FW to handle 64-bit
  890. * addresses.
  891. */
  892. #define ADV_VADDR_TO_U32 virt_to_bus
  893. #define ADV_U32_TO_VADDR bus_to_virt
  894. #define AdvPortAddr void __iomem * /* Virtual memory address size */
  895. /*
  896. * Define Adv Library required memory access macros.
  897. */
  898. #define ADV_MEM_READB(addr) readb(addr)
  899. #define ADV_MEM_READW(addr) readw(addr)
  900. #define ADV_MEM_WRITEB(addr, byte) writeb(byte, addr)
  901. #define ADV_MEM_WRITEW(addr, word) writew(word, addr)
  902. #define ADV_MEM_WRITEDW(addr, dword) writel(dword, addr)
  903. #define ADV_CARRIER_COUNT (ASC_DEF_MAX_HOST_QNG + 15)
  904. /*
  905. * Define total number of simultaneous maximum element scatter-gather
  906. * request blocks per wide adapter. ASC_DEF_MAX_HOST_QNG (253) is the
  907. * maximum number of outstanding commands per wide host adapter. Each
  908. * command uses one or more ADV_SG_BLOCK each with 15 scatter-gather
  909. * elements. Allow each command to have at least one ADV_SG_BLOCK structure.
  910. * This allows about 15 commands to have the maximum 17 ADV_SG_BLOCK
  911. * structures or 255 scatter-gather elements.
  912. */
  913. #define ADV_TOT_SG_BLOCK ASC_DEF_MAX_HOST_QNG
  914. /*
  915. * Define maximum number of scatter-gather elements per request.
  916. */
  917. #define ADV_MAX_SG_LIST 255
  918. #define NO_OF_SG_PER_BLOCK 15
  919. #define ADV_EEP_DVC_CFG_BEGIN (0x00)
  920. #define ADV_EEP_DVC_CFG_END (0x15)
  921. #define ADV_EEP_DVC_CTL_BEGIN (0x16) /* location of OEM name */
  922. #define ADV_EEP_MAX_WORD_ADDR (0x1E)
  923. #define ADV_EEP_DELAY_MS 100
  924. #define ADV_EEPROM_BIG_ENDIAN 0x8000 /* EEPROM Bit 15 */
  925. #define ADV_EEPROM_BIOS_ENABLE 0x4000 /* EEPROM Bit 14 */
  926. /*
  927. * For the ASC3550 Bit 13 is Termination Polarity control bit.
  928. * For later ICs Bit 13 controls whether the CIS (Card Information
  929. * Service Section) is loaded from EEPROM.
  930. */
  931. #define ADV_EEPROM_TERM_POL 0x2000 /* EEPROM Bit 13 */
  932. #define ADV_EEPROM_CIS_LD 0x2000 /* EEPROM Bit 13 */
  933. /*
  934. * ASC38C1600 Bit 11
  935. *
  936. * If EEPROM Bit 11 is 0 for Function 0, then Function 0 will specify
  937. * INT A in the PCI Configuration Space Int Pin field. If it is 1, then
  938. * Function 0 will specify INT B.
  939. *
  940. * If EEPROM Bit 11 is 0 for Function 1, then Function 1 will specify
  941. * INT B in the PCI Configuration Space Int Pin field. If it is 1, then
  942. * Function 1 will specify INT A.
  943. */
  944. #define ADV_EEPROM_INTAB 0x0800 /* EEPROM Bit 11 */
  945. typedef struct adveep_3550_config {
  946. /* Word Offset, Description */
  947. ushort cfg_lsw; /* 00 power up initialization */
  948. /* bit 13 set - Term Polarity Control */
  949. /* bit 14 set - BIOS Enable */
  950. /* bit 15 set - Big Endian Mode */
  951. ushort cfg_msw; /* 01 unused */
  952. ushort disc_enable; /* 02 disconnect enable */
  953. ushort wdtr_able; /* 03 Wide DTR able */
  954. ushort sdtr_able; /* 04 Synchronous DTR able */
  955. ushort start_motor; /* 05 send start up motor */
  956. ushort tagqng_able; /* 06 tag queuing able */
  957. ushort bios_scan; /* 07 BIOS device control */
  958. ushort scam_tolerant; /* 08 no scam */
  959. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  960. uchar bios_boot_delay; /* power up wait */
  961. uchar scsi_reset_delay; /* 10 reset delay */
  962. uchar bios_id_lun; /* first boot device scsi id & lun */
  963. /* high nibble is lun */
  964. /* low nibble is scsi id */
  965. uchar termination; /* 11 0 - automatic */
  966. /* 1 - low off / high off */
  967. /* 2 - low off / high on */
  968. /* 3 - low on / high on */
  969. /* There is no low on / high off */
  970. uchar reserved1; /* reserved byte (not used) */
  971. ushort bios_ctrl; /* 12 BIOS control bits */
  972. /* bit 0 BIOS don't act as initiator. */
  973. /* bit 1 BIOS > 1 GB support */
  974. /* bit 2 BIOS > 2 Disk Support */
  975. /* bit 3 BIOS don't support removables */
  976. /* bit 4 BIOS support bootable CD */
  977. /* bit 5 BIOS scan enabled */
  978. /* bit 6 BIOS support multiple LUNs */
  979. /* bit 7 BIOS display of message */
  980. /* bit 8 SCAM disabled */
  981. /* bit 9 Reset SCSI bus during init. */
  982. /* bit 10 */
  983. /* bit 11 No verbose initialization. */
  984. /* bit 12 SCSI parity enabled */
  985. /* bit 13 */
  986. /* bit 14 */
  987. /* bit 15 */
  988. ushort ultra_able; /* 13 ULTRA speed able */
  989. ushort reserved2; /* 14 reserved */
  990. uchar max_host_qng; /* 15 maximum host queuing */
  991. uchar max_dvc_qng; /* maximum per device queuing */
  992. ushort dvc_cntl; /* 16 control bit for driver */
  993. ushort bug_fix; /* 17 control bit for bug fix */
  994. ushort serial_number_word1; /* 18 Board serial number word 1 */
  995. ushort serial_number_word2; /* 19 Board serial number word 2 */
  996. ushort serial_number_word3; /* 20 Board serial number word 3 */
  997. ushort check_sum; /* 21 EEP check sum */
  998. uchar oem_name[16]; /* 22 OEM name */
  999. ushort dvc_err_code; /* 30 last device driver error code */
  1000. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  1001. ushort adv_err_addr; /* 32 last uc error address */
  1002. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  1003. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  1004. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  1005. ushort num_of_err; /* 36 number of error */
  1006. } ADVEEP_3550_CONFIG;
  1007. typedef struct adveep_38C0800_config {
  1008. /* Word Offset, Description */
  1009. ushort cfg_lsw; /* 00 power up initialization */
  1010. /* bit 13 set - Load CIS */
  1011. /* bit 14 set - BIOS Enable */
  1012. /* bit 15 set - Big Endian Mode */
  1013. ushort cfg_msw; /* 01 unused */
  1014. ushort disc_enable; /* 02 disconnect enable */
  1015. ushort wdtr_able; /* 03 Wide DTR able */
  1016. ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
  1017. ushort start_motor; /* 05 send start up motor */
  1018. ushort tagqng_able; /* 06 tag queuing able */
  1019. ushort bios_scan; /* 07 BIOS device control */
  1020. ushort scam_tolerant; /* 08 no scam */
  1021. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  1022. uchar bios_boot_delay; /* power up wait */
  1023. uchar scsi_reset_delay; /* 10 reset delay */
  1024. uchar bios_id_lun; /* first boot device scsi id & lun */
  1025. /* high nibble is lun */
  1026. /* low nibble is scsi id */
  1027. uchar termination_se; /* 11 0 - automatic */
  1028. /* 1 - low off / high off */
  1029. /* 2 - low off / high on */
  1030. /* 3 - low on / high on */
  1031. /* There is no low on / high off */
  1032. uchar termination_lvd; /* 11 0 - automatic */
  1033. /* 1 - low off / high off */
  1034. /* 2 - low off / high on */
  1035. /* 3 - low on / high on */
  1036. /* There is no low on / high off */
  1037. ushort bios_ctrl; /* 12 BIOS control bits */
  1038. /* bit 0 BIOS don't act as initiator. */
  1039. /* bit 1 BIOS > 1 GB support */
  1040. /* bit 2 BIOS > 2 Disk Support */
  1041. /* bit 3 BIOS don't support removables */
  1042. /* bit 4 BIOS support bootable CD */
  1043. /* bit 5 BIOS scan enabled */
  1044. /* bit 6 BIOS support multiple LUNs */
  1045. /* bit 7 BIOS display of message */
  1046. /* bit 8 SCAM disabled */
  1047. /* bit 9 Reset SCSI bus during init. */
  1048. /* bit 10 */
  1049. /* bit 11 No verbose initialization. */
  1050. /* bit 12 SCSI parity enabled */
  1051. /* bit 13 */
  1052. /* bit 14 */
  1053. /* bit 15 */
  1054. ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
  1055. ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
  1056. uchar max_host_qng; /* 15 maximum host queueing */
  1057. uchar max_dvc_qng; /* maximum per device queuing */
  1058. ushort dvc_cntl; /* 16 control bit for driver */
  1059. ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
  1060. ushort serial_number_word1; /* 18 Board serial number word 1 */
  1061. ushort serial_number_word2; /* 19 Board serial number word 2 */
  1062. ushort serial_number_word3; /* 20 Board serial number word 3 */
  1063. ushort check_sum; /* 21 EEP check sum */
  1064. uchar oem_name[16]; /* 22 OEM name */
  1065. ushort dvc_err_code; /* 30 last device driver error code */
  1066. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  1067. ushort adv_err_addr; /* 32 last uc error address */
  1068. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  1069. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  1070. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  1071. ushort reserved36; /* 36 reserved */
  1072. ushort reserved37; /* 37 reserved */
  1073. ushort reserved38; /* 38 reserved */
  1074. ushort reserved39; /* 39 reserved */
  1075. ushort reserved40; /* 40 reserved */
  1076. ushort reserved41; /* 41 reserved */
  1077. ushort reserved42; /* 42 reserved */
  1078. ushort reserved43; /* 43 reserved */
  1079. ushort reserved44; /* 44 reserved */
  1080. ushort reserved45; /* 45 reserved */
  1081. ushort reserved46; /* 46 reserved */
  1082. ushort reserved47; /* 47 reserved */
  1083. ushort reserved48; /* 48 reserved */
  1084. ushort reserved49; /* 49 reserved */
  1085. ushort reserved50; /* 50 reserved */
  1086. ushort reserved51; /* 51 reserved */
  1087. ushort reserved52; /* 52 reserved */
  1088. ushort reserved53; /* 53 reserved */
  1089. ushort reserved54; /* 54 reserved */
  1090. ushort reserved55; /* 55 reserved */
  1091. ushort cisptr_lsw; /* 56 CIS PTR LSW */
  1092. ushort cisprt_msw; /* 57 CIS PTR MSW */
  1093. ushort subsysvid; /* 58 SubSystem Vendor ID */
  1094. ushort subsysid; /* 59 SubSystem ID */
  1095. ushort reserved60; /* 60 reserved */
  1096. ushort reserved61; /* 61 reserved */
  1097. ushort reserved62; /* 62 reserved */
  1098. ushort reserved63; /* 63 reserved */
  1099. } ADVEEP_38C0800_CONFIG;
  1100. typedef struct adveep_38C1600_config {
  1101. /* Word Offset, Description */
  1102. ushort cfg_lsw; /* 00 power up initialization */
  1103. /* bit 11 set - Func. 0 INTB, Func. 1 INTA */
  1104. /* clear - Func. 0 INTA, Func. 1 INTB */
  1105. /* bit 13 set - Load CIS */
  1106. /* bit 14 set - BIOS Enable */
  1107. /* bit 15 set - Big Endian Mode */
  1108. ushort cfg_msw; /* 01 unused */
  1109. ushort disc_enable; /* 02 disconnect enable */
  1110. ushort wdtr_able; /* 03 Wide DTR able */
  1111. ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */
  1112. ushort start_motor; /* 05 send start up motor */
  1113. ushort tagqng_able; /* 06 tag queuing able */
  1114. ushort bios_scan; /* 07 BIOS device control */
  1115. ushort scam_tolerant; /* 08 no scam */
  1116. uchar adapter_scsi_id; /* 09 Host Adapter ID */
  1117. uchar bios_boot_delay; /* power up wait */
  1118. uchar scsi_reset_delay; /* 10 reset delay */
  1119. uchar bios_id_lun; /* first boot device scsi id & lun */
  1120. /* high nibble is lun */
  1121. /* low nibble is scsi id */
  1122. uchar termination_se; /* 11 0 - automatic */
  1123. /* 1 - low off / high off */
  1124. /* 2 - low off / high on */
  1125. /* 3 - low on / high on */
  1126. /* There is no low on / high off */
  1127. uchar termination_lvd; /* 11 0 - automatic */
  1128. /* 1 - low off / high off */
  1129. /* 2 - low off / high on */
  1130. /* 3 - low on / high on */
  1131. /* There is no low on / high off */
  1132. ushort bios_ctrl; /* 12 BIOS control bits */
  1133. /* bit 0 BIOS don't act as initiator. */
  1134. /* bit 1 BIOS > 1 GB support */
  1135. /* bit 2 BIOS > 2 Disk Support */
  1136. /* bit 3 BIOS don't support removables */
  1137. /* bit 4 BIOS support bootable CD */
  1138. /* bit 5 BIOS scan enabled */
  1139. /* bit 6 BIOS support multiple LUNs */
  1140. /* bit 7 BIOS display of message */
  1141. /* bit 8 SCAM disabled */
  1142. /* bit 9 Reset SCSI bus during init. */
  1143. /* bit 10 Basic Integrity Checking disabled */
  1144. /* bit 11 No verbose initialization. */
  1145. /* bit 12 SCSI parity enabled */
  1146. /* bit 13 AIPP (Asyn. Info. Ph. Prot.) dis. */
  1147. /* bit 14 */
  1148. /* bit 15 */
  1149. ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */
  1150. ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */
  1151. uchar max_host_qng; /* 15 maximum host queueing */
  1152. uchar max_dvc_qng; /* maximum per device queuing */
  1153. ushort dvc_cntl; /* 16 control bit for driver */
  1154. ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */
  1155. ushort serial_number_word1; /* 18 Board serial number word 1 */
  1156. ushort serial_number_word2; /* 19 Board serial number word 2 */
  1157. ushort serial_number_word3; /* 20 Board serial number word 3 */
  1158. ushort check_sum; /* 21 EEP check sum */
  1159. uchar oem_name[16]; /* 22 OEM name */
  1160. ushort dvc_err_code; /* 30 last device driver error code */
  1161. ushort adv_err_code; /* 31 last uc and Adv Lib error code */
  1162. ushort adv_err_addr; /* 32 last uc error address */
  1163. ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */
  1164. ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */
  1165. ushort saved_adv_err_addr; /* 35 saved last uc error address */
  1166. ushort reserved36; /* 36 reserved */
  1167. ushort reserved37; /* 37 reserved */
  1168. ushort reserved38; /* 38 reserved */
  1169. ushort reserved39; /* 39 reserved */
  1170. ushort reserved40; /* 40 reserved */
  1171. ushort reserved41; /* 41 reserved */
  1172. ushort reserved42; /* 42 reserved */
  1173. ushort reserved43; /* 43 reserved */
  1174. ushort reserved44; /* 44 reserved */
  1175. ushort reserved45; /* 45 reserved */
  1176. ushort reserved46; /* 46 reserved */
  1177. ushort reserved47; /* 47 reserved */
  1178. ushort reserved48; /* 48 reserved */
  1179. ushort reserved49; /* 49 reserved */
  1180. ushort reserved50; /* 50 reserved */
  1181. ushort reserved51; /* 51 reserved */
  1182. ushort reserved52; /* 52 reserved */
  1183. ushort reserved53; /* 53 reserved */
  1184. ushort reserved54; /* 54 reserved */
  1185. ushort reserved55; /* 55 reserved */
  1186. ushort cisptr_lsw; /* 56 CIS PTR LSW */
  1187. ushort cisprt_msw; /* 57 CIS PTR MSW */
  1188. ushort subsysvid; /* 58 SubSystem Vendor ID */
  1189. ushort subsysid; /* 59 SubSystem ID */
  1190. ushort reserved60; /* 60 reserved */
  1191. ushort reserved61; /* 61 reserved */
  1192. ushort reserved62; /* 62 reserved */
  1193. ushort reserved63; /* 63 reserved */
  1194. } ADVEEP_38C1600_CONFIG;
  1195. /*
  1196. * EEPROM Commands
  1197. */
  1198. #define ASC_EEP_CMD_DONE 0x0200
  1199. /* bios_ctrl */
  1200. #define BIOS_CTRL_BIOS 0x0001
  1201. #define BIOS_CTRL_EXTENDED_XLAT 0x0002
  1202. #define BIOS_CTRL_GT_2_DISK 0x0004
  1203. #define BIOS_CTRL_BIOS_REMOVABLE 0x0008
  1204. #define BIOS_CTRL_BOOTABLE_CD 0x0010
  1205. #define BIOS_CTRL_MULTIPLE_LUN 0x0040
  1206. #define BIOS_CTRL_DISPLAY_MSG 0x0080
  1207. #define BIOS_CTRL_NO_SCAM 0x0100
  1208. #define BIOS_CTRL_RESET_SCSI_BUS 0x0200
  1209. #define BIOS_CTRL_INIT_VERBOSE 0x0800
  1210. #define BIOS_CTRL_SCSI_PARITY 0x1000
  1211. #define BIOS_CTRL_AIPP_DIS 0x2000
  1212. #define ADV_3550_MEMSIZE 0x2000 /* 8 KB Internal Memory */
  1213. #define ADV_38C0800_MEMSIZE 0x4000 /* 16 KB Internal Memory */
  1214. /*
  1215. * XXX - Since ASC38C1600 Rev.3 has a local RAM failure issue, there is
  1216. * a special 16K Adv Library and Microcode version. After the issue is
  1217. * resolved, should restore 32K support.
  1218. *
  1219. * #define ADV_38C1600_MEMSIZE 0x8000L * 32 KB Internal Memory *
  1220. */
  1221. #define ADV_38C1600_MEMSIZE 0x4000 /* 16 KB Internal Memory */
  1222. /*
  1223. * Byte I/O register address from base of 'iop_base'.
  1224. */
  1225. #define IOPB_INTR_STATUS_REG 0x00
  1226. #define IOPB_CHIP_ID_1 0x01
  1227. #define IOPB_INTR_ENABLES 0x02
  1228. #define IOPB_CHIP_TYPE_REV 0x03
  1229. #define IOPB_RES_ADDR_4 0x04
  1230. #define IOPB_RES_ADDR_5 0x05
  1231. #define IOPB_RAM_DATA 0x06
  1232. #define IOPB_RES_ADDR_7 0x07
  1233. #define IOPB_FLAG_REG 0x08
  1234. #define IOPB_RES_ADDR_9 0x09
  1235. #define IOPB_RISC_CSR 0x0A
  1236. #define IOPB_RES_ADDR_B 0x0B
  1237. #define IOPB_RES_ADDR_C 0x0C
  1238. #define IOPB_RES_ADDR_D 0x0D
  1239. #define IOPB_SOFT_OVER_WR 0x0E
  1240. #define IOPB_RES_ADDR_F 0x0F
  1241. #define IOPB_MEM_CFG 0x10
  1242. #define IOPB_RES_ADDR_11 0x11
  1243. #define IOPB_GPIO_DATA 0x12
  1244. #define IOPB_RES_ADDR_13 0x13
  1245. #define IOPB_FLASH_PAGE 0x14
  1246. #define IOPB_RES_ADDR_15 0x15
  1247. #define IOPB_GPIO_CNTL 0x16
  1248. #define IOPB_RES_ADDR_17 0x17
  1249. #define IOPB_FLASH_DATA 0x18
  1250. #define IOPB_RES_ADDR_19 0x19
  1251. #define IOPB_RES_ADDR_1A 0x1A
  1252. #define IOPB_RES_ADDR_1B 0x1B
  1253. #define IOPB_RES_ADDR_1C 0x1C
  1254. #define IOPB_RES_ADDR_1D 0x1D
  1255. #define IOPB_RES_ADDR_1E 0x1E
  1256. #define IOPB_RES_ADDR_1F 0x1F
  1257. #define IOPB_DMA_CFG0 0x20
  1258. #define IOPB_DMA_CFG1 0x21
  1259. #define IOPB_TICKLE 0x22
  1260. #define IOPB_DMA_REG_WR 0x23
  1261. #define IOPB_SDMA_STATUS 0x24
  1262. #define IOPB_SCSI_BYTE_CNT 0x25
  1263. #define IOPB_HOST_BYTE_CNT 0x26
  1264. #define IOPB_BYTE_LEFT_TO_XFER 0x27
  1265. #define IOPB_BYTE_TO_XFER_0 0x28
  1266. #define IOPB_BYTE_TO_XFER_1 0x29
  1267. #define IOPB_BYTE_TO_XFER_2 0x2A
  1268. #define IOPB_BYTE_TO_XFER_3 0x2B
  1269. #define IOPB_ACC_GRP 0x2C
  1270. #define IOPB_RES_ADDR_2D 0x2D
  1271. #define IOPB_DEV_ID 0x2E
  1272. #define IOPB_RES_ADDR_2F 0x2F
  1273. #define IOPB_SCSI_DATA 0x30
  1274. #define IOPB_RES_ADDR_31 0x31
  1275. #define IOPB_RES_ADDR_32 0x32
  1276. #define IOPB_SCSI_DATA_HSHK 0x33
  1277. #define IOPB_SCSI_CTRL 0x34
  1278. #define IOPB_RES_ADDR_35 0x35
  1279. #define IOPB_RES_ADDR_36 0x36
  1280. #define IOPB_RES_ADDR_37 0x37
  1281. #define IOPB_RAM_BIST 0x38
  1282. #define IOPB_PLL_TEST 0x39
  1283. #define IOPB_PCI_INT_CFG 0x3A
  1284. #define IOPB_RES_ADDR_3B 0x3B
  1285. #define IOPB_RFIFO_CNT 0x3C
  1286. #define IOPB_RES_ADDR_3D 0x3D
  1287. #define IOPB_RES_ADDR_3E 0x3E
  1288. #define IOPB_RES_ADDR_3F 0x3F
  1289. /*
  1290. * Word I/O register address from base of 'iop_base'.
  1291. */
  1292. #define IOPW_CHIP_ID_0 0x00 /* CID0 */
  1293. #define IOPW_CTRL_REG 0x02 /* CC */
  1294. #define IOPW_RAM_ADDR 0x04 /* LA */
  1295. #define IOPW_RAM_DATA 0x06 /* LD */
  1296. #define IOPW_RES_ADDR_08 0x08
  1297. #define IOPW_RISC_CSR 0x0A /* CSR */
  1298. #define IOPW_SCSI_CFG0 0x0C /* CFG0 */
  1299. #define IOPW_SCSI_CFG1 0x0E /* CFG1 */
  1300. #define IOPW_RES_ADDR_10 0x10
  1301. #define IOPW_SEL_MASK 0x12 /* SM */
  1302. #define IOPW_RES_ADDR_14 0x14
  1303. #define IOPW_FLASH_ADDR 0x16 /* FA */
  1304. #define IOPW_RES_ADDR_18 0x18
  1305. #define IOPW_EE_CMD 0x1A /* EC */
  1306. #define IOPW_EE_DATA 0x1C /* ED */
  1307. #define IOPW_SFIFO_CNT 0x1E /* SFC */
  1308. #define IOPW_RES_ADDR_20 0x20
  1309. #define IOPW_Q_BASE 0x22 /* QB */
  1310. #define IOPW_QP 0x24 /* QP */
  1311. #define IOPW_IX 0x26 /* IX */
  1312. #define IOPW_SP 0x28 /* SP */
  1313. #define IOPW_PC 0x2A /* PC */
  1314. #define IOPW_RES_ADDR_2C 0x2C
  1315. #define IOPW_RES_ADDR_2E 0x2E
  1316. #define IOPW_SCSI_DATA 0x30 /* SD */
  1317. #define IOPW_SCSI_DATA_HSHK 0x32 /* SDH */
  1318. #define IOPW_SCSI_CTRL 0x34 /* SC */
  1319. #define IOPW_HSHK_CFG 0x36 /* HCFG */
  1320. #define IOPW_SXFR_STATUS 0x36 /* SXS */
  1321. #define IOPW_SXFR_CNTL 0x38 /* SXL */
  1322. #define IOPW_SXFR_CNTH 0x3A /* SXH */
  1323. #define IOPW_RES_ADDR_3C 0x3C
  1324. #define IOPW_RFIFO_DATA 0x3E /* RFD */
  1325. /*
  1326. * Doubleword I/O register address from base of 'iop_base'.
  1327. */
  1328. #define IOPDW_RES_ADDR_0 0x00
  1329. #define IOPDW_RAM_DATA 0x04
  1330. #define IOPDW_RES_ADDR_8 0x08
  1331. #define IOPDW_RES_ADDR_C 0x0C
  1332. #define IOPDW_RES_ADDR_10 0x10
  1333. #define IOPDW_COMMA 0x14
  1334. #define IOPDW_COMMB 0x18
  1335. #define IOPDW_RES_ADDR_1C 0x1C
  1336. #define IOPDW_SDMA_ADDR0 0x20
  1337. #define IOPDW_SDMA_ADDR1 0x24
  1338. #define IOPDW_SDMA_COUNT 0x28
  1339. #define IOPDW_SDMA_ERROR 0x2C
  1340. #define IOPDW_RDMA_ADDR0 0x30
  1341. #define IOPDW_RDMA_ADDR1 0x34
  1342. #define IOPDW_RDMA_COUNT 0x38
  1343. #define IOPDW_RDMA_ERROR 0x3C
  1344. #define ADV_CHIP_ID_BYTE 0x25
  1345. #define ADV_CHIP_ID_WORD 0x04C1
  1346. #define ADV_INTR_ENABLE_HOST_INTR 0x01
  1347. #define ADV_INTR_ENABLE_SEL_INTR 0x02
  1348. #define ADV_INTR_ENABLE_DPR_INTR 0x04
  1349. #define ADV_INTR_ENABLE_RTA_INTR 0x08
  1350. #define ADV_INTR_ENABLE_RMA_INTR 0x10
  1351. #define ADV_INTR_ENABLE_RST_INTR 0x20
  1352. #define ADV_INTR_ENABLE_DPE_INTR 0x40
  1353. #define ADV_INTR_ENABLE_GLOBAL_INTR 0x80
  1354. #define ADV_INTR_STATUS_INTRA 0x01
  1355. #define ADV_INTR_STATUS_INTRB 0x02
  1356. #define ADV_INTR_STATUS_INTRC 0x04
  1357. #define ADV_RISC_CSR_STOP (0x0000)
  1358. #define ADV_RISC_TEST_COND (0x2000)
  1359. #define ADV_RISC_CSR_RUN (0x4000)
  1360. #define ADV_RISC_CSR_SINGLE_STEP (0x8000)
  1361. #define ADV_CTRL_REG_HOST_INTR 0x0100
  1362. #define ADV_CTRL_REG_SEL_INTR 0x0200
  1363. #define ADV_CTRL_REG_DPR_INTR 0x0400
  1364. #define ADV_CTRL_REG_RTA_INTR 0x0800
  1365. #define ADV_CTRL_REG_RMA_INTR 0x1000
  1366. #define ADV_CTRL_REG_RES_BIT14 0x2000
  1367. #define ADV_CTRL_REG_DPE_INTR 0x4000
  1368. #define ADV_CTRL_REG_POWER_DONE 0x8000
  1369. #define ADV_CTRL_REG_ANY_INTR 0xFF00
  1370. #define ADV_CTRL_REG_CMD_RESET 0x00C6
  1371. #define ADV_CTRL_REG_CMD_WR_IO_REG 0x00C5
  1372. #define ADV_CTRL_REG_CMD_RD_IO_REG 0x00C4
  1373. #define ADV_CTRL_REG_CMD_WR_PCI_CFG_SPACE 0x00C3
  1374. #define ADV_CTRL_REG_CMD_RD_PCI_CFG_SPACE 0x00C2
  1375. #define ADV_TICKLE_NOP 0x00
  1376. #define ADV_TICKLE_A 0x01
  1377. #define ADV_TICKLE_B 0x02
  1378. #define ADV_TICKLE_C 0x03
  1379. #define AdvIsIntPending(port) \
  1380. (AdvReadWordRegister(port, IOPW_CTRL_REG) & ADV_CTRL_REG_HOST_INTR)
  1381. /*
  1382. * SCSI_CFG0 Register bit definitions
  1383. */
  1384. #define TIMER_MODEAB 0xC000 /* Watchdog, Second, and Select. Timer Ctrl. */
  1385. #define PARITY_EN 0x2000 /* Enable SCSI Parity Error detection */
  1386. #define EVEN_PARITY 0x1000 /* Select Even Parity */
  1387. #define WD_LONG 0x0800 /* Watchdog Interval, 1: 57 min, 0: 13 sec */
  1388. #define QUEUE_128 0x0400 /* Queue Size, 1: 128 byte, 0: 64 byte */
  1389. #define PRIM_MODE 0x0100 /* Primitive SCSI mode */
  1390. #define SCAM_EN 0x0080 /* Enable SCAM selection */
  1391. #define SEL_TMO_LONG 0x0040 /* Sel/Resel Timeout, 1: 400 ms, 0: 1.6 ms */
  1392. #define CFRM_ID 0x0020 /* SCAM id sel. confirm., 1: fast, 0: 6.4 ms */
  1393. #define OUR_ID_EN 0x0010 /* Enable OUR_ID bits */
  1394. #define OUR_ID 0x000F /* SCSI ID */
  1395. /*
  1396. * SCSI_CFG1 Register bit definitions
  1397. */
  1398. #define BIG_ENDIAN 0x8000 /* Enable Big Endian Mode MIO:15, EEP:15 */
  1399. #define TERM_POL 0x2000 /* Terminator Polarity Ctrl. MIO:13, EEP:13 */
  1400. #define SLEW_RATE 0x1000 /* SCSI output buffer slew rate */
  1401. #define FILTER_SEL 0x0C00 /* Filter Period Selection */
  1402. #define FLTR_DISABLE 0x0000 /* Input Filtering Disabled */
  1403. #define FLTR_11_TO_20NS 0x0800 /* Input Filtering 11ns to 20ns */
  1404. #define FLTR_21_TO_39NS 0x0C00 /* Input Filtering 21ns to 39ns */
  1405. #define ACTIVE_DBL 0x0200 /* Disable Active Negation */
  1406. #define DIFF_MODE 0x0100 /* SCSI differential Mode (Read-Only) */
  1407. #define DIFF_SENSE 0x0080 /* 1: No SE cables, 0: SE cable (Read-Only) */
  1408. #define TERM_CTL_SEL 0x0040 /* Enable TERM_CTL_H and TERM_CTL_L */
  1409. #define TERM_CTL 0x0030 /* External SCSI Termination Bits */
  1410. #define TERM_CTL_H 0x0020 /* Enable External SCSI Upper Termination */
  1411. #define TERM_CTL_L 0x0010 /* Enable External SCSI Lower Termination */
  1412. #define CABLE_DETECT 0x000F /* External SCSI Cable Connection Status */
  1413. /*
  1414. * Addendum for ASC-38C0800 Chip
  1415. *
  1416. * The ASC-38C1600 Chip uses the same definitions except that the
  1417. * bus mode override bits [12:10] have been moved to byte register
  1418. * offset 0xE (IOPB_SOFT_OVER_WR) bits [12:10]. The [12:10] bits in
  1419. * SCSI_CFG1 are read-only and always available. Bit 14 (DIS_TERM_DRV)
  1420. * is not needed. The [12:10] bits in IOPB_SOFT_OVER_WR are write-only.
  1421. * Also each ASC-38C1600 function or channel uses only cable bits [5:4]
  1422. * and [1:0]. Bits [14], [7:6], [3:2] are unused.
  1423. */
  1424. #define DIS_TERM_DRV 0x4000 /* 1: Read c_det[3:0], 0: cannot read */
  1425. #define HVD_LVD_SE 0x1C00 /* Device Detect Bits */
  1426. #define HVD 0x1000 /* HVD Device Detect */
  1427. #define LVD 0x0800 /* LVD Device Detect */
  1428. #define SE 0x0400 /* SE Device Detect */
  1429. #define TERM_LVD 0x00C0 /* LVD Termination Bits */
  1430. #define TERM_LVD_HI 0x0080 /* Enable LVD Upper Termination */
  1431. #define TERM_LVD_LO 0x0040 /* Enable LVD Lower Termination */
  1432. #define TERM_SE 0x0030 /* SE Termination Bits */
  1433. #define TERM_SE_HI 0x0020 /* Enable SE Upper Termination */
  1434. #define TERM_SE_LO 0x0010 /* Enable SE Lower Termination */
  1435. #define C_DET_LVD 0x000C /* LVD Cable Detect Bits */
  1436. #define C_DET3 0x0008 /* Cable Detect for LVD External Wide */
  1437. #define C_DET2 0x0004 /* Cable Detect for LVD Internal Wide */
  1438. #define C_DET_SE 0x0003 /* SE Cable Detect Bits */
  1439. #define C_DET1 0x0002 /* Cable Detect for SE Internal Wide */
  1440. #define C_DET0 0x0001 /* Cable Detect for SE Internal Narrow */
  1441. #define CABLE_ILLEGAL_A 0x7
  1442. /* x 0 0 0 | on on | Illegal (all 3 connectors are used) */
  1443. #define CABLE_ILLEGAL_B 0xB
  1444. /* 0 x 0 0 | on on | Illegal (all 3 connectors are used) */
  1445. /*
  1446. * MEM_CFG Register bit definitions
  1447. */
  1448. #define BIOS_EN 0x40 /* BIOS Enable MIO:14,EEP:14 */
  1449. #define FAST_EE_CLK 0x20 /* Diagnostic Bit */
  1450. #define RAM_SZ 0x1C /* Specify size of RAM to RISC */
  1451. #define RAM_SZ_2KB 0x00 /* 2 KB */
  1452. #define RAM_SZ_4KB 0x04 /* 4 KB */
  1453. #define RAM_SZ_8KB 0x08 /* 8 KB */
  1454. #define RAM_SZ_16KB 0x0C /* 16 KB */
  1455. #define RAM_SZ_32KB 0x10 /* 32 KB */
  1456. #define RAM_SZ_64KB 0x14 /* 64 KB */
  1457. /*
  1458. * DMA_CFG0 Register bit definitions
  1459. *
  1460. * This register is only accessible to the host.
  1461. */
  1462. #define BC_THRESH_ENB 0x80 /* PCI DMA Start Conditions */
  1463. #define FIFO_THRESH 0x70 /* PCI DMA FIFO Threshold */
  1464. #define FIFO_THRESH_16B 0x00 /* 16 bytes */
  1465. #define FIFO_THRESH_32B 0x20 /* 32 bytes */
  1466. #define FIFO_THRESH_48B 0x30 /* 48 bytes */
  1467. #define FIFO_THRESH_64B 0x40 /* 64 bytes */
  1468. #define FIFO_THRESH_80B 0x50 /* 80 bytes (default) */
  1469. #define FIFO_THRESH_96B 0x60 /* 96 bytes */
  1470. #define FIFO_THRESH_112B 0x70 /* 112 bytes */
  1471. #define START_CTL 0x0C /* DMA start conditions */
  1472. #define START_CTL_TH 0x00 /* Wait threshold level (default) */
  1473. #define START_CTL_ID 0x04 /* Wait SDMA/SBUS idle */
  1474. #define START_CTL_THID 0x08 /* Wait threshold and SDMA/SBUS idle */
  1475. #define START_CTL_EMFU 0x0C /* Wait SDMA FIFO empty/full */
  1476. #define READ_CMD 0x03 /* Memory Read Method */
  1477. #define READ_CMD_MR 0x00 /* Memory Read */
  1478. #define READ_CMD_MRL 0x02 /* Memory Read Long */
  1479. #define READ_CMD_MRM 0x03 /* Memory Read Multiple (default) */
  1480. /*
  1481. * ASC-38C0800 RAM BIST Register bit definitions
  1482. */
  1483. #define RAM_TEST_MODE 0x80
  1484. #define PRE_TEST_MODE 0x40
  1485. #define NORMAL_MODE 0x00
  1486. #define RAM_TEST_DONE 0x10
  1487. #define RAM_TEST_STATUS 0x0F
  1488. #define RAM_TEST_HOST_ERROR 0x08
  1489. #define RAM_TEST_INTRAM_ERROR 0x04
  1490. #define RAM_TEST_RISC_ERROR 0x02
  1491. #define RAM_TEST_SCSI_ERROR 0x01
  1492. #define RAM_TEST_SUCCESS 0x00
  1493. #define PRE_TEST_VALUE 0x05
  1494. #define NORMAL_VALUE 0x00
  1495. /*
  1496. * ASC38C1600 Definitions
  1497. *
  1498. * IOPB_PCI_INT_CFG Bit Field Definitions
  1499. */
  1500. #define INTAB_LD 0x80 /* Value loaded from EEPROM Bit 11. */
  1501. /*
  1502. * Bit 1 can be set to change the interrupt for the Function to operate in
  1503. * Totem Pole mode. By default Bit 1 is 0 and the interrupt operates in
  1504. * Open Drain mode. Both functions of the ASC38C1600 must be set to the same
  1505. * mode, otherwise the operating mode is undefined.
  1506. */
  1507. #define TOTEMPOLE 0x02
  1508. /*
  1509. * Bit 0 can be used to change the Int Pin for the Function. The value is
  1510. * 0 by default for both Functions with Function 0 using INT A and Function
  1511. * B using INT B. For Function 0 if set, INT B is used. For Function 1 if set,
  1512. * INT A is used.
  1513. *
  1514. * EEPROM Word 0 Bit 11 for each Function may change the initial Int Pin
  1515. * value specified in the PCI Configuration Space.
  1516. */
  1517. #define INTAB 0x01
  1518. /*
  1519. * Adv Library Status Definitions
  1520. */
  1521. #define ADV_TRUE 1
  1522. #define ADV_FALSE 0
  1523. #define ADV_SUCCESS 1
  1524. #define ADV_BUSY 0
  1525. #define ADV_ERROR (-1)
  1526. /*
  1527. * ADV_DVC_VAR 'warn_code' values
  1528. */
  1529. #define ASC_WARN_BUSRESET_ERROR 0x0001 /* SCSI Bus Reset error */
  1530. #define ASC_WARN_EEPROM_CHKSUM 0x0002 /* EEP check sum error */
  1531. #define ASC_WARN_EEPROM_TERMINATION 0x0004 /* EEP termination bad field */
  1532. #define ASC_WARN_ERROR 0xFFFF /* ADV_ERROR return */
  1533. #define ADV_MAX_TID 15 /* max. target identifier */
  1534. #define ADV_MAX_LUN 7 /* max. logical unit number */
  1535. /*
  1536. * Fixed locations of microcode operating variables.
  1537. */
  1538. #define ASC_MC_CODE_BEGIN_ADDR 0x0028 /* microcode start address */
  1539. #define ASC_MC_CODE_END_ADDR 0x002A /* microcode end address */
  1540. #define ASC_MC_CODE_CHK_SUM 0x002C /* microcode code checksum */
  1541. #define ASC_MC_VERSION_DATE 0x0038 /* microcode version */
  1542. #define ASC_MC_VERSION_NUM 0x003A /* microcode number */
  1543. #define ASC_MC_BIOSMEM 0x0040 /* BIOS RISC Memory Start */
  1544. #define ASC_MC_BIOSLEN 0x0050 /* BIOS RISC Memory Length */
  1545. #define ASC_MC_BIOS_SIGNATURE 0x0058 /* BIOS Signature 0x55AA */
  1546. #define ASC_MC_BIOS_VERSION 0x005A /* BIOS Version (2 bytes) */
  1547. #define ASC_MC_SDTR_SPEED1 0x0090 /* SDTR Speed for TID 0-3 */
  1548. #define ASC_MC_SDTR_SPEED2 0x0092 /* SDTR Speed for TID 4-7 */
  1549. #define ASC_MC_SDTR_SPEED3 0x0094 /* SDTR Speed for TID 8-11 */
  1550. #define ASC_MC_SDTR_SPEED4 0x0096 /* SDTR Speed for TID 12-15 */
  1551. #define ASC_MC_CHIP_TYPE 0x009A
  1552. #define ASC_MC_INTRB_CODE 0x009B
  1553. #define ASC_MC_WDTR_ABLE 0x009C
  1554. #define ASC_MC_SDTR_ABLE 0x009E
  1555. #define ASC_MC_TAGQNG_ABLE 0x00A0
  1556. #define ASC_MC_DISC_ENABLE 0x00A2
  1557. #define ASC_MC_IDLE_CMD_STATUS 0x00A4
  1558. #define ASC_MC_IDLE_CMD 0x00A6
  1559. #define ASC_MC_IDLE_CMD_PARAMETER 0x00A8
  1560. #define ASC_MC_DEFAULT_SCSI_CFG0 0x00AC
  1561. #define ASC_MC_DEFAULT_SCSI_CFG1 0x00AE
  1562. #define ASC_MC_DEFAULT_MEM_CFG 0x00B0
  1563. #define ASC_MC_DEFAULT_SEL_MASK 0x00B2
  1564. #define ASC_MC_SDTR_DONE 0x00B6
  1565. #define ASC_MC_NUMBER_OF_QUEUED_CMD 0x00C0
  1566. #define ASC_MC_NUMBER_OF_MAX_CMD 0x00D0
  1567. #define ASC_MC_DEVICE_HSHK_CFG_TABLE 0x0100
  1568. #define ASC_MC_CONTROL_FLAG 0x0122 /* Microcode control flag. */
  1569. #define ASC_MC_WDTR_DONE 0x0124
  1570. #define ASC_MC_CAM_MODE_MASK 0x015E /* CAM mode TID bitmask. */
  1571. #define ASC_MC_ICQ 0x0160
  1572. #define ASC_MC_IRQ 0x0164
  1573. #define ASC_MC_PPR_ABLE 0x017A
  1574. /*
  1575. * BIOS LRAM variable absolute offsets.
  1576. */
  1577. #define BIOS_CODESEG 0x54
  1578. #define BIOS_CODELEN 0x56
  1579. #define BIOS_SIGNATURE 0x58
  1580. #define BIOS_VERSION 0x5A
  1581. /*
  1582. * Microcode Control Flags
  1583. *
  1584. * Flags set by the Adv Library in RISC variable 'control_flag' (0x122)
  1585. * and handled by the microcode.
  1586. */
  1587. #define CONTROL_FLAG_IGNORE_PERR 0x0001 /* Ignore DMA Parity Errors */
  1588. #define CONTROL_FLAG_ENABLE_AIPP 0x0002 /* Enabled AIPP checking. */
  1589. /*
  1590. * ASC_MC_DEVICE_HSHK_CFG_TABLE microcode table or HSHK_CFG register format
  1591. */
  1592. #define HSHK_CFG_WIDE_XFR 0x8000
  1593. #define HSHK_CFG_RATE 0x0F00
  1594. #define HSHK_CFG_OFFSET 0x001F
  1595. #define ASC_DEF_MAX_HOST_QNG 0xFD /* Max. number of host commands (253) */
  1596. #define ASC_DEF_MIN_HOST_QNG 0x10 /* Min. number of host commands (16) */
  1597. #define ASC_DEF_MAX_DVC_QNG 0x3F /* Max. number commands per device (63) */
  1598. #define ASC_DEF_MIN_DVC_QNG 0x04 /* Min. number commands per device (4) */
  1599. #define ASC_QC_DATA_CHECK 0x01 /* Require ASC_QC_DATA_OUT set or clear. */
  1600. #define ASC_QC_DATA_OUT 0x02 /* Data out DMA transfer. */
  1601. #define ASC_QC_START_MOTOR 0x04 /* Send auto-start motor before request. */
  1602. #define ASC_QC_NO_OVERRUN 0x08 /* Don't report overrun. */
  1603. #define ASC_QC_FREEZE_TIDQ 0x10 /* Freeze TID queue after request. XXX TBD */
  1604. #define ASC_QSC_NO_DISC 0x01 /* Don't allow disconnect for request. */
  1605. #define ASC_QSC_NO_TAGMSG 0x02 /* Don't allow tag queuing for request. */
  1606. #define ASC_QSC_NO_SYNC 0x04 /* Don't use Synch. transfer on request. */
  1607. #define ASC_QSC_NO_WIDE 0x08 /* Don't use Wide transfer on request. */
  1608. #define ASC_QSC_REDO_DTR 0x10 /* Renegotiate WDTR/SDTR before request. */
  1609. /*
  1610. * Note: If a Tag Message is to be sent and neither ASC_QSC_HEAD_TAG or
  1611. * ASC_QSC_ORDERED_TAG is set, then a Simple Tag Message (0x20) is used.
  1612. */
  1613. #define ASC_QSC_HEAD_TAG 0x40 /* Use Head Tag Message (0x21). */
  1614. #define ASC_QSC_ORDERED_TAG 0x80 /* Use Ordered Tag Message (0x22). */
  1615. /*
  1616. * All fields here are accessed by the board microcode and need to be
  1617. * little-endian.
  1618. */
  1619. typedef struct adv_carr_t {
  1620. ADV_VADDR carr_va; /* Carrier Virtual Address */
  1621. ADV_PADDR carr_pa; /* Carrier Physical Address */
  1622. ADV_VADDR areq_vpa; /* ASC_SCSI_REQ_Q Virtual or Physical Address */
  1623. /*
  1624. * next_vpa [31:4] Carrier Virtual or Physical Next Pointer
  1625. *
  1626. * next_vpa [3:1] Reserved Bits
  1627. * next_vpa [0] Done Flag set in Response Queue.
  1628. */
  1629. ADV_VADDR next_vpa;
  1630. } ADV_CARR_T;
  1631. /*
  1632. * Mask used to eliminate low 4 bits of carrier 'next_vpa' field.
  1633. */
  1634. #define ASC_NEXT_VPA_MASK 0xFFFFFFF0
  1635. #define ASC_RQ_DONE 0x00000001
  1636. #define ASC_RQ_GOOD 0x00000002
  1637. #define ASC_CQ_STOPPER 0x00000000
  1638. #define ASC_GET_CARRP(carrp) ((carrp) & ASC_NEXT_VPA_MASK)
  1639. #define ADV_CARRIER_NUM_PAGE_CROSSING \
  1640. (((ADV_CARRIER_COUNT * sizeof(ADV_CARR_T)) + (PAGE_SIZE - 1))/PAGE_SIZE)
  1641. #define ADV_CARRIER_BUFSIZE \
  1642. ((ADV_CARRIER_COUNT + ADV_CARRIER_NUM_PAGE_CROSSING) * sizeof(ADV_CARR_T))
  1643. /*
  1644. * ASC_SCSI_REQ_Q 'a_flag' definitions
  1645. *
  1646. * The Adv Library should limit use to the lower nibble (4 bits) of
  1647. * a_flag. Drivers are free to use the upper nibble (4 bits) of a_flag.
  1648. */
  1649. #define ADV_POLL_REQUEST 0x01 /* poll for request completion */
  1650. #define ADV_SCSIQ_DONE 0x02 /* request done */
  1651. #define ADV_DONT_RETRY 0x08 /* don't do retry */
  1652. #define ADV_CHIP_ASC3550 0x01 /* Ultra-Wide IC */
  1653. #define ADV_CHIP_ASC38C0800 0x02 /* Ultra2-Wide/LVD IC */
  1654. #define ADV_CHIP_ASC38C1600 0x03 /* Ultra3-Wide/LVD2 IC */
  1655. /*
  1656. * Adapter temporary configuration structure
  1657. *
  1658. * This structure can be discarded after initialization. Don't add
  1659. * fields here needed after initialization.
  1660. *
  1661. * Field naming convention:
  1662. *
  1663. * *_enable indicates the field enables or disables a feature. The
  1664. * value of the field is never reset.
  1665. */
  1666. typedef struct adv_dvc_cfg {
  1667. ushort disc_enable; /* enable disconnection */
  1668. uchar chip_version; /* chip version */
  1669. uchar termination; /* Term. Ctrl. bits 6-5 of SCSI_CFG1 register */
  1670. ushort control_flag; /* Microcode Control Flag */
  1671. ushort mcode_date; /* Microcode date */
  1672. ushort mcode_version; /* Microcode version */
  1673. ushort serial1; /* EEPROM serial number word 1 */
  1674. ushort serial2; /* EEPROM serial number word 2 */
  1675. ushort serial3; /* EEPROM serial number word 3 */
  1676. } ADV_DVC_CFG;
  1677. struct adv_dvc_var;
  1678. struct adv_scsi_req_q;
  1679. typedef struct asc_sg_block {
  1680. uchar reserved1;
  1681. uchar reserved2;
  1682. uchar reserved3;
  1683. uchar sg_cnt; /* Valid entries in block. */
  1684. ADV_PADDR sg_ptr; /* Pointer to next sg block. */
  1685. struct {
  1686. ADV_PADDR sg_addr; /* SG element address. */
  1687. ADV_DCNT sg_count; /* SG element count. */
  1688. } sg_list[NO_OF_SG_PER_BLOCK];
  1689. } ADV_SG_BLOCK;
  1690. /*
  1691. * ADV_SCSI_REQ_Q - microcode request structure
  1692. *
  1693. * All fields in this structure up to byte 60 are used by the microcode.
  1694. * The microcode makes assumptions about the size and ordering of fields
  1695. * in this structure. Do not change the structure definition here without
  1696. * coordinating the change with the microcode.
  1697. *
  1698. * All fields accessed by microcode must be maintained in little_endian
  1699. * order.
  1700. */
  1701. typedef struct adv_scsi_req_q {
  1702. uchar cntl; /* Ucode flags and state (ASC_MC_QC_*). */
  1703. uchar target_cmd;
  1704. uchar target_id; /* Device target identifier. */
  1705. uchar target_lun; /* Device target logical unit number. */
  1706. ADV_PADDR data_addr; /* Data buffer physical address. */
  1707. ADV_DCNT data_cnt; /* Data count. Ucode sets to residual. */
  1708. ADV_PADDR sense_addr;
  1709. ADV_PADDR carr_pa;
  1710. uchar mflag;
  1711. uchar sense_len;
  1712. uchar cdb_len; /* SCSI CDB length. Must <= 16 bytes. */
  1713. uchar scsi_cntl;
  1714. uchar done_status; /* Completion status. */
  1715. uchar scsi_status; /* SCSI status byte. */
  1716. uchar host_status; /* Ucode host status. */
  1717. uchar sg_working_ix;
  1718. uchar cdb[12]; /* SCSI CDB bytes 0-11. */
  1719. ADV_PADDR sg_real_addr; /* SG list physical address. */
  1720. ADV_PADDR scsiq_rptr;
  1721. uchar cdb16[4]; /* SCSI CDB bytes 12-15. */
  1722. ADV_VADDR scsiq_ptr;
  1723. ADV_VADDR carr_va;
  1724. /*
  1725. * End of microcode structure - 60 bytes. The rest of the structure
  1726. * is used by the Adv Library and ignored by the microcode.
  1727. */
  1728. ADV_VADDR srb_ptr;
  1729. ADV_SG_BLOCK *sg_list_ptr; /* SG list virtual address. */
  1730. char *vdata_addr; /* Data buffer virtual address. */
  1731. uchar a_flag;
  1732. uchar pad[2]; /* Pad out to a word boundary. */
  1733. } ADV_SCSI_REQ_Q;
  1734. /*
  1735. * The following two structures are used to process Wide Board requests.
  1736. *
  1737. * The ADV_SCSI_REQ_Q structure in adv_req_t is passed to the Adv Library
  1738. * and microcode with the ADV_SCSI_REQ_Q field 'srb_ptr' pointing to the
  1739. * adv_req_t. The adv_req_t structure 'cmndp' field in turn points to the
  1740. * Mid-Level SCSI request structure.
  1741. *
  1742. * Zero or more ADV_SG_BLOCK are used with each ADV_SCSI_REQ_Q. Each
  1743. * ADV_SG_BLOCK structure holds 15 scatter-gather elements. Under Linux
  1744. * up to 255 scatter-gather elements may be used per request or
  1745. * ADV_SCSI_REQ_Q.
  1746. *
  1747. * Both structures must be 32 byte aligned.
  1748. */
  1749. typedef struct adv_sgblk {
  1750. ADV_SG_BLOCK sg_block; /* Sgblock structure. */
  1751. uchar align[32]; /* Sgblock structure padding. */
  1752. struct adv_sgblk *next_sgblkp; /* Next scatter-gather structure. */
  1753. } adv_sgblk_t;
  1754. typedef struct adv_req {
  1755. ADV_SCSI_REQ_Q scsi_req_q; /* Adv Library request structure. */
  1756. uchar align[32]; /* Request structure padding. */
  1757. struct scsi_cmnd *cmndp; /* Mid-Level SCSI command pointer. */
  1758. adv_sgblk_t *sgblkp; /* Adv Library scatter-gather pointer. */
  1759. struct adv_req *next_reqp; /* Next Request Structure. */
  1760. } adv_req_t;
  1761. /*
  1762. * Adapter operation variable structure.
  1763. *
  1764. * One structure is required per host adapter.
  1765. *
  1766. * Field naming convention:
  1767. *
  1768. * *_able indicates both whether a feature should be enabled or disabled
  1769. * and whether a device isi capable of the feature. At initialization
  1770. * this field may be set, but later if a device is found to be incapable
  1771. * of the feature, the field is cleared.
  1772. */
  1773. typedef struct adv_dvc_var {
  1774. AdvPortAddr iop_base; /* I/O port address */
  1775. ushort err_code; /* fatal error code */
  1776. ushort bios_ctrl; /* BIOS control word, EEPROM word 12 */
  1777. ushort wdtr_able; /* try WDTR for a device */
  1778. ushort sdtr_able; /* try SDTR for a device */
  1779. ushort ultra_able; /* try SDTR Ultra speed for a device */
  1780. ushort sdtr_speed1; /* EEPROM SDTR Speed for TID 0-3 */
  1781. ushort sdtr_speed2; /* EEPROM SDTR Speed for TID 4-7 */
  1782. ushort sdtr_speed3; /* EEPROM SDTR Speed for TID 8-11 */
  1783. ushort sdtr_speed4; /* EEPROM SDTR Speed for TID 12-15 */
  1784. ushort tagqng_able; /* try tagged queuing with a device */
  1785. ushort ppr_able; /* PPR message capable per TID bitmask. */
  1786. uchar max_dvc_qng; /* maximum number of tagged commands per device */
  1787. ushort start_motor; /* start motor command allowed */
  1788. uchar scsi_reset_wait; /* delay in seconds after scsi bus reset */
  1789. uchar chip_no; /* should be assigned by caller */
  1790. uchar max_host_qng; /* maximum number of Q'ed command allowed */
  1791. ushort no_scam; /* scam_tolerant of EEPROM */
  1792. struct asc_board *drv_ptr; /* driver pointer to private structure */
  1793. uchar chip_scsi_id; /* chip SCSI target ID */
  1794. uchar chip_type;
  1795. uchar bist_err_code;
  1796. ADV_CARR_T *carrier_buf;
  1797. ADV_CARR_T *carr_freelist; /* Carrier free list. */
  1798. ADV_CARR_T *icq_sp; /* Initiator command queue stopper pointer. */
  1799. ADV_CARR_T *irq_sp; /* Initiator response queue stopper pointer. */
  1800. ushort carr_pending_cnt; /* Count of pending carriers. */
  1801. struct adv_req *orig_reqp; /* adv_req_t memory block. */
  1802. /*
  1803. * Note: The following fields will not be used after initialization. The
  1804. * driver may discard the buffer after initialization is done.
  1805. */
  1806. ADV_DVC_CFG *cfg; /* temporary configuration structure */
  1807. } ADV_DVC_VAR;
  1808. /*
  1809. * Microcode idle loop commands
  1810. */
  1811. #define IDLE_CMD_COMPLETED 0
  1812. #define IDLE_CMD_STOP_CHIP 0x0001
  1813. #define IDLE_CMD_STOP_CHIP_SEND_INT 0x0002
  1814. #define IDLE_CMD_SEND_INT 0x0004
  1815. #define IDLE_CMD_ABORT 0x0008
  1816. #define IDLE_CMD_DEVICE_RESET 0x0010
  1817. #define IDLE_CMD_SCSI_RESET_START 0x0020 /* Assert SCSI Bus Reset */
  1818. #define IDLE_CMD_SCSI_RESET_END 0x0040 /* Deassert SCSI Bus Reset */
  1819. #define IDLE_CMD_SCSIREQ 0x0080
  1820. #define IDLE_CMD_STATUS_SUCCESS 0x0001
  1821. #define IDLE_CMD_STATUS_FAILURE 0x0002
  1822. /*
  1823. * AdvSendIdleCmd() flag definitions.
  1824. */
  1825. #define ADV_NOWAIT 0x01
  1826. /*
  1827. * Wait loop time out values.
  1828. */
  1829. #define SCSI_WAIT_100_MSEC 100UL /* 100 milliseconds */
  1830. #define SCSI_US_PER_MSEC 1000 /* microseconds per millisecond */
  1831. #define SCSI_MAX_RETRY 10 /* retry count */
  1832. #define ADV_ASYNC_RDMA_FAILURE 0x01 /* Fatal RDMA failure. */
  1833. #define ADV_ASYNC_SCSI_BUS_RESET_DET 0x02 /* Detected SCSI Bus Reset. */
  1834. #define ADV_ASYNC_CARRIER_READY_FAILURE 0x03 /* Carrier Ready failure. */
  1835. #define ADV_RDMA_IN_CARR_AND_Q_INVALID 0x04 /* RDMAed-in data invalid. */
  1836. #define ADV_HOST_SCSI_BUS_RESET 0x80 /* Host Initiated SCSI Bus Reset. */
  1837. /* Read byte from a register. */
  1838. #define AdvReadByteRegister(iop_base, reg_off) \
  1839. (ADV_MEM_READB((iop_base) + (reg_off)))
  1840. /* Write byte to a register. */
  1841. #define AdvWriteByteRegister(iop_base, reg_off, byte) \
  1842. (ADV_MEM_WRITEB((iop_base) + (reg_off), (byte)))
  1843. /* Read word (2 bytes) from a register. */
  1844. #define AdvReadWordRegister(iop_base, reg_off) \
  1845. (ADV_MEM_READW((iop_base) + (reg_off)))
  1846. /* Write word (2 bytes) to a register. */
  1847. #define AdvWriteWordRegister(iop_base, reg_off, word) \
  1848. (ADV_MEM_WRITEW((iop_base) + (reg_off), (word)))
  1849. /* Write dword (4 bytes) to a register. */
  1850. #define AdvWriteDWordRegister(iop_base, reg_off, dword) \
  1851. (ADV_MEM_WRITEDW((iop_base) + (reg_off), (dword)))
  1852. /* Read byte from LRAM. */
  1853. #define AdvReadByteLram(iop_base, addr, byte) \
  1854. do { \
  1855. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
  1856. (byte) = ADV_MEM_READB((iop_base) + IOPB_RAM_DATA); \
  1857. } while (0)
  1858. /* Write byte to LRAM. */
  1859. #define AdvWriteByteLram(iop_base, addr, byte) \
  1860. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1861. ADV_MEM_WRITEB((iop_base) + IOPB_RAM_DATA, (byte)))
  1862. /* Read word (2 bytes) from LRAM. */
  1863. #define AdvReadWordLram(iop_base, addr, word) \
  1864. do { \
  1865. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
  1866. (word) = (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA)); \
  1867. } while (0)
  1868. /* Write word (2 bytes) to LRAM. */
  1869. #define AdvWriteWordLram(iop_base, addr, word) \
  1870. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1871. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
  1872. /* Write little-endian double word (4 bytes) to LRAM */
  1873. /* Because of unspecified C language ordering don't use auto-increment. */
  1874. #define AdvWriteDWordLramNoSwap(iop_base, addr, dword) \
  1875. ((ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
  1876. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
  1877. cpu_to_le16((ushort) ((dword) & 0xFFFF)))), \
  1878. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr) + 2), \
  1879. ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
  1880. cpu_to_le16((ushort) ((dword >> 16) & 0xFFFF)))))
  1881. /* Read word (2 bytes) from LRAM assuming that the address is already set. */
  1882. #define AdvReadWordAutoIncLram(iop_base) \
  1883. (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA))
  1884. /* Write word (2 bytes) to LRAM assuming that the address is already set. */
  1885. #define AdvWriteWordAutoIncLram(iop_base, word) \
  1886. (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
  1887. /*
  1888. * Define macro to check for Condor signature.
  1889. *
  1890. * Evaluate to ADV_TRUE if a Condor chip is found the specified port
  1891. * address 'iop_base'. Otherwise evalue to ADV_FALSE.
  1892. */
  1893. #define AdvFindSignature(iop_base) \
  1894. (((AdvReadByteRegister((iop_base), IOPB_CHIP_ID_1) == \
  1895. ADV_CHIP_ID_BYTE) && \
  1896. (AdvReadWordRegister((iop_base), IOPW_CHIP_ID_0) == \
  1897. ADV_CHIP_ID_WORD)) ? ADV_TRUE : ADV_FALSE)
  1898. /*
  1899. * Define macro to Return the version number of the chip at 'iop_base'.
  1900. *
  1901. * The second parameter 'bus_type' is currently unused.
  1902. */
  1903. #define AdvGetChipVersion(iop_base, bus_type) \
  1904. AdvReadByteRegister((iop_base), IOPB_CHIP_TYPE_REV)
  1905. /*
  1906. * Abort an SRB in the chip's RISC Memory. The 'srb_ptr' argument must
  1907. * match the ASC_SCSI_REQ_Q 'srb_ptr' field.
  1908. *
  1909. * If the request has not yet been sent to the device it will simply be
  1910. * aborted from RISC memory. If the request is disconnected it will be
  1911. * aborted on reselection by sending an Abort Message to the target ID.
  1912. *
  1913. * Return value:
  1914. * ADV_TRUE(1) - Queue was successfully aborted.
  1915. * ADV_FALSE(0) - Queue was not found on the active queue list.
  1916. */
  1917. #define AdvAbortQueue(asc_dvc, scsiq) \
  1918. AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_ABORT, \
  1919. (ADV_DCNT) (scsiq))
  1920. /*
  1921. * Send a Bus Device Reset Message to the specified target ID.
  1922. *
  1923. * All outstanding commands will be purged if sending the
  1924. * Bus Device Reset Message is successful.
  1925. *
  1926. * Return Value:
  1927. * ADV_TRUE(1) - All requests on the target are purged.
  1928. * ADV_FALSE(0) - Couldn't issue Bus Device Reset Message; Requests
  1929. * are not purged.
  1930. */
  1931. #define AdvResetDevice(asc_dvc, target_id) \
  1932. AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_DEVICE_RESET, \
  1933. (ADV_DCNT) (target_id))
  1934. /*
  1935. * SCSI Wide Type definition.
  1936. */
  1937. #define ADV_SCSI_BIT_ID_TYPE ushort
  1938. /*
  1939. * AdvInitScsiTarget() 'cntl_flag' options.
  1940. */
  1941. #define ADV_SCAN_LUN 0x01
  1942. #define ADV_CAPINFO_NOLUN 0x02
  1943. /*
  1944. * Convert target id to target id bit mask.
  1945. */
  1946. #define ADV_TID_TO_TIDMASK(tid) (0x01 << ((tid) & ADV_MAX_TID))
  1947. /*
  1948. * ASC_SCSI_REQ_Q 'done_status' and 'host_status' return values.
  1949. */
  1950. #define QD_NO_STATUS 0x00 /* Request not completed yet. */
  1951. #define QD_NO_ERROR 0x01
  1952. #define QD_ABORTED_BY_HOST 0x02
  1953. #define QD_WITH_ERROR 0x04
  1954. #define QHSTA_NO_ERROR 0x00
  1955. #define QHSTA_M_SEL_TIMEOUT 0x11
  1956. #define QHSTA_M_DATA_OVER_RUN 0x12
  1957. #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
  1958. #define QHSTA_M_QUEUE_ABORTED 0x15
  1959. #define QHSTA_M_SXFR_SDMA_ERR 0x16 /* SXFR_STATUS SCSI DMA Error */
  1960. #define QHSTA_M_SXFR_SXFR_PERR 0x17 /* SXFR_STATUS SCSI Bus Parity Error */
  1961. #define QHSTA_M_RDMA_PERR 0x18 /* RISC PCI DMA parity error */
  1962. #define QHSTA_M_SXFR_OFF_UFLW 0x19 /* SXFR_STATUS Offset Underflow */
  1963. #define QHSTA_M_SXFR_OFF_OFLW 0x20 /* SXFR_STATUS Offset Overflow */
  1964. #define QHSTA_M_SXFR_WD_TMO 0x21 /* SXFR_STATUS Watchdog Timeout */
  1965. #define QHSTA_M_SXFR_DESELECTED 0x22 /* SXFR_STATUS Deselected */
  1966. /* Note: QHSTA_M_SXFR_XFR_OFLW is identical to QHSTA_M_DATA_OVER_RUN. */
  1967. #define QHSTA_M_SXFR_XFR_OFLW 0x12 /* SXFR_STATUS Transfer Overflow */
  1968. #define QHSTA_M_SXFR_XFR_PH_ERR 0x24 /* SXFR_STATUS Transfer Phase Error */
  1969. #define QHSTA_M_SXFR_UNKNOWN_ERROR 0x25 /* SXFR_STATUS Unknown Error */
  1970. #define QHSTA_M_SCSI_BUS_RESET 0x30 /* Request aborted from SBR */
  1971. #define QHSTA_M_SCSI_BUS_RESET_UNSOL 0x31 /* Request aborted from unsol. SBR */
  1972. #define QHSTA_M_BUS_DEVICE_RESET 0x32 /* Request aborted from BDR */
  1973. #define QHSTA_M_DIRECTION_ERR 0x35 /* Data Phase mismatch */
  1974. #define QHSTA_M_DIRECTION_ERR_HUNG 0x36 /* Data Phase mismatch and bus hang */
  1975. #define QHSTA_M_WTM_TIMEOUT 0x41
  1976. #define QHSTA_M_BAD_CMPL_STATUS_IN 0x42
  1977. #define QHSTA_M_NO_AUTO_REQ_SENSE 0x43
  1978. #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
  1979. #define QHSTA_M_INVALID_DEVICE 0x45 /* Bad target ID */
  1980. #define QHSTA_M_FROZEN_TIDQ 0x46 /* TID Queue frozen. */
  1981. #define QHSTA_M_SGBACKUP_ERROR 0x47 /* Scatter-Gather backup error */
  1982. /* Return the address that is aligned at the next doubleword >= to 'addr'. */
  1983. #define ADV_8BALIGN(addr) (((ulong) (addr) + 0x7) & ~0x7)
  1984. #define ADV_16BALIGN(addr) (((ulong) (addr) + 0xF) & ~0xF)
  1985. #define ADV_32BALIGN(addr) (((ulong) (addr) + 0x1F) & ~0x1F)
  1986. /*
  1987. * Total contiguous memory needed for driver SG blocks.
  1988. *
  1989. * ADV_MAX_SG_LIST must be defined by a driver. It is the maximum
  1990. * number of scatter-gather elements the driver supports in a
  1991. * single request.
  1992. */
  1993. #define ADV_SG_LIST_MAX_BYTE_SIZE \
  1994. (sizeof(ADV_SG_BLOCK) * \
  1995. ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK))
  1996. /* struct asc_board flags */
  1997. #define ASC_IS_WIDE_BOARD 0x04 /* AdvanSys Wide Board */
  1998. #define ASC_NARROW_BOARD(boardp) (((boardp)->flags & ASC_IS_WIDE_BOARD) == 0)
  1999. #define NO_ISA_DMA 0xff /* No ISA DMA Channel Used */
  2000. #define ASC_INFO_SIZE 128 /* advansys_info() line size */
  2001. /* Asc Library return codes */
  2002. #define ASC_TRUE 1
  2003. #define ASC_FALSE 0
  2004. #define ASC_NOERROR 1
  2005. #define ASC_BUSY 0
  2006. #define ASC_ERROR (-1)
  2007. /* struct scsi_cmnd function return codes */
  2008. #define STATUS_BYTE(byte) (byte)
  2009. #define MSG_BYTE(byte) ((byte) << 8)
  2010. #define HOST_BYTE(byte) ((byte) << 16)
  2011. #define DRIVER_BYTE(byte) ((byte) << 24)
  2012. #define ASC_STATS(shost, counter) ASC_STATS_ADD(shost, counter, 1)
  2013. #ifndef ADVANSYS_STATS
  2014. #define ASC_STATS_ADD(shost, counter, count)
  2015. #else /* ADVANSYS_STATS */
  2016. #define ASC_STATS_ADD(shost, counter, count) \
  2017. (((struct asc_board *) shost_priv(shost))->asc_stats.counter += (count))
  2018. #endif /* ADVANSYS_STATS */
  2019. /* If the result wraps when calculating tenths, return 0. */
  2020. #define ASC_TENTHS(num, den) \
  2021. (((10 * ((num)/(den))) > (((num) * 10)/(den))) ? \
  2022. 0 : ((((num) * 10)/(den)) - (10 * ((num)/(den)))))
  2023. /*
  2024. * Display a message to the console.
  2025. */
  2026. #define ASC_PRINT(s) \
  2027. { \
  2028. printk("advansys: "); \
  2029. printk(s); \
  2030. }
  2031. #define ASC_PRINT1(s, a1) \
  2032. { \
  2033. printk("advansys: "); \
  2034. printk((s), (a1)); \
  2035. }
  2036. #define ASC_PRINT2(s, a1, a2) \
  2037. { \
  2038. printk("advansys: "); \
  2039. printk((s), (a1), (a2)); \
  2040. }
  2041. #define ASC_PRINT3(s, a1, a2, a3) \
  2042. { \
  2043. printk("advansys: "); \
  2044. printk((s), (a1), (a2), (a3)); \
  2045. }
  2046. #define ASC_PRINT4(s, a1, a2, a3, a4) \
  2047. { \
  2048. printk("advansys: "); \
  2049. printk((s), (a1), (a2), (a3), (a4)); \
  2050. }
  2051. #ifndef ADVANSYS_DEBUG
  2052. #define ASC_DBG(lvl, s...)
  2053. #define ASC_DBG_PRT_SCSI_HOST(lvl, s)
  2054. #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp)
  2055. #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
  2056. #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone)
  2057. #define ADV_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
  2058. #define ASC_DBG_PRT_HEX(lvl, name, start, length)
  2059. #define ASC_DBG_PRT_CDB(lvl, cdb, len)
  2060. #define ASC_DBG_PRT_SENSE(lvl, sense, len)
  2061. #define ASC_DBG_PRT_INQUIRY(lvl, inq, len)
  2062. #else /* ADVANSYS_DEBUG */
  2063. /*
  2064. * Debugging Message Levels:
  2065. * 0: Errors Only
  2066. * 1: High-Level Tracing
  2067. * 2-N: Verbose Tracing
  2068. */
  2069. #define ASC_DBG(lvl, format, arg...) { \
  2070. if (asc_dbglvl >= (lvl)) \
  2071. printk(KERN_DEBUG "%s: %s: " format, DRV_NAME, \
  2072. __func__ , ## arg); \
  2073. }
  2074. #define ASC_DBG_PRT_SCSI_HOST(lvl, s) \
  2075. { \
  2076. if (asc_dbglvl >= (lvl)) { \
  2077. asc_prt_scsi_host(s); \
  2078. } \
  2079. }
  2080. #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp) \
  2081. { \
  2082. if (asc_dbglvl >= (lvl)) { \
  2083. asc_prt_asc_scsi_q(scsiqp); \
  2084. } \
  2085. }
  2086. #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone) \
  2087. { \
  2088. if (asc_dbglvl >= (lvl)) { \
  2089. asc_prt_asc_qdone_info(qdone); \
  2090. } \
  2091. }
  2092. #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp) \
  2093. { \
  2094. if (asc_dbglvl >= (lvl)) { \
  2095. asc_prt_adv_scsi_req_q(scsiqp); \
  2096. } \
  2097. }
  2098. #define ASC_DBG_PRT_HEX(lvl, name, start, length) \
  2099. { \
  2100. if (asc_dbglvl >= (lvl)) { \
  2101. asc_prt_hex((name), (start), (length)); \
  2102. } \
  2103. }
  2104. #define ASC_DBG_PRT_CDB(lvl, cdb, len) \
  2105. ASC_DBG_PRT_HEX((lvl), "CDB", (uchar *) (cdb), (len));
  2106. #define ASC_DBG_PRT_SENSE(lvl, sense, len) \
  2107. ASC_DBG_PRT_HEX((lvl), "SENSE", (uchar *) (sense), (len));
  2108. #define ASC_DBG_PRT_INQUIRY(lvl, inq, len) \
  2109. ASC_DBG_PRT_HEX((lvl), "INQUIRY", (uchar *) (inq), (len));
  2110. #endif /* ADVANSYS_DEBUG */
  2111. #ifdef ADVANSYS_STATS
  2112. /* Per board statistics structure */
  2113. struct asc_stats {
  2114. /* Driver Entrypoint Statistics */
  2115. ADV_DCNT queuecommand; /* # calls to advansys_queuecommand() */
  2116. ADV_DCNT reset; /* # calls to advansys_eh_bus_reset() */
  2117. ADV_DCNT biosparam; /* # calls to advansys_biosparam() */
  2118. ADV_DCNT interrupt; /* # advansys_interrupt() calls */
  2119. ADV_DCNT callback; /* # calls to asc/adv_isr_callback() */
  2120. ADV_DCNT done; /* # calls to request's scsi_done function */
  2121. ADV_DCNT build_error; /* # asc/adv_build_req() ASC_ERROR returns. */
  2122. ADV_DCNT adv_build_noreq; /* # adv_build_req() adv_req_t alloc. fail. */
  2123. ADV_DCNT adv_build_nosg; /* # adv_build_req() adv_sgblk_t alloc. fail. */
  2124. /* AscExeScsiQueue()/AdvExeScsiQueue() Statistics */
  2125. ADV_DCNT exe_noerror; /* # ASC_NOERROR returns. */
  2126. ADV_DCNT exe_busy; /* # ASC_BUSY returns. */
  2127. ADV_DCNT exe_error; /* # ASC_ERROR returns. */
  2128. ADV_DCNT exe_unknown; /* # unknown returns. */
  2129. /* Data Transfer Statistics */
  2130. ADV_DCNT xfer_cnt; /* # I/O requests received */
  2131. ADV_DCNT xfer_elem; /* # scatter-gather elements */
  2132. ADV_DCNT xfer_sect; /* # 512-byte blocks */
  2133. };
  2134. #endif /* ADVANSYS_STATS */
  2135. /*
  2136. * Structure allocated for each board.
  2137. *
  2138. * This structure is allocated by scsi_host_alloc() at the end
  2139. * of the 'Scsi_Host' structure starting at the 'hostdata'
  2140. * field. It is guaranteed to be allocated from DMA-able memory.
  2141. */
  2142. struct asc_board {
  2143. struct device *dev;
  2144. uint flags; /* Board flags */
  2145. unsigned int irq;
  2146. union {
  2147. ASC_DVC_VAR asc_dvc_var; /* Narrow board */
  2148. ADV_DVC_VAR adv_dvc_var; /* Wide board */
  2149. } dvc_var;
  2150. union {
  2151. ASC_DVC_CFG asc_dvc_cfg; /* Narrow board */
  2152. ADV_DVC_CFG adv_dvc_cfg; /* Wide board */
  2153. } dvc_cfg;
  2154. ushort asc_n_io_port; /* Number I/O ports. */
  2155. ADV_SCSI_BIT_ID_TYPE init_tidmask; /* Target init./valid mask */
  2156. ushort reqcnt[ADV_MAX_TID + 1]; /* Starvation request count */
  2157. ADV_SCSI_BIT_ID_TYPE queue_full; /* Queue full mask */
  2158. ushort queue_full_cnt[ADV_MAX_TID + 1]; /* Queue full count */
  2159. union {
  2160. ASCEEP_CONFIG asc_eep; /* Narrow EEPROM config. */
  2161. ADVEEP_3550_CONFIG adv_3550_eep; /* 3550 EEPROM config. */
  2162. ADVEEP_38C0800_CONFIG adv_38C0800_eep; /* 38C0800 EEPROM config. */
  2163. ADVEEP_38C1600_CONFIG adv_38C1600_eep; /* 38C1600 EEPROM config. */
  2164. } eep_config;
  2165. ulong last_reset; /* Saved last reset time */
  2166. /* /proc/scsi/advansys/[0...] */
  2167. #ifdef ADVANSYS_STATS
  2168. struct asc_stats asc_stats; /* Board statistics */
  2169. #endif /* ADVANSYS_STATS */
  2170. /*
  2171. * The following fields are used only for Narrow Boards.
  2172. */
  2173. uchar sdtr_data[ASC_MAX_TID + 1]; /* SDTR information */
  2174. /*
  2175. * The following fields are used only for Wide Boards.
  2176. */
  2177. void __iomem *ioremap_addr; /* I/O Memory remap address. */
  2178. ushort ioport; /* I/O Port address. */
  2179. adv_req_t *adv_reqp; /* Request structures. */
  2180. adv_sgblk_t *adv_sgblkp; /* Scatter-gather structures. */
  2181. ushort bios_signature; /* BIOS Signature. */
  2182. ushort bios_version; /* BIOS Version. */
  2183. ushort bios_codeseg; /* BIOS Code Segment. */
  2184. ushort bios_codelen; /* BIOS Code Segment Length. */
  2185. };
  2186. #define asc_dvc_to_board(asc_dvc) container_of(asc_dvc, struct asc_board, \
  2187. dvc_var.asc_dvc_var)
  2188. #define adv_dvc_to_board(adv_dvc) container_of(adv_dvc, struct asc_board, \
  2189. dvc_var.adv_dvc_var)
  2190. #define adv_dvc_to_pdev(adv_dvc) to_pci_dev(adv_dvc_to_board(adv_dvc)->dev)
  2191. #ifdef ADVANSYS_DEBUG
  2192. static int asc_dbglvl = 3;
  2193. /*
  2194. * asc_prt_asc_dvc_var()
  2195. */
  2196. static void asc_prt_asc_dvc_var(ASC_DVC_VAR *h)
  2197. {
  2198. printk("ASC_DVC_VAR at addr 0x%lx\n", (ulong)h);
  2199. printk(" iop_base 0x%x, err_code 0x%x, dvc_cntl 0x%x, bug_fix_cntl "
  2200. "%d,\n", h->iop_base, h->err_code, h->dvc_cntl, h->bug_fix_cntl);
  2201. printk(" bus_type %d, init_sdtr 0x%x,\n", h->bus_type,
  2202. (unsigned)h->init_sdtr);
  2203. printk(" sdtr_done 0x%x, use_tagged_qng 0x%x, unit_not_ready 0x%x, "
  2204. "chip_no 0x%x,\n", (unsigned)h->sdtr_done,
  2205. (unsigned)h->use_tagged_qng, (unsigned)h->unit_not_ready,
  2206. (unsigned)h->chip_no);
  2207. printk(" queue_full_or_busy 0x%x, start_motor 0x%x, scsi_reset_wait "
  2208. "%u,\n", (unsigned)h->queue_full_or_busy,
  2209. (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
  2210. printk(" is_in_int %u, max_total_qng %u, cur_total_qng %u, "
  2211. "in_critical_cnt %u,\n", (unsigned)h->is_in_int,
  2212. (unsigned)h->max_total_qng, (unsigned)h->cur_total_qng,
  2213. (unsigned)h->in_critical_cnt);
  2214. printk(" last_q_shortage %u, init_state 0x%x, no_scam 0x%x, "
  2215. "pci_fix_asyn_xfer 0x%x,\n", (unsigned)h->last_q_shortage,
  2216. (unsigned)h->init_state, (unsigned)h->no_scam,
  2217. (unsigned)h->pci_fix_asyn_xfer);
  2218. printk(" cfg 0x%lx\n", (ulong)h->cfg);
  2219. }
  2220. /*
  2221. * asc_prt_asc_dvc_cfg()
  2222. */
  2223. static void asc_prt_asc_dvc_cfg(ASC_DVC_CFG *h)
  2224. {
  2225. printk("ASC_DVC_CFG at addr 0x%lx\n", (ulong)h);
  2226. printk(" can_tagged_qng 0x%x, cmd_qng_enabled 0x%x,\n",
  2227. h->can_tagged_qng, h->cmd_qng_enabled);
  2228. printk(" disc_enable 0x%x, sdtr_enable 0x%x,\n",
  2229. h->disc_enable, h->sdtr_enable);
  2230. printk(" chip_scsi_id %d, isa_dma_speed %d, isa_dma_channel %d, "
  2231. "chip_version %d,\n", h->chip_scsi_id, h->isa_dma_speed,
  2232. h->isa_dma_channel, h->chip_version);
  2233. printk(" mcode_date 0x%x, mcode_version %d\n",
  2234. h->mcode_date, h->mcode_version);
  2235. }
  2236. /*
  2237. * asc_prt_adv_dvc_var()
  2238. *
  2239. * Display an ADV_DVC_VAR structure.
  2240. */
  2241. static void asc_prt_adv_dvc_var(ADV_DVC_VAR *h)
  2242. {
  2243. printk(" ADV_DVC_VAR at addr 0x%lx\n", (ulong)h);
  2244. printk(" iop_base 0x%lx, err_code 0x%x, ultra_able 0x%x\n",
  2245. (ulong)h->iop_base, h->err_code, (unsigned)h->ultra_able);
  2246. printk(" sdtr_able 0x%x, wdtr_able 0x%x\n",
  2247. (unsigned)h->sdtr_able, (unsigned)h->wdtr_able);
  2248. printk(" start_motor 0x%x, scsi_reset_wait 0x%x\n",
  2249. (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait);
  2250. printk(" max_host_qng %u, max_dvc_qng %u, carr_freelist 0x%lxn\n",
  2251. (unsigned)h->max_host_qng, (unsigned)h->max_dvc_qng,
  2252. (ulong)h->carr_freelist);
  2253. printk(" icq_sp 0x%lx, irq_sp 0x%lx\n",
  2254. (ulong)h->icq_sp, (ulong)h->irq_sp);
  2255. printk(" no_scam 0x%x, tagqng_able 0x%x\n",
  2256. (unsigned)h->no_scam, (unsigned)h->tagqng_able);
  2257. printk(" chip_scsi_id 0x%x, cfg 0x%lx\n",
  2258. (unsigned)h->chip_scsi_id, (ulong)h->cfg);
  2259. }
  2260. /*
  2261. * asc_prt_adv_dvc_cfg()
  2262. *
  2263. * Display an ADV_DVC_CFG structure.
  2264. */
  2265. static void asc_prt_adv_dvc_cfg(ADV_DVC_CFG *h)
  2266. {
  2267. printk(" ADV_DVC_CFG at addr 0x%lx\n", (ulong)h);
  2268. printk(" disc_enable 0x%x, termination 0x%x\n",
  2269. h->disc_enable, h->termination);
  2270. printk(" chip_version 0x%x, mcode_date 0x%x\n",
  2271. h->chip_version, h->mcode_date);
  2272. printk(" mcode_version 0x%x, control_flag 0x%x\n",
  2273. h->mcode_version, h->control_flag);
  2274. }
  2275. /*
  2276. * asc_prt_scsi_host()
  2277. */
  2278. static void asc_prt_scsi_host(struct Scsi_Host *s)
  2279. {
  2280. struct asc_board *boardp = shost_priv(s);
  2281. printk("Scsi_Host at addr 0x%p, device %s\n", s, dev_name(boardp->dev));
  2282. printk(" host_busy %u, host_no %d,\n",
  2283. s->host_busy, s->host_no);
  2284. printk(" base 0x%lx, io_port 0x%lx, irq %d,\n",
  2285. (ulong)s->base, (ulong)s->io_port, boardp->irq);
  2286. printk(" dma_channel %d, this_id %d, can_queue %d,\n",
  2287. s->dma_channel, s->this_id, s->can_queue);
  2288. printk(" cmd_per_lun %d, sg_tablesize %d, unchecked_isa_dma %d\n",
  2289. s->cmd_per_lun, s->sg_tablesize, s->unchecked_isa_dma);
  2290. if (ASC_NARROW_BOARD(boardp)) {
  2291. asc_prt_asc_dvc_var(&boardp->dvc_var.asc_dvc_var);
  2292. asc_prt_asc_dvc_cfg(&boardp->dvc_cfg.asc_dvc_cfg);
  2293. } else {
  2294. asc_prt_adv_dvc_var(&boardp->dvc_var.adv_dvc_var);
  2295. asc_prt_adv_dvc_cfg(&boardp->dvc_cfg.adv_dvc_cfg);
  2296. }
  2297. }
  2298. /*
  2299. * asc_prt_hex()
  2300. *
  2301. * Print hexadecimal output in 4 byte groupings 32 bytes
  2302. * or 8 double-words per line.
  2303. */
  2304. static void asc_prt_hex(char *f, uchar *s, int l)
  2305. {
  2306. int i;
  2307. int j;
  2308. int k;
  2309. int m;
  2310. printk("%s: (%d bytes)\n", f, l);
  2311. for (i = 0; i < l; i += 32) {
  2312. /* Display a maximum of 8 double-words per line. */
  2313. if ((k = (l - i) / 4) >= 8) {
  2314. k = 8;
  2315. m = 0;
  2316. } else {
  2317. m = (l - i) % 4;
  2318. }
  2319. for (j = 0; j < k; j++) {
  2320. printk(" %2.2X%2.2X%2.2X%2.2X",
  2321. (unsigned)s[i + (j * 4)],
  2322. (unsigned)s[i + (j * 4) + 1],
  2323. (unsigned)s[i + (j * 4) + 2],
  2324. (unsigned)s[i + (j * 4) + 3]);
  2325. }
  2326. switch (m) {
  2327. case 0:
  2328. default:
  2329. break;
  2330. case 1:
  2331. printk(" %2.2X", (unsigned)s[i + (j * 4)]);
  2332. break;
  2333. case 2:
  2334. printk(" %2.2X%2.2X",
  2335. (unsigned)s[i + (j * 4)],
  2336. (unsigned)s[i + (j * 4) + 1]);
  2337. break;
  2338. case 3:
  2339. printk(" %2.2X%2.2X%2.2X",
  2340. (unsigned)s[i + (j * 4) + 1],
  2341. (unsigned)s[i + (j * 4) + 2],
  2342. (unsigned)s[i + (j * 4) + 3]);
  2343. break;
  2344. }
  2345. printk("\n");
  2346. }
  2347. }
  2348. /*
  2349. * asc_prt_asc_scsi_q()
  2350. */
  2351. static void asc_prt_asc_scsi_q(ASC_SCSI_Q *q)
  2352. {
  2353. ASC_SG_HEAD *sgp;
  2354. int i;
  2355. printk("ASC_SCSI_Q at addr 0x%lx\n", (ulong)q);
  2356. printk
  2357. (" target_ix 0x%x, target_lun %u, srb_ptr 0x%lx, tag_code 0x%x,\n",
  2358. q->q2.target_ix, q->q1.target_lun, (ulong)q->q2.srb_ptr,
  2359. q->q2.tag_code);
  2360. printk
  2361. (" data_addr 0x%lx, data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
  2362. (ulong)le32_to_cpu(q->q1.data_addr),
  2363. (ulong)le32_to_cpu(q->q1.data_cnt),
  2364. (ulong)le32_to_cpu(q->q1.sense_addr), q->q1.sense_len);
  2365. printk(" cdbptr 0x%lx, cdb_len %u, sg_head 0x%lx, sg_queue_cnt %u\n",
  2366. (ulong)q->cdbptr, q->q2.cdb_len,
  2367. (ulong)q->sg_head, q->q1.sg_queue_cnt);
  2368. if (q->sg_head) {
  2369. sgp = q->sg_head;
  2370. printk("ASC_SG_HEAD at addr 0x%lx\n", (ulong)sgp);
  2371. printk(" entry_cnt %u, queue_cnt %u\n", sgp->entry_cnt,
  2372. sgp->queue_cnt);
  2373. for (i = 0; i < sgp->entry_cnt; i++) {
  2374. printk(" [%u]: addr 0x%lx, bytes %lu\n",
  2375. i, (ulong)le32_to_cpu(sgp->sg_list[i].addr),
  2376. (ulong)le32_to_cpu(sgp->sg_list[i].bytes));
  2377. }
  2378. }
  2379. }
  2380. /*
  2381. * asc_prt_asc_qdone_info()
  2382. */
  2383. static void asc_prt_asc_qdone_info(ASC_QDONE_INFO *q)
  2384. {
  2385. printk("ASC_QDONE_INFO at addr 0x%lx\n", (ulong)q);
  2386. printk(" srb_ptr 0x%lx, target_ix %u, cdb_len %u, tag_code %u,\n",
  2387. (ulong)q->d2.srb_ptr, q->d2.target_ix, q->d2.cdb_len,
  2388. q->d2.tag_code);
  2389. printk
  2390. (" done_stat 0x%x, host_stat 0x%x, scsi_stat 0x%x, scsi_msg 0x%x\n",
  2391. q->d3.done_stat, q->d3.host_stat, q->d3.scsi_stat, q->d3.scsi_msg);
  2392. }
  2393. /*
  2394. * asc_prt_adv_sgblock()
  2395. *
  2396. * Display an ADV_SG_BLOCK structure.
  2397. */
  2398. static void asc_prt_adv_sgblock(int sgblockno, ADV_SG_BLOCK *b)
  2399. {
  2400. int i;
  2401. printk(" ASC_SG_BLOCK at addr 0x%lx (sgblockno %d)\n",
  2402. (ulong)b, sgblockno);
  2403. printk(" sg_cnt %u, sg_ptr 0x%lx\n",
  2404. b->sg_cnt, (ulong)le32_to_cpu(b->sg_ptr));
  2405. BUG_ON(b->sg_cnt > NO_OF_SG_PER_BLOCK);
  2406. if (b->sg_ptr != 0)
  2407. BUG_ON(b->sg_cnt != NO_OF_SG_PER_BLOCK);
  2408. for (i = 0; i < b->sg_cnt; i++) {
  2409. printk(" [%u]: sg_addr 0x%lx, sg_count 0x%lx\n",
  2410. i, (ulong)b->sg_list[i].sg_addr,
  2411. (ulong)b->sg_list[i].sg_count);
  2412. }
  2413. }
  2414. /*
  2415. * asc_prt_adv_scsi_req_q()
  2416. *
  2417. * Display an ADV_SCSI_REQ_Q structure.
  2418. */
  2419. static void asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q *q)
  2420. {
  2421. int sg_blk_cnt;
  2422. struct asc_sg_block *sg_ptr;
  2423. printk("ADV_SCSI_REQ_Q at addr 0x%lx\n", (ulong)q);
  2424. printk(" target_id %u, target_lun %u, srb_ptr 0x%lx, a_flag 0x%x\n",
  2425. q->target_id, q->target_lun, (ulong)q->srb_ptr, q->a_flag);
  2426. printk(" cntl 0x%x, data_addr 0x%lx, vdata_addr 0x%lx\n",
  2427. q->cntl, (ulong)le32_to_cpu(q->data_addr), (ulong)q->vdata_addr);
  2428. printk(" data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
  2429. (ulong)le32_to_cpu(q->data_cnt),
  2430. (ulong)le32_to_cpu(q->sense_addr), q->sense_len);
  2431. printk
  2432. (" cdb_len %u, done_status 0x%x, host_status 0x%x, scsi_status 0x%x\n",
  2433. q->cdb_len, q->done_status, q->host_status, q->scsi_status);
  2434. printk(" sg_working_ix 0x%x, target_cmd %u\n",
  2435. q->sg_working_ix, q->target_cmd);
  2436. printk(" scsiq_rptr 0x%lx, sg_real_addr 0x%lx, sg_list_ptr 0x%lx\n",
  2437. (ulong)le32_to_cpu(q->scsiq_rptr),
  2438. (ulong)le32_to_cpu(q->sg_real_addr), (ulong)q->sg_list_ptr);
  2439. /* Display the request's ADV_SG_BLOCK structures. */
  2440. if (q->sg_list_ptr != NULL) {
  2441. sg_blk_cnt = 0;
  2442. while (1) {
  2443. /*
  2444. * 'sg_ptr' is a physical address. Convert it to a virtual
  2445. * address by indexing 'sg_blk_cnt' into the virtual address
  2446. * array 'sg_list_ptr'.
  2447. *
  2448. * XXX - Assumes all SG physical blocks are virtually contiguous.
  2449. */
  2450. sg_ptr =
  2451. &(((ADV_SG_BLOCK *)(q->sg_list_ptr))[sg_blk_cnt]);
  2452. asc_prt_adv_sgblock(sg_blk_cnt, sg_ptr);
  2453. if (sg_ptr->sg_ptr == 0) {
  2454. break;
  2455. }
  2456. sg_blk_cnt++;
  2457. }
  2458. }
  2459. }
  2460. #endif /* ADVANSYS_DEBUG */
  2461. /*
  2462. * The advansys chip/microcode contains a 32-bit identifier for each command
  2463. * known as the 'srb'. I don't know what it stands for. The driver used
  2464. * to encode the scsi_cmnd pointer by calling virt_to_bus and retrieve it
  2465. * with bus_to_virt. Now the driver keeps a per-host map of integers to
  2466. * pointers. It auto-expands when full, unless it can't allocate memory.
  2467. * Note that an srb of 0 is treated specially by the chip/firmware, hence
  2468. * the return of i+1 in this routine, and the corresponding subtraction in
  2469. * the inverse routine.
  2470. */
  2471. #define BAD_SRB 0
  2472. static u32 advansys_ptr_to_srb(struct asc_dvc_var *asc_dvc, void *ptr)
  2473. {
  2474. int i;
  2475. void **new_ptr;
  2476. for (i = 0; i < asc_dvc->ptr_map_count; i++) {
  2477. if (!asc_dvc->ptr_map[i])
  2478. goto out;
  2479. }
  2480. if (asc_dvc->ptr_map_count == 0)
  2481. asc_dvc->ptr_map_count = 1;
  2482. else
  2483. asc_dvc->ptr_map_count *= 2;
  2484. new_ptr = krealloc(asc_dvc->ptr_map,
  2485. asc_dvc->ptr_map_count * sizeof(void *), GFP_ATOMIC);
  2486. if (!new_ptr)
  2487. return BAD_SRB;
  2488. asc_dvc->ptr_map = new_ptr;
  2489. out:
  2490. ASC_DBG(3, "Putting ptr %p into array offset %d\n", ptr, i);
  2491. asc_dvc->ptr_map[i] = ptr;
  2492. return i + 1;
  2493. }
  2494. static void * advansys_srb_to_ptr(struct asc_dvc_var *asc_dvc, u32 srb)
  2495. {
  2496. void *ptr;
  2497. srb--;
  2498. if (srb >= asc_dvc->ptr_map_count) {
  2499. printk("advansys: bad SRB %u, max %u\n", srb,
  2500. asc_dvc->ptr_map_count);
  2501. return NULL;
  2502. }
  2503. ptr = asc_dvc->ptr_map[srb];
  2504. asc_dvc->ptr_map[srb] = NULL;
  2505. ASC_DBG(3, "Returning ptr %p from array offset %d\n", ptr, srb);
  2506. return ptr;
  2507. }
  2508. /*
  2509. * advansys_info()
  2510. *
  2511. * Return suitable for printing on the console with the argument
  2512. * adapter's configuration information.
  2513. *
  2514. * Note: The information line should not exceed ASC_INFO_SIZE bytes,
  2515. * otherwise the static 'info' array will be overrun.
  2516. */
  2517. static const char *advansys_info(struct Scsi_Host *shost)
  2518. {
  2519. static char info[ASC_INFO_SIZE];
  2520. struct asc_board *boardp = shost_priv(shost);
  2521. ASC_DVC_VAR *asc_dvc_varp;
  2522. ADV_DVC_VAR *adv_dvc_varp;
  2523. char *busname;
  2524. char *widename = NULL;
  2525. if (ASC_NARROW_BOARD(boardp)) {
  2526. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  2527. ASC_DBG(1, "begin\n");
  2528. if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
  2529. if ((asc_dvc_varp->bus_type & ASC_IS_ISAPNP) ==
  2530. ASC_IS_ISAPNP) {
  2531. busname = "ISA PnP";
  2532. } else {
  2533. busname = "ISA";
  2534. }
  2535. sprintf(info,
  2536. "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X, DMA 0x%X",
  2537. ASC_VERSION, busname,
  2538. (ulong)shost->io_port,
  2539. (ulong)shost->io_port + ASC_IOADR_GAP - 1,
  2540. boardp->irq, shost->dma_channel);
  2541. } else {
  2542. if (asc_dvc_varp->bus_type & ASC_IS_VL) {
  2543. busname = "VL";
  2544. } else if (asc_dvc_varp->bus_type & ASC_IS_EISA) {
  2545. busname = "EISA";
  2546. } else if (asc_dvc_varp->bus_type & ASC_IS_PCI) {
  2547. if ((asc_dvc_varp->bus_type & ASC_IS_PCI_ULTRA)
  2548. == ASC_IS_PCI_ULTRA) {
  2549. busname = "PCI Ultra";
  2550. } else {
  2551. busname = "PCI";
  2552. }
  2553. } else {
  2554. busname = "?";
  2555. shost_printk(KERN_ERR, shost, "unknown bus "
  2556. "type %d\n", asc_dvc_varp->bus_type);
  2557. }
  2558. sprintf(info,
  2559. "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X",
  2560. ASC_VERSION, busname, (ulong)shost->io_port,
  2561. (ulong)shost->io_port + ASC_IOADR_GAP - 1,
  2562. boardp->irq);
  2563. }
  2564. } else {
  2565. /*
  2566. * Wide Adapter Information
  2567. *
  2568. * Memory-mapped I/O is used instead of I/O space to access
  2569. * the adapter, but display the I/O Port range. The Memory
  2570. * I/O address is displayed through the driver /proc file.
  2571. */
  2572. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  2573. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2574. widename = "Ultra-Wide";
  2575. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2576. widename = "Ultra2-Wide";
  2577. } else {
  2578. widename = "Ultra3-Wide";
  2579. }
  2580. sprintf(info,
  2581. "AdvanSys SCSI %s: PCI %s: PCIMEM 0x%lX-0x%lX, IRQ 0x%X",
  2582. ASC_VERSION, widename, (ulong)adv_dvc_varp->iop_base,
  2583. (ulong)adv_dvc_varp->iop_base + boardp->asc_n_io_port - 1, boardp->irq);
  2584. }
  2585. BUG_ON(strlen(info) >= ASC_INFO_SIZE);
  2586. ASC_DBG(1, "end\n");
  2587. return info;
  2588. }
  2589. #ifdef CONFIG_PROC_FS
  2590. /*
  2591. * asc_prt_board_devices()
  2592. *
  2593. * Print driver information for devices attached to the board.
  2594. */
  2595. static void asc_prt_board_devices(struct seq_file *m, struct Scsi_Host *shost)
  2596. {
  2597. struct asc_board *boardp = shost_priv(shost);
  2598. int chip_scsi_id;
  2599. int i;
  2600. seq_printf(m,
  2601. "\nDevice Information for AdvanSys SCSI Host %d:\n",
  2602. shost->host_no);
  2603. if (ASC_NARROW_BOARD(boardp)) {
  2604. chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
  2605. } else {
  2606. chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
  2607. }
  2608. seq_printf(m, "Target IDs Detected:");
  2609. for (i = 0; i <= ADV_MAX_TID; i++) {
  2610. if (boardp->init_tidmask & ADV_TID_TO_TIDMASK(i))
  2611. seq_printf(m, " %X,", i);
  2612. }
  2613. seq_printf(m, " (%X=Host Adapter)\n", chip_scsi_id);
  2614. }
  2615. /*
  2616. * Display Wide Board BIOS Information.
  2617. */
  2618. static void asc_prt_adv_bios(struct seq_file *m, struct Scsi_Host *shost)
  2619. {
  2620. struct asc_board *boardp = shost_priv(shost);
  2621. ushort major, minor, letter;
  2622. seq_printf(m, "\nROM BIOS Version: ");
  2623. /*
  2624. * If the BIOS saved a valid signature, then fill in
  2625. * the BIOS code segment base address.
  2626. */
  2627. if (boardp->bios_signature != 0x55AA) {
  2628. seq_printf(m, "Disabled or Pre-3.1\n");
  2629. seq_printf(m,
  2630. "BIOS either disabled or Pre-3.1. If it is pre-3.1, then a newer version\n");
  2631. seq_printf(m,
  2632. "can be found at the ConnectCom FTP site: ftp://ftp.connectcom.net/pub\n");
  2633. } else {
  2634. major = (boardp->bios_version >> 12) & 0xF;
  2635. minor = (boardp->bios_version >> 8) & 0xF;
  2636. letter = (boardp->bios_version & 0xFF);
  2637. seq_printf(m, "%d.%d%c\n",
  2638. major, minor,
  2639. letter >= 26 ? '?' : letter + 'A');
  2640. /*
  2641. * Current available ROM BIOS release is 3.1I for UW
  2642. * and 3.2I for U2W. This code doesn't differentiate
  2643. * UW and U2W boards.
  2644. */
  2645. if (major < 3 || (major <= 3 && minor < 1) ||
  2646. (major <= 3 && minor <= 1 && letter < ('I' - 'A'))) {
  2647. seq_printf(m,
  2648. "Newer version of ROM BIOS is available at the ConnectCom FTP site:\n");
  2649. seq_printf(m,
  2650. "ftp://ftp.connectcom.net/pub\n");
  2651. }
  2652. }
  2653. }
  2654. /*
  2655. * Add serial number to information bar if signature AAh
  2656. * is found in at bit 15-9 (7 bits) of word 1.
  2657. *
  2658. * Serial Number consists fo 12 alpha-numeric digits.
  2659. *
  2660. * 1 - Product type (A,B,C,D..) Word0: 15-13 (3 bits)
  2661. * 2 - MFG Location (A,B,C,D..) Word0: 12-10 (3 bits)
  2662. * 3-4 - Product ID (0-99) Word0: 9-0 (10 bits)
  2663. * 5 - Product revision (A-J) Word0: " "
  2664. *
  2665. * Signature Word1: 15-9 (7 bits)
  2666. * 6 - Year (0-9) Word1: 8-6 (3 bits) & Word2: 15 (1 bit)
  2667. * 7-8 - Week of the year (1-52) Word1: 5-0 (6 bits)
  2668. *
  2669. * 9-12 - Serial Number (A001-Z999) Word2: 14-0 (15 bits)
  2670. *
  2671. * Note 1: Only production cards will have a serial number.
  2672. *
  2673. * Note 2: Signature is most significant 7 bits (0xFE).
  2674. *
  2675. * Returns ASC_TRUE if serial number found, otherwise returns ASC_FALSE.
  2676. */
  2677. static int asc_get_eeprom_string(ushort *serialnum, uchar *cp)
  2678. {
  2679. ushort w, num;
  2680. if ((serialnum[1] & 0xFE00) != ((ushort)0xAA << 8)) {
  2681. return ASC_FALSE;
  2682. } else {
  2683. /*
  2684. * First word - 6 digits.
  2685. */
  2686. w = serialnum[0];
  2687. /* Product type - 1st digit. */
  2688. if ((*cp = 'A' + ((w & 0xE000) >> 13)) == 'H') {
  2689. /* Product type is P=Prototype */
  2690. *cp += 0x8;
  2691. }
  2692. cp++;
  2693. /* Manufacturing location - 2nd digit. */
  2694. *cp++ = 'A' + ((w & 0x1C00) >> 10);
  2695. /* Product ID - 3rd, 4th digits. */
  2696. num = w & 0x3FF;
  2697. *cp++ = '0' + (num / 100);
  2698. num %= 100;
  2699. *cp++ = '0' + (num / 10);
  2700. /* Product revision - 5th digit. */
  2701. *cp++ = 'A' + (num % 10);
  2702. /*
  2703. * Second word
  2704. */
  2705. w = serialnum[1];
  2706. /*
  2707. * Year - 6th digit.
  2708. *
  2709. * If bit 15 of third word is set, then the
  2710. * last digit of the year is greater than 7.
  2711. */
  2712. if (serialnum[2] & 0x8000) {
  2713. *cp++ = '8' + ((w & 0x1C0) >> 6);
  2714. } else {
  2715. *cp++ = '0' + ((w & 0x1C0) >> 6);
  2716. }
  2717. /* Week of year - 7th, 8th digits. */
  2718. num = w & 0x003F;
  2719. *cp++ = '0' + num / 10;
  2720. num %= 10;
  2721. *cp++ = '0' + num;
  2722. /*
  2723. * Third word
  2724. */
  2725. w = serialnum[2] & 0x7FFF;
  2726. /* Serial number - 9th digit. */
  2727. *cp++ = 'A' + (w / 1000);
  2728. /* 10th, 11th, 12th digits. */
  2729. num = w % 1000;
  2730. *cp++ = '0' + num / 100;
  2731. num %= 100;
  2732. *cp++ = '0' + num / 10;
  2733. num %= 10;
  2734. *cp++ = '0' + num;
  2735. *cp = '\0'; /* Null Terminate the string. */
  2736. return ASC_TRUE;
  2737. }
  2738. }
  2739. /*
  2740. * asc_prt_asc_board_eeprom()
  2741. *
  2742. * Print board EEPROM configuration.
  2743. */
  2744. static void asc_prt_asc_board_eeprom(struct seq_file *m, struct Scsi_Host *shost)
  2745. {
  2746. struct asc_board *boardp = shost_priv(shost);
  2747. ASC_DVC_VAR *asc_dvc_varp;
  2748. ASCEEP_CONFIG *ep;
  2749. int i;
  2750. #ifdef CONFIG_ISA
  2751. int isa_dma_speed[] = { 10, 8, 7, 6, 5, 4, 3, 2 };
  2752. #endif /* CONFIG_ISA */
  2753. uchar serialstr[13];
  2754. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  2755. ep = &boardp->eep_config.asc_eep;
  2756. seq_printf(m,
  2757. "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
  2758. shost->host_no);
  2759. if (asc_get_eeprom_string((ushort *)&ep->adapter_info[0], serialstr)
  2760. == ASC_TRUE)
  2761. seq_printf(m, " Serial Number: %s\n", serialstr);
  2762. else if (ep->adapter_info[5] == 0xBB)
  2763. seq_printf(m,
  2764. " Default Settings Used for EEPROM-less Adapter.\n");
  2765. else
  2766. seq_printf(m,
  2767. " Serial Number Signature Not Present.\n");
  2768. seq_printf(m,
  2769. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2770. ASC_EEP_GET_CHIP_ID(ep), ep->max_total_qng,
  2771. ep->max_tag_qng);
  2772. seq_printf(m,
  2773. " cntl 0x%x, no_scam 0x%x\n", ep->cntl, ep->no_scam);
  2774. seq_printf(m, " Target ID: ");
  2775. for (i = 0; i <= ASC_MAX_TID; i++)
  2776. seq_printf(m, " %d", i);
  2777. seq_printf(m, "\n");
  2778. seq_printf(m, " Disconnects: ");
  2779. for (i = 0; i <= ASC_MAX_TID; i++)
  2780. seq_printf(m, " %c",
  2781. (ep->disc_enable & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2782. seq_printf(m, "\n");
  2783. seq_printf(m, " Command Queuing: ");
  2784. for (i = 0; i <= ASC_MAX_TID; i++)
  2785. seq_printf(m, " %c",
  2786. (ep->use_cmd_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2787. seq_printf(m, "\n");
  2788. seq_printf(m, " Start Motor: ");
  2789. for (i = 0; i <= ASC_MAX_TID; i++)
  2790. seq_printf(m, " %c",
  2791. (ep->start_motor & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2792. seq_printf(m, "\n");
  2793. seq_printf(m, " Synchronous Transfer:");
  2794. for (i = 0; i <= ASC_MAX_TID; i++)
  2795. seq_printf(m, " %c",
  2796. (ep->init_sdtr & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2797. seq_printf(m, "\n");
  2798. #ifdef CONFIG_ISA
  2799. if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
  2800. seq_printf(m,
  2801. " Host ISA DMA speed: %d MB/S\n",
  2802. isa_dma_speed[ASC_EEP_GET_DMA_SPD(ep)]);
  2803. }
  2804. #endif /* CONFIG_ISA */
  2805. }
  2806. /*
  2807. * asc_prt_adv_board_eeprom()
  2808. *
  2809. * Print board EEPROM configuration.
  2810. */
  2811. static void asc_prt_adv_board_eeprom(struct seq_file *m, struct Scsi_Host *shost)
  2812. {
  2813. struct asc_board *boardp = shost_priv(shost);
  2814. ADV_DVC_VAR *adv_dvc_varp;
  2815. int i;
  2816. char *termstr;
  2817. uchar serialstr[13];
  2818. ADVEEP_3550_CONFIG *ep_3550 = NULL;
  2819. ADVEEP_38C0800_CONFIG *ep_38C0800 = NULL;
  2820. ADVEEP_38C1600_CONFIG *ep_38C1600 = NULL;
  2821. ushort word;
  2822. ushort *wordp;
  2823. ushort sdtr_speed = 0;
  2824. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  2825. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2826. ep_3550 = &boardp->eep_config.adv_3550_eep;
  2827. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2828. ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
  2829. } else {
  2830. ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
  2831. }
  2832. seq_printf(m,
  2833. "\nEEPROM Settings for AdvanSys SCSI Host %d:\n",
  2834. shost->host_no);
  2835. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2836. wordp = &ep_3550->serial_number_word1;
  2837. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2838. wordp = &ep_38C0800->serial_number_word1;
  2839. } else {
  2840. wordp = &ep_38C1600->serial_number_word1;
  2841. }
  2842. if (asc_get_eeprom_string(wordp, serialstr) == ASC_TRUE)
  2843. seq_printf(m, " Serial Number: %s\n", serialstr);
  2844. else
  2845. seq_printf(m, " Serial Number Signature Not Present.\n");
  2846. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
  2847. seq_printf(m,
  2848. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2849. ep_3550->adapter_scsi_id,
  2850. ep_3550->max_host_qng, ep_3550->max_dvc_qng);
  2851. else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
  2852. seq_printf(m,
  2853. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2854. ep_38C0800->adapter_scsi_id,
  2855. ep_38C0800->max_host_qng,
  2856. ep_38C0800->max_dvc_qng);
  2857. else
  2858. seq_printf(m,
  2859. " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
  2860. ep_38C1600->adapter_scsi_id,
  2861. ep_38C1600->max_host_qng,
  2862. ep_38C1600->max_dvc_qng);
  2863. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2864. word = ep_3550->termination;
  2865. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2866. word = ep_38C0800->termination_lvd;
  2867. } else {
  2868. word = ep_38C1600->termination_lvd;
  2869. }
  2870. switch (word) {
  2871. case 1:
  2872. termstr = "Low Off/High Off";
  2873. break;
  2874. case 2:
  2875. termstr = "Low Off/High On";
  2876. break;
  2877. case 3:
  2878. termstr = "Low On/High On";
  2879. break;
  2880. default:
  2881. case 0:
  2882. termstr = "Automatic";
  2883. break;
  2884. }
  2885. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
  2886. seq_printf(m,
  2887. " termination: %u (%s), bios_ctrl: 0x%x\n",
  2888. ep_3550->termination, termstr,
  2889. ep_3550->bios_ctrl);
  2890. else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
  2891. seq_printf(m,
  2892. " termination: %u (%s), bios_ctrl: 0x%x\n",
  2893. ep_38C0800->termination_lvd, termstr,
  2894. ep_38C0800->bios_ctrl);
  2895. else
  2896. seq_printf(m,
  2897. " termination: %u (%s), bios_ctrl: 0x%x\n",
  2898. ep_38C1600->termination_lvd, termstr,
  2899. ep_38C1600->bios_ctrl);
  2900. seq_printf(m, " Target ID: ");
  2901. for (i = 0; i <= ADV_MAX_TID; i++)
  2902. seq_printf(m, " %X", i);
  2903. seq_printf(m, "\n");
  2904. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2905. word = ep_3550->disc_enable;
  2906. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2907. word = ep_38C0800->disc_enable;
  2908. } else {
  2909. word = ep_38C1600->disc_enable;
  2910. }
  2911. seq_printf(m, " Disconnects: ");
  2912. for (i = 0; i <= ADV_MAX_TID; i++)
  2913. seq_printf(m, " %c",
  2914. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2915. seq_printf(m, "\n");
  2916. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2917. word = ep_3550->tagqng_able;
  2918. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2919. word = ep_38C0800->tagqng_able;
  2920. } else {
  2921. word = ep_38C1600->tagqng_able;
  2922. }
  2923. seq_printf(m, " Command Queuing: ");
  2924. for (i = 0; i <= ADV_MAX_TID; i++)
  2925. seq_printf(m, " %c",
  2926. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2927. seq_printf(m, "\n");
  2928. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2929. word = ep_3550->start_motor;
  2930. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2931. word = ep_38C0800->start_motor;
  2932. } else {
  2933. word = ep_38C1600->start_motor;
  2934. }
  2935. seq_printf(m, " Start Motor: ");
  2936. for (i = 0; i <= ADV_MAX_TID; i++)
  2937. seq_printf(m, " %c",
  2938. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2939. seq_printf(m, "\n");
  2940. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2941. seq_printf(m, " Synchronous Transfer:");
  2942. for (i = 0; i <= ADV_MAX_TID; i++)
  2943. seq_printf(m, " %c",
  2944. (ep_3550->sdtr_able & ADV_TID_TO_TIDMASK(i)) ?
  2945. 'Y' : 'N');
  2946. seq_printf(m, "\n");
  2947. }
  2948. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2949. seq_printf(m, " Ultra Transfer: ");
  2950. for (i = 0; i <= ADV_MAX_TID; i++)
  2951. seq_printf(m, " %c",
  2952. (ep_3550->ultra_able & ADV_TID_TO_TIDMASK(i))
  2953. ? 'Y' : 'N');
  2954. seq_printf(m, "\n");
  2955. }
  2956. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  2957. word = ep_3550->wdtr_able;
  2958. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  2959. word = ep_38C0800->wdtr_able;
  2960. } else {
  2961. word = ep_38C1600->wdtr_able;
  2962. }
  2963. seq_printf(m, " Wide Transfer: ");
  2964. for (i = 0; i <= ADV_MAX_TID; i++)
  2965. seq_printf(m, " %c",
  2966. (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  2967. seq_printf(m, "\n");
  2968. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800 ||
  2969. adv_dvc_varp->chip_type == ADV_CHIP_ASC38C1600) {
  2970. seq_printf(m,
  2971. " Synchronous Transfer Speed (Mhz):\n ");
  2972. for (i = 0; i <= ADV_MAX_TID; i++) {
  2973. char *speed_str;
  2974. if (i == 0) {
  2975. sdtr_speed = adv_dvc_varp->sdtr_speed1;
  2976. } else if (i == 4) {
  2977. sdtr_speed = adv_dvc_varp->sdtr_speed2;
  2978. } else if (i == 8) {
  2979. sdtr_speed = adv_dvc_varp->sdtr_speed3;
  2980. } else if (i == 12) {
  2981. sdtr_speed = adv_dvc_varp->sdtr_speed4;
  2982. }
  2983. switch (sdtr_speed & ADV_MAX_TID) {
  2984. case 0:
  2985. speed_str = "Off";
  2986. break;
  2987. case 1:
  2988. speed_str = " 5";
  2989. break;
  2990. case 2:
  2991. speed_str = " 10";
  2992. break;
  2993. case 3:
  2994. speed_str = " 20";
  2995. break;
  2996. case 4:
  2997. speed_str = " 40";
  2998. break;
  2999. case 5:
  3000. speed_str = " 80";
  3001. break;
  3002. default:
  3003. speed_str = "Unk";
  3004. break;
  3005. }
  3006. seq_printf(m, "%X:%s ", i, speed_str);
  3007. if (i == 7)
  3008. seq_printf(m, "\n ");
  3009. sdtr_speed >>= 4;
  3010. }
  3011. seq_printf(m, "\n");
  3012. }
  3013. }
  3014. /*
  3015. * asc_prt_driver_conf()
  3016. */
  3017. static void asc_prt_driver_conf(struct seq_file *m, struct Scsi_Host *shost)
  3018. {
  3019. struct asc_board *boardp = shost_priv(shost);
  3020. int chip_scsi_id;
  3021. seq_printf(m,
  3022. "\nLinux Driver Configuration and Information for AdvanSys SCSI Host %d:\n",
  3023. shost->host_no);
  3024. seq_printf(m,
  3025. " host_busy %u, max_id %u, max_lun %u, max_channel %u\n",
  3026. shost->host_busy, shost->max_id,
  3027. shost->max_lun, shost->max_channel);
  3028. seq_printf(m,
  3029. " unique_id %d, can_queue %d, this_id %d, sg_tablesize %u, cmd_per_lun %u\n",
  3030. shost->unique_id, shost->can_queue, shost->this_id,
  3031. shost->sg_tablesize, shost->cmd_per_lun);
  3032. seq_printf(m,
  3033. " unchecked_isa_dma %d, use_clustering %d\n",
  3034. shost->unchecked_isa_dma, shost->use_clustering);
  3035. seq_printf(m,
  3036. " flags 0x%x, last_reset 0x%lx, jiffies 0x%lx, asc_n_io_port 0x%x\n",
  3037. boardp->flags, boardp->last_reset, jiffies,
  3038. boardp->asc_n_io_port);
  3039. seq_printf(m, " io_port 0x%lx\n", shost->io_port);
  3040. if (ASC_NARROW_BOARD(boardp)) {
  3041. chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
  3042. } else {
  3043. chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
  3044. }
  3045. }
  3046. /*
  3047. * asc_prt_asc_board_info()
  3048. *
  3049. * Print dynamic board configuration information.
  3050. */
  3051. static void asc_prt_asc_board_info(struct seq_file *m, struct Scsi_Host *shost)
  3052. {
  3053. struct asc_board *boardp = shost_priv(shost);
  3054. int chip_scsi_id;
  3055. ASC_DVC_VAR *v;
  3056. ASC_DVC_CFG *c;
  3057. int i;
  3058. int renegotiate = 0;
  3059. v = &boardp->dvc_var.asc_dvc_var;
  3060. c = &boardp->dvc_cfg.asc_dvc_cfg;
  3061. chip_scsi_id = c->chip_scsi_id;
  3062. seq_printf(m,
  3063. "\nAsc Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
  3064. shost->host_no);
  3065. seq_printf(m, " chip_version %u, mcode_date 0x%x, "
  3066. "mcode_version 0x%x, err_code %u\n",
  3067. c->chip_version, c->mcode_date, c->mcode_version,
  3068. v->err_code);
  3069. /* Current number of commands waiting for the host. */
  3070. seq_printf(m,
  3071. " Total Command Pending: %d\n", v->cur_total_qng);
  3072. seq_printf(m, " Command Queuing:");
  3073. for (i = 0; i <= ASC_MAX_TID; i++) {
  3074. if ((chip_scsi_id == i) ||
  3075. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3076. continue;
  3077. }
  3078. seq_printf(m, " %X:%c",
  3079. i,
  3080. (v->use_tagged_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3081. }
  3082. seq_printf(m, "\n");
  3083. /* Current number of commands waiting for a device. */
  3084. seq_printf(m, " Command Queue Pending:");
  3085. for (i = 0; i <= ASC_MAX_TID; i++) {
  3086. if ((chip_scsi_id == i) ||
  3087. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3088. continue;
  3089. }
  3090. seq_printf(m, " %X:%u", i, v->cur_dvc_qng[i]);
  3091. }
  3092. seq_printf(m, "\n");
  3093. /* Current limit on number of commands that can be sent to a device. */
  3094. seq_printf(m, " Command Queue Limit:");
  3095. for (i = 0; i <= ASC_MAX_TID; i++) {
  3096. if ((chip_scsi_id == i) ||
  3097. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3098. continue;
  3099. }
  3100. seq_printf(m, " %X:%u", i, v->max_dvc_qng[i]);
  3101. }
  3102. seq_printf(m, "\n");
  3103. /* Indicate whether the device has returned queue full status. */
  3104. seq_printf(m, " Command Queue Full:");
  3105. for (i = 0; i <= ASC_MAX_TID; i++) {
  3106. if ((chip_scsi_id == i) ||
  3107. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3108. continue;
  3109. }
  3110. if (boardp->queue_full & ADV_TID_TO_TIDMASK(i))
  3111. seq_printf(m, " %X:Y-%d",
  3112. i, boardp->queue_full_cnt[i]);
  3113. else
  3114. seq_printf(m, " %X:N", i);
  3115. }
  3116. seq_printf(m, "\n");
  3117. seq_printf(m, " Synchronous Transfer:");
  3118. for (i = 0; i <= ASC_MAX_TID; i++) {
  3119. if ((chip_scsi_id == i) ||
  3120. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3121. continue;
  3122. }
  3123. seq_printf(m, " %X:%c",
  3124. i,
  3125. (v->sdtr_done & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3126. }
  3127. seq_printf(m, "\n");
  3128. for (i = 0; i <= ASC_MAX_TID; i++) {
  3129. uchar syn_period_ix;
  3130. if ((chip_scsi_id == i) ||
  3131. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
  3132. ((v->init_sdtr & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3133. continue;
  3134. }
  3135. seq_printf(m, " %X:", i);
  3136. if ((boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET) == 0) {
  3137. seq_printf(m, " Asynchronous");
  3138. } else {
  3139. syn_period_ix =
  3140. (boardp->sdtr_data[i] >> 4) & (v->max_sdtr_index -
  3141. 1);
  3142. seq_printf(m,
  3143. " Transfer Period Factor: %d (%d.%d Mhz),",
  3144. v->sdtr_period_tbl[syn_period_ix],
  3145. 250 / v->sdtr_period_tbl[syn_period_ix],
  3146. ASC_TENTHS(250,
  3147. v->sdtr_period_tbl[syn_period_ix]));
  3148. seq_printf(m, " REQ/ACK Offset: %d",
  3149. boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET);
  3150. }
  3151. if ((v->sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  3152. seq_printf(m, "*\n");
  3153. renegotiate = 1;
  3154. } else {
  3155. seq_printf(m, "\n");
  3156. }
  3157. }
  3158. if (renegotiate) {
  3159. seq_printf(m,
  3160. " * = Re-negotiation pending before next command.\n");
  3161. }
  3162. }
  3163. /*
  3164. * asc_prt_adv_board_info()
  3165. *
  3166. * Print dynamic board configuration information.
  3167. */
  3168. static void asc_prt_adv_board_info(struct seq_file *m, struct Scsi_Host *shost)
  3169. {
  3170. struct asc_board *boardp = shost_priv(shost);
  3171. int i;
  3172. ADV_DVC_VAR *v;
  3173. ADV_DVC_CFG *c;
  3174. AdvPortAddr iop_base;
  3175. ushort chip_scsi_id;
  3176. ushort lramword;
  3177. uchar lrambyte;
  3178. ushort tagqng_able;
  3179. ushort sdtr_able, wdtr_able;
  3180. ushort wdtr_done, sdtr_done;
  3181. ushort period = 0;
  3182. int renegotiate = 0;
  3183. v = &boardp->dvc_var.adv_dvc_var;
  3184. c = &boardp->dvc_cfg.adv_dvc_cfg;
  3185. iop_base = v->iop_base;
  3186. chip_scsi_id = v->chip_scsi_id;
  3187. seq_printf(m,
  3188. "\nAdv Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
  3189. shost->host_no);
  3190. seq_printf(m,
  3191. " iop_base 0x%lx, cable_detect: %X, err_code %u\n",
  3192. (unsigned long)v->iop_base,
  3193. AdvReadWordRegister(iop_base,IOPW_SCSI_CFG1) & CABLE_DETECT,
  3194. v->err_code);
  3195. seq_printf(m, " chip_version %u, mcode_date 0x%x, "
  3196. "mcode_version 0x%x\n", c->chip_version,
  3197. c->mcode_date, c->mcode_version);
  3198. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  3199. seq_printf(m, " Queuing Enabled:");
  3200. for (i = 0; i <= ADV_MAX_TID; i++) {
  3201. if ((chip_scsi_id == i) ||
  3202. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3203. continue;
  3204. }
  3205. seq_printf(m, " %X:%c",
  3206. i,
  3207. (tagqng_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3208. }
  3209. seq_printf(m, "\n");
  3210. seq_printf(m, " Queue Limit:");
  3211. for (i = 0; i <= ADV_MAX_TID; i++) {
  3212. if ((chip_scsi_id == i) ||
  3213. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3214. continue;
  3215. }
  3216. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + i,
  3217. lrambyte);
  3218. seq_printf(m, " %X:%d", i, lrambyte);
  3219. }
  3220. seq_printf(m, "\n");
  3221. seq_printf(m, " Command Pending:");
  3222. for (i = 0; i <= ADV_MAX_TID; i++) {
  3223. if ((chip_scsi_id == i) ||
  3224. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3225. continue;
  3226. }
  3227. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_QUEUED_CMD + i,
  3228. lrambyte);
  3229. seq_printf(m, " %X:%d", i, lrambyte);
  3230. }
  3231. seq_printf(m, "\n");
  3232. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  3233. seq_printf(m, " Wide Enabled:");
  3234. for (i = 0; i <= ADV_MAX_TID; i++) {
  3235. if ((chip_scsi_id == i) ||
  3236. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3237. continue;
  3238. }
  3239. seq_printf(m, " %X:%c",
  3240. i,
  3241. (wdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3242. }
  3243. seq_printf(m, "\n");
  3244. AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, wdtr_done);
  3245. seq_printf(m, " Transfer Bit Width:");
  3246. for (i = 0; i <= ADV_MAX_TID; i++) {
  3247. if ((chip_scsi_id == i) ||
  3248. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3249. continue;
  3250. }
  3251. AdvReadWordLram(iop_base,
  3252. ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
  3253. lramword);
  3254. seq_printf(m, " %X:%d",
  3255. i, (lramword & 0x8000) ? 16 : 8);
  3256. if ((wdtr_able & ADV_TID_TO_TIDMASK(i)) &&
  3257. (wdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  3258. seq_printf(m, "*");
  3259. renegotiate = 1;
  3260. }
  3261. }
  3262. seq_printf(m, "\n");
  3263. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  3264. seq_printf(m, " Synchronous Enabled:");
  3265. for (i = 0; i <= ADV_MAX_TID; i++) {
  3266. if ((chip_scsi_id == i) ||
  3267. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3268. continue;
  3269. }
  3270. seq_printf(m, " %X:%c",
  3271. i,
  3272. (sdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
  3273. }
  3274. seq_printf(m, "\n");
  3275. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, sdtr_done);
  3276. for (i = 0; i <= ADV_MAX_TID; i++) {
  3277. AdvReadWordLram(iop_base,
  3278. ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
  3279. lramword);
  3280. lramword &= ~0x8000;
  3281. if ((chip_scsi_id == i) ||
  3282. ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
  3283. ((sdtr_able & ADV_TID_TO_TIDMASK(i)) == 0)) {
  3284. continue;
  3285. }
  3286. seq_printf(m, " %X:", i);
  3287. if ((lramword & 0x1F) == 0) { /* Check for REQ/ACK Offset 0. */
  3288. seq_printf(m, " Asynchronous");
  3289. } else {
  3290. seq_printf(m, " Transfer Period Factor: ");
  3291. if ((lramword & 0x1F00) == 0x1100) { /* 80 Mhz */
  3292. seq_printf(m, "9 (80.0 Mhz),");
  3293. } else if ((lramword & 0x1F00) == 0x1000) { /* 40 Mhz */
  3294. seq_printf(m, "10 (40.0 Mhz),");
  3295. } else { /* 20 Mhz or below. */
  3296. period = (((lramword >> 8) * 25) + 50) / 4;
  3297. if (period == 0) { /* Should never happen. */
  3298. seq_printf(m, "%d (? Mhz), ", period);
  3299. } else {
  3300. seq_printf(m,
  3301. "%d (%d.%d Mhz),",
  3302. period, 250 / period,
  3303. ASC_TENTHS(250, period));
  3304. }
  3305. }
  3306. seq_printf(m, " REQ/ACK Offset: %d",
  3307. lramword & 0x1F);
  3308. }
  3309. if ((sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
  3310. seq_printf(m, "*\n");
  3311. renegotiate = 1;
  3312. } else {
  3313. seq_printf(m, "\n");
  3314. }
  3315. }
  3316. if (renegotiate) {
  3317. seq_printf(m,
  3318. " * = Re-negotiation pending before next command.\n");
  3319. }
  3320. }
  3321. #ifdef ADVANSYS_STATS
  3322. /*
  3323. * asc_prt_board_stats()
  3324. */
  3325. static void asc_prt_board_stats(struct seq_file *m, struct Scsi_Host *shost)
  3326. {
  3327. struct asc_board *boardp = shost_priv(shost);
  3328. struct asc_stats *s = &boardp->asc_stats;
  3329. seq_printf(m,
  3330. "\nLinux Driver Statistics for AdvanSys SCSI Host %d:\n",
  3331. shost->host_no);
  3332. seq_printf(m,
  3333. " queuecommand %u, reset %u, biosparam %u, interrupt %u\n",
  3334. s->queuecommand, s->reset, s->biosparam,
  3335. s->interrupt);
  3336. seq_printf(m,
  3337. " callback %u, done %u, build_error %u, build_noreq %u, build_nosg %u\n",
  3338. s->callback, s->done, s->build_error,
  3339. s->adv_build_noreq, s->adv_build_nosg);
  3340. seq_printf(m,
  3341. " exe_noerror %u, exe_busy %u, exe_error %u, exe_unknown %u\n",
  3342. s->exe_noerror, s->exe_busy, s->exe_error,
  3343. s->exe_unknown);
  3344. /*
  3345. * Display data transfer statistics.
  3346. */
  3347. if (s->xfer_cnt > 0) {
  3348. seq_printf(m, " xfer_cnt %u, xfer_elem %u, ",
  3349. s->xfer_cnt, s->xfer_elem);
  3350. seq_printf(m, "xfer_bytes %u.%01u kb\n",
  3351. s->xfer_sect / 2, ASC_TENTHS(s->xfer_sect, 2));
  3352. /* Scatter gather transfer statistics */
  3353. seq_printf(m, " avg_num_elem %u.%01u, ",
  3354. s->xfer_elem / s->xfer_cnt,
  3355. ASC_TENTHS(s->xfer_elem, s->xfer_cnt));
  3356. seq_printf(m, "avg_elem_size %u.%01u kb, ",
  3357. (s->xfer_sect / 2) / s->xfer_elem,
  3358. ASC_TENTHS((s->xfer_sect / 2), s->xfer_elem));
  3359. seq_printf(m, "avg_xfer_size %u.%01u kb\n",
  3360. (s->xfer_sect / 2) / s->xfer_cnt,
  3361. ASC_TENTHS((s->xfer_sect / 2), s->xfer_cnt));
  3362. }
  3363. }
  3364. #endif /* ADVANSYS_STATS */
  3365. /*
  3366. * advansys_show_info() - /proc/scsi/advansys/{0,1,2,3,...}
  3367. *
  3368. * m: seq_file to print into
  3369. * shost: Scsi_Host
  3370. *
  3371. * Return the number of bytes read from or written to a
  3372. * /proc/scsi/advansys/[0...] file.
  3373. */
  3374. static int
  3375. advansys_show_info(struct seq_file *m, struct Scsi_Host *shost)
  3376. {
  3377. struct asc_board *boardp = shost_priv(shost);
  3378. ASC_DBG(1, "begin\n");
  3379. /*
  3380. * User read of /proc/scsi/advansys/[0...] file.
  3381. */
  3382. /*
  3383. * Get board configuration information.
  3384. *
  3385. * advansys_info() returns the board string from its own static buffer.
  3386. */
  3387. /* Copy board information. */
  3388. seq_printf(m, "%s\n", (char *)advansys_info(shost));
  3389. /*
  3390. * Display Wide Board BIOS Information.
  3391. */
  3392. if (!ASC_NARROW_BOARD(boardp))
  3393. asc_prt_adv_bios(m, shost);
  3394. /*
  3395. * Display driver information for each device attached to the board.
  3396. */
  3397. asc_prt_board_devices(m, shost);
  3398. /*
  3399. * Display EEPROM configuration for the board.
  3400. */
  3401. if (ASC_NARROW_BOARD(boardp))
  3402. asc_prt_asc_board_eeprom(m, shost);
  3403. else
  3404. asc_prt_adv_board_eeprom(m, shost);
  3405. /*
  3406. * Display driver configuration and information for the board.
  3407. */
  3408. asc_prt_driver_conf(m, shost);
  3409. #ifdef ADVANSYS_STATS
  3410. /*
  3411. * Display driver statistics for the board.
  3412. */
  3413. asc_prt_board_stats(m, shost);
  3414. #endif /* ADVANSYS_STATS */
  3415. /*
  3416. * Display Asc Library dynamic configuration information
  3417. * for the board.
  3418. */
  3419. if (ASC_NARROW_BOARD(boardp))
  3420. asc_prt_asc_board_info(m, shost);
  3421. else
  3422. asc_prt_adv_board_info(m, shost);
  3423. return 0;
  3424. }
  3425. #endif /* CONFIG_PROC_FS */
  3426. static void asc_scsi_done(struct scsi_cmnd *scp)
  3427. {
  3428. scsi_dma_unmap(scp);
  3429. ASC_STATS(scp->device->host, done);
  3430. scp->scsi_done(scp);
  3431. }
  3432. static void AscSetBank(PortAddr iop_base, uchar bank)
  3433. {
  3434. uchar val;
  3435. val = AscGetChipControl(iop_base) &
  3436. (~
  3437. (CC_SINGLE_STEP | CC_TEST | CC_DIAG | CC_SCSI_RESET |
  3438. CC_CHIP_RESET));
  3439. if (bank == 1) {
  3440. val |= CC_BANK_ONE;
  3441. } else if (bank == 2) {
  3442. val |= CC_DIAG | CC_BANK_ONE;
  3443. } else {
  3444. val &= ~CC_BANK_ONE;
  3445. }
  3446. AscSetChipControl(iop_base, val);
  3447. }
  3448. static void AscSetChipIH(PortAddr iop_base, ushort ins_code)
  3449. {
  3450. AscSetBank(iop_base, 1);
  3451. AscWriteChipIH(iop_base, ins_code);
  3452. AscSetBank(iop_base, 0);
  3453. }
  3454. static int AscStartChip(PortAddr iop_base)
  3455. {
  3456. AscSetChipControl(iop_base, 0);
  3457. if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
  3458. return (0);
  3459. }
  3460. return (1);
  3461. }
  3462. static int AscStopChip(PortAddr iop_base)
  3463. {
  3464. uchar cc_val;
  3465. cc_val =
  3466. AscGetChipControl(iop_base) &
  3467. (~(CC_SINGLE_STEP | CC_TEST | CC_DIAG));
  3468. AscSetChipControl(iop_base, (uchar)(cc_val | CC_HALT));
  3469. AscSetChipIH(iop_base, INS_HALT);
  3470. AscSetChipIH(iop_base, INS_RFLAG_WTM);
  3471. if ((AscGetChipStatus(iop_base) & CSW_HALTED) == 0) {
  3472. return (0);
  3473. }
  3474. return (1);
  3475. }
  3476. static int AscIsChipHalted(PortAddr iop_base)
  3477. {
  3478. if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
  3479. if ((AscGetChipControl(iop_base) & CC_HALT) != 0) {
  3480. return (1);
  3481. }
  3482. }
  3483. return (0);
  3484. }
  3485. static int AscResetChipAndScsiBus(ASC_DVC_VAR *asc_dvc)
  3486. {
  3487. PortAddr iop_base;
  3488. int i = 10;
  3489. iop_base = asc_dvc->iop_base;
  3490. while ((AscGetChipStatus(iop_base) & CSW_SCSI_RESET_ACTIVE)
  3491. && (i-- > 0)) {
  3492. mdelay(100);
  3493. }
  3494. AscStopChip(iop_base);
  3495. AscSetChipControl(iop_base, CC_CHIP_RESET | CC_SCSI_RESET | CC_HALT);
  3496. udelay(60);
  3497. AscSetChipIH(iop_base, INS_RFLAG_WTM);
  3498. AscSetChipIH(iop_base, INS_HALT);
  3499. AscSetChipControl(iop_base, CC_CHIP_RESET | CC_HALT);
  3500. AscSetChipControl(iop_base, CC_HALT);
  3501. mdelay(200);
  3502. AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
  3503. AscSetChipStatus(iop_base, 0);
  3504. return (AscIsChipHalted(iop_base));
  3505. }
  3506. static int AscFindSignature(PortAddr iop_base)
  3507. {
  3508. ushort sig_word;
  3509. ASC_DBG(1, "AscGetChipSignatureByte(0x%x) 0x%x\n",
  3510. iop_base, AscGetChipSignatureByte(iop_base));
  3511. if (AscGetChipSignatureByte(iop_base) == (uchar)ASC_1000_ID1B) {
  3512. ASC_DBG(1, "AscGetChipSignatureWord(0x%x) 0x%x\n",
  3513. iop_base, AscGetChipSignatureWord(iop_base));
  3514. sig_word = AscGetChipSignatureWord(iop_base);
  3515. if ((sig_word == (ushort)ASC_1000_ID0W) ||
  3516. (sig_word == (ushort)ASC_1000_ID0W_FIX)) {
  3517. return (1);
  3518. }
  3519. }
  3520. return (0);
  3521. }
  3522. static void AscEnableInterrupt(PortAddr iop_base)
  3523. {
  3524. ushort cfg;
  3525. cfg = AscGetChipCfgLsw(iop_base);
  3526. AscSetChipCfgLsw(iop_base, cfg | ASC_CFG0_HOST_INT_ON);
  3527. }
  3528. static void AscDisableInterrupt(PortAddr iop_base)
  3529. {
  3530. ushort cfg;
  3531. cfg = AscGetChipCfgLsw(iop_base);
  3532. AscSetChipCfgLsw(iop_base, cfg & (~ASC_CFG0_HOST_INT_ON));
  3533. }
  3534. static uchar AscReadLramByte(PortAddr iop_base, ushort addr)
  3535. {
  3536. unsigned char byte_data;
  3537. unsigned short word_data;
  3538. if (isodd_word(addr)) {
  3539. AscSetChipLramAddr(iop_base, addr - 1);
  3540. word_data = AscGetChipLramData(iop_base);
  3541. byte_data = (word_data >> 8) & 0xFF;
  3542. } else {
  3543. AscSetChipLramAddr(iop_base, addr);
  3544. word_data = AscGetChipLramData(iop_base);
  3545. byte_data = word_data & 0xFF;
  3546. }
  3547. return byte_data;
  3548. }
  3549. static ushort AscReadLramWord(PortAddr iop_base, ushort addr)
  3550. {
  3551. ushort word_data;
  3552. AscSetChipLramAddr(iop_base, addr);
  3553. word_data = AscGetChipLramData(iop_base);
  3554. return (word_data);
  3555. }
  3556. #if CC_VERY_LONG_SG_LIST
  3557. static ASC_DCNT AscReadLramDWord(PortAddr iop_base, ushort addr)
  3558. {
  3559. ushort val_low, val_high;
  3560. ASC_DCNT dword_data;
  3561. AscSetChipLramAddr(iop_base, addr);
  3562. val_low = AscGetChipLramData(iop_base);
  3563. val_high = AscGetChipLramData(iop_base);
  3564. dword_data = ((ASC_DCNT) val_high << 16) | (ASC_DCNT) val_low;
  3565. return (dword_data);
  3566. }
  3567. #endif /* CC_VERY_LONG_SG_LIST */
  3568. static void
  3569. AscMemWordSetLram(PortAddr iop_base, ushort s_addr, ushort set_wval, int words)
  3570. {
  3571. int i;
  3572. AscSetChipLramAddr(iop_base, s_addr);
  3573. for (i = 0; i < words; i++) {
  3574. AscSetChipLramData(iop_base, set_wval);
  3575. }
  3576. }
  3577. static void AscWriteLramWord(PortAddr iop_base, ushort addr, ushort word_val)
  3578. {
  3579. AscSetChipLramAddr(iop_base, addr);
  3580. AscSetChipLramData(iop_base, word_val);
  3581. }
  3582. static void AscWriteLramByte(PortAddr iop_base, ushort addr, uchar byte_val)
  3583. {
  3584. ushort word_data;
  3585. if (isodd_word(addr)) {
  3586. addr--;
  3587. word_data = AscReadLramWord(iop_base, addr);
  3588. word_data &= 0x00FF;
  3589. word_data |= (((ushort)byte_val << 8) & 0xFF00);
  3590. } else {
  3591. word_data = AscReadLramWord(iop_base, addr);
  3592. word_data &= 0xFF00;
  3593. word_data |= ((ushort)byte_val & 0x00FF);
  3594. }
  3595. AscWriteLramWord(iop_base, addr, word_data);
  3596. }
  3597. /*
  3598. * Copy 2 bytes to LRAM.
  3599. *
  3600. * The source data is assumed to be in little-endian order in memory
  3601. * and is maintained in little-endian order when written to LRAM.
  3602. */
  3603. static void
  3604. AscMemWordCopyPtrToLram(PortAddr iop_base, ushort s_addr,
  3605. const uchar *s_buffer, int words)
  3606. {
  3607. int i;
  3608. AscSetChipLramAddr(iop_base, s_addr);
  3609. for (i = 0; i < 2 * words; i += 2) {
  3610. /*
  3611. * On a little-endian system the second argument below
  3612. * produces a little-endian ushort which is written to
  3613. * LRAM in little-endian order. On a big-endian system
  3614. * the second argument produces a big-endian ushort which
  3615. * is "transparently" byte-swapped by outpw() and written
  3616. * in little-endian order to LRAM.
  3617. */
  3618. outpw(iop_base + IOP_RAM_DATA,
  3619. ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]);
  3620. }
  3621. }
  3622. /*
  3623. * Copy 4 bytes to LRAM.
  3624. *
  3625. * The source data is assumed to be in little-endian order in memory
  3626. * and is maintained in little-endian order when written to LRAM.
  3627. */
  3628. static void
  3629. AscMemDWordCopyPtrToLram(PortAddr iop_base,
  3630. ushort s_addr, uchar *s_buffer, int dwords)
  3631. {
  3632. int i;
  3633. AscSetChipLramAddr(iop_base, s_addr);
  3634. for (i = 0; i < 4 * dwords; i += 4) {
  3635. outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]); /* LSW */
  3636. outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 3] << 8) | s_buffer[i + 2]); /* MSW */
  3637. }
  3638. }
  3639. /*
  3640. * Copy 2 bytes from LRAM.
  3641. *
  3642. * The source data is assumed to be in little-endian order in LRAM
  3643. * and is maintained in little-endian order when written to memory.
  3644. */
  3645. static void
  3646. AscMemWordCopyPtrFromLram(PortAddr iop_base,
  3647. ushort s_addr, uchar *d_buffer, int words)
  3648. {
  3649. int i;
  3650. ushort word;
  3651. AscSetChipLramAddr(iop_base, s_addr);
  3652. for (i = 0; i < 2 * words; i += 2) {
  3653. word = inpw(iop_base + IOP_RAM_DATA);
  3654. d_buffer[i] = word & 0xff;
  3655. d_buffer[i + 1] = (word >> 8) & 0xff;
  3656. }
  3657. }
  3658. static ASC_DCNT AscMemSumLramWord(PortAddr iop_base, ushort s_addr, int words)
  3659. {
  3660. ASC_DCNT sum;
  3661. int i;
  3662. sum = 0L;
  3663. for (i = 0; i < words; i++, s_addr += 2) {
  3664. sum += AscReadLramWord(iop_base, s_addr);
  3665. }
  3666. return (sum);
  3667. }
  3668. static ushort AscInitLram(ASC_DVC_VAR *asc_dvc)
  3669. {
  3670. uchar i;
  3671. ushort s_addr;
  3672. PortAddr iop_base;
  3673. ushort warn_code;
  3674. iop_base = asc_dvc->iop_base;
  3675. warn_code = 0;
  3676. AscMemWordSetLram(iop_base, ASC_QADR_BEG, 0,
  3677. (ushort)(((int)(asc_dvc->max_total_qng + 2 + 1) *
  3678. 64) >> 1));
  3679. i = ASC_MIN_ACTIVE_QNO;
  3680. s_addr = ASC_QADR_BEG + ASC_QBLK_SIZE;
  3681. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  3682. (uchar)(i + 1));
  3683. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  3684. (uchar)(asc_dvc->max_total_qng));
  3685. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  3686. (uchar)i);
  3687. i++;
  3688. s_addr += ASC_QBLK_SIZE;
  3689. for (; i < asc_dvc->max_total_qng; i++, s_addr += ASC_QBLK_SIZE) {
  3690. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  3691. (uchar)(i + 1));
  3692. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  3693. (uchar)(i - 1));
  3694. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  3695. (uchar)i);
  3696. }
  3697. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD),
  3698. (uchar)ASC_QLINK_END);
  3699. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD),
  3700. (uchar)(asc_dvc->max_total_qng - 1));
  3701. AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO),
  3702. (uchar)asc_dvc->max_total_qng);
  3703. i++;
  3704. s_addr += ASC_QBLK_SIZE;
  3705. for (; i <= (uchar)(asc_dvc->max_total_qng + 3);
  3706. i++, s_addr += ASC_QBLK_SIZE) {
  3707. AscWriteLramByte(iop_base,
  3708. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_FWD), i);
  3709. AscWriteLramByte(iop_base,
  3710. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_BWD), i);
  3711. AscWriteLramByte(iop_base,
  3712. (ushort)(s_addr + (ushort)ASC_SCSIQ_B_QNO), i);
  3713. }
  3714. return warn_code;
  3715. }
  3716. static ASC_DCNT
  3717. AscLoadMicroCode(PortAddr iop_base, ushort s_addr,
  3718. const uchar *mcode_buf, ushort mcode_size)
  3719. {
  3720. ASC_DCNT chksum;
  3721. ushort mcode_word_size;
  3722. ushort mcode_chksum;
  3723. /* Write the microcode buffer starting at LRAM address 0. */
  3724. mcode_word_size = (ushort)(mcode_size >> 1);
  3725. AscMemWordSetLram(iop_base, s_addr, 0, mcode_word_size);
  3726. AscMemWordCopyPtrToLram(iop_base, s_addr, mcode_buf, mcode_word_size);
  3727. chksum = AscMemSumLramWord(iop_base, s_addr, mcode_word_size);
  3728. ASC_DBG(1, "chksum 0x%lx\n", (ulong)chksum);
  3729. mcode_chksum = (ushort)AscMemSumLramWord(iop_base,
  3730. (ushort)ASC_CODE_SEC_BEG,
  3731. (ushort)((mcode_size -
  3732. s_addr - (ushort)
  3733. ASC_CODE_SEC_BEG) /
  3734. 2));
  3735. ASC_DBG(1, "mcode_chksum 0x%lx\n", (ulong)mcode_chksum);
  3736. AscWriteLramWord(iop_base, ASCV_MCODE_CHKSUM_W, mcode_chksum);
  3737. AscWriteLramWord(iop_base, ASCV_MCODE_SIZE_W, mcode_size);
  3738. return chksum;
  3739. }
  3740. static void AscInitQLinkVar(ASC_DVC_VAR *asc_dvc)
  3741. {
  3742. PortAddr iop_base;
  3743. int i;
  3744. ushort lram_addr;
  3745. iop_base = asc_dvc->iop_base;
  3746. AscPutRiscVarFreeQHead(iop_base, 1);
  3747. AscPutRiscVarDoneQTail(iop_base, asc_dvc->max_total_qng);
  3748. AscPutVarFreeQHead(iop_base, 1);
  3749. AscPutVarDoneQTail(iop_base, asc_dvc->max_total_qng);
  3750. AscWriteLramByte(iop_base, ASCV_BUSY_QHEAD_B,
  3751. (uchar)((int)asc_dvc->max_total_qng + 1));
  3752. AscWriteLramByte(iop_base, ASCV_DISC1_QHEAD_B,
  3753. (uchar)((int)asc_dvc->max_total_qng + 2));
  3754. AscWriteLramByte(iop_base, (ushort)ASCV_TOTAL_READY_Q_B,
  3755. asc_dvc->max_total_qng);
  3756. AscWriteLramWord(iop_base, ASCV_ASCDVC_ERR_CODE_W, 0);
  3757. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  3758. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, 0);
  3759. AscWriteLramByte(iop_base, ASCV_SCSIBUSY_B, 0);
  3760. AscWriteLramByte(iop_base, ASCV_WTM_FLAG_B, 0);
  3761. AscPutQDoneInProgress(iop_base, 0);
  3762. lram_addr = ASC_QADR_BEG;
  3763. for (i = 0; i < 32; i++, lram_addr += 2) {
  3764. AscWriteLramWord(iop_base, lram_addr, 0);
  3765. }
  3766. }
  3767. static ushort AscInitMicroCodeVar(ASC_DVC_VAR *asc_dvc)
  3768. {
  3769. int i;
  3770. ushort warn_code;
  3771. PortAddr iop_base;
  3772. ASC_PADDR phy_addr;
  3773. ASC_DCNT phy_size;
  3774. struct asc_board *board = asc_dvc_to_board(asc_dvc);
  3775. iop_base = asc_dvc->iop_base;
  3776. warn_code = 0;
  3777. for (i = 0; i <= ASC_MAX_TID; i++) {
  3778. AscPutMCodeInitSDTRAtID(iop_base, i,
  3779. asc_dvc->cfg->sdtr_period_offset[i]);
  3780. }
  3781. AscInitQLinkVar(asc_dvc);
  3782. AscWriteLramByte(iop_base, ASCV_DISC_ENABLE_B,
  3783. asc_dvc->cfg->disc_enable);
  3784. AscWriteLramByte(iop_base, ASCV_HOSTSCSI_ID_B,
  3785. ASC_TID_TO_TARGET_ID(asc_dvc->cfg->chip_scsi_id));
  3786. /* Ensure overrun buffer is aligned on an 8 byte boundary. */
  3787. BUG_ON((unsigned long)asc_dvc->overrun_buf & 7);
  3788. asc_dvc->overrun_dma = dma_map_single(board->dev, asc_dvc->overrun_buf,
  3789. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  3790. if (dma_mapping_error(board->dev, asc_dvc->overrun_dma)) {
  3791. warn_code = -ENOMEM;
  3792. goto err_dma_map;
  3793. }
  3794. phy_addr = cpu_to_le32(asc_dvc->overrun_dma);
  3795. AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_PADDR_D,
  3796. (uchar *)&phy_addr, 1);
  3797. phy_size = cpu_to_le32(ASC_OVERRUN_BSIZE);
  3798. AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_BSIZE_D,
  3799. (uchar *)&phy_size, 1);
  3800. asc_dvc->cfg->mcode_date =
  3801. AscReadLramWord(iop_base, (ushort)ASCV_MC_DATE_W);
  3802. asc_dvc->cfg->mcode_version =
  3803. AscReadLramWord(iop_base, (ushort)ASCV_MC_VER_W);
  3804. AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
  3805. if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
  3806. asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
  3807. warn_code = UW_ERR;
  3808. goto err_mcode_start;
  3809. }
  3810. if (AscStartChip(iop_base) != 1) {
  3811. asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
  3812. warn_code = UW_ERR;
  3813. goto err_mcode_start;
  3814. }
  3815. return warn_code;
  3816. err_mcode_start:
  3817. dma_unmap_single(board->dev, asc_dvc->overrun_dma,
  3818. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  3819. err_dma_map:
  3820. asc_dvc->overrun_dma = 0;
  3821. return warn_code;
  3822. }
  3823. static ushort AscInitAsc1000Driver(ASC_DVC_VAR *asc_dvc)
  3824. {
  3825. const struct firmware *fw;
  3826. const char fwname[] = "advansys/mcode.bin";
  3827. int err;
  3828. unsigned long chksum;
  3829. ushort warn_code;
  3830. PortAddr iop_base;
  3831. iop_base = asc_dvc->iop_base;
  3832. warn_code = 0;
  3833. if ((asc_dvc->dvc_cntl & ASC_CNTL_RESET_SCSI) &&
  3834. !(asc_dvc->init_state & ASC_INIT_RESET_SCSI_DONE)) {
  3835. AscResetChipAndScsiBus(asc_dvc);
  3836. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  3837. }
  3838. asc_dvc->init_state |= ASC_INIT_STATE_BEG_LOAD_MC;
  3839. if (asc_dvc->err_code != 0)
  3840. return UW_ERR;
  3841. if (!AscFindSignature(asc_dvc->iop_base)) {
  3842. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  3843. return warn_code;
  3844. }
  3845. AscDisableInterrupt(iop_base);
  3846. warn_code |= AscInitLram(asc_dvc);
  3847. if (asc_dvc->err_code != 0)
  3848. return UW_ERR;
  3849. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  3850. if (err) {
  3851. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  3852. fwname, err);
  3853. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  3854. return err;
  3855. }
  3856. if (fw->size < 4) {
  3857. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  3858. fw->size, fwname);
  3859. release_firmware(fw);
  3860. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  3861. return -EINVAL;
  3862. }
  3863. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  3864. (fw->data[1] << 8) | fw->data[0];
  3865. ASC_DBG(1, "_asc_mcode_chksum 0x%lx\n", (ulong)chksum);
  3866. if (AscLoadMicroCode(iop_base, 0, &fw->data[4],
  3867. fw->size - 4) != chksum) {
  3868. asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
  3869. release_firmware(fw);
  3870. return warn_code;
  3871. }
  3872. release_firmware(fw);
  3873. warn_code |= AscInitMicroCodeVar(asc_dvc);
  3874. if (!asc_dvc->overrun_dma)
  3875. return warn_code;
  3876. asc_dvc->init_state |= ASC_INIT_STATE_END_LOAD_MC;
  3877. AscEnableInterrupt(iop_base);
  3878. return warn_code;
  3879. }
  3880. /*
  3881. * Load the Microcode
  3882. *
  3883. * Write the microcode image to RISC memory starting at address 0.
  3884. *
  3885. * The microcode is stored compressed in the following format:
  3886. *
  3887. * 254 word (508 byte) table indexed by byte code followed
  3888. * by the following byte codes:
  3889. *
  3890. * 1-Byte Code:
  3891. * 00: Emit word 0 in table.
  3892. * 01: Emit word 1 in table.
  3893. * .
  3894. * FD: Emit word 253 in table.
  3895. *
  3896. * Multi-Byte Code:
  3897. * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
  3898. * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
  3899. *
  3900. * Returns 0 or an error if the checksum doesn't match
  3901. */
  3902. static int AdvLoadMicrocode(AdvPortAddr iop_base, const unsigned char *buf,
  3903. int size, int memsize, int chksum)
  3904. {
  3905. int i, j, end, len = 0;
  3906. ADV_DCNT sum;
  3907. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
  3908. for (i = 253 * 2; i < size; i++) {
  3909. if (buf[i] == 0xff) {
  3910. unsigned short word = (buf[i + 3] << 8) | buf[i + 2];
  3911. for (j = 0; j < buf[i + 1]; j++) {
  3912. AdvWriteWordAutoIncLram(iop_base, word);
  3913. len += 2;
  3914. }
  3915. i += 3;
  3916. } else if (buf[i] == 0xfe) {
  3917. unsigned short word = (buf[i + 2] << 8) | buf[i + 1];
  3918. AdvWriteWordAutoIncLram(iop_base, word);
  3919. i += 2;
  3920. len += 2;
  3921. } else {
  3922. unsigned int off = buf[i] * 2;
  3923. unsigned short word = (buf[off + 1] << 8) | buf[off];
  3924. AdvWriteWordAutoIncLram(iop_base, word);
  3925. len += 2;
  3926. }
  3927. }
  3928. end = len;
  3929. while (len < memsize) {
  3930. AdvWriteWordAutoIncLram(iop_base, 0);
  3931. len += 2;
  3932. }
  3933. /* Verify the microcode checksum. */
  3934. sum = 0;
  3935. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
  3936. for (len = 0; len < end; len += 2) {
  3937. sum += AdvReadWordAutoIncLram(iop_base);
  3938. }
  3939. if (sum != chksum)
  3940. return ASC_IERR_MCODE_CHKSUM;
  3941. return 0;
  3942. }
  3943. static void AdvBuildCarrierFreelist(struct adv_dvc_var *asc_dvc)
  3944. {
  3945. ADV_CARR_T *carrp;
  3946. ADV_SDCNT buf_size;
  3947. ADV_PADDR carr_paddr;
  3948. carrp = (ADV_CARR_T *) ADV_16BALIGN(asc_dvc->carrier_buf);
  3949. asc_dvc->carr_freelist = NULL;
  3950. if (carrp == asc_dvc->carrier_buf) {
  3951. buf_size = ADV_CARRIER_BUFSIZE;
  3952. } else {
  3953. buf_size = ADV_CARRIER_BUFSIZE - sizeof(ADV_CARR_T);
  3954. }
  3955. do {
  3956. /* Get physical address of the carrier 'carrp'. */
  3957. carr_paddr = cpu_to_le32(virt_to_bus(carrp));
  3958. buf_size -= sizeof(ADV_CARR_T);
  3959. carrp->carr_pa = carr_paddr;
  3960. carrp->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(carrp));
  3961. /*
  3962. * Insert the carrier at the beginning of the freelist.
  3963. */
  3964. carrp->next_vpa =
  3965. cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
  3966. asc_dvc->carr_freelist = carrp;
  3967. carrp++;
  3968. } while (buf_size > 0);
  3969. }
  3970. /*
  3971. * Send an idle command to the chip and wait for completion.
  3972. *
  3973. * Command completion is polled for once per microsecond.
  3974. *
  3975. * The function can be called from anywhere including an interrupt handler.
  3976. * But the function is not re-entrant, so it uses the DvcEnter/LeaveCritical()
  3977. * functions to prevent reentrancy.
  3978. *
  3979. * Return Values:
  3980. * ADV_TRUE - command completed successfully
  3981. * ADV_FALSE - command failed
  3982. * ADV_ERROR - command timed out
  3983. */
  3984. static int
  3985. AdvSendIdleCmd(ADV_DVC_VAR *asc_dvc,
  3986. ushort idle_cmd, ADV_DCNT idle_cmd_parameter)
  3987. {
  3988. int result;
  3989. ADV_DCNT i, j;
  3990. AdvPortAddr iop_base;
  3991. iop_base = asc_dvc->iop_base;
  3992. /*
  3993. * Clear the idle command status which is set by the microcode
  3994. * to a non-zero value to indicate when the command is completed.
  3995. * The non-zero result is one of the IDLE_CMD_STATUS_* values
  3996. */
  3997. AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, (ushort)0);
  3998. /*
  3999. * Write the idle command value after the idle command parameter
  4000. * has been written to avoid a race condition. If the order is not
  4001. * followed, the microcode may process the idle command before the
  4002. * parameters have been written to LRAM.
  4003. */
  4004. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IDLE_CMD_PARAMETER,
  4005. cpu_to_le32(idle_cmd_parameter));
  4006. AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD, idle_cmd);
  4007. /*
  4008. * Tickle the RISC to tell it to process the idle command.
  4009. */
  4010. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_B);
  4011. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  4012. /*
  4013. * Clear the tickle value. In the ASC-3550 the RISC flag
  4014. * command 'clr_tickle_b' does not work unless the host
  4015. * value is cleared.
  4016. */
  4017. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
  4018. }
  4019. /* Wait for up to 100 millisecond for the idle command to timeout. */
  4020. for (i = 0; i < SCSI_WAIT_100_MSEC; i++) {
  4021. /* Poll once each microsecond for command completion. */
  4022. for (j = 0; j < SCSI_US_PER_MSEC; j++) {
  4023. AdvReadWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS,
  4024. result);
  4025. if (result != 0)
  4026. return result;
  4027. udelay(1);
  4028. }
  4029. }
  4030. BUG(); /* The idle command should never timeout. */
  4031. return ADV_ERROR;
  4032. }
  4033. /*
  4034. * Reset SCSI Bus and purge all outstanding requests.
  4035. *
  4036. * Return Value:
  4037. * ADV_TRUE(1) - All requests are purged and SCSI Bus is reset.
  4038. * ADV_FALSE(0) - Microcode command failed.
  4039. * ADV_ERROR(-1) - Microcode command timed-out. Microcode or IC
  4040. * may be hung which requires driver recovery.
  4041. */
  4042. static int AdvResetSB(ADV_DVC_VAR *asc_dvc)
  4043. {
  4044. int status;
  4045. /*
  4046. * Send the SCSI Bus Reset idle start idle command which asserts
  4047. * the SCSI Bus Reset signal.
  4048. */
  4049. status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_START, 0L);
  4050. if (status != ADV_TRUE) {
  4051. return status;
  4052. }
  4053. /*
  4054. * Delay for the specified SCSI Bus Reset hold time.
  4055. *
  4056. * The hold time delay is done on the host because the RISC has no
  4057. * microsecond accurate timer.
  4058. */
  4059. udelay(ASC_SCSI_RESET_HOLD_TIME_US);
  4060. /*
  4061. * Send the SCSI Bus Reset end idle command which de-asserts
  4062. * the SCSI Bus Reset signal and purges any pending requests.
  4063. */
  4064. status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_END, 0L);
  4065. if (status != ADV_TRUE) {
  4066. return status;
  4067. }
  4068. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  4069. return status;
  4070. }
  4071. /*
  4072. * Initialize the ASC-3550.
  4073. *
  4074. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  4075. *
  4076. * For a non-fatal error return a warning code. If there are no warnings
  4077. * then 0 is returned.
  4078. *
  4079. * Needed after initialization for error recovery.
  4080. */
  4081. static int AdvInitAsc3550Driver(ADV_DVC_VAR *asc_dvc)
  4082. {
  4083. const struct firmware *fw;
  4084. const char fwname[] = "advansys/3550.bin";
  4085. AdvPortAddr iop_base;
  4086. ushort warn_code;
  4087. int begin_addr;
  4088. int end_addr;
  4089. ushort code_sum;
  4090. int word;
  4091. int i;
  4092. int err;
  4093. unsigned long chksum;
  4094. ushort scsi_cfg1;
  4095. uchar tid;
  4096. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  4097. ushort wdtr_able = 0, sdtr_able, tagqng_able;
  4098. uchar max_cmd[ADV_MAX_TID + 1];
  4099. /* If there is already an error, don't continue. */
  4100. if (asc_dvc->err_code != 0)
  4101. return ADV_ERROR;
  4102. /*
  4103. * The caller must set 'chip_type' to ADV_CHIP_ASC3550.
  4104. */
  4105. if (asc_dvc->chip_type != ADV_CHIP_ASC3550) {
  4106. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  4107. return ADV_ERROR;
  4108. }
  4109. warn_code = 0;
  4110. iop_base = asc_dvc->iop_base;
  4111. /*
  4112. * Save the RISC memory BIOS region before writing the microcode.
  4113. * The BIOS may already be loaded and using its RISC LRAM region
  4114. * so its region must be saved and restored.
  4115. *
  4116. * Note: This code makes the assumption, which is currently true,
  4117. * that a chip reset does not clear RISC LRAM.
  4118. */
  4119. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4120. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4121. bios_mem[i]);
  4122. }
  4123. /*
  4124. * Save current per TID negotiated values.
  4125. */
  4126. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] == 0x55AA) {
  4127. ushort bios_version, major, minor;
  4128. bios_version =
  4129. bios_mem[(ASC_MC_BIOS_VERSION - ASC_MC_BIOSMEM) / 2];
  4130. major = (bios_version >> 12) & 0xF;
  4131. minor = (bios_version >> 8) & 0xF;
  4132. if (major < 3 || (major == 3 && minor == 1)) {
  4133. /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */
  4134. AdvReadWordLram(iop_base, 0x120, wdtr_able);
  4135. } else {
  4136. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4137. }
  4138. }
  4139. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4140. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  4141. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4142. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4143. max_cmd[tid]);
  4144. }
  4145. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  4146. if (err) {
  4147. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  4148. fwname, err);
  4149. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4150. return err;
  4151. }
  4152. if (fw->size < 4) {
  4153. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  4154. fw->size, fwname);
  4155. release_firmware(fw);
  4156. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4157. return -EINVAL;
  4158. }
  4159. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  4160. (fw->data[1] << 8) | fw->data[0];
  4161. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  4162. fw->size - 4, ADV_3550_MEMSIZE,
  4163. chksum);
  4164. release_firmware(fw);
  4165. if (asc_dvc->err_code)
  4166. return ADV_ERROR;
  4167. /*
  4168. * Restore the RISC memory BIOS region.
  4169. */
  4170. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4171. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4172. bios_mem[i]);
  4173. }
  4174. /*
  4175. * Calculate and write the microcode code checksum to the microcode
  4176. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  4177. */
  4178. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  4179. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  4180. code_sum = 0;
  4181. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  4182. for (word = begin_addr; word < end_addr; word += 2) {
  4183. code_sum += AdvReadWordAutoIncLram(iop_base);
  4184. }
  4185. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  4186. /*
  4187. * Read and save microcode version and date.
  4188. */
  4189. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  4190. asc_dvc->cfg->mcode_date);
  4191. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  4192. asc_dvc->cfg->mcode_version);
  4193. /*
  4194. * Set the chip type to indicate the ASC3550.
  4195. */
  4196. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC3550);
  4197. /*
  4198. * If the PCI Configuration Command Register "Parity Error Response
  4199. * Control" Bit was clear (0), then set the microcode variable
  4200. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  4201. * to ignore DMA parity errors.
  4202. */
  4203. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  4204. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4205. word |= CONTROL_FLAG_IGNORE_PERR;
  4206. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4207. }
  4208. /*
  4209. * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO
  4210. * threshold of 128 bytes. This register is only accessible to the host.
  4211. */
  4212. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  4213. START_CTL_EMFU | READ_CMD_MRM);
  4214. /*
  4215. * Microcode operating variables for WDTR, SDTR, and command tag
  4216. * queuing will be set in slave_configure() based on what a
  4217. * device reports it is capable of in Inquiry byte 7.
  4218. *
  4219. * If SCSI Bus Resets have been disabled, then directly set
  4220. * SDTR and WDTR from the EEPROM configuration. This will allow
  4221. * the BIOS and warm boot to work without a SCSI bus hang on
  4222. * the Inquiry caused by host and target mismatched DTR values.
  4223. * Without the SCSI Bus Reset, before an Inquiry a device can't
  4224. * be assumed to be in Asynchronous, Narrow mode.
  4225. */
  4226. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  4227. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  4228. asc_dvc->wdtr_able);
  4229. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  4230. asc_dvc->sdtr_able);
  4231. }
  4232. /*
  4233. * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2,
  4234. * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID
  4235. * bitmask. These values determine the maximum SDTR speed negotiated
  4236. * with a device.
  4237. *
  4238. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  4239. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  4240. * without determining here whether the device supports SDTR.
  4241. *
  4242. * 4-bit speed SDTR speed name
  4243. * =========== ===============
  4244. * 0000b (0x0) SDTR disabled
  4245. * 0001b (0x1) 5 Mhz
  4246. * 0010b (0x2) 10 Mhz
  4247. * 0011b (0x3) 20 Mhz (Ultra)
  4248. * 0100b (0x4) 40 Mhz (LVD/Ultra2)
  4249. * 0101b (0x5) 80 Mhz (LVD2/Ultra3)
  4250. * 0110b (0x6) Undefined
  4251. * .
  4252. * 1111b (0xF) Undefined
  4253. */
  4254. word = 0;
  4255. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4256. if (ADV_TID_TO_TIDMASK(tid) & asc_dvc->ultra_able) {
  4257. /* Set Ultra speed for TID 'tid'. */
  4258. word |= (0x3 << (4 * (tid % 4)));
  4259. } else {
  4260. /* Set Fast speed for TID 'tid'. */
  4261. word |= (0x2 << (4 * (tid % 4)));
  4262. }
  4263. if (tid == 3) { /* Check if done with sdtr_speed1. */
  4264. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, word);
  4265. word = 0;
  4266. } else if (tid == 7) { /* Check if done with sdtr_speed2. */
  4267. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, word);
  4268. word = 0;
  4269. } else if (tid == 11) { /* Check if done with sdtr_speed3. */
  4270. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, word);
  4271. word = 0;
  4272. } else if (tid == 15) { /* Check if done with sdtr_speed4. */
  4273. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, word);
  4274. /* End of loop. */
  4275. }
  4276. }
  4277. /*
  4278. * Set microcode operating variable for the disconnect per TID bitmask.
  4279. */
  4280. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  4281. asc_dvc->cfg->disc_enable);
  4282. /*
  4283. * Set SCSI_CFG0 Microcode Default Value.
  4284. *
  4285. * The microcode will set the SCSI_CFG0 register using this value
  4286. * after it is started below.
  4287. */
  4288. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  4289. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  4290. asc_dvc->chip_scsi_id);
  4291. /*
  4292. * Determine SCSI_CFG1 Microcode Default Value.
  4293. *
  4294. * The microcode will set the SCSI_CFG1 register using this value
  4295. * after it is started below.
  4296. */
  4297. /* Read current SCSI_CFG1 Register value. */
  4298. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4299. /*
  4300. * If all three connectors are in use, return an error.
  4301. */
  4302. if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 ||
  4303. (scsi_cfg1 & CABLE_ILLEGAL_B) == 0) {
  4304. asc_dvc->err_code |= ASC_IERR_ILLEGAL_CONNECTION;
  4305. return ADV_ERROR;
  4306. }
  4307. /*
  4308. * If the internal narrow cable is reversed all of the SCSI_CTRL
  4309. * register signals will be set. Check for and return an error if
  4310. * this condition is found.
  4311. */
  4312. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  4313. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  4314. return ADV_ERROR;
  4315. }
  4316. /*
  4317. * If this is a differential board and a single-ended device
  4318. * is attached to one of the connectors, return an error.
  4319. */
  4320. if ((scsi_cfg1 & DIFF_MODE) && (scsi_cfg1 & DIFF_SENSE) == 0) {
  4321. asc_dvc->err_code |= ASC_IERR_SINGLE_END_DEVICE;
  4322. return ADV_ERROR;
  4323. }
  4324. /*
  4325. * If automatic termination control is enabled, then set the
  4326. * termination value based on a table listed in a_condor.h.
  4327. *
  4328. * If manual termination was specified with an EEPROM setting
  4329. * then 'termination' was set-up in AdvInitFrom3550EEPROM() and
  4330. * is ready to be 'ored' into SCSI_CFG1.
  4331. */
  4332. if (asc_dvc->cfg->termination == 0) {
  4333. /*
  4334. * The software always controls termination by setting TERM_CTL_SEL.
  4335. * If TERM_CTL_SEL were set to 0, the hardware would set termination.
  4336. */
  4337. asc_dvc->cfg->termination |= TERM_CTL_SEL;
  4338. switch (scsi_cfg1 & CABLE_DETECT) {
  4339. /* TERM_CTL_H: on, TERM_CTL_L: on */
  4340. case 0x3:
  4341. case 0x7:
  4342. case 0xB:
  4343. case 0xD:
  4344. case 0xE:
  4345. case 0xF:
  4346. asc_dvc->cfg->termination |= (TERM_CTL_H | TERM_CTL_L);
  4347. break;
  4348. /* TERM_CTL_H: on, TERM_CTL_L: off */
  4349. case 0x1:
  4350. case 0x5:
  4351. case 0x9:
  4352. case 0xA:
  4353. case 0xC:
  4354. asc_dvc->cfg->termination |= TERM_CTL_H;
  4355. break;
  4356. /* TERM_CTL_H: off, TERM_CTL_L: off */
  4357. case 0x2:
  4358. case 0x6:
  4359. break;
  4360. }
  4361. }
  4362. /*
  4363. * Clear any set TERM_CTL_H and TERM_CTL_L bits.
  4364. */
  4365. scsi_cfg1 &= ~TERM_CTL;
  4366. /*
  4367. * Invert the TERM_CTL_H and TERM_CTL_L bits and then
  4368. * set 'scsi_cfg1'. The TERM_POL bit does not need to be
  4369. * referenced, because the hardware internally inverts
  4370. * the Termination High and Low bits if TERM_POL is set.
  4371. */
  4372. scsi_cfg1 |= (TERM_CTL_SEL | (~asc_dvc->cfg->termination & TERM_CTL));
  4373. /*
  4374. * Set SCSI_CFG1 Microcode Default Value
  4375. *
  4376. * Set filter value and possibly modified termination control
  4377. * bits in the Microcode SCSI_CFG1 Register Value.
  4378. *
  4379. * The microcode will set the SCSI_CFG1 register using this value
  4380. * after it is started below.
  4381. */
  4382. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1,
  4383. FLTR_DISABLE | scsi_cfg1);
  4384. /*
  4385. * Set MEM_CFG Microcode Default Value
  4386. *
  4387. * The microcode will set the MEM_CFG register using this value
  4388. * after it is started below.
  4389. *
  4390. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  4391. * are defined.
  4392. *
  4393. * ASC-3550 has 8KB internal memory.
  4394. */
  4395. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  4396. BIOS_EN | RAM_SZ_8KB);
  4397. /*
  4398. * Set SEL_MASK Microcode Default Value
  4399. *
  4400. * The microcode will set the SEL_MASK register using this value
  4401. * after it is started below.
  4402. */
  4403. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  4404. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  4405. AdvBuildCarrierFreelist(asc_dvc);
  4406. /*
  4407. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  4408. */
  4409. if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL) {
  4410. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4411. return ADV_ERROR;
  4412. }
  4413. asc_dvc->carr_freelist = (ADV_CARR_T *)
  4414. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
  4415. /*
  4416. * The first command issued will be placed in the stopper carrier.
  4417. */
  4418. asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  4419. /*
  4420. * Set RISC ICQ physical address start value.
  4421. */
  4422. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  4423. /*
  4424. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  4425. */
  4426. if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL) {
  4427. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4428. return ADV_ERROR;
  4429. }
  4430. asc_dvc->carr_freelist = (ADV_CARR_T *)
  4431. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
  4432. /*
  4433. * The first command completed by the RISC will be placed in
  4434. * the stopper.
  4435. *
  4436. * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
  4437. * completed the RISC will set the ASC_RQ_STOPPER bit.
  4438. */
  4439. asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  4440. /*
  4441. * Set RISC IRQ physical address start value.
  4442. */
  4443. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  4444. asc_dvc->carr_pending_cnt = 0;
  4445. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  4446. (ADV_INTR_ENABLE_HOST_INTR |
  4447. ADV_INTR_ENABLE_GLOBAL_INTR));
  4448. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  4449. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  4450. /* finally, finally, gentlemen, start your engine */
  4451. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  4452. /*
  4453. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  4454. * Resets should be performed. The RISC has to be running
  4455. * to issue a SCSI Bus Reset.
  4456. */
  4457. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  4458. /*
  4459. * If the BIOS Signature is present in memory, restore the
  4460. * BIOS Handshake Configuration Table and do not perform
  4461. * a SCSI Bus Reset.
  4462. */
  4463. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  4464. 0x55AA) {
  4465. /*
  4466. * Restore per TID negotiated values.
  4467. */
  4468. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4469. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4470. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  4471. tagqng_able);
  4472. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4473. AdvWriteByteLram(iop_base,
  4474. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4475. max_cmd[tid]);
  4476. }
  4477. } else {
  4478. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  4479. warn_code = ASC_WARN_BUSRESET_ERROR;
  4480. }
  4481. }
  4482. }
  4483. return warn_code;
  4484. }
  4485. /*
  4486. * Initialize the ASC-38C0800.
  4487. *
  4488. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  4489. *
  4490. * For a non-fatal error return a warning code. If there are no warnings
  4491. * then 0 is returned.
  4492. *
  4493. * Needed after initialization for error recovery.
  4494. */
  4495. static int AdvInitAsc38C0800Driver(ADV_DVC_VAR *asc_dvc)
  4496. {
  4497. const struct firmware *fw;
  4498. const char fwname[] = "advansys/38C0800.bin";
  4499. AdvPortAddr iop_base;
  4500. ushort warn_code;
  4501. int begin_addr;
  4502. int end_addr;
  4503. ushort code_sum;
  4504. int word;
  4505. int i;
  4506. int err;
  4507. unsigned long chksum;
  4508. ushort scsi_cfg1;
  4509. uchar byte;
  4510. uchar tid;
  4511. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  4512. ushort wdtr_able, sdtr_able, tagqng_able;
  4513. uchar max_cmd[ADV_MAX_TID + 1];
  4514. /* If there is already an error, don't continue. */
  4515. if (asc_dvc->err_code != 0)
  4516. return ADV_ERROR;
  4517. /*
  4518. * The caller must set 'chip_type' to ADV_CHIP_ASC38C0800.
  4519. */
  4520. if (asc_dvc->chip_type != ADV_CHIP_ASC38C0800) {
  4521. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  4522. return ADV_ERROR;
  4523. }
  4524. warn_code = 0;
  4525. iop_base = asc_dvc->iop_base;
  4526. /*
  4527. * Save the RISC memory BIOS region before writing the microcode.
  4528. * The BIOS may already be loaded and using its RISC LRAM region
  4529. * so its region must be saved and restored.
  4530. *
  4531. * Note: This code makes the assumption, which is currently true,
  4532. * that a chip reset does not clear RISC LRAM.
  4533. */
  4534. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4535. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4536. bios_mem[i]);
  4537. }
  4538. /*
  4539. * Save current per TID negotiated values.
  4540. */
  4541. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4542. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4543. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  4544. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4545. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4546. max_cmd[tid]);
  4547. }
  4548. /*
  4549. * RAM BIST (RAM Built-In Self Test)
  4550. *
  4551. * Address : I/O base + offset 0x38h register (byte).
  4552. * Function: Bit 7-6(RW) : RAM mode
  4553. * Normal Mode : 0x00
  4554. * Pre-test Mode : 0x40
  4555. * RAM Test Mode : 0x80
  4556. * Bit 5 : unused
  4557. * Bit 4(RO) : Done bit
  4558. * Bit 3-0(RO) : Status
  4559. * Host Error : 0x08
  4560. * Int_RAM Error : 0x04
  4561. * RISC Error : 0x02
  4562. * SCSI Error : 0x01
  4563. * No Error : 0x00
  4564. *
  4565. * Note: RAM BIST code should be put right here, before loading the
  4566. * microcode and after saving the RISC memory BIOS region.
  4567. */
  4568. /*
  4569. * LRAM Pre-test
  4570. *
  4571. * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
  4572. * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
  4573. * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
  4574. * to NORMAL_MODE, return an error too.
  4575. */
  4576. for (i = 0; i < 2; i++) {
  4577. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
  4578. mdelay(10); /* Wait for 10ms before reading back. */
  4579. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  4580. if ((byte & RAM_TEST_DONE) == 0
  4581. || (byte & 0x0F) != PRE_TEST_VALUE) {
  4582. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  4583. return ADV_ERROR;
  4584. }
  4585. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  4586. mdelay(10); /* Wait for 10ms before reading back. */
  4587. if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
  4588. != NORMAL_VALUE) {
  4589. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  4590. return ADV_ERROR;
  4591. }
  4592. }
  4593. /*
  4594. * LRAM Test - It takes about 1.5 ms to run through the test.
  4595. *
  4596. * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
  4597. * If Done bit not set or Status not 0, save register byte, set the
  4598. * err_code, and return an error.
  4599. */
  4600. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
  4601. mdelay(10); /* Wait for 10ms before checking status. */
  4602. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  4603. if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
  4604. /* Get here if Done bit not set or Status not 0. */
  4605. asc_dvc->bist_err_code = byte; /* for BIOS display message */
  4606. asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
  4607. return ADV_ERROR;
  4608. }
  4609. /* We need to reset back to normal mode after LRAM test passes. */
  4610. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  4611. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  4612. if (err) {
  4613. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  4614. fwname, err);
  4615. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4616. return err;
  4617. }
  4618. if (fw->size < 4) {
  4619. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  4620. fw->size, fwname);
  4621. release_firmware(fw);
  4622. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  4623. return -EINVAL;
  4624. }
  4625. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  4626. (fw->data[1] << 8) | fw->data[0];
  4627. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  4628. fw->size - 4, ADV_38C0800_MEMSIZE,
  4629. chksum);
  4630. release_firmware(fw);
  4631. if (asc_dvc->err_code)
  4632. return ADV_ERROR;
  4633. /*
  4634. * Restore the RISC memory BIOS region.
  4635. */
  4636. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4637. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4638. bios_mem[i]);
  4639. }
  4640. /*
  4641. * Calculate and write the microcode code checksum to the microcode
  4642. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  4643. */
  4644. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  4645. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  4646. code_sum = 0;
  4647. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  4648. for (word = begin_addr; word < end_addr; word += 2) {
  4649. code_sum += AdvReadWordAutoIncLram(iop_base);
  4650. }
  4651. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  4652. /*
  4653. * Read microcode version and date.
  4654. */
  4655. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  4656. asc_dvc->cfg->mcode_date);
  4657. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  4658. asc_dvc->cfg->mcode_version);
  4659. /*
  4660. * Set the chip type to indicate the ASC38C0800.
  4661. */
  4662. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C0800);
  4663. /*
  4664. * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
  4665. * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
  4666. * cable detection and then we are able to read C_DET[3:0].
  4667. *
  4668. * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
  4669. * Microcode Default Value' section below.
  4670. */
  4671. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4672. AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
  4673. scsi_cfg1 | DIS_TERM_DRV);
  4674. /*
  4675. * If the PCI Configuration Command Register "Parity Error Response
  4676. * Control" Bit was clear (0), then set the microcode variable
  4677. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  4678. * to ignore DMA parity errors.
  4679. */
  4680. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  4681. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4682. word |= CONTROL_FLAG_IGNORE_PERR;
  4683. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  4684. }
  4685. /*
  4686. * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and START_CTL_TH [3:2]
  4687. * bits for the default FIFO threshold.
  4688. *
  4689. * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
  4690. *
  4691. * For DMA Errata #4 set the BC_THRESH_ENB bit.
  4692. */
  4693. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  4694. BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH |
  4695. READ_CMD_MRM);
  4696. /*
  4697. * Microcode operating variables for WDTR, SDTR, and command tag
  4698. * queuing will be set in slave_configure() based on what a
  4699. * device reports it is capable of in Inquiry byte 7.
  4700. *
  4701. * If SCSI Bus Resets have been disabled, then directly set
  4702. * SDTR and WDTR from the EEPROM configuration. This will allow
  4703. * the BIOS and warm boot to work without a SCSI bus hang on
  4704. * the Inquiry caused by host and target mismatched DTR values.
  4705. * Without the SCSI Bus Reset, before an Inquiry a device can't
  4706. * be assumed to be in Asynchronous, Narrow mode.
  4707. */
  4708. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  4709. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  4710. asc_dvc->wdtr_able);
  4711. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  4712. asc_dvc->sdtr_able);
  4713. }
  4714. /*
  4715. * Set microcode operating variables for DISC and SDTR_SPEED1,
  4716. * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
  4717. * configuration values.
  4718. *
  4719. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  4720. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  4721. * without determining here whether the device supports SDTR.
  4722. */
  4723. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  4724. asc_dvc->cfg->disc_enable);
  4725. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
  4726. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
  4727. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
  4728. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
  4729. /*
  4730. * Set SCSI_CFG0 Microcode Default Value.
  4731. *
  4732. * The microcode will set the SCSI_CFG0 register using this value
  4733. * after it is started below.
  4734. */
  4735. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  4736. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  4737. asc_dvc->chip_scsi_id);
  4738. /*
  4739. * Determine SCSI_CFG1 Microcode Default Value.
  4740. *
  4741. * The microcode will set the SCSI_CFG1 register using this value
  4742. * after it is started below.
  4743. */
  4744. /* Read current SCSI_CFG1 Register value. */
  4745. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  4746. /*
  4747. * If the internal narrow cable is reversed all of the SCSI_CTRL
  4748. * register signals will be set. Check for and return an error if
  4749. * this condition is found.
  4750. */
  4751. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  4752. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  4753. return ADV_ERROR;
  4754. }
  4755. /*
  4756. * All kind of combinations of devices attached to one of four
  4757. * connectors are acceptable except HVD device attached. For example,
  4758. * LVD device can be attached to SE connector while SE device attached
  4759. * to LVD connector. If LVD device attached to SE connector, it only
  4760. * runs up to Ultra speed.
  4761. *
  4762. * If an HVD device is attached to one of LVD connectors, return an
  4763. * error. However, there is no way to detect HVD device attached to
  4764. * SE connectors.
  4765. */
  4766. if (scsi_cfg1 & HVD) {
  4767. asc_dvc->err_code = ASC_IERR_HVD_DEVICE;
  4768. return ADV_ERROR;
  4769. }
  4770. /*
  4771. * If either SE or LVD automatic termination control is enabled, then
  4772. * set the termination value based on a table listed in a_condor.h.
  4773. *
  4774. * If manual termination was specified with an EEPROM setting then
  4775. * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready
  4776. * to be 'ored' into SCSI_CFG1.
  4777. */
  4778. if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
  4779. /* SE automatic termination control is enabled. */
  4780. switch (scsi_cfg1 & C_DET_SE) {
  4781. /* TERM_SE_HI: on, TERM_SE_LO: on */
  4782. case 0x1:
  4783. case 0x2:
  4784. case 0x3:
  4785. asc_dvc->cfg->termination |= TERM_SE;
  4786. break;
  4787. /* TERM_SE_HI: on, TERM_SE_LO: off */
  4788. case 0x0:
  4789. asc_dvc->cfg->termination |= TERM_SE_HI;
  4790. break;
  4791. }
  4792. }
  4793. if ((asc_dvc->cfg->termination & TERM_LVD) == 0) {
  4794. /* LVD automatic termination control is enabled. */
  4795. switch (scsi_cfg1 & C_DET_LVD) {
  4796. /* TERM_LVD_HI: on, TERM_LVD_LO: on */
  4797. case 0x4:
  4798. case 0x8:
  4799. case 0xC:
  4800. asc_dvc->cfg->termination |= TERM_LVD;
  4801. break;
  4802. /* TERM_LVD_HI: off, TERM_LVD_LO: off */
  4803. case 0x0:
  4804. break;
  4805. }
  4806. }
  4807. /*
  4808. * Clear any set TERM_SE and TERM_LVD bits.
  4809. */
  4810. scsi_cfg1 &= (~TERM_SE & ~TERM_LVD);
  4811. /*
  4812. * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
  4813. */
  4814. scsi_cfg1 |= (~asc_dvc->cfg->termination & 0xF0);
  4815. /*
  4816. * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE
  4817. * bits and set possibly modified termination control bits in the
  4818. * Microcode SCSI_CFG1 Register Value.
  4819. */
  4820. scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL & ~HVD_LVD_SE);
  4821. /*
  4822. * Set SCSI_CFG1 Microcode Default Value
  4823. *
  4824. * Set possibly modified termination control and reset DIS_TERM_DRV
  4825. * bits in the Microcode SCSI_CFG1 Register Value.
  4826. *
  4827. * The microcode will set the SCSI_CFG1 register using this value
  4828. * after it is started below.
  4829. */
  4830. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
  4831. /*
  4832. * Set MEM_CFG Microcode Default Value
  4833. *
  4834. * The microcode will set the MEM_CFG register using this value
  4835. * after it is started below.
  4836. *
  4837. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  4838. * are defined.
  4839. *
  4840. * ASC-38C0800 has 16KB internal memory.
  4841. */
  4842. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  4843. BIOS_EN | RAM_SZ_16KB);
  4844. /*
  4845. * Set SEL_MASK Microcode Default Value
  4846. *
  4847. * The microcode will set the SEL_MASK register using this value
  4848. * after it is started below.
  4849. */
  4850. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  4851. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  4852. AdvBuildCarrierFreelist(asc_dvc);
  4853. /*
  4854. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  4855. */
  4856. if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL) {
  4857. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4858. return ADV_ERROR;
  4859. }
  4860. asc_dvc->carr_freelist = (ADV_CARR_T *)
  4861. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
  4862. /*
  4863. * The first command issued will be placed in the stopper carrier.
  4864. */
  4865. asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  4866. /*
  4867. * Set RISC ICQ physical address start value.
  4868. * carr_pa is LE, must be native before write
  4869. */
  4870. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  4871. /*
  4872. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  4873. */
  4874. if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL) {
  4875. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  4876. return ADV_ERROR;
  4877. }
  4878. asc_dvc->carr_freelist = (ADV_CARR_T *)
  4879. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
  4880. /*
  4881. * The first command completed by the RISC will be placed in
  4882. * the stopper.
  4883. *
  4884. * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
  4885. * completed the RISC will set the ASC_RQ_STOPPER bit.
  4886. */
  4887. asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  4888. /*
  4889. * Set RISC IRQ physical address start value.
  4890. *
  4891. * carr_pa is LE, must be native before write *
  4892. */
  4893. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  4894. asc_dvc->carr_pending_cnt = 0;
  4895. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  4896. (ADV_INTR_ENABLE_HOST_INTR |
  4897. ADV_INTR_ENABLE_GLOBAL_INTR));
  4898. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  4899. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  4900. /* finally, finally, gentlemen, start your engine */
  4901. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  4902. /*
  4903. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  4904. * Resets should be performed. The RISC has to be running
  4905. * to issue a SCSI Bus Reset.
  4906. */
  4907. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  4908. /*
  4909. * If the BIOS Signature is present in memory, restore the
  4910. * BIOS Handshake Configuration Table and do not perform
  4911. * a SCSI Bus Reset.
  4912. */
  4913. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  4914. 0x55AA) {
  4915. /*
  4916. * Restore per TID negotiated values.
  4917. */
  4918. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4919. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4920. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  4921. tagqng_able);
  4922. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  4923. AdvWriteByteLram(iop_base,
  4924. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4925. max_cmd[tid]);
  4926. }
  4927. } else {
  4928. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  4929. warn_code = ASC_WARN_BUSRESET_ERROR;
  4930. }
  4931. }
  4932. }
  4933. return warn_code;
  4934. }
  4935. /*
  4936. * Initialize the ASC-38C1600.
  4937. *
  4938. * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
  4939. *
  4940. * For a non-fatal error return a warning code. If there are no warnings
  4941. * then 0 is returned.
  4942. *
  4943. * Needed after initialization for error recovery.
  4944. */
  4945. static int AdvInitAsc38C1600Driver(ADV_DVC_VAR *asc_dvc)
  4946. {
  4947. const struct firmware *fw;
  4948. const char fwname[] = "advansys/38C1600.bin";
  4949. AdvPortAddr iop_base;
  4950. ushort warn_code;
  4951. int begin_addr;
  4952. int end_addr;
  4953. ushort code_sum;
  4954. long word;
  4955. int i;
  4956. int err;
  4957. unsigned long chksum;
  4958. ushort scsi_cfg1;
  4959. uchar byte;
  4960. uchar tid;
  4961. ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */
  4962. ushort wdtr_able, sdtr_able, ppr_able, tagqng_able;
  4963. uchar max_cmd[ASC_MAX_TID + 1];
  4964. /* If there is already an error, don't continue. */
  4965. if (asc_dvc->err_code != 0) {
  4966. return ADV_ERROR;
  4967. }
  4968. /*
  4969. * The caller must set 'chip_type' to ADV_CHIP_ASC38C1600.
  4970. */
  4971. if (asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
  4972. asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
  4973. return ADV_ERROR;
  4974. }
  4975. warn_code = 0;
  4976. iop_base = asc_dvc->iop_base;
  4977. /*
  4978. * Save the RISC memory BIOS region before writing the microcode.
  4979. * The BIOS may already be loaded and using its RISC LRAM region
  4980. * so its region must be saved and restored.
  4981. *
  4982. * Note: This code makes the assumption, which is currently true,
  4983. * that a chip reset does not clear RISC LRAM.
  4984. */
  4985. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  4986. AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  4987. bios_mem[i]);
  4988. }
  4989. /*
  4990. * Save current per TID negotiated values.
  4991. */
  4992. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  4993. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  4994. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  4995. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  4996. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  4997. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  4998. max_cmd[tid]);
  4999. }
  5000. /*
  5001. * RAM BIST (Built-In Self Test)
  5002. *
  5003. * Address : I/O base + offset 0x38h register (byte).
  5004. * Function: Bit 7-6(RW) : RAM mode
  5005. * Normal Mode : 0x00
  5006. * Pre-test Mode : 0x40
  5007. * RAM Test Mode : 0x80
  5008. * Bit 5 : unused
  5009. * Bit 4(RO) : Done bit
  5010. * Bit 3-0(RO) : Status
  5011. * Host Error : 0x08
  5012. * Int_RAM Error : 0x04
  5013. * RISC Error : 0x02
  5014. * SCSI Error : 0x01
  5015. * No Error : 0x00
  5016. *
  5017. * Note: RAM BIST code should be put right here, before loading the
  5018. * microcode and after saving the RISC memory BIOS region.
  5019. */
  5020. /*
  5021. * LRAM Pre-test
  5022. *
  5023. * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
  5024. * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
  5025. * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
  5026. * to NORMAL_MODE, return an error too.
  5027. */
  5028. for (i = 0; i < 2; i++) {
  5029. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
  5030. mdelay(10); /* Wait for 10ms before reading back. */
  5031. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  5032. if ((byte & RAM_TEST_DONE) == 0
  5033. || (byte & 0x0F) != PRE_TEST_VALUE) {
  5034. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  5035. return ADV_ERROR;
  5036. }
  5037. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  5038. mdelay(10); /* Wait for 10ms before reading back. */
  5039. if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
  5040. != NORMAL_VALUE) {
  5041. asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST;
  5042. return ADV_ERROR;
  5043. }
  5044. }
  5045. /*
  5046. * LRAM Test - It takes about 1.5 ms to run through the test.
  5047. *
  5048. * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
  5049. * If Done bit not set or Status not 0, save register byte, set the
  5050. * err_code, and return an error.
  5051. */
  5052. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
  5053. mdelay(10); /* Wait for 10ms before checking status. */
  5054. byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
  5055. if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
  5056. /* Get here if Done bit not set or Status not 0. */
  5057. asc_dvc->bist_err_code = byte; /* for BIOS display message */
  5058. asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST;
  5059. return ADV_ERROR;
  5060. }
  5061. /* We need to reset back to normal mode after LRAM test passes. */
  5062. AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
  5063. err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev);
  5064. if (err) {
  5065. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  5066. fwname, err);
  5067. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  5068. return err;
  5069. }
  5070. if (fw->size < 4) {
  5071. printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
  5072. fw->size, fwname);
  5073. release_firmware(fw);
  5074. asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM;
  5075. return -EINVAL;
  5076. }
  5077. chksum = (fw->data[3] << 24) | (fw->data[2] << 16) |
  5078. (fw->data[1] << 8) | fw->data[0];
  5079. asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4],
  5080. fw->size - 4, ADV_38C1600_MEMSIZE,
  5081. chksum);
  5082. release_firmware(fw);
  5083. if (asc_dvc->err_code)
  5084. return ADV_ERROR;
  5085. /*
  5086. * Restore the RISC memory BIOS region.
  5087. */
  5088. for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) {
  5089. AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i),
  5090. bios_mem[i]);
  5091. }
  5092. /*
  5093. * Calculate and write the microcode code checksum to the microcode
  5094. * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
  5095. */
  5096. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
  5097. AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
  5098. code_sum = 0;
  5099. AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
  5100. for (word = begin_addr; word < end_addr; word += 2) {
  5101. code_sum += AdvReadWordAutoIncLram(iop_base);
  5102. }
  5103. AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
  5104. /*
  5105. * Read microcode version and date.
  5106. */
  5107. AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE,
  5108. asc_dvc->cfg->mcode_date);
  5109. AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM,
  5110. asc_dvc->cfg->mcode_version);
  5111. /*
  5112. * Set the chip type to indicate the ASC38C1600.
  5113. */
  5114. AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C1600);
  5115. /*
  5116. * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
  5117. * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
  5118. * cable detection and then we are able to read C_DET[3:0].
  5119. *
  5120. * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
  5121. * Microcode Default Value' section below.
  5122. */
  5123. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  5124. AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1,
  5125. scsi_cfg1 | DIS_TERM_DRV);
  5126. /*
  5127. * If the PCI Configuration Command Register "Parity Error Response
  5128. * Control" Bit was clear (0), then set the microcode variable
  5129. * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
  5130. * to ignore DMA parity errors.
  5131. */
  5132. if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) {
  5133. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5134. word |= CONTROL_FLAG_IGNORE_PERR;
  5135. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5136. }
  5137. /*
  5138. * If the BIOS control flag AIPP (Asynchronous Information
  5139. * Phase Protection) disable bit is not set, then set the firmware
  5140. * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable
  5141. * AIPP checking and encoding.
  5142. */
  5143. if ((asc_dvc->bios_ctrl & BIOS_CTRL_AIPP_DIS) == 0) {
  5144. AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5145. word |= CONTROL_FLAG_ENABLE_AIPP;
  5146. AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
  5147. }
  5148. /*
  5149. * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4],
  5150. * and START_CTL_TH [3:2].
  5151. */
  5152. AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
  5153. FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
  5154. /*
  5155. * Microcode operating variables for WDTR, SDTR, and command tag
  5156. * queuing will be set in slave_configure() based on what a
  5157. * device reports it is capable of in Inquiry byte 7.
  5158. *
  5159. * If SCSI Bus Resets have been disabled, then directly set
  5160. * SDTR and WDTR from the EEPROM configuration. This will allow
  5161. * the BIOS and warm boot to work without a SCSI bus hang on
  5162. * the Inquiry caused by host and target mismatched DTR values.
  5163. * Without the SCSI Bus Reset, before an Inquiry a device can't
  5164. * be assumed to be in Asynchronous, Narrow mode.
  5165. */
  5166. if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
  5167. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE,
  5168. asc_dvc->wdtr_able);
  5169. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE,
  5170. asc_dvc->sdtr_able);
  5171. }
  5172. /*
  5173. * Set microcode operating variables for DISC and SDTR_SPEED1,
  5174. * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
  5175. * configuration values.
  5176. *
  5177. * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
  5178. * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
  5179. * without determining here whether the device supports SDTR.
  5180. */
  5181. AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE,
  5182. asc_dvc->cfg->disc_enable);
  5183. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
  5184. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
  5185. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
  5186. AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
  5187. /*
  5188. * Set SCSI_CFG0 Microcode Default Value.
  5189. *
  5190. * The microcode will set the SCSI_CFG0 register using this value
  5191. * after it is started below.
  5192. */
  5193. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
  5194. PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
  5195. asc_dvc->chip_scsi_id);
  5196. /*
  5197. * Calculate SCSI_CFG1 Microcode Default Value.
  5198. *
  5199. * The microcode will set the SCSI_CFG1 register using this value
  5200. * after it is started below.
  5201. *
  5202. * Each ASC-38C1600 function has only two cable detect bits.
  5203. * The bus mode override bits are in IOPB_SOFT_OVER_WR.
  5204. */
  5205. scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
  5206. /*
  5207. * If the cable is reversed all of the SCSI_CTRL register signals
  5208. * will be set. Check for and return an error if this condition is
  5209. * found.
  5210. */
  5211. if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) {
  5212. asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
  5213. return ADV_ERROR;
  5214. }
  5215. /*
  5216. * Each ASC-38C1600 function has two connectors. Only an HVD device
  5217. * can not be connected to either connector. An LVD device or SE device
  5218. * may be connected to either connecor. If an SE device is connected,
  5219. * then at most Ultra speed (20 Mhz) can be used on both connectors.
  5220. *
  5221. * If an HVD device is attached, return an error.
  5222. */
  5223. if (scsi_cfg1 & HVD) {
  5224. asc_dvc->err_code |= ASC_IERR_HVD_DEVICE;
  5225. return ADV_ERROR;
  5226. }
  5227. /*
  5228. * Each function in the ASC-38C1600 uses only the SE cable detect and
  5229. * termination because there are two connectors for each function. Each
  5230. * function may use either LVD or SE mode. Corresponding the SE automatic
  5231. * termination control EEPROM bits are used for each function. Each
  5232. * function has its own EEPROM. If SE automatic control is enabled for
  5233. * the function, then set the termination value based on a table listed
  5234. * in a_condor.h.
  5235. *
  5236. * If manual termination is specified in the EEPROM for the function,
  5237. * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is
  5238. * ready to be 'ored' into SCSI_CFG1.
  5239. */
  5240. if ((asc_dvc->cfg->termination & TERM_SE) == 0) {
  5241. struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
  5242. /* SE automatic termination control is enabled. */
  5243. switch (scsi_cfg1 & C_DET_SE) {
  5244. /* TERM_SE_HI: on, TERM_SE_LO: on */
  5245. case 0x1:
  5246. case 0x2:
  5247. case 0x3:
  5248. asc_dvc->cfg->termination |= TERM_SE;
  5249. break;
  5250. case 0x0:
  5251. if (PCI_FUNC(pdev->devfn) == 0) {
  5252. /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */
  5253. } else {
  5254. /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */
  5255. asc_dvc->cfg->termination |= TERM_SE_HI;
  5256. }
  5257. break;
  5258. }
  5259. }
  5260. /*
  5261. * Clear any set TERM_SE bits.
  5262. */
  5263. scsi_cfg1 &= ~TERM_SE;
  5264. /*
  5265. * Invert the TERM_SE bits and then set 'scsi_cfg1'.
  5266. */
  5267. scsi_cfg1 |= (~asc_dvc->cfg->termination & TERM_SE);
  5268. /*
  5269. * Clear Big Endian and Terminator Polarity bits and set possibly
  5270. * modified termination control bits in the Microcode SCSI_CFG1
  5271. * Register Value.
  5272. *
  5273. * Big Endian bit is not used even on big endian machines.
  5274. */
  5275. scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL);
  5276. /*
  5277. * Set SCSI_CFG1 Microcode Default Value
  5278. *
  5279. * Set possibly modified termination control bits in the Microcode
  5280. * SCSI_CFG1 Register Value.
  5281. *
  5282. * The microcode will set the SCSI_CFG1 register using this value
  5283. * after it is started below.
  5284. */
  5285. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
  5286. /*
  5287. * Set MEM_CFG Microcode Default Value
  5288. *
  5289. * The microcode will set the MEM_CFG register using this value
  5290. * after it is started below.
  5291. *
  5292. * MEM_CFG may be accessed as a word or byte, but only bits 0-7
  5293. * are defined.
  5294. *
  5295. * ASC-38C1600 has 32KB internal memory.
  5296. *
  5297. * XXX - Since ASC38C1600 Rev.3 has a Local RAM failure issue, we come
  5298. * out a special 16K Adv Library and Microcode version. After the issue
  5299. * resolved, we should turn back to the 32K support. Both a_condor.h and
  5300. * mcode.sas files also need to be updated.
  5301. *
  5302. * AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5303. * BIOS_EN | RAM_SZ_32KB);
  5304. */
  5305. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
  5306. BIOS_EN | RAM_SZ_16KB);
  5307. /*
  5308. * Set SEL_MASK Microcode Default Value
  5309. *
  5310. * The microcode will set the SEL_MASK register using this value
  5311. * after it is started below.
  5312. */
  5313. AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
  5314. ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
  5315. AdvBuildCarrierFreelist(asc_dvc);
  5316. /*
  5317. * Set-up the Host->RISC Initiator Command Queue (ICQ).
  5318. */
  5319. if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL) {
  5320. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5321. return ADV_ERROR;
  5322. }
  5323. asc_dvc->carr_freelist = (ADV_CARR_T *)
  5324. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
  5325. /*
  5326. * The first command issued will be placed in the stopper carrier.
  5327. */
  5328. asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  5329. /*
  5330. * Set RISC ICQ physical address start value. Initialize the
  5331. * COMMA register to the same value otherwise the RISC will
  5332. * prematurely detect a command is available.
  5333. */
  5334. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
  5335. AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
  5336. le32_to_cpu(asc_dvc->icq_sp->carr_pa));
  5337. /*
  5338. * Set-up the RISC->Host Initiator Response Queue (IRQ).
  5339. */
  5340. if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL) {
  5341. asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
  5342. return ADV_ERROR;
  5343. }
  5344. asc_dvc->carr_freelist = (ADV_CARR_T *)
  5345. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
  5346. /*
  5347. * The first command completed by the RISC will be placed in
  5348. * the stopper.
  5349. *
  5350. * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
  5351. * completed the RISC will set the ASC_RQ_STOPPER bit.
  5352. */
  5353. asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  5354. /*
  5355. * Set RISC IRQ physical address start value.
  5356. */
  5357. AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
  5358. asc_dvc->carr_pending_cnt = 0;
  5359. AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
  5360. (ADV_INTR_ENABLE_HOST_INTR |
  5361. ADV_INTR_ENABLE_GLOBAL_INTR));
  5362. AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
  5363. AdvWriteWordRegister(iop_base, IOPW_PC, word);
  5364. /* finally, finally, gentlemen, start your engine */
  5365. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
  5366. /*
  5367. * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
  5368. * Resets should be performed. The RISC has to be running
  5369. * to issue a SCSI Bus Reset.
  5370. */
  5371. if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
  5372. /*
  5373. * If the BIOS Signature is present in memory, restore the
  5374. * per TID microcode operating variables.
  5375. */
  5376. if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] ==
  5377. 0x55AA) {
  5378. /*
  5379. * Restore per TID negotiated values.
  5380. */
  5381. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5382. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5383. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5384. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  5385. tagqng_able);
  5386. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  5387. AdvWriteByteLram(iop_base,
  5388. ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5389. max_cmd[tid]);
  5390. }
  5391. } else {
  5392. if (AdvResetSB(asc_dvc) != ADV_TRUE) {
  5393. warn_code = ASC_WARN_BUSRESET_ERROR;
  5394. }
  5395. }
  5396. }
  5397. return warn_code;
  5398. }
  5399. /*
  5400. * Reset chip and SCSI Bus.
  5401. *
  5402. * Return Value:
  5403. * ADV_TRUE(1) - Chip re-initialization and SCSI Bus Reset successful.
  5404. * ADV_FALSE(0) - Chip re-initialization and SCSI Bus Reset failure.
  5405. */
  5406. static int AdvResetChipAndSB(ADV_DVC_VAR *asc_dvc)
  5407. {
  5408. int status;
  5409. ushort wdtr_able, sdtr_able, tagqng_able;
  5410. ushort ppr_able = 0;
  5411. uchar tid, max_cmd[ADV_MAX_TID + 1];
  5412. AdvPortAddr iop_base;
  5413. ushort bios_sig;
  5414. iop_base = asc_dvc->iop_base;
  5415. /*
  5416. * Save current per TID negotiated values.
  5417. */
  5418. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5419. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5420. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5421. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5422. }
  5423. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5424. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5425. AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5426. max_cmd[tid]);
  5427. }
  5428. /*
  5429. * Force the AdvInitAsc3550/38C0800Driver() function to
  5430. * perform a SCSI Bus Reset by clearing the BIOS signature word.
  5431. * The initialization functions assumes a SCSI Bus Reset is not
  5432. * needed if the BIOS signature word is present.
  5433. */
  5434. AdvReadWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
  5435. AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, 0);
  5436. /*
  5437. * Stop chip and reset it.
  5438. */
  5439. AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_STOP);
  5440. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_RESET);
  5441. mdelay(100);
  5442. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  5443. ADV_CTRL_REG_CMD_WR_IO_REG);
  5444. /*
  5445. * Reset Adv Library error code, if any, and try
  5446. * re-initializing the chip.
  5447. */
  5448. asc_dvc->err_code = 0;
  5449. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5450. status = AdvInitAsc38C1600Driver(asc_dvc);
  5451. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  5452. status = AdvInitAsc38C0800Driver(asc_dvc);
  5453. } else {
  5454. status = AdvInitAsc3550Driver(asc_dvc);
  5455. }
  5456. /* Translate initialization return value to status value. */
  5457. if (status == 0) {
  5458. status = ADV_TRUE;
  5459. } else {
  5460. status = ADV_FALSE;
  5461. }
  5462. /*
  5463. * Restore the BIOS signature word.
  5464. */
  5465. AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
  5466. /*
  5467. * Restore per TID negotiated values.
  5468. */
  5469. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
  5470. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
  5471. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  5472. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
  5473. }
  5474. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
  5475. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  5476. AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
  5477. max_cmd[tid]);
  5478. }
  5479. return status;
  5480. }
  5481. /*
  5482. * adv_async_callback() - Adv Library asynchronous event callback function.
  5483. */
  5484. static void adv_async_callback(ADV_DVC_VAR *adv_dvc_varp, uchar code)
  5485. {
  5486. switch (code) {
  5487. case ADV_ASYNC_SCSI_BUS_RESET_DET:
  5488. /*
  5489. * The firmware detected a SCSI Bus reset.
  5490. */
  5491. ASC_DBG(0, "ADV_ASYNC_SCSI_BUS_RESET_DET\n");
  5492. break;
  5493. case ADV_ASYNC_RDMA_FAILURE:
  5494. /*
  5495. * Handle RDMA failure by resetting the SCSI Bus and
  5496. * possibly the chip if it is unresponsive. Log the error
  5497. * with a unique code.
  5498. */
  5499. ASC_DBG(0, "ADV_ASYNC_RDMA_FAILURE\n");
  5500. AdvResetChipAndSB(adv_dvc_varp);
  5501. break;
  5502. case ADV_HOST_SCSI_BUS_RESET:
  5503. /*
  5504. * Host generated SCSI bus reset occurred.
  5505. */
  5506. ASC_DBG(0, "ADV_HOST_SCSI_BUS_RESET\n");
  5507. break;
  5508. default:
  5509. ASC_DBG(0, "unknown code 0x%x\n", code);
  5510. break;
  5511. }
  5512. }
  5513. /*
  5514. * adv_isr_callback() - Second Level Interrupt Handler called by AdvISR().
  5515. *
  5516. * Callback function for the Wide SCSI Adv Library.
  5517. */
  5518. static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
  5519. {
  5520. struct asc_board *boardp;
  5521. adv_req_t *reqp;
  5522. adv_sgblk_t *sgblkp;
  5523. struct scsi_cmnd *scp;
  5524. struct Scsi_Host *shost;
  5525. ADV_DCNT resid_cnt;
  5526. ASC_DBG(1, "adv_dvc_varp 0x%lx, scsiqp 0x%lx\n",
  5527. (ulong)adv_dvc_varp, (ulong)scsiqp);
  5528. ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
  5529. /*
  5530. * Get the adv_req_t structure for the command that has been
  5531. * completed. The adv_req_t structure actually contains the
  5532. * completed ADV_SCSI_REQ_Q structure.
  5533. */
  5534. reqp = (adv_req_t *)ADV_U32_TO_VADDR(scsiqp->srb_ptr);
  5535. ASC_DBG(1, "reqp 0x%lx\n", (ulong)reqp);
  5536. if (reqp == NULL) {
  5537. ASC_PRINT("adv_isr_callback: reqp is NULL\n");
  5538. return;
  5539. }
  5540. /*
  5541. * Get the struct scsi_cmnd structure and Scsi_Host structure for the
  5542. * command that has been completed.
  5543. *
  5544. * Note: The adv_req_t request structure and adv_sgblk_t structure,
  5545. * if any, are dropped, because a board structure pointer can not be
  5546. * determined.
  5547. */
  5548. scp = reqp->cmndp;
  5549. ASC_DBG(1, "scp 0x%p\n", scp);
  5550. if (scp == NULL) {
  5551. ASC_PRINT
  5552. ("adv_isr_callback: scp is NULL; adv_req_t dropped.\n");
  5553. return;
  5554. }
  5555. ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
  5556. shost = scp->device->host;
  5557. ASC_STATS(shost, callback);
  5558. ASC_DBG(1, "shost 0x%p\n", shost);
  5559. boardp = shost_priv(shost);
  5560. BUG_ON(adv_dvc_varp != &boardp->dvc_var.adv_dvc_var);
  5561. /*
  5562. * 'done_status' contains the command's ending status.
  5563. */
  5564. switch (scsiqp->done_status) {
  5565. case QD_NO_ERROR:
  5566. ASC_DBG(2, "QD_NO_ERROR\n");
  5567. scp->result = 0;
  5568. /*
  5569. * Check for an underrun condition.
  5570. *
  5571. * If there was no error and an underrun condition, then
  5572. * then return the number of underrun bytes.
  5573. */
  5574. resid_cnt = le32_to_cpu(scsiqp->data_cnt);
  5575. if (scsi_bufflen(scp) != 0 && resid_cnt != 0 &&
  5576. resid_cnt <= scsi_bufflen(scp)) {
  5577. ASC_DBG(1, "underrun condition %lu bytes\n",
  5578. (ulong)resid_cnt);
  5579. scsi_set_resid(scp, resid_cnt);
  5580. }
  5581. break;
  5582. case QD_WITH_ERROR:
  5583. ASC_DBG(2, "QD_WITH_ERROR\n");
  5584. switch (scsiqp->host_status) {
  5585. case QHSTA_NO_ERROR:
  5586. if (scsiqp->scsi_status == SAM_STAT_CHECK_CONDITION) {
  5587. ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
  5588. ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
  5589. SCSI_SENSE_BUFFERSIZE);
  5590. /*
  5591. * Note: The 'status_byte()' macro used by
  5592. * target drivers defined in scsi.h shifts the
  5593. * status byte returned by host drivers right
  5594. * by 1 bit. This is why target drivers also
  5595. * use right shifted status byte definitions.
  5596. * For instance target drivers use
  5597. * CHECK_CONDITION, defined to 0x1, instead of
  5598. * the SCSI defined check condition value of
  5599. * 0x2. Host drivers are supposed to return
  5600. * the status byte as it is defined by SCSI.
  5601. */
  5602. scp->result = DRIVER_BYTE(DRIVER_SENSE) |
  5603. STATUS_BYTE(scsiqp->scsi_status);
  5604. } else {
  5605. scp->result = STATUS_BYTE(scsiqp->scsi_status);
  5606. }
  5607. break;
  5608. default:
  5609. /* Some other QHSTA error occurred. */
  5610. ASC_DBG(1, "host_status 0x%x\n", scsiqp->host_status);
  5611. scp->result = HOST_BYTE(DID_BAD_TARGET);
  5612. break;
  5613. }
  5614. break;
  5615. case QD_ABORTED_BY_HOST:
  5616. ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
  5617. scp->result =
  5618. HOST_BYTE(DID_ABORT) | STATUS_BYTE(scsiqp->scsi_status);
  5619. break;
  5620. default:
  5621. ASC_DBG(1, "done_status 0x%x\n", scsiqp->done_status);
  5622. scp->result =
  5623. HOST_BYTE(DID_ERROR) | STATUS_BYTE(scsiqp->scsi_status);
  5624. break;
  5625. }
  5626. /*
  5627. * If the 'init_tidmask' bit isn't already set for the target and the
  5628. * current request finished normally, then set the bit for the target
  5629. * to indicate that a device is present.
  5630. */
  5631. if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
  5632. scsiqp->done_status == QD_NO_ERROR &&
  5633. scsiqp->host_status == QHSTA_NO_ERROR) {
  5634. boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
  5635. }
  5636. asc_scsi_done(scp);
  5637. /*
  5638. * Free all 'adv_sgblk_t' structures allocated for the request.
  5639. */
  5640. while ((sgblkp = reqp->sgblkp) != NULL) {
  5641. /* Remove 'sgblkp' from the request list. */
  5642. reqp->sgblkp = sgblkp->next_sgblkp;
  5643. /* Add 'sgblkp' to the board free list. */
  5644. sgblkp->next_sgblkp = boardp->adv_sgblkp;
  5645. boardp->adv_sgblkp = sgblkp;
  5646. }
  5647. /*
  5648. * Free the adv_req_t structure used with the command by adding
  5649. * it back to the board free list.
  5650. */
  5651. reqp->next_reqp = boardp->adv_reqp;
  5652. boardp->adv_reqp = reqp;
  5653. ASC_DBG(1, "done\n");
  5654. }
  5655. /*
  5656. * Adv Library Interrupt Service Routine
  5657. *
  5658. * This function is called by a driver's interrupt service routine.
  5659. * The function disables and re-enables interrupts.
  5660. *
  5661. * When a microcode idle command is completed, the ADV_DVC_VAR
  5662. * 'idle_cmd_done' field is set to ADV_TRUE.
  5663. *
  5664. * Note: AdvISR() can be called when interrupts are disabled or even
  5665. * when there is no hardware interrupt condition present. It will
  5666. * always check for completed idle commands and microcode requests.
  5667. * This is an important feature that shouldn't be changed because it
  5668. * allows commands to be completed from polling mode loops.
  5669. *
  5670. * Return:
  5671. * ADV_TRUE(1) - interrupt was pending
  5672. * ADV_FALSE(0) - no interrupt was pending
  5673. */
  5674. static int AdvISR(ADV_DVC_VAR *asc_dvc)
  5675. {
  5676. AdvPortAddr iop_base;
  5677. uchar int_stat;
  5678. ushort target_bit;
  5679. ADV_CARR_T *free_carrp;
  5680. ADV_VADDR irq_next_vpa;
  5681. ADV_SCSI_REQ_Q *scsiq;
  5682. iop_base = asc_dvc->iop_base;
  5683. /* Reading the register clears the interrupt. */
  5684. int_stat = AdvReadByteRegister(iop_base, IOPB_INTR_STATUS_REG);
  5685. if ((int_stat & (ADV_INTR_STATUS_INTRA | ADV_INTR_STATUS_INTRB |
  5686. ADV_INTR_STATUS_INTRC)) == 0) {
  5687. return ADV_FALSE;
  5688. }
  5689. /*
  5690. * Notify the driver of an asynchronous microcode condition by
  5691. * calling the adv_async_callback function. The function
  5692. * is passed the microcode ASC_MC_INTRB_CODE byte value.
  5693. */
  5694. if (int_stat & ADV_INTR_STATUS_INTRB) {
  5695. uchar intrb_code;
  5696. AdvReadByteLram(iop_base, ASC_MC_INTRB_CODE, intrb_code);
  5697. if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
  5698. asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  5699. if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE &&
  5700. asc_dvc->carr_pending_cnt != 0) {
  5701. AdvWriteByteRegister(iop_base, IOPB_TICKLE,
  5702. ADV_TICKLE_A);
  5703. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  5704. AdvWriteByteRegister(iop_base,
  5705. IOPB_TICKLE,
  5706. ADV_TICKLE_NOP);
  5707. }
  5708. }
  5709. }
  5710. adv_async_callback(asc_dvc, intrb_code);
  5711. }
  5712. /*
  5713. * Check if the IRQ stopper carrier contains a completed request.
  5714. */
  5715. while (((irq_next_vpa =
  5716. le32_to_cpu(asc_dvc->irq_sp->next_vpa)) & ASC_RQ_DONE) != 0) {
  5717. /*
  5718. * Get a pointer to the newly completed ADV_SCSI_REQ_Q structure.
  5719. * The RISC will have set 'areq_vpa' to a virtual address.
  5720. *
  5721. * The firmware will have copied the ASC_SCSI_REQ_Q.scsiq_ptr
  5722. * field to the carrier ADV_CARR_T.areq_vpa field. The conversion
  5723. * below complements the conversion of ASC_SCSI_REQ_Q.scsiq_ptr'
  5724. * in AdvExeScsiQueue().
  5725. */
  5726. scsiq = (ADV_SCSI_REQ_Q *)
  5727. ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->areq_vpa));
  5728. /*
  5729. * Request finished with good status and the queue was not
  5730. * DMAed to host memory by the firmware. Set all status fields
  5731. * to indicate good status.
  5732. */
  5733. if ((irq_next_vpa & ASC_RQ_GOOD) != 0) {
  5734. scsiq->done_status = QD_NO_ERROR;
  5735. scsiq->host_status = scsiq->scsi_status = 0;
  5736. scsiq->data_cnt = 0L;
  5737. }
  5738. /*
  5739. * Advance the stopper pointer to the next carrier
  5740. * ignoring the lower four bits. Free the previous
  5741. * stopper carrier.
  5742. */
  5743. free_carrp = asc_dvc->irq_sp;
  5744. asc_dvc->irq_sp = (ADV_CARR_T *)
  5745. ADV_U32_TO_VADDR(ASC_GET_CARRP(irq_next_vpa));
  5746. free_carrp->next_vpa =
  5747. cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
  5748. asc_dvc->carr_freelist = free_carrp;
  5749. asc_dvc->carr_pending_cnt--;
  5750. target_bit = ADV_TID_TO_TIDMASK(scsiq->target_id);
  5751. /*
  5752. * Clear request microcode control flag.
  5753. */
  5754. scsiq->cntl = 0;
  5755. /*
  5756. * Notify the driver of the completed request by passing
  5757. * the ADV_SCSI_REQ_Q pointer to its callback function.
  5758. */
  5759. scsiq->a_flag |= ADV_SCSIQ_DONE;
  5760. adv_isr_callback(asc_dvc, scsiq);
  5761. /*
  5762. * Note: After the driver callback function is called, 'scsiq'
  5763. * can no longer be referenced.
  5764. *
  5765. * Fall through and continue processing other completed
  5766. * requests...
  5767. */
  5768. }
  5769. return ADV_TRUE;
  5770. }
  5771. static int AscSetLibErrorCode(ASC_DVC_VAR *asc_dvc, ushort err_code)
  5772. {
  5773. if (asc_dvc->err_code == 0) {
  5774. asc_dvc->err_code = err_code;
  5775. AscWriteLramWord(asc_dvc->iop_base, ASCV_ASCDVC_ERR_CODE_W,
  5776. err_code);
  5777. }
  5778. return err_code;
  5779. }
  5780. static void AscAckInterrupt(PortAddr iop_base)
  5781. {
  5782. uchar host_flag;
  5783. uchar risc_flag;
  5784. ushort loop;
  5785. loop = 0;
  5786. do {
  5787. risc_flag = AscReadLramByte(iop_base, ASCV_RISC_FLAG_B);
  5788. if (loop++ > 0x7FFF) {
  5789. break;
  5790. }
  5791. } while ((risc_flag & ASC_RISC_FLAG_GEN_INT) != 0);
  5792. host_flag =
  5793. AscReadLramByte(iop_base,
  5794. ASCV_HOST_FLAG_B) & (~ASC_HOST_FLAG_ACK_INT);
  5795. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
  5796. (uchar)(host_flag | ASC_HOST_FLAG_ACK_INT));
  5797. AscSetChipStatus(iop_base, CIW_INT_ACK);
  5798. loop = 0;
  5799. while (AscGetChipStatus(iop_base) & CSW_INT_PENDING) {
  5800. AscSetChipStatus(iop_base, CIW_INT_ACK);
  5801. if (loop++ > 3) {
  5802. break;
  5803. }
  5804. }
  5805. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
  5806. }
  5807. static uchar AscGetSynPeriodIndex(ASC_DVC_VAR *asc_dvc, uchar syn_time)
  5808. {
  5809. const uchar *period_table;
  5810. int max_index;
  5811. int min_index;
  5812. int i;
  5813. period_table = asc_dvc->sdtr_period_tbl;
  5814. max_index = (int)asc_dvc->max_sdtr_index;
  5815. min_index = (int)asc_dvc->min_sdtr_index;
  5816. if ((syn_time <= period_table[max_index])) {
  5817. for (i = min_index; i < (max_index - 1); i++) {
  5818. if (syn_time <= period_table[i]) {
  5819. return (uchar)i;
  5820. }
  5821. }
  5822. return (uchar)max_index;
  5823. } else {
  5824. return (uchar)(max_index + 1);
  5825. }
  5826. }
  5827. static uchar
  5828. AscMsgOutSDTR(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar sdtr_offset)
  5829. {
  5830. EXT_MSG sdtr_buf;
  5831. uchar sdtr_period_index;
  5832. PortAddr iop_base;
  5833. iop_base = asc_dvc->iop_base;
  5834. sdtr_buf.msg_type = EXTENDED_MESSAGE;
  5835. sdtr_buf.msg_len = MS_SDTR_LEN;
  5836. sdtr_buf.msg_req = EXTENDED_SDTR;
  5837. sdtr_buf.xfer_period = sdtr_period;
  5838. sdtr_offset &= ASC_SYN_MAX_OFFSET;
  5839. sdtr_buf.req_ack_offset = sdtr_offset;
  5840. sdtr_period_index = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
  5841. if (sdtr_period_index <= asc_dvc->max_sdtr_index) {
  5842. AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
  5843. (uchar *)&sdtr_buf,
  5844. sizeof(EXT_MSG) >> 1);
  5845. return ((sdtr_period_index << 4) | sdtr_offset);
  5846. } else {
  5847. sdtr_buf.req_ack_offset = 0;
  5848. AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG,
  5849. (uchar *)&sdtr_buf,
  5850. sizeof(EXT_MSG) >> 1);
  5851. return 0;
  5852. }
  5853. }
  5854. static uchar
  5855. AscCalSDTRData(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar syn_offset)
  5856. {
  5857. uchar byte;
  5858. uchar sdtr_period_ix;
  5859. sdtr_period_ix = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
  5860. if (sdtr_period_ix > asc_dvc->max_sdtr_index)
  5861. return 0xFF;
  5862. byte = (sdtr_period_ix << 4) | (syn_offset & ASC_SYN_MAX_OFFSET);
  5863. return byte;
  5864. }
  5865. static int AscSetChipSynRegAtID(PortAddr iop_base, uchar id, uchar sdtr_data)
  5866. {
  5867. ASC_SCSI_BIT_ID_TYPE org_id;
  5868. int i;
  5869. int sta = TRUE;
  5870. AscSetBank(iop_base, 1);
  5871. org_id = AscReadChipDvcID(iop_base);
  5872. for (i = 0; i <= ASC_MAX_TID; i++) {
  5873. if (org_id == (0x01 << i))
  5874. break;
  5875. }
  5876. org_id = (ASC_SCSI_BIT_ID_TYPE) i;
  5877. AscWriteChipDvcID(iop_base, id);
  5878. if (AscReadChipDvcID(iop_base) == (0x01 << id)) {
  5879. AscSetBank(iop_base, 0);
  5880. AscSetChipSyn(iop_base, sdtr_data);
  5881. if (AscGetChipSyn(iop_base) != sdtr_data) {
  5882. sta = FALSE;
  5883. }
  5884. } else {
  5885. sta = FALSE;
  5886. }
  5887. AscSetBank(iop_base, 1);
  5888. AscWriteChipDvcID(iop_base, org_id);
  5889. AscSetBank(iop_base, 0);
  5890. return (sta);
  5891. }
  5892. static void AscSetChipSDTR(PortAddr iop_base, uchar sdtr_data, uchar tid_no)
  5893. {
  5894. AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
  5895. AscPutMCodeSDTRDoneAtID(iop_base, tid_no, sdtr_data);
  5896. }
  5897. static int AscIsrChipHalted(ASC_DVC_VAR *asc_dvc)
  5898. {
  5899. EXT_MSG ext_msg;
  5900. EXT_MSG out_msg;
  5901. ushort halt_q_addr;
  5902. int sdtr_accept;
  5903. ushort int_halt_code;
  5904. ASC_SCSI_BIT_ID_TYPE scsi_busy;
  5905. ASC_SCSI_BIT_ID_TYPE target_id;
  5906. PortAddr iop_base;
  5907. uchar tag_code;
  5908. uchar q_status;
  5909. uchar halt_qp;
  5910. uchar sdtr_data;
  5911. uchar target_ix;
  5912. uchar q_cntl, tid_no;
  5913. uchar cur_dvc_qng;
  5914. uchar asyn_sdtr;
  5915. uchar scsi_status;
  5916. struct asc_board *boardp;
  5917. BUG_ON(!asc_dvc->drv_ptr);
  5918. boardp = asc_dvc->drv_ptr;
  5919. iop_base = asc_dvc->iop_base;
  5920. int_halt_code = AscReadLramWord(iop_base, ASCV_HALTCODE_W);
  5921. halt_qp = AscReadLramByte(iop_base, ASCV_CURCDB_B);
  5922. halt_q_addr = ASC_QNO_TO_QADDR(halt_qp);
  5923. target_ix = AscReadLramByte(iop_base,
  5924. (ushort)(halt_q_addr +
  5925. (ushort)ASC_SCSIQ_B_TARGET_IX));
  5926. q_cntl = AscReadLramByte(iop_base,
  5927. (ushort)(halt_q_addr + (ushort)ASC_SCSIQ_B_CNTL));
  5928. tid_no = ASC_TIX_TO_TID(target_ix);
  5929. target_id = (uchar)ASC_TID_TO_TARGET_ID(tid_no);
  5930. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  5931. asyn_sdtr = ASYN_SDTR_DATA_FIX_PCI_REV_AB;
  5932. } else {
  5933. asyn_sdtr = 0;
  5934. }
  5935. if (int_halt_code == ASC_HALT_DISABLE_ASYN_USE_SYN_FIX) {
  5936. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  5937. AscSetChipSDTR(iop_base, 0, tid_no);
  5938. boardp->sdtr_data[tid_no] = 0;
  5939. }
  5940. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5941. return (0);
  5942. } else if (int_halt_code == ASC_HALT_ENABLE_ASYN_USE_SYN_FIX) {
  5943. if (asc_dvc->pci_fix_asyn_xfer & target_id) {
  5944. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  5945. boardp->sdtr_data[tid_no] = asyn_sdtr;
  5946. }
  5947. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  5948. return (0);
  5949. } else if (int_halt_code == ASC_HALT_EXTMSG_IN) {
  5950. AscMemWordCopyPtrFromLram(iop_base,
  5951. ASCV_MSGIN_BEG,
  5952. (uchar *)&ext_msg,
  5953. sizeof(EXT_MSG) >> 1);
  5954. if (ext_msg.msg_type == EXTENDED_MESSAGE &&
  5955. ext_msg.msg_req == EXTENDED_SDTR &&
  5956. ext_msg.msg_len == MS_SDTR_LEN) {
  5957. sdtr_accept = TRUE;
  5958. if ((ext_msg.req_ack_offset > ASC_SYN_MAX_OFFSET)) {
  5959. sdtr_accept = FALSE;
  5960. ext_msg.req_ack_offset = ASC_SYN_MAX_OFFSET;
  5961. }
  5962. if ((ext_msg.xfer_period <
  5963. asc_dvc->sdtr_period_tbl[asc_dvc->min_sdtr_index])
  5964. || (ext_msg.xfer_period >
  5965. asc_dvc->sdtr_period_tbl[asc_dvc->
  5966. max_sdtr_index])) {
  5967. sdtr_accept = FALSE;
  5968. ext_msg.xfer_period =
  5969. asc_dvc->sdtr_period_tbl[asc_dvc->
  5970. min_sdtr_index];
  5971. }
  5972. if (sdtr_accept) {
  5973. sdtr_data =
  5974. AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
  5975. ext_msg.req_ack_offset);
  5976. if ((sdtr_data == 0xFF)) {
  5977. q_cntl |= QC_MSG_OUT;
  5978. asc_dvc->init_sdtr &= ~target_id;
  5979. asc_dvc->sdtr_done &= ~target_id;
  5980. AscSetChipSDTR(iop_base, asyn_sdtr,
  5981. tid_no);
  5982. boardp->sdtr_data[tid_no] = asyn_sdtr;
  5983. }
  5984. }
  5985. if (ext_msg.req_ack_offset == 0) {
  5986. q_cntl &= ~QC_MSG_OUT;
  5987. asc_dvc->init_sdtr &= ~target_id;
  5988. asc_dvc->sdtr_done &= ~target_id;
  5989. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  5990. } else {
  5991. if (sdtr_accept && (q_cntl & QC_MSG_OUT)) {
  5992. q_cntl &= ~QC_MSG_OUT;
  5993. asc_dvc->sdtr_done |= target_id;
  5994. asc_dvc->init_sdtr |= target_id;
  5995. asc_dvc->pci_fix_asyn_xfer &=
  5996. ~target_id;
  5997. sdtr_data =
  5998. AscCalSDTRData(asc_dvc,
  5999. ext_msg.xfer_period,
  6000. ext_msg.
  6001. req_ack_offset);
  6002. AscSetChipSDTR(iop_base, sdtr_data,
  6003. tid_no);
  6004. boardp->sdtr_data[tid_no] = sdtr_data;
  6005. } else {
  6006. q_cntl |= QC_MSG_OUT;
  6007. AscMsgOutSDTR(asc_dvc,
  6008. ext_msg.xfer_period,
  6009. ext_msg.req_ack_offset);
  6010. asc_dvc->pci_fix_asyn_xfer &=
  6011. ~target_id;
  6012. sdtr_data =
  6013. AscCalSDTRData(asc_dvc,
  6014. ext_msg.xfer_period,
  6015. ext_msg.
  6016. req_ack_offset);
  6017. AscSetChipSDTR(iop_base, sdtr_data,
  6018. tid_no);
  6019. boardp->sdtr_data[tid_no] = sdtr_data;
  6020. asc_dvc->sdtr_done |= target_id;
  6021. asc_dvc->init_sdtr |= target_id;
  6022. }
  6023. }
  6024. AscWriteLramByte(iop_base,
  6025. (ushort)(halt_q_addr +
  6026. (ushort)ASC_SCSIQ_B_CNTL),
  6027. q_cntl);
  6028. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6029. return (0);
  6030. } else if (ext_msg.msg_type == EXTENDED_MESSAGE &&
  6031. ext_msg.msg_req == EXTENDED_WDTR &&
  6032. ext_msg.msg_len == MS_WDTR_LEN) {
  6033. ext_msg.wdtr_width = 0;
  6034. AscMemWordCopyPtrToLram(iop_base,
  6035. ASCV_MSGOUT_BEG,
  6036. (uchar *)&ext_msg,
  6037. sizeof(EXT_MSG) >> 1);
  6038. q_cntl |= QC_MSG_OUT;
  6039. AscWriteLramByte(iop_base,
  6040. (ushort)(halt_q_addr +
  6041. (ushort)ASC_SCSIQ_B_CNTL),
  6042. q_cntl);
  6043. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6044. return (0);
  6045. } else {
  6046. ext_msg.msg_type = MESSAGE_REJECT;
  6047. AscMemWordCopyPtrToLram(iop_base,
  6048. ASCV_MSGOUT_BEG,
  6049. (uchar *)&ext_msg,
  6050. sizeof(EXT_MSG) >> 1);
  6051. q_cntl |= QC_MSG_OUT;
  6052. AscWriteLramByte(iop_base,
  6053. (ushort)(halt_q_addr +
  6054. (ushort)ASC_SCSIQ_B_CNTL),
  6055. q_cntl);
  6056. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6057. return (0);
  6058. }
  6059. } else if (int_halt_code == ASC_HALT_CHK_CONDITION) {
  6060. q_cntl |= QC_REQ_SENSE;
  6061. if ((asc_dvc->init_sdtr & target_id) != 0) {
  6062. asc_dvc->sdtr_done &= ~target_id;
  6063. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  6064. q_cntl |= QC_MSG_OUT;
  6065. AscMsgOutSDTR(asc_dvc,
  6066. asc_dvc->
  6067. sdtr_period_tbl[(sdtr_data >> 4) &
  6068. (uchar)(asc_dvc->
  6069. max_sdtr_index -
  6070. 1)],
  6071. (uchar)(sdtr_data & (uchar)
  6072. ASC_SYN_MAX_OFFSET));
  6073. }
  6074. AscWriteLramByte(iop_base,
  6075. (ushort)(halt_q_addr +
  6076. (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
  6077. tag_code = AscReadLramByte(iop_base,
  6078. (ushort)(halt_q_addr + (ushort)
  6079. ASC_SCSIQ_B_TAG_CODE));
  6080. tag_code &= 0xDC;
  6081. if ((asc_dvc->pci_fix_asyn_xfer & target_id)
  6082. && !(asc_dvc->pci_fix_asyn_xfer_always & target_id)
  6083. ) {
  6084. tag_code |= (ASC_TAG_FLAG_DISABLE_DISCONNECT
  6085. | ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX);
  6086. }
  6087. AscWriteLramByte(iop_base,
  6088. (ushort)(halt_q_addr +
  6089. (ushort)ASC_SCSIQ_B_TAG_CODE),
  6090. tag_code);
  6091. q_status = AscReadLramByte(iop_base,
  6092. (ushort)(halt_q_addr + (ushort)
  6093. ASC_SCSIQ_B_STATUS));
  6094. q_status |= (QS_READY | QS_BUSY);
  6095. AscWriteLramByte(iop_base,
  6096. (ushort)(halt_q_addr +
  6097. (ushort)ASC_SCSIQ_B_STATUS),
  6098. q_status);
  6099. scsi_busy = AscReadLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B);
  6100. scsi_busy &= ~target_id;
  6101. AscWriteLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B, scsi_busy);
  6102. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6103. return (0);
  6104. } else if (int_halt_code == ASC_HALT_SDTR_REJECTED) {
  6105. AscMemWordCopyPtrFromLram(iop_base,
  6106. ASCV_MSGOUT_BEG,
  6107. (uchar *)&out_msg,
  6108. sizeof(EXT_MSG) >> 1);
  6109. if ((out_msg.msg_type == EXTENDED_MESSAGE) &&
  6110. (out_msg.msg_len == MS_SDTR_LEN) &&
  6111. (out_msg.msg_req == EXTENDED_SDTR)) {
  6112. asc_dvc->init_sdtr &= ~target_id;
  6113. asc_dvc->sdtr_done &= ~target_id;
  6114. AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
  6115. boardp->sdtr_data[tid_no] = asyn_sdtr;
  6116. }
  6117. q_cntl &= ~QC_MSG_OUT;
  6118. AscWriteLramByte(iop_base,
  6119. (ushort)(halt_q_addr +
  6120. (ushort)ASC_SCSIQ_B_CNTL), q_cntl);
  6121. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6122. return (0);
  6123. } else if (int_halt_code == ASC_HALT_SS_QUEUE_FULL) {
  6124. scsi_status = AscReadLramByte(iop_base,
  6125. (ushort)((ushort)halt_q_addr +
  6126. (ushort)
  6127. ASC_SCSIQ_SCSI_STATUS));
  6128. cur_dvc_qng =
  6129. AscReadLramByte(iop_base,
  6130. (ushort)((ushort)ASC_QADR_BEG +
  6131. (ushort)target_ix));
  6132. if ((cur_dvc_qng > 0) && (asc_dvc->cur_dvc_qng[tid_no] > 0)) {
  6133. scsi_busy = AscReadLramByte(iop_base,
  6134. (ushort)ASCV_SCSIBUSY_B);
  6135. scsi_busy |= target_id;
  6136. AscWriteLramByte(iop_base,
  6137. (ushort)ASCV_SCSIBUSY_B, scsi_busy);
  6138. asc_dvc->queue_full_or_busy |= target_id;
  6139. if (scsi_status == SAM_STAT_TASK_SET_FULL) {
  6140. if (cur_dvc_qng > ASC_MIN_TAGGED_CMD) {
  6141. cur_dvc_qng -= 1;
  6142. asc_dvc->max_dvc_qng[tid_no] =
  6143. cur_dvc_qng;
  6144. AscWriteLramByte(iop_base,
  6145. (ushort)((ushort)
  6146. ASCV_MAX_DVC_QNG_BEG
  6147. + (ushort)
  6148. tid_no),
  6149. cur_dvc_qng);
  6150. /*
  6151. * Set the device queue depth to the
  6152. * number of active requests when the
  6153. * QUEUE FULL condition was encountered.
  6154. */
  6155. boardp->queue_full |= target_id;
  6156. boardp->queue_full_cnt[tid_no] =
  6157. cur_dvc_qng;
  6158. }
  6159. }
  6160. }
  6161. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6162. return (0);
  6163. }
  6164. #if CC_VERY_LONG_SG_LIST
  6165. else if (int_halt_code == ASC_HALT_HOST_COPY_SG_LIST_TO_RISC) {
  6166. uchar q_no;
  6167. ushort q_addr;
  6168. uchar sg_wk_q_no;
  6169. uchar first_sg_wk_q_no;
  6170. ASC_SCSI_Q *scsiq; /* Ptr to driver request. */
  6171. ASC_SG_HEAD *sg_head; /* Ptr to driver SG request. */
  6172. ASC_SG_LIST_Q scsi_sg_q; /* Structure written to queue. */
  6173. ushort sg_list_dwords;
  6174. ushort sg_entry_cnt;
  6175. uchar next_qp;
  6176. int i;
  6177. q_no = AscReadLramByte(iop_base, (ushort)ASCV_REQ_SG_LIST_QP);
  6178. if (q_no == ASC_QLINK_END)
  6179. return 0;
  6180. q_addr = ASC_QNO_TO_QADDR(q_no);
  6181. /*
  6182. * Convert the request's SRB pointer to a host ASC_SCSI_REQ
  6183. * structure pointer using a macro provided by the driver.
  6184. * The ASC_SCSI_REQ pointer provides a pointer to the
  6185. * host ASC_SG_HEAD structure.
  6186. */
  6187. /* Read request's SRB pointer. */
  6188. scsiq = (ASC_SCSI_Q *)
  6189. ASC_SRB2SCSIQ(ASC_U32_TO_VADDR(AscReadLramDWord(iop_base,
  6190. (ushort)
  6191. (q_addr +
  6192. ASC_SCSIQ_D_SRBPTR))));
  6193. /*
  6194. * Get request's first and working SG queue.
  6195. */
  6196. sg_wk_q_no = AscReadLramByte(iop_base,
  6197. (ushort)(q_addr +
  6198. ASC_SCSIQ_B_SG_WK_QP));
  6199. first_sg_wk_q_no = AscReadLramByte(iop_base,
  6200. (ushort)(q_addr +
  6201. ASC_SCSIQ_B_FIRST_SG_WK_QP));
  6202. /*
  6203. * Reset request's working SG queue back to the
  6204. * first SG queue.
  6205. */
  6206. AscWriteLramByte(iop_base,
  6207. (ushort)(q_addr +
  6208. (ushort)ASC_SCSIQ_B_SG_WK_QP),
  6209. first_sg_wk_q_no);
  6210. sg_head = scsiq->sg_head;
  6211. /*
  6212. * Set sg_entry_cnt to the number of SG elements
  6213. * that will be completed on this interrupt.
  6214. *
  6215. * Note: The allocated SG queues contain ASC_MAX_SG_LIST - 1
  6216. * SG elements. The data_cnt and data_addr fields which
  6217. * add 1 to the SG element capacity are not used when
  6218. * restarting SG handling after a halt.
  6219. */
  6220. if (scsiq->remain_sg_entry_cnt > (ASC_MAX_SG_LIST - 1)) {
  6221. sg_entry_cnt = ASC_MAX_SG_LIST - 1;
  6222. /*
  6223. * Keep track of remaining number of SG elements that
  6224. * will need to be handled on the next interrupt.
  6225. */
  6226. scsiq->remain_sg_entry_cnt -= (ASC_MAX_SG_LIST - 1);
  6227. } else {
  6228. sg_entry_cnt = scsiq->remain_sg_entry_cnt;
  6229. scsiq->remain_sg_entry_cnt = 0;
  6230. }
  6231. /*
  6232. * Copy SG elements into the list of allocated SG queues.
  6233. *
  6234. * Last index completed is saved in scsiq->next_sg_index.
  6235. */
  6236. next_qp = first_sg_wk_q_no;
  6237. q_addr = ASC_QNO_TO_QADDR(next_qp);
  6238. scsi_sg_q.sg_head_qp = q_no;
  6239. scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
  6240. for (i = 0; i < sg_head->queue_cnt; i++) {
  6241. scsi_sg_q.seq_no = i + 1;
  6242. if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
  6243. sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2);
  6244. sg_entry_cnt -= ASC_SG_LIST_PER_Q;
  6245. /*
  6246. * After very first SG queue RISC FW uses next
  6247. * SG queue first element then checks sg_list_cnt
  6248. * against zero and then decrements, so set
  6249. * sg_list_cnt 1 less than number of SG elements
  6250. * in each SG queue.
  6251. */
  6252. scsi_sg_q.sg_list_cnt = ASC_SG_LIST_PER_Q - 1;
  6253. scsi_sg_q.sg_cur_list_cnt =
  6254. ASC_SG_LIST_PER_Q - 1;
  6255. } else {
  6256. /*
  6257. * This is the last SG queue in the list of
  6258. * allocated SG queues. If there are more
  6259. * SG elements than will fit in the allocated
  6260. * queues, then set the QCSG_SG_XFER_MORE flag.
  6261. */
  6262. if (scsiq->remain_sg_entry_cnt != 0) {
  6263. scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
  6264. } else {
  6265. scsi_sg_q.cntl |= QCSG_SG_XFER_END;
  6266. }
  6267. /* equals sg_entry_cnt * 2 */
  6268. sg_list_dwords = sg_entry_cnt << 1;
  6269. scsi_sg_q.sg_list_cnt = sg_entry_cnt - 1;
  6270. scsi_sg_q.sg_cur_list_cnt = sg_entry_cnt - 1;
  6271. sg_entry_cnt = 0;
  6272. }
  6273. scsi_sg_q.q_no = next_qp;
  6274. AscMemWordCopyPtrToLram(iop_base,
  6275. q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
  6276. (uchar *)&scsi_sg_q,
  6277. sizeof(ASC_SG_LIST_Q) >> 1);
  6278. AscMemDWordCopyPtrToLram(iop_base,
  6279. q_addr + ASC_SGQ_LIST_BEG,
  6280. (uchar *)&sg_head->
  6281. sg_list[scsiq->next_sg_index],
  6282. sg_list_dwords);
  6283. scsiq->next_sg_index += ASC_SG_LIST_PER_Q;
  6284. /*
  6285. * If the just completed SG queue contained the
  6286. * last SG element, then no more SG queues need
  6287. * to be written.
  6288. */
  6289. if (scsi_sg_q.cntl & QCSG_SG_XFER_END) {
  6290. break;
  6291. }
  6292. next_qp = AscReadLramByte(iop_base,
  6293. (ushort)(q_addr +
  6294. ASC_SCSIQ_B_FWD));
  6295. q_addr = ASC_QNO_TO_QADDR(next_qp);
  6296. }
  6297. /*
  6298. * Clear the halt condition so the RISC will be restarted
  6299. * after the return.
  6300. */
  6301. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
  6302. return (0);
  6303. }
  6304. #endif /* CC_VERY_LONG_SG_LIST */
  6305. return (0);
  6306. }
  6307. /*
  6308. * void
  6309. * DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
  6310. *
  6311. * Calling/Exit State:
  6312. * none
  6313. *
  6314. * Description:
  6315. * Input an ASC_QDONE_INFO structure from the chip
  6316. */
  6317. static void
  6318. DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
  6319. {
  6320. int i;
  6321. ushort word;
  6322. AscSetChipLramAddr(iop_base, s_addr);
  6323. for (i = 0; i < 2 * words; i += 2) {
  6324. if (i == 10) {
  6325. continue;
  6326. }
  6327. word = inpw(iop_base + IOP_RAM_DATA);
  6328. inbuf[i] = word & 0xff;
  6329. inbuf[i + 1] = (word >> 8) & 0xff;
  6330. }
  6331. ASC_DBG_PRT_HEX(2, "DvcGetQinfo", inbuf, 2 * words);
  6332. }
  6333. static uchar
  6334. _AscCopyLramScsiDoneQ(PortAddr iop_base,
  6335. ushort q_addr,
  6336. ASC_QDONE_INFO *scsiq, ASC_DCNT max_dma_count)
  6337. {
  6338. ushort _val;
  6339. uchar sg_queue_cnt;
  6340. DvcGetQinfo(iop_base,
  6341. q_addr + ASC_SCSIQ_DONE_INFO_BEG,
  6342. (uchar *)scsiq,
  6343. (sizeof(ASC_SCSIQ_2) + sizeof(ASC_SCSIQ_3)) / 2);
  6344. _val = AscReadLramWord(iop_base,
  6345. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS));
  6346. scsiq->q_status = (uchar)_val;
  6347. scsiq->q_no = (uchar)(_val >> 8);
  6348. _val = AscReadLramWord(iop_base,
  6349. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_CNTL));
  6350. scsiq->cntl = (uchar)_val;
  6351. sg_queue_cnt = (uchar)(_val >> 8);
  6352. _val = AscReadLramWord(iop_base,
  6353. (ushort)(q_addr +
  6354. (ushort)ASC_SCSIQ_B_SENSE_LEN));
  6355. scsiq->sense_len = (uchar)_val;
  6356. scsiq->extra_bytes = (uchar)(_val >> 8);
  6357. /*
  6358. * Read high word of remain bytes from alternate location.
  6359. */
  6360. scsiq->remain_bytes = (((ADV_DCNT)AscReadLramWord(iop_base,
  6361. (ushort)(q_addr +
  6362. (ushort)
  6363. ASC_SCSIQ_W_ALT_DC1)))
  6364. << 16);
  6365. /*
  6366. * Read low word of remain bytes from original location.
  6367. */
  6368. scsiq->remain_bytes += AscReadLramWord(iop_base,
  6369. (ushort)(q_addr + (ushort)
  6370. ASC_SCSIQ_DW_REMAIN_XFER_CNT));
  6371. scsiq->remain_bytes &= max_dma_count;
  6372. return sg_queue_cnt;
  6373. }
  6374. /*
  6375. * asc_isr_callback() - Second Level Interrupt Handler called by AscISR().
  6376. *
  6377. * Interrupt callback function for the Narrow SCSI Asc Library.
  6378. */
  6379. static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
  6380. {
  6381. struct asc_board *boardp;
  6382. struct scsi_cmnd *scp;
  6383. struct Scsi_Host *shost;
  6384. ASC_DBG(1, "asc_dvc_varp 0x%p, qdonep 0x%p\n", asc_dvc_varp, qdonep);
  6385. ASC_DBG_PRT_ASC_QDONE_INFO(2, qdonep);
  6386. scp = advansys_srb_to_ptr(asc_dvc_varp, qdonep->d2.srb_ptr);
  6387. if (!scp)
  6388. return;
  6389. ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
  6390. shost = scp->device->host;
  6391. ASC_STATS(shost, callback);
  6392. ASC_DBG(1, "shost 0x%p\n", shost);
  6393. boardp = shost_priv(shost);
  6394. BUG_ON(asc_dvc_varp != &boardp->dvc_var.asc_dvc_var);
  6395. dma_unmap_single(boardp->dev, scp->SCp.dma_handle,
  6396. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  6397. /*
  6398. * 'qdonep' contains the command's ending status.
  6399. */
  6400. switch (qdonep->d3.done_stat) {
  6401. case QD_NO_ERROR:
  6402. ASC_DBG(2, "QD_NO_ERROR\n");
  6403. scp->result = 0;
  6404. /*
  6405. * Check for an underrun condition.
  6406. *
  6407. * If there was no error and an underrun condition, then
  6408. * return the number of underrun bytes.
  6409. */
  6410. if (scsi_bufflen(scp) != 0 && qdonep->remain_bytes != 0 &&
  6411. qdonep->remain_bytes <= scsi_bufflen(scp)) {
  6412. ASC_DBG(1, "underrun condition %u bytes\n",
  6413. (unsigned)qdonep->remain_bytes);
  6414. scsi_set_resid(scp, qdonep->remain_bytes);
  6415. }
  6416. break;
  6417. case QD_WITH_ERROR:
  6418. ASC_DBG(2, "QD_WITH_ERROR\n");
  6419. switch (qdonep->d3.host_stat) {
  6420. case QHSTA_NO_ERROR:
  6421. if (qdonep->d3.scsi_stat == SAM_STAT_CHECK_CONDITION) {
  6422. ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
  6423. ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
  6424. SCSI_SENSE_BUFFERSIZE);
  6425. /*
  6426. * Note: The 'status_byte()' macro used by
  6427. * target drivers defined in scsi.h shifts the
  6428. * status byte returned by host drivers right
  6429. * by 1 bit. This is why target drivers also
  6430. * use right shifted status byte definitions.
  6431. * For instance target drivers use
  6432. * CHECK_CONDITION, defined to 0x1, instead of
  6433. * the SCSI defined check condition value of
  6434. * 0x2. Host drivers are supposed to return
  6435. * the status byte as it is defined by SCSI.
  6436. */
  6437. scp->result = DRIVER_BYTE(DRIVER_SENSE) |
  6438. STATUS_BYTE(qdonep->d3.scsi_stat);
  6439. } else {
  6440. scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
  6441. }
  6442. break;
  6443. default:
  6444. /* QHSTA error occurred */
  6445. ASC_DBG(1, "host_stat 0x%x\n", qdonep->d3.host_stat);
  6446. scp->result = HOST_BYTE(DID_BAD_TARGET);
  6447. break;
  6448. }
  6449. break;
  6450. case QD_ABORTED_BY_HOST:
  6451. ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
  6452. scp->result =
  6453. HOST_BYTE(DID_ABORT) | MSG_BYTE(qdonep->d3.
  6454. scsi_msg) |
  6455. STATUS_BYTE(qdonep->d3.scsi_stat);
  6456. break;
  6457. default:
  6458. ASC_DBG(1, "done_stat 0x%x\n", qdonep->d3.done_stat);
  6459. scp->result =
  6460. HOST_BYTE(DID_ERROR) | MSG_BYTE(qdonep->d3.
  6461. scsi_msg) |
  6462. STATUS_BYTE(qdonep->d3.scsi_stat);
  6463. break;
  6464. }
  6465. /*
  6466. * If the 'init_tidmask' bit isn't already set for the target and the
  6467. * current request finished normally, then set the bit for the target
  6468. * to indicate that a device is present.
  6469. */
  6470. if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
  6471. qdonep->d3.done_stat == QD_NO_ERROR &&
  6472. qdonep->d3.host_stat == QHSTA_NO_ERROR) {
  6473. boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
  6474. }
  6475. asc_scsi_done(scp);
  6476. }
  6477. static int AscIsrQDone(ASC_DVC_VAR *asc_dvc)
  6478. {
  6479. uchar next_qp;
  6480. uchar n_q_used;
  6481. uchar sg_list_qp;
  6482. uchar sg_queue_cnt;
  6483. uchar q_cnt;
  6484. uchar done_q_tail;
  6485. uchar tid_no;
  6486. ASC_SCSI_BIT_ID_TYPE scsi_busy;
  6487. ASC_SCSI_BIT_ID_TYPE target_id;
  6488. PortAddr iop_base;
  6489. ushort q_addr;
  6490. ushort sg_q_addr;
  6491. uchar cur_target_qng;
  6492. ASC_QDONE_INFO scsiq_buf;
  6493. ASC_QDONE_INFO *scsiq;
  6494. int false_overrun;
  6495. iop_base = asc_dvc->iop_base;
  6496. n_q_used = 1;
  6497. scsiq = (ASC_QDONE_INFO *)&scsiq_buf;
  6498. done_q_tail = (uchar)AscGetVarDoneQTail(iop_base);
  6499. q_addr = ASC_QNO_TO_QADDR(done_q_tail);
  6500. next_qp = AscReadLramByte(iop_base,
  6501. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_FWD));
  6502. if (next_qp != ASC_QLINK_END) {
  6503. AscPutVarDoneQTail(iop_base, next_qp);
  6504. q_addr = ASC_QNO_TO_QADDR(next_qp);
  6505. sg_queue_cnt = _AscCopyLramScsiDoneQ(iop_base, q_addr, scsiq,
  6506. asc_dvc->max_dma_count);
  6507. AscWriteLramByte(iop_base,
  6508. (ushort)(q_addr +
  6509. (ushort)ASC_SCSIQ_B_STATUS),
  6510. (uchar)(scsiq->
  6511. q_status & (uchar)~(QS_READY |
  6512. QS_ABORTED)));
  6513. tid_no = ASC_TIX_TO_TID(scsiq->d2.target_ix);
  6514. target_id = ASC_TIX_TO_TARGET_ID(scsiq->d2.target_ix);
  6515. if ((scsiq->cntl & QC_SG_HEAD) != 0) {
  6516. sg_q_addr = q_addr;
  6517. sg_list_qp = next_qp;
  6518. for (q_cnt = 0; q_cnt < sg_queue_cnt; q_cnt++) {
  6519. sg_list_qp = AscReadLramByte(iop_base,
  6520. (ushort)(sg_q_addr
  6521. + (ushort)
  6522. ASC_SCSIQ_B_FWD));
  6523. sg_q_addr = ASC_QNO_TO_QADDR(sg_list_qp);
  6524. if (sg_list_qp == ASC_QLINK_END) {
  6525. AscSetLibErrorCode(asc_dvc,
  6526. ASCQ_ERR_SG_Q_LINKS);
  6527. scsiq->d3.done_stat = QD_WITH_ERROR;
  6528. scsiq->d3.host_stat =
  6529. QHSTA_D_QDONE_SG_LIST_CORRUPTED;
  6530. goto FATAL_ERR_QDONE;
  6531. }
  6532. AscWriteLramByte(iop_base,
  6533. (ushort)(sg_q_addr + (ushort)
  6534. ASC_SCSIQ_B_STATUS),
  6535. QS_FREE);
  6536. }
  6537. n_q_used = sg_queue_cnt + 1;
  6538. AscPutVarDoneQTail(iop_base, sg_list_qp);
  6539. }
  6540. if (asc_dvc->queue_full_or_busy & target_id) {
  6541. cur_target_qng = AscReadLramByte(iop_base,
  6542. (ushort)((ushort)
  6543. ASC_QADR_BEG
  6544. + (ushort)
  6545. scsiq->d2.
  6546. target_ix));
  6547. if (cur_target_qng < asc_dvc->max_dvc_qng[tid_no]) {
  6548. scsi_busy = AscReadLramByte(iop_base, (ushort)
  6549. ASCV_SCSIBUSY_B);
  6550. scsi_busy &= ~target_id;
  6551. AscWriteLramByte(iop_base,
  6552. (ushort)ASCV_SCSIBUSY_B,
  6553. scsi_busy);
  6554. asc_dvc->queue_full_or_busy &= ~target_id;
  6555. }
  6556. }
  6557. if (asc_dvc->cur_total_qng >= n_q_used) {
  6558. asc_dvc->cur_total_qng -= n_q_used;
  6559. if (asc_dvc->cur_dvc_qng[tid_no] != 0) {
  6560. asc_dvc->cur_dvc_qng[tid_no]--;
  6561. }
  6562. } else {
  6563. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CUR_QNG);
  6564. scsiq->d3.done_stat = QD_WITH_ERROR;
  6565. goto FATAL_ERR_QDONE;
  6566. }
  6567. if ((scsiq->d2.srb_ptr == 0UL) ||
  6568. ((scsiq->q_status & QS_ABORTED) != 0)) {
  6569. return (0x11);
  6570. } else if (scsiq->q_status == QS_DONE) {
  6571. false_overrun = FALSE;
  6572. if (scsiq->extra_bytes != 0) {
  6573. scsiq->remain_bytes +=
  6574. (ADV_DCNT)scsiq->extra_bytes;
  6575. }
  6576. if (scsiq->d3.done_stat == QD_WITH_ERROR) {
  6577. if (scsiq->d3.host_stat ==
  6578. QHSTA_M_DATA_OVER_RUN) {
  6579. if ((scsiq->
  6580. cntl & (QC_DATA_IN | QC_DATA_OUT))
  6581. == 0) {
  6582. scsiq->d3.done_stat =
  6583. QD_NO_ERROR;
  6584. scsiq->d3.host_stat =
  6585. QHSTA_NO_ERROR;
  6586. } else if (false_overrun) {
  6587. scsiq->d3.done_stat =
  6588. QD_NO_ERROR;
  6589. scsiq->d3.host_stat =
  6590. QHSTA_NO_ERROR;
  6591. }
  6592. } else if (scsiq->d3.host_stat ==
  6593. QHSTA_M_HUNG_REQ_SCSI_BUS_RESET) {
  6594. AscStopChip(iop_base);
  6595. AscSetChipControl(iop_base,
  6596. (uchar)(CC_SCSI_RESET
  6597. | CC_HALT));
  6598. udelay(60);
  6599. AscSetChipControl(iop_base, CC_HALT);
  6600. AscSetChipStatus(iop_base,
  6601. CIW_CLR_SCSI_RESET_INT);
  6602. AscSetChipStatus(iop_base, 0);
  6603. AscSetChipControl(iop_base, 0);
  6604. }
  6605. }
  6606. if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
  6607. asc_isr_callback(asc_dvc, scsiq);
  6608. } else {
  6609. if ((AscReadLramByte(iop_base,
  6610. (ushort)(q_addr + (ushort)
  6611. ASC_SCSIQ_CDB_BEG))
  6612. == START_STOP)) {
  6613. asc_dvc->unit_not_ready &= ~target_id;
  6614. if (scsiq->d3.done_stat != QD_NO_ERROR) {
  6615. asc_dvc->start_motor &=
  6616. ~target_id;
  6617. }
  6618. }
  6619. }
  6620. return (1);
  6621. } else {
  6622. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_Q_STATUS);
  6623. FATAL_ERR_QDONE:
  6624. if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
  6625. asc_isr_callback(asc_dvc, scsiq);
  6626. }
  6627. return (0x80);
  6628. }
  6629. }
  6630. return (0);
  6631. }
  6632. static int AscISR(ASC_DVC_VAR *asc_dvc)
  6633. {
  6634. ASC_CS_TYPE chipstat;
  6635. PortAddr iop_base;
  6636. ushort saved_ram_addr;
  6637. uchar ctrl_reg;
  6638. uchar saved_ctrl_reg;
  6639. int int_pending;
  6640. int status;
  6641. uchar host_flag;
  6642. iop_base = asc_dvc->iop_base;
  6643. int_pending = FALSE;
  6644. if (AscIsIntPending(iop_base) == 0)
  6645. return int_pending;
  6646. if ((asc_dvc->init_state & ASC_INIT_STATE_END_LOAD_MC) == 0) {
  6647. return ERR;
  6648. }
  6649. if (asc_dvc->in_critical_cnt != 0) {
  6650. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_ON_CRITICAL);
  6651. return ERR;
  6652. }
  6653. if (asc_dvc->is_in_int) {
  6654. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_RE_ENTRY);
  6655. return ERR;
  6656. }
  6657. asc_dvc->is_in_int = TRUE;
  6658. ctrl_reg = AscGetChipControl(iop_base);
  6659. saved_ctrl_reg = ctrl_reg & (~(CC_SCSI_RESET | CC_CHIP_RESET |
  6660. CC_SINGLE_STEP | CC_DIAG | CC_TEST));
  6661. chipstat = AscGetChipStatus(iop_base);
  6662. if (chipstat & CSW_SCSI_RESET_LATCH) {
  6663. if (!(asc_dvc->bus_type & (ASC_IS_VL | ASC_IS_EISA))) {
  6664. int i = 10;
  6665. int_pending = TRUE;
  6666. asc_dvc->sdtr_done = 0;
  6667. saved_ctrl_reg &= (uchar)(~CC_HALT);
  6668. while ((AscGetChipStatus(iop_base) &
  6669. CSW_SCSI_RESET_ACTIVE) && (i-- > 0)) {
  6670. mdelay(100);
  6671. }
  6672. AscSetChipControl(iop_base, (CC_CHIP_RESET | CC_HALT));
  6673. AscSetChipControl(iop_base, CC_HALT);
  6674. AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
  6675. AscSetChipStatus(iop_base, 0);
  6676. chipstat = AscGetChipStatus(iop_base);
  6677. }
  6678. }
  6679. saved_ram_addr = AscGetChipLramAddr(iop_base);
  6680. host_flag = AscReadLramByte(iop_base,
  6681. ASCV_HOST_FLAG_B) &
  6682. (uchar)(~ASC_HOST_FLAG_IN_ISR);
  6683. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
  6684. (uchar)(host_flag | (uchar)ASC_HOST_FLAG_IN_ISR));
  6685. if ((chipstat & CSW_INT_PENDING) || (int_pending)) {
  6686. AscAckInterrupt(iop_base);
  6687. int_pending = TRUE;
  6688. if ((chipstat & CSW_HALTED) && (ctrl_reg & CC_SINGLE_STEP)) {
  6689. if (AscIsrChipHalted(asc_dvc) == ERR) {
  6690. goto ISR_REPORT_QDONE_FATAL_ERROR;
  6691. } else {
  6692. saved_ctrl_reg &= (uchar)(~CC_HALT);
  6693. }
  6694. } else {
  6695. ISR_REPORT_QDONE_FATAL_ERROR:
  6696. if ((asc_dvc->dvc_cntl & ASC_CNTL_INT_MULTI_Q) != 0) {
  6697. while (((status =
  6698. AscIsrQDone(asc_dvc)) & 0x01) != 0) {
  6699. }
  6700. } else {
  6701. do {
  6702. if ((status =
  6703. AscIsrQDone(asc_dvc)) == 1) {
  6704. break;
  6705. }
  6706. } while (status == 0x11);
  6707. }
  6708. if ((status & 0x80) != 0)
  6709. int_pending = ERR;
  6710. }
  6711. }
  6712. AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
  6713. AscSetChipLramAddr(iop_base, saved_ram_addr);
  6714. AscSetChipControl(iop_base, saved_ctrl_reg);
  6715. asc_dvc->is_in_int = FALSE;
  6716. return int_pending;
  6717. }
  6718. /*
  6719. * advansys_reset()
  6720. *
  6721. * Reset the bus associated with the command 'scp'.
  6722. *
  6723. * This function runs its own thread. Interrupts must be blocked but
  6724. * sleeping is allowed and no locking other than for host structures is
  6725. * required. Returns SUCCESS or FAILED.
  6726. */
  6727. static int advansys_reset(struct scsi_cmnd *scp)
  6728. {
  6729. struct Scsi_Host *shost = scp->device->host;
  6730. struct asc_board *boardp = shost_priv(shost);
  6731. unsigned long flags;
  6732. int status;
  6733. int ret = SUCCESS;
  6734. ASC_DBG(1, "0x%p\n", scp);
  6735. ASC_STATS(shost, reset);
  6736. scmd_printk(KERN_INFO, scp, "SCSI bus reset started...\n");
  6737. if (ASC_NARROW_BOARD(boardp)) {
  6738. ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  6739. /* Reset the chip and SCSI bus. */
  6740. ASC_DBG(1, "before AscInitAsc1000Driver()\n");
  6741. status = AscInitAsc1000Driver(asc_dvc);
  6742. /* Refer to ASC_IERR_* definitions for meaning of 'err_code'. */
  6743. if (asc_dvc->err_code || !asc_dvc->overrun_dma) {
  6744. scmd_printk(KERN_INFO, scp, "SCSI bus reset error: "
  6745. "0x%x, status: 0x%x\n", asc_dvc->err_code,
  6746. status);
  6747. ret = FAILED;
  6748. } else if (status) {
  6749. scmd_printk(KERN_INFO, scp, "SCSI bus reset warning: "
  6750. "0x%x\n", status);
  6751. } else {
  6752. scmd_printk(KERN_INFO, scp, "SCSI bus reset "
  6753. "successful\n");
  6754. }
  6755. ASC_DBG(1, "after AscInitAsc1000Driver()\n");
  6756. spin_lock_irqsave(shost->host_lock, flags);
  6757. } else {
  6758. /*
  6759. * If the suggest reset bus flags are set, then reset the bus.
  6760. * Otherwise only reset the device.
  6761. */
  6762. ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
  6763. /*
  6764. * Reset the target's SCSI bus.
  6765. */
  6766. ASC_DBG(1, "before AdvResetChipAndSB()\n");
  6767. switch (AdvResetChipAndSB(adv_dvc)) {
  6768. case ASC_TRUE:
  6769. scmd_printk(KERN_INFO, scp, "SCSI bus reset "
  6770. "successful\n");
  6771. break;
  6772. case ASC_FALSE:
  6773. default:
  6774. scmd_printk(KERN_INFO, scp, "SCSI bus reset error\n");
  6775. ret = FAILED;
  6776. break;
  6777. }
  6778. spin_lock_irqsave(shost->host_lock, flags);
  6779. AdvISR(adv_dvc);
  6780. }
  6781. /* Save the time of the most recently completed reset. */
  6782. boardp->last_reset = jiffies;
  6783. spin_unlock_irqrestore(shost->host_lock, flags);
  6784. ASC_DBG(1, "ret %d\n", ret);
  6785. return ret;
  6786. }
  6787. /*
  6788. * advansys_biosparam()
  6789. *
  6790. * Translate disk drive geometry if the "BIOS greater than 1 GB"
  6791. * support is enabled for a drive.
  6792. *
  6793. * ip (information pointer) is an int array with the following definition:
  6794. * ip[0]: heads
  6795. * ip[1]: sectors
  6796. * ip[2]: cylinders
  6797. */
  6798. static int
  6799. advansys_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  6800. sector_t capacity, int ip[])
  6801. {
  6802. struct asc_board *boardp = shost_priv(sdev->host);
  6803. ASC_DBG(1, "begin\n");
  6804. ASC_STATS(sdev->host, biosparam);
  6805. if (ASC_NARROW_BOARD(boardp)) {
  6806. if ((boardp->dvc_var.asc_dvc_var.dvc_cntl &
  6807. ASC_CNTL_BIOS_GT_1GB) && capacity > 0x200000) {
  6808. ip[0] = 255;
  6809. ip[1] = 63;
  6810. } else {
  6811. ip[0] = 64;
  6812. ip[1] = 32;
  6813. }
  6814. } else {
  6815. if ((boardp->dvc_var.adv_dvc_var.bios_ctrl &
  6816. BIOS_CTRL_EXTENDED_XLAT) && capacity > 0x200000) {
  6817. ip[0] = 255;
  6818. ip[1] = 63;
  6819. } else {
  6820. ip[0] = 64;
  6821. ip[1] = 32;
  6822. }
  6823. }
  6824. ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
  6825. ASC_DBG(1, "end\n");
  6826. return 0;
  6827. }
  6828. /*
  6829. * First-level interrupt handler.
  6830. *
  6831. * 'dev_id' is a pointer to the interrupting adapter's Scsi_Host.
  6832. */
  6833. static irqreturn_t advansys_interrupt(int irq, void *dev_id)
  6834. {
  6835. struct Scsi_Host *shost = dev_id;
  6836. struct asc_board *boardp = shost_priv(shost);
  6837. irqreturn_t result = IRQ_NONE;
  6838. ASC_DBG(2, "boardp 0x%p\n", boardp);
  6839. spin_lock(shost->host_lock);
  6840. if (ASC_NARROW_BOARD(boardp)) {
  6841. if (AscIsIntPending(shost->io_port)) {
  6842. result = IRQ_HANDLED;
  6843. ASC_STATS(shost, interrupt);
  6844. ASC_DBG(1, "before AscISR()\n");
  6845. AscISR(&boardp->dvc_var.asc_dvc_var);
  6846. }
  6847. } else {
  6848. ASC_DBG(1, "before AdvISR()\n");
  6849. if (AdvISR(&boardp->dvc_var.adv_dvc_var)) {
  6850. result = IRQ_HANDLED;
  6851. ASC_STATS(shost, interrupt);
  6852. }
  6853. }
  6854. spin_unlock(shost->host_lock);
  6855. ASC_DBG(1, "end\n");
  6856. return result;
  6857. }
  6858. static int AscHostReqRiscHalt(PortAddr iop_base)
  6859. {
  6860. int count = 0;
  6861. int sta = 0;
  6862. uchar saved_stop_code;
  6863. if (AscIsChipHalted(iop_base))
  6864. return (1);
  6865. saved_stop_code = AscReadLramByte(iop_base, ASCV_STOP_CODE_B);
  6866. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
  6867. ASC_STOP_HOST_REQ_RISC_HALT | ASC_STOP_REQ_RISC_STOP);
  6868. do {
  6869. if (AscIsChipHalted(iop_base)) {
  6870. sta = 1;
  6871. break;
  6872. }
  6873. mdelay(100);
  6874. } while (count++ < 20);
  6875. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, saved_stop_code);
  6876. return (sta);
  6877. }
  6878. static int
  6879. AscSetRunChipSynRegAtID(PortAddr iop_base, uchar tid_no, uchar sdtr_data)
  6880. {
  6881. int sta = FALSE;
  6882. if (AscHostReqRiscHalt(iop_base)) {
  6883. sta = AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
  6884. AscStartChip(iop_base);
  6885. }
  6886. return sta;
  6887. }
  6888. static void AscAsyncFix(ASC_DVC_VAR *asc_dvc, struct scsi_device *sdev)
  6889. {
  6890. char type = sdev->type;
  6891. ASC_SCSI_BIT_ID_TYPE tid_bits = 1 << sdev->id;
  6892. if (!(asc_dvc->bug_fix_cntl & ASC_BUG_FIX_ASYN_USE_SYN))
  6893. return;
  6894. if (asc_dvc->init_sdtr & tid_bits)
  6895. return;
  6896. if ((type == TYPE_ROM) && (strncmp(sdev->vendor, "HP ", 3) == 0))
  6897. asc_dvc->pci_fix_asyn_xfer_always |= tid_bits;
  6898. asc_dvc->pci_fix_asyn_xfer |= tid_bits;
  6899. if ((type == TYPE_PROCESSOR) || (type == TYPE_SCANNER) ||
  6900. (type == TYPE_ROM) || (type == TYPE_TAPE))
  6901. asc_dvc->pci_fix_asyn_xfer &= ~tid_bits;
  6902. if (asc_dvc->pci_fix_asyn_xfer & tid_bits)
  6903. AscSetRunChipSynRegAtID(asc_dvc->iop_base, sdev->id,
  6904. ASYN_SDTR_DATA_FIX_PCI_REV_AB);
  6905. }
  6906. static void
  6907. advansys_narrow_slave_configure(struct scsi_device *sdev, ASC_DVC_VAR *asc_dvc)
  6908. {
  6909. ASC_SCSI_BIT_ID_TYPE tid_bit = 1 << sdev->id;
  6910. ASC_SCSI_BIT_ID_TYPE orig_use_tagged_qng = asc_dvc->use_tagged_qng;
  6911. if (sdev->lun == 0) {
  6912. ASC_SCSI_BIT_ID_TYPE orig_init_sdtr = asc_dvc->init_sdtr;
  6913. if ((asc_dvc->cfg->sdtr_enable & tid_bit) && sdev->sdtr) {
  6914. asc_dvc->init_sdtr |= tid_bit;
  6915. } else {
  6916. asc_dvc->init_sdtr &= ~tid_bit;
  6917. }
  6918. if (orig_init_sdtr != asc_dvc->init_sdtr)
  6919. AscAsyncFix(asc_dvc, sdev);
  6920. }
  6921. if (sdev->tagged_supported) {
  6922. if (asc_dvc->cfg->cmd_qng_enabled & tid_bit) {
  6923. if (sdev->lun == 0) {
  6924. asc_dvc->cfg->can_tagged_qng |= tid_bit;
  6925. asc_dvc->use_tagged_qng |= tid_bit;
  6926. }
  6927. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
  6928. asc_dvc->max_dvc_qng[sdev->id]);
  6929. }
  6930. } else {
  6931. if (sdev->lun == 0) {
  6932. asc_dvc->cfg->can_tagged_qng &= ~tid_bit;
  6933. asc_dvc->use_tagged_qng &= ~tid_bit;
  6934. }
  6935. scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
  6936. }
  6937. if ((sdev->lun == 0) &&
  6938. (orig_use_tagged_qng != asc_dvc->use_tagged_qng)) {
  6939. AscWriteLramByte(asc_dvc->iop_base, ASCV_DISC_ENABLE_B,
  6940. asc_dvc->cfg->disc_enable);
  6941. AscWriteLramByte(asc_dvc->iop_base, ASCV_USE_TAGGED_QNG_B,
  6942. asc_dvc->use_tagged_qng);
  6943. AscWriteLramByte(asc_dvc->iop_base, ASCV_CAN_TAGGED_QNG_B,
  6944. asc_dvc->cfg->can_tagged_qng);
  6945. asc_dvc->max_dvc_qng[sdev->id] =
  6946. asc_dvc->cfg->max_tag_qng[sdev->id];
  6947. AscWriteLramByte(asc_dvc->iop_base,
  6948. (ushort)(ASCV_MAX_DVC_QNG_BEG + sdev->id),
  6949. asc_dvc->max_dvc_qng[sdev->id]);
  6950. }
  6951. }
  6952. /*
  6953. * Wide Transfers
  6954. *
  6955. * If the EEPROM enabled WDTR for the device and the device supports wide
  6956. * bus (16 bit) transfers, then turn on the device's 'wdtr_able' bit and
  6957. * write the new value to the microcode.
  6958. */
  6959. static void
  6960. advansys_wide_enable_wdtr(AdvPortAddr iop_base, unsigned short tidmask)
  6961. {
  6962. unsigned short cfg_word;
  6963. AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
  6964. if ((cfg_word & tidmask) != 0)
  6965. return;
  6966. cfg_word |= tidmask;
  6967. AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
  6968. /*
  6969. * Clear the microcode SDTR and WDTR negotiation done indicators for
  6970. * the target to cause it to negotiate with the new setting set above.
  6971. * WDTR when accepted causes the target to enter asynchronous mode, so
  6972. * SDTR must be negotiated.
  6973. */
  6974. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  6975. cfg_word &= ~tidmask;
  6976. AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  6977. AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
  6978. cfg_word &= ~tidmask;
  6979. AdvWriteWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
  6980. }
  6981. /*
  6982. * Synchronous Transfers
  6983. *
  6984. * If the EEPROM enabled SDTR for the device and the device
  6985. * supports synchronous transfers, then turn on the device's
  6986. * 'sdtr_able' bit. Write the new value to the microcode.
  6987. */
  6988. static void
  6989. advansys_wide_enable_sdtr(AdvPortAddr iop_base, unsigned short tidmask)
  6990. {
  6991. unsigned short cfg_word;
  6992. AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
  6993. if ((cfg_word & tidmask) != 0)
  6994. return;
  6995. cfg_word |= tidmask;
  6996. AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
  6997. /*
  6998. * Clear the microcode "SDTR negotiation" done indicator for the
  6999. * target to cause it to negotiate with the new setting set above.
  7000. */
  7001. AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  7002. cfg_word &= ~tidmask;
  7003. AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
  7004. }
  7005. /*
  7006. * PPR (Parallel Protocol Request) Capable
  7007. *
  7008. * If the device supports DT mode, then it must be PPR capable.
  7009. * The PPR message will be used in place of the SDTR and WDTR
  7010. * messages to negotiate synchronous speed and offset, transfer
  7011. * width, and protocol options.
  7012. */
  7013. static void advansys_wide_enable_ppr(ADV_DVC_VAR *adv_dvc,
  7014. AdvPortAddr iop_base, unsigned short tidmask)
  7015. {
  7016. AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
  7017. adv_dvc->ppr_able |= tidmask;
  7018. AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able);
  7019. }
  7020. static void
  7021. advansys_wide_slave_configure(struct scsi_device *sdev, ADV_DVC_VAR *adv_dvc)
  7022. {
  7023. AdvPortAddr iop_base = adv_dvc->iop_base;
  7024. unsigned short tidmask = 1 << sdev->id;
  7025. if (sdev->lun == 0) {
  7026. /*
  7027. * Handle WDTR, SDTR, and Tag Queuing. If the feature
  7028. * is enabled in the EEPROM and the device supports the
  7029. * feature, then enable it in the microcode.
  7030. */
  7031. if ((adv_dvc->wdtr_able & tidmask) && sdev->wdtr)
  7032. advansys_wide_enable_wdtr(iop_base, tidmask);
  7033. if ((adv_dvc->sdtr_able & tidmask) && sdev->sdtr)
  7034. advansys_wide_enable_sdtr(iop_base, tidmask);
  7035. if (adv_dvc->chip_type == ADV_CHIP_ASC38C1600 && sdev->ppr)
  7036. advansys_wide_enable_ppr(adv_dvc, iop_base, tidmask);
  7037. /*
  7038. * Tag Queuing is disabled for the BIOS which runs in polled
  7039. * mode and would see no benefit from Tag Queuing. Also by
  7040. * disabling Tag Queuing in the BIOS devices with Tag Queuing
  7041. * bugs will at least work with the BIOS.
  7042. */
  7043. if ((adv_dvc->tagqng_able & tidmask) &&
  7044. sdev->tagged_supported) {
  7045. unsigned short cfg_word;
  7046. AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word);
  7047. cfg_word |= tidmask;
  7048. AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE,
  7049. cfg_word);
  7050. AdvWriteByteLram(iop_base,
  7051. ASC_MC_NUMBER_OF_MAX_CMD + sdev->id,
  7052. adv_dvc->max_dvc_qng);
  7053. }
  7054. }
  7055. if ((adv_dvc->tagqng_able & tidmask) && sdev->tagged_supported) {
  7056. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
  7057. adv_dvc->max_dvc_qng);
  7058. } else {
  7059. scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
  7060. }
  7061. }
  7062. /*
  7063. * Set the number of commands to queue per device for the
  7064. * specified host adapter.
  7065. */
  7066. static int advansys_slave_configure(struct scsi_device *sdev)
  7067. {
  7068. struct asc_board *boardp = shost_priv(sdev->host);
  7069. if (ASC_NARROW_BOARD(boardp))
  7070. advansys_narrow_slave_configure(sdev,
  7071. &boardp->dvc_var.asc_dvc_var);
  7072. else
  7073. advansys_wide_slave_configure(sdev,
  7074. &boardp->dvc_var.adv_dvc_var);
  7075. return 0;
  7076. }
  7077. static __le32 advansys_get_sense_buffer_dma(struct scsi_cmnd *scp)
  7078. {
  7079. struct asc_board *board = shost_priv(scp->device->host);
  7080. scp->SCp.dma_handle = dma_map_single(board->dev, scp->sense_buffer,
  7081. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  7082. dma_cache_sync(board->dev, scp->sense_buffer,
  7083. SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
  7084. return cpu_to_le32(scp->SCp.dma_handle);
  7085. }
  7086. static int asc_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
  7087. struct asc_scsi_q *asc_scsi_q)
  7088. {
  7089. struct asc_dvc_var *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  7090. int use_sg;
  7091. memset(asc_scsi_q, 0, sizeof(*asc_scsi_q));
  7092. /*
  7093. * Point the ASC_SCSI_Q to the 'struct scsi_cmnd'.
  7094. */
  7095. asc_scsi_q->q2.srb_ptr = advansys_ptr_to_srb(asc_dvc, scp);
  7096. if (asc_scsi_q->q2.srb_ptr == BAD_SRB) {
  7097. scp->result = HOST_BYTE(DID_SOFT_ERROR);
  7098. return ASC_ERROR;
  7099. }
  7100. /*
  7101. * Build the ASC_SCSI_Q request.
  7102. */
  7103. asc_scsi_q->cdbptr = &scp->cmnd[0];
  7104. asc_scsi_q->q2.cdb_len = scp->cmd_len;
  7105. asc_scsi_q->q1.target_id = ASC_TID_TO_TARGET_ID(scp->device->id);
  7106. asc_scsi_q->q1.target_lun = scp->device->lun;
  7107. asc_scsi_q->q2.target_ix =
  7108. ASC_TIDLUN_TO_IX(scp->device->id, scp->device->lun);
  7109. asc_scsi_q->q1.sense_addr = advansys_get_sense_buffer_dma(scp);
  7110. asc_scsi_q->q1.sense_len = SCSI_SENSE_BUFFERSIZE;
  7111. /*
  7112. * If there are any outstanding requests for the current target,
  7113. * then every 255th request send an ORDERED request. This heuristic
  7114. * tries to retain the benefit of request sorting while preventing
  7115. * request starvation. 255 is the max number of tags or pending commands
  7116. * a device may have outstanding.
  7117. *
  7118. * The request count is incremented below for every successfully
  7119. * started request.
  7120. *
  7121. */
  7122. if ((asc_dvc->cur_dvc_qng[scp->device->id] > 0) &&
  7123. (boardp->reqcnt[scp->device->id] % 255) == 0) {
  7124. asc_scsi_q->q2.tag_code = MSG_ORDERED_TAG;
  7125. } else {
  7126. asc_scsi_q->q2.tag_code = MSG_SIMPLE_TAG;
  7127. }
  7128. /* Build ASC_SCSI_Q */
  7129. use_sg = scsi_dma_map(scp);
  7130. if (use_sg != 0) {
  7131. int sgcnt;
  7132. struct scatterlist *slp;
  7133. struct asc_sg_head *asc_sg_head;
  7134. if (use_sg > scp->device->host->sg_tablesize) {
  7135. scmd_printk(KERN_ERR, scp, "use_sg %d > "
  7136. "sg_tablesize %d\n", use_sg,
  7137. scp->device->host->sg_tablesize);
  7138. scsi_dma_unmap(scp);
  7139. scp->result = HOST_BYTE(DID_ERROR);
  7140. return ASC_ERROR;
  7141. }
  7142. asc_sg_head = kzalloc(sizeof(asc_scsi_q->sg_head) +
  7143. use_sg * sizeof(struct asc_sg_list), GFP_ATOMIC);
  7144. if (!asc_sg_head) {
  7145. scsi_dma_unmap(scp);
  7146. scp->result = HOST_BYTE(DID_SOFT_ERROR);
  7147. return ASC_ERROR;
  7148. }
  7149. asc_scsi_q->q1.cntl |= QC_SG_HEAD;
  7150. asc_scsi_q->sg_head = asc_sg_head;
  7151. asc_scsi_q->q1.data_cnt = 0;
  7152. asc_scsi_q->q1.data_addr = 0;
  7153. /* This is a byte value, otherwise it would need to be swapped. */
  7154. asc_sg_head->entry_cnt = asc_scsi_q->q1.sg_queue_cnt = use_sg;
  7155. ASC_STATS_ADD(scp->device->host, xfer_elem,
  7156. asc_sg_head->entry_cnt);
  7157. /*
  7158. * Convert scatter-gather list into ASC_SG_HEAD list.
  7159. */
  7160. scsi_for_each_sg(scp, slp, use_sg, sgcnt) {
  7161. asc_sg_head->sg_list[sgcnt].addr =
  7162. cpu_to_le32(sg_dma_address(slp));
  7163. asc_sg_head->sg_list[sgcnt].bytes =
  7164. cpu_to_le32(sg_dma_len(slp));
  7165. ASC_STATS_ADD(scp->device->host, xfer_sect,
  7166. DIV_ROUND_UP(sg_dma_len(slp), 512));
  7167. }
  7168. }
  7169. ASC_STATS(scp->device->host, xfer_cnt);
  7170. ASC_DBG_PRT_ASC_SCSI_Q(2, asc_scsi_q);
  7171. ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
  7172. return ASC_NOERROR;
  7173. }
  7174. /*
  7175. * Build scatter-gather list for Adv Library (Wide Board).
  7176. *
  7177. * Additional ADV_SG_BLOCK structures will need to be allocated
  7178. * if the total number of scatter-gather elements exceeds
  7179. * NO_OF_SG_PER_BLOCK (15). The ADV_SG_BLOCK structures are
  7180. * assumed to be physically contiguous.
  7181. *
  7182. * Return:
  7183. * ADV_SUCCESS(1) - SG List successfully created
  7184. * ADV_ERROR(-1) - SG List creation failed
  7185. */
  7186. static int
  7187. adv_get_sglist(struct asc_board *boardp, adv_req_t *reqp, struct scsi_cmnd *scp,
  7188. int use_sg)
  7189. {
  7190. adv_sgblk_t *sgblkp;
  7191. ADV_SCSI_REQ_Q *scsiqp;
  7192. struct scatterlist *slp;
  7193. int sg_elem_cnt;
  7194. ADV_SG_BLOCK *sg_block, *prev_sg_block;
  7195. ADV_PADDR sg_block_paddr;
  7196. int i;
  7197. scsiqp = (ADV_SCSI_REQ_Q *)ADV_32BALIGN(&reqp->scsi_req_q);
  7198. slp = scsi_sglist(scp);
  7199. sg_elem_cnt = use_sg;
  7200. prev_sg_block = NULL;
  7201. reqp->sgblkp = NULL;
  7202. for (;;) {
  7203. /*
  7204. * Allocate a 'adv_sgblk_t' structure from the board free
  7205. * list. One 'adv_sgblk_t' structure holds NO_OF_SG_PER_BLOCK
  7206. * (15) scatter-gather elements.
  7207. */
  7208. if ((sgblkp = boardp->adv_sgblkp) == NULL) {
  7209. ASC_DBG(1, "no free adv_sgblk_t\n");
  7210. ASC_STATS(scp->device->host, adv_build_nosg);
  7211. /*
  7212. * Allocation failed. Free 'adv_sgblk_t' structures
  7213. * already allocated for the request.
  7214. */
  7215. while ((sgblkp = reqp->sgblkp) != NULL) {
  7216. /* Remove 'sgblkp' from the request list. */
  7217. reqp->sgblkp = sgblkp->next_sgblkp;
  7218. /* Add 'sgblkp' to the board free list. */
  7219. sgblkp->next_sgblkp = boardp->adv_sgblkp;
  7220. boardp->adv_sgblkp = sgblkp;
  7221. }
  7222. return ASC_BUSY;
  7223. }
  7224. /* Complete 'adv_sgblk_t' board allocation. */
  7225. boardp->adv_sgblkp = sgblkp->next_sgblkp;
  7226. sgblkp->next_sgblkp = NULL;
  7227. /*
  7228. * Get 8 byte aligned virtual and physical addresses
  7229. * for the allocated ADV_SG_BLOCK structure.
  7230. */
  7231. sg_block = (ADV_SG_BLOCK *)ADV_8BALIGN(&sgblkp->sg_block);
  7232. sg_block_paddr = virt_to_bus(sg_block);
  7233. /*
  7234. * Check if this is the first 'adv_sgblk_t' for the
  7235. * request.
  7236. */
  7237. if (reqp->sgblkp == NULL) {
  7238. /* Request's first scatter-gather block. */
  7239. reqp->sgblkp = sgblkp;
  7240. /*
  7241. * Set ADV_SCSI_REQ_T ADV_SG_BLOCK virtual and physical
  7242. * address pointers.
  7243. */
  7244. scsiqp->sg_list_ptr = sg_block;
  7245. scsiqp->sg_real_addr = cpu_to_le32(sg_block_paddr);
  7246. } else {
  7247. /* Request's second or later scatter-gather block. */
  7248. sgblkp->next_sgblkp = reqp->sgblkp;
  7249. reqp->sgblkp = sgblkp;
  7250. /*
  7251. * Point the previous ADV_SG_BLOCK structure to
  7252. * the newly allocated ADV_SG_BLOCK structure.
  7253. */
  7254. prev_sg_block->sg_ptr = cpu_to_le32(sg_block_paddr);
  7255. }
  7256. for (i = 0; i < NO_OF_SG_PER_BLOCK; i++) {
  7257. sg_block->sg_list[i].sg_addr =
  7258. cpu_to_le32(sg_dma_address(slp));
  7259. sg_block->sg_list[i].sg_count =
  7260. cpu_to_le32(sg_dma_len(slp));
  7261. ASC_STATS_ADD(scp->device->host, xfer_sect,
  7262. DIV_ROUND_UP(sg_dma_len(slp), 512));
  7263. if (--sg_elem_cnt == 0) { /* Last ADV_SG_BLOCK and scatter-gather entry. */
  7264. sg_block->sg_cnt = i + 1;
  7265. sg_block->sg_ptr = 0L; /* Last ADV_SG_BLOCK in list. */
  7266. return ADV_SUCCESS;
  7267. }
  7268. slp++;
  7269. }
  7270. sg_block->sg_cnt = NO_OF_SG_PER_BLOCK;
  7271. prev_sg_block = sg_block;
  7272. }
  7273. }
  7274. /*
  7275. * Build a request structure for the Adv Library (Wide Board).
  7276. *
  7277. * If an adv_req_t can not be allocated to issue the request,
  7278. * then return ASC_BUSY. If an error occurs, then return ASC_ERROR.
  7279. *
  7280. * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the
  7281. * microcode for DMA addresses or math operations are byte swapped
  7282. * to little-endian order.
  7283. */
  7284. static int
  7285. adv_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
  7286. ADV_SCSI_REQ_Q **adv_scsiqpp)
  7287. {
  7288. adv_req_t *reqp;
  7289. ADV_SCSI_REQ_Q *scsiqp;
  7290. int i;
  7291. int ret;
  7292. int use_sg;
  7293. /*
  7294. * Allocate an adv_req_t structure from the board to execute
  7295. * the command.
  7296. */
  7297. if (boardp->adv_reqp == NULL) {
  7298. ASC_DBG(1, "no free adv_req_t\n");
  7299. ASC_STATS(scp->device->host, adv_build_noreq);
  7300. return ASC_BUSY;
  7301. } else {
  7302. reqp = boardp->adv_reqp;
  7303. boardp->adv_reqp = reqp->next_reqp;
  7304. reqp->next_reqp = NULL;
  7305. }
  7306. /*
  7307. * Get 32-byte aligned ADV_SCSI_REQ_Q and ADV_SG_BLOCK pointers.
  7308. */
  7309. scsiqp = (ADV_SCSI_REQ_Q *)ADV_32BALIGN(&reqp->scsi_req_q);
  7310. /*
  7311. * Initialize the structure.
  7312. */
  7313. scsiqp->cntl = scsiqp->scsi_cntl = scsiqp->done_status = 0;
  7314. /*
  7315. * Set the ADV_SCSI_REQ_Q 'srb_ptr' to point to the adv_req_t structure.
  7316. */
  7317. scsiqp->srb_ptr = ADV_VADDR_TO_U32(reqp);
  7318. /*
  7319. * Set the adv_req_t 'cmndp' to point to the struct scsi_cmnd structure.
  7320. */
  7321. reqp->cmndp = scp;
  7322. /*
  7323. * Build the ADV_SCSI_REQ_Q request.
  7324. */
  7325. /* Set CDB length and copy it to the request structure. */
  7326. scsiqp->cdb_len = scp->cmd_len;
  7327. /* Copy first 12 CDB bytes to cdb[]. */
  7328. for (i = 0; i < scp->cmd_len && i < 12; i++) {
  7329. scsiqp->cdb[i] = scp->cmnd[i];
  7330. }
  7331. /* Copy last 4 CDB bytes, if present, to cdb16[]. */
  7332. for (; i < scp->cmd_len; i++) {
  7333. scsiqp->cdb16[i - 12] = scp->cmnd[i];
  7334. }
  7335. scsiqp->target_id = scp->device->id;
  7336. scsiqp->target_lun = scp->device->lun;
  7337. scsiqp->sense_addr = cpu_to_le32(virt_to_bus(&scp->sense_buffer[0]));
  7338. scsiqp->sense_len = SCSI_SENSE_BUFFERSIZE;
  7339. /* Build ADV_SCSI_REQ_Q */
  7340. use_sg = scsi_dma_map(scp);
  7341. if (use_sg == 0) {
  7342. /* Zero-length transfer */
  7343. reqp->sgblkp = NULL;
  7344. scsiqp->data_cnt = 0;
  7345. scsiqp->vdata_addr = NULL;
  7346. scsiqp->data_addr = 0;
  7347. scsiqp->sg_list_ptr = NULL;
  7348. scsiqp->sg_real_addr = 0;
  7349. } else {
  7350. if (use_sg > ADV_MAX_SG_LIST) {
  7351. scmd_printk(KERN_ERR, scp, "use_sg %d > "
  7352. "ADV_MAX_SG_LIST %d\n", use_sg,
  7353. scp->device->host->sg_tablesize);
  7354. scsi_dma_unmap(scp);
  7355. scp->result = HOST_BYTE(DID_ERROR);
  7356. /*
  7357. * Free the 'adv_req_t' structure by adding it back
  7358. * to the board free list.
  7359. */
  7360. reqp->next_reqp = boardp->adv_reqp;
  7361. boardp->adv_reqp = reqp;
  7362. return ASC_ERROR;
  7363. }
  7364. scsiqp->data_cnt = cpu_to_le32(scsi_bufflen(scp));
  7365. ret = adv_get_sglist(boardp, reqp, scp, use_sg);
  7366. if (ret != ADV_SUCCESS) {
  7367. /*
  7368. * Free the adv_req_t structure by adding it back to
  7369. * the board free list.
  7370. */
  7371. reqp->next_reqp = boardp->adv_reqp;
  7372. boardp->adv_reqp = reqp;
  7373. return ret;
  7374. }
  7375. ASC_STATS_ADD(scp->device->host, xfer_elem, use_sg);
  7376. }
  7377. ASC_STATS(scp->device->host, xfer_cnt);
  7378. ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
  7379. ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
  7380. *adv_scsiqpp = scsiqp;
  7381. return ASC_NOERROR;
  7382. }
  7383. static int AscSgListToQueue(int sg_list)
  7384. {
  7385. int n_sg_list_qs;
  7386. n_sg_list_qs = ((sg_list - 1) / ASC_SG_LIST_PER_Q);
  7387. if (((sg_list - 1) % ASC_SG_LIST_PER_Q) != 0)
  7388. n_sg_list_qs++;
  7389. return n_sg_list_qs + 1;
  7390. }
  7391. static uint
  7392. AscGetNumOfFreeQueue(ASC_DVC_VAR *asc_dvc, uchar target_ix, uchar n_qs)
  7393. {
  7394. uint cur_used_qs;
  7395. uint cur_free_qs;
  7396. ASC_SCSI_BIT_ID_TYPE target_id;
  7397. uchar tid_no;
  7398. target_id = ASC_TIX_TO_TARGET_ID(target_ix);
  7399. tid_no = ASC_TIX_TO_TID(target_ix);
  7400. if ((asc_dvc->unit_not_ready & target_id) ||
  7401. (asc_dvc->queue_full_or_busy & target_id)) {
  7402. return 0;
  7403. }
  7404. if (n_qs == 1) {
  7405. cur_used_qs = (uint) asc_dvc->cur_total_qng +
  7406. (uint) asc_dvc->last_q_shortage + (uint) ASC_MIN_FREE_Q;
  7407. } else {
  7408. cur_used_qs = (uint) asc_dvc->cur_total_qng +
  7409. (uint) ASC_MIN_FREE_Q;
  7410. }
  7411. if ((uint) (cur_used_qs + n_qs) <= (uint) asc_dvc->max_total_qng) {
  7412. cur_free_qs = (uint) asc_dvc->max_total_qng - cur_used_qs;
  7413. if (asc_dvc->cur_dvc_qng[tid_no] >=
  7414. asc_dvc->max_dvc_qng[tid_no]) {
  7415. return 0;
  7416. }
  7417. return cur_free_qs;
  7418. }
  7419. if (n_qs > 1) {
  7420. if ((n_qs > asc_dvc->last_q_shortage)
  7421. && (n_qs <= (asc_dvc->max_total_qng - ASC_MIN_FREE_Q))) {
  7422. asc_dvc->last_q_shortage = n_qs;
  7423. }
  7424. }
  7425. return 0;
  7426. }
  7427. static uchar AscAllocFreeQueue(PortAddr iop_base, uchar free_q_head)
  7428. {
  7429. ushort q_addr;
  7430. uchar next_qp;
  7431. uchar q_status;
  7432. q_addr = ASC_QNO_TO_QADDR(free_q_head);
  7433. q_status = (uchar)AscReadLramByte(iop_base,
  7434. (ushort)(q_addr +
  7435. ASC_SCSIQ_B_STATUS));
  7436. next_qp = AscReadLramByte(iop_base, (ushort)(q_addr + ASC_SCSIQ_B_FWD));
  7437. if (((q_status & QS_READY) == 0) && (next_qp != ASC_QLINK_END))
  7438. return next_qp;
  7439. return ASC_QLINK_END;
  7440. }
  7441. static uchar
  7442. AscAllocMultipleFreeQueue(PortAddr iop_base, uchar free_q_head, uchar n_free_q)
  7443. {
  7444. uchar i;
  7445. for (i = 0; i < n_free_q; i++) {
  7446. free_q_head = AscAllocFreeQueue(iop_base, free_q_head);
  7447. if (free_q_head == ASC_QLINK_END)
  7448. break;
  7449. }
  7450. return free_q_head;
  7451. }
  7452. /*
  7453. * void
  7454. * DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
  7455. *
  7456. * Calling/Exit State:
  7457. * none
  7458. *
  7459. * Description:
  7460. * Output an ASC_SCSI_Q structure to the chip
  7461. */
  7462. static void
  7463. DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
  7464. {
  7465. int i;
  7466. ASC_DBG_PRT_HEX(2, "DvcPutScsiQ", outbuf, 2 * words);
  7467. AscSetChipLramAddr(iop_base, s_addr);
  7468. for (i = 0; i < 2 * words; i += 2) {
  7469. if (i == 4 || i == 20) {
  7470. continue;
  7471. }
  7472. outpw(iop_base + IOP_RAM_DATA,
  7473. ((ushort)outbuf[i + 1] << 8) | outbuf[i]);
  7474. }
  7475. }
  7476. static int AscPutReadyQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
  7477. {
  7478. ushort q_addr;
  7479. uchar tid_no;
  7480. uchar sdtr_data;
  7481. uchar syn_period_ix;
  7482. uchar syn_offset;
  7483. PortAddr iop_base;
  7484. iop_base = asc_dvc->iop_base;
  7485. if (((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) &&
  7486. ((asc_dvc->sdtr_done & scsiq->q1.target_id) == 0)) {
  7487. tid_no = ASC_TIX_TO_TID(scsiq->q2.target_ix);
  7488. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  7489. syn_period_ix =
  7490. (sdtr_data >> 4) & (asc_dvc->max_sdtr_index - 1);
  7491. syn_offset = sdtr_data & ASC_SYN_MAX_OFFSET;
  7492. AscMsgOutSDTR(asc_dvc,
  7493. asc_dvc->sdtr_period_tbl[syn_period_ix],
  7494. syn_offset);
  7495. scsiq->q1.cntl |= QC_MSG_OUT;
  7496. }
  7497. q_addr = ASC_QNO_TO_QADDR(q_no);
  7498. if ((scsiq->q1.target_id & asc_dvc->use_tagged_qng) == 0) {
  7499. scsiq->q2.tag_code &= ~MSG_SIMPLE_TAG;
  7500. }
  7501. scsiq->q1.status = QS_FREE;
  7502. AscMemWordCopyPtrToLram(iop_base,
  7503. q_addr + ASC_SCSIQ_CDB_BEG,
  7504. (uchar *)scsiq->cdbptr, scsiq->q2.cdb_len >> 1);
  7505. DvcPutScsiQ(iop_base,
  7506. q_addr + ASC_SCSIQ_CPY_BEG,
  7507. (uchar *)&scsiq->q1.cntl,
  7508. ((sizeof(ASC_SCSIQ_1) + sizeof(ASC_SCSIQ_2)) / 2) - 1);
  7509. AscWriteLramWord(iop_base,
  7510. (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS),
  7511. (ushort)(((ushort)scsiq->q1.
  7512. q_no << 8) | (ushort)QS_READY));
  7513. return 1;
  7514. }
  7515. static int
  7516. AscPutReadySgListQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no)
  7517. {
  7518. int sta;
  7519. int i;
  7520. ASC_SG_HEAD *sg_head;
  7521. ASC_SG_LIST_Q scsi_sg_q;
  7522. ASC_DCNT saved_data_addr;
  7523. ASC_DCNT saved_data_cnt;
  7524. PortAddr iop_base;
  7525. ushort sg_list_dwords;
  7526. ushort sg_index;
  7527. ushort sg_entry_cnt;
  7528. ushort q_addr;
  7529. uchar next_qp;
  7530. iop_base = asc_dvc->iop_base;
  7531. sg_head = scsiq->sg_head;
  7532. saved_data_addr = scsiq->q1.data_addr;
  7533. saved_data_cnt = scsiq->q1.data_cnt;
  7534. scsiq->q1.data_addr = (ASC_PADDR) sg_head->sg_list[0].addr;
  7535. scsiq->q1.data_cnt = (ASC_DCNT) sg_head->sg_list[0].bytes;
  7536. #if CC_VERY_LONG_SG_LIST
  7537. /*
  7538. * If sg_head->entry_cnt is greater than ASC_MAX_SG_LIST
  7539. * then not all SG elements will fit in the allocated queues.
  7540. * The rest of the SG elements will be copied when the RISC
  7541. * completes the SG elements that fit and halts.
  7542. */
  7543. if (sg_head->entry_cnt > ASC_MAX_SG_LIST) {
  7544. /*
  7545. * Set sg_entry_cnt to be the number of SG elements that
  7546. * will fit in the allocated SG queues. It is minus 1, because
  7547. * the first SG element is handled above. ASC_MAX_SG_LIST is
  7548. * already inflated by 1 to account for this. For example it
  7549. * may be 50 which is 1 + 7 queues * 7 SG elements.
  7550. */
  7551. sg_entry_cnt = ASC_MAX_SG_LIST - 1;
  7552. /*
  7553. * Keep track of remaining number of SG elements that will
  7554. * need to be handled from a_isr.c.
  7555. */
  7556. scsiq->remain_sg_entry_cnt =
  7557. sg_head->entry_cnt - ASC_MAX_SG_LIST;
  7558. } else {
  7559. #endif /* CC_VERY_LONG_SG_LIST */
  7560. /*
  7561. * Set sg_entry_cnt to be the number of SG elements that
  7562. * will fit in the allocated SG queues. It is minus 1, because
  7563. * the first SG element is handled above.
  7564. */
  7565. sg_entry_cnt = sg_head->entry_cnt - 1;
  7566. #if CC_VERY_LONG_SG_LIST
  7567. }
  7568. #endif /* CC_VERY_LONG_SG_LIST */
  7569. if (sg_entry_cnt != 0) {
  7570. scsiq->q1.cntl |= QC_SG_HEAD;
  7571. q_addr = ASC_QNO_TO_QADDR(q_no);
  7572. sg_index = 1;
  7573. scsiq->q1.sg_queue_cnt = sg_head->queue_cnt;
  7574. scsi_sg_q.sg_head_qp = q_no;
  7575. scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
  7576. for (i = 0; i < sg_head->queue_cnt; i++) {
  7577. scsi_sg_q.seq_no = i + 1;
  7578. if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
  7579. sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2);
  7580. sg_entry_cnt -= ASC_SG_LIST_PER_Q;
  7581. if (i == 0) {
  7582. scsi_sg_q.sg_list_cnt =
  7583. ASC_SG_LIST_PER_Q;
  7584. scsi_sg_q.sg_cur_list_cnt =
  7585. ASC_SG_LIST_PER_Q;
  7586. } else {
  7587. scsi_sg_q.sg_list_cnt =
  7588. ASC_SG_LIST_PER_Q - 1;
  7589. scsi_sg_q.sg_cur_list_cnt =
  7590. ASC_SG_LIST_PER_Q - 1;
  7591. }
  7592. } else {
  7593. #if CC_VERY_LONG_SG_LIST
  7594. /*
  7595. * This is the last SG queue in the list of
  7596. * allocated SG queues. If there are more
  7597. * SG elements than will fit in the allocated
  7598. * queues, then set the QCSG_SG_XFER_MORE flag.
  7599. */
  7600. if (sg_head->entry_cnt > ASC_MAX_SG_LIST) {
  7601. scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
  7602. } else {
  7603. #endif /* CC_VERY_LONG_SG_LIST */
  7604. scsi_sg_q.cntl |= QCSG_SG_XFER_END;
  7605. #if CC_VERY_LONG_SG_LIST
  7606. }
  7607. #endif /* CC_VERY_LONG_SG_LIST */
  7608. sg_list_dwords = sg_entry_cnt << 1;
  7609. if (i == 0) {
  7610. scsi_sg_q.sg_list_cnt = sg_entry_cnt;
  7611. scsi_sg_q.sg_cur_list_cnt =
  7612. sg_entry_cnt;
  7613. } else {
  7614. scsi_sg_q.sg_list_cnt =
  7615. sg_entry_cnt - 1;
  7616. scsi_sg_q.sg_cur_list_cnt =
  7617. sg_entry_cnt - 1;
  7618. }
  7619. sg_entry_cnt = 0;
  7620. }
  7621. next_qp = AscReadLramByte(iop_base,
  7622. (ushort)(q_addr +
  7623. ASC_SCSIQ_B_FWD));
  7624. scsi_sg_q.q_no = next_qp;
  7625. q_addr = ASC_QNO_TO_QADDR(next_qp);
  7626. AscMemWordCopyPtrToLram(iop_base,
  7627. q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
  7628. (uchar *)&scsi_sg_q,
  7629. sizeof(ASC_SG_LIST_Q) >> 1);
  7630. AscMemDWordCopyPtrToLram(iop_base,
  7631. q_addr + ASC_SGQ_LIST_BEG,
  7632. (uchar *)&sg_head->
  7633. sg_list[sg_index],
  7634. sg_list_dwords);
  7635. sg_index += ASC_SG_LIST_PER_Q;
  7636. scsiq->next_sg_index = sg_index;
  7637. }
  7638. } else {
  7639. scsiq->q1.cntl &= ~QC_SG_HEAD;
  7640. }
  7641. sta = AscPutReadyQueue(asc_dvc, scsiq, q_no);
  7642. scsiq->q1.data_addr = saved_data_addr;
  7643. scsiq->q1.data_cnt = saved_data_cnt;
  7644. return (sta);
  7645. }
  7646. static int
  7647. AscSendScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar n_q_required)
  7648. {
  7649. PortAddr iop_base;
  7650. uchar free_q_head;
  7651. uchar next_qp;
  7652. uchar tid_no;
  7653. uchar target_ix;
  7654. int sta;
  7655. iop_base = asc_dvc->iop_base;
  7656. target_ix = scsiq->q2.target_ix;
  7657. tid_no = ASC_TIX_TO_TID(target_ix);
  7658. sta = 0;
  7659. free_q_head = (uchar)AscGetVarFreeQHead(iop_base);
  7660. if (n_q_required > 1) {
  7661. next_qp = AscAllocMultipleFreeQueue(iop_base, free_q_head,
  7662. (uchar)n_q_required);
  7663. if (next_qp != ASC_QLINK_END) {
  7664. asc_dvc->last_q_shortage = 0;
  7665. scsiq->sg_head->queue_cnt = n_q_required - 1;
  7666. scsiq->q1.q_no = free_q_head;
  7667. sta = AscPutReadySgListQueue(asc_dvc, scsiq,
  7668. free_q_head);
  7669. }
  7670. } else if (n_q_required == 1) {
  7671. next_qp = AscAllocFreeQueue(iop_base, free_q_head);
  7672. if (next_qp != ASC_QLINK_END) {
  7673. scsiq->q1.q_no = free_q_head;
  7674. sta = AscPutReadyQueue(asc_dvc, scsiq, free_q_head);
  7675. }
  7676. }
  7677. if (sta == 1) {
  7678. AscPutVarFreeQHead(iop_base, next_qp);
  7679. asc_dvc->cur_total_qng += n_q_required;
  7680. asc_dvc->cur_dvc_qng[tid_no]++;
  7681. }
  7682. return sta;
  7683. }
  7684. #define ASC_SYN_OFFSET_ONE_DISABLE_LIST 16
  7685. static uchar _syn_offset_one_disable_cmd[ASC_SYN_OFFSET_ONE_DISABLE_LIST] = {
  7686. INQUIRY,
  7687. REQUEST_SENSE,
  7688. READ_CAPACITY,
  7689. READ_TOC,
  7690. MODE_SELECT,
  7691. MODE_SENSE,
  7692. MODE_SELECT_10,
  7693. MODE_SENSE_10,
  7694. 0xFF,
  7695. 0xFF,
  7696. 0xFF,
  7697. 0xFF,
  7698. 0xFF,
  7699. 0xFF,
  7700. 0xFF,
  7701. 0xFF
  7702. };
  7703. static int AscExeScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq)
  7704. {
  7705. PortAddr iop_base;
  7706. int sta;
  7707. int n_q_required;
  7708. int disable_syn_offset_one_fix;
  7709. int i;
  7710. ASC_PADDR addr;
  7711. ushort sg_entry_cnt = 0;
  7712. ushort sg_entry_cnt_minus_one = 0;
  7713. uchar target_ix;
  7714. uchar tid_no;
  7715. uchar sdtr_data;
  7716. uchar extra_bytes;
  7717. uchar scsi_cmd;
  7718. uchar disable_cmd;
  7719. ASC_SG_HEAD *sg_head;
  7720. ASC_DCNT data_cnt;
  7721. iop_base = asc_dvc->iop_base;
  7722. sg_head = scsiq->sg_head;
  7723. if (asc_dvc->err_code != 0)
  7724. return (ERR);
  7725. scsiq->q1.q_no = 0;
  7726. if ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES) == 0) {
  7727. scsiq->q1.extra_bytes = 0;
  7728. }
  7729. sta = 0;
  7730. target_ix = scsiq->q2.target_ix;
  7731. tid_no = ASC_TIX_TO_TID(target_ix);
  7732. n_q_required = 1;
  7733. if (scsiq->cdbptr[0] == REQUEST_SENSE) {
  7734. if ((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) {
  7735. asc_dvc->sdtr_done &= ~scsiq->q1.target_id;
  7736. sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
  7737. AscMsgOutSDTR(asc_dvc,
  7738. asc_dvc->
  7739. sdtr_period_tbl[(sdtr_data >> 4) &
  7740. (uchar)(asc_dvc->
  7741. max_sdtr_index -
  7742. 1)],
  7743. (uchar)(sdtr_data & (uchar)
  7744. ASC_SYN_MAX_OFFSET));
  7745. scsiq->q1.cntl |= (QC_MSG_OUT | QC_URGENT);
  7746. }
  7747. }
  7748. if (asc_dvc->in_critical_cnt != 0) {
  7749. AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CRITICAL_RE_ENTRY);
  7750. return (ERR);
  7751. }
  7752. asc_dvc->in_critical_cnt++;
  7753. if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
  7754. if ((sg_entry_cnt = sg_head->entry_cnt) == 0) {
  7755. asc_dvc->in_critical_cnt--;
  7756. return (ERR);
  7757. }
  7758. #if !CC_VERY_LONG_SG_LIST
  7759. if (sg_entry_cnt > ASC_MAX_SG_LIST) {
  7760. asc_dvc->in_critical_cnt--;
  7761. return (ERR);
  7762. }
  7763. #endif /* !CC_VERY_LONG_SG_LIST */
  7764. if (sg_entry_cnt == 1) {
  7765. scsiq->q1.data_addr =
  7766. (ADV_PADDR)sg_head->sg_list[0].addr;
  7767. scsiq->q1.data_cnt =
  7768. (ADV_DCNT)sg_head->sg_list[0].bytes;
  7769. scsiq->q1.cntl &= ~(QC_SG_HEAD | QC_SG_SWAP_QUEUE);
  7770. }
  7771. sg_entry_cnt_minus_one = sg_entry_cnt - 1;
  7772. }
  7773. scsi_cmd = scsiq->cdbptr[0];
  7774. disable_syn_offset_one_fix = FALSE;
  7775. if ((asc_dvc->pci_fix_asyn_xfer & scsiq->q1.target_id) &&
  7776. !(asc_dvc->pci_fix_asyn_xfer_always & scsiq->q1.target_id)) {
  7777. if (scsiq->q1.cntl & QC_SG_HEAD) {
  7778. data_cnt = 0;
  7779. for (i = 0; i < sg_entry_cnt; i++) {
  7780. data_cnt +=
  7781. (ADV_DCNT)le32_to_cpu(sg_head->sg_list[i].
  7782. bytes);
  7783. }
  7784. } else {
  7785. data_cnt = le32_to_cpu(scsiq->q1.data_cnt);
  7786. }
  7787. if (data_cnt != 0UL) {
  7788. if (data_cnt < 512UL) {
  7789. disable_syn_offset_one_fix = TRUE;
  7790. } else {
  7791. for (i = 0; i < ASC_SYN_OFFSET_ONE_DISABLE_LIST;
  7792. i++) {
  7793. disable_cmd =
  7794. _syn_offset_one_disable_cmd[i];
  7795. if (disable_cmd == 0xFF) {
  7796. break;
  7797. }
  7798. if (scsi_cmd == disable_cmd) {
  7799. disable_syn_offset_one_fix =
  7800. TRUE;
  7801. break;
  7802. }
  7803. }
  7804. }
  7805. }
  7806. }
  7807. if (disable_syn_offset_one_fix) {
  7808. scsiq->q2.tag_code &= ~MSG_SIMPLE_TAG;
  7809. scsiq->q2.tag_code |= (ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX |
  7810. ASC_TAG_FLAG_DISABLE_DISCONNECT);
  7811. } else {
  7812. scsiq->q2.tag_code &= 0x27;
  7813. }
  7814. if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
  7815. if (asc_dvc->bug_fix_cntl) {
  7816. if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
  7817. if ((scsi_cmd == READ_6) ||
  7818. (scsi_cmd == READ_10)) {
  7819. addr =
  7820. (ADV_PADDR)le32_to_cpu(sg_head->
  7821. sg_list
  7822. [sg_entry_cnt_minus_one].
  7823. addr) +
  7824. (ADV_DCNT)le32_to_cpu(sg_head->
  7825. sg_list
  7826. [sg_entry_cnt_minus_one].
  7827. bytes);
  7828. extra_bytes =
  7829. (uchar)((ushort)addr & 0x0003);
  7830. if ((extra_bytes != 0)
  7831. &&
  7832. ((scsiq->q2.
  7833. tag_code &
  7834. ASC_TAG_FLAG_EXTRA_BYTES)
  7835. == 0)) {
  7836. scsiq->q2.tag_code |=
  7837. ASC_TAG_FLAG_EXTRA_BYTES;
  7838. scsiq->q1.extra_bytes =
  7839. extra_bytes;
  7840. data_cnt =
  7841. le32_to_cpu(sg_head->
  7842. sg_list
  7843. [sg_entry_cnt_minus_one].
  7844. bytes);
  7845. data_cnt -=
  7846. (ASC_DCNT) extra_bytes;
  7847. sg_head->
  7848. sg_list
  7849. [sg_entry_cnt_minus_one].
  7850. bytes =
  7851. cpu_to_le32(data_cnt);
  7852. }
  7853. }
  7854. }
  7855. }
  7856. sg_head->entry_to_copy = sg_head->entry_cnt;
  7857. #if CC_VERY_LONG_SG_LIST
  7858. /*
  7859. * Set the sg_entry_cnt to the maximum possible. The rest of
  7860. * the SG elements will be copied when the RISC completes the
  7861. * SG elements that fit and halts.
  7862. */
  7863. if (sg_entry_cnt > ASC_MAX_SG_LIST) {
  7864. sg_entry_cnt = ASC_MAX_SG_LIST;
  7865. }
  7866. #endif /* CC_VERY_LONG_SG_LIST */
  7867. n_q_required = AscSgListToQueue(sg_entry_cnt);
  7868. if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, n_q_required) >=
  7869. (uint) n_q_required)
  7870. || ((scsiq->q1.cntl & QC_URGENT) != 0)) {
  7871. if ((sta =
  7872. AscSendScsiQueue(asc_dvc, scsiq,
  7873. n_q_required)) == 1) {
  7874. asc_dvc->in_critical_cnt--;
  7875. return (sta);
  7876. }
  7877. }
  7878. } else {
  7879. if (asc_dvc->bug_fix_cntl) {
  7880. if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
  7881. if ((scsi_cmd == READ_6) ||
  7882. (scsi_cmd == READ_10)) {
  7883. addr =
  7884. le32_to_cpu(scsiq->q1.data_addr) +
  7885. le32_to_cpu(scsiq->q1.data_cnt);
  7886. extra_bytes =
  7887. (uchar)((ushort)addr & 0x0003);
  7888. if ((extra_bytes != 0)
  7889. &&
  7890. ((scsiq->q2.
  7891. tag_code &
  7892. ASC_TAG_FLAG_EXTRA_BYTES)
  7893. == 0)) {
  7894. data_cnt =
  7895. le32_to_cpu(scsiq->q1.
  7896. data_cnt);
  7897. if (((ushort)data_cnt & 0x01FF)
  7898. == 0) {
  7899. scsiq->q2.tag_code |=
  7900. ASC_TAG_FLAG_EXTRA_BYTES;
  7901. data_cnt -= (ASC_DCNT)
  7902. extra_bytes;
  7903. scsiq->q1.data_cnt =
  7904. cpu_to_le32
  7905. (data_cnt);
  7906. scsiq->q1.extra_bytes =
  7907. extra_bytes;
  7908. }
  7909. }
  7910. }
  7911. }
  7912. }
  7913. n_q_required = 1;
  7914. if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, 1) >= 1) ||
  7915. ((scsiq->q1.cntl & QC_URGENT) != 0)) {
  7916. if ((sta = AscSendScsiQueue(asc_dvc, scsiq,
  7917. n_q_required)) == 1) {
  7918. asc_dvc->in_critical_cnt--;
  7919. return (sta);
  7920. }
  7921. }
  7922. }
  7923. asc_dvc->in_critical_cnt--;
  7924. return (sta);
  7925. }
  7926. /*
  7927. * AdvExeScsiQueue() - Send a request to the RISC microcode program.
  7928. *
  7929. * Allocate a carrier structure, point the carrier to the ADV_SCSI_REQ_Q,
  7930. * add the carrier to the ICQ (Initiator Command Queue), and tickle the
  7931. * RISC to notify it a new command is ready to be executed.
  7932. *
  7933. * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
  7934. * set to SCSI_MAX_RETRY.
  7935. *
  7936. * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the microcode
  7937. * for DMA addresses or math operations are byte swapped to little-endian
  7938. * order.
  7939. *
  7940. * Return:
  7941. * ADV_SUCCESS(1) - The request was successfully queued.
  7942. * ADV_BUSY(0) - Resource unavailable; Retry again after pending
  7943. * request completes.
  7944. * ADV_ERROR(-1) - Invalid ADV_SCSI_REQ_Q request structure
  7945. * host IC error.
  7946. */
  7947. static int AdvExeScsiQueue(ADV_DVC_VAR *asc_dvc, ADV_SCSI_REQ_Q *scsiq)
  7948. {
  7949. AdvPortAddr iop_base;
  7950. ADV_PADDR req_paddr;
  7951. ADV_CARR_T *new_carrp;
  7952. /*
  7953. * The ADV_SCSI_REQ_Q 'target_id' field should never exceed ADV_MAX_TID.
  7954. */
  7955. if (scsiq->target_id > ADV_MAX_TID) {
  7956. scsiq->host_status = QHSTA_M_INVALID_DEVICE;
  7957. scsiq->done_status = QD_WITH_ERROR;
  7958. return ADV_ERROR;
  7959. }
  7960. iop_base = asc_dvc->iop_base;
  7961. /*
  7962. * Allocate a carrier ensuring at least one carrier always
  7963. * remains on the freelist and initialize fields.
  7964. */
  7965. if ((new_carrp = asc_dvc->carr_freelist) == NULL) {
  7966. return ADV_BUSY;
  7967. }
  7968. asc_dvc->carr_freelist = (ADV_CARR_T *)
  7969. ADV_U32_TO_VADDR(le32_to_cpu(new_carrp->next_vpa));
  7970. asc_dvc->carr_pending_cnt++;
  7971. /*
  7972. * Set the carrier to be a stopper by setting 'next_vpa'
  7973. * to the stopper value. The current stopper will be changed
  7974. * below to point to the new stopper.
  7975. */
  7976. new_carrp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
  7977. /*
  7978. * Clear the ADV_SCSI_REQ_Q done flag.
  7979. */
  7980. scsiq->a_flag &= ~ADV_SCSIQ_DONE;
  7981. req_paddr = virt_to_bus(scsiq);
  7982. BUG_ON(req_paddr & 31);
  7983. /* Wait for assertion before making little-endian */
  7984. req_paddr = cpu_to_le32(req_paddr);
  7985. /* Save virtual and physical address of ADV_SCSI_REQ_Q and carrier. */
  7986. scsiq->scsiq_ptr = cpu_to_le32(ADV_VADDR_TO_U32(scsiq));
  7987. scsiq->scsiq_rptr = req_paddr;
  7988. scsiq->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->icq_sp));
  7989. /*
  7990. * Every ADV_CARR_T.carr_pa is byte swapped to little-endian
  7991. * order during initialization.
  7992. */
  7993. scsiq->carr_pa = asc_dvc->icq_sp->carr_pa;
  7994. /*
  7995. * Use the current stopper to send the ADV_SCSI_REQ_Q command to
  7996. * the microcode. The newly allocated stopper will become the new
  7997. * stopper.
  7998. */
  7999. asc_dvc->icq_sp->areq_vpa = req_paddr;
  8000. /*
  8001. * Set the 'next_vpa' pointer for the old stopper to be the
  8002. * physical address of the new stopper. The RISC can only
  8003. * follow physical addresses.
  8004. */
  8005. asc_dvc->icq_sp->next_vpa = new_carrp->carr_pa;
  8006. /*
  8007. * Set the host adapter stopper pointer to point to the new carrier.
  8008. */
  8009. asc_dvc->icq_sp = new_carrp;
  8010. if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
  8011. asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  8012. /*
  8013. * Tickle the RISC to tell it to read its Command Queue Head pointer.
  8014. */
  8015. AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A);
  8016. if (asc_dvc->chip_type == ADV_CHIP_ASC3550) {
  8017. /*
  8018. * Clear the tickle value. In the ASC-3550 the RISC flag
  8019. * command 'clr_tickle_a' does not work unless the host
  8020. * value is cleared.
  8021. */
  8022. AdvWriteByteRegister(iop_base, IOPB_TICKLE,
  8023. ADV_TICKLE_NOP);
  8024. }
  8025. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  8026. /*
  8027. * Notify the RISC a carrier is ready by writing the physical
  8028. * address of the new carrier stopper to the COMMA register.
  8029. */
  8030. AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
  8031. le32_to_cpu(new_carrp->carr_pa));
  8032. }
  8033. return ADV_SUCCESS;
  8034. }
  8035. /*
  8036. * Execute a single 'Scsi_Cmnd'.
  8037. */
  8038. static int asc_execute_scsi_cmnd(struct scsi_cmnd *scp)
  8039. {
  8040. int ret, err_code;
  8041. struct asc_board *boardp = shost_priv(scp->device->host);
  8042. ASC_DBG(1, "scp 0x%p\n", scp);
  8043. if (ASC_NARROW_BOARD(boardp)) {
  8044. ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var;
  8045. struct asc_scsi_q asc_scsi_q;
  8046. /* asc_build_req() can not return ASC_BUSY. */
  8047. ret = asc_build_req(boardp, scp, &asc_scsi_q);
  8048. if (ret == ASC_ERROR) {
  8049. ASC_STATS(scp->device->host, build_error);
  8050. return ASC_ERROR;
  8051. }
  8052. ret = AscExeScsiQueue(asc_dvc, &asc_scsi_q);
  8053. kfree(asc_scsi_q.sg_head);
  8054. err_code = asc_dvc->err_code;
  8055. } else {
  8056. ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var;
  8057. ADV_SCSI_REQ_Q *adv_scsiqp;
  8058. switch (adv_build_req(boardp, scp, &adv_scsiqp)) {
  8059. case ASC_NOERROR:
  8060. ASC_DBG(3, "adv_build_req ASC_NOERROR\n");
  8061. break;
  8062. case ASC_BUSY:
  8063. ASC_DBG(1, "adv_build_req ASC_BUSY\n");
  8064. /*
  8065. * The asc_stats fields 'adv_build_noreq' and
  8066. * 'adv_build_nosg' count wide board busy conditions.
  8067. * They are updated in adv_build_req and
  8068. * adv_get_sglist, respectively.
  8069. */
  8070. return ASC_BUSY;
  8071. case ASC_ERROR:
  8072. default:
  8073. ASC_DBG(1, "adv_build_req ASC_ERROR\n");
  8074. ASC_STATS(scp->device->host, build_error);
  8075. return ASC_ERROR;
  8076. }
  8077. ret = AdvExeScsiQueue(adv_dvc, adv_scsiqp);
  8078. err_code = adv_dvc->err_code;
  8079. }
  8080. switch (ret) {
  8081. case ASC_NOERROR:
  8082. ASC_STATS(scp->device->host, exe_noerror);
  8083. /*
  8084. * Increment monotonically increasing per device
  8085. * successful request counter. Wrapping doesn't matter.
  8086. */
  8087. boardp->reqcnt[scp->device->id]++;
  8088. ASC_DBG(1, "ExeScsiQueue() ASC_NOERROR\n");
  8089. break;
  8090. case ASC_BUSY:
  8091. ASC_STATS(scp->device->host, exe_busy);
  8092. break;
  8093. case ASC_ERROR:
  8094. scmd_printk(KERN_ERR, scp, "ExeScsiQueue() ASC_ERROR, "
  8095. "err_code 0x%x\n", err_code);
  8096. ASC_STATS(scp->device->host, exe_error);
  8097. scp->result = HOST_BYTE(DID_ERROR);
  8098. break;
  8099. default:
  8100. scmd_printk(KERN_ERR, scp, "ExeScsiQueue() unknown, "
  8101. "err_code 0x%x\n", err_code);
  8102. ASC_STATS(scp->device->host, exe_unknown);
  8103. scp->result = HOST_BYTE(DID_ERROR);
  8104. break;
  8105. }
  8106. ASC_DBG(1, "end\n");
  8107. return ret;
  8108. }
  8109. /*
  8110. * advansys_queuecommand() - interrupt-driven I/O entrypoint.
  8111. *
  8112. * This function always returns 0. Command return status is saved
  8113. * in the 'scp' result field.
  8114. */
  8115. static int
  8116. advansys_queuecommand_lck(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *))
  8117. {
  8118. struct Scsi_Host *shost = scp->device->host;
  8119. int asc_res, result = 0;
  8120. ASC_STATS(shost, queuecommand);
  8121. scp->scsi_done = done;
  8122. asc_res = asc_execute_scsi_cmnd(scp);
  8123. switch (asc_res) {
  8124. case ASC_NOERROR:
  8125. break;
  8126. case ASC_BUSY:
  8127. result = SCSI_MLQUEUE_HOST_BUSY;
  8128. break;
  8129. case ASC_ERROR:
  8130. default:
  8131. asc_scsi_done(scp);
  8132. break;
  8133. }
  8134. return result;
  8135. }
  8136. static DEF_SCSI_QCMD(advansys_queuecommand)
  8137. static ushort AscGetEisaChipCfg(PortAddr iop_base)
  8138. {
  8139. PortAddr eisa_cfg_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
  8140. (PortAddr) (ASC_EISA_CFG_IOP_MASK);
  8141. return inpw(eisa_cfg_iop);
  8142. }
  8143. /*
  8144. * Return the BIOS address of the adapter at the specified
  8145. * I/O port and with the specified bus type.
  8146. */
  8147. static unsigned short AscGetChipBiosAddress(PortAddr iop_base,
  8148. unsigned short bus_type)
  8149. {
  8150. unsigned short cfg_lsw;
  8151. unsigned short bios_addr;
  8152. /*
  8153. * The PCI BIOS is re-located by the motherboard BIOS. Because
  8154. * of this the driver can not determine where a PCI BIOS is
  8155. * loaded and executes.
  8156. */
  8157. if (bus_type & ASC_IS_PCI)
  8158. return 0;
  8159. if ((bus_type & ASC_IS_EISA) != 0) {
  8160. cfg_lsw = AscGetEisaChipCfg(iop_base);
  8161. cfg_lsw &= 0x000F;
  8162. bios_addr = ASC_BIOS_MIN_ADDR + cfg_lsw * ASC_BIOS_BANK_SIZE;
  8163. return bios_addr;
  8164. }
  8165. cfg_lsw = AscGetChipCfgLsw(iop_base);
  8166. /*
  8167. * ISA PnP uses the top bit as the 32K BIOS flag
  8168. */
  8169. if (bus_type == ASC_IS_ISAPNP)
  8170. cfg_lsw &= 0x7FFF;
  8171. bios_addr = ASC_BIOS_MIN_ADDR + (cfg_lsw >> 12) * ASC_BIOS_BANK_SIZE;
  8172. return bios_addr;
  8173. }
  8174. static uchar AscSetChipScsiID(PortAddr iop_base, uchar new_host_id)
  8175. {
  8176. ushort cfg_lsw;
  8177. if (AscGetChipScsiID(iop_base) == new_host_id) {
  8178. return (new_host_id);
  8179. }
  8180. cfg_lsw = AscGetChipCfgLsw(iop_base);
  8181. cfg_lsw &= 0xF8FF;
  8182. cfg_lsw |= (ushort)((new_host_id & ASC_MAX_TID) << 8);
  8183. AscSetChipCfgLsw(iop_base, cfg_lsw);
  8184. return (AscGetChipScsiID(iop_base));
  8185. }
  8186. static unsigned char AscGetChipScsiCtrl(PortAddr iop_base)
  8187. {
  8188. unsigned char sc;
  8189. AscSetBank(iop_base, 1);
  8190. sc = inp(iop_base + IOP_REG_SC);
  8191. AscSetBank(iop_base, 0);
  8192. return sc;
  8193. }
  8194. static unsigned char AscGetChipVersion(PortAddr iop_base,
  8195. unsigned short bus_type)
  8196. {
  8197. if (bus_type & ASC_IS_EISA) {
  8198. PortAddr eisa_iop;
  8199. unsigned char revision;
  8200. eisa_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
  8201. (PortAddr) ASC_EISA_REV_IOP_MASK;
  8202. revision = inp(eisa_iop);
  8203. return ASC_CHIP_MIN_VER_EISA - 1 + revision;
  8204. }
  8205. return AscGetChipVerNo(iop_base);
  8206. }
  8207. #ifdef CONFIG_ISA
  8208. static void AscEnableIsaDma(uchar dma_channel)
  8209. {
  8210. if (dma_channel < 4) {
  8211. outp(0x000B, (ushort)(0xC0 | dma_channel));
  8212. outp(0x000A, dma_channel);
  8213. } else if (dma_channel < 8) {
  8214. outp(0x00D6, (ushort)(0xC0 | (dma_channel - 4)));
  8215. outp(0x00D4, (ushort)(dma_channel - 4));
  8216. }
  8217. }
  8218. #endif /* CONFIG_ISA */
  8219. static int AscStopQueueExe(PortAddr iop_base)
  8220. {
  8221. int count = 0;
  8222. if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) == 0) {
  8223. AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
  8224. ASC_STOP_REQ_RISC_STOP);
  8225. do {
  8226. if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) &
  8227. ASC_STOP_ACK_RISC_STOP) {
  8228. return (1);
  8229. }
  8230. mdelay(100);
  8231. } while (count++ < 20);
  8232. }
  8233. return (0);
  8234. }
  8235. static ASC_DCNT AscGetMaxDmaCount(ushort bus_type)
  8236. {
  8237. if (bus_type & ASC_IS_ISA)
  8238. return ASC_MAX_ISA_DMA_COUNT;
  8239. else if (bus_type & (ASC_IS_EISA | ASC_IS_VL))
  8240. return ASC_MAX_VL_DMA_COUNT;
  8241. return ASC_MAX_PCI_DMA_COUNT;
  8242. }
  8243. #ifdef CONFIG_ISA
  8244. static ushort AscGetIsaDmaChannel(PortAddr iop_base)
  8245. {
  8246. ushort channel;
  8247. channel = AscGetChipCfgLsw(iop_base) & 0x0003;
  8248. if (channel == 0x03)
  8249. return (0);
  8250. else if (channel == 0x00)
  8251. return (7);
  8252. return (channel + 4);
  8253. }
  8254. static ushort AscSetIsaDmaChannel(PortAddr iop_base, ushort dma_channel)
  8255. {
  8256. ushort cfg_lsw;
  8257. uchar value;
  8258. if ((dma_channel >= 5) && (dma_channel <= 7)) {
  8259. if (dma_channel == 7)
  8260. value = 0x00;
  8261. else
  8262. value = dma_channel - 4;
  8263. cfg_lsw = AscGetChipCfgLsw(iop_base) & 0xFFFC;
  8264. cfg_lsw |= value;
  8265. AscSetChipCfgLsw(iop_base, cfg_lsw);
  8266. return (AscGetIsaDmaChannel(iop_base));
  8267. }
  8268. return 0;
  8269. }
  8270. static uchar AscGetIsaDmaSpeed(PortAddr iop_base)
  8271. {
  8272. uchar speed_value;
  8273. AscSetBank(iop_base, 1);
  8274. speed_value = AscReadChipDmaSpeed(iop_base);
  8275. speed_value &= 0x07;
  8276. AscSetBank(iop_base, 0);
  8277. return speed_value;
  8278. }
  8279. static uchar AscSetIsaDmaSpeed(PortAddr iop_base, uchar speed_value)
  8280. {
  8281. speed_value &= 0x07;
  8282. AscSetBank(iop_base, 1);
  8283. AscWriteChipDmaSpeed(iop_base, speed_value);
  8284. AscSetBank(iop_base, 0);
  8285. return AscGetIsaDmaSpeed(iop_base);
  8286. }
  8287. #endif /* CONFIG_ISA */
  8288. static ushort AscInitAscDvcVar(ASC_DVC_VAR *asc_dvc)
  8289. {
  8290. int i;
  8291. PortAddr iop_base;
  8292. ushort warn_code;
  8293. uchar chip_version;
  8294. iop_base = asc_dvc->iop_base;
  8295. warn_code = 0;
  8296. asc_dvc->err_code = 0;
  8297. if ((asc_dvc->bus_type &
  8298. (ASC_IS_ISA | ASC_IS_PCI | ASC_IS_EISA | ASC_IS_VL)) == 0) {
  8299. asc_dvc->err_code |= ASC_IERR_NO_BUS_TYPE;
  8300. }
  8301. AscSetChipControl(iop_base, CC_HALT);
  8302. AscSetChipStatus(iop_base, 0);
  8303. asc_dvc->bug_fix_cntl = 0;
  8304. asc_dvc->pci_fix_asyn_xfer = 0;
  8305. asc_dvc->pci_fix_asyn_xfer_always = 0;
  8306. /* asc_dvc->init_state initialized in AscInitGetConfig(). */
  8307. asc_dvc->sdtr_done = 0;
  8308. asc_dvc->cur_total_qng = 0;
  8309. asc_dvc->is_in_int = 0;
  8310. asc_dvc->in_critical_cnt = 0;
  8311. asc_dvc->last_q_shortage = 0;
  8312. asc_dvc->use_tagged_qng = 0;
  8313. asc_dvc->no_scam = 0;
  8314. asc_dvc->unit_not_ready = 0;
  8315. asc_dvc->queue_full_or_busy = 0;
  8316. asc_dvc->redo_scam = 0;
  8317. asc_dvc->res2 = 0;
  8318. asc_dvc->min_sdtr_index = 0;
  8319. asc_dvc->cfg->can_tagged_qng = 0;
  8320. asc_dvc->cfg->cmd_qng_enabled = 0;
  8321. asc_dvc->dvc_cntl = ASC_DEF_DVC_CNTL;
  8322. asc_dvc->init_sdtr = 0;
  8323. asc_dvc->max_total_qng = ASC_DEF_MAX_TOTAL_QNG;
  8324. asc_dvc->scsi_reset_wait = 3;
  8325. asc_dvc->start_motor = ASC_SCSI_WIDTH_BIT_SET;
  8326. asc_dvc->max_dma_count = AscGetMaxDmaCount(asc_dvc->bus_type);
  8327. asc_dvc->cfg->sdtr_enable = ASC_SCSI_WIDTH_BIT_SET;
  8328. asc_dvc->cfg->disc_enable = ASC_SCSI_WIDTH_BIT_SET;
  8329. asc_dvc->cfg->chip_scsi_id = ASC_DEF_CHIP_SCSI_ID;
  8330. chip_version = AscGetChipVersion(iop_base, asc_dvc->bus_type);
  8331. asc_dvc->cfg->chip_version = chip_version;
  8332. asc_dvc->sdtr_period_tbl = asc_syn_xfer_period;
  8333. asc_dvc->max_sdtr_index = 7;
  8334. if ((asc_dvc->bus_type & ASC_IS_PCI) &&
  8335. (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3150)) {
  8336. asc_dvc->bus_type = ASC_IS_PCI_ULTRA;
  8337. asc_dvc->sdtr_period_tbl = asc_syn_ultra_xfer_period;
  8338. asc_dvc->max_sdtr_index = 15;
  8339. if (chip_version == ASC_CHIP_VER_PCI_ULTRA_3150) {
  8340. AscSetExtraControl(iop_base,
  8341. (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
  8342. } else if (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3050) {
  8343. AscSetExtraControl(iop_base,
  8344. (SEC_ACTIVE_NEGATE |
  8345. SEC_ENABLE_FILTER));
  8346. }
  8347. }
  8348. if (asc_dvc->bus_type == ASC_IS_PCI) {
  8349. AscSetExtraControl(iop_base,
  8350. (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
  8351. }
  8352. asc_dvc->cfg->isa_dma_speed = ASC_DEF_ISA_DMA_SPEED;
  8353. #ifdef CONFIG_ISA
  8354. if ((asc_dvc->bus_type & ASC_IS_ISA) != 0) {
  8355. if (chip_version >= ASC_CHIP_MIN_VER_ISA_PNP) {
  8356. AscSetChipIFC(iop_base, IFC_INIT_DEFAULT);
  8357. asc_dvc->bus_type = ASC_IS_ISAPNP;
  8358. }
  8359. asc_dvc->cfg->isa_dma_channel =
  8360. (uchar)AscGetIsaDmaChannel(iop_base);
  8361. }
  8362. #endif /* CONFIG_ISA */
  8363. for (i = 0; i <= ASC_MAX_TID; i++) {
  8364. asc_dvc->cur_dvc_qng[i] = 0;
  8365. asc_dvc->max_dvc_qng[i] = ASC_MAX_SCSI1_QNG;
  8366. asc_dvc->scsiq_busy_head[i] = (ASC_SCSI_Q *)0L;
  8367. asc_dvc->scsiq_busy_tail[i] = (ASC_SCSI_Q *)0L;
  8368. asc_dvc->cfg->max_tag_qng[i] = ASC_MAX_INRAM_TAG_QNG;
  8369. }
  8370. return warn_code;
  8371. }
  8372. static int AscWriteEEPCmdReg(PortAddr iop_base, uchar cmd_reg)
  8373. {
  8374. int retry;
  8375. for (retry = 0; retry < ASC_EEP_MAX_RETRY; retry++) {
  8376. unsigned char read_back;
  8377. AscSetChipEEPCmd(iop_base, cmd_reg);
  8378. mdelay(1);
  8379. read_back = AscGetChipEEPCmd(iop_base);
  8380. if (read_back == cmd_reg)
  8381. return 1;
  8382. }
  8383. return 0;
  8384. }
  8385. static void AscWaitEEPRead(void)
  8386. {
  8387. mdelay(1);
  8388. }
  8389. static ushort AscReadEEPWord(PortAddr iop_base, uchar addr)
  8390. {
  8391. ushort read_wval;
  8392. uchar cmd_reg;
  8393. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
  8394. AscWaitEEPRead();
  8395. cmd_reg = addr | ASC_EEP_CMD_READ;
  8396. AscWriteEEPCmdReg(iop_base, cmd_reg);
  8397. AscWaitEEPRead();
  8398. read_wval = AscGetChipEEPData(iop_base);
  8399. AscWaitEEPRead();
  8400. return read_wval;
  8401. }
  8402. static ushort AscGetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
  8403. ushort bus_type)
  8404. {
  8405. ushort wval;
  8406. ushort sum;
  8407. ushort *wbuf;
  8408. int cfg_beg;
  8409. int cfg_end;
  8410. int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
  8411. int s_addr;
  8412. wbuf = (ushort *)cfg_buf;
  8413. sum = 0;
  8414. /* Read two config words; Byte-swapping done by AscReadEEPWord(). */
  8415. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  8416. *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
  8417. sum += *wbuf;
  8418. }
  8419. if (bus_type & ASC_IS_VL) {
  8420. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  8421. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  8422. } else {
  8423. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  8424. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  8425. }
  8426. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  8427. wval = AscReadEEPWord(iop_base, (uchar)s_addr);
  8428. if (s_addr <= uchar_end_in_config) {
  8429. /*
  8430. * Swap all char fields - must unswap bytes already swapped
  8431. * by AscReadEEPWord().
  8432. */
  8433. *wbuf = le16_to_cpu(wval);
  8434. } else {
  8435. /* Don't swap word field at the end - cntl field. */
  8436. *wbuf = wval;
  8437. }
  8438. sum += wval; /* Checksum treats all EEPROM data as words. */
  8439. }
  8440. /*
  8441. * Read the checksum word which will be compared against 'sum'
  8442. * by the caller. Word field already swapped.
  8443. */
  8444. *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr);
  8445. return sum;
  8446. }
  8447. static int AscTestExternalLram(ASC_DVC_VAR *asc_dvc)
  8448. {
  8449. PortAddr iop_base;
  8450. ushort q_addr;
  8451. ushort saved_word;
  8452. int sta;
  8453. iop_base = asc_dvc->iop_base;
  8454. sta = 0;
  8455. q_addr = ASC_QNO_TO_QADDR(241);
  8456. saved_word = AscReadLramWord(iop_base, q_addr);
  8457. AscSetChipLramAddr(iop_base, q_addr);
  8458. AscSetChipLramData(iop_base, 0x55AA);
  8459. mdelay(10);
  8460. AscSetChipLramAddr(iop_base, q_addr);
  8461. if (AscGetChipLramData(iop_base) == 0x55AA) {
  8462. sta = 1;
  8463. AscWriteLramWord(iop_base, q_addr, saved_word);
  8464. }
  8465. return (sta);
  8466. }
  8467. static void AscWaitEEPWrite(void)
  8468. {
  8469. mdelay(20);
  8470. }
  8471. static int AscWriteEEPDataReg(PortAddr iop_base, ushort data_reg)
  8472. {
  8473. ushort read_back;
  8474. int retry;
  8475. retry = 0;
  8476. while (TRUE) {
  8477. AscSetChipEEPData(iop_base, data_reg);
  8478. mdelay(1);
  8479. read_back = AscGetChipEEPData(iop_base);
  8480. if (read_back == data_reg) {
  8481. return (1);
  8482. }
  8483. if (retry++ > ASC_EEP_MAX_RETRY) {
  8484. return (0);
  8485. }
  8486. }
  8487. }
  8488. static ushort AscWriteEEPWord(PortAddr iop_base, uchar addr, ushort word_val)
  8489. {
  8490. ushort read_wval;
  8491. read_wval = AscReadEEPWord(iop_base, addr);
  8492. if (read_wval != word_val) {
  8493. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_ABLE);
  8494. AscWaitEEPRead();
  8495. AscWriteEEPDataReg(iop_base, word_val);
  8496. AscWaitEEPRead();
  8497. AscWriteEEPCmdReg(iop_base,
  8498. (uchar)((uchar)ASC_EEP_CMD_WRITE | addr));
  8499. AscWaitEEPWrite();
  8500. AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
  8501. AscWaitEEPRead();
  8502. return (AscReadEEPWord(iop_base, addr));
  8503. }
  8504. return (read_wval);
  8505. }
  8506. static int AscSetEEPConfigOnce(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
  8507. ushort bus_type)
  8508. {
  8509. int n_error;
  8510. ushort *wbuf;
  8511. ushort word;
  8512. ushort sum;
  8513. int s_addr;
  8514. int cfg_beg;
  8515. int cfg_end;
  8516. int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
  8517. wbuf = (ushort *)cfg_buf;
  8518. n_error = 0;
  8519. sum = 0;
  8520. /* Write two config words; AscWriteEEPWord() will swap bytes. */
  8521. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  8522. sum += *wbuf;
  8523. if (*wbuf != AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
  8524. n_error++;
  8525. }
  8526. }
  8527. if (bus_type & ASC_IS_VL) {
  8528. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  8529. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  8530. } else {
  8531. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  8532. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  8533. }
  8534. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  8535. if (s_addr <= uchar_end_in_config) {
  8536. /*
  8537. * This is a char field. Swap char fields before they are
  8538. * swapped again by AscWriteEEPWord().
  8539. */
  8540. word = cpu_to_le16(*wbuf);
  8541. if (word !=
  8542. AscWriteEEPWord(iop_base, (uchar)s_addr, word)) {
  8543. n_error++;
  8544. }
  8545. } else {
  8546. /* Don't swap word field at the end - cntl field. */
  8547. if (*wbuf !=
  8548. AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) {
  8549. n_error++;
  8550. }
  8551. }
  8552. sum += *wbuf; /* Checksum calculated from word values. */
  8553. }
  8554. /* Write checksum word. It will be swapped by AscWriteEEPWord(). */
  8555. *wbuf = sum;
  8556. if (sum != AscWriteEEPWord(iop_base, (uchar)s_addr, sum)) {
  8557. n_error++;
  8558. }
  8559. /* Read EEPROM back again. */
  8560. wbuf = (ushort *)cfg_buf;
  8561. /*
  8562. * Read two config words; Byte-swapping done by AscReadEEPWord().
  8563. */
  8564. for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
  8565. if (*wbuf != AscReadEEPWord(iop_base, (uchar)s_addr)) {
  8566. n_error++;
  8567. }
  8568. }
  8569. if (bus_type & ASC_IS_VL) {
  8570. cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
  8571. cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
  8572. } else {
  8573. cfg_beg = ASC_EEP_DVC_CFG_BEG;
  8574. cfg_end = ASC_EEP_MAX_DVC_ADDR;
  8575. }
  8576. for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
  8577. if (s_addr <= uchar_end_in_config) {
  8578. /*
  8579. * Swap all char fields. Must unswap bytes already swapped
  8580. * by AscReadEEPWord().
  8581. */
  8582. word =
  8583. le16_to_cpu(AscReadEEPWord
  8584. (iop_base, (uchar)s_addr));
  8585. } else {
  8586. /* Don't swap word field at the end - cntl field. */
  8587. word = AscReadEEPWord(iop_base, (uchar)s_addr);
  8588. }
  8589. if (*wbuf != word) {
  8590. n_error++;
  8591. }
  8592. }
  8593. /* Read checksum; Byte swapping not needed. */
  8594. if (AscReadEEPWord(iop_base, (uchar)s_addr) != sum) {
  8595. n_error++;
  8596. }
  8597. return n_error;
  8598. }
  8599. static int AscSetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf,
  8600. ushort bus_type)
  8601. {
  8602. int retry;
  8603. int n_error;
  8604. retry = 0;
  8605. while (TRUE) {
  8606. if ((n_error = AscSetEEPConfigOnce(iop_base, cfg_buf,
  8607. bus_type)) == 0) {
  8608. break;
  8609. }
  8610. if (++retry > ASC_EEP_MAX_RETRY) {
  8611. break;
  8612. }
  8613. }
  8614. return n_error;
  8615. }
  8616. static ushort AscInitFromEEP(ASC_DVC_VAR *asc_dvc)
  8617. {
  8618. ASCEEP_CONFIG eep_config_buf;
  8619. ASCEEP_CONFIG *eep_config;
  8620. PortAddr iop_base;
  8621. ushort chksum;
  8622. ushort warn_code;
  8623. ushort cfg_msw, cfg_lsw;
  8624. int i;
  8625. int write_eep = 0;
  8626. iop_base = asc_dvc->iop_base;
  8627. warn_code = 0;
  8628. AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0x00FE);
  8629. AscStopQueueExe(iop_base);
  8630. if ((AscStopChip(iop_base) == FALSE) ||
  8631. (AscGetChipScsiCtrl(iop_base) != 0)) {
  8632. asc_dvc->init_state |= ASC_INIT_RESET_SCSI_DONE;
  8633. AscResetChipAndScsiBus(asc_dvc);
  8634. mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */
  8635. }
  8636. if (AscIsChipHalted(iop_base) == FALSE) {
  8637. asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
  8638. return (warn_code);
  8639. }
  8640. AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
  8641. if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
  8642. asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
  8643. return (warn_code);
  8644. }
  8645. eep_config = (ASCEEP_CONFIG *)&eep_config_buf;
  8646. cfg_msw = AscGetChipCfgMsw(iop_base);
  8647. cfg_lsw = AscGetChipCfgLsw(iop_base);
  8648. if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
  8649. cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  8650. warn_code |= ASC_WARN_CFG_MSW_RECOVER;
  8651. AscSetChipCfgMsw(iop_base, cfg_msw);
  8652. }
  8653. chksum = AscGetEEPConfig(iop_base, eep_config, asc_dvc->bus_type);
  8654. ASC_DBG(1, "chksum 0x%x\n", chksum);
  8655. if (chksum == 0) {
  8656. chksum = 0xaa55;
  8657. }
  8658. if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
  8659. warn_code |= ASC_WARN_AUTO_CONFIG;
  8660. if (asc_dvc->cfg->chip_version == 3) {
  8661. if (eep_config->cfg_lsw != cfg_lsw) {
  8662. warn_code |= ASC_WARN_EEPROM_RECOVER;
  8663. eep_config->cfg_lsw =
  8664. AscGetChipCfgLsw(iop_base);
  8665. }
  8666. if (eep_config->cfg_msw != cfg_msw) {
  8667. warn_code |= ASC_WARN_EEPROM_RECOVER;
  8668. eep_config->cfg_msw =
  8669. AscGetChipCfgMsw(iop_base);
  8670. }
  8671. }
  8672. }
  8673. eep_config->cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  8674. eep_config->cfg_lsw |= ASC_CFG0_HOST_INT_ON;
  8675. ASC_DBG(1, "eep_config->chksum 0x%x\n", eep_config->chksum);
  8676. if (chksum != eep_config->chksum) {
  8677. if (AscGetChipVersion(iop_base, asc_dvc->bus_type) ==
  8678. ASC_CHIP_VER_PCI_ULTRA_3050) {
  8679. ASC_DBG(1, "chksum error ignored; EEPROM-less board\n");
  8680. eep_config->init_sdtr = 0xFF;
  8681. eep_config->disc_enable = 0xFF;
  8682. eep_config->start_motor = 0xFF;
  8683. eep_config->use_cmd_qng = 0;
  8684. eep_config->max_total_qng = 0xF0;
  8685. eep_config->max_tag_qng = 0x20;
  8686. eep_config->cntl = 0xBFFF;
  8687. ASC_EEP_SET_CHIP_ID(eep_config, 7);
  8688. eep_config->no_scam = 0;
  8689. eep_config->adapter_info[0] = 0;
  8690. eep_config->adapter_info[1] = 0;
  8691. eep_config->adapter_info[2] = 0;
  8692. eep_config->adapter_info[3] = 0;
  8693. eep_config->adapter_info[4] = 0;
  8694. /* Indicate EEPROM-less board. */
  8695. eep_config->adapter_info[5] = 0xBB;
  8696. } else {
  8697. ASC_PRINT
  8698. ("AscInitFromEEP: EEPROM checksum error; Will try to re-write EEPROM.\n");
  8699. write_eep = 1;
  8700. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  8701. }
  8702. }
  8703. asc_dvc->cfg->sdtr_enable = eep_config->init_sdtr;
  8704. asc_dvc->cfg->disc_enable = eep_config->disc_enable;
  8705. asc_dvc->cfg->cmd_qng_enabled = eep_config->use_cmd_qng;
  8706. asc_dvc->cfg->isa_dma_speed = ASC_EEP_GET_DMA_SPD(eep_config);
  8707. asc_dvc->start_motor = eep_config->start_motor;
  8708. asc_dvc->dvc_cntl = eep_config->cntl;
  8709. asc_dvc->no_scam = eep_config->no_scam;
  8710. asc_dvc->cfg->adapter_info[0] = eep_config->adapter_info[0];
  8711. asc_dvc->cfg->adapter_info[1] = eep_config->adapter_info[1];
  8712. asc_dvc->cfg->adapter_info[2] = eep_config->adapter_info[2];
  8713. asc_dvc->cfg->adapter_info[3] = eep_config->adapter_info[3];
  8714. asc_dvc->cfg->adapter_info[4] = eep_config->adapter_info[4];
  8715. asc_dvc->cfg->adapter_info[5] = eep_config->adapter_info[5];
  8716. if (!AscTestExternalLram(asc_dvc)) {
  8717. if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) ==
  8718. ASC_IS_PCI_ULTRA)) {
  8719. eep_config->max_total_qng =
  8720. ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG;
  8721. eep_config->max_tag_qng =
  8722. ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG;
  8723. } else {
  8724. eep_config->cfg_msw |= 0x0800;
  8725. cfg_msw |= 0x0800;
  8726. AscSetChipCfgMsw(iop_base, cfg_msw);
  8727. eep_config->max_total_qng = ASC_MAX_PCI_INRAM_TOTAL_QNG;
  8728. eep_config->max_tag_qng = ASC_MAX_INRAM_TAG_QNG;
  8729. }
  8730. } else {
  8731. }
  8732. if (eep_config->max_total_qng < ASC_MIN_TOTAL_QNG) {
  8733. eep_config->max_total_qng = ASC_MIN_TOTAL_QNG;
  8734. }
  8735. if (eep_config->max_total_qng > ASC_MAX_TOTAL_QNG) {
  8736. eep_config->max_total_qng = ASC_MAX_TOTAL_QNG;
  8737. }
  8738. if (eep_config->max_tag_qng > eep_config->max_total_qng) {
  8739. eep_config->max_tag_qng = eep_config->max_total_qng;
  8740. }
  8741. if (eep_config->max_tag_qng < ASC_MIN_TAG_Q_PER_DVC) {
  8742. eep_config->max_tag_qng = ASC_MIN_TAG_Q_PER_DVC;
  8743. }
  8744. asc_dvc->max_total_qng = eep_config->max_total_qng;
  8745. if ((eep_config->use_cmd_qng & eep_config->disc_enable) !=
  8746. eep_config->use_cmd_qng) {
  8747. eep_config->disc_enable = eep_config->use_cmd_qng;
  8748. warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
  8749. }
  8750. ASC_EEP_SET_CHIP_ID(eep_config,
  8751. ASC_EEP_GET_CHIP_ID(eep_config) & ASC_MAX_TID);
  8752. asc_dvc->cfg->chip_scsi_id = ASC_EEP_GET_CHIP_ID(eep_config);
  8753. if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) &&
  8754. !(asc_dvc->dvc_cntl & ASC_CNTL_SDTR_ENABLE_ULTRA)) {
  8755. asc_dvc->min_sdtr_index = ASC_SDTR_ULTRA_PCI_10MB_INDEX;
  8756. }
  8757. for (i = 0; i <= ASC_MAX_TID; i++) {
  8758. asc_dvc->dos_int13_table[i] = eep_config->dos_int13_table[i];
  8759. asc_dvc->cfg->max_tag_qng[i] = eep_config->max_tag_qng;
  8760. asc_dvc->cfg->sdtr_period_offset[i] =
  8761. (uchar)(ASC_DEF_SDTR_OFFSET |
  8762. (asc_dvc->min_sdtr_index << 4));
  8763. }
  8764. eep_config->cfg_msw = AscGetChipCfgMsw(iop_base);
  8765. if (write_eep) {
  8766. if ((i = AscSetEEPConfig(iop_base, eep_config,
  8767. asc_dvc->bus_type)) != 0) {
  8768. ASC_PRINT1
  8769. ("AscInitFromEEP: Failed to re-write EEPROM with %d errors.\n",
  8770. i);
  8771. } else {
  8772. ASC_PRINT
  8773. ("AscInitFromEEP: Successfully re-wrote EEPROM.\n");
  8774. }
  8775. }
  8776. return (warn_code);
  8777. }
  8778. static int AscInitGetConfig(struct Scsi_Host *shost)
  8779. {
  8780. struct asc_board *board = shost_priv(shost);
  8781. ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
  8782. unsigned short warn_code = 0;
  8783. asc_dvc->init_state = ASC_INIT_STATE_BEG_GET_CFG;
  8784. if (asc_dvc->err_code != 0)
  8785. return asc_dvc->err_code;
  8786. if (AscFindSignature(asc_dvc->iop_base)) {
  8787. warn_code |= AscInitAscDvcVar(asc_dvc);
  8788. warn_code |= AscInitFromEEP(asc_dvc);
  8789. asc_dvc->init_state |= ASC_INIT_STATE_END_GET_CFG;
  8790. if (asc_dvc->scsi_reset_wait > ASC_MAX_SCSI_RESET_WAIT)
  8791. asc_dvc->scsi_reset_wait = ASC_MAX_SCSI_RESET_WAIT;
  8792. } else {
  8793. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  8794. }
  8795. switch (warn_code) {
  8796. case 0: /* No error */
  8797. break;
  8798. case ASC_WARN_IO_PORT_ROTATE:
  8799. shost_printk(KERN_WARNING, shost, "I/O port address "
  8800. "modified\n");
  8801. break;
  8802. case ASC_WARN_AUTO_CONFIG:
  8803. shost_printk(KERN_WARNING, shost, "I/O port increment switch "
  8804. "enabled\n");
  8805. break;
  8806. case ASC_WARN_EEPROM_CHKSUM:
  8807. shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
  8808. break;
  8809. case ASC_WARN_IRQ_MODIFIED:
  8810. shost_printk(KERN_WARNING, shost, "IRQ modified\n");
  8811. break;
  8812. case ASC_WARN_CMD_QNG_CONFLICT:
  8813. shost_printk(KERN_WARNING, shost, "tag queuing enabled w/o "
  8814. "disconnects\n");
  8815. break;
  8816. default:
  8817. shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
  8818. warn_code);
  8819. break;
  8820. }
  8821. if (asc_dvc->err_code != 0)
  8822. shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
  8823. "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
  8824. return asc_dvc->err_code;
  8825. }
  8826. static int AscInitSetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
  8827. {
  8828. struct asc_board *board = shost_priv(shost);
  8829. ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var;
  8830. PortAddr iop_base = asc_dvc->iop_base;
  8831. unsigned short cfg_msw;
  8832. unsigned short warn_code = 0;
  8833. asc_dvc->init_state |= ASC_INIT_STATE_BEG_SET_CFG;
  8834. if (asc_dvc->err_code != 0)
  8835. return asc_dvc->err_code;
  8836. if (!AscFindSignature(asc_dvc->iop_base)) {
  8837. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  8838. return asc_dvc->err_code;
  8839. }
  8840. cfg_msw = AscGetChipCfgMsw(iop_base);
  8841. if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
  8842. cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
  8843. warn_code |= ASC_WARN_CFG_MSW_RECOVER;
  8844. AscSetChipCfgMsw(iop_base, cfg_msw);
  8845. }
  8846. if ((asc_dvc->cfg->cmd_qng_enabled & asc_dvc->cfg->disc_enable) !=
  8847. asc_dvc->cfg->cmd_qng_enabled) {
  8848. asc_dvc->cfg->disc_enable = asc_dvc->cfg->cmd_qng_enabled;
  8849. warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
  8850. }
  8851. if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
  8852. warn_code |= ASC_WARN_AUTO_CONFIG;
  8853. }
  8854. #ifdef CONFIG_PCI
  8855. if (asc_dvc->bus_type & ASC_IS_PCI) {
  8856. cfg_msw &= 0xFFC0;
  8857. AscSetChipCfgMsw(iop_base, cfg_msw);
  8858. if ((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) {
  8859. } else {
  8860. if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
  8861. (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
  8862. asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_IF_NOT_DWB;
  8863. asc_dvc->bug_fix_cntl |=
  8864. ASC_BUG_FIX_ASYN_USE_SYN;
  8865. }
  8866. }
  8867. } else
  8868. #endif /* CONFIG_PCI */
  8869. if (asc_dvc->bus_type == ASC_IS_ISAPNP) {
  8870. if (AscGetChipVersion(iop_base, asc_dvc->bus_type)
  8871. == ASC_CHIP_VER_ASYN_BUG) {
  8872. asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_ASYN_USE_SYN;
  8873. }
  8874. }
  8875. if (AscSetChipScsiID(iop_base, asc_dvc->cfg->chip_scsi_id) !=
  8876. asc_dvc->cfg->chip_scsi_id) {
  8877. asc_dvc->err_code |= ASC_IERR_SET_SCSI_ID;
  8878. }
  8879. #ifdef CONFIG_ISA
  8880. if (asc_dvc->bus_type & ASC_IS_ISA) {
  8881. AscSetIsaDmaChannel(iop_base, asc_dvc->cfg->isa_dma_channel);
  8882. AscSetIsaDmaSpeed(iop_base, asc_dvc->cfg->isa_dma_speed);
  8883. }
  8884. #endif /* CONFIG_ISA */
  8885. asc_dvc->init_state |= ASC_INIT_STATE_END_SET_CFG;
  8886. switch (warn_code) {
  8887. case 0: /* No error. */
  8888. break;
  8889. case ASC_WARN_IO_PORT_ROTATE:
  8890. shost_printk(KERN_WARNING, shost, "I/O port address "
  8891. "modified\n");
  8892. break;
  8893. case ASC_WARN_AUTO_CONFIG:
  8894. shost_printk(KERN_WARNING, shost, "I/O port increment switch "
  8895. "enabled\n");
  8896. break;
  8897. case ASC_WARN_EEPROM_CHKSUM:
  8898. shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n");
  8899. break;
  8900. case ASC_WARN_IRQ_MODIFIED:
  8901. shost_printk(KERN_WARNING, shost, "IRQ modified\n");
  8902. break;
  8903. case ASC_WARN_CMD_QNG_CONFLICT:
  8904. shost_printk(KERN_WARNING, shost, "tag queuing w/o "
  8905. "disconnects\n");
  8906. break;
  8907. default:
  8908. shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n",
  8909. warn_code);
  8910. break;
  8911. }
  8912. if (asc_dvc->err_code != 0)
  8913. shost_printk(KERN_ERR, shost, "error 0x%x at init_state "
  8914. "0x%x\n", asc_dvc->err_code, asc_dvc->init_state);
  8915. return asc_dvc->err_code;
  8916. }
  8917. /*
  8918. * EEPROM Configuration.
  8919. *
  8920. * All drivers should use this structure to set the default EEPROM
  8921. * configuration. The BIOS now uses this structure when it is built.
  8922. * Additional structure information can be found in a_condor.h where
  8923. * the structure is defined.
  8924. *
  8925. * The *_Field_IsChar structs are needed to correct for endianness.
  8926. * These values are read from the board 16 bits at a time directly
  8927. * into the structs. Because some fields are char, the values will be
  8928. * in the wrong order. The *_Field_IsChar tells when to flip the
  8929. * bytes. Data read and written to PCI memory is automatically swapped
  8930. * on big-endian platforms so char fields read as words are actually being
  8931. * unswapped on big-endian platforms.
  8932. */
  8933. static ADVEEP_3550_CONFIG Default_3550_EEPROM_Config = {
  8934. ADV_EEPROM_BIOS_ENABLE, /* cfg_lsw */
  8935. 0x0000, /* cfg_msw */
  8936. 0xFFFF, /* disc_enable */
  8937. 0xFFFF, /* wdtr_able */
  8938. 0xFFFF, /* sdtr_able */
  8939. 0xFFFF, /* start_motor */
  8940. 0xFFFF, /* tagqng_able */
  8941. 0xFFFF, /* bios_scan */
  8942. 0, /* scam_tolerant */
  8943. 7, /* adapter_scsi_id */
  8944. 0, /* bios_boot_delay */
  8945. 3, /* scsi_reset_delay */
  8946. 0, /* bios_id_lun */
  8947. 0, /* termination */
  8948. 0, /* reserved1 */
  8949. 0xFFE7, /* bios_ctrl */
  8950. 0xFFFF, /* ultra_able */
  8951. 0, /* reserved2 */
  8952. ASC_DEF_MAX_HOST_QNG, /* max_host_qng */
  8953. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  8954. 0, /* dvc_cntl */
  8955. 0, /* bug_fix */
  8956. 0, /* serial_number_word1 */
  8957. 0, /* serial_number_word2 */
  8958. 0, /* serial_number_word3 */
  8959. 0, /* check_sum */
  8960. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  8961. , /* oem_name[16] */
  8962. 0, /* dvc_err_code */
  8963. 0, /* adv_err_code */
  8964. 0, /* adv_err_addr */
  8965. 0, /* saved_dvc_err_code */
  8966. 0, /* saved_adv_err_code */
  8967. 0, /* saved_adv_err_addr */
  8968. 0 /* num_of_err */
  8969. };
  8970. static ADVEEP_3550_CONFIG ADVEEP_3550_Config_Field_IsChar = {
  8971. 0, /* cfg_lsw */
  8972. 0, /* cfg_msw */
  8973. 0, /* -disc_enable */
  8974. 0, /* wdtr_able */
  8975. 0, /* sdtr_able */
  8976. 0, /* start_motor */
  8977. 0, /* tagqng_able */
  8978. 0, /* bios_scan */
  8979. 0, /* scam_tolerant */
  8980. 1, /* adapter_scsi_id */
  8981. 1, /* bios_boot_delay */
  8982. 1, /* scsi_reset_delay */
  8983. 1, /* bios_id_lun */
  8984. 1, /* termination */
  8985. 1, /* reserved1 */
  8986. 0, /* bios_ctrl */
  8987. 0, /* ultra_able */
  8988. 0, /* reserved2 */
  8989. 1, /* max_host_qng */
  8990. 1, /* max_dvc_qng */
  8991. 0, /* dvc_cntl */
  8992. 0, /* bug_fix */
  8993. 0, /* serial_number_word1 */
  8994. 0, /* serial_number_word2 */
  8995. 0, /* serial_number_word3 */
  8996. 0, /* check_sum */
  8997. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  8998. , /* oem_name[16] */
  8999. 0, /* dvc_err_code */
  9000. 0, /* adv_err_code */
  9001. 0, /* adv_err_addr */
  9002. 0, /* saved_dvc_err_code */
  9003. 0, /* saved_adv_err_code */
  9004. 0, /* saved_adv_err_addr */
  9005. 0 /* num_of_err */
  9006. };
  9007. static ADVEEP_38C0800_CONFIG Default_38C0800_EEPROM_Config = {
  9008. ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
  9009. 0x0000, /* 01 cfg_msw */
  9010. 0xFFFF, /* 02 disc_enable */
  9011. 0xFFFF, /* 03 wdtr_able */
  9012. 0x4444, /* 04 sdtr_speed1 */
  9013. 0xFFFF, /* 05 start_motor */
  9014. 0xFFFF, /* 06 tagqng_able */
  9015. 0xFFFF, /* 07 bios_scan */
  9016. 0, /* 08 scam_tolerant */
  9017. 7, /* 09 adapter_scsi_id */
  9018. 0, /* bios_boot_delay */
  9019. 3, /* 10 scsi_reset_delay */
  9020. 0, /* bios_id_lun */
  9021. 0, /* 11 termination_se */
  9022. 0, /* termination_lvd */
  9023. 0xFFE7, /* 12 bios_ctrl */
  9024. 0x4444, /* 13 sdtr_speed2 */
  9025. 0x4444, /* 14 sdtr_speed3 */
  9026. ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
  9027. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  9028. 0, /* 16 dvc_cntl */
  9029. 0x4444, /* 17 sdtr_speed4 */
  9030. 0, /* 18 serial_number_word1 */
  9031. 0, /* 19 serial_number_word2 */
  9032. 0, /* 20 serial_number_word3 */
  9033. 0, /* 21 check_sum */
  9034. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  9035. , /* 22-29 oem_name[16] */
  9036. 0, /* 30 dvc_err_code */
  9037. 0, /* 31 adv_err_code */
  9038. 0, /* 32 adv_err_addr */
  9039. 0, /* 33 saved_dvc_err_code */
  9040. 0, /* 34 saved_adv_err_code */
  9041. 0, /* 35 saved_adv_err_addr */
  9042. 0, /* 36 reserved */
  9043. 0, /* 37 reserved */
  9044. 0, /* 38 reserved */
  9045. 0, /* 39 reserved */
  9046. 0, /* 40 reserved */
  9047. 0, /* 41 reserved */
  9048. 0, /* 42 reserved */
  9049. 0, /* 43 reserved */
  9050. 0, /* 44 reserved */
  9051. 0, /* 45 reserved */
  9052. 0, /* 46 reserved */
  9053. 0, /* 47 reserved */
  9054. 0, /* 48 reserved */
  9055. 0, /* 49 reserved */
  9056. 0, /* 50 reserved */
  9057. 0, /* 51 reserved */
  9058. 0, /* 52 reserved */
  9059. 0, /* 53 reserved */
  9060. 0, /* 54 reserved */
  9061. 0, /* 55 reserved */
  9062. 0, /* 56 cisptr_lsw */
  9063. 0, /* 57 cisprt_msw */
  9064. PCI_VENDOR_ID_ASP, /* 58 subsysvid */
  9065. PCI_DEVICE_ID_38C0800_REV1, /* 59 subsysid */
  9066. 0, /* 60 reserved */
  9067. 0, /* 61 reserved */
  9068. 0, /* 62 reserved */
  9069. 0 /* 63 reserved */
  9070. };
  9071. static ADVEEP_38C0800_CONFIG ADVEEP_38C0800_Config_Field_IsChar = {
  9072. 0, /* 00 cfg_lsw */
  9073. 0, /* 01 cfg_msw */
  9074. 0, /* 02 disc_enable */
  9075. 0, /* 03 wdtr_able */
  9076. 0, /* 04 sdtr_speed1 */
  9077. 0, /* 05 start_motor */
  9078. 0, /* 06 tagqng_able */
  9079. 0, /* 07 bios_scan */
  9080. 0, /* 08 scam_tolerant */
  9081. 1, /* 09 adapter_scsi_id */
  9082. 1, /* bios_boot_delay */
  9083. 1, /* 10 scsi_reset_delay */
  9084. 1, /* bios_id_lun */
  9085. 1, /* 11 termination_se */
  9086. 1, /* termination_lvd */
  9087. 0, /* 12 bios_ctrl */
  9088. 0, /* 13 sdtr_speed2 */
  9089. 0, /* 14 sdtr_speed3 */
  9090. 1, /* 15 max_host_qng */
  9091. 1, /* max_dvc_qng */
  9092. 0, /* 16 dvc_cntl */
  9093. 0, /* 17 sdtr_speed4 */
  9094. 0, /* 18 serial_number_word1 */
  9095. 0, /* 19 serial_number_word2 */
  9096. 0, /* 20 serial_number_word3 */
  9097. 0, /* 21 check_sum */
  9098. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  9099. , /* 22-29 oem_name[16] */
  9100. 0, /* 30 dvc_err_code */
  9101. 0, /* 31 adv_err_code */
  9102. 0, /* 32 adv_err_addr */
  9103. 0, /* 33 saved_dvc_err_code */
  9104. 0, /* 34 saved_adv_err_code */
  9105. 0, /* 35 saved_adv_err_addr */
  9106. 0, /* 36 reserved */
  9107. 0, /* 37 reserved */
  9108. 0, /* 38 reserved */
  9109. 0, /* 39 reserved */
  9110. 0, /* 40 reserved */
  9111. 0, /* 41 reserved */
  9112. 0, /* 42 reserved */
  9113. 0, /* 43 reserved */
  9114. 0, /* 44 reserved */
  9115. 0, /* 45 reserved */
  9116. 0, /* 46 reserved */
  9117. 0, /* 47 reserved */
  9118. 0, /* 48 reserved */
  9119. 0, /* 49 reserved */
  9120. 0, /* 50 reserved */
  9121. 0, /* 51 reserved */
  9122. 0, /* 52 reserved */
  9123. 0, /* 53 reserved */
  9124. 0, /* 54 reserved */
  9125. 0, /* 55 reserved */
  9126. 0, /* 56 cisptr_lsw */
  9127. 0, /* 57 cisprt_msw */
  9128. 0, /* 58 subsysvid */
  9129. 0, /* 59 subsysid */
  9130. 0, /* 60 reserved */
  9131. 0, /* 61 reserved */
  9132. 0, /* 62 reserved */
  9133. 0 /* 63 reserved */
  9134. };
  9135. static ADVEEP_38C1600_CONFIG Default_38C1600_EEPROM_Config = {
  9136. ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
  9137. 0x0000, /* 01 cfg_msw */
  9138. 0xFFFF, /* 02 disc_enable */
  9139. 0xFFFF, /* 03 wdtr_able */
  9140. 0x5555, /* 04 sdtr_speed1 */
  9141. 0xFFFF, /* 05 start_motor */
  9142. 0xFFFF, /* 06 tagqng_able */
  9143. 0xFFFF, /* 07 bios_scan */
  9144. 0, /* 08 scam_tolerant */
  9145. 7, /* 09 adapter_scsi_id */
  9146. 0, /* bios_boot_delay */
  9147. 3, /* 10 scsi_reset_delay */
  9148. 0, /* bios_id_lun */
  9149. 0, /* 11 termination_se */
  9150. 0, /* termination_lvd */
  9151. 0xFFE7, /* 12 bios_ctrl */
  9152. 0x5555, /* 13 sdtr_speed2 */
  9153. 0x5555, /* 14 sdtr_speed3 */
  9154. ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
  9155. ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
  9156. 0, /* 16 dvc_cntl */
  9157. 0x5555, /* 17 sdtr_speed4 */
  9158. 0, /* 18 serial_number_word1 */
  9159. 0, /* 19 serial_number_word2 */
  9160. 0, /* 20 serial_number_word3 */
  9161. 0, /* 21 check_sum */
  9162. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  9163. , /* 22-29 oem_name[16] */
  9164. 0, /* 30 dvc_err_code */
  9165. 0, /* 31 adv_err_code */
  9166. 0, /* 32 adv_err_addr */
  9167. 0, /* 33 saved_dvc_err_code */
  9168. 0, /* 34 saved_adv_err_code */
  9169. 0, /* 35 saved_adv_err_addr */
  9170. 0, /* 36 reserved */
  9171. 0, /* 37 reserved */
  9172. 0, /* 38 reserved */
  9173. 0, /* 39 reserved */
  9174. 0, /* 40 reserved */
  9175. 0, /* 41 reserved */
  9176. 0, /* 42 reserved */
  9177. 0, /* 43 reserved */
  9178. 0, /* 44 reserved */
  9179. 0, /* 45 reserved */
  9180. 0, /* 46 reserved */
  9181. 0, /* 47 reserved */
  9182. 0, /* 48 reserved */
  9183. 0, /* 49 reserved */
  9184. 0, /* 50 reserved */
  9185. 0, /* 51 reserved */
  9186. 0, /* 52 reserved */
  9187. 0, /* 53 reserved */
  9188. 0, /* 54 reserved */
  9189. 0, /* 55 reserved */
  9190. 0, /* 56 cisptr_lsw */
  9191. 0, /* 57 cisprt_msw */
  9192. PCI_VENDOR_ID_ASP, /* 58 subsysvid */
  9193. PCI_DEVICE_ID_38C1600_REV1, /* 59 subsysid */
  9194. 0, /* 60 reserved */
  9195. 0, /* 61 reserved */
  9196. 0, /* 62 reserved */
  9197. 0 /* 63 reserved */
  9198. };
  9199. static ADVEEP_38C1600_CONFIG ADVEEP_38C1600_Config_Field_IsChar = {
  9200. 0, /* 00 cfg_lsw */
  9201. 0, /* 01 cfg_msw */
  9202. 0, /* 02 disc_enable */
  9203. 0, /* 03 wdtr_able */
  9204. 0, /* 04 sdtr_speed1 */
  9205. 0, /* 05 start_motor */
  9206. 0, /* 06 tagqng_able */
  9207. 0, /* 07 bios_scan */
  9208. 0, /* 08 scam_tolerant */
  9209. 1, /* 09 adapter_scsi_id */
  9210. 1, /* bios_boot_delay */
  9211. 1, /* 10 scsi_reset_delay */
  9212. 1, /* bios_id_lun */
  9213. 1, /* 11 termination_se */
  9214. 1, /* termination_lvd */
  9215. 0, /* 12 bios_ctrl */
  9216. 0, /* 13 sdtr_speed2 */
  9217. 0, /* 14 sdtr_speed3 */
  9218. 1, /* 15 max_host_qng */
  9219. 1, /* max_dvc_qng */
  9220. 0, /* 16 dvc_cntl */
  9221. 0, /* 17 sdtr_speed4 */
  9222. 0, /* 18 serial_number_word1 */
  9223. 0, /* 19 serial_number_word2 */
  9224. 0, /* 20 serial_number_word3 */
  9225. 0, /* 21 check_sum */
  9226. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  9227. , /* 22-29 oem_name[16] */
  9228. 0, /* 30 dvc_err_code */
  9229. 0, /* 31 adv_err_code */
  9230. 0, /* 32 adv_err_addr */
  9231. 0, /* 33 saved_dvc_err_code */
  9232. 0, /* 34 saved_adv_err_code */
  9233. 0, /* 35 saved_adv_err_addr */
  9234. 0, /* 36 reserved */
  9235. 0, /* 37 reserved */
  9236. 0, /* 38 reserved */
  9237. 0, /* 39 reserved */
  9238. 0, /* 40 reserved */
  9239. 0, /* 41 reserved */
  9240. 0, /* 42 reserved */
  9241. 0, /* 43 reserved */
  9242. 0, /* 44 reserved */
  9243. 0, /* 45 reserved */
  9244. 0, /* 46 reserved */
  9245. 0, /* 47 reserved */
  9246. 0, /* 48 reserved */
  9247. 0, /* 49 reserved */
  9248. 0, /* 50 reserved */
  9249. 0, /* 51 reserved */
  9250. 0, /* 52 reserved */
  9251. 0, /* 53 reserved */
  9252. 0, /* 54 reserved */
  9253. 0, /* 55 reserved */
  9254. 0, /* 56 cisptr_lsw */
  9255. 0, /* 57 cisprt_msw */
  9256. 0, /* 58 subsysvid */
  9257. 0, /* 59 subsysid */
  9258. 0, /* 60 reserved */
  9259. 0, /* 61 reserved */
  9260. 0, /* 62 reserved */
  9261. 0 /* 63 reserved */
  9262. };
  9263. #ifdef CONFIG_PCI
  9264. /*
  9265. * Wait for EEPROM command to complete
  9266. */
  9267. static void AdvWaitEEPCmd(AdvPortAddr iop_base)
  9268. {
  9269. int eep_delay_ms;
  9270. for (eep_delay_ms = 0; eep_delay_ms < ADV_EEP_DELAY_MS; eep_delay_ms++) {
  9271. if (AdvReadWordRegister(iop_base, IOPW_EE_CMD) &
  9272. ASC_EEP_CMD_DONE) {
  9273. break;
  9274. }
  9275. mdelay(1);
  9276. }
  9277. if ((AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE) ==
  9278. 0)
  9279. BUG();
  9280. }
  9281. /*
  9282. * Read the EEPROM from specified location
  9283. */
  9284. static ushort AdvReadEEPWord(AdvPortAddr iop_base, int eep_word_addr)
  9285. {
  9286. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9287. ASC_EEP_CMD_READ | eep_word_addr);
  9288. AdvWaitEEPCmd(iop_base);
  9289. return AdvReadWordRegister(iop_base, IOPW_EE_DATA);
  9290. }
  9291. /*
  9292. * Write the EEPROM from 'cfg_buf'.
  9293. */
  9294. static void AdvSet3550EEPConfig(AdvPortAddr iop_base,
  9295. ADVEEP_3550_CONFIG *cfg_buf)
  9296. {
  9297. ushort *wbuf;
  9298. ushort addr, chksum;
  9299. ushort *charfields;
  9300. wbuf = (ushort *)cfg_buf;
  9301. charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
  9302. chksum = 0;
  9303. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  9304. AdvWaitEEPCmd(iop_base);
  9305. /*
  9306. * Write EEPROM from word 0 to word 20.
  9307. */
  9308. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  9309. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  9310. ushort word;
  9311. if (*charfields++) {
  9312. word = cpu_to_le16(*wbuf);
  9313. } else {
  9314. word = *wbuf;
  9315. }
  9316. chksum += *wbuf; /* Checksum is calculated from word values. */
  9317. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9318. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9319. ASC_EEP_CMD_WRITE | addr);
  9320. AdvWaitEEPCmd(iop_base);
  9321. mdelay(ADV_EEP_DELAY_MS);
  9322. }
  9323. /*
  9324. * Write EEPROM checksum at word 21.
  9325. */
  9326. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  9327. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  9328. AdvWaitEEPCmd(iop_base);
  9329. wbuf++;
  9330. charfields++;
  9331. /*
  9332. * Write EEPROM OEM name at words 22 to 29.
  9333. */
  9334. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  9335. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  9336. ushort word;
  9337. if (*charfields++) {
  9338. word = cpu_to_le16(*wbuf);
  9339. } else {
  9340. word = *wbuf;
  9341. }
  9342. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9343. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9344. ASC_EEP_CMD_WRITE | addr);
  9345. AdvWaitEEPCmd(iop_base);
  9346. }
  9347. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  9348. AdvWaitEEPCmd(iop_base);
  9349. }
  9350. /*
  9351. * Write the EEPROM from 'cfg_buf'.
  9352. */
  9353. static void AdvSet38C0800EEPConfig(AdvPortAddr iop_base,
  9354. ADVEEP_38C0800_CONFIG *cfg_buf)
  9355. {
  9356. ushort *wbuf;
  9357. ushort *charfields;
  9358. ushort addr, chksum;
  9359. wbuf = (ushort *)cfg_buf;
  9360. charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
  9361. chksum = 0;
  9362. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  9363. AdvWaitEEPCmd(iop_base);
  9364. /*
  9365. * Write EEPROM from word 0 to word 20.
  9366. */
  9367. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  9368. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  9369. ushort word;
  9370. if (*charfields++) {
  9371. word = cpu_to_le16(*wbuf);
  9372. } else {
  9373. word = *wbuf;
  9374. }
  9375. chksum += *wbuf; /* Checksum is calculated from word values. */
  9376. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9377. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9378. ASC_EEP_CMD_WRITE | addr);
  9379. AdvWaitEEPCmd(iop_base);
  9380. mdelay(ADV_EEP_DELAY_MS);
  9381. }
  9382. /*
  9383. * Write EEPROM checksum at word 21.
  9384. */
  9385. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  9386. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  9387. AdvWaitEEPCmd(iop_base);
  9388. wbuf++;
  9389. charfields++;
  9390. /*
  9391. * Write EEPROM OEM name at words 22 to 29.
  9392. */
  9393. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  9394. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  9395. ushort word;
  9396. if (*charfields++) {
  9397. word = cpu_to_le16(*wbuf);
  9398. } else {
  9399. word = *wbuf;
  9400. }
  9401. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9402. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9403. ASC_EEP_CMD_WRITE | addr);
  9404. AdvWaitEEPCmd(iop_base);
  9405. }
  9406. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  9407. AdvWaitEEPCmd(iop_base);
  9408. }
  9409. /*
  9410. * Write the EEPROM from 'cfg_buf'.
  9411. */
  9412. static void AdvSet38C1600EEPConfig(AdvPortAddr iop_base,
  9413. ADVEEP_38C1600_CONFIG *cfg_buf)
  9414. {
  9415. ushort *wbuf;
  9416. ushort *charfields;
  9417. ushort addr, chksum;
  9418. wbuf = (ushort *)cfg_buf;
  9419. charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
  9420. chksum = 0;
  9421. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
  9422. AdvWaitEEPCmd(iop_base);
  9423. /*
  9424. * Write EEPROM from word 0 to word 20.
  9425. */
  9426. for (addr = ADV_EEP_DVC_CFG_BEGIN;
  9427. addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) {
  9428. ushort word;
  9429. if (*charfields++) {
  9430. word = cpu_to_le16(*wbuf);
  9431. } else {
  9432. word = *wbuf;
  9433. }
  9434. chksum += *wbuf; /* Checksum is calculated from word values. */
  9435. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9436. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9437. ASC_EEP_CMD_WRITE | addr);
  9438. AdvWaitEEPCmd(iop_base);
  9439. mdelay(ADV_EEP_DELAY_MS);
  9440. }
  9441. /*
  9442. * Write EEPROM checksum at word 21.
  9443. */
  9444. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
  9445. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
  9446. AdvWaitEEPCmd(iop_base);
  9447. wbuf++;
  9448. charfields++;
  9449. /*
  9450. * Write EEPROM OEM name at words 22 to 29.
  9451. */
  9452. for (addr = ADV_EEP_DVC_CTL_BEGIN;
  9453. addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
  9454. ushort word;
  9455. if (*charfields++) {
  9456. word = cpu_to_le16(*wbuf);
  9457. } else {
  9458. word = *wbuf;
  9459. }
  9460. AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
  9461. AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
  9462. ASC_EEP_CMD_WRITE | addr);
  9463. AdvWaitEEPCmd(iop_base);
  9464. }
  9465. AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
  9466. AdvWaitEEPCmd(iop_base);
  9467. }
  9468. /*
  9469. * Read EEPROM configuration into the specified buffer.
  9470. *
  9471. * Return a checksum based on the EEPROM configuration read.
  9472. */
  9473. static ushort AdvGet3550EEPConfig(AdvPortAddr iop_base,
  9474. ADVEEP_3550_CONFIG *cfg_buf)
  9475. {
  9476. ushort wval, chksum;
  9477. ushort *wbuf;
  9478. int eep_addr;
  9479. ushort *charfields;
  9480. charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar;
  9481. wbuf = (ushort *)cfg_buf;
  9482. chksum = 0;
  9483. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  9484. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  9485. wval = AdvReadEEPWord(iop_base, eep_addr);
  9486. chksum += wval; /* Checksum is calculated from word values. */
  9487. if (*charfields++) {
  9488. *wbuf = le16_to_cpu(wval);
  9489. } else {
  9490. *wbuf = wval;
  9491. }
  9492. }
  9493. /* Read checksum word. */
  9494. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9495. wbuf++;
  9496. charfields++;
  9497. /* Read rest of EEPROM not covered by the checksum. */
  9498. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  9499. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  9500. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9501. if (*charfields++) {
  9502. *wbuf = le16_to_cpu(*wbuf);
  9503. }
  9504. }
  9505. return chksum;
  9506. }
  9507. /*
  9508. * Read EEPROM configuration into the specified buffer.
  9509. *
  9510. * Return a checksum based on the EEPROM configuration read.
  9511. */
  9512. static ushort AdvGet38C0800EEPConfig(AdvPortAddr iop_base,
  9513. ADVEEP_38C0800_CONFIG *cfg_buf)
  9514. {
  9515. ushort wval, chksum;
  9516. ushort *wbuf;
  9517. int eep_addr;
  9518. ushort *charfields;
  9519. charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar;
  9520. wbuf = (ushort *)cfg_buf;
  9521. chksum = 0;
  9522. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  9523. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  9524. wval = AdvReadEEPWord(iop_base, eep_addr);
  9525. chksum += wval; /* Checksum is calculated from word values. */
  9526. if (*charfields++) {
  9527. *wbuf = le16_to_cpu(wval);
  9528. } else {
  9529. *wbuf = wval;
  9530. }
  9531. }
  9532. /* Read checksum word. */
  9533. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9534. wbuf++;
  9535. charfields++;
  9536. /* Read rest of EEPROM not covered by the checksum. */
  9537. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  9538. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  9539. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9540. if (*charfields++) {
  9541. *wbuf = le16_to_cpu(*wbuf);
  9542. }
  9543. }
  9544. return chksum;
  9545. }
  9546. /*
  9547. * Read EEPROM configuration into the specified buffer.
  9548. *
  9549. * Return a checksum based on the EEPROM configuration read.
  9550. */
  9551. static ushort AdvGet38C1600EEPConfig(AdvPortAddr iop_base,
  9552. ADVEEP_38C1600_CONFIG *cfg_buf)
  9553. {
  9554. ushort wval, chksum;
  9555. ushort *wbuf;
  9556. int eep_addr;
  9557. ushort *charfields;
  9558. charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar;
  9559. wbuf = (ushort *)cfg_buf;
  9560. chksum = 0;
  9561. for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
  9562. eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) {
  9563. wval = AdvReadEEPWord(iop_base, eep_addr);
  9564. chksum += wval; /* Checksum is calculated from word values. */
  9565. if (*charfields++) {
  9566. *wbuf = le16_to_cpu(wval);
  9567. } else {
  9568. *wbuf = wval;
  9569. }
  9570. }
  9571. /* Read checksum word. */
  9572. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9573. wbuf++;
  9574. charfields++;
  9575. /* Read rest of EEPROM not covered by the checksum. */
  9576. for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
  9577. eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) {
  9578. *wbuf = AdvReadEEPWord(iop_base, eep_addr);
  9579. if (*charfields++) {
  9580. *wbuf = le16_to_cpu(*wbuf);
  9581. }
  9582. }
  9583. return chksum;
  9584. }
  9585. /*
  9586. * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
  9587. * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
  9588. * all of this is done.
  9589. *
  9590. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  9591. *
  9592. * For a non-fatal error return a warning code. If there are no warnings
  9593. * then 0 is returned.
  9594. *
  9595. * Note: Chip is stopped on entry.
  9596. */
  9597. static int AdvInitFrom3550EEP(ADV_DVC_VAR *asc_dvc)
  9598. {
  9599. AdvPortAddr iop_base;
  9600. ushort warn_code;
  9601. ADVEEP_3550_CONFIG eep_config;
  9602. iop_base = asc_dvc->iop_base;
  9603. warn_code = 0;
  9604. /*
  9605. * Read the board's EEPROM configuration.
  9606. *
  9607. * Set default values if a bad checksum is found.
  9608. */
  9609. if (AdvGet3550EEPConfig(iop_base, &eep_config) != eep_config.check_sum) {
  9610. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  9611. /*
  9612. * Set EEPROM default values.
  9613. */
  9614. memcpy(&eep_config, &Default_3550_EEPROM_Config,
  9615. sizeof(ADVEEP_3550_CONFIG));
  9616. /*
  9617. * Assume the 6 byte board serial number that was read from
  9618. * EEPROM is correct even if the EEPROM checksum failed.
  9619. */
  9620. eep_config.serial_number_word3 =
  9621. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  9622. eep_config.serial_number_word2 =
  9623. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  9624. eep_config.serial_number_word1 =
  9625. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  9626. AdvSet3550EEPConfig(iop_base, &eep_config);
  9627. }
  9628. /*
  9629. * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
  9630. * EEPROM configuration that was read.
  9631. *
  9632. * This is the mapping of EEPROM fields to Adv Library fields.
  9633. */
  9634. asc_dvc->wdtr_able = eep_config.wdtr_able;
  9635. asc_dvc->sdtr_able = eep_config.sdtr_able;
  9636. asc_dvc->ultra_able = eep_config.ultra_able;
  9637. asc_dvc->tagqng_able = eep_config.tagqng_able;
  9638. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  9639. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9640. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9641. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
  9642. asc_dvc->start_motor = eep_config.start_motor;
  9643. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  9644. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  9645. asc_dvc->no_scam = eep_config.scam_tolerant;
  9646. asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
  9647. asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
  9648. asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
  9649. /*
  9650. * Set the host maximum queuing (max. 253, min. 16) and the per device
  9651. * maximum queuing (max. 63, min. 4).
  9652. */
  9653. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  9654. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9655. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  9656. /* If the value is zero, assume it is uninitialized. */
  9657. if (eep_config.max_host_qng == 0) {
  9658. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9659. } else {
  9660. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  9661. }
  9662. }
  9663. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  9664. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9665. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  9666. /* If the value is zero, assume it is uninitialized. */
  9667. if (eep_config.max_dvc_qng == 0) {
  9668. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9669. } else {
  9670. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  9671. }
  9672. }
  9673. /*
  9674. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  9675. * set 'max_dvc_qng' to 'max_host_qng'.
  9676. */
  9677. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  9678. eep_config.max_dvc_qng = eep_config.max_host_qng;
  9679. }
  9680. /*
  9681. * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
  9682. * values based on possibly adjusted EEPROM values.
  9683. */
  9684. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9685. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9686. /*
  9687. * If the EEPROM 'termination' field is set to automatic (0), then set
  9688. * the ADV_DVC_CFG 'termination' field to automatic also.
  9689. *
  9690. * If the termination is specified with a non-zero 'termination'
  9691. * value check that a legal value is set and set the ADV_DVC_CFG
  9692. * 'termination' field appropriately.
  9693. */
  9694. if (eep_config.termination == 0) {
  9695. asc_dvc->cfg->termination = 0; /* auto termination */
  9696. } else {
  9697. /* Enable manual control with low off / high off. */
  9698. if (eep_config.termination == 1) {
  9699. asc_dvc->cfg->termination = TERM_CTL_SEL;
  9700. /* Enable manual control with low off / high on. */
  9701. } else if (eep_config.termination == 2) {
  9702. asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H;
  9703. /* Enable manual control with low on / high on. */
  9704. } else if (eep_config.termination == 3) {
  9705. asc_dvc->cfg->termination =
  9706. TERM_CTL_SEL | TERM_CTL_H | TERM_CTL_L;
  9707. } else {
  9708. /*
  9709. * The EEPROM 'termination' field contains a bad value. Use
  9710. * automatic termination instead.
  9711. */
  9712. asc_dvc->cfg->termination = 0;
  9713. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9714. }
  9715. }
  9716. return warn_code;
  9717. }
  9718. /*
  9719. * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
  9720. * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
  9721. * all of this is done.
  9722. *
  9723. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  9724. *
  9725. * For a non-fatal error return a warning code. If there are no warnings
  9726. * then 0 is returned.
  9727. *
  9728. * Note: Chip is stopped on entry.
  9729. */
  9730. static int AdvInitFrom38C0800EEP(ADV_DVC_VAR *asc_dvc)
  9731. {
  9732. AdvPortAddr iop_base;
  9733. ushort warn_code;
  9734. ADVEEP_38C0800_CONFIG eep_config;
  9735. uchar tid, termination;
  9736. ushort sdtr_speed = 0;
  9737. iop_base = asc_dvc->iop_base;
  9738. warn_code = 0;
  9739. /*
  9740. * Read the board's EEPROM configuration.
  9741. *
  9742. * Set default values if a bad checksum is found.
  9743. */
  9744. if (AdvGet38C0800EEPConfig(iop_base, &eep_config) !=
  9745. eep_config.check_sum) {
  9746. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  9747. /*
  9748. * Set EEPROM default values.
  9749. */
  9750. memcpy(&eep_config, &Default_38C0800_EEPROM_Config,
  9751. sizeof(ADVEEP_38C0800_CONFIG));
  9752. /*
  9753. * Assume the 6 byte board serial number that was read from
  9754. * EEPROM is correct even if the EEPROM checksum failed.
  9755. */
  9756. eep_config.serial_number_word3 =
  9757. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  9758. eep_config.serial_number_word2 =
  9759. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  9760. eep_config.serial_number_word1 =
  9761. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  9762. AdvSet38C0800EEPConfig(iop_base, &eep_config);
  9763. }
  9764. /*
  9765. * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
  9766. * EEPROM configuration that was read.
  9767. *
  9768. * This is the mapping of EEPROM fields to Adv Library fields.
  9769. */
  9770. asc_dvc->wdtr_able = eep_config.wdtr_able;
  9771. asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
  9772. asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
  9773. asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
  9774. asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
  9775. asc_dvc->tagqng_able = eep_config.tagqng_able;
  9776. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  9777. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9778. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9779. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
  9780. asc_dvc->start_motor = eep_config.start_motor;
  9781. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  9782. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  9783. asc_dvc->no_scam = eep_config.scam_tolerant;
  9784. asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
  9785. asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
  9786. asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
  9787. /*
  9788. * For every Target ID if any of its 'sdtr_speed[1234]' bits
  9789. * are set, then set an 'sdtr_able' bit for it.
  9790. */
  9791. asc_dvc->sdtr_able = 0;
  9792. for (tid = 0; tid <= ADV_MAX_TID; tid++) {
  9793. if (tid == 0) {
  9794. sdtr_speed = asc_dvc->sdtr_speed1;
  9795. } else if (tid == 4) {
  9796. sdtr_speed = asc_dvc->sdtr_speed2;
  9797. } else if (tid == 8) {
  9798. sdtr_speed = asc_dvc->sdtr_speed3;
  9799. } else if (tid == 12) {
  9800. sdtr_speed = asc_dvc->sdtr_speed4;
  9801. }
  9802. if (sdtr_speed & ADV_MAX_TID) {
  9803. asc_dvc->sdtr_able |= (1 << tid);
  9804. }
  9805. sdtr_speed >>= 4;
  9806. }
  9807. /*
  9808. * Set the host maximum queuing (max. 253, min. 16) and the per device
  9809. * maximum queuing (max. 63, min. 4).
  9810. */
  9811. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  9812. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9813. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  9814. /* If the value is zero, assume it is uninitialized. */
  9815. if (eep_config.max_host_qng == 0) {
  9816. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  9817. } else {
  9818. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  9819. }
  9820. }
  9821. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  9822. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9823. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  9824. /* If the value is zero, assume it is uninitialized. */
  9825. if (eep_config.max_dvc_qng == 0) {
  9826. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  9827. } else {
  9828. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  9829. }
  9830. }
  9831. /*
  9832. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  9833. * set 'max_dvc_qng' to 'max_host_qng'.
  9834. */
  9835. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  9836. eep_config.max_dvc_qng = eep_config.max_host_qng;
  9837. }
  9838. /*
  9839. * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
  9840. * values based on possibly adjusted EEPROM values.
  9841. */
  9842. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9843. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9844. /*
  9845. * If the EEPROM 'termination' field is set to automatic (0), then set
  9846. * the ADV_DVC_CFG 'termination' field to automatic also.
  9847. *
  9848. * If the termination is specified with a non-zero 'termination'
  9849. * value check that a legal value is set and set the ADV_DVC_CFG
  9850. * 'termination' field appropriately.
  9851. */
  9852. if (eep_config.termination_se == 0) {
  9853. termination = 0; /* auto termination for SE */
  9854. } else {
  9855. /* Enable manual control with low off / high off. */
  9856. if (eep_config.termination_se == 1) {
  9857. termination = 0;
  9858. /* Enable manual control with low off / high on. */
  9859. } else if (eep_config.termination_se == 2) {
  9860. termination = TERM_SE_HI;
  9861. /* Enable manual control with low on / high on. */
  9862. } else if (eep_config.termination_se == 3) {
  9863. termination = TERM_SE;
  9864. } else {
  9865. /*
  9866. * The EEPROM 'termination_se' field contains a bad value.
  9867. * Use automatic termination instead.
  9868. */
  9869. termination = 0;
  9870. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9871. }
  9872. }
  9873. if (eep_config.termination_lvd == 0) {
  9874. asc_dvc->cfg->termination = termination; /* auto termination for LVD */
  9875. } else {
  9876. /* Enable manual control with low off / high off. */
  9877. if (eep_config.termination_lvd == 1) {
  9878. asc_dvc->cfg->termination = termination;
  9879. /* Enable manual control with low off / high on. */
  9880. } else if (eep_config.termination_lvd == 2) {
  9881. asc_dvc->cfg->termination = termination | TERM_LVD_HI;
  9882. /* Enable manual control with low on / high on. */
  9883. } else if (eep_config.termination_lvd == 3) {
  9884. asc_dvc->cfg->termination = termination | TERM_LVD;
  9885. } else {
  9886. /*
  9887. * The EEPROM 'termination_lvd' field contains a bad value.
  9888. * Use automatic termination instead.
  9889. */
  9890. asc_dvc->cfg->termination = termination;
  9891. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  9892. }
  9893. }
  9894. return warn_code;
  9895. }
  9896. /*
  9897. * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and
  9898. * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while
  9899. * all of this is done.
  9900. *
  9901. * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
  9902. *
  9903. * For a non-fatal error return a warning code. If there are no warnings
  9904. * then 0 is returned.
  9905. *
  9906. * Note: Chip is stopped on entry.
  9907. */
  9908. static int AdvInitFrom38C1600EEP(ADV_DVC_VAR *asc_dvc)
  9909. {
  9910. AdvPortAddr iop_base;
  9911. ushort warn_code;
  9912. ADVEEP_38C1600_CONFIG eep_config;
  9913. uchar tid, termination;
  9914. ushort sdtr_speed = 0;
  9915. iop_base = asc_dvc->iop_base;
  9916. warn_code = 0;
  9917. /*
  9918. * Read the board's EEPROM configuration.
  9919. *
  9920. * Set default values if a bad checksum is found.
  9921. */
  9922. if (AdvGet38C1600EEPConfig(iop_base, &eep_config) !=
  9923. eep_config.check_sum) {
  9924. struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc);
  9925. warn_code |= ASC_WARN_EEPROM_CHKSUM;
  9926. /*
  9927. * Set EEPROM default values.
  9928. */
  9929. memcpy(&eep_config, &Default_38C1600_EEPROM_Config,
  9930. sizeof(ADVEEP_38C1600_CONFIG));
  9931. if (PCI_FUNC(pdev->devfn) != 0) {
  9932. u8 ints;
  9933. /*
  9934. * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60
  9935. * and old Mac system booting problem. The Expansion
  9936. * ROM must be disabled in Function 1 for these systems
  9937. */
  9938. eep_config.cfg_lsw &= ~ADV_EEPROM_BIOS_ENABLE;
  9939. /*
  9940. * Clear the INTAB (bit 11) if the GPIO 0 input
  9941. * indicates the Function 1 interrupt line is wired
  9942. * to INTB.
  9943. *
  9944. * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
  9945. * 1 - Function 1 interrupt line wired to INT A.
  9946. * 0 - Function 1 interrupt line wired to INT B.
  9947. *
  9948. * Note: Function 0 is always wired to INTA.
  9949. * Put all 5 GPIO bits in input mode and then read
  9950. * their input values.
  9951. */
  9952. AdvWriteByteRegister(iop_base, IOPB_GPIO_CNTL, 0);
  9953. ints = AdvReadByteRegister(iop_base, IOPB_GPIO_DATA);
  9954. if ((ints & 0x01) == 0)
  9955. eep_config.cfg_lsw &= ~ADV_EEPROM_INTAB;
  9956. }
  9957. /*
  9958. * Assume the 6 byte board serial number that was read from
  9959. * EEPROM is correct even if the EEPROM checksum failed.
  9960. */
  9961. eep_config.serial_number_word3 =
  9962. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
  9963. eep_config.serial_number_word2 =
  9964. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
  9965. eep_config.serial_number_word1 =
  9966. AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
  9967. AdvSet38C1600EEPConfig(iop_base, &eep_config);
  9968. }
  9969. /*
  9970. * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
  9971. * EEPROM configuration that was read.
  9972. *
  9973. * This is the mapping of EEPROM fields to Adv Library fields.
  9974. */
  9975. asc_dvc->wdtr_able = eep_config.wdtr_able;
  9976. asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
  9977. asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
  9978. asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
  9979. asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
  9980. asc_dvc->ppr_able = 0;
  9981. asc_dvc->tagqng_able = eep_config.tagqng_able;
  9982. asc_dvc->cfg->disc_enable = eep_config.disc_enable;
  9983. asc_dvc->max_host_qng = eep_config.max_host_qng;
  9984. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  9985. asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ASC_MAX_TID);
  9986. asc_dvc->start_motor = eep_config.start_motor;
  9987. asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
  9988. asc_dvc->bios_ctrl = eep_config.bios_ctrl;
  9989. asc_dvc->no_scam = eep_config.scam_tolerant;
  9990. /*
  9991. * For every Target ID if any of its 'sdtr_speed[1234]' bits
  9992. * are set, then set an 'sdtr_able' bit for it.
  9993. */
  9994. asc_dvc->sdtr_able = 0;
  9995. for (tid = 0; tid <= ASC_MAX_TID; tid++) {
  9996. if (tid == 0) {
  9997. sdtr_speed = asc_dvc->sdtr_speed1;
  9998. } else if (tid == 4) {
  9999. sdtr_speed = asc_dvc->sdtr_speed2;
  10000. } else if (tid == 8) {
  10001. sdtr_speed = asc_dvc->sdtr_speed3;
  10002. } else if (tid == 12) {
  10003. sdtr_speed = asc_dvc->sdtr_speed4;
  10004. }
  10005. if (sdtr_speed & ASC_MAX_TID) {
  10006. asc_dvc->sdtr_able |= (1 << tid);
  10007. }
  10008. sdtr_speed >>= 4;
  10009. }
  10010. /*
  10011. * Set the host maximum queuing (max. 253, min. 16) and the per device
  10012. * maximum queuing (max. 63, min. 4).
  10013. */
  10014. if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
  10015. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10016. } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
  10017. /* If the value is zero, assume it is uninitialized. */
  10018. if (eep_config.max_host_qng == 0) {
  10019. eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
  10020. } else {
  10021. eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
  10022. }
  10023. }
  10024. if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
  10025. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10026. } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
  10027. /* If the value is zero, assume it is uninitialized. */
  10028. if (eep_config.max_dvc_qng == 0) {
  10029. eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
  10030. } else {
  10031. eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
  10032. }
  10033. }
  10034. /*
  10035. * If 'max_dvc_qng' is greater than 'max_host_qng', then
  10036. * set 'max_dvc_qng' to 'max_host_qng'.
  10037. */
  10038. if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
  10039. eep_config.max_dvc_qng = eep_config.max_host_qng;
  10040. }
  10041. /*
  10042. * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng'
  10043. * values based on possibly adjusted EEPROM values.
  10044. */
  10045. asc_dvc->max_host_qng = eep_config.max_host_qng;
  10046. asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
  10047. /*
  10048. * If the EEPROM 'termination' field is set to automatic (0), then set
  10049. * the ASC_DVC_CFG 'termination' field to automatic also.
  10050. *
  10051. * If the termination is specified with a non-zero 'termination'
  10052. * value check that a legal value is set and set the ASC_DVC_CFG
  10053. * 'termination' field appropriately.
  10054. */
  10055. if (eep_config.termination_se == 0) {
  10056. termination = 0; /* auto termination for SE */
  10057. } else {
  10058. /* Enable manual control with low off / high off. */
  10059. if (eep_config.termination_se == 1) {
  10060. termination = 0;
  10061. /* Enable manual control with low off / high on. */
  10062. } else if (eep_config.termination_se == 2) {
  10063. termination = TERM_SE_HI;
  10064. /* Enable manual control with low on / high on. */
  10065. } else if (eep_config.termination_se == 3) {
  10066. termination = TERM_SE;
  10067. } else {
  10068. /*
  10069. * The EEPROM 'termination_se' field contains a bad value.
  10070. * Use automatic termination instead.
  10071. */
  10072. termination = 0;
  10073. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10074. }
  10075. }
  10076. if (eep_config.termination_lvd == 0) {
  10077. asc_dvc->cfg->termination = termination; /* auto termination for LVD */
  10078. } else {
  10079. /* Enable manual control with low off / high off. */
  10080. if (eep_config.termination_lvd == 1) {
  10081. asc_dvc->cfg->termination = termination;
  10082. /* Enable manual control with low off / high on. */
  10083. } else if (eep_config.termination_lvd == 2) {
  10084. asc_dvc->cfg->termination = termination | TERM_LVD_HI;
  10085. /* Enable manual control with low on / high on. */
  10086. } else if (eep_config.termination_lvd == 3) {
  10087. asc_dvc->cfg->termination = termination | TERM_LVD;
  10088. } else {
  10089. /*
  10090. * The EEPROM 'termination_lvd' field contains a bad value.
  10091. * Use automatic termination instead.
  10092. */
  10093. asc_dvc->cfg->termination = termination;
  10094. warn_code |= ASC_WARN_EEPROM_TERMINATION;
  10095. }
  10096. }
  10097. return warn_code;
  10098. }
  10099. /*
  10100. * Initialize the ADV_DVC_VAR structure.
  10101. *
  10102. * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
  10103. *
  10104. * For a non-fatal error return a warning code. If there are no warnings
  10105. * then 0 is returned.
  10106. */
  10107. static int AdvInitGetConfig(struct pci_dev *pdev, struct Scsi_Host *shost)
  10108. {
  10109. struct asc_board *board = shost_priv(shost);
  10110. ADV_DVC_VAR *asc_dvc = &board->dvc_var.adv_dvc_var;
  10111. unsigned short warn_code = 0;
  10112. AdvPortAddr iop_base = asc_dvc->iop_base;
  10113. u16 cmd;
  10114. int status;
  10115. asc_dvc->err_code = 0;
  10116. /*
  10117. * Save the state of the PCI Configuration Command Register
  10118. * "Parity Error Response Control" Bit. If the bit is clear (0),
  10119. * in AdvInitAsc3550/38C0800Driver() tell the microcode to ignore
  10120. * DMA parity errors.
  10121. */
  10122. asc_dvc->cfg->control_flag = 0;
  10123. pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  10124. if ((cmd & PCI_COMMAND_PARITY) == 0)
  10125. asc_dvc->cfg->control_flag |= CONTROL_FLAG_IGNORE_PERR;
  10126. asc_dvc->cfg->chip_version =
  10127. AdvGetChipVersion(iop_base, asc_dvc->bus_type);
  10128. ASC_DBG(1, "iopb_chip_id_1: 0x%x 0x%x\n",
  10129. (ushort)AdvReadByteRegister(iop_base, IOPB_CHIP_ID_1),
  10130. (ushort)ADV_CHIP_ID_BYTE);
  10131. ASC_DBG(1, "iopw_chip_id_0: 0x%x 0x%x\n",
  10132. (ushort)AdvReadWordRegister(iop_base, IOPW_CHIP_ID_0),
  10133. (ushort)ADV_CHIP_ID_WORD);
  10134. /*
  10135. * Reset the chip to start and allow register writes.
  10136. */
  10137. if (AdvFindSignature(iop_base) == 0) {
  10138. asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
  10139. return ADV_ERROR;
  10140. } else {
  10141. /*
  10142. * The caller must set 'chip_type' to a valid setting.
  10143. */
  10144. if (asc_dvc->chip_type != ADV_CHIP_ASC3550 &&
  10145. asc_dvc->chip_type != ADV_CHIP_ASC38C0800 &&
  10146. asc_dvc->chip_type != ADV_CHIP_ASC38C1600) {
  10147. asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE;
  10148. return ADV_ERROR;
  10149. }
  10150. /*
  10151. * Reset Chip.
  10152. */
  10153. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  10154. ADV_CTRL_REG_CMD_RESET);
  10155. mdelay(100);
  10156. AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
  10157. ADV_CTRL_REG_CMD_WR_IO_REG);
  10158. if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) {
  10159. status = AdvInitFrom38C1600EEP(asc_dvc);
  10160. } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  10161. status = AdvInitFrom38C0800EEP(asc_dvc);
  10162. } else {
  10163. status = AdvInitFrom3550EEP(asc_dvc);
  10164. }
  10165. warn_code |= status;
  10166. }
  10167. if (warn_code != 0)
  10168. shost_printk(KERN_WARNING, shost, "warning: 0x%x\n", warn_code);
  10169. if (asc_dvc->err_code)
  10170. shost_printk(KERN_ERR, shost, "error code 0x%x\n",
  10171. asc_dvc->err_code);
  10172. return asc_dvc->err_code;
  10173. }
  10174. #endif
  10175. static struct scsi_host_template advansys_template = {
  10176. .proc_name = DRV_NAME,
  10177. #ifdef CONFIG_PROC_FS
  10178. .show_info = advansys_show_info,
  10179. #endif
  10180. .name = DRV_NAME,
  10181. .info = advansys_info,
  10182. .queuecommand = advansys_queuecommand,
  10183. .eh_bus_reset_handler = advansys_reset,
  10184. .bios_param = advansys_biosparam,
  10185. .slave_configure = advansys_slave_configure,
  10186. /*
  10187. * Because the driver may control an ISA adapter 'unchecked_isa_dma'
  10188. * must be set. The flag will be cleared in advansys_board_found
  10189. * for non-ISA adapters.
  10190. */
  10191. .unchecked_isa_dma = 1,
  10192. /*
  10193. * All adapters controlled by this driver are capable of large
  10194. * scatter-gather lists. According to the mid-level SCSI documentation
  10195. * this obviates any performance gain provided by setting
  10196. * 'use_clustering'. But empirically while CPU utilization is increased
  10197. * by enabling clustering, I/O throughput increases as well.
  10198. */
  10199. .use_clustering = ENABLE_CLUSTERING,
  10200. };
  10201. static int advansys_wide_init_chip(struct Scsi_Host *shost)
  10202. {
  10203. struct asc_board *board = shost_priv(shost);
  10204. struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
  10205. int req_cnt = 0;
  10206. adv_req_t *reqp = NULL;
  10207. int sg_cnt = 0;
  10208. adv_sgblk_t *sgp;
  10209. int warn_code, err_code;
  10210. /*
  10211. * Allocate buffer carrier structures. The total size
  10212. * is about 4 KB, so allocate all at once.
  10213. */
  10214. adv_dvc->carrier_buf = kmalloc(ADV_CARRIER_BUFSIZE, GFP_KERNEL);
  10215. ASC_DBG(1, "carrier_buf 0x%p\n", adv_dvc->carrier_buf);
  10216. if (!adv_dvc->carrier_buf)
  10217. goto kmalloc_failed;
  10218. /*
  10219. * Allocate up to 'max_host_qng' request structures for the Wide
  10220. * board. The total size is about 16 KB, so allocate all at once.
  10221. * If the allocation fails decrement and try again.
  10222. */
  10223. for (req_cnt = adv_dvc->max_host_qng; req_cnt > 0; req_cnt--) {
  10224. reqp = kmalloc(sizeof(adv_req_t) * req_cnt, GFP_KERNEL);
  10225. ASC_DBG(1, "reqp 0x%p, req_cnt %d, bytes %lu\n", reqp, req_cnt,
  10226. (ulong)sizeof(adv_req_t) * req_cnt);
  10227. if (reqp)
  10228. break;
  10229. }
  10230. if (!reqp)
  10231. goto kmalloc_failed;
  10232. adv_dvc->orig_reqp = reqp;
  10233. /*
  10234. * Allocate up to ADV_TOT_SG_BLOCK request structures for
  10235. * the Wide board. Each structure is about 136 bytes.
  10236. */
  10237. board->adv_sgblkp = NULL;
  10238. for (sg_cnt = 0; sg_cnt < ADV_TOT_SG_BLOCK; sg_cnt++) {
  10239. sgp = kmalloc(sizeof(adv_sgblk_t), GFP_KERNEL);
  10240. if (!sgp)
  10241. break;
  10242. sgp->next_sgblkp = board->adv_sgblkp;
  10243. board->adv_sgblkp = sgp;
  10244. }
  10245. ASC_DBG(1, "sg_cnt %d * %lu = %lu bytes\n", sg_cnt, sizeof(adv_sgblk_t),
  10246. sizeof(adv_sgblk_t) * sg_cnt);
  10247. if (!board->adv_sgblkp)
  10248. goto kmalloc_failed;
  10249. /*
  10250. * Point 'adv_reqp' to the request structures and
  10251. * link them together.
  10252. */
  10253. req_cnt--;
  10254. reqp[req_cnt].next_reqp = NULL;
  10255. for (; req_cnt > 0; req_cnt--) {
  10256. reqp[req_cnt - 1].next_reqp = &reqp[req_cnt];
  10257. }
  10258. board->adv_reqp = &reqp[0];
  10259. if (adv_dvc->chip_type == ADV_CHIP_ASC3550) {
  10260. ASC_DBG(2, "AdvInitAsc3550Driver()\n");
  10261. warn_code = AdvInitAsc3550Driver(adv_dvc);
  10262. } else if (adv_dvc->chip_type == ADV_CHIP_ASC38C0800) {
  10263. ASC_DBG(2, "AdvInitAsc38C0800Driver()\n");
  10264. warn_code = AdvInitAsc38C0800Driver(adv_dvc);
  10265. } else {
  10266. ASC_DBG(2, "AdvInitAsc38C1600Driver()\n");
  10267. warn_code = AdvInitAsc38C1600Driver(adv_dvc);
  10268. }
  10269. err_code = adv_dvc->err_code;
  10270. if (warn_code || err_code) {
  10271. shost_printk(KERN_WARNING, shost, "error: warn 0x%x, error "
  10272. "0x%x\n", warn_code, err_code);
  10273. }
  10274. goto exit;
  10275. kmalloc_failed:
  10276. shost_printk(KERN_ERR, shost, "error: kmalloc() failed\n");
  10277. err_code = ADV_ERROR;
  10278. exit:
  10279. return err_code;
  10280. }
  10281. static void advansys_wide_free_mem(struct asc_board *board)
  10282. {
  10283. struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var;
  10284. kfree(adv_dvc->carrier_buf);
  10285. adv_dvc->carrier_buf = NULL;
  10286. kfree(adv_dvc->orig_reqp);
  10287. adv_dvc->orig_reqp = board->adv_reqp = NULL;
  10288. while (board->adv_sgblkp) {
  10289. adv_sgblk_t *sgp = board->adv_sgblkp;
  10290. board->adv_sgblkp = sgp->next_sgblkp;
  10291. kfree(sgp);
  10292. }
  10293. }
  10294. static int advansys_board_found(struct Scsi_Host *shost, unsigned int iop,
  10295. int bus_type)
  10296. {
  10297. struct pci_dev *pdev;
  10298. struct asc_board *boardp = shost_priv(shost);
  10299. ASC_DVC_VAR *asc_dvc_varp = NULL;
  10300. ADV_DVC_VAR *adv_dvc_varp = NULL;
  10301. int share_irq, warn_code, ret;
  10302. pdev = (bus_type == ASC_IS_PCI) ? to_pci_dev(boardp->dev) : NULL;
  10303. if (ASC_NARROW_BOARD(boardp)) {
  10304. ASC_DBG(1, "narrow board\n");
  10305. asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
  10306. asc_dvc_varp->bus_type = bus_type;
  10307. asc_dvc_varp->drv_ptr = boardp;
  10308. asc_dvc_varp->cfg = &boardp->dvc_cfg.asc_dvc_cfg;
  10309. asc_dvc_varp->iop_base = iop;
  10310. } else {
  10311. #ifdef CONFIG_PCI
  10312. adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
  10313. adv_dvc_varp->drv_ptr = boardp;
  10314. adv_dvc_varp->cfg = &boardp->dvc_cfg.adv_dvc_cfg;
  10315. if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW) {
  10316. ASC_DBG(1, "wide board ASC-3550\n");
  10317. adv_dvc_varp->chip_type = ADV_CHIP_ASC3550;
  10318. } else if (pdev->device == PCI_DEVICE_ID_38C0800_REV1) {
  10319. ASC_DBG(1, "wide board ASC-38C0800\n");
  10320. adv_dvc_varp->chip_type = ADV_CHIP_ASC38C0800;
  10321. } else {
  10322. ASC_DBG(1, "wide board ASC-38C1600\n");
  10323. adv_dvc_varp->chip_type = ADV_CHIP_ASC38C1600;
  10324. }
  10325. boardp->asc_n_io_port = pci_resource_len(pdev, 1);
  10326. boardp->ioremap_addr = pci_ioremap_bar(pdev, 1);
  10327. if (!boardp->ioremap_addr) {
  10328. shost_printk(KERN_ERR, shost, "ioremap(%lx, %d) "
  10329. "returned NULL\n",
  10330. (long)pci_resource_start(pdev, 1),
  10331. boardp->asc_n_io_port);
  10332. ret = -ENODEV;
  10333. goto err_shost;
  10334. }
  10335. adv_dvc_varp->iop_base = (AdvPortAddr)boardp->ioremap_addr;
  10336. ASC_DBG(1, "iop_base: 0x%p\n", adv_dvc_varp->iop_base);
  10337. /*
  10338. * Even though it isn't used to access wide boards, other
  10339. * than for the debug line below, save I/O Port address so
  10340. * that it can be reported.
  10341. */
  10342. boardp->ioport = iop;
  10343. ASC_DBG(1, "iopb_chip_id_1 0x%x, iopw_chip_id_0 0x%x\n",
  10344. (ushort)inp(iop + 1), (ushort)inpw(iop));
  10345. #endif /* CONFIG_PCI */
  10346. }
  10347. if (ASC_NARROW_BOARD(boardp)) {
  10348. /*
  10349. * Set the board bus type and PCI IRQ before
  10350. * calling AscInitGetConfig().
  10351. */
  10352. switch (asc_dvc_varp->bus_type) {
  10353. #ifdef CONFIG_ISA
  10354. case ASC_IS_ISA:
  10355. shost->unchecked_isa_dma = TRUE;
  10356. share_irq = 0;
  10357. break;
  10358. case ASC_IS_VL:
  10359. shost->unchecked_isa_dma = FALSE;
  10360. share_irq = 0;
  10361. break;
  10362. case ASC_IS_EISA:
  10363. shost->unchecked_isa_dma = FALSE;
  10364. share_irq = IRQF_SHARED;
  10365. break;
  10366. #endif /* CONFIG_ISA */
  10367. #ifdef CONFIG_PCI
  10368. case ASC_IS_PCI:
  10369. shost->unchecked_isa_dma = FALSE;
  10370. share_irq = IRQF_SHARED;
  10371. break;
  10372. #endif /* CONFIG_PCI */
  10373. default:
  10374. shost_printk(KERN_ERR, shost, "unknown adapter type: "
  10375. "%d\n", asc_dvc_varp->bus_type);
  10376. shost->unchecked_isa_dma = TRUE;
  10377. share_irq = 0;
  10378. break;
  10379. }
  10380. /*
  10381. * NOTE: AscInitGetConfig() may change the board's
  10382. * bus_type value. The bus_type value should no
  10383. * longer be used. If the bus_type field must be
  10384. * referenced only use the bit-wise AND operator "&".
  10385. */
  10386. ASC_DBG(2, "AscInitGetConfig()\n");
  10387. ret = AscInitGetConfig(shost) ? -ENODEV : 0;
  10388. } else {
  10389. #ifdef CONFIG_PCI
  10390. /*
  10391. * For Wide boards set PCI information before calling
  10392. * AdvInitGetConfig().
  10393. */
  10394. shost->unchecked_isa_dma = FALSE;
  10395. share_irq = IRQF_SHARED;
  10396. ASC_DBG(2, "AdvInitGetConfig()\n");
  10397. ret = AdvInitGetConfig(pdev, shost) ? -ENODEV : 0;
  10398. #endif /* CONFIG_PCI */
  10399. }
  10400. if (ret)
  10401. goto err_unmap;
  10402. /*
  10403. * Save the EEPROM configuration so that it can be displayed
  10404. * from /proc/scsi/advansys/[0...].
  10405. */
  10406. if (ASC_NARROW_BOARD(boardp)) {
  10407. ASCEEP_CONFIG *ep;
  10408. /*
  10409. * Set the adapter's target id bit in the 'init_tidmask' field.
  10410. */
  10411. boardp->init_tidmask |=
  10412. ADV_TID_TO_TIDMASK(asc_dvc_varp->cfg->chip_scsi_id);
  10413. /*
  10414. * Save EEPROM settings for the board.
  10415. */
  10416. ep = &boardp->eep_config.asc_eep;
  10417. ep->init_sdtr = asc_dvc_varp->cfg->sdtr_enable;
  10418. ep->disc_enable = asc_dvc_varp->cfg->disc_enable;
  10419. ep->use_cmd_qng = asc_dvc_varp->cfg->cmd_qng_enabled;
  10420. ASC_EEP_SET_DMA_SPD(ep, asc_dvc_varp->cfg->isa_dma_speed);
  10421. ep->start_motor = asc_dvc_varp->start_motor;
  10422. ep->cntl = asc_dvc_varp->dvc_cntl;
  10423. ep->no_scam = asc_dvc_varp->no_scam;
  10424. ep->max_total_qng = asc_dvc_varp->max_total_qng;
  10425. ASC_EEP_SET_CHIP_ID(ep, asc_dvc_varp->cfg->chip_scsi_id);
  10426. /* 'max_tag_qng' is set to the same value for every device. */
  10427. ep->max_tag_qng = asc_dvc_varp->cfg->max_tag_qng[0];
  10428. ep->adapter_info[0] = asc_dvc_varp->cfg->adapter_info[0];
  10429. ep->adapter_info[1] = asc_dvc_varp->cfg->adapter_info[1];
  10430. ep->adapter_info[2] = asc_dvc_varp->cfg->adapter_info[2];
  10431. ep->adapter_info[3] = asc_dvc_varp->cfg->adapter_info[3];
  10432. ep->adapter_info[4] = asc_dvc_varp->cfg->adapter_info[4];
  10433. ep->adapter_info[5] = asc_dvc_varp->cfg->adapter_info[5];
  10434. /*
  10435. * Modify board configuration.
  10436. */
  10437. ASC_DBG(2, "AscInitSetConfig()\n");
  10438. ret = AscInitSetConfig(pdev, shost) ? -ENODEV : 0;
  10439. if (ret)
  10440. goto err_unmap;
  10441. } else {
  10442. ADVEEP_3550_CONFIG *ep_3550;
  10443. ADVEEP_38C0800_CONFIG *ep_38C0800;
  10444. ADVEEP_38C1600_CONFIG *ep_38C1600;
  10445. /*
  10446. * Save Wide EEP Configuration Information.
  10447. */
  10448. if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) {
  10449. ep_3550 = &boardp->eep_config.adv_3550_eep;
  10450. ep_3550->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
  10451. ep_3550->max_host_qng = adv_dvc_varp->max_host_qng;
  10452. ep_3550->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10453. ep_3550->termination = adv_dvc_varp->cfg->termination;
  10454. ep_3550->disc_enable = adv_dvc_varp->cfg->disc_enable;
  10455. ep_3550->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10456. ep_3550->wdtr_able = adv_dvc_varp->wdtr_able;
  10457. ep_3550->sdtr_able = adv_dvc_varp->sdtr_able;
  10458. ep_3550->ultra_able = adv_dvc_varp->ultra_able;
  10459. ep_3550->tagqng_able = adv_dvc_varp->tagqng_able;
  10460. ep_3550->start_motor = adv_dvc_varp->start_motor;
  10461. ep_3550->scsi_reset_delay =
  10462. adv_dvc_varp->scsi_reset_wait;
  10463. ep_3550->serial_number_word1 =
  10464. adv_dvc_varp->cfg->serial1;
  10465. ep_3550->serial_number_word2 =
  10466. adv_dvc_varp->cfg->serial2;
  10467. ep_3550->serial_number_word3 =
  10468. adv_dvc_varp->cfg->serial3;
  10469. } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
  10470. ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
  10471. ep_38C0800->adapter_scsi_id =
  10472. adv_dvc_varp->chip_scsi_id;
  10473. ep_38C0800->max_host_qng = adv_dvc_varp->max_host_qng;
  10474. ep_38C0800->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10475. ep_38C0800->termination_lvd =
  10476. adv_dvc_varp->cfg->termination;
  10477. ep_38C0800->disc_enable =
  10478. adv_dvc_varp->cfg->disc_enable;
  10479. ep_38C0800->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10480. ep_38C0800->wdtr_able = adv_dvc_varp->wdtr_able;
  10481. ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
  10482. ep_38C0800->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
  10483. ep_38C0800->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
  10484. ep_38C0800->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
  10485. ep_38C0800->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
  10486. ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
  10487. ep_38C0800->start_motor = adv_dvc_varp->start_motor;
  10488. ep_38C0800->scsi_reset_delay =
  10489. adv_dvc_varp->scsi_reset_wait;
  10490. ep_38C0800->serial_number_word1 =
  10491. adv_dvc_varp->cfg->serial1;
  10492. ep_38C0800->serial_number_word2 =
  10493. adv_dvc_varp->cfg->serial2;
  10494. ep_38C0800->serial_number_word3 =
  10495. adv_dvc_varp->cfg->serial3;
  10496. } else {
  10497. ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
  10498. ep_38C1600->adapter_scsi_id =
  10499. adv_dvc_varp->chip_scsi_id;
  10500. ep_38C1600->max_host_qng = adv_dvc_varp->max_host_qng;
  10501. ep_38C1600->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
  10502. ep_38C1600->termination_lvd =
  10503. adv_dvc_varp->cfg->termination;
  10504. ep_38C1600->disc_enable =
  10505. adv_dvc_varp->cfg->disc_enable;
  10506. ep_38C1600->bios_ctrl = adv_dvc_varp->bios_ctrl;
  10507. ep_38C1600->wdtr_able = adv_dvc_varp->wdtr_able;
  10508. ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
  10509. ep_38C1600->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
  10510. ep_38C1600->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
  10511. ep_38C1600->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
  10512. ep_38C1600->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
  10513. ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
  10514. ep_38C1600->start_motor = adv_dvc_varp->start_motor;
  10515. ep_38C1600->scsi_reset_delay =
  10516. adv_dvc_varp->scsi_reset_wait;
  10517. ep_38C1600->serial_number_word1 =
  10518. adv_dvc_varp->cfg->serial1;
  10519. ep_38C1600->serial_number_word2 =
  10520. adv_dvc_varp->cfg->serial2;
  10521. ep_38C1600->serial_number_word3 =
  10522. adv_dvc_varp->cfg->serial3;
  10523. }
  10524. /*
  10525. * Set the adapter's target id bit in the 'init_tidmask' field.
  10526. */
  10527. boardp->init_tidmask |=
  10528. ADV_TID_TO_TIDMASK(adv_dvc_varp->chip_scsi_id);
  10529. }
  10530. /*
  10531. * Channels are numbered beginning with 0. For AdvanSys one host
  10532. * structure supports one channel. Multi-channel boards have a
  10533. * separate host structure for each channel.
  10534. */
  10535. shost->max_channel = 0;
  10536. if (ASC_NARROW_BOARD(boardp)) {
  10537. shost->max_id = ASC_MAX_TID + 1;
  10538. shost->max_lun = ASC_MAX_LUN + 1;
  10539. shost->max_cmd_len = ASC_MAX_CDB_LEN;
  10540. shost->io_port = asc_dvc_varp->iop_base;
  10541. boardp->asc_n_io_port = ASC_IOADR_GAP;
  10542. shost->this_id = asc_dvc_varp->cfg->chip_scsi_id;
  10543. /* Set maximum number of queues the adapter can handle. */
  10544. shost->can_queue = asc_dvc_varp->max_total_qng;
  10545. } else {
  10546. shost->max_id = ADV_MAX_TID + 1;
  10547. shost->max_lun = ADV_MAX_LUN + 1;
  10548. shost->max_cmd_len = ADV_MAX_CDB_LEN;
  10549. /*
  10550. * Save the I/O Port address and length even though
  10551. * I/O ports are not used to access Wide boards.
  10552. * Instead the Wide boards are accessed with
  10553. * PCI Memory Mapped I/O.
  10554. */
  10555. shost->io_port = iop;
  10556. shost->this_id = adv_dvc_varp->chip_scsi_id;
  10557. /* Set maximum number of queues the adapter can handle. */
  10558. shost->can_queue = adv_dvc_varp->max_host_qng;
  10559. }
  10560. /*
  10561. * Following v1.3.89, 'cmd_per_lun' is no longer needed
  10562. * and should be set to zero.
  10563. *
  10564. * But because of a bug introduced in v1.3.89 if the driver is
  10565. * compiled as a module and 'cmd_per_lun' is zero, the Mid-Level
  10566. * SCSI function 'allocate_device' will panic. To allow the driver
  10567. * to work as a module in these kernels set 'cmd_per_lun' to 1.
  10568. *
  10569. * Note: This is wrong. cmd_per_lun should be set to the depth
  10570. * you want on untagged devices always.
  10571. #ifdef MODULE
  10572. */
  10573. shost->cmd_per_lun = 1;
  10574. /* #else
  10575. shost->cmd_per_lun = 0;
  10576. #endif */
  10577. /*
  10578. * Set the maximum number of scatter-gather elements the
  10579. * adapter can handle.
  10580. */
  10581. if (ASC_NARROW_BOARD(boardp)) {
  10582. /*
  10583. * Allow two commands with 'sg_tablesize' scatter-gather
  10584. * elements to be executed simultaneously. This value is
  10585. * the theoretical hardware limit. It may be decreased
  10586. * below.
  10587. */
  10588. shost->sg_tablesize =
  10589. (((asc_dvc_varp->max_total_qng - 2) / 2) *
  10590. ASC_SG_LIST_PER_Q) + 1;
  10591. } else {
  10592. shost->sg_tablesize = ADV_MAX_SG_LIST;
  10593. }
  10594. /*
  10595. * The value of 'sg_tablesize' can not exceed the SCSI
  10596. * mid-level driver definition of SG_ALL. SG_ALL also
  10597. * must not be exceeded, because it is used to define the
  10598. * size of the scatter-gather table in 'struct asc_sg_head'.
  10599. */
  10600. if (shost->sg_tablesize > SG_ALL) {
  10601. shost->sg_tablesize = SG_ALL;
  10602. }
  10603. ASC_DBG(1, "sg_tablesize: %d\n", shost->sg_tablesize);
  10604. /* BIOS start address. */
  10605. if (ASC_NARROW_BOARD(boardp)) {
  10606. shost->base = AscGetChipBiosAddress(asc_dvc_varp->iop_base,
  10607. asc_dvc_varp->bus_type);
  10608. } else {
  10609. /*
  10610. * Fill-in BIOS board variables. The Wide BIOS saves
  10611. * information in LRAM that is used by the driver.
  10612. */
  10613. AdvReadWordLram(adv_dvc_varp->iop_base,
  10614. BIOS_SIGNATURE, boardp->bios_signature);
  10615. AdvReadWordLram(adv_dvc_varp->iop_base,
  10616. BIOS_VERSION, boardp->bios_version);
  10617. AdvReadWordLram(adv_dvc_varp->iop_base,
  10618. BIOS_CODESEG, boardp->bios_codeseg);
  10619. AdvReadWordLram(adv_dvc_varp->iop_base,
  10620. BIOS_CODELEN, boardp->bios_codelen);
  10621. ASC_DBG(1, "bios_signature 0x%x, bios_version 0x%x\n",
  10622. boardp->bios_signature, boardp->bios_version);
  10623. ASC_DBG(1, "bios_codeseg 0x%x, bios_codelen 0x%x\n",
  10624. boardp->bios_codeseg, boardp->bios_codelen);
  10625. /*
  10626. * If the BIOS saved a valid signature, then fill in
  10627. * the BIOS code segment base address.
  10628. */
  10629. if (boardp->bios_signature == 0x55AA) {
  10630. /*
  10631. * Convert x86 realmode code segment to a linear
  10632. * address by shifting left 4.
  10633. */
  10634. shost->base = ((ulong)boardp->bios_codeseg << 4);
  10635. } else {
  10636. shost->base = 0;
  10637. }
  10638. }
  10639. /*
  10640. * Register Board Resources - I/O Port, DMA, IRQ
  10641. */
  10642. /* Register DMA Channel for Narrow boards. */
  10643. shost->dma_channel = NO_ISA_DMA; /* Default to no ISA DMA. */
  10644. #ifdef CONFIG_ISA
  10645. if (ASC_NARROW_BOARD(boardp)) {
  10646. /* Register DMA channel for ISA bus. */
  10647. if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
  10648. shost->dma_channel = asc_dvc_varp->cfg->isa_dma_channel;
  10649. ret = request_dma(shost->dma_channel, DRV_NAME);
  10650. if (ret) {
  10651. shost_printk(KERN_ERR, shost, "request_dma() "
  10652. "%d failed %d\n",
  10653. shost->dma_channel, ret);
  10654. goto err_unmap;
  10655. }
  10656. AscEnableIsaDma(shost->dma_channel);
  10657. }
  10658. }
  10659. #endif /* CONFIG_ISA */
  10660. /* Register IRQ Number. */
  10661. ASC_DBG(2, "request_irq(%d, %p)\n", boardp->irq, shost);
  10662. ret = request_irq(boardp->irq, advansys_interrupt, share_irq,
  10663. DRV_NAME, shost);
  10664. if (ret) {
  10665. if (ret == -EBUSY) {
  10666. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  10667. "already in use\n", boardp->irq);
  10668. } else if (ret == -EINVAL) {
  10669. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  10670. "not valid\n", boardp->irq);
  10671. } else {
  10672. shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x "
  10673. "failed with %d\n", boardp->irq, ret);
  10674. }
  10675. goto err_free_dma;
  10676. }
  10677. /*
  10678. * Initialize board RISC chip and enable interrupts.
  10679. */
  10680. if (ASC_NARROW_BOARD(boardp)) {
  10681. ASC_DBG(2, "AscInitAsc1000Driver()\n");
  10682. asc_dvc_varp->overrun_buf = kzalloc(ASC_OVERRUN_BSIZE, GFP_KERNEL);
  10683. if (!asc_dvc_varp->overrun_buf) {
  10684. ret = -ENOMEM;
  10685. goto err_free_irq;
  10686. }
  10687. warn_code = AscInitAsc1000Driver(asc_dvc_varp);
  10688. if (warn_code || asc_dvc_varp->err_code) {
  10689. shost_printk(KERN_ERR, shost, "error: init_state 0x%x, "
  10690. "warn 0x%x, error 0x%x\n",
  10691. asc_dvc_varp->init_state, warn_code,
  10692. asc_dvc_varp->err_code);
  10693. if (!asc_dvc_varp->overrun_dma) {
  10694. ret = -ENODEV;
  10695. goto err_free_mem;
  10696. }
  10697. }
  10698. } else {
  10699. if (advansys_wide_init_chip(shost)) {
  10700. ret = -ENODEV;
  10701. goto err_free_mem;
  10702. }
  10703. }
  10704. ASC_DBG_PRT_SCSI_HOST(2, shost);
  10705. ret = scsi_add_host(shost, boardp->dev);
  10706. if (ret)
  10707. goto err_free_mem;
  10708. scsi_scan_host(shost);
  10709. return 0;
  10710. err_free_mem:
  10711. if (ASC_NARROW_BOARD(boardp)) {
  10712. if (asc_dvc_varp->overrun_dma)
  10713. dma_unmap_single(boardp->dev, asc_dvc_varp->overrun_dma,
  10714. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  10715. kfree(asc_dvc_varp->overrun_buf);
  10716. } else
  10717. advansys_wide_free_mem(boardp);
  10718. err_free_irq:
  10719. free_irq(boardp->irq, shost);
  10720. err_free_dma:
  10721. #ifdef CONFIG_ISA
  10722. if (shost->dma_channel != NO_ISA_DMA)
  10723. free_dma(shost->dma_channel);
  10724. #endif
  10725. err_unmap:
  10726. if (boardp->ioremap_addr)
  10727. iounmap(boardp->ioremap_addr);
  10728. err_shost:
  10729. return ret;
  10730. }
  10731. /*
  10732. * advansys_release()
  10733. *
  10734. * Release resources allocated for a single AdvanSys adapter.
  10735. */
  10736. static int advansys_release(struct Scsi_Host *shost)
  10737. {
  10738. struct asc_board *board = shost_priv(shost);
  10739. ASC_DBG(1, "begin\n");
  10740. scsi_remove_host(shost);
  10741. free_irq(board->irq, shost);
  10742. #ifdef CONFIG_ISA
  10743. if (shost->dma_channel != NO_ISA_DMA) {
  10744. ASC_DBG(1, "free_dma()\n");
  10745. free_dma(shost->dma_channel);
  10746. }
  10747. #endif
  10748. if (ASC_NARROW_BOARD(board)) {
  10749. dma_unmap_single(board->dev,
  10750. board->dvc_var.asc_dvc_var.overrun_dma,
  10751. ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE);
  10752. kfree(board->dvc_var.asc_dvc_var.overrun_buf);
  10753. } else {
  10754. iounmap(board->ioremap_addr);
  10755. advansys_wide_free_mem(board);
  10756. }
  10757. scsi_host_put(shost);
  10758. ASC_DBG(1, "end\n");
  10759. return 0;
  10760. }
  10761. #define ASC_IOADR_TABLE_MAX_IX 11
  10762. static PortAddr _asc_def_iop_base[ASC_IOADR_TABLE_MAX_IX] = {
  10763. 0x100, 0x0110, 0x120, 0x0130, 0x140, 0x0150, 0x0190,
  10764. 0x0210, 0x0230, 0x0250, 0x0330
  10765. };
  10766. /*
  10767. * The ISA IRQ number is found in bits 2 and 3 of the CfgLsw. It decodes as:
  10768. * 00: 10
  10769. * 01: 11
  10770. * 10: 12
  10771. * 11: 15
  10772. */
  10773. static unsigned int advansys_isa_irq_no(PortAddr iop_base)
  10774. {
  10775. unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
  10776. unsigned int chip_irq = ((cfg_lsw >> 2) & 0x03) + 10;
  10777. if (chip_irq == 13)
  10778. chip_irq = 15;
  10779. return chip_irq;
  10780. }
  10781. static int advansys_isa_probe(struct device *dev, unsigned int id)
  10782. {
  10783. int err = -ENODEV;
  10784. PortAddr iop_base = _asc_def_iop_base[id];
  10785. struct Scsi_Host *shost;
  10786. struct asc_board *board;
  10787. if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
  10788. ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
  10789. return -ENODEV;
  10790. }
  10791. ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
  10792. if (!AscFindSignature(iop_base))
  10793. goto release_region;
  10794. if (!(AscGetChipVersion(iop_base, ASC_IS_ISA) & ASC_CHIP_VER_ISA_BIT))
  10795. goto release_region;
  10796. err = -ENOMEM;
  10797. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  10798. if (!shost)
  10799. goto release_region;
  10800. board = shost_priv(shost);
  10801. board->irq = advansys_isa_irq_no(iop_base);
  10802. board->dev = dev;
  10803. err = advansys_board_found(shost, iop_base, ASC_IS_ISA);
  10804. if (err)
  10805. goto free_host;
  10806. dev_set_drvdata(dev, shost);
  10807. return 0;
  10808. free_host:
  10809. scsi_host_put(shost);
  10810. release_region:
  10811. release_region(iop_base, ASC_IOADR_GAP);
  10812. return err;
  10813. }
  10814. static int advansys_isa_remove(struct device *dev, unsigned int id)
  10815. {
  10816. int ioport = _asc_def_iop_base[id];
  10817. advansys_release(dev_get_drvdata(dev));
  10818. release_region(ioport, ASC_IOADR_GAP);
  10819. return 0;
  10820. }
  10821. static struct isa_driver advansys_isa_driver = {
  10822. .probe = advansys_isa_probe,
  10823. .remove = advansys_isa_remove,
  10824. .driver = {
  10825. .owner = THIS_MODULE,
  10826. .name = DRV_NAME,
  10827. },
  10828. };
  10829. /*
  10830. * The VLB IRQ number is found in bits 2 to 4 of the CfgLsw. It decodes as:
  10831. * 000: invalid
  10832. * 001: 10
  10833. * 010: 11
  10834. * 011: 12
  10835. * 100: invalid
  10836. * 101: 14
  10837. * 110: 15
  10838. * 111: invalid
  10839. */
  10840. static unsigned int advansys_vlb_irq_no(PortAddr iop_base)
  10841. {
  10842. unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base);
  10843. unsigned int chip_irq = ((cfg_lsw >> 2) & 0x07) + 9;
  10844. if ((chip_irq < 10) || (chip_irq == 13) || (chip_irq > 15))
  10845. return 0;
  10846. return chip_irq;
  10847. }
  10848. static int advansys_vlb_probe(struct device *dev, unsigned int id)
  10849. {
  10850. int err = -ENODEV;
  10851. PortAddr iop_base = _asc_def_iop_base[id];
  10852. struct Scsi_Host *shost;
  10853. struct asc_board *board;
  10854. if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) {
  10855. ASC_DBG(1, "I/O port 0x%x busy\n", iop_base);
  10856. return -ENODEV;
  10857. }
  10858. ASC_DBG(1, "probing I/O port 0x%x\n", iop_base);
  10859. if (!AscFindSignature(iop_base))
  10860. goto release_region;
  10861. /*
  10862. * I don't think this condition can actually happen, but the old
  10863. * driver did it, and the chances of finding a VLB setup in 2007
  10864. * to do testing with is slight to none.
  10865. */
  10866. if (AscGetChipVersion(iop_base, ASC_IS_VL) > ASC_CHIP_MAX_VER_VL)
  10867. goto release_region;
  10868. err = -ENOMEM;
  10869. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  10870. if (!shost)
  10871. goto release_region;
  10872. board = shost_priv(shost);
  10873. board->irq = advansys_vlb_irq_no(iop_base);
  10874. board->dev = dev;
  10875. err = advansys_board_found(shost, iop_base, ASC_IS_VL);
  10876. if (err)
  10877. goto free_host;
  10878. dev_set_drvdata(dev, shost);
  10879. return 0;
  10880. free_host:
  10881. scsi_host_put(shost);
  10882. release_region:
  10883. release_region(iop_base, ASC_IOADR_GAP);
  10884. return -ENODEV;
  10885. }
  10886. static struct isa_driver advansys_vlb_driver = {
  10887. .probe = advansys_vlb_probe,
  10888. .remove = advansys_isa_remove,
  10889. .driver = {
  10890. .owner = THIS_MODULE,
  10891. .name = "advansys_vlb",
  10892. },
  10893. };
  10894. static struct eisa_device_id advansys_eisa_table[] = {
  10895. { "ABP7401" },
  10896. { "ABP7501" },
  10897. { "" }
  10898. };
  10899. MODULE_DEVICE_TABLE(eisa, advansys_eisa_table);
  10900. /*
  10901. * EISA is a little more tricky than PCI; each EISA device may have two
  10902. * channels, and this driver is written to make each channel its own Scsi_Host
  10903. */
  10904. struct eisa_scsi_data {
  10905. struct Scsi_Host *host[2];
  10906. };
  10907. /*
  10908. * The EISA IRQ number is found in bits 8 to 10 of the CfgLsw. It decodes as:
  10909. * 000: 10
  10910. * 001: 11
  10911. * 010: 12
  10912. * 011: invalid
  10913. * 100: 14
  10914. * 101: 15
  10915. * 110: invalid
  10916. * 111: invalid
  10917. */
  10918. static unsigned int advansys_eisa_irq_no(struct eisa_device *edev)
  10919. {
  10920. unsigned short cfg_lsw = inw(edev->base_addr + 0xc86);
  10921. unsigned int chip_irq = ((cfg_lsw >> 8) & 0x07) + 10;
  10922. if ((chip_irq == 13) || (chip_irq > 15))
  10923. return 0;
  10924. return chip_irq;
  10925. }
  10926. static int advansys_eisa_probe(struct device *dev)
  10927. {
  10928. int i, ioport, irq = 0;
  10929. int err;
  10930. struct eisa_device *edev = to_eisa_device(dev);
  10931. struct eisa_scsi_data *data;
  10932. err = -ENOMEM;
  10933. data = kzalloc(sizeof(*data), GFP_KERNEL);
  10934. if (!data)
  10935. goto fail;
  10936. ioport = edev->base_addr + 0xc30;
  10937. err = -ENODEV;
  10938. for (i = 0; i < 2; i++, ioport += 0x20) {
  10939. struct asc_board *board;
  10940. struct Scsi_Host *shost;
  10941. if (!request_region(ioport, ASC_IOADR_GAP, DRV_NAME)) {
  10942. printk(KERN_WARNING "Region %x-%x busy\n", ioport,
  10943. ioport + ASC_IOADR_GAP - 1);
  10944. continue;
  10945. }
  10946. if (!AscFindSignature(ioport)) {
  10947. release_region(ioport, ASC_IOADR_GAP);
  10948. continue;
  10949. }
  10950. /*
  10951. * I don't know why we need to do this for EISA chips, but
  10952. * not for any others. It looks to be equivalent to
  10953. * AscGetChipCfgMsw, but I may have overlooked something,
  10954. * so I'm not converting it until I get an EISA board to
  10955. * test with.
  10956. */
  10957. inw(ioport + 4);
  10958. if (!irq)
  10959. irq = advansys_eisa_irq_no(edev);
  10960. err = -ENOMEM;
  10961. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  10962. if (!shost)
  10963. goto release_region;
  10964. board = shost_priv(shost);
  10965. board->irq = irq;
  10966. board->dev = dev;
  10967. err = advansys_board_found(shost, ioport, ASC_IS_EISA);
  10968. if (!err) {
  10969. data->host[i] = shost;
  10970. continue;
  10971. }
  10972. scsi_host_put(shost);
  10973. release_region:
  10974. release_region(ioport, ASC_IOADR_GAP);
  10975. break;
  10976. }
  10977. if (err)
  10978. goto free_data;
  10979. dev_set_drvdata(dev, data);
  10980. return 0;
  10981. free_data:
  10982. kfree(data->host[0]);
  10983. kfree(data->host[1]);
  10984. kfree(data);
  10985. fail:
  10986. return err;
  10987. }
  10988. static int advansys_eisa_remove(struct device *dev)
  10989. {
  10990. int i;
  10991. struct eisa_scsi_data *data = dev_get_drvdata(dev);
  10992. for (i = 0; i < 2; i++) {
  10993. int ioport;
  10994. struct Scsi_Host *shost = data->host[i];
  10995. if (!shost)
  10996. continue;
  10997. ioport = shost->io_port;
  10998. advansys_release(shost);
  10999. release_region(ioport, ASC_IOADR_GAP);
  11000. }
  11001. kfree(data);
  11002. return 0;
  11003. }
  11004. static struct eisa_driver advansys_eisa_driver = {
  11005. .id_table = advansys_eisa_table,
  11006. .driver = {
  11007. .name = DRV_NAME,
  11008. .probe = advansys_eisa_probe,
  11009. .remove = advansys_eisa_remove,
  11010. }
  11011. };
  11012. /* PCI Devices supported by this driver */
  11013. static struct pci_device_id advansys_pci_tbl[] = {
  11014. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_1200A,
  11015. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11016. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940,
  11017. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11018. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940U,
  11019. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11020. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940UW,
  11021. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11022. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C0800_REV1,
  11023. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11024. {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C1600_REV1,
  11025. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  11026. {}
  11027. };
  11028. MODULE_DEVICE_TABLE(pci, advansys_pci_tbl);
  11029. static void advansys_set_latency(struct pci_dev *pdev)
  11030. {
  11031. if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) ||
  11032. (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) {
  11033. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0);
  11034. } else {
  11035. u8 latency;
  11036. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
  11037. if (latency < 0x20)
  11038. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x20);
  11039. }
  11040. }
  11041. static int advansys_pci_probe(struct pci_dev *pdev,
  11042. const struct pci_device_id *ent)
  11043. {
  11044. int err, ioport;
  11045. struct Scsi_Host *shost;
  11046. struct asc_board *board;
  11047. err = pci_enable_device(pdev);
  11048. if (err)
  11049. goto fail;
  11050. err = pci_request_regions(pdev, DRV_NAME);
  11051. if (err)
  11052. goto disable_device;
  11053. pci_set_master(pdev);
  11054. advansys_set_latency(pdev);
  11055. err = -ENODEV;
  11056. if (pci_resource_len(pdev, 0) == 0)
  11057. goto release_region;
  11058. ioport = pci_resource_start(pdev, 0);
  11059. err = -ENOMEM;
  11060. shost = scsi_host_alloc(&advansys_template, sizeof(*board));
  11061. if (!shost)
  11062. goto release_region;
  11063. board = shost_priv(shost);
  11064. board->irq = pdev->irq;
  11065. board->dev = &pdev->dev;
  11066. if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW ||
  11067. pdev->device == PCI_DEVICE_ID_38C0800_REV1 ||
  11068. pdev->device == PCI_DEVICE_ID_38C1600_REV1) {
  11069. board->flags |= ASC_IS_WIDE_BOARD;
  11070. }
  11071. err = advansys_board_found(shost, ioport, ASC_IS_PCI);
  11072. if (err)
  11073. goto free_host;
  11074. pci_set_drvdata(pdev, shost);
  11075. return 0;
  11076. free_host:
  11077. scsi_host_put(shost);
  11078. release_region:
  11079. pci_release_regions(pdev);
  11080. disable_device:
  11081. pci_disable_device(pdev);
  11082. fail:
  11083. return err;
  11084. }
  11085. static void advansys_pci_remove(struct pci_dev *pdev)
  11086. {
  11087. advansys_release(pci_get_drvdata(pdev));
  11088. pci_release_regions(pdev);
  11089. pci_disable_device(pdev);
  11090. }
  11091. static struct pci_driver advansys_pci_driver = {
  11092. .name = DRV_NAME,
  11093. .id_table = advansys_pci_tbl,
  11094. .probe = advansys_pci_probe,
  11095. .remove = advansys_pci_remove,
  11096. };
  11097. static int __init advansys_init(void)
  11098. {
  11099. int error;
  11100. error = isa_register_driver(&advansys_isa_driver,
  11101. ASC_IOADR_TABLE_MAX_IX);
  11102. if (error)
  11103. goto fail;
  11104. error = isa_register_driver(&advansys_vlb_driver,
  11105. ASC_IOADR_TABLE_MAX_IX);
  11106. if (error)
  11107. goto unregister_isa;
  11108. error = eisa_driver_register(&advansys_eisa_driver);
  11109. if (error)
  11110. goto unregister_vlb;
  11111. error = pci_register_driver(&advansys_pci_driver);
  11112. if (error)
  11113. goto unregister_eisa;
  11114. return 0;
  11115. unregister_eisa:
  11116. eisa_driver_unregister(&advansys_eisa_driver);
  11117. unregister_vlb:
  11118. isa_unregister_driver(&advansys_vlb_driver);
  11119. unregister_isa:
  11120. isa_unregister_driver(&advansys_isa_driver);
  11121. fail:
  11122. return error;
  11123. }
  11124. static void __exit advansys_exit(void)
  11125. {
  11126. pci_unregister_driver(&advansys_pci_driver);
  11127. eisa_driver_unregister(&advansys_eisa_driver);
  11128. isa_unregister_driver(&advansys_vlb_driver);
  11129. isa_unregister_driver(&advansys_isa_driver);
  11130. }
  11131. module_init(advansys_init);
  11132. module_exit(advansys_exit);
  11133. MODULE_LICENSE("GPL");
  11134. MODULE_FIRMWARE("advansys/mcode.bin");
  11135. MODULE_FIRMWARE("advansys/3550.bin");
  11136. MODULE_FIRMWARE("advansys/38C0800.bin");
  11137. MODULE_FIRMWARE("advansys/38C1600.bin");