aic7xxx_old.c 360 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196
  1. /*+M*************************************************************************
  2. * Adaptec AIC7xxx device driver for Linux.
  3. *
  4. * Copyright (c) 1994 John Aycock
  5. * The University of Calgary Department of Computer Science.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; see the file COPYING. If not, write to
  19. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20. *
  21. * Sources include the Adaptec 1740 driver (aha1740.c), the Ultrastor 24F
  22. * driver (ultrastor.c), various Linux kernel source, the Adaptec EISA
  23. * config file (!adp7771.cfg), the Adaptec AHA-2740A Series User's Guide,
  24. * the Linux Kernel Hacker's Guide, Writing a SCSI Device Driver for Linux,
  25. * the Adaptec 1542 driver (aha1542.c), the Adaptec EISA overlay file
  26. * (adp7770.ovl), the Adaptec AHA-2740 Series Technical Reference Manual,
  27. * the Adaptec AIC-7770 Data Book, the ANSI SCSI specification, the
  28. * ANSI SCSI-2 specification (draft 10c), ...
  29. *
  30. * --------------------------------------------------------------------------
  31. *
  32. * Modifications by Daniel M. Eischen (deischen@iworks.InterWorks.org):
  33. *
  34. * Substantially modified to include support for wide and twin bus
  35. * adapters, DMAing of SCBs, tagged queueing, IRQ sharing, bug fixes,
  36. * SCB paging, and other rework of the code.
  37. *
  38. * Parts of this driver were also based on the FreeBSD driver by
  39. * Justin T. Gibbs. His copyright follows:
  40. *
  41. * --------------------------------------------------------------------------
  42. * Copyright (c) 1994-1997 Justin Gibbs.
  43. * All rights reserved.
  44. *
  45. * Redistribution and use in source and binary forms, with or without
  46. * modification, are permitted provided that the following conditions
  47. * are met:
  48. * 1. Redistributions of source code must retain the above copyright
  49. * notice, this list of conditions, and the following disclaimer,
  50. * without modification, immediately at the beginning of the file.
  51. * 2. Redistributions in binary form must reproduce the above copyright
  52. * notice, this list of conditions and the following disclaimer in the
  53. * documentation and/or other materials provided with the distribution.
  54. * 3. The name of the author may not be used to endorse or promote products
  55. * derived from this software without specific prior written permission.
  56. *
  57. * Where this Software is combined with software released under the terms of
  58. * the GNU General Public License ("GPL") and the terms of the GPL would require the
  59. * combined work to also be released under the terms of the GPL, the terms
  60. * and conditions of this License will apply in addition to those of the
  61. * GPL with the exception of any terms or conditions of this License that
  62. * conflict with, or are expressly prohibited by, the GPL.
  63. *
  64. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  65. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  68. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  69. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  70. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  71. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  72. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  73. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  74. * SUCH DAMAGE.
  75. *
  76. * $Id: aic7xxx.c,v 1.119 1997/06/27 19:39:18 gibbs Exp $
  77. *---------------------------------------------------------------------------
  78. *
  79. * Thanks also go to (in alphabetical order) the following:
  80. *
  81. * Rory Bolt - Sequencer bug fixes
  82. * Jay Estabrook - Initial DEC Alpha support
  83. * Doug Ledford - Much needed abort/reset bug fixes
  84. * Kai Makisara - DMAing of SCBs
  85. *
  86. * A Boot time option was also added for not resetting the scsi bus.
  87. *
  88. * Form: aic7xxx=extended
  89. * aic7xxx=no_reset
  90. * aic7xxx=ultra
  91. * aic7xxx=irq_trigger:[0,1] # 0 edge, 1 level
  92. * aic7xxx=verbose
  93. *
  94. * Daniel M. Eischen, deischen@iworks.InterWorks.org, 1/23/97
  95. *
  96. * $Id: aic7xxx.c,v 4.1 1997/06/12 08:23:42 deang Exp $
  97. *-M*************************************************************************/
  98. /*+M**************************************************************************
  99. *
  100. * Further driver modifications made by Doug Ledford <dledford@redhat.com>
  101. *
  102. * Copyright (c) 1997-1999 Doug Ledford
  103. *
  104. * These changes are released under the same licensing terms as the FreeBSD
  105. * driver written by Justin Gibbs. Please see his Copyright notice above
  106. * for the exact terms and conditions covering my changes as well as the
  107. * warranty statement.
  108. *
  109. * Modifications made to the aic7xxx.c,v 4.1 driver from Dan Eischen include
  110. * but are not limited to:
  111. *
  112. * 1: Import of the latest FreeBSD sequencer code for this driver
  113. * 2: Modification of kernel code to accommodate different sequencer semantics
  114. * 3: Extensive changes throughout kernel portion of driver to improve
  115. * abort/reset processing and error hanndling
  116. * 4: Other work contributed by various people on the Internet
  117. * 5: Changes to printk information and verbosity selection code
  118. * 6: General reliability related changes, especially in IRQ management
  119. * 7: Modifications to the default probe/attach order for supported cards
  120. * 8: SMP friendliness has been improved
  121. *
  122. * Overall, this driver represents a significant departure from the official
  123. * aic7xxx driver released by Dan Eischen in two ways. First, in the code
  124. * itself. A diff between the two version of the driver is now a several
  125. * thousand line diff. Second, in approach to solving the same problem. The
  126. * problem is importing the FreeBSD aic7xxx driver code to linux can be a
  127. * difficult and time consuming process, that also can be error prone. Dan
  128. * Eischen's official driver uses the approach that the linux and FreeBSD
  129. * drivers should be as identical as possible. To that end, his next version
  130. * of this driver will be using a mid-layer code library that he is developing
  131. * to moderate communications between the linux mid-level SCSI code and the
  132. * low level FreeBSD driver. He intends to be able to essentially drop the
  133. * FreeBSD driver into the linux kernel with only a few minor tweaks to some
  134. * include files and the like and get things working, making for fast easy
  135. * imports of the FreeBSD code into linux.
  136. *
  137. * I disagree with Dan's approach. Not that I don't think his way of doing
  138. * things would be nice, easy to maintain, and create a more uniform driver
  139. * between FreeBSD and Linux. I have no objection to those issues. My
  140. * disagreement is on the needed functionality. There simply are certain
  141. * things that are done differently in FreeBSD than linux that will cause
  142. * problems for this driver regardless of any middle ware Dan implements.
  143. * The biggest example of this at the moment is interrupt semantics. Linux
  144. * doesn't provide the same protection techniques as FreeBSD does, nor can
  145. * they be easily implemented in any middle ware code since they would truly
  146. * belong in the kernel proper and would effect all drivers. For the time
  147. * being, I see issues such as these as major stumbling blocks to the
  148. * reliability of code based upon such middle ware. Therefore, I choose to
  149. * use a different approach to importing the FreeBSD code that doesn't
  150. * involve any middle ware type code. My approach is to import the sequencer
  151. * code from FreeBSD wholesale. Then, to only make changes in the kernel
  152. * portion of the driver as they are needed for the new sequencer semantics.
  153. * In this way, the portion of the driver that speaks to the rest of the
  154. * linux kernel is fairly static and can be changed/modified to solve
  155. * any problems one might encounter without concern for the FreeBSD driver.
  156. *
  157. * Note: If time and experience should prove me wrong that the middle ware
  158. * code Dan writes is reliable in its operation, then I'll retract my above
  159. * statements. But, for those that don't know, I'm from Missouri (in the US)
  160. * and our state motto is "The Show-Me State". Well, before I will put
  161. * faith into it, you'll have to show me that it works :)
  162. *
  163. *_M*************************************************************************/
  164. /*
  165. * The next three defines are user configurable. These should be the only
  166. * defines a user might need to get in here and change. There are other
  167. * defines buried deeper in the code, but those really shouldn't need touched
  168. * under normal conditions.
  169. */
  170. /*
  171. * AIC7XXX_STRICT_PCI_SETUP
  172. * Should we assume the PCI config options on our controllers are set with
  173. * sane and proper values, or should we be anal about our PCI config
  174. * registers and force them to what we want? The main advantage to
  175. * defining this option is on non-Intel hardware where the BIOS may not
  176. * have been run to set things up, or if you have one of the BIOSless
  177. * Adaptec controllers, such as a 2910, that don't get set up by the
  178. * BIOS. However, keep in mind that we really do set the most important
  179. * items in the driver regardless of this setting, this only controls some
  180. * of the more esoteric PCI options on these cards. In that sense, I
  181. * would default to leaving this off. However, if people wish to try
  182. * things both ways, that would also help me to know if there are some
  183. * machines where it works one way but not another.
  184. *
  185. * -- July 7, 17:09
  186. * OK...I need this on my machine for testing, so the default is to
  187. * leave it defined.
  188. *
  189. * -- July 7, 18:49
  190. * I needed it for testing, but it didn't make any difference, so back
  191. * off she goes.
  192. *
  193. * -- July 16, 23:04
  194. * I turned it back on to try and compensate for the 2.1.x PCI code
  195. * which no longer relies solely on the BIOS and now tries to set
  196. * things itself.
  197. */
  198. #define AIC7XXX_STRICT_PCI_SETUP
  199. /*
  200. * AIC7XXX_VERBOSE_DEBUGGING
  201. * This option enables a lot of extra printk();s in the code, surrounded
  202. * by if (aic7xxx_verbose ...) statements. Executing all of those if
  203. * statements and the extra checks can get to where it actually does have
  204. * an impact on CPU usage and such, as well as code size. Disabling this
  205. * define will keep some of those from becoming part of the code.
  206. *
  207. * NOTE: Currently, this option has no real effect, I will be adding the
  208. * various #ifdef's in the code later when I've decided a section is
  209. * complete and no longer needs debugging. OK...a lot of things are now
  210. * surrounded by this define, so turning this off does have an impact.
  211. */
  212. /*
  213. * #define AIC7XXX_VERBOSE_DEBUGGING
  214. */
  215. #include <linux/module.h>
  216. #include <stdarg.h>
  217. #include <asm/io.h>
  218. #include <asm/irq.h>
  219. #include <asm/byteorder.h>
  220. #include <linux/string.h>
  221. #include <linux/errno.h>
  222. #include <linux/kernel.h>
  223. #include <linux/ioport.h>
  224. #include <linux/delay.h>
  225. #include <linux/sched.h>
  226. #include <linux/pci.h>
  227. #include <linux/proc_fs.h>
  228. #include <linux/blkdev.h>
  229. #include <linux/init.h>
  230. #include <linux/spinlock.h>
  231. #include <linux/smp.h>
  232. #include <linux/interrupt.h>
  233. #include "scsi.h"
  234. #include <scsi/scsi_host.h>
  235. #include "aic7xxx_old/aic7xxx.h"
  236. #include "aic7xxx_old/sequencer.h"
  237. #include "aic7xxx_old/scsi_message.h"
  238. #include "aic7xxx_old/aic7xxx_reg.h"
  239. #include <scsi/scsicam.h>
  240. #include <linux/stat.h>
  241. #include <linux/slab.h> /* for kmalloc() */
  242. #define AIC7XXX_C_VERSION "5.2.6"
  243. #define ALL_TARGETS -1
  244. #define ALL_CHANNELS -1
  245. #define ALL_LUNS -1
  246. #define MAX_TARGETS 16
  247. #define MAX_LUNS 8
  248. #ifndef TRUE
  249. # define TRUE 1
  250. #endif
  251. #ifndef FALSE
  252. # define FALSE 0
  253. #endif
  254. #if defined(__powerpc__) || defined(__i386__) || defined(__x86_64__)
  255. # define MMAPIO
  256. #endif
  257. /*
  258. * You can try raising me for better performance or lowering me if you have
  259. * flaky devices that go off the scsi bus when hit with too many tagged
  260. * commands (like some IBM SCSI-3 LVD drives).
  261. */
  262. #define AIC7XXX_CMDS_PER_DEVICE 32
  263. typedef struct
  264. {
  265. unsigned char tag_commands[16]; /* Allow for wide/twin adapters. */
  266. } adapter_tag_info_t;
  267. /*
  268. * Make a define that will tell the driver not to the default tag depth
  269. * everywhere.
  270. */
  271. #define DEFAULT_TAG_COMMANDS {0, 0, 0, 0, 0, 0, 0, 0,\
  272. 0, 0, 0, 0, 0, 0, 0, 0}
  273. /*
  274. * Modify this as you see fit for your system. By setting tag_commands
  275. * to 0, the driver will use it's own algorithm for determining the
  276. * number of commands to use (see above). When 255, the driver will
  277. * not enable tagged queueing for that particular device. When positive
  278. * (> 0) and (< 255) the values in the array are used for the queue_depth.
  279. * Note that the maximum value for an entry is 254, but you're insane if
  280. * you try to use that many commands on one device.
  281. *
  282. * In this example, the first line will disable tagged queueing for all
  283. * the devices on the first probed aic7xxx adapter.
  284. *
  285. * The second line enables tagged queueing with 4 commands/LUN for IDs
  286. * (1, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
  287. * driver to use its own algorithm for ID 1.
  288. *
  289. * The third line is the same as the first line.
  290. *
  291. * The fourth line disables tagged queueing for devices 0 and 3. It
  292. * enables tagged queueing for the other IDs, with 16 commands/LUN
  293. * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
  294. * IDs 2, 5-7, and 9-15.
  295. */
  296. /*
  297. * NOTE: The below structure is for reference only, the actual structure
  298. * to modify in order to change things is found after this fake one.
  299. *
  300. adapter_tag_info_t aic7xxx_tag_info[] =
  301. {
  302. {DEFAULT_TAG_COMMANDS},
  303. {{4, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 255, 4, 4, 4}},
  304. {DEFAULT_TAG_COMMANDS},
  305. {{255, 16, 4, 255, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
  306. };
  307. */
  308. static adapter_tag_info_t aic7xxx_tag_info[] =
  309. {
  310. {DEFAULT_TAG_COMMANDS},
  311. {DEFAULT_TAG_COMMANDS},
  312. {DEFAULT_TAG_COMMANDS},
  313. {DEFAULT_TAG_COMMANDS},
  314. {DEFAULT_TAG_COMMANDS},
  315. {DEFAULT_TAG_COMMANDS},
  316. {DEFAULT_TAG_COMMANDS},
  317. {DEFAULT_TAG_COMMANDS},
  318. {DEFAULT_TAG_COMMANDS},
  319. {DEFAULT_TAG_COMMANDS},
  320. {DEFAULT_TAG_COMMANDS},
  321. {DEFAULT_TAG_COMMANDS},
  322. {DEFAULT_TAG_COMMANDS},
  323. {DEFAULT_TAG_COMMANDS},
  324. {DEFAULT_TAG_COMMANDS},
  325. {DEFAULT_TAG_COMMANDS}
  326. };
  327. /*
  328. * Define an array of board names that can be indexed by aha_type.
  329. * Don't forget to change this when changing the types!
  330. */
  331. static const char *board_names[] = {
  332. "AIC-7xxx Unknown", /* AIC_NONE */
  333. "Adaptec AIC-7810 Hardware RAID Controller", /* AIC_7810 */
  334. "Adaptec AIC-7770 SCSI host adapter", /* AIC_7770 */
  335. "Adaptec AHA-274X SCSI host adapter", /* AIC_7771 */
  336. "Adaptec AHA-284X SCSI host adapter", /* AIC_284x */
  337. "Adaptec AIC-7850 SCSI host adapter", /* AIC_7850 */
  338. "Adaptec AIC-7855 SCSI host adapter", /* AIC_7855 */
  339. "Adaptec AIC-7860 Ultra SCSI host adapter", /* AIC_7860 */
  340. "Adaptec AHA-2940A Ultra SCSI host adapter", /* AIC_7861 */
  341. "Adaptec AIC-7870 SCSI host adapter", /* AIC_7870 */
  342. "Adaptec AHA-294X SCSI host adapter", /* AIC_7871 */
  343. "Adaptec AHA-394X SCSI host adapter", /* AIC_7872 */
  344. "Adaptec AHA-398X SCSI host adapter", /* AIC_7873 */
  345. "Adaptec AHA-2944 SCSI host adapter", /* AIC_7874 */
  346. "Adaptec AIC-7880 Ultra SCSI host adapter", /* AIC_7880 */
  347. "Adaptec AHA-294X Ultra SCSI host adapter", /* AIC_7881 */
  348. "Adaptec AHA-394X Ultra SCSI host adapter", /* AIC_7882 */
  349. "Adaptec AHA-398X Ultra SCSI host adapter", /* AIC_7883 */
  350. "Adaptec AHA-2944 Ultra SCSI host adapter", /* AIC_7884 */
  351. "Adaptec AHA-2940UW Pro Ultra SCSI host adapter", /* AIC_7887 */
  352. "Adaptec AIC-7895 Ultra SCSI host adapter", /* AIC_7895 */
  353. "Adaptec AIC-7890/1 Ultra2 SCSI host adapter", /* AIC_7890 */
  354. "Adaptec AHA-293X Ultra2 SCSI host adapter", /* AIC_7890 */
  355. "Adaptec AHA-294X Ultra2 SCSI host adapter", /* AIC_7890 */
  356. "Adaptec AIC-7896/7 Ultra2 SCSI host adapter", /* AIC_7896 */
  357. "Adaptec AHA-394X Ultra2 SCSI host adapter", /* AIC_7897 */
  358. "Adaptec AHA-395X Ultra2 SCSI host adapter", /* AIC_7897 */
  359. "Adaptec PCMCIA SCSI controller", /* card bus stuff */
  360. "Adaptec AIC-7892 Ultra 160/m SCSI host adapter", /* AIC_7892 */
  361. "Adaptec AIC-7899 Ultra 160/m SCSI host adapter", /* AIC_7899 */
  362. };
  363. /*
  364. * There should be a specific return value for this in scsi.h, but
  365. * it seems that most drivers ignore it.
  366. */
  367. #define DID_UNDERFLOW DID_ERROR
  368. /*
  369. * What we want to do is have the higher level scsi driver requeue
  370. * the command to us. There is no specific driver status for this
  371. * condition, but the higher level scsi driver will requeue the
  372. * command on a DID_BUS_BUSY error.
  373. *
  374. * Upon further inspection and testing, it seems that DID_BUS_BUSY
  375. * will *always* retry the command. We can get into an infinite loop
  376. * if this happens when we really want some sort of counter that
  377. * will automatically abort/reset the command after so many retries.
  378. * Using DID_ERROR will do just that. (Made by a suggestion by
  379. * Doug Ledford 8/1/96)
  380. */
  381. #define DID_RETRY_COMMAND DID_ERROR
  382. #define HSCSIID 0x07
  383. #define SCSI_RESET 0x040
  384. /*
  385. * EISA/VL-bus stuff
  386. */
  387. #define MINSLOT 1
  388. #define MAXSLOT 15
  389. #define SLOTBASE(x) ((x) << 12)
  390. #define BASE_TO_SLOT(x) ((x) >> 12)
  391. /*
  392. * Standard EISA Host ID regs (Offset from slot base)
  393. */
  394. #define AHC_HID0 0x80 /* 0,1: msb of ID2, 2-7: ID1 */
  395. #define AHC_HID1 0x81 /* 0-4: ID3, 5-7: LSB ID2 */
  396. #define AHC_HID2 0x82 /* product */
  397. #define AHC_HID3 0x83 /* firmware revision */
  398. /*
  399. * AIC-7770 I/O range to reserve for a card
  400. */
  401. #define MINREG 0xC00
  402. #define MAXREG 0xCFF
  403. #define INTDEF 0x5C /* Interrupt Definition Register */
  404. /*
  405. * AIC-78X0 PCI registers
  406. */
  407. #define CLASS_PROGIF_REVID 0x08
  408. #define DEVREVID 0x000000FFul
  409. #define PROGINFC 0x0000FF00ul
  410. #define SUBCLASS 0x00FF0000ul
  411. #define BASECLASS 0xFF000000ul
  412. #define CSIZE_LATTIME 0x0C
  413. #define CACHESIZE 0x0000003Ful /* only 5 bits */
  414. #define LATTIME 0x0000FF00ul
  415. #define DEVCONFIG 0x40
  416. #define SCBSIZE32 0x00010000ul /* aic789X only */
  417. #define MPORTMODE 0x00000400ul /* aic7870 only */
  418. #define RAMPSM 0x00000200ul /* aic7870 only */
  419. #define RAMPSM_ULTRA2 0x00000004
  420. #define VOLSENSE 0x00000100ul
  421. #define SCBRAMSEL 0x00000080ul
  422. #define SCBRAMSEL_ULTRA2 0x00000008
  423. #define MRDCEN 0x00000040ul
  424. #define EXTSCBTIME 0x00000020ul /* aic7870 only */
  425. #define EXTSCBPEN 0x00000010ul /* aic7870 only */
  426. #define BERREN 0x00000008ul
  427. #define DACEN 0x00000004ul
  428. #define STPWLEVEL 0x00000002ul
  429. #define DIFACTNEGEN 0x00000001ul /* aic7870 only */
  430. #define SCAMCTL 0x1a /* Ultra2 only */
  431. #define CCSCBBADDR 0xf0 /* aic7895/6/7 */
  432. /*
  433. * Define the different types of SEEPROMs on aic7xxx adapters
  434. * and make it also represent the address size used in accessing
  435. * its registers. The 93C46 chips have 1024 bits organized into
  436. * 64 16-bit words, while the 93C56 chips have 2048 bits organized
  437. * into 128 16-bit words. The C46 chips use 6 bits to address
  438. * each word, while the C56 and C66 (4096 bits) use 8 bits to
  439. * address each word.
  440. */
  441. typedef enum {C46 = 6, C56_66 = 8} seeprom_chip_type;
  442. /*
  443. *
  444. * Define the format of the SEEPROM registers (16 bits).
  445. *
  446. */
  447. struct seeprom_config {
  448. /*
  449. * SCSI ID Configuration Flags
  450. */
  451. #define CFXFER 0x0007 /* synchronous transfer rate */
  452. #define CFSYNCH 0x0008 /* enable synchronous transfer */
  453. #define CFDISC 0x0010 /* enable disconnection */
  454. #define CFWIDEB 0x0020 /* wide bus device (wide card) */
  455. #define CFSYNCHISULTRA 0x0040 /* CFSYNC is an ultra offset */
  456. #define CFNEWULTRAFORMAT 0x0080 /* Use the Ultra2 SEEPROM format */
  457. #define CFSTART 0x0100 /* send start unit SCSI command */
  458. #define CFINCBIOS 0x0200 /* include in BIOS scan */
  459. #define CFRNFOUND 0x0400 /* report even if not found */
  460. #define CFMULTILUN 0x0800 /* probe mult luns in BIOS scan */
  461. #define CFWBCACHEYES 0x4000 /* Enable W-Behind Cache on drive */
  462. #define CFWBCACHENC 0xc000 /* Don't change W-Behind Cache */
  463. /* UNUSED 0x3000 */
  464. unsigned short device_flags[16]; /* words 0-15 */
  465. /*
  466. * BIOS Control Bits
  467. */
  468. #define CFSUPREM 0x0001 /* support all removable drives */
  469. #define CFSUPREMB 0x0002 /* support removable drives for boot only */
  470. #define CFBIOSEN 0x0004 /* BIOS enabled */
  471. /* UNUSED 0x0008 */
  472. #define CFSM2DRV 0x0010 /* support more than two drives */
  473. #define CF284XEXTEND 0x0020 /* extended translation (284x cards) */
  474. /* UNUSED 0x0040 */
  475. #define CFEXTEND 0x0080 /* extended translation enabled */
  476. /* UNUSED 0xFF00 */
  477. unsigned short bios_control; /* word 16 */
  478. /*
  479. * Host Adapter Control Bits
  480. */
  481. #define CFAUTOTERM 0x0001 /* Perform Auto termination */
  482. #define CFULTRAEN 0x0002 /* Ultra SCSI speed enable (Ultra cards) */
  483. #define CF284XSELTO 0x0003 /* Selection timeout (284x cards) */
  484. #define CF284XFIFO 0x000C /* FIFO Threshold (284x cards) */
  485. #define CFSTERM 0x0004 /* SCSI low byte termination */
  486. #define CFWSTERM 0x0008 /* SCSI high byte termination (wide card) */
  487. #define CFSPARITY 0x0010 /* SCSI parity */
  488. #define CF284XSTERM 0x0020 /* SCSI low byte termination (284x cards) */
  489. #define CFRESETB 0x0040 /* reset SCSI bus at boot */
  490. #define CFBPRIMARY 0x0100 /* Channel B primary on 7895 chipsets */
  491. #define CFSEAUTOTERM 0x0400 /* aic7890 Perform SE Auto Term */
  492. #define CFLVDSTERM 0x0800 /* aic7890 LVD Termination */
  493. /* UNUSED 0xF280 */
  494. unsigned short adapter_control; /* word 17 */
  495. /*
  496. * Bus Release, Host Adapter ID
  497. */
  498. #define CFSCSIID 0x000F /* host adapter SCSI ID */
  499. /* UNUSED 0x00F0 */
  500. #define CFBRTIME 0xFF00 /* bus release time */
  501. unsigned short brtime_id; /* word 18 */
  502. /*
  503. * Maximum targets
  504. */
  505. #define CFMAXTARG 0x00FF /* maximum targets */
  506. /* UNUSED 0xFF00 */
  507. unsigned short max_targets; /* word 19 */
  508. unsigned short res_1[11]; /* words 20-30 */
  509. unsigned short checksum; /* word 31 */
  510. };
  511. #define SELBUS_MASK 0x0a
  512. #define SELNARROW 0x00
  513. #define SELBUSB 0x08
  514. #define SINGLE_BUS 0x00
  515. #define SCB_TARGET(scb) \
  516. (((scb)->hscb->target_channel_lun & TID) >> 4)
  517. #define SCB_LUN(scb) \
  518. ((scb)->hscb->target_channel_lun & LID)
  519. #define SCB_IS_SCSIBUS_B(scb) \
  520. (((scb)->hscb->target_channel_lun & SELBUSB) != 0)
  521. /*
  522. * If an error occurs during a data transfer phase, run the command
  523. * to completion - it's easier that way - making a note of the error
  524. * condition in this location. This then will modify a DID_OK status
  525. * into an appropriate error for the higher-level SCSI code.
  526. */
  527. #define aic7xxx_error(cmd) ((cmd)->SCp.Status)
  528. /*
  529. * Keep track of the targets returned status.
  530. */
  531. #define aic7xxx_status(cmd) ((cmd)->SCp.sent_command)
  532. /*
  533. * The position of the SCSI commands scb within the scb array.
  534. */
  535. #define aic7xxx_position(cmd) ((cmd)->SCp.have_data_in)
  536. /*
  537. * The stored DMA mapping for single-buffer data transfers.
  538. */
  539. #define aic7xxx_mapping(cmd) ((cmd)->SCp.phase)
  540. /*
  541. * Get out private data area from a scsi cmd pointer
  542. */
  543. #define AIC_DEV(cmd) ((struct aic_dev_data *)(cmd)->device->hostdata)
  544. /*
  545. * So we can keep track of our host structs
  546. */
  547. static struct aic7xxx_host *first_aic7xxx = NULL;
  548. /*
  549. * As of Linux 2.1, the mid-level SCSI code uses virtual addresses
  550. * in the scatter-gather lists. We need to convert the virtual
  551. * addresses to physical addresses.
  552. */
  553. struct hw_scatterlist {
  554. unsigned int address;
  555. unsigned int length;
  556. };
  557. /*
  558. * Maximum number of SG segments these cards can support.
  559. */
  560. #define AIC7XXX_MAX_SG 128
  561. /*
  562. * The maximum number of SCBs we could have for ANY type
  563. * of card. DON'T FORGET TO CHANGE THE SCB MASK IN THE
  564. * SEQUENCER CODE IF THIS IS MODIFIED!
  565. */
  566. #define AIC7XXX_MAXSCB 255
  567. struct aic7xxx_hwscb {
  568. /* ------------ Begin hardware supported fields ---------------- */
  569. /* 0*/ unsigned char control;
  570. /* 1*/ unsigned char target_channel_lun; /* 4/1/3 bits */
  571. /* 2*/ unsigned char target_status;
  572. /* 3*/ unsigned char SG_segment_count;
  573. /* 4*/ unsigned int SG_list_pointer;
  574. /* 8*/ unsigned char residual_SG_segment_count;
  575. /* 9*/ unsigned char residual_data_count[3];
  576. /*12*/ unsigned int data_pointer;
  577. /*16*/ unsigned int data_count;
  578. /*20*/ unsigned int SCSI_cmd_pointer;
  579. /*24*/ unsigned char SCSI_cmd_length;
  580. /*25*/ unsigned char tag; /* Index into our kernel SCB array.
  581. * Also used as the tag for tagged I/O
  582. */
  583. #define SCB_PIO_TRANSFER_SIZE 26 /* amount we need to upload/download
  584. * via PIO to initialize a transaction.
  585. */
  586. /*26*/ unsigned char next; /* Used to thread SCBs awaiting selection
  587. * or disconnected down in the sequencer.
  588. */
  589. /*27*/ unsigned char prev;
  590. /*28*/ unsigned int pad; /*
  591. * Unused by the kernel, but we require
  592. * the padding so that the array of
  593. * hardware SCBs is aligned on 32 byte
  594. * boundaries so the sequencer can index
  595. */
  596. };
  597. typedef enum {
  598. SCB_FREE = 0x0000,
  599. SCB_DTR_SCB = 0x0001,
  600. SCB_WAITINGQ = 0x0002,
  601. SCB_ACTIVE = 0x0004,
  602. SCB_SENSE = 0x0008,
  603. SCB_ABORT = 0x0010,
  604. SCB_DEVICE_RESET = 0x0020,
  605. SCB_RESET = 0x0040,
  606. SCB_RECOVERY_SCB = 0x0080,
  607. SCB_MSGOUT_PPR = 0x0100,
  608. SCB_MSGOUT_SENT = 0x0200,
  609. SCB_MSGOUT_SDTR = 0x0400,
  610. SCB_MSGOUT_WDTR = 0x0800,
  611. SCB_MSGOUT_BITS = SCB_MSGOUT_PPR |
  612. SCB_MSGOUT_SENT |
  613. SCB_MSGOUT_SDTR |
  614. SCB_MSGOUT_WDTR,
  615. SCB_QUEUED_ABORT = 0x1000,
  616. SCB_QUEUED_FOR_DONE = 0x2000,
  617. SCB_WAS_BUSY = 0x4000,
  618. SCB_QUEUE_FULL = 0x8000
  619. } scb_flag_type;
  620. typedef enum {
  621. AHC_FNONE = 0x00000000,
  622. AHC_PAGESCBS = 0x00000001,
  623. AHC_CHANNEL_B_PRIMARY = 0x00000002,
  624. AHC_USEDEFAULTS = 0x00000004,
  625. AHC_INDIRECT_PAGING = 0x00000008,
  626. AHC_CHNLB = 0x00000020,
  627. AHC_CHNLC = 0x00000040,
  628. AHC_EXTEND_TRANS_A = 0x00000100,
  629. AHC_EXTEND_TRANS_B = 0x00000200,
  630. AHC_TERM_ENB_A = 0x00000400,
  631. AHC_TERM_ENB_SE_LOW = 0x00000400,
  632. AHC_TERM_ENB_B = 0x00000800,
  633. AHC_TERM_ENB_SE_HIGH = 0x00000800,
  634. AHC_HANDLING_REQINITS = 0x00001000,
  635. AHC_TARGETMODE = 0x00002000,
  636. AHC_NEWEEPROM_FMT = 0x00004000,
  637. /*
  638. * Here ends the FreeBSD defined flags and here begins the linux defined
  639. * flags. NOTE: I did not preserve the old flag name during this change
  640. * specifically to force me to evaluate what flags were being used properly
  641. * and what flags weren't. This way, I could clean up the flag usage on
  642. * a use by use basis. Doug Ledford
  643. */
  644. AHC_MOTHERBOARD = 0x00020000,
  645. AHC_NO_STPWEN = 0x00040000,
  646. AHC_RESET_DELAY = 0x00080000,
  647. AHC_A_SCANNED = 0x00100000,
  648. AHC_B_SCANNED = 0x00200000,
  649. AHC_MULTI_CHANNEL = 0x00400000,
  650. AHC_BIOS_ENABLED = 0x00800000,
  651. AHC_SEEPROM_FOUND = 0x01000000,
  652. AHC_TERM_ENB_LVD = 0x02000000,
  653. AHC_ABORT_PENDING = 0x04000000,
  654. AHC_RESET_PENDING = 0x08000000,
  655. #define AHC_IN_ISR_BIT 28
  656. AHC_IN_ISR = 0x10000000,
  657. AHC_IN_ABORT = 0x20000000,
  658. AHC_IN_RESET = 0x40000000,
  659. AHC_EXTERNAL_SRAM = 0x80000000
  660. } ahc_flag_type;
  661. typedef enum {
  662. AHC_NONE = 0x0000,
  663. AHC_CHIPID_MASK = 0x00ff,
  664. AHC_AIC7770 = 0x0001,
  665. AHC_AIC7850 = 0x0002,
  666. AHC_AIC7860 = 0x0003,
  667. AHC_AIC7870 = 0x0004,
  668. AHC_AIC7880 = 0x0005,
  669. AHC_AIC7890 = 0x0006,
  670. AHC_AIC7895 = 0x0007,
  671. AHC_AIC7896 = 0x0008,
  672. AHC_AIC7892 = 0x0009,
  673. AHC_AIC7899 = 0x000a,
  674. AHC_VL = 0x0100,
  675. AHC_EISA = 0x0200,
  676. AHC_PCI = 0x0400,
  677. } ahc_chip;
  678. typedef enum {
  679. AHC_FENONE = 0x0000,
  680. AHC_ULTRA = 0x0001,
  681. AHC_ULTRA2 = 0x0002,
  682. AHC_WIDE = 0x0004,
  683. AHC_TWIN = 0x0008,
  684. AHC_MORE_SRAM = 0x0010,
  685. AHC_CMD_CHAN = 0x0020,
  686. AHC_QUEUE_REGS = 0x0040,
  687. AHC_SG_PRELOAD = 0x0080,
  688. AHC_SPIOCAP = 0x0100,
  689. AHC_ULTRA3 = 0x0200,
  690. AHC_NEW_AUTOTERM = 0x0400,
  691. AHC_AIC7770_FE = AHC_FENONE,
  692. AHC_AIC7850_FE = AHC_SPIOCAP,
  693. AHC_AIC7860_FE = AHC_ULTRA|AHC_SPIOCAP,
  694. AHC_AIC7870_FE = AHC_FENONE,
  695. AHC_AIC7880_FE = AHC_ULTRA,
  696. AHC_AIC7890_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA2|
  697. AHC_QUEUE_REGS|AHC_SG_PRELOAD|AHC_NEW_AUTOTERM,
  698. AHC_AIC7895_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA,
  699. AHC_AIC7896_FE = AHC_AIC7890_FE,
  700. AHC_AIC7892_FE = AHC_AIC7890_FE|AHC_ULTRA3,
  701. AHC_AIC7899_FE = AHC_AIC7890_FE|AHC_ULTRA3,
  702. } ahc_feature;
  703. #define SCB_DMA_ADDR(scb, addr) ((unsigned long)(addr) + (scb)->scb_dma->dma_offset)
  704. struct aic7xxx_scb_dma {
  705. unsigned long dma_offset; /* Correction you have to add
  706. * to virtual address to get
  707. * dma handle in this region */
  708. dma_addr_t dma_address; /* DMA handle of the start,
  709. * for unmap */
  710. unsigned int dma_len; /* DMA length */
  711. };
  712. typedef enum {
  713. AHC_BUG_NONE = 0x0000,
  714. AHC_BUG_TMODE_WIDEODD = 0x0001,
  715. AHC_BUG_AUTOFLUSH = 0x0002,
  716. AHC_BUG_CACHETHEN = 0x0004,
  717. AHC_BUG_CACHETHEN_DIS = 0x0008,
  718. AHC_BUG_PCI_2_1_RETRY = 0x0010,
  719. AHC_BUG_PCI_MWI = 0x0020,
  720. AHC_BUG_SCBCHAN_UPLOAD = 0x0040,
  721. } ahc_bugs;
  722. struct aic7xxx_scb {
  723. struct aic7xxx_hwscb *hscb; /* corresponding hardware scb */
  724. struct scsi_cmnd *cmd; /* scsi_cmnd for this scb */
  725. struct aic7xxx_scb *q_next; /* next scb in queue */
  726. volatile scb_flag_type flags; /* current state of scb */
  727. struct hw_scatterlist *sg_list; /* SG list in adapter format */
  728. unsigned char tag_action;
  729. unsigned char sg_count;
  730. unsigned char *sense_cmd; /*
  731. * Allocate 6 characters for
  732. * sense command.
  733. */
  734. unsigned char *cmnd;
  735. unsigned int sg_length; /*
  736. * We init this during
  737. * buildscb so we don't have
  738. * to calculate anything during
  739. * underflow/overflow/stat code
  740. */
  741. void *kmalloc_ptr;
  742. struct aic7xxx_scb_dma *scb_dma;
  743. };
  744. /*
  745. * Define a linked list of SCBs.
  746. */
  747. typedef struct {
  748. struct aic7xxx_scb *head;
  749. struct aic7xxx_scb *tail;
  750. } scb_queue_type;
  751. static struct {
  752. unsigned char errno;
  753. const char *errmesg;
  754. } hard_error[] = {
  755. { ILLHADDR, "Illegal Host Access" },
  756. { ILLSADDR, "Illegal Sequencer Address referenced" },
  757. { ILLOPCODE, "Illegal Opcode in sequencer program" },
  758. { SQPARERR, "Sequencer Ram Parity Error" },
  759. { DPARERR, "Data-Path Ram Parity Error" },
  760. { MPARERR, "Scratch Ram/SCB Array Ram Parity Error" },
  761. { PCIERRSTAT,"PCI Error detected" },
  762. { CIOPARERR, "CIOBUS Parity Error" }
  763. };
  764. static unsigned char
  765. generic_sense[] = { REQUEST_SENSE, 0, 0, 0, 255, 0 };
  766. typedef struct {
  767. scb_queue_type free_scbs; /*
  768. * SCBs assigned to free slot on
  769. * card (no paging required)
  770. */
  771. struct aic7xxx_scb *scb_array[AIC7XXX_MAXSCB];
  772. struct aic7xxx_hwscb *hscbs;
  773. unsigned char numscbs; /* current number of scbs */
  774. unsigned char maxhscbs; /* hardware scbs */
  775. unsigned char maxscbs; /* max scbs including pageable scbs */
  776. dma_addr_t hscbs_dma; /* DMA handle to hscbs */
  777. unsigned int hscbs_dma_len; /* length of the above DMA area */
  778. void *hscb_kmalloc_ptr;
  779. } scb_data_type;
  780. struct target_cmd {
  781. unsigned char mesg_bytes[4];
  782. unsigned char command[28];
  783. };
  784. #define AHC_TRANS_CUR 0x0001
  785. #define AHC_TRANS_ACTIVE 0x0002
  786. #define AHC_TRANS_GOAL 0x0004
  787. #define AHC_TRANS_USER 0x0008
  788. #define AHC_TRANS_QUITE 0x0010
  789. typedef struct {
  790. unsigned char width;
  791. unsigned char period;
  792. unsigned char offset;
  793. unsigned char options;
  794. } transinfo_type;
  795. struct aic_dev_data {
  796. volatile scb_queue_type delayed_scbs;
  797. volatile unsigned short temp_q_depth;
  798. unsigned short max_q_depth;
  799. volatile unsigned char active_cmds;
  800. /*
  801. * Statistics Kept:
  802. *
  803. * Total Xfers (count for each command that has a data xfer),
  804. * broken down by reads && writes.
  805. *
  806. * Further sorted into a few bins for keeping tabs on how many commands
  807. * we get of various sizes.
  808. *
  809. */
  810. long w_total; /* total writes */
  811. long r_total; /* total reads */
  812. long barrier_total; /* total num of REQ_BARRIER commands */
  813. long ordered_total; /* How many REQ_BARRIER commands we
  814. used ordered tags to satisfy */
  815. long w_bins[6]; /* binned write */
  816. long r_bins[6]; /* binned reads */
  817. transinfo_type cur;
  818. transinfo_type goal;
  819. #define BUS_DEVICE_RESET_PENDING 0x01
  820. #define DEVICE_RESET_DELAY 0x02
  821. #define DEVICE_PRINT_DTR 0x04
  822. #define DEVICE_WAS_BUSY 0x08
  823. #define DEVICE_DTR_SCANNED 0x10
  824. #define DEVICE_SCSI_3 0x20
  825. volatile unsigned char flags;
  826. unsigned needppr:1;
  827. unsigned needppr_copy:1;
  828. unsigned needsdtr:1;
  829. unsigned needsdtr_copy:1;
  830. unsigned needwdtr:1;
  831. unsigned needwdtr_copy:1;
  832. unsigned dtr_pending:1;
  833. struct scsi_device *SDptr;
  834. struct list_head list;
  835. };
  836. /*
  837. * Define a structure used for each host adapter. Note, in order to avoid
  838. * problems with architectures I can't test on (because I don't have one,
  839. * such as the Alpha based systems) which happen to give faults for
  840. * non-aligned memory accesses, care was taken to align this structure
  841. * in a way that gauranteed all accesses larger than 8 bits were aligned
  842. * on the appropriate boundary. It's also organized to try and be more
  843. * cache line efficient. Be careful when changing this lest you might hurt
  844. * overall performance and bring down the wrath of the masses.
  845. */
  846. struct aic7xxx_host {
  847. /*
  848. * This is the first 64 bytes in the host struct
  849. */
  850. /*
  851. * We are grouping things here....first, items that get either read or
  852. * written with nearly every interrupt
  853. */
  854. volatile long flags;
  855. ahc_feature features; /* chip features */
  856. unsigned long base; /* card base address */
  857. volatile unsigned char __iomem *maddr; /* memory mapped address */
  858. unsigned long isr_count; /* Interrupt count */
  859. unsigned long spurious_int;
  860. scb_data_type *scb_data;
  861. struct aic7xxx_cmd_queue {
  862. struct scsi_cmnd *head;
  863. struct scsi_cmnd *tail;
  864. } completeq;
  865. /*
  866. * Things read/written on nearly every entry into aic7xxx_queue()
  867. */
  868. volatile scb_queue_type waiting_scbs;
  869. unsigned char unpause; /* unpause value for HCNTRL */
  870. unsigned char pause; /* pause value for HCNTRL */
  871. volatile unsigned char qoutfifonext;
  872. volatile unsigned char activescbs; /* active scbs */
  873. volatile unsigned char max_activescbs;
  874. volatile unsigned char qinfifonext;
  875. volatile unsigned char *untagged_scbs;
  876. volatile unsigned char *qoutfifo;
  877. volatile unsigned char *qinfifo;
  878. unsigned char dev_last_queue_full[MAX_TARGETS];
  879. unsigned char dev_last_queue_full_count[MAX_TARGETS];
  880. unsigned short ultraenb; /* Gets downloaded to card as a bitmap */
  881. unsigned short discenable; /* Gets downloaded to card as a bitmap */
  882. transinfo_type user[MAX_TARGETS];
  883. unsigned char msg_buf[13]; /* The message for the target */
  884. unsigned char msg_type;
  885. #define MSG_TYPE_NONE 0x00
  886. #define MSG_TYPE_INITIATOR_MSGOUT 0x01
  887. #define MSG_TYPE_INITIATOR_MSGIN 0x02
  888. unsigned char msg_len; /* Length of message */
  889. unsigned char msg_index; /* Index into msg_buf array */
  890. /*
  891. * We put the less frequently used host structure items
  892. * after the more frequently used items to try and ease
  893. * the burden on the cache subsystem.
  894. * These entries are not *commonly* accessed, whereas
  895. * the preceding entries are accessed very often.
  896. */
  897. unsigned int irq; /* IRQ for this adapter */
  898. int instance; /* aic7xxx instance number */
  899. int scsi_id; /* host adapter SCSI ID */
  900. int scsi_id_b; /* channel B for twin adapters */
  901. unsigned int bios_address;
  902. int board_name_index;
  903. unsigned short bios_control; /* bios control - SEEPROM */
  904. unsigned short adapter_control; /* adapter control - SEEPROM */
  905. struct pci_dev *pdev;
  906. unsigned char pci_bus;
  907. unsigned char pci_device_fn;
  908. struct seeprom_config sc;
  909. unsigned short sc_type;
  910. unsigned short sc_size;
  911. struct aic7xxx_host *next; /* allow for multiple IRQs */
  912. struct Scsi_Host *host; /* pointer to scsi host */
  913. struct list_head aic_devs; /* all aic_dev structs on host */
  914. int host_no; /* SCSI host number */
  915. unsigned long mbase; /* I/O memory address */
  916. ahc_chip chip; /* chip type */
  917. ahc_bugs bugs;
  918. dma_addr_t fifo_dma; /* DMA handle for fifo arrays */
  919. };
  920. /*
  921. * Valid SCSIRATE values. (p. 3-17)
  922. * Provides a mapping of transfer periods in ns/4 to the proper value to
  923. * stick in the SCSIRATE reg to use that transfer rate.
  924. */
  925. #define AHC_SYNCRATE_ULTRA3 0
  926. #define AHC_SYNCRATE_ULTRA2 1
  927. #define AHC_SYNCRATE_ULTRA 3
  928. #define AHC_SYNCRATE_FAST 6
  929. #define AHC_SYNCRATE_CRC 0x40
  930. #define AHC_SYNCRATE_SE 0x10
  931. static struct aic7xxx_syncrate {
  932. /* Rates in Ultra mode have bit 8 of sxfr set */
  933. #define ULTRA_SXFR 0x100
  934. int sxfr_ultra2;
  935. int sxfr;
  936. unsigned char period;
  937. const char *rate[2];
  938. } aic7xxx_syncrates[] = {
  939. { 0x42, 0x000, 9, {"80.0", "160.0"} },
  940. { 0x13, 0x000, 10, {"40.0", "80.0"} },
  941. { 0x14, 0x000, 11, {"33.0", "66.6"} },
  942. { 0x15, 0x100, 12, {"20.0", "40.0"} },
  943. { 0x16, 0x110, 15, {"16.0", "32.0"} },
  944. { 0x17, 0x120, 18, {"13.4", "26.8"} },
  945. { 0x18, 0x000, 25, {"10.0", "20.0"} },
  946. { 0x19, 0x010, 31, {"8.0", "16.0"} },
  947. { 0x1a, 0x020, 37, {"6.67", "13.3"} },
  948. { 0x1b, 0x030, 43, {"5.7", "11.4"} },
  949. { 0x10, 0x040, 50, {"5.0", "10.0"} },
  950. { 0x00, 0x050, 56, {"4.4", "8.8" } },
  951. { 0x00, 0x060, 62, {"4.0", "8.0" } },
  952. { 0x00, 0x070, 68, {"3.6", "7.2" } },
  953. { 0x00, 0x000, 0, {NULL, NULL} },
  954. };
  955. #define CTL_OF_SCB(scb) (((scb->hscb)->target_channel_lun >> 3) & 0x1), \
  956. (((scb->hscb)->target_channel_lun >> 4) & 0xf), \
  957. ((scb->hscb)->target_channel_lun & 0x07)
  958. #define CTL_OF_CMD(cmd) ((cmd->device->channel) & 0x01), \
  959. ((cmd->device->id) & 0x0f), \
  960. ((cmd->device->lun) & 0x07)
  961. #define TARGET_INDEX(cmd) ((cmd)->device->id | ((cmd)->device->channel << 3))
  962. /*
  963. * A nice little define to make doing our printks a little easier
  964. */
  965. #define WARN_LEAD KERN_WARNING "(scsi%d:%d:%d:%d) "
  966. #define INFO_LEAD KERN_INFO "(scsi%d:%d:%d:%d) "
  967. /*
  968. * XXX - these options apply unilaterally to _all_ 274x/284x/294x
  969. * cards in the system. This should be fixed. Exceptions to this
  970. * rule are noted in the comments.
  971. */
  972. /*
  973. * Use this as the default queue depth when setting tagged queueing on.
  974. */
  975. static unsigned int aic7xxx_default_queue_depth = AIC7XXX_CMDS_PER_DEVICE;
  976. /*
  977. * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
  978. * has no effect on any later resets that might occur due to things like
  979. * SCSI bus timeouts.
  980. */
  981. static unsigned int aic7xxx_no_reset = 0;
  982. /*
  983. * Certain PCI motherboards will scan PCI devices from highest to lowest,
  984. * others scan from lowest to highest, and they tend to do all kinds of
  985. * strange things when they come into contact with PCI bridge chips. The
  986. * net result of all this is that the PCI card that is actually used to boot
  987. * the machine is very hard to detect. Most motherboards go from lowest
  988. * PCI slot number to highest, and the first SCSI controller found is the
  989. * one you boot from. The only exceptions to this are when a controller
  990. * has its BIOS disabled. So, we by default sort all of our SCSI controllers
  991. * from lowest PCI slot number to highest PCI slot number. We also force
  992. * all controllers with their BIOS disabled to the end of the list. This
  993. * works on *almost* all computers. Where it doesn't work, we have this
  994. * option. Setting this option to non-0 will reverse the order of the sort
  995. * to highest first, then lowest, but will still leave cards with their BIOS
  996. * disabled at the very end. That should fix everyone up unless there are
  997. * really strange cirumstances.
  998. */
  999. static int aic7xxx_reverse_scan = 0;
  1000. /*
  1001. * Should we force EXTENDED translation on a controller.
  1002. * 0 == Use whatever is in the SEEPROM or default to off
  1003. * 1 == Use whatever is in the SEEPROM or default to on
  1004. */
  1005. static unsigned int aic7xxx_extended = 0;
  1006. /*
  1007. * The IRQ trigger method used on EISA controllers. Does not effect PCI cards.
  1008. * -1 = Use detected settings.
  1009. * 0 = Force Edge triggered mode.
  1010. * 1 = Force Level triggered mode.
  1011. */
  1012. static int aic7xxx_irq_trigger = -1;
  1013. /*
  1014. * This variable is used to override the termination settings on a controller.
  1015. * This should not be used under normal conditions. However, in the case
  1016. * that a controller does not have a readable SEEPROM (so that we can't
  1017. * read the SEEPROM settings directly) and that a controller has a buggered
  1018. * version of the cable detection logic, this can be used to force the
  1019. * correct termination. It is preferable to use the manual termination
  1020. * settings in the BIOS if possible, but some motherboard controllers store
  1021. * those settings in a format we can't read. In other cases, auto term
  1022. * should also work, but the chipset was put together with no auto term
  1023. * logic (common on motherboard controllers). In those cases, we have
  1024. * 32 bits here to work with. That's good for 8 controllers/channels. The
  1025. * bits are organized as 4 bits per channel, with scsi0 getting the lowest
  1026. * 4 bits in the int. A 1 in a bit position indicates the termination setting
  1027. * that corresponds to that bit should be enabled, a 0 is disabled.
  1028. * It looks something like this:
  1029. *
  1030. * 0x0f = 1111-Single Ended Low Byte Termination on/off
  1031. * ||\-Single Ended High Byte Termination on/off
  1032. * |\-LVD Low Byte Termination on/off
  1033. * \-LVD High Byte Termination on/off
  1034. *
  1035. * For non-Ultra2 controllers, the upper 2 bits are not important. So, to
  1036. * enable both high byte and low byte termination on scsi0, I would need to
  1037. * make sure that the override_term variable was set to 0x03 (bits 0011).
  1038. * To make sure that all termination is enabled on an Ultra2 controller at
  1039. * scsi2 and only high byte termination on scsi1 and high and low byte
  1040. * termination on scsi0, I would set override_term=0xf23 (bits 1111 0010 0011)
  1041. *
  1042. * For the most part, users should never have to use this, that's why I
  1043. * left it fairly cryptic instead of easy to understand. If you need it,
  1044. * most likely someone will be telling you what your's needs to be set to.
  1045. */
  1046. static int aic7xxx_override_term = -1;
  1047. /*
  1048. * Certain motherboard chipset controllers tend to screw
  1049. * up the polarity of the term enable output pin. Use this variable
  1050. * to force the correct polarity for your system. This is a bitfield variable
  1051. * similar to the previous one, but this one has one bit per channel instead
  1052. * of four.
  1053. * 0 = Force the setting to active low.
  1054. * 1 = Force setting to active high.
  1055. * Most Adaptec cards are active high, several motherboards are active low.
  1056. * To force a 2940 card at SCSI 0 to active high and a motherboard 7895
  1057. * controller at scsi1 and scsi2 to active low, and a 2910 card at scsi3
  1058. * to active high, you would need to set stpwlev=0x9 (bits 1001).
  1059. *
  1060. * People shouldn't need to use this, but if you are experiencing lots of
  1061. * SCSI timeout problems, this may help. There is one sure way to test what
  1062. * this option needs to be. Using a boot floppy to boot the system, configure
  1063. * your system to enable all SCSI termination (in the Adaptec SCSI BIOS) and
  1064. * if needed then also pass a value to override_term to make sure that the
  1065. * driver is enabling SCSI termination, then set this variable to either 0
  1066. * or 1. When the driver boots, make sure there are *NO* SCSI cables
  1067. * connected to your controller. If it finds and inits the controller
  1068. * without problem, then the setting you passed to stpwlev was correct. If
  1069. * the driver goes into a reset loop and hangs the system, then you need the
  1070. * other setting for this variable. If neither setting lets the machine
  1071. * boot then you have definite termination problems that may not be fixable.
  1072. */
  1073. static int aic7xxx_stpwlev = -1;
  1074. /*
  1075. * Set this to non-0 in order to force the driver to panic the kernel
  1076. * and print out debugging info on a SCSI abort or reset cycle.
  1077. */
  1078. static int aic7xxx_panic_on_abort = 0;
  1079. /*
  1080. * PCI bus parity checking of the Adaptec controllers. This is somewhat
  1081. * dubious at best. To my knowledge, this option has never actually
  1082. * solved a PCI parity problem, but on certain machines with broken PCI
  1083. * chipset configurations, it can generate tons of false error messages.
  1084. * It's included in the driver for completeness.
  1085. * 0 = Shut off PCI parity check
  1086. * -1 = Normal polarity pci parity checking
  1087. * 1 = reverse polarity pci parity checking
  1088. *
  1089. * NOTE: you can't actually pass -1 on the lilo prompt. So, to set this
  1090. * variable to -1 you would actually want to simply pass the variable
  1091. * name without a number. That will invert the 0 which will result in
  1092. * -1.
  1093. */
  1094. static int aic7xxx_pci_parity = 0;
  1095. /*
  1096. * Set this to any non-0 value to cause us to dump the contents of all
  1097. * the card's registers in a hex dump format tailored to each model of
  1098. * controller.
  1099. *
  1100. * NOTE: THE CONTROLLER IS LEFT IN AN UNUSEABLE STATE BY THIS OPTION.
  1101. * YOU CANNOT BOOT UP WITH THIS OPTION, IT IS FOR DEBUGGING PURPOSES
  1102. * ONLY
  1103. */
  1104. static int aic7xxx_dump_card = 0;
  1105. /*
  1106. * Set this to a non-0 value to make us dump out the 32 bit instruction
  1107. * registers on the card after completing the sequencer download. This
  1108. * allows the actual sequencer download to be verified. It is possible
  1109. * to use this option and still boot up and run your system. This is
  1110. * only intended for debugging purposes.
  1111. */
  1112. static int aic7xxx_dump_sequencer = 0;
  1113. /*
  1114. * Certain newer motherboards have put new PCI based devices into the
  1115. * IO spaces that used to typically be occupied by VLB or EISA cards.
  1116. * This overlap can cause these newer motherboards to lock up when scanned
  1117. * for older EISA and VLB devices. Setting this option to non-0 will
  1118. * cause the driver to skip scanning for any VLB or EISA controllers and
  1119. * only support the PCI controllers. NOTE: this means that if the kernel
  1120. * os compiled with PCI support disabled, then setting this to non-0
  1121. * would result in never finding any devices :)
  1122. */
  1123. static int aic7xxx_no_probe = 0;
  1124. /*
  1125. * On some machines, enabling the external SCB RAM isn't reliable yet. I
  1126. * haven't had time to make test patches for things like changing the
  1127. * timing mode on that external RAM either. Some of those changes may
  1128. * fix the problem. Until then though, we default to external SCB RAM
  1129. * off and give a command line option to enable it.
  1130. */
  1131. static int aic7xxx_scbram = 0;
  1132. /*
  1133. * So that we can set how long each device is given as a selection timeout.
  1134. * The table of values goes like this:
  1135. * 0 - 256ms
  1136. * 1 - 128ms
  1137. * 2 - 64ms
  1138. * 3 - 32ms
  1139. * We default to 64ms because it's fast. Some old SCSI-I devices need a
  1140. * longer time. The final value has to be left shifted by 3, hence 0x10
  1141. * is the final value.
  1142. */
  1143. static int aic7xxx_seltime = 0x10;
  1144. /*
  1145. * So that insmod can find the variable and make it point to something
  1146. */
  1147. #ifdef MODULE
  1148. static char * aic7xxx = NULL;
  1149. module_param(aic7xxx, charp, 0);
  1150. #endif
  1151. #define VERBOSE_NORMAL 0x0000
  1152. #define VERBOSE_NEGOTIATION 0x0001
  1153. #define VERBOSE_SEQINT 0x0002
  1154. #define VERBOSE_SCSIINT 0x0004
  1155. #define VERBOSE_PROBE 0x0008
  1156. #define VERBOSE_PROBE2 0x0010
  1157. #define VERBOSE_NEGOTIATION2 0x0020
  1158. #define VERBOSE_MINOR_ERROR 0x0040
  1159. #define VERBOSE_TRACING 0x0080
  1160. #define VERBOSE_ABORT 0x0f00
  1161. #define VERBOSE_ABORT_MID 0x0100
  1162. #define VERBOSE_ABORT_FIND 0x0200
  1163. #define VERBOSE_ABORT_PROCESS 0x0400
  1164. #define VERBOSE_ABORT_RETURN 0x0800
  1165. #define VERBOSE_RESET 0xf000
  1166. #define VERBOSE_RESET_MID 0x1000
  1167. #define VERBOSE_RESET_FIND 0x2000
  1168. #define VERBOSE_RESET_PROCESS 0x4000
  1169. #define VERBOSE_RESET_RETURN 0x8000
  1170. static int aic7xxx_verbose = VERBOSE_NORMAL | VERBOSE_NEGOTIATION |
  1171. VERBOSE_PROBE; /* verbose messages */
  1172. /****************************************************************************
  1173. *
  1174. * We're going to start putting in function declarations so that order of
  1175. * functions is no longer important. As needed, they are added here.
  1176. *
  1177. ***************************************************************************/
  1178. static int aic7xxx_release(struct Scsi_Host *host);
  1179. static void aic7xxx_set_syncrate(struct aic7xxx_host *p,
  1180. struct aic7xxx_syncrate *syncrate, int target, int channel,
  1181. unsigned int period, unsigned int offset, unsigned char options,
  1182. unsigned int type, struct aic_dev_data *aic_dev);
  1183. static void aic7xxx_set_width(struct aic7xxx_host *p, int target, int channel,
  1184. int lun, unsigned int width, unsigned int type,
  1185. struct aic_dev_data *aic_dev);
  1186. static void aic7xxx_panic_abort(struct aic7xxx_host *p, struct scsi_cmnd *cmd);
  1187. static void aic7xxx_print_card(struct aic7xxx_host *p);
  1188. static void aic7xxx_print_scratch_ram(struct aic7xxx_host *p);
  1189. static void aic7xxx_print_sequencer(struct aic7xxx_host *p, int downloaded);
  1190. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  1191. static void aic7xxx_check_scbs(struct aic7xxx_host *p, char *buffer);
  1192. #endif
  1193. /****************************************************************************
  1194. *
  1195. * These functions are now used. They happen to be wrapped in useless
  1196. * inb/outb port read/writes around the real reads and writes because it
  1197. * seems that certain very fast CPUs have a problem dealing with us when
  1198. * going at full speed.
  1199. *
  1200. ***************************************************************************/
  1201. static unsigned char
  1202. aic_inb(struct aic7xxx_host *p, long port)
  1203. {
  1204. #ifdef MMAPIO
  1205. unsigned char x;
  1206. if(p->maddr)
  1207. {
  1208. x = readb(p->maddr + port);
  1209. }
  1210. else
  1211. {
  1212. x = inb(p->base + port);
  1213. }
  1214. return(x);
  1215. #else
  1216. return(inb(p->base + port));
  1217. #endif
  1218. }
  1219. static void
  1220. aic_outb(struct aic7xxx_host *p, unsigned char val, long port)
  1221. {
  1222. #ifdef MMAPIO
  1223. if(p->maddr)
  1224. {
  1225. writeb(val, p->maddr + port);
  1226. mb(); /* locked operation in order to force CPU ordering */
  1227. readb(p->maddr + HCNTRL); /* dummy read to flush the PCI write */
  1228. }
  1229. else
  1230. {
  1231. outb(val, p->base + port);
  1232. mb(); /* locked operation in order to force CPU ordering */
  1233. }
  1234. #else
  1235. outb(val, p->base + port);
  1236. mb(); /* locked operation in order to force CPU ordering */
  1237. #endif
  1238. }
  1239. /*+F*************************************************************************
  1240. * Function:
  1241. * aic7xxx_setup
  1242. *
  1243. * Description:
  1244. * Handle Linux boot parameters. This routine allows for assigning a value
  1245. * to a parameter with a ':' between the parameter and the value.
  1246. * ie. aic7xxx=unpause:0x0A,extended
  1247. *-F*************************************************************************/
  1248. static int
  1249. aic7xxx_setup(char *s)
  1250. {
  1251. int i, n;
  1252. char *p;
  1253. char *end;
  1254. static struct {
  1255. const char *name;
  1256. unsigned int *flag;
  1257. } options[] = {
  1258. { "extended", &aic7xxx_extended },
  1259. { "no_reset", &aic7xxx_no_reset },
  1260. { "irq_trigger", &aic7xxx_irq_trigger },
  1261. { "verbose", &aic7xxx_verbose },
  1262. { "reverse_scan",&aic7xxx_reverse_scan },
  1263. { "override_term", &aic7xxx_override_term },
  1264. { "stpwlev", &aic7xxx_stpwlev },
  1265. { "no_probe", &aic7xxx_no_probe },
  1266. { "panic_on_abort", &aic7xxx_panic_on_abort },
  1267. { "pci_parity", &aic7xxx_pci_parity },
  1268. { "dump_card", &aic7xxx_dump_card },
  1269. { "dump_sequencer", &aic7xxx_dump_sequencer },
  1270. { "default_queue_depth", &aic7xxx_default_queue_depth },
  1271. { "scbram", &aic7xxx_scbram },
  1272. { "seltime", &aic7xxx_seltime },
  1273. { "tag_info", NULL }
  1274. };
  1275. end = strchr(s, '\0');
  1276. while ((p = strsep(&s, ",.")) != NULL)
  1277. {
  1278. for (i = 0; i < ARRAY_SIZE(options); i++)
  1279. {
  1280. n = strlen(options[i].name);
  1281. if (!strncmp(options[i].name, p, n))
  1282. {
  1283. if (!strncmp(p, "tag_info", n))
  1284. {
  1285. if (p[n] == ':')
  1286. {
  1287. char *base;
  1288. char *tok, *tok_end, *tok_end2;
  1289. char tok_list[] = { '.', ',', '{', '}', '\0' };
  1290. int i, instance = -1, device = -1;
  1291. unsigned char done = FALSE;
  1292. base = p;
  1293. tok = base + n + 1; /* Forward us just past the ':' */
  1294. tok_end = strchr(tok, '\0');
  1295. if (tok_end < end)
  1296. *tok_end = ',';
  1297. while(!done)
  1298. {
  1299. switch(*tok)
  1300. {
  1301. case '{':
  1302. if (instance == -1)
  1303. instance = 0;
  1304. else if (device == -1)
  1305. device = 0;
  1306. tok++;
  1307. break;
  1308. case '}':
  1309. if (device != -1)
  1310. device = -1;
  1311. else if (instance != -1)
  1312. instance = -1;
  1313. tok++;
  1314. break;
  1315. case ',':
  1316. case '.':
  1317. if (instance == -1)
  1318. done = TRUE;
  1319. else if (device >= 0)
  1320. device++;
  1321. else if (instance >= 0)
  1322. instance++;
  1323. if ( (device >= MAX_TARGETS) ||
  1324. (instance >= ARRAY_SIZE(aic7xxx_tag_info)) )
  1325. done = TRUE;
  1326. tok++;
  1327. if (!done)
  1328. {
  1329. base = tok;
  1330. }
  1331. break;
  1332. case '\0':
  1333. done = TRUE;
  1334. break;
  1335. default:
  1336. done = TRUE;
  1337. tok_end = strchr(tok, '\0');
  1338. for(i=0; tok_list[i]; i++)
  1339. {
  1340. tok_end2 = strchr(tok, tok_list[i]);
  1341. if ( (tok_end2) && (tok_end2 < tok_end) )
  1342. {
  1343. tok_end = tok_end2;
  1344. done = FALSE;
  1345. }
  1346. }
  1347. if ( (instance >= 0) && (device >= 0) &&
  1348. (instance < ARRAY_SIZE(aic7xxx_tag_info)) &&
  1349. (device < MAX_TARGETS) )
  1350. aic7xxx_tag_info[instance].tag_commands[device] =
  1351. simple_strtoul(tok, NULL, 0) & 0xff;
  1352. tok = tok_end;
  1353. break;
  1354. }
  1355. }
  1356. while((p != base) && (p != NULL))
  1357. p = strsep(&s, ",.");
  1358. }
  1359. }
  1360. else if (p[n] == ':')
  1361. {
  1362. *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
  1363. if(!strncmp(p, "seltime", n))
  1364. {
  1365. *(options[i].flag) = (*(options[i].flag) % 4) << 3;
  1366. }
  1367. }
  1368. else if (!strncmp(p, "verbose", n))
  1369. {
  1370. *(options[i].flag) = 0xff29;
  1371. }
  1372. else
  1373. {
  1374. *(options[i].flag) = ~(*(options[i].flag));
  1375. if(!strncmp(p, "seltime", n))
  1376. {
  1377. *(options[i].flag) = (*(options[i].flag) % 4) << 3;
  1378. }
  1379. }
  1380. }
  1381. }
  1382. }
  1383. return 1;
  1384. }
  1385. __setup("aic7xxx=", aic7xxx_setup);
  1386. /*+F*************************************************************************
  1387. * Function:
  1388. * pause_sequencer
  1389. *
  1390. * Description:
  1391. * Pause the sequencer and wait for it to actually stop - this
  1392. * is important since the sequencer can disable pausing for critical
  1393. * sections.
  1394. *-F*************************************************************************/
  1395. static void
  1396. pause_sequencer(struct aic7xxx_host *p)
  1397. {
  1398. aic_outb(p, p->pause, HCNTRL);
  1399. while ((aic_inb(p, HCNTRL) & PAUSE) == 0)
  1400. {
  1401. ;
  1402. }
  1403. if(p->features & AHC_ULTRA2)
  1404. {
  1405. aic_inb(p, CCSCBCTL);
  1406. }
  1407. }
  1408. /*+F*************************************************************************
  1409. * Function:
  1410. * unpause_sequencer
  1411. *
  1412. * Description:
  1413. * Unpause the sequencer. Unremarkable, yet done often enough to
  1414. * warrant an easy way to do it.
  1415. *-F*************************************************************************/
  1416. static void
  1417. unpause_sequencer(struct aic7xxx_host *p, int unpause_always)
  1418. {
  1419. if (unpause_always ||
  1420. ( !(aic_inb(p, INTSTAT) & (SCSIINT | SEQINT | BRKADRINT)) &&
  1421. !(p->flags & AHC_HANDLING_REQINITS) ) )
  1422. {
  1423. aic_outb(p, p->unpause, HCNTRL);
  1424. }
  1425. }
  1426. /*+F*************************************************************************
  1427. * Function:
  1428. * restart_sequencer
  1429. *
  1430. * Description:
  1431. * Restart the sequencer program from address zero. This assumes
  1432. * that the sequencer is already paused.
  1433. *-F*************************************************************************/
  1434. static void
  1435. restart_sequencer(struct aic7xxx_host *p)
  1436. {
  1437. aic_outb(p, 0, SEQADDR0);
  1438. aic_outb(p, 0, SEQADDR1);
  1439. aic_outb(p, FASTMODE, SEQCTL);
  1440. }
  1441. /*
  1442. * We include the aic7xxx_seq.c file here so that the other defines have
  1443. * already been made, and so that it comes before the code that actually
  1444. * downloads the instructions (since we don't typically use function
  1445. * prototype, our code has to be ordered that way, it's a left-over from
  1446. * the original driver days.....I should fix it some time DL).
  1447. */
  1448. #include "aic7xxx_old/aic7xxx_seq.c"
  1449. /*+F*************************************************************************
  1450. * Function:
  1451. * aic7xxx_check_patch
  1452. *
  1453. * Description:
  1454. * See if the next patch to download should be downloaded.
  1455. *-F*************************************************************************/
  1456. static int
  1457. aic7xxx_check_patch(struct aic7xxx_host *p,
  1458. struct sequencer_patch **start_patch, int start_instr, int *skip_addr)
  1459. {
  1460. struct sequencer_patch *cur_patch;
  1461. struct sequencer_patch *last_patch;
  1462. int num_patches;
  1463. num_patches = ARRAY_SIZE(sequencer_patches);
  1464. last_patch = &sequencer_patches[num_patches];
  1465. cur_patch = *start_patch;
  1466. while ((cur_patch < last_patch) && (start_instr == cur_patch->begin))
  1467. {
  1468. if (cur_patch->patch_func(p) == 0)
  1469. {
  1470. /*
  1471. * Start rejecting code.
  1472. */
  1473. *skip_addr = start_instr + cur_patch->skip_instr;
  1474. cur_patch += cur_patch->skip_patch;
  1475. }
  1476. else
  1477. {
  1478. /*
  1479. * Found an OK patch. Advance the patch pointer to the next patch
  1480. * and wait for our instruction pointer to get here.
  1481. */
  1482. cur_patch++;
  1483. }
  1484. }
  1485. *start_patch = cur_patch;
  1486. if (start_instr < *skip_addr)
  1487. /*
  1488. * Still skipping
  1489. */
  1490. return (0);
  1491. return(1);
  1492. }
  1493. /*+F*************************************************************************
  1494. * Function:
  1495. * aic7xxx_download_instr
  1496. *
  1497. * Description:
  1498. * Find the next patch to download.
  1499. *-F*************************************************************************/
  1500. static void
  1501. aic7xxx_download_instr(struct aic7xxx_host *p, int instrptr,
  1502. unsigned char *dconsts)
  1503. {
  1504. union ins_formats instr;
  1505. struct ins_format1 *fmt1_ins;
  1506. struct ins_format3 *fmt3_ins;
  1507. unsigned char opcode;
  1508. instr = *(union ins_formats*) &seqprog[instrptr * 4];
  1509. instr.integer = le32_to_cpu(instr.integer);
  1510. fmt1_ins = &instr.format1;
  1511. fmt3_ins = NULL;
  1512. /* Pull the opcode */
  1513. opcode = instr.format1.opcode;
  1514. switch (opcode)
  1515. {
  1516. case AIC_OP_JMP:
  1517. case AIC_OP_JC:
  1518. case AIC_OP_JNC:
  1519. case AIC_OP_CALL:
  1520. case AIC_OP_JNE:
  1521. case AIC_OP_JNZ:
  1522. case AIC_OP_JE:
  1523. case AIC_OP_JZ:
  1524. {
  1525. struct sequencer_patch *cur_patch;
  1526. int address_offset;
  1527. unsigned int address;
  1528. int skip_addr;
  1529. int i;
  1530. fmt3_ins = &instr.format3;
  1531. address_offset = 0;
  1532. address = fmt3_ins->address;
  1533. cur_patch = sequencer_patches;
  1534. skip_addr = 0;
  1535. for (i = 0; i < address;)
  1536. {
  1537. aic7xxx_check_patch(p, &cur_patch, i, &skip_addr);
  1538. if (skip_addr > i)
  1539. {
  1540. int end_addr;
  1541. end_addr = min_t(int, address, skip_addr);
  1542. address_offset += end_addr - i;
  1543. i = skip_addr;
  1544. }
  1545. else
  1546. {
  1547. i++;
  1548. }
  1549. }
  1550. address -= address_offset;
  1551. fmt3_ins->address = address;
  1552. /* Fall Through to the next code section */
  1553. }
  1554. case AIC_OP_OR:
  1555. case AIC_OP_AND:
  1556. case AIC_OP_XOR:
  1557. case AIC_OP_ADD:
  1558. case AIC_OP_ADC:
  1559. case AIC_OP_BMOV:
  1560. if (fmt1_ins->parity != 0)
  1561. {
  1562. fmt1_ins->immediate = dconsts[fmt1_ins->immediate];
  1563. }
  1564. fmt1_ins->parity = 0;
  1565. /* Fall Through to the next code section */
  1566. case AIC_OP_ROL:
  1567. if ((p->features & AHC_ULTRA2) != 0)
  1568. {
  1569. int i, count;
  1570. /* Calculate odd parity for the instruction */
  1571. for ( i=0, count=0; i < 31; i++)
  1572. {
  1573. unsigned int mask;
  1574. mask = 0x01 << i;
  1575. if ((instr.integer & mask) != 0)
  1576. count++;
  1577. }
  1578. if (!(count & 0x01))
  1579. instr.format1.parity = 1;
  1580. }
  1581. else
  1582. {
  1583. if (fmt3_ins != NULL)
  1584. {
  1585. instr.integer = fmt3_ins->immediate |
  1586. (fmt3_ins->source << 8) |
  1587. (fmt3_ins->address << 16) |
  1588. (fmt3_ins->opcode << 25);
  1589. }
  1590. else
  1591. {
  1592. instr.integer = fmt1_ins->immediate |
  1593. (fmt1_ins->source << 8) |
  1594. (fmt1_ins->destination << 16) |
  1595. (fmt1_ins->ret << 24) |
  1596. (fmt1_ins->opcode << 25);
  1597. }
  1598. }
  1599. aic_outb(p, (instr.integer & 0xff), SEQRAM);
  1600. aic_outb(p, ((instr.integer >> 8) & 0xff), SEQRAM);
  1601. aic_outb(p, ((instr.integer >> 16) & 0xff), SEQRAM);
  1602. aic_outb(p, ((instr.integer >> 24) & 0xff), SEQRAM);
  1603. udelay(10);
  1604. break;
  1605. default:
  1606. panic("aic7xxx: Unknown opcode encountered in sequencer program.");
  1607. break;
  1608. }
  1609. }
  1610. /*+F*************************************************************************
  1611. * Function:
  1612. * aic7xxx_loadseq
  1613. *
  1614. * Description:
  1615. * Load the sequencer code into the controller memory.
  1616. *-F*************************************************************************/
  1617. static void
  1618. aic7xxx_loadseq(struct aic7xxx_host *p)
  1619. {
  1620. struct sequencer_patch *cur_patch;
  1621. int i;
  1622. int downloaded;
  1623. int skip_addr;
  1624. unsigned char download_consts[4] = {0, 0, 0, 0};
  1625. if (aic7xxx_verbose & VERBOSE_PROBE)
  1626. {
  1627. printk(KERN_INFO "(scsi%d) Downloading sequencer code...", p->host_no);
  1628. }
  1629. #if 0
  1630. download_consts[TMODE_NUMCMDS] = p->num_targetcmds;
  1631. #endif
  1632. download_consts[TMODE_NUMCMDS] = 0;
  1633. cur_patch = &sequencer_patches[0];
  1634. downloaded = 0;
  1635. skip_addr = 0;
  1636. aic_outb(p, PERRORDIS|LOADRAM|FAILDIS|FASTMODE, SEQCTL);
  1637. aic_outb(p, 0, SEQADDR0);
  1638. aic_outb(p, 0, SEQADDR1);
  1639. for (i = 0; i < sizeof(seqprog) / 4; i++)
  1640. {
  1641. if (aic7xxx_check_patch(p, &cur_patch, i, &skip_addr) == 0)
  1642. {
  1643. /* Skip this instruction for this configuration. */
  1644. continue;
  1645. }
  1646. aic7xxx_download_instr(p, i, &download_consts[0]);
  1647. downloaded++;
  1648. }
  1649. aic_outb(p, 0, SEQADDR0);
  1650. aic_outb(p, 0, SEQADDR1);
  1651. aic_outb(p, FASTMODE | FAILDIS, SEQCTL);
  1652. unpause_sequencer(p, TRUE);
  1653. mdelay(1);
  1654. pause_sequencer(p);
  1655. aic_outb(p, FASTMODE, SEQCTL);
  1656. if (aic7xxx_verbose & VERBOSE_PROBE)
  1657. {
  1658. printk(" %d instructions downloaded\n", downloaded);
  1659. }
  1660. if (aic7xxx_dump_sequencer)
  1661. aic7xxx_print_sequencer(p, downloaded);
  1662. }
  1663. /*+F*************************************************************************
  1664. * Function:
  1665. * aic7xxx_print_sequencer
  1666. *
  1667. * Description:
  1668. * Print the contents of the sequencer memory to the screen.
  1669. *-F*************************************************************************/
  1670. static void
  1671. aic7xxx_print_sequencer(struct aic7xxx_host *p, int downloaded)
  1672. {
  1673. int i, k, temp;
  1674. aic_outb(p, PERRORDIS|LOADRAM|FAILDIS|FASTMODE, SEQCTL);
  1675. aic_outb(p, 0, SEQADDR0);
  1676. aic_outb(p, 0, SEQADDR1);
  1677. k = 0;
  1678. for (i=0; i < downloaded; i++)
  1679. {
  1680. if ( k == 0 )
  1681. printk("%03x: ", i);
  1682. temp = aic_inb(p, SEQRAM);
  1683. temp |= (aic_inb(p, SEQRAM) << 8);
  1684. temp |= (aic_inb(p, SEQRAM) << 16);
  1685. temp |= (aic_inb(p, SEQRAM) << 24);
  1686. printk("%08x", temp);
  1687. if ( ++k == 8 )
  1688. {
  1689. printk("\n");
  1690. k = 0;
  1691. }
  1692. else
  1693. printk(" ");
  1694. }
  1695. aic_outb(p, 0, SEQADDR0);
  1696. aic_outb(p, 0, SEQADDR1);
  1697. aic_outb(p, FASTMODE | FAILDIS, SEQCTL);
  1698. unpause_sequencer(p, TRUE);
  1699. mdelay(1);
  1700. pause_sequencer(p);
  1701. aic_outb(p, FASTMODE, SEQCTL);
  1702. printk("\n");
  1703. }
  1704. /*+F*************************************************************************
  1705. * Function:
  1706. * aic7xxx_info
  1707. *
  1708. * Description:
  1709. * Return a string describing the driver.
  1710. *-F*************************************************************************/
  1711. static const char *
  1712. aic7xxx_info(struct Scsi_Host *dooh)
  1713. {
  1714. static char buffer[256];
  1715. char *bp;
  1716. struct aic7xxx_host *p;
  1717. bp = &buffer[0];
  1718. p = (struct aic7xxx_host *)dooh->hostdata;
  1719. memset(bp, 0, sizeof(buffer));
  1720. strcpy(bp, "Adaptec AHA274x/284x/294x (EISA/VLB/PCI-Fast SCSI) ");
  1721. strcat(bp, AIC7XXX_C_VERSION);
  1722. strcat(bp, "/");
  1723. strcat(bp, AIC7XXX_H_VERSION);
  1724. strcat(bp, "\n");
  1725. strcat(bp, " <");
  1726. strcat(bp, board_names[p->board_name_index]);
  1727. strcat(bp, ">");
  1728. return(bp);
  1729. }
  1730. /*+F*************************************************************************
  1731. * Function:
  1732. * aic7xxx_find_syncrate
  1733. *
  1734. * Description:
  1735. * Look up the valid period to SCSIRATE conversion in our table
  1736. *-F*************************************************************************/
  1737. static struct aic7xxx_syncrate *
  1738. aic7xxx_find_syncrate(struct aic7xxx_host *p, unsigned int *period,
  1739. unsigned int maxsync, unsigned char *options)
  1740. {
  1741. struct aic7xxx_syncrate *syncrate;
  1742. int done = FALSE;
  1743. switch(*options)
  1744. {
  1745. case MSG_EXT_PPR_OPTION_DT_CRC:
  1746. case MSG_EXT_PPR_OPTION_DT_UNITS:
  1747. if(!(p->features & AHC_ULTRA3))
  1748. {
  1749. *options = 0;
  1750. maxsync = max_t(unsigned int, maxsync, AHC_SYNCRATE_ULTRA2);
  1751. }
  1752. break;
  1753. case MSG_EXT_PPR_OPTION_DT_CRC_QUICK:
  1754. case MSG_EXT_PPR_OPTION_DT_UNITS_QUICK:
  1755. if(!(p->features & AHC_ULTRA3))
  1756. {
  1757. *options = 0;
  1758. maxsync = max_t(unsigned int, maxsync, AHC_SYNCRATE_ULTRA2);
  1759. }
  1760. else
  1761. {
  1762. /*
  1763. * we don't support the Quick Arbitration variants of dual edge
  1764. * clocking. As it turns out, we want to send back the
  1765. * same basic option, but without the QA attribute.
  1766. * We know that we are responding because we would never set
  1767. * these options ourself, we would only respond to them.
  1768. */
  1769. switch(*options)
  1770. {
  1771. case MSG_EXT_PPR_OPTION_DT_CRC_QUICK:
  1772. *options = MSG_EXT_PPR_OPTION_DT_CRC;
  1773. break;
  1774. case MSG_EXT_PPR_OPTION_DT_UNITS_QUICK:
  1775. *options = MSG_EXT_PPR_OPTION_DT_UNITS;
  1776. break;
  1777. }
  1778. }
  1779. break;
  1780. default:
  1781. *options = 0;
  1782. maxsync = max_t(unsigned int, maxsync, AHC_SYNCRATE_ULTRA2);
  1783. break;
  1784. }
  1785. syncrate = &aic7xxx_syncrates[maxsync];
  1786. while ( (syncrate->rate[0] != NULL) &&
  1787. (!(p->features & AHC_ULTRA2) || syncrate->sxfr_ultra2) )
  1788. {
  1789. if (*period <= syncrate->period)
  1790. {
  1791. switch(*options)
  1792. {
  1793. case MSG_EXT_PPR_OPTION_DT_CRC:
  1794. case MSG_EXT_PPR_OPTION_DT_UNITS:
  1795. if(!(syncrate->sxfr_ultra2 & AHC_SYNCRATE_CRC))
  1796. {
  1797. done = TRUE;
  1798. /*
  1799. * oops, we went too low for the CRC/DualEdge signalling, so
  1800. * clear the options byte
  1801. */
  1802. *options = 0;
  1803. /*
  1804. * We'll be sending a reply to this packet to set the options
  1805. * properly, so unilaterally set the period as well.
  1806. */
  1807. *period = syncrate->period;
  1808. }
  1809. else
  1810. {
  1811. done = TRUE;
  1812. if(syncrate == &aic7xxx_syncrates[maxsync])
  1813. {
  1814. *period = syncrate->period;
  1815. }
  1816. }
  1817. break;
  1818. default:
  1819. if(!(syncrate->sxfr_ultra2 & AHC_SYNCRATE_CRC))
  1820. {
  1821. done = TRUE;
  1822. if(syncrate == &aic7xxx_syncrates[maxsync])
  1823. {
  1824. *period = syncrate->period;
  1825. }
  1826. }
  1827. break;
  1828. }
  1829. if(done)
  1830. {
  1831. break;
  1832. }
  1833. }
  1834. syncrate++;
  1835. }
  1836. if ( (*period == 0) || (syncrate->rate[0] == NULL) ||
  1837. ((p->features & AHC_ULTRA2) && (syncrate->sxfr_ultra2 == 0)) )
  1838. {
  1839. /*
  1840. * Use async transfers for this target
  1841. */
  1842. *options = 0;
  1843. *period = 255;
  1844. syncrate = NULL;
  1845. }
  1846. return (syncrate);
  1847. }
  1848. /*+F*************************************************************************
  1849. * Function:
  1850. * aic7xxx_find_period
  1851. *
  1852. * Description:
  1853. * Look up the valid SCSIRATE to period conversion in our table
  1854. *-F*************************************************************************/
  1855. static unsigned int
  1856. aic7xxx_find_period(struct aic7xxx_host *p, unsigned int scsirate,
  1857. unsigned int maxsync)
  1858. {
  1859. struct aic7xxx_syncrate *syncrate;
  1860. if (p->features & AHC_ULTRA2)
  1861. {
  1862. scsirate &= SXFR_ULTRA2;
  1863. }
  1864. else
  1865. {
  1866. scsirate &= SXFR;
  1867. }
  1868. syncrate = &aic7xxx_syncrates[maxsync];
  1869. while (syncrate->rate[0] != NULL)
  1870. {
  1871. if (p->features & AHC_ULTRA2)
  1872. {
  1873. if (syncrate->sxfr_ultra2 == 0)
  1874. break;
  1875. else if (scsirate == syncrate->sxfr_ultra2)
  1876. return (syncrate->period);
  1877. else if (scsirate == (syncrate->sxfr_ultra2 & ~AHC_SYNCRATE_CRC))
  1878. return (syncrate->period);
  1879. }
  1880. else if (scsirate == (syncrate->sxfr & ~ULTRA_SXFR))
  1881. {
  1882. return (syncrate->period);
  1883. }
  1884. syncrate++;
  1885. }
  1886. return (0); /* async */
  1887. }
  1888. /*+F*************************************************************************
  1889. * Function:
  1890. * aic7xxx_validate_offset
  1891. *
  1892. * Description:
  1893. * Set a valid offset value for a particular card in use and transfer
  1894. * settings in use.
  1895. *-F*************************************************************************/
  1896. static void
  1897. aic7xxx_validate_offset(struct aic7xxx_host *p,
  1898. struct aic7xxx_syncrate *syncrate, unsigned int *offset, int wide)
  1899. {
  1900. unsigned int maxoffset;
  1901. /* Limit offset to what the card (and device) can do */
  1902. if (syncrate == NULL)
  1903. {
  1904. maxoffset = 0;
  1905. }
  1906. else if (p->features & AHC_ULTRA2)
  1907. {
  1908. maxoffset = MAX_OFFSET_ULTRA2;
  1909. }
  1910. else
  1911. {
  1912. if (wide)
  1913. maxoffset = MAX_OFFSET_16BIT;
  1914. else
  1915. maxoffset = MAX_OFFSET_8BIT;
  1916. }
  1917. *offset = min(*offset, maxoffset);
  1918. }
  1919. /*+F*************************************************************************
  1920. * Function:
  1921. * aic7xxx_set_syncrate
  1922. *
  1923. * Description:
  1924. * Set the actual syncrate down in the card and in our host structs
  1925. *-F*************************************************************************/
  1926. static void
  1927. aic7xxx_set_syncrate(struct aic7xxx_host *p, struct aic7xxx_syncrate *syncrate,
  1928. int target, int channel, unsigned int period, unsigned int offset,
  1929. unsigned char options, unsigned int type, struct aic_dev_data *aic_dev)
  1930. {
  1931. unsigned char tindex;
  1932. unsigned short target_mask;
  1933. unsigned char lun, old_options;
  1934. unsigned int old_period, old_offset;
  1935. tindex = target | (channel << 3);
  1936. target_mask = 0x01 << tindex;
  1937. lun = aic_inb(p, SCB_TCL) & 0x07;
  1938. if (syncrate == NULL)
  1939. {
  1940. period = 0;
  1941. offset = 0;
  1942. }
  1943. old_period = aic_dev->cur.period;
  1944. old_offset = aic_dev->cur.offset;
  1945. old_options = aic_dev->cur.options;
  1946. if (type & AHC_TRANS_CUR)
  1947. {
  1948. unsigned int scsirate;
  1949. scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
  1950. if (p->features & AHC_ULTRA2)
  1951. {
  1952. scsirate &= ~SXFR_ULTRA2;
  1953. if (syncrate != NULL)
  1954. {
  1955. switch(options)
  1956. {
  1957. case MSG_EXT_PPR_OPTION_DT_UNITS:
  1958. /*
  1959. * mask off the CRC bit in the xfer settings
  1960. */
  1961. scsirate |= (syncrate->sxfr_ultra2 & ~AHC_SYNCRATE_CRC);
  1962. break;
  1963. default:
  1964. scsirate |= syncrate->sxfr_ultra2;
  1965. break;
  1966. }
  1967. }
  1968. if (type & AHC_TRANS_ACTIVE)
  1969. {
  1970. aic_outb(p, offset, SCSIOFFSET);
  1971. }
  1972. aic_outb(p, offset, TARG_OFFSET + tindex);
  1973. }
  1974. else /* Not an Ultra2 controller */
  1975. {
  1976. scsirate &= ~(SXFR|SOFS);
  1977. p->ultraenb &= ~target_mask;
  1978. if (syncrate != NULL)
  1979. {
  1980. if (syncrate->sxfr & ULTRA_SXFR)
  1981. {
  1982. p->ultraenb |= target_mask;
  1983. }
  1984. scsirate |= (syncrate->sxfr & SXFR);
  1985. scsirate |= (offset & SOFS);
  1986. }
  1987. if (type & AHC_TRANS_ACTIVE)
  1988. {
  1989. unsigned char sxfrctl0;
  1990. sxfrctl0 = aic_inb(p, SXFRCTL0);
  1991. sxfrctl0 &= ~FAST20;
  1992. if (p->ultraenb & target_mask)
  1993. sxfrctl0 |= FAST20;
  1994. aic_outb(p, sxfrctl0, SXFRCTL0);
  1995. }
  1996. aic_outb(p, p->ultraenb & 0xff, ULTRA_ENB);
  1997. aic_outb(p, (p->ultraenb >> 8) & 0xff, ULTRA_ENB + 1 );
  1998. }
  1999. if (type & AHC_TRANS_ACTIVE)
  2000. {
  2001. aic_outb(p, scsirate, SCSIRATE);
  2002. }
  2003. aic_outb(p, scsirate, TARG_SCSIRATE + tindex);
  2004. aic_dev->cur.period = period;
  2005. aic_dev->cur.offset = offset;
  2006. aic_dev->cur.options = options;
  2007. if ( !(type & AHC_TRANS_QUITE) &&
  2008. (aic7xxx_verbose & VERBOSE_NEGOTIATION) &&
  2009. (aic_dev->flags & DEVICE_PRINT_DTR) )
  2010. {
  2011. if (offset)
  2012. {
  2013. int rate_mod = (scsirate & WIDEXFER) ? 1 : 0;
  2014. printk(INFO_LEAD "Synchronous at %s Mbyte/sec, "
  2015. "offset %d.\n", p->host_no, channel, target, lun,
  2016. syncrate->rate[rate_mod], offset);
  2017. }
  2018. else
  2019. {
  2020. printk(INFO_LEAD "Using asynchronous transfers.\n",
  2021. p->host_no, channel, target, lun);
  2022. }
  2023. aic_dev->flags &= ~DEVICE_PRINT_DTR;
  2024. }
  2025. }
  2026. if (type & AHC_TRANS_GOAL)
  2027. {
  2028. aic_dev->goal.period = period;
  2029. aic_dev->goal.offset = offset;
  2030. aic_dev->goal.options = options;
  2031. }
  2032. if (type & AHC_TRANS_USER)
  2033. {
  2034. p->user[tindex].period = period;
  2035. p->user[tindex].offset = offset;
  2036. p->user[tindex].options = options;
  2037. }
  2038. }
  2039. /*+F*************************************************************************
  2040. * Function:
  2041. * aic7xxx_set_width
  2042. *
  2043. * Description:
  2044. * Set the actual width down in the card and in our host structs
  2045. *-F*************************************************************************/
  2046. static void
  2047. aic7xxx_set_width(struct aic7xxx_host *p, int target, int channel, int lun,
  2048. unsigned int width, unsigned int type, struct aic_dev_data *aic_dev)
  2049. {
  2050. unsigned char tindex;
  2051. unsigned short target_mask;
  2052. unsigned int old_width;
  2053. tindex = target | (channel << 3);
  2054. target_mask = 1 << tindex;
  2055. old_width = aic_dev->cur.width;
  2056. if (type & AHC_TRANS_CUR)
  2057. {
  2058. unsigned char scsirate;
  2059. scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
  2060. scsirate &= ~WIDEXFER;
  2061. if (width == MSG_EXT_WDTR_BUS_16_BIT)
  2062. scsirate |= WIDEXFER;
  2063. aic_outb(p, scsirate, TARG_SCSIRATE + tindex);
  2064. if (type & AHC_TRANS_ACTIVE)
  2065. aic_outb(p, scsirate, SCSIRATE);
  2066. aic_dev->cur.width = width;
  2067. if ( !(type & AHC_TRANS_QUITE) &&
  2068. (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  2069. (aic_dev->flags & DEVICE_PRINT_DTR) )
  2070. {
  2071. printk(INFO_LEAD "Using %s transfers\n", p->host_no, channel, target,
  2072. lun, (scsirate & WIDEXFER) ? "Wide(16bit)" : "Narrow(8bit)" );
  2073. }
  2074. }
  2075. if (type & AHC_TRANS_GOAL)
  2076. aic_dev->goal.width = width;
  2077. if (type & AHC_TRANS_USER)
  2078. p->user[tindex].width = width;
  2079. if (aic_dev->goal.offset)
  2080. {
  2081. if (p->features & AHC_ULTRA2)
  2082. {
  2083. aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
  2084. }
  2085. else if (width == MSG_EXT_WDTR_BUS_16_BIT)
  2086. {
  2087. aic_dev->goal.offset = MAX_OFFSET_16BIT;
  2088. }
  2089. else
  2090. {
  2091. aic_dev->goal.offset = MAX_OFFSET_8BIT;
  2092. }
  2093. }
  2094. }
  2095. /*+F*************************************************************************
  2096. * Function:
  2097. * scbq_init
  2098. *
  2099. * Description:
  2100. * SCB queue initialization.
  2101. *
  2102. *-F*************************************************************************/
  2103. static void
  2104. scbq_init(volatile scb_queue_type *queue)
  2105. {
  2106. queue->head = NULL;
  2107. queue->tail = NULL;
  2108. }
  2109. /*+F*************************************************************************
  2110. * Function:
  2111. * scbq_insert_head
  2112. *
  2113. * Description:
  2114. * Add an SCB to the head of the list.
  2115. *
  2116. *-F*************************************************************************/
  2117. static inline void
  2118. scbq_insert_head(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
  2119. {
  2120. scb->q_next = queue->head;
  2121. queue->head = scb;
  2122. if (queue->tail == NULL) /* If list was empty, update tail. */
  2123. queue->tail = queue->head;
  2124. }
  2125. /*+F*************************************************************************
  2126. * Function:
  2127. * scbq_remove_head
  2128. *
  2129. * Description:
  2130. * Remove an SCB from the head of the list.
  2131. *
  2132. *-F*************************************************************************/
  2133. static inline struct aic7xxx_scb *
  2134. scbq_remove_head(volatile scb_queue_type *queue)
  2135. {
  2136. struct aic7xxx_scb * scbp;
  2137. scbp = queue->head;
  2138. if (queue->head != NULL)
  2139. queue->head = queue->head->q_next;
  2140. if (queue->head == NULL) /* If list is now empty, update tail. */
  2141. queue->tail = NULL;
  2142. return(scbp);
  2143. }
  2144. /*+F*************************************************************************
  2145. * Function:
  2146. * scbq_remove
  2147. *
  2148. * Description:
  2149. * Removes an SCB from the list.
  2150. *
  2151. *-F*************************************************************************/
  2152. static inline void
  2153. scbq_remove(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
  2154. {
  2155. if (queue->head == scb)
  2156. {
  2157. /* At beginning of queue, remove from head. */
  2158. scbq_remove_head(queue);
  2159. }
  2160. else
  2161. {
  2162. struct aic7xxx_scb *curscb = queue->head;
  2163. /*
  2164. * Search until the next scb is the one we're looking for, or
  2165. * we run out of queue.
  2166. */
  2167. while ((curscb != NULL) && (curscb->q_next != scb))
  2168. {
  2169. curscb = curscb->q_next;
  2170. }
  2171. if (curscb != NULL)
  2172. {
  2173. /* Found it. */
  2174. curscb->q_next = scb->q_next;
  2175. if (scb->q_next == NULL)
  2176. {
  2177. /* Update the tail when removing the tail. */
  2178. queue->tail = curscb;
  2179. }
  2180. }
  2181. }
  2182. }
  2183. /*+F*************************************************************************
  2184. * Function:
  2185. * scbq_insert_tail
  2186. *
  2187. * Description:
  2188. * Add an SCB at the tail of the list.
  2189. *
  2190. *-F*************************************************************************/
  2191. static inline void
  2192. scbq_insert_tail(volatile scb_queue_type *queue, struct aic7xxx_scb *scb)
  2193. {
  2194. scb->q_next = NULL;
  2195. if (queue->tail != NULL) /* Add the scb at the end of the list. */
  2196. queue->tail->q_next = scb;
  2197. queue->tail = scb; /* Update the tail. */
  2198. if (queue->head == NULL) /* If list was empty, update head. */
  2199. queue->head = queue->tail;
  2200. }
  2201. /*+F*************************************************************************
  2202. * Function:
  2203. * aic7xxx_match_scb
  2204. *
  2205. * Description:
  2206. * Checks to see if an scb matches the target/channel as specified.
  2207. * If target is ALL_TARGETS (-1), then we're looking for any device
  2208. * on the specified channel; this happens when a channel is going
  2209. * to be reset and all devices on that channel must be aborted.
  2210. *-F*************************************************************************/
  2211. static int
  2212. aic7xxx_match_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb,
  2213. int target, int channel, int lun, unsigned char tag)
  2214. {
  2215. int targ = (scb->hscb->target_channel_lun >> 4) & 0x0F;
  2216. int chan = (scb->hscb->target_channel_lun >> 3) & 0x01;
  2217. int slun = scb->hscb->target_channel_lun & 0x07;
  2218. int match;
  2219. match = ((chan == channel) || (channel == ALL_CHANNELS));
  2220. if (match != 0)
  2221. match = ((targ == target) || (target == ALL_TARGETS));
  2222. if (match != 0)
  2223. match = ((lun == slun) || (lun == ALL_LUNS));
  2224. if (match != 0)
  2225. match = ((tag == scb->hscb->tag) || (tag == SCB_LIST_NULL));
  2226. return (match);
  2227. }
  2228. /*+F*************************************************************************
  2229. * Function:
  2230. * aic7xxx_add_curscb_to_free_list
  2231. *
  2232. * Description:
  2233. * Adds the current scb (in SCBPTR) to the list of free SCBs.
  2234. *-F*************************************************************************/
  2235. static void
  2236. aic7xxx_add_curscb_to_free_list(struct aic7xxx_host *p)
  2237. {
  2238. /*
  2239. * Invalidate the tag so that aic7xxx_find_scb doesn't think
  2240. * it's active
  2241. */
  2242. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  2243. aic_outb(p, 0, SCB_CONTROL);
  2244. aic_outb(p, aic_inb(p, FREE_SCBH), SCB_NEXT);
  2245. aic_outb(p, aic_inb(p, SCBPTR), FREE_SCBH);
  2246. }
  2247. /*+F*************************************************************************
  2248. * Function:
  2249. * aic7xxx_rem_scb_from_disc_list
  2250. *
  2251. * Description:
  2252. * Removes the current SCB from the disconnected list and adds it
  2253. * to the free list.
  2254. *-F*************************************************************************/
  2255. static unsigned char
  2256. aic7xxx_rem_scb_from_disc_list(struct aic7xxx_host *p, unsigned char scbptr,
  2257. unsigned char prev)
  2258. {
  2259. unsigned char next;
  2260. aic_outb(p, scbptr, SCBPTR);
  2261. next = aic_inb(p, SCB_NEXT);
  2262. aic7xxx_add_curscb_to_free_list(p);
  2263. if (prev != SCB_LIST_NULL)
  2264. {
  2265. aic_outb(p, prev, SCBPTR);
  2266. aic_outb(p, next, SCB_NEXT);
  2267. }
  2268. else
  2269. {
  2270. aic_outb(p, next, DISCONNECTED_SCBH);
  2271. }
  2272. return next;
  2273. }
  2274. /*+F*************************************************************************
  2275. * Function:
  2276. * aic7xxx_busy_target
  2277. *
  2278. * Description:
  2279. * Set the specified target busy.
  2280. *-F*************************************************************************/
  2281. static inline void
  2282. aic7xxx_busy_target(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  2283. {
  2284. p->untagged_scbs[scb->hscb->target_channel_lun] = scb->hscb->tag;
  2285. }
  2286. /*+F*************************************************************************
  2287. * Function:
  2288. * aic7xxx_index_busy_target
  2289. *
  2290. * Description:
  2291. * Returns the index of the busy target, and optionally sets the
  2292. * target inactive.
  2293. *-F*************************************************************************/
  2294. static inline unsigned char
  2295. aic7xxx_index_busy_target(struct aic7xxx_host *p, unsigned char tcl,
  2296. int unbusy)
  2297. {
  2298. unsigned char busy_scbid;
  2299. busy_scbid = p->untagged_scbs[tcl];
  2300. if (unbusy)
  2301. {
  2302. p->untagged_scbs[tcl] = SCB_LIST_NULL;
  2303. }
  2304. return (busy_scbid);
  2305. }
  2306. /*+F*************************************************************************
  2307. * Function:
  2308. * aic7xxx_find_scb
  2309. *
  2310. * Description:
  2311. * Look through the SCB array of the card and attempt to find the
  2312. * hardware SCB that corresponds to the passed in SCB. Return
  2313. * SCB_LIST_NULL if unsuccessful. This routine assumes that the
  2314. * card is already paused.
  2315. *-F*************************************************************************/
  2316. static unsigned char
  2317. aic7xxx_find_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  2318. {
  2319. unsigned char saved_scbptr;
  2320. unsigned char curindex;
  2321. saved_scbptr = aic_inb(p, SCBPTR);
  2322. curindex = 0;
  2323. for (curindex = 0; curindex < p->scb_data->maxhscbs; curindex++)
  2324. {
  2325. aic_outb(p, curindex, SCBPTR);
  2326. if (aic_inb(p, SCB_TAG) == scb->hscb->tag)
  2327. {
  2328. break;
  2329. }
  2330. }
  2331. aic_outb(p, saved_scbptr, SCBPTR);
  2332. if (curindex >= p->scb_data->maxhscbs)
  2333. {
  2334. curindex = SCB_LIST_NULL;
  2335. }
  2336. return (curindex);
  2337. }
  2338. /*+F*************************************************************************
  2339. * Function:
  2340. * aic7xxx_allocate_scb
  2341. *
  2342. * Description:
  2343. * Get an SCB from the free list or by allocating a new one.
  2344. *-F*************************************************************************/
  2345. static int
  2346. aic7xxx_allocate_scb(struct aic7xxx_host *p)
  2347. {
  2348. struct aic7xxx_scb *scbp = NULL;
  2349. int scb_size = (sizeof (struct hw_scatterlist) * AIC7XXX_MAX_SG) + 12 + 6;
  2350. int i;
  2351. int step = PAGE_SIZE / 1024;
  2352. unsigned long scb_count = 0;
  2353. struct hw_scatterlist *hsgp;
  2354. struct aic7xxx_scb *scb_ap;
  2355. struct aic7xxx_scb_dma *scb_dma;
  2356. unsigned char *bufs;
  2357. if (p->scb_data->numscbs < p->scb_data->maxscbs)
  2358. {
  2359. /*
  2360. * Calculate the optimal number of SCBs to allocate.
  2361. *
  2362. * NOTE: This formula works because the sizeof(sg_array) is always
  2363. * 1024. Therefore, scb_size * i would always be > PAGE_SIZE *
  2364. * (i/step). The (i-1) allows the left hand side of the equation
  2365. * to grow into the right hand side to a point of near perfect
  2366. * efficiency since scb_size * (i -1) is growing slightly faster
  2367. * than the right hand side. If the number of SG array elements
  2368. * is changed, this function may not be near so efficient any more.
  2369. *
  2370. * Since the DMA'able buffers are now allocated in a separate
  2371. * chunk this algorithm has been modified to match. The '12'
  2372. * and '6' factors in scb_size are for the DMA'able command byte
  2373. * and sensebuffers respectively. -DaveM
  2374. */
  2375. for ( i=step;; i *= 2 )
  2376. {
  2377. if ( (scb_size * (i-1)) >= ( (PAGE_SIZE * (i/step)) - 64 ) )
  2378. {
  2379. i /= 2;
  2380. break;
  2381. }
  2382. }
  2383. scb_count = min( (i-1), p->scb_data->maxscbs - p->scb_data->numscbs);
  2384. scb_ap = (struct aic7xxx_scb *)kmalloc(sizeof (struct aic7xxx_scb) * scb_count
  2385. + sizeof(struct aic7xxx_scb_dma), GFP_ATOMIC);
  2386. if (scb_ap == NULL)
  2387. return(0);
  2388. scb_dma = (struct aic7xxx_scb_dma *)&scb_ap[scb_count];
  2389. hsgp = (struct hw_scatterlist *)
  2390. pci_alloc_consistent(p->pdev, scb_size * scb_count,
  2391. &scb_dma->dma_address);
  2392. if (hsgp == NULL)
  2393. {
  2394. kfree(scb_ap);
  2395. return(0);
  2396. }
  2397. bufs = (unsigned char *)&hsgp[scb_count * AIC7XXX_MAX_SG];
  2398. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  2399. if (aic7xxx_verbose > 0xffff)
  2400. {
  2401. if (p->scb_data->numscbs == 0)
  2402. printk(INFO_LEAD "Allocating initial %ld SCB structures.\n",
  2403. p->host_no, -1, -1, -1, scb_count);
  2404. else
  2405. printk(INFO_LEAD "Allocating %ld additional SCB structures.\n",
  2406. p->host_no, -1, -1, -1, scb_count);
  2407. }
  2408. #endif
  2409. memset(scb_ap, 0, sizeof (struct aic7xxx_scb) * scb_count);
  2410. scb_dma->dma_offset = (unsigned long)scb_dma->dma_address
  2411. - (unsigned long)hsgp;
  2412. scb_dma->dma_len = scb_size * scb_count;
  2413. for (i=0; i < scb_count; i++)
  2414. {
  2415. scbp = &scb_ap[i];
  2416. scbp->hscb = &p->scb_data->hscbs[p->scb_data->numscbs];
  2417. scbp->sg_list = &hsgp[i * AIC7XXX_MAX_SG];
  2418. scbp->sense_cmd = bufs;
  2419. scbp->cmnd = bufs + 6;
  2420. bufs += 12 + 6;
  2421. scbp->scb_dma = scb_dma;
  2422. memset(scbp->hscb, 0, sizeof(struct aic7xxx_hwscb));
  2423. scbp->hscb->tag = p->scb_data->numscbs;
  2424. /*
  2425. * Place in the scb array; never is removed
  2426. */
  2427. p->scb_data->scb_array[p->scb_data->numscbs++] = scbp;
  2428. scbq_insert_tail(&p->scb_data->free_scbs, scbp);
  2429. }
  2430. scbp->kmalloc_ptr = scb_ap;
  2431. }
  2432. return(scb_count);
  2433. }
  2434. /*+F*************************************************************************
  2435. * Function:
  2436. * aic7xxx_queue_cmd_complete
  2437. *
  2438. * Description:
  2439. * Due to race conditions present in the SCSI subsystem, it is easier
  2440. * to queue completed commands, then call scsi_done() on them when
  2441. * we're finished. This function queues the completed commands.
  2442. *-F*************************************************************************/
  2443. static void
  2444. aic7xxx_queue_cmd_complete(struct aic7xxx_host *p, struct scsi_cmnd *cmd)
  2445. {
  2446. aic7xxx_position(cmd) = SCB_LIST_NULL;
  2447. cmd->host_scribble = (char *)p->completeq.head;
  2448. p->completeq.head = cmd;
  2449. }
  2450. /*+F*************************************************************************
  2451. * Function:
  2452. * aic7xxx_done_cmds_complete
  2453. *
  2454. * Description:
  2455. * Process the completed command queue.
  2456. *-F*************************************************************************/
  2457. static void aic7xxx_done_cmds_complete(struct aic7xxx_host *p)
  2458. {
  2459. struct scsi_cmnd *cmd;
  2460. while (p->completeq.head != NULL) {
  2461. cmd = p->completeq.head;
  2462. p->completeq.head = (struct scsi_Cmnd *) cmd->host_scribble;
  2463. cmd->host_scribble = NULL;
  2464. cmd->scsi_done(cmd);
  2465. }
  2466. }
  2467. /*+F*************************************************************************
  2468. * Function:
  2469. * aic7xxx_free_scb
  2470. *
  2471. * Description:
  2472. * Free the scb and insert into the free scb list.
  2473. *-F*************************************************************************/
  2474. static void
  2475. aic7xxx_free_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  2476. {
  2477. scb->flags = SCB_FREE;
  2478. scb->cmd = NULL;
  2479. scb->sg_count = 0;
  2480. scb->sg_length = 0;
  2481. scb->tag_action = 0;
  2482. scb->hscb->control = 0;
  2483. scb->hscb->target_status = 0;
  2484. scb->hscb->target_channel_lun = SCB_LIST_NULL;
  2485. scbq_insert_head(&p->scb_data->free_scbs, scb);
  2486. }
  2487. /*+F*************************************************************************
  2488. * Function:
  2489. * aic7xxx_done
  2490. *
  2491. * Description:
  2492. * Calls the higher level scsi done function and frees the scb.
  2493. *-F*************************************************************************/
  2494. static void
  2495. aic7xxx_done(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  2496. {
  2497. struct scsi_cmnd *cmd = scb->cmd;
  2498. struct aic_dev_data *aic_dev = cmd->device->hostdata;
  2499. int tindex = TARGET_INDEX(cmd);
  2500. struct aic7xxx_scb *scbp;
  2501. unsigned char queue_depth;
  2502. if (cmd->use_sg > 1)
  2503. {
  2504. struct scatterlist *sg;
  2505. sg = (struct scatterlist *)cmd->request_buffer;
  2506. pci_unmap_sg(p->pdev, sg, cmd->use_sg, cmd->sc_data_direction);
  2507. }
  2508. else if (cmd->request_bufflen)
  2509. pci_unmap_single(p->pdev, aic7xxx_mapping(cmd),
  2510. cmd->request_bufflen,
  2511. cmd->sc_data_direction);
  2512. if (scb->flags & SCB_SENSE)
  2513. {
  2514. pci_unmap_single(p->pdev,
  2515. le32_to_cpu(scb->sg_list[0].address),
  2516. sizeof(cmd->sense_buffer),
  2517. PCI_DMA_FROMDEVICE);
  2518. }
  2519. if (scb->flags & SCB_RECOVERY_SCB)
  2520. {
  2521. p->flags &= ~AHC_ABORT_PENDING;
  2522. }
  2523. if (scb->flags & (SCB_RESET|SCB_ABORT))
  2524. {
  2525. cmd->result |= (DID_RESET << 16);
  2526. }
  2527. if ((scb->flags & SCB_MSGOUT_BITS) != 0)
  2528. {
  2529. unsigned short mask;
  2530. int message_error = FALSE;
  2531. mask = 0x01 << tindex;
  2532. /*
  2533. * Check to see if we get an invalid message or a message error
  2534. * after failing to negotiate a wide or sync transfer message.
  2535. */
  2536. if ((scb->flags & SCB_SENSE) &&
  2537. ((scb->cmd->sense_buffer[12] == 0x43) || /* INVALID_MESSAGE */
  2538. (scb->cmd->sense_buffer[12] == 0x49))) /* MESSAGE_ERROR */
  2539. {
  2540. message_error = TRUE;
  2541. }
  2542. if (scb->flags & SCB_MSGOUT_WDTR)
  2543. {
  2544. if (message_error)
  2545. {
  2546. if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  2547. (aic_dev->flags & DEVICE_PRINT_DTR) )
  2548. {
  2549. printk(INFO_LEAD "Device failed to complete Wide Negotiation "
  2550. "processing and\n", p->host_no, CTL_OF_SCB(scb));
  2551. printk(INFO_LEAD "returned a sense error code for invalid message, "
  2552. "disabling future\n", p->host_no, CTL_OF_SCB(scb));
  2553. printk(INFO_LEAD "Wide negotiation to this device.\n", p->host_no,
  2554. CTL_OF_SCB(scb));
  2555. }
  2556. aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
  2557. }
  2558. }
  2559. if (scb->flags & SCB_MSGOUT_SDTR)
  2560. {
  2561. if (message_error)
  2562. {
  2563. if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  2564. (aic_dev->flags & DEVICE_PRINT_DTR) )
  2565. {
  2566. printk(INFO_LEAD "Device failed to complete Sync Negotiation "
  2567. "processing and\n", p->host_no, CTL_OF_SCB(scb));
  2568. printk(INFO_LEAD "returned a sense error code for invalid message, "
  2569. "disabling future\n", p->host_no, CTL_OF_SCB(scb));
  2570. printk(INFO_LEAD "Sync negotiation to this device.\n", p->host_no,
  2571. CTL_OF_SCB(scb));
  2572. aic_dev->flags &= ~DEVICE_PRINT_DTR;
  2573. }
  2574. aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
  2575. }
  2576. }
  2577. if (scb->flags & SCB_MSGOUT_PPR)
  2578. {
  2579. if(message_error)
  2580. {
  2581. if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  2582. (aic_dev->flags & DEVICE_PRINT_DTR) )
  2583. {
  2584. printk(INFO_LEAD "Device failed to complete Parallel Protocol "
  2585. "Request processing and\n", p->host_no, CTL_OF_SCB(scb));
  2586. printk(INFO_LEAD "returned a sense error code for invalid message, "
  2587. "disabling future\n", p->host_no, CTL_OF_SCB(scb));
  2588. printk(INFO_LEAD "Parallel Protocol Request negotiation to this "
  2589. "device.\n", p->host_no, CTL_OF_SCB(scb));
  2590. }
  2591. /*
  2592. * Disable PPR negotiation and revert back to WDTR and SDTR setup
  2593. */
  2594. aic_dev->needppr = aic_dev->needppr_copy = 0;
  2595. aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
  2596. aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
  2597. }
  2598. }
  2599. }
  2600. queue_depth = aic_dev->temp_q_depth;
  2601. if (queue_depth >= aic_dev->active_cmds)
  2602. {
  2603. scbp = scbq_remove_head(&aic_dev->delayed_scbs);
  2604. if (scbp)
  2605. {
  2606. if (queue_depth == 1)
  2607. {
  2608. /*
  2609. * Give extra preference to untagged devices, such as CD-R devices
  2610. * This makes it more likely that a drive *won't* stuff up while
  2611. * waiting on data at a critical time, such as CD-R writing and
  2612. * audio CD ripping operations. Should also benefit tape drives.
  2613. */
  2614. scbq_insert_head(&p->waiting_scbs, scbp);
  2615. }
  2616. else
  2617. {
  2618. scbq_insert_tail(&p->waiting_scbs, scbp);
  2619. }
  2620. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  2621. if (aic7xxx_verbose > 0xffff)
  2622. printk(INFO_LEAD "Moving SCB from delayed to waiting queue.\n",
  2623. p->host_no, CTL_OF_SCB(scbp));
  2624. #endif
  2625. if (queue_depth > aic_dev->active_cmds)
  2626. {
  2627. scbp = scbq_remove_head(&aic_dev->delayed_scbs);
  2628. if (scbp)
  2629. scbq_insert_tail(&p->waiting_scbs, scbp);
  2630. }
  2631. }
  2632. }
  2633. if (!(scb->tag_action))
  2634. {
  2635. aic7xxx_index_busy_target(p, scb->hscb->target_channel_lun,
  2636. /* unbusy */ TRUE);
  2637. if (cmd->device->simple_tags)
  2638. {
  2639. aic_dev->temp_q_depth = aic_dev->max_q_depth;
  2640. }
  2641. }
  2642. if(scb->flags & SCB_DTR_SCB)
  2643. {
  2644. aic_dev->dtr_pending = 0;
  2645. }
  2646. aic_dev->active_cmds--;
  2647. p->activescbs--;
  2648. if ((scb->sg_length >= 512) && (((cmd->result >> 16) & 0xf) == DID_OK))
  2649. {
  2650. long *ptr;
  2651. int x, i;
  2652. if (rq_data_dir(cmd->request) == WRITE)
  2653. {
  2654. aic_dev->w_total++;
  2655. ptr = aic_dev->w_bins;
  2656. }
  2657. else
  2658. {
  2659. aic_dev->r_total++;
  2660. ptr = aic_dev->r_bins;
  2661. }
  2662. if(cmd->device->simple_tags && cmd->request->cmd_flags & REQ_HARDBARRIER)
  2663. {
  2664. aic_dev->barrier_total++;
  2665. if(scb->tag_action == MSG_ORDERED_Q_TAG)
  2666. aic_dev->ordered_total++;
  2667. }
  2668. x = scb->sg_length;
  2669. x >>= 10;
  2670. for(i=0; i<6; i++)
  2671. {
  2672. x >>= 2;
  2673. if(!x) {
  2674. ptr[i]++;
  2675. break;
  2676. }
  2677. }
  2678. if(i == 6 && x)
  2679. ptr[5]++;
  2680. }
  2681. aic7xxx_free_scb(p, scb);
  2682. aic7xxx_queue_cmd_complete(p, cmd);
  2683. }
  2684. /*+F*************************************************************************
  2685. * Function:
  2686. * aic7xxx_run_done_queue
  2687. *
  2688. * Description:
  2689. * Calls the aic7xxx_done() for the scsi_cmnd of each scb in the
  2690. * aborted list, and adds each scb to the free list. If complete
  2691. * is TRUE, we also process the commands complete list.
  2692. *-F*************************************************************************/
  2693. static void
  2694. aic7xxx_run_done_queue(struct aic7xxx_host *p, /*complete*/ int complete)
  2695. {
  2696. struct aic7xxx_scb *scb;
  2697. int i, found = 0;
  2698. for (i = 0; i < p->scb_data->numscbs; i++)
  2699. {
  2700. scb = p->scb_data->scb_array[i];
  2701. if (scb->flags & SCB_QUEUED_FOR_DONE)
  2702. {
  2703. if (scb->flags & SCB_QUEUE_FULL)
  2704. {
  2705. scb->cmd->result = QUEUE_FULL << 1;
  2706. }
  2707. else
  2708. {
  2709. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  2710. printk(INFO_LEAD "Aborting scb %d\n",
  2711. p->host_no, CTL_OF_SCB(scb), scb->hscb->tag);
  2712. /*
  2713. * Clear any residual information since the normal aic7xxx_done() path
  2714. * doesn't touch the residuals.
  2715. */
  2716. scb->hscb->residual_SG_segment_count = 0;
  2717. scb->hscb->residual_data_count[0] = 0;
  2718. scb->hscb->residual_data_count[1] = 0;
  2719. scb->hscb->residual_data_count[2] = 0;
  2720. }
  2721. found++;
  2722. aic7xxx_done(p, scb);
  2723. }
  2724. }
  2725. if (aic7xxx_verbose & (VERBOSE_ABORT_RETURN | VERBOSE_RESET_RETURN))
  2726. {
  2727. printk(INFO_LEAD "%d commands found and queued for "
  2728. "completion.\n", p->host_no, -1, -1, -1, found);
  2729. }
  2730. if (complete)
  2731. {
  2732. aic7xxx_done_cmds_complete(p);
  2733. }
  2734. }
  2735. /*+F*************************************************************************
  2736. * Function:
  2737. * aic7xxx_abort_waiting_scb
  2738. *
  2739. * Description:
  2740. * Manipulate the waiting for selection list and return the
  2741. * scb that follows the one that we remove.
  2742. *-F*************************************************************************/
  2743. static unsigned char
  2744. aic7xxx_abort_waiting_scb(struct aic7xxx_host *p, struct aic7xxx_scb *scb,
  2745. unsigned char scbpos, unsigned char prev)
  2746. {
  2747. unsigned char curscb, next;
  2748. /*
  2749. * Select the SCB we want to abort and pull the next pointer out of it.
  2750. */
  2751. curscb = aic_inb(p, SCBPTR);
  2752. aic_outb(p, scbpos, SCBPTR);
  2753. next = aic_inb(p, SCB_NEXT);
  2754. aic7xxx_add_curscb_to_free_list(p);
  2755. /*
  2756. * Update the waiting list
  2757. */
  2758. if (prev == SCB_LIST_NULL)
  2759. {
  2760. /*
  2761. * First in the list
  2762. */
  2763. aic_outb(p, next, WAITING_SCBH);
  2764. }
  2765. else
  2766. {
  2767. /*
  2768. * Select the scb that pointed to us and update its next pointer.
  2769. */
  2770. aic_outb(p, prev, SCBPTR);
  2771. aic_outb(p, next, SCB_NEXT);
  2772. }
  2773. /*
  2774. * Point us back at the original scb position and inform the SCSI
  2775. * system that the command has been aborted.
  2776. */
  2777. aic_outb(p, curscb, SCBPTR);
  2778. return (next);
  2779. }
  2780. /*+F*************************************************************************
  2781. * Function:
  2782. * aic7xxx_search_qinfifo
  2783. *
  2784. * Description:
  2785. * Search the queue-in FIFO for matching SCBs and conditionally
  2786. * requeue. Returns the number of matching SCBs.
  2787. *-F*************************************************************************/
  2788. static int
  2789. aic7xxx_search_qinfifo(struct aic7xxx_host *p, int target, int channel,
  2790. int lun, unsigned char tag, int flags, int requeue,
  2791. volatile scb_queue_type *queue)
  2792. {
  2793. int found;
  2794. unsigned char qinpos, qintail;
  2795. struct aic7xxx_scb *scbp;
  2796. found = 0;
  2797. qinpos = aic_inb(p, QINPOS);
  2798. qintail = p->qinfifonext;
  2799. p->qinfifonext = qinpos;
  2800. while (qinpos != qintail)
  2801. {
  2802. scbp = p->scb_data->scb_array[p->qinfifo[qinpos++]];
  2803. if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
  2804. {
  2805. /*
  2806. * We found an scb that needs to be removed.
  2807. */
  2808. if (requeue && (queue != NULL))
  2809. {
  2810. if (scbp->flags & SCB_WAITINGQ)
  2811. {
  2812. scbq_remove(queue, scbp);
  2813. scbq_remove(&p->waiting_scbs, scbp);
  2814. scbq_remove(&AIC_DEV(scbp->cmd)->delayed_scbs, scbp);
  2815. AIC_DEV(scbp->cmd)->active_cmds++;
  2816. p->activescbs++;
  2817. }
  2818. scbq_insert_tail(queue, scbp);
  2819. AIC_DEV(scbp->cmd)->active_cmds--;
  2820. p->activescbs--;
  2821. scbp->flags |= SCB_WAITINGQ;
  2822. if ( !(scbp->tag_action & TAG_ENB) )
  2823. {
  2824. aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
  2825. TRUE);
  2826. }
  2827. }
  2828. else if (requeue)
  2829. {
  2830. p->qinfifo[p->qinfifonext++] = scbp->hscb->tag;
  2831. }
  2832. else
  2833. {
  2834. /*
  2835. * Preserve any SCB_RECOVERY_SCB flags on this scb then set the
  2836. * flags we were called with, presumeably so aic7xxx_run_done_queue
  2837. * can find this scb
  2838. */
  2839. scbp->flags = flags | (scbp->flags & SCB_RECOVERY_SCB);
  2840. if (aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
  2841. FALSE) == scbp->hscb->tag)
  2842. {
  2843. aic7xxx_index_busy_target(p, scbp->hscb->target_channel_lun,
  2844. TRUE);
  2845. }
  2846. }
  2847. found++;
  2848. }
  2849. else
  2850. {
  2851. p->qinfifo[p->qinfifonext++] = scbp->hscb->tag;
  2852. }
  2853. }
  2854. /*
  2855. * Now that we've done the work, clear out any left over commands in the
  2856. * qinfifo and update the KERNEL_QINPOS down on the card.
  2857. *
  2858. * NOTE: This routine expect the sequencer to already be paused when
  2859. * it is run....make sure it's that way!
  2860. */
  2861. qinpos = p->qinfifonext;
  2862. while(qinpos != qintail)
  2863. {
  2864. p->qinfifo[qinpos++] = SCB_LIST_NULL;
  2865. }
  2866. if (p->features & AHC_QUEUE_REGS)
  2867. aic_outb(p, p->qinfifonext, HNSCB_QOFF);
  2868. else
  2869. aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
  2870. return (found);
  2871. }
  2872. /*+F*************************************************************************
  2873. * Function:
  2874. * aic7xxx_scb_on_qoutfifo
  2875. *
  2876. * Description:
  2877. * Is the scb that was passed to us currently on the qoutfifo?
  2878. *-F*************************************************************************/
  2879. static int
  2880. aic7xxx_scb_on_qoutfifo(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  2881. {
  2882. int i=0;
  2883. while(p->qoutfifo[(p->qoutfifonext + i) & 0xff ] != SCB_LIST_NULL)
  2884. {
  2885. if(p->qoutfifo[(p->qoutfifonext + i) & 0xff ] == scb->hscb->tag)
  2886. return TRUE;
  2887. else
  2888. i++;
  2889. }
  2890. return FALSE;
  2891. }
  2892. /*+F*************************************************************************
  2893. * Function:
  2894. * aic7xxx_reset_device
  2895. *
  2896. * Description:
  2897. * The device at the given target/channel has been reset. Abort
  2898. * all active and queued scbs for that target/channel. This function
  2899. * need not worry about linked next pointers because if was a MSG_ABORT_TAG
  2900. * then we had a tagged command (no linked next), if it was MSG_ABORT or
  2901. * MSG_BUS_DEV_RESET then the device won't know about any commands any more
  2902. * and no busy commands will exist, and if it was a bus reset, then nothing
  2903. * knows about any linked next commands any more. In all cases, we don't
  2904. * need to worry about the linked next or busy scb, we just need to clear
  2905. * them.
  2906. *-F*************************************************************************/
  2907. static void
  2908. aic7xxx_reset_device(struct aic7xxx_host *p, int target, int channel,
  2909. int lun, unsigned char tag)
  2910. {
  2911. struct aic7xxx_scb *scbp, *prev_scbp;
  2912. struct scsi_device *sd;
  2913. unsigned char active_scb, tcl, scb_tag;
  2914. int i = 0, init_lists = FALSE;
  2915. struct aic_dev_data *aic_dev;
  2916. /*
  2917. * Restore this when we're done
  2918. */
  2919. active_scb = aic_inb(p, SCBPTR);
  2920. scb_tag = aic_inb(p, SCB_TAG);
  2921. if (aic7xxx_verbose & (VERBOSE_RESET_PROCESS | VERBOSE_ABORT_PROCESS))
  2922. {
  2923. printk(INFO_LEAD "Reset device, hardware_scb %d,\n",
  2924. p->host_no, channel, target, lun, active_scb);
  2925. printk(INFO_LEAD "Current scb %d, SEQADDR 0x%x, LASTPHASE "
  2926. "0x%x\n",
  2927. p->host_no, channel, target, lun, scb_tag,
  2928. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  2929. aic_inb(p, LASTPHASE));
  2930. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SG_COUNT %d, SCSISIGI 0x%x\n",
  2931. p->host_no, channel, target, lun,
  2932. (p->features & AHC_ULTRA2) ? aic_inb(p, SG_CACHEPTR) : 0,
  2933. aic_inb(p, SG_COUNT), aic_inb(p, SCSISIGI));
  2934. printk(INFO_LEAD "SSTAT0 0x%x, SSTAT1 0x%x, SSTAT2 0x%x\n",
  2935. p->host_no, channel, target, lun, aic_inb(p, SSTAT0),
  2936. aic_inb(p, SSTAT1), aic_inb(p, SSTAT2));
  2937. }
  2938. /*
  2939. * Deal with the busy target and linked next issues.
  2940. */
  2941. list_for_each_entry(aic_dev, &p->aic_devs, list)
  2942. {
  2943. if (aic7xxx_verbose & (VERBOSE_RESET_PROCESS | VERBOSE_ABORT_PROCESS))
  2944. printk(INFO_LEAD "processing aic_dev %p\n", p->host_no, channel, target,
  2945. lun, aic_dev);
  2946. sd = aic_dev->SDptr;
  2947. if((target != ALL_TARGETS && target != sd->id) ||
  2948. (channel != ALL_CHANNELS && channel != sd->channel))
  2949. continue;
  2950. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  2951. printk(INFO_LEAD "Cleaning up status information "
  2952. "and delayed_scbs.\n", p->host_no, sd->channel, sd->id, sd->lun);
  2953. aic_dev->flags &= ~BUS_DEVICE_RESET_PENDING;
  2954. if ( tag == SCB_LIST_NULL )
  2955. {
  2956. aic_dev->dtr_pending = 0;
  2957. aic_dev->needppr = aic_dev->needppr_copy;
  2958. aic_dev->needsdtr = aic_dev->needsdtr_copy;
  2959. aic_dev->needwdtr = aic_dev->needwdtr_copy;
  2960. aic_dev->flags = DEVICE_PRINT_DTR;
  2961. aic_dev->temp_q_depth = aic_dev->max_q_depth;
  2962. }
  2963. tcl = (sd->id << 4) | (sd->channel << 3) | sd->lun;
  2964. if ( (aic7xxx_index_busy_target(p, tcl, FALSE) == tag) ||
  2965. (tag == SCB_LIST_NULL) )
  2966. aic7xxx_index_busy_target(p, tcl, /* unbusy */ TRUE);
  2967. prev_scbp = NULL;
  2968. scbp = aic_dev->delayed_scbs.head;
  2969. while (scbp != NULL)
  2970. {
  2971. prev_scbp = scbp;
  2972. scbp = scbp->q_next;
  2973. if (aic7xxx_match_scb(p, prev_scbp, target, channel, lun, tag))
  2974. {
  2975. scbq_remove(&aic_dev->delayed_scbs, prev_scbp);
  2976. if (prev_scbp->flags & SCB_WAITINGQ)
  2977. {
  2978. aic_dev->active_cmds++;
  2979. p->activescbs++;
  2980. }
  2981. prev_scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
  2982. prev_scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
  2983. }
  2984. }
  2985. }
  2986. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  2987. printk(INFO_LEAD "Cleaning QINFIFO.\n", p->host_no, channel, target, lun );
  2988. aic7xxx_search_qinfifo(p, target, channel, lun, tag,
  2989. SCB_RESET | SCB_QUEUED_FOR_DONE, /* requeue */ FALSE, NULL);
  2990. /*
  2991. * Search the waiting_scbs queue for matches, this catches any SCB_QUEUED
  2992. * ABORT/RESET commands.
  2993. */
  2994. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  2995. printk(INFO_LEAD "Cleaning waiting_scbs.\n", p->host_no, channel,
  2996. target, lun );
  2997. {
  2998. struct aic7xxx_scb *scbp, *prev_scbp;
  2999. prev_scbp = NULL;
  3000. scbp = p->waiting_scbs.head;
  3001. while (scbp != NULL)
  3002. {
  3003. prev_scbp = scbp;
  3004. scbp = scbp->q_next;
  3005. if (aic7xxx_match_scb(p, prev_scbp, target, channel, lun, tag))
  3006. {
  3007. scbq_remove(&p->waiting_scbs, prev_scbp);
  3008. if (prev_scbp->flags & SCB_WAITINGQ)
  3009. {
  3010. AIC_DEV(prev_scbp->cmd)->active_cmds++;
  3011. p->activescbs++;
  3012. }
  3013. prev_scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
  3014. prev_scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
  3015. }
  3016. }
  3017. }
  3018. /*
  3019. * Search waiting for selection list.
  3020. */
  3021. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  3022. printk(INFO_LEAD "Cleaning waiting for selection "
  3023. "list.\n", p->host_no, channel, target, lun);
  3024. {
  3025. unsigned char next, prev, scb_index;
  3026. next = aic_inb(p, WAITING_SCBH); /* Start at head of list. */
  3027. prev = SCB_LIST_NULL;
  3028. while (next != SCB_LIST_NULL)
  3029. {
  3030. aic_outb(p, next, SCBPTR);
  3031. scb_index = aic_inb(p, SCB_TAG);
  3032. if (scb_index >= p->scb_data->numscbs)
  3033. {
  3034. /*
  3035. * No aic7xxx_verbose check here.....we want to see this since it
  3036. * means either the kernel driver or the sequencer screwed things up
  3037. */
  3038. printk(WARN_LEAD "Waiting List inconsistency; SCB index=%d, "
  3039. "numscbs=%d\n", p->host_no, channel, target, lun, scb_index,
  3040. p->scb_data->numscbs);
  3041. next = aic_inb(p, SCB_NEXT);
  3042. aic7xxx_add_curscb_to_free_list(p);
  3043. }
  3044. else
  3045. {
  3046. scbp = p->scb_data->scb_array[scb_index];
  3047. if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
  3048. {
  3049. next = aic7xxx_abort_waiting_scb(p, scbp, next, prev);
  3050. if (scbp->flags & SCB_WAITINGQ)
  3051. {
  3052. AIC_DEV(scbp->cmd)->active_cmds++;
  3053. p->activescbs++;
  3054. }
  3055. scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
  3056. scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
  3057. if (prev == SCB_LIST_NULL)
  3058. {
  3059. /*
  3060. * This is either the first scb on the waiting list, or we
  3061. * have already yanked the first and haven't left any behind.
  3062. * Either way, we need to turn off the selection hardware if
  3063. * it isn't already off.
  3064. */
  3065. aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
  3066. aic_outb(p, CLRSELTIMEO, CLRSINT1);
  3067. }
  3068. }
  3069. else
  3070. {
  3071. prev = next;
  3072. next = aic_inb(p, SCB_NEXT);
  3073. }
  3074. }
  3075. }
  3076. }
  3077. /*
  3078. * Go through disconnected list and remove any entries we have queued
  3079. * for completion, zeroing their control byte too.
  3080. */
  3081. if (aic7xxx_verbose & (VERBOSE_ABORT_PROCESS | VERBOSE_RESET_PROCESS))
  3082. printk(INFO_LEAD "Cleaning disconnected scbs "
  3083. "list.\n", p->host_no, channel, target, lun);
  3084. if (p->flags & AHC_PAGESCBS)
  3085. {
  3086. unsigned char next, prev, scb_index;
  3087. next = aic_inb(p, DISCONNECTED_SCBH);
  3088. prev = SCB_LIST_NULL;
  3089. while (next != SCB_LIST_NULL)
  3090. {
  3091. aic_outb(p, next, SCBPTR);
  3092. scb_index = aic_inb(p, SCB_TAG);
  3093. if (scb_index > p->scb_data->numscbs)
  3094. {
  3095. printk(WARN_LEAD "Disconnected List inconsistency; SCB index=%d, "
  3096. "numscbs=%d\n", p->host_no, channel, target, lun, scb_index,
  3097. p->scb_data->numscbs);
  3098. next = aic7xxx_rem_scb_from_disc_list(p, next, prev);
  3099. }
  3100. else
  3101. {
  3102. scbp = p->scb_data->scb_array[scb_index];
  3103. if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
  3104. {
  3105. next = aic7xxx_rem_scb_from_disc_list(p, next, prev);
  3106. if (scbp->flags & SCB_WAITINGQ)
  3107. {
  3108. AIC_DEV(scbp->cmd)->active_cmds++;
  3109. p->activescbs++;
  3110. }
  3111. scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
  3112. scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
  3113. scbp->hscb->control = 0;
  3114. }
  3115. else
  3116. {
  3117. prev = next;
  3118. next = aic_inb(p, SCB_NEXT);
  3119. }
  3120. }
  3121. }
  3122. }
  3123. /*
  3124. * Walk the free list making sure no entries on the free list have
  3125. * a valid SCB_TAG value or SCB_CONTROL byte.
  3126. */
  3127. if (p->flags & AHC_PAGESCBS)
  3128. {
  3129. unsigned char next;
  3130. next = aic_inb(p, FREE_SCBH);
  3131. while (next != SCB_LIST_NULL)
  3132. {
  3133. aic_outb(p, next, SCBPTR);
  3134. if (aic_inb(p, SCB_TAG) < p->scb_data->numscbs)
  3135. {
  3136. printk(WARN_LEAD "Free list inconsistency!.\n", p->host_no, channel,
  3137. target, lun);
  3138. init_lists = TRUE;
  3139. next = SCB_LIST_NULL;
  3140. }
  3141. else
  3142. {
  3143. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  3144. aic_outb(p, 0, SCB_CONTROL);
  3145. next = aic_inb(p, SCB_NEXT);
  3146. }
  3147. }
  3148. }
  3149. /*
  3150. * Go through the hardware SCB array looking for commands that
  3151. * were active but not on any list.
  3152. */
  3153. if (init_lists)
  3154. {
  3155. aic_outb(p, SCB_LIST_NULL, FREE_SCBH);
  3156. aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
  3157. aic_outb(p, SCB_LIST_NULL, DISCONNECTED_SCBH);
  3158. }
  3159. for (i = p->scb_data->maxhscbs - 1; i >= 0; i--)
  3160. {
  3161. unsigned char scbid;
  3162. aic_outb(p, i, SCBPTR);
  3163. if (init_lists)
  3164. {
  3165. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  3166. aic_outb(p, SCB_LIST_NULL, SCB_NEXT);
  3167. aic_outb(p, 0, SCB_CONTROL);
  3168. aic7xxx_add_curscb_to_free_list(p);
  3169. }
  3170. else
  3171. {
  3172. scbid = aic_inb(p, SCB_TAG);
  3173. if (scbid < p->scb_data->numscbs)
  3174. {
  3175. scbp = p->scb_data->scb_array[scbid];
  3176. if (aic7xxx_match_scb(p, scbp, target, channel, lun, tag))
  3177. {
  3178. aic_outb(p, 0, SCB_CONTROL);
  3179. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  3180. aic7xxx_add_curscb_to_free_list(p);
  3181. }
  3182. }
  3183. }
  3184. }
  3185. /*
  3186. * Go through the entire SCB array now and look for commands for
  3187. * for this target that are stillactive. These are other (most likely
  3188. * tagged) commands that were disconnected when the reset occurred.
  3189. * Any commands we find here we know this about, it wasn't on any queue,
  3190. * it wasn't in the qinfifo, it wasn't in the disconnected or waiting
  3191. * lists, so it really must have been a paged out SCB. In that case,
  3192. * we shouldn't need to bother with updating any counters, just mark
  3193. * the correct flags and go on.
  3194. */
  3195. for (i = 0; i < p->scb_data->numscbs; i++)
  3196. {
  3197. scbp = p->scb_data->scb_array[i];
  3198. if ((scbp->flags & SCB_ACTIVE) &&
  3199. aic7xxx_match_scb(p, scbp, target, channel, lun, tag) &&
  3200. !aic7xxx_scb_on_qoutfifo(p, scbp))
  3201. {
  3202. if (scbp->flags & SCB_WAITINGQ)
  3203. {
  3204. scbq_remove(&p->waiting_scbs, scbp);
  3205. scbq_remove(&AIC_DEV(scbp->cmd)->delayed_scbs, scbp);
  3206. AIC_DEV(scbp->cmd)->active_cmds++;
  3207. p->activescbs++;
  3208. }
  3209. scbp->flags |= SCB_RESET | SCB_QUEUED_FOR_DONE;
  3210. scbp->flags &= ~(SCB_ACTIVE | SCB_WAITINGQ);
  3211. }
  3212. }
  3213. aic_outb(p, active_scb, SCBPTR);
  3214. }
  3215. /*+F*************************************************************************
  3216. * Function:
  3217. * aic7xxx_clear_intstat
  3218. *
  3219. * Description:
  3220. * Clears the interrupt status.
  3221. *-F*************************************************************************/
  3222. static void
  3223. aic7xxx_clear_intstat(struct aic7xxx_host *p)
  3224. {
  3225. /* Clear any interrupt conditions this may have caused. */
  3226. aic_outb(p, CLRSELDO | CLRSELDI | CLRSELINGO, CLRSINT0);
  3227. aic_outb(p, CLRSELTIMEO | CLRATNO | CLRSCSIRSTI | CLRBUSFREE | CLRSCSIPERR |
  3228. CLRPHASECHG | CLRREQINIT, CLRSINT1);
  3229. aic_outb(p, CLRSCSIINT | CLRSEQINT | CLRBRKADRINT | CLRPARERR, CLRINT);
  3230. }
  3231. /*+F*************************************************************************
  3232. * Function:
  3233. * aic7xxx_reset_current_bus
  3234. *
  3235. * Description:
  3236. * Reset the current SCSI bus.
  3237. *-F*************************************************************************/
  3238. static void
  3239. aic7xxx_reset_current_bus(struct aic7xxx_host *p)
  3240. {
  3241. /* Disable reset interrupts. */
  3242. aic_outb(p, aic_inb(p, SIMODE1) & ~ENSCSIRST, SIMODE1);
  3243. /* Turn off the bus' current operations, after all, we shouldn't have any
  3244. * valid commands left to cause a RSELI and SELO once we've tossed the
  3245. * bus away with this reset, so we might as well shut down the sequencer
  3246. * until the bus is restarted as oppossed to saving the current settings
  3247. * and restoring them (which makes no sense to me). */
  3248. /* Turn on the bus reset. */
  3249. aic_outb(p, aic_inb(p, SCSISEQ) | SCSIRSTO, SCSISEQ);
  3250. while ( (aic_inb(p, SCSISEQ) & SCSIRSTO) == 0)
  3251. mdelay(5);
  3252. /*
  3253. * Some of the new Ultra2 chipsets need a longer delay after a chip
  3254. * reset than just the init setup creates, so we have to delay here
  3255. * before we go into a reset in order to make the chips happy.
  3256. */
  3257. if (p->features & AHC_ULTRA2)
  3258. mdelay(250);
  3259. else
  3260. mdelay(50);
  3261. /* Turn off the bus reset. */
  3262. aic_outb(p, 0, SCSISEQ);
  3263. mdelay(10);
  3264. aic7xxx_clear_intstat(p);
  3265. /* Re-enable reset interrupts. */
  3266. aic_outb(p, aic_inb(p, SIMODE1) | ENSCSIRST, SIMODE1);
  3267. }
  3268. /*+F*************************************************************************
  3269. * Function:
  3270. * aic7xxx_reset_channel
  3271. *
  3272. * Description:
  3273. * Reset the channel.
  3274. *-F*************************************************************************/
  3275. static void
  3276. aic7xxx_reset_channel(struct aic7xxx_host *p, int channel, int initiate_reset)
  3277. {
  3278. unsigned long offset_min, offset_max;
  3279. unsigned char sblkctl;
  3280. int cur_channel;
  3281. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  3282. printk(INFO_LEAD "Reset channel called, %s initiate reset.\n",
  3283. p->host_no, channel, -1, -1, (initiate_reset==TRUE) ? "will" : "won't" );
  3284. if (channel == 1)
  3285. {
  3286. offset_min = 8;
  3287. offset_max = 16;
  3288. }
  3289. else
  3290. {
  3291. if (p->features & AHC_TWIN)
  3292. {
  3293. /* Channel A */
  3294. offset_min = 0;
  3295. offset_max = 8;
  3296. }
  3297. else
  3298. {
  3299. offset_min = 0;
  3300. if (p->features & AHC_WIDE)
  3301. {
  3302. offset_max = 16;
  3303. }
  3304. else
  3305. {
  3306. offset_max = 8;
  3307. }
  3308. }
  3309. }
  3310. while (offset_min < offset_max)
  3311. {
  3312. /*
  3313. * Revert to async/narrow transfers until we renegotiate.
  3314. */
  3315. aic_outb(p, 0, TARG_SCSIRATE + offset_min);
  3316. if (p->features & AHC_ULTRA2)
  3317. {
  3318. aic_outb(p, 0, TARG_OFFSET + offset_min);
  3319. }
  3320. offset_min++;
  3321. }
  3322. /*
  3323. * Reset the bus and unpause/restart the controller
  3324. */
  3325. sblkctl = aic_inb(p, SBLKCTL);
  3326. if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
  3327. cur_channel = (sblkctl & SELBUSB) >> 3;
  3328. else
  3329. cur_channel = 0;
  3330. if ( (cur_channel != channel) && (p->features & AHC_TWIN) )
  3331. {
  3332. /*
  3333. * Case 1: Command for another bus is active
  3334. */
  3335. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  3336. printk(INFO_LEAD "Stealthily resetting idle channel.\n", p->host_no,
  3337. channel, -1, -1);
  3338. /*
  3339. * Stealthily reset the other bus without upsetting the current bus.
  3340. */
  3341. aic_outb(p, sblkctl ^ SELBUSB, SBLKCTL);
  3342. aic_outb(p, aic_inb(p, SIMODE1) & ~ENBUSFREE, SIMODE1);
  3343. if (initiate_reset)
  3344. {
  3345. aic7xxx_reset_current_bus(p);
  3346. }
  3347. aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP), SCSISEQ);
  3348. aic7xxx_clear_intstat(p);
  3349. aic_outb(p, sblkctl, SBLKCTL);
  3350. }
  3351. else
  3352. {
  3353. /*
  3354. * Case 2: A command from this bus is active or we're idle.
  3355. */
  3356. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  3357. printk(INFO_LEAD "Resetting currently active channel.\n", p->host_no,
  3358. channel, -1, -1);
  3359. aic_outb(p, aic_inb(p, SIMODE1) & ~(ENBUSFREE|ENREQINIT),
  3360. SIMODE1);
  3361. p->flags &= ~AHC_HANDLING_REQINITS;
  3362. p->msg_type = MSG_TYPE_NONE;
  3363. p->msg_len = 0;
  3364. if (initiate_reset)
  3365. {
  3366. aic7xxx_reset_current_bus(p);
  3367. }
  3368. aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP), SCSISEQ);
  3369. aic7xxx_clear_intstat(p);
  3370. }
  3371. if (aic7xxx_verbose & VERBOSE_RESET_RETURN)
  3372. printk(INFO_LEAD "Channel reset\n", p->host_no, channel, -1, -1);
  3373. /*
  3374. * Clean up all the state information for the pending transactions
  3375. * on this bus.
  3376. */
  3377. aic7xxx_reset_device(p, ALL_TARGETS, channel, ALL_LUNS, SCB_LIST_NULL);
  3378. if ( !(p->features & AHC_TWIN) )
  3379. {
  3380. restart_sequencer(p);
  3381. }
  3382. return;
  3383. }
  3384. /*+F*************************************************************************
  3385. * Function:
  3386. * aic7xxx_run_waiting_queues
  3387. *
  3388. * Description:
  3389. * Scan the awaiting_scbs queue downloading and starting as many
  3390. * scbs as we can.
  3391. *-F*************************************************************************/
  3392. static void
  3393. aic7xxx_run_waiting_queues(struct aic7xxx_host *p)
  3394. {
  3395. struct aic7xxx_scb *scb;
  3396. struct aic_dev_data *aic_dev;
  3397. int sent;
  3398. if (p->waiting_scbs.head == NULL)
  3399. return;
  3400. sent = 0;
  3401. /*
  3402. * First handle SCBs that are waiting but have been assigned a slot.
  3403. */
  3404. while ((scb = scbq_remove_head(&p->waiting_scbs)) != NULL)
  3405. {
  3406. aic_dev = scb->cmd->device->hostdata;
  3407. if ( !scb->tag_action )
  3408. {
  3409. aic_dev->temp_q_depth = 1;
  3410. }
  3411. if ( aic_dev->active_cmds >= aic_dev->temp_q_depth)
  3412. {
  3413. scbq_insert_tail(&aic_dev->delayed_scbs, scb);
  3414. }
  3415. else
  3416. {
  3417. scb->flags &= ~SCB_WAITINGQ;
  3418. aic_dev->active_cmds++;
  3419. p->activescbs++;
  3420. if ( !(scb->tag_action) )
  3421. {
  3422. aic7xxx_busy_target(p, scb);
  3423. }
  3424. p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
  3425. sent++;
  3426. }
  3427. }
  3428. if (sent)
  3429. {
  3430. if (p->features & AHC_QUEUE_REGS)
  3431. aic_outb(p, p->qinfifonext, HNSCB_QOFF);
  3432. else
  3433. {
  3434. pause_sequencer(p);
  3435. aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
  3436. unpause_sequencer(p, FALSE);
  3437. }
  3438. if (p->activescbs > p->max_activescbs)
  3439. p->max_activescbs = p->activescbs;
  3440. }
  3441. }
  3442. #ifdef CONFIG_PCI
  3443. #define DPE 0x80
  3444. #define SSE 0x40
  3445. #define RMA 0x20
  3446. #define RTA 0x10
  3447. #define STA 0x08
  3448. #define DPR 0x01
  3449. /*+F*************************************************************************
  3450. * Function:
  3451. * aic7xxx_pci_intr
  3452. *
  3453. * Description:
  3454. * Check the scsi card for PCI errors and clear the interrupt
  3455. *
  3456. * NOTE: If you don't have this function and a 2940 card encounters
  3457. * a PCI error condition, the machine will end up locked as the
  3458. * interrupt handler gets slammed with non-stop PCI error interrupts
  3459. *-F*************************************************************************/
  3460. static void
  3461. aic7xxx_pci_intr(struct aic7xxx_host *p)
  3462. {
  3463. unsigned char status1;
  3464. pci_read_config_byte(p->pdev, PCI_STATUS + 1, &status1);
  3465. if ( (status1 & DPE) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3466. printk(WARN_LEAD "Data Parity Error during PCI address or PCI write"
  3467. "phase.\n", p->host_no, -1, -1, -1);
  3468. if ( (status1 & SSE) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3469. printk(WARN_LEAD "Signal System Error Detected\n", p->host_no,
  3470. -1, -1, -1);
  3471. if ( (status1 & RMA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3472. printk(WARN_LEAD "Received a PCI Master Abort\n", p->host_no,
  3473. -1, -1, -1);
  3474. if ( (status1 & RTA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3475. printk(WARN_LEAD "Received a PCI Target Abort\n", p->host_no,
  3476. -1, -1, -1);
  3477. if ( (status1 & STA) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3478. printk(WARN_LEAD "Signaled a PCI Target Abort\n", p->host_no,
  3479. -1, -1, -1);
  3480. if ( (status1 & DPR) && (aic7xxx_verbose & VERBOSE_MINOR_ERROR) )
  3481. printk(WARN_LEAD "Data Parity Error has been reported via PCI pin "
  3482. "PERR#\n", p->host_no, -1, -1, -1);
  3483. pci_write_config_byte(p->pdev, PCI_STATUS + 1, status1);
  3484. if (status1 & (DPR|RMA|RTA))
  3485. aic_outb(p, CLRPARERR, CLRINT);
  3486. if ( (aic7xxx_panic_on_abort) && (p->spurious_int > 500) )
  3487. aic7xxx_panic_abort(p, NULL);
  3488. }
  3489. #endif /* CONFIG_PCI */
  3490. /*+F*************************************************************************
  3491. * Function:
  3492. * aic7xxx_construct_ppr
  3493. *
  3494. * Description:
  3495. * Build up a Parallel Protocol Request message for use with SCSI-3
  3496. * devices.
  3497. *-F*************************************************************************/
  3498. static void
  3499. aic7xxx_construct_ppr(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  3500. {
  3501. p->msg_buf[p->msg_index++] = MSG_EXTENDED;
  3502. p->msg_buf[p->msg_index++] = MSG_EXT_PPR_LEN;
  3503. p->msg_buf[p->msg_index++] = MSG_EXT_PPR;
  3504. p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.period;
  3505. p->msg_buf[p->msg_index++] = 0;
  3506. p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.offset;
  3507. p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.width;
  3508. p->msg_buf[p->msg_index++] = AIC_DEV(scb->cmd)->goal.options;
  3509. p->msg_len += 8;
  3510. }
  3511. /*+F*************************************************************************
  3512. * Function:
  3513. * aic7xxx_construct_sdtr
  3514. *
  3515. * Description:
  3516. * Constucts a synchronous data transfer message in the message
  3517. * buffer on the sequencer.
  3518. *-F*************************************************************************/
  3519. static void
  3520. aic7xxx_construct_sdtr(struct aic7xxx_host *p, unsigned char period,
  3521. unsigned char offset)
  3522. {
  3523. p->msg_buf[p->msg_index++] = MSG_EXTENDED;
  3524. p->msg_buf[p->msg_index++] = MSG_EXT_SDTR_LEN;
  3525. p->msg_buf[p->msg_index++] = MSG_EXT_SDTR;
  3526. p->msg_buf[p->msg_index++] = period;
  3527. p->msg_buf[p->msg_index++] = offset;
  3528. p->msg_len += 5;
  3529. }
  3530. /*+F*************************************************************************
  3531. * Function:
  3532. * aic7xxx_construct_wdtr
  3533. *
  3534. * Description:
  3535. * Constucts a wide data transfer message in the message buffer
  3536. * on the sequencer.
  3537. *-F*************************************************************************/
  3538. static void
  3539. aic7xxx_construct_wdtr(struct aic7xxx_host *p, unsigned char bus_width)
  3540. {
  3541. p->msg_buf[p->msg_index++] = MSG_EXTENDED;
  3542. p->msg_buf[p->msg_index++] = MSG_EXT_WDTR_LEN;
  3543. p->msg_buf[p->msg_index++] = MSG_EXT_WDTR;
  3544. p->msg_buf[p->msg_index++] = bus_width;
  3545. p->msg_len += 4;
  3546. }
  3547. /*+F*************************************************************************
  3548. * Function:
  3549. * aic7xxx_calc_residual
  3550. *
  3551. * Description:
  3552. * Calculate the residual data not yet transferred.
  3553. *-F*************************************************************************/
  3554. static void
  3555. aic7xxx_calculate_residual (struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  3556. {
  3557. struct aic7xxx_hwscb *hscb;
  3558. struct scsi_cmnd *cmd;
  3559. int actual, i;
  3560. cmd = scb->cmd;
  3561. hscb = scb->hscb;
  3562. /*
  3563. * Don't destroy valid residual information with
  3564. * residual coming from a check sense operation.
  3565. */
  3566. if (((scb->hscb->control & DISCONNECTED) == 0) &&
  3567. (scb->flags & SCB_SENSE) == 0)
  3568. {
  3569. /*
  3570. * We had an underflow. At this time, there's only
  3571. * one other driver that bothers to check for this,
  3572. * and cmd->underflow seems to be set rather half-
  3573. * heartedly in the higher-level SCSI code.
  3574. */
  3575. actual = scb->sg_length;
  3576. for (i=1; i < hscb->residual_SG_segment_count; i++)
  3577. {
  3578. actual -= scb->sg_list[scb->sg_count - i].length;
  3579. }
  3580. actual -= (hscb->residual_data_count[2] << 16) |
  3581. (hscb->residual_data_count[1] << 8) |
  3582. hscb->residual_data_count[0];
  3583. if (actual < cmd->underflow)
  3584. {
  3585. if (aic7xxx_verbose & VERBOSE_MINOR_ERROR)
  3586. {
  3587. printk(INFO_LEAD "Underflow - Wanted %u, %s %u, residual SG "
  3588. "count %d.\n", p->host_no, CTL_OF_SCB(scb), cmd->underflow,
  3589. (rq_data_dir(cmd->request) == WRITE) ? "wrote" : "read", actual,
  3590. hscb->residual_SG_segment_count);
  3591. printk(INFO_LEAD "status 0x%x.\n", p->host_no, CTL_OF_SCB(scb),
  3592. hscb->target_status);
  3593. }
  3594. /*
  3595. * In 2.4, only send back the residual information, don't flag this
  3596. * as an error. Before 2.4 we had to flag this as an error because
  3597. * the mid layer didn't check residual data counts to see if the
  3598. * command needs retried.
  3599. */
  3600. cmd->resid = scb->sg_length - actual;
  3601. aic7xxx_status(cmd) = hscb->target_status;
  3602. }
  3603. }
  3604. /*
  3605. * Clean out the residual information in the SCB for the
  3606. * next consumer.
  3607. */
  3608. hscb->residual_data_count[2] = 0;
  3609. hscb->residual_data_count[1] = 0;
  3610. hscb->residual_data_count[0] = 0;
  3611. hscb->residual_SG_segment_count = 0;
  3612. }
  3613. /*+F*************************************************************************
  3614. * Function:
  3615. * aic7xxx_handle_device_reset
  3616. *
  3617. * Description:
  3618. * Interrupt handler for sequencer interrupts (SEQINT).
  3619. *-F*************************************************************************/
  3620. static void
  3621. aic7xxx_handle_device_reset(struct aic7xxx_host *p, int target, int channel)
  3622. {
  3623. unsigned char tindex = target;
  3624. tindex |= ((channel & 0x01) << 3);
  3625. /*
  3626. * Go back to async/narrow transfers and renegotiate.
  3627. */
  3628. aic_outb(p, 0, TARG_SCSIRATE + tindex);
  3629. if (p->features & AHC_ULTRA2)
  3630. aic_outb(p, 0, TARG_OFFSET + tindex);
  3631. aic7xxx_reset_device(p, target, channel, ALL_LUNS, SCB_LIST_NULL);
  3632. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  3633. printk(INFO_LEAD "Bus Device Reset delivered.\n", p->host_no, channel,
  3634. target, -1);
  3635. aic7xxx_run_done_queue(p, /*complete*/ TRUE);
  3636. }
  3637. /*+F*************************************************************************
  3638. * Function:
  3639. * aic7xxx_handle_seqint
  3640. *
  3641. * Description:
  3642. * Interrupt handler for sequencer interrupts (SEQINT).
  3643. *-F*************************************************************************/
  3644. static void
  3645. aic7xxx_handle_seqint(struct aic7xxx_host *p, unsigned char intstat)
  3646. {
  3647. struct aic7xxx_scb *scb;
  3648. struct aic_dev_data *aic_dev;
  3649. unsigned short target_mask;
  3650. unsigned char target, lun, tindex;
  3651. unsigned char queue_flag = FALSE;
  3652. char channel;
  3653. int result;
  3654. target = ((aic_inb(p, SAVED_TCL) >> 4) & 0x0f);
  3655. if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
  3656. channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
  3657. else
  3658. channel = 0;
  3659. tindex = target + (channel << 3);
  3660. lun = aic_inb(p, SAVED_TCL) & 0x07;
  3661. target_mask = (0x01 << tindex);
  3662. /*
  3663. * Go ahead and clear the SEQINT now, that avoids any interrupt race
  3664. * conditions later on in case we enable some other interrupt.
  3665. */
  3666. aic_outb(p, CLRSEQINT, CLRINT);
  3667. switch (intstat & SEQINT_MASK)
  3668. {
  3669. case NO_MATCH:
  3670. {
  3671. aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP),
  3672. SCSISEQ);
  3673. printk(WARN_LEAD "No active SCB for reconnecting target - Issuing "
  3674. "BUS DEVICE RESET.\n", p->host_no, channel, target, lun);
  3675. printk(WARN_LEAD " SAVED_TCL=0x%x, ARG_1=0x%x, SEQADDR=0x%x\n",
  3676. p->host_no, channel, target, lun,
  3677. aic_inb(p, SAVED_TCL), aic_inb(p, ARG_1),
  3678. (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
  3679. if (aic7xxx_panic_on_abort)
  3680. aic7xxx_panic_abort(p, NULL);
  3681. }
  3682. break;
  3683. case SEND_REJECT:
  3684. {
  3685. if (aic7xxx_verbose & VERBOSE_MINOR_ERROR)
  3686. printk(INFO_LEAD "Rejecting unknown message (0x%x) received from "
  3687. "target, SEQ_FLAGS=0x%x\n", p->host_no, channel, target, lun,
  3688. aic_inb(p, ACCUM), aic_inb(p, SEQ_FLAGS));
  3689. }
  3690. break;
  3691. case NO_IDENT:
  3692. {
  3693. /*
  3694. * The reconnecting target either did not send an identify
  3695. * message, or did, but we didn't find an SCB to match and
  3696. * before it could respond to our ATN/abort, it hit a dataphase.
  3697. * The only safe thing to do is to blow it away with a bus
  3698. * reset.
  3699. */
  3700. if (aic7xxx_verbose & (VERBOSE_SEQINT | VERBOSE_RESET_MID))
  3701. printk(INFO_LEAD "Target did not send an IDENTIFY message; "
  3702. "LASTPHASE 0x%x, SAVED_TCL 0x%x\n", p->host_no, channel, target,
  3703. lun, aic_inb(p, LASTPHASE), aic_inb(p, SAVED_TCL));
  3704. aic7xxx_reset_channel(p, channel, /*initiate reset*/ TRUE);
  3705. aic7xxx_run_done_queue(p, TRUE);
  3706. }
  3707. break;
  3708. case BAD_PHASE:
  3709. if (aic_inb(p, LASTPHASE) == P_BUSFREE)
  3710. {
  3711. if (aic7xxx_verbose & VERBOSE_SEQINT)
  3712. printk(INFO_LEAD "Missed busfree.\n", p->host_no, channel,
  3713. target, lun);
  3714. restart_sequencer(p);
  3715. }
  3716. else
  3717. {
  3718. if (aic7xxx_verbose & VERBOSE_SEQINT)
  3719. printk(INFO_LEAD "Unknown scsi bus phase, continuing\n", p->host_no,
  3720. channel, target, lun);
  3721. }
  3722. break;
  3723. case EXTENDED_MSG:
  3724. {
  3725. p->msg_type = MSG_TYPE_INITIATOR_MSGIN;
  3726. p->msg_len = 0;
  3727. p->msg_index = 0;
  3728. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  3729. if (aic7xxx_verbose > 0xffff)
  3730. printk(INFO_LEAD "Enabling REQINITs for MSG_IN\n", p->host_no,
  3731. channel, target, lun);
  3732. #endif
  3733. /*
  3734. * To actually receive the message, simply turn on
  3735. * REQINIT interrupts and let our interrupt handler
  3736. * do the rest (REQINIT should already be true).
  3737. */
  3738. p->flags |= AHC_HANDLING_REQINITS;
  3739. aic_outb(p, aic_inb(p, SIMODE1) | ENREQINIT, SIMODE1);
  3740. /*
  3741. * We don't want the sequencer unpaused yet so we return early
  3742. */
  3743. return;
  3744. }
  3745. case REJECT_MSG:
  3746. {
  3747. /*
  3748. * What we care about here is if we had an outstanding SDTR
  3749. * or WDTR message for this target. If we did, this is a
  3750. * signal that the target is refusing negotiation.
  3751. */
  3752. unsigned char scb_index;
  3753. unsigned char last_msg;
  3754. scb_index = aic_inb(p, SCB_TAG);
  3755. scb = p->scb_data->scb_array[scb_index];
  3756. aic_dev = AIC_DEV(scb->cmd);
  3757. last_msg = aic_inb(p, LAST_MSG);
  3758. if ( (last_msg == MSG_IDENTIFYFLAG) &&
  3759. (scb->tag_action) &&
  3760. !(scb->flags & SCB_MSGOUT_BITS) )
  3761. {
  3762. if (scb->tag_action == MSG_ORDERED_Q_TAG)
  3763. {
  3764. /*
  3765. * OK...the device seems able to accept tagged commands, but
  3766. * not ordered tag commands, only simple tag commands. So, we
  3767. * disable ordered tag commands and go on with life just like
  3768. * normal.
  3769. */
  3770. scsi_adjust_queue_depth(scb->cmd->device, MSG_SIMPLE_TAG,
  3771. scb->cmd->device->queue_depth);
  3772. scb->tag_action = MSG_SIMPLE_Q_TAG;
  3773. scb->hscb->control &= ~SCB_TAG_TYPE;
  3774. scb->hscb->control |= MSG_SIMPLE_Q_TAG;
  3775. aic_outb(p, scb->hscb->control, SCB_CONTROL);
  3776. /*
  3777. * OK..we set the tag type to simple tag command, now we re-assert
  3778. * ATNO and hope this will take us into the identify phase again
  3779. * so we can resend the tag type and info to the device.
  3780. */
  3781. aic_outb(p, MSG_IDENTIFYFLAG, MSG_OUT);
  3782. aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
  3783. }
  3784. else if (scb->tag_action == MSG_SIMPLE_Q_TAG)
  3785. {
  3786. unsigned char i;
  3787. struct aic7xxx_scb *scbp;
  3788. int old_verbose;
  3789. /*
  3790. * Hmmmm....the device is flaking out on tagged commands.
  3791. */
  3792. scsi_adjust_queue_depth(scb->cmd->device, 0 /* untagged */,
  3793. p->host->cmd_per_lun);
  3794. aic_dev->max_q_depth = aic_dev->temp_q_depth = 1;
  3795. /*
  3796. * We set this command up as a bus device reset. However, we have
  3797. * to clear the tag type as it's causing us problems. We shouldnt
  3798. * have to worry about any other commands being active, since if
  3799. * the device is refusing tagged commands, this should be the
  3800. * first tagged command sent to the device, however, we do have
  3801. * to worry about any other tagged commands that may already be
  3802. * in the qinfifo. The easiest way to do this, is to issue a BDR,
  3803. * send all the commands back to the mid level code, then let them
  3804. * come back and get rebuilt as untagged commands.
  3805. */
  3806. scb->tag_action = 0;
  3807. scb->hscb->control &= ~(TAG_ENB | SCB_TAG_TYPE);
  3808. aic_outb(p, scb->hscb->control, SCB_CONTROL);
  3809. old_verbose = aic7xxx_verbose;
  3810. aic7xxx_verbose &= ~(VERBOSE_RESET|VERBOSE_ABORT);
  3811. for (i=0; i < p->scb_data->numscbs; i++)
  3812. {
  3813. scbp = p->scb_data->scb_array[i];
  3814. if ((scbp->flags & SCB_ACTIVE) && (scbp != scb))
  3815. {
  3816. if (aic7xxx_match_scb(p, scbp, target, channel, lun, i))
  3817. {
  3818. aic7xxx_reset_device(p, target, channel, lun, i);
  3819. }
  3820. }
  3821. }
  3822. aic7xxx_run_done_queue(p, TRUE);
  3823. aic7xxx_verbose = old_verbose;
  3824. /*
  3825. * Wait until after the for loop to set the busy index since
  3826. * aic7xxx_reset_device will clear the busy index during its
  3827. * operation.
  3828. */
  3829. aic7xxx_busy_target(p, scb);
  3830. printk(INFO_LEAD "Device is refusing tagged commands, using "
  3831. "untagged I/O.\n", p->host_no, channel, target, lun);
  3832. aic_outb(p, MSG_IDENTIFYFLAG, MSG_OUT);
  3833. aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
  3834. }
  3835. }
  3836. else if (scb->flags & SCB_MSGOUT_PPR)
  3837. {
  3838. /*
  3839. * As per the draft specs, any device capable of supporting any of
  3840. * the option values other than 0 are not allowed to reject the
  3841. * PPR message. Instead, they must negotiate out what they do
  3842. * support instead of rejecting our offering or else they cause
  3843. * a parity error during msg_out phase to signal that they don't
  3844. * like our settings.
  3845. */
  3846. aic_dev->needppr = aic_dev->needppr_copy = 0;
  3847. aic7xxx_set_width(p, target, channel, lun, MSG_EXT_WDTR_BUS_8_BIT,
  3848. (AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE), aic_dev);
  3849. aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
  3850. AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
  3851. aic_dev);
  3852. aic_dev->goal.options = aic_dev->dtr_pending = 0;
  3853. scb->flags &= ~SCB_MSGOUT_BITS;
  3854. if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  3855. {
  3856. printk(INFO_LEAD "Device is rejecting PPR messages, falling "
  3857. "back.\n", p->host_no, channel, target, lun);
  3858. }
  3859. if ( aic_dev->goal.width )
  3860. {
  3861. aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
  3862. aic_dev->dtr_pending = 1;
  3863. scb->flags |= SCB_MSGOUT_WDTR;
  3864. }
  3865. if ( aic_dev->goal.offset )
  3866. {
  3867. aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
  3868. if( !aic_dev->dtr_pending )
  3869. {
  3870. aic_dev->dtr_pending = 1;
  3871. scb->flags |= SCB_MSGOUT_SDTR;
  3872. }
  3873. }
  3874. if ( aic_dev->dtr_pending )
  3875. {
  3876. aic_outb(p, HOST_MSG, MSG_OUT);
  3877. aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
  3878. }
  3879. }
  3880. else if (scb->flags & SCB_MSGOUT_WDTR)
  3881. {
  3882. /*
  3883. * note 8bit xfers and clear flag
  3884. */
  3885. aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
  3886. scb->flags &= ~SCB_MSGOUT_BITS;
  3887. aic7xxx_set_width(p, target, channel, lun, MSG_EXT_WDTR_BUS_8_BIT,
  3888. (AHC_TRANS_ACTIVE|AHC_TRANS_GOAL|AHC_TRANS_CUR), aic_dev);
  3889. aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
  3890. AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
  3891. aic_dev);
  3892. if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  3893. {
  3894. printk(INFO_LEAD "Device is rejecting WDTR messages, using "
  3895. "narrow transfers.\n", p->host_no, channel, target, lun);
  3896. }
  3897. aic_dev->needsdtr = aic_dev->needsdtr_copy;
  3898. }
  3899. else if (scb->flags & SCB_MSGOUT_SDTR)
  3900. {
  3901. /*
  3902. * note asynch xfers and clear flag
  3903. */
  3904. aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
  3905. scb->flags &= ~SCB_MSGOUT_BITS;
  3906. aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
  3907. (AHC_TRANS_CUR|AHC_TRANS_ACTIVE|AHC_TRANS_GOAL), aic_dev);
  3908. if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  3909. {
  3910. printk(INFO_LEAD "Device is rejecting SDTR messages, using "
  3911. "async transfers.\n", p->host_no, channel, target, lun);
  3912. }
  3913. }
  3914. else if (aic7xxx_verbose & VERBOSE_SEQINT)
  3915. {
  3916. /*
  3917. * Otherwise, we ignore it.
  3918. */
  3919. printk(INFO_LEAD "Received MESSAGE_REJECT for unknown cause. "
  3920. "Ignoring.\n", p->host_no, channel, target, lun);
  3921. }
  3922. }
  3923. break;
  3924. case BAD_STATUS:
  3925. {
  3926. unsigned char scb_index;
  3927. struct aic7xxx_hwscb *hscb;
  3928. struct scsi_cmnd *cmd;
  3929. /* The sequencer will notify us when a command has an error that
  3930. * would be of interest to the kernel. This allows us to leave
  3931. * the sequencer running in the common case of command completes
  3932. * without error. The sequencer will have DMA'd the SCB back
  3933. * up to us, so we can reference the drivers SCB array.
  3934. *
  3935. * Set the default return value to 0 indicating not to send
  3936. * sense. The sense code will change this if needed and this
  3937. * reduces code duplication.
  3938. */
  3939. aic_outb(p, 0, RETURN_1);
  3940. scb_index = aic_inb(p, SCB_TAG);
  3941. if (scb_index > p->scb_data->numscbs)
  3942. {
  3943. printk(WARN_LEAD "Invalid SCB during SEQINT 0x%02x, SCB_TAG %d.\n",
  3944. p->host_no, channel, target, lun, intstat, scb_index);
  3945. break;
  3946. }
  3947. scb = p->scb_data->scb_array[scb_index];
  3948. hscb = scb->hscb;
  3949. if (!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
  3950. {
  3951. printk(WARN_LEAD "Invalid SCB during SEQINT 0x%x, scb %d, flags 0x%x,"
  3952. " cmd 0x%lx.\n", p->host_no, channel, target, lun, intstat,
  3953. scb_index, scb->flags, (unsigned long) scb->cmd);
  3954. }
  3955. else
  3956. {
  3957. cmd = scb->cmd;
  3958. aic_dev = AIC_DEV(scb->cmd);
  3959. hscb->target_status = aic_inb(p, SCB_TARGET_STATUS);
  3960. aic7xxx_status(cmd) = hscb->target_status;
  3961. cmd->result = hscb->target_status;
  3962. switch (status_byte(hscb->target_status))
  3963. {
  3964. case GOOD:
  3965. if (aic7xxx_verbose & VERBOSE_SEQINT)
  3966. printk(INFO_LEAD "Interrupted for status of GOOD???\n",
  3967. p->host_no, CTL_OF_SCB(scb));
  3968. break;
  3969. case COMMAND_TERMINATED:
  3970. case CHECK_CONDITION:
  3971. if ( !(scb->flags & SCB_SENSE) )
  3972. {
  3973. /*
  3974. * Send a sense command to the requesting target.
  3975. * XXX - revisit this and get rid of the memcopys.
  3976. */
  3977. memcpy(scb->sense_cmd, &generic_sense[0],
  3978. sizeof(generic_sense));
  3979. scb->sense_cmd[1] = (cmd->device->lun << 5);
  3980. scb->sense_cmd[4] = sizeof(cmd->sense_buffer);
  3981. scb->sg_list[0].length =
  3982. cpu_to_le32(sizeof(cmd->sense_buffer));
  3983. scb->sg_list[0].address =
  3984. cpu_to_le32(pci_map_single(p->pdev, cmd->sense_buffer,
  3985. sizeof(cmd->sense_buffer),
  3986. PCI_DMA_FROMDEVICE));
  3987. /*
  3988. * XXX - We should allow disconnection, but can't as it
  3989. * might allow overlapped tagged commands.
  3990. */
  3991. /* hscb->control &= DISCENB; */
  3992. hscb->control = 0;
  3993. hscb->target_status = 0;
  3994. hscb->SG_list_pointer =
  3995. cpu_to_le32(SCB_DMA_ADDR(scb, scb->sg_list));
  3996. hscb->SCSI_cmd_pointer =
  3997. cpu_to_le32(SCB_DMA_ADDR(scb, scb->sense_cmd));
  3998. hscb->data_count = scb->sg_list[0].length;
  3999. hscb->data_pointer = scb->sg_list[0].address;
  4000. hscb->SCSI_cmd_length = COMMAND_SIZE(scb->sense_cmd[0]);
  4001. hscb->residual_SG_segment_count = 0;
  4002. hscb->residual_data_count[0] = 0;
  4003. hscb->residual_data_count[1] = 0;
  4004. hscb->residual_data_count[2] = 0;
  4005. scb->sg_count = hscb->SG_segment_count = 1;
  4006. scb->sg_length = sizeof(cmd->sense_buffer);
  4007. scb->tag_action = 0;
  4008. scb->flags |= SCB_SENSE;
  4009. /*
  4010. * Ensure the target is busy since this will be an
  4011. * an untagged request.
  4012. */
  4013. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  4014. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4015. {
  4016. if (scb->flags & SCB_MSGOUT_BITS)
  4017. printk(INFO_LEAD "Requesting SENSE with %s\n", p->host_no,
  4018. CTL_OF_SCB(scb), (scb->flags & SCB_MSGOUT_SDTR) ?
  4019. "SDTR" : "WDTR");
  4020. else
  4021. printk(INFO_LEAD "Requesting SENSE, no MSG\n", p->host_no,
  4022. CTL_OF_SCB(scb));
  4023. }
  4024. #endif
  4025. aic7xxx_busy_target(p, scb);
  4026. aic_outb(p, SEND_SENSE, RETURN_1);
  4027. aic7xxx_error(cmd) = DID_OK;
  4028. break;
  4029. } /* first time sense, no errors */
  4030. printk(INFO_LEAD "CHECK_CONDITION on REQUEST_SENSE, returning "
  4031. "an error.\n", p->host_no, CTL_OF_SCB(scb));
  4032. aic7xxx_error(cmd) = DID_ERROR;
  4033. scb->flags &= ~SCB_SENSE;
  4034. break;
  4035. case QUEUE_FULL:
  4036. queue_flag = TRUE; /* Mark that this is a QUEUE_FULL and */
  4037. case BUSY: /* drop through to here */
  4038. {
  4039. struct aic7xxx_scb *next_scbp, *prev_scbp;
  4040. unsigned char active_hscb, next_hscb, prev_hscb, scb_index;
  4041. /*
  4042. * We have to look three places for queued commands:
  4043. * 1: p->waiting_scbs queue
  4044. * 2: QINFIFO
  4045. * 3: WAITING_SCBS list on card (for commands that are started
  4046. * but haven't yet made it to the device)
  4047. *
  4048. * Of special note here is that commands on 2 or 3 above will
  4049. * have already been marked as active, while commands on 1 will
  4050. * not. The aic7xxx_done() function will want to unmark them
  4051. * from active, so any commands we pull off of 1 need to
  4052. * up the active count.
  4053. */
  4054. next_scbp = p->waiting_scbs.head;
  4055. while ( next_scbp != NULL )
  4056. {
  4057. prev_scbp = next_scbp;
  4058. next_scbp = next_scbp->q_next;
  4059. if ( aic7xxx_match_scb(p, prev_scbp, target, channel, lun,
  4060. SCB_LIST_NULL) )
  4061. {
  4062. scbq_remove(&p->waiting_scbs, prev_scbp);
  4063. scb->flags = SCB_QUEUED_FOR_DONE | SCB_QUEUE_FULL;
  4064. p->activescbs++;
  4065. aic_dev->active_cmds++;
  4066. }
  4067. }
  4068. aic7xxx_search_qinfifo(p, target, channel, lun,
  4069. SCB_LIST_NULL, SCB_QUEUED_FOR_DONE | SCB_QUEUE_FULL,
  4070. FALSE, NULL);
  4071. next_scbp = NULL;
  4072. active_hscb = aic_inb(p, SCBPTR);
  4073. prev_hscb = next_hscb = scb_index = SCB_LIST_NULL;
  4074. next_hscb = aic_inb(p, WAITING_SCBH);
  4075. while (next_hscb != SCB_LIST_NULL)
  4076. {
  4077. aic_outb(p, next_hscb, SCBPTR);
  4078. scb_index = aic_inb(p, SCB_TAG);
  4079. if (scb_index < p->scb_data->numscbs)
  4080. {
  4081. next_scbp = p->scb_data->scb_array[scb_index];
  4082. if (aic7xxx_match_scb(p, next_scbp, target, channel, lun,
  4083. SCB_LIST_NULL) )
  4084. {
  4085. next_scbp->flags = SCB_QUEUED_FOR_DONE | SCB_QUEUE_FULL;
  4086. next_hscb = aic_inb(p, SCB_NEXT);
  4087. aic_outb(p, 0, SCB_CONTROL);
  4088. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  4089. aic7xxx_add_curscb_to_free_list(p);
  4090. if (prev_hscb == SCB_LIST_NULL)
  4091. {
  4092. /* We were first on the list,
  4093. * so we kill the selection
  4094. * hardware. Let the sequencer
  4095. * re-init the hardware itself
  4096. */
  4097. aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
  4098. aic_outb(p, CLRSELTIMEO, CLRSINT1);
  4099. aic_outb(p, next_hscb, WAITING_SCBH);
  4100. }
  4101. else
  4102. {
  4103. aic_outb(p, prev_hscb, SCBPTR);
  4104. aic_outb(p, next_hscb, SCB_NEXT);
  4105. }
  4106. }
  4107. else
  4108. {
  4109. prev_hscb = next_hscb;
  4110. next_hscb = aic_inb(p, SCB_NEXT);
  4111. }
  4112. } /* scb_index >= p->scb_data->numscbs */
  4113. }
  4114. aic_outb(p, active_hscb, SCBPTR);
  4115. aic7xxx_run_done_queue(p, FALSE);
  4116. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  4117. if( (aic7xxx_verbose & VERBOSE_MINOR_ERROR) ||
  4118. (aic7xxx_verbose > 0xffff) )
  4119. {
  4120. if (queue_flag)
  4121. printk(INFO_LEAD "Queue full received; queue depth %d, "
  4122. "active %d\n", p->host_no, CTL_OF_SCB(scb),
  4123. aic_dev->max_q_depth, aic_dev->active_cmds);
  4124. else
  4125. printk(INFO_LEAD "Target busy\n", p->host_no, CTL_OF_SCB(scb));
  4126. }
  4127. #endif
  4128. if (queue_flag)
  4129. {
  4130. int diff;
  4131. result = scsi_track_queue_full(cmd->device,
  4132. aic_dev->active_cmds);
  4133. if ( result < 0 )
  4134. {
  4135. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4136. printk(INFO_LEAD "Tagged Command Queueing disabled.\n",
  4137. p->host_no, CTL_OF_SCB(scb));
  4138. diff = aic_dev->max_q_depth - p->host->cmd_per_lun;
  4139. aic_dev->temp_q_depth = 1;
  4140. aic_dev->max_q_depth = 1;
  4141. }
  4142. else if ( result > 0 )
  4143. {
  4144. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4145. printk(INFO_LEAD "Queue depth reduced to %d\n", p->host_no,
  4146. CTL_OF_SCB(scb), result);
  4147. diff = aic_dev->max_q_depth - result;
  4148. aic_dev->max_q_depth = result;
  4149. /* temp_q_depth could have been dropped to 1 for an untagged
  4150. * command that might be coming up */
  4151. if(aic_dev->temp_q_depth > result)
  4152. aic_dev->temp_q_depth = result;
  4153. }
  4154. /* We should free up the no unused SCB entries. But, that's
  4155. * a difficult thing to do because we use a direct indexed
  4156. * array, so we can't just take any entries and free them,
  4157. * we *have* to free the ones at the end of the array, and
  4158. * they very well could be in use right now, which means
  4159. * in order to do this right, we have to add a delayed
  4160. * freeing mechanism tied into the scb_free() code area.
  4161. * We'll add that later.
  4162. */
  4163. }
  4164. break;
  4165. }
  4166. default:
  4167. if (aic7xxx_verbose & VERBOSE_SEQINT)
  4168. printk(INFO_LEAD "Unexpected target status 0x%x.\n", p->host_no,
  4169. CTL_OF_SCB(scb), scb->hscb->target_status);
  4170. if (!aic7xxx_error(cmd))
  4171. {
  4172. aic7xxx_error(cmd) = DID_RETRY_COMMAND;
  4173. }
  4174. break;
  4175. } /* end switch */
  4176. } /* end else of */
  4177. }
  4178. break;
  4179. case AWAITING_MSG:
  4180. {
  4181. unsigned char scb_index, msg_out;
  4182. scb_index = aic_inb(p, SCB_TAG);
  4183. msg_out = aic_inb(p, MSG_OUT);
  4184. scb = p->scb_data->scb_array[scb_index];
  4185. aic_dev = AIC_DEV(scb->cmd);
  4186. p->msg_index = p->msg_len = 0;
  4187. /*
  4188. * This SCB had a MK_MESSAGE set in its control byte informing
  4189. * the sequencer that we wanted to send a special message to
  4190. * this target.
  4191. */
  4192. if ( !(scb->flags & SCB_DEVICE_RESET) &&
  4193. (msg_out == MSG_IDENTIFYFLAG) &&
  4194. (scb->hscb->control & TAG_ENB) )
  4195. {
  4196. p->msg_buf[p->msg_index++] = scb->tag_action;
  4197. p->msg_buf[p->msg_index++] = scb->hscb->tag;
  4198. p->msg_len += 2;
  4199. }
  4200. if (scb->flags & SCB_DEVICE_RESET)
  4201. {
  4202. p->msg_buf[p->msg_index++] = MSG_BUS_DEV_RESET;
  4203. p->msg_len++;
  4204. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  4205. printk(INFO_LEAD "Bus device reset mailed.\n",
  4206. p->host_no, CTL_OF_SCB(scb));
  4207. }
  4208. else if (scb->flags & SCB_ABORT)
  4209. {
  4210. if (scb->tag_action)
  4211. {
  4212. p->msg_buf[p->msg_index++] = MSG_ABORT_TAG;
  4213. }
  4214. else
  4215. {
  4216. p->msg_buf[p->msg_index++] = MSG_ABORT;
  4217. }
  4218. p->msg_len++;
  4219. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  4220. printk(INFO_LEAD "Abort message mailed.\n", p->host_no,
  4221. CTL_OF_SCB(scb));
  4222. }
  4223. else if (scb->flags & SCB_MSGOUT_PPR)
  4224. {
  4225. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4226. {
  4227. printk(INFO_LEAD "Sending PPR (%d/%d/%d/%d) message.\n",
  4228. p->host_no, CTL_OF_SCB(scb),
  4229. aic_dev->goal.period,
  4230. aic_dev->goal.offset,
  4231. aic_dev->goal.width,
  4232. aic_dev->goal.options);
  4233. }
  4234. aic7xxx_construct_ppr(p, scb);
  4235. }
  4236. else if (scb->flags & SCB_MSGOUT_WDTR)
  4237. {
  4238. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4239. {
  4240. printk(INFO_LEAD "Sending WDTR message.\n", p->host_no,
  4241. CTL_OF_SCB(scb));
  4242. }
  4243. aic7xxx_construct_wdtr(p, aic_dev->goal.width);
  4244. }
  4245. else if (scb->flags & SCB_MSGOUT_SDTR)
  4246. {
  4247. unsigned int max_sync, period;
  4248. unsigned char options = 0;
  4249. /*
  4250. * Now that the device is selected, use the bits in SBLKCTL and
  4251. * SSTAT2 to determine the max sync rate for this device.
  4252. */
  4253. if (p->features & AHC_ULTRA2)
  4254. {
  4255. if ( (aic_inb(p, SBLKCTL) & ENAB40) &&
  4256. !(aic_inb(p, SSTAT2) & EXP_ACTIVE) )
  4257. {
  4258. max_sync = AHC_SYNCRATE_ULTRA2;
  4259. }
  4260. else
  4261. {
  4262. max_sync = AHC_SYNCRATE_ULTRA;
  4263. }
  4264. }
  4265. else if (p->features & AHC_ULTRA)
  4266. {
  4267. max_sync = AHC_SYNCRATE_ULTRA;
  4268. }
  4269. else
  4270. {
  4271. max_sync = AHC_SYNCRATE_FAST;
  4272. }
  4273. period = aic_dev->goal.period;
  4274. aic7xxx_find_syncrate(p, &period, max_sync, &options);
  4275. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4276. {
  4277. printk(INFO_LEAD "Sending SDTR %d/%d message.\n", p->host_no,
  4278. CTL_OF_SCB(scb), period,
  4279. aic_dev->goal.offset);
  4280. }
  4281. aic7xxx_construct_sdtr(p, period, aic_dev->goal.offset);
  4282. }
  4283. else
  4284. {
  4285. panic("aic7xxx: AWAITING_MSG for an SCB that does "
  4286. "not have a waiting message.\n");
  4287. }
  4288. /*
  4289. * We've set everything up to send our message, now to actually do
  4290. * so we need to enable reqinit interrupts and let the interrupt
  4291. * handler do the rest. We don't want to unpause the sequencer yet
  4292. * though so we'll return early. We also have to make sure that
  4293. * we clear the SEQINT *BEFORE* we set the REQINIT handler active
  4294. * or else it's possible on VLB cards to lose the first REQINIT
  4295. * interrupt. Edge triggered EISA cards could also lose this
  4296. * interrupt, although PCI and level triggered cards should not
  4297. * have this problem since they continually interrupt the kernel
  4298. * until we take care of the situation.
  4299. */
  4300. scb->flags |= SCB_MSGOUT_SENT;
  4301. p->msg_index = 0;
  4302. p->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
  4303. p->flags |= AHC_HANDLING_REQINITS;
  4304. aic_outb(p, aic_inb(p, SIMODE1) | ENREQINIT, SIMODE1);
  4305. return;
  4306. }
  4307. break;
  4308. case DATA_OVERRUN:
  4309. {
  4310. unsigned char scb_index = aic_inb(p, SCB_TAG);
  4311. unsigned char lastphase = aic_inb(p, LASTPHASE);
  4312. unsigned int i;
  4313. scb = (p->scb_data->scb_array[scb_index]);
  4314. /*
  4315. * XXX - What do we really want to do on an overrun? The
  4316. * mid-level SCSI code should handle this, but for now,
  4317. * we'll just indicate that the command should retried.
  4318. * If we retrieved sense info on this target, then the
  4319. * base SENSE info should have been saved prior to the
  4320. * overrun error. In that case, we return DID_OK and let
  4321. * the mid level code pick up on the sense info. Otherwise
  4322. * we return DID_ERROR so the command will get retried.
  4323. */
  4324. if ( !(scb->flags & SCB_SENSE) )
  4325. {
  4326. printk(WARN_LEAD "Data overrun detected in %s phase, tag %d;\n",
  4327. p->host_no, CTL_OF_SCB(scb),
  4328. (lastphase == P_DATAIN) ? "Data-In" : "Data-Out", scb->hscb->tag);
  4329. printk(KERN_WARNING " %s seen Data Phase. Length=%d, NumSGs=%d.\n",
  4330. (aic_inb(p, SEQ_FLAGS) & DPHASE) ? "Have" : "Haven't",
  4331. scb->sg_length, scb->sg_count);
  4332. printk(KERN_WARNING " Raw SCSI Command: 0x");
  4333. for (i = 0; i < scb->hscb->SCSI_cmd_length; i++)
  4334. {
  4335. printk("%02x ", scb->cmd->cmnd[i]);
  4336. }
  4337. printk("\n");
  4338. if(aic7xxx_verbose > 0xffff)
  4339. {
  4340. for (i = 0; i < scb->sg_count; i++)
  4341. {
  4342. printk(KERN_WARNING " sg[%d] - Addr 0x%x : Length %d\n",
  4343. i,
  4344. le32_to_cpu(scb->sg_list[i].address),
  4345. le32_to_cpu(scb->sg_list[i].length) );
  4346. }
  4347. }
  4348. aic7xxx_error(scb->cmd) = DID_ERROR;
  4349. }
  4350. else
  4351. printk(INFO_LEAD "Data Overrun during SEND_SENSE operation.\n",
  4352. p->host_no, CTL_OF_SCB(scb));
  4353. }
  4354. break;
  4355. case WIDE_RESIDUE:
  4356. {
  4357. unsigned char resid_sgcnt, index;
  4358. unsigned char scb_index = aic_inb(p, SCB_TAG);
  4359. unsigned int cur_addr, resid_dcnt;
  4360. unsigned int native_addr, native_length, sg_addr;
  4361. int i;
  4362. if(scb_index > p->scb_data->numscbs)
  4363. {
  4364. printk(WARN_LEAD "invalid scb_index during WIDE_RESIDUE.\n",
  4365. p->host_no, -1, -1, -1);
  4366. /*
  4367. * XXX: Add error handling here
  4368. */
  4369. break;
  4370. }
  4371. scb = p->scb_data->scb_array[scb_index];
  4372. if(!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
  4373. {
  4374. printk(WARN_LEAD "invalid scb during WIDE_RESIDUE flags:0x%x "
  4375. "scb->cmd:0x%lx\n", p->host_no, CTL_OF_SCB(scb),
  4376. scb->flags, (unsigned long)scb->cmd);
  4377. break;
  4378. }
  4379. if(aic7xxx_verbose & VERBOSE_MINOR_ERROR)
  4380. printk(INFO_LEAD "Got WIDE_RESIDUE message, patching up data "
  4381. "pointer.\n", p->host_no, CTL_OF_SCB(scb));
  4382. /*
  4383. * We have a valid scb to use on this WIDE_RESIDUE message, so
  4384. * we need to walk the sg list looking for this particular sg
  4385. * segment, then see if we happen to be at the very beginning of
  4386. * the segment. If we are, then we have to back things up to
  4387. * the previous segment. If not, then we simply need to remove
  4388. * one byte from this segments address and add one to the byte
  4389. * count.
  4390. */
  4391. cur_addr = aic_inb(p, SHADDR) | (aic_inb(p, SHADDR + 1) << 8) |
  4392. (aic_inb(p, SHADDR + 2) << 16) | (aic_inb(p, SHADDR + 3) << 24);
  4393. sg_addr = aic_inb(p, SG_COUNT + 1) | (aic_inb(p, SG_COUNT + 2) << 8) |
  4394. (aic_inb(p, SG_COUNT + 3) << 16) | (aic_inb(p, SG_COUNT + 4) << 24);
  4395. resid_sgcnt = aic_inb(p, SCB_RESID_SGCNT);
  4396. resid_dcnt = aic_inb(p, SCB_RESID_DCNT) |
  4397. (aic_inb(p, SCB_RESID_DCNT + 1) << 8) |
  4398. (aic_inb(p, SCB_RESID_DCNT + 2) << 16);
  4399. index = scb->sg_count - ((resid_sgcnt) ? resid_sgcnt : 1);
  4400. native_addr = le32_to_cpu(scb->sg_list[index].address);
  4401. native_length = le32_to_cpu(scb->sg_list[index].length);
  4402. /*
  4403. * If resid_dcnt == native_length, then we just loaded this SG
  4404. * segment and we need to back it up one...
  4405. */
  4406. if(resid_dcnt == native_length)
  4407. {
  4408. if(index == 0)
  4409. {
  4410. /*
  4411. * Oops, this isn't right, we can't back up to before the
  4412. * beginning. This must be a bogus message, ignore it.
  4413. */
  4414. break;
  4415. }
  4416. resid_dcnt = 1;
  4417. resid_sgcnt += 1;
  4418. native_addr = le32_to_cpu(scb->sg_list[index - 1].address);
  4419. native_length = le32_to_cpu(scb->sg_list[index - 1].length);
  4420. cur_addr = native_addr + (native_length - 1);
  4421. sg_addr -= sizeof(struct hw_scatterlist);
  4422. }
  4423. else
  4424. {
  4425. /*
  4426. * resid_dcnt != native_length, so we are in the middle of a SG
  4427. * element. Back it up one byte and leave the rest alone.
  4428. */
  4429. resid_dcnt += 1;
  4430. cur_addr -= 1;
  4431. }
  4432. /*
  4433. * Output the new addresses and counts to the right places on the
  4434. * card.
  4435. */
  4436. aic_outb(p, resid_sgcnt, SG_COUNT);
  4437. aic_outb(p, resid_sgcnt, SCB_RESID_SGCNT);
  4438. aic_outb(p, sg_addr & 0xff, SG_COUNT + 1);
  4439. aic_outb(p, (sg_addr >> 8) & 0xff, SG_COUNT + 2);
  4440. aic_outb(p, (sg_addr >> 16) & 0xff, SG_COUNT + 3);
  4441. aic_outb(p, (sg_addr >> 24) & 0xff, SG_COUNT + 4);
  4442. aic_outb(p, resid_dcnt & 0xff, SCB_RESID_DCNT);
  4443. aic_outb(p, (resid_dcnt >> 8) & 0xff, SCB_RESID_DCNT + 1);
  4444. aic_outb(p, (resid_dcnt >> 16) & 0xff, SCB_RESID_DCNT + 2);
  4445. /*
  4446. * The sequencer actually wants to find the new address
  4447. * in the SHADDR register set. On the Ultra2 and later controllers
  4448. * this register set is readonly. In order to get the right number
  4449. * into the register, you actually have to enter it in HADDR and then
  4450. * use the PRELOADEN bit of DFCNTRL to drop it through from the
  4451. * HADDR register to the SHADDR register. On non-Ultra2 controllers,
  4452. * we simply write it direct.
  4453. */
  4454. if(p->features & AHC_ULTRA2)
  4455. {
  4456. /*
  4457. * We might as well be accurate and drop both the resid_dcnt and
  4458. * cur_addr into HCNT and HADDR and have both of them drop
  4459. * through to the shadow layer together.
  4460. */
  4461. aic_outb(p, resid_dcnt & 0xff, HCNT);
  4462. aic_outb(p, (resid_dcnt >> 8) & 0xff, HCNT + 1);
  4463. aic_outb(p, (resid_dcnt >> 16) & 0xff, HCNT + 2);
  4464. aic_outb(p, cur_addr & 0xff, HADDR);
  4465. aic_outb(p, (cur_addr >> 8) & 0xff, HADDR + 1);
  4466. aic_outb(p, (cur_addr >> 16) & 0xff, HADDR + 2);
  4467. aic_outb(p, (cur_addr >> 24) & 0xff, HADDR + 3);
  4468. aic_outb(p, aic_inb(p, DMAPARAMS) | PRELOADEN, DFCNTRL);
  4469. udelay(1);
  4470. aic_outb(p, aic_inb(p, DMAPARAMS) & ~(SCSIEN|HDMAEN), DFCNTRL);
  4471. i=0;
  4472. while(((aic_inb(p, DFCNTRL) & (SCSIEN|HDMAEN)) != 0) && (i++ < 1000))
  4473. {
  4474. udelay(1);
  4475. }
  4476. }
  4477. else
  4478. {
  4479. aic_outb(p, cur_addr & 0xff, SHADDR);
  4480. aic_outb(p, (cur_addr >> 8) & 0xff, SHADDR + 1);
  4481. aic_outb(p, (cur_addr >> 16) & 0xff, SHADDR + 2);
  4482. aic_outb(p, (cur_addr >> 24) & 0xff, SHADDR + 3);
  4483. }
  4484. }
  4485. break;
  4486. case SEQ_SG_FIXUP:
  4487. {
  4488. unsigned char scb_index, tmp;
  4489. int sg_addr, sg_length;
  4490. scb_index = aic_inb(p, SCB_TAG);
  4491. if(scb_index > p->scb_data->numscbs)
  4492. {
  4493. printk(WARN_LEAD "invalid scb_index during SEQ_SG_FIXUP.\n",
  4494. p->host_no, -1, -1, -1);
  4495. printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
  4496. "0x%x\n", p->host_no, -1, -1, -1,
  4497. aic_inb(p, SCSISIGI),
  4498. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  4499. aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
  4500. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SSTAT2 0x%x, STCNT 0x%x\n",
  4501. p->host_no, -1, -1, -1, aic_inb(p, SG_CACHEPTR),
  4502. aic_inb(p, SSTAT2), aic_inb(p, STCNT + 2) << 16 |
  4503. aic_inb(p, STCNT + 1) << 8 | aic_inb(p, STCNT));
  4504. /*
  4505. * XXX: Add error handling here
  4506. */
  4507. break;
  4508. }
  4509. scb = p->scb_data->scb_array[scb_index];
  4510. if(!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
  4511. {
  4512. printk(WARN_LEAD "invalid scb during SEQ_SG_FIXUP flags:0x%x "
  4513. "scb->cmd:0x%p\n", p->host_no, CTL_OF_SCB(scb),
  4514. scb->flags, scb->cmd);
  4515. printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
  4516. "0x%x\n", p->host_no, CTL_OF_SCB(scb),
  4517. aic_inb(p, SCSISIGI),
  4518. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  4519. aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
  4520. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SSTAT2 0x%x, STCNT 0x%x\n",
  4521. p->host_no, CTL_OF_SCB(scb), aic_inb(p, SG_CACHEPTR),
  4522. aic_inb(p, SSTAT2), aic_inb(p, STCNT + 2) << 16 |
  4523. aic_inb(p, STCNT + 1) << 8 | aic_inb(p, STCNT));
  4524. break;
  4525. }
  4526. if(aic7xxx_verbose & VERBOSE_MINOR_ERROR)
  4527. printk(INFO_LEAD "Fixing up SG address for sequencer.\n", p->host_no,
  4528. CTL_OF_SCB(scb));
  4529. /*
  4530. * Advance the SG pointer to the next element in the list
  4531. */
  4532. tmp = aic_inb(p, SG_NEXT);
  4533. tmp += SG_SIZEOF;
  4534. aic_outb(p, tmp, SG_NEXT);
  4535. if( tmp < SG_SIZEOF )
  4536. aic_outb(p, aic_inb(p, SG_NEXT + 1) + 1, SG_NEXT + 1);
  4537. tmp = aic_inb(p, SG_COUNT) - 1;
  4538. aic_outb(p, tmp, SG_COUNT);
  4539. sg_addr = le32_to_cpu(scb->sg_list[scb->sg_count - tmp].address);
  4540. sg_length = le32_to_cpu(scb->sg_list[scb->sg_count - tmp].length);
  4541. /*
  4542. * Now stuff the element we just advanced past down onto the
  4543. * card so it can be stored in the residual area.
  4544. */
  4545. aic_outb(p, sg_addr & 0xff, HADDR);
  4546. aic_outb(p, (sg_addr >> 8) & 0xff, HADDR + 1);
  4547. aic_outb(p, (sg_addr >> 16) & 0xff, HADDR + 2);
  4548. aic_outb(p, (sg_addr >> 24) & 0xff, HADDR + 3);
  4549. aic_outb(p, sg_length & 0xff, HCNT);
  4550. aic_outb(p, (sg_length >> 8) & 0xff, HCNT + 1);
  4551. aic_outb(p, (sg_length >> 16) & 0xff, HCNT + 2);
  4552. aic_outb(p, (tmp << 2) | ((tmp == 1) ? LAST_SEG : 0), SG_CACHEPTR);
  4553. aic_outb(p, aic_inb(p, DMAPARAMS), DFCNTRL);
  4554. while(aic_inb(p, SSTAT0) & SDONE) udelay(1);
  4555. while(aic_inb(p, DFCNTRL) & (HDMAEN|SCSIEN)) aic_outb(p, 0, DFCNTRL);
  4556. }
  4557. break;
  4558. #ifdef AIC7XXX_NOT_YET
  4559. case TRACEPOINT2:
  4560. {
  4561. printk(INFO_LEAD "Tracepoint #2 reached.\n", p->host_no,
  4562. channel, target, lun);
  4563. }
  4564. break;
  4565. /* XXX Fill these in later */
  4566. case MSG_BUFFER_BUSY:
  4567. printk("aic7xxx: Message buffer busy.\n");
  4568. break;
  4569. case MSGIN_PHASEMIS:
  4570. printk("aic7xxx: Message-in phasemis.\n");
  4571. break;
  4572. #endif
  4573. default: /* unknown */
  4574. printk(WARN_LEAD "Unknown SEQINT, INTSTAT 0x%x, SCSISIGI 0x%x.\n",
  4575. p->host_no, channel, target, lun, intstat,
  4576. aic_inb(p, SCSISIGI));
  4577. break;
  4578. }
  4579. /*
  4580. * Clear the sequencer interrupt and unpause the sequencer.
  4581. */
  4582. unpause_sequencer(p, /* unpause always */ TRUE);
  4583. }
  4584. /*+F*************************************************************************
  4585. * Function:
  4586. * aic7xxx_parse_msg
  4587. *
  4588. * Description:
  4589. * Parses incoming messages into actions on behalf of
  4590. * aic7xxx_handle_reqinit
  4591. *_F*************************************************************************/
  4592. static int
  4593. aic7xxx_parse_msg(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  4594. {
  4595. int reject, reply, done;
  4596. unsigned char target_scsirate, tindex;
  4597. unsigned short target_mask;
  4598. unsigned char target, channel, lun;
  4599. unsigned char bus_width, new_bus_width;
  4600. unsigned char trans_options, new_trans_options;
  4601. unsigned int period, new_period, offset, new_offset, maxsync;
  4602. struct aic7xxx_syncrate *syncrate;
  4603. struct aic_dev_data *aic_dev;
  4604. target = scb->cmd->device->id;
  4605. channel = scb->cmd->device->channel;
  4606. lun = scb->cmd->device->lun;
  4607. reply = reject = done = FALSE;
  4608. tindex = TARGET_INDEX(scb->cmd);
  4609. aic_dev = AIC_DEV(scb->cmd);
  4610. target_scsirate = aic_inb(p, TARG_SCSIRATE + tindex);
  4611. target_mask = (0x01 << tindex);
  4612. /*
  4613. * Parse as much of the message as is available,
  4614. * rejecting it if we don't support it. When
  4615. * the entire message is available and has been
  4616. * handled, return TRUE indicating that we have
  4617. * parsed an entire message.
  4618. */
  4619. if (p->msg_buf[0] != MSG_EXTENDED)
  4620. {
  4621. reject = TRUE;
  4622. }
  4623. /*
  4624. * Even if we are an Ultra3 card, don't allow Ultra3 sync rates when
  4625. * using the SDTR messages. We need the PPR messages to enable the
  4626. * higher speeds that include things like Dual Edge clocking.
  4627. */
  4628. if (p->features & AHC_ULTRA2)
  4629. {
  4630. if ( (aic_inb(p, SBLKCTL) & ENAB40) &&
  4631. !(aic_inb(p, SSTAT2) & EXP_ACTIVE) )
  4632. {
  4633. if (p->features & AHC_ULTRA3)
  4634. maxsync = AHC_SYNCRATE_ULTRA3;
  4635. else
  4636. maxsync = AHC_SYNCRATE_ULTRA2;
  4637. }
  4638. else
  4639. {
  4640. maxsync = AHC_SYNCRATE_ULTRA;
  4641. }
  4642. }
  4643. else if (p->features & AHC_ULTRA)
  4644. {
  4645. maxsync = AHC_SYNCRATE_ULTRA;
  4646. }
  4647. else
  4648. {
  4649. maxsync = AHC_SYNCRATE_FAST;
  4650. }
  4651. /*
  4652. * Just accept the length byte outright and perform
  4653. * more checking once we know the message type.
  4654. */
  4655. if ( !reject && (p->msg_len > 2) )
  4656. {
  4657. switch(p->msg_buf[2])
  4658. {
  4659. case MSG_EXT_SDTR:
  4660. {
  4661. if (p->msg_buf[1] != MSG_EXT_SDTR_LEN)
  4662. {
  4663. reject = TRUE;
  4664. break;
  4665. }
  4666. if (p->msg_len < (MSG_EXT_SDTR_LEN + 2))
  4667. {
  4668. break;
  4669. }
  4670. period = new_period = p->msg_buf[3];
  4671. offset = new_offset = p->msg_buf[4];
  4672. trans_options = new_trans_options = 0;
  4673. bus_width = new_bus_width = target_scsirate & WIDEXFER;
  4674. /*
  4675. * If our current max syncrate is in the Ultra3 range, bump it back
  4676. * down to Ultra2 since we can't negotiate DT transfers using SDTR
  4677. */
  4678. if(maxsync == AHC_SYNCRATE_ULTRA3)
  4679. maxsync = AHC_SYNCRATE_ULTRA2;
  4680. /*
  4681. * We might have a device that is starting negotiation with us
  4682. * before we can start up negotiation with it....be prepared to
  4683. * have a device ask for a higher speed then we want to give it
  4684. * in that case
  4685. */
  4686. if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR)) !=
  4687. (SCB_MSGOUT_SENT|SCB_MSGOUT_SDTR) )
  4688. {
  4689. if (!(aic_dev->flags & DEVICE_DTR_SCANNED))
  4690. {
  4691. /*
  4692. * We shouldn't get here unless this is a narrow drive, wide
  4693. * devices should trigger this same section of code in the WDTR
  4694. * handler first instead.
  4695. */
  4696. aic_dev->goal.width = MSG_EXT_WDTR_BUS_8_BIT;
  4697. aic_dev->goal.options = 0;
  4698. if(p->user[tindex].offset)
  4699. {
  4700. aic_dev->needsdtr_copy = 1;
  4701. aic_dev->goal.period = max_t(unsigned char, 10,p->user[tindex].period);
  4702. if(p->features & AHC_ULTRA2)
  4703. {
  4704. aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
  4705. }
  4706. else
  4707. {
  4708. aic_dev->goal.offset = MAX_OFFSET_8BIT;
  4709. }
  4710. }
  4711. else
  4712. {
  4713. aic_dev->needsdtr_copy = 0;
  4714. aic_dev->goal.period = 255;
  4715. aic_dev->goal.offset = 0;
  4716. }
  4717. aic_dev->flags |= DEVICE_DTR_SCANNED | DEVICE_PRINT_DTR;
  4718. }
  4719. else if (aic_dev->needsdtr_copy == 0)
  4720. {
  4721. /*
  4722. * This is a preemptive message from the target, we've already
  4723. * scanned this target and set our options for it, and we
  4724. * don't need a SDTR with this target (for whatever reason),
  4725. * so reject this incoming SDTR
  4726. */
  4727. reject = TRUE;
  4728. break;
  4729. }
  4730. /* The device is sending this message first and we have to reply */
  4731. reply = TRUE;
  4732. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4733. {
  4734. printk(INFO_LEAD "Received pre-emptive SDTR message from "
  4735. "target.\n", p->host_no, CTL_OF_SCB(scb));
  4736. }
  4737. /*
  4738. * Validate the values the device passed to us against our SEEPROM
  4739. * settings. We don't have to do this if we aren't replying since
  4740. * the device isn't allowed to send values greater than the ones
  4741. * we first sent to it.
  4742. */
  4743. new_period = max_t(unsigned int, period, aic_dev->goal.period);
  4744. new_offset = min_t(unsigned int, offset, aic_dev->goal.offset);
  4745. }
  4746. /*
  4747. * Use our new_period, new_offset, bus_width, and card options
  4748. * to determine the actual syncrate settings
  4749. */
  4750. syncrate = aic7xxx_find_syncrate(p, &new_period, maxsync,
  4751. &trans_options);
  4752. aic7xxx_validate_offset(p, syncrate, &new_offset, bus_width);
  4753. /*
  4754. * Did we drop to async? If so, send a reply regardless of whether
  4755. * or not we initiated this negotiation.
  4756. */
  4757. if ((new_offset == 0) && (new_offset != offset))
  4758. {
  4759. aic_dev->needsdtr_copy = 0;
  4760. reply = TRUE;
  4761. }
  4762. /*
  4763. * Did we start this, if not, or if we went too low and had to
  4764. * go async, then send an SDTR back to the target
  4765. */
  4766. if(reply)
  4767. {
  4768. /* when sending a reply, make sure that the goal settings are
  4769. * updated along with current and active since the code that
  4770. * will actually build the message for the sequencer uses the
  4771. * goal settings as its guidelines.
  4772. */
  4773. aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
  4774. new_offset, trans_options,
  4775. AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
  4776. aic_dev);
  4777. scb->flags &= ~SCB_MSGOUT_BITS;
  4778. scb->flags |= SCB_MSGOUT_SDTR;
  4779. aic_outb(p, HOST_MSG, MSG_OUT);
  4780. aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
  4781. }
  4782. else
  4783. {
  4784. aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
  4785. new_offset, trans_options,
  4786. AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
  4787. aic_dev->needsdtr = 0;
  4788. }
  4789. done = TRUE;
  4790. break;
  4791. }
  4792. case MSG_EXT_WDTR:
  4793. {
  4794. if (p->msg_buf[1] != MSG_EXT_WDTR_LEN)
  4795. {
  4796. reject = TRUE;
  4797. break;
  4798. }
  4799. if (p->msg_len < (MSG_EXT_WDTR_LEN + 2))
  4800. {
  4801. break;
  4802. }
  4803. bus_width = new_bus_width = p->msg_buf[3];
  4804. if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_WDTR)) ==
  4805. (SCB_MSGOUT_SENT|SCB_MSGOUT_WDTR) )
  4806. {
  4807. switch(bus_width)
  4808. {
  4809. default:
  4810. {
  4811. reject = TRUE;
  4812. if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  4813. ((aic_dev->flags & DEVICE_PRINT_DTR) ||
  4814. (aic7xxx_verbose > 0xffff)) )
  4815. {
  4816. printk(INFO_LEAD "Requesting %d bit transfers, rejecting.\n",
  4817. p->host_no, CTL_OF_SCB(scb), 8 * (0x01 << bus_width));
  4818. }
  4819. } /* We fall through on purpose */
  4820. case MSG_EXT_WDTR_BUS_8_BIT:
  4821. {
  4822. aic_dev->goal.width = MSG_EXT_WDTR_BUS_8_BIT;
  4823. aic_dev->needwdtr_copy &= ~target_mask;
  4824. break;
  4825. }
  4826. case MSG_EXT_WDTR_BUS_16_BIT:
  4827. {
  4828. break;
  4829. }
  4830. }
  4831. aic_dev->needwdtr = 0;
  4832. aic7xxx_set_width(p, target, channel, lun, new_bus_width,
  4833. AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
  4834. }
  4835. else
  4836. {
  4837. if ( !(aic_dev->flags & DEVICE_DTR_SCANNED) )
  4838. {
  4839. /*
  4840. * Well, we now know the WDTR and SYNC caps of this device since
  4841. * it contacted us first, mark it as such and copy the user stuff
  4842. * over to the goal stuff.
  4843. */
  4844. if( (p->features & AHC_WIDE) && p->user[tindex].width )
  4845. {
  4846. aic_dev->goal.width = MSG_EXT_WDTR_BUS_16_BIT;
  4847. aic_dev->needwdtr_copy = 1;
  4848. }
  4849. /*
  4850. * Devices that support DT transfers don't start WDTR requests
  4851. */
  4852. aic_dev->goal.options = 0;
  4853. if(p->user[tindex].offset)
  4854. {
  4855. aic_dev->needsdtr_copy = 1;
  4856. aic_dev->goal.period = max_t(unsigned char, 10, p->user[tindex].period);
  4857. if(p->features & AHC_ULTRA2)
  4858. {
  4859. aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
  4860. }
  4861. else if( aic_dev->goal.width )
  4862. {
  4863. aic_dev->goal.offset = MAX_OFFSET_16BIT;
  4864. }
  4865. else
  4866. {
  4867. aic_dev->goal.offset = MAX_OFFSET_8BIT;
  4868. }
  4869. } else {
  4870. aic_dev->needsdtr_copy = 0;
  4871. aic_dev->goal.period = 255;
  4872. aic_dev->goal.offset = 0;
  4873. }
  4874. aic_dev->flags |= DEVICE_DTR_SCANNED | DEVICE_PRINT_DTR;
  4875. }
  4876. else if (aic_dev->needwdtr_copy == 0)
  4877. {
  4878. /*
  4879. * This is a preemptive message from the target, we've already
  4880. * scanned this target and set our options for it, and we
  4881. * don't need a WDTR with this target (for whatever reason),
  4882. * so reject this incoming WDTR
  4883. */
  4884. reject = TRUE;
  4885. break;
  4886. }
  4887. /* The device is sending this message first and we have to reply */
  4888. reply = TRUE;
  4889. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4890. {
  4891. printk(INFO_LEAD "Received pre-emptive WDTR message from "
  4892. "target.\n", p->host_no, CTL_OF_SCB(scb));
  4893. }
  4894. switch(bus_width)
  4895. {
  4896. case MSG_EXT_WDTR_BUS_16_BIT:
  4897. {
  4898. if ( (p->features & AHC_WIDE) &&
  4899. (aic_dev->goal.width == MSG_EXT_WDTR_BUS_16_BIT) )
  4900. {
  4901. new_bus_width = MSG_EXT_WDTR_BUS_16_BIT;
  4902. break;
  4903. }
  4904. } /* Fall through if we aren't a wide card */
  4905. default:
  4906. case MSG_EXT_WDTR_BUS_8_BIT:
  4907. {
  4908. aic_dev->needwdtr_copy = 0;
  4909. new_bus_width = MSG_EXT_WDTR_BUS_8_BIT;
  4910. break;
  4911. }
  4912. }
  4913. scb->flags &= ~SCB_MSGOUT_BITS;
  4914. scb->flags |= SCB_MSGOUT_WDTR;
  4915. aic_dev->needwdtr = 0;
  4916. if(aic_dev->dtr_pending == 0)
  4917. {
  4918. /* there is no other command with SCB_DTR_SCB already set that will
  4919. * trigger the release of the dtr_pending bit. Both set the bit
  4920. * and set scb->flags |= SCB_DTR_SCB
  4921. */
  4922. aic_dev->dtr_pending = 1;
  4923. scb->flags |= SCB_DTR_SCB;
  4924. }
  4925. aic_outb(p, HOST_MSG, MSG_OUT);
  4926. aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
  4927. /* when sending a reply, make sure that the goal settings are
  4928. * updated along with current and active since the code that
  4929. * will actually build the message for the sequencer uses the
  4930. * goal settings as its guidelines.
  4931. */
  4932. aic7xxx_set_width(p, target, channel, lun, new_bus_width,
  4933. AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
  4934. aic_dev);
  4935. }
  4936. /*
  4937. * By virtue of the SCSI spec, a WDTR message negates any existing
  4938. * SDTR negotiations. So, even if needsdtr isn't marked for this
  4939. * device, we still have to do a new SDTR message if the device
  4940. * supports SDTR at all. Therefore, we check needsdtr_copy instead
  4941. * of needstr.
  4942. */
  4943. aic7xxx_set_syncrate(p, NULL, target, channel, 0, 0, 0,
  4944. AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
  4945. aic_dev);
  4946. aic_dev->needsdtr = aic_dev->needsdtr_copy;
  4947. done = TRUE;
  4948. break;
  4949. }
  4950. case MSG_EXT_PPR:
  4951. {
  4952. if (p->msg_buf[1] != MSG_EXT_PPR_LEN)
  4953. {
  4954. reject = TRUE;
  4955. break;
  4956. }
  4957. if (p->msg_len < (MSG_EXT_PPR_LEN + 2))
  4958. {
  4959. break;
  4960. }
  4961. period = new_period = p->msg_buf[3];
  4962. offset = new_offset = p->msg_buf[5];
  4963. bus_width = new_bus_width = p->msg_buf[6];
  4964. trans_options = new_trans_options = p->msg_buf[7] & 0xf;
  4965. if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  4966. {
  4967. printk(INFO_LEAD "Parsing PPR message (%d/%d/%d/%d)\n",
  4968. p->host_no, CTL_OF_SCB(scb), period, offset, bus_width,
  4969. trans_options);
  4970. }
  4971. /*
  4972. * We might have a device that is starting negotiation with us
  4973. * before we can start up negotiation with it....be prepared to
  4974. * have a device ask for a higher speed then we want to give it
  4975. * in that case
  4976. */
  4977. if ( (scb->flags & (SCB_MSGOUT_SENT|SCB_MSGOUT_PPR)) !=
  4978. (SCB_MSGOUT_SENT|SCB_MSGOUT_PPR) )
  4979. {
  4980. /* Have we scanned the device yet? */
  4981. if (!(aic_dev->flags & DEVICE_DTR_SCANNED))
  4982. {
  4983. /* The device is electing to use PPR messages, so we will too until
  4984. * we know better */
  4985. aic_dev->needppr = aic_dev->needppr_copy = 1;
  4986. aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
  4987. aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
  4988. /* We know the device is SCSI-3 compliant due to PPR */
  4989. aic_dev->flags |= DEVICE_SCSI_3;
  4990. /*
  4991. * Not only is the device starting this up, but it also hasn't
  4992. * been scanned yet, so this would likely be our TUR or our
  4993. * INQUIRY command at scan time, so we need to use the
  4994. * settings from the SEEPROM if they existed. Of course, even
  4995. * if we didn't find a SEEPROM, we stuffed default values into
  4996. * the user settings anyway, so use those in all cases.
  4997. */
  4998. aic_dev->goal.width = p->user[tindex].width;
  4999. if(p->user[tindex].offset)
  5000. {
  5001. aic_dev->goal.period = p->user[tindex].period;
  5002. aic_dev->goal.options = p->user[tindex].options;
  5003. if(p->features & AHC_ULTRA2)
  5004. {
  5005. aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
  5006. }
  5007. else if( aic_dev->goal.width &&
  5008. (bus_width == MSG_EXT_WDTR_BUS_16_BIT) &&
  5009. p->features & AHC_WIDE )
  5010. {
  5011. aic_dev->goal.offset = MAX_OFFSET_16BIT;
  5012. }
  5013. else
  5014. {
  5015. aic_dev->goal.offset = MAX_OFFSET_8BIT;
  5016. }
  5017. }
  5018. else
  5019. {
  5020. aic_dev->goal.period = 255;
  5021. aic_dev->goal.offset = 0;
  5022. aic_dev->goal.options = 0;
  5023. }
  5024. aic_dev->flags |= DEVICE_DTR_SCANNED | DEVICE_PRINT_DTR;
  5025. }
  5026. else if (aic_dev->needppr_copy == 0)
  5027. {
  5028. /*
  5029. * This is a preemptive message from the target, we've already
  5030. * scanned this target and set our options for it, and we
  5031. * don't need a PPR with this target (for whatever reason),
  5032. * so reject this incoming PPR
  5033. */
  5034. reject = TRUE;
  5035. break;
  5036. }
  5037. /* The device is sending this message first and we have to reply */
  5038. reply = TRUE;
  5039. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  5040. {
  5041. printk(INFO_LEAD "Received pre-emptive PPR message from "
  5042. "target.\n", p->host_no, CTL_OF_SCB(scb));
  5043. }
  5044. }
  5045. switch(bus_width)
  5046. {
  5047. case MSG_EXT_WDTR_BUS_16_BIT:
  5048. {
  5049. if ( (aic_dev->goal.width == MSG_EXT_WDTR_BUS_16_BIT) &&
  5050. p->features & AHC_WIDE)
  5051. {
  5052. break;
  5053. }
  5054. }
  5055. default:
  5056. {
  5057. if ( (aic7xxx_verbose & VERBOSE_NEGOTIATION2) &&
  5058. ((aic_dev->flags & DEVICE_PRINT_DTR) ||
  5059. (aic7xxx_verbose > 0xffff)) )
  5060. {
  5061. reply = TRUE;
  5062. printk(INFO_LEAD "Requesting %d bit transfers, rejecting.\n",
  5063. p->host_no, CTL_OF_SCB(scb), 8 * (0x01 << bus_width));
  5064. }
  5065. } /* We fall through on purpose */
  5066. case MSG_EXT_WDTR_BUS_8_BIT:
  5067. {
  5068. /*
  5069. * According to the spec, if we aren't wide, we also can't be
  5070. * Dual Edge so clear the options byte
  5071. */
  5072. new_trans_options = 0;
  5073. new_bus_width = MSG_EXT_WDTR_BUS_8_BIT;
  5074. break;
  5075. }
  5076. }
  5077. if(reply)
  5078. {
  5079. /* when sending a reply, make sure that the goal settings are
  5080. * updated along with current and active since the code that
  5081. * will actually build the message for the sequencer uses the
  5082. * goal settings as its guidelines.
  5083. */
  5084. aic7xxx_set_width(p, target, channel, lun, new_bus_width,
  5085. AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
  5086. aic_dev);
  5087. syncrate = aic7xxx_find_syncrate(p, &new_period, maxsync,
  5088. &new_trans_options);
  5089. aic7xxx_validate_offset(p, syncrate, &new_offset, new_bus_width);
  5090. aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
  5091. new_offset, new_trans_options,
  5092. AHC_TRANS_GOAL|AHC_TRANS_ACTIVE|AHC_TRANS_CUR,
  5093. aic_dev);
  5094. }
  5095. else
  5096. {
  5097. aic7xxx_set_width(p, target, channel, lun, new_bus_width,
  5098. AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
  5099. syncrate = aic7xxx_find_syncrate(p, &new_period, maxsync,
  5100. &new_trans_options);
  5101. aic7xxx_validate_offset(p, syncrate, &new_offset, new_bus_width);
  5102. aic7xxx_set_syncrate(p, syncrate, target, channel, new_period,
  5103. new_offset, new_trans_options,
  5104. AHC_TRANS_ACTIVE|AHC_TRANS_CUR, aic_dev);
  5105. }
  5106. /*
  5107. * As it turns out, if we don't *have* to have PPR messages, then
  5108. * configure ourselves not to use them since that makes some
  5109. * external drive chassis work (those chassis can't parse PPR
  5110. * messages and they mangle the SCSI bus until you send a WDTR
  5111. * and SDTR that they can understand).
  5112. */
  5113. if(new_trans_options == 0)
  5114. {
  5115. aic_dev->needppr = aic_dev->needppr_copy = 0;
  5116. if(new_offset)
  5117. {
  5118. aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
  5119. }
  5120. if (new_bus_width)
  5121. {
  5122. aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
  5123. }
  5124. }
  5125. if((new_offset == 0) && (offset != 0))
  5126. {
  5127. /*
  5128. * Oops, the syncrate went to low for this card and we fell off
  5129. * to async (should never happen with a device that uses PPR
  5130. * messages, but have to be complete)
  5131. */
  5132. reply = TRUE;
  5133. }
  5134. if(reply)
  5135. {
  5136. scb->flags &= ~SCB_MSGOUT_BITS;
  5137. scb->flags |= SCB_MSGOUT_PPR;
  5138. aic_outb(p, HOST_MSG, MSG_OUT);
  5139. aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
  5140. }
  5141. else
  5142. {
  5143. aic_dev->needppr = 0;
  5144. }
  5145. done = TRUE;
  5146. break;
  5147. }
  5148. default:
  5149. {
  5150. reject = TRUE;
  5151. break;
  5152. }
  5153. } /* end of switch(p->msg_type) */
  5154. } /* end of if (!reject && (p->msg_len > 2)) */
  5155. if (!reply && reject)
  5156. {
  5157. aic_outb(p, MSG_MESSAGE_REJECT, MSG_OUT);
  5158. aic_outb(p, aic_inb(p, SCSISIGO) | ATNO, SCSISIGO);
  5159. done = TRUE;
  5160. }
  5161. return(done);
  5162. }
  5163. /*+F*************************************************************************
  5164. * Function:
  5165. * aic7xxx_handle_reqinit
  5166. *
  5167. * Description:
  5168. * Interrupt handler for REQINIT interrupts (used to transfer messages to
  5169. * and from devices).
  5170. *_F*************************************************************************/
  5171. static void
  5172. aic7xxx_handle_reqinit(struct aic7xxx_host *p, struct aic7xxx_scb *scb)
  5173. {
  5174. unsigned char lastbyte;
  5175. unsigned char phasemis;
  5176. int done = FALSE;
  5177. switch(p->msg_type)
  5178. {
  5179. case MSG_TYPE_INITIATOR_MSGOUT:
  5180. {
  5181. if (p->msg_len == 0)
  5182. panic("aic7xxx: REQINIT with no active message!\n");
  5183. lastbyte = (p->msg_index == (p->msg_len - 1));
  5184. phasemis = ( aic_inb(p, SCSISIGI) & PHASE_MASK) != P_MESGOUT;
  5185. if (lastbyte || phasemis)
  5186. {
  5187. /* Time to end the message */
  5188. p->msg_len = 0;
  5189. p->msg_type = MSG_TYPE_NONE;
  5190. /*
  5191. * NOTE-TO-MYSELF: If you clear the REQINIT after you
  5192. * disable REQINITs, then cases of REJECT_MSG stop working
  5193. * and hang the bus
  5194. */
  5195. aic_outb(p, aic_inb(p, SIMODE1) & ~ENREQINIT, SIMODE1);
  5196. aic_outb(p, CLRSCSIINT, CLRINT);
  5197. p->flags &= ~AHC_HANDLING_REQINITS;
  5198. if (phasemis == 0)
  5199. {
  5200. aic_outb(p, p->msg_buf[p->msg_index], SINDEX);
  5201. aic_outb(p, 0, RETURN_1);
  5202. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5203. if (aic7xxx_verbose > 0xffff)
  5204. printk(INFO_LEAD "Completed sending of REQINIT message.\n",
  5205. p->host_no, CTL_OF_SCB(scb));
  5206. #endif
  5207. }
  5208. else
  5209. {
  5210. aic_outb(p, MSGOUT_PHASEMIS, RETURN_1);
  5211. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5212. if (aic7xxx_verbose > 0xffff)
  5213. printk(INFO_LEAD "PHASEMIS while sending REQINIT message.\n",
  5214. p->host_no, CTL_OF_SCB(scb));
  5215. #endif
  5216. }
  5217. unpause_sequencer(p, TRUE);
  5218. }
  5219. else
  5220. {
  5221. /*
  5222. * Present the byte on the bus (clearing REQINIT) but don't
  5223. * unpause the sequencer.
  5224. */
  5225. aic_outb(p, CLRREQINIT, CLRSINT1);
  5226. aic_outb(p, CLRSCSIINT, CLRINT);
  5227. aic_outb(p, p->msg_buf[p->msg_index++], SCSIDATL);
  5228. }
  5229. break;
  5230. }
  5231. case MSG_TYPE_INITIATOR_MSGIN:
  5232. {
  5233. phasemis = ( aic_inb(p, SCSISIGI) & PHASE_MASK ) != P_MESGIN;
  5234. if (phasemis == 0)
  5235. {
  5236. p->msg_len++;
  5237. /* Pull the byte in without acking it */
  5238. p->msg_buf[p->msg_index] = aic_inb(p, SCSIBUSL);
  5239. done = aic7xxx_parse_msg(p, scb);
  5240. /* Ack the byte */
  5241. aic_outb(p, CLRREQINIT, CLRSINT1);
  5242. aic_outb(p, CLRSCSIINT, CLRINT);
  5243. aic_inb(p, SCSIDATL);
  5244. p->msg_index++;
  5245. }
  5246. if (phasemis || done)
  5247. {
  5248. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5249. if (aic7xxx_verbose > 0xffff)
  5250. {
  5251. if (phasemis)
  5252. printk(INFO_LEAD "PHASEMIS while receiving REQINIT message.\n",
  5253. p->host_no, CTL_OF_SCB(scb));
  5254. else
  5255. printk(INFO_LEAD "Completed receipt of REQINIT message.\n",
  5256. p->host_no, CTL_OF_SCB(scb));
  5257. }
  5258. #endif
  5259. /* Time to end our message session */
  5260. p->msg_len = 0;
  5261. p->msg_type = MSG_TYPE_NONE;
  5262. aic_outb(p, aic_inb(p, SIMODE1) & ~ENREQINIT, SIMODE1);
  5263. aic_outb(p, CLRSCSIINT, CLRINT);
  5264. p->flags &= ~AHC_HANDLING_REQINITS;
  5265. unpause_sequencer(p, TRUE);
  5266. }
  5267. break;
  5268. }
  5269. default:
  5270. {
  5271. panic("aic7xxx: Unknown REQINIT message type.\n");
  5272. break;
  5273. }
  5274. } /* End of switch(p->msg_type) */
  5275. }
  5276. /*+F*************************************************************************
  5277. * Function:
  5278. * aic7xxx_handle_scsiint
  5279. *
  5280. * Description:
  5281. * Interrupt handler for SCSI interrupts (SCSIINT).
  5282. *-F*************************************************************************/
  5283. static void
  5284. aic7xxx_handle_scsiint(struct aic7xxx_host *p, unsigned char intstat)
  5285. {
  5286. unsigned char scb_index;
  5287. unsigned char status;
  5288. struct aic7xxx_scb *scb;
  5289. struct aic_dev_data *aic_dev;
  5290. scb_index = aic_inb(p, SCB_TAG);
  5291. status = aic_inb(p, SSTAT1);
  5292. if (scb_index < p->scb_data->numscbs)
  5293. {
  5294. scb = p->scb_data->scb_array[scb_index];
  5295. if ((scb->flags & SCB_ACTIVE) == 0)
  5296. {
  5297. scb = NULL;
  5298. }
  5299. }
  5300. else
  5301. {
  5302. scb = NULL;
  5303. }
  5304. if ((status & SCSIRSTI) != 0)
  5305. {
  5306. int channel;
  5307. if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
  5308. channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
  5309. else
  5310. channel = 0;
  5311. if (aic7xxx_verbose & VERBOSE_RESET)
  5312. printk(WARN_LEAD "Someone else reset the channel!!\n",
  5313. p->host_no, channel, -1, -1);
  5314. if (aic7xxx_panic_on_abort)
  5315. aic7xxx_panic_abort(p, NULL);
  5316. /*
  5317. * Go through and abort all commands for the channel, but do not
  5318. * reset the channel again.
  5319. */
  5320. aic7xxx_reset_channel(p, channel, /* Initiate Reset */ FALSE);
  5321. aic7xxx_run_done_queue(p, TRUE);
  5322. scb = NULL;
  5323. }
  5324. else if ( ((status & BUSFREE) != 0) && ((status & SELTO) == 0) )
  5325. {
  5326. /*
  5327. * First look at what phase we were last in. If it's message-out,
  5328. * chances are pretty good that the bus free was in response to
  5329. * one of our abort requests.
  5330. */
  5331. unsigned char lastphase = aic_inb(p, LASTPHASE);
  5332. unsigned char saved_tcl = aic_inb(p, SAVED_TCL);
  5333. unsigned char target = (saved_tcl >> 4) & 0x0F;
  5334. int channel;
  5335. int printerror = TRUE;
  5336. if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
  5337. channel = (aic_inb(p, SBLKCTL) & SELBUSB) >> 3;
  5338. else
  5339. channel = 0;
  5340. aic_outb(p, aic_inb(p, SCSISEQ) & (ENSELI|ENRSELI|ENAUTOATNP),
  5341. SCSISEQ);
  5342. if (lastphase == P_MESGOUT)
  5343. {
  5344. unsigned char message;
  5345. message = aic_inb(p, SINDEX);
  5346. if ((message == MSG_ABORT) || (message == MSG_ABORT_TAG))
  5347. {
  5348. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  5349. printk(INFO_LEAD "SCB %d abort delivered.\n", p->host_no,
  5350. CTL_OF_SCB(scb), scb->hscb->tag);
  5351. aic7xxx_reset_device(p, target, channel, ALL_LUNS,
  5352. (message == MSG_ABORT) ? SCB_LIST_NULL : scb->hscb->tag );
  5353. aic7xxx_run_done_queue(p, TRUE);
  5354. scb = NULL;
  5355. printerror = 0;
  5356. }
  5357. else if (message == MSG_BUS_DEV_RESET)
  5358. {
  5359. aic7xxx_handle_device_reset(p, target, channel);
  5360. scb = NULL;
  5361. printerror = 0;
  5362. }
  5363. }
  5364. if ( (scb != NULL) && (scb->flags & SCB_DTR_SCB) )
  5365. {
  5366. /*
  5367. * Hmmm...error during a negotiation command. Either we have a
  5368. * borken bus, or the device doesn't like our negotiation message.
  5369. * Since we check the INQUIRY data of a device before sending it
  5370. * negotiation messages, assume the bus is borken for whatever
  5371. * reason. Complete the command.
  5372. */
  5373. printerror = 0;
  5374. aic7xxx_reset_device(p, target, channel, ALL_LUNS, scb->hscb->tag);
  5375. aic7xxx_run_done_queue(p, TRUE);
  5376. scb = NULL;
  5377. }
  5378. if (printerror != 0)
  5379. {
  5380. if (scb != NULL)
  5381. {
  5382. unsigned char tag;
  5383. if ((scb->hscb->control & TAG_ENB) != 0)
  5384. {
  5385. tag = scb->hscb->tag;
  5386. }
  5387. else
  5388. {
  5389. tag = SCB_LIST_NULL;
  5390. }
  5391. aic7xxx_reset_device(p, target, channel, ALL_LUNS, tag);
  5392. aic7xxx_run_done_queue(p, TRUE);
  5393. }
  5394. else
  5395. {
  5396. aic7xxx_reset_device(p, target, channel, ALL_LUNS, SCB_LIST_NULL);
  5397. aic7xxx_run_done_queue(p, TRUE);
  5398. }
  5399. printk(INFO_LEAD "Unexpected busfree, LASTPHASE = 0x%x, "
  5400. "SEQADDR = 0x%x\n", p->host_no, channel, target, -1, lastphase,
  5401. (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
  5402. scb = NULL;
  5403. }
  5404. aic_outb(p, MSG_NOOP, MSG_OUT);
  5405. aic_outb(p, aic_inb(p, SIMODE1) & ~(ENBUSFREE|ENREQINIT),
  5406. SIMODE1);
  5407. p->flags &= ~AHC_HANDLING_REQINITS;
  5408. aic_outb(p, CLRBUSFREE, CLRSINT1);
  5409. aic_outb(p, CLRSCSIINT, CLRINT);
  5410. restart_sequencer(p);
  5411. unpause_sequencer(p, TRUE);
  5412. }
  5413. else if ((status & SELTO) != 0)
  5414. {
  5415. unsigned char scbptr;
  5416. unsigned char nextscb;
  5417. struct scsi_cmnd *cmd;
  5418. scbptr = aic_inb(p, WAITING_SCBH);
  5419. if (scbptr > p->scb_data->maxhscbs)
  5420. {
  5421. /*
  5422. * I'm still trying to track down exactly how this happens, but until
  5423. * I find it, this code will make sure we aren't passing bogus values
  5424. * into the SCBPTR register, even if that register will just wrap
  5425. * things around, we still don't like having out of range variables.
  5426. *
  5427. * NOTE: Don't check the aic7xxx_verbose variable, I want this message
  5428. * to always be displayed.
  5429. */
  5430. printk(INFO_LEAD "Invalid WAITING_SCBH value %d, improvising.\n",
  5431. p->host_no, -1, -1, -1, scbptr);
  5432. if (p->scb_data->maxhscbs > 4)
  5433. scbptr &= (p->scb_data->maxhscbs - 1);
  5434. else
  5435. scbptr &= 0x03;
  5436. }
  5437. aic_outb(p, scbptr, SCBPTR);
  5438. scb_index = aic_inb(p, SCB_TAG);
  5439. scb = NULL;
  5440. if (scb_index < p->scb_data->numscbs)
  5441. {
  5442. scb = p->scb_data->scb_array[scb_index];
  5443. if ((scb->flags & SCB_ACTIVE) == 0)
  5444. {
  5445. scb = NULL;
  5446. }
  5447. }
  5448. if (scb == NULL)
  5449. {
  5450. printk(WARN_LEAD "Referenced SCB %d not valid during SELTO.\n",
  5451. p->host_no, -1, -1, -1, scb_index);
  5452. printk(KERN_WARNING " SCSISEQ = 0x%x SEQADDR = 0x%x SSTAT0 = 0x%x "
  5453. "SSTAT1 = 0x%x\n", aic_inb(p, SCSISEQ),
  5454. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  5455. aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
  5456. if (aic7xxx_panic_on_abort)
  5457. aic7xxx_panic_abort(p, NULL);
  5458. }
  5459. else
  5460. {
  5461. cmd = scb->cmd;
  5462. cmd->result = (DID_TIME_OUT << 16);
  5463. /*
  5464. * Clear out this hardware SCB
  5465. */
  5466. aic_outb(p, 0, SCB_CONTROL);
  5467. /*
  5468. * Clear out a few values in the card that are in an undetermined
  5469. * state.
  5470. */
  5471. aic_outb(p, MSG_NOOP, MSG_OUT);
  5472. /*
  5473. * Shift the waiting for selection queue forward
  5474. */
  5475. nextscb = aic_inb(p, SCB_NEXT);
  5476. aic_outb(p, nextscb, WAITING_SCBH);
  5477. /*
  5478. * Put this SCB back on the free list.
  5479. */
  5480. aic7xxx_add_curscb_to_free_list(p);
  5481. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5482. if (aic7xxx_verbose > 0xffff)
  5483. printk(INFO_LEAD "Selection Timeout.\n", p->host_no, CTL_OF_SCB(scb));
  5484. #endif
  5485. if (scb->flags & SCB_QUEUED_ABORT)
  5486. {
  5487. /*
  5488. * We know that this particular SCB had to be the queued abort since
  5489. * the disconnected SCB would have gotten a reconnect instead.
  5490. * What we need to do then is to let the command timeout again so
  5491. * we get a reset since this abort just failed.
  5492. */
  5493. cmd->result = 0;
  5494. scb = NULL;
  5495. }
  5496. }
  5497. /*
  5498. * Keep the sequencer from trying to restart any selections
  5499. */
  5500. aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
  5501. /*
  5502. * Make sure the data bits on the bus are released
  5503. * Don't do this on 7770 chipsets, it makes them give us
  5504. * a BRKADDRINT and kills the card.
  5505. */
  5506. if( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI )
  5507. aic_outb(p, 0, SCSIBUSL);
  5508. /*
  5509. * Delay for the selection timeout delay period then stop the selection
  5510. */
  5511. udelay(301);
  5512. aic_outb(p, CLRSELINGO, CLRSINT0);
  5513. /*
  5514. * Clear out all the interrupt status bits
  5515. */
  5516. aic_outb(p, aic_inb(p, SIMODE1) & ~(ENREQINIT|ENBUSFREE), SIMODE1);
  5517. p->flags &= ~AHC_HANDLING_REQINITS;
  5518. aic_outb(p, CLRSELTIMEO | CLRBUSFREE, CLRSINT1);
  5519. aic_outb(p, CLRSCSIINT, CLRINT);
  5520. /*
  5521. * Restarting the sequencer will stop the selection and make sure devices
  5522. * are allowed to reselect in.
  5523. */
  5524. restart_sequencer(p);
  5525. unpause_sequencer(p, TRUE);
  5526. }
  5527. else if (scb == NULL)
  5528. {
  5529. printk(WARN_LEAD "aic7xxx_isr - referenced scb not valid "
  5530. "during scsiint 0x%x scb(%d)\n"
  5531. " SIMODE0 0x%x, SIMODE1 0x%x, SSTAT0 0x%x, SEQADDR 0x%x\n",
  5532. p->host_no, -1, -1, -1, status, scb_index, aic_inb(p, SIMODE0),
  5533. aic_inb(p, SIMODE1), aic_inb(p, SSTAT0),
  5534. (aic_inb(p, SEQADDR1) << 8) | aic_inb(p, SEQADDR0));
  5535. /*
  5536. * Turn off the interrupt and set status to zero, so that it
  5537. * falls through the rest of the SCSIINT code.
  5538. */
  5539. aic_outb(p, status, CLRSINT1);
  5540. aic_outb(p, CLRSCSIINT, CLRINT);
  5541. unpause_sequencer(p, /* unpause always */ TRUE);
  5542. scb = NULL;
  5543. }
  5544. else if (status & SCSIPERR)
  5545. {
  5546. /*
  5547. * Determine the bus phase and queue an appropriate message.
  5548. */
  5549. char *phase;
  5550. struct scsi_cmnd *cmd;
  5551. unsigned char mesg_out = MSG_NOOP;
  5552. unsigned char lastphase = aic_inb(p, LASTPHASE);
  5553. unsigned char sstat2 = aic_inb(p, SSTAT2);
  5554. cmd = scb->cmd;
  5555. switch (lastphase)
  5556. {
  5557. case P_DATAOUT:
  5558. phase = "Data-Out";
  5559. break;
  5560. case P_DATAIN:
  5561. phase = "Data-In";
  5562. mesg_out = MSG_INITIATOR_DET_ERR;
  5563. break;
  5564. case P_COMMAND:
  5565. phase = "Command";
  5566. break;
  5567. case P_MESGOUT:
  5568. phase = "Message-Out";
  5569. break;
  5570. case P_STATUS:
  5571. phase = "Status";
  5572. mesg_out = MSG_INITIATOR_DET_ERR;
  5573. break;
  5574. case P_MESGIN:
  5575. phase = "Message-In";
  5576. mesg_out = MSG_PARITY_ERROR;
  5577. break;
  5578. default:
  5579. phase = "unknown";
  5580. break;
  5581. }
  5582. /*
  5583. * A parity error has occurred during a data
  5584. * transfer phase. Flag it and continue.
  5585. */
  5586. if( (p->features & AHC_ULTRA3) &&
  5587. (aic_inb(p, SCSIRATE) & AHC_SYNCRATE_CRC) &&
  5588. (lastphase == P_DATAIN) )
  5589. {
  5590. printk(WARN_LEAD "CRC error during %s phase.\n",
  5591. p->host_no, CTL_OF_SCB(scb), phase);
  5592. if(sstat2 & CRCVALERR)
  5593. {
  5594. printk(WARN_LEAD " CRC error in intermediate CRC packet.\n",
  5595. p->host_no, CTL_OF_SCB(scb));
  5596. }
  5597. if(sstat2 & CRCENDERR)
  5598. {
  5599. printk(WARN_LEAD " CRC error in ending CRC packet.\n",
  5600. p->host_no, CTL_OF_SCB(scb));
  5601. }
  5602. if(sstat2 & CRCREQERR)
  5603. {
  5604. printk(WARN_LEAD " Target incorrectly requested a CRC packet.\n",
  5605. p->host_no, CTL_OF_SCB(scb));
  5606. }
  5607. if(sstat2 & DUAL_EDGE_ERROR)
  5608. {
  5609. printk(WARN_LEAD " Dual Edge transmission error.\n",
  5610. p->host_no, CTL_OF_SCB(scb));
  5611. }
  5612. }
  5613. else if( (lastphase == P_MESGOUT) &&
  5614. (scb->flags & SCB_MSGOUT_PPR) )
  5615. {
  5616. /*
  5617. * As per the draft specs, any device capable of supporting any of
  5618. * the option values other than 0 are not allowed to reject the
  5619. * PPR message. Instead, they must negotiate out what they do
  5620. * support instead of rejecting our offering or else they cause
  5621. * a parity error during msg_out phase to signal that they don't
  5622. * like our settings.
  5623. */
  5624. aic_dev = AIC_DEV(scb->cmd);
  5625. aic_dev->needppr = aic_dev->needppr_copy = 0;
  5626. aic7xxx_set_width(p, scb->cmd->device->id, scb->cmd->device->channel, scb->cmd->device->lun,
  5627. MSG_EXT_WDTR_BUS_8_BIT,
  5628. (AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE),
  5629. aic_dev);
  5630. aic7xxx_set_syncrate(p, NULL, scb->cmd->device->id, scb->cmd->device->channel, 0, 0,
  5631. 0, AHC_TRANS_ACTIVE|AHC_TRANS_CUR|AHC_TRANS_QUITE,
  5632. aic_dev);
  5633. aic_dev->goal.options = 0;
  5634. scb->flags &= ~SCB_MSGOUT_BITS;
  5635. if(aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  5636. {
  5637. printk(INFO_LEAD "parity error during PPR message, reverting "
  5638. "to WDTR/SDTR\n", p->host_no, CTL_OF_SCB(scb));
  5639. }
  5640. if ( aic_dev->goal.width )
  5641. {
  5642. aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
  5643. }
  5644. if ( aic_dev->goal.offset )
  5645. {
  5646. if( aic_dev->goal.period <= 9 )
  5647. {
  5648. aic_dev->goal.period = 10;
  5649. }
  5650. aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
  5651. }
  5652. scb = NULL;
  5653. }
  5654. /*
  5655. * We've set the hardware to assert ATN if we get a parity
  5656. * error on "in" phases, so all we need to do is stuff the
  5657. * message buffer with the appropriate message. "In" phases
  5658. * have set mesg_out to something other than MSG_NOP.
  5659. */
  5660. if (mesg_out != MSG_NOOP)
  5661. {
  5662. aic_outb(p, mesg_out, MSG_OUT);
  5663. aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
  5664. scb = NULL;
  5665. }
  5666. aic_outb(p, CLRSCSIPERR, CLRSINT1);
  5667. aic_outb(p, CLRSCSIINT, CLRINT);
  5668. unpause_sequencer(p, /* unpause_always */ TRUE);
  5669. }
  5670. else if ( (status & REQINIT) &&
  5671. (p->flags & AHC_HANDLING_REQINITS) )
  5672. {
  5673. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5674. if (aic7xxx_verbose > 0xffff)
  5675. printk(INFO_LEAD "Handling REQINIT, SSTAT1=0x%x.\n", p->host_no,
  5676. CTL_OF_SCB(scb), aic_inb(p, SSTAT1));
  5677. #endif
  5678. aic7xxx_handle_reqinit(p, scb);
  5679. return;
  5680. }
  5681. else
  5682. {
  5683. /*
  5684. * We don't know what's going on. Turn off the
  5685. * interrupt source and try to continue.
  5686. */
  5687. if (aic7xxx_verbose & VERBOSE_SCSIINT)
  5688. printk(INFO_LEAD "Unknown SCSIINT status, SSTAT1(0x%x).\n",
  5689. p->host_no, -1, -1, -1, status);
  5690. aic_outb(p, status, CLRSINT1);
  5691. aic_outb(p, CLRSCSIINT, CLRINT);
  5692. unpause_sequencer(p, /* unpause always */ TRUE);
  5693. scb = NULL;
  5694. }
  5695. if (scb != NULL)
  5696. {
  5697. aic7xxx_done(p, scb);
  5698. }
  5699. }
  5700. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5701. static void
  5702. aic7xxx_check_scbs(struct aic7xxx_host *p, char *buffer)
  5703. {
  5704. unsigned char saved_scbptr, free_scbh, dis_scbh, wait_scbh, temp;
  5705. int i, bogus, lost;
  5706. static unsigned char scb_status[AIC7XXX_MAXSCB];
  5707. #define SCB_NO_LIST 0
  5708. #define SCB_FREE_LIST 1
  5709. #define SCB_WAITING_LIST 2
  5710. #define SCB_DISCONNECTED_LIST 4
  5711. #define SCB_CURRENTLY_ACTIVE 8
  5712. /*
  5713. * Note, these checks will fail on a regular basis once the machine moves
  5714. * beyond the bus scan phase. The problem is race conditions concerning
  5715. * the scbs and where they are linked in. When you have 30 or so commands
  5716. * outstanding on the bus, and run this twice with every interrupt, the
  5717. * chances get pretty good that you'll catch the sequencer with an SCB
  5718. * only partially linked in. Therefore, once we pass the scan phase
  5719. * of the bus, we really should disable this function.
  5720. */
  5721. bogus = FALSE;
  5722. memset(&scb_status[0], 0, sizeof(scb_status));
  5723. pause_sequencer(p);
  5724. saved_scbptr = aic_inb(p, SCBPTR);
  5725. if (saved_scbptr >= p->scb_data->maxhscbs)
  5726. {
  5727. printk("Bogus SCBPTR %d\n", saved_scbptr);
  5728. bogus = TRUE;
  5729. }
  5730. scb_status[saved_scbptr] = SCB_CURRENTLY_ACTIVE;
  5731. free_scbh = aic_inb(p, FREE_SCBH);
  5732. if ( (free_scbh != SCB_LIST_NULL) &&
  5733. (free_scbh >= p->scb_data->maxhscbs) )
  5734. {
  5735. printk("Bogus FREE_SCBH %d\n", free_scbh);
  5736. bogus = TRUE;
  5737. }
  5738. else
  5739. {
  5740. temp = free_scbh;
  5741. while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
  5742. {
  5743. if(scb_status[temp] & 0x07)
  5744. {
  5745. printk("HSCB %d on multiple lists, status 0x%02x", temp,
  5746. scb_status[temp] | SCB_FREE_LIST);
  5747. bogus = TRUE;
  5748. }
  5749. scb_status[temp] |= SCB_FREE_LIST;
  5750. aic_outb(p, temp, SCBPTR);
  5751. temp = aic_inb(p, SCB_NEXT);
  5752. }
  5753. }
  5754. dis_scbh = aic_inb(p, DISCONNECTED_SCBH);
  5755. if ( (dis_scbh != SCB_LIST_NULL) &&
  5756. (dis_scbh >= p->scb_data->maxhscbs) )
  5757. {
  5758. printk("Bogus DISCONNECTED_SCBH %d\n", dis_scbh);
  5759. bogus = TRUE;
  5760. }
  5761. else
  5762. {
  5763. temp = dis_scbh;
  5764. while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
  5765. {
  5766. if(scb_status[temp] & 0x07)
  5767. {
  5768. printk("HSCB %d on multiple lists, status 0x%02x", temp,
  5769. scb_status[temp] | SCB_DISCONNECTED_LIST);
  5770. bogus = TRUE;
  5771. }
  5772. scb_status[temp] |= SCB_DISCONNECTED_LIST;
  5773. aic_outb(p, temp, SCBPTR);
  5774. temp = aic_inb(p, SCB_NEXT);
  5775. }
  5776. }
  5777. wait_scbh = aic_inb(p, WAITING_SCBH);
  5778. if ( (wait_scbh != SCB_LIST_NULL) &&
  5779. (wait_scbh >= p->scb_data->maxhscbs) )
  5780. {
  5781. printk("Bogus WAITING_SCBH %d\n", wait_scbh);
  5782. bogus = TRUE;
  5783. }
  5784. else
  5785. {
  5786. temp = wait_scbh;
  5787. while( (temp != SCB_LIST_NULL) && (temp < p->scb_data->maxhscbs) )
  5788. {
  5789. if(scb_status[temp] & 0x07)
  5790. {
  5791. printk("HSCB %d on multiple lists, status 0x%02x", temp,
  5792. scb_status[temp] | SCB_WAITING_LIST);
  5793. bogus = TRUE;
  5794. }
  5795. scb_status[temp] |= SCB_WAITING_LIST;
  5796. aic_outb(p, temp, SCBPTR);
  5797. temp = aic_inb(p, SCB_NEXT);
  5798. }
  5799. }
  5800. lost=0;
  5801. for(i=0; i < p->scb_data->maxhscbs; i++)
  5802. {
  5803. aic_outb(p, i, SCBPTR);
  5804. temp = aic_inb(p, SCB_NEXT);
  5805. if ( ((temp != SCB_LIST_NULL) &&
  5806. (temp >= p->scb_data->maxhscbs)) )
  5807. {
  5808. printk("HSCB %d bad, SCB_NEXT invalid(%d).\n", i, temp);
  5809. bogus = TRUE;
  5810. }
  5811. if ( temp == i )
  5812. {
  5813. printk("HSCB %d bad, SCB_NEXT points to self.\n", i);
  5814. bogus = TRUE;
  5815. }
  5816. if (scb_status[i] == 0)
  5817. lost++;
  5818. if (lost > 1)
  5819. {
  5820. printk("Too many lost scbs.\n");
  5821. bogus=TRUE;
  5822. }
  5823. }
  5824. aic_outb(p, saved_scbptr, SCBPTR);
  5825. unpause_sequencer(p, FALSE);
  5826. if (bogus)
  5827. {
  5828. printk("Bogus parameters found in card SCB array structures.\n");
  5829. printk("%s\n", buffer);
  5830. aic7xxx_panic_abort(p, NULL);
  5831. }
  5832. return;
  5833. }
  5834. #endif
  5835. /*+F*************************************************************************
  5836. * Function:
  5837. * aic7xxx_handle_command_completion_intr
  5838. *
  5839. * Description:
  5840. * SCSI command completion interrupt handler.
  5841. *-F*************************************************************************/
  5842. static void
  5843. aic7xxx_handle_command_completion_intr(struct aic7xxx_host *p)
  5844. {
  5845. struct aic7xxx_scb *scb = NULL;
  5846. struct aic_dev_data *aic_dev;
  5847. struct scsi_cmnd *cmd;
  5848. unsigned char scb_index, tindex;
  5849. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5850. if( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) )
  5851. printk(INFO_LEAD "Command Complete Int.\n", p->host_no, -1, -1, -1);
  5852. #endif
  5853. /*
  5854. * Read the INTSTAT location after clearing the CMDINT bit. This forces
  5855. * any posted PCI writes to flush to memory. Gerard Roudier suggested
  5856. * this fix to the possible race of clearing the CMDINT bit but not
  5857. * having all command bytes flushed onto the qoutfifo.
  5858. */
  5859. aic_outb(p, CLRCMDINT, CLRINT);
  5860. aic_inb(p, INTSTAT);
  5861. /*
  5862. * The sequencer will continue running when it
  5863. * issues this interrupt. There may be >1 commands
  5864. * finished, so loop until we've processed them all.
  5865. */
  5866. while (p->qoutfifo[p->qoutfifonext] != SCB_LIST_NULL)
  5867. {
  5868. scb_index = p->qoutfifo[p->qoutfifonext];
  5869. p->qoutfifo[p->qoutfifonext++] = SCB_LIST_NULL;
  5870. if ( scb_index >= p->scb_data->numscbs )
  5871. {
  5872. printk(WARN_LEAD "CMDCMPLT with invalid SCB index %d\n", p->host_no,
  5873. -1, -1, -1, scb_index);
  5874. continue;
  5875. }
  5876. scb = p->scb_data->scb_array[scb_index];
  5877. if (!(scb->flags & SCB_ACTIVE) || (scb->cmd == NULL))
  5878. {
  5879. printk(WARN_LEAD "CMDCMPLT without command for SCB %d, SCB flags "
  5880. "0x%x, cmd 0x%lx\n", p->host_no, -1, -1, -1, scb_index, scb->flags,
  5881. (unsigned long) scb->cmd);
  5882. continue;
  5883. }
  5884. tindex = TARGET_INDEX(scb->cmd);
  5885. aic_dev = AIC_DEV(scb->cmd);
  5886. if (scb->flags & SCB_QUEUED_ABORT)
  5887. {
  5888. pause_sequencer(p);
  5889. if ( ((aic_inb(p, LASTPHASE) & PHASE_MASK) != P_BUSFREE) &&
  5890. (aic_inb(p, SCB_TAG) == scb->hscb->tag) )
  5891. {
  5892. unpause_sequencer(p, FALSE);
  5893. continue;
  5894. }
  5895. aic7xxx_reset_device(p, scb->cmd->device->id, scb->cmd->device->channel,
  5896. scb->cmd->device->lun, scb->hscb->tag);
  5897. scb->flags &= ~(SCB_QUEUED_FOR_DONE | SCB_RESET | SCB_ABORT |
  5898. SCB_QUEUED_ABORT);
  5899. unpause_sequencer(p, FALSE);
  5900. }
  5901. else if (scb->flags & SCB_ABORT)
  5902. {
  5903. /*
  5904. * We started to abort this, but it completed on us, let it
  5905. * through as successful
  5906. */
  5907. scb->flags &= ~(SCB_ABORT|SCB_RESET);
  5908. }
  5909. else if (scb->flags & SCB_SENSE)
  5910. {
  5911. char *buffer = &scb->cmd->sense_buffer[0];
  5912. if (buffer[12] == 0x47 || buffer[12] == 0x54)
  5913. {
  5914. /*
  5915. * Signal that we need to re-negotiate things.
  5916. */
  5917. aic_dev->needppr = aic_dev->needppr_copy;
  5918. aic_dev->needsdtr = aic_dev->needsdtr_copy;
  5919. aic_dev->needwdtr = aic_dev->needwdtr_copy;
  5920. }
  5921. }
  5922. cmd = scb->cmd;
  5923. if (scb->hscb->residual_SG_segment_count != 0)
  5924. {
  5925. aic7xxx_calculate_residual(p, scb);
  5926. }
  5927. cmd->result |= (aic7xxx_error(cmd) << 16);
  5928. aic7xxx_done(p, scb);
  5929. }
  5930. }
  5931. /*+F*************************************************************************
  5932. * Function:
  5933. * aic7xxx_isr
  5934. *
  5935. * Description:
  5936. * SCSI controller interrupt handler.
  5937. *-F*************************************************************************/
  5938. static void
  5939. aic7xxx_isr(void *dev_id)
  5940. {
  5941. struct aic7xxx_host *p;
  5942. unsigned char intstat;
  5943. p = dev_id;
  5944. /*
  5945. * Just a few sanity checks. Make sure that we have an int pending.
  5946. * Also, if PCI, then we are going to check for a PCI bus error status
  5947. * should we get too many spurious interrupts.
  5948. */
  5949. if (!((intstat = aic_inb(p, INTSTAT)) & INT_PEND))
  5950. {
  5951. #ifdef CONFIG_PCI
  5952. if ( (p->chip & AHC_PCI) && (p->spurious_int > 500) &&
  5953. !(p->flags & AHC_HANDLING_REQINITS) )
  5954. {
  5955. if ( aic_inb(p, ERROR) & PCIERRSTAT )
  5956. {
  5957. aic7xxx_pci_intr(p);
  5958. }
  5959. p->spurious_int = 0;
  5960. }
  5961. else if ( !(p->flags & AHC_HANDLING_REQINITS) )
  5962. {
  5963. p->spurious_int++;
  5964. }
  5965. #endif
  5966. return;
  5967. }
  5968. p->spurious_int = 0;
  5969. /*
  5970. * Keep track of interrupts for /proc/scsi
  5971. */
  5972. p->isr_count++;
  5973. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  5974. if ( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) &&
  5975. (aic7xxx_panic_on_abort) && (p->flags & AHC_PAGESCBS) )
  5976. aic7xxx_check_scbs(p, "Bogus settings at start of interrupt.");
  5977. #endif
  5978. /*
  5979. * Handle all the interrupt sources - especially for SCSI
  5980. * interrupts, we won't get a second chance at them.
  5981. */
  5982. if (intstat & CMDCMPLT)
  5983. {
  5984. aic7xxx_handle_command_completion_intr(p);
  5985. }
  5986. if (intstat & BRKADRINT)
  5987. {
  5988. int i;
  5989. unsigned char errno = aic_inb(p, ERROR);
  5990. printk(KERN_ERR "(scsi%d) BRKADRINT error(0x%x):\n", p->host_no, errno);
  5991. for (i = 0; i < ARRAY_SIZE(hard_error); i++)
  5992. {
  5993. if (errno & hard_error[i].errno)
  5994. {
  5995. printk(KERN_ERR " %s\n", hard_error[i].errmesg);
  5996. }
  5997. }
  5998. printk(KERN_ERR "(scsi%d) SEQADDR=0x%x\n", p->host_no,
  5999. (((aic_inb(p, SEQADDR1) << 8) & 0x100) | aic_inb(p, SEQADDR0)));
  6000. if (aic7xxx_panic_on_abort)
  6001. aic7xxx_panic_abort(p, NULL);
  6002. #ifdef CONFIG_PCI
  6003. if (errno & PCIERRSTAT)
  6004. aic7xxx_pci_intr(p);
  6005. #endif
  6006. if (errno & (SQPARERR | ILLOPCODE | ILLSADDR))
  6007. {
  6008. panic("aic7xxx: unrecoverable BRKADRINT.\n");
  6009. }
  6010. if (errno & ILLHADDR)
  6011. {
  6012. printk(KERN_ERR "(scsi%d) BUG! Driver accessed chip without first "
  6013. "pausing controller!\n", p->host_no);
  6014. }
  6015. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  6016. if (errno & DPARERR)
  6017. {
  6018. if (aic_inb(p, DMAPARAMS) & DIRECTION)
  6019. printk("(scsi%d) while DMAing SCB from host to card.\n", p->host_no);
  6020. else
  6021. printk("(scsi%d) while DMAing SCB from card to host.\n", p->host_no);
  6022. }
  6023. #endif
  6024. aic_outb(p, CLRPARERR | CLRBRKADRINT, CLRINT);
  6025. unpause_sequencer(p, FALSE);
  6026. }
  6027. if (intstat & SEQINT)
  6028. {
  6029. /*
  6030. * Read the CCSCBCTL register to work around a bug in the Ultra2 cards
  6031. */
  6032. if(p->features & AHC_ULTRA2)
  6033. {
  6034. aic_inb(p, CCSCBCTL);
  6035. }
  6036. aic7xxx_handle_seqint(p, intstat);
  6037. }
  6038. if (intstat & SCSIINT)
  6039. {
  6040. aic7xxx_handle_scsiint(p, intstat);
  6041. }
  6042. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  6043. if ( (p->isr_count < 16) && (aic7xxx_verbose > 0xffff) &&
  6044. (aic7xxx_panic_on_abort) && (p->flags & AHC_PAGESCBS) )
  6045. aic7xxx_check_scbs(p, "Bogus settings at end of interrupt.");
  6046. #endif
  6047. }
  6048. /*+F*************************************************************************
  6049. * Function:
  6050. * do_aic7xxx_isr
  6051. *
  6052. * Description:
  6053. * This is a gross hack to solve a problem in linux kernels 2.1.85 and
  6054. * above. Please, children, do not try this at home, and if you ever see
  6055. * anything like it, please inform the Gross Hack Police immediately
  6056. *-F*************************************************************************/
  6057. static irqreturn_t
  6058. do_aic7xxx_isr(int irq, void *dev_id)
  6059. {
  6060. unsigned long cpu_flags;
  6061. struct aic7xxx_host *p;
  6062. p = (struct aic7xxx_host *)dev_id;
  6063. if(!p)
  6064. return IRQ_NONE;
  6065. spin_lock_irqsave(p->host->host_lock, cpu_flags);
  6066. p->flags |= AHC_IN_ISR;
  6067. do
  6068. {
  6069. aic7xxx_isr(dev_id);
  6070. } while ( (aic_inb(p, INTSTAT) & INT_PEND) );
  6071. aic7xxx_done_cmds_complete(p);
  6072. aic7xxx_run_waiting_queues(p);
  6073. p->flags &= ~AHC_IN_ISR;
  6074. spin_unlock_irqrestore(p->host->host_lock, cpu_flags);
  6075. return IRQ_HANDLED;
  6076. }
  6077. /*+F*************************************************************************
  6078. * Function:
  6079. * aic7xxx_init_transinfo
  6080. *
  6081. * Description:
  6082. * Set up the initial aic_dev values from the BIOS settings and from
  6083. * INQUIRY results
  6084. *-F*************************************************************************/
  6085. static void
  6086. aic7xxx_init_transinfo(struct aic7xxx_host *p, struct aic_dev_data *aic_dev)
  6087. {
  6088. struct scsi_device *sdpnt = aic_dev->SDptr;
  6089. unsigned char tindex;
  6090. tindex = sdpnt->id | (sdpnt->channel << 3);
  6091. if (!(aic_dev->flags & DEVICE_DTR_SCANNED))
  6092. {
  6093. aic_dev->flags |= DEVICE_DTR_SCANNED;
  6094. if ( sdpnt->wdtr && (p->features & AHC_WIDE) )
  6095. {
  6096. aic_dev->needwdtr = aic_dev->needwdtr_copy = 1;
  6097. aic_dev->goal.width = p->user[tindex].width;
  6098. }
  6099. else
  6100. {
  6101. aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
  6102. pause_sequencer(p);
  6103. aic7xxx_set_width(p, sdpnt->id, sdpnt->channel, sdpnt->lun,
  6104. MSG_EXT_WDTR_BUS_8_BIT, (AHC_TRANS_ACTIVE |
  6105. AHC_TRANS_GOAL |
  6106. AHC_TRANS_CUR), aic_dev );
  6107. unpause_sequencer(p, FALSE);
  6108. }
  6109. if ( sdpnt->sdtr && p->user[tindex].offset )
  6110. {
  6111. aic_dev->goal.period = p->user[tindex].period;
  6112. aic_dev->goal.options = p->user[tindex].options;
  6113. if (p->features & AHC_ULTRA2)
  6114. aic_dev->goal.offset = MAX_OFFSET_ULTRA2;
  6115. else if (aic_dev->goal.width == MSG_EXT_WDTR_BUS_16_BIT)
  6116. aic_dev->goal.offset = MAX_OFFSET_16BIT;
  6117. else
  6118. aic_dev->goal.offset = MAX_OFFSET_8BIT;
  6119. if ( sdpnt->ppr && p->user[tindex].period <= 9 &&
  6120. p->user[tindex].options )
  6121. {
  6122. aic_dev->needppr = aic_dev->needppr_copy = 1;
  6123. aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
  6124. aic_dev->needwdtr = aic_dev->needwdtr_copy = 0;
  6125. aic_dev->flags |= DEVICE_SCSI_3;
  6126. }
  6127. else
  6128. {
  6129. aic_dev->needsdtr = aic_dev->needsdtr_copy = 1;
  6130. aic_dev->goal.period = max_t(unsigned char, 10, aic_dev->goal.period);
  6131. aic_dev->goal.options = 0;
  6132. }
  6133. }
  6134. else
  6135. {
  6136. aic_dev->needsdtr = aic_dev->needsdtr_copy = 0;
  6137. aic_dev->goal.period = 255;
  6138. aic_dev->goal.offset = 0;
  6139. aic_dev->goal.options = 0;
  6140. }
  6141. aic_dev->flags |= DEVICE_PRINT_DTR;
  6142. }
  6143. }
  6144. /*+F*************************************************************************
  6145. * Function:
  6146. * aic7xxx_slave_alloc
  6147. *
  6148. * Description:
  6149. * Set up the initial aic_dev struct pointers
  6150. *-F*************************************************************************/
  6151. static int
  6152. aic7xxx_slave_alloc(struct scsi_device *SDptr)
  6153. {
  6154. struct aic7xxx_host *p = (struct aic7xxx_host *)SDptr->host->hostdata;
  6155. struct aic_dev_data *aic_dev;
  6156. aic_dev = kmalloc(sizeof(struct aic_dev_data), GFP_ATOMIC | GFP_KERNEL);
  6157. if(!aic_dev)
  6158. return 1;
  6159. /*
  6160. * Check to see if channel was scanned.
  6161. */
  6162. if (!(p->flags & AHC_A_SCANNED) && (SDptr->channel == 0))
  6163. {
  6164. if (aic7xxx_verbose & VERBOSE_PROBE2)
  6165. printk(INFO_LEAD "Scanning channel for devices.\n",
  6166. p->host_no, 0, -1, -1);
  6167. p->flags |= AHC_A_SCANNED;
  6168. }
  6169. else
  6170. {
  6171. if (!(p->flags & AHC_B_SCANNED) && (SDptr->channel == 1))
  6172. {
  6173. if (aic7xxx_verbose & VERBOSE_PROBE2)
  6174. printk(INFO_LEAD "Scanning channel for devices.\n",
  6175. p->host_no, 1, -1, -1);
  6176. p->flags |= AHC_B_SCANNED;
  6177. }
  6178. }
  6179. memset(aic_dev, 0, sizeof(struct aic_dev_data));
  6180. SDptr->hostdata = aic_dev;
  6181. aic_dev->SDptr = SDptr;
  6182. aic_dev->max_q_depth = 1;
  6183. aic_dev->temp_q_depth = 1;
  6184. scbq_init(&aic_dev->delayed_scbs);
  6185. INIT_LIST_HEAD(&aic_dev->list);
  6186. list_add_tail(&aic_dev->list, &p->aic_devs);
  6187. return 0;
  6188. }
  6189. /*+F*************************************************************************
  6190. * Function:
  6191. * aic7xxx_device_queue_depth
  6192. *
  6193. * Description:
  6194. * Determines the queue depth for a given device. There are two ways
  6195. * a queue depth can be obtained for a tagged queueing device. One
  6196. * way is the default queue depth which is determined by whether
  6197. * aic7xxx_default_queue_depth. The other is by the aic7xxx_tag_info
  6198. * array.
  6199. *
  6200. * If tagged queueing isn't supported on the device, then we set the
  6201. * depth to p->host->hostt->cmd_per_lun for internal driver queueing.
  6202. * as the default queue depth. Otherwise, we use either 4 or 8 as the
  6203. * default queue depth (dependent on the number of hardware SCBs).
  6204. * The other way we determine queue depth is through the use of the
  6205. * aic7xxx_tag_info array which is enabled by defining
  6206. * AIC7XXX_TAGGED_QUEUEING_BY_DEVICE. This array can be initialized
  6207. * with queue depths for individual devices. It also allows tagged
  6208. * queueing to be [en|dis]abled for a specific adapter.
  6209. *-F*************************************************************************/
  6210. static void
  6211. aic7xxx_device_queue_depth(struct aic7xxx_host *p, struct scsi_device *device)
  6212. {
  6213. int tag_enabled = FALSE;
  6214. struct aic_dev_data *aic_dev = device->hostdata;
  6215. unsigned char tindex;
  6216. tindex = device->id | (device->channel << 3);
  6217. if (device->simple_tags)
  6218. return; // We've already enabled this device
  6219. if (device->tagged_supported)
  6220. {
  6221. tag_enabled = TRUE;
  6222. if (!(p->discenable & (1 << tindex)))
  6223. {
  6224. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  6225. printk(INFO_LEAD "Disconnection disabled, unable to "
  6226. "enable tagged queueing.\n",
  6227. p->host_no, device->channel, device->id, device->lun);
  6228. tag_enabled = FALSE;
  6229. }
  6230. else
  6231. {
  6232. if (p->instance >= ARRAY_SIZE(aic7xxx_tag_info))
  6233. {
  6234. static int print_warning = TRUE;
  6235. if(print_warning)
  6236. {
  6237. printk(KERN_INFO "aic7xxx: WARNING, insufficient tag_info instances for"
  6238. " installed controllers.\n");
  6239. printk(KERN_INFO "aic7xxx: Please update the aic7xxx_tag_info array in"
  6240. " the aic7xxx.c source file.\n");
  6241. print_warning = FALSE;
  6242. }
  6243. aic_dev->max_q_depth = aic_dev->temp_q_depth =
  6244. aic7xxx_default_queue_depth;
  6245. }
  6246. else
  6247. {
  6248. if (aic7xxx_tag_info[p->instance].tag_commands[tindex] == 255)
  6249. {
  6250. tag_enabled = FALSE;
  6251. }
  6252. else if (aic7xxx_tag_info[p->instance].tag_commands[tindex] == 0)
  6253. {
  6254. aic_dev->max_q_depth = aic_dev->temp_q_depth =
  6255. aic7xxx_default_queue_depth;
  6256. }
  6257. else
  6258. {
  6259. aic_dev->max_q_depth = aic_dev->temp_q_depth =
  6260. aic7xxx_tag_info[p->instance].tag_commands[tindex];
  6261. }
  6262. }
  6263. }
  6264. }
  6265. if (tag_enabled)
  6266. {
  6267. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  6268. {
  6269. printk(INFO_LEAD "Tagged queuing enabled, queue depth %d.\n",
  6270. p->host_no, device->channel, device->id,
  6271. device->lun, aic_dev->max_q_depth);
  6272. }
  6273. scsi_adjust_queue_depth(device, MSG_ORDERED_TAG, aic_dev->max_q_depth);
  6274. }
  6275. else
  6276. {
  6277. if (aic7xxx_verbose & VERBOSE_NEGOTIATION2)
  6278. {
  6279. printk(INFO_LEAD "Tagged queuing disabled, queue depth %d.\n",
  6280. p->host_no, device->channel, device->id,
  6281. device->lun, device->host->cmd_per_lun);
  6282. }
  6283. scsi_adjust_queue_depth(device, 0, device->host->cmd_per_lun);
  6284. }
  6285. return;
  6286. }
  6287. /*+F*************************************************************************
  6288. * Function:
  6289. * aic7xxx_slave_destroy
  6290. *
  6291. * Description:
  6292. * prepare for this device to go away
  6293. *-F*************************************************************************/
  6294. static void
  6295. aic7xxx_slave_destroy(struct scsi_device *SDptr)
  6296. {
  6297. struct aic_dev_data *aic_dev = SDptr->hostdata;
  6298. list_del(&aic_dev->list);
  6299. SDptr->hostdata = NULL;
  6300. kfree(aic_dev);
  6301. return;
  6302. }
  6303. /*+F*************************************************************************
  6304. * Function:
  6305. * aic7xxx_slave_configure
  6306. *
  6307. * Description:
  6308. * Configure the device we are attaching to the controller. This is
  6309. * where we get to do things like scan the INQUIRY data, set queue
  6310. * depths, allocate command structs, etc.
  6311. *-F*************************************************************************/
  6312. static int
  6313. aic7xxx_slave_configure(struct scsi_device *SDptr)
  6314. {
  6315. struct aic7xxx_host *p = (struct aic7xxx_host *) SDptr->host->hostdata;
  6316. struct aic_dev_data *aic_dev;
  6317. int scbnum;
  6318. aic_dev = (struct aic_dev_data *)SDptr->hostdata;
  6319. aic7xxx_init_transinfo(p, aic_dev);
  6320. aic7xxx_device_queue_depth(p, SDptr);
  6321. if(list_empty(&aic_dev->list))
  6322. list_add_tail(&aic_dev->list, &p->aic_devs);
  6323. scbnum = 0;
  6324. list_for_each_entry(aic_dev, &p->aic_devs, list) {
  6325. scbnum += aic_dev->max_q_depth;
  6326. }
  6327. while (scbnum > p->scb_data->numscbs)
  6328. {
  6329. /*
  6330. * Pre-allocate the needed SCBs to get around the possibility of having
  6331. * to allocate some when memory is more or less exhausted and we need
  6332. * the SCB in order to perform a swap operation (possible deadlock)
  6333. */
  6334. if ( aic7xxx_allocate_scb(p) == 0 )
  6335. break;
  6336. }
  6337. return(0);
  6338. }
  6339. /*+F*************************************************************************
  6340. * Function:
  6341. * aic7xxx_probe
  6342. *
  6343. * Description:
  6344. * Probing for EISA boards: it looks like the first two bytes
  6345. * are a manufacturer code - three characters, five bits each:
  6346. *
  6347. * BYTE 0 BYTE 1 BYTE 2 BYTE 3
  6348. * ?1111122 22233333 PPPPPPPP RRRRRRRR
  6349. *
  6350. * The characters are baselined off ASCII '@', so add that value
  6351. * to each to get the real ASCII code for it. The next two bytes
  6352. * appear to be a product and revision number, probably vendor-
  6353. * specific. This is what is being searched for at each port,
  6354. * and what should probably correspond to the ID= field in the
  6355. * ECU's .cfg file for the card - if your card is not detected,
  6356. * make sure your signature is listed in the array.
  6357. *
  6358. * The fourth byte's lowest bit seems to be an enabled/disabled
  6359. * flag (rest of the bits are reserved?).
  6360. *
  6361. * NOTE: This function is only needed on Intel and Alpha platforms,
  6362. * the other platforms we support don't have EISA/VLB busses. So,
  6363. * we #ifdef this entire function to avoid compiler warnings about
  6364. * an unused function.
  6365. *-F*************************************************************************/
  6366. #if defined(__i386__) || defined(__alpha__)
  6367. static int
  6368. aic7xxx_probe(int slot, int base, ahc_flag_type *flags)
  6369. {
  6370. int i;
  6371. unsigned char buf[4];
  6372. static struct {
  6373. int n;
  6374. unsigned char signature[sizeof(buf)];
  6375. ahc_chip type;
  6376. int bios_disabled;
  6377. } AIC7xxx[] = {
  6378. { 4, { 0x04, 0x90, 0x77, 0x70 },
  6379. AHC_AIC7770|AHC_EISA, FALSE }, /* mb 7770 */
  6380. { 4, { 0x04, 0x90, 0x77, 0x71 },
  6381. AHC_AIC7770|AHC_EISA, FALSE }, /* host adapter 274x */
  6382. { 4, { 0x04, 0x90, 0x77, 0x56 },
  6383. AHC_AIC7770|AHC_VL, FALSE }, /* 284x BIOS enabled */
  6384. { 4, { 0x04, 0x90, 0x77, 0x57 },
  6385. AHC_AIC7770|AHC_VL, TRUE } /* 284x BIOS disabled */
  6386. };
  6387. /*
  6388. * The VL-bus cards need to be primed by
  6389. * writing before a signature check.
  6390. */
  6391. for (i = 0; i < sizeof(buf); i++)
  6392. {
  6393. outb(0x80 + i, base);
  6394. buf[i] = inb(base + i);
  6395. }
  6396. for (i = 0; i < ARRAY_SIZE(AIC7xxx); i++)
  6397. {
  6398. /*
  6399. * Signature match on enabled card?
  6400. */
  6401. if (!memcmp(buf, AIC7xxx[i].signature, AIC7xxx[i].n))
  6402. {
  6403. if (inb(base + 4) & 1)
  6404. {
  6405. if (AIC7xxx[i].bios_disabled)
  6406. {
  6407. *flags |= AHC_USEDEFAULTS;
  6408. }
  6409. else
  6410. {
  6411. *flags |= AHC_BIOS_ENABLED;
  6412. }
  6413. return (i);
  6414. }
  6415. printk("aic7xxx: <Adaptec 7770 SCSI Host Adapter> "
  6416. "disabled at slot %d, ignored.\n", slot);
  6417. }
  6418. }
  6419. return (-1);
  6420. }
  6421. #endif /* (__i386__) || (__alpha__) */
  6422. /*+F*************************************************************************
  6423. * Function:
  6424. * read_2840_seeprom
  6425. *
  6426. * Description:
  6427. * Reads the 2840 serial EEPROM and returns 1 if successful and 0 if
  6428. * not successful.
  6429. *
  6430. * See read_seeprom (for the 2940) for the instruction set of the 93C46
  6431. * chip.
  6432. *
  6433. * The 2840 interface to the 93C46 serial EEPROM is through the
  6434. * STATUS_2840 and SEECTL_2840 registers. The CS_2840, CK_2840, and
  6435. * DO_2840 bits of the SEECTL_2840 register are connected to the chip
  6436. * select, clock, and data out lines respectively of the serial EEPROM.
  6437. * The DI_2840 bit of the STATUS_2840 is connected to the data in line
  6438. * of the serial EEPROM. The EEPROM_TF bit of STATUS_2840 register is
  6439. * useful in that it gives us an 800 nsec timer. After a read from the
  6440. * SEECTL_2840 register the timing flag is cleared and goes high 800 nsec
  6441. * later.
  6442. *-F*************************************************************************/
  6443. static int
  6444. read_284x_seeprom(struct aic7xxx_host *p, struct seeprom_config *sc)
  6445. {
  6446. int i = 0, k = 0;
  6447. unsigned char temp;
  6448. unsigned short checksum = 0;
  6449. unsigned short *seeprom = (unsigned short *) sc;
  6450. struct seeprom_cmd {
  6451. unsigned char len;
  6452. unsigned char bits[3];
  6453. };
  6454. struct seeprom_cmd seeprom_read = {3, {1, 1, 0}};
  6455. #define CLOCK_PULSE(p) \
  6456. while ((aic_inb(p, STATUS_2840) & EEPROM_TF) == 0) \
  6457. { \
  6458. ; /* Do nothing */ \
  6459. } \
  6460. (void) aic_inb(p, SEECTL_2840);
  6461. /*
  6462. * Read the first 32 registers of the seeprom. For the 2840,
  6463. * the 93C46 SEEPROM is a 1024-bit device with 64 16-bit registers
  6464. * but only the first 32 are used by Adaptec BIOS. The loop
  6465. * will range from 0 to 31.
  6466. */
  6467. for (k = 0; k < (sizeof(*sc) / 2); k++)
  6468. {
  6469. /*
  6470. * Send chip select for one clock cycle.
  6471. */
  6472. aic_outb(p, CK_2840 | CS_2840, SEECTL_2840);
  6473. CLOCK_PULSE(p);
  6474. /*
  6475. * Now we're ready to send the read command followed by the
  6476. * address of the 16-bit register we want to read.
  6477. */
  6478. for (i = 0; i < seeprom_read.len; i++)
  6479. {
  6480. temp = CS_2840 | seeprom_read.bits[i];
  6481. aic_outb(p, temp, SEECTL_2840);
  6482. CLOCK_PULSE(p);
  6483. temp = temp ^ CK_2840;
  6484. aic_outb(p, temp, SEECTL_2840);
  6485. CLOCK_PULSE(p);
  6486. }
  6487. /*
  6488. * Send the 6 bit address (MSB first, LSB last).
  6489. */
  6490. for (i = 5; i >= 0; i--)
  6491. {
  6492. temp = k;
  6493. temp = (temp >> i) & 1; /* Mask out all but lower bit. */
  6494. temp = CS_2840 | temp;
  6495. aic_outb(p, temp, SEECTL_2840);
  6496. CLOCK_PULSE(p);
  6497. temp = temp ^ CK_2840;
  6498. aic_outb(p, temp, SEECTL_2840);
  6499. CLOCK_PULSE(p);
  6500. }
  6501. /*
  6502. * Now read the 16 bit register. An initial 0 precedes the
  6503. * register contents which begins with bit 15 (MSB) and ends
  6504. * with bit 0 (LSB). The initial 0 will be shifted off the
  6505. * top of our word as we let the loop run from 0 to 16.
  6506. */
  6507. for (i = 0; i <= 16; i++)
  6508. {
  6509. temp = CS_2840;
  6510. aic_outb(p, temp, SEECTL_2840);
  6511. CLOCK_PULSE(p);
  6512. temp = temp ^ CK_2840;
  6513. seeprom[k] = (seeprom[k] << 1) | (aic_inb(p, STATUS_2840) & DI_2840);
  6514. aic_outb(p, temp, SEECTL_2840);
  6515. CLOCK_PULSE(p);
  6516. }
  6517. /*
  6518. * The serial EEPROM has a checksum in the last word. Keep a
  6519. * running checksum for all words read except for the last
  6520. * word. We'll verify the checksum after all words have been
  6521. * read.
  6522. */
  6523. if (k < (sizeof(*sc) / 2) - 1)
  6524. {
  6525. checksum = checksum + seeprom[k];
  6526. }
  6527. /*
  6528. * Reset the chip select for the next command cycle.
  6529. */
  6530. aic_outb(p, 0, SEECTL_2840);
  6531. CLOCK_PULSE(p);
  6532. aic_outb(p, CK_2840, SEECTL_2840);
  6533. CLOCK_PULSE(p);
  6534. aic_outb(p, 0, SEECTL_2840);
  6535. CLOCK_PULSE(p);
  6536. }
  6537. #if 0
  6538. printk("Computed checksum 0x%x, checksum read 0x%x\n", checksum, sc->checksum);
  6539. printk("Serial EEPROM:");
  6540. for (k = 0; k < (sizeof(*sc) / 2); k++)
  6541. {
  6542. if (((k % 8) == 0) && (k != 0))
  6543. {
  6544. printk("\n ");
  6545. }
  6546. printk(" 0x%x", seeprom[k]);
  6547. }
  6548. printk("\n");
  6549. #endif
  6550. if (checksum != sc->checksum)
  6551. {
  6552. printk("aic7xxx: SEEPROM checksum error, ignoring SEEPROM settings.\n");
  6553. return (0);
  6554. }
  6555. return (1);
  6556. #undef CLOCK_PULSE
  6557. }
  6558. #define CLOCK_PULSE(p) \
  6559. do { \
  6560. int limit = 0; \
  6561. do { \
  6562. mb(); \
  6563. pause_sequencer(p); /* This is just to generate some PCI */ \
  6564. /* traffic so the PCI read is flushed */ \
  6565. /* it shouldn't be needed, but some */ \
  6566. /* chipsets do indeed appear to need */ \
  6567. /* something to force PCI reads to get */ \
  6568. /* flushed */ \
  6569. udelay(1); /* Do nothing */ \
  6570. } while (((aic_inb(p, SEECTL) & SEERDY) == 0) && (++limit < 1000)); \
  6571. } while(0)
  6572. /*+F*************************************************************************
  6573. * Function:
  6574. * acquire_seeprom
  6575. *
  6576. * Description:
  6577. * Acquires access to the memory port on PCI controllers.
  6578. *-F*************************************************************************/
  6579. static int
  6580. acquire_seeprom(struct aic7xxx_host *p)
  6581. {
  6582. /*
  6583. * Request access of the memory port. When access is
  6584. * granted, SEERDY will go high. We use a 1 second
  6585. * timeout which should be near 1 second more than
  6586. * is needed. Reason: after the 7870 chip reset, there
  6587. * should be no contention.
  6588. */
  6589. aic_outb(p, SEEMS, SEECTL);
  6590. CLOCK_PULSE(p);
  6591. if ((aic_inb(p, SEECTL) & SEERDY) == 0)
  6592. {
  6593. aic_outb(p, 0, SEECTL);
  6594. return (0);
  6595. }
  6596. return (1);
  6597. }
  6598. /*+F*************************************************************************
  6599. * Function:
  6600. * release_seeprom
  6601. *
  6602. * Description:
  6603. * Releases access to the memory port on PCI controllers.
  6604. *-F*************************************************************************/
  6605. static void
  6606. release_seeprom(struct aic7xxx_host *p)
  6607. {
  6608. /*
  6609. * Make sure the SEEPROM is ready before we release it.
  6610. */
  6611. CLOCK_PULSE(p);
  6612. aic_outb(p, 0, SEECTL);
  6613. }
  6614. /*+F*************************************************************************
  6615. * Function:
  6616. * read_seeprom
  6617. *
  6618. * Description:
  6619. * Reads the serial EEPROM and returns 1 if successful and 0 if
  6620. * not successful.
  6621. *
  6622. * The instruction set of the 93C46/56/66 chips is as follows:
  6623. *
  6624. * Start OP
  6625. * Function Bit Code Address Data Description
  6626. * -------------------------------------------------------------------
  6627. * READ 1 10 A5 - A0 Reads data stored in memory,
  6628. * starting at specified address
  6629. * EWEN 1 00 11XXXX Write enable must precede
  6630. * all programming modes
  6631. * ERASE 1 11 A5 - A0 Erase register A5A4A3A2A1A0
  6632. * WRITE 1 01 A5 - A0 D15 - D0 Writes register
  6633. * ERAL 1 00 10XXXX Erase all registers
  6634. * WRAL 1 00 01XXXX D15 - D0 Writes to all registers
  6635. * EWDS 1 00 00XXXX Disables all programming
  6636. * instructions
  6637. * *Note: A value of X for address is a don't care condition.
  6638. * *Note: The 93C56 and 93C66 have 8 address bits.
  6639. *
  6640. *
  6641. * The 93C46 has a four wire interface: clock, chip select, data in, and
  6642. * data out. In order to perform one of the above functions, you need
  6643. * to enable the chip select for a clock period (typically a minimum of
  6644. * 1 usec, with the clock high and low a minimum of 750 and 250 nsec
  6645. * respectively. While the chip select remains high, you can clock in
  6646. * the instructions (above) starting with the start bit, followed by the
  6647. * OP code, Address, and Data (if needed). For the READ instruction, the
  6648. * requested 16-bit register contents is read from the data out line but
  6649. * is preceded by an initial zero (leading 0, followed by 16-bits, MSB
  6650. * first). The clock cycling from low to high initiates the next data
  6651. * bit to be sent from the chip.
  6652. *
  6653. * The 78xx interface to the 93C46 serial EEPROM is through the SEECTL
  6654. * register. After successful arbitration for the memory port, the
  6655. * SEECS bit of the SEECTL register is connected to the chip select.
  6656. * The SEECK, SEEDO, and SEEDI are connected to the clock, data out,
  6657. * and data in lines respectively. The SEERDY bit of SEECTL is useful
  6658. * in that it gives us an 800 nsec timer. After a write to the SEECTL
  6659. * register, the SEERDY goes high 800 nsec later. The one exception
  6660. * to this is when we first request access to the memory port. The
  6661. * SEERDY goes high to signify that access has been granted and, for
  6662. * this case, has no implied timing.
  6663. *-F*************************************************************************/
  6664. static int
  6665. read_seeprom(struct aic7xxx_host *p, int offset,
  6666. unsigned short *scarray, unsigned int len, seeprom_chip_type chip)
  6667. {
  6668. int i = 0, k;
  6669. unsigned char temp;
  6670. unsigned short checksum = 0;
  6671. struct seeprom_cmd {
  6672. unsigned char len;
  6673. unsigned char bits[3];
  6674. };
  6675. struct seeprom_cmd seeprom_read = {3, {1, 1, 0}};
  6676. /*
  6677. * Request access of the memory port.
  6678. */
  6679. if (acquire_seeprom(p) == 0)
  6680. {
  6681. return (0);
  6682. }
  6683. /*
  6684. * Read 'len' registers of the seeprom. For the 7870, the 93C46
  6685. * SEEPROM is a 1024-bit device with 64 16-bit registers but only
  6686. * the first 32 are used by Adaptec BIOS. Some adapters use the
  6687. * 93C56 SEEPROM which is a 2048-bit device. The loop will range
  6688. * from 0 to 'len' - 1.
  6689. */
  6690. for (k = 0; k < len; k++)
  6691. {
  6692. /*
  6693. * Send chip select for one clock cycle.
  6694. */
  6695. aic_outb(p, SEEMS | SEECK | SEECS, SEECTL);
  6696. CLOCK_PULSE(p);
  6697. /*
  6698. * Now we're ready to send the read command followed by the
  6699. * address of the 16-bit register we want to read.
  6700. */
  6701. for (i = 0; i < seeprom_read.len; i++)
  6702. {
  6703. temp = SEEMS | SEECS | (seeprom_read.bits[i] << 1);
  6704. aic_outb(p, temp, SEECTL);
  6705. CLOCK_PULSE(p);
  6706. temp = temp ^ SEECK;
  6707. aic_outb(p, temp, SEECTL);
  6708. CLOCK_PULSE(p);
  6709. }
  6710. /*
  6711. * Send the 6 or 8 bit address (MSB first, LSB last).
  6712. */
  6713. for (i = ((int) chip - 1); i >= 0; i--)
  6714. {
  6715. temp = k + offset;
  6716. temp = (temp >> i) & 1; /* Mask out all but lower bit. */
  6717. temp = SEEMS | SEECS | (temp << 1);
  6718. aic_outb(p, temp, SEECTL);
  6719. CLOCK_PULSE(p);
  6720. temp = temp ^ SEECK;
  6721. aic_outb(p, temp, SEECTL);
  6722. CLOCK_PULSE(p);
  6723. }
  6724. /*
  6725. * Now read the 16 bit register. An initial 0 precedes the
  6726. * register contents which begins with bit 15 (MSB) and ends
  6727. * with bit 0 (LSB). The initial 0 will be shifted off the
  6728. * top of our word as we let the loop run from 0 to 16.
  6729. */
  6730. for (i = 0; i <= 16; i++)
  6731. {
  6732. temp = SEEMS | SEECS;
  6733. aic_outb(p, temp, SEECTL);
  6734. CLOCK_PULSE(p);
  6735. temp = temp ^ SEECK;
  6736. scarray[k] = (scarray[k] << 1) | (aic_inb(p, SEECTL) & SEEDI);
  6737. aic_outb(p, temp, SEECTL);
  6738. CLOCK_PULSE(p);
  6739. }
  6740. /*
  6741. * The serial EEPROM should have a checksum in the last word.
  6742. * Keep a running checksum for all words read except for the
  6743. * last word. We'll verify the checksum after all words have
  6744. * been read.
  6745. */
  6746. if (k < (len - 1))
  6747. {
  6748. checksum = checksum + scarray[k];
  6749. }
  6750. /*
  6751. * Reset the chip select for the next command cycle.
  6752. */
  6753. aic_outb(p, SEEMS, SEECTL);
  6754. CLOCK_PULSE(p);
  6755. aic_outb(p, SEEMS | SEECK, SEECTL);
  6756. CLOCK_PULSE(p);
  6757. aic_outb(p, SEEMS, SEECTL);
  6758. CLOCK_PULSE(p);
  6759. }
  6760. /*
  6761. * Release access to the memory port and the serial EEPROM.
  6762. */
  6763. release_seeprom(p);
  6764. #if 0
  6765. printk("Computed checksum 0x%x, checksum read 0x%x\n",
  6766. checksum, scarray[len - 1]);
  6767. printk("Serial EEPROM:");
  6768. for (k = 0; k < len; k++)
  6769. {
  6770. if (((k % 8) == 0) && (k != 0))
  6771. {
  6772. printk("\n ");
  6773. }
  6774. printk(" 0x%x", scarray[k]);
  6775. }
  6776. printk("\n");
  6777. #endif
  6778. if ( (checksum != scarray[len - 1]) || (checksum == 0) )
  6779. {
  6780. return (0);
  6781. }
  6782. return (1);
  6783. }
  6784. /*+F*************************************************************************
  6785. * Function:
  6786. * read_brdctl
  6787. *
  6788. * Description:
  6789. * Reads the BRDCTL register.
  6790. *-F*************************************************************************/
  6791. static unsigned char
  6792. read_brdctl(struct aic7xxx_host *p)
  6793. {
  6794. unsigned char brdctl, value;
  6795. /*
  6796. * Make sure the SEEPROM is ready before we access it
  6797. */
  6798. CLOCK_PULSE(p);
  6799. if (p->features & AHC_ULTRA2)
  6800. {
  6801. brdctl = BRDRW_ULTRA2;
  6802. aic_outb(p, brdctl, BRDCTL);
  6803. CLOCK_PULSE(p);
  6804. value = aic_inb(p, BRDCTL);
  6805. CLOCK_PULSE(p);
  6806. return(value);
  6807. }
  6808. brdctl = BRDRW;
  6809. if ( !((p->chip & AHC_CHIPID_MASK) == AHC_AIC7895) ||
  6810. (p->flags & AHC_CHNLB) )
  6811. {
  6812. brdctl |= BRDCS;
  6813. }
  6814. aic_outb(p, brdctl, BRDCTL);
  6815. CLOCK_PULSE(p);
  6816. value = aic_inb(p, BRDCTL);
  6817. CLOCK_PULSE(p);
  6818. aic_outb(p, 0, BRDCTL);
  6819. CLOCK_PULSE(p);
  6820. return (value);
  6821. }
  6822. /*+F*************************************************************************
  6823. * Function:
  6824. * write_brdctl
  6825. *
  6826. * Description:
  6827. * Writes a value to the BRDCTL register.
  6828. *-F*************************************************************************/
  6829. static void
  6830. write_brdctl(struct aic7xxx_host *p, unsigned char value)
  6831. {
  6832. unsigned char brdctl;
  6833. /*
  6834. * Make sure the SEEPROM is ready before we access it
  6835. */
  6836. CLOCK_PULSE(p);
  6837. if (p->features & AHC_ULTRA2)
  6838. {
  6839. brdctl = value;
  6840. aic_outb(p, brdctl, BRDCTL);
  6841. CLOCK_PULSE(p);
  6842. brdctl |= BRDSTB_ULTRA2;
  6843. aic_outb(p, brdctl, BRDCTL);
  6844. CLOCK_PULSE(p);
  6845. brdctl &= ~BRDSTB_ULTRA2;
  6846. aic_outb(p, brdctl, BRDCTL);
  6847. CLOCK_PULSE(p);
  6848. read_brdctl(p);
  6849. CLOCK_PULSE(p);
  6850. }
  6851. else
  6852. {
  6853. brdctl = BRDSTB;
  6854. if ( !((p->chip & AHC_CHIPID_MASK) == AHC_AIC7895) ||
  6855. (p->flags & AHC_CHNLB) )
  6856. {
  6857. brdctl |= BRDCS;
  6858. }
  6859. brdctl = BRDSTB | BRDCS;
  6860. aic_outb(p, brdctl, BRDCTL);
  6861. CLOCK_PULSE(p);
  6862. brdctl |= value;
  6863. aic_outb(p, brdctl, BRDCTL);
  6864. CLOCK_PULSE(p);
  6865. brdctl &= ~BRDSTB;
  6866. aic_outb(p, brdctl, BRDCTL);
  6867. CLOCK_PULSE(p);
  6868. brdctl &= ~BRDCS;
  6869. aic_outb(p, brdctl, BRDCTL);
  6870. CLOCK_PULSE(p);
  6871. }
  6872. }
  6873. /*+F*************************************************************************
  6874. * Function:
  6875. * aic785x_cable_detect
  6876. *
  6877. * Description:
  6878. * Detect the cables that are present on aic785x class controller chips
  6879. *-F*************************************************************************/
  6880. static void
  6881. aic785x_cable_detect(struct aic7xxx_host *p, int *int_50,
  6882. int *ext_present, int *eeprom)
  6883. {
  6884. unsigned char brdctl;
  6885. aic_outb(p, BRDRW | BRDCS, BRDCTL);
  6886. CLOCK_PULSE(p);
  6887. aic_outb(p, 0, BRDCTL);
  6888. CLOCK_PULSE(p);
  6889. brdctl = aic_inb(p, BRDCTL);
  6890. CLOCK_PULSE(p);
  6891. *int_50 = !(brdctl & BRDDAT5);
  6892. *ext_present = !(brdctl & BRDDAT6);
  6893. *eeprom = (aic_inb(p, SPIOCAP) & EEPROM);
  6894. }
  6895. #undef CLOCK_PULSE
  6896. /*+F*************************************************************************
  6897. * Function:
  6898. * aic2940_uwpro_cable_detect
  6899. *
  6900. * Description:
  6901. * Detect the cables that are present on the 2940-UWPro cards
  6902. *
  6903. * NOTE: This function assumes the SEEPROM will have already been acquired
  6904. * prior to invocation of this function.
  6905. *-F*************************************************************************/
  6906. static void
  6907. aic2940_uwpro_wide_cable_detect(struct aic7xxx_host *p, int *int_68,
  6908. int *ext_68, int *eeprom)
  6909. {
  6910. unsigned char brdctl;
  6911. /*
  6912. * First read the status of our cables. Set the rom bank to
  6913. * 0 since the bank setting serves as a multiplexor for the
  6914. * cable detection logic. BRDDAT5 controls the bank switch.
  6915. */
  6916. write_brdctl(p, 0);
  6917. /*
  6918. * Now we read the state of the internal 68 connector. BRDDAT6
  6919. * is don't care, BRDDAT7 is internal 68. The cable is
  6920. * present if the bit is 0
  6921. */
  6922. brdctl = read_brdctl(p);
  6923. *int_68 = !(brdctl & BRDDAT7);
  6924. /*
  6925. * Set the bank bit in brdctl and then read the external cable state
  6926. * and the EEPROM status
  6927. */
  6928. write_brdctl(p, BRDDAT5);
  6929. brdctl = read_brdctl(p);
  6930. *ext_68 = !(brdctl & BRDDAT6);
  6931. *eeprom = !(brdctl & BRDDAT7);
  6932. /*
  6933. * We're done, the calling function will release the SEEPROM for us
  6934. */
  6935. }
  6936. /*+F*************************************************************************
  6937. * Function:
  6938. * aic787x_cable_detect
  6939. *
  6940. * Description:
  6941. * Detect the cables that are present on aic787x class controller chips
  6942. *
  6943. * NOTE: This function assumes the SEEPROM will have already been acquired
  6944. * prior to invocation of this function.
  6945. *-F*************************************************************************/
  6946. static void
  6947. aic787x_cable_detect(struct aic7xxx_host *p, int *int_50, int *int_68,
  6948. int *ext_present, int *eeprom)
  6949. {
  6950. unsigned char brdctl;
  6951. /*
  6952. * First read the status of our cables. Set the rom bank to
  6953. * 0 since the bank setting serves as a multiplexor for the
  6954. * cable detection logic. BRDDAT5 controls the bank switch.
  6955. */
  6956. write_brdctl(p, 0);
  6957. /*
  6958. * Now we read the state of the two internal connectors. BRDDAT6
  6959. * is internal 50, BRDDAT7 is internal 68. For each, the cable is
  6960. * present if the bit is 0
  6961. */
  6962. brdctl = read_brdctl(p);
  6963. *int_50 = !(brdctl & BRDDAT6);
  6964. *int_68 = !(brdctl & BRDDAT7);
  6965. /*
  6966. * Set the bank bit in brdctl and then read the external cable state
  6967. * and the EEPROM status
  6968. */
  6969. write_brdctl(p, BRDDAT5);
  6970. brdctl = read_brdctl(p);
  6971. *ext_present = !(brdctl & BRDDAT6);
  6972. *eeprom = !(brdctl & BRDDAT7);
  6973. /*
  6974. * We're done, the calling function will release the SEEPROM for us
  6975. */
  6976. }
  6977. /*+F*************************************************************************
  6978. * Function:
  6979. * aic787x_ultra2_term_detect
  6980. *
  6981. * Description:
  6982. * Detect the termination settings present on ultra2 class controllers
  6983. *
  6984. * NOTE: This function assumes the SEEPROM will have already been acquired
  6985. * prior to invocation of this function.
  6986. *-F*************************************************************************/
  6987. static void
  6988. aic7xxx_ultra2_term_detect(struct aic7xxx_host *p, int *enableSE_low,
  6989. int *enableSE_high, int *enableLVD_low,
  6990. int *enableLVD_high, int *eprom_present)
  6991. {
  6992. unsigned char brdctl;
  6993. brdctl = read_brdctl(p);
  6994. *eprom_present = (brdctl & BRDDAT7);
  6995. *enableSE_high = (brdctl & BRDDAT6);
  6996. *enableSE_low = (brdctl & BRDDAT5);
  6997. *enableLVD_high = (brdctl & BRDDAT4);
  6998. *enableLVD_low = (brdctl & BRDDAT3);
  6999. }
  7000. /*+F*************************************************************************
  7001. * Function:
  7002. * configure_termination
  7003. *
  7004. * Description:
  7005. * Configures the termination settings on PCI adapters that have
  7006. * SEEPROMs available.
  7007. *-F*************************************************************************/
  7008. static void
  7009. configure_termination(struct aic7xxx_host *p)
  7010. {
  7011. int internal50_present = 0;
  7012. int internal68_present = 0;
  7013. int external_present = 0;
  7014. int eprom_present = 0;
  7015. int enableSE_low = 0;
  7016. int enableSE_high = 0;
  7017. int enableLVD_low = 0;
  7018. int enableLVD_high = 0;
  7019. unsigned char brddat = 0;
  7020. unsigned char max_target = 0;
  7021. unsigned char sxfrctl1 = aic_inb(p, SXFRCTL1);
  7022. if (acquire_seeprom(p))
  7023. {
  7024. if (p->features & (AHC_WIDE|AHC_TWIN))
  7025. max_target = 16;
  7026. else
  7027. max_target = 8;
  7028. aic_outb(p, SEEMS | SEECS, SEECTL);
  7029. sxfrctl1 &= ~STPWEN;
  7030. /*
  7031. * The termination/cable detection logic is split into three distinct
  7032. * groups. Ultra2 and later controllers, 2940UW-Pro controllers, and
  7033. * older 7850, 7860, 7870, 7880, and 7895 controllers. Each has its
  7034. * own unique way of detecting their cables and writing the results
  7035. * back to the card.
  7036. */
  7037. if (p->features & AHC_ULTRA2)
  7038. {
  7039. /*
  7040. * As long as user hasn't overridden term settings, always check the
  7041. * cable detection logic
  7042. */
  7043. if (aic7xxx_override_term == -1)
  7044. {
  7045. aic7xxx_ultra2_term_detect(p, &enableSE_low, &enableSE_high,
  7046. &enableLVD_low, &enableLVD_high,
  7047. &eprom_present);
  7048. }
  7049. /*
  7050. * If the user is overriding settings, then they have been preserved
  7051. * to here as fake adapter_control entries. Parse them and allow
  7052. * them to override the detected settings (if we even did detection).
  7053. */
  7054. if (!(p->adapter_control & CFSEAUTOTERM))
  7055. {
  7056. enableSE_low = (p->adapter_control & CFSTERM);
  7057. enableSE_high = (p->adapter_control & CFWSTERM);
  7058. }
  7059. if (!(p->adapter_control & CFAUTOTERM))
  7060. {
  7061. enableLVD_low = enableLVD_high = (p->adapter_control & CFLVDSTERM);
  7062. }
  7063. /*
  7064. * Now take those settings that we have and translate them into the
  7065. * values that must be written into the registers.
  7066. *
  7067. * Flash Enable = BRDDAT7
  7068. * Secondary High Term Enable = BRDDAT6
  7069. * Secondary Low Term Enable = BRDDAT5
  7070. * LVD/Primary High Term Enable = BRDDAT4
  7071. * LVD/Primary Low Term Enable = STPWEN bit in SXFRCTL1
  7072. */
  7073. if (enableLVD_low != 0)
  7074. {
  7075. sxfrctl1 |= STPWEN;
  7076. p->flags |= AHC_TERM_ENB_LVD;
  7077. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7078. printk(KERN_INFO "(scsi%d) LVD/Primary Low byte termination "
  7079. "Enabled\n", p->host_no);
  7080. }
  7081. if (enableLVD_high != 0)
  7082. {
  7083. brddat |= BRDDAT4;
  7084. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7085. printk(KERN_INFO "(scsi%d) LVD/Primary High byte termination "
  7086. "Enabled\n", p->host_no);
  7087. }
  7088. if (enableSE_low != 0)
  7089. {
  7090. brddat |= BRDDAT5;
  7091. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7092. printk(KERN_INFO "(scsi%d) Secondary Low byte termination "
  7093. "Enabled\n", p->host_no);
  7094. }
  7095. if (enableSE_high != 0)
  7096. {
  7097. brddat |= BRDDAT6;
  7098. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7099. printk(KERN_INFO "(scsi%d) Secondary High byte termination "
  7100. "Enabled\n", p->host_no);
  7101. }
  7102. }
  7103. else if (p->features & AHC_NEW_AUTOTERM)
  7104. {
  7105. /*
  7106. * The 50 pin connector termination is controlled by STPWEN in the
  7107. * SXFRCTL1 register. Since the Adaptec docs typically say the
  7108. * controller is not allowed to be in the middle of a cable and
  7109. * this is the only connection on that stub of the bus, there is
  7110. * no need to even check for narrow termination, it's simply
  7111. * always on.
  7112. */
  7113. sxfrctl1 |= STPWEN;
  7114. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7115. printk(KERN_INFO "(scsi%d) Narrow channel termination Enabled\n",
  7116. p->host_no);
  7117. if (p->adapter_control & CFAUTOTERM)
  7118. {
  7119. aic2940_uwpro_wide_cable_detect(p, &internal68_present,
  7120. &external_present,
  7121. &eprom_present);
  7122. printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Int-68 %s, "
  7123. "Ext-68 %s)\n", p->host_no,
  7124. "Don't Care",
  7125. internal68_present ? "YES" : "NO",
  7126. external_present ? "YES" : "NO");
  7127. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7128. printk(KERN_INFO "(scsi%d) EEPROM %s present.\n", p->host_no,
  7129. eprom_present ? "is" : "is not");
  7130. if (internal68_present && external_present)
  7131. {
  7132. brddat = 0;
  7133. p->flags &= ~AHC_TERM_ENB_SE_HIGH;
  7134. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7135. printk(KERN_INFO "(scsi%d) Wide channel termination Disabled\n",
  7136. p->host_no);
  7137. }
  7138. else
  7139. {
  7140. brddat = BRDDAT6;
  7141. p->flags |= AHC_TERM_ENB_SE_HIGH;
  7142. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7143. printk(KERN_INFO "(scsi%d) Wide channel termination Enabled\n",
  7144. p->host_no);
  7145. }
  7146. }
  7147. else
  7148. {
  7149. /*
  7150. * The termination of the Wide channel is done more like normal
  7151. * though, and the setting of this termination is done by writing
  7152. * either a 0 or 1 to BRDDAT6 of the BRDDAT register
  7153. */
  7154. if (p->adapter_control & CFWSTERM)
  7155. {
  7156. brddat = BRDDAT6;
  7157. p->flags |= AHC_TERM_ENB_SE_HIGH;
  7158. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7159. printk(KERN_INFO "(scsi%d) Wide channel termination Enabled\n",
  7160. p->host_no);
  7161. }
  7162. else
  7163. {
  7164. brddat = 0;
  7165. }
  7166. }
  7167. }
  7168. else
  7169. {
  7170. if (p->adapter_control & CFAUTOTERM)
  7171. {
  7172. if (p->flags & AHC_MOTHERBOARD)
  7173. {
  7174. printk(KERN_INFO "(scsi%d) Warning - detected auto-termination\n",
  7175. p->host_no);
  7176. printk(KERN_INFO "(scsi%d) Please verify driver detected settings "
  7177. "are correct.\n", p->host_no);
  7178. printk(KERN_INFO "(scsi%d) If not, then please properly set the "
  7179. "device termination\n", p->host_no);
  7180. printk(KERN_INFO "(scsi%d) in the Adaptec SCSI BIOS by hitting "
  7181. "CTRL-A when prompted\n", p->host_no);
  7182. printk(KERN_INFO "(scsi%d) during machine bootup.\n", p->host_no);
  7183. }
  7184. /* Configure auto termination. */
  7185. if ( (p->chip & AHC_CHIPID_MASK) >= AHC_AIC7870 )
  7186. {
  7187. aic787x_cable_detect(p, &internal50_present, &internal68_present,
  7188. &external_present, &eprom_present);
  7189. }
  7190. else
  7191. {
  7192. aic785x_cable_detect(p, &internal50_present, &external_present,
  7193. &eprom_present);
  7194. }
  7195. if (max_target <= 8)
  7196. internal68_present = 0;
  7197. if (max_target > 8)
  7198. {
  7199. printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Int-68 %s, "
  7200. "Ext-68 %s)\n", p->host_no,
  7201. internal50_present ? "YES" : "NO",
  7202. internal68_present ? "YES" : "NO",
  7203. external_present ? "YES" : "NO");
  7204. }
  7205. else
  7206. {
  7207. printk(KERN_INFO "(scsi%d) Cables present (Int-50 %s, Ext-50 %s)\n",
  7208. p->host_no,
  7209. internal50_present ? "YES" : "NO",
  7210. external_present ? "YES" : "NO");
  7211. }
  7212. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7213. printk(KERN_INFO "(scsi%d) EEPROM %s present.\n", p->host_no,
  7214. eprom_present ? "is" : "is not");
  7215. /*
  7216. * Now set the termination based on what we found. BRDDAT6
  7217. * controls wide termination enable.
  7218. * Flash Enable = BRDDAT7
  7219. * SE High Term Enable = BRDDAT6
  7220. */
  7221. if (internal50_present && internal68_present && external_present)
  7222. {
  7223. printk(KERN_INFO "(scsi%d) Illegal cable configuration!! Only two\n",
  7224. p->host_no);
  7225. printk(KERN_INFO "(scsi%d) connectors on the SCSI controller may be "
  7226. "in use at a time!\n", p->host_no);
  7227. /*
  7228. * Force termination (low and high byte) on. This is safer than
  7229. * leaving it completely off, especially since this message comes
  7230. * most often from motherboard controllers that don't even have 3
  7231. * connectors, but instead are failing the cable detection.
  7232. */
  7233. internal50_present = external_present = 0;
  7234. enableSE_high = enableSE_low = 1;
  7235. }
  7236. if ((max_target > 8) &&
  7237. ((external_present == 0) || (internal68_present == 0)) )
  7238. {
  7239. brddat |= BRDDAT6;
  7240. p->flags |= AHC_TERM_ENB_SE_HIGH;
  7241. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7242. printk(KERN_INFO "(scsi%d) SE High byte termination Enabled\n",
  7243. p->host_no);
  7244. }
  7245. if ( ((internal50_present ? 1 : 0) +
  7246. (internal68_present ? 1 : 0) +
  7247. (external_present ? 1 : 0)) <= 1 )
  7248. {
  7249. sxfrctl1 |= STPWEN;
  7250. p->flags |= AHC_TERM_ENB_SE_LOW;
  7251. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7252. printk(KERN_INFO "(scsi%d) SE Low byte termination Enabled\n",
  7253. p->host_no);
  7254. }
  7255. }
  7256. else /* p->adapter_control & CFAUTOTERM */
  7257. {
  7258. if (p->adapter_control & CFSTERM)
  7259. {
  7260. sxfrctl1 |= STPWEN;
  7261. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7262. printk(KERN_INFO "(scsi%d) SE Low byte termination Enabled\n",
  7263. p->host_no);
  7264. }
  7265. if (p->adapter_control & CFWSTERM)
  7266. {
  7267. brddat |= BRDDAT6;
  7268. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7269. printk(KERN_INFO "(scsi%d) SE High byte termination Enabled\n",
  7270. p->host_no);
  7271. }
  7272. }
  7273. }
  7274. aic_outb(p, sxfrctl1, SXFRCTL1);
  7275. write_brdctl(p, brddat);
  7276. release_seeprom(p);
  7277. }
  7278. }
  7279. /*+F*************************************************************************
  7280. * Function:
  7281. * detect_maxscb
  7282. *
  7283. * Description:
  7284. * Detects the maximum number of SCBs for the controller and returns
  7285. * the count and a mask in p (p->maxscbs, p->qcntmask).
  7286. *-F*************************************************************************/
  7287. static void
  7288. detect_maxscb(struct aic7xxx_host *p)
  7289. {
  7290. int i;
  7291. /*
  7292. * It's possible that we've already done this for multichannel
  7293. * adapters.
  7294. */
  7295. if (p->scb_data->maxhscbs == 0)
  7296. {
  7297. /*
  7298. * We haven't initialized the SCB settings yet. Walk the SCBs to
  7299. * determince how many there are.
  7300. */
  7301. aic_outb(p, 0, FREE_SCBH);
  7302. for (i = 0; i < AIC7XXX_MAXSCB; i++)
  7303. {
  7304. aic_outb(p, i, SCBPTR);
  7305. aic_outb(p, i, SCB_CONTROL);
  7306. if (aic_inb(p, SCB_CONTROL) != i)
  7307. break;
  7308. aic_outb(p, 0, SCBPTR);
  7309. if (aic_inb(p, SCB_CONTROL) != 0)
  7310. break;
  7311. aic_outb(p, i, SCBPTR);
  7312. aic_outb(p, 0, SCB_CONTROL); /* Clear the control byte. */
  7313. aic_outb(p, i + 1, SCB_NEXT); /* Set the next pointer. */
  7314. aic_outb(p, SCB_LIST_NULL, SCB_TAG); /* Make the tag invalid. */
  7315. aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS); /* no busy untagged */
  7316. aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+1);/* targets active yet */
  7317. aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+2);
  7318. aic_outb(p, SCB_LIST_NULL, SCB_BUSYTARGETS+3);
  7319. }
  7320. /* Make sure the last SCB terminates the free list. */
  7321. aic_outb(p, i - 1, SCBPTR);
  7322. aic_outb(p, SCB_LIST_NULL, SCB_NEXT);
  7323. /* Ensure we clear the first (0) SCBs control byte. */
  7324. aic_outb(p, 0, SCBPTR);
  7325. aic_outb(p, 0, SCB_CONTROL);
  7326. p->scb_data->maxhscbs = i;
  7327. /*
  7328. * Use direct indexing instead for speed
  7329. */
  7330. if ( i == AIC7XXX_MAXSCB )
  7331. p->flags &= ~AHC_PAGESCBS;
  7332. }
  7333. }
  7334. /*+F*************************************************************************
  7335. * Function:
  7336. * aic7xxx_register
  7337. *
  7338. * Description:
  7339. * Register a Adaptec aic7xxx chip SCSI controller with the kernel.
  7340. *-F*************************************************************************/
  7341. static int
  7342. aic7xxx_register(struct scsi_host_template *template, struct aic7xxx_host *p,
  7343. int reset_delay)
  7344. {
  7345. int i, result;
  7346. int max_targets;
  7347. int found = 1;
  7348. unsigned char term, scsi_conf;
  7349. struct Scsi_Host *host;
  7350. host = p->host;
  7351. p->scb_data->maxscbs = AIC7XXX_MAXSCB;
  7352. host->can_queue = AIC7XXX_MAXSCB;
  7353. host->cmd_per_lun = 3;
  7354. host->sg_tablesize = AIC7XXX_MAX_SG;
  7355. host->this_id = p->scsi_id;
  7356. host->io_port = p->base;
  7357. host->n_io_port = 0xFF;
  7358. host->base = p->mbase;
  7359. host->irq = p->irq;
  7360. if (p->features & AHC_WIDE)
  7361. {
  7362. host->max_id = 16;
  7363. }
  7364. if (p->features & AHC_TWIN)
  7365. {
  7366. host->max_channel = 1;
  7367. }
  7368. p->host = host;
  7369. p->host_no = host->host_no;
  7370. host->unique_id = p->instance;
  7371. p->isr_count = 0;
  7372. p->next = NULL;
  7373. p->completeq.head = NULL;
  7374. p->completeq.tail = NULL;
  7375. scbq_init(&p->scb_data->free_scbs);
  7376. scbq_init(&p->waiting_scbs);
  7377. INIT_LIST_HEAD(&p->aic_devs);
  7378. /*
  7379. * We currently have no commands of any type
  7380. */
  7381. p->qinfifonext = 0;
  7382. p->qoutfifonext = 0;
  7383. printk(KERN_INFO "(scsi%d) <%s> found at ", p->host_no,
  7384. board_names[p->board_name_index]);
  7385. switch(p->chip)
  7386. {
  7387. case (AHC_AIC7770|AHC_EISA):
  7388. printk("EISA slot %d\n", p->pci_device_fn);
  7389. break;
  7390. case (AHC_AIC7770|AHC_VL):
  7391. printk("VLB slot %d\n", p->pci_device_fn);
  7392. break;
  7393. default:
  7394. printk("PCI %d/%d/%d\n", p->pci_bus, PCI_SLOT(p->pci_device_fn),
  7395. PCI_FUNC(p->pci_device_fn));
  7396. break;
  7397. }
  7398. if (p->features & AHC_TWIN)
  7399. {
  7400. printk(KERN_INFO "(scsi%d) Twin Channel, A SCSI ID %d, B SCSI ID %d, ",
  7401. p->host_no, p->scsi_id, p->scsi_id_b);
  7402. }
  7403. else
  7404. {
  7405. char *channel;
  7406. channel = "";
  7407. if ((p->flags & AHC_MULTI_CHANNEL) != 0)
  7408. {
  7409. channel = " A";
  7410. if ( (p->flags & (AHC_CHNLB|AHC_CHNLC)) != 0 )
  7411. {
  7412. channel = (p->flags & AHC_CHNLB) ? " B" : " C";
  7413. }
  7414. }
  7415. if (p->features & AHC_WIDE)
  7416. {
  7417. printk(KERN_INFO "(scsi%d) Wide ", p->host_no);
  7418. }
  7419. else
  7420. {
  7421. printk(KERN_INFO "(scsi%d) Narrow ", p->host_no);
  7422. }
  7423. printk("Channel%s, SCSI ID=%d, ", channel, p->scsi_id);
  7424. }
  7425. aic_outb(p, 0, SEQ_FLAGS);
  7426. detect_maxscb(p);
  7427. printk("%d/%d SCBs\n", p->scb_data->maxhscbs, p->scb_data->maxscbs);
  7428. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7429. {
  7430. printk(KERN_INFO "(scsi%d) BIOS %sabled, IO Port 0x%lx, IRQ %d\n",
  7431. p->host_no, (p->flags & AHC_BIOS_ENABLED) ? "en" : "dis",
  7432. p->base, p->irq);
  7433. printk(KERN_INFO "(scsi%d) IO Memory at 0x%lx, MMAP Memory at %p\n",
  7434. p->host_no, p->mbase, p->maddr);
  7435. }
  7436. #ifdef CONFIG_PCI
  7437. /*
  7438. * Now that we know our instance number, we can set the flags we need to
  7439. * force termination if need be.
  7440. */
  7441. if (aic7xxx_stpwlev != -1)
  7442. {
  7443. /*
  7444. * This option only applies to PCI controllers.
  7445. */
  7446. if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI)
  7447. {
  7448. unsigned char devconfig;
  7449. pci_read_config_byte(p->pdev, DEVCONFIG, &devconfig);
  7450. if ( (aic7xxx_stpwlev >> p->instance) & 0x01 )
  7451. {
  7452. devconfig |= STPWLEVEL;
  7453. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7454. printk("(scsi%d) Force setting STPWLEVEL bit\n", p->host_no);
  7455. }
  7456. else
  7457. {
  7458. devconfig &= ~STPWLEVEL;
  7459. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7460. printk("(scsi%d) Force clearing STPWLEVEL bit\n", p->host_no);
  7461. }
  7462. pci_write_config_byte(p->pdev, DEVCONFIG, devconfig);
  7463. }
  7464. }
  7465. #endif
  7466. /*
  7467. * That took care of devconfig and stpwlev, now for the actual termination
  7468. * settings.
  7469. */
  7470. if (aic7xxx_override_term != -1)
  7471. {
  7472. /*
  7473. * Again, this only applies to PCI controllers. We don't have problems
  7474. * with the termination on 274x controllers to the best of my knowledge.
  7475. */
  7476. if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI)
  7477. {
  7478. unsigned char term_override;
  7479. term_override = ( (aic7xxx_override_term >> (p->instance * 4)) & 0x0f);
  7480. p->adapter_control &=
  7481. ~(CFSTERM|CFWSTERM|CFLVDSTERM|CFAUTOTERM|CFSEAUTOTERM);
  7482. if ( (p->features & AHC_ULTRA2) && (term_override & 0x0c) )
  7483. {
  7484. p->adapter_control |= CFLVDSTERM;
  7485. }
  7486. if (term_override & 0x02)
  7487. {
  7488. p->adapter_control |= CFWSTERM;
  7489. }
  7490. if (term_override & 0x01)
  7491. {
  7492. p->adapter_control |= CFSTERM;
  7493. }
  7494. }
  7495. }
  7496. if ( (p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1) )
  7497. {
  7498. if (p->features & AHC_SPIOCAP)
  7499. {
  7500. if ( aic_inb(p, SPIOCAP) & SSPIOCPS )
  7501. /*
  7502. * Update the settings in sxfrctl1 to match the termination
  7503. * settings.
  7504. */
  7505. configure_termination(p);
  7506. }
  7507. else if ((p->chip & AHC_CHIPID_MASK) >= AHC_AIC7870)
  7508. {
  7509. configure_termination(p);
  7510. }
  7511. }
  7512. /*
  7513. * Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1, for both channels
  7514. */
  7515. if (p->features & AHC_TWIN)
  7516. {
  7517. /* Select channel B */
  7518. aic_outb(p, aic_inb(p, SBLKCTL) | SELBUSB, SBLKCTL);
  7519. if ((p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1))
  7520. term = (aic_inb(p, SXFRCTL1) & STPWEN);
  7521. else
  7522. term = ((p->flags & AHC_TERM_ENB_B) ? STPWEN : 0);
  7523. aic_outb(p, p->scsi_id_b, SCSIID);
  7524. scsi_conf = aic_inb(p, SCSICONF + 1);
  7525. aic_outb(p, DFON | SPIOEN, SXFRCTL0);
  7526. aic_outb(p, (scsi_conf & ENSPCHK) | aic7xxx_seltime | term |
  7527. ENSTIMER | ACTNEGEN, SXFRCTL1);
  7528. aic_outb(p, 0, SIMODE0);
  7529. aic_outb(p, ENSELTIMO | ENSCSIRST | ENSCSIPERR, SIMODE1);
  7530. aic_outb(p, 0, SCSIRATE);
  7531. /* Select channel A */
  7532. aic_outb(p, aic_inb(p, SBLKCTL) & ~SELBUSB, SBLKCTL);
  7533. }
  7534. if (p->features & AHC_ULTRA2)
  7535. {
  7536. aic_outb(p, p->scsi_id, SCSIID_ULTRA2);
  7537. }
  7538. else
  7539. {
  7540. aic_outb(p, p->scsi_id, SCSIID);
  7541. }
  7542. if ((p->flags & AHC_SEEPROM_FOUND) || (aic7xxx_override_term != -1))
  7543. term = (aic_inb(p, SXFRCTL1) & STPWEN);
  7544. else
  7545. term = ((p->flags & (AHC_TERM_ENB_A|AHC_TERM_ENB_LVD)) ? STPWEN : 0);
  7546. scsi_conf = aic_inb(p, SCSICONF);
  7547. aic_outb(p, DFON | SPIOEN, SXFRCTL0);
  7548. aic_outb(p, (scsi_conf & ENSPCHK) | aic7xxx_seltime | term |
  7549. ENSTIMER | ACTNEGEN, SXFRCTL1);
  7550. aic_outb(p, 0, SIMODE0);
  7551. /*
  7552. * If we are a cardbus adapter then don't enable SCSI reset detection.
  7553. * We shouldn't likely be sharing SCSI busses with someone else, and
  7554. * if we don't have a cable currently plugged into the controller then
  7555. * we won't have a power source for the SCSI termination, which means
  7556. * we'll see infinite incoming bus resets.
  7557. */
  7558. if(p->flags & AHC_NO_STPWEN)
  7559. aic_outb(p, ENSELTIMO | ENSCSIPERR, SIMODE1);
  7560. else
  7561. aic_outb(p, ENSELTIMO | ENSCSIRST | ENSCSIPERR, SIMODE1);
  7562. aic_outb(p, 0, SCSIRATE);
  7563. if ( p->features & AHC_ULTRA2)
  7564. aic_outb(p, 0, SCSIOFFSET);
  7565. /*
  7566. * Look at the information that board initialization or the board
  7567. * BIOS has left us. In the lower four bits of each target's
  7568. * scratch space any value other than 0 indicates that we should
  7569. * initiate synchronous transfers. If it's zero, the user or the
  7570. * BIOS has decided to disable synchronous negotiation to that
  7571. * target so we don't activate the needsdtr flag.
  7572. */
  7573. if ((p->features & (AHC_TWIN|AHC_WIDE)) == 0)
  7574. {
  7575. max_targets = 8;
  7576. }
  7577. else
  7578. {
  7579. max_targets = 16;
  7580. }
  7581. if (!(aic7xxx_no_reset))
  7582. {
  7583. /*
  7584. * If we reset the bus, then clear the transfer settings, else leave
  7585. * them be.
  7586. */
  7587. aic_outb(p, 0, ULTRA_ENB);
  7588. aic_outb(p, 0, ULTRA_ENB + 1);
  7589. p->ultraenb = 0;
  7590. }
  7591. /*
  7592. * Allocate enough hardware scbs to handle the maximum number of
  7593. * concurrent transactions we can have. We have to make sure that
  7594. * the allocated memory is contiguous memory. The Linux kmalloc
  7595. * routine should only allocate contiguous memory, but note that
  7596. * this could be a problem if kmalloc() is changed.
  7597. */
  7598. {
  7599. size_t array_size;
  7600. unsigned int hscb_physaddr;
  7601. array_size = p->scb_data->maxscbs * sizeof(struct aic7xxx_hwscb);
  7602. if (p->scb_data->hscbs == NULL)
  7603. {
  7604. /* pci_alloc_consistent enforces the alignment already and
  7605. * clears the area as well.
  7606. */
  7607. p->scb_data->hscbs = pci_alloc_consistent(p->pdev, array_size,
  7608. &p->scb_data->hscbs_dma);
  7609. /* We have to use pci_free_consistent, not kfree */
  7610. p->scb_data->hscb_kmalloc_ptr = NULL;
  7611. p->scb_data->hscbs_dma_len = array_size;
  7612. }
  7613. if (p->scb_data->hscbs == NULL)
  7614. {
  7615. printk("(scsi%d) Unable to allocate hardware SCB array; "
  7616. "failing detection.\n", p->host_no);
  7617. aic_outb(p, 0, SIMODE1);
  7618. p->irq = 0;
  7619. return(0);
  7620. }
  7621. hscb_physaddr = p->scb_data->hscbs_dma;
  7622. aic_outb(p, hscb_physaddr & 0xFF, HSCB_ADDR);
  7623. aic_outb(p, (hscb_physaddr >> 8) & 0xFF, HSCB_ADDR + 1);
  7624. aic_outb(p, (hscb_physaddr >> 16) & 0xFF, HSCB_ADDR + 2);
  7625. aic_outb(p, (hscb_physaddr >> 24) & 0xFF, HSCB_ADDR + 3);
  7626. /* Set up the fifo areas at the same time */
  7627. p->untagged_scbs = pci_alloc_consistent(p->pdev, 3*256, &p->fifo_dma);
  7628. if (p->untagged_scbs == NULL)
  7629. {
  7630. printk("(scsi%d) Unable to allocate hardware FIFO arrays; "
  7631. "failing detection.\n", p->host_no);
  7632. p->irq = 0;
  7633. return(0);
  7634. }
  7635. p->qoutfifo = p->untagged_scbs + 256;
  7636. p->qinfifo = p->qoutfifo + 256;
  7637. for (i = 0; i < 256; i++)
  7638. {
  7639. p->untagged_scbs[i] = SCB_LIST_NULL;
  7640. p->qinfifo[i] = SCB_LIST_NULL;
  7641. p->qoutfifo[i] = SCB_LIST_NULL;
  7642. }
  7643. hscb_physaddr = p->fifo_dma;
  7644. aic_outb(p, hscb_physaddr & 0xFF, SCBID_ADDR);
  7645. aic_outb(p, (hscb_physaddr >> 8) & 0xFF, SCBID_ADDR + 1);
  7646. aic_outb(p, (hscb_physaddr >> 16) & 0xFF, SCBID_ADDR + 2);
  7647. aic_outb(p, (hscb_physaddr >> 24) & 0xFF, SCBID_ADDR + 3);
  7648. }
  7649. /* The Q-FIFOs we just set up are all empty */
  7650. aic_outb(p, 0, QINPOS);
  7651. aic_outb(p, 0, KERNEL_QINPOS);
  7652. aic_outb(p, 0, QOUTPOS);
  7653. if(p->features & AHC_QUEUE_REGS)
  7654. {
  7655. aic_outb(p, SCB_QSIZE_256, QOFF_CTLSTA);
  7656. aic_outb(p, 0, SDSCB_QOFF);
  7657. aic_outb(p, 0, SNSCB_QOFF);
  7658. aic_outb(p, 0, HNSCB_QOFF);
  7659. }
  7660. /*
  7661. * We don't have any waiting selections or disconnected SCBs.
  7662. */
  7663. aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
  7664. aic_outb(p, SCB_LIST_NULL, DISCONNECTED_SCBH);
  7665. /*
  7666. * Message out buffer starts empty
  7667. */
  7668. aic_outb(p, MSG_NOOP, MSG_OUT);
  7669. aic_outb(p, MSG_NOOP, LAST_MSG);
  7670. /*
  7671. * Set all the other asundry items that haven't been set yet.
  7672. * This includes just dumping init values to a lot of registers simply
  7673. * to make sure they've been touched and are ready for use parity wise
  7674. * speaking.
  7675. */
  7676. aic_outb(p, 0, TMODE_CMDADDR);
  7677. aic_outb(p, 0, TMODE_CMDADDR + 1);
  7678. aic_outb(p, 0, TMODE_CMDADDR + 2);
  7679. aic_outb(p, 0, TMODE_CMDADDR + 3);
  7680. aic_outb(p, 0, TMODE_CMDADDR_NEXT);
  7681. /*
  7682. * Link us into the list of valid hosts
  7683. */
  7684. p->next = first_aic7xxx;
  7685. first_aic7xxx = p;
  7686. /*
  7687. * Allocate the first set of scbs for this controller. This is to stream-
  7688. * line code elsewhere in the driver. If we have to check for the existence
  7689. * of scbs in certain code sections, it slows things down. However, as
  7690. * soon as we register the IRQ for this card, we could get an interrupt that
  7691. * includes possibly the SCSI_RSTI interrupt. If we catch that interrupt
  7692. * then we are likely to segfault if we don't have at least one chunk of
  7693. * SCBs allocated or add checks all through the reset code to make sure
  7694. * that the SCBs have been allocated which is an invalid running condition
  7695. * and therefore I think it's preferable to simply pre-allocate the first
  7696. * chunk of SCBs.
  7697. */
  7698. aic7xxx_allocate_scb(p);
  7699. /*
  7700. * Load the sequencer program, then re-enable the board -
  7701. * resetting the AIC-7770 disables it, leaving the lights
  7702. * on with nobody home.
  7703. */
  7704. aic7xxx_loadseq(p);
  7705. /*
  7706. * Make sure the AUTOFLUSHDIS bit is *not* set in the SBLKCTL register
  7707. */
  7708. aic_outb(p, aic_inb(p, SBLKCTL) & ~AUTOFLUSHDIS, SBLKCTL);
  7709. if ( (p->chip & AHC_CHIPID_MASK) == AHC_AIC7770 )
  7710. {
  7711. aic_outb(p, ENABLE, BCTL); /* Enable the boards BUS drivers. */
  7712. }
  7713. if ( !(aic7xxx_no_reset) )
  7714. {
  7715. if (p->features & AHC_TWIN)
  7716. {
  7717. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7718. printk(KERN_INFO "(scsi%d) Resetting channel B\n", p->host_no);
  7719. aic_outb(p, aic_inb(p, SBLKCTL) | SELBUSB, SBLKCTL);
  7720. aic7xxx_reset_current_bus(p);
  7721. aic_outb(p, aic_inb(p, SBLKCTL) & ~SELBUSB, SBLKCTL);
  7722. }
  7723. /* Reset SCSI bus A. */
  7724. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7725. { /* In case we are a 3940, 3985, or 7895, print the right channel */
  7726. char *channel = "";
  7727. if (p->flags & AHC_MULTI_CHANNEL)
  7728. {
  7729. channel = " A";
  7730. if (p->flags & (AHC_CHNLB|AHC_CHNLC))
  7731. channel = (p->flags & AHC_CHNLB) ? " B" : " C";
  7732. }
  7733. printk(KERN_INFO "(scsi%d) Resetting channel%s\n", p->host_no, channel);
  7734. }
  7735. aic7xxx_reset_current_bus(p);
  7736. }
  7737. else
  7738. {
  7739. if (!reset_delay)
  7740. {
  7741. printk(KERN_INFO "(scsi%d) Not resetting SCSI bus. Note: Don't use "
  7742. "the no_reset\n", p->host_no);
  7743. printk(KERN_INFO "(scsi%d) option unless you have a verifiable need "
  7744. "for it.\n", p->host_no);
  7745. }
  7746. }
  7747. /*
  7748. * Register IRQ with the kernel. Only allow sharing IRQs with
  7749. * PCI devices.
  7750. */
  7751. if (!(p->chip & AHC_PCI))
  7752. {
  7753. result = (request_irq(p->irq, do_aic7xxx_isr, 0, "aic7xxx", p));
  7754. }
  7755. else
  7756. {
  7757. result = (request_irq(p->irq, do_aic7xxx_isr, IRQF_SHARED,
  7758. "aic7xxx", p));
  7759. if (result < 0)
  7760. {
  7761. result = (request_irq(p->irq, do_aic7xxx_isr, IRQF_DISABLED | IRQF_SHARED,
  7762. "aic7xxx", p));
  7763. }
  7764. }
  7765. if (result < 0)
  7766. {
  7767. printk(KERN_WARNING "(scsi%d) Couldn't register IRQ %d, ignoring "
  7768. "controller.\n", p->host_no, p->irq);
  7769. aic_outb(p, 0, SIMODE1);
  7770. p->irq = 0;
  7771. return (0);
  7772. }
  7773. if(aic_inb(p, INTSTAT) & INT_PEND)
  7774. printk(INFO_LEAD "spurious interrupt during configuration, cleared.\n",
  7775. p->host_no, -1, -1 , -1);
  7776. aic7xxx_clear_intstat(p);
  7777. unpause_sequencer(p, /* unpause_always */ TRUE);
  7778. return (found);
  7779. }
  7780. /*+F*************************************************************************
  7781. * Function:
  7782. * aic7xxx_chip_reset
  7783. *
  7784. * Description:
  7785. * Perform a chip reset on the aic7xxx SCSI controller. The controller
  7786. * is paused upon return.
  7787. *-F*************************************************************************/
  7788. static int
  7789. aic7xxx_chip_reset(struct aic7xxx_host *p)
  7790. {
  7791. unsigned char sblkctl;
  7792. int wait;
  7793. /*
  7794. * For some 274x boards, we must clear the CHIPRST bit and pause
  7795. * the sequencer. For some reason, this makes the driver work.
  7796. */
  7797. aic_outb(p, PAUSE | CHIPRST, HCNTRL);
  7798. /*
  7799. * In the future, we may call this function as a last resort for
  7800. * error handling. Let's be nice and not do any unnecessary delays.
  7801. */
  7802. wait = 1000; /* 1 msec (1000 * 1 msec) */
  7803. while (--wait && !(aic_inb(p, HCNTRL) & CHIPRSTACK))
  7804. {
  7805. udelay(1); /* 1 usec */
  7806. }
  7807. pause_sequencer(p);
  7808. sblkctl = aic_inb(p, SBLKCTL) & (SELBUSB|SELWIDE);
  7809. if (p->chip & AHC_PCI)
  7810. sblkctl &= ~SELBUSB;
  7811. switch( sblkctl )
  7812. {
  7813. case 0: /* normal narrow card */
  7814. break;
  7815. case 2: /* Wide card */
  7816. p->features |= AHC_WIDE;
  7817. break;
  7818. case 8: /* Twin card */
  7819. p->features |= AHC_TWIN;
  7820. p->flags |= AHC_MULTI_CHANNEL;
  7821. break;
  7822. default: /* hmmm...we don't know what this is */
  7823. printk(KERN_WARNING "aic7xxx: Unsupported adapter type %d, ignoring.\n",
  7824. aic_inb(p, SBLKCTL) & 0x0a);
  7825. return(-1);
  7826. }
  7827. return(0);
  7828. }
  7829. /*+F*************************************************************************
  7830. * Function:
  7831. * aic7xxx_alloc
  7832. *
  7833. * Description:
  7834. * Allocate and initialize a host structure. Returns NULL upon error
  7835. * and a pointer to a aic7xxx_host struct upon success.
  7836. *-F*************************************************************************/
  7837. static struct aic7xxx_host *
  7838. aic7xxx_alloc(struct scsi_host_template *sht, struct aic7xxx_host *temp)
  7839. {
  7840. struct aic7xxx_host *p = NULL;
  7841. struct Scsi_Host *host;
  7842. /*
  7843. * Allocate a storage area by registering us with the mid-level
  7844. * SCSI layer.
  7845. */
  7846. host = scsi_register(sht, sizeof(struct aic7xxx_host));
  7847. if (host != NULL)
  7848. {
  7849. p = (struct aic7xxx_host *) host->hostdata;
  7850. memset(p, 0, sizeof(struct aic7xxx_host));
  7851. *p = *temp;
  7852. p->host = host;
  7853. p->scb_data = kmalloc(sizeof(scb_data_type), GFP_ATOMIC);
  7854. if (p->scb_data != NULL)
  7855. {
  7856. memset(p->scb_data, 0, sizeof(scb_data_type));
  7857. scbq_init (&p->scb_data->free_scbs);
  7858. }
  7859. else
  7860. {
  7861. /*
  7862. * For some reason we don't have enough memory. Free the
  7863. * allocated memory for the aic7xxx_host struct, and return NULL.
  7864. */
  7865. release_region(p->base, MAXREG - MINREG);
  7866. scsi_unregister(host);
  7867. return(NULL);
  7868. }
  7869. p->host_no = host->host_no;
  7870. }
  7871. return (p);
  7872. }
  7873. /*+F*************************************************************************
  7874. * Function:
  7875. * aic7xxx_free
  7876. *
  7877. * Description:
  7878. * Frees and releases all resources associated with an instance of
  7879. * the driver (struct aic7xxx_host *).
  7880. *-F*************************************************************************/
  7881. static void
  7882. aic7xxx_free(struct aic7xxx_host *p)
  7883. {
  7884. int i;
  7885. /*
  7886. * Free the allocated hardware SCB space.
  7887. */
  7888. if (p->scb_data != NULL)
  7889. {
  7890. struct aic7xxx_scb_dma *scb_dma = NULL;
  7891. if (p->scb_data->hscbs != NULL)
  7892. {
  7893. pci_free_consistent(p->pdev, p->scb_data->hscbs_dma_len,
  7894. p->scb_data->hscbs, p->scb_data->hscbs_dma);
  7895. p->scb_data->hscbs = p->scb_data->hscb_kmalloc_ptr = NULL;
  7896. }
  7897. /*
  7898. * Free the driver SCBs. These were allocated on an as-need
  7899. * basis. We allocated these in groups depending on how many
  7900. * we could fit into a given amount of RAM. The tail SCB for
  7901. * these allocations has a pointer to the alloced area.
  7902. */
  7903. for (i = 0; i < p->scb_data->numscbs; i++)
  7904. {
  7905. if (p->scb_data->scb_array[i]->scb_dma != scb_dma)
  7906. {
  7907. scb_dma = p->scb_data->scb_array[i]->scb_dma;
  7908. pci_free_consistent(p->pdev, scb_dma->dma_len,
  7909. (void *)((unsigned long)scb_dma->dma_address
  7910. - scb_dma->dma_offset),
  7911. scb_dma->dma_address);
  7912. }
  7913. kfree(p->scb_data->scb_array[i]->kmalloc_ptr);
  7914. p->scb_data->scb_array[i] = NULL;
  7915. }
  7916. /*
  7917. * Free the SCB data area.
  7918. */
  7919. kfree(p->scb_data);
  7920. }
  7921. pci_free_consistent(p->pdev, 3*256, (void *)p->untagged_scbs, p->fifo_dma);
  7922. }
  7923. /*+F*************************************************************************
  7924. * Function:
  7925. * aic7xxx_load_seeprom
  7926. *
  7927. * Description:
  7928. * Load the seeprom and configure adapter and target settings.
  7929. * Returns 1 if the load was successful and 0 otherwise.
  7930. *-F*************************************************************************/
  7931. static void
  7932. aic7xxx_load_seeprom(struct aic7xxx_host *p, unsigned char *sxfrctl1)
  7933. {
  7934. int have_seeprom = 0;
  7935. int i, max_targets, mask;
  7936. unsigned char scsirate, scsi_conf;
  7937. unsigned short scarray[128];
  7938. struct seeprom_config *sc = (struct seeprom_config *) scarray;
  7939. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7940. {
  7941. printk(KERN_INFO "aic7xxx: Loading serial EEPROM...");
  7942. }
  7943. switch (p->chip)
  7944. {
  7945. case (AHC_AIC7770|AHC_EISA): /* None of these adapters have seeproms. */
  7946. if (aic_inb(p, SCSICONF) & TERM_ENB)
  7947. p->flags |= AHC_TERM_ENB_A;
  7948. if ( (p->features & AHC_TWIN) && (aic_inb(p, SCSICONF + 1) & TERM_ENB) )
  7949. p->flags |= AHC_TERM_ENB_B;
  7950. break;
  7951. case (AHC_AIC7770|AHC_VL):
  7952. have_seeprom = read_284x_seeprom(p, (struct seeprom_config *) scarray);
  7953. break;
  7954. default:
  7955. have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7956. scarray, p->sc_size, p->sc_type);
  7957. if (!have_seeprom)
  7958. {
  7959. if(p->sc_type == C46)
  7960. have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7961. scarray, p->sc_size, C56_66);
  7962. else
  7963. have_seeprom = read_seeprom(p, (p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7964. scarray, p->sc_size, C46);
  7965. }
  7966. if (!have_seeprom)
  7967. {
  7968. p->sc_size = 128;
  7969. have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7970. scarray, p->sc_size, p->sc_type);
  7971. if (!have_seeprom)
  7972. {
  7973. if(p->sc_type == C46)
  7974. have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7975. scarray, p->sc_size, C56_66);
  7976. else
  7977. have_seeprom = read_seeprom(p, 4*(p->flags & (AHC_CHNLB|AHC_CHNLC)),
  7978. scarray, p->sc_size, C46);
  7979. }
  7980. }
  7981. break;
  7982. }
  7983. if (!have_seeprom)
  7984. {
  7985. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7986. {
  7987. printk("\naic7xxx: No SEEPROM available.\n");
  7988. }
  7989. p->flags |= AHC_NEWEEPROM_FMT;
  7990. if (aic_inb(p, SCSISEQ) == 0)
  7991. {
  7992. p->flags |= AHC_USEDEFAULTS;
  7993. p->flags &= ~AHC_BIOS_ENABLED;
  7994. p->scsi_id = p->scsi_id_b = 7;
  7995. *sxfrctl1 |= STPWEN;
  7996. if (aic7xxx_verbose & VERBOSE_PROBE2)
  7997. {
  7998. printk("aic7xxx: Using default values.\n");
  7999. }
  8000. }
  8001. else if (aic7xxx_verbose & VERBOSE_PROBE2)
  8002. {
  8003. printk("aic7xxx: Using leftover BIOS values.\n");
  8004. }
  8005. if ( ((p->chip & ~AHC_CHIPID_MASK) == AHC_PCI) && (*sxfrctl1 & STPWEN) )
  8006. {
  8007. p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
  8008. sc->adapter_control &= ~CFAUTOTERM;
  8009. sc->adapter_control |= CFSTERM | CFWSTERM | CFLVDSTERM;
  8010. }
  8011. if (aic7xxx_extended)
  8012. p->flags |= (AHC_EXTEND_TRANS_A | AHC_EXTEND_TRANS_B);
  8013. else
  8014. p->flags &= ~(AHC_EXTEND_TRANS_A | AHC_EXTEND_TRANS_B);
  8015. }
  8016. else
  8017. {
  8018. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8019. {
  8020. printk("done\n");
  8021. }
  8022. /*
  8023. * Note things in our flags
  8024. */
  8025. p->flags |= AHC_SEEPROM_FOUND;
  8026. /*
  8027. * Update the settings in sxfrctl1 to match the termination settings.
  8028. */
  8029. *sxfrctl1 = 0;
  8030. /*
  8031. * Get our SCSI ID from the SEEPROM setting...
  8032. */
  8033. p->scsi_id = (sc->brtime_id & CFSCSIID);
  8034. /*
  8035. * First process the settings that are different between the VLB
  8036. * and PCI adapter seeproms.
  8037. */
  8038. if ((p->chip & AHC_CHIPID_MASK) == AHC_AIC7770)
  8039. {
  8040. /* VLB adapter seeproms */
  8041. if (sc->bios_control & CF284XEXTEND)
  8042. p->flags |= AHC_EXTEND_TRANS_A;
  8043. if (sc->adapter_control & CF284XSTERM)
  8044. {
  8045. *sxfrctl1 |= STPWEN;
  8046. p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
  8047. }
  8048. }
  8049. else
  8050. {
  8051. /* PCI adapter seeproms */
  8052. if (sc->bios_control & CFEXTEND)
  8053. p->flags |= AHC_EXTEND_TRANS_A;
  8054. if (sc->bios_control & CFBIOSEN)
  8055. p->flags |= AHC_BIOS_ENABLED;
  8056. else
  8057. p->flags &= ~AHC_BIOS_ENABLED;
  8058. if (sc->adapter_control & CFSTERM)
  8059. {
  8060. *sxfrctl1 |= STPWEN;
  8061. p->flags |= AHC_TERM_ENB_SE_LOW | AHC_TERM_ENB_SE_HIGH;
  8062. }
  8063. }
  8064. memcpy(&p->sc, sc, sizeof(struct seeprom_config));
  8065. }
  8066. p->discenable = 0;
  8067. /*
  8068. * Limit to 16 targets just in case. The 2842 for one is known to
  8069. * blow the max_targets setting, future cards might also.
  8070. */
  8071. max_targets = ((p->features & (AHC_TWIN | AHC_WIDE)) ? 16 : 8);
  8072. if (have_seeprom)
  8073. {
  8074. for (i = 0; i < max_targets; i++)
  8075. {
  8076. if( ((p->features & AHC_ULTRA) &&
  8077. !(sc->adapter_control & CFULTRAEN) &&
  8078. (sc->device_flags[i] & CFSYNCHISULTRA)) ||
  8079. (sc->device_flags[i] & CFNEWULTRAFORMAT) )
  8080. {
  8081. p->flags |= AHC_NEWEEPROM_FMT;
  8082. break;
  8083. }
  8084. }
  8085. }
  8086. for (i = 0; i < max_targets; i++)
  8087. {
  8088. mask = (0x01 << i);
  8089. if (!have_seeprom)
  8090. {
  8091. if (aic_inb(p, SCSISEQ) != 0)
  8092. {
  8093. /*
  8094. * OK...the BIOS set things up and left behind the settings we need.
  8095. * Just make our sc->device_flags[i] entry match what the card has
  8096. * set for this device.
  8097. */
  8098. p->discenable =
  8099. ~(aic_inb(p, DISC_DSB) | (aic_inb(p, DISC_DSB + 1) << 8) );
  8100. p->ultraenb =
  8101. (aic_inb(p, ULTRA_ENB) | (aic_inb(p, ULTRA_ENB + 1) << 8) );
  8102. sc->device_flags[i] = (p->discenable & mask) ? CFDISC : 0;
  8103. if (aic_inb(p, TARG_SCSIRATE + i) & WIDEXFER)
  8104. sc->device_flags[i] |= CFWIDEB;
  8105. if (p->features & AHC_ULTRA2)
  8106. {
  8107. if (aic_inb(p, TARG_OFFSET + i))
  8108. {
  8109. sc->device_flags[i] |= CFSYNCH;
  8110. sc->device_flags[i] |= (aic_inb(p, TARG_SCSIRATE + i) & 0x07);
  8111. if ( (aic_inb(p, TARG_SCSIRATE + i) & 0x18) == 0x18 )
  8112. sc->device_flags[i] |= CFSYNCHISULTRA;
  8113. }
  8114. }
  8115. else
  8116. {
  8117. if (aic_inb(p, TARG_SCSIRATE + i) & ~WIDEXFER)
  8118. {
  8119. sc->device_flags[i] |= CFSYNCH;
  8120. if (p->features & AHC_ULTRA)
  8121. sc->device_flags[i] |= ((p->ultraenb & mask) ?
  8122. CFSYNCHISULTRA : 0);
  8123. }
  8124. }
  8125. }
  8126. else
  8127. {
  8128. /*
  8129. * Assume the BIOS has NOT been run on this card and nothing between
  8130. * the card and the devices is configured yet.
  8131. */
  8132. sc->device_flags[i] = CFDISC;
  8133. if (p->features & AHC_WIDE)
  8134. sc->device_flags[i] |= CFWIDEB;
  8135. if (p->features & AHC_ULTRA3)
  8136. sc->device_flags[i] |= 2;
  8137. else if (p->features & AHC_ULTRA2)
  8138. sc->device_flags[i] |= 3;
  8139. else if (p->features & AHC_ULTRA)
  8140. sc->device_flags[i] |= CFSYNCHISULTRA;
  8141. sc->device_flags[i] |= CFSYNCH;
  8142. aic_outb(p, 0, TARG_SCSIRATE + i);
  8143. if (p->features & AHC_ULTRA2)
  8144. aic_outb(p, 0, TARG_OFFSET + i);
  8145. }
  8146. }
  8147. if (sc->device_flags[i] & CFDISC)
  8148. {
  8149. p->discenable |= mask;
  8150. }
  8151. if (p->flags & AHC_NEWEEPROM_FMT)
  8152. {
  8153. if ( !(p->features & AHC_ULTRA2) )
  8154. {
  8155. /*
  8156. * I know of two different Ultra BIOSes that do this differently.
  8157. * One on the Gigabyte 6BXU mb that wants flags[i] & CFXFER to
  8158. * be == to 0x03 and SYNCHISULTRA to be true to mean 40MByte/s
  8159. * while on the IBM Netfinity 5000 they want the same thing
  8160. * to be something else, while flags[i] & CFXFER == 0x03 and
  8161. * SYNCHISULTRA false should be 40MByte/s. So, we set both to
  8162. * 40MByte/s and the lower speeds be damned. People will have
  8163. * to select around the conversely mapped lower speeds in order
  8164. * to select lower speeds on these boards.
  8165. */
  8166. if ( (sc->device_flags[i] & CFNEWULTRAFORMAT) &&
  8167. ((sc->device_flags[i] & CFXFER) == 0x03) )
  8168. {
  8169. sc->device_flags[i] &= ~CFXFER;
  8170. sc->device_flags[i] |= CFSYNCHISULTRA;
  8171. }
  8172. if (sc->device_flags[i] & CFSYNCHISULTRA)
  8173. {
  8174. p->ultraenb |= mask;
  8175. }
  8176. }
  8177. else if ( !(sc->device_flags[i] & CFNEWULTRAFORMAT) &&
  8178. (p->features & AHC_ULTRA2) &&
  8179. (sc->device_flags[i] & CFSYNCHISULTRA) )
  8180. {
  8181. p->ultraenb |= mask;
  8182. }
  8183. }
  8184. else if (sc->adapter_control & CFULTRAEN)
  8185. {
  8186. p->ultraenb |= mask;
  8187. }
  8188. if ( (sc->device_flags[i] & CFSYNCH) == 0)
  8189. {
  8190. sc->device_flags[i] &= ~CFXFER;
  8191. p->ultraenb &= ~mask;
  8192. p->user[i].offset = 0;
  8193. p->user[i].period = 0;
  8194. p->user[i].options = 0;
  8195. }
  8196. else
  8197. {
  8198. if (p->features & AHC_ULTRA3)
  8199. {
  8200. p->user[i].offset = MAX_OFFSET_ULTRA2;
  8201. if( (sc->device_flags[i] & CFXFER) < 0x03 )
  8202. {
  8203. scsirate = (sc->device_flags[i] & CFXFER);
  8204. p->user[i].options = MSG_EXT_PPR_OPTION_DT_CRC;
  8205. }
  8206. else
  8207. {
  8208. scsirate = (sc->device_flags[i] & CFXFER) |
  8209. ((p->ultraenb & mask) ? 0x18 : 0x10);
  8210. p->user[i].options = 0;
  8211. }
  8212. p->user[i].period = aic7xxx_find_period(p, scsirate,
  8213. AHC_SYNCRATE_ULTRA3);
  8214. }
  8215. else if (p->features & AHC_ULTRA2)
  8216. {
  8217. p->user[i].offset = MAX_OFFSET_ULTRA2;
  8218. scsirate = (sc->device_flags[i] & CFXFER) |
  8219. ((p->ultraenb & mask) ? 0x18 : 0x10);
  8220. p->user[i].options = 0;
  8221. p->user[i].period = aic7xxx_find_period(p, scsirate,
  8222. AHC_SYNCRATE_ULTRA2);
  8223. }
  8224. else
  8225. {
  8226. scsirate = (sc->device_flags[i] & CFXFER) << 4;
  8227. p->user[i].options = 0;
  8228. p->user[i].offset = MAX_OFFSET_8BIT;
  8229. if (p->features & AHC_ULTRA)
  8230. {
  8231. short ultraenb;
  8232. ultraenb = aic_inb(p, ULTRA_ENB) |
  8233. (aic_inb(p, ULTRA_ENB + 1) << 8);
  8234. p->user[i].period = aic7xxx_find_period(p, scsirate,
  8235. (p->ultraenb & mask) ?
  8236. AHC_SYNCRATE_ULTRA :
  8237. AHC_SYNCRATE_FAST);
  8238. }
  8239. else
  8240. p->user[i].period = aic7xxx_find_period(p, scsirate,
  8241. AHC_SYNCRATE_FAST);
  8242. }
  8243. }
  8244. if ( (sc->device_flags[i] & CFWIDEB) && (p->features & AHC_WIDE) )
  8245. {
  8246. p->user[i].width = MSG_EXT_WDTR_BUS_16_BIT;
  8247. }
  8248. else
  8249. {
  8250. p->user[i].width = MSG_EXT_WDTR_BUS_8_BIT;
  8251. }
  8252. }
  8253. aic_outb(p, ~(p->discenable & 0xFF), DISC_DSB);
  8254. aic_outb(p, ~((p->discenable >> 8) & 0xFF), DISC_DSB + 1);
  8255. /*
  8256. * We set the p->ultraenb from the SEEPROM to begin with, but now we make
  8257. * it match what is already down in the card. If we are doing a reset
  8258. * on the card then this will get put back to a default state anyway.
  8259. * This allows us to not have to pre-emptively negotiate when using the
  8260. * no_reset option.
  8261. */
  8262. if (p->features & AHC_ULTRA)
  8263. p->ultraenb = aic_inb(p, ULTRA_ENB) | (aic_inb(p, ULTRA_ENB + 1) << 8);
  8264. scsi_conf = (p->scsi_id & HSCSIID);
  8265. if(have_seeprom)
  8266. {
  8267. p->adapter_control = sc->adapter_control;
  8268. p->bios_control = sc->bios_control;
  8269. switch (p->chip & AHC_CHIPID_MASK)
  8270. {
  8271. case AHC_AIC7895:
  8272. case AHC_AIC7896:
  8273. case AHC_AIC7899:
  8274. if (p->adapter_control & CFBPRIMARY)
  8275. p->flags |= AHC_CHANNEL_B_PRIMARY;
  8276. default:
  8277. break;
  8278. }
  8279. if (sc->adapter_control & CFSPARITY)
  8280. scsi_conf |= ENSPCHK;
  8281. }
  8282. else
  8283. {
  8284. scsi_conf |= ENSPCHK | RESET_SCSI;
  8285. }
  8286. /*
  8287. * Only set the SCSICONF and SCSICONF + 1 registers if we are a PCI card.
  8288. * The 2842 and 2742 cards already have these registers set and we don't
  8289. * want to muck with them since we don't set all the bits they do.
  8290. */
  8291. if ( (p->chip & ~AHC_CHIPID_MASK) == AHC_PCI )
  8292. {
  8293. /* Set the host ID */
  8294. aic_outb(p, scsi_conf, SCSICONF);
  8295. /* In case we are a wide card */
  8296. aic_outb(p, p->scsi_id, SCSICONF + 1);
  8297. }
  8298. }
  8299. /*+F*************************************************************************
  8300. * Function:
  8301. * aic7xxx_configure_bugs
  8302. *
  8303. * Description:
  8304. * Take the card passed in and set the appropriate bug flags based upon
  8305. * the card model. Also make any changes needed to device registers or
  8306. * PCI registers while we are here.
  8307. *-F*************************************************************************/
  8308. static void
  8309. aic7xxx_configure_bugs(struct aic7xxx_host *p)
  8310. {
  8311. unsigned short tmp_word;
  8312. switch(p->chip & AHC_CHIPID_MASK)
  8313. {
  8314. case AHC_AIC7860:
  8315. p->bugs |= AHC_BUG_PCI_2_1_RETRY;
  8316. /* fall through */
  8317. case AHC_AIC7850:
  8318. case AHC_AIC7870:
  8319. p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
  8320. break;
  8321. case AHC_AIC7880:
  8322. p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_PCI_2_1_RETRY |
  8323. AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
  8324. break;
  8325. case AHC_AIC7890:
  8326. p->bugs |= AHC_BUG_AUTOFLUSH | AHC_BUG_CACHETHEN;
  8327. break;
  8328. case AHC_AIC7892:
  8329. p->bugs |= AHC_BUG_SCBCHAN_UPLOAD;
  8330. break;
  8331. case AHC_AIC7895:
  8332. p->bugs |= AHC_BUG_TMODE_WIDEODD | AHC_BUG_PCI_2_1_RETRY |
  8333. AHC_BUG_CACHETHEN | AHC_BUG_PCI_MWI;
  8334. break;
  8335. case AHC_AIC7896:
  8336. p->bugs |= AHC_BUG_CACHETHEN_DIS;
  8337. break;
  8338. case AHC_AIC7899:
  8339. p->bugs |= AHC_BUG_SCBCHAN_UPLOAD;
  8340. break;
  8341. default:
  8342. /* Nothing to do */
  8343. break;
  8344. }
  8345. /*
  8346. * Now handle the bugs that require PCI register or card register tweaks
  8347. */
  8348. pci_read_config_word(p->pdev, PCI_COMMAND, &tmp_word);
  8349. if(p->bugs & AHC_BUG_PCI_MWI)
  8350. {
  8351. tmp_word &= ~PCI_COMMAND_INVALIDATE;
  8352. }
  8353. else
  8354. {
  8355. tmp_word |= PCI_COMMAND_INVALIDATE;
  8356. }
  8357. pci_write_config_word(p->pdev, PCI_COMMAND, tmp_word);
  8358. if(p->bugs & AHC_BUG_CACHETHEN)
  8359. {
  8360. aic_outb(p, aic_inb(p, DSCOMMAND0) & ~CACHETHEN, DSCOMMAND0);
  8361. }
  8362. else if (p->bugs & AHC_BUG_CACHETHEN_DIS)
  8363. {
  8364. aic_outb(p, aic_inb(p, DSCOMMAND0) | CACHETHEN, DSCOMMAND0);
  8365. }
  8366. return;
  8367. }
  8368. /*+F*************************************************************************
  8369. * Function:
  8370. * aic7xxx_detect
  8371. *
  8372. * Description:
  8373. * Try to detect and register an Adaptec 7770 or 7870 SCSI controller.
  8374. *
  8375. * XXX - This should really be called aic7xxx_probe(). A sequence of
  8376. * probe(), attach()/detach(), and init() makes more sense than
  8377. * one do-it-all function. This may be useful when (and if) the
  8378. * mid-level SCSI code is overhauled.
  8379. *-F*************************************************************************/
  8380. static int
  8381. aic7xxx_detect(struct scsi_host_template *template)
  8382. {
  8383. struct aic7xxx_host *temp_p = NULL;
  8384. struct aic7xxx_host *current_p = NULL;
  8385. struct aic7xxx_host *list_p = NULL;
  8386. int found = 0;
  8387. #if defined(__i386__) || defined(__alpha__)
  8388. ahc_flag_type flags = 0;
  8389. int type;
  8390. #endif
  8391. unsigned char sxfrctl1;
  8392. #if defined(__i386__) || defined(__alpha__)
  8393. unsigned char hcntrl, hostconf;
  8394. unsigned int slot, base;
  8395. #endif
  8396. #ifdef MODULE
  8397. /*
  8398. * If we are called as a module, the aic7xxx pointer may not be null
  8399. * and it would point to our bootup string, just like on the lilo
  8400. * command line. IF not NULL, then process this config string with
  8401. * aic7xxx_setup
  8402. */
  8403. if(aic7xxx)
  8404. aic7xxx_setup(aic7xxx);
  8405. #endif
  8406. template->proc_name = "aic7xxx";
  8407. template->sg_tablesize = AIC7XXX_MAX_SG;
  8408. #ifdef CONFIG_PCI
  8409. /*
  8410. * PCI-bus probe.
  8411. */
  8412. {
  8413. static struct
  8414. {
  8415. unsigned short vendor_id;
  8416. unsigned short device_id;
  8417. ahc_chip chip;
  8418. ahc_flag_type flags;
  8419. ahc_feature features;
  8420. int board_name_index;
  8421. unsigned short seeprom_size;
  8422. unsigned short seeprom_type;
  8423. } const aic_pdevs[] = {
  8424. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7810, AHC_NONE,
  8425. AHC_FNONE, AHC_FENONE, 1,
  8426. 32, C46 },
  8427. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7850, AHC_AIC7850,
  8428. AHC_PAGESCBS, AHC_AIC7850_FE, 5,
  8429. 32, C46 },
  8430. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7855, AHC_AIC7850,
  8431. AHC_PAGESCBS, AHC_AIC7850_FE, 6,
  8432. 32, C46 },
  8433. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7821, AHC_AIC7860,
  8434. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8435. AHC_AIC7860_FE, 7,
  8436. 32, C46 },
  8437. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_3860, AHC_AIC7860,
  8438. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8439. AHC_AIC7860_FE, 7,
  8440. 32, C46 },
  8441. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_38602, AHC_AIC7860,
  8442. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8443. AHC_AIC7860_FE, 7,
  8444. 32, C46 },
  8445. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_38602, AHC_AIC7860,
  8446. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8447. AHC_AIC7860_FE, 7,
  8448. 32, C46 },
  8449. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7860, AHC_AIC7860,
  8450. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
  8451. AHC_AIC7860_FE, 7,
  8452. 32, C46 },
  8453. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7861, AHC_AIC7860,
  8454. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8455. AHC_AIC7860_FE, 8,
  8456. 32, C46 },
  8457. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7870, AHC_AIC7870,
  8458. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
  8459. AHC_AIC7870_FE, 9,
  8460. 32, C46 },
  8461. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7871, AHC_AIC7870,
  8462. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 10,
  8463. 32, C46 },
  8464. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7872, AHC_AIC7870,
  8465. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8466. AHC_AIC7870_FE, 11,
  8467. 32, C56_66 },
  8468. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7873, AHC_AIC7870,
  8469. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8470. AHC_AIC7870_FE, 12,
  8471. 32, C56_66 },
  8472. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7874, AHC_AIC7870,
  8473. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7870_FE, 13,
  8474. 32, C46 },
  8475. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7880, AHC_AIC7880,
  8476. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MOTHERBOARD,
  8477. AHC_AIC7880_FE, 14,
  8478. 32, C46 },
  8479. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7881, AHC_AIC7880,
  8480. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 15,
  8481. 32, C46 },
  8482. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7882, AHC_AIC7880,
  8483. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8484. AHC_AIC7880_FE, 16,
  8485. 32, C56_66 },
  8486. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7883, AHC_AIC7880,
  8487. AHC_PAGESCBS | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8488. AHC_AIC7880_FE, 17,
  8489. 32, C56_66 },
  8490. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7884, AHC_AIC7880,
  8491. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
  8492. 32, C46 },
  8493. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7885, AHC_AIC7880,
  8494. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
  8495. 32, C46 },
  8496. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7886, AHC_AIC7880,
  8497. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
  8498. 32, C46 },
  8499. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7887, AHC_AIC7880,
  8500. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE | AHC_NEW_AUTOTERM, 19,
  8501. 32, C46 },
  8502. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7888, AHC_AIC7880,
  8503. AHC_PAGESCBS | AHC_BIOS_ENABLED, AHC_AIC7880_FE, 18,
  8504. 32, C46 },
  8505. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_7895, AHC_AIC7895,
  8506. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8507. AHC_AIC7895_FE, 20,
  8508. 32, C56_66 },
  8509. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7890, AHC_AIC7890,
  8510. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8511. AHC_AIC7890_FE, 21,
  8512. 32, C46 },
  8513. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7890B, AHC_AIC7890,
  8514. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8515. AHC_AIC7890_FE, 21,
  8516. 32, C46 },
  8517. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_2930U2, AHC_AIC7890,
  8518. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8519. AHC_AIC7890_FE, 22,
  8520. 32, C46 },
  8521. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_2940U2, AHC_AIC7890,
  8522. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8523. AHC_AIC7890_FE, 23,
  8524. 32, C46 },
  8525. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7896, AHC_AIC7896,
  8526. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8527. AHC_AIC7896_FE, 24,
  8528. 32, C56_66 },
  8529. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_3940U2, AHC_AIC7896,
  8530. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8531. AHC_AIC7896_FE, 25,
  8532. 32, C56_66 },
  8533. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_3950U2D, AHC_AIC7896,
  8534. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8535. AHC_AIC7896_FE, 26,
  8536. 32, C56_66 },
  8537. {PCI_VENDOR_ID_ADAPTEC, PCI_DEVICE_ID_ADAPTEC_1480A, AHC_AIC7860,
  8538. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_NO_STPWEN,
  8539. AHC_AIC7860_FE, 27,
  8540. 32, C46 },
  8541. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892A, AHC_AIC7892,
  8542. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8543. AHC_AIC7892_FE, 28,
  8544. 32, C46 },
  8545. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892B, AHC_AIC7892,
  8546. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8547. AHC_AIC7892_FE, 28,
  8548. 32, C46 },
  8549. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892D, AHC_AIC7892,
  8550. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8551. AHC_AIC7892_FE, 28,
  8552. 32, C46 },
  8553. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7892P, AHC_AIC7892,
  8554. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED,
  8555. AHC_AIC7892_FE, 28,
  8556. 32, C46 },
  8557. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899A, AHC_AIC7899,
  8558. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8559. AHC_AIC7899_FE, 29,
  8560. 32, C56_66 },
  8561. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899B, AHC_AIC7899,
  8562. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8563. AHC_AIC7899_FE, 29,
  8564. 32, C56_66 },
  8565. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899D, AHC_AIC7899,
  8566. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8567. AHC_AIC7899_FE, 29,
  8568. 32, C56_66 },
  8569. {PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_7899P, AHC_AIC7899,
  8570. AHC_PAGESCBS | AHC_NEWEEPROM_FMT | AHC_BIOS_ENABLED | AHC_MULTI_CHANNEL,
  8571. AHC_AIC7899_FE, 29,
  8572. 32, C56_66 },
  8573. };
  8574. unsigned short command;
  8575. unsigned int devconfig, i, oldverbose;
  8576. struct pci_dev *pdev = NULL;
  8577. for (i = 0; i < ARRAY_SIZE(aic_pdevs); i++)
  8578. {
  8579. pdev = NULL;
  8580. while ((pdev = pci_get_device(aic_pdevs[i].vendor_id,
  8581. aic_pdevs[i].device_id,
  8582. pdev))) {
  8583. if (pci_enable_device(pdev))
  8584. continue;
  8585. if ( i == 0 ) /* We found one, but it's the 7810 RAID cont. */
  8586. {
  8587. if (aic7xxx_verbose & (VERBOSE_PROBE|VERBOSE_PROBE2))
  8588. {
  8589. printk(KERN_INFO "aic7xxx: The 7810 RAID controller is not "
  8590. "supported by\n");
  8591. printk(KERN_INFO " this driver, we are ignoring it.\n");
  8592. }
  8593. }
  8594. else if ( (temp_p = kmalloc(sizeof(struct aic7xxx_host),
  8595. GFP_ATOMIC)) != NULL )
  8596. {
  8597. memset(temp_p, 0, sizeof(struct aic7xxx_host));
  8598. temp_p->chip = aic_pdevs[i].chip | AHC_PCI;
  8599. temp_p->flags = aic_pdevs[i].flags;
  8600. temp_p->features = aic_pdevs[i].features;
  8601. temp_p->board_name_index = aic_pdevs[i].board_name_index;
  8602. temp_p->sc_size = aic_pdevs[i].seeprom_size;
  8603. temp_p->sc_type = aic_pdevs[i].seeprom_type;
  8604. /*
  8605. * Read sundry information from PCI BIOS.
  8606. */
  8607. temp_p->irq = pdev->irq;
  8608. temp_p->pdev = pdev;
  8609. temp_p->pci_bus = pdev->bus->number;
  8610. temp_p->pci_device_fn = pdev->devfn;
  8611. temp_p->base = pci_resource_start(pdev, 0);
  8612. temp_p->mbase = pci_resource_start(pdev, 1);
  8613. current_p = list_p;
  8614. while(current_p && temp_p)
  8615. {
  8616. if ( ((current_p->pci_bus == temp_p->pci_bus) &&
  8617. (current_p->pci_device_fn == temp_p->pci_device_fn)) ||
  8618. (temp_p->base && (current_p->base == temp_p->base)) ||
  8619. (temp_p->mbase && (current_p->mbase == temp_p->mbase)) )
  8620. {
  8621. /* duplicate PCI entry, skip it */
  8622. kfree(temp_p);
  8623. temp_p = NULL;
  8624. continue;
  8625. }
  8626. current_p = current_p->next;
  8627. }
  8628. if(pci_request_regions(temp_p->pdev, "aic7xxx"))
  8629. {
  8630. printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
  8631. board_names[aic_pdevs[i].board_name_index],
  8632. temp_p->pci_bus,
  8633. PCI_SLOT(temp_p->pci_device_fn),
  8634. PCI_FUNC(temp_p->pci_device_fn));
  8635. printk("aic7xxx: I/O ports already in use, ignoring.\n");
  8636. kfree(temp_p);
  8637. continue;
  8638. }
  8639. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8640. printk("aic7xxx: <%s> at PCI %d/%d\n",
  8641. board_names[aic_pdevs[i].board_name_index],
  8642. PCI_SLOT(pdev->devfn),
  8643. PCI_FUNC(pdev->devfn));
  8644. pci_read_config_word(pdev, PCI_COMMAND, &command);
  8645. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8646. {
  8647. printk("aic7xxx: Initial PCI_COMMAND value was 0x%x\n",
  8648. (int)command);
  8649. }
  8650. #ifdef AIC7XXX_STRICT_PCI_SETUP
  8651. command |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
  8652. PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
  8653. #else
  8654. command |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
  8655. #endif
  8656. command &= ~PCI_COMMAND_INVALIDATE;
  8657. if (aic7xxx_pci_parity == 0)
  8658. command &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  8659. pci_write_config_word(pdev, PCI_COMMAND, command);
  8660. #ifdef AIC7XXX_STRICT_PCI_SETUP
  8661. pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
  8662. if (aic7xxx_verbose & VERBOSE_PROBE2)
  8663. {
  8664. printk("aic7xxx: Initial DEVCONFIG value was 0x%x\n", devconfig);
  8665. }
  8666. devconfig |= 0x80000040;
  8667. pci_write_config_dword(pdev, DEVCONFIG, devconfig);
  8668. #endif /* AIC7XXX_STRICT_PCI_SETUP */
  8669. temp_p->unpause = INTEN;
  8670. temp_p->pause = temp_p->unpause | PAUSE;
  8671. if ( ((temp_p->base == 0) &&
  8672. (temp_p->mbase == 0)) ||
  8673. (temp_p->irq == 0) )
  8674. {
  8675. printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
  8676. board_names[aic_pdevs[i].board_name_index],
  8677. temp_p->pci_bus,
  8678. PCI_SLOT(temp_p->pci_device_fn),
  8679. PCI_FUNC(temp_p->pci_device_fn));
  8680. printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
  8681. goto skip_pci_controller;
  8682. }
  8683. #ifdef MMAPIO
  8684. if ( !(temp_p->base) || !(temp_p->flags & AHC_MULTI_CHANNEL) ||
  8685. ((temp_p->chip != (AHC_AIC7870 | AHC_PCI)) &&
  8686. (temp_p->chip != (AHC_AIC7880 | AHC_PCI))) )
  8687. {
  8688. temp_p->maddr = ioremap_nocache(temp_p->mbase, 256);
  8689. if(temp_p->maddr)
  8690. {
  8691. /*
  8692. * We need to check the I/O with the MMAPed address. Some machines
  8693. * simply fail to work with MMAPed I/O and certain controllers.
  8694. */
  8695. if(aic_inb(temp_p, HCNTRL) == 0xff)
  8696. {
  8697. /*
  8698. * OK.....we failed our test....go back to programmed I/O
  8699. */
  8700. printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
  8701. board_names[aic_pdevs[i].board_name_index],
  8702. temp_p->pci_bus,
  8703. PCI_SLOT(temp_p->pci_device_fn),
  8704. PCI_FUNC(temp_p->pci_device_fn));
  8705. printk(KERN_INFO "aic7xxx: MMAPed I/O failed, reverting to "
  8706. "Programmed I/O.\n");
  8707. iounmap(temp_p->maddr);
  8708. temp_p->maddr = NULL;
  8709. if(temp_p->base == 0)
  8710. {
  8711. printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
  8712. board_names[aic_pdevs[i].board_name_index],
  8713. temp_p->pci_bus,
  8714. PCI_SLOT(temp_p->pci_device_fn),
  8715. PCI_FUNC(temp_p->pci_device_fn));
  8716. printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
  8717. goto skip_pci_controller;
  8718. }
  8719. }
  8720. }
  8721. }
  8722. #endif
  8723. /*
  8724. * We HAVE to make sure the first pause_sequencer() and all other
  8725. * subsequent I/O that isn't PCI config space I/O takes place
  8726. * after the MMAPed I/O region is configured and tested. The
  8727. * problem is the PowerPC architecture that doesn't support
  8728. * programmed I/O at all, so we have to have the MMAP I/O set up
  8729. * for this pause to even work on those machines.
  8730. */
  8731. pause_sequencer(temp_p);
  8732. /*
  8733. * Clear out any pending PCI error status messages. Also set
  8734. * verbose to 0 so that we don't emit strange PCI error messages
  8735. * while cleaning out the current status bits.
  8736. */
  8737. oldverbose = aic7xxx_verbose;
  8738. aic7xxx_verbose = 0;
  8739. aic7xxx_pci_intr(temp_p);
  8740. aic7xxx_verbose = oldverbose;
  8741. temp_p->bios_address = 0;
  8742. /*
  8743. * Remember how the card was setup in case there is no seeprom.
  8744. */
  8745. if (temp_p->features & AHC_ULTRA2)
  8746. temp_p->scsi_id = aic_inb(temp_p, SCSIID_ULTRA2) & OID;
  8747. else
  8748. temp_p->scsi_id = aic_inb(temp_p, SCSIID) & OID;
  8749. /*
  8750. * Get current termination setting
  8751. */
  8752. sxfrctl1 = aic_inb(temp_p, SXFRCTL1);
  8753. if (aic7xxx_chip_reset(temp_p) == -1)
  8754. {
  8755. goto skip_pci_controller;
  8756. }
  8757. /*
  8758. * Very quickly put the term setting back into the register since
  8759. * the chip reset may cause odd things to happen. This is to keep
  8760. * LVD busses with lots of drives from draining the power out of
  8761. * the diffsense line before we get around to running the
  8762. * configure_termination() function. Also restore the STPWLEVEL
  8763. * bit of DEVCONFIG
  8764. */
  8765. aic_outb(temp_p, sxfrctl1, SXFRCTL1);
  8766. pci_write_config_dword(temp_p->pdev, DEVCONFIG, devconfig);
  8767. sxfrctl1 &= STPWEN;
  8768. /*
  8769. * We need to set the CHNL? assignments before loading the SEEPROM
  8770. * The 3940 and 3985 cards (original stuff, not any of the later
  8771. * stuff) are 7870 and 7880 class chips. The Ultra2 stuff falls
  8772. * under 7896 and 7897. The 7895 is in a class by itself :)
  8773. */
  8774. switch (temp_p->chip & AHC_CHIPID_MASK)
  8775. {
  8776. case AHC_AIC7870: /* 3840 / 3985 */
  8777. case AHC_AIC7880: /* 3840 UW / 3985 UW */
  8778. if(temp_p->flags & AHC_MULTI_CHANNEL)
  8779. {
  8780. switch(PCI_SLOT(temp_p->pci_device_fn))
  8781. {
  8782. case 5:
  8783. temp_p->flags |= AHC_CHNLB;
  8784. break;
  8785. case 8:
  8786. temp_p->flags |= AHC_CHNLB;
  8787. break;
  8788. case 12:
  8789. temp_p->flags |= AHC_CHNLC;
  8790. break;
  8791. default:
  8792. break;
  8793. }
  8794. }
  8795. break;
  8796. case AHC_AIC7895: /* 7895 */
  8797. case AHC_AIC7896: /* 7896/7 */
  8798. case AHC_AIC7899: /* 7899 */
  8799. if (PCI_FUNC(pdev->devfn) != 0)
  8800. {
  8801. temp_p->flags |= AHC_CHNLB;
  8802. }
  8803. /*
  8804. * The 7895 is the only chipset that sets the SCBSIZE32 param
  8805. * in the DEVCONFIG register. The Ultra2 chipsets use
  8806. * the DSCOMMAND0 register instead.
  8807. */
  8808. if ((temp_p->chip & AHC_CHIPID_MASK) == AHC_AIC7895)
  8809. {
  8810. pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
  8811. devconfig |= SCBSIZE32;
  8812. pci_write_config_dword(pdev, DEVCONFIG, devconfig);
  8813. }
  8814. break;
  8815. default:
  8816. break;
  8817. }
  8818. /*
  8819. * Loading of the SEEPROM needs to come after we've set the flags
  8820. * to indicate possible CHNLB and CHNLC assigments. Otherwise,
  8821. * on 394x and 398x cards we'll end up reading the wrong settings
  8822. * for channels B and C
  8823. */
  8824. switch (temp_p->chip & AHC_CHIPID_MASK)
  8825. {
  8826. case AHC_AIC7892:
  8827. case AHC_AIC7899:
  8828. aic_outb(temp_p, 0, SCAMCTL);
  8829. /*
  8830. * Switch to the alt mode of the chip...
  8831. */
  8832. aic_outb(temp_p, aic_inb(temp_p, SFUNCT) | ALT_MODE, SFUNCT);
  8833. /*
  8834. * Set our options...the last two items set our CRC after x byte
  8835. * count in target mode...
  8836. */
  8837. aic_outb(temp_p, AUTO_MSGOUT_DE | DIS_MSGIN_DUALEDGE, OPTIONMODE);
  8838. aic_outb(temp_p, 0x00, 0x0b);
  8839. aic_outb(temp_p, 0x10, 0x0a);
  8840. /*
  8841. * switch back to normal mode...
  8842. */
  8843. aic_outb(temp_p, aic_inb(temp_p, SFUNCT) & ~ALT_MODE, SFUNCT);
  8844. aic_outb(temp_p, CRCVALCHKEN | CRCENDCHKEN | CRCREQCHKEN |
  8845. TARGCRCENDEN | TARGCRCCNTEN,
  8846. CRCCONTROL1);
  8847. aic_outb(temp_p, ((aic_inb(temp_p, DSCOMMAND0) | USCBSIZE32 |
  8848. MPARCKEN | CIOPARCKEN | CACHETHEN) &
  8849. ~DPARCKEN), DSCOMMAND0);
  8850. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  8851. break;
  8852. case AHC_AIC7890:
  8853. case AHC_AIC7896:
  8854. aic_outb(temp_p, 0, SCAMCTL);
  8855. aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
  8856. CACHETHEN | MPARCKEN | USCBSIZE32 |
  8857. CIOPARCKEN) & ~DPARCKEN, DSCOMMAND0);
  8858. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  8859. break;
  8860. case AHC_AIC7850:
  8861. case AHC_AIC7860:
  8862. /*
  8863. * Set the DSCOMMAND0 register on these cards different from
  8864. * on the 789x cards. Also, read the SEEPROM as well.
  8865. */
  8866. aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
  8867. CACHETHEN | MPARCKEN) & ~DPARCKEN,
  8868. DSCOMMAND0);
  8869. /* FALLTHROUGH */
  8870. default:
  8871. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  8872. break;
  8873. case AHC_AIC7880:
  8874. /*
  8875. * Check the rev of the chipset before we change DSCOMMAND0
  8876. */
  8877. pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
  8878. if ((devconfig & 0xff) >= 1)
  8879. {
  8880. aic_outb(temp_p, (aic_inb(temp_p, DSCOMMAND0) |
  8881. CACHETHEN | MPARCKEN) & ~DPARCKEN,
  8882. DSCOMMAND0);
  8883. }
  8884. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  8885. break;
  8886. }
  8887. /*
  8888. * and then we need another switch based on the type in order to
  8889. * make sure the channel B primary flag is set properly on 7895
  8890. * controllers....Arrrgggghhh!!! We also have to catch the fact
  8891. * that when you disable the BIOS on the 7895 on the Intel DK440LX
  8892. * motherboard, and possibly others, it only sets the BIOS disabled
  8893. * bit on the A channel...I think I'm starting to lean towards
  8894. * going postal....
  8895. */
  8896. switch(temp_p->chip & AHC_CHIPID_MASK)
  8897. {
  8898. case AHC_AIC7895:
  8899. case AHC_AIC7896:
  8900. case AHC_AIC7899:
  8901. current_p = list_p;
  8902. while(current_p != NULL)
  8903. {
  8904. if ( (current_p->pci_bus == temp_p->pci_bus) &&
  8905. (PCI_SLOT(current_p->pci_device_fn) ==
  8906. PCI_SLOT(temp_p->pci_device_fn)) )
  8907. {
  8908. if ( PCI_FUNC(current_p->pci_device_fn) == 0 )
  8909. {
  8910. temp_p->flags |=
  8911. (current_p->flags & AHC_CHANNEL_B_PRIMARY);
  8912. temp_p->flags &= ~(AHC_BIOS_ENABLED|AHC_USEDEFAULTS);
  8913. temp_p->flags |=
  8914. (current_p->flags & (AHC_BIOS_ENABLED|AHC_USEDEFAULTS));
  8915. }
  8916. else
  8917. {
  8918. current_p->flags |=
  8919. (temp_p->flags & AHC_CHANNEL_B_PRIMARY);
  8920. current_p->flags &= ~(AHC_BIOS_ENABLED|AHC_USEDEFAULTS);
  8921. current_p->flags |=
  8922. (temp_p->flags & (AHC_BIOS_ENABLED|AHC_USEDEFAULTS));
  8923. }
  8924. }
  8925. current_p = current_p->next;
  8926. }
  8927. break;
  8928. default:
  8929. break;
  8930. }
  8931. /*
  8932. * We only support external SCB RAM on the 7895/6/7 chipsets.
  8933. * We could support it on the 7890/1 easy enough, but I don't
  8934. * know of any 7890/1 based cards that have it. I do know
  8935. * of 7895/6/7 cards that have it and they work properly.
  8936. */
  8937. switch(temp_p->chip & AHC_CHIPID_MASK)
  8938. {
  8939. default:
  8940. break;
  8941. case AHC_AIC7895:
  8942. case AHC_AIC7896:
  8943. case AHC_AIC7899:
  8944. pci_read_config_dword(pdev, DEVCONFIG, &devconfig);
  8945. if (temp_p->features & AHC_ULTRA2)
  8946. {
  8947. if ( (aic_inb(temp_p, DSCOMMAND0) & RAMPSM_ULTRA2) &&
  8948. (aic7xxx_scbram) )
  8949. {
  8950. aic_outb(temp_p,
  8951. aic_inb(temp_p, DSCOMMAND0) & ~SCBRAMSEL_ULTRA2,
  8952. DSCOMMAND0);
  8953. temp_p->flags |= AHC_EXTERNAL_SRAM;
  8954. devconfig |= EXTSCBPEN;
  8955. }
  8956. else if (aic_inb(temp_p, DSCOMMAND0) & RAMPSM_ULTRA2)
  8957. {
  8958. printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
  8959. board_names[aic_pdevs[i].board_name_index],
  8960. temp_p->pci_bus,
  8961. PCI_SLOT(temp_p->pci_device_fn),
  8962. PCI_FUNC(temp_p->pci_device_fn));
  8963. printk("aic7xxx: external SCB RAM detected, "
  8964. "but not enabled\n");
  8965. }
  8966. }
  8967. else
  8968. {
  8969. if ((devconfig & RAMPSM) && (aic7xxx_scbram))
  8970. {
  8971. devconfig &= ~SCBRAMSEL;
  8972. devconfig |= EXTSCBPEN;
  8973. temp_p->flags |= AHC_EXTERNAL_SRAM;
  8974. }
  8975. else if (devconfig & RAMPSM)
  8976. {
  8977. printk(KERN_INFO "aic7xxx: <%s> at PCI %d/%d/%d\n",
  8978. board_names[aic_pdevs[i].board_name_index],
  8979. temp_p->pci_bus,
  8980. PCI_SLOT(temp_p->pci_device_fn),
  8981. PCI_FUNC(temp_p->pci_device_fn));
  8982. printk("aic7xxx: external SCB RAM detected, "
  8983. "but not enabled\n");
  8984. }
  8985. }
  8986. pci_write_config_dword(pdev, DEVCONFIG, devconfig);
  8987. if ( (temp_p->flags & AHC_EXTERNAL_SRAM) &&
  8988. (temp_p->flags & AHC_CHNLB) )
  8989. aic_outb(temp_p, 1, CCSCBBADDR);
  8990. break;
  8991. }
  8992. /*
  8993. * Take the LED out of diagnostic mode
  8994. */
  8995. aic_outb(temp_p,
  8996. (aic_inb(temp_p, SBLKCTL) & ~(DIAGLEDEN | DIAGLEDON)),
  8997. SBLKCTL);
  8998. /*
  8999. * We don't know where this is set in the SEEPROM or by the
  9000. * BIOS, so we default to 100%. On Ultra2 controllers, use 75%
  9001. * instead.
  9002. */
  9003. if (temp_p->features & AHC_ULTRA2)
  9004. {
  9005. aic_outb(temp_p, RD_DFTHRSH_MAX | WR_DFTHRSH_MAX, DFF_THRSH);
  9006. }
  9007. else
  9008. {
  9009. aic_outb(temp_p, DFTHRSH_100, DSPCISTATUS);
  9010. }
  9011. /*
  9012. * Call our function to fixup any bugs that exist on this chipset.
  9013. * This may muck with PCI settings and other device settings, so
  9014. * make sure it's after all the other PCI and device register
  9015. * tweaks so it can back out bad settings on specific broken cards.
  9016. */
  9017. aic7xxx_configure_bugs(temp_p);
  9018. /* Hold a pci device reference */
  9019. pci_dev_get(temp_p->pdev);
  9020. if ( list_p == NULL )
  9021. {
  9022. list_p = current_p = temp_p;
  9023. }
  9024. else
  9025. {
  9026. current_p = list_p;
  9027. while(current_p->next != NULL)
  9028. current_p = current_p->next;
  9029. current_p->next = temp_p;
  9030. }
  9031. temp_p->next = NULL;
  9032. found++;
  9033. continue;
  9034. skip_pci_controller:
  9035. #ifdef CONFIG_PCI
  9036. pci_release_regions(temp_p->pdev);
  9037. #endif
  9038. kfree(temp_p);
  9039. } /* Found an Adaptec PCI device. */
  9040. else /* Well, we found one, but we couldn't get any memory */
  9041. {
  9042. printk("aic7xxx: Found <%s>\n",
  9043. board_names[aic_pdevs[i].board_name_index]);
  9044. printk(KERN_INFO "aic7xxx: Unable to allocate device memory, "
  9045. "skipping.\n");
  9046. }
  9047. } /* while(pdev=....) */
  9048. } /* for PCI_DEVICES */
  9049. }
  9050. #endif /* CONFIG_PCI */
  9051. #if defined(__i386__) || defined(__alpha__)
  9052. /*
  9053. * EISA/VL-bus card signature probe.
  9054. */
  9055. slot = MINSLOT;
  9056. while ( (slot <= MAXSLOT) &&
  9057. !(aic7xxx_no_probe) )
  9058. {
  9059. base = SLOTBASE(slot) + MINREG;
  9060. if (!request_region(base, MAXREG - MINREG, "aic7xxx"))
  9061. {
  9062. /*
  9063. * Some other driver has staked a
  9064. * claim to this i/o region already.
  9065. */
  9066. slot++;
  9067. continue; /* back to the beginning of the for loop */
  9068. }
  9069. flags = 0;
  9070. type = aic7xxx_probe(slot, base + AHC_HID0, &flags);
  9071. if (type == -1)
  9072. {
  9073. release_region(base, MAXREG - MINREG);
  9074. slot++;
  9075. continue;
  9076. }
  9077. temp_p = kmalloc(sizeof(struct aic7xxx_host), GFP_ATOMIC);
  9078. if (temp_p == NULL)
  9079. {
  9080. printk(KERN_WARNING "aic7xxx: Unable to allocate device space.\n");
  9081. release_region(base, MAXREG - MINREG);
  9082. slot++;
  9083. continue; /* back to the beginning of the while loop */
  9084. }
  9085. /*
  9086. * Pause the card preserving the IRQ type. Allow the operator
  9087. * to override the IRQ trigger.
  9088. */
  9089. if (aic7xxx_irq_trigger == 1)
  9090. hcntrl = IRQMS; /* Level */
  9091. else if (aic7xxx_irq_trigger == 0)
  9092. hcntrl = 0; /* Edge */
  9093. else
  9094. hcntrl = inb(base + HCNTRL) & IRQMS; /* Default */
  9095. memset(temp_p, 0, sizeof(struct aic7xxx_host));
  9096. temp_p->unpause = hcntrl | INTEN;
  9097. temp_p->pause = hcntrl | PAUSE | INTEN;
  9098. temp_p->base = base;
  9099. temp_p->mbase = 0;
  9100. temp_p->maddr = NULL;
  9101. temp_p->pci_bus = 0;
  9102. temp_p->pci_device_fn = slot;
  9103. aic_outb(temp_p, hcntrl | PAUSE, HCNTRL);
  9104. while( (aic_inb(temp_p, HCNTRL) & PAUSE) == 0 ) ;
  9105. if (aic7xxx_chip_reset(temp_p) == -1)
  9106. temp_p->irq = 0;
  9107. else
  9108. temp_p->irq = aic_inb(temp_p, INTDEF) & 0x0F;
  9109. temp_p->flags |= AHC_PAGESCBS;
  9110. switch (temp_p->irq)
  9111. {
  9112. case 9:
  9113. case 10:
  9114. case 11:
  9115. case 12:
  9116. case 14:
  9117. case 15:
  9118. break;
  9119. default:
  9120. printk(KERN_WARNING "aic7xxx: Host adapter uses unsupported IRQ "
  9121. "level %d, ignoring.\n", temp_p->irq);
  9122. kfree(temp_p);
  9123. release_region(base, MAXREG - MINREG);
  9124. slot++;
  9125. continue; /* back to the beginning of the while loop */
  9126. }
  9127. /*
  9128. * We are commited now, everything has been checked and this card
  9129. * has been found, now we just set it up
  9130. */
  9131. /*
  9132. * Insert our new struct into the list at the end
  9133. */
  9134. if (list_p == NULL)
  9135. {
  9136. list_p = current_p = temp_p;
  9137. }
  9138. else
  9139. {
  9140. current_p = list_p;
  9141. while (current_p->next != NULL)
  9142. current_p = current_p->next;
  9143. current_p->next = temp_p;
  9144. }
  9145. switch (type)
  9146. {
  9147. case 0:
  9148. temp_p->board_name_index = 2;
  9149. if (aic7xxx_verbose & VERBOSE_PROBE2)
  9150. printk("aic7xxx: <%s> at EISA %d\n",
  9151. board_names[2], slot);
  9152. /* FALLTHROUGH */
  9153. case 1:
  9154. {
  9155. temp_p->chip = AHC_AIC7770 | AHC_EISA;
  9156. temp_p->features |= AHC_AIC7770_FE;
  9157. temp_p->bios_control = aic_inb(temp_p, HA_274_BIOSCTRL);
  9158. /*
  9159. * Get the primary channel information. Right now we don't
  9160. * do anything with this, but someday we will be able to inform
  9161. * the mid-level SCSI code which channel is primary.
  9162. */
  9163. if (temp_p->board_name_index == 0)
  9164. {
  9165. temp_p->board_name_index = 3;
  9166. if (aic7xxx_verbose & VERBOSE_PROBE2)
  9167. printk("aic7xxx: <%s> at EISA %d\n",
  9168. board_names[3], slot);
  9169. }
  9170. if (temp_p->bios_control & CHANNEL_B_PRIMARY)
  9171. {
  9172. temp_p->flags |= AHC_CHANNEL_B_PRIMARY;
  9173. }
  9174. if ((temp_p->bios_control & BIOSMODE) == BIOSDISABLED)
  9175. {
  9176. temp_p->flags &= ~AHC_BIOS_ENABLED;
  9177. }
  9178. else
  9179. {
  9180. temp_p->flags &= ~AHC_USEDEFAULTS;
  9181. temp_p->flags |= AHC_BIOS_ENABLED;
  9182. if ( (temp_p->bios_control & 0x20) == 0 )
  9183. {
  9184. temp_p->bios_address = 0xcc000;
  9185. temp_p->bios_address += (0x4000 * (temp_p->bios_control & 0x07));
  9186. }
  9187. else
  9188. {
  9189. temp_p->bios_address = 0xd0000;
  9190. temp_p->bios_address += (0x8000 * (temp_p->bios_control & 0x06));
  9191. }
  9192. }
  9193. temp_p->adapter_control = aic_inb(temp_p, SCSICONF) << 8;
  9194. temp_p->adapter_control |= aic_inb(temp_p, SCSICONF + 1);
  9195. if (temp_p->features & AHC_WIDE)
  9196. {
  9197. temp_p->scsi_id = temp_p->adapter_control & HWSCSIID;
  9198. temp_p->scsi_id_b = temp_p->scsi_id;
  9199. }
  9200. else
  9201. {
  9202. temp_p->scsi_id = (temp_p->adapter_control >> 8) & HSCSIID;
  9203. temp_p->scsi_id_b = temp_p->adapter_control & HSCSIID;
  9204. }
  9205. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  9206. break;
  9207. }
  9208. case 2:
  9209. case 3:
  9210. temp_p->chip = AHC_AIC7770 | AHC_VL;
  9211. temp_p->features |= AHC_AIC7770_FE;
  9212. if (type == 2)
  9213. temp_p->flags |= AHC_BIOS_ENABLED;
  9214. else
  9215. temp_p->flags &= ~AHC_BIOS_ENABLED;
  9216. if (aic_inb(temp_p, SCSICONF) & TERM_ENB)
  9217. sxfrctl1 = STPWEN;
  9218. aic7xxx_load_seeprom(temp_p, &sxfrctl1);
  9219. temp_p->board_name_index = 4;
  9220. if (aic7xxx_verbose & VERBOSE_PROBE2)
  9221. printk("aic7xxx: <%s> at VLB %d\n",
  9222. board_names[2], slot);
  9223. switch( aic_inb(temp_p, STATUS_2840) & BIOS_SEL )
  9224. {
  9225. case 0x00:
  9226. temp_p->bios_address = 0xe0000;
  9227. break;
  9228. case 0x20:
  9229. temp_p->bios_address = 0xc8000;
  9230. break;
  9231. case 0x40:
  9232. temp_p->bios_address = 0xd0000;
  9233. break;
  9234. case 0x60:
  9235. temp_p->bios_address = 0xd8000;
  9236. break;
  9237. default:
  9238. break; /* can't get here */
  9239. }
  9240. break;
  9241. default: /* Won't get here. */
  9242. break;
  9243. }
  9244. if (aic7xxx_verbose & VERBOSE_PROBE2)
  9245. {
  9246. printk(KERN_INFO "aic7xxx: BIOS %sabled, IO Port 0x%lx, IRQ %d (%s)\n",
  9247. (temp_p->flags & AHC_USEDEFAULTS) ? "dis" : "en", temp_p->base,
  9248. temp_p->irq,
  9249. (temp_p->pause & IRQMS) ? "level sensitive" : "edge triggered");
  9250. printk(KERN_INFO "aic7xxx: Extended translation %sabled.\n",
  9251. (temp_p->flags & AHC_EXTEND_TRANS_A) ? "en" : "dis");
  9252. }
  9253. /*
  9254. * All the 7770 based chipsets have this bug
  9255. */
  9256. temp_p->bugs |= AHC_BUG_TMODE_WIDEODD;
  9257. /*
  9258. * Set the FIFO threshold and the bus off time.
  9259. */
  9260. hostconf = aic_inb(temp_p, HOSTCONF);
  9261. aic_outb(temp_p, hostconf & DFTHRSH, BUSSPD);
  9262. aic_outb(temp_p, (hostconf << 2) & BOFF, BUSTIME);
  9263. slot++;
  9264. found++;
  9265. }
  9266. #endif /* defined(__i386__) || defined(__alpha__) */
  9267. /*
  9268. * Now, we re-order the probed devices by BIOS address and BUS class.
  9269. * In general, we follow this algorithm to make the adapters show up
  9270. * in the same order under linux that the computer finds them.
  9271. * 1: All VLB/EISA cards with BIOS_ENABLED first, according to BIOS
  9272. * address, going from lowest to highest.
  9273. * 2: All PCI controllers with BIOS_ENABLED next, according to BIOS
  9274. * address, going from lowest to highest.
  9275. * 3: Remaining VLB/EISA controllers going in slot order.
  9276. * 4: Remaining PCI controllers, going in PCI device order (reversable)
  9277. */
  9278. {
  9279. struct aic7xxx_host *sort_list[4] = { NULL, NULL, NULL, NULL };
  9280. struct aic7xxx_host *vlb, *pci;
  9281. struct aic7xxx_host *prev_p;
  9282. struct aic7xxx_host *p;
  9283. unsigned char left;
  9284. prev_p = vlb = pci = NULL;
  9285. temp_p = list_p;
  9286. while (temp_p != NULL)
  9287. {
  9288. switch(temp_p->chip & ~AHC_CHIPID_MASK)
  9289. {
  9290. case AHC_EISA:
  9291. case AHC_VL:
  9292. {
  9293. p = temp_p;
  9294. if (p->flags & AHC_BIOS_ENABLED)
  9295. vlb = sort_list[0];
  9296. else
  9297. vlb = sort_list[2];
  9298. if (vlb == NULL)
  9299. {
  9300. vlb = temp_p;
  9301. temp_p = temp_p->next;
  9302. vlb->next = NULL;
  9303. }
  9304. else
  9305. {
  9306. current_p = vlb;
  9307. prev_p = NULL;
  9308. while ( (current_p != NULL) &&
  9309. (current_p->bios_address < temp_p->bios_address))
  9310. {
  9311. prev_p = current_p;
  9312. current_p = current_p->next;
  9313. }
  9314. if (prev_p != NULL)
  9315. {
  9316. prev_p->next = temp_p;
  9317. temp_p = temp_p->next;
  9318. prev_p->next->next = current_p;
  9319. }
  9320. else
  9321. {
  9322. vlb = temp_p;
  9323. temp_p = temp_p->next;
  9324. vlb->next = current_p;
  9325. }
  9326. }
  9327. if (p->flags & AHC_BIOS_ENABLED)
  9328. sort_list[0] = vlb;
  9329. else
  9330. sort_list[2] = vlb;
  9331. break;
  9332. }
  9333. default: /* All PCI controllers fall through to default */
  9334. {
  9335. p = temp_p;
  9336. if (p->flags & AHC_BIOS_ENABLED)
  9337. pci = sort_list[1];
  9338. else
  9339. pci = sort_list[3];
  9340. if (pci == NULL)
  9341. {
  9342. pci = temp_p;
  9343. temp_p = temp_p->next;
  9344. pci->next = NULL;
  9345. }
  9346. else
  9347. {
  9348. current_p = pci;
  9349. prev_p = NULL;
  9350. if (!aic7xxx_reverse_scan)
  9351. {
  9352. while ( (current_p != NULL) &&
  9353. ( (PCI_SLOT(current_p->pci_device_fn) |
  9354. (current_p->pci_bus << 8)) <
  9355. (PCI_SLOT(temp_p->pci_device_fn) |
  9356. (temp_p->pci_bus << 8)) ) )
  9357. {
  9358. prev_p = current_p;
  9359. current_p = current_p->next;
  9360. }
  9361. }
  9362. else
  9363. {
  9364. while ( (current_p != NULL) &&
  9365. ( (PCI_SLOT(current_p->pci_device_fn) |
  9366. (current_p->pci_bus << 8)) >
  9367. (PCI_SLOT(temp_p->pci_device_fn) |
  9368. (temp_p->pci_bus << 8)) ) )
  9369. {
  9370. prev_p = current_p;
  9371. current_p = current_p->next;
  9372. }
  9373. }
  9374. /*
  9375. * Are we dealing with a 7895/6/7/9 where we need to sort the
  9376. * channels as well, if so, the bios_address values should
  9377. * be the same
  9378. */
  9379. if ( (current_p) && (temp_p->flags & AHC_MULTI_CHANNEL) &&
  9380. (temp_p->pci_bus == current_p->pci_bus) &&
  9381. (PCI_SLOT(temp_p->pci_device_fn) ==
  9382. PCI_SLOT(current_p->pci_device_fn)) )
  9383. {
  9384. if (temp_p->flags & AHC_CHNLB)
  9385. {
  9386. if ( !(temp_p->flags & AHC_CHANNEL_B_PRIMARY) )
  9387. {
  9388. prev_p = current_p;
  9389. current_p = current_p->next;
  9390. }
  9391. }
  9392. else
  9393. {
  9394. if (temp_p->flags & AHC_CHANNEL_B_PRIMARY)
  9395. {
  9396. prev_p = current_p;
  9397. current_p = current_p->next;
  9398. }
  9399. }
  9400. }
  9401. if (prev_p != NULL)
  9402. {
  9403. prev_p->next = temp_p;
  9404. temp_p = temp_p->next;
  9405. prev_p->next->next = current_p;
  9406. }
  9407. else
  9408. {
  9409. pci = temp_p;
  9410. temp_p = temp_p->next;
  9411. pci->next = current_p;
  9412. }
  9413. }
  9414. if (p->flags & AHC_BIOS_ENABLED)
  9415. sort_list[1] = pci;
  9416. else
  9417. sort_list[3] = pci;
  9418. break;
  9419. }
  9420. } /* End of switch(temp_p->type) */
  9421. } /* End of while (temp_p != NULL) */
  9422. /*
  9423. * At this point, the cards have been broken into 4 sorted lists, now
  9424. * we run through the lists in order and register each controller
  9425. */
  9426. {
  9427. int i;
  9428. left = found;
  9429. for (i=0; i<ARRAY_SIZE(sort_list); i++)
  9430. {
  9431. temp_p = sort_list[i];
  9432. while(temp_p != NULL)
  9433. {
  9434. template->name = board_names[temp_p->board_name_index];
  9435. p = aic7xxx_alloc(template, temp_p);
  9436. if (p != NULL)
  9437. {
  9438. p->instance = found - left;
  9439. if (aic7xxx_register(template, p, (--left)) == 0)
  9440. {
  9441. found--;
  9442. aic7xxx_release(p->host);
  9443. scsi_unregister(p->host);
  9444. }
  9445. else if (aic7xxx_dump_card)
  9446. {
  9447. pause_sequencer(p);
  9448. aic7xxx_print_card(p);
  9449. aic7xxx_print_scratch_ram(p);
  9450. unpause_sequencer(p, TRUE);
  9451. }
  9452. }
  9453. current_p = temp_p;
  9454. temp_p = (struct aic7xxx_host *)temp_p->next;
  9455. kfree(current_p);
  9456. }
  9457. }
  9458. }
  9459. }
  9460. return (found);
  9461. }
  9462. /*+F*************************************************************************
  9463. * Function:
  9464. * aic7xxx_buildscb
  9465. *
  9466. * Description:
  9467. * Build a SCB.
  9468. *-F*************************************************************************/
  9469. static void aic7xxx_buildscb(struct aic7xxx_host *p, struct scsi_cmnd *cmd,
  9470. struct aic7xxx_scb *scb)
  9471. {
  9472. unsigned short mask;
  9473. struct aic7xxx_hwscb *hscb;
  9474. struct aic_dev_data *aic_dev = cmd->device->hostdata;
  9475. struct scsi_device *sdptr = cmd->device;
  9476. unsigned char tindex = TARGET_INDEX(cmd);
  9477. struct request *req = cmd->request;
  9478. mask = (0x01 << tindex);
  9479. hscb = scb->hscb;
  9480. /*
  9481. * Setup the control byte if we need negotiation and have not
  9482. * already requested it.
  9483. */
  9484. hscb->control = 0;
  9485. scb->tag_action = 0;
  9486. if (p->discenable & mask)
  9487. {
  9488. hscb->control |= DISCENB;
  9489. /* We always force TEST_UNIT_READY to untagged */
  9490. if (cmd->cmnd[0] != TEST_UNIT_READY && sdptr->simple_tags)
  9491. {
  9492. if (req->cmd_flags & REQ_HARDBARRIER)
  9493. {
  9494. if(sdptr->ordered_tags)
  9495. {
  9496. hscb->control |= MSG_ORDERED_Q_TAG;
  9497. scb->tag_action = MSG_ORDERED_Q_TAG;
  9498. }
  9499. }
  9500. else
  9501. {
  9502. hscb->control |= MSG_SIMPLE_Q_TAG;
  9503. scb->tag_action = MSG_SIMPLE_Q_TAG;
  9504. }
  9505. }
  9506. }
  9507. if ( !(aic_dev->dtr_pending) &&
  9508. (aic_dev->needppr || aic_dev->needwdtr || aic_dev->needsdtr) &&
  9509. (aic_dev->flags & DEVICE_DTR_SCANNED) )
  9510. {
  9511. aic_dev->dtr_pending = 1;
  9512. scb->tag_action = 0;
  9513. hscb->control &= DISCENB;
  9514. hscb->control |= MK_MESSAGE;
  9515. if(aic_dev->needppr)
  9516. {
  9517. scb->flags |= SCB_MSGOUT_PPR;
  9518. }
  9519. else if(aic_dev->needwdtr)
  9520. {
  9521. scb->flags |= SCB_MSGOUT_WDTR;
  9522. }
  9523. else if(aic_dev->needsdtr)
  9524. {
  9525. scb->flags |= SCB_MSGOUT_SDTR;
  9526. }
  9527. scb->flags |= SCB_DTR_SCB;
  9528. }
  9529. hscb->target_channel_lun = ((cmd->device->id << 4) & 0xF0) |
  9530. ((cmd->device->channel & 0x01) << 3) | (cmd->device->lun & 0x07);
  9531. /*
  9532. * The interpretation of request_buffer and request_bufflen
  9533. * changes depending on whether or not use_sg is zero; a
  9534. * non-zero use_sg indicates the number of elements in the
  9535. * scatter-gather array.
  9536. */
  9537. /*
  9538. * XXX - this relies on the host data being stored in a
  9539. * little-endian format.
  9540. */
  9541. hscb->SCSI_cmd_length = cmd->cmd_len;
  9542. memcpy(scb->cmnd, cmd->cmnd, cmd->cmd_len);
  9543. hscb->SCSI_cmd_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, scb->cmnd));
  9544. if (cmd->use_sg)
  9545. {
  9546. struct scatterlist *sg; /* Must be mid-level SCSI code scatterlist */
  9547. /*
  9548. * We must build an SG list in adapter format, as the kernel's SG list
  9549. * cannot be used directly because of data field size (__alpha__)
  9550. * differences and the kernel SG list uses virtual addresses where
  9551. * we need physical addresses.
  9552. */
  9553. int i, use_sg;
  9554. sg = (struct scatterlist *)cmd->request_buffer;
  9555. scb->sg_length = 0;
  9556. use_sg = pci_map_sg(p->pdev, sg, cmd->use_sg, cmd->sc_data_direction);
  9557. /*
  9558. * Copy the segments into the SG array. NOTE!!! - We used to
  9559. * have the first entry both in the data_pointer area and the first
  9560. * SG element. That has changed somewhat. We still have the first
  9561. * entry in both places, but now we download the address of
  9562. * scb->sg_list[1] instead of 0 to the sg pointer in the hscb.
  9563. */
  9564. for (i = 0; i < use_sg; i++)
  9565. {
  9566. unsigned int len = sg_dma_len(sg+i);
  9567. scb->sg_list[i].address = cpu_to_le32(sg_dma_address(sg+i));
  9568. scb->sg_list[i].length = cpu_to_le32(len);
  9569. scb->sg_length += len;
  9570. }
  9571. /* Copy the first SG into the data pointer area. */
  9572. hscb->data_pointer = scb->sg_list[0].address;
  9573. hscb->data_count = scb->sg_list[0].length;
  9574. scb->sg_count = i;
  9575. hscb->SG_segment_count = i;
  9576. hscb->SG_list_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, &scb->sg_list[1]));
  9577. }
  9578. else
  9579. {
  9580. if (cmd->request_bufflen)
  9581. {
  9582. unsigned int address = pci_map_single(p->pdev, cmd->request_buffer,
  9583. cmd->request_bufflen,
  9584. cmd->sc_data_direction);
  9585. aic7xxx_mapping(cmd) = address;
  9586. scb->sg_list[0].address = cpu_to_le32(address);
  9587. scb->sg_list[0].length = cpu_to_le32(cmd->request_bufflen);
  9588. scb->sg_count = 1;
  9589. scb->sg_length = cmd->request_bufflen;
  9590. hscb->SG_segment_count = 1;
  9591. hscb->SG_list_pointer = cpu_to_le32(SCB_DMA_ADDR(scb, &scb->sg_list[0]));
  9592. hscb->data_count = scb->sg_list[0].length;
  9593. hscb->data_pointer = scb->sg_list[0].address;
  9594. }
  9595. else
  9596. {
  9597. scb->sg_count = 0;
  9598. scb->sg_length = 0;
  9599. hscb->SG_segment_count = 0;
  9600. hscb->SG_list_pointer = 0;
  9601. hscb->data_count = 0;
  9602. hscb->data_pointer = 0;
  9603. }
  9604. }
  9605. }
  9606. /*+F*************************************************************************
  9607. * Function:
  9608. * aic7xxx_queue
  9609. *
  9610. * Description:
  9611. * Queue a SCB to the controller.
  9612. *-F*************************************************************************/
  9613. static int aic7xxx_queue(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
  9614. {
  9615. struct aic7xxx_host *p;
  9616. struct aic7xxx_scb *scb;
  9617. struct aic_dev_data *aic_dev;
  9618. p = (struct aic7xxx_host *) cmd->device->host->hostdata;
  9619. aic_dev = cmd->device->hostdata;
  9620. #ifdef AIC7XXX_VERBOSE_DEBUGGING
  9621. if (aic_dev->active_cmds > aic_dev->max_q_depth)
  9622. {
  9623. printk(WARN_LEAD "Commands queued exceeds queue "
  9624. "depth, active=%d\n",
  9625. p->host_no, CTL_OF_CMD(cmd),
  9626. aic_dev->active_cmds);
  9627. }
  9628. #endif
  9629. scb = scbq_remove_head(&p->scb_data->free_scbs);
  9630. if (scb == NULL)
  9631. {
  9632. aic7xxx_allocate_scb(p);
  9633. scb = scbq_remove_head(&p->scb_data->free_scbs);
  9634. if(scb == NULL)
  9635. {
  9636. printk(WARN_LEAD "Couldn't get a free SCB.\n", p->host_no,
  9637. CTL_OF_CMD(cmd));
  9638. return 1;
  9639. }
  9640. }
  9641. scb->cmd = cmd;
  9642. /*
  9643. * Make sure the scsi_cmnd pointer is saved, the struct it points to
  9644. * is set up properly, and the parity error flag is reset, then send
  9645. * the SCB to the sequencer and watch the fun begin.
  9646. */
  9647. aic7xxx_position(cmd) = scb->hscb->tag;
  9648. cmd->scsi_done = fn;
  9649. cmd->result = DID_OK;
  9650. memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
  9651. aic7xxx_error(cmd) = DID_OK;
  9652. aic7xxx_status(cmd) = 0;
  9653. cmd->host_scribble = NULL;
  9654. /*
  9655. * Construct the SCB beforehand, so the sequencer is
  9656. * paused a minimal amount of time.
  9657. */
  9658. aic7xxx_buildscb(p, cmd, scb);
  9659. scb->flags |= SCB_ACTIVE | SCB_WAITINGQ;
  9660. scbq_insert_tail(&p->waiting_scbs, scb);
  9661. aic7xxx_run_waiting_queues(p);
  9662. return (0);
  9663. }
  9664. /*+F*************************************************************************
  9665. * Function:
  9666. * aic7xxx_bus_device_reset
  9667. *
  9668. * Description:
  9669. * Abort or reset the current SCSI command(s). If the scb has not
  9670. * previously been aborted, then we attempt to send a BUS_DEVICE_RESET
  9671. * message to the target. If the scb has previously been unsuccessfully
  9672. * aborted, then we will reset the channel and have all devices renegotiate.
  9673. * Returns an enumerated type that indicates the status of the operation.
  9674. *-F*************************************************************************/
  9675. static int __aic7xxx_bus_device_reset(struct scsi_cmnd *cmd)
  9676. {
  9677. struct aic7xxx_host *p;
  9678. struct aic7xxx_scb *scb;
  9679. struct aic7xxx_hwscb *hscb;
  9680. int channel;
  9681. unsigned char saved_scbptr, lastphase;
  9682. unsigned char hscb_index;
  9683. int disconnected;
  9684. struct aic_dev_data *aic_dev;
  9685. if(cmd == NULL)
  9686. {
  9687. printk(KERN_ERR "aic7xxx_bus_device_reset: called with NULL cmd!\n");
  9688. return FAILED;
  9689. }
  9690. p = (struct aic7xxx_host *)cmd->device->host->hostdata;
  9691. aic_dev = AIC_DEV(cmd);
  9692. if(aic7xxx_position(cmd) < p->scb_data->numscbs)
  9693. scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
  9694. else
  9695. return FAILED;
  9696. hscb = scb->hscb;
  9697. aic7xxx_isr(p);
  9698. aic7xxx_done_cmds_complete(p);
  9699. /* If the command was already complete or just completed, then we didn't
  9700. * do a reset, return FAILED */
  9701. if(!(scb->flags & SCB_ACTIVE))
  9702. return FAILED;
  9703. pause_sequencer(p);
  9704. lastphase = aic_inb(p, LASTPHASE);
  9705. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  9706. {
  9707. printk(INFO_LEAD "Bus Device reset, scb flags 0x%x, ",
  9708. p->host_no, CTL_OF_SCB(scb), scb->flags);
  9709. switch (lastphase)
  9710. {
  9711. case P_DATAOUT:
  9712. printk("Data-Out phase\n");
  9713. break;
  9714. case P_DATAIN:
  9715. printk("Data-In phase\n");
  9716. break;
  9717. case P_COMMAND:
  9718. printk("Command phase\n");
  9719. break;
  9720. case P_MESGOUT:
  9721. printk("Message-Out phase\n");
  9722. break;
  9723. case P_STATUS:
  9724. printk("Status phase\n");
  9725. break;
  9726. case P_MESGIN:
  9727. printk("Message-In phase\n");
  9728. break;
  9729. default:
  9730. /*
  9731. * We're not in a valid phase, so assume we're idle.
  9732. */
  9733. printk("while idle, LASTPHASE = 0x%x\n", lastphase);
  9734. break;
  9735. }
  9736. printk(INFO_LEAD "SCSISIGI 0x%x, SEQADDR 0x%x, SSTAT0 0x%x, SSTAT1 "
  9737. "0x%x\n", p->host_no, CTL_OF_SCB(scb),
  9738. aic_inb(p, SCSISIGI),
  9739. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  9740. aic_inb(p, SSTAT0), aic_inb(p, SSTAT1));
  9741. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SSTAT2 0x%x, STCNT 0x%x\n", p->host_no,
  9742. CTL_OF_SCB(scb),
  9743. (p->features & AHC_ULTRA2) ? aic_inb(p, SG_CACHEPTR) : 0,
  9744. aic_inb(p, SSTAT2),
  9745. aic_inb(p, STCNT + 2) << 16 | aic_inb(p, STCNT + 1) << 8 |
  9746. aic_inb(p, STCNT));
  9747. }
  9748. channel = cmd->device->channel;
  9749. /*
  9750. * Send a Device Reset Message:
  9751. * The target that is holding up the bus may not be the same as
  9752. * the one that triggered this timeout (different commands have
  9753. * different timeout lengths). Our strategy here is to queue an
  9754. * abort message to the timed out target if it is disconnected.
  9755. * Otherwise, if we have an active target we stuff the message buffer
  9756. * with an abort message and assert ATN in the hopes that the target
  9757. * will let go of the bus and go to the mesgout phase. If this
  9758. * fails, we'll get another timeout a few seconds later which will
  9759. * attempt a bus reset.
  9760. */
  9761. saved_scbptr = aic_inb(p, SCBPTR);
  9762. disconnected = FALSE;
  9763. if (lastphase != P_BUSFREE)
  9764. {
  9765. if (aic_inb(p, SCB_TAG) >= p->scb_data->numscbs)
  9766. {
  9767. printk(WARN_LEAD "Invalid SCB ID %d is active, "
  9768. "SCB flags = 0x%x.\n", p->host_no,
  9769. CTL_OF_CMD(cmd), scb->hscb->tag, scb->flags);
  9770. unpause_sequencer(p, FALSE);
  9771. return FAILED;
  9772. }
  9773. if (scb->hscb->tag == aic_inb(p, SCB_TAG))
  9774. {
  9775. if ( (lastphase == P_MESGOUT) || (lastphase == P_MESGIN) )
  9776. {
  9777. printk(WARN_LEAD "Device reset, Message buffer "
  9778. "in use\n", p->host_no, CTL_OF_SCB(scb));
  9779. unpause_sequencer(p, FALSE);
  9780. return FAILED;
  9781. }
  9782. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  9783. printk(INFO_LEAD "Device reset message in "
  9784. "message buffer\n", p->host_no, CTL_OF_SCB(scb));
  9785. scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
  9786. aic7xxx_error(cmd) = DID_RESET;
  9787. aic_dev->flags |= BUS_DEVICE_RESET_PENDING;
  9788. /* Send the abort message to the active SCB. */
  9789. aic_outb(p, HOST_MSG, MSG_OUT);
  9790. aic_outb(p, lastphase | ATNO, SCSISIGO);
  9791. unpause_sequencer(p, FALSE);
  9792. spin_unlock_irq(p->host->host_lock);
  9793. ssleep(1);
  9794. spin_lock_irq(p->host->host_lock);
  9795. if(aic_dev->flags & BUS_DEVICE_RESET_PENDING)
  9796. return FAILED;
  9797. else
  9798. return SUCCESS;
  9799. }
  9800. } /* if (last_phase != P_BUSFREE).....indicates we are idle and can work */
  9801. /*
  9802. * Simply set the MK_MESSAGE flag and the SEQINT handler will do
  9803. * the rest on a reconnect/connect.
  9804. */
  9805. scb->hscb->control |= MK_MESSAGE;
  9806. scb->flags |= SCB_RESET | SCB_DEVICE_RESET;
  9807. aic_dev->flags |= BUS_DEVICE_RESET_PENDING;
  9808. /*
  9809. * Check to see if the command is on the qinfifo. If it is, then we will
  9810. * not need to queue the command again since the card should start it soon
  9811. */
  9812. if (aic7xxx_search_qinfifo(p, cmd->device->channel, cmd->device->id, cmd->device->lun, hscb->tag,
  9813. 0, TRUE, NULL) == 0)
  9814. {
  9815. disconnected = TRUE;
  9816. if ((hscb_index = aic7xxx_find_scb(p, scb)) != SCB_LIST_NULL)
  9817. {
  9818. unsigned char scb_control;
  9819. aic_outb(p, hscb_index, SCBPTR);
  9820. scb_control = aic_inb(p, SCB_CONTROL);
  9821. /*
  9822. * If the DISCONNECTED bit is not set in SCB_CONTROL, then we are
  9823. * actually on the waiting list, not disconnected, and we don't
  9824. * need to requeue the command.
  9825. */
  9826. disconnected = (scb_control & DISCONNECTED);
  9827. aic_outb(p, scb_control | MK_MESSAGE, SCB_CONTROL);
  9828. }
  9829. if (disconnected)
  9830. {
  9831. /*
  9832. * Actually requeue this SCB in case we can select the
  9833. * device before it reconnects. This can result in the command
  9834. * being on the qinfifo twice, but we don't care because it will
  9835. * all get cleaned up if/when the reset takes place.
  9836. */
  9837. if (aic7xxx_verbose & VERBOSE_RESET_PROCESS)
  9838. printk(INFO_LEAD "Queueing device reset command.\n", p->host_no,
  9839. CTL_OF_SCB(scb));
  9840. p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
  9841. if (p->features & AHC_QUEUE_REGS)
  9842. aic_outb(p, p->qinfifonext, HNSCB_QOFF);
  9843. else
  9844. aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
  9845. scb->flags |= SCB_QUEUED_ABORT;
  9846. }
  9847. }
  9848. aic_outb(p, saved_scbptr, SCBPTR);
  9849. unpause_sequencer(p, FALSE);
  9850. spin_unlock_irq(p->host->host_lock);
  9851. msleep(1000/4);
  9852. spin_lock_irq(p->host->host_lock);
  9853. if(aic_dev->flags & BUS_DEVICE_RESET_PENDING)
  9854. return FAILED;
  9855. else
  9856. return SUCCESS;
  9857. }
  9858. static int aic7xxx_bus_device_reset(struct scsi_cmnd *cmd)
  9859. {
  9860. int rc;
  9861. spin_lock_irq(cmd->device->host->host_lock);
  9862. rc = __aic7xxx_bus_device_reset(cmd);
  9863. spin_unlock_irq(cmd->device->host->host_lock);
  9864. return rc;
  9865. }
  9866. /*+F*************************************************************************
  9867. * Function:
  9868. * aic7xxx_panic_abort
  9869. *
  9870. * Description:
  9871. * Abort the current SCSI command(s).
  9872. *-F*************************************************************************/
  9873. static void aic7xxx_panic_abort(struct aic7xxx_host *p, struct scsi_cmnd *cmd)
  9874. {
  9875. printk("aic7xxx driver version %s\n", AIC7XXX_C_VERSION);
  9876. printk("Controller type:\n %s\n", board_names[p->board_name_index]);
  9877. printk("p->flags=0x%lx, p->chip=0x%x, p->features=0x%x, "
  9878. "sequencer %s paused\n",
  9879. p->flags, p->chip, p->features,
  9880. (aic_inb(p, HCNTRL) & PAUSE) ? "is" : "isn't" );
  9881. pause_sequencer(p);
  9882. disable_irq(p->irq);
  9883. aic7xxx_print_card(p);
  9884. aic7xxx_print_scratch_ram(p);
  9885. spin_unlock_irq(p->host->host_lock);
  9886. for(;;) barrier();
  9887. }
  9888. /*+F*************************************************************************
  9889. * Function:
  9890. * aic7xxx_abort
  9891. *
  9892. * Description:
  9893. * Abort the current SCSI command(s).
  9894. *-F*************************************************************************/
  9895. static int __aic7xxx_abort(struct scsi_cmnd *cmd)
  9896. {
  9897. struct aic7xxx_scb *scb = NULL;
  9898. struct aic7xxx_host *p;
  9899. int found=0, disconnected;
  9900. unsigned char saved_hscbptr, hscbptr, scb_control;
  9901. struct aic_dev_data *aic_dev;
  9902. if(cmd == NULL)
  9903. {
  9904. printk(KERN_ERR "aic7xxx_abort: called with NULL cmd!\n");
  9905. return FAILED;
  9906. }
  9907. p = (struct aic7xxx_host *)cmd->device->host->hostdata;
  9908. aic_dev = AIC_DEV(cmd);
  9909. if(aic7xxx_position(cmd) < p->scb_data->numscbs)
  9910. scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
  9911. else
  9912. return FAILED;
  9913. aic7xxx_isr(p);
  9914. aic7xxx_done_cmds_complete(p);
  9915. /* If the command was already complete or just completed, then we didn't
  9916. * do a reset, return FAILED */
  9917. if(!(scb->flags & SCB_ACTIVE))
  9918. return FAILED;
  9919. pause_sequencer(p);
  9920. /*
  9921. * I added a new config option to the driver: "panic_on_abort" that will
  9922. * cause the driver to panic and the machine to stop on the first abort
  9923. * or reset call into the driver. At that point, it prints out a lot of
  9924. * useful information for me which I can then use to try and debug the
  9925. * problem. Simply enable the boot time prompt in order to activate this
  9926. * code.
  9927. */
  9928. if (aic7xxx_panic_on_abort)
  9929. aic7xxx_panic_abort(p, cmd);
  9930. if (aic7xxx_verbose & VERBOSE_ABORT)
  9931. {
  9932. printk(INFO_LEAD "Aborting scb %d, flags 0x%x, SEQADDR 0x%x, LASTPHASE "
  9933. "0x%x\n",
  9934. p->host_no, CTL_OF_SCB(scb), scb->hscb->tag, scb->flags,
  9935. aic_inb(p, SEQADDR0) | (aic_inb(p, SEQADDR1) << 8),
  9936. aic_inb(p, LASTPHASE));
  9937. printk(INFO_LEAD "SG_CACHEPTR 0x%x, SG_COUNT %d, SCSISIGI 0x%x\n",
  9938. p->host_no, CTL_OF_SCB(scb), (p->features & AHC_ULTRA2) ?
  9939. aic_inb(p, SG_CACHEPTR) : 0, aic_inb(p, SG_COUNT),
  9940. aic_inb(p, SCSISIGI));
  9941. printk(INFO_LEAD "SSTAT0 0x%x, SSTAT1 0x%x, SSTAT2 0x%x\n",
  9942. p->host_no, CTL_OF_SCB(scb), aic_inb(p, SSTAT0),
  9943. aic_inb(p, SSTAT1), aic_inb(p, SSTAT2));
  9944. }
  9945. if (scb->flags & SCB_WAITINGQ)
  9946. {
  9947. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  9948. printk(INFO_LEAD "SCB found on waiting list and "
  9949. "aborted.\n", p->host_no, CTL_OF_SCB(scb));
  9950. scbq_remove(&p->waiting_scbs, scb);
  9951. scbq_remove(&aic_dev->delayed_scbs, scb);
  9952. aic_dev->active_cmds++;
  9953. p->activescbs++;
  9954. scb->flags &= ~(SCB_WAITINGQ | SCB_ACTIVE);
  9955. scb->flags |= SCB_ABORT | SCB_QUEUED_FOR_DONE;
  9956. goto success;
  9957. }
  9958. /*
  9959. * We just checked the waiting_q, now for the QINFIFO
  9960. */
  9961. if ( ((found = aic7xxx_search_qinfifo(p, cmd->device->id, cmd->device->channel,
  9962. cmd->device->lun, scb->hscb->tag, SCB_ABORT | SCB_QUEUED_FOR_DONE,
  9963. FALSE, NULL)) != 0) &&
  9964. (aic7xxx_verbose & VERBOSE_ABORT_PROCESS))
  9965. {
  9966. printk(INFO_LEAD "SCB found in QINFIFO and aborted.\n", p->host_no,
  9967. CTL_OF_SCB(scb));
  9968. goto success;
  9969. }
  9970. /*
  9971. * QINFIFO, waitingq, completeq done. Next, check WAITING_SCB list in card
  9972. */
  9973. saved_hscbptr = aic_inb(p, SCBPTR);
  9974. if ((hscbptr = aic7xxx_find_scb(p, scb)) != SCB_LIST_NULL)
  9975. {
  9976. aic_outb(p, hscbptr, SCBPTR);
  9977. scb_control = aic_inb(p, SCB_CONTROL);
  9978. disconnected = scb_control & DISCONNECTED;
  9979. /*
  9980. * If the DISCONNECTED bit is not set in SCB_CONTROL, then we are
  9981. * either currently active or on the waiting list.
  9982. */
  9983. if(!disconnected && aic_inb(p, LASTPHASE) == P_BUSFREE) {
  9984. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  9985. printk(INFO_LEAD "SCB found on hardware waiting"
  9986. " list and aborted.\n", p->host_no, CTL_OF_SCB(scb));
  9987. /* If we are the only waiting command, stop the selection engine */
  9988. if (aic_inb(p, WAITING_SCBH) == hscbptr && aic_inb(p, SCB_NEXT) ==
  9989. SCB_LIST_NULL)
  9990. {
  9991. aic_outb(p, aic_inb(p, SCSISEQ) & ~ENSELO, SCSISEQ);
  9992. aic_outb(p, CLRSELTIMEO, CLRSINT1);
  9993. aic_outb(p, SCB_LIST_NULL, WAITING_SCBH);
  9994. }
  9995. else
  9996. {
  9997. unsigned char prev, next;
  9998. prev = SCB_LIST_NULL;
  9999. next = aic_inb(p, WAITING_SCBH);
  10000. while(next != SCB_LIST_NULL)
  10001. {
  10002. aic_outb(p, next, SCBPTR);
  10003. if (next == hscbptr)
  10004. {
  10005. next = aic_inb(p, SCB_NEXT);
  10006. if (prev != SCB_LIST_NULL)
  10007. {
  10008. aic_outb(p, prev, SCBPTR);
  10009. aic_outb(p, next, SCB_NEXT);
  10010. }
  10011. else
  10012. aic_outb(p, next, WAITING_SCBH);
  10013. aic_outb(p, hscbptr, SCBPTR);
  10014. next = SCB_LIST_NULL;
  10015. }
  10016. else
  10017. {
  10018. prev = next;
  10019. next = aic_inb(p, SCB_NEXT);
  10020. }
  10021. }
  10022. }
  10023. aic_outb(p, SCB_LIST_NULL, SCB_TAG);
  10024. aic_outb(p, 0, SCB_CONTROL);
  10025. aic7xxx_add_curscb_to_free_list(p);
  10026. scb->flags = SCB_ABORT | SCB_QUEUED_FOR_DONE;
  10027. goto success;
  10028. }
  10029. else if (!disconnected)
  10030. {
  10031. /*
  10032. * We are the currently active command
  10033. */
  10034. if((aic_inb(p, LASTPHASE) == P_MESGIN) ||
  10035. (aic_inb(p, LASTPHASE) == P_MESGOUT))
  10036. {
  10037. /*
  10038. * Message buffer busy, unable to abort
  10039. */
  10040. printk(INFO_LEAD "message buffer busy, unable to abort.\n",
  10041. p->host_no, CTL_OF_SCB(scb));
  10042. unpause_sequencer(p, FALSE);
  10043. return FAILED;
  10044. }
  10045. /* Fallthrough to below, set ATNO after we set SCB_CONTROL */
  10046. }
  10047. aic_outb(p, scb_control | MK_MESSAGE, SCB_CONTROL);
  10048. if(!disconnected)
  10049. {
  10050. aic_outb(p, HOST_MSG, MSG_OUT);
  10051. aic_outb(p, aic_inb(p, SCSISIGI) | ATNO, SCSISIGO);
  10052. }
  10053. aic_outb(p, saved_hscbptr, SCBPTR);
  10054. }
  10055. else
  10056. {
  10057. /*
  10058. * The scb isn't in the card at all and it is active and it isn't in
  10059. * any of the queues, so it must be disconnected and paged out. Fall
  10060. * through to the code below.
  10061. */
  10062. disconnected = 1;
  10063. }
  10064. p->flags |= AHC_ABORT_PENDING;
  10065. scb->flags |= SCB_QUEUED_ABORT | SCB_ABORT | SCB_RECOVERY_SCB;
  10066. scb->hscb->control |= MK_MESSAGE;
  10067. if(disconnected)
  10068. {
  10069. if (aic7xxx_verbose & VERBOSE_ABORT_PROCESS)
  10070. printk(INFO_LEAD "SCB disconnected. Queueing Abort"
  10071. " SCB.\n", p->host_no, CTL_OF_SCB(scb));
  10072. p->qinfifo[p->qinfifonext++] = scb->hscb->tag;
  10073. if (p->features & AHC_QUEUE_REGS)
  10074. aic_outb(p, p->qinfifonext, HNSCB_QOFF);
  10075. else
  10076. aic_outb(p, p->qinfifonext, KERNEL_QINPOS);
  10077. }
  10078. unpause_sequencer(p, FALSE);
  10079. spin_unlock_irq(p->host->host_lock);
  10080. msleep(1000/4);
  10081. spin_lock_irq(p->host->host_lock);
  10082. if (p->flags & AHC_ABORT_PENDING)
  10083. {
  10084. if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
  10085. printk(INFO_LEAD "Abort never delivered, returning FAILED\n", p->host_no,
  10086. CTL_OF_CMD(cmd));
  10087. p->flags &= ~AHC_ABORT_PENDING;
  10088. return FAILED;
  10089. }
  10090. if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
  10091. printk(INFO_LEAD "Abort successful.\n", p->host_no, CTL_OF_CMD(cmd));
  10092. return SUCCESS;
  10093. success:
  10094. if (aic7xxx_verbose & VERBOSE_ABORT_RETURN)
  10095. printk(INFO_LEAD "Abort successful.\n", p->host_no, CTL_OF_CMD(cmd));
  10096. aic7xxx_run_done_queue(p, TRUE);
  10097. unpause_sequencer(p, FALSE);
  10098. return SUCCESS;
  10099. }
  10100. static int aic7xxx_abort(struct scsi_cmnd *cmd)
  10101. {
  10102. int rc;
  10103. spin_lock_irq(cmd->device->host->host_lock);
  10104. rc = __aic7xxx_abort(cmd);
  10105. spin_unlock_irq(cmd->device->host->host_lock);
  10106. return rc;
  10107. }
  10108. /*+F*************************************************************************
  10109. * Function:
  10110. * aic7xxx_reset
  10111. *
  10112. * Description:
  10113. * Resetting the bus always succeeds - is has to, otherwise the
  10114. * kernel will panic! Try a surgical technique - sending a BUS
  10115. * DEVICE RESET message - on the offending target before pulling
  10116. * the SCSI bus reset line.
  10117. *-F*************************************************************************/
  10118. static int aic7xxx_reset(struct scsi_cmnd *cmd)
  10119. {
  10120. struct aic7xxx_scb *scb;
  10121. struct aic7xxx_host *p;
  10122. struct aic_dev_data *aic_dev;
  10123. p = (struct aic7xxx_host *) cmd->device->host->hostdata;
  10124. spin_lock_irq(p->host->host_lock);
  10125. aic_dev = AIC_DEV(cmd);
  10126. if(aic7xxx_position(cmd) < p->scb_data->numscbs)
  10127. {
  10128. scb = (p->scb_data->scb_array[aic7xxx_position(cmd)]);
  10129. if (scb->cmd != cmd)
  10130. scb = NULL;
  10131. }
  10132. else
  10133. {
  10134. scb = NULL;
  10135. }
  10136. /*
  10137. * I added a new config option to the driver: "panic_on_abort" that will
  10138. * cause the driver to panic and the machine to stop on the first abort
  10139. * or reset call into the driver. At that point, it prints out a lot of
  10140. * useful information for me which I can then use to try and debug the
  10141. * problem. Simply enable the boot time prompt in order to activate this
  10142. * code.
  10143. */
  10144. if (aic7xxx_panic_on_abort)
  10145. aic7xxx_panic_abort(p, cmd);
  10146. pause_sequencer(p);
  10147. while((aic_inb(p, INTSTAT) & INT_PEND) && !(p->flags & AHC_IN_ISR))
  10148. {
  10149. aic7xxx_isr(p);
  10150. pause_sequencer(p);
  10151. }
  10152. aic7xxx_done_cmds_complete(p);
  10153. if(scb && (scb->cmd == NULL))
  10154. {
  10155. /*
  10156. * We just completed the command when we ran the isr stuff, so we no
  10157. * longer have it.
  10158. */
  10159. unpause_sequencer(p, FALSE);
  10160. spin_unlock_irq(p->host->host_lock);
  10161. return SUCCESS;
  10162. }
  10163. /*
  10164. * By this point, we want to already know what we are going to do and
  10165. * only have the following code implement our course of action.
  10166. */
  10167. aic7xxx_reset_channel(p, cmd->device->channel, TRUE);
  10168. if (p->features & AHC_TWIN)
  10169. {
  10170. aic7xxx_reset_channel(p, cmd->device->channel ^ 0x01, TRUE);
  10171. restart_sequencer(p);
  10172. }
  10173. aic_outb(p, aic_inb(p, SIMODE1) & ~(ENREQINIT|ENBUSFREE), SIMODE1);
  10174. aic7xxx_clear_intstat(p);
  10175. p->flags &= ~AHC_HANDLING_REQINITS;
  10176. p->msg_type = MSG_TYPE_NONE;
  10177. p->msg_index = 0;
  10178. p->msg_len = 0;
  10179. aic7xxx_run_done_queue(p, TRUE);
  10180. unpause_sequencer(p, FALSE);
  10181. spin_unlock_irq(p->host->host_lock);
  10182. ssleep(2);
  10183. return SUCCESS;
  10184. }
  10185. /*+F*************************************************************************
  10186. * Function:
  10187. * aic7xxx_biosparam
  10188. *
  10189. * Description:
  10190. * Return the disk geometry for the given SCSI device.
  10191. *
  10192. * Note:
  10193. * This function is broken for today's really large drives and needs
  10194. * fixed.
  10195. *-F*************************************************************************/
  10196. static int
  10197. aic7xxx_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  10198. sector_t capacity, int geom[])
  10199. {
  10200. sector_t heads, sectors, cylinders;
  10201. int ret;
  10202. struct aic7xxx_host *p;
  10203. unsigned char *buf;
  10204. p = (struct aic7xxx_host *) sdev->host->hostdata;
  10205. buf = scsi_bios_ptable(bdev);
  10206. if ( buf )
  10207. {
  10208. ret = scsi_partsize(buf, capacity, &geom[2], &geom[0], &geom[1]);
  10209. kfree(buf);
  10210. if ( ret != -1 )
  10211. return(ret);
  10212. }
  10213. heads = 64;
  10214. sectors = 32;
  10215. cylinders = capacity >> 11;
  10216. if ((p->flags & AHC_EXTEND_TRANS_A) && (cylinders > 1024))
  10217. {
  10218. heads = 255;
  10219. sectors = 63;
  10220. cylinders = capacity >> 14;
  10221. if(capacity > (65535 * heads * sectors))
  10222. cylinders = 65535;
  10223. else
  10224. cylinders = ((unsigned int)capacity) / (unsigned int)(heads * sectors);
  10225. }
  10226. geom[0] = (int)heads;
  10227. geom[1] = (int)sectors;
  10228. geom[2] = (int)cylinders;
  10229. return (0);
  10230. }
  10231. /*+F*************************************************************************
  10232. * Function:
  10233. * aic7xxx_release
  10234. *
  10235. * Description:
  10236. * Free the passed in Scsi_Host memory structures prior to unloading the
  10237. * module.
  10238. *-F*************************************************************************/
  10239. static int
  10240. aic7xxx_release(struct Scsi_Host *host)
  10241. {
  10242. struct aic7xxx_host *p = (struct aic7xxx_host *) host->hostdata;
  10243. struct aic7xxx_host *next, *prev;
  10244. if(p->irq)
  10245. free_irq(p->irq, p);
  10246. #ifdef MMAPIO
  10247. if(p->maddr)
  10248. {
  10249. iounmap(p->maddr);
  10250. }
  10251. #endif /* MMAPIO */
  10252. if(!p->pdev)
  10253. release_region(p->base, MAXREG - MINREG);
  10254. #ifdef CONFIG_PCI
  10255. else {
  10256. pci_release_regions(p->pdev);
  10257. pci_dev_put(p->pdev);
  10258. }
  10259. #endif
  10260. prev = NULL;
  10261. next = first_aic7xxx;
  10262. while(next != NULL)
  10263. {
  10264. if(next == p)
  10265. {
  10266. if(prev == NULL)
  10267. first_aic7xxx = next->next;
  10268. else
  10269. prev->next = next->next;
  10270. }
  10271. else
  10272. {
  10273. prev = next;
  10274. }
  10275. next = next->next;
  10276. }
  10277. aic7xxx_free(p);
  10278. return(0);
  10279. }
  10280. /*+F*************************************************************************
  10281. * Function:
  10282. * aic7xxx_print_card
  10283. *
  10284. * Description:
  10285. * Print out all of the control registers on the card
  10286. *
  10287. * NOTE: This function is not yet safe for use on the VLB and EISA
  10288. * controllers, so it isn't used on those controllers at all.
  10289. *-F*************************************************************************/
  10290. static void
  10291. aic7xxx_print_card(struct aic7xxx_host *p)
  10292. {
  10293. int i, j, k, chip;
  10294. static struct register_ranges {
  10295. int num_ranges;
  10296. int range_val[32];
  10297. } cards_ds[] = {
  10298. { 0, {0,} }, /* none */
  10299. {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1f, 0x1f, 0x60, 0x60, /*7771*/
  10300. 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9b, 0x9f} },
  10301. { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7850*/
  10302. 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
  10303. { 9, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7860*/
  10304. 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
  10305. {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1c, 0x1f, 0x60, 0x60, /*7870*/
  10306. 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
  10307. {10, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1a, 0x1c, 0x1f, 0x60, 0x60, /*7880*/
  10308. 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9f} },
  10309. {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7890*/
  10310. 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
  10311. 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
  10312. 0xfe, 0xff} },
  10313. {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x19, 0x1b, 0x1f, 0x60, 0x60, /*7895*/
  10314. 0x62, 0x66, 0x80, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a,
  10315. 0x9f, 0x9f, 0xe0, 0xf1} },
  10316. {16, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7896*/
  10317. 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9f, 0x9f,
  10318. 0xe0, 0xf1, 0xf4, 0xf4, 0xf6, 0xf6, 0xf8, 0xf8, 0xfa, 0xfc,
  10319. 0xfe, 0xff} },
  10320. {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7892*/
  10321. 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
  10322. 0xe0, 0xf1, 0xf4, 0xfc} },
  10323. {12, {0x00, 0x05, 0x08, 0x11, 0x18, 0x1f, 0x60, 0x60, 0x62, 0x66, /*7899*/
  10324. 0x84, 0x8e, 0x90, 0x95, 0x97, 0x97, 0x9a, 0x9a, 0x9c, 0x9f,
  10325. 0xe0, 0xf1, 0xf4, 0xfc} },
  10326. };
  10327. chip = p->chip & AHC_CHIPID_MASK;
  10328. printk("%s at ",
  10329. board_names[p->board_name_index]);
  10330. switch(p->chip & ~AHC_CHIPID_MASK)
  10331. {
  10332. case AHC_VL:
  10333. printk("VLB Slot %d.\n", p->pci_device_fn);
  10334. break;
  10335. case AHC_EISA:
  10336. printk("EISA Slot %d.\n", p->pci_device_fn);
  10337. break;
  10338. case AHC_PCI:
  10339. default:
  10340. printk("PCI %d/%d/%d.\n", p->pci_bus, PCI_SLOT(p->pci_device_fn),
  10341. PCI_FUNC(p->pci_device_fn));
  10342. break;
  10343. }
  10344. /*
  10345. * the registers on the card....
  10346. */
  10347. printk("Card Dump:\n");
  10348. k = 0;
  10349. for(i=0; i<cards_ds[chip].num_ranges; i++)
  10350. {
  10351. for(j = cards_ds[chip].range_val[ i * 2 ];
  10352. j <= cards_ds[chip].range_val[ i * 2 + 1 ] ;
  10353. j++)
  10354. {
  10355. printk("%02x:%02x ", j, aic_inb(p, j));
  10356. if(++k == 13)
  10357. {
  10358. printk("\n");
  10359. k=0;
  10360. }
  10361. }
  10362. }
  10363. if(k != 0)
  10364. printk("\n");
  10365. /*
  10366. * If this was an Ultra2 controller, then we just hosed the card in terms
  10367. * of the QUEUE REGS. This function is only called at init time or by
  10368. * the panic_abort function, so it's safe to assume a generic init time
  10369. * setting here
  10370. */
  10371. if(p->features & AHC_QUEUE_REGS)
  10372. {
  10373. aic_outb(p, 0, SDSCB_QOFF);
  10374. aic_outb(p, 0, SNSCB_QOFF);
  10375. aic_outb(p, 0, HNSCB_QOFF);
  10376. }
  10377. }
  10378. /*+F*************************************************************************
  10379. * Function:
  10380. * aic7xxx_print_scratch_ram
  10381. *
  10382. * Description:
  10383. * Print out the scratch RAM values on the card.
  10384. *-F*************************************************************************/
  10385. static void
  10386. aic7xxx_print_scratch_ram(struct aic7xxx_host *p)
  10387. {
  10388. int i, k;
  10389. k = 0;
  10390. printk("Scratch RAM:\n");
  10391. for(i = SRAM_BASE; i < SEQCTL; i++)
  10392. {
  10393. printk("%02x:%02x ", i, aic_inb(p, i));
  10394. if(++k == 13)
  10395. {
  10396. printk("\n");
  10397. k=0;
  10398. }
  10399. }
  10400. if (p->features & AHC_MORE_SRAM)
  10401. {
  10402. for(i = TARG_OFFSET; i < 0x80; i++)
  10403. {
  10404. printk("%02x:%02x ", i, aic_inb(p, i));
  10405. if(++k == 13)
  10406. {
  10407. printk("\n");
  10408. k=0;
  10409. }
  10410. }
  10411. }
  10412. printk("\n");
  10413. }
  10414. #include "aic7xxx_old/aic7xxx_proc.c"
  10415. MODULE_LICENSE("Dual BSD/GPL");
  10416. MODULE_VERSION(AIC7XXX_H_VERSION);
  10417. static struct scsi_host_template driver_template = {
  10418. .proc_info = aic7xxx_proc_info,
  10419. .detect = aic7xxx_detect,
  10420. .release = aic7xxx_release,
  10421. .info = aic7xxx_info,
  10422. .queuecommand = aic7xxx_queue,
  10423. .slave_alloc = aic7xxx_slave_alloc,
  10424. .slave_configure = aic7xxx_slave_configure,
  10425. .slave_destroy = aic7xxx_slave_destroy,
  10426. .bios_param = aic7xxx_biosparam,
  10427. .eh_abort_handler = aic7xxx_abort,
  10428. .eh_device_reset_handler = aic7xxx_bus_device_reset,
  10429. .eh_host_reset_handler = aic7xxx_reset,
  10430. .can_queue = 255,
  10431. .this_id = -1,
  10432. .max_sectors = 2048,
  10433. .cmd_per_lun = 3,
  10434. .use_clustering = ENABLE_CLUSTERING,
  10435. };
  10436. #include "scsi_module.c"
  10437. /*
  10438. * Overrides for Emacs so that we almost follow Linus's tabbing style.
  10439. * Emacs will notice this stuff at the end of the file and automatically
  10440. * adjust the settings for this buffer only. This must remain at the end
  10441. * of the file.
  10442. * ---------------------------------------------------------------------------
  10443. * Local variables:
  10444. * c-indent-level: 2
  10445. * c-brace-imaginary-offset: 0
  10446. * c-brace-offset: -2
  10447. * c-argdecl-indent: 2
  10448. * c-label-offset: -2
  10449. * c-continued-statement-offset: 2
  10450. * c-continued-brace-offset: 0
  10451. * indent-tabs-mode: nil
  10452. * tab-width: 8
  10453. * End:
  10454. */